Skip to content

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

Sort nodes by position when wrapping in auto-layout, fix null node crash

Danila Poyarkovce46dea54d7c
diff --git a/src/components/properties/AppearanceSection.vue b/src/components/properties/AppearanceSection.vue
index cacd5ddc1..82f2681f2 100644
--- a/src/components/properties/AppearanceSection.vue
+++ b/src/components/properties/AppearanceSection.vue
@@ -11,7 +11,7 @@ function toggleVisibility() {
</script>
<template>
- <div class="border-b border-border px-3 py-2">
+ <div v-if="node" class="border-b border-border px-3 py-2">
<div class="mb-1.5 flex items-center justify-between">
<label class="text-[11px] text-muted">Appearance</label>
<button
diff --git a/src/components/properties/FillSection.vue b/src/components/properties/FillSection.vue
index bb389711c..f312028a5 100644
--- a/src/components/properties/FillSection.vue
+++ b/src/components/properties/FillSection.vue
@@ -43,7 +43,7 @@ function remove(index: number) {
</script>
<template>
- <div class="border-b border-border px-3 py-2">
+ <div v-if="node" class="border-b border-border px-3 py-2">
<div class="flex items-center justify-between">
<label class="mb-1 block text-[11px] text-muted">Fill</label>
<button class="cursor-pointer rounded border-none bg-transparent px-1 text-base leading-none text-muted hover:bg-hover hover:text-surface" @click="add">+</button>
diff --git a/src/components/properties/LayoutSection.vue b/src/components/properties/LayoutSection.vue
index 7467fef57..c11ce2a25 100644
--- a/src/components/properties/LayoutSection.vue
+++ b/src/components/properties/LayoutSection.vue
@@ -100,7 +100,7 @@ function setAlignment(primary: LayoutAlign, counter: LayoutCounterAlign) {
</script>
<template>
- <div class="border-b border-border px-3 py-2">
+ <div v-if="node" 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">
<!-- Width -->
diff --git a/src/components/properties/PositionSection.vue b/src/components/properties/PositionSection.vue
index c72409f90..63673ccc4 100644
--- a/src/components/properties/PositionSection.vue
+++ b/src/components/properties/PositionSection.vue
@@ -75,7 +75,7 @@ function rotate90() {
</script>
<template>
- <div class="border-b border-border px-3 py-2">
+ <div v-if="node" class="border-b border-border px-3 py-2">
<label class="mb-1.5 block text-[11px] text-muted">Position</label>
<!-- Alignment buttons -->
diff --git a/src/components/properties/StrokeSection.vue b/src/components/properties/StrokeSection.vue
index d9d28bdcd..0afe16480 100644
--- a/src/components/properties/StrokeSection.vue
+++ b/src/components/properties/StrokeSection.vue
@@ -49,7 +49,7 @@ function remove(index: number) {
</script>
<template>
- <div class="border-b border-border px-3 py-2">
+ <div v-if="node" class="border-b border-border px-3 py-2">
<div class="flex items-center justify-between">
<label class="mb-1 block text-[11px] text-muted">Stroke</label>
<button class="cursor-pointer rounded border-none bg-transparent px-1 text-base leading-none text-muted hover:bg-hover hover:text-surface" @click="add">+</button>
diff --git a/src/components/properties/TypographySection.vue b/src/components/properties/TypographySection.vue
index 567d0def8..4da44d600 100644
--- a/src/components/properties/TypographySection.vue
+++ b/src/components/properties/TypographySection.vue
@@ -77,7 +77,7 @@ onMounted(async () => {
</script>
<template>
- <div class="border-b border-border px-3 py-2">
+ <div v-if="node" class="border-b border-border px-3 py-2">
<label class="mb-1.5 block text-[11px] text-muted">Typography</label>
<!-- Font family picker -->
diff --git a/src/composables/use-node-props.ts b/src/composables/use-node-props.ts
index 6ec1984da..4b95b3d11 100644
--- a/src/composables/use-node-props.ts
+++ b/src/composables/use-node-props.ts
@@ -6,7 +6,7 @@ import type { SceneNode } from '../engine/scene-graph'
export function useNodeProps() {
const store = useEditorStore()
- const node = computed(() => store.selectedNode.value!)
+ const node = computed(() => store.selectedNode.value ?? null)
const nodes = computed(() => store.selectedNodes.value)
function updateProp(key: string, value: number | string) {
diff --git a/src/stores/editor.ts b/src/stores/editor.ts
index b7151fc53..66e093173 100644
--- a/src/stores/editor.ts
+++ b/src/stores/editor.ts
@@ -502,8 +502,13 @@ export function createEditorStore() {
})
const frameId = frame.id
- for (const n of nodes) {
- graph.reparentNode(n.id, frameId)
+ const sortedIds = nodes
+ .map((n) => ({ id: n.id, pos: graph.getAbsolutePosition(n.id) }))
+ .sort((a, b) => a.pos.y - b.pos.y || a.pos.x - b.pos.x)
+ .map((n) => n.id)
+
+ for (const id of sortedIds) {
+ graph.reparentNode(id, frameId)
}
computeLayout(graph, frameId)