Skip to content

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

fix(properties): simplify style controls and anchor variable pickers

Danila Poyarkov3d74f5234496
diff --git a/src/components/properties/FillSection.vue b/src/components/properties/FillSection.vue
index b6351cbcc..50171793f 100644
--- a/src/components/properties/FillSection.vue
+++ b/src/components/properties/FillSection.vue
@@ -29,7 +29,7 @@ import { createFillOkhclAdapter } from '@/components/properties/paint/okhcl'
import PaintField from '@/components/properties/paint/PaintField.vue'
import PaintValue from '@/components/properties/paint/PaintValue.vue'
import PropertyListRoot from '@/components/properties/PropertyListRoot.vue'
-import SharedStyleField from '@/components/properties/shared-style/SharedStyleField.vue'
+import { useSharedStylePicker } from '@/components/properties/shared-style/useSharedStylePicker'
import IconButton from '@/components/ui/button/IconButton.vue'
import PanelFieldGroup from '@/components/ui/panel/PanelFieldGroup.vue'
import PanelSection from '@/components/ui/panel/PanelSection.vue'
@@ -40,6 +40,13 @@ const okhcl = useOkHCL()
const colorProvider = useColorBindingProvider()
const { panels, common } = useI18n()
const blendModeOptions = useBlendModeOptions()
+const {
+ visible: stylesVisible,
+ hasStyle,
+ value: styleValue,
+ options: styleOptions,
+ update: updateStyle
+} = useSharedStylePicker('fill')
function displayFill(fill: Fill, resolvedColor: Color | undefined): Fill {
return fill.type === 'SOLID' && resolvedColor ? { ...fill, color: resolvedColor } : fill
@@ -75,12 +82,32 @@ function updateSolidColor(
>
<PanelSection :label="panels.fill" :empty="!isMixed && items.length === 0">
<template #actions>
+ <AppSelect
+ v-if="stylesVisible && !hasStyle"
+ :model-value="styleValue"
+ :options="styleOptions"
+ @update:model-value="updateStyle"
+ >
+ <template #trigger>
+ <IconButton :label="panels.fillStyle" data-property="fill-style"
+ ><icon-lucide-layout-grid class="size-3.5"
+ /></IconButton>
+ </template>
+ </AppSelect>
<IconButton :label="panels.addFill" @click="actions.add({ ...fillCtx.defaultFill })">
<icon-lucide-plus class="size-3.5" />
</IconButton>
</template>
- <SharedStyleField kind="fill" :label="panels.fillStyle" />
+ <AppSelect
+ v-if="stylesVisible && hasStyle"
+ :model-value="styleValue"
+ :options="styleOptions"
+ :label="panels.fillStyle"
+ data-property="fill-style"
+ class="mb-1.5"
+ @update:model-value="updateStyle"
+ />
<p v-if="isMixed" class="text-[11px] text-muted">{{ panels.mixedFillsHelp }}</p>
diff --git a/src/components/properties/binding/VariableBindingPicker.vue b/src/components/properties/binding/VariableBindingPicker.vue
index b6cb8b7d2..3473541f4 100644
--- a/src/components/properties/binding/VariableBindingPicker.vue
+++ b/src/components/properties/binding/VariableBindingPicker.vue
@@ -119,8 +119,8 @@ defineOptions({ inheritAttrs: false })
<ComboboxContent
v-if="picker.open"
position="popper"
- side="left"
- align="center"
+ side="bottom"
+ align="end"
:side-offset="8"
:collision-padding="8"
:class="styles.pickerContent"
diff --git a/src/components/properties/layout/LayoutSection.vue b/src/components/properties/layout/LayoutSection.vue
index 7f37699e3..8ec07bf60 100644
--- a/src/components/properties/layout/LayoutSection.vue
+++ b/src/components/properties/layout/LayoutSection.vue
@@ -38,7 +38,9 @@ const CONTAINER_TYPES = ['FRAME', 'COMPONENT', 'COMPONENT_SET', 'INSTANCE']
</template>
<LayoutFlowControl v-if="CONTAINER_TYPES.includes(ctx.node.type)" />
- <div class="mt-2 mb-1 text-[11px] text-muted">{{ panels.dimensions }}</div>
+ <div v-if="ctx.node.type !== 'TEXT'" class="mt-2 mb-1 text-[11px] text-muted">
+ {{ panels.dimensions }}
+ </div>
<TextResizingControl v-if="ctx.node.type === 'TEXT'" />
<SizeControls />
<ClipContentControl
diff --git a/src/components/properties/shared-style/SharedStyleField.vue b/src/components/properties/shared-style/SharedStyleField.vue
index 2519eb005..ae15314c1 100644
--- a/src/components/properties/shared-style/SharedStyleField.vue
+++ b/src/components/properties/shared-style/SharedStyleField.vue
@@ -1,53 +1,20 @@
<script setup lang="ts">
-import { computed } from 'vue'
-
import type { SharedStyleKind } from '@open-pencil/scene-graph'
-import { MIXED, useI18n, useSharedStyleBinding } from '@open-pencil/vue'
+import { useSharedStylePicker } from '@/components/properties/shared-style/useSharedStylePicker'
import PanelFieldGroup from '@/components/ui/panel/PanelFieldGroup.vue'
import PanelGrid from '@/components/ui/panel/PanelGrid.vue'
import AppSelect from '@/components/ui/select/AppSelect.vue'
-interface SharedStyleFieldProps {
- kind: SharedStyleKind
- label: string
-}
-
-const { kind, label } = defineProps<SharedStyleFieldProps>()
-const { panels } = useI18n()
-const binding = useSharedStyleBinding(kind)
-const { active, styleId, styles } = binding
-const visible = computed(
- () =>
- active.value && (styles.value.length > 0 || styleId.value === MIXED || styleId.value !== null)
-)
-const options = computed(() => {
- const result: Array<{ value: string; label: string }> = [
- { value: 'NONE', label: panels.value.none }
- ]
- if (styleId.value === MIXED) result.unshift({ value: 'MIXED', label: panels.value.mixed })
- for (const style of styles.value) result.push({ value: style.id, label: style.name })
- if (
- typeof styleId.value === 'string' &&
- !styles.value.some((style) => style.id === styleId.value)
- ) {
- result.push({ value: styleId.value, label: panels.value.missingStyle({ id: styleId.value }) })
- }
- return result
-})
-
-function update(value: string) {
- if (value === 'MIXED') return
- if (value === 'NONE') binding.unbind()
- else binding.bind(value)
-}
+const { kind, label } = defineProps<{ kind: SharedStyleKind; label: string }>()
+const { visible, value, options, update } = useSharedStylePicker(kind)
</script>
<template>
<PanelGrid v-if="visible" class="mb-1.5">
<PanelFieldGroup :label="label">
<AppSelect
- :model-value="styleId === MIXED ? 'MIXED' : (styleId ?? 'NONE')"
+ :model-value="value"
:options="options"
:label="label"
:data-property="`${kind}-style`"
diff --git a/src/components/properties/shared-style/useSharedStylePicker.ts b/src/components/properties/shared-style/useSharedStylePicker.ts
new file mode 100644
index 000000000..fbbd7df68
--- /dev/null
+++ b/src/components/properties/shared-style/useSharedStylePicker.ts
@@ -0,0 +1,35 @@
+import { computed } from 'vue'
+
+import type { SharedStyleKind } from '@open-pencil/scene-graph'
+import { MIXED, useI18n, useSharedStyleBinding } from '@open-pencil/vue'
+
+export function useSharedStylePicker(kind: SharedStyleKind) {
+ const { panels } = useI18n()
+ const binding = useSharedStyleBinding(kind)
+ const { active, styleId, styles } = binding
+ const visible = computed(
+ () => active.value && (styles.value.length > 0 || styleId.value !== null)
+ )
+ const hasStyle = computed(() => styleId.value !== null)
+ const value = computed(() => (styleId.value === MIXED ? 'MIXED' : (styleId.value ?? 'NONE')))
+ const options = computed(() => {
+ const result: Array<{ value: string; label: string }> = [
+ { value: 'NONE', label: panels.value.none }
+ ]
+ if (styleId.value === MIXED) result.unshift({ value: 'MIXED', label: panels.value.mixed })
+ for (const style of styles.value) result.push({ value: style.id, label: style.name })
+ if (
+ typeof styleId.value === 'string' &&
+ !styles.value.some((style) => style.id === styleId.value)
+ ) {
+ result.push({ value: styleId.value, label: panels.value.missingStyle({ id: styleId.value }) })
+ }
+ return result
+ })
+ function update(next: string) {
+ if (next === 'MIXED') return
+ if (next === 'NONE') binding.unbind()
+ else binding.bind(next)
+ }
+ return { visible, hasStyle, value, options, update }
+}
diff --git a/src/components/properties/stroke/StrokeSection.vue b/src/components/properties/stroke/StrokeSection.vue
index ff87bd81b..1be9cd1ae 100644
--- a/src/components/properties/stroke/StrokeSection.vue
+++ b/src/components/properties/stroke/StrokeSection.vue
@@ -27,12 +27,19 @@ import { createStrokeOkhclAdapter } from '@/components/properties/paint/okhcl'
import PaintField from '@/components/properties/paint/PaintField.vue'
import PaintValue from '@/components/properties/paint/PaintValue.vue'
import PropertyListRoot from '@/components/properties/PropertyListRoot.vue'
-import SharedStyleField from '@/components/properties/shared-style/SharedStyleField.vue'
+import { useSharedStylePicker } from '@/components/properties/shared-style/useSharedStylePicker'
import IconButton from '@/components/ui/button/IconButton.vue'
import Tip from '@/components/ui/overlay/Tip.vue'
import FillSwatchTrigger from '@/components/ui/paint/FillSwatchTrigger.vue'
import PanelSection from '@/components/ui/panel/PanelSection.vue'
import AppSelect from '@/components/ui/select/AppSelect.vue'
+const {
+ visible: stylesVisible,
+ hasStyle,
+ value: styleValue,
+ options: styleOptions,
+ update: updateStyle
+} = useSharedStylePicker('stroke')
import StrokeSettingsPopover from './StrokeSettingsPopover.vue'
@@ -90,12 +97,32 @@ function onToggleSides(activeNode: SceneNode | null) {
>
<PanelSection :label="panels.stroke" :empty="!isMixed && items.length === 0">
<template #actions>
+ <AppSelect
+ v-if="stylesVisible && !hasStyle"
+ :model-value="styleValue"
+ :options="styleOptions"
+ @update:model-value="updateStyle"
+ >
+ <template #trigger>
+ <IconButton :label="panels.strokeStyle" data-property="stroke-style"
+ ><icon-lucide-layout-grid class="size-3.5"
+ /></IconButton>
+ </template>
+ </AppSelect>
<IconButton :label="panels.addStroke" @click="actions.add(strokeCtx.defaultStroke)">
<icon-lucide-plus class="size-3.5" />
</IconButton>
</template>
- <SharedStyleField kind="stroke" :label="panels.strokeStyle" />
+ <AppSelect
+ v-if="stylesVisible && hasStyle"
+ :model-value="styleValue"
+ :options="styleOptions"
+ :label="panels.strokeStyle"
+ data-property="stroke-style"
+ class="mb-1.5"
+ @update:model-value="updateStyle"
+ />
<p v-if="isMixed" class="text-[11px] text-muted">{{ panels.mixedStrokesHelp }}</p>
diff --git a/src/components/ui/select/AppSelect.vue b/src/components/ui/select/AppSelect.vue
index fd05b12b2..94c6f2919 100644
--- a/src/components/ui/select/AppSelect.vue
+++ b/src/components/ui/select/AppSelect.vue
@@ -34,7 +34,11 @@ const styles = tv(theme)()
<template>
<SelectRoot v-model="modelValue">
+ <SelectTrigger v-if="$slots.trigger" as-child>
+ <slot name="trigger" />
+ </SelectTrigger>
<SelectTrigger
+ v-else
v-bind="$attrs"
:class="styles.trigger({ class: ui?.trigger })"
:aria-label="label"
diff --git a/tests/e2e/properties/panel-hierarchy.spec.ts b/tests/e2e/properties/panel-hierarchy.spec.ts
new file mode 100644
index 000000000..94d073d47
--- /dev/null
+++ b/tests/e2e/properties/panel-hierarchy.spec.ts
@@ -0,0 +1,43 @@
+import { expect, test } from '@playwright/test'
+
+import { CanvasHelper } from '#tests/helpers/canvas'
+
+for (const type of ['TEXT', 'RECTANGLE', 'FRAME'] as const) {
+ test(`${type} layout uses one appropriate sizing heading`, async ({ page }) => {
+ await page.goto('/?test')
+ await new CanvasHelper(page).waitForInit()
+ await page.evaluate((type) => {
+ const editor = window.openPencil?.getStore?.()
+ if (!editor) throw new Error('Editor unavailable')
+ const id = editor.createShape(type, 100, 100, 240, 80)
+ if (type === 'TEXT') editor.updateNode(id, { text: 'Sizing', fontSize: 24 })
+ editor.select([id])
+ }, type)
+ const layout = page.getByRole('region', { name: 'Layout', exact: true })
+ await expect(layout.getByText('Dimensions', { exact: true })).toHaveCount(
+ type === 'TEXT' ? 0 : 1
+ )
+ await expect(layout.getByText('Resizing', { exact: true })).toHaveCount(type === 'TEXT' ? 1 : 0)
+ await expect(layout).toHaveScreenshot(`layout-${type.toLowerCase()}.png`)
+ })
+}
+
+test('missing paint styles stay visible and detachable', async ({ page }) => {
+ await page.goto('/?test')
+ await new CanvasHelper(page).waitForInit()
+ await page.evaluate(() => {
+ const editor = window.openPencil?.getStore?.()
+ if (!editor) throw new Error('Editor unavailable')
+ const id = editor.createShape('RECTANGLE', 100, 100, 240, 80)
+ editor.updateNode(id, { fillStyleId: 'missing:style' })
+ editor.select([id])
+ })
+ const fill = page.getByRole('region', { name: 'Fill', exact: true })
+ const style = fill.getByRole('combobox', { name: 'Fill style' })
+ await expect(style).toHaveCount(1)
+ await expect(style).toContainText('missing:style')
+ await expect(fill).toHaveScreenshot('fill-missing-style.png')
+ await style.click()
+ await page.getByRole('option', { name: 'None', exact: true }).click()
+ await expect(style).toHaveCount(0)
+})
diff --git a/tests/e2e/properties/panel-hierarchy.spec.ts-snapshots/fill-missing-style-openpencil-darwin.png b/tests/e2e/properties/panel-hierarchy.spec.ts-snapshots/fill-missing-style-openpencil-darwin.png
new file mode 100644
index 000000000..7a5785170
Binary files /dev/null and b/tests/e2e/properties/panel-hierarchy.spec.ts-snapshots/fill-missing-style-openpencil-darwin.png differ
diff --git a/tests/e2e/properties/panel-hierarchy.spec.ts-snapshots/layout-frame-openpencil-darwin.png b/tests/e2e/properties/panel-hierarchy.spec.ts-snapshots/layout-frame-openpencil-darwin.png
new file mode 100644
index 000000000..5a68ff83c
Binary files /dev/null and b/tests/e2e/properties/panel-hierarchy.spec.ts-snapshots/layout-frame-openpencil-darwin.png differ
diff --git a/tests/e2e/properties/panel-hierarchy.spec.ts-snapshots/layout-rectangle-openpencil-darwin.png b/tests/e2e/properties/panel-hierarchy.spec.ts-snapshots/layout-rectangle-openpencil-darwin.png
new file mode 100644
index 000000000..00f9f687f
Binary files /dev/null and b/tests/e2e/properties/panel-hierarchy.spec.ts-snapshots/layout-rectangle-openpencil-darwin.png differ
diff --git a/tests/e2e/properties/panel-hierarchy.spec.ts-snapshots/layout-text-openpencil-darwin.png b/tests/e2e/properties/panel-hierarchy.spec.ts-snapshots/layout-text-openpencil-darwin.png
new file mode 100644
index 000000000..07ad99503
Binary files /dev/null and b/tests/e2e/properties/panel-hierarchy.spec.ts-snapshots/layout-text-openpencil-darwin.png differ
diff --git a/tests/e2e/properties/panel.spec.ts b/tests/e2e/properties/panel.spec.ts
index 67927de59..5aed07218 100644
--- a/tests/e2e/properties/panel.spec.ts
+++ b/tests/e2e/properties/panel.spec.ts
@@ -42,17 +42,41 @@ test('appearance fields share control height and show variable actions', async (
await expect(applyVariable).toHaveCSS('background-color', 'rgba(0, 0, 0, 0)')
await applyVariable.click()
- const search = editor.page.getByPlaceholder('Search')
+ const search = editor.page.locator('input[data-slot="search"]')
const picker = editor.page.locator('[data-slot=content]').filter({ has: search })
await expect(picker).toBeVisible()
const triggerBox = expectDefined(await applyVariable.boundingBox(), 'variable trigger bounds')
const pickerBox = expectDefined(await picker.boundingBox(), 'variable picker bounds')
- expect(pickerBox.x + pickerBox.width).toBeLessThan(triggerBox.x)
- expect(
- Math.abs(pickerBox.y + pickerBox.height / 2 - (triggerBox.y + triggerBox.height / 2))
- ).toBeLessThan(4)
+ await expect(picker).toHaveAttribute('data-side', 'bottom')
+ expect(pickerBox.y).toBeGreaterThanOrEqual(triggerBox.y + triggerBox.height)
+ expect(Math.abs(pickerBox.x + pickerBox.width - (triggerBox.x + triggerBox.width))).toBeLessThan(
+ 4
+ )
await search.press('Escape')
+ // Move the anchor near the bottom without changing its actual panel layout.
+ const viewport = editor.page.viewportSize()
+ if (!viewport) throw new Error('Viewport unavailable')
+ await editor.page.setViewportSize({
+ width: viewport.width,
+ height: Math.ceil(triggerBox.y + triggerBox.height + 24)
+ })
+ try {
+ await applyVariable.click()
+ await expect(picker).toHaveAttribute('data-side', 'top')
+ const flipped = expectDefined(await picker.boundingBox(), 'flipped picker bounds')
+ const anchor = expectDefined(await applyVariable.boundingBox(), 'edge trigger bounds')
+ expect(flipped.y).toBeGreaterThanOrEqual(8)
+ expect(flipped.y + flipped.height).toBeLessThanOrEqual(anchor.y)
+ await search.press('Escape')
+ } finally {
+ await editor.page.setViewportSize(viewport)
+ }
+})
+
+test('paint fields retain editable color and opacity widths', async () => {
+ await editor.canvas.clearCanvas()
+ await editor.canvas.drawRect(200, 200, 80, 80)
const fillItem = propertyItems(editor.page, 'fills').first()
const paintField = fillItem.locator('[data-slot="paint-field"]')
await expect(paintField).toHaveCSS('height', '24px')
diff --git a/tests/e2e/properties/shared-styles.spec.ts b/tests/e2e/properties/shared-styles.spec.ts
index 77770da62..ea141fdd5 100644
--- a/tests/e2e/properties/shared-styles.spec.ts
+++ b/tests/e2e/properties/shared-styles.spec.ts
@@ -110,11 +110,26 @@ async function targetStyles(id = targetId) {
}, id)
}
+test('unbound paint styles use one header action without redundant field labels', async () => {
+ for (const [section, label] of [
+ ['Fill', 'Fill style'],
+ ['Stroke', 'Stroke style']
+ ]) {
+ const panel = propertySection(page, section)
+ await expect(panel.getByRole('combobox', { name: label })).toHaveCount(1)
+ await expect(panel.getByText(label, { exact: true })).toHaveCount(0)
+ await expect(panel.getByText('None', { exact: true })).toHaveCount(0)
+ await expect(panel).toHaveScreenshot(`${section.toLowerCase()}-unbound-style.png`)
+ }
+})
+
test('applies fill, stroke, effect, and grid styles from local definitions', async () => {
await chooseStyle('Fill', 'Fill style', 'Brand/Primary')
await chooseStyle('Stroke', 'Stroke style', 'Brand/Primary')
await chooseStyle('Effects', 'Effect style', 'Effects/Card')
await chooseStyle('Layout guide', 'Grid style', 'Grid/12 columns')
+ await expect(propertySection(page, 'Fill')).toHaveScreenshot('fill-applied-style.png')
+ await expect(propertySection(page, 'Stroke')).toHaveScreenshot('stroke-applied-style.png')
expect(await targetStyles()).toMatchObject({
fillStyleId: '1:100',
diff --git a/tests/e2e/properties/shared-styles.spec.ts-snapshots/fill-applied-style-openpencil-darwin.png b/tests/e2e/properties/shared-styles.spec.ts-snapshots/fill-applied-style-openpencil-darwin.png
new file mode 100644
index 000000000..f29d1431c
Binary files /dev/null and b/tests/e2e/properties/shared-styles.spec.ts-snapshots/fill-applied-style-openpencil-darwin.png differ
diff --git a/tests/e2e/properties/shared-styles.spec.ts-snapshots/fill-unbound-style-openpencil-darwin.png b/tests/e2e/properties/shared-styles.spec.ts-snapshots/fill-unbound-style-openpencil-darwin.png
new file mode 100644
index 000000000..6d92626ae
Binary files /dev/null and b/tests/e2e/properties/shared-styles.spec.ts-snapshots/fill-unbound-style-openpencil-darwin.png differ
diff --git a/tests/e2e/properties/shared-styles.spec.ts-snapshots/stroke-applied-style-openpencil-darwin.png b/tests/e2e/properties/shared-styles.spec.ts-snapshots/stroke-applied-style-openpencil-darwin.png
new file mode 100644
index 000000000..d491ac023
Binary files /dev/null and b/tests/e2e/properties/shared-styles.spec.ts-snapshots/stroke-applied-style-openpencil-darwin.png differ
diff --git a/tests/e2e/properties/shared-styles.spec.ts-snapshots/stroke-unbound-style-openpencil-darwin.png b/tests/e2e/properties/shared-styles.spec.ts-snapshots/stroke-unbound-style-openpencil-darwin.png
new file mode 100644
index 000000000..06d8b2490
Binary files /dev/null and b/tests/e2e/properties/shared-styles.spec.ts-snapshots/stroke-unbound-style-openpencil-darwin.png differ