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