@niscorp/nova 0.1.0 → 0.1.2

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