From 08b4c31f54feaa899f47febb7eed54efcf26092d Mon Sep 17 00:00:00 2001 From: Doruk Kavcioglu Date: Tue, 21 Jul 2026 21:42:07 +0300 Subject: [PATCH] refactor(inspector): keep the persistent host inside the keyed boundary and add owner-aware timeline policy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Follow-up to the persistent floating-inspector host. The host no longer needs to outlive the selection boundary — a normal keyframe click may close the session — so this pulls it back inside and replaces the cross-boundary lifetime machinery with a narrower timeline policy. - Move ActiveInspectorProvider and the single host back inside the selectionHash keyed boundary. Genuine selection changes (empty click, another layer, a keyframe click) now close the session via the keyed remount; the host stays non-keyed so it still persists across owner changes within one selection. - Fix cross-owner handoff with a dedicated data-inspector-handoff attribute: pointerdown over an inspector-opening control no longer dismisses the current session, so state goes directly owner→owner without passing through null (which rebuilt the layer). Marked on the effect/shadow/transition/animation/export rows, the direct shadow/fill/ stroke "+" buttons, and the color/fill swatches — not on dropdowns, remove buttons, or unrelated controls, which keep normal dismissal. - Replace the selection-membership ownership effect with owner-aware drag detection: drags never touch Selected (clip.ts/keyframe.ts mutate it on click only), so query ClipDragOrigin/KeyframeDragOrigin and close only when a dragged clip/keyframe belongs to a different layer than ownerNodeEid. Playhead and current-layer drags preserve the full main+nested session; other-layer drags close it. - Trim InspectorSession to what remains needed (drop triggerEl, triggerControlSelector, keepOpenWhile); keep ownerNodeEid solely for the timeline policy. Layer-less inspectors (background/export) pass null and keep normal dismissal. --- .../inspector/active-inspector.tsx | 53 +++++++------------ .../sidebar-right/inspector/animations.tsx | 3 +- .../sidebar-right/inspector/background.tsx | 2 - .../inspector/caption-settings.tsx | 2 - .../sidebar-right/inspector/effects.tsx | 3 +- .../sidebar-right/inspector/export.tsx | 3 +- .../sidebar-right/inspector/fills.tsx | 3 +- .../sidebar-right/inspector/inspector.tsx | 4 +- .../sidebar-right/inspector/shadows.tsx | 4 +- .../sidebar-right/inspector/strokes.tsx | 3 +- .../sidebar-right/inspector/transition.tsx | 3 +- .../src/components/ui/color-opacity-row.tsx | 1 + apps/web/src/components/ui/fill-item.tsx | 1 + .../src/components/ui/floating-inspector.tsx | 12 +++-- apps/web/src/components/ui/item-row.tsx | 26 ++++++--- 15 files changed, 58 insertions(+), 65 deletions(-) diff --git a/apps/web/src/components/sidebar-right/inspector/active-inspector.tsx b/apps/web/src/components/sidebar-right/inspector/active-inspector.tsx index cf18c9d..306a67d 100644 --- a/apps/web/src/components/sidebar-right/inspector/active-inspector.tsx +++ b/apps/web/src/components/sidebar-right/inspector/active-inspector.tsx @@ -3,40 +3,26 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ import { createContext, createEffect, createSignal, Show, useContext, type Accessor, type JSX } from "solid-js"; -import { useECS } from "@/context/ecs"; +import { Or } from "bitecs"; +import { useEngine } from "@/context/engine"; +import { useQuery, findKeyframeTargetNode } from "@/components/engine"; import { FloatingInspector, FloatingInspectorLayer, FloatingInspectorSessionProvider, } from "@/components/ui/floating-inspector"; -/** - * A floating inspector and its open nested pickers form one editing session - * owned by a layer. The session is host-owned and ID-driven so it outlives the - * property section that opened it — the section can unmount (e.g. selection - * target flips to a keyframe) while the session stays open, as long as the - * owning layer remains selected. - */ export type InspectorSession = { owner: string; - /** The inspected entity (shadow/effect/fill/… eid). */ id: number; - /** Owning layer; the session closes when this leaves the selection. Null for - * layer-less inspectors (background/export) which keep normal dismissal. */ + /** Owning layer for the timeline policy; null for layer-less inspectors + * (background/export), which keep normal dismissal. */ ownerNodeEid: number | null; - /** Positioning anchor, captured at open so it survives the section unmounting. */ anchorEl: HTMLElement | null; - /** Trigger subtree; clicks on its control are ignored so re-click toggles. */ - triggerEl?: HTMLElement | null; width?: number; offset?: number; labelledBy?: string; - triggerControlSelector?: string; - /** Body factory, executed under the host owner. Must be self-contained and - * read entity data from the global ECS world by id — no section-owned scope. */ render: () => JSX.Element; - /** Overrides the default "owning layer stays selected" keep-open rule. */ - keepOpenWhile?: (selected: Set) => boolean; }; type ActiveInspectorContextValue = { @@ -76,25 +62,26 @@ function FloatingInspectorHost(props: { session: Accessor; onClose: (owner: string) => void; }) { - const { selectedNodes } = useECS(); + const { world } = useEngine(); + const c = world.components; + + // Selection changes close via the keyed boundary; this only handles direct + // drags, which never touch Selected (clip.ts/keyframe.ts mutate it on click only). + const draggedClips = useQuery([Or(c.Geometry, c.Group, c.AdjustmentLayer), c.ClipDragOrigin]); + const draggedKeyframes = useQuery([c.Keyframe, c.KeyframeDragOrigin]); - // Ownership effect: selection is the authority. Close the whole session once - // its owning layer leaves the selection. Uses ownerNodeEid membership (not - // selection-hash equality) so keyframe selection — which changes the hash - // while the layer stays selected — never closes the session. createEffect(() => { const s = props.session(); if (!s || s.ownerNodeEid == null) return; - const ownerNodeEid = s.ownerNodeEid; - const keepOpen = s.keepOpenWhile ?? ((sel: Set) => sel.has(ownerNodeEid)); - if (!keepOpen(selectedNodes())) props.onClose(s.owner); + const owner = s.ownerNodeEid; + const otherLayerDragged = + draggedClips().some((cid) => cid !== owner) || + draggedKeyframes().some((kid) => findKeyframeTargetNode(world, kid) !== owner); + if (otherLayerDragged) props.onClose(s.owner); }); - // Non-keyed: the layer/portal mounts once when any session opens and PERSISTS - // across owner and id changes — only the body (and anchor) swap reactively. This - // is what removes the cross-owner teardown flicker; a keyed Show here would - // rebuild the Kobalte dialog on every handoff. Session-context value is a getter - // so nested pickers read the current owner's policy through the persistent layer. + // Non-keyed so the layer persists across owner/id changes — a cross-owner handoff + // swaps only the body, never tearing down the Kobalte dialog. return ( } onClick={props.onInspect} + handoff > ( ( <> diff --git a/apps/web/src/components/sidebar-right/inspector/caption-settings.tsx b/apps/web/src/components/sidebar-right/inspector/caption-settings.tsx index 388e123..0261b6a 100644 --- a/apps/web/src/components/sidebar-right/inspector/caption-settings.tsx +++ b/apps/web/src/components/sidebar-right/inspector/caption-settings.tsx @@ -149,9 +149,7 @@ export function CaptionSettings(props: CaptionSettingsProps) { id: slotIndex, ownerNodeEid: eid(), anchorEl: anchorRef ?? null, - triggerEl: sectionRef ?? null, labelledBy: titleId, - triggerControlSelector: "[data-row-control]", render: () => ( } onClick={props.onInspect} + handoff disabled={hidden()} > ( ( } onClick={() => inspectors.toggle(exportSession())} + handoff > ( diff --git a/apps/web/src/components/sidebar-right/inspector/inspector.tsx b/apps/web/src/components/sidebar-right/inspector/inspector.tsx index 3184956..85d9497 100644 --- a/apps/web/src/components/sidebar-right/inspector/inspector.tsx +++ b/apps/web/src/components/sidebar-right/inspector/inspector.tsx @@ -93,8 +93,8 @@ export function Inspector() { return (
- + @@ -177,8 +177,8 @@ export function Inspector() { + -
); } diff --git a/apps/web/src/components/sidebar-right/inspector/shadows.tsx b/apps/web/src/components/sidebar-right/inspector/shadows.tsx index 7f0cca5..8d1f01a 100644 --- a/apps/web/src/components/sidebar-right/inspector/shadows.tsx +++ b/apps/web/src/components/sidebar-right/inspector/shadows.tsx @@ -79,6 +79,7 @@ function ShadowRow(props: ShadowRowProps) { value={color()} icon={} onClick={handleOpenInspector} + handoff disabled={hidden()} > @@ -140,10 +141,8 @@ export function ShadowsSettings(props: ShadowSettingsProps) { id: shadowEid, ownerNodeEid: eid(), anchorEl: anchorRef ?? null, - triggerEl: sectionRef ?? null, width: 248, labelledBy: titleId, - triggerControlSelector: "[data-row-control]", render: () => ( diff --git a/apps/web/src/components/sidebar-right/inspector/strokes.tsx b/apps/web/src/components/sidebar-right/inspector/strokes.tsx index 2907be7..c3e60b4 100644 --- a/apps/web/src/components/sidebar-right/inspector/strokes.tsx +++ b/apps/web/src/components/sidebar-right/inspector/strokes.tsx @@ -51,9 +51,7 @@ export function StrokesSettings(props: StrokesSettingsProps) { id: strokeEid, ownerNodeEid: eid(), anchorEl: anchorRef ?? null, - triggerEl: sectionRef ?? null, labelledBy: titleId, - triggerControlSelector: "[data-row-control]", render: () => ( diff --git a/apps/web/src/components/sidebar-right/inspector/transition.tsx b/apps/web/src/components/sidebar-right/inspector/transition.tsx index ecf6ede..2fca640 100644 --- a/apps/web/src/components/sidebar-right/inspector/transition.tsx +++ b/apps/web/src/components/sidebar-right/inspector/transition.tsx @@ -75,10 +75,8 @@ export function TransitionSettings(props: TransitionSettingsProps) { id: eid(), ownerNodeEid: eid(), anchorEl: anchorRef ?? null, - triggerEl: sectionRef ?? null, width: 248, labelledBy: titleId, - triggerControlSelector: "[data-row-control]", render: () => ( <> @@ -172,6 +170,7 @@ export function TransitionSettings(props: TransitionSettingsProps) { value={transitionLabel()} icon={} onClick={() => openInspector()} + handoff >