AI-native design editor. Open-source Figma alternative.
Fix component interaction: click selects component, drag by label, no white fill
Danila Poyarkov33fa8505739f
diff --git a/src/components/EditorCanvas.vue b/src/components/EditorCanvas.vueindex 4c3524bd7..a25624d1a 100644--- a/src/components/EditorCanvas.vue+++ b/src/components/EditorCanvas.vue@@ -9,8 +9,8 @@ import CanvasContextMenu from './CanvasContextMenu.vue'const store = useEditorStore()const canvasRef = ref<HTMLCanvasElement | null>(null)-const { hitTestSectionTitle } = useCanvas(canvasRef, store)-const { cursorOverride } = useCanvasInput(canvasRef, store, hitTestSectionTitle)+const { hitTestSectionTitle, hitTestComponentLabel } = useCanvas(canvasRef, store)+const { cursorOverride } = useCanvasInput(canvasRef, store, hitTestSectionTitle, hitTestComponentLabel)const cursor = computed(() => {if (cursorOverride.value) return cursorOverride.valuediff --git a/src/composables/use-canvas-input.ts b/src/composables/use-canvas-input.tsindex fcc09b592..acd197279 100644--- a/src/composables/use-canvas-input.ts+++ b/src/composables/use-canvas-input.ts@@ -204,7 +204,8 @@ function hitTestRotationHandle(export function useCanvasInput(canvasRef: Ref<HTMLCanvasElement | null>,store: EditorStore,- hitTestSectionTitle: (cx: number, cy: number) => import('../engine/scene-graph').SceneNode | null+ hitTestSectionTitle: (cx: number, cy: number) => import('../engine/scene-graph').SceneNode | null,+ hitTestComponentLabel: (cx: number, cy: number) => import('../engine/scene-graph').SceneNode | null) {const drag = ref<DragState | null>(null)const cursorOverride = ref<string | null>(null)@@ -313,8 +314,8 @@ export function useCanvasInput(}}- // Hit test nodes (section title pill first, then body)- const hit = hitTestSectionTitle(cx, cy) ?? store.graph.hitTest(cx, cy, store.state.currentPageId)+ // Hit test nodes (labels first, then body)+ const hit = hitTestSectionTitle(cx, cy) ?? hitTestComponentLabel(cx, cy) ?? store.graph.hitTest(cx, cy, store.state.currentPageId)if (hit) {if (!store.state.selectedIds.has(hit.id) && !e.shiftKey) {store.select([hit.id])@@ -484,7 +485,7 @@ export function useCanvasInput(}cursorOverride.value = cursor- const hit = hitTestSectionTitle(cx, cy) ?? store.graph.hitTest(cx, cy)+ const hit = hitTestSectionTitle(cx, cy) ?? hitTestComponentLabel(cx, cy) ?? store.graph.hitTest(cx, cy)store.setHoveredNode(hit && !store.state.selectedIds.has(hit.id) ? hit.id : null)}@@ -829,11 +830,17 @@ export function useCanvasInput(function onDblClick(e: MouseEvent) {const { cx, cy } = getCoords(e)- const hit = hitTestSectionTitle(cx, cy) ?? store.graph.hitTest(cx, cy, store.state.currentPageId)- if (hit && hit.type === 'TEXT') {+ const hit = hitTestSectionTitle(cx, cy) ?? hitTestComponentLabel(cx, cy) ?? store.graph.hitTestDeep(cx, cy, store.state.currentPageId)+ if (!hit) return++ if (hit.type === 'TEXT') {store.select([hit.id])store.startTextEditing(hit.id)+ return}++ // Double-click enters components/instances — select the child inside+ store.select([hit.id])}function computeAutoLayoutIndicator(d: DragMove, cx: number, cy: number) {diff --git a/src/composables/use-canvas.ts b/src/composables/use-canvas.tsindex 4825d245e..0e8b70229 100644--- a/src/composables/use-canvas.ts+++ b/src/composables/use-canvas.ts@@ -104,5 +104,9 @@ export function useCanvas(canvasRef: Ref<HTMLCanvasElement | null>, store: Editoreturn renderer?.hitTestSectionTitle(store.graph, canvasX, canvasY) ?? null}- return { render, hitTestSectionTitle }+ function hitTestComponentLabel(canvasX: number, canvasY: number) {+ return renderer?.hitTestComponentLabel(store.graph, canvasX, canvasY) ?? null+ }++ return { render, hitTestSectionTitle, hitTestComponentLabel }}diff --git a/src/engine/renderer.ts b/src/engine/renderer.tsindex 7c3f7e87f..3dd3cdfc8 100644--- a/src/engine/renderer.ts+++ b/src/engine/renderer.ts@@ -210,6 +210,60 @@ export class SkiaRenderer {return result}+ hitTestComponentLabel(graph: SceneGraph, canvasX: number, canvasY: number): SceneNode | null {+ if (!this.componentLabelFont) return null++ const pageNode = graph.getNode(this.pageId ?? graph.rootId)+ if (!pageNode) return null++ const font = this.componentLabelFont+ const LABEL_TYPES = new Set(['COMPONENT', 'COMPONENT_SET', 'INSTANCE'])+ let result: SceneNode | null = null++ const check = (parentId: string, ox: number, oy: number) => {+ const parent = graph.getNode(parentId)+ if (!parent) return+ for (let i = parent.childIds.length - 1; i >= 0; i--) {+ if (result) return+ const childId = parent.childIds[i]+ const child = graph.getNode(childId)+ if (!child || !child.visible) continue+ const ax = ox + child.x+ const ay = oy + child.y+ if (LABEL_TYPES.has(child.type)) {+ const glyphIds = font.getGlyphIDs(child.name)+ const widths = font.getGlyphWidths(glyphIds)+ let textW = 0+ for (const w of widths) textW += w+ const labelW = (COMPONENT_LABEL_ICON_SIZE + COMPONENT_LABEL_ICON_GAP + textW) / this.zoom+ const labelH = COMPONENT_LABEL_FONT_SIZE / this.zoom+ const gap = COMPONENT_LABEL_GAP / this.zoom++ const isInsideSet = parent.type === 'COMPONENT_SET'+ const labelX = ax+ let labelY: number+ if (isInsideSet) {+ labelY = ay + gap+ } else {+ labelY = ay - labelH - gap+ }++ if (canvasX >= labelX && canvasX <= labelX + labelW &&+ canvasY >= labelY && canvasY <= labelY + labelH) {+ result = child+ return+ }+ }+ if (child.childIds.length > 0) {+ check(childId, ax, ay)+ }+ }+ }++ check(pageNode.id, 0, 0)+ return result+ }+renderSceneToCanvas(canvas: Canvas, graph: SceneGraph, pageId: string): void {const pageNode = graph.getNode(pageId)if (pageNode) {diff --git a/src/engine/scene-graph.ts b/src/engine/scene-graph.tsindex 253f7be93..95715ef31 100644--- a/src/engine/scene-graph.ts+++ b/src/engine/scene-graph.ts@@ -456,15 +456,23 @@ export class SceneGraph {hitTest(px: number, py: number, scopeId?: string): SceneNode | null {const scope = scopeId ?? this.rootId- return this.hitTestChildren(px, py, scope, 0, 0)+ return this.hitTestChildren(px, py, scope, 0, 0, false)}+ hitTestDeep(px: number, py: number, scopeId?: string): SceneNode | null {+ const scope = scopeId ?? this.rootId+ return this.hitTestChildren(px, py, scope, 0, 0, true)+ }++ private static readonly OPAQUE_CONTAINER_TYPES = new Set<NodeType>(['COMPONENT', 'INSTANCE'])+private hitTestChildren(px: number,py: number,parentId: string,offsetX: number,- offsetY: number+ offsetY: number,+ deep = false): SceneNode | null {const parent = this.nodes.get(parentId)if (!parent) return null@@ -478,9 +486,17 @@ export class SceneGraph {const ax = offsetX + child.xconst ay = offsetY + child.y+ // Components/instances: don't recurse unless in deep mode (double-click)+ if (SceneGraph.OPAQUE_CONTAINER_TYPES.has(child.type) && !deep) {+ if (px >= ax && px <= ax + child.width && py >= ay && py <= ay + child.height) {+ return child+ }+ continue+ }+// Check children first (deeper hit)if (CONTAINER_TYPES.has(child.type)) {- const deepHit = this.hitTestChildren(px, py, childId, ax, ay)+ const deepHit = this.hitTestChildren(px, py, childId, ax, ay, deep)if (deepHit) return deepHit}diff --git a/src/stores/editor.ts b/src/stores/editor.tsindex f156e4309..6399c11f6 100644--- a/src/stores/editor.ts+++ b/src/stores/editor.ts@@ -853,7 +853,7 @@ export function createEditorStore() {y: minY - parentAbs.y,width: maxX - minX,height: maxY - minY,- fills: [{ type: 'SOLID', color: { r: 1, g: 1, b: 1, a: 1 }, opacity: 1, visible: true }]+ fills: []})const componentId = component.id