@niscorp/nova 0.2.0 → 0.2.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 (111) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/README.md +56 -13
  3. package/SHELL_DOCS.md +13 -4
  4. package/dist/adapters/dom/components/index.cjs +4 -51
  5. package/dist/adapters/dom/components/index.cjs.map +1 -1
  6. package/dist/adapters/dom/index.cjs +22 -686
  7. package/dist/adapters/dom/index.cjs.map +1 -1
  8. package/dist/adapters/dom/index.js +2 -2
  9. package/dist/adapters/dom/server.cjs +14 -411
  10. package/dist/adapters/dom/server.cjs.map +1 -1
  11. package/dist/adapters/dom/server.js +2 -2
  12. package/dist/adapters/react/components/index.cjs +87 -562
  13. package/dist/adapters/react/components/index.cjs.map +1 -1
  14. package/dist/adapters/react/components/index.d.cts +2 -2
  15. package/dist/adapters/react/components/index.d.ts +2 -2
  16. package/dist/adapters/react/components/index.js +3 -3
  17. package/dist/adapters/react/index.cjs +97 -1815
  18. package/dist/adapters/react/index.cjs.map +1 -1
  19. package/dist/adapters/react/index.js +3 -3
  20. package/dist/adapters/tty/components/index.cjs +3 -44
  21. package/dist/adapters/tty/components/index.cjs.map +1 -1
  22. package/dist/adapters/tty/index.cjs +13 -5
  23. package/dist/adapters/tty/index.cjs.map +1 -1
  24. package/dist/adapters/tty/index.js +1 -1
  25. package/dist/adapters/vue/components/index.cjs +88 -639
  26. package/dist/adapters/vue/components/index.cjs.map +1 -1
  27. package/dist/adapters/vue/components/index.d.cts +10 -10
  28. package/dist/adapters/vue/components/index.d.ts +10 -10
  29. package/dist/adapters/vue/components/index.js +3 -3
  30. package/dist/adapters/vue/index.cjs +96 -962
  31. package/dist/adapters/vue/index.cjs.map +1 -1
  32. package/dist/adapters/vue/index.js +4 -4
  33. package/dist/agent/index.cjs +13 -151
  34. package/dist/agent/index.cjs.map +1 -1
  35. package/dist/chunk-3IPM5QBT.cjs +436 -0
  36. package/dist/chunk-3IPM5QBT.cjs.map +1 -0
  37. package/dist/chunk-5AF72LOE.cjs +97 -0
  38. package/dist/chunk-5AF72LOE.cjs.map +1 -0
  39. package/dist/chunk-5YQIAS4V.cjs +184 -0
  40. package/dist/chunk-5YQIAS4V.cjs.map +1 -0
  41. package/dist/chunk-D4PUWBN6.cjs +72 -0
  42. package/dist/chunk-D4PUWBN6.cjs.map +1 -0
  43. package/dist/{chunk-RYIIIXDX.js → chunk-DU2VIJAF.js} +57 -15
  44. package/dist/chunk-DU2VIJAF.js.map +1 -0
  45. package/dist/{chunk-VU6NNCEJ.js → chunk-F2H7WP6R.js} +4 -4
  46. package/dist/{chunk-VU6NNCEJ.js.map → chunk-F2H7WP6R.js.map} +1 -1
  47. package/dist/chunk-FSUMCJAR.cjs +646 -0
  48. package/dist/chunk-FSUMCJAR.cjs.map +1 -0
  49. package/dist/{chunk-QXQCPH33.js → chunk-G4LSLLGI.js} +4 -4
  50. package/dist/{chunk-QXQCPH33.js.map → chunk-G4LSLLGI.js.map} +1 -1
  51. package/dist/chunk-GV7UC3SS.cjs +33 -0
  52. package/dist/chunk-GV7UC3SS.cjs.map +1 -0
  53. package/dist/chunk-IZ2UU5UL.cjs +808 -0
  54. package/dist/chunk-IZ2UU5UL.cjs.map +1 -0
  55. package/dist/chunk-KOYRJXTI.cjs +123 -0
  56. package/dist/chunk-KOYRJXTI.cjs.map +1 -0
  57. package/dist/chunk-KW34ZKF5.cjs +12 -0
  58. package/dist/chunk-KW34ZKF5.cjs.map +1 -0
  59. package/dist/chunk-OE527MXF.cjs +49 -0
  60. package/dist/chunk-OE527MXF.cjs.map +1 -0
  61. package/dist/chunk-OO247V4J.cjs +2117 -0
  62. package/dist/chunk-OO247V4J.cjs.map +1 -0
  63. package/dist/chunk-PMKWYOOX.cjs +64 -0
  64. package/dist/chunk-PMKWYOOX.cjs.map +1 -0
  65. package/dist/chunk-PNQY6OFB.cjs +132 -0
  66. package/dist/chunk-PNQY6OFB.cjs.map +1 -0
  67. package/dist/chunk-Q7SFCCGT.cjs +11 -0
  68. package/dist/chunk-Q7SFCCGT.cjs.map +1 -0
  69. package/dist/{chunk-MHW5VEIM.js → chunk-SVNK5NIK.js} +3 -3
  70. package/dist/{chunk-MHW5VEIM.js.map → chunk-SVNK5NIK.js.map} +1 -1
  71. package/dist/chunk-TMLNVU5W.cjs +318 -0
  72. package/dist/chunk-TMLNVU5W.cjs.map +1 -0
  73. package/dist/chunk-TRJYDVWK.cjs +623 -0
  74. package/dist/chunk-TRJYDVWK.cjs.map +1 -0
  75. package/dist/chunk-UGG7MCX4.cjs +34 -0
  76. package/dist/chunk-UGG7MCX4.cjs.map +1 -0
  77. package/dist/{chunk-UDCXGDLQ.js → chunk-VOD5JA4D.js} +3 -3
  78. package/dist/{chunk-UDCXGDLQ.js.map → chunk-VOD5JA4D.js.map} +1 -1
  79. package/dist/chunk-WGPFR7MN.cjs +808 -0
  80. package/dist/chunk-WGPFR7MN.cjs.map +1 -0
  81. package/dist/chunk-WGZZKCJQ.cjs +157 -0
  82. package/dist/chunk-WGZZKCJQ.cjs.map +1 -0
  83. package/dist/chunk-XQTI4Q4I.js +178 -0
  84. package/dist/chunk-XQTI4Q4I.js.map +1 -0
  85. package/dist/devtools/index.cjs +13 -697
  86. package/dist/devtools/index.cjs.map +1 -1
  87. package/dist/document/index.cjs +56 -301
  88. package/dist/document/index.cjs.map +1 -1
  89. package/dist/examples/index.cjs +1161 -0
  90. package/dist/examples/index.cjs.map +1 -0
  91. package/dist/examples/index.d.cts +63 -0
  92. package/dist/examples/index.d.ts +63 -0
  93. package/dist/examples/index.js +1158 -0
  94. package/dist/examples/index.js.map +1 -0
  95. package/dist/i18n/index.cjs +44 -292
  96. package/dist/i18n/index.cjs.map +1 -1
  97. package/dist/i18n/index.js +2 -176
  98. package/dist/i18n/index.js.map +1 -1
  99. package/dist/index.cjs +335 -3911
  100. package/dist/index.cjs.map +1 -1
  101. package/dist/index.d.cts +5 -1
  102. package/dist/index.d.ts +5 -1
  103. package/dist/index.js +1 -1
  104. package/dist/migrations/index.cjs +7 -590
  105. package/dist/migrations/index.cjs.map +1 -1
  106. package/dist/reflect/index.cjs +85 -994
  107. package/dist/reflect/index.cjs.map +1 -1
  108. package/package.json +19 -8
  109. package/dist/chunk-RYIIIXDX.js.map +0 -1
  110. package/dist/{primitive-props-CGoJvmcH.d.cts → primitive-props-Cl5jiC8g.d.cts} +5 -5
  111. package/dist/{primitive-props-CGoJvmcH.d.ts → primitive-props-Cl5jiC8g.d.ts} +5 -5
@@ -1,1827 +1,109 @@
1
1
  'use strict';
2
2
 
3
- var react = require('react');
4
- var zod = require('zod');
5
- var prism = require('@niscorp/prism');
6
- var strata = require('@niscorp/strata');
7
- var jsxRuntime = require('react/jsx-runtime');
8
-
9
- // src/adapters/react/provider.tsx
10
- var NovaRenderContext = react.createContext(void 0);
11
- var NovaShellContext = react.createContext(void 0);
12
- zod.z.object({
13
- $if: zod.z.unknown().describe("Condition \u2014 resolved recursively, then checked for truthiness."),
14
- $then: zod.z.unknown().describe("Value when condition is truthy \u2014 resolved recursively."),
15
- $else: zod.z.unknown().optional().describe("Value when condition is falsy \u2014 resolved recursively.")
16
- }).strict().describe("Conditional value directive. Resolved at bind time.");
17
- var ResolvableSchema = zod.z.unknown().describe(
18
- 'Any value. Strings support {{}} templates and bare $-paths. The data ROOT is "$." \u2014 a data key is ALWAYS "$.key" ("{{$.rows.length}} found", "$.loading"); "$key" without the dot is INVALID. Loop variables (a `for` directive\'s `as`) are "$<name>.field" ("{{$row.title}}"). Objects may be directives like {$if,$then,$else}. Arrays and nested objects are walked recursively. Everything else is literal.'
19
- );
20
-
21
- // src/layout/schemas.ts
22
- var LayoutPrimitiveSchema = zod.z.union([zod.z.string(), zod.z.number(), zod.z.boolean(), zod.z.null()]).describe("A primitive layout value rendered as text.");
23
- var ComponentNodeSchema = zod.z.lazy(
24
- () => zod.z.object({
25
- component: zod.z.string().describe("The registry name of the component to render."),
26
- props: zod.z.record(zod.z.string(), zod.z.unknown()).optional().describe("Component props; values may be bindings to be resolved at render time."),
27
- children: zod.z.union([LayoutNodeSchema, zod.z.array(LayoutNodeSchema)]).optional().describe("Child layout content (a single node or an array of nodes)."),
28
- ref: zod.z.string().optional().describe("A stable identifier used to target this component from event handlers."),
29
- model: zod.z.string().optional().describe('A two-way binding path, e.g. "$.name".'),
30
- events: zod.z.record(zod.z.string(), zod.z.unknown()).optional().describe("Map of event name to event configuration handled by the action runtime.")
31
- }).strict().describe("A node that instantiates a component from the registry.")
32
- );
33
- var ConditionalNodeSchema = zod.z.lazy(
34
- () => zod.z.object({
35
- if: ResolvableSchema.describe("Resolvable value evaluated for truthiness."),
36
- then: LayoutNodeSchema.describe("Layout to render when condition is truthy."),
37
- else: LayoutNodeSchema.optional().describe("Layout to render when condition is falsy.")
38
- }).strict().describe("A node that conditionally renders one of two branches.")
39
- );
40
- var LoopNodeSchema = zod.z.lazy(
41
- () => zod.z.object({
42
- for: ResolvableSchema.describe("Resolvable value that resolves to an iterable array."),
43
- as: zod.z.string().describe("Name to bind each iterated item under in the inner scope."),
44
- key: zod.z.string().optional().describe("Optional key path on each item used for stable identity."),
45
- do: LayoutNodeSchema.describe("Layout rendered once per iterated item.")
46
- }).strict().describe("A node that iterates an array binding and renders a layout for each item.")
47
- );
48
- var LayoutRefNodeSchema = zod.z.object({
49
- ref: zod.z.string().describe("Identifier of a layout stored in the layout store to inline at this position.")
50
- }).strict().describe("A reference to a stored layout, inlined during render.");
51
- var SlotNodeSchema = zod.z.object({
52
- slot: zod.z.string().describe(
53
- "Name of a slot placeholder. When an ActionFragment is composed with an action (a push/replace `with`), the fragment's `{ slot: \"body\" }` node is replaced by the composing action's own layout. An unfilled slot renders nothing."
54
- )
55
- }).strict().describe(
56
- "A placeholder that a fragment-merge fills with a composing action's layout. Only meaningful inside an ActionFragment's layout."
57
- );
58
- var LayoutNodeSchema = zod.z.lazy(
59
- () => zod.z.union([
60
- ComponentNodeSchema,
61
- ConditionalNodeSchema,
62
- LoopNodeSchema,
63
- LayoutRefNodeSchema,
64
- SlotNodeSchema,
65
- zod.z.array(LayoutNodeSchema),
66
- LayoutPrimitiveSchema
67
- ]).describe("Any layout node: component, conditional, loop, layout ref, slot, array of nodes, or a primitive text value.")
68
- );
69
-
70
- // src/shared/common.ts
71
- var isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
72
- var isArray = (value) => Array.isArray(value);
73
- var hasKey = (obj, key) => isObject(obj) && key in obj;
74
-
75
- // src/shared/bindings/paths.ts
76
- var splitPath = (path) => {
77
- if (path.length === 0) return [];
78
- return path.split(".");
79
- };
80
- var isIndex = (segment) => /^\d+$/.test(segment);
81
- var getPath = (data, path) => {
82
- const segments = splitPath(path);
83
- let current = data;
84
- for (const segment of segments) {
85
- if (current === void 0 || current === null) return void 0;
86
- if (isArray(current)) {
87
- if (isIndex(segment)) {
88
- const index = Number.parseInt(segment, 10);
89
- current = current[index];
90
- continue;
91
- }
92
- if (segment === "length") {
93
- current = current.length;
94
- continue;
95
- }
96
- return void 0;
97
- }
98
- if (isObject(current)) {
99
- if (segment in current) {
100
- current = current[segment];
101
- continue;
102
- }
103
- return void 0;
104
- }
105
- return void 0;
106
- }
107
- return current;
108
- };
109
-
110
- // src/shared/errors.ts
111
- var ErrorCodes = {
112
- render: "RENDER_ERROR",
113
- componentNotFound: "COMPONENT_NOT_FOUND",
114
- layoutRefNotFound: "LAYOUT_REF_NOT_FOUND",
115
- definitionValidation: "DEFINITION_VALIDATION_ERROR"};
116
- var NovaError = class extends Error {
117
- code;
118
- context;
119
- constructor(code, message, context, options) {
120
- super(message, options);
121
- this.name = "NovaError";
122
- this.code = code;
123
- this.context = context;
124
- }
125
- };
126
- var RenderError = class extends NovaError {
127
- constructor(message, context, options) {
128
- super(ErrorCodes.render, message, context, options);
129
- this.name = "RenderError";
130
- }
131
- };
132
- var ComponentNotFoundError = class extends NovaError {
133
- constructor(message, context, options) {
134
- super(ErrorCodes.componentNotFound, message, context, options);
135
- this.name = "ComponentNotFoundError";
136
- }
137
- };
138
- var LayoutRefNotFoundError = class extends NovaError {
139
- constructor(message, context, options) {
140
- super(ErrorCodes.layoutRefNotFound, message, context, options);
141
- this.name = "LayoutRefNotFoundError";
142
- }
143
- };
144
- var DefinitionValidationError = class extends NovaError {
145
- constructor(message, context, options) {
146
- super(ErrorCodes.definitionValidation, message, context, options);
147
- this.name = "DefinitionValidationError";
148
- }
149
- };
150
-
151
- // src/layout/guards.ts
152
- var isLayoutPrimitive = (value) => value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean";
153
- var isComponentNode = (value) => hasKey(value, "component") && typeof value["component"] === "string";
154
- var isConditionalNode = (value) => hasKey(value, "if") && hasKey(value, "then") && !hasKey(value, "for");
155
- var isLoopNode = (value) => hasKey(value, "for") && hasKey(value, "as") && hasKey(value, "do");
156
- var isLayoutRefNode = (value) => isObject(value) && hasKey(value, "ref") && typeof value["ref"] === "string" && !hasKey(value, "component") && Object.keys(value).length === 1;
157
- var isSlotNode = (value) => isObject(value) && hasKey(value, "slot") && typeof value["slot"] === "string" && Object.keys(value).length === 1;
158
-
159
- // src/shared/bindings/scope.ts
160
- var createScopeChain = (data) => [data];
161
- var pushScope = (chain, scope) => [scope, ...chain];
162
- var TEMPLATE_REGEX = /\{\{\s*([^}]+?)\s*\}\}/g;
163
- var SOLE_TEMPLATE_REGEX = /^\{\{\s*([^}]+?)\s*\}\}$/;
164
- var BARE_PATH_REGEX = /^\$(\.|[A-Za-z_]|$)/;
165
- var matchExtra = (expression, extras) => {
166
- let matched;
167
- for (const key of Object.keys(extras)) {
168
- if (expression === key || expression.startsWith(`${key}.`)) {
169
- if (matched === void 0 || key.length > matched.length) matched = key;
170
- }
171
- }
172
- return matched;
173
- };
174
- var resolveExtraExpression = (expression, matchedKey, extras) => {
175
- const root = extras[matchedKey];
176
- if (expression === matchedKey) return root;
177
- const rest = expression.slice(matchedKey.length + 1);
178
- if (rest.length === 0) return root;
179
- return getPath(root, rest);
180
- };
181
- var walkFromScopeHead = (head, restSegments) => {
182
- if (restSegments.length === 0) return head;
183
- return getPath(head, restSegments.join("."));
184
- };
185
- var resolvePath = (path, chain, extras = {}) => {
186
- const extraKey = matchExtra(path, extras);
187
- if (extraKey !== void 0) return resolveExtraExpression(path, extraKey, extras);
188
- if (!path.startsWith("$")) return void 0;
189
- if (path === "$") return chain[0];
190
- const afterDollar = path.slice(1);
191
- if (afterDollar.startsWith(".")) {
192
- const rest = afterDollar.slice(1);
193
- if (rest.length === 0) return chain[0];
194
- const segments2 = rest.split(".");
195
- const head = segments2[0];
196
- if (head === void 0) return void 0;
197
- for (const scope of chain) {
198
- if (hasKey(scope, head)) {
199
- return walkFromScopeHead(scope[head], segments2.slice(1));
200
- }
201
- }
202
- return void 0;
203
- }
204
- const segments = afterDollar.split(".");
205
- const varName = segments[0];
206
- if (varName === void 0 || varName.length === 0) return void 0;
207
- for (const scope of chain) {
208
- if (hasKey(scope, varName)) {
209
- return walkFromScopeHead(scope[varName], segments.slice(1));
210
- }
211
- }
212
- return void 0;
213
- };
214
- var stringify = (value) => {
215
- if (value === null || value === void 0) return "";
216
- if (typeof value === "string") return value;
217
- if (typeof value === "number" || typeof value === "boolean") return String(value);
218
- try {
219
- return JSON.stringify(value);
220
- } catch {
221
- return "";
222
- }
223
- };
224
- var isTruthy = (value) => {
225
- if (value === null || value === void 0) return false;
226
- if (value === false) return false;
227
- if (value === 0) return false;
228
- if (value === "") return false;
229
- if (isArray(value) && value.length === 0) return false;
230
- return true;
231
- };
232
- var DIRECTIVES = {
233
- $if: (node, chain, extras) => {
234
- if (isTruthy(resolve(node.$if, chain, extras))) return resolve(node.$then, chain, extras);
235
- if (hasKey(node, "$else")) return resolve(node.$else, chain, extras);
236
- return void 0;
237
- },
238
- $eq: (node, chain, extras) => {
239
- const args = isArray(node.$eq) ? node.$eq : [];
240
- return resolve(args[0], chain, extras) === resolve(args[1], chain, extras);
241
- },
242
- // True when the operand path resolves to a present value. The structural
243
- // counterpart to `$eq`: discriminate a union by which key a branch carries
244
- // (`{ $exists: "$.shape.component" }`) rather than a shared tag's value.
245
- $exists: (node, chain, extras) => resolve(node.$exists, chain, extras) !== void 0,
246
- // Read an array element by a (dynamic) index: `{ $at: ["$.results", "$.i"] }`.
247
- // An optional third arg pulls one field off the element: `["$.results", "$.i",
248
- // "id"]`. Returns undefined when the array/index doesn't resolve.
249
- $at: (node, chain, extras) => {
250
- const args = isArray(node.$at) ? node.$at : [];
251
- const arr = resolve(args[0], chain, extras);
252
- const index = Number(resolve(args[1], chain, extras));
253
- if (!isArray(arr) || Number.isNaN(index)) return void 0;
254
- const element = arr[index];
255
- const field = args[2];
256
- return field !== void 0 && isObject(element) ? element[String(field)] : element;
257
- },
258
- // THE WHOLE TRANSFORM GRAMMAR, BEHIND ONE EXPLICIT DOOR. The directives
259
- // above stay the small binding set; a value that needs a real transformation
260
- // — a join, a projection, a group — says so out loud: `{ $prism: <node> }`
261
- // evaluates the node with prism against the action's ROOT data. One grammar,
262
- // one evaluator, nothing ambient — a prism-shaped object OUTSIDE this
263
- // wrapper stays what it always was, a plain object walked for strings.
264
- //
265
- // The quiet failure this replaces was worse than a crash: an unrecognised
266
- // op-shaped value passed through `resolve` as structure, landed in data, and
267
- // rendered as garbage three screens later. Inside the wrapper, a bad node
268
- // resolves to undefined — absent, not wrong.
269
- $prism: (node, chain) => {
270
- const result = prism.evaluateSafe(node.$prism, chain[0] ?? {});
271
- return result.ok ? result.data : void 0;
272
- }
273
- };
274
- var directiveOf = (value) => {
275
- for (const key of Object.keys(value)) {
276
- const directive = DIRECTIVES[key];
277
- if (directive !== void 0) return directive;
278
- }
279
- return void 0;
280
- };
281
- var resolveString = (value, chain, extras) => {
282
- const sole = value.match(SOLE_TEMPLATE_REGEX);
283
- if (sole !== null) {
284
- const expr = sole[1];
285
- if (expr === void 0) return value;
286
- return resolvePath(expr.trim(), chain, extras);
287
- }
288
- if (value.includes("{{")) {
289
- return value.replace(TEMPLATE_REGEX, (_match, expression) => {
290
- const resolved = resolvePath(expression.trim(), chain, extras);
291
- return stringify(resolved);
292
- });
293
- }
294
- if (BARE_PATH_REGEX.test(value)) {
295
- return resolvePath(value, chain, extras);
296
- }
297
- if (matchExtra(value, extras) !== void 0) {
298
- return resolvePath(value, chain, extras);
299
- }
300
- return value;
301
- };
302
- var resolve = (value, chain, extras = {}) => {
303
- if (typeof value === "string") return resolveString(value, chain, extras);
304
- if (isArray(value)) return value.map((entry) => resolve(entry, chain, extras));
305
- if (isObject(value)) {
306
- const directive = directiveOf(value);
307
- if (directive !== void 0) return directive(value, chain, extras);
308
- const out = {};
309
- for (const key of Object.keys(value)) {
310
- out[key] = resolve(value[key], chain, extras);
311
- }
312
- return out;
313
- }
314
- return value;
315
- };
316
-
317
- // src/i18n/phrases.ts
318
- var DEFAULT_PHRASE_KEYS = {
319
- // A starting set, not a standard — an app with its own vocabulary passes its
320
- // own. Deliberately absent: `name`, `value`, `id`, `icon`, `tone`, `variant`,
321
- // `key`. Those carry data or design tokens, and translating them is how a
322
- // person called "Active" gets renamed.
323
- props: [
324
- "label",
325
- "title",
326
- "subtitle",
327
- "heading",
328
- "eyebrow",
329
- "lead",
330
- "blurb",
331
- "placeholder",
332
- "hint",
333
- "help",
334
- "message",
335
- "empty",
336
- "emptyHint",
337
- "emptyLabel",
338
- "noMatch",
339
- "caption",
340
- "description",
341
- "confirmLabel",
342
- "cancelLabel",
343
- "alt",
344
- "tooltip"
345
- ],
346
- text: true
347
- };
348
- var matcherFor = (keys) => {
349
- const props = new Set(keys?.props ?? DEFAULT_PHRASE_KEYS.props);
350
- const suffixes = keys?.suffixes ?? [];
351
- return {
352
- isProse: (key) => props.has(key) || suffixes.some((suffix) => key.endsWith(suffix)),
353
- text: keys?.text ?? DEFAULT_PHRASE_KEYS.text
354
- };
355
- };
356
- var BARE_PATH = /^\$(\.|[A-Za-z_]|$)/;
357
- var EXTRA_SCOPE = /^@[A-Za-z_]/;
358
- var isBinding = (value) => BARE_PATH.test(value) || EXTRA_SCOPE.test(value) || value.includes("{{");
359
- var isPhrase = (value) => {
360
- const trimmed = value.trim();
361
- if (trimmed === "" || isBinding(trimmed)) return false;
362
- return /\p{L}/u.test(trimmed);
363
- };
364
-
365
- // src/i18n/swap.ts
366
- var EMPTY = {};
367
- var passFor = (options) => {
368
- if (options === void 0) return void 0;
369
- if (options.phrases === void 0 && options.keys === void 0) return void 0;
370
- const matcher = matcherFor(options.keys);
371
- return {
372
- phrases: options.phrases ?? EMPTY,
373
- isProse: matcher.isProse,
374
- text: matcher.text,
375
- onMiss: options.onMiss
376
- };
377
- };
378
- var swap = (value, where, pass) => {
379
- if (!isPhrase(value)) return value;
380
- const hit = pass.phrases[value];
381
- if (hit !== void 0) return hit;
382
- const trimmed = value.trim();
383
- if (trimmed !== value) {
384
- const onTrimmed = pass.phrases[trimmed];
385
- if (onTrimmed !== void 0) return value.replace(trimmed, onTrimmed);
386
- }
387
- pass.onMiss?.(trimmed, where);
388
- return value;
389
- };
390
- var isPattern = (value) => typeof value["phrase"] === "string" && isObject(value["slots"]);
391
- var fillPattern = (pattern, where, pass) => swap(pattern.phrase, where, pass).replace(/\{([A-Za-z_][A-Za-z0-9_]*)\}/g, (hole, name) => {
392
- const slot = pattern.slots[name];
393
- if (slot === void 0 || slot === null) return hole;
394
- return typeof slot === "string" && isPhrase(slot) ? swap(slot, `${where}.${name}`, pass) : String(slot);
3
+ var chunkWGPFR7MN_cjs = require('../../chunk-WGPFR7MN.cjs');
4
+ require('../../chunk-5AF72LOE.cjs');
5
+ require('../../chunk-WGZZKCJQ.cjs');
6
+ require('../../chunk-OO247V4J.cjs');
7
+ require('../../chunk-PNQY6OFB.cjs');
8
+ require('../../chunk-IZ2UU5UL.cjs');
9
+ require('../../chunk-PMKWYOOX.cjs');
10
+ require('../../chunk-KOYRJXTI.cjs');
11
+ require('../../chunk-GV7UC3SS.cjs');
12
+ require('../../chunk-FSUMCJAR.cjs');
13
+ require('../../chunk-D4PUWBN6.cjs');
14
+ require('../../chunk-KW34ZKF5.cjs');
15
+ require('../../chunk-OE527MXF.cjs');
16
+ require('../../chunk-Q7SFCCGT.cjs');
17
+
18
+
19
+
20
+ Object.defineProperty(exports, "ErrorMarker", {
21
+ enumerable: true,
22
+ get: function () { return chunkWGPFR7MN_cjs.ErrorMarker; }
395
23
  });
396
- var walkValue = (value, prose, where, pass) => {
397
- if (typeof value === "string") return prose ? swap(value, where, pass) : value;
398
- if (isArray(value)) {
399
- let changed = false;
400
- const out = value.map((entry, index) => {
401
- const next = walkValue(entry, prose, `${where}[${String(index)}]`, pass);
402
- if (next !== entry) changed = true;
403
- return next;
404
- });
405
- return changed ? out : value;
406
- }
407
- if (isObject(value)) {
408
- if (prose && isPattern(value)) return fillPattern(value, where, pass);
409
- let changed = false;
410
- const out = {};
411
- for (const [key, entry] of Object.entries(value)) {
412
- const next = walkValue(entry, pass.isProse(key), `${where}.${key}`, pass);
413
- if (next !== entry) changed = true;
414
- out[key] = next;
415
- }
416
- return changed ? out : value;
417
- }
418
- return value;
419
- };
420
-
421
- // src/layout/head.ts
422
- var HEAD_NAME = "nova:head";
423
- var HEAD_TITLE_NAME = "nova:title";
424
- var HEAD_META_NAME = "nova:meta";
425
- var HEAD_LINK_NAME = "nova:link";
426
- var HEAD_SCRIPT_NAME = "nova:script";
427
- var HEAD_NAMES = [HEAD_NAME, HEAD_TITLE_NAME, HEAD_META_NAME, HEAD_LINK_NAME, HEAD_SCRIPT_NAME];
428
- var headKeyOf = (element) => {
429
- const said = (name) => {
430
- const found = Object.entries(element.attributes).find(([key]) => key.toLowerCase() === name)?.[1].trim().toLowerCase();
431
- return found === void 0 || found === "" ? void 0 : found;
432
- };
433
- if (element.tag === "title") return "title";
434
- if (element.tag === "meta") {
435
- const [name, property] = [said("name"), said("property")];
436
- if (name !== void 0) return `meta name ${name}`;
437
- return property === void 0 ? void 0 : `meta property ${property}`;
438
- }
439
- if (element.tag === "link") return (said("rel") ?? "").split(/\s+/).includes("canonical") ? "link canonical" : void 0;
440
- return void 0;
441
- };
442
-
443
- // src/layout/renderer.ts
444
- var noopOnError = (_error) => {
445
- };
446
- var textNode = (value) => ({ type: "text", value });
447
- var fragment = (children) => ({ type: "fragment", children });
448
- var errorNode = (error, nodeRef) => ({
449
- type: "error",
450
- code: error.code,
451
- message: error.message,
452
- ...{}
24
+ Object.defineProperty(exports, "Nova", {
25
+ enumerable: true,
26
+ get: function () { return chunkWGPFR7MN_cjs.Nova; }
453
27
  });
454
- var toRenderError = (err) => {
455
- if (err instanceof NovaError) return err;
456
- const message = err instanceof Error ? err.message : String(err);
457
- return new RenderError(message, {}, { cause: err });
458
- };
459
- var resolveDataPath = (binding, scopePaths) => {
460
- if (!binding.startsWith("$")) return void 0;
461
- const after = binding.slice(1);
462
- if (after.startsWith(".")) return after.slice(1);
463
- const segments = after.split(".");
464
- const head = segments[0];
465
- if (head === void 0 || head.length === 0) return void 0;
466
- for (let i = scopePaths.length - 1; i >= 0; i -= 1) {
467
- const entry = scopePaths[i];
468
- if (entry === void 0) continue;
469
- const eq = entry.indexOf("=");
470
- if (eq < 0) continue;
471
- const key = entry.slice(0, eq);
472
- if (key !== head) continue;
473
- const rooted = entry.slice(eq + 1);
474
- const rest = segments.slice(1).join(".");
475
- if (rest.length === 0) return rooted;
476
- return `${rooted}.${rest}`;
477
- }
478
- return void 0;
479
- };
480
- var makeAutoRef = (componentName, path) => `auto-${componentName}-${path}`;
481
- var renderNode = (node, chain, ctx) => {
482
- if (node === null) return [textNode("")];
483
- if (typeof node === "string") {
484
- const resolved = resolve(node, chain);
485
- if (resolved === void 0 || resolved === null) return [textNode("")];
486
- const value = String(resolved);
487
- if (ctx.pass === void 0 || !ctx.pass.text || isBinding(node)) return [textNode(value)];
488
- return [textNode(swap(value, `${ctx.where}#text`, ctx.pass))];
489
- }
490
- if (isLayoutPrimitive(node)) {
491
- return [textNode(String(node))];
492
- }
493
- if (isArray(node)) {
494
- const children = renderChildArray(node, chain, ctx);
495
- return [fragment(children)];
496
- }
497
- if (isLayoutRefNode(node)) {
498
- const target = ctx.store.get(node.ref);
499
- if (target === void 0) {
500
- throw new LayoutRefNotFoundError(`Layout ref not found: ${node.ref}`, { ref: node.ref });
501
- }
502
- return renderNode(target, chain, ctx);
503
- }
504
- if (isSlotNode(node)) {
505
- return [];
506
- }
507
- if (isConditionalNode(node)) {
508
- const condition = resolve(node.if, chain);
509
- const truthy = condition !== void 0 && condition !== null && condition !== false && condition !== 0 && condition !== "";
510
- const branchTruthy = isArray(condition) ? condition.length > 0 : truthy;
511
- if (branchTruthy) return renderNode(node.then, chain, ctx);
512
- if (node.else !== void 0) return renderNode(node.else, chain, ctx);
513
- return [];
514
- }
515
- if (isLoopNode(node)) {
516
- const items = resolve(node.for, chain);
517
- if (!isArray(items)) return [];
518
- const loopBasePath = typeof node.for === "string" ? resolveDataPath(node.for, ctx.scopePaths) : void 0;
519
- const out = [];
520
- items.forEach((item, index) => {
521
- const innerChain = pushScope(chain, { [node.as]: item, index, items });
522
- const nextScopePaths = loopBasePath === void 0 ? ctx.scopePaths : [...ctx.scopePaths, `${node.as}=${loopBasePath}.${index}`, `items=${loopBasePath}`];
523
- const innerCtx = { ...ctx, scopePaths: nextScopePaths };
524
- const idKey = node.key !== void 0 ? getPath(item, node.key) : index;
525
- const rendered = safeRenderSingle(node.do, innerChain, innerCtx);
526
- rendered.forEach((rn, sub) => {
527
- out.push({ ...rn, key: rendered.length === 1 ? String(idKey) : `${String(idKey)}:${sub}` });
528
- });
529
- });
530
- return [fragment(out)];
531
- }
532
- if (isComponentNode(node)) {
533
- return [renderComponent(node, chain, ctx)];
534
- }
535
- return [];
536
- };
537
- var renderComponent = (node, chain, ctx) => {
538
- if (!HEAD_NAMES.includes(node.component) && !ctx.registry.has(node.component)) {
539
- throw new ComponentNotFoundError(
540
- `Component not found in registry: ${node.component}`,
541
- { name: node.component }
542
- );
543
- }
544
- const pass = ctx.pass;
545
- const at = pass === void 0 ? "" : `${ctx.where}/${node.component}`;
546
- const props = Object.fromEntries(
547
- Object.entries(node.props ?? {}).map(([k, v]) => {
548
- const resolved = resolve(v, chain);
549
- if (pass === void 0) return [k, resolved];
550
- return [k, walkValue(resolved, pass.isProse(k), `${at}.${k}`, pass)];
551
- })
552
- );
553
- const children = renderChildren(node.children, chain, pass === void 0 ? ctx : { ...ctx, where: at });
554
- let model;
555
- if (node.model !== void 0) {
556
- const resolvedPath = resolveDataPath(node.model, ctx.scopePaths);
557
- if (resolvedPath !== void 0) {
558
- const ref = node.ref ?? makeAutoRef(node.component, resolvedPath);
559
- model = { path: resolvedPath, ref };
560
- if (!("value" in props)) {
561
- props["value"] = resolve(node.model, chain);
562
- }
563
- }
564
- }
565
- const component = {
566
- type: "component",
567
- name: node.component,
568
- props,
569
- children,
570
- ...node.ref === void 0 ? {} : { ref: node.ref },
571
- ...model === void 0 ? {} : { model }
572
- };
573
- return component;
574
- };
575
- var safeRenderSingle = (node, chain, ctx, nodeRef) => {
576
- try {
577
- return renderNode(node, chain, ctx);
578
- } catch (err) {
579
- const novaError = toRenderError(err);
580
- if (ctx.strict) throw novaError;
581
- ctx.onError(novaError);
582
- return [errorNode(novaError)];
583
- }
584
- };
585
- var renderChildArray = (nodes, chain, ctx) => {
586
- const out = [];
587
- for (const child of nodes) out.push(...safeRenderSingle(child, chain, ctx));
588
- return out;
589
- };
590
- var renderChildren = (children, chain, ctx) => {
591
- if (children === void 0) return [];
592
- if (isArray(children)) return renderChildArray(children, chain, ctx);
593
- return safeRenderSingle(children, chain, ctx);
594
- };
595
- var toInternal = (ctx) => ({
596
- store: ctx.store,
597
- registry: ctx.registry,
598
- strict: ctx.strict ?? false,
599
- onError: ctx.onError ?? noopOnError,
600
- scopePaths: [],
601
- // Built once per render call. The matcher compiles a Set and a suffix list,
602
- // and doing that per node would make the cheapest branch the expensive one.
603
- pass: passFor({
604
- ...ctx.phrases === void 0 ? {} : { phrases: ctx.phrases },
605
- ...ctx.phraseKeys === void 0 ? {} : { keys: ctx.phraseKeys },
606
- ...ctx.onPhraseMiss === void 0 ? {} : { onMiss: ctx.onPhraseMiss }
607
- }),
608
- where: ""
28
+ Object.defineProperty(exports, "NovaCanvas", {
29
+ enumerable: true,
30
+ get: function () { return chunkWGPFR7MN_cjs.NovaCanvas; }
609
31
  });
610
- var renderLayout = (node, data, ctx) => {
611
- const internal = toInternal(ctx);
612
- return safeRenderSingle(node, createScopeChain(data), internal);
613
- };
614
-
615
- // src/layout/adapter.ts
616
- var NOVA_MODEL_PROP = "novaModel";
617
- var NOVA_REF_PROP = "novaRef";
618
- var renderNodeKey = (node, index) => {
619
- if (node.key !== void 0) return `k:${node.key}`;
620
- if (node.type === "component") {
621
- if (node.ref !== void 0) return `c:${node.ref}`;
622
- return `c:${node.name}:${index}`;
623
- }
624
- if (node.type === "text") return `t:${index}`;
625
- if (node.type === "fragment") return `f:${index}`;
626
- return `e:${node.code}:${index}`;
627
- };
628
- var createLayoutStore = () => {
629
- const layouts = /* @__PURE__ */ new Map();
630
- const get = (id) => layouts.get(id);
631
- const set = (id, layout) => {
632
- if (strata.exceedsDepth(layout)) {
633
- throw new DefinitionValidationError(`Invalid layout for id "${id}"`, { failures: [{ id, issues: [{ code: "custom", path: [], message: strata.depthRefusal(), input: void 0 }] }] });
634
- }
635
- const result = LayoutNodeSchema.safeParse(layout);
636
- if (!result.success) {
637
- throw new DefinitionValidationError(`Invalid layout for id "${id}"`, {
638
- failures: [{ id, issues: result.error.issues }]
639
- });
640
- }
641
- layouts.set(id, layout);
642
- };
643
- const remove = (id) => {
644
- layouts.delete(id);
645
- };
646
- const list = () => Array.from(layouts.keys());
647
- const resolveReferences = (layout) => {
648
- if (isLayoutRefNode(layout)) {
649
- const target = layouts.get(layout.ref);
650
- if (target === void 0) return layout;
651
- return resolveReferences(target);
652
- }
653
- if (Array.isArray(layout)) {
654
- return layout.map(resolveReferences);
655
- }
656
- if (isComponentNode(layout)) {
657
- const children = layout.children;
658
- let resolvedChildren;
659
- if (children === void 0) {
660
- resolvedChildren = void 0;
661
- } else if (Array.isArray(children)) {
662
- resolvedChildren = children.map(resolveReferences);
663
- } else {
664
- resolvedChildren = resolveReferences(children);
665
- }
666
- return {
667
- ...layout,
668
- ...resolvedChildren === void 0 ? {} : { children: resolvedChildren }
669
- };
670
- }
671
- if (isConditionalNode(layout)) {
672
- return {
673
- ...layout,
674
- then: resolveReferences(layout.then),
675
- ...layout.else === void 0 ? {} : { else: resolveReferences(layout.else) }
676
- };
677
- }
678
- if (isLoopNode(layout)) {
679
- return {
680
- ...layout,
681
- do: resolveReferences(layout.do)
682
- };
683
- }
684
- return layout;
685
- };
686
- return { get, set, delete: remove, list, resolveReferences };
687
- };
688
-
689
- // src/layout/registry.ts
690
- var hasOwn = (value, key) => Object.prototype.hasOwnProperty.call(value, key);
691
- var isComponentMeta = (value) => {
692
- if (typeof value !== "object" || value === null) return false;
693
- return true;
694
- };
695
- var extractStaticMeta = (component) => {
696
- if (typeof component !== "function" && (typeof component !== "object" || component === null)) {
697
- return void 0;
698
- }
699
- const host = component;
700
- if (!hasOwn(host, "meta")) return void 0;
701
- const candidate = host.meta;
702
- if (!isComponentMeta(candidate)) return void 0;
703
- return candidate;
704
- };
705
- var isEntryShape = (value) => {
706
- if (typeof value !== "object" || value === null) return false;
707
- return hasOwn(value, "component");
708
- };
709
- var createComponentRegistry = () => {
710
- const entries = /* @__PURE__ */ new Map();
711
- const register = (name, component, meta) => {
712
- const staticMeta = extractStaticMeta(component);
713
- const merged = { ...staticMeta ?? {}, ...meta ?? {} };
714
- entries.set(name, { component, meta: merged });
715
- };
716
- const registerAll = (batch) => {
717
- for (const name of Object.keys(batch)) {
718
- const input = batch[name];
719
- if (input === void 0) continue;
720
- if (isEntryShape(input)) {
721
- register(name, input.component, input.meta);
722
- } else {
723
- register(name, input);
724
- }
725
- }
726
- };
727
- const get = (name) => entries.get(name);
728
- const has2 = (name) => entries.has(name);
729
- const list = () => Array.from(entries.keys());
730
- return { register, registerAll, get, has: has2, list };
731
- };
732
-
733
- // src/shared/event-bus/scope-dispatch.ts
734
- var scopeDispatch = (dispatch, origin) => {
735
- return (event) => dispatch(event.origin === void 0 ? { ...event, origin } : event);
736
- };
737
-
738
- // src/shell/slot-names.ts
739
- var CANVAS_SLOT_NAME = "CanvasSlot";
740
- var ACTION_SLOT_NAME = "ActionSlot";
741
-
742
- // src/shell/head.ts
743
- var ATTRIBUTE_NAME = /^[A-Za-z][A-Za-z0-9:._-]*$/;
744
- var DATA_TYPE = /^application\/([a-z0-9.-]+\+)?json$/i;
745
- var written = (value) => {
746
- if (typeof value === "string") return value.trim() === "" ? void 0 : value;
747
- if (typeof value === "number") return String(value);
748
- return value === true ? "" : void 0;
749
- };
750
- var attributesOf = (what, props, skip = []) => {
751
- const attributes = {};
752
- for (const [name, value] of Object.entries(props)) {
753
- if (skip.includes(name)) continue;
754
- if (!ATTRIBUTE_NAME.test(name)) return { refused: `${what}: "${name}" is not an attribute\u2019s name` };
755
- if (/^on/i.test(name)) return { refused: `${what}: \`${name}\` is a handler, and a layout does not run` };
756
- const text = written(value);
757
- if (text !== void 0) attributes[name] = text;
758
- }
759
- return { attributes };
760
- };
761
- var has = (attributes, name) => Object.keys(attributes).some((key) => key.toLowerCase() === name);
762
- var valueOf = (attributes, name) => Object.entries(attributes).find(([key]) => key.toLowerCase() === name)?.[1] ?? "";
763
- var textOf = (nodes) => nodes.map((node) => node.type === "text" ? node.value : node.type === "fragment" ? textOf(node.children) : "").join("");
764
- var titleOf = (node) => {
765
- const text = textOf(node.children).trim();
766
- return text === "" ? void 0 : { element: { tag: "title", attributes: {}, text } };
767
- };
768
- var metaOf = (node) => {
769
- const read = attributesOf(HEAD_META_NAME, node.props);
770
- if ("refused" in read) return read;
771
- if (has(read.attributes, "http-equiv")) return { refused: `${HEAD_META_NAME}: \`http-equiv\` instructs the browser, and a layout does not` };
772
- return has(read.attributes, "content") ? { element: { tag: "meta", attributes: read.attributes } } : void 0;
773
- };
774
- var linkOf = (node) => {
775
- const read = attributesOf(HEAD_LINK_NAME, node.props);
776
- if ("refused" in read) return read;
777
- if (valueOf(read.attributes, "rel").toLowerCase().split(/\s+/).includes("stylesheet")) return { refused: `${HEAD_LINK_NAME}: a stylesheet styles the page, and a layout does not` };
778
- return has(read.attributes, "href") ? { element: { tag: "link", attributes: read.attributes } } : void 0;
779
- };
780
- var scriptOf = (node) => {
781
- const read = attributesOf(HEAD_SCRIPT_NAME, node.props, ["data"]);
782
- if ("refused" in read) return read;
783
- if (has(read.attributes, "src")) return { refused: `${HEAD_SCRIPT_NAME}: a script with a \`src\` runs, and a layout does not` };
784
- const type = valueOf(read.attributes, "type");
785
- if (!DATA_TYPE.test(type)) return { refused: `${HEAD_SCRIPT_NAME}: only a data block may be written (a JSON \`type\`), and "${type}" is not one` };
786
- const data = node.props["data"];
787
- if (data === void 0 || data === null || data === "") return void 0;
788
- return { element: { tag: "script", attributes: read.attributes, text: JSON.stringify(data) } };
789
- };
790
- var READERS = {
791
- [HEAD_TITLE_NAME]: titleOf,
792
- [HEAD_META_NAME]: metaOf,
793
- [HEAD_LINK_NAME]: linkOf,
794
- [HEAD_SCRIPT_NAME]: scriptOf
795
- };
796
- var isHeadNode = (node) => node.type === "component" && node.name === HEAD_NAME;
797
- var headOf = (api) => {
798
- let heads = 0;
799
- const said = [];
800
- const refused = [];
801
- const open = /* @__PURE__ */ new Set();
802
- const hold = (nodes, action) => {
803
- for (const node of nodes) {
804
- if (node.type === "fragment") {
805
- hold(node.children, action);
806
- continue;
807
- }
808
- if (node.type === "error") {
809
- refused.push(`${HEAD_NAME}: ${node.message}`);
810
- continue;
811
- }
812
- if (node.type !== "component") continue;
813
- const read = READERS[node.name];
814
- if (read === void 0) {
815
- refused.push(`${HEAD_NAME}: "${node.name}" is not something a head holds`);
816
- continue;
817
- }
818
- const found = read(node);
819
- if (found === void 0) continue;
820
- if ("refused" in found) {
821
- refused.push(found.refused);
822
- continue;
823
- }
824
- const key = headKeyOf(found.element);
825
- const earlier = key === void 0 ? -1 : said.findIndex((other) => headKeyOf(other.element) === key);
826
- if (earlier >= 0) said.splice(earlier, 1);
827
- said.push({ element: found.element, action });
828
- }
829
- };
830
- const walk = (nodes, action) => {
831
- for (const node of nodes) {
832
- if (node.type === "fragment") {
833
- walk(node.children, action);
834
- continue;
835
- }
836
- if (node.type !== "component") continue;
837
- if (node.name === HEAD_NAME) {
838
- heads += 1;
839
- hold(node.children, action);
840
- continue;
841
- }
842
- if (node.name === CANVAS_SLOT_NAME) {
843
- const canvasId = node.props["canvasId"];
844
- if (typeof canvasId !== "string" || canvasId === "" || open.has(canvasId)) continue;
845
- open.add(canvasId);
846
- walk(api.canvasTree(canvasId), void 0);
847
- open.delete(canvasId);
848
- continue;
849
- }
850
- const definitionId = node.name === ACTION_SLOT_NAME ? node.props["definitionId"] : void 0;
851
- walk(node.children, typeof definitionId === "string" ? definitionId : action);
852
- }
853
- };
854
- walk(api.frame(), void 0);
855
- if (heads === 0) return void 0;
856
- const actions = [...new Set(said.flatMap((one) => one.action === void 0 ? [] : [one.action]))];
857
- return { elements: said.map((one) => one.element), actions, refused };
858
- };
859
-
860
- // src/shell/view.ts
861
- var hasVisibleContent = (nodes) => nodes.some((node) => {
862
- if (node.type === "text") return node.value !== "";
863
- if (node.type === "fragment") return hasVisibleContent(node.children);
864
- if (node.type === "component" && node.name === ACTION_SLOT_NAME) return hasVisibleContent(node.children);
865
- if (isHeadNode(node)) return false;
866
- return true;
32
+ Object.defineProperty(exports, "NovaErrorBoundary", {
33
+ enumerable: true,
34
+ get: function () { return chunkWGPFR7MN_cjs.NovaErrorBoundary; }
867
35
  });
868
- var canvasTreeOf = (shell, canvasId) => {
869
- const tree = shell.flattenRenderTree(shell.getCanvasRenderTree(canvasId));
870
- return hasVisibleContent(tree) ? tree : [];
871
- };
872
- var shellView = (shell) => ({
873
- api: {
874
- frame: () => shell.getShellRenderTree(),
875
- canvasTree: (canvasId) => canvasTreeOf(shell, canvasId),
876
- // An event that names no origin belongs to the canvas's ACTIVE instance — on
877
- // a card deck that is the only one drawn. One that names its own (an
878
- // adapter stamps it at the instance boundary, `scopeDispatch`) keeps it. A
879
- // canvas with nothing mounted dispatches unstamped.
880
- dispatch: (canvasId, event) => {
881
- const active = shell.getState().canvases[canvasId]?.active;
882
- shell.dispatch(event.origin === void 0 && active !== void 0 ? { ...event, origin: active.id } : event);
883
- },
884
- publish: (channel, payload) => shell.publish(channel, payload)
885
- },
886
- subscribe: (listener) => {
887
- let pending = false;
888
- let stopped = false;
889
- const changed = () => {
890
- if (pending || stopped) return;
891
- pending = true;
892
- queueMicrotask(() => {
893
- pending = false;
894
- if (!stopped) listener();
895
- });
896
- };
897
- const offState = shell.onStateChange(changed);
898
- const offData = shell.onDataChange(changed);
899
- return () => {
900
- stopped = true;
901
- offState();
902
- offData();
903
- };
904
- }
36
+ Object.defineProperty(exports, "NovaLayout", {
37
+ enumerable: true,
38
+ get: function () { return chunkWGPFR7MN_cjs.NovaLayout; }
905
39
  });
906
-
907
- // src/document/place-head.ts
908
- var HEAD_MARK = "data-nova-head";
909
- var OWN_MARK = "data-nova-own";
910
-
911
- // src/document/head-keeper.ts
912
- var TAGS2 = ["title", "meta", "link"];
913
- var keyOfNode = (node) => {
914
- const tag = TAGS2.find((name) => name === node.tagName.toLowerCase());
915
- if (tag !== "title" && tag !== "meta" && tag !== "link") return void 0;
916
- return headKeyOf({ tag, attributes: Object.fromEntries([...node.attributes].map((attribute) => [attribute.name, attribute.value])) });
917
- };
918
- var createHeadKeeper = (doc) => {
919
- let mine = [];
920
- let away = [];
921
- let said;
922
- const built = (element) => {
923
- const node = doc.createElement(element.tag);
924
- for (const [name, value] of Object.entries(element.attributes)) node.setAttribute(name, value);
925
- node.setAttribute(HEAD_MARK, "");
926
- if (element.text !== void 0) node.textContent = element.text;
927
- return node;
928
- };
929
- const adopt = () => {
930
- mine = [...doc.head.querySelectorAll(`[${HEAD_MARK}]`)];
931
- const view = doc.defaultView;
932
- for (const stash of doc.head.querySelectorAll(`template[${OWN_MARK}]`)) {
933
- if (view === null || !(stash instanceof view.HTMLTemplateElement)) continue;
934
- for (const child of [...stash.content.children]) {
935
- const key = keyOfNode(child);
936
- if (key !== void 0) away.push({ key, node: doc.importNode(child, true), before: null });
937
- }
938
- stash.remove();
939
- }
940
- };
941
- return (elements) => {
942
- const now = elements ?? [];
943
- const next = JSON.stringify(now);
944
- if (said === void 0) {
945
- if (now.length === 0) return;
946
- adopt();
947
- }
948
- if (next === said) return;
949
- said = next;
950
- for (const node of mine) node.remove();
951
- mine = now.map(built);
952
- const keys = new Set(now.flatMap((element) => headKeyOf(element) ?? []));
953
- for (const node of [...doc.head.children]) {
954
- const key = keyOfNode(node);
955
- if (key === void 0 || !keys.has(key)) continue;
956
- away.push({ key, node, before: node.nextSibling });
957
- node.remove();
958
- }
959
- const [back, still] = [away.filter((gone) => !keys.has(gone.key)), away.filter((gone) => keys.has(gone.key))];
960
- for (const gone of [...back].reverse()) doc.head.insertBefore(gone.node, gone.before !== null && gone.before.parentNode === doc.head ? gone.before : null);
961
- away = still;
962
- doc.head.append(...mine);
963
- };
964
- };
965
-
966
- // src/document/shell-head.ts
967
- var createShellHead = (shell) => {
968
- const view = shellView(shell);
969
- let present = 0;
970
- let keep;
971
- let queued = false;
972
- const read = () => {
973
- if (queued || typeof document === "undefined") return;
974
- queued = true;
975
- queueMicrotask(() => {
976
- queued = false;
977
- keep ??= createHeadKeeper(document);
978
- keep(present > 0 ? headOf(view.api)?.elements : void 0);
979
- });
980
- };
981
- return {
982
- enter: () => {
983
- present += 1;
984
- read();
985
- },
986
- leave: () => {
987
- present -= 1;
988
- read();
989
- },
990
- watch: () => view.subscribe(() => {
991
- if (present > 0) read();
992
- })
993
- };
994
- };
995
- var ShellHeadContext = react.createContext(void 0);
996
- var HeadMark = () => {
997
- const head = react.useContext(ShellHeadContext);
998
- react.useEffect(() => {
999
- if (head === void 0) return void 0;
1000
- head.enter();
1001
- return head.leave;
1002
- }, [head]);
1003
- return null;
1004
- };
1005
- var ShellHeadProvider = ({ shell, children }) => {
1006
- const head = react.useMemo(() => createShellHead(shell), [shell]);
1007
- react.useEffect(() => head.watch(), [head]);
1008
- return /* @__PURE__ */ jsxRuntime.jsx(ShellHeadContext.Provider, { value: head, children });
1009
- };
1010
- var noopDispatch = () => {
1011
- };
1012
- var noopPublish = () => {
1013
- };
1014
- var NovaRenderProvider = ({
1015
- registry,
1016
- dispatch = noopDispatch,
1017
- publish = noopPublish,
1018
- slotWrapper,
1019
- fallback,
1020
- textWrapper,
1021
- errorMarker,
1022
- children
1023
- }) => {
1024
- const value = react.useMemo(
1025
- () => ({ registry, dispatch, publish, slotWrapper, fallback, textWrapper, errorMarker }),
1026
- [registry, dispatch, publish, slotWrapper, fallback, textWrapper, errorMarker]
1027
- );
1028
- return /* @__PURE__ */ jsxRuntime.jsx(NovaRenderContext.Provider, { value, children });
1029
- };
1030
- var NovaShellProvider = ({
1031
- shell,
1032
- registry,
1033
- slotWrapper,
1034
- children
1035
- }) => {
1036
- const dispatch = react.useMemo(() => (event) => shell.dispatch(event), [shell]);
1037
- const publish = react.useMemo(
1038
- () => (channel, payload) => shell.publish(channel, payload),
1039
- [shell]
1040
- );
1041
- const resolvedRegistry = registry ?? shell.registry;
1042
- return /* @__PURE__ */ jsxRuntime.jsx(NovaShellContext.Provider, { value: shell, children: /* @__PURE__ */ jsxRuntime.jsx(
1043
- NovaRenderProvider,
1044
- {
1045
- registry: resolvedRegistry,
1046
- dispatch,
1047
- publish,
1048
- slotWrapper,
1049
- children: /* @__PURE__ */ jsxRuntime.jsx(ShellHeadProvider, { shell, children })
1050
- }
1051
- ) });
1052
- };
1053
- var ErrorMarker = ({ code, message }) => /* @__PURE__ */ jsxRuntime.jsx("span", { "data-nova-error": code, role: "alert", children: `[${code}] ${message}` });
1054
- var RenderNodeView = ({ node }) => {
1055
- const ctx = react.useContext(NovaRenderContext);
1056
- if (ctx === void 0) {
1057
- throw new Error("RenderNodeView must be used inside <NovaRenderProvider>");
1058
- }
1059
- if (node.type === "text") {
1060
- const TextWrap = ctx.textWrapper;
1061
- return TextWrap === void 0 ? /* @__PURE__ */ jsxRuntime.jsx(react.Fragment, { children: node.value }) : /* @__PURE__ */ jsxRuntime.jsx(TextWrap, { children: node.value });
1062
- }
1063
- if (node.type === "fragment") {
1064
- return /* @__PURE__ */ jsxRuntime.jsx(RenderTree, { nodes: node.children });
1065
- }
1066
- if (node.type === "error") {
1067
- const Marker = ctx.errorMarker ?? ErrorMarker;
1068
- return /* @__PURE__ */ jsxRuntime.jsx(Marker, { code: node.code, message: node.message });
1069
- }
1070
- if (isHeadNode(node)) return /* @__PURE__ */ jsxRuntime.jsx(HeadMark, {});
1071
- const entry = ctx.registry.get(node.name);
1072
- const Component2 = entry !== void 0 ? entry.component : ctx.fallback;
1073
- if (Component2 === void 0) {
1074
- return /* @__PURE__ */ jsxRuntime.jsx(ErrorMarker, { code: "COMPONENT_NOT_FOUND", message: node.name });
1075
- }
1076
- const props = { ...node.props };
1077
- if (node.model !== void 0) {
1078
- props[NOVA_MODEL_PROP] = { ref: node.model.ref, path: node.model.path };
1079
- }
1080
- if (node.ref !== void 0) {
1081
- props[NOVA_REF_PROP] = node.ref;
1082
- }
1083
- const viewOf = (child, i) => /* @__PURE__ */ jsxRuntime.jsx(RenderNodeView, { node: child }, renderNodeKey(child, i));
1084
- if (!node.children.some(isHeadNode)) {
1085
- return react.createElement(Component2, props, node.children.length === 0 ? void 0 : node.children.map(viewOf));
1086
- }
1087
- const views = node.children.map((child, i) => ({ head: isHeadNode(child), view: viewOf(child, i) }));
1088
- const shown = views.filter((child) => !child.head).map((child) => child.view);
1089
- return /* @__PURE__ */ jsxRuntime.jsxs(react.Fragment, { children: [
1090
- react.createElement(Component2, props, shown.length === 0 ? void 0 : shown),
1091
- views.filter((child) => child.head).map((child) => child.view)
1092
- ] });
1093
- };
1094
- var RenderTree = ({ nodes }) => /* @__PURE__ */ jsxRuntime.jsx(react.Fragment, { children: nodes.map((node, i) => /* @__PURE__ */ jsxRuntime.jsx(RenderNodeView, { node }, renderNodeKey(node, i))) });
1095
- var NovaErrorBoundary = class extends react.Component {
1096
- state = { error: void 0 };
1097
- static getDerivedStateFromError(error) {
1098
- return { error };
1099
- }
1100
- componentDidCatch(error, info) {
1101
- const handler = this.props.onError;
1102
- if (handler !== void 0) handler(error, info);
1103
- }
1104
- render() {
1105
- const { error } = this.state;
1106
- if (error !== void 0) {
1107
- const fallback = this.props.fallback;
1108
- if (fallback !== void 0) return fallback(error);
1109
- return /* @__PURE__ */ jsxRuntime.jsx("div", { "data-nova-error-boundary": "true", role: "alert", children: error.message });
1110
- }
1111
- return this.props.children;
1112
- }
1113
- };
1114
- var StackPropsSchema = zod.z.object({
1115
- direction: zod.z.enum(["row", "column"]).optional().describe("Flex direction. Default: column."),
1116
- gap: zod.z.number().int().min(0).optional().describe("Gap between children in pixels. Default: 0."),
1117
- align: zod.z.enum(["start", "center", "end", "stretch"]).optional().describe("Cross-axis alignment. Default: stretch."),
1118
- justify: zod.z.enum(["start", "center", "end", "between", "around"]).optional().describe("Main-axis justification. Default: start."),
1119
- padding: zod.z.number().int().min(0).optional().describe("Inner padding in pixels. Default: 0."),
1120
- wrap: zod.z.boolean().optional().describe("Whether children wrap to a new line. Default: false.")
1121
- }).strict().describe("Flex container that arranges children in a row or column.");
1122
- var TextPropsSchema = zod.z.object({
1123
- as: zod.z.enum(["span", "p", "h1", "h2", "h3", "h4"]).optional().describe("HTML element to render. Default: span."),
1124
- size: zod.z.enum(["sm", "md", "lg", "xl", "2xl"]).optional().describe("Font size token. Default: md."),
1125
- weight: zod.z.enum(["normal", "medium", "bold"]).optional().describe("Font weight token. Default: normal."),
1126
- color: zod.z.string().optional().describe("CSS color string (open set). Default: inherit.")
1127
- }).strict().describe("Text element with semantic typography props.");
1128
- var InputPropsSchema = zod.z.object({
1129
- type: zod.z.enum(["text", "number", "email", "password"]).optional().describe("Input type. Default: text."),
1130
- placeholder: zod.z.string().optional().describe("Placeholder text shown when empty."),
1131
- disabled: zod.z.boolean().optional().describe("Whether the input is disabled. Default: false."),
1132
- value: zod.z.string().optional().describe("Current value. Typically supplied via model binding."),
1133
- debounce: zod.z.number().optional().describe("Milliseconds to coalesce keystrokes before dispatching ui:model. Default: 0 (every keystroke). Set it when the shell is remote to cut round-trips.")
1134
- }).strict().describe("Text input bound to data via the `model` field on the layout node.");
1135
- var ButtonPropsSchema = zod.z.object({
1136
- label: zod.z.string().optional().describe("Button label. If absent, children are used."),
1137
- variant: zod.z.enum(["primary", "secondary", "ghost"]).optional().describe("Visual variant. Default: primary."),
1138
- disabled: zod.z.boolean().optional().describe("Whether the button is disabled. Default: false.")
1139
- }).strict().describe("Clickable button. Click events fire as `ui:click` with the layout node's ref.");
1140
- var BoxPropsSchema = zod.z.object({
1141
- padding: zod.z.number().int().min(0).optional().describe("Inner padding in pixels. Default: 0."),
1142
- background: zod.z.string().optional().describe("CSS background color or value."),
1143
- border: zod.z.boolean().optional().describe("Whether to show a 1px border. Default: false."),
1144
- radius: zod.z.number().int().min(0).optional().describe("Border radius in pixels. Default: 0.")
1145
- }).strict().describe("Generic container with basic styling props. Use Stack for layout, Box for visual wrapping.");
1146
- var PanelPropsSchema = zod.z.object({
1147
- title: zod.z.string().optional().describe("Optional header title."),
1148
- backRef: zod.z.string().optional().describe("When set, the header grows a \u2190 (before the title) that fires ui:click with this ref."),
1149
- closeRef: zod.z.string().optional().describe("When set, the header grows a \u2715 that fires ui:click with this ref.")
1150
- }).strict().describe("A framed, elevated surface with an optional title.");
1151
- var JsonTreePropsSchema = zod.z.object({
1152
- value: zod.z.unknown().optional().describe("The value to render."),
1153
- label: zod.z.string().optional().describe("A name for the root node.")
1154
- }).strict().describe("A collapsible view of any JSON value.");
1155
- var CanvasSlotPropsSchema = zod.z.object({
1156
- canvasId: zod.z.string().optional().describe('Id of the canvas to render. Usually bound from a loop, e.g. "$.c.id".')
1157
- }).strict().describe("Renders a canvas by id, recursing into its actionLayout. Resolves to nothing when canvasId is missing.");
1158
- var ActionSlotPropsSchema = zod.z.object({
1159
- instanceId: zod.z.string().optional().describe('Id of the action instance to render. Usually bound from canvas scope, e.g. "$.active.id" or "$.i.id".')
1160
- }).strict().describe("Renders an action instance by id. Resolves to nothing when instanceId is missing.");
1161
- var ALIGN_MAP = {
1162
- start: "flex-start",
1163
- center: "center",
1164
- end: "flex-end",
1165
- stretch: "stretch"
1166
- };
1167
- var JUSTIFY_MAP = {
1168
- start: "flex-start",
1169
- center: "center",
1170
- end: "flex-end",
1171
- between: "space-between",
1172
- around: "space-around"
1173
- };
1174
- var Stack = ({
1175
- direction,
1176
- gap,
1177
- align,
1178
- justify,
1179
- padding,
1180
- wrap,
1181
- children
1182
- }) => {
1183
- const style = {
1184
- display: "flex",
1185
- flexDirection: direction ?? "column",
1186
- gap: gap ?? 0,
1187
- alignItems: ALIGN_MAP[align ?? "stretch"],
1188
- justifyContent: JUSTIFY_MAP[justify ?? "start"],
1189
- padding: padding ?? 0,
1190
- flexWrap: wrap === true ? "wrap" : "nowrap"
1191
- };
1192
- return /* @__PURE__ */ jsxRuntime.jsx("div", { style, children });
1193
- };
1194
- Stack.meta = {
1195
- description: "Flex container that arranges children in a row or column.",
1196
- propsSchema: StackPropsSchema
1197
- };
1198
- var SIZE_MAP = {
1199
- sm: "12px",
1200
- md: "14px",
1201
- lg: "16px",
1202
- xl: "20px",
1203
- "2xl": "24px"
1204
- };
1205
- var WEIGHT_MAP = {
1206
- normal: 400,
1207
- medium: 500,
1208
- bold: 700
1209
- };
1210
- var Text = ({
1211
- as,
1212
- size,
1213
- weight,
1214
- color,
1215
- children
1216
- }) => {
1217
- const tag = as ?? "span";
1218
- const style = {
1219
- fontSize: SIZE_MAP[size ?? "md"],
1220
- fontWeight: WEIGHT_MAP[weight ?? "normal"],
1221
- color: color ?? "inherit"
1222
- };
1223
- return react.createElement(tag, { style }, children);
1224
- };
1225
- Text.meta = {
1226
- description: "Text element with semantic typography props.",
1227
- propsSchema: TextPropsSchema
1228
- };
1229
- var computeStyle = (isDisabled, isFocused, isHovered) => {
1230
- const borderColor = isDisabled ? "#d1d5db" : isFocused ? "#2563eb" : isHovered ? "#9ca3af" : "#d1d5db";
1231
- return {
1232
- padding: "8px 12px",
1233
- border: `1px solid ${borderColor}`,
1234
- borderRadius: 6,
1235
- fontSize: 14,
1236
- background: isDisabled ? "#f9fafb" : "#ffffff",
1237
- color: isDisabled ? "#9ca3af" : "inherit",
1238
- cursor: isDisabled ? "not-allowed" : "text",
1239
- minWidth: 240,
1240
- outline: "none",
1241
- boxShadow: isFocused ? "0 0 0 3px rgba(37, 99, 235, 0.15)" : "none",
1242
- transition: "border-color 150ms, box-shadow 150ms"
1243
- };
1244
- };
1245
- var Input = ({
1246
- type,
1247
- placeholder,
1248
- disabled,
1249
- value,
1250
- debounce,
1251
- novaModel
1252
- }) => {
1253
- const dispatch = useNovaDispatch();
1254
- const [isHovered, setIsHovered] = react.useState(false);
1255
- const [draft, setDraft] = react.useState(null);
1256
- const isFocused = draft !== null;
1257
- const shown = draft ?? value ?? "";
1258
- const isDisabled = disabled ?? false;
1259
- const debounceMs = debounce ?? 0;
1260
- const timer = react.useRef(void 0);
1261
- const clearPending = () => {
1262
- if (timer.current !== void 0) {
1263
- clearTimeout(timer.current);
1264
- timer.current = void 0;
1265
- }
1266
- };
1267
- react.useEffect(() => clearPending, []);
1268
- const fire = (next) => {
1269
- if (novaModel === void 0) return;
1270
- dispatch({ type: "ui:model", ref: novaModel.ref, payload: next });
1271
- };
1272
- const onChange = (event) => {
1273
- const next = event.target.value;
1274
- setDraft(next);
1275
- if (debounceMs > 0) {
1276
- clearPending();
1277
- timer.current = setTimeout(() => {
1278
- timer.current = void 0;
1279
- fire(next);
1280
- }, debounceMs);
1281
- } else {
1282
- fire(next);
1283
- }
1284
- };
1285
- const onFocus = () => setDraft(value ?? "");
1286
- const onBlur = () => {
1287
- if (timer.current !== void 0 && draft !== null) {
1288
- clearPending();
1289
- fire(draft);
1290
- }
1291
- setDraft(null);
1292
- };
1293
- return /* @__PURE__ */ jsxRuntime.jsx(
1294
- "input",
1295
- {
1296
- type: type ?? "text",
1297
- placeholder,
1298
- disabled: isDisabled,
1299
- value: shown,
1300
- onChange,
1301
- onFocus,
1302
- onBlur,
1303
- onMouseEnter: () => setIsHovered(true),
1304
- onMouseLeave: () => setIsHovered(false),
1305
- style: computeStyle(isDisabled, isFocused, isHovered)
1306
- }
1307
- );
1308
- };
1309
- Input.meta = {
1310
- description: "Text input bound to data via the `model` field on the layout node.",
1311
- propsSchema: InputPropsSchema
1312
- };
1313
- var BASE_STYLE = {
1314
- borderRadius: 6,
1315
- fontSize: 14,
1316
- fontWeight: 500,
1317
- transition: "background-color 100ms"
1318
- };
1319
- var primaryStyle = (isDisabled, isHovered, isActive) => ({
1320
- ...BASE_STYLE,
1321
- padding: "8px 16px",
1322
- border: "none",
1323
- color: "#ffffff",
1324
- cursor: isDisabled ? "not-allowed" : "pointer",
1325
- background: isDisabled ? "#93c5fd" : isActive ? "#1e40af" : isHovered ? "#1d4ed8" : "#2563eb"
40
+ Object.defineProperty(exports, "NovaRenderProvider", {
41
+ enumerable: true,
42
+ get: function () { return chunkWGPFR7MN_cjs.NovaRenderProvider; }
1326
43
  });
1327
- var secondaryStyle = (isDisabled, isHovered, isActive) => ({
1328
- ...BASE_STYLE,
1329
- padding: "8px 16px",
1330
- border: `1px solid ${isDisabled ? "#e5e7eb" : isHovered ? "#9ca3af" : "#d1d5db"}`,
1331
- color: isDisabled ? "#9ca3af" : "#1f2937",
1332
- cursor: isDisabled ? "not-allowed" : "pointer",
1333
- background: isDisabled ? "#ffffff" : isActive ? "#e5e7eb" : isHovered ? "#f3f4f6" : "#ffffff"
44
+ Object.defineProperty(exports, "NovaShell", {
45
+ enumerable: true,
46
+ get: function () { return chunkWGPFR7MN_cjs.NovaShell; }
1334
47
  });
1335
- var ghostStyle = (isDisabled, isHovered, isActive) => ({
1336
- ...BASE_STYLE,
1337
- padding: "8px 12px",
1338
- border: "none",
1339
- color: isDisabled ? "#93c5fd" : "#2563eb",
1340
- cursor: isDisabled ? "not-allowed" : "pointer",
1341
- background: isDisabled ? "transparent" : isActive ? "#dbeafe" : isHovered ? "#eff6ff" : "transparent"
48
+ Object.defineProperty(exports, "NovaShellProvider", {
49
+ enumerable: true,
50
+ get: function () { return chunkWGPFR7MN_cjs.NovaShellProvider; }
51
+ });
52
+ Object.defineProperty(exports, "RenderNodeView", {
53
+ enumerable: true,
54
+ get: function () { return chunkWGPFR7MN_cjs.RenderNodeView; }
55
+ });
56
+ Object.defineProperty(exports, "RenderTree", {
57
+ enumerable: true,
58
+ get: function () { return chunkWGPFR7MN_cjs.RenderTree; }
59
+ });
60
+ Object.defineProperty(exports, "useActionData", {
61
+ enumerable: true,
62
+ get: function () { return chunkWGPFR7MN_cjs.useActionData; }
63
+ });
64
+ Object.defineProperty(exports, "useActionStatus", {
65
+ enumerable: true,
66
+ get: function () { return chunkWGPFR7MN_cjs.useActionStatus; }
67
+ });
68
+ Object.defineProperty(exports, "useCanvas", {
69
+ enumerable: true,
70
+ get: function () { return chunkWGPFR7MN_cjs.useCanvas; }
71
+ });
72
+ Object.defineProperty(exports, "useCanvasRenderTree", {
73
+ enumerable: true,
74
+ get: function () { return chunkWGPFR7MN_cjs.useCanvasRenderTree; }
75
+ });
76
+ Object.defineProperty(exports, "useNovaDispatch", {
77
+ enumerable: true,
78
+ get: function () { return chunkWGPFR7MN_cjs.useNovaDispatch; }
79
+ });
80
+ Object.defineProperty(exports, "useNovaPublish", {
81
+ enumerable: true,
82
+ get: function () { return chunkWGPFR7MN_cjs.useNovaPublish; }
83
+ });
84
+ Object.defineProperty(exports, "useNovaRegistry", {
85
+ enumerable: true,
86
+ get: function () { return chunkWGPFR7MN_cjs.useNovaRegistry; }
87
+ });
88
+ Object.defineProperty(exports, "useRenderTree", {
89
+ enumerable: true,
90
+ get: function () { return chunkWGPFR7MN_cjs.useRenderTree; }
91
+ });
92
+ Object.defineProperty(exports, "useShell", {
93
+ enumerable: true,
94
+ get: function () { return chunkWGPFR7MN_cjs.useShell; }
95
+ });
96
+ Object.defineProperty(exports, "useShellRenderTree", {
97
+ enumerable: true,
98
+ get: function () { return chunkWGPFR7MN_cjs.useShellRenderTree; }
99
+ });
100
+ Object.defineProperty(exports, "useShellState", {
101
+ enumerable: true,
102
+ get: function () { return chunkWGPFR7MN_cjs.useShellState; }
103
+ });
104
+ Object.defineProperty(exports, "useSlotWrapper", {
105
+ enumerable: true,
106
+ get: function () { return chunkWGPFR7MN_cjs.useSlotWrapper; }
1342
107
  });
1343
- var styleFor = (variant, isDisabled, isHovered, isActive) => {
1344
- if (variant === "primary") return primaryStyle(isDisabled, isHovered, isActive);
1345
- if (variant === "secondary") return secondaryStyle(isDisabled, isHovered, isActive);
1346
- return ghostStyle(isDisabled, isHovered, isActive);
1347
- };
1348
- var Button = ({
1349
- label,
1350
- variant,
1351
- disabled,
1352
- novaRef,
1353
- children
1354
- }) => {
1355
- const dispatch = useNovaDispatch();
1356
- const [isHovered, setIsHovered] = react.useState(false);
1357
- const [isActive, setIsActive] = react.useState(false);
1358
- const isDisabled = disabled ?? false;
1359
- const style = styleFor(variant ?? "primary", isDisabled, isHovered, isActive);
1360
- const onClick = (_event) => {
1361
- if (isDisabled) return;
1362
- if (novaRef === void 0) return;
1363
- dispatch({ type: "ui:click", ref: novaRef });
1364
- };
1365
- return /* @__PURE__ */ jsxRuntime.jsx(
1366
- "button",
1367
- {
1368
- type: "button",
1369
- disabled: isDisabled,
1370
- style,
1371
- onClick,
1372
- onMouseEnter: () => setIsHovered(true),
1373
- onMouseLeave: () => {
1374
- setIsHovered(false);
1375
- setIsActive(false);
1376
- },
1377
- onMouseDown: () => setIsActive(true),
1378
- onMouseUp: () => setIsActive(false),
1379
- children: label ?? children
1380
- }
1381
- );
1382
- };
1383
- Button.meta = {
1384
- description: "Clickable button. Click events fire as `ui:click` with the layout node's ref.",
1385
- propsSchema: ButtonPropsSchema
1386
- };
1387
- var Box = ({
1388
- padding,
1389
- background,
1390
- border,
1391
- radius,
1392
- children
1393
- }) => {
1394
- const style = {
1395
- padding: padding ?? 0,
1396
- background: background ?? "transparent",
1397
- border: border === true ? "1px solid #e5e7eb" : "none",
1398
- borderRadius: radius ?? 0
1399
- };
1400
- return /* @__PURE__ */ jsxRuntime.jsx("div", { style, children });
1401
- };
1402
- Box.meta = {
1403
- description: "Generic container with basic styling props. Use Stack for layout, Box for visual wrapping.",
1404
- propsSchema: BoxPropsSchema
1405
- };
1406
- var Panel = ({ title, backRef, closeRef, children }) => {
1407
- const dispatch = useNovaDispatch();
1408
- 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: [
1409
- title !== void 0 && /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", alignItems: "center", gap: 6, fontWeight: 600, fontSize: 13, marginBottom: 8 }, children: [
1410
- backRef !== void 0 && /* @__PURE__ */ jsxRuntime.jsx(
1411
- "button",
1412
- {
1413
- type: "button",
1414
- style: { border: "none", background: "none", color: "#6b7280", cursor: "pointer", fontSize: 13, lineHeight: 1, padding: 2 },
1415
- onClick: () => dispatch({ type: "ui:click", ref: backRef }),
1416
- children: "\u2190"
1417
- }
1418
- ),
1419
- /* @__PURE__ */ jsxRuntime.jsx("span", { style: { flex: 1 }, children: title }),
1420
- closeRef !== void 0 && /* @__PURE__ */ jsxRuntime.jsx(
1421
- "button",
1422
- {
1423
- type: "button",
1424
- style: { border: "none", background: "none", color: "#6b7280", cursor: "pointer", fontSize: 13, lineHeight: 1, padding: 2 },
1425
- onClick: () => dispatch({ type: "ui:click", ref: closeRef }),
1426
- children: "\u2715"
1427
- }
1428
- )
1429
- ] }),
1430
- children
1431
- ] });
1432
- };
1433
- Panel.meta = { description: "A framed, elevated surface with an optional title; `closeRef` adds a header \u2715.", propsSchema: PanelPropsSchema };
1434
- var entriesOf = (value) => Array.isArray(value) ? value.map((item, index) => [String(index), item]) : Object.entries(value);
1435
- var JsonNode = ({ value, name }) => {
1436
- if (value !== null && typeof value === "object") {
1437
- const entries = entriesOf(value);
1438
- const shape = Array.isArray(value) ? `[${entries.length}]` : `{${entries.length}}`;
1439
- return /* @__PURE__ */ jsxRuntime.jsxs("details", { children: [
1440
- /* @__PURE__ */ jsxRuntime.jsx("summary", { style: { cursor: "pointer", color: "#6b7280" }, children: name === void 0 ? shape : `${name} ${shape}` }),
1441
- /* @__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)) })
1442
- ] });
1443
- }
1444
- const text = name === void 0 ? JSON.stringify(value) : `${name}: ${JSON.stringify(value)}`;
1445
- return /* @__PURE__ */ jsxRuntime.jsx("div", { style: { whiteSpace: "pre-wrap", wordBreak: "break-word" }, children: text });
1446
- };
1447
- 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 }) });
1448
- JsonTree.meta = { description: "A collapsible view of any JSON value.", propsSchema: JsonTreePropsSchema };
1449
- var CanvasSlot = ({
1450
- canvasId
1451
- }) => {
1452
- const tree = useCanvasRenderTree(canvasId);
1453
- if (canvasId === void 0 || canvasId === "") return null;
1454
- return /* @__PURE__ */ jsxRuntime.jsx(RenderTree, { nodes: tree });
1455
- };
1456
- CanvasSlot.meta = {
1457
- description: "Renders a canvas by id, recursing into its actionLayout.",
1458
- propsSchema: CanvasSlotPropsSchema
1459
- };
1460
- var ActionSlot = ({
1461
- instanceId
1462
- }) => {
1463
- const tree = useRenderTree(instanceId ?? "");
1464
- const slotWrapper = useSlotWrapper();
1465
- const shell = useShell();
1466
- const hasInstance = instanceId !== void 0 && instanceId !== "";
1467
- const ctx = react.useContext(NovaRenderContext);
1468
- const scoped = react.useMemo(() => {
1469
- if (ctx === void 0 || instanceId === void 0 || instanceId === "") return ctx;
1470
- return { ...ctx, dispatch: scopeDispatch(ctx.dispatch, instanceId) };
1471
- }, [ctx, instanceId]);
1472
- if (slotWrapper === void 0) {
1473
- if (!hasInstance) return null;
1474
- return /* @__PURE__ */ jsxRuntime.jsx(NovaRenderContext.Provider, { value: scoped, children: /* @__PURE__ */ jsxRuntime.jsx(RenderTree, { nodes: tree }) });
1475
- }
1476
- const runtime = hasInstance ? shell.getRuntime(instanceId) : void 0;
1477
- const Wrapper = slotWrapper;
1478
- return /* @__PURE__ */ jsxRuntime.jsx(
1479
- Wrapper,
1480
- {
1481
- canvasId: runtime?.instance.canvasId,
1482
- instanceId: hasInstance ? instanceId : void 0,
1483
- action: runtime?.definition,
1484
- children: hasInstance && tree.length ? /* @__PURE__ */ jsxRuntime.jsx(NovaRenderContext.Provider, { value: scoped, children: /* @__PURE__ */ jsxRuntime.jsx(RenderTree, { nodes: tree }) }) : null
1485
- }
1486
- );
1487
- };
1488
- ActionSlot.meta = {
1489
- description: "Renders an action instance by id. Used inside a canvas actionLayout.",
1490
- propsSchema: ActionSlotPropsSchema
1491
- };
1492
-
1493
- // src/adapters/react/components/index.ts
1494
- var registerNovaReactComponents = (registry) => {
1495
- registry.registerAll({
1496
- Stack,
1497
- Text,
1498
- Input,
1499
- Button,
1500
- Box,
1501
- Panel,
1502
- JsonTree,
1503
- CanvasSlot,
1504
- ActionSlot
1505
- });
1506
- };
1507
- var useShell = () => {
1508
- const shell = react.useContext(NovaShellContext);
1509
- if (shell === void 0) {
1510
- throw new Error("useShell must be used inside <NovaShellProvider>");
1511
- }
1512
- return shell;
1513
- };
1514
-
1515
- // src/adapters/react/hooks/use-canvas-render-tree.ts
1516
- var EMPTY2 = [];
1517
- var useCanvasRenderTree = (canvasId) => {
1518
- const shell = useShell();
1519
- const cacheRef = react.useRef(void 0);
1520
- const subscribe = react.useCallback(
1521
- (cb) => shell.onStateChange(() => {
1522
- const tree = canvasId === void 0 ? EMPTY2 : shell.getCanvasRenderTree(canvasId);
1523
- cacheRef.current = { shell, canvasId, tree };
1524
- cb();
1525
- }),
1526
- [shell, canvasId]
1527
- );
1528
- const getSnapshot = react.useCallback(() => {
1529
- const cached = cacheRef.current;
1530
- if (cached !== void 0 && cached.shell === shell && cached.canvasId === canvasId) {
1531
- return cached.tree;
1532
- }
1533
- const tree = canvasId === void 0 ? EMPTY2 : shell.getCanvasRenderTree(canvasId);
1534
- cacheRef.current = { shell, canvasId, tree };
1535
- return tree;
1536
- }, [shell, canvasId]);
1537
- return react.useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
1538
- };
1539
- var useShellRenderTree = () => {
1540
- const shell = useShell();
1541
- const cacheRef = react.useRef(void 0);
1542
- const subscribe = react.useCallback(
1543
- (cb) => shell.onStateChange(() => {
1544
- cacheRef.current = { shell, tree: shell.getShellRenderTree() };
1545
- cb();
1546
- }),
1547
- [shell]
1548
- );
1549
- const getSnapshot = react.useCallback(() => {
1550
- const cached = cacheRef.current;
1551
- if (cached === void 0 || cached.shell !== shell) {
1552
- const tree = shell.getShellRenderTree();
1553
- cacheRef.current = { shell, tree };
1554
- return tree;
1555
- }
1556
- return cached.tree;
1557
- }, [shell]);
1558
- return react.useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
1559
- };
1560
- var ensureReactBuiltins = (registry) => {
1561
- if (registry.has("CanvasSlot")) return;
1562
- registerNovaReactComponents(registry);
1563
- };
1564
- var NovaLayout = ({
1565
- layout,
1566
- data,
1567
- components,
1568
- registry: registryProp,
1569
- store: storeProp,
1570
- builtins = true,
1571
- strict,
1572
- onError,
1573
- phrases,
1574
- phraseKeys,
1575
- onPhraseMiss,
1576
- children
1577
- }) => {
1578
- const [registry] = react.useState(() => {
1579
- if (registryProp !== void 0) return registryProp;
1580
- const reg = createComponentRegistry();
1581
- if (builtins) registerNovaReactComponents(reg);
1582
- if (components !== void 0) reg.registerAll(components);
1583
- return reg;
1584
- });
1585
- const [store] = react.useState(() => storeProp ?? createLayoutStore());
1586
- const nodes = react.useMemo(() => {
1587
- const resolved = typeof layout === "string" ? store.get(layout) : layout;
1588
- if (resolved === void 0) return [];
1589
- return renderLayout(resolved, data ?? {}, {
1590
- store,
1591
- registry,
1592
- ...strict === void 0 ? {} : { strict },
1593
- ...onError === void 0 ? {} : { onError },
1594
- ...phrases === void 0 ? {} : { phrases },
1595
- ...phraseKeys === void 0 ? {} : { phraseKeys },
1596
- ...onPhraseMiss === void 0 ? {} : { onPhraseMiss }
1597
- });
1598
- }, [layout, data, store, registry, strict, onError, phrases, phraseKeys, onPhraseMiss]);
1599
- return /* @__PURE__ */ jsxRuntime.jsxs(NovaRenderProvider, { registry, children: [
1600
- /* @__PURE__ */ jsxRuntime.jsx(RenderTree, { nodes }),
1601
- children
1602
- ] });
1603
- };
1604
- var ShellRenderTreeView = () => {
1605
- const nodes = useShellRenderTree();
1606
- return /* @__PURE__ */ jsxRuntime.jsx(RenderTree, { nodes });
1607
- };
1608
- var NovaShell = ({ shell, registry, slotWrapper, builtins = true }) => {
1609
- const resolvedRegistry = registry ?? shell.registry;
1610
- react.useState(() => {
1611
- if (builtins) ensureReactBuiltins(resolvedRegistry);
1612
- return true;
1613
- });
1614
- return /* @__PURE__ */ jsxRuntime.jsx(NovaShellProvider, { shell, registry: resolvedRegistry, slotWrapper, children: /* @__PURE__ */ jsxRuntime.jsx(ShellRenderTreeView, {}) });
1615
- };
1616
- var CanvasRenderTreeView = ({ canvasId }) => {
1617
- const nodes = useCanvasRenderTree(canvasId);
1618
- return /* @__PURE__ */ jsxRuntime.jsx(RenderTree, { nodes });
1619
- };
1620
- var CanvasInContext = ({ canvasId }) => {
1621
- useShell();
1622
- return /* @__PURE__ */ jsxRuntime.jsx(CanvasRenderTreeView, { canvasId });
1623
- };
1624
- var CanvasStandalone = ({ canvasId, shell, registry, builtins }) => {
1625
- const resolvedRegistry = registry ?? shell.registry;
1626
- react.useState(() => {
1627
- if (builtins) ensureReactBuiltins(resolvedRegistry);
1628
- return true;
1629
- });
1630
- return /* @__PURE__ */ jsxRuntime.jsx(NovaShellProvider, { shell, registry: resolvedRegistry, children: /* @__PURE__ */ jsxRuntime.jsx(CanvasRenderTreeView, { canvasId }) });
1631
- };
1632
- var NovaCanvas = ({ id, shell, registry, builtins = true }) => {
1633
- if (shell === void 0) return /* @__PURE__ */ jsxRuntime.jsx(CanvasInContext, { canvasId: id });
1634
- return /* @__PURE__ */ jsxRuntime.jsx(
1635
- CanvasStandalone,
1636
- {
1637
- canvasId: id,
1638
- shell,
1639
- builtins,
1640
- ...registry === void 0 ? {} : { registry }
1641
- }
1642
- );
1643
- };
1644
- var Nova = {
1645
- Layout: NovaLayout,
1646
- Shell: NovaShell,
1647
- Canvas: NovaCanvas
1648
- };
1649
- var useShellState = () => {
1650
- const shell = useShell();
1651
- const cacheRef = react.useRef(void 0);
1652
- if (cacheRef.current === void 0 || cacheRef.current.shell !== shell) {
1653
- cacheRef.current = { shell, snapshot: shell.getState() };
1654
- }
1655
- const subscribe = react.useCallback(
1656
- (cb) => shell.onStateChange((snapshot) => {
1657
- cacheRef.current = { shell, snapshot };
1658
- cb();
1659
- }),
1660
- [shell]
1661
- );
1662
- const getSnapshot = react.useCallback(() => {
1663
- const cached = cacheRef.current;
1664
- if (cached === void 0 || cached.shell !== shell) {
1665
- const snapshot = shell.getState();
1666
- cacheRef.current = { shell, snapshot };
1667
- return snapshot;
1668
- }
1669
- return cached.snapshot;
1670
- }, [shell]);
1671
- return react.useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
1672
- };
1673
- var useCanvas = (canvasId) => {
1674
- const shell = useShell();
1675
- const cacheRef = react.useRef(void 0);
1676
- const subscribe = react.useCallback(
1677
- (cb) => shell.onCanvasChange(canvasId, (next) => {
1678
- cacheRef.current = { shell, canvasId, state: next };
1679
- cb();
1680
- }),
1681
- [shell, canvasId]
1682
- );
1683
- const getSnapshot = react.useCallback(() => {
1684
- const cached = cacheRef.current;
1685
- if (cached !== void 0 && cached.shell === shell && cached.canvasId === canvasId) {
1686
- return cached.state;
1687
- }
1688
- const state = shell.getCanvasState(canvasId);
1689
- cacheRef.current = { shell, canvasId, state };
1690
- return state;
1691
- }, [shell, canvasId]);
1692
- return react.useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
1693
- };
1694
- var useActionData = (instanceId) => {
1695
- const shell = useShell();
1696
- const cacheRef = react.useRef(void 0);
1697
- const subscribe = react.useCallback(
1698
- (cb) => {
1699
- const runtime = shell.getRuntime(instanceId);
1700
- if (runtime === void 0) return () => {
1701
- };
1702
- return runtime.onDataChange((next) => {
1703
- cacheRef.current = next;
1704
- cb();
1705
- });
1706
- },
1707
- [shell, instanceId]
1708
- );
1709
- const getSnapshot = react.useCallback(() => {
1710
- const runtime = shell.getRuntime(instanceId);
1711
- if (runtime === void 0) {
1712
- cacheRef.current = void 0;
1713
- return void 0;
1714
- }
1715
- const current = runtime.getData();
1716
- if (cacheRef.current !== current) cacheRef.current = current;
1717
- return cacheRef.current;
1718
- }, [shell, instanceId]);
1719
- return react.useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
1720
- };
1721
- var useActionStatus = (instanceId) => {
1722
- const shell = useShell();
1723
- const cacheRef = react.useRef(void 0);
1724
- const subscribe = react.useCallback(
1725
- (cb) => {
1726
- const runtime = shell.getRuntime(instanceId);
1727
- if (runtime === void 0) return () => {
1728
- };
1729
- return runtime.onStatusChange((next) => {
1730
- cacheRef.current = next;
1731
- cb();
1732
- });
1733
- },
1734
- [shell, instanceId]
1735
- );
1736
- const getSnapshot = react.useCallback(() => {
1737
- const runtime = shell.getRuntime(instanceId);
1738
- if (runtime === void 0) {
1739
- cacheRef.current = void 0;
1740
- return void 0;
1741
- }
1742
- const current = runtime.instance.status;
1743
- if (cacheRef.current !== current) cacheRef.current = current;
1744
- return cacheRef.current;
1745
- }, [shell, instanceId]);
1746
- return react.useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
1747
- };
1748
- var EMPTY3 = [];
1749
- var useRenderTree = (instanceId) => {
1750
- const shell = useShell();
1751
- const cacheRef = react.useRef(void 0);
1752
- const subscribe = react.useCallback(
1753
- (cb) => {
1754
- const offState = shell.onStateChange(() => cb());
1755
- const runtime = shell.getRuntime(instanceId);
1756
- if (runtime === void 0) return offState;
1757
- const offData = runtime.onDataChange(() => cb());
1758
- return () => {
1759
- offData();
1760
- offState();
1761
- };
1762
- },
1763
- [shell, instanceId]
1764
- );
1765
- const getSnapshot = react.useCallback(() => {
1766
- const runtime = shell.getRuntime(instanceId);
1767
- if (runtime === void 0) {
1768
- cacheRef.current = void 0;
1769
- return EMPTY3;
1770
- }
1771
- const data = runtime.getData();
1772
- const phrases = shell.getPhrases();
1773
- const cached = cacheRef.current;
1774
- if (cached !== void 0 && cached.data === data && cached.phrases === phrases) return cached.tree;
1775
- const tree = runtime.render();
1776
- cacheRef.current = { data, phrases, tree };
1777
- return tree;
1778
- }, [shell, instanceId]);
1779
- return react.useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
1780
- };
1781
- var useNovaDispatch = () => {
1782
- const ctx = react.useContext(NovaRenderContext);
1783
- if (ctx === void 0) {
1784
- throw new Error("useNovaDispatch must be used inside <NovaRenderProvider>");
1785
- }
1786
- return ctx.dispatch;
1787
- };
1788
- var useNovaPublish = () => {
1789
- const ctx = react.useContext(NovaRenderContext);
1790
- if (ctx === void 0) {
1791
- throw new Error("useNovaPublish must be used inside <NovaRenderProvider>");
1792
- }
1793
- return ctx.publish;
1794
- };
1795
- var useNovaRegistry = () => {
1796
- const ctx = react.useContext(NovaRenderContext);
1797
- if (ctx === void 0) {
1798
- throw new Error("useNovaRegistry must be used inside <NovaRenderProvider>");
1799
- }
1800
- return ctx.registry;
1801
- };
1802
- var useSlotWrapper = () => react.useContext(NovaRenderContext)?.slotWrapper;
1803
-
1804
- exports.ErrorMarker = ErrorMarker;
1805
- exports.Nova = Nova;
1806
- exports.NovaCanvas = NovaCanvas;
1807
- exports.NovaErrorBoundary = NovaErrorBoundary;
1808
- exports.NovaLayout = NovaLayout;
1809
- exports.NovaRenderProvider = NovaRenderProvider;
1810
- exports.NovaShell = NovaShell;
1811
- exports.NovaShellProvider = NovaShellProvider;
1812
- exports.RenderNodeView = RenderNodeView;
1813
- exports.RenderTree = RenderTree;
1814
- exports.useActionData = useActionData;
1815
- exports.useActionStatus = useActionStatus;
1816
- exports.useCanvas = useCanvas;
1817
- exports.useCanvasRenderTree = useCanvasRenderTree;
1818
- exports.useNovaDispatch = useNovaDispatch;
1819
- exports.useNovaPublish = useNovaPublish;
1820
- exports.useNovaRegistry = useNovaRegistry;
1821
- exports.useRenderTree = useRenderTree;
1822
- exports.useShell = useShell;
1823
- exports.useShellRenderTree = useShellRenderTree;
1824
- exports.useShellState = useShellState;
1825
- exports.useSlotWrapper = useSlotWrapper;
1826
108
  //# sourceMappingURL=index.cjs.map
1827
109
  //# sourceMappingURL=index.cjs.map