@catchlight/editor-web 0.0.0 → 0.6.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.
Files changed (111) hide show
  1. package/LICENSE-APACHE +201 -0
  2. package/LICENSE-MIT +21 -0
  3. package/README.md +26 -2
  4. package/THIRD-PARTY-NOTICES.md +331 -0
  5. package/dist/editor/CatchlightEditor.d.ts +21 -0
  6. package/dist/editor/CatchlightEditor.js +720 -0
  7. package/dist/editor/dialogs.d.ts +18 -0
  8. package/dist/editor/dialogs.js +71 -0
  9. package/dist/editor/import-panel.d.ts +6 -0
  10. package/dist/editor/import-panel.js +98 -0
  11. package/dist/editor/logo.svg +11 -0
  12. package/dist/editor/notification.d.ts +4 -0
  13. package/dist/editor/notification.js +24 -0
  14. package/dist/editor/stage.d.ts +13 -0
  15. package/dist/editor/stage.js +23 -0
  16. package/dist/editor/test/setup.d.ts +5 -0
  17. package/dist/editor/test/setup.js +5 -0
  18. package/dist/index.d.ts +11 -0
  19. package/dist/index.js +10 -0
  20. package/dist/lib/animations-panel.d.ts +10 -0
  21. package/dist/lib/animations-panel.js +48 -0
  22. package/dist/lib/authoring.d.ts +17 -0
  23. package/dist/lib/authoring.js +116 -0
  24. package/dist/lib/binding-grid.d.ts +19 -0
  25. package/dist/lib/binding-grid.js +92 -0
  26. package/dist/lib/bindings.d.ts +21 -0
  27. package/dist/lib/bindings.js +100 -0
  28. package/dist/lib/camera.d.ts +21 -0
  29. package/dist/lib/camera.js +61 -0
  30. package/dist/lib/controls-panel.d.ts +36 -0
  31. package/dist/lib/controls-panel.js +201 -0
  32. package/dist/lib/controls.d.ts +103 -0
  33. package/dist/lib/controls.js +163 -0
  34. package/dist/lib/editing.d.ts +126 -0
  35. package/dist/lib/editing.js +415 -0
  36. package/dist/lib/editor-context.d.ts +15 -0
  37. package/dist/lib/editor-context.js +23 -0
  38. package/dist/lib/expressions-panel.d.ts +10 -0
  39. package/dist/lib/expressions-panel.js +120 -0
  40. package/dist/lib/file-open.d.ts +11 -0
  41. package/dist/lib/file-open.js +25 -0
  42. package/dist/lib/file-save.d.ts +29 -0
  43. package/dist/lib/file-save.js +68 -0
  44. package/dist/lib/gizmo.d.ts +13 -0
  45. package/dist/lib/gizmo.js +247 -0
  46. package/dist/lib/image-markup.d.ts +12 -0
  47. package/dist/lib/image-markup.js +153 -0
  48. package/dist/lib/index.d.ts +71 -0
  49. package/dist/lib/index.js +44 -0
  50. package/dist/lib/inspector.d.ts +19 -0
  51. package/dist/lib/inspector.js +161 -0
  52. package/dist/lib/latest.d.ts +3 -0
  53. package/dist/lib/latest.js +9 -0
  54. package/dist/lib/layer-import.d.ts +38 -0
  55. package/dist/lib/layer-import.js +187 -0
  56. package/dist/lib/mesh-editor.d.ts +13 -0
  57. package/dist/lib/mesh-editor.js +337 -0
  58. package/dist/lib/model-panels.d.ts +23 -0
  59. package/dist/lib/model-panels.js +180 -0
  60. package/dist/lib/node-actions.d.ts +42 -0
  61. package/dist/lib/node-actions.js +115 -0
  62. package/dist/lib/node-drag.d.ts +18 -0
  63. package/dist/lib/node-drag.js +65 -0
  64. package/dist/lib/node-patch.d.ts +8 -0
  65. package/dist/lib/node-patch.js +10 -0
  66. package/dist/lib/node-tree.d.ts +36 -0
  67. package/dist/lib/node-tree.js +221 -0
  68. package/dist/lib/official.d.ts +82 -0
  69. package/dist/lib/official.js +197 -0
  70. package/dist/lib/param-actions.d.ts +48 -0
  71. package/dist/lib/param-actions.js +106 -0
  72. package/dist/lib/param-list.d.ts +36 -0
  73. package/dist/lib/param-list.js +73 -0
  74. package/dist/lib/param-slider.d.ts +44 -0
  75. package/dist/lib/param-slider.js +149 -0
  76. package/dist/lib/pose.d.ts +13 -0
  77. package/dist/lib/pose.js +32 -0
  78. package/dist/lib/posing-panel.d.ts +40 -0
  79. package/dist/lib/posing-panel.js +154 -0
  80. package/dist/lib/presence.d.ts +27 -0
  81. package/dist/lib/presence.js +98 -0
  82. package/dist/lib/properties-panel.d.ts +13 -0
  83. package/dist/lib/properties-panel.js +63 -0
  84. package/dist/lib/recording-panel.d.ts +4 -0
  85. package/dist/lib/recording-panel.js +161 -0
  86. package/dist/lib/replica.d.ts +18 -0
  87. package/dist/lib/replica.js +34 -0
  88. package/dist/lib/review.d.ts +113 -0
  89. package/dist/lib/review.js +529 -0
  90. package/dist/lib/rigging.d.ts +10 -0
  91. package/dist/lib/rigging.js +116 -0
  92. package/dist/lib/selection.d.ts +3 -0
  93. package/dist/lib/selection.js +2 -0
  94. package/dist/lib/session-list.d.ts +16 -0
  95. package/dist/lib/session-list.js +7 -0
  96. package/dist/lib/sessions.d.ts +8 -0
  97. package/dist/lib/sessions.js +29 -0
  98. package/dist/lib/test/harness.d.ts +32 -0
  99. package/dist/lib/test/harness.js +139 -0
  100. package/dist/lib/test/setup.d.ts +4 -0
  101. package/dist/lib/test/setup.js +5 -0
  102. package/dist/lib/versions.d.ts +69 -0
  103. package/dist/lib/versions.js +250 -0
  104. package/dist/lib/viewport.d.ts +57 -0
  105. package/dist/lib/viewport.js +315 -0
  106. package/dist/lib/workspace-layout.d.ts +24 -0
  107. package/dist/lib/workspace-layout.js +145 -0
  108. package/dist/lib/workspace.d.ts +29 -0
  109. package/dist/lib/workspace.js +263 -0
  110. package/dist/theme.css +4577 -0
  111. package/package.json +32 -6
@@ -0,0 +1,116 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState } from "react";
3
+ import { Disclosure, EmptyState, Field, Icon, NumberField, } from "./controls.js";
4
+ import { flattenTree, useCommand } from "./authoring.js";
5
+ import { useReplica } from "./replica.js";
6
+ import { useEditing } from "./editing.js";
7
+ export function MeshPanel({ session, info, onError }) {
8
+ const editing = useEditing();
9
+ const { run, busy } = useCommand(session, onError);
10
+ const [mode, setMode] = useState("contour");
11
+ const [spacing, setSpacing] = useState(32);
12
+ const [margin, setMargin] = useState(4);
13
+ const [cols, setCols] = useState(6);
14
+ const [rows, setRows] = useState(8);
15
+ if (info.vertex_count == null)
16
+ return null;
17
+ return (_jsxs(Disclosure, { title: "Mesh", badge: _jsxs("span", { "data-catchlight-badge": "", children: [info.vertex_count, " vertices"] }), children: [_jsxs("div", { "data-catchlight-metrics": "", children: [_jsxs("span", { children: [_jsx("b", { children: info.vertex_count }), " vertices"] }), _jsxs("span", { children: [_jsx("b", { children: info.triangle_count }), " triangles"] })] }), editing && info.kind === "part" && (_jsxs("button", { type: "button", "data-catchlight-action": "", disabled: !info.texture, onClick: () => editing.requestMode("mesh"), children: [_jsx(Icon, { name: "mesh" }), "Edit mesh on artwork\u2026"] })), info.kind === "part" && !editing && (_jsxs("fieldset", { disabled: busy || !info.texture, children: [_jsx(Field, { label: "Generate", children: _jsxs("select", { "aria-label": "Mesh method", value: mode, onChange: (e) => setMode(e.currentTarget.value), children: [_jsx("option", { value: "contour", children: "Trace artwork" }), _jsx("option", { value: "grid", children: "Regular grid" })] }) }), mode === "contour" ? (_jsxs(_Fragment, { children: [_jsx(Field, { label: "Spacing", children: _jsx(NumberField, { label: "Mesh spacing", value: spacing, min: 1, max: 4096, step: 1, unit: "px", onCommit: setSpacing }) }), _jsx(Field, { label: "Margin", children: _jsx(NumberField, { label: "Mesh margin", value: margin, min: 0, max: 128, step: 1, unit: "px", onCommit: setMargin }) })] })) : (_jsxs(Field, { label: "Grid size", children: [_jsx(NumberField, { label: "Mesh columns", value: cols, min: 2, max: 128, step: 1, prefix: "C", onCommit: setCols }), _jsx(NumberField, { label: "Mesh rows", value: rows, min: 2, max: 128, step: 1, prefix: "R", onCommit: setRows })] })), _jsxs("button", { type: "button", "data-catchlight-action": "", onClick: () => void run({
18
+ cmd: "mesh_generate",
19
+ node: info.id,
20
+ mode: mode === "contour"
21
+ ? { mode, spacing, margin }
22
+ : { mode, cols, rows },
23
+ }), children: [_jsx(Icon, { name: "mesh" }), busy ? "Generating…" : "Generate mesh"] }), _jsx("p", { "data-catchlight-hint": "", children: "Refits existing deforms. Filled slots will need to be assigned again." })] })), info.kind === "part" && !info.texture && (_jsx("p", { "data-catchlight-hint": "", children: "Add artwork to generate a mesh from its silhouette." }))] }));
24
+ }
25
+ export function RiggingEmpty() {
26
+ return (_jsx(EmptyState, { icon: "response", title: "No motion response selected", children: "Select a motion response node to edit its parameters." }));
27
+ }
28
+ export function MotionResponsePanel(props) {
29
+ const response = props.info.motion_response;
30
+ return response ? _jsx(ResponseFields, { ...props, response: response }) : null;
31
+ }
32
+ function ResponseFields({ session, info, onError, response, }) {
33
+ const { run, busy } = useCommand(session, onError);
34
+ const { sources, outputCandidates } = useReplica(session, (s) => {
35
+ const nodes = flattenTree(s.tree());
36
+ const poseInputs = new Set();
37
+ for (const node of nodes) {
38
+ if (node.kind !== "motion_response")
39
+ continue;
40
+ const driver = s.nodeInfo(node.id)?.motion_response;
41
+ if (!driver)
42
+ continue;
43
+ for (const { source } of driver.inputs) {
44
+ if (source.kind === "pose_param")
45
+ poseInputs.add(source.param);
46
+ }
47
+ }
48
+ const params = s.params();
49
+ const choices = params
50
+ .filter((p) => !p.driven_by)
51
+ .map((p) => ({
52
+ label: p.name,
53
+ source: { kind: "pose_param", param: p.id },
54
+ }));
55
+ for (const part of nodes.filter((node) => node.kind === "part")) {
56
+ const body = s.query({ cmd: "slot_list", node: part.id });
57
+ if (body.result !== "slots")
58
+ continue;
59
+ for (const slot of body.slots) {
60
+ choices.push({
61
+ label: part.name + " / " + slot.id,
62
+ source: {
63
+ kind: "part_slot",
64
+ part: part.id,
65
+ slot: slot.id,
66
+ angle_deg: 0,
67
+ reference_length: 100,
68
+ },
69
+ });
70
+ }
71
+ }
72
+ const outputCandidates = params
73
+ .filter((p) => p.default === 0 && !poseInputs.has(p.id))
74
+ .map((p) => ({ param: p, owner: p.driven_by }));
75
+ return { sources: choices, outputCandidates };
76
+ });
77
+ const choices = info.parent && session.nodeInfo(info.parent)?.motion_response
78
+ ? [
79
+ { label: "Parent response", source: { kind: "parent" } },
80
+ ...sources,
81
+ ]
82
+ : sources;
83
+ const set = (patch) => void run({
84
+ cmd: "motion_response_set",
85
+ node: info.id,
86
+ response: { ...response, ...patch },
87
+ });
88
+ const setInput = (i, input) => set({
89
+ inputs: response.inputs.map((current, j) => (j === i ? input : current)),
90
+ });
91
+ const sourceKey = (s) => s.kind === "parent"
92
+ ? "parent"
93
+ : JSON.stringify(s.kind === "pose_param" ? [s.param] : [s.part, s.slot]);
94
+ return (_jsx("fieldset", { disabled: busy, children: _jsxs(Disclosure, { title: "Motion response", children: [_jsx(Field, { label: "Period", children: _jsx(NumberField, { label: "Period", value: response.period_s, min: 0.001, step: 0.01, unit: "s", onCommit: (period_s) => set({ period_s }) }) }), _jsx(Field, { label: "Damping ratio", children: _jsx(NumberField, { label: "Damping ratio", value: response.damping_ratio, min: 0.001, step: 0.01, onCommit: (damping_ratio) => set({ damping_ratio }) }) }), _jsx(Field, { label: "Output", children: _jsxs("select", { "aria-label": "Response output", value: response.output_param ?? "", onChange: (e) => set({ output_param: e.currentTarget.value || null }), children: [_jsx("option", { value: "", children: "No art output" }), outputCandidates
95
+ .filter(({ owner }) => !owner || owner === info.id)
96
+ .map(({ param: p }) => (_jsx("option", { value: p.id, children: p.name }, p.id)))] }) }), response.inputs.map((input, i) => {
97
+ const { source } = input;
98
+ return (_jsxs("div", { children: [_jsx(Field, { label: "Input", children: _jsx("select", { "aria-label": `Input ${i + 1}`, value: sourceKey(source), onChange: (e) => {
99
+ const next = choices.find((c) => sourceKey(c.source) === e.currentTarget.value);
100
+ if (next)
101
+ setInput(i, { ...input, source: next.source });
102
+ }, children: choices.map((c) => (_jsx("option", { value: sourceKey(c.source), children: c.label }, sourceKey(c.source)))) }) }), _jsx(Field, { label: "Gain", children: _jsx(NumberField, { label: `Input ${i + 1} gain`, value: input.gain, step: 0.01, onCommit: (gain) => setInput(i, { ...input, gain }) }) }), source.kind === "part_slot" && (_jsxs(_Fragment, { children: [_jsx(Field, { label: "Angle", children: _jsx(NumberField, { label: "Projection angle", value: source.angle_deg, unit: "\u00B0", onCommit: (angle_deg) => setInput(i, {
103
+ ...input,
104
+ source: { ...source, angle_deg },
105
+ }) }) }), _jsx(Field, { label: "Reference length", children: _jsx(NumberField, { label: "Reference length", value: source.reference_length, min: 0.001, onCommit: (reference_length) => setInput(i, {
106
+ ...input,
107
+ source: { ...source, reference_length },
108
+ }) }) })] })), _jsx("button", { type: "button", onClick: () => set({ inputs: response.inputs.filter((_, j) => i !== j) }), children: "Remove input" })] }, i));
109
+ }), _jsxs("select", { "aria-label": "Add response input", value: "", onChange: (e) => {
110
+ const next = choices.find((c) => sourceKey(c.source) === e.currentTarget.value);
111
+ if (next)
112
+ set({
113
+ inputs: [...response.inputs, { source: next.source, gain: 1 }],
114
+ });
115
+ }, children: [_jsx("option", { value: "", children: "Add input\u2026" }), choices.map((c) => (_jsx("option", { value: sourceKey(c.source), children: c.label }, sourceKey(c.source))))] })] }) }));
116
+ }
@@ -0,0 +1,3 @@
1
+ /** The selection half of presence; selection and pose publish as one command. */
2
+ export { PresenceProvider as SelectionProvider, useSelection } from "./presence.js";
3
+ export type { PresenceProviderProps as SelectionProviderProps, Selection } from "./presence.js";
@@ -0,0 +1,2 @@
1
+ /** The selection half of presence; selection and pose publish as one command. */
2
+ export { PresenceProvider as SelectionProvider, useSelection } from "./presence.js";
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Every model the editor has open, including other clients' sessions. A
3
+ * read-only session showing a saved version is not a model of its own.
4
+ */
5
+ import type { SessionId, SessionInfo } from "@catchlight/editor-core";
6
+ import type { ComponentProps } from "react";
7
+ export interface SessionListRootProps extends Omit<ComponentProps<"ul">, "children" | "onSelect"> {
8
+ onSelect?: (info: SessionInfo) => void;
9
+ /** With this set, every row carries a close control. */
10
+ onClose?: (info: SessionInfo) => void;
11
+ current?: SessionId | undefined;
12
+ }
13
+ export declare function SessionListRoot({ onSelect, onClose, current, ...rest }: SessionListRootProps): import("react").JSX.Element;
14
+ export declare const SessionList: {
15
+ Root: typeof SessionListRoot;
16
+ };
@@ -0,0 +1,7 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useSessions } from "./sessions.js";
3
+ export function SessionListRoot({ onSelect, onClose, current, ...rest }) {
4
+ const { sessions } = useSessions();
5
+ return (_jsx("ul", { "data-catchlight-session-list": "", ...rest, children: sessions.filter((info) => !info.viewing).map((info) => (_jsxs("li", { "data-catchlight-session": "", "data-session": info.session, "data-dirty": info.dirty ? "" : undefined, "data-current": info.session === current ? "" : undefined, children: [_jsx("button", { type: "button", onClick: () => onSelect?.(info), children: info.title }), onClose ? (_jsx("button", { type: "button", "data-catchlight-session-close": "", "aria-label": `Close ${info.title}`, onClick: () => onClose(info), children: "×" })) : null] }, info.session))) }));
6
+ }
7
+ export const SessionList = { Root: SessionListRoot };
@@ -0,0 +1,8 @@
1
+ /** Open sessions, re-fetched whenever the editor says the set changed. */
2
+ import type { SessionInfo } from "@catchlight/editor-core";
3
+ export interface Sessions {
4
+ sessions: SessionInfo[];
5
+ /** Re-asks the editor. Rejects if the editor refuses; the automatic refresh does not. */
6
+ refresh(): Promise<void>;
7
+ }
8
+ export declare function useSessions(): Sessions;
@@ -0,0 +1,29 @@
1
+ /** Open sessions, re-fetched whenever the editor says the set changed. */
2
+ import { useCallback, useEffect, useRef, useState } from "react";
3
+ import { useEditor } from "./editor-context.js";
4
+ export function useSessions() {
5
+ const editor = useEditor();
6
+ const [sessions, setSessions] = useState([]);
7
+ const request = useRef(0);
8
+ const refresh = useCallback(async () => {
9
+ const generation = ++request.current;
10
+ const listed = await editor.listSessions();
11
+ // An older response must not restore a model that a newer list removed.
12
+ if (generation === request.current)
13
+ setSessions(listed);
14
+ }, [editor]);
15
+ useEffect(() => {
16
+ const reload = () => {
17
+ void refresh().catch((cause) => {
18
+ console.warn("catchlight: listing sessions failed", cause);
19
+ });
20
+ };
21
+ reload();
22
+ const off = editor.onSessionsChanged(reload);
23
+ return () => {
24
+ ++request.current;
25
+ off();
26
+ };
27
+ }, [editor, refresh]);
28
+ return { sessions, refresh };
29
+ }
@@ -0,0 +1,32 @@
1
+ import { Editor } from "@catchlight/editor-core";
2
+ import type { Session } from "@catchlight/editor-core";
3
+ import { FakeEditor } from "@catchlight/editor-core/fakes";
4
+ import type { FakeReplica, FakeViewport } from "@catchlight/editor-core/fakes";
5
+ import type { ReactNode } from "react";
6
+ export interface Harness {
7
+ editor: Editor;
8
+ wasm: FakeEditor;
9
+ replicas: FakeReplica[];
10
+ viewports: FakeViewport[];
11
+ }
12
+ export declare function harness(): Promise<Harness>;
13
+ export declare function fakeReplica(session: Session): FakeReplica;
14
+ export interface Mounted {
15
+ container: HTMLElement;
16
+ render(ui: ReactNode): Promise<void>;
17
+ unmount(): Promise<void>;
18
+ }
19
+ export declare function mount(ui: ReactNode): Promise<Mounted>;
20
+ export declare function run<T>(action: () => Promise<T> | T): Promise<T>;
21
+ export declare function settle(): Promise<void>;
22
+ export declare function stubLayout(width: number, height: number, left?: number, top?: number): () => void;
23
+ export declare function pointer(type: string, parts: {
24
+ clientX?: number;
25
+ clientY?: number;
26
+ button?: number;
27
+ pointerId?: number;
28
+ }): PointerEvent;
29
+ export declare function wheel(deltaY: number, clientX: number, clientY: number): WheelEvent;
30
+ export declare function fire(target: EventTarget, event: Event): Promise<void>;
31
+ /** Types `value` into a `NumberField` or text input and commits it on blur. */
32
+ export declare function enter(input: HTMLInputElement, value: string): Promise<void>;
@@ -0,0 +1,139 @@
1
+ import { Editor, InTabBackend, MemoryStorage } from "@catchlight/editor-core";
2
+ import { FakeEditor, fakeWasm } from "@catchlight/editor-core/fakes";
3
+ import { act } from "react";
4
+ import { createRoot } from "react-dom/client";
5
+ export async function harness() {
6
+ const module = fakeWasm();
7
+ const wasm = new module.module.CatchlightEditor();
8
+ const editor = await Editor.create(module.module, new InTabBackend(wasm, new MemoryStorage()));
9
+ return { editor, wasm, replicas: module.replicas, viewports: module.viewports };
10
+ }
11
+ export function fakeReplica(session) {
12
+ return session.replica;
13
+ }
14
+ export async function mount(ui) {
15
+ const container = document.createElement("div");
16
+ document.body.append(container);
17
+ const root = createRoot(container);
18
+ const render = async (next) => {
19
+ await act(async () => {
20
+ root.render(next);
21
+ });
22
+ };
23
+ await render(ui);
24
+ return {
25
+ container,
26
+ render,
27
+ unmount: async () => {
28
+ await act(async () => {
29
+ root.unmount();
30
+ });
31
+ container.remove();
32
+ },
33
+ };
34
+ }
35
+ export async function run(action) {
36
+ let result;
37
+ await act(async () => {
38
+ result = await action();
39
+ });
40
+ return result;
41
+ }
42
+ export async function settle() {
43
+ await act(async () => {
44
+ await Promise.resolve();
45
+ await Promise.resolve();
46
+ });
47
+ }
48
+ // Fixed CSS size and position for observed elements; happy-dom reports zero.
49
+ export function stubLayout(width, height, left = 0, top = 0) {
50
+ const saved = {
51
+ ResizeObserver: globalThis.ResizeObserver,
52
+ IntersectionObserver: globalThis.IntersectionObserver,
53
+ rect: Element.prototype.getBoundingClientRect,
54
+ };
55
+ globalThis.ResizeObserver = class {
56
+ #callback;
57
+ constructor(callback) {
58
+ this.#callback = callback;
59
+ }
60
+ observe() {
61
+ const box = { inlineSize: width, blockSize: height };
62
+ const entry = {
63
+ contentBoxSize: [box],
64
+ devicePixelContentBoxSize: [box],
65
+ contentRect: { width, height },
66
+ };
67
+ this.#callback([entry], this);
68
+ }
69
+ unobserve() { }
70
+ disconnect() { }
71
+ };
72
+ globalThis.IntersectionObserver = class {
73
+ observe() { }
74
+ unobserve() { }
75
+ disconnect() { }
76
+ takeRecords() {
77
+ return [];
78
+ }
79
+ };
80
+ Element.prototype.getBoundingClientRect = function rect() {
81
+ return {
82
+ x: left,
83
+ y: top,
84
+ left,
85
+ top,
86
+ width,
87
+ height,
88
+ right: left + width,
89
+ bottom: top + height,
90
+ toJSON: () => ({}),
91
+ };
92
+ };
93
+ return () => {
94
+ globalThis.ResizeObserver = saved.ResizeObserver;
95
+ globalThis.IntersectionObserver = saved.IntersectionObserver;
96
+ Element.prototype.getBoundingClientRect = saved.rect;
97
+ };
98
+ }
99
+ export function pointer(type, parts) {
100
+ const event = new PointerEvent(type, {
101
+ bubbles: true,
102
+ cancelable: true,
103
+ clientX: parts.clientX ?? 0,
104
+ clientY: parts.clientY ?? 0,
105
+ button: parts.button ?? 0,
106
+ });
107
+ // happy-dom drops `pointerId` from the constructor init.
108
+ Object.defineProperty(event, "pointerId", { value: parts.pointerId ?? 1 });
109
+ return event;
110
+ }
111
+ export function wheel(deltaY, clientX, clientY) {
112
+ const event = new WheelEvent("wheel", { deltaY, bubbles: true, cancelable: true });
113
+ // happy-dom's `WheelEvent` drops the mouse half of the init dictionary.
114
+ Object.defineProperty(event, "clientX", { value: clientX });
115
+ Object.defineProperty(event, "clientY", { value: clientY });
116
+ return event;
117
+ }
118
+ export async function fire(target, event) {
119
+ await act(async () => {
120
+ target.dispatchEvent(event);
121
+ });
122
+ }
123
+ /** Types `value` into a `NumberField` or text input and commits it on blur. */
124
+ export async function enter(input, value) {
125
+ // IE methods react-dom's pre-`input` fallback calls under happy-dom.
126
+ const proto = HTMLElement.prototype;
127
+ proto["attachEvent"] ??= () => { };
128
+ proto["detachEvent"] ??= () => { };
129
+ await fire(input, new FocusEvent("focusin", { bubbles: true }));
130
+ await act(async () => {
131
+ // Through the prototype's setter, so React sees a change to report.
132
+ Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value").set.call(input, value);
133
+ input.dispatchEvent(new Event("input", { bubbles: true }));
134
+ });
135
+ // That fallback notices a changed value on a key event, not on `input`.
136
+ await fire(input, new KeyboardEvent("keyup", { key: "0", bubbles: true }));
137
+ // `focusout` because it bubbles; React's `onBlur` listens for it.
138
+ await fire(input, new FocusEvent("focusout", { bubbles: true }));
139
+ }
@@ -0,0 +1,4 @@
1
+ declare global {
2
+ var IS_REACT_ACT_ENVIRONMENT: boolean;
3
+ }
4
+ export {};
@@ -0,0 +1,5 @@
1
+ // Imported per suite, not preloaded: `@catchlight/editor-core`'s suites must run without a DOM.
2
+ import { GlobalRegistrator } from "@happy-dom/global-registrator";
3
+ if (!globalThis.document)
4
+ GlobalRegistrator.register();
5
+ globalThis.IS_REACT_ACT_ENVIRONMENT = true;
@@ -0,0 +1,69 @@
1
+ /**
2
+ * A session's saved versions: numbered snapshots of its model kept beside it.
3
+ * Not revisions — a revision counts edits and ends with the session. Looking
4
+ * at a version opens it as a read-only session of its own, so the stage shows
5
+ * it through the same replica path as any model while the live one stays put.
6
+ */
7
+ import type { Kept, Session, VersionInfo } from "@catchlight/editor-core";
8
+ import type { ReactNode } from "react";
9
+ import type { ErrorHandler } from "./authoring.js";
10
+ import type { Reviewer } from "./review.js";
11
+ export interface VersionsState {
12
+ /** Oldest first. */
13
+ versions: readonly VersionInfo[];
14
+ kept: Kept;
15
+ keptProblem: string | undefined;
16
+ busy: boolean;
17
+ /** The version saved, or `undefined` when the editor refused. */
18
+ save(label?: string): Promise<VersionInfo | undefined>;
19
+ restore(version: number): Promise<boolean>;
20
+ }
21
+ /** `reviewer` signs what this tab saves, as it signs comments. */
22
+ export declare function useVersions(session: Session | undefined, onError: ErrorHandler, reviewer?: Reviewer): VersionsState;
23
+ export interface VersionView {
24
+ /** The read-only session on show, and which version it is. */
25
+ viewing: {
26
+ session: Session;
27
+ version: VersionInfo;
28
+ } | undefined;
29
+ open(version: VersionInfo): void;
30
+ /** Shows the live model again and closes the read-only session. */
31
+ back(): void;
32
+ /** Restores the version on show into the live session, then goes back. */
33
+ restore(): Promise<boolean>;
34
+ }
35
+ /**
36
+ * Which of `live`'s versions is on show instead of it. Changing `live` drops
37
+ * the view; the editor closes a version's session with the one it came from.
38
+ */
39
+ export declare function useVersionView(live: Session | undefined, versions: VersionsState, onError: ErrorHandler): VersionView;
40
+ /** "v3 · label", or "v3" without a label. */
41
+ export declare function versionName(version: VersionInfo): string;
42
+ /** Coarse and short: "just now", "5 min ago", "3 h ago", "2 d ago", else the date. */
43
+ export declare function relativeTime(ms: number, now?: number): string;
44
+ export interface VersionSelectProps {
45
+ versions: VersionsState;
46
+ /** The version on show, or `undefined` for the live model. */
47
+ current: number | undefined;
48
+ /** `undefined` picks the live model. */
49
+ onSelect: (version: VersionInfo | undefined) => void;
50
+ reviewer?: Reviewer | undefined;
51
+ /** Bumped to open the list with the save field focused. */
52
+ saveRequested?: number;
53
+ disabled?: boolean;
54
+ now?: number;
55
+ }
56
+ /**
57
+ * A trigger naming what the stage shows and a list of versions, newest
58
+ * first, with a field to save the model as the next one. Unstyled: every
59
+ * part carries a `data-catchlight-version-*` attribute.
60
+ */
61
+ export declare function VersionSelect({ versions, current, onSelect, reviewer, saveRequested, disabled, now, }: VersionSelectProps): ReactNode;
62
+ export interface VersionBannerProps {
63
+ version: VersionInfo;
64
+ busy?: boolean;
65
+ onRestore: () => void;
66
+ onBack: () => void;
67
+ }
68
+ /** Says the stage shows a saved version, not the model being edited. */
69
+ export declare function VersionBanner({ version, busy, onRestore, onBack }: VersionBannerProps): ReactNode;