@niscorp/nova 0.1.3 → 0.2.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/ADAPTER.md +6 -0
- package/CHANGELOG.md +44 -0
- package/README.md +53 -0
- package/dist/adapters/dom/components/index.d.cts +2 -2
- package/dist/adapters/dom/components/index.d.ts +2 -2
- package/dist/adapters/dom/index.cjs +227 -4
- package/dist/adapters/dom/index.cjs.map +1 -1
- package/dist/adapters/dom/index.d.cts +2 -2
- package/dist/adapters/dom/index.d.ts +2 -2
- package/dist/adapters/dom/index.js +7 -7
- package/dist/adapters/dom/server.cjs +10 -1
- package/dist/adapters/dom/server.cjs.map +1 -1
- package/dist/adapters/dom/server.d.cts +2 -2
- package/dist/adapters/dom/server.d.ts +2 -2
- package/dist/adapters/dom/server.js +7 -7
- package/dist/adapters/react/components/index.cjs +30 -10
- package/dist/adapters/react/components/index.cjs.map +1 -1
- package/dist/adapters/react/components/index.d.cts +4 -4
- package/dist/adapters/react/components/index.d.ts +4 -4
- package/dist/adapters/react/components/index.js +9 -5
- package/dist/adapters/react/index.cjs +400 -99
- package/dist/adapters/react/index.cjs.map +1 -1
- package/dist/adapters/react/index.d.cts +4 -4
- package/dist/adapters/react/index.d.ts +4 -4
- package/dist/adapters/react/index.js +9 -5
- package/dist/adapters/tty/components/index.d.cts +2 -2
- package/dist/adapters/tty/components/index.d.ts +2 -2
- package/dist/adapters/tty/index.cjs +6 -1
- package/dist/adapters/tty/index.cjs.map +1 -1
- package/dist/adapters/tty/index.d.cts +2 -2
- package/dist/adapters/tty/index.d.ts +2 -2
- package/dist/adapters/tty/index.js +12 -1
- package/dist/adapters/tty/index.js.map +1 -1
- package/dist/adapters/vue/components/index.cjs +30 -1
- package/dist/adapters/vue/components/index.cjs.map +1 -1
- package/dist/adapters/vue/components/index.d.cts +9 -9
- package/dist/adapters/vue/components/index.d.ts +9 -9
- package/dist/adapters/vue/components/index.js +9 -5
- package/dist/adapters/vue/index.cjs +347 -23
- package/dist/adapters/vue/index.cjs.map +1 -1
- package/dist/adapters/vue/index.d.cts +4 -4
- package/dist/adapters/vue/index.d.ts +4 -4
- package/dist/adapters/vue/index.js +10 -9
- package/dist/adapters/vue/index.js.map +1 -1
- package/dist/agent/index.d.cts +2 -2
- package/dist/agent/index.d.ts +2 -2
- package/dist/{chunk-IGLCWXQ3.js → chunk-3JRTELLC.js} +3 -3
- package/dist/{chunk-IGLCWXQ3.js.map → chunk-3JRTELLC.js.map} +1 -1
- package/dist/{chunk-GVBBL36G.js → chunk-DIFE573X.js} +196 -4
- package/dist/chunk-DIFE573X.js.map +1 -0
- package/dist/{chunk-FQAJ24KA.js → chunk-MHW5VEIM.js} +33 -8
- package/dist/chunk-MHW5VEIM.js.map +1 -0
- package/dist/chunk-OE4E6IBD.js +25 -0
- package/dist/chunk-OE4E6IBD.js.map +1 -0
- package/dist/{chunk-3HGE3VWK.js → chunk-QXQCPH33.js} +33 -11
- package/dist/chunk-QXQCPH33.js.map +1 -0
- package/dist/chunk-RFBIGRCI.js +127 -0
- package/dist/chunk-RFBIGRCI.js.map +1 -0
- package/dist/{chunk-6N4WRC5V.js → chunk-RYIIIXDX.js} +85 -12
- package/dist/chunk-RYIIIXDX.js.map +1 -0
- package/dist/{chunk-7S5BNPUS.js → chunk-UDCXGDLQ.js} +36 -4
- package/dist/chunk-UDCXGDLQ.js.map +1 -0
- package/dist/chunk-V4BPFFFV.js +152 -0
- package/dist/chunk-V4BPFFFV.js.map +1 -0
- package/dist/{chunk-4ZID7UX5.js → chunk-VU6NNCEJ.js} +52 -8
- package/dist/{chunk-4ZID7UX5.js.map → chunk-VU6NNCEJ.js.map} +1 -1
- package/dist/{chunk-V32EVEVM.js → chunk-Y6XVPRYH.js} +316 -5
- package/dist/chunk-Y6XVPRYH.js.map +1 -0
- package/dist/devtools/index.d.cts +2 -2
- package/dist/devtools/index.d.ts +2 -2
- package/dist/devtools/index.js +4 -5
- package/dist/devtools/index.js.map +1 -1
- package/dist/document/index.cjs +308 -0
- package/dist/document/index.cjs.map +1 -0
- package/dist/document/index.d.cts +22 -0
- package/dist/document/index.d.ts +22 -0
- package/dist/document/index.js +6 -0
- package/dist/document/index.js.map +1 -0
- package/dist/head-CAzfTnpV.d.cts +25 -0
- package/dist/head-DRpbbj-l.d.ts +25 -0
- package/dist/i18n/index.d.cts +2 -2
- package/dist/i18n/index.d.ts +2 -2
- package/dist/index.cjs +191 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +20 -6
- package/dist/index.d.ts +20 -6
- package/dist/index.js +5 -6
- package/dist/migrations/index.js +1 -2
- package/dist/migrations/index.js.map +1 -1
- package/dist/{palette-Mx7XHYC6.d.ts → palette-CIpPH90W.d.ts} +1 -1
- package/dist/{palette-wbJB_svk.d.cts → palette-CvwZZCkx.d.cts} +1 -1
- package/dist/reflect/index.d.cts +2 -2
- package/dist/reflect/index.d.ts +2 -2
- package/dist/reflect/index.js +4 -5
- package/dist/{types-B-rjaUX0.d.ts → types-BSKx5MXW.d.ts} +1 -1
- package/dist/{types-B_nOtkyt.d.ts → types-BWc-olbY.d.ts} +1 -1
- package/dist/{types-mRKXqZPX.d.cts → types-C9734_lJ.d.cts} +1 -1
- package/dist/{types-BB9RXel5.d.ts → types-D23TRvqe.d.ts} +1 -1
- package/dist/{types-uk19d6KC.d.cts → types-DsWNYc7R.d.cts} +1 -1
- package/dist/{types-BLVRduoz.d.cts → types-j290XhCn.d.cts} +1 -1
- package/dist/{types-PDXOkvtK.d.cts → types-qkzTfSye.d.cts} +1 -1
- package/dist/{types-DE77Jl2W.d.ts → types-qnKMx0_V.d.ts} +1 -1
- package/package.json +13 -3
- package/dist/chunk-3HGE3VWK.js.map +0 -1
- package/dist/chunk-6N4WRC5V.js.map +0 -1
- package/dist/chunk-7S5BNPUS.js.map +0 -1
- package/dist/chunk-FQAJ24KA.js.map +0 -1
- package/dist/chunk-GVBBL36G.js.map +0 -1
- package/dist/chunk-PF4OJTYU.js +0 -199
- package/dist/chunk-PF4OJTYU.js.map +0 -1
- package/dist/chunk-RQB4PRPV.js +0 -285
- package/dist/chunk-RQB4PRPV.js.map +0 -1
- package/dist/chunk-V32EVEVM.js.map +0 -1
- package/dist/chunk-ZITHBBF3.js +0 -85
- package/dist/chunk-ZITHBBF3.js.map +0 -1
- package/dist/{primitive-props-BH_EJWIe.d.ts → primitive-props-CGoJvmcH.d.cts} +4 -4
- package/dist/{primitive-props-BH_EJWIe.d.cts → primitive-props-CGoJvmcH.d.ts} +4 -4
|
@@ -1,57 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var react = require('react');
|
|
4
|
-
var jsxRuntime = require('react/jsx-runtime');
|
|
5
4
|
var zod = require('zod');
|
|
6
5
|
var prism = require('@niscorp/prism');
|
|
7
6
|
var strata = require('@niscorp/strata');
|
|
7
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
8
8
|
|
|
9
9
|
// src/adapters/react/provider.tsx
|
|
10
10
|
var NovaRenderContext = react.createContext(void 0);
|
|
11
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
12
|
zod.z.object({
|
|
56
13
|
$if: zod.z.unknown().describe("Condition \u2014 resolved recursively, then checked for truthiness."),
|
|
57
14
|
$then: zod.z.unknown().describe("Value when condition is truthy \u2014 resolved recursively."),
|
|
@@ -115,13 +72,40 @@ var isObject = (value) => typeof value === "object" && value !== null && !Array.
|
|
|
115
72
|
var isArray = (value) => Array.isArray(value);
|
|
116
73
|
var hasKey = (obj, key) => isObject(obj) && key in obj;
|
|
117
74
|
|
|
118
|
-
// src/
|
|
119
|
-
var
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
var
|
|
124
|
-
var
|
|
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
|
+
};
|
|
125
109
|
|
|
126
110
|
// src/shared/errors.ts
|
|
127
111
|
var ErrorCodes = {
|
|
@@ -164,44 +148,17 @@ var DefinitionValidationError = class extends NovaError {
|
|
|
164
148
|
}
|
|
165
149
|
};
|
|
166
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
|
+
|
|
167
159
|
// src/shared/bindings/scope.ts
|
|
168
160
|
var createScopeChain = (data) => [data];
|
|
169
161
|
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
162
|
var TEMPLATE_REGEX = /\{\{\s*([^}]+?)\s*\}\}/g;
|
|
206
163
|
var SOLE_TEMPLATE_REGEX = /^\{\{\s*([^}]+?)\s*\}\}$/;
|
|
207
164
|
var BARE_PATH_REGEX = /^\$(\.|[A-Za-z_]|$)/;
|
|
@@ -461,6 +418,28 @@ var walkValue = (value, prose, where, pass) => {
|
|
|
461
418
|
return value;
|
|
462
419
|
};
|
|
463
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
|
+
|
|
464
443
|
// src/layout/renderer.ts
|
|
465
444
|
var noopOnError = (_error) => {
|
|
466
445
|
};
|
|
@@ -556,7 +535,7 @@ var renderNode = (node, chain, ctx) => {
|
|
|
556
535
|
return [];
|
|
557
536
|
};
|
|
558
537
|
var renderComponent = (node, chain, ctx) => {
|
|
559
|
-
if (!ctx.registry.has(node.component)) {
|
|
538
|
+
if (!HEAD_NAMES.includes(node.component) && !ctx.registry.has(node.component)) {
|
|
560
539
|
throw new ComponentNotFoundError(
|
|
561
540
|
`Component not found in registry: ${node.component}`,
|
|
562
541
|
{ name: node.component }
|
|
@@ -746,9 +725,330 @@ var createComponentRegistry = () => {
|
|
|
746
725
|
}
|
|
747
726
|
};
|
|
748
727
|
const get = (name) => entries.get(name);
|
|
749
|
-
const
|
|
728
|
+
const has2 = (name) => entries.has(name);
|
|
750
729
|
const list = () => Array.from(entries.keys());
|
|
751
|
-
return { register, registerAll, get, has, list };
|
|
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;
|
|
867
|
+
});
|
|
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
|
+
}
|
|
905
|
+
});
|
|
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
|
+
) });
|
|
752
1052
|
};
|
|
753
1053
|
var ErrorMarker = ({ code, message }) => /* @__PURE__ */ jsxRuntime.jsx("span", { "data-nova-error": code, role: "alert", children: `[${code}] ${message}` });
|
|
754
1054
|
var RenderNodeView = ({ node }) => {
|
|
@@ -767,6 +1067,7 @@ var RenderNodeView = ({ node }) => {
|
|
|
767
1067
|
const Marker = ctx.errorMarker ?? ErrorMarker;
|
|
768
1068
|
return /* @__PURE__ */ jsxRuntime.jsx(Marker, { code: node.code, message: node.message });
|
|
769
1069
|
}
|
|
1070
|
+
if (isHeadNode(node)) return /* @__PURE__ */ jsxRuntime.jsx(HeadMark, {});
|
|
770
1071
|
const entry = ctx.registry.get(node.name);
|
|
771
1072
|
const Component2 = entry !== void 0 ? entry.component : ctx.fallback;
|
|
772
1073
|
if (Component2 === void 0) {
|
|
@@ -779,11 +1080,16 @@ var RenderNodeView = ({ node }) => {
|
|
|
779
1080
|
if (node.ref !== void 0) {
|
|
780
1081
|
props[NOVA_REF_PROP] = node.ref;
|
|
781
1082
|
}
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
props,
|
|
785
|
-
|
|
786
|
-
);
|
|
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
|
+
] });
|
|
787
1093
|
};
|
|
788
1094
|
var RenderTree = ({ nodes }) => /* @__PURE__ */ jsxRuntime.jsx(react.Fragment, { children: nodes.map((node, i) => /* @__PURE__ */ jsxRuntime.jsx(RenderNodeView, { node }, renderNodeKey(node, i))) });
|
|
789
1095
|
var NovaErrorBoundary = class extends react.Component {
|
|
@@ -1151,11 +1457,6 @@ CanvasSlot.meta = {
|
|
|
1151
1457
|
description: "Renders a canvas by id, recursing into its actionLayout.",
|
|
1152
1458
|
propsSchema: CanvasSlotPropsSchema
|
|
1153
1459
|
};
|
|
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
1460
|
var ActionSlot = ({
|
|
1160
1461
|
instanceId
|
|
1161
1462
|
}) => {
|