@overmap-ai/forms 1.0.1 → 1.0.2

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