@overmap-ai/forms 1.0.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 (64) hide show
  1. package/README.md +12 -0
  2. package/dist/builder/DropDispatch.d.ts +27 -0
  3. package/dist/builder/FieldActions.d.ts +11 -0
  4. package/dist/builder/FieldBuilder.d.ts +22 -0
  5. package/dist/builder/FieldSectionWithActions.d.ts +10 -0
  6. package/dist/builder/FieldWithActions.d.ts +10 -0
  7. package/dist/builder/FieldsEditor.d.ts +2 -0
  8. package/dist/builder/FormBuilder.d.ts +15 -0
  9. package/dist/builder/constants.d.ts +1 -0
  10. package/dist/builder/index.d.ts +2 -0
  11. package/dist/builder/typings.d.ts +11 -0
  12. package/dist/builder/utils.d.ts +11 -0
  13. package/dist/fields/BaseField/BaseField.d.ts +32 -0
  14. package/dist/fields/BaseField/hooks.d.ts +374 -0
  15. package/dist/fields/BaseField/index.d.ts +4 -0
  16. package/dist/fields/BaseField/layouts.d.ts +19 -0
  17. package/dist/fields/BaseField/typings.d.ts +7 -0
  18. package/dist/fields/BooleanField/BooleanInput.d.ts +4 -0
  19. package/dist/fields/BooleanField/index.d.ts +2 -0
  20. package/dist/fields/CustomField/CustomField.d.ts +19 -0
  21. package/dist/fields/CustomField/FieldInputClonerField/FieldInputCloner.d.ts +8 -0
  22. package/dist/fields/CustomField/FieldInputClonerField/FieldInputClonerField.d.ts +18 -0
  23. package/dist/fields/CustomField/FieldInputClonerField/index.d.ts +3 -0
  24. package/dist/fields/CustomField/FieldInputClonerField/typings.d.ts +5 -0
  25. package/dist/fields/CustomField/index.d.ts +1 -0
  26. package/dist/fields/DateField/DateInput.d.ts +4 -0
  27. package/dist/fields/DateField/index.d.ts +2 -0
  28. package/dist/fields/FieldSection/FieldSection.d.ts +29 -0
  29. package/dist/fields/FieldSection/FieldSectionLayout.d.ts +7 -0
  30. package/dist/fields/FieldSection/index.d.ts +1 -0
  31. package/dist/fields/MultiStringField/MultiStringInput.d.ts +8 -0
  32. package/dist/fields/MultiStringField/index.d.ts +2 -0
  33. package/dist/fields/NumberField/NumberInput.d.ts +4 -0
  34. package/dist/fields/NumberField/index.d.ts +2 -0
  35. package/dist/fields/SelectField/BaseSelectField.d.ts +26 -0
  36. package/dist/fields/SelectField/MultiSelectInput.d.ts +4 -0
  37. package/dist/fields/SelectField/SelectInput.d.ts +4 -0
  38. package/dist/fields/SelectField/index.d.ts +4 -0
  39. package/dist/fields/StringOrTextFields/StringField/StringInput.d.ts +4 -0
  40. package/dist/fields/StringOrTextFields/StringField/index.d.ts +2 -0
  41. package/dist/fields/StringOrTextFields/StringOrTextField.d.ts +29 -0
  42. package/dist/fields/StringOrTextFields/TextField/TextInput.d.ts +4 -0
  43. package/dist/fields/StringOrTextFields/TextField/index.d.ts +2 -0
  44. package/dist/fields/StringOrTextFields/index.d.ts +2 -0
  45. package/dist/fields/constants.d.ts +18 -0
  46. package/dist/fields/hooks.d.ts +6 -0
  47. package/dist/fields/index.d.ts +11 -0
  48. package/dist/fields/typings.d.ts +24 -0
  49. package/dist/fields/utils.d.ts +12 -0
  50. package/dist/forms.js +1786 -0
  51. package/dist/forms.umd.cjs +1 -0
  52. package/dist/index.d.ts +3 -0
  53. package/dist/renderer/FormBrowser/FormBrowser.d.ts +11 -0
  54. package/dist/renderer/FormRenderer/FormRenderer.d.ts +28 -0
  55. package/dist/renderer/FormSubmissionBrowser/FormSubmissionBrowser.d.ts +28 -0
  56. package/dist/renderer/FormSubmissionViewer/FormSubmissionViewer.d.ts +17 -0
  57. package/dist/renderer/PatchForm/Field.d.ts +15 -0
  58. package/dist/renderer/PatchForm/Provider.d.ts +24 -0
  59. package/dist/renderer/PatchForm/index.d.ts +2 -0
  60. package/dist/renderer/index.d.ts +5 -0
  61. package/dist/style.css +1 -0
  62. package/dist/typings.d.ts +5 -0
  63. package/dist/utils.d.ts +7 -0
  64. package/package.json +88 -0
package/dist/forms.js ADDED
@@ -0,0 +1,1786 @@
1
+ var Et = Object.defineProperty;
2
+ var zt = (o, i, e) => i in o ? Et(o, i, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[i] = e;
3
+ var p = (o, i, e) => (zt(o, typeof i != "symbol" ? i + "" : i, e), e);
4
+ import { jsx as r, jsxs as b, Fragment as ot } from "react/jsx-runtime";
5
+ import { Flex as v, Text as k, useSeverityColor as pe, Checkbox as Lt, CheckCircledIcon as Pt, TextField as oe, FontFamilyIcon as At, CalendarIcon as Dt, InputIcon as kt, TextArea as Mt, RowsIcon as Ot, Select as st, Box as ge, IconButton as ce, PlusIcon as Se, Badge as _e, Cross1Icon as Vt, ListBulletIcon as _t, DropdownMenuIcon as $t, MultiSelect as Rt, CheckboxIcon as qt, Card as Ee, Heading as ze, Button as G, ButtonList as Le, divButtonProps as Nt, StarFilledIcon as Bt, StarIcon as Wt, QuestionMarkCircledIcon as jt, PersonIcon as Ht, Tooltip as Ut, Avatar as Gt, Separator as Kt, Dialog as Yt, Pencil1Icon as Qt, TrashIcon as Xt, DragHandleDots2Icon as Jt, DropdownMenu as Zt, DotsVerticalIcon as ei, useAlertDialog as ti, Em as ii, Strong as Ze, useToast as ni, Tabs as Q } from "@overmap-ai/blocks";
6
+ import { useField as We, useFormikContext as ae, useFormik as je, FormikProvider as He } from "formik";
7
+ import ri, { useMemo as T, memo as z, useCallback as E, useState as de, useEffect as Pe, forwardRef as me, useReducer as oi } from "react";
8
+ import { DragDropContext as lt, Droppable as Ue, Draggable as Ge } from "@hello-pangea/dnd";
9
+ import { slugify as at, useAppSelector as $, selectFormRevision as ct, useSDK as si, selectFilteredUserForms as li, selectUserFormMapping as ai, selectOrganization as dt, selectUser as Ke, selectNumberOfUserForms as ci, selectCurrentUser as ut, classNames as ft, isToday as di, getLocalDateString as ui, selectLatestFormRevision as fi, useFileSrc as hi, selectSubmissionsForForm as pi } from "@overmap-ai/core";
10
+ import se from "lodash.get";
11
+ import Ye from "lodash.set";
12
+ class ht {
13
+ constructor(i) {
14
+ p(this, "type");
15
+ p(this, "identifier");
16
+ p(this, "description");
17
+ const { description: e = null, identifier: t, type: n } = i;
18
+ this.identifier = t, this.description = e, this.type = n;
19
+ }
20
+ getId() {
21
+ return this.identifier;
22
+ }
23
+ static deserialize(i) {
24
+ throw new Error(`${this.name} must implement deserialize.`);
25
+ }
26
+ _serialize() {
27
+ if (!this.identifier)
28
+ throw new Error("Field identifier must be set before serializing.");
29
+ return {
30
+ type: this.type,
31
+ identifier: this.identifier,
32
+ description: this.description
33
+ };
34
+ }
35
+ }
36
+ class R extends ht {
37
+ constructor(e) {
38
+ const { label: t, required: n, fieldValidators: s = [], formValidators: a = [], ...l } = e;
39
+ super(l);
40
+ p(this, "required");
41
+ p(this, "formValidators");
42
+ p(this, "fieldValidators");
43
+ p(this, "label");
44
+ this.label = t, this.required = n, this.fieldValidators = s, this.formValidators = a;
45
+ }
46
+ static getFieldCreationSchema() {
47
+ return [];
48
+ }
49
+ isBlank(e) {
50
+ return e == null || e === "";
51
+ }
52
+ getError(e, t) {
53
+ if (this.required && this.isBlank(e))
54
+ return "This field is required.";
55
+ for (const n of this.getFieldValidators()) {
56
+ const s = n(e);
57
+ if (s)
58
+ return s;
59
+ }
60
+ if (t)
61
+ for (const n of this.getFormValidators()) {
62
+ const s = n(e, t);
63
+ if (s)
64
+ return s;
65
+ }
66
+ }
67
+ // TODO: We can probably combine _serialize and serialize.
68
+ _serialize() {
69
+ return {
70
+ ...super._serialize(),
71
+ label: this.label,
72
+ required: this.required
73
+ };
74
+ }
75
+ getFieldValidators() {
76
+ return [...this.fieldValidators];
77
+ }
78
+ getFormValidators() {
79
+ return [...this.formValidators];
80
+ }
81
+ }
82
+ p(R, "fieldTypeName"), p(R, "fieldTypeDescription");
83
+ const mi = "_description_17zed_1", Ae = {
84
+ description: mi
85
+ }, W = (o) => {
86
+ const { label: i, children: e, severity: t, inputId: n, labelId: s, flexProps: a } = o;
87
+ return /* @__PURE__ */ r(v, { direction: "column", gap: "1", asChild: !0, ...a, children: /* @__PURE__ */ b("label", { htmlFor: n, children: [
88
+ /* @__PURE__ */ r(k, { severity: t, id: s, children: i }),
89
+ e
90
+ ] }) });
91
+ }, j = (o) => {
92
+ const { helpText: i, children: e, severity: t } = o;
93
+ return /* @__PURE__ */ b(v, { direction: "column", gap: "1", children: [
94
+ e,
95
+ /* @__PURE__ */ r(v, { direction: "column", children: /* @__PURE__ */ r(k, { size: "1", severity: t, className: Ae.description, children: i }) })
96
+ ] });
97
+ }, H = (o) => {
98
+ const { id: i, field: e, formId: t, ...n } = o, [s, a, l] = We(e.getId()), { touched: c } = a, f = a.error ?? e.description, u = a.error ? "danger" : void 0, d = i ?? `${t}-${e.getId()}-input`, h = `${d}-label`, m = e.required ? `${e.label} *` : e.label, g = T(() => ({
99
+ ...s,
100
+ onChange: (w) => {
101
+ l.setValue(w.target.value, !1).then(), c && l.setError(e.getError(w.target.value));
102
+ },
103
+ onBlur: (w) => {
104
+ l.setTouched(!0, !1).then(), l.setError(e.getError(w.target.value));
105
+ }
106
+ }), [e, s, l, c]);
107
+ return [
108
+ {
109
+ helpText: f,
110
+ severity: u,
111
+ inputId: d,
112
+ labelId: h,
113
+ label: m,
114
+ fieldProps: g,
115
+ helpers: l,
116
+ field: e
117
+ },
118
+ { ...n, "aria-labelledby": h }
119
+ ];
120
+ }, gi = [!0, "true"], bi = z(function(i) {
121
+ const [{ inputId: e, labelId: t, severity: n, helpText: s, field: a, label: l, fieldProps: c, helpers: f }, u] = H(i), d = pe(n), { setValue: h, setTouched: m, setError: g } = f, y = gi.includes(c.value), I = E(
122
+ (w) => {
123
+ if (w === "indeterminate")
124
+ throw new Error("indeterminate CheckedState value is not supported");
125
+ h(w, !1).then(), m(!0, !1).then(), g(a.getError(w));
126
+ },
127
+ [h, m, g, a]
128
+ );
129
+ return /* @__PURE__ */ r(j, { helpText: s, severity: n, children: /* @__PURE__ */ r(
130
+ W,
131
+ {
132
+ severity: n,
133
+ inputId: e,
134
+ labelId: t,
135
+ label: l,
136
+ flexProps: { direction: "row-reverse", justify: "end", align: "center", gap: "2" },
137
+ children: /* @__PURE__ */ r(
138
+ Lt,
139
+ {
140
+ ...u,
141
+ ...c,
142
+ id: e,
143
+ color: d,
144
+ value: y.toString(),
145
+ checked: y,
146
+ onCheckedChange: I,
147
+ onChange: void 0,
148
+ onBlur: void 0
149
+ }
150
+ )
151
+ }
152
+ ) });
153
+ }), X = class X extends R {
154
+ constructor(i) {
155
+ super({ ...i, type: "boolean" });
156
+ }
157
+ // if a BooleanField is required, `false` is considered blank
158
+ isBlank(i) {
159
+ return this.required && !i;
160
+ }
161
+ serialize() {
162
+ return super._serialize();
163
+ }
164
+ static deserialize(i) {
165
+ if (i.type !== "boolean")
166
+ throw new Error("Type mismatch.");
167
+ return new X(i);
168
+ }
169
+ getInput(i) {
170
+ return /* @__PURE__ */ r(bi, { ...i, field: this });
171
+ }
172
+ };
173
+ p(X, "fieldTypeName", "Checkbox"), p(X, "fieldTypeDescription", "Perfect for both optional and required yes/no questions."), p(X, "Icon", Pt);
174
+ let le = X;
175
+ const yi = z(function(i) {
176
+ const [{ inputId: e, labelId: t, severity: n, helpText: s, label: a, fieldProps: l, field: c }, f] = H(i), u = pe(n);
177
+ return /* @__PURE__ */ r(j, { helpText: s, severity: n, children: /* @__PURE__ */ r(W, { severity: n, inputId: e, labelId: t, label: a, children: /* @__PURE__ */ r(
178
+ oe.Input,
179
+ {
180
+ ...f,
181
+ ...l,
182
+ type: "number",
183
+ id: e,
184
+ min: c.minimum,
185
+ max: c.maximum,
186
+ step: c.integers ? 1 : 0.1,
187
+ color: u
188
+ }
189
+ ) }) });
190
+ }), q = class q extends R {
191
+ constructor(e) {
192
+ const {
193
+ minimum: t = Number.MIN_SAFE_INTEGER,
194
+ maximum: n = Number.MAX_SAFE_INTEGER,
195
+ integers: s = !1,
196
+ ...a
197
+ } = e;
198
+ super({ ...a, type: "number" });
199
+ p(this, "minimum");
200
+ p(this, "maximum");
201
+ p(this, "integers");
202
+ this.minimum = t, this.maximum = n, this.integers = s;
203
+ }
204
+ static getFieldCreationSchema() {
205
+ return [
206
+ new q({
207
+ label: "Minimum",
208
+ description: "Minimum value",
209
+ integers: !0,
210
+ required: !1,
211
+ identifier: "minimum",
212
+ formValidators: [this._validateMin]
213
+ }),
214
+ new q({
215
+ label: "Maximum",
216
+ description: "Maximum value",
217
+ integers: !0,
218
+ required: !1,
219
+ identifier: "maximum",
220
+ formValidators: [this._validateMax]
221
+ }),
222
+ new le({
223
+ label: "Integers",
224
+ description: "Whole numbers only",
225
+ required: !1,
226
+ identifier: "integers"
227
+ })
228
+ ];
229
+ }
230
+ getFieldValidators() {
231
+ const e = super.getFieldValidators(), t = this.minimum, n = this.maximum;
232
+ return typeof t == "number" && e.push((s) => {
233
+ if (typeof s == "number" && s < t)
234
+ return `Must be at least ${this.minimum}.`;
235
+ }), typeof n == "number" && e.push((s) => {
236
+ if (typeof s == "number" && s > n)
237
+ return `Must be at most ${this.maximum}.`;
238
+ }), this.integers && e.push((s) => {
239
+ if (typeof s == "number" && !Number.isInteger(s))
240
+ return "Must be a whole number.";
241
+ }), e;
242
+ }
243
+ serialize() {
244
+ return {
245
+ ...super._serialize(),
246
+ minimum: this.minimum,
247
+ maximum: this.maximum,
248
+ integers: this.integers
249
+ };
250
+ }
251
+ static deserialize(e) {
252
+ if (e.type !== "number")
253
+ throw new Error("Type mismatch.");
254
+ return new q(e);
255
+ }
256
+ getInput(e) {
257
+ return /* @__PURE__ */ r(yi, { field: this, ...e });
258
+ }
259
+ };
260
+ p(q, "fieldTypeName", "Number"), p(q, "fieldTypeDescription", "Allows specifying a number within a given range."), p(q, "Icon", At), p(q, "_validateMin", (e, t) => typeof t.maximum == "number" && typeof e == "number" && t.maximum < e ? "Minimum cannot be greater than minimum." : null), p(q, "_validateMax", (e, t) => typeof t.minimum == "number" && typeof e == "number" && t.minimum > e ? "Maximum cannot be less than minimum." : null);
261
+ let ue = q;
262
+ const vi = z(function(i) {
263
+ const [{ inputId: e, labelId: t, severity: n, helpText: s, label: a, field: l, fieldProps: c, helpers: f }, u] = H(i), d = pe(n), { setValue: h, setError: m } = f, g = c.value ? c.value.split("T")[0] : "", y = E(
264
+ (I) => {
265
+ const w = new Date(I.target.value).toISOString();
266
+ h(w, !1).then(), m(l.getError(w));
267
+ },
268
+ [l, m, h]
269
+ );
270
+ return /* @__PURE__ */ r(j, { helpText: s, severity: n, children: /* @__PURE__ */ r(W, { severity: n, inputId: e, labelId: t, label: a, children: /* @__PURE__ */ r(
271
+ oe.Input,
272
+ {
273
+ ...u,
274
+ ...c,
275
+ type: "date",
276
+ id: e,
277
+ color: d,
278
+ value: g,
279
+ onChange: y
280
+ }
281
+ ) }) });
282
+ }), J = class J extends R {
283
+ constructor(i) {
284
+ super({ ...i, type: "date" });
285
+ }
286
+ serialize() {
287
+ return super._serialize();
288
+ }
289
+ static deserialize(i) {
290
+ if (i.type !== "date")
291
+ throw new Error("Type mismatch.");
292
+ return new J(i);
293
+ }
294
+ getInput(i) {
295
+ return /* @__PURE__ */ r(vi, { field: this, ...i });
296
+ }
297
+ };
298
+ p(J, "fieldTypeName", "Date"), p(J, "fieldTypeDescription", "Allows specifying a date."), p(J, "Icon", Dt);
299
+ let $e = J;
300
+ class be extends R {
301
+ constructor(e) {
302
+ const { minLength: t, maxLength: n = 5e3, ...s } = e;
303
+ super(s);
304
+ p(this, "minLength");
305
+ p(this, "maxLength");
306
+ this.minLength = t ? Math.max(t, 0) : void 0, this.maxLength = n ? Math.max(n, 0) : 5e3;
307
+ }
308
+ static getFieldCreationSchema() {
309
+ return [
310
+ // min, max
311
+ new ue({
312
+ label: "Minimum length",
313
+ description: "Minimum number of characters",
314
+ required: !1,
315
+ identifier: "minimum_length",
316
+ minimum: 0,
317
+ maximum: 100,
318
+ formValidators: [this._validateMin],
319
+ integers: !0
320
+ }),
321
+ new ue({
322
+ label: "Maximum length",
323
+ description: "Maximum number of characters",
324
+ required: !1,
325
+ identifier: "maximum_length",
326
+ minimum: 1,
327
+ maximum: 5e3,
328
+ // TODO: depends on short vs long text
329
+ formValidators: [this._validateMax],
330
+ // TODO: default: 500 (see: "Short text fields can hold up to 500 characters on a single line.")
331
+ integers: !0
332
+ })
333
+ ];
334
+ }
335
+ getFieldValidators() {
336
+ const e = super.getFieldValidators();
337
+ return this.minLength && e.push((t) => {
338
+ if (this.minLength && (!t || t.length < this.minLength))
339
+ return !this.required && !t ? null : `Minimum ${this.minLength} character(s).`;
340
+ }), this.maxLength && e.push((t) => {
341
+ if (typeof t == "string" && this.maxLength && t.length > this.maxLength)
342
+ return `Maximum ${this.maxLength} character(s).`;
343
+ }), e;
344
+ }
345
+ _serialize() {
346
+ if (!this.identifier)
347
+ throw new Error("Field identifier must be set before serializing.");
348
+ return {
349
+ ...super._serialize(),
350
+ minimum_length: this.minLength,
351
+ maximum_length: this.maxLength
352
+ };
353
+ }
354
+ }
355
+ /**
356
+ * This function validates that the value given for "minimum length" (when creating a new field) is less than or
357
+ * equal to the value given for "maximum length".
358
+ */
359
+ p(be, "_validateMin", (e, t) => typeof t.maximum_length == "number" && typeof e == "number" && t.maximum_length < e ? "Minimum cannot be greater than maximum." : null), /**
360
+ * This function validates that the value given for "maximum length" (when creating a new field) is greater than or
361
+ * equal to the value given for "minimum length".
362
+ */
363
+ p(be, "_validateMax", (e, t) => {
364
+ if (typeof e != "number")
365
+ return null;
366
+ const { minimum_length: n } = t;
367
+ return typeof n != "number" ? null : n > e ? "Maximum cannot be less than minimum." : null;
368
+ });
369
+ const wi = z(function(i) {
370
+ const [{ inputId: e, labelId: t, severity: n, helpText: s, label: a, fieldProps: l, field: c }, f] = H(i), u = pe(n);
371
+ return /* @__PURE__ */ r(j, { helpText: s, severity: n, children: /* @__PURE__ */ r(W, { severity: n, inputId: e, labelId: t, label: a, children: /* @__PURE__ */ r(oe.Input, { ...f, ...l, type: c.inputType, id: e, color: u }) }) });
372
+ }), Z = class Z extends be {
373
+ constructor(e) {
374
+ const { inputType: t = "text", ...n } = e, s = e.maxLength ? Math.min(500, e.maxLength) : 500, a = e.minLength ? Math.min(e.minLength, s) : void 0;
375
+ super({ ...n, maxLength: s, minLength: a, type: "string" });
376
+ p(this, "inputType");
377
+ this.inputType = t;
378
+ }
379
+ serialize() {
380
+ return { ...super._serialize(), input_type: this.inputType };
381
+ }
382
+ static deserialize(e) {
383
+ if (e.type !== "string")
384
+ throw new Error("Type mismatch.");
385
+ const { maximum_length: t, minimum_length: n, input_type: s, ...a } = e;
386
+ return new Z({ ...a, maxLength: t, minLength: n, inputType: s });
387
+ }
388
+ getInput(e) {
389
+ return /* @__PURE__ */ r(wi, { field: this, ...e });
390
+ }
391
+ };
392
+ p(Z, "fieldTypeName", "Short Text"), p(Z, "fieldTypeDescription", "Short text fields can hold up to 500 characters on a single line."), p(Z, "Icon", kt);
393
+ let fe = Z;
394
+ const Ii = z(function(i) {
395
+ const [{ inputId: e, labelId: t, severity: n, helpText: s, label: a, fieldProps: l }, c] = H(i);
396
+ return /* @__PURE__ */ r(j, { helpText: s, severity: n, children: /* @__PURE__ */ r(W, { severity: n, inputId: e, labelId: t, label: a, children: /* @__PURE__ */ r(Mt, { ...c, ...l, resize: "vertical", id: e, severity: n }) }) });
397
+ }), ee = class ee extends be {
398
+ constructor(i) {
399
+ const e = i.maxLength ? Math.min(5e3, i.maxLength) : 5e3, t = i.minLength ? Math.min(i.minLength, e) : void 0;
400
+ super({ ...i, maxLength: e, minLength: t, type: "text" });
401
+ }
402
+ serialize() {
403
+ return super._serialize();
404
+ }
405
+ static deserialize(i) {
406
+ if (i.type !== "text")
407
+ throw new Error("Type mismatch.");
408
+ const { maximum_length: e, minimum_length: t, ...n } = i;
409
+ return new ee({ ...n, maxLength: e, minLength: t });
410
+ }
411
+ getInput(i) {
412
+ return /* @__PURE__ */ r(Ii, { field: this, ...i });
413
+ }
414
+ };
415
+ p(ee, "fieldTypeName", "Paragraph"), p(ee, "fieldTypeDescription", "Paragraph fields can hold up to 5000 characters and can have multiple lines."), p(ee, "Icon", Ot);
416
+ let he = ee;
417
+ const xi = z(function(i) {
418
+ const [{ inputId: e, labelId: t, severity: n, helpText: s, label: a, fieldProps: l, field: c, helpers: f }, u] = H(i), { setValue: d, setTouched: h, setError: m } = f, g = T(
419
+ () => c.options.map((I) => ({ value: I.value, itemContent: I.label })),
420
+ [c.options]
421
+ ), y = E(
422
+ (I) => {
423
+ d(I, !1).then(), h(!0, !1).then(), m(c.getError(I));
424
+ },
425
+ [h, d, m, c]
426
+ );
427
+ return /* @__PURE__ */ r(j, { helpText: s, severity: n, children: /* @__PURE__ */ r(W, { severity: n, inputId: e, labelId: t, label: a, children: /* @__PURE__ */ r(
428
+ st,
429
+ {
430
+ items: g,
431
+ ...l,
432
+ onValueChange: y,
433
+ placeholder: "Select one...",
434
+ id: e,
435
+ severity: n,
436
+ ...u
437
+ }
438
+ ) }) });
439
+ }), ye = (o = "", i = []) => ({
440
+ type: "section",
441
+ fields: i,
442
+ identifier: o,
443
+ label: null,
444
+ condition: null,
445
+ conditional: !1
446
+ }), Ci = (o) => {
447
+ if (!o)
448
+ return;
449
+ const i = o.fields;
450
+ let e = [];
451
+ const t = [];
452
+ for (const n of i)
453
+ n.type === "section" ? (e.length > 0 && (t.push(ye(`AUTO_section-${i.indexOf(n)}`, e)), e = []), t.push(n)) : e.push(n);
454
+ return e.length > 0 && t.push(ye("AUTO_section-last", e)), { ...o, fields: t };
455
+ };
456
+ function Re(o, i, e) {
457
+ const t = Array.from(o), [n] = t.splice(i, 1);
458
+ if (!n)
459
+ throw new Error("Could not find field to reorder.");
460
+ return t.splice(e, 0, n), t;
461
+ }
462
+ function Ti(o, i, e) {
463
+ const t = Array.from(o);
464
+ return t[i] = e, t;
465
+ }
466
+ function pt(o, i, e) {
467
+ const t = Array.from(o ?? []);
468
+ return t.splice(i, 0, e), t;
469
+ }
470
+ function ve(o, i) {
471
+ const e = Array.from(o);
472
+ return e.splice(i, 1), e;
473
+ }
474
+ const Fi = (o, i) => typeof o == "string" && o.length > 0 ? o : at(i), mt = (o, i) => {
475
+ if (!i)
476
+ return null;
477
+ for (const e of o)
478
+ if (e.type === "section") {
479
+ const t = mt(e.fields, i);
480
+ if (t)
481
+ return t;
482
+ } else if (e.identifier === i)
483
+ return e;
484
+ return null;
485
+ }, qe = (o, i) => o.filter((e, t) => t < i).flatMap((e) => e.fields), Si = z(function(i) {
486
+ const [{ inputId: e, labelId: t, severity: n, helpText: s, label: a, fieldProps: l, field: c, helpers: f }, u] = H(i), d = pe(n), h = T(() => Array.isArray(l.value) ? l.value : [], [l.value]), { setValue: m, setTouched: g, setError: y } = f, I = `${e}-droppable`, { disabled: w } = u, [x, P] = de(""), [A, L] = de(""), O = A || s, B = A ? "red" : d, V = E(
487
+ (S) => {
488
+ m(S, !1).then(), g(!0, !1).then(), y(c.getError(S));
489
+ },
490
+ [m, g, y, c]
491
+ ), F = E(
492
+ (S) => {
493
+ h.findIndex((_) => _.value === S.target.value.trim()) >= 0 ? L("All options must be unique") : S.target.value ? L("") : L("Option cannot be empty"), P(S.target.value);
494
+ },
495
+ [P, h]
496
+ ), C = E(() => {
497
+ if (A)
498
+ return;
499
+ if (!x.trim())
500
+ return L("Option cannot be empty");
501
+ const S = x.trim();
502
+ V([...h, { value: S, label: S }]), P("");
503
+ }, [x, A, V, h]), M = E(
504
+ (S) => {
505
+ S.key === "Enter" && (S.preventDefault(), C());
506
+ },
507
+ [C]
508
+ ), D = E(
509
+ (S) => {
510
+ V(ve(h, S));
511
+ },
512
+ [h, V]
513
+ ), N = E(
514
+ (S) => {
515
+ if (!S.destination)
516
+ return;
517
+ const _ = S.source.index, U = S.destination.index;
518
+ V(Re(h, _, U));
519
+ },
520
+ [V, h]
521
+ );
522
+ return /* @__PURE__ */ r(lt, { onDragEnd: N, children: /* @__PURE__ */ b(v, { direction: "column", gap: "2", children: [
523
+ /* @__PURE__ */ r(j, { helpText: O, severity: n, children: /* @__PURE__ */ r(W, { severity: n, inputId: e, labelId: t, label: a, children: (!w || h.length === 0) && /* @__PURE__ */ b(v, { gap: "2", children: [
524
+ /* @__PURE__ */ r(ge, { grow: "1", children: /* @__PURE__ */ r(
525
+ oe.Input,
526
+ {
527
+ placeholder: "Press enter to add a new option",
528
+ ...u,
529
+ ...l,
530
+ value: x,
531
+ onChange: F,
532
+ onKeyDown: M,
533
+ id: e,
534
+ color: B,
535
+ onBlur: void 0
536
+ }
537
+ ) }),
538
+ /* @__PURE__ */ r(
539
+ ce,
540
+ {
541
+ type: "button",
542
+ "aria-label": "Add option",
543
+ disabled: !!A || w,
544
+ onClick: C,
545
+ children: /* @__PURE__ */ r(Se, {})
546
+ }
547
+ )
548
+ ] }) }) }),
549
+ /* @__PURE__ */ r(Ue, { droppableId: I, children: (S) => /* @__PURE__ */ b(v, { ...S.droppableProps, ref: S.innerRef, direction: "column", children: [
550
+ h.map((_, U) => /* @__PURE__ */ r(
551
+ Ge,
552
+ {
553
+ draggableId: `${_.value}-draggable`,
554
+ index: U,
555
+ isDragDisabled: w,
556
+ children: ({ draggableProps: Y, dragHandleProps: Me, innerRef: St }) => /* @__PURE__ */ r(
557
+ v,
558
+ {
559
+ ...Me,
560
+ ...Y,
561
+ ref: St,
562
+ gap: "2",
563
+ align: "center",
564
+ justify: "between",
565
+ mb: "1",
566
+ asChild: !0,
567
+ children: /* @__PURE__ */ b(_e, { color: "gray", size: "2", children: [
568
+ /* @__PURE__ */ r("span", { children: _.label }),
569
+ /* @__PURE__ */ r(
570
+ ce,
571
+ {
572
+ size: "small",
573
+ variant: "ghost",
574
+ type: "button",
575
+ "aria-label": "Delete option",
576
+ severity: "info",
577
+ disabled: w,
578
+ onClick: () => D(U),
579
+ children: /* @__PURE__ */ r(Vt, {})
580
+ }
581
+ )
582
+ ] })
583
+ }
584
+ )
585
+ },
586
+ _.value
587
+ )),
588
+ S.placeholder
589
+ ] }) })
590
+ ] }) });
591
+ }), te = class te extends R {
592
+ constructor(e) {
593
+ const { minimum_length: t, maximum_length: n, ...s } = e;
594
+ super({ ...s, type: "multi-string" });
595
+ p(this, "minLength");
596
+ p(this, "maxLength");
597
+ this.minLength = t ?? 0, this.maxLength = n ?? 1 / 0;
598
+ }
599
+ getInput(e) {
600
+ return /* @__PURE__ */ r(Si, { field: this, ...e });
601
+ }
602
+ serialize() {
603
+ return { ...super._serialize(), minimum_length: this.minLength, maximum_length: this.maxLength };
604
+ }
605
+ isBlank(e) {
606
+ return super.isBlank(e) || e.length === 0;
607
+ }
608
+ getFieldValidators() {
609
+ const e = super.getFieldValidators();
610
+ return e.push((t) => {
611
+ if (Array.isArray(t) && t.length < this.minLength)
612
+ return `Must have at least ${this.minLength} options.`;
613
+ }), e.push((t) => {
614
+ if (Array.isArray(t) && t.length > this.maxLength)
615
+ return `Must have at most ${this.maxLength} options.`;
616
+ }), e;
617
+ }
618
+ static deserialize(e) {
619
+ if (e.type !== "multi-string")
620
+ throw new Error("Type mismatch.");
621
+ return new te(e);
622
+ }
623
+ };
624
+ p(te, "fieldTypeName", "Multi-string"), p(te, "fieldTypeDescription", "Allows the user to provide multiple unique strings."), p(te, "Icon", _t);
625
+ let we = te;
626
+ class gt extends R {
627
+ constructor(e) {
628
+ super(e);
629
+ p(this, "options");
630
+ const t = /* @__PURE__ */ new Set();
631
+ this.options = e.options.map((n) => (typeof n == "string" && (n = { label: n, value: n }), t.add(n.label), n)), t.size !== e.options.length && console.error(
632
+ `${e.options.length - t.size} duplicate identifiers found in options. This may cause unexpected behavior. Options:`,
633
+ e.options
634
+ );
635
+ }
636
+ _serialize() {
637
+ return {
638
+ ...super._serialize(),
639
+ options: this.options
640
+ };
641
+ }
642
+ static getFieldCreationSchema() {
643
+ return [
644
+ new we({
645
+ label: "Options",
646
+ description: "List possible options for the user to select from.",
647
+ required: !0,
648
+ identifier: "options",
649
+ minimum_length: 2,
650
+ maximum_length: 20
651
+ })
652
+ ];
653
+ }
654
+ }
655
+ const ie = class ie extends gt {
656
+ constructor(i) {
657
+ super({ ...i, type: "select" });
658
+ }
659
+ serialize() {
660
+ return super._serialize();
661
+ }
662
+ static deserialize(i) {
663
+ if (i.type !== "select")
664
+ throw new Error("Type mismatch.");
665
+ return new ie(i);
666
+ }
667
+ getInput(i) {
668
+ return /* @__PURE__ */ r(xi, { field: this, ...i });
669
+ }
670
+ };
671
+ p(ie, "fieldTypeName", "Dropdown"), p(ie, "fieldTypeDescription", "Allows the user to select a single option from a list of options."), p(ie, "Icon", $t);
672
+ let Ie = ie;
673
+ const Ei = z(function(i) {
674
+ const [{ inputId: e, labelId: t, severity: n, helpText: s, label: a, fieldProps: l, field: c, helpers: f }, u] = H(i), { setValue: d, setTouched: h, setError: m } = f, g = T(() => Array.isArray(l.value) ? l.value : [], [l.value]), y = E(
675
+ (I) => {
676
+ d(I, !1).then(), h(!0, !1).then(), m(c.getError(I));
677
+ },
678
+ [h, d, m, c]
679
+ );
680
+ return /* @__PURE__ */ r(j, { helpText: s, severity: n, children: /* @__PURE__ */ r(W, { severity: n, inputId: e, labelId: t, label: a, children: /* @__PURE__ */ r(
681
+ Rt,
682
+ {
683
+ value: g,
684
+ onValueChange: y,
685
+ options: c.options,
686
+ name: l.name,
687
+ placeholder: "Select one or more...",
688
+ id: e,
689
+ severity: n,
690
+ ...u
691
+ }
692
+ ) }) });
693
+ }), ne = class ne extends gt {
694
+ constructor(i) {
695
+ super({ ...i, type: "multi-select" });
696
+ }
697
+ isBlank(i) {
698
+ return super.isBlank(i) || i.length === 0;
699
+ }
700
+ serialize() {
701
+ return super._serialize();
702
+ }
703
+ static deserialize(i) {
704
+ if (i.type !== "multi-select")
705
+ throw new Error("Type mismatch.");
706
+ return new ne(i);
707
+ }
708
+ getInput(i) {
709
+ return /* @__PURE__ */ r(Ei, { field: this, ...i });
710
+ }
711
+ };
712
+ p(ne, "fieldTypeName", "Multi-select"), p(ne, "fieldTypeDescription", "Allows the user to select a multiple options from a list of options."), p(ne, "Icon", qt);
713
+ let Ne = ne;
714
+ const zi = z(function({ field: i, ...e }) {
715
+ const [{ value: t }] = We(i.options.clonedFieldIdentifier), n = T(() => {
716
+ const s = i.options.getFieldToClone(t);
717
+ return s ? De(s) : null;
718
+ }, [i.options, t]);
719
+ return Ce(n, e);
720
+ });
721
+ class xe extends R {
722
+ constructor(e, t) {
723
+ super({ ...e, type: "custom" });
724
+ p(this, "Component");
725
+ // identifier of the field whose value is the label of the field to re-render
726
+ p(this, "options");
727
+ this.options = e, this.Component = t;
728
+ }
729
+ serialize() {
730
+ throw new Error("Serializing only supported for public input types.");
731
+ }
732
+ getInput(e) {
733
+ const t = this.Component;
734
+ return /* @__PURE__ */ r(t, { field: this, ...e });
735
+ }
736
+ }
737
+ p(xe, "fieldTypeName", "Custom"), p(xe, "fieldTypeDescription", "Allows re-rendering of field already in the form");
738
+ class Li extends xe {
739
+ constructor(i) {
740
+ super(i, zi);
741
+ }
742
+ }
743
+ const Pi = z(function(i) {
744
+ const { field: e, ...t } = i, { label: n, description: s, fields: a, condition: l } = e, { values: c, setFieldValue: f } = ae(), u = l != null && l.identifier ? se(c, l.identifier) : void 0, d = T(() => vt(l, u), [l, u]);
745
+ Pe(() => {
746
+ if (!d)
747
+ for (const m of a)
748
+ f(m.getId(), "").then();
749
+ }, [d, a, f]);
750
+ const h = wt(a, t);
751
+ return d ? n ? /* @__PURE__ */ r(Ee, { children: /* @__PURE__ */ b(v, { direction: "column", gap: "3", children: [
752
+ /* @__PURE__ */ b(v, { direction: "column", children: [
753
+ /* @__PURE__ */ r(ze, { as: "h3", size: "3", children: n }),
754
+ /* @__PURE__ */ r(k, { className: Ae.description, children: s })
755
+ ] }),
756
+ h
757
+ ] }) }) : h : null;
758
+ }), re = class re extends ht {
759
+ constructor(e) {
760
+ const { label: t = null, fields: n, condition: s = null, conditional: a, ...l } = e;
761
+ super({ ...l, type: "section" });
762
+ p(this, "label");
763
+ p(this, "fields");
764
+ p(this, "condition");
765
+ this.fields = n, this.condition = s, this.label = t, a === !1 && (this.condition = null);
766
+ }
767
+ static getFieldCreationSchema(e) {
768
+ return e.length === 0 ? [] : [
769
+ new le({
770
+ label: "Conditional",
771
+ description: "Conditionally show or hide this section.",
772
+ identifier: "conditional",
773
+ required: !1
774
+ }),
775
+ // Declare a section that will hold options for the condition (if any).
776
+ new re({
777
+ label: "Conditional settings",
778
+ identifier: "conditional-settings",
779
+ // This section will only be rendered if the above "Conditional" field is checked.
780
+ condition: {
781
+ identifier: "conditional",
782
+ value: !0
783
+ },
784
+ // These are the options of the condition.
785
+ fields: [
786
+ // Declare a select field that will be used to select the field against which we will check the
787
+ // condition. This must be selected before the next field is rendered.
788
+ new Ie({
789
+ label: "Field",
790
+ description: "The field to use for the condition.",
791
+ // The options (for the field against which we will check the condition) are all the labels of
792
+ // the fields in the previous section(s) (or fields declared before with no section) that
793
+ // support conditions. We pass in both the label and the identifier of each supported field. The
794
+ // identifier becomes the value of the option.
795
+ options: e.map((t) => t.label ? {
796
+ label: t.label,
797
+ value: t.identifier
798
+ } : null).filter((t) => !!t),
799
+ identifier: "condition.identifier",
800
+ required: !0
801
+ }),
802
+ // Declare a custom field that will be used to input a value for the condition. The value of the
803
+ // conditional field selected in the previous step must be equal to the value the user inputs into
804
+ // this field for the section to be rendered.
805
+ new Li({
806
+ label: "Value",
807
+ identifier: "condition.value",
808
+ required: !0,
809
+ clonedFieldIdentifier: "condition.identifier",
810
+ getFieldToClone(t) {
811
+ if (!t)
812
+ return null;
813
+ const n = e.find((s) => s.identifier === t);
814
+ return n ? {
815
+ ...n,
816
+ // Override some options to make it make sense in the context and to make it work with the framework.
817
+ label: "Value",
818
+ identifier: "condition.value",
819
+ description: "The value to compare against.",
820
+ required: n.type !== "boolean"
821
+ } : (console.error("Could not find field with identifier", t), null);
822
+ }
823
+ })
824
+ ]
825
+ })
826
+ ];
827
+ }
828
+ static deserialize(e) {
829
+ var n;
830
+ if (e.type !== "section")
831
+ throw new Error("Invalid type");
832
+ const t = ((n = e.fields) == null ? void 0 : n.map(bt)) ?? [];
833
+ return new re({ ...e, fields: t });
834
+ }
835
+ conditional() {
836
+ return this.condition !== null;
837
+ }
838
+ serialize() {
839
+ return {
840
+ ...super._serialize(),
841
+ label: this.label,
842
+ condition: this.condition,
843
+ conditional: this.conditional(),
844
+ fields: this.fields.map((e) => e.serialize())
845
+ };
846
+ }
847
+ getErrors(e) {
848
+ const t = {};
849
+ for (const n of this.fields) {
850
+ const s = n.getId(), a = n.getError(se(e, s), e);
851
+ a && Ye(t, n.getId(), a);
852
+ }
853
+ return t;
854
+ }
855
+ getInput(e) {
856
+ return /* @__PURE__ */ r(Pi, { field: this, ...e });
857
+ }
858
+ };
859
+ p(re, "fieldTypeName", "Section"), p(re, "fieldTypeDescription", "Sections can be useful for grouping fields together. They can also be conditionally shown or hidden.");
860
+ let K = re;
861
+ const Qe = {
862
+ date: $e,
863
+ number: ue,
864
+ boolean: le,
865
+ select: Ie,
866
+ string: fe,
867
+ text: he,
868
+ custom: xe,
869
+ // TODO: Underscore
870
+ "multi-string": we,
871
+ "multi-select": Ne
872
+ }, bt = (o) => {
873
+ const i = o.type;
874
+ return Qe[i].deserialize(o);
875
+ }, De = (o) => o.type === "section" ? K.deserialize(o) : bt(o);
876
+ function yt(o, i = {}) {
877
+ const { readonly: e = !1 } = i;
878
+ return {
879
+ title: o.title,
880
+ description: o.description,
881
+ fields: o.fields.map((t) => De(t)),
882
+ meta: { readonly: e }
883
+ };
884
+ }
885
+ function vt(o, i) {
886
+ if (!o)
887
+ return !0;
888
+ const e = Array.isArray(i) ? i.map((n) => typeof n == "string" ? n : n.value) : i, t = Array.isArray(o.value) ? o.value.map((n) => typeof n == "string" ? n : n.value) : o.value;
889
+ if (Array.isArray(t) && Array.isArray(e)) {
890
+ for (const n of t)
891
+ if (!e.includes(n))
892
+ return !1;
893
+ return !0;
894
+ }
895
+ return t === i;
896
+ }
897
+ const Ce = (o, i) => T(() => !i || !o ? null : o.getInput(i), [o, i]), wt = (o, i) => {
898
+ const e = T(() => o.map((t) => /* @__PURE__ */ r("div", { children: t.getInput(i) }, t.getId())), [o, i]);
899
+ return /* @__PURE__ */ r(v, { direction: "column", gap: "2", children: e });
900
+ }, Te = (o) => Object.keys(o).length > 0, It = async (o, i) => {
901
+ const e = {};
902
+ for (const t of o.fields)
903
+ if (t instanceof K) {
904
+ if (t.condition) {
905
+ const { identifier: n } = t.condition;
906
+ if (!vt(t.condition, se(i, n)))
907
+ continue;
908
+ }
909
+ Object.assign(e, t.getErrors(i));
910
+ } else {
911
+ if (!(t instanceof R))
912
+ throw new Error("Invalid field type");
913
+ const n = t.getId(), s = t.getError(se(i, n), i);
914
+ s && Ye(e, n, s);
915
+ }
916
+ if (Te(e))
917
+ return e;
918
+ }, Ai = [null, void 0], Xe = (o, i) => o.reduce((e, t) => t instanceof K ? { ...e, ...Xe(t.fields, i) } : (Ai.includes(se(e, t.getId())) && Ye(e, t.getId(), ""), e), i), Di = () => {
919
+ throw new Error("onSubmit must be provided if form is not readonly.");
920
+ }, Je = z(
921
+ me((o, i) => {
922
+ const {
923
+ schema: e,
924
+ values: t = {},
925
+ onSubmit: n = Di,
926
+ submitText: s = "Submit",
927
+ cancelText: a,
928
+ onCancel: l,
929
+ onDirty: c,
930
+ // if the title isn't provided, hide it by default
931
+ hideTitle: f = !e.title,
932
+ hideDescription: u,
933
+ className: d
934
+ } = o, { readonly: h } = e.meta, m = T(() => crypto.randomUUID(), []), g = je({
935
+ initialValues: Xe(e.fields, t),
936
+ onSubmit: n,
937
+ validate: (P) => It(e, P),
938
+ // only validate the entire form on submit
939
+ validateOnBlur: !1,
940
+ validateOnChange: !1
941
+ }), { dirty: y } = g, I = T(
942
+ () => typeof e.title == "string" ? /* @__PURE__ */ r(ze, { children: e.title }) : e.title,
943
+ [e.title]
944
+ ), w = T(
945
+ () => typeof e.description == "string" ? /* @__PURE__ */ r(k, { className: Ae.description, children: e.description }) : e.description,
946
+ [e.description]
947
+ ), x = wt(e.fields, { formId: m, disabled: h });
948
+ return Pe(() => {
949
+ y && c && c();
950
+ }, [y, c]), /* @__PURE__ */ r(He, { value: g, children: /* @__PURE__ */ r(v, { ref: i, direction: "column", gap: "2", className: d, asChild: !0, children: /* @__PURE__ */ b("form", { id: m, onSubmit: g.handleSubmit, children: [
951
+ !f && /* @__PURE__ */ r(Ee, { children: /* @__PURE__ */ b(v, { direction: "column", gap: "1", children: [
952
+ I,
953
+ !u && w
954
+ ] }) }),
955
+ x,
956
+ !h && /* @__PURE__ */ b(v, { justify: "end", gap: "2", children: [
957
+ a && /* @__PURE__ */ r(G, { type: "button", variant: "soft", onClick: l, children: a }),
958
+ /* @__PURE__ */ r(G, { type: "submit", disabled: !g.isValid, children: s })
959
+ ] })
960
+ ] }) }) });
961
+ })
962
+ ), fn = z(
963
+ me((o, i) => {
964
+ const { submission: e, showFormDescription: t = !1, showFormTitle: n = !0 } = o, s = $(ct(e.form_revision));
965
+ if (!s)
966
+ throw new Error(
967
+ `Could not find revision ${e.form_revision} for submission ${e.offline_id}.`
968
+ );
969
+ const a = T(() => yt(s, { readonly: !0 }), [s]);
970
+ return /* @__PURE__ */ r(
971
+ Je,
972
+ {
973
+ ref: i,
974
+ schema: a,
975
+ values: e.values,
976
+ hideDescription: !t,
977
+ hideTitle: !n
978
+ }
979
+ );
980
+ })
981
+ ), ki = "_favoriteIcon_1bixi_1", Mi = "_regularIcon_1bixi_9", et = {
982
+ favoriteIcon: ki,
983
+ regularIcon: Mi
984
+ }, Oe = "organization:", Ve = "user:", hn = z(
985
+ me((o, i) => {
986
+ const { maxResults: e = 20, ...t } = o, [n, s] = de(""), [a, l] = de(""), { sdk: c } = si(), f = T(() => {
987
+ const x = { maxResults: e, searchTerm: n };
988
+ return a && (a.startsWith(Oe) ? x.owner_organization = parseInt(a.slice(Oe.length)) : a.startsWith(Ve) && (x.owner_user = parseInt(a.slice(Ve.length)))), x;
989
+ }, [n, e, a]), u = $(li(f)) ?? [], d = $(ai), h = E(
990
+ (x) => {
991
+ x.favorite ? c.userForms.unfavorite(x.offline_id).then() : c.userForms.favorite(x.offline_id).then();
992
+ },
993
+ [c]
994
+ ), m = T(() => {
995
+ const x = c.store.getState(), P = {};
996
+ for (const A of Object.values(d)) {
997
+ const L = dt(A.owner_organization || -1)(x);
998
+ L && (P[`${Oe}${L.id}`] = L.name);
999
+ const O = Ke(A.owner_user || -1)(x);
1000
+ O && (P[`${Ve}${O.id}`] = O.username);
1001
+ }
1002
+ return Object.entries(P).map(([A, L]) => ({ itemContent: L, value: A }));
1003
+ }, [d, c.store]), g = E((x) => {
1004
+ s(x.currentTarget.value);
1005
+ }, []), I = ($(ci) || 0) - u.length, w = u.length == e && I > 0 ? `Only the first ${e} results are shown (${I} hidden)` : I > 0 && `${I} hidden forms`;
1006
+ return /* @__PURE__ */ b(v, { ref: i, direction: "column", gap: "2", children: [
1007
+ /* @__PURE__ */ b(v, { gap: "2", grow: "1", children: [
1008
+ /* @__PURE__ */ r(ge, { grow: "1", asChild: !0, children: /* @__PURE__ */ r(oe.Root, { size: "3", children: /* @__PURE__ */ r(oe.Input, { placeholder: "Filter", value: n, onChange: g }) }) }),
1009
+ /* @__PURE__ */ r(
1010
+ st,
1011
+ {
1012
+ items: m,
1013
+ value: a,
1014
+ onValueChange: l,
1015
+ placeholder: "Owner",
1016
+ size: "large"
1017
+ }
1018
+ )
1019
+ ] }),
1020
+ u.length > 0 && /* @__PURE__ */ r(Le.Root, { children: u.map((x) => /* @__PURE__ */ r(
1021
+ Oi,
1022
+ {
1023
+ ...t,
1024
+ form: x,
1025
+ handleToggleFavorite: () => h(x)
1026
+ },
1027
+ x.offline_id
1028
+ )) }),
1029
+ /* @__PURE__ */ r(ge, { px: "3", children: /* @__PURE__ */ r(k, { size: "2", severity: "info", children: w }) })
1030
+ ] });
1031
+ })
1032
+ ), Oi = (o) => {
1033
+ var h;
1034
+ const { form: i, onSelectForm: e, isFavoriteEditable: t, handleToggleFavorite: n } = o, s = (h = $(dt(i.owner_organization || -1))) == null ? void 0 : h.name, a = $(Ke(i.owner_user || -1)), l = $(ut).id, c = !!a && a.id === l, f = s ?? (c ? "You" : a == null ? void 0 : a.username) ?? "Unknown", u = E(
1035
+ (m) => {
1036
+ m.stopPropagation(), n();
1037
+ },
1038
+ [n]
1039
+ ), d = /* @__PURE__ */ r(Le.Item, { onClick: () => e(i), asChild: !0, children: /* @__PURE__ */ b(v, { justify: "between", gap: "2", py: "2", px: "3", ...Nt, children: [
1040
+ /* @__PURE__ */ b(v, { grow: "1", align: "center", gap: "2", children: [
1041
+ /* @__PURE__ */ r(
1042
+ ce,
1043
+ {
1044
+ className: ft(i.favorite ? et.favoriteIcon : et.regularIcon),
1045
+ variant: "ghost",
1046
+ onClick: u,
1047
+ "aria-label": i.favorite ? "Favorite form" : "Standard form",
1048
+ disabled: !t,
1049
+ children: i.favorite ? /* @__PURE__ */ r(Bt, {}) : /* @__PURE__ */ r(Wt, {})
1050
+ }
1051
+ ),
1052
+ /* @__PURE__ */ r(k, { noWrap: !0, children: i.latestRevision.title }),
1053
+ i.latestRevision.description && /* @__PURE__ */ r(jt, {})
1054
+ ] }),
1055
+ f && /* @__PURE__ */ b(v, { align: "center", gap: "2", children: [
1056
+ /* @__PURE__ */ r(Ht, {}),
1057
+ " ",
1058
+ f
1059
+ ] })
1060
+ ] }) });
1061
+ return i.latestRevision.description ? /* @__PURE__ */ r(Ut, { content: i.latestRevision.description, children: d }, i.offline_id) : d;
1062
+ }, Vi = "_submissionsContainer_9iirt_1", _i = "_stopHorizontalOverflow_9iirt_6", xt = {
1063
+ submissionsContainer: Vi,
1064
+ stopHorizontalOverflow: _i
1065
+ }, $i = z(function(i) {
1066
+ var x;
1067
+ const { submission: e, onSubmissionClick: t, compact: n, labelType: s, rowDecorator: a } = i, l = $(ut), c = $(Ke("created_by" in e ? e.created_by : l.id)), f = Be(e), u = di(f) ? f.toLocaleTimeString([], {
1068
+ hour: "2-digit",
1069
+ minute: "2-digit"
1070
+ }) : ui(f), d = $(ct(e.form_revision));
1071
+ if (!d)
1072
+ throw new Error(`Could not find revision ${e.form_revision} for submission ${e.offline_id}.`);
1073
+ const h = (x = $(fi(d.form))) == null ? void 0 : x.revision, m = hi({
1074
+ file: (c == null ? void 0 : c.profile.file) ?? null,
1075
+ fileSha1: (c == null ? void 0 : c.profile.file_sha1) ?? null
1076
+ }), g = (c == null ? void 0 : c.username.charAt(0).toUpperCase()) ?? "?", y = d.revision === h, I = ri.useCallback(() => {
1077
+ t && t({ submission: e });
1078
+ }, [e, t]), w = /* @__PURE__ */ r(Le.Item, { onClick: I, asChild: !0, children: /* @__PURE__ */ b(v, { grow: "1", width: "100%", p: "2", gap: "2", justify: "between", children: [
1079
+ /* @__PURE__ */ b(v, { gap: "2", align: "center", className: xt.stopHorizontalOverflow, children: [
1080
+ /* @__PURE__ */ r(Gt, { src: m, size: "1", fallback: g }),
1081
+ /* @__PURE__ */ r(k, { size: "2", noWrap: !0, children: s === "creator" ? (c || l).username : d.title })
1082
+ ] }),
1083
+ /* @__PURE__ */ b(v, { gap: "2", align: "center", children: [
1084
+ !n && (d.revision ? /* @__PURE__ */ r(_e, { variant: "soft", severity: y ? "primary" : "info", children: n ? d.revision.toString() : `Revision #${d.revision}` }) : !!h && /* @__PURE__ */ r(_e, { children: "Original" })),
1085
+ /* @__PURE__ */ r(k, { size: "2", noWrap: !0, children: u })
1086
+ ] })
1087
+ ] }) });
1088
+ return a ? a(e, w) : w;
1089
+ }), Be = (o) => {
1090
+ const i = "created_at" in o ? o.created_at : o.submitted_at;
1091
+ return new Date(i);
1092
+ }, pn = z(function(i) {
1093
+ const {
1094
+ formId: e,
1095
+ submissions: t,
1096
+ compact: n = !1,
1097
+ className: s,
1098
+ after: a,
1099
+ variant: l = "outline",
1100
+ ...c
1101
+ } = i;
1102
+ if (!!e == !!t)
1103
+ throw new Error("Either formId or submissions must be provided, but not both.");
1104
+ const f = $(
1105
+ t ? () => t : pi(e)
1106
+ ), u = T(
1107
+ () => f == null ? void 0 : f.sort((d, h) => Be(h).getTime() - Be(d).getTime()),
1108
+ [f]
1109
+ );
1110
+ return /* @__PURE__ */ r(
1111
+ Le.Root,
1112
+ {
1113
+ className: ft(xt.submissionsContainer, s),
1114
+ size: "small",
1115
+ variant: l,
1116
+ before: !n && /* @__PURE__ */ b(k, { severity: "info", children: [
1117
+ "There are ",
1118
+ ((f == null ? void 0 : f.length) || 0).toString(),
1119
+ " submissions of this form."
1120
+ ] }),
1121
+ after: a,
1122
+ children: u == null ? void 0 : u.map((d, h) => /* @__PURE__ */ r(
1123
+ $i,
1124
+ {
1125
+ submission: d,
1126
+ compact: n,
1127
+ ...c
1128
+ },
1129
+ h
1130
+ ))
1131
+ }
1132
+ );
1133
+ }), mn = z(function(i) {
1134
+ const { name: e, render: t } = i, { submitForm: n } = ae(), [s, a, l] = We(e);
1135
+ return T(() => {
1136
+ const c = (f) => l.setValue(f, !1);
1137
+ return t({
1138
+ value: s.value,
1139
+ setValue: c,
1140
+ patchValue: n
1141
+ });
1142
+ }, [n, l, s.value, t]);
1143
+ }), gn = z(
1144
+ me((o, i) => {
1145
+ const { children: e, schema: t, values: n, onPatch: s, onError: a, ...l } = o, c = T(() => Xe(t.fields, n), [t.fields, n]), f = E(
1146
+ (g) => {
1147
+ const y = {};
1148
+ for (const I in g) {
1149
+ const w = g[I];
1150
+ w !== c[I] && w !== void 0 && (y[I] = w);
1151
+ }
1152
+ Te(y) && s(y);
1153
+ },
1154
+ [c, s]
1155
+ ), u = E(
1156
+ async (g) => {
1157
+ const y = await It(t, g);
1158
+ return y && a(y), y;
1159
+ },
1160
+ [t, a]
1161
+ ), d = je({
1162
+ initialValues: c,
1163
+ onSubmit: f,
1164
+ validate: u,
1165
+ // only validate the entire form on submit
1166
+ validateOnBlur: !1,
1167
+ validateOnChange: !1
1168
+ }), { errors: h, resetForm: m } = d;
1169
+ return Pe(() => {
1170
+ Te(h) && m({ values: c, errors: {} });
1171
+ }, [h, c, m]), /* @__PURE__ */ r(He, { value: d, children: /* @__PURE__ */ r("form", { ...l, ref: i, onSubmit: d.handleSubmit, children: e }) });
1172
+ })
1173
+ ), Ct = {
1174
+ ...Qe,
1175
+ section: K
1176
+ }, Ri = z(function(i) {
1177
+ const { field: e, setFieldType: t } = i, n = e.fieldTypeName, s = e.fieldTypeDescription, a = e.Icon;
1178
+ return /* @__PURE__ */ b(v, { gap: "4", align: "center", children: [
1179
+ /* @__PURE__ */ r(G, { type: "button", variant: "surface", onClick: t, style: { width: "135px" }, children: /* @__PURE__ */ b(v, { gap: "3", align: "center", grow: "1", children: [
1180
+ /* @__PURE__ */ r(a, {}),
1181
+ n
1182
+ ] }) }),
1183
+ /* @__PURE__ */ r(k, { children: s })
1184
+ ] });
1185
+ }), Tt = [
1186
+ ["string", "text"],
1187
+ ["select", "multi-select"],
1188
+ ["boolean", "date", "number", "multi-string"]
1189
+ ], qi = Tt.length - 1, Ni = z(function(i) {
1190
+ const { setFieldType: e } = i;
1191
+ return /* @__PURE__ */ r(v, { direction: "column", gap: "3", children: Tt.map((t, n) => /* @__PURE__ */ b(v, { direction: "column", gap: "3", children: [
1192
+ /* @__PURE__ */ r(v, { direction: "column", gap: "2", children: t.map((s) => /* @__PURE__ */ r(
1193
+ Ri,
1194
+ {
1195
+ field: Qe[s],
1196
+ setFieldType: () => e(s)
1197
+ },
1198
+ s
1199
+ )) }),
1200
+ n < qi && /* @__PURE__ */ r(Kt, { size: "4" })
1201
+ ] }, n)) });
1202
+ }), Bi = (o) => (i) => {
1203
+ if (!i || typeof i != "string")
1204
+ return;
1205
+ const e = at(i);
1206
+ if (o.includes(e))
1207
+ return "This name is already taken.";
1208
+ }, Wi = (o, i) => {
1209
+ const e = [
1210
+ new fe({
1211
+ label: "Label",
1212
+ required: !0,
1213
+ maxLength: 100,
1214
+ identifier: "label",
1215
+ fieldValidators: [Bi(o)]
1216
+ }),
1217
+ new he({
1218
+ label: "Description",
1219
+ required: !1,
1220
+ maxLength: 1e3,
1221
+ identifier: "description"
1222
+ })
1223
+ ];
1224
+ return i === "section" ? e : [
1225
+ ...e,
1226
+ new le({ label: "Required", description: null, required: !1, identifier: "required" })
1227
+ ];
1228
+ }, ji = z(function(i) {
1229
+ const { fieldType: e, handleCancel: t, handleCreateField: n, defaultField: s, conditionalSourceFields: a } = i, l = Ct[e], c = ae(), f = T(() => {
1230
+ const u = c.values.fields.flatMap(
1231
+ (h) => h.type === "section" ? [...h.fields.map((m) => m.identifier), h.identifier] : h.identifier
1232
+ ).filter((h) => h !== (s == null ? void 0 : s.identifier));
1233
+ let d = Wi(u, e);
1234
+ if (l === K) {
1235
+ if (a === void 0)
1236
+ throw new Error("Conditional source fields must be provided when changing sections.");
1237
+ d = d.concat(l.getFieldCreationSchema(a));
1238
+ } else {
1239
+ if (!(l.prototype instanceof R))
1240
+ throw new Error(`Field must be an instance of BaseField. Got ${l}.`);
1241
+ d = [...d, ...l.getFieldCreationSchema()];
1242
+ }
1243
+ return {
1244
+ fields: d,
1245
+ meta: { readonly: !1 },
1246
+ // using the dialog title as the form title
1247
+ title: null
1248
+ };
1249
+ }, [c.values.fields, e, l, s == null ? void 0 : s.identifier, a]);
1250
+ return /* @__PURE__ */ r(
1251
+ Je,
1252
+ {
1253
+ schema: f,
1254
+ values: s,
1255
+ onSubmit: n,
1256
+ cancelText: s ? void 0 : "Back",
1257
+ onCancel: t
1258
+ }
1259
+ );
1260
+ }), Fe = z(function(i) {
1261
+ const { parentPath: e, index: t, children: n, initial: s, editing: a, conditionalSourceFields: l } = i, [c, f] = de(), u = (s == null ? void 0 : s.type) ?? c, d = u ? Ct[u].fieldTypeName : void 0, { setFieldValue: h, values: m } = ae();
1262
+ if (a && !s)
1263
+ throw new Error("Initial field must be provided if editing is true.");
1264
+ const g = !u && !a && !s, y = g ? "Choose a field type" : `${d} settings`, I = g ? "Select a field type to add to this section." : (d == null ? void 0 : d.toLowerCase()) === "section" ? "Customize your section" : `Customize your ${d == null ? void 0 : d.toLowerCase()} field.`, w = E(() => f(void 0), []), x = E((L) => {
1265
+ f(void 0), L();
1266
+ }, []), P = E(
1267
+ (L, O) => {
1268
+ const { label: B } = L;
1269
+ if (!u)
1270
+ throw new Error("Field type must be selected before creating a field.");
1271
+ if (!B || typeof B != "string")
1272
+ throw new Error("Label must be provided before creating a field.");
1273
+ const V = De({
1274
+ type: u,
1275
+ ...L,
1276
+ identifier: Fi(L.identifier, B)
1277
+ }).serialize(), F = se(m, e);
1278
+ if (F === void 0)
1279
+ throw new Error("Parent path must point to an existing field.");
1280
+ let C;
1281
+ if (!Array.isArray(F))
1282
+ throw new Error("Parent path must point to an array.");
1283
+ a ? C = Ti(F, t, V) : C = pt(F, t, V), h(e, C).then(), O();
1284
+ },
1285
+ [a, u, m, e, h, t]
1286
+ ), A = E(
1287
+ (L) => g ? /* @__PURE__ */ r(Ni, { setFieldType: f }) : /* @__PURE__ */ r(
1288
+ ji,
1289
+ {
1290
+ conditionalSourceFields: l,
1291
+ handleCancel: w,
1292
+ handleCreateField: (O) => P(O, L),
1293
+ fieldType: u,
1294
+ defaultField: s
1295
+ }
1296
+ ),
1297
+ [l, w, P, s, g, u]
1298
+ );
1299
+ return /* @__PURE__ */ r(Yt, { onCloseInterrupt: x, title: y, description: I, content: A, children: n });
1300
+ }), tt = ({ children: o }) => /* @__PURE__ */ r(ot, { children: o }), it = (o, i) => ({
1301
+ initial: o ? i : "none",
1302
+ sm: o ? "none" : i
1303
+ }), Ft = z(function(i) {
1304
+ const { remove: e, dragHandleProps: t, editProps: n, insertAfterProps: s } = i, a = T(
1305
+ () => [
1306
+ {
1307
+ Wrapper: Fe,
1308
+ wrapperProps: n,
1309
+ Icon: Qt,
1310
+ text: "Edit"
1311
+ },
1312
+ {
1313
+ Icon: Xt,
1314
+ buttonProps: {
1315
+ onClick: e
1316
+ },
1317
+ text: "Delete"
1318
+ },
1319
+ {
1320
+ Wrapper: Fe,
1321
+ wrapperProps: s,
1322
+ Icon: Se,
1323
+ text: "Add after"
1324
+ },
1325
+ {
1326
+ // Wrapping icon in a div so that the asChild turns the button into a div
1327
+ // so that the drag handle props are not applied to the icon
1328
+ // Note: b/c the <button> does not handle the space-press event correctly
1329
+ Icon: (l) => /* @__PURE__ */ r("div", { ...l, children: /* @__PURE__ */ r(Jt, {}) }),
1330
+ text: "Reorder",
1331
+ disableOnMobile: !0,
1332
+ buttonProps: { ...t, asChild: !0 }
1333
+ }
1334
+ ],
1335
+ [t, n, s, e]
1336
+ );
1337
+ return /* @__PURE__ */ b(ot, { children: [
1338
+ /* @__PURE__ */ r(v, { gap: "4", display: it(!1, "flex"), children: a.map((l) => {
1339
+ const c = l.Wrapper ?? tt;
1340
+ return /* @__PURE__ */ r(c, { ...l.wrapperProps, children: /* @__PURE__ */ r(ce, { type: "button", variant: "ghost", "aria-label": l.text, ...l.buttonProps, children: /* @__PURE__ */ r(l.Icon, {}) }) }, l.text);
1341
+ }) }),
1342
+ /* @__PURE__ */ r(ge, { display: it(!0, "block"), children: /* @__PURE__ */ r(
1343
+ Zt,
1344
+ {
1345
+ trigger: /* @__PURE__ */ r(ce, { variant: "ghost", "aria-label": "Actions menu", children: /* @__PURE__ */ r(ei, {}) }),
1346
+ closeOnSelect: !1,
1347
+ items: a.map((l) => {
1348
+ var f;
1349
+ if (l.disableOnMobile)
1350
+ return null;
1351
+ const c = l.Wrapper ?? tt;
1352
+ return {
1353
+ ...l.buttonProps,
1354
+ onSelect: (f = l.buttonProps) == null ? void 0 : f.onClick,
1355
+ content: /* @__PURE__ */ r(c, { ...l.wrapperProps, children: /* @__PURE__ */ b(v, { gap: "2", align: "center", children: [
1356
+ /* @__PURE__ */ r(l.Icon, {}),
1357
+ l.text
1358
+ ] }) })
1359
+ };
1360
+ }).filter((l) => l !== null)
1361
+ }
1362
+ ) })
1363
+ ] });
1364
+ }), ke = "form-builder", Hi = z(function(i) {
1365
+ const { field: e, index: t, sectionIndex: n, remove: s } = i, a = T(() => De(e), [e]), l = Ce(a, { formId: ke, disabled: !0 }), c = T(
1366
+ () => ({
1367
+ index: t,
1368
+ parentPath: `fields.${n}.fields`,
1369
+ initial: e,
1370
+ editing: !0
1371
+ }),
1372
+ [e, t, n]
1373
+ ), f = T(
1374
+ () => ({
1375
+ parentPath: `fields.${n}.fields`,
1376
+ index: t + 1,
1377
+ initial: void 0
1378
+ }),
1379
+ [t, n]
1380
+ );
1381
+ return /* @__PURE__ */ r(Ge, { draggableId: e.identifier, index: t, children: (u) => /* @__PURE__ */ r(
1382
+ Ee,
1383
+ {
1384
+ ref: u.innerRef,
1385
+ ...u.draggableProps,
1386
+ ...u.dragHandleProps,
1387
+ mb: "4",
1388
+ children: /* @__PURE__ */ b(v, { gap: "4", justify: "between", align: "center", children: [
1389
+ l,
1390
+ /* @__PURE__ */ r(
1391
+ Ft,
1392
+ {
1393
+ remove: s,
1394
+ editProps: c,
1395
+ insertAfterProps: f,
1396
+ dragHandleProps: u.dragHandleProps
1397
+ }
1398
+ )
1399
+ ] })
1400
+ }
1401
+ ) });
1402
+ }), Ui = z(function(i) {
1403
+ var P, A, L, O, B, V;
1404
+ const { field: e, index: t, dropState: n } = i, s = (P = n[e.identifier]) == null ? void 0 : P.disabled, { setFieldValue: a, values: l } = ae(), c = ti(), f = E(
1405
+ (F, C) => {
1406
+ for (const M of F) {
1407
+ const D = C.indexOf(M);
1408
+ a(`fields.${D}.condition`, null).then(), a(`fields.${D}.conditional`, !1).then();
1409
+ }
1410
+ },
1411
+ [a]
1412
+ ), u = E(
1413
+ (F) => {
1414
+ var D;
1415
+ const C = e.fields[F];
1416
+ if (!C)
1417
+ throw new Error("Could not find field to remove.");
1418
+ const M = [];
1419
+ for (const N of l.fields)
1420
+ ((D = N.condition) == null ? void 0 : D.identifier) === C.identifier && M.push(N);
1421
+ return {
1422
+ removing: C,
1423
+ affectedSections: M,
1424
+ action: () => a(`fields.${t}.fields`, ve(e.fields, F))
1425
+ };
1426
+ },
1427
+ [e.fields, l.fields, a, t]
1428
+ ), d = E(
1429
+ (F) => {
1430
+ const { affectedSections: C, action: M, removing: D } = u(F), N = () => {
1431
+ M().then(), f(C, l.fields);
1432
+ };
1433
+ if (C.length > 0) {
1434
+ const S = C.map((_) => _.label).join(", ");
1435
+ return c({
1436
+ title: "Remove condition?",
1437
+ description: `${D.label} is being used as a condition, deleting it will remove the condition from the ${S} section(s).`,
1438
+ severity: "danger",
1439
+ actionText: "Remove",
1440
+ onAction: N
1441
+ });
1442
+ }
1443
+ N();
1444
+ },
1445
+ [u, f, l.fields, c]
1446
+ ), h = E(() => {
1447
+ const C = e.fields.map((Y, Me) => u(Me)).flatMap((Y) => Y.affectedSections), M = C.length ? "Remove fields and conditions?" : "Remove fields?", D = e.fields.length, N = C.map((Y) => Y.label).join(", "), S = C.length ? `Deleting this section will remove the ${D} field(s) it contains and will remove the conditions from following sections: ${N}` : `Deleting this section will remove the ${D} field(s) it contains.`, _ = ve(l.fields, t), U = () => a("fields", _);
1448
+ if (C.length > 0)
1449
+ return c({
1450
+ title: M,
1451
+ description: S,
1452
+ severity: "danger",
1453
+ actionText: "Remove",
1454
+ onAction: () => {
1455
+ U().then(() => {
1456
+ f(C, _);
1457
+ });
1458
+ }
1459
+ });
1460
+ U().then();
1461
+ }, [
1462
+ e.fields,
1463
+ l.fields,
1464
+ t,
1465
+ u,
1466
+ a,
1467
+ c,
1468
+ f
1469
+ ]), m = T(
1470
+ () => ({
1471
+ index: t,
1472
+ parentPath: "fields",
1473
+ initial: e,
1474
+ editing: !0,
1475
+ conditionalSourceFields: qe(l.fields, t)
1476
+ }),
1477
+ [e, t, l.fields]
1478
+ ), g = T(
1479
+ () => ({
1480
+ index: t + 1,
1481
+ parentPath: "fields",
1482
+ initial: ye(),
1483
+ conditionalSourceFields: qe(l.fields, t + 1)
1484
+ }),
1485
+ [t, l.fields]
1486
+ ), y = T(
1487
+ () => ({
1488
+ parentPath: `fields.${t}.fields`,
1489
+ index: e.fields.length,
1490
+ initial: void 0
1491
+ }),
1492
+ [e.fields.length, t]
1493
+ ), I = T(
1494
+ () => {
1495
+ var F, C;
1496
+ return (C = mt(l.fields, (F = e.condition) == null ? void 0 : F.identifier)) == null ? void 0 : C.label;
1497
+ },
1498
+ [(A = e.condition) == null ? void 0 : A.identifier, l.fields]
1499
+ ), w = Array.isArray((L = e.condition) == null ? void 0 : L.value) ? "contains all of" : "equals", x = Array.isArray((O = e.condition) == null ? void 0 : O.value) ? (B = e.condition) == null ? void 0 : B.value.map((F) => typeof F == "string" ? F : F.label).join(", ") : (V = e.condition) == null ? void 0 : V.value.toString();
1500
+ return /* @__PURE__ */ r(Ge, { draggableId: e.identifier, index: t, children: (F) => /* @__PURE__ */ r(
1501
+ Ee,
1502
+ {
1503
+ ref: F.innerRef,
1504
+ ...F.draggableProps,
1505
+ ...F.dragHandleProps,
1506
+ mb: "4",
1507
+ children: /* @__PURE__ */ b(v, { gap: "3", justify: "between", align: "center", children: [
1508
+ /* @__PURE__ */ b(v, { direction: "column", gap: "2", grow: "1", children: [
1509
+ /* @__PURE__ */ b(v, { direction: "column", children: [
1510
+ /* @__PURE__ */ r(ze, { as: "h3", size: "3", children: e.label }),
1511
+ /* @__PURE__ */ r(k, { className: Ae.description, children: e.description })
1512
+ ] }),
1513
+ e.condition && /* @__PURE__ */ r(k, { size: "1", children: /* @__PURE__ */ b(ii, { children: [
1514
+ "Display only if ",
1515
+ /* @__PURE__ */ r(Ze, { children: I }),
1516
+ " ",
1517
+ w,
1518
+ " ",
1519
+ /* @__PURE__ */ r(Ze, { children: x })
1520
+ ] }) }),
1521
+ /* @__PURE__ */ r(Ue, { droppableId: e.identifier, type: "SECTION", isDropDisabled: s, children: (C) => /* @__PURE__ */ b(
1522
+ v,
1523
+ {
1524
+ ref: C.innerRef,
1525
+ ...C.droppableProps,
1526
+ direction: "column",
1527
+ gap: "0",
1528
+ children: [
1529
+ e.fields.map((M, D) => /* @__PURE__ */ r(
1530
+ Hi,
1531
+ {
1532
+ field: M,
1533
+ index: D,
1534
+ sectionIndex: t,
1535
+ remove: () => d(D)
1536
+ },
1537
+ M.identifier
1538
+ )),
1539
+ C.placeholder,
1540
+ /* @__PURE__ */ r(Fe, { ...y, children: /* @__PURE__ */ b(G, { type: "button", variant: "outline", children: [
1541
+ /* @__PURE__ */ r(Se, {}),
1542
+ " Add a field"
1543
+ ] }) })
1544
+ ]
1545
+ }
1546
+ ) })
1547
+ ] }),
1548
+ /* @__PURE__ */ r(
1549
+ Ft,
1550
+ {
1551
+ remove: h,
1552
+ insertAfterProps: g,
1553
+ dragHandleProps: F.dragHandleProps,
1554
+ editProps: m
1555
+ }
1556
+ )
1557
+ ] })
1558
+ }
1559
+ ) });
1560
+ }), Gi = (o, i) => {
1561
+ var t;
1562
+ const e = { ...o };
1563
+ switch (i.type) {
1564
+ case "release":
1565
+ for (const n in e)
1566
+ e[n].disabled = !1;
1567
+ return e;
1568
+ case "hold":
1569
+ for (const n in e)
1570
+ (t = e[n]) != null && t.conditionFields.has(i.fieldId) && (e[n].disabled = !0);
1571
+ return e;
1572
+ case "update":
1573
+ return i.state;
1574
+ }
1575
+ }, Ki = (o, i) => {
1576
+ if (i)
1577
+ for (let e = 0; e < o.length; e++) {
1578
+ const t = o[e];
1579
+ if (t) {
1580
+ for (const n of t.fields)
1581
+ if (n.identifier === i)
1582
+ return e;
1583
+ }
1584
+ }
1585
+ }, nt = (o) => {
1586
+ var e, t, n;
1587
+ const i = {};
1588
+ for (let s = 0; s < o.length; s++) {
1589
+ const a = o[s];
1590
+ if (!a)
1591
+ throw new Error("Field is undefined.");
1592
+ const l = s > 0 ? (e = i[o[s - 1].identifier]) == null ? void 0 : e.conditionFields : void 0, c = new Set(l);
1593
+ (t = a.condition) != null && t.identifier && c.add(a.condition.identifier), i[a.identifier] = {
1594
+ disabled: !1,
1595
+ conditionFields: c,
1596
+ conditionIndex: Ki(o, (n = a.condition) == null ? void 0 : n.identifier),
1597
+ index: s,
1598
+ label: a.label
1599
+ };
1600
+ }
1601
+ return i;
1602
+ }, rt = (o, i) => {
1603
+ for (const [e, t] of Object.entries(o))
1604
+ if (t.identifier === i)
1605
+ return [t, e];
1606
+ }, Yi = z(function() {
1607
+ const { values: i, setFieldValue: e } = ae(), [t, n] = oi(Gi, i.fields, nt), { showInfo: s } = ni();
1608
+ Pe(() => {
1609
+ n({ type: "update", state: nt(i.fields) });
1610
+ }, [n, i.fields]);
1611
+ const a = E((f) => {
1612
+ f.type === "SECTION" && n({ type: "hold", fieldId: f.draggableId });
1613
+ }, []), l = E(
1614
+ (f) => {
1615
+ const { source: u, destination: d, type: h, reason: m, draggableId: g } = f;
1616
+ if (n({ type: "release" }), !d || m === "CANCEL")
1617
+ return;
1618
+ if (h === "ROOT") {
1619
+ const P = t[g];
1620
+ if (!P)
1621
+ throw new Error("Could not find section context.");
1622
+ let A = typeof P.conditionIndex < "u" ? (
1623
+ // cannot move a section with a condition before the condition's field
1624
+ Math.max(P.conditionIndex + 1, d.index)
1625
+ ) : d.index;
1626
+ for (const L of Object.values(t))
1627
+ L.conditionIndex === u.index && (A = Math.min(A, L.index - 1));
1628
+ return A != d.index && s({
1629
+ title: "Reordered sections",
1630
+ description: "Sections with conditions must be below the fields they reference."
1631
+ }), e("fields", Re(i.fields, u.index, A));
1632
+ }
1633
+ if (h !== "SECTION")
1634
+ throw new Error("Unexpected droppable type.");
1635
+ const [y, I] = rt(i.fields, u.droppableId) ?? [], [w, x] = rt(i.fields, d.droppableId) ?? [];
1636
+ if (!(y != null && y.fields) || !w)
1637
+ throw new Error("Could not find section with fields.");
1638
+ if (y.identifier === w.identifier)
1639
+ e(
1640
+ `fields.${I}.fields`,
1641
+ Re(y.fields, u.index, d.index)
1642
+ ).then();
1643
+ else {
1644
+ const P = y.fields[u.index];
1645
+ if (!P)
1646
+ throw new Error("Could not find field to reorder.");
1647
+ e(`fields.${I}.fields`, ve(y.fields, u.index)).then(), e(
1648
+ `fields.${x}.fields`,
1649
+ pt(w.fields, d.index, P)
1650
+ ).then();
1651
+ }
1652
+ },
1653
+ [i.fields, e, t, s]
1654
+ ), c = T(
1655
+ () => ({
1656
+ index: i.fields.length,
1657
+ parentPath: "fields",
1658
+ initial: ye(),
1659
+ conditionalSourceFields: qe(i.fields, i.fields.length)
1660
+ }),
1661
+ [i.fields]
1662
+ );
1663
+ return /* @__PURE__ */ r(lt, { onDragStart: a, onDragEnd: l, children: /* @__PURE__ */ r(Ue, { droppableId: "droppable", type: "ROOT", children: (f) => /* @__PURE__ */ b(
1664
+ v,
1665
+ {
1666
+ ref: f.innerRef,
1667
+ ...f.droppableProps,
1668
+ direction: "column",
1669
+ gap: "0",
1670
+ children: [
1671
+ i.fields.map((u, d) => /* @__PURE__ */ r(
1672
+ Ui,
1673
+ {
1674
+ field: u,
1675
+ index: d,
1676
+ dropState: t
1677
+ },
1678
+ u.label
1679
+ )),
1680
+ f.placeholder,
1681
+ /* @__PURE__ */ r(Fe, { ...c, children: /* @__PURE__ */ b(G, { type: "button", variant: "outline", children: [
1682
+ /* @__PURE__ */ r(Se, {}),
1683
+ " Add a section"
1684
+ ] }) })
1685
+ ]
1686
+ }
1687
+ ) }) });
1688
+ }), Qi = {
1689
+ title: "",
1690
+ description: "",
1691
+ fields: []
1692
+ }, Xi = new fe({
1693
+ label: "Title",
1694
+ minLength: 0,
1695
+ maxLength: 100,
1696
+ required: !0,
1697
+ identifier: "title"
1698
+ }), Ji = { formId: ke, placeholder: "Give your form a title." }, Zi = new he({
1699
+ label: "Description",
1700
+ minLength: 0,
1701
+ maxLength: 1e3,
1702
+ required: !1,
1703
+ identifier: "description"
1704
+ }), en = { formId: ke, placeholder: "Explain the purpose of this form." }, tn = () => {
1705
+ alert("This is a form preview, your data will not be saved.");
1706
+ }, bn = z(
1707
+ me((o, i) => {
1708
+ const { onCancel: e, onSave: t, revision: n } = o, s = n ? "Edit form" : "Create a new form", { heading: a = s } = o, l = E((m) => {
1709
+ const g = {};
1710
+ if (m.title || (g.title = "Title is required."), (!m.fields || m.fields.length === 0) && (g.fields = "At least one field is required."), Te(g))
1711
+ return g;
1712
+ }, []), c = je({
1713
+ initialValues: Ci(n) ?? Qi,
1714
+ validate: l,
1715
+ onSubmit: (m) => t(m),
1716
+ // only validate the entire for on submit
1717
+ validateOnChange: !1,
1718
+ validateOnBlur: !1
1719
+ }), f = T(() => yt(c.values), [c.values]), u = Ce(Xi, Ji), d = Ce(Zi, en), h = T(
1720
+ () => typeof a == "object" ? a : /* @__PURE__ */ r(ze, { children: a }),
1721
+ [a]
1722
+ );
1723
+ return /* @__PURE__ */ r(Q.Root, { ref: i, defaultValue: "edit", children: /* @__PURE__ */ b(v, { direction: "column", gap: "2", children: [
1724
+ /* @__PURE__ */ b(Q.List, { children: [
1725
+ /* @__PURE__ */ r(Q.Trigger, { value: "edit", children: "Edit" }),
1726
+ /* @__PURE__ */ r(Q.Trigger, { value: "preview", children: "Preview" })
1727
+ ] }),
1728
+ /* @__PURE__ */ b(Q.Content, { value: "edit", children: [
1729
+ h,
1730
+ /* @__PURE__ */ b(k, { children: [
1731
+ "Add a new form field by clicking a + button. Specify options for each field, then drag and drop to rearrange them. You can see what a submitted form might look like in the",
1732
+ " ",
1733
+ /* @__PURE__ */ r("em", { children: "Preview" }),
1734
+ " tab, but",
1735
+ " ",
1736
+ /* @__PURE__ */ r("strong", { children: "field values entered on this page will not be saved." })
1737
+ ] }),
1738
+ /* @__PURE__ */ r(v, { asChild: !0, direction: "column", gap: "2", mt: "3", children: /* @__PURE__ */ b("form", { id: ke, onSubmit: c.handleSubmit, children: [
1739
+ /* @__PURE__ */ b(He, { value: c, children: [
1740
+ u,
1741
+ d,
1742
+ /* @__PURE__ */ r(Yi, {}),
1743
+ /* @__PURE__ */ r(k, { severity: "danger", size: "1", children: typeof c.errors.fields == "string" && c.errors.fields })
1744
+ ] }),
1745
+ /* @__PURE__ */ b(v, { justify: "end", gap: "2", children: [
1746
+ /* @__PURE__ */ r(G, { type: "button", variant: "soft", onClick: e, children: "Cancel" }),
1747
+ /* @__PURE__ */ r(G, { type: "submit", disabled: !c.isValid, children: "Save" })
1748
+ ] })
1749
+ ] }) })
1750
+ ] }),
1751
+ /* @__PURE__ */ r(Q.Content, { value: "preview", children: /* @__PURE__ */ r(Je, { schema: f, onSubmit: tn }) })
1752
+ ] }) });
1753
+ })
1754
+ );
1755
+ export {
1756
+ le as BooleanField,
1757
+ bi as BooleanInput,
1758
+ $e as DateField,
1759
+ vi as DateInput,
1760
+ K as FieldSection,
1761
+ hn as FormBrowser,
1762
+ bn as FormBuilder,
1763
+ Je as FormRenderer,
1764
+ pn as FormSubmissionBrowser,
1765
+ fn as FormSubmissionViewer,
1766
+ Ne as MultiSelectField,
1767
+ Ei as MultiSelectInput,
1768
+ we as MultiStringField,
1769
+ Si as MultiStringInput,
1770
+ ue as NumberField,
1771
+ yi as NumberInput,
1772
+ mn as PatchField,
1773
+ gn as PatchFormProvider,
1774
+ Ie as SelectField,
1775
+ xi as SelectInput,
1776
+ fe as StringField,
1777
+ wi as StringInput,
1778
+ he as TextField,
1779
+ Ii as TextInput,
1780
+ De as deserialize,
1781
+ bt as deserializeField,
1782
+ yt as formRevisionToSchema,
1783
+ vt as isConditionMet,
1784
+ Ce as useFieldInput,
1785
+ wt as useFieldInputs
1786
+ };