diff --git a/apps/admin/src/styles.css b/apps/admin/src/styles.css index 2e62e17..c2dd3ed 100644 --- a/apps/admin/src/styles.css +++ b/apps/admin/src/styles.css @@ -420,8 +420,10 @@ table.data tr:hover td { background: rgba(244,245,249,.6); } .badge-el { position: absolute; overflow: visible; cursor: move; } .badge-el.selected { outline: 1.5px solid var(--accent); } .badge-text-body { width: 100%; height: 100%; display: flex; overflow: hidden; } -.badge-text-body > span { max-width: 100%; overflow-wrap: anywhere; } +.badge-text-body > span { width: 100%; overflow-wrap: anywhere; } .badge-el-placeholder { color: #cbd5e1; font-style: italic; } +.badge-align-group { margin-top: 8px; } +.badge-align-group-label { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 4px; } .badge-qr-body { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; } .badge-qr-body svg { width: 100%; height: 100%; } .badge-image-body { width: 100%; height: 100%; display: block; } diff --git a/apps/admin/src/views/BadgeEditor.tsx b/apps/admin/src/views/BadgeEditor.tsx index 72a7788..3ab6835 100644 --- a/apps/admin/src/views/BadgeEditor.tsx +++ b/apps/admin/src/views/BadgeEditor.tsx @@ -19,6 +19,12 @@ import { AlignEndHorizontal, AlignHorizontalDistributeCenter, AlignVerticalDistributeCenter, + AlignLeft, + AlignCenter, + AlignRight, + ArrowUpToLine, + ArrowDownToLine, + ChevronsUpDown, } from 'lucide-react'; import { deleteBadgeLayout, @@ -64,6 +70,18 @@ const QR_LABEL: Record = { static: 'Static value', }; +// Text alignment *within* an element's own box (not the box on the page). +const ALIGN_H: { v: BadgeTextElement['align_h']; label: string; Icon: typeof AlignLeft }[] = [ + { v: 'left', label: 'Align text left', Icon: AlignLeft }, + { v: 'center', label: 'Center text', Icon: AlignCenter }, + { v: 'right', label: 'Align text right', Icon: AlignRight }, +]; +const ALIGN_V: { v: BadgeTextElement['align_v']; label: string; Icon: typeof ArrowUpToLine }[] = [ + { v: 'top', label: 'Align text to top', Icon: ArrowUpToLine }, + { v: 'middle', label: 'Center text vertically', Icon: ChevronsUpDown }, + { v: 'bottom', label: 'Align text to bottom', Icon: ArrowDownToLine }, +]; + function newId(): string { return Math.random().toString(36).slice(2, 10) + Date.now().toString(36).slice(-4); } @@ -462,14 +480,23 @@ export function BadgeEditor() { commit({ ...doc, elements }); } - // Keyboard: Delete/Backspace removes the selection, Escape clears it — but - // only when focus is not in a text field (so typing in the panel is safe). + // Keyboard: Delete/Backspace removes the selection, Escape clears it, and + // Ctrl/Cmd+Z undoes / Ctrl+Y (or Ctrl/Cmd+Shift+Z) redoes — but only when + // focus is not in a text field (so typing or native field undo is safe). useEffect(() => { function onKey(e: KeyboardEvent) { const t = e.target as HTMLElement | null; const typing = !!t && (t.tagName === 'INPUT' || t.tagName === 'TEXTAREA' || t.tagName === 'SELECT' || t.isContentEditable); if (typing) return; - if ((e.key === 'Delete' || e.key === 'Backspace') && selectedIds.length > 0) { + const mod = e.ctrlKey || e.metaKey; + const key = e.key.toLowerCase(); + if (mod && key === 'z' && !e.shiftKey) { + e.preventDefault(); + undo(); + } else if ((mod && key === 'y') || (mod && key === 'z' && e.shiftKey)) { + e.preventDefault(); + redo(); + } else if ((e.key === 'Delete' || e.key === 'Backspace') && selectedIds.length > 0) { e.preventDefault(); deleteSelected(); } else if (e.key === 'Escape') { @@ -720,8 +747,8 @@ export function BadgeEditor() { - - + +
@@ -934,7 +961,7 @@ function BadgePropsPanel({ setDocPage({ page_width_mm: Math.max(1, n) })} /> setDocPage({ page_height_mm: Math.max(1, n) })} />
-

Select an element on the canvas to edit its properties. Shift-click to select several, then use the align tools. Press Del to remove.

+

Select an element on the canvas to edit its properties. Shift-click to select several, then use the align tools. Press Del to remove, Ctrl+Z to undo and Ctrl+Y to redo.

); @@ -1009,17 +1036,31 @@ function BadgePropsPanel({ Text color patchElement(t.id, { color: e.target.value })} /> -
- - - - {(['left', 'center', 'right'] as const).map((a) => ( - - ))} - - {(['top', 'middle', 'bottom'] as const).map((a) => ( - - ))} +
+ Style +
+ + +
+
+
+ Align text in box +
+ Horizontal +
+ {ALIGN_H.map(({ v, label, Icon }) => ( + + ))} +
+
+
+ Vertical +
+ {ALIGN_V.map(({ v, label, Icon }) => ( + + ))} +
+