Skip to content

AI-native design editor. Open-source Figma alternative.

Extract Vue SDK editor controls and pickers

Danila Poyarkov74bb11957925
diff --git a/SDK-PLAN.md b/SDK-PLAN.md
index 2c810552f..7587a2db0 100644
--- a/SDK-PLAN.md
+++ b/SDK-PLAN.md
@@ -50,12 +50,12 @@ OpenPencil app becomes a styled composition of these primitives.
|-----|------|-----------|
| `useNodeProps()` | Composable | Selection-aware property editing with undo |
| `PositionControls` | Component | x, y, w, h, rotation, alignment actions |
-| `FillList` | Component | Fill array CRUD, variable binding |
-| `StrokeList` | Component | Stroke array CRUD, side/weight |
-| `EffectList` | Component | Effect array CRUD |
-| `AppearanceControls` | Component | Corner radius, opacity, blend, visibility |
-| `TypographyControls` | Component | Font family/weight/size, alignment, decoration |
-| `LayoutControls` | Component | Auto-layout/grid, sizing, padding, alignment |
+| `FillControlsRoot` | Component | fill CRUD, variable binding helpers |
+| `StrokeControlsRoot` | Component | stroke align/side/weight helpers |
+| `EffectsControlsRoot` | Component | effect defaults, scrub/commit helpers |
+| `AppearanceControlsRoot` | Component | corner radius, opacity, visibility helpers |
+| `TypographyControlsRoot` | Component | font family/weight/size, alignment, decoration helpers |
+| `LayoutControlsRoot` | Component | auto-layout/grid, sizing, padding, alignment helpers |
| `ExportControls` | Component | Format/scale, export trigger |
| `PageControls` | Component | Page background color |
| `VariablesIndicator` | Component | Variable count |
@@ -76,7 +76,7 @@ OpenPencil app becomes a styled composition of these primitives.
| SDK | Type | Slot props |
|-----|------|-----------|
-| `VariablesEditorRoot` | Component | Collection tabs, variable table CRUD |
+| `VariablesEditorRoot` | Component | collections, active tab/search state, table instance, collection actions |
### Menus
@@ -92,7 +92,7 @@ OpenPencil app becomes a styled composition of these primitives.
| SDK | Type | Slot props |
|-----|------|-----------|
| `ScrubInput` | Component | Drag-to-change number input |
-| `FontPicker` | Component | Font family combobox |
+| `FontPickerRoot` | Component | Font family combobox behavior + slots |
### Composables (existing, keep)
@@ -133,9 +133,10 @@ OpenPencil app becomes a styled composition of these primitives.
- Clean `useCanvasInput`, `usePanZoom`, `useTextEdit`, `useCanvasDrop`
### Phase 3: Property primitives
-- `FillList`, `StrokeList`, `EffectList`
-- `PositionControls`, `AppearanceControls`, `TypographyControls`, `LayoutControls`
-- Move `ScrubInput`, `ColorInput`, `FontPicker` to SDK
+- ✅ `FillControlsRoot`, `StrokeControlsRoot`, `EffectsControlsRoot`
+- ✅ `PositionControlsRoot`, `AppearanceControlsRoot`, `TypographyControlsRoot`, `LayoutControlsRoot`
+- ✅ `FontPickerRoot`
+- Next: tighten slot APIs and decide whether `ColorInput` / richer fill picker pieces belong in SDK
### Phase 4: Layer tree primitives
- `LayerTreeRoot`/`LayerTreeItem` with Atlaskit DnD
@@ -147,7 +148,7 @@ OpenPencil app becomes a styled composition of these primitives.
- Next: optional `EditorContextMenu`, `EditorMenuBar` renderers once app-side host overrides settle
### Phase 6: Dialog/picker primitives
-- `VariablesEditorRoot`
+- ✅ `VariablesEditorRoot`
- `FillPickerRoot`, `GradientEditorRoot`, `ImageFillControls`
- `ExportControls`
@@ -162,13 +163,26 @@ Completed:
- `useEditorCommands()`
- `useViewportKind()`
- `useMenuModel()`
+- `FontPickerRoot`
+- `PageListRoot`
+- `PositionControlsRoot`
+- `TypographyControlsRoot`
+- `AppearanceControlsRoot`
+- `LayoutControlsRoot`
+- `FillControlsRoot`
+- `StrokeControlsRoot`
+- `EffectsControlsRoot`
+- `VariablesEditorRoot`
- `CanvasMenu.vue` partly rendered from SDK menu model
- `AppMenu.vue` partly rendered from SDK menu model
- keyboard shortcuts migrated to shared command execution for core editor actions
Next recommended steps:
-1. Standardize remaining app primitives on the `ui` + `useComponentUI()` pattern, preferring semantic slot overrides over raw class props
-2. Continue moving app-styled reusable components into `src/components/ui/`
-3. Normalize slot-based style helpers (`menu`, `dialog`, `popover`, `tooltip`, `select`) around the same override conventions
-4. Move remaining `MobileHud` menu/action groups behind command/menu abstractions
-5. Decide whether `EditorContextMenu` / `EditorMenuBar` should exist as SDK renderers or stay as app renderers over SDK data
+1. Tighten SDK slot APIs to avoid broad "ctx dump" slot objects where possible
+2. Continue peeling reusable editor logic from root components into shared composables (`useVariablesEditor`, fill/effect/stroke helpers, etc.)
+3. Decide whether `ColorInput`, `FillPickerRoot`, and image/gradient subcontrols should move into SDK next
+4. Standardize remaining app primitives on the `ui` + `useComponentUI()` pattern, preferring semantic slot overrides over raw class props
+5. Continue moving app-styled reusable components into `src/components/ui/`
+6. Normalize slot-based style helpers (`menu`, `dialog`, `popover`, `tooltip`, `select`) around the same override conventions
+7. Move remaining `MobileHud` menu/action groups behind command/menu abstractions
+8. Decide whether `EditorContextMenu` / `EditorMenuBar` should exist as SDK renderers or stay as app renderers over SDK data
diff --git a/packages/vue/src/AppearanceControls/AppearanceControlsRoot.vue b/packages/vue/src/AppearanceControls/AppearanceControlsRoot.vue
new file mode 100644
index 000000000..073f4ce0b
--- /dev/null
+++ b/packages/vue/src/AppearanceControls/AppearanceControlsRoot.vue
@@ -0,0 +1,24 @@
+<script setup lang="ts">
+import { useAppearance } from '../shared/useAppearance'
+
+const ctx = useAppearance()
+</script>
+
+<template>
+ <slot
+ :node="ctx.node.value"
+ :is-multi="ctx.isMulti.value"
+ :active="ctx.active.value"
+ :has-corner-radius="ctx.hasCornerRadius.value"
+ :independent-corners="ctx.independentCorners.value"
+ :corner-radius-value="ctx.cornerRadiusValue.value"
+ :opacity-percent="ctx.opacityPercent.value"
+ :visibility-state="ctx.visibilityState.value"
+ :update-prop="ctx.updateProp"
+ :commit-prop="ctx.commitProp"
+ :toggle-visibility="ctx.toggleVisibility"
+ :toggle-independent-corners="ctx.toggleIndependentCorners"
+ :update-corner-prop="ctx.updateCornerProp"
+ :commit-corner-prop="ctx.commitCornerProp"
+ />
+</template>
diff --git a/packages/vue/src/AppearanceControls/index.ts b/packages/vue/src/AppearanceControls/index.ts
new file mode 100644
index 000000000..0a795c6ab
--- /dev/null
+++ b/packages/vue/src/AppearanceControls/index.ts
@@ -0,0 +1 @@
+export { default as AppearanceControlsRoot } from './AppearanceControlsRoot.vue'
diff --git a/packages/vue/src/ColorPicker/ColorInputRoot.vue b/packages/vue/src/ColorPicker/ColorInputRoot.vue
new file mode 100644
index 000000000..16acaae38
--- /dev/null
+++ b/packages/vue/src/ColorPicker/ColorInputRoot.vue
@@ -0,0 +1,30 @@
+<script setup lang="ts">
+import { computed } from 'vue'
+import { colorToHexRaw, parseColor } from '@open-pencil/core'
+
+import type { Color } from '@open-pencil/core'
+
+const props = defineProps<{
+ color: Color
+ editable?: boolean
+}>()
+
+const emit = defineEmits<{ update: [color: Color] }>()
+
+const hex = computed(() => colorToHexRaw(props.color))
+
+function updateFromHex(value: string) {
+ const parsed = parseColor(value.startsWith('#') ? value : `#${value}`)
+ emit('update', { ...parsed, a: props.color.a })
+}
+</script>
+
+<template>
+ <slot
+ :color="color"
+ :editable="editable ?? false"
+ :hex="hex"
+ :update-from-hex="updateFromHex"
+ :update-color="(nextColor: Color) => emit('update', nextColor)"
+ />
+</template>
diff --git a/packages/vue/src/ColorPicker/ColorPickerRoot.vue b/packages/vue/src/ColorPicker/ColorPickerRoot.vue
new file mode 100644
index 000000000..8aa2c2ea3
--- /dev/null
+++ b/packages/vue/src/ColorPicker/ColorPickerRoot.vue
@@ -0,0 +1,33 @@
+<script setup lang="ts">
+import { computed } from 'vue'
+import { PopoverContent, PopoverPortal, PopoverRoot, PopoverTrigger } from 'reka-ui'
+import { colorToCSS } from '@open-pencil/core'
+
+import type { Color } from '@open-pencil/core'
+
+const props = defineProps<{
+ color: Color
+ contentClass?: string
+ swatchClass?: string
+}>()
+
+const emit = defineEmits<{ update: [color: Color] }>()
+
+const swatchBg = computed(() => colorToCSS(props.color))
+</script>
+
+<template>
+ <PopoverRoot>
+ <PopoverTrigger as-child>
+ <slot name="trigger" :style="{ background: swatchBg }">
+ <button :class="swatchClass" :style="{ background: swatchBg }" />
+ </slot>
+ </PopoverTrigger>
+
+ <PopoverPortal>
+ <PopoverContent data-test-id="color-picker-popover" :class="contentClass" :side-offset="4" side="left">
+ <slot :color="color" :update="(nextColor: Color) => emit('update', nextColor)" />
+ </PopoverContent>
+ </PopoverPortal>
+ </PopoverRoot>
+</template>
diff --git a/packages/vue/src/ColorPicker/index.ts b/packages/vue/src/ColorPicker/index.ts
new file mode 100644
index 000000000..d4cca1749
--- /dev/null
+++ b/packages/vue/src/ColorPicker/index.ts
@@ -0,0 +1,2 @@
+export { default as ColorInputRoot } from './ColorInputRoot.vue'
+export { default as ColorPickerRoot } from './ColorPickerRoot.vue'
diff --git a/packages/vue/src/EffectsControls/EffectsControlsRoot.vue b/packages/vue/src/EffectsControls/EffectsControlsRoot.vue
new file mode 100644
index 000000000..345963bba
--- /dev/null
+++ b/packages/vue/src/EffectsControls/EffectsControlsRoot.vue
@@ -0,0 +1,119 @@
+<script setup lang="ts">
+import { ref } from 'vue'
+
+import { useEditor } from '../shared/editorContext'
+
+import type { Color, Effect, SceneNode } from '@open-pencil/core'
+
+type EffectType = Effect['type']
+
+const editor = useEditor()
+
+const expandedIndex = ref<number | null>(null)
+const effectsBeforeScrub = ref<Effect[] | null>(null)
+
+const EFFECT_LABELS: Record<string, string> = {
+ DROP_SHADOW: 'Drop shadow',
+ INNER_SHADOW: 'Inner shadow',
+ LAYER_BLUR: 'Layer blur',
+ BACKGROUND_BLUR: 'Background blur',
+ FOREGROUND_BLUR: 'Foreground blur'
+}
+
+const EFFECT_TYPES = Object.keys(EFFECT_LABELS) as EffectType[]
+const effectOptions = EFFECT_TYPES.map((t) => ({ value: t, label: EFFECT_LABELS[t] }))
+
+function isShadow(type: string) {
+ return type === 'DROP_SHADOW' || type === 'INNER_SHADOW'
+}
+
+function defaultEffect(): Effect {
+ return {
+ type: 'DROP_SHADOW',
+ color: { r: 0, g: 0, b: 0, a: 0.25 },
+ offset: { x: 0, y: 4 },
+ radius: 4,
+ spread: 0,
+ visible: true
+ }
+}
+
+function scrubEffect(node: SceneNode | null, index: number, changes: Partial<Effect>) {
+ if (!node) return
+ if (!effectsBeforeScrub.value) {
+ effectsBeforeScrub.value = node.effects.map((e) => ({
+ ...e,
+ color: { ...e.color },
+ offset: { ...e.offset }
+ }))
+ }
+ const effects = [...node.effects]
+ effects[index] = { ...effects[index], ...changes }
+ editor.updateNode(node.id, { effects })
+ editor.requestRender()
+}
+
+function commitEffect(node: SceneNode | null, index: number, changes: Partial<Effect>) {
+ if (!node) return
+ const previous = effectsBeforeScrub.value
+ effectsBeforeScrub.value = null
+ const effects = [...node.effects]
+ effects[index] = { ...effects[index], ...changes }
+ editor.updateNode(node.id, { effects })
+ editor.requestRender()
+ if (previous) {
+ editor.commitNodeUpdate(node.id, { effects: previous }, 'Change effect')
+ }
+}
+
+function updateType(
+ patch: (index: number, changes: Partial<Effect>) => void,
+ node: SceneNode | null,
+ index: number,
+ type: EffectType
+) {
+ if (!node) return
+ const changes: Partial<Effect> = { type }
+ if (!isShadow(type)) {
+ changes.offset = { x: 0, y: 0 }
+ changes.spread = 0
+ } else if (!isShadow(node.effects[index].type)) {
+ changes.offset = { x: 0, y: 4 }
+ changes.spread = 0
+ }
+ patch(index, changes)
+}
+
+function updateColor(
+ patch: (index: number, changes: Partial<Effect>) => void,
+ index: number,
+ color: Color
+) {
+ patch(index, { color })
+}
+
+function handleRemove(removeFn: (index: number) => void, index: number) {
+ removeFn(index)
+ if (expandedIndex.value === index) expandedIndex.value = null
+ else if (expandedIndex.value !== null && expandedIndex.value > index) expandedIndex.value--
+}
+
+function toggleExpand(index: number) {
+ expandedIndex.value = expandedIndex.value === index ? null : index
+}
+</script>
+
+<template>
+ <slot
+ :expanded-index="expandedIndex"
+ :effect-options="effectOptions"
+ :default-effect="defaultEffect()"
+ :is-shadow="isShadow"
+ :scrub-effect="scrubEffect"
+ :commit-effect="commitEffect"
+ :update-type="updateType"
+ :update-color="updateColor"
+ :handle-remove="handleRemove"
+ :toggle-expand="toggleExpand"
+ />
+</template>
diff --git a/packages/vue/src/EffectsControls/index.ts b/packages/vue/src/EffectsControls/index.ts
new file mode 100644
index 000000000..01c50f3eb
--- /dev/null
+++ b/packages/vue/src/EffectsControls/index.ts
@@ -0,0 +1 @@
+export { default as EffectsControlsRoot } from './EffectsControlsRoot.vue'
diff --git a/packages/vue/src/FillControls/FillControlsRoot.vue b/packages/vue/src/FillControls/FillControlsRoot.vue
new file mode 100644
index 000000000..d9ee7766b
--- /dev/null
+++ b/packages/vue/src/FillControls/FillControlsRoot.vue
@@ -0,0 +1,20 @@
+<script setup lang="ts">
+import { DEFAULT_SHAPE_FILL } from '@open-pencil/core'
+
+import { useFillVariableBinding } from '../shared/use-fill-variable-binding'
+
+const ctx = useFillVariableBinding()
+</script>
+
+<template>
+ <slot
+ :store="ctx.store"
+ :default-fill="DEFAULT_SHAPE_FILL"
+ :color-variables="ctx.colorVariables.value"
+ :search-term="ctx.searchTerm.value"
+ :filtered-variables="ctx.filteredVariables.value"
+ :get-bound-variable="ctx.getBoundVariable"
+ :bind-fill-variable="ctx.bindFillVariable"
+ :unbind-fill-variable="ctx.unbindFillVariable"
+ />
+</template>
diff --git a/packages/vue/src/FillControls/index.ts b/packages/vue/src/FillControls/index.ts
new file mode 100644
index 000000000..514f63c1a
--- /dev/null
+++ b/packages/vue/src/FillControls/index.ts
@@ -0,0 +1 @@
+export { default as FillControlsRoot } from './FillControlsRoot.vue'
diff --git a/packages/vue/src/FillPicker/FillPickerRoot.vue b/packages/vue/src/FillPicker/FillPickerRoot.vue
new file mode 100644
index 000000000..81b64943d
--- /dev/null
+++ b/packages/vue/src/FillPicker/FillPickerRoot.vue
@@ -0,0 +1,44 @@
+<script setup lang="ts">
+import { computed } from 'vue'
+import { PopoverContent, PopoverPortal, PopoverRoot, PopoverTrigger } from 'reka-ui'
+
+import { useFillPicker } from '../shared/useFillPicker'
+
+import type { Fill } from '@open-pencil/core'
+
+const props = defineProps<{
+ fill: Fill
+ contentClass?: string
+ swatchClass?: string
+}>()
+
+const emit = defineEmits<{ update: [fill: Fill] }>()
+
+const { category, swatchBg, toSolid, toGradient, toImage } = useFillPicker(
+ computed(() => props.fill),
+ (updated) => emit('update', updated)
+)
+</script>
+
+<template>
+ <PopoverRoot>
+ <PopoverTrigger as-child>
+ <slot name="trigger" :style="{ background: swatchBg }">
+ <button :class="swatchClass" :style="{ background: swatchBg }" />
+ </slot>
+ </PopoverTrigger>
+
+ <PopoverPortal>
+ <PopoverContent :class="contentClass" :side-offset="4" side="left">
+ <slot
+ :fill="fill"
+ :category="category"
+ :to-solid="toSolid"
+ :to-gradient="toGradient"
+ :to-image="toImage"
+ :update="(nextFill: Fill) => emit('update', nextFill)"
+ />
+ </PopoverContent>
+ </PopoverPortal>
+ </PopoverRoot>
+</template>
diff --git a/packages/vue/src/FillPicker/index.ts b/packages/vue/src/FillPicker/index.ts
new file mode 100644
index 000000000..554f42ad9
--- /dev/null
+++ b/packages/vue/src/FillPicker/index.ts
@@ -0,0 +1 @@
+export { default as FillPickerRoot } from './FillPickerRoot.vue'
diff --git a/packages/vue/src/FontPicker/FontPickerRoot.vue b/packages/vue/src/FontPicker/FontPickerRoot.vue
new file mode 100644
index 000000000..4fa100b99
--- /dev/null
+++ b/packages/vue/src/FontPicker/FontPickerRoot.vue
@@ -0,0 +1,115 @@
+<script setup lang="ts">
+import { nextTick, ref } from 'vue'
+import {
+ ComboboxAnchor,
+ ComboboxContent,
+ ComboboxInput,
+ ComboboxItem,
+ ComboboxItemIndicator,
+ ComboboxPortal,
+ ComboboxRoot,
+ ComboboxVirtualizer,
+ ComboboxViewport,
+ type AcceptableValue
+} from 'reka-ui'
+
+import { useFontPicker } from '../shared/useFontPicker'
+
+const props = defineProps<{
+ listFamilies: () => Promise<string[]>
+ triggerClass?: string
+ contentClass?: string
+ itemClass?: string
+ searchClass?: string
+ emptyClass?: string
+ emptySearchText?: string
+ emptyFontsText?: string
+ emptyFontsHint?: string
+}>()
+
+const modelValue = defineModel<string>({ required: true })
+const emit = defineEmits<{ select: [family: string] }>()
+
+const inputRef = ref<HTMLInputElement | null>(null)
+
+const { searchTerm, open, filtered, select } = useFontPicker({
+ modelValue,
+ listFamilies: props.listFamilies,
+ onSelect: (family) => emit('select', family)
+})
+</script>
+
+<template>
+ <ComboboxRoot
+ v-model:open="open"
+ :model-value="modelValue"
+ :ignore-filter="true"
+ @update:model-value="
+ (v: AcceptableValue) => {
+ if (typeof v === 'string') select(v)
+ }
+ "
+ >
+ <ComboboxAnchor as-child>
+ <slot name="trigger" :value="modelValue" :open="open">
+ <button :class="triggerClass">
+ <span class="truncate">{{ modelValue }}</span>
+ </button>
+ </slot>
+ </ComboboxAnchor>
+
+ <ComboboxPortal>
+ <ComboboxContent
+ :side-offset="2"
+ align="start"
+ position="popper"
+ :class="contentClass"
+ @open-auto-focus.prevent
+ @vue:mounted="nextTick(() => inputRef?.focus())"
+ >
+ <slot name="search" :search-term="searchTerm">
+ <ComboboxInput
+ ref="inputRef"
+ v-model="searchTerm"
+ :class="searchClass"
+ placeholder="Search fonts…"
+ autocomplete="off"
+ autocorrect="off"
+ autocapitalize="off"
+ spellcheck="false"
+ />
+ </slot>
+
+ <ComboboxViewport class="max-h-72 overflow-y-auto">
+ <ComboboxVirtualizer
+ v-slot="{ option }"
+ :options="filtered"
+ :text-content="(family: string) => family"
+ :estimate-size="36"
+ >
+ <slot name="item" :family="option" :selected="option === modelValue">
+ <ComboboxItem :value="option" :class="itemClass" :style="{ fontFamily: `'${option}', sans-serif` }">
+ <ComboboxItemIndicator>
+ <slot name="indicator" :selected="option === modelValue" />
+ </ComboboxItemIndicator>
+ <span class="truncate">{{ option }}</span>
+ </ComboboxItem>
+ </slot>
+ </ComboboxVirtualizer>
+
+ <div v-if="filtered.length === 0 && searchTerm" :class="emptyClass">
+ {{ emptySearchText ?? 'No fonts found' }}
+ </div>
+ <div v-else-if="filtered.length === 0" :class="emptyClass">
+ <slot name="empty">
+ <div>
+ <p>{{ emptyFontsText ?? 'No local fonts available.' }}</p>
+ <p v-if="emptyFontsHint" class="mt-1">{{ emptyFontsHint }}</p>
+ </div>
+ </slot>
+ </div>
+ </ComboboxViewport>
+ </ComboboxContent>
+ </ComboboxPortal>
+ </ComboboxRoot>
+</template>
diff --git a/packages/vue/src/FontPicker/index.ts b/packages/vue/src/FontPicker/index.ts
new file mode 100644
index 000000000..1195a355f
--- /dev/null
+++ b/packages/vue/src/FontPicker/index.ts
@@ -0,0 +1 @@
+export { default as FontPickerRoot } from './FontPickerRoot.vue'
diff --git a/packages/vue/src/LayoutControls/LayoutControlsRoot.vue b/packages/vue/src/LayoutControls/LayoutControlsRoot.vue
new file mode 100644
index 000000000..23cf2e5c5
--- /dev/null
+++ b/packages/vue/src/LayoutControls/LayoutControlsRoot.vue
@@ -0,0 +1,35 @@
+<script setup lang="ts">
+import { useLayout } from '../shared/useLayout'
+
+const ctx = useLayout()
+</script>
+
+<template>
+ <slot
+ :editor="ctx.editor"
+ :node="ctx.node.value"
+ :is-in-auto-layout="ctx.isInAutoLayout.value"
+ :is-grid="ctx.isGrid.value"
+ :is-flex="ctx.isFlex.value"
+ :width-sizing="ctx.widthSizing.value"
+ :height-sizing="ctx.heightSizing.value"
+ :width-sizing-options="ctx.widthSizingOptions.value"
+ :height-sizing-options="ctx.heightSizingOptions.value"
+ :align-grid="ctx.alignGrid.value"
+ :show-individual-padding="ctx.showIndividualPadding.value"
+ :has-uniform-padding="ctx.hasUniformPadding.value"
+ :track-sizing-options="ctx.trackSizingOptions"
+ :update-prop="ctx.updateProp"
+ :commit-prop="ctx.commitProp"
+ :set-width-sizing="ctx.setWidthSizing"
+ :set-height-sizing="ctx.setHeightSizing"
+ :set-uniform-padding="ctx.setUniformPadding"
+ :commit-uniform-padding="ctx.commitUniformPadding"
+ :set-alignment="ctx.setAlignment"
+ :update-grid-track="ctx.updateGridTrack"
+ :add-track="ctx.addTrack"
+ :remove-track="ctx.removeTrack"
+ :track-label="ctx.trackLabel"
+ :toggle-individual-padding="ctx.toggleIndividualPadding"
+ />
+</template>
diff --git a/packages/vue/src/LayoutControls/index.ts b/packages/vue/src/LayoutControls/index.ts
new file mode 100644
index 000000000..b6899b659
--- /dev/null
+++ b/packages/vue/src/LayoutControls/index.ts
@@ -0,0 +1 @@
+export { default as LayoutControlsRoot } from './LayoutControlsRoot.vue'
diff --git a/packages/vue/src/PageList/PageListRoot.vue b/packages/vue/src/PageList/PageListRoot.vue
new file mode 100644
index 000000000..96c657f96
--- /dev/null
+++ b/packages/vue/src/PageList/PageListRoot.vue
@@ -0,0 +1,56 @@
+<script setup lang="ts">
+import { computed } from 'vue'
+
+import { usePageList } from '../shared/usePageList'
+
+const props = defineProps<{
+ dividerPattern?: RegExp
+}>()
+
+const emit = defineEmits<{
+ add: []
+ switch: [pageId: string]
+ rename: [pageId: string, name: string]
+ delete: [pageId: string]
+}>()
+
+const { pages, currentPageId, switchPage, addPage, renamePage, deletePage } = usePageList()
+
+const dividerPattern = computed(() => props.dividerPattern ?? /^[-–—*\s]+$/)
+
+function isDivider(page: { name: string; childIds: string[] }) {
+ return page.childIds.length === 0 && dividerPattern.value.test(page.name)
+}
+
+function handleAdd() {
+ addPage()
+ emit('add')
+}
+
+function handleSwitch(pageId: string) {
+ switchPage(pageId)
+ emit('switch', pageId)
+}
+
+function handleRename(pageId: string, name: string) {
+ renamePage(pageId, name)
+ emit('rename', pageId, name)
+}
+
+function handleDelete(pageId: string) {
+ deletePage(pageId)
+ emit('delete', pageId)
+}
+</script>
+
+<template>
+ <slot
+ :pages="pages"
+ :current-page-id="currentPageId"
+ :is-divider="isDivider"
+ :add-page="handleAdd"
+ :switch-page="handleSwitch"
+ :rename-page="handleRename"
+ :delete-page="handleDelete"
+ />
+</template>
diff --git a/packages/vue/src/PageList/index.ts b/packages/vue/src/PageList/index.ts
new file mode 100644
index 000000000..abb1df0a1
--- /dev/null
+++ b/packages/vue/src/PageList/index.ts
@@ -0,0 +1 @@
+export { default as PageListRoot } from './PageListRoot.vue'
diff --git a/packages/vue/src/PositionControls/PositionControlsRoot.vue b/packages/vue/src/PositionControls/PositionControlsRoot.vue
new file mode 100644
index 000000000..a2e087476
--- /dev/null
+++ b/packages/vue/src/PositionControls/PositionControlsRoot.vue
@@ -0,0 +1,56 @@
+<script setup lang="ts">
+import { computed } from 'vue'
+
+import { MIXED, useNodeProps } from '../shared/useNodeProps'
+
+const {
+ updateProp,
+ commitProp,
+ node,
+ nodes,
+ isMulti,
+ active,
+ prop: multiProp,
+ store
+} = useNodeProps()
+
+const xValue = computed(() => (isMulti.value ? multiProp('x').value : Math.round(node.value?.x ?? 0)))
+const yValue = computed(() => (isMulti.value ? multiProp('y').value : Math.round(node.value?.y ?? 0)))
+const wValue = multiProp('width')
+const hValue = multiProp('height')
+const rotationValue = computed(() =>
+ isMulti.value ? multiProp('rotation').value : Math.round(node.value?.rotation ?? 0)
+)
+const ids = computed(() => nodes.value.map((n) => n.id))
+
+function align(axis: 'horizontal' | 'vertical', pos: 'min' | 'center' | 'max') {
+ store.alignNodes(ids.value, axis, pos)
+}
+
+function flip(axis: 'horizontal' | 'vertical') {
+ store.flipNodes(ids.value, axis)
+}
+
+function rotate(degrees: number) {
+ store.rotateNodes(ids.value, degrees)
+}
+</script>
+
+<template>
+ <slot
+ :active="active"
+ :is-multi="isMulti"
+ :ids="ids"
+ :x-value="xValue"
+ :y-value="yValue"
+ :w-value="wValue"
+ :h-value="hValue"
+ :rotation-value="rotationValue"
+ :mixed="MIXED"
+ :update-prop="updateProp"
+ :commit-prop="commitProp"
+ :align="align"
+ :flip="flip"
+ :rotate="rotate"
+ />
+</template>
diff --git a/packages/vue/src/PositionControls/index.ts b/packages/vue/src/PositionControls/index.ts
new file mode 100644
index 000000000..9fb0f748a
--- /dev/null
+++ b/packages/vue/src/PositionControls/index.ts
@@ -0,0 +1 @@
+export { default as PositionControlsRoot } from './PositionControlsRoot.vue'
diff --git a/packages/vue/src/StrokeControls/StrokeControlsRoot.vue b/packages/vue/src/StrokeControls/StrokeControlsRoot.vue
new file mode 100644
index 000000000..ae21d34f1
--- /dev/null
+++ b/packages/vue/src/StrokeControls/StrokeControlsRoot.vue
@@ -0,0 +1,145 @@
+<script setup lang="ts">
+import { ref } from 'vue'
+
+import { useEditor } from '../shared/editorContext'
+
+import type { SceneNode, Stroke } from '@open-pencil/core'
+
+type StrokeSides = 'ALL' | 'TOP' | 'BOTTOM' | 'LEFT' | 'RIGHT' | 'CUSTOM'
+
+const store = useEditor()
+
+const ALIGN_OPTIONS: { value: Stroke['align']; label: string }[] = [
+ { value: 'INSIDE', label: 'Inside' },
+ { value: 'CENTER', label: 'Center' },
+ { value: 'OUTSIDE', label: 'Outside' }
+]
+
+const SIDE_OPTIONS: { value: StrokeSides; label: string }[] = [
+ { value: 'ALL', label: 'All' },
+ { value: 'TOP', label: 'Top' },
+ { value: 'BOTTOM', label: 'Bottom' },
+ { value: 'LEFT', label: 'Left' },
+ { value: 'RIGHT', label: 'Right' },
+ { value: 'CUSTOM', label: 'Custom' }
+]
+
+const BORDER_SIDES = ['top', 'right', 'bottom', 'left'] as const
+const sideMenuOpen = ref(false)
+
+function updateAlign(align: Stroke['align'], activeNode: SceneNode) {
+ const strokes = activeNode.strokes.map((s) => ({ ...s, align }))
+ store.updateNodeWithUndo(activeNode.id, { strokes }, 'Change stroke align')
+}
+
+function currentAlign(activeNode: SceneNode | null): Stroke['align'] {
+ if (!activeNode || activeNode.strokes.length === 0) return 'CENTER'
+ return activeNode.strokes[0].align
+}
+
+function currentSides(activeNode: SceneNode | null): StrokeSides {
+ if (!activeNode?.independentStrokeWeights) return 'ALL'
+ const {
+ borderTopWeight: t,
+ borderRightWeight: r,
+ borderBottomWeight: b,
+ borderLeftWeight: l
+ } = activeNode
+ const active = [t > 0, r > 0, b > 0, l > 0]
+ const count = active.filter(Boolean).length
+ if (count === 4 && t === r && r === b && b === l) return 'ALL'
+ if (count === 1) {
+ if (t > 0) return 'TOP'
+ if (b > 0) return 'BOTTOM'
+ if (l > 0) return 'LEFT'
+ if (r > 0) return 'RIGHT'
+ }
+ return 'CUSTOM'
+}
+
+function selectSide(side: StrokeSides, activeNode: SceneNode) {
+ const weight = activeNode.strokes.length > 0 ? activeNode.strokes[0].weight : 1
+ if (side === 'ALL') {
+ store.updateNodeWithUndo(
+ activeNode.id,
+ {
+ independentStrokeWeights: false,
+ borderTopWeight: 0,
+ borderRightWeight: 0,
+ borderBottomWeight: 0,
+ borderLeftWeight: 0
+ } as Partial<SceneNode>,
+ 'Stroke all sides'
+ )
+ } else if (side === 'CUSTOM') {
+ const w = activeNode.independentStrokeWeights
+ ? {
+ top: activeNode.borderTopWeight,
+ right: activeNode.borderRightWeight,
+ bottom: activeNode.borderBottomWeight,
+ left: activeNode.borderLeftWeight
+ }
+ : { top: weight, right: weight, bottom: weight, left: weight }
+ store.updateNodeWithUndo(
+ activeNode.id,
+ {
+ independentStrokeWeights: true,
+ borderTopWeight: w.top,
+ borderRightWeight: w.right,
+ borderBottomWeight: w.bottom,
+ borderLeftWeight: w.left
+ } as Partial<SceneNode>,
+ 'Custom stroke sides'
+ )
+ } else {
+ store.updateNodeWithUndo(
+ activeNode.id,
+ {
+ independentStrokeWeights: true,
+ borderTopWeight: side === 'TOP' ? weight : 0,
+ borderRightWeight: side === 'RIGHT' ? weight : 0,
+ borderBottomWeight: side === 'BOTTOM' ? weight : 0,
+ borderLeftWeight: side === 'LEFT' ? weight : 0
+ } as Partial<SceneNode>,
+ `Stroke ${side.toLowerCase()} only`
+ )
+ }
+ sideMenuOpen.value = false
+}
+
+function updateBorderWeight(
+ side: (typeof BORDER_SIDES)[number],
+ value: number,
+ activeNode: SceneNode
+) {
+ const key = `border${side[0].toUpperCase()}${side.slice(1)}Weight` as keyof SceneNode
+ store.updateNodeWithUndo(
+ activeNode.id,
+ { [key]: value } as Partial<SceneNode>,
+ 'Change stroke weight'
+ )
+}
+
+const defaultStroke: Stroke = {
+ color: { r: 0, g: 0, b: 0, a: 1 },
+ weight: 1,
+ opacity: 1,
+ visible: true,
+ align: 'CENTER'
+}
+</script>
+
+<template>
+ <slot
+ :align-options="ALIGN_OPTIONS"
+ :side-options="SIDE_OPTIONS"
+ :border-sides="BORDER_SIDES"
+ :side-menu-open="sideMenuOpen"
+ :default-stroke="defaultStroke"
+ :update-align="updateAlign"
+ :current-align="currentAlign"
+ :current-sides="currentSides"
+ :select-side="selectSide"
+ :update-border-weight="updateBorderWeight"
+ />
+</template>
diff --git a/packages/vue/src/StrokeControls/index.ts b/packages/vue/src/StrokeControls/index.ts
new file mode 100644
index 000000000..5f09a93c9
--- /dev/null
+++ b/packages/vue/src/StrokeControls/index.ts
@@ -0,0 +1 @@
+export { default as StrokeControlsRoot } from './StrokeControlsRoot.vue'
diff --git a/packages/vue/src/TypographyControls/TypographyControlsRoot.vue b/packages/vue/src/TypographyControls/TypographyControlsRoot.vue
new file mode 100644
index 000000000..b225c5189
--- /dev/null
+++ b/packages/vue/src/TypographyControls/TypographyControlsRoot.vue
@@ -0,0 +1,35 @@
+<script setup lang="ts">
+import { useTypography } from '../shared/useTypography'
+
+import type { AcceptableValue } from 'reka-ui'
+
+const props = defineProps<{
+ loadFont?: (family: string, style: string) => Promise<unknown>
+}>()
+
+const ctx = useTypography({ loadFont: props.loadFont })
+
+function onAlignChange(val: AcceptableValue) {
+ if (val) ctx.setAlign(val as 'LEFT' | 'CENTER' | 'RIGHT')
+}
+
+function onFormattingChange(val: AcceptableValue | AcceptableValue[]) {
+ if (Array.isArray(val)) ctx.onFormattingChange(val as string[])
+}
+</script>
+
+<template>
+ <slot
+ :node="ctx.node"
+ :weights="ctx.weights"
+ :missing-fonts="ctx.missingFonts"
+ :has-missing-fonts="ctx.hasMissingFonts"
+ :active-formatting="ctx.activeFormatting"
+ :set-family="ctx.setFamily"
+ :set-weight="ctx.setWeight"
+ :update-prop="ctx.updateProp"
+ :commit-prop="ctx.commitProp"
+ :on-align-change="onAlignChange"
+ :on-formatting-change="onFormattingChange"
+ />
+</template>
diff --git a/packages/vue/src/TypographyControls/index.ts b/packages/vue/src/TypographyControls/index.ts
new file mode 100644
index 000000000..1c2ea0745
--- /dev/null
+++ b/packages/vue/src/TypographyControls/index.ts
@@ -0,0 +1 @@
+export { default as TypographyControlsRoot } from './TypographyControlsRoot.vue'
diff --git a/packages/vue/src/VariablesEditor/VariablesEditorRoot.vue b/packages/vue/src/VariablesEditor/VariablesEditorRoot.vue
new file mode 100644
index 000000000..0e69cc76e
--- /dev/null
+++ b/packages/vue/src/VariablesEditor/VariablesEditorRoot.vue
@@ -0,0 +1,37 @@
+<script setup lang="ts">
+import { type Component } from 'vue'
+
+import { useVariablesEditor } from '../shared/use-variables-editor'
+
+const props = defineProps<{
+ colorInput: Component
+ icons: Record<string, Component>
+ fallbackIcon: Component
+ deleteIcon: Component
+}>()
+
+const ctx = useVariablesEditor({
+ colorInput: props.colorInput,
+ icons: props.icons,
+ fallbackIcon: props.fallbackIcon,
+ deleteIcon: props.deleteIcon
+})
+</script>
+
+<template>
+ <slot
+ :collections="ctx.collections"
+ :variables="ctx.variables"
+ :active-collection-id="ctx.activeCollectionId"
+ :active-modes="ctx.activeModes"
+ :search-term="ctx.searchTerm"
+ :editing-collection-id="ctx.editingCollectionId"
+ :table="ctx.table"
+ :has-collections="ctx.hasCollections"
+ :add-collection="ctx.addCollection"
+ :add-variable="ctx.addVariable"
+ :set-collection-input-ref="ctx.setCollectionInputRef"
+ :start-rename-collection="ctx.startRenameCollection"
+ :commit-rename-collection="ctx.commitRenameCollection"
+ />
+</template>
diff --git a/packages/vue/src/VariablesEditor/index.ts b/packages/vue/src/VariablesEditor/index.ts
new file mode 100644
index 000000000..da6554126
--- /dev/null
+++ b/packages/vue/src/VariablesEditor/index.ts
@@ -0,0 +1 @@
+export { default as VariablesEditorRoot } from './VariablesEditorRoot.vue'
diff --git a/packages/vue/src/index.ts b/packages/vue/src/index.ts
index 6d454c9a2..cf2f39ebb 100644
--- a/packages/vue/src/index.ts
+++ b/packages/vue/src/index.ts
@@ -1,4 +1,10 @@
-export type { Editor, EditorState, EditorOptions, Tool, EditorToolDef } from '@open-pencil/core/editor'
+export type {
+ Editor,
+ EditorState,
+ EditorOptions,
+ Tool,
+ EditorToolDef
+} from '@open-pencil/core/editor'
export { createEditor, EDITOR_TOOLS, TOOL_SHORTCUTS } from '@open-pencil/core/editor'
export { provideEditor, useEditor, EDITOR_KEY } from './shared/editorContext'
@@ -32,15 +38,29 @@ export type { UseTypographyOptions } from './shared/useTypography'
export { useExport } from './shared/useExport'
export { useVariables } from './shared/useVariables'
export { useVariablesDialogState } from './shared/useVariablesDialogState'
+export { useVariablesEditor } from './shared/use-variables-editor'
export { useVariablesTable } from './shared/useVariablesTable'
export { useFillPicker } from './shared/useFillPicker'
+export { useFillVariableBinding } from './shared/use-fill-variable-binding'
export { useGradientStops } from './shared/useGradientStops'
export { usePageList } from './shared/usePageList'
export { useFontPicker } from './shared/useFontPicker'
export * from './Canvas'
+export * from './ColorPicker'
+export * from './EffectsControls'
+export * from './FillControls'
+export * from './FillPicker'
+export * from './FontPicker'
export * from './GradientEditor'
export * from './LayerTree'
+export * from './LayoutControls'
+export * from './AppearanceControls'
+export * from './PageList'
+export * from './PositionControls'
export * from './PropertyList'
export * from './ScrubInput'
+export * from './StrokeControls'
+export * from './TypographyControls'
export * from './Toolbar'
+export * from './VariablesEditor'
diff --git a/packages/vue/src/shared/use-fill-variable-binding.ts b/packages/vue/src/shared/use-fill-variable-binding.ts
new file mode 100644
index 000000000..886c00bd3
--- /dev/null
+++ b/packages/vue/src/shared/use-fill-variable-binding.ts
@@ -0,0 +1,42 @@
+import { computed, ref } from 'vue'
+import { useFilter } from 'reka-ui'
+
+import { useEditor } from './editorContext'
+
+import type { Variable } from '@open-pencil/core'
+
+export function useFillVariableBinding() {
+ const store = useEditor()
+ const colorVariables = computed(() => store.getVariablesByType('COLOR'))
+ const searchTerm = ref('')
+ const { contains } = useFilter({ sensitivity: 'base' })
+ const filteredVariables = computed(() => {
+ if (!searchTerm.value) return colorVariables.value
+ return colorVariables.value.filter((v) => contains(v.name, searchTerm.value))
+ })
+
+ function getBoundVariable(nodeId: string, index: number): Variable | undefined {
+ const n = store.getNode(nodeId)
+ if (!n) return undefined
+ const varId = n.boundVariables[`fills/${index}/color`]
+ return varId ? store.getVariable(varId) : undefined
+ }
+
+ function bindFillVariable(nodeId: string, index: number, variableId: string) {
+ store.bindVariable(nodeId, `fills/${index}/color`, variableId)
+ }
+
+ function unbindFillVariable(nodeId: string, index: number) {
+ store.unbindVariable(nodeId, `fills/${index}/color`)
+ }
+
+ return {
+ store,
+ colorVariables,
+ searchTerm,
+ filteredVariables,
+ getBoundVariable,
+ bindFillVariable,
+ unbindFillVariable
+ }
+}
diff --git a/packages/vue/src/shared/use-variables-editor.ts b/packages/vue/src/shared/use-variables-editor.ts
new file mode 100644
index 000000000..023e98497
--- /dev/null
+++ b/packages/vue/src/shared/use-variables-editor.ts
@@ -0,0 +1,53 @@
+import { computed, type Component } from 'vue'
+import { useVueTable, getCoreRowModel } from '@tanstack/vue-table'
+
+import { useVariablesDialogState } from './useVariablesDialogState'
+import { useVariablesTable } from './useVariablesTable'
+
+export function useVariablesEditor(options: {
+ colorInput: Component
+ icons: Record<string, Component>
+ fallbackIcon: Component
+ deleteIcon: Component
+}) {
+ const ctx = useVariablesDialogState()
+
+ const { columns } = useVariablesTable({
+ activeModes: ctx.activeModes,
+ formatModeValue: ctx.formatModeValue,
+ parseVariableValue: ctx.parseVariableValue,
+ shortName: ctx.shortName,
+ renameVariable: ctx.renameVariable,
+ updateVariableValue: ctx.updateVariableValue,
+ removeVariable: ctx.removeVariable,
+ ColorInput: options.colorInput,
+ icons: options.icons,
+ fallbackIcon: options.fallbackIcon,
+ deleteIcon: options.deleteIcon
+ })
+
+ const table = useVueTable({
+ get data() {
+ return ctx.variables.value
+ },
+ get columns() {
+ return columns.value
+ },
+ columnResizeMode: 'onChange',
+ getCoreRowModel: getCoreRowModel(),
+ defaultColumn: {
+ minSize: 60,
+ maxSize: 800
+ },
+ getRowId: (row) => row.id
+ })
+
+ const hasCollections = computed(() => ctx.collections.value.length > 0)
+
+ return {
+ ...ctx,
+ columns,
+ table,
+ hasCollections
+ }
+}
diff --git a/src/components/ColorInput.vue b/src/components/ColorInput.vue
index 1bde550d4..1a16e11ba 100644
--- a/src/components/ColorInput.vue
+++ b/src/components/ColorInput.vue
@@ -1,6 +1,5 @@
<script setup lang="ts">
-import { computed } from 'vue'
-import { colorToHexRaw, parseColor } from '@open-pencil/core'
+import { ColorInputRoot } from '@open-pencil/vue'
import ColorPicker from './ColorPicker.vue'
@@ -11,28 +10,25 @@ const { editable = false, color } = defineProps<{
editable?: boolean
}>()
const emit = defineEmits<{ update: [color: Color] }>()
-
-const hex = computed(() => colorToHexRaw(color))
-
-function updateFromHex(value: string) {
- const parsed = parseColor(value.startsWith('#') ? value : `#${value}`)
- emit('update', { ...parsed, a: color.a })
-}
</script>
<template>
- <div class="flex items-center gap-1.5">
- <ColorPicker :color="color" @update="emit('update', $event)" />
- <input
- v-if="editable"
- data-test-id="color-hex-input"
- class="min-w-0 flex-1 border-none bg-transparent font-mono text-xs text-surface outline-none"
- :value="hex"
- maxlength="6"
- @change="updateFromHex(($event.target as HTMLInputElement).value)"
- />
- <span v-else class="min-w-0 flex-1 truncate font-mono text-xs text-muted">
- {{ hex }}
- </span>
- </div>
+ <ColorInputRoot :color="color" :editable="editable" @update="emit('update', $event)">
+ <template #default="{ editable: isEditable, hex, updateFromHex, updateColor }">
+ <div class="flex items-center gap-1.5">
+ <ColorPicker :color="color" @update="updateColor($event)" />
+ <input
+ v-if="isEditable"
+ data-test-id="color-hex-input"
+ class="min-w-0 flex-1 border-none bg-transparent font-mono text-xs text-surface outline-none"
+ :value="hex"
+ maxlength="6"
+ @change="updateFromHex(($event.target as HTMLInputElement).value)"
+ />
+ <span v-else class="min-w-0 flex-1 truncate font-mono text-xs text-muted">
+ {{ hex }}
+ </span>
+ </div>
+ </template>
+ </ColorInputRoot>
</template>
diff --git a/src/components/ColorPicker.vue b/src/components/ColorPicker.vue
index 859bfb757..ab2b84142 100644
--- a/src/components/ColorPicker.vue
+++ b/src/components/ColorPicker.vue
@@ -1,7 +1,5 @@
<script setup lang="ts">
-import { computed } from 'vue'
-import { PopoverRoot, PopoverTrigger, PopoverPortal, PopoverContent } from 'reka-ui'
-import { colorToCSS } from '@open-pencil/core'
+import { ColorPickerRoot } from '@open-pencil/vue'
import HsvColorArea from './HsvColorArea.vue'
import { usePopoverUI } from './ui/popover'
@@ -11,29 +9,17 @@ import type { Color } from '@open-pencil/core'
const { color } = defineProps<{ color: Color }>()
const emit = defineEmits<{ update: [color: Color] }>()
const cls = usePopoverUI({ content: 'w-56 p-2' })
-
-const swatchBg = computed(() => colorToCSS(color))
</script>
<template>
- <PopoverRoot>
- <PopoverTrigger as-child>
- <button
- data-test-id="color-picker-swatch"
- class="size-5 shrink-0 cursor-pointer rounded border border-border p-0"
- :style="{ background: swatchBg }"
- />
- </PopoverTrigger>
-
- <PopoverPortal>
- <PopoverContent
- data-test-id="color-picker-popover"
- :class="cls.content"
- :side-offset="4"
- side="left"
- >
- <HsvColorArea :color="color" @update="emit('update', $event)" />
- </PopoverContent>
- </PopoverPortal>
- </PopoverRoot>
+ <ColorPickerRoot
+ :color="color"
+ :content-class="cls.content"
+ swatch-class="size-5 shrink-0 cursor-pointer rounded border border-border p-0"
+ @update="emit('update', $event)"
+ >
+ <template #default="{ color: currentColor, update }">
+ <HsvColorArea :color="currentColor" @update="update($event)" />
+ </template>
+ </ColorPickerRoot>
</template>
diff --git a/src/components/FillPicker.vue b/src/components/FillPicker.vue
index 61f082292..d1efde713 100644
--- a/src/components/FillPicker.vue
+++ b/src/components/FillPicker.vue
@@ -1,13 +1,11 @@
<script setup lang="ts">
-import { computed } from 'vue'
-import { PopoverRoot, PopoverTrigger, PopoverPortal, PopoverContent } from 'reka-ui'
import { twMerge } from 'tailwind-merge'
+import { FillPickerRoot } from '@open-pencil/vue'
+
import GradientEditor from './GradientEditor.vue'
import HsvColorArea from './HsvColorArea.vue'
import ImageFillPicker from './ImageFillPicker.vue'
-import { useFillPicker } from '@open-pencil/vue'
-
import Tip from './ui/Tip.vue'
import { usePopoverUI } from './ui/popover'
@@ -26,73 +24,47 @@ function tabClass(active: boolean) {
const { fill } = defineProps<{ fill: Fill }>()
const emit = defineEmits<{ update: [fill: Fill] }>()
const cls = usePopoverUI({ content: 'w-60 p-2' })
-
-const { category, swatchBg, toSolid, toGradient, toImage } = useFillPicker(
- computed(() => fill),
- (updated) => emit('update', updated)
-)
</script>
<template>
- <PopoverRoot>
- <PopoverTrigger as-child>
- <button
- data-test-id="fill-picker-swatch"
- class="size-5 shrink-0 cursor-pointer rounded border border-border p-0"
- :style="{ background: swatchBg }"
- />
- </PopoverTrigger>
-
- <PopoverPortal>
- <PopoverContent :class="cls.content" :side-offset="4" side="left">
- <div class="mb-2 flex items-center gap-0.5">
- <Tip label="Solid">
- <button
- :class="tabClass(category === 'SOLID')"
- data-test-id="fill-picker-tab-solid"
- @click="toSolid"
- >
- <icon-lucide-square class="size-3.5" />
- </button>
- </Tip>
- <Tip label="Gradient">
- <button
- :class="tabClass(category === 'GRADIENT')"
- data-test-id="fill-picker-tab-gradient"
- @click="toGradient"
- >
- <icon-lucide-blend class="size-3.5" />
- </button>
- </Tip>
- <Tip label="Image">
- <button
- :class="tabClass(category === 'IMAGE')"
- data-test-id="fill-picker-tab-image"
- @click="toImage"
- >
- <icon-lucide-image class="size-3.5" />
- </button>
- </Tip>
- </div>
+ <FillPickerRoot
+ :fill="fill"
+ :content-class="cls.content"
+ swatch-class="size-5 shrink-0 cursor-pointer rounded border border-border p-0"
+ @update="emit('update', $event)"
+ >
+ <template #default="{ fill: currentFill, category, toSolid, toGradient, toImage, update }">
+ <div class="mb-2 flex items-center gap-0.5">
+ <Tip label="Solid">
+ <button :class="tabClass(category === 'SOLID')" data-test-id="fill-picker-tab-solid" @click="toSolid">
+ <icon-lucide-square class="size-3.5" />
+ </button>
+ </Tip>
+ <Tip label="Gradient">
+ <button
+ :class="tabClass(category === 'GRADIENT')"
+ data-test-id="fill-picker-tab-gradient"
+ @click="toGradient"
+ >
+ <icon-lucide-blend class="size-3.5" />
+ </button>
+ </Tip>
+ <Tip label="Image">
+ <button :class="tabClass(category === 'IMAGE')" data-test-id="fill-picker-tab-image" @click="toImage">
+ <icon-lucide-image class="size-3.5" />
+ </button>
+ </Tip>
+ </div>
- <HsvColorArea
- v-if="category === 'SOLID'"
- :color="fill.color"
- @update="emit('update', { ...fill, color: $event })"
- />
+ <HsvColorArea
+ v-if="category === 'SOLID'"
+ :color="currentFill.color"
+ @update="update({ ...currentFill, color: $event })"
+ />
- <GradientEditor
- v-if="category === 'GRADIENT'"
- :fill="fill"
- @update="emit('update', $event)"
- />
+ <GradientEditor v-if="category === 'GRADIENT'" :fill="currentFill" @update="update($event)" />
- <ImageFillPicker
- v-if="category === 'IMAGE'"
- :fill="fill"
- @update="emit('update', $event)"
- />
- </PopoverContent>
- </PopoverPortal>
- </PopoverRoot>
+ <ImageFillPicker v-if="category === 'IMAGE'" :fill="currentFill" @update="update($event)" />
+ </template>
+ </FillPickerRoot>
</template>
diff --git a/src/components/FontPicker.vue b/src/components/FontPicker.vue
index df4941f89..56e02b43a 100644
--- a/src/components/FontPicker.vue
+++ b/src/components/FontPicker.vue
@@ -1,22 +1,9 @@
<script setup lang="ts">
-import { nextTick, ref } from 'vue'
-import {
- ComboboxAnchor,
- ComboboxContent,
- ComboboxInput,
- ComboboxItem,
- ComboboxItemIndicator,
- ComboboxPortal,
- ComboboxRoot,
- ComboboxVirtualizer,
- ComboboxViewport,
- type AcceptableValue
-} from 'reka-ui'
+import { FontPickerRoot } from '@open-pencil/vue'
import { useSelectUI } from '@/components/ui/select'
import { usePopoverUI } from '@/components/ui/popover'
import { listFamilies } from '@/engine/fonts'
-import { useFontPicker } from '@open-pencil/vue'
const modelValue = defineModel<string>({ required: true })
const emit = defineEmits<{ select: [family: string] }>()
@@ -24,99 +11,56 @@ const emit = defineEmits<{ select: [family: string] }>()
const cls = usePopoverUI({
content: 'w-[var(--reka-combobox-trigger-width)] min-w-56 overflow-hidden p-0'
})
-const inputRef = ref<HTMLInputElement | null>(null)
const selectCls = useSelectUI({
trigger: 'w-full rounded px-2 py-1 text-xs',
item: 'w-full gap-2 px-2 py-2 text-sm'
})
-
-const { searchTerm, open, filtered, select } = useFontPicker({
- modelValue,
- listFamilies,
- onSelect: (family) => emit('select', family)
-})
</script>
<template>
- <ComboboxRoot
- v-model:open="open"
- :model-value="modelValue"
- :ignore-filter="true"
- @update:model-value="
- (v: AcceptableValue) => {
- if (typeof v === 'string') select(v)
- }
- "
+ <FontPickerRoot
+ v-model="modelValue"
+ data-test-id="font-picker-root"
+ :list-families="listFamilies"
+ :trigger-class="selectCls.trigger"
+ :content-class="cls.content"
+ item-class=""
+ search-class="min-w-0 flex-1 border-none bg-transparent text-xs text-surface outline-none placeholder:text-muted"
+ empty-class="px-2 py-3 text-center text-xs text-muted"
+ empty-fonts-hint="Use the desktop app or Chrome/Edge to access system fonts."
+ @select="emit('select', $event)"
>
- <ComboboxAnchor as-child>
+ <template #trigger>
<button data-test-id="font-picker-trigger" :class="selectCls.trigger">
<span class="truncate">{{ modelValue }}</span>
<icon-lucide-chevron-down class="size-3 shrink-0 text-muted" />
</button>
- </ComboboxAnchor>
+ </template>
- <ComboboxPortal>
- <ComboboxContent
- :side-offset="2"
- align="start"
- position="popper"
- :class="cls.content"
- @open-auto-focus.prevent
- @vue:mounted="nextTick(() => inputRef?.focus())"
- >
- <div class="flex items-center gap-1 border-b border-border px-2 py-1">
- <icon-lucide-search class="size-3 shrink-0 text-muted" />
- <ComboboxInput
- ref="inputRef"
- v-model="searchTerm"
- data-test-id="font-picker-search"
- class="min-w-0 flex-1 border-none bg-transparent text-xs text-surface outline-none placeholder:text-muted"
- placeholder="Search fonts…"
- autocomplete="off"
- autocorrect="off"
- autocapitalize="off"
- spellcheck="false"
- />
- </div>
+ <template #search>
+ <div class="flex items-center gap-1 border-b border-border px-2 py-1">
+ <icon-lucide-search class="size-3 shrink-0 text-muted" />
+ <input
+ class="min-w-0 flex-1 border-none bg-transparent text-xs text-surface outline-none placeholder:text-muted"
+ placeholder="Search fonts…"
+ autocomplete="off"
+ autocorrect="off"
+ autocapitalize="off"
+ spellcheck="false"
+ />
+ </div>
+ </template>
- <ComboboxViewport class="max-h-72 overflow-y-auto">
- <ComboboxVirtualizer
- v-slot="{ option }"
- :options="filtered"
- :text-content="(family: string) => family"
- :estimate-size="36"
- >
- <ComboboxItem
- :value="option"
- data-test-id="font-picker-item"
- :class="selectCls.item"
- :style="{ fontFamily: `'${option}', sans-serif` }"
- >
- <ComboboxItemIndicator>
- <icon-lucide-check class="size-3 shrink-0 text-accent" />
- </ComboboxItemIndicator>
- <span v-if="option !== modelValue" class="size-3 shrink-0" />
- <span class="truncate">{{ option }}</span>
- </ComboboxItem>
- </ComboboxVirtualizer>
-
- <div
- v-if="filtered.length === 0 && searchTerm"
- class="px-2 py-3 text-center text-xs text-muted"
- >
- No fonts found
- </div>
- <div
- v-else-if="filtered.length === 0"
- class="flex h-full items-center justify-center px-3 py-3 text-center text-xs text-muted"
- >
- <div>
- <p>No local fonts available.</p>
- <p class="mt-1">Use the desktop app or Chrome/Edge to access system fonts.</p>
- </div>
- </div>
- </ComboboxViewport>
- </ComboboxContent>
- </ComboboxPortal>
- </ComboboxRoot>
+ <template #item="{ family, selected }">
+ <div
+ data-test-id="font-picker-item"
+ :class="selectCls.item"
+ :style="{ fontFamily: `'${family}', sans-serif` }"
+ >
+ <icon-lucide-check v-if="selected" class="size-3 shrink-0 text-accent" />
+ <span v-else class="size-3 shrink-0" />
+ <span class="truncate">{{ family }}</span>
+ </div>
+ </template>
+ </FontPickerRoot>
</template>
diff --git a/src/components/PagesPanel.vue b/src/components/PagesPanel.vue
index c751f5a19..3622150fa 100644
--- a/src/components/PagesPanel.vue
+++ b/src/components/PagesPanel.vue
@@ -1,21 +1,17 @@
<script setup lang="ts">
import { ref } from 'vue'
-import Tip from '@/components/Tip.vue'
-import { useInlineRename, usePageList } from '@open-pencil/vue'
+import { PageListRoot, useInlineRename } from '@open-pencil/vue'
-const { pages, currentPageId, switchPage, addPage, renamePage } = usePageList()
-
-const DIVIDER_RE = /^[-–—*\s]+$/
-
-function isDivider(page: { name: string; childIds: string[] }) {
- return page.childIds.length === 0 && DIVIDER_RE.test(page.name)
-}
+import Tip from '@/components/ui/Tip.vue'
const pageInputRefs = new Map<string, HTMLInputElement>()
-
-const rename = useInlineRename((id, name) => renamePage(id, name))
const activeRenameId = ref<string | null>(null)
+const rename = useInlineRename((id, name) => pageActions.value?.renamePage(id, name))
+
+const pageActions = ref<{
+ renamePage: (pageId: string, name: string) => void
+} | null>(null)
function setPageInputRef(pageId: string, el: HTMLInputElement | null) {
if (el) pageInputRefs.set(pageId, el)
@@ -34,60 +30,61 @@ function startRename(pg: { id: string; name: string }) {
</script>
<template>
- <div data-test-id="pages-panel" class="flex min-h-0 flex-1 flex-col">
- <div class="flex shrink-0 items-center justify-between px-3 py-1.5">
- <span data-test-id="pages-header" class="text-[11px] tracking-wider text-muted uppercase"
- >Pages</span
- >
- <Tip label="Add page">
- <button
- data-test-id="pages-add"
- class="cursor-pointer rounded border-none bg-transparent px-1 text-base leading-none text-muted hover:bg-hover hover:text-surface"
- @click="addPage()"
+ <PageListRoot v-slot="{ pages, currentPageId, isDivider, addPage, switchPage, renamePage }">
+ <div data-test-id="pages-panel" class="flex min-h-0 flex-1 flex-col">
+ <div class="flex shrink-0 items-center justify-between px-3 py-1.5">
+ <span data-test-id="pages-header" class="text-[11px] tracking-wider text-muted uppercase"
+ >Pages</span
>
- +
- </button>
- </Tip>
- </div>
- <div class="scrollbar-thin overflow-x-hidden overflow-y-auto px-1 pb-1">
- <div v-for="pg in pages" :key="pg.id">
- <div
- v-if="rename.editingId.value === pg.id"
- class="flex w-full items-center gap-1.5 rounded px-2 py-1"
- >
- <icon-lucide-file class="size-3 shrink-0 opacity-70" />
- <input
- :ref="(el) => setPageInputRef(pg.id, el as HTMLInputElement | null)"
- data-test-id="pages-item-input"
- class="min-w-0 flex-1 rounded border border-accent bg-input px-1 py-0 text-xs text-surface outline-none"
- :value="pg.name"
- @blur="rename.commit(pg.id, $event.target as HTMLInputElement)"
- @keydown="rename.onKeydown"
- />
- </div>
- <div
- v-else-if="isDivider(pg)"
- class="my-1 flex items-center px-2"
- @dblclick="startRename(pg)"
- >
- <div class="h-px flex-1 bg-border" />
+ <Tip label="Add page">
+ <button
+ data-test-id="pages-add"
+ class="cursor-pointer rounded border-none bg-transparent px-1 text-base leading-none text-muted hover:bg-hover hover:text-surface"
+ @click="addPage()"
+ >
+ +
+ </button>
+ </Tip>
+ </div>
+ <div class="scrollbar-thin overflow-x-hidden overflow-y-auto px-1 pb-1">
+ <div v-for="pg in pages" :key="pg.id">
+ <div
+ v-if="rename.editingId.value === pg.id"
+ class="flex w-full items-center gap-1.5 rounded px-2 py-1"
+ >
+ <icon-lucide-file class="size-3 shrink-0 opacity-70" />
+ <input
+ :ref="(el) => setPageInputRef(pg.id, el as HTMLInputElement | null)"
+ data-test-id="pages-item-input"
+ class="min-w-0 flex-1 rounded border border-accent bg-input px-1 py-0 text-xs text-surface outline-none"
+ :value="pg.name"
+ @blur="rename.commit(pg.id, $event.target as HTMLInputElement)"
+ @keydown="rename.onKeydown"
+ />
+ </div>
+ <div v-else-if="isDivider(pg)" class="my-1 flex items-center px-2" @dblclick="startRename(pg)">
+ <div class="h-px flex-1 bg-border" />
+ </div>
+ <button
+ v-else
+ data-test-id="pages-item"
+ class="flex w-full cursor-pointer items-center gap-1.5 rounded border-none px-2 py-1 text-left text-xs"
+ :class="
+ pg.id === currentPageId
+ ? 'bg-hover text-surface'
+ : 'bg-transparent text-muted hover:bg-hover hover:text-surface'
+ "
+ @click="switchPage(pg.id)"
+ @dblclick="
+ pageActions = { renamePage }
+ startRename(pg)
+ "
+ >
+ <icon-lucide-file class="size-3 shrink-0" />
+ <span class="truncate">{{ pg.name }}</span>
+ </button>
</div>
- <button
- v-else
- data-test-id="pages-item"
- class="flex w-full cursor-pointer items-center gap-1.5 rounded border-none px-2 py-1 text-left text-xs"
- :class="
- pg.id === currentPageId
- ? 'bg-hover text-surface'
- : 'bg-transparent text-muted hover:bg-hover hover:text-surface'
- "
- @click="switchPage(pg.id)"
- @dblclick="startRename(pg)"
- >
- <icon-lucide-file class="size-3 shrink-0" />
- <span class="truncate">{{ pg.name }}</span>
- </button>
</div>
</div>
- </div>
+ </PageListRoot>
</template>
diff --git a/src/components/VariablesDialog.vue b/src/components/VariablesDialog.vue
index a9d133e49..aae3093ea 100644
--- a/src/components/VariablesDialog.vue
+++ b/src/components/VariablesDialog.vue
@@ -1,253 +1,202 @@
<script setup lang="ts">
import { type Component } from 'vue'
import {
- DialogRoot,
- DialogPortal,
- DialogOverlay,
+ DialogClose,
DialogContent,
+ DialogOverlay,
+ DialogPortal,
+ DialogRoot,
DialogTitle,
- DialogClose,
- TabsRoot,
+ TabsContent,
TabsList,
- TabsTrigger,
- TabsContent
+ TabsRoot,
+ TabsTrigger
} from 'reka-ui'
-import { useVueTable, getCoreRowModel, FlexRender } from '@tanstack/vue-table'
+import { FlexRender } from '@tanstack/vue-table'
+
+import { VariablesEditorRoot } from '@open-pencil/vue'
-import IconPalette from '~icons/lucide/palette'
import IconHash from '~icons/lucide/hash'
-import IconType from '~icons/lucide/type'
+import IconPalette from '~icons/lucide/palette'
import IconToggleLeft from '~icons/lucide/toggle-left'
+import IconType from '~icons/lucide/type'
import IconX from '~icons/lucide/x'
-import Tip from './ui/Tip.vue'
import ColorInput from './ColorInput.vue'
+import Tip from './ui/Tip.vue'
import { useDialogUI } from '@/components/ui/dialog'
-import { useVariablesDialogState, useVariablesTable } from '@open-pencil/vue'
const open = defineModel<boolean>('open', { default: false })
const cls = useDialogUI({ content: 'flex h-[75vh] w-[800px] max-w-[90vw] flex-col' })
-const {
- collections,
- variables,
- activeCollectionId,
- activeModes,
- searchTerm,
- addCollection,
- addVariable,
- removeVariable,
- renameVariable,
- updateVariableValue,
- formatModeValue,
- parseVariableValue,
- shortName,
- editingCollectionId,
- setCollectionInputRef,
- startRenameCollection,
- commitRenameCollection
-} = useVariablesDialogState()
-
-const VARIABLE_TYPE_ICONS: Record<string, Component> = {
+const variableTypeIcons: Record<string, Component> = {
COLOR: IconPalette,
FLOAT: IconHash,
STRING: IconType,
BOOLEAN: IconToggleLeft
}
-
-const { columns } = useVariablesTable({
- activeModes: activeModes,
- formatModeValue,
- parseVariableValue,
- shortName,
- renameVariable,
- updateVariableValue,
- removeVariable,
- ColorInput,
- icons: VARIABLE_TYPE_ICONS,
- fallbackIcon: IconToggleLeft,
- deleteIcon: IconX
-})
-
-const table = useVueTable({
- get data() {
- return variables.value
- },
- get columns() {
- return columns.value
- },
- columnResizeMode: 'onChange',
- getCoreRowModel: getCoreRowModel(),
- defaultColumn: {
- minSize: 60,
- maxSize: 800
- },
- getRowId: (row) => row.id
-})
</script>
<template>
- <DialogRoot v-model:open="open">
- <DialogPortal>
- <DialogOverlay :class="cls.overlay" />
- <DialogContent data-test-id="variables-dialog" :class="cls.content">
- <div v-if="collections.length === 0" class="flex flex-1 flex-col">
- <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>
- <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 class="flex flex-1 items-center justify-center">
- <div class="text-center">
- <p class="text-sm text-muted">No variable collections</p>
- <button
- data-test-id="variables-create-collection"
- class="mt-2 cursor-pointer rounded bg-hover px-3 py-1.5 text-xs text-surface hover:bg-border"
- @click="addCollection"
+ <VariablesEditorRoot
+ v-slot="ctx"
+ :color-input="ColorInput"
+ :icons="variableTypeIcons"
+ :fallback-icon="IconToggleLeft"
+ :delete-icon="IconX"
+ >
+ <DialogRoot v-model:open="open">
+ <DialogPortal>
+ <DialogOverlay :class="cls.overlay" />
+ <DialogContent data-test-id="variables-dialog" :class="cls.content">
+ <div v-if="!ctx.hasCollections" class="flex flex-1 flex-col">
+ <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>
+ <DialogClose
+ class="flex size-6 cursor-pointer items-center justify-center rounded border-none bg-transparent text-muted hover:bg-hover hover:text-surface"
>
- Create collection
- </button>
+ <icon-lucide-x class="size-4" />
+ </DialogClose>
+ </div>
+ <div class="flex flex-1 items-center justify-center">
+ <div class="text-center">
+ <p class="text-sm text-muted">No variable collections</p>
+ <button
+ data-test-id="variables-create-collection"
+ class="mt-2 cursor-pointer rounded bg-hover px-3 py-1.5 text-xs text-surface hover:bg-border"
+ @click="ctx.addCollection"
+ >
+ Create collection
+ </button>
+ </div>
</div>
</div>
- </div>
- <template v-else>
- <TabsRoot v-model="activeCollectionId" class="flex flex-1 flex-col overflow-hidden">
- <!-- Top bar -->
- <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"
- :ref="(el) => setCollectionInputRef(col.id, el as HTMLInputElement | null)"
- 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"
- data-test-id="variables-collection-tab"
- class="cursor-pointer rounded border-none px-2.5 py-1 text-xs whitespace-nowrap text-muted data-[state=active]:bg-hover data-[state=active]:text-surface"
- @dblclick="startRenameCollection(col.id)"
- >
- {{ col.name }}
- </TabsTrigger>
- </template>
- </TabsList>
+ <template v-else>
+ <TabsRoot v-model="ctx.activeCollectionId.value" class="flex flex-1 flex-col overflow-hidden">
+ <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 ctx.collections.value" :key="col.id">
+ <input
+ v-if="ctx.editingCollectionId.value === col.id"
+ :ref="(el) => ctx.setCollectionInputRef(col.id, el as HTMLInputElement | null)"
+ class="w-24 rounded border border-accent bg-input px-2 py-0.5 text-xs text-surface outline-none"
+ :value="col.name"
+ @blur="ctx.commitRenameCollection(col.id, $event.target as HTMLInputElement)"
+ @keydown.enter="($event.target as HTMLInputElement).blur()"
+ @keydown.escape="ctx.editingCollectionId.value = null"
+ />
+ <TabsTrigger
+ v-else
+ :value="col.id"
+ data-test-id="variables-collection-tab"
+ class="cursor-pointer rounded border-none px-2.5 py-1 text-xs whitespace-nowrap text-muted data-[state=active]:bg-hover data-[state=active]:text-surface"
+ @dblclick="ctx.startRenameCollection(col.id)"
+ >
+ {{ col.name }}
+ </TabsTrigger>
+ </template>
+ </TabsList>
- <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"
- data-test-id="variables-search-input"
- class="w-24 border-none bg-transparent text-xs text-surface outline-none placeholder:text-muted"
- placeholder="Search"
- />
- </div>
- <Tip label="Add collection">
- <button
- data-test-id="variables-add-collection"
+ <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="ctx.searchTerm.value"
+ data-test-id="variables-search-input"
+ class="w-24 border-none bg-transparent text-xs text-surface outline-none placeholder:text-muted"
+ placeholder="Search"
+ />
+ </div>
+ <Tip label="Add collection">
+ <button
+ data-test-id="variables-add-collection"
+ class="flex size-6 cursor-pointer items-center justify-center rounded border-none bg-transparent text-muted hover:bg-hover hover:text-surface"
+ @click="ctx.addCollection"
+ >
+ <icon-lucide-folder-plus class="size-3.5" />
+ </button>
+ </Tip>
+ <DialogClose
class="flex size-6 cursor-pointer items-center justify-center rounded border-none bg-transparent text-muted hover:bg-hover hover:text-surface"
- @click="addCollection"
>
- <icon-lucide-folder-plus class="size-3.5" />
- </button>
- </Tip>
- <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>
+ <icon-lucide-x class="size-4" />
+ </DialogClose>
+ </div>
</div>
- </div>
- <!-- Table -->
- <TabsContent
- v-for="col in collections"
- :key="col.id"
- :value="col.id"
- class="flex flex-1 flex-col overflow-hidden outline-none"
- >
- <div class="flex-1 overflow-auto">
- <table
- class="w-full border-collapse"
- :style="{ width: `${table.getCenterTotalSize()}px` }"
- >
- <thead class="sticky top-0 z-10 bg-panel">
- <tr
- v-for="headerGroup in table.getHeaderGroups()"
- :key="headerGroup.id"
- class="border-b border-border"
- >
- <th
- v-for="header in headerGroup.headers"
- :key="header.id"
- class="relative px-4 py-2 text-left text-[11px] font-medium text-muted"
- :style="{ width: `${header.getSize()}px` }"
+ <TabsContent
+ v-for="col in ctx.collections.value"
+ :key="col.id"
+ :value="col.id"
+ class="flex flex-1 flex-col overflow-hidden outline-none"
+ >
+ <div class="flex-1 overflow-auto">
+ <table class="w-full border-collapse" :style="{ width: `${ctx.table.getCenterTotalSize()}px` }">
+ <thead class="sticky top-0 z-10 bg-panel">
+ <tr
+ v-for="headerGroup in ctx.table.getHeaderGroups()"
+ :key="headerGroup.id"
+ class="border-b border-border"
>
- <FlexRender
- v-if="!header.isPlaceholder"
- :render="header.column.columnDef.header"
- :props="header.getContext()"
- />
- <!-- Resize handle -->
- <div
- v-if="header.column.getCanResize()"
- class="absolute top-0 right-0 h-full w-1 cursor-col-resize touch-none select-none"
- :class="
- header.column.getIsResizing()
- ? 'bg-accent'
- : 'bg-transparent hover:bg-border'
- "
- @mousedown="header.getResizeHandler()?.($event)"
- @touchstart="header.getResizeHandler()?.($event)"
- @dblclick="header.column.resetSize()"
- />
- </th>
- </tr>
- </thead>
- <tbody>
- <tr
- v-for="row in table.getRowModel().rows"
- :key="row.id"
- data-test-id="variable-row"
- class="group border-b border-border/30 hover:bg-hover/50"
- >
- <td
- v-for="cell in row.getVisibleCells()"
- :key="cell.id"
- class="px-4 py-1.5"
- :style="{ width: `${cell.column.getSize()}px` }"
+ <th
+ v-for="header in headerGroup.headers"
+ :key="header.id"
+ class="relative px-4 py-2 text-left text-[11px] font-medium text-muted"
+ :style="{ width: `${header.getSize()}px` }"
+ >
+ <FlexRender
+ v-if="!header.isPlaceholder"
+ :render="header.column.columnDef.header"
+ :props="header.getContext()"
+ />
+ <div
+ v-if="header.column.getCanResize()"
+ class="absolute top-0 right-0 h-full w-1 cursor-col-resize touch-none select-none"
+ :class="
+ header.column.getIsResizing()
+ ? 'bg-accent'
+ : 'bg-transparent hover:bg-border'
+ "
+ @mousedown="header.getResizeHandler()?.($event)"
+ @touchstart="header.getResizeHandler()?.($event)"
+ @dblclick="header.column.resetSize()"
+ />
+ </th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr
+ v-for="row in ctx.table.getRowModel().rows"
+ :key="row.id"
+ data-test-id="variable-row"
+ class="group border-b border-border/30 hover:bg-hover/50"
>
- <FlexRender
- :render="cell.column.columnDef.cell"
- :props="cell.getContext()"
- />
- </td>
- </tr>
- </tbody>
- </table>
- </div>
+ <td
+ v-for="cell in row.getVisibleCells()"
+ :key="cell.id"
+ class="px-4 py-1.5"
+ :style="{ width: `${cell.column.getSize()}px` }"
+ >
+ <FlexRender :render="cell.column.columnDef.cell" :props="cell.getContext()" />
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ </div>
- <!-- Footer -->
- <button
- data-test-id="variables-add-variable"
- 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>
- </template>
- </DialogContent>
- </DialogPortal>
- </DialogRoot>
+ <button
+ data-test-id="variables-add-variable"
+ 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="ctx.addVariable"
+ >
+ <icon-lucide-plus class="size-3.5" />
+ Create variable
+ </button>
+ </TabsContent>
+ </TabsRoot>
+ </template>
+ </DialogContent>
+ </DialogPortal>
+ </DialogRoot>
+ </VariablesEditorRoot>
</template>
diff --git a/src/components/properties/AppearanceSection.vue b/src/components/properties/AppearanceSection.vue
index 52e0b566a..9fb895b4c 100644
--- a/src/components/properties/AppearanceSection.vue
+++ b/src/components/properties/AppearanceSection.vue
@@ -1,77 +1,127 @@
<script setup lang="ts">
+import { AppearanceControlsRoot } from '@open-pencil/vue'
+
import ScrubInput from '@/components/ScrubInput.vue'
-import Tip from '@/components/Tip.vue'
+import Tip from '@/components/ui/Tip.vue'
import { sectionWrapper } from '@/components/ui/section'
-import { useAppearance } from '@open-pencil/vue'
-
-const {
- node,
- isMulti,
- active,
- hasCornerRadius,
- independentCorners,
- cornerRadiusValue,
- opacityPercent,
- visibilityState,
- updateProp,
- commitProp,
- toggleVisibility,
- toggleIndependentCorners,
- updateCornerProp,
- commitCornerProp
-} = useAppearance()
</script>
<template>
- <div v-if="active" 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">
- <button
- data-test-id="appearance-visibility"
- class="flex cursor-pointer items-center justify-center rounded border-none bg-transparent p-0.5 text-muted hover:bg-hover hover:text-surface"
- :class="{ 'text-accent': visibilityState === 'hidden' }"
- @click="toggleVisibility"
+ <AppearanceControlsRoot
+ v-slot="{
+ node,
+ isMulti,
+ active,
+ hasCornerRadius,
+ independentCorners,
+ cornerRadiusValue,
+ opacityPercent,
+ visibilityState,
+ updateProp,
+ commitProp,
+ toggleVisibility,
+ toggleIndependentCorners,
+ updateCornerProp,
+ commitCornerProp
+ }"
+ >
+ <div v-if="active" 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">
+ <button
+ data-test-id="appearance-visibility"
+ class="flex cursor-pointer items-center justify-center rounded border-none bg-transparent p-0.5 text-muted hover:bg-hover hover:text-surface"
+ :class="{ 'text-accent': visibilityState === 'hidden' }"
+ @click="toggleVisibility"
+ >
+ <icon-lucide-eye v-if="visibilityState === 'visible'" class="size-3.5" />
+ <icon-lucide-eye-off v-else-if="visibilityState === 'hidden'" class="size-3.5" />
+ <icon-lucide-eye v-else class="size-3.5 opacity-50" />
+ </button>
+ </Tip>
+ </div>
+ <div class="flex gap-1.5">
+ <ScrubInput
+ suffix="%"
+ :model-value="opacityPercent"
+ :min="0"
+ :max="100"
+ @update:model-value="updateProp('opacity', $event / 100)"
+ @commit="(v: number, p: number) => commitProp('opacity', v / 100, p / 100)"
>
- <icon-lucide-eye v-if="visibilityState === 'visible'" class="size-3.5" />
- <icon-lucide-eye-off v-else-if="visibilityState === 'hidden'" class="size-3.5" />
- <icon-lucide-eye class="size-3.5 opacity-50" v-else />
- </button>
- </Tip>
- </div>
- <div class="flex gap-1.5">
- <ScrubInput
- suffix="%"
- :model-value="opacityPercent"
- :min="0"
- :max="100"
- @update:model-value="updateProp('opacity', $event / 100)"
- @commit="(v: number, p: number) => commitProp('opacity', v / 100, p / 100)"
- >
- <template #icon>
- <icon-lucide-blend class="size-3" />
+ <template #icon>
+ <icon-lucide-blend class="size-3" />
+ </template>
+ </ScrubInput>
+ <template v-if="hasCornerRadius">
+ <ScrubInput
+ v-if="independentCorners !== true"
+ data-test-id="corner-radius-input"
+ :model-value="cornerRadiusValue"
+ :min="0"
+ @update:model-value="updateProp('cornerRadius', $event)"
+ @commit="(v: number, p: number) => commitProp('cornerRadius', v, p)"
+ >
+ <template #icon>
+ <icon-lucide-radius class="size-3" />
+ </template>
+ </ScrubInput>
+ <Tip label="Independent corner radii">
+ <button
+ data-test-id="independent-corners-toggle"
+ class="flex size-[26px] shrink-0 cursor-pointer items-center justify-center rounded border border-border bg-input text-muted hover:bg-hover hover:text-surface"
+ :class="{ '!border-accent !text-accent': independentCorners === true }"
+ @click="toggleIndependentCorners"
+ >
+ <svg
+ class="size-3"
+ viewBox="0 0 12 12"
+ fill="none"
+ stroke="currentColor"
+ stroke-width="1.5"
+ >
+ <path d="M1 4V2.5A1.5 1.5 0 0 1 2.5 1H4" />
+ <path d="M8 1h1.5A2.5 2.5 0 0 1 11 3.5V5" />
+ <path d="M11 8v1a2 2 0 0 1-2 2H8" />
+ <path d="M4 11H3a2 2 0 0 1-2-2V8" />
+ </svg>
+ </button>
+ </Tip>
</template>
- </ScrubInput>
- <template v-if="hasCornerRadius">
+ </div>
+
+ <div
+ v-if="hasCornerRadius && independentCorners === true && !isMulti"
+ class="mt-1.5 grid grid-cols-2 gap-1.5"
+ >
<ScrubInput
- v-if="independentCorners !== true"
- data-test-id="corner-radius-input"
- :model-value="cornerRadiusValue"
+ data-test-id="corner-tl-input"
+ :model-value="node!.topLeftRadius"
:min="0"
- @update:model-value="updateProp('cornerRadius', $event)"
- @commit="(v: number, p: number) => commitProp('cornerRadius', v, p)"
+ @update:model-value="updateCornerProp('topLeftRadius', $event)"
+ @commit="(v: number, p: number) => commitCornerProp('topLeftRadius', v, p)"
>
<template #icon>
- <icon-lucide-radius class="size-3" />
+ <svg
+ class="size-3"
+ viewBox="0 0 12 12"
+ fill="none"
+ stroke="currentColor"
+ stroke-width="1.5"
+ >
+ <path d="M1 11V4a3 3 0 0 1 3-3h7" />
+ </svg>
</template>
</ScrubInput>
- <Tip label="Independent corner radii">
- <button
- data-test-id="independent-corners-toggle"
- class="flex size-[26px] shrink-0 cursor-pointer items-center justify-center rounded border border-border bg-input text-muted hover:bg-hover hover:text-surface"
- :class="{ '!border-accent !text-accent': independentCorners === true }"
- @click="toggleIndependentCorners"
- >
+ <ScrubInput
+ data-test-id="corner-tr-input"
+ :model-value="node!.topRightRadius"
+ :min="0"
+ @update:model-value="updateCornerProp('topRightRadius', $event)"
+ @commit="(v: number, p: number) => commitCornerProp('topRightRadius', v, p)"
+ >
+ <template #icon>
<svg
class="size-3"
viewBox="0 0 12 12"
@@ -79,96 +129,49 @@ const {
stroke="currentColor"
stroke-width="1.5"
>
- <path d="M1 4V2.5A1.5 1.5 0 0 1 2.5 1H4" />
- <path d="M8 1h1.5A2.5 2.5 0 0 1 11 3.5V5" />
- <path d="M11 8v1a2 2 0 0 1-2 2H8" />
- <path d="M4 11H3a2 2 0 0 1-2-2V8" />
+ <path d="M11 11V4a3 3 0 0 0-3-3H1" />
</svg>
- </button>
- </Tip>
- </template>
- </div>
-
- <div
- v-if="hasCornerRadius && independentCorners === true && !isMulti"
- class="mt-1.5 grid grid-cols-2 gap-1.5"
- >
- <ScrubInput
- data-test-id="corner-tl-input"
- :model-value="node!.topLeftRadius"
- :min="0"
- @update:model-value="updateCornerProp('topLeftRadius', $event)"
- @commit="(v: number, p: number) => commitCornerProp('topLeftRadius', v, p)"
- >
- <template #icon>
- <svg
- class="size-3"
- viewBox="0 0 12 12"
- fill="none"
- stroke="currentColor"
- stroke-width="1.5"
- >
- <path d="M1 11V4a3 3 0 0 1 3-3h7" />
- </svg>
- </template>
- </ScrubInput>
- <ScrubInput
- data-test-id="corner-tr-input"
- :model-value="node!.topRightRadius"
- :min="0"
- @update:model-value="updateCornerProp('topRightRadius', $event)"
- @commit="(v: number, p: number) => commitCornerProp('topRightRadius', v, p)"
- >
- <template #icon>
- <svg
- class="size-3"
- viewBox="0 0 12 12"
- fill="none"
- stroke="currentColor"
- stroke-width="1.5"
- >
- <path d="M11 11V4a3 3 0 0 0-3-3H1" />
- </svg>
- </template>
- </ScrubInput>
- <ScrubInput
- data-test-id="corner-bl-input"
- :model-value="node!.bottomLeftRadius"
- :min="0"
- @update:model-value="updateCornerProp('bottomLeftRadius', $event)"
- @commit="(v: number, p: number) => commitCornerProp('bottomLeftRadius', v, p)"
- >
- <template #icon>
- <svg
- class="size-3"
- viewBox="0 0 12 12"
- fill="none"
- stroke="currentColor"
- stroke-width="1.5"
- >
- <path d="M1 1v7a3 3 0 0 0 3 3h7" />
- </svg>
- </template>
- </ScrubInput>
- <ScrubInput
- data-test-id="corner-br-input"
- :model-value="node!.bottomRightRadius"
- :min="0"
- @update:model-value="updateCornerProp('bottomRightRadius', $event)"
- @commit="(v: number, p: number) => commitCornerProp('bottomRightRadius', v, p)"
- >
- <template #icon>
- <svg
- class="size-3"
- viewBox="0 0 12 12"
- fill="none"
- stroke="currentColor"
- stroke-width="1.5"
- >
- <path d="M11 1v7a3 3 0 0 1-3 3H1" />
- </svg>
- </template>
- </ScrubInput>
+ </template>
+ </ScrubInput>
+ <ScrubInput
+ data-test-id="corner-bl-input"
+ :model-value="node!.bottomLeftRadius"
+ :min="0"
+ @update:model-value="updateCornerProp('bottomLeftRadius', $event)"
+ @commit="(v: number, p: number) => commitCornerProp('bottomLeftRadius', v, p)"
+ >
+ <template #icon>
+ <svg
+ class="size-3"
+ viewBox="0 0 12 12"
+ fill="none"
+ stroke="currentColor"
+ stroke-width="1.5"
+ >
+ <path d="M1 1v7a3 3 0 0 0 3 3h7" />
+ </svg>
+ </template>
+ </ScrubInput>
+ <ScrubInput
+ data-test-id="corner-br-input"
+ :model-value="node!.bottomRightRadius"
+ :min="0"
+ @update:model-value="updateCornerProp('bottomRightRadius', $event)"
+ @commit="(v: number, p: number) => commitCornerProp('bottomRightRadius', v, p)"
+ >
+ <template #icon>
+ <svg
+ class="size-3"
+ viewBox="0 0 12 12"
+ fill="none"
+ stroke="currentColor"
+ stroke-width="1.5"
+ >
+ <path d="M11 1v7a3 3 0 0 1-3 3H1" />
+ </svg>
+ </template>
+ </ScrubInput>
+ </div>
</div>
- </div>
+ </AppearanceControlsRoot>
</template>
diff --git a/src/components/properties/EffectsSection.vue b/src/components/properties/EffectsSection.vue
index 0af515d87..af24544ec 100644
--- a/src/components/properties/EffectsSection.vue
+++ b/src/components/properties/EffectsSection.vue
@@ -1,243 +1,149 @@
<script setup lang="ts">
-import { ref } from 'vue'
-import AppSelect from '@/components/AppSelect.vue'
+import AppSelect from '@/components/ui/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 { EffectsControlsRoot, PropertyListRoot } from '@open-pencil/vue'
import { colorToCSS } from '@open-pencil/core'
-import type { Color, Effect, SceneNode } from '@open-pencil/core'
-
-const editor = useEditor()
-
-const expandedIndex = ref<number | null>(null)
-const effectsBeforeScrub = ref<Effect[] | null>(null)
-
-type EffectType = Effect['type']
-
-const EFFECT_LABELS: Record<string, string> = {
- DROP_SHADOW: 'Drop shadow',
- INNER_SHADOW: 'Inner shadow',
- LAYER_BLUR: 'Layer blur',
- BACKGROUND_BLUR: 'Background blur',
- FOREGROUND_BLUR: 'Foreground blur'
-}
-
-const EFFECT_TYPES = Object.keys(EFFECT_LABELS) as EffectType[]
-const EFFECT_OPTIONS = EFFECT_TYPES.map((t) => ({ value: t, label: EFFECT_LABELS[t] }))
-
-function isShadow(type: string) {
- return type === 'DROP_SHADOW' || type === 'INNER_SHADOW'
-}
-
-function defaultEffect(): Effect {
- return {
- type: 'DROP_SHADOW',
- color: { r: 0, g: 0, b: 0, a: 0.25 },
- offset: { x: 0, y: 4 },
- radius: 4,
- spread: 0,
- visible: true
- }
-}
-
-function scrubEffect(node: SceneNode | null, index: number, changes: Partial<Effect>) {
- if (!node) return
- if (!effectsBeforeScrub.value) {
- effectsBeforeScrub.value = node.effects.map((e) => ({
- ...e,
- color: { ...e.color },
- offset: { ...e.offset }
- }))
- }
- const effects = [...node.effects]
- effects[index] = { ...effects[index], ...changes }
- editor.updateNode(node.id, { effects })
- editor.requestRender()
-}
-
-function commitEffect(node: SceneNode | null, index: number, changes: Partial<Effect>) {
- if (!node) return
- const previous = effectsBeforeScrub.value
- effectsBeforeScrub.value = null
- const effects = [...node.effects]
- effects[index] = { ...effects[index], ...changes }
- editor.updateNode(node.id, { effects })
- editor.requestRender()
- if (previous) {
- editor.commitNodeUpdate(node.id, { effects: previous }, 'Change effect')
- }
-}
-
-function updateType(
- patch: (index: number, changes: Partial<Effect>) => void,
- node: SceneNode | null,
- index: number,
- type: EffectType
-) {
- if (!node) return
- const changes: Partial<Effect> = { type }
- if (!isShadow(type)) {
- changes.offset = { x: 0, y: 0 }
- changes.spread = 0
- } else if (!isShadow(node.effects[index].type)) {
- changes.offset = { x: 0, y: 4 }
- changes.spread = 0
- }
- patch(index, changes)
-}
-
-function updateColor(
- patch: (index: number, changes: Partial<Effect>) => void,
- index: number,
- color: Color
-) {
- patch(index, { color })
-}
-
-function handleRemove(removeFn: (index: number) => void, index: number) {
- removeFn(index)
- if (expandedIndex.value === index) expandedIndex.value = null
- else if (expandedIndex.value !== null && expandedIndex.value > index) expandedIndex.value--
-}
-
-function toggleExpand(index: number) {
- expandedIndex.value = expandedIndex.value === index ? null : index
-}
+import type { Effect } from '@open-pencil/core'
</script>
<template>
- <PropertyListRoot
- v-slot="{ items, isMixed, activeNode, patch, add, remove, toggleVisibility }"
- prop-key="effects"
- label="Effects"
- >
- <div data-test-id="effects-section" :class="sectionWrapper()">
- <div class="flex items-center justify-between">
- <label :class="sectionLabel()">Effects</label>
- <button
- data-test-id="effects-section-add"
- :class="iconButton()"
- @click="add(defaultEffect())"
- >
- +
- </button>
- </div>
-
- <p v-if="isMixed" class="text-[11px] text-muted">Click + to replace mixed effects</p>
-
- <div
- v-for="(effect, i) in items as Effect[]"
- :key="i"
- data-test-id="effects-item"
- :data-test-index="i"
- >
- <!-- Collapsed row: color swatch | type dropdown | eye | minus -->
- <div class="group flex items-center gap-1.5 py-0.5">
- <button
- v-if="isShadow(effect.type)"
- class="size-5 shrink-0 cursor-pointer rounded border border-border"
- :style="{ background: colorToCSS(effect.color) }"
- @click="toggleExpand(i)"
- />
+ <EffectsControlsRoot v-slot="effectsCtx">
+ <PropertyListRoot
+ v-slot="{ items, isMixed, activeNode, patch, add, remove, toggleVisibility }"
+ prop-key="effects"
+ label="Effects"
+ >
+ <div data-test-id="effects-section" :class="sectionWrapper()">
+ <div class="flex items-center justify-between">
+ <label :class="sectionLabel()">Effects</label>
<button
- v-else
- class="flex size-5 shrink-0 cursor-pointer items-center justify-center rounded border border-border bg-input"
- @click="toggleExpand(i)"
+ data-test-id="effects-section-add"
+ :class="iconButton()"
+ @click="add(effectsCtx.defaultEffect)"
>
- <icon-lucide-blend class="size-3 text-muted" />
+ +
</button>
-
- <AppSelect
- :model-value="effect.type"
- :options="EFFECT_OPTIONS"
- @update:model-value="updateType(patch, activeNode, i, $event as EffectType)"
- />
-
- <button
- class="cursor-pointer border-none bg-transparent p-0 text-muted hover:text-surface"
- @click="toggleVisibility(i)"
- >
- <icon-lucide-eye v-if="effect.visible" class="size-3.5" />
- <icon-lucide-eye-off v-else class="size-3.5" />
- </button>
- <button :class="iconButton()" @click="handleRemove(remove, i)">−</button>
</div>
- <!-- Expanded controls inline -->
- <div v-if="expandedIndex === i" class="flex flex-col gap-1.5 py-1.5">
- <template v-if="isShadow(effect.type)">
- <div class="flex items-center gap-1.5">
- <ScrubInput
- icon="X"
- :model-value="effect.offset.x"
- @update:model-value="
- scrubEffect(activeNode, i, { offset: { ...effect.offset, x: $event } })
- "
- @commit="commitEffect(activeNode, i, { offset: { ...effect.offset, x: $event } })"
- />
- <ScrubInput
- icon="Y"
- :model-value="effect.offset.y"
- @update:model-value="
- scrubEffect(activeNode, i, { offset: { ...effect.offset, y: $event } })
- "
- @commit="commitEffect(activeNode, i, { offset: { ...effect.offset, y: $event } })"
- />
- </div>
+ <p v-if="isMixed" class="text-[11px] text-muted">Click + to replace mixed effects</p>
- <div class="flex items-center gap-1.5">
+ <div
+ v-for="(effect, i) in items as Effect[]"
+ :key="i"
+ data-test-id="effects-item"
+ :data-test-index="i"
+ >
+ <div class="group flex items-center gap-1.5 py-0.5">
+ <button
+ v-if="effectsCtx.isShadow(effect.type)"
+ class="size-5 shrink-0 cursor-pointer rounded border border-border"
+ :style="{ background: colorToCSS(effect.color) }"
+ @click="effectsCtx.toggleExpand(i)"
+ />
+ <button
+ v-else
+ class="flex size-5 shrink-0 cursor-pointer items-center justify-center rounded border border-border bg-input"
+ @click="effectsCtx.toggleExpand(i)"
+ >
+ <icon-lucide-blend class="size-3 text-muted" />
+ </button>
+
+ <AppSelect
+ :model-value="effect.type"
+ :options="effectsCtx.effectOptions"
+ @update:model-value="effectsCtx.updateType(patch, activeNode, i, $event as Effect['type'])"
+ />
+
+ <button
+ class="cursor-pointer border-none bg-transparent p-0 text-muted hover:text-surface"
+ @click="toggleVisibility(i)"
+ >
+ <icon-lucide-eye v-if="effect.visible" class="size-3.5" />
+ <icon-lucide-eye-off v-else class="size-3.5" />
+ </button>
+ <button :class="iconButton()" @click="effectsCtx.handleRemove(remove, i)">−</button>
+ </div>
+
+ <div v-if="effectsCtx.expandedIndex === i" class="flex flex-col gap-1.5 py-1.5">
+ <template v-if="effectsCtx.isShadow(effect.type)">
+ <div class="flex items-center gap-1.5">
+ <ScrubInput
+ icon="X"
+ :model-value="effect.offset.x"
+ @update:model-value="
+ effectsCtx.scrubEffect(activeNode, i, { offset: { ...effect.offset, x: $event } })
+ "
+ @commit="
+ effectsCtx.commitEffect(activeNode, i, { offset: { ...effect.offset, x: $event } })
+ "
+ />
+ <ScrubInput
+ icon="Y"
+ :model-value="effect.offset.y"
+ @update:model-value="
+ effectsCtx.scrubEffect(activeNode, i, { offset: { ...effect.offset, y: $event } })
+ "
+ @commit="
+ effectsCtx.commitEffect(activeNode, i, { offset: { ...effect.offset, y: $event } })
+ "
+ />
+ </div>
+
+ <div class="flex items-center gap-1.5">
+ <ScrubInput
+ icon="B"
+ :model-value="effect.radius"
+ :min="0"
+ @update:model-value="effectsCtx.scrubEffect(activeNode, i, { radius: $event })"
+ @commit="effectsCtx.commitEffect(activeNode, i, { radius: $event })"
+ />
+ <ScrubInput
+ icon="S"
+ :model-value="effect.spread"
+ @update:model-value="effectsCtx.scrubEffect(activeNode, i, { spread: $event })"
+ @commit="effectsCtx.commitEffect(activeNode, i, { spread: $event })"
+ />
+ </div>
+
+ <div class="flex items-center gap-1.5">
+ <ColorInput :color="effect.color" editable @update="effectsCtx.updateColor(patch, i, $event)" />
+ <ScrubInput
+ class="w-14"
+ suffix="%"
+ :model-value="Math.round(effect.color.a * 100)"
+ :min="0"
+ :max="100"
+ @update:model-value="
+ effectsCtx.scrubEffect(activeNode, i, {
+ color: { ...effect.color, a: Math.max(0, Math.min(1, $event / 100)) }
+ })
+ "
+ @commit="
+ effectsCtx.commitEffect(activeNode, i, {
+ color: { ...effect.color, a: Math.max(0, Math.min(1, $event / 100)) }
+ })
+ "
+ />
+ </div>
+ </template>
+
+ <template v-else>
<ScrubInput
icon="B"
:model-value="effect.radius"
:min="0"
- @update:model-value="scrubEffect(activeNode, i, { radius: $event })"
- @commit="commitEffect(activeNode, i, { radius: $event })"
- />
- <ScrubInput
- icon="S"
- :model-value="effect.spread"
- @update:model-value="scrubEffect(activeNode, i, { spread: $event })"
- @commit="commitEffect(activeNode, i, { spread: $event })"
+ @update:model-value="effectsCtx.scrubEffect(activeNode, i, { radius: $event })"
+ @commit="effectsCtx.commitEffect(activeNode, i, { radius: $event })"
/>
- </div>
-
- <div class="flex items-center gap-1.5">
- <ColorInput :color="effect.color" editable @update="updateColor(patch, i, $event)" />
- <ScrubInput
- class="w-14"
- suffix="%"
- :model-value="Math.round(effect.color.a * 100)"
- :min="0"
- :max="100"
- @update:model-value="
- scrubEffect(activeNode, i, {
- color: { ...effect.color, a: Math.max(0, Math.min(1, $event / 100)) }
- })
- "
- @commit="
- commitEffect(activeNode, i, {
- color: { ...effect.color, a: Math.max(0, Math.min(1, $event / 100)) }
- })
- "
- />
- </div>
- </template>
-
- <template v-else>
- <ScrubInput
- icon="B"
- :model-value="effect.radius"
- :min="0"
- @update:model-value="scrubEffect(activeNode, i, { radius: $event })"
- @commit="commitEffect(activeNode, i, { radius: $event })"
- />
- </template>
+ </template>
+ </div>
</div>
</div>
- </div>
- </PropertyListRoot>
+ </PropertyListRoot>
+ </EffectsControlsRoot>
</template>
diff --git a/src/components/properties/FillSection.vue b/src/components/properties/FillSection.vue
index dfa419379..bb1bdeed5 100644
--- a/src/components/properties/FillSection.vue
+++ b/src/components/properties/FillSection.vue
@@ -1,186 +1,158 @@
<script setup lang="ts">
-import { computed, ref } from 'vue'
import {
- PopoverRoot,
- PopoverTrigger,
- PopoverPortal,
- PopoverContent,
- ComboboxRoot,
- ComboboxInput,
ComboboxContent,
- ComboboxItem,
ComboboxEmpty,
- useFilter
+ ComboboxInput,
+ ComboboxItem,
+ ComboboxRoot,
+ PopoverContent,
+ PopoverPortal,
+ PopoverRoot,
+ PopoverTrigger
} from 'reka-ui'
+import { colorToCSS, colorToHexRaw } from '@open-pencil/core'
+import { FillControlsRoot, PropertyListRoot } from '@open-pencil/vue'
+
import FillPicker from '@/components/FillPicker.vue'
import ScrubInput from '@/components/ScrubInput.vue'
-import Tip from '@/components/Tip.vue'
+import Tip from '@/components/ui/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'
import type { Fill, Variable } from '@open-pencil/core'
-
-const store = useEditor()
-
-const colorVariables = computed(() => store.getVariablesByType('COLOR'))
-
-function getBoundVariable(nodeId: string, index: number): Variable | undefined {
- const n = store.getNode(nodeId)
- if (!n) return undefined
- const varId = n.boundVariables[`fills/${index}/color`]
- return varId ? store.getVariable(varId) : undefined
-}
-
-function bindFillVariable(nodeId: string, index: number, variableId: string) {
- store.bindVariable(nodeId, `fills/${index}/color`, variableId)
-}
-
-function unbindFillVariable(nodeId: string, index: number) {
- store.unbindVariable(nodeId, `fills/${index}/color`)
-}
-
-function resolvedSwatchStyle(variable: Variable): string {
- const color = store.resolveColorVariable(variable.id)
- if (!color) return 'background: #000'
- return `background: ${colorToCSS(color)}`
-}
-
-const searchTerm = ref('')
-const { contains } = useFilter({ sensitivity: 'base' })
-const filteredVariables = computed(() => {
- if (!searchTerm.value) return colorVariables.value
- return colorVariables.value.filter((v) => contains(v.name, searchTerm.value))
-})
</script>
<template>
- <PropertyListRoot
- v-slot="{ items, isMixed, activeNode, add, remove, update, patch, toggleVisibility }"
- prop-key="fills"
- label="Fill"
- >
- <div data-test-id="fill-section" :class="sectionWrapper()">
- <div class="flex items-center justify-between">
- <label :class="sectionLabel()">Fill</label>
- <button
- data-test-id="fill-section-add"
- :class="iconButton()"
- @click="add({ ...DEFAULT_SHAPE_FILL })"
+ <FillControlsRoot v-slot="fillCtx">
+ <PropertyListRoot
+ v-slot="{ items, isMixed, activeNode, add, remove, update, patch, toggleVisibility }"
+ prop-key="fills"
+ label="Fill"
+ >
+ <div data-test-id="fill-section" :class="sectionWrapper()">
+ <div class="flex items-center justify-between">
+ <label :class="sectionLabel()">Fill</label>
+ <button
+ data-test-id="fill-section-add"
+ :class="iconButton()"
+ @click="add({ ...fillCtx.defaultFill })"
+ >
+ +
+ </button>
+ </div>
+ <p v-if="isMixed" class="text-[11px] text-muted">Click + to replace mixed fills</p>
+ <div
+ v-for="(fill, i) in items as Fill[]"
+ :key="i"
+ data-test-id="fill-item"
+ :data-test-index="i"
+ class="group flex items-center gap-1.5 py-0.5"
>
- +
- </button>
- </div>
- <p v-if="isMixed" class="text-[11px] text-muted">Click + to replace mixed fills</p>
- <div
- v-for="(fill, i) in items as Fill[]"
- :key="i"
- data-test-id="fill-item"
- :data-test-index="i"
- class="group flex items-center gap-1.5 py-0.5"
- >
- <FillPicker :fill="fill" @update="update(i, $event)" />
+ <FillPicker :fill="fill" @update="update(i, $event)" />
- <template v-if="activeNode && getBoundVariable(activeNode.id, i)">
- <span
- class="min-w-0 flex-1 truncate rounded bg-violet-500/10 px-1 font-mono text-xs text-violet-400"
- >
- {{ getBoundVariable(activeNode.id, i)!.name }}
- </span>
- <Tip label="Detach variable">
- <button
- data-test-id="fill-unbind-variable"
- class="cursor-pointer border-none bg-transparent p-0 text-violet-400 hover:text-surface"
- @click="unbindFillVariable(activeNode.id, i)"
+ <template v-if="activeNode && fillCtx.getBoundVariable(activeNode.id, i)">
+ <span
+ class="min-w-0 flex-1 truncate rounded bg-violet-500/10 px-1 font-mono text-xs text-violet-400"
>
- <icon-lucide-unlink class="size-3" />
- </button>
- </Tip>
- </template>
- <template v-else>
- <span class="min-w-0 flex-1 font-mono text-xs text-surface">
- <template v-if="fill.type === 'SOLID'">{{ colorToHexRaw(fill.color) }}</template>
- <template v-else-if="fill.type.startsWith('GRADIENT')">{{
- fill.type.replace('GRADIENT_', '')
- }}</template>
- <template v-else>{{ fill.type }}</template>
- </span>
- </template>
+ {{ fillCtx.getBoundVariable(activeNode.id, i)!.name }}
+ </span>
+ <Tip label="Detach variable">
+ <button
+ data-test-id="fill-unbind-variable"
+ class="cursor-pointer border-none bg-transparent p-0 text-violet-400 hover:text-surface"
+ @click="fillCtx.unbindFillVariable(activeNode.id, i)"
+ >
+ <icon-lucide-unlink class="size-3" />
+ </button>
+ </Tip>
+ </template>
+ <template v-else>
+ <span class="min-w-0 flex-1 font-mono text-xs text-surface">
+ <template v-if="fill.type === 'SOLID'">{{ colorToHexRaw(fill.color) }}</template>
+ <template v-else-if="fill.type.startsWith('GRADIENT')">{{
+ fill.type.replace('GRADIENT_', '')
+ }}</template>
+ <template v-else>{{ fill.type }}</template>
+ </span>
+ </template>
- <ScrubInput
- class="w-12"
- suffix="%"
- :model-value="Math.round(fill.opacity * 100)"
- :min="0"
- :max="100"
- @update:model-value="patch(i, { opacity: Math.max(0, Math.min(1, $event / 100)) })"
- />
+ <ScrubInput
+ class="w-12"
+ suffix="%"
+ :model-value="Math.round(fill.opacity * 100)"
+ :min="0"
+ :max="100"
+ @update:model-value="patch(i, { opacity: Math.max(0, Math.min(1, $event / 100)) })"
+ />
- <PopoverRoot
- v-if="
- colorVariables.length > 0 &&
- fill.type === 'SOLID' &&
- activeNode &&
- !getBoundVariable(activeNode.id, i)
- "
- >
- <Tip label="Apply variable">
- <PopoverTrigger
- class="cursor-pointer border-none bg-transparent p-0 text-muted hover:text-surface"
- >
- <icon-lucide-link class="size-3.5" />
- </PopoverTrigger>
- </Tip>
- <PopoverPortal>
- <PopoverContent
- side="left"
- :side-offset="8"
- class="z-50 w-56 rounded-lg border border-border bg-panel shadow-lg"
- >
- <ComboboxRoot
- @update:model-value="
- activeNode && bindFillVariable(activeNode.id, i, ($event as Variable).id)
- "
+ <PopoverRoot
+ v-if="
+ fillCtx.colorVariables.length > 0 &&
+ fill.type === 'SOLID' &&
+ activeNode &&
+ !fillCtx.getBoundVariable(activeNode.id, i)
+ "
+ >
+ <Tip label="Apply variable">
+ <PopoverTrigger class="cursor-pointer border-none bg-transparent p-0 text-muted hover:text-surface">
+ <icon-lucide-link class="size-3.5" />
+ </PopoverTrigger>
+ </Tip>
+ <PopoverPortal>
+ <PopoverContent
+ side="left"
+ :side-offset="8"
+ class="z-50 w-56 rounded-lg border border-border bg-panel shadow-lg"
>
- <ComboboxInput
- v-model="searchTerm"
- placeholder="Search variables…"
- class="w-full border-b border-border bg-transparent px-2 py-1.5 text-[11px] text-surface outline-none placeholder:text-muted"
- />
- <ComboboxContent class="max-h-48 overflow-y-auto p-1">
- <ComboboxEmpty class="px-2 py-3 text-center text-[11px] text-muted"
- >No variables found</ComboboxEmpty
- >
- <ComboboxItem
- v-for="v in filteredVariables"
- :key="v.id"
- :value="v"
- class="flex cursor-pointer items-center gap-2 rounded px-2 py-1 text-[11px] text-surface data-[highlighted]:bg-hover"
- >
- <div
- class="size-3 shrink-0 rounded-sm border border-border"
- :style="resolvedSwatchStyle(v)"
- />
- <span class="min-w-0 flex-1 truncate">{{ v.name }}</span>
- </ComboboxItem>
- </ComboboxContent>
- </ComboboxRoot>
- </PopoverContent>
- </PopoverPortal>
- </PopoverRoot>
+ <ComboboxRoot
+ @update:model-value="
+ activeNode && fillCtx.bindFillVariable(activeNode.id, i, ($event as Variable).id)
+ "
+ >
+ <ComboboxInput
+ :model-value="fillCtx.searchTerm"
+ @update:model-value="fillCtx.searchTerm = String($event)"
+ placeholder="Search variables…"
+ class="w-full border-b border-border bg-transparent px-2 py-1.5 text-[11px] text-surface outline-none placeholder:text-muted"
+ />
+ <ComboboxContent class="max-h-48 overflow-y-auto p-1">
+ <ComboboxEmpty class="px-2 py-3 text-center text-[11px] text-muted"
+ >No variables found</ComboboxEmpty
+ >
+ <ComboboxItem
+ v-for="v in fillCtx.filteredVariables"
+ :key="v.id"
+ :value="v"
+ class="flex cursor-pointer items-center gap-2 rounded px-2 py-1 text-[11px] text-surface data-[highlighted]:bg-hover"
+ >
+ <div
+ class="size-3 shrink-0 rounded-sm border border-border"
+ :style="{
+ background:
+ fillCtx.store.resolveColorVariable(v.id)
+ ? colorToCSS(fillCtx.store.resolveColorVariable(v.id)!)
+ : '#000'
+ }"
+ />
+ <span class="min-w-0 flex-1 truncate">{{ v.name }}</span>
+ </ComboboxItem>
+ </ComboboxContent>
+ </ComboboxRoot>
+ </PopoverContent>
+ </PopoverPortal>
+ </PopoverRoot>
- <button
- class="cursor-pointer border-none bg-transparent p-0 text-muted hover:text-surface"
- @click="toggleVisibility(i)"
- >
- <icon-lucide-eye v-if="fill.visible" class="size-3.5" />
- <icon-lucide-eye-off v-else class="size-3.5" />
- </button>
- <button :class="iconButton()" @click="remove(i)">−</button>
+ <button
+ class="cursor-pointer border-none bg-transparent p-0 text-muted hover:text-surface"
+ @click="toggleVisibility(i)"
+ >
+ <icon-lucide-eye v-if="fill.visible" class="size-3.5" />
+ <icon-lucide-eye-off v-else class="size-3.5" />
+ </button>
+ <button :class="iconButton()" @click="remove(i)">−</button>
+ </div>
</div>
- </div>
- </PropertyListRoot>
+ </PropertyListRoot>
+ </FillControlsRoot>
</template>
diff --git a/src/components/properties/LayoutSection.vue b/src/components/properties/LayoutSection.vue
index bbd155f12..a58f89fa2 100644
--- a/src/components/properties/LayoutSection.vue
+++ b/src/components/properties/LayoutSection.vue
@@ -1,300 +1,275 @@
<script setup lang="ts">
-import AppSelect from '@/components/AppSelect.vue'
+import { LayoutControlsRoot } from '@open-pencil/vue'
+
+import AppSelect from '@/components/ui/AppSelect.vue'
import ScrubInput from '@/components/ScrubInput.vue'
-import Tip from '@/components/Tip.vue'
+import Tip from '@/components/ui/Tip.vue'
import { sectionWrapper } from '@/components/ui/section'
-import { useLayout } from '@open-pencil/vue'
-
-const {
- editor: store,
- node,
- isInAutoLayout,
- isGrid,
- isFlex,
- widthSizing,
- heightSizing,
- widthSizingOptions,
- heightSizingOptions,
- alignGrid,
- showIndividualPadding,
- hasUniformPadding,
- trackSizingOptions,
- updateProp,
- commitProp,
- setWidthSizing,
- setHeightSizing,
- setUniformPadding,
- commitUniformPadding,
- setAlignment,
- updateGridTrack,
- addTrack,
- removeTrack,
- trackLabel,
- toggleIndividualPadding
-} = useLayout()
</script>
<template>
- <template v-if="node">
- <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">
- <ScrubInput
- icon="W"
- :model-value="Math.round(node.width)"
- :min="0"
- @update:model-value="updateProp('width', $event)"
- @commit="(v: number, p: number) => commitProp('width', v, p)"
- />
- <AppSelect
- v-if="isFlex || isInAutoLayout"
- :model-value="widthSizing"
- :options="widthSizingOptions"
- @update:model-value="setWidthSizing"
- />
- </div>
- <div class="flex min-w-0 flex-1 items-center gap-1">
- <ScrubInput
- icon="H"
- :model-value="Math.round(node.height)"
- :min="0"
- @update:model-value="updateProp('height', $event)"
- @commit="(v: number, p: number) => commitProp('height', v, p)"
- />
- <AppSelect
- v-if="isFlex || isInAutoLayout"
- :model-value="heightSizing"
- :options="heightSizingOptions"
- @update:model-value="setHeightSizing"
- />
+ <LayoutControlsRoot v-slot="ctx">
+ <template v-if="ctx.node">
+ <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">
+ <ScrubInput
+ icon="W"
+ :model-value="Math.round(ctx.node.width)"
+ :min="0"
+ @update:model-value="ctx.updateProp('width', $event)"
+ @commit="(v: number, p: number) => ctx.commitProp('width', v, p)"
+ />
+ <AppSelect
+ v-if="ctx.isFlex || ctx.isInAutoLayout"
+ :model-value="ctx.widthSizing"
+ :options="ctx.widthSizingOptions"
+ @update:model-value="ctx.setWidthSizing"
+ />
+ </div>
+ <div class="flex min-w-0 flex-1 items-center gap-1">
+ <ScrubInput
+ icon="H"
+ :model-value="Math.round(ctx.node.height)"
+ :min="0"
+ @update:model-value="ctx.updateProp('height', $event)"
+ @commit="(v: number, p: number) => ctx.commitProp('height', v, p)"
+ />
+ <AppSelect
+ v-if="ctx.isFlex || ctx.isInAutoLayout"
+ :model-value="ctx.heightSizing"
+ :options="ctx.heightSizingOptions"
+ @update:model-value="ctx.setHeightSizing"
+ />
+ </div>
</div>
</div>
- </div>
-
- <template v-if="node.type === 'FRAME'">
- <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)">
- <button
- class="cursor-pointer rounded border-none bg-transparent px-1 text-base leading-none text-muted hover:bg-hover hover:text-surface"
- data-test-id="layout-add-auto"
- @click="store.setLayoutMode(node.id, 'VERTICAL')"
- >
- +
- </button>
- </Tip>
- <Tip v-else label="Remove auto layout">
- <button
- class="cursor-pointer rounded border-none bg-transparent px-1 text-base leading-none text-muted hover:bg-hover hover:text-surface"
- data-test-id="layout-remove-auto"
- @click="store.setLayoutMode(node.id, 'NONE')"
- >
- −
- </button>
- </Tip>
- </div>
-
- <template v-if="node.layoutMode !== 'NONE'">
- <div class="mt-1.5 flex gap-0.5">
- <button
- v-for="dir in [
- { mode: 'HORIZONTAL', icon: 'arrow-right', test: 'horizontal' },
- { mode: 'VERTICAL', icon: 'arrow-down', test: 'vertical' },
- { mode: 'GRID', icon: 'layout-grid', test: 'grid' }
- ] as const"
- :key="dir.mode"
- :data-test-id="`layout-direction-${dir.test}`"
- class="flex cursor-pointer items-center justify-center rounded border px-2 py-1"
- :class="
- (dir.mode === 'GRID' ? isGrid : node.layoutMode === dir.mode)
- ? 'border-accent bg-accent/10 text-accent'
- : 'border-border text-muted hover:bg-hover hover:text-surface'
- "
- @click="store.setLayoutMode(node.id, dir.mode)"
- >
- <component :is="`icon-lucide-${dir.icon}`" class="size-3.5" />
- </button>
- <button
- v-if="isFlex"
- data-test-id="layout-direction-wrap"
- class="flex cursor-pointer items-center justify-center rounded border px-2 py-1"
- :class="
- node.layoutWrap === 'WRAP'
- ? 'border-accent bg-accent/10 text-accent'
- : 'border-border text-muted hover:bg-hover hover:text-surface'
- "
- @click="updateProp('layoutWrap', node.layoutWrap === 'WRAP' ? 'NO_WRAP' : 'WRAP')"
- >
- <icon-lucide-wrap-text class="size-3.5" />
- </button>
- </div>
- <!-- Grid tracks -->
- <template v-if="isGrid">
- <div
- v-for="trackProp in ['gridTemplateColumns', 'gridTemplateRows'] as const"
- :key="trackProp"
- class="mt-2"
- >
- <div class="mb-1 flex items-center justify-between">
- <label class="text-[11px] text-muted">{{
- trackProp === 'gridTemplateColumns' ? 'Columns' : 'Rows'
- }}</label>
- <button
- class="cursor-pointer rounded border-none bg-transparent px-1 text-xs leading-none text-muted hover:bg-hover hover:text-surface"
- @click="addTrack(trackProp)"
- >
- +
- </button>
- </div>
- <div class="flex flex-col gap-1">
- <div v-for="(track, i) in node[trackProp]" :key="i" class="flex items-center gap-1">
- <ScrubInput
- v-if="track.sizing !== 'AUTO'"
- class="flex-1"
- :icon="`${trackProp === 'gridTemplateColumns' ? 'C' : 'R'}${i + 1}`"
- :model-value="track.value"
- :min="track.sizing === 'FR' ? 1 : 0"
- :suffix="track.sizing === 'FR' ? 'fr' : 'px'"
- @update:model-value="updateGridTrack(trackProp, i, { value: $event })"
- />
- <span v-else class="flex-1 px-1 text-xs text-muted">{{ trackLabel(track) }}</span>
- <AppSelect
- :model-value="track.sizing"
- :options="trackSizingOptions"
- @update:model-value="
- updateGridTrack(trackProp, i, {
- sizing: $event,
- value: $event === 'FR' ? 1 : $event === 'FIXED' ? 100 : 0
- })
- "
- />
- <button
- v-if="node[trackProp].length > 1"
- class="cursor-pointer rounded border-none bg-transparent px-0.5 text-xs text-muted hover:text-surface"
- @click="removeTrack(trackProp, i)"
- >
- ×
- </button>
- </div>
- </div>
- </div>
- <div class="mt-2 grid grid-cols-2 gap-1.5">
- <ScrubInput
- icon="↔"
- :model-value="Math.round(node.gridColumnGap)"
- :min="0"
- @update:model-value="updateProp('gridColumnGap', $event)"
- @commit="(v: number, p: number) => commitProp('gridColumnGap', v, p)"
- />
- <ScrubInput
- icon="↕"
- :model-value="Math.round(node.gridRowGap)"
- :min="0"
- @update:model-value="updateProp('gridRowGap', $event)"
- @commit="(v: number, p: number) => commitProp('gridRowGap', v, p)"
- />
- </div>
- </template>
-
- <!-- Flex gap + padding toggle -->
- <template v-if="isFlex">
- <div class="mt-2 flex items-center gap-1.5">
- <ScrubInput
- data-test-id="layout-gap-input"
- class="flex-1"
- :icon="node.layoutMode === 'VERTICAL' ? '↕' : '↔'"
- :model-value="Math.round(node.itemSpacing)"
- :min="0"
- @update:model-value="updateProp('itemSpacing', $event)"
- @commit="(v: number, p: number) => commitProp('itemSpacing', v, p)"
- />
+ <template v-if="ctx.node.type === 'FRAME'">
+ <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="ctx.node.layoutMode === 'NONE'" label="Add auto layout (Shift+A)">
<button
- class="flex size-7 shrink-0 cursor-pointer items-center justify-center rounded border border-border bg-transparent text-muted hover:bg-hover hover:text-surface"
- @click="toggleIndividualPadding"
+ class="cursor-pointer rounded border-none bg-transparent px-1 text-base leading-none text-muted hover:bg-hover hover:text-surface"
+ data-test-id="layout-add-auto"
+ @click="ctx.editor.setLayoutMode(ctx.node.id, 'VERTICAL')"
>
- <icon-lucide-minus
- v-if="showIndividualPadding || !hasUniformPadding"
- class="size-3"
- />
- <icon-lucide-plus v-else class="size-3" />
+ +
</button>
- </div>
- <div v-if="!showIndividualPadding && hasUniformPadding" class="mt-1.5">
- <ScrubInput
- data-test-id="layout-uniform-padding-input"
- icon="☐"
- :model-value="Math.round(node.paddingTop)"
- :min="0"
- @update:model-value="setUniformPadding"
- @commit="commitUniformPadding"
- />
- </div>
- </template>
+ </Tip>
+ <Tip v-else label="Remove auto layout">
+ <button
+ class="cursor-pointer rounded border-none bg-transparent px-1 text-base leading-none text-muted hover:bg-hover hover:text-surface"
+ data-test-id="layout-remove-auto"
+ @click="ctx.editor.setLayoutMode(ctx.node.id, 'NONE')"
+ >
+ −
+ </button>
+ </Tip>
+ </div>
- <!-- Per-side padding -->
- <template v-if="isGrid || (isFlex && (showIndividualPadding || !hasUniformPadding))">
- <div class="mt-1.5 grid grid-cols-2 gap-1.5">
- <ScrubInput
- v-for="side in [
- 'paddingTop',
- 'paddingRight',
- 'paddingBottom',
- 'paddingLeft'
+ <template v-if="ctx.node.layoutMode !== 'NONE'">
+ <div class="mt-1.5 flex gap-0.5">
+ <button
+ v-for="dir in [
+ { mode: 'HORIZONTAL', icon: 'arrow-right', test: 'horizontal' },
+ { mode: 'VERTICAL', icon: 'arrow-down', test: 'vertical' },
+ { mode: 'GRID', icon: 'layout-grid', test: 'grid' }
] as const"
- :key="side"
- :icon="side[7]"
- :model-value="Math.round(node[side])"
- :min="0"
- @update:model-value="updateProp(side, $event)"
- @commit="(v: number, p: number) => commitProp(side, v, p)"
- />
- </div>
- </template>
-
- <!-- Alignment grid (flex only) -->
- <div v-if="isFlex" class="mt-2">
- <label class="mb-1 block text-[11px] text-muted">Alignment</label>
- <div data-test-id="layout-alignment-grid" class="grid w-fit grid-cols-3 gap-0.5">
+ :key="dir.mode"
+ :data-test-id="`layout-direction-${dir.test}`"
+ class="flex cursor-pointer items-center justify-center rounded border px-2 py-1"
+ :class="
+ (dir.mode === 'GRID' ? ctx.isGrid : ctx.node.layoutMode === dir.mode)
+ ? 'border-accent bg-accent/10 text-accent'
+ : 'border-border text-muted hover:bg-hover hover:text-surface'
+ "
+ @click="ctx.editor.setLayoutMode(ctx.node.id, dir.mode)"
+ >
+ <component :is="`icon-lucide-${dir.icon}`" class="size-3.5" />
+ </button>
<button
- v-for="cell in alignGrid"
- :key="`${cell.primary}-${cell.counter}`"
- class="flex size-6 cursor-pointer items-center justify-center rounded border text-[11px]"
+ v-if="ctx.isFlex"
+ data-test-id="layout-direction-wrap"
+ class="flex cursor-pointer items-center justify-center rounded border px-2 py-1"
:class="
- node.primaryAxisAlign === cell.primary && node.counterAxisAlign === cell.counter
+ ctx.node.layoutWrap === 'WRAP'
? 'border-accent bg-accent/10 text-accent'
: 'border-border text-muted hover:bg-hover hover:text-surface'
"
- @click="setAlignment(cell.primary, cell.counter)"
+ @click="ctx.updateProp('layoutWrap', ctx.node.layoutWrap === 'WRAP' ? 'NO_WRAP' : 'WRAP')"
>
- <span class="size-1.5 rounded-full bg-current" />
+ <icon-lucide-wrap-text class="size-3.5" />
</button>
</div>
- </div>
- </template>
- </div>
- <!-- Clip content -->
- <div :class="sectionWrapper()">
- <label class="flex cursor-pointer items-center gap-2 text-xs text-surface">
- <input
- type="checkbox"
- data-test-id="clip-content-checkbox"
- class="accent-accent"
- :checked="node.clipsContent"
- @change="
- store.updateNodeWithUndo(
- node.id,
- { clipsContent: !node.clipsContent },
- 'Toggle clip content'
- )
- "
- />
- Clip content
- </label>
- </div>
+ <template v-if="ctx.isGrid">
+ <div
+ v-for="trackProp in ['gridTemplateColumns', 'gridTemplateRows'] as const"
+ :key="trackProp"
+ class="mt-2"
+ >
+ <div class="mb-1 flex items-center justify-between">
+ <label class="text-[11px] text-muted">{{
+ trackProp === 'gridTemplateColumns' ? 'Columns' : 'Rows'
+ }}</label>
+ <button
+ class="cursor-pointer rounded border-none bg-transparent px-1 text-xs leading-none text-muted hover:bg-hover hover:text-surface"
+ @click="ctx.addTrack(trackProp)"
+ >
+ +
+ </button>
+ </div>
+ <div class="flex flex-col gap-1">
+ <div
+ v-for="(track, i) in ctx.node[trackProp]"
+ :key="i"
+ class="flex items-center gap-1"
+ >
+ <ScrubInput
+ v-if="track.sizing !== 'AUTO'"
+ class="flex-1"
+ :icon="`${trackProp === 'gridTemplateColumns' ? 'C' : 'R'}${i + 1}`"
+ :model-value="track.value"
+ :min="track.sizing === 'FR' ? 1 : 0"
+ :suffix="track.sizing === 'FR' ? 'fr' : 'px'"
+ @update:model-value="ctx.updateGridTrack(trackProp, i, { value: $event })"
+ />
+ <span v-else class="flex-1 px-1 text-xs text-muted">{{ ctx.trackLabel(track) }}</span>
+ <AppSelect
+ :model-value="track.sizing"
+ :options="ctx.trackSizingOptions"
+ @update:model-value="
+ ctx.updateGridTrack(trackProp, i, {
+ sizing: $event,
+ value: $event === 'FR' ? 1 : $event === 'FIXED' ? 100 : 0
+ })
+ "
+ />
+ <button
+ v-if="ctx.node[trackProp].length > 1"
+ class="cursor-pointer rounded border-none bg-transparent px-0.5 text-xs text-muted hover:text-surface"
+ @click="ctx.removeTrack(trackProp, i)"
+ >
+ ×
+ </button>
+ </div>
+ </div>
+ </div>
+ <div class="mt-2 grid grid-cols-2 gap-1.5">
+ <ScrubInput
+ icon="↔"
+ :model-value="Math.round(ctx.node.gridColumnGap)"
+ :min="0"
+ @update:model-value="ctx.updateProp('gridColumnGap', $event)"
+ @commit="(v: number, p: number) => ctx.commitProp('gridColumnGap', v, p)"
+ />
+ <ScrubInput
+ icon="↕"
+ :model-value="Math.round(ctx.node.gridRowGap)"
+ :min="0"
+ @update:model-value="ctx.updateProp('gridRowGap', $event)"
+ @commit="(v: number, p: number) => ctx.commitProp('gridRowGap', v, p)"
+ />
+ </div>
+ </template>
+
+ <template v-if="ctx.isFlex">
+ <div class="mt-2 flex items-center gap-1.5">
+ <ScrubInput
+ data-test-id="layout-gap-input"
+ class="flex-1"
+ :icon="ctx.node.layoutMode === 'VERTICAL' ? '↕' : '↔'"
+ :model-value="Math.round(ctx.node.itemSpacing)"
+ :min="0"
+ @update:model-value="ctx.updateProp('itemSpacing', $event)"
+ @commit="(v: number, p: number) => ctx.commitProp('itemSpacing', v, p)"
+ />
+ <button
+ class="flex size-7 shrink-0 cursor-pointer items-center justify-center rounded border border-border bg-transparent text-muted hover:bg-hover hover:text-surface"
+ @click="ctx.toggleIndividualPadding"
+ >
+ <icon-lucide-minus
+ v-if="ctx.showIndividualPadding || !ctx.hasUniformPadding"
+ class="size-3"
+ />
+ <icon-lucide-plus v-else class="size-3" />
+ </button>
+ </div>
+ <div v-if="!ctx.showIndividualPadding && ctx.hasUniformPadding" class="mt-1.5">
+ <ScrubInput
+ data-test-id="layout-uniform-padding-input"
+ icon="☐"
+ :model-value="Math.round(ctx.node.paddingTop)"
+ :min="0"
+ @update:model-value="ctx.setUniformPadding"
+ @commit="ctx.commitUniformPadding"
+ />
+ </div>
+ </template>
+
+ <template v-if="ctx.isGrid || (ctx.isFlex && (ctx.showIndividualPadding || !ctx.hasUniformPadding))">
+ <div class="mt-1.5 grid grid-cols-2 gap-1.5">
+ <ScrubInput
+ v-for="side in [
+ 'paddingTop',
+ 'paddingRight',
+ 'paddingBottom',
+ 'paddingLeft'
+ ] as const"
+ :key="side"
+ :icon="side[7]"
+ :model-value="Math.round(ctx.node[side])"
+ :min="0"
+ @update:model-value="ctx.updateProp(side, $event)"
+ @commit="(v: number, p: number) => ctx.commitProp(side, v, p)"
+ />
+ </div>
+ </template>
+
+ <div v-if="ctx.isFlex" class="mt-2">
+ <label class="mb-1 block text-[11px] text-muted">Alignment</label>
+ <div data-test-id="layout-alignment-grid" class="grid w-fit grid-cols-3 gap-0.5">
+ <button
+ v-for="cell in ctx.alignGrid"
+ :key="`${cell.primary}-${cell.counter}`"
+ class="flex size-6 cursor-pointer items-center justify-center rounded border text-[11px]"
+ :class="
+ ctx.node.primaryAxisAlign === cell.primary &&
+ ctx.node.counterAxisAlign === cell.counter
+ ? 'border-accent bg-accent/10 text-accent'
+ : 'border-border text-muted hover:bg-hover hover:text-surface'
+ "
+ @click="ctx.setAlignment(cell.primary, cell.counter)"
+ >
+ <span class="size-1.5 rounded-full bg-current" />
+ </button>
+ </div>
+ </div>
+ </template>
+ </div>
+
+ <div :class="sectionWrapper()">
+ <label class="flex cursor-pointer items-center gap-2 text-xs text-surface">
+ <input
+ type="checkbox"
+ data-test-id="clip-content-checkbox"
+ class="accent-accent"
+ :checked="ctx.node.clipsContent"
+ @change="
+ ctx.editor.updateNodeWithUndo(
+ ctx.node.id,
+ { clipsContent: !ctx.node.clipsContent },
+ 'Toggle clip content'
+ )
+ "
+ />
+ Clip content
+ </label>
+ </div>
+ </template>
</template>
- </template>
+ </LayoutControlsRoot>
</template>
diff --git a/src/components/properties/PositionSection.vue b/src/components/properties/PositionSection.vue
index 64472b5c0..9241b1c94 100644
--- a/src/components/properties/PositionSection.vue
+++ b/src/components/properties/PositionSection.vue
@@ -1,179 +1,153 @@
<script setup lang="ts">
-import { computed } from 'vue'
-
import ScrubInput from '@/components/ScrubInput.vue'
import Tip from '@/components/ui/Tip.vue'
import { iconButton } from '@/components/ui/icon-button'
import { sectionWrapper } from '@/components/ui/section'
-import { useNodeProps } from '@open-pencil/vue'
-
-const {
- store,
- updateProp,
- commitProp,
- node,
- nodes,
- isMulti,
- active,
- prop: multiProp
-} = useNodeProps()
-
-const xValue = computed(() =>
- isMulti.value ? multiProp('x').value : Math.round(node.value?.x ?? 0)
-)
-const yValue = computed(() =>
- isMulti.value ? multiProp('y').value : Math.round(node.value?.y ?? 0)
-)
-const wValue = multiProp('width')
-const hValue = multiProp('height')
-const rotationValue = computed(() =>
- isMulti.value ? multiProp('rotation').value : Math.round(node.value?.rotation ?? 0)
-)
-const ids = computed(() => nodes.value.map((n) => n.id))
+import { PositionControlsRoot } from '@open-pencil/vue'
</script>
<template>
- <div v-if="active" data-test-id="position-section" :class="sectionWrapper()">
- <label class="mb-1.5 block text-[11px] text-muted">Position</label>
+ <PositionControlsRoot
+ v-slot="{ active, isMulti, xValue, yValue, wValue, hValue, rotationValue, updateProp, commitProp, align, flip, rotate }"
+ >
+ <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 -->
- <div class="mb-1.5 flex gap-2">
- <div class="flex gap-0.5">
- <Tip label="Align left">
- <button
- :class="iconButton({ size: 'md' })"
- data-test-id="position-align-left"
- @click="store.alignNodes(ids, 'horizontal', 'min')"
- >
- <icon-lucide-align-horizontal-justify-start class="size-3.5" />
- </button>
- </Tip>
- <Tip label="Align center horizontally">
- <button
- :class="iconButton({ size: 'md' })"
- data-test-id="position-align-center-h"
- @click="store.alignNodes(ids, 'horizontal', 'center')"
- >
- <icon-lucide-align-horizontal-justify-center class="size-3.5" />
- </button>
- </Tip>
- <Tip label="Align right">
- <button
- :class="iconButton({ size: 'md' })"
- data-test-id="position-align-right"
- @click="store.alignNodes(ids, 'horizontal', 'max')"
- >
- <icon-lucide-align-horizontal-justify-end class="size-3.5" />
- </button>
- </Tip>
+ <div class="mb-1.5 flex gap-2">
+ <div class="flex gap-0.5">
+ <Tip label="Align left">
+ <button
+ :class="iconButton({ size: 'md' })"
+ data-test-id="position-align-left"
+ @click="align('horizontal', 'min')"
+ >
+ <icon-lucide-align-horizontal-justify-start class="size-3.5" />
+ </button>
+ </Tip>
+ <Tip label="Align center horizontally">
+ <button
+ :class="iconButton({ size: 'md' })"
+ data-test-id="position-align-center-h"
+ @click="align('horizontal', 'center')"
+ >
+ <icon-lucide-align-horizontal-justify-center class="size-3.5" />
+ </button>
+ </Tip>
+ <Tip label="Align right">
+ <button
+ :class="iconButton({ size: 'md' })"
+ data-test-id="position-align-right"
+ @click="align('horizontal', 'max')"
+ >
+ <icon-lucide-align-horizontal-justify-end class="size-3.5" />
+ </button>
+ </Tip>
+ </div>
+ <div class="flex gap-0.5">
+ <Tip label="Align top">
+ <button
+ :class="iconButton({ size: 'md' })"
+ data-test-id="position-align-top"
+ @click="align('vertical', 'min')"
+ >
+ <icon-lucide-align-vertical-justify-start class="size-3.5" />
+ </button>
+ </Tip>
+ <Tip label="Align center vertically">
+ <button
+ :class="iconButton({ size: 'md' })"
+ data-test-id="position-align-center-v"
+ @click="align('vertical', 'center')"
+ >
+ <icon-lucide-align-vertical-justify-center class="size-3.5" />
+ </button>
+ </Tip>
+ <Tip label="Align bottom">
+ <button
+ :class="iconButton({ size: 'md' })"
+ data-test-id="position-align-bottom"
+ @click="align('vertical', 'max')"
+ >
+ <icon-lucide-align-vertical-justify-end class="size-3.5" />
+ </button>
+ </Tip>
+ </div>
</div>
- <div class="flex gap-0.5">
- <Tip label="Align top">
+
+ <div class="flex gap-1.5">
+ <ScrubInput
+ icon="X"
+ :model-value="xValue"
+ @update:model-value="updateProp('x', $event)"
+ @commit="(v: number, p: number) => commitProp('x', v, p)"
+ />
+ <ScrubInput
+ icon="Y"
+ :model-value="yValue"
+ @update:model-value="updateProp('y', $event)"
+ @commit="(v: number, p: number) => commitProp('y', v, p)"
+ />
+ </div>
+
+ <div v-if="isMulti" class="mt-1.5 flex gap-1.5">
+ <ScrubInput
+ icon="W"
+ :model-value="wValue"
+ :min="1"
+ @update:model-value="updateProp('width', $event)"
+ @commit="(v: number, p: number) => commitProp('width', v, p)"
+ />
+ <ScrubInput
+ icon="H"
+ :model-value="hValue"
+ :min="1"
+ @update:model-value="updateProp('height', $event)"
+ @commit="(v: number, p: number) => commitProp('height', v, p)"
+ />
+ </div>
+
+ <div class="mt-1.5 flex items-center gap-1.5">
+ <ScrubInput
+ class="flex-1"
+ suffix="°"
+ :model-value="rotationValue"
+ :min="-360"
+ :max="360"
+ @update:model-value="updateProp('rotation', $event)"
+ @commit="(v: number, p: number) => commitProp('rotation', v, p)"
+ >
+ <template #icon>
+ <icon-lucide-rotate-ccw class="size-3" />
+ </template>
+ </ScrubInput>
+ <Tip label="Flip horizontal">
<button
- :class="iconButton({ size: 'md' })"
- data-test-id="position-align-top"
- @click="store.alignNodes(ids, 'vertical', 'min')"
+ :class="iconButton({ size: 'md', ui: { base: 'shrink-0' } })"
+ data-test-id="position-flip-horizontal"
+ @click="flip('horizontal')"
>
- <icon-lucide-align-vertical-justify-start class="size-3.5" />
+ <icon-lucide-flip-horizontal class="size-3.5" />
</button>
</Tip>
- <Tip label="Align center vertically">
+ <Tip label="Flip vertical">
<button
- :class="iconButton({ size: 'md' })"
- data-test-id="position-align-center-v"
- @click="store.alignNodes(ids, 'vertical', 'center')"
+ :class="iconButton({ size: 'md', ui: { base: 'shrink-0' } })"
+ data-test-id="position-flip-vertical"
+ @click="flip('vertical')"
>
- <icon-lucide-align-vertical-justify-center class="size-3.5" />
+ <icon-lucide-flip-vertical class="size-3.5" />
</button>
</Tip>
- <Tip label="Align bottom">
+ <Tip label="Rotate 90°">
<button
- :class="iconButton({ size: 'md' })"
- data-test-id="position-align-bottom"
- @click="store.alignNodes(ids, 'vertical', 'max')"
+ :class="iconButton({ size: 'md', ui: { base: 'shrink-0' } })"
+ data-test-id="position-rotate-90"
+ @click="rotate(90)"
>
- <icon-lucide-align-vertical-justify-end class="size-3.5" />
+ <icon-lucide-rotate-cw class="size-3.5" />
</button>
</Tip>
</div>
</div>
-
- <!-- X / Y -->
- <div class="flex gap-1.5">
- <ScrubInput
- icon="X"
- :model-value="xValue"
- @update:model-value="updateProp('x', $event)"
- @commit="(v: number, p: number) => commitProp('x', v, p)"
- />
- <ScrubInput
- icon="Y"
- :model-value="yValue"
- @update:model-value="updateProp('y', $event)"
- @commit="(v: number, p: number) => commitProp('y', v, p)"
- />
- </div>
-
- <!-- W / H (multi-select only; single-select shows in LayoutSection) -->
- <div v-if="isMulti" class="mt-1.5 flex gap-1.5">
- <ScrubInput
- icon="W"
- :model-value="wValue"
- :min="1"
- @update:model-value="updateProp('width', $event)"
- @commit="(v: number, p: number) => commitProp('width', v, p)"
- />
- <ScrubInput
- icon="H"
- :model-value="hValue"
- :min="1"
- @update:model-value="updateProp('height', $event)"
- @commit="(v: number, p: number) => commitProp('height', v, p)"
- />
- </div>
-
- <!-- Rotation + flip -->
- <div class="mt-1.5 flex items-center gap-1.5">
- <ScrubInput
- class="flex-1"
- suffix="°"
- :model-value="rotationValue"
- :min="-360"
- :max="360"
- @update:model-value="updateProp('rotation', $event)"
- @commit="(v: number, p: number) => commitProp('rotation', v, p)"
- >
- <template #icon>
- <icon-lucide-rotate-ccw class="size-3" />
- </template>
- </ScrubInput>
- <Tip label="Flip horizontal">
- <button
- :class="iconButton({ size: 'md', ui: { base: 'shrink-0' } })"
- data-test-id="position-flip-horizontal"
- @click="store.flipNodes(ids, 'horizontal')"
- >
- <icon-lucide-flip-horizontal class="size-3.5" />
- </button>
- </Tip>
- <Tip label="Flip vertical">
- <button
- :class="iconButton({ size: 'md', ui: { base: 'shrink-0' } })"
- data-test-id="position-flip-vertical"
- @click="store.flipNodes(ids, 'vertical')"
- >
- <icon-lucide-flip-vertical class="size-3.5" />
- </button>
- </Tip>
- <Tip label="Rotate 90°">
- <button
- :class="iconButton({ size: 'md', ui: { base: 'shrink-0' } })"
- data-test-id="position-rotate-90"
- @click="store.rotateNodes(ids, 90)"
- >
- <icon-lucide-rotate-cw class="size-3.5" />
- </button>
- </Tip>
- </div>
- </div>
+ </PositionControlsRoot>
</template>
diff --git a/src/components/properties/StrokeSection.vue b/src/components/properties/StrokeSection.vue
index 740b2dee1..daa1667c4 100644
--- a/src/components/properties/StrokeSection.vue
+++ b/src/components/properties/StrokeSection.vue
@@ -1,350 +1,218 @@
<script setup lang="ts">
-import { ref } from 'vue'
import {
- DropdownMenuRoot,
- DropdownMenuTrigger,
DropdownMenuContent,
DropdownMenuItem,
- DropdownMenuPortal
+ DropdownMenuPortal,
+ DropdownMenuRoot,
+ DropdownMenuTrigger
} from 'reka-ui'
+import { PropertyListRoot, StrokeControlsRoot } from '@open-pencil/vue'
+
import AppSelect from '@/components/ui/AppSelect.vue'
import ColorInput from '@/components/ColorInput.vue'
import ScrubInput from '@/components/ScrubInput.vue'
import Tip from '@/components/ui/Tip.vue'
import { iconButton } from '@/components/ui/icon-button'
-import { sectionLabel, sectionWrapper } from '@/components/ui/section'
-import { PropertyListRoot, useEditor } from '@open-pencil/vue'
import { menu, useMenuUI } from '@/components/ui/menu'
+import { sectionLabel, sectionWrapper } from '@/components/ui/section'
import type { SceneNode, Stroke } from '@open-pencil/core'
-
-type StrokeSides = 'ALL' | 'TOP' | 'BOTTOM' | 'LEFT' | 'RIGHT' | 'CUSTOM'
-
-const store = useEditor()
-
-const ALIGN_OPTIONS: { value: Stroke['align']; label: string }[] = [
- { value: 'INSIDE', label: 'Inside' },
- { value: 'CENTER', label: 'Center' },
- { value: 'OUTSIDE', label: 'Outside' }
-]
-
-const SIDE_OPTIONS: { value: StrokeSides; label: string }[] = [
- { value: 'ALL', label: 'All' },
- { value: 'TOP', label: 'Top' },
- { value: 'BOTTOM', label: 'Bottom' },
- { value: 'LEFT', label: 'Left' },
- { value: 'RIGHT', label: 'Right' },
- { value: 'CUSTOM', label: 'Custom' }
-]
-
-const BORDER_SIDES = ['top', 'right', 'bottom', 'left'] as const
-
-const sideMenuOpen = ref(false)
-const sideMenuCls = useMenuUI({
- content: 'min-w-[140px] rounded-md p-0.5',
- item: 'relative px-2'
-})
-
-function updateAlign(align: Stroke['align'], activeNode: SceneNode) {
- const strokes = activeNode.strokes.map((s) => ({ ...s, align }))
- store.updateNodeWithUndo(activeNode.id, { strokes }, 'Change stroke align')
-}
-
-function currentAlign(activeNode: SceneNode | null): Stroke['align'] {
- if (!activeNode || activeNode.strokes.length === 0) return 'CENTER'
- return activeNode.strokes[0].align
-}
-
-function currentSides(activeNode: SceneNode | null): StrokeSides {
- if (!activeNode?.independentStrokeWeights) return 'ALL'
- const {
- borderTopWeight: t,
- borderRightWeight: r,
- borderBottomWeight: b,
- borderLeftWeight: l
- } = activeNode
- const active = [t > 0, r > 0, b > 0, l > 0]
- const count = active.filter(Boolean).length
- if (count === 4 && t === r && r === b && b === l) return 'ALL'
- if (count === 1) {
- if (t > 0) return 'TOP'
- if (b > 0) return 'BOTTOM'
- if (l > 0) return 'LEFT'
- if (r > 0) return 'RIGHT'
- }
- return 'CUSTOM'
-}
-
-function selectSide(side: StrokeSides, activeNode: SceneNode) {
- const weight = activeNode.strokes.length > 0 ? activeNode.strokes[0].weight : 1
- if (side === 'ALL') {
- store.updateNodeWithUndo(
- activeNode.id,
- {
- independentStrokeWeights: false,
- borderTopWeight: 0,
- borderRightWeight: 0,
- borderBottomWeight: 0,
- borderLeftWeight: 0
- } as Partial<SceneNode>,
- 'Stroke all sides'
- )
- } else if (side === 'CUSTOM') {
- const w = activeNode.independentStrokeWeights
- ? {
- top: activeNode.borderTopWeight,
- right: activeNode.borderRightWeight,
- bottom: activeNode.borderBottomWeight,
- left: activeNode.borderLeftWeight
- }
- : { top: weight, right: weight, bottom: weight, left: weight }
- store.updateNodeWithUndo(
- activeNode.id,
- {
- independentStrokeWeights: true,
- borderTopWeight: w.top,
- borderRightWeight: w.right,
- borderBottomWeight: w.bottom,
- borderLeftWeight: w.left
- } as Partial<SceneNode>,
- 'Custom stroke sides'
- )
- } else {
- store.updateNodeWithUndo(
- activeNode.id,
- {
- independentStrokeWeights: true,
- borderTopWeight: side === 'TOP' ? weight : 0,
- borderRightWeight: side === 'RIGHT' ? weight : 0,
- borderBottomWeight: side === 'BOTTOM' ? weight : 0,
- borderLeftWeight: side === 'LEFT' ? weight : 0
- } as Partial<SceneNode>,
- `Stroke ${side.toLowerCase()} only`
- )
- }
- sideMenuOpen.value = false
-}
-
-function updateBorderWeight(
- side: (typeof BORDER_SIDES)[number],
- value: number,
- activeNode: SceneNode
-) {
- const key = `border${side[0].toUpperCase()}${side.slice(1)}Weight` as keyof SceneNode
- store.updateNodeWithUndo(
- activeNode.id,
- { [key]: value } as Partial<SceneNode>,
- 'Change stroke weight'
- )
-}
-
-const DEFAULT_STROKE: Stroke = {
- color: { r: 0, g: 0, b: 0, a: 1 },
- weight: 1,
- opacity: 1,
- visible: true,
- align: 'CENTER'
-}
</script>
<template>
- <PropertyListRoot
- v-slot="{ items, isMixed, activeNode, add, remove, patch, toggleVisibility }"
- prop-key="strokes"
- label="Stroke"
- >
- <div data-test-id="stroke-section" :class="sectionWrapper()">
- <div class="flex items-center justify-between">
- <label :class="sectionLabel()">Stroke</label>
- <button
- data-test-id="stroke-section-add"
- :class="iconButton()"
- @click="add(DEFAULT_STROKE)"
- >
- +
- </button>
- </div>
-
- <p v-if="isMixed" class="text-[11px] text-muted">Click + to replace mixed strokes</p>
-
- <div
- v-for="(stroke, i) in items as Stroke[]"
- :key="i"
- data-test-id="stroke-item"
- :data-test-index="i"
- class="group flex items-center gap-1.5 py-0.5"
- >
- <ColorInput
- class="min-w-0 flex-1"
- :color="stroke.color"
- editable
- @update="patch(i, { color: $event })"
- />
- <button
- class="shrink-0 cursor-pointer border-none bg-transparent p-0 text-muted hover:text-surface"
- @click="toggleVisibility(i)"
+ <StrokeControlsRoot v-slot="strokeCtx">
+ <PropertyListRoot
+ v-slot="{ items, isMixed, activeNode, add, remove, patch, toggleVisibility }"
+ prop-key="strokes"
+ label="Stroke"
+ >
+ <div data-test-id="stroke-section" :class="sectionWrapper()">
+ <div class="flex items-center justify-between">
+ <label :class="sectionLabel()">Stroke</label>
+ <button
+ data-test-id="stroke-section-add"
+ :class="iconButton()"
+ @click="add(strokeCtx.defaultStroke)"
+ >
+ +
+ </button>
+ </div>
+
+ <p v-if="isMixed" class="text-[11px] text-muted">Click + to replace mixed strokes</p>
+
+ <div
+ v-for="(stroke, i) in items as Stroke[]"
+ :key="i"
+ data-test-id="stroke-item"
+ :data-test-index="i"
+ class="group flex items-center gap-1.5 py-0.5"
>
- <icon-lucide-eye v-if="stroke.visible" class="size-3.5" />
- <icon-lucide-eye-off v-else class="size-3.5" />
- </button>
- <button :class="iconButton({ ui: { base: 'shrink-0' } })" @click="remove(i)">−</button>
- </div>
-
- <!-- Stroke details -->
- <div
- v-if="!isMixed && activeNode && activeNode.strokes.length > 0"
- class="mt-1 flex items-center gap-1.5"
- >
- <AppSelect
- class="w-[72px]"
- :model-value="currentAlign(activeNode)"
- :options="ALIGN_OPTIONS"
- @update:model-value="updateAlign($event as Stroke['align'], activeNode)"
- />
- <ScrubInput
- v-if="!activeNode.independentStrokeWeights"
- class="flex-1"
- :model-value="activeNode.strokes[0]?.weight ?? 1"
- :min="0"
- @update:model-value="patch(0, { weight: $event })"
- >
- <template #icon>
- <svg
- class="size-3"
- viewBox="0 0 12 12"
- fill="none"
- stroke="currentColor"
- stroke-width="1.5"
- >
- <line x1="1" y1="3" x2="11" y2="3" />
- <line x1="1" y1="6" x2="11" y2="6" />
- <line x1="1" y1="9" x2="11" y2="9" />
- </svg>
- </template>
- </ScrubInput>
- <DropdownMenuRoot v-model:open="sideMenuOpen">
- <Tip label="Stroke sides">
- <DropdownMenuTrigger as-child>
- <button
- class="flex size-[26px] shrink-0 cursor-pointer items-center justify-center rounded border border-border bg-input text-muted hover:bg-hover hover:text-surface"
- :class="{ '!border-accent !text-accent': activeNode.independentStrokeWeights }"
- >
- <svg class="size-3.5" viewBox="0 0 14 14" fill="currentColor">
- <rect x="1" y="1" width="5" height="5" rx="1" />
- <rect x="8" y="1" width="5" height="5" rx="1" />
- <rect x="1" y="8" width="5" height="5" rx="1" />
- <rect x="8" y="8" width="5" height="5" rx="1" />
- </svg>
- </button>
- </DropdownMenuTrigger>
- </Tip>
- <DropdownMenuPortal>
- <DropdownMenuContent :side-offset="4" align="end" :class="sideMenuCls.content">
- <DropdownMenuItem
- v-for="opt in SIDE_OPTIONS"
- :key="opt.value"
- :class="menu({ justify: 'start' }).item({ class: sideMenuCls.item })"
- @click="selectSide(opt.value, activeNode)"
+ <ColorInput
+ class="min-w-0 flex-1"
+ :color="stroke.color"
+ editable
+ @update="patch(i, { color: $event })"
+ />
+ <button
+ class="shrink-0 cursor-pointer border-none bg-transparent p-0 text-muted hover:text-surface"
+ @click="toggleVisibility(i)"
+ >
+ <icon-lucide-eye v-if="stroke.visible" class="size-3.5" />
+ <icon-lucide-eye-off v-else class="size-3.5" />
+ </button>
+ <button :class="iconButton({ ui: { base: 'shrink-0' } })" @click="remove(i)">−</button>
+ </div>
+
+ <div v-if="!isMixed && activeNode && activeNode.strokes.length > 0" class="mt-1 flex items-center gap-1.5">
+ <AppSelect
+ class="w-[72px]"
+ :model-value="strokeCtx.currentAlign(activeNode)"
+ :options="strokeCtx.alignOptions"
+ @update:model-value="strokeCtx.updateAlign($event as Stroke['align'], activeNode)"
+ />
+ <ScrubInput
+ v-if="!activeNode.independentStrokeWeights"
+ class="flex-1"
+ :model-value="activeNode.strokes[0]?.weight ?? 1"
+ :min="0"
+ @update:model-value="patch(0, { weight: $event })"
+ >
+ <template #icon>
+ <svg
+ class="size-3"
+ viewBox="0 0 12 12"
+ fill="none"
+ stroke="currentColor"
+ stroke-width="1.5"
>
- <icon-lucide-check
- v-if="currentSides(activeNode) === opt.value"
- class="absolute left-2 size-3 text-accent"
- />
- <span class="flex items-center gap-2 pl-5">
- <svg
- class="size-3.5"
- viewBox="0 0 14 14"
- fill="none"
- stroke="currentColor"
- stroke-width="1.5"
- >
- <template v-if="opt.value === 'ALL'">
- <rect x="1" y="1" width="12" height="12" rx="1" />
- </template>
- <template v-else-if="opt.value === 'CUSTOM'">
- <line x1="4" y1="7" x2="10" y2="7" />
- <line x1="7" y1="4" x2="7" y2="10" />
- </template>
- <template v-else>
- <rect
- x="1"
- y="1"
- width="12"
- height="12"
- rx="1"
- stroke-opacity="0.3"
- stroke-dasharray="2 2"
- />
- <line v-if="opt.value === 'TOP'" x1="1" y1="1" x2="13" y2="1" />
- <line v-else-if="opt.value === 'BOTTOM'" x1="1" y1="13" x2="13" y2="13" />
- <line v-else-if="opt.value === 'LEFT'" x1="1" y1="1" x2="1" y2="13" />
- <line v-else-if="opt.value === 'RIGHT'" x1="13" y1="1" x2="13" y2="13" />
- </template>
+ <line x1="1" y1="3" x2="11" y2="3" />
+ <line x1="1" y1="6" x2="11" y2="6" />
+ <line x1="1" y1="9" x2="11" y2="9" />
+ </svg>
+ </template>
+ </ScrubInput>
+ <DropdownMenuRoot v-model:open="strokeCtx.sideMenuOpen">
+ <Tip label="Stroke sides">
+ <DropdownMenuTrigger as-child>
+ <button
+ class="flex size-[26px] shrink-0 cursor-pointer items-center justify-center rounded border border-border bg-input text-muted hover:bg-hover hover:text-surface"
+ :class="{ '!border-accent !text-accent': activeNode.independentStrokeWeights }"
+ >
+ <svg class="size-3.5" viewBox="0 0 14 14" fill="currentColor">
+ <rect x="1" y="1" width="5" height="5" rx="1" />
+ <rect x="8" y="1" width="5" height="5" rx="1" />
+ <rect x="1" y="8" width="5" height="5" rx="1" />
+ <rect x="8" y="8" width="5" height="5" rx="1" />
</svg>
- <span>{{ opt.label }}</span>
- </span>
- </DropdownMenuItem>
- </DropdownMenuContent>
- </DropdownMenuPortal>
- </DropdownMenuRoot>
- </div>
-
- <!-- Individual border weights -->
- <div
- v-if="
- !isMixed &&
- activeNode &&
- activeNode.strokes.length > 0 &&
- activeNode.independentStrokeWeights
- "
- class="mt-1.5 grid grid-cols-2 gap-1.5"
- >
- <ScrubInput
- v-for="side in BORDER_SIDES"
- :key="side"
- :model-value="
- activeNode[
- `border${side[0].toUpperCase()}${side.slice(1)}Weight` as keyof SceneNode
- ] as number
- "
- :min="0"
- @update:model-value="updateBorderWeight(side, $event, activeNode)"
+ </button>
+ </DropdownMenuTrigger>
+ </Tip>
+ <DropdownMenuPortal>
+ <DropdownMenuContent
+ :side-offset="4"
+ align="end"
+ :class="useMenuUI({ content: 'min-w-[140px] rounded-md p-0.5' }).content"
+ >
+ <DropdownMenuItem
+ v-for="opt in strokeCtx.sideOptions"
+ :key="opt.value"
+ :class="menu({ justify: 'start' }).item({ class: 'relative px-2' })"
+ @click="strokeCtx.selectSide(opt.value, activeNode)"
+ >
+ <icon-lucide-check
+ v-if="strokeCtx.currentSides(activeNode) === opt.value"
+ class="absolute left-2 size-3 text-accent"
+ />
+ <span class="flex items-center gap-2 pl-5">
+ <svg
+ class="size-3.5"
+ viewBox="0 0 14 14"
+ fill="none"
+ stroke="currentColor"
+ stroke-width="1.5"
+ >
+ <template v-if="opt.value === 'ALL'">
+ <rect x="1" y="1" width="12" height="12" rx="1" />
+ </template>
+ <template v-else-if="opt.value === 'CUSTOM'">
+ <line x1="4" y1="7" x2="10" y2="7" />
+ <line x1="7" y1="4" x2="7" y2="10" />
+ </template>
+ <template v-else>
+ <rect
+ x="1"
+ y="1"
+ width="12"
+ height="12"
+ rx="1"
+ stroke-opacity="0.3"
+ stroke-dasharray="2 2"
+ />
+ <line v-if="opt.value === 'TOP'" x1="1" y1="1" x2="13" y2="1" />
+ <line v-else-if="opt.value === 'BOTTOM'" x1="1" y1="13" x2="13" y2="13" />
+ <line v-else-if="opt.value === 'LEFT'" x1="1" y1="1" x2="1" y2="13" />
+ <line v-else-if="opt.value === 'RIGHT'" x1="13" y1="1" x2="13" y2="13" />
+ </template>
+ </svg>
+ <span>{{ opt.label }}</span>
+ </span>
+ </DropdownMenuItem>
+ </DropdownMenuContent>
+ </DropdownMenuPortal>
+ </DropdownMenuRoot>
+ </div>
+
+ <div
+ v-if="!isMixed && activeNode && activeNode.strokes.length > 0 && activeNode.independentStrokeWeights"
+ class="mt-1.5 grid grid-cols-2 gap-1.5"
>
- <template #icon>
- <svg class="size-3" viewBox="0 0 12 12" fill="none" stroke-width="1.5">
- <rect
- x="1"
- y="1"
- width="10"
- height="10"
- rx="1"
- stroke="currentColor"
- stroke-opacity="0.3"
- stroke-dasharray="2 2"
- />
- <line v-if="side === 'top'" x1="1" y1="1" x2="11" y2="1" stroke="currentColor" />
- <line
- v-else-if="side === 'right'"
- x1="11"
- y1="1"
- x2="11"
- y2="11"
- stroke="currentColor"
- />
- <line
- v-else-if="side === 'bottom'"
- x1="1"
- y1="11"
- x2="11"
- y2="11"
- stroke="currentColor"
- />
- <line v-else x1="1" y1="1" x2="1" y2="11" stroke="currentColor" />
- </svg>
- </template>
- </ScrubInput>
+ <ScrubInput
+ v-for="side in strokeCtx.borderSides"
+ :key="side"
+ :model-value="
+ activeNode[
+ `border${side[0].toUpperCase()}${side.slice(1)}Weight` as keyof SceneNode
+ ] as number
+ "
+ :min="0"
+ @update:model-value="strokeCtx.updateBorderWeight(side, $event, activeNode)"
+ >
+ <template #icon>
+ <svg class="size-3" viewBox="0 0 12 12" fill="none" stroke-width="1.5">
+ <rect
+ x="1"
+ y="1"
+ width="10"
+ height="10"
+ rx="1"
+ stroke="currentColor"
+ stroke-opacity="0.3"
+ stroke-dasharray="2 2"
+ />
+ <line v-if="side === 'top'" x1="1" y1="1" x2="11" y2="1" stroke="currentColor" />
+ <line
+ v-else-if="side === 'right'"
+ x1="11"
+ y1="1"
+ x2="11"
+ y2="11"
+ stroke="currentColor"
+ />
+ <line
+ v-else-if="side === 'bottom'"
+ x1="1"
+ y1="11"
+ x2="11"
+ y2="11"
+ stroke="currentColor"
+ />
+ <line v-else x1="1" y1="1" x2="1" y2="11" stroke="currentColor" />
+ </svg>
+ </template>
+ </ScrubInput>
+ </div>
</div>
- </div>
- </PropertyListRoot>
+ </PropertyListRoot>
+ </StrokeControlsRoot>
</template>
diff --git a/src/components/properties/TypographySection.vue b/src/components/properties/TypographySection.vue
index fb336baaf..726a0a423 100644
--- a/src/components/properties/TypographySection.vue
+++ b/src/components/properties/TypographySection.vue
@@ -1,154 +1,139 @@
<script setup lang="ts">
-import AppSelect from '@/components/AppSelect.vue'
+import { ToggleGroupItem, ToggleGroupRoot } from 'reka-ui'
+
+import { TypographyControlsRoot } from '@open-pencil/vue'
+
import FontPicker from '@/components/FontPicker.vue'
import ScrubInput from '@/components/ScrubInput.vue'
-import Tip from '@/components/Tip.vue'
+import AppSelect from '@/components/ui/AppSelect.vue'
+import Tip from '@/components/ui/Tip.vue'
import { sectionWrapper } from '@/components/ui/section'
import { loadFont } from '@/engine/fonts'
-import { useTypography } from '@open-pencil/vue'
-import { ToggleGroupItem, ToggleGroupRoot, type AcceptableValue } from 'reka-ui'
-
-const ctx = useTypography({ loadFont })
</script>
<template>
- <div v-if="ctx.node.value" data-test-id="typography-section" :class="sectionWrapper()">
- <label class="mb-1.5 block text-[11px] text-muted">Typography</label>
+ <TypographyControlsRoot v-slot="ctx" :load-font="loadFont">
+ <div v-if="ctx.node.value" 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">
- <FontPicker
- class="min-w-0 flex-1"
- :model-value="ctx.node.value.fontFamily"
- @select="ctx.setFamily"
- />
- <Tip
- v-if="ctx.hasMissingFonts.value"
- :label="
- 'Missing font' +
- (ctx.missingFonts.value.length > 1 ? 's' : '') +
- ': ' +
- ctx.missingFonts.value.join(', ')
- "
- >
- <icon-lucide-alert-triangle
- data-test-id="typography-missing-font"
- class="size-3.5 shrink-0 text-amber-400"
- />
- </Tip>
- </div>
+ <div class="mb-1.5 flex items-center gap-1.5">
+ <FontPicker class="min-w-0 flex-1" :model-value="ctx.node.value.fontFamily" @select="ctx.setFamily" />
+ <Tip
+ v-if="ctx.hasMissingFonts.value"
+ :label="
+ 'Missing font' +
+ (ctx.missingFonts.value.length > 1 ? 's' : '') +
+ ': ' +
+ ctx.missingFonts.value.join(', ')
+ "
+ >
+ <icon-lucide-alert-triangle
+ data-test-id="typography-missing-font"
+ class="size-3.5 shrink-0 text-amber-400"
+ />
+ </Tip>
+ </div>
- <!-- Weight + Size -->
- <div class="mb-1.5 flex gap-1.5">
- <AppSelect
- :model-value="ctx.node.value.fontWeight"
- :options="ctx.weights"
- @update:model-value="ctx.setWeight(+$event)"
- />
- <ScrubInput
- class="flex-1"
- :model-value="ctx.node.value.fontSize"
- :min="1"
- :max="1000"
- @update:model-value="ctx.updateProp('fontSize', $event)"
- @commit="(v: number, p: number) => ctx.commitProp('fontSize', v, p)"
- />
- </div>
+ <div class="mb-1.5 flex gap-1.5">
+ <AppSelect
+ :model-value="ctx.node.value.fontWeight"
+ :options="ctx.weights"
+ @update:model-value="ctx.setWeight(+$event)"
+ />
+ <ScrubInput
+ class="flex-1"
+ :model-value="ctx.node.value.fontSize"
+ :min="1"
+ :max="1000"
+ @update:model-value="ctx.updateProp('fontSize', $event)"
+ @commit="(v: number, p: number) => ctx.commitProp('fontSize', v, p)"
+ />
+ </div>
- <!-- Line height + Letter spacing -->
- <div class="mb-1.5 flex gap-1.5">
- <ScrubInput
- class="flex-1"
- :model-value="
- ctx.node.value.lineHeight ?? Math.round((ctx.node.value.fontSize || 14) * 1.2)
- "
- :min="0"
- @update:model-value="ctx.updateProp('lineHeight', $event)"
- @commit="(v: number, p: number) => ctx.commitProp('lineHeight', v, p)"
- >
- <template #icon>
- <icon-lucide-baseline class="size-3" />
- </template>
- </ScrubInput>
- <ScrubInput
- class="flex-1"
- suffix="%"
- :model-value="ctx.node.value.letterSpacing"
- @update:model-value="ctx.updateProp('letterSpacing', $event)"
- @commit="(v: number, p: number) => ctx.commitProp('letterSpacing', v, p)"
- >
- <template #icon>
- <icon-lucide-a-large-small class="size-3" />
- </template>
- </ScrubInput>
- </div>
+ <div class="mb-1.5 flex gap-1.5">
+ <ScrubInput
+ class="flex-1"
+ :model-value="ctx.node.value.lineHeight ?? Math.round((ctx.node.value.fontSize || 14) * 1.2)"
+ :min="0"
+ @update:model-value="ctx.updateProp('lineHeight', $event)"
+ @commit="(v: number, p: number) => ctx.commitProp('lineHeight', v, p)"
+ >
+ <template #icon>
+ <icon-lucide-baseline class="size-3" />
+ </template>
+ </ScrubInput>
+ <ScrubInput
+ class="flex-1"
+ suffix="%"
+ :model-value="ctx.node.value.letterSpacing"
+ @update:model-value="ctx.updateProp('letterSpacing', $event)"
+ @commit="(v: number, p: number) => ctx.commitProp('letterSpacing', v, p)"
+ >
+ <template #icon>
+ <icon-lucide-a-large-small class="size-3" />
+ </template>
+ </ScrubInput>
+ </div>
- <!-- Text alignment + formatting -->
- <div class="flex items-center gap-3">
- <ToggleGroupRoot
- type="single"
- class="flex gap-0.5"
- :model-value="ctx.node.value.textAlignHorizontal"
- @update:model-value="
- (val: AcceptableValue) => {
- if (val) ctx.setAlign(val as 'LEFT' | 'CENTER' | 'RIGHT')
- }
- "
- >
- <ToggleGroupItem
- v-for="align in ['LEFT', 'CENTER', 'RIGHT'] as const"
- :key="align"
- :value="align"
- class="flex cursor-pointer items-center justify-center rounded border border-border bg-input px-2 py-1 text-muted hover:bg-hover hover:text-surface data-[state=on]:border-accent data-[state=on]:bg-accent data-[state=on]:text-white"
+ <div class="flex items-center gap-3">
+ <ToggleGroupRoot
+ type="single"
+ class="flex gap-0.5"
+ :model-value="ctx.node.value.textAlignHorizontal"
+ @update:model-value="ctx.onAlignChange"
>
- <icon-lucide-align-left v-if="align === 'LEFT'" class="size-3.5" />
- <icon-lucide-align-center v-else-if="align === 'CENTER'" class="size-3.5" />
- <icon-lucide-align-right v-else class="size-3.5" />
- </ToggleGroupItem>
- </ToggleGroupRoot>
- <ToggleGroupRoot
- type="multiple"
- class="flex gap-0.5"
- :model-value="ctx.activeFormatting.value"
- @update:model-value="
- (val: AcceptableValue | AcceptableValue[]) => {
- if (Array.isArray(val)) ctx.onFormattingChange(val as string[])
- }
- "
- >
- <Tip label="Bold (⌘B)">
<ToggleGroupItem
- value="bold"
- data-test-id="typography-bold-button"
- class="flex cursor-pointer items-center justify-center rounded border border-border bg-input px-2 py-1 font-bold text-muted hover:bg-hover hover:text-surface data-[state=on]:border-accent data-[state=on]:bg-accent data-[state=on]:text-white"
- >
- <icon-lucide-bold class="size-3.5" />
- </ToggleGroupItem>
- </Tip>
- <Tip label="Italic (⌘I)">
- <ToggleGroupItem
- value="italic"
- class="flex cursor-pointer items-center justify-center rounded border border-border bg-input px-2 py-1 text-muted hover:bg-hover hover:text-surface data-[state=on]:border-accent data-[state=on]:bg-accent data-[state=on]:text-white"
- >
- <icon-lucide-italic class="size-3.5" />
- </ToggleGroupItem>
- </Tip>
- <Tip label="Underline (⌘U)">
- <ToggleGroupItem
- value="underline"
+ v-for="align in ['LEFT', 'CENTER', 'RIGHT'] as const"
+ :key="align"
+ :value="align"
class="flex cursor-pointer items-center justify-center rounded border border-border bg-input px-2 py-1 text-muted hover:bg-hover hover:text-surface data-[state=on]:border-accent data-[state=on]:bg-accent data-[state=on]:text-white"
>
- <icon-lucide-underline class="size-3.5" />
+ <icon-lucide-align-left v-if="align === 'LEFT'" class="size-3.5" />
+ <icon-lucide-align-center v-else-if="align === 'CENTER'" class="size-3.5" />
+ <icon-lucide-align-right v-else class="size-3.5" />
</ToggleGroupItem>
- </Tip>
- <Tip label="Strikethrough">
- <ToggleGroupItem
- value="strikethrough"
- class="flex cursor-pointer items-center justify-center rounded border border-border bg-input px-2 py-1 text-muted hover:bg-hover hover:text-surface data-[state=on]:border-accent data-[state=on]:bg-accent data-[state=on]:text-white"
- >
- <icon-lucide-strikethrough class="size-3.5" />
- </ToggleGroupItem>
- </Tip>
- </ToggleGroupRoot>
+ </ToggleGroupRoot>
+ <ToggleGroupRoot
+ type="multiple"
+ class="flex gap-0.5"
+ :model-value="ctx.activeFormatting.value"
+ @update:model-value="ctx.onFormattingChange"
+ >
+ <Tip label="Bold (⌘B)">
+ <ToggleGroupItem
+ value="bold"
+ data-test-id="typography-bold-button"
+ class="flex cursor-pointer items-center justify-center rounded border border-border bg-input px-2 py-1 font-bold text-muted hover:bg-hover hover:text-surface data-[state=on]:border-accent data-[state=on]:bg-accent data-[state=on]:text-white"
+ >
+ <icon-lucide-bold class="size-3.5" />
+ </ToggleGroupItem>
+ </Tip>
+ <Tip label="Italic (⌘I)">
+ <ToggleGroupItem
+ value="italic"
+ class="flex cursor-pointer items-center justify-center rounded border border-border bg-input px-2 py-1 text-muted hover:bg-hover hover:text-surface data-[state=on]:border-accent data-[state=on]:bg-accent data-[state=on]:text-white"
+ >
+ <icon-lucide-italic class="size-3.5" />
+ </ToggleGroupItem>
+ </Tip>
+ <Tip label="Underline (⌘U)">
+ <ToggleGroupItem
+ value="underline"
+ class="flex cursor-pointer items-center justify-center rounded border border-border bg-input px-2 py-1 text-muted hover:bg-hover hover:text-surface data-[state=on]:border-accent data-[state=on]:bg-accent data-[state=on]:text-white"
+ >
+ <icon-lucide-underline class="size-3.5" />
+ </ToggleGroupItem>
+ </Tip>
+ <Tip label="Strikethrough">
+ <ToggleGroupItem
+ value="strikethrough"
+ class="flex cursor-pointer items-center justify-center rounded border border-border bg-input px-2 py-1 text-muted hover:bg-hover hover:text-surface data-[state=on]:border-accent data-[state=on]:bg-accent data-[state=on]:text-white"
+ >
+ <icon-lucide-strikethrough class="size-3.5" />
+ </ToggleGroupItem>
+ </Tip>
+ </ToggleGroupRoot>
+ </div>
</div>
- </div>
+ </TypographyControlsRoot>
</template>