@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,103 @@
|
|
|
1
|
+
import type { ComponentProps, ReactNode } from "react";
|
|
2
|
+
declare const paths: {
|
|
3
|
+
readonly select: "m5 3 14 10-7 1-3 7Z";
|
|
4
|
+
readonly hand: "M8 12V6a2 2 0 0 1 4 0v5-7a2 2 0 0 1 4 0v8-5a2 2 0 0 1 4 0v7c0 5-3 8-7 8h-1c-3 0-5-2-7-5l-2-3a2 2 0 0 1 3-2l2 2";
|
|
5
|
+
readonly plus: "M12 5v14M5 12h14";
|
|
6
|
+
readonly close: "m6 6 12 12M6 18 18 6";
|
|
7
|
+
readonly search: "M21 21l-5-5M18 10a8 8 0 1 1-16 0 8 8 0 0 1 16 0";
|
|
8
|
+
readonly chevron: "m9 5 7 7-7 7";
|
|
9
|
+
readonly down: "m6 9 6 6 6-6";
|
|
10
|
+
readonly group: "M3 7V5h7l2 2h9v13H3Z";
|
|
11
|
+
readonly part: "M4 3h16v18H4ZM4 16l5-5 4 4 3-3 4 4M8 7h.01";
|
|
12
|
+
readonly mesh: "M3 4h18v16H3ZM3 4l9 8 9-8M3 20l9-8 9 8M12 12V4m0 8v8";
|
|
13
|
+
readonly composite: "m12 3 10 5-10 5L2 8Zm-10 9 10 5 10-5M2 16l10 5 10-5";
|
|
14
|
+
readonly response: "M2 17h3c3 0 3-13 6-13s3 13 6 9 3-3 5-3";
|
|
15
|
+
readonly eye: "M2 12s3-7 10-7 10 7 10 7-3 7-10 7S2 12 2 12Zm10-3a3 3 0 1 0 0 6 3 3 0 0 0 0-6";
|
|
16
|
+
readonly hidden: "m3 3 18 18M9 5a12 12 0 0 1 3 0c7 0 10 7 10 7a17 17 0 0 1-4 5M6 6a20 20 0 0 0-4 6s3 7 10 7a12 12 0 0 0 5-1";
|
|
17
|
+
readonly undo: "M3 10h11a6 6 0 0 1 0 12M3 10l5-5m-5 5 5 5";
|
|
18
|
+
readonly redo: "M21 10H10a6 6 0 0 0 0 12m11-12-5-5m5 5-5 5";
|
|
19
|
+
readonly save: "M5 3h12l4 4v14H3V3Zm2 0v6h10V3M7 21v-8h10v8";
|
|
20
|
+
readonly upload: "M12 16V3m-5 5 5-5 5 5M3 15v6h18v-6";
|
|
21
|
+
readonly download: "M12 3v13m-5-5 5 5 5-5M3 16v5h18v-5";
|
|
22
|
+
readonly fit: "M9 3H3v6m12-6h6v6M3 15v6h6m6 0h6v-6M8 8h8v8H8Z";
|
|
23
|
+
readonly minus: "M5 12h14";
|
|
24
|
+
readonly more: "M5 12h.01M12 12h.01M19 12h.01";
|
|
25
|
+
readonly check: "m5 12 4 4L19 6";
|
|
26
|
+
readonly warning: "m12 3 10 18H2Zm0 6v5m0 3h.01";
|
|
27
|
+
readonly trash: "M3 6h18M9 6V3h6v3M5 6l1 15h12l1-15M10 10v7m4-7v7";
|
|
28
|
+
readonly duplicate: "M8 8h13v13H8ZM16 8V3H3v13h5";
|
|
29
|
+
readonly settings: "M4 7h16M4 17h16M8 4v6m8 4v6";
|
|
30
|
+
readonly play: "m8 4 12 8-12 8Z";
|
|
31
|
+
readonly pause: "M8 4v16M16 4v16";
|
|
32
|
+
readonly reset: "M3 10a9 9 0 1 1 1 8M3 3v7h7";
|
|
33
|
+
readonly link: "m9 15 6-6m-7 3-3 3a4 4 0 0 0 6 6l3-3m-4-12 3-3a4 4 0 0 1 6 6l-3 3";
|
|
34
|
+
readonly key: "m12 4 8 8-8 8-8-8Z";
|
|
35
|
+
readonly code: "m8 6-6 6 6 6m8-12 6 6-6 6m-5 3 2-18";
|
|
36
|
+
readonly help: "M9 8a3 3 0 1 1 4 3c-1 1-1 2-1 3m0 3h.01M22 12a10 10 0 1 1-20 0 10 10 0 0 1 20 0";
|
|
37
|
+
readonly grid: "M3 3h18v18H3ZM3 9h18M3 15h18M9 3v18M15 3v18";
|
|
38
|
+
readonly panel: "M3 4h18v16H3ZM9 4v16";
|
|
39
|
+
readonly arrow: "M5 12h14m-5-5 5 5-5 5";
|
|
40
|
+
readonly pen: "m5 20 4-7 6-3 4-6M5 20h.01M9 13h.01M15 10h.01M19 4h.01";
|
|
41
|
+
readonly comment: "M4 5h16v11h-9l-5 4v-4H4Z";
|
|
42
|
+
readonly send: "M4 12 21 4l-6 17-3-7Zm8 2 4-5";
|
|
43
|
+
readonly spark: "M12 3l2 6 6 3-6 3-2 6-2-6-6-3 6-3Z";
|
|
44
|
+
readonly history: "M3 12a9 9 0 1 0 3-6.7L3 8m0-5v5h5m4-1v5l3 2";
|
|
45
|
+
readonly control: "M12 2v4m0 12v4M2 12h4m12 0h4m-10 0a2 2 0 1 0 4 0 2 2 0 0 0-4 0";
|
|
46
|
+
readonly face: "M22 12a10 10 0 1 1-20 0 10 10 0 0 1 20 0M8 14s1.5 2 4 2 4-2 4-2M9 9h.01M15 9h.01";
|
|
47
|
+
readonly film: "M3 4h18v16H3ZM7 4v16M17 4v16M3 9h4m-4 6h4m10-6h4m-4 6h4";
|
|
48
|
+
readonly stop: "M6 6h12v12H6Z";
|
|
49
|
+
};
|
|
50
|
+
export type IconName = keyof typeof paths;
|
|
51
|
+
export declare function Icon({ name, ...props }: {
|
|
52
|
+
name: IconName;
|
|
53
|
+
} & ComponentProps<"svg">): import("react").JSX.Element;
|
|
54
|
+
export declare function IconButton({ icon, label, children, ...props }: {
|
|
55
|
+
icon: IconName;
|
|
56
|
+
label: string;
|
|
57
|
+
} & ComponentProps<"button">): import("react").JSX.Element;
|
|
58
|
+
export declare function Field({ label, children, hint, }: {
|
|
59
|
+
label: string;
|
|
60
|
+
children: ReactNode;
|
|
61
|
+
hint?: string;
|
|
62
|
+
}): import("react").JSX.Element;
|
|
63
|
+
/** Clearing keeps focus in the search; an empty Escape belongs to its parent. */
|
|
64
|
+
export declare function SearchField({ label, placeholder, value, onValueChange, }: {
|
|
65
|
+
label: string;
|
|
66
|
+
placeholder: string;
|
|
67
|
+
value: string;
|
|
68
|
+
onValueChange: (value: string) => void;
|
|
69
|
+
}): import("react").JSX.Element;
|
|
70
|
+
export declare function NumberField({ label, value, onCommit, prefix, unit, min, max, step, ...props }: {
|
|
71
|
+
label: string;
|
|
72
|
+
value: number;
|
|
73
|
+
onCommit: (value: number) => void;
|
|
74
|
+
/** Axis or channel label before the value; physical units follow it. */
|
|
75
|
+
prefix?: string;
|
|
76
|
+
unit?: string;
|
|
77
|
+
min?: number;
|
|
78
|
+
max?: number;
|
|
79
|
+
} & Omit<ComponentProps<"input">, "value" | "onChange" | "type" | "min" | "max">): import("react").JSX.Element;
|
|
80
|
+
export declare function TextField({ label, value, onCommit, ...props }: {
|
|
81
|
+
label: string;
|
|
82
|
+
value: string;
|
|
83
|
+
onCommit: (value: string) => void;
|
|
84
|
+
} & Omit<ComponentProps<"input">, "value" | "onChange">): import("react").JSX.Element;
|
|
85
|
+
export declare function Disclosure({ title, children, defaultOpen, badge, ...props }: {
|
|
86
|
+
title: string;
|
|
87
|
+
children: ReactNode;
|
|
88
|
+
badge?: ReactNode;
|
|
89
|
+
defaultOpen?: boolean;
|
|
90
|
+
} & ComponentProps<"details">): import("react").JSX.Element;
|
|
91
|
+
export declare function EmptyState({ icon, title, children, }: {
|
|
92
|
+
icon?: IconName;
|
|
93
|
+
title: string;
|
|
94
|
+
children?: ReactNode;
|
|
95
|
+
}): import("react").JSX.Element;
|
|
96
|
+
export declare function Modal({ title, children, onClose, wide, }: {
|
|
97
|
+
title: string;
|
|
98
|
+
children: ReactNode;
|
|
99
|
+
onClose: () => void;
|
|
100
|
+
wide?: boolean;
|
|
101
|
+
}): import("react").JSX.Element;
|
|
102
|
+
export declare const round: (n: number) => number;
|
|
103
|
+
export {};
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/** Unstyled editor controls. Invalid numeric text never becomes a command. */
|
|
3
|
+
import { useEffect, useId, useRef, useState } from "react";
|
|
4
|
+
const paths = {
|
|
5
|
+
select: "m5 3 14 10-7 1-3 7Z",
|
|
6
|
+
hand: "M8 12V6a2 2 0 0 1 4 0v5-7a2 2 0 0 1 4 0v8-5a2 2 0 0 1 4 0v7c0 5-3 8-7 8h-1c-3 0-5-2-7-5l-2-3a2 2 0 0 1 3-2l2 2",
|
|
7
|
+
plus: "M12 5v14M5 12h14",
|
|
8
|
+
close: "m6 6 12 12M6 18 18 6",
|
|
9
|
+
search: "M21 21l-5-5M18 10a8 8 0 1 1-16 0 8 8 0 0 1 16 0",
|
|
10
|
+
chevron: "m9 5 7 7-7 7",
|
|
11
|
+
down: "m6 9 6 6 6-6",
|
|
12
|
+
group: "M3 7V5h7l2 2h9v13H3Z",
|
|
13
|
+
part: "M4 3h16v18H4ZM4 16l5-5 4 4 3-3 4 4M8 7h.01",
|
|
14
|
+
mesh: "M3 4h18v16H3ZM3 4l9 8 9-8M3 20l9-8 9 8M12 12V4m0 8v8",
|
|
15
|
+
composite: "m12 3 10 5-10 5L2 8Zm-10 9 10 5 10-5M2 16l10 5 10-5",
|
|
16
|
+
response: "M2 17h3c3 0 3-13 6-13s3 13 6 9 3-3 5-3",
|
|
17
|
+
eye: "M2 12s3-7 10-7 10 7 10 7-3 7-10 7S2 12 2 12Zm10-3a3 3 0 1 0 0 6 3 3 0 0 0 0-6",
|
|
18
|
+
hidden: "m3 3 18 18M9 5a12 12 0 0 1 3 0c7 0 10 7 10 7a17 17 0 0 1-4 5M6 6a20 20 0 0 0-4 6s3 7 10 7a12 12 0 0 0 5-1",
|
|
19
|
+
undo: "M3 10h11a6 6 0 0 1 0 12M3 10l5-5m-5 5 5 5",
|
|
20
|
+
redo: "M21 10H10a6 6 0 0 0 0 12m11-12-5-5m5 5-5 5",
|
|
21
|
+
save: "M5 3h12l4 4v14H3V3Zm2 0v6h10V3M7 21v-8h10v8",
|
|
22
|
+
upload: "M12 16V3m-5 5 5-5 5 5M3 15v6h18v-6",
|
|
23
|
+
download: "M12 3v13m-5-5 5 5 5-5M3 16v5h18v-5",
|
|
24
|
+
fit: "M9 3H3v6m12-6h6v6M3 15v6h6m6 0h6v-6M8 8h8v8H8Z",
|
|
25
|
+
minus: "M5 12h14",
|
|
26
|
+
more: "M5 12h.01M12 12h.01M19 12h.01",
|
|
27
|
+
check: "m5 12 4 4L19 6",
|
|
28
|
+
warning: "m12 3 10 18H2Zm0 6v5m0 3h.01",
|
|
29
|
+
trash: "M3 6h18M9 6V3h6v3M5 6l1 15h12l1-15M10 10v7m4-7v7",
|
|
30
|
+
duplicate: "M8 8h13v13H8ZM16 8V3H3v13h5",
|
|
31
|
+
settings: "M4 7h16M4 17h16M8 4v6m8 4v6",
|
|
32
|
+
play: "m8 4 12 8-12 8Z",
|
|
33
|
+
pause: "M8 4v16M16 4v16",
|
|
34
|
+
reset: "M3 10a9 9 0 1 1 1 8M3 3v7h7",
|
|
35
|
+
link: "m9 15 6-6m-7 3-3 3a4 4 0 0 0 6 6l3-3m-4-12 3-3a4 4 0 0 1 6 6l-3 3",
|
|
36
|
+
key: "m12 4 8 8-8 8-8-8Z",
|
|
37
|
+
code: "m8 6-6 6 6 6m8-12 6 6-6 6m-5 3 2-18",
|
|
38
|
+
help: "M9 8a3 3 0 1 1 4 3c-1 1-1 2-1 3m0 3h.01M22 12a10 10 0 1 1-20 0 10 10 0 0 1 20 0",
|
|
39
|
+
grid: "M3 3h18v18H3ZM3 9h18M3 15h18M9 3v18M15 3v18",
|
|
40
|
+
panel: "M3 4h18v16H3ZM9 4v16",
|
|
41
|
+
arrow: "M5 12h14m-5-5 5 5-5 5",
|
|
42
|
+
pen: "m5 20 4-7 6-3 4-6M5 20h.01M9 13h.01M15 10h.01M19 4h.01",
|
|
43
|
+
comment: "M4 5h16v11h-9l-5 4v-4H4Z",
|
|
44
|
+
send: "M4 12 21 4l-6 17-3-7Zm8 2 4-5",
|
|
45
|
+
spark: "M12 3l2 6 6 3-6 3-2 6-2-6-6-3 6-3Z",
|
|
46
|
+
history: "M3 12a9 9 0 1 0 3-6.7L3 8m0-5v5h5m4-1v5l3 2",
|
|
47
|
+
control: "M12 2v4m0 12v4M2 12h4m12 0h4m-10 0a2 2 0 1 0 4 0 2 2 0 0 0-4 0",
|
|
48
|
+
face: "M22 12a10 10 0 1 1-20 0 10 10 0 0 1 20 0M8 14s1.5 2 4 2 4-2 4-2M9 9h.01M15 9h.01",
|
|
49
|
+
film: "M3 4h18v16H3ZM7 4v16M17 4v16M3 9h4m-4 6h4m10-6h4m-4 6h4",
|
|
50
|
+
stop: "M6 6h12v12H6Z",
|
|
51
|
+
};
|
|
52
|
+
export function Icon({ name, ...props }) {
|
|
53
|
+
return (_jsx("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.6", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", ...props, children: _jsx("path", { d: paths[name] }) }));
|
|
54
|
+
}
|
|
55
|
+
export function IconButton({ icon, label, children, ...props }) {
|
|
56
|
+
return (_jsxs("button", { type: "button", "data-catchlight-icon-button": "", "aria-label": label, title: label, ...props, children: [_jsx(Icon, { name: icon }), children] }));
|
|
57
|
+
}
|
|
58
|
+
export function Field({ label, children, hint, }) {
|
|
59
|
+
return (_jsxs("div", { "data-catchlight-field": "", children: [_jsx("span", { "data-catchlight-field-label": "", children: label }), _jsx("div", { "data-catchlight-field-control": "", children: children }), hint && _jsx("small", { "data-catchlight-field-hint": "", children: hint })] }));
|
|
60
|
+
}
|
|
61
|
+
/** Clearing keeps focus in the search; an empty Escape belongs to its parent. */
|
|
62
|
+
export function SearchField({ label, placeholder, value, onValueChange, }) {
|
|
63
|
+
const input = useRef(null);
|
|
64
|
+
return (_jsxs("div", { "data-catchlight-search": "", children: [_jsx(Icon, { name: "search", width: "14", height: "14" }), _jsx("input", { ref: input, "aria-label": label, placeholder: placeholder, value: value, onChange: (event) => onValueChange(event.currentTarget.value), onKeyDown: (event) => {
|
|
65
|
+
if (event.key === "Escape" && value) {
|
|
66
|
+
event.preventDefault();
|
|
67
|
+
event.stopPropagation();
|
|
68
|
+
onValueChange("");
|
|
69
|
+
}
|
|
70
|
+
} }), value && (_jsx(IconButton, { icon: "close", label: `Clear ${label.toLocaleLowerCase()}`, onClick: () => {
|
|
71
|
+
onValueChange("");
|
|
72
|
+
input.current?.focus();
|
|
73
|
+
} }))] }));
|
|
74
|
+
}
|
|
75
|
+
export function NumberField({ label, value, onCommit, prefix, unit, min, max, step = "any", ...props }) {
|
|
76
|
+
const [draft, setDraft] = useState(String(round(value)));
|
|
77
|
+
const [editing, setEditing] = useState(false);
|
|
78
|
+
useEffect(() => {
|
|
79
|
+
if (!editing)
|
|
80
|
+
setDraft(String(round(value)));
|
|
81
|
+
}, [value, editing]);
|
|
82
|
+
const next = Number(draft);
|
|
83
|
+
const invalid = draft.trim() === "" ||
|
|
84
|
+
!Number.isFinite(next) ||
|
|
85
|
+
(Number(step) === 1 && !Number.isInteger(next)) ||
|
|
86
|
+
(min !== undefined && next < min) ||
|
|
87
|
+
(max !== undefined && next > max);
|
|
88
|
+
const commit = () => {
|
|
89
|
+
setEditing(false);
|
|
90
|
+
if (!invalid && next !== value)
|
|
91
|
+
onCommit(next);
|
|
92
|
+
else
|
|
93
|
+
setDraft(String(round(value)));
|
|
94
|
+
};
|
|
95
|
+
return (_jsxs("span", { "data-catchlight-number": "", "data-invalid": editing && invalid ? "" : undefined, children: [prefix && _jsx("span", { "data-catchlight-number-prefix": "", "aria-hidden": "true", children: prefix }), _jsx("input", { type: "number", inputMode: "decimal", "aria-label": label, "aria-invalid": editing && invalid, value: draft, min: min, max: max, step: step, onFocus: () => setEditing(true), onChange: (e) => setDraft(e.currentTarget.value), onBlur: commit, onKeyDown: (e) => {
|
|
96
|
+
if (e.key === "Enter") {
|
|
97
|
+
e.preventDefault();
|
|
98
|
+
e.currentTarget.blur();
|
|
99
|
+
}
|
|
100
|
+
if (e.key === "Escape") {
|
|
101
|
+
setDraft(String(round(value)));
|
|
102
|
+
setEditing(false);
|
|
103
|
+
e.preventDefault();
|
|
104
|
+
e.stopPropagation();
|
|
105
|
+
}
|
|
106
|
+
}, ...props }), unit && _jsx("span", { "data-catchlight-number-unit": "", "aria-hidden": "true", children: unit })] }));
|
|
107
|
+
}
|
|
108
|
+
export function TextField({ label, value, onCommit, ...props }) {
|
|
109
|
+
const [draft, setDraft] = useState(value);
|
|
110
|
+
useEffect(() => setDraft(value), [value]);
|
|
111
|
+
return (_jsx("input", { type: "text", "aria-label": label, value: draft, onChange: (e) => setDraft(e.currentTarget.value), onBlur: () => {
|
|
112
|
+
if (draft.trim() && draft !== value)
|
|
113
|
+
onCommit(draft.trim());
|
|
114
|
+
else
|
|
115
|
+
setDraft(value);
|
|
116
|
+
}, onKeyDown: (e) => {
|
|
117
|
+
if (e.key === "Enter")
|
|
118
|
+
e.currentTarget.blur();
|
|
119
|
+
if (e.key === "Escape") {
|
|
120
|
+
setDraft(value);
|
|
121
|
+
e.stopPropagation();
|
|
122
|
+
}
|
|
123
|
+
}, ...props }));
|
|
124
|
+
}
|
|
125
|
+
export function Disclosure({ title, children, defaultOpen = true, badge, ...props }) {
|
|
126
|
+
return (_jsxs("details", { "data-catchlight-disclosure": "", open: defaultOpen, ...props, children: [_jsxs("summary", { children: [_jsx(Icon, { name: "chevron" }), _jsx("span", { children: title }), badge] }), _jsx("div", { "data-catchlight-disclosure-body": "", children: children })] }));
|
|
127
|
+
}
|
|
128
|
+
export function EmptyState({ icon = "select", title, children, }) {
|
|
129
|
+
return (_jsxs("div", { "data-catchlight-empty-state": "", children: [_jsx(Icon, { name: icon, width: "28", height: "28" }), _jsx("strong", { children: title }), children && _jsx("p", { children: children })] }));
|
|
130
|
+
}
|
|
131
|
+
export function Modal({ title, children, onClose, wide = false, }) {
|
|
132
|
+
const ref = useRef(null);
|
|
133
|
+
const id = useId();
|
|
134
|
+
const close = useRef(onClose);
|
|
135
|
+
close.current = onClose;
|
|
136
|
+
useEffect(() => {
|
|
137
|
+
const dialog = ref.current;
|
|
138
|
+
if (!dialog)
|
|
139
|
+
return;
|
|
140
|
+
const before = document.activeElement;
|
|
141
|
+
dialog.showModal?.();
|
|
142
|
+
return () => {
|
|
143
|
+
dialog.close?.();
|
|
144
|
+
if (before instanceof HTMLElement && before.isConnected)
|
|
145
|
+
before.focus();
|
|
146
|
+
};
|
|
147
|
+
}, []);
|
|
148
|
+
return (_jsxs("dialog", { ref: ref, "data-catchlight-dialog": "", "data-wide": wide ? "" : undefined, "aria-labelledby": id, "aria-modal": "true", onCancel: (e) => {
|
|
149
|
+
e.preventDefault();
|
|
150
|
+
close.current();
|
|
151
|
+
}, onClick: (e) => {
|
|
152
|
+
if (e.target === e.currentTarget) {
|
|
153
|
+
const r = e.currentTarget.getBoundingClientRect();
|
|
154
|
+
if (e.clientX < r.left ||
|
|
155
|
+
e.clientX > r.right ||
|
|
156
|
+
e.clientY < r.top ||
|
|
157
|
+
e.clientY > r.bottom)
|
|
158
|
+
close.current();
|
|
159
|
+
}
|
|
160
|
+
}, children: [_jsxs("header", { children: [_jsx("h2", { id: id, children: title }), _jsx(IconButton, { icon: "close", label: "Close dialog", onClick: onClose })] }), _jsx("div", { "data-catchlight-dialog-body": "", children: children })] }));
|
|
161
|
+
}
|
|
162
|
+
export const round = (n) => Math.round(n * 1000) / 1000;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/** Only a mesh draft and an armed recording destination live in React state.
|
|
2
|
+
* Every route out of a dirty draft goes through the same finish dialog. */
|
|
3
|
+
import { MeshDraft, RecordingGesture } from "@catchlight/editor-core";
|
|
4
|
+
import type { MeshDraftView, ParamId, RecordProperties, RecordingTarget, Session } from "@catchlight/editor-core";
|
|
5
|
+
import type { ReactNode } from "react";
|
|
6
|
+
import type { ErrorHandler } from "./authoring.js";
|
|
7
|
+
export type EditingMode = "arrange" | "mesh" | "record";
|
|
8
|
+
export type RecordingTool = "shape" | "transform";
|
|
9
|
+
declare function useEditingController(session: Session | undefined, onError: ErrorHandler, onNotice: (s: string) => void): {
|
|
10
|
+
session: Session | undefined;
|
|
11
|
+
revision: number;
|
|
12
|
+
mode: EditingMode;
|
|
13
|
+
requestMode: (next: EditingMode) => void;
|
|
14
|
+
guard: (action: () => void) => void;
|
|
15
|
+
node: string | undefined;
|
|
16
|
+
info: import("@catchlight/editor-core").NodeInfo | undefined;
|
|
17
|
+
params: import("@catchlight/editor-core").ParamInfo[];
|
|
18
|
+
bindings: import("@catchlight/editor-core").BindingInfo[];
|
|
19
|
+
param: string | undefined;
|
|
20
|
+
selectParam: (id: ParamId) => void;
|
|
21
|
+
primary: import("@catchlight/editor-core").ParamInfo | undefined;
|
|
22
|
+
secondary: import("@catchlight/editor-core").ParamInfo | undefined;
|
|
23
|
+
pair: [string, string] | undefined;
|
|
24
|
+
pairChoices: [string, string][];
|
|
25
|
+
setPair: (next: [string, string]) => void;
|
|
26
|
+
x: number | undefined;
|
|
27
|
+
y: number | undefined;
|
|
28
|
+
xValue: number;
|
|
29
|
+
yValue: number;
|
|
30
|
+
target: RecordingTarget | undefined;
|
|
31
|
+
relevant: import("@catchlight/editor-core").BindingInfo[];
|
|
32
|
+
authored: boolean;
|
|
33
|
+
recording: boolean;
|
|
34
|
+
arm: () => void;
|
|
35
|
+
stop: () => void;
|
|
36
|
+
recordTool: RecordingTool;
|
|
37
|
+
setRecordTool: (next: RecordingTool) => void;
|
|
38
|
+
xPositions: number[];
|
|
39
|
+
yPositions: number[];
|
|
40
|
+
keyAuthored: (at: [number, number]) => boolean;
|
|
41
|
+
selectCell: (cx: number, cy?: number) => void;
|
|
42
|
+
beginRecording: () => RecordingGesture | undefined;
|
|
43
|
+
runGesture: (gesture: RecordingGesture, commit: () => Promise<void>) => Promise<void>;
|
|
44
|
+
patch: (fields: RecordProperties, authoredBasis?: boolean) => Promise<void>;
|
|
45
|
+
keyAction: (action: "neutral" | "clear") => Promise<void>;
|
|
46
|
+
posed: RecordProperties | undefined;
|
|
47
|
+
busy: boolean;
|
|
48
|
+
mesh: MeshDraftView | undefined;
|
|
49
|
+
meshSelection: number[];
|
|
50
|
+
setMeshSelection: import("react").Dispatch<import("react").SetStateAction<number[]>>;
|
|
51
|
+
meshTool: "add" | "move" | "connect";
|
|
52
|
+
setMeshTool: import("react").Dispatch<import("react").SetStateAction<"add" | "move" | "connect">>;
|
|
53
|
+
meshError: string | undefined;
|
|
54
|
+
stale: boolean;
|
|
55
|
+
meshAction: (action: (d: MeshDraft) => void) => void;
|
|
56
|
+
moveMesh: (selectedIndices: number[], delta: [number, number]) => void;
|
|
57
|
+
applyMesh: (then?: () => void) => Promise<void>;
|
|
58
|
+
discardMesh: () => void;
|
|
59
|
+
reloadMesh: () => void;
|
|
60
|
+
emptiedSlots: string[];
|
|
61
|
+
pending: (() => void) | undefined;
|
|
62
|
+
setPending: import("react").Dispatch<import("react").SetStateAction<(() => void) | undefined>>;
|
|
63
|
+
};
|
|
64
|
+
export type Editing = ReturnType<typeof useEditingController>;
|
|
65
|
+
export declare function useEditing(): {
|
|
66
|
+
session: Session | undefined;
|
|
67
|
+
revision: number;
|
|
68
|
+
mode: EditingMode;
|
|
69
|
+
requestMode: (next: EditingMode) => void;
|
|
70
|
+
guard: (action: () => void) => void;
|
|
71
|
+
node: string | undefined;
|
|
72
|
+
info: import("@catchlight/editor-core").NodeInfo | undefined;
|
|
73
|
+
params: import("@catchlight/editor-core").ParamInfo[];
|
|
74
|
+
bindings: import("@catchlight/editor-core").BindingInfo[];
|
|
75
|
+
param: string | undefined;
|
|
76
|
+
selectParam: (id: ParamId) => void;
|
|
77
|
+
primary: import("@catchlight/editor-core").ParamInfo | undefined;
|
|
78
|
+
secondary: import("@catchlight/editor-core").ParamInfo | undefined;
|
|
79
|
+
pair: [string, string] | undefined;
|
|
80
|
+
pairChoices: [string, string][];
|
|
81
|
+
setPair: (next: [string, string]) => void;
|
|
82
|
+
x: number | undefined;
|
|
83
|
+
y: number | undefined;
|
|
84
|
+
xValue: number;
|
|
85
|
+
yValue: number;
|
|
86
|
+
target: RecordingTarget | undefined;
|
|
87
|
+
relevant: import("@catchlight/editor-core").BindingInfo[];
|
|
88
|
+
authored: boolean;
|
|
89
|
+
recording: boolean;
|
|
90
|
+
arm: () => void;
|
|
91
|
+
stop: () => void;
|
|
92
|
+
recordTool: RecordingTool;
|
|
93
|
+
setRecordTool: (next: RecordingTool) => void;
|
|
94
|
+
xPositions: number[];
|
|
95
|
+
yPositions: number[];
|
|
96
|
+
keyAuthored: (at: [number, number]) => boolean;
|
|
97
|
+
selectCell: (cx: number, cy?: number) => void;
|
|
98
|
+
beginRecording: () => RecordingGesture | undefined;
|
|
99
|
+
runGesture: (gesture: RecordingGesture, commit: () => Promise<void>) => Promise<void>;
|
|
100
|
+
patch: (fields: RecordProperties, authoredBasis?: boolean) => Promise<void>;
|
|
101
|
+
keyAction: (action: "neutral" | "clear") => Promise<void>;
|
|
102
|
+
posed: RecordProperties | undefined;
|
|
103
|
+
busy: boolean;
|
|
104
|
+
mesh: MeshDraftView | undefined;
|
|
105
|
+
meshSelection: number[];
|
|
106
|
+
setMeshSelection: import("react").Dispatch<import("react").SetStateAction<number[]>>;
|
|
107
|
+
meshTool: "add" | "move" | "connect";
|
|
108
|
+
setMeshTool: import("react").Dispatch<import("react").SetStateAction<"add" | "move" | "connect">>;
|
|
109
|
+
meshError: string | undefined;
|
|
110
|
+
stale: boolean;
|
|
111
|
+
meshAction: (action: (d: MeshDraft) => void) => void;
|
|
112
|
+
moveMesh: (selectedIndices: number[], delta: [number, number]) => void;
|
|
113
|
+
applyMesh: (then?: () => void) => Promise<void>;
|
|
114
|
+
discardMesh: () => void;
|
|
115
|
+
reloadMesh: () => void;
|
|
116
|
+
emptiedSlots: string[];
|
|
117
|
+
pending: (() => void) | undefined;
|
|
118
|
+
setPending: import("react").Dispatch<import("react").SetStateAction<(() => void) | undefined>>;
|
|
119
|
+
} | undefined;
|
|
120
|
+
export declare function EditingProvider({ session, onError, onNotice, children, }: {
|
|
121
|
+
session: Session | undefined;
|
|
122
|
+
onError: ErrorHandler;
|
|
123
|
+
onNotice: (s: string) => void;
|
|
124
|
+
children: ReactNode;
|
|
125
|
+
}): import("react").JSX.Element;
|
|
126
|
+
export {};
|