@catchlight/editor-web 0.0.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE-APACHE +201 -0
- package/LICENSE-MIT +21 -0
- package/README.md +26 -2
- package/THIRD-PARTY-NOTICES.md +331 -0
- package/dist/editor/CatchlightEditor.d.ts +21 -0
- package/dist/editor/CatchlightEditor.js +720 -0
- package/dist/editor/dialogs.d.ts +18 -0
- package/dist/editor/dialogs.js +71 -0
- package/dist/editor/import-panel.d.ts +6 -0
- package/dist/editor/import-panel.js +98 -0
- package/dist/editor/logo.svg +11 -0
- package/dist/editor/notification.d.ts +4 -0
- package/dist/editor/notification.js +24 -0
- package/dist/editor/stage.d.ts +13 -0
- package/dist/editor/stage.js +24 -0
- package/dist/editor/test/setup.d.ts +5 -0
- package/dist/editor/test/setup.js +5 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +10 -0
- package/dist/lib/animations-panel.d.ts +10 -0
- package/dist/lib/animations-panel.js +48 -0
- package/dist/lib/authoring.d.ts +17 -0
- package/dist/lib/authoring.js +116 -0
- package/dist/lib/binding-grid.d.ts +19 -0
- package/dist/lib/binding-grid.js +92 -0
- package/dist/lib/bindings.d.ts +21 -0
- package/dist/lib/bindings.js +100 -0
- package/dist/lib/camera.d.ts +21 -0
- package/dist/lib/camera.js +61 -0
- package/dist/lib/controls-panel.d.ts +36 -0
- package/dist/lib/controls-panel.js +201 -0
- package/dist/lib/controls.d.ts +103 -0
- package/dist/lib/controls.js +162 -0
- package/dist/lib/editing.d.ts +126 -0
- package/dist/lib/editing.js +415 -0
- package/dist/lib/editor-context.d.ts +9 -0
- package/dist/lib/editor-context.js +13 -0
- package/dist/lib/expressions-panel.d.ts +10 -0
- package/dist/lib/expressions-panel.js +120 -0
- package/dist/lib/file-open.d.ts +11 -0
- package/dist/lib/file-open.js +25 -0
- package/dist/lib/file-save.d.ts +29 -0
- package/dist/lib/file-save.js +68 -0
- package/dist/lib/gizmo.d.ts +13 -0
- package/dist/lib/gizmo.js +247 -0
- package/dist/lib/image-markup.d.ts +12 -0
- package/dist/lib/image-markup.js +153 -0
- package/dist/lib/index.d.ts +71 -0
- package/dist/lib/index.js +44 -0
- package/dist/lib/inspector.d.ts +19 -0
- package/dist/lib/inspector.js +161 -0
- package/dist/lib/latest.d.ts +3 -0
- package/dist/lib/latest.js +9 -0
- package/dist/lib/layer-import.d.ts +38 -0
- package/dist/lib/layer-import.js +187 -0
- package/dist/lib/mesh-editor.d.ts +13 -0
- package/dist/lib/mesh-editor.js +337 -0
- package/dist/lib/model-panels.d.ts +23 -0
- package/dist/lib/model-panels.js +180 -0
- package/dist/lib/node-actions.d.ts +42 -0
- package/dist/lib/node-actions.js +115 -0
- package/dist/lib/node-drag.d.ts +18 -0
- package/dist/lib/node-drag.js +65 -0
- package/dist/lib/node-patch.d.ts +8 -0
- package/dist/lib/node-patch.js +10 -0
- package/dist/lib/node-tree.d.ts +36 -0
- package/dist/lib/node-tree.js +221 -0
- package/dist/lib/official.d.ts +82 -0
- package/dist/lib/official.js +197 -0
- package/dist/lib/param-actions.d.ts +48 -0
- package/dist/lib/param-actions.js +106 -0
- package/dist/lib/param-list.d.ts +36 -0
- package/dist/lib/param-list.js +73 -0
- package/dist/lib/param-slider.d.ts +44 -0
- package/dist/lib/param-slider.js +149 -0
- package/dist/lib/pose.d.ts +13 -0
- package/dist/lib/pose.js +32 -0
- package/dist/lib/posing-panel.d.ts +40 -0
- package/dist/lib/posing-panel.js +154 -0
- package/dist/lib/presence.d.ts +27 -0
- package/dist/lib/presence.js +98 -0
- package/dist/lib/properties-panel.d.ts +13 -0
- package/dist/lib/properties-panel.js +63 -0
- package/dist/lib/recording-panel.d.ts +4 -0
- package/dist/lib/recording-panel.js +161 -0
- package/dist/lib/replica.d.ts +18 -0
- package/dist/lib/replica.js +34 -0
- package/dist/lib/review.d.ts +113 -0
- package/dist/lib/review.js +529 -0
- package/dist/lib/rigging.d.ts +10 -0
- package/dist/lib/rigging.js +116 -0
- package/dist/lib/selection.d.ts +3 -0
- package/dist/lib/selection.js +2 -0
- package/dist/lib/session-list.d.ts +16 -0
- package/dist/lib/session-list.js +7 -0
- package/dist/lib/sessions.d.ts +8 -0
- package/dist/lib/sessions.js +29 -0
- package/dist/lib/test/harness.d.ts +32 -0
- package/dist/lib/test/harness.js +139 -0
- package/dist/lib/test/setup.d.ts +4 -0
- package/dist/lib/test/setup.js +5 -0
- package/dist/lib/versions.d.ts +69 -0
- package/dist/lib/versions.js +250 -0
- package/dist/lib/viewport.d.ts +57 -0
- package/dist/lib/viewport.js +315 -0
- package/dist/lib/workspace-layout.d.ts +24 -0
- package/dist/lib/workspace-layout.js +145 -0
- package/dist/lib/workspace.d.ts +29 -0
- package/dist/lib/workspace.js +263 -0
- package/dist/theme.css +4573 -0
- package/package.json +32 -6
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tree edits as commands. Indices are read from the replica at call time, not
|
|
3
|
+
* captured, since another client may have reordered the tree since render.
|
|
4
|
+
*/
|
|
5
|
+
import { useMemo } from "react";
|
|
6
|
+
import { useLatest } from "./latest.js";
|
|
7
|
+
import { useSelection } from "./selection.js";
|
|
8
|
+
/** Must sit under a `<SelectionProvider>`: deleting the selected node clears the selection. */
|
|
9
|
+
export function useNodeActions(session) {
|
|
10
|
+
// Boxed so a selection change does not rebuild every callback.
|
|
11
|
+
const selection = useLatest(useSelection());
|
|
12
|
+
return useMemo(() => ({
|
|
13
|
+
async addChild(parent, kind, name) {
|
|
14
|
+
const body = await session.send({
|
|
15
|
+
cmd: "node_add",
|
|
16
|
+
parent,
|
|
17
|
+
kind,
|
|
18
|
+
name: name ?? null,
|
|
19
|
+
});
|
|
20
|
+
if (body.result !== "node") {
|
|
21
|
+
throw new Error(`node_add answered ${body.result}, not the node it added`);
|
|
22
|
+
}
|
|
23
|
+
return body.node;
|
|
24
|
+
},
|
|
25
|
+
async remove(node) {
|
|
26
|
+
// Asked before the delete: afterwards the tree cannot answer it.
|
|
27
|
+
const held = subtreeHolds(findNode(session.tree(), node), selection.current.node);
|
|
28
|
+
const body = await session.send({ cmd: "node_delete", node });
|
|
29
|
+
if (held)
|
|
30
|
+
selection.current.select(undefined);
|
|
31
|
+
return body;
|
|
32
|
+
},
|
|
33
|
+
duplicate: (node) => session.send({ cmd: "node_duplicate", node }),
|
|
34
|
+
rename: (node, name) => session.send({ cmd: "node_set", node, name }),
|
|
35
|
+
setEnabled: (node, enabled) => session.send({ cmd: "node_set", node, enabled }),
|
|
36
|
+
move: (node, parent, index) => session.send({ cmd: "edit_apply", if_rev: session.getRevision(), edits: [
|
|
37
|
+
{ op: "node_reparent", node, to: parent },
|
|
38
|
+
{ op: "node_reorder", node, index },
|
|
39
|
+
] }),
|
|
40
|
+
moveUp(node) {
|
|
41
|
+
const at = siblingIndex(session.tree(), node);
|
|
42
|
+
if (!at || at.index === 0)
|
|
43
|
+
return NOTHING();
|
|
44
|
+
return session.send({ cmd: "node_reorder", node, index: at.index - 1 });
|
|
45
|
+
},
|
|
46
|
+
moveDown(node) {
|
|
47
|
+
const at = siblingIndex(session.tree(), node);
|
|
48
|
+
if (!at || at.index >= at.parent.children.length - 1)
|
|
49
|
+
return NOTHING();
|
|
50
|
+
return session.send({ cmd: "node_reorder", node, index: at.index + 1 });
|
|
51
|
+
},
|
|
52
|
+
}), [session, selection]);
|
|
53
|
+
}
|
|
54
|
+
export function findNode(tree, node) {
|
|
55
|
+
if (tree.id === node)
|
|
56
|
+
return tree;
|
|
57
|
+
for (const child of tree.children) {
|
|
58
|
+
const found = findNode(child, node);
|
|
59
|
+
if (found)
|
|
60
|
+
return found;
|
|
61
|
+
}
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
/** `undefined` for the root and for a node the tree does not carry. */
|
|
65
|
+
export function siblingIndex(tree, node) {
|
|
66
|
+
const index = tree.children.findIndex((child) => child.id === node);
|
|
67
|
+
if (index >= 0)
|
|
68
|
+
return { parent: tree, index };
|
|
69
|
+
for (const child of tree.children) {
|
|
70
|
+
const found = siblingIndex(child, node);
|
|
71
|
+
if (found)
|
|
72
|
+
return found;
|
|
73
|
+
}
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
/** Whether `node` is `held`'s subtree root or anywhere inside it. */
|
|
77
|
+
export function subtreeHolds(held, node) {
|
|
78
|
+
if (!held || node === undefined)
|
|
79
|
+
return false;
|
|
80
|
+
return findNode(held, node) !== undefined;
|
|
81
|
+
}
|
|
82
|
+
/** Every Id in this subtree, its own included — what a drop may not land on. */
|
|
83
|
+
export function subtreeIds(tree) {
|
|
84
|
+
const ids = new Set();
|
|
85
|
+
const walk = (node) => {
|
|
86
|
+
ids.add(node.id);
|
|
87
|
+
for (const child of node.children)
|
|
88
|
+
walk(child);
|
|
89
|
+
};
|
|
90
|
+
walk(tree);
|
|
91
|
+
return ids;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* A drop beside a row counts the target's siblings with the dragged node
|
|
95
|
+
* already removed, the list the model reinserts into. `undefined` for a drop
|
|
96
|
+
* onto the node itself, into its own subtree, or beside the root.
|
|
97
|
+
*/
|
|
98
|
+
export function dropIndex(tree, node, target, where) {
|
|
99
|
+
const dragged = findNode(tree, node);
|
|
100
|
+
if (!dragged || subtreeHolds(dragged, target))
|
|
101
|
+
return undefined;
|
|
102
|
+
if (where === "into") {
|
|
103
|
+
const parent = findNode(tree, target);
|
|
104
|
+
return parent ? { parent: target, index: parent.children.length } : undefined;
|
|
105
|
+
}
|
|
106
|
+
const at = siblingIndex(tree, target);
|
|
107
|
+
if (!at)
|
|
108
|
+
return undefined;
|
|
109
|
+
const siblings = at.parent.children.filter((child) => child.id !== node);
|
|
110
|
+
const index = siblings.findIndex((child) => child.id === target);
|
|
111
|
+
if (index < 0)
|
|
112
|
+
return undefined;
|
|
113
|
+
return { parent: at.parent.id, index: where === "before" ? index : index + 1 };
|
|
114
|
+
}
|
|
115
|
+
const NOTHING = () => Promise.resolve({ result: "empty" });
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node-drag handlers to spread onto the viewport. A world delta goes to Rust,
|
|
3
|
+
* which resolves the parent's frame. The scratch preview is cleared only once
|
|
4
|
+
* the commit's revision lands (or the send is refused), so the node does not
|
|
5
|
+
* snap back during the round trip. With no session, every handler is a no-op.
|
|
6
|
+
*/
|
|
7
|
+
import type { NodeId, Session } from "@catchlight/editor-core";
|
|
8
|
+
import type { ViewportPointerEvent } from "./viewport.js";
|
|
9
|
+
export interface NodeDrag {
|
|
10
|
+
handlers: {
|
|
11
|
+
onPointerDown: (event: ViewportPointerEvent) => void;
|
|
12
|
+
onPointerMove: (event: ViewportPointerEvent) => void;
|
|
13
|
+
onPointerUp: (event: ViewportPointerEvent) => void;
|
|
14
|
+
onPointerCancel: (event: ViewportPointerEvent) => void;
|
|
15
|
+
};
|
|
16
|
+
dragging: boolean;
|
|
17
|
+
}
|
|
18
|
+
export declare function useNodeDrag(session: Session | undefined, node: NodeId | undefined): NodeDrag;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node-drag handlers to spread onto the viewport. A world delta goes to Rust,
|
|
3
|
+
* which resolves the parent's frame. The scratch preview is cleared only once
|
|
4
|
+
* the commit's revision lands (or the send is refused), so the node does not
|
|
5
|
+
* snap back during the round trip. With no session, every handler is a no-op.
|
|
6
|
+
*/
|
|
7
|
+
import { useCallback, useRef, useState } from "react";
|
|
8
|
+
export function useNodeDrag(session, node) {
|
|
9
|
+
const [dragging, setDragging] = useState(false);
|
|
10
|
+
const drag = useRef(undefined);
|
|
11
|
+
const onPointerDown = useCallback(({ world, event }) => {
|
|
12
|
+
if (!session || node === undefined || event.button !== 0)
|
|
13
|
+
return;
|
|
14
|
+
drag.current = { pointerId: event.pointerId, node, from: world, translate: undefined };
|
|
15
|
+
setDragging(true);
|
|
16
|
+
}, [session, node]);
|
|
17
|
+
const onPointerMove = useCallback(({ world, event }) => {
|
|
18
|
+
const active = drag.current;
|
|
19
|
+
if (!active || active.pointerId !== event.pointerId || !session)
|
|
20
|
+
return;
|
|
21
|
+
const moved = session.translationAfterWorldDelta(active.node, world[0] - active.from[0], world[1] - active.from[1]);
|
|
22
|
+
if (!moved)
|
|
23
|
+
return;
|
|
24
|
+
active.translate = moved;
|
|
25
|
+
session.scratchTransform(active.node, { translate: moved });
|
|
26
|
+
}, [session]);
|
|
27
|
+
const onPointerUp = useCallback(({ event }) => {
|
|
28
|
+
const active = drag.current;
|
|
29
|
+
if (!active || active.pointerId !== event.pointerId)
|
|
30
|
+
return;
|
|
31
|
+
drag.current = undefined;
|
|
32
|
+
setDragging(false);
|
|
33
|
+
if (!session)
|
|
34
|
+
return;
|
|
35
|
+
const translate = active.translate;
|
|
36
|
+
if (!translate) {
|
|
37
|
+
// A click with no movement must not create an undo entry.
|
|
38
|
+
session.clearScratchTransform(active.node);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
void (async () => {
|
|
42
|
+
try {
|
|
43
|
+
await session.send({ cmd: "node_set", node: active.node, translate });
|
|
44
|
+
}
|
|
45
|
+
catch (cause) {
|
|
46
|
+
console.warn("catchlight: committing the drag failed", cause);
|
|
47
|
+
}
|
|
48
|
+
finally {
|
|
49
|
+
session.clearScratchTransform(active.node);
|
|
50
|
+
}
|
|
51
|
+
})();
|
|
52
|
+
}, [session]);
|
|
53
|
+
const onPointerCancel = useCallback(({ event }) => {
|
|
54
|
+
const active = drag.current;
|
|
55
|
+
if (!active || active.pointerId !== event.pointerId)
|
|
56
|
+
return;
|
|
57
|
+
drag.current = undefined;
|
|
58
|
+
setDragging(false);
|
|
59
|
+
session?.clearScratchTransform(active.node);
|
|
60
|
+
}, [session]);
|
|
61
|
+
return {
|
|
62
|
+
handlers: { onPointerDown, onPointerMove, onPointerUp, onPointerCancel },
|
|
63
|
+
dragging,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node field authoring. Only the given fields are sent: extra fields would
|
|
3
|
+
* join the same undo entry and be silently restored by undo.
|
|
4
|
+
*/
|
|
5
|
+
import type { NodeId, NodePatch, Session } from "@catchlight/editor-core";
|
|
6
|
+
/** Resolves once the replica can answer for `fields`. */
|
|
7
|
+
export type NodePatchFn = (node: NodeId, fields: NodePatch) => Promise<void>;
|
|
8
|
+
export declare function useNodePatch(session: Session): NodePatchFn;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node field authoring. Only the given fields are sent: extra fields would
|
|
3
|
+
* join the same undo entry and be silently restored by undo.
|
|
4
|
+
*/
|
|
5
|
+
import { useCallback } from "react";
|
|
6
|
+
export function useNodePatch(session) {
|
|
7
|
+
return useCallback(async (node, fields) => {
|
|
8
|
+
await session.send({ cmd: "node_set", node, ...fields });
|
|
9
|
+
}, [session]);
|
|
10
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The node tree as an ARIA tree, and its editing panel. State is exposed as
|
|
3
|
+
* data attributes (`data-selected`, `data-kind`, `data-drop`).
|
|
4
|
+
*
|
|
5
|
+
* The dragged node is module state: `dataTransfer` cannot be read during
|
|
6
|
+
* `dragover`, and React state would re-render every row on the way past.
|
|
7
|
+
*/
|
|
8
|
+
import type { NodeKindArg, Session, TreeNode } from "@catchlight/editor-core";
|
|
9
|
+
import type { ComponentProps } from "react";
|
|
10
|
+
export declare const NODE_KINDS: readonly NodeKindArg[];
|
|
11
|
+
type ErrorSink = ((cause: unknown) => void) | undefined;
|
|
12
|
+
export interface NodeTreeRootProps extends Omit<ComponentProps<"ul">, "children" | "onError"> {
|
|
13
|
+
session: Session;
|
|
14
|
+
onError?: ErrorSink;
|
|
15
|
+
filter?: string;
|
|
16
|
+
}
|
|
17
|
+
export declare function NodeTreeRoot({ session, onError, filter, ...rest }: NodeTreeRootProps): import("react").JSX.Element;
|
|
18
|
+
export interface NodeTreeItemProps extends Omit<ComponentProps<"li">, "children" | "onError"> {
|
|
19
|
+
session: Session;
|
|
20
|
+
node: TreeNode;
|
|
21
|
+
/** The one node that cannot be dragged, dropped beside, or deleted. */
|
|
22
|
+
isRoot?: boolean | undefined;
|
|
23
|
+
onError?: ErrorSink;
|
|
24
|
+
}
|
|
25
|
+
export declare function NodeTreeItem({ session, node, isRoot, onError, ...rest }: NodeTreeItemProps): import("react").JSX.Element;
|
|
26
|
+
export interface NodeTreeActionsProps extends Omit<ComponentProps<"div">, "children" | "onError"> {
|
|
27
|
+
session: Session;
|
|
28
|
+
onError?: ErrorSink;
|
|
29
|
+
}
|
|
30
|
+
export declare function NodeTreeActions({ session, onError, ...rest }: NodeTreeActionsProps): import("react").JSX.Element;
|
|
31
|
+
export declare const NodeTree: {
|
|
32
|
+
Root: typeof NodeTreeRoot;
|
|
33
|
+
Item: typeof NodeTreeItem;
|
|
34
|
+
Actions: typeof NodeTreeActions;
|
|
35
|
+
};
|
|
36
|
+
export {};
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useContext, useState } from "react";
|
|
3
|
+
import { dropIndex, findNode, siblingIndex, subtreeIds, useNodeActions } from "./node-actions.js";
|
|
4
|
+
import { useTree } from "./replica.js";
|
|
5
|
+
import { useSelection } from "./selection.js";
|
|
6
|
+
import { Icon } from "./controls.js";
|
|
7
|
+
import { kindIcons, kindLabels } from "./authoring.js";
|
|
8
|
+
import { ReviewBadge } from "./review.js";
|
|
9
|
+
export const NODE_KINDS = ["group", "part", "composite", "mesh_group"];
|
|
10
|
+
const TreeDisclosureContext = createContext(undefined);
|
|
11
|
+
function setCollapsed(current, node, expanded) {
|
|
12
|
+
const next = new Set(current);
|
|
13
|
+
if (expanded)
|
|
14
|
+
next.delete(node);
|
|
15
|
+
else
|
|
16
|
+
next.add(node);
|
|
17
|
+
return next;
|
|
18
|
+
}
|
|
19
|
+
export function NodeTreeRoot({ session, onError, filter = "", ...rest }) {
|
|
20
|
+
const root = useTree(session);
|
|
21
|
+
const needle = filter.trim().toLocaleLowerCase();
|
|
22
|
+
const [collapsed, updateCollapsed] = useState(() => new Set());
|
|
23
|
+
const [search, setSearch] = useState({ needle: "", collapsed: new Set() });
|
|
24
|
+
if (search.needle !== needle)
|
|
25
|
+
setSearch({ needle, collapsed: new Set() });
|
|
26
|
+
const visible = needle ? new Set() : undefined;
|
|
27
|
+
const matching = (node, parentMatches = false) => {
|
|
28
|
+
const matches = parentMatches || node.name.toLocaleLowerCase().includes(needle);
|
|
29
|
+
let found = matches;
|
|
30
|
+
for (const child of node.children) {
|
|
31
|
+
if (matching(child, matches))
|
|
32
|
+
found = true;
|
|
33
|
+
}
|
|
34
|
+
if (found)
|
|
35
|
+
visible?.add(node.id);
|
|
36
|
+
return found;
|
|
37
|
+
};
|
|
38
|
+
if (visible)
|
|
39
|
+
matching(root);
|
|
40
|
+
// Search disclosures belong to one query; ordinary expansion survives hidden rows.
|
|
41
|
+
const currentCollapsed = needle
|
|
42
|
+
? search.needle === needle
|
|
43
|
+
? search.collapsed
|
|
44
|
+
: new Set()
|
|
45
|
+
: collapsed;
|
|
46
|
+
const setExpanded = (node, expanded) => {
|
|
47
|
+
if (needle) {
|
|
48
|
+
setSearch((current) => ({
|
|
49
|
+
needle,
|
|
50
|
+
collapsed: setCollapsed(current.needle === needle ? current.collapsed : new Set(), node, expanded),
|
|
51
|
+
}));
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
updateCollapsed((current) => setCollapsed(current, node, expanded));
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
return (_jsx(TreeDisclosureContext, { value: { visible, collapsed: currentCollapsed, setExpanded }, children: _jsx("ul", { role: "tree", "aria-label": "Model structure", "data-catchlight-node-tree": "", ...rest, children: !visible || visible.has(root.id) ? (_jsx(NodeTreeItem, { session: session, node: root, isRoot: true, onError: onError })) : (_jsx("li", { "data-catchlight-empty": "", children: "No matching nodes." })) }) }));
|
|
58
|
+
}
|
|
59
|
+
export function NodeTreeItem({ session, node, isRoot, onError, ...rest }) {
|
|
60
|
+
const { node: selected, select } = useSelection();
|
|
61
|
+
const actions = useNodeActions(session);
|
|
62
|
+
const [drop, setDrop] = useState(undefined);
|
|
63
|
+
const [renaming, setRenaming] = useState(false);
|
|
64
|
+
const disclosure = useContext(TreeDisclosureContext);
|
|
65
|
+
const [localExpanded, setLocalExpanded] = useState(true);
|
|
66
|
+
const expanded = disclosure ? !disclosure.collapsed.has(node.id) : localExpanded;
|
|
67
|
+
const setExpanded = (next) => {
|
|
68
|
+
if (disclosure)
|
|
69
|
+
disclosure.setExpanded(node.id, next);
|
|
70
|
+
else
|
|
71
|
+
setLocalExpanded(next);
|
|
72
|
+
};
|
|
73
|
+
const children = disclosure?.visible
|
|
74
|
+
? node.children.filter((child) => disclosure.visible?.has(child.id))
|
|
75
|
+
: node.children;
|
|
76
|
+
const isSelected = selected === node.id;
|
|
77
|
+
const onDragStart = (event) => {
|
|
78
|
+
if (isRoot)
|
|
79
|
+
return;
|
|
80
|
+
dragging = { node: node.id, subtree: subtreeIds(node) };
|
|
81
|
+
event.dataTransfer?.setData("text/plain", node.id);
|
|
82
|
+
if (event.dataTransfer)
|
|
83
|
+
event.dataTransfer.effectAllowed = "move";
|
|
84
|
+
};
|
|
85
|
+
const onDragEnd = () => {
|
|
86
|
+
dragging = undefined;
|
|
87
|
+
setDrop(undefined);
|
|
88
|
+
};
|
|
89
|
+
const onDragOver = (event) => {
|
|
90
|
+
const where = placement(event, node.id, isRoot === true);
|
|
91
|
+
setDrop(where);
|
|
92
|
+
if (where === undefined)
|
|
93
|
+
return;
|
|
94
|
+
// Only a prevented `dragover` makes an element a drop target at all.
|
|
95
|
+
event.preventDefault();
|
|
96
|
+
event.stopPropagation();
|
|
97
|
+
if (event.dataTransfer)
|
|
98
|
+
event.dataTransfer.dropEffect = "move";
|
|
99
|
+
};
|
|
100
|
+
const onDragLeave = (event) => {
|
|
101
|
+
// Crossing into the checkbox or the label is not leaving the row.
|
|
102
|
+
const to = event.relatedTarget;
|
|
103
|
+
if (to instanceof Node && event.currentTarget.contains(to))
|
|
104
|
+
return;
|
|
105
|
+
setDrop(undefined);
|
|
106
|
+
};
|
|
107
|
+
const onDrop = (event) => {
|
|
108
|
+
const where = placement(event, node.id, isRoot === true);
|
|
109
|
+
const source = dragging?.node;
|
|
110
|
+
dragging = undefined;
|
|
111
|
+
setDrop(undefined);
|
|
112
|
+
if (where === undefined || source === undefined)
|
|
113
|
+
return;
|
|
114
|
+
event.preventDefault();
|
|
115
|
+
event.stopPropagation();
|
|
116
|
+
const landing = dropIndex(session.tree(), source, node.id, where);
|
|
117
|
+
if (!landing)
|
|
118
|
+
return;
|
|
119
|
+
report(onError, actions.move(source, landing.parent, landing.index));
|
|
120
|
+
};
|
|
121
|
+
const commitRename = (value) => {
|
|
122
|
+
setRenaming(false);
|
|
123
|
+
const name = value.trim();
|
|
124
|
+
if (name === "" || name === node.name)
|
|
125
|
+
return;
|
|
126
|
+
report(onError, actions.rename(node.id, name));
|
|
127
|
+
};
|
|
128
|
+
return (_jsxs("li", { role: "treeitem", "aria-selected": isSelected, "aria-expanded": children.length ? expanded : undefined, "data-catchlight-node": "", "data-node": node.id, "data-kind": node.kind, "data-selected": isSelected ? "" : undefined, "data-drop": drop, ...rest, children: [_jsxs("div", { "data-catchlight-node-row": "", draggable: isRoot ? undefined : true, onDragStart: onDragStart, onDragEnd: onDragEnd, onDragOver: onDragOver, onDragLeave: onDragLeave, onDrop: onDrop, children: [children.length ? (_jsx("button", { type: "button", "data-catchlight-disclosure-toggle": "", "aria-label": `${expanded ? "Collapse" : "Expand"} ${node.name}`, onClick: () => setExpanded(!expanded), children: _jsx(Icon, { name: expanded ? "down" : "chevron", width: "12", height: "12" }) })) : (_jsx("span", { "data-catchlight-disclosure-spacer": "" })), _jsx("span", { "data-catchlight-kind-icon": "", title: kindLabels[node.kind], children: _jsx(Icon, { name: kindIcons[node.kind], width: "16", height: "16" }) }), _jsxs("label", { "data-catchlight-visibility": "", title: node.enabled ? "Hide node" : "Show node", children: [_jsx("input", { type: "checkbox", "data-catchlight-node-enabled": "", "aria-label": `${node.name} enabled`, checked: node.enabled, onChange: (event) => report(onError, actions.setEnabled(node.id, event.currentTarget.checked)) }), _jsx(Icon, { name: node.enabled ? "eye" : "hidden", width: "15", height: "15" })] }), renaming ? (_jsx(NodeRename, { name: node.name, onCommit: commitRename, onCancel: () => setRenaming(false) })) : (_jsx("button", { type: "button", "data-catchlight-node-label": "", onClick: () => select(node.id), onDoubleClick: () => setRenaming(true), onKeyDown: (event) => {
|
|
129
|
+
if (event.key === "F2") {
|
|
130
|
+
event.preventDefault();
|
|
131
|
+
setRenaming(true);
|
|
132
|
+
}
|
|
133
|
+
if (event.key === "ArrowRight") {
|
|
134
|
+
event.preventDefault();
|
|
135
|
+
setExpanded(true);
|
|
136
|
+
}
|
|
137
|
+
if (event.key === "ArrowLeft") {
|
|
138
|
+
event.preventDefault();
|
|
139
|
+
setExpanded(false);
|
|
140
|
+
}
|
|
141
|
+
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
142
|
+
event.preventDefault();
|
|
143
|
+
const tree = event.currentTarget.closest('[role="tree"]');
|
|
144
|
+
const rows = [
|
|
145
|
+
...(tree?.querySelectorAll("[data-catchlight-node-label]") ??
|
|
146
|
+
[]),
|
|
147
|
+
];
|
|
148
|
+
const at = rows.indexOf(event.currentTarget);
|
|
149
|
+
rows[at + (event.key === "ArrowDown" ? 1 : -1)]?.focus();
|
|
150
|
+
}
|
|
151
|
+
}, children: node.name })), _jsx(ReviewBadge, { target: { kind: "node", node: node.id }, label: node.name })] }), children.length > 0 && expanded && (_jsx("ul", { role: "group", children: children.map((child) => (_jsx(NodeTreeItem, { session: session, node: child, onError: onError }, child.id))) }))] }));
|
|
152
|
+
}
|
|
153
|
+
// Uncontrolled and mounted fresh, since `defaultValue` is read only once.
|
|
154
|
+
function NodeRename({ name, onCommit, onCancel, }) {
|
|
155
|
+
// Escape unmounts the input, and a blur must not then commit what Escape
|
|
156
|
+
// just threw away.
|
|
157
|
+
const [cancelled, setCancelled] = useState(false);
|
|
158
|
+
const onKeyDown = (event) => {
|
|
159
|
+
if (event.key === "Enter") {
|
|
160
|
+
event.preventDefault();
|
|
161
|
+
onCommit(event.currentTarget.value);
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
if (event.key !== "Escape")
|
|
165
|
+
return;
|
|
166
|
+
event.preventDefault();
|
|
167
|
+
setCancelled(true);
|
|
168
|
+
onCancel();
|
|
169
|
+
};
|
|
170
|
+
return (_jsx("input", { type: "text", "data-catchlight-node-rename": "", "aria-label": `rename ${name}`, defaultValue: name, autoFocus: true, onKeyDown: onKeyDown, onBlur: (event) => {
|
|
171
|
+
if (!cancelled)
|
|
172
|
+
onCommit(event.currentTarget.value);
|
|
173
|
+
} }));
|
|
174
|
+
}
|
|
175
|
+
export function NodeTreeActions({ session, onError, ...rest }) {
|
|
176
|
+
const tree = useTree(session);
|
|
177
|
+
const { node: selected, select } = useSelection();
|
|
178
|
+
const actions = useNodeActions(session);
|
|
179
|
+
const [kind, setKind] = useState("group");
|
|
180
|
+
// A stale selection adds under the root rather than failing.
|
|
181
|
+
const target = selected !== undefined && findNode(tree, selected) ? selected : tree.id;
|
|
182
|
+
const at = selected === undefined ? undefined : siblingIndex(tree, selected);
|
|
183
|
+
const movable = at !== undefined;
|
|
184
|
+
const add = () => {
|
|
185
|
+
report(onError, actions.addChild(target, kind).then((added) => {
|
|
186
|
+
select(added);
|
|
187
|
+
}));
|
|
188
|
+
};
|
|
189
|
+
return (_jsxs("div", { "data-catchlight-node-actions": "", ...rest, children: [_jsx("select", { "data-catchlight-node-kind": "", "aria-label": "node kind", value: kind, onChange: (event) => setKind(event.currentTarget.value), children: NODE_KINDS.map((each) => (_jsx("option", { value: each, children: each }, each))) }), _jsx("button", { type: "button", "data-catchlight-node-add": "", onClick: add, children: "Add" }), _jsx("button", { type: "button", "data-catchlight-node-delete": "", disabled: !movable, onClick: () => selected !== undefined && report(onError, actions.remove(selected)), children: "Delete" }), _jsx("button", { type: "button", "data-catchlight-node-duplicate": "", disabled: !movable, onClick: () => selected !== undefined && report(onError, actions.duplicate(selected)), children: "Duplicate" }), _jsx("button", { type: "button", "data-catchlight-node-up": "", disabled: !at || at.index === 0, onClick: () => selected !== undefined && report(onError, actions.moveUp(selected)), children: "Up" }), _jsx("button", { type: "button", "data-catchlight-node-down": "", disabled: !at || at.index >= at.parent.children.length - 1, onClick: () => selected !== undefined && report(onError, actions.moveDown(selected)), children: "Down" })] }));
|
|
190
|
+
}
|
|
191
|
+
export const NodeTree = {
|
|
192
|
+
Root: NodeTreeRoot,
|
|
193
|
+
Item: NodeTreeItem,
|
|
194
|
+
Actions: NodeTreeActions,
|
|
195
|
+
};
|
|
196
|
+
let dragging;
|
|
197
|
+
/** Outer quarters insert beside the row, the middle half inside; `undefined` if the row cannot take the drag. */
|
|
198
|
+
function placement(event, node, isRoot) {
|
|
199
|
+
const drag = dragging;
|
|
200
|
+
if (!drag || drag.subtree.has(node))
|
|
201
|
+
return undefined;
|
|
202
|
+
if (isRoot)
|
|
203
|
+
return "into";
|
|
204
|
+
const box = event.currentTarget.getBoundingClientRect();
|
|
205
|
+
if (box.height <= 0)
|
|
206
|
+
return "into";
|
|
207
|
+
const at = (event.clientY - box.top) / box.height;
|
|
208
|
+
if (at < 0.25)
|
|
209
|
+
return "before";
|
|
210
|
+
if (at > 0.75)
|
|
211
|
+
return "after";
|
|
212
|
+
return "into";
|
|
213
|
+
}
|
|
214
|
+
function report(onError, work) {
|
|
215
|
+
void work.catch((cause) => {
|
|
216
|
+
if (onError)
|
|
217
|
+
onError(cause);
|
|
218
|
+
else
|
|
219
|
+
console.warn("catchlight: the tree edit failed", cause);
|
|
220
|
+
});
|
|
221
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { ExtensionWarningInfo, ParamId, Playing, LiveInputs, ResponseBody, Session, SessionEditCommand, SessionReplicaQueryCommand } from "@catchlight/editor-core";
|
|
2
|
+
import type { ErrorHandler } from "./authoring.js";
|
|
3
|
+
export declare const HUMANOID = "catchlight.humanoid";
|
|
4
|
+
export declare const EXPRESSIONS = "catchlight.expressions";
|
|
5
|
+
export declare const ANIMATIONS = "catchlight.animations";
|
|
6
|
+
/** A read of one official extension, or why this build cannot read its data. */
|
|
7
|
+
export type OfficialRead<R extends ResponseBody["result"]> = {
|
|
8
|
+
body: Extract<ResponseBody, {
|
|
9
|
+
result: R;
|
|
10
|
+
}>;
|
|
11
|
+
unread?: undefined;
|
|
12
|
+
} | {
|
|
13
|
+
body?: undefined;
|
|
14
|
+
unread: string;
|
|
15
|
+
};
|
|
16
|
+
export declare function useOfficialRead<R extends ResponseBody["result"]>(session: Session, command: SessionReplicaQueryCommand, result: R): OfficialRead<R>;
|
|
17
|
+
export declare function useHumanoid(session: Session): OfficialRead<"humanoid">;
|
|
18
|
+
export declare function useExpressions(session: Session): OfficialRead<"expressions">;
|
|
19
|
+
export declare function useClips(session: Session): OfficialRead<"clips">;
|
|
20
|
+
/** The findings about the extension under `key`, and the params they concern. */
|
|
21
|
+
export declare function useExtensionWarnings(session: Session, key: string): {
|
|
22
|
+
warnings: ExtensionWarningInfo[];
|
|
23
|
+
params: Map<string, string[]>;
|
|
24
|
+
};
|
|
25
|
+
/** The messages of the warnings about any of `params`; empty when none. */
|
|
26
|
+
export declare function warningsOn(warned: Map<ParamId, string[]>, params: Iterable<ParamId>): string[];
|
|
27
|
+
export declare function useLiveInputs(session: Session): LiveInputs;
|
|
28
|
+
/** The name of the clip that plays; `undefined` when none does. */
|
|
29
|
+
export declare function usePlayingClip(session: Session | undefined): string | undefined;
|
|
30
|
+
/** Where the playing clip is, updated every frame while it plays. */
|
|
31
|
+
export declare function usePlayhead(session: Session): Playing | undefined;
|
|
32
|
+
type Nonstandard = Extract<SessionEditCommand, {
|
|
33
|
+
nonstandard: boolean;
|
|
34
|
+
}>;
|
|
35
|
+
/**
|
|
36
|
+
* Edits that may name a control, or key a zone or landmark, outside the
|
|
37
|
+
* humanoid standard. A refusal for
|
|
38
|
+
* that waits in `asking` until the person keeps the name (resent with
|
|
39
|
+
* `nonstandard`) or cancels; every other failure goes to `onError`.
|
|
40
|
+
*/
|
|
41
|
+
export declare function useOfficialCommand(session: Session, onError: ErrorHandler): {
|
|
42
|
+
run: (command: SessionEditCommand, done?: () => void) => Promise<ResponseBody | undefined>;
|
|
43
|
+
busy: boolean;
|
|
44
|
+
asking: {
|
|
45
|
+
command: Nonstandard;
|
|
46
|
+
code: string;
|
|
47
|
+
message: string;
|
|
48
|
+
done?: () => void;
|
|
49
|
+
} | undefined;
|
|
50
|
+
keep: () => void;
|
|
51
|
+
dismiss: () => void;
|
|
52
|
+
};
|
|
53
|
+
export declare function NonstandardDialog({ asking, onKeep, onCancel, }: {
|
|
54
|
+
asking: {
|
|
55
|
+
code: string;
|
|
56
|
+
message: string;
|
|
57
|
+
} | undefined;
|
|
58
|
+
onKeep: () => void;
|
|
59
|
+
onCancel: () => void;
|
|
60
|
+
}): import("react").JSX.Element | null;
|
|
61
|
+
/**
|
|
62
|
+
* In the style of the Model tab's health list. Folded when there are more
|
|
63
|
+
* than two, so a model with many findings still shows its rows.
|
|
64
|
+
*/
|
|
65
|
+
export declare function ExtensionWarnings({ warnings }: {
|
|
66
|
+
warnings: ExtensionWarningInfo[];
|
|
67
|
+
}): import("react").JSX.Element | null;
|
|
68
|
+
export declare function UnreadNotice({ what, why }: {
|
|
69
|
+
what: string;
|
|
70
|
+
why: string;
|
|
71
|
+
}): import("react").JSX.Element;
|
|
72
|
+
export declare function capitalize(text: string): string;
|
|
73
|
+
export declare function plural(count: number, one: string, many?: string): string;
|
|
74
|
+
/** A question mark whose tooltip explains what sits beside it. */
|
|
75
|
+
export declare function HelpMark({ text }: {
|
|
76
|
+
text: string;
|
|
77
|
+
}): import("react").JSX.Element;
|
|
78
|
+
/** Marks a card or row that a warning concerns; the messages are its label. */
|
|
79
|
+
export declare function WarningMark({ warnings }: {
|
|
80
|
+
warnings: string[];
|
|
81
|
+
}): import("react").JSX.Element | null;
|
|
82
|
+
export {};
|