refactor(inspector): keep the persistent host inside the keyed boundary and add owner-aware timeline policy
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.
This commit is contained in:
parent
16cf01e6a6
commit
08b4c31f54
@ -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<number>) => boolean;
|
||||
};
|
||||
|
||||
type ActiveInspectorContextValue = {
|
||||
@ -76,25 +62,26 @@ function FloatingInspectorHost(props: {
|
||||
session: Accessor<InspectorSession | null>;
|
||||
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<number>) => 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 (
|
||||
<Show when={props.session()}>
|
||||
<FloatingInspectorSessionProvider
|
||||
@ -109,8 +96,6 @@ function FloatingInspectorHost(props: {
|
||||
const s = props.session();
|
||||
if (s) props.onClose(s.owner);
|
||||
}}
|
||||
triggerRef={props.session()?.triggerEl ?? undefined}
|
||||
triggerControlSelector={props.session()?.triggerControlSelector}
|
||||
labelledBy={props.session()?.labelledBy}
|
||||
>
|
||||
<FloatingInspector
|
||||
|
||||
@ -124,6 +124,7 @@ function AnimationRow(props: AnimationRowProps) {
|
||||
label={phaseLabel()}
|
||||
icon={<Icon name="preferences-adjust" />}
|
||||
onClick={props.onInspect}
|
||||
handoff
|
||||
>
|
||||
<IconButton
|
||||
tooltip="Remove animation"
|
||||
@ -180,10 +181,8 @@ export function AnimationsSettings(props: AnimationsSettingsProps) {
|
||||
id: animEid,
|
||||
ownerNodeEid: eid(),
|
||||
anchorEl: inspectorAnchorRef ?? null,
|
||||
triggerEl: sectionRef ?? null,
|
||||
width: 248,
|
||||
labelledBy: titleId,
|
||||
triggerControlSelector: "[data-row-control]",
|
||||
render: () => (
|
||||
<AnimationInspectorBody
|
||||
animEid={animEid}
|
||||
|
||||
@ -45,9 +45,7 @@ export function BackgroundSettings() {
|
||||
id: SLOT,
|
||||
ownerNodeEid: null,
|
||||
anchorEl: anchorRef ?? null,
|
||||
triggerEl: sectionRef ?? null,
|
||||
labelledBy: titleId,
|
||||
triggerControlSelector: "[data-row-control]",
|
||||
render: () => (
|
||||
<>
|
||||
<FloatingInspectorHeader>
|
||||
|
||||
@ -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: () => (
|
||||
<CaptionColorBody
|
||||
captionEid={eid()}
|
||||
|
||||
@ -71,6 +71,7 @@ function EffectRow(props: EffectRowProps) {
|
||||
value={label()}
|
||||
icon={<Icon name="fx" />}
|
||||
onClick={props.onInspect}
|
||||
handoff
|
||||
disabled={hidden()}
|
||||
>
|
||||
<IconButton
|
||||
@ -123,10 +124,8 @@ export function EffectsSettings(props: EffectsSettingsProps) {
|
||||
id: effectEid,
|
||||
ownerNodeEid: eid(),
|
||||
anchorEl: anchorRef ?? null,
|
||||
triggerEl: sectionRef ?? null,
|
||||
width: 248,
|
||||
labelledBy: titleId,
|
||||
triggerControlSelector: "[data-row-control]",
|
||||
render: () => (
|
||||
<EffectsInspectorBody
|
||||
effectEid={effectEid}
|
||||
|
||||
@ -160,10 +160,8 @@ export function ExportPanel(props: ExportPanelProps) {
|
||||
id: eid(),
|
||||
ownerNodeEid: null,
|
||||
anchorEl: inspectorAnchorRef ?? null,
|
||||
triggerEl: sectionRef ?? null,
|
||||
width: 272,
|
||||
labelledBy: titleId,
|
||||
triggerControlSelector: "[data-row-control]",
|
||||
render: () => (
|
||||
<ExportInspectorBody
|
||||
eid={eid}
|
||||
@ -294,6 +292,7 @@ export function ExportPanel(props: ExportPanelProps) {
|
||||
value={`${template().name} · ${template().video?.resolution}p`}
|
||||
icon={<Icon name="film-video-export" />}
|
||||
onClick={() => inspectors.toggle(exportSession())}
|
||||
handoff
|
||||
>
|
||||
<Tooltip>
|
||||
<TooltipTrigger
|
||||
|
||||
@ -49,9 +49,7 @@ export function FillsSettings(props: FillsSettingsProps) {
|
||||
id: fillEid,
|
||||
ownerNodeEid: eid(),
|
||||
anchorEl: anchorRef ?? null,
|
||||
triggerEl: sectionRef ?? null,
|
||||
labelledBy: titleId,
|
||||
triggerControlSelector: "[data-row-control]",
|
||||
render: () => (
|
||||
<FillPickerBody
|
||||
nodeEid={eid()}
|
||||
@ -103,6 +101,7 @@ export function FillsSettings(props: FillsSettingsProps) {
|
||||
variant="ghost"
|
||||
class="text-muted-foreground"
|
||||
data-row-control=""
|
||||
data-inspector-handoff=""
|
||||
onClick={handleAppendFill}
|
||||
>
|
||||
<Icon name="plus-add" />
|
||||
|
||||
@ -93,8 +93,8 @@ export function Inspector() {
|
||||
return (
|
||||
<div class="h-full min-h-0 flex flex-col" data-right-sidebar>
|
||||
<InspectorHeader />
|
||||
<ActiveInspectorProvider>
|
||||
<Show when={selectionHash()} keyed>
|
||||
<ActiveInspectorProvider>
|
||||
<ControlScrollArea class="flex-1 min-h-0">
|
||||
<Show when={includesTarget("scene-tool")}>
|
||||
<SceneTemplatePanel />
|
||||
@ -177,8 +177,8 @@ export function Inspector() {
|
||||
<InterpolationSettings />
|
||||
</Show>
|
||||
</ControlScrollArea>
|
||||
</ActiveInspectorProvider>
|
||||
</Show>
|
||||
</ActiveInspectorProvider>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@ -79,6 +79,7 @@ function ShadowRow(props: ShadowRowProps) {
|
||||
value={color()}
|
||||
icon={<Icon name="color-grade" />}
|
||||
onClick={handleOpenInspector}
|
||||
handoff
|
||||
disabled={hidden()}
|
||||
>
|
||||
<Tooltip>
|
||||
@ -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: () => (
|
||||
<ShadowInspectorBody
|
||||
shadowEid={shadowEid}
|
||||
@ -190,6 +189,7 @@ export function ShadowsSettings(props: ShadowSettingsProps) {
|
||||
variant="ghost"
|
||||
class="text-muted-foreground"
|
||||
data-row-control=""
|
||||
data-inspector-handoff=""
|
||||
onClick={handleAddShadow}
|
||||
>
|
||||
<Icon name="plus-add" />
|
||||
|
||||
@ -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: () => (
|
||||
<FillPickerBody
|
||||
nodeEid={eid()}
|
||||
@ -119,6 +117,7 @@ export function StrokesSettings(props: StrokesSettingsProps) {
|
||||
variant="ghost"
|
||||
class="text-muted-foreground"
|
||||
data-row-control=""
|
||||
data-inspector-handoff=""
|
||||
onClick={handleAppendStroke}
|
||||
>
|
||||
<Icon name="plus-add" />
|
||||
|
||||
@ -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: () => (
|
||||
<>
|
||||
<FloatingInspectorHeader class="items-center justify-between">
|
||||
@ -172,6 +170,7 @@ export function TransitionSettings(props: TransitionSettingsProps) {
|
||||
value={transitionLabel()}
|
||||
icon={<Icon name="video-transition" />}
|
||||
onClick={() => openInspector()}
|
||||
handoff
|
||||
>
|
||||
<Tooltip>
|
||||
<TooltipTrigger
|
||||
|
||||
@ -187,6 +187,7 @@ export function ColorOpacityRow(props: ColorOpacityRowProps) {
|
||||
<div class="relative z-10 flex h-full items-center">
|
||||
<button
|
||||
data-row-control=""
|
||||
data-inspector-handoff=""
|
||||
class="flex h-full shrink-0 items-center pl-1 pr-1"
|
||||
onClick={props.onClick}
|
||||
onPointerDown={(e) => e.stopPropagation()}
|
||||
|
||||
@ -302,6 +302,7 @@ export function FillItem(props: FillItemProps) {
|
||||
<div class="relative z-0 flex h-full items-center">
|
||||
<button
|
||||
data-row-control=""
|
||||
data-inspector-handoff=""
|
||||
class="flex h-full shrink-0 items-center pl-1 pr-1"
|
||||
onFocusIn={(e) => e.stopPropagation()}
|
||||
onClick={props.onClick}
|
||||
|
||||
@ -51,6 +51,10 @@ export const FloatingInspectorSessionProvider = FloatingInspectorSessionContext.
|
||||
* directly dismiss a layer-owned session; the ownership effect decides. */
|
||||
const TIMELINE_SURFACE_SELECTOR = "[data-timeline-surface]"
|
||||
|
||||
/** Controls that open/switch a floating inspector; pointerdown here must not
|
||||
* dismiss the current session, so it hands off directly without a null flash. */
|
||||
const INSPECTOR_HANDOFF_SELECTOR = "[data-inspector-handoff]"
|
||||
|
||||
const DRAG_HANDLE_SELECTOR = "[data-slot='floating-inspector-header']"
|
||||
const NON_DRAG_INTERACTIVE_SELECTOR = [
|
||||
"button",
|
||||
@ -330,13 +334,15 @@ export const FloatingInspectorLayer: Component<FloatingInspectorLayerProps> = (
|
||||
onFocusOutside={(event) => event.preventDefault()}
|
||||
onInteractOutside={(event) => {
|
||||
const target = event.target as Element | null
|
||||
// In a layer-owned session, timeline interactions never dismiss here;
|
||||
// the selection-driven ownership effect makes the keep/close call once
|
||||
// selection settles. Inherited by nested pickers via session context.
|
||||
if (target?.closest(INSPECTOR_HANDOFF_SELECTOR)) {
|
||||
event.preventDefault()
|
||||
return
|
||||
}
|
||||
if (session?.deferTimelineDismiss && target?.closest(TIMELINE_SURFACE_SELECTOR)) {
|
||||
event.preventDefault()
|
||||
return
|
||||
}
|
||||
// Nested pickers: re-click on their own trigger toggles, not dismiss.
|
||||
if (!target || !props.triggerRef?.contains(target)) return
|
||||
if (props.triggerControlSelector && !target.closest(props.triggerControlSelector)) return
|
||||
event.preventDefault()
|
||||
|
||||
@ -12,6 +12,9 @@ export type ItemRowProps = JSX.HTMLAttributes<HTMLDivElement> & {
|
||||
label?: string;
|
||||
icon?: JSX.Element;
|
||||
disabled?: boolean;
|
||||
/** Mark the opener region (icon + value, not the trailing action) as an
|
||||
* inspector handoff so opening from here doesn't dismiss the current one. */
|
||||
handoff?: boolean;
|
||||
children?: JSX.Element;
|
||||
};
|
||||
|
||||
@ -27,6 +30,7 @@ export function ItemRow(props: ItemRowProps) {
|
||||
"class",
|
||||
"disabled",
|
||||
"onClick",
|
||||
"handoff",
|
||||
"children",
|
||||
]);
|
||||
|
||||
@ -52,15 +56,21 @@ export function ItemRow(props: ItemRowProps) {
|
||||
class="bg-input flex-1 min-w-0 h-7 rounded-md p-1 pr-0 flex items-center gap-2 hover:bg-input/80 transition-colors relative cursor-default overflow-clip"
|
||||
onClick={handleClick}
|
||||
>
|
||||
<Show when={local.icon}>
|
||||
<div class="text-foreground size-5 rounded-sm flex items-center justify-center bg-primary overflow-clip">
|
||||
{local.icon}
|
||||
</div>
|
||||
</Show>
|
||||
{/* Opener only; the trailing action stays outside so it keeps normal dismissal. */}
|
||||
<div
|
||||
{...(local.handoff ? { "data-inspector-handoff": "" } : {})}
|
||||
class="flex flex-1 min-w-0 items-center gap-2 overflow-clip"
|
||||
>
|
||||
<Show when={local.icon}>
|
||||
<div class="text-foreground size-5 rounded-sm flex items-center justify-center bg-primary overflow-clip">
|
||||
{local.icon}
|
||||
</div>
|
||||
</Show>
|
||||
|
||||
<span class="flex-1 min-w-0 text-xs text-foreground truncate">
|
||||
{local.value}
|
||||
</span>
|
||||
<span class="flex-1 min-w-0 text-xs text-foreground truncate">
|
||||
{local.value}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{local.children}
|
||||
</div>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user