AI-native design editor. Open-source Figma alternative.
Self-review fixes: VueUse adoption, tailwind-variants recipes
Danila Poyarkovd3aa5110565f
diff --git a/src/components/CodePanel.vue b/src/components/CodePanel.vueindex a6d52685e..03c71ec0f 100644--- a/src/components/CodePanel.vue+++ b/src/components/CodePanel.vue@@ -3,7 +3,7 @@ import Prism from 'prismjs'import 'prismjs/components/prism-jsx'import { ScrollAreaRoot, ScrollAreaScrollbar, ScrollAreaThumb, ScrollAreaViewport } from 'reka-ui'import { useClipboard } from '@vueuse/core'-import { computed, ref, watch } from 'vue'+import { computed, ref } from 'vue'import { selectionToJSX } from '@open-pencil/core'import { useEditor, useSceneComputed } from '@open-pencil/vue'@@ -11,8 +11,7 @@ import { useEditor, useSceneComputed } from '@open-pencil/vue'import type { JSXFormat } from '@open-pencil/core'const store = useEditor()-const { copy } = useClipboard()-const copied = ref(false)+const { copy, copied } = useClipboard({ copiedDuring: 2000 })const jsxFormat = ref<JSXFormat>('openpencil')function toggleFormat() {@@ -31,18 +30,9 @@ const highlightedLines = computed(() => {return jsxCode.value.split('\n').map((line) => Prism.highlight(line, grammar, 'jsx'))})-let copyTimeout: ReturnType<typeof setTimeout> | undefined-function copyCode() {copy(jsxCode.value)- copied.value = true- clearTimeout(copyTimeout)- copyTimeout = setTimeout(() => (copied.value = false), 2000)}--watch(jsxCode, () => {- copied.value = false-})</script><template>diff --git a/src/components/CollabPanel.vue b/src/components/CollabPanel.vueindex fd098ee76..a2d5d5c1a 100644--- a/src/components/CollabPanel.vue+++ b/src/components/CollabPanel.vue@@ -1,6 +1,6 @@<script setup lang="ts">import { useClipboard } from '@vueuse/core'-import { ref, computed } from 'vue'+import { computed, ref } from 'vue'import { useRoute, useRouter } from 'vue-router'import {PopoverRoot,@@ -22,11 +22,10 @@ import { initials } from '@/utils/text'const route = useRoute()const router = useRouter()const collab = useCollabInjected()-const { copy } = useClipboard()+const { copy, copied } = useClipboard({ copiedDuring: 2000 })const joinInput = ref('')const nameDraft = ref(collab?.state.value.localName ?? '')-const copied = ref(false)const pendingRoomId = (route.params.roomId as string) || nullconst popoverOpen = ref(!!pendingRoomId)@@ -45,10 +44,6 @@ function copyLink() {if (!shareUrl.value) returncopy(shareUrl.value)toast.show('Link copied to clipboard')- copied.value = true- setTimeout(() => {- copied.value = false- }, 2000)}function onShare() {diff --git a/src/components/properties/AppearanceSection.vue b/src/components/properties/AppearanceSection.vueindex 9876bcf98..115f4001a 100644--- a/src/components/properties/AppearanceSection.vue+++ b/src/components/properties/AppearanceSection.vue@@ -1,6 +1,7 @@<script setup lang="ts">import ScrubInput from '@/components/ScrubInput.vue'import Tip from '@/components/Tip.vue'+import { sectionWrapper } from '@/components/ui/section'import { AppearanceControlsRoot } from '@open-pencil/vue'</script>@@ -22,7 +23,7 @@ import { AppearanceControlsRoot } from '@open-pencil/vue'commitCornerProp}">- <div data-test-id="appearance-section" class="border-b border-border px-3 py-2">+ <div data-test-id="appearance-section" :class="sectionWrapper()"><div class="mb-1.5 flex items-center justify-between"><label class="text-[11px] text-muted">Appearance</label><Tip label="Toggle visibility">diff --git a/src/components/properties/EffectsSection.vue b/src/components/properties/EffectsSection.vueindex 3ea22f29c..0af515d87 100644--- a/src/components/properties/EffectsSection.vue+++ b/src/components/properties/EffectsSection.vue@@ -3,6 +3,8 @@ import { ref } from 'vue'import AppSelect from '@/components/AppSelect.vue'import ColorInput from '@/components/ColorInput.vue'import ScrubInput from '@/components/ScrubInput.vue'+import { iconButton } from '@/components/ui/icon-button'+import { sectionLabel, sectionWrapper } from '@/components/ui/section'import { PropertyListRoot, useEditor } from '@open-pencil/vue'import { colorToCSS } from '@open-pencil/core'@@ -113,12 +115,12 @@ function toggleExpand(index: number) {prop-key="effects"label="Effects">- <div data-test-id="effects-section" class="border-b border-border px-3 py-2">+ <div data-test-id="effects-section" :class="sectionWrapper()"><div class="flex items-center justify-between">- <label class="mb-1 block text-[11px] text-muted">Effects</label>+ <label :class="sectionLabel()">Effects</label><buttondata-test-id="effects-section-add"- class="flex size-5 cursor-pointer items-center justify-center rounded border-none bg-transparent text-sm leading-none text-muted hover:bg-hover hover:text-surface"+ :class="iconButton()"@click="add(defaultEffect())">+@@ -162,12 +164,7 @@ function toggleExpand(index: number) {<icon-lucide-eye v-if="effect.visible" class="size-3.5" /><icon-lucide-eye-off v-else class="size-3.5" /></button>- <button- class="flex size-5 cursor-pointer items-center justify-center rounded border-none bg-transparent text-sm leading-none text-muted hover:bg-hover hover:text-surface"- @click="handleRemove(remove, i)"- >- −- </button>+ <button :class="iconButton()" @click="handleRemove(remove, i)">−</button></div><!-- Expanded controls inline -->diff --git a/src/components/properties/ExportSection.vue b/src/components/properties/ExportSection.vueindex 0b7e9df7b..a7b801881 100644--- a/src/components/properties/ExportSection.vue+++ b/src/components/properties/ExportSection.vue@@ -1,7 +1,9 @@<script setup lang="ts">-import { ref, computed, watch, onUnmounted } from 'vue'+import { ref, computed, watch, onScopeDispose } from 'vue'import AppSelect from '@/components/AppSelect.vue'+import { iconButton } from '@/components/ui/icon-button'+import { sectionLabel, sectionWrapper } from '@/components/ui/section'import { useEditorStore } from '@/stores/editor'import { ExportControlsRoot } from '@open-pencil/vue'@@ -61,7 +63,7 @@ const previewKey = computed(watch(() => showPreview.value, updatePreview, { flush: 'post' })watch(previewKey, updatePreview, { flush: 'post' })-onUnmounted(() => {+onScopeDispose(() => {if (previewUrl.value) URL.revokeObjectURL(previewUrl.value)})</script>@@ -70,14 +72,10 @@ onUnmounted(() => {<ExportControlsRootv-slot="{ settings, nodeName, addSetting, removeSetting, updateScale, updateFormat }">- <div data-test-id="export-section" class="border-b border-border px-3 py-2">+ <div data-test-id="export-section" :class="sectionWrapper()"><div class="flex items-center justify-between">- <label class="mb-1 block text-[11px] text-muted">Export</label>- <button- data-test-id="export-section-add"- class="flex size-5 cursor-pointer items-center justify-center rounded border-none bg-transparent text-sm leading-none text-muted hover:bg-hover hover:text-surface"- @click="addSetting"- >+ <label :class="sectionLabel()">Export</label>+ <button data-test-id="export-section-add" :class="iconButton()" @click="addSetting">+</button></div>@@ -100,12 +98,7 @@ onUnmounted(() => {:options="FORMAT_OPTIONS"@update:model-value="updateFormat(i, $event as ExportFormat)"/>- <button- class="flex size-5 shrink-0 cursor-pointer items-center justify-center rounded border-none bg-transparent text-sm leading-none text-muted hover:bg-hover hover:text-surface"- @click="removeSetting(i)"- >- −- </button>+ <button :class="iconButton({ class: 'shrink-0' })" @click="removeSetting(i)">−</button></div><buttondiff --git a/src/components/properties/FillSection.vue b/src/components/properties/FillSection.vueindex 66c8557a0..dfa419379 100644--- a/src/components/properties/FillSection.vue+++ b/src/components/properties/FillSection.vue@@ -16,6 +16,8 @@ import {import FillPicker from '@/components/FillPicker.vue'import ScrubInput from '@/components/ScrubInput.vue'import Tip from '@/components/Tip.vue'+import { iconButton } from '@/components/ui/icon-button'+import { sectionLabel, sectionWrapper } from '@/components/ui/section'import { PropertyListRoot, useEditor } from '@open-pencil/vue'import { DEFAULT_SHAPE_FILL } from '@/constants'import { colorToCSS, colorToHexRaw } from '@open-pencil/core'@@ -61,12 +63,12 @@ const filteredVariables = computed(() => {prop-key="fills"label="Fill">- <div data-test-id="fill-section" class="border-b border-border px-3 py-2">+ <div data-test-id="fill-section" :class="sectionWrapper()"><div class="flex items-center justify-between">- <label class="mb-1 block text-[11px] text-muted">Fill</label>+ <label :class="sectionLabel()">Fill</label><buttondata-test-id="fill-section-add"- class="flex size-5 cursor-pointer items-center justify-center rounded border-none bg-transparent text-sm leading-none text-muted hover:bg-hover hover:text-surface"+ :class="iconButton()"@click="add({ ...DEFAULT_SHAPE_FILL })">+@@ -177,12 +179,7 @@ const filteredVariables = computed(() => {<icon-lucide-eye v-if="fill.visible" class="size-3.5" /><icon-lucide-eye-off v-else class="size-3.5" /></button>- <button- class="flex size-5 cursor-pointer items-center justify-center rounded border-none bg-transparent text-sm leading-none text-muted hover:bg-hover hover:text-surface"- @click="remove(i)"- >- −- </button>+ <button :class="iconButton()" @click="remove(i)">−</button></div></div></PropertyListRoot>diff --git a/src/components/properties/LayoutSection.vue b/src/components/properties/LayoutSection.vueindex 85ffbbe73..99760d388 100644--- a/src/components/properties/LayoutSection.vue+++ b/src/components/properties/LayoutSection.vue@@ -2,6 +2,7 @@import AppSelect from '@/components/AppSelect.vue'import ScrubInput from '@/components/ScrubInput.vue'import Tip from '@/components/Tip.vue'+import { sectionWrapper } from '@/components/ui/section'import { LayoutControlsRoot, useEditor } from '@open-pencil/vue'const store = useEditor()@@ -36,7 +37,7 @@ const store = useEditor()toggleIndividualPadding}">- <div data-test-id="layout-section" class="border-b border-border px-3 py-2">+ <div data-test-id="layout-section" :class="sectionWrapper()"><label class="mb-1.5 block text-[11px] text-muted">Layout</label><div class="flex gap-1.5"><div class="flex min-w-0 flex-1 items-center gap-1">@@ -73,7 +74,7 @@ const store = useEditor()</div><template v-if="node.type === 'FRAME'">- <div class="border-b border-border px-3 py-2">+ <div :class="sectionWrapper()"><div class="flex items-center justify-between"><label class="mb-1.5 block text-[11px] text-muted">Auto layout</label><Tip v-if="node.layoutMode === 'NONE'" label="Add auto layout (Shift+A)">@@ -277,7 +278,7 @@ const store = useEditor()</div><!-- Clip content -->- <div class="border-b border-border px-3 py-2">+ <div :class="sectionWrapper()"><label class="flex cursor-pointer items-center gap-2 text-xs text-surface"><inputtype="checkbox"diff --git a/src/components/properties/PageSection.vue b/src/components/properties/PageSection.vueindex 894f9823a..26428ee25 100644--- a/src/components/properties/PageSection.vue+++ b/src/components/properties/PageSection.vue@@ -1,11 +1,12 @@<script setup lang="ts">import ColorInput from '@/components/ColorInput.vue'+import { sectionWrapper } from '@/components/ui/section'import { PageControlsRoot } from '@open-pencil/vue'</script><template><PageControlsRoot v-slot="{ pageColor, setPageColor }">- <div data-test-id="page-section" class="border-b border-border px-3 py-2">+ <div data-test-id="page-section" :class="sectionWrapper()"><label class="mb-1.5 block text-[11px] text-muted">Page</label><ColorInput :color="pageColor" editable @update="setPageColor" /></div>diff --git a/src/components/properties/PositionSection.vue b/src/components/properties/PositionSection.vueindex 676da30c6..d6f1d1eb0 100644--- a/src/components/properties/PositionSection.vue+++ b/src/components/properties/PositionSection.vue@@ -3,6 +3,8 @@ import { computed } from 'vue'import ScrubInput from '@/components/ScrubInput.vue'import Tip from '@/components/Tip.vue'+import { iconButton } from '@/components/ui/icon-button'+import { sectionWrapper } from '@/components/ui/section'import { useNodeProps } from '@open-pencil/vue'const {@@ -31,7 +33,7 @@ const ids = computed(() => nodes.value.map((n) => n.id))</script><template>- <div v-if="active" data-test-id="position-section" class="border-b border-border px-3 py-2">+ <div v-if="active" data-test-id="position-section" :class="sectionWrapper()"><label class="mb-1.5 block text-[11px] text-muted">Position</label><!-- Alignment buttons -->@@ -39,7 +41,7 @@ const ids = computed(() => nodes.value.map((n) => n.id))<div class="flex gap-0.5"><Tip label="Align left"><button- class="flex size-7 cursor-pointer items-center justify-center rounded border border-border bg-input text-muted hover:bg-hover hover:text-surface"+ :class="iconButton({ size: 'md' })"data-test-id="position-align-left"@click="store.alignNodes(ids, 'horizontal', 'min')">@@ -48,7 +50,7 @@ const ids = computed(() => nodes.value.map((n) => n.id))</Tip><Tip label="Align center horizontally"><button- class="flex size-7 cursor-pointer items-center justify-center rounded border border-border bg-input text-muted hover:bg-hover hover:text-surface"+ :class="iconButton({ size: 'md' })"data-test-id="position-align-center-h"@click="store.alignNodes(ids, 'horizontal', 'center')">@@ -57,7 +59,7 @@ const ids = computed(() => nodes.value.map((n) => n.id))</Tip><Tip label="Align right"><button- class="flex size-7 cursor-pointer items-center justify-center rounded border border-border bg-input text-muted hover:bg-hover hover:text-surface"+ :class="iconButton({ size: 'md' })"data-test-id="position-align-right"@click="store.alignNodes(ids, 'horizontal', 'max')">@@ -68,7 +70,7 @@ const ids = computed(() => nodes.value.map((n) => n.id))<div class="flex gap-0.5"><Tip label="Align top"><button- class="flex size-7 cursor-pointer items-center justify-center rounded border border-border bg-input text-muted hover:bg-hover hover:text-surface"+ :class="iconButton({ size: 'md' })"data-test-id="position-align-top"@click="store.alignNodes(ids, 'vertical', 'min')">@@ -77,7 +79,7 @@ const ids = computed(() => nodes.value.map((n) => n.id))</Tip><Tip label="Align center vertically"><button- class="flex size-7 cursor-pointer items-center justify-center rounded border border-border bg-input text-muted hover:bg-hover hover:text-surface"+ :class="iconButton({ size: 'md' })"data-test-id="position-align-center-v"@click="store.alignNodes(ids, 'vertical', 'center')">@@ -86,7 +88,7 @@ const ids = computed(() => nodes.value.map((n) => n.id))</Tip><Tip label="Align bottom"><button- class="flex size-7 cursor-pointer items-center justify-center rounded border border-border bg-input text-muted hover:bg-hover hover:text-surface"+ :class="iconButton({ size: 'md' })"data-test-id="position-align-bottom"@click="store.alignNodes(ids, 'vertical', 'max')">@@ -147,7 +149,7 @@ const ids = computed(() => nodes.value.map((n) => n.id))</ScrubInput><Tip label="Flip horizontal"><button- class="flex size-7 shrink-0 cursor-pointer items-center justify-center rounded border border-border bg-input text-muted hover:bg-hover hover:text-surface"+ :class="iconButton({ size: 'md', class: 'shrink-0' })"data-test-id="position-flip-horizontal"@click="store.flipNodes(ids, 'horizontal')">@@ -156,7 +158,7 @@ const ids = computed(() => nodes.value.map((n) => n.id))</Tip><Tip label="Flip vertical"><button- class="flex size-7 shrink-0 cursor-pointer items-center justify-center rounded border border-border bg-input text-muted hover:bg-hover hover:text-surface"+ :class="iconButton({ size: 'md', class: 'shrink-0' })"data-test-id="position-flip-vertical"@click="store.flipNodes(ids, 'vertical')">@@ -165,7 +167,7 @@ const ids = computed(() => nodes.value.map((n) => n.id))</Tip><Tip label="Rotate 90°"><button- class="flex size-7 shrink-0 cursor-pointer items-center justify-center rounded border border-border bg-input text-muted hover:bg-hover hover:text-surface"+ :class="iconButton({ size: 'md', class: 'shrink-0' })"data-test-id="position-rotate-90"@click="store.rotateNodes(ids, 90)">diff --git a/src/components/properties/StrokeSection.vue b/src/components/properties/StrokeSection.vueindex 4e60b9998..684af8c75 100644--- a/src/components/properties/StrokeSection.vue+++ b/src/components/properties/StrokeSection.vue@@ -12,6 +12,8 @@ import AppSelect from '@/components/AppSelect.vue'import ColorInput from '@/components/ColorInput.vue'import ScrubInput from '@/components/ScrubInput.vue'import Tip from '@/components/Tip.vue'+import { iconButton } from '@/components/ui/icon-button'+import { sectionLabel, sectionWrapper } from '@/components/ui/section'import { PropertyListRoot, useEditor } from '@open-pencil/vue'import { menuContent, menuItem } from '@/components/ui/menu'@@ -148,12 +150,12 @@ const DEFAULT_STROKE: Stroke = {prop-key="strokes"label="Stroke">- <div data-test-id="stroke-section" class="border-b border-border px-3 py-2">+ <div data-test-id="stroke-section" :class="sectionWrapper()"><div class="flex items-center justify-between">- <label class="mb-1 block text-[11px] text-muted">Stroke</label>+ <label :class="sectionLabel()">Stroke</label><buttondata-test-id="stroke-section-add"- class="flex size-5 cursor-pointer items-center justify-center rounded border-none bg-transparent text-sm leading-none text-muted hover:bg-hover hover:text-surface"+ :class="iconButton()"@click="add(DEFAULT_STROKE)">+@@ -182,12 +184,7 @@ const DEFAULT_STROKE: Stroke = {<icon-lucide-eye v-if="stroke.visible" class="size-3.5" /><icon-lucide-eye-off v-else class="size-3.5" /></button>- <button- class="flex size-5 shrink-0 cursor-pointer items-center justify-center rounded border-none bg-transparent text-sm leading-none text-muted hover:bg-hover hover:text-surface"- @click="remove(i)"- >- −- </button>+ <button :class="iconButton({ class: 'shrink-0' })" @click="remove(i)">−</button></div><!-- Stroke details -->diff --git a/src/components/properties/TypographySection.vue b/src/components/properties/TypographySection.vueindex faea6d13c..086afe6d4 100644--- a/src/components/properties/TypographySection.vue+++ b/src/components/properties/TypographySection.vue@@ -3,6 +3,7 @@ import AppSelect from '@/components/AppSelect.vue'import FontPicker from '@/components/FontPicker.vue'import ScrubInput from '@/components/ScrubInput.vue'import Tip from '@/components/Tip.vue'+import { sectionWrapper } from '@/components/ui/section'import { loadFont } from '@/engine/fonts'import { TypographyControlsRoot } from '@open-pencil/vue'import { ToggleGroupItem, ToggleGroupRoot, type AcceptableValue } from 'reka-ui'@@ -10,7 +11,7 @@ import { ToggleGroupItem, ToggleGroupRoot, type AcceptableValue } from 'reka-ui'<template><TypographyControlsRoot v-slot="ctx" :load-font="loadFont">- <div data-test-id="typography-section" class="border-b border-border px-3 py-2">+ <div data-test-id="typography-section" :class="sectionWrapper()"><label class="mb-1.5 block text-[11px] text-muted">Typography</label><div class="mb-1.5 flex items-center gap-1.5">diff --git a/src/components/properties/VariablesSection.vue b/src/components/properties/VariablesSection.vueindex 9414c9e9b..929d8ed99 100644--- a/src/components/properties/VariablesSection.vue+++ b/src/components/properties/VariablesSection.vue@@ -1,5 +1,6 @@<script setup lang="ts">import Tip from '@/components/Tip.vue'+import { sectionWrapper } from '@/components/ui/section'import { VariablesIndicatorRoot } from '@open-pencil/vue'const emit = defineEmits<{ openDialog: [] }>()@@ -7,7 +8,7 @@ const emit = defineEmits<{ openDialog: [] }>()<template><VariablesIndicatorRoot v-slot="{ variableCount, collectionCount, hasVariables }">- <div data-test-id="variables-section" class="border-b border-border px-3 py-2">+ <div data-test-id="variables-section" :class="sectionWrapper()"><div class="flex items-center justify-between"><label class="text-[11px] font-medium text-surface">Variables</label><Tip label="Open variables">diff --git a/src/components/ui/icon-button.ts b/src/components/ui/icon-button.tsnew file mode 100644index 000000000..01cb70359--- /dev/null+++ b/src/components/ui/icon-button.ts@@ -0,0 +1,12 @@+import { tv } from 'tailwind-variants'++export const iconButton = tv({+ base: 'flex cursor-pointer items-center justify-center rounded border-none bg-transparent text-muted hover:bg-hover hover:text-surface',+ variants: {+ size: {+ sm: 'size-5 text-sm leading-none',+ md: 'size-7 border border-border bg-input'+ }+ },+ defaultVariants: { size: 'sm' }+})diff --git a/src/components/ui/section.ts b/src/components/ui/section.tsnew file mode 100644index 000000000..e488ec3e3--- /dev/null+++ b/src/components/ui/section.ts@@ -0,0 +1,9 @@+import { tv } from 'tailwind-variants'++export const sectionWrapper = tv({+ base: 'border-b border-border px-3 py-2'+})++export const sectionLabel = tv({+ base: 'mb-1 block text-[11px] text-muted'+})diff --git a/src/stores/editor.ts b/src/stores/editor.tsindex 350c8f29d..3d6f6ac81 100644--- a/src/stores/editor.ts+++ b/src/stores/editor.ts@@ -1,3 +1,4 @@+import { useDebounceFn } from '@vueuse/core'import { shallowReactive, shallowRef, computed, watch } from 'vue'import { IS_TAURI, CANVAS_BG_COLOR } from '@/constants'@@ -72,29 +73,28 @@ export function createEditorStore() {let filePath: string | null = nulllet downloadName: string | null = nulllet savedVersion = 0- let autosaveTimer: ReturnType<typeof setTimeout> | undefinedlet lastWriteTime = 0let unwatchFile: (() => void) | null = nullconst AUTOSAVE_DELAY = 3000+ const debouncedAutosave = useDebounceFn(async () => {+ if (state.sceneVersion === savedVersion) return+ if (!state.autosaveEnabled) return+ try {+ await writeFile(await buildFigFile())+ } catch (e) {+ console.warn('Autosave failed:', e)+ }+ }, AUTOSAVE_DELAY)+watch(() => state.sceneVersion,(version) => {if (version === savedVersion) returnif (!state.autosaveEnabled) returnif (!fileHandle && !filePath) return- clearTimeout(autosaveTimer)- // oxlint-disable-next-line typescript/no-misused-promises- autosaveTimer = setTimeout(async () => {- if (state.sceneVersion === savedVersion) return- if (!state.autosaveEnabled) return- try {- await writeFile(await buildFigFile())- } catch (e) {- console.warn('Autosave failed:', e)- }- }, AUTOSAVE_DELAY)+ void debouncedAutosave()})