@namroodinc/liquid-editorial 0.2.1 → 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.
Files changed (179) hide show
  1. package/README.md +26 -1
  2. package/UPGRADING.md +75 -0
  3. package/dist/chunks/{FormEditor-DuW8x78Y.js → FormEditor-DRmPFe2E.js} +100 -102
  4. package/dist/chunks/FormEditor-DRmPFe2E.js.map +1 -0
  5. package/dist/chunks/FormEditor-PVkvKep1.cjs +2 -0
  6. package/dist/chunks/FormEditor-PVkvKep1.cjs.map +1 -0
  7. package/dist/chunks/{RichTextEditor-BxtlbjXj.cjs → RichTextEditor-C7nMfDmE.cjs} +2 -2
  8. package/dist/chunks/RichTextEditor-C7nMfDmE.cjs.map +1 -0
  9. package/dist/chunks/{RichTextEditor-Dnx4i7bQ.js → RichTextEditor-DjR10XJ-.js} +55 -53
  10. package/dist/chunks/RichTextEditor-DjR10XJ-.js.map +1 -0
  11. package/dist/chunks/binding-Bshy43sG.js +33 -0
  12. package/dist/chunks/binding-Bshy43sG.js.map +1 -0
  13. package/dist/chunks/binding-tMjrUzkU.cjs +2 -0
  14. package/dist/chunks/binding-tMjrUzkU.cjs.map +1 -0
  15. package/dist/chunks/context-BONPXF-V.cjs +2 -0
  16. package/dist/chunks/context-BONPXF-V.cjs.map +1 -0
  17. package/dist/chunks/context-CXvOl4Kt.js +7 -0
  18. package/dist/chunks/context-CXvOl4Kt.js.map +1 -0
  19. package/dist/chunks/frame-Bs_jaQRw.js +70 -0
  20. package/dist/chunks/frame-Bs_jaQRw.js.map +1 -0
  21. package/dist/chunks/frame-CNxvbg0D.cjs +2 -0
  22. package/dist/chunks/frame-CNxvbg0D.cjs.map +1 -0
  23. package/dist/chunks/group-CzbacuAY.js +29 -0
  24. package/dist/chunks/group-CzbacuAY.js.map +1 -0
  25. package/dist/chunks/group-pKDQtq-9.cjs +2 -0
  26. package/dist/chunks/group-pKDQtq-9.cjs.map +1 -0
  27. package/dist/components/Badge/index.cjs +1 -1
  28. package/dist/components/Badge/index.cjs.map +1 -1
  29. package/dist/components/Badge/index.d.cts +2 -0
  30. package/dist/components/Badge/index.d.cts.map +1 -1
  31. package/dist/components/Badge/index.d.ts +2 -0
  32. package/dist/components/Badge/index.d.ts.map +1 -1
  33. package/dist/components/Badge/index.js +8 -8
  34. package/dist/components/Badge/index.js.map +1 -1
  35. package/dist/components/Choice/index.cjs +1 -1
  36. package/dist/components/Choice/index.cjs.map +1 -1
  37. package/dist/components/Choice/index.d.cts +3 -3
  38. package/dist/components/Choice/index.d.cts.map +1 -1
  39. package/dist/components/Choice/index.d.ts +3 -3
  40. package/dist/components/Choice/index.d.ts.map +1 -1
  41. package/dist/components/Choice/index.js +27 -27
  42. package/dist/components/Choice/index.js.map +1 -1
  43. package/dist/components/Choice/style.css +0 -7
  44. package/dist/components/DatePicker/index.cjs +1 -1
  45. package/dist/components/DatePicker/index.cjs.map +1 -1
  46. package/dist/components/DatePicker/index.d.cts +5 -9
  47. package/dist/components/DatePicker/index.d.cts.map +1 -1
  48. package/dist/components/DatePicker/index.d.ts +5 -9
  49. package/dist/components/DatePicker/index.d.ts.map +1 -1
  50. package/dist/components/DatePicker/index.js +124 -120
  51. package/dist/components/DatePicker/index.js.map +1 -1
  52. package/dist/components/DatePicker/style.css +15 -1
  53. package/dist/components/EntryPicker/index.cjs +1 -1
  54. package/dist/components/EntryPicker/index.cjs.map +1 -1
  55. package/dist/components/EntryPicker/index.d.cts +3 -2
  56. package/dist/components/EntryPicker/index.d.cts.map +1 -1
  57. package/dist/components/EntryPicker/index.d.ts +3 -2
  58. package/dist/components/EntryPicker/index.d.ts.map +1 -1
  59. package/dist/components/EntryPicker/index.js +39 -46
  60. package/dist/components/EntryPicker/index.js.map +1 -1
  61. package/dist/components/EntryPicker/style.css +0 -11
  62. package/dist/components/Field/binding.d.cts +18 -0
  63. package/dist/components/Field/binding.d.cts.map +1 -0
  64. package/dist/components/Field/binding.d.ts +18 -0
  65. package/dist/components/Field/binding.d.ts.map +1 -0
  66. package/dist/components/Field/context.d.cts +9 -0
  67. package/dist/components/Field/context.d.cts.map +1 -0
  68. package/dist/components/Field/context.d.ts +9 -0
  69. package/dist/components/Field/context.d.ts.map +1 -0
  70. package/dist/components/Field/frame.d.cts +12 -0
  71. package/dist/components/Field/frame.d.cts.map +1 -0
  72. package/dist/components/Field/frame.d.ts +12 -0
  73. package/dist/components/Field/frame.d.ts.map +1 -0
  74. package/dist/components/Field/group.d.cts +12 -0
  75. package/dist/components/Field/group.d.cts.map +1 -0
  76. package/dist/components/Field/group.d.ts +12 -0
  77. package/dist/components/Field/group.d.ts.map +1 -0
  78. package/dist/components/Field/index.cjs +1 -1
  79. package/dist/components/Field/index.cjs.map +1 -1
  80. package/dist/components/Field/index.d.cts +4 -22
  81. package/dist/components/Field/index.d.cts.map +1 -1
  82. package/dist/components/Field/index.d.ts +4 -22
  83. package/dist/components/Field/index.d.ts.map +1 -1
  84. package/dist/components/Field/index.js +5 -42
  85. package/dist/components/Field/index.js.map +1 -1
  86. package/dist/components/Field/style.css +5 -0
  87. package/dist/components/Field/types.d.cts +31 -0
  88. package/dist/components/Field/types.d.cts.map +1 -0
  89. package/dist/components/Field/types.d.ts +31 -0
  90. package/dist/components/Field/types.d.ts.map +1 -0
  91. package/dist/components/FormEditor/control.d.cts +5 -3
  92. package/dist/components/FormEditor/control.d.cts.map +1 -1
  93. package/dist/components/FormEditor/control.d.ts +5 -3
  94. package/dist/components/FormEditor/control.d.ts.map +1 -1
  95. package/dist/components/FormEditor/index.cjs +1 -1
  96. package/dist/components/FormEditor/index.d.cts.map +1 -1
  97. package/dist/components/FormEditor/index.d.ts.map +1 -1
  98. package/dist/components/FormEditor/index.js +1 -1
  99. package/dist/components/FormEditor/model.d.cts +8 -5
  100. package/dist/components/FormEditor/model.d.cts.map +1 -1
  101. package/dist/components/FormEditor/model.d.ts +8 -5
  102. package/dist/components/FormEditor/model.d.ts.map +1 -1
  103. package/dist/components/ImageCropper/index.cjs +1 -1
  104. package/dist/components/ImageCropper/index.cjs.map +1 -1
  105. package/dist/components/ImageCropper/index.d.cts.map +1 -1
  106. package/dist/components/ImageCropper/index.d.ts.map +1 -1
  107. package/dist/components/ImageCropper/index.js +113 -112
  108. package/dist/components/ImageCropper/index.js.map +1 -1
  109. package/dist/components/NumberField/index.cjs +1 -1
  110. package/dist/components/NumberField/index.cjs.map +1 -1
  111. package/dist/components/NumberField/index.d.cts +4 -3
  112. package/dist/components/NumberField/index.d.cts.map +1 -1
  113. package/dist/components/NumberField/index.d.ts +4 -3
  114. package/dist/components/NumberField/index.d.ts.map +1 -1
  115. package/dist/components/NumberField/index.js +57 -53
  116. package/dist/components/NumberField/index.js.map +1 -1
  117. package/dist/components/NumberField/style.css +16 -1
  118. package/dist/components/RichTextEditor/index.cjs +1 -1
  119. package/dist/components/RichTextEditor/index.d.cts +3 -7
  120. package/dist/components/RichTextEditor/index.d.cts.map +1 -1
  121. package/dist/components/RichTextEditor/index.d.ts +3 -7
  122. package/dist/components/RichTextEditor/index.d.ts.map +1 -1
  123. package/dist/components/RichTextEditor/index.js +1 -1
  124. package/dist/components/Select/index.cjs +1 -1
  125. package/dist/components/Select/index.cjs.map +1 -1
  126. package/dist/components/Select/index.d.cts +1 -0
  127. package/dist/components/Select/index.d.cts.map +1 -1
  128. package/dist/components/Select/index.d.ts +1 -0
  129. package/dist/components/Select/index.d.ts.map +1 -1
  130. package/dist/components/Select/index.js +53 -52
  131. package/dist/components/Select/index.js.map +1 -1
  132. package/dist/components/SelectionCard/index.cjs +1 -1
  133. package/dist/components/SelectionCard/index.cjs.map +1 -1
  134. package/dist/components/SelectionCard/index.d.cts +3 -2
  135. package/dist/components/SelectionCard/index.d.cts.map +1 -1
  136. package/dist/components/SelectionCard/index.d.ts +3 -2
  137. package/dist/components/SelectionCard/index.d.ts.map +1 -1
  138. package/dist/components/SelectionCard/index.js +28 -28
  139. package/dist/components/SelectionCard/index.js.map +1 -1
  140. package/dist/components/SelectionCard/style.css +1 -8
  141. package/dist/components/Slider/index.cjs +1 -1
  142. package/dist/components/Slider/index.cjs.map +1 -1
  143. package/dist/components/Slider/index.d.cts +3 -2
  144. package/dist/components/Slider/index.d.cts.map +1 -1
  145. package/dist/components/Slider/index.d.ts +3 -2
  146. package/dist/components/Slider/index.d.ts.map +1 -1
  147. package/dist/components/Slider/index.js +60 -56
  148. package/dist/components/Slider/index.js.map +1 -1
  149. package/dist/components/Slider/style.css +14 -0
  150. package/dist/components/Switch/index.cjs +1 -1
  151. package/dist/components/Switch/index.cjs.map +1 -1
  152. package/dist/components/Switch/index.d.cts +2 -0
  153. package/dist/components/Switch/index.d.cts.map +1 -1
  154. package/dist/components/Switch/index.d.ts +2 -0
  155. package/dist/components/Switch/index.d.ts.map +1 -1
  156. package/dist/components/Switch/index.js +13 -12
  157. package/dist/components/Switch/index.js.map +1 -1
  158. package/dist/components/Switch/style.css +4 -0
  159. package/dist/components/TagsInput/index.cjs +1 -1
  160. package/dist/components/TagsInput/index.cjs.map +1 -1
  161. package/dist/components/TagsInput/index.d.cts +2 -5
  162. package/dist/components/TagsInput/index.d.cts.map +1 -1
  163. package/dist/components/TagsInput/index.d.ts +2 -5
  164. package/dist/components/TagsInput/index.d.ts.map +1 -1
  165. package/dist/components/TagsInput/index.js +19 -17
  166. package/dist/components/TagsInput/index.js.map +1 -1
  167. package/dist/index.cjs +1 -1
  168. package/dist/index.d.cts +1 -1
  169. package/dist/index.d.cts.map +1 -1
  170. package/dist/index.d.ts +1 -1
  171. package/dist/index.d.ts.map +1 -1
  172. package/dist/index.js +7 -7
  173. package/dist/styles.css +1 -1
  174. package/package.json +1 -1
  175. package/dist/chunks/FormEditor-8bz3pOdP.cjs +0 -2
  176. package/dist/chunks/FormEditor-8bz3pOdP.cjs.map +0 -1
  177. package/dist/chunks/FormEditor-DuW8x78Y.js.map +0 -1
  178. package/dist/chunks/RichTextEditor-BxtlbjXj.cjs.map +0 -1
  179. package/dist/chunks/RichTextEditor-Dnx4i7bQ.js.map +0 -1
package/README.md CHANGED
@@ -31,6 +31,31 @@ export function ArticleForm() {
31
31
 
32
32
  `Field.hint` accepts a string or React node, such as `hint={<>Use a <strong>short headline</strong>.</>}`. Hints are associated with the control through `aria-describedby`; an error replaces the hint while present.
33
33
 
34
+ `Field` owns the visible label, required marker, hint and error for every control.
35
+ Spread its render-prop binding onto the interactive component; custom adapters can
36
+ import `FieldBinding` or `FieldRenderProps`. Use `isGroup` for related controls,
37
+ which gives the group a `<fieldset>/<legend>` while retaining each option caption
38
+ and range-member name, following [W3C grouping guidance](https://www.w3.org/WAI/tutorials/forms/grouping/).
39
+ Native inputs receive `required`; custom inputs use supported ARIA semantics.
40
+ Group validation remains with the consumer rather than making every member required.
41
+
42
+ ```tsx
43
+ <Field label="Related Articles" isGroup>
44
+ {(binding) => (
45
+ <EntryPicker {...binding} items={articles} value={selected} onValueChange={setSelected} />
46
+ )}
47
+ </Field>
48
+ ```
49
+
50
+ `count` renders the shared count Badge beside the label, including zero and full
51
+ totals above 99, without changing its accessible name. EntryPicker, ChoiceGroup and
52
+ SelectionCardGroup keep their standalone label props and compose the same frame.
53
+ Bound to their own Field, they render only their controls and the Field shows their
54
+ count unless it has its own `count`. Labelled by anything else through
55
+ `aria-labelledby`, they keep their own frame. A group Field's fieldset carries the
56
+ hint or error, so bound groups and range members don't repeat it. FormEditor uses
57
+ this path for all field types, including picker-label overrides and selection counts.
58
+
34
59
  Every family also has a direct entry point:
35
60
 
36
61
  ```tsx
@@ -98,7 +123,7 @@ General forms can use select fields with `options: [{ value, label }]`, per-fiel
98
123
 
99
124
  `columns` sets the most columns and defaults to one. The form drops a column whenever a field would be narrower than `minColumnWidth` (default `16rem`), measured against the form's own width, so it steps down inside drawers and modals. Use `columns="auto"` to fit as many columns as the width allows. FormEditor is not a size container, so it keeps its content width in flex rows and popovers.
100
125
 
101
- Changes emit `onValueChange(nextValues, { fieldId })`. Use the changed field ID when adapting to APIs that accept patches, generated IDs, or dependent values. Runtime form schemas can hold JSX and live choices, so keep them separate from persisted content definitions. Picker field options such as `picker: { itemLabel: "image", itemsLabel: "images" }` provide contextual search and selection copy without putting data access in the library. Omitted or `undefined` options keep the asset or entry wording.
126
+ Changes emit `onValueChange(nextValues, { fieldId })`. Use the changed field ID when adapting to APIs that accept patches, generated IDs, or dependent values. Runtime form schemas can hold JSX and live choices, so keep them separate from persisted content definitions. Picker field options such as `picker: { itemLabel: "image", itemsLabel: "images" }` provide contextual search and selection copy without putting data access in the library. `picker.label` overrides the field's name: its legend, accessible name, default "Choose …" action and required message. Omitted or `undefined` item and action options keep the asset or entry wording.
102
127
 
103
128
  `RichTextEditor` also supports `format="json"` with `value`/`defaultValue` and an `onChange` callback receiving the document. HTML remains its default format. Unsupported JSON content produces an error and cannot be edited until corrected.
104
129
 
package/UPGRADING.md CHANGED
@@ -2,6 +2,81 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.3.0
6
+
7
+ ### Breaking changes
8
+
9
+ - `EntryPicker`'s root is now a `<fieldset class="ds-field ds-entry-picker">` with a `<legend>`, not a `<div>`. `.ds-entry-picker__head` and `.ds-entry-picker__label` are removed: the label is `.ds-field__label` and the count is `.ds-field__count`.
10
+ - `ChoiceGroup` and `SelectionCardGroup` legends use `.ds-field__label`. `.ds-choice-group__label` and `.ds-selection-card-group__label` are removed, and the selection-card legend now uses Field's semibold weight and spacing.
11
+ - FormEditor asset and reference fields no longer show an "Assets" or "Entries" sub-heading. `picker.label` now names the field: it replaces `label` in the legend, the accessible name, the default "Choose …" action and dialog title, and the required message. If you used it as a sub-heading, remove it.
12
+ - A `Field` with `isGroup` now describes its fieldset with the hint or error and marks it invalid. If you spread the binding onto your own `role="group"` wrapper inside it, remove the wrapper, or its `aria-labelledby` and `aria-describedby`, so the group and its description are not announced twice.
13
+
14
+ ### Shared Field composition
15
+
16
+ `Field` owns the label or group legend, required marker, hint, error and optional
17
+ selection count. `count={3}` renders **Related Articles** beside the shared count
18
+ Badge containing **3**, without parentheses. Zero and totals above 99 are shown in
19
+ full. The count is supplemental visual content and does not change the accessible
20
+ name.
21
+
22
+ #### Adoption
23
+
24
+ Spread the existing render-prop binding onto each control. `FieldBinding` and
25
+ `FieldRenderProps` are exported from the root and `components/Field` for custom
26
+ adapters. Use `isGroup` for ranges, choices, calendars, croppers and pickers; keep
27
+ option captions and individual range-member names. The fieldset is the one group:
28
+ its hint or error describes it, and range members keep their Minimum/Maximum or
29
+ Start/End names and are marked invalid with it. Bound to a single-control `Field`,
30
+ a range becomes that described group itself.
31
+
32
+ ```tsx
33
+ <Field label="Related Articles" hint="Choose related stories." isGroup>
34
+ {(binding) => <EntryPicker {...binding} items={articles} value={selected} onValueChange={setSelected} />}
35
+ </Field>
36
+ ```
37
+
38
+ Standalone EntryPicker, ChoiceGroup and SelectionCardGroup delegate their label,
39
+ `hint`, `error`, `isRequired` and optional count to that same frame. Bound to their
40
+ own `Field`, they render only their controls; the Field supplies the visible copy
41
+ and shows the group's count unless it has its own `count`. Labelled by anything
42
+ else, such as a page heading through `aria-labelledby`, they keep their own legend,
43
+ hint, error, required marker and count. Standalone EntryPicker still defaults to
44
+ Entries. FormEditor supplies counts from current asset/reference values and keeps
45
+ contextual picker action/search copy and UTC date-time labeling.
46
+
47
+ #### Compatibility
48
+
49
+ Existing values, events, refs, standalone label props and Field callbacks remain
50
+ supported. Native inputs receive `required`. Select, Switch, TagsInput and rich
51
+ text use `aria-required`; DateField buttons and group containers omit the unsupported
52
+ native flag. DateField still forwards every other attribute, such as `data-testid`,
53
+ to its trigger. Required group markers describe the group; consumers keep member
54
+ validation rules (for example requiring one radio, rather than every checkbox).
55
+ TagsInput's empty typing draft is not a required native input after tags are added.
56
+
57
+ Field-bound errors now reach custom interactive surfaces and their visual skins; a
58
+ disabled slider keeps its muted track when invalid. Number and date ranges stack
59
+ when the range itself is narrower than 24rem. Group fieldsets are not size
60
+ containers, so groups keep their content width in popovers and flex rows, and
61
+ pickers' drag previews stay under the pointer. The count Badge sits inside the
62
+ owning label or legend as `.ds-field__count`. Because of the breaking changes above,
63
+ the release workflow publishes this as a minor version.
64
+
65
+ #### Verification
66
+
67
+ Run consuming typechecks, tests and builds against the packed library. Search for
68
+ the removed CSS hooks and for `picker.label`. Check Field's SharedComposition story
69
+ in every theme and at narrow widths. Verify one visible label, counts 0/1/3/128,
70
+ required state, hint/error announced once per group, option and range-member names,
71
+ read-only/disabled controls and controlled updates. Check standalone pickers, pickers
72
+ inside another dialog (including Escape and focus return), drag reordering in a
73
+ scrolled page, and groups inside popovers. No dependency, schema field type or
74
+ release workflow changes are needed.
75
+
76
+ `Badge` adds optional `isCountExact` for this Field composition: zero is visible and
77
+ totals are uncapped. Existing Badge usage keeps its compact defaults (zero hidden,
78
+ totals above 99 shown as `99+`).
79
+
5
80
  ## 0.2.1
6
81
 
7
82
  ### Edit layouts
@@ -1,6 +1,6 @@
1
1
  import { Field as e } from "../components/Field/index.js";
2
2
  import { TextArea as t, TextField as n } from "../components/TextField/index.js";
3
- import { n as r, r as i, t as a } from "./RichTextEditor-Dnx4i7bQ.js";
3
+ import { n as r, r as i, t as a } from "./RichTextEditor-DjR10XJ-.js";
4
4
  import { EntryPicker as o } from "../components/EntryPicker/index.js";
5
5
  import { NumberField as s } from "../components/NumberField/index.js";
6
6
  import { Select as c } from "../components/Select/index.js";
@@ -31,71 +31,77 @@ function m(e) {
31
31
  var h = {
32
32
  asset: {
33
33
  key: "assetId",
34
- label: "Assets",
35
34
  itemLabel: "asset",
36
35
  itemsLabel: "assets"
37
36
  },
38
37
  reference: {
39
38
  key: "entryId",
40
- label: "Entries",
41
39
  itemLabel: "entry",
42
40
  itemsLabel: "entries"
43
41
  }
44
42
  };
45
43
  function g(e) {
46
- let t = h[e.type], { label: n = t.label, addLabel: r = `Choose ${e.label}`, itemLabel: i = t.itemLabel, itemsLabel: a = t.itemsLabel, ...o } = e.picker ?? {};
44
+ return e.type === "asset" || e.type === "reference" ? e.picker?.label ?? e.label : e.label;
45
+ }
46
+ function _(e) {
47
+ let t = h[e.type], { addLabel: n = `Choose ${g(e)}`, emptyLabel: r, itemLabel: i = t.itemLabel, itemsLabel: a = t.itemsLabel, max: o, isReorderable: s } = e.picker ?? {};
47
48
  return {
48
- ...o,
49
- label: n,
50
- addLabel: r,
49
+ addLabel: n,
50
+ emptyLabel: r,
51
51
  itemLabel: i,
52
- itemsLabel: a
52
+ itemsLabel: a,
53
+ max: o,
54
+ isReorderable: s
53
55
  };
54
56
  }
55
- function _(e) {
57
+ function v(e, t) {
58
+ let { key: n } = h[e.type];
59
+ return (Array.isArray(t) ? t : t === void 0 ? [] : [t]).flatMap((e) => b(e, n) ? [e[n]] : []);
60
+ }
61
+ function y(e) {
56
62
  if (typeof e != "string") return;
57
63
  let t = /^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2})(?::(\d{2})(?:\.(\d{1,3}))?)?(?:Z|\+00:00)$/.exec(e);
58
64
  if (!t) return;
59
65
  let n = `${t[1]}:${t[2] ?? "00"}.${(t[3] ?? "").padEnd(3, "0")}Z`, r = new Date(n);
60
66
  if (Number.isFinite(r.getTime()) && r.toISOString() === n) return n;
61
67
  }
62
- function v(e, t) {
68
+ function b(e, t) {
63
69
  return !!e && typeof e == "object" && t in e && typeof e[t] == "string" && e[t].trim().length > 0;
64
70
  }
65
- function y(e) {
66
- return !!e.text?.trim() || e.type === "horizontalRule" || !!e.content?.some(y);
71
+ function x(e) {
72
+ return !!e.text?.trim() || e.type === "horizontalRule" || !!e.content?.some(x);
67
73
  }
68
- function b(e) {
69
- return `${e.label} is required.`;
74
+ function S(e) {
75
+ return `${g(e)} is required.`;
70
76
  }
71
- function x(e, t) {
77
+ function C(e, t) {
72
78
  if (typeof t != "string") return "Enter text.";
73
- if (e.required && !t.trim()) return b(e);
79
+ if (e.required && !t.trim()) return S(e);
74
80
  if ((e.type === "shortText" || e.type === "longText") && e.maxLength !== void 0 && t.length > e.maxLength) return `Enter no more than ${e.maxLength} characters.`;
75
81
  }
76
- function S(e, t) {
82
+ function w(e, t) {
77
83
  let n = r(t);
78
84
  if (n) return n;
79
- if (e.required && !y(t)) return b(e);
85
+ if (e.required && !x(t)) return S(e);
80
86
  }
81
- function C(e, t) {
87
+ function T(e, t) {
82
88
  if (typeof t != "string") return "Choose an available option.";
83
- if (t === "") return e.required ? b(e) : void 0;
89
+ if (t === "") return e.required ? S(e) : void 0;
84
90
  if (e.type === "select" && e.options.length > 0 && !e.options.some((e) => e.value === t)) return "Choose an available option.";
85
91
  }
86
- function w(e, t) {
92
+ function E(e, t) {
87
93
  if (e.type !== "asset" && e.type !== "reference") return;
88
94
  let { key: n, itemLabel: r, itemsLabel: i } = h[e.type];
89
- if (!e.multiple) return v(t, n) ? void 0 : `Choose an ${r}.`;
90
- if (!Array.isArray(t) || !t.every((e) => v(e, n))) return `Choose a list of ${i}.`;
91
- if (e.required && t.length === 0) return b(e);
95
+ if (!e.multiple) return b(t, n) ? void 0 : `Choose an ${r}.`;
96
+ if (!Array.isArray(t) || !t.every((e) => b(e, n))) return `Choose a list of ${i}.`;
97
+ if (e.required && t.length === 0) return S(e);
92
98
  let a = e.picker?.max;
93
- if (a !== void 0 && t.length > a) return `Choose no more than ${a} ${g(e).itemsLabel}.`;
99
+ if (a !== void 0 && t.length > a) return `Choose no more than ${a} ${_(e).itemsLabel}.`;
94
100
  }
95
- var T = {
96
- shortText: x,
97
- longText: x,
98
- richText: S,
101
+ var D = {
102
+ shortText: C,
103
+ longText: C,
104
+ richText: w,
99
105
  number: (e, t) => {
100
106
  if (typeof t != "number" || !Number.isFinite(t)) return "Enter a finite number.";
101
107
  if (e.type === "number") {
@@ -104,31 +110,23 @@ var T = {
104
110
  }
105
111
  },
106
112
  boolean: (e, t) => typeof t == "boolean" ? void 0 : "Choose a boolean value.",
107
- dateTime: (e, t) => _(t) ? void 0 : "Enter a valid UTC date and time.",
108
- select: C,
109
- asset: w,
110
- reference: w
113
+ dateTime: (e, t) => y(t) ? void 0 : "Enter a valid UTC date and time.",
114
+ select: T,
115
+ asset: E,
116
+ reference: E
111
117
  };
112
- function E(e, t) {
113
- return t === void 0 ? e.required ? b(e) : void 0 : T[e.type](e, t);
118
+ function O(e, t) {
119
+ return t === void 0 ? e.required ? S(e) : void 0 : D[e.type](e, t);
114
120
  }
115
- function D(e, t) {
121
+ function k(e, t) {
116
122
  return m(e), Object.fromEntries(e.fields.flatMap((e) => {
117
- let n = E(e, Object.hasOwn(t, e.id) ? t[e.id] : void 0);
123
+ let n = O(e, Object.hasOwn(t, e.id) ? t[e.id] : void 0);
118
124
  return n ? [[e.id, n]] : [];
119
125
  }));
120
126
  }
121
127
  //#endregion
122
128
  //#region src/components/FormEditor/control.tsx
123
- function O(e, t) {
124
- let n = e.type === "asset" ? "assetId" : "entryId";
125
- return (Array.isArray(t) ? t : t === void 0 ? [] : [t]).flatMap((e) => {
126
- if (!e || typeof e != "object" || !(n in e)) return [];
127
- let t = e[n];
128
- return typeof t == "string" ? [t] : [];
129
- });
130
- }
131
- function k(e, t) {
129
+ function A(e, t) {
132
130
  if (e.type === "asset") {
133
131
  let n = t.map((e) => ({ assetId: e }));
134
132
  return e.multiple ? n : n[0];
@@ -136,7 +134,7 @@ function k(e, t) {
136
134
  let n = t.map((e) => ({ entryId: e }));
137
135
  return e.multiple ? n : n[0];
138
136
  }
139
- function A({ field: e, stored: t, isDisabled: n, required: r, accessibility: i, onChange: a }) {
137
+ function j({ field: e, stored: t, isDisabled: n, required: r, accessibility: i, onChange: a }) {
140
138
  return /* @__PURE__ */ f(s, {
141
139
  ...i,
142
140
  required: r,
@@ -155,7 +153,7 @@ function A({ field: e, stored: t, isDisabled: n, required: r, accessibility: i,
155
153
  }
156
154
  });
157
155
  }
158
- function j({ field: e, stored: t, isDisabled: n, required: r, accessibility: i, onChange: a }) {
156
+ function M({ field: e, stored: t, isDisabled: n, required: r, accessibility: i, onChange: a }) {
159
157
  let o = !r && !e.options.some((e) => e.value === "");
160
158
  return /* @__PURE__ */ f(c, {
161
159
  ...i,
@@ -172,114 +170,114 @@ function j({ field: e, stored: t, isDisabled: n, required: r, accessibility: i,
172
170
  onValueChange: (e) => a(e === "" ? void 0 : e)
173
171
  });
174
172
  }
175
- function M({ field: e, stored: t, items: n, isDisabled: r, accessibility: i, onChange: a }) {
176
- return /* @__PURE__ */ f("div", {
173
+ function N({ field: e, selected: t, items: n, isDisabled: r, accessibility: i, onChange: a }) {
174
+ return /* @__PURE__ */ f(o, {
177
175
  ...i,
178
- role: "group",
179
- children: /* @__PURE__ */ f(o, {
180
- items: n,
181
- value: O(e, t),
182
- ...g(e),
183
- mode: e.multiple ? "multiple" : "single",
184
- isDisabled: r,
185
- onValueChange: (t) => a(k(e, t))
186
- })
176
+ items: n,
177
+ value: t,
178
+ ..._(e),
179
+ mode: e.multiple ? "multiple" : "single",
180
+ isDisabled: r,
181
+ onValueChange: (t) => a(A(e, t))
187
182
  });
188
183
  }
189
- function N({ field: e, stored: r, items: o, isDisabled: s, accessibility: { required: c, ...u }, onChange: d }) {
190
- let p = {
184
+ function P({ field: e, stored: r, selected: o, items: s, isDisabled: c, accessibility: { required: u, ...d }, onChange: p }) {
185
+ let m = {
191
186
  stored: r,
192
- isDisabled: s,
193
- required: c,
194
- accessibility: u,
195
- onChange: d
187
+ isDisabled: c,
188
+ required: u,
189
+ accessibility: d,
190
+ onChange: p
196
191
  };
197
192
  switch (e.type) {
198
193
  case "shortText": return /* @__PURE__ */ f(n, {
199
- ...u,
200
- required: c,
201
- disabled: s,
194
+ ...d,
195
+ required: u,
196
+ disabled: c,
202
197
  placeholder: e.placeholder,
203
198
  type: e.inputType,
204
199
  maxLength: e.maxLength,
205
200
  readOnly: e.readOnly,
206
201
  autoFocus: e.autoFocus,
207
202
  value: typeof r == "string" ? r : "",
208
- onChange: (e) => d(e.target.value)
203
+ onChange: (e) => p(e.target.value)
209
204
  });
210
205
  case "longText": return /* @__PURE__ */ f(t, {
211
- ...u,
212
- required: c,
213
- disabled: s,
206
+ ...d,
207
+ required: u,
208
+ disabled: c,
214
209
  placeholder: e.placeholder,
215
210
  rows: e.rows,
216
211
  maxLength: e.maxLength,
217
212
  readOnly: e.readOnly,
218
213
  autoFocus: e.autoFocus,
219
214
  value: typeof r == "string" ? r : "",
220
- onChange: (e) => d(e.target.value)
215
+ onChange: (e) => p(e.target.value)
221
216
  });
222
- case "number": return /* @__PURE__ */ f(A, {
217
+ case "number": return /* @__PURE__ */ f(j, {
223
218
  field: e,
224
- ...p
219
+ ...m
225
220
  });
226
221
  case "boolean": return /* @__PURE__ */ f(l, {
227
- ...u,
228
- isDisabled: s,
222
+ ...d,
223
+ isDisabled: c,
229
224
  autoFocus: e.autoFocus,
230
225
  isSelected: r === !0,
231
- onSelectedChange: d
226
+ onSelectedChange: p
232
227
  });
233
228
  case "dateTime": return /* @__PURE__ */ f(n, {
234
- ...u,
235
- required: c,
236
- disabled: s,
229
+ ...d,
230
+ required: u,
231
+ disabled: c,
237
232
  type: "datetime-local",
238
233
  step: "0.001",
239
234
  autoFocus: e.autoFocus,
240
- value: _(r)?.slice(0, -1) ?? "",
241
- onChange: (e) => d(_(`${e.target.value}Z`))
235
+ value: y(r)?.slice(0, -1) ?? "",
236
+ onChange: (e) => p(y(`${e.target.value}Z`))
242
237
  });
243
238
  case "richText": return /* @__PURE__ */ f(a, {
244
- ...u,
239
+ ...d,
245
240
  label: e.label,
246
- isRequired: c,
247
- isDisabled: s,
241
+ isRequired: u,
242
+ isDisabled: c,
248
243
  placeholder: e.placeholder,
249
244
  format: "json",
250
245
  value: r === void 0 ? i : r,
251
- onChange: d
246
+ onChange: p
252
247
  });
253
- case "select": return /* @__PURE__ */ f(j, {
248
+ case "select": return /* @__PURE__ */ f(M, {
254
249
  field: e,
255
- ...p
250
+ ...m
256
251
  });
257
252
  case "asset":
258
- case "reference": return /* @__PURE__ */ f(M, {
253
+ case "reference": return /* @__PURE__ */ f(N, {
259
254
  field: e,
260
- items: o,
261
- ...p
255
+ items: s,
256
+ selected: o ?? [],
257
+ ...m
262
258
  });
263
259
  }
264
260
  }
265
261
  //#endregion
266
262
  //#region src/components/FormEditor/index.tsx
267
- function P({ field: t, stored: n, items: r, isDisabled: i, error: a, isErrorVisible: o, onChange: s }) {
268
- let c = u(() => a === void 0 && o ? E(t, n) : void 0, [
263
+ function F({ field: t, stored: n, items: r, isDisabled: i, error: a, isErrorVisible: o, onChange: s }) {
264
+ let c = u(() => a === void 0 && o ? O(t, n) : void 0, [
269
265
  a,
270
266
  o,
271
267
  t,
272
268
  n
273
- ]), l = t.type === "dateTime" ? `${t.label} (UTC)` : t.label;
269
+ ]), l = u(() => t.type === "asset" || t.type === "reference" ? v(t, n) : void 0, [t, n]);
274
270
  return /* @__PURE__ */ f(e, {
275
- label: l,
271
+ label: t.type === "dateTime" ? `${t.label} (UTC)` : g(t),
276
272
  hint: t.hint,
277
273
  error: a ?? c,
278
274
  isRequired: t.required,
279
- isGroup: t.type === "asset" || t.type === "reference",
280
- children: (e) => /* @__PURE__ */ f(N, {
275
+ count: l?.length,
276
+ isGroup: l !== void 0,
277
+ children: (e) => /* @__PURE__ */ f(P, {
281
278
  field: t,
282
279
  stored: n,
280
+ selected: l,
283
281
  items: r,
284
282
  isDisabled: i,
285
283
  accessibility: e,
@@ -287,7 +285,7 @@ function P({ field: t, stored: n, items: r, isDisabled: i, error: a, isErrorVisi
287
285
  })
288
286
  });
289
287
  }
290
- function F({ schema: e, value: t, defaultValue: n = {}, onValueChange: r, pickerItems: i = {}, errors: a = {}, isDisabled: o = !1, showAllErrors: s = !1, columns: c = 1, minColumnWidth: l = "16rem", className: p, style: h, ...g }) {
288
+ function I({ schema: e, value: t, defaultValue: n = {}, onValueChange: r, pickerItems: i = {}, errors: a = {}, isDisabled: o = !1, showAllErrors: s = !1, columns: c = 1, minColumnWidth: l = "16rem", className: p, style: h, ...g }) {
291
289
  let [_, v] = d(n), [y, b] = d(() => /* @__PURE__ */ new Set()), x = t ?? _;
292
290
  u(() => m(e), [e]);
293
291
  let S = (e, n) => {
@@ -310,7 +308,7 @@ function F({ schema: e, value: t, defaultValue: n = {}, onValueChange: r, picker
310
308
  ...g,
311
309
  children: e.fields.map((e) => {
312
310
  let t = Object.hasOwn(x, e.id) ? x[e.id] : void 0, n = o || !!e.isDisabled, r = n || "readOnly" in e && !!e.readOnly, c = s || y.has(e.id) || e.type === "number" && typeof t == "number";
313
- return /* @__PURE__ */ f(P, {
311
+ return /* @__PURE__ */ f(F, {
314
312
  field: e,
315
313
  stored: t,
316
314
  items: i[e.id] ?? [],
@@ -325,6 +323,6 @@ function F({ schema: e, value: t, defaultValue: n = {}, onValueChange: r, picker
325
323
  });
326
324
  }
327
325
  //#endregion
328
- export { D as n, F as t };
326
+ export { k as n, I as t };
329
327
 
330
- //# sourceMappingURL=FormEditor-DuW8x78Y.js.map
328
+ //# sourceMappingURL=FormEditor-DRmPFe2E.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FormEditor-DRmPFe2E.js","names":["documentError","emptyDocument","RichTextEditor","fieldTypes","assertModel","ids","field","model","linkCopy","fieldLabel","pickerCopy","defaults","selectedIds","value","isLink","link","key","parseUtcDateTime","match","canonical","date","hasRichText","node","requiredError","textError","richTextError","error","choiceError","option","linkError","itemLabel","item","itemsLabel","max","validators","fieldError","validateFormValues","values","pickerValue","links","NumberControl","NumberField","accessibility","stored","next","onChange","SelectControl","isClearable","required","Select","PickerControl","EntryPicker","selected","FormControl","shared","TextField","isDisabled","event","TextArea","Switch","FormEditorField","validation","useMemo","isErrorVisible","Field","FormEditor","rest","internal","setInternal","useState","defaultValue","changed","setChanged","current","schema","commit","fieldId","previous","onValueChange","layout","columns","minColumnWidth","className","style","fieldDisabled","isLocked","showAllErrors","pickerItems","errors"],"sources":["../../src/components/FormEditor/model.ts","../../src/components/FormEditor/control.tsx","../../src/components/FormEditor/index.tsx"],"sourcesContent":["import type { ReactNode } from \"react\";\nimport type { SelectOption } from \"../Select\";\nimport type { EntryPickerProps } from \"../EntryPicker\";\nimport type { JSONContent } from \"@tiptap/react\";\nimport { documentError } from \"../RichTextEditor/document\";\nimport type { RichTextDocument } from \"../RichTextEditor\";\n\ninterface FormFieldBase {\n id: string;\n label: string;\n hint?: ReactNode;\n placeholder?: string;\n required?: boolean;\n isDisabled?: boolean;\n}\n\nexport type FormField = FormFieldBase &\n (\n | {\n type: \"shortText\";\n inputType?: \"text\" | \"email\";\n maxLength?: number;\n readOnly?: boolean;\n autoFocus?: boolean;\n multiple?: never;\n }\n | {\n type: \"longText\";\n rows?: number;\n maxLength?: number;\n readOnly?: boolean;\n autoFocus?: boolean;\n multiple?: never;\n }\n | { type: \"boolean\" | \"dateTime\"; autoFocus?: boolean; multiple?: never }\n | { type: \"richText\"; autoFocus?: never; multiple?: never }\n | {\n type: \"number\";\n min?: number;\n max?: number;\n step?: number | \"any\";\n hasSteppers?: boolean;\n autoFocus?: boolean;\n multiple?: never;\n }\n | { type: \"select\"; options: SelectOption[]; autoFocus?: boolean; multiple?: never }\n | {\n type: \"asset\" | \"reference\";\n multiple?: boolean;\n autoFocus?: never;\n picker?: Pick<\n EntryPickerProps,\n \"label\" | \"addLabel\" | \"emptyLabel\" | \"itemLabel\" | \"itemsLabel\" | \"max\" | \"isReorderable\"\n >;\n }\n );\n\nexport type FieldOf<T extends FormField[\"type\"]> = Extract<FormField, { type: T }>;\n\nexport interface FormSchema {\n fields: readonly FormField[];\n}\n\nexport interface AssetValue {\n assetId: string;\n}\nexport interface ReferenceValue {\n entryId: string;\n}\nexport type FormFieldValue =\n | string\n | number\n | boolean\n | RichTextDocument\n | AssetValue\n | ReferenceValue\n | AssetValue[]\n | ReferenceValue[];\nexport type FormValues = Record<string, FormFieldValue | undefined>;\nexport type FormErrors = Partial<Record<string, string>>;\n\nconst fieldTypes = new Set([\n \"shortText\",\n \"longText\",\n \"richText\",\n \"number\",\n \"boolean\",\n \"dateTime\",\n \"asset\",\n \"reference\",\n \"select\",\n]);\n\nexport function assertModel(model: FormSchema) {\n const ids = new Set<string>();\n for (const field of model.fields) {\n if (!field.id?.trim() || ids.has(field.id))\n throw new Error(\"Form field IDs must be nonempty and unique.\");\n if (!fieldTypes.has(field.type)) throw new Error(`Unsupported form field type: ${field.type}`);\n if (field.type === \"select\" && !Array.isArray(field.options))\n throw new Error(`Select field ${field.id} needs an options array.`);\n ids.add(field.id);\n }\n}\n\nconst linkCopy = {\n asset: { key: \"assetId\", itemLabel: \"asset\", itemsLabel: \"assets\" },\n reference: { key: \"entryId\", itemLabel: \"entry\", itemsLabel: \"entries\" },\n} as const;\n\n/** The field's visible and accessible name. A picker's `label` overrides it. */\nexport function fieldLabel(field: FormField): string {\n return field.type === \"asset\" || field.type === \"reference\"\n ? (field.picker?.label ?? field.label)\n : field.label;\n}\n\n/** Picker action and item copy, with asset or entry wording for any option left out or undefined. */\nexport function pickerCopy(field: FieldOf<\"asset\" | \"reference\">) {\n const defaults = linkCopy[field.type];\n const {\n addLabel = `Choose ${fieldLabel(field)}`,\n emptyLabel,\n itemLabel = defaults.itemLabel,\n itemsLabel = defaults.itemsLabel,\n max,\n isReorderable,\n } = field.picker ?? {};\n return { addLabel, emptyLabel, itemLabel, itemsLabel, max, isReorderable };\n}\n\n/** The picked IDs, in stored order, skipping anything that isn't a link. */\nexport function selectedIds(field: FieldOf<\"asset\" | \"reference\">, value: unknown): string[] {\n const { key } = linkCopy[field.type];\n const links = Array.isArray(value) ? value : value === undefined ? [] : [value];\n return links.flatMap((link) =>\n isLink(link, key) ? [(link as Record<string, string>)[key]] : [],\n );\n}\n\n/** Accept UTC ISO strings without rolling invalid dates into the next month. */\nexport function parseUtcDateTime(value: unknown): string | undefined {\n if (typeof value !== \"string\") return;\n const match = /^(\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2})(?::(\\d{2})(?:\\.(\\d{1,3}))?)?(?:Z|\\+00:00)$/.exec(\n value,\n );\n if (!match) return;\n const canonical = `${match[1]}:${match[2] ?? \"00\"}.${(match[3] ?? \"\").padEnd(3, \"0\")}Z`;\n const date = new Date(canonical);\n if (Number.isFinite(date.getTime()) && date.toISOString() === canonical) return canonical;\n}\n\nfunction isLink(value: unknown, key: \"assetId\" | \"entryId\"): boolean {\n return (\n !!value &&\n typeof value === \"object\" &&\n key in value &&\n typeof (value as Record<string, unknown>)[key] === \"string\" &&\n (value as Record<string, string>)[key].trim().length > 0\n );\n}\n\nfunction hasRichText(node: JSONContent): boolean {\n return !!node.text?.trim() || node.type === \"horizontalRule\" || !!node.content?.some(hasRichText);\n}\n\nfunction requiredError(field: FormField): string {\n return `${fieldLabel(field)} is required.`;\n}\n\nfunction textError(field: FormField, value: unknown): string | undefined {\n if (typeof value !== \"string\") return \"Enter text.\";\n if (field.required && !value.trim()) return requiredError(field);\n if (\n (field.type === \"shortText\" || field.type === \"longText\") &&\n field.maxLength !== undefined &&\n value.length > field.maxLength\n ) {\n return `Enter no more than ${field.maxLength} characters.`;\n }\n}\n\nfunction richTextError(field: FormField, value: unknown): string | undefined {\n const error = documentError(value);\n if (error) return error;\n if (field.required && !hasRichText(value as RichTextDocument)) return requiredError(field);\n}\n\nfunction choiceError(field: FormField, value: unknown): string | undefined {\n if (typeof value !== \"string\") return \"Choose an available option.\";\n if (value === \"\") return field.required ? requiredError(field) : undefined;\n // An empty list means the choices are still loading, so a stored value stays valid until they arrive.\n if (\n field.type === \"select\" &&\n field.options.length > 0 &&\n !field.options.some((option) => option.value === value)\n ) {\n return \"Choose an available option.\";\n }\n}\n\nfunction linkError(field: FormField, value: unknown): string | undefined {\n if (field.type !== \"asset\" && field.type !== \"reference\") return;\n const { key, itemLabel, itemsLabel } = linkCopy[field.type];\n if (!field.multiple) return isLink(value, key) ? undefined : `Choose an ${itemLabel}.`;\n if (!Array.isArray(value) || !value.every((item) => isLink(item, key)))\n return `Choose a list of ${itemsLabel}.`;\n if (field.required && value.length === 0) return requiredError(field);\n const max = field.picker?.max;\n if (max !== undefined && value.length > max)\n return `Choose no more than ${max} ${pickerCopy(field).itemsLabel}.`;\n}\n\nconst validators: Record<\n FormField[\"type\"],\n (field: FormField, value: unknown) => string | undefined\n> = {\n shortText: textError,\n longText: textError,\n richText: richTextError,\n number: (field, value) => {\n if (typeof value !== \"number\" || !Number.isFinite(value)) return \"Enter a finite number.\";\n if (field.type !== \"number\") return;\n if (field.min !== undefined && value < field.min)\n return `Enter a number of at least ${field.min}.`;\n if (field.max !== undefined && value > field.max)\n return `Enter a number no greater than ${field.max}.`;\n },\n boolean: (_field, value) => (typeof value === \"boolean\" ? undefined : \"Choose a boolean value.\"),\n dateTime: (_field, value) =>\n parseUtcDateTime(value) ? undefined : \"Enter a valid UTC date and time.\",\n select: choiceError,\n asset: linkError,\n reference: linkError,\n};\n\nexport function fieldError(field: FormField, value: unknown): string | undefined {\n if (value === undefined) return field.required ? requiredError(field) : undefined;\n return validators[field.type](field, value);\n}\n\n/** Validate data loaded from JSON as well as values emitted by FormEditor. */\nexport function validateFormValues(model: FormSchema, values: Record<string, unknown>): FormErrors {\n assertModel(model);\n return Object.fromEntries(\n model.fields.flatMap((field): [string, string][] => {\n const error = fieldError(\n field,\n Object.hasOwn(values, field.id) ? values[field.id] : undefined,\n );\n return error ? [[field.id, error]] : [];\n }),\n );\n}\n","import { EntryPicker, type EntryItem } from \"../EntryPicker\";\nimport type { FieldRenderProps } from \"../Field\";\nimport { NumberField } from \"../NumberField\";\nimport { RichTextEditor, type RichTextDocument } from \"../RichTextEditor\";\nimport { emptyDocument } from \"../RichTextEditor/document\";\nimport { Select } from \"../Select\";\nimport { Switch } from \"../Switch\";\nimport { TextArea, TextField } from \"../TextField\";\nimport {\n parseUtcDateTime,\n pickerCopy,\n type FieldOf,\n type FormField,\n type FormFieldValue,\n} from \"./model\";\n\nfunction pickerValue(field: FormField, ids: string[]): FormFieldValue | undefined {\n if (field.type === \"asset\") {\n const links = ids.map((assetId) => ({ assetId }));\n return field.multiple ? links : links[0];\n }\n const links = ids.map((entryId) => ({ entryId }));\n return field.multiple ? links : links[0];\n}\n\ntype Accessibility = FieldRenderProps;\n\ninterface ControlProps<F extends FormField> {\n field: F;\n stored: FormFieldValue | undefined;\n isDisabled: boolean;\n required: boolean | undefined;\n accessibility: Omit<Accessibility, \"required\">;\n onChange: (value: FormFieldValue | undefined) => void;\n}\n\nfunction NumberControl({\n field,\n stored,\n isDisabled,\n required,\n accessibility,\n onChange,\n}: ControlProps<FieldOf<\"number\">>) {\n return (\n <NumberField\n {...accessibility}\n required={required}\n isDisabled={isDisabled}\n placeholder={field.placeholder}\n min={field.min}\n max={field.max}\n step={field.step ?? \"any\"}\n hasSteppers={field.hasSteppers ?? false}\n autoFocus={field.autoFocus}\n decreaseLabel={`Decrease ${field.label}`}\n increaseLabel={`Increase ${field.label}`}\n value={typeof stored === \"number\" && Number.isFinite(stored) ? stored : \"\"}\n onValueChange={(next) => {\n if (next === \"\" || Number.isFinite(next)) onChange(next === \"\" ? undefined : next);\n }}\n />\n );\n}\n\nfunction SelectControl({\n field,\n stored,\n isDisabled,\n required,\n accessibility,\n onChange,\n}: ControlProps<FieldOf<\"select\">>) {\n // Optional selects lead with an empty choice; picking it removes the key.\n const isClearable = !required && !field.options.some((option) => option.value === \"\");\n return (\n <Select\n {...accessibility}\n aria-required={required || undefined}\n isDisabled={isDisabled}\n isInvalid={accessibility[\"aria-invalid\"]}\n options={\n isClearable\n ? [{ value: \"\", label: field.placeholder ?? \"None\" }, ...field.options]\n : field.options\n }\n placeholder={field.placeholder}\n autoFocus={field.autoFocus}\n value={typeof stored === \"string\" ? stored : \"\"}\n onValueChange={(next) => onChange(next === \"\" ? undefined : next)}\n />\n );\n}\n\nfunction PickerControl({\n field,\n selected,\n items,\n isDisabled,\n accessibility,\n onChange,\n}: ControlProps<FieldOf<\"asset\" | \"reference\">> & { items: EntryItem[]; selected: string[] }) {\n return (\n <EntryPicker\n {...accessibility}\n items={items}\n value={selected}\n {...pickerCopy(field)}\n mode={field.multiple ? \"multiple\" : \"single\"}\n isDisabled={isDisabled}\n onValueChange={(ids) => onChange(pickerValue(field, ids))}\n />\n );\n}\n\ninterface FormControlProps {\n field: FormField;\n stored: FormFieldValue | undefined;\n /** Picker fields' stored IDs, derived once by the owning field. */\n selected: string[] | undefined;\n items: EntryItem[];\n isDisabled: boolean;\n accessibility: Accessibility;\n onChange: (value: FormFieldValue | undefined) => void;\n}\n\nexport function FormControl({\n field,\n stored,\n selected,\n items,\n isDisabled,\n accessibility: { required, ...accessibility },\n onChange,\n}: FormControlProps) {\n const shared = { stored, isDisabled, required, accessibility, onChange };\n switch (field.type) {\n case \"shortText\":\n return (\n <TextField\n {...accessibility}\n required={required}\n disabled={isDisabled}\n placeholder={field.placeholder}\n type={field.inputType}\n maxLength={field.maxLength}\n readOnly={field.readOnly}\n autoFocus={field.autoFocus}\n value={typeof stored === \"string\" ? stored : \"\"}\n onChange={(event) => onChange(event.target.value)}\n />\n );\n case \"longText\":\n return (\n <TextArea\n {...accessibility}\n required={required}\n disabled={isDisabled}\n placeholder={field.placeholder}\n rows={field.rows}\n maxLength={field.maxLength}\n readOnly={field.readOnly}\n autoFocus={field.autoFocus}\n value={typeof stored === \"string\" ? stored : \"\"}\n onChange={(event) => onChange(event.target.value)}\n />\n );\n case \"number\":\n return (\n <NumberControl\n field={field}\n {...shared}\n />\n );\n case \"boolean\":\n return (\n <Switch\n {...accessibility}\n isDisabled={isDisabled}\n autoFocus={field.autoFocus}\n isSelected={stored === true}\n onSelectedChange={onChange}\n />\n );\n case \"dateTime\":\n return (\n <TextField\n {...accessibility}\n required={required}\n disabled={isDisabled}\n type=\"datetime-local\"\n step=\"0.001\"\n autoFocus={field.autoFocus}\n value={parseUtcDateTime(stored)?.slice(0, -1) ?? \"\"}\n onChange={(event) => onChange(parseUtcDateTime(`${event.target.value}Z`))}\n />\n );\n case \"richText\":\n return (\n <RichTextEditor\n {...accessibility}\n label={field.label}\n isRequired={required}\n isDisabled={isDisabled}\n placeholder={field.placeholder}\n format=\"json\"\n value={stored === undefined ? emptyDocument : (stored as RichTextDocument)}\n onChange={onChange}\n />\n );\n case \"select\":\n return (\n <SelectControl\n field={field}\n {...shared}\n />\n );\n case \"asset\":\n case \"reference\":\n return (\n <PickerControl\n field={field}\n items={items}\n selected={selected ?? []}\n {...shared}\n />\n );\n }\n}\n","import { useMemo, useState, type CSSProperties, type HTMLAttributes } from \"react\";\nimport type { EntryItem } from \"../EntryPicker\";\nimport { Field } from \"../Field\";\nimport type { GridColumns } from \"../Grid\";\nimport { FormControl } from \"./control\";\nimport {\n assertModel,\n fieldError,\n fieldLabel,\n selectedIds,\n type FormField,\n type FormSchema,\n type FormErrors,\n type FormFieldValue,\n type FormValues,\n} from \"./model\";\nimport \"./style.css\";\n\nexport { validateFormValues } from \"./model\";\nexport type {\n AssetValue,\n FormField,\n FormSchema,\n FormErrors,\n FormFieldValue,\n FormValues,\n ReferenceValue,\n} from \"./model\";\n\nexport interface FormChange {\n fieldId: string;\n}\n\nexport interface FormEditorProps extends Omit<\n HTMLAttributes<HTMLDivElement>,\n \"defaultValue\" | \"onChange\"\n> {\n schema: FormSchema;\n value?: FormValues;\n defaultValue?: FormValues;\n onValueChange?: (values: FormValues, change: FormChange) => void;\n /** Available assets or entries, keyed by field ID. Loading belongs to the app. */\n pickerItems?: Record<string, EntryItem[]>;\n /** App-provided messages take precedence over built-in validation. */\n errors?: FormErrors;\n isDisabled?: boolean;\n showAllErrors?: boolean;\n /** Columns at the widest. The form drops one whenever a field would be narrower than `minColumnWidth`. */\n columns?: GridColumns;\n /** Narrowest a field may get before the form drops a column. */\n minColumnWidth?: string;\n}\n\ninterface FormEditorFieldProps {\n field: FormField;\n stored: FormFieldValue | undefined;\n items: EntryItem[];\n isDisabled: boolean;\n error: string | undefined;\n isErrorVisible: boolean;\n onChange: (value: FormFieldValue | undefined) => void;\n}\n\n/** Validates only when its message can show, and only when its own field or value changes. */\nfunction FormEditorField({\n field,\n stored,\n items,\n isDisabled,\n error,\n isErrorVisible,\n onChange,\n}: FormEditorFieldProps) {\n const validation = useMemo(\n () => (error === undefined && isErrorVisible ? fieldError(field, stored) : undefined),\n [error, isErrorVisible, field, stored],\n );\n const selected = useMemo(\n () =>\n field.type === \"asset\" || field.type === \"reference\" ? selectedIds(field, stored) : undefined,\n [field, stored],\n );\n return (\n <Field\n label={field.type === \"dateTime\" ? `${field.label} (UTC)` : fieldLabel(field)}\n hint={field.hint}\n error={error ?? validation}\n isRequired={field.required}\n count={selected?.length}\n isGroup={selected !== undefined}\n >\n {(accessibility) => (\n <FormControl\n field={field}\n stored={stored}\n selected={selected}\n items={items}\n isDisabled={isDisabled}\n accessibility={accessibility}\n onChange={onChange}\n />\n )}\n </Field>\n );\n}\n\n/** Ordered form controls. Loading, submission, and persistence belong to the app. */\nexport function FormEditor({\n schema,\n value,\n defaultValue = {},\n onValueChange,\n pickerItems = {},\n errors = {},\n isDisabled = false,\n showAllErrors = false,\n columns = 1,\n minColumnWidth = \"16rem\",\n className,\n style,\n ...rest\n}: FormEditorProps) {\n const [internal, setInternal] = useState<FormValues>(defaultValue);\n const [changed, setChanged] = useState<Set<string>>(() => new Set());\n const current = value ?? internal;\n useMemo(() => assertModel(schema), [schema]);\n\n const commit = (fieldId: string, next: FormFieldValue | undefined) => {\n const values = { ...current };\n if (next === undefined) delete values[fieldId];\n else values[fieldId] = next;\n if (value === undefined) setInternal(values);\n setChanged((previous) => new Set(previous).add(fieldId));\n onValueChange?.(values, { fieldId });\n };\n\n const layout =\n columns === \"auto\"\n ? { \"--form-editor-min-column\": minColumnWidth }\n : { \"--form-editor-columns\": columns, \"--form-editor-min-column\": minColumnWidth };\n\n return (\n <div\n className={[\"ds-form-editor\", columns === \"auto\" && \"ds-form-editor--auto\", className]\n .filter(Boolean)\n .join(\" \")}\n style={{ ...layout, ...style } as CSSProperties}\n {...rest}\n >\n {schema.fields.map((field) => {\n const stored = Object.hasOwn(current, field.id) ? current[field.id] : undefined;\n const fieldDisabled = isDisabled || Boolean(field.isDisabled);\n const isLocked = fieldDisabled || (\"readOnly\" in field && Boolean(field.readOnly));\n // NumberField marks an out-of-range number invalid itself, so its message shows straight away.\n const isErrorVisible =\n showAllErrors ||\n changed.has(field.id) ||\n (field.type === \"number\" && typeof stored === \"number\");\n return (\n <FormEditorField\n key={field.id}\n field={field}\n stored={stored}\n items={pickerItems[field.id] ?? []}\n isDisabled={fieldDisabled}\n error={errors[field.id]}\n isErrorVisible={isErrorVisible}\n onChange={(next) => {\n if (!isLocked) commit(field.id, next);\n }}\n />\n );\n })}\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;AAiFA,IAAMG,oBAAa,IAAI,IAAI;CACzB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,SAAgBC,EAAY,GAAmB;CAC7C,IAAMC,oBAAM,IAAI,IAAY;CAC5B,KAAK,IAAMC,KAASC,EAAM,QAAQ;EAChC,IAAI,CAACD,EAAM,IAAI,KAAK,KAAKD,EAAI,IAAIC,EAAM,EAAE,GACvC,MAAU,MAAM,6CAA6C;EAC/D,IAAI,CAACH,EAAW,IAAIG,EAAM,IAAI,GAAG,MAAU,MAAM,gCAAgCA,EAAM,MAAM;EAC7F,IAAIA,EAAM,SAAS,YAAY,CAAC,MAAM,QAAQA,EAAM,OAAO,GACzD,MAAU,MAAM,gBAAgBA,EAAM,GAAG,yBAAyB;EACpE,EAAI,IAAIA,EAAM,EAAE;CAClB;AACF;AAEA,IAAME,IAAW;CACf,OAAO;EAAE,KAAK;EAAW,WAAW;EAAS,YAAY;CAAS;CAClE,WAAW;EAAE,KAAK;EAAW,WAAW;EAAS,YAAY;CAAU;AACzE;AAGA,SAAgBC,EAAW,GAA0B;CACnD,OAAOH,EAAM,SAAS,WAAWA,EAAM,SAAS,cAC3CA,EAAM,QAAQ,SAASA,EAAM,QAC9BA,EAAM;AACZ;AAGA,SAAgBI,EAAW,GAAuC;CAChE,IAAMC,IAAWH,EAASF,EAAM,OAC1B,EACJ,cAAW,UAAUG,EAAWH,CAAK,KACrC,eACA,eAAYK,EAAS,WACrB,gBAAaA,EAAS,YACtB,QACA,qBACEL,EAAM,UAAU,CAAC;CAC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IAAS,EAAE,GAAGoC,EAAQ;EAK5B,AAJI7B,MAAS,KAAA,IAAW,OAAOP,EAAOuC,KACjC,EAAOA,KAAWhC,GACnB/B,MAAU,KAAA,KAAWuD,EAAY/B,CAAM,GAC3CmC,GAAY,MAAa,IAAI,IAAIK,CAAQ,CAAC,CAAC,IAAID,CAAO,CAAC,GACvDE,IAAgBzC,GAAQ,EAAE,WAAQ,CAAC;CACrC,GAEM0C,IACJC,MAAY,SACR,EAAE,4BAA4BC,EAAe,IAC7C;EAAE,yBAAyBD;EAAS,4BAA4BC;CAAe;CAErF,OACE,kBAAC,OAAD;EACE,WAAW;GAAC;GAAkBD,MAAY,UAAU;GAAwBE;EAAS,CAAC,CACnF,OAAO,OAAO,CAAC,CACf,KAAK,GAAG;EACX,OAAO;GAAE,GAAGH;GAAQ,GAAGI;EAAM;EAC7B,GAAIjB;EAEH,UAAAQ,EAAO,OAAO,KAAK,MAAU;GAC5B,IAAM/B,IAAS,OAAO,OAAO8B,GAASnE,EAAM,EAAE,IAAImE,EAAQnE,EAAM,MAAM,KAAA,GAChE8E,IAAgB5B,KAAc,EAAQlD,EAAM,YAC5C+E,IAAWD,KAAkB,cAAc9E,KAAS,EAAQA,EAAM,UAElEyD,IACJuB,KACAf,EAAQ,IAAIjE,EAAM,EAAE,KACnBA,EAAM,SAAS,YAAY,OAAOqC,KAAW;GAChD,OACE,kBAACiB,GAAD;IAES;IACC;IACR,OAAO2B,EAAYjF,EAAM,OAAO,CAAC;IACjC,YAAY8E;IACZ,OAAOI,EAAOlF,EAAM;IACJ;IAChB,WAAW,MAAS;KAClB,AAAK+E,KAAUV,EAAOrE,EAAM,IAAIsC,CAAI;IACtC;GACD,GAVMtC,EAAM,EAUZ;EAEL,CAAC;CACE,CAAA;AAET"}
@@ -0,0 +1,2 @@
1
+ const e=require("../components/Field/index.cjs"),t=require("../components/TextField/index.cjs"),n=require("./RichTextEditor-C7nMfDmE.cjs"),r=require("../components/EntryPicker/index.cjs"),i=require("../components/NumberField/index.cjs"),a=require("../components/Select/index.cjs"),o=require("../components/Switch/index.cjs");let s=require("react"),c=require("react/jsx-runtime");var l=new Set([`shortText`,`longText`,`richText`,`number`,`boolean`,`dateTime`,`asset`,`reference`,`select`]);function u(e){let t=new Set;for(let n of e.fields){if(!n.id?.trim()||t.has(n.id))throw Error(`Form field IDs must be nonempty and unique.`);if(!l.has(n.type))throw Error(`Unsupported form field type: ${n.type}`);if(n.type===`select`&&!Array.isArray(n.options))throw Error(`Select field ${n.id} needs an options array.`);t.add(n.id)}}var d={asset:{key:`assetId`,itemLabel:`asset`,itemsLabel:`assets`},reference:{key:`entryId`,itemLabel:`entry`,itemsLabel:`entries`}};function f(e){return e.type===`asset`||e.type===`reference`?e.picker?.label??e.label:e.label}function p(e){let t=d[e.type],{addLabel:n=`Choose ${f(e)}`,emptyLabel:r,itemLabel:i=t.itemLabel,itemsLabel:a=t.itemsLabel,max:o,isReorderable:s}=e.picker??{};return{addLabel:n,emptyLabel:r,itemLabel:i,itemsLabel:a,max:o,isReorderable:s}}function m(e,t){let{key:n}=d[e.type];return(Array.isArray(t)?t:t===void 0?[]:[t]).flatMap(e=>g(e,n)?[e[n]]:[])}function h(e){if(typeof e!=`string`)return;let t=/^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2})(?::(\d{2})(?:\.(\d{1,3}))?)?(?:Z|\+00:00)$/.exec(e);if(!t)return;let n=`${t[1]}:${t[2]??`00`}.${(t[3]??``).padEnd(3,`0`)}Z`,r=new Date(n);if(Number.isFinite(r.getTime())&&r.toISOString()===n)return n}function g(e,t){return!!e&&typeof e==`object`&&t in e&&typeof e[t]==`string`&&e[t].trim().length>0}function _(e){return!!e.text?.trim()||e.type===`horizontalRule`||!!e.content?.some(_)}function v(e){return`${f(e)} is required.`}function y(e,t){if(typeof t!=`string`)return`Enter text.`;if(e.required&&!t.trim())return v(e);if((e.type===`shortText`||e.type===`longText`)&&e.maxLength!==void 0&&t.length>e.maxLength)return`Enter no more than ${e.maxLength} characters.`}function b(e,t){let r=n.n(t);if(r)return r;if(e.required&&!_(t))return v(e)}function x(e,t){if(typeof t!=`string`)return`Choose an available option.`;if(t===``)return e.required?v(e):void 0;if(e.type===`select`&&e.options.length>0&&!e.options.some(e=>e.value===t))return`Choose an available option.`}function S(e,t){if(e.type!==`asset`&&e.type!==`reference`)return;let{key:n,itemLabel:r,itemsLabel:i}=d[e.type];if(!e.multiple)return g(t,n)?void 0:`Choose an ${r}.`;if(!Array.isArray(t)||!t.every(e=>g(e,n)))return`Choose a list of ${i}.`;if(e.required&&t.length===0)return v(e);let a=e.picker?.max;if(a!==void 0&&t.length>a)return`Choose no more than ${a} ${p(e).itemsLabel}.`}var C={shortText:y,longText:y,richText:b,number:(e,t)=>{if(typeof t!=`number`||!Number.isFinite(t))return`Enter a finite number.`;if(e.type===`number`){if(e.min!==void 0&&t<e.min)return`Enter a number of at least ${e.min}.`;if(e.max!==void 0&&t>e.max)return`Enter a number no greater than ${e.max}.`}},boolean:(e,t)=>typeof t==`boolean`?void 0:`Choose a boolean value.`,dateTime:(e,t)=>h(t)?void 0:`Enter a valid UTC date and time.`,select:x,asset:S,reference:S};function w(e,t){return t===void 0?e.required?v(e):void 0:C[e.type](e,t)}function T(e,t){return u(e),Object.fromEntries(e.fields.flatMap(e=>{let n=w(e,Object.hasOwn(t,e.id)?t[e.id]:void 0);return n?[[e.id,n]]:[]}))}function E(e,t){if(e.type===`asset`){let n=t.map(e=>({assetId:e}));return e.multiple?n:n[0]}let n=t.map(e=>({entryId:e}));return e.multiple?n:n[0]}function D({field:e,stored:t,isDisabled:n,required:r,accessibility:a,onChange:o}){return(0,c.jsx)(i.NumberField,{...a,required:r,isDisabled:n,placeholder:e.placeholder,min:e.min,max:e.max,step:e.step??`any`,hasSteppers:e.hasSteppers??!1,autoFocus:e.autoFocus,decreaseLabel:`Decrease ${e.label}`,increaseLabel:`Increase ${e.label}`,value:typeof t==`number`&&Number.isFinite(t)?t:``,onValueChange:e=>{(e===``||Number.isFinite(e))&&o(e===``?void 0:e)}})}function O({field:e,stored:t,isDisabled:n,required:r,accessibility:i,onChange:o}){let s=!r&&!e.options.some(e=>e.value===``);return(0,c.jsx)(a.Select,{...i,"aria-required":r||void 0,isDisabled:n,isInvalid:i[`aria-invalid`],options:s?[{value:``,label:e.placeholder??`None`},...e.options]:e.options,placeholder:e.placeholder,autoFocus:e.autoFocus,value:typeof t==`string`?t:``,onValueChange:e=>o(e===``?void 0:e)})}function k({field:e,selected:t,items:n,isDisabled:i,accessibility:a,onChange:o}){return(0,c.jsx)(r.EntryPicker,{...a,items:n,value:t,...p(e),mode:e.multiple?`multiple`:`single`,isDisabled:i,onValueChange:t=>o(E(e,t))})}function A({field:e,stored:r,selected:i,items:a,isDisabled:s,accessibility:{required:l,...u},onChange:d}){let f={stored:r,isDisabled:s,required:l,accessibility:u,onChange:d};switch(e.type){case`shortText`:return(0,c.jsx)(t.TextField,{...u,required:l,disabled:s,placeholder:e.placeholder,type:e.inputType,maxLength:e.maxLength,readOnly:e.readOnly,autoFocus:e.autoFocus,value:typeof r==`string`?r:``,onChange:e=>d(e.target.value)});case`longText`:return(0,c.jsx)(t.TextArea,{...u,required:l,disabled:s,placeholder:e.placeholder,rows:e.rows,maxLength:e.maxLength,readOnly:e.readOnly,autoFocus:e.autoFocus,value:typeof r==`string`?r:``,onChange:e=>d(e.target.value)});case`number`:return(0,c.jsx)(D,{field:e,...f});case`boolean`:return(0,c.jsx)(o.Switch,{...u,isDisabled:s,autoFocus:e.autoFocus,isSelected:r===!0,onSelectedChange:d});case`dateTime`:return(0,c.jsx)(t.TextField,{...u,required:l,disabled:s,type:`datetime-local`,step:`0.001`,autoFocus:e.autoFocus,value:h(r)?.slice(0,-1)??``,onChange:e=>d(h(`${e.target.value}Z`))});case`richText`:return(0,c.jsx)(n.t,{...u,label:e.label,isRequired:l,isDisabled:s,placeholder:e.placeholder,format:`json`,value:r===void 0?n.r:r,onChange:d});case`select`:return(0,c.jsx)(O,{field:e,...f});case`asset`:case`reference`:return(0,c.jsx)(k,{field:e,items:a,selected:i??[],...f})}}function j({field:t,stored:n,items:r,isDisabled:i,error:a,isErrorVisible:o,onChange:l}){let u=(0,s.useMemo)(()=>a===void 0&&o?w(t,n):void 0,[a,o,t,n]),d=(0,s.useMemo)(()=>t.type===`asset`||t.type===`reference`?m(t,n):void 0,[t,n]);return(0,c.jsx)(e.Field,{label:t.type===`dateTime`?`${t.label} (UTC)`:f(t),hint:t.hint,error:a??u,isRequired:t.required,count:d?.length,isGroup:d!==void 0,children:e=>(0,c.jsx)(A,{field:t,stored:n,selected:d,items:r,isDisabled:i,accessibility:e,onChange:l})})}function M({schema:e,value:t,defaultValue:n={},onValueChange:r,pickerItems:i={},errors:a={},isDisabled:o=!1,showAllErrors:l=!1,columns:d=1,minColumnWidth:f=`16rem`,className:p,style:m,...h}){let[g,_]=(0,s.useState)(n),[v,y]=(0,s.useState)(()=>new Set),b=t??g;(0,s.useMemo)(()=>u(e),[e]);let x=(e,n)=>{let i={...b};n===void 0?delete i[e]:i[e]=n,t===void 0&&_(i),y(t=>new Set(t).add(e)),r?.(i,{fieldId:e})},S=d===`auto`?{"--form-editor-min-column":f}:{"--form-editor-columns":d,"--form-editor-min-column":f};return(0,c.jsx)(`div`,{className:[`ds-form-editor`,d===`auto`&&`ds-form-editor--auto`,p].filter(Boolean).join(` `),style:{...S,...m},...h,children:e.fields.map(e=>{let t=Object.hasOwn(b,e.id)?b[e.id]:void 0,n=o||!!e.isDisabled,r=n||`readOnly`in e&&!!e.readOnly,s=l||v.has(e.id)||e.type===`number`&&typeof t==`number`;return(0,c.jsx)(j,{field:e,stored:t,items:i[e.id]??[],isDisabled:n,error:a[e.id],isErrorVisible:s,onChange:t=>{r||x(e.id,t)}},e.id)})})}Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return T}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return M}});
2
+ //# sourceMappingURL=FormEditor-PVkvKep1.cjs.map