@overmap-ai/forms 1.0.3-form-improvements.5 → 1.0.3-form-improvements.6

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
@@ -90,8 +90,8 @@ class M extends Ct {
90
90
  }
91
91
  }
92
92
  m(M, "fieldTypeName"), m(M, "fieldTypeDescription");
93
- const Pi = "_description_17zed_1", $e = {
94
- description: Pi
93
+ const Li = "_description_17zed_1", $e = {
94
+ description: Li
95
95
  }, W = (s) => {
96
96
  const { label: i, children: e, severity: t, inputId: n, labelId: o, flexProps: l } = s;
97
97
  return /* @__PURE__ */ r(y, { direction: "column", gap: "1", asChild: !0, ...l, children: /* @__PURE__ */ b("label", { htmlFor: n, children: [
@@ -128,8 +128,8 @@ const Pi = "_description_17zed_1", $e = {
128
128
  },
129
129
  { ...n, "aria-labelledby": p }
130
130
  ];
131
- }, Li = [!0, "true"], Vi = T(function(i) {
132
- const [{ inputId: e, labelId: t, severity: n, helpText: o, label: l, fieldProps: c }, a] = H(i), f = fe(n), d = Li.includes(c.value);
131
+ }, Pi = [!0, "true"], Vi = T(function(i) {
132
+ const [{ inputId: e, labelId: t, severity: n, helpText: o, label: l, fieldProps: c }, a] = H(i), f = fe(n), d = Pi.includes(c.value);
133
133
  return /* @__PURE__ */ r(j, { helpText: o, severity: n, children: /* @__PURE__ */ r(
134
134
  W,
135
135
  {
@@ -270,7 +270,7 @@ const ki = T(function(i) {
270
270
  }
271
271
  };
272
272
  m(B, "fieldTypeName", "Number"), m(B, "fieldTypeDescription", "Allows specifying a number within a given range."), m(B, "Icon", jt), m(B, "_validateMin", (e, t) => typeof t.maximum == "number" && typeof e == "number" && t.maximum < e ? "Minimum cannot be greater than minimum." : null), m(B, "_validateMax", (e, t) => typeof t.minimum == "number" && typeof e == "number" && t.minimum > e ? "Maximum cannot be less than minimum." : null);
273
- let Q = B;
273
+ let Y = B;
274
274
  const Di = T(function(i) {
275
275
  const [{ inputId: e, labelId: t, severity: n, helpText: o, label: l, fieldProps: c }, a] = H(i), f = fe(n), d = c.value ? c.value.split("T")[0] : "";
276
276
  return /* @__PURE__ */ r(j, { helpText: o, severity: n, children: /* @__PURE__ */ r(W, { severity: n, inputId: e, labelId: t, label: l, children: /* @__PURE__ */ r(le.Input, { ...a, ...c, type: "date", id: e, color: f, value: d }) }) });
@@ -307,7 +307,7 @@ class Ce extends M {
307
307
  static getFieldCreationSchema() {
308
308
  return [
309
309
  // min, max
310
- new Q({
310
+ new Y({
311
311
  label: "Minimum length",
312
312
  description: "Minimum number of characters",
313
313
  required: !1,
@@ -317,7 +317,7 @@ class Ce extends M {
317
317
  formValidators: [this._validateMin],
318
318
  integers: !0
319
319
  }),
320
- new Q({
320
+ new Y({
321
321
  label: "Maximum length",
322
322
  description: "Maximum number of characters",
323
323
  required: !1,
@@ -494,7 +494,7 @@ const St = (s, i) => {
494
494
  t = `${s} (${++e})`;
495
495
  return t;
496
496
  }, Ni = T(function(i) {
497
- const [{ inputId: e, labelId: t, severity: n, helpText: o, label: l, fieldProps: c }, a] = H(i), f = fe(n), d = w(() => Array.isArray(c.value) ? c.value : [], [c.value]), { onChange: u, onBlur: p } = c, h = `${e}-droppable`, { disabled: g } = a, [x, z] = ce(""), [F, v] = ce(""), P = F || o, L = F ? "red" : f, I = S(
497
+ const [{ inputId: e, labelId: t, severity: n, helpText: o, label: l, fieldProps: c }, a] = H(i), f = fe(n), d = w(() => Array.isArray(c.value) ? c.value : [], [c.value]), { onChange: u, onBlur: p } = c, h = `${e}-droppable`, { disabled: g } = a, [x, z] = ce(""), [F, v] = ce(""), L = F || o, P = F ? "red" : f, I = S(
498
498
  (A) => {
499
499
  u(A), p(A);
500
500
  },
@@ -511,7 +511,7 @@ const St = (s, i) => {
511
511
  return v("Option cannot be empty");
512
512
  const A = x.trim();
513
513
  I([...d, { value: A, label: A }]), z("");
514
- }, [x, F, I, d]), Y = S(
514
+ }, [x, F, I, d]), K = S(
515
515
  (A) => {
516
516
  A.key === "Enter" && (A.preventDefault(), O());
517
517
  },
@@ -531,7 +531,7 @@ const St = (s, i) => {
531
531
  [I, d]
532
532
  );
533
533
  return /* @__PURE__ */ r(yt, { onDragEnd: U, children: /* @__PURE__ */ b(y, { direction: "column", gap: "2", children: [
534
- /* @__PURE__ */ r(j, { helpText: P, severity: n, children: /* @__PURE__ */ r(W, { severity: n, inputId: e, labelId: t, label: l, children: (!g || d.length === 0) && /* @__PURE__ */ b(y, { gap: "2", children: [
534
+ /* @__PURE__ */ r(j, { helpText: L, severity: n, children: /* @__PURE__ */ r(W, { severity: n, inputId: e, labelId: t, label: l, children: (!g || d.length === 0) && /* @__PURE__ */ b(y, { gap: "2", children: [
535
535
  /* @__PURE__ */ r(he, { grow: "1", children: /* @__PURE__ */ r(
536
536
  le.Input,
537
537
  {
@@ -540,9 +540,9 @@ const St = (s, i) => {
540
540
  ...c,
541
541
  value: x,
542
542
  onChange: V,
543
- onKeyDown: Y,
543
+ onKeyDown: K,
544
544
  id: e,
545
- color: L,
545
+ color: P,
546
546
  onBlur: void 0
547
547
  }
548
548
  ) }),
@@ -742,9 +742,9 @@ const Wi = T(function({ field: i, ...e }) {
742
742
  const o = i.options.getFieldToClone(t);
743
743
  return o ? Me(o) : null;
744
744
  }, [i.options, t]);
745
- return Le(n, e);
745
+ return Pe(n, e);
746
746
  });
747
- class Pe extends M {
747
+ class Le extends M {
748
748
  constructor(e, t) {
749
749
  super({ ...e, type: "custom" });
750
750
  m(this, "Component");
@@ -760,8 +760,8 @@ class Pe extends M {
760
760
  return /* @__PURE__ */ r(t, { field: this, ...e });
761
761
  }
762
762
  }
763
- m(Pe, "fieldTypeName", "Custom"), m(Pe, "fieldTypeDescription", "Allows re-rendering of field already in the form");
764
- class ji extends Pe {
763
+ m(Le, "fieldTypeName", "Custom"), m(Le, "fieldTypeDescription", "Allows re-rendering of field already in the form");
764
+ class ji extends Le {
765
765
  constructor(i) {
766
766
  super(i, Wi);
767
767
  }
@@ -855,7 +855,7 @@ const Hi = T(function(i) {
855
855
  var n;
856
856
  if (e.type !== "section")
857
857
  throw new Error("Invalid type");
858
- const t = ((n = e.fields) == null ? void 0 : n.map(Pt)) ?? [];
858
+ const t = ((n = e.fields) == null ? void 0 : n.map(Lt)) ?? [];
859
859
  return new oe({ ...e, fields: t });
860
860
  }
861
861
  conditional() {
@@ -883,7 +883,7 @@ const Hi = T(function(i) {
883
883
  }
884
884
  };
885
885
  m(oe, "fieldTypeName", "Section"), m(oe, "fieldTypeDescription", "Sections can be useful for grouping fields together. They can also be conditionally shown or hidden.");
886
- let K = oe;
886
+ let Q = oe;
887
887
  const Ui = "_previewImage_1ig84_1", Gi = {
888
888
  previewImage: Ui
889
889
  }, it = (s) => {
@@ -893,7 +893,7 @@ const Ui = "_previewImage_1ig84_1", Gi = {
893
893
  e /= 1024, t++;
894
894
  return new Intl.NumberFormat([], { maximumFractionDigits: 2, style: "unit", unit: i[t] }).format(e);
895
895
  }, Ki = T(function(i) {
896
- var L;
896
+ var P;
897
897
  const [{ inputId: e, labelId: t, severity: n, helpText: o, label: l, fieldProps: c, field: a }, f] = H(i), { onChange: d } = c, u = fe(n), p = yi(null), { value: h } = c, g = w(() => o || (a.maxFileSize ? `Maximum file size: ${it(a.maxFileSize)}` : null), [a.maxFileSize, o]), x = S(() => {
898
898
  var I;
899
899
  (I = p.current) == null || I.click();
@@ -903,13 +903,13 @@ const Ui = "_previewImage_1ig84_1", Gi = {
903
903
  V.splice(I, 1), d({ target: { files: V } });
904
904
  },
905
905
  [h, d]
906
- ), F = h ? "Select new files" : "Select files", v = h ? "Select new file" : "Select a file", P = a.maxFiles > 1 ? F : v;
906
+ ), F = h ? "Select new files" : "Select files", v = h ? "Select new file" : "Select a file", L = a.maxFiles > 1 ? F : v;
907
907
  return /* @__PURE__ */ b(y, { direction: "column", gap: "2", children: [
908
908
  /* @__PURE__ */ r(j, { helpText: g, severity: n, children: /* @__PURE__ */ b(W, { severity: n, inputId: e, labelId: t, label: l, children: [
909
909
  /* @__PURE__ */ r(y, { direction: "row", gap: "2", children: /* @__PURE__ */ r(he, { width: "max-content", asChild: !0, children: /* @__PURE__ */ b(G, { ...f, onClick: x, children: [
910
910
  /* @__PURE__ */ r(bt, {}),
911
911
  " ",
912
- P
912
+ L
913
913
  ] }) }) }),
914
914
  /* @__PURE__ */ r(
915
915
  "input",
@@ -918,7 +918,7 @@ const Ui = "_previewImage_1ig84_1", Gi = {
918
918
  type: "file",
919
919
  ref: p,
920
920
  id: e,
921
- accept: (L = a.extensions) == null ? void 0 : L.join(","),
921
+ accept: (P = a.extensions) == null ? void 0 : P.join(","),
922
922
  multiple: a.maxFiles > 1,
923
923
  color: u,
924
924
  style: { display: "none" },
@@ -984,7 +984,7 @@ const Ui = "_previewImage_1ig84_1", Gi = {
984
984
  }
985
985
  static getFieldCreationSchema() {
986
986
  return [
987
- new Q({
987
+ new Y({
988
988
  label: "How many files can be uploaded?",
989
989
  description: "By default, only one file can be uploaded.",
990
990
  required: !1,
@@ -992,7 +992,7 @@ const Ui = "_previewImage_1ig84_1", Gi = {
992
992
  maximum: 10,
993
993
  identifier: "maximum_files"
994
994
  }),
995
- new Q({
995
+ new Y({
996
996
  label: "What is the maximum size of each file?",
997
997
  description: "Maximum file size in bytes.",
998
998
  required: !1,
@@ -1062,21 +1062,21 @@ m(se, "fieldTypeName", "Upload"), m(se, "fieldTypeDescription", "Allows a file t
1062
1062
  let Ue = se;
1063
1063
  const nt = {
1064
1064
  date: We,
1065
- number: Q,
1065
+ number: Y,
1066
1066
  boolean: ue,
1067
1067
  select: Ee,
1068
1068
  string: ge,
1069
1069
  text: be,
1070
- custom: Pe,
1070
+ custom: Le,
1071
1071
  upload: Ue,
1072
1072
  // TODO: Underscore
1073
1073
  "multi-string": ze,
1074
1074
  "multi-select": Ae
1075
- }, Pt = (s) => {
1075
+ }, Lt = (s) => {
1076
1076
  const i = s.type;
1077
1077
  return nt[i].deserialize(s);
1078
- }, Me = (s) => s.type === "section" ? K.deserialize(s) : Pt(s);
1079
- function Lt(s, i = {}) {
1078
+ }, Me = (s) => s.type === "section" ? Q.deserialize(s) : Lt(s);
1079
+ function Pt(s, i = {}) {
1080
1080
  const { readonly: e = !1 } = i;
1081
1081
  return {
1082
1082
  title: s.title,
@@ -1102,13 +1102,13 @@ function Vt(s, i) {
1102
1102
  }
1103
1103
  return t === i;
1104
1104
  }
1105
- const Le = (s, i) => w(() => !i || !s ? null : s.getInput(i), [s, i]), kt = (s, i) => {
1105
+ const Pe = (s, i) => w(() => !i || !s ? null : s.getInput(i), [s, i]), kt = (s, i) => {
1106
1106
  const e = w(() => s.map((t) => /* @__PURE__ */ r("div", { children: t.getInput(i) }, t.getId())), [s, i]);
1107
1107
  return /* @__PURE__ */ r(y, { direction: "column", gap: "2", children: e });
1108
1108
  }, Ve = (s) => Object.keys(s).length > 0, Dt = async (s, i) => {
1109
1109
  const e = {};
1110
1110
  for (const t of s.fields)
1111
- if (t instanceof K) {
1111
+ if (t instanceof Q) {
1112
1112
  if (t.condition) {
1113
1113
  const { identifier: n } = t.condition;
1114
1114
  if (!Vt(t.condition, de(i, n)))
@@ -1123,7 +1123,7 @@ const Le = (s, i) => w(() => !i || !s ? null : s.getInput(i), [s, i]), kt = (s,
1123
1123
  }
1124
1124
  if (Ve(e))
1125
1125
  return e;
1126
- }, Qi = [null, void 0], rt = (s, i) => s.reduce((e, t) => t instanceof K ? { ...e, ...rt(t.fields, i) } : (Qi.includes(de(e, t.getId())) && tt(e, t.getId(), ""), e), i), Xi = () => {
1126
+ }, Qi = [null, void 0], rt = (s, i) => s.reduce((e, t) => t instanceof Q ? { ...e, ...rt(t.fields, i) } : (Qi.includes(de(e, t.getId())) && tt(e, t.getId(), ""), e), i), Xi = () => {
1127
1127
  throw new Error("onSubmit must be provided if form is not readonly.");
1128
1128
  }, ot = T(
1129
1129
  we((s, i) => {
@@ -1142,7 +1142,7 @@ const Le = (s, i) => w(() => !i || !s ? null : s.getInput(i), [s, i]), kt = (s,
1142
1142
  } = s, { readonly: p } = e.meta, h = w(() => crypto.randomUUID(), []), g = Qe({
1143
1143
  initialValues: rt(e.fields, t),
1144
1144
  onSubmit: n,
1145
- validate: (P) => Dt(e, P),
1145
+ validate: (L) => Dt(e, L),
1146
1146
  // only validate the entire form on submit
1147
1147
  validateOnBlur: !1,
1148
1148
  validateOnChange: !1
@@ -1167,14 +1167,14 @@ const Le = (s, i) => w(() => !i || !s ? null : s.getInput(i), [s, i]), kt = (s,
1167
1167
  ] })
1168
1168
  ] }) }) });
1169
1169
  })
1170
- ), Ln = T(
1170
+ ), Pn = T(
1171
1171
  we((s, i) => {
1172
1172
  const { submission: e, showFormDescription: t = !1, showFormTitle: n = !0 } = s, o = $(vt(e.form_revision)), { sdk: l } = wt();
1173
1173
  if (!o)
1174
1174
  throw new Error(
1175
1175
  `Could not find revision ${e.form_revision} for submission ${e.offline_id}.`
1176
1176
  );
1177
- const c = w(() => Lt(o, { readonly: !0 }), [o]), a = w(() => {
1177
+ const c = w(() => Pt(o, { readonly: !0 }), [o]), a = w(() => {
1178
1178
  const f = xi(e.offline_id)(l.store.getState()) ?? [], d = {};
1179
1179
  for (const u of f) {
1180
1180
  const p = l.files.fetchFileFromUrl(u.file, u.file_sha1, u.file_name).then((g) => {
@@ -1211,14 +1211,14 @@ const Le = (s, i) => w(() => !i || !s ? null : s.getInput(i), [s, i]), kt = (s,
1211
1211
  },
1212
1212
  [a]
1213
1213
  ), h = w(() => {
1214
- const v = a.store.getState(), P = {};
1215
- for (const L of Object.values(u)) {
1216
- const I = xt(L.owner_organization || -1)(v);
1217
- I && (P[`${Ne}${I.id}`] = I.name);
1218
- const V = et(L.owner_user || -1)(v);
1219
- V && (P[`${Be}${V.id}`] = V.username);
1214
+ const v = a.store.getState(), L = {};
1215
+ for (const P of Object.values(u)) {
1216
+ const I = xt(P.owner_organization || -1)(v);
1217
+ I && (L[`${Ne}${I.id}`] = I.name);
1218
+ const V = et(P.owner_user || -1)(v);
1219
+ V && (L[`${Be}${V.id}`] = V.username);
1220
1220
  }
1221
- return Object.entries(P).map(([L, I]) => ({ itemContent: I, value: L }));
1221
+ return Object.entries(L).map(([P, I]) => ({ itemContent: I, value: P }));
1222
1222
  }, [u, a.store]), g = S((v) => {
1223
1223
  o(v.currentTarget.value);
1224
1224
  }, []), z = ($(Ci) || 0) - d.length, F = d.length == e && z > 0 ? `Only the first ${e} results are shown (${z} hidden)` : z > 0 && `${z} hidden forms`;
@@ -1391,7 +1391,7 @@ const Le = (s, i) => w(() => !i || !s ? null : s.getInput(i), [s, i]), kt = (s,
1391
1391
  })
1392
1392
  ), $t = {
1393
1393
  ...nt,
1394
- section: K
1394
+ section: Q
1395
1395
  }, on = T(function(i) {
1396
1396
  const { field: e, setFieldType: t } = i, n = e.fieldTypeName, o = e.fieldTypeDescription, l = e.Icon;
1397
1397
  return /* @__PURE__ */ b(y, { gap: "4", align: "center", children: [
@@ -1419,7 +1419,7 @@ const Le = (s, i) => w(() => !i || !s ? null : s.getInput(i), [s, i]), kt = (s,
1419
1419
  n < sn && /* @__PURE__ */ r(si, { size: "4" })
1420
1420
  ] }, n)) });
1421
1421
  }), an = (s) => (i) => {
1422
- if (console.log("in validate", s, i), !(!i || typeof i != "string") && s.includes(i.trim()))
1422
+ if (!(!i || typeof i != "string") && s.includes(i.trim()))
1423
1423
  return "This name is already taken.";
1424
1424
  }, cn = (s, i) => {
1425
1425
  const e = [
@@ -1442,18 +1442,16 @@ const Le = (s, i) => w(() => !i || !s ? null : s.getInput(i), [s, i]), kt = (s,
1442
1442
  new ue({ label: "Required", description: null, required: !1, identifier: "required" })
1443
1443
  ];
1444
1444
  }, dn = T(function(i) {
1445
- const { fieldType: e, handleCancel: t, handleCreateField: n, defaultField: o, conditionalSourceFields: l } = i, c = $t[e];
1446
- console.log("default field", o);
1447
- const a = me(), f = w(() => {
1445
+ const { fieldType: e, handleCancel: t, handleCreateField: n, defaultField: o, conditionalSourceFields: l } = i, c = $t[e], a = me(), f = w(() => {
1448
1446
  const d = Et(a.values.fields).filter((p) => p !== (o == null ? void 0 : o.label));
1449
1447
  let u = cn(d, e);
1450
- if (console.log("first set of errors", c, K, l), c === K) {
1448
+ if (c === Q) {
1451
1449
  if (l === void 0)
1452
1450
  throw new Error("Conditional source fields must be provided when changing sections.");
1453
1451
  u = u.concat(c.getFieldCreationSchema(l));
1454
1452
  } else {
1455
1453
  if (!(c.prototype instanceof M))
1456
- throw console.log("badinstance"), new Error(`Field must be an instance of BaseField. Got ${c}.`);
1454
+ throw new Error(`Field must be an instance of BaseField. Got ${c}.`);
1457
1455
  u = [...u, ...c.getFieldCreationSchema()];
1458
1456
  }
1459
1457
  return {
@@ -1479,14 +1477,14 @@ const Le = (s, i) => w(() => !i || !s ? null : s.getInput(i), [s, i]), kt = (s,
1479
1477
  throw new Error("Initial field must be provided if editing is true.");
1480
1478
  const g = !d && !l && !o, x = g ? "Choose a field type" : `${u} settings`, z = g ? "Select a field type to add to this section." : (u == null ? void 0 : u.toLowerCase()) === "section" ? "Customize your section" : `Customize your ${u == null ? void 0 : u.toLowerCase()} field.`, F = S(() => f(void 0), []), v = S((I) => {
1481
1479
  f(void 0), I();
1482
- }, []), P = S(
1480
+ }, []), L = S(
1483
1481
  (I, V) => {
1484
1482
  const { label: O } = I;
1485
1483
  if (!d)
1486
1484
  throw new Error("Field type must be selected before creating a field.");
1487
1485
  if (!O || typeof O != "string")
1488
1486
  throw new Error("Label must be provided before creating a field.");
1489
- const Y = Me({
1487
+ const K = Me({
1490
1488
  type: d,
1491
1489
  ...I,
1492
1490
  identifier: St(I.identifier, O)
@@ -1496,23 +1494,23 @@ const Le = (s, i) => w(() => !i || !s ? null : s.getInput(i), [s, i]), kt = (s,
1496
1494
  let U;
1497
1495
  if (!Array.isArray(q))
1498
1496
  throw new Error("Parent path must point to an array.");
1499
- l ? U = Ri(q, t, Y) : U = Tt(q, t, Y), p(e, U).then(), V();
1497
+ l ? U = Ri(q, t, K) : U = Tt(q, t, K), p(e, U).then(), V();
1500
1498
  },
1501
1499
  [l, d, h, e, p, t]
1502
- ), L = S(
1500
+ ), P = S(
1503
1501
  (I) => g ? /* @__PURE__ */ r(ln, { setFieldType: f }) : /* @__PURE__ */ r(
1504
1502
  dn,
1505
1503
  {
1506
1504
  conditionalSourceFields: c,
1507
1505
  handleCancel: F,
1508
- handleCreateField: (V) => P(V, I),
1506
+ handleCreateField: (V) => L(V, I),
1509
1507
  fieldType: d,
1510
1508
  defaultField: o
1511
1509
  }
1512
1510
  ),
1513
- [c, F, P, o, g, d]
1511
+ [c, F, L, o, g, d]
1514
1512
  );
1515
- return /* @__PURE__ */ r(li, { onCloseInterrupt: v, title: x, description: z, content: L, children: n });
1513
+ return /* @__PURE__ */ r(li, { onCloseInterrupt: v, title: x, description: z, content: P, children: n });
1516
1514
  }), dt = ({ children: s }) => /* @__PURE__ */ r(pt, { children: s }), ut = (s, i) => ({
1517
1515
  initial: s ? i : "none",
1518
1516
  sm: s ? "none" : i
@@ -1584,9 +1582,7 @@ const Le = (s, i) => w(() => !i || !s ? null : s.getInput(i), [s, i]), kt = (s,
1584
1582
  ) })
1585
1583
  ] });
1586
1584
  }), Oe = "form-builder", un = T(function(i) {
1587
- const { field: e, index: t, sectionIndex: n, takenLabels: o, remove: l } = i, c = w(() => Me(e), [e]), a = Le(c, { formId: Oe, disabled: !0 });
1588
- console.log(e, t, n, c);
1589
- const f = w(
1585
+ const { field: e, index: t, sectionIndex: n, takenLabels: o, remove: l } = i, c = w(() => Me(e), [e]), a = Pe(c, { formId: Oe, disabled: !0 }), f = w(
1590
1586
  () => ({
1591
1587
  index: t,
1592
1588
  parentPath: `fields.${n}.fields`,
@@ -1632,10 +1628,8 @@ const Le = (s, i) => w(() => !i || !s ? null : s.getInput(i), [s, i]), kt = (s,
1632
1628
  }
1633
1629
  ) });
1634
1630
  }), fn = T(function(i) {
1635
- var V, O, Y, q, U, A, R;
1636
- const { field: e, index: t, dropState: n } = i, o = (V = n[e.identifier]) == null ? void 0 : V.disabled, { setFieldValue: l, values: c } = me(), a = pi(), f = Et(c.fields);
1637
- console.log("field section", e, t, c);
1638
- const d = S(
1631
+ var V, O, K, q, U, A, R;
1632
+ const { field: e, index: t, dropState: n } = i, o = (V = n[e.identifier]) == null ? void 0 : V.disabled, { setFieldValue: l, values: c } = me(), a = pi(), f = Et(c.fields), d = S(
1639
1633
  (C, E) => {
1640
1634
  for (const _ of C) {
1641
1635
  const k = E.indexOf(_);
@@ -1745,13 +1739,13 @@ const Le = (s, i) => w(() => !i || !s ? null : s.getInput(i), [s, i]), kt = (s,
1745
1739
  conditionalSourceFields: Fe(c.fields, t + 1)
1746
1740
  }),
1747
1741
  [g, e, t, c.fields]
1748
- ), P = w(
1742
+ ), L = w(
1749
1743
  () => {
1750
1744
  var C, E;
1751
1745
  return (E = zt(c.fields, (C = e.condition) == null ? void 0 : C.identifier)) == null ? void 0 : E.label;
1752
1746
  },
1753
1747
  [(O = e.condition) == null ? void 0 : O.identifier, c.fields]
1754
- ), L = Array.isArray((Y = e.condition) == null ? void 0 : Y.value) ? "contains all of" : "equals";
1748
+ ), P = Array.isArray((K = e.condition) == null ? void 0 : K.value) ? "contains all of" : "equals";
1755
1749
  if (Ge((q = e.condition) == null ? void 0 : q.value))
1756
1750
  throw new Error("File values are not supported for conditions.");
1757
1751
  const I = Array.isArray((U = e.condition) == null ? void 0 : U.value) ? (A = e.condition) == null ? void 0 : A.value.map((C) => typeof C == "string" ? C : C.label).join(", ") : (R = e.condition) == null ? void 0 : R.value.toString();
@@ -1770,9 +1764,9 @@ const Le = (s, i) => w(() => !i || !s ? null : s.getInput(i), [s, i]), kt = (s,
1770
1764
  ] }),
1771
1765
  e.condition && /* @__PURE__ */ r(D, { size: "1", children: /* @__PURE__ */ b(hi, { children: [
1772
1766
  "Display only if ",
1773
- /* @__PURE__ */ r(lt, { children: P }),
1767
+ /* @__PURE__ */ r(lt, { children: L }),
1774
1768
  " ",
1775
- L,
1769
+ P,
1776
1770
  " ",
1777
1771
  /* @__PURE__ */ r(lt, { children: I })
1778
1772
  ] }) }),
@@ -1876,19 +1870,19 @@ const Le = (s, i) => w(() => !i || !s ? null : s.getInput(i), [s, i]), kt = (s,
1876
1870
  if (n({ type: "release" }), !u || h === "CANCEL")
1877
1871
  return;
1878
1872
  if (p === "ROOT") {
1879
- const P = t[g];
1880
- if (!P)
1873
+ const L = t[g];
1874
+ if (!L)
1881
1875
  throw new Error("Could not find section context.");
1882
- let L = typeof P.conditionIndex < "u" ? (
1876
+ let P = typeof L.conditionIndex < "u" ? (
1883
1877
  // cannot move a section with a condition before the condition's field
1884
- Math.max(P.conditionIndex + 1, u.index)
1878
+ Math.max(L.conditionIndex + 1, u.index)
1885
1879
  ) : u.index;
1886
1880
  for (const I of Object.values(t))
1887
- I.conditionIndex === d.index && (L = Math.min(L, I.index - 1));
1888
- return L != u.index && o({
1881
+ I.conditionIndex === d.index && (P = Math.min(P, I.index - 1));
1882
+ return P != u.index && o({
1889
1883
  title: "Reordered sections",
1890
1884
  description: "Sections with conditions must be below the fields they reference."
1891
- }), e("fields", je(i.fields, d.index, L));
1885
+ }), e("fields", je(i.fields, d.index, P));
1892
1886
  }
1893
1887
  if (p !== "SECTION")
1894
1888
  throw new Error("Unexpected droppable type.");
@@ -1901,12 +1895,12 @@ const Le = (s, i) => w(() => !i || !s ? null : s.getInput(i), [s, i]), kt = (s,
1901
1895
  je(x.fields, d.index, u.index)
1902
1896
  ).then();
1903
1897
  else {
1904
- const P = x.fields[d.index];
1905
- if (!P)
1898
+ const L = x.fields[d.index];
1899
+ if (!L)
1906
1900
  throw new Error("Could not find field to reorder.");
1907
1901
  e(`fields.${z}.fields`, Se(x.fields, d.index)).then(), e(
1908
1902
  `fields.${v}.fields`,
1909
- Tt(F.fields, u.index, P)
1903
+ Tt(F.fields, u.index, L)
1910
1904
  ).then();
1911
1905
  }
1912
1906
  },
@@ -1976,7 +1970,7 @@ const Le = (s, i) => w(() => !i || !s ? null : s.getInput(i), [s, i]), kt = (s,
1976
1970
  // only validate the entire for on submit
1977
1971
  validateOnChange: !1,
1978
1972
  validateOnBlur: !1
1979
- }), f = w(() => Lt(a.values), [a.values]), d = Le(bn, yn), u = Le(vn, wn), p = w(
1973
+ }), f = w(() => Pt(a.values), [a.values]), d = Pe(bn, yn), u = Pe(vn, wn), p = w(
1980
1974
  () => typeof l == "object" ? l : /* @__PURE__ */ r(De, { children: l }),
1981
1975
  [l]
1982
1976
  );
@@ -2017,17 +2011,17 @@ export {
2017
2011
  Vi as BooleanInput,
2018
2012
  We as DateField,
2019
2013
  Di as DateInput,
2020
- K as FieldSection,
2014
+ Q as FieldSection,
2021
2015
  Vn as FormBrowser,
2022
2016
  $n as FormBuilder,
2023
2017
  ot as FormRenderer,
2024
2018
  kn as FormSubmissionBrowser,
2025
- Ln as FormSubmissionViewer,
2019
+ Pn as FormSubmissionViewer,
2026
2020
  Ae as MultiSelectField,
2027
2021
  qi as MultiSelectInput,
2028
2022
  ze as MultiStringField,
2029
2023
  Ni as MultiStringInput,
2030
- Q as NumberField,
2024
+ Y as NumberField,
2031
2025
  ki as NumberInput,
2032
2026
  Dn as PatchField,
2033
2027
  _n as PatchFormProvider,
@@ -2038,10 +2032,10 @@ export {
2038
2032
  be as TextField,
2039
2033
  $i as TextInput,
2040
2034
  Me as deserialize,
2041
- Pt as deserializeField,
2042
- Lt as formRevisionToSchema,
2035
+ Lt as deserializeField,
2036
+ Pt as formRevisionToSchema,
2043
2037
  Vt as isConditionMet,
2044
- Le as useFieldInput,
2038
+ Pe as useFieldInput,
2045
2039
  kt as useFieldInputs,
2046
2040
  Ge as valueIsFile
2047
2041
  };
@@ -1 +1 @@
1
- (function(y,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("react/jsx-runtime"),require("@overmap-ai/blocks"),require("formik"),require("react"),require("@hello-pangea/dnd"),require("@overmap-ai/core"),require("lodash.get"),require("lodash.set")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","@overmap-ai/blocks","formik","react","@hello-pangea/dnd","@overmap-ai/core","lodash.get","lodash.set"],n):(y=typeof globalThis<"u"?globalThis:y||self,n(y.forms={},y.jsxRuntime,y.blocks,y.formik,y.React,y.dnd,y.core,y.get,y.set))})(this,function(y,n,s,D,u,G,F,J,ze){"use strict";var kt=Object.defineProperty;var Rt=(y,n,s)=>n in y?kt(y,n,{enumerable:!0,configurable:!0,writable:!0,value:s}):y[n]=s;var m=(y,n,s)=>(Rt(y,typeof n!="symbol"?n+"":n,s),s);class je{constructor(i){m(this,"type");m(this,"identifier");m(this,"description");const{description:e=null,identifier:t,type:r}=i;this.identifier=t,this.description=e,this.type=r}getId(){return this.identifier}static deserialize(i){throw new Error(`${this.name} must implement deserialize.`)}_serialize(){if(!this.identifier)throw new Error("Field identifier must be set before serializing.");return{type:this.type,identifier:this.identifier,description:this.description}}}class $ extends je{constructor(e){const{label:t,required:r,fieldValidators:o=[],formValidators:a=[],...c}=e;super(c);m(this,"required");m(this,"formValidators");m(this,"fieldValidators");m(this,"label");m(this,"onlyValidateAfterTouched",!0);this.label=t,this.required=r,this.fieldValidators=o,this.formValidators=a}static getFieldCreationSchema(){return[]}isBlank(e){return e==null||e===""}getValueFromChangeEvent(e){return e.target.value}getError(e,t){if(this.required&&this.isBlank(e))return"This field is required.";for(const r of this.getFieldValidators()){const o=r(e);if(o)return o}if(t)for(const r of this.getFormValidators()){const o=r(e,t);if(o)return o}}_serialize(){return{...super._serialize(),label:this.label,required:this.required}}getFieldValidators(){return[...this.fieldValidators]}getFormValidators(){return[...this.formValidators]}}m($,"fieldTypeName"),m($,"fieldTypeDescription");const he={description:"_description_17zed_1"},N=l=>{const{label:i,children:e,severity:t,inputId:r,labelId:o,flexProps:a}=l;return n.jsx(s.Flex,{direction:"column",gap:"1",asChild:!0,...a,children:n.jsxs("label",{htmlFor:r,children:[n.jsx(s.Text,{severity:t,id:o,children:i}),e]})})},W=l=>{const{helpText:i,children:e,severity:t}=l;return n.jsxs(s.Flex,{direction:"column",gap:"1",children:[e,n.jsx(s.Flex,{direction:"column",children:n.jsx(s.Text,{size:"1",severity:t,className:he.description,children:i})})]})},j=l=>{const{id:i,field:e,formId:t,...r}=l,[o,a,c]=D.useField(e.getId()),{touched:d}=a,h=a.error??e.description,f=a.error?"danger":void 0,p=i??`${t}-${e.getId()}-input`,g=`${p}-label`,x=e.required?`${e.label} *`:e.label,v=u.useMemo(()=>({...o,onChange:C=>{const w=e.getValueFromChangeEvent(C);c.setValue(w,!1).then(),(d||!e.onlyValidateAfterTouched)&&c.setError(e.getError(w))},onBlur:C=>{c.setTouched(!0,!1).then(),c.setError(e.getError(e.getValueFromChangeEvent(C)))}}),[e,o,c,d]);return[{helpText:h,severity:f,inputId:p,labelId:g,label:x,fieldProps:v,helpers:c,field:e},{...r,"aria-labelledby":g}]},ht=[!0,"true"],He=u.memo(function(i){const[{inputId:e,labelId:t,severity:r,helpText:o,label:a,fieldProps:c},d]=j(i),h=s.useSeverityColor(r),f=ht.includes(c.value);return n.jsx(W,{helpText:o,severity:r,children:n.jsx(N,{severity:r,inputId:e,labelId:t,label:a,flexProps:{direction:"row-reverse",justify:"end",align:"center",gap:"2"},children:n.jsx(s.Checkbox,{...d,...c,id:e,color:h,value:f.toString(),checked:f,onCheckedChange:c.onChange,onChange:void 0,onBlur:void 0})})})}),R=class R extends ${constructor(e){super({...e,type:"boolean"});m(this,"onlyValidateAfterTouched",!1)}isBlank(e){return this.required&&!e}getValueFromChangeEvent(e){return typeof e=="boolean"?e:e.target.checked}serialize(){return super._serialize()}static deserialize(e){if(e.type!=="boolean")throw new Error("Type mismatch.");return new R(e)}getInput(e){return n.jsx(He,{...e,field:this})}};m(R,"fieldTypeName","Checkbox"),m(R,"fieldTypeDescription","Perfect for both optional and required yes/no questions."),m(R,"Icon",s.CheckCircledIcon);let Q=R;const Ue=u.memo(function(i){const[{inputId:e,labelId:t,severity:r,helpText:o,label:a,fieldProps:c,field:d},h]=j(i),f=s.useSeverityColor(r);return n.jsx(W,{helpText:o,severity:r,children:n.jsx(N,{severity:r,inputId:e,labelId:t,label:a,children:n.jsx(s.TextField.Input,{...h,...c,type:"number",id:e,min:d.minimum,max:d.maximum,step:d.integers?1:.1,color:f})})})}),_=class _ extends ${constructor(e){const{minimum:t=Number.MIN_SAFE_INTEGER,maximum:r=Number.MAX_SAFE_INTEGER,integers:o=!1,...a}=e;super({...a,type:"number"});m(this,"minimum");m(this,"maximum");m(this,"integers");this.minimum=t,this.maximum=r,this.integers=o}getValueFromChangeEvent(e){const t=Number.parseFloat(e.target.value);return Number.isNaN(t)?"":t}static getFieldCreationSchema(){return[new _({label:"Minimum",description:"Minimum value",integers:!0,required:!1,identifier:"minimum",formValidators:[this._validateMin]}),new _({label:"Maximum",description:"Maximum value",integers:!0,required:!1,identifier:"maximum",formValidators:[this._validateMax]}),new Q({label:"Integers",description:"Whole numbers only",required:!1,identifier:"integers"})]}getFieldValidators(){const e=super.getFieldValidators(),t=this.minimum,r=this.maximum;return typeof t=="number"&&e.push(o=>{if(typeof o=="number"&&o<t)return`Must be at least ${this.minimum}.`}),typeof r=="number"&&e.push(o=>{if(typeof o=="number"&&o>r)return`Must be at most ${this.maximum}.`}),this.integers&&e.push(o=>{if(typeof o=="number"&&!Number.isInteger(o))return"Must be a whole number."}),e}serialize(){return{...super._serialize(),minimum:this.minimum,maximum:this.maximum,integers:this.integers}}static deserialize(e){if(e.type!=="number")throw new Error("Type mismatch.");return new _(e)}getInput(e){return n.jsx(Ue,{field:this,...e})}};m(_,"fieldTypeName","Number"),m(_,"fieldTypeDescription","Allows specifying a number within a given range."),m(_,"Icon",s.FontFamilyIcon),m(_,"_validateMin",(e,t)=>typeof t.maximum=="number"&&typeof e=="number"&&t.maximum<e?"Minimum cannot be greater than minimum.":null),m(_,"_validateMax",(e,t)=>typeof t.minimum=="number"&&typeof e=="number"&&t.minimum>e?"Maximum cannot be less than minimum.":null);let K=_;const Ge=u.memo(function(i){const[{inputId:e,labelId:t,severity:r,helpText:o,label:a,fieldProps:c},d]=j(i),h=s.useSeverityColor(r),f=c.value?c.value.split("T")[0]:"";return n.jsx(W,{helpText:o,severity:r,children:n.jsx(N,{severity:r,inputId:e,labelId:t,label:a,children:n.jsx(s.TextField.Input,{...d,...c,type:"date",id:e,color:h,value:f})})})}),ee=class ee extends ${constructor(e){super({...e,type:"date"});m(this,"onlyValidateAfterTouched",!1)}serialize(){return super._serialize()}getValueFromChangeEvent(e){return new Date(e.target.value).toISOString()}static deserialize(e){if(e.type!=="date")throw new Error("Type mismatch.");return new ee(e)}getInput(e){return n.jsx(Ge,{field:this,...e})}};m(ee,"fieldTypeName","Date"),m(ee,"fieldTypeDescription","Allows specifying a date."),m(ee,"Icon",s.CalendarIcon);let me=ee;class ge extends ${constructor(e){const{minLength:t,maxLength:r=5e3,...o}=e;super(o);m(this,"minLength");m(this,"maxLength");this.minLength=t?Math.max(t,0):void 0,this.maxLength=r?Math.max(r,0):5e3}static getFieldCreationSchema(){return[new K({label:"Minimum length",description:"Minimum number of characters",required:!1,identifier:"minimum_length",minimum:0,maximum:100,formValidators:[this._validateMin],integers:!0}),new K({label:"Maximum length",description:"Maximum number of characters",required:!1,identifier:"maximum_length",minimum:1,maximum:5e3,formValidators:[this._validateMax],integers:!0})]}getFieldValidators(){const e=super.getFieldValidators();return this.minLength&&e.push(t=>{if(this.minLength&&(!t||t.length<this.minLength))return!this.required&&!t?null:`Minimum ${this.minLength} character(s).`}),this.maxLength&&e.push(t=>{if(typeof t=="string"&&this.maxLength&&t.length>this.maxLength)return`Maximum ${this.maxLength} character(s).`}),e}_serialize(){if(!this.identifier)throw new Error("Field identifier must be set before serializing.");return{...super._serialize(),minimum_length:this.minLength,maximum_length:this.maxLength}}}m(ge,"_validateMin",(e,t)=>typeof t.maximum_length=="number"&&typeof e=="number"&&t.maximum_length<e?"Minimum cannot be greater than maximum.":null),m(ge,"_validateMax",(e,t)=>{if(typeof e!="number")return null;const{minimum_length:r}=t;return typeof r!="number"?null:r>e?"Maximum cannot be less than minimum.":null});const Ke=u.memo(function(i){const[{inputId:e,labelId:t,severity:r,helpText:o,label:a,fieldProps:c,field:d},h]=j(i),f=s.useSeverityColor(r);return n.jsx(W,{helpText:o,severity:r,children:n.jsx(N,{severity:r,inputId:e,labelId:t,label:a,children:n.jsx(s.TextField.Input,{...h,...c,type:d.inputType,id:e,color:f})})})}),te=class te extends ge{constructor(e){const{inputType:t="text",...r}=e,o=e.maxLength?Math.min(500,e.maxLength):500,a=e.minLength?Math.min(e.minLength,o):void 0;super({...r,maxLength:o,minLength:a,type:"string"});m(this,"inputType");this.inputType=t}serialize(){return{...super._serialize(),input_type:this.inputType}}static deserialize(e){if(e.type!=="string")throw new Error("Type mismatch.");const{maximum_length:t,minimum_length:r,input_type:o,...a}=e;return new te({...a,maxLength:t,minLength:r,inputType:o})}getInput(e){return n.jsx(Ke,{field:this,...e})}};m(te,"fieldTypeName","Short Text"),m(te,"fieldTypeDescription","Short text fields can hold up to 500 characters on a single line."),m(te,"Icon",s.InputIcon);let Z=te;const Ye=u.memo(function(i){const[{inputId:e,labelId:t,severity:r,helpText:o,label:a,fieldProps:c},d]=j(i);return n.jsx(W,{helpText:o,severity:r,children:n.jsx(N,{severity:r,inputId:e,labelId:t,label:a,children:n.jsx(s.TextArea,{...d,...c,resize:"vertical",id:e,severity:r})})})}),ie=class ie extends ge{constructor(i){const e=i.maxLength?Math.min(5e3,i.maxLength):5e3,t=i.minLength?Math.min(i.minLength,e):void 0;super({...i,maxLength:e,minLength:t,type:"text"})}serialize(){return super._serialize()}static deserialize(i){if(i.type!=="text")throw new Error("Type mismatch.");const{maximum_length:e,minimum_length:t,...r}=i;return new ie({...r,maxLength:e,minLength:t})}getInput(i){return n.jsx(Ye,{field:this,...i})}};m(ie,"fieldTypeName","Paragraph"),m(ie,"fieldTypeDescription","Paragraph fields can hold up to 5000 characters and can have multiple lines."),m(ie,"Icon",s.RowsIcon);let k=ie;const Qe=u.memo(function(i){const[{inputId:e,labelId:t,severity:r,helpText:o,label:a,fieldProps:c,field:d},h]=j(i),{onChange:f,onBlur:p}=c,g=u.useMemo(()=>d.options.map(v=>({value:v.value,itemContent:v.label})),[d.options]),x=u.useCallback(v=>{f(v),p(v)},[f,p]);return n.jsx(W,{helpText:o,severity:r,children:n.jsx(N,{severity:r,inputId:e,labelId:t,label:a,children:n.jsx(s.Select,{items:g,...c,onValueChange:x,placeholder:"Select one...",id:e,severity:r,...h})})})}),ye=(l="",i=[])=>({type:"section",fields:i,identifier:l,label:null,condition:null,conditional:!1}),mt=l=>{if(!l)return;const i=l.fields;let e=[];const t=[];for(const r of i)r.type==="section"?(e.length>0&&(t.push(ye(`AUTO_section-${i.indexOf(r)}`,e)),e=[]),t.push(r)):e.push(r);return e.length>0&&t.push(ye("AUTO_section-last",e)),{...l,fields:t,description:l.description??""}};function Ee(l,i,e){const t=Array.from(l),[r]=t.splice(i,1);if(!r)throw new Error("Could not find field to reorder.");return t.splice(e,0,r),t}function gt(l,i,e){const t=Array.from(l);return t[i]=e,t}function Xe(l,i,e){const t=Array.from(l??[]);return t.splice(i,0,e),t}function xe(l,i){const e=Array.from(l);return e.splice(i,1),e}const Je=(l,i)=>{if(typeof l=="string"&&l.length>0)return l;const e=new Date;return`${F.slugify(i)}-${e.getTime()}`},Ze=(l,i)=>{if(!i)return null;for(const e of l)if(e.type==="section"){const t=Ze(e.fields,i);if(t)return t}else if(e.identifier===i)return e;return null},ve=(l,i)=>l.filter((e,t)=>t<i).flatMap(e=>e.fields),ke=l=>l.flatMap(i=>i.type==="section"?[...i.fields.map(e=>e.label),i.label]:i.label).filter(i=>i!==null),Me=(l,i)=>{let e=1,t=`${l} (${e})`;for(;i.includes(t);)t=`${l} (${++e})`;return t},Re=u.memo(function(i){const[{inputId:e,labelId:t,severity:r,helpText:o,label:a,fieldProps:c},d]=j(i),h=s.useSeverityColor(r),f=u.useMemo(()=>Array.isArray(c.value)?c.value:[],[c.value]),{onChange:p,onBlur:g}=c,x=`${e}-droppable`,{disabled:v}=d,[I,S]=u.useState(""),[C,w]=u.useState(""),M=C||o,A=C?"red":h,b=u.useCallback(E=>{p(E),g(E)},[p,g]),P=u.useCallback(E=>{f.findIndex(O=>O.value===E.target.value.trim())>=0?w("All options must be unique"):E.target.value?w(""):w("Option cannot be empty"),S(E.target.value)},[S,f]),B=u.useCallback(()=>{if(C)return;if(!I.trim())return w("Option cannot be empty");const E=I.trim();b([...f,{value:E,label:E}]),S("")},[I,C,b,f]),X=u.useCallback(E=>{E.key==="Enter"&&(E.preventDefault(),B())},[B]),U=u.useCallback(E=>{b(xe(f,E))},[f,b]),Y=u.useCallback(E=>{if(!E.destination)return;const O=E.source.index,T=E.destination.index;b(Ee(f,O,T))},[b,f]);return n.jsx(G.DragDropContext,{onDragEnd:Y,children:n.jsxs(s.Flex,{direction:"column",gap:"2",children:[n.jsx(W,{helpText:M,severity:r,children:n.jsx(N,{severity:r,inputId:e,labelId:t,label:a,children:(!v||f.length===0)&&n.jsxs(s.Flex,{gap:"2",children:[n.jsx(s.Box,{grow:"1",children:n.jsx(s.TextField.Input,{placeholder:"Press enter to add a new option",...d,...c,value:I,onChange:P,onKeyDown:X,id:e,color:A,onBlur:void 0})}),n.jsx(s.IconButton,{type:"button","aria-label":"Add option",disabled:!!C||v,onClick:B,children:n.jsx(s.PlusIcon,{})})]})})}),n.jsx(G.Droppable,{droppableId:x,children:E=>n.jsxs(s.Flex,{...E.droppableProps,ref:E.innerRef,direction:"column",children:[f.map((O,T)=>n.jsx(G.Draggable,{draggableId:`${O.value}-draggable`,index:T,isDragDisabled:v,children:({draggableProps:z,dragHandleProps:V,innerRef:L})=>n.jsx(s.Flex,{...V,...z,ref:L,gap:"2",align:"center",justify:"between",mb:"1",asChild:!0,children:n.jsxs(s.Badge,{color:"gray",size:"2",children:[n.jsx("span",{children:O.label}),n.jsx(s.IconButton,{size:"small",variant:"ghost",type:"button","aria-label":"Delete option",severity:"info",disabled:v,onClick:()=>U(T),children:n.jsx(s.Cross1Icon,{})})]})})},O.value)),E.placeholder]})})]})})}),ne=class ne extends ${constructor(e){const{minimum_length:t,maximum_length:r,...o}=e;super({...o,type:"multi-string"});m(this,"minLength");m(this,"maxLength");m(this,"onlyValidateAfterTouched",!1);this.minLength=t??0,this.maxLength=r??1/0}getValueFromChangeEvent(e){if(Array.isArray(e))return e;throw new Error("Expected an array.")}getInput(e){return n.jsx(Re,{field:this,...e})}serialize(){return{...super._serialize(),minimum_length:this.minLength,maximum_length:this.maxLength}}isBlank(e){return super.isBlank(e)||e.length===0}getFieldValidators(){const e=super.getFieldValidators();return e.push(t=>{if(Array.isArray(t)&&t.length<this.minLength)return`Must have at least ${this.minLength} options.`}),e.push(t=>{if(Array.isArray(t)&&t.length>this.maxLength)return`Must have at most ${this.maxLength} options.`}),e}static deserialize(e){if(e.type!=="multi-string")throw new Error("Type mismatch.");return new ne(e)}};m(ne,"fieldTypeName","Multi-string"),m(ne,"fieldTypeDescription","Allows the user to provide multiple unique strings."),m(ne,"Icon",s.ListBulletIcon);let ae=ne;class et extends ${constructor(e){super(e);m(this,"options");m(this,"onlyValidateAfterTouched",!1);const t=new Set;this.options=e.options.map(r=>(typeof r=="string"&&(r={label:r,value:r}),t.add(r.label),r)),t.size!==e.options.length&&console.error(`${e.options.length-t.size} duplicate identifiers found in options. This may cause unexpected behavior. Options:`,e.options)}_serialize(){return{...super._serialize(),options:this.options}}static getFieldCreationSchema(){return[new ae({label:"Options",description:"List possible options for the user to select from.",required:!0,identifier:"options",minimum_length:2,maximum_length:20})]}}const re=class re extends et{constructor(i){super({...i,type:"select"})}getValueFromChangeEvent(i){return typeof i=="string"?i:i.target.value}serialize(){return super._serialize()}static deserialize(i){if(i.type!=="select")throw new Error("Type mismatch.");return new re(i)}getInput(i){return n.jsx(Qe,{field:this,...i})}};m(re,"fieldTypeName","Dropdown"),m(re,"fieldTypeDescription","Allows the user to select a single option from a list of options."),m(re,"Icon",s.DropdownMenuIcon);let de=re;const yt=l=>l?Array.isArray(l)?l:[l]:[],tt=u.memo(function(i){const[{inputId:e,labelId:t,severity:r,helpText:o,label:a,fieldProps:c,field:d},h]=j(i),{onChange:f,onBlur:p}=c,g=u.useMemo(()=>yt(c.value),[c.value]),x=u.useCallback(v=>{f(v),p(v)},[f,p]);return n.jsx(W,{helpText:o,severity:r,children:n.jsx(N,{severity:r,inputId:e,labelId:t,label:a,children:n.jsx(s.MultiSelect,{value:g,onValueChange:x,options:d.options,name:c.name,placeholder:"Select one or more...",id:e,severity:r,...h})})})}),se=class se extends et{constructor(i){super({...i,type:"multi-select"})}getValueFromChangeEvent(i){if(Array.isArray(i))return i;throw new Error("Expected an array.")}isBlank(i){return super.isBlank(i)||i.length===0}serialize(){return super._serialize()}static deserialize(i){if(i.type!=="multi-select")throw new Error("Type mismatch.");return new se(i)}getInput(i){return n.jsx(tt,{field:this,...i})}};m(se,"fieldTypeName","Multi-select"),m(se,"fieldTypeDescription","Allows the user to select a multiple options from a list of options."),m(se,"Icon",s.CheckboxIcon);let ce=se;const xt=u.memo(function({field:i,...e}){const[{value:t}]=D.useField(i.options.clonedFieldIdentifier),r=u.useMemo(()=>{const o=i.options.getFieldToClone(t);return o?ue(o):null},[i.options,t]);return fe(r,e)});class we extends ${constructor(e,t){super({...e,type:"custom"});m(this,"Component");m(this,"options");this.options=e,this.Component=t}serialize(){throw new Error("Serializing only supported for public input types.")}getInput(e){const t=this.Component;return n.jsx(t,{field:this,...e})}}m(we,"fieldTypeName","Custom"),m(we,"fieldTypeDescription","Allows re-rendering of field already in the form");class vt extends we{constructor(i){super(i,xt)}}const wt=u.memo(function(i){const{field:e,...t}=i,{label:r,description:o,fields:a,condition:c}=e,{values:d,setFieldValue:h}=D.useFormikContext(),f=c!=null&&c.identifier?J(d,c.identifier):void 0,p=u.useMemo(()=>$e(c,f),[c,f]);u.useEffect(()=>{if(!p)for(const x of a)h(x.getId(),"").then()},[p,a,h]);const g=Be(a,t);return p?r?n.jsx(s.Card,{children:n.jsxs(s.Flex,{direction:"column",gap:"3",children:[n.jsxs(s.Flex,{direction:"column",children:[n.jsx(s.Heading,{as:"h3",size:"3",children:r}),n.jsx(s.Text,{className:he.description,children:o})]}),g]})}):g:null}),oe=class oe extends je{constructor(e){const{label:t=null,fields:r,condition:o=null,conditional:a,...c}=e;super({...c,type:"section"});m(this,"label");m(this,"fields");m(this,"condition");this.fields=r,this.condition=o,this.label=t,a===!1&&(this.condition=null)}static getFieldCreationSchema(e){return e.length===0?[]:[new Q({label:"Conditional",description:"Conditionally show or hide this section.",identifier:"conditional",required:!1}),new oe({label:"Conditional settings",identifier:"conditional-settings",condition:{identifier:"conditional",value:!0},fields:[new de({label:"Field",description:"The field to use for the condition.",options:e.map(t=>!t.label||t.type==="upload"?null:{label:t.label,value:t.identifier}).filter(t=>!!t),identifier:"condition.identifier",required:!0}),new vt({label:"Value",identifier:"condition.value",required:!0,clonedFieldIdentifier:"condition.identifier",getFieldToClone(t){if(!t)return null;const r=e.find(o=>o.identifier===t);return r?{...r,label:"Value",identifier:"condition.value",description:"The value to compare against.",required:r.type!=="boolean"}:(console.error("Could not find field with identifier",t),null)}})]})]}static deserialize(e){var r;if(e.type!=="section")throw new Error("Invalid type");const t=((r=e.fields)==null?void 0:r.map(De))??[];return new oe({...e,fields:t})}conditional(){return this.condition!==null}serialize(){return{...super._serialize(),label:this.label,condition:this.condition,conditional:this.conditional(),fields:this.fields.map(e=>e.serialize())}}getErrors(e){const t={};for(const r of this.fields){const o=r.getId(),a=r.getError(J(e,o),e);a&&ze(t,r.getId(),a)}return t}getInput(e){return n.jsx(wt,{field:this,...e})}};m(oe,"fieldTypeName","Section"),m(oe,"fieldTypeDescription","Sections can be useful for grouping fields together. They can also be conditionally shown or hidden.");let H=oe;const Ft={previewImage:"_previewImage_1ig84_1"},Ae=l=>{const i=["byte","kilobyte","megabyte"];let e=l,t=0;for(;e>1024&&t<i.length-1;)e/=1024,t++;return new Intl.NumberFormat([],{maximumFractionDigits:2,style:"unit",unit:i[t]}).format(e)},It=u.memo(function(i){var A;const[{inputId:e,labelId:t,severity:r,helpText:o,label:a,fieldProps:c,field:d},h]=j(i),{onChange:f}=c,p=s.useSeverityColor(r),g=u.useRef(null),{value:x}=c,v=u.useMemo(()=>o||(d.maxFileSize?`Maximum file size: ${Ae(d.maxFileSize)}`:null),[d.maxFileSize,o]),I=u.useCallback(()=>{var b;(b=g.current)==null||b.click()},[]),S=u.useCallback(b=>{const P=[...x];P.splice(b,1),f({target:{files:P}})},[x,f]),C=x?"Select new files":"Select files",w=x?"Select new file":"Select a file",M=d.maxFiles>1?C:w;return n.jsxs(s.Flex,{direction:"column",gap:"2",children:[n.jsx(W,{helpText:v,severity:r,children:n.jsxs(N,{severity:r,inputId:e,labelId:t,label:a,children:[n.jsx(s.Flex,{direction:"row",gap:"2",children:n.jsx(s.Box,{width:"max-content",asChild:!0,children:n.jsxs(s.Button,{...h,onClick:I,children:[n.jsx(s.UploadIcon,{})," ",M]})})}),n.jsx("input",{...h,type:"file",ref:g,id:e,accept:(A=d.extensions)==null?void 0:A.join(","),multiple:d.maxFiles>1,color:p,style:{display:"none"},...c,value:""})]})}),Array.isArray(x)&&x.length>0&&n.jsx(s.Flex,{direction:"column",gap:"2",children:x.map((b,P)=>n.jsx(bt,{field:d,file:b,onRemove:()=>S(P),disabled:h.disabled},P))})]})}),bt=u.memo(function({file:i,field:e,onRemove:t,disabled:r}){const[o,a]=u.useState(null),c=u.useMemo(()=>o&&e.getError([o]),[e,o]),{url:d,name:h,size:f}=u.useMemo(()=>{let p=null,g,x;return o!=null&&o.type.startsWith("image/")&&(p=URL.createObjectURL(o)),o?(g=o.name,x=Ae(o.size)):(g="Downloading...",x="..."),{url:p,name:g,size:x}},[o]);return u.useEffect(()=>{i instanceof Promise?i.then(a):a(i)},[i]),n.jsx(s.Card,{children:n.jsxs(s.Flex,{direction:{initial:"column",sm:"row"},gap:"3",justify:"between",children:[n.jsxs(s.Flex,{direction:"row",gap:"3",align:"center",grow:"1",shrink:"0",children:[n.jsx(s.IconButton,{severity:"info",variant:"outline","aria-label":`Remove ${h}`,disabled:r,onClick:t,children:n.jsx(s.Cross1Icon,{})}),n.jsxs(s.Flex,{direction:"column",gap:"1",children:[n.jsx(s.Text,{children:h}),n.jsx(s.Text,{size:"1",children:f}),c&&n.jsx(s.Text,{size:"1",severity:"danger",children:c})]})]}),d&&n.jsx("img",{className:Ft.previewImage,src:d,alt:h})]})})}),it=50*1024*1024,le=class le extends ${constructor(e){const{extensions:t,maximum_files:r,maximum_size:o,...a}=e;super({...a,type:"upload"});m(this,"extensions");m(this,"maxFileSize");m(this,"maxFiles");m(this,"onlyValidateAfterTouched",!1);this.maxFileSize=typeof o=="number"?o:void 0,this.maxFiles=Math.max(typeof r=="number"?r:1,1),this.extensions=t}getValueFromChangeEvent(e){return Array.from(e.target.files||[])}isBlank(e){return super.isBlank(e)||e.length===0}static getFieldCreationSchema(){return[new K({label:"How many files can be uploaded?",description:"By default, only one file can be uploaded.",required:!1,minimum:1,maximum:10,identifier:"maximum_files"}),new K({label:"What is the maximum size of each file?",description:"Maximum file size in bytes.",required:!1,identifier:"maximum_size",minimum:1,maximum:it,integers:!0}),new ce({label:"Accepted file types",description:"Types of allowed files to upload. If left blank, all files will be accepted.",required:!1,identifier:"extensions",options:[{value:"image/*",label:"Images"},{value:"audio/*",label:"Audio files"},{value:"video/*",label:"Videos"},{value:"text/*",label:"Text files"},{value:"application/*",label:"Application files (includes PDFs and Word documents)"}]})]}getFieldValidators(){const e=super.getFieldValidators(),t=this.maxFileSize??it,r=this.maxFiles??1;return e.push(o=>{if(o&&o.some(a=>a.size>t))return`Files must be at most ${Ae(t)}.`}),e.push(o=>{if(o&&o.length>r)return`You can only upload ${r} files.`}),e}serialize(){return{...super._serialize(),extensions:this.extensions,maximum_size:this.maxFileSize,maximum_files:this.maxFiles}}static deserialize(e){if(e.type!=="upload")throw new Error("Type mismatch.");return new le(e)}getInput(e){return n.jsx(It,{field:this,...e})}};m(le,"fieldTypeName","Upload"),m(le,"fieldTypeDescription","Allows a file to be uploaded."),m(le,"Icon",s.UploadIcon);let Pe=le;const Le={date:me,number:K,boolean:Q,select:de,string:Z,text:k,custom:we,upload:Pe,"multi-string":ae,"multi-select":ce},De=l=>{const i=l.type;return Le[i].deserialize(l)},ue=l=>l.type==="section"?H.deserialize(l):De(l);function Ve(l,i={}){const{readonly:e=!1}=i;return{title:l.title,description:l.description,fields:l.fields.map(t=>ue(t)),meta:{readonly:e}}}function Fe(l){return!!(Array.isArray(l)&&l.some(i=>i instanceof File||i instanceof Promise))}function $e(l,i){if(!l)return!0;if(Fe(i)||Fe(l.value))throw new Error("Conditions do not support file uploads");const e=Array.isArray(i)?i.map(r=>typeof r=="string"?r:r.value):i,t=Array.isArray(l.value)?l.value.map(r=>typeof r=="string"?r:r.value):l.value;if(Array.isArray(t)&&Array.isArray(e)){for(const r of t)if(!e.includes(r))return!1;return!0}return t===i}const fe=(l,i)=>u.useMemo(()=>!i||!l?null:l.getInput(i),[l,i]),Be=(l,i)=>{const e=u.useMemo(()=>l.map(t=>n.jsx("div",{children:t.getInput(i)},t.getId())),[l,i]);return n.jsx(s.Flex,{direction:"column",gap:"2",children:e})},Ie=l=>Object.keys(l).length>0,nt=async(l,i)=>{const e={};for(const t of l.fields)if(t instanceof H){if(t.condition){const{identifier:r}=t.condition;if(!$e(t.condition,J(i,r)))continue}Object.assign(e,t.getErrors(i))}else{if(!(t instanceof $))throw new Error("Invalid field type");const r=t.getId(),o=t.getError(J(i,r),i);o&&ze(e,r,o)}if(Ie(e))return e},Ct=[null,void 0],_e=(l,i)=>l.reduce((e,t)=>t instanceof H?{...e,..._e(t.fields,i)}:(Ct.includes(J(e,t.getId()))&&ze(e,t.getId(),""),e),i),Tt=()=>{throw new Error("onSubmit must be provided if form is not readonly.")},be=u.memo(u.forwardRef((l,i)=>{const{schema:e,values:t={},onSubmit:r=Tt,submitText:o="Submit",cancelText:a,onCancel:c,onDirty:d,hideTitle:h=!e.title,hideDescription:f,className:p}=l,{readonly:g}=e.meta,x=u.useMemo(()=>crypto.randomUUID(),[]),v=D.useFormik({initialValues:_e(e.fields,t),onSubmit:r,validate:M=>nt(e,M),validateOnBlur:!1,validateOnChange:!1}),{dirty:I}=v,S=u.useMemo(()=>typeof e.title=="string"?n.jsx(s.Heading,{children:e.title}):e.title,[e.title]),C=u.useMemo(()=>typeof e.description=="string"?n.jsx(s.Text,{className:he.description,children:e.description}):e.description,[e.description]),w=Be(e.fields,{formId:x,disabled:g});return u.useEffect(()=>{I&&d&&d()},[I,d]),n.jsx(D.FormikProvider,{value:v,children:n.jsx(s.Flex,{ref:i,direction:"column",gap:"2",className:p,asChild:!0,children:n.jsxs("form",{id:x,onSubmit:v.handleSubmit,children:[!h&&n.jsx(s.Card,{children:n.jsxs(s.Flex,{direction:"column",gap:"1",children:[S,!f&&C]})}),w,!g&&n.jsxs(s.Flex,{justify:"end",gap:"2",children:[a&&n.jsx(s.Button,{type:"button",variant:"soft",onClick:c,children:a}),n.jsx(s.Button,{type:"submit",disabled:!v.isValid,children:o})]})]})})})})),St=u.memo(u.forwardRef((l,i)=>{const{submission:e,showFormDescription:t=!1,showFormTitle:r=!0}=l,o=F.useAppSelector(F.selectFormRevision(e.form_revision)),{sdk:a}=F.useSDK();if(!o)throw new Error(`Could not find revision ${e.form_revision} for submission ${e.offline_id}.`);const c=u.useMemo(()=>Ve(o,{readonly:!0}),[o]),d=u.useMemo(()=>{const h=F.selectSubmissionAttachments(e.offline_id)(a.store.getState())??[],f={};for(const p of h){const g=a.files.fetchFileFromUrl(p.file,p.file_sha1,p.file_name).then(v=>{if(!v.success)throw new Error(`Failed to download attachment ${p.file_name}.`);return v.body}),x=f[p.field_identifier];x?x.push(g):f[p.field_identifier]=[g]}return{...e.values,...f}},[a.files,a.store,e.offline_id,e.values]);return n.jsx(be,{ref:i,schema:c,values:d,hideDescription:!t,hideTitle:!r})})),rt={favoriteIcon:"_favoriteIcon_1bixi_1",regularIcon:"_regularIcon_1bixi_9"},Oe="organization:",qe="user:",zt=u.memo(u.forwardRef((l,i)=>{const{maxResults:e=20,...t}=l,[r,o]=u.useState(""),[a,c]=u.useState(""),{sdk:d}=F.useSDK(),h=u.useMemo(()=>{const w={maxResults:e,searchTerm:r};return a&&(a.startsWith(Oe)?w.owner_organization=parseInt(a.slice(Oe.length)):a.startsWith(qe)&&(w.owner_user=parseInt(a.slice(qe.length)))),w},[r,e,a]),f=F.useAppSelector(F.selectFilteredUserForms(h))??[],p=F.useAppSelector(F.selectUserFormMapping),g=u.useCallback(w=>{w.favorite?d.userForms.unfavorite(w.offline_id).then():d.userForms.favorite(w.offline_id).then()},[d]),x=u.useMemo(()=>{const w=d.store.getState(),M={};for(const A of Object.values(p)){const b=F.selectOrganization(A.owner_organization||-1)(w);b&&(M[`${Oe}${b.id}`]=b.name);const P=F.selectUser(A.owner_user||-1)(w);P&&(M[`${qe}${P.id}`]=P.username)}return Object.entries(M).map(([A,b])=>({itemContent:b,value:A}))},[p,d.store]),v=u.useCallback(w=>{o(w.currentTarget.value)},[]),S=(F.useAppSelector(F.selectNumberOfUserForms)||0)-f.length,C=f.length==e&&S>0?`Only the first ${e} results are shown (${S} hidden)`:S>0&&`${S} hidden forms`;return n.jsxs(s.Flex,{ref:i,direction:"column",gap:"2",children:[n.jsxs(s.Flex,{gap:"2",grow:"1",children:[n.jsx(s.Box,{grow:"1",asChild:!0,children:n.jsx(s.TextField.Root,{size:"3",children:n.jsx(s.TextField.Input,{placeholder:"Filter",value:r,onChange:v})})}),n.jsx(s.Select,{items:x,value:a,onValueChange:c,placeholder:"Owner",size:"large"})]}),f.length>0&&n.jsx(s.ButtonList.Root,{children:f.map(w=>n.jsx(Et,{...t,form:w,handleToggleFavorite:()=>g(w)},w.offline_id))}),n.jsx(s.Box,{px:"3",children:n.jsx(s.Text,{size:"2",severity:"info",children:C})})]})})),Et=l=>{var g;const{form:i,onSelectForm:e,isFavoriteEditable:t,handleToggleFavorite:r}=l,o=(g=F.useAppSelector(F.selectOrganization(i.owner_organization||-1)))==null?void 0:g.name,a=F.useAppSelector(F.selectUser(i.owner_user||-1)),c=F.useAppSelector(F.selectCurrentUser).id,d=!!a&&a.id===c,h=o??(d?"You":a==null?void 0:a.username)??"Unknown",f=u.useCallback(x=>{x.stopPropagation(),r()},[r]),p=n.jsx(s.ButtonList.Item,{onClick:()=>e(i),asChild:!0,children:n.jsxs(s.Flex,{justify:"between",gap:"2",py:"2",px:"3",...s.divButtonProps,children:[n.jsxs(s.Flex,{grow:"1",align:"center",gap:"2",children:[n.jsx(s.IconButton,{className:F.classNames(i.favorite?rt.favoriteIcon:rt.regularIcon),variant:"ghost",onClick:f,"aria-label":i.favorite?"Favorite form":"Standard form",disabled:!t,children:i.favorite?n.jsx(s.StarFilledIcon,{}):n.jsx(s.StarIcon,{})}),n.jsx(s.Text,{noWrap:!0,children:i.latestRevision.title}),i.latestRevision.description&&n.jsx(s.QuestionMarkCircledIcon,{})]}),h&&n.jsxs(s.Flex,{align:"center",gap:"2",children:[n.jsx(s.PersonIcon,{})," ",h]})]})});return i.latestRevision.description?n.jsx(s.Tooltip,{content:i.latestRevision.description,children:p},i.offline_id):p},st={submissionsContainer:"_submissionsContainer_9iirt_1",stopHorizontalOverflow:"_stopHorizontalOverflow_9iirt_6"},Mt=u.memo(function(i){var w;const{submission:e,onSubmissionClick:t,compact:r,labelType:o,rowDecorator:a}=i,c=F.useAppSelector(F.selectCurrentUser),d=F.useAppSelector(F.selectUser("created_by"in e?e.created_by:c.id)),h=Ne(e),f=F.isToday(h)?h.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):F.getLocalDateString(h),p=F.useAppSelector(F.selectFormRevision(e.form_revision));if(!p)throw new Error(`Could not find revision ${e.form_revision} for submission ${e.offline_id}.`);const g=(w=F.useAppSelector(F.selectLatestFormRevision(p.form)))==null?void 0:w.revision,x=F.useFileSrc({file:(d==null?void 0:d.profile.file)??null,fileSha1:(d==null?void 0:d.profile.file_sha1)??null}),v=(d==null?void 0:d.username.charAt(0).toUpperCase())??"?",I=p.revision===g,S=u.useCallback(()=>{t&&t({submission:e})},[e,t]),C=n.jsx(s.ButtonList.Item,{onClick:S,asChild:!0,children:n.jsxs(s.Flex,{grow:"1",width:"100%",p:"2",gap:"2",justify:"between",children:[n.jsxs(s.Flex,{gap:"2",align:"center",className:st.stopHorizontalOverflow,children:[n.jsx(s.Avatar,{src:x,size:"1",fallback:v}),n.jsx(s.Text,{size:"2",noWrap:!0,children:o==="creator"?(d||c).username:p.title})]}),n.jsxs(s.Flex,{gap:"2",align:"center",children:[!r&&(p.revision?n.jsx(s.Badge,{variant:"soft",severity:I?"primary":"info",children:r?p.revision.toString():`Revision #${p.revision}`}):!!g&&n.jsx(s.Badge,{children:"Original"})),n.jsx(s.Text,{size:"2",noWrap:!0,children:f})]})]})});return a?a(e,C):C}),Ne=l=>{const i="created_at"in l?l.created_at:l.submitted_at;return new Date(i)},At=u.memo(function(i){const{formId:e,submissions:t,compact:r=!1,className:o,after:a,variant:c="outline",...d}=i;if(!!e==!!t)throw new Error("Either formId or submissions must be provided, but not both.");const h=F.useAppSelector(t?()=>t:F.selectSubmissionsForForm(e)),f=u.useMemo(()=>h==null?void 0:h.sort((p,g)=>Ne(g).getTime()-Ne(p).getTime()),[h]);return n.jsx(s.ButtonList.Root,{className:F.classNames(st.submissionsContainer,o),size:"small",variant:c,before:!r&&n.jsxs(s.Text,{severity:"info",children:["There are ",((h==null?void 0:h.length)||0).toString()," submissions of this form."]}),after:a,children:f==null?void 0:f.map((p,g)=>n.jsx(Mt,{submission:p,compact:r,...d},g))})}),Pt=u.memo(function(i){const{name:e,render:t}=i,{submitForm:r}=D.useFormikContext(),[o,a,c]=D.useField(e);return u.useMemo(()=>{const d=h=>c.setValue(h,!1);return t({value:o.value,setValue:d,patchValue:r})},[r,c,o.value,t])}),Lt=u.memo(u.forwardRef((l,i)=>{const{children:e,schema:t,values:r,onPatch:o,onError:a,...c}=l,d=u.useMemo(()=>_e(t.fields,r),[t.fields,r]),h=u.useCallback(v=>{const I={};for(const S in v){const C=v[S];C!==d[S]&&C!==void 0&&(I[S]=C)}Ie(I)&&o(I)},[d,o]),f=u.useCallback(async v=>{const I=await nt(t,v);return I&&a(I),I},[t,a]),p=D.useFormik({initialValues:d,onSubmit:h,validate:f,validateOnBlur:!1,validateOnChange:!1}),{errors:g,resetForm:x}=p;return u.useEffect(()=>{Ie(g)&&x({values:d,errors:{}})},[g,d,x]),n.jsx(D.FormikProvider,{value:p,children:n.jsx("form",{...c,ref:i,onSubmit:p.handleSubmit,children:e})})})),ot={...Le,section:H},Dt=u.memo(function(i){const{field:e,setFieldType:t}=i,r=e.fieldTypeName,o=e.fieldTypeDescription,a=e.Icon;return n.jsxs(s.Flex,{gap:"4",align:"center",children:[n.jsx(s.Button,{type:"button",variant:"surface",onClick:t,style:{width:"135px"},children:n.jsxs(s.Flex,{gap:"3",align:"center",grow:"1",children:[n.jsx(a,{}),r]})}),n.jsx(s.Text,{children:o})]})}),lt=[["string","text"],["select","multi-select","upload"],["boolean","date","number","multi-string"]],Vt=lt.length-1,$t=u.memo(function(i){const{setFieldType:e}=i;return n.jsx(s.Flex,{direction:"column",gap:"3",children:lt.map((t,r)=>n.jsxs(s.Flex,{direction:"column",gap:"3",children:[n.jsx(s.Flex,{direction:"column",gap:"2",children:t.map(o=>n.jsx(Dt,{field:Le[o],setFieldType:()=>e(o)},o))}),r<Vt&&n.jsx(s.Separator,{size:"4"})]},r))})}),Bt=l=>i=>{if(console.log("in validate",l,i),!(!i||typeof i!="string")&&l.includes(i.trim()))return"This name is already taken."},_t=(l,i)=>{const e=[new Z({label:"Label",required:!0,maxLength:200,identifier:"label",fieldValidators:[Bt(l)]}),new k({label:"Description",required:!1,maxLength:1e3,identifier:"description"})];return i==="section"?e:[...e,new Q({label:"Required",description:null,required:!1,identifier:"required"})]},Ot=u.memo(function(i){const{fieldType:e,handleCancel:t,handleCreateField:r,defaultField:o,conditionalSourceFields:a}=i,c=ot[e];console.log("default field",o);const d=D.useFormikContext(),h=u.useMemo(()=>{const f=ke(d.values.fields).filter(g=>g!==(o==null?void 0:o.label));let p=_t(f,e);if(console.log("first set of errors",c,H,a),c===H){if(a===void 0)throw new Error("Conditional source fields must be provided when changing sections.");p=p.concat(c.getFieldCreationSchema(a))}else{if(!(c.prototype instanceof $))throw console.log("badinstance"),new Error(`Field must be an instance of BaseField. Got ${c}.`);p=[...p,...c.getFieldCreationSchema()]}return{fields:p,meta:{readonly:!1},title:null}},[d.values.fields,e,c,o==null?void 0:o.label,a]);return n.jsx(be,{schema:h,values:o,onSubmit:r,cancelText:o?void 0:"Back",onCancel:t})}),pe=u.memo(function(i){const{parentPath:e,index:t,children:r,initial:o,editing:a,conditionalSourceFields:c}=i,[d,h]=u.useState(),f=(o==null?void 0:o.type)??d,p=f?ot[f].fieldTypeName:void 0,{setFieldValue:g,values:x}=D.useFormikContext();if(a&&!o)throw new Error("Initial field must be provided if editing is true.");const v=!f&&!a&&!o,I=v?"Choose a field type":`${p} settings`,S=v?"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.`,C=u.useCallback(()=>h(void 0),[]),w=u.useCallback(b=>{h(void 0),b()},[]),M=u.useCallback((b,P)=>{const{label:B}=b;if(!f)throw new Error("Field type must be selected before creating a field.");if(!B||typeof B!="string")throw new Error("Label must be provided before creating a field.");const X=ue({type:f,...b,identifier:Je(b.identifier,B)}).serialize(),U=J(x,e);if(U===void 0)throw new Error("Parent path must point to an existing field.");let Y;if(!Array.isArray(U))throw new Error("Parent path must point to an array.");a?Y=gt(U,t,X):Y=Xe(U,t,X),g(e,Y).then(),P()},[a,f,x,e,g,t]),A=u.useCallback(b=>v?n.jsx($t,{setFieldType:h}):n.jsx(Ot,{conditionalSourceFields:c,handleCancel:C,handleCreateField:P=>M(P,b),fieldType:f,defaultField:o}),[c,C,M,o,v,f]);return n.jsx(s.Dialog,{onCloseInterrupt:w,title:I,description:S,content:A,children:r})}),at=({children:l})=>n.jsx(n.Fragment,{children:l}),dt=(l,i)=>({initial:l?i:"none",sm:l?"none":i}),ct=u.memo(function(i){const{remove:e,dragHandleProps:t,editProps:r,insertAfterProps:o,duplicateProps:a}=i,c=u.useMemo(()=>[{Wrapper:pe,wrapperProps:r,Icon:s.Pencil1Icon,text:"Edit"},{Icon:s.TrashIcon,buttonProps:{onClick:e},text:"Delete"},{Wrapper:pe,wrapperProps:a,Icon:s.CopyIcon,text:"Duplicate"},{Wrapper:pe,wrapperProps:o,Icon:s.PlusIcon,text:"Add after"},{Icon:d=>n.jsx("div",{...d,children:n.jsx(s.DragHandleDots2Icon,{})}),text:"Reorder",disableOnMobile:!0,buttonProps:{...t,asChild:!0}}],[t,a,r,o,e]);return n.jsxs(n.Fragment,{children:[n.jsx(s.Flex,{gap:"4",display:dt(!1,"flex"),children:c.map(d=>{const h=d.Wrapper??at;return n.jsx(h,{...d.wrapperProps,children:n.jsx(s.IconButton,{type:"button",variant:"ghost","aria-label":d.text,...d.buttonProps,children:n.jsx(d.Icon,{})})},d.text)})}),n.jsx(s.Box,{display:dt(!0,"block"),children:n.jsx(s.DropdownMenu,{trigger:n.jsx(s.IconButton,{variant:"ghost","aria-label":"Actions menu",children:n.jsx(s.DotsVerticalIcon,{})}),closeOnSelect:!1,items:c.map(d=>{var f;if(d.disableOnMobile)return null;const h=d.Wrapper??at;return{...d.buttonProps,onSelect:(f=d.buttonProps)==null?void 0:f.onClick,content:n.jsx(h,{...d.wrapperProps,children:n.jsxs(s.Flex,{gap:"2",align:"center",children:[n.jsx(d.Icon,{}),d.text]})})}}).filter(d=>d!==null)})})]})}),Ce="form-builder",qt=u.memo(function(i){const{field:e,index:t,sectionIndex:r,takenLabels:o,remove:a}=i,c=u.useMemo(()=>ue(e),[e]),d=fe(c,{formId:Ce,disabled:!0});console.log(e,t,r,c);const h=u.useMemo(()=>({index:t,parentPath:`fields.${r}.fields`,initial:e,editing:!0}),[e,t,r]),f=u.useMemo(()=>({parentPath:`fields.${r}.fields`,index:t+1,initial:{...e,label:Me(e.label??"",o),identifier:""}}),[e,t,r,o]),p=u.useMemo(()=>({parentPath:`fields.${r}.fields`,index:t+1,initial:void 0}),[t,r]);return n.jsx(G.Draggable,{draggableId:e.identifier,index:t,children:g=>n.jsx(s.Card,{ref:g.innerRef,...g.draggableProps,...g.dragHandleProps,mb:"4",children:n.jsxs(s.Flex,{gap:"4",justify:"between",align:"center",children:[d,n.jsx(ct,{remove:a,editProps:h,duplicateProps:f,insertAfterProps:p,dragHandleProps:g.dragHandleProps})]})})})}),Nt=u.memo(function(i){var P,B,X,U,Y,E,O;const{field:e,index:t,dropState:r}=i,o=(P=r[e.identifier])==null?void 0:P.disabled,{setFieldValue:a,values:c}=D.useFormikContext(),d=s.useAlertDialog(),h=ke(c.fields);console.log("field section",e,t,c);const f=u.useCallback((T,z)=>{for(const V of T){const L=z.indexOf(V);a(`fields.${L}.condition`,null).then(),a(`fields.${L}.conditional`,!1).then()}},[a]),p=u.useCallback(T=>{var L;const z=e.fields[T];if(!z)throw new Error("Could not find field to remove.");const V=[];for(const q of c.fields)((L=q.condition)==null?void 0:L.identifier)===z.identifier&&V.push(q);return{removing:z,affectedSections:V,action:()=>a(`fields.${t}.fields`,xe(e.fields,T))}},[e.fields,c.fields,a,t]),g=u.useCallback(T=>{const{affectedSections:z,action:V,removing:L}=p(T),q=()=>{V().then(),f(z,c.fields)};if(z.length>0){const We=z.map(Te=>Te.label).join(", ");return d({title:"Remove condition?",description:`${L.label} is being used as a condition, deleting it will remove the condition from the ${We} section(s).`,severity:"danger",actionText:"Remove",onAction:q})}q()},[p,f,c.fields,d]),x=u.useCallback(()=>{const z=e.fields.map((Se,Zt)=>p(Zt)).flatMap(Se=>Se.affectedSections),V=z.length?"Remove fields and conditions?":"Remove fields?",L=e.fields.length,q=z.map(Se=>Se.label).join(", "),We=z.length?`Deleting this section will remove the ${L} field(s) it contains and will remove the conditions from following sections: ${q}`:`Deleting this section will remove the ${L} field(s) it contains.`,Te=xe(c.fields,t),pt=()=>a("fields",Te);if(z.length>0)return d({title:V,description:We,severity:"danger",actionText:"Remove",onAction:()=>{pt().then(()=>{f(z,Te)})}});pt().then()},[e.fields,c.fields,t,p,a,d,f]),v=u.useCallback(T=>{const z=Me(T.label??"",h),V=T.fields.map(L=>{const q=Me(L.label,h);return{...L,label:q,identifier:Je(void 0,q)}});return{...T,label:z,fields:V,identifier:""}},[h]),I=u.useMemo(()=>({index:t,parentPath:"fields",initial:e,editing:!0,conditionalSourceFields:ve(c.fields,t)}),[e,t,c.fields]),S=u.useMemo(()=>({index:t+1,parentPath:"fields",initial:ye(),conditionalSourceFields:ve(c.fields,t+1)}),[t,c.fields]),C=u.useMemo(()=>({parentPath:`fields.${t}.fields`,index:e.fields.length,initial:void 0}),[e.fields.length,t]),w=u.useMemo(()=>({index:t+1,parentPath:"fields",initial:v(e),conditionalSourceFields:ve(c.fields,t+1)}),[v,e,t,c.fields]),M=u.useMemo(()=>{var T,z;return(z=Ze(c.fields,(T=e.condition)==null?void 0:T.identifier))==null?void 0:z.label},[(B=e.condition)==null?void 0:B.identifier,c.fields]),A=Array.isArray((X=e.condition)==null?void 0:X.value)?"contains all of":"equals";if(Fe((U=e.condition)==null?void 0:U.value))throw new Error("File values are not supported for conditions.");const b=Array.isArray((Y=e.condition)==null?void 0:Y.value)?(E=e.condition)==null?void 0:E.value.map(T=>typeof T=="string"?T:T.label).join(", "):(O=e.condition)==null?void 0:O.value.toString();return n.jsx(G.Draggable,{draggableId:e.identifier,index:t,children:T=>n.jsx(s.Card,{ref:T.innerRef,...T.draggableProps,...T.dragHandleProps,mb:"4",children:n.jsxs(s.Flex,{gap:"3",justify:"between",align:"center",children:[n.jsxs(s.Flex,{direction:"column",gap:"2",grow:"1",children:[n.jsxs(s.Flex,{direction:"column",children:[n.jsx(s.Heading,{as:"h3",size:"3",children:e.label}),n.jsx(s.Text,{className:he.description,children:e.description})]}),e.condition&&n.jsx(s.Text,{size:"1",children:n.jsxs(s.Em,{children:["Display only if ",n.jsx(s.Strong,{children:M})," ",A," ",n.jsx(s.Strong,{children:b})]})}),n.jsx(G.Droppable,{droppableId:e.identifier,type:"SECTION",isDropDisabled:o,children:z=>n.jsxs(s.Flex,{ref:z.innerRef,...z.droppableProps,direction:"column",gap:"0",children:[e.fields.map((V,L)=>n.jsx(qt,{field:V,index:L,sectionIndex:t,remove:()=>g(L),takenLabels:h},V.identifier)),z.placeholder,n.jsx(pe,{...C,children:n.jsxs(s.Button,{type:"button",variant:"outline",children:[n.jsx(s.PlusIcon,{})," Add a field"]})})]})})]}),n.jsx(ct,{remove:x,insertAfterProps:S,dragHandleProps:T.dragHandleProps,editProps:I,duplicateProps:w})]})})})}),Wt=(l,i)=>{var t;const e={...l};switch(i.type){case"release":for(const r in e)e[r].disabled=!1;return e;case"hold":for(const r in e)(t=e[r])!=null&&t.conditionFields.has(i.fieldId)&&(e[r].disabled=!0);return e;case"update":return i.state}},jt=(l,i)=>{if(i)for(let e=0;e<l.length;e++){const t=l[e];if(t){for(const r of t.fields)if(r.identifier===i)return e}}},ut=l=>{var e,t,r;const i={};for(let o=0;o<l.length;o++){const a=l[o];if(!a)throw new Error("Field is undefined.");const c=o>0?(e=i[l[o-1].identifier])==null?void 0:e.conditionFields:void 0,d=new Set(c);(t=a.condition)!=null&&t.identifier&&d.add(a.condition.identifier),i[a.identifier]={disabled:!1,conditionFields:d,conditionIndex:jt(l,(r=a.condition)==null?void 0:r.identifier),index:o,label:a.label}}return i},ft=(l,i)=>{for(const[e,t]of Object.entries(l))if(t.identifier===i)return[t,e]},Ht=u.memo(function(){const{values:i,setFieldValue:e}=D.useFormikContext(),[t,r]=u.useReducer(Wt,i.fields,ut),{showInfo:o}=s.useToast();u.useEffect(()=>{r({type:"update",state:ut(i.fields)})},[r,i.fields]);const a=u.useCallback(h=>{h.type==="SECTION"&&r({type:"hold",fieldId:h.draggableId})},[]),c=u.useCallback(h=>{const{source:f,destination:p,type:g,reason:x,draggableId:v}=h;if(r({type:"release"}),!p||x==="CANCEL")return;if(g==="ROOT"){const M=t[v];if(!M)throw new Error("Could not find section context.");let A=typeof M.conditionIndex<"u"?Math.max(M.conditionIndex+1,p.index):p.index;for(const b of Object.values(t))b.conditionIndex===f.index&&(A=Math.min(A,b.index-1));return A!=p.index&&o({title:"Reordered sections",description:"Sections with conditions must be below the fields they reference."}),e("fields",Ee(i.fields,f.index,A))}if(g!=="SECTION")throw new Error("Unexpected droppable type.");const[I,S]=ft(i.fields,f.droppableId)??[],[C,w]=ft(i.fields,p.droppableId)??[];if(!(I!=null&&I.fields)||!C)throw new Error("Could not find section with fields.");if(I.identifier===C.identifier)e(`fields.${S}.fields`,Ee(I.fields,f.index,p.index)).then();else{const M=I.fields[f.index];if(!M)throw new Error("Could not find field to reorder.");e(`fields.${S}.fields`,xe(I.fields,f.index)).then(),e(`fields.${w}.fields`,Xe(C.fields,p.index,M)).then()}},[i.fields,e,t,o]),d=u.useMemo(()=>({index:i.fields.length,parentPath:"fields",initial:ye(),conditionalSourceFields:ve(i.fields,i.fields.length)}),[i.fields]);return n.jsx(G.DragDropContext,{onDragStart:a,onDragEnd:c,children:n.jsx(G.Droppable,{droppableId:"droppable",type:"ROOT",children:h=>n.jsxs(s.Flex,{ref:h.innerRef,...h.droppableProps,direction:"column",gap:"0",children:[i.fields.map((f,p)=>n.jsx(Nt,{field:f,index:p,dropState:t},f.label)),h.placeholder,n.jsx(pe,{...d,children:n.jsxs(s.Button,{type:"button",variant:"outline",children:[n.jsx(s.PlusIcon,{})," Add a section"]})})]})})})}),Ut={title:"",description:"",fields:[]},Gt=new Z({label:"Title",minLength:0,maxLength:100,required:!0,identifier:"title"}),Kt={formId:Ce,placeholder:"Give your form a title."},Yt=new k({label:"Description",minLength:0,maxLength:1e3,required:!1,identifier:"description"}),Qt={formId:Ce,placeholder:"Explain the purpose of this form."},Xt=()=>{alert("This is a form preview, your data will not be saved.")},Jt=u.memo(u.forwardRef((l,i)=>{const{onCancel:e,onSave:t,revision:r}=l,o=r?"Edit form":"Create a new form",{heading:a=o}=l,c=u.useCallback(x=>{const v={};if(x.title||(v.title="Title is required."),(!x.fields||x.fields.length===0)&&(v.fields="At least one field is required."),Ie(v))return v},[]),d=D.useFormik({initialValues:mt(r)??Ut,validate:c,onSubmit:x=>t(x),validateOnChange:!1,validateOnBlur:!1}),h=u.useMemo(()=>Ve(d.values),[d.values]),f=fe(Gt,Kt),p=fe(Yt,Qt),g=u.useMemo(()=>typeof a=="object"?a:n.jsx(s.Heading,{children:a}),[a]);return n.jsx(s.Tabs.Root,{ref:i,defaultValue:"edit",children:n.jsxs(s.Flex,{direction:"column",gap:"2",children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Trigger,{value:"edit",children:"Edit"}),n.jsx(s.Tabs.Trigger,{value:"preview",children:"Preview"})]}),n.jsxs(s.Tabs.Content,{value:"edit",children:[g,n.jsxs(s.Text,{children:["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"," ",n.jsx("em",{children:"Preview"})," tab, but"," ",n.jsx("strong",{children:"field values entered on this page will not be saved."})]}),n.jsx(s.Flex,{asChild:!0,direction:"column",gap:"2",mt:"3",children:n.jsxs("form",{id:Ce,onSubmit:d.handleSubmit,children:[n.jsxs(D.FormikProvider,{value:d,children:[f,p,n.jsx(Ht,{}),n.jsx(s.Text,{severity:"danger",size:"1",children:typeof d.errors.fields=="string"&&d.errors.fields})]}),n.jsxs(s.Flex,{justify:"end",gap:"2",children:[n.jsx(s.Button,{type:"button",variant:"soft",onClick:e,children:"Cancel"}),n.jsx(s.Button,{type:"submit",disabled:!d.isValid,children:"Save"})]})]})})]}),n.jsx(s.Tabs.Content,{value:"preview",children:n.jsx(be,{schema:h,onSubmit:Xt})})]})})}));y.BooleanField=Q,y.BooleanInput=He,y.DateField=me,y.DateInput=Ge,y.FieldSection=H,y.FormBrowser=zt,y.FormBuilder=Jt,y.FormRenderer=be,y.FormSubmissionBrowser=At,y.FormSubmissionViewer=St,y.MultiSelectField=ce,y.MultiSelectInput=tt,y.MultiStringField=ae,y.MultiStringInput=Re,y.NumberField=K,y.NumberInput=Ue,y.PatchField=Pt,y.PatchFormProvider=Lt,y.SelectField=de,y.SelectInput=Qe,y.StringField=Z,y.StringInput=Ke,y.TextField=k,y.TextInput=Ye,y.deserialize=ue,y.deserializeField=De,y.formRevisionToSchema=Ve,y.isConditionMet=$e,y.useFieldInput=fe,y.useFieldInputs=Be,y.valueIsFile=Fe,Object.defineProperty(y,Symbol.toStringTag,{value:"Module"})});
1
+ (function(y,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("react/jsx-runtime"),require("@overmap-ai/blocks"),require("formik"),require("react"),require("@hello-pangea/dnd"),require("@overmap-ai/core"),require("lodash.get"),require("lodash.set")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","@overmap-ai/blocks","formik","react","@hello-pangea/dnd","@overmap-ai/core","lodash.get","lodash.set"],n):(y=typeof globalThis<"u"?globalThis:y||self,n(y.forms={},y.jsxRuntime,y.blocks,y.formik,y.React,y.dnd,y.core,y.get,y.set))})(this,function(y,n,s,D,c,U,F,J,ze){"use strict";var kt=Object.defineProperty;var Rt=(y,n,s)=>n in y?kt(y,n,{enumerable:!0,configurable:!0,writable:!0,value:s}):y[n]=s;var m=(y,n,s)=>(Rt(y,typeof n!="symbol"?n+"":n,s),s);class je{constructor(i){m(this,"type");m(this,"identifier");m(this,"description");const{description:e=null,identifier:t,type:r}=i;this.identifier=t,this.description=e,this.type=r}getId(){return this.identifier}static deserialize(i){throw new Error(`${this.name} must implement deserialize.`)}_serialize(){if(!this.identifier)throw new Error("Field identifier must be set before serializing.");return{type:this.type,identifier:this.identifier,description:this.description}}}class $ extends je{constructor(e){const{label:t,required:r,fieldValidators:o=[],formValidators:a=[],...u}=e;super(u);m(this,"required");m(this,"formValidators");m(this,"fieldValidators");m(this,"label");m(this,"onlyValidateAfterTouched",!0);this.label=t,this.required=r,this.fieldValidators=o,this.formValidators=a}static getFieldCreationSchema(){return[]}isBlank(e){return e==null||e===""}getValueFromChangeEvent(e){return e.target.value}getError(e,t){if(this.required&&this.isBlank(e))return"This field is required.";for(const r of this.getFieldValidators()){const o=r(e);if(o)return o}if(t)for(const r of this.getFormValidators()){const o=r(e,t);if(o)return o}}_serialize(){return{...super._serialize(),label:this.label,required:this.required}}getFieldValidators(){return[...this.fieldValidators]}getFormValidators(){return[...this.formValidators]}}m($,"fieldTypeName"),m($,"fieldTypeDescription");const he={description:"_description_17zed_1"},N=l=>{const{label:i,children:e,severity:t,inputId:r,labelId:o,flexProps:a}=l;return n.jsx(s.Flex,{direction:"column",gap:"1",asChild:!0,...a,children:n.jsxs("label",{htmlFor:r,children:[n.jsx(s.Text,{severity:t,id:o,children:i}),e]})})},W=l=>{const{helpText:i,children:e,severity:t}=l;return n.jsxs(s.Flex,{direction:"column",gap:"1",children:[e,n.jsx(s.Flex,{direction:"column",children:n.jsx(s.Text,{size:"1",severity:t,className:he.description,children:i})})]})},j=l=>{const{id:i,field:e,formId:t,...r}=l,[o,a,u]=D.useField(e.getId()),{touched:d}=a,h=a.error??e.description,f=a.error?"danger":void 0,p=i??`${t}-${e.getId()}-input`,g=`${p}-label`,x=e.required?`${e.label} *`:e.label,v=c.useMemo(()=>({...o,onChange:C=>{const w=e.getValueFromChangeEvent(C);u.setValue(w,!1).then(),(d||!e.onlyValidateAfterTouched)&&u.setError(e.getError(w))},onBlur:C=>{u.setTouched(!0,!1).then(),u.setError(e.getError(e.getValueFromChangeEvent(C)))}}),[e,o,u,d]);return[{helpText:h,severity:f,inputId:p,labelId:g,label:x,fieldProps:v,helpers:u,field:e},{...r,"aria-labelledby":g}]},ht=[!0,"true"],He=c.memo(function(i){const[{inputId:e,labelId:t,severity:r,helpText:o,label:a,fieldProps:u},d]=j(i),h=s.useSeverityColor(r),f=ht.includes(u.value);return n.jsx(W,{helpText:o,severity:r,children:n.jsx(N,{severity:r,inputId:e,labelId:t,label:a,flexProps:{direction:"row-reverse",justify:"end",align:"center",gap:"2"},children:n.jsx(s.Checkbox,{...d,...u,id:e,color:h,value:f.toString(),checked:f,onCheckedChange:u.onChange,onChange:void 0,onBlur:void 0})})})}),R=class R extends ${constructor(e){super({...e,type:"boolean"});m(this,"onlyValidateAfterTouched",!1)}isBlank(e){return this.required&&!e}getValueFromChangeEvent(e){return typeof e=="boolean"?e:e.target.checked}serialize(){return super._serialize()}static deserialize(e){if(e.type!=="boolean")throw new Error("Type mismatch.");return new R(e)}getInput(e){return n.jsx(He,{...e,field:this})}};m(R,"fieldTypeName","Checkbox"),m(R,"fieldTypeDescription","Perfect for both optional and required yes/no questions."),m(R,"Icon",s.CheckCircledIcon);let Q=R;const Ue=c.memo(function(i){const[{inputId:e,labelId:t,severity:r,helpText:o,label:a,fieldProps:u,field:d},h]=j(i),f=s.useSeverityColor(r);return n.jsx(W,{helpText:o,severity:r,children:n.jsx(N,{severity:r,inputId:e,labelId:t,label:a,children:n.jsx(s.TextField.Input,{...h,...u,type:"number",id:e,min:d.minimum,max:d.maximum,step:d.integers?1:.1,color:f})})})}),_=class _ extends ${constructor(e){const{minimum:t=Number.MIN_SAFE_INTEGER,maximum:r=Number.MAX_SAFE_INTEGER,integers:o=!1,...a}=e;super({...a,type:"number"});m(this,"minimum");m(this,"maximum");m(this,"integers");this.minimum=t,this.maximum=r,this.integers=o}getValueFromChangeEvent(e){const t=Number.parseFloat(e.target.value);return Number.isNaN(t)?"":t}static getFieldCreationSchema(){return[new _({label:"Minimum",description:"Minimum value",integers:!0,required:!1,identifier:"minimum",formValidators:[this._validateMin]}),new _({label:"Maximum",description:"Maximum value",integers:!0,required:!1,identifier:"maximum",formValidators:[this._validateMax]}),new Q({label:"Integers",description:"Whole numbers only",required:!1,identifier:"integers"})]}getFieldValidators(){const e=super.getFieldValidators(),t=this.minimum,r=this.maximum;return typeof t=="number"&&e.push(o=>{if(typeof o=="number"&&o<t)return`Must be at least ${this.minimum}.`}),typeof r=="number"&&e.push(o=>{if(typeof o=="number"&&o>r)return`Must be at most ${this.maximum}.`}),this.integers&&e.push(o=>{if(typeof o=="number"&&!Number.isInteger(o))return"Must be a whole number."}),e}serialize(){return{...super._serialize(),minimum:this.minimum,maximum:this.maximum,integers:this.integers}}static deserialize(e){if(e.type!=="number")throw new Error("Type mismatch.");return new _(e)}getInput(e){return n.jsx(Ue,{field:this,...e})}};m(_,"fieldTypeName","Number"),m(_,"fieldTypeDescription","Allows specifying a number within a given range."),m(_,"Icon",s.FontFamilyIcon),m(_,"_validateMin",(e,t)=>typeof t.maximum=="number"&&typeof e=="number"&&t.maximum<e?"Minimum cannot be greater than minimum.":null),m(_,"_validateMax",(e,t)=>typeof t.minimum=="number"&&typeof e=="number"&&t.minimum>e?"Maximum cannot be less than minimum.":null);let G=_;const Ge=c.memo(function(i){const[{inputId:e,labelId:t,severity:r,helpText:o,label:a,fieldProps:u},d]=j(i),h=s.useSeverityColor(r),f=u.value?u.value.split("T")[0]:"";return n.jsx(W,{helpText:o,severity:r,children:n.jsx(N,{severity:r,inputId:e,labelId:t,label:a,children:n.jsx(s.TextField.Input,{...d,...u,type:"date",id:e,color:h,value:f})})})}),ee=class ee extends ${constructor(e){super({...e,type:"date"});m(this,"onlyValidateAfterTouched",!1)}serialize(){return super._serialize()}getValueFromChangeEvent(e){return new Date(e.target.value).toISOString()}static deserialize(e){if(e.type!=="date")throw new Error("Type mismatch.");return new ee(e)}getInput(e){return n.jsx(Ge,{field:this,...e})}};m(ee,"fieldTypeName","Date"),m(ee,"fieldTypeDescription","Allows specifying a date."),m(ee,"Icon",s.CalendarIcon);let me=ee;class ge extends ${constructor(e){const{minLength:t,maxLength:r=5e3,...o}=e;super(o);m(this,"minLength");m(this,"maxLength");this.minLength=t?Math.max(t,0):void 0,this.maxLength=r?Math.max(r,0):5e3}static getFieldCreationSchema(){return[new G({label:"Minimum length",description:"Minimum number of characters",required:!1,identifier:"minimum_length",minimum:0,maximum:100,formValidators:[this._validateMin],integers:!0}),new G({label:"Maximum length",description:"Maximum number of characters",required:!1,identifier:"maximum_length",minimum:1,maximum:5e3,formValidators:[this._validateMax],integers:!0})]}getFieldValidators(){const e=super.getFieldValidators();return this.minLength&&e.push(t=>{if(this.minLength&&(!t||t.length<this.minLength))return!this.required&&!t?null:`Minimum ${this.minLength} character(s).`}),this.maxLength&&e.push(t=>{if(typeof t=="string"&&this.maxLength&&t.length>this.maxLength)return`Maximum ${this.maxLength} character(s).`}),e}_serialize(){if(!this.identifier)throw new Error("Field identifier must be set before serializing.");return{...super._serialize(),minimum_length:this.minLength,maximum_length:this.maxLength}}}m(ge,"_validateMin",(e,t)=>typeof t.maximum_length=="number"&&typeof e=="number"&&t.maximum_length<e?"Minimum cannot be greater than maximum.":null),m(ge,"_validateMax",(e,t)=>{if(typeof e!="number")return null;const{minimum_length:r}=t;return typeof r!="number"?null:r>e?"Maximum cannot be less than minimum.":null});const Ke=c.memo(function(i){const[{inputId:e,labelId:t,severity:r,helpText:o,label:a,fieldProps:u,field:d},h]=j(i),f=s.useSeverityColor(r);return n.jsx(W,{helpText:o,severity:r,children:n.jsx(N,{severity:r,inputId:e,labelId:t,label:a,children:n.jsx(s.TextField.Input,{...h,...u,type:d.inputType,id:e,color:f})})})}),te=class te extends ge{constructor(e){const{inputType:t="text",...r}=e,o=e.maxLength?Math.min(500,e.maxLength):500,a=e.minLength?Math.min(e.minLength,o):void 0;super({...r,maxLength:o,minLength:a,type:"string"});m(this,"inputType");this.inputType=t}serialize(){return{...super._serialize(),input_type:this.inputType}}static deserialize(e){if(e.type!=="string")throw new Error("Type mismatch.");const{maximum_length:t,minimum_length:r,input_type:o,...a}=e;return new te({...a,maxLength:t,minLength:r,inputType:o})}getInput(e){return n.jsx(Ke,{field:this,...e})}};m(te,"fieldTypeName","Short Text"),m(te,"fieldTypeDescription","Short text fields can hold up to 500 characters on a single line."),m(te,"Icon",s.InputIcon);let Z=te;const Ye=c.memo(function(i){const[{inputId:e,labelId:t,severity:r,helpText:o,label:a,fieldProps:u},d]=j(i);return n.jsx(W,{helpText:o,severity:r,children:n.jsx(N,{severity:r,inputId:e,labelId:t,label:a,children:n.jsx(s.TextArea,{...d,...u,resize:"vertical",id:e,severity:r})})})}),ie=class ie extends ge{constructor(i){const e=i.maxLength?Math.min(5e3,i.maxLength):5e3,t=i.minLength?Math.min(i.minLength,e):void 0;super({...i,maxLength:e,minLength:t,type:"text"})}serialize(){return super._serialize()}static deserialize(i){if(i.type!=="text")throw new Error("Type mismatch.");const{maximum_length:e,minimum_length:t,...r}=i;return new ie({...r,maxLength:e,minLength:t})}getInput(i){return n.jsx(Ye,{field:this,...i})}};m(ie,"fieldTypeName","Paragraph"),m(ie,"fieldTypeDescription","Paragraph fields can hold up to 5000 characters and can have multiple lines."),m(ie,"Icon",s.RowsIcon);let k=ie;const Qe=c.memo(function(i){const[{inputId:e,labelId:t,severity:r,helpText:o,label:a,fieldProps:u,field:d},h]=j(i),{onChange:f,onBlur:p}=u,g=c.useMemo(()=>d.options.map(v=>({value:v.value,itemContent:v.label})),[d.options]),x=c.useCallback(v=>{f(v),p(v)},[f,p]);return n.jsx(W,{helpText:o,severity:r,children:n.jsx(N,{severity:r,inputId:e,labelId:t,label:a,children:n.jsx(s.Select,{items:g,...u,onValueChange:x,placeholder:"Select one...",id:e,severity:r,...h})})})}),ye=(l="",i=[])=>({type:"section",fields:i,identifier:l,label:null,condition:null,conditional:!1}),mt=l=>{if(!l)return;const i=l.fields;let e=[];const t=[];for(const r of i)r.type==="section"?(e.length>0&&(t.push(ye(`AUTO_section-${i.indexOf(r)}`,e)),e=[]),t.push(r)):e.push(r);return e.length>0&&t.push(ye("AUTO_section-last",e)),{...l,fields:t,description:l.description??""}};function Ee(l,i,e){const t=Array.from(l),[r]=t.splice(i,1);if(!r)throw new Error("Could not find field to reorder.");return t.splice(e,0,r),t}function gt(l,i,e){const t=Array.from(l);return t[i]=e,t}function Xe(l,i,e){const t=Array.from(l??[]);return t.splice(i,0,e),t}function xe(l,i){const e=Array.from(l);return e.splice(i,1),e}const Je=(l,i)=>{if(typeof l=="string"&&l.length>0)return l;const e=new Date;return`${F.slugify(i)}-${e.getTime()}`},Ze=(l,i)=>{if(!i)return null;for(const e of l)if(e.type==="section"){const t=Ze(e.fields,i);if(t)return t}else if(e.identifier===i)return e;return null},ve=(l,i)=>l.filter((e,t)=>t<i).flatMap(e=>e.fields),ke=l=>l.flatMap(i=>i.type==="section"?[...i.fields.map(e=>e.label),i.label]:i.label).filter(i=>i!==null),Me=(l,i)=>{let e=1,t=`${l} (${e})`;for(;i.includes(t);)t=`${l} (${++e})`;return t},Re=c.memo(function(i){const[{inputId:e,labelId:t,severity:r,helpText:o,label:a,fieldProps:u},d]=j(i),h=s.useSeverityColor(r),f=c.useMemo(()=>Array.isArray(u.value)?u.value:[],[u.value]),{onChange:p,onBlur:g}=u,x=`${e}-droppable`,{disabled:v}=d,[I,S]=c.useState(""),[C,w]=c.useState(""),M=C||o,A=C?"red":h,b=c.useCallback(E=>{p(E),g(E)},[p,g]),P=c.useCallback(E=>{f.findIndex(O=>O.value===E.target.value.trim())>=0?w("All options must be unique"):E.target.value?w(""):w("Option cannot be empty"),S(E.target.value)},[S,f]),B=c.useCallback(()=>{if(C)return;if(!I.trim())return w("Option cannot be empty");const E=I.trim();b([...f,{value:E,label:E}]),S("")},[I,C,b,f]),X=c.useCallback(E=>{E.key==="Enter"&&(E.preventDefault(),B())},[B]),H=c.useCallback(E=>{b(xe(f,E))},[f,b]),Y=c.useCallback(E=>{if(!E.destination)return;const O=E.source.index,T=E.destination.index;b(Ee(f,O,T))},[b,f]);return n.jsx(U.DragDropContext,{onDragEnd:Y,children:n.jsxs(s.Flex,{direction:"column",gap:"2",children:[n.jsx(W,{helpText:M,severity:r,children:n.jsx(N,{severity:r,inputId:e,labelId:t,label:a,children:(!v||f.length===0)&&n.jsxs(s.Flex,{gap:"2",children:[n.jsx(s.Box,{grow:"1",children:n.jsx(s.TextField.Input,{placeholder:"Press enter to add a new option",...d,...u,value:I,onChange:P,onKeyDown:X,id:e,color:A,onBlur:void 0})}),n.jsx(s.IconButton,{type:"button","aria-label":"Add option",disabled:!!C||v,onClick:B,children:n.jsx(s.PlusIcon,{})})]})})}),n.jsx(U.Droppable,{droppableId:x,children:E=>n.jsxs(s.Flex,{...E.droppableProps,ref:E.innerRef,direction:"column",children:[f.map((O,T)=>n.jsx(U.Draggable,{draggableId:`${O.value}-draggable`,index:T,isDragDisabled:v,children:({draggableProps:z,dragHandleProps:V,innerRef:L})=>n.jsx(s.Flex,{...V,...z,ref:L,gap:"2",align:"center",justify:"between",mb:"1",asChild:!0,children:n.jsxs(s.Badge,{color:"gray",size:"2",children:[n.jsx("span",{children:O.label}),n.jsx(s.IconButton,{size:"small",variant:"ghost",type:"button","aria-label":"Delete option",severity:"info",disabled:v,onClick:()=>H(T),children:n.jsx(s.Cross1Icon,{})})]})})},O.value)),E.placeholder]})})]})})}),ne=class ne extends ${constructor(e){const{minimum_length:t,maximum_length:r,...o}=e;super({...o,type:"multi-string"});m(this,"minLength");m(this,"maxLength");m(this,"onlyValidateAfterTouched",!1);this.minLength=t??0,this.maxLength=r??1/0}getValueFromChangeEvent(e){if(Array.isArray(e))return e;throw new Error("Expected an array.")}getInput(e){return n.jsx(Re,{field:this,...e})}serialize(){return{...super._serialize(),minimum_length:this.minLength,maximum_length:this.maxLength}}isBlank(e){return super.isBlank(e)||e.length===0}getFieldValidators(){const e=super.getFieldValidators();return e.push(t=>{if(Array.isArray(t)&&t.length<this.minLength)return`Must have at least ${this.minLength} options.`}),e.push(t=>{if(Array.isArray(t)&&t.length>this.maxLength)return`Must have at most ${this.maxLength} options.`}),e}static deserialize(e){if(e.type!=="multi-string")throw new Error("Type mismatch.");return new ne(e)}};m(ne,"fieldTypeName","Multi-string"),m(ne,"fieldTypeDescription","Allows the user to provide multiple unique strings."),m(ne,"Icon",s.ListBulletIcon);let ae=ne;class et extends ${constructor(e){super(e);m(this,"options");m(this,"onlyValidateAfterTouched",!1);const t=new Set;this.options=e.options.map(r=>(typeof r=="string"&&(r={label:r,value:r}),t.add(r.label),r)),t.size!==e.options.length&&console.error(`${e.options.length-t.size} duplicate identifiers found in options. This may cause unexpected behavior. Options:`,e.options)}_serialize(){return{...super._serialize(),options:this.options}}static getFieldCreationSchema(){return[new ae({label:"Options",description:"List possible options for the user to select from.",required:!0,identifier:"options",minimum_length:2,maximum_length:20})]}}const re=class re extends et{constructor(i){super({...i,type:"select"})}getValueFromChangeEvent(i){return typeof i=="string"?i:i.target.value}serialize(){return super._serialize()}static deserialize(i){if(i.type!=="select")throw new Error("Type mismatch.");return new re(i)}getInput(i){return n.jsx(Qe,{field:this,...i})}};m(re,"fieldTypeName","Dropdown"),m(re,"fieldTypeDescription","Allows the user to select a single option from a list of options."),m(re,"Icon",s.DropdownMenuIcon);let de=re;const yt=l=>l?Array.isArray(l)?l:[l]:[],tt=c.memo(function(i){const[{inputId:e,labelId:t,severity:r,helpText:o,label:a,fieldProps:u,field:d},h]=j(i),{onChange:f,onBlur:p}=u,g=c.useMemo(()=>yt(u.value),[u.value]),x=c.useCallback(v=>{f(v),p(v)},[f,p]);return n.jsx(W,{helpText:o,severity:r,children:n.jsx(N,{severity:r,inputId:e,labelId:t,label:a,children:n.jsx(s.MultiSelect,{value:g,onValueChange:x,options:d.options,name:u.name,placeholder:"Select one or more...",id:e,severity:r,...h})})})}),se=class se extends et{constructor(i){super({...i,type:"multi-select"})}getValueFromChangeEvent(i){if(Array.isArray(i))return i;throw new Error("Expected an array.")}isBlank(i){return super.isBlank(i)||i.length===0}serialize(){return super._serialize()}static deserialize(i){if(i.type!=="multi-select")throw new Error("Type mismatch.");return new se(i)}getInput(i){return n.jsx(tt,{field:this,...i})}};m(se,"fieldTypeName","Multi-select"),m(se,"fieldTypeDescription","Allows the user to select a multiple options from a list of options."),m(se,"Icon",s.CheckboxIcon);let ce=se;const xt=c.memo(function({field:i,...e}){const[{value:t}]=D.useField(i.options.clonedFieldIdentifier),r=c.useMemo(()=>{const o=i.options.getFieldToClone(t);return o?ue(o):null},[i.options,t]);return fe(r,e)});class we extends ${constructor(e,t){super({...e,type:"custom"});m(this,"Component");m(this,"options");this.options=e,this.Component=t}serialize(){throw new Error("Serializing only supported for public input types.")}getInput(e){const t=this.Component;return n.jsx(t,{field:this,...e})}}m(we,"fieldTypeName","Custom"),m(we,"fieldTypeDescription","Allows re-rendering of field already in the form");class vt extends we{constructor(i){super(i,xt)}}const wt=c.memo(function(i){const{field:e,...t}=i,{label:r,description:o,fields:a,condition:u}=e,{values:d,setFieldValue:h}=D.useFormikContext(),f=u!=null&&u.identifier?J(d,u.identifier):void 0,p=c.useMemo(()=>$e(u,f),[u,f]);c.useEffect(()=>{if(!p)for(const x of a)h(x.getId(),"").then()},[p,a,h]);const g=Be(a,t);return p?r?n.jsx(s.Card,{children:n.jsxs(s.Flex,{direction:"column",gap:"3",children:[n.jsxs(s.Flex,{direction:"column",children:[n.jsx(s.Heading,{as:"h3",size:"3",children:r}),n.jsx(s.Text,{className:he.description,children:o})]}),g]})}):g:null}),oe=class oe extends je{constructor(e){const{label:t=null,fields:r,condition:o=null,conditional:a,...u}=e;super({...u,type:"section"});m(this,"label");m(this,"fields");m(this,"condition");this.fields=r,this.condition=o,this.label=t,a===!1&&(this.condition=null)}static getFieldCreationSchema(e){return e.length===0?[]:[new Q({label:"Conditional",description:"Conditionally show or hide this section.",identifier:"conditional",required:!1}),new oe({label:"Conditional settings",identifier:"conditional-settings",condition:{identifier:"conditional",value:!0},fields:[new de({label:"Field",description:"The field to use for the condition.",options:e.map(t=>!t.label||t.type==="upload"?null:{label:t.label,value:t.identifier}).filter(t=>!!t),identifier:"condition.identifier",required:!0}),new vt({label:"Value",identifier:"condition.value",required:!0,clonedFieldIdentifier:"condition.identifier",getFieldToClone(t){if(!t)return null;const r=e.find(o=>o.identifier===t);return r?{...r,label:"Value",identifier:"condition.value",description:"The value to compare against.",required:r.type!=="boolean"}:(console.error("Could not find field with identifier",t),null)}})]})]}static deserialize(e){var r;if(e.type!=="section")throw new Error("Invalid type");const t=((r=e.fields)==null?void 0:r.map(De))??[];return new oe({...e,fields:t})}conditional(){return this.condition!==null}serialize(){return{...super._serialize(),label:this.label,condition:this.condition,conditional:this.conditional(),fields:this.fields.map(e=>e.serialize())}}getErrors(e){const t={};for(const r of this.fields){const o=r.getId(),a=r.getError(J(e,o),e);a&&ze(t,r.getId(),a)}return t}getInput(e){return n.jsx(wt,{field:this,...e})}};m(oe,"fieldTypeName","Section"),m(oe,"fieldTypeDescription","Sections can be useful for grouping fields together. They can also be conditionally shown or hidden.");let K=oe;const Ft={previewImage:"_previewImage_1ig84_1"},Ae=l=>{const i=["byte","kilobyte","megabyte"];let e=l,t=0;for(;e>1024&&t<i.length-1;)e/=1024,t++;return new Intl.NumberFormat([],{maximumFractionDigits:2,style:"unit",unit:i[t]}).format(e)},It=c.memo(function(i){var A;const[{inputId:e,labelId:t,severity:r,helpText:o,label:a,fieldProps:u,field:d},h]=j(i),{onChange:f}=u,p=s.useSeverityColor(r),g=c.useRef(null),{value:x}=u,v=c.useMemo(()=>o||(d.maxFileSize?`Maximum file size: ${Ae(d.maxFileSize)}`:null),[d.maxFileSize,o]),I=c.useCallback(()=>{var b;(b=g.current)==null||b.click()},[]),S=c.useCallback(b=>{const P=[...x];P.splice(b,1),f({target:{files:P}})},[x,f]),C=x?"Select new files":"Select files",w=x?"Select new file":"Select a file",M=d.maxFiles>1?C:w;return n.jsxs(s.Flex,{direction:"column",gap:"2",children:[n.jsx(W,{helpText:v,severity:r,children:n.jsxs(N,{severity:r,inputId:e,labelId:t,label:a,children:[n.jsx(s.Flex,{direction:"row",gap:"2",children:n.jsx(s.Box,{width:"max-content",asChild:!0,children:n.jsxs(s.Button,{...h,onClick:I,children:[n.jsx(s.UploadIcon,{})," ",M]})})}),n.jsx("input",{...h,type:"file",ref:g,id:e,accept:(A=d.extensions)==null?void 0:A.join(","),multiple:d.maxFiles>1,color:p,style:{display:"none"},...u,value:""})]})}),Array.isArray(x)&&x.length>0&&n.jsx(s.Flex,{direction:"column",gap:"2",children:x.map((b,P)=>n.jsx(bt,{field:d,file:b,onRemove:()=>S(P),disabled:h.disabled},P))})]})}),bt=c.memo(function({file:i,field:e,onRemove:t,disabled:r}){const[o,a]=c.useState(null),u=c.useMemo(()=>o&&e.getError([o]),[e,o]),{url:d,name:h,size:f}=c.useMemo(()=>{let p=null,g,x;return o!=null&&o.type.startsWith("image/")&&(p=URL.createObjectURL(o)),o?(g=o.name,x=Ae(o.size)):(g="Downloading...",x="..."),{url:p,name:g,size:x}},[o]);return c.useEffect(()=>{i instanceof Promise?i.then(a):a(i)},[i]),n.jsx(s.Card,{children:n.jsxs(s.Flex,{direction:{initial:"column",sm:"row"},gap:"3",justify:"between",children:[n.jsxs(s.Flex,{direction:"row",gap:"3",align:"center",grow:"1",shrink:"0",children:[n.jsx(s.IconButton,{severity:"info",variant:"outline","aria-label":`Remove ${h}`,disabled:r,onClick:t,children:n.jsx(s.Cross1Icon,{})}),n.jsxs(s.Flex,{direction:"column",gap:"1",children:[n.jsx(s.Text,{children:h}),n.jsx(s.Text,{size:"1",children:f}),u&&n.jsx(s.Text,{size:"1",severity:"danger",children:u})]})]}),d&&n.jsx("img",{className:Ft.previewImage,src:d,alt:h})]})})}),it=50*1024*1024,le=class le extends ${constructor(e){const{extensions:t,maximum_files:r,maximum_size:o,...a}=e;super({...a,type:"upload"});m(this,"extensions");m(this,"maxFileSize");m(this,"maxFiles");m(this,"onlyValidateAfterTouched",!1);this.maxFileSize=typeof o=="number"?o:void 0,this.maxFiles=Math.max(typeof r=="number"?r:1,1),this.extensions=t}getValueFromChangeEvent(e){return Array.from(e.target.files||[])}isBlank(e){return super.isBlank(e)||e.length===0}static getFieldCreationSchema(){return[new G({label:"How many files can be uploaded?",description:"By default, only one file can be uploaded.",required:!1,minimum:1,maximum:10,identifier:"maximum_files"}),new G({label:"What is the maximum size of each file?",description:"Maximum file size in bytes.",required:!1,identifier:"maximum_size",minimum:1,maximum:it,integers:!0}),new ce({label:"Accepted file types",description:"Types of allowed files to upload. If left blank, all files will be accepted.",required:!1,identifier:"extensions",options:[{value:"image/*",label:"Images"},{value:"audio/*",label:"Audio files"},{value:"video/*",label:"Videos"},{value:"text/*",label:"Text files"},{value:"application/*",label:"Application files (includes PDFs and Word documents)"}]})]}getFieldValidators(){const e=super.getFieldValidators(),t=this.maxFileSize??it,r=this.maxFiles??1;return e.push(o=>{if(o&&o.some(a=>a.size>t))return`Files must be at most ${Ae(t)}.`}),e.push(o=>{if(o&&o.length>r)return`You can only upload ${r} files.`}),e}serialize(){return{...super._serialize(),extensions:this.extensions,maximum_size:this.maxFileSize,maximum_files:this.maxFiles}}static deserialize(e){if(e.type!=="upload")throw new Error("Type mismatch.");return new le(e)}getInput(e){return n.jsx(It,{field:this,...e})}};m(le,"fieldTypeName","Upload"),m(le,"fieldTypeDescription","Allows a file to be uploaded."),m(le,"Icon",s.UploadIcon);let Pe=le;const Le={date:me,number:G,boolean:Q,select:de,string:Z,text:k,custom:we,upload:Pe,"multi-string":ae,"multi-select":ce},De=l=>{const i=l.type;return Le[i].deserialize(l)},ue=l=>l.type==="section"?K.deserialize(l):De(l);function Ve(l,i={}){const{readonly:e=!1}=i;return{title:l.title,description:l.description,fields:l.fields.map(t=>ue(t)),meta:{readonly:e}}}function Fe(l){return!!(Array.isArray(l)&&l.some(i=>i instanceof File||i instanceof Promise))}function $e(l,i){if(!l)return!0;if(Fe(i)||Fe(l.value))throw new Error("Conditions do not support file uploads");const e=Array.isArray(i)?i.map(r=>typeof r=="string"?r:r.value):i,t=Array.isArray(l.value)?l.value.map(r=>typeof r=="string"?r:r.value):l.value;if(Array.isArray(t)&&Array.isArray(e)){for(const r of t)if(!e.includes(r))return!1;return!0}return t===i}const fe=(l,i)=>c.useMemo(()=>!i||!l?null:l.getInput(i),[l,i]),Be=(l,i)=>{const e=c.useMemo(()=>l.map(t=>n.jsx("div",{children:t.getInput(i)},t.getId())),[l,i]);return n.jsx(s.Flex,{direction:"column",gap:"2",children:e})},Ie=l=>Object.keys(l).length>0,nt=async(l,i)=>{const e={};for(const t of l.fields)if(t instanceof K){if(t.condition){const{identifier:r}=t.condition;if(!$e(t.condition,J(i,r)))continue}Object.assign(e,t.getErrors(i))}else{if(!(t instanceof $))throw new Error("Invalid field type");const r=t.getId(),o=t.getError(J(i,r),i);o&&ze(e,r,o)}if(Ie(e))return e},Ct=[null,void 0],_e=(l,i)=>l.reduce((e,t)=>t instanceof K?{...e,..._e(t.fields,i)}:(Ct.includes(J(e,t.getId()))&&ze(e,t.getId(),""),e),i),Tt=()=>{throw new Error("onSubmit must be provided if form is not readonly.")},be=c.memo(c.forwardRef((l,i)=>{const{schema:e,values:t={},onSubmit:r=Tt,submitText:o="Submit",cancelText:a,onCancel:u,onDirty:d,hideTitle:h=!e.title,hideDescription:f,className:p}=l,{readonly:g}=e.meta,x=c.useMemo(()=>crypto.randomUUID(),[]),v=D.useFormik({initialValues:_e(e.fields,t),onSubmit:r,validate:M=>nt(e,M),validateOnBlur:!1,validateOnChange:!1}),{dirty:I}=v,S=c.useMemo(()=>typeof e.title=="string"?n.jsx(s.Heading,{children:e.title}):e.title,[e.title]),C=c.useMemo(()=>typeof e.description=="string"?n.jsx(s.Text,{className:he.description,children:e.description}):e.description,[e.description]),w=Be(e.fields,{formId:x,disabled:g});return c.useEffect(()=>{I&&d&&d()},[I,d]),n.jsx(D.FormikProvider,{value:v,children:n.jsx(s.Flex,{ref:i,direction:"column",gap:"2",className:p,asChild:!0,children:n.jsxs("form",{id:x,onSubmit:v.handleSubmit,children:[!h&&n.jsx(s.Card,{children:n.jsxs(s.Flex,{direction:"column",gap:"1",children:[S,!f&&C]})}),w,!g&&n.jsxs(s.Flex,{justify:"end",gap:"2",children:[a&&n.jsx(s.Button,{type:"button",variant:"soft",onClick:u,children:a}),n.jsx(s.Button,{type:"submit",disabled:!v.isValid,children:o})]})]})})})})),St=c.memo(c.forwardRef((l,i)=>{const{submission:e,showFormDescription:t=!1,showFormTitle:r=!0}=l,o=F.useAppSelector(F.selectFormRevision(e.form_revision)),{sdk:a}=F.useSDK();if(!o)throw new Error(`Could not find revision ${e.form_revision} for submission ${e.offline_id}.`);const u=c.useMemo(()=>Ve(o,{readonly:!0}),[o]),d=c.useMemo(()=>{const h=F.selectSubmissionAttachments(e.offline_id)(a.store.getState())??[],f={};for(const p of h){const g=a.files.fetchFileFromUrl(p.file,p.file_sha1,p.file_name).then(v=>{if(!v.success)throw new Error(`Failed to download attachment ${p.file_name}.`);return v.body}),x=f[p.field_identifier];x?x.push(g):f[p.field_identifier]=[g]}return{...e.values,...f}},[a.files,a.store,e.offline_id,e.values]);return n.jsx(be,{ref:i,schema:u,values:d,hideDescription:!t,hideTitle:!r})})),rt={favoriteIcon:"_favoriteIcon_1bixi_1",regularIcon:"_regularIcon_1bixi_9"},Oe="organization:",qe="user:",zt=c.memo(c.forwardRef((l,i)=>{const{maxResults:e=20,...t}=l,[r,o]=c.useState(""),[a,u]=c.useState(""),{sdk:d}=F.useSDK(),h=c.useMemo(()=>{const w={maxResults:e,searchTerm:r};return a&&(a.startsWith(Oe)?w.owner_organization=parseInt(a.slice(Oe.length)):a.startsWith(qe)&&(w.owner_user=parseInt(a.slice(qe.length)))),w},[r,e,a]),f=F.useAppSelector(F.selectFilteredUserForms(h))??[],p=F.useAppSelector(F.selectUserFormMapping),g=c.useCallback(w=>{w.favorite?d.userForms.unfavorite(w.offline_id).then():d.userForms.favorite(w.offline_id).then()},[d]),x=c.useMemo(()=>{const w=d.store.getState(),M={};for(const A of Object.values(p)){const b=F.selectOrganization(A.owner_organization||-1)(w);b&&(M[`${Oe}${b.id}`]=b.name);const P=F.selectUser(A.owner_user||-1)(w);P&&(M[`${qe}${P.id}`]=P.username)}return Object.entries(M).map(([A,b])=>({itemContent:b,value:A}))},[p,d.store]),v=c.useCallback(w=>{o(w.currentTarget.value)},[]),S=(F.useAppSelector(F.selectNumberOfUserForms)||0)-f.length,C=f.length==e&&S>0?`Only the first ${e} results are shown (${S} hidden)`:S>0&&`${S} hidden forms`;return n.jsxs(s.Flex,{ref:i,direction:"column",gap:"2",children:[n.jsxs(s.Flex,{gap:"2",grow:"1",children:[n.jsx(s.Box,{grow:"1",asChild:!0,children:n.jsx(s.TextField.Root,{size:"3",children:n.jsx(s.TextField.Input,{placeholder:"Filter",value:r,onChange:v})})}),n.jsx(s.Select,{items:x,value:a,onValueChange:u,placeholder:"Owner",size:"large"})]}),f.length>0&&n.jsx(s.ButtonList.Root,{children:f.map(w=>n.jsx(Et,{...t,form:w,handleToggleFavorite:()=>g(w)},w.offline_id))}),n.jsx(s.Box,{px:"3",children:n.jsx(s.Text,{size:"2",severity:"info",children:C})})]})})),Et=l=>{var g;const{form:i,onSelectForm:e,isFavoriteEditable:t,handleToggleFavorite:r}=l,o=(g=F.useAppSelector(F.selectOrganization(i.owner_organization||-1)))==null?void 0:g.name,a=F.useAppSelector(F.selectUser(i.owner_user||-1)),u=F.useAppSelector(F.selectCurrentUser).id,d=!!a&&a.id===u,h=o??(d?"You":a==null?void 0:a.username)??"Unknown",f=c.useCallback(x=>{x.stopPropagation(),r()},[r]),p=n.jsx(s.ButtonList.Item,{onClick:()=>e(i),asChild:!0,children:n.jsxs(s.Flex,{justify:"between",gap:"2",py:"2",px:"3",...s.divButtonProps,children:[n.jsxs(s.Flex,{grow:"1",align:"center",gap:"2",children:[n.jsx(s.IconButton,{className:F.classNames(i.favorite?rt.favoriteIcon:rt.regularIcon),variant:"ghost",onClick:f,"aria-label":i.favorite?"Favorite form":"Standard form",disabled:!t,children:i.favorite?n.jsx(s.StarFilledIcon,{}):n.jsx(s.StarIcon,{})}),n.jsx(s.Text,{noWrap:!0,children:i.latestRevision.title}),i.latestRevision.description&&n.jsx(s.QuestionMarkCircledIcon,{})]}),h&&n.jsxs(s.Flex,{align:"center",gap:"2",children:[n.jsx(s.PersonIcon,{})," ",h]})]})});return i.latestRevision.description?n.jsx(s.Tooltip,{content:i.latestRevision.description,children:p},i.offline_id):p},st={submissionsContainer:"_submissionsContainer_9iirt_1",stopHorizontalOverflow:"_stopHorizontalOverflow_9iirt_6"},Mt=c.memo(function(i){var w;const{submission:e,onSubmissionClick:t,compact:r,labelType:o,rowDecorator:a}=i,u=F.useAppSelector(F.selectCurrentUser),d=F.useAppSelector(F.selectUser("created_by"in e?e.created_by:u.id)),h=Ne(e),f=F.isToday(h)?h.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):F.getLocalDateString(h),p=F.useAppSelector(F.selectFormRevision(e.form_revision));if(!p)throw new Error(`Could not find revision ${e.form_revision} for submission ${e.offline_id}.`);const g=(w=F.useAppSelector(F.selectLatestFormRevision(p.form)))==null?void 0:w.revision,x=F.useFileSrc({file:(d==null?void 0:d.profile.file)??null,fileSha1:(d==null?void 0:d.profile.file_sha1)??null}),v=(d==null?void 0:d.username.charAt(0).toUpperCase())??"?",I=p.revision===g,S=c.useCallback(()=>{t&&t({submission:e})},[e,t]),C=n.jsx(s.ButtonList.Item,{onClick:S,asChild:!0,children:n.jsxs(s.Flex,{grow:"1",width:"100%",p:"2",gap:"2",justify:"between",children:[n.jsxs(s.Flex,{gap:"2",align:"center",className:st.stopHorizontalOverflow,children:[n.jsx(s.Avatar,{src:x,size:"1",fallback:v}),n.jsx(s.Text,{size:"2",noWrap:!0,children:o==="creator"?(d||u).username:p.title})]}),n.jsxs(s.Flex,{gap:"2",align:"center",children:[!r&&(p.revision?n.jsx(s.Badge,{variant:"soft",severity:I?"primary":"info",children:r?p.revision.toString():`Revision #${p.revision}`}):!!g&&n.jsx(s.Badge,{children:"Original"})),n.jsx(s.Text,{size:"2",noWrap:!0,children:f})]})]})});return a?a(e,C):C}),Ne=l=>{const i="created_at"in l?l.created_at:l.submitted_at;return new Date(i)},At=c.memo(function(i){const{formId:e,submissions:t,compact:r=!1,className:o,after:a,variant:u="outline",...d}=i;if(!!e==!!t)throw new Error("Either formId or submissions must be provided, but not both.");const h=F.useAppSelector(t?()=>t:F.selectSubmissionsForForm(e)),f=c.useMemo(()=>h==null?void 0:h.sort((p,g)=>Ne(g).getTime()-Ne(p).getTime()),[h]);return n.jsx(s.ButtonList.Root,{className:F.classNames(st.submissionsContainer,o),size:"small",variant:u,before:!r&&n.jsxs(s.Text,{severity:"info",children:["There are ",((h==null?void 0:h.length)||0).toString()," submissions of this form."]}),after:a,children:f==null?void 0:f.map((p,g)=>n.jsx(Mt,{submission:p,compact:r,...d},g))})}),Pt=c.memo(function(i){const{name:e,render:t}=i,{submitForm:r}=D.useFormikContext(),[o,a,u]=D.useField(e);return c.useMemo(()=>{const d=h=>u.setValue(h,!1);return t({value:o.value,setValue:d,patchValue:r})},[r,u,o.value,t])}),Lt=c.memo(c.forwardRef((l,i)=>{const{children:e,schema:t,values:r,onPatch:o,onError:a,...u}=l,d=c.useMemo(()=>_e(t.fields,r),[t.fields,r]),h=c.useCallback(v=>{const I={};for(const S in v){const C=v[S];C!==d[S]&&C!==void 0&&(I[S]=C)}Ie(I)&&o(I)},[d,o]),f=c.useCallback(async v=>{const I=await nt(t,v);return I&&a(I),I},[t,a]),p=D.useFormik({initialValues:d,onSubmit:h,validate:f,validateOnBlur:!1,validateOnChange:!1}),{errors:g,resetForm:x}=p;return c.useEffect(()=>{Ie(g)&&x({values:d,errors:{}})},[g,d,x]),n.jsx(D.FormikProvider,{value:p,children:n.jsx("form",{...u,ref:i,onSubmit:p.handleSubmit,children:e})})})),ot={...Le,section:K},Dt=c.memo(function(i){const{field:e,setFieldType:t}=i,r=e.fieldTypeName,o=e.fieldTypeDescription,a=e.Icon;return n.jsxs(s.Flex,{gap:"4",align:"center",children:[n.jsx(s.Button,{type:"button",variant:"surface",onClick:t,style:{width:"135px"},children:n.jsxs(s.Flex,{gap:"3",align:"center",grow:"1",children:[n.jsx(a,{}),r]})}),n.jsx(s.Text,{children:o})]})}),lt=[["string","text"],["select","multi-select","upload"],["boolean","date","number","multi-string"]],Vt=lt.length-1,$t=c.memo(function(i){const{setFieldType:e}=i;return n.jsx(s.Flex,{direction:"column",gap:"3",children:lt.map((t,r)=>n.jsxs(s.Flex,{direction:"column",gap:"3",children:[n.jsx(s.Flex,{direction:"column",gap:"2",children:t.map(o=>n.jsx(Dt,{field:Le[o],setFieldType:()=>e(o)},o))}),r<Vt&&n.jsx(s.Separator,{size:"4"})]},r))})}),Bt=l=>i=>{if(!(!i||typeof i!="string")&&l.includes(i.trim()))return"This name is already taken."},_t=(l,i)=>{const e=[new Z({label:"Label",required:!0,maxLength:200,identifier:"label",fieldValidators:[Bt(l)]}),new k({label:"Description",required:!1,maxLength:1e3,identifier:"description"})];return i==="section"?e:[...e,new Q({label:"Required",description:null,required:!1,identifier:"required"})]},Ot=c.memo(function(i){const{fieldType:e,handleCancel:t,handleCreateField:r,defaultField:o,conditionalSourceFields:a}=i,u=ot[e],d=D.useFormikContext(),h=c.useMemo(()=>{const f=ke(d.values.fields).filter(g=>g!==(o==null?void 0:o.label));let p=_t(f,e);if(u===K){if(a===void 0)throw new Error("Conditional source fields must be provided when changing sections.");p=p.concat(u.getFieldCreationSchema(a))}else{if(!(u.prototype instanceof $))throw new Error(`Field must be an instance of BaseField. Got ${u}.`);p=[...p,...u.getFieldCreationSchema()]}return{fields:p,meta:{readonly:!1},title:null}},[d.values.fields,e,u,o==null?void 0:o.label,a]);return n.jsx(be,{schema:h,values:o,onSubmit:r,cancelText:o?void 0:"Back",onCancel:t})}),pe=c.memo(function(i){const{parentPath:e,index:t,children:r,initial:o,editing:a,conditionalSourceFields:u}=i,[d,h]=c.useState(),f=(o==null?void 0:o.type)??d,p=f?ot[f].fieldTypeName:void 0,{setFieldValue:g,values:x}=D.useFormikContext();if(a&&!o)throw new Error("Initial field must be provided if editing is true.");const v=!f&&!a&&!o,I=v?"Choose a field type":`${p} settings`,S=v?"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.`,C=c.useCallback(()=>h(void 0),[]),w=c.useCallback(b=>{h(void 0),b()},[]),M=c.useCallback((b,P)=>{const{label:B}=b;if(!f)throw new Error("Field type must be selected before creating a field.");if(!B||typeof B!="string")throw new Error("Label must be provided before creating a field.");const X=ue({type:f,...b,identifier:Je(b.identifier,B)}).serialize(),H=J(x,e);if(H===void 0)throw new Error("Parent path must point to an existing field.");let Y;if(!Array.isArray(H))throw new Error("Parent path must point to an array.");a?Y=gt(H,t,X):Y=Xe(H,t,X),g(e,Y).then(),P()},[a,f,x,e,g,t]),A=c.useCallback(b=>v?n.jsx($t,{setFieldType:h}):n.jsx(Ot,{conditionalSourceFields:u,handleCancel:C,handleCreateField:P=>M(P,b),fieldType:f,defaultField:o}),[u,C,M,o,v,f]);return n.jsx(s.Dialog,{onCloseInterrupt:w,title:I,description:S,content:A,children:r})}),at=({children:l})=>n.jsx(n.Fragment,{children:l}),dt=(l,i)=>({initial:l?i:"none",sm:l?"none":i}),ct=c.memo(function(i){const{remove:e,dragHandleProps:t,editProps:r,insertAfterProps:o,duplicateProps:a}=i,u=c.useMemo(()=>[{Wrapper:pe,wrapperProps:r,Icon:s.Pencil1Icon,text:"Edit"},{Icon:s.TrashIcon,buttonProps:{onClick:e},text:"Delete"},{Wrapper:pe,wrapperProps:a,Icon:s.CopyIcon,text:"Duplicate"},{Wrapper:pe,wrapperProps:o,Icon:s.PlusIcon,text:"Add after"},{Icon:d=>n.jsx("div",{...d,children:n.jsx(s.DragHandleDots2Icon,{})}),text:"Reorder",disableOnMobile:!0,buttonProps:{...t,asChild:!0}}],[t,a,r,o,e]);return n.jsxs(n.Fragment,{children:[n.jsx(s.Flex,{gap:"4",display:dt(!1,"flex"),children:u.map(d=>{const h=d.Wrapper??at;return n.jsx(h,{...d.wrapperProps,children:n.jsx(s.IconButton,{type:"button",variant:"ghost","aria-label":d.text,...d.buttonProps,children:n.jsx(d.Icon,{})})},d.text)})}),n.jsx(s.Box,{display:dt(!0,"block"),children:n.jsx(s.DropdownMenu,{trigger:n.jsx(s.IconButton,{variant:"ghost","aria-label":"Actions menu",children:n.jsx(s.DotsVerticalIcon,{})}),closeOnSelect:!1,items:u.map(d=>{var f;if(d.disableOnMobile)return null;const h=d.Wrapper??at;return{...d.buttonProps,onSelect:(f=d.buttonProps)==null?void 0:f.onClick,content:n.jsx(h,{...d.wrapperProps,children:n.jsxs(s.Flex,{gap:"2",align:"center",children:[n.jsx(d.Icon,{}),d.text]})})}}).filter(d=>d!==null)})})]})}),Ce="form-builder",qt=c.memo(function(i){const{field:e,index:t,sectionIndex:r,takenLabels:o,remove:a}=i,u=c.useMemo(()=>ue(e),[e]),d=fe(u,{formId:Ce,disabled:!0}),h=c.useMemo(()=>({index:t,parentPath:`fields.${r}.fields`,initial:e,editing:!0}),[e,t,r]),f=c.useMemo(()=>({parentPath:`fields.${r}.fields`,index:t+1,initial:{...e,label:Me(e.label??"",o),identifier:""}}),[e,t,r,o]),p=c.useMemo(()=>({parentPath:`fields.${r}.fields`,index:t+1,initial:void 0}),[t,r]);return n.jsx(U.Draggable,{draggableId:e.identifier,index:t,children:g=>n.jsx(s.Card,{ref:g.innerRef,...g.draggableProps,...g.dragHandleProps,mb:"4",children:n.jsxs(s.Flex,{gap:"4",justify:"between",align:"center",children:[d,n.jsx(ct,{remove:a,editProps:h,duplicateProps:f,insertAfterProps:p,dragHandleProps:g.dragHandleProps})]})})})}),Nt=c.memo(function(i){var P,B,X,H,Y,E,O;const{field:e,index:t,dropState:r}=i,o=(P=r[e.identifier])==null?void 0:P.disabled,{setFieldValue:a,values:u}=D.useFormikContext(),d=s.useAlertDialog(),h=ke(u.fields),f=c.useCallback((T,z)=>{for(const V of T){const L=z.indexOf(V);a(`fields.${L}.condition`,null).then(),a(`fields.${L}.conditional`,!1).then()}},[a]),p=c.useCallback(T=>{var L;const z=e.fields[T];if(!z)throw new Error("Could not find field to remove.");const V=[];for(const q of u.fields)((L=q.condition)==null?void 0:L.identifier)===z.identifier&&V.push(q);return{removing:z,affectedSections:V,action:()=>a(`fields.${t}.fields`,xe(e.fields,T))}},[e.fields,u.fields,a,t]),g=c.useCallback(T=>{const{affectedSections:z,action:V,removing:L}=p(T),q=()=>{V().then(),f(z,u.fields)};if(z.length>0){const We=z.map(Te=>Te.label).join(", ");return d({title:"Remove condition?",description:`${L.label} is being used as a condition, deleting it will remove the condition from the ${We} section(s).`,severity:"danger",actionText:"Remove",onAction:q})}q()},[p,f,u.fields,d]),x=c.useCallback(()=>{const z=e.fields.map((Se,Zt)=>p(Zt)).flatMap(Se=>Se.affectedSections),V=z.length?"Remove fields and conditions?":"Remove fields?",L=e.fields.length,q=z.map(Se=>Se.label).join(", "),We=z.length?`Deleting this section will remove the ${L} field(s) it contains and will remove the conditions from following sections: ${q}`:`Deleting this section will remove the ${L} field(s) it contains.`,Te=xe(u.fields,t),pt=()=>a("fields",Te);if(z.length>0)return d({title:V,description:We,severity:"danger",actionText:"Remove",onAction:()=>{pt().then(()=>{f(z,Te)})}});pt().then()},[e.fields,u.fields,t,p,a,d,f]),v=c.useCallback(T=>{const z=Me(T.label??"",h),V=T.fields.map(L=>{const q=Me(L.label,h);return{...L,label:q,identifier:Je(void 0,q)}});return{...T,label:z,fields:V,identifier:""}},[h]),I=c.useMemo(()=>({index:t,parentPath:"fields",initial:e,editing:!0,conditionalSourceFields:ve(u.fields,t)}),[e,t,u.fields]),S=c.useMemo(()=>({index:t+1,parentPath:"fields",initial:ye(),conditionalSourceFields:ve(u.fields,t+1)}),[t,u.fields]),C=c.useMemo(()=>({parentPath:`fields.${t}.fields`,index:e.fields.length,initial:void 0}),[e.fields.length,t]),w=c.useMemo(()=>({index:t+1,parentPath:"fields",initial:v(e),conditionalSourceFields:ve(u.fields,t+1)}),[v,e,t,u.fields]),M=c.useMemo(()=>{var T,z;return(z=Ze(u.fields,(T=e.condition)==null?void 0:T.identifier))==null?void 0:z.label},[(B=e.condition)==null?void 0:B.identifier,u.fields]),A=Array.isArray((X=e.condition)==null?void 0:X.value)?"contains all of":"equals";if(Fe((H=e.condition)==null?void 0:H.value))throw new Error("File values are not supported for conditions.");const b=Array.isArray((Y=e.condition)==null?void 0:Y.value)?(E=e.condition)==null?void 0:E.value.map(T=>typeof T=="string"?T:T.label).join(", "):(O=e.condition)==null?void 0:O.value.toString();return n.jsx(U.Draggable,{draggableId:e.identifier,index:t,children:T=>n.jsx(s.Card,{ref:T.innerRef,...T.draggableProps,...T.dragHandleProps,mb:"4",children:n.jsxs(s.Flex,{gap:"3",justify:"between",align:"center",children:[n.jsxs(s.Flex,{direction:"column",gap:"2",grow:"1",children:[n.jsxs(s.Flex,{direction:"column",children:[n.jsx(s.Heading,{as:"h3",size:"3",children:e.label}),n.jsx(s.Text,{className:he.description,children:e.description})]}),e.condition&&n.jsx(s.Text,{size:"1",children:n.jsxs(s.Em,{children:["Display only if ",n.jsx(s.Strong,{children:M})," ",A," ",n.jsx(s.Strong,{children:b})]})}),n.jsx(U.Droppable,{droppableId:e.identifier,type:"SECTION",isDropDisabled:o,children:z=>n.jsxs(s.Flex,{ref:z.innerRef,...z.droppableProps,direction:"column",gap:"0",children:[e.fields.map((V,L)=>n.jsx(qt,{field:V,index:L,sectionIndex:t,remove:()=>g(L),takenLabels:h},V.identifier)),z.placeholder,n.jsx(pe,{...C,children:n.jsxs(s.Button,{type:"button",variant:"outline",children:[n.jsx(s.PlusIcon,{})," Add a field"]})})]})})]}),n.jsx(ct,{remove:x,insertAfterProps:S,dragHandleProps:T.dragHandleProps,editProps:I,duplicateProps:w})]})})})}),Wt=(l,i)=>{var t;const e={...l};switch(i.type){case"release":for(const r in e)e[r].disabled=!1;return e;case"hold":for(const r in e)(t=e[r])!=null&&t.conditionFields.has(i.fieldId)&&(e[r].disabled=!0);return e;case"update":return i.state}},jt=(l,i)=>{if(i)for(let e=0;e<l.length;e++){const t=l[e];if(t){for(const r of t.fields)if(r.identifier===i)return e}}},ut=l=>{var e,t,r;const i={};for(let o=0;o<l.length;o++){const a=l[o];if(!a)throw new Error("Field is undefined.");const u=o>0?(e=i[l[o-1].identifier])==null?void 0:e.conditionFields:void 0,d=new Set(u);(t=a.condition)!=null&&t.identifier&&d.add(a.condition.identifier),i[a.identifier]={disabled:!1,conditionFields:d,conditionIndex:jt(l,(r=a.condition)==null?void 0:r.identifier),index:o,label:a.label}}return i},ft=(l,i)=>{for(const[e,t]of Object.entries(l))if(t.identifier===i)return[t,e]},Ht=c.memo(function(){const{values:i,setFieldValue:e}=D.useFormikContext(),[t,r]=c.useReducer(Wt,i.fields,ut),{showInfo:o}=s.useToast();c.useEffect(()=>{r({type:"update",state:ut(i.fields)})},[r,i.fields]);const a=c.useCallback(h=>{h.type==="SECTION"&&r({type:"hold",fieldId:h.draggableId})},[]),u=c.useCallback(h=>{const{source:f,destination:p,type:g,reason:x,draggableId:v}=h;if(r({type:"release"}),!p||x==="CANCEL")return;if(g==="ROOT"){const M=t[v];if(!M)throw new Error("Could not find section context.");let A=typeof M.conditionIndex<"u"?Math.max(M.conditionIndex+1,p.index):p.index;for(const b of Object.values(t))b.conditionIndex===f.index&&(A=Math.min(A,b.index-1));return A!=p.index&&o({title:"Reordered sections",description:"Sections with conditions must be below the fields they reference."}),e("fields",Ee(i.fields,f.index,A))}if(g!=="SECTION")throw new Error("Unexpected droppable type.");const[I,S]=ft(i.fields,f.droppableId)??[],[C,w]=ft(i.fields,p.droppableId)??[];if(!(I!=null&&I.fields)||!C)throw new Error("Could not find section with fields.");if(I.identifier===C.identifier)e(`fields.${S}.fields`,Ee(I.fields,f.index,p.index)).then();else{const M=I.fields[f.index];if(!M)throw new Error("Could not find field to reorder.");e(`fields.${S}.fields`,xe(I.fields,f.index)).then(),e(`fields.${w}.fields`,Xe(C.fields,p.index,M)).then()}},[i.fields,e,t,o]),d=c.useMemo(()=>({index:i.fields.length,parentPath:"fields",initial:ye(),conditionalSourceFields:ve(i.fields,i.fields.length)}),[i.fields]);return n.jsx(U.DragDropContext,{onDragStart:a,onDragEnd:u,children:n.jsx(U.Droppable,{droppableId:"droppable",type:"ROOT",children:h=>n.jsxs(s.Flex,{ref:h.innerRef,...h.droppableProps,direction:"column",gap:"0",children:[i.fields.map((f,p)=>n.jsx(Nt,{field:f,index:p,dropState:t},f.label)),h.placeholder,n.jsx(pe,{...d,children:n.jsxs(s.Button,{type:"button",variant:"outline",children:[n.jsx(s.PlusIcon,{})," Add a section"]})})]})})})}),Ut={title:"",description:"",fields:[]},Gt=new Z({label:"Title",minLength:0,maxLength:100,required:!0,identifier:"title"}),Kt={formId:Ce,placeholder:"Give your form a title."},Yt=new k({label:"Description",minLength:0,maxLength:1e3,required:!1,identifier:"description"}),Qt={formId:Ce,placeholder:"Explain the purpose of this form."},Xt=()=>{alert("This is a form preview, your data will not be saved.")},Jt=c.memo(c.forwardRef((l,i)=>{const{onCancel:e,onSave:t,revision:r}=l,o=r?"Edit form":"Create a new form",{heading:a=o}=l,u=c.useCallback(x=>{const v={};if(x.title||(v.title="Title is required."),(!x.fields||x.fields.length===0)&&(v.fields="At least one field is required."),Ie(v))return v},[]),d=D.useFormik({initialValues:mt(r)??Ut,validate:u,onSubmit:x=>t(x),validateOnChange:!1,validateOnBlur:!1}),h=c.useMemo(()=>Ve(d.values),[d.values]),f=fe(Gt,Kt),p=fe(Yt,Qt),g=c.useMemo(()=>typeof a=="object"?a:n.jsx(s.Heading,{children:a}),[a]);return n.jsx(s.Tabs.Root,{ref:i,defaultValue:"edit",children:n.jsxs(s.Flex,{direction:"column",gap:"2",children:[n.jsxs(s.Tabs.List,{children:[n.jsx(s.Tabs.Trigger,{value:"edit",children:"Edit"}),n.jsx(s.Tabs.Trigger,{value:"preview",children:"Preview"})]}),n.jsxs(s.Tabs.Content,{value:"edit",children:[g,n.jsxs(s.Text,{children:["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"," ",n.jsx("em",{children:"Preview"})," tab, but"," ",n.jsx("strong",{children:"field values entered on this page will not be saved."})]}),n.jsx(s.Flex,{asChild:!0,direction:"column",gap:"2",mt:"3",children:n.jsxs("form",{id:Ce,onSubmit:d.handleSubmit,children:[n.jsxs(D.FormikProvider,{value:d,children:[f,p,n.jsx(Ht,{}),n.jsx(s.Text,{severity:"danger",size:"1",children:typeof d.errors.fields=="string"&&d.errors.fields})]}),n.jsxs(s.Flex,{justify:"end",gap:"2",children:[n.jsx(s.Button,{type:"button",variant:"soft",onClick:e,children:"Cancel"}),n.jsx(s.Button,{type:"submit",disabled:!d.isValid,children:"Save"})]})]})})]}),n.jsx(s.Tabs.Content,{value:"preview",children:n.jsx(be,{schema:h,onSubmit:Xt})})]})})}));y.BooleanField=Q,y.BooleanInput=He,y.DateField=me,y.DateInput=Ge,y.FieldSection=K,y.FormBrowser=zt,y.FormBuilder=Jt,y.FormRenderer=be,y.FormSubmissionBrowser=At,y.FormSubmissionViewer=St,y.MultiSelectField=ce,y.MultiSelectInput=tt,y.MultiStringField=ae,y.MultiStringInput=Re,y.NumberField=G,y.NumberInput=Ue,y.PatchField=Pt,y.PatchFormProvider=Lt,y.SelectField=de,y.SelectInput=Qe,y.StringField=Z,y.StringInput=Ke,y.TextField=k,y.TextInput=Ye,y.deserialize=ue,y.deserializeField=De,y.formRevisionToSchema=Ve,y.isConditionMet=$e,y.useFieldInput=fe,y.useFieldInputs=Be,y.valueIsFile=Fe,Object.defineProperty(y,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Form functionality for Overmap",
4
4
  "author": "Wôrdn Inc.",
5
5
  "license": "UNLICENSED",
6
- "version": "1.0.3-form-improvements.5",
6
+ "version": "1.0.3-form-improvements.6",
7
7
  "type": "module",
8
8
  "main": "dist/forms.umd.cjs",
9
9
  "module": "dist/forms.js",