@nibblearn/editor 0.0.0-stage → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs ADDED
@@ -0,0 +1,2023 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ // \0rolldown/runtime.js
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
13
+ get: ((k) => from[k]).bind(null, key),
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
+ });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
20
+ value: mod,
21
+ enumerable: true
22
+ }) : target, mod));
23
+ let react = require("react");
24
+ let lucide_react = require("lucide-react");
25
+ let _nibblearn_react = require("@nibblearn/react");
26
+ let clsx = require("clsx");
27
+ clsx = __toESM(clsx, 1);
28
+ let react_jsx_runtime = require("react/jsx-runtime");
29
+ let _nibblearn_core_examples = require("@nibblearn/core/examples");
30
+ // src/messages.ts
31
+ /** English UI strings of the editor. Override any of them through `NibblearnProvider messages`. */
32
+ var editorMessages = {
33
+ "editor.add": "Add {item}",
34
+ "editor.remove": "Delete",
35
+ "editor.removeItem": "Delete {item} {index}",
36
+ "editor.duplicate": "Duplicate",
37
+ "editor.duplicateItem": "Duplicate {item} {index}",
38
+ "editor.moveUp": "Move up",
39
+ "editor.moveUpItem": "Move {item} {index} up",
40
+ "editor.moveDown": "Move down",
41
+ "editor.moveDownItem": "Move {item} {index} down",
42
+ "editor.expandItem": "Show {item} {index}",
43
+ "editor.collapseItem": "Hide {item} {index}",
44
+ "editor.itemAdded": "{item} added.",
45
+ "editor.itemRemoved": "{item} {index} deleted.",
46
+ "editor.itemMoved": "{item} moved to position {position}.",
47
+ "editor.itemDuplicated": "{item} duplicated.",
48
+ "editor.untitled": "Untitled {item}",
49
+ "editor.optional": "optional",
50
+ "editor.set": "Add",
51
+ "editor.clear": "Clear",
52
+ "editor.variant": "Type",
53
+ "editor.group.content": "Content",
54
+ "editor.group.behavior": "Behaviour",
55
+ "editor.group.feedback": "Feedback",
56
+ "editor.group.appearance": "Appearance",
57
+ "editor.group.advanced": "Advanced",
58
+ "editor.image.src": "Image URL",
59
+ "editor.image.alt": "Alternative text",
60
+ "editor.image.caption": "Caption",
61
+ "editor.image.choose": "Choose image",
62
+ "editor.image.decorative": "Leave empty for a decorative image.",
63
+ "editor.richtext.bold": "Bold",
64
+ "editor.richtext.italic": "Italic",
65
+ "editor.richtext.code": "Code",
66
+ "editor.richtext.link": "Link",
67
+ "editor.richtext.list": "List",
68
+ "editor.richtext.toolbar": "Formatting for {field}",
69
+ "editor.json.invalid": "Not valid JSON.",
70
+ "editor.record.key": "Key",
71
+ "editor.record.value": "Value",
72
+ "editor.record.add": "Add entry",
73
+ "editor.issues.title": "Fix {count} problem(s) before this block can be shown",
74
+ "editor.issues.goTo": "Go to {field}",
75
+ "editor.preview": "Preview",
76
+ "editor.preview.lastValid": "Showing the last valid version while you edit.",
77
+ "editor.form": "Settings",
78
+ "editor.picker.title": "Add a block",
79
+ "editor.picker.search": "Search blocks",
80
+ "editor.picker.example": "With example content",
81
+ "editor.picker.blank": "Blank",
82
+ "editor.picker.start": "Start from",
83
+ "editor.picker.empty": "No blocks match “{query}”.",
84
+ "editor.picker.add": "Add {name}",
85
+ "editor.category.learn": "Learn",
86
+ "editor.category.practice": "Practice",
87
+ "editor.category.explore": "Explore",
88
+ "editor.category.decide": "Decide",
89
+ "editor.category.simulate": "Simulate",
90
+ "editor.category.present": "Present",
91
+ "editor.lesson.modules": "Blocks",
92
+ "editor.lesson.settings": "Lesson settings",
93
+ "editor.lesson.addBlock": "Add block",
94
+ "editor.lesson.empty": "This lesson has no blocks yet.",
95
+ "editor.lesson.select": "Edit {name}",
96
+ "editor.lesson.position": "Block {current} of {total}",
97
+ "editor.lesson.hasIssues": "Has problems",
98
+ "editor.lesson.blockIssues": "In this lesson:"
99
+ };
100
+ /** Translator for editor strings: provider `messages` first, then the English defaults. */
101
+ function useEditorT() {
102
+ const { messages } = (0, _nibblearn_react.useNibblearn)();
103
+ return (0, react.useCallback)((key, values) => {
104
+ const own = Object.prototype.hasOwnProperty.call(messages, key) ? messages[key] : void 0;
105
+ const fallback = Object.prototype.hasOwnProperty.call(editorMessages, key) ? editorMessages[key] : key;
106
+ return (0, _nibblearn_react.formatMessage)(own ?? fallback, values);
107
+ }, [messages]);
108
+ }
109
+ // src/form/context.ts
110
+ var FormContext = (0, react.createContext)(null);
111
+ function useForm() {
112
+ const ctx = (0, react.useContext)(FormContext);
113
+ if (!ctx) throw new Error("Form fields must be rendered inside ModuleForm");
114
+ return ctx;
115
+ }
116
+ /** DOM id for the control at `path`. */
117
+ var fieldId = (formId, path) => `${formId}-${path.map(String).join("-") || "root"}`;
118
+ /** Key used to match validation issues to fields. */
119
+ var pathKey = (path) => path.map(String).join(".");
120
+ function issueMap(issues) {
121
+ const map = /* @__PURE__ */ new Map();
122
+ for (const issue of issues ?? []) {
123
+ const key = issue.segments ? pathKey(issue.segments) : issue.path.replace(/\[(\d+)\]/g, ".$1");
124
+ map.set(key, [...map.get(key) ?? [], issue.message]);
125
+ }
126
+ return map;
127
+ }
128
+ // src/form/defaults.ts
129
+ /** A new id like `card-3` that is not used by `siblings` (deterministic: a counter, not random). */
130
+ function uniqueId(prefix, taken) {
131
+ const used = new Set(taken);
132
+ const base = prefix.replace(/[^a-zA-Z0-9_-]+/g, "-").replace(/^-+|-+$/g, "") || "item";
133
+ for (let n = 1; n < 1e5; n++) {
134
+ const id = `${base}-${n}`;
135
+ if (!used.has(id)) return id;
136
+ }
137
+ return `${base}-${used.size + 1}`;
138
+ }
139
+ /**
140
+ * A minimal value for a node: required object fields filled recursively, `minItems` array
141
+ * items, the first enum value, `min` for numbers. Optional fields are left out.
142
+ */
143
+ function defaultFor(node, ctx = {}, depth = 0) {
144
+ if (depth > 20) return void 0;
145
+ if (node.default !== void 0) return structuredClone(node.default);
146
+ switch (node.kind) {
147
+ case "string":
148
+ if (node.ui.widget === "id") return uniqueId(ctx.idPrefix ?? "item", ctx.takenIds ?? []);
149
+ if (node.enum?.length) return node.enum[0];
150
+ return node.minLength ? "New text" : "";
151
+ case "number": {
152
+ const inc = node.step ?? 1;
153
+ const lo = node.min === void 0 ? void 0 : node.min + (node.minExclusive ? inc : 0);
154
+ const hi = node.max === void 0 ? void 0 : node.max - (node.maxExclusive ? inc : 0);
155
+ if (lo !== void 0 && lo > 0) return lo;
156
+ if (hi !== void 0 && hi < 0) return hi;
157
+ return 0;
158
+ }
159
+ case "boolean": return false;
160
+ case "const": return node.value;
161
+ case "object": {
162
+ const out = {};
163
+ for (const f of node.fields) {
164
+ if (!f.required) continue;
165
+ const v = defaultFor(f.node, f.key === "id" ? ctx : { idPrefix: f.key }, depth + 1);
166
+ if (v !== void 0) out[f.key] = v;
167
+ }
168
+ return out;
169
+ }
170
+ case "array": {
171
+ const n = node.minItems ?? 0;
172
+ const items = [];
173
+ const prefix = node.ui.itemName ?? "item";
174
+ for (let i = 0; i < n; i++) {
175
+ const taken = items.map((it) => typeof it === "object" && it && "id" in it ? String(it.id) : "").filter(Boolean);
176
+ items.push(defaultFor(node.item, {
177
+ idPrefix: prefix,
178
+ takenIds: taken
179
+ }, depth + 1));
180
+ }
181
+ return items;
182
+ }
183
+ case "union": {
184
+ const first = node.variants[0];
185
+ return first ? defaultFor(first.node, ctx, depth + 1) : void 0;
186
+ }
187
+ case "record": return {};
188
+ default: return null;
189
+ }
190
+ }
191
+ // src/form/path.ts
192
+ var FORBIDDEN = /* @__PURE__ */ new Set([
193
+ "__proto__",
194
+ "constructor",
195
+ "prototype"
196
+ ]);
197
+ function assertSafe(path) {
198
+ for (const seg of path) if (typeof seg === "string" && FORBIDDEN.has(seg)) throw new TypeError(`unsafe path segment "${seg}"`);
199
+ }
200
+ var isRecord$1 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
201
+ /** Read the value at `path` (own properties only). */
202
+ function getAt(root, path) {
203
+ let cur = root;
204
+ for (const seg of path) if (typeof seg === "number") {
205
+ if (!Array.isArray(cur)) return void 0;
206
+ cur = cur[seg];
207
+ } else {
208
+ if (!isRecord$1(cur) || !Object.prototype.hasOwnProperty.call(cur, seg)) return void 0;
209
+ cur = cur[seg];
210
+ }
211
+ return cur;
212
+ }
213
+ /**
214
+ * Return a copy of `root` with `value` at `path`; containers along the path are copied, the
215
+ * rest is shared. `undefined` removes an object key.
216
+ */
217
+ function setAt(root, path, value) {
218
+ assertSafe(path);
219
+ const rec = (node, i) => {
220
+ if (i === path.length) return value;
221
+ const seg = path[i];
222
+ if (typeof seg === "number") {
223
+ const arr = Array.isArray(node) ? [...node] : [];
224
+ arr[seg] = rec(arr[seg], i + 1);
225
+ return arr;
226
+ }
227
+ const obj = isRecord$1(node) ? { ...node } : {};
228
+ const next = rec(Object.prototype.hasOwnProperty.call(obj, seg) ? obj[seg] : void 0, i + 1);
229
+ if (next === void 0) delete obj[seg];
230
+ else obj[seg] = next;
231
+ return obj;
232
+ };
233
+ return rec(root, 0);
234
+ }
235
+ /** Remove the array item or object key at `path`. */
236
+ function removeAt(root, path) {
237
+ if (path.length === 0) return root;
238
+ const parentPath = path.slice(0, -1);
239
+ const last = path[path.length - 1];
240
+ const parent = getAt(root, parentPath);
241
+ if (typeof last === "number" && Array.isArray(parent)) return setAt(root, parentPath, parent.filter((_, i) => i !== last));
242
+ return setAt(root, path, void 0);
243
+ }
244
+ /** Insert `value` into the array at `path` before `index` (default: at the end). */
245
+ function insertAt(root, path, value, index) {
246
+ const arr = getAt(root, path);
247
+ const list = Array.isArray(arr) ? [...arr] : [];
248
+ list.splice(index ?? list.length, 0, value);
249
+ return setAt(root, path, list);
250
+ }
251
+ /** Move the array item at `path` from `from` to `to`. */
252
+ function moveItem(root, path, from, to) {
253
+ const arr = getAt(root, path);
254
+ if (!Array.isArray(arr) || from === to || to < 0 || to >= arr.length || from < 0 || from >= arr.length) return root;
255
+ const list = [...arr];
256
+ const [item] = list.splice(from, 1);
257
+ list.splice(to, 0, item);
258
+ return setAt(root, path, list);
259
+ }
260
+ // src/form/fields.tsx
261
+ var isRecord = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
262
+ /** Label for a field: `field.<type>.<path>` message override, then the schema title. */
263
+ function useLabel(path, node, fallbackKey) {
264
+ const { type } = useForm();
265
+ const t = useEditorT();
266
+ const key = `field.${type}.${path.filter((s) => typeof s === "string").join(".")}`;
267
+ const custom = t(key);
268
+ return custom !== key ? custom : node.title ?? (0, _nibblearn_react.humanizeKey)(fallbackKey);
269
+ }
270
+ /** Label, description and error wrapper shared by single-control fields. */
271
+ function FieldFrame({ id, label, description, errors, required, children, inline }) {
272
+ const t = useEditorT();
273
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
274
+ className: (0, clsx.default)("nbe-field", inline && "nbe-field--inline", errors.length > 0 && "nbe-field--invalid"),
275
+ children: [
276
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
277
+ className: "nbe-field__label",
278
+ htmlFor: id,
279
+ children: [label, !required && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
280
+ className: "nbe-field__optional",
281
+ children: [
282
+ " (",
283
+ t("editor.optional"),
284
+ ")"
285
+ ]
286
+ })]
287
+ }),
288
+ children,
289
+ description && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
290
+ className: "nbe-field__help",
291
+ id: `${id}-help`,
292
+ children: description
293
+ }),
294
+ errors.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
295
+ className: "nbe-field__error",
296
+ id: `${id}-error`,
297
+ children: errors.join(" ")
298
+ })
299
+ ]
300
+ });
301
+ }
302
+ var describedBy = (id, description, errors = []) => [description && `${id}-help`, errors.length && `${id}-error`].filter(Boolean).join(" ") || void 0;
303
+ function TextField({ node, path, value, label, required }) {
304
+ const { formId, update, issuesAt } = useForm();
305
+ const id = fieldId(formId, path);
306
+ const errors = issuesAt(path);
307
+ const multiline = node.ui.widget === "textarea";
308
+ const str = typeof value === "string" ? value : "";
309
+ const onChange = (v) => update(path, v === "" && !required ? void 0 : v);
310
+ const common = {
311
+ id,
312
+ className: "nbe-input",
313
+ value: str,
314
+ maxLength: node.kind === "string" ? node.maxLength : void 0,
315
+ "aria-invalid": errors.length > 0 || void 0,
316
+ "aria-describedby": describedBy(id, node.description, errors)
317
+ };
318
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FieldFrame, {
319
+ id,
320
+ label,
321
+ description: node.description,
322
+ errors,
323
+ required,
324
+ children: multiline ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("textarea", {
325
+ ...common,
326
+ rows: 3,
327
+ onChange: (e) => onChange(e.target.value)
328
+ }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
329
+ ...common,
330
+ type: "text",
331
+ onChange: (e) => onChange(e.target.value)
332
+ })
333
+ });
334
+ }
335
+ /** Wraps the selection of a textarea in markup, e.g. **bold**. */
336
+ function wrapSelection(el, before, after, placeholder) {
337
+ const { selectionStart: s, selectionEnd: e, value } = el;
338
+ const selected = value.slice(s, e) || placeholder;
339
+ return {
340
+ next: value.slice(0, s) + before + selected + after + value.slice(e),
341
+ start: s + before.length,
342
+ end: s + before.length + selected.length
343
+ };
344
+ }
345
+ function RichTextField({ node, path, value, label, required }) {
346
+ const { formId, update, issuesAt } = useForm();
347
+ const t = useEditorT();
348
+ const id = fieldId(formId, path);
349
+ const errors = issuesAt(path);
350
+ const ref = (0, react.useRef)(null);
351
+ const block = node.ui.widget === "richtext-block";
352
+ const str = typeof value === "string" ? value : "";
353
+ const set = (v) => update(path, v === "" && !required ? void 0 : v);
354
+ const apply = (before, after, placeholder) => {
355
+ const el = ref.current;
356
+ if (!el) return;
357
+ const { next, start, end } = wrapSelection(el, before, after, placeholder);
358
+ set(next);
359
+ requestAnimationFrame(() => {
360
+ el.focus();
361
+ el.setSelectionRange(start, end);
362
+ });
363
+ };
364
+ const tools = [
365
+ [
366
+ t("editor.richtext.bold"),
367
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Bold, {
368
+ "aria-hidden": true,
369
+ size: 16
370
+ }, "b"),
371
+ "**",
372
+ "**",
373
+ "bold"
374
+ ],
375
+ [
376
+ t("editor.richtext.italic"),
377
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Italic, {
378
+ "aria-hidden": true,
379
+ size: 16
380
+ }, "i"),
381
+ "*",
382
+ "*",
383
+ "italic"
384
+ ],
385
+ [
386
+ t("editor.richtext.code"),
387
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Code, {
388
+ "aria-hidden": true,
389
+ size: 16
390
+ }, "c"),
391
+ "`",
392
+ "`",
393
+ "code"
394
+ ],
395
+ [
396
+ t("editor.richtext.link"),
397
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Link, {
398
+ "aria-hidden": true,
399
+ size: 16
400
+ }, "l"),
401
+ "[",
402
+ "](https://)",
403
+ "link text"
404
+ ],
405
+ ...block ? [[
406
+ t("editor.richtext.list"),
407
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.List, {
408
+ "aria-hidden": true,
409
+ size: 16
410
+ }, "li"),
411
+ "\n- ",
412
+ "",
413
+ "item"
414
+ ]] : []
415
+ ];
416
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(FieldFrame, {
417
+ id,
418
+ label,
419
+ description: node.description,
420
+ errors,
421
+ required,
422
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
423
+ className: "nbe-toolbar",
424
+ role: "toolbar",
425
+ "aria-label": t("editor.richtext.toolbar", { field: label }),
426
+ children: tools.map(([name, icon, before, after, placeholder]) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
427
+ type: "button",
428
+ className: "nbe-icon-btn",
429
+ onClick: () => apply(before, after, placeholder),
430
+ children: [icon, /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
431
+ className: "nbe-sr-only",
432
+ children: name
433
+ })]
434
+ }, name))
435
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("textarea", {
436
+ ref,
437
+ id,
438
+ className: "nbe-input nbe-input--rich",
439
+ rows: block ? 5 : 2,
440
+ value: str,
441
+ maxLength: node.kind === "string" ? node.maxLength : void 0,
442
+ "aria-invalid": errors.length > 0 || void 0,
443
+ "aria-describedby": describedBy(id, node.description, errors),
444
+ onChange: (e) => set(e.target.value)
445
+ })]
446
+ });
447
+ }
448
+ function NumberField({ node, path, value, label, required }) {
449
+ const { formId, update, issuesAt } = useForm();
450
+ const id = fieldId(formId, path);
451
+ const errors = issuesAt(path);
452
+ const num = typeof value === "number" ? value : "";
453
+ const n = node.kind === "number" ? node : void 0;
454
+ const step = n?.step ?? (n?.integer ? 1 : n && n.max !== void 0 && n.min !== void 0 && n.max - n.min <= 1 ? .01 : "any");
455
+ const [draft, setDraft] = (0, react.useState)(null);
456
+ const set = (raw) => {
457
+ if (raw === "") {
458
+ if (!required) update(path, void 0);
459
+ return;
460
+ }
461
+ const v = Number(raw);
462
+ if (Number.isFinite(v)) update(path, v);
463
+ };
464
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FieldFrame, {
465
+ id,
466
+ label,
467
+ description: node.description,
468
+ errors,
469
+ required,
470
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
471
+ className: "nbe-number",
472
+ children: [node.ui.widget === "slider" && n?.min !== void 0 && n.max !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
473
+ type: "range",
474
+ className: "nbe-range",
475
+ min: n.min,
476
+ max: n.max,
477
+ step,
478
+ value: num === "" ? n.min : num,
479
+ tabIndex: -1,
480
+ "aria-hidden": true,
481
+ onChange: (e) => set(e.target.value)
482
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
483
+ id,
484
+ type: "number",
485
+ className: "nbe-input nbe-input--number",
486
+ value: draft ?? num,
487
+ min: n?.min,
488
+ max: n?.max,
489
+ step,
490
+ "aria-invalid": errors.length > 0 || void 0,
491
+ "aria-describedby": describedBy(id, node.description, errors),
492
+ onChange: (e) => {
493
+ setDraft(e.target.value);
494
+ set(e.target.value);
495
+ },
496
+ onBlur: () => setDraft(null)
497
+ })]
498
+ })
499
+ });
500
+ }
501
+ function SwitchField({ node, path, value, label }) {
502
+ const { formId, update, issuesAt } = useForm();
503
+ const id = fieldId(formId, path);
504
+ const errors = issuesAt(path);
505
+ const checked = value === true || value === void 0 && node.default === true;
506
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
507
+ className: "nbe-field nbe-field--switch",
508
+ children: [
509
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
510
+ id,
511
+ type: "checkbox",
512
+ role: "switch",
513
+ className: "nbe-switch",
514
+ checked,
515
+ "aria-describedby": describedBy(id, node.description, errors),
516
+ onChange: (e) => update(path, e.target.checked)
517
+ }),
518
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", {
519
+ htmlFor: id,
520
+ className: "nbe-field__label",
521
+ children: label
522
+ }),
523
+ node.description && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
524
+ className: "nbe-field__help",
525
+ id: `${id}-help`,
526
+ children: node.description
527
+ }),
528
+ errors.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
529
+ className: "nbe-field__error",
530
+ id: `${id}-error`,
531
+ children: errors.join(" ")
532
+ })
533
+ ]
534
+ });
535
+ }
536
+ function SelectField({ node, path, value, label, required }) {
537
+ const { formId, update, issuesAt } = useForm();
538
+ const id = fieldId(formId, path);
539
+ const errors = issuesAt(path);
540
+ const options = node.kind === "string" ? node.enum ?? [] : [];
541
+ const current = typeof value === "string" ? value : typeof node.default === "string" ? node.default : "";
542
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FieldFrame, {
543
+ id,
544
+ label,
545
+ description: node.description,
546
+ errors,
547
+ required,
548
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("select", {
549
+ id,
550
+ className: "nbe-input",
551
+ value: current,
552
+ "aria-invalid": errors.length > 0 || void 0,
553
+ "aria-describedby": describedBy(id, node.description, errors),
554
+ onChange: (e) => update(path, e.target.value === "" ? void 0 : e.target.value),
555
+ children: [!required && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
556
+ value: "",
557
+ children: "—"
558
+ }), options.map((o) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
559
+ value: o,
560
+ children: (0, _nibblearn_react.humanizeKey)(o)
561
+ }, o))]
562
+ })
563
+ });
564
+ }
565
+ function ColorField({ node, path, value, label, required }) {
566
+ const { formId, update, issuesAt } = useForm();
567
+ const id = fieldId(formId, path);
568
+ const errors = issuesAt(path);
569
+ const str = typeof value === "string" ? value : "";
570
+ const hex = /^#[0-9a-fA-F]{6}$/.test(str) ? str : "#3b5bdb";
571
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FieldFrame, {
572
+ id,
573
+ label,
574
+ description: node.description,
575
+ errors,
576
+ required,
577
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
578
+ className: "nbe-color",
579
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
580
+ type: "color",
581
+ className: "nbe-color__swatch",
582
+ value: hex,
583
+ "aria-hidden": true,
584
+ tabIndex: -1,
585
+ onChange: (e) => update(path, e.target.value)
586
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
587
+ id,
588
+ type: "text",
589
+ className: "nbe-input",
590
+ value: str,
591
+ placeholder: "#3b5bdb",
592
+ "aria-invalid": errors.length > 0 || void 0,
593
+ "aria-describedby": describedBy(id, node.description, errors),
594
+ onChange: (e) => update(path, e.target.value === "" && !required ? void 0 : e.target.value)
595
+ })]
596
+ })
597
+ });
598
+ }
599
+ function JsonField({ node, path, value, label, required }) {
600
+ const { formId, update, issuesAt } = useForm();
601
+ const t = useEditorT();
602
+ const id = fieldId(formId, path);
603
+ const [text, setText] = (0, react.useState)(() => JSON.stringify(value ?? null, null, 2));
604
+ const [bad, setBad] = (0, react.useState)(false);
605
+ const errors = [...issuesAt(path), ...bad ? [t("editor.json.invalid")] : []];
606
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FieldFrame, {
607
+ id,
608
+ label,
609
+ description: node.description,
610
+ errors,
611
+ required,
612
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("textarea", {
613
+ id,
614
+ className: "nbe-input nbe-input--code",
615
+ rows: 4,
616
+ value: text,
617
+ "aria-invalid": errors.length > 0 || void 0,
618
+ "aria-describedby": describedBy(id, node.description, errors),
619
+ onChange: (e) => {
620
+ setText(e.target.value);
621
+ try {
622
+ update(path, JSON.parse(e.target.value));
623
+ setBad(false);
624
+ } catch {
625
+ setBad(true);
626
+ }
627
+ }
628
+ })
629
+ });
630
+ }
631
+ function ImageField({ node, path, value, label, required }) {
632
+ const { formId, update, issuesAt, onPickImage } = useForm();
633
+ const t = useEditorT();
634
+ const media = isRecord(value) ? value : void 0;
635
+ const src = typeof media?.src === "string" ? media.src : "";
636
+ const set = (key, v) => update([...path, key], v === "" && key !== "src" && key !== "alt" ? void 0 : v);
637
+ if (!media && !required) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(OptionalAdd, {
638
+ label,
639
+ onAdd: () => update(path, {
640
+ src: "",
641
+ alt: ""
642
+ })
643
+ });
644
+ const srcId = fieldId(formId, [...path, "src"]);
645
+ const altId = fieldId(formId, [...path, "alt"]);
646
+ const capId = fieldId(formId, [...path, "caption"]);
647
+ const srcErrors = [...issuesAt(path), ...issuesAt([...path, "src"])];
648
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("fieldset", {
649
+ className: "nbe-group nbe-image",
650
+ children: [
651
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("legend", {
652
+ className: "nbe-group__legend",
653
+ children: label
654
+ }),
655
+ node.description && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
656
+ className: "nbe-field__help",
657
+ children: node.description
658
+ }),
659
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
660
+ className: "nbe-image__body",
661
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
662
+ className: "nbe-image__preview",
663
+ children: src ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_nibblearn_react.SafeImage, {
664
+ media: {
665
+ src,
666
+ alt: ""
667
+ },
668
+ showCaption: false
669
+ }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
670
+ className: "nbe-image__empty",
671
+ "aria-hidden": true
672
+ })
673
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
674
+ className: "nbe-image__fields",
675
+ children: [
676
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FieldFrame, {
677
+ id: srcId,
678
+ label: t("editor.image.src"),
679
+ errors: srcErrors,
680
+ required: true,
681
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
682
+ className: "nbe-row",
683
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
684
+ id: srcId,
685
+ className: "nbe-input",
686
+ value: src,
687
+ "aria-invalid": srcErrors.length > 0 || void 0,
688
+ "aria-describedby": describedBy(srcId, void 0, srcErrors),
689
+ onChange: (e) => set("src", e.target.value)
690
+ }), onPickImage && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
691
+ type: "button",
692
+ className: "nbe-btn",
693
+ onClick: async () => {
694
+ const picked = await onPickImage();
695
+ if (!picked) return;
696
+ update([...path, "src"], picked.src);
697
+ if (picked.alt !== void 0 || typeof media?.alt !== "string") update([...path, "alt"], picked.alt ?? "");
698
+ },
699
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.ImagePlus, {
700
+ "aria-hidden": true,
701
+ size: 16
702
+ }), t("editor.image.choose")]
703
+ })]
704
+ })
705
+ }),
706
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FieldFrame, {
707
+ id: altId,
708
+ label: t("editor.image.alt"),
709
+ description: t("editor.image.decorative"),
710
+ errors: issuesAt([...path, "alt"]),
711
+ required: false,
712
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
713
+ id: altId,
714
+ className: "nbe-input",
715
+ value: typeof media?.alt === "string" ? media.alt : "",
716
+ "aria-describedby": `${altId}-help`,
717
+ onChange: (e) => set("alt", e.target.value)
718
+ })
719
+ }),
720
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FieldFrame, {
721
+ id: capId,
722
+ label: t("editor.image.caption"),
723
+ errors: issuesAt([...path, "caption"]),
724
+ required: false,
725
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
726
+ id: capId,
727
+ className: "nbe-input",
728
+ value: typeof media?.caption === "string" ? media.caption : "",
729
+ onChange: (e) => set("caption", e.target.value)
730
+ })
731
+ })
732
+ ]
733
+ })]
734
+ }),
735
+ !required && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
736
+ type: "button",
737
+ className: "nbe-btn nbe-btn--quiet",
738
+ onClick: () => update(path, void 0),
739
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.X, {
740
+ "aria-hidden": true,
741
+ size: 14
742
+ }), t("editor.clear")]
743
+ })
744
+ ]
745
+ });
746
+ }
747
+ function OptionalAdd({ label, onAdd }) {
748
+ const t = useEditorT();
749
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
750
+ className: "nbe-field nbe-field--add",
751
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
752
+ type: "button",
753
+ className: "nbe-btn nbe-btn--dashed",
754
+ onClick: onAdd,
755
+ children: [
756
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Plus, {
757
+ "aria-hidden": true,
758
+ size: 14
759
+ }),
760
+ t("editor.set"),
761
+ " ",
762
+ label.charAt(0).toLowerCase() + label.slice(1)
763
+ ]
764
+ })
765
+ });
766
+ }
767
+ var GROUP_ORDER = [
768
+ "content",
769
+ "behavior",
770
+ "feedback",
771
+ "appearance",
772
+ "advanced"
773
+ ];
774
+ function ObjectField({ node, path, value, label, required, depth }) {
775
+ const { update } = useForm();
776
+ const t = useEditorT();
777
+ if (node.kind !== "object") return null;
778
+ const obj = isRecord(value) ? value : void 0;
779
+ if (!obj && !required && depth > 0) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(OptionalAdd, {
780
+ label,
781
+ onAdd: () => update(path, defaultFor(node))
782
+ });
783
+ const visible = node.fields.filter((f) => f.node.ui.widget !== "hidden" && f.node.kind !== "const");
784
+ const ids = visible.filter((f) => f.node.ui.widget === "id");
785
+ const rest = visible.filter((f) => f.node.ui.widget !== "id");
786
+ const render = (f) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
787
+ field: f,
788
+ path: [...path, f.key],
789
+ value: obj ? Object.prototype.hasOwnProperty.call(obj, f.key) ? obj[f.key] : void 0 : void 0,
790
+ depth: depth + 1,
791
+ bare: depth === 0 && f.node.kind === "object" && f.node.ui.group !== void 0
792
+ }, f.key);
793
+ if (depth === 0) {
794
+ const byGroup = /* @__PURE__ */ new Map();
795
+ for (const f of rest) {
796
+ const g = f.node.ui.group ?? "content";
797
+ byGroup.set(g, [...byGroup.get(g) ?? [], f]);
798
+ }
799
+ for (const f of ids) byGroup.set("advanced", [...byGroup.get("advanced") ?? [], f]);
800
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
801
+ className: "nbe-form__groups",
802
+ children: GROUP_ORDER.filter((g) => byGroup.has(g)).map((g) => g === "content" ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
803
+ className: "nbe-section",
804
+ "aria-labelledby": `${path.join("-")}-${g}`,
805
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", {
806
+ className: "nbe-section__title",
807
+ id: `${path.join("-")}-${g}`,
808
+ children: t(`editor.group.${g}`)
809
+ }), byGroup.get(g).map(render)]
810
+ }, g) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("details", {
811
+ className: "nbe-section nbe-section--collapsible",
812
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("summary", {
813
+ className: "nbe-section__title",
814
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.ChevronDown, {
815
+ "aria-hidden": true,
816
+ size: 16,
817
+ className: "nbe-chevron"
818
+ }), t(`editor.group.${g}`)]
819
+ }), byGroup.get(g).map(render)]
820
+ }, g))
821
+ });
822
+ }
823
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("fieldset", {
824
+ className: "nbe-group",
825
+ children: [
826
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("legend", {
827
+ className: "nbe-group__legend",
828
+ children: label
829
+ }),
830
+ node.description && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
831
+ className: "nbe-field__help",
832
+ children: node.description
833
+ }),
834
+ rest.map(render),
835
+ ids.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("details", {
836
+ className: "nbe-advanced",
837
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("summary", { children: t("editor.group.advanced") }), ids.map(render)]
838
+ }),
839
+ !required && obj && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
840
+ type: "button",
841
+ className: "nbe-btn nbe-btn--quiet",
842
+ onClick: () => update(path, void 0),
843
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.X, {
844
+ "aria-hidden": true,
845
+ size: 14
846
+ }), t("editor.clear")]
847
+ })
848
+ ]
849
+ });
850
+ }
851
+ function itemTitle(labelKey, item, fallback) {
852
+ const key = labelKey;
853
+ if (key && isRecord(item) && typeof item[key] === "string" && item[key]) return (0, _nibblearn_react.stripMarkup)(item[key]);
854
+ if (typeof item === "string" && item) return (0, _nibblearn_react.stripMarkup)(item);
855
+ return fallback;
856
+ }
857
+ function ArrayField({ node, path, value, label, required, depth }) {
858
+ const { formId, update, root, announce, onFocusPath } = useForm();
859
+ const t = useEditorT();
860
+ const list = Array.isArray(value) ? value : [];
861
+ const itemName = node.ui.itemName ?? "item";
862
+ const [expanded, setExpanded] = (0, react.useState)(() => new Set(list.length <= 4 ? list.map((_, i) => i) : [0]));
863
+ const focusAfter = (0, react.useRef)(null);
864
+ const listRef = (0, react.useRef)(null);
865
+ const addRef = (0, react.useRef)(null);
866
+ (0, react.useEffect)(() => {
867
+ const target = focusAfter.current;
868
+ if (!target) return;
869
+ focusAfter.current = null;
870
+ const item = listRef.current?.querySelector(`[data-index="${target.index}"]`);
871
+ const wanted = item?.querySelector(`[data-action="${target.action}"]`);
872
+ ((wanted && !wanted.disabled ? wanted : null) ?? item?.querySelector("button:not(:disabled), input, textarea, select") ?? addRef.current)?.focus();
873
+ });
874
+ if (node.kind !== "array") return null;
875
+ const Item = node.item;
876
+ const min = node.minItems ?? 0;
877
+ const max = node.maxItems ?? Infinity;
878
+ const name = (i) => itemTitle(node.ui.itemLabel, list[i], t("editor.untitled", { item: itemName }));
879
+ const idsInList = () => list.map((it) => isRecord(it) && typeof it.id === "string" ? it.id : "").filter(Boolean);
880
+ const add = () => {
881
+ const created = defaultFor(Item, {
882
+ idPrefix: itemName.replace(/\s+/g, "-"),
883
+ takenIds: idsInList()
884
+ });
885
+ update(path, [...list, created]);
886
+ setExpanded(/* @__PURE__ */ new Set([...expanded, list.length]));
887
+ focusAfter.current = {
888
+ index: list.length,
889
+ action: "toggle"
890
+ };
891
+ announce(t("editor.itemAdded", { item: (0, _nibblearn_react.humanizeKey)(itemName) }));
892
+ };
893
+ const remove = (i) => {
894
+ update(path, getAt(removeAt(root, [...path, i]), path));
895
+ focusAfter.current = {
896
+ index: Math.max(0, i - 1),
897
+ action: "toggle"
898
+ };
899
+ announce(t("editor.itemRemoved", {
900
+ item: (0, _nibblearn_react.humanizeKey)(itemName),
901
+ index: i + 1
902
+ }));
903
+ };
904
+ const move = (i, to) => {
905
+ update(path, getAt(moveItem(root, path, i, to), path));
906
+ focusAfter.current = {
907
+ index: to,
908
+ action: to < i ? "up" : "down"
909
+ };
910
+ announce(t("editor.itemMoved", {
911
+ item: name(i),
912
+ position: to + 1
913
+ }));
914
+ };
915
+ const duplicate = (i) => {
916
+ const copy = structuredClone(list[i]);
917
+ if (isRecord(copy) && typeof copy.id === "string") copy.id = uniqueId(copy.id.replace(/-\d+$/, ""), idsInList());
918
+ update(path, getAt(insertAt(root, path, copy, i + 1), path));
919
+ setExpanded(/* @__PURE__ */ new Set([...expanded, i + 1]));
920
+ focusAfter.current = {
921
+ index: i + 1,
922
+ action: "toggle"
923
+ };
924
+ announce(t("editor.itemDuplicated", { item: name(i) }));
925
+ };
926
+ const toggle = (i) => {
927
+ const next = new Set(expanded);
928
+ if (next.has(i)) next.delete(i);
929
+ else next.add(i);
930
+ setExpanded(next);
931
+ };
932
+ const scalarItems = Item.kind !== "object" && Item.kind !== "union" && Item.kind !== "array";
933
+ const headingId = `${fieldId(formId, path)}-label`;
934
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
935
+ className: "nbe-array",
936
+ "aria-labelledby": headingId,
937
+ children: [
938
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
939
+ className: "nbe-array__head",
940
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("h4", {
941
+ className: "nbe-array__title",
942
+ id: headingId,
943
+ children: [
944
+ label,
945
+ " ",
946
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
947
+ className: "nbe-array__count",
948
+ children: list.length
949
+ }),
950
+ !required && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
951
+ className: "nbe-field__optional",
952
+ children: [
953
+ " (",
954
+ t("editor.optional"),
955
+ ")"
956
+ ]
957
+ })
958
+ ]
959
+ })
960
+ }),
961
+ node.description && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
962
+ className: "nbe-field__help",
963
+ children: node.description
964
+ }),
965
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("ol", {
966
+ className: "nbe-array__list",
967
+ ref: listRef,
968
+ children: list.map((item, i) => {
969
+ const itemPath = [...path, i];
970
+ const open = scalarItems || expanded.has(i);
971
+ const n = {
972
+ item: itemName,
973
+ index: i + 1
974
+ };
975
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("li", {
976
+ className: "nbe-item",
977
+ "data-index": i,
978
+ onFocusCapture: () => onFocusPath?.(itemPath),
979
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
980
+ className: "nbe-item__head",
981
+ children: [
982
+ scalarItems ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
983
+ className: "nbe-item__index",
984
+ "aria-hidden": true,
985
+ children: i + 1
986
+ }) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
987
+ type: "button",
988
+ className: "nbe-item__toggle",
989
+ "aria-expanded": open,
990
+ "data-action": "toggle",
991
+ onClick: () => toggle(i),
992
+ children: [
993
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.ChevronDown, {
994
+ "aria-hidden": true,
995
+ size: 16,
996
+ className: "nbe-chevron"
997
+ }),
998
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
999
+ className: "nbe-item__index",
1000
+ children: [i + 1, "."]
1001
+ }),
1002
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1003
+ className: "nbe-item__name",
1004
+ children: name(i)
1005
+ })
1006
+ ]
1007
+ }),
1008
+ scalarItems && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1009
+ className: "nbe-item__inline",
1010
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
1011
+ field: {
1012
+ key: String(i),
1013
+ node: {
1014
+ ...Item,
1015
+ title: `${(0, _nibblearn_react.humanizeKey)(itemName)} ${i + 1}`
1016
+ },
1017
+ required: true
1018
+ },
1019
+ path: itemPath,
1020
+ value: item,
1021
+ depth: depth + 1
1022
+ })
1023
+ }),
1024
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1025
+ className: "nbe-item__actions",
1026
+ children: [
1027
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
1028
+ type: "button",
1029
+ className: "nbe-icon-btn",
1030
+ "data-action": "up",
1031
+ disabled: i === 0,
1032
+ onClick: () => move(i, i - 1),
1033
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.ArrowUp, {
1034
+ "aria-hidden": true,
1035
+ size: 16
1036
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1037
+ className: "nbe-sr-only",
1038
+ children: t("editor.moveUpItem", n)
1039
+ })]
1040
+ }),
1041
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
1042
+ type: "button",
1043
+ className: "nbe-icon-btn",
1044
+ "data-action": "down",
1045
+ disabled: i === list.length - 1,
1046
+ onClick: () => move(i, i + 1),
1047
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.ArrowDown, {
1048
+ "aria-hidden": true,
1049
+ size: 16
1050
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1051
+ className: "nbe-sr-only",
1052
+ children: t("editor.moveDownItem", n)
1053
+ })]
1054
+ }),
1055
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
1056
+ type: "button",
1057
+ className: "nbe-icon-btn",
1058
+ "data-action": "duplicate",
1059
+ disabled: list.length >= max,
1060
+ onClick: () => duplicate(i),
1061
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Copy, {
1062
+ "aria-hidden": true,
1063
+ size: 16
1064
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1065
+ className: "nbe-sr-only",
1066
+ children: t("editor.duplicateItem", n)
1067
+ })]
1068
+ }),
1069
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
1070
+ type: "button",
1071
+ className: "nbe-icon-btn nbe-icon-btn--danger",
1072
+ "data-action": "remove",
1073
+ disabled: list.length <= min,
1074
+ onClick: () => remove(i),
1075
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Trash2, {
1076
+ "aria-hidden": true,
1077
+ size: 16
1078
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1079
+ className: "nbe-sr-only",
1080
+ children: t("editor.removeItem", n)
1081
+ })]
1082
+ })
1083
+ ]
1084
+ })
1085
+ ]
1086
+ }), !scalarItems && open && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1087
+ className: "nbe-item__body",
1088
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
1089
+ field: {
1090
+ key: String(i),
1091
+ node: Item,
1092
+ required: true
1093
+ },
1094
+ path: itemPath,
1095
+ value: item,
1096
+ depth: depth + 1,
1097
+ bare: true
1098
+ })
1099
+ })]
1100
+ }, i);
1101
+ })
1102
+ }),
1103
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
1104
+ ref: addRef,
1105
+ type: "button",
1106
+ className: "nbe-btn nbe-btn--dashed",
1107
+ disabled: list.length >= max,
1108
+ onClick: add,
1109
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Plus, {
1110
+ "aria-hidden": true,
1111
+ size: 14
1112
+ }), t("editor.add", { item: itemName })]
1113
+ })
1114
+ ]
1115
+ });
1116
+ }
1117
+ function UnionField({ node, path, value, label, required, depth }) {
1118
+ const { formId, update } = useForm();
1119
+ const t = useEditorT();
1120
+ if (node.kind !== "union") return null;
1121
+ const disc = node.discriminator;
1122
+ const current = disc && isRecord(value) ? node.variants.findIndex((v) => v.value === value[disc]) : node.variants.findIndex((v) => v.node.kind === typeof value);
1123
+ const index = current >= 0 ? current : 0;
1124
+ const variant = node.variants[index];
1125
+ const selectId = `${fieldId(formId, path)}-variant`;
1126
+ if (value === void 0 && !required) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(OptionalAdd, {
1127
+ label,
1128
+ onAdd: () => update(path, defaultFor(variant.node))
1129
+ });
1130
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("fieldset", {
1131
+ className: "nbe-group",
1132
+ children: [
1133
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("legend", {
1134
+ className: "nbe-group__legend",
1135
+ children: label
1136
+ }),
1137
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1138
+ className: "nbe-field",
1139
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", {
1140
+ className: "nbe-field__label",
1141
+ htmlFor: selectId,
1142
+ children: t("editor.variant")
1143
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("select", {
1144
+ id: selectId,
1145
+ className: "nbe-input",
1146
+ value: index,
1147
+ onChange: (e) => update(path, defaultFor(node.variants[Number(e.target.value)].node)),
1148
+ children: node.variants.map((v, i) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
1149
+ value: i,
1150
+ children: v.value ? (0, _nibblearn_react.humanizeKey)(v.value) : v.label
1151
+ }, i))
1152
+ })]
1153
+ }),
1154
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
1155
+ field: {
1156
+ key: label,
1157
+ node: variant.node,
1158
+ required: true
1159
+ },
1160
+ path,
1161
+ value,
1162
+ depth: depth + 1,
1163
+ bare: true
1164
+ })
1165
+ ]
1166
+ });
1167
+ }
1168
+ function RecordField({ node, path, value, label, required }) {
1169
+ const { formId, update } = useForm();
1170
+ const t = useEditorT();
1171
+ if (node.kind !== "record") return null;
1172
+ const obj = isRecord(value) ? value : {};
1173
+ const entries = Object.entries(obj);
1174
+ const numeric = node.value.kind === "number";
1175
+ const setEntry = (oldKey, newKey, v) => {
1176
+ const next = {};
1177
+ for (const [k, val] of entries) if (k === oldKey) {
1178
+ if (newKey && ![
1179
+ "__proto__",
1180
+ "constructor",
1181
+ "prototype"
1182
+ ].includes(newKey)) next[newKey] = v;
1183
+ } else next[k] = val;
1184
+ update(path, Object.keys(next).length || required ? next : void 0);
1185
+ };
1186
+ const base = fieldId(formId, path);
1187
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("fieldset", {
1188
+ className: "nbe-group",
1189
+ children: [
1190
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("legend", {
1191
+ className: "nbe-group__legend",
1192
+ children: label
1193
+ }),
1194
+ node.description && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
1195
+ className: "nbe-field__help",
1196
+ children: node.description
1197
+ }),
1198
+ entries.map(([k, v], i) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1199
+ className: "nbe-row nbe-record",
1200
+ children: [
1201
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
1202
+ className: "nbe-sr-only",
1203
+ htmlFor: `${base}-k${i}`,
1204
+ children: [
1205
+ t("editor.record.key"),
1206
+ " ",
1207
+ i + 1
1208
+ ]
1209
+ }),
1210
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1211
+ id: `${base}-k${i}`,
1212
+ className: "nbe-input",
1213
+ value: k,
1214
+ onChange: (e) => setEntry(k, e.target.value, v)
1215
+ }),
1216
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
1217
+ className: "nbe-sr-only",
1218
+ htmlFor: `${base}-v${i}`,
1219
+ children: [
1220
+ t("editor.record.value"),
1221
+ " ",
1222
+ i + 1
1223
+ ]
1224
+ }),
1225
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1226
+ id: `${base}-v${i}`,
1227
+ className: "nbe-input",
1228
+ type: numeric ? "number" : "text",
1229
+ value: typeof v === "number" || typeof v === "string" ? v : "",
1230
+ onChange: (e) => setEntry(k, k, numeric ? Number(e.target.value) : e.target.value)
1231
+ }),
1232
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
1233
+ type: "button",
1234
+ className: "nbe-icon-btn nbe-icon-btn--danger",
1235
+ onClick: () => setEntry(k, "", void 0),
1236
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Trash2, {
1237
+ "aria-hidden": true,
1238
+ size: 16
1239
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
1240
+ className: "nbe-sr-only",
1241
+ children: [
1242
+ t("editor.remove"),
1243
+ " ",
1244
+ k
1245
+ ]
1246
+ })]
1247
+ })
1248
+ ]
1249
+ }, i)),
1250
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
1251
+ type: "button",
1252
+ className: "nbe-btn nbe-btn--dashed",
1253
+ onClick: () => update(path, {
1254
+ ...obj,
1255
+ [uniqueId("key", Object.keys(obj))]: numeric ? 0 : ""
1256
+ }),
1257
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Plus, {
1258
+ "aria-hidden": true,
1259
+ size: 14
1260
+ }), t("editor.record.add")]
1261
+ })
1262
+ ]
1263
+ });
1264
+ }
1265
+ function Field({ field, path, value, depth, bare }) {
1266
+ const { node, key, required } = field;
1267
+ const props = {
1268
+ node,
1269
+ path,
1270
+ value,
1271
+ label: useLabel(path, node, key),
1272
+ required,
1273
+ depth
1274
+ };
1275
+ const w = node.ui.widget;
1276
+ if (w === "hidden" || node.kind === "const") return null;
1277
+ if (w === "image") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ImageField, { ...props });
1278
+ if (w === "json") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(JsonField, { ...props });
1279
+ switch (node.kind) {
1280
+ case "string":
1281
+ if (node.enum || w === "select") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SelectField, { ...props });
1282
+ if (w === "color") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ColorField, { ...props });
1283
+ if (w === "richtext" || w === "richtext-block") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RichTextField, { ...props });
1284
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(TextField, { ...props });
1285
+ case "number": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(NumberField, { ...props });
1286
+ case "boolean": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(SwitchField, { ...props });
1287
+ case "object": return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [bare ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(BareObject, { ...props }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ObjectField, { ...props }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ContainerErrors, { path })] });
1288
+ case "array": return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(ArrayField, { ...props }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ContainerErrors, { path })] });
1289
+ case "union": return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(UnionField, { ...props }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ContainerErrors, { path })] });
1290
+ case "record": return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(RecordField, { ...props }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ContainerErrors, { path })] });
1291
+ default: return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(JsonField, { ...props });
1292
+ }
1293
+ }
1294
+ /**
1295
+ * Problems reported for a list or group itself (too few items, duplicate ids, cross-field
1296
+ * rules). It carries the field id, so "go to" in the issue summary lands here.
1297
+ */
1298
+ function ContainerErrors({ path }) {
1299
+ const { formId, issuesAt } = useForm();
1300
+ const errors = issuesAt(path);
1301
+ if (errors.length === 0) return null;
1302
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
1303
+ className: "nbe-field__error nbe-field__error--group",
1304
+ id: fieldId(formId, path),
1305
+ tabIndex: -1,
1306
+ children: errors.join(" ")
1307
+ });
1308
+ }
1309
+ /** An object's fields without a fieldset (inside an array item or a union variant). */
1310
+ function BareObject({ node, path, value, depth }) {
1311
+ const t = useEditorT();
1312
+ if (node.kind !== "object") return null;
1313
+ const obj = isRecord(value) ? value : {};
1314
+ const visible = node.fields.filter((f) => f.node.ui.widget !== "hidden" && f.node.kind !== "const");
1315
+ const ids = visible.filter((f) => f.node.ui.widget === "id");
1316
+ const rest = visible.filter((f) => f.node.ui.widget !== "id");
1317
+ const render = (f) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
1318
+ field: f,
1319
+ path: [...path, f.key],
1320
+ value: Object.prototype.hasOwnProperty.call(obj, f.key) ? obj[f.key] : void 0,
1321
+ depth: depth + 1
1322
+ }, f.key);
1323
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [rest.map(render), ids.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("details", {
1324
+ className: "nbe-advanced",
1325
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("summary", { children: t("editor.group.advanced") }), ids.map(render)]
1326
+ })] });
1327
+ }
1328
+ // src/form/schema.ts
1329
+ var types = (s) => Array.isArray(s.type) ? s.type : s.type ? [s.type] : [];
1330
+ var isNullSchema = (s) => types(s).length === 1 && types(s)[0] === "null";
1331
+ function meta(s, node, extra = {}) {
1332
+ return {
1333
+ ...node,
1334
+ title: s.title,
1335
+ description: s.description,
1336
+ default: s.default,
1337
+ ui: { ...s["x-ui"] ?? {} },
1338
+ ...extra
1339
+ };
1340
+ }
1341
+ /** The property every variant fixes with `const`, if any. */
1342
+ function discriminatorOf(variants) {
1343
+ const first = variants[0]?.properties;
1344
+ if (!first) return void 0;
1345
+ return Object.keys(first).find((k) => variants.every((v) => v.properties?.[k] && v.properties[k].const !== void 0));
1346
+ }
1347
+ /** Normalise a JSON Schema (as produced by `getModuleJsonSchema`) into a form tree. */
1348
+ function toFormNode(schema, depth = 0) {
1349
+ const s = schema;
1350
+ if (depth > 40) return meta(s, { kind: "unknown" });
1351
+ const alternatives = s.oneOf ?? s.anyOf;
1352
+ if (alternatives) {
1353
+ const real = alternatives.filter((a) => !isNullSchema(a));
1354
+ const nullable = real.length < alternatives.length;
1355
+ if (real.length === 1) {
1356
+ const inner = toFormNode({
1357
+ ...real[0],
1358
+ title: s.title ?? real[0].title,
1359
+ description: s.description ?? real[0].description,
1360
+ "x-ui": {
1361
+ ...real[0]["x-ui"] ?? {},
1362
+ ...s["x-ui"] ?? {}
1363
+ }
1364
+ }, depth + 1);
1365
+ return {
1366
+ ...inner,
1367
+ nullable: nullable || inner.nullable,
1368
+ default: s.default ?? inner.default
1369
+ };
1370
+ }
1371
+ const discriminator = discriminatorOf(real);
1372
+ return meta(s, {
1373
+ kind: "union",
1374
+ discriminator,
1375
+ variants: real.map((v, i) => {
1376
+ const value = discriminator ? String(v.properties[discriminator].const) : void 0;
1377
+ return {
1378
+ label: v.title ?? value ?? `Option ${i + 1}`,
1379
+ value,
1380
+ node: toFormNode(v, depth + 1)
1381
+ };
1382
+ })
1383
+ }, { nullable });
1384
+ }
1385
+ if (s.const !== void 0) return meta(s, {
1386
+ kind: "const",
1387
+ value: s.const
1388
+ });
1389
+ const t = types(s).filter((x) => x !== "null");
1390
+ const nullable = types(s).includes("null");
1391
+ if (s.enum && s.enum.every((v) => typeof v === "string")) return meta(s, {
1392
+ kind: "string",
1393
+ enum: s.enum
1394
+ }, { nullable });
1395
+ switch (t[0]) {
1396
+ case "string": return meta(s, {
1397
+ kind: "string",
1398
+ maxLength: s.maxLength,
1399
+ minLength: s.minLength,
1400
+ pattern: s.pattern
1401
+ }, { nullable });
1402
+ case "number":
1403
+ case "integer": {
1404
+ const minExclusive = s.minimum === void 0 && s.exclusiveMinimum !== void 0;
1405
+ const min = minExclusive ? s.exclusiveMinimum : s.minimum;
1406
+ const maxInclusive = s.maximum !== void 0 && s.maximum < Number.MAX_SAFE_INTEGER;
1407
+ const maxExclusive = !maxInclusive && s.exclusiveMaximum !== void 0;
1408
+ const max = maxInclusive ? s.maximum : s.exclusiveMaximum;
1409
+ return meta(s, {
1410
+ kind: "number",
1411
+ integer: t[0] === "integer",
1412
+ min,
1413
+ max,
1414
+ step: s.multipleOf,
1415
+ ...minExclusive ? { minExclusive } : {},
1416
+ ...maxExclusive ? { maxExclusive } : {}
1417
+ }, { nullable });
1418
+ }
1419
+ case "boolean": return meta(s, { kind: "boolean" }, { nullable });
1420
+ case "array": return meta(s, {
1421
+ kind: "array",
1422
+ item: toFormNode(s.items ?? {}, depth + 1),
1423
+ minItems: s.minItems,
1424
+ maxItems: s.maxItems
1425
+ }, { nullable });
1426
+ case "object":
1427
+ if (s.properties) {
1428
+ const required = new Set(s.required ?? []);
1429
+ return meta(s, {
1430
+ kind: "object",
1431
+ fields: Object.entries(s.properties).map(([key, child]) => ({
1432
+ key,
1433
+ node: toFormNode(child, depth + 1),
1434
+ required: required.has(key)
1435
+ }))
1436
+ }, { nullable });
1437
+ }
1438
+ if (s.additionalProperties && typeof s.additionalProperties === "object") return meta(s, {
1439
+ kind: "record",
1440
+ value: toFormNode(s.additionalProperties, depth + 1)
1441
+ }, { nullable });
1442
+ return meta(s, { kind: "unknown" }, { nullable });
1443
+ default: return meta(s, { kind: "unknown" });
1444
+ }
1445
+ }
1446
+ // src/ModuleForm.tsx
1447
+ /**
1448
+ * A form for any registered module, generated from its JSON Schema (field titles, hints and
1449
+ * widgets come from the schema's `x-ui` metadata). Fully controlled.
1450
+ */
1451
+ function ModuleForm({ value, onChange, issues, registry = _nibblearn_react.defaultRegistry, onFocusPath, onPickImage, schema: schemaOverride, className }) {
1452
+ const t = useEditorT();
1453
+ const type = String(value.type ?? "");
1454
+ const schema = (0, react.useMemo)(() => schemaOverride ?? (0, _nibblearn_react.getModuleJsonSchema)(type, { registry: registry.schemas }), [
1455
+ schemaOverride,
1456
+ type,
1457
+ registry
1458
+ ]);
1459
+ const root = (0, react.useMemo)(() => schema ? toFormNode(schema) : null, [schema]);
1460
+ const formId = `nbe${(0, react.useId)().replace(/[^a-zA-Z0-9]/g, "")}`;
1461
+ const { message, announce } = (0, _nibblearn_react.useAnnounce)();
1462
+ const issueIndex = (0, react.useMemo)(() => issueMap(issues), [issues]);
1463
+ const committed = (0, react.useRef)(value);
1464
+ const pending = (0, react.useRef)(null);
1465
+ (0, react.useEffect)(() => {
1466
+ committed.current = value;
1467
+ });
1468
+ const update = (0, react.useCallback)((path, next) => {
1469
+ const updated = setAt(pending.current ? pending.current.value : committed.current, path, next);
1470
+ if (!pending.current) queueMicrotask(() => pending.current = null);
1471
+ pending.current = { value: updated };
1472
+ onChange(updated);
1473
+ }, [onChange]);
1474
+ const ctx = (0, react.useMemo)(() => ({
1475
+ formId,
1476
+ type,
1477
+ root: value,
1478
+ update,
1479
+ issuesAt: (path) => issueIndex.get(pathKey(path)) ?? [],
1480
+ onFocusPath,
1481
+ onPickImage,
1482
+ announce
1483
+ }), [
1484
+ formId,
1485
+ type,
1486
+ value,
1487
+ update,
1488
+ issueIndex,
1489
+ onFocusPath,
1490
+ onPickImage,
1491
+ announce
1492
+ ]);
1493
+ if (!root) return null;
1494
+ const focusField = (issue) => {
1495
+ const segments = issue.segments ?? [];
1496
+ for (let n = segments.length; n >= 0; n--) {
1497
+ const el = document.getElementById(fieldId(formId, segments.slice(0, n)));
1498
+ if (el) {
1499
+ el.focus();
1500
+ el.scrollIntoView?.({ block: "center" });
1501
+ return;
1502
+ }
1503
+ }
1504
+ };
1505
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FormContext.Provider, {
1506
+ value: ctx,
1507
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1508
+ className: ["nbe-form", className].filter(Boolean).join(" "),
1509
+ children: [
1510
+ issues && issues.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1511
+ className: "nbe-issues",
1512
+ role: "group",
1513
+ "aria-labelledby": `${formId}-issues`,
1514
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("p", {
1515
+ className: "nbe-issues__title",
1516
+ id: `${formId}-issues`,
1517
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.AlertCircle, {
1518
+ "aria-hidden": true,
1519
+ size: 16
1520
+ }), t("editor.issues.title", { count: issues.length })]
1521
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("ul", {
1522
+ className: "nbe-issues__list",
1523
+ children: issues.slice(0, 12).map((issue, i) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("li", { children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
1524
+ type: "button",
1525
+ className: "nbe-link",
1526
+ onClick: () => focusField(issue),
1527
+ children: [
1528
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", { children: issue.path }),
1529
+ ": ",
1530
+ issue.message
1531
+ ]
1532
+ }) }, i))
1533
+ })]
1534
+ }),
1535
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Field, {
1536
+ field: {
1537
+ key: type,
1538
+ node: root,
1539
+ required: true
1540
+ },
1541
+ path: [],
1542
+ value,
1543
+ depth: 0
1544
+ }),
1545
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_nibblearn_react.LiveRegion, { message })
1546
+ ]
1547
+ })
1548
+ });
1549
+ }
1550
+ // src/ModuleEditor.tsx
1551
+ /** A module form with a live preview that follows the item being edited. */
1552
+ function ModuleEditor({ layout = "split", onValidityChange, ...form }) {
1553
+ const t = useEditorT();
1554
+ const registry = form.registry ?? _nibblearn_react.defaultRegistry;
1555
+ const result = (0, react.useMemo)(() => (0, _nibblearn_react.validateModule)(form.value, { registry: registry.schemas }), [form.value, registry]);
1556
+ const issues = result.success ? [] : result.issues;
1557
+ const [lastValid, setLastValid] = (0, react.useState)(() => result.success ? result.data : null);
1558
+ if (result.success && result.data !== lastValid) setLastValid(result.data);
1559
+ const [focusPath, setFocusPath] = (0, react.useState)(null);
1560
+ (0, react.useEffect)(() => {
1561
+ onValidityChange?.({
1562
+ valid: result.success,
1563
+ issues
1564
+ });
1565
+ }, [result.success, JSON.stringify(issues)]);
1566
+ const preview = lastValid ?? null;
1567
+ const rootProps = (0, _nibblearn_react.useRootProps)();
1568
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1569
+ className: "nbe-root nb-theme",
1570
+ ...rootProps,
1571
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1572
+ className: `nbe-editor nbe-editor--${layout}`,
1573
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1574
+ className: "nbe-editor__form",
1575
+ "aria-label": t("editor.form"),
1576
+ role: "region",
1577
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ModuleForm, {
1578
+ ...form,
1579
+ registry,
1580
+ issues,
1581
+ onFocusPath: setFocusPath
1582
+ })
1583
+ }), layout !== "form" && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1584
+ className: "nbe-editor__preview",
1585
+ role: "region",
1586
+ "aria-label": t("editor.preview"),
1587
+ children: [!result.success && preview && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
1588
+ className: "nbe-note",
1589
+ children: t("editor.preview.lastValid")
1590
+ }), preview && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_nibblearn_react.ModuleRenderer, {
1591
+ config: preview,
1592
+ registry,
1593
+ mode: "preview",
1594
+ focus: focusPath ? { path: focusPath } : null
1595
+ })]
1596
+ })]
1597
+ })
1598
+ });
1599
+ }
1600
+ // src/BlockPicker.tsx
1601
+ var CATEGORY_ORDER = [
1602
+ "learn",
1603
+ "practice",
1604
+ "explore",
1605
+ "decide",
1606
+ "simulate",
1607
+ "present"
1608
+ ];
1609
+ var isBuiltIn = (type) => _nibblearn_react.builtInModuleTypes.includes(type);
1610
+ /** A searchable catalogue of block types that creates ready-to-edit configs. */
1611
+ function BlockPicker({ registry = _nibblearn_react.defaultRegistry, onPick, existingIds = [], defaultFrom = "example" }) {
1612
+ const t = useEditorT();
1613
+ const id = (0, react.useId)().replace(/[^a-zA-Z0-9]/g, "");
1614
+ const [query, setQuery] = (0, react.useState)("");
1615
+ const [from, setFrom] = (0, react.useState)(defaultFrom);
1616
+ const groups = (0, react.useMemo)(() => {
1617
+ const q = query.trim().toLowerCase();
1618
+ const defs = registry.list().filter((d) => !q || d.name.toLowerCase().includes(q) || d.description.toLowerCase().includes(q) || d.type.includes(q));
1619
+ return [...CATEGORY_ORDER, ...new Set(defs.map((d) => d.category))].filter((c, i, a) => a.indexOf(c) === i).map((c) => ({
1620
+ category: c,
1621
+ defs: defs.filter((d) => d.category === c)
1622
+ })).filter((g) => g.defs.length);
1623
+ }, [registry, query]);
1624
+ const pick = (type) => {
1625
+ const newId = uniqueId(type, existingIds);
1626
+ onPick(isBuiltIn(type) ? from === "example" ? (0, _nibblearn_core_examples.createExample)(type, { id: newId }) : (0, _nibblearn_core_examples.createEmpty)(type, { id: newId }) : {
1627
+ id: newId,
1628
+ type
1629
+ }, {
1630
+ type,
1631
+ from
1632
+ });
1633
+ };
1634
+ const rootProps = (0, _nibblearn_react.useRootProps)();
1635
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1636
+ className: "nbe-root nb-theme nbe-picker",
1637
+ ...rootProps,
1638
+ children: [
1639
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h2", {
1640
+ className: "nbe-picker__title",
1641
+ children: t("editor.picker.title")
1642
+ }),
1643
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1644
+ className: "nbe-picker__controls",
1645
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1646
+ className: "nbe-search",
1647
+ children: [
1648
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Search, {
1649
+ "aria-hidden": true,
1650
+ size: 16
1651
+ }),
1652
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", {
1653
+ className: "nbe-sr-only",
1654
+ htmlFor: `${id}-q`,
1655
+ children: t("editor.picker.search")
1656
+ }),
1657
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1658
+ id: `${id}-q`,
1659
+ type: "search",
1660
+ className: "nbe-input",
1661
+ placeholder: t("editor.picker.search"),
1662
+ value: query,
1663
+ onChange: (e) => setQuery(e.target.value)
1664
+ })
1665
+ ]
1666
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("fieldset", {
1667
+ className: "nbe-segmented",
1668
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("legend", {
1669
+ className: "nbe-sr-only",
1670
+ children: t("editor.picker.start")
1671
+ }), ["example", "empty"].map((v) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
1672
+ className: "nbe-segmented__option",
1673
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
1674
+ type: "radio",
1675
+ name: `${id}-from`,
1676
+ value: v,
1677
+ checked: from === v,
1678
+ onChange: () => setFrom(v)
1679
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: t(v === "example" ? "editor.picker.example" : "editor.picker.blank") })]
1680
+ }, v))]
1681
+ })]
1682
+ }),
1683
+ groups.length === 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
1684
+ className: "nbe-note",
1685
+ children: t("editor.picker.empty", { query })
1686
+ }),
1687
+ groups.map((g) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
1688
+ className: "nbe-picker__group",
1689
+ "aria-labelledby": `${id}-${g.category}`,
1690
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", {
1691
+ className: "nbe-picker__category",
1692
+ id: `${id}-${g.category}`,
1693
+ children: t(`editor.category.${g.category}`)
1694
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("ul", {
1695
+ className: "nbe-picker__list",
1696
+ children: g.defs.map((d) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("li", { children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
1697
+ type: "button",
1698
+ className: "nbe-block",
1699
+ onClick: () => pick(d.type),
1700
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1701
+ className: "nbe-block__icon",
1702
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_nibblearn_react.ModuleIcon, {
1703
+ type: d.type,
1704
+ registry,
1705
+ size: 20
1706
+ })
1707
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
1708
+ className: "nbe-block__text",
1709
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1710
+ className: "nbe-block__name",
1711
+ children: d.name
1712
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1713
+ className: "nbe-block__desc",
1714
+ children: d.description
1715
+ })]
1716
+ })]
1717
+ }) }, d.type))
1718
+ })]
1719
+ }, g.category))
1720
+ ]
1721
+ });
1722
+ }
1723
+ // src/LessonEditor.tsx
1724
+ /** Edit a whole lesson: the list of blocks, each block's settings with preview, and lesson settings. */
1725
+ function LessonEditor({ value, onChange, registry = _nibblearn_react.defaultRegistry, onPickImage }) {
1726
+ const t = useEditorT();
1727
+ const id = (0, react.useId)().replace(/[^a-zA-Z0-9]/g, "");
1728
+ const modules = Array.isArray(value.modules) ? value.modules : [];
1729
+ const [selected, setSelected] = (0, react.useState)(modules.length ? 0 : "add");
1730
+ const index = typeof selected === "number" && modules.length ? Math.min(selected, modules.length - 1) : -1;
1731
+ const current = index >= 0 ? modules[index] : void 0;
1732
+ const settingsSchema = (0, react.useMemo)(() => {
1733
+ const s = (0, _nibblearn_react.getLessonJsonSchema)({ registry: registry.schemas });
1734
+ const { modules: _modules, schemaVersion: _version, ...properties } = s.properties;
1735
+ return {
1736
+ ...s,
1737
+ properties,
1738
+ required: (s.required ?? []).filter((k) => k !== "modules" && k !== "schemaVersion")
1739
+ };
1740
+ }, [registry]);
1741
+ const [generation, setGeneration] = (0, react.useState)(0);
1742
+ const [own, setOwn] = (0, react.useState)(null);
1743
+ const [seen, setSeen] = (0, react.useState)(value);
1744
+ if (seen !== value) {
1745
+ setSeen(value);
1746
+ if (value !== own) setGeneration((g) => g + 1);
1747
+ }
1748
+ const latest = (0, react.useRef)({
1749
+ value,
1750
+ generation
1751
+ });
1752
+ (0, react.useEffect)(() => {
1753
+ latest.current = {
1754
+ value,
1755
+ generation
1756
+ };
1757
+ });
1758
+ const emit = (next) => {
1759
+ setOwn(next);
1760
+ onChange(next);
1761
+ };
1762
+ const setModules = (next, structural = false) => {
1763
+ if (structural) setGeneration((g) => g + 1);
1764
+ emit({
1765
+ ...latest.current.value,
1766
+ modules: next
1767
+ });
1768
+ };
1769
+ const ids = modules.map((m) => String(m.id ?? ""));
1770
+ const lessonIssues = (0, react.useMemo)(() => {
1771
+ const r = (0, _nibblearn_react.validateLesson)(value, { registry: registry.schemas });
1772
+ return r.success ? [] : r.issues;
1773
+ }, [value, registry]);
1774
+ const blockOf = (i) => i.segments?.[0] === "modules" && typeof i.segments[1] === "number" ? i.segments[1] : -1;
1775
+ const settingsIssues = lessonIssues.filter((i) => blockOf(i) < 0);
1776
+ const hasIssues = (b) => lessonIssues.some((i) => blockOf(i) === b);
1777
+ const ownIssues = current ? (0, _nibblearn_react.validateModule)(current, { registry: registry.schemas }) : null;
1778
+ const known = new Set(ownIssues && !ownIssues.success ? ownIssues.issues.map((i) => i.message) : []);
1779
+ const currentExtra = current ? lessonIssues.filter((i) => blockOf(i) === index && !known.has(i.message)) : [];
1780
+ const nameOf = (m) => (typeof m.title === "string" && m.title ? (0, _nibblearn_react.stripMarkup)(m.title) : void 0) ?? registry.get(String(m.type))?.name ?? String(m.type);
1781
+ const move = (i, to) => {
1782
+ if (to < 0 || to >= modules.length) return;
1783
+ const next = [...modules];
1784
+ const [m] = next.splice(i, 1);
1785
+ next.splice(to, 0, m);
1786
+ setModules(next, true);
1787
+ setSelected(to);
1788
+ };
1789
+ const duplicate = (i) => {
1790
+ const copy = structuredClone(modules[i]);
1791
+ copy.id = uniqueId(String(copy.id ?? copy.type ?? "block").replace(/-\d+$/, ""), ids);
1792
+ const next = [...modules];
1793
+ next.splice(i + 1, 0, copy);
1794
+ setModules(next, true);
1795
+ setSelected(i + 1);
1796
+ };
1797
+ const remove = (i) => {
1798
+ setModules(modules.filter((_, j) => j !== i), true);
1799
+ setSelected(modules.length > 1 ? Math.max(0, i - 1) : "add");
1800
+ };
1801
+ const rootProps = (0, _nibblearn_react.useRootProps)();
1802
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1803
+ className: "nbe-root nb-theme",
1804
+ ...rootProps,
1805
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1806
+ className: "nbe-lesson",
1807
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("nav", {
1808
+ className: "nbe-lesson__nav",
1809
+ "aria-labelledby": `${id}-blocks`,
1810
+ children: [
1811
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h2", {
1812
+ className: "nbe-lesson__heading",
1813
+ id: `${id}-blocks`,
1814
+ children: t("editor.lesson.modules")
1815
+ }),
1816
+ modules.length === 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
1817
+ className: "nbe-note",
1818
+ children: t("editor.lesson.empty")
1819
+ }),
1820
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("ol", {
1821
+ className: "nbe-lesson__list",
1822
+ children: modules.map((m, i) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("li", {
1823
+ className: "nbe-lesson__item",
1824
+ "data-selected": selected === i || void 0,
1825
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
1826
+ type: "button",
1827
+ className: "nbe-lesson__select",
1828
+ "aria-current": selected === i ? "true" : void 0,
1829
+ onClick: () => setSelected(i),
1830
+ children: [
1831
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_nibblearn_react.ModuleIcon, {
1832
+ type: String(m.type),
1833
+ registry,
1834
+ size: 16
1835
+ }),
1836
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1837
+ className: "nbe-lesson__name",
1838
+ children: nameOf(m)
1839
+ }),
1840
+ hasIssues(i) && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.AlertCircle, {
1841
+ "aria-hidden": true,
1842
+ size: 14,
1843
+ className: "nbe-lesson__issue"
1844
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
1845
+ className: "nbe-sr-only",
1846
+ children: [", ", t("editor.lesson.hasIssues")]
1847
+ })] }),
1848
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1849
+ className: "nbe-sr-only",
1850
+ children: t("editor.lesson.position", {
1851
+ current: i + 1,
1852
+ total: modules.length
1853
+ })
1854
+ })
1855
+ ]
1856
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
1857
+ className: "nbe-lesson__actions",
1858
+ children: [
1859
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
1860
+ type: "button",
1861
+ className: "nbe-icon-btn",
1862
+ disabled: i === 0,
1863
+ onClick: () => move(i, i - 1),
1864
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.ArrowUp, {
1865
+ "aria-hidden": true,
1866
+ size: 14
1867
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1868
+ className: "nbe-sr-only",
1869
+ children: t("editor.moveUpItem", {
1870
+ item: nameOf(m),
1871
+ index: ""
1872
+ })
1873
+ })]
1874
+ }),
1875
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
1876
+ type: "button",
1877
+ className: "nbe-icon-btn",
1878
+ disabled: i === modules.length - 1,
1879
+ onClick: () => move(i, i + 1),
1880
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.ArrowDown, {
1881
+ "aria-hidden": true,
1882
+ size: 14
1883
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1884
+ className: "nbe-sr-only",
1885
+ children: t("editor.moveDownItem", {
1886
+ item: nameOf(m),
1887
+ index: ""
1888
+ })
1889
+ })]
1890
+ }),
1891
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
1892
+ type: "button",
1893
+ className: "nbe-icon-btn",
1894
+ onClick: () => duplicate(i),
1895
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Copy, {
1896
+ "aria-hidden": true,
1897
+ size: 14
1898
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1899
+ className: "nbe-sr-only",
1900
+ children: t("editor.duplicateItem", {
1901
+ item: nameOf(m),
1902
+ index: ""
1903
+ })
1904
+ })]
1905
+ }),
1906
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
1907
+ type: "button",
1908
+ className: "nbe-icon-btn nbe-icon-btn--danger",
1909
+ disabled: modules.length <= 1,
1910
+ onClick: () => remove(i),
1911
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Trash2, {
1912
+ "aria-hidden": true,
1913
+ size: 14
1914
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
1915
+ className: "nbe-sr-only",
1916
+ children: t("editor.removeItem", {
1917
+ item: nameOf(m),
1918
+ index: ""
1919
+ })
1920
+ })]
1921
+ })
1922
+ ]
1923
+ })]
1924
+ }, `${String(m.id)}-${i}`))
1925
+ }),
1926
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1927
+ className: "nbe-lesson__nav-actions",
1928
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
1929
+ type: "button",
1930
+ className: "nbe-btn nbe-btn--dashed",
1931
+ "aria-pressed": selected === "add",
1932
+ onClick: () => setSelected("add"),
1933
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Plus, {
1934
+ "aria-hidden": true,
1935
+ size: 14
1936
+ }), t("editor.lesson.addBlock")]
1937
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
1938
+ type: "button",
1939
+ className: "nbe-btn",
1940
+ "aria-pressed": selected === "settings",
1941
+ onClick: () => setSelected("settings"),
1942
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.Settings, {
1943
+ "aria-hidden": true,
1944
+ size: 14
1945
+ }), t("editor.lesson.settings")]
1946
+ })]
1947
+ })
1948
+ ]
1949
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1950
+ className: "nbe-lesson__main",
1951
+ children: [
1952
+ selected === "settings" && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("section", {
1953
+ "aria-labelledby": `${id}-settings`,
1954
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("h2", {
1955
+ className: "nbe-lesson__heading",
1956
+ id: `${id}-settings`,
1957
+ children: t("editor.lesson.settings")
1958
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ModuleForm, {
1959
+ value,
1960
+ onChange: (next) => emit({
1961
+ ...next,
1962
+ modules: latest.current.value.modules,
1963
+ schemaVersion: latest.current.value.schemaVersion ?? 1
1964
+ }),
1965
+ schema: settingsSchema,
1966
+ registry,
1967
+ onPickImage,
1968
+ issues: settingsIssues
1969
+ })]
1970
+ }),
1971
+ selected === "add" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(BlockPicker, {
1972
+ registry,
1973
+ existingIds: ids,
1974
+ onPick: (config) => {
1975
+ setModules([...modules, config], true);
1976
+ setSelected(modules.length);
1977
+ }
1978
+ }),
1979
+ current && typeof selected === "number" && currentExtra.length > 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1980
+ className: "nbe-issues",
1981
+ role: "group",
1982
+ "aria-label": t("editor.lesson.blockIssues"),
1983
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("ul", {
1984
+ className: "nbe-issues__list",
1985
+ children: currentExtra.map((issue, k) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("li", { children: [
1986
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", { children: issue.path }),
1987
+ ": ",
1988
+ issue.message
1989
+ ] }, k))
1990
+ })
1991
+ }),
1992
+ current && typeof selected === "number" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ModuleEditor, {
1993
+ value: current,
1994
+ registry,
1995
+ onPickImage,
1996
+ onChange: (next) => {
1997
+ const at = latest.current;
1998
+ if (at.generation !== generation) return;
1999
+ const list = Array.isArray(at.value.modules) ? at.value.modules : [];
2000
+ setModules(list.map((m, j) => j === index ? next : m));
2001
+ }
2002
+ }, `${generation}:${index}`)
2003
+ ]
2004
+ })]
2005
+ })
2006
+ });
2007
+ }
2008
+ exports.BlockPicker = BlockPicker;
2009
+ exports.LessonEditor = LessonEditor;
2010
+ exports.ModuleEditor = ModuleEditor;
2011
+ exports.ModuleForm = ModuleForm;
2012
+ exports.defaultFor = defaultFor;
2013
+ exports.editorMessages = editorMessages;
2014
+ exports.getAt = getAt;
2015
+ exports.insertAt = insertAt;
2016
+ exports.moveItem = moveItem;
2017
+ exports.removeAt = removeAt;
2018
+ exports.setAt = setAt;
2019
+ exports.toFormNode = toFormNode;
2020
+ exports.uniqueId = uniqueId;
2021
+ exports.useEditorT = useEditorT;
2022
+
2023
+ //# sourceMappingURL=index.cjs.map