AI-native design editor. Open-source Figma alternative.
Nested section titles inside body, auto-adopt siblings on creation
Danila Poyarkov715f6e3281f4
diff --git a/src/composables/use-canvas-input.ts b/src/composables/use-canvas-input.tsindex cb595b07c..4d282e232 100644--- a/src/composables/use-canvas-input.ts+++ b/src/composables/use-canvas-input.ts@@ -789,6 +789,9 @@ export function useCanvasInput(canvasRef: Ref<HTMLCanvasElement | null>, store:if (node && node.width < 2 && node.height < 2) {store.updateNode(d.nodeId, { width: 100, height: 100 })}+ if (node?.type === 'SECTION') {+ store.adoptNodesIntoSection(node.id)+ }store.setTool('SELECT')}diff --git a/src/engine/renderer.ts b/src/engine/renderer.tsindex b7fffcfc3..8c83abc7d 100644--- a/src/engine/renderer.ts+++ b/src/engine/renderer.ts@@ -725,8 +725,8 @@ export class SkiaRenderer {const pageNode = graph.getNode(this.pageId ?? graph.rootId)if (!pageNode) return- const sections: { node: SceneNode; absX: number; absY: number }[] = []- const collectSections = (parentId: string, ox: number, oy: number) => {+ const sections: { node: SceneNode; absX: number; absY: number; nested: boolean }[] = []+ const collectSections = (parentId: string, ox: number, oy: number, insideSection: boolean) => {const parent = graph.getNode(parentId)if (!parent) returnfor (const childId of parent.childIds) {@@ -734,18 +734,22 @@ export class SkiaRenderer {if (!child || !child.visible) continueconst ax = ox + child.xconst ay = oy + child.y- if (child.type === 'SECTION') sections.push({ node: child, absX: ax, absY: ay })- if (child.childIds.length > 0) collectSections(childId, ax, ay)+ if (child.type === 'SECTION') {+ sections.push({ node: child, absX: ax, absY: ay, nested: insideSection })+ collectSections(childId, ax, ay, true)+ } else if (child.childIds.length > 0) {+ collectSections(childId, ax, ay, insideSection)+ }}}- collectSections(pageNode.id, 0, 0)+ collectSections(pageNode.id, 0, 0, false)const font = this.sectionTitleFontconst ellipsis = '…'const ellipsisGlyphs = font.getGlyphIDs(ellipsis)const ellipsisWidth = font.getGlyphWidths(ellipsisGlyphs)[0]- for (const { node, absX, absY } of sections) {+ for (const { node, absX, absY, nested } of sections) {const screenX = (absX * this.zoom + this.panX)const screenY = (absY * this.zoom + this.panY)const screenW = node.width * this.zoom@@ -779,7 +783,9 @@ export class SkiaRenderer {const pillW = Math.min(textWidth + SECTION_TITLE_PADDING_X * 2, maxPillW)const pillH = SECTION_TITLE_HEIGHTconst pillX = screenX- const pillY = screenY - pillH - SECTION_TITLE_GAP+ const pillY = nested+ ? screenY + SECTION_TITLE_GAP+ : screenY - pillH - SECTION_TITLE_GAPconst pillPaint = new this.ck.Paint()pillPaint.setStyle(this.ck.PaintStyle.Fill)diff --git a/src/stores/editor.ts b/src/stores/editor.tsindex bc9c34045..546f058c3 100644--- a/src/stores/editor.ts+++ b/src/stores/editor.ts@@ -800,6 +800,63 @@ export function createEditorStore() {return id}+ function adoptNodesIntoSection(sectionId: string) {+ const section = graph.getNode(sectionId)+ if (!section || section.type !== 'SECTION') return++ const parentId = section.parentId ?? state.currentPageId+ const siblings = graph.getChildren(parentId)++ const sx = section.x+ const sy = section.y+ const sx2 = sx + section.width+ const sy2 = sy + section.height++ const toAdopt: string[] = []+ for (const sibling of siblings) {+ if (sibling.id === sectionId) continue+ const nx = sibling.x+ const ny = sibling.y+ const nx2 = nx + sibling.width+ const ny2 = ny + sibling.height+ if (nx >= sx && ny >= sy && nx2 <= sx2 && ny2 <= sy2) {+ toAdopt.push(sibling.id)+ }+ }++ if (toAdopt.length === 0) return++ const undoOps: Array<{ id: string; oldParent: string; oldX: number; oldY: number; newX: number; newY: number }> = []+ for (const id of toAdopt) {+ const node = graph.getNode(id)+ if (!node) continue+ const newX = node.x - sx+ const newY = node.y - sy+ undoOps.push({ id, oldParent: parentId, oldX: node.x, oldY: node.y, newX, newY })+ graph.reparentNode(id, sectionId)+ graph.updateNode(id, { x: newX, y: newY })+ }++ undo.push({+ label: 'Adopt into section',+ forward: () => {+ for (const op of undoOps) {+ graph.reparentNode(op.id, sectionId)+ graph.updateNode(op.id, { x: op.newX, y: op.newY })+ }+ requestRender()+ },+ inverse: () => {+ for (const op of undoOps) {+ graph.reparentNode(op.id, op.oldParent)+ graph.updateNode(op.id, { x: op.oldX, y: op.oldY })+ }+ requestRender()+ }+ })+ requestRender()+ }+function selectAll() {const children = graph.getChildren(state.currentPageId)state.selectedIds = new Set(children.map((n) => n.id))@@ -1147,6 +1204,7 @@ export function createEditorStore() {groupSelected,ungroupSelected,createShape,+ adoptNodesIntoSection,duplicateSelected,writeCopyData,pasteFromHTML,