@box-kite/react 2.0.1 → 2.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.
Files changed (145) hide show
  1. package/.claude/rules/box-kite-rules.md +24 -2
  2. package/.claude/skills/box-kite/SKILL.md +27 -5
  3. package/.claude/skills/box-kite/references/components.md +8 -3
  4. package/.claude/skills/box-kite/references/patterns.md +24 -1
  5. package/.claude/skills/box-kite/references/styling.md +23 -0
  6. package/.cursor/rules/box-kite.mdc +25 -3
  7. package/AGENTS.md +28 -3
  8. package/BOX_AI_CONTEXT.md +732 -12
  9. package/BOX_KITE_AI_CONTEXT.md +732 -12
  10. package/README.md +41 -9
  11. package/box.cjs +1 -1
  12. package/box.d.ts +13 -2
  13. package/box.mjs +25 -18
  14. package/catalog.cjs +1 -0
  15. package/catalog.d.ts +8 -0
  16. package/catalog.mjs +2347 -0
  17. package/client.cjs +1 -1
  18. package/client.mjs +59 -53
  19. package/components/agent.cjs +1 -0
  20. package/components/agent.d.ts +215 -0
  21. package/components/agent.mjs +405 -0
  22. package/components/button.cjs +1 -1
  23. package/components/button.mjs +10 -14
  24. package/components/chart.d.ts +1 -0
  25. package/components/dashboard.cjs +1 -0
  26. package/components/dashboard.d.ts +121 -0
  27. package/components/dashboard.mjs +690 -0
  28. package/components/dataGrid/components/dataGridBody.d.ts +2 -1
  29. package/components/dataGrid/components/dataGridDetailRow.d.ts +13 -2
  30. package/components/dataGrid/components/dataGridGroupRow.d.ts +13 -2
  31. package/components/dataGrid/components/dataGridRow.d.ts +13 -2
  32. package/components/dataGrid/contracts/dataGridContract.d.ts +66 -2
  33. package/components/dataGrid/models/cellModel.d.ts +3 -0
  34. package/components/dataGrid/models/editModel.d.ts +27 -0
  35. package/components/dataGrid/models/exportModel.d.ts +2 -1
  36. package/components/dataGrid/models/gridModel.d.ts +3 -0
  37. package/components/dataGrid/models/rangeModel.d.ts +119 -0
  38. package/components/dataGrid/models/viewportModel.d.ts +23 -2
  39. package/components/dataGrid/useGridNavigation.d.ts +10 -2
  40. package/components/dataGrid.cjs +4 -1
  41. package/components/dataGrid.d.ts +3 -0
  42. package/components/dataGrid.mjs +1056 -765
  43. package/components/flex.cjs +1 -1
  44. package/components/flex.mjs +10 -13
  45. package/components/form.cjs +1 -1
  46. package/components/form.mjs +7 -7
  47. package/components/grid.cjs +1 -1
  48. package/components/grid.mjs +10 -13
  49. package/components/markdown.cjs +1 -0
  50. package/components/markdown.d.ts +55 -0
  51. package/components/markdown.mjs +179 -0
  52. package/components/menu.cjs +1 -1
  53. package/components/menu.mjs +16 -16
  54. package/components/overlay.cjs +1 -1
  55. package/components/overlay.mjs +35 -34
  56. package/components/popover.cjs +1 -1
  57. package/components/popover.mjs +4 -4
  58. package/components/semantics.cjs +1 -1
  59. package/components/semantics.d.ts +29 -29
  60. package/components/semantics.mjs +9 -13
  61. package/components/skeleton.cjs +1 -0
  62. package/components/skeleton.d.ts +34 -0
  63. package/components/skeleton.mjs +25 -0
  64. package/components/svg.cjs +1 -1
  65. package/components/svg.mjs +38 -44
  66. package/components/textarea.cjs +1 -1
  67. package/components/textarea.mjs +12 -16
  68. package/components/textbox.cjs +1 -1
  69. package/components/textbox.mjs +12 -16
  70. package/components/toaster.cjs +1 -1
  71. package/components/toaster.mjs +42 -43
  72. package/components/visuallyHidden.cjs +1 -1
  73. package/components/visuallyHidden.mjs +10 -13
  74. package/dashboardSchema.cjs +1 -0
  75. package/dashboardSchema.mjs +78 -0
  76. package/docs/a11y.md +2 -3
  77. package/docs/catalog.md +451 -0
  78. package/docs/components.md +4 -0
  79. package/docs/index.md +3 -0
  80. package/docs/interop.md +237 -0
  81. package/docs/mcp.md +70 -0
  82. package/docs/props.md +135 -23
  83. package/interop.cjs +1 -0
  84. package/interop.d.ts +51 -0
  85. package/interop.mjs +454 -0
  86. package/layer.cjs +1 -1
  87. package/layer.mjs +61 -59
  88. package/mcp/src/data.d.ts +88 -0
  89. package/mcp/src/data.test.d.ts +1 -0
  90. package/mcp/src/engine.d.ts +23 -0
  91. package/mcp/src/index.d.ts +1 -0
  92. package/mcp/src/search.d.ts +26 -0
  93. package/mcp/src/search.test.d.ts +1 -0
  94. package/mcp/src/server.d.ts +18 -0
  95. package/mcp/src/server.test.d.ts +1 -0
  96. package/mcp/src/styles.d.ts +27 -0
  97. package/mcp/src/styles.test.d.ts +1 -0
  98. package/mcp/src/tools.d.ts +18 -0
  99. package/mcp/src/vocabulary.d.ts +41 -0
  100. package/package.json +170 -37
  101. package/react/boxComponent.d.ts +10 -0
  102. package/react/popover/useTopLayer.d.ts +17 -0
  103. package/react/spec/renderSpec.d.ts +51 -0
  104. package/react/spec/specBoundary.d.ts +25 -0
  105. package/react/spec/specRegistry.d.ts +42 -0
  106. package/react/spec/specRenderer.d.ts +10 -0
  107. package/react/theme/theme.d.ts +10 -0
  108. package/react/useStyles.d.ts +2 -0
  109. package/react-shared.cjs +1 -1
  110. package/react-shared.mjs +44 -37
  111. package/registry/blocks/dashboard-shell/dashboard-shell.d.ts +22 -0
  112. package/registry/blocks/dashboard-shell/dashboard-stats.d.ts +13 -0
  113. package/registry/blocks/data-grid/invoice-rows.d.ts +15 -0
  114. package/registry/blocks/data-grid/invoices-grid.d.ts +1 -0
  115. package/registry/blocks/settings-form/settings-form.d.ts +17 -0
  116. package/rsc.cjs +1 -1
  117. package/rsc.d.ts +11 -1
  118. package/rsc.mjs +15 -12
  119. package/spec.cjs +2 -0
  120. package/spec.d.ts +12 -0
  121. package/spec.mjs +382 -0
  122. package/specData.cjs +1 -0
  123. package/specData.mjs +69 -0
  124. package/specDefs.cjs +1 -0
  125. package/specDefs.mjs +33 -0
  126. package/specSchema.cjs +1 -0
  127. package/specSchema.mjs +88 -0
  128. package/ssg.cjs +1 -1
  129. package/ssg.d.ts +8 -2
  130. package/ssg.mjs +13 -9
  131. package/utils/agent/agentUtils.d.ts +81 -0
  132. package/utils/catalog/catalogContracts.d.ts +19 -0
  133. package/utils/catalog/catalogManifest.d.ts +8 -0
  134. package/utils/dashboard/dashboardSchema.d.ts +18 -0
  135. package/utils/dashboard/dashboardUtils.d.ts +97 -0
  136. package/utils/environment/environmentUtils.d.ts +5 -0
  137. package/utils/interop/a2uiInterop.d.ts +82 -0
  138. package/utils/interop/assistantUiInterop.d.ts +34 -0
  139. package/utils/interop/toolInterop.d.ts +30 -0
  140. package/utils/spec/specData.d.ts +19 -0
  141. package/utils/spec/specDefs.d.ts +11 -0
  142. package/utils/spec/specProps.d.ts +15 -0
  143. package/utils/spec/specSchema.d.ts +23 -0
  144. package/utils/spec/specTypes.d.ts +71 -0
  145. package/utils/spec/specValidate.d.ts +10 -0
package/spec.mjs ADDED
@@ -0,0 +1,382 @@
1
+ "use client";
2
+ import { n as e } from "./effects.mjs";
3
+ import { t } from "./specSchema.mjs";
4
+ import { t as n } from "./specData.mjs";
5
+ import { Component as r, Fragment as i, createElement as a, useEffect as o, useRef as s, useState as c } from "react";
6
+ import { jsx as l } from "react/jsx-runtime";
7
+ //#region src/utils/spec/specValidate.ts
8
+ var u;
9
+ (function(e) {
10
+ let t = [
11
+ "__proto__",
12
+ "constructor",
13
+ "prototype"
14
+ ], n = /* @__PURE__ */ new Map();
15
+ function r(e) {
16
+ if (!n.has(e)) try {
17
+ n.set(e, new RegExp(e));
18
+ } catch {
19
+ n.set(e, null);
20
+ }
21
+ return n.get(e) ?? null;
22
+ }
23
+ function i(e) {
24
+ return !t.includes(e);
25
+ }
26
+ e.isSafeKey = i;
27
+ function a(e) {
28
+ return typeof e == "object" && !!e && !Array.isArray(e);
29
+ }
30
+ e.isPlainObject = a;
31
+ function o(e, t) {
32
+ if (!e.$ref) return e;
33
+ let n = e.$ref.startsWith("#/$defs/") ? e.$ref.slice(8) : null, r = n ? t.$defs?.[n] : void 0;
34
+ return r ? o(r, t) : null;
35
+ }
36
+ function s(e, t, n) {
37
+ return !a(t) || e.required?.some((e) => !(e in t)) ? !1 : Object.keys(t).every((r) => {
38
+ let a = e.properties?.[r];
39
+ return a ? i(r) && c(a, t[r], n) : e.additionalProperties !== !1 && i(r);
40
+ });
41
+ }
42
+ function c(e, t, n = e) {
43
+ let i = o(e, n);
44
+ if (!i) return !1;
45
+ if (i.anyOf) return i.anyOf.some((e) => c(e, t, n));
46
+ if (i.enum && !i.enum.includes(t)) return !1;
47
+ switch (i.type) {
48
+ case "string": return typeof t == "string" ? !i.pattern || (r(i.pattern)?.test(t) ?? !1) : !1;
49
+ case "number": return typeof t == "number" && Number.isFinite(t);
50
+ case "integer": return typeof t == "number" && Number.isInteger(t);
51
+ case "boolean": return typeof t == "boolean";
52
+ case "array": return Array.isArray(t) && (!i.items || t.every((e) => c(i.items, e, n)));
53
+ case "object": return s(i, t, n);
54
+ default: return t !== void 0;
55
+ }
56
+ }
57
+ e.matches = c;
58
+ })(u ||= {});
59
+ var d = u, f;
60
+ (function(e) {
61
+ function t(e) {
62
+ let t = JSON.stringify(e) ?? "undefined";
63
+ return t.length > 40 ? `${t.slice(0, 39)}…` : t;
64
+ }
65
+ function r(e, t) {
66
+ return typeof e == "string" ? { action: e } : !d.isPlainObject(e) || typeof e.action != "string" ? null : {
67
+ action: e.action,
68
+ payload: n.deep(e.payload, t)
69
+ };
70
+ }
71
+ function i(e, i, a, o) {
72
+ let s = typeof e.type == "string" ? e.type : void 0, c = [], l = {}, u = {}, f = i.props, p = f?.properties;
73
+ if (d.isPlainObject(e.props)) for (let [r, i] of Object.entries(e.props)) {
74
+ let e = `${o}.props.${r}`;
75
+ if (!d.isSafeKey(r)) {
76
+ c.push({
77
+ code: "unknown-prop",
78
+ path: e,
79
+ component: s,
80
+ prop: r,
81
+ message: `${r} is not a prop a spec can set.`
82
+ });
83
+ continue;
84
+ }
85
+ let u = p?.[r];
86
+ if (!u && (!f || f.additionalProperties === !1)) {
87
+ c.push({
88
+ code: "unknown-prop",
89
+ path: e,
90
+ component: s,
91
+ prop: r,
92
+ message: `${s ?? "The component"} has no ${r} prop.`
93
+ });
94
+ continue;
95
+ }
96
+ let m = null, h = n.deep(i, a, (e) => {
97
+ m ??= e;
98
+ });
99
+ if (m) {
100
+ c.push({
101
+ code: "unresolved-data",
102
+ path: e,
103
+ component: s,
104
+ prop: r,
105
+ message: `${m} resolved to nothing.`
106
+ });
107
+ continue;
108
+ }
109
+ if (u && !d.matches(u, h, f)) {
110
+ c.push({
111
+ code: "invalid-prop",
112
+ path: e,
113
+ component: s,
114
+ prop: r,
115
+ message: `${t(h)} is not a value ${r} takes.`
116
+ });
117
+ continue;
118
+ }
119
+ l[r] = h;
120
+ }
121
+ if (d.isPlainObject(e.on)) for (let [t, n] of Object.entries(e.on)) {
122
+ let e = `${o}.on.${t}`, l = i.events.includes(t) ? r(n, a) : null;
123
+ if (!l) {
124
+ c.push({
125
+ code: "unknown-event",
126
+ path: e,
127
+ component: s,
128
+ prop: t,
129
+ message: `${s ?? "The component"} has no ${t} event.`
130
+ });
131
+ continue;
132
+ }
133
+ u[t] = l;
134
+ }
135
+ return {
136
+ props: l,
137
+ actions: u,
138
+ issues: c,
139
+ missing: (f?.required ?? []).filter((e) => !(e in l))
140
+ };
141
+ }
142
+ e.resolve = i;
143
+ })(f ||= {});
144
+ var p = f, m = class extends r {
145
+ state = {
146
+ message: null,
147
+ resetKey: this.props.resetKey
148
+ };
149
+ static getDerivedStateFromProps(e, t) {
150
+ return e.resetKey === t.resetKey ? null : {
151
+ message: null,
152
+ resetKey: e.resetKey
153
+ };
154
+ }
155
+ static getDerivedStateFromError(e) {
156
+ return { message: e instanceof Error ? e.message : String(e) };
157
+ }
158
+ componentDidCatch(e) {
159
+ this.props.onError?.(this.issue(e instanceof Error ? e.message : String(e)));
160
+ }
161
+ issue(e) {
162
+ return {
163
+ code: "render-error",
164
+ path: this.props.path,
165
+ component: this.props.component,
166
+ message: e
167
+ };
168
+ }
169
+ render() {
170
+ return this.state.message === null ? this.props.children : this.props.fallback(this.issue(this.state.message));
171
+ }
172
+ }, h = 1e3, g = 32;
173
+ function _(e, t) {
174
+ e.issues.push(t);
175
+ }
176
+ function v(e, t, n) {
177
+ _(e, t);
178
+ let r = e.fallback(t);
179
+ return n === void 0 || r == null ? r ?? null : a(i, { key: n }, r);
180
+ }
181
+ function y(e, t, r, i, a) {
182
+ if (e == null || typeof e == "boolean") return null;
183
+ if (typeof e == "string" || typeof e == "number") return e;
184
+ if (Array.isArray(e)) return e.map((e, n) => y(e, t, r, `${i}.${n}`, a));
185
+ if (n.isRef(e)) {
186
+ let a = n.resolve(e, r);
187
+ return a.found ? a.value === null || a.value === void 0 || typeof a.value == "boolean" ? null : typeof a.value == "string" || typeof a.value == "number" ? a.value : (_(t, {
188
+ code: "invalid-child",
189
+ path: i,
190
+ message: `${n.pathOf(e)} is not text.`
191
+ }), null) : (_(t, {
192
+ code: "unresolved-data",
193
+ path: i,
194
+ message: `${n.pathOf(e)} resolved to nothing.`
195
+ }), null);
196
+ }
197
+ return d.isPlainObject(e) ? "type" in e ? typeof e.type == "string" ? e.type === "" ? null : x(e, t, r, i, a, e.type) : (_(t, {
198
+ code: "invalid-child",
199
+ path: i,
200
+ message: "A node names its component in `type`."
201
+ }), null) : null : (_(t, {
202
+ code: "invalid-child",
203
+ path: i,
204
+ message: "A child is a node, text, or a reference to text."
205
+ }), null);
206
+ }
207
+ function b(e, t, r, i, a, o) {
208
+ let s = e.repeat;
209
+ if (!n.isRef(s)) return v(t, {
210
+ code: "invalid-repeat",
211
+ path: `${i}.repeat`,
212
+ component: o,
213
+ message: "A repeat is a reference to an array."
214
+ });
215
+ let c = n.resolve(s, r);
216
+ if (!c.found) return _(t, {
217
+ code: "unresolved-data",
218
+ path: `${i}.repeat`,
219
+ component: o,
220
+ message: `${n.pathOf(s)} resolved to nothing.`
221
+ }), null;
222
+ if (!Array.isArray(c.value)) return v(t, {
223
+ code: "invalid-repeat",
224
+ path: `${i}.repeat`,
225
+ component: o,
226
+ message: `${n.pathOf(s)} is not an array.`
227
+ });
228
+ let l = typeof e.key == "string" ? e.key : i;
229
+ return c.value.map((n, s) => S(e, t, {
230
+ data: r.data,
231
+ item: n,
232
+ index: s,
233
+ repeating: !0
234
+ }, i, a, o, `${l}#${s}`));
235
+ }
236
+ function x(e, t, n, r, i, a) {
237
+ return i > t.maxDepth ? v(t, {
238
+ code: "too-deep",
239
+ path: r,
240
+ component: a,
241
+ message: `Nested deeper than the ${t.maxDepth} levels allowed.`
242
+ }) : e.repeat === void 0 ? S(e, t, n, r, i, a, typeof e.key == "string" ? e.key : r) : b(e, t, n, r, i, a);
243
+ }
244
+ function S(e, t, n, r, i, o, s) {
245
+ if (t.nodes += 1, t.nodes > t.maxNodes) return t.overflowed || (t.overflowed = !0, _(t, {
246
+ code: "too-many-nodes",
247
+ path: r,
248
+ component: o,
249
+ message: `More than the ${t.maxNodes} nodes allowed.`
250
+ })), null;
251
+ let c = t.registry.get(o);
252
+ if (!c) return v(t, {
253
+ code: "unknown-component",
254
+ path: r,
255
+ component: o,
256
+ message: `${o} is not a component this app allows.`
257
+ }, s);
258
+ let u = p.resolve(e, c, n, r), f = { ...u.props };
259
+ t.issues.push(...u.issues);
260
+ let h = t.memory?.get(`${r}:${o}`);
261
+ if (u.missing.length) {
262
+ if (!(h && u.missing.every((e) => e in h))) {
263
+ let e = u.missing.join(", ");
264
+ return v(t, {
265
+ code: "missing-prop",
266
+ path: r,
267
+ component: o,
268
+ prop: u.missing[0],
269
+ message: `${o} cannot render without ${e}.`
270
+ }, s);
271
+ }
272
+ for (let e of u.missing) f[e] = h[e];
273
+ }
274
+ if (t.memory) {
275
+ let e = c.props?.required ?? [];
276
+ e.length && t.memory.set(`${r}:${o}`, Object.fromEntries(e.map((e) => [e, f[e]])));
277
+ }
278
+ for (let [e, n] of Object.entries(u.actions)) f[e] = (...i) => t.onAction?.(n.action, {
279
+ payload: n.payload,
280
+ args: i,
281
+ prop: e,
282
+ component: o,
283
+ path: r
284
+ });
285
+ if (e.children !== void 0 && (c.slots.includes("default") ? f.children = y(e.children, t, n, `${r}.children`, i + 1) : _(t, {
286
+ code: "unknown-slot",
287
+ path: `${r}.children`,
288
+ component: o,
289
+ message: `${o} takes no children.`
290
+ })), d.isPlainObject(e.slots)) for (let [a, s] of Object.entries(e.slots)) {
291
+ let e = `${r}.slots.${a}`;
292
+ if (!d.isSafeKey(a) || !c.slots.includes(a)) {
293
+ _(t, {
294
+ code: "unknown-slot",
295
+ path: e,
296
+ component: o,
297
+ message: `${o} has no ${a} slot.`
298
+ });
299
+ continue;
300
+ }
301
+ f[a === "default" ? "children" : a] = y(s, t, n, e, i + 1);
302
+ }
303
+ return /* @__PURE__ */ l(m, {
304
+ path: r,
305
+ component: o,
306
+ resetKey: t.resetKey,
307
+ fallback: t.fallback,
308
+ onError: t.onError,
309
+ children: a(c.component, f)
310
+ }, s);
311
+ }
312
+ function C(e, t) {
313
+ let n = {
314
+ registry: t.registry,
315
+ data: t.data,
316
+ onAction: t.onAction,
317
+ onError: t.onError,
318
+ fallback: t.fallback ?? (() => null),
319
+ maxNodes: t.maxNodes ?? h,
320
+ maxDepth: t.maxDepth ?? g,
321
+ resetKey: t.resetKey,
322
+ memory: t.memory,
323
+ issues: [],
324
+ nodes: 0,
325
+ overflowed: !1
326
+ };
327
+ return {
328
+ element: y(e, n, { data: t.data }, "spec", 0),
329
+ issues: n.issues
330
+ };
331
+ }
332
+ //#endregion
333
+ //#region src/react/spec/specRenderer.tsx
334
+ function w(t) {
335
+ let n = s(t);
336
+ return e(() => {
337
+ n.current = t;
338
+ }), n;
339
+ }
340
+ function T({ spec: e, onIssues: t, ...n }) {
341
+ let [r] = c(() => /* @__PURE__ */ new Map()), { element: i, issues: a } = C(e, {
342
+ ...n,
343
+ memory: r,
344
+ resetKey: e,
345
+ onError: (e) => t?.([e])
346
+ }), s = w(t), l = w(a), u = a.map((e) => `${e.code} ${e.path} ${e.message}`).join("\n");
347
+ return o(() => {
348
+ s.current?.(l.current);
349
+ }, [
350
+ u,
351
+ l,
352
+ s
353
+ ]), i;
354
+ }
355
+ //#endregion
356
+ //#region src/react/spec/specRegistry.ts
357
+ function E(e) {
358
+ return typeof e == "object" && !!e && "component" in e;
359
+ }
360
+ function D(e, t, n) {
361
+ let r = E(t) ? t : { component: t }, i = n?.components[e];
362
+ return {
363
+ component: r.component,
364
+ props: r.props ?? i?.props,
365
+ slots: r.slots ?? i?.slots ?? ["default"],
366
+ events: r.events ?? i?.events ?? [],
367
+ description: r.description ?? i?.description
368
+ };
369
+ }
370
+ function O(e) {
371
+ let t = Object.keys(e.components), n = new Map(t.map((t) => [t, D(t, e.components[t], e.catalog)]));
372
+ return {
373
+ names: t,
374
+ components: Object.fromEntries([...n].map(([e, { component: t, ...n }]) => [e, n])),
375
+ get: (e) => n.get(e)
376
+ };
377
+ }
378
+ //#endregion
379
+ //#region src/spec.ts
380
+ var k = d.matches;
381
+ //#endregion
382
+ export { T as SpecRenderer, T as default, O as createSpecRegistry, k as matchesSchema, C as renderSpec, t as specSchema };
package/specData.cjs ADDED
@@ -0,0 +1 @@
1
+ var e;(function(e){function t(e){if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=Object.keys(e);if(t.length!==1)return!1;let n=e;return t[0]===`$data`?typeof n.$data==`string`:t[0]===`$item`?typeof n.$item==`string`:t[0]===`$index`&&n.$index===!0}e.isRef=t;function n(e){return e===``||e===`.`||e===`/`?[]:e.startsWith(`/`)?e.slice(1).split(`/`):e.split(`.`)}function r(e,t){if(Array.isArray(e)){let n=/^\d+$/.test(t)?Number(t):-1;return n>=0&&n<e.length?{value:e[n],found:!0}:{value:void 0,found:!1}}return typeof e==`object`&&e&&Object.hasOwn(e,t)?{value:e[t],found:!0}:{value:void 0,found:!1}}function i(e,t){if(`$index`in e)return t.repeating?{value:t.index,found:!0}:{value:void 0,found:!1};let i=`$item`in e?e.$item:e.$data,a=`$item`in e?t.item:t.data;return`$item`in e&&!t.repeating?{value:void 0,found:!1}:n(i).reduce((e,t)=>e.found?r(e.value,t):e,{value:a,found:!0})}e.resolve=i;function a(e){return`$index`in e?`$index`:`$item`in e?`$item ${e.$item}`:`$data ${e.$data}`}e.pathOf=a;function o(e,n,r,s=0){if(!(s>16)){if(t(e)){let t=i(e,n);return t.found||r?.(a(e)),t.value}return Array.isArray(e)?e.map(e=>o(e,n,r,s+1)):typeof e==`object`&&e?Object.fromEntries(Object.entries(e).map(([e,t])=>[e,o(t,n,r,s+1)])):e}}e.deep=o})(e||={});var t=e;Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return t}});
package/specData.mjs ADDED
@@ -0,0 +1,69 @@
1
+ //#region src/utils/spec/specData.ts
2
+ var e;
3
+ (function(e) {
4
+ function t(e) {
5
+ if (typeof e != "object" || !e || Array.isArray(e)) return !1;
6
+ let t = Object.keys(e);
7
+ if (t.length !== 1) return !1;
8
+ let n = e;
9
+ return t[0] === "$data" ? typeof n.$data == "string" : t[0] === "$item" ? typeof n.$item == "string" : t[0] === "$index" && n.$index === !0;
10
+ }
11
+ e.isRef = t;
12
+ function n(e) {
13
+ return e === "" || e === "." || e === "/" ? [] : e.startsWith("/") ? e.slice(1).split("/") : e.split(".");
14
+ }
15
+ function r(e, t) {
16
+ if (Array.isArray(e)) {
17
+ let n = /^\d+$/.test(t) ? Number(t) : -1;
18
+ return n >= 0 && n < e.length ? {
19
+ value: e[n],
20
+ found: !0
21
+ } : {
22
+ value: void 0,
23
+ found: !1
24
+ };
25
+ }
26
+ return typeof e == "object" && e && Object.hasOwn(e, t) ? {
27
+ value: e[t],
28
+ found: !0
29
+ } : {
30
+ value: void 0,
31
+ found: !1
32
+ };
33
+ }
34
+ function i(e, t) {
35
+ if ("$index" in e) return t.repeating ? {
36
+ value: t.index,
37
+ found: !0
38
+ } : {
39
+ value: void 0,
40
+ found: !1
41
+ };
42
+ let i = "$item" in e ? e.$item : e.$data, a = "$item" in e ? t.item : t.data;
43
+ return "$item" in e && !t.repeating ? {
44
+ value: void 0,
45
+ found: !1
46
+ } : n(i).reduce((e, t) => e.found ? r(e.value, t) : e, {
47
+ value: a,
48
+ found: !0
49
+ });
50
+ }
51
+ e.resolve = i;
52
+ function a(e) {
53
+ return "$index" in e ? "$index" : "$item" in e ? `$item ${e.$item}` : `$data ${e.$data}`;
54
+ }
55
+ e.pathOf = a;
56
+ function o(e, n, r, s = 0) {
57
+ if (!(s > 16)) {
58
+ if (t(e)) {
59
+ let t = i(e, n);
60
+ return t.found || r?.(a(e)), t.value;
61
+ }
62
+ return Array.isArray(e) ? e.map((e) => o(e, n, r, s + 1)) : typeof e == "object" && e ? Object.fromEntries(Object.entries(e).map(([e, t]) => [e, o(t, n, r, s + 1)])) : e;
63
+ }
64
+ }
65
+ e.deep = o;
66
+ })(e ||= {});
67
+ var t = e;
68
+ //#endregion
69
+ export { t };
package/specDefs.cjs ADDED
@@ -0,0 +1 @@
1
+ var e;(function(e){function t(e,n){let r={...e};if(r.$ref?.startsWith(`#/$defs/`)){let e=n[r.$ref.slice(8)];e&&(r.$ref=`#/$defs/${e}`)}return r.anyOf&&=r.anyOf.map(e=>t(e,n)),r.items&&=t(r.items,n),r.properties&&=Object.fromEntries(Object.entries(r.properties).map(([e,r])=>[e,t(r,n)])),r}function n(e,n){let{$defs:r,...i}=e;if(!r)return i;let a={};for(let[e,t]of Object.entries(r)){let r=n[e];if(!r){n[e]=t;continue}if(JSON.stringify(r)===JSON.stringify(t))continue;let i=2;for(;n[`${e}${i}`]&&JSON.stringify(n[`${e}${i}`])!==JSON.stringify(t);)i+=1;n[`${e}${i}`]=t,a[e]=`${e}${i}`}return Object.keys(a).length?t(i,a):i}e.hoist=n})(e||={});var t=e;Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return t}});
package/specDefs.mjs ADDED
@@ -0,0 +1,33 @@
1
+ //#region src/utils/spec/specDefs.ts
2
+ var e;
3
+ (function(e) {
4
+ function t(e, n) {
5
+ let r = { ...e };
6
+ if (r.$ref?.startsWith("#/$defs/")) {
7
+ let e = n[r.$ref.slice(8)];
8
+ e && (r.$ref = `#/$defs/${e}`);
9
+ }
10
+ return r.anyOf &&= r.anyOf.map((e) => t(e, n)), r.items &&= t(r.items, n), r.properties &&= Object.fromEntries(Object.entries(r.properties).map(([e, r]) => [e, t(r, n)])), r;
11
+ }
12
+ function n(e, n) {
13
+ let { $defs: r, ...i } = e;
14
+ if (!r) return i;
15
+ let a = {};
16
+ for (let [e, t] of Object.entries(r)) {
17
+ let r = n[e];
18
+ if (!r) {
19
+ n[e] = t;
20
+ continue;
21
+ }
22
+ if (JSON.stringify(r) === JSON.stringify(t)) continue;
23
+ let i = 2;
24
+ for (; n[`${e}${i}`] && JSON.stringify(n[`${e}${i}`]) !== JSON.stringify(t);) i += 1;
25
+ n[`${e}${i}`] = t, a[e] = `${e}${i}`;
26
+ }
27
+ return Object.keys(a).length ? t(i, a) : i;
28
+ }
29
+ e.hoist = n;
30
+ })(e ||= {});
31
+ var t = e;
32
+ //#endregion
33
+ export { t };
package/specSchema.cjs ADDED
@@ -0,0 +1 @@
1
+ const e=require("./specDefs.cjs");var t=`default`,n=`#/$defs/node`,r=`#/$defs/children`,i=`#/$defs/reference`,a=`#/$defs/action`;function o(e){return e.properties?{...e,properties:Object.fromEntries(Object.entries(e.properties).map(([e,t])=>[e,{anyOf:[t,{$ref:i}]}]))}:e}function s(n,s,c,l){let u=s.slots??[`default`],d=u.filter(e=>e!==t),f=s.events??[],p=s.props&&Object.keys(s.props.properties??{}).length?e.t.hoist(s.props,c):null,m={type:{type:`string`,enum:[n]}};return p&&(m.props=l?o(p):p),u.includes(`default`)&&(m.children={$ref:r}),d.length&&(m.slots={type:`object`,properties:Object.fromEntries(d.map(e=>[e,{$ref:r}])),additionalProperties:!1}),f.length&&(m.on={type:`object`,properties:Object.fromEntries(f.map(e=>[e,{$ref:a}])),additionalProperties:!1}),l&&(m.repeat={$ref:i}),m.key={type:`string`},{...s.description?{description:s.description}:{},type:`object`,properties:m,required:p?.required?.length?[`type`,`props`]:[`type`],additionalProperties:!1}}var c={description:`A value read from the data the view is rendered against, rather than written into the spec.`,anyOf:[{type:`object`,properties:{$data:{type:`string`}},required:[`$data`],additionalProperties:!1},{type:`object`,properties:{$item:{type:`string`}},required:[`$item`],additionalProperties:!1},{type:`object`,properties:{$index:{type:`boolean`,enum:[!0]}},required:[`$index`],additionalProperties:!1}]},l={description:`What to tell the host when this happens. The host decides what it does; the spec never can.`,anyOf:[{type:`string`},{type:`object`,properties:{action:{type:`string`},payload:{type:`object`}},required:[`action`],additionalProperties:!1}]};function u(e,t={}){let r=t.bindings===!0,a=Object.keys(e.components),o={};o.node={anyOf:a.map(e=>({$ref:`#/$defs/${e}`}))},o.children={type:`array`,items:{anyOf:[{type:`string`},{type:`number`},{$ref:n},...r?[{$ref:i}]:[]]}},r&&(o.reference=c),a.some(t=>e.components[t].events?.length)&&(o.action=l);for(let e of a)o[e]={};for(let t of a)o[t]=s(t,e.components[t],o,r);return{description:`A user interface, as a tree of components the application allows.`,$defs:o,anyOf:(t.root?a.filter(e=>t.root.includes(e)):a).map(e=>({$ref:`#/$defs/${e}`}))}}Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return t}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return u}});
package/specSchema.mjs ADDED
@@ -0,0 +1,88 @@
1
+ import { t as e } from "./specDefs.mjs";
2
+ //#region src/utils/spec/specTypes.ts
3
+ var t = "default", n = "#/$defs/node", r = "#/$defs/children", i = "#/$defs/reference", a = "#/$defs/action";
4
+ function o(e) {
5
+ return e.properties ? {
6
+ ...e,
7
+ properties: Object.fromEntries(Object.entries(e.properties).map(([e, t]) => [e, { anyOf: [t, { $ref: i }] }]))
8
+ } : e;
9
+ }
10
+ function s(n, s, c, l) {
11
+ let u = s.slots ?? ["default"], d = u.filter((e) => e !== t), f = s.events ?? [], p = s.props && Object.keys(s.props.properties ?? {}).length ? e.hoist(s.props, c) : null, m = { type: {
12
+ type: "string",
13
+ enum: [n]
14
+ } };
15
+ return p && (m.props = l ? o(p) : p), u.includes("default") && (m.children = { $ref: r }), d.length && (m.slots = {
16
+ type: "object",
17
+ properties: Object.fromEntries(d.map((e) => [e, { $ref: r }])),
18
+ additionalProperties: !1
19
+ }), f.length && (m.on = {
20
+ type: "object",
21
+ properties: Object.fromEntries(f.map((e) => [e, { $ref: a }])),
22
+ additionalProperties: !1
23
+ }), l && (m.repeat = { $ref: i }), m.key = { type: "string" }, {
24
+ ...s.description ? { description: s.description } : {},
25
+ type: "object",
26
+ properties: m,
27
+ required: p?.required?.length ? ["type", "props"] : ["type"],
28
+ additionalProperties: !1
29
+ };
30
+ }
31
+ var c = {
32
+ description: "A value read from the data the view is rendered against, rather than written into the spec.",
33
+ anyOf: [
34
+ {
35
+ type: "object",
36
+ properties: { $data: { type: "string" } },
37
+ required: ["$data"],
38
+ additionalProperties: !1
39
+ },
40
+ {
41
+ type: "object",
42
+ properties: { $item: { type: "string" } },
43
+ required: ["$item"],
44
+ additionalProperties: !1
45
+ },
46
+ {
47
+ type: "object",
48
+ properties: { $index: {
49
+ type: "boolean",
50
+ enum: [!0]
51
+ } },
52
+ required: ["$index"],
53
+ additionalProperties: !1
54
+ }
55
+ ]
56
+ }, l = {
57
+ description: "What to tell the host when this happens. The host decides what it does; the spec never can.",
58
+ anyOf: [{ type: "string" }, {
59
+ type: "object",
60
+ properties: {
61
+ action: { type: "string" },
62
+ payload: { type: "object" }
63
+ },
64
+ required: ["action"],
65
+ additionalProperties: !1
66
+ }]
67
+ };
68
+ function u(e, t = {}) {
69
+ let r = t.bindings === !0, a = Object.keys(e.components), o = {};
70
+ o.node = { anyOf: a.map((e) => ({ $ref: `#/$defs/${e}` })) }, o.children = {
71
+ type: "array",
72
+ items: { anyOf: [
73
+ { type: "string" },
74
+ { type: "number" },
75
+ { $ref: n },
76
+ ...r ? [{ $ref: i }] : []
77
+ ] }
78
+ }, r && (o.reference = c), a.some((t) => e.components[t].events?.length) && (o.action = l);
79
+ for (let e of a) o[e] = {};
80
+ for (let t of a) o[t] = s(t, e.components[t], o, r);
81
+ return {
82
+ description: "A user interface, as a tree of components the application allows.",
83
+ $defs: o,
84
+ anyOf: (t.root ? a.filter((e) => t.root.includes(e)) : a).map((e) => ({ $ref: `#/$defs/${e}` }))
85
+ };
86
+ }
87
+ //#endregion
88
+ export { t as n, u as t };
package/ssg.cjs CHANGED
@@ -1 +1 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./rolldown-runtime.cjs"),t=require("./client.cjs");let n=require("react-dom/server");n=e.t(n,1);function r(){return t.r.getStyles()}function i(){t.r.clear()}function a(e,a=!0){let o=n.default.renderToStaticMarkup(e),s=r();if(a){let e=o.indexOf(`<head>`);if(e>-1){let n=e+6;o=o.substring(0,n)+`<style id="${t.r.styleElementId()}">${s}</style>`+o.substring(n)}}return i(),{html:o,styles:s}}exports.getStyles=r,exports.renderToStaticMarkup=a,exports.resetStyles=i;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./rolldown-runtime.cjs"),t=require("./client.cjs");let n=require("react-dom/server");n=e.t(n,1);function r(){return t.r.getStyles()}function i(){return t.r.getStyleTag()}function a(){t.r.clear()}function o(e,t=!0){let o=n.default.renderToStaticMarkup(e),s=r(),c=i();if(t){let e=o.indexOf(`<head>`);if(e>-1){let t=e+6;o=o.substring(0,t)+c+o.substring(t)}}return a(),{html:o,styles:s,styleTag:c}}exports.getStyleTag=i,exports.getStyles=r,exports.renderToStaticMarkup=o,exports.resetStyles=a;
package/ssg.d.ts CHANGED
@@ -5,9 +5,14 @@ import { default as React } from 'react';
5
5
  */
6
6
  /**
7
7
  * The CSS for everything rendered since the last reset. Flushes first, so it is safe straight after
8
- * `renderToString` — no effects have run at that point. Goes in a `<style id="box-kite-styles">` in the head.
8
+ * `renderToString` — no effects have run at that point. `getStyleTag()` is the same CSS ready for the head.
9
9
  */
10
10
  export declare function getStyles(): string;
11
+ /**
12
+ * The CSS as `<style id="box-kite-styles" data-box-kite="…">`, for the head. The attribute is what lets the
13
+ * browser adopt the sheet on hydration instead of generating and inserting every rule in it a second time.
14
+ */
15
+ export declare function getStyleTag(): string;
11
16
  /**
12
17
  * Drop every rule, class name and variable the engine has emitted, so the next request starts blank.
13
18
  * Registration (`Box.extend()`, `Box.components()`) survives. Call it once per request, after `getStyles()`.
@@ -15,10 +20,11 @@ export declare function getStyles(): string;
15
20
  export declare function resetStyles(): void;
16
21
  /**
17
22
  * Render `element` to static HTML together with its CSS. With `addStylesToHead` (the default) and a
18
- * `<head>` in the tree the styles go there; otherwise use the returned `styles`. The engine is reset
23
+ * `<head>` in the tree the style tag goes there; otherwise use the returned `styleTag`. The engine is reset
19
24
  * before returning, so sequential calls are independent.
20
25
  */
21
26
  export declare function renderToStaticMarkup(element: React.ReactElement, addStylesToHead?: boolean): {
22
27
  html: string;
23
28
  styles: string;
29
+ styleTag: string;
24
30
  };
package/ssg.mjs CHANGED
@@ -5,21 +5,25 @@ function n() {
5
5
  return e.getStyles();
6
6
  }
7
7
  function r() {
8
+ return e.getStyleTag();
9
+ }
10
+ function i() {
8
11
  e.clear();
9
12
  }
10
- function i(i, a = !0) {
11
- let o = t.renderToStaticMarkup(i), s = n();
13
+ function a(e, a = !0) {
14
+ let o = t.renderToStaticMarkup(e), s = n(), c = r();
12
15
  if (a) {
13
- let t = o.indexOf("<head>");
14
- if (t > -1) {
15
- let n = t + 6;
16
- o = o.substring(0, n) + `<style id="${e.styleElementId()}">${s}</style>` + o.substring(n);
16
+ let e = o.indexOf("<head>");
17
+ if (e > -1) {
18
+ let t = e + 6;
19
+ o = o.substring(0, t) + c + o.substring(t);
17
20
  }
18
21
  }
19
- return r(), {
22
+ return i(), {
20
23
  html: o,
21
- styles: s
24
+ styles: s,
25
+ styleTag: c
22
26
  };
23
27
  }
24
28
  //#endregion
25
- export { n as getStyles, i as renderToStaticMarkup, r as resetStyles };
29
+ export { r as getStyleTag, n as getStyles, a as renderToStaticMarkup, i as resetStyles };