AI-native design editor. Open-source Figma alternative.
feat(vue): add flip commands to canvas menu
Danila Poyarkovcc90c63952c0
diff --git a/packages/vue/src/editor/commands/registry.ts b/packages/vue/src/editor/commands/registry.tsindex 0f6138161..7a6c1f177 100644--- a/packages/vue/src/editor/commands/registry.ts+++ b/packages/vue/src/editor/commands/registry.ts@@ -48,6 +48,16 @@ export const EDITOR_COMMAND_METADATA = {keybinding: '$mod+Shift+KeyL',contextTestId: 'context-toggle-lock'},+ 'selection.flipHorizontal': {+ shortcut: '⇧H',+ keybinding: 'Shift+KeyH',+ contextTestId: 'context-flip-horizontal'+ },+ 'selection.flipVertical': {+ shortcut: '⇧V',+ keybinding: 'Shift+KeyV',+ contextTestId: 'context-flip-vertical'+ },'selection.moveToPage': {},'view.zoom100': { keybinding: '$mod+Digit0' },'view.zoomFit': { keybinding: ['$mod+Digit1', 'Shift+Digit1'] },diff --git a/packages/vue/src/editor/commands/selection.ts b/packages/vue/src/editor/commands/selection.tsindex e58d3de07..d6ee1cc08 100644--- a/packages/vue/src/editor/commands/selection.ts+++ b/packages/vue/src/editor/commands/selection.ts@@ -135,6 +135,22 @@ export function createSelectionCommands({enabled: capabilities.canToggleLock,run: () => editor.toggleLock()},+ 'selection.flipHorizontal': {+ id: 'selection.flipHorizontal',+ get label() {+ return t.value.flipHorizontal+ },+ enabled: capabilities.canFlip,+ run: () => editor.flipNodes([...selection.selectedIds.value], 'horizontal')+ },+ 'selection.flipVertical': {+ id: 'selection.flipVertical',+ get label() {+ return t.value.flipVertical+ },+ enabled: capabilities.canFlip,+ run: () => editor.flipNodes([...selection.selectedIds.value], 'vertical')+ },'selection.moveToPage': {id: 'selection.moveToPage',get label() {diff --git a/packages/vue/src/editor/commands/types.ts b/packages/vue/src/editor/commands/types.tsindex 5d2f3a8a1..df742f764 100644--- a/packages/vue/src/editor/commands/types.ts+++ b/packages/vue/src/editor/commands/types.ts@@ -18,6 +18,8 @@ export type EditorCommandId =| 'selection.sendToBack'| 'selection.toggleVisibility'| 'selection.toggleLock'+ | 'selection.flipHorizontal'+ | 'selection.flipVertical'| 'selection.moveToPage'| 'view.zoom100'| 'view.zoomFit'diff --git a/packages/vue/src/editor/menu-model/canvas.ts b/packages/vue/src/editor/menu-model/canvas.tsindex 17aa6cf49..65bfd9180 100644--- a/packages/vue/src/editor/menu-model/canvas.ts+++ b/packages/vue/src/editor/menu-model/canvas.ts@@ -33,7 +33,8 @@ const CANVAS_MENU_GROUPS = [['selection.moveToPageWhenAvailable', 'selection.bringToFront', 'selection.sendToBack'],['selection.group', 'selection.ungroupWhenGroup', 'selection.wrapInAutoLayout'],['selection.componentAction', 'selection.componentSetAction', 'selection.instanceActions'],- ['selection.toggleVisibility', 'selection.toggleLock']+ ['selection.toggleVisibility', 'selection.toggleLock'],+ ['selection.flipHorizontal', 'selection.flipVertical']] satisfies readonly CanvasMenuGroup[]function separator(): MenuSeparatorNode {diff --git a/packages/vue/src/editor/selection-capabilities/use.ts b/packages/vue/src/editor/selection-capabilities/use.tsindex 32131bb75..4fe44f42e 100644--- a/packages/vue/src/editor/selection-capabilities/use.ts+++ b/packages/vue/src/editor/selection-capabilities/use.ts@@ -33,6 +33,7 @@ export function useSelectionCapabilities() {canSendToBack: computed(() => hasSelection.value),canToggleVisibility: computed(() => hasSelection.value),canToggleLock: computed(() => hasSelection.value),+ canFlip: computed(() => hasSelection.value),canGoToMainComponent: computed(() => selection.isInstance.value),canCreateInstance: computed(() => selectedNode.value?.type === 'COMPONENT'),canMoveToPage: useSceneComputed(() => hasSelection.value && editor.graph.getPages().length > 1),diff --git a/packages/vue/src/i18n/messages.ts b/packages/vue/src/i18n/messages.tsindex 09d080044..1071ca3d5 100644--- a/packages/vue/src/i18n/messages.ts+++ b/packages/vue/src/i18n/messages.ts@@ -91,6 +91,8 @@ export const commandMessages = i18n('commands', {sendToBack: 'Send to back',showHide: 'Show/Hide',lockUnlock: 'Lock/Unlock',+ flipHorizontal: 'Flip horizontal',+ flipVertical: 'Flip vertical',moveToPage: 'Move to page',zoomTo100: 'Zoom to 100%',zoomToFit: 'Zoom to fit',diff --git a/packages/vue/src/locales/de.json b/packages/vue/src/locales/de.jsonindex 98cf07893..24a66e8c2 100644--- a/packages/vue/src/locales/de.json+++ b/packages/vue/src/locales/de.json@@ -63,7 +63,9 @@"zoomToSelection": "Auswahl einpassen","groupSelection": "Gruppieren","showHide": "Sichtbarkeit",- "lockUnlock": "Sperren"+ "lockUnlock": "Sperren",+ "flipHorizontal": "Horizontal spiegeln",+ "flipVertical": "Vertikal spiegeln"},"tools": {"move": "Verschieben",diff --git a/packages/vue/src/locales/es.json b/packages/vue/src/locales/es.jsonindex 5da9c7c3f..27787b2b5 100644--- a/packages/vue/src/locales/es.json+++ b/packages/vue/src/locales/es.json@@ -63,7 +63,9 @@"zoomToSelection": "Zoom a selección","groupSelection": "Agrupar","showHide": "Visibilidad",- "lockUnlock": "Bloqueo"+ "lockUnlock": "Bloqueo",+ "flipHorizontal": "Voltear horizontalmente",+ "flipVertical": "Voltear verticalmente"},"tools": {"move": "Mover",diff --git a/packages/vue/src/locales/fr.json b/packages/vue/src/locales/fr.jsonindex 944343741..602b4424b 100644--- a/packages/vue/src/locales/fr.json+++ b/packages/vue/src/locales/fr.json@@ -63,7 +63,9 @@"zoomToSelection": "Zoom sur la sélection","groupSelection": "Grouper","showHide": "Visibilité",- "lockUnlock": "Verrouillage"+ "lockUnlock": "Verrouillage",+ "flipHorizontal": "Retourner horizontalement",+ "flipVertical": "Retourner verticalement"},"tools": {"move": "Déplacer",diff --git a/packages/vue/src/locales/it.json b/packages/vue/src/locales/it.jsonindex bfadc3168..d5213d032 100644--- a/packages/vue/src/locales/it.json+++ b/packages/vue/src/locales/it.json@@ -63,7 +63,9 @@"zoomToSelection": "Zoom sulla selezione","groupSelection": "Raggruppa","showHide": "Visibilità",- "lockUnlock": "Blocco"+ "lockUnlock": "Blocco",+ "flipHorizontal": "Rifletti orizzontalmente",+ "flipVertical": "Rifletti verticalmente"},"tools": {"move": "Sposta",diff --git a/packages/vue/src/locales/pl.json b/packages/vue/src/locales/pl.jsonindex c2716f6c9..972dfb2df 100644--- a/packages/vue/src/locales/pl.json+++ b/packages/vue/src/locales/pl.json@@ -63,7 +63,9 @@"zoomToSelection": "Zoom do zaznaczenia","groupSelection": "Grupuj","showHide": "Widoczność",- "lockUnlock": "Blokada"+ "lockUnlock": "Blokada",+ "flipHorizontal": "Odbij poziomo",+ "flipVertical": "Odbij pionowo"},"tools": {"move": "Przesuń",diff --git a/packages/vue/src/locales/ru.json b/packages/vue/src/locales/ru.jsonindex 1cbbb5978..73c7286be 100644--- a/packages/vue/src/locales/ru.json+++ b/packages/vue/src/locales/ru.json@@ -63,7 +63,9 @@"zoomToSelection": "Масштаб по выделению","groupSelection": "Сгруппировать","showHide": "Видимость",- "lockUnlock": "Блокировка"+ "lockUnlock": "Блокировка",+ "flipHorizontal": "Отразить по горизонтали",+ "flipVertical": "Отразить по вертикали"},"tools": {"move": "Перемещение",diff --git a/packages/vue/src/locales/zh-CN.json b/packages/vue/src/locales/zh-CN.jsonindex 4c8368c38..d254bc076 100644--- a/packages/vue/src/locales/zh-CN.json+++ b/packages/vue/src/locales/zh-CN.json@@ -63,7 +63,9 @@"zoomToSelection": "适应所选内容","groupSelection": "成组","showHide": "切换可见性",- "lockUnlock": "切换锁定"+ "lockUnlock": "切换锁定",+ "flipHorizontal": "水平翻转",+ "flipVertical": "垂直翻转"},"tools": {"move": "移动",diff --git a/src/app/shell/keyboard/registry.ts b/src/app/shell/keyboard/registry.tsindex 5d20b4471..566056777 100644--- a/src/app/shell/keyboard/registry.ts+++ b/src/app/shell/keyboard/registry.ts@@ -77,7 +77,9 @@ export function registerKeyboardShortcuts(options: KeyboardShortcutOptions) {'selection.detachInstance','selection.createComponentSet','selection.toggleVisibility',- 'selection.toggleLock'+ 'selection.toggleLock',+ 'selection.flipHorizontal',+ 'selection.flipVertical'),{id: 'export-selection-png',diff --git a/tests/engine/vue/editor/menu-model/canvas.test.ts b/tests/engine/vue/editor/menu-model/canvas.test.tsnew file mode 100644index 000000000..3b218ae8e--- /dev/null+++ b/tests/engine/vue/editor/menu-model/canvas.test.ts@@ -0,0 +1,74 @@+import { describe, expect, test } from 'bun:test'+import { computed, ref } from 'vue'++import type { EditorCommandId } from '@open-pencil/vue'+import { buildCanvasContextMenu } from '#vue/editor/menu-model/canvas'+import type { CanvasMenuOptions } from '#vue/editor/menu-model/canvas'++function selection(overrides: Partial<CanvasMenuOptions['selection']> = {}) {+ return {+ hasSelection: ref(true),+ isGroup: ref(false),+ isComponent: ref(false),+ isInstance: ref(false),+ canCreateComponentSet: ref(false),+ ...overrides+ } as CanvasMenuOptions['selection']+}++function options(overrides: Partial<CanvasMenuOptions> = {}): CanvasMenuOptions {+ return {+ commandMenuItem(id: EditorCommandId) {+ return { id, label: id }+ },+ otherPages: [],+ moveSelectionToPage: (pageId: string) => pageId,+ selection: selection(),+ t: { moveToPage: 'Move to page' },+ ...overrides+ } as CanvasMenuOptions+}++function itemIds(menu: ReturnType<typeof buildCanvasContextMenu>) {+ return menu.map((item) => (item.separator ? '---' : item.id ?? item.label))+}++describe('buildCanvasContextMenu', () => {+ test('keeps the default selection menu in semantic groups', () => {+ expect(itemIds(buildCanvasContextMenu(options()))).toEqual([+ 'selection.duplicate',+ 'selection.delete',+ '---',+ 'selection.bringToFront',+ 'selection.sendToBack',+ '---',+ 'selection.group',+ 'selection.wrapInAutoLayout',+ '---',+ 'selection.createComponent',+ '---',+ 'selection.toggleVisibility',+ 'selection.toggleLock',+ '---',+ 'selection.flipHorizontal',+ 'selection.flipVertical'+ ])+ })++ test('shows instance actions only for instances', () => {+ expect(+ itemIds(+ buildCanvasContextMenu(+ options({ selection: selection({ isInstance: computed(() => true) }) })+ )+ )+ ).toContain('selection.detachInstance')+ })++ test('does not emit empty leading or repeated separators', () => {+ const ids = itemIds(buildCanvasContextMenu(options({ otherPages: [] })))+ expect(ids[0]).not.toBe('---')+ expect(ids.at(-1)).not.toBe('---')+ expect(ids.join(',')).not.toContain('---,---')+ })+})