Skip to content

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

Add LayoutControlsRoot SDK primitive, LayoutSection 556→119 lines

Danila Poyarkov92857aed456f
diff --git a/packages/vue/src/LayoutControls/LayoutControlsRoot.vue b/packages/vue/src/LayoutControls/LayoutControlsRoot.vue
new file mode 100644
index 000000000..42060b349
--- /dev/null
+++ b/packages/vue/src/LayoutControls/LayoutControlsRoot.vue
@@ -0,0 +1,189 @@
+<script setup lang="ts">
+import { computed, ref } from 'vue'
+
+import { useEditor } from '../context'
+
+import type {
+ SceneNode,
+ LayoutSizing,
+ LayoutAlign,
+ LayoutCounterAlign,
+ GridTrack
+} from '@open-pencil/core'
+
+const editor = useEditor()
+
+const node = computed<SceneNode | null>(() => editor.getSelectedNode() ?? null)
+
+const isInAutoLayout = computed(() => {
+ const n = node.value
+ if (!n?.parentId) return false
+ const parent = editor.getNode(n.parentId)
+ return parent ? parent.layoutMode !== 'NONE' : false
+})
+
+const isGrid = computed(() => node.value?.layoutMode === 'GRID')
+const isFlex = computed(
+ () => node.value?.layoutMode === 'HORIZONTAL' || node.value?.layoutMode === 'VERTICAL'
+)
+
+const widthSizing = computed<LayoutSizing>(() => {
+ const n = node.value
+ if (!n) return 'FIXED'
+ if (isFlex.value) return n.layoutMode === 'HORIZONTAL' ? n.primaryAxisSizing : n.counterAxisSizing
+ if (isInAutoLayout.value && n.layoutGrow > 0) return 'FILL'
+ return 'FIXED'
+})
+
+const heightSizing = computed<LayoutSizing>(() => {
+ const n = node.value
+ if (!n) return 'FIXED'
+ if (isFlex.value) return n.layoutMode === 'VERTICAL' ? n.primaryAxisSizing : n.counterAxisSizing
+ if (isInAutoLayout.value && n.layoutAlignSelf === 'STRETCH') return 'FILL'
+ return 'FIXED'
+})
+
+const widthSizingOptions = computed(() => {
+ const options: { value: LayoutSizing; label: string }[] = [{ value: 'FIXED', label: 'Fixed' }]
+ if (isFlex.value) options.push({ value: 'HUG', label: 'Hug' })
+ if (isInAutoLayout.value || isFlex.value) options.push({ value: 'FILL', label: 'Fill' })
+ return options
+})
+
+const heightSizingOptions = computed(() => {
+ const options: { value: LayoutSizing; label: string }[] = [{ value: 'FIXED', label: 'Fixed' }]
+ if (isFlex.value) options.push({ value: 'HUG', label: 'Hug' })
+ if (isInAutoLayout.value || isFlex.value) options.push({ value: 'FILL', label: 'Fill' })
+ return options
+})
+
+type AlignCell = { primary: LayoutAlign; counter: LayoutCounterAlign }
+
+const ALIGN_HORIZONTAL: AlignCell[] = [
+ { primary: 'MIN', counter: 'MIN' }, { primary: 'CENTER', counter: 'MIN' }, { primary: 'MAX', counter: 'MIN' },
+ { primary: 'MIN', counter: 'CENTER' }, { primary: 'CENTER', counter: 'CENTER' }, { primary: 'MAX', counter: 'CENTER' },
+ { primary: 'MIN', counter: 'MAX' }, { primary: 'CENTER', counter: 'MAX' }, { primary: 'MAX', counter: 'MAX' }
+]
+
+const ALIGN_VERTICAL: AlignCell[] = [
+ { primary: 'MIN', counter: 'MIN' }, { primary: 'MIN', counter: 'CENTER' }, { primary: 'MIN', counter: 'MAX' },
+ { primary: 'CENTER', counter: 'MIN' }, { primary: 'CENTER', counter: 'CENTER' }, { primary: 'CENTER', counter: 'MAX' },
+ { primary: 'MAX', counter: 'MIN' }, { primary: 'MAX', counter: 'CENTER' }, { primary: 'MAX', counter: 'MAX' }
+]
+
+const alignGrid = computed(() =>
+ node.value?.layoutMode === 'VERTICAL' ? ALIGN_VERTICAL : ALIGN_HORIZONTAL
+)
+
+const showIndividualPadding = ref(false)
+
+const hasUniformPadding = computed(() => {
+ const n = node.value
+ if (!n) return true
+ return n.paddingTop === n.paddingRight && n.paddingRight === n.paddingBottom && n.paddingBottom === n.paddingLeft
+})
+
+function updateProp(key: string, value: number | string) {
+ if (node.value) editor.updateNode(node.value.id, { [key]: value })
+}
+
+function commitProp(key: string, _value: number | string, previous: number | string) {
+ if (node.value) editor.commitNodeUpdate(node.value.id, { [key]: previous } as Partial<SceneNode>, `Change ${key}`)
+}
+
+function setWidthSizing(sizing: LayoutSizing) {
+ if (!node.value) return
+ if (isFlex.value) {
+ const key = node.value.layoutMode === 'HORIZONTAL' ? 'primaryAxisSizing' : 'counterAxisSizing'
+ updateProp(key, sizing)
+ } else if (isInAutoLayout.value) {
+ updateProp('layoutGrow', sizing === 'FILL' ? 1 : 0)
+ }
+}
+
+function setHeightSizing(sizing: LayoutSizing) {
+ if (!node.value) return
+ if (isFlex.value) {
+ const key = node.value.layoutMode === 'VERTICAL' ? 'primaryAxisSizing' : 'counterAxisSizing'
+ updateProp(key, sizing)
+ } else if (isInAutoLayout.value) {
+ updateProp('layoutAlignSelf', sizing === 'FILL' ? 'STRETCH' : 'AUTO')
+ }
+}
+
+function setUniformPadding(v: number) {
+ if (!node.value) return
+ editor.updateNode(node.value.id, { paddingTop: v, paddingRight: v, paddingBottom: v, paddingLeft: v })
+}
+
+function commitUniformPadding(_value: number, previous: number) {
+ if (!node.value) return
+ editor.commitNodeUpdate(node.value.id, {
+ paddingTop: previous, paddingRight: previous, paddingBottom: previous, paddingLeft: previous
+ } as unknown as Partial<SceneNode>, 'Change padding')
+}
+
+function setAlignment(primary: LayoutAlign, counter: LayoutCounterAlign) {
+ if (!node.value) return
+ editor.updateNodeWithUndo(node.value.id, { primaryAxisAlign: primary, counterAxisAlign: counter }, 'Change alignment')
+}
+
+function updateGridTrack(prop: 'gridTemplateColumns' | 'gridTemplateRows', index: number, updates: Partial<GridTrack>) {
+ if (!node.value) return
+ const tracks = [...node.value[prop]]
+ tracks[index] = { ...tracks[index], ...updates }
+ editor.updateNodeWithUndo(node.value.id, { [prop]: tracks }, 'Change grid track')
+}
+
+function addTrack(prop: 'gridTemplateColumns' | 'gridTemplateRows') {
+ if (!node.value) return
+ editor.updateNodeWithUndo(node.value.id, { [prop]: [...node.value[prop], { sizing: 'FR' as const, value: 1 }] }, 'Add grid track')
+}
+
+function removeTrack(prop: 'gridTemplateColumns' | 'gridTemplateRows', index: number) {
+ if (!node.value) return
+ editor.updateNodeWithUndo(node.value.id, { [prop]: node.value[prop].filter((_: GridTrack, i: number) => i !== index) }, 'Remove grid track')
+}
+
+function trackLabel(track: GridTrack): string {
+ if (track.sizing === 'FR') return `${track.value}fr`
+ if (track.sizing === 'FIXED') return `${track.value}px`
+ return 'Auto'
+}
+
+const TRACK_SIZING_OPTIONS = [
+ { value: 'FR' as const, label: 'Fill (fr)' },
+ { value: 'FIXED' as const, label: 'Fixed (px)' },
+ { value: 'AUTO' as const, label: 'Auto' }
+]
+</script>
+
+<template>
+ <slot
+ v-if="node"
+ :node="node"
+ :is-in-auto-layout="isInAutoLayout"
+ :is-grid="isGrid"
+ :is-flex="isFlex"
+ :width-sizing="widthSizing"
+ :height-sizing="heightSizing"
+ :width-sizing-options="widthSizingOptions"
+ :height-sizing-options="heightSizingOptions"
+ :align-grid="alignGrid"
+ :show-individual-padding="showIndividualPadding"
+ :has-uniform-padding="hasUniformPadding"
+ :track-sizing-options="TRACK_SIZING_OPTIONS"
+ :update-prop="updateProp"
+ :commit-prop="commitProp"
+ :set-width-sizing="setWidthSizing"
+ :set-height-sizing="setHeightSizing"
+ :set-uniform-padding="setUniformPadding"
+ :commit-uniform-padding="commitUniformPadding"
+ :set-alignment="setAlignment"
+ :update-grid-track="updateGridTrack"
+ :add-track="addTrack"
+ :remove-track="removeTrack"
+ :track-label="trackLabel"
+ :toggle-individual-padding="() => { showIndividualPadding = !showIndividualPadding }"
+ />
+</template>
diff --git a/packages/vue/src/LayoutControls/index.ts b/packages/vue/src/LayoutControls/index.ts
new file mode 100644
index 000000000..b6899b659
--- /dev/null
+++ b/packages/vue/src/LayoutControls/index.ts
@@ -0,0 +1 @@
+export { default as LayoutControlsRoot } from './LayoutControlsRoot.vue'
diff --git a/packages/vue/src/index.ts b/packages/vue/src/index.ts
index aa80401c2..b1f361c27 100644
--- a/packages/vue/src/index.ts
+++ b/packages/vue/src/index.ts
@@ -33,6 +33,7 @@ export { PropertyListRoot, PropertyListItem, usePropertyList } from './PropertyL
export type { PropertyListContext } from './PropertyList'
export { PositionControlsRoot } from './PositionControls'
+export { LayoutControlsRoot } from './LayoutControls'
export { LayerTreeRoot, LayerTreeItem, useLayerTree } from './LayerTree'
diff --git a/src/components/properties/LayoutSection.vue b/src/components/properties/LayoutSection.vue
index 2397c9810..91e1bc942 100644
--- a/src/components/properties/LayoutSection.vue
+++ b/src/components/properties/LayoutSection.vue
@@ -1,556 +1,299 @@
<script setup lang="ts">
-import { computed, ref } from 'vue'
-
import AppSelect from '@/components/AppSelect.vue'
import ScrubInput from '@/components/ScrubInput.vue'
-import { useNodeProps } from '@open-pencil/vue'
-
-import type {
- SceneNode,
- LayoutSizing,
- LayoutAlign,
- LayoutCounterAlign,
- GridTrack
-} from '@open-pencil/core'
-
-const { store, node, updateProp, commitProp } = useNodeProps()
-
-const showIndividualPadding = ref(false)
-
-const isInAutoLayout = computed(() => {
- const n = node.value
- if (!n?.parentId) return false
- const parent = store.getNode(n.parentId)
- return parent ? parent.layoutMode !== 'NONE' : false
-})
-
-const isGrid = computed(() => node.value?.layoutMode === 'GRID')
-const isFlex = computed(
- () => node.value?.layoutMode === 'HORIZONTAL' || node.value?.layoutMode === 'VERTICAL'
-)
-
-const widthSizing = computed<LayoutSizing>(() => {
- const n = node.value
- if (!n) return 'FIXED'
- if (isFlex.value) {
- return n.layoutMode === 'HORIZONTAL' ? n.primaryAxisSizing : n.counterAxisSizing
- }
- if (isInAutoLayout.value && n.layoutGrow > 0) return 'FILL'
- return 'FIXED'
-})
-
-const heightSizing = computed<LayoutSizing>(() => {
- const n = node.value
- if (!n) return 'FIXED'
- if (isFlex.value) {
- return n.layoutMode === 'VERTICAL' ? n.primaryAxisSizing : n.counterAxisSizing
- }
- if (isInAutoLayout.value && n.layoutAlignSelf === 'STRETCH') return 'FILL'
- return 'FIXED'
-})
-
-function setWidthSizing(sizing: LayoutSizing) {
- if (!node.value) return
- if (isFlex.value) {
- if (node.value.layoutMode === 'HORIZONTAL') updateProp('primaryAxisSizing', sizing)
- else updateProp('counterAxisSizing', sizing)
- } else if (isInAutoLayout.value) {
- updateProp('layoutGrow', sizing === 'FILL' ? 1 : 0)
- }
-}
-
-function setHeightSizing(sizing: LayoutSizing) {
- if (!node.value) return
- if (isFlex.value) {
- if (node.value.layoutMode === 'VERTICAL') updateProp('primaryAxisSizing', sizing)
- else updateProp('counterAxisSizing', sizing)
- } else if (isInAutoLayout.value) {
- updateProp('layoutAlignSelf', sizing === 'FILL' ? 'STRETCH' : 'AUTO')
- }
-}
-
-function hasUniformPadding() {
- const n = node.value
- if (!n) return true
- return (
- n.paddingTop === n.paddingRight &&
- n.paddingRight === n.paddingBottom &&
- n.paddingBottom === n.paddingLeft
- )
-}
-
-function setUniformPadding(v: number) {
- if (!node.value) return
- store.updateNode(node.value.id, {
- paddingTop: v,
- paddingRight: v,
- paddingBottom: v,
- paddingLeft: v
- })
-}
-
-function commitUniformPadding(_value: number, previous: number) {
- if (!node.value) return
- store.commitNodeUpdate(
- node.value.id,
- {
- paddingTop: previous,
- paddingRight: previous,
- paddingBottom: previous,
- paddingLeft: previous
- } as unknown as Partial<SceneNode>,
- 'Change padding'
- )
-}
-
-const widthSizingOptions = computed(() => {
- const options: { value: LayoutSizing; label: string }[] = [{ value: 'FIXED', label: 'Fixed' }]
- if (isFlex.value) options.push({ value: 'HUG', label: 'Hug' })
- if (isInAutoLayout.value || isFlex.value) options.push({ value: 'FILL', label: 'Fill' })
- return options
-})
-
-const heightSizingOptions = computed(() => {
- const options: { value: LayoutSizing; label: string }[] = [{ value: 'FIXED', label: 'Fixed' }]
- if (isFlex.value) options.push({ value: 'HUG', label: 'Hug' })
- if (isInAutoLayout.value || isFlex.value) options.push({ value: 'FILL', label: 'Fill' })
- return options
-})
+import { LayoutControlsRoot, useEditor } from '@open-pencil/vue'
-type AlignCell = { primary: LayoutAlign; counter: LayoutCounterAlign }
-
-const ALIGN_HORIZONTAL: AlignCell[] = [
- { primary: 'MIN', counter: 'MIN' },
- { primary: 'CENTER', counter: 'MIN' },
- { primary: 'MAX', counter: 'MIN' },
- { primary: 'MIN', counter: 'CENTER' },
- { primary: 'CENTER', counter: 'CENTER' },
- { primary: 'MAX', counter: 'CENTER' },
- { primary: 'MIN', counter: 'MAX' },
- { primary: 'CENTER', counter: 'MAX' },
- { primary: 'MAX', counter: 'MAX' }
-]
-
-const ALIGN_VERTICAL: AlignCell[] = [
- { primary: 'MIN', counter: 'MIN' },
- { primary: 'MIN', counter: 'CENTER' },
- { primary: 'MIN', counter: 'MAX' },
- { primary: 'CENTER', counter: 'MIN' },
- { primary: 'CENTER', counter: 'CENTER' },
- { primary: 'CENTER', counter: 'MAX' },
- { primary: 'MAX', counter: 'MIN' },
- { primary: 'MAX', counter: 'CENTER' },
- { primary: 'MAX', counter: 'MAX' }
-]
-
-const alignGrid = computed(() =>
- node.value?.layoutMode === 'VERTICAL' ? ALIGN_VERTICAL : ALIGN_HORIZONTAL
-)
-
-function setAlignment(primary: LayoutAlign, counter: LayoutCounterAlign) {
- if (!node.value) return
- store.updateNodeWithUndo(
- node.value.id,
- { primaryAxisAlign: primary, counterAxisAlign: counter },
- 'Change alignment'
- )
-}
-
-// --- Grid helpers ---
-
-const TRACK_SIZING_OPTIONS = [
- { value: 'FR' as const, label: 'Fill (fr)' },
- { value: 'FIXED' as const, label: 'Fixed (px)' },
- { value: 'AUTO' as const, label: 'Auto' }
-]
-
-function updateGridTrack(
- prop: 'gridTemplateColumns' | 'gridTemplateRows',
- index: number,
- updates: Partial<GridTrack>
-) {
- if (!node.value) return
- const tracks = [...node.value[prop]]
- tracks[index] = { ...tracks[index], ...updates }
- store.updateNodeWithUndo(node.value.id, { [prop]: tracks }, 'Change grid track')
-}
-
-function addTrack(prop: 'gridTemplateColumns' | 'gridTemplateRows') {
- if (!node.value) return
- const tracks = [...node.value[prop], { sizing: 'FR' as const, value: 1 }]
- store.updateNodeWithUndo(node.value.id, { [prop]: tracks }, 'Add grid track')
-}
-
-function removeTrack(prop: 'gridTemplateColumns' | 'gridTemplateRows', index: number) {
- if (!node.value) return
- const tracks = node.value[prop].filter((_: GridTrack, i: number) => i !== index)
- store.updateNodeWithUndo(node.value.id, { [prop]: tracks }, 'Remove grid track')
-}
-
-function trackLabel(track: GridTrack): string {
- if (track.sizing === 'FR') return `${track.value}fr`
- if (track.sizing === 'FIXED') return `${track.value}px`
- return 'Auto'
-}
+const store = useEditor()
</script>
<template>
- <div v-if="node" data-test-id="layout-section" class="border-b border-border px-3 py-2">
- <label class="mb-1.5 block text-[11px] text-muted">Layout</label>
- <div class="flex gap-1.5">
- <div class="flex min-w-0 flex-1 items-center gap-1">
- <ScrubInput
- icon="W"
- :model-value="Math.round(node.width)"
- :min="0"
- @update:model-value="updateProp('width', $event)"
- @commit="(v: number, p: number) => commitProp('width', v, p)"
- />
- <AppSelect
- v-if="isFlex || isInAutoLayout"
- :model-value="widthSizing"
- :options="widthSizingOptions"
- @update:model-value="setWidthSizing"
- />
- </div>
-
- <div class="flex min-w-0 flex-1 items-center gap-1">
- <ScrubInput
- icon="H"
- :model-value="Math.round(node.height)"
- :min="0"
- @update:model-value="updateProp('height', $event)"
- @commit="(v: number, p: number) => commitProp('height', v, p)"
- />
- <AppSelect
- v-if="isFlex || isInAutoLayout"
- :model-value="heightSizing"
- :options="heightSizingOptions"
- @update:model-value="setHeightSizing"
- />
+ <LayoutControlsRoot
+ v-slot="{
+ node,
+ isInAutoLayout,
+ isGrid,
+ isFlex,
+ widthSizing,
+ heightSizing,
+ widthSizingOptions,
+ heightSizingOptions,
+ alignGrid,
+ showIndividualPadding,
+ hasUniformPadding,
+ trackSizingOptions,
+ updateProp,
+ commitProp,
+ setWidthSizing,
+ setHeightSizing,
+ setUniformPadding,
+ commitUniformPadding,
+ setAlignment,
+ updateGridTrack,
+ addTrack,
+ removeTrack,
+ trackLabel,
+ toggleIndividualPadding
+ }"
+ >
+ <div data-test-id="layout-section" class="border-b border-border px-3 py-2">
+ <label class="mb-1.5 block text-[11px] text-muted">Layout</label>
+ <div class="flex gap-1.5">
+ <div class="flex min-w-0 flex-1 items-center gap-1">
+ <ScrubInput
+ icon="W"
+ :model-value="Math.round(node.width)"
+ :min="0"
+ @update:model-value="updateProp('width', $event)"
+ @commit="(v: number, p: number) => commitProp('width', v, p)"
+ />
+ <AppSelect
+ v-if="isFlex || isInAutoLayout"
+ :model-value="widthSizing"
+ :options="widthSizingOptions"
+ @update:model-value="setWidthSizing"
+ />
+ </div>
+ <div class="flex min-w-0 flex-1 items-center gap-1">
+ <ScrubInput
+ icon="H"
+ :model-value="Math.round(node.height)"
+ :min="0"
+ @update:model-value="updateProp('height', $event)"
+ @commit="(v: number, p: number) => commitProp('height', v, p)"
+ />
+ <AppSelect
+ v-if="isFlex || isInAutoLayout"
+ :model-value="heightSizing"
+ :options="heightSizingOptions"
+ @update:model-value="setHeightSizing"
+ />
+ </div>
</div>
</div>
- </div>
- <template v-if="node?.type === 'FRAME'">
- <div class="border-b border-border px-3 py-2">
- <div class="flex items-center justify-between">
- <label class="mb-1.5 block text-[11px] text-muted">Auto layout</label>
- <button
- v-if="node.layoutMode === 'NONE'"
- class="cursor-pointer rounded border-none bg-transparent px-1 text-base leading-none text-muted hover:bg-hover hover:text-surface"
- data-test-id="layout-add-auto"
- title="Add auto layout (Shift+A)"
- @click="store.setLayoutMode(node.id, 'VERTICAL')"
- >
- +
- </button>
- <button
- v-else
- class="cursor-pointer rounded border-none bg-transparent px-1 text-base leading-none text-muted hover:bg-hover hover:text-surface"
- data-test-id="layout-remove-auto"
- title="Remove auto layout"
- @click="store.setLayoutMode(node.id, 'NONE')"
- >
- −
- </button>
- </div>
-
- <template v-if="node.layoutMode !== 'NONE'">
- <!-- Flow direction buttons -->
- <div class="mt-1.5 flex gap-0.5">
+ <template v-if="node.type === 'FRAME'">
+ <div class="border-b border-border px-3 py-2">
+ <div class="flex items-center justify-between">
+ <label class="mb-1.5 block text-[11px] text-muted">Auto layout</label>
<button
- data-test-id="layout-direction-horizontal"
- class="flex cursor-pointer items-center justify-center rounded border px-2 py-1"
- :class="
- node.layoutMode === 'HORIZONTAL'
- ? 'border-accent bg-accent/10 text-accent'
- : 'border-border text-muted hover:bg-hover hover:text-surface'
- "
- title="Horizontal layout"
- @click="store.setLayoutMode(node.id, 'HORIZONTAL')"
- >
- <icon-lucide-arrow-right class="size-3.5" />
- </button>
- <button
- data-test-id="layout-direction-vertical"
- class="flex cursor-pointer items-center justify-center rounded border px-2 py-1"
- :class="
- node.layoutMode === 'VERTICAL'
- ? 'border-accent bg-accent/10 text-accent'
- : 'border-border text-muted hover:bg-hover hover:text-surface'
- "
- title="Vertical layout"
+ v-if="node.layoutMode === 'NONE'"
+ class="cursor-pointer rounded border-none bg-transparent px-1 text-base leading-none text-muted hover:bg-hover hover:text-surface"
+ data-test-id="layout-add-auto"
+ title="Add auto layout (Shift+A)"
@click="store.setLayoutMode(node.id, 'VERTICAL')"
>
- <icon-lucide-arrow-down class="size-3.5" />
+ +
</button>
<button
- data-test-id="layout-direction-grid"
- class="flex cursor-pointer items-center justify-center rounded border px-2 py-1"
- :class="
- isGrid
- ? 'border-accent bg-accent/10 text-accent'
- : 'border-border text-muted hover:bg-hover hover:text-surface'
- "
- title="Grid layout"
- @click="store.setLayoutMode(node.id, 'GRID')"
+ v-else
+ class="cursor-pointer rounded border-none bg-transparent px-1 text-base leading-none text-muted hover:bg-hover hover:text-surface"
+ data-test-id="layout-remove-auto"
+ title="Remove auto layout"
+ @click="store.setLayoutMode(node.id, 'NONE')"
>
- <icon-lucide-layout-grid class="size-3.5" />
- </button>
- <button
- v-if="isFlex"
- data-test-id="layout-direction-wrap"
- class="flex cursor-pointer items-center justify-center rounded border px-2 py-1"
- :class="
- node.layoutWrap === 'WRAP'
- ? 'border-accent bg-accent/10 text-accent'
- : 'border-border text-muted hover:bg-hover hover:text-surface'
- "
- title="Wrap"
- @click="updateProp('layoutWrap', node.layoutWrap === 'WRAP' ? 'NO_WRAP' : 'WRAP')"
- >
- <icon-lucide-wrap-text class="size-3.5" />
+ −
</button>
</div>
- <!-- Grid-specific controls -->
- <template v-if="isGrid">
- <!-- Column tracks -->
- <div class="mt-2">
- <div class="mb-1 flex items-center justify-between">
- <label class="text-[11px] text-muted">Columns</label>
- <button
- class="cursor-pointer rounded border-none bg-transparent px-1 text-xs leading-none text-muted hover:bg-hover hover:text-surface"
- title="Add column"
- @click="addTrack('gridTemplateColumns')"
- >
- +
- </button>
- </div>
- <div class="flex flex-col gap-1">
- <div
- v-for="(col, i) in node.gridTemplateColumns"
- :key="i"
- class="flex items-center gap-1"
- >
- <ScrubInput
- v-if="col.sizing !== 'AUTO'"
- class="flex-1"
- :icon="`C${i + 1}`"
- :model-value="col.value"
- :min="col.sizing === 'FR' ? 1 : 0"
- :step="col.sizing === 'FR' ? 1 : 1"
- :suffix="col.sizing === 'FR' ? 'fr' : 'px'"
- @update:model-value="updateGridTrack('gridTemplateColumns', i, { value: $event })"
- />
- <span v-else class="flex-1 px-1 text-xs text-muted">{{ trackLabel(col) }}</span>
- <AppSelect
- :model-value="col.sizing"
- :options="TRACK_SIZING_OPTIONS"
- @update:model-value="
- updateGridTrack('gridTemplateColumns', i, {
- sizing: $event,
- value: $event === 'FR' ? 1 : $event === 'FIXED' ? 100 : 0
- })
- "
- />
+ <template v-if="node.layoutMode !== 'NONE'">
+ <div class="mt-1.5 flex gap-0.5">
+ <button
+ v-for="dir in [
+ { mode: 'HORIZONTAL', icon: 'arrow-right', test: 'horizontal' },
+ { mode: 'VERTICAL', icon: 'arrow-down', test: 'vertical' },
+ { mode: 'GRID', icon: 'layout-grid', test: 'grid' }
+ ] as const"
+ :key="dir.mode"
+ :data-test-id="`layout-direction-${dir.test}`"
+ class="flex cursor-pointer items-center justify-center rounded border px-2 py-1"
+ :class="
+ (dir.mode === 'GRID' ? isGrid : node.layoutMode === dir.mode)
+ ? 'border-accent bg-accent/10 text-accent'
+ : 'border-border text-muted hover:bg-hover hover:text-surface'
+ "
+ @click="store.setLayoutMode(node.id, dir.mode)"
+ >
+ <component :is="`icon-lucide-${dir.icon}`" class="size-3.5" />
+ </button>
+ <button
+ v-if="isFlex"
+ data-test-id="layout-direction-wrap"
+ class="flex cursor-pointer items-center justify-center rounded border px-2 py-1"
+ :class="
+ node.layoutWrap === 'WRAP'
+ ? 'border-accent bg-accent/10 text-accent'
+ : 'border-border text-muted hover:bg-hover hover:text-surface'
+ "
+ @click="updateProp('layoutWrap', node.layoutWrap === 'WRAP' ? 'NO_WRAP' : 'WRAP')"
+ >
+ <icon-lucide-wrap-text class="size-3.5" />
+ </button>
+ </div>
+
+ <!-- Grid tracks -->
+ <template v-if="isGrid">
+ <div
+ v-for="trackProp in ['gridTemplateColumns', 'gridTemplateRows'] as const"
+ :key="trackProp"
+ class="mt-2"
+ >
+ <div class="mb-1 flex items-center justify-between">
+ <label class="text-[11px] text-muted">{{
+ trackProp === 'gridTemplateColumns' ? 'Columns' : 'Rows'
+ }}</label>
<button
- v-if="node.gridTemplateColumns.length > 1"
- class="cursor-pointer rounded border-none bg-transparent px-0.5 text-xs text-muted hover:text-surface"
- title="Remove column"
- @click="removeTrack('gridTemplateColumns', i)"
+ class="cursor-pointer rounded border-none bg-transparent px-1 text-xs leading-none text-muted hover:bg-hover hover:text-surface"
+ @click="addTrack(trackProp)"
>
- ×
+ +
</button>
</div>
+ <div class="flex flex-col gap-1">
+ <div v-for="(track, i) in node[trackProp]" :key="i" class="flex items-center gap-1">
+ <ScrubInput
+ v-if="track.sizing !== 'AUTO'"
+ class="flex-1"
+ :icon="`${trackProp === 'gridTemplateColumns' ? 'C' : 'R'}${i + 1}`"
+ :model-value="track.value"
+ :min="track.sizing === 'FR' ? 1 : 0"
+ :suffix="track.sizing === 'FR' ? 'fr' : 'px'"
+ @update:model-value="updateGridTrack(trackProp, i, { value: $event })"
+ />
+ <span v-else class="flex-1 px-1 text-xs text-muted">{{ trackLabel(track) }}</span>
+ <AppSelect
+ :model-value="track.sizing"
+ :options="trackSizingOptions"
+ @update:model-value="
+ updateGridTrack(trackProp, i, {
+ sizing: $event,
+ value: $event === 'FR' ? 1 : $event === 'FIXED' ? 100 : 0
+ })
+ "
+ />
+ <button
+ v-if="node[trackProp].length > 1"
+ class="cursor-pointer rounded border-none bg-transparent px-0.5 text-xs text-muted hover:text-surface"
+ @click="removeTrack(trackProp, i)"
+ >
+ ×
+ </button>
+ </div>
+ </div>
</div>
- </div>
-
- <!-- Row tracks -->
- <div class="mt-2">
- <div class="mb-1 flex items-center justify-between">
- <label class="text-[11px] text-muted">Rows</label>
+ <div class="mt-2 grid grid-cols-2 gap-1.5">
+ <ScrubInput
+ icon="↔"
+ :model-value="Math.round(node.gridColumnGap)"
+ :min="0"
+ @update:model-value="updateProp('gridColumnGap', $event)"
+ @commit="(v: number, p: number) => commitProp('gridColumnGap', v, p)"
+ />
+ <ScrubInput
+ icon="↕"
+ :model-value="Math.round(node.gridRowGap)"
+ :min="0"
+ @update:model-value="updateProp('gridRowGap', $event)"
+ @commit="(v: number, p: number) => commitProp('gridRowGap', v, p)"
+ />
+ </div>
+ </template>
+
+ <!-- Flex gap + padding toggle -->
+ <template v-if="isFlex">
+ <div class="mt-2 flex items-center gap-1.5">
+ <ScrubInput
+ data-test-id="layout-gap-input"
+ class="flex-1"
+ :icon="node.layoutMode === 'VERTICAL' ? '↕' : '↔'"
+ :model-value="Math.round(node.itemSpacing)"
+ :min="0"
+ @update:model-value="updateProp('itemSpacing', $event)"
+ @commit="(v: number, p: number) => commitProp('itemSpacing', v, p)"
+ />
<button
- class="cursor-pointer rounded border-none bg-transparent px-1 text-xs leading-none text-muted hover:bg-hover hover:text-surface"
- title="Add row"
- @click="addTrack('gridTemplateRows')"
+ class="flex size-7 shrink-0 cursor-pointer items-center justify-center rounded border border-border bg-transparent text-muted hover:bg-hover hover:text-surface"
+ @click="toggleIndividualPadding"
>
- +
+ <icon-lucide-minus
+ v-if="showIndividualPadding || !hasUniformPadding"
+ class="size-3"
+ />
+ <icon-lucide-plus v-else class="size-3" />
</button>
</div>
- <div class="flex flex-col gap-1">
- <div
- v-for="(row, i) in node.gridTemplateRows"
- :key="i"
- class="flex items-center gap-1"
- >
- <ScrubInput
- v-if="row.sizing !== 'AUTO'"
- class="flex-1"
- :icon="`R${i + 1}`"
- :model-value="row.value"
- :min="row.sizing === 'FR' ? 1 : 0"
- :step="row.sizing === 'FR' ? 1 : 1"
- :suffix="row.sizing === 'FR' ? 'fr' : 'px'"
- @update:model-value="updateGridTrack('gridTemplateRows', i, { value: $event })"
- />
- <span v-else class="flex-1 px-1 text-xs text-muted">{{ trackLabel(row) }}</span>
- <AppSelect
- :model-value="row.sizing"
- :options="TRACK_SIZING_OPTIONS"
- @update:model-value="
- updateGridTrack('gridTemplateRows', i, {
- sizing: $event,
- value: $event === 'FR' ? 1 : $event === 'FIXED' ? 100 : 0
- })
- "
- />
- <button
- v-if="node.gridTemplateRows.length > 1"
- class="cursor-pointer rounded border-none bg-transparent px-0.5 text-xs text-muted hover:text-surface"
- title="Remove row"
- @click="removeTrack('gridTemplateRows', i)"
- >
- ×
- </button>
- </div>
+ <div v-if="!showIndividualPadding && hasUniformPadding" class="mt-1.5">
+ <ScrubInput
+ data-test-id="layout-uniform-padding-input"
+ icon="☐"
+ :model-value="Math.round(node.paddingTop)"
+ :min="0"
+ @update:model-value="setUniformPadding"
+ @commit="commitUniformPadding"
+ />
</div>
- </div>
-
- <!-- Grid gaps -->
- <div class="mt-2 grid grid-cols-2 gap-1.5">
- <ScrubInput
- icon="↔"
- :model-value="Math.round(node.gridColumnGap)"
- :min="0"
- @update:model-value="updateProp('gridColumnGap', $event)"
- @commit="(v: number, p: number) => commitProp('gridColumnGap', v, p)"
- />
- <ScrubInput
- icon="↕"
- :model-value="Math.round(node.gridRowGap)"
- :min="0"
- @update:model-value="updateProp('gridRowGap', $event)"
- @commit="(v: number, p: number) => commitProp('gridRowGap', v, p)"
- />
- </div>
- </template>
-
- <!-- Flex-specific controls -->
- <template v-if="isFlex">
- <div class="mt-2 flex items-center gap-1.5">
- <ScrubInput
- data-test-id="layout-gap-input"
- class="flex-1"
- :icon="node.layoutMode === 'VERTICAL' ? '↕' : '↔'"
- :model-value="Math.round(node.itemSpacing)"
- :min="0"
- @update:model-value="updateProp('itemSpacing', $event)"
- @commit="(v: number, p: number) => commitProp('itemSpacing', v, p)"
- />
- <button
- class="flex size-7 shrink-0 cursor-pointer items-center justify-center rounded border border-border bg-transparent text-muted hover:bg-hover hover:text-surface"
- :title="
- showIndividualPadding || !hasUniformPadding()
- ? 'Uniform padding'
- : 'Per-side padding'
- "
- @click="showIndividualPadding = !showIndividualPadding"
- >
- <icon-lucide-minus
- v-if="showIndividualPadding || !hasUniformPadding()"
- class="size-3"
+ </template>
+
+ <!-- Per-side padding -->
+ <template v-if="isGrid || (isFlex && (showIndividualPadding || !hasUniformPadding))">
+ <div class="mt-1.5 grid grid-cols-2 gap-1.5">
+ <ScrubInput
+ v-for="side in [
+ 'paddingTop',
+ 'paddingRight',
+ 'paddingBottom',
+ 'paddingLeft'
+ ] as const"
+ :key="side"
+ :icon="side[7]"
+ :model-value="Math.round(node[side])"
+ :min="0"
+ @update:model-value="updateProp(side, $event)"
+ @commit="(v: number, p: number) => commitProp(side, v, p)"
/>
- <icon-lucide-plus v-else class="size-3" />
- </button>
- </div>
-
- <div v-if="!showIndividualPadding && hasUniformPadding()" class="mt-1.5">
- <ScrubInput
- data-test-id="layout-uniform-padding-input"
- icon="☐"
- :model-value="Math.round(node.paddingTop)"
- :min="0"
- @update:model-value="setUniformPadding"
- @commit="commitUniformPadding"
- />
- </div>
- </template>
+ </div>
+ </template>
- <!-- Per-side padding -->
- <template v-if="isGrid || (isFlex && (showIndividualPadding || !hasUniformPadding()))">
- <div class="mt-1.5 grid grid-cols-2 gap-1.5">
- <ScrubInput
- icon="T"
- :model-value="Math.round(node.paddingTop)"
- :min="0"
- @update:model-value="updateProp('paddingTop', $event)"
- @commit="(v: number, p: number) => commitProp('paddingTop', v, p)"
- />
- <ScrubInput
- icon="R"
- :model-value="Math.round(node.paddingRight)"
- :min="0"
- @update:model-value="updateProp('paddingRight', $event)"
- @commit="(v: number, p: number) => commitProp('paddingRight', v, p)"
- />
- <ScrubInput
- icon="B"
- :model-value="Math.round(node.paddingBottom)"
- :min="0"
- @update:model-value="updateProp('paddingBottom', $event)"
- @commit="(v: number, p: number) => commitProp('paddingBottom', v, p)"
- />
- <ScrubInput
- icon="L"
- :model-value="Math.round(node.paddingLeft)"
- :min="0"
- @update:model-value="updateProp('paddingLeft', $event)"
- @commit="(v: number, p: number) => commitProp('paddingLeft', v, p)"
- />
+ <!-- Alignment grid (flex only) -->
+ <div v-if="isFlex" class="mt-2">
+ <label class="mb-1 block text-[11px] text-muted">Alignment</label>
+ <div data-test-id="layout-alignment-grid" class="grid w-fit grid-cols-3 gap-0.5">
+ <button
+ v-for="cell in alignGrid"
+ :key="`${cell.primary}-${cell.counter}`"
+ class="flex size-6 cursor-pointer items-center justify-center rounded border text-[11px]"
+ :class="
+ node.primaryAxisAlign === cell.primary && node.counterAxisAlign === cell.counter
+ ? 'border-accent bg-accent/10 text-accent'
+ : 'border-border text-muted hover:bg-hover hover:text-surface'
+ "
+ @click="setAlignment(cell.primary, cell.counter)"
+ >
+ <span class="size-1.5 rounded-full bg-current" />
+ </button>
+ </div>
</div>
</template>
+ </div>
- <!-- Alignment (flex only) -->
- <div v-if="isFlex" class="mt-2">
- <label class="mb-1 block text-[11px] text-muted">Alignment</label>
- <div data-test-id="layout-alignment-grid" class="grid w-fit grid-cols-3 gap-0.5">
- <button
- v-for="cell in alignGrid"
- :key="`${cell.primary}-${cell.counter}`"
- class="flex size-6 cursor-pointer items-center justify-center rounded border text-[11px]"
- :class="
- node.primaryAxisAlign === cell.primary && node.counterAxisAlign === cell.counter
- ? 'border-accent bg-accent/10 text-accent'
- : 'border-border text-muted hover:bg-hover hover:text-surface'
- "
- @click="setAlignment(cell.primary, cell.counter)"
- >
- <span class="size-1.5 rounded-full bg-current" />
- </button>
- </div>
- </div>
- </template>
- </div>
-
- <div class="border-b border-border px-3 py-2">
- <label class="flex cursor-pointer items-center gap-2 text-xs text-surface">
- <input
- type="checkbox"
- data-test-id="clip-content-checkbox"
- class="accent-accent"
- :checked="node.clipsContent"
- @change="
- store.updateNodeWithUndo(
- node.id,
- { clipsContent: !node.clipsContent },
- 'Toggle clip content'
- )
- "
- />
- Clip content
- </label>
- </div>
- </template>
+ <!-- Clip content -->
+ <div class="border-b border-border px-3 py-2">
+ <label class="flex cursor-pointer items-center gap-2 text-xs text-surface">
+ <input
+ type="checkbox"
+ data-test-id="clip-content-checkbox"
+ class="accent-accent"
+ :checked="node.clipsContent"
+ @change="
+ store.updateNodeWithUndo(
+ node.id,
+ { clipsContent: !node.clipsContent },
+ 'Toggle clip content'
+ )
+ "
+ />
+ Clip content
+ </label>
+ </div>
+ </template>
+ </LayoutControlsRoot>
</template>