@niscorp/nova 0.2.1 → 0.3.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 (99) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/dist/adapters/dom/components/index.cjs +4 -51
  3. package/dist/adapters/dom/components/index.cjs.map +1 -1
  4. package/dist/adapters/dom/index.cjs +22 -686
  5. package/dist/adapters/dom/index.cjs.map +1 -1
  6. package/dist/adapters/dom/index.js +3 -3
  7. package/dist/adapters/dom/server.cjs +14 -411
  8. package/dist/adapters/dom/server.cjs.map +1 -1
  9. package/dist/adapters/dom/server.js +3 -3
  10. package/dist/adapters/react/components/index.cjs +87 -562
  11. package/dist/adapters/react/components/index.cjs.map +1 -1
  12. package/dist/adapters/react/components/index.js +4 -4
  13. package/dist/adapters/react/index.cjs +97 -1815
  14. package/dist/adapters/react/index.cjs.map +1 -1
  15. package/dist/adapters/react/index.js +4 -4
  16. package/dist/adapters/tty/components/index.cjs +3 -44
  17. package/dist/adapters/tty/components/index.cjs.map +1 -1
  18. package/dist/adapters/tty/index.cjs +13 -5
  19. package/dist/adapters/tty/index.cjs.map +1 -1
  20. package/dist/adapters/tty/index.js +2 -2
  21. package/dist/adapters/vue/components/index.cjs +88 -639
  22. package/dist/adapters/vue/components/index.cjs.map +1 -1
  23. package/dist/adapters/vue/components/index.js +4 -4
  24. package/dist/adapters/vue/index.cjs +96 -962
  25. package/dist/adapters/vue/index.cjs.map +1 -1
  26. package/dist/adapters/vue/index.js +5 -5
  27. package/dist/agent/index.cjs +13 -151
  28. package/dist/agent/index.cjs.map +1 -1
  29. package/dist/chunk-5YQIAS4V.cjs +184 -0
  30. package/dist/chunk-5YQIAS4V.cjs.map +1 -0
  31. package/dist/{chunk-F2H7WP6R.js → chunk-7MATRNZZ.js} +5 -5
  32. package/dist/{chunk-F2H7WP6R.js.map → chunk-7MATRNZZ.js.map} +1 -1
  33. package/dist/chunk-AGEAMUQR.cjs +436 -0
  34. package/dist/chunk-AGEAMUQR.cjs.map +1 -0
  35. package/dist/chunk-D4PUWBN6.cjs +72 -0
  36. package/dist/chunk-D4PUWBN6.cjs.map +1 -0
  37. package/dist/chunk-ECFWPZGL.cjs +2117 -0
  38. package/dist/chunk-ECFWPZGL.cjs.map +1 -0
  39. package/dist/{chunk-VOD5JA4D.js → chunk-EG45GQOE.js} +3 -3
  40. package/dist/{chunk-VOD5JA4D.js.map → chunk-EG45GQOE.js.map} +1 -1
  41. package/dist/chunk-FSUMCJAR.cjs +646 -0
  42. package/dist/chunk-FSUMCJAR.cjs.map +1 -0
  43. package/dist/chunk-GV7UC3SS.cjs +33 -0
  44. package/dist/chunk-GV7UC3SS.cjs.map +1 -0
  45. package/dist/chunk-HYFNOF7Y.cjs +97 -0
  46. package/dist/chunk-HYFNOF7Y.cjs.map +1 -0
  47. package/dist/chunk-KOYRJXTI.cjs +123 -0
  48. package/dist/chunk-KOYRJXTI.cjs.map +1 -0
  49. package/dist/chunk-KW34ZKF5.cjs +12 -0
  50. package/dist/chunk-KW34ZKF5.cjs.map +1 -0
  51. package/dist/chunk-M3UFIUXK.cjs +318 -0
  52. package/dist/chunk-M3UFIUXK.cjs.map +1 -0
  53. package/dist/chunk-OE527MXF.cjs +49 -0
  54. package/dist/chunk-OE527MXF.cjs.map +1 -0
  55. package/dist/{chunk-DU2VIJAF.js → chunk-P5SJ3QXJ.js} +3 -3
  56. package/dist/{chunk-DU2VIJAF.js.map → chunk-P5SJ3QXJ.js.map} +1 -1
  57. package/dist/chunk-PBPUSZIQ.cjs +808 -0
  58. package/dist/chunk-PBPUSZIQ.cjs.map +1 -0
  59. package/dist/chunk-PMKWYOOX.cjs +64 -0
  60. package/dist/chunk-PMKWYOOX.cjs.map +1 -0
  61. package/dist/chunk-PNQY6OFB.cjs +132 -0
  62. package/dist/chunk-PNQY6OFB.cjs.map +1 -0
  63. package/dist/chunk-Q7SFCCGT.cjs +11 -0
  64. package/dist/chunk-Q7SFCCGT.cjs.map +1 -0
  65. package/dist/{chunk-SVNK5NIK.js → chunk-QLFHYHJ2.js} +4 -4
  66. package/dist/{chunk-SVNK5NIK.js.map → chunk-QLFHYHJ2.js.map} +1 -1
  67. package/dist/{chunk-G4LSLLGI.js → chunk-RB4OMSPA.js} +5 -5
  68. package/dist/{chunk-G4LSLLGI.js.map → chunk-RB4OMSPA.js.map} +1 -1
  69. package/dist/chunk-UGG7MCX4.cjs +34 -0
  70. package/dist/chunk-UGG7MCX4.cjs.map +1 -0
  71. package/dist/chunk-WGZZKCJQ.cjs +157 -0
  72. package/dist/chunk-WGZZKCJQ.cjs.map +1 -0
  73. package/dist/{chunk-3JRTELLC.js → chunk-X5JTZ5LW.js} +3 -3
  74. package/dist/{chunk-3JRTELLC.js.map → chunk-X5JTZ5LW.js.map} +1 -1
  75. package/dist/{chunk-Y6XVPRYH.js → chunk-XUSKGJRI.js} +2 -2
  76. package/dist/chunk-XUSKGJRI.js.map +1 -0
  77. package/dist/chunk-Z7CS43ZT.cjs +808 -0
  78. package/dist/chunk-Z7CS43ZT.cjs.map +1 -0
  79. package/dist/chunk-ZYTWQZZC.cjs +623 -0
  80. package/dist/chunk-ZYTWQZZC.cjs.map +1 -0
  81. package/dist/devtools/index.cjs +13 -697
  82. package/dist/devtools/index.cjs.map +1 -1
  83. package/dist/devtools/index.js +2 -2
  84. package/dist/document/index.cjs +56 -301
  85. package/dist/document/index.cjs.map +1 -1
  86. package/dist/examples/index.cjs +6 -31
  87. package/dist/examples/index.cjs.map +1 -1
  88. package/dist/i18n/index.cjs +44 -292
  89. package/dist/i18n/index.cjs.map +1 -1
  90. package/dist/index.cjs +335 -3954
  91. package/dist/index.cjs.map +1 -1
  92. package/dist/index.js +2 -2
  93. package/dist/migrations/index.cjs +7 -590
  94. package/dist/migrations/index.cjs.map +1 -1
  95. package/dist/reflect/index.cjs +85 -994
  96. package/dist/reflect/index.cjs.map +1 -1
  97. package/dist/reflect/index.js +2 -2
  98. package/package.json +5 -5
  99. package/dist/chunk-Y6XVPRYH.js.map +0 -1
@@ -0,0 +1,808 @@
1
+ 'use strict';
2
+
3
+ var chunkHYFNOF7Y_cjs = require('./chunk-HYFNOF7Y.cjs');
4
+ var chunkECFWPZGL_cjs = require('./chunk-ECFWPZGL.cjs');
5
+ var chunkPNQY6OFB_cjs = require('./chunk-PNQY6OFB.cjs');
6
+ var chunkPBPUSZIQ_cjs = require('./chunk-PBPUSZIQ.cjs');
7
+ var chunkOE527MXF_cjs = require('./chunk-OE527MXF.cjs');
8
+ var jsxRuntime = require('react/jsx-runtime');
9
+ var react = require('react');
10
+
11
+ var ALIGN_MAP = {
12
+ start: "flex-start",
13
+ center: "center",
14
+ end: "flex-end",
15
+ stretch: "stretch"
16
+ };
17
+ var JUSTIFY_MAP = {
18
+ start: "flex-start",
19
+ center: "center",
20
+ end: "flex-end",
21
+ between: "space-between",
22
+ around: "space-around"
23
+ };
24
+ var Stack = ({
25
+ direction,
26
+ gap,
27
+ align,
28
+ justify,
29
+ padding,
30
+ wrap,
31
+ children
32
+ }) => {
33
+ const style = {
34
+ display: "flex",
35
+ flexDirection: direction ?? "column",
36
+ gap: gap ?? 0,
37
+ alignItems: ALIGN_MAP[align ?? "stretch"],
38
+ justifyContent: JUSTIFY_MAP[justify ?? "start"],
39
+ padding: padding ?? 0,
40
+ flexWrap: wrap === true ? "wrap" : "nowrap"
41
+ };
42
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { style, children });
43
+ };
44
+ Stack.meta = {
45
+ description: "Flex container that arranges children in a row or column.",
46
+ propsSchema: chunkHYFNOF7Y_cjs.StackPropsSchema
47
+ };
48
+ var SIZE_MAP = {
49
+ sm: "12px",
50
+ md: "14px",
51
+ lg: "16px",
52
+ xl: "20px",
53
+ "2xl": "24px"
54
+ };
55
+ var WEIGHT_MAP = {
56
+ normal: 400,
57
+ medium: 500,
58
+ bold: 700
59
+ };
60
+ var Text = ({
61
+ as,
62
+ size,
63
+ weight,
64
+ color,
65
+ children
66
+ }) => {
67
+ const tag = as ?? "span";
68
+ const style = {
69
+ fontSize: SIZE_MAP[size ?? "md"],
70
+ fontWeight: WEIGHT_MAP[weight ?? "normal"],
71
+ color: color ?? "inherit"
72
+ };
73
+ return react.createElement(tag, { style }, children);
74
+ };
75
+ Text.meta = {
76
+ description: "Text element with semantic typography props.",
77
+ propsSchema: chunkHYFNOF7Y_cjs.TextPropsSchema
78
+ };
79
+ var NovaRenderContext = react.createContext(void 0);
80
+ var NovaShellContext = react.createContext(void 0);
81
+ var ShellHeadContext = react.createContext(void 0);
82
+ var HeadMark = () => {
83
+ const head = react.useContext(ShellHeadContext);
84
+ react.useEffect(() => {
85
+ if (head === void 0) return void 0;
86
+ head.enter();
87
+ return head.leave;
88
+ }, [head]);
89
+ return null;
90
+ };
91
+ var ShellHeadProvider = ({ shell, children }) => {
92
+ const head = react.useMemo(() => chunkHYFNOF7Y_cjs.createShellHead(shell), [shell]);
93
+ react.useEffect(() => head.watch(), [head]);
94
+ return /* @__PURE__ */ jsxRuntime.jsx(ShellHeadContext.Provider, { value: head, children });
95
+ };
96
+ var noopDispatch = () => {
97
+ };
98
+ var noopPublish = () => {
99
+ };
100
+ var NovaRenderProvider = ({
101
+ registry,
102
+ dispatch = noopDispatch,
103
+ publish = noopPublish,
104
+ slotWrapper,
105
+ fallback,
106
+ textWrapper,
107
+ errorMarker,
108
+ children
109
+ }) => {
110
+ const value = react.useMemo(
111
+ () => ({ registry, dispatch, publish, slotWrapper, fallback, textWrapper, errorMarker }),
112
+ [registry, dispatch, publish, slotWrapper, fallback, textWrapper, errorMarker]
113
+ );
114
+ return /* @__PURE__ */ jsxRuntime.jsx(NovaRenderContext.Provider, { value, children });
115
+ };
116
+ var NovaShellProvider = ({
117
+ shell,
118
+ registry,
119
+ slotWrapper,
120
+ children
121
+ }) => {
122
+ const dispatch = react.useMemo(() => (event) => shell.dispatch(event), [shell]);
123
+ const publish = react.useMemo(
124
+ () => (channel, payload) => shell.publish(channel, payload),
125
+ [shell]
126
+ );
127
+ const resolvedRegistry = registry ?? shell.registry;
128
+ return /* @__PURE__ */ jsxRuntime.jsx(NovaShellContext.Provider, { value: shell, children: /* @__PURE__ */ jsxRuntime.jsx(
129
+ NovaRenderProvider,
130
+ {
131
+ registry: resolvedRegistry,
132
+ dispatch,
133
+ publish,
134
+ slotWrapper,
135
+ children: /* @__PURE__ */ jsxRuntime.jsx(ShellHeadProvider, { shell, children })
136
+ }
137
+ ) });
138
+ };
139
+ var ErrorMarker = ({ code, message }) => /* @__PURE__ */ jsxRuntime.jsx("span", { "data-nova-error": code, role: "alert", children: `[${code}] ${message}` });
140
+ var RenderNodeView = ({ node }) => {
141
+ const ctx = react.useContext(NovaRenderContext);
142
+ if (ctx === void 0) {
143
+ throw new Error("RenderNodeView must be used inside <NovaRenderProvider>");
144
+ }
145
+ if (node.type === "text") {
146
+ const TextWrap = ctx.textWrapper;
147
+ return TextWrap === void 0 ? /* @__PURE__ */ jsxRuntime.jsx(react.Fragment, { children: node.value }) : /* @__PURE__ */ jsxRuntime.jsx(TextWrap, { children: node.value });
148
+ }
149
+ if (node.type === "fragment") {
150
+ return /* @__PURE__ */ jsxRuntime.jsx(RenderTree, { nodes: node.children });
151
+ }
152
+ if (node.type === "error") {
153
+ const Marker = ctx.errorMarker ?? ErrorMarker;
154
+ return /* @__PURE__ */ jsxRuntime.jsx(Marker, { code: node.code, message: node.message });
155
+ }
156
+ if (chunkPNQY6OFB_cjs.isHeadNode(node)) return /* @__PURE__ */ jsxRuntime.jsx(HeadMark, {});
157
+ const entry = ctx.registry.get(node.name);
158
+ const Component2 = entry !== void 0 ? entry.component : ctx.fallback;
159
+ if (Component2 === void 0) {
160
+ return /* @__PURE__ */ jsxRuntime.jsx(ErrorMarker, { code: "COMPONENT_NOT_FOUND", message: node.name });
161
+ }
162
+ const props = { ...node.props };
163
+ if (node.model !== void 0) {
164
+ props[chunkPBPUSZIQ_cjs.NOVA_MODEL_PROP] = { ref: node.model.ref, path: node.model.path };
165
+ }
166
+ if (node.ref !== void 0) {
167
+ props[chunkPBPUSZIQ_cjs.NOVA_REF_PROP] = node.ref;
168
+ }
169
+ const viewOf = (child, i) => /* @__PURE__ */ jsxRuntime.jsx(RenderNodeView, { node: child }, chunkPBPUSZIQ_cjs.renderNodeKey(child, i));
170
+ if (!node.children.some(chunkPNQY6OFB_cjs.isHeadNode)) {
171
+ return react.createElement(Component2, props, node.children.length === 0 ? void 0 : node.children.map(viewOf));
172
+ }
173
+ const views = node.children.map((child, i) => ({ head: chunkPNQY6OFB_cjs.isHeadNode(child), view: viewOf(child, i) }));
174
+ const shown = views.filter((child) => !child.head).map((child) => child.view);
175
+ return /* @__PURE__ */ jsxRuntime.jsxs(react.Fragment, { children: [
176
+ react.createElement(Component2, props, shown.length === 0 ? void 0 : shown),
177
+ views.filter((child) => child.head).map((child) => child.view)
178
+ ] });
179
+ };
180
+ var RenderTree = ({ nodes }) => /* @__PURE__ */ jsxRuntime.jsx(react.Fragment, { children: nodes.map((node, i) => /* @__PURE__ */ jsxRuntime.jsx(RenderNodeView, { node }, chunkPBPUSZIQ_cjs.renderNodeKey(node, i))) });
181
+ var NovaErrorBoundary = class extends react.Component {
182
+ state = { error: void 0 };
183
+ static getDerivedStateFromError(error) {
184
+ return { error };
185
+ }
186
+ componentDidCatch(error, info) {
187
+ const handler = this.props.onError;
188
+ if (handler !== void 0) handler(error, info);
189
+ }
190
+ render() {
191
+ const { error } = this.state;
192
+ if (error !== void 0) {
193
+ const fallback = this.props.fallback;
194
+ if (fallback !== void 0) return fallback(error);
195
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { "data-nova-error-boundary": "true", role: "alert", children: error.message });
196
+ }
197
+ return this.props.children;
198
+ }
199
+ };
200
+ var useShell = () => {
201
+ const shell = react.useContext(NovaShellContext);
202
+ if (shell === void 0) {
203
+ throw new Error("useShell must be used inside <NovaShellProvider>");
204
+ }
205
+ return shell;
206
+ };
207
+
208
+ // src/adapters/react/hooks/use-canvas-render-tree.ts
209
+ var EMPTY = [];
210
+ var useCanvasRenderTree = (canvasId) => {
211
+ const shell = useShell();
212
+ const cacheRef = react.useRef(void 0);
213
+ const subscribe = react.useCallback(
214
+ (cb) => shell.onStateChange(() => {
215
+ const tree = canvasId === void 0 ? EMPTY : shell.getCanvasRenderTree(canvasId);
216
+ cacheRef.current = { shell, canvasId, tree };
217
+ cb();
218
+ }),
219
+ [shell, canvasId]
220
+ );
221
+ const getSnapshot = react.useCallback(() => {
222
+ const cached = cacheRef.current;
223
+ if (cached !== void 0 && cached.shell === shell && cached.canvasId === canvasId) {
224
+ return cached.tree;
225
+ }
226
+ const tree = canvasId === void 0 ? EMPTY : shell.getCanvasRenderTree(canvasId);
227
+ cacheRef.current = { shell, canvasId, tree };
228
+ return tree;
229
+ }, [shell, canvasId]);
230
+ return react.useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
231
+ };
232
+ var useShellRenderTree = () => {
233
+ const shell = useShell();
234
+ const cacheRef = react.useRef(void 0);
235
+ const subscribe = react.useCallback(
236
+ (cb) => shell.onStateChange(() => {
237
+ cacheRef.current = { shell, tree: shell.getShellRenderTree() };
238
+ cb();
239
+ }),
240
+ [shell]
241
+ );
242
+ const getSnapshot = react.useCallback(() => {
243
+ const cached = cacheRef.current;
244
+ if (cached === void 0 || cached.shell !== shell) {
245
+ const tree = shell.getShellRenderTree();
246
+ cacheRef.current = { shell, tree };
247
+ return tree;
248
+ }
249
+ return cached.tree;
250
+ }, [shell]);
251
+ return react.useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
252
+ };
253
+ var ensureReactBuiltins = (registry) => {
254
+ if (registry.has("CanvasSlot")) return;
255
+ registerNovaReactComponents(registry);
256
+ };
257
+ var NovaLayout = ({
258
+ layout,
259
+ data,
260
+ components,
261
+ registry: registryProp,
262
+ store: storeProp,
263
+ builtins = true,
264
+ strict,
265
+ onError,
266
+ phrases,
267
+ phraseKeys,
268
+ onPhraseMiss,
269
+ children
270
+ }) => {
271
+ const [registry] = react.useState(() => {
272
+ if (registryProp !== void 0) return registryProp;
273
+ const reg = chunkOE527MXF_cjs.createComponentRegistry();
274
+ if (builtins) registerNovaReactComponents(reg);
275
+ if (components !== void 0) reg.registerAll(components);
276
+ return reg;
277
+ });
278
+ const [store] = react.useState(() => storeProp ?? chunkPBPUSZIQ_cjs.createLayoutStore());
279
+ const nodes = react.useMemo(() => {
280
+ const resolved = typeof layout === "string" ? store.get(layout) : layout;
281
+ if (resolved === void 0) return [];
282
+ return chunkPBPUSZIQ_cjs.renderLayout(resolved, data ?? {}, {
283
+ store,
284
+ registry,
285
+ ...strict === void 0 ? {} : { strict },
286
+ ...onError === void 0 ? {} : { onError },
287
+ ...phrases === void 0 ? {} : { phrases },
288
+ ...phraseKeys === void 0 ? {} : { phraseKeys },
289
+ ...onPhraseMiss === void 0 ? {} : { onPhraseMiss }
290
+ });
291
+ }, [layout, data, store, registry, strict, onError, phrases, phraseKeys, onPhraseMiss]);
292
+ return /* @__PURE__ */ jsxRuntime.jsxs(NovaRenderProvider, { registry, children: [
293
+ /* @__PURE__ */ jsxRuntime.jsx(RenderTree, { nodes }),
294
+ children
295
+ ] });
296
+ };
297
+ var ShellRenderTreeView = () => {
298
+ const nodes = useShellRenderTree();
299
+ return /* @__PURE__ */ jsxRuntime.jsx(RenderTree, { nodes });
300
+ };
301
+ var NovaShell = ({ shell, registry, slotWrapper, builtins = true }) => {
302
+ const resolvedRegistry = registry ?? shell.registry;
303
+ react.useState(() => {
304
+ if (builtins) ensureReactBuiltins(resolvedRegistry);
305
+ return true;
306
+ });
307
+ return /* @__PURE__ */ jsxRuntime.jsx(NovaShellProvider, { shell, registry: resolvedRegistry, slotWrapper, children: /* @__PURE__ */ jsxRuntime.jsx(ShellRenderTreeView, {}) });
308
+ };
309
+ var CanvasRenderTreeView = ({ canvasId }) => {
310
+ const nodes = useCanvasRenderTree(canvasId);
311
+ return /* @__PURE__ */ jsxRuntime.jsx(RenderTree, { nodes });
312
+ };
313
+ var CanvasInContext = ({ canvasId }) => {
314
+ useShell();
315
+ return /* @__PURE__ */ jsxRuntime.jsx(CanvasRenderTreeView, { canvasId });
316
+ };
317
+ var CanvasStandalone = ({ canvasId, shell, registry, builtins }) => {
318
+ const resolvedRegistry = registry ?? shell.registry;
319
+ react.useState(() => {
320
+ if (builtins) ensureReactBuiltins(resolvedRegistry);
321
+ return true;
322
+ });
323
+ return /* @__PURE__ */ jsxRuntime.jsx(NovaShellProvider, { shell, registry: resolvedRegistry, children: /* @__PURE__ */ jsxRuntime.jsx(CanvasRenderTreeView, { canvasId }) });
324
+ };
325
+ var NovaCanvas = ({ id, shell, registry, builtins = true }) => {
326
+ if (shell === void 0) return /* @__PURE__ */ jsxRuntime.jsx(CanvasInContext, { canvasId: id });
327
+ return /* @__PURE__ */ jsxRuntime.jsx(
328
+ CanvasStandalone,
329
+ {
330
+ canvasId: id,
331
+ shell,
332
+ builtins,
333
+ ...registry === void 0 ? {} : { registry }
334
+ }
335
+ );
336
+ };
337
+ var Nova = {
338
+ Layout: NovaLayout,
339
+ Shell: NovaShell,
340
+ Canvas: NovaCanvas
341
+ };
342
+ var useShellState = () => {
343
+ const shell = useShell();
344
+ const cacheRef = react.useRef(void 0);
345
+ if (cacheRef.current === void 0 || cacheRef.current.shell !== shell) {
346
+ cacheRef.current = { shell, snapshot: shell.getState() };
347
+ }
348
+ const subscribe = react.useCallback(
349
+ (cb) => shell.onStateChange((snapshot) => {
350
+ cacheRef.current = { shell, snapshot };
351
+ cb();
352
+ }),
353
+ [shell]
354
+ );
355
+ const getSnapshot = react.useCallback(() => {
356
+ const cached = cacheRef.current;
357
+ if (cached === void 0 || cached.shell !== shell) {
358
+ const snapshot = shell.getState();
359
+ cacheRef.current = { shell, snapshot };
360
+ return snapshot;
361
+ }
362
+ return cached.snapshot;
363
+ }, [shell]);
364
+ return react.useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
365
+ };
366
+ var useCanvas = (canvasId) => {
367
+ const shell = useShell();
368
+ const cacheRef = react.useRef(void 0);
369
+ const subscribe = react.useCallback(
370
+ (cb) => shell.onCanvasChange(canvasId, (next) => {
371
+ cacheRef.current = { shell, canvasId, state: next };
372
+ cb();
373
+ }),
374
+ [shell, canvasId]
375
+ );
376
+ const getSnapshot = react.useCallback(() => {
377
+ const cached = cacheRef.current;
378
+ if (cached !== void 0 && cached.shell === shell && cached.canvasId === canvasId) {
379
+ return cached.state;
380
+ }
381
+ const state = shell.getCanvasState(canvasId);
382
+ cacheRef.current = { shell, canvasId, state };
383
+ return state;
384
+ }, [shell, canvasId]);
385
+ return react.useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
386
+ };
387
+ var useActionData = (instanceId) => {
388
+ const shell = useShell();
389
+ const cacheRef = react.useRef(void 0);
390
+ const subscribe = react.useCallback(
391
+ (cb) => {
392
+ const runtime = shell.getRuntime(instanceId);
393
+ if (runtime === void 0) return () => {
394
+ };
395
+ return runtime.onDataChange((next) => {
396
+ cacheRef.current = next;
397
+ cb();
398
+ });
399
+ },
400
+ [shell, instanceId]
401
+ );
402
+ const getSnapshot = react.useCallback(() => {
403
+ const runtime = shell.getRuntime(instanceId);
404
+ if (runtime === void 0) {
405
+ cacheRef.current = void 0;
406
+ return void 0;
407
+ }
408
+ const current = runtime.getData();
409
+ if (cacheRef.current !== current) cacheRef.current = current;
410
+ return cacheRef.current;
411
+ }, [shell, instanceId]);
412
+ return react.useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
413
+ };
414
+ var useActionStatus = (instanceId) => {
415
+ const shell = useShell();
416
+ const cacheRef = react.useRef(void 0);
417
+ const subscribe = react.useCallback(
418
+ (cb) => {
419
+ const runtime = shell.getRuntime(instanceId);
420
+ if (runtime === void 0) return () => {
421
+ };
422
+ return runtime.onStatusChange((next) => {
423
+ cacheRef.current = next;
424
+ cb();
425
+ });
426
+ },
427
+ [shell, instanceId]
428
+ );
429
+ const getSnapshot = react.useCallback(() => {
430
+ const runtime = shell.getRuntime(instanceId);
431
+ if (runtime === void 0) {
432
+ cacheRef.current = void 0;
433
+ return void 0;
434
+ }
435
+ const current = runtime.instance.status;
436
+ if (cacheRef.current !== current) cacheRef.current = current;
437
+ return cacheRef.current;
438
+ }, [shell, instanceId]);
439
+ return react.useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
440
+ };
441
+ var EMPTY2 = [];
442
+ var useRenderTree = (instanceId) => {
443
+ const shell = useShell();
444
+ const cacheRef = react.useRef(void 0);
445
+ const subscribe = react.useCallback(
446
+ (cb) => {
447
+ const offState = shell.onStateChange(() => cb());
448
+ const runtime = shell.getRuntime(instanceId);
449
+ if (runtime === void 0) return offState;
450
+ const offData = runtime.onDataChange(() => cb());
451
+ return () => {
452
+ offData();
453
+ offState();
454
+ };
455
+ },
456
+ [shell, instanceId]
457
+ );
458
+ const getSnapshot = react.useCallback(() => {
459
+ const runtime = shell.getRuntime(instanceId);
460
+ if (runtime === void 0) {
461
+ cacheRef.current = void 0;
462
+ return EMPTY2;
463
+ }
464
+ const data = runtime.getData();
465
+ const phrases = shell.getPhrases();
466
+ const cached = cacheRef.current;
467
+ if (cached !== void 0 && cached.data === data && cached.phrases === phrases) return cached.tree;
468
+ const tree = runtime.render();
469
+ cacheRef.current = { data, phrases, tree };
470
+ return tree;
471
+ }, [shell, instanceId]);
472
+ return react.useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
473
+ };
474
+ var useNovaDispatch = () => {
475
+ const ctx = react.useContext(NovaRenderContext);
476
+ if (ctx === void 0) {
477
+ throw new Error("useNovaDispatch must be used inside <NovaRenderProvider>");
478
+ }
479
+ return ctx.dispatch;
480
+ };
481
+ var useNovaPublish = () => {
482
+ const ctx = react.useContext(NovaRenderContext);
483
+ if (ctx === void 0) {
484
+ throw new Error("useNovaPublish must be used inside <NovaRenderProvider>");
485
+ }
486
+ return ctx.publish;
487
+ };
488
+ var useNovaRegistry = () => {
489
+ const ctx = react.useContext(NovaRenderContext);
490
+ if (ctx === void 0) {
491
+ throw new Error("useNovaRegistry must be used inside <NovaRenderProvider>");
492
+ }
493
+ return ctx.registry;
494
+ };
495
+ var useSlotWrapper = () => react.useContext(NovaRenderContext)?.slotWrapper;
496
+ var computeStyle = (isDisabled, isFocused, isHovered) => {
497
+ const borderColor = isDisabled ? "#d1d5db" : isFocused ? "#2563eb" : isHovered ? "#9ca3af" : "#d1d5db";
498
+ return {
499
+ padding: "8px 12px",
500
+ border: `1px solid ${borderColor}`,
501
+ borderRadius: 6,
502
+ fontSize: 14,
503
+ background: isDisabled ? "#f9fafb" : "#ffffff",
504
+ color: isDisabled ? "#9ca3af" : "inherit",
505
+ cursor: isDisabled ? "not-allowed" : "text",
506
+ minWidth: 240,
507
+ outline: "none",
508
+ boxShadow: isFocused ? "0 0 0 3px rgba(37, 99, 235, 0.15)" : "none",
509
+ transition: "border-color 150ms, box-shadow 150ms"
510
+ };
511
+ };
512
+ var Input = ({
513
+ type,
514
+ placeholder,
515
+ disabled,
516
+ value,
517
+ debounce,
518
+ novaModel
519
+ }) => {
520
+ const dispatch = useNovaDispatch();
521
+ const [isHovered, setIsHovered] = react.useState(false);
522
+ const [draft, setDraft] = react.useState(null);
523
+ const isFocused = draft !== null;
524
+ const shown = draft ?? value ?? "";
525
+ const isDisabled = disabled ?? false;
526
+ const debounceMs = debounce ?? 0;
527
+ const timer = react.useRef(void 0);
528
+ const clearPending = () => {
529
+ if (timer.current !== void 0) {
530
+ clearTimeout(timer.current);
531
+ timer.current = void 0;
532
+ }
533
+ };
534
+ react.useEffect(() => clearPending, []);
535
+ const fire = (next) => {
536
+ if (novaModel === void 0) return;
537
+ dispatch({ type: "ui:model", ref: novaModel.ref, payload: next });
538
+ };
539
+ const onChange = (event) => {
540
+ const next = event.target.value;
541
+ setDraft(next);
542
+ if (debounceMs > 0) {
543
+ clearPending();
544
+ timer.current = setTimeout(() => {
545
+ timer.current = void 0;
546
+ fire(next);
547
+ }, debounceMs);
548
+ } else {
549
+ fire(next);
550
+ }
551
+ };
552
+ const onFocus = () => setDraft(value ?? "");
553
+ const onBlur = () => {
554
+ if (timer.current !== void 0 && draft !== null) {
555
+ clearPending();
556
+ fire(draft);
557
+ }
558
+ setDraft(null);
559
+ };
560
+ return /* @__PURE__ */ jsxRuntime.jsx(
561
+ "input",
562
+ {
563
+ type: type ?? "text",
564
+ placeholder,
565
+ disabled: isDisabled,
566
+ value: shown,
567
+ onChange,
568
+ onFocus,
569
+ onBlur,
570
+ onMouseEnter: () => setIsHovered(true),
571
+ onMouseLeave: () => setIsHovered(false),
572
+ style: computeStyle(isDisabled, isFocused, isHovered)
573
+ }
574
+ );
575
+ };
576
+ Input.meta = {
577
+ description: "Text input bound to data via the `model` field on the layout node.",
578
+ propsSchema: chunkHYFNOF7Y_cjs.InputPropsSchema
579
+ };
580
+ var BASE_STYLE = {
581
+ borderRadius: 6,
582
+ fontSize: 14,
583
+ fontWeight: 500,
584
+ transition: "background-color 100ms"
585
+ };
586
+ var primaryStyle = (isDisabled, isHovered, isActive) => ({
587
+ ...BASE_STYLE,
588
+ padding: "8px 16px",
589
+ border: "none",
590
+ color: "#ffffff",
591
+ cursor: isDisabled ? "not-allowed" : "pointer",
592
+ background: isDisabled ? "#93c5fd" : isActive ? "#1e40af" : isHovered ? "#1d4ed8" : "#2563eb"
593
+ });
594
+ var secondaryStyle = (isDisabled, isHovered, isActive) => ({
595
+ ...BASE_STYLE,
596
+ padding: "8px 16px",
597
+ border: `1px solid ${isDisabled ? "#e5e7eb" : isHovered ? "#9ca3af" : "#d1d5db"}`,
598
+ color: isDisabled ? "#9ca3af" : "#1f2937",
599
+ cursor: isDisabled ? "not-allowed" : "pointer",
600
+ background: isDisabled ? "#ffffff" : isActive ? "#e5e7eb" : isHovered ? "#f3f4f6" : "#ffffff"
601
+ });
602
+ var ghostStyle = (isDisabled, isHovered, isActive) => ({
603
+ ...BASE_STYLE,
604
+ padding: "8px 12px",
605
+ border: "none",
606
+ color: isDisabled ? "#93c5fd" : "#2563eb",
607
+ cursor: isDisabled ? "not-allowed" : "pointer",
608
+ background: isDisabled ? "transparent" : isActive ? "#dbeafe" : isHovered ? "#eff6ff" : "transparent"
609
+ });
610
+ var styleFor = (variant, isDisabled, isHovered, isActive) => {
611
+ if (variant === "primary") return primaryStyle(isDisabled, isHovered, isActive);
612
+ if (variant === "secondary") return secondaryStyle(isDisabled, isHovered, isActive);
613
+ return ghostStyle(isDisabled, isHovered, isActive);
614
+ };
615
+ var Button = ({
616
+ label,
617
+ variant,
618
+ disabled,
619
+ novaRef,
620
+ children
621
+ }) => {
622
+ const dispatch = useNovaDispatch();
623
+ const [isHovered, setIsHovered] = react.useState(false);
624
+ const [isActive, setIsActive] = react.useState(false);
625
+ const isDisabled = disabled ?? false;
626
+ const style = styleFor(variant ?? "primary", isDisabled, isHovered, isActive);
627
+ const onClick = (_event) => {
628
+ if (isDisabled) return;
629
+ if (novaRef === void 0) return;
630
+ dispatch({ type: "ui:click", ref: novaRef });
631
+ };
632
+ return /* @__PURE__ */ jsxRuntime.jsx(
633
+ "button",
634
+ {
635
+ type: "button",
636
+ disabled: isDisabled,
637
+ style,
638
+ onClick,
639
+ onMouseEnter: () => setIsHovered(true),
640
+ onMouseLeave: () => {
641
+ setIsHovered(false);
642
+ setIsActive(false);
643
+ },
644
+ onMouseDown: () => setIsActive(true),
645
+ onMouseUp: () => setIsActive(false),
646
+ children: label ?? children
647
+ }
648
+ );
649
+ };
650
+ Button.meta = {
651
+ description: "Clickable button. Click events fire as `ui:click` with the layout node's ref.",
652
+ propsSchema: chunkHYFNOF7Y_cjs.ButtonPropsSchema
653
+ };
654
+ var Box = ({
655
+ padding,
656
+ background,
657
+ border,
658
+ radius,
659
+ children
660
+ }) => {
661
+ const style = {
662
+ padding: padding ?? 0,
663
+ background: background ?? "transparent",
664
+ border: border === true ? "1px solid #e5e7eb" : "none",
665
+ borderRadius: radius ?? 0
666
+ };
667
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { style, children });
668
+ };
669
+ Box.meta = {
670
+ description: "Generic container with basic styling props. Use Stack for layout, Box for visual wrapping.",
671
+ propsSchema: chunkHYFNOF7Y_cjs.BoxPropsSchema
672
+ };
673
+ var Panel = ({ title, backRef, closeRef, children }) => {
674
+ const dispatch = useNovaDispatch();
675
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { border: "1px solid #d8dae0", borderRadius: 10, background: "#fff", boxShadow: "0 1px 3px rgba(0,0,0,.06)", padding: 12 }, children: [
676
+ title !== void 0 && /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", alignItems: "center", gap: 6, fontWeight: 600, fontSize: 13, marginBottom: 8 }, children: [
677
+ backRef !== void 0 && /* @__PURE__ */ jsxRuntime.jsx(
678
+ "button",
679
+ {
680
+ type: "button",
681
+ style: { border: "none", background: "none", color: "#6b7280", cursor: "pointer", fontSize: 13, lineHeight: 1, padding: 2 },
682
+ onClick: () => dispatch({ type: "ui:click", ref: backRef }),
683
+ children: "\u2190"
684
+ }
685
+ ),
686
+ /* @__PURE__ */ jsxRuntime.jsx("span", { style: { flex: 1 }, children: title }),
687
+ closeRef !== void 0 && /* @__PURE__ */ jsxRuntime.jsx(
688
+ "button",
689
+ {
690
+ type: "button",
691
+ style: { border: "none", background: "none", color: "#6b7280", cursor: "pointer", fontSize: 13, lineHeight: 1, padding: 2 },
692
+ onClick: () => dispatch({ type: "ui:click", ref: closeRef }),
693
+ children: "\u2715"
694
+ }
695
+ )
696
+ ] }),
697
+ children
698
+ ] });
699
+ };
700
+ Panel.meta = { description: "A framed, elevated surface with an optional title; `closeRef` adds a header \u2715.", propsSchema: chunkHYFNOF7Y_cjs.PanelPropsSchema };
701
+ var entriesOf = (value) => Array.isArray(value) ? value.map((item, index) => [String(index), item]) : Object.entries(value);
702
+ var JsonNode = ({ value, name }) => {
703
+ if (value !== null && typeof value === "object") {
704
+ const entries = entriesOf(value);
705
+ const shape = Array.isArray(value) ? `[${entries.length}]` : `{${entries.length}}`;
706
+ return /* @__PURE__ */ jsxRuntime.jsxs("details", { children: [
707
+ /* @__PURE__ */ jsxRuntime.jsx("summary", { style: { cursor: "pointer", color: "#6b7280" }, children: name === void 0 ? shape : `${name} ${shape}` }),
708
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: { paddingLeft: 13, borderLeft: "1px solid #d8dae0", marginLeft: 3 }, children: entries.map(([key, child]) => /* @__PURE__ */ jsxRuntime.jsx(JsonNode, { value: child, name: key }, key)) })
709
+ ] });
710
+ }
711
+ const text = name === void 0 ? JSON.stringify(value) : `${name}: ${JSON.stringify(value)}`;
712
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { style: { whiteSpace: "pre-wrap", wordBreak: "break-word" }, children: text });
713
+ };
714
+ var JsonTree = ({ value, label }) => /* @__PURE__ */ jsxRuntime.jsx("div", { style: { fontFamily: "ui-monospace, SFMono-Regular, Menlo, monospace", fontSize: 12, lineHeight: 1.5 }, children: /* @__PURE__ */ jsxRuntime.jsx(JsonNode, { value, name: label }) });
715
+ JsonTree.meta = { description: "A collapsible view of any JSON value.", propsSchema: chunkHYFNOF7Y_cjs.JsonTreePropsSchema };
716
+ var CanvasSlot = ({
717
+ canvasId
718
+ }) => {
719
+ const tree = useCanvasRenderTree(canvasId);
720
+ if (canvasId === void 0 || canvasId === "") return null;
721
+ return /* @__PURE__ */ jsxRuntime.jsx(RenderTree, { nodes: tree });
722
+ };
723
+ CanvasSlot.meta = {
724
+ description: "Renders a canvas by id, recursing into its actionLayout.",
725
+ propsSchema: chunkHYFNOF7Y_cjs.CanvasSlotPropsSchema
726
+ };
727
+ var ActionSlot = ({
728
+ instanceId
729
+ }) => {
730
+ const tree = useRenderTree(instanceId ?? "");
731
+ const slotWrapper = useSlotWrapper();
732
+ const shell = useShell();
733
+ const hasInstance = instanceId !== void 0 && instanceId !== "";
734
+ const ctx = react.useContext(NovaRenderContext);
735
+ const scoped = react.useMemo(() => {
736
+ if (ctx === void 0 || instanceId === void 0 || instanceId === "") return ctx;
737
+ return { ...ctx, dispatch: chunkECFWPZGL_cjs.scopeDispatch(ctx.dispatch, instanceId) };
738
+ }, [ctx, instanceId]);
739
+ if (slotWrapper === void 0) {
740
+ if (!hasInstance) return null;
741
+ return /* @__PURE__ */ jsxRuntime.jsx(NovaRenderContext.Provider, { value: scoped, children: /* @__PURE__ */ jsxRuntime.jsx(RenderTree, { nodes: tree }) });
742
+ }
743
+ const runtime = hasInstance ? shell.getRuntime(instanceId) : void 0;
744
+ const Wrapper = slotWrapper;
745
+ return /* @__PURE__ */ jsxRuntime.jsx(
746
+ Wrapper,
747
+ {
748
+ canvasId: runtime?.instance.canvasId,
749
+ instanceId: hasInstance ? instanceId : void 0,
750
+ action: runtime?.definition,
751
+ children: hasInstance && tree.length ? /* @__PURE__ */ jsxRuntime.jsx(NovaRenderContext.Provider, { value: scoped, children: /* @__PURE__ */ jsxRuntime.jsx(RenderTree, { nodes: tree }) }) : null
752
+ }
753
+ );
754
+ };
755
+ ActionSlot.meta = {
756
+ description: "Renders an action instance by id. Used inside a canvas actionLayout.",
757
+ propsSchema: chunkHYFNOF7Y_cjs.ActionSlotPropsSchema
758
+ };
759
+
760
+ // src/adapters/react/components/index.ts
761
+ var registerNovaReactComponents = (registry) => {
762
+ registry.registerAll({
763
+ Stack,
764
+ Text,
765
+ Input,
766
+ Button,
767
+ Box,
768
+ Panel,
769
+ JsonTree,
770
+ CanvasSlot,
771
+ ActionSlot
772
+ });
773
+ };
774
+
775
+ exports.ActionSlot = ActionSlot;
776
+ exports.Box = Box;
777
+ exports.Button = Button;
778
+ exports.CanvasSlot = CanvasSlot;
779
+ exports.ErrorMarker = ErrorMarker;
780
+ exports.Input = Input;
781
+ exports.JsonTree = JsonTree;
782
+ exports.Nova = Nova;
783
+ exports.NovaCanvas = NovaCanvas;
784
+ exports.NovaErrorBoundary = NovaErrorBoundary;
785
+ exports.NovaLayout = NovaLayout;
786
+ exports.NovaRenderProvider = NovaRenderProvider;
787
+ exports.NovaShell = NovaShell;
788
+ exports.NovaShellProvider = NovaShellProvider;
789
+ exports.Panel = Panel;
790
+ exports.RenderNodeView = RenderNodeView;
791
+ exports.RenderTree = RenderTree;
792
+ exports.Stack = Stack;
793
+ exports.Text = Text;
794
+ exports.registerNovaReactComponents = registerNovaReactComponents;
795
+ exports.useActionData = useActionData;
796
+ exports.useActionStatus = useActionStatus;
797
+ exports.useCanvas = useCanvas;
798
+ exports.useCanvasRenderTree = useCanvasRenderTree;
799
+ exports.useNovaDispatch = useNovaDispatch;
800
+ exports.useNovaPublish = useNovaPublish;
801
+ exports.useNovaRegistry = useNovaRegistry;
802
+ exports.useRenderTree = useRenderTree;
803
+ exports.useShell = useShell;
804
+ exports.useShellRenderTree = useShellRenderTree;
805
+ exports.useShellState = useShellState;
806
+ exports.useSlotWrapper = useSlotWrapper;
807
+ //# sourceMappingURL=chunk-Z7CS43ZT.cjs.map
808
+ //# sourceMappingURL=chunk-Z7CS43ZT.cjs.map