@niscorp/loom 0.4.0 → 0.6.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 (79) hide show
  1. package/CHANGELOG.md +118 -0
  2. package/DESIGN.md +48 -10
  3. package/README.md +63 -11
  4. package/dist/{chunk-HHPSU7IA.js → chunk-3UI7CG24.js} +3 -4
  5. package/dist/chunk-3UI7CG24.js.map +1 -0
  6. package/dist/{chunk-LVDY6FUH.js → chunk-BYOKCNIJ.js} +3 -3
  7. package/dist/{chunk-LVDY6FUH.js.map → chunk-BYOKCNIJ.js.map} +1 -1
  8. package/dist/chunk-GXA57JFR.js +409 -0
  9. package/dist/chunk-GXA57JFR.js.map +1 -0
  10. package/dist/chunk-J5SYOIR2.js +100 -0
  11. package/dist/chunk-J5SYOIR2.js.map +1 -0
  12. package/dist/{chunk-VMOYMYMV.js → chunk-LAQIW27Q.js} +3 -3
  13. package/dist/chunk-LAQIW27Q.js.map +1 -0
  14. package/dist/{chunk-IQMWPPHW.js → chunk-OVTQEAV3.js} +290 -23
  15. package/dist/chunk-OVTQEAV3.js.map +1 -0
  16. package/dist/index.cjs +74 -32
  17. package/dist/index.cjs.map +1 -1
  18. package/dist/index.d.cts +9 -9
  19. package/dist/index.d.ts +9 -9
  20. package/dist/index.js +1 -4
  21. package/dist/loom-editor-DlNYrfT9.d.ts +15 -0
  22. package/dist/loom-editor-DtGAf8eH.d.cts +15 -0
  23. package/dist/plugins/nova/index.cjs +6 -3
  24. package/dist/plugins/nova/index.cjs.map +1 -1
  25. package/dist/plugins/nova/index.d.cts +1 -1
  26. package/dist/plugins/nova/index.d.ts +1 -1
  27. package/dist/plugins/nova/index.js +2 -3
  28. package/dist/plugins/nova/react/index.cjs +21 -7
  29. package/dist/plugins/nova/react/index.cjs.map +1 -1
  30. package/dist/plugins/nova/react/index.d.cts +2 -2
  31. package/dist/plugins/nova/react/index.d.ts +2 -2
  32. package/dist/plugins/nova/react/index.js +5 -5
  33. package/dist/plugins/nova/react/index.js.map +1 -1
  34. package/dist/plugins/prism/index.cjs +2 -0
  35. package/dist/plugins/prism/index.cjs.map +1 -1
  36. package/dist/plugins/prism/index.d.cts +1 -1
  37. package/dist/plugins/prism/index.d.ts +1 -1
  38. package/dist/plugins/prism/index.js +2 -2
  39. package/dist/plugins/prism/react/index.cjs +200 -189
  40. package/dist/plugins/prism/react/index.cjs.map +1 -1
  41. package/dist/plugins/prism/react/index.d.cts +3 -3
  42. package/dist/plugins/prism/react/index.d.ts +3 -3
  43. package/dist/plugins/prism/react/index.js +48 -108
  44. package/dist/plugins/prism/react/index.js.map +1 -1
  45. package/dist/plugins/vex/index.cjs +2 -0
  46. package/dist/plugins/vex/index.cjs.map +1 -1
  47. package/dist/plugins/vex/index.d.cts +1 -1
  48. package/dist/plugins/vex/index.d.ts +1 -1
  49. package/dist/plugins/vex/index.js +2 -2
  50. package/dist/plugins/vex/react/index.cjs +154 -96
  51. package/dist/plugins/vex/react/index.cjs.map +1 -1
  52. package/dist/plugins/vex/react/index.d.cts +3 -3
  53. package/dist/plugins/vex/react/index.d.ts +3 -3
  54. package/dist/plugins/vex/react/index.js +42 -29
  55. package/dist/plugins/vex/react/index.js.map +1 -1
  56. package/dist/react/index.cjs +153 -92
  57. package/dist/react/index.cjs.map +1 -1
  58. package/dist/react/index.d.cts +7 -3
  59. package/dist/react/index.d.ts +7 -3
  60. package/dist/react/index.js +3 -118
  61. package/dist/react/index.js.map +1 -1
  62. package/dist/{types-V5kJWZJn.d.ts → types-BWIIThEy.d.cts} +2 -0
  63. package/dist/{types-V5kJWZJn.d.cts → types-BWIIThEy.d.ts} +2 -0
  64. package/package.json +7 -7
  65. package/dist/chunk-27OMOR7I.js +0 -17
  66. package/dist/chunk-27OMOR7I.js.map +0 -1
  67. package/dist/chunk-67D727GH.js +0 -47
  68. package/dist/chunk-67D727GH.js.map +0 -1
  69. package/dist/chunk-BU5TULRP.js +0 -132
  70. package/dist/chunk-BU5TULRP.js.map +0 -1
  71. package/dist/chunk-DEZGKUTO.js +0 -170
  72. package/dist/chunk-DEZGKUTO.js.map +0 -1
  73. package/dist/chunk-HHPSU7IA.js.map +0 -1
  74. package/dist/chunk-IQMWPPHW.js.map +0 -1
  75. package/dist/chunk-OFKHIREC.js +0 -212
  76. package/dist/chunk-OFKHIREC.js.map +0 -1
  77. package/dist/chunk-VMOYMYMV.js.map +0 -1
  78. package/dist/loom-editor-BthwIGIZ.d.cts +0 -24
  79. package/dist/loom-editor-CHtjjiBp.d.ts +0 -24
@@ -1,83 +1,15 @@
1
1
  'use strict';
2
2
 
3
3
  var prism$1 = require('@niscorp/prism');
4
+ require('zod');
5
+ require('@niscorp/nova');
6
+ var react$1 = require('@niscorp/nova/adapters/react');
4
7
  var jsxRuntime = require('react/jsx-runtime');
5
8
  var react = require('react');
6
- var react$1 = require('@niscorp/nova/adapters/react');
9
+ var examples = require('@niscorp/prism/examples');
7
10
 
8
11
  // src/plugins/prism/index.ts
9
12
 
10
- // src/editor/view.ts
11
- var mountView = (editor, action, read) => {
12
- const { shell } = editor;
13
- shell.registerAction(action);
14
- shell.addCanvas({ id: action.id, initial: action.id });
15
- const instance = shell.getCanvasState(action.id).active?.id;
16
- if (instance === void 0) return;
17
- const sync = () => {
18
- shell.getRuntime(instance)?.setData(read(editor));
19
- };
20
- editor.on("change", sync);
21
- sync();
22
- };
23
-
24
- // src/plugins/prism/preview.layout.ts
25
- var PREVIEW = "prism:preview";
26
- var previewLayout = {
27
- component: PREVIEW,
28
- props: { config: "$.config" }
29
- };
30
-
31
- // src/plugins/prism/preview.action.ts
32
- var previewAction = {
33
- id: PREVIEW,
34
- layout: previewLayout,
35
- data: { config: null }
36
- };
37
-
38
- // src/plugins/prism/index.ts
39
- var NODE = "prism:node";
40
- var prismPlugin = (options) => ({
41
- name: "prism",
42
- documents: { config: options.schema ?? prism$1.NodeSchema },
43
- widgets: [{ role: NODE, match: (field) => field.kind === "union" && field.path === "" }],
44
- mount: (editor) => mountView(editor, previewAction, (e) => ({ config: e.documents["config"] }))
45
- });
46
- var mono = "ui-monospace, SFMono-Regular, Menlo, monospace";
47
- var Note = ({ children }) => /* @__PURE__ */ jsxRuntime.jsx("div", { style: { fontSize: 13, color: "#6b7280", padding: 12 }, children });
48
- var jsonStyle = (tone) => ({
49
- margin: 0,
50
- padding: 12,
51
- borderRadius: 6,
52
- fontSize: 12,
53
- fontFamily: mono,
54
- whiteSpace: "pre-wrap",
55
- wordBreak: "break-word",
56
- maxHeight: 320,
57
- overflow: "auto",
58
- border: "1px solid #e5e7eb",
59
- background: tone === "error" ? "#fef2f2" : tone === "muted" ? "#f9fafb" : "#ffffff",
60
- color: tone === "error" ? "#991b1b" : "#1f2937"
61
- });
62
- var head = { fontSize: 11, fontWeight: 700, textTransform: "uppercase", letterSpacing: 0.4, color: "#6b7280", margin: "0 0 4px" };
63
- var Panel = ({ label: label2, tone = "plain", children }) => /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
64
- /* @__PURE__ */ jsxRuntime.jsx("div", { style: head, children: label2 }),
65
- /* @__PURE__ */ jsxRuntime.jsx("pre", { style: jsonStyle(tone), children })
66
- ] });
67
- var show = (value) => JSON.stringify(value, null, 2);
68
- var makePreview = (input2) => {
69
- const Preview = ({ config }) => {
70
- if (config === null || config === void 0) return /* @__PURE__ */ jsxRuntime.jsx(Note, { children: "Edit the config to see its output." });
71
- const parsed = prism$1.ConfigSchema.safeParse(config);
72
- const result = parsed.success ? prism$1.evaluateSafe(parsed.data, input2) : void 0;
73
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", flexDirection: "column", gap: 12 }, children: [
74
- /* @__PURE__ */ jsxRuntime.jsx(Panel, { label: "Input", tone: "muted", children: show(input2) }),
75
- !parsed.success ? /* @__PURE__ */ jsxRuntime.jsx(Panel, { label: "Output", tone: "error", children: parsed.error.message }) : result !== void 0 && result.ok ? /* @__PURE__ */ jsxRuntime.jsx(Panel, { label: "Output", children: show(result.data) }) : /* @__PURE__ */ jsxRuntime.jsx(Panel, { label: "Output", tone: "error", children: result !== void 0 && !result.ok ? result.error.message : "" })
76
- ] });
77
- };
78
- return Preview;
79
- };
80
-
81
13
  // src/compile/parse.ts
82
14
  var defOf = (schema) => schema.def;
83
15
  var INTEGER_FORMAT = "safeint";
@@ -95,24 +27,41 @@ var isInteger = (schema) => {
95
27
  return (def.checks ?? []).some((check) => check.def?.format === INTEGER_FORMAT);
96
28
  };
97
29
  var enumOptions = (schema) => Object.values(defOf(schema).entries ?? {}).map((value) => ({ value, label: String(value) }));
30
+ var acceptsAbsence = (schema) => {
31
+ try {
32
+ return schema.safeParse(void 0).success;
33
+ } catch {
34
+ return false;
35
+ }
36
+ };
98
37
  var objectFields = (schema, walk) => Object.entries(defOf(schema).shape ?? {}).map(([key, value]) => ({
99
38
  key,
100
- required: !value.safeParse(void 0).success,
39
+ required: !acceptsAbsence(value),
101
40
  field: parseField(value, walk)
102
41
  }));
103
- var branchKeys = (branch) => Object.keys(defOf(branch).shape ?? {});
42
+ var shapeOf = (branch) => defOf(unwrap(branch).core).shape ?? {};
43
+ var branchKeys = (branch) => Object.keys(shapeOf(branch));
104
44
  var JSON_TYPES = /* @__PURE__ */ new Set(["string", "number", "boolean", "object", "array", "null"]);
105
45
  var jsonType = (branch) => {
106
- const type = defOf(branch).type;
46
+ const type = defOf(unwrap(branch).core).type;
107
47
  return JSON_TYPES.has(type) ? type : void 0;
108
48
  };
49
+ var tagPattern = (key, discriminator) => {
50
+ const def = discriminator === void 0 ? void 0 : defOf(discriminator);
51
+ const values = def === void 0 ? [] : def.values !== void 0 ? [...def.values] : Object.values(def.entries ?? {});
52
+ return values.length > 1 ? { kind: "tag", key, value: values[0], values } : { kind: "tag", key, value: values[0] };
53
+ };
109
54
  var distinguish = (branch, siblings, tag2) => {
55
+ const shape = shapeOf(branch);
110
56
  if (tag2 !== void 0) {
111
- const literal = (defOf(branch).shape ?? {})[tag2];
112
- return { kind: "tag", key: tag2, value: literal !== void 0 ? defOf(literal).values?.[0] : void 0 };
57
+ return tagPattern(tag2, shape[tag2]);
113
58
  }
114
59
  const elsewhere = new Set(siblings.flatMap(branchKeys));
115
- const key = branchKeys(branch).find((k) => !elsewhere.has(k));
60
+ const own = Object.keys(shape).filter((k) => !elsewhere.has(k));
61
+ const key = own.find((k) => {
62
+ const schema = shape[k];
63
+ return schema !== void 0 && !acceptsAbsence(schema);
64
+ }) ?? own[0];
116
65
  if (key !== void 0) return { kind: "key", key };
117
66
  const type = jsonType(branch);
118
67
  if (type !== void 0 && siblings.every((s) => jsonType(s) !== type)) return { kind: "type", type };
@@ -134,6 +83,10 @@ var parseByType = {
134
83
  number: (schema) => isInteger(schema) ? { kind: "number", integer: true } : { kind: "number" },
135
84
  boolean: () => ({ kind: "boolean" }),
136
85
  enum: (schema) => ({ kind: "enum", options: enumOptions(schema) }),
86
+ literal: (schema) => {
87
+ const values = defOf(schema).values ?? [];
88
+ return { kind: "enum", options: values.map((value) => ({ value, label: String(value) })), default: values[0] };
89
+ },
137
90
  object: (schema, walk) => {
138
91
  const def = defOf(schema);
139
92
  walk.stack.add(def);
@@ -178,15 +131,17 @@ var resolveLazy = (lazy) => {
178
131
  var unwrap = (schema) => {
179
132
  let core = schema;
180
133
  let fallback;
134
+ let nullable = false;
181
135
  let def = defOf(core);
182
136
  while (WRAPPERS.has(def.type) || def.type === "lazy") {
137
+ if (def.type === "nullable") nullable = true;
183
138
  const inner = def.type === "lazy" ? resolveLazy(core) : def.innerType;
184
139
  if (inner === void 0) break;
185
- if ("defaultValue" in def) fallback = def.defaultValue;
140
+ if ("defaultValue" in def && fallback === void 0) fallback = def.defaultValue;
186
141
  core = inner;
187
142
  def = defOf(core);
188
143
  }
189
- return fallback !== void 0 ? { core, default: fallback } : { core };
144
+ return { core, ...fallback !== void 0 ? { default: fallback } : {}, ...nullable ? { nullable: true } : {} };
190
145
  };
191
146
  var readMeta = (schema) => {
192
147
  const meta = {};
@@ -196,14 +151,14 @@ var readMeta = (schema) => {
196
151
  return meta;
197
152
  };
198
153
  var parseField = (schema, walk) => {
199
- const { core, default: fallback } = unwrap(schema);
154
+ const { core, default: fallback, nullable } = unwrap(schema);
200
155
  if (walk.stack.has(defOf(core))) {
201
156
  walk.targets.add(defOf(core));
202
157
  return { kind: "self" };
203
158
  }
204
159
  const body = (parseByType[defOf(core).type] ?? unknownField)(core, walk);
205
160
  const meta = { ...readMeta(core), ...readMeta(schema) };
206
- return { ...body, ...meta, ...fallback !== void 0 ? { default: fallback } : {} };
161
+ return { ...body, ...meta, ...fallback !== void 0 ? { default: fallback } : {}, ...nullable === true ? { nullable } : {} };
207
162
  };
208
163
  var parse = (schema) => parseField(schema, { stack: /* @__PURE__ */ new Set(), targets: /* @__PURE__ */ new Set() });
209
164
  var EMPTY = {
@@ -228,10 +183,10 @@ var EMPTY = {
228
183
  }
229
184
  return document;
230
185
  },
231
- union: (field) => {
186
+ union: (field, options) => {
232
187
  if (field.kind !== "union") return {};
233
188
  const first = field.variants[0];
234
- return first === void 0 ? {} : variantDefaults(first);
189
+ return first === void 0 ? {} : variantDefaults(first, options);
235
190
  }
236
191
  };
237
192
  var buildDocument = (field, options) => {
@@ -239,11 +194,48 @@ var buildDocument = (field, options) => {
239
194
  return (options.empty?.[field.kind] ?? EMPTY[field.kind])(field, options);
240
195
  };
241
196
  var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
242
- var variantDefaults = (variant) => {
243
- const defaults = buildDocument(variant.field, {});
197
+ var variantDefaults = (variant, options) => {
198
+ const defaults = buildDocument(variant.field, options);
244
199
  if (variant.pattern.kind !== "tag") return defaults;
245
200
  return { [variant.pattern.key]: variant.pattern.value, ...isRecord(defaults) ? defaults : {} };
246
201
  };
202
+
203
+ // src/editor/view.ts
204
+ var mountView = (editor, action, read) => {
205
+ const { shell } = editor;
206
+ shell.registerAction(action);
207
+ shell.addCanvas({ id: action.id, initial: action.id });
208
+ const instance = shell.getCanvasState(action.id).active?.id;
209
+ if (instance === void 0) return;
210
+ const sync = () => {
211
+ shell.getRuntime(instance)?.setData(read(editor));
212
+ };
213
+ editor.on("change", sync);
214
+ sync();
215
+ };
216
+
217
+ // src/plugins/prism/preview.layout.ts
218
+ var PREVIEW = "prism:preview";
219
+ var previewLayout = {
220
+ component: PREVIEW,
221
+ props: { config: "$.config" }
222
+ };
223
+
224
+ // src/plugins/prism/preview.action.ts
225
+ var previewAction = {
226
+ id: PREVIEW,
227
+ layout: previewLayout,
228
+ data: { config: null }
229
+ };
230
+
231
+ // src/plugins/prism/index.ts
232
+ var NODE = "prism:node";
233
+ var prismPlugin = (options) => ({
234
+ name: "prism",
235
+ documents: { config: options.schema ?? prism$1.NodeSchema },
236
+ widgets: [{ role: NODE, match: (field) => field.kind === "union" && field.path === "" }],
237
+ mount: (editor) => mountView(editor, previewAction, (e) => ({ config: e.documents["config"] }))
238
+ });
247
239
  var useModelWrite = (model) => {
248
240
  const dispatch = react$1.useNovaDispatch();
249
241
  return (value) => {
@@ -251,8 +243,27 @@ var useModelWrite = (model) => {
251
243
  };
252
244
  };
253
245
 
246
+ // src/react/kit/tokens.ts
247
+ var COLORS = {
248
+ border: "var(--loom-border, #d1d5db)",
249
+ borderSubtle: "var(--loom-border-subtle, #e5e7eb)",
250
+ surface: "var(--loom-surface, #fff)",
251
+ surfaceMuted: "var(--loom-surface-muted, #f9fafb)",
252
+ fill: "var(--loom-fill, #f3f4f6)",
253
+ textBody: "var(--loom-text-body, #1f2937)",
254
+ label: "var(--loom-label, #374151)",
255
+ muted: "var(--loom-muted, #6b7280)",
256
+ faint: "var(--loom-faint, #9ca3af)",
257
+ accent: "var(--loom-accent, #1d4ed8)",
258
+ accentFill: "var(--loom-accent-fill, #eff6ff)",
259
+ danger: "var(--loom-danger, #dc2626)",
260
+ dangerText: "var(--loom-danger-text, #991b1b)",
261
+ dangerFill: "var(--loom-danger-fill, #fef2f2)",
262
+ shadow: "var(--loom-shadow, rgba(0,0,0,0.12))",
263
+ shadowStrong: "var(--loom-shadow-strong, rgba(0,0,0,0.14))"};
264
+
254
265
  // src/react/kit/shared.ts
255
- var inputStyle = { padding: "6px 10px", border: "1px solid #d1d5db", borderRadius: 6, fontSize: 14, width: "100%", boxSizing: "border-box" };
266
+ var inputStyle = { padding: "6px 10px", border: `1px solid ${COLORS.border}`, borderRadius: 6, fontSize: 14, width: "100%", boxSizing: "border-box" };
256
267
  var rawStyle = {
257
268
  ...inputStyle,
258
269
  margin: 0,
@@ -298,19 +309,20 @@ var JsonEditor = ({ value, onChange }) => {
298
309
  setValid(false);
299
310
  }
300
311
  },
301
- style: valid ? rawStyle : { ...rawStyle, borderColor: "#dc2626", background: "#fef2f2" }
312
+ style: valid ? rawStyle : { ...rawStyle, borderColor: COLORS.danger, background: COLORS.dangerFill }
302
313
  }
303
314
  );
304
315
  };
305
- var trigger = { padding: "4px 8px", border: "1px solid #d1d5db", borderRadius: 6, background: "#fff", cursor: "pointer", fontSize: 13, lineHeight: 1 };
306
- var base = { position: "absolute", zIndex: 30, minWidth: 170, display: "flex", flexDirection: "column", background: "#fff", border: "1px solid #d1d5db", borderRadius: 6, boxShadow: "0 6px 16px rgba(0,0,0,0.12)", padding: 4 };
316
+ react.createContext(0);
317
+ var trigger = { padding: "4px 8px", border: `1px solid ${COLORS.border}`, borderRadius: 6, background: COLORS.surface, cursor: "pointer", fontSize: 13, lineHeight: 1 };
318
+ var base = { position: "absolute", zIndex: 30, minWidth: 170, display: "flex", flexDirection: "column", background: COLORS.surface, border: `1px solid ${COLORS.border}`, borderRadius: 6, boxShadow: `0 6px 16px ${COLORS.shadow}`, padding: 4 };
307
319
  var menuRight = { ...base, top: "100%", right: 0, marginTop: 4 };
308
320
  var menuLeft = { ...base, top: "100%", left: 0, marginTop: 4 };
309
321
  var flyLeft = { ...base, top: 0, right: "100%", maxHeight: 280, overflowY: "auto" };
310
322
  var flyRight = { ...base, top: 0, left: "100%", maxHeight: 280, overflowY: "auto" };
311
323
  var itemStyle = { width: "100%", boxSizing: "border-box", textAlign: "left", padding: "6px 10px", cursor: "pointer", fontSize: 13, borderRadius: 4, whiteSpace: "nowrap", display: "flex", justifyContent: "space-between", gap: 12 };
312
- var itemDisabled = { ...itemStyle, color: "#9ca3af", cursor: "default" };
313
- var MENU_CSS = ".loom-menu-item{background:transparent;border:none;}.loom-menu-item:hover:not(:disabled){background:#f3f4f6;}";
324
+ var itemDisabled = { ...itemStyle, color: COLORS.faint, cursor: "default" };
325
+ var MENU_CSS = `.loom-menu-item{background:transparent;border:none;}.loom-menu-item:hover:not(:disabled){background:${COLORS.fill};}`;
314
326
  var MenuContext = react.createContext({ close: () => {
315
327
  }, anchor: "right" });
316
328
  var ActionMenu = ({
@@ -359,81 +371,78 @@ var SubMenu = ({ label: label2, children }) => {
359
371
  open ? /* @__PURE__ */ jsxRuntime.jsx("div", { style: anchor === "right" ? flyLeft : flyRight, children }) : null
360
372
  ] });
361
373
  };
362
- var CATEGORY_ORDER = ["Value", "Core", "Array", "Math", "String", "Predicate", "Logic", "Structure", "Object", "Time", "Sugar"];
363
- var OP_CATEGORY = {
364
- $ref: "Core",
365
- $const: "Core",
366
- $var: "Core",
367
- $get: "Core",
368
- $with: "Core",
369
- $map: "Array",
370
- $filter: "Array",
371
- $reduce: "Array",
372
- $slice: "Array",
373
- $flatten: "Array",
374
- $unique: "Array",
375
- $sortBy: "Array",
376
- $add: "Math",
377
- $sub: "Math",
378
- $mul: "Math",
379
- $div: "Math",
380
- $mod: "Math",
381
- $round: "Math",
382
- $toNumber: "Math",
383
- $join: "String",
384
- $toString: "String",
385
- $interpolate: "String",
386
- $trim: "String",
387
- $lower: "String",
388
- $upper: "String",
389
- $split: "String",
390
- $replace: "String",
391
- $eq: "Predicate",
392
- $neq: "Predicate",
393
- $gt: "Predicate",
394
- $gte: "Predicate",
395
- $lt: "Predicate",
396
- $lte: "Predicate",
397
- $empty: "Predicate",
398
- $startsWith: "Predicate",
399
- $endsWith: "Predicate",
400
- $contains: "Predicate",
401
- $not: "Logic",
402
- $and: "Logic",
403
- $or: "Logic",
404
- $merge: "Structure",
405
- $coalesce: "Structure",
406
- $case: "Structure",
407
- $entriesOf: "Structure",
408
- $keyBy: "Structure",
409
- $groupBy: "Structure",
410
- $keys: "Object",
411
- $values: "Object",
412
- $fromEntries: "Object",
413
- $pick: "Object",
414
- $omit: "Object",
415
- $type: "Object",
416
- $length: "Object",
417
- $date: "Time",
418
- $dateAdd: "Time",
419
- $dateDiff: "Time",
420
- $sum: "Sugar",
421
- $avg: "Sugar",
422
- $count: "Sugar",
423
- $min: "Sugar",
424
- $max: "Sugar",
425
- $pluck: "Sugar",
426
- $take: "Sugar",
427
- $drop: "Sugar",
428
- $match: "Sugar",
429
- $flatMap: "Sugar"
374
+ var clashStyle = { fontSize: 12, color: COLORS.danger };
375
+ var KeyInput = ({ value, isTaken, onRename, placeholder, style }) => {
376
+ const [clash, setClash] = react.useState(void 0);
377
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", flexDirection: "column", gap: 2 }, children: [
378
+ /* @__PURE__ */ jsxRuntime.jsx(
379
+ "input",
380
+ {
381
+ value: clash ?? value,
382
+ placeholder,
383
+ "aria-invalid": clash !== void 0,
384
+ onChange: (event) => {
385
+ const name = event.target.value;
386
+ if (name !== value && isTaken(name)) {
387
+ setClash(name);
388
+ return;
389
+ }
390
+ setClash(void 0);
391
+ if (name !== value) onRename(name);
392
+ },
393
+ onBlur: () => setClash(void 0),
394
+ style: clash === void 0 ? style : { ...style, borderColor: COLORS.danger }
395
+ }
396
+ ),
397
+ clash !== void 0 ? /* @__PURE__ */ jsxRuntime.jsx("span", { role: "alert", style: clashStyle, children: `"${clash}" is already a key` }) : null
398
+ ] });
399
+ };
400
+ var mono = "ui-monospace, SFMono-Regular, Menlo, monospace";
401
+ var Note = ({ children }) => /* @__PURE__ */ jsxRuntime.jsx("div", { style: { fontSize: 13, color: COLORS.muted, padding: 12 }, children });
402
+ var jsonStyle = (tone) => ({
403
+ margin: 0,
404
+ padding: 12,
405
+ borderRadius: 6,
406
+ fontSize: 12,
407
+ fontFamily: mono,
408
+ whiteSpace: "pre-wrap",
409
+ wordBreak: "break-word",
410
+ maxHeight: 320,
411
+ overflow: "auto",
412
+ border: `1px solid ${COLORS.borderSubtle}`,
413
+ background: tone === "error" ? COLORS.dangerFill : tone === "muted" ? COLORS.surfaceMuted : COLORS.surface,
414
+ color: tone === "error" ? COLORS.dangerText : COLORS.textBody
415
+ });
416
+ var head = { fontSize: 11, fontWeight: 700, textTransform: "uppercase", letterSpacing: 0.4, color: COLORS.muted, margin: "0 0 4px" };
417
+ var Panel = ({ label: label2, tone = "plain", children }) => /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
418
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: head, children: label2 }),
419
+ /* @__PURE__ */ jsxRuntime.jsx("pre", { style: jsonStyle(tone), children })
420
+ ] });
421
+ var show = (value) => JSON.stringify(value, null, 2);
422
+ var makePreview = (input2) => {
423
+ const Preview = ({ config }) => {
424
+ if (config === null || config === void 0) return /* @__PURE__ */ jsxRuntime.jsx(Note, { children: "Edit the config to see its output." });
425
+ const parsed = prism$1.ConfigSchema.safeParse(config);
426
+ const result = parsed.success ? prism$1.evaluateSafe(parsed.data, input2) : void 0;
427
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", flexDirection: "column", gap: 12 }, children: [
428
+ /* @__PURE__ */ jsxRuntime.jsx(Panel, { label: "Input", tone: "muted", children: show(input2) }),
429
+ !parsed.success ? /* @__PURE__ */ jsxRuntime.jsx(Panel, { label: "Output", tone: "error", children: parsed.error.message }) : result !== void 0 && result.ok ? /* @__PURE__ */ jsxRuntime.jsx(Panel, { label: "Output", children: show(result.data) }) : /* @__PURE__ */ jsxRuntime.jsx(Panel, { label: "Output", tone: "error", children: result !== void 0 && !result.ok ? result.error.message : "" })
430
+ ] });
431
+ };
432
+ return Preview;
430
433
  };
434
+ var GROUP_TITLE = new Map(examples.PRISM_EXAMPLE_GROUPS.map((group) => [group.id, group.title]));
435
+ var OP_CATEGORY = new Map(
436
+ examples.PRISM_EXAMPLES.flatMap((example) => example.op === void 0 ? [] : [[example.op, GROUP_TITLE.get(example.group) ?? example.group]])
437
+ );
438
+ var CATEGORY_ORDER = ["Value", ...GROUP_TITLE.values(), "Other"];
439
+ var OPS = new Set(prism$1.OP_KEYS);
431
440
  var TYPE_LABEL = { string: "string", number: "number", boolean: "boolean", null: "null", array: "array of nodes" };
432
441
  var NODE_IR = parse(prism$1.NodeSchema);
433
442
  var KINDS = (NODE_IR.kind === "union" ? NODE_IR.variants : []).map((variant) => {
434
443
  if (variant.pattern.kind === "key") {
435
444
  const id = variant.pattern.key;
436
- return { id, label: id, category: OP_CATEGORY[id] ?? "Other", variant };
445
+ return { id, label: id, category: OP_CATEGORY.get(id) ?? "Other", variant };
437
446
  }
438
447
  if (variant.pattern.kind === "type") {
439
448
  const id = variant.pattern.type;
@@ -442,7 +451,6 @@ var KINDS = (NODE_IR.kind === "union" ? NODE_IR.variants : []).map((variant) =>
442
451
  return { id: "template", label: "object (template)", category: "Value", variant };
443
452
  });
444
453
  var BY_ID = new Map(KINDS.map((kind) => [kind.id, kind]));
445
- var OP_KEYS = new Set(KINDS.filter((kind) => kind.category !== "Value").map((kind) => kind.id));
446
454
  var isObj = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
447
455
  var argFieldOf = (variant) => variant.field.kind === "object" ? variant.field.fields[0]?.field : variant.field;
448
456
  var kindOf = (value) => {
@@ -450,9 +458,10 @@ var kindOf = (value) => {
450
458
  if (value === null || value === void 0) return "null";
451
459
  const type = typeof value;
452
460
  if (type === "string" || type === "number" || type === "boolean") return type;
453
- if (type === "object") return Object.keys(value).find((key) => OP_KEYS.has(key)) ?? "template";
461
+ if (type === "object") return Object.keys(value).find((key) => OPS.has(key)) ?? "template";
454
462
  return "template";
455
463
  };
464
+ var REQUIRED_ONLY = { includeOptional: false };
456
465
  var defaultFor = (id) => {
457
466
  switch (id) {
458
467
  case "template":
@@ -469,11 +478,11 @@ var defaultFor = (id) => {
469
478
  return null;
470
479
  default: {
471
480
  const arg = argFieldOf(BY_ID.get(id).variant);
472
- return { [id]: arg !== void 0 ? buildDocument(arg, {}) : {} };
481
+ return { [id]: arg !== void 0 ? buildDocument(arg, REQUIRED_ONLY) : {} };
473
482
  }
474
483
  }
475
484
  };
476
- var defaultItem = (field) => field.kind === "self" ? null : field.kind === "string" ? "" : field.kind === "number" ? 0 : field.kind === "boolean" ? false : buildDocument(field, {});
485
+ var defaultItem = (field) => field.kind === "self" ? null : buildDocument(field, REQUIRED_ONLY);
477
486
  var nodeSlot = (field) => {
478
487
  if (field.kind === "self") return (node) => node;
479
488
  if (field.kind === "array" && field.item.kind === "self") return (node) => [node];
@@ -481,7 +490,7 @@ var nodeSlot = (field) => {
481
490
  const at = field.items.findIndex((item) => item.kind === "self");
482
491
  if (at < 0) return void 0;
483
492
  return (node) => {
484
- const slots = buildDocument(field, {}).slice();
493
+ const slots = buildDocument(field, REQUIRED_ONLY).slice();
485
494
  slots[at] = node;
486
495
  return slots;
487
496
  };
@@ -490,7 +499,7 @@ var nodeSlot = (field) => {
490
499
  const prop = field.fields.find((p) => nodeSlot(p.field) !== void 0);
491
500
  if (prop === void 0) return void 0;
492
501
  const place = nodeSlot(prop.field);
493
- return (node) => ({ ...isObj(buildDocument(field, {})) ? buildDocument(field, {}) : {}, [prop.key]: place(node) });
502
+ return (node) => ({ ...isObj(buildDocument(field, REQUIRED_ONLY)) ? buildDocument(field, REQUIRED_ONLY) : {}, [prop.key]: place(node) });
494
503
  }
495
504
  return void 0;
496
505
  };
@@ -526,21 +535,21 @@ var unwrapChildren = (value) => {
526
535
  if (kind === void 0 || kind.category === "Value") return [];
527
536
  return nodeChildren(argFieldOf(kind.variant), isObj(value) ? value[id] : void 0);
528
537
  };
529
- var input = { padding: "6px 10px", border: "1px solid #d1d5db", borderRadius: 6, fontSize: 14, width: "100%", boxSizing: "border-box" };
538
+ var input = { padding: "6px 10px", border: `1px solid ${COLORS.border}`, borderRadius: 6, fontSize: 14, width: "100%", boxSizing: "border-box" };
530
539
  var block = { display: "flex", flexDirection: "column", gap: 8 };
531
- var nested = { ...block, paddingLeft: 12, borderLeft: "2px solid #e5e7eb" };
532
- var groupBox = { ...block, padding: 10, border: "1px solid #e5e7eb", borderRadius: 6 };
533
- var label = { fontSize: 12, fontWeight: 600, color: "#374151" };
540
+ var nested = { ...block, paddingLeft: 12, borderLeft: `2px solid ${COLORS.borderSubtle}` };
541
+ var groupBox = { ...block, padding: 10, border: `1px solid ${COLORS.borderSubtle}`, borderRadius: 6 };
542
+ var label = { fontSize: 12, fontWeight: 600, color: COLORS.label };
534
543
  var rowStyle = { display: "flex", gap: 6, alignItems: "flex-start" };
535
- var iconBtn = { padding: "4px 8px", border: "1px solid #d1d5db", borderRadius: 6, background: "#fff", cursor: "pointer", fontSize: 13, lineHeight: 1 };
536
- var addBtn = { ...input, alignSelf: "flex-start", cursor: "pointer", background: "#f3f4f6", width: "auto" };
537
- var chooserBtn = { ...input, display: "flex", justifyContent: "space-between", alignItems: "center", cursor: "pointer", background: "#fff", textAlign: "left" };
538
- var popover = { position: "absolute", top: "100%", left: 0, zIndex: 40, marginTop: 4, width: 380, background: "#fff", border: "1px solid #d1d5db", borderRadius: 8, boxShadow: "0 8px 24px rgba(0,0,0,0.14)", overflow: "hidden" };
539
- var catPane = { minWidth: 132, borderRight: "1px solid #e5e7eb", overflowY: "auto", padding: 4 };
544
+ var iconBtn = { padding: "4px 8px", border: `1px solid ${COLORS.border}`, borderRadius: 6, background: COLORS.surface, cursor: "pointer", fontSize: 13, lineHeight: 1 };
545
+ var addBtn = { ...input, alignSelf: "flex-start", cursor: "pointer", background: COLORS.fill, width: "auto" };
546
+ var chooserBtn = { ...input, display: "flex", justifyContent: "space-between", alignItems: "center", cursor: "pointer", background: COLORS.surface, textAlign: "left" };
547
+ var popover = { position: "absolute", top: "100%", left: 0, zIndex: 40, marginTop: 4, width: 380, background: COLORS.surface, border: `1px solid ${COLORS.border}`, borderRadius: 8, boxShadow: `0 8px 24px ${COLORS.shadowStrong}`, overflow: "hidden" };
548
+ var catPane = { minWidth: 132, borderRight: `1px solid ${COLORS.borderSubtle}`, overflowY: "auto", padding: 4 };
540
549
  var opPane = { flex: 1, overflowY: "auto", padding: 4 };
541
- var tag = { fontSize: 11, color: "#9ca3af" };
542
- var empty = { padding: 12, fontSize: 13, color: "#9ca3af" };
543
- var CHOOSER_CSS = '.prism-pick{width:100%;box-sizing:border-box;text-align:left;padding:6px 10px;border:none;border-radius:4px;background:transparent;cursor:pointer;font-size:13px;display:flex;justify-content:space-between;gap:10px;align-items:center;}.prism-pick:hover{background:#f3f4f6;}.prism-pick[data-active="true"]{background:#eff6ff;color:#1d4ed8;font-weight:600;}';
550
+ var tag = { fontSize: 11, color: COLORS.faint };
551
+ var empty = { padding: 12, fontSize: 13, color: COLORS.faint };
552
+ var CHOOSER_CSS = `.prism-pick{width:100%;box-sizing:border-box;text-align:left;padding:6px 10px;border:none;border-radius:4px;background:transparent;cursor:pointer;font-size:13px;display:flex;justify-content:space-between;gap:10px;align-items:center;}.prism-pick:hover{background:${COLORS.fill};}.prism-pick[data-active="true"]{background:${COLORS.accentFill};color:${COLORS.accent};font-weight:600;}`;
544
553
  var NodeKindChooser = ({ current, onPick }) => {
545
554
  const here = BY_ID.get(current);
546
555
  const [open, setOpen] = react.useState(false);
@@ -623,14 +632,17 @@ var ArgEditor = ({ field, value, onChange }) => {
623
632
  }
624
633
  ) }, index)) });
625
634
  case "object":
626
- return /* @__PURE__ */ jsxRuntime.jsx("div", { style: groupBox, children: field.fields.map((prop) => /* @__PURE__ */ jsxRuntime.jsx(Labeled, { label: prop.field.title ?? prop.key, required: prop.required, children: /* @__PURE__ */ jsxRuntime.jsx(
627
- ArgEditor,
628
- {
629
- field: prop.field,
630
- value: isObj(value) ? value[prop.key] : void 0,
631
- onChange: (next) => onChange({ ...isObj(value) ? value : {}, [prop.key]: next })
632
- }
633
- ) }, prop.key)) });
635
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { style: groupBox, children: field.fields.map((prop) => /* @__PURE__ */ jsxRuntime.jsxs(Labeled, { label: prop.field.title ?? prop.key, required: prop.required, children: [
636
+ /* @__PURE__ */ jsxRuntime.jsx(
637
+ ArgEditor,
638
+ {
639
+ field: prop.field,
640
+ value: isObj(value) ? value[prop.key] : void 0,
641
+ onChange: (next) => onChange({ ...isObj(value) ? value : {}, [prop.key]: next })
642
+ }
643
+ ),
644
+ !prop.required && isObj(value) && value[prop.key] !== void 0 ? /* @__PURE__ */ jsxRuntime.jsx("button", { type: "button", style: iconBtn, onClick: () => onChange(Object.fromEntries(Object.entries(value).filter(([key]) => key !== prop.key))), children: "Remove" }) : null
645
+ ] }, prop.key)) });
634
646
  default:
635
647
  return /* @__PURE__ */ jsxRuntime.jsx(JsonEditor, { value, onChange });
636
648
  }
@@ -652,7 +664,6 @@ var ListEditor = ({ itemField, value, onChange }) => {
652
664
  var TemplateEditor = ({ value, onChange }) => {
653
665
  const entries = Object.entries(isObj(value) ? value : {});
654
666
  const rename = (from, to) => {
655
- if (to === from) return;
656
667
  onChange(Object.fromEntries(entries.map(([key, val]) => [key === from ? to : key, val])));
657
668
  };
658
669
  const addField = () => {
@@ -663,7 +674,7 @@ var TemplateEditor = ({ value, onChange }) => {
663
674
  };
664
675
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { style: block, children: [
665
676
  entries.map(([key, val], index) => /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { ...rowStyle, alignItems: "flex-start" }, children: [
666
- /* @__PURE__ */ jsxRuntime.jsx("input", { style: { ...input, width: 150 }, value: key, onChange: (event) => rename(key, event.target.value) }),
677
+ /* @__PURE__ */ jsxRuntime.jsx(KeyInput, { style: { ...input, width: 150 }, value: key, isTaken: (name) => entries.some(([k]) => k === name), onRename: (name) => rename(key, name) }),
667
678
  /* @__PURE__ */ jsxRuntime.jsx("div", { style: { flex: 1, minWidth: 0 }, children: /* @__PURE__ */ jsxRuntime.jsx(
668
679
  NodeEditor,
669
680
  {