@niscorp/loom 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/DESIGN.md +253 -0
  2. package/LICENSE +202 -0
  3. package/README.md +101 -0
  4. package/dist/chunk-A3UOFGL4.js +29 -0
  5. package/dist/chunk-A3UOFGL4.js.map +1 -0
  6. package/dist/chunk-D743DI5J.js +17 -0
  7. package/dist/chunk-D743DI5J.js.map +1 -0
  8. package/dist/chunk-DWQWPBBV.js +63 -0
  9. package/dist/chunk-DWQWPBBV.js.map +1 -0
  10. package/dist/chunk-LWY5TG7M.js +208 -0
  11. package/dist/chunk-LWY5TG7M.js.map +1 -0
  12. package/dist/chunk-MIRMQPUE.js +132 -0
  13. package/dist/chunk-MIRMQPUE.js.map +1 -0
  14. package/dist/chunk-PTXRAWJX.js +58 -0
  15. package/dist/chunk-PTXRAWJX.js.map +1 -0
  16. package/dist/chunk-TV4U22MY.js +176 -0
  17. package/dist/chunk-TV4U22MY.js.map +1 -0
  18. package/dist/chunk-X7PCPONB.js +380 -0
  19. package/dist/chunk-X7PCPONB.js.map +1 -0
  20. package/dist/chunk-XTY7XO5C.js +61 -0
  21. package/dist/chunk-XTY7XO5C.js.map +1 -0
  22. package/dist/index.cjs +630 -0
  23. package/dist/index.cjs.map +1 -0
  24. package/dist/index.d.cts +40 -0
  25. package/dist/index.d.ts +40 -0
  26. package/dist/index.js +6 -0
  27. package/dist/index.js.map +1 -0
  28. package/dist/loom-editor-CQ_GI4IA.d.cts +27 -0
  29. package/dist/loom-editor-D5SBQ4_F.d.ts +27 -0
  30. package/dist/plugins/nova/index.cjs +81 -0
  31. package/dist/plugins/nova/index.cjs.map +1 -0
  32. package/dist/plugins/nova/index.d.cts +14 -0
  33. package/dist/plugins/nova/index.d.ts +14 -0
  34. package/dist/plugins/nova/index.js +5 -0
  35. package/dist/plugins/nova/index.js.map +1 -0
  36. package/dist/plugins/nova/react/index.cjs +107 -0
  37. package/dist/plugins/nova/react/index.cjs.map +1 -0
  38. package/dist/plugins/nova/react/index.d.cts +17 -0
  39. package/dist/plugins/nova/react/index.d.ts +17 -0
  40. package/dist/plugins/nova/react/index.js +36 -0
  41. package/dist/plugins/nova/react/index.js.map +1 -0
  42. package/dist/plugins/prism/index.cjs +48 -0
  43. package/dist/plugins/prism/index.cjs.map +1 -0
  44. package/dist/plugins/prism/index.d.cts +18 -0
  45. package/dist/plugins/prism/index.d.ts +18 -0
  46. package/dist/plugins/prism/index.js +4 -0
  47. package/dist/plugins/prism/index.js.map +1 -0
  48. package/dist/plugins/prism/react/index.cjs +744 -0
  49. package/dist/plugins/prism/react/index.cjs.map +1 -0
  50. package/dist/plugins/prism/react/index.d.cts +12 -0
  51. package/dist/plugins/prism/react/index.d.ts +12 -0
  52. package/dist/plugins/prism/react/index.js +419 -0
  53. package/dist/plugins/prism/react/index.js.map +1 -0
  54. package/dist/plugins/vex/index.cjs +67 -0
  55. package/dist/plugins/vex/index.cjs.map +1 -0
  56. package/dist/plugins/vex/index.d.cts +25 -0
  57. package/dist/plugins/vex/index.d.ts +25 -0
  58. package/dist/plugins/vex/index.js +4 -0
  59. package/dist/plugins/vex/index.js.map +1 -0
  60. package/dist/plugins/vex/react/index.cjs +432 -0
  61. package/dist/plugins/vex/react/index.cjs.map +1 -0
  62. package/dist/plugins/vex/react/index.d.cts +13 -0
  63. package/dist/plugins/vex/react/index.d.ts +13 -0
  64. package/dist/plugins/vex/react/index.js +296 -0
  65. package/dist/plugins/vex/react/index.js.map +1 -0
  66. package/dist/react/index.cjs +1076 -0
  67. package/dist/react/index.cjs.map +1 -0
  68. package/dist/react/index.d.cts +82 -0
  69. package/dist/react/index.d.ts +82 -0
  70. package/dist/react/index.js +120 -0
  71. package/dist/react/index.js.map +1 -0
  72. package/dist/schema--OhtatTX.d.cts +10 -0
  73. package/dist/schema--OhtatTX.d.ts +10 -0
  74. package/dist/types-BonjN3CB.d.cts +144 -0
  75. package/dist/types-BonjN3CB.d.ts +144 -0
  76. package/package.json +144 -0
@@ -0,0 +1,63 @@
1
+ import { isRecord } from './chunk-TV4U22MY.js';
2
+ import { mountView } from './chunk-D743DI5J.js';
3
+ import { z } from 'zod';
4
+
5
+ var layoutSchema = (manifest) => {
6
+ const [first, ...rest] = manifest;
7
+ if (first === void 0) throw new Error("nova plugin: the manifest is empty");
8
+ const recur = z.lazy(() => layoutNode);
9
+ const branch = (component) => z.object({
10
+ component: z.literal(component.name),
11
+ props: component.props,
12
+ ...component.container === true ? { children: z.array(recur) } : {}
13
+ });
14
+ const layoutNode = z.discriminatedUnion("component", [branch(first), ...rest.map(branch)]);
15
+ return layoutNode;
16
+ };
17
+
18
+ // src/plugins/nova/data.layout.ts
19
+ var fieldFor = (key, value) => ({
20
+ component: "loom:field",
21
+ props: { label: key },
22
+ children: [{ component: typeof value === "string" ? "loom:text" : "loom:raw", model: `$.${key}` }]
23
+ });
24
+ var dataLayout = (value) => {
25
+ const data = isRecord(value) ? value : {};
26
+ return {
27
+ component: "Stack",
28
+ props: { direction: "column", gap: 12 },
29
+ children: Object.keys(data).map((key) => fieldFor(key, data[key]))
30
+ };
31
+ };
32
+
33
+ // src/plugins/nova/preview.layout.ts
34
+ var PREVIEW = "nova:preview";
35
+ var previewLayout = {
36
+ component: PREVIEW,
37
+ props: { documents: "$.documents" }
38
+ };
39
+
40
+ // src/plugins/nova/preview.action.ts
41
+ var previewAction = {
42
+ id: PREVIEW,
43
+ layout: previewLayout,
44
+ data: { documents: {} }
45
+ };
46
+
47
+ // src/plugins/nova/index.ts
48
+ var novaPlugin = (config) => ({
49
+ name: "nova",
50
+ documents: {
51
+ layout: layoutSchema(config.manifest),
52
+ // `data` is freeform (its shape follows the layout's bindings), so it has no
53
+ // schema. The plugin builds its editing layout from the data's keys instead.
54
+ data: dataLayout
55
+ },
56
+ // The preview is a Nova concept, not a Loom one, so the plugin contributes it:
57
+ // a view canvas rendering the preview component bound to the live documents.
58
+ mount: (editor) => mountView(editor, previewAction, (e) => ({ documents: e.documents }))
59
+ });
60
+
61
+ export { PREVIEW, layoutSchema, novaPlugin };
62
+ //# sourceMappingURL=chunk-DWQWPBBV.js.map
63
+ //# sourceMappingURL=chunk-DWQWPBBV.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/plugins/nova/schema.ts","../src/plugins/nova/data.layout.ts","../src/plugins/nova/preview.layout.ts","../src/plugins/nova/preview.action.ts","../src/plugins/nova/index.ts"],"names":[],"mappings":";;;;AAWO,IAAM,YAAA,GAAe,CAAC,QAAA,KAAqD;AAChF,EAAA,MAAM,CAAC,KAAA,EAAO,GAAG,IAAI,CAAA,GAAI,QAAA;AACzB,EAAA,IAAI,KAAA,KAAU,MAAA,EAAW,MAAM,IAAI,MAAM,oCAAoC,CAAA;AAE7E,EAAA,MAAM,KAAA,GAAiB,CAAA,CAAE,IAAA,CAAK,MAAM,UAAU,CAAA;AAC9C,EAAA,MAAM,MAAA,GAAS,CAAC,SAAA,KACd,CAAA,CAAE,MAAA,CAAO;AAAA,IACP,SAAA,EAAW,CAAA,CAAE,OAAA,CAAQ,SAAA,CAAU,IAAI,CAAA;AAAA,IACnC,OAAO,SAAA,CAAU,KAAA;AAAA,IACjB,GAAI,SAAA,CAAU,SAAA,KAAc,IAAA,GAAO,EAAE,QAAA,EAAU,CAAA,CAAE,KAAA,CAAM,KAAK,CAAA,EAAE,GAAI;AAAC,GACpE,CAAA;AAEH,EAAA,MAAM,UAAA,GAAa,CAAA,CAAE,kBAAA,CAAmB,WAAA,EAAa,CAAC,MAAA,CAAO,KAAK,CAAA,EAAG,GAAG,IAAA,CAAK,GAAA,CAAI,MAAM,CAAC,CAAC,CAAA;AACzF,EAAA,OAAO,UAAA;AACT;;;AClBA,IAAM,QAAA,GAAW,CAAC,GAAA,EAAa,KAAA,MAAgC;AAAA,EAC7D,SAAA,EAAW,YAAA;AAAA,EACX,KAAA,EAAO,EAAE,KAAA,EAAO,GAAA,EAAI;AAAA,EACpB,QAAA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DWQWPBBV.js","sourcesContent":["import { z, type ZodType } from 'zod';\n\n// The framework-free shape of one component in the manifest: its name, the schema\n// for its props, and whether it nests children. The render function (React, Vue,\n// …) lives in the per-framework surface, not here.\nexport type NovaComponentShape = { name: string; props: ZodType; container?: boolean };\n\n// Build the layout document's schema. Each component becomes a branch\n// discriminated by its `component` literal, carrying its prop schema; containers\n// recurse through `children`. This is the shape of a Nova ComponentNode, so the\n// edited `layout` document is itself a layout.\nexport const layoutSchema = (manifest: readonly NovaComponentShape[]): ZodType => {\n const [first, ...rest] = manifest;\n if (first === undefined) throw new Error('nova plugin: the manifest is empty');\n\n const recur: ZodType = z.lazy(() => layoutNode);\n const branch = (component: NovaComponentShape) =>\n z.object({\n component: z.literal(component.name),\n props: component.props,\n ...(component.container === true ? { children: z.array(recur) } : {}),\n });\n\n const layoutNode = z.discriminatedUnion('component', [branch(first), ...rest.map(branch)]);\n return layoutNode;\n};\n","import type { LayoutNode } from '@niscorp/nova';\nimport { isRecord } from '@compile/parse';\n\n// The data document's editing layout — the nova plugin builds it from the data's\n// own keys (the freeform key→value map the layout binds to). One field per key,\n// each control bound to `$.<key>`, a writable path (the bare root `$` is not). A\n// string value edits as a text input; anything else as a JSON editor.\nconst fieldFor = (key: string, value: unknown): LayoutNode => ({\n component: 'loom:field',\n props: { label: key },\n children: [{ component: typeof value === 'string' ? 'loom:text' : 'loom:raw', model: `$.${key}` }],\n});\n\nexport const dataLayout = (value: unknown): LayoutNode => {\n const data = isRecord(value) ? value : {};\n return {\n component: 'Stack',\n props: { direction: 'column', gap: 12 },\n children: Object.keys(data).map((key) => fieldFor(key, data[key])),\n };\n};\n","import type { LayoutNode } from '@niscorp/nova';\n\n// The preview view's id — one string for one view: the name its component\n// registers under, the id of its action, and the id of its canvas. The framework\n// surface registers the component under it; the core's mount references it.\nexport const PREVIEW = 'nova:preview';\n\n// The preview layout: one component bound to the editor's live documents (the\n// layout + its data). The component renders the layout against the data with Nova.\nexport const previewLayout: LayoutNode = {\n component: PREVIEW,\n props: { documents: '$.documents' },\n};\n","import type { ActionDefinition } from '@niscorp/nova';\nimport { previewLayout, PREVIEW } from './preview.layout.js';\n\n// The preview action: the preview layout over a `documents` data slot the mount\n// keeps in sync. Canvas id equals the action id (PREVIEW).\nexport const previewAction: ActionDefinition = {\n id: PREVIEW,\n layout: previewLayout,\n data: { documents: {} },\n};\n","import { mountView } from '@editor/view';\nimport type { LoomPlugin } from '@editor/types';\nimport { layoutSchema, type NovaComponentShape } from './schema.js';\nimport { dataLayout } from './data.layout.js';\nimport { previewAction } from './preview.action.js';\n\n// @niscorp/loom/plugins/nova — the Nova plugin (framework-free).\n//\n// A Nova layout has two documents: the `layout` (a component tree, its schema\n// derived from the component manifest) and the `data` its bindings (`$.x`)\n// resolve against. The plugin declares both and contributes the preview canvas;\n// the per-framework surface (./react) supplies the preview component.\n\nexport { PREVIEW } from './preview.layout.js';\nexport { layoutSchema, type NovaComponentShape } from './schema.js';\n\nexport type NovaPluginConfig = { manifest: readonly NovaComponentShape[] };\n\nexport const novaPlugin = (config: NovaPluginConfig): LoomPlugin => ({\n name: 'nova',\n documents: {\n layout: layoutSchema(config.manifest),\n // `data` is freeform (its shape follows the layout's bindings), so it has no\n // schema. The plugin builds its editing layout from the data's keys instead.\n data: dataLayout,\n },\n // The preview is a Nova concept, not a Loom one, so the plugin contributes it:\n // a view canvas rendering the preview component bound to the live documents.\n mount: (editor) => mountView(editor, previewAction, (e) => ({ documents: e.documents })),\n});\n"]}
@@ -0,0 +1,208 @@
1
+ import { Roles, LOOM_COLUMN } from './chunk-PTXRAWJX.js';
2
+ import { inputStyle, useModelWrite, JsonEditor, decodeLiteral, matches, ActionMenu, MenuItem, SubMenu } from './chunk-MIRMQPUE.js';
3
+ import { isRecord } from './chunk-TV4U22MY.js';
4
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
5
+ import { createContext, useContext } from 'react';
6
+ import { createComponentRegistry } from '@niscorp/nova';
7
+
8
+ var groupStyle = { display: "flex", flexDirection: "column" };
9
+ var titleStyle = { fontSize: 15, fontWeight: 700, marginBottom: 8, color: "#111827" };
10
+ var fieldStyle = { display: "flex", flexDirection: "column", gap: 4, marginBottom: 12 };
11
+ var labelStyle = { fontSize: 13, fontWeight: 600, color: "#374151" };
12
+ var hintStyle = { fontSize: 12, color: "#6b7280" };
13
+ var LoomGroup = ({ title, children }) => /* @__PURE__ */ jsxs("div", { style: groupStyle, children: [
14
+ title !== void 0 ? /* @__PURE__ */ jsx("div", { style: titleStyle, children: title }) : null,
15
+ children
16
+ ] });
17
+ var LoomField = ({ label, description, required, error, children }) => /* @__PURE__ */ jsxs("div", { style: fieldStyle, children: [
18
+ /* @__PURE__ */ jsxs("span", { style: labelStyle, children: [
19
+ label,
20
+ required ? /* @__PURE__ */ jsx("span", { style: { color: "#dc2626" }, children: " *" }) : null
21
+ ] }),
22
+ description !== void 0 ? /* @__PURE__ */ jsx("span", { style: hintStyle, children: description }) : null,
23
+ children,
24
+ typeof error === "string" ? /* @__PURE__ */ jsx("span", { style: { ...hintStyle, color: "#dc2626" }, children: error }) : null
25
+ ] });
26
+ var HTML_INPUT_TYPE = { email: "email", uri: "url", date: "date" };
27
+ var LoomText = ({
28
+ value,
29
+ format,
30
+ placeholder,
31
+ novaModel
32
+ }) => {
33
+ const set = useModelWrite(novaModel);
34
+ return /* @__PURE__ */ jsx(
35
+ "input",
36
+ {
37
+ type: HTML_INPUT_TYPE[format ?? ""] ?? "text",
38
+ placeholder,
39
+ value: String(value ?? ""),
40
+ onChange: (event) => set(event.target.value),
41
+ style: inputStyle
42
+ }
43
+ );
44
+ };
45
+ var LoomNumber = ({ value, novaModel }) => {
46
+ const set = useModelWrite(novaModel);
47
+ return /* @__PURE__ */ jsx(
48
+ "input",
49
+ {
50
+ type: "number",
51
+ value: Number.isFinite(value) ? value : "",
52
+ onChange: (event) => {
53
+ const raw = event.target.value;
54
+ set(raw ? Number(raw) : null);
55
+ },
56
+ style: inputStyle
57
+ }
58
+ );
59
+ };
60
+ var LoomCheckbox = ({ value, novaModel }) => {
61
+ const set = useModelWrite(novaModel);
62
+ return /* @__PURE__ */ jsx(
63
+ "input",
64
+ {
65
+ type: "checkbox",
66
+ checked: Boolean(value),
67
+ onChange: (event) => set(event.target.checked),
68
+ style: { width: 16, height: 16 }
69
+ }
70
+ );
71
+ };
72
+ var LoomSelect = ({ value, options, novaModel }) => {
73
+ const set = useModelWrite(novaModel);
74
+ return /* @__PURE__ */ jsx("select", { value: String(value ?? ""), onChange: (event) => set(event.target.value), style: inputStyle, children: (options ?? []).map((option) => /* @__PURE__ */ jsx("option", { value: String(option.value), children: option.label }, String(option.value))) });
75
+ };
76
+ var LoomRaw = ({ value, novaModel }) => {
77
+ const set = useModelWrite(novaModel);
78
+ return /* @__PURE__ */ jsx(JsonEditor, { value, onChange: set });
79
+ };
80
+ var variantStyle = { display: "flex", flexDirection: "column", gap: 12 };
81
+ var ActiveBranch = createContext(0);
82
+ var LoomBranch = ({ index, children }) => useContext(ActiveBranch) === index ? /* @__PURE__ */ jsx(Fragment, { children }) : null;
83
+ var LoomVariant = ({
84
+ value,
85
+ branches,
86
+ children,
87
+ novaModel
88
+ }) => {
89
+ const set = useModelWrite(novaModel);
90
+ const options = decodeLiteral(branches) ?? [];
91
+ const matched = options.findIndex((branch) => matches(value, branch.pattern));
92
+ const fallback = options.findIndex((branch) => branch.pattern.kind === "fallback");
93
+ const active = matched >= 0 ? matched : Math.max(0, fallback);
94
+ const switchTo = (chosen) => {
95
+ const activeKey = options[active]?.childrenKey;
96
+ const oldChildren = activeKey !== void 0 && isRecord(value) ? value[activeKey] : void 0;
97
+ if (chosen.childrenKey !== void 0 && Array.isArray(oldChildren)) {
98
+ set({ ...isRecord(chosen.defaults) ? chosen.defaults : {}, [chosen.childrenKey]: oldChildren });
99
+ return;
100
+ }
101
+ if (Array.isArray(oldChildren) && oldChildren.length > 0 && !window.confirm("This type has no children. Discard them?")) return;
102
+ set(chosen.defaults);
103
+ };
104
+ return /* @__PURE__ */ jsxs("div", { style: variantStyle, children: [
105
+ /* @__PURE__ */ jsx(
106
+ "select",
107
+ {
108
+ value: active,
109
+ onChange: (event) => {
110
+ const chosen = options[Number(event.target.value)];
111
+ if (chosen !== void 0) switchTo(chosen);
112
+ },
113
+ style: inputStyle,
114
+ children: options.map((branch, index) => /* @__PURE__ */ jsx("option", { value: index, children: branch.label }, index))
115
+ }
116
+ ),
117
+ /* @__PURE__ */ jsx(ActiveBranch.Provider, { value: active, children })
118
+ ] });
119
+ };
120
+ var arrayStyle = { display: "flex", flexDirection: "column", gap: 8, padding: 12, border: "1px dashed #d1d5db", borderRadius: 6 };
121
+ var arrayItemStyle = { display: "flex", gap: 6, alignItems: "flex-start" };
122
+ var itemEditorStyle = { flex: 1, minWidth: 0 };
123
+ var addButtonStyle = { ...inputStyle, alignSelf: "flex-start", cursor: "pointer", background: "#f3f4f6" };
124
+ var LoomArray = ({ children }) => /* @__PURE__ */ jsx("div", { style: arrayStyle, children });
125
+ var LoomArrayItem = ({ children }) => /* @__PURE__ */ jsx("div", { style: arrayItemStyle, children });
126
+ var LoomBox = ({ children }) => /* @__PURE__ */ jsx("div", { style: itemEditorStyle, children });
127
+ var LoomColumn = ({ grow, min, children }) => {
128
+ const style = { flexGrow: grow ?? 1, flexShrink: 1, flexBasis: min ?? 320, minWidth: min ?? 320 };
129
+ return /* @__PURE__ */ jsx("div", { style, children });
130
+ };
131
+ var LoomAppend = ({
132
+ label,
133
+ value,
134
+ child,
135
+ novaModel
136
+ }) => {
137
+ const set = useModelWrite(novaModel);
138
+ const onClick = () => {
139
+ const current = Array.isArray(value) ? value : [];
140
+ set([...current, decodeLiteral(child)]);
141
+ };
142
+ return /* @__PURE__ */ jsx("button", { type: "button", onClick, style: addButtonStyle, children: label ?? "Add" });
143
+ };
144
+ var reorder = (list, from, to) => {
145
+ if (to < 0 || to >= list.length) return [...list];
146
+ const next = [...list];
147
+ const [moved] = next.splice(from, 1);
148
+ next.splice(to, 0, moved);
149
+ return next;
150
+ };
151
+ var LoomRowMenu = ({ index, containers, value, novaModel }) => {
152
+ const set = useModelWrite(novaModel);
153
+ const i = Number(index);
154
+ const list = Array.isArray(value) ? value : void 0;
155
+ if (list === void 0 || !Number.isInteger(i)) return null;
156
+ const element = list[i];
157
+ const targets = decodeLiteral(containers) ?? [];
158
+ const unwrapTarget = targets.find((container) => matches(element, container.pattern));
159
+ const wrapInto = (container) => [
160
+ ...list.slice(0, i),
161
+ { ...isRecord(container.defaults) ? container.defaults : {}, [container.key]: [element] },
162
+ ...list.slice(i + 1)
163
+ ];
164
+ return /* @__PURE__ */ jsxs(ActionMenu, { children: [
165
+ /* @__PURE__ */ jsx(MenuItem, { label: "\u2191 Move up", onSelect: () => set(reorder(list, i, i - 1)), disabled: i === 0 }),
166
+ /* @__PURE__ */ jsx(MenuItem, { label: "\u2193 Move down", onSelect: () => set(reorder(list, i, i + 1)), disabled: i === list.length - 1 }),
167
+ targets.length > 0 ? /* @__PURE__ */ jsx(SubMenu, { label: "\u29C9 Wrap in", children: targets.map((container, k) => /* @__PURE__ */ jsx(MenuItem, { label: container.label, onSelect: () => set(wrapInto(container)) }, k)) }) : null,
168
+ unwrapTarget !== void 0 ? /* @__PURE__ */ jsx(
169
+ MenuItem,
170
+ {
171
+ label: "\u21F2 Unwrap",
172
+ onSelect: () => {
173
+ const children = isRecord(element) && Array.isArray(element[unwrapTarget.key]) ? element[unwrapTarget.key] : [];
174
+ set([...list.slice(0, i), ...children, ...list.slice(i + 1)]);
175
+ }
176
+ }
177
+ ) : null,
178
+ /* @__PURE__ */ jsx(MenuItem, { label: "\u2715 Remove", onSelect: () => set(list.filter((_, j) => j !== i)) })
179
+ ] });
180
+ };
181
+ var loomComponents = {
182
+ [Roles.group]: LoomGroup,
183
+ [Roles.field]: LoomField,
184
+ [Roles.box]: LoomBox,
185
+ [Roles.array]: LoomArray,
186
+ [Roles.arrayItem]: LoomArrayItem,
187
+ [Roles.variant]: LoomVariant,
188
+ [Roles.branch]: LoomBranch,
189
+ [Roles.append]: LoomAppend,
190
+ [Roles.rowMenu]: LoomRowMenu,
191
+ [Roles.text]: LoomText,
192
+ [Roles.number]: LoomNumber,
193
+ [Roles.checkbox]: LoomCheckbox,
194
+ [Roles.select]: LoomSelect,
195
+ [Roles.raw]: LoomRaw,
196
+ [LOOM_COLUMN]: LoomColumn
197
+ };
198
+ var createLoomRegistry = () => {
199
+ const registry = createComponentRegistry();
200
+ registry.registerAll(loomComponents);
201
+ return registry;
202
+ };
203
+ var LoomDocumentContext = createContext(void 0);
204
+ var useLoomDocument = () => useContext(LoomDocumentContext);
205
+
206
+ export { LoomAppend, LoomArray, LoomArrayItem, LoomBox, LoomBranch, LoomCheckbox, LoomColumn, LoomDocumentContext, LoomField, LoomGroup, LoomNumber, LoomRaw, LoomRowMenu, LoomSelect, LoomText, LoomVariant, createLoomRegistry, loomComponents, useLoomDocument };
207
+ //# sourceMappingURL=chunk-LWY5TG7M.js.map
208
+ //# sourceMappingURL=chunk-LWY5TG7M.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/react/kit/fields.tsx","../src/react/kit/controls.tsx","../src/react/kit/variant.tsx","../src/react/kit/array.tsx","../src/react/kit/index.ts","../src/react/hooks/document.ts"],"names":["jsx","jsxs","createContext","useContext"],"mappings":";;;;;;;AAMA,IAAM,UAAA,GAA4B,EAAE,OAAA,EAAS,MAAA,EAAQ,eAAe,QAAA,EAAS;AAC7E,IAAM,UAAA,GAA4B,EAAE,QAAA,EAAU,EAAA,EAAI,YAAY,GAAA,EAAK,YAAA,EAAc,CAAA,EAAG,KAAA,EAAO,SAAA,EAAU;AACrG,IAAM,UAAA,GAA4B,EAAE,OAAA,EAAS,MAAA,EAAQ,eAAe,QAAA,EAAU,GAAA,EAAK,CAAA,EAAG,YAAA,EAAc,EAAA,EAAG;AACvG,IAAM,aAA4B,EAAE,QAAA,EAAU,IAAI,UAAA,EAAY,GAAA,EAAK,OAAO,SAAA,EAAU;AACpF,IAAM,SAA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","sourcesContent":["import type { CSSProperties } from 'react';\nimport type { NovaComponent } from '@niscorp/nova/adapters/react';\n\n// The layout + field shells: the group heading and the per-field wrapper\n// (label / description / required marker / error) around one control.\n\nconst groupStyle: CSSProperties = { display: 'flex', flexDirection: 'column' };\nconst titleStyle: CSSProperties = { fontSize: 15, fontWeight: 700, marginBottom: 8, color: '#111827' };\nconst fieldStyle: CSSProperties = { display: 'flex', flexDirection: 'column', gap: 4, marginBottom: 12 };\nconst labelStyle: CSSProperties = { fontSize: 13, fontWeight: 600, color: '#374151' };\nconst hintStyle: CSSProperties = { fontSize: 12, color: '#6b7280' };\n\nexport const LoomGroup: NovaComponent<{ title?: string }> = ({ title, children }) => (\n <div style={groupStyle}>\n {title !== undefined ? <div style={titleStyle}>{title}</div> : null}\n {children}\n </div>\n);\n\nexport const LoomField: NovaComponent<{\n label?: string;\n description?: string;\n required?: boolean;\n // Resolved from the error channel: a string at a leaf path, the error\n // sub-tree at a container path (rendered only when it's a string).\n error?: unknown;\n // A plain <div>, not a <label>: a field can wrap composite content (an\n // object group, an array with its own buttons), and a <label> would\n // capture every control inside it as its target.\n}> = ({ label, description, required, error, children }) => (\n <div style={fieldStyle}>\n <span style={labelStyle}>\n {label}\n {required ? <span style={{ color: '#dc2626' }}> *</span> : null}\n </span>\n {description !== undefined ? <span style={hintStyle}>{description}</span> : null}\n {children}\n {typeof error === 'string' ? <span style={{ ...hintStyle, color: '#dc2626' }}>{error}</span> : null}\n </div>\n);\n","import type { NovaComponent } from '@niscorp/nova/adapters/react';\nimport { useModelWrite } from '../hooks/model.js';\nimport { inputStyle } from './shared.js';\nimport { JsonEditor } from './json-editor.js';\n\n// The leaf controls: each reads its value from the auto-bound `value` prop and\n// writes back through `useModelWrite`.\n\nconst HTML_INPUT_TYPE: Record<string, string> = { email: 'email', uri: 'url', date: 'date' };\n\nexport const LoomText: NovaComponent<{ value?: unknown; format?: string; placeholder?: string }> = ({\n value,\n format,\n placeholder,\n novaModel,\n}) => {\n const set = useModelWrite(novaModel);\n return (\n <input\n type={HTML_INPUT_TYPE[format ?? ''] ?? 'text'}\n placeholder={placeholder}\n value={String(value ?? '')}\n onChange={(event) => set(event.target.value)}\n style={inputStyle}\n />\n );\n};\n\nexport const LoomNumber: NovaComponent<{ value?: unknown }> = ({ value, novaModel }) => {\n const set = useModelWrite(novaModel);\n return (\n <input\n type=\"number\"\n value={Number.isFinite(value) ? (value as number) : ''}\n onChange={(event) => {\n const raw = event.target.value;\n set(raw ? Number(raw) : null);\n }}\n style={inputStyle}\n />\n );\n};\n\nexport const LoomCheckbox: NovaComponent<{ value?: unknown }> = ({ value, novaModel }) => {\n const set = useModelWrite(novaModel);\n return (\n <input\n type=\"checkbox\"\n checked={Boolean(value)}\n onChange={(event) => set(event.target.checked)}\n style={{ width: 16, height: 16 }}\n />\n );\n};\n\nexport const LoomSelect: NovaComponent<{\n value?: unknown;\n options?: { value: unknown; label: string }[];\n}> = ({ value, options, novaModel }) => {\n const set = useModelWrite(novaModel);\n return (\n <select value={String(value ?? '')} onChange={(event) => set(event.target.value)} style={inputStyle}>\n {(options ?? []).map((option) => (\n <option key={String(option.value)} value={String(option.value)}>\n {option.label}\n </option>\n ))}\n </select>\n );\n};\n\n// The raw role: JsonEditor wired to the model.\nexport const LoomRaw: NovaComponent<{ value?: unknown }> = ({ value, novaModel }) => {\n const set = useModelWrite(novaModel);\n return <JsonEditor value={value} onChange={set} />;\n};\n","import { createContext, useContext, type CSSProperties } from 'react';\nimport type { NovaComponent } from '@niscorp/nova/adapters/react';\nimport { isRecord } from '@compile/parse';\nimport type { Pattern } from '@compile/types';\nimport { useModelWrite } from '../hooks/model.js';\nimport { decodeLiteral, inputStyle, matches } from './shared.js';\n\n// The union editor and its branch wrappers.\n\nconst variantStyle: CSSProperties = { display: 'flex', flexDirection: 'column', gap: 12 };\n\ntype Branch = { label: string; pattern: Pattern; defaults: unknown; childrenKey?: string };\n\n// The active branch index, shared from the variant down to its branch wrappers.\nconst ActiveBranch = createContext(0);\n\n// One branch of a variant — renders its editor only when it is the active one.\nexport const LoomBranch: NovaComponent<{ index?: number }> = ({ index, children }) =>\n useContext(ActiveBranch) === index ? <>{children}</> : null;\n\n// A union editor: a type chooser plus the active branch. It matches the current\n// value to a branch in JS, tells the branches which is active (via context), and\n// each shows or hides itself; on change it writes the chosen branch's default,\n// reshaping the value. Tagged, structural, and mixed unions are the same code —\n// only the pattern differs.\nexport const LoomVariant: NovaComponent<{ value?: unknown; branches?: unknown }> = ({\n value,\n branches,\n children,\n novaModel,\n}) => {\n const set = useModelWrite(novaModel);\n const options = decodeLiteral<Branch[]>(branches) ?? [];\n // The first branch whose pattern matches the value; failing that, the open\n // `fallback` branch (which never matches positively), else the first branch.\n const matched = options.findIndex((branch) => matches(value, branch.pattern));\n const fallback = options.findIndex((branch) => branch.pattern.kind === 'fallback');\n const active = matched >= 0 ? matched : Math.max(0, fallback);\n // Switching between two container variants carries the children over; switching\n // to one without a child-list drops them (after a confirm).\n const switchTo = (chosen: Branch): void => {\n const activeKey = options[active]?.childrenKey;\n const oldChildren = activeKey !== undefined && isRecord(value) ? value[activeKey] : undefined;\n if (chosen.childrenKey !== undefined && Array.isArray(oldChildren)) {\n set({ ...(isRecord(chosen.defaults) ? chosen.defaults : {}), [chosen.childrenKey]: oldChildren });\n return;\n }\n if (Array.isArray(oldChildren) && oldChildren.length > 0 && !window.confirm('This type has no children. Discard them?')) return;\n set(chosen.defaults);\n };\n return (\n <div style={variantStyle}>\n <select\n value={active}\n onChange={(event) => {\n const chosen = options[Number(event.target.value)];\n if (chosen !== undefined) switchTo(chosen);\n }}\n style={inputStyle}\n >\n {options.map((branch, index) => (\n <option key={index} value={index}>\n {branch.label}\n </option>\n ))}\n </select>\n <ActiveBranch.Provider value={active}>{children}</ActiveBranch.Provider>\n </div>\n );\n};\n","import type { CSSProperties } from 'react';\nimport type { NovaComponent } from '@niscorp/nova/adapters/react';\nimport { isRecord } from '@compile/parse';\nimport type { Pattern } from '@compile/types';\nimport { LOOM_COLUMN } from '@editor/default.layout';\nimport { useModelWrite } from '../hooks/model.js';\nimport { decodeLiteral, inputStyle, matches } from './shared.js';\nimport { ActionMenu, MenuItem, SubMenu } from './menu.js';\n\n// The array container, its item cells, the editor's canvas column, and the\n// list-mutating actions (append + the per-row menu).\n\nconst arrayStyle: CSSProperties = { display: 'flex', flexDirection: 'column', gap: 8, padding: 12, border: '1px dashed #d1d5db', borderRadius: 6 };\nconst arrayItemStyle: CSSProperties = { display: 'flex', gap: 6, alignItems: 'flex-start' };\nconst itemEditorStyle: CSSProperties = { flex: 1, minWidth: 0 };\nconst addButtonStyle: CSSProperties = { ...inputStyle, alignSelf: 'flex-start', cursor: 'pointer', background: '#f3f4f6' };\n\n// Holds the rendered items (the compiled loop) plus the add button.\nexport const LoomArray: NovaComponent = ({ children }) => <div style={arrayStyle}>{children}</div>;\n\n// One item's row, laid out left-to-right: the editor cell (a `box`, which grows)\n// then the actions menu. The compiler wraps the editor in the box, so this is a\n// plain flex row — no splitting of children (Nova hands them as one tree).\nexport const LoomArrayItem: NovaComponent = ({ children }) => <div style={arrayItemStyle}>{children}</div>;\n\n// A flexible cell that grows to fill its row — the array item's editor lives in one.\nexport const LoomBox: NovaComponent = ({ children }) => <div style={itemEditorStyle}>{children}</div>;\n\n// A sized column for the editor's canvasLayout: grows to share the row but won't\n// shrink below `min`, so columns don't squish. The one layout primitive no Nova\n// builtin provides (Stack/Box can't size a child).\nexport const LoomColumn: NovaComponent<{ grow?: number; min?: number }> = ({ grow, min, children }) => {\n const style: CSSProperties = { flexGrow: grow ?? 1, flexShrink: 1, flexBasis: min ?? 320, minWidth: min ?? 320 };\n return <div style={style}>{children}</div>;\n};\n\n// Grows a recursive list: bound to the list as its model, it appends a default\n// `child` and writes the new array back through `ui:model` — the same pipeline a\n// control edit uses, so the resolved path is correct at any depth. This is how a\n// node deeper in a tree gains a child without a static push target.\nexport const LoomAppend: NovaComponent<{ label?: string; value?: unknown; child?: unknown }> = ({\n label,\n value,\n child,\n novaModel,\n}) => {\n const set = useModelWrite(novaModel);\n const onClick = (): void => {\n const current = Array.isArray(value) ? value : [];\n set([...current, decodeLiteral(child)]);\n };\n return (\n <button type=\"button\" onClick={onClick} style={addButtonStyle}>\n {label ?? 'Add'}\n </button>\n );\n};\n\n// Move `from` to `to`, clamped — out-of-range (past either end) is a no-op.\nconst reorder = (list: readonly unknown[], from: number, to: number): unknown[] => {\n if (to < 0 || to >= list.length) return [...list];\n const next = [...list];\n const [moved] = next.splice(from, 1);\n next.splice(to, 0, moved);\n return next;\n};\n\n// A container variant the menu can wrap an element into, or recognize for\n// unwrap. `key` holds the child-list. Mirror of the compiler's `Container`.\ntype RowContainer = { label: string; pattern: Pattern; defaults: unknown; key: string };\n\n// The per-row actions menu. Bound to the loop's `$items` (the whole list), so\n// `value` is the list and a write replaces it; `index` is this row. Move and\n// remove always; wrap (into each container variant) and unwrap (when this row is\n// a container) appear only when `containers` is non-empty. All are array writes.\nexport const LoomRowMenu: NovaComponent<{\n index?: unknown;\n containers?: unknown;\n value?: unknown;\n}> = ({ index, containers, value, novaModel }) => {\n const set = useModelWrite(novaModel);\n const i = Number(index);\n const list = Array.isArray(value) ? value : undefined;\n if (list === undefined || !Number.isInteger(i)) return null;\n\n const element = list[i];\n const targets = decodeLiteral<RowContainer[]>(containers) ?? [];\n const unwrapTarget = targets.find((container) => matches(element, container.pattern));\n const wrapInto = (container: RowContainer): unknown[] => [\n ...list.slice(0, i),\n { ...(isRecord(container.defaults) ? container.defaults : {}), [container.key]: [element] },\n ...list.slice(i + 1),\n ];\n\n return (\n <ActionMenu>\n <MenuItem label=\"↑ Move up\" onSelect={() => set(reorder(list, i, i - 1))} disabled={i === 0} />\n <MenuItem label=\"↓ Move down\" onSelect={() => set(reorder(list, i, i + 1))} disabled={i === list.length - 1} />\n {targets.length > 0 ? (\n <SubMenu label=\"⧉ Wrap in\">\n {targets.map((container, k) => (\n <MenuItem key={k} label={container.label} onSelect={() => set(wrapInto(container))} />\n ))}\n </SubMenu>\n ) : null}\n {unwrapTarget !== undefined ? (\n <MenuItem\n label=\"⇲ Unwrap\"\n onSelect={() => {\n const children = isRecord(element) && Array.isArray(element[unwrapTarget.key]) ? (element[unwrapTarget.key] as unknown[]) : [];\n set([...list.slice(0, i), ...children, ...list.slice(i + 1)]);\n }}\n />\n ) : null}\n <MenuItem label=\"✕ Remove\" onSelect={() => set(list.filter((_, j) => j !== i))} />\n </ActionMenu>\n );\n};\n\nexport { LOOM_COLUMN };\n","import { createComponentRegistry, type ComponentRegistry } from '@niscorp/nova';\nimport type { NovaComponent } from '@niscorp/nova/adapters/react';\nimport { Roles } from '@compile/roles';\nimport { LOOM_COLUMN } from '@editor/default.layout';\nimport { LoomGroup, LoomField } from './fields.js';\nimport { LoomText, LoomNumber, LoomCheckbox, LoomSelect, LoomRaw } from './controls.js';\nimport { LoomBranch, LoomVariant } from './variant.js';\nimport { LoomArray, LoomArrayItem, LoomBox, LoomColumn, LoomAppend, LoomRowMenu } from './array.js';\n\n// The default Loom widget kit: one React component per role the compiler emits,\n// plus the editor's `loom:column`. Swapping the kit = registering different\n// components under the same role names.\n\nexport { LoomGroup, LoomField } from './fields.js';\nexport { LoomText, LoomNumber, LoomCheckbox, LoomSelect, LoomRaw } from './controls.js';\nexport { LoomBranch, LoomVariant } from './variant.js';\nexport { LoomArray, LoomArrayItem, LoomBox, LoomColumn, LoomAppend, LoomRowMenu } from './array.js';\nexport { JsonEditor } from './json-editor.js';\nexport { ActionMenu, MenuItem, SubMenu } from './menu.js';\n\n// Role → component. Keyed by the `Roles` constants, so the kit and the compiler\n// can never disagree on a name.\nexport const loomComponents: Record<string, NovaComponent> = {\n [Roles.group]: LoomGroup,\n [Roles.field]: LoomField,\n [Roles.box]: LoomBox,\n [Roles.array]: LoomArray,\n [Roles.arrayItem]: LoomArrayItem,\n [Roles.variant]: LoomVariant,\n [Roles.branch]: LoomBranch,\n [Roles.append]: LoomAppend,\n [Roles.rowMenu]: LoomRowMenu,\n [Roles.text]: LoomText,\n [Roles.number]: LoomNumber,\n [Roles.checkbox]: LoomCheckbox,\n [Roles.select]: LoomSelect,\n [Roles.raw]: LoomRaw,\n [LOOM_COLUMN]: LoomColumn,\n};\n\nexport const createLoomRegistry = (): ComponentRegistry<NovaComponent> => {\n const registry = createComponentRegistry<NovaComponent>();\n registry.registerAll(loomComponents);\n return registry;\n};\n","import { createContext, useContext } from 'react';\n\n// The document the editor is currently editing, available to widgets. A widget\n// gets its own field value as a prop; useLoomDocument gives it the whole\n// document, for widgets that need other fields (e.g. a Vex field-path picker\n// reading the query's `from`).\n\nexport type LoomDocument = Record<string, unknown> | undefined;\n\nexport const LoomDocumentContext = createContext<LoomDocument>(undefined);\n\nexport const useLoomDocument = (): LoomDocument => useContext(LoomDocumentContext);\n"]}
@@ -0,0 +1,132 @@
1
+ import { isRecord } from './chunk-TV4U22MY.js';
2
+ import { useNovaDispatch } from '@niscorp/nova/adapters/react';
3
+ import { createContext, useState, useEffect, useContext } from 'react';
4
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
5
+
6
+ var useModelWrite = (model) => {
7
+ const dispatch = useNovaDispatch();
8
+ return (value) => {
9
+ if (model !== void 0) dispatch({ type: "ui:model", ref: model.ref, payload: value });
10
+ };
11
+ };
12
+
13
+ // src/react/kit/shared.ts
14
+ var inputStyle = { padding: "6px 10px", border: "1px solid #d1d5db", borderRadius: 6, fontSize: 14, width: "100%", boxSizing: "border-box" };
15
+ var jsType = (value) => Array.isArray(value) ? "array" : value === null ? "null" : typeof value;
16
+ var decodeLiteral = (value) => typeof value === "string" ? JSON.parse(value) : value;
17
+ var matches = (value, pattern) => {
18
+ if (pattern.kind === "tag") return isRecord(value) && value[pattern.key] === pattern.value;
19
+ if (pattern.kind === "key") return isRecord(value) && pattern.key in value;
20
+ if (pattern.kind === "type") return jsType(value) === pattern.type;
21
+ return false;
22
+ };
23
+ var rawStyle = {
24
+ ...inputStyle,
25
+ margin: 0,
26
+ fontFamily: "ui-monospace, SFMono-Regular, Menlo, monospace",
27
+ fontSize: 13,
28
+ minHeight: 64,
29
+ resize: "vertical",
30
+ width: "100%",
31
+ boxSizing: "border-box"
32
+ };
33
+ var showJson = (value) => JSON.stringify(value ?? null, null, 2);
34
+ var JsonEditor = ({ value, onChange }) => {
35
+ const [text, setText] = useState(() => showJson(value));
36
+ const [valid, setValid] = useState(true);
37
+ const serialized = JSON.stringify(value ?? null);
38
+ useEffect(() => {
39
+ let mine;
40
+ try {
41
+ mine = JSON.parse(text);
42
+ } catch {
43
+ setText(showJson(value));
44
+ setValid(true);
45
+ return;
46
+ }
47
+ if (JSON.stringify(mine ?? null) !== serialized) {
48
+ setText(showJson(value));
49
+ setValid(true);
50
+ }
51
+ }, [serialized]);
52
+ return /* @__PURE__ */ jsx(
53
+ "textarea",
54
+ {
55
+ value: text,
56
+ spellCheck: false,
57
+ onChange: (event) => {
58
+ const next = event.target.value;
59
+ setText(next);
60
+ try {
61
+ const parsed = JSON.parse(next);
62
+ setValid(true);
63
+ onChange(parsed);
64
+ } catch {
65
+ setValid(false);
66
+ }
67
+ },
68
+ style: valid ? rawStyle : { ...rawStyle, borderColor: "#dc2626", background: "#fef2f2" }
69
+ }
70
+ );
71
+ };
72
+ var trigger = { padding: "4px 8px", border: "1px solid #d1d5db", borderRadius: 6, background: "#fff", cursor: "pointer", fontSize: 13, lineHeight: 1 };
73
+ 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 };
74
+ var menuRight = { ...base, top: "100%", right: 0, marginTop: 4 };
75
+ var menuLeft = { ...base, top: "100%", left: 0, marginTop: 4 };
76
+ var flyLeft = { ...base, top: 0, right: "100%", maxHeight: 280, overflowY: "auto" };
77
+ var flyRight = { ...base, top: 0, left: "100%", maxHeight: 280, overflowY: "auto" };
78
+ 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 };
79
+ var itemDisabled = { ...itemStyle, color: "#9ca3af", cursor: "default" };
80
+ var MENU_CSS = ".loom-menu-item{background:transparent;border:none;}.loom-menu-item:hover:not(:disabled){background:#f3f4f6;}";
81
+ var MenuContext = createContext({ close: () => {
82
+ }, anchor: "right" });
83
+ var ActionMenu = ({
84
+ label = "\u22EF",
85
+ ariaLabel = "Actions",
86
+ anchor = "right",
87
+ children
88
+ }) => {
89
+ const [open, setOpen] = useState(false);
90
+ return /* @__PURE__ */ jsxs("div", { style: { position: "relative" }, children: [
91
+ /* @__PURE__ */ jsx("button", { type: "button", "aria-label": ariaLabel, onClick: () => setOpen((was) => !was), style: trigger, children: label }),
92
+ open ? /* @__PURE__ */ jsxs(Fragment, { children: [
93
+ /* @__PURE__ */ jsx("div", { onMouseDown: () => setOpen(false), style: { position: "fixed", inset: 0, zIndex: 29 } }),
94
+ /* @__PURE__ */ jsxs("div", { style: anchor === "right" ? menuRight : menuLeft, children: [
95
+ /* @__PURE__ */ jsx("style", { children: MENU_CSS }),
96
+ /* @__PURE__ */ jsx(MenuContext.Provider, { value: { close: () => setOpen(false), anchor }, children })
97
+ ] })
98
+ ] }) : null
99
+ ] });
100
+ };
101
+ var MenuItem = ({ label, onSelect, disabled }) => {
102
+ const { close } = useContext(MenuContext);
103
+ return /* @__PURE__ */ jsx(
104
+ "button",
105
+ {
106
+ type: "button",
107
+ className: "loom-menu-item",
108
+ disabled,
109
+ onClick: () => {
110
+ onSelect();
111
+ close();
112
+ },
113
+ style: disabled ? itemDisabled : itemStyle,
114
+ children: typeof label === "string" ? /* @__PURE__ */ jsx("span", { children: label }) : label
115
+ }
116
+ );
117
+ };
118
+ var SubMenu = ({ label, children }) => {
119
+ const { anchor } = useContext(MenuContext);
120
+ const [open, setOpen] = useState(false);
121
+ return /* @__PURE__ */ jsxs("div", { style: { position: "relative" }, onMouseEnter: () => setOpen(true), onMouseLeave: () => setOpen(false), children: [
122
+ /* @__PURE__ */ jsxs("button", { type: "button", className: "loom-menu-item", onClick: () => setOpen((was) => !was), style: itemStyle, children: [
123
+ /* @__PURE__ */ jsx("span", { children: label }),
124
+ /* @__PURE__ */ jsx("span", { children: "\u25B8" })
125
+ ] }),
126
+ open ? /* @__PURE__ */ jsx("div", { style: anchor === "right" ? flyLeft : flyRight, children }) : null
127
+ ] });
128
+ };
129
+
130
+ export { ActionMenu, JsonEditor, MenuItem, SubMenu, decodeLiteral, inputStyle, matches, useModelWrite };
131
+ //# sourceMappingURL=chunk-MIRMQPUE.js.map
132
+ //# sourceMappingURL=chunk-MIRMQPUE.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/react/hooks/model.ts","../src/react/kit/shared.ts","../src/react/kit/json-editor.tsx","../src/react/kit/menu.tsx"],"names":["useState","jsx"],"mappings":";;;;;AAKO,IAAM,aAAA,GAAgB,CAAC,KAAA,KAAoE;AAChG,EAAA,MAAM,WAAW,eAAA,EAAgB;AACjC,EAAA,OAAO,CAAC,KAAA,KAAU;AAChB,IAAA,IAAI,KAAA,KAAU,MAAA,EAAW,QAAA,CAAS,EAAE,IAAA,EAAM,UAAA,EAAY,GAAA,EAAK,KAAA,CAAM,GAAA,EAAK,OAAA,EAAS,KAAA,EAAO,CAAA;AAAA,EACxF,CAAA;AACF;;;ACJO,IAAM,UAAA,GAA4B,EAAE,OAAA,EAAS,UAAA,EAAY,MAAA,EAAQ,mBAAA,EAAqB,YAAA,EAAc,CAAA,EAAG,QAAA,EAAU,EAAA,EAAI,KAAA,EAAO,MAAA,EAAQ,WAAW,YAAA;AAG/I,IAAM,MAAA,GAAS,CAAC,KAAA,KACrB,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,GAAI,OAAA,GAAU,KAAA,KAAU,IAAA,GAAO,MAAA,GAAS,OAAO,KAAA;AAM7D,IAAM,aAAA,GAAgB,CAAI,KAAA,KAC/B,OAA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EACT,CAAA;AAAA,IACC,IAAA,mBAAOA,GAAAA,CAAC,KAAA,EAAA,EAAI,KAAA,EAAO,WAAW,OAAA,GAAU,OAAA,GAAU,QAAA,EAAW,QAAA,EAAS,CAAA,GAAS;AAAA,GAAA,EAClF,CAAA;AAEJ","file":"chunk-MIRMQPUE.js","sourcesContent":["import { useNovaDispatch, type NovaModelBinding } from '@niscorp/nova/adapters/react';\n\n// Returns a function that writes a new value to the field's bound path, through\n// the same `ui:model` pipeline the built-in controls use. A control or a plugin\n// widget calls it with its edited value.\nexport const useModelWrite = (model: NovaModelBinding | undefined): ((value: unknown) => void) => {\n const dispatch = useNovaDispatch();\n return (value) => {\n if (model !== undefined) dispatch({ type: 'ui:model', ref: model.ref, payload: value });\n };\n};\n","import type { CSSProperties } from 'react';\nimport { isRecord } from '@compile/parse';\nimport type { Pattern } from '@compile/types';\n\n// Shared by the kit's controls and structural editors.\n\nexport const inputStyle: CSSProperties = { padding: '6px 10px', border: '1px solid #d1d5db', borderRadius: 6, fontSize: 14, width: '100%', boxSizing: 'border-box' };\n\n// The value's own JS type, in the vocabulary the compiler's patterns use.\nexport const jsType = (value: unknown): string =>\n Array.isArray(value) ? 'array' : value === null ? 'null' : typeof value;\n\n// Decode a JSON-encoded literal prop (see `literal` in to-nova). The compiler\n// passes static `$`-bearing metadata (a variant's branches, a list's containers,\n// an \"add\" default) as a JSON string so Nova's resolver leaves it intact; the\n// component parses it back. Tolerates an already-decoded value or absence.\nexport const decodeLiteral = <T>(value: unknown): T | undefined =>\n typeof value === 'string' ? (JSON.parse(value) as T) : (value as T | undefined);\n\n// Does a value belong to a branch? `===` for a tag, `in` for a key, `typeof`\n// for a type — the whole of union discrimination, in plain JS. A `fallback`\n// branch never matches positively; the widget selects it only when nothing else\n// does, so it answers false here.\nexport const matches = (value: unknown, pattern: Pattern): boolean => {\n if (pattern.kind === 'tag') return isRecord(value) && value[pattern.key] === pattern.value;\n if (pattern.kind === 'key') return isRecord(value) && pattern.key in value;\n if (pattern.kind === 'type') return jsType(value) === pattern.type;\n return false;\n};\n","import { useEffect, useState, type CSSProperties, type FC } from 'react';\nimport { inputStyle } from './shared.js';\n\n// A controlled JSON editor: a textarea with pretty-printed JSON that commits only\n// when the text parses, so mid-edit invalid JSON doesn't fight the keystrokes. An\n// external change to the value reloads the buffer; the serialized-value dep makes\n// that fire on real content changes only, not on our own commits. Exported so\n// plugins can reuse it as the fallback editor for values they don't structure.\n\nconst rawStyle: CSSProperties = {\n ...inputStyle,\n margin: 0,\n fontFamily: 'ui-monospace, SFMono-Regular, Menlo, monospace',\n fontSize: 13,\n minHeight: 64,\n resize: 'vertical',\n width: '100%',\n boxSizing: 'border-box',\n};\n\nconst showJson = (value: unknown): string => JSON.stringify(value ?? null, null, 2);\n\nexport const JsonEditor: FC<{ value: unknown; onChange: (value: unknown) => void }> = ({ value, onChange }) => {\n const [text, setText] = useState(() => showJson(value));\n const [valid, setValid] = useState(true);\n const serialized = JSON.stringify(value ?? null);\n\n useEffect(() => {\n // Adopt the value only when it differs from what the buffer already holds,\n // so an external edit reloads it but our own committed edits don't churn it.\n let mine: unknown;\n try {\n mine = JSON.parse(text);\n } catch {\n setText(showJson(value));\n setValid(true);\n return;\n }\n if (JSON.stringify(mine ?? null) !== serialized) {\n setText(showJson(value));\n setValid(true);\n }\n // Keyed on the serialized value: runs only when the value's content changes.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [serialized]);\n\n return (\n <textarea\n value={text}\n spellCheck={false}\n onChange={(event) => {\n const next = event.target.value;\n setText(next);\n try {\n const parsed: unknown = JSON.parse(next);\n setValid(true);\n onChange(parsed);\n } catch {\n setValid(false);\n }\n }}\n style={valid ? rawStyle : { ...rawStyle, borderColor: '#dc2626', background: '#fef2f2' }}\n />\n );\n};\n","import { createContext, useContext, useState, type CSSProperties, type FC, type ReactNode } from 'react';\n\n// A small actions-menu primitive: a `⋯` trigger that opens a popover of items,\n// with optional fly-out submenus. Shared by the array row menu and the Prism\n// node editor so both look and behave the same. Presentational only — callers\n// supply the items and what they do.\n\nconst trigger: CSSProperties = { padding: '4px 8px', border: '1px solid #d1d5db', borderRadius: 6, background: '#fff', cursor: 'pointer', fontSize: 13, lineHeight: 1 };\nconst base: CSSProperties = { 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 };\nconst menuRight: CSSProperties = { ...base, top: '100%', right: 0, marginTop: 4 };\nconst menuLeft: CSSProperties = { ...base, top: '100%', left: 0, marginTop: 4 };\n// A submenu flies away from the menu's anchored edge (and scrolls): out to the\n// left for a right-anchored menu, out to the right for a left-anchored one. No\n// gap (flush `100%`) so the pointer can cross into it without leaving the row.\nconst flyLeft: CSSProperties = { ...base, top: 0, right: '100%', maxHeight: 280, overflowY: 'auto' };\nconst flyRight: CSSProperties = { ...base, top: 0, left: '100%', maxHeight: 280, overflowY: 'auto' };\nconst itemStyle: CSSProperties = { 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 };\nconst itemDisabled: CSSProperties = { ...itemStyle, color: '#9ca3af', cursor: 'default' };\n// Hover highlight (inline styles can't express `:hover`); the class is on every\n// item, the rule injected once with the open menu.\nconst MENU_CSS = '.loom-menu-item{background:transparent;border:none;}.loom-menu-item:hover:not(:disabled){background:#f3f4f6;}';\n\ntype Anchor = 'left' | 'right';\nconst MenuContext = createContext<{ close: () => void; anchor: Anchor }>({ close: () => {}, anchor: 'right' });\n\n// The trigger plus the popover. `anchor` is which edge the popover and its\n// submenus hang from. Children are `MenuItem` / `SubMenu`.\nexport const ActionMenu: FC<{ label?: ReactNode; ariaLabel?: string; anchor?: Anchor; children: ReactNode }> = ({\n label = '⋯',\n ariaLabel = 'Actions',\n anchor = 'right',\n children,\n}) => {\n const [open, setOpen] = useState(false);\n return (\n <div style={{ position: 'relative' }}>\n <button type=\"button\" aria-label={ariaLabel} onClick={() => setOpen((was) => !was)} style={trigger}>\n {label}\n </button>\n {open ? (\n <>\n <div onMouseDown={() => setOpen(false)} style={{ position: 'fixed', inset: 0, zIndex: 29 }} />\n <div style={anchor === 'right' ? menuRight : menuLeft}>\n <style>{MENU_CSS}</style>\n <MenuContext.Provider value={{ close: () => setOpen(false), anchor }}>{children}</MenuContext.Provider>\n </div>\n </>\n ) : null}\n </div>\n );\n};\n\n// A menu row: runs its action then closes the whole menu.\nexport const MenuItem: FC<{ label: ReactNode; onSelect: () => void; disabled?: boolean }> = ({ label, onSelect, disabled }) => {\n const { close } = useContext(MenuContext);\n return (\n <button\n type=\"button\"\n className=\"loom-menu-item\"\n disabled={disabled}\n onClick={() => {\n onSelect();\n close();\n }}\n style={disabled ? itemDisabled : itemStyle}\n >\n {typeof label === 'string' ? <span>{label}</span> : label}\n </button>\n );\n};\n\n// A row that flies out a submenu of its children on hover.\nexport const SubMenu: FC<{ label: ReactNode; children: ReactNode }> = ({ label, children }) => {\n const { anchor } = useContext(MenuContext);\n const [open, setOpen] = useState(false);\n return (\n <div style={{ position: 'relative' }} onMouseEnter={() => setOpen(true)} onMouseLeave={() => setOpen(false)}>\n <button type=\"button\" className=\"loom-menu-item\" onClick={() => setOpen((was) => !was)} style={itemStyle}>\n <span>{label}</span>\n <span>▸</span>\n </button>\n {open ? <div style={anchor === 'right' ? flyLeft : flyRight}>{children}</div> : null}\n </div>\n );\n};\n"]}
@@ -0,0 +1,58 @@
1
+ // src/compile/roles.ts
2
+ var Roles = {
3
+ // Layout primitives — arrange other nodes.
4
+ box: "loom:box",
5
+ // a flexible cell that grows to fill its row (an array item's editor)
6
+ group: "loom:group",
7
+ array: "loom:array",
8
+ arrayItem: "loom:array-item",
9
+ variant: "loom:variant",
10
+ // One branch of a variant — shows itself only when it's the active branch
11
+ // (the widget matches the value to a branch in JS and tells it through context).
12
+ branch: "loom:branch",
13
+ // Field wrapper — label, description, error, and required marker around one control.
14
+ field: "loom:field",
15
+ // Controls — edit a value; emit `ui:model`.
16
+ text: "loom:text",
17
+ number: "loom:number",
18
+ checkbox: "loom:checkbox",
19
+ select: "loom:select",
20
+ raw: "loom:raw",
21
+ // List actions — model writes to the bound array (no triggers). `append` adds
22
+ // a default element to the list it binds. `rowMenu` is the per-row actions menu
23
+ // (move / remove, and wrap / unwrap when the list's items are a recursive union
24
+ // with container variants); it reads `$items` and `$index` and writes the new
25
+ // array. Both work at any depth, since the bound path resolves per render.
26
+ append: "loom:append",
27
+ rowMenu: "loom:row-menu"
28
+ };
29
+
30
+ // src/editor/default.layout.ts
31
+ var LOOM_COLUMN = "loom:column";
32
+ var slot = (canvasId) => ({ component: "CanvasSlot", props: { canvasId } });
33
+ var titleOf = (formId) => {
34
+ const name = formId.replace(/^form:/, "");
35
+ return name.charAt(0).toUpperCase() + name.slice(1);
36
+ };
37
+ var formPanel = (formId) => ({
38
+ component: "Box",
39
+ props: { border: true, radius: 8, padding: 16 },
40
+ children: [{ component: "loom:group", props: { title: titleOf(formId) }, children: [slot(formId)] }]
41
+ });
42
+ var column = (grow, min, children) => ({
43
+ component: LOOM_COLUMN,
44
+ props: { grow, min },
45
+ children: [{ component: "Stack", props: { direction: "column", gap: 16 }, children }]
46
+ });
47
+ var defaultCanvasLayout = (formIds, viewIds) => ({
48
+ component: "Stack",
49
+ props: { direction: "row", gap: 16, align: "start" },
50
+ children: [
51
+ ...formIds.length > 0 ? [column(2, 420, formIds.map(formPanel))] : [],
52
+ ...viewIds.length > 0 ? [column(1, 340, viewIds.map(slot))] : []
53
+ ]
54
+ });
55
+
56
+ export { LOOM_COLUMN, Roles, defaultCanvasLayout };
57
+ //# sourceMappingURL=chunk-PTXRAWJX.js.map
58
+ //# sourceMappingURL=chunk-PTXRAWJX.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/compile/roles.ts","../src/editor/default.layout.ts"],"names":[],"mappings":";AAQ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AC,IAAA,EAAc,GAAA,EAAa,QAAA,MAAwC;AAAA,EACjF,SAAA,EAAW,WAAA;AAAA,EACX,KAAA,EAAO,EAAE,IAAA,EAAM,GAAA,EAAI;AAAA,EACnB,QAAA,EAAU,CAAC,EAAE,SAAA,EAAW,OAAA,EAAS,KAAA,EAAO,EAAE,SAAA,EAAW,QAAA,EAAU,GAAA,EAAK,EAAA,EAAG,EAAG,UAAU;AACtF,CAAA,CAAA;AAEO,IAAM,mBAAA,GAAsB,CAAC,OAAA,EAAmB,OAAA,MAAmC;AAAA,EACxF,SAAA,EAAW,OAAA;AAAA,EACX,OAAO,EAAE,SAAA,EAAW,OAAO,GAAA,EAAK,EAAA,EAAI,OAAO,OAAA,EAAQ;AAAA,EACnD,QAAA,EAAU;AAAA,IACR,GAAI,OAAA,CAAQ,MAAA,GAAS,CAAA,GAAI,CAAC,MAAA,CAAO,CAAA,EAAG,GAAA,EAAK,OAAA,CAAQ,GAAA,CAAI,SAAS,CAAC,CAAC,IAAI,EAAC;AAAA,IACrE,GAAI,OAAA,CAAQ,MAAA,GAAS,CAAA,GAAI,CAAC,MAAA,CAAO,CAAA,EAAG,GAAA,EAAK,OAAA,CAAQ,GAAA,CAAI,IAAI,CAAC,CAAC,IAAI;AAAC;AAEpE,CAAA","file":"chunk-PTXRAWJX.js","sourcesContent":["// The widget vocabulary the compiler emits as Nova component names. Each is\n// an abstract role; a kit registers a concrete component under the name, so\n// swapping the kit swaps the pixels without touching the compiler. Small and\n// stable on purpose — sub-variants ride as props, not new roles.\n//\n// Structural shapes (objects, arrays, unions) are compiled compositions of\n// these roles, not roles of their own.\n\nexport const Roles = {\n // Layout primitives — arrange other nodes.\n box: 'loom:box', // a flexible cell that grows to fill its row (an array item's editor)\n group: 'loom:group',\n array: 'loom:array',\n arrayItem: 'loom:array-item',\n variant: 'loom:variant',\n // One branch of a variant — shows itself only when it's the active branch\n // (the widget matches the value to a branch in JS and tells it through context).\n branch: 'loom:branch',\n\n // Field wrapper — label, description, error, and required marker around one control.\n field: 'loom:field',\n\n // Controls — edit a value; emit `ui:model`.\n text: 'loom:text',\n number: 'loom:number',\n checkbox: 'loom:checkbox',\n select: 'loom:select',\n raw: 'loom:raw',\n\n // List actions — model writes to the bound array (no triggers). `append` adds\n // a default element to the list it binds. `rowMenu` is the per-row actions menu\n // (move / remove, and wrap / unwrap when the list's items are a recursive union\n // with container variants); it reads `$items` and `$index` and writes the new\n // array. Both work at any depth, since the bound path resolves per render.\n append: 'loom:append',\n rowMenu: 'loom:row-menu',\n} as const;\n\nexport type Role = (typeof Roles)[keyof typeof Roles];\n","import type { LayoutNode } from '@niscorp/nova';\n\n// The editor's default canvasLayout — a plain Nova layout. The forms are the main\n// column (each in a titled, bordered panel); every other canvas (preview, JSON\n// views) stacks in a side column (those already render their own panel). No Nova\n// primitive can size a flex child, so the columns use Loom's `loom:column` (a Loom\n// component, registered with the kit). A plugin can replace the whole arrangement\n// with shell.setCanvasLayout.\n\nexport const LOOM_COLUMN = 'loom:column';\n\nconst slot = (canvasId: string): LayoutNode => ({ component: 'CanvasSlot', props: { canvasId } });\n\n// `form:data` -> `Data`. A form canvas's title is its document name.\nconst titleOf = (formId: string): string => {\n const name = formId.replace(/^form:/, '');\n return name.charAt(0).toUpperCase() + name.slice(1);\n};\n\n// A form sits in a bordered panel headed by its document name.\nconst formPanel = (formId: string): LayoutNode => ({\n component: 'Box',\n props: { border: true, radius: 8, padding: 16 },\n children: [{ component: 'loom:group', props: { title: titleOf(formId) }, children: [slot(formId)] }],\n});\n\nconst column = (grow: number, min: number, children: LayoutNode[]): LayoutNode => ({\n component: LOOM_COLUMN,\n props: { grow, min },\n children: [{ component: 'Stack', props: { direction: 'column', gap: 16 }, children }],\n});\n\nexport const defaultCanvasLayout = (formIds: string[], viewIds: string[]): LayoutNode => ({\n component: 'Stack',\n props: { direction: 'row', gap: 16, align: 'start' },\n children: [\n ...(formIds.length > 0 ? [column(2, 420, formIds.map(formPanel))] : []),\n ...(viewIds.length > 0 ? [column(1, 340, viewIds.map(slot))] : []),\n ],\n});\n"]}