@overmap-ai/forms 1.0.4-conditional-arrows-2.7 → 1.0.4-conditional-arrows-2.8
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 +197 -200
- package/dist/forms.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/forms.js
CHANGED
|
@@ -4,7 +4,7 @@ var m = (s, i, e) => (Kt(s, typeof i != "symbol" ? i + "" : i, e), e);
|
|
|
4
4
|
import { jsx as r, jsxs as g, Fragment as Je } from "react/jsx-runtime";
|
|
5
5
|
import { Flex as y, Text as $, useSeverityColor as me, Checkbox as Yt, CheckCircledIcon as Zt, TextField as ae, FontFamilyIcon as Xt, CalendarIcon as Qt, InputIcon as Jt, TextArea as ei, RowsIcon as ti, Select as It, Box as ge, IconButton as ce, PlusIcon as Oe, Badge as Ue, Cross1Icon as Ct, ListBulletIcon as ii, DropdownMenuIcon as ni, MultiSelect as ri, CheckboxIcon as oi, Card as we, Heading as Me, Button as G, UploadIcon as Ft, ButtonList as Re, divButtonProps as si, StarFilledIcon as li, StarIcon as ai, QuestionMarkCircledIcon as ci, PersonIcon as di, Tooltip as ui, Avatar as fi, Separator as mi, Dialog as pi, Pencil1Icon as hi, TrashIcon as gi, CopyIcon as bi, DragHandleDots2Icon as yi, DropdownMenu as wi, DotsVerticalIcon as vi, useAlertDialog as xi, Em as Ii, Strong as pt, useToast as Ci, Tabs as Q } from "@overmap-ai/blocks";
|
|
6
6
|
import { useField as et, useFormikContext as pe, useFormik as tt, FormikProvider as it } from "formik";
|
|
7
|
-
import Fi, { useMemo as x, memo as
|
|
7
|
+
import Fi, { useMemo as x, memo as z, useCallback as S, useState as de, useEffect as ve, useRef as Ti, forwardRef as xe, useReducer as Si } from "react";
|
|
8
8
|
import { DragDropContext as Tt, Droppable as nt, Draggable as rt } from "@hello-pangea/dnd";
|
|
9
9
|
import { slugify as zi, useAppSelector as _, selectFormRevision as St, useSDK as zt, selectSubmissionAttachments as Ei, selectFilteredUserForms as Ai, selectUserFormMapping as Li, selectOrganization as Et, selectUser as ot, selectNumberOfUserForms as Pi, selectCurrentUser as At, classNames as Lt, isToday as ki, getLocalDateString as $i, selectLatestFormRevision as Vi, useFileSrc as Di, selectSubmissionsForForm as _i, selectAppearance as Oi } from "@overmap-ai/core";
|
|
10
10
|
import ue from "lodash.get";
|
|
@@ -129,7 +129,7 @@ const Mi = "_description_17zed_1", Ne = {
|
|
|
129
129
|
},
|
|
130
130
|
{ ...n, "aria-labelledby": p }
|
|
131
131
|
];
|
|
132
|
-
}, Ri = [!0, "true"], Ni =
|
|
132
|
+
}, Ri = [!0, "true"], Ni = z(function(i) {
|
|
133
133
|
const [{ inputId: e, labelId: t, severity: n, helpText: o, label: a, fieldProps: c }, l] = H(i), f = me(n), d = Ri.includes(c.value);
|
|
134
134
|
return /* @__PURE__ */ r(W, { helpText: o, severity: n, children: /* @__PURE__ */ r(
|
|
135
135
|
q,
|
|
@@ -181,7 +181,7 @@ const Mi = "_description_17zed_1", Ne = {
|
|
|
181
181
|
};
|
|
182
182
|
m(J, "fieldTypeName", "Checkbox"), m(J, "fieldTypeDescription", "Perfect for both optional and required yes/no questions."), m(J, "Icon", Zt);
|
|
183
183
|
let fe = J;
|
|
184
|
-
const Bi =
|
|
184
|
+
const Bi = z(function(i) {
|
|
185
185
|
const [{ inputId: e, labelId: t, severity: n, helpText: o, label: a, fieldProps: c, field: l }, f] = H(i), d = me(n);
|
|
186
186
|
return /* @__PURE__ */ r(W, { helpText: o, severity: n, children: /* @__PURE__ */ r(q, { severity: n, inputId: e, labelId: t, label: a, children: /* @__PURE__ */ r(
|
|
187
187
|
ae.Input,
|
|
@@ -272,7 +272,7 @@ const Bi = S(function(i) {
|
|
|
272
272
|
};
|
|
273
273
|
m(B, "fieldTypeName", "Number"), m(B, "fieldTypeDescription", "Allows specifying a number within a given range."), m(B, "Icon", Xt), 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);
|
|
274
274
|
let Y = B;
|
|
275
|
-
const qi =
|
|
275
|
+
const qi = z(function(i) {
|
|
276
276
|
const [{ inputId: e, labelId: t, severity: n, helpText: o, label: a, fieldProps: c }, l] = H(i), f = me(n), d = c.value ? c.value.split("T")[0] : "";
|
|
277
277
|
return /* @__PURE__ */ r(W, { helpText: o, severity: n, children: /* @__PURE__ */ r(q, { severity: n, inputId: e, labelId: t, label: a, children: /* @__PURE__ */ r(ae.Input, { ...l, ...c, type: "date", id: e, color: f, value: d }) }) });
|
|
278
278
|
}), ee = class ee extends M {
|
|
@@ -366,7 +366,7 @@ m(Ee, "_validateMax", (e, t) => {
|
|
|
366
366
|
const { minimum_length: n } = t;
|
|
367
367
|
return typeof n != "number" ? null : n > e ? "Maximum cannot be less than minimum." : null;
|
|
368
368
|
});
|
|
369
|
-
const Wi =
|
|
369
|
+
const Wi = z(function(i) {
|
|
370
370
|
const [{ inputId: e, labelId: t, severity: n, helpText: o, label: a, fieldProps: c, field: l }, f] = H(i), d = me(n);
|
|
371
371
|
return /* @__PURE__ */ r(W, { helpText: o, severity: n, children: /* @__PURE__ */ r(q, { severity: n, inputId: e, labelId: t, label: a, children: /* @__PURE__ */ r(ae.Input, { ...f, ...c, type: l.inputType, id: e, color: d }) }) });
|
|
372
372
|
}), te = class te extends Ee {
|
|
@@ -391,7 +391,7 @@ const Wi = S(function(i) {
|
|
|
391
391
|
};
|
|
392
392
|
m(te, "fieldTypeName", "Short Text"), m(te, "fieldTypeDescription", "Short text fields can hold up to 500 characters on a single line."), m(te, "Icon", Jt);
|
|
393
393
|
let be = te;
|
|
394
|
-
const Hi =
|
|
394
|
+
const Hi = z(function(i) {
|
|
395
395
|
const [{ inputId: e, labelId: t, severity: n, helpText: o, label: a, fieldProps: c }, l] = H(i);
|
|
396
396
|
return /* @__PURE__ */ r(W, { helpText: o, severity: n, children: /* @__PURE__ */ r(q, { severity: n, inputId: e, labelId: t, label: a, children: /* @__PURE__ */ r(ei, { ...l, ...c, resize: "vertical", id: e, severity: n }) }) });
|
|
397
397
|
}), ie = class ie extends Ee {
|
|
@@ -414,11 +414,11 @@ const Hi = S(function(i) {
|
|
|
414
414
|
};
|
|
415
415
|
m(ie, "fieldTypeName", "Paragraph"), m(ie, "fieldTypeDescription", "Paragraph fields can hold up to 5000 characters and can have multiple lines."), m(ie, "Icon", ti);
|
|
416
416
|
let ye = ie;
|
|
417
|
-
const ji =
|
|
417
|
+
const ji = z(function(i) {
|
|
418
418
|
const [{ inputId: e, labelId: t, severity: n, helpText: o, label: a, fieldProps: c, field: l }, f] = H(i), { onChange: d, onBlur: u } = c, p = x(
|
|
419
419
|
() => l.options.map((b) => ({ value: b.value, itemContent: b.label })),
|
|
420
420
|
[l.options]
|
|
421
|
-
), h =
|
|
421
|
+
), h = S(
|
|
422
422
|
(b) => {
|
|
423
423
|
d(b), u(b);
|
|
424
424
|
},
|
|
@@ -494,35 +494,35 @@ const $t = (s, i) => {
|
|
|
494
494
|
for (; i.includes(t); )
|
|
495
495
|
t = `${s} (${++e})`;
|
|
496
496
|
return t;
|
|
497
|
-
}, Ki =
|
|
498
|
-
const [{ inputId: e, labelId: t, severity: n, helpText: o, label: a, fieldProps: c }, l] = H(i), f = me(n), d = x(() => Array.isArray(c.value) ? c.value : [], [c.value]), { onChange: u, onBlur: p } = c, h = `${e}-droppable`, { disabled: b } = l, [
|
|
497
|
+
}, Ki = z(function(i) {
|
|
498
|
+
const [{ inputId: e, labelId: t, severity: n, helpText: o, label: a, fieldProps: c }, l] = H(i), f = me(n), d = x(() => Array.isArray(c.value) ? c.value : [], [c.value]), { onChange: u, onBlur: p } = c, h = `${e}-droppable`, { disabled: b } = l, [E, I] = de(""), [C, w] = de(""), V = C || o, L = C ? "red" : f, v = S(
|
|
499
499
|
(A) => {
|
|
500
500
|
u(A), p(A);
|
|
501
501
|
},
|
|
502
502
|
[u, p]
|
|
503
|
-
), P =
|
|
503
|
+
), P = S(
|
|
504
504
|
(A) => {
|
|
505
505
|
d.findIndex((N) => N.value === A.target.value.trim()) >= 0 ? w("All options must be unique") : A.target.value ? w("") : w("Option cannot be empty"), I(A.target.value);
|
|
506
506
|
},
|
|
507
507
|
[I, d]
|
|
508
|
-
), R =
|
|
508
|
+
), R = S(() => {
|
|
509
509
|
if (C)
|
|
510
510
|
return;
|
|
511
|
-
if (!
|
|
511
|
+
if (!E.trim())
|
|
512
512
|
return w("Option cannot be empty");
|
|
513
|
-
const A =
|
|
513
|
+
const A = E.trim();
|
|
514
514
|
v([...d, { value: A, label: A }]), I("");
|
|
515
|
-
}, [
|
|
515
|
+
}, [E, C, v, d]), X = S(
|
|
516
516
|
(A) => {
|
|
517
517
|
A.key === "Enter" && (A.preventDefault(), R());
|
|
518
518
|
},
|
|
519
519
|
[R]
|
|
520
|
-
), j =
|
|
520
|
+
), j = S(
|
|
521
521
|
(A) => {
|
|
522
522
|
v(Le(d, A));
|
|
523
523
|
},
|
|
524
524
|
[d, v]
|
|
525
|
-
), U =
|
|
525
|
+
), U = S(
|
|
526
526
|
(A) => {
|
|
527
527
|
if (!A.destination)
|
|
528
528
|
return;
|
|
@@ -539,7 +539,7 @@ const $t = (s, i) => {
|
|
|
539
539
|
placeholder: "Press enter to add a new option",
|
|
540
540
|
...l,
|
|
541
541
|
...c,
|
|
542
|
-
value:
|
|
542
|
+
value: E,
|
|
543
543
|
onChange: P,
|
|
544
544
|
onKeyDown: X,
|
|
545
545
|
id: e,
|
|
@@ -692,8 +692,8 @@ const re = class re extends _t {
|
|
|
692
692
|
};
|
|
693
693
|
m(re, "fieldTypeName", "Dropdown"), m(re, "fieldTypeDescription", "Allows the user to select a single option from a list of options."), m(re, "Icon", ni);
|
|
694
694
|
let ke = re;
|
|
695
|
-
const Yi = (s) => s ? Array.isArray(s) ? s : [s] : [], Zi =
|
|
696
|
-
const [{ inputId: e, labelId: t, severity: n, helpText: o, label: a, fieldProps: c, field: l }, f] = H(i), { onChange: d, onBlur: u } = c, p = x(() => Yi(c.value), [c.value]), h =
|
|
695
|
+
const Yi = (s) => s ? Array.isArray(s) ? s : [s] : [], Zi = z(function(i) {
|
|
696
|
+
const [{ inputId: e, labelId: t, severity: n, helpText: o, label: a, fieldProps: c, field: l }, f] = H(i), { onChange: d, onBlur: u } = c, p = x(() => Yi(c.value), [c.value]), h = S(
|
|
697
697
|
(b) => {
|
|
698
698
|
d(b), u(b);
|
|
699
699
|
},
|
|
@@ -738,7 +738,7 @@ const Yi = (s) => s ? Array.isArray(s) ? s : [s] : [], Zi = S(function(i) {
|
|
|
738
738
|
};
|
|
739
739
|
m(oe, "fieldTypeName", "Multi-select"), m(oe, "fieldTypeDescription", "Allows the user to select a multiple options from a list of options."), m(oe, "Icon", oi);
|
|
740
740
|
let $e = oe;
|
|
741
|
-
const Xi =
|
|
741
|
+
const Xi = z(function({ field: i, ...e }) {
|
|
742
742
|
const [{ value: t }] = et(i.options.clonedFieldIdentifier), n = x(() => {
|
|
743
743
|
const o = i.options.getFieldToClone(t);
|
|
744
744
|
return o ? Be(o) : null;
|
|
@@ -767,7 +767,7 @@ class Qi extends Ve {
|
|
|
767
767
|
super(i, Xi);
|
|
768
768
|
}
|
|
769
769
|
}
|
|
770
|
-
const Ji =
|
|
770
|
+
const Ji = z(function(i) {
|
|
771
771
|
const { field: e, ...t } = i, { label: n, description: o, fields: a, condition: c } = e, { values: l, setFieldValue: f } = pe(), d = c != null && c.identifier ? ue(l, c.identifier) : void 0, u = x(() => Rt(c, d), [c, d]);
|
|
772
772
|
ve(() => {
|
|
773
773
|
if (!u)
|
|
@@ -893,12 +893,12 @@ const en = "_previewImage_1ig84_1", tn = {
|
|
|
893
893
|
for (; e > 1024 && t < i.length - 1; )
|
|
894
894
|
e /= 1024, t++;
|
|
895
895
|
return new Intl.NumberFormat([], { maximumFractionDigits: 2, style: "unit", unit: i[t] }).format(e);
|
|
896
|
-
}, nn =
|
|
896
|
+
}, nn = z(function(i) {
|
|
897
897
|
var L;
|
|
898
|
-
const [{ inputId: e, labelId: t, severity: n, helpText: o, label: a, fieldProps: c, field: l }, f] = H(i), { onChange: d } = c, u = me(n), p = Ti(null), { value: h } = c, b = x(() => o || (l.maxFileSize ? `Maximum file size: ${lt(l.maxFileSize)}` : null), [l.maxFileSize, o]),
|
|
898
|
+
const [{ inputId: e, labelId: t, severity: n, helpText: o, label: a, fieldProps: c, field: l }, f] = H(i), { onChange: d } = c, u = me(n), p = Ti(null), { value: h } = c, b = x(() => o || (l.maxFileSize ? `Maximum file size: ${lt(l.maxFileSize)}` : null), [l.maxFileSize, o]), E = S(() => {
|
|
899
899
|
var v;
|
|
900
900
|
(v = p.current) == null || v.click();
|
|
901
|
-
}, []), I =
|
|
901
|
+
}, []), I = S(
|
|
902
902
|
(v) => {
|
|
903
903
|
const P = [...h];
|
|
904
904
|
P.splice(v, 1), d({ target: { files: P } });
|
|
@@ -907,7 +907,7 @@ const en = "_previewImage_1ig84_1", tn = {
|
|
|
907
907
|
), C = h ? "Select new files" : "Select files", w = h ? "Select new file" : "Select a file", V = l.maxFiles > 1 ? C : w;
|
|
908
908
|
return /* @__PURE__ */ g(y, { direction: "column", gap: "2", children: [
|
|
909
909
|
/* @__PURE__ */ r(W, { helpText: b, severity: n, children: /* @__PURE__ */ g(q, { severity: n, inputId: e, labelId: t, label: a, children: [
|
|
910
|
-
/* @__PURE__ */ r(y, { direction: "row", gap: "2", children: /* @__PURE__ */ r(ge, { width: "max-content", asChild: !0, children: /* @__PURE__ */ g(G, { ...f, onClick:
|
|
910
|
+
/* @__PURE__ */ r(y, { direction: "row", gap: "2", children: /* @__PURE__ */ r(ge, { width: "max-content", asChild: !0, children: /* @__PURE__ */ g(G, { ...f, onClick: E, children: [
|
|
911
911
|
/* @__PURE__ */ r(Ft, {}),
|
|
912
912
|
" ",
|
|
913
913
|
V
|
|
@@ -939,7 +939,7 @@ const en = "_previewImage_1ig84_1", tn = {
|
|
|
939
939
|
P
|
|
940
940
|
)) })
|
|
941
941
|
] });
|
|
942
|
-
}), rn =
|
|
942
|
+
}), rn = z(function({ file: i, field: e, onRemove: t, disabled: n }) {
|
|
943
943
|
const [o, a] = de(null), c = x(() => o && e.getError([o]), [e, o]), { url: l, name: f, size: d } = x(() => {
|
|
944
944
|
let u = null, p, h;
|
|
945
945
|
return o != null && o.type.startsWith("image/") && (u = URL.createObjectURL(o)), o ? (p = o.name, h = lt(o.size)) : (p = "Downloading...", h = "..."), { url: u, name: p, size: h };
|
|
@@ -1126,7 +1126,7 @@ const De = (s, i) => x(() => !i || !s ? null : s.getInput(i), [s, i]), Nt = (s,
|
|
|
1126
1126
|
return e;
|
|
1127
1127
|
}, on = [null, void 0], ct = (s, i) => s.reduce((e, t) => t instanceof Z ? { ...e, ...ct(t.fields, i) } : (on.includes(ue(e, t.getId())) && st(e, t.getId(), ""), e), i), sn = () => {
|
|
1128
1128
|
throw new Error("onSubmit must be provided if form is not readonly.");
|
|
1129
|
-
}, dt =
|
|
1129
|
+
}, dt = z(
|
|
1130
1130
|
xe((s, i) => {
|
|
1131
1131
|
const {
|
|
1132
1132
|
schema: e,
|
|
@@ -1147,7 +1147,7 @@ const De = (s, i) => x(() => !i || !s ? null : s.getInput(i), [s, i]), Nt = (s,
|
|
|
1147
1147
|
// only validate the entire form on submit
|
|
1148
1148
|
validateOnBlur: !1,
|
|
1149
1149
|
validateOnChange: !1
|
|
1150
|
-
}), { dirty:
|
|
1150
|
+
}), { dirty: E } = b, I = x(
|
|
1151
1151
|
() => typeof e.title == "string" ? /* @__PURE__ */ r(Me, { children: e.title }) : e.title,
|
|
1152
1152
|
[e.title]
|
|
1153
1153
|
), C = x(
|
|
@@ -1155,8 +1155,8 @@ const De = (s, i) => x(() => !i || !s ? null : s.getInput(i), [s, i]), Nt = (s,
|
|
|
1155
1155
|
[e.description]
|
|
1156
1156
|
), w = Nt(e.fields, { formId: h, disabled: p });
|
|
1157
1157
|
return ve(() => {
|
|
1158
|
-
|
|
1159
|
-
}, [
|
|
1158
|
+
E && l && l();
|
|
1159
|
+
}, [E, l]), /* @__PURE__ */ r(it, { value: b, children: /* @__PURE__ */ r(y, { ref: i, direction: "column", gap: "2", className: u, asChild: !0, children: /* @__PURE__ */ g("form", { id: h, onSubmit: b.handleSubmit, children: [
|
|
1160
1160
|
!f && /* @__PURE__ */ r(we, { children: /* @__PURE__ */ g(y, { direction: "column", gap: "1", children: [
|
|
1161
1161
|
I,
|
|
1162
1162
|
!d && C
|
|
@@ -1168,7 +1168,7 @@ const De = (s, i) => x(() => !i || !s ? null : s.getInput(i), [s, i]), Nt = (s,
|
|
|
1168
1168
|
] })
|
|
1169
1169
|
] }) }) });
|
|
1170
1170
|
})
|
|
1171
|
-
), Nn =
|
|
1171
|
+
), Nn = z(
|
|
1172
1172
|
xe((s, i) => {
|
|
1173
1173
|
const { submission: e, showFormDescription: t = !1, showFormTitle: n = !0 } = s, o = _(St(e.form_revision)), { sdk: a } = zt();
|
|
1174
1174
|
if (!o)
|
|
@@ -1201,12 +1201,12 @@ const De = (s, i) => x(() => !i || !s ? null : s.getInput(i), [s, i]), Nt = (s,
|
|
|
1201
1201
|
), ln = "_favoriteIcon_1bixi_1", an = "_regularIcon_1bixi_9", bt = {
|
|
1202
1202
|
favoriteIcon: ln,
|
|
1203
1203
|
regularIcon: an
|
|
1204
|
-
}, He = "organization:", je = "user:", Bn =
|
|
1204
|
+
}, He = "organization:", je = "user:", Bn = z(
|
|
1205
1205
|
xe((s, i) => {
|
|
1206
1206
|
const { maxResults: e = 20, ...t } = s, [n, o] = de(""), [a, c] = de(""), { sdk: l } = zt(), f = x(() => {
|
|
1207
1207
|
const w = { maxResults: e, searchTerm: n };
|
|
1208
1208
|
return a && (a.startsWith(He) ? w.owner_organization = parseInt(a.slice(He.length)) : a.startsWith(je) && (w.owner_user = parseInt(a.slice(je.length)))), w;
|
|
1209
|
-
}, [n, e, a]), d = _(Ai(f)) ?? [], u = _(Li), p =
|
|
1209
|
+
}, [n, e, a]), d = _(Ai(f)) ?? [], u = _(Li), p = S(
|
|
1210
1210
|
(w) => {
|
|
1211
1211
|
w.favorite ? l.userForms.unfavorite(w.offline_id).then() : l.userForms.favorite(w.offline_id).then();
|
|
1212
1212
|
},
|
|
@@ -1220,7 +1220,7 @@ const De = (s, i) => x(() => !i || !s ? null : s.getInput(i), [s, i]), Nt = (s,
|
|
|
1220
1220
|
P && (V[`${je}${P.id}`] = P.username);
|
|
1221
1221
|
}
|
|
1222
1222
|
return Object.entries(V).map(([L, v]) => ({ itemContent: v, value: L }));
|
|
1223
|
-
}, [u, l.store]), b =
|
|
1223
|
+
}, [u, l.store]), b = S((w) => {
|
|
1224
1224
|
o(w.currentTarget.value);
|
|
1225
1225
|
}, []), I = (_(Pi) || 0) - d.length, C = d.length == e && I > 0 ? `Only the first ${e} results are shown (${I} hidden)` : I > 0 && `${I} hidden forms`;
|
|
1226
1226
|
return /* @__PURE__ */ g(y, { ref: i, direction: "column", gap: "2", children: [
|
|
@@ -1251,7 +1251,7 @@ const De = (s, i) => x(() => !i || !s ? null : s.getInput(i), [s, i]), Nt = (s,
|
|
|
1251
1251
|
})
|
|
1252
1252
|
), cn = (s) => {
|
|
1253
1253
|
var p;
|
|
1254
|
-
const { form: i, onSelectForm: e, isFavoriteEditable: t, handleToggleFavorite: n } = s, o = (p = _(Et(i.owner_organization || -1))) == null ? void 0 : p.name, a = _(ot(i.owner_user || -1)), c = _(At).id, l = !!a && a.id === c, f = o ?? (l ? "You" : a == null ? void 0 : a.username) ?? "Unknown", d =
|
|
1254
|
+
const { form: i, onSelectForm: e, isFavoriteEditable: t, handleToggleFavorite: n } = s, o = (p = _(Et(i.owner_organization || -1))) == null ? void 0 : p.name, a = _(ot(i.owner_user || -1)), c = _(At).id, l = !!a && a.id === c, f = o ?? (l ? "You" : a == null ? void 0 : a.username) ?? "Unknown", d = S(
|
|
1255
1255
|
(h) => {
|
|
1256
1256
|
h.stopPropagation(), n();
|
|
1257
1257
|
},
|
|
@@ -1282,7 +1282,7 @@ const De = (s, i) => x(() => !i || !s ? null : s.getInput(i), [s, i]), Nt = (s,
|
|
|
1282
1282
|
}, dn = "_submissionsContainer_9iirt_1", un = "_stopHorizontalOverflow_9iirt_6", qt = {
|
|
1283
1283
|
submissionsContainer: dn,
|
|
1284
1284
|
stopHorizontalOverflow: un
|
|
1285
|
-
}, fn =
|
|
1285
|
+
}, fn = z(function(i) {
|
|
1286
1286
|
var w;
|
|
1287
1287
|
const { submission: e, onSubmissionClick: t, compact: n, labelType: o, rowDecorator: a } = i, c = _(At), l = _(ot("created_by" in e ? e.created_by : c.id)), f = Qe(e), d = ki(f) ? f.toLocaleTimeString([], {
|
|
1288
1288
|
hour: "2-digit",
|
|
@@ -1293,7 +1293,7 @@ const De = (s, i) => x(() => !i || !s ? null : s.getInput(i), [s, i]), Nt = (s,
|
|
|
1293
1293
|
const p = (w = _(Vi(u.form))) == null ? void 0 : w.revision, h = Di({
|
|
1294
1294
|
file: (l == null ? void 0 : l.profile.file) ?? null,
|
|
1295
1295
|
fileSha1: (l == null ? void 0 : l.profile.file_sha1) ?? null
|
|
1296
|
-
}), b = (l == null ? void 0 : l.username.charAt(0).toUpperCase()) ?? "?",
|
|
1296
|
+
}), b = (l == null ? void 0 : l.username.charAt(0).toUpperCase()) ?? "?", E = u.revision === p, I = Fi.useCallback(() => {
|
|
1297
1297
|
t && t({ submission: e });
|
|
1298
1298
|
}, [e, t]), C = /* @__PURE__ */ r(Re.Item, { onClick: I, asChild: !0, children: /* @__PURE__ */ g(y, { grow: "1", width: "100%", p: "2", gap: "2", justify: "between", children: [
|
|
1299
1299
|
/* @__PURE__ */ g(y, { gap: "2", align: "center", className: qt.stopHorizontalOverflow, children: [
|
|
@@ -1301,7 +1301,7 @@ const De = (s, i) => x(() => !i || !s ? null : s.getInput(i), [s, i]), Nt = (s,
|
|
|
1301
1301
|
/* @__PURE__ */ r($, { size: "2", noWrap: !0, children: o === "creator" ? (l || c).username : u.title })
|
|
1302
1302
|
] }),
|
|
1303
1303
|
/* @__PURE__ */ g(y, { gap: "2", align: "center", children: [
|
|
1304
|
-
!n && (u.revision ? /* @__PURE__ */ r(Ue, { variant: "soft", severity:
|
|
1304
|
+
!n && (u.revision ? /* @__PURE__ */ r(Ue, { variant: "soft", severity: E ? "primary" : "info", children: n ? u.revision.toString() : `Revision #${u.revision}` }) : !!p && /* @__PURE__ */ r(Ue, { children: "Original" })),
|
|
1305
1305
|
/* @__PURE__ */ r($, { size: "2", noWrap: !0, children: d })
|
|
1306
1306
|
] })
|
|
1307
1307
|
] }) });
|
|
@@ -1309,7 +1309,7 @@ const De = (s, i) => x(() => !i || !s ? null : s.getInput(i), [s, i]), Nt = (s,
|
|
|
1309
1309
|
}), Qe = (s) => {
|
|
1310
1310
|
const i = "created_at" in s ? s.created_at : s.submitted_at;
|
|
1311
1311
|
return new Date(i);
|
|
1312
|
-
}, qn =
|
|
1312
|
+
}, qn = z(function(i) {
|
|
1313
1313
|
const {
|
|
1314
1314
|
formId: e,
|
|
1315
1315
|
submissions: t,
|
|
@@ -1350,7 +1350,7 @@ const De = (s, i) => x(() => !i || !s ? null : s.getInput(i), [s, i]), Nt = (s,
|
|
|
1350
1350
|
))
|
|
1351
1351
|
}
|
|
1352
1352
|
);
|
|
1353
|
-
}), Wn =
|
|
1353
|
+
}), Wn = z(function(i) {
|
|
1354
1354
|
const { name: e, render: t } = i, { submitForm: n } = pe(), [o, a, c] = et(e);
|
|
1355
1355
|
return x(() => {
|
|
1356
1356
|
const l = (f) => c.setValue(f, !1);
|
|
@@ -1360,22 +1360,22 @@ const De = (s, i) => x(() => !i || !s ? null : s.getInput(i), [s, i]), Nt = (s,
|
|
|
1360
1360
|
patchValue: n
|
|
1361
1361
|
});
|
|
1362
1362
|
}, [n, c, o.value, t]);
|
|
1363
|
-
}), Hn =
|
|
1363
|
+
}), Hn = z(
|
|
1364
1364
|
xe((s, i) => {
|
|
1365
|
-
const { children: e, schema: t, values: n, onPatch: o, onError: a, ...c } = s, l = x(() => ct(t.fields, n), [t.fields, n]), f =
|
|
1365
|
+
const { children: e, schema: t, values: n, onPatch: o, onError: a, ...c } = s, l = x(() => ct(t.fields, n), [t.fields, n]), f = S(
|
|
1366
1366
|
(b) => {
|
|
1367
|
-
const
|
|
1367
|
+
const E = {};
|
|
1368
1368
|
for (const I in b) {
|
|
1369
1369
|
const C = b[I];
|
|
1370
|
-
C !== l[I] && C !== void 0 && (
|
|
1370
|
+
C !== l[I] && C !== void 0 && (E[I] = C);
|
|
1371
1371
|
}
|
|
1372
|
-
_e(
|
|
1372
|
+
_e(E) && o(E);
|
|
1373
1373
|
},
|
|
1374
1374
|
[l, o]
|
|
1375
|
-
), d =
|
|
1375
|
+
), d = S(
|
|
1376
1376
|
async (b) => {
|
|
1377
|
-
const
|
|
1378
|
-
return
|
|
1377
|
+
const E = await Bt(t, b);
|
|
1378
|
+
return E && a(E), E;
|
|
1379
1379
|
},
|
|
1380
1380
|
[t, a]
|
|
1381
1381
|
), u = tt({
|
|
@@ -1393,7 +1393,7 @@ const De = (s, i) => x(() => !i || !s ? null : s.getInput(i), [s, i]), Nt = (s,
|
|
|
1393
1393
|
), Wt = {
|
|
1394
1394
|
...at,
|
|
1395
1395
|
section: Z
|
|
1396
|
-
}, mn =
|
|
1396
|
+
}, mn = z(function(i) {
|
|
1397
1397
|
const { field: e, setFieldType: t } = i, n = e.fieldTypeName, o = e.fieldTypeDescription, a = e.Icon;
|
|
1398
1398
|
return /* @__PURE__ */ g(y, { gap: "4", align: "center", children: [
|
|
1399
1399
|
/* @__PURE__ */ r(G, { type: "button", variant: "surface", onClick: t, style: { width: "135px" }, children: /* @__PURE__ */ g(y, { gap: "3", align: "center", grow: "1", children: [
|
|
@@ -1406,7 +1406,7 @@ const De = (s, i) => x(() => !i || !s ? null : s.getInput(i), [s, i]), Nt = (s,
|
|
|
1406
1406
|
["string", "text"],
|
|
1407
1407
|
["select", "multi-select", "upload"],
|
|
1408
1408
|
["boolean", "date", "number", "multi-string"]
|
|
1409
|
-
], pn = Ht.length - 1, hn =
|
|
1409
|
+
], pn = Ht.length - 1, hn = z(function(i) {
|
|
1410
1410
|
const { setFieldType: e } = i;
|
|
1411
1411
|
return /* @__PURE__ */ r(y, { direction: "column", gap: "3", children: Ht.map((t, n) => /* @__PURE__ */ g(y, { direction: "column", gap: "3", children: [
|
|
1412
1412
|
/* @__PURE__ */ r(y, { direction: "column", gap: "2", children: t.map((o) => /* @__PURE__ */ r(
|
|
@@ -1442,7 +1442,7 @@ const De = (s, i) => x(() => !i || !s ? null : s.getInput(i), [s, i]), Nt = (s,
|
|
|
1442
1442
|
...e,
|
|
1443
1443
|
new fe({ label: "Required", description: null, required: !1, identifier: "required" })
|
|
1444
1444
|
];
|
|
1445
|
-
}, yn =
|
|
1445
|
+
}, yn = z(function(i) {
|
|
1446
1446
|
const { fieldType: e, handleCancel: t, handleCreateField: n, defaultField: o, conditionalSourceFields: a } = i, c = Wt[e], l = pe(), f = x(() => {
|
|
1447
1447
|
const d = Dt(l.values.fields).filter((p) => p !== (o == null ? void 0 : o.label));
|
|
1448
1448
|
let u = bn(d, e);
|
|
@@ -1472,13 +1472,13 @@ const De = (s, i) => x(() => !i || !s ? null : s.getInput(i), [s, i]), Nt = (s,
|
|
|
1472
1472
|
onCancel: t
|
|
1473
1473
|
}
|
|
1474
1474
|
);
|
|
1475
|
-
}), he =
|
|
1475
|
+
}), he = z(function(i) {
|
|
1476
1476
|
const { parentPath: e, index: t, children: n, initial: o, editing: a, conditionalSourceFields: c } = i, [l, f] = de(), d = (o == null ? void 0 : o.type) ?? l, u = d ? Wt[d].fieldTypeName : void 0, { setFieldValue: p, values: h } = pe();
|
|
1477
1477
|
if (a && !o)
|
|
1478
1478
|
throw new Error("Initial field must be provided if editing is true.");
|
|
1479
|
-
const b = !d && !a && !o,
|
|
1479
|
+
const b = !d && !a && !o, E = b ? "Choose a field type" : `${u} settings`, I = b ? "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.`, C = S(() => f(void 0), []), w = S((v) => {
|
|
1480
1480
|
f(void 0), v();
|
|
1481
|
-
}, []), V =
|
|
1481
|
+
}, []), V = S(
|
|
1482
1482
|
(v, P) => {
|
|
1483
1483
|
const { label: R } = v;
|
|
1484
1484
|
if (!d)
|
|
@@ -1498,7 +1498,7 @@ const De = (s, i) => x(() => !i || !s ? null : s.getInput(i), [s, i]), Nt = (s,
|
|
|
1498
1498
|
a ? U = Gi(j, t, X) : U = kt(j, t, X), p(e, U).then(), P();
|
|
1499
1499
|
},
|
|
1500
1500
|
[a, d, h, e, p, t]
|
|
1501
|
-
), L =
|
|
1501
|
+
), L = S(
|
|
1502
1502
|
(v) => b ? /* @__PURE__ */ r(hn, { setFieldType: f }) : /* @__PURE__ */ r(
|
|
1503
1503
|
yn,
|
|
1504
1504
|
{
|
|
@@ -1511,11 +1511,11 @@ const De = (s, i) => x(() => !i || !s ? null : s.getInput(i), [s, i]), Nt = (s,
|
|
|
1511
1511
|
),
|
|
1512
1512
|
[c, C, V, o, b, d]
|
|
1513
1513
|
);
|
|
1514
|
-
return /* @__PURE__ */ r(pi, { onCloseInterrupt: w, title:
|
|
1514
|
+
return /* @__PURE__ */ r(pi, { onCloseInterrupt: w, title: E, description: I, content: L, children: n });
|
|
1515
1515
|
}), yt = ({ children: s }) => /* @__PURE__ */ r(Je, { children: s }), wt = (s, i) => ({
|
|
1516
1516
|
initial: s ? i : "none",
|
|
1517
1517
|
sm: s ? "none" : i
|
|
1518
|
-
}), jt =
|
|
1518
|
+
}), jt = z(function(i) {
|
|
1519
1519
|
const { remove: e, dragHandleProps: t, editProps: n, insertAfterProps: o, duplicateProps: a } = i, c = x(
|
|
1520
1520
|
() => [
|
|
1521
1521
|
{
|
|
@@ -1582,8 +1582,8 @@ const De = (s, i) => x(() => !i || !s ? null : s.getInput(i), [s, i]), Nt = (s,
|
|
|
1582
1582
|
}
|
|
1583
1583
|
) })
|
|
1584
1584
|
] });
|
|
1585
|
-
}), qe = "form-builder", wn =
|
|
1586
|
-
const { field: e, index: t, sectionIndex: n, takenLabels: o, remove: a } = i, c = x(() => Be(e), [e]), l = De(c, { formId: qe, disabled: !0 }), f =
|
|
1585
|
+
}), qe = "form-builder", wn = z(function(i) {
|
|
1586
|
+
const { field: e, index: t, sectionIndex: n, takenLabels: o, remove: a } = i, c = x(() => Be(e), [e]), l = De(c, { formId: qe, disabled: !0 }), f = S(
|
|
1587
1587
|
(h) => {
|
|
1588
1588
|
if (h.label === null)
|
|
1589
1589
|
throw new Error(`Expected a label for field ${h.identifier}`);
|
|
@@ -1636,39 +1636,39 @@ const De = (s, i) => x(() => !i || !s ? null : s.getInput(i), [s, i]), Nt = (s,
|
|
|
1636
1636
|
] })
|
|
1637
1637
|
}
|
|
1638
1638
|
) });
|
|
1639
|
-
}), vn =
|
|
1639
|
+
}), vn = z(function(i) {
|
|
1640
1640
|
var U, A, N, K, Ie, Ce, Fe, ut, ft;
|
|
1641
|
-
const { field: e, index: t, dropState: n, conditionalFieldCounts: o } = i, a = (U = n[e.identifier]) == null ? void 0 : U.disabled, c = _(Oi), { setFieldValue: l, values: f } = pe(), d = xi(), u = Dt(f.fields), p =
|
|
1642
|
-
(
|
|
1643
|
-
for (const D of
|
|
1644
|
-
const k =
|
|
1641
|
+
const { field: e, index: t, dropState: n, conditionalFieldCounts: o } = i, a = (U = n[e.identifier]) == null ? void 0 : U.disabled, c = _(Oi), { setFieldValue: l, values: f } = pe(), d = xi(), u = Dt(f.fields), p = S(
|
|
1642
|
+
(F, T) => {
|
|
1643
|
+
for (const D of F) {
|
|
1644
|
+
const k = T.indexOf(D);
|
|
1645
1645
|
l(`fields.${k}.condition`, null).then(), l(`fields.${k}.conditional`, !1).then();
|
|
1646
1646
|
}
|
|
1647
1647
|
},
|
|
1648
1648
|
[l]
|
|
1649
|
-
), h =
|
|
1650
|
-
(
|
|
1649
|
+
), h = S(
|
|
1650
|
+
(F) => {
|
|
1651
1651
|
var k;
|
|
1652
|
-
const
|
|
1653
|
-
if (!
|
|
1652
|
+
const T = e.fields[F];
|
|
1653
|
+
if (!T)
|
|
1654
1654
|
throw new Error("Could not find field to remove.");
|
|
1655
1655
|
const D = [];
|
|
1656
1656
|
for (const O of f.fields)
|
|
1657
|
-
((k = O.condition) == null ? void 0 : k.identifier) ===
|
|
1657
|
+
((k = O.condition) == null ? void 0 : k.identifier) === T.identifier && D.push(O);
|
|
1658
1658
|
return {
|
|
1659
|
-
removing:
|
|
1659
|
+
removing: T,
|
|
1660
1660
|
affectedSections: D,
|
|
1661
|
-
action: () => l(`fields.${t}.fields`, Le(e.fields,
|
|
1661
|
+
action: () => l(`fields.${t}.fields`, Le(e.fields, F))
|
|
1662
1662
|
};
|
|
1663
1663
|
},
|
|
1664
1664
|
[e.fields, f.fields, l, t]
|
|
1665
|
-
), b =
|
|
1666
|
-
(
|
|
1667
|
-
const { affectedSections:
|
|
1668
|
-
D().then(), p(
|
|
1665
|
+
), b = S(
|
|
1666
|
+
(F) => {
|
|
1667
|
+
const { affectedSections: T, action: D, removing: k } = h(F), O = () => {
|
|
1668
|
+
D().then(), p(T, f.fields);
|
|
1669
1669
|
};
|
|
1670
|
-
if (
|
|
1671
|
-
const We =
|
|
1670
|
+
if (T.length > 0) {
|
|
1671
|
+
const We = T.map((Te) => Te.label).join(", ");
|
|
1672
1672
|
return d({
|
|
1673
1673
|
title: "Remove condition?",
|
|
1674
1674
|
description: `${k.label} is being used as a condition, deleting it will remove the condition from the ${We} section(s).`,
|
|
@@ -1680,9 +1680,9 @@ const De = (s, i) => x(() => !i || !s ? null : s.getInput(i), [s, i]), Nt = (s,
|
|
|
1680
1680
|
O();
|
|
1681
1681
|
},
|
|
1682
1682
|
[h, p, f.fields, d]
|
|
1683
|
-
),
|
|
1684
|
-
const
|
|
1685
|
-
if (
|
|
1683
|
+
), E = S(() => {
|
|
1684
|
+
const T = e.fields.map((Se, Ut) => h(Ut)).flatMap((Se) => Se.affectedSections), D = T.length ? "Remove fields and conditions?" : "Remove fields?", k = e.fields.length, O = T.map((Se) => Se.label).join(", "), We = T.length ? `Deleting this section will remove the ${k} field(s) it contains and will remove the conditions from following sections: ${O}` : `Deleting this section will remove the ${k} field(s) it contains.`, Te = Le(f.fields, t), mt = () => l("fields", Te);
|
|
1685
|
+
if (T.length > 0)
|
|
1686
1686
|
return d({
|
|
1687
1687
|
title: D,
|
|
1688
1688
|
description: We,
|
|
@@ -1690,7 +1690,7 @@ const De = (s, i) => x(() => !i || !s ? null : s.getInput(i), [s, i]), Nt = (s,
|
|
|
1690
1690
|
actionText: "Remove",
|
|
1691
1691
|
onAction: () => {
|
|
1692
1692
|
mt().then(() => {
|
|
1693
|
-
p(
|
|
1693
|
+
p(T, Te);
|
|
1694
1694
|
});
|
|
1695
1695
|
}
|
|
1696
1696
|
});
|
|
@@ -1703,11 +1703,11 @@ const De = (s, i) => x(() => !i || !s ? null : s.getInput(i), [s, i]), Nt = (s,
|
|
|
1703
1703
|
l,
|
|
1704
1704
|
d,
|
|
1705
1705
|
p
|
|
1706
|
-
]), I =
|
|
1707
|
-
(
|
|
1708
|
-
if (
|
|
1709
|
-
throw new Error(`Expected a label for field ${
|
|
1710
|
-
const
|
|
1706
|
+
]), I = S(
|
|
1707
|
+
(F) => {
|
|
1708
|
+
if (F.label === null)
|
|
1709
|
+
throw new Error(`Expected a label for field ${F.identifier}`);
|
|
1710
|
+
const T = Ye(F.label, u), D = F.fields.map((k) => {
|
|
1711
1711
|
const O = Ye(k.label, u);
|
|
1712
1712
|
return {
|
|
1713
1713
|
...k,
|
|
@@ -1715,7 +1715,7 @@ const De = (s, i) => x(() => !i || !s ? null : s.getInput(i), [s, i]), Nt = (s,
|
|
|
1715
1715
|
identifier: $t(void 0, O)
|
|
1716
1716
|
};
|
|
1717
1717
|
});
|
|
1718
|
-
return { ...
|
|
1718
|
+
return { ...F, label: T, fields: D, identifier: "" };
|
|
1719
1719
|
},
|
|
1720
1720
|
[u]
|
|
1721
1721
|
), C = x(
|
|
@@ -1752,135 +1752,132 @@ const De = (s, i) => x(() => !i || !s ? null : s.getInput(i), [s, i]), Nt = (s,
|
|
|
1752
1752
|
[I, e, t, f.fields]
|
|
1753
1753
|
), v = x(
|
|
1754
1754
|
() => {
|
|
1755
|
-
var
|
|
1756
|
-
return (
|
|
1755
|
+
var F, T;
|
|
1756
|
+
return (T = Vt(f.fields, (F = e.condition) == null ? void 0 : F.identifier)) == null ? void 0 : T.label;
|
|
1757
1757
|
},
|
|
1758
1758
|
[(A = e.condition) == null ? void 0 : A.identifier, f.fields]
|
|
1759
1759
|
), P = Array.isArray((N = e.condition) == null ? void 0 : N.value) ? "contains all of" : "equals";
|
|
1760
1760
|
if (Xe((K = e.condition) == null ? void 0 : K.value))
|
|
1761
1761
|
throw new Error("File values are not supported for conditions.");
|
|
1762
|
-
const R = Array.isArray((Ie = e.condition) == null ? void 0 : Ie.value) ? (Fe = (Ce = e.condition) == null ? void 0 : Ce.value) == null ? void 0 : Fe.map((
|
|
1763
|
-
const
|
|
1762
|
+
const R = Array.isArray((Ie = e.condition) == null ? void 0 : Ie.value) ? (Fe = (Ce = e.condition) == null ? void 0 : Ce.value) == null ? void 0 : Fe.map((F) => typeof F == "string" ? F : F.label).join(", ") : (ft = (ut = e.condition) == null ? void 0 : ut.value) == null ? void 0 : ft.toString(), X = () => {
|
|
1763
|
+
const T = o.filter((O) => O !== null).length, D = o[t] ?? 0, k = 6 / T * D;
|
|
1764
1764
|
return /* @__PURE__ */ r(
|
|
1765
1765
|
"div",
|
|
1766
1766
|
{
|
|
1767
1767
|
id: `${e.identifier}-floating-point`,
|
|
1768
1768
|
style: {
|
|
1769
1769
|
width: `${6 - k}%`,
|
|
1770
|
-
marginRight: `${k}
|
|
1771
|
-
marginBottom: "4"
|
|
1770
|
+
marginRight: `${k}%`
|
|
1772
1771
|
}
|
|
1773
1772
|
}
|
|
1774
1773
|
);
|
|
1775
|
-
}, j = () =>
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1774
|
+
}, j = () => {
|
|
1775
|
+
if (!e.condition)
|
|
1776
|
+
return null;
|
|
1777
|
+
const F = c === "light" ? "black" : "white";
|
|
1778
|
+
return /* @__PURE__ */ g(Je, { children: [
|
|
1779
|
+
/* @__PURE__ */ r(
|
|
1780
|
+
ht,
|
|
1781
|
+
{
|
|
1782
|
+
start: `${e.identifier}-card`,
|
|
1783
|
+
end: `${e.identifier}-floating-point`,
|
|
1784
|
+
startAnchor: "left",
|
|
1785
|
+
endAnchor: "right",
|
|
1786
|
+
color: F,
|
|
1787
|
+
strokeWidth: 2,
|
|
1788
|
+
path: "straight",
|
|
1789
|
+
showHead: !1
|
|
1790
|
+
}
|
|
1791
|
+
),
|
|
1792
|
+
/* @__PURE__ */ r(
|
|
1793
|
+
ht,
|
|
1794
|
+
{
|
|
1795
|
+
start: `${e.identifier}-floating-point`,
|
|
1796
|
+
end: `${e.condition.identifier}-card`,
|
|
1797
|
+
startAnchor: "right",
|
|
1798
|
+
endAnchor: "left",
|
|
1799
|
+
color: F,
|
|
1800
|
+
strokeWidth: 2,
|
|
1801
|
+
path: "grid",
|
|
1802
|
+
gridBreak: "0"
|
|
1803
|
+
}
|
|
1804
|
+
)
|
|
1805
|
+
] });
|
|
1806
|
+
};
|
|
1807
|
+
return /* @__PURE__ */ r(rt, { draggableId: e.identifier, index: t, children: (F) => /* @__PURE__ */ g(
|
|
1804
1808
|
y,
|
|
1805
1809
|
{
|
|
1806
|
-
ref:
|
|
1807
|
-
...
|
|
1808
|
-
...
|
|
1810
|
+
ref: F.innerRef,
|
|
1811
|
+
...F.draggableProps,
|
|
1812
|
+
...F.dragHandleProps,
|
|
1809
1813
|
direction: "row",
|
|
1810
1814
|
justify: "center",
|
|
1811
1815
|
align: "center",
|
|
1816
|
+
mb: "4",
|
|
1812
1817
|
children: [
|
|
1813
|
-
o.some((
|
|
1818
|
+
o.some((T) => T !== null) && X(),
|
|
1814
1819
|
e.condition && j(),
|
|
1815
|
-
/* @__PURE__ */ r(
|
|
1816
|
-
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
/* @__PURE__ */
|
|
1836
|
-
|
|
1820
|
+
/* @__PURE__ */ r(we, { id: `${e.identifier}-card`, style: { flexGrow: "1" }, children: /* @__PURE__ */ g(y, { gap: "3", justify: "between", align: "center", children: [
|
|
1821
|
+
/* @__PURE__ */ g(y, { direction: "column", gap: "2", grow: "1", children: [
|
|
1822
|
+
/* @__PURE__ */ g(y, { direction: "column", children: [
|
|
1823
|
+
/* @__PURE__ */ r(Me, { as: "h3", size: "3", children: e.label }),
|
|
1824
|
+
/* @__PURE__ */ r($, { className: Ne.description, children: e.description })
|
|
1825
|
+
] }),
|
|
1826
|
+
e.condition && /* @__PURE__ */ r($, { size: "1", children: /* @__PURE__ */ g(Ii, { children: [
|
|
1827
|
+
"Display only if ",
|
|
1828
|
+
/* @__PURE__ */ r(pt, { children: v }),
|
|
1829
|
+
" ",
|
|
1830
|
+
P,
|
|
1831
|
+
" ",
|
|
1832
|
+
/* @__PURE__ */ r(pt, { children: R })
|
|
1833
|
+
] }) }),
|
|
1834
|
+
/* @__PURE__ */ r(
|
|
1835
|
+
nt,
|
|
1836
|
+
{
|
|
1837
|
+
droppableId: e.identifier,
|
|
1838
|
+
type: "SECTION",
|
|
1839
|
+
isDropDisabled: a,
|
|
1840
|
+
children: (T) => /* @__PURE__ */ g(
|
|
1841
|
+
y,
|
|
1837
1842
|
{
|
|
1838
|
-
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
F.placeholder,
|
|
1861
|
-
/* @__PURE__ */ r(he, { ...V, children: /* @__PURE__ */ g(G, { type: "button", variant: "outline", children: [
|
|
1862
|
-
/* @__PURE__ */ r(Oe, {}),
|
|
1863
|
-
" Add a field"
|
|
1864
|
-
] }) })
|
|
1865
|
-
]
|
|
1866
|
-
}
|
|
1867
|
-
)
|
|
1843
|
+
ref: T.innerRef,
|
|
1844
|
+
...T.droppableProps,
|
|
1845
|
+
direction: "column",
|
|
1846
|
+
gap: "0",
|
|
1847
|
+
children: [
|
|
1848
|
+
e.fields.map((D, k) => /* @__PURE__ */ r(
|
|
1849
|
+
wn,
|
|
1850
|
+
{
|
|
1851
|
+
field: D,
|
|
1852
|
+
index: k,
|
|
1853
|
+
sectionIndex: t,
|
|
1854
|
+
remove: () => b(k),
|
|
1855
|
+
takenLabels: u
|
|
1856
|
+
},
|
|
1857
|
+
D.identifier
|
|
1858
|
+
)),
|
|
1859
|
+
T.placeholder,
|
|
1860
|
+
/* @__PURE__ */ r(he, { ...V, children: /* @__PURE__ */ g(G, { type: "button", variant: "outline", children: [
|
|
1861
|
+
/* @__PURE__ */ r(Oe, {}),
|
|
1862
|
+
" Add a field"
|
|
1863
|
+
] }) })
|
|
1864
|
+
]
|
|
1868
1865
|
}
|
|
1869
1866
|
)
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
)
|
|
1867
|
+
}
|
|
1868
|
+
)
|
|
1869
|
+
] }),
|
|
1870
|
+
/* @__PURE__ */ r(
|
|
1871
|
+
jt,
|
|
1872
|
+
{
|
|
1873
|
+
remove: E,
|
|
1874
|
+
insertAfterProps: w,
|
|
1875
|
+
dragHandleProps: F.dragHandleProps,
|
|
1876
|
+
editProps: C,
|
|
1877
|
+
duplicateProps: L
|
|
1878
|
+
}
|
|
1879
|
+
)
|
|
1880
|
+
] }) })
|
|
1884
1881
|
]
|
|
1885
1882
|
}
|
|
1886
1883
|
) });
|
|
@@ -1930,20 +1927,20 @@ const De = (s, i) => x(() => !i || !s ? null : s.getInput(i), [s, i]), Nt = (s,
|
|
|
1930
1927
|
for (const [e, t] of Object.entries(s))
|
|
1931
1928
|
if (t.identifier === i)
|
|
1932
1929
|
return [t, e];
|
|
1933
|
-
}, Cn =
|
|
1930
|
+
}, Cn = z(function() {
|
|
1934
1931
|
const { values: i, setFieldValue: e } = pe(), [t, n] = Si(xn, i.fields, vt), { showInfo: o } = Ci();
|
|
1935
1932
|
ve(() => {
|
|
1936
1933
|
n({ type: "update", state: vt(i.fields) });
|
|
1937
1934
|
}, [n, i.fields]);
|
|
1938
|
-
const a =
|
|
1935
|
+
const a = S((d) => {
|
|
1939
1936
|
d.type === "SECTION" && n({ type: "hold", fieldId: d.draggableId });
|
|
1940
|
-
}, []), c =
|
|
1937
|
+
}, []), c = S(
|
|
1941
1938
|
(d) => {
|
|
1942
|
-
const { source: u, destination: p, type: h, reason: b, draggableId:
|
|
1939
|
+
const { source: u, destination: p, type: h, reason: b, draggableId: E } = d;
|
|
1943
1940
|
if (n({ type: "release" }), !p || b === "CANCEL")
|
|
1944
1941
|
return;
|
|
1945
1942
|
if (h === "ROOT") {
|
|
1946
|
-
const L = t[
|
|
1943
|
+
const L = t[E];
|
|
1947
1944
|
if (!L)
|
|
1948
1945
|
throw new Error("Could not find section context.");
|
|
1949
1946
|
let v = typeof L.conditionIndex < "u" ? (
|
|
@@ -2034,9 +2031,9 @@ const De = (s, i) => x(() => !i || !s ? null : s.getInput(i), [s, i]), Nt = (s,
|
|
|
2034
2031
|
identifier: "description"
|
|
2035
2032
|
}), En = { formId: qe, placeholder: "Explain the purpose of this form." }, An = () => {
|
|
2036
2033
|
alert("This is a form preview, your data will not be saved.");
|
|
2037
|
-
}, jn =
|
|
2034
|
+
}, jn = z(
|
|
2038
2035
|
xe((s, i) => {
|
|
2039
|
-
const { onCancel: e, onSave: t, revision: n } = s, o = n ? "Edit form" : "Create a new form", { heading: a = o } = s, c =
|
|
2036
|
+
const { onCancel: e, onSave: t, revision: n } = s, o = n ? "Edit form" : "Create a new form", { heading: a = o } = s, c = S((h) => {
|
|
2040
2037
|
const b = {};
|
|
2041
2038
|
if (h.title || (b.title = "Title is required."), (!h.fields || h.fields.length === 0) && (b.fields = "At least one field is required."), _e(b))
|
|
2042
2039
|
return b;
|
package/dist/forms.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(x,i){typeof exports=="object"&&typeof module<"u"?i(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"),require("react-xarrows")):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","react-xarrows"],i):(x=typeof globalThis<"u"?globalThis:x||self,i(x.forms={},x.jsxRuntime,x.blocks,x.formik,x.React,x.dnd,x.core,x.get,x.set,x.Xarrow))})(this,function(x,i,o,D,d,j,F,X,Pe,Ke){"use strict";var oi=Object.defineProperty;var si=(x,i,o)=>i in x?oi(x,i,{enumerable:!0,configurable:!0,writable:!0,value:o}):x[i]=o;var m=(x,i,o)=>(si(x,typeof i!="symbol"?i+"":i,o),o);class Ye{constructor(n){m(this,"type");m(this,"identifier");m(this,"description");const{description:e=null,identifier:t,type:r}=n;this.identifier=t,this.description=e,this.type=r}getId(){return this.identifier}static deserialize(n){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 V extends Ye{constructor(e){const{label:t,required:r,fieldValidators:s=[],formValidators:c=[],...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=s,this.formValidators=c}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 s=r(e);if(s)return s}if(t)for(const r of this.getFormValidators()){const s=r(e,t);if(s)return s}}_serialize(){return{...super._serialize(),label:this.label,required:this.required}}getFieldValidators(){return[...this.fieldValidators]}getFormValidators(){return[...this.formValidators]}}m(V,"fieldTypeName"),m(V,"fieldTypeDescription");const me={description:"_description_17zed_1"},q=l=>{const{label:n,children:e,severity:t,inputId:r,labelId:s,flexProps:c}=l;return i.jsx(o.Flex,{direction:"column",gap:"1",asChild:!0,...c,children:i.jsxs("label",{htmlFor:r,children:[i.jsx(o.Text,{severity:t,id:s,children:n}),e]})})},H=l=>{const{helpText:n,children:e,severity:t}=l;return i.jsxs(o.Flex,{direction:"column",gap:"1",children:[e,i.jsx(o.Flex,{direction:"column",children:i.jsx(o.Text,{size:"1",severity:t,className:me.description,children:n})})]})},W=l=>{const{id:n,field:e,formId:t,...r}=l,[s,c,u]=D.useField(e.getId()),{touched:a}=c,h=c.error??e.description,f=c.error?"danger":void 0,p=n??`${t}-${e.getId()}-input`,g=`${p}-label`,y=e.required?`${e.label} *`:e.label,v=d.useMemo(()=>({...s,onChange:C=>{const w=e.getValueFromChangeEvent(C);u.setValue(w,!1).then(),(a||!e.onlyValidateAfterTouched)&&u.setError(e.getError(w))},onBlur:C=>{u.setTouched(!0,!1).then(),u.setError(e.getError(e.getValueFromChangeEvent(C)))}}),[e,s,u,a]);return[{helpText:h,severity:f,inputId:p,labelId:g,label:y,fieldProps:v,helpers:u,field:e},{...r,"aria-labelledby":g}]},Ft=[!0,"true"],Ze=d.memo(function(n){const[{inputId:e,labelId:t,severity:r,helpText:s,label:c,fieldProps:u},a]=W(n),h=o.useSeverityColor(r),f=Ft.includes(u.value);return i.jsx(H,{helpText:s,severity:r,children:i.jsx(q,{severity:r,inputId:e,labelId:t,label:c,flexProps:{direction:"row-reverse",justify:"end",align:"center",gap:"2"},children:i.jsx(o.Checkbox,{...a,...u,id:e,color:h,value:f.toString(),checked:f,onCheckedChange:u.onChange,onChange:void 0,onBlur:void 0})})})}),R=class R extends V{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 i.jsx(Ze,{...e,field:this})}};m(R,"fieldTypeName","Checkbox"),m(R,"fieldTypeDescription","Perfect for both optional and required yes/no questions."),m(R,"Icon",o.CheckCircledIcon);let Z=R;const Qe=d.memo(function(n){const[{inputId:e,labelId:t,severity:r,helpText:s,label:c,fieldProps:u,field:a},h]=W(n),f=o.useSeverityColor(r);return i.jsx(H,{helpText:s,severity:r,children:i.jsx(q,{severity:r,inputId:e,labelId:t,label:c,children:i.jsx(o.TextField.Input,{...h,...u,type:"number",id:e,min:a.minimum,max:a.maximum,step:a.integers?1:.1,color:f})})})}),_=class _ extends V{constructor(e){const{minimum:t=Number.MIN_SAFE_INTEGER,maximum:r=Number.MAX_SAFE_INTEGER,integers:s=!1,...c}=e;super({...c,type:"number"});m(this,"minimum");m(this,"maximum");m(this,"integers");this.minimum=t,this.maximum=r,this.integers=s}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 Z({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(s=>{if(typeof s=="number"&&s<t)return`Must be at least ${this.minimum}.`}),typeof r=="number"&&e.push(s=>{if(typeof s=="number"&&s>r)return`Must be at most ${this.maximum}.`}),this.integers&&e.push(s=>{if(typeof s=="number"&&!Number.isInteger(s))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 i.jsx(Qe,{field:this,...e})}};m(_,"fieldTypeName","Number"),m(_,"fieldTypeDescription","Allows specifying a number within a given range."),m(_,"Icon",o.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 U=_;const Xe=d.memo(function(n){const[{inputId:e,labelId:t,severity:r,helpText:s,label:c,fieldProps:u},a]=W(n),h=o.useSeverityColor(r),f=u.value?u.value.split("T")[0]:"";return i.jsx(H,{helpText:s,severity:r,children:i.jsx(q,{severity:r,inputId:e,labelId:t,label:c,children:i.jsx(o.TextField.Input,{...a,...u,type:"date",id:e,color:h,value:f})})})}),ee=class ee extends V{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 i.jsx(Xe,{field:this,...e})}};m(ee,"fieldTypeName","Date"),m(ee,"fieldTypeDescription","Allows specifying a date."),m(ee,"Icon",o.CalendarIcon);let ge=ee;class ye extends V{constructor(e){const{minLength:t,maxLength:r=5e3,...s}=e;super(s);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 U({label:"Minimum length",description:"Minimum number of characters",required:!1,identifier:"minimum_length",minimum:0,maximum:100,formValidators:[this._validateMin],integers:!0}),new U({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(ye,"_validateMin",(e,t)=>typeof t.maximum_length=="number"&&typeof e=="number"&&t.maximum_length<e?"Minimum cannot be greater than maximum.":null),m(ye,"_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 Je=d.memo(function(n){const[{inputId:e,labelId:t,severity:r,helpText:s,label:c,fieldProps:u,field:a},h]=W(n),f=o.useSeverityColor(r);return i.jsx(H,{helpText:s,severity:r,children:i.jsx(q,{severity:r,inputId:e,labelId:t,label:c,children:i.jsx(o.TextField.Input,{...h,...u,type:a.inputType,id:e,color:f})})})}),te=class te extends ye{constructor(e){const{inputType:t="text",...r}=e,s=e.maxLength?Math.min(500,e.maxLength):500,c=e.minLength?Math.min(e.minLength,s):void 0;super({...r,maxLength:s,minLength:c,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:s,...c}=e;return new te({...c,maxLength:t,minLength:r,inputType:s})}getInput(e){return i.jsx(Je,{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",o.InputIcon);let J=te;const ke=d.memo(function(n){const[{inputId:e,labelId:t,severity:r,helpText:s,label:c,fieldProps:u},a]=W(n);return i.jsx(H,{helpText:s,severity:r,children:i.jsx(q,{severity:r,inputId:e,labelId:t,label:c,children:i.jsx(o.TextArea,{...a,...u,resize:"vertical",id:e,severity:r})})})}),ie=class ie extends ye{constructor(n){const e=n.maxLength?Math.min(5e3,n.maxLength):5e3,t=n.minLength?Math.min(n.minLength,e):void 0;super({...n,maxLength:e,minLength:t,type:"text"})}serialize(){return super._serialize()}static deserialize(n){if(n.type!=="text")throw new Error("Type mismatch.");const{maximum_length:e,minimum_length:t,...r}=n;return new ie({...r,maxLength:e,minLength:t})}getInput(n){return i.jsx(ke,{field:this,...n})}};m(ie,"fieldTypeName","Paragraph"),m(ie,"fieldTypeDescription","Paragraph fields can hold up to 5000 characters and can have multiple lines."),m(ie,"Icon",o.RowsIcon);let k=ie;const Re=d.memo(function(n){const[{inputId:e,labelId:t,severity:r,helpText:s,label:c,fieldProps:u,field:a},h]=W(n),{onChange:f,onBlur:p}=u,g=d.useMemo(()=>a.options.map(v=>({value:v.value,itemContent:v.label})),[a.options]),y=d.useCallback(v=>{f(v),p(v)},[f,p]);return i.jsx(H,{helpText:s,severity:r,children:i.jsx(q,{severity:r,inputId:e,labelId:t,label:c,children:i.jsx(o.Select,{items:g,...u,onValueChange:y,placeholder:"Select one...",id:e,severity:r,...h})})})}),xe=(l="",n=[])=>({type:"section",fields:n,identifier:l,label:null,condition:null,conditional:!1}),It=l=>{if(!l)return;const n=l.fields;let e=[];const t=[];for(const r of n)r.type==="section"?(e.length>0&&(t.push(xe(`AUTO_section-${n.indexOf(r)}`,e)),e=[]),t.push(r)):e.push(r);return e.length>0&&t.push(xe("AUTO_section-last",e)),{...l,fields:t,description:l.description??""}};function Le(l,n,e){const t=Array.from(l),[r]=t.splice(n,1);if(!r)throw new Error("Could not find field to reorder.");return t.splice(e,0,r),t}function bt(l,n,e){const t=Array.from(l);return t[n]=e,t}function et(l,n,e){const t=Array.from(l??[]);return t.splice(n,0,e),t}function ve(l,n){const e=Array.from(l);return e.splice(n,1),e}const tt=(l,n)=>{if(typeof l=="string"&&l.length>0)return l;const e=new Date;return`${F.slugify(n)}-${e.getTime()}`},it=(l,n)=>{if(!n)return null;for(const e of l)if(e.type==="section"){const t=it(e.fields,n);if(t)return t}else if(e.identifier===n)return e;return null},we=(l,n)=>l.filter((e,t)=>t<n).flatMap(e=>e.fields),nt=l=>l.flatMap(n=>n.type==="section"?[...n.fields.map(e=>e.label),n.label]:n.label).filter(n=>n!==null),De=(l,n)=>{let e=1,t=`${l} (${e})`;for(;n.includes(t);)t=`${l} (${++e})`;return t},rt=d.memo(function(n){const[{inputId:e,labelId:t,severity:r,helpText:s,label:c,fieldProps:u},a]=W(n),h=o.useSeverityColor(r),f=d.useMemo(()=>Array.isArray(u.value)?u.value:[],[u.value]),{onChange:p,onBlur:g}=u,y=`${e}-droppable`,{disabled:v}=a,[S,b]=d.useState(""),[C,w]=d.useState(""),L=C||s,E=C?"red":h,I=d.useCallback(A=>{p(A),g(A)},[p,g]),M=d.useCallback(A=>{f.findIndex(N=>N.value===A.target.value.trim())>=0?w("All options must be unique"):A.target.value?w(""):w("Option cannot be empty"),b(A.target.value)},[b,f]),O=d.useCallback(()=>{if(C)return;if(!S.trim())return w("Option cannot be empty");const A=S.trim();I([...f,{value:A,label:A}]),b("")},[S,C,I,f]),ae=d.useCallback(A=>{A.key==="Enter"&&(A.preventDefault(),O())},[O]),K=d.useCallback(A=>{I(ve(f,A))},[f,I]),Y=d.useCallback(A=>{if(!A.destination)return;const N=A.source.index,Q=A.destination.index;I(Le(f,N,Q))},[I,f]);return i.jsx(j.DragDropContext,{onDragEnd:Y,children:i.jsxs(o.Flex,{direction:"column",gap:"2",children:[i.jsx(H,{helpText:L,severity:r,children:i.jsx(q,{severity:r,inputId:e,labelId:t,label:c,children:(!v||f.length===0)&&i.jsxs(o.Flex,{gap:"2",children:[i.jsx(o.Box,{grow:"1",children:i.jsx(o.TextField.Input,{placeholder:"Press enter to add a new option",...a,...u,value:S,onChange:M,onKeyDown:ae,id:e,color:E,onBlur:void 0})}),i.jsx(o.IconButton,{type:"button","aria-label":"Add option",disabled:!!C||v,onClick:O,children:i.jsx(o.PlusIcon,{})})]})})}),i.jsx(j.Droppable,{droppableId:y,children:A=>i.jsxs(o.Flex,{...A.droppableProps,ref:A.innerRef,direction:"column",children:[f.map((N,Q)=>i.jsx(j.Draggable,{draggableId:`${N.value}-draggable`,index:Q,isDragDisabled:v,children:({draggableProps:Se,dragHandleProps:ze,innerRef:Ae})=>i.jsx(o.Flex,{...ze,...Se,ref:Ae,gap:"2",align:"center",justify:"between",mb:"1",asChild:!0,children:i.jsxs(o.Badge,{color:"gray",size:"2",children:[i.jsx("span",{children:N.label}),i.jsx(o.IconButton,{size:"small",variant:"ghost",type:"button","aria-label":"Delete option",severity:"info",disabled:v,onClick:()=>K(Q),children:i.jsx(o.Cross1Icon,{})})]})})},N.value)),A.placeholder]})})]})})}),ne=class ne extends V{constructor(e){const{minimum_length:t,maximum_length:r,...s}=e;super({...s,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 i.jsx(rt,{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",o.ListBulletIcon);let de=ne;class ot extends V{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 de({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 ot{constructor(n){super({...n,type:"select"})}getValueFromChangeEvent(n){return typeof n=="string"?n:n.target.value}serialize(){return super._serialize()}static deserialize(n){if(n.type!=="select")throw new Error("Type mismatch.");return new re(n)}getInput(n){return i.jsx(Re,{field:this,...n})}};m(re,"fieldTypeName","Dropdown"),m(re,"fieldTypeDescription","Allows the user to select a single option from a list of options."),m(re,"Icon",o.DropdownMenuIcon);let ce=re;const Ct=l=>l?Array.isArray(l)?l:[l]:[],st=d.memo(function(n){const[{inputId:e,labelId:t,severity:r,helpText:s,label:c,fieldProps:u,field:a},h]=W(n),{onChange:f,onBlur:p}=u,g=d.useMemo(()=>Ct(u.value),[u.value]),y=d.useCallback(v=>{f(v),p(v)},[f,p]);return i.jsx(H,{helpText:s,severity:r,children:i.jsx(q,{severity:r,inputId:e,labelId:t,label:c,children:i.jsx(o.MultiSelect,{value:g,onValueChange:y,options:a.options,name:u.name,placeholder:"Select one or more...",id:e,severity:r,...h})})})}),oe=class oe extends ot{constructor(n){super({...n,type:"multi-select"})}getValueFromChangeEvent(n){if(Array.isArray(n))return n;throw new Error("Expected an array.")}isBlank(n){return super.isBlank(n)||n.length===0}serialize(){return super._serialize()}static deserialize(n){if(n.type!=="multi-select")throw new Error("Type mismatch.");return new oe(n)}getInput(n){return i.jsx(st,{field:this,...n})}};m(oe,"fieldTypeName","Multi-select"),m(oe,"fieldTypeDescription","Allows the user to select a multiple options from a list of options."),m(oe,"Icon",o.CheckboxIcon);let ue=oe;const Tt=d.memo(function({field:n,...e}){const[{value:t}]=D.useField(n.options.clonedFieldIdentifier),r=d.useMemo(()=>{const s=n.options.getFieldToClone(t);return s?fe(s):null},[n.options,t]);return pe(r,e)});class Fe extends V{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 i.jsx(t,{field:this,...e})}}m(Fe,"fieldTypeName","Custom"),m(Fe,"fieldTypeDescription","Allows re-rendering of field already in the form");class St extends Fe{constructor(n){super(n,Tt)}}const zt=d.memo(function(n){const{field:e,...t}=n,{label:r,description:s,fields:c,condition:u}=e,{values:a,setFieldValue:h}=D.useFormikContext(),f=u!=null&&u.identifier?X(a,u.identifier):void 0,p=d.useMemo(()=>Ne(u,f),[u,f]);d.useEffect(()=>{if(!p)for(const y of c)h(y.getId(),"").then()},[p,c,h]);const g=qe(c,t);return p?r?i.jsx(o.Card,{children:i.jsxs(o.Flex,{direction:"column",gap:"3",children:[i.jsxs(o.Flex,{direction:"column",children:[i.jsx(o.Heading,{as:"h3",size:"3",children:r}),i.jsx(o.Text,{className:me.description,children:s})]}),g]})}):g:null}),se=class se extends Ye{constructor(e){const{label:t=null,fields:r,condition:s=null,conditional:c,...u}=e;super({...u,type:"section"});m(this,"label");m(this,"fields");m(this,"condition");this.fields=r,this.condition=s,this.label=t,c===!1&&(this.condition=null)}static getFieldCreationSchema(e){return e.length===0?[]:[new Z({label:"Conditional",description:"Conditionally show or hide this section.",identifier:"conditional",required:!1}),new se({label:"Conditional settings",identifier:"conditional-settings",condition:{identifier:"conditional",value:!0},fields:[new ce({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 St({label:"Value",identifier:"condition.value",required:!0,clonedFieldIdentifier:"condition.identifier",getFieldToClone(t){if(!t)return null;const r=e.find(s=>s.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(_e))??[];return new se({...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 s=r.getId(),c=r.getError(X(e,s),e);c&&Pe(t,r.getId(),c)}return t}getInput(e){return i.jsx(zt,{field:this,...e})}};m(se,"fieldTypeName","Section"),m(se,"fieldTypeDescription","Sections can be useful for grouping fields together. They can also be conditionally shown or hidden.");let G=se;const At={previewImage:"_previewImage_1ig84_1"},$e=l=>{const n=["byte","kilobyte","megabyte"];let e=l,t=0;for(;e>1024&&t<n.length-1;)e/=1024,t++;return new Intl.NumberFormat([],{maximumFractionDigits:2,style:"unit",unit:n[t]}).format(e)},Et=d.memo(function(n){var E;const[{inputId:e,labelId:t,severity:r,helpText:s,label:c,fieldProps:u,field:a},h]=W(n),{onChange:f}=u,p=o.useSeverityColor(r),g=d.useRef(null),{value:y}=u,v=d.useMemo(()=>s||(a.maxFileSize?`Maximum file size: ${$e(a.maxFileSize)}`:null),[a.maxFileSize,s]),S=d.useCallback(()=>{var I;(I=g.current)==null||I.click()},[]),b=d.useCallback(I=>{const M=[...y];M.splice(I,1),f({target:{files:M}})},[y,f]),C=y?"Select new files":"Select files",w=y?"Select new file":"Select a file",L=a.maxFiles>1?C:w;return i.jsxs(o.Flex,{direction:"column",gap:"2",children:[i.jsx(H,{helpText:v,severity:r,children:i.jsxs(q,{severity:r,inputId:e,labelId:t,label:c,children:[i.jsx(o.Flex,{direction:"row",gap:"2",children:i.jsx(o.Box,{width:"max-content",asChild:!0,children:i.jsxs(o.Button,{...h,onClick:S,children:[i.jsx(o.UploadIcon,{})," ",L]})})}),i.jsx("input",{...h,type:"file",ref:g,id:e,accept:(E=a.extensions)==null?void 0:E.join(","),multiple:a.maxFiles>1,color:p,style:{display:"none"},...u,value:""})]})}),Array.isArray(y)&&y.length>0&&i.jsx(o.Flex,{direction:"column",gap:"2",children:y.map((I,M)=>i.jsx(Mt,{field:a,file:I,onRemove:()=>b(M),disabled:h.disabled},M))})]})}),Mt=d.memo(function({file:n,field:e,onRemove:t,disabled:r}){const[s,c]=d.useState(null),u=d.useMemo(()=>s&&e.getError([s]),[e,s]),{url:a,name:h,size:f}=d.useMemo(()=>{let p=null,g,y;return s!=null&&s.type.startsWith("image/")&&(p=URL.createObjectURL(s)),s?(g=s.name,y=$e(s.size)):(g="Downloading...",y="..."),{url:p,name:g,size:y}},[s]);return d.useEffect(()=>{n instanceof Promise?n.then(c):c(n)},[n]),i.jsx(o.Card,{children:i.jsxs(o.Flex,{direction:{initial:"column",sm:"row"},gap:"3",justify:"between",children:[i.jsxs(o.Flex,{direction:"row",gap:"3",align:"center",grow:"1",shrink:"0",children:[i.jsx(o.IconButton,{severity:"info",variant:"outline","aria-label":`Remove ${h}`,disabled:r,onClick:t,children:i.jsx(o.Cross1Icon,{})}),i.jsxs(o.Flex,{direction:"column",gap:"1",children:[i.jsx(o.Text,{children:h}),i.jsx(o.Text,{size:"1",children:f}),u&&i.jsx(o.Text,{size:"1",severity:"danger",children:u})]})]}),a&&i.jsx("img",{className:At.previewImage,src:a,alt:h})]})})}),lt=50*1024*1024,le=class le extends V{constructor(e){const{extensions:t,maximum_files:r,maximum_size:s,...c}=e;super({...c,type:"upload"});m(this,"extensions");m(this,"maxFileSize");m(this,"maxFiles");m(this,"onlyValidateAfterTouched",!1);this.maxFileSize=typeof s=="number"?s: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 U({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 U({label:"What is the maximum size of each file?",description:"Maximum file size in bytes.",required:!1,identifier:"maximum_size",minimum:1,maximum:lt,integers:!0}),new ue({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??lt,r=this.maxFiles??1;return e.push(s=>{if(s&&s.some(c=>c.size>t))return`Files must be at most ${$e(t)}.`}),e.push(s=>{if(s&&s.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 i.jsx(Et,{field:this,...e})}};m(le,"fieldTypeName","Upload"),m(le,"fieldTypeDescription","Allows a file to be uploaded."),m(le,"Icon",o.UploadIcon);let Ve=le;const Be={date:ge,number:U,boolean:Z,select:ce,string:J,text:k,custom:Fe,upload:Ve,"multi-string":de,"multi-select":ue},_e=l=>{const n=l.type;return Be[n].deserialize(l)},fe=l=>l.type==="section"?G.deserialize(l):_e(l);function Oe(l,n={}){const{readonly:e=!1}=n;return{title:l.title,description:l.description,fields:l.fields.map(t=>fe(t)),meta:{readonly:e}}}function Ie(l){return!!(Array.isArray(l)&&l.some(n=>n instanceof File||n instanceof Promise))}function Ne(l,n){if(!l)return!0;if(Ie(n)||Ie(l.value))throw new Error("Conditions do not support file uploads");const e=Array.isArray(n)?n.map(r=>typeof r=="string"?r:r.value):n,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===n}const pe=(l,n)=>d.useMemo(()=>!n||!l?null:l.getInput(n),[l,n]),qe=(l,n)=>{const e=d.useMemo(()=>l.map(t=>i.jsx("div",{children:t.getInput(n)},t.getId())),[l,n]);return i.jsx(o.Flex,{direction:"column",gap:"2",children:e})},be=l=>Object.keys(l).length>0,at=async(l,n)=>{const e={};for(const t of l.fields)if(t instanceof G){if(t.condition){const{identifier:r}=t.condition;if(!Ne(t.condition,X(n,r)))continue}Object.assign(e,t.getErrors(n))}else{if(!(t instanceof V))throw new Error("Invalid field type");const r=t.getId(),s=t.getError(X(n,r),n);s&&Pe(e,r,s)}if(be(e))return e},Pt=[null,void 0],He=(l,n)=>l.reduce((e,t)=>t instanceof G?{...e,...He(t.fields,n)}:(Pt.includes(X(e,t.getId()))&&Pe(e,t.getId(),""),e),n),Lt=()=>{throw new Error("onSubmit must be provided if form is not readonly.")},Ce=d.memo(d.forwardRef((l,n)=>{const{schema:e,values:t={},onSubmit:r=Lt,submitText:s="Submit",cancelText:c,onCancel:u,onDirty:a,hideTitle:h=!e.title,hideDescription:f,className:p}=l,{readonly:g}=e.meta,y=d.useMemo(()=>crypto.randomUUID(),[]),v=D.useFormik({initialValues:He(e.fields,t),onSubmit:r,validate:L=>at(e,L),validateOnBlur:!1,validateOnChange:!1}),{dirty:S}=v,b=d.useMemo(()=>typeof e.title=="string"?i.jsx(o.Heading,{children:e.title}):e.title,[e.title]),C=d.useMemo(()=>typeof e.description=="string"?i.jsx(o.Text,{className:me.description,children:e.description}):e.description,[e.description]),w=qe(e.fields,{formId:y,disabled:g});return d.useEffect(()=>{S&&a&&a()},[S,a]),i.jsx(D.FormikProvider,{value:v,children:i.jsx(o.Flex,{ref:n,direction:"column",gap:"2",className:p,asChild:!0,children:i.jsxs("form",{id:y,onSubmit:v.handleSubmit,children:[!h&&i.jsx(o.Card,{children:i.jsxs(o.Flex,{direction:"column",gap:"1",children:[b,!f&&C]})}),w,!g&&i.jsxs(o.Flex,{justify:"end",gap:"2",children:[c&&i.jsx(o.Button,{type:"button",variant:"soft",onClick:u,children:c}),i.jsx(o.Button,{type:"submit",disabled:!v.isValid,children:s})]})]})})})})),Dt=d.memo(d.forwardRef((l,n)=>{const{submission:e,showFormDescription:t=!1,showFormTitle:r=!0}=l,s=F.useAppSelector(F.selectFormRevision(e.form_revision)),{sdk:c}=F.useSDK();if(!s)throw new Error(`Could not find revision ${e.form_revision} for submission ${e.offline_id}.`);const u=d.useMemo(()=>Oe(s,{readonly:!0}),[s]),a=d.useMemo(()=>{const h=F.selectSubmissionAttachments(e.offline_id)(c.store.getState())??[],f={};for(const p of h){const g=c.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}),y=f[p.field_identifier];y?y.push(g):f[p.field_identifier]=[g]}return{...e.values,...f}},[c.files,c.store,e.offline_id,e.values]);return i.jsx(Ce,{ref:n,schema:u,values:a,hideDescription:!t,hideTitle:!r})})),dt={favoriteIcon:"_favoriteIcon_1bixi_1",regularIcon:"_regularIcon_1bixi_9"},We="organization:",je="user:",$t=d.memo(d.forwardRef((l,n)=>{const{maxResults:e=20,...t}=l,[r,s]=d.useState(""),[c,u]=d.useState(""),{sdk:a}=F.useSDK(),h=d.useMemo(()=>{const w={maxResults:e,searchTerm:r};return c&&(c.startsWith(We)?w.owner_organization=parseInt(c.slice(We.length)):c.startsWith(je)&&(w.owner_user=parseInt(c.slice(je.length)))),w},[r,e,c]),f=F.useAppSelector(F.selectFilteredUserForms(h))??[],p=F.useAppSelector(F.selectUserFormMapping),g=d.useCallback(w=>{w.favorite?a.userForms.unfavorite(w.offline_id).then():a.userForms.favorite(w.offline_id).then()},[a]),y=d.useMemo(()=>{const w=a.store.getState(),L={};for(const E of Object.values(p)){const I=F.selectOrganization(E.owner_organization||-1)(w);I&&(L[`${We}${I.id}`]=I.name);const M=F.selectUser(E.owner_user||-1)(w);M&&(L[`${je}${M.id}`]=M.username)}return Object.entries(L).map(([E,I])=>({itemContent:I,value:E}))},[p,a.store]),v=d.useCallback(w=>{s(w.currentTarget.value)},[]),b=(F.useAppSelector(F.selectNumberOfUserForms)||0)-f.length,C=f.length==e&&b>0?`Only the first ${e} results are shown (${b} hidden)`:b>0&&`${b} hidden forms`;return i.jsxs(o.Flex,{ref:n,direction:"column",gap:"2",children:[i.jsxs(o.Flex,{gap:"2",grow:"1",children:[i.jsx(o.Box,{grow:"1",asChild:!0,children:i.jsx(o.TextField.Root,{size:"3",children:i.jsx(o.TextField.Input,{placeholder:"Filter",value:r,onChange:v})})}),i.jsx(o.Select,{items:y,value:c,onValueChange:u,placeholder:"Owner",size:"large"})]}),f.length>0&&i.jsx(o.ButtonList.Root,{children:f.map(w=>i.jsx(Vt,{...t,form:w,handleToggleFavorite:()=>g(w)},w.offline_id))}),i.jsx(o.Box,{px:"3",children:i.jsx(o.Text,{size:"2",severity:"info",children:C})})]})})),Vt=l=>{var g;const{form:n,onSelectForm:e,isFavoriteEditable:t,handleToggleFavorite:r}=l,s=(g=F.useAppSelector(F.selectOrganization(n.owner_organization||-1)))==null?void 0:g.name,c=F.useAppSelector(F.selectUser(n.owner_user||-1)),u=F.useAppSelector(F.selectCurrentUser).id,a=!!c&&c.id===u,h=s??(a?"You":c==null?void 0:c.username)??"Unknown",f=d.useCallback(y=>{y.stopPropagation(),r()},[r]),p=i.jsx(o.ButtonList.Item,{onClick:()=>e(n),asChild:!0,children:i.jsxs(o.Flex,{justify:"between",gap:"2",py:"2",px:"3",...o.divButtonProps,children:[i.jsxs(o.Flex,{grow:"1",align:"center",gap:"2",children:[i.jsx(o.IconButton,{className:F.classNames(n.favorite?dt.favoriteIcon:dt.regularIcon),variant:"ghost",onClick:f,"aria-label":n.favorite?"Favorite form":"Standard form",disabled:!t,children:n.favorite?i.jsx(o.StarFilledIcon,{}):i.jsx(o.StarIcon,{})}),i.jsx(o.Text,{noWrap:!0,children:n.latestRevision.title}),n.latestRevision.description&&i.jsx(o.QuestionMarkCircledIcon,{})]}),h&&i.jsxs(o.Flex,{align:"center",gap:"2",children:[i.jsx(o.PersonIcon,{})," ",h]})]})});return n.latestRevision.description?i.jsx(o.Tooltip,{content:n.latestRevision.description,children:p},n.offline_id):p},ct={submissionsContainer:"_submissionsContainer_9iirt_1",stopHorizontalOverflow:"_stopHorizontalOverflow_9iirt_6"},Bt=d.memo(function(n){var w;const{submission:e,onSubmissionClick:t,compact:r,labelType:s,rowDecorator:c}=n,u=F.useAppSelector(F.selectCurrentUser),a=F.useAppSelector(F.selectUser("created_by"in e?e.created_by:u.id)),h=Ue(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,y=F.useFileSrc({file:(a==null?void 0:a.profile.file)??null,fileSha1:(a==null?void 0:a.profile.file_sha1)??null}),v=(a==null?void 0:a.username.charAt(0).toUpperCase())??"?",S=p.revision===g,b=d.useCallback(()=>{t&&t({submission:e})},[e,t]),C=i.jsx(o.ButtonList.Item,{onClick:b,asChild:!0,children:i.jsxs(o.Flex,{grow:"1",width:"100%",p:"2",gap:"2",justify:"between",children:[i.jsxs(o.Flex,{gap:"2",align:"center",className:ct.stopHorizontalOverflow,children:[i.jsx(o.Avatar,{src:y,size:"1",fallback:v}),i.jsx(o.Text,{size:"2",noWrap:!0,children:s==="creator"?(a||u).username:p.title})]}),i.jsxs(o.Flex,{gap:"2",align:"center",children:[!r&&(p.revision?i.jsx(o.Badge,{variant:"soft",severity:S?"primary":"info",children:r?p.revision.toString():`Revision #${p.revision}`}):!!g&&i.jsx(o.Badge,{children:"Original"})),i.jsx(o.Text,{size:"2",noWrap:!0,children:f})]})]})});return c?c(e,C):C}),Ue=l=>{const n="created_at"in l?l.created_at:l.submitted_at;return new Date(n)},_t=d.memo(function(n){const{formId:e,submissions:t,compact:r=!1,className:s,after:c,variant:u="outline",...a}=n;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=d.useMemo(()=>h==null?void 0:h.sort((p,g)=>Ue(g).getTime()-Ue(p).getTime()),[h]);return i.jsx(o.ButtonList.Root,{className:F.classNames(ct.submissionsContainer,s),size:"small",variant:u,before:!r&&i.jsxs(o.Text,{severity:"info",children:["There are ",((h==null?void 0:h.length)||0).toString()," submissions of this form."]}),after:c,children:f==null?void 0:f.map((p,g)=>i.jsx(Bt,{submission:p,compact:r,...a},g))})}),Ot=d.memo(function(n){const{name:e,render:t}=n,{submitForm:r}=D.useFormikContext(),[s,c,u]=D.useField(e);return d.useMemo(()=>{const a=h=>u.setValue(h,!1);return t({value:s.value,setValue:a,patchValue:r})},[r,u,s.value,t])}),Nt=d.memo(d.forwardRef((l,n)=>{const{children:e,schema:t,values:r,onPatch:s,onError:c,...u}=l,a=d.useMemo(()=>He(t.fields,r),[t.fields,r]),h=d.useCallback(v=>{const S={};for(const b in v){const C=v[b];C!==a[b]&&C!==void 0&&(S[b]=C)}be(S)&&s(S)},[a,s]),f=d.useCallback(async v=>{const S=await at(t,v);return S&&c(S),S},[t,c]),p=D.useFormik({initialValues:a,onSubmit:h,validate:f,validateOnBlur:!1,validateOnChange:!1}),{errors:g,resetForm:y}=p;return d.useEffect(()=>{be(g)&&y({values:a,errors:{}})},[g,a,y]),i.jsx(D.FormikProvider,{value:p,children:i.jsx("form",{...u,ref:n,onSubmit:p.handleSubmit,children:e})})})),ut={...Be,section:G},qt=d.memo(function(n){const{field:e,setFieldType:t}=n,r=e.fieldTypeName,s=e.fieldTypeDescription,c=e.Icon;return i.jsxs(o.Flex,{gap:"4",align:"center",children:[i.jsx(o.Button,{type:"button",variant:"surface",onClick:t,style:{width:"135px"},children:i.jsxs(o.Flex,{gap:"3",align:"center",grow:"1",children:[i.jsx(c,{}),r]})}),i.jsx(o.Text,{children:s})]})}),ft=[["string","text"],["select","multi-select","upload"],["boolean","date","number","multi-string"]],Ht=ft.length-1,Wt=d.memo(function(n){const{setFieldType:e}=n;return i.jsx(o.Flex,{direction:"column",gap:"3",children:ft.map((t,r)=>i.jsxs(o.Flex,{direction:"column",gap:"3",children:[i.jsx(o.Flex,{direction:"column",gap:"2",children:t.map(s=>i.jsx(qt,{field:Be[s],setFieldType:()=>e(s)},s))}),r<Ht&&i.jsx(o.Separator,{size:"4"})]},r))})}),jt=l=>n=>{if(!(!n||typeof n!="string")&&l.includes(n.trim()))return"This name is already taken."},Ut=(l,n)=>{const e=[new J({label:"Label",required:!0,maxLength:200,identifier:"label",fieldValidators:[jt(l)]}),new k({label:"Description",required:!1,maxLength:1e3,identifier:"description"})];return n==="section"?e:[...e,new Z({label:"Required",description:null,required:!1,identifier:"required"})]},Gt=d.memo(function(n){const{fieldType:e,handleCancel:t,handleCreateField:r,defaultField:s,conditionalSourceFields:c}=n,u=ut[e],a=D.useFormikContext(),h=d.useMemo(()=>{const f=nt(a.values.fields).filter(g=>g!==(s==null?void 0:s.label));let p=Ut(f,e);if(u===G){if(c===void 0)throw new Error("Conditional source fields must be provided when changing sections.");p=p.concat(u.getFieldCreationSchema(c))}else{if(!(u.prototype instanceof V))throw new Error(`Field must be an instance of BaseField. Got ${u}.`);p=[...p,...u.getFieldCreationSchema()]}return{fields:p,meta:{readonly:!1},title:null}},[a.values.fields,e,u,s==null?void 0:s.label,c]);return i.jsx(Ce,{schema:h,values:s,onSubmit:r,cancelText:s?void 0:"Back",onCancel:t})}),he=d.memo(function(n){const{parentPath:e,index:t,children:r,initial:s,editing:c,conditionalSourceFields:u}=n,[a,h]=d.useState(),f=(s==null?void 0:s.type)??a,p=f?ut[f].fieldTypeName:void 0,{setFieldValue:g,values:y}=D.useFormikContext();if(c&&!s)throw new Error("Initial field must be provided if editing is true.");const v=!f&&!c&&!s,S=v?"Choose a field type":`${p} settings`,b=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=d.useCallback(()=>h(void 0),[]),w=d.useCallback(I=>{h(void 0),I()},[]),L=d.useCallback((I,M)=>{const{label:O}=I;if(!f)throw new Error("Field type must be selected before creating a field.");if(!O||typeof O!="string")throw new Error("Label must be provided before creating a field.");const ae=fe({type:f,...I,identifier:tt(I.identifier,O)}).serialize(),K=X(y,e);if(K===void 0)throw new Error("Parent path must point to an existing field.");let Y;if(!Array.isArray(K))throw new Error("Parent path must point to an array.");c?Y=bt(K,t,ae):Y=et(K,t,ae),g(e,Y).then(),M()},[c,f,y,e,g,t]),E=d.useCallback(I=>v?i.jsx(Wt,{setFieldType:h}):i.jsx(Gt,{conditionalSourceFields:u,handleCancel:C,handleCreateField:M=>L(M,I),fieldType:f,defaultField:s}),[u,C,L,s,v,f]);return i.jsx(o.Dialog,{onCloseInterrupt:w,title:S,description:b,content:E,children:r})}),pt=({children:l})=>i.jsx(i.Fragment,{children:l}),ht=(l,n)=>({initial:l?n:"none",sm:l?"none":n}),mt=d.memo(function(n){const{remove:e,dragHandleProps:t,editProps:r,insertAfterProps:s,duplicateProps:c}=n,u=d.useMemo(()=>[{Wrapper:he,wrapperProps:r,Icon:o.Pencil1Icon,text:"Edit"},{Icon:o.TrashIcon,buttonProps:{onClick:e},text:"Delete"},{Wrapper:he,wrapperProps:c,Icon:o.CopyIcon,text:"Duplicate"},{Wrapper:he,wrapperProps:s,Icon:o.PlusIcon,text:"Add after"},{Icon:a=>i.jsx("div",{...a,children:i.jsx(o.DragHandleDots2Icon,{})}),text:"Reorder",disableOnMobile:!0,buttonProps:{...t,asChild:!0}}],[t,c,r,s,e]);return i.jsxs(i.Fragment,{children:[i.jsx(o.Flex,{gap:"4",display:ht(!1,"flex"),children:u.map(a=>{const h=a.Wrapper??pt;return i.jsx(h,{...a.wrapperProps,children:i.jsx(o.IconButton,{type:"button",variant:"ghost","aria-label":a.text,...a.buttonProps,children:i.jsx(a.Icon,{})})},a.text)})}),i.jsx(o.Box,{display:ht(!0,"block"),children:i.jsx(o.DropdownMenu,{trigger:i.jsx(o.IconButton,{variant:"ghost","aria-label":"Actions menu",children:i.jsx(o.DotsVerticalIcon,{})}),closeOnSelect:!1,items:u.map(a=>{var f;if(a.disableOnMobile)return null;const h=a.Wrapper??pt;return{...a.buttonProps,onSelect:(f=a.buttonProps)==null?void 0:f.onClick,content:i.jsx(h,{...a.wrapperProps,children:i.jsxs(o.Flex,{gap:"2",align:"center",children:[i.jsx(a.Icon,{}),a.text]})})}}).filter(a=>a!==null)})})]})}),Te="form-builder",Kt=d.memo(function(n){const{field:e,index:t,sectionIndex:r,takenLabels:s,remove:c}=n,u=d.useMemo(()=>fe(e),[e]),a=pe(u,{formId:Te,disabled:!0}),h=d.useCallback(y=>{if(y.label===null)throw new Error(`Expected a label for field ${y.identifier}`);return{...y,label:De(y.label,s),identifier:""}},[s]),f=d.useMemo(()=>({index:t,parentPath:`fields.${r}.fields`,initial:e,editing:!0}),[e,t,r]),p=d.useMemo(()=>({parentPath:`fields.${r}.fields`,index:t+1,initial:h(e)}),[h,e,t,r]),g=d.useMemo(()=>({parentPath:`fields.${r}.fields`,index:t+1,initial:void 0}),[t,r]);return i.jsx(j.Draggable,{draggableId:e.identifier,index:t,children:y=>i.jsx(o.Card,{ref:y.innerRef,...y.draggableProps,...y.dragHandleProps,id:`${e.identifier}-card`,mb:"4",children:i.jsxs(o.Flex,{gap:"4",justify:"between",align:"center",children:[a,i.jsx(mt,{remove:c,editProps:f,duplicateProps:p,insertAfterProps:g,dragHandleProps:y.dragHandleProps})]})})})}),Yt=d.memo(function(n){var Y,A,N,Q,Se,ze,Ae,xt,vt;const{field:e,index:t,dropState:r,conditionalFieldCounts:s}=n,c=(Y=r[e.identifier])==null?void 0:Y.disabled,u=F.useAppSelector(F.selectAppearance),{setFieldValue:a,values:h}=D.useFormikContext(),f=o.useAlertDialog(),p=nt(h.fields),g=d.useCallback((z,T)=>{for(const $ of z){const P=T.indexOf($);a(`fields.${P}.condition`,null).then(),a(`fields.${P}.conditional`,!1).then()}},[a]),y=d.useCallback(z=>{var P;const T=e.fields[z];if(!T)throw new Error("Could not find field to remove.");const $=[];for(const B of h.fields)((P=B.condition)==null?void 0:P.identifier)===T.identifier&&$.push(B);return{removing:T,affectedSections:$,action:()=>a(`fields.${t}.fields`,ve(e.fields,z))}},[e.fields,h.fields,a,t]),v=d.useCallback(z=>{const{affectedSections:T,action:$,removing:P}=y(z),B=()=>{$().then(),g(T,h.fields)};if(T.length>0){const Ge=T.map(Ee=>Ee.label).join(", ");return f({title:"Remove condition?",description:`${P.label} is being used as a condition, deleting it will remove the condition from the ${Ge} section(s).`,severity:"danger",actionText:"Remove",onAction:B})}B()},[y,g,h.fields,f]),S=d.useCallback(()=>{const T=e.fields.map((Me,ri)=>y(ri)).flatMap(Me=>Me.affectedSections),$=T.length?"Remove fields and conditions?":"Remove fields?",P=e.fields.length,B=T.map(Me=>Me.label).join(", "),Ge=T.length?`Deleting this section will remove the ${P} field(s) it contains and will remove the conditions from following sections: ${B}`:`Deleting this section will remove the ${P} field(s) it contains.`,Ee=ve(h.fields,t),wt=()=>a("fields",Ee);if(T.length>0)return f({title:$,description:Ge,severity:"danger",actionText:"Remove",onAction:()=>{wt().then(()=>{g(T,Ee)})}});wt().then()},[e.fields,h.fields,t,y,a,f,g]),b=d.useCallback(z=>{if(z.label===null)throw new Error(`Expected a label for field ${z.identifier}`);const T=De(z.label,p),$=z.fields.map(P=>{const B=De(P.label,p);return{...P,label:B,identifier:tt(void 0,B)}});return{...z,label:T,fields:$,identifier:""}},[p]),C=d.useMemo(()=>({index:t,parentPath:"fields",initial:e,editing:!0,conditionalSourceFields:we(h.fields,t)}),[e,t,h.fields]),w=d.useMemo(()=>({index:t+1,parentPath:"fields",initial:xe(),conditionalSourceFields:we(h.fields,t+1)}),[t,h.fields]),L=d.useMemo(()=>({parentPath:`fields.${t}.fields`,index:e.fields.length,initial:void 0}),[e.fields.length,t]),E=d.useMemo(()=>({index:t+1,parentPath:"fields",initial:b(e),conditionalSourceFields:we(h.fields,t+1)}),[b,e,t,h.fields]),I=d.useMemo(()=>{var z,T;return(T=it(h.fields,(z=e.condition)==null?void 0:z.identifier))==null?void 0:T.label},[(A=e.condition)==null?void 0:A.identifier,h.fields]),M=Array.isArray((N=e.condition)==null?void 0:N.value)?"contains all of":"equals";if(Ie((Q=e.condition)==null?void 0:Q.value))throw new Error("File values are not supported for conditions.");const O=Array.isArray((Se=e.condition)==null?void 0:Se.value)?(Ae=(ze=e.condition)==null?void 0:ze.value)==null?void 0:Ae.map(z=>typeof z=="string"?z:z.label).join(", "):(vt=(xt=e.condition)==null?void 0:xt.value)==null?void 0:vt.toString(),ae=()=>{const T=s.filter(B=>B!==null).length,$=s[t]??0,P=6/T*$;return i.jsx("div",{id:`${e.identifier}-floating-point`,style:{width:`${6-P}%`,marginRight:`${P}%`,marginBottom:"4"}})},K=()=>e.condition?i.jsxs(i.Fragment,{children:[i.jsx(Ke,{start:`${e.identifier}-card`,end:`${e.identifier}-floating-point`,startAnchor:"left",endAnchor:"right",color:u==="light"?"black":"white",strokeWidth:2,path:"straight",showHead:!1}),i.jsx(Ke,{start:`${e.identifier}-floating-point`,end:`${e.condition.identifier}-card`,startAnchor:"right",endAnchor:"left",color:u==="light"?"white":"black",strokeWidth:2,path:"grid",gridBreak:"0"})]}):null;return i.jsx(j.Draggable,{draggableId:e.identifier,index:t,children:z=>i.jsxs(o.Flex,{ref:z.innerRef,...z.draggableProps,...z.dragHandleProps,direction:"row",justify:"center",align:"center",children:[s.some(T=>T!==null)&&ae(),e.condition&&K(),i.jsx(o.Card,{id:`${e.identifier}-card`,mb:"4",style:{flexGrow:"1"},children:i.jsxs(o.Flex,{gap:"3",justify:"between",align:"center",children:[i.jsxs(o.Flex,{direction:"column",gap:"2",grow:"1",children:[i.jsxs(o.Flex,{direction:"column",children:[i.jsx(o.Heading,{as:"h3",size:"3",children:e.label}),i.jsx(o.Text,{className:me.description,children:e.description})]}),e.condition&&i.jsx(o.Text,{size:"1",children:i.jsxs(o.Em,{children:["Display only if ",i.jsx(o.Strong,{children:I})," ",M," ",i.jsx(o.Strong,{children:O})]})}),i.jsx(j.Droppable,{droppableId:e.identifier,type:"SECTION",isDropDisabled:c,children:T=>i.jsxs(o.Flex,{ref:T.innerRef,...T.droppableProps,direction:"column",gap:"0",children:[e.fields.map(($,P)=>i.jsx(Kt,{field:$,index:P,sectionIndex:t,remove:()=>v(P),takenLabels:p},$.identifier)),T.placeholder,i.jsx(he,{...L,children:i.jsxs(o.Button,{type:"button",variant:"outline",children:[i.jsx(o.PlusIcon,{})," Add a field"]})})]})})]}),i.jsx(mt,{remove:S,insertAfterProps:w,dragHandleProps:z.dragHandleProps,editProps:C,duplicateProps:E})]})})]})})}),Zt=(l,n)=>{var t;const e={...l};switch(n.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(n.fieldId)&&(e[r].disabled=!0);return e;case"update":return n.state}},Qt=(l,n)=>{if(n)for(let e=0;e<l.length;e++){const t=l[e];if(t){for(const r of t.fields)if(r.identifier===n)return e}}},gt=l=>{var e,t,r;const n={};for(let s=0;s<l.length;s++){const c=l[s];if(!c)throw new Error("Field is undefined.");const u=s>0?(e=n[l[s-1].identifier])==null?void 0:e.conditionFields:void 0,a=new Set(u);(t=c.condition)!=null&&t.identifier&&a.add(c.condition.identifier),n[c.identifier]={disabled:!1,conditionFields:a,conditionIndex:Qt(l,(r=c.condition)==null?void 0:r.identifier),index:s,label:c.label}}return n},yt=(l,n)=>{for(const[e,t]of Object.entries(l))if(t.identifier===n)return[t,e]},Xt=d.memo(function(){const{values:n,setFieldValue:e}=D.useFormikContext(),[t,r]=d.useReducer(Zt,n.fields,gt),{showInfo:s}=o.useToast();d.useEffect(()=>{r({type:"update",state:gt(n.fields)})},[r,n.fields]);const c=d.useCallback(f=>{f.type==="SECTION"&&r({type:"hold",fieldId:f.draggableId})},[]),u=d.useCallback(f=>{const{source:p,destination:g,type:y,reason:v,draggableId:S}=f;if(r({type:"release"}),!g||v==="CANCEL")return;if(y==="ROOT"){const E=t[S];if(!E)throw new Error("Could not find section context.");let I=typeof E.conditionIndex<"u"?Math.max(E.conditionIndex+1,g.index):g.index;for(const M of Object.values(t))M.conditionIndex===p.index&&(I=Math.min(I,M.index-1));return I!=g.index&&s({title:"Reordered sections",description:"Sections with conditions must be below the fields they reference."}),e("fields",Le(n.fields,p.index,I))}if(y!=="SECTION")throw new Error("Unexpected droppable type.");const[b,C]=yt(n.fields,p.droppableId)??[],[w,L]=yt(n.fields,g.droppableId)??[];if(!(b!=null&&b.fields)||!w)throw new Error("Could not find section with fields.");if(b.identifier===w.identifier)e(`fields.${C}.fields`,Le(b.fields,p.index,g.index)).then();else{const E=b.fields[p.index];if(!E)throw new Error("Could not find field to reorder.");e(`fields.${C}.fields`,ve(b.fields,p.index)).then(),e(`fields.${L}.fields`,et(w.fields,g.index,E)).then()}},[n.fields,e,t,s]),a=d.useMemo(()=>({index:n.fields.length,parentPath:"fields",initial:xe(),conditionalSourceFields:we(n.fields,n.fields.length)}),[n.fields]),h=()=>{let f=1;return n.fields.map(p=>p.conditional?f++:null)};return i.jsx(j.DragDropContext,{onDragStart:c,onDragEnd:u,children:i.jsx(j.Droppable,{droppableId:"droppable",type:"ROOT",children:f=>i.jsxs(o.Flex,{ref:f.innerRef,...f.droppableProps,direction:"column",gap:"0",children:[n.fields.map((p,g)=>i.jsx(Yt,{field:p,index:g,dropState:t,conditionalFieldCounts:h()},p.label)),f.placeholder,i.jsx(he,{...a,children:i.jsxs(o.Button,{type:"button",variant:"outline",children:[i.jsx(o.PlusIcon,{})," Add a section"]})})]})})})}),Jt={title:"",description:"",fields:[]},kt=new J({label:"Title",minLength:0,maxLength:100,required:!0,identifier:"title"}),Rt={formId:Te,placeholder:"Give your form a title."},ei=new k({label:"Description",minLength:0,maxLength:1e3,required:!1,identifier:"description"}),ti={formId:Te,placeholder:"Explain the purpose of this form."},ii=()=>{alert("This is a form preview, your data will not be saved.")},ni=d.memo(d.forwardRef((l,n)=>{const{onCancel:e,onSave:t,revision:r}=l,s=r?"Edit form":"Create a new form",{heading:c=s}=l,u=d.useCallback(y=>{const v={};if(y.title||(v.title="Title is required."),(!y.fields||y.fields.length===0)&&(v.fields="At least one field is required."),be(v))return v},[]),a=D.useFormik({initialValues:It(r)??Jt,validate:u,onSubmit:y=>t(y),validateOnChange:!1,validateOnBlur:!1}),h=d.useMemo(()=>Oe(a.values),[a.values]),f=pe(kt,Rt),p=pe(ei,ti),g=d.useMemo(()=>typeof c=="object"?c:i.jsx(o.Heading,{children:c}),[c]);return i.jsx(o.Tabs.Root,{ref:n,defaultValue:"edit",children:i.jsxs(o.Flex,{direction:"column",gap:"2",children:[i.jsxs(o.Tabs.List,{children:[i.jsx(o.Tabs.Trigger,{value:"edit",children:"Edit"}),i.jsx(o.Tabs.Trigger,{value:"preview",children:"Preview"})]}),i.jsxs(o.Tabs.Content,{value:"edit",children:[g,i.jsxs(o.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"," ",i.jsx("em",{children:"Preview"})," tab, but"," ",i.jsx("strong",{children:"field values entered on this page will not be saved."})]}),i.jsx(o.Flex,{asChild:!0,direction:"column",gap:"2",mt:"3",children:i.jsxs("form",{id:Te,onSubmit:a.handleSubmit,children:[i.jsxs(D.FormikProvider,{value:a,children:[f,p,i.jsx(Xt,{}),i.jsx(o.Text,{severity:"danger",size:"1",children:typeof a.errors.fields=="string"&&a.errors.fields})]}),i.jsxs(o.Flex,{justify:"end",gap:"2",children:[i.jsx(o.Button,{type:"button",variant:"soft",onClick:e,children:"Cancel"}),i.jsx(o.Button,{type:"submit",disabled:!a.isValid,children:"Save"})]})]})})]}),i.jsx(o.Tabs.Content,{value:"preview",children:i.jsx(Ce,{schema:h,onSubmit:ii})})]})})}));x.BooleanField=Z,x.BooleanInput=Ze,x.DateField=ge,x.DateInput=Xe,x.FieldSection=G,x.FormBrowser=$t,x.FormBuilder=ni,x.FormRenderer=Ce,x.FormSubmissionBrowser=_t,x.FormSubmissionViewer=Dt,x.MultiSelectField=ue,x.MultiSelectInput=st,x.MultiStringField=de,x.MultiStringInput=rt,x.NumberField=U,x.NumberInput=Qe,x.PatchField=Ot,x.PatchFormProvider=Nt,x.SelectField=ce,x.SelectInput=Re,x.StringField=J,x.StringInput=Je,x.TextField=k,x.TextInput=ke,x.deserialize=fe,x.deserializeField=_e,x.formRevisionToSchema=Oe,x.isConditionMet=Ne,x.useFieldInput=pe,x.useFieldInputs=qe,x.valueIsFile=Ie,Object.defineProperty(x,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(x,i){typeof exports=="object"&&typeof module<"u"?i(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"),require("react-xarrows")):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","react-xarrows"],i):(x=typeof globalThis<"u"?globalThis:x||self,i(x.forms={},x.jsxRuntime,x.blocks,x.formik,x.React,x.dnd,x.core,x.get,x.set,x.Xarrow))})(this,function(x,i,o,D,d,j,F,X,Pe,Ke){"use strict";var oi=Object.defineProperty;var si=(x,i,o)=>i in x?oi(x,i,{enumerable:!0,configurable:!0,writable:!0,value:o}):x[i]=o;var m=(x,i,o)=>(si(x,typeof i!="symbol"?i+"":i,o),o);class Ye{constructor(n){m(this,"type");m(this,"identifier");m(this,"description");const{description:e=null,identifier:t,type:r}=n;this.identifier=t,this.description=e,this.type=r}getId(){return this.identifier}static deserialize(n){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 V extends Ye{constructor(e){const{label:t,required:r,fieldValidators:s=[],formValidators:c=[],...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=s,this.formValidators=c}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 s=r(e);if(s)return s}if(t)for(const r of this.getFormValidators()){const s=r(e,t);if(s)return s}}_serialize(){return{...super._serialize(),label:this.label,required:this.required}}getFieldValidators(){return[...this.fieldValidators]}getFormValidators(){return[...this.formValidators]}}m(V,"fieldTypeName"),m(V,"fieldTypeDescription");const me={description:"_description_17zed_1"},q=l=>{const{label:n,children:e,severity:t,inputId:r,labelId:s,flexProps:c}=l;return i.jsx(o.Flex,{direction:"column",gap:"1",asChild:!0,...c,children:i.jsxs("label",{htmlFor:r,children:[i.jsx(o.Text,{severity:t,id:s,children:n}),e]})})},H=l=>{const{helpText:n,children:e,severity:t}=l;return i.jsxs(o.Flex,{direction:"column",gap:"1",children:[e,i.jsx(o.Flex,{direction:"column",children:i.jsx(o.Text,{size:"1",severity:t,className:me.description,children:n})})]})},W=l=>{const{id:n,field:e,formId:t,...r}=l,[s,c,u]=D.useField(e.getId()),{touched:a}=c,h=c.error??e.description,f=c.error?"danger":void 0,p=n??`${t}-${e.getId()}-input`,g=`${p}-label`,y=e.required?`${e.label} *`:e.label,v=d.useMemo(()=>({...s,onChange:C=>{const w=e.getValueFromChangeEvent(C);u.setValue(w,!1).then(),(a||!e.onlyValidateAfterTouched)&&u.setError(e.getError(w))},onBlur:C=>{u.setTouched(!0,!1).then(),u.setError(e.getError(e.getValueFromChangeEvent(C)))}}),[e,s,u,a]);return[{helpText:h,severity:f,inputId:p,labelId:g,label:y,fieldProps:v,helpers:u,field:e},{...r,"aria-labelledby":g}]},Ft=[!0,"true"],Ze=d.memo(function(n){const[{inputId:e,labelId:t,severity:r,helpText:s,label:c,fieldProps:u},a]=W(n),h=o.useSeverityColor(r),f=Ft.includes(u.value);return i.jsx(H,{helpText:s,severity:r,children:i.jsx(q,{severity:r,inputId:e,labelId:t,label:c,flexProps:{direction:"row-reverse",justify:"end",align:"center",gap:"2"},children:i.jsx(o.Checkbox,{...a,...u,id:e,color:h,value:f.toString(),checked:f,onCheckedChange:u.onChange,onChange:void 0,onBlur:void 0})})})}),R=class R extends V{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 i.jsx(Ze,{...e,field:this})}};m(R,"fieldTypeName","Checkbox"),m(R,"fieldTypeDescription","Perfect for both optional and required yes/no questions."),m(R,"Icon",o.CheckCircledIcon);let Z=R;const Qe=d.memo(function(n){const[{inputId:e,labelId:t,severity:r,helpText:s,label:c,fieldProps:u,field:a},h]=W(n),f=o.useSeverityColor(r);return i.jsx(H,{helpText:s,severity:r,children:i.jsx(q,{severity:r,inputId:e,labelId:t,label:c,children:i.jsx(o.TextField.Input,{...h,...u,type:"number",id:e,min:a.minimum,max:a.maximum,step:a.integers?1:.1,color:f})})})}),_=class _ extends V{constructor(e){const{minimum:t=Number.MIN_SAFE_INTEGER,maximum:r=Number.MAX_SAFE_INTEGER,integers:s=!1,...c}=e;super({...c,type:"number"});m(this,"minimum");m(this,"maximum");m(this,"integers");this.minimum=t,this.maximum=r,this.integers=s}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 Z({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(s=>{if(typeof s=="number"&&s<t)return`Must be at least ${this.minimum}.`}),typeof r=="number"&&e.push(s=>{if(typeof s=="number"&&s>r)return`Must be at most ${this.maximum}.`}),this.integers&&e.push(s=>{if(typeof s=="number"&&!Number.isInteger(s))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 i.jsx(Qe,{field:this,...e})}};m(_,"fieldTypeName","Number"),m(_,"fieldTypeDescription","Allows specifying a number within a given range."),m(_,"Icon",o.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 U=_;const Xe=d.memo(function(n){const[{inputId:e,labelId:t,severity:r,helpText:s,label:c,fieldProps:u},a]=W(n),h=o.useSeverityColor(r),f=u.value?u.value.split("T")[0]:"";return i.jsx(H,{helpText:s,severity:r,children:i.jsx(q,{severity:r,inputId:e,labelId:t,label:c,children:i.jsx(o.TextField.Input,{...a,...u,type:"date",id:e,color:h,value:f})})})}),ee=class ee extends V{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 i.jsx(Xe,{field:this,...e})}};m(ee,"fieldTypeName","Date"),m(ee,"fieldTypeDescription","Allows specifying a date."),m(ee,"Icon",o.CalendarIcon);let ge=ee;class ye extends V{constructor(e){const{minLength:t,maxLength:r=5e3,...s}=e;super(s);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 U({label:"Minimum length",description:"Minimum number of characters",required:!1,identifier:"minimum_length",minimum:0,maximum:100,formValidators:[this._validateMin],integers:!0}),new U({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(ye,"_validateMin",(e,t)=>typeof t.maximum_length=="number"&&typeof e=="number"&&t.maximum_length<e?"Minimum cannot be greater than maximum.":null),m(ye,"_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 Je=d.memo(function(n){const[{inputId:e,labelId:t,severity:r,helpText:s,label:c,fieldProps:u,field:a},h]=W(n),f=o.useSeverityColor(r);return i.jsx(H,{helpText:s,severity:r,children:i.jsx(q,{severity:r,inputId:e,labelId:t,label:c,children:i.jsx(o.TextField.Input,{...h,...u,type:a.inputType,id:e,color:f})})})}),te=class te extends ye{constructor(e){const{inputType:t="text",...r}=e,s=e.maxLength?Math.min(500,e.maxLength):500,c=e.minLength?Math.min(e.minLength,s):void 0;super({...r,maxLength:s,minLength:c,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:s,...c}=e;return new te({...c,maxLength:t,minLength:r,inputType:s})}getInput(e){return i.jsx(Je,{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",o.InputIcon);let J=te;const ke=d.memo(function(n){const[{inputId:e,labelId:t,severity:r,helpText:s,label:c,fieldProps:u},a]=W(n);return i.jsx(H,{helpText:s,severity:r,children:i.jsx(q,{severity:r,inputId:e,labelId:t,label:c,children:i.jsx(o.TextArea,{...a,...u,resize:"vertical",id:e,severity:r})})})}),ie=class ie extends ye{constructor(n){const e=n.maxLength?Math.min(5e3,n.maxLength):5e3,t=n.minLength?Math.min(n.minLength,e):void 0;super({...n,maxLength:e,minLength:t,type:"text"})}serialize(){return super._serialize()}static deserialize(n){if(n.type!=="text")throw new Error("Type mismatch.");const{maximum_length:e,minimum_length:t,...r}=n;return new ie({...r,maxLength:e,minLength:t})}getInput(n){return i.jsx(ke,{field:this,...n})}};m(ie,"fieldTypeName","Paragraph"),m(ie,"fieldTypeDescription","Paragraph fields can hold up to 5000 characters and can have multiple lines."),m(ie,"Icon",o.RowsIcon);let k=ie;const Re=d.memo(function(n){const[{inputId:e,labelId:t,severity:r,helpText:s,label:c,fieldProps:u,field:a},h]=W(n),{onChange:f,onBlur:p}=u,g=d.useMemo(()=>a.options.map(v=>({value:v.value,itemContent:v.label})),[a.options]),y=d.useCallback(v=>{f(v),p(v)},[f,p]);return i.jsx(H,{helpText:s,severity:r,children:i.jsx(q,{severity:r,inputId:e,labelId:t,label:c,children:i.jsx(o.Select,{items:g,...u,onValueChange:y,placeholder:"Select one...",id:e,severity:r,...h})})})}),xe=(l="",n=[])=>({type:"section",fields:n,identifier:l,label:null,condition:null,conditional:!1}),It=l=>{if(!l)return;const n=l.fields;let e=[];const t=[];for(const r of n)r.type==="section"?(e.length>0&&(t.push(xe(`AUTO_section-${n.indexOf(r)}`,e)),e=[]),t.push(r)):e.push(r);return e.length>0&&t.push(xe("AUTO_section-last",e)),{...l,fields:t,description:l.description??""}};function Le(l,n,e){const t=Array.from(l),[r]=t.splice(n,1);if(!r)throw new Error("Could not find field to reorder.");return t.splice(e,0,r),t}function bt(l,n,e){const t=Array.from(l);return t[n]=e,t}function et(l,n,e){const t=Array.from(l??[]);return t.splice(n,0,e),t}function ve(l,n){const e=Array.from(l);return e.splice(n,1),e}const tt=(l,n)=>{if(typeof l=="string"&&l.length>0)return l;const e=new Date;return`${F.slugify(n)}-${e.getTime()}`},it=(l,n)=>{if(!n)return null;for(const e of l)if(e.type==="section"){const t=it(e.fields,n);if(t)return t}else if(e.identifier===n)return e;return null},we=(l,n)=>l.filter((e,t)=>t<n).flatMap(e=>e.fields),nt=l=>l.flatMap(n=>n.type==="section"?[...n.fields.map(e=>e.label),n.label]:n.label).filter(n=>n!==null),De=(l,n)=>{let e=1,t=`${l} (${e})`;for(;n.includes(t);)t=`${l} (${++e})`;return t},rt=d.memo(function(n){const[{inputId:e,labelId:t,severity:r,helpText:s,label:c,fieldProps:u},a]=W(n),h=o.useSeverityColor(r),f=d.useMemo(()=>Array.isArray(u.value)?u.value:[],[u.value]),{onChange:p,onBlur:g}=u,y=`${e}-droppable`,{disabled:v}=a,[z,b]=d.useState(""),[C,w]=d.useState(""),L=C||s,E=C?"red":h,I=d.useCallback(A=>{p(A),g(A)},[p,g]),M=d.useCallback(A=>{f.findIndex(N=>N.value===A.target.value.trim())>=0?w("All options must be unique"):A.target.value?w(""):w("Option cannot be empty"),b(A.target.value)},[b,f]),O=d.useCallback(()=>{if(C)return;if(!z.trim())return w("Option cannot be empty");const A=z.trim();I([...f,{value:A,label:A}]),b("")},[z,C,I,f]),ae=d.useCallback(A=>{A.key==="Enter"&&(A.preventDefault(),O())},[O]),K=d.useCallback(A=>{I(ve(f,A))},[f,I]),Y=d.useCallback(A=>{if(!A.destination)return;const N=A.source.index,Q=A.destination.index;I(Le(f,N,Q))},[I,f]);return i.jsx(j.DragDropContext,{onDragEnd:Y,children:i.jsxs(o.Flex,{direction:"column",gap:"2",children:[i.jsx(H,{helpText:L,severity:r,children:i.jsx(q,{severity:r,inputId:e,labelId:t,label:c,children:(!v||f.length===0)&&i.jsxs(o.Flex,{gap:"2",children:[i.jsx(o.Box,{grow:"1",children:i.jsx(o.TextField.Input,{placeholder:"Press enter to add a new option",...a,...u,value:z,onChange:M,onKeyDown:ae,id:e,color:E,onBlur:void 0})}),i.jsx(o.IconButton,{type:"button","aria-label":"Add option",disabled:!!C||v,onClick:O,children:i.jsx(o.PlusIcon,{})})]})})}),i.jsx(j.Droppable,{droppableId:y,children:A=>i.jsxs(o.Flex,{...A.droppableProps,ref:A.innerRef,direction:"column",children:[f.map((N,Q)=>i.jsx(j.Draggable,{draggableId:`${N.value}-draggable`,index:Q,isDragDisabled:v,children:({draggableProps:Se,dragHandleProps:ze,innerRef:Ae})=>i.jsx(o.Flex,{...ze,...Se,ref:Ae,gap:"2",align:"center",justify:"between",mb:"1",asChild:!0,children:i.jsxs(o.Badge,{color:"gray",size:"2",children:[i.jsx("span",{children:N.label}),i.jsx(o.IconButton,{size:"small",variant:"ghost",type:"button","aria-label":"Delete option",severity:"info",disabled:v,onClick:()=>K(Q),children:i.jsx(o.Cross1Icon,{})})]})})},N.value)),A.placeholder]})})]})})}),ne=class ne extends V{constructor(e){const{minimum_length:t,maximum_length:r,...s}=e;super({...s,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 i.jsx(rt,{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",o.ListBulletIcon);let de=ne;class ot extends V{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 de({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 ot{constructor(n){super({...n,type:"select"})}getValueFromChangeEvent(n){return typeof n=="string"?n:n.target.value}serialize(){return super._serialize()}static deserialize(n){if(n.type!=="select")throw new Error("Type mismatch.");return new re(n)}getInput(n){return i.jsx(Re,{field:this,...n})}};m(re,"fieldTypeName","Dropdown"),m(re,"fieldTypeDescription","Allows the user to select a single option from a list of options."),m(re,"Icon",o.DropdownMenuIcon);let ce=re;const Ct=l=>l?Array.isArray(l)?l:[l]:[],st=d.memo(function(n){const[{inputId:e,labelId:t,severity:r,helpText:s,label:c,fieldProps:u,field:a},h]=W(n),{onChange:f,onBlur:p}=u,g=d.useMemo(()=>Ct(u.value),[u.value]),y=d.useCallback(v=>{f(v),p(v)},[f,p]);return i.jsx(H,{helpText:s,severity:r,children:i.jsx(q,{severity:r,inputId:e,labelId:t,label:c,children:i.jsx(o.MultiSelect,{value:g,onValueChange:y,options:a.options,name:u.name,placeholder:"Select one or more...",id:e,severity:r,...h})})})}),oe=class oe extends ot{constructor(n){super({...n,type:"multi-select"})}getValueFromChangeEvent(n){if(Array.isArray(n))return n;throw new Error("Expected an array.")}isBlank(n){return super.isBlank(n)||n.length===0}serialize(){return super._serialize()}static deserialize(n){if(n.type!=="multi-select")throw new Error("Type mismatch.");return new oe(n)}getInput(n){return i.jsx(st,{field:this,...n})}};m(oe,"fieldTypeName","Multi-select"),m(oe,"fieldTypeDescription","Allows the user to select a multiple options from a list of options."),m(oe,"Icon",o.CheckboxIcon);let ue=oe;const Tt=d.memo(function({field:n,...e}){const[{value:t}]=D.useField(n.options.clonedFieldIdentifier),r=d.useMemo(()=>{const s=n.options.getFieldToClone(t);return s?fe(s):null},[n.options,t]);return pe(r,e)});class Fe extends V{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 i.jsx(t,{field:this,...e})}}m(Fe,"fieldTypeName","Custom"),m(Fe,"fieldTypeDescription","Allows re-rendering of field already in the form");class St extends Fe{constructor(n){super(n,Tt)}}const zt=d.memo(function(n){const{field:e,...t}=n,{label:r,description:s,fields:c,condition:u}=e,{values:a,setFieldValue:h}=D.useFormikContext(),f=u!=null&&u.identifier?X(a,u.identifier):void 0,p=d.useMemo(()=>Ne(u,f),[u,f]);d.useEffect(()=>{if(!p)for(const y of c)h(y.getId(),"").then()},[p,c,h]);const g=qe(c,t);return p?r?i.jsx(o.Card,{children:i.jsxs(o.Flex,{direction:"column",gap:"3",children:[i.jsxs(o.Flex,{direction:"column",children:[i.jsx(o.Heading,{as:"h3",size:"3",children:r}),i.jsx(o.Text,{className:me.description,children:s})]}),g]})}):g:null}),se=class se extends Ye{constructor(e){const{label:t=null,fields:r,condition:s=null,conditional:c,...u}=e;super({...u,type:"section"});m(this,"label");m(this,"fields");m(this,"condition");this.fields=r,this.condition=s,this.label=t,c===!1&&(this.condition=null)}static getFieldCreationSchema(e){return e.length===0?[]:[new Z({label:"Conditional",description:"Conditionally show or hide this section.",identifier:"conditional",required:!1}),new se({label:"Conditional settings",identifier:"conditional-settings",condition:{identifier:"conditional",value:!0},fields:[new ce({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 St({label:"Value",identifier:"condition.value",required:!0,clonedFieldIdentifier:"condition.identifier",getFieldToClone(t){if(!t)return null;const r=e.find(s=>s.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(_e))??[];return new se({...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 s=r.getId(),c=r.getError(X(e,s),e);c&&Pe(t,r.getId(),c)}return t}getInput(e){return i.jsx(zt,{field:this,...e})}};m(se,"fieldTypeName","Section"),m(se,"fieldTypeDescription","Sections can be useful for grouping fields together. They can also be conditionally shown or hidden.");let G=se;const At={previewImage:"_previewImage_1ig84_1"},$e=l=>{const n=["byte","kilobyte","megabyte"];let e=l,t=0;for(;e>1024&&t<n.length-1;)e/=1024,t++;return new Intl.NumberFormat([],{maximumFractionDigits:2,style:"unit",unit:n[t]}).format(e)},Et=d.memo(function(n){var E;const[{inputId:e,labelId:t,severity:r,helpText:s,label:c,fieldProps:u,field:a},h]=W(n),{onChange:f}=u,p=o.useSeverityColor(r),g=d.useRef(null),{value:y}=u,v=d.useMemo(()=>s||(a.maxFileSize?`Maximum file size: ${$e(a.maxFileSize)}`:null),[a.maxFileSize,s]),z=d.useCallback(()=>{var I;(I=g.current)==null||I.click()},[]),b=d.useCallback(I=>{const M=[...y];M.splice(I,1),f({target:{files:M}})},[y,f]),C=y?"Select new files":"Select files",w=y?"Select new file":"Select a file",L=a.maxFiles>1?C:w;return i.jsxs(o.Flex,{direction:"column",gap:"2",children:[i.jsx(H,{helpText:v,severity:r,children:i.jsxs(q,{severity:r,inputId:e,labelId:t,label:c,children:[i.jsx(o.Flex,{direction:"row",gap:"2",children:i.jsx(o.Box,{width:"max-content",asChild:!0,children:i.jsxs(o.Button,{...h,onClick:z,children:[i.jsx(o.UploadIcon,{})," ",L]})})}),i.jsx("input",{...h,type:"file",ref:g,id:e,accept:(E=a.extensions)==null?void 0:E.join(","),multiple:a.maxFiles>1,color:p,style:{display:"none"},...u,value:""})]})}),Array.isArray(y)&&y.length>0&&i.jsx(o.Flex,{direction:"column",gap:"2",children:y.map((I,M)=>i.jsx(Mt,{field:a,file:I,onRemove:()=>b(M),disabled:h.disabled},M))})]})}),Mt=d.memo(function({file:n,field:e,onRemove:t,disabled:r}){const[s,c]=d.useState(null),u=d.useMemo(()=>s&&e.getError([s]),[e,s]),{url:a,name:h,size:f}=d.useMemo(()=>{let p=null,g,y;return s!=null&&s.type.startsWith("image/")&&(p=URL.createObjectURL(s)),s?(g=s.name,y=$e(s.size)):(g="Downloading...",y="..."),{url:p,name:g,size:y}},[s]);return d.useEffect(()=>{n instanceof Promise?n.then(c):c(n)},[n]),i.jsx(o.Card,{children:i.jsxs(o.Flex,{direction:{initial:"column",sm:"row"},gap:"3",justify:"between",children:[i.jsxs(o.Flex,{direction:"row",gap:"3",align:"center",grow:"1",shrink:"0",children:[i.jsx(o.IconButton,{severity:"info",variant:"outline","aria-label":`Remove ${h}`,disabled:r,onClick:t,children:i.jsx(o.Cross1Icon,{})}),i.jsxs(o.Flex,{direction:"column",gap:"1",children:[i.jsx(o.Text,{children:h}),i.jsx(o.Text,{size:"1",children:f}),u&&i.jsx(o.Text,{size:"1",severity:"danger",children:u})]})]}),a&&i.jsx("img",{className:At.previewImage,src:a,alt:h})]})})}),lt=50*1024*1024,le=class le extends V{constructor(e){const{extensions:t,maximum_files:r,maximum_size:s,...c}=e;super({...c,type:"upload"});m(this,"extensions");m(this,"maxFileSize");m(this,"maxFiles");m(this,"onlyValidateAfterTouched",!1);this.maxFileSize=typeof s=="number"?s: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 U({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 U({label:"What is the maximum size of each file?",description:"Maximum file size in bytes.",required:!1,identifier:"maximum_size",minimum:1,maximum:lt,integers:!0}),new ue({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??lt,r=this.maxFiles??1;return e.push(s=>{if(s&&s.some(c=>c.size>t))return`Files must be at most ${$e(t)}.`}),e.push(s=>{if(s&&s.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 i.jsx(Et,{field:this,...e})}};m(le,"fieldTypeName","Upload"),m(le,"fieldTypeDescription","Allows a file to be uploaded."),m(le,"Icon",o.UploadIcon);let Ve=le;const Be={date:ge,number:U,boolean:Z,select:ce,string:J,text:k,custom:Fe,upload:Ve,"multi-string":de,"multi-select":ue},_e=l=>{const n=l.type;return Be[n].deserialize(l)},fe=l=>l.type==="section"?G.deserialize(l):_e(l);function Oe(l,n={}){const{readonly:e=!1}=n;return{title:l.title,description:l.description,fields:l.fields.map(t=>fe(t)),meta:{readonly:e}}}function Ie(l){return!!(Array.isArray(l)&&l.some(n=>n instanceof File||n instanceof Promise))}function Ne(l,n){if(!l)return!0;if(Ie(n)||Ie(l.value))throw new Error("Conditions do not support file uploads");const e=Array.isArray(n)?n.map(r=>typeof r=="string"?r:r.value):n,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===n}const pe=(l,n)=>d.useMemo(()=>!n||!l?null:l.getInput(n),[l,n]),qe=(l,n)=>{const e=d.useMemo(()=>l.map(t=>i.jsx("div",{children:t.getInput(n)},t.getId())),[l,n]);return i.jsx(o.Flex,{direction:"column",gap:"2",children:e})},be=l=>Object.keys(l).length>0,at=async(l,n)=>{const e={};for(const t of l.fields)if(t instanceof G){if(t.condition){const{identifier:r}=t.condition;if(!Ne(t.condition,X(n,r)))continue}Object.assign(e,t.getErrors(n))}else{if(!(t instanceof V))throw new Error("Invalid field type");const r=t.getId(),s=t.getError(X(n,r),n);s&&Pe(e,r,s)}if(be(e))return e},Pt=[null,void 0],He=(l,n)=>l.reduce((e,t)=>t instanceof G?{...e,...He(t.fields,n)}:(Pt.includes(X(e,t.getId()))&&Pe(e,t.getId(),""),e),n),Lt=()=>{throw new Error("onSubmit must be provided if form is not readonly.")},Ce=d.memo(d.forwardRef((l,n)=>{const{schema:e,values:t={},onSubmit:r=Lt,submitText:s="Submit",cancelText:c,onCancel:u,onDirty:a,hideTitle:h=!e.title,hideDescription:f,className:p}=l,{readonly:g}=e.meta,y=d.useMemo(()=>crypto.randomUUID(),[]),v=D.useFormik({initialValues:He(e.fields,t),onSubmit:r,validate:L=>at(e,L),validateOnBlur:!1,validateOnChange:!1}),{dirty:z}=v,b=d.useMemo(()=>typeof e.title=="string"?i.jsx(o.Heading,{children:e.title}):e.title,[e.title]),C=d.useMemo(()=>typeof e.description=="string"?i.jsx(o.Text,{className:me.description,children:e.description}):e.description,[e.description]),w=qe(e.fields,{formId:y,disabled:g});return d.useEffect(()=>{z&&a&&a()},[z,a]),i.jsx(D.FormikProvider,{value:v,children:i.jsx(o.Flex,{ref:n,direction:"column",gap:"2",className:p,asChild:!0,children:i.jsxs("form",{id:y,onSubmit:v.handleSubmit,children:[!h&&i.jsx(o.Card,{children:i.jsxs(o.Flex,{direction:"column",gap:"1",children:[b,!f&&C]})}),w,!g&&i.jsxs(o.Flex,{justify:"end",gap:"2",children:[c&&i.jsx(o.Button,{type:"button",variant:"soft",onClick:u,children:c}),i.jsx(o.Button,{type:"submit",disabled:!v.isValid,children:s})]})]})})})})),Dt=d.memo(d.forwardRef((l,n)=>{const{submission:e,showFormDescription:t=!1,showFormTitle:r=!0}=l,s=F.useAppSelector(F.selectFormRevision(e.form_revision)),{sdk:c}=F.useSDK();if(!s)throw new Error(`Could not find revision ${e.form_revision} for submission ${e.offline_id}.`);const u=d.useMemo(()=>Oe(s,{readonly:!0}),[s]),a=d.useMemo(()=>{const h=F.selectSubmissionAttachments(e.offline_id)(c.store.getState())??[],f={};for(const p of h){const g=c.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}),y=f[p.field_identifier];y?y.push(g):f[p.field_identifier]=[g]}return{...e.values,...f}},[c.files,c.store,e.offline_id,e.values]);return i.jsx(Ce,{ref:n,schema:u,values:a,hideDescription:!t,hideTitle:!r})})),dt={favoriteIcon:"_favoriteIcon_1bixi_1",regularIcon:"_regularIcon_1bixi_9"},We="organization:",je="user:",$t=d.memo(d.forwardRef((l,n)=>{const{maxResults:e=20,...t}=l,[r,s]=d.useState(""),[c,u]=d.useState(""),{sdk:a}=F.useSDK(),h=d.useMemo(()=>{const w={maxResults:e,searchTerm:r};return c&&(c.startsWith(We)?w.owner_organization=parseInt(c.slice(We.length)):c.startsWith(je)&&(w.owner_user=parseInt(c.slice(je.length)))),w},[r,e,c]),f=F.useAppSelector(F.selectFilteredUserForms(h))??[],p=F.useAppSelector(F.selectUserFormMapping),g=d.useCallback(w=>{w.favorite?a.userForms.unfavorite(w.offline_id).then():a.userForms.favorite(w.offline_id).then()},[a]),y=d.useMemo(()=>{const w=a.store.getState(),L={};for(const E of Object.values(p)){const I=F.selectOrganization(E.owner_organization||-1)(w);I&&(L[`${We}${I.id}`]=I.name);const M=F.selectUser(E.owner_user||-1)(w);M&&(L[`${je}${M.id}`]=M.username)}return Object.entries(L).map(([E,I])=>({itemContent:I,value:E}))},[p,a.store]),v=d.useCallback(w=>{s(w.currentTarget.value)},[]),b=(F.useAppSelector(F.selectNumberOfUserForms)||0)-f.length,C=f.length==e&&b>0?`Only the first ${e} results are shown (${b} hidden)`:b>0&&`${b} hidden forms`;return i.jsxs(o.Flex,{ref:n,direction:"column",gap:"2",children:[i.jsxs(o.Flex,{gap:"2",grow:"1",children:[i.jsx(o.Box,{grow:"1",asChild:!0,children:i.jsx(o.TextField.Root,{size:"3",children:i.jsx(o.TextField.Input,{placeholder:"Filter",value:r,onChange:v})})}),i.jsx(o.Select,{items:y,value:c,onValueChange:u,placeholder:"Owner",size:"large"})]}),f.length>0&&i.jsx(o.ButtonList.Root,{children:f.map(w=>i.jsx(Vt,{...t,form:w,handleToggleFavorite:()=>g(w)},w.offline_id))}),i.jsx(o.Box,{px:"3",children:i.jsx(o.Text,{size:"2",severity:"info",children:C})})]})})),Vt=l=>{var g;const{form:n,onSelectForm:e,isFavoriteEditable:t,handleToggleFavorite:r}=l,s=(g=F.useAppSelector(F.selectOrganization(n.owner_organization||-1)))==null?void 0:g.name,c=F.useAppSelector(F.selectUser(n.owner_user||-1)),u=F.useAppSelector(F.selectCurrentUser).id,a=!!c&&c.id===u,h=s??(a?"You":c==null?void 0:c.username)??"Unknown",f=d.useCallback(y=>{y.stopPropagation(),r()},[r]),p=i.jsx(o.ButtonList.Item,{onClick:()=>e(n),asChild:!0,children:i.jsxs(o.Flex,{justify:"between",gap:"2",py:"2",px:"3",...o.divButtonProps,children:[i.jsxs(o.Flex,{grow:"1",align:"center",gap:"2",children:[i.jsx(o.IconButton,{className:F.classNames(n.favorite?dt.favoriteIcon:dt.regularIcon),variant:"ghost",onClick:f,"aria-label":n.favorite?"Favorite form":"Standard form",disabled:!t,children:n.favorite?i.jsx(o.StarFilledIcon,{}):i.jsx(o.StarIcon,{})}),i.jsx(o.Text,{noWrap:!0,children:n.latestRevision.title}),n.latestRevision.description&&i.jsx(o.QuestionMarkCircledIcon,{})]}),h&&i.jsxs(o.Flex,{align:"center",gap:"2",children:[i.jsx(o.PersonIcon,{})," ",h]})]})});return n.latestRevision.description?i.jsx(o.Tooltip,{content:n.latestRevision.description,children:p},n.offline_id):p},ct={submissionsContainer:"_submissionsContainer_9iirt_1",stopHorizontalOverflow:"_stopHorizontalOverflow_9iirt_6"},Bt=d.memo(function(n){var w;const{submission:e,onSubmissionClick:t,compact:r,labelType:s,rowDecorator:c}=n,u=F.useAppSelector(F.selectCurrentUser),a=F.useAppSelector(F.selectUser("created_by"in e?e.created_by:u.id)),h=Ue(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,y=F.useFileSrc({file:(a==null?void 0:a.profile.file)??null,fileSha1:(a==null?void 0:a.profile.file_sha1)??null}),v=(a==null?void 0:a.username.charAt(0).toUpperCase())??"?",z=p.revision===g,b=d.useCallback(()=>{t&&t({submission:e})},[e,t]),C=i.jsx(o.ButtonList.Item,{onClick:b,asChild:!0,children:i.jsxs(o.Flex,{grow:"1",width:"100%",p:"2",gap:"2",justify:"between",children:[i.jsxs(o.Flex,{gap:"2",align:"center",className:ct.stopHorizontalOverflow,children:[i.jsx(o.Avatar,{src:y,size:"1",fallback:v}),i.jsx(o.Text,{size:"2",noWrap:!0,children:s==="creator"?(a||u).username:p.title})]}),i.jsxs(o.Flex,{gap:"2",align:"center",children:[!r&&(p.revision?i.jsx(o.Badge,{variant:"soft",severity:z?"primary":"info",children:r?p.revision.toString():`Revision #${p.revision}`}):!!g&&i.jsx(o.Badge,{children:"Original"})),i.jsx(o.Text,{size:"2",noWrap:!0,children:f})]})]})});return c?c(e,C):C}),Ue=l=>{const n="created_at"in l?l.created_at:l.submitted_at;return new Date(n)},_t=d.memo(function(n){const{formId:e,submissions:t,compact:r=!1,className:s,after:c,variant:u="outline",...a}=n;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=d.useMemo(()=>h==null?void 0:h.sort((p,g)=>Ue(g).getTime()-Ue(p).getTime()),[h]);return i.jsx(o.ButtonList.Root,{className:F.classNames(ct.submissionsContainer,s),size:"small",variant:u,before:!r&&i.jsxs(o.Text,{severity:"info",children:["There are ",((h==null?void 0:h.length)||0).toString()," submissions of this form."]}),after:c,children:f==null?void 0:f.map((p,g)=>i.jsx(Bt,{submission:p,compact:r,...a},g))})}),Ot=d.memo(function(n){const{name:e,render:t}=n,{submitForm:r}=D.useFormikContext(),[s,c,u]=D.useField(e);return d.useMemo(()=>{const a=h=>u.setValue(h,!1);return t({value:s.value,setValue:a,patchValue:r})},[r,u,s.value,t])}),Nt=d.memo(d.forwardRef((l,n)=>{const{children:e,schema:t,values:r,onPatch:s,onError:c,...u}=l,a=d.useMemo(()=>He(t.fields,r),[t.fields,r]),h=d.useCallback(v=>{const z={};for(const b in v){const C=v[b];C!==a[b]&&C!==void 0&&(z[b]=C)}be(z)&&s(z)},[a,s]),f=d.useCallback(async v=>{const z=await at(t,v);return z&&c(z),z},[t,c]),p=D.useFormik({initialValues:a,onSubmit:h,validate:f,validateOnBlur:!1,validateOnChange:!1}),{errors:g,resetForm:y}=p;return d.useEffect(()=>{be(g)&&y({values:a,errors:{}})},[g,a,y]),i.jsx(D.FormikProvider,{value:p,children:i.jsx("form",{...u,ref:n,onSubmit:p.handleSubmit,children:e})})})),ut={...Be,section:G},qt=d.memo(function(n){const{field:e,setFieldType:t}=n,r=e.fieldTypeName,s=e.fieldTypeDescription,c=e.Icon;return i.jsxs(o.Flex,{gap:"4",align:"center",children:[i.jsx(o.Button,{type:"button",variant:"surface",onClick:t,style:{width:"135px"},children:i.jsxs(o.Flex,{gap:"3",align:"center",grow:"1",children:[i.jsx(c,{}),r]})}),i.jsx(o.Text,{children:s})]})}),ft=[["string","text"],["select","multi-select","upload"],["boolean","date","number","multi-string"]],Ht=ft.length-1,Wt=d.memo(function(n){const{setFieldType:e}=n;return i.jsx(o.Flex,{direction:"column",gap:"3",children:ft.map((t,r)=>i.jsxs(o.Flex,{direction:"column",gap:"3",children:[i.jsx(o.Flex,{direction:"column",gap:"2",children:t.map(s=>i.jsx(qt,{field:Be[s],setFieldType:()=>e(s)},s))}),r<Ht&&i.jsx(o.Separator,{size:"4"})]},r))})}),jt=l=>n=>{if(!(!n||typeof n!="string")&&l.includes(n.trim()))return"This name is already taken."},Ut=(l,n)=>{const e=[new J({label:"Label",required:!0,maxLength:200,identifier:"label",fieldValidators:[jt(l)]}),new k({label:"Description",required:!1,maxLength:1e3,identifier:"description"})];return n==="section"?e:[...e,new Z({label:"Required",description:null,required:!1,identifier:"required"})]},Gt=d.memo(function(n){const{fieldType:e,handleCancel:t,handleCreateField:r,defaultField:s,conditionalSourceFields:c}=n,u=ut[e],a=D.useFormikContext(),h=d.useMemo(()=>{const f=nt(a.values.fields).filter(g=>g!==(s==null?void 0:s.label));let p=Ut(f,e);if(u===G){if(c===void 0)throw new Error("Conditional source fields must be provided when changing sections.");p=p.concat(u.getFieldCreationSchema(c))}else{if(!(u.prototype instanceof V))throw new Error(`Field must be an instance of BaseField. Got ${u}.`);p=[...p,...u.getFieldCreationSchema()]}return{fields:p,meta:{readonly:!1},title:null}},[a.values.fields,e,u,s==null?void 0:s.label,c]);return i.jsx(Ce,{schema:h,values:s,onSubmit:r,cancelText:s?void 0:"Back",onCancel:t})}),he=d.memo(function(n){const{parentPath:e,index:t,children:r,initial:s,editing:c,conditionalSourceFields:u}=n,[a,h]=d.useState(),f=(s==null?void 0:s.type)??a,p=f?ut[f].fieldTypeName:void 0,{setFieldValue:g,values:y}=D.useFormikContext();if(c&&!s)throw new Error("Initial field must be provided if editing is true.");const v=!f&&!c&&!s,z=v?"Choose a field type":`${p} settings`,b=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=d.useCallback(()=>h(void 0),[]),w=d.useCallback(I=>{h(void 0),I()},[]),L=d.useCallback((I,M)=>{const{label:O}=I;if(!f)throw new Error("Field type must be selected before creating a field.");if(!O||typeof O!="string")throw new Error("Label must be provided before creating a field.");const ae=fe({type:f,...I,identifier:tt(I.identifier,O)}).serialize(),K=X(y,e);if(K===void 0)throw new Error("Parent path must point to an existing field.");let Y;if(!Array.isArray(K))throw new Error("Parent path must point to an array.");c?Y=bt(K,t,ae):Y=et(K,t,ae),g(e,Y).then(),M()},[c,f,y,e,g,t]),E=d.useCallback(I=>v?i.jsx(Wt,{setFieldType:h}):i.jsx(Gt,{conditionalSourceFields:u,handleCancel:C,handleCreateField:M=>L(M,I),fieldType:f,defaultField:s}),[u,C,L,s,v,f]);return i.jsx(o.Dialog,{onCloseInterrupt:w,title:z,description:b,content:E,children:r})}),pt=({children:l})=>i.jsx(i.Fragment,{children:l}),ht=(l,n)=>({initial:l?n:"none",sm:l?"none":n}),mt=d.memo(function(n){const{remove:e,dragHandleProps:t,editProps:r,insertAfterProps:s,duplicateProps:c}=n,u=d.useMemo(()=>[{Wrapper:he,wrapperProps:r,Icon:o.Pencil1Icon,text:"Edit"},{Icon:o.TrashIcon,buttonProps:{onClick:e},text:"Delete"},{Wrapper:he,wrapperProps:c,Icon:o.CopyIcon,text:"Duplicate"},{Wrapper:he,wrapperProps:s,Icon:o.PlusIcon,text:"Add after"},{Icon:a=>i.jsx("div",{...a,children:i.jsx(o.DragHandleDots2Icon,{})}),text:"Reorder",disableOnMobile:!0,buttonProps:{...t,asChild:!0}}],[t,c,r,s,e]);return i.jsxs(i.Fragment,{children:[i.jsx(o.Flex,{gap:"4",display:ht(!1,"flex"),children:u.map(a=>{const h=a.Wrapper??pt;return i.jsx(h,{...a.wrapperProps,children:i.jsx(o.IconButton,{type:"button",variant:"ghost","aria-label":a.text,...a.buttonProps,children:i.jsx(a.Icon,{})})},a.text)})}),i.jsx(o.Box,{display:ht(!0,"block"),children:i.jsx(o.DropdownMenu,{trigger:i.jsx(o.IconButton,{variant:"ghost","aria-label":"Actions menu",children:i.jsx(o.DotsVerticalIcon,{})}),closeOnSelect:!1,items:u.map(a=>{var f;if(a.disableOnMobile)return null;const h=a.Wrapper??pt;return{...a.buttonProps,onSelect:(f=a.buttonProps)==null?void 0:f.onClick,content:i.jsx(h,{...a.wrapperProps,children:i.jsxs(o.Flex,{gap:"2",align:"center",children:[i.jsx(a.Icon,{}),a.text]})})}}).filter(a=>a!==null)})})]})}),Te="form-builder",Kt=d.memo(function(n){const{field:e,index:t,sectionIndex:r,takenLabels:s,remove:c}=n,u=d.useMemo(()=>fe(e),[e]),a=pe(u,{formId:Te,disabled:!0}),h=d.useCallback(y=>{if(y.label===null)throw new Error(`Expected a label for field ${y.identifier}`);return{...y,label:De(y.label,s),identifier:""}},[s]),f=d.useMemo(()=>({index:t,parentPath:`fields.${r}.fields`,initial:e,editing:!0}),[e,t,r]),p=d.useMemo(()=>({parentPath:`fields.${r}.fields`,index:t+1,initial:h(e)}),[h,e,t,r]),g=d.useMemo(()=>({parentPath:`fields.${r}.fields`,index:t+1,initial:void 0}),[t,r]);return i.jsx(j.Draggable,{draggableId:e.identifier,index:t,children:y=>i.jsx(o.Card,{ref:y.innerRef,...y.draggableProps,...y.dragHandleProps,id:`${e.identifier}-card`,mb:"4",children:i.jsxs(o.Flex,{gap:"4",justify:"between",align:"center",children:[a,i.jsx(mt,{remove:c,editProps:f,duplicateProps:p,insertAfterProps:g,dragHandleProps:y.dragHandleProps})]})})})}),Yt=d.memo(function(n){var Y,A,N,Q,Se,ze,Ae,xt,vt;const{field:e,index:t,dropState:r,conditionalFieldCounts:s}=n,c=(Y=r[e.identifier])==null?void 0:Y.disabled,u=F.useAppSelector(F.selectAppearance),{setFieldValue:a,values:h}=D.useFormikContext(),f=o.useAlertDialog(),p=nt(h.fields),g=d.useCallback((T,S)=>{for(const $ of T){const P=S.indexOf($);a(`fields.${P}.condition`,null).then(),a(`fields.${P}.conditional`,!1).then()}},[a]),y=d.useCallback(T=>{var P;const S=e.fields[T];if(!S)throw new Error("Could not find field to remove.");const $=[];for(const B of h.fields)((P=B.condition)==null?void 0:P.identifier)===S.identifier&&$.push(B);return{removing:S,affectedSections:$,action:()=>a(`fields.${t}.fields`,ve(e.fields,T))}},[e.fields,h.fields,a,t]),v=d.useCallback(T=>{const{affectedSections:S,action:$,removing:P}=y(T),B=()=>{$().then(),g(S,h.fields)};if(S.length>0){const Ge=S.map(Ee=>Ee.label).join(", ");return f({title:"Remove condition?",description:`${P.label} is being used as a condition, deleting it will remove the condition from the ${Ge} section(s).`,severity:"danger",actionText:"Remove",onAction:B})}B()},[y,g,h.fields,f]),z=d.useCallback(()=>{const S=e.fields.map((Me,ri)=>y(ri)).flatMap(Me=>Me.affectedSections),$=S.length?"Remove fields and conditions?":"Remove fields?",P=e.fields.length,B=S.map(Me=>Me.label).join(", "),Ge=S.length?`Deleting this section will remove the ${P} field(s) it contains and will remove the conditions from following sections: ${B}`:`Deleting this section will remove the ${P} field(s) it contains.`,Ee=ve(h.fields,t),wt=()=>a("fields",Ee);if(S.length>0)return f({title:$,description:Ge,severity:"danger",actionText:"Remove",onAction:()=>{wt().then(()=>{g(S,Ee)})}});wt().then()},[e.fields,h.fields,t,y,a,f,g]),b=d.useCallback(T=>{if(T.label===null)throw new Error(`Expected a label for field ${T.identifier}`);const S=De(T.label,p),$=T.fields.map(P=>{const B=De(P.label,p);return{...P,label:B,identifier:tt(void 0,B)}});return{...T,label:S,fields:$,identifier:""}},[p]),C=d.useMemo(()=>({index:t,parentPath:"fields",initial:e,editing:!0,conditionalSourceFields:we(h.fields,t)}),[e,t,h.fields]),w=d.useMemo(()=>({index:t+1,parentPath:"fields",initial:xe(),conditionalSourceFields:we(h.fields,t+1)}),[t,h.fields]),L=d.useMemo(()=>({parentPath:`fields.${t}.fields`,index:e.fields.length,initial:void 0}),[e.fields.length,t]),E=d.useMemo(()=>({index:t+1,parentPath:"fields",initial:b(e),conditionalSourceFields:we(h.fields,t+1)}),[b,e,t,h.fields]),I=d.useMemo(()=>{var T,S;return(S=it(h.fields,(T=e.condition)==null?void 0:T.identifier))==null?void 0:S.label},[(A=e.condition)==null?void 0:A.identifier,h.fields]),M=Array.isArray((N=e.condition)==null?void 0:N.value)?"contains all of":"equals";if(Ie((Q=e.condition)==null?void 0:Q.value))throw new Error("File values are not supported for conditions.");const O=Array.isArray((Se=e.condition)==null?void 0:Se.value)?(Ae=(ze=e.condition)==null?void 0:ze.value)==null?void 0:Ae.map(T=>typeof T=="string"?T:T.label).join(", "):(vt=(xt=e.condition)==null?void 0:xt.value)==null?void 0:vt.toString(),ae=()=>{const S=s.filter(B=>B!==null).length,$=s[t]??0,P=6/S*$;return i.jsx("div",{id:`${e.identifier}-floating-point`,style:{width:`${6-P}%`,marginRight:`${P}%`}})},K=()=>{if(!e.condition)return null;const T=u==="light"?"black":"white";return i.jsxs(i.Fragment,{children:[i.jsx(Ke,{start:`${e.identifier}-card`,end:`${e.identifier}-floating-point`,startAnchor:"left",endAnchor:"right",color:T,strokeWidth:2,path:"straight",showHead:!1}),i.jsx(Ke,{start:`${e.identifier}-floating-point`,end:`${e.condition.identifier}-card`,startAnchor:"right",endAnchor:"left",color:T,strokeWidth:2,path:"grid",gridBreak:"0"})]})};return i.jsx(j.Draggable,{draggableId:e.identifier,index:t,children:T=>i.jsxs(o.Flex,{ref:T.innerRef,...T.draggableProps,...T.dragHandleProps,direction:"row",justify:"center",align:"center",mb:"4",children:[s.some(S=>S!==null)&&ae(),e.condition&&K(),i.jsx(o.Card,{id:`${e.identifier}-card`,style:{flexGrow:"1"},children:i.jsxs(o.Flex,{gap:"3",justify:"between",align:"center",children:[i.jsxs(o.Flex,{direction:"column",gap:"2",grow:"1",children:[i.jsxs(o.Flex,{direction:"column",children:[i.jsx(o.Heading,{as:"h3",size:"3",children:e.label}),i.jsx(o.Text,{className:me.description,children:e.description})]}),e.condition&&i.jsx(o.Text,{size:"1",children:i.jsxs(o.Em,{children:["Display only if ",i.jsx(o.Strong,{children:I})," ",M," ",i.jsx(o.Strong,{children:O})]})}),i.jsx(j.Droppable,{droppableId:e.identifier,type:"SECTION",isDropDisabled:c,children:S=>i.jsxs(o.Flex,{ref:S.innerRef,...S.droppableProps,direction:"column",gap:"0",children:[e.fields.map(($,P)=>i.jsx(Kt,{field:$,index:P,sectionIndex:t,remove:()=>v(P),takenLabels:p},$.identifier)),S.placeholder,i.jsx(he,{...L,children:i.jsxs(o.Button,{type:"button",variant:"outline",children:[i.jsx(o.PlusIcon,{})," Add a field"]})})]})})]}),i.jsx(mt,{remove:z,insertAfterProps:w,dragHandleProps:T.dragHandleProps,editProps:C,duplicateProps:E})]})})]})})}),Zt=(l,n)=>{var t;const e={...l};switch(n.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(n.fieldId)&&(e[r].disabled=!0);return e;case"update":return n.state}},Qt=(l,n)=>{if(n)for(let e=0;e<l.length;e++){const t=l[e];if(t){for(const r of t.fields)if(r.identifier===n)return e}}},gt=l=>{var e,t,r;const n={};for(let s=0;s<l.length;s++){const c=l[s];if(!c)throw new Error("Field is undefined.");const u=s>0?(e=n[l[s-1].identifier])==null?void 0:e.conditionFields:void 0,a=new Set(u);(t=c.condition)!=null&&t.identifier&&a.add(c.condition.identifier),n[c.identifier]={disabled:!1,conditionFields:a,conditionIndex:Qt(l,(r=c.condition)==null?void 0:r.identifier),index:s,label:c.label}}return n},yt=(l,n)=>{for(const[e,t]of Object.entries(l))if(t.identifier===n)return[t,e]},Xt=d.memo(function(){const{values:n,setFieldValue:e}=D.useFormikContext(),[t,r]=d.useReducer(Zt,n.fields,gt),{showInfo:s}=o.useToast();d.useEffect(()=>{r({type:"update",state:gt(n.fields)})},[r,n.fields]);const c=d.useCallback(f=>{f.type==="SECTION"&&r({type:"hold",fieldId:f.draggableId})},[]),u=d.useCallback(f=>{const{source:p,destination:g,type:y,reason:v,draggableId:z}=f;if(r({type:"release"}),!g||v==="CANCEL")return;if(y==="ROOT"){const E=t[z];if(!E)throw new Error("Could not find section context.");let I=typeof E.conditionIndex<"u"?Math.max(E.conditionIndex+1,g.index):g.index;for(const M of Object.values(t))M.conditionIndex===p.index&&(I=Math.min(I,M.index-1));return I!=g.index&&s({title:"Reordered sections",description:"Sections with conditions must be below the fields they reference."}),e("fields",Le(n.fields,p.index,I))}if(y!=="SECTION")throw new Error("Unexpected droppable type.");const[b,C]=yt(n.fields,p.droppableId)??[],[w,L]=yt(n.fields,g.droppableId)??[];if(!(b!=null&&b.fields)||!w)throw new Error("Could not find section with fields.");if(b.identifier===w.identifier)e(`fields.${C}.fields`,Le(b.fields,p.index,g.index)).then();else{const E=b.fields[p.index];if(!E)throw new Error("Could not find field to reorder.");e(`fields.${C}.fields`,ve(b.fields,p.index)).then(),e(`fields.${L}.fields`,et(w.fields,g.index,E)).then()}},[n.fields,e,t,s]),a=d.useMemo(()=>({index:n.fields.length,parentPath:"fields",initial:xe(),conditionalSourceFields:we(n.fields,n.fields.length)}),[n.fields]),h=()=>{let f=1;return n.fields.map(p=>p.conditional?f++:null)};return i.jsx(j.DragDropContext,{onDragStart:c,onDragEnd:u,children:i.jsx(j.Droppable,{droppableId:"droppable",type:"ROOT",children:f=>i.jsxs(o.Flex,{ref:f.innerRef,...f.droppableProps,direction:"column",gap:"0",children:[n.fields.map((p,g)=>i.jsx(Yt,{field:p,index:g,dropState:t,conditionalFieldCounts:h()},p.label)),f.placeholder,i.jsx(he,{...a,children:i.jsxs(o.Button,{type:"button",variant:"outline",children:[i.jsx(o.PlusIcon,{})," Add a section"]})})]})})})}),Jt={title:"",description:"",fields:[]},kt=new J({label:"Title",minLength:0,maxLength:100,required:!0,identifier:"title"}),Rt={formId:Te,placeholder:"Give your form a title."},ei=new k({label:"Description",minLength:0,maxLength:1e3,required:!1,identifier:"description"}),ti={formId:Te,placeholder:"Explain the purpose of this form."},ii=()=>{alert("This is a form preview, your data will not be saved.")},ni=d.memo(d.forwardRef((l,n)=>{const{onCancel:e,onSave:t,revision:r}=l,s=r?"Edit form":"Create a new form",{heading:c=s}=l,u=d.useCallback(y=>{const v={};if(y.title||(v.title="Title is required."),(!y.fields||y.fields.length===0)&&(v.fields="At least one field is required."),be(v))return v},[]),a=D.useFormik({initialValues:It(r)??Jt,validate:u,onSubmit:y=>t(y),validateOnChange:!1,validateOnBlur:!1}),h=d.useMemo(()=>Oe(a.values),[a.values]),f=pe(kt,Rt),p=pe(ei,ti),g=d.useMemo(()=>typeof c=="object"?c:i.jsx(o.Heading,{children:c}),[c]);return i.jsx(o.Tabs.Root,{ref:n,defaultValue:"edit",children:i.jsxs(o.Flex,{direction:"column",gap:"2",children:[i.jsxs(o.Tabs.List,{children:[i.jsx(o.Tabs.Trigger,{value:"edit",children:"Edit"}),i.jsx(o.Tabs.Trigger,{value:"preview",children:"Preview"})]}),i.jsxs(o.Tabs.Content,{value:"edit",children:[g,i.jsxs(o.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"," ",i.jsx("em",{children:"Preview"})," tab, but"," ",i.jsx("strong",{children:"field values entered on this page will not be saved."})]}),i.jsx(o.Flex,{asChild:!0,direction:"column",gap:"2",mt:"3",children:i.jsxs("form",{id:Te,onSubmit:a.handleSubmit,children:[i.jsxs(D.FormikProvider,{value:a,children:[f,p,i.jsx(Xt,{}),i.jsx(o.Text,{severity:"danger",size:"1",children:typeof a.errors.fields=="string"&&a.errors.fields})]}),i.jsxs(o.Flex,{justify:"end",gap:"2",children:[i.jsx(o.Button,{type:"button",variant:"soft",onClick:e,children:"Cancel"}),i.jsx(o.Button,{type:"submit",disabled:!a.isValid,children:"Save"})]})]})})]}),i.jsx(o.Tabs.Content,{value:"preview",children:i.jsx(Ce,{schema:h,onSubmit:ii})})]})})}));x.BooleanField=Z,x.BooleanInput=Ze,x.DateField=ge,x.DateInput=Xe,x.FieldSection=G,x.FormBrowser=$t,x.FormBuilder=ni,x.FormRenderer=Ce,x.FormSubmissionBrowser=_t,x.FormSubmissionViewer=Dt,x.MultiSelectField=ue,x.MultiSelectInput=st,x.MultiStringField=de,x.MultiStringInput=rt,x.NumberField=U,x.NumberInput=Qe,x.PatchField=Ot,x.PatchFormProvider=Nt,x.SelectField=ce,x.SelectInput=Re,x.StringField=J,x.StringInput=Je,x.TextField=k,x.TextInput=ke,x.deserialize=fe,x.deserializeField=_e,x.formRevisionToSchema=Oe,x.isConditionMet=Ne,x.useFieldInput=pe,x.useFieldInputs=qe,x.valueIsFile=Ie,Object.defineProperty(x,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.4-conditional-arrows-2.
|
|
6
|
+
"version": "1.0.4-conditional-arrows-2.8",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"main": "dist/forms.umd.cjs",
|
|
9
9
|
"module": "dist/forms.js",
|