@namroodinc/liquid-editorial 0.3.2 → 0.4.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 (155) hide show
  1. package/AGENTS.md +4 -0
  2. package/README.md +1576 -180
  3. package/UPGRADING.md +215 -0
  4. package/dist/chunks/ColourField-CJicr3OT.cjs +2 -0
  5. package/dist/chunks/ColourField-CJicr3OT.cjs.map +1 -0
  6. package/dist/chunks/{ColourField-C2YDshDg.js → ColourField-DjHRiFDU.js} +167 -162
  7. package/dist/chunks/ColourField-DjHRiFDU.js.map +1 -0
  8. package/dist/chunks/DatePicker-D_6CQpUd.js +296 -0
  9. package/dist/chunks/DatePicker-D_6CQpUd.js.map +1 -0
  10. package/dist/chunks/DatePicker-aSlYLjtW.cjs +2 -0
  11. package/dist/chunks/DatePicker-aSlYLjtW.cjs.map +1 -0
  12. package/dist/chunks/FormEditor-M7tNidFo.js +584 -0
  13. package/dist/chunks/FormEditor-M7tNidFo.js.map +1 -0
  14. package/dist/chunks/FormEditor-UzbPdiJo.cjs +2 -0
  15. package/dist/chunks/FormEditor-UzbPdiJo.cjs.map +1 -0
  16. package/dist/chunks/Slider-k8weRl34.cjs +2 -0
  17. package/dist/chunks/Slider-k8weRl34.cjs.map +1 -0
  18. package/dist/chunks/Slider-vdMFLX-H.js +174 -0
  19. package/dist/chunks/Slider-vdMFLX-H.js.map +1 -0
  20. package/dist/chunks/dialogFocus-B9iqKl3I.cjs +2 -0
  21. package/dist/chunks/dialogFocus-B9iqKl3I.cjs.map +1 -0
  22. package/dist/chunks/dialogFocus-BFoyeTpA.js +48 -0
  23. package/dist/chunks/dialogFocus-BFoyeTpA.js.map +1 -0
  24. package/dist/components/Choice/index.cjs +1 -1
  25. package/dist/components/Choice/index.cjs.map +1 -1
  26. package/dist/components/Choice/index.d.cts.map +1 -1
  27. package/dist/components/Choice/index.d.ts.map +1 -1
  28. package/dist/components/Choice/index.js +2 -0
  29. package/dist/components/Choice/index.js.map +1 -1
  30. package/dist/components/ColourField/focus.d.cts +0 -1
  31. package/dist/components/ColourField/focus.d.cts.map +1 -1
  32. package/dist/components/ColourField/focus.d.ts +0 -1
  33. package/dist/components/ColourField/focus.d.ts.map +1 -1
  34. package/dist/components/ColourField/index.cjs +1 -1
  35. package/dist/components/ColourField/index.d.cts.map +1 -1
  36. package/dist/components/ColourField/index.d.ts.map +1 -1
  37. package/dist/components/ColourField/index.js +1 -1
  38. package/dist/components/ColourField/value.d.cts +6 -0
  39. package/dist/components/ColourField/value.d.cts.map +1 -1
  40. package/dist/components/ColourField/value.d.ts +6 -0
  41. package/dist/components/ColourField/value.d.ts.map +1 -1
  42. package/dist/components/DatePicker/date.d.cts +9 -0
  43. package/dist/components/DatePicker/date.d.cts.map +1 -0
  44. package/dist/components/DatePicker/date.d.ts +9 -0
  45. package/dist/components/DatePicker/date.d.ts.map +1 -0
  46. package/dist/components/DatePicker/index.cjs +1 -2
  47. package/dist/components/DatePicker/index.d.cts +9 -6
  48. package/dist/components/DatePicker/index.d.cts.map +1 -1
  49. package/dist/components/DatePicker/index.d.ts +9 -6
  50. package/dist/components/DatePicker/index.d.ts.map +1 -1
  51. package/dist/components/DatePicker/index.js +1 -259
  52. package/dist/components/DatePicker/style.css +5 -0
  53. package/dist/components/Drawer/index.cjs +1 -1
  54. package/dist/components/Drawer/index.cjs.map +1 -1
  55. package/dist/components/Drawer/index.d.cts.map +1 -1
  56. package/dist/components/Drawer/index.d.ts.map +1 -1
  57. package/dist/components/Drawer/index.js +69 -73
  58. package/dist/components/Drawer/index.js.map +1 -1
  59. package/dist/components/EditLayout/index.cjs +1 -1
  60. package/dist/components/EditLayout/index.cjs.map +1 -1
  61. package/dist/components/EditLayout/index.d.cts.map +1 -1
  62. package/dist/components/EditLayout/index.d.ts.map +1 -1
  63. package/dist/components/EditLayout/index.js +68 -55
  64. package/dist/components/EditLayout/index.js.map +1 -1
  65. package/dist/components/Field/style.css +20 -0
  66. package/dist/components/FormEditor/README.md +375 -0
  67. package/dist/components/FormEditor/additional-control.d.cts +6 -0
  68. package/dist/components/FormEditor/additional-control.d.cts.map +1 -0
  69. package/dist/components/FormEditor/additional-control.d.ts +6 -0
  70. package/dist/components/FormEditor/additional-control.d.ts.map +1 -0
  71. package/dist/components/FormEditor/choice-control.d.cts +6 -0
  72. package/dist/components/FormEditor/choice-control.d.cts.map +1 -0
  73. package/dist/components/FormEditor/choice-control.d.ts +6 -0
  74. package/dist/components/FormEditor/choice-control.d.ts.map +1 -0
  75. package/dist/components/FormEditor/control.d.cts +8 -0
  76. package/dist/components/FormEditor/control.d.cts.map +1 -1
  77. package/dist/components/FormEditor/control.d.ts +8 -0
  78. package/dist/components/FormEditor/control.d.ts.map +1 -1
  79. package/dist/components/FormEditor/index.cjs +1 -1
  80. package/dist/components/FormEditor/index.d.cts +1 -1
  81. package/dist/components/FormEditor/index.d.cts.map +1 -1
  82. package/dist/components/FormEditor/index.d.ts +1 -1
  83. package/dist/components/FormEditor/index.d.ts.map +1 -1
  84. package/dist/components/FormEditor/index.js +1 -1
  85. package/dist/components/FormEditor/model.d.cts +68 -2
  86. package/dist/components/FormEditor/model.d.cts.map +1 -1
  87. package/dist/components/FormEditor/model.d.ts +68 -2
  88. package/dist/components/FormEditor/model.d.ts.map +1 -1
  89. package/dist/components/FormEditor/style.css +12 -0
  90. package/dist/components/Grid/style.css +2 -1
  91. package/dist/components/ImageCropper/index.cjs +1 -1
  92. package/dist/components/ImageCropper/index.cjs.map +1 -1
  93. package/dist/components/ImageCropper/index.js +6 -6
  94. package/dist/components/ImageCropper/index.js.map +1 -1
  95. package/dist/components/Modal/index.cjs +1 -1
  96. package/dist/components/Modal/index.cjs.map +1 -1
  97. package/dist/components/Modal/index.d.cts.map +1 -1
  98. package/dist/components/Modal/index.d.ts.map +1 -1
  99. package/dist/components/Modal/index.js +40 -48
  100. package/dist/components/Modal/index.js.map +1 -1
  101. package/dist/components/NumberField/index.cjs +1 -1
  102. package/dist/components/NumberField/index.cjs.map +1 -1
  103. package/dist/components/NumberField/index.d.cts.map +1 -1
  104. package/dist/components/NumberField/index.d.ts.map +1 -1
  105. package/dist/components/NumberField/index.js +4 -0
  106. package/dist/components/NumberField/index.js.map +1 -1
  107. package/dist/components/Popover/index.cjs +1 -1
  108. package/dist/components/Popover/index.cjs.map +1 -1
  109. package/dist/components/Popover/index.d.cts +2 -0
  110. package/dist/components/Popover/index.d.cts.map +1 -1
  111. package/dist/components/Popover/index.d.ts +2 -0
  112. package/dist/components/Popover/index.d.ts.map +1 -1
  113. package/dist/components/Popover/index.js +45 -44
  114. package/dist/components/Popover/index.js.map +1 -1
  115. package/dist/components/SelectionCard/index.cjs +1 -1
  116. package/dist/components/SelectionCard/index.cjs.map +1 -1
  117. package/dist/components/SelectionCard/index.d.cts.map +1 -1
  118. package/dist/components/SelectionCard/index.d.ts.map +1 -1
  119. package/dist/components/SelectionCard/index.js +2 -1
  120. package/dist/components/SelectionCard/index.js.map +1 -1
  121. package/dist/components/Slider/index.cjs +1 -2
  122. package/dist/components/Slider/index.d.cts +14 -1
  123. package/dist/components/Slider/index.d.cts.map +1 -1
  124. package/dist/components/Slider/index.d.ts +14 -1
  125. package/dist/components/Slider/index.d.ts.map +1 -1
  126. package/dist/components/Slider/index.js +1 -127
  127. package/dist/components/Slider/scale.d.cts +13 -0
  128. package/dist/components/Slider/scale.d.cts.map +1 -0
  129. package/dist/components/Slider/scale.d.ts +13 -0
  130. package/dist/components/Slider/scale.d.ts.map +1 -0
  131. package/dist/elements.css +9 -0
  132. package/dist/index.cjs +1 -1
  133. package/dist/index.d.cts +1 -1
  134. package/dist/index.d.cts.map +1 -1
  135. package/dist/index.d.ts +1 -1
  136. package/dist/index.d.ts.map +1 -1
  137. package/dist/index.js +20 -20
  138. package/dist/internal/dialogFocus.d.cts +17 -0
  139. package/dist/internal/dialogFocus.d.cts.map +1 -0
  140. package/dist/internal/dialogFocus.d.ts +17 -0
  141. package/dist/internal/dialogFocus.d.ts.map +1 -0
  142. package/dist/reset.css +2 -0
  143. package/dist/styles.css +1 -0
  144. package/package.json +2 -2
  145. package/dist/chunks/ColourField-C2YDshDg.js.map +0 -1
  146. package/dist/chunks/ColourField-Dc9533G6.cjs +0 -2
  147. package/dist/chunks/ColourField-Dc9533G6.cjs.map +0 -1
  148. package/dist/chunks/FormEditor-DRmPFe2E.js +0 -328
  149. package/dist/chunks/FormEditor-DRmPFe2E.js.map +0 -1
  150. package/dist/chunks/FormEditor-PVkvKep1.cjs +0 -2
  151. package/dist/chunks/FormEditor-PVkvKep1.cjs.map +0 -1
  152. package/dist/components/DatePicker/index.cjs.map +0 -1
  153. package/dist/components/DatePicker/index.js.map +0 -1
  154. package/dist/components/Slider/index.cjs.map +0 -1
  155. package/dist/components/Slider/index.js.map +0 -1
@@ -1,328 +0,0 @@
1
- import { Field as e } from "../components/Field/index.js";
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-DjR10XJ-.js";
4
- import { EntryPicker as o } from "../components/EntryPicker/index.js";
5
- import { NumberField as s } from "../components/NumberField/index.js";
6
- import { Select as c } from "../components/Select/index.js";
7
- import { Switch as l } from "../components/Switch/index.js";
8
- import { useMemo as u, useState as d } from "react";
9
- import { jsx as f } from "react/jsx-runtime";
10
- //#region src/components/FormEditor/model.ts
11
- var p = /* @__PURE__ */ new Set([
12
- "shortText",
13
- "longText",
14
- "richText",
15
- "number",
16
- "boolean",
17
- "dateTime",
18
- "asset",
19
- "reference",
20
- "select"
21
- ]);
22
- function m(e) {
23
- let t = /* @__PURE__ */ new Set();
24
- for (let n of e.fields) {
25
- if (!n.id?.trim() || t.has(n.id)) throw Error("Form field IDs must be nonempty and unique.");
26
- if (!p.has(n.type)) throw Error(`Unsupported form field type: ${n.type}`);
27
- if (n.type === "select" && !Array.isArray(n.options)) throw Error(`Select field ${n.id} needs an options array.`);
28
- t.add(n.id);
29
- }
30
- }
31
- var h = {
32
- asset: {
33
- key: "assetId",
34
- itemLabel: "asset",
35
- itemsLabel: "assets"
36
- },
37
- reference: {
38
- key: "entryId",
39
- itemLabel: "entry",
40
- itemsLabel: "entries"
41
- }
42
- };
43
- function g(e) {
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 ?? {};
48
- return {
49
- addLabel: n,
50
- emptyLabel: r,
51
- itemLabel: i,
52
- itemsLabel: a,
53
- max: o,
54
- isReorderable: s
55
- };
56
- }
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) {
62
- if (typeof e != "string") return;
63
- let t = /^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2})(?::(\d{2})(?:\.(\d{1,3}))?)?(?:Z|\+00:00)$/.exec(e);
64
- if (!t) return;
65
- let n = `${t[1]}:${t[2] ?? "00"}.${(t[3] ?? "").padEnd(3, "0")}Z`, r = new Date(n);
66
- if (Number.isFinite(r.getTime()) && r.toISOString() === n) return n;
67
- }
68
- function b(e, t) {
69
- return !!e && typeof e == "object" && t in e && typeof e[t] == "string" && e[t].trim().length > 0;
70
- }
71
- function x(e) {
72
- return !!e.text?.trim() || e.type === "horizontalRule" || !!e.content?.some(x);
73
- }
74
- function S(e) {
75
- return `${g(e)} is required.`;
76
- }
77
- function C(e, t) {
78
- if (typeof t != "string") return "Enter text.";
79
- if (e.required && !t.trim()) return S(e);
80
- if ((e.type === "shortText" || e.type === "longText") && e.maxLength !== void 0 && t.length > e.maxLength) return `Enter no more than ${e.maxLength} characters.`;
81
- }
82
- function w(e, t) {
83
- let n = r(t);
84
- if (n) return n;
85
- if (e.required && !x(t)) return S(e);
86
- }
87
- function T(e, t) {
88
- if (typeof t != "string") return "Choose an available option.";
89
- if (t === "") return e.required ? S(e) : void 0;
90
- if (e.type === "select" && e.options.length > 0 && !e.options.some((e) => e.value === t)) return "Choose an available option.";
91
- }
92
- function E(e, t) {
93
- if (e.type !== "asset" && e.type !== "reference") return;
94
- let { key: n, itemLabel: r, itemsLabel: i } = h[e.type];
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);
98
- let a = e.picker?.max;
99
- if (a !== void 0 && t.length > a) return `Choose no more than ${a} ${_(e).itemsLabel}.`;
100
- }
101
- var D = {
102
- shortText: C,
103
- longText: C,
104
- richText: w,
105
- number: (e, t) => {
106
- if (typeof t != "number" || !Number.isFinite(t)) return "Enter a finite number.";
107
- if (e.type === "number") {
108
- if (e.min !== void 0 && t < e.min) return `Enter a number of at least ${e.min}.`;
109
- if (e.max !== void 0 && t > e.max) return `Enter a number no greater than ${e.max}.`;
110
- }
111
- },
112
- boolean: (e, t) => typeof t == "boolean" ? void 0 : "Choose a boolean value.",
113
- dateTime: (e, t) => y(t) ? void 0 : "Enter a valid UTC date and time.",
114
- select: T,
115
- asset: E,
116
- reference: E
117
- };
118
- function O(e, t) {
119
- return t === void 0 ? e.required ? S(e) : void 0 : D[e.type](e, t);
120
- }
121
- function k(e, t) {
122
- return m(e), Object.fromEntries(e.fields.flatMap((e) => {
123
- let n = O(e, Object.hasOwn(t, e.id) ? t[e.id] : void 0);
124
- return n ? [[e.id, n]] : [];
125
- }));
126
- }
127
- //#endregion
128
- //#region src/components/FormEditor/control.tsx
129
- function A(e, t) {
130
- if (e.type === "asset") {
131
- let n = t.map((e) => ({ assetId: e }));
132
- return e.multiple ? n : n[0];
133
- }
134
- let n = t.map((e) => ({ entryId: e }));
135
- return e.multiple ? n : n[0];
136
- }
137
- function j({ field: e, stored: t, isDisabled: n, required: r, accessibility: i, onChange: a }) {
138
- return /* @__PURE__ */ f(s, {
139
- ...i,
140
- required: r,
141
- isDisabled: n,
142
- placeholder: e.placeholder,
143
- min: e.min,
144
- max: e.max,
145
- step: e.step ?? "any",
146
- hasSteppers: e.hasSteppers ?? !1,
147
- autoFocus: e.autoFocus,
148
- decreaseLabel: `Decrease ${e.label}`,
149
- increaseLabel: `Increase ${e.label}`,
150
- value: typeof t == "number" && Number.isFinite(t) ? t : "",
151
- onValueChange: (e) => {
152
- (e === "" || Number.isFinite(e)) && a(e === "" ? void 0 : e);
153
- }
154
- });
155
- }
156
- function M({ field: e, stored: t, isDisabled: n, required: r, accessibility: i, onChange: a }) {
157
- let o = !r && !e.options.some((e) => e.value === "");
158
- return /* @__PURE__ */ f(c, {
159
- ...i,
160
- "aria-required": r || void 0,
161
- isDisabled: n,
162
- isInvalid: i["aria-invalid"],
163
- options: o ? [{
164
- value: "",
165
- label: e.placeholder ?? "None"
166
- }, ...e.options] : e.options,
167
- placeholder: e.placeholder,
168
- autoFocus: e.autoFocus,
169
- value: typeof t == "string" ? t : "",
170
- onValueChange: (e) => a(e === "" ? void 0 : e)
171
- });
172
- }
173
- function N({ field: e, selected: t, items: n, isDisabled: r, accessibility: i, onChange: a }) {
174
- return /* @__PURE__ */ f(o, {
175
- ...i,
176
- items: n,
177
- value: t,
178
- ..._(e),
179
- mode: e.multiple ? "multiple" : "single",
180
- isDisabled: r,
181
- onValueChange: (t) => a(A(e, t))
182
- });
183
- }
184
- function P({ field: e, stored: r, selected: o, items: s, isDisabled: c, accessibility: { required: u, ...d }, onChange: p }) {
185
- let m = {
186
- stored: r,
187
- isDisabled: c,
188
- required: u,
189
- accessibility: d,
190
- onChange: p
191
- };
192
- switch (e.type) {
193
- case "shortText": return /* @__PURE__ */ f(n, {
194
- ...d,
195
- required: u,
196
- disabled: c,
197
- placeholder: e.placeholder,
198
- type: e.inputType,
199
- maxLength: e.maxLength,
200
- readOnly: e.readOnly,
201
- autoFocus: e.autoFocus,
202
- value: typeof r == "string" ? r : "",
203
- onChange: (e) => p(e.target.value)
204
- });
205
- case "longText": return /* @__PURE__ */ f(t, {
206
- ...d,
207
- required: u,
208
- disabled: c,
209
- placeholder: e.placeholder,
210
- rows: e.rows,
211
- maxLength: e.maxLength,
212
- readOnly: e.readOnly,
213
- autoFocus: e.autoFocus,
214
- value: typeof r == "string" ? r : "",
215
- onChange: (e) => p(e.target.value)
216
- });
217
- case "number": return /* @__PURE__ */ f(j, {
218
- field: e,
219
- ...m
220
- });
221
- case "boolean": return /* @__PURE__ */ f(l, {
222
- ...d,
223
- isDisabled: c,
224
- autoFocus: e.autoFocus,
225
- isSelected: r === !0,
226
- onSelectedChange: p
227
- });
228
- case "dateTime": return /* @__PURE__ */ f(n, {
229
- ...d,
230
- required: u,
231
- disabled: c,
232
- type: "datetime-local",
233
- step: "0.001",
234
- autoFocus: e.autoFocus,
235
- value: y(r)?.slice(0, -1) ?? "",
236
- onChange: (e) => p(y(`${e.target.value}Z`))
237
- });
238
- case "richText": return /* @__PURE__ */ f(a, {
239
- ...d,
240
- label: e.label,
241
- isRequired: u,
242
- isDisabled: c,
243
- placeholder: e.placeholder,
244
- format: "json",
245
- value: r === void 0 ? i : r,
246
- onChange: p
247
- });
248
- case "select": return /* @__PURE__ */ f(M, {
249
- field: e,
250
- ...m
251
- });
252
- case "asset":
253
- case "reference": return /* @__PURE__ */ f(N, {
254
- field: e,
255
- items: s,
256
- selected: o ?? [],
257
- ...m
258
- });
259
- }
260
- }
261
- //#endregion
262
- //#region src/components/FormEditor/index.tsx
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, [
265
- a,
266
- o,
267
- t,
268
- n
269
- ]), l = u(() => t.type === "asset" || t.type === "reference" ? v(t, n) : void 0, [t, n]);
270
- return /* @__PURE__ */ f(e, {
271
- label: t.type === "dateTime" ? `${t.label} (UTC)` : g(t),
272
- hint: t.hint,
273
- error: a ?? c,
274
- isRequired: t.required,
275
- count: l?.length,
276
- isGroup: l !== void 0,
277
- children: (e) => /* @__PURE__ */ f(P, {
278
- field: t,
279
- stored: n,
280
- selected: l,
281
- items: r,
282
- isDisabled: i,
283
- accessibility: e,
284
- onChange: s
285
- })
286
- });
287
- }
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 }) {
289
- let [_, v] = d(n), [y, b] = d(() => /* @__PURE__ */ new Set()), x = t ?? _;
290
- u(() => m(e), [e]);
291
- let S = (e, n) => {
292
- let i = { ...x };
293
- n === void 0 ? delete i[e] : i[e] = n, t === void 0 && v(i), b((t) => new Set(t).add(e)), r?.(i, { fieldId: e });
294
- }, C = c === "auto" ? { "--form-editor-min-column": l } : {
295
- "--form-editor-columns": c,
296
- "--form-editor-min-column": l
297
- };
298
- return /* @__PURE__ */ f("div", {
299
- className: [
300
- "ds-form-editor",
301
- c === "auto" && "ds-form-editor--auto",
302
- p
303
- ].filter(Boolean).join(" "),
304
- style: {
305
- ...C,
306
- ...h
307
- },
308
- ...g,
309
- children: e.fields.map((e) => {
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";
311
- return /* @__PURE__ */ f(F, {
312
- field: e,
313
- stored: t,
314
- items: i[e.id] ?? [],
315
- isDisabled: n,
316
- error: a[e.id],
317
- isErrorVisible: c,
318
- onChange: (t) => {
319
- r || S(e.id, t);
320
- }
321
- }, e.id);
322
- })
323
- });
324
- }
325
- //#endregion
326
- export { k as n, I as t };
327
-
328
- //# sourceMappingURL=FormEditor-DRmPFe2E.js.map
@@ -1 +0,0 @@
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 }\n if (!fieldTypes.has(field.type)) {\n throw new Error(`Unsupported form field type: ${field.type}`);\n }\n if (field.type === \"select\" && !Array.isArray(field.options)) {\n throw new Error(`Select field ${field.id} needs an options array.`);\n }\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\") {\n return;\n }\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) {\n return;\n }\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) {\n return canonical;\n }\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\") {\n return \"Enter text.\";\n }\n if (field.required && !value.trim()) {\n return requiredError(field);\n }\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) {\n return error;\n }\n if (field.required && !hasRichText(value as RichTextDocument)) {\n return requiredError(field);\n }\n}\n\nfunction choiceError(field: FormField, value: unknown): string | undefined {\n if (typeof value !== \"string\") {\n return \"Choose an available option.\";\n }\n if (value === \"\") {\n return field.required ? requiredError(field) : undefined;\n }\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\") {\n return;\n }\n const { key, itemLabel, itemsLabel } = linkCopy[field.type];\n if (!field.multiple) {\n return isLink(value, key) ? undefined : `Choose an ${itemLabel}.`;\n }\n if (!Array.isArray(value) || !value.every((item) => isLink(item, key))) {\n return `Choose a list of ${itemsLabel}.`;\n }\n if (field.required && value.length === 0) {\n return requiredError(field);\n }\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}\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)) {\n return \"Enter a finite number.\";\n }\n if (field.type !== \"number\") {\n return;\n }\n if (field.min !== undefined && value < field.min) {\n return `Enter a number of at least ${field.min}.`;\n }\n if (field.max !== undefined && value > field.max) {\n return `Enter a number no greater than ${field.max}.`;\n }\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) {\n return field.required ? requiredError(field) : undefined;\n }\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)) {\n onChange(next === \"\" ? undefined : next);\n }\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) {\n delete values[fieldId];\n } else {\n values[fieldId] = next;\n }\n if (value === undefined) {\n setInternal(values);\n }\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) {\n commit(field.id, next);\n }\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,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AO,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,KACHV,EAAOrE,EAAM,IAAIsC,CAAI;IAEzB;GACD,GAZMtC,EAAM,EAYZ;EAEL,CAAC;CACE,CAAA;AAET"}
@@ -1,2 +0,0 @@
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
@@ -1 +0,0 @@
1
- {"version":3,"file":"FormEditor-PVkvKep1.cjs","names":["documentError","NumberField","Select","EntryPicker","TextField","TextArea","Switch","RichTextEditor","emptyDocument","useMemo","Field","useState","require_components_Field_index","require_components_TextField_index","require_RichTextEditor","require_components_EntryPicker_index","require_components_NumberField_index","require_components_Select_index","require_components_Switch_index","react","react_jsx_runtime","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","accessibility","stored","next","onChange","SelectControl","isClearable","required","PickerControl","selected","FormControl","shared","isDisabled","event","FormEditorField","validation","isErrorVisible","FormEditor","rest","internal","setInternal","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 }\n if (!fieldTypes.has(field.type)) {\n throw new Error(`Unsupported form field type: ${field.type}`);\n }\n if (field.type === \"select\" && !Array.isArray(field.options)) {\n throw new Error(`Select field ${field.id} needs an options array.`);\n }\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\") {\n return;\n }\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) {\n return;\n }\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) {\n return canonical;\n }\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\") {\n return \"Enter text.\";\n }\n if (field.required && !value.trim()) {\n return requiredError(field);\n }\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) {\n return error;\n }\n if (field.required && !hasRichText(value as RichTextDocument)) {\n return requiredError(field);\n }\n}\n\nfunction choiceError(field: FormField, value: unknown): string | undefined {\n if (typeof value !== \"string\") {\n return \"Choose an available option.\";\n }\n if (value === \"\") {\n return field.required ? requiredError(field) : undefined;\n }\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\") {\n return;\n }\n const { key, itemLabel, itemsLabel } = linkCopy[field.type];\n if (!field.multiple) {\n return isLink(value, key) ? undefined : `Choose an ${itemLabel}.`;\n }\n if (!Array.isArray(value) || !value.every((item) => isLink(item, key))) {\n return `Choose a list of ${itemsLabel}.`;\n }\n if (field.required && value.length === 0) {\n return requiredError(field);\n }\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}\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)) {\n return \"Enter a finite number.\";\n }\n if (field.type !== \"number\") {\n return;\n }\n if (field.min !== undefined && value < field.min) {\n return `Enter a number of at least ${field.min}.`;\n }\n if (field.max !== undefined && value > field.max) {\n return `Enter a number no greater than ${field.max}.`;\n }\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) {\n return field.required ? requiredError(field) : undefined;\n }\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)) {\n onChange(next === \"\" ? undefined : next);\n }\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) {\n delete values[fieldId];\n } else {\n values[fieldId] = next;\n }\n if (value === undefined) {\n setInternal(values);\n }\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) {\n commit(field.id, next);\n }\n }}\n />\n );\n })}\n </div>\n );\n}\n"],"mappings":"A,2XAiFA,IAAMqB,EAAa,IAAI,IAAI,CACzB,YACA,WACA,WACA,SACA,UACA,WACA,QACA,YACA,QACF,CAAC,EAED,SAAgBC,EAAY,EAAmB,CAC7C,IAAMC,EAAM,IAAI,IAChB,IAAK,IAAMC,KAASC,EAAM,OAAQ,CAChC,GAAI,CAACD,EAAM,IAAI,KAAK,GAAKD,EAAI,IAAIC,EAAM,EAAE,EACvC,MAAU,MAAM,6CAA6C,EAE/D,GAAI,CAACH,EAAW,IAAIG,EAAM,IAAI,EAC5B,MAAU,MAAM,gCAAgCA,EAAM,MAAM,EAE9D,GAAIA,EAAM,OAAS,UAAY,CAAC,MAAM,QAAQA,EAAM,OAAO,EACzD,MAA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,CAAE,2BAA4BC,CAAe,EAC7C,CAAE,wBAAyBD,EAAS,2BAA4BC,CAAe,EAErF,OACE,EAAAtE,EAAA,IAAA,CAAC,MAAD,CACE,UAAW,CAAC,iBAAkBqE,IAAY,QAAU,uBAAwBE,CAAS,CAAC,CACnF,OAAO,OAAO,CAAC,CACf,KAAK,GAAG,EACX,MAAO,CAAE,GAAGH,EAAQ,GAAGI,CAAM,EAC7B,GAAIhB,EAEH,SAAAO,EAAO,OAAO,IAAK,GAAU,CAC5B,IAAMvB,EAAS,OAAO,OAAOsB,EAAS1D,EAAM,EAAE,EAAI0D,EAAQ1D,EAAM,IAAM,IAAA,GAChEqE,EAAgBvB,GAAc,EAAQ9C,EAAM,WAC5CsE,EAAWD,GAAkB,aAAcrE,GAAS,EAAQA,EAAM,SAElEkD,EACJqB,GACAf,EAAQ,IAAIxD,EAAM,EAAE,GACnBA,EAAM,OAAS,UAAY,OAAOoC,GAAW,SAChD,OACE,EAAAxC,EAAA,IAAA,CAACoD,EAAD,CAES,QACC,SACR,MAAOwB,EAAYxE,EAAM,KAAO,CAAC,EACjC,WAAYqE,EACZ,MAAOI,EAAOzE,EAAM,IACJ,iBAChB,SAAW,GAAS,CACbsE,GACHV,EAAO5D,EAAM,GAAIqC,CAAI,CAEzB,CACD,EAZMrC,EAAM,EAYZ,CAEL,CAAC,CACE,CAAA,CAET,C"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.cjs","names":["forwardRef","useState","useRef","omitRequired","Button","useId","Icon","Popover","useGroupBinding","require_Icon","require_components_Button_index","require_binding","require_components_Popover_index","react","react_jsx_runtime","cx","parts","WEEKDAYS","toIso","month","date","day","fromIso","value","year","formatIsoDate","monthLabel","startOfGrid","first","weekday","dayVariant","isEdge","inRange","isToday","Calendar","rest","selected","setMonth","focused","setFocused","gridRef","shouldFocus","next","days","start","index","today","changeMonth","delta","move","base","deltaDays","onKeyDown","event","className","rowIndex","iso","isOutside","isDisabled","min","max","endValue","onSelect","DateField","ariaInvalid","internal","setInternal","defaultValue","current","isOpen","setOpen","rootRef","triggerRef","panelRef","generatedId","triggerId","id","onPointerDown","target","isInvalid","open","placeholder","onValueChange","DateRangeField","binding","commit","attributes","startLabel","endLabel"],"sources":["../../../src/components/DatePicker/index.tsx"],"sourcesContent":["import { forwardRef, useEffect, useId, useRef, useState, type HTMLAttributes } from \"react\";\nimport { Button } from \"../Button\";\nimport { Icon } from \"../Icon\";\nimport { Popover, type PopoverPlacement } from \"../Popover\";\nimport { omitRequired, useGroupBinding } from \"../Field/binding\";\nimport type { FieldBinding, FieldSize } from \"../Field\";\nimport \"../Field/style.css\";\nimport \"./style.css\";\n\nfunction cx(...parts: (string | undefined | false)[]) {\n return parts.filter(Boolean).join(\" \");\n}\n\n/** ISO calendar date, \"YYYY-MM-DD\" — the only date shape the system passes around. */\nexport type IsoDate = string;\n\nconst WEEKDAYS = [\"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\", \"Sun\"];\n\nfunction toIso(date: Date): IsoDate {\n const month = `${date.getMonth() + 1}`.padStart(2, \"0\");\n const day = `${date.getDate()}`.padStart(2, \"0\");\n return `${date.getFullYear()}-${month}-${day}`;\n}\n\nfunction fromIso(value: string | undefined): Date | null {\n if (!value || !/^\\d{4}-\\d{2}-\\d{2}$/.test(value)) {\n return null;\n }\n const [year, month, day] = value.split(\"-\").map(Number);\n if (!year || !month || !day) {\n return null;\n }\n const date = new Date(year, month - 1, day);\n return Number.isNaN(date.getTime()) || toIso(date) !== value ? null : date;\n}\n\n/** \"12 March 2026\" — the system's one long date format. */\nexport function formatIsoDate(value: string | undefined): string {\n const date = fromIso(value);\n if (!date) {\n return \"\";\n }\n return date.toLocaleDateString(\"en-GB\", { day: \"numeric\", month: \"long\", year: \"numeric\" });\n}\n\nfunction monthLabel(date: Date) {\n return date.toLocaleDateString(\"en-GB\", { month: \"long\", year: \"numeric\" });\n}\n\nfunction startOfGrid(month: Date) {\n const first = new Date(month.getFullYear(), month.getMonth(), 1);\n const weekday = (first.getDay() + 6) % 7; // Monday-first\n return new Date(first.getFullYear(), first.getMonth(), 1 - weekday);\n}\n\nfunction dayVariant(isEdge: boolean, inRange: boolean, isToday: boolean) {\n if (isEdge) {\n return \"primary\";\n }\n if (inRange) {\n return \"active\";\n }\n return isToday ? \"neutral\" : \"simple\";\n}\n\nexport interface CalendarProps extends Omit<HTMLAttributes<HTMLDivElement>, \"onSelect\"> {\n /** Selected day, or the start of a selected span. */\n value?: IsoDate;\n /** End of a selected span. Set it to put the calendar in range mode. */\n endValue?: IsoDate;\n onSelect?: (value: IsoDate) => void;\n min?: IsoDate;\n max?: IsoDate;\n}\n\n/**\n * A month of days, Monday first. Arrow keys walk the grid; the month follows\n * the focused day, so a whole year is reachable from the keyboard.\n */\nexport const Calendar = forwardRef<HTMLDivElement, CalendarProps>(function Calendar(\n { value, endValue, onSelect, min, max, className, ...rest },\n ref,\n) {\n const selected = fromIso(value);\n const [month, setMonth] = useState(() => selected ?? new Date());\n const [focused, setFocused] = useState<IsoDate>(() => value ?? toIso(new Date()));\n const gridRef = useRef<HTMLDivElement | null>(null);\n const shouldFocus = useRef(false);\n\n useEffect(() => {\n const next = fromIso(value);\n if (!next) {\n return;\n }\n // Controlled changes intentionally reposition the visible and roving-focus month.\n // eslint-disable-next-line react-hooks/set-state-in-effect\n setFocused(value!);\n setMonth(new Date(next.getFullYear(), next.getMonth(), 1));\n }, [value]);\n\n useEffect(() => {\n if (!shouldFocus.current) {\n return;\n }\n shouldFocus.current = false;\n gridRef.current?.querySelector<HTMLButtonElement>(\"[data-focused]\")?.focus();\n }, [focused]);\n\n const days = Array.from({ length: 42 }, (_, index) => {\n const start = startOfGrid(month);\n return new Date(start.getFullYear(), start.getMonth(), start.getDate() + index);\n });\n\n const today = toIso(new Date());\n\n const changeMonth = (delta: number) => {\n const next = new Date(month.getFullYear(), month.getMonth() + delta, 1);\n setMonth(next);\n setFocused(toIso(next));\n };\n\n const move = (deltaDays: number) => {\n const base = fromIso(focused) ?? new Date();\n const next = new Date(base.getFullYear(), base.getMonth(), base.getDate() + deltaDays);\n shouldFocus.current = true;\n setFocused(toIso(next));\n setMonth(new Date(next.getFullYear(), next.getMonth(), 1));\n };\n\n const onKeyDown = (event: React.KeyboardEvent) => {\n const steps: Record<string, number> = {\n ArrowLeft: -1,\n ArrowRight: 1,\n ArrowUp: -7,\n ArrowDown: 7,\n PageUp: -28,\n PageDown: 28,\n };\n const delta = steps[event.key];\n if (delta === undefined) {\n return;\n }\n event.preventDefault();\n move(delta);\n };\n\n return (\n <div\n ref={ref}\n className={cx(\"ds-calendar\", className)}\n {...omitRequired(rest)}\n >\n <div className=\"ds-calendar__head\">\n <Button\n variant=\"simple\"\n size=\"sm\"\n isIconOnly\n iconStart=\"chevron-left\"\n aria-label=\"Previous month\"\n onClick={() => changeMonth(-1)}\n />\n <span className=\"ds-calendar__month\">{monthLabel(month)}</span>\n <Button\n variant=\"simple\"\n size=\"sm\"\n isIconOnly\n iconStart=\"chevron-right\"\n aria-label=\"Next month\"\n onClick={() => changeMonth(1)}\n />\n </div>\n <div\n className=\"ds-calendar__weekdays\"\n aria-hidden=\"true\"\n >\n {WEEKDAYS.map((day) => (\n <span key={day}>{day.slice(0, 2)}</span>\n ))}\n </div>\n <div\n ref={gridRef}\n className=\"ds-calendar__grid\"\n role=\"grid\"\n onKeyDown={onKeyDown}\n >\n {Array.from({ length: 6 }, (_, rowIndex) => (\n <div\n role=\"row\"\n className=\"ds-calendar__row\"\n key={rowIndex}\n >\n {days.slice(rowIndex * 7, rowIndex * 7 + 7).map((day) => {\n const iso = toIso(day);\n const isOutside = day.getMonth() !== month.getMonth();\n const isDisabled = (min && iso < min) || (max && iso > max);\n const inRange = Boolean(value && endValue && iso > value && iso < endValue);\n const isEdge = iso === value || iso === endValue;\n return (\n <Button\n key={iso}\n variant={dayVariant(isEdge, inRange, iso === today)}\n size=\"sm\"\n isIconOnly\n role=\"gridcell\"\n aria-label={formatIsoDate(iso)}\n tabIndex={iso === focused ? 0 : -1}\n isDisabled={Boolean(isDisabled)}\n aria-selected={isEdge || undefined}\n data-outside={isOutside || undefined}\n data-today={iso === today || undefined}\n data-in-range={inRange || undefined}\n data-focused={iso === focused || undefined}\n className=\"ds-calendar__day\"\n onClick={() => {\n setFocused(iso);\n onSelect?.(iso);\n }}\n >\n {day.getDate()}\n </Button>\n );\n })}\n </div>\n ))}\n </div>\n </div>\n );\n});\n\nexport interface DateFieldProps extends FieldBinding {\n /** Preferred side; the shared Popover flips when space requires it. */\n placement?: PopoverPlacement;\n value?: IsoDate;\n defaultValue?: IsoDate;\n onValueChange?: (value: IsoDate) => void;\n size?: FieldSize;\n placeholder?: string;\n min?: IsoDate;\n max?: IsoDate;\n isDisabled?: boolean;\n isInvalid?: boolean;\n className?: string;\n}\n\n/** One day, picked from a calendar. The field prints the long date, never a mask. */\nexport function DateField({\n value,\n defaultValue = \"\",\n onValueChange,\n size = \"md\",\n placeholder = \"Pick a date\",\n placement,\n min,\n max,\n isDisabled = false,\n isInvalid = false,\n \"aria-invalid\": ariaInvalid,\n id,\n className,\n ...rest\n}: DateFieldProps) {\n const [internal, setInternal] = useState<IsoDate>(defaultValue);\n const current = value ?? internal;\n const [isOpen, setOpen] = useState(false);\n const rootRef = useRef<HTMLDivElement | null>(null);\n const triggerRef = useRef<HTMLButtonElement | null>(null);\n const panelRef = useRef<HTMLDivElement | null>(null);\n const generatedId = useId();\n const triggerId = id ?? generatedId;\n\n useEffect(() => {\n if (!isOpen) {\n return;\n }\n const onPointerDown = (event: MouseEvent) => {\n const target = event.target as Node;\n if (!rootRef.current?.contains(target) && !panelRef.current?.contains(target)) {\n setOpen(false);\n }\n };\n const onKeyDown = (event: KeyboardEvent) => {\n if (event.key === \"Escape\") {\n event.preventDefault();\n setOpen(false);\n triggerRef.current?.focus();\n }\n };\n document.addEventListener(\"mousedown\", onPointerDown);\n document.addEventListener(\"keydown\", onKeyDown);\n return () => {\n document.removeEventListener(\"mousedown\", onPointerDown);\n document.removeEventListener(\"keydown\", onKeyDown);\n };\n }, [isOpen]);\n\n return (\n <div\n className={cx(\"ds-datefield\", className)}\n ref={rootRef}\n >\n <Button\n {...omitRequired(rest)}\n ref={triggerRef}\n id={triggerId}\n size={size}\n aria-haspopup=\"dialog\"\n aria-expanded={isOpen}\n aria-invalid={isInvalid || ariaInvalid || undefined}\n isDisabled={isDisabled}\n data-placeholder={current ? undefined : \"\"}\n className=\"ds-field-skin ds-datefield__control\"\n onClick={() => setOpen((open) => !open)}\n >\n <span className=\"ds-datefield__value\">\n {current ? formatIsoDate(current) : placeholder}\n </span>\n <Icon\n name=\"calendar\"\n size={16}\n className=\"ds-datefield__glyph\"\n />\n </Button>\n <Popover\n anchorRef={triggerRef}\n placement={placement}\n anchorId={triggerId}\n isOpen={isOpen}\n panelRef={panelRef}\n className=\"ds-datefield__popover\"\n role=\"dialog\"\n aria-label=\"Choose a date\"\n >\n <Calendar\n value={current}\n min={min}\n max={max}\n onSelect={(next) => {\n if (value === undefined) {\n setInternal(next);\n }\n onValueChange?.(next);\n setOpen(false);\n triggerRef.current?.focus();\n }}\n />\n </Popover>\n </div>\n );\n}\n\nexport interface DateRangeValue {\n start: IsoDate;\n end: IsoDate;\n}\n\nexport interface DateRangeFieldProps extends FieldBinding {\n placement?: PopoverPlacement;\n value?: DateRangeValue;\n defaultValue?: DateRangeValue;\n onValueChange?: (value: DateRangeValue) => void;\n size?: FieldSize;\n min?: IsoDate;\n max?: IsoDate;\n isDisabled?: boolean;\n startLabel?: string;\n endLabel?: string;\n className?: string;\n}\n\n/** A span of days. The end field never offers a day before the start. */\nexport function DateRangeField({\n value,\n defaultValue = { start: \"\", end: \"\" },\n onValueChange,\n size = \"md\",\n min,\n max,\n isDisabled = false,\n startLabel = \"Start date\",\n endLabel = \"End date\",\n placement,\n className,\n ...binding\n}: DateRangeFieldProps) {\n const [internal, setInternal] = useState<DateRangeValue>(defaultValue);\n const current = value ?? internal;\n\n const commit = (next: DateRangeValue) => {\n if (value === undefined) {\n setInternal(next);\n }\n onValueChange?.(next);\n };\n const { attributes } = useGroupBinding(binding);\n\n return (\n <div\n {...attributes}\n className={cx(\"ds-daterange\", className)}\n >\n <DateField\n aria-invalid={binding[\"aria-invalid\"]}\n aria-label={startLabel}\n placement={placement}\n size={size}\n value={current.start}\n min={min}\n max={current.end || max}\n isDisabled={isDisabled}\n placeholder={startLabel}\n onValueChange={(next) => commit({ ...current, start: next })}\n />\n <span\n className=\"ds-daterange__dash\"\n aria-hidden=\"true\"\n >\n –\n </span>\n <DateField\n aria-invalid={binding[\"aria-invalid\"]}\n aria-label={endLabel}\n placement={placement}\n size={size}\n value={current.end}\n min={current.start || min}\n max={max}\n isDisabled={isDisabled}\n placeholder={endLabel}\n onValueChange={(next) => commit({ ...current, end: next })}\n />\n </div>\n );\n}\n"],"mappings":"A,8UASA,SAASe,EAAG,GAAGC,EAAuC,CACpD,OAAOA,EAAM,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG,CACvC,CAKA,IAAMC,EAAW,CAAC,MAAO,MAAO,MAAO,MAAO,MAAO,MAAO,KAAK,EAEjE,SAASC,EAAM,EAAqB,CAClC,IAAMC,EAAQ,GAAGC,EAAK,SAAS,EAAI,IAAI,SAAS,EAAG,GAAG,EAChDC,EAAM,GAAGD,EAAK,QAAQ,IAAI,SAAS,EAAG,GAAG,EAC/C,MAAO,GAAGA,EAAK,YAAY,EAAE,GAAGD,EAAM,GAAGE,GAC3C,CAEA,SAASC,EAAQ,EAAwC,CACvD,GAAI,CAACC,GAAS,CAAC,sBAAsB,KAAKA,CAAK,EAC7C,OAAO,KAET,GAAM,CAACC,EAAML,EAAOE,GAAOE,EAAM,MAAM,GAAG,CAAC,CAAC,IAAI,MAAM,EACtD,GAAI,CAACC,GAAQ,CAACL,GAAS,CAACE,EACtB,OAAO,KAET,IAAMD,EAAO,IAAI,KAAKI,EAAML,EAAQ,EAAGE,CAAG,EAC1C,OAAO,OAAO,MAAMD,EAAK,QAAQ,CAAC,GAAKF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AE,MAAO,GAAI,IAAK,EAAG,EACpC,gBACA,OAAO,KACP,MACA,MACA,aAAa,GACb,aAAa,aACb,WAAW,WACX,YACA,YACA,GAAGC,GACmB,CACtB,GAAM,CAACnB,EAAUC,IAAA,EAAejE,EAAAA,SAAAA,CAAyBkE,CAAY,EAC/DC,EAAU7C,GAAS0C,EAEnBoB,EAAU,GAAyB,CACnC9D,IAAU,IAAA,IACZ2C,EAAYxB,CAAI,EAElBwC,IAAgBxC,CAAI,CACtB,EACM,CAAE,cAAelC,EAAAA,EAAgB4E,CAAO,EAE9C,OACE,EAAAtE,EAAA,KAAA,CAAC,MAAD,CACE,GAAIwE,EACJ,UAAWvE,EAAG,eAAgBuC,CAAS,EAFzC,SAAA,EAIE,EAAAxC,EAAA,IAAA,CAACiD,EAAD,CACE,eAAcqB,EAAQ,gBACtB,aAAYG,EACD,YACL,OACN,MAAOnB,EAAQ,MACV,MACL,IAAKA,EAAQ,KAAOR,EACR,aACZ,YAAa2B,EACb,cAAgB,GAASF,EAAO,CAAE,GAAGjB,EAAS,MAAO1B,CAAK,CAAC,CAC5D,CAAA,GACD,EAAA5B,EAAA,IAAA,CAAC,OAAD,CACE,UAAU,qBACV,cAAY,OACb,SAAA,GAEK,CAAA,GACN,EAAAA,EAAA,IAAA,CAACiD,EAAD,CACE,eAAcqB,EAAQ,gBACtB,aAAYI,EACD,YACL,OACN,MAAOpB,EAAQ,IACf,IAAKA,EAAQ,OAAST,EACjB,MACO,aACZ,YAAa6B,EACb,cAAgB,GAASH,EAAO,CAAE,GAAGjB,EAAS,IAAK1B,CAAK,CAAC,CAC1D,CAAA,CACE,C,EAET,C"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","names":["Icon","cx","parts","WEEKDAYS","toIso","month","date","day","fromIso","value","year","formatIsoDate","monthLabel","startOfGrid","first","weekday","dayVariant","isEdge","inRange","isToday","Calendar","forwardRef","rest","selected","setMonth","useState","focused","setFocused","gridRef","useRef","shouldFocus","useEffect","next","days","start","index","today","changeMonth","delta","move","base","deltaDays","onKeyDown","event","className","omitRequired","Button","rowIndex","iso","isOutside","isDisabled","min","max","endValue","onSelect","DateField","ariaInvalid","internal","setInternal","defaultValue","current","isOpen","setOpen","rootRef","triggerRef","panelRef","generatedId","useId","triggerId","id","onPointerDown","target","isInvalid","open","placeholder","Popover","onValueChange","DateRangeField","binding","commit","useGroupBinding","attributes","startLabel","endLabel"],"sources":["../../../src/components/DatePicker/index.tsx"],"sourcesContent":["import { forwardRef, useEffect, useId, useRef, useState, type HTMLAttributes } from \"react\";\nimport { Button } from \"../Button\";\nimport { Icon } from \"../Icon\";\nimport { Popover, type PopoverPlacement } from \"../Popover\";\nimport { omitRequired, useGroupBinding } from \"../Field/binding\";\nimport type { FieldBinding, FieldSize } from \"../Field\";\nimport \"../Field/style.css\";\nimport \"./style.css\";\n\nfunction cx(...parts: (string | undefined | false)[]) {\n return parts.filter(Boolean).join(\" \");\n}\n\n/** ISO calendar date, \"YYYY-MM-DD\" — the only date shape the system passes around. */\nexport type IsoDate = string;\n\nconst WEEKDAYS = [\"Mon\", \"Tue\", \"Wed\", \"Thu\", \"Fri\", \"Sat\", \"Sun\"];\n\nfunction toIso(date: Date): IsoDate {\n const month = `${date.getMonth() + 1}`.padStart(2, \"0\");\n const day = `${date.getDate()}`.padStart(2, \"0\");\n return `${date.getFullYear()}-${month}-${day}`;\n}\n\nfunction fromIso(value: string | undefined): Date | null {\n if (!value || !/^\\d{4}-\\d{2}-\\d{2}$/.test(value)) {\n return null;\n }\n const [year, month, day] = value.split(\"-\").map(Number);\n if (!year || !month || !day) {\n return null;\n }\n const date = new Date(year, month - 1, day);\n return Number.isNaN(date.getTime()) || toIso(date) !== value ? null : date;\n}\n\n/** \"12 March 2026\" — the system's one long date format. */\nexport function formatIsoDate(value: string | undefined): string {\n const date = fromIso(value);\n if (!date) {\n return \"\";\n }\n return date.toLocaleDateString(\"en-GB\", { day: \"numeric\", month: \"long\", year: \"numeric\" });\n}\n\nfunction monthLabel(date: Date) {\n return date.toLocaleDateString(\"en-GB\", { month: \"long\", year: \"numeric\" });\n}\n\nfunction startOfGrid(month: Date) {\n const first = new Date(month.getFullYear(), month.getMonth(), 1);\n const weekday = (first.getDay() + 6) % 7; // Monday-first\n return new Date(first.getFullYear(), first.getMonth(), 1 - weekday);\n}\n\nfunction dayVariant(isEdge: boolean, inRange: boolean, isToday: boolean) {\n if (isEdge) {\n return \"primary\";\n }\n if (inRange) {\n return \"active\";\n }\n return isToday ? \"neutral\" : \"simple\";\n}\n\nexport interface CalendarProps extends Omit<HTMLAttributes<HTMLDivElement>, \"onSelect\"> {\n /** Selected day, or the start of a selected span. */\n value?: IsoDate;\n /** End of a selected span. Set it to put the calendar in range mode. */\n endValue?: IsoDate;\n onSelect?: (value: IsoDate) => void;\n min?: IsoDate;\n max?: IsoDate;\n}\n\n/**\n * A month of days, Monday first. Arrow keys walk the grid; the month follows\n * the focused day, so a whole year is reachable from the keyboard.\n */\nexport const Calendar = forwardRef<HTMLDivElement, CalendarProps>(function Calendar(\n { value, endValue, onSelect, min, max, className, ...rest },\n ref,\n) {\n const selected = fromIso(value);\n const [month, setMonth] = useState(() => selected ?? new Date());\n const [focused, setFocused] = useState<IsoDate>(() => value ?? toIso(new Date()));\n const gridRef = useRef<HTMLDivElement | null>(null);\n const shouldFocus = useRef(false);\n\n useEffect(() => {\n const next = fromIso(value);\n if (!next) {\n return;\n }\n // Controlled changes intentionally reposition the visible and roving-focus month.\n // eslint-disable-next-line react-hooks/set-state-in-effect\n setFocused(value!);\n setMonth(new Date(next.getFullYear(), next.getMonth(), 1));\n }, [value]);\n\n useEffect(() => {\n if (!shouldFocus.current) {\n return;\n }\n shouldFocus.current = false;\n gridRef.current?.querySelector<HTMLButtonElement>(\"[data-focused]\")?.focus();\n }, [focused]);\n\n const days = Array.from({ length: 42 }, (_, index) => {\n const start = startOfGrid(month);\n return new Date(start.getFullYear(), start.getMonth(), start.getDate() + index);\n });\n\n const today = toIso(new Date());\n\n const changeMonth = (delta: number) => {\n const next = new Date(month.getFullYear(), month.getMonth() + delta, 1);\n setMonth(next);\n setFocused(toIso(next));\n };\n\n const move = (deltaDays: number) => {\n const base = fromIso(focused) ?? new Date();\n const next = new Date(base.getFullYear(), base.getMonth(), base.getDate() + deltaDays);\n shouldFocus.current = true;\n setFocused(toIso(next));\n setMonth(new Date(next.getFullYear(), next.getMonth(), 1));\n };\n\n const onKeyDown = (event: React.KeyboardEvent) => {\n const steps: Record<string, number> = {\n ArrowLeft: -1,\n ArrowRight: 1,\n ArrowUp: -7,\n ArrowDown: 7,\n PageUp: -28,\n PageDown: 28,\n };\n const delta = steps[event.key];\n if (delta === undefined) {\n return;\n }\n event.preventDefault();\n move(delta);\n };\n\n return (\n <div\n ref={ref}\n className={cx(\"ds-calendar\", className)}\n {...omitRequired(rest)}\n >\n <div className=\"ds-calendar__head\">\n <Button\n variant=\"simple\"\n size=\"sm\"\n isIconOnly\n iconStart=\"chevron-left\"\n aria-label=\"Previous month\"\n onClick={() => changeMonth(-1)}\n />\n <span className=\"ds-calendar__month\">{monthLabel(month)}</span>\n <Button\n variant=\"simple\"\n size=\"sm\"\n isIconOnly\n iconStart=\"chevron-right\"\n aria-label=\"Next month\"\n onClick={() => changeMonth(1)}\n />\n </div>\n <div\n className=\"ds-calendar__weekdays\"\n aria-hidden=\"true\"\n >\n {WEEKDAYS.map((day) => (\n <span key={day}>{day.slice(0, 2)}</span>\n ))}\n </div>\n <div\n ref={gridRef}\n className=\"ds-calendar__grid\"\n role=\"grid\"\n onKeyDown={onKeyDown}\n >\n {Array.from({ length: 6 }, (_, rowIndex) => (\n <div\n role=\"row\"\n className=\"ds-calendar__row\"\n key={rowIndex}\n >\n {days.slice(rowIndex * 7, rowIndex * 7 + 7).map((day) => {\n const iso = toIso(day);\n const isOutside = day.getMonth() !== month.getMonth();\n const isDisabled = (min && iso < min) || (max && iso > max);\n const inRange = Boolean(value && endValue && iso > value && iso < endValue);\n const isEdge = iso === value || iso === endValue;\n return (\n <Button\n key={iso}\n variant={dayVariant(isEdge, inRange, iso === today)}\n size=\"sm\"\n isIconOnly\n role=\"gridcell\"\n aria-label={formatIsoDate(iso)}\n tabIndex={iso === focused ? 0 : -1}\n isDisabled={Boolean(isDisabled)}\n aria-selected={isEdge || undefined}\n data-outside={isOutside || undefined}\n data-today={iso === today || undefined}\n data-in-range={inRange || undefined}\n data-focused={iso === focused || undefined}\n className=\"ds-calendar__day\"\n onClick={() => {\n setFocused(iso);\n onSelect?.(iso);\n }}\n >\n {day.getDate()}\n </Button>\n );\n })}\n </div>\n ))}\n </div>\n </div>\n );\n});\n\nexport interface DateFieldProps extends FieldBinding {\n /** Preferred side; the shared Popover flips when space requires it. */\n placement?: PopoverPlacement;\n value?: IsoDate;\n defaultValue?: IsoDate;\n onValueChange?: (value: IsoDate) => void;\n size?: FieldSize;\n placeholder?: string;\n min?: IsoDate;\n max?: IsoDate;\n isDisabled?: boolean;\n isInvalid?: boolean;\n className?: string;\n}\n\n/** One day, picked from a calendar. The field prints the long date, never a mask. */\nexport function DateField({\n value,\n defaultValue = \"\",\n onValueChange,\n size = \"md\",\n placeholder = \"Pick a date\",\n placement,\n min,\n max,\n isDisabled = false,\n isInvalid = false,\n \"aria-invalid\": ariaInvalid,\n id,\n className,\n ...rest\n}: DateFieldProps) {\n const [internal, setInternal] = useState<IsoDate>(defaultValue);\n const current = value ?? internal;\n const [isOpen, setOpen] = useState(false);\n const rootRef = useRef<HTMLDivElement | null>(null);\n const triggerRef = useRef<HTMLButtonElement | null>(null);\n const panelRef = useRef<HTMLDivElement | null>(null);\n const generatedId = useId();\n const triggerId = id ?? generatedId;\n\n useEffect(() => {\n if (!isOpen) {\n return;\n }\n const onPointerDown = (event: MouseEvent) => {\n const target = event.target as Node;\n if (!rootRef.current?.contains(target) && !panelRef.current?.contains(target)) {\n setOpen(false);\n }\n };\n const onKeyDown = (event: KeyboardEvent) => {\n if (event.key === \"Escape\") {\n event.preventDefault();\n setOpen(false);\n triggerRef.current?.focus();\n }\n };\n document.addEventListener(\"mousedown\", onPointerDown);\n document.addEventListener(\"keydown\", onKeyDown);\n return () => {\n document.removeEventListener(\"mousedown\", onPointerDown);\n document.removeEventListener(\"keydown\", onKeyDown);\n };\n }, [isOpen]);\n\n return (\n <div\n className={cx(\"ds-datefield\", className)}\n ref={rootRef}\n >\n <Button\n {...omitRequired(rest)}\n ref={triggerRef}\n id={triggerId}\n size={size}\n aria-haspopup=\"dialog\"\n aria-expanded={isOpen}\n aria-invalid={isInvalid || ariaInvalid || undefined}\n isDisabled={isDisabled}\n data-placeholder={current ? undefined : \"\"}\n className=\"ds-field-skin ds-datefield__control\"\n onClick={() => setOpen((open) => !open)}\n >\n <span className=\"ds-datefield__value\">\n {current ? formatIsoDate(current) : placeholder}\n </span>\n <Icon\n name=\"calendar\"\n size={16}\n className=\"ds-datefield__glyph\"\n />\n </Button>\n <Popover\n anchorRef={triggerRef}\n placement={placement}\n anchorId={triggerId}\n isOpen={isOpen}\n panelRef={panelRef}\n className=\"ds-datefield__popover\"\n role=\"dialog\"\n aria-label=\"Choose a date\"\n >\n <Calendar\n value={current}\n min={min}\n max={max}\n onSelect={(next) => {\n if (value === undefined) {\n setInternal(next);\n }\n onValueChange?.(next);\n setOpen(false);\n triggerRef.current?.focus();\n }}\n />\n </Popover>\n </div>\n );\n}\n\nexport interface DateRangeValue {\n start: IsoDate;\n end: IsoDate;\n}\n\nexport interface DateRangeFieldProps extends FieldBinding {\n placement?: PopoverPlacement;\n value?: DateRangeValue;\n defaultValue?: DateRangeValue;\n onValueChange?: (value: DateRangeValue) => void;\n size?: FieldSize;\n min?: IsoDate;\n max?: IsoDate;\n isDisabled?: boolean;\n startLabel?: string;\n endLabel?: string;\n className?: string;\n}\n\n/** A span of days. The end field never offers a day before the start. */\nexport function DateRangeField({\n value,\n defaultValue = { start: \"\", end: \"\" },\n onValueChange,\n size = \"md\",\n min,\n max,\n isDisabled = false,\n startLabel = \"Start date\",\n endLabel = \"End date\",\n placement,\n className,\n ...binding\n}: DateRangeFieldProps) {\n const [internal, setInternal] = useState<DateRangeValue>(defaultValue);\n const current = value ?? internal;\n\n const commit = (next: DateRangeValue) => {\n if (value === undefined) {\n setInternal(next);\n }\n onValueChange?.(next);\n };\n const { attributes } = useGroupBinding(binding);\n\n return (\n <div\n {...attributes}\n className={cx(\"ds-daterange\", className)}\n >\n <DateField\n aria-invalid={binding[\"aria-invalid\"]}\n aria-label={startLabel}\n placement={placement}\n size={size}\n value={current.start}\n min={min}\n max={current.end || max}\n isDisabled={isDisabled}\n placeholder={startLabel}\n onValueChange={(next) => commit({ ...current, start: next })}\n />\n <span\n className=\"ds-daterange__dash\"\n aria-hidden=\"true\"\n >\n –\n </span>\n <DateField\n aria-invalid={binding[\"aria-invalid\"]}\n aria-label={endLabel}\n placement={placement}\n size={size}\n value={current.end}\n min={current.start || min}\n max={max}\n isDisabled={isDisabled}\n placeholder={endLabel}\n onValueChange={(next) => commit({ ...current, end: next })}\n />\n </div>\n );\n}\n"],"mappings":";;;;;;;;AASA,SAASC,EAAG,GAAGC,GAAuC;CACpD,OAAOA,EAAM,OAAO,OAAO,CAAC,CAAC,KAAK,GAAG;AACvC;AAKA,IAAMC,IAAW;CAAC;CAAO;CAAO;CAAO;CAAO;CAAO;CAAO;AAAK;AAEjE,SAASC,EAAM,GAAqB;CAClC,IAAMC,IAAQ,GAAGC,EAAK,SAAS,IAAI,IAAI,SAAS,GAAG,GAAG,GAChDC,IAAM,GAAGD,EAAK,QAAQ,IAAI,SAAS,GAAG,GAAG;CAC/C,OAAO,GAAGA,EAAK,YAAY,EAAE,GAAGD,EAAM,GAAGE;AAC3C;AAEA,SAASC,EAAQ,GAAwC;CACvD,IAAI,CAACC,KAAS,CAAC,sBAAsB,KAAKA,CAAK,GAC7C,OAAO;CAET,IAAM,CAACC,GAAML,GAAOE,KAAOE,EAAM,MAAM,GAAG,CAAC,CAAC,IAAI,MAAM;CACtD,IAAI,CAACC,KAAQ,CAACL,KAAS,CAAC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