AI-native design editor. Open-source Figma alternative.
Redesign variables dialog to match Figma's table layout
Danila Poyarkove3f8ff623eab
diff --git a/components.d.ts b/components.d.tsindex 6e5697368..06e1ede06 100644--- a/components.d.ts+++ b/components.d.ts@@ -34,6 +34,7 @@ declare module 'vue' {IconLucideCheck: typeof import('~icons/lucide/check')['default']IconLucideChevronDown: typeof import('~icons/lucide/chevron-down')['default']IconLucideChevronRight: typeof import('~icons/lucide/chevron-right')['default']+ IconLucideCircleDot: typeof import('~icons/lucide/circle-dot')['default']IconLucideEye: typeof import('~icons/lucide/eye')['default']IconLucideEyeOff: typeof import('~icons/lucide/eye-off')['default']IconLucideFile: typeof import('~icons/lucide/file')['default']diff --git a/src/components/VariablesDialog.vue b/src/components/VariablesDialog.vueindex 704bee6ba..769c07ab2 100644--- a/src/components/VariablesDialog.vue+++ b/src/components/VariablesDialog.vue@@ -19,10 +19,11 @@ import {import { colorToHexRaw } from '@/engine/color'import { useEditorStore } from '@/stores/editor'-import type { Variable, VariableType, Color } from '@/engine/scene-graph'+import type { Variable, Color, VariableCollectionMode } from '@/engine/scene-graph'const open = defineModel<boolean>('open', { default: false })const store = useEditorStore()+const searchTerm = ref('')const collections = computed(() => {void store.state.sceneVersion@@ -56,9 +57,17 @@ function commitRenameCollection(id: string, input: HTMLInputElement) {editingCollectionId.value = null}+const activeModes = computed(() => {+ const col = store.graph.variableCollections.get(activeTab.value)+ return col?.modes ?? []+})+const variables = computed(() => {if (!activeTab.value) return []- return store.graph.getVariablesForCollection(activeTab.value)+ const all = store.graph.getVariablesForCollection(activeTab.value)+ if (!searchTerm.value) return all+ const q = searchTerm.value.toLowerCase()+ return all.filter((v) => v.name.toLowerCase().includes(q))})const groupedVariables = computed(() => {@@ -73,12 +82,7 @@ const groupedVariables = computed(() => {return groups})-function activeCollection() {- return store.graph.variableCollections.get(activeTab.value)-}--function formatValue(variable: Variable): string {- const modeId = store.graph.getActiveModeId(variable.collectionId)+function formatModeValue(variable: Variable, modeId: string): string {const value = variable.valuesByMode[modeId]if (value === undefined) return '—'if (typeof value === 'object' && 'r' in value) return colorToHexRaw(value as Color)@@ -89,11 +93,21 @@ function formatValue(variable: Variable): string {return String(value)}-function getSwatchColor(variable: Variable): string | null {+function getModeSwatchColor(variable: Variable, modeId: string): string | null {if (variable.type !== 'COLOR') return null- const resolved = store.graph.resolveColorVariable(variable.id)- if (!resolved) return null- return `rgb(${Math.round(resolved.r * 255)}, ${Math.round(resolved.g * 255)}, ${Math.round(resolved.b * 255)})`+ const value = variable.valuesByMode[modeId]+ if (!value) return null++ if (typeof value === 'object' && 'aliasId' in value) {+ const resolved = store.graph.resolveColorVariable(variable.id)+ if (!resolved) return null+ return `rgb(${Math.round(resolved.r * 255)}, ${Math.round(resolved.g * 255)}, ${Math.round(resolved.b * 255)})`+ }+ if (typeof value === 'object' && 'r' in value) {+ const c = value as Color+ return `rgb(${Math.round(c.r * 255)}, ${Math.round(c.g * 255)}, ${Math.round(c.b * 255)})`+ }+ return null}function shortName(variable: Variable): string {@@ -108,9 +122,7 @@ function commitNameEdit(variable: Variable, newName: string) {}}-function commitValueEdit(variable: Variable, newValue: string) {- const modeId = store.graph.getActiveModeId(variable.collectionId)-+function commitValueEdit(variable: Variable, modeId: string, newValue: string) {if (variable.type === 'COLOR') {const hex = newValue.replace('#', '')if (/^[0-9a-fA-F]{6}$/.test(hex)) {@@ -130,24 +142,22 @@ function commitValueEdit(variable: Variable, newValue: string) {store.requestRender()}-function addVariable(type: VariableType) {- const collection = activeCollection()- if (!collection) return+function addVariable() {+ const col = store.graph.variableCollections.get(activeTab.value)+ if (!col) return- const defaults: Record<VariableType, import('@open-pencil/core').VariableValue> = {- COLOR: { r: 0, g: 0, b: 0, a: 1 },- FLOAT: 0,- STRING: '',- BOOLEAN: false+ const id = `var:${Date.now()}`+ const valuesByMode: Record<string, import('@open-pencil/core').VariableValue> = {}+ for (const mode of col.modes) {+ valuesByMode[mode.modeId] = { r: 0, g: 0, b: 0, a: 1 }}- const id = `var:${Date.now()}`store.graph.addVariable({id,- name: `New ${type.toLowerCase()}`,- type,- collectionId: collection.id,- valuesByMode: { [collection.defaultModeId]: defaults[type] },+ name: 'New variable',+ type: 'COLOR',+ collectionId: col.id,+ valuesByMode,description: '',hiddenFromPublishing: false})@@ -159,7 +169,7 @@ function addCollection() {store.graph.addCollection({id,name: 'New collection',- modes: [{ modeId: 'default', name: 'Default' }],+ modes: [{ modeId: 'default', name: 'Mode 1' }],defaultModeId: 'default',variableIds: []})@@ -171,6 +181,11 @@ function removeVariable(id: string) {store.graph.removeVariable(id)store.requestRender()}++function modeColumnWidth(modes: VariableCollectionMode[]): string {+ if (modes.length <= 1) return 'flex-1'+ return `w-[${Math.floor(100 / modes.length)}%]`+}</script><template>@@ -178,185 +193,197 @@ function removeVariable(id: string) {<DialogPortal><DialogOverlay class="fixed inset-0 z-40 bg-black/50" /><DialogContent- class="fixed left-1/2 top-1/2 z-50 flex h-[70vh] w-[640px] max-w-[90vw] -translate-x-1/2 -translate-y-1/2 flex-col rounded-xl border border-border bg-panel shadow-2xl outline-none"+ class="fixed left-1/2 top-1/2 z-50 flex h-[75vh] w-[800px] max-w-[90vw] -translate-x-1/2 -translate-y-1/2 flex-col rounded-xl border border-border bg-panel shadow-2xl outline-none">- <!-- Header -->- <div class="flex shrink-0 items-center justify-between border-b border-border px-4 py-3">- <DialogTitle class="text-sm font-semibold text-surface">Local variables</DialogTitle>- <div class="flex items-center gap-2">- <button- class="flex size-6 cursor-pointer items-center justify-center rounded border-none bg-transparent text-muted hover:bg-hover hover:text-surface"- title="Add collection"- @click="addCollection"- >- <icon-lucide-folder-plus class="size-4" />- </button>+ <div v-if="collections.length === 0" class="flex flex-1 flex-col">+ <!-- Header for empty state -->+ <div class="flex shrink-0 items-center justify-between border-b border-border px-4 py-3">+ <DialogTitle class="text-sm font-semibold text-surface">Local variables</DialogTitle><DialogCloseclass="flex size-6 cursor-pointer items-center justify-center rounded border-none bg-transparent text-muted hover:bg-hover hover:text-surface"><icon-lucide-x class="size-4" /></DialogClose></div>- </div>-- <div v-if="collections.length === 0" class="flex flex-1 items-center justify-center">- <div class="text-center">- <p class="text-sm text-muted">No variable collections</p>- <button- class="mt-2 cursor-pointer rounded bg-hover px-3 py-1.5 text-xs text-surface hover:bg-border"- @click="addCollection"- >- Create collection- </button>+ <div class="flex flex-1 items-center justify-center">+ <div class="text-center">+ <p class="text-sm text-muted">No variable collections</p>+ <button+ class="mt-2 cursor-pointer rounded bg-hover px-3 py-1.5 text-xs text-surface hover:bg-border"+ @click="addCollection"+ >+ Create collection+ </button>+ </div></div></div><template v-else><TabsRoot v-model="activeTab" class="flex flex-1 flex-col overflow-hidden">- <!-- Collection tabs -->- <TabsList- class="flex shrink-0 gap-0.5 overflow-x-auto border-b border-border px-3 py-1"- >- <template v-for="col in collections" :key="col.id">- <input- v-if="editingCollectionId === col.id"- data-collection-edit- class="w-24 rounded border border-accent bg-input px-2 py-0.5 text-xs text-surface outline-none"- :value="col.name"- @blur="commitRenameCollection(col.id, $event.target as HTMLInputElement)"- @keydown.enter="($event.target as HTMLInputElement).blur()"- @keydown.escape="editingCollectionId = null"- />- <TabsTrigger- v-else- :value="col.id"- class="cursor-pointer whitespace-nowrap rounded border-none px-2.5 py-1 text-xs text-muted data-[state=active]:bg-hover data-[state=active]:text-surface"- @dblclick="startRenameCollection(col.id)"- >- {{ col.name }}- <span class="ml-1 text-[10px] opacity-50">{{ col.variableIds.length }}</span>- </TabsTrigger>- </template>- </TabsList>+ <!-- Top bar: collection tabs + search + actions -->+ <div class="flex shrink-0 items-center border-b border-border">+ <TabsList class="flex flex-1 gap-0.5 overflow-x-auto px-3 py-1">+ <template v-for="col in collections" :key="col.id">+ <input+ v-if="editingCollectionId === col.id"+ data-collection-edit+ class="w-24 rounded border border-accent bg-input px-2 py-0.5 text-xs text-surface outline-none"+ :value="col.name"+ @blur="commitRenameCollection(col.id, $event.target as HTMLInputElement)"+ @keydown.enter="($event.target as HTMLInputElement).blur()"+ @keydown.escape="editingCollectionId = null"+ />+ <TabsTrigger+ v-else+ :value="col.id"+ class="cursor-pointer whitespace-nowrap rounded border-none px-2.5 py-1 text-xs text-muted data-[state=active]:bg-hover data-[state=active]:text-surface"+ @dblclick="startRenameCollection(col.id)"+ >+ {{ col.name }}+ </TabsTrigger>+ </template>+ </TabsList>- <!-- Table header -->- <div- class="flex shrink-0 items-center border-b border-border bg-surface/5 px-4 py-1.5 text-[10px] font-medium uppercase tracking-wider text-muted"- >- <span class="w-6" />- <span class="min-w-0 flex-1">Name</span>- <span class="w-32 text-right">Value</span>- <span class="w-8" />+ <div class="flex items-center gap-1.5 px-3">+ <div class="flex items-center gap-1 rounded border border-border px-2 py-0.5">+ <icon-lucide-search class="size-3 text-muted" />+ <input+ v-model="searchTerm"+ class="w-24 border-none bg-transparent text-xs text-surface outline-none placeholder:text-muted"+ placeholder="Search"+ />+ </div>+ <button+ class="flex size-6 cursor-pointer items-center justify-center rounded border-none bg-transparent text-muted hover:bg-hover hover:text-surface"+ title="Add collection"+ @click="addCollection"+ >+ <icon-lucide-folder-plus class="size-3.5" />+ </button>+ <DialogClose+ class="flex size-6 cursor-pointer items-center justify-center rounded border-none bg-transparent text-muted hover:bg-hover hover:text-surface"+ >+ <icon-lucide-x class="size-4" />+ </DialogClose>+ </div></div>- <!-- Variable rows -->+ <!-- Table --><TabsContentv-for="col in collections":key="col.id":value="col.id"- class="flex-1 overflow-y-auto outline-none"+ class="flex flex-1 flex-col overflow-hidden outline-none">- <template v-for="[group, vars] in groupedVariables" :key="group">+ <!-- Column headers -->+ <div class="flex shrink-0 border-b border-border text-[11px] font-medium text-muted">+ <div class="w-[200px] shrink-0 px-4 py-2">Name</div><div- v-if="group"- class="px-4 pt-3 pb-1 text-[10px] font-medium uppercase tracking-wider text-muted"+ v-for="mode in activeModes"+ :key="mode.modeId"+ class="flex-1 border-l border-border px-4 py-2">- {{ group }}+ {{ mode.name }}</div>- <div- v-for="v in vars"- :key="v.id"- class="group flex items-center gap-2 px-4 py-1.5 hover:bg-hover"- >- <!-- Type indicator -->- <div- v-if="v.type === 'COLOR'"- class="size-4 shrink-0 rounded border border-border"- :style="{ background: getSwatchColor(v) ?? '#000' }"- />- <icon-lucide-hash- v-else-if="v.type === 'FLOAT'"- class="size-4 shrink-0 text-muted"- />- <icon-lucide-type- v-else-if="v.type === 'STRING'"- class="size-4 shrink-0 text-muted"- />- <icon-lucide-toggle-left v-else class="size-4 shrink-0 text-muted" />+ <!-- Spacer for delete button column -->+ <div class="w-8 shrink-0" />+ </div>- <!-- Editable name -->- <EditableRoot- :default-value="shortName(v)"- class="min-w-0 flex-1"- @submit="commitNameEdit(v, $event)"+ <!-- Rows -->+ <div class="flex-1 overflow-y-auto">+ <template v-for="[group, vars] in groupedVariables" :key="group">+ <div+ v-if="group"+ class="border-b border-border/50 px-4 py-1.5 text-[10px] font-medium uppercase tracking-wider text-muted">- <EditableArea class="flex">- <EditablePreview class="min-w-0 flex-1 truncate text-xs text-surface" />- <EditableInput- class="min-w-0 flex-1 rounded border border-border bg-surface/10 px-1.5 py-0.5 text-xs text-surface outline-none"- />- </EditableArea>- </EditableRoot>-- <!-- Editable value -->- <EditableRoot- :default-value="formatValue(v)"- class="w-32 shrink-0"- @submit="commitValueEdit(v, $event)"+ {{ group }}+ </div>+ <div+ v-for="v in vars"+ :key="v.id"+ class="group flex items-center border-b border-border/30 hover:bg-hover/50">- <EditableArea class="flex justify-end">- <EditablePreview- class="w-full truncate text-right font-mono text-xs text-muted"+ <!-- Name column -->+ <div class="flex w-[200px] shrink-0 items-center gap-2 px-4 py-2">+ <icon-lucide-circle-dot+ v-if="v.type === 'COLOR'"+ class="size-3.5 shrink-0 text-muted"/>- <EditableInput- class="w-full rounded border border-border bg-surface/10 px-1.5 py-0.5 text-right font-mono text-xs text-surface outline-none"+ <icon-lucide-hash+ v-else-if="v.type === 'FLOAT'"+ class="size-3.5 shrink-0 text-muted"/>- </EditableArea>- </EditableRoot>+ <icon-lucide-type+ v-else-if="v.type === 'STRING'"+ class="size-3.5 shrink-0 text-muted"+ />+ <icon-lucide-toggle-left v-else class="size-3.5 shrink-0 text-muted" />+ <EditableRoot+ :default-value="shortName(v)"+ class="min-w-0 flex-1"+ @submit="commitNameEdit(v, $event)"+ >+ <EditableArea class="flex">+ <EditablePreview+ class="min-w-0 flex-1 cursor-text truncate text-xs text-surface"+ />+ <EditableInput+ class="min-w-0 flex-1 rounded border border-border bg-surface/10 px-1 py-0.5 text-xs text-surface outline-none"+ />+ </EditableArea>+ </EditableRoot>+ </div>- <!-- Delete -->- <button- class="flex size-5 cursor-pointer items-center justify-center rounded border-none bg-transparent text-muted opacity-0 transition-opacity group-hover:opacity-100 hover:text-surface"- @click="removeVariable(v.id)"- >- <icon-lucide-x class="size-3" />- </button>- </div>- </template>+ <!-- Value columns (one per mode) -->+ <div+ v-for="mode in activeModes"+ :key="mode.modeId"+ class="flex flex-1 items-center gap-2 border-l border-border/30 px-4 py-2"+ >+ <div+ v-if="v.type === 'COLOR'"+ class="size-5 shrink-0 rounded border border-border"+ :style="{ background: getModeSwatchColor(v, mode.modeId) ?? '#000' }"+ />+ <EditableRoot+ :default-value="formatModeValue(v, mode.modeId)"+ class="min-w-0 flex-1"+ @submit="commitValueEdit(v, mode.modeId, $event)"+ >+ <EditableArea class="flex">+ <EditablePreview+ class="min-w-0 flex-1 cursor-text truncate font-mono text-xs text-muted"+ />+ <EditableInput+ class="min-w-0 flex-1 rounded border border-border bg-surface/10 px-1 py-0.5 font-mono text-xs text-surface outline-none"+ />+ </EditableArea>+ </EditableRoot>+ </div>++ <!-- Delete -->+ <div class="flex w-8 shrink-0 items-center justify-center">+ <button+ class="flex size-5 cursor-pointer items-center justify-center rounded border-none bg-transparent text-muted opacity-0 transition-opacity group-hover:opacity-100 hover:text-surface"+ @click="removeVariable(v.id)"+ >+ <icon-lucide-x class="size-3" />+ </button>+ </div>+ </div>+ </template>+ </div>++ <!-- Footer: create variable -->+ <button+ class="flex w-full shrink-0 cursor-pointer items-center gap-1.5 border-t border-border bg-transparent px-4 py-2 text-xs text-muted hover:bg-hover hover:text-surface"+ @click="addVariable"+ >+ <icon-lucide-plus class="size-3.5" />+ Create variable+ </button></TabsContent></TabsRoot>-- <!-- Footer: add buttons -->- <div class="flex shrink-0 gap-1.5 border-t border-border px-4 py-2">- <button- class="flex cursor-pointer items-center gap-1.5 rounded border-none bg-transparent px-2 py-1 text-xs text-muted hover:bg-hover hover:text-surface"- @click="addVariable('COLOR')"- >- <div class="size-2.5 rounded-sm bg-current" />- Color- </button>- <button- class="flex cursor-pointer items-center gap-1.5 rounded border-none bg-transparent px-2 py-1 text-xs text-muted hover:bg-hover hover:text-surface"- @click="addVariable('FLOAT')"- >- <icon-lucide-hash class="size-2.5" />- Number- </button>- <button- class="flex cursor-pointer items-center gap-1.5 rounded border-none bg-transparent px-2 py-1 text-xs text-muted hover:bg-hover hover:text-surface"- @click="addVariable('STRING')"- >- <icon-lucide-type class="size-2.5" />- String- </button>- <button- class="flex cursor-pointer items-center gap-1.5 rounded border-none bg-transparent px-2 py-1 text-xs text-muted hover:bg-hover hover:text-surface"- @click="addVariable('BOOLEAN')"- >- <icon-lucide-toggle-left class="size-2.5" />- Bool- </button>- </div></template></DialogContent></DialogPortal>