Skip to content

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

refactor(vue): clean up primitive UI APIs

Danila Poyarkovf29da6c5cdfb
diff --git a/AGENTS.md b/AGENTS.md
index a46e857fe..55519edc8 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -306,6 +306,9 @@ Self-review checklist:
## UI
- Use reka-ui for UI components (Splitter, ContextMenu, DropdownMenu, etc.)
+- Vue UI styling APIs must follow the existing `:ui` / `tailwind-variants` slot pattern. Do not add one-off `fooClass`, `barClass`, `emptyActionClass`, etc. props to components; define a typed `Ui` object with named slots and merge through the local `use*UI()` helper or a `ui` prop.
+- Do not pass imperative setters/actions through slots as `:set-*`, `:update-*`, `:request-*`, `:toggle-*`, etc. unless the component is explicitly a renderless primitive whose whole contract is slot actions. Prefer `v-model`, emitted events, normal component props, or owned default UI. For DOM refs/focus, use VueUse (`templateRef`, `unrefElement`, `useFocus`, etc.) instead of ref callback plumbing through slots.
+- App wrappers around SDK primitives should compose a single `ui` object from shared UI helpers (`useSelectUI`, `usePopoverUI`, etc.) rather than bypassing the design system with raw Tailwind strings spread across multiple props.
- Browser and Tauri menus share `src/app/shell/menu/schema.ts` as the canonical menu model. Do not add menu items directly in `src/components/AppMenu.vue` or `desktop/src/menu.rs`.
- Regenerate the native menu with `bun run generate:tauri-menu` after editing the shared menu schema; `desktop/generated/menu.json` is consumed by the Tauri menu builder. Tauri also runs this generator from `desktop/tauri.conf.json` via `beforeDevCommand` and `beforeBuildCommand`.
- Every shared menu item with an `id` must be handled by `src/app/shell/menu/use.ts`, an editor command, or explicitly marked browser/native-only in the schema.
diff --git a/packages/vue/src/canvas/CanvasSurface.vue b/packages/vue/src/canvas/CanvasSurface.vue
index 5a95b1d7a..b4a57eea4 100644
--- a/packages/vue/src/canvas/CanvasSurface.vue
+++ b/packages/vue/src/canvas/CanvasSurface.vue
@@ -1,18 +1,19 @@
<script setup lang="ts">
+import { templateRef } from '@vueuse/core'
+import { watchEffect } from 'vue'
+
import { useCanvasContext } from '#vue/canvas/context'
const { canvasRef } = useCanvasContext()
+const surfaceRef = templateRef<HTMLCanvasElement>('surfaceRef')
+
+watchEffect(() => {
+ canvasRef.value = surfaceRef.value
+})
</script>
<template>
- <canvas
- :ref="
- (el) => {
- canvasRef = el as HTMLCanvasElement | null
- }
- "
- v-bind="$attrs"
- />
+ <canvas ref="surfaceRef" v-bind="$attrs" />
</template>
<script lang="ts">
diff --git a/packages/vue/src/controls/typography/actions.ts b/packages/vue/src/controls/typography/actions.ts
index 3719391e2..d77709d06 100644
--- a/packages/vue/src/controls/typography/actions.ts
+++ b/packages/vue/src/controls/typography/actions.ts
@@ -65,7 +65,7 @@ export function createTypographyActions({
options
}: TypographyActionOptions) {
async function doLoadFont(family: string, style: string) {
- if (options.loadFont) await options.loadFont(family, style)
+ await options.fontLoader?.load(family, style)
}
async function setFamily(family: string) {
diff --git a/packages/vue/src/controls/typography/use.ts b/packages/vue/src/controls/typography/use.ts
index e94ee4593..a80f4dcdd 100644
--- a/packages/vue/src/controls/typography/use.ts
+++ b/packages/vue/src/controls/typography/use.ts
@@ -8,11 +8,15 @@ import { useEditor } from '#vue/editor/context'
/**
* Options for {@link useTypography}.
*/
+export interface TypographyFontLoader {
+ load: (family: string, style: string) => Promise<unknown>
+}
+
export interface UseTypographyOptions {
/**
* Optional font loader invoked before changing family or weight.
*/
- loadFont?: (family: string, style: string) => Promise<unknown>
+ fontLoader?: TypographyFontLoader
}
/**
diff --git a/packages/vue/src/index.ts b/packages/vue/src/index.ts
index 24cb89719..224120cc4 100644
--- a/packages/vue/src/index.ts
+++ b/packages/vue/src/index.ts
@@ -101,6 +101,7 @@ export {
export type { ColorFieldFormat, OkHCLControls } from '#vue/primitives/ColorPicker'
export { FillPickerRoot } from '#vue/primitives/FillPicker'
export { FontPickerRoot } from '#vue/primitives/FontPicker'
+export type { FontPickerUi } from '#vue/primitives/FontPicker'
export {
GradientEditorRoot,
GradientEditorBar,
diff --git a/packages/vue/src/primitives/AppearanceControls/AppearanceControlsRoot.vue b/packages/vue/src/primitives/AppearanceControls/AppearanceControlsRoot.vue
index 443866726..4fe8bff7d 100644
--- a/packages/vue/src/primitives/AppearanceControls/AppearanceControlsRoot.vue
+++ b/packages/vue/src/primitives/AppearanceControls/AppearanceControlsRoot.vue
@@ -2,6 +2,14 @@
import { useAppearance } from '#vue/controls/appearance/use'
const ctx = useAppearance()
+const actions = {
+ updateProp: ctx.updateProp,
+ commitProp: ctx.commitProp,
+ toggleVisibility: ctx.toggleVisibility,
+ toggleIndependentCorners: ctx.toggleIndependentCorners,
+ updateCornerProp: ctx.updateCornerProp,
+ commitCornerProp: ctx.commitCornerProp
+}
</script>
<template>
@@ -14,11 +22,6 @@ const ctx = useAppearance()
: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"
+ :actions="actions"
/>
</template>
diff --git a/packages/vue/src/primitives/ColorPicker/ColorInputRoot.vue b/packages/vue/src/primitives/ColorPicker/ColorInputRoot.vue
index 04af1db20..8c6e7e84d 100644
--- a/packages/vue/src/primitives/ColorPicker/ColorInputRoot.vue
+++ b/packages/vue/src/primitives/ColorPicker/ColorInputRoot.vue
@@ -23,6 +23,11 @@ function updateFromHex(value: string) {
const parsed = parseColor(value.startsWith('#') ? value : `#${value}`)
emit('update', { ...parsed, a: color.a })
}
+
+const actions = {
+ updateFromHex,
+ updateColor: (nextColor: Color) => emit('update', nextColor)
+}
</script>
<template>
@@ -30,8 +35,7 @@ function updateFromHex(value: string) {
:color="color"
:editable="editable"
:hex="hex"
- :update-from-hex="updateFromHex"
- :update-color="(nextColor: Color) => emit('update', nextColor)"
+ :actions="actions"
:okhcl="okhcl"
/>
</template>
diff --git a/packages/vue/src/primitives/ColorPicker/ColorPickerRoot.vue b/packages/vue/src/primitives/ColorPicker/ColorPickerRoot.vue
index f9b67f5f1..f9395a438 100644
--- a/packages/vue/src/primitives/ColorPicker/ColorPickerRoot.vue
+++ b/packages/vue/src/primitives/ColorPicker/ColorPickerRoot.vue
@@ -5,10 +5,14 @@ import { colorToCSS } from '@open-pencil/core/color'
import type { Color } from '@open-pencil/core/types'
-const { color, contentClass, swatchClass } = defineProps<{
+export interface ColorPickerUi {
+ content?: string
+ swatch?: string
+}
+
+const { color, ui } = defineProps<{
color: Color
- contentClass?: string
- swatchClass?: string
+ ui?: ColorPickerUi
}>()
const emit = defineEmits<{ update: [color: Color] }>()
@@ -22,7 +26,7 @@ const swatchBg = computed(() => colorToCSS(color))
<slot name="trigger" :style="{ background: swatchBg }">
<button
data-test-id="color-picker-swatch"
- :class="swatchClass"
+ :class="ui?.swatch"
:style="{ background: swatchBg }"
/>
</slot>
@@ -31,11 +35,11 @@ const swatchBg = computed(() => colorToCSS(color))
<PopoverPortal>
<PopoverContent
data-test-id="color-picker-popover"
- :class="contentClass"
+ :class="ui?.content"
:side-offset="4"
side="left"
>
- <slot :color="color" :update="(nextColor: Color) => emit('update', nextColor)" />
+ <slot :color="color" />
</PopoverContent>
</PopoverPortal>
</PopoverRoot>
diff --git a/packages/vue/src/primitives/FillPicker/FillPickerRoot.vue b/packages/vue/src/primitives/FillPicker/FillPickerRoot.vue
index 3036c00c5..ef6714c23 100644
--- a/packages/vue/src/primitives/FillPicker/FillPickerRoot.vue
+++ b/packages/vue/src/primitives/FillPicker/FillPickerRoot.vue
@@ -6,10 +6,14 @@ import { useFillPicker } from '#vue/primitives/FillPicker/useFillPicker'
import type { Fill } from '@open-pencil/core/scene-graph'
-const { fill, contentClass, swatchClass } = defineProps<{
+export interface FillPickerUi {
+ content?: string
+ swatch?: string
+}
+
+const { fill, ui } = defineProps<{
fill: Fill
- contentClass?: string
- swatchClass?: string
+ ui?: FillPickerUi
}>()
const emit = defineEmits<{ update: [fill: Fill] }>()
@@ -24,19 +28,18 @@ const { category, swatchBg, toSolid, toGradient, toImage } = useFillPicker(
<PopoverRoot>
<PopoverTrigger as-child>
<slot name="trigger" :style="{ background: swatchBg }">
- <button :class="swatchClass" :style="{ background: swatchBg }" />
+ <button :class="ui?.swatch" :style="{ background: swatchBg }" />
</slot>
</PopoverTrigger>
<PopoverPortal>
- <PopoverContent :class="contentClass" :side-offset="4" side="left">
+ <PopoverContent :class="ui?.content" :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>
diff --git a/packages/vue/src/primitives/FontPicker/FontPickerRoot.vue b/packages/vue/src/primitives/FontPicker/FontPickerRoot.vue
index 15c8ed8c7..47f33c277 100644
--- a/packages/vue/src/primitives/FontPicker/FontPickerRoot.vue
+++ b/packages/vue/src/primitives/FontPicker/FontPickerRoot.vue
@@ -1,5 +1,6 @@
<script setup lang="ts">
-import { nextTick, ref } from 'vue'
+import { nextTick } from 'vue'
+import { templateRef, unrefElement } from '@vueuse/core'
import {
ComboboxAnchor,
ComboboxContent,
@@ -13,27 +14,24 @@ import {
type AcceptableValue
} from 'reka-ui'
-import { useFontPicker } from '#vue/primitives/FontPicker/useFontPicker'
+import {
+ useFontPicker,
+ type FontAccessController
+} from '#vue/primitives/FontPicker/useFontPicker'
+
+import type { FontPickerUi } from '#vue/primitives/FontPicker/types'
const {
listFamilies,
- triggerClass,
- contentClass,
- itemClass,
- searchClass,
- viewportClass,
- emptyClass,
+ localFontAccess,
+ ui,
emptySearchText,
emptyFontsText,
emptyFontsHint
} = defineProps<{
listFamilies: () => Promise<string[]>
- triggerClass?: string
- contentClass?: string
- itemClass?: string
- searchClass?: string
- viewportClass?: string
- emptyClass?: string
+ localFontAccess?: FontAccessController
+ ui?: FontPickerUi
emptySearchText?: string
emptyFontsText?: string
emptyFontsHint?: string
@@ -42,15 +40,24 @@ const {
const modelValue = defineModel<string>({ required: true })
const emit = defineEmits<{ select: [family: string] }>()
-const inputRef = ref<HTMLInputElement | null>(null)
+const contentRef = templateRef<HTMLElement>('contentRef')
-function setInputRef(el: HTMLInputElement | null) {
- inputRef.value = el
+function focusSearchInput() {
+ nextTick(() => unrefElement(contentRef)?.querySelector('input')?.focus())
}
-const { searchTerm, open, filtered, select } = useFontPicker({
+const {
+ searchTerm,
+ open,
+ filtered,
+ loading,
+ accessState,
+ requestAccess,
+ select
+} = useFontPicker({
modelValue,
listFamilies,
+ localFontAccess,
onSelect: (family) => emit('select', family)
})
</script>
@@ -68,7 +75,7 @@ const { searchTerm, open, filtered, select } = useFontPicker({
>
<ComboboxAnchor as-child>
<slot name="trigger" :value="modelValue" :open="open">
- <button :class="triggerClass">
+ <button :class="ui?.trigger">
<span class="truncate">{{ modelValue }}</span>
</button>
</slot>
@@ -79,15 +86,15 @@ const { searchTerm, open, filtered, select } = useFontPicker({
:side-offset="2"
align="start"
position="popper"
- :class="contentClass"
+ :class="ui?.content"
@open-auto-focus.prevent
- @vue:mounted="nextTick(() => inputRef?.focus())"
+ ref="contentRef"
+ @vue:mounted="focusSearchInput"
>
- <slot name="search" :search-term="searchTerm" :set-input-ref="setInputRef">
+ <slot name="search" :search-term="searchTerm">
<ComboboxInput
- ref="inputRef"
v-model="searchTerm"
- :class="searchClass"
+ :class="ui?.search"
placeholder="Search fonts…"
autocomplete="off"
autocorrect="off"
@@ -96,7 +103,7 @@ const { searchTerm, open, filtered, select } = useFontPicker({
/>
</slot>
- <ComboboxViewport :class="viewportClass ?? 'max-h-72 overflow-y-auto'">
+ <ComboboxViewport :class="ui?.viewport ?? 'max-h-72 overflow-y-auto'">
<ComboboxVirtualizer
v-slot="{ option }"
:options="filtered"
@@ -106,7 +113,7 @@ const { searchTerm, open, filtered, select } = useFontPicker({
<slot name="item" :family="option" :selected="option === modelValue">
<ComboboxItem
:value="option"
- :class="itemClass"
+ :class="ui?.item"
:style="{ fontFamily: `'${option}', sans-serif` }"
>
<ComboboxItemIndicator>
@@ -117,16 +124,32 @@ const { searchTerm, open, filtered, select } = useFontPicker({
</slot>
</ComboboxVirtualizer>
- <div v-if="filtered.length === 0 && searchTerm" :class="emptyClass">
+ <div v-if="filtered.length === 0 && searchTerm" :class="ui?.empty">
{{ 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 v-else-if="filtered.length === 0" :class="ui?.empty">
+ <div>
+ <p v-if="accessState === 'prompt'">
+ Allow local font access to browse installed fonts.
+ </p>
+ <p v-else-if="accessState === 'denied'">
+ Local font access is blocked for this site.
+ </p>
+ <p v-else-if="accessState === 'unsupported'">
+ Local fonts are not available in this browser.
+ </p>
+ <p v-else>{{ emptyFontsText ?? 'No local fonts available.' }}</p>
+ <p v-if="emptyFontsHint" class="mt-1">{{ emptyFontsHint }}</p>
+ <button
+ v-if="accessState === 'prompt'"
+ type="button"
+ :class="ui?.emptyAction"
+ :disabled="loading"
+ @click="requestAccess"
+ >
+ {{ loading ? 'Loading…' : 'Allow local fonts' }}
+ </button>
+ </div>
</div>
</ComboboxViewport>
</ComboboxContent>
diff --git a/packages/vue/src/primitives/FontPicker/index.ts b/packages/vue/src/primitives/FontPicker/index.ts
index cb7d14a79..04ff3394a 100644
--- a/packages/vue/src/primitives/FontPicker/index.ts
+++ b/packages/vue/src/primitives/FontPicker/index.ts
@@ -1 +1,2 @@
export { default as FontPickerRoot } from '#vue/primitives/FontPicker/FontPickerRoot.vue'
+export type { FontPickerUi } from '#vue/primitives/FontPicker/types'
diff --git a/packages/vue/src/primitives/FontPicker/types.ts b/packages/vue/src/primitives/FontPicker/types.ts
new file mode 100644
index 000000000..2889ebe71
--- /dev/null
+++ b/packages/vue/src/primitives/FontPicker/types.ts
@@ -0,0 +1,9 @@
+export interface FontPickerUi {
+ trigger?: string
+ content?: string
+ item?: string
+ search?: string
+ viewport?: string
+ empty?: string
+ emptyAction?: string
+}
diff --git a/packages/vue/src/primitives/FontPicker/useFontPicker.ts b/packages/vue/src/primitives/FontPicker/useFontPicker.ts
index ea70f4c3b..c2b8efa62 100644
--- a/packages/vue/src/primitives/FontPicker/useFontPicker.ts
+++ b/packages/vue/src/primitives/FontPicker/useFontPicker.ts
@@ -1,6 +1,13 @@
import { useFilter } from 'reka-ui'
import { computed, ref, watch } from 'vue'
+export type FontAccessState = 'unsupported' | 'prompt' | 'granted' | 'denied'
+
+export interface FontAccessController {
+ state: () => FontAccessState
+ load: () => Promise<string[]>
+}
+
/**
* Options for {@link useFontPicker}.
*/
@@ -9,6 +16,8 @@ export interface UseFontPickerOptions {
modelValue: { value: string }
/** Async source for available font families. */
listFamilies: () => Promise<string[]>
+ /** Host-provided local-font permission controller. */
+ localFontAccess?: FontAccessController
/** Optional callback fired after a family is selected. */
onSelect?: (family: string) => void
}
@@ -20,6 +29,8 @@ export function useFontPicker(options: UseFontPickerOptions) {
const families = ref<string[]>([])
const searchTerm = ref('')
const open = ref(false)
+ const loading = ref(false)
+ const accessState = ref<FontAccessState>(options.localFontAccess?.state() ?? 'granted')
const { contains } = useFilter({ sensitivity: 'base' })
const filtered = computed(() => {
@@ -27,14 +38,37 @@ export function useFontPicker(options: UseFontPickerOptions) {
return families.value.filter((family) => contains(family, searchTerm.value))
})
+ async function loadFamilies() {
+ if (families.value.length > 0 || loading.value) return
+ loading.value = true
+ try {
+ families.value = await options.listFamilies()
+ accessState.value = options.localFontAccess?.state() ?? accessState.value
+ } finally {
+ loading.value = false
+ }
+ }
+
watch(open, async (isOpen) => {
if (!isOpen) return
searchTerm.value = ''
- if (families.value.length === 0) {
- families.value = await options.listFamilies()
+ accessState.value = options.localFontAccess?.state() ?? accessState.value
+ if (accessState.value !== 'prompt') {
+ await loadFamilies()
}
})
+ async function requestAccess() {
+ if (!options.localFontAccess || loading.value) return
+ loading.value = true
+ try {
+ families.value = await options.localFontAccess.load()
+ accessState.value = options.localFontAccess.state()
+ } finally {
+ loading.value = false
+ }
+ }
+
function select(family: string) {
options.modelValue.value = family
options.onSelect?.(family)
@@ -46,6 +80,9 @@ export function useFontPicker(options: UseFontPickerOptions) {
searchTerm,
open,
filtered,
+ loading,
+ accessState,
+ requestAccess,
select
}
}
diff --git a/packages/vue/src/primitives/GradientEditor/GradientEditorBar.vue b/packages/vue/src/primitives/GradientEditor/GradientEditorBar.vue
index 4e6a3d32e..198b404fa 100644
--- a/packages/vue/src/primitives/GradientEditor/GradientEditorBar.vue
+++ b/packages/vue/src/primitives/GradientEditor/GradientEditorBar.vue
@@ -1,12 +1,16 @@
<script setup lang="ts">
+import { templateRef } from '@vueuse/core'
import { ref } from 'vue'
import type { GradientStop } from '@open-pencil/core/scene-graph'
-const { stops } = defineProps<{
+const { stops, ui } = defineProps<{
stops: GradientStop[]
activeStopIndex: number
barBackground: string
+ ui?: {
+ bar?: string
+ }
}>()
const emit = defineEmits<{
@@ -14,10 +18,10 @@ const emit = defineEmits<{
dragStop: [index: number, position: number]
}>()
-const barRef = ref<HTMLElement | null>(null)
+const barRef = templateRef<HTMLElement>('barRef')
const draggingIndex = ref<number | null>(null)
-function onStopPointerDown(index: number, e: PointerEvent) {
+function stopPointerDown(index: number, e: PointerEvent) {
emit('selectStop', index)
draggingIndex.value = index
barRef.value?.setPointerCapture(e.pointerId)
@@ -35,22 +39,27 @@ function onPointerUp() {
draggingIndex.value = null
}
-function setBarRef(el: unknown) {
- barRef.value = el instanceof HTMLElement ? el : null
+const actions = {
+ stopPointerDown
}
defineExpose({ barRef })
</script>
<template>
- <slot
- :stops="stops"
- :active-stop-index="activeStopIndex"
- :bar-background="barBackground"
- :bar-ref="setBarRef"
- :on-stop-pointer-down="onStopPointerDown"
- :on-pointer-move="onPointerMove"
- :on-pointer-up="onPointerUp"
- :dragging-index="draggingIndex"
- />
+ <div
+ ref="barRef"
+ :class="ui?.bar"
+ :style="{ background: barBackground }"
+ @pointermove="onPointerMove"
+ @pointerup="onPointerUp"
+ >
+ <slot
+ :stops="stops"
+ :active-stop-index="activeStopIndex"
+ :bar-background="barBackground"
+ :actions="actions"
+ :dragging-index="draggingIndex"
+ />
+ </div>
</template>
diff --git a/packages/vue/src/primitives/GradientEditor/GradientEditorRoot.vue b/packages/vue/src/primitives/GradientEditor/GradientEditorRoot.vue
index 50372e3d1..70b45a8dd 100644
--- a/packages/vue/src/primitives/GradientEditor/GradientEditorRoot.vue
+++ b/packages/vue/src/primitives/GradientEditor/GradientEditorRoot.vue
@@ -28,6 +28,18 @@ const {
computed(() => fill),
(updated) => emit('update', updated)
)
+
+const actions = {
+ setSubtype,
+ selectStop,
+ addStop,
+ removeStop,
+ updateStopPosition,
+ updateStopColor,
+ updateStopOpacity,
+ updateActiveColor,
+ dragStop
+}
</script>
<template>
@@ -38,14 +50,6 @@ const {
:active-stop-index="activeStopIndex"
:active-color="activeColor"
:bar-background="barBackground"
- :set-subtype="setSubtype"
- :select-stop="selectStop"
- :add-stop="addStop"
- :remove-stop="removeStop"
- :update-stop-position="updateStopPosition"
- :update-stop-color="updateStopColor"
- :update-stop-opacity="updateStopOpacity"
- :update-active-color="updateActiveColor"
- :drag-stop="dragStop"
+ :actions="actions"
/>
</template>
diff --git a/packages/vue/src/primitives/GradientEditor/GradientEditorStop.vue b/packages/vue/src/primitives/GradientEditor/GradientEditorStop.vue
index 4aa2716d8..18df3da73 100644
--- a/packages/vue/src/primitives/GradientEditor/GradientEditorStop.vue
+++ b/packages/vue/src/primitives/GradientEditor/GradientEditorStop.vue
@@ -22,6 +22,13 @@ const positionPercent = computed(() => Math.round(stop.position * 100))
const opacityPercent = computed(() => Math.round(stop.color.a * 100))
const hex = computed(() => colorToHexRaw(stop.color))
const css = computed(() => colorToCSS(stop.color))
+const actions = {
+ select: () => emit('select', index),
+ updatePosition: (pos: number) => emit('updatePosition', index, pos),
+ updateColor: (hexValue: string) => emit('updateColor', index, hexValue),
+ updateOpacity: (opacity: number) => emit('updateOpacity', index, opacity),
+ remove: () => emit('remove', index)
+}
</script>
<template>
@@ -33,10 +40,6 @@ const css = computed(() => colorToCSS(stop.color))
:opacity-percent="opacityPercent"
:hex="hex"
:css="css"
- :select="() => emit('select', index)"
- :update-position="(pos: number) => emit('updatePosition', index, pos)"
- :update-color="(h: string) => emit('updateColor', index, h)"
- :update-opacity="(o: number) => emit('updateOpacity', index, o)"
- :remove="() => emit('remove', index)"
+ :actions="actions"
/>
</template>
diff --git a/packages/vue/src/primitives/LayerTree/LayerTreeItem.vue b/packages/vue/src/primitives/LayerTree/LayerTreeItem.vue
index 018d9f750..c408a574d 100644
--- a/packages/vue/src/primitives/LayerTree/LayerTreeItem.vue
+++ b/packages/vue/src/primitives/LayerTree/LayerTreeItem.vue
@@ -33,6 +33,29 @@ function onRef(el: unknown) {
ctx.setRowRef(node.id, htmlEl)
}
+const actions = {
+ select: (additive: boolean) => {
+ emit('select', node.id, additive)
+ ctx.select(node.id, additive)
+ },
+ toggleExpand: () => {
+ emit('toggleExpand', node.id)
+ ctx.toggleExpand(node.id)
+ },
+ toggleVisibility: () => {
+ emit('toggleVisibility', node.id)
+ ctx.toggleVisibility(node.id)
+ },
+ toggleLock: () => {
+ emit('toggleLock', node.id)
+ ctx.toggleLock(node.id)
+ },
+ rename: (name: string) => {
+ emit('rename', node.id, name)
+ ctx.rename(node.id, name)
+ }
+}
+
defineExpose({ rowEl })
</script>
@@ -45,36 +68,7 @@ defineExpose({ rowEl })
:is-selected="isSelected"
:is-dragging="isDragging"
:pad-left="padLeft"
- :select="
- (additive: boolean) => {
- emit('select', node.id, additive)
- ctx.select(node.id, additive)
- }
- "
- :toggle-expand="
- () => {
- emit('toggleExpand', node.id)
- ctx.toggleExpand(node.id)
- }
- "
- :toggle-visibility="
- () => {
- emit('toggleVisibility', node.id)
- ctx.toggleVisibility(node.id)
- }
- "
- :toggle-lock="
- () => {
- emit('toggleLock', node.id)
- ctx.toggleLock(node.id)
- }
- "
- :rename="
- (name: string) => {
- emit('rename', node.id, name)
- ctx.rename(node.id, name)
- }
- "
+ :actions="actions"
/>
</div>
</template>
diff --git a/packages/vue/src/primitives/LayerTree/LayerTreeRoot.vue b/packages/vue/src/primitives/LayerTree/LayerTreeRoot.vue
index 33361ddee..43791392e 100644
--- a/packages/vue/src/primitives/LayerTree/LayerTreeRoot.vue
+++ b/packages/vue/src/primitives/LayerTree/LayerTreeRoot.vue
@@ -105,6 +105,11 @@ function toggleExpand(id: string) {
else expanded.value = [...expanded.value, id]
}
+const actions = {
+ select,
+ toggleExpand
+}
+
provideLayerTree({
editor,
items,
@@ -136,8 +141,7 @@ provideLayerTree({
:expanded="expanded"
:tree-key="treeKey"
:selected-ids="selectedIds"
- :select="select"
- :toggle-expand="toggleExpand"
+ :actions="actions"
:get-key="(v: LayerNode) => v.id"
:get-children="(v: LayerNode) => v.children"
/>
diff --git a/packages/vue/src/primitives/LayoutControls/LayoutControlsRoot.vue b/packages/vue/src/primitives/LayoutControls/LayoutControlsRoot.vue
index 51cf6c7f9..6a68c273e 100644
--- a/packages/vue/src/primitives/LayoutControls/LayoutControlsRoot.vue
+++ b/packages/vue/src/primitives/LayoutControls/LayoutControlsRoot.vue
@@ -4,6 +4,28 @@ import { provideLayoutControls } from '#vue/primitives/LayoutControls/context'
import { proxyRefs } from 'vue'
const ctx = useLayout()
+const actions = {
+ updateProp: ctx.updateProp,
+ updateSizeLimit: ctx.updateSizeLimit,
+ setSizeLimitToCurrent: ctx.setSizeLimitToCurrent,
+ commitSizeLimit: ctx.commitSizeLimit,
+ addSizeLimit: ctx.addSizeLimit,
+ removeSizeLimit: ctx.removeSizeLimit,
+ commitProp: ctx.commitProp,
+ setWidthSizing: ctx.setWidthSizing,
+ setHeightSizing: ctx.setHeightSizing,
+ setHorizontalPadding: ctx.setHorizontalPadding,
+ commitHorizontalPadding: ctx.commitHorizontalPadding,
+ setVerticalPadding: ctx.setVerticalPadding,
+ commitVerticalPadding: ctx.commitVerticalPadding,
+ setAlignment: ctx.setAlignment,
+ setGapAuto: ctx.setGapAuto,
+ setLayoutDirection: ctx.setLayoutDirection,
+ updateGridTrack: ctx.updateGridTrack,
+ addTrack: ctx.addTrack,
+ removeTrack: ctx.removeTrack,
+ toggleIndividualPadding: ctx.toggleIndividualPadding
+}
provideLayoutControls(
proxyRefs(ctx) as ReturnType<typeof proxyRefs<typeof ctx>> & {
node: NonNullable<typeof ctx.node.value>
@@ -29,26 +51,7 @@ provideLayoutControls(
:has-uniform-padding="ctx.hasUniformPadding.value"
:has-symmetric-padding="ctx.hasSymmetricPadding.value"
:track-sizing-options="ctx.trackSizingOptions"
- :update-prop="ctx.updateProp"
- :update-size-limit="ctx.updateSizeLimit"
- :set-size-limit-to-current="ctx.setSizeLimitToCurrent"
- :commit-size-limit="ctx.commitSizeLimit"
- :add-size-limit="ctx.addSizeLimit"
- :remove-size-limit="ctx.removeSizeLimit"
- :commit-prop="ctx.commitProp"
- :set-width-sizing="ctx.setWidthSizing"
- :set-height-sizing="ctx.setHeightSizing"
- :set-horizontal-padding="ctx.setHorizontalPadding"
- :commit-horizontal-padding="ctx.commitHorizontalPadding"
- :set-vertical-padding="ctx.setVerticalPadding"
- :commit-vertical-padding="ctx.commitVerticalPadding"
- :set-alignment="ctx.setAlignment"
- :set-gap-auto="ctx.setGapAuto"
- :set-layout-direction="ctx.setLayoutDirection"
- :update-grid-track="ctx.updateGridTrack"
- :add-track="ctx.addTrack"
- :remove-track="ctx.removeTrack"
:track-label="ctx.trackLabel"
- :toggle-individual-padding="ctx.toggleIndividualPadding"
+ :actions="actions"
/>
</template>
diff --git a/packages/vue/src/primitives/PageList/PageListRoot.vue b/packages/vue/src/primitives/PageList/PageListRoot.vue
index 4e848fcb0..94bcb8baa 100644
--- a/packages/vue/src/primitives/PageList/PageListRoot.vue
+++ b/packages/vue/src/primitives/PageList/PageListRoot.vue
@@ -41,6 +41,13 @@ function handleDelete(pageId: string) {
deletePage(pageId)
emit('delete', pageId)
}
+
+const actions = {
+ add: handleAdd,
+ switch: handleSwitch,
+ rename: handleRename,
+ delete: handleDelete
+}
</script>
<template>
@@ -48,9 +55,6 @@ function handleDelete(pageId: string) {
:pages="pages"
:current-page-id="currentPageId"
:is-divider="isDivider"
- :add-page="handleAdd"
- :switch-page="handleSwitch"
- :rename-page="handleRename"
- :delete-page="handleDelete"
+ :actions="actions"
/>
</template>
diff --git a/packages/vue/src/primitives/PositionControls/PositionControlsRoot.vue b/packages/vue/src/primitives/PositionControls/PositionControlsRoot.vue
index 02f3f0608..10eac2c2b 100644
--- a/packages/vue/src/primitives/PositionControls/PositionControlsRoot.vue
+++ b/packages/vue/src/primitives/PositionControls/PositionControlsRoot.vue
@@ -38,6 +38,14 @@ function flip(axis: 'horizontal' | 'vertical') {
function rotate(degrees: number) {
store.rotateNodes(ids.value, degrees)
}
+
+const actions = {
+ updateProp,
+ commitProp,
+ align,
+ flip,
+ rotate
+}
</script>
<template>
@@ -51,10 +59,6 @@ function rotate(degrees: number) {
:h-value="hValue"
:rotation-value="rotationValue"
:mixed="MIXED"
- :update-prop="updateProp"
- :commit-prop="commitProp"
- :align="align"
- :flip="flip"
- :rotate="rotate"
+ :actions="actions"
/>
</template>
diff --git a/packages/vue/src/primitives/PropertyList/PropertyListItem.vue b/packages/vue/src/primitives/PropertyList/PropertyListItem.vue
index 52ddcb66e..ab1f4402d 100644
--- a/packages/vue/src/primitives/PropertyList/PropertyListItem.vue
+++ b/packages/vue/src/primitives/PropertyList/PropertyListItem.vue
@@ -13,34 +13,27 @@ const emit = defineEmits<{
}>()
const { update, patch, remove, toggleVisibility } = usePropertyList()
+
+const actions = {
+ update: (item: unknown) => {
+ emit('update', index, item)
+ update(index, item)
+ },
+ patch: (changes: Record<string, unknown>) => {
+ emit('patch', index, changes)
+ patch(index, changes)
+ },
+ remove: () => {
+ emit('remove', index)
+ remove(index)
+ },
+ toggleVisibility: () => {
+ emit('toggleVisibility', index)
+ toggleVisibility(index)
+ }
+}
</script>
<template>
- <slot
- :index="index"
- :update="
- (item: unknown) => {
- emit('update', index, item)
- update(index, item)
- }
- "
- :patch="
- (changes: Record<string, unknown>) => {
- emit('patch', index, changes)
- patch(index, changes)
- }
- "
- :remove="
- () => {
- emit('remove', index)
- remove(index)
- }
- "
- :toggle-visibility="
- () => {
- emit('toggleVisibility', index)
- toggleVisibility(index)
- }
- "
- />
+ <slot :index="index" :actions="actions" />
</template>
diff --git a/packages/vue/src/primitives/PropertyList/PropertyListRoot.vue b/packages/vue/src/primitives/PropertyList/PropertyListRoot.vue
index 167b3d2a0..deb69a815 100644
--- a/packages/vue/src/primitives/PropertyList/PropertyListRoot.vue
+++ b/packages/vue/src/primitives/PropertyList/PropertyListRoot.vue
@@ -130,6 +130,14 @@ function toggleVisibility(index: number) {
else updateVisibility()
}
+const actions = {
+ add,
+ remove,
+ update,
+ patch,
+ toggleVisibility
+}
+
providePropertyList({
editor,
propKey,
@@ -152,10 +160,6 @@ providePropertyList({
:is-mixed="isMixed"
:is-multi="isMulti"
:active-node="activeNode"
- :add="add"
- :remove="remove"
- :update="update"
- :patch="patch"
- :toggle-visibility="toggleVisibility"
+ :actions="actions"
/>
</template>
diff --git a/packages/vue/src/primitives/ScrubInput/ScrubInputField.vue b/packages/vue/src/primitives/ScrubInput/ScrubInputField.vue
index baaf235da..5a1e8ad2b 100644
--- a/packages/vue/src/primitives/ScrubInput/ScrubInputField.vue
+++ b/packages/vue/src/primitives/ScrubInput/ScrubInputField.vue
@@ -1,17 +1,21 @@
<script setup lang="ts">
+import { templateRef } from '@vueuse/core'
+import { watchEffect } from 'vue'
+
import { useScrubInput } from '#vue/primitives/ScrubInput/context'
const ctx = useScrubInput()
+const inputEl = templateRef<HTMLInputElement>('inputEl')
+
+watchEffect(() => {
+ ctx.inputRef.value = inputEl.value
+})
</script>
<template>
<input
v-if="ctx.editing.value"
- :ref="
- (el) => {
- ctx.inputRef.value = el as HTMLInputElement | null
- }
- "
+ ref="inputEl"
type="number"
:value="ctx.isMixed.value ? '' : ctx.displayValue.value"
v-bind="$attrs"
diff --git a/packages/vue/src/primitives/ScrubInput/ScrubInputRoot.vue b/packages/vue/src/primitives/ScrubInput/ScrubInputRoot.vue
index 25d6404ae..45352aeb1 100644
--- a/packages/vue/src/primitives/ScrubInput/ScrubInputRoot.vue
+++ b/packages/vue/src/primitives/ScrubInput/ScrubInputRoot.vue
@@ -125,6 +125,13 @@ const ctx = {
onKeydown
}
+const actions = {
+ startScrub,
+ startEdit,
+ commitEdit,
+ keydown: onKeydown
+}
+
provideScrubInput(ctx)
watch(editing, (v) => emit('editing-change', v))
@@ -137,10 +144,7 @@ watch(editing, (v) => emit('editing-change', v))
:is-mixed="isMixed"
:editing="editing"
:scrubbing="scrubbing"
- :start-scrub="startScrub"
- :start-edit="startEdit"
- :commit-edit="commitEdit"
- :keydown="onKeydown"
+ :actions="actions"
:placeholder="placeholder"
/>
</template>
diff --git a/packages/vue/src/primitives/Toolbar/ToolbarItem.vue b/packages/vue/src/primitives/Toolbar/ToolbarItem.vue
index 90f7e6013..a9eaace75 100644
--- a/packages/vue/src/primitives/Toolbar/ToolbarItem.vue
+++ b/packages/vue/src/primitives/Toolbar/ToolbarItem.vue
@@ -12,8 +12,11 @@ const { tool } = defineProps<{
const { activeTool, setTool } = useToolbar()
const isActive = computed(() => activeTool.value === tool)
+const actions = {
+ select: () => setTool(tool)
+}
</script>
<template>
- <slot :active="isActive" :select="() => setTool(tool)" :tool="tool" />
+ <slot :active="isActive" :actions="actions" :tool="tool" />
</template>
diff --git a/packages/vue/src/primitives/Toolbar/ToolbarRoot.vue b/packages/vue/src/primitives/Toolbar/ToolbarRoot.vue
index 6fdc56df7..691e80462 100644
--- a/packages/vue/src/primitives/Toolbar/ToolbarRoot.vue
+++ b/packages/vue/src/primitives/Toolbar/ToolbarRoot.vue
@@ -28,6 +28,12 @@ function closeFlyout() {
expandedFlyout.value = null
}
+const actions = {
+ setTool,
+ toggleFlyout,
+ closeFlyout
+}
+
provideToolbar({
editor,
tools,
@@ -44,8 +50,6 @@ provideToolbar({
:tools="tools"
:active-tool="activeTool"
:expanded-flyout="expandedFlyout"
- :set-tool="setTool"
- :toggle-flyout="toggleFlyout"
- :close-flyout="closeFlyout"
+ :actions="actions"
/>
</template>
diff --git a/packages/vue/src/primitives/TypographyControls/TypographyControlsRoot.vue b/packages/vue/src/primitives/TypographyControls/TypographyControlsRoot.vue
index 1ecb19865..52a0e346a 100644
--- a/packages/vue/src/primitives/TypographyControls/TypographyControlsRoot.vue
+++ b/packages/vue/src/primitives/TypographyControls/TypographyControlsRoot.vue
@@ -1,13 +1,14 @@
<script setup lang="ts">
import { useTypography } from '#vue/controls/typography/use'
+import type { TypographyFontLoader } from '#vue/controls/typography/use'
import type { AcceptableValue } from 'reka-ui'
-const { loadFont } = defineProps<{
- loadFont?: (family: string, style: string) => Promise<unknown>
+const { fontLoader } = defineProps<{
+ fontLoader?: TypographyFontLoader
}>()
-const ctx = useTypography({ loadFont })
+const ctx = useTypography({ fontLoader })
function onAlignChange(val: AcceptableValue) {
if (val) ctx.setAlign(val as 'LEFT' | 'CENTER' | 'RIGHT')
@@ -16,6 +17,19 @@ function onAlignChange(val: AcceptableValue) {
function onFormattingChange(val: AcceptableValue | AcceptableValue[]) {
if (Array.isArray(val)) ctx.onFormattingChange(val as string[])
}
+
+const actions = {
+ setFamily: ctx.setFamily,
+ setWeight: ctx.setWeight,
+ setDirection: ctx.setDirection,
+ updateProp: ctx.updateProp,
+ commitProp: ctx.commitProp,
+ align: onAlignChange,
+ formatting: onFormattingChange,
+ toggleBold: ctx.toggleBold,
+ toggleItalic: ctx.toggleItalic,
+ toggleDecoration: ctx.toggleDecoration
+}
</script>
<template>
@@ -25,15 +39,6 @@ function onFormattingChange(val: AcceptableValue | AcceptableValue[]) {
:missing-fonts="ctx.missingFonts"
:has-missing-fonts="ctx.hasMissingFonts"
:active-formatting="ctx.activeFormatting"
- :set-family="ctx.setFamily"
- :set-weight="ctx.setWeight"
- :set-direction="ctx.setDirection"
- :update-prop="ctx.updateProp"
- :commit-prop="ctx.commitProp"
- :on-align-change="onAlignChange"
- :on-formatting-change="onFormattingChange"
- :toggle-bold="ctx.toggleBold"
- :toggle-italic="ctx.toggleItalic"
- :toggle-decoration="ctx.toggleDecoration"
+ :actions="actions"
/>
</template>
diff --git a/packages/vue/src/variables/dialog/use.ts b/packages/vue/src/variables/dialog/use.ts
index 30c8309ff..9e56bb7f6 100644
--- a/packages/vue/src/variables/dialog/use.ts
+++ b/packages/vue/src/variables/dialog/use.ts
@@ -5,25 +5,15 @@ export function useVariablesDialogState() {
const variables = useVariables()
const editingCollectionId = ref<string | null>(null)
- const collectionInputRefs = new Map<string, HTMLInputElement>()
- const pendingCollectionFocusId = ref<string | null>(null)
-
- function setCollectionInputRef(id: string, el: HTMLInputElement | null) {
- if (el) collectionInputRefs.set(id, el)
- else collectionInputRefs.delete(id)
-
- if (el && pendingCollectionFocusId.value === id) {
- pendingCollectionFocusId.value = null
- void nextTick(() => {
- el.focus()
- el.select()
- })
- }
+ async function focusCollectionInput(input: HTMLInputElement | null) {
+ if (!input) return
+ await nextTick()
+ input.focus()
+ input.select()
}
function startRenameCollection(id: string) {
editingCollectionId.value = id
- pendingCollectionFocusId.value = id
}
function commitRenameCollection(id: string, input: HTMLInputElement) {
@@ -39,7 +29,7 @@ export function useVariablesDialogState() {
return {
...variables,
editingCollectionId,
- setCollectionInputRef,
+ focusCollectionInput,
startRenameCollection,
commitRenameCollection
}
diff --git a/src/app/editor/fonts.ts b/src/app/editor/fonts.ts
index d3c208a03..309954ca9 100644
--- a/src/app/editor/fonts.ts
+++ b/src/app/editor/fonts.ts
@@ -1,5 +1,5 @@
import { IS_TAURI } from '@open-pencil/core/constants'
-import { fontManager, styleToWeight } from '@open-pencil/core/text'
+import { fontManager, styleToWeight, type LocalFontAccessState } from '@open-pencil/core/text'
interface TauriFontFamily {
family: string
@@ -29,6 +29,16 @@ export function preloadFonts(): void {
}
}
+export function localFontAccessState(): LocalFontAccessState {
+ return IS_TAURI ? 'granted' : fontManager.localAccessState()
+}
+
+export async function requestLocalFontAccess(): Promise<string[]> {
+ if (IS_TAURI) return listFamilies()
+ await fontManager.requestLocalFontAccess()
+ return fontManager.listFamilies()
+}
+
function registerFontFaces(fonts: TauriFontFamily[]): void {
if (typeof document === 'undefined') return
for (const { family } of fonts) {
diff --git a/src/app/shell/menu/document-name.ts b/src/app/shell/menu/document-name.ts
index 32278e316..9fe8beb94 100644
--- a/src/app/shell/menu/document-name.ts
+++ b/src/app/shell/menu/document-name.ts
@@ -12,10 +12,6 @@ export function useDocumentNameRename(store: EditorStore) {
})
const editingName = computed(() => rename.editingId.value === DOCUMENT_NAME_ID)
- function setNameInputRef(el: HTMLInputElement | null) {
- if (el) void rename.focusInput(el)
- }
-
function startRename() {
rename.start(DOCUMENT_NAME_ID, store.state.documentName)
}
@@ -24,5 +20,5 @@ export function useDocumentNameRename(store: EditorStore) {
rename.commit(DOCUMENT_NAME_ID, input)
}
- return { rename, editingName, setNameInputRef, startRename, commitRename }
+ return { rename, editingName, startRename, commitRename }
}
diff --git a/src/components/AppMenu.vue b/src/components/AppMenu.vue
index 98d4e4f80..3683c55b2 100644
--- a/src/components/AppMenu.vue
+++ b/src/components/AppMenu.vue
@@ -1,4 +1,7 @@
<script setup lang="ts">
+import { watch } from 'vue'
+import { templateRef } from '@vueuse/core'
+
import {
MenubarCheckboxItem,
MenubarContent,
@@ -37,8 +40,12 @@ import { useEditorStore } from '@/app/editor/active-store'
const store = useEditorStore()
-const { rename, editingName, setNameInputRef, startRename, commitRename } =
- useDocumentNameRename(store)
+const { rename, editingName, startRename, commitRename } = useDocumentNameRename(store)
+const nameInput = templateRef<HTMLInputElement>('nameInput')
+
+watch(nameInput, (input) => {
+ if (input) void rename.focusInput(input)
+})
const isMac = navigator.platform.includes('Mac')
const mod = isMac ? '⌘' : 'Ctrl+'
@@ -56,7 +63,7 @@ const subMenuCls = useMenuUI({ content: 'min-w-44' })
<img data-test-id="app-logo" src="/favicon-32.png" class="size-4" alt="OpenPencil" />
<input
v-if="editingName"
- :ref="(el) => setNameInputRef(el as HTMLInputElement | null)"
+ ref="nameInput"
data-test-id="app-document-name-input"
class="min-w-0 flex-1 rounded border border-accent bg-input px-1 py-0.5 text-xs text-surface outline-none"
:value="store.state.documentName"
diff --git a/src/components/ColorPicker/ColorInput.vue b/src/components/ColorPicker/ColorInput.vue
index df4ac3ad2..bf5f67e0e 100644
--- a/src/components/ColorPicker/ColorInput.vue
+++ b/src/components/ColorPicker/ColorInput.vue
@@ -31,18 +31,16 @@ const emit = defineEmits<{ update: [color: Color] }>()
:okhcl="okhcl"
@update="emit('update', $event)"
>
- <template
- #default="{ editable: isEditable, hex, updateFromHex, updateColor, okhcl: okhclControls }"
- >
+ <template #default="{ editable: isEditable, hex, actions, okhcl: okhclControls }">
<div v-bind="attrs" class="flex items-center gap-1.5">
- <ColorPicker :color="color" :okhcl="okhclControls" @update="updateColor($event)" />
+ <ColorPicker :color="color" :okhcl="okhclControls" @update="actions.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)"
+ @change="actions.updateFromHex(($event.target as HTMLInputElement).value)"
/>
<span v-else class="min-w-0 flex-1 truncate font-mono text-xs text-muted">
{{ hex }}
diff --git a/src/components/ColorPicker/ColorPicker.vue b/src/components/ColorPicker/ColorPicker.vue
index 9a41dffb5..9eeae08c3 100644
--- a/src/components/ColorPicker/ColorPicker.vue
+++ b/src/components/ColorPicker/ColorPicker.vue
@@ -15,12 +15,14 @@ const cls = usePopoverUI({ content: 'w-56 p-2' })
<template>
<ColorPickerRoot
:color="color"
- :content-class="cls.content"
- swatch-class="size-5 shrink-0 cursor-pointer rounded border border-border p-0"
+ :ui="{
+ content: cls.content,
+ swatch: 'size-5 shrink-0 cursor-pointer rounded border border-border p-0'
+ }"
@update="emit('update', $event)"
>
- <template #default="{ color: currentColor, update }">
- <ColorPickerPanel :color="currentColor" :okhcl="okhcl" @update="update($event)" />
+ <template #default="{ color: currentColor }">
+ <ColorPickerPanel :color="currentColor" :okhcl="okhcl" @update="emit('update', $event)" />
</template>
</ColorPickerRoot>
</template>
diff --git a/src/components/FillPicker.vue b/src/components/FillPicker.vue
index 62fbf2aff..f7583b65c 100644
--- a/src/components/FillPicker.vue
+++ b/src/components/FillPicker.vue
@@ -39,8 +39,10 @@ const { panels } = useI18n()
<template>
<FillPickerRoot
:fill="fill"
- :content-class="cls.content"
- swatch-class="size-5 shrink-0 cursor-pointer rounded border border-border p-0"
+ :ui="{
+ content: cls.content,
+ swatch: 'size-5 shrink-0 cursor-pointer rounded border border-border p-0'
+ }"
@update="emit('update', $event)"
>
<template #trigger="{ style }">
@@ -50,7 +52,7 @@ const { panels } = useI18n()
:style="{ ...style, background: swatchBackground ?? style.background }"
/>
</template>
- <template #default="{ fill: currentFill, category, toSolid, toGradient, toImage, update }">
+ <template #default="{ fill: currentFill, category, toSolid, toGradient, toImage }">
<div class="mb-2 flex items-center gap-0.5">
<Tip :label="panels.solid">
<button
@@ -85,12 +87,12 @@ const { panels } = useI18n()
v-if="category === 'SOLID'"
:color="currentFill.color"
:okhcl="okhcl"
- @update="update(applySolidFillColor(currentFill, $event))"
+ @update="emit('update', applySolidFillColor(currentFill, $event))"
/>
- <GradientEditor v-if="category === 'GRADIENT'" :fill="currentFill" @update="update($event)" />
+ <GradientEditor v-if="category === 'GRADIENT'" :fill="currentFill" @update="emit('update', $event)" />
- <ImageFillPicker v-if="category === 'IMAGE'" :fill="currentFill" @update="update($event)" />
+ <ImageFillPicker v-if="category === 'IMAGE'" :fill="currentFill" @update="emit('update', $event)" />
</template>
</FillPickerRoot>
</template>
diff --git a/src/components/FontPicker.vue b/src/components/FontPicker.vue
index 8657b4ba2..0105bae96 100644
--- a/src/components/FontPicker.vue
+++ b/src/components/FontPicker.vue
@@ -1,9 +1,12 @@
<script setup lang="ts">
+import { computed } from 'vue'
import { FontPickerRoot } from '@open-pencil/vue'
import { useSelectUI } from '@/components/ui/select'
import { usePopoverUI } from '@/components/ui/popover'
-import { listFamilies } from '@/app/editor/fonts'
+import { listFamilies, localFontAccessState, requestLocalFontAccess } from '@/app/editor/fonts'
+
+import type { FontPickerUi } from '@open-pencil/vue'
const modelValue = defineModel<string>({ required: true })
const emit = defineEmits<{ select: [family: string] }>()
@@ -15,6 +18,20 @@ 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 ui = computed<FontPickerUi>(() => ({
+ trigger: selectCls.trigger,
+ content: cls.content,
+ item: selectCls.item,
+ search: 'w-full border-b border-border bg-transparent px-2 py-1 text-xs text-surface outline-none placeholder:text-muted',
+ empty: 'px-2 py-3 text-center text-xs text-muted',
+ emptyAction: 'mt-2 rounded bg-accent px-2 py-1 text-xs font-medium text-white disabled:opacity-50'
+}))
+
+const localFontAccess = {
+ state: localFontAccessState,
+ load: requestLocalFontAccess
+}
</script>
<template>
@@ -22,11 +39,8 @@ const selectCls = useSelectUI({
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"
+ :local-font-access="localFontAccess"
+ :ui="ui"
empty-fonts-hint="Use the desktop app or Chrome/Edge to access system fonts."
@select="emit('select', $event)"
>
@@ -37,19 +51,7 @@ const selectCls = useSelectUI({
</button>
</template>
- <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>
+
<template #item="{ family, selected }">
<div
diff --git a/src/components/GradientEditor.vue b/src/components/GradientEditor.vue
index d9e86e295..034c79415 100644
--- a/src/components/GradientEditor.vue
+++ b/src/components/GradientEditor.vue
@@ -25,7 +25,7 @@ const { panels } = useI18n()
<AppSelect
:model-value="root.subtype"
:options="root.subtypes"
- @update:model-value="root.setSubtype($event)"
+ @update:model-value="root.actions.setSubtype($event)"
/>
</div>
@@ -33,27 +33,20 @@ const { panels } = useI18n()
:stops="root.stops"
:active-stop-index="root.activeStopIndex"
:bar-background="root.barBackground"
- @select-stop="root.selectStop"
- @drag-stop="root.dragStop"
+ :ui="{ bar: 'relative mb-2 h-6 rounded' }"
+ data-test-id="fill-picker-gradient-bar"
+ @select-stop="root.actions.selectStop"
+ @drag-stop="root.actions.dragStop"
v-slot="bar"
>
<div
- :ref="bar.barRef"
- data-test-id="fill-picker-gradient-bar"
- class="relative mb-2 h-6 rounded"
- :style="{ background: bar.barBackground }"
- @pointermove="bar.onPointerMove"
- @pointerup="bar.onPointerUp"
- >
- <div
- v-for="(stop, idx) in bar.stops"
- :key="idx"
- class="absolute top-1/2 size-3.5 -translate-x-1/2 -translate-y-1/2 cursor-grab rounded-sm border-2 shadow-sm"
- :class="idx === bar.activeStopIndex ? 'border-white' : 'border-white/60'"
- :style="{ left: `${stop.position * 100}%`, background: colorToCSS(stop.color) }"
- @pointerdown.stop="bar.onStopPointerDown(idx, $event)"
- />
- </div>
+ v-for="(stop, idx) in bar.stops"
+ :key="idx"
+ class="absolute top-1/2 size-3.5 -translate-x-1/2 -translate-y-1/2 cursor-grab rounded-sm border-2 shadow-sm"
+ :class="idx === bar.activeStopIndex ? 'border-white' : 'border-white/60'"
+ :style="{ left: `${stop.position * 100}%`, background: colorToCSS(stop.color) }"
+ @pointerdown.stop="bar.actions.stopPointerDown(idx, $event)"
+ />
</GradientEditorBar>
<div class="mb-2">
@@ -63,7 +56,7 @@ const { panels } = useI18n()
<button
class="flex size-4 cursor-pointer items-center justify-center rounded border-none bg-transparent p-0 text-muted hover:text-surface"
data-test-id="fill-picker-add-stop"
- @click="root.addStop"
+ @click="root.actions.addStop"
>
<icon-lucide-plus class="size-3" />
</button>
@@ -75,17 +68,17 @@ const { panels } = useI18n()
:stop="stop"
:index="idx"
:active="idx === root.activeStopIndex"
- @select="root.selectStop"
- @update-position="root.updateStopPosition"
- @update-color="root.updateStopColor"
- @update-opacity="root.updateStopOpacity"
- @remove="root.removeStop"
+ @select="root.actions.selectStop"
+ @update-position="root.actions.updateStopPosition"
+ @update-color="root.actions.updateStopColor"
+ @update-opacity="root.actions.updateStopOpacity"
+ @remove="root.actions.removeStop"
v-slot="s"
>
<div
class="flex items-center gap-1 py-0.5"
:class="{ 'rounded bg-hover/50': s.active }"
- @click="s.select"
+ @click="s.actions.select"
>
<ScrubInput
class="w-11"
@@ -93,19 +86,19 @@ const { panels } = useI18n()
:model-value="s.positionPercent"
:min="0"
:max="100"
- @update:model-value="s.updatePosition(Number($event))"
+ @update:model-value="s.actions.updatePosition(Number($event))"
@click.stop
/>
<button
class="size-4 shrink-0 cursor-pointer rounded border border-border p-0"
:style="{ background: s.css }"
- @click.stop="s.select"
+ @click.stop="s.actions.select"
/>
<input
class="min-w-0 flex-1 rounded border border-border bg-input px-1 py-0.5 font-mono text-[11px] text-surface"
:value="s.hex"
maxlength="6"
- @change="s.updateColor(($event.target as HTMLInputElement).value)"
+ @change="s.actions.updateColor(($event.target as HTMLInputElement).value)"
@click.stop
/>
<ScrubInput
@@ -114,13 +107,13 @@ const { panels } = useI18n()
:model-value="s.opacityPercent"
:min="0"
:max="100"
- @update:model-value="s.updateOpacity(Number($event))"
+ @update:model-value="s.actions.updateOpacity(Number($event))"
@click.stop
/>
<button
v-if="root.stops.length > 2"
class="flex size-4 cursor-pointer items-center justify-center rounded border-none bg-transparent p-0 text-muted hover:text-surface"
- @click.stop="s.remove"
+ @click.stop="s.actions.remove"
>
−
</button>
@@ -128,7 +121,7 @@ const { panels } = useI18n()
</GradientEditorStop>
</div>
- <ColorPickerPanel :color="root.activeColor" @update="root.updateActiveColor" />
+ <ColorPickerPanel :color="root.activeColor" @update="root.actions.updateActiveColor" />
</div>
</GradientEditorRoot>
</template>
diff --git a/src/components/LayerTree.vue b/src/components/LayerTree.vue
index db7b514a0..faa250972 100644
--- a/src/components/LayerTree.vue
+++ b/src/components/LayerTree.vue
@@ -1,5 +1,6 @@
<script setup lang="ts">
-import { useAttrs } from 'vue'
+import { useAttrs, watch } from 'vue'
+import { templateRef } from '@vueuse/core'
import { TreeRoot, TreeItem, ContextMenuRoot, ContextMenuTrigger, ContextMenuPortal } from 'reka-ui'
import {
@@ -19,10 +20,15 @@ defineOptions({ inheritAttrs: false })
const INDENT = 16
const attrs = useAttrs()
const store = useEditorStore()
+const renameInput = templateRef<HTMLInputElement>('renameInput')
const rename = useInlineRename((id, name) => store.renameNode(id, name))
const { menu: t } = useI18n()
const { draggingId, instruction, instructionTargetId } = useLayerDrag(store, INDENT)
+watch(renameInput, (input) => {
+ if (input) void rename.focusInput(input)
+})
+
function onLayerRightClick(e: MouseEvent) {
const row = (e.target as HTMLElement).closest<HTMLElement>('[data-node-id]')
if (!row?.dataset.nodeId) return
@@ -63,10 +69,7 @@ function onTreeSelect(e: CustomEvent, select: (additive: boolean) => void) {
node,
isSelected,
padLeft,
- select: selectNode,
- toggleExpand,
- toggleVisibility,
- toggleLock
+ actions
}"
:node="item.value"
:level="item.level"
@@ -77,7 +80,7 @@ function onTreeSelect(e: CustomEvent, select: (additive: boolean) => void) {
:value="item.value"
:level="item.level"
as-child
- @select="(e: CustomEvent) => onTreeSelect(e, selectNode)"
+ @select="(e: CustomEvent) => onTreeSelect(e, actions.select)"
@toggle="
(e: CustomEvent) => {
if (e.detail.originalEvent?.type === 'click') e.preventDefault()
@@ -94,18 +97,14 @@ function onTreeSelect(e: CustomEvent, select: (additive: boolean) => void) {
v-if="item.hasChildren"
class="flex w-4 shrink-0 cursor-pointer items-center justify-center text-muted transition-transform hover:text-surface"
:class="isExpanded ? 'rotate-90' : 'rotate-0'"
- @click.stop="toggleExpand"
+ @click.stop="actions.toggleExpand"
>
<icon-lucide-chevron-right class="size-3" />
</span>
<span v-else class="w-4 shrink-0" />
<component :is="nodeIcon(node)" class="size-3 shrink-0 opacity-70" />
<input
- :ref="
- (el) => {
- if (el) rename.focusInput(el as HTMLInputElement)
- }
- "
+ ref="renameInput"
data-layer-edit
data-test-id="layers-item-input"
class="min-w-0 flex-1 rounded border border-accent bg-input px-1 py-0 text-xs text-surface outline-none"
@@ -137,7 +136,7 @@ function onTreeSelect(e: CustomEvent, select: (additive: boolean) => void) {
v-if="item.hasChildren"
class="flex w-4 shrink-0 cursor-pointer items-center justify-center text-muted transition-transform hover:text-surface"
:class="isExpanded ? 'rotate-90' : 'rotate-0'"
- @click.stop="toggleExpand"
+ @click.stop="actions.toggleExpand"
>
<icon-lucide-chevron-right class="size-3" />
</span>
@@ -162,7 +161,7 @@ function onTreeSelect(e: CustomEvent, select: (additive: boolean) => void) {
<span
class="flex size-4 items-center justify-center rounded hover:bg-white/15"
@pointerdown.stop
- @click.stop="toggleLock"
+ @click.stop="actions.toggleLock"
>
<icon-lucide-lock
v-if="node.locked"
@@ -180,7 +179,7 @@ function onTreeSelect(e: CustomEvent, select: (additive: boolean) => void) {
<span
class="flex size-4 items-center justify-center rounded hover:bg-white/15"
@pointerdown.stop
- @click.stop="toggleVisibility"
+ @click.stop="actions.toggleVisibility"
>
<icon-lucide-eye-off
v-if="!node.visible"
diff --git a/src/components/PagesPanel.vue b/src/components/PagesPanel.vue
index db5337977..6973d67b4 100644
--- a/src/components/PagesPanel.vue
+++ b/src/components/PagesPanel.vue
@@ -1,36 +1,29 @@
<script setup lang="ts">
-import { ref } from 'vue'
+import { ref, watch } from 'vue'
+import { templateRef } from '@vueuse/core'
import { PageListRoot, useI18n, useInlineRename } from '@open-pencil/vue'
import Tip from '@/components/ui/Tip.vue'
-const pageInputRefs = new Map<string, HTMLInputElement>()
-const activeRenameId = ref<string | null>(null)
-const rename = useInlineRename((id, name) => pageActions.value?.renamePage(id, name))
+const pageInput = templateRef<HTMLInputElement>('pageInput')
+const rename = useInlineRename((id, name) => pageActions.value?.rename(id, name))
const { panels } = useI18n()
const pageActions = ref<{
- renamePage: (pageId: string, name: string) => void
+ rename: (pageId: string, name: string) => void
} | null>(null)
function setPageActions(renamePage: (pageId: string, name: string) => void) {
- pageActions.value = { renamePage }
+ pageActions.value = { rename: renamePage }
}
-function setPageInputRef(pageId: string, el: HTMLInputElement | null) {
- if (el) pageInputRefs.set(pageId, el)
- else pageInputRefs.delete(pageId)
-
- if (el && activeRenameId.value === pageId) {
- activeRenameId.value = null
- void rename.focusInput(el)
- }
-}
+watch(pageInput, (input) => {
+ if (input) void rename.focusInput(input)
+})
function startRename(pg: { id: string; name: string }) {
rename.start(pg.id, pg.name)
- activeRenameId.value = pg.id
}
function handlePageDblClick(
@@ -43,7 +36,7 @@ function handlePageDblClick(
</script>
<template>
- <PageListRoot v-slot="{ pages, currentPageId, isDivider, addPage, switchPage, renamePage }">
+ <PageListRoot v-slot="{ pages, currentPageId, isDivider, actions }">
<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">{{
@@ -53,7 +46,7 @@ function handlePageDblClick(
<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()"
+ @click="actions.add()"
>
+
</button>
@@ -67,7 +60,7 @@ function handlePageDblClick(
>
<icon-lucide-file class="size-3 shrink-0 opacity-70" />
<input
- :ref="(el) => setPageInputRef(pg.id, el as HTMLInputElement | null)"
+ ref="pageInput"
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"
@@ -91,8 +84,8 @@ function handlePageDblClick(
? 'bg-hover text-surface'
: 'bg-transparent text-muted hover:bg-hover hover:text-surface'
"
- @click="switchPage(pg.id)"
- @dblclick="handlePageDblClick(pg, renamePage)"
+ @click="actions.switch(pg.id)"
+ @dblclick="handlePageDblClick(pg, actions.rename)"
>
<icon-lucide-file class="size-3 shrink-0" />
<span class="truncate">{{ pg.name }}</span>
diff --git a/src/components/ScrubInput.vue b/src/components/ScrubInput.vue
index 75859d24b..a8d2d4051 100644
--- a/src/components/ScrubInput.vue
+++ b/src/components/ScrubInput.vue
@@ -29,7 +29,7 @@ defineOptions({ inheritAttrs: false })
<template>
<ScrubInputRoot
- v-slot="{ editing, startScrub, startEdit, placeholder: ph }"
+ v-slot="{ editing, actions, placeholder: ph }"
:model-value="modelValue"
:min="min"
:max="max"
@@ -50,9 +50,9 @@ defineOptions({ inheritAttrs: false })
]"
:style="{ cursor: editing ? 'auto' : 'ew-resize' }"
@pointerdown="
- !editing && !($event.target as HTMLElement)?.closest?.('button') && startScrub($event)
+ !editing && !($event.target as HTMLElement)?.closest?.('button') && actions.startScrub($event)
"
- @focus="!editing && startEdit()"
+ @focus="!editing && actions.startEdit()"
>
<span v-if="attrs['data-test-id']" data-test-id="scrub-input" class="hidden" />
<span
diff --git a/src/components/Toolbar/DesktopToolbar.vue b/src/components/Toolbar/DesktopToolbar.vue
index 3818c1448..3e941d5aa 100644
--- a/src/components/Toolbar/DesktopToolbar.vue
+++ b/src/components/Toolbar/DesktopToolbar.vue
@@ -6,17 +6,16 @@ import { ToolbarItem } from '@open-pencil/vue'
import type { Tool } from '@open-pencil/vue'
import type { EditorToolDef } from '@open-pencil/core/editor'
-import type { ToolIconMap, ToolLabels } from '@/components/Toolbar/types'
+import type { ToolbarUi, ToolIconMap, ToolLabels } from '@/components/Toolbar/types'
-const { tools, activeTool, toolIcons, toolLabels, toolShortcuts, flyoutContentClass } =
- defineProps<{
+const { tools, activeTool, toolIcons, toolLabels, toolShortcuts, ui } = defineProps<{
tools: EditorToolDef[]
activeTool: Tool
toolIcons: ToolIconMap
- toolLabels: ToolLabels
- toolShortcuts: Record<Tool, string>
- flyoutContentClass: string
- }>()
+ toolLabels: ToolLabels
+ toolShortcuts: Record<Tool, string>
+ ui?: ToolbarUi
+}>()
const emit = defineEmits<{
setTool: [tool: Tool]
@@ -48,18 +47,18 @@ function activeKeyForTool(tool: EditorToolDef) {
:tool-icons="toolIcons"
:tool-labels="toolLabels"
:tool-shortcuts="toolShortcuts"
- :content-class="flyoutContentClass"
+ :ui="ui"
@select="emit('setTool', $event)"
/>
</Tip>
- <ToolbarItem v-else v-slot="{ active, select: selectTool }" :tool="tool.key">
+ <ToolbarItem v-else v-slot="{ active, actions }" :tool="tool.key">
<Tip :label="`${toolLabels[tool.key]} (${tool.shortcut})`">
<ToolButton
:test-id="`toolbar-tool-${tool.key.toLowerCase()}`"
:icon="toolIcons[tool.key]"
:active="active || isActive(tool)"
- @click="selectTool"
+ @click="actions.select"
/>
</Tip>
</ToolbarItem>
diff --git a/src/components/Toolbar/MobileToolbar.vue b/src/components/Toolbar/MobileToolbar.vue
index e7abe8b8b..812da8bb5 100644
--- a/src/components/Toolbar/MobileToolbar.vue
+++ b/src/components/Toolbar/MobileToolbar.vue
@@ -11,7 +11,7 @@ import { ToolbarItem } from '@open-pencil/vue'
import type { Tool } from '@open-pencil/vue'
import type { EditorToolDef } from '@open-pencil/core/editor'
-import type { ToolbarActionItem, ToolIconMap, ToolLabels } from '@/components/Toolbar/types'
+import type { ToolbarActionItem, ToolbarUi, ToolIconMap, ToolLabels } from '@/components/Toolbar/types'
const {
tools,
@@ -19,7 +19,7 @@ const {
toolIcons,
toolLabels,
toolShortcuts,
- flyoutContentClass,
+ ui,
mobileCategory,
slideDirection,
hasPrev,
@@ -32,7 +32,7 @@ const {
toolIcons: ToolIconMap
toolLabels: ToolLabels
toolShortcuts: Record<Tool, string>
- flyoutContentClass: string
+ ui?: ToolbarUi
mobileCategory: number
slideDirection: number
hasPrev: boolean
@@ -106,17 +106,17 @@ function activeKeyForTool(tool: EditorToolDef) {
:tool-icons="toolIcons"
:tool-labels="toolLabels"
:tool-shortcuts="toolShortcuts"
- :content-class="flyoutContentClass"
+ :ui="ui"
@select="emit('setTool', $event)"
/>
- <ToolbarItem v-else v-slot="{ active, select: selectTool }" :tool="tool.key">
+ <ToolbarItem v-else v-slot="{ active, actions }" :tool="tool.key">
<ToolButton
mobile
:test-id="`mobile-toolbar-tool-${tool.key.toLowerCase()}`"
:icon="toolIcons[tool.key]"
:active="active || activeKeyForTool(tool) === activeTool"
- @click="selectTool"
+ @click="actions.select"
/>
</ToolbarItem>
</template>
diff --git a/src/components/Toolbar/ToolFlyout.vue b/src/components/Toolbar/ToolFlyout.vue
index d765d8c2d..e64055f35 100644
--- a/src/components/Toolbar/ToolFlyout.vue
+++ b/src/components/Toolbar/ToolFlyout.vue
@@ -15,7 +15,7 @@ import { ToolbarItem } from '@open-pencil/vue'
import type { Tool } from '@open-pencil/vue'
import type { EditorToolDef } from '@open-pencil/core/editor'
-import type { ToolIconMap, ToolLabels } from '@/components/Toolbar/types'
+import type { ToolbarUi, ToolIconMap, ToolLabels } from '@/components/Toolbar/types'
const {
tool,
@@ -23,7 +23,7 @@ const {
toolIcons,
toolLabels,
toolShortcuts,
- contentClass,
+ ui,
mobile = false
} = defineProps<{
tool: EditorToolDef
@@ -31,7 +31,7 @@ const {
toolIcons: ToolIconMap
toolLabels: ToolLabels
toolShortcuts: Record<Tool, string>
- contentClass: string
+ ui?: ToolbarUi
mobile?: boolean
}>()
@@ -85,17 +85,17 @@ function activeKeyForTool() {
</DropdownMenuTrigger>
<DropdownMenuPortal>
- <DropdownMenuContent side="top" :side-offset="8" align="start" :class="contentClass">
+ <DropdownMenuContent side="top" :side-offset="8" align="start" :class="ui?.flyoutContent">
<ToolbarItem
v-for="sub in tool.flyout"
:key="sub"
- v-slot="{ active: subActive, select: selectSub }"
+ v-slot="{ active: subActive, actions }"
:tool="sub"
>
<DropdownMenuItem
:data-test-id="`${mobile ? 'mobile-' : ''}toolbar-flyout-item-${sub.toLowerCase()}`"
:class="menu().item({ class: subActive ? 'bg-accent text-white' : undefined })"
- @select="selectSub"
+ @select="actions.select"
>
<component :is="toolIcons[sub]" class="size-3.5" />
<span class="flex-1">{{ toolLabels[sub] }}</span>
diff --git a/src/components/Toolbar/Toolbar.vue b/src/components/Toolbar/Toolbar.vue
index 48039d8f0..eb223c302 100644
--- a/src/components/Toolbar/Toolbar.vue
+++ b/src/components/Toolbar/Toolbar.vue
@@ -54,6 +54,7 @@ const toolShortcuts: Record<Tool, string> = {
}
const flyoutMenuCls = useMenuUI({ content: 'min-w-32' })
+const toolbarUi = { flyoutContent: flyoutMenuCls.content }
const { editActions, arrangeActions } = useToolbarActions({ store, getCommand, menu })
const { mobileCategory, slideDirection, hasPrev, hasNext, goPrev, goNext } = useToolbarState()
@@ -65,7 +66,7 @@ function onActionTap(item: ToolbarActionItem) {
</script>
<template>
- <ToolbarRoot v-slot="{ tools, activeTool, setTool }">
+ <ToolbarRoot v-slot="{ tools, activeTool, actions }">
<DesktopToolbar
v-if="!isMobile"
:tools="tools"
@@ -73,8 +74,8 @@ function onActionTap(item: ToolbarActionItem) {
:tool-icons="toolIcons"
:tool-labels="toolLabels"
:tool-shortcuts="toolShortcuts"
- :flyout-content-class="flyoutMenuCls.content"
- @set-tool="setTool"
+ :ui="toolbarUi"
+ @set-tool="actions.setTool"
/>
<MobileToolbar
@@ -84,14 +85,14 @@ function onActionTap(item: ToolbarActionItem) {
:tool-icons="toolIcons"
:tool-labels="toolLabels"
:tool-shortcuts="toolShortcuts"
- :flyout-content-class="flyoutMenuCls.content"
+ :ui="toolbarUi"
:mobile-category="mobileCategory"
:slide-direction="slideDirection"
:has-prev="hasPrev"
:has-next="hasNext"
:edit-actions="editActions"
:arrange-actions="arrangeActions"
- @set-tool="setTool"
+ @set-tool="actions.setTool"
@prev="goPrev"
@next="goNext"
@action="onActionTap"
diff --git a/src/components/Toolbar/types.ts b/src/components/Toolbar/types.ts
index 03a93e547..e25aefec3 100644
--- a/src/components/Toolbar/types.ts
+++ b/src/components/Toolbar/types.ts
@@ -7,5 +7,9 @@ export interface ToolbarActionItem {
action: () => void
}
+export interface ToolbarUi {
+ flyoutContent?: string
+}
+
export type ToolLabels = Record<Tool, string>
export type ToolIconMap = Record<Tool, Component>
diff --git a/src/components/VariablesDialog.vue b/src/components/VariablesDialog.vue
index d29c1d059..0d158e848 100644
--- a/src/components/VariablesDialog.vue
+++ b/src/components/VariablesDialog.vue
@@ -1,5 +1,6 @@
<script setup lang="ts">
-import { type Component } from 'vue'
+import { watch, type Component } from 'vue'
+import { templateRef } from '@vueuse/core'
import {
DialogClose,
DialogContent,
@@ -43,6 +44,11 @@ const ctx = useVariablesEditor({
fallbackIcon: IconToggleLeft,
deleteIcon: IconX
})
+const collectionInput = templateRef<HTMLInputElement>('collectionInput')
+
+watch(collectionInput, (input) => {
+ void ctx.focusCollectionInput(input)
+})
</script>
<template>
@@ -85,7 +91,7 @@ const ctx = useVariablesEditor({
<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)"
+ ref="collectionInput"
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)"
diff --git a/src/components/properties/EffectsSection.vue b/src/components/properties/EffectsSection.vue
index 45ffedaf2..d361e6560 100644
--- a/src/components/properties/EffectsSection.vue
+++ b/src/components/properties/EffectsSection.vue
@@ -17,7 +17,7 @@ const sectionCls = useSectionUI()
<template>
<PropertyListRoot
- v-slot="{ items, isMixed, activeNode, patch, add, remove, toggleVisibility }"
+ v-slot="{ items, isMixed, activeNode, actions }"
prop-key="effects"
:label="panels.effects"
>
@@ -27,7 +27,7 @@ const sectionCls = useSectionUI()
<button
data-test-id="effects-section-add"
:class="useIconButtonUI().base"
- @click="add(effectsCtx.createDefaultEffect())"
+ @click="actions.add(effectsCtx.createDefaultEffect())"
>
+
</button>
@@ -60,7 +60,7 @@ const sectionCls = useSectionUI()
:model-value="effect.type"
:options="effectsCtx.effectOptions"
@update:model-value="
- effectsCtx.updateType(patch, activeNode, i, $event as Effect['type'])
+ effectsCtx.updateType(actions.patch, activeNode, i, $event as Effect['type'])
"
/>
@@ -68,7 +68,7 @@ const sectionCls = useSectionUI()
:data-test-id="`effect-visibility-${i}`"
:data-visible="effect.visible ? 'true' : 'false'"
class="cursor-pointer border-none bg-transparent p-0 text-muted hover:text-surface"
- @click="toggleVisibility(i)"
+ @click="actions.toggleVisibility(i)"
>
<icon-lucide-eye
v-if="effect.visible"
@@ -77,7 +77,7 @@ const sectionCls = useSectionUI()
/>
<icon-lucide-eye-off v-else data-test-id="visibility-icon-off" class="size-3.5" />
</button>
- <button :class="useIconButtonUI().base" @click="effectsCtx.handleRemove(remove, i)">
+ <button :class="useIconButtonUI().base" @click="effectsCtx.handleRemove(actions.remove, i)">
−
</button>
</div>
@@ -131,7 +131,7 @@ const sectionCls = useSectionUI()
<ColorInput
:color="effect.color"
editable
- @update="effectsCtx.updateColor(patch, i, $event)"
+ @update="effectsCtx.updateColor(actions.patch, i, $event)"
/>
<ScrubInput
class="w-14"
diff --git a/src/components/properties/FillSection.vue b/src/components/properties/FillSection.vue
index 5662b488d..784b365ba 100644
--- a/src/components/properties/FillSection.vue
+++ b/src/components/properties/FillSection.vue
@@ -34,7 +34,7 @@ function updateFill(
<template>
<PropertyListRoot
- v-slot="{ items, isMixed, activeNode, add, remove, update, patch, toggleVisibility }"
+ v-slot="{ items, isMixed, activeNode, actions }"
prop-key="fills"
:label="panels.fill"
>
@@ -44,7 +44,7 @@ function updateFill(
<button
data-test-id="fill-section-add"
:class="useIconButtonUI().base"
- @click="add({ ...fillCtx.defaultFill })"
+ @click="actions.add({ ...fillCtx.defaultFill })"
>
+
</button>
@@ -63,9 +63,9 @@ function updateFill(
unbind-test-id="fill-unbind-variable"
data-test-id="fill-item"
:data-test-index="i"
- @patch="patch(i, $event)"
- @toggle-visibility="toggleVisibility(i)"
- @remove="remove(i)"
+ @patch="actions.patch(i, $event)"
+ @toggle-visibility="actions.toggleVisibility(i)"
+ @remove="actions.remove(i)"
>
<FillPicker
:fill="activeNode ? displayFillWithBoundVariable(fillCtx, activeNode.id, i, fill) : fill"
@@ -73,7 +73,7 @@ function updateFill(
:swatch-background="
activeNode ? boundVariableSwatchBackground(fillCtx, activeNode.id, i) : undefined
"
- @update="updateFill(activeNode, i, $event, update)"
+ @update="updateFill(activeNode, i, $event, actions.update)"
/>
<span
diff --git a/src/components/properties/LayoutSection/SizeControls.vue b/src/components/properties/LayoutSection/SizeControls.vue
index 060d7afe7..2b291e13d 100644
--- a/src/components/properties/LayoutSection/SizeControls.vue
+++ b/src/components/properties/LayoutSection/SizeControls.vue
@@ -1,5 +1,6 @@
<script setup lang="ts">
-import { ref } from 'vue'
+import { computed, ref } from 'vue'
+import { useTemplateRefsList } from '@vueuse/core'
import {
SelectContent,
SelectItem,
@@ -36,12 +37,7 @@ const widthVariableBinding = useNumberVariableBinding('width')
const heightVariableBinding = useNumberVariableBinding('height')
const widthFieldRef = ref<HTMLElement | null>(null)
const heightFieldRef = ref<HTMLElement | null>(null)
-const limitFieldRefs = ref<Record<SizeLimitProp, HTMLElement | null>>({
- minWidth: null,
- maxWidth: null,
- minHeight: null,
- maxHeight: null
-})
+const limitFieldRefs = useTemplateRefsList<HTMLElement>()
const { panels, dialogs } = useI18n()
const sizingSelect = useSelectUI({ item: 'rounded py-1.5 pr-2 pl-6 text-xs' })
@@ -94,6 +90,8 @@ const activeSizeLimits: ActiveSizeLimit[] = [
}
]
+const visibleSizeLimits = computed(() => activeSizeLimits.filter((item) => item.value() != null))
+
const heightLimitItems = [
{
prop: 'minHeight' as const,
@@ -111,6 +109,10 @@ function anchorRef(element: HTMLElement | null): HTMLElement | undefined {
return element ?? undefined
}
+function limitFieldAnchor(index: number): HTMLElement | undefined {
+ return anchorRef(limitFieldRefs.value[index] ?? null)
+}
+
function handleLimitSelect(prop: SizeLimitProp, value: string) {
if (value === 'CURRENT') ctx.setSizeLimitToCurrent(prop)
else if (value === 'REMOVE') ctx.removeSizeLimit(prop)
@@ -334,12 +336,8 @@ function handleSizeSelect(axis: 'width' | 'height', value: SizeSelectValue) {
"
class="mt-1.5 grid grid-cols-2 gap-1.5"
>
- <template v-for="item in activeSizeLimits" :key="item.prop">
- <div
- v-if="item.value() != null"
- :ref="(el) => (limitFieldRefs[item.prop] = el as HTMLElement | null)"
- class="min-w-0"
- >
+ <template v-for="(item, index) in visibleSizeLimits" :key="item.prop">
+ <div :ref="limitFieldRefs.set" class="min-w-0">
<ScrubInput
:data-test-id="item.testId"
:icon="item.icon()"
@@ -355,7 +353,7 @@ function handleSizeSelect(axis: 'width' | 'height', value: SizeSelectValue) {
>
<SelectTrigger
:data-test-id="`${item.testId}-menu`"
- :reference="anchorRef(limitFieldRefs[item.prop])"
+ :reference="limitFieldAnchor(index)"
class="flex shrink-0 cursor-pointer items-center self-stretch border-none bg-transparent px-1 text-[11px] text-muted outline-none"
@pointerdown.stop
>
diff --git a/src/components/properties/PositionSection.vue b/src/components/properties/PositionSection.vue
index 2e3e8001e..d86261cbc 100644
--- a/src/components/properties/PositionSection.vue
+++ b/src/components/properties/PositionSection.vue
@@ -34,11 +34,7 @@ function handleAlign(
wValue,
hValue,
rotationValue,
- updateProp,
- commitProp,
- align,
- flip,
- rotate
+ actions
}"
>
<div v-if="active" data-test-id="position-section" :class="sectionCls.wrapper">
@@ -50,7 +46,7 @@ function handleAlign(
<button
:class="useIconButtonUI({ size: 'md' }).base"
data-test-id="position-align-left"
- @click="handleAlign(align, 'horizontal', 'min')"
+ @click="handleAlign(actions.align, 'horizontal', 'min')"
>
<icon-lucide-align-start-vertical class="size-3.5" />
</button>
@@ -59,7 +55,7 @@ function handleAlign(
<button
:class="useIconButtonUI({ size: 'md' }).base"
data-test-id="position-align-center-h"
- @click="handleAlign(align, 'horizontal', 'center')"
+ @click="handleAlign(actions.align, 'horizontal', 'center')"
>
<icon-lucide-align-center-vertical class="size-3.5" />
</button>
@@ -68,7 +64,7 @@ function handleAlign(
<button
:class="useIconButtonUI({ size: 'md' }).base"
data-test-id="position-align-right"
- @click="handleAlign(align, 'horizontal', 'max')"
+ @click="handleAlign(actions.align, 'horizontal', 'max')"
>
<icon-lucide-align-end-vertical class="size-3.5" />
</button>
@@ -79,7 +75,7 @@ function handleAlign(
<button
:class="useIconButtonUI({ size: 'md' }).base"
data-test-id="position-align-top"
- @click="handleAlign(align, 'vertical', 'min')"
+ @click="handleAlign(actions.align, 'vertical', 'min')"
>
<icon-lucide-align-start-horizontal class="size-3.5" />
</button>
@@ -88,7 +84,7 @@ function handleAlign(
<button
:class="useIconButtonUI({ size: 'md' }).base"
data-test-id="position-align-center-v"
- @click="handleAlign(align, 'vertical', 'center')"
+ @click="handleAlign(actions.align, 'vertical', 'center')"
>
<icon-lucide-align-center-horizontal class="size-3.5" />
</button>
@@ -97,7 +93,7 @@ function handleAlign(
<button
:class="useIconButtonUI({ size: 'md' }).base"
data-test-id="position-align-bottom"
- @click="handleAlign(align, 'vertical', 'max')"
+ @click="handleAlign(actions.align, 'vertical', 'max')"
>
<icon-lucide-align-end-horizontal class="size-3.5" />
</button>
@@ -109,14 +105,14 @@ function handleAlign(
<ScrubInput
icon="X"
:model-value="xValue"
- @update:model-value="updateProp('x', $event)"
- @commit="(v: number, p: number) => commitProp('x', v, p)"
+ @update:model-value="actions.updateProp('x', $event)"
+ @commit="(v: number, p: number) => actions.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)"
+ @update:model-value="actions.updateProp('y', $event)"
+ @commit="(v: number, p: number) => actions.commitProp('y', v, p)"
/>
</div>
@@ -125,15 +121,15 @@ function handleAlign(
icon="W"
:model-value="wValue"
:min="1"
- @update:model-value="updateProp('width', $event)"
- @commit="(v: number, p: number) => commitProp('width', v, p)"
+ @update:model-value="actions.updateProp('width', $event)"
+ @commit="(v: number, p: number) => actions.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)"
+ @update:model-value="actions.updateProp('height', $event)"
+ @commit="(v: number, p: number) => actions.commitProp('height', v, p)"
/>
</div>
@@ -144,8 +140,8 @@ function handleAlign(
:model-value="rotationValue"
:min="-360"
:max="360"
- @update:model-value="updateProp('rotation', $event)"
- @commit="(v: number, p: number) => commitProp('rotation', v, p)"
+ @update:model-value="actions.updateProp('rotation', $event)"
+ @commit="(v: number, p: number) => actions.commitProp('rotation', v, p)"
>
<template #icon>
<icon-lucide-rotate-cw class="size-3" />
@@ -155,7 +151,7 @@ function handleAlign(
<button
:class="useIconButtonUI({ size: 'md', ui: { base: 'shrink-0' } }).base"
data-test-id="position-flip-horizontal"
- @click="flip('horizontal')"
+ @click="actions.flip('horizontal')"
>
<icon-lucide-flip-horizontal-2 class="size-3.5" />
</button>
@@ -164,7 +160,7 @@ function handleAlign(
<button
:class="useIconButtonUI({ size: 'md', ui: { base: 'shrink-0' } }).base"
data-test-id="position-flip-vertical"
- @click="flip('vertical')"
+ @click="actions.flip('vertical')"
>
<icon-lucide-flip-vertical-2 class="size-3.5" />
</button>
@@ -173,7 +169,7 @@ function handleAlign(
<button
:class="useIconButtonUI({ size: 'md', ui: { base: 'shrink-0' } }).base"
data-test-id="position-rotate-90"
- @click="rotate(90)"
+ @click="actions.rotate(90)"
>
<icon-lucide-rotate-cw-square class="size-3.5" />
</button>
diff --git a/src/components/properties/StrokeSection.vue b/src/components/properties/StrokeSection.vue
index 475c5d783..ba61a327d 100644
--- a/src/components/properties/StrokeSection.vue
+++ b/src/components/properties/StrokeSection.vue
@@ -84,7 +84,7 @@ function setGap(stroke: Stroke | undefined, patch: StrokePatch, value: number) {
<template>
<PropertyListRoot
- v-slot="{ items, isMixed, activeNode, add, remove, patch, toggleVisibility }"
+ v-slot="{ items, isMixed, activeNode, actions }"
prop-key="strokes"
:label="panels.stroke"
>
@@ -94,7 +94,7 @@ function setGap(stroke: Stroke | undefined, patch: StrokePatch, value: number) {
<button
data-test-id="stroke-section-add"
:class="useIconButtonUI().base"
- @click="add(strokeCtx.defaultStroke)"
+ @click="actions.add(strokeCtx.defaultStroke)"
>
+
</button>
@@ -115,9 +115,9 @@ function setGap(stroke: Stroke | undefined, patch: StrokePatch, value: number) {
unbind-test-id="stroke-unbind-variable"
data-test-id="stroke-item"
:data-test-index="i"
- @patch="patch(i, $event)"
- @toggle-visibility="toggleVisibility(i)"
- @remove="remove(i)"
+ @patch="actions.patch(i, $event)"
+ @toggle-visibility="actions.toggleVisibility(i)"
+ @remove="actions.remove(i)"
>
<ColorInput
class="min-w-0 flex-1"
@@ -139,7 +139,7 @@ function setGap(stroke: Stroke | undefined, patch: StrokePatch, value: number) {
: null
"
editable
- @update="updateStrokeColor(activeNode, i, $event, patch)"
+ @update="updateStrokeColor(activeNode, i, $event, actions.patch)"
/>
</ColorStyleRow>
@@ -158,7 +158,7 @@ function setGap(stroke: Stroke | undefined, patch: StrokePatch, value: number) {
class="flex-1"
:model-value="activeNode!.strokes[0]?.weight ?? 1"
:min="0"
- @update:model-value="patch(0, { weight: $event })"
+ @update:model-value="actions.patch(0, { weight: $event })"
>
<template #icon>
<svg
@@ -204,7 +204,7 @@ function setGap(stroke: Stroke | undefined, patch: StrokePatch, value: number) {
? '!border-accent !text-accent'
: 'border-border text-muted hover:bg-hover hover:text-surface'
"
- @click="toggleDash((items as Stroke[])[0], patch)"
+ @click="toggleDash((items as Stroke[])[0], actions.patch)"
>
<svg
class="size-3"
@@ -222,7 +222,7 @@ function setGap(stroke: Stroke | undefined, patch: StrokePatch, value: number) {
:model-value="(items as Stroke[])[0].dashPattern?.[0] ?? 6"
:min="1"
data-test-id="stroke-dash-length"
- @update:model-value="setDash((items as Stroke[])[0], patch, $event)"
+ @update:model-value="setDash((items as Stroke[])[0], actions.patch, $event)"
>
<template #icon>
<svg
@@ -246,7 +246,7 @@ function setGap(stroke: Stroke | undefined, patch: StrokePatch, value: number) {
"
:min="1"
data-test-id="stroke-dash-gap"
- @update:model-value="setGap((items as Stroke[])[0], patch, $event)"
+ @update:model-value="setGap((items as Stroke[])[0], actions.patch, $event)"
>
<template #icon>
<svg
diff --git a/src/components/properties/TypographySection.vue b/src/components/properties/TypographySection.vue
index 257b87d0b..a81a70a30 100644
--- a/src/components/properties/TypographySection.vue
+++ b/src/components/properties/TypographySection.vue
@@ -13,10 +13,11 @@ import { loadFont } from '@/app/editor/fonts'
const { panels } = useI18n()
const sectionCls = useSectionUI()
+const fontLoader = { load: loadFont }
</script>
<template>
- <TypographyControlsRoot v-slot="ctx" :load-font="loadFont">
+ <TypographyControlsRoot v-slot="ctx" :font-loader="fontLoader">
<div v-if="ctx.node.value" data-test-id="typography-section" :class="sectionCls.wrapper">
<label class="mb-1.5 block text-[11px] text-muted">{{ panels.typography }}</label>
@@ -24,7 +25,7 @@ const sectionCls = useSectionUI()
<FontPicker
class="min-w-0 flex-1"
:model-value="ctx.node.value.fontFamily"
- @select="ctx.setFamily"
+ @select="ctx.actions.setFamily"
/>
<Tip
v-if="ctx.hasMissingFonts.value"
@@ -46,7 +47,7 @@ const sectionCls = useSectionUI()
<AppSelect
:model-value="ctx.node.value.fontWeight"
:options="ctx.weights"
- @update:model-value="ctx.setWeight(+$event)"
+ @update:model-value="ctx.actions.setWeight(+$event)"
/>
<VariableScrubInput
class="flex-1"
@@ -55,8 +56,8 @@ const sectionCls = useSectionUI()
:max="1000"
:node-id="ctx.node.value.id"
binding-path="fontSize"
- @update:model-value="ctx.updateProp('fontSize', $event)"
- @commit="(v: number, p: number) => ctx.commitProp('fontSize', v, p)"
+ @update:model-value="ctx.actions.updateProp('fontSize', $event)"
+ @commit="(v: number, p: number) => ctx.actions.commitProp('fontSize', v, p)"
/>
</div>
@@ -67,8 +68,8 @@ const sectionCls = useSectionUI()
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)"
+ @update:model-value="ctx.actions.updateProp('lineHeight', $event)"
+ @commit="(v: number, p: number) => ctx.actions.commitProp('lineHeight', v, p)"
>
<template #icon>
<icon-lucide-baseline class="size-3" />
@@ -78,8 +79,8 @@ const sectionCls = useSectionUI()
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)"
+ @update:model-value="ctx.actions.updateProp('letterSpacing', $event)"
+ @commit="(v: number, p: number) => ctx.actions.commitProp('letterSpacing', v, p)"
>
<template #icon>
<icon-lucide-a-large-small class="size-3" />
@@ -96,7 +97,7 @@ const sectionCls = useSectionUI()
{ value: 'LTR', label: 'LTR' },
{ value: 'RTL', label: 'RTL' }
]"
- @update:model-value="ctx.setDirection($event as 'AUTO' | 'LTR' | 'RTL')"
+ @update:model-value="ctx.actions.setDirection($event as 'AUTO' | 'LTR' | 'RTL')"
/>
</div>
@@ -105,7 +106,7 @@ const sectionCls = useSectionUI()
type="single"
class="flex gap-0.5"
:model-value="ctx.node.value.textAlignHorizontal"
- @update:model-value="ctx.onAlignChange"
+ @update:model-value="ctx.actions.align"
>
<ToggleGroupItem
v-for="align in ['LEFT', 'CENTER', 'RIGHT'] as const"
@@ -124,7 +125,7 @@ const sectionCls = useSectionUI()
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"
:data-state="ctx.activeFormatting.value.includes('bold') ? 'on' : 'off'"
- @click="ctx.toggleBold"
+ @click="ctx.actions.toggleBold"
>
<icon-lucide-bold class="size-3.5" />
</button>
@@ -133,7 +134,7 @@ const sectionCls = useSectionUI()
<button
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"
:data-state="ctx.activeFormatting.value.includes('italic') ? 'on' : 'off'"
- @click="ctx.toggleItalic"
+ @click="ctx.actions.toggleItalic"
>
<icon-lucide-italic class="size-3.5" />
</button>
@@ -142,7 +143,7 @@ const sectionCls = useSectionUI()
<button
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"
:data-state="ctx.activeFormatting.value.includes('underline') ? 'on' : 'off'"
- @click="ctx.toggleDecoration('UNDERLINE')"
+ @click="ctx.actions.toggleDecoration('UNDERLINE')"
>
<icon-lucide-underline class="size-3.5" />
</button>
@@ -151,7 +152,7 @@ const sectionCls = useSectionUI()
<button
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"
:data-state="ctx.activeFormatting.value.includes('strikethrough') ? 'on' : 'off'"
- @click="ctx.toggleDecoration('STRIKETHROUGH')"
+ @click="ctx.actions.toggleDecoration('STRIKETHROUGH')"
>
<icon-lucide-strikethrough class="size-3.5" />
</button>