@overmap-ai/forms 1.0.1 → 1.0.3-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/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 kt = Object.defineProperty;
2
+ var _t = (s, i, e) => i in s ? kt(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 y, Fragment as dt } from "react/jsx-runtime";
5
+ import { Flex as v, Text as k, useSeverityColor as de, Checkbox as Mt, CheckCircledIcon as $t, TextField as se, FontFamilyIcon as Ot, CalendarIcon as Rt, InputIcon as Nt, TextArea as Bt, RowsIcon as qt, Select as ut, Box as me, IconButton as le, PlusIcon as De, Badge as Oe, Cross1Icon as ft, ListBulletIcon as Wt, DropdownMenuIcon as jt, MultiSelect as Ht, CheckboxIcon as Ut, Card as ge, Heading as Le, Button as H, UploadIcon as mt, ButtonList as Pe, divButtonProps as Gt, StarFilledIcon as Kt, StarIcon as Yt, QuestionMarkCircledIcon as Qt, PersonIcon as Xt, Tooltip as Jt, Avatar as Zt, Separator as ei, useDiscardAlertDialog as ti, Dialog as ii, Pencil1Icon as ni, TrashIcon as ri, DragHandleDots2Icon as oi, DropdownMenu as si, DotsVerticalIcon as li, useAlertDialog as ai, Em as ci, Strong as nt, useToast as di, Tabs as Q } from "@overmap-ai/blocks";
6
+ import { useField as He, useFormikContext as ue, useFormik as Ue, FormikProvider as Ge } from "formik";
7
+ import ui, { useMemo as C, memo as S, useCallback as E, useState as U, useEffect as be, useRef as fi, forwardRef as ye, useReducer as mi } from "react";
8
+ import { DragDropContext as ht, Droppable as Ke, Draggable as Ye } from "@hello-pangea/dnd";
9
+ import { slugify as hi, useAppSelector as M, selectFormRevision as pt, useSDK as gt, selectSubmissionAttachments as pi, selectFilteredUserForms as gi, selectUserFormMapping as bi, selectOrganization as bt, selectUser as Qe, selectNumberOfUserForms as yi, selectCurrentUser as yt, classNames as vt, isToday as vi, getLocalDateString as wi, selectLatestFormRevision as xi, useFileSrc as Ii, selectSubmissionsForForm as Ci } 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 $ extends wt {
37
37
  constructor(e) {
38
- const { label: t, required: n, fieldValidators: s = [], formValidators: a = [], ...l } = e;
39
- super(l);
40
- p(this, "required");
41
- p(this, "formValidators");
42
- p(this, "fieldValidators");
43
- p(this, "label");
44
- this.label = t, this.required = n, this.fieldValidators = s, this.formValidators = a;
38
+ const { label: t, required: n, fieldValidators: o = [], formValidators: l = [], ...a } = e;
39
+ super(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 = l;
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,55 +89,49 @@ 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;
87
- return /* @__PURE__ */ r(v, { direction: "column", gap: "1", asChild: !0, ...a, children: /* @__PURE__ */ b("label", { htmlFor: n, children: [
88
- /* @__PURE__ */ r(k, { severity: t, id: s, children: i }),
92
+ m($, "fieldTypeName"), m($, "fieldTypeDescription");
93
+ const Fi = "_description_17zed_1", Ve = {
94
+ description: Fi
95
+ }, q = (s) => {
96
+ const { label: i, children: e, severity: t, inputId: n, labelId: o, flexProps: l } = s;
97
+ return /* @__PURE__ */ r(v, { direction: "column", gap: "1", asChild: !0, ...l, children: /* @__PURE__ */ y("label", { htmlFor: n, children: [
98
+ /* @__PURE__ */ r(k, { severity: t, id: o, children: i }),
89
99
  e
90
100
  ] }) });
91
- }, j = (o) => {
92
- const { helpText: i, children: e, severity: t } = o;
93
- return /* @__PURE__ */ b(v, { direction: "column", gap: "1", children: [
101
+ }, W = (s) => {
102
+ const { helpText: i, children: e, severity: t } = s;
103
+ return /* @__PURE__ */ y(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(k, { size: "1", severity: t, className: Ve.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
+ }, j = (s) => {
108
+ const { id: i, field: e, formId: t, ...n } = s, [o, l, a] = He(e.getId()), { touched: c } = l, u = l.error ?? e.description, d = l.error ? "danger" : void 0, f = i ?? `${t}-${e.getId()}-input`, h = `${f}-label`, p = e.required ? `${e.label} *` : e.label, g = C(() => ({
109
+ ...o,
110
+ onChange: (I) => {
111
+ const w = e.getValueFromChangeEvent(I);
112
+ a.setValue(w, !1).then(), (c || !e.onlyValidateAfterTouched) && a.setError(e.getError(w));
102
113
  },
103
- onBlur: (w) => {
104
- l.setTouched(!0, !1).then(), l.setError(e.getError(w.target.value));
114
+ onBlur: (I) => {
115
+ a.setTouched(!0, !1).then(), a.setError(e.getError(e.getValueFromChangeEvent(I)));
105
116
  }
106
- }), [e, s, l, c]);
117
+ }), [e, o, a, c]);
107
118
  return [
108
119
  {
109
- helpText: f,
110
- severity: u,
111
- inputId: d,
120
+ helpText: u,
121
+ severity: d,
122
+ inputId: f,
112
123
  labelId: h,
113
- label: m,
124
+ label: p,
114
125
  fieldProps: g,
115
- helpers: l,
126
+ helpers: a,
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
+ }, Ti = [!0, "true"], Si = S(function(i) {
132
+ const [{ inputId: e, labelId: t, severity: n, helpText: o, label: l, fieldProps: a }, c] = j(i), u = de(n), d = Ti.includes(a.value);
133
+ return /* @__PURE__ */ r(W, { helpText: o, severity: n, children: /* @__PURE__ */ r(
134
+ q,
131
135
  {
132
136
  severity: n,
133
137
  inputId: e,
@@ -135,75 +139,83 @@ const mi = "_description_17zed_1", Ae = {
135
139
  label: l,
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
+ ...a,
142
146
  id: e,
143
- color: d,
144
- value: y.toString(),
145
- checked: y,
146
- onCheckedChange: I,
147
+ color: u,
148
+ value: d.toString(),
149
+ checked: d,
150
+ onCheckedChange: a.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
+ }), X = class X extends $ {
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 X(e);
168
176
  }
169
- getInput(i) {
170
- return /* @__PURE__ */ r(bi, { ...i, field: this });
177
+ getInput(e) {
178
+ return /* @__PURE__ */ r(Si, { ...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(
178
- oe.Input,
181
+ m(X, "fieldTypeName", "Checkbox"), m(X, "fieldTypeDescription", "Perfect for both optional and required yes/no questions."), m(X, "Icon", $t);
182
+ let ce = X;
183
+ const zi = S(function(i) {
184
+ const [{ inputId: e, labelId: t, severity: n, helpText: o, label: l, fieldProps: a, field: c }, u] = j(i), d = de(n);
185
+ return /* @__PURE__ */ r(W, { helpText: o, severity: n, children: /* @__PURE__ */ r(q, { severity: n, inputId: e, labelId: t, label: l, children: /* @__PURE__ */ r(
186
+ se.Input,
179
187
  {
180
- ...f,
181
- ...l,
188
+ ...u,
189
+ ...a,
182
190
  type: "number",
183
191
  id: e,
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
+ }), R = class R extends $ {
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,
196
- ...a
203
+ integers: o = !1,
204
+ ...l
197
205
  } = e;
198
- super({ ...a, type: "number" });
199
- p(this, "minimum");
200
- p(this, "maximum");
201
- p(this, "integers");
202
- this.minimum = t, this.maximum = n, this.integers = s;
206
+ super({ ...l, type: "number" });
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 R({
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 R({
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 R(e);
255
267
  }
256
268
  getInput(e) {
257
- return /* @__PURE__ */ r(yi, { field: this, ...e });
269
+ return /* @__PURE__ */ r(zi, { 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(R, "fieldTypeName", "Number"), m(R, "fieldTypeDescription", "Allows specifying a number within a given range."), m(R, "Icon", Ot), m(R, "_validateMin", (e, t) => typeof t.maximum == "number" && typeof e == "number" && t.maximum < e ? "Minimum cannot be greater than minimum." : null), m(R, "_validateMax", (e, t) => typeof t.minimum == "number" && typeof e == "number" && t.minimum > e ? "Maximum cannot be less than minimum." : null);
273
+ let G = R;
274
+ const Ei = S(function(i) {
275
+ const [{ inputId: e, labelId: t, severity: n, helpText: o, label: l, fieldProps: a }, c] = j(i), u = de(n), d = a.value ? a.value.split("T")[0] : "";
276
+ return /* @__PURE__ */ r(W, { helpText: o, severity: n, children: /* @__PURE__ */ r(q, { severity: n, inputId: e, labelId: t, label: l, children: /* @__PURE__ */ r(se.Input, { ...c, ...a, type: "date", id: e, color: u, value: d }) }) });
277
+ }), J = class J extends $ {
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 J(e);
293
292
  }
294
- getInput(i) {
295
- return /* @__PURE__ */ r(vi, { field: this, ...i });
293
+ getInput(e) {
294
+ return /* @__PURE__ */ r(Ei, { 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(J, "fieldTypeName", "Date"), m(J, "fieldTypeDescription", "Allows specifying a date."), m(J, "Icon", Rt);
298
+ let Re = J;
299
+ class we extends $ {
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 G({
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 G({
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 Ai = S(function(i) {
369
+ const [{ inputId: e, labelId: t, severity: n, helpText: o, label: l, fieldProps: a, field: c }, u] = j(i), d = de(n);
370
+ return /* @__PURE__ */ r(W, { helpText: o, severity: n, children: /* @__PURE__ */ r(q, { severity: n, inputId: e, labelId: t, label: l, children: /* @__PURE__ */ r(se.Input, { ...u, ...a, type: c.inputType, id: e, color: d }) }) });
371
+ }), Z = class Z 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, l = e.minLength ? Math.min(e.minLength, o) : void 0;
374
+ super({ ...n, maxLength: o, minLength: l, 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, ...l } = e;
385
+ return new Z({ ...l, maxLength: t, minLength: n, inputType: o });
387
386
  }
388
387
  getInput(e) {
389
- return /* @__PURE__ */ r(wi, { field: this, ...e });
388
+ return /* @__PURE__ */ r(Ai, { 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(Z, "fieldTypeName", "Short Text"), m(Z, "fieldTypeDescription", "Short text fields can hold up to 500 characters on a single line."), m(Z, "Icon", Nt);
392
+ let he = Z;
393
+ const Di = S(function(i) {
394
+ const [{ inputId: e, labelId: t, severity: n, helpText: o, label: l, fieldProps: a }, c] = j(i);
395
+ return /* @__PURE__ */ r(W, { helpText: o, severity: n, children: /* @__PURE__ */ r(q, { severity: n, inputId: e, labelId: t, label: l, children: /* @__PURE__ */ r(Bt, { ...c, ...a, resize: "vertical", id: e, severity: n }) }) });
396
+ }), ee = class ee 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" });
@@ -409,195 +408,206 @@ const Ii = z(function(i) {
409
408
  return new ee({ ...n, maxLength: e, minLength: t });
410
409
  }
411
410
  getInput(i) {
412
- return /* @__PURE__ */ r(Ii, { field: this, ...i });
411
+ return /* @__PURE__ */ r(Di, { 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(ee, "fieldTypeName", "Paragraph"), m(ee, "fieldTypeDescription", "Paragraph fields can hold up to 5000 characters and can have multiple lines."), m(ee, "Icon", qt);
415
+ let pe = ee;
416
+ const Li = S(function(i) {
417
+ const [{ inputId: e, labelId: t, severity: n, helpText: o, label: l, fieldProps: a, field: c }, u] = j(i), { onChange: d, onBlur: f } = a, 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 = E(
421
+ (g) => {
422
+ d(g), f(g);
424
423
  },
425
- [h, d, m, c]
424
+ [d, f]
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(W, { helpText: o, severity: n, children: /* @__PURE__ */ r(q, { severity: n, inputId: e, labelId: t, label: l, children: /* @__PURE__ */ r(
427
+ ut,
429
428
  {
430
- items: g,
431
- ...l,
432
- onValueChange: y,
429
+ items: h,
430
+ ...a,
431
+ onValueChange: p,
433
432
  placeholder: "Select one...",
434
433
  id: e,
435
434
  severity: n,
436
435
  ...u
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 `${hi(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), _i = S(function(i) {
490
+ const [{ inputId: e, labelId: t, severity: n, helpText: o, label: l, fieldProps: a }, c] = j(i), u = de(n), d = C(() => Array.isArray(a.value) ? a.value : [], [a.value]), { onChange: f, onBlur: h } = a, p = `${e}-droppable`, { disabled: g } = c, [x, z] = U(""), [I, w] = U(""), L = I || o, P = I ? "red" : u, F = E(
491
+ (b) => {
492
+ f(b), h(b);
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
+ [f, h]
495
+ ), V = E(
496
+ (b) => {
497
+ d.findIndex((A) => A.value === b.target.value.trim()) >= 0 ? w("All options must be unique") : b.target.value ? w("") : w("Option cannot be empty"), z(b.target.value);
494
498
  },
495
- [P, h]
496
- ), C = E(() => {
497
- if (A)
499
+ [z, d]
500
+ ), N = E(() => {
501
+ if (I)
498
502
  return;
499
503
  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());
504
+ return w("Option cannot be empty");
505
+ const b = x.trim();
506
+ F([...d, { value: b, label: b }]), z("");
507
+ }, [x, I, F, d]), _ = E(
508
+ (b) => {
509
+ b.key === "Enter" && (b.preventDefault(), N());
506
510
  },
507
- [C]
508
- ), D = E(
509
- (S) => {
510
- V(ve(h, S));
511
+ [N]
512
+ ), O = E(
513
+ (b) => {
514
+ F(Ie(d, b));
511
515
  },
512
- [h, V]
513
- ), N = E(
514
- (S) => {
515
- if (!S.destination)
516
+ [d, F]
517
+ ), T = E(
518
+ (b) => {
519
+ if (!b.destination)
516
520
  return;
517
- const _ = S.source.index, U = S.destination.index;
518
- V(Re(h, _, U));
521
+ const A = b.source.index, D = b.destination.index;
522
+ F(Ne(d, A, D));
519
523
  },
520
- [V, h]
524
+ [F, 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(
525
- oe.Input,
526
+ return /* @__PURE__ */ r(ht, { onDragEnd: T, children: /* @__PURE__ */ y(v, { direction: "column", gap: "2", children: [
527
+ /* @__PURE__ */ r(W, { helpText: L, severity: n, children: /* @__PURE__ */ r(q, { severity: n, inputId: e, labelId: t, label: l, children: (!g || d.length === 0) && /* @__PURE__ */ y(v, { gap: "2", children: [
528
+ /* @__PURE__ */ r(me, { grow: "1", children: /* @__PURE__ */ r(
529
+ se.Input,
526
530
  {
527
531
  placeholder: "Press enter to add a new option",
528
- ...u,
529
- ...l,
532
+ ...c,
533
+ ...a,
530
534
  value: x,
531
- onChange: F,
532
- onKeyDown: M,
535
+ onChange: V,
536
+ onKeyDown: _,
533
537
  id: e,
534
- color: B,
538
+ color: P,
535
539
  onBlur: void 0
536
540
  }
537
541
  ) }),
538
542
  /* @__PURE__ */ r(
539
- ce,
543
+ le,
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: !!I || g,
548
+ onClick: N,
549
+ children: /* @__PURE__ */ r(De, {})
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: (b) => /* @__PURE__ */ y(v, { ...b.droppableProps, ref: b.innerRef, direction: "column", children: [
554
+ d.map((A, D) => /* @__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: `${A.value}-draggable`,
558
+ index: D,
559
+ isDragDisabled: g,
560
+ children: ({ draggableProps: B, dragHandleProps: fe, innerRef: Y }) => /* @__PURE__ */ r(
557
561
  v,
558
562
  {
559
- ...Me,
560
- ...Y,
561
- ref: St,
563
+ ...fe,
564
+ ...B,
565
+ ref: Y,
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__ */ y(Oe, { color: "gray", size: "2", children: [
572
+ /* @__PURE__ */ r("span", { children: A.label }),
569
573
  /* @__PURE__ */ r(
570
- ce,
574
+ le,
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: () => O(D),
583
+ children: /* @__PURE__ */ r(ft, {})
580
584
  }
581
585
  )
582
586
  ] })
583
587
  }
584
588
  )
585
589
  },
586
- _.value
590
+ A.value
587
591
  )),
588
- S.placeholder
592
+ b.placeholder
589
593
  ] }) })
590
594
  ] }) });
591
- }), te = class te extends R {
595
+ }), te = class te extends $ {
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(_i, { field: this, ...e });
601
611
  }
602
612
  serialize() {
603
613
  return { ...super._serialize(), minimum_length: this.minLength, maximum_length: this.maxLength };
@@ -621,12 +631,13 @@ const Fi = (o, i) => typeof o == "string" && o.length > 0 ? o : at(i), mt = (o,
621
631
  return new te(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(te, "fieldTypeName", "Multi-string"), m(te, "fieldTypeDescription", "Allows the user to provide multiple unique strings."), m(te, "Icon", Wt);
635
+ let Ce = te;
636
+ class Ct extends $ {
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,10 +663,13 @@ class gt extends R {
652
663
  ];
653
664
  }
654
665
  }
655
- const ie = class ie extends gt {
666
+ const ie = class ie 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
  }
@@ -665,35 +679,40 @@ const ie = class ie extends gt {
665
679
  return new ie(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(ie, "fieldTypeName", "Dropdown"), m(ie, "fieldTypeDescription", "Allows the user to select a single option from a list of options."), m(ie, "Icon", jt);
686
+ let Fe = ie;
687
+ const Mi = (s) => s ? Array.isArray(s) ? s : [s] : [], $i = S(function(i) {
688
+ const [{ inputId: e, labelId: t, severity: n, helpText: o, label: l, fieldProps: a, field: c }, u] = j(i), { onChange: d, onBlur: f } = a, h = C(() => Mi(a.value), [a.value]), p = E(
689
+ (g) => {
690
+ d(g), f(g);
677
691
  },
678
- [h, d, m, c]
692
+ [d, f]
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(W, { helpText: o, severity: n, children: /* @__PURE__ */ r(q, { severity: n, inputId: e, labelId: t, label: l, 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
- name: l.name,
700
+ name: a.name,
687
701
  placeholder: "Select one or more...",
688
702
  id: e,
689
703
  severity: n,
690
704
  ...u
691
705
  }
692
706
  ) }) });
693
- }), ne = class ne extends gt {
707
+ }), ne = class ne 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
  }
@@ -706,24 +725,24 @@ const Ei = z(function(i) {
706
725
  return new ne(i);
707
726
  }
708
727
  getInput(i) {
709
- return /* @__PURE__ */ r(Ei, { field: this, ...i });
728
+ return /* @__PURE__ */ r($i, { 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(ne, "fieldTypeName", "Multi-select"), m(ne, "fieldTypeDescription", "Allows the user to select a multiple options from a list of options."), m(ne, "Icon", Ut);
732
+ let Te = ne;
733
+ const Oi = S(function({ field: i, ...e }) {
734
+ const [{ value: t }] = He(i.options.clonedFieldIdentifier), n = C(() => {
735
+ const o = i.options.getFieldToClone(t);
736
+ return o ? ke(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 $ {
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,39 +753,39 @@ 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 Ri extends Se {
739
758
  constructor(i) {
740
- super(i, zi);
759
+ super(i, Oi);
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: [
752
- /* @__PURE__ */ b(v, { direction: "column", children: [
753
- /* @__PURE__ */ r(ze, { as: "h3", size: "3", children: n }),
754
- /* @__PURE__ */ r(k, { className: Ae.description, children: s })
762
+ const Ni = S(function(i) {
763
+ const { field: e, ...t } = i, { label: n, description: o, fields: l, condition: a } = e, { values: c, setFieldValue: u } = ue(), d = a != null && a.identifier ? ae(c, a.identifier) : void 0, f = C(() => St(a, d), [a, d]);
764
+ be(() => {
765
+ if (!f)
766
+ for (const p of l)
767
+ u(p.getId(), "").then();
768
+ }, [f, l, u]);
769
+ const h = zt(l, t);
770
+ return f ? n ? /* @__PURE__ */ r(ge, { children: /* @__PURE__ */ y(v, { direction: "column", gap: "3", children: [
771
+ /* @__PURE__ */ y(v, { direction: "column", children: [
772
+ /* @__PURE__ */ r(Le, { as: "h3", size: "3", children: n }),
773
+ /* @__PURE__ */ r(k, { className: Ve.description, children: o })
755
774
  ] }),
756
775
  h
757
776
  ] }) }) : h : null;
758
- }), re = class re extends ht {
777
+ }), re = class re extends wt {
759
778
  constructor(e) {
760
- const { label: t = null, fields: n, condition: s = null, conditional: a, ...l } = e;
761
- super({ ...l, type: "section" });
762
- p(this, "label");
763
- p(this, "fields");
764
- p(this, "condition");
765
- this.fields = n, this.condition = s, this.label = t, a === !1 && (this.condition = null);
779
+ const { label: t = null, fields: n, condition: o = null, conditional: l, ...a } = e;
780
+ super({ ...a, type: "section" });
781
+ m(this, "label");
782
+ m(this, "fields");
783
+ m(this, "condition");
784
+ this.fields = n, this.condition = o, this.label = t, l === !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",
@@ -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 Ri({
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,7 +848,7 @@ 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)) ?? [];
851
+ const t = ((n = e.fields) == null ? void 0 : n.map(Ft)) ?? [];
833
852
  return new re({ ...e, fields: t });
834
853
  }
835
854
  conditional() {
@@ -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(), l = n.getError(ae(e, o), e);
870
+ l && Xe(t, n.getId(), l);
852
871
  }
853
872
  return t;
854
873
  }
855
874
  getInput(e) {
856
- return /* @__PURE__ */ r(Pi, { field: this, ...e });
875
+ return /* @__PURE__ */ r(Ni, { field: this, ...e });
857
876
  }
858
877
  };
859
- p(re, "fieldTypeName", "Section"), p(re, "fieldTypeDescription", "Sections can be useful for grouping fields together. They can also be conditionally shown or hidden.");
878
+ m(re, "fieldTypeName", "Section"), m(re, "fieldTypeDescription", "Sections can be useful for grouping fields together. They can also be conditionally shown or hidden.");
860
879
  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,
880
+ const Bi = "_previewImage_1ig84_1", qi = {
881
+ previewImage: Bi
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
+ }, Wi = S(function(i) {
889
+ var P;
890
+ const [{ inputId: e, labelId: t, severity: n, helpText: o, label: l, fieldProps: a, field: c }, u] = j(i), { onChange: d } = a, f = de(n), h = fi(null), { value: p } = a, g = C(() => o || (c.maxFileSize ? `Maximum file size: ${Je(c.maxFileSize)}` : null), [c.maxFileSize, o]), x = E(() => {
891
+ var F;
892
+ (F = h.current) == null || F.click();
893
+ }, []), z = E(
894
+ (F) => {
895
+ const V = [...p];
896
+ V.splice(F, 1), d({ target: { files: V } });
897
+ },
898
+ [p, d]
899
+ ), I = p ? "Select new files" : "Select files", w = p ? "Select new file" : "Select a file", L = c.maxFiles > 1 ? I : w;
900
+ return /* @__PURE__ */ y(v, { direction: "column", gap: "2", children: [
901
+ /* @__PURE__ */ r(W, { helpText: g, severity: n, children: /* @__PURE__ */ y(q, { severity: n, inputId: e, labelId: t, label: l, children: [
902
+ /* @__PURE__ */ r(v, { direction: "row", gap: "2", children: /* @__PURE__ */ r(me, { width: "max-content", asChild: !0, children: /* @__PURE__ */ y(H, { ...u, onClick: x, children: [
903
+ /* @__PURE__ */ r(mt, {}),
904
+ " ",
905
+ L
906
+ ] }) }) }),
907
+ /* @__PURE__ */ r(
908
+ "input",
909
+ {
910
+ ...u,
911
+ type: "file",
912
+ ref: h,
913
+ id: e,
914
+ accept: (P = c.extensions) == null ? void 0 : P.join(","),
915
+ multiple: c.maxFiles > 1,
916
+ color: f,
917
+ style: { display: "none" },
918
+ ...a,
919
+ value: ""
920
+ }
921
+ )
922
+ ] }) }),
923
+ Array.isArray(p) && p.length > 0 && /* @__PURE__ */ r(v, { direction: "column", gap: "2", children: p.map((F, V) => /* @__PURE__ */ r(
924
+ ji,
925
+ {
926
+ field: c,
927
+ file: F,
928
+ onRemove: () => z(V),
929
+ disabled: u.disabled
930
+ },
931
+ V
932
+ )) })
933
+ ] });
934
+ }), ji = S(function({ file: i, field: e, onRemove: t, disabled: n }) {
935
+ const [o, l] = U(null), a = C(() => o && e.getError([o]), [e, o]), { url: c, name: u, size: d } = C(() => {
936
+ let f = null, h, p;
937
+ return o != null && o.type.startsWith("image/") && (f = URL.createObjectURL(o)), o ? (h = o.name, p = Je(o.size)) : (h = "Downloading...", p = "..."), { url: f, name: h, size: p };
938
+ }, [o]);
939
+ return be(() => {
940
+ i instanceof Promise ? i.then(l) : l(i);
941
+ }, [i]), /* @__PURE__ */ r(ge, { children: /* @__PURE__ */ y(v, { direction: { initial: "column", sm: "row" }, gap: "3", justify: "between", children: [
942
+ /* @__PURE__ */ y(v, { direction: "row", gap: "3", align: "center", grow: "1", shrink: "0", children: [
943
+ /* @__PURE__ */ r(
944
+ le,
945
+ {
946
+ severity: "info",
947
+ variant: "outline",
948
+ "aria-label": `Remove ${u}`,
949
+ disabled: n,
950
+ onClick: t,
951
+ children: /* @__PURE__ */ r(ft, {})
952
+ }
953
+ ),
954
+ /* @__PURE__ */ y(v, { direction: "column", gap: "1", children: [
955
+ /* @__PURE__ */ r(k, { children: u }),
956
+ /* @__PURE__ */ r(k, { size: "1", children: d }),
957
+ a && /* @__PURE__ */ r(k, { size: "1", severity: "danger", children: a })
958
+ ] })
959
+ ] }),
960
+ c && /* @__PURE__ */ r("img", { className: qi.previewImage, src: c, alt: u })
961
+ ] }) });
962
+ }), rt = 50 * 1024 * 1024, oe = class oe extends $ {
963
+ constructor(e) {
964
+ const { extensions: t, maximum_files: n, maximum_size: o, ...l } = e;
965
+ super({ ...l, 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 G({
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 G({
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((l) => l.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 oe(e);
1049
+ }
1050
+ getInput(e) {
1051
+ return /* @__PURE__ */ r(Wi, { field: this, ...e });
1052
+ }
1053
+ };
1054
+ m(oe, "fieldTypeName", "Upload"), m(oe, "fieldTypeDescription", "Allows a file to be uploaded."), m(oe, "Icon", mt);
1055
+ let qe = oe;
1056
+ const Ze = {
1057
+ date: Re,
1058
+ number: G,
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
+ }, ke = (s) => s.type === "section" ? K.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) => ke(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,235 +1095,246 @@ 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)
1103
+ for (const t of s.fields)
903
1104
  if (t instanceof K) {
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 $))
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
+ }, Hi = [null, void 0], et = (s, i) => s.reduce((e, t) => t instanceof K ? { ...e, ...et(t.fields, i) } : (Hi.includes(ae(e, t.getId())) && Xe(e, t.getId(), ""), e), i), Ui = () => {
919
1120
  throw new Error("onSubmit must be provided if form is not readonly.");
920
- }, Je = z(
921
- me((o, i) => {
1121
+ }, tt = S(
1122
+ ye((s, i) => {
922
1123
  const {
923
1124
  schema: e,
924
1125
  values: t = {},
925
- onSubmit: n = Di,
926
- submitText: s = "Submit",
927
- cancelText: a,
928
- onCancel: l,
1126
+ onSubmit: n = Ui,
1127
+ submitText: o = "Submit",
1128
+ cancelText: l,
1129
+ onCancel: a,
929
1130
  onDirty: c,
930
1131
  // if the title isn't provided, hide it by default
931
- hideTitle: f = !e.title,
932
- hideDescription: u,
933
- className: d
934
- } = o, { readonly: h } = e.meta, m = T(() => crypto.randomUUID(), []), g = je({
935
- initialValues: Xe(e.fields, t),
1132
+ hideTitle: u = !e.title,
1133
+ hideDescription: d,
1134
+ className: f
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: (L) => Et(e, L),
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: x } = g, z = C(
1143
+ () => typeof e.title == "string" ? /* @__PURE__ */ r(Le, { 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
+ ), I = C(
1146
+ () => typeof e.description == "string" ? /* @__PURE__ */ r(k, { className: Ve.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
+ x && c && c();
1151
+ }, [x, c]), /* @__PURE__ */ r(Ge, { value: g, children: /* @__PURE__ */ r(v, { ref: i, direction: "column", gap: "2", className: f, asChild: !0, children: /* @__PURE__ */ y("form", { id: p, onSubmit: g.handleSubmit, children: [
1152
+ !u && /* @__PURE__ */ r(ge, { children: /* @__PURE__ */ y(v, { direction: "column", gap: "1", children: [
1153
+ z,
1154
+ !d && I
954
1155
  ] }) }),
955
- x,
956
- !h && /* @__PURE__ */ b(v, { justify: "end", gap: "2", children: [
957
- a && /* @__PURE__ */ r(G, { type: "button", variant: "soft", onClick: l, children: a }),
958
- /* @__PURE__ */ r(G, { type: "submit", disabled: !g.isValid, children: s })
1156
+ w,
1157
+ !h && /* @__PURE__ */ y(v, { justify: "end", gap: "2", children: [
1158
+ l && /* @__PURE__ */ r(H, { type: "button", variant: "soft", onClick: a, children: l }),
1159
+ /* @__PURE__ */ r(H, { 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
+ ), Sn = S(
1164
+ ye((s, i) => {
1165
+ const { submission: e, showFormDescription: t = !1, showFormTitle: n = !0 } = s, o = M(pt(e.form_revision)), { sdk: l } = 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 a = C(() => Tt(o, { readonly: !0 }), [o]), c = C(() => {
1171
+ const u = pi(e.offline_id)(l.store.getState()) ?? [], d = {};
1172
+ for (const f of u) {
1173
+ const h = l.files.fetchFileFromUrl(f.file, f.file_sha1, f.file_name).then((g) => {
1174
+ if (!g.success)
1175
+ throw new Error(`Failed to download attachment ${f.file_name}.`);
1176
+ return g.body;
1177
+ }), p = d[f.field_identifier];
1178
+ p ? p.push(h) : d[f.field_identifier] = [h];
1179
+ }
1180
+ return { ...e.values, ...d };
1181
+ }, [l.files, l.store, e.offline_id, e.values]);
970
1182
  return /* @__PURE__ */ r(
971
- Je,
1183
+ tt,
972
1184
  {
973
1185
  ref: i,
974
1186
  schema: a,
975
- values: e.values,
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
+ ), Gi = "_favoriteIcon_1bixi_1", Ki = "_regularIcon_1bixi_9", ot = {
1194
+ favoriteIcon: Gi,
1195
+ regularIcon: Ki
1196
+ }, Me = "organization:", $e = "user:", zn = S(
1197
+ ye((s, i) => {
1198
+ const { maxResults: e = 20, ...t } = s, [n, o] = U(""), [l, a] = U(""), { sdk: c } = gt(), u = C(() => {
1199
+ const w = { maxResults: e, searchTerm: n };
1200
+ return l && (l.startsWith(Me) ? w.owner_organization = parseInt(l.slice(Me.length)) : l.startsWith($e) && (w.owner_user = parseInt(l.slice($e.length)))), w;
1201
+ }, [n, e, l]), d = M(gi(u)) ?? [], f = M(bi), h = E(
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(), L = {};
1208
+ for (const P of Object.values(f)) {
1209
+ const F = bt(P.owner_organization || -1)(w);
1210
+ F && (L[`${Me}${F.id}`] = F.name);
1211
+ const V = Qe(P.owner_user || -1)(w);
1212
+ V && (L[`${$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`;
1006
- return /* @__PURE__ */ b(v, { ref: i, direction: "column", gap: "2", children: [
1007
- /* @__PURE__ */ b(v, { gap: "2", grow: "1", children: [
1008
- /* @__PURE__ */ r(ge, { grow: "1", asChild: !0, children: /* @__PURE__ */ r(oe.Root, { size: "3", children: /* @__PURE__ */ r(oe.Input, { placeholder: "Filter", value: n, onChange: g }) }) }),
1214
+ return Object.entries(L).map(([P, F]) => ({ itemContent: F, value: P }));
1215
+ }, [f, c.store]), g = E((w) => {
1216
+ o(w.currentTarget.value);
1217
+ }, []), z = (M(yi) || 0) - d.length, I = d.length == e && z > 0 ? `Only the first ${e} results are shown (${z} hidden)` : z > 0 && `${z} hidden forms`;
1218
+ return /* @__PURE__ */ y(v, { ref: i, direction: "column", gap: "2", children: [
1219
+ /* @__PURE__ */ y(v, { gap: "2", grow: "1", children: [
1220
+ /* @__PURE__ */ r(me, { grow: "1", asChild: !0, children: /* @__PURE__ */ r(se.Root, { size: "3", children: /* @__PURE__ */ r(se.Input, { placeholder: "Filter", value: n, onChange: g }) }) }),
1009
1221
  /* @__PURE__ */ r(
1010
- st,
1222
+ ut,
1011
1223
  {
1012
- items: m,
1013
- value: a,
1014
- onValueChange: l,
1224
+ items: p,
1225
+ value: l,
1226
+ onValueChange: a,
1015
1227
  placeholder: "Owner",
1016
1228
  size: "large"
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(Pe.Root, { children: d.map((w) => /* @__PURE__ */ r(
1233
+ Yi,
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(k, { size: "2", severity: "info", children: I }) })
1030
1242
  ] });
1031
1243
  })
1032
- ), Oi = (o) => {
1244
+ ), Yi = (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 = M(bt(i.owner_organization || -1))) == null ? void 0 : h.name, l = M(Qe(i.owner_user || -1)), a = M(yt).id, c = !!l && l.id === a, u = o ?? (c ? "You" : l == null ? void 0 : l.username) ?? "Unknown", d = E(
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: [
1040
- /* @__PURE__ */ b(v, { grow: "1", align: "center", gap: "2", children: [
1251
+ ), f = /* @__PURE__ */ r(Pe.Item, { onClick: () => e(i), asChild: !0, children: /* @__PURE__ */ y(v, { justify: "between", gap: "2", py: "2", px: "3", ...Gt, children: [
1252
+ /* @__PURE__ */ y(v, { grow: "1", align: "center", gap: "2", children: [
1041
1253
  /* @__PURE__ */ r(
1042
- ce,
1254
+ le,
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
1264
  /* @__PURE__ */ r(k, { noWrap: !0, children: i.latestRevision.title }),
1053
- i.latestRevision.description && /* @__PURE__ */ r(jt, {})
1265
+ i.latestRevision.description && /* @__PURE__ */ r(Qt, {})
1054
1266
  ] }),
1055
- f && /* @__PURE__ */ b(v, { align: "center", gap: "2", children: [
1056
- /* @__PURE__ */ r(Ht, {}),
1267
+ u && /* @__PURE__ */ y(v, { align: "center", gap: "2", children: [
1268
+ /* @__PURE__ */ r(Xt, {}),
1057
1269
  " ",
1058
- f
1270
+ u
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: f }, i.offline_id) : f;
1274
+ }, Qi = "_submissionsContainer_9iirt_1", Xi = "_stopHorizontalOverflow_9iirt_6", At = {
1275
+ submissionsContainer: Qi,
1276
+ stopHorizontalOverflow: Xi
1277
+ }, Ji = S(function(i) {
1278
+ var w;
1279
+ const { submission: e, onSubmissionClick: t, compact: n, labelType: o, rowDecorator: l } = i, a = M(yt), c = M(Qe("created_by" in e ? e.created_by : a.id)), u = je(e), d = vi(u) ? u.toLocaleTimeString([], {
1068
1280
  hour: "2-digit",
1069
1281
  minute: "2-digit"
1070
- }) : ui(f), d = $(ct(e.form_revision));
1071
- if (!d)
1282
+ }) : wi(u), f = M(pt(e.form_revision));
1283
+ if (!f)
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 = M(xi(f.form))) == null ? void 0 : w.revision, p = Ii({
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()) ?? "?", x = f.revision === h, z = ui.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]), I = /* @__PURE__ */ r(Pe.Item, { onClick: z, asChild: !0, children: /* @__PURE__ */ y(v, { grow: "1", width: "100%", p: "2", gap: "2", justify: "between", children: [
1291
+ /* @__PURE__ */ y(v, { gap: "2", align: "center", className: At.stopHorizontalOverflow, children: [
1292
+ /* @__PURE__ */ r(Zt, { src: p, size: "1", fallback: g }),
1293
+ /* @__PURE__ */ r(k, { size: "2", noWrap: !0, children: o === "creator" ? (c || a).username : f.title })
1082
1294
  ] }),
1083
- /* @__PURE__ */ b(v, { gap: "2", align: "center", children: [
1084
- !n && (d.revision ? /* @__PURE__ */ r(_e, { variant: "soft", severity: y ? "primary" : "info", children: n ? d.revision.toString() : `Revision #${d.revision}` }) : !!h && /* @__PURE__ */ r(_e, { children: "Original" })),
1085
- /* @__PURE__ */ r(k, { size: "2", noWrap: !0, children: u })
1295
+ /* @__PURE__ */ y(v, { gap: "2", align: "center", children: [
1296
+ !n && (f.revision ? /* @__PURE__ */ r(Oe, { variant: "soft", severity: x ? "primary" : "info", children: n ? f.revision.toString() : `Revision #${f.revision}` }) : !!h && /* @__PURE__ */ r(Oe, { children: "Original" })),
1297
+ /* @__PURE__ */ r(k, { 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 l ? l(e, I) : I;
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
+ }, En = S(function(i) {
1093
1305
  const {
1094
1306
  formId: e,
1095
1307
  submissions: t,
1096
1308
  compact: n = !1,
1097
- className: s,
1098
- after: a,
1099
- variant: l = "outline",
1309
+ className: o,
1310
+ after: l,
1311
+ variant: a = "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()),
1108
- [f]
1316
+ const u = M(
1317
+ t ? () => t : Ci(e)
1318
+ ), d = C(
1319
+ () => u == null ? void 0 : u.sort((f, h) => je(h).getTime() - je(f).getTime()),
1320
+ [u]
1109
1321
  );
1110
1322
  return /* @__PURE__ */ r(
1111
- Le.Root,
1323
+ Pe.Root,
1112
1324
  {
1113
- className: ft(xt.submissionsContainer, s),
1325
+ className: vt(At.submissionsContainer, o),
1114
1326
  size: "small",
1115
- variant: l,
1116
- before: !n && /* @__PURE__ */ b(k, { severity: "info", children: [
1327
+ variant: a,
1328
+ before: !n && /* @__PURE__ */ y(k, { severity: "info", children: [
1117
1329
  "There are ",
1118
- ((f == null ? void 0 : f.length) || 0).toString(),
1330
+ ((u == null ? void 0 : u.length) || 0).toString(),
1119
1331
  " submissions of this form."
1120
1332
  ] }),
1121
- after: a,
1122
- children: u == null ? void 0 : u.map((d, h) => /* @__PURE__ */ r(
1123
- $i,
1333
+ after: l,
1334
+ children: d == null ? void 0 : d.map((f, h) => /* @__PURE__ */ r(
1335
+ Ji,
1124
1336
  {
1125
- submission: d,
1337
+ submission: f,
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(() => {
1136
- const c = (f) => l.setValue(f, !1);
1345
+ }), An = S(function(i) {
1346
+ const { name: e, render: t } = i, { submitForm: n } = ue(), [o, l, a] = He(e);
1347
+ return C(() => {
1348
+ const c = (u) => a.setValue(u, !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, a, o.value, t]);
1355
+ }), Dn = S(
1356
+ ye((s, i) => {
1357
+ const { children: e, schema: t, values: n, onPatch: o, onError: l, ...a } = s, c = C(() => et(t.fields, n), [t.fields, n]), u = E(
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 x = {};
1360
+ for (const z in g) {
1361
+ const I = g[z];
1362
+ I !== c[z] && I !== void 0 && (x[z] = I);
1151
1363
  }
1152
- Te(y) && s(y);
1364
+ Ee(x) && o(x);
1153
1365
  },
1154
- [c, s]
1155
- ), u = E(
1366
+ [c, o]
1367
+ ), d = E(
1156
1368
  async (g) => {
1157
- const y = await It(t, g);
1158
- return y && a(y), y;
1369
+ const x = await Et(t, g);
1370
+ return x && l(x), x;
1159
1371
  },
1160
- [t, a]
1161
- ), d = je({
1372
+ [t, l]
1373
+ ), f = Ue({
1162
1374
  initialValues: c,
1163
- onSubmit: f,
1164
- validate: u,
1375
+ onSubmit: 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 } = f;
1381
+ return be(() => {
1382
+ Ee(h) && p({ values: c, errors: {} });
1383
+ }, [h, c, p]), /* @__PURE__ */ r(Ge, { value: f, children: /* @__PURE__ */ r("form", { ...a, ref: i, onSubmit: f.handleSubmit, children: e }) });
1172
1384
  })
1173
- ), Ct = {
1174
- ...Qe,
1385
+ ), Dt = {
1386
+ ...Ze,
1175
1387
  section: K
1176
- }, Ri = z(function(i) {
1177
- const { field: e, setFieldType: t } = i, n = e.fieldTypeName, s = e.fieldTypeDescription, a = e.Icon;
1178
- return /* @__PURE__ */ b(v, { gap: "4", align: "center", children: [
1179
- /* @__PURE__ */ r(G, { type: "button", variant: "surface", onClick: t, style: { width: "135px" }, children: /* @__PURE__ */ b(v, { gap: "3", align: "center", grow: "1", children: [
1180
- /* @__PURE__ */ r(a, {}),
1388
+ }, Zi = S(function(i) {
1389
+ const { field: e, setFieldType: t } = i, n = e.fieldTypeName, o = e.fieldTypeDescription, l = e.Icon;
1390
+ return /* @__PURE__ */ y(v, { gap: "4", align: "center", children: [
1391
+ /* @__PURE__ */ r(H, { type: "button", variant: "surface", onClick: t, style: { width: "135px" }, children: /* @__PURE__ */ y(v, { gap: "3", align: "center", grow: "1", children: [
1392
+ /* @__PURE__ */ r(l, {}),
1181
1393
  n
1182
1394
  ] }) }),
1183
- /* @__PURE__ */ r(k, { children: s })
1395
+ /* @__PURE__ */ r(k, { children: o })
1184
1396
  ] });
1185
- }), Tt = [
1397
+ }), Lt = [
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
+ ], en = Lt.length - 1, tn = S(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: Lt.map((t, n) => /* @__PURE__ */ y(v, { direction: "column", gap: "3", children: [
1404
+ /* @__PURE__ */ r(v, { direction: "column", gap: "2", children: t.map((o) => /* @__PURE__ */ r(
1405
+ Zi,
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 < en && /* @__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
+ }), nn = (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
+ }, rn = (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: [nn(s)]
1216
1425
  }),
1217
- new he({
1426
+ new pe({
1218
1427
  label: "Description",
1219
1428
  required: !1,
1220
1429
  maxLength: 1e3,
@@ -1223,146 +1432,166 @@ 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
+ }, on = S(function(i) {
1438
+ const { fieldType: e, handleCancel: t, handleCreateField: n, handleDirty: o, defaultField: l, conditionalSourceFields: a } = i, c = Dt[e], u = ue(), d = C(() => {
1439
+ const f = u.values.fields.flatMap(
1440
+ (p) => p.type === "section" ? [...p.fields.map((g) => g.label), p.label] : p.label
1441
+ ).filter((p) => p !== (l == null ? void 0 : l.label) && p !== null);
1442
+ let h = rn(f, e);
1443
+ if (c === K) {
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
+ h = h.concat(c.getFieldCreationSchema(a));
1238
1447
  } else {
1239
- if (!(l.prototype instanceof R))
1240
- throw new Error(`Field must be an instance of BaseField. Got ${l}.`);
1241
- d = [...d, ...l.getFieldCreationSchema()];
1448
+ if (!(c.prototype instanceof $))
1449
+ throw new Error(`Field must be an instance of BaseField. Got ${c}.`);
1450
+ h = [...h, ...c.getFieldCreationSchema()];
1242
1451
  }
1243
1452
  return {
1244
- fields: d,
1453
+ fields: h,
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
+ }, [u.values.fields, e, c, l == null ? void 0 : l.label, a]);
1250
1459
  return /* @__PURE__ */ r(
1251
- Je,
1460
+ tt,
1252
1461
  {
1253
- schema: f,
1254
- values: s,
1462
+ schema: d,
1463
+ values: l,
1255
1464
  onSubmit: n,
1256
- cancelText: s ? void 0 : "Back",
1257
- onCancel: t
1465
+ cancelText: l ? void 0 : "Back",
1466
+ onCancel: t,
1467
+ onDirty: o
1258
1468
  }
1259
1469
  );
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)
1470
+ }), Ae = S(function(i) {
1471
+ const { parentPath: e, index: t, children: n, initial: o, editing: l, conditionalSourceFields: a } = i, [c, u] = U(), [d, f] = U(!1), h = (o == null ? void 0 : o.type) ?? c, p = h ? Dt[h].fieldTypeName : void 0, { setFieldValue: g, values: x } = ue();
1472
+ if (l && !o)
1263
1473
  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)
1474
+ const z = ti(), I = !h && !l && !o, w = I ? "Choose a field type" : `${p} settings`, L = I ? "Select a field type to add to this section." : (p == null ? void 0 : p.toLowerCase()) === "section" ? "Customize your section" : `Customize your ${p == null ? void 0 : p.toLowerCase()} field.`, P = E(() => {
1475
+ console.log("handlecancel ran", d), u(void 0), f(!1);
1476
+ }, []), F = E(
1477
+ (_, O) => (T) => {
1478
+ console.log("closeinterrupt ran", _), _ ? z({
1479
+ onDiscard: () => {
1480
+ O(!1), u(void 0), T();
1481
+ }
1482
+ }) : (u(void 0), T());
1483
+ },
1484
+ [z]
1485
+ ), V = E(
1486
+ (_, O) => {
1487
+ const { label: T } = _;
1488
+ if (!h)
1270
1489
  throw new Error("Field type must be selected before creating a field.");
1271
- if (!B || typeof B != "string")
1490
+ if (!T || typeof T != "string")
1272
1491
  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)
1492
+ const b = ke({
1493
+ type: h,
1494
+ ..._,
1495
+ identifier: ki(_.identifier, T)
1496
+ }).serialize(), A = ae(x, e);
1497
+ if (A === void 0)
1279
1498
  throw new Error("Parent path must point to an existing field.");
1280
- let C;
1281
- if (!Array.isArray(F))
1499
+ let D;
1500
+ if (!Array.isArray(A))
1282
1501
  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();
1502
+ l ? D = Vi(A, t, b) : D = xt(A, t, b), g(e, D).then(), f(!1), O();
1284
1503
  },
1285
- [a, u, m, e, h, t]
1286
- ), A = E(
1287
- (L) => g ? /* @__PURE__ */ r(Ni, { setFieldType: f }) : /* @__PURE__ */ r(
1288
- ji,
1504
+ [l, h, x, e, g, t]
1505
+ ), N = E(
1506
+ (_) => I ? /* @__PURE__ */ r(tn, { setFieldType: u }) : /* @__PURE__ */ r(
1507
+ on,
1289
1508
  {
1290
- conditionalSourceFields: l,
1291
- handleCancel: w,
1292
- handleCreateField: (O) => P(O, L),
1293
- fieldType: u,
1294
- defaultField: s
1509
+ conditionalSourceFields: a,
1510
+ handleCancel: P,
1511
+ handleCreateField: (O) => V(O, _),
1512
+ fieldType: h,
1513
+ defaultField: o,
1514
+ handleDirty: () => f(!0)
1295
1515
  }
1296
1516
  ),
1297
- [l, w, P, s, g, u]
1517
+ [a, P, V, o, I, h]
1518
+ );
1519
+ return /* @__PURE__ */ r(
1520
+ ii,
1521
+ {
1522
+ onCloseInterrupt: F(d, f),
1523
+ title: w,
1524
+ description: L,
1525
+ content: N,
1526
+ children: n
1527
+ }
1298
1528
  );
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(
1529
+ }), st = ({ children: s }) => /* @__PURE__ */ r(dt, { children: s }), lt = (s, i) => ({
1530
+ initial: s ? i : "none",
1531
+ sm: s ? "none" : i
1532
+ }), Pt = S(function(i) {
1533
+ const { remove: e, dragHandleProps: t, editProps: n, insertAfterProps: o } = i, l = C(
1305
1534
  () => [
1306
1535
  {
1307
- Wrapper: Fe,
1536
+ Wrapper: Ae,
1308
1537
  wrapperProps: n,
1309
- Icon: Qt,
1538
+ Icon: ni,
1310
1539
  text: "Edit"
1311
1540
  },
1312
1541
  {
1313
- Icon: Xt,
1542
+ Icon: ri,
1314
1543
  buttonProps: {
1315
1544
  onClick: e
1316
1545
  },
1317
1546
  text: "Delete"
1318
1547
  },
1319
1548
  {
1320
- Wrapper: Fe,
1321
- wrapperProps: s,
1322
- Icon: Se,
1549
+ Wrapper: Ae,
1550
+ wrapperProps: o,
1551
+ Icon: De,
1323
1552
  text: "Add after"
1324
1553
  },
1325
1554
  {
1326
1555
  // Wrapping icon in a div so that the asChild turns the button into a div
1327
1556
  // so that the drag handle props are not applied to the icon
1328
1557
  // Note: b/c the <button> does not handle the space-press event correctly
1329
- Icon: (l) => /* @__PURE__ */ r("div", { ...l, children: /* @__PURE__ */ r(Jt, {}) }),
1558
+ Icon: (a) => /* @__PURE__ */ r("div", { ...a, children: /* @__PURE__ */ r(oi, {}) }),
1330
1559
  text: "Reorder",
1331
1560
  disableOnMobile: !0,
1332
1561
  buttonProps: { ...t, asChild: !0 }
1333
1562
  }
1334
1563
  ],
1335
- [t, n, s, e]
1564
+ [t, n, o, e]
1336
1565
  );
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);
1566
+ return /* @__PURE__ */ y(dt, { children: [
1567
+ /* @__PURE__ */ r(v, { gap: "4", display: lt(!1, "flex"), children: l.map((a) => {
1568
+ const c = a.Wrapper ?? st;
1569
+ return /* @__PURE__ */ r(c, { ...a.wrapperProps, children: /* @__PURE__ */ r(le, { type: "button", variant: "ghost", "aria-label": a.text, ...a.buttonProps, children: /* @__PURE__ */ r(a.Icon, {}) }) }, a.text);
1341
1570
  }) }),
1342
- /* @__PURE__ */ r(ge, { display: it(!0, "block"), children: /* @__PURE__ */ r(
1343
- Zt,
1571
+ /* @__PURE__ */ r(me, { display: lt(!0, "block"), children: /* @__PURE__ */ r(
1572
+ si,
1344
1573
  {
1345
- trigger: /* @__PURE__ */ r(ce, { variant: "ghost", "aria-label": "Actions menu", children: /* @__PURE__ */ r(ei, {}) }),
1574
+ trigger: /* @__PURE__ */ r(le, { variant: "ghost", "aria-label": "Actions menu", children: /* @__PURE__ */ r(li, {}) }),
1346
1575
  closeOnSelect: !1,
1347
- items: a.map((l) => {
1348
- var f;
1349
- if (l.disableOnMobile)
1576
+ items: l.map((a) => {
1577
+ var u;
1578
+ if (a.disableOnMobile)
1350
1579
  return null;
1351
- const c = l.Wrapper ?? tt;
1580
+ const c = a.Wrapper ?? st;
1352
1581
  return {
1353
- ...l.buttonProps,
1354
- onSelect: (f = l.buttonProps) == null ? void 0 : f.onClick,
1355
- content: /* @__PURE__ */ r(c, { ...l.wrapperProps, children: /* @__PURE__ */ b(v, { gap: "2", align: "center", children: [
1356
- /* @__PURE__ */ r(l.Icon, {}),
1357
- l.text
1582
+ ...a.buttonProps,
1583
+ onSelect: (u = a.buttonProps) == null ? void 0 : u.onClick,
1584
+ content: /* @__PURE__ */ r(c, { ...a.wrapperProps, children: /* @__PURE__ */ y(v, { gap: "2", align: "center", children: [
1585
+ /* @__PURE__ */ r(a.Icon, {}),
1586
+ a.text
1358
1587
  ] }) })
1359
1588
  };
1360
- }).filter((l) => l !== null)
1589
+ }).filter((a) => a !== null)
1361
1590
  }
1362
1591
  ) })
1363
1592
  ] });
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(
1593
+ }), _e = "form-builder", sn = S(function(i) {
1594
+ const { field: e, index: t, sectionIndex: n, remove: o } = i, l = C(() => ke(e), [e]), a = ze(l, { formId: _e, disabled: !0 }), c = C(
1366
1595
  () => ({
1367
1596
  index: t,
1368
1597
  parentPath: `fields.${n}.fields`,
@@ -1370,7 +1599,7 @@ const Ce = (o, i) => T(() => !i || !o ? null : o.getInput(i), [o, i]), wt = (o,
1370
1599
  editing: !0
1371
1600
  }),
1372
1601
  [e, t, n]
1373
- ), f = T(
1602
+ ), u = C(
1374
1603
  () => ({
1375
1604
  parentPath: `fields.${n}.fields`,
1376
1605
  index: t + 1,
@@ -1378,167 +1607,170 @@ const Ce = (o, i) => T(() => !i || !o ? null : o.getInput(i), [o, i]), wt = (o,
1378
1607
  }),
1379
1608
  [t, n]
1380
1609
  );
1381
- return /* @__PURE__ */ r(Ge, { draggableId: e.identifier, index: t, children: (u) => /* @__PURE__ */ r(
1382
- Ee,
1610
+ return /* @__PURE__ */ r(Ye, { draggableId: e.identifier, index: t, children: (d) => /* @__PURE__ */ r(
1611
+ ge,
1383
1612
  {
1384
- ref: u.innerRef,
1385
- ...u.draggableProps,
1386
- ...u.dragHandleProps,
1613
+ ref: d.innerRef,
1614
+ ...d.draggableProps,
1615
+ ...d.dragHandleProps,
1387
1616
  mb: "4",
1388
- children: /* @__PURE__ */ b(v, { gap: "4", justify: "between", align: "center", children: [
1389
- l,
1617
+ children: /* @__PURE__ */ y(v, { gap: "4", justify: "between", align: "center", children: [
1618
+ a,
1390
1619
  /* @__PURE__ */ r(
1391
- Ft,
1620
+ Pt,
1392
1621
  {
1393
- remove: s,
1622
+ remove: o,
1394
1623
  editProps: c,
1395
- insertAfterProps: f,
1396
- dragHandleProps: u.dragHandleProps
1624
+ insertAfterProps: u,
1625
+ dragHandleProps: d.dragHandleProps
1397
1626
  }
1398
1627
  )
1399
1628
  ] })
1400
1629
  }
1401
1630
  ) });
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();
1631
+ }), ln = S(function(i) {
1632
+ var L, P, F, V, N, _, O;
1633
+ const { field: e, index: t, dropState: n } = i, o = (L = n[e.identifier]) == null ? void 0 : L.disabled, { setFieldValue: l, values: a } = ue(), c = ai(), u = E(
1634
+ (T, b) => {
1635
+ for (const A of T) {
1636
+ const D = b.indexOf(A);
1637
+ l(`fields.${D}.condition`, null).then(), l(`fields.${D}.conditional`, !1).then();
1409
1638
  }
1410
1639
  },
1411
- [a]
1412
- ), u = E(
1413
- (F) => {
1640
+ [l]
1641
+ ), d = E(
1642
+ (T) => {
1414
1643
  var D;
1415
- const C = e.fields[F];
1416
- if (!C)
1644
+ const b = e.fields[T];
1645
+ if (!b)
1417
1646
  throw new Error("Could not find field to remove.");
1418
- const M = [];
1419
- for (const N of l.fields)
1420
- ((D = N.condition) == null ? void 0 : D.identifier) === C.identifier && M.push(N);
1647
+ const A = [];
1648
+ for (const B of a.fields)
1649
+ ((D = B.condition) == null ? void 0 : D.identifier) === b.identifier && A.push(B);
1421
1650
  return {
1422
- removing: C,
1423
- affectedSections: M,
1424
- action: () => a(`fields.${t}.fields`, ve(e.fields, F))
1651
+ removing: b,
1652
+ affectedSections: A,
1653
+ action: () => l(`fields.${t}.fields`, Ie(e.fields, T))
1425
1654
  };
1426
1655
  },
1427
- [e.fields, l.fields, a, t]
1428
- ), d = E(
1429
- (F) => {
1430
- const { affectedSections: C, action: M, removing: D } = u(F), N = () => {
1431
- M().then(), f(C, l.fields);
1656
+ [e.fields, a.fields, l, t]
1657
+ ), f = E(
1658
+ (T) => {
1659
+ const { affectedSections: b, action: A, removing: D } = d(T), B = () => {
1660
+ A().then(), u(b, a.fields);
1432
1661
  };
1433
- if (C.length > 0) {
1434
- const S = C.map((_) => _.label).join(", ");
1662
+ if (b.length > 0) {
1663
+ const fe = b.map((Y) => Y.label).join(", ");
1435
1664
  return c({
1436
1665
  title: "Remove condition?",
1437
- description: `${D.label} is being used as a condition, deleting it will remove the condition from the ${S} section(s).`,
1666
+ description: `${D.label} is being used as a condition, deleting it will remove the condition from the ${fe} section(s).`,
1438
1667
  severity: "danger",
1439
1668
  actionText: "Remove",
1440
- onAction: N
1669
+ onAction: B
1441
1670
  });
1442
1671
  }
1443
- N();
1672
+ B();
1444
1673
  },
1445
- [u, f, l.fields, c]
1674
+ [d, u, a.fields, c]
1446
1675
  ), 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)
1676
+ const b = e.fields.map((ve, Vt) => d(Vt)).flatMap((ve) => ve.affectedSections), A = b.length ? "Remove fields and conditions?" : "Remove fields?", D = e.fields.length, B = b.map((ve) => ve.label).join(", "), fe = b.length ? `Deleting this section will remove the ${D} field(s) it contains and will remove the conditions from following sections: ${B}` : `Deleting this section will remove the ${D} field(s) it contains.`, Y = Ie(a.fields, t), it = () => l("fields", Y);
1677
+ if (b.length > 0)
1449
1678
  return c({
1450
- title: M,
1451
- description: S,
1679
+ title: A,
1680
+ description: fe,
1452
1681
  severity: "danger",
1453
1682
  actionText: "Remove",
1454
1683
  onAction: () => {
1455
- U().then(() => {
1456
- f(C, _);
1684
+ it().then(() => {
1685
+ u(b, Y);
1457
1686
  });
1458
1687
  }
1459
1688
  });
1460
- U().then();
1689
+ it().then();
1461
1690
  }, [
1462
1691
  e.fields,
1463
- l.fields,
1692
+ a.fields,
1464
1693
  t,
1465
- u,
1466
- a,
1694
+ d,
1695
+ l,
1467
1696
  c,
1468
- f
1469
- ]), m = T(
1697
+ u
1698
+ ]), p = C(
1470
1699
  () => ({
1471
1700
  index: t,
1472
1701
  parentPath: "fields",
1473
1702
  initial: e,
1474
1703
  editing: !0,
1475
- conditionalSourceFields: qe(l.fields, t)
1704
+ conditionalSourceFields: Be(a.fields, t)
1476
1705
  }),
1477
- [e, t, l.fields]
1478
- ), g = T(
1706
+ [e, t, a.fields]
1707
+ ), g = C(
1479
1708
  () => ({
1480
1709
  index: t + 1,
1481
1710
  parentPath: "fields",
1482
- initial: ye(),
1483
- conditionalSourceFields: qe(l.fields, t + 1)
1711
+ initial: xe(),
1712
+ conditionalSourceFields: Be(a.fields, t + 1)
1484
1713
  }),
1485
- [t, l.fields]
1486
- ), y = T(
1714
+ [t, a.fields]
1715
+ ), x = C(
1487
1716
  () => ({
1488
1717
  parentPath: `fields.${t}.fields`,
1489
1718
  index: e.fields.length,
1490
1719
  initial: void 0
1491
1720
  }),
1492
1721
  [e.fields.length, t]
1493
- ), I = T(
1722
+ ), z = C(
1494
1723
  () => {
1495
- var F, C;
1496
- return (C = mt(l.fields, (F = e.condition) == null ? void 0 : F.identifier)) == null ? void 0 : C.label;
1724
+ var T, b;
1725
+ return (b = It(a.fields, (T = e.condition) == null ? void 0 : T.identifier)) == null ? void 0 : b.label;
1497
1726
  },
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,
1727
+ [(P = e.condition) == null ? void 0 : P.identifier, a.fields]
1728
+ ), I = Array.isArray((F = e.condition) == null ? void 0 : F.value) ? "contains all of" : "equals";
1729
+ if (We((V = e.condition) == null ? void 0 : V.value))
1730
+ throw new Error("File values are not supported for conditions.");
1731
+ const w = Array.isArray((N = e.condition) == null ? void 0 : N.value) ? (_ = e.condition) == null ? void 0 : _.value.map((T) => typeof T == "string" ? T : T.label).join(", ") : (O = e.condition) == null ? void 0 : O.value.toString();
1732
+ return /* @__PURE__ */ r(Ye, { draggableId: e.identifier, index: t, children: (T) => /* @__PURE__ */ r(
1733
+ ge,
1502
1734
  {
1503
- ref: F.innerRef,
1504
- ...F.draggableProps,
1505
- ...F.dragHandleProps,
1735
+ ref: T.innerRef,
1736
+ ...T.draggableProps,
1737
+ ...T.dragHandleProps,
1506
1738
  mb: "4",
1507
- children: /* @__PURE__ */ b(v, { gap: "3", justify: "between", align: "center", children: [
1508
- /* @__PURE__ */ b(v, { direction: "column", gap: "2", grow: "1", children: [
1509
- /* @__PURE__ */ b(v, { direction: "column", children: [
1510
- /* @__PURE__ */ r(ze, { as: "h3", size: "3", children: e.label }),
1511
- /* @__PURE__ */ r(k, { className: Ae.description, children: e.description })
1739
+ children: /* @__PURE__ */ y(v, { gap: "3", justify: "between", align: "center", children: [
1740
+ /* @__PURE__ */ y(v, { direction: "column", gap: "2", grow: "1", children: [
1741
+ /* @__PURE__ */ y(v, { direction: "column", children: [
1742
+ /* @__PURE__ */ r(Le, { as: "h3", size: "3", children: e.label }),
1743
+ /* @__PURE__ */ r(k, { className: Ve.description, children: e.description })
1512
1744
  ] }),
1513
- e.condition && /* @__PURE__ */ r(k, { size: "1", children: /* @__PURE__ */ b(ii, { children: [
1745
+ e.condition && /* @__PURE__ */ r(k, { size: "1", children: /* @__PURE__ */ y(ci, { children: [
1514
1746
  "Display only if ",
1515
- /* @__PURE__ */ r(Ze, { children: I }),
1747
+ /* @__PURE__ */ r(nt, { children: z }),
1516
1748
  " ",
1517
- w,
1749
+ I,
1518
1750
  " ",
1519
- /* @__PURE__ */ r(Ze, { children: x })
1751
+ /* @__PURE__ */ r(nt, { children: w })
1520
1752
  ] }) }),
1521
- /* @__PURE__ */ r(Ue, { droppableId: e.identifier, type: "SECTION", isDropDisabled: s, children: (C) => /* @__PURE__ */ b(
1753
+ /* @__PURE__ */ r(Ke, { droppableId: e.identifier, type: "SECTION", isDropDisabled: o, children: (b) => /* @__PURE__ */ y(
1522
1754
  v,
1523
1755
  {
1524
- ref: C.innerRef,
1525
- ...C.droppableProps,
1756
+ ref: b.innerRef,
1757
+ ...b.droppableProps,
1526
1758
  direction: "column",
1527
1759
  gap: "0",
1528
1760
  children: [
1529
- e.fields.map((M, D) => /* @__PURE__ */ r(
1530
- Hi,
1761
+ e.fields.map((A, D) => /* @__PURE__ */ r(
1762
+ sn,
1531
1763
  {
1532
- field: M,
1764
+ field: A,
1533
1765
  index: D,
1534
1766
  sectionIndex: t,
1535
- remove: () => d(D)
1767
+ remove: () => f(D)
1536
1768
  },
1537
- M.identifier
1769
+ A.identifier
1538
1770
  )),
1539
- C.placeholder,
1540
- /* @__PURE__ */ r(Fe, { ...y, children: /* @__PURE__ */ b(G, { type: "button", variant: "outline", children: [
1541
- /* @__PURE__ */ r(Se, {}),
1771
+ b.placeholder,
1772
+ /* @__PURE__ */ r(Ae, { ...x, children: /* @__PURE__ */ y(H, { type: "button", variant: "outline", children: [
1773
+ /* @__PURE__ */ r(De, {}),
1542
1774
  " Add a field"
1543
1775
  ] }) })
1544
1776
  ]
@@ -1546,20 +1778,20 @@ const Ce = (o, i) => T(() => !i || !o ? null : o.getInput(i), [o, i]), wt = (o,
1546
1778
  ) })
1547
1779
  ] }),
1548
1780
  /* @__PURE__ */ r(
1549
- Ft,
1781
+ Pt,
1550
1782
  {
1551
1783
  remove: h,
1552
1784
  insertAfterProps: g,
1553
- dragHandleProps: F.dragHandleProps,
1554
- editProps: m
1785
+ dragHandleProps: T.dragHandleProps,
1786
+ editProps: p
1555
1787
  }
1556
1788
  )
1557
1789
  ] })
1558
1790
  }
1559
1791
  ) });
1560
- }), Gi = (o, i) => {
1792
+ }), an = (s, i) => {
1561
1793
  var t;
1562
- const e = { ...o };
1794
+ const e = { ...s };
1563
1795
  switch (i.type) {
1564
1796
  case "release":
1565
1797
  for (const n in e)
@@ -1572,162 +1804,162 @@ const Ce = (o, i) => T(() => !i || !o ? null : o.getInput(i), [o, i]), wt = (o,
1572
1804
  case "update":
1573
1805
  return i.state;
1574
1806
  }
1575
- }, Ki = (o, i) => {
1807
+ }, cn = (s, i) => {
1576
1808
  if (i)
1577
- for (let e = 0; e < o.length; e++) {
1578
- const t = o[e];
1809
+ for (let e = 0; e < s.length; e++) {
1810
+ const t = s[e];
1579
1811
  if (t) {
1580
1812
  for (const n of t.fields)
1581
1813
  if (n.identifier === i)
1582
1814
  return e;
1583
1815
  }
1584
1816
  }
1585
- }, nt = (o) => {
1817
+ }, at = (s) => {
1586
1818
  var e, t, n;
1587
1819
  const i = {};
1588
- for (let s = 0; s < o.length; s++) {
1589
- const a = o[s];
1590
- if (!a)
1820
+ for (let o = 0; o < s.length; o++) {
1821
+ const l = s[o];
1822
+ if (!l)
1591
1823
  throw new Error("Field is undefined.");
1592
- const l = s > 0 ? (e = i[o[s - 1].identifier]) == null ? void 0 : e.conditionFields : void 0, c = new Set(l);
1593
- (t = a.condition) != null && t.identifier && c.add(a.condition.identifier), i[a.identifier] = {
1824
+ const a = o > 0 ? (e = i[s[o - 1].identifier]) == null ? void 0 : e.conditionFields : void 0, c = new Set(a);
1825
+ (t = l.condition) != null && t.identifier && c.add(l.condition.identifier), i[l.identifier] = {
1594
1826
  disabled: !1,
1595
1827
  conditionFields: c,
1596
- conditionIndex: Ki(o, (n = a.condition) == null ? void 0 : n.identifier),
1597
- index: s,
1598
- label: a.label
1828
+ conditionIndex: cn(s, (n = l.condition) == null ? void 0 : n.identifier),
1829
+ index: o,
1830
+ label: l.label
1599
1831
  };
1600
1832
  }
1601
1833
  return i;
1602
- }, rt = (o, i) => {
1603
- for (const [e, t] of Object.entries(o))
1834
+ }, ct = (s, i) => {
1835
+ for (const [e, t] of Object.entries(s))
1604
1836
  if (t.identifier === i)
1605
1837
  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) });
1838
+ }, dn = S(function() {
1839
+ const { values: i, setFieldValue: e } = ue(), [t, n] = mi(an, i.fields, at), { showInfo: o } = di();
1840
+ be(() => {
1841
+ n({ type: "update", state: at(i.fields) });
1610
1842
  }, [n, i.fields]);
1611
- const a = E((f) => {
1612
- f.type === "SECTION" && n({ type: "hold", fieldId: f.draggableId });
1613
- }, []), l = E(
1614
- (f) => {
1615
- const { source: u, destination: d, type: h, reason: m, draggableId: g } = f;
1616
- if (n({ type: "release" }), !d || m === "CANCEL")
1843
+ const l = E((u) => {
1844
+ u.type === "SECTION" && n({ type: "hold", fieldId: u.draggableId });
1845
+ }, []), a = E(
1846
+ (u) => {
1847
+ const { source: d, destination: f, type: h, reason: p, draggableId: g } = u;
1848
+ if (n({ type: "release" }), !f || p === "CANCEL")
1617
1849
  return;
1618
1850
  if (h === "ROOT") {
1619
- const P = t[g];
1620
- if (!P)
1851
+ const L = t[g];
1852
+ if (!L)
1621
1853
  throw new Error("Could not find section context.");
1622
- let A = typeof P.conditionIndex < "u" ? (
1854
+ let P = typeof L.conditionIndex < "u" ? (
1623
1855
  // 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({
1856
+ Math.max(L.conditionIndex + 1, f.index)
1857
+ ) : f.index;
1858
+ for (const F of Object.values(t))
1859
+ F.conditionIndex === d.index && (P = Math.min(P, F.index - 1));
1860
+ return P != f.index && o({
1629
1861
  title: "Reordered sections",
1630
1862
  description: "Sections with conditions must be below the fields they reference."
1631
- }), e("fields", Re(i.fields, u.index, A));
1863
+ }), e("fields", Ne(i.fields, d.index, P));
1632
1864
  }
1633
1865
  if (h !== "SECTION")
1634
1866
  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)
1867
+ const [x, z] = ct(i.fields, d.droppableId) ?? [], [I, w] = ct(i.fields, f.droppableId) ?? [];
1868
+ if (!(x != null && x.fields) || !I)
1637
1869
  throw new Error("Could not find section with fields.");
1638
- if (y.identifier === w.identifier)
1870
+ if (x.identifier === I.identifier)
1639
1871
  e(
1640
- `fields.${I}.fields`,
1641
- Re(y.fields, u.index, d.index)
1872
+ `fields.${z}.fields`,
1873
+ Ne(x.fields, d.index, f.index)
1642
1874
  ).then();
1643
1875
  else {
1644
- const P = y.fields[u.index];
1645
- if (!P)
1876
+ const L = x.fields[d.index];
1877
+ if (!L)
1646
1878
  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)
1879
+ e(`fields.${z}.fields`, Ie(x.fields, d.index)).then(), e(
1880
+ `fields.${w}.fields`,
1881
+ xt(I.fields, f.index, L)
1650
1882
  ).then();
1651
1883
  }
1652
1884
  },
1653
- [i.fields, e, t, s]
1654
- ), c = T(
1885
+ [i.fields, e, t, o]
1886
+ ), c = C(
1655
1887
  () => ({
1656
1888
  index: i.fields.length,
1657
1889
  parentPath: "fields",
1658
- initial: ye(),
1659
- conditionalSourceFields: qe(i.fields, i.fields.length)
1890
+ initial: xe(),
1891
+ conditionalSourceFields: Be(i.fields, i.fields.length)
1660
1892
  }),
1661
1893
  [i.fields]
1662
1894
  );
1663
- return /* @__PURE__ */ r(lt, { onDragStart: a, onDragEnd: l, children: /* @__PURE__ */ r(Ue, { droppableId: "droppable", type: "ROOT", children: (f) => /* @__PURE__ */ b(
1895
+ return /* @__PURE__ */ r(ht, { onDragStart: l, onDragEnd: a, children: /* @__PURE__ */ r(Ke, { droppableId: "droppable", type: "ROOT", children: (u) => /* @__PURE__ */ y(
1664
1896
  v,
1665
1897
  {
1666
- ref: f.innerRef,
1667
- ...f.droppableProps,
1898
+ ref: u.innerRef,
1899
+ ...u.droppableProps,
1668
1900
  direction: "column",
1669
1901
  gap: "0",
1670
1902
  children: [
1671
- i.fields.map((u, d) => /* @__PURE__ */ r(
1672
- Ui,
1903
+ i.fields.map((d, f) => /* @__PURE__ */ r(
1904
+ ln,
1673
1905
  {
1674
- field: u,
1675
- index: d,
1906
+ field: d,
1907
+ index: f,
1676
1908
  dropState: t
1677
1909
  },
1678
- u.label
1910
+ d.label
1679
1911
  )),
1680
- f.placeholder,
1681
- /* @__PURE__ */ r(Fe, { ...c, children: /* @__PURE__ */ b(G, { type: "button", variant: "outline", children: [
1682
- /* @__PURE__ */ r(Se, {}),
1912
+ u.placeholder,
1913
+ /* @__PURE__ */ r(Ae, { ...c, children: /* @__PURE__ */ y(H, { type: "button", variant: "outline", children: [
1914
+ /* @__PURE__ */ r(De, {}),
1683
1915
  " Add a section"
1684
1916
  ] }) })
1685
1917
  ]
1686
1918
  }
1687
1919
  ) }) });
1688
- }), Qi = {
1920
+ }), un = {
1689
1921
  title: "",
1690
1922
  description: "",
1691
1923
  fields: []
1692
- }, Xi = new fe({
1924
+ }, fn = new he({
1693
1925
  label: "Title",
1694
1926
  minLength: 0,
1695
1927
  maxLength: 100,
1696
1928
  required: !0,
1697
1929
  identifier: "title"
1698
- }), Ji = { formId: ke, placeholder: "Give your form a title." }, Zi = new he({
1930
+ }), mn = { formId: _e, placeholder: "Give your form a title." }, hn = new pe({
1699
1931
  label: "Description",
1700
1932
  minLength: 0,
1701
1933
  maxLength: 1e3,
1702
1934
  required: !1,
1703
1935
  identifier: "description"
1704
- }), en = { formId: ke, placeholder: "Explain the purpose of this form." }, tn = () => {
1936
+ }), pn = { formId: _e, placeholder: "Explain the purpose of this form." }, gn = () => {
1705
1937
  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) => {
1938
+ }, Ln = S(
1939
+ ye((s, i) => {
1940
+ const { onCancel: e, onSave: t, revision: n } = s, o = n ? "Edit form" : "Create a new form", { heading: l = o } = s, a = E((p) => {
1709
1941
  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))
1942
+ 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
1943
  return g;
1712
- }, []), c = je({
1713
- initialValues: Ci(n) ?? Qi,
1714
- validate: l,
1715
- onSubmit: (m) => t(m),
1944
+ }, []), c = Ue({
1945
+ initialValues: Pi(n) ?? un,
1946
+ validate: a,
1947
+ onSubmit: (p) => t(p),
1716
1948
  // only validate the entire for on submit
1717
1949
  validateOnChange: !1,
1718
1950
  validateOnBlur: !1
1719
- }), f = T(() => yt(c.values), [c.values]), u = Ce(Xi, Ji), d = Ce(Zi, en), h = T(
1720
- () => typeof a == "object" ? a : /* @__PURE__ */ r(ze, { children: a }),
1721
- [a]
1951
+ }), u = C(() => Tt(c.values), [c.values]), d = ze(fn, mn), f = ze(hn, pn), h = C(
1952
+ () => typeof l == "object" ? l : /* @__PURE__ */ r(Le, { children: l }),
1953
+ [l]
1722
1954
  );
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: [
1955
+ return /* @__PURE__ */ r(Q.Root, { ref: i, defaultValue: "edit", children: /* @__PURE__ */ y(v, { direction: "column", gap: "2", children: [
1956
+ /* @__PURE__ */ y(Q.List, { children: [
1725
1957
  /* @__PURE__ */ r(Q.Trigger, { value: "edit", children: "Edit" }),
1726
1958
  /* @__PURE__ */ r(Q.Trigger, { value: "preview", children: "Preview" })
1727
1959
  ] }),
1728
- /* @__PURE__ */ b(Q.Content, { value: "edit", children: [
1960
+ /* @__PURE__ */ y(Q.Content, { value: "edit", children: [
1729
1961
  h,
1730
- /* @__PURE__ */ b(k, { children: [
1962
+ /* @__PURE__ */ y(k, { children: [
1731
1963
  "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
1964
  " ",
1733
1965
  /* @__PURE__ */ r("em", { children: "Preview" }),
@@ -1735,52 +1967,53 @@ const Ce = (o, i) => T(() => !i || !o ? null : o.getInput(i), [o, i]), wt = (o,
1735
1967
  " ",
1736
1968
  /* @__PURE__ */ r("strong", { children: "field values entered on this page will not be saved." })
1737
1969
  ] }),
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,
1970
+ /* @__PURE__ */ r(v, { asChild: !0, direction: "column", gap: "2", mt: "3", children: /* @__PURE__ */ y("form", { id: _e, onSubmit: c.handleSubmit, children: [
1971
+ /* @__PURE__ */ y(Ge, { value: c, children: [
1741
1972
  d,
1742
- /* @__PURE__ */ r(Yi, {}),
1973
+ f,
1974
+ /* @__PURE__ */ r(dn, {}),
1743
1975
  /* @__PURE__ */ r(k, { severity: "danger", size: "1", children: typeof c.errors.fields == "string" && c.errors.fields })
1744
1976
  ] }),
1745
- /* @__PURE__ */ b(v, { justify: "end", gap: "2", children: [
1746
- /* @__PURE__ */ r(G, { type: "button", variant: "soft", onClick: e, children: "Cancel" }),
1747
- /* @__PURE__ */ r(G, { type: "submit", disabled: !c.isValid, children: "Save" })
1977
+ /* @__PURE__ */ y(v, { justify: "end", gap: "2", children: [
1978
+ /* @__PURE__ */ r(H, { type: "button", variant: "soft", onClick: e, children: "Cancel" }),
1979
+ /* @__PURE__ */ r(H, { type: "submit", disabled: !c.isValid, children: "Save" })
1748
1980
  ] })
1749
1981
  ] }) })
1750
1982
  ] }),
1751
- /* @__PURE__ */ r(Q.Content, { value: "preview", children: /* @__PURE__ */ r(Je, { schema: f, onSubmit: tn }) })
1983
+ /* @__PURE__ */ r(Q.Content, { value: "preview", children: /* @__PURE__ */ r(tt, { schema: u, onSubmit: gn }) })
1752
1984
  ] }) });
1753
1985
  })
1754
1986
  );
1755
1987
  export {
1756
- le as BooleanField,
1757
- bi as BooleanInput,
1758
- $e as DateField,
1759
- vi as DateInput,
1988
+ ce as BooleanField,
1989
+ Si as BooleanInput,
1990
+ Re as DateField,
1991
+ Ei as DateInput,
1760
1992
  K as FieldSection,
1761
- hn as FormBrowser,
1762
- bn as FormBuilder,
1763
- Je as FormRenderer,
1764
- pn as FormSubmissionBrowser,
1765
- fn as FormSubmissionViewer,
1766
- Ne as MultiSelectField,
1767
- Ei as MultiSelectInput,
1768
- we as MultiStringField,
1769
- Si as MultiStringInput,
1770
- ue as NumberField,
1771
- yi as NumberInput,
1772
- mn as PatchField,
1773
- gn as PatchFormProvider,
1774
- Ie as SelectField,
1775
- xi as SelectInput,
1776
- fe as StringField,
1777
- wi as StringInput,
1778
- he as TextField,
1779
- Ii as TextInput,
1780
- De as deserialize,
1781
- bt as deserializeField,
1782
- yt as formRevisionToSchema,
1783
- vt as isConditionMet,
1784
- Ce as useFieldInput,
1785
- wt as useFieldInputs
1993
+ zn as FormBrowser,
1994
+ Ln as FormBuilder,
1995
+ tt as FormRenderer,
1996
+ En as FormSubmissionBrowser,
1997
+ Sn as FormSubmissionViewer,
1998
+ Te as MultiSelectField,
1999
+ $i as MultiSelectInput,
2000
+ Ce as MultiStringField,
2001
+ _i as MultiStringInput,
2002
+ G as NumberField,
2003
+ zi as NumberInput,
2004
+ An as PatchField,
2005
+ Dn as PatchFormProvider,
2006
+ Fe as SelectField,
2007
+ Li as SelectInput,
2008
+ he as StringField,
2009
+ Ai as StringInput,
2010
+ pe as TextField,
2011
+ Di as TextInput,
2012
+ ke as deserialize,
2013
+ Ft as deserializeField,
2014
+ Tt as formRevisionToSchema,
2015
+ St as isConditionMet,
2016
+ ze as useFieldInput,
2017
+ zt as useFieldInputs,
2018
+ We as valueIsFile
1786
2019
  };