@overmap-ai/forms 1.0.4-conditional-arrows-2.14 → 1.0.4-conditional-arrows-2.15
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 +113 -115
- package/dist/forms.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/forms.js
CHANGED
|
@@ -2,9 +2,9 @@ var Wt = Object.defineProperty;
|
|
|
2
2
|
var jt = (s, i, e) => i in s ? Wt(s, i, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[i] = e;
|
|
3
3
|
var m = (s, i, e) => (jt(s, typeof i != "symbol" ? i + "" : i, e), e);
|
|
4
4
|
import { jsx as r, jsxs as b, Fragment as bt } from "react/jsx-runtime";
|
|
5
|
-
import { Flex as y, Text as $, useSeverityColor as fe, Checkbox as Ht, CheckCircledIcon as Ut, TextField as ce, FontFamilyIcon as Gt, CalendarIcon as Kt, InputIcon as
|
|
5
|
+
import { Flex as y, Text as $, useSeverityColor as fe, Checkbox as Ht, CheckCircledIcon as Ut, TextField as ce, FontFamilyIcon as Gt, CalendarIcon as Kt, InputIcon as Yt, TextArea as Zt, RowsIcon as Xt, Select as yt, Box as pe, IconButton as ge, PlusIcon as Me, Badge as Ue, Cross1Icon as vt, ListBulletIcon as Qt, DropdownMenuIcon as Jt, MultiSelect as ei, CheckboxIcon as ti, Card as ve, Heading as Oe, Button as G, UploadIcon as wt, ButtonList as Ne, divButtonProps as ii, StarFilledIcon as ni, StarIcon as ri, QuestionMarkCircledIcon as oi, PersonIcon as si, Tooltip as li, Avatar as ai, Separator as ci, Dialog as di, Pencil1Icon as ui, TrashIcon as fi, CopyIcon as mi, DropdownMenu as hi, DotsVerticalIcon as pi, useAlertDialog as gi, Em as bi, Strong as ut, useToast as yi, Tabs as J } from "@overmap-ai/blocks";
|
|
6
6
|
import { useField as Je, useFormikContext as me, useFormik as et, FormikProvider as tt } from "formik";
|
|
7
|
-
import vi, { useMemo as x, memo as
|
|
7
|
+
import vi, { useMemo as x, memo as S, useCallback as F, useState as Z, useEffect as we, useRef as wi, forwardRef as xe, useReducer as xi } from "react";
|
|
8
8
|
import { DragDropContext as xt, Droppable as it, Draggable as nt } from "@hello-pangea/dnd";
|
|
9
9
|
import { slugify as Ii, useAppSelector as M, selectFormRevision as It, useSDK as Ct, selectSubmissionAttachments as Ci, selectFilteredUserForms as Fi, selectUserFormMapping as Ti, selectOrganization as Ft, selectUser as rt, selectNumberOfUserForms as Si, selectCurrentUser as Tt, classNames as St, isToday as Ei, getLocalDateString as zi, selectLatestFormRevision as Ai, useFileSrc as Li, selectSubmissionsForForm as Pi } from "@overmap-ai/core";
|
|
10
10
|
import de from "lodash.get";
|
|
@@ -129,7 +129,7 @@ const ki = "_description_17zed_1", Re = {
|
|
|
129
129
|
},
|
|
130
130
|
{ ...n, "aria-labelledby": h }
|
|
131
131
|
];
|
|
132
|
-
}, $i = [!0, "true"], Vi =
|
|
132
|
+
}, $i = [!0, "true"], Vi = S(function(i) {
|
|
133
133
|
const [{ inputId: e, labelId: t, severity: n, helpText: o, label: a, fieldProps: c }, l] = H(i), f = fe(n), d = $i.includes(c.value);
|
|
134
134
|
return /* @__PURE__ */ r(j, { helpText: o, severity: n, children: /* @__PURE__ */ r(
|
|
135
135
|
W,
|
|
@@ -181,7 +181,7 @@ const ki = "_description_17zed_1", Re = {
|
|
|
181
181
|
};
|
|
182
182
|
m(ee, "fieldTypeName", "Checkbox"), m(ee, "fieldTypeDescription", "Perfect for both optional and required yes/no questions."), m(ee, "Icon", Ut);
|
|
183
183
|
let ue = ee;
|
|
184
|
-
const Di =
|
|
184
|
+
const Di = S(function(i) {
|
|
185
185
|
const [{ inputId: e, labelId: t, severity: n, helpText: o, label: a, fieldProps: c, field: l }, f] = H(i), d = fe(n);
|
|
186
186
|
return /* @__PURE__ */ r(j, { helpText: o, severity: n, children: /* @__PURE__ */ r(W, { severity: n, inputId: e, labelId: t, label: a, children: /* @__PURE__ */ r(
|
|
187
187
|
ce.Input,
|
|
@@ -272,7 +272,7 @@ const Di = E(function(i) {
|
|
|
272
272
|
};
|
|
273
273
|
m(B, "fieldTypeName", "Number"), m(B, "fieldTypeDescription", "Allows specifying a number within a given range."), m(B, "Icon", Gt), 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 X = B;
|
|
275
|
-
const _i =
|
|
275
|
+
const _i = S(function(i) {
|
|
276
276
|
const [{ inputId: e, labelId: t, severity: n, helpText: o, label: a, fieldProps: c }, l] = H(i), f = fe(n), d = c.value ? c.value.split("T")[0] : "";
|
|
277
277
|
return /* @__PURE__ */ r(j, { helpText: o, severity: n, children: /* @__PURE__ */ r(W, { severity: n, inputId: e, labelId: t, label: a, children: /* @__PURE__ */ r(ce.Input, { ...l, ...c, type: "date", id: e, color: f, value: d }) }) });
|
|
278
278
|
}), te = class te extends O {
|
|
@@ -366,7 +366,7 @@ m(ze, "_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 Mi =
|
|
369
|
+
const Mi = S(function(i) {
|
|
370
370
|
const [{ inputId: e, labelId: t, severity: n, helpText: o, label: a, fieldProps: c, field: l }, f] = H(i), d = fe(n);
|
|
371
371
|
return /* @__PURE__ */ r(j, { helpText: o, severity: n, children: /* @__PURE__ */ r(W, { severity: n, inputId: e, labelId: t, label: a, children: /* @__PURE__ */ r(ce.Input, { ...f, ...c, type: l.inputType, id: e, color: d }) }) });
|
|
372
372
|
}), ie = class ie extends ze {
|
|
@@ -389,11 +389,11 @@ const Mi = E(function(i) {
|
|
|
389
389
|
return /* @__PURE__ */ r(Mi, { field: this, ...e });
|
|
390
390
|
}
|
|
391
391
|
};
|
|
392
|
-
m(ie, "fieldTypeName", "Short Text"), m(ie, "fieldTypeDescription", "Short text fields can hold up to 500 characters on a single line."), m(ie, "Icon",
|
|
392
|
+
m(ie, "fieldTypeName", "Short Text"), m(ie, "fieldTypeDescription", "Short text fields can hold up to 500 characters on a single line."), m(ie, "Icon", Yt);
|
|
393
393
|
let be = ie;
|
|
394
|
-
const Oi =
|
|
394
|
+
const Oi = S(function(i) {
|
|
395
395
|
const [{ inputId: e, labelId: t, severity: n, helpText: o, label: a, fieldProps: c }, l] = H(i);
|
|
396
|
-
return /* @__PURE__ */ r(j, { helpText: o, severity: n, children: /* @__PURE__ */ r(W, { severity: n, inputId: e, labelId: t, label: a, children: /* @__PURE__ */ r(
|
|
396
|
+
return /* @__PURE__ */ r(j, { helpText: o, severity: n, children: /* @__PURE__ */ r(W, { severity: n, inputId: e, labelId: t, label: a, children: /* @__PURE__ */ r(Zt, { ...l, ...c, resize: "vertical", id: e, severity: n }) }) });
|
|
397
397
|
}), ne = class ne extends ze {
|
|
398
398
|
constructor(i) {
|
|
399
399
|
const e = i.maxLength ? Math.min(5e3, i.maxLength) : 5e3, t = i.minLength ? Math.min(i.minLength, e) : void 0;
|
|
@@ -414,7 +414,7 @@ const Oi = E(function(i) {
|
|
|
414
414
|
};
|
|
415
415
|
m(ne, "fieldTypeName", "Paragraph"), m(ne, "fieldTypeDescription", "Paragraph fields can hold up to 5000 characters and can have multiple lines."), m(ne, "Icon", Xt);
|
|
416
416
|
let ye = ne;
|
|
417
|
-
const Ni =
|
|
417
|
+
const Ni = S(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, h = x(
|
|
419
419
|
() => l.options.map((g) => ({ value: g.value, itemContent: g.label })),
|
|
420
420
|
[l.options]
|
|
@@ -489,20 +489,20 @@ const At = (s, i) => {
|
|
|
489
489
|
return null;
|
|
490
490
|
}, Ee = (s, i) => s.filter((e, t) => t < i).flatMap((e) => e.fields), Pt = (s) => s.flatMap(
|
|
491
491
|
(i) => i.type === "section" ? [...i.fields.map((e) => e.label), i.label] : i.label
|
|
492
|
-
).filter((i) => i !== null),
|
|
492
|
+
).filter((i) => i !== null), Ye = (s, i) => {
|
|
493
493
|
let e = 1, t = `${s} (${e})`;
|
|
494
494
|
for (; i.includes(t); )
|
|
495
495
|
t = `${s} (${++e})`;
|
|
496
496
|
return t;
|
|
497
|
-
}, qi =
|
|
498
|
-
const [{ inputId: e, labelId: t, severity: n, helpText: o, label: a, fieldProps: c }, l] = H(i), f = fe(n), d = x(() => Array.isArray(c.value) ? c.value : [], [c.value]), { onChange: u, onBlur: h } = c, p = `${e}-droppable`, { disabled: g } = l, [T, I] =
|
|
499
|
-
(
|
|
500
|
-
u(
|
|
497
|
+
}, qi = S(function(i) {
|
|
498
|
+
const [{ inputId: e, labelId: t, severity: n, helpText: o, label: a, fieldProps: c }, l] = H(i), f = fe(n), d = x(() => Array.isArray(c.value) ? c.value : [], [c.value]), { onChange: u, onBlur: h } = c, p = `${e}-droppable`, { disabled: g } = l, [T, I] = Z(""), [C, v] = Z(""), V = C || o, L = C ? "red" : f, w = F(
|
|
499
|
+
(A) => {
|
|
500
|
+
u(A), h(A);
|
|
501
501
|
},
|
|
502
502
|
[u, h]
|
|
503
503
|
), P = F(
|
|
504
|
-
(
|
|
505
|
-
d.findIndex((R) => R.value ===
|
|
504
|
+
(A) => {
|
|
505
|
+
d.findIndex((R) => R.value === A.target.value.trim()) >= 0 ? v("All options must be unique") : A.target.value ? v("") : v("Option cannot be empty"), I(A.target.value);
|
|
506
506
|
},
|
|
507
507
|
[I, d]
|
|
508
508
|
), N = F(() => {
|
|
@@ -510,23 +510,23 @@ const At = (s, i) => {
|
|
|
510
510
|
return;
|
|
511
511
|
if (!T.trim())
|
|
512
512
|
return v("Option cannot be empty");
|
|
513
|
-
const
|
|
514
|
-
w([...d, { value:
|
|
515
|
-
}, [T, C, w, d]),
|
|
516
|
-
(
|
|
517
|
-
|
|
513
|
+
const A = T.trim();
|
|
514
|
+
w([...d, { value: A, label: A }]), I("");
|
|
515
|
+
}, [T, C, w, d]), K = F(
|
|
516
|
+
(A) => {
|
|
517
|
+
A.key === "Enter" && (A.preventDefault(), N());
|
|
518
518
|
},
|
|
519
519
|
[N]
|
|
520
520
|
), q = F(
|
|
521
|
-
(
|
|
522
|
-
w(Le(d,
|
|
521
|
+
(A) => {
|
|
522
|
+
w(Le(d, A));
|
|
523
523
|
},
|
|
524
524
|
[d, w]
|
|
525
525
|
), U = F(
|
|
526
|
-
(
|
|
527
|
-
if (!
|
|
526
|
+
(A) => {
|
|
527
|
+
if (!A.destination)
|
|
528
528
|
return;
|
|
529
|
-
const R =
|
|
529
|
+
const R = A.source.index, Y = A.destination.index;
|
|
530
530
|
w(Ke(d, R, Y));
|
|
531
531
|
},
|
|
532
532
|
[w, d]
|
|
@@ -541,7 +541,7 @@ const At = (s, i) => {
|
|
|
541
541
|
...c,
|
|
542
542
|
value: T,
|
|
543
543
|
onChange: P,
|
|
544
|
-
onKeyDown:
|
|
544
|
+
onKeyDown: K,
|
|
545
545
|
id: e,
|
|
546
546
|
color: L,
|
|
547
547
|
onBlur: void 0
|
|
@@ -558,7 +558,7 @@ const At = (s, i) => {
|
|
|
558
558
|
}
|
|
559
559
|
)
|
|
560
560
|
] }) }) }),
|
|
561
|
-
/* @__PURE__ */ r(it, { droppableId: p, children: (
|
|
561
|
+
/* @__PURE__ */ r(it, { droppableId: p, children: (A) => /* @__PURE__ */ b(y, { ...A.droppableProps, ref: A.innerRef, direction: "column", children: [
|
|
562
562
|
d.map((R, Y) => /* @__PURE__ */ r(
|
|
563
563
|
nt,
|
|
564
564
|
{
|
|
@@ -597,7 +597,7 @@ const At = (s, i) => {
|
|
|
597
597
|
},
|
|
598
598
|
R.value
|
|
599
599
|
)),
|
|
600
|
-
|
|
600
|
+
A.placeholder
|
|
601
601
|
] }) })
|
|
602
602
|
] }) });
|
|
603
603
|
}), re = class re extends O {
|
|
@@ -692,7 +692,7 @@ const oe = class oe extends kt {
|
|
|
692
692
|
};
|
|
693
693
|
m(oe, "fieldTypeName", "Dropdown"), m(oe, "fieldTypeDescription", "Allows the user to select a single option from a list of options."), m(oe, "Icon", Jt);
|
|
694
694
|
let ke = oe;
|
|
695
|
-
const Wi = (s) => s ? Array.isArray(s) ? s : [s] : [], ji =
|
|
695
|
+
const Wi = (s) => s ? Array.isArray(s) ? s : [s] : [], ji = S(function(i) {
|
|
696
696
|
const [{ inputId: e, labelId: t, severity: n, helpText: o, label: a, fieldProps: c, field: l }, f] = H(i), { onChange: d, onBlur: u } = c, h = x(() => Wi(c.value), [c.value]), p = F(
|
|
697
697
|
(g) => {
|
|
698
698
|
d(g), u(g);
|
|
@@ -738,7 +738,7 @@ const Wi = (s) => s ? Array.isArray(s) ? s : [s] : [], ji = E(function(i) {
|
|
|
738
738
|
};
|
|
739
739
|
m(se, "fieldTypeName", "Multi-select"), m(se, "fieldTypeDescription", "Allows the user to select a multiple options from a list of options."), m(se, "Icon", ti);
|
|
740
740
|
let $e = se;
|
|
741
|
-
const Hi =
|
|
741
|
+
const Hi = S(function({ field: i, ...e }) {
|
|
742
742
|
const [{ value: t }] = Je(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 Ui extends Ve {
|
|
|
767
767
|
super(i, Hi);
|
|
768
768
|
}
|
|
769
769
|
}
|
|
770
|
-
const Gi =
|
|
770
|
+
const Gi = S(function(i) {
|
|
771
771
|
const { field: e, ...t } = i, { label: n, description: o, fields: a, condition: c } = e, { values: l, setFieldValue: f } = me(), d = c != null && c.identifier ? de(l, c.identifier) : void 0, u = x(() => Dt(c, d), [c, d]);
|
|
772
772
|
we(() => {
|
|
773
773
|
if (!u)
|
|
@@ -885,7 +885,7 @@ const Gi = E(function(i) {
|
|
|
885
885
|
};
|
|
886
886
|
m(le, "fieldTypeName", "Section"), m(le, "fieldTypeDescription", "Sections can be useful for grouping fields together. They can also be conditionally shown or hidden.");
|
|
887
887
|
let Q = le;
|
|
888
|
-
const Ki = "_previewImage_1ig84_1",
|
|
888
|
+
const Ki = "_previewImage_1ig84_1", Yi = {
|
|
889
889
|
previewImage: Ki
|
|
890
890
|
}, st = (s) => {
|
|
891
891
|
const i = ["byte", "kilobyte", "megabyte"];
|
|
@@ -893,7 +893,7 @@ const Ki = "_previewImage_1ig84_1", Zi = {
|
|
|
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
|
-
},
|
|
896
|
+
}, Zi = S(function(i) {
|
|
897
897
|
var L;
|
|
898
898
|
const [{ inputId: e, labelId: t, severity: n, helpText: o, label: a, fieldProps: c, field: l }, f] = H(i), { onChange: d } = c, u = fe(n), h = wi(null), { value: p } = c, g = x(() => o || (l.maxFileSize ? `Maximum file size: ${st(l.maxFileSize)}` : null), [l.maxFileSize, o]), T = F(() => {
|
|
899
899
|
var w;
|
|
@@ -939,8 +939,8 @@ const Ki = "_previewImage_1ig84_1", Zi = {
|
|
|
939
939
|
P
|
|
940
940
|
)) })
|
|
941
941
|
] });
|
|
942
|
-
}), Xi =
|
|
943
|
-
const [o, a] =
|
|
942
|
+
}), Xi = S(function({ file: i, field: e, onRemove: t, disabled: n }) {
|
|
943
|
+
const [o, a] = Z(null), c = x(() => o && e.getError([o]), [e, o]), { url: l, name: f, size: d } = x(() => {
|
|
944
944
|
let u = null, h, p;
|
|
945
945
|
return o != null && o.type.startsWith("image/") && (u = URL.createObjectURL(o)), o ? (h = o.name, p = st(o.size)) : (h = "Downloading...", p = "..."), { url: u, name: h, size: p };
|
|
946
946
|
}, [o]);
|
|
@@ -965,7 +965,7 @@ const Ki = "_previewImage_1ig84_1", Zi = {
|
|
|
965
965
|
c && /* @__PURE__ */ r($, { size: "1", severity: "danger", children: c })
|
|
966
966
|
] })
|
|
967
967
|
] }),
|
|
968
|
-
l && /* @__PURE__ */ r("img", { className:
|
|
968
|
+
l && /* @__PURE__ */ r("img", { className: Yi.previewImage, src: l, alt: f })
|
|
969
969
|
] }) });
|
|
970
970
|
}), mt = 50 * 1024 * 1024, ae = class ae extends O {
|
|
971
971
|
constructor(e) {
|
|
@@ -1056,11 +1056,11 @@ const Ki = "_previewImage_1ig84_1", Zi = {
|
|
|
1056
1056
|
return new ae(e);
|
|
1057
1057
|
}
|
|
1058
1058
|
getInput(e) {
|
|
1059
|
-
return /* @__PURE__ */ r(
|
|
1059
|
+
return /* @__PURE__ */ r(Zi, { field: this, ...e });
|
|
1060
1060
|
}
|
|
1061
1061
|
};
|
|
1062
1062
|
m(ae, "fieldTypeName", "Upload"), m(ae, "fieldTypeDescription", "Allows a file to be uploaded."), m(ae, "Icon", wt);
|
|
1063
|
-
let
|
|
1063
|
+
let Ze = ae;
|
|
1064
1064
|
const lt = {
|
|
1065
1065
|
date: Ge,
|
|
1066
1066
|
number: X,
|
|
@@ -1069,7 +1069,7 @@ const lt = {
|
|
|
1069
1069
|
string: be,
|
|
1070
1070
|
text: ye,
|
|
1071
1071
|
custom: Ve,
|
|
1072
|
-
upload:
|
|
1072
|
+
upload: Ze,
|
|
1073
1073
|
// TODO: Underscore
|
|
1074
1074
|
"multi-string": Pe,
|
|
1075
1075
|
"multi-select": $e
|
|
@@ -1126,7 +1126,7 @@ const De = (s, i) => x(() => !i || !s ? null : s.getInput(i), [s, i]), _t = (s,
|
|
|
1126
1126
|
return e;
|
|
1127
1127
|
}, Qi = [null, void 0], at = (s, i) => s.reduce((e, t) => t instanceof Q ? { ...e, ...at(t.fields, i) } : (Qi.includes(de(e, t.getId())) && ot(e, t.getId(), ""), e), i), Ji = () => {
|
|
1128
1128
|
throw new Error("onSubmit must be provided if form is not readonly.");
|
|
1129
|
-
}, ct =
|
|
1129
|
+
}, ct = S(
|
|
1130
1130
|
xe((s, i) => {
|
|
1131
1131
|
const {
|
|
1132
1132
|
schema: e,
|
|
@@ -1168,7 +1168,7 @@ const De = (s, i) => x(() => !i || !s ? null : s.getInput(i), [s, i]), _t = (s,
|
|
|
1168
1168
|
] })
|
|
1169
1169
|
] }) }) });
|
|
1170
1170
|
})
|
|
1171
|
-
), _n =
|
|
1171
|
+
), _n = S(
|
|
1172
1172
|
xe((s, i) => {
|
|
1173
1173
|
const { submission: e, showFormDescription: t = !1, showFormTitle: n = !0 } = s, o = M(It(e.form_revision)), { sdk: a } = Ct();
|
|
1174
1174
|
if (!o)
|
|
@@ -1201,9 +1201,9 @@ const De = (s, i) => x(() => !i || !s ? null : s.getInput(i), [s, i]), _t = (s,
|
|
|
1201
1201
|
), en = "_favoriteIcon_1bixi_1", tn = "_regularIcon_1bixi_9", ht = {
|
|
1202
1202
|
favoriteIcon: en,
|
|
1203
1203
|
regularIcon: tn
|
|
1204
|
-
}, je = "organization:", He = "user:", Mn =
|
|
1204
|
+
}, je = "organization:", He = "user:", Mn = S(
|
|
1205
1205
|
xe((s, i) => {
|
|
1206
|
-
const { maxResults: e = 20, ...t } = s, [n, o] =
|
|
1206
|
+
const { maxResults: e = 20, ...t } = s, [n, o] = Z(""), [a, c] = Z(""), { sdk: l } = Ct(), f = x(() => {
|
|
1207
1207
|
const v = { maxResults: e, searchTerm: n };
|
|
1208
1208
|
return a && (a.startsWith(je) ? v.owner_organization = parseInt(a.slice(je.length)) : a.startsWith(He) && (v.owner_user = parseInt(a.slice(He.length)))), v;
|
|
1209
1209
|
}, [n, e, a]), d = M(Fi(f)) ?? [], u = M(Ti), h = F(
|
|
@@ -1282,7 +1282,7 @@ const De = (s, i) => x(() => !i || !s ? null : s.getInput(i), [s, i]), _t = (s,
|
|
|
1282
1282
|
}, rn = "_submissionsContainer_9iirt_1", on = "_stopHorizontalOverflow_9iirt_6", Ot = {
|
|
1283
1283
|
submissionsContainer: rn,
|
|
1284
1284
|
stopHorizontalOverflow: on
|
|
1285
|
-
}, sn =
|
|
1285
|
+
}, sn = S(function(i) {
|
|
1286
1286
|
var v;
|
|
1287
1287
|
const { submission: e, onSubmissionClick: t, compact: n, labelType: o, rowDecorator: a } = i, c = M(Tt), l = M(rt("created_by" in e ? e.created_by : c.id)), f = Qe(e), d = Ei(f) ? f.toLocaleTimeString([], {
|
|
1288
1288
|
hour: "2-digit",
|
|
@@ -1309,7 +1309,7 @@ const De = (s, i) => x(() => !i || !s ? null : s.getInput(i), [s, i]), _t = (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
|
-
}, On =
|
|
1312
|
+
}, On = S(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]), _t = (s,
|
|
|
1350
1350
|
))
|
|
1351
1351
|
}
|
|
1352
1352
|
);
|
|
1353
|
-
}), Nn =
|
|
1353
|
+
}), Nn = S(function(i) {
|
|
1354
1354
|
const { name: e, render: t } = i, { submitForm: n } = me(), [o, a, c] = Je(e);
|
|
1355
1355
|
return x(() => {
|
|
1356
1356
|
const l = (f) => c.setValue(f, !1);
|
|
@@ -1360,7 +1360,7 @@ const De = (s, i) => x(() => !i || !s ? null : s.getInput(i), [s, i]), _t = (s,
|
|
|
1360
1360
|
patchValue: n
|
|
1361
1361
|
});
|
|
1362
1362
|
}, [n, c, o.value, t]);
|
|
1363
|
-
}), Rn =
|
|
1363
|
+
}), Rn = S(
|
|
1364
1364
|
xe((s, i) => {
|
|
1365
1365
|
const { children: e, schema: t, values: n, onPatch: o, onError: a, ...c } = s, l = x(() => at(t.fields, n), [t.fields, n]), f = F(
|
|
1366
1366
|
(g) => {
|
|
@@ -1393,7 +1393,7 @@ const De = (s, i) => x(() => !i || !s ? null : s.getInput(i), [s, i]), _t = (s,
|
|
|
1393
1393
|
), Nt = {
|
|
1394
1394
|
...lt,
|
|
1395
1395
|
section: Q
|
|
1396
|
-
}, ln =
|
|
1396
|
+
}, ln = S(function(i) {
|
|
1397
1397
|
const { field: e, setFieldType: t } = i, n = e.fieldTypeName, o = e.fieldTypeDescription, a = e.Icon;
|
|
1398
1398
|
return /* @__PURE__ */ b(y, { gap: "4", align: "center", children: [
|
|
1399
1399
|
/* @__PURE__ */ r(G, { type: "button", variant: "surface", onClick: t, style: { width: "135px" }, children: /* @__PURE__ */ b(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]), _t = (s,
|
|
|
1406
1406
|
["string", "text"],
|
|
1407
1407
|
["select", "multi-select", "upload"],
|
|
1408
1408
|
["boolean", "date", "number", "multi-string"]
|
|
1409
|
-
], an = Rt.length - 1, cn =
|
|
1409
|
+
], an = Rt.length - 1, cn = S(function(i) {
|
|
1410
1410
|
const { setFieldType: e } = i;
|
|
1411
1411
|
return /* @__PURE__ */ r(y, { direction: "column", gap: "3", children: Rt.map((t, n) => /* @__PURE__ */ b(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]), _t = (s,
|
|
|
1442
1442
|
...e,
|
|
1443
1443
|
new ue({ label: "Required", description: null, required: !1, identifier: "required" })
|
|
1444
1444
|
];
|
|
1445
|
-
}, fn =
|
|
1445
|
+
}, fn = S(function(i) {
|
|
1446
1446
|
const { fieldType: e, handleCancel: t, handleCreateField: n, defaultField: o, conditionalSourceFields: a } = i, c = Nt[e], l = me(), f = x(() => {
|
|
1447
1447
|
const d = Pt(l.values.fields).filter((h) => h !== (o == null ? void 0 : o.label));
|
|
1448
1448
|
let u = un(d, e);
|
|
@@ -1472,8 +1472,8 @@ const De = (s, i) => x(() => !i || !s ? null : s.getInput(i), [s, i]), _t = (s,
|
|
|
1472
1472
|
onCancel: t
|
|
1473
1473
|
}
|
|
1474
1474
|
);
|
|
1475
|
-
}), he =
|
|
1476
|
-
const { parentPath: e, index: t, children: n, initial: o, editing: a, conditionalSourceFields: c } = i, [l, f] =
|
|
1475
|
+
}), he = S(function(i) {
|
|
1476
|
+
const { parentPath: e, index: t, children: n, initial: o, editing: a, conditionalSourceFields: c } = i, [l, f] = Z(), d = (o == null ? void 0 : o.type) ?? l, u = d ? Nt[d].fieldTypeName : void 0, { setFieldValue: h, values: p } = me();
|
|
1477
1477
|
if (a && !o)
|
|
1478
1478
|
throw new Error("Initial field must be provided if editing is true.");
|
|
1479
1479
|
const g = !d && !a && !o, T = g ? "Choose a field type" : `${u} settings`, I = g ? "Select a field type to add to this section." : (u == null ? void 0 : u.toLowerCase()) === "section" ? "Customize your section" : `Customize your ${u == null ? void 0 : u.toLowerCase()} field.`, C = F(() => f(void 0), []), v = F((w) => {
|
|
@@ -1485,7 +1485,7 @@ const De = (s, i) => x(() => !i || !s ? null : s.getInput(i), [s, i]), _t = (s,
|
|
|
1485
1485
|
throw new Error("Field type must be selected before creating a field.");
|
|
1486
1486
|
if (!N || typeof N != "string")
|
|
1487
1487
|
throw new Error("Label must be provided before creating a field.");
|
|
1488
|
-
const
|
|
1488
|
+
const K = Be({
|
|
1489
1489
|
type: d,
|
|
1490
1490
|
...w,
|
|
1491
1491
|
identifier: At(w.identifier, N)
|
|
@@ -1495,7 +1495,7 @@ const De = (s, i) => x(() => !i || !s ? null : s.getInput(i), [s, i]), _t = (s,
|
|
|
1495
1495
|
let U;
|
|
1496
1496
|
if (!Array.isArray(q))
|
|
1497
1497
|
throw new Error("Parent path must point to an array.");
|
|
1498
|
-
a ? U = Bi(q, t,
|
|
1498
|
+
a ? U = Bi(q, t, K) : U = zt(q, t, K), h(e, U).then(), P();
|
|
1499
1499
|
},
|
|
1500
1500
|
[a, d, p, e, h, t]
|
|
1501
1501
|
), L = F(
|
|
@@ -1512,7 +1512,7 @@ const De = (s, i) => x(() => !i || !s ? null : s.getInput(i), [s, i]), _t = (s,
|
|
|
1512
1512
|
[c, C, V, o, g, d]
|
|
1513
1513
|
);
|
|
1514
1514
|
return /* @__PURE__ */ r(di, { onCloseInterrupt: v, title: T, description: I, content: L, children: n });
|
|
1515
|
-
}), mn = ({ children: s }) => /* @__PURE__ */ r(bt, { children: s }), Bt =
|
|
1515
|
+
}), mn = ({ children: s }) => /* @__PURE__ */ r(bt, { children: s }), Bt = S(function(i) {
|
|
1516
1516
|
const { remove: e, editProps: t, insertAfterProps: n, duplicateProps: o, type: a } = i, c = x(
|
|
1517
1517
|
() => [
|
|
1518
1518
|
{
|
|
@@ -1562,12 +1562,12 @@ const De = (s, i) => x(() => !i || !s ? null : s.getInput(i), [s, i]), _t = (s,
|
|
|
1562
1562
|
}).filter((l) => l !== null)
|
|
1563
1563
|
}
|
|
1564
1564
|
) });
|
|
1565
|
-
}), qe = "form-builder", hn =
|
|
1565
|
+
}), qe = "form-builder", hn = S(function(i) {
|
|
1566
1566
|
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 = F(
|
|
1567
1567
|
(p) => {
|
|
1568
1568
|
if (p.label === null)
|
|
1569
1569
|
throw new Error(`Expected a label for field ${p.identifier}`);
|
|
1570
|
-
return { ...p, label:
|
|
1570
|
+
return { ...p, label: Ye(p.label, o), identifier: "" };
|
|
1571
1571
|
},
|
|
1572
1572
|
[o]
|
|
1573
1573
|
), d = x(
|
|
@@ -1616,10 +1616,10 @@ const De = (s, i) => x(() => !i || !s ? null : s.getInput(i), [s, i]), _t = (s,
|
|
|
1616
1616
|
}
|
|
1617
1617
|
) });
|
|
1618
1618
|
}), pn = (s) => {
|
|
1619
|
-
const { identifier: i, condition: e } = s, t = { primary: "var(--gray-a4)", hover: "var(--primary-color)" }, [n, o] =
|
|
1620
|
-
o(t.hover)
|
|
1621
|
-
}, [t.hover]),
|
|
1622
|
-
o(t.primary)
|
|
1619
|
+
const { identifier: i, condition: e } = s, t = { primary: "var(--gray-a4)", hover: "var(--primary-color)" }, [n, o] = Z(t.primary), a = F(() => {
|
|
1620
|
+
o(t.hover);
|
|
1621
|
+
}, [t.hover]), c = F(() => {
|
|
1622
|
+
o(t.primary);
|
|
1623
1623
|
}, [t.primary]);
|
|
1624
1624
|
return e ? /* @__PURE__ */ b(bt, { children: [
|
|
1625
1625
|
/* @__PURE__ */ r(
|
|
@@ -1633,11 +1633,10 @@ const De = (s, i) => x(() => !i || !s ? null : s.getInput(i), [s, i]), _t = (s,
|
|
|
1633
1633
|
strokeWidth: 1,
|
|
1634
1634
|
path: "straight",
|
|
1635
1635
|
showHead: !1,
|
|
1636
|
-
zIndex: a,
|
|
1637
1636
|
arrowBodyProps: {
|
|
1638
1637
|
pointerEvents: "stroke",
|
|
1639
|
-
onMouseEnter:
|
|
1640
|
-
onMouseLeave:
|
|
1638
|
+
onMouseEnter: a,
|
|
1639
|
+
onMouseLeave: c
|
|
1641
1640
|
}
|
|
1642
1641
|
}
|
|
1643
1642
|
),
|
|
@@ -1653,48 +1652,47 @@ const De = (s, i) => x(() => !i || !s ? null : s.getInput(i), [s, i]), _t = (s,
|
|
|
1653
1652
|
path: "grid",
|
|
1654
1653
|
gridBreak: "0",
|
|
1655
1654
|
showHead: !1,
|
|
1656
|
-
zIndex: a,
|
|
1657
1655
|
arrowBodyProps: {
|
|
1658
1656
|
pointerEvents: "stroke",
|
|
1659
|
-
onMouseEnter:
|
|
1660
|
-
onMouseLeave:
|
|
1657
|
+
onMouseEnter: a,
|
|
1658
|
+
onMouseLeave: c
|
|
1661
1659
|
}
|
|
1662
1660
|
}
|
|
1663
1661
|
)
|
|
1664
1662
|
] }) : null;
|
|
1665
|
-
}, gn =
|
|
1666
|
-
var
|
|
1667
|
-
const { field: e, index: t, dropState: n, conditionalFieldCounts: o } = i, a = (
|
|
1668
|
-
(
|
|
1669
|
-
for (const D of
|
|
1670
|
-
const k =
|
|
1663
|
+
}, gn = S(function(i) {
|
|
1664
|
+
var K, q, U, A, R, Y, Ie, Ce, Fe;
|
|
1665
|
+
const { field: e, index: t, dropState: n, conditionalFieldCounts: o } = i, a = (K = n[e.identifier]) == null ? void 0 : K.disabled, { setFieldValue: c, values: l } = me(), f = gi(), d = Pt(l.fields), u = F(
|
|
1666
|
+
(E, z) => {
|
|
1667
|
+
for (const D of E) {
|
|
1668
|
+
const k = z.indexOf(D);
|
|
1671
1669
|
c(`fields.${k}.condition`, null).then(), c(`fields.${k}.conditional`, !1).then();
|
|
1672
1670
|
}
|
|
1673
1671
|
},
|
|
1674
1672
|
[c]
|
|
1675
1673
|
), h = F(
|
|
1676
|
-
(
|
|
1674
|
+
(E) => {
|
|
1677
1675
|
var k;
|
|
1678
|
-
const
|
|
1679
|
-
if (!
|
|
1676
|
+
const z = e.fields[E];
|
|
1677
|
+
if (!z)
|
|
1680
1678
|
throw new Error("Could not find field to remove.");
|
|
1681
1679
|
const D = [];
|
|
1682
1680
|
for (const _ of l.fields)
|
|
1683
|
-
((k = _.condition) == null ? void 0 : k.identifier) ===
|
|
1681
|
+
((k = _.condition) == null ? void 0 : k.identifier) === z.identifier && D.push(_);
|
|
1684
1682
|
return {
|
|
1685
|
-
removing:
|
|
1683
|
+
removing: z,
|
|
1686
1684
|
affectedSections: D,
|
|
1687
|
-
action: () => c(`fields.${t}.fields`, Le(e.fields,
|
|
1685
|
+
action: () => c(`fields.${t}.fields`, Le(e.fields, E))
|
|
1688
1686
|
};
|
|
1689
1687
|
},
|
|
1690
1688
|
[e.fields, l.fields, c, t]
|
|
1691
1689
|
), p = F(
|
|
1692
|
-
(
|
|
1693
|
-
const { affectedSections:
|
|
1694
|
-
D().then(), u(
|
|
1690
|
+
(E) => {
|
|
1691
|
+
const { affectedSections: z, action: D, removing: k } = h(E), _ = () => {
|
|
1692
|
+
D().then(), u(z, l.fields);
|
|
1695
1693
|
};
|
|
1696
|
-
if (
|
|
1697
|
-
const We =
|
|
1694
|
+
if (z.length > 0) {
|
|
1695
|
+
const We = z.map((Te) => Te.label).join(", ");
|
|
1698
1696
|
return f({
|
|
1699
1697
|
title: "Remove condition?",
|
|
1700
1698
|
description: `${k.label} is being used as a condition, deleting it will remove the condition from the ${We} section(s).`,
|
|
@@ -1707,8 +1705,8 @@ const De = (s, i) => x(() => !i || !s ? null : s.getInput(i), [s, i]), _t = (s,
|
|
|
1707
1705
|
},
|
|
1708
1706
|
[h, u, l.fields, f]
|
|
1709
1707
|
), g = F(() => {
|
|
1710
|
-
const
|
|
1711
|
-
if (
|
|
1708
|
+
const z = e.fields.map((Se, qt) => h(qt)).flatMap((Se) => Se.affectedSections), D = z.length ? "Remove fields and conditions?" : "Remove fields?", k = e.fields.length, _ = z.map((Se) => Se.label).join(", "), We = z.length ? `Deleting this section will remove the ${k} field(s) it contains and will remove the conditions from following sections: ${_}` : `Deleting this section will remove the ${k} field(s) it contains.`, Te = Le(l.fields, t), dt = () => c("fields", Te);
|
|
1709
|
+
if (z.length > 0)
|
|
1712
1710
|
return f({
|
|
1713
1711
|
title: D,
|
|
1714
1712
|
description: We,
|
|
@@ -1716,7 +1714,7 @@ const De = (s, i) => x(() => !i || !s ? null : s.getInput(i), [s, i]), _t = (s,
|
|
|
1716
1714
|
actionText: "Remove",
|
|
1717
1715
|
onAction: () => {
|
|
1718
1716
|
dt().then(() => {
|
|
1719
|
-
u(
|
|
1717
|
+
u(z, Te);
|
|
1720
1718
|
});
|
|
1721
1719
|
}
|
|
1722
1720
|
});
|
|
@@ -1730,18 +1728,18 @@ const De = (s, i) => x(() => !i || !s ? null : s.getInput(i), [s, i]), _t = (s,
|
|
|
1730
1728
|
f,
|
|
1731
1729
|
u
|
|
1732
1730
|
]), T = F(
|
|
1733
|
-
(
|
|
1734
|
-
if (
|
|
1735
|
-
throw new Error(`Expected a label for field ${
|
|
1736
|
-
const
|
|
1737
|
-
const _ =
|
|
1731
|
+
(E) => {
|
|
1732
|
+
if (E.label === null)
|
|
1733
|
+
throw new Error(`Expected a label for field ${E.identifier}`);
|
|
1734
|
+
const z = Ye(E.label, d), D = E.fields.map((k) => {
|
|
1735
|
+
const _ = Ye(k.label, d);
|
|
1738
1736
|
return {
|
|
1739
1737
|
...k,
|
|
1740
1738
|
label: _,
|
|
1741
1739
|
identifier: At(void 0, _)
|
|
1742
1740
|
};
|
|
1743
1741
|
});
|
|
1744
|
-
return { ...
|
|
1742
|
+
return { ...E, label: z, fields: D, identifier: "" };
|
|
1745
1743
|
},
|
|
1746
1744
|
[d]
|
|
1747
1745
|
), I = x(
|
|
@@ -1778,27 +1776,27 @@ const De = (s, i) => x(() => !i || !s ? null : s.getInput(i), [s, i]), _t = (s,
|
|
|
1778
1776
|
[T, e, t, l.fields]
|
|
1779
1777
|
), L = x(
|
|
1780
1778
|
() => {
|
|
1781
|
-
var
|
|
1782
|
-
return (
|
|
1779
|
+
var E, z;
|
|
1780
|
+
return (z = Lt(l.fields, (E = e.condition) == null ? void 0 : E.identifier)) == null ? void 0 : z.label;
|
|
1783
1781
|
},
|
|
1784
1782
|
[(q = e.condition) == null ? void 0 : q.identifier, l.fields]
|
|
1785
1783
|
), w = Array.isArray((U = e.condition) == null ? void 0 : U.value) ? "contains all of" : "equals";
|
|
1786
|
-
if (Xe((
|
|
1784
|
+
if (Xe((A = e.condition) == null ? void 0 : A.value))
|
|
1787
1785
|
throw new Error("File values are not supported for conditions.");
|
|
1788
|
-
const P = Array.isArray((R = e.condition) == null ? void 0 : R.value) ? (Ie = (Y = e.condition) == null ? void 0 : Y.value) == null ? void 0 : Ie.map((
|
|
1789
|
-
const
|
|
1786
|
+
const P = Array.isArray((R = e.condition) == null ? void 0 : R.value) ? (Ie = (Y = e.condition) == null ? void 0 : Y.value) == null ? void 0 : Ie.map((E) => typeof E == "string" ? E : E.label).join(", ") : (Fe = (Ce = e.condition) == null ? void 0 : Ce.value) == null ? void 0 : Fe.toString(), N = () => {
|
|
1787
|
+
const z = o.filter((_) => _ !== null).length, D = o[t] ?? 0, k = 3 / z * D;
|
|
1790
1788
|
return /* @__PURE__ */ r(
|
|
1791
1789
|
"div",
|
|
1792
1790
|
{
|
|
1793
1791
|
id: `${e.identifier}-floating-point`,
|
|
1794
1792
|
style: {
|
|
1795
|
-
width: `${
|
|
1793
|
+
width: `${3 - k}%`,
|
|
1796
1794
|
marginLeft: `${k}%`
|
|
1797
1795
|
}
|
|
1798
1796
|
}
|
|
1799
1797
|
);
|
|
1800
1798
|
};
|
|
1801
|
-
return /* @__PURE__ */
|
|
1799
|
+
return /* @__PURE__ */ b(
|
|
1802
1800
|
y,
|
|
1803
1801
|
{
|
|
1804
1802
|
direction: "row",
|
|
@@ -1806,12 +1804,12 @@ const De = (s, i) => x(() => !i || !s ? null : s.getInput(i), [s, i]), _t = (s,
|
|
|
1806
1804
|
align: "center",
|
|
1807
1805
|
mb: "4",
|
|
1808
1806
|
children: [
|
|
1809
|
-
/* @__PURE__ */ r(
|
|
1807
|
+
/* @__PURE__ */ r(nt, { draggableId: e.identifier, index: t, children: (E) => /* @__PURE__ */ r(
|
|
1810
1808
|
ve,
|
|
1811
1809
|
{
|
|
1812
|
-
ref:
|
|
1813
|
-
...
|
|
1814
|
-
...
|
|
1810
|
+
ref: E.innerRef,
|
|
1811
|
+
...E.draggableProps,
|
|
1812
|
+
...E.dragHandleProps,
|
|
1815
1813
|
id: `${e.identifier}-card`,
|
|
1816
1814
|
style: { flexGrow: "1" },
|
|
1817
1815
|
children: /* @__PURE__ */ b(y, { gap: "3", justify: "between", align: "center", children: [
|
|
@@ -1834,11 +1832,11 @@ const De = (s, i) => x(() => !i || !s ? null : s.getInput(i), [s, i]), _t = (s,
|
|
|
1834
1832
|
droppableId: e.identifier,
|
|
1835
1833
|
type: "SECTION",
|
|
1836
1834
|
isDropDisabled: a,
|
|
1837
|
-
children: (
|
|
1835
|
+
children: (z) => /* @__PURE__ */ b(
|
|
1838
1836
|
y,
|
|
1839
1837
|
{
|
|
1840
|
-
ref:
|
|
1841
|
-
...
|
|
1838
|
+
ref: z.innerRef,
|
|
1839
|
+
...z.droppableProps,
|
|
1842
1840
|
direction: "column",
|
|
1843
1841
|
gap: "0",
|
|
1844
1842
|
children: [
|
|
@@ -1853,7 +1851,7 @@ const De = (s, i) => x(() => !i || !s ? null : s.getInput(i), [s, i]), _t = (s,
|
|
|
1853
1851
|
},
|
|
1854
1852
|
D.identifier
|
|
1855
1853
|
)),
|
|
1856
|
-
|
|
1854
|
+
z.placeholder,
|
|
1857
1855
|
/* @__PURE__ */ r(he, { ...v, children: /* @__PURE__ */ b(G, { type: "button", variant: "outline", children: [
|
|
1858
1856
|
/* @__PURE__ */ r(Me, {}),
|
|
1859
1857
|
" Add a field"
|
|
@@ -1876,12 +1874,12 @@ const De = (s, i) => x(() => !i || !s ? null : s.getInput(i), [s, i]), _t = (s,
|
|
|
1876
1874
|
)
|
|
1877
1875
|
] })
|
|
1878
1876
|
}
|
|
1879
|
-
),
|
|
1880
|
-
o.some((
|
|
1877
|
+
) }),
|
|
1878
|
+
o.some((E) => E !== null) && N(),
|
|
1881
1879
|
e.condition && /* @__PURE__ */ r(pn, { identifier: e.identifier, condition: e.condition })
|
|
1882
1880
|
]
|
|
1883
1881
|
}
|
|
1884
|
-
)
|
|
1882
|
+
);
|
|
1885
1883
|
}), bn = (s, i) => {
|
|
1886
1884
|
var t;
|
|
1887
1885
|
const e = { ...s };
|
|
@@ -1928,7 +1926,7 @@ const De = (s, i) => x(() => !i || !s ? null : s.getInput(i), [s, i]), _t = (s,
|
|
|
1928
1926
|
for (const [e, t] of Object.entries(s))
|
|
1929
1927
|
if (t.identifier === i)
|
|
1930
1928
|
return [t, e];
|
|
1931
|
-
}, vn =
|
|
1929
|
+
}, vn = S(function() {
|
|
1932
1930
|
const { values: i, setFieldValue: e } = me(), [t, n] = xi(bn, i.fields, pt), { showInfo: o } = yi();
|
|
1933
1931
|
we(() => {
|
|
1934
1932
|
n({ type: "update", state: pt(i.fields) });
|
|
@@ -2032,7 +2030,7 @@ const De = (s, i) => x(() => !i || !s ? null : s.getInput(i), [s, i]), _t = (s,
|
|
|
2032
2030
|
identifier: "description"
|
|
2033
2031
|
}), Fn = { formId: qe, placeholder: "Explain the purpose of this form." }, Tn = () => {
|
|
2034
2032
|
alert("This is a form preview, your data will not be saved.");
|
|
2035
|
-
}, Bn =
|
|
2033
|
+
}, Bn = S(
|
|
2036
2034
|
xe((s, i) => {
|
|
2037
2035
|
const { onCancel: e, onSave: t, revision: n } = s, o = n ? "Edit form" : "Create a new form", { heading: a = o } = s, c = F((p) => {
|
|
2038
2036
|
const g = {};
|
package/dist/forms.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(x,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("react/jsx-runtime"),require("@overmap-ai/blocks"),require("formik"),require("react"),require("@hello-pangea/dnd"),require("@overmap-ai/core"),require("lodash.get"),require("lodash.set"),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"],n):(x=typeof globalThis<"u"?globalThis:x||self,n(x.forms={},x.jsxRuntime,x.blocks,x.formik,x.React,x.dnd,x.core,x.get,x.set,x.Xarrow))})(this,function(x,n,o,$,d,U,F,J,Le,Ke){"use strict";var ni=Object.defineProperty;var ri=(x,n,o)=>n in x?ni(x,n,{enumerable:!0,configurable:!0,writable:!0,value:o}):x[n]=o;var m=(x,n,o)=>(ri(x,typeof n!="symbol"?n+"":n,o),o);class Ze{constructor(i){m(this,"type");m(this,"identifier");m(this,"description");const{description:e=null,identifier:t,type:r}=i;this.identifier=t,this.description=e,this.type=r}getId(){return this.identifier}static deserialize(i){throw new Error(`${this.name} must implement deserialize.`)}_serialize(){if(!this.identifier)throw new Error("Field identifier must be set before serializing.");return{type:this.type,identifier:this.identifier,description:this.description}}}class V extends Ze{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:i,children:e,severity:t,inputId:r,labelId:s,flexProps:c}=l;return n.jsx(o.Flex,{direction:"column",gap:"1",asChild:!0,...c,children:n.jsxs("label",{htmlFor:r,children:[n.jsx(o.Text,{severity:t,id:s,children:i}),e]})})},W=l=>{const{helpText:i,children:e,severity:t}=l;return n.jsxs(o.Flex,{direction:"column",gap:"1",children:[e,n.jsx(o.Flex,{direction:"column",children:n.jsx(o.Text,{size:"1",severity:t,className:me.description,children:i})})]})},j=l=>{const{id:i,field:e,formId:t,...r}=l,[s,c,u]=$.useField(e.getId()),{touched:a}=c,p=c.error??e.description,f=c.error?"danger":void 0,h=i??`${t}-${e.getId()}-input`,g=`${h}-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:p,severity:f,inputId:h,labelId:g,label:y,fieldProps:v,helpers:u,field:e},{...r,"aria-labelledby":g}]},yt=[!0,"true"],Ye=d.memo(function(i){const[{inputId:e,labelId:t,severity:r,helpText:s,label:c,fieldProps:u},a]=j(i),p=o.useSeverityColor(r),f=yt.includes(u.value);return n.jsx(W,{helpText:s,severity:r,children:n.jsx(q,{severity:r,inputId:e,labelId:t,label:c,flexProps:{direction:"row-reverse",justify:"end",align:"center",gap:"2"},children:n.jsx(o.Checkbox,{...a,...u,id:e,color:p,value:f.toString(),checked:f,onCheckedChange:u.onChange,onChange:void 0,onBlur:void 0})})})}),ee=class ee 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 ee(e)}getInput(e){return n.jsx(Ye,{...e,field:this})}};m(ee,"fieldTypeName","Checkbox"),m(ee,"fieldTypeDescription","Perfect for both optional and required yes/no questions."),m(ee,"Icon",o.CheckCircledIcon);let Y=ee;const Qe=d.memo(function(i){const[{inputId:e,labelId:t,severity:r,helpText:s,label:c,fieldProps:u,field:a},p]=j(i),f=o.useSeverityColor(r);return n.jsx(W,{helpText:s,severity:r,children:n.jsx(q,{severity:r,inputId:e,labelId:t,label:c,children:n.jsx(o.TextField.Input,{...p,...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 Y({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 n.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 G=_;const Xe=d.memo(function(i){const[{inputId:e,labelId:t,severity:r,helpText:s,label:c,fieldProps:u},a]=j(i),p=o.useSeverityColor(r),f=u.value?u.value.split("T")[0]:"";return n.jsx(W,{helpText:s,severity:r,children:n.jsx(q,{severity:r,inputId:e,labelId:t,label:c,children:n.jsx(o.TextField.Input,{...a,...u,type:"date",id:e,color:p,value:f})})})}),te=class te 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 te(e)}getInput(e){return n.jsx(Xe,{field:this,...e})}};m(te,"fieldTypeName","Date"),m(te,"fieldTypeDescription","Allows specifying a date."),m(te,"Icon",o.CalendarIcon);let ge=te;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 G({label:"Minimum length",description:"Minimum number of characters",required:!1,identifier:"minimum_length",minimum:0,maximum:100,formValidators:[this._validateMin],integers:!0}),new G({label:"Maximum length",description:"Maximum number of characters",required:!1,identifier:"maximum_length",minimum:1,maximum:5e3,formValidators:[this._validateMax],integers:!0})]}getFieldValidators(){const e=super.getFieldValidators();return this.minLength&&e.push(t=>{if(this.minLength&&(!t||t.length<this.minLength))return!this.required&&!t?null:`Minimum ${this.minLength} character(s).`}),this.maxLength&&e.push(t=>{if(typeof t=="string"&&this.maxLength&&t.length>this.maxLength)return`Maximum ${this.maxLength} character(s).`}),e}_serialize(){if(!this.identifier)throw new Error("Field identifier must be set before serializing.");return{...super._serialize(),minimum_length:this.minLength,maximum_length:this.maxLength}}}m(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(i){const[{inputId:e,labelId:t,severity:r,helpText:s,label:c,fieldProps:u,field:a},p]=j(i),f=o.useSeverityColor(r);return n.jsx(W,{helpText:s,severity:r,children:n.jsx(q,{severity:r,inputId:e,labelId:t,label:c,children:n.jsx(o.TextField.Input,{...p,...u,type:a.inputType,id:e,color:f})})})}),ie=class ie 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 ie({...c,maxLength:t,minLength:r,inputType:s})}getInput(e){return n.jsx(Je,{field:this,...e})}};m(ie,"fieldTypeName","Short Text"),m(ie,"fieldTypeDescription","Short text fields can hold up to 500 characters on a single line."),m(ie,"Icon",o.InputIcon);let k=ie;const ke=d.memo(function(i){const[{inputId:e,labelId:t,severity:r,helpText:s,label:c,fieldProps:u},a]=j(i);return n.jsx(W,{helpText:s,severity:r,children:n.jsx(q,{severity:r,inputId:e,labelId:t,label:c,children:n.jsx(o.TextArea,{...a,...u,resize:"vertical",id:e,severity:r})})})}),ne=class ne extends ye{constructor(i){const e=i.maxLength?Math.min(5e3,i.maxLength):5e3,t=i.minLength?Math.min(i.minLength,e):void 0;super({...i,maxLength:e,minLength:t,type:"text"})}serialize(){return super._serialize()}static deserialize(i){if(i.type!=="text")throw new Error("Type mismatch.");const{maximum_length:e,minimum_length:t,...r}=i;return new ne({...r,maxLength:e,minLength:t})}getInput(i){return n.jsx(ke,{field:this,...i})}};m(ne,"fieldTypeName","Paragraph"),m(ne,"fieldTypeDescription","Paragraph fields can hold up to 5000 characters and can have multiple lines."),m(ne,"Icon",o.RowsIcon);let R=ne;const Re=d.memo(function(i){const[{inputId:e,labelId:t,severity:r,helpText:s,label:c,fieldProps:u,field:a},p]=j(i),{onChange:f,onBlur:h}=u,g=d.useMemo(()=>a.options.map(v=>({value:v.value,itemContent:v.label})),[a.options]),y=d.useCallback(v=>{f(v),h(v)},[f,h]);return n.jsx(W,{helpText:s,severity:r,children:n.jsx(q,{severity:r,inputId:e,labelId:t,label:c,children:n.jsx(o.Select,{items:g,...u,onValueChange:y,placeholder:"Select one...",id:e,severity:r,...p})})})}),xe=(l="",i=[])=>({type:"section",fields:i,identifier:l,label:null,condition:null,conditional:!1}),xt=l=>{if(!l)return;const i=l.fields;let e=[];const t=[];for(const r of i)r.type==="section"?(e.length>0&&(t.push(xe(`AUTO_section-${i.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 Pe(l,i,e){const t=Array.from(l),[r]=t.splice(i,1);if(!r)throw new Error("Could not find field to reorder.");return t.splice(e,0,r),t}function vt(l,i,e){const t=Array.from(l);return t[i]=e,t}function et(l,i,e){const t=Array.from(l??[]);return t.splice(i,0,e),t}function ve(l,i){const e=Array.from(l);return e.splice(i,1),e}const tt=(l,i)=>{if(typeof l=="string"&&l.length>0)return l;const e=new Date;return`${F.slugify(i)}-${e.getTime()}`},it=(l,i)=>{if(!i)return null;for(const e of l)if(e.type==="section"){const t=it(e.fields,i);if(t)return t}else if(e.identifier===i)return e;return null},we=(l,i)=>l.filter((e,t)=>t<i).flatMap(e=>e.fields),nt=l=>l.flatMap(i=>i.type==="section"?[...i.fields.map(e=>e.label),i.label]:i.label).filter(i=>i!==null),$e=(l,i)=>{let e=1,t=`${l} (${e})`;for(;i.includes(t);)t=`${l} (${++e})`;return t},rt=d.memo(function(i){const[{inputId:e,labelId:t,severity:r,helpText:s,label:c,fieldProps:u},a]=j(i),p=o.useSeverityColor(r),f=d.useMemo(()=>Array.isArray(u.value)?u.value:[],[u.value]),{onChange:h,onBlur:g}=u,y=`${e}-droppable`,{disabled:v}=a,[T,b]=d.useState(""),[C,w]=d.useState(""),P=C||s,z=C?"red":p,I=d.useCallback(A=>{h(A),g(A)},[h,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(!T.trim())return w("Option cannot be empty");const A=T.trim();I([...f,{value:A,label:A}]),b("")},[T,C,I,f]),Q=d.useCallback(A=>{A.key==="Enter"&&(A.preventDefault(),O())},[O]),H=d.useCallback(A=>{I(ve(f,A))},[f,I]),Z=d.useCallback(A=>{if(!A.destination)return;const N=A.source.index,X=A.destination.index;I(Pe(f,N,X))},[I,f]);return n.jsx(U.DragDropContext,{onDragEnd:Z,children:n.jsxs(o.Flex,{direction:"column",gap:"2",children:[n.jsx(W,{helpText:P,severity:r,children:n.jsx(q,{severity:r,inputId:e,labelId:t,label:c,children:(!v||f.length===0)&&n.jsxs(o.Flex,{gap:"2",children:[n.jsx(o.Box,{grow:"1",children:n.jsx(o.TextField.Input,{placeholder:"Press enter to add a new option",...a,...u,value:T,onChange:M,onKeyDown:Q,id:e,color:z,onBlur:void 0})}),n.jsx(o.IconButton,{type:"button","aria-label":"Add option",disabled:!!C||v,onClick:O,children:n.jsx(o.PlusIcon,{})})]})})}),n.jsx(U.Droppable,{droppableId:y,children:A=>n.jsxs(o.Flex,{...A.droppableProps,ref:A.innerRef,direction:"column",children:[f.map((N,X)=>n.jsx(U.Draggable,{draggableId:`${N.value}-draggable`,index:X,isDragDisabled:v,children:({draggableProps:Se,dragHandleProps:Ae,innerRef:Ee})=>n.jsx(o.Flex,{...Ae,...Se,ref:Ee,gap:"2",align:"center",justify:"between",mb:"1",asChild:!0,children:n.jsxs(o.Badge,{color:"gray",size:"2",children:[n.jsx("span",{children:N.label}),n.jsx(o.IconButton,{size:"small",variant:"ghost",type:"button","aria-label":"Delete option",severity:"info",disabled:v,onClick:()=>H(X),children:n.jsx(o.Cross1Icon,{})})]})})},N.value)),A.placeholder]})})]})})}),re=class re 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 n.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 re(e)}};m(re,"fieldTypeName","Multi-string"),m(re,"fieldTypeDescription","Allows the user to provide multiple unique strings."),m(re,"Icon",o.ListBulletIcon);let de=re;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 oe=class oe extends ot{constructor(i){super({...i,type:"select"})}getValueFromChangeEvent(i){return typeof i=="string"?i:i.target.value}serialize(){return super._serialize()}static deserialize(i){if(i.type!=="select")throw new Error("Type mismatch.");return new oe(i)}getInput(i){return n.jsx(Re,{field:this,...i})}};m(oe,"fieldTypeName","Dropdown"),m(oe,"fieldTypeDescription","Allows the user to select a single option from a list of options."),m(oe,"Icon",o.DropdownMenuIcon);let ce=oe;const wt=l=>l?Array.isArray(l)?l:[l]:[],st=d.memo(function(i){const[{inputId:e,labelId:t,severity:r,helpText:s,label:c,fieldProps:u,field:a},p]=j(i),{onChange:f,onBlur:h}=u,g=d.useMemo(()=>wt(u.value),[u.value]),y=d.useCallback(v=>{f(v),h(v)},[f,h]);return n.jsx(W,{helpText:s,severity:r,children:n.jsx(q,{severity:r,inputId:e,labelId:t,label:c,children:n.jsx(o.MultiSelect,{value:g,onValueChange:y,options:a.options,name:u.name,placeholder:"Select one or more...",id:e,severity:r,...p})})})}),se=class se extends ot{constructor(i){super({...i,type:"multi-select"})}getValueFromChangeEvent(i){if(Array.isArray(i))return i;throw new Error("Expected an array.")}isBlank(i){return super.isBlank(i)||i.length===0}serialize(){return super._serialize()}static deserialize(i){if(i.type!=="multi-select")throw new Error("Type mismatch.");return new se(i)}getInput(i){return n.jsx(st,{field:this,...i})}};m(se,"fieldTypeName","Multi-select"),m(se,"fieldTypeDescription","Allows the user to select a multiple options from a list of options."),m(se,"Icon",o.CheckboxIcon);let ue=se;const Ft=d.memo(function({field:i,...e}){const[{value:t}]=$.useField(i.options.clonedFieldIdentifier),r=d.useMemo(()=>{const s=i.options.getFieldToClone(t);return s?fe(s):null},[i.options,t]);return he(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 n.jsx(t,{field:this,...e})}}m(Fe,"fieldTypeName","Custom"),m(Fe,"fieldTypeDescription","Allows re-rendering of field already in the form");class It extends Fe{constructor(i){super(i,Ft)}}const bt=d.memo(function(i){const{field:e,...t}=i,{label:r,description:s,fields:c,condition:u}=e,{values:a,setFieldValue:p}=$.useFormikContext(),f=u!=null&&u.identifier?J(a,u.identifier):void 0,h=d.useMemo(()=>Ne(u,f),[u,f]);d.useEffect(()=>{if(!h)for(const y of c)p(y.getId(),"").then()},[h,c,p]);const g=qe(c,t);return h?r?n.jsx(o.Card,{children:n.jsxs(o.Flex,{direction:"column",gap:"3",children:[n.jsxs(o.Flex,{direction:"column",children:[n.jsx(o.Heading,{as:"h3",size:"3",children:r}),n.jsx(o.Text,{className:me.description,children:s})]}),g]})}):g:null}),le=class le extends Ze{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 Y({label:"Conditional",description:"Conditionally show or hide this section.",identifier:"conditional",required:!1}),new le({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 It({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 le({...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(J(e,s),e);c&&Le(t,r.getId(),c)}return t}getInput(e){return n.jsx(bt,{field:this,...e})}};m(le,"fieldTypeName","Section"),m(le,"fieldTypeDescription","Sections can be useful for grouping fields together. They can also be conditionally shown or hidden.");let K=le;const Ct={previewImage:"_previewImage_1ig84_1"},De=l=>{const i=["byte","kilobyte","megabyte"];let e=l,t=0;for(;e>1024&&t<i.length-1;)e/=1024,t++;return new Intl.NumberFormat([],{maximumFractionDigits:2,style:"unit",unit:i[t]}).format(e)},Tt=d.memo(function(i){var z;const[{inputId:e,labelId:t,severity:r,helpText:s,label:c,fieldProps:u,field:a},p]=j(i),{onChange:f}=u,h=o.useSeverityColor(r),g=d.useRef(null),{value:y}=u,v=d.useMemo(()=>s||(a.maxFileSize?`Maximum file size: ${De(a.maxFileSize)}`:null),[a.maxFileSize,s]),T=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",P=a.maxFiles>1?C:w;return n.jsxs(o.Flex,{direction:"column",gap:"2",children:[n.jsx(W,{helpText:v,severity:r,children:n.jsxs(q,{severity:r,inputId:e,labelId:t,label:c,children:[n.jsx(o.Flex,{direction:"row",gap:"2",children:n.jsx(o.Box,{width:"max-content",asChild:!0,children:n.jsxs(o.Button,{...p,onClick:T,children:[n.jsx(o.UploadIcon,{})," ",P]})})}),n.jsx("input",{...p,type:"file",ref:g,id:e,accept:(z=a.extensions)==null?void 0:z.join(","),multiple:a.maxFiles>1,color:h,style:{display:"none"},...u,value:""})]})}),Array.isArray(y)&&y.length>0&&n.jsx(o.Flex,{direction:"column",gap:"2",children:y.map((I,M)=>n.jsx(St,{field:a,file:I,onRemove:()=>b(M),disabled:p.disabled},M))})]})}),St=d.memo(function({file:i,field:e,onRemove:t,disabled:r}){const[s,c]=d.useState(null),u=d.useMemo(()=>s&&e.getError([s]),[e,s]),{url:a,name:p,size:f}=d.useMemo(()=>{let h=null,g,y;return s!=null&&s.type.startsWith("image/")&&(h=URL.createObjectURL(s)),s?(g=s.name,y=De(s.size)):(g="Downloading...",y="..."),{url:h,name:g,size:y}},[s]);return d.useEffect(()=>{i instanceof Promise?i.then(c):c(i)},[i]),n.jsx(o.Card,{children:n.jsxs(o.Flex,{direction:{initial:"column",sm:"row"},gap:"3",justify:"between",children:[n.jsxs(o.Flex,{direction:"row",gap:"3",align:"center",grow:"1",shrink:"0",children:[n.jsx(o.IconButton,{severity:"info",variant:"outline","aria-label":`Remove ${p}`,disabled:r,onClick:t,children:n.jsx(o.Cross1Icon,{})}),n.jsxs(o.Flex,{direction:"column",gap:"1",children:[n.jsx(o.Text,{children:p}),n.jsx(o.Text,{size:"1",children:f}),u&&n.jsx(o.Text,{size:"1",severity:"danger",children:u})]})]}),a&&n.jsx("img",{className:Ct.previewImage,src:a,alt:p})]})})}),lt=50*1024*1024,ae=class ae 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 G({label:"How many files can be uploaded?",description:"By default, only one file can be uploaded.",required:!1,minimum:1,maximum:10,identifier:"maximum_files"}),new G({label:"What is the maximum size of each file?",description:"Maximum file size in bytes.",required:!1,identifier:"maximum_size",minimum:1,maximum: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 ${De(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 ae(e)}getInput(e){return n.jsx(Tt,{field:this,...e})}};m(ae,"fieldTypeName","Upload"),m(ae,"fieldTypeDescription","Allows a file to be uploaded."),m(ae,"Icon",o.UploadIcon);let Ve=ae;const Be={date:ge,number:G,boolean:Y,select:ce,string:k,text:R,custom:Fe,upload:Ve,"multi-string":de,"multi-select":ue},_e=l=>{const i=l.type;return Be[i].deserialize(l)},fe=l=>l.type==="section"?K.deserialize(l):_e(l);function Oe(l,i={}){const{readonly:e=!1}=i;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(i=>i instanceof File||i instanceof Promise))}function Ne(l,i){if(!l)return!0;if(Ie(i)||Ie(l.value))throw new Error("Conditions do not support file uploads");const e=Array.isArray(i)?i.map(r=>typeof r=="string"?r:r.value):i,t=Array.isArray(l.value)?l.value.map(r=>typeof r=="string"?r:r.value):l.value;if(Array.isArray(t)&&Array.isArray(e)){for(const r of t)if(!e.includes(r))return!1;return!0}return t===i}const he=(l,i)=>d.useMemo(()=>!i||!l?null:l.getInput(i),[l,i]),qe=(l,i)=>{const e=d.useMemo(()=>l.map(t=>n.jsx("div",{children:t.getInput(i)},t.getId())),[l,i]);return n.jsx(o.Flex,{direction:"column",gap:"2",children:e})},be=l=>Object.keys(l).length>0,at=async(l,i)=>{const e={};for(const t of l.fields)if(t instanceof K){if(t.condition){const{identifier:r}=t.condition;if(!Ne(t.condition,J(i,r)))continue}Object.assign(e,t.getErrors(i))}else{if(!(t instanceof V))throw new Error("Invalid field type");const r=t.getId(),s=t.getError(J(i,r),i);s&&Le(e,r,s)}if(be(e))return e},At=[null,void 0],We=(l,i)=>l.reduce((e,t)=>t instanceof K?{...e,...We(t.fields,i)}:(At.includes(J(e,t.getId()))&&Le(e,t.getId(),""),e),i),Et=()=>{throw new Error("onSubmit must be provided if form is not readonly.")},Ce=d.memo(d.forwardRef((l,i)=>{const{schema:e,values:t={},onSubmit:r=Et,submitText:s="Submit",cancelText:c,onCancel:u,onDirty:a,hideTitle:p=!e.title,hideDescription:f,className:h}=l,{readonly:g}=e.meta,y=d.useMemo(()=>crypto.randomUUID(),[]),v=$.useFormik({initialValues:We(e.fields,t),onSubmit:r,validate:P=>at(e,P),validateOnBlur:!1,validateOnChange:!1}),{dirty:T}=v,b=d.useMemo(()=>typeof e.title=="string"?n.jsx(o.Heading,{children:e.title}):e.title,[e.title]),C=d.useMemo(()=>typeof e.description=="string"?n.jsx(o.Text,{className:me.description,children:e.description}):e.description,[e.description]),w=qe(e.fields,{formId:y,disabled:g});return d.useEffect(()=>{T&&a&&a()},[T,a]),n.jsx($.FormikProvider,{value:v,children:n.jsx(o.Flex,{ref:i,direction:"column",gap:"2",className:h,asChild:!0,children:n.jsxs("form",{id:y,onSubmit:v.handleSubmit,children:[!p&&n.jsx(o.Card,{children:n.jsxs(o.Flex,{direction:"column",gap:"1",children:[b,!f&&C]})}),w,!g&&n.jsxs(o.Flex,{justify:"end",gap:"2",children:[c&&n.jsx(o.Button,{type:"button",variant:"soft",onClick:u,children:c}),n.jsx(o.Button,{type:"submit",disabled:!v.isValid,children:s})]})]})})})})),zt=d.memo(d.forwardRef((l,i)=>{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 p=F.selectSubmissionAttachments(e.offline_id)(c.store.getState())??[],f={};for(const h of p){const g=c.files.fetchFileFromUrl(h.file,h.file_sha1,h.file_name).then(v=>{if(!v.success)throw new Error(`Failed to download attachment ${h.file_name}.`);return v.body}),y=f[h.field_identifier];y?y.push(g):f[h.field_identifier]=[g]}return{...e.values,...f}},[c.files,c.store,e.offline_id,e.values]);return n.jsx(Ce,{ref:i,schema:u,values:a,hideDescription:!t,hideTitle:!r})})),dt={favoriteIcon:"_favoriteIcon_1bixi_1",regularIcon:"_regularIcon_1bixi_9"},je="organization:",He="user:",Mt=d.memo(d.forwardRef((l,i)=>{const{maxResults:e=20,...t}=l,[r,s]=d.useState(""),[c,u]=d.useState(""),{sdk:a}=F.useSDK(),p=d.useMemo(()=>{const w={maxResults:e,searchTerm:r};return c&&(c.startsWith(je)?w.owner_organization=parseInt(c.slice(je.length)):c.startsWith(He)&&(w.owner_user=parseInt(c.slice(He.length)))),w},[r,e,c]),f=F.useAppSelector(F.selectFilteredUserForms(p))??[],h=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(),P={};for(const z of Object.values(h)){const I=F.selectOrganization(z.owner_organization||-1)(w);I&&(P[`${je}${I.id}`]=I.name);const M=F.selectUser(z.owner_user||-1)(w);M&&(P[`${He}${M.id}`]=M.username)}return Object.entries(P).map(([z,I])=>({itemContent:I,value:z}))},[h,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 n.jsxs(o.Flex,{ref:i,direction:"column",gap:"2",children:[n.jsxs(o.Flex,{gap:"2",grow:"1",children:[n.jsx(o.Box,{grow:"1",asChild:!0,children:n.jsx(o.TextField.Root,{size:"3",children:n.jsx(o.TextField.Input,{placeholder:"Filter",value:r,onChange:v})})}),n.jsx(o.Select,{items:y,value:c,onValueChange:u,placeholder:"Owner",size:"large"})]}),f.length>0&&n.jsx(o.ButtonList.Root,{children:f.map(w=>n.jsx(Lt,{...t,form:w,handleToggleFavorite:()=>g(w)},w.offline_id))}),n.jsx(o.Box,{px:"3",children:n.jsx(o.Text,{size:"2",severity:"info",children:C})})]})})),Lt=l=>{var g;const{form:i,onSelectForm:e,isFavoriteEditable:t,handleToggleFavorite:r}=l,s=(g=F.useAppSelector(F.selectOrganization(i.owner_organization||-1)))==null?void 0:g.name,c=F.useAppSelector(F.selectUser(i.owner_user||-1)),u=F.useAppSelector(F.selectCurrentUser).id,a=!!c&&c.id===u,p=s??(a?"You":c==null?void 0:c.username)??"Unknown",f=d.useCallback(y=>{y.stopPropagation(),r()},[r]),h=n.jsx(o.ButtonList.Item,{onClick:()=>e(i),asChild:!0,children:n.jsxs(o.Flex,{justify:"between",gap:"2",py:"2",px:"3",...o.divButtonProps,children:[n.jsxs(o.Flex,{grow:"1",align:"center",gap:"2",children:[n.jsx(o.IconButton,{className:F.classNames(i.favorite?dt.favoriteIcon:dt.regularIcon),variant:"ghost",onClick:f,"aria-label":i.favorite?"Favorite form":"Standard form",disabled:!t,children:i.favorite?n.jsx(o.StarFilledIcon,{}):n.jsx(o.StarIcon,{})}),n.jsx(o.Text,{noWrap:!0,children:i.latestRevision.title}),i.latestRevision.description&&n.jsx(o.QuestionMarkCircledIcon,{})]}),p&&n.jsxs(o.Flex,{align:"center",gap:"2",children:[n.jsx(o.PersonIcon,{})," ",p]})]})});return i.latestRevision.description?n.jsx(o.Tooltip,{content:i.latestRevision.description,children:h},i.offline_id):h},ct={submissionsContainer:"_submissionsContainer_9iirt_1",stopHorizontalOverflow:"_stopHorizontalOverflow_9iirt_6"},Pt=d.memo(function(i){var w;const{submission:e,onSubmissionClick:t,compact:r,labelType:s,rowDecorator:c}=i,u=F.useAppSelector(F.selectCurrentUser),a=F.useAppSelector(F.selectUser("created_by"in e?e.created_by:u.id)),p=Ue(e),f=F.isToday(p)?p.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):F.getLocalDateString(p),h=F.useAppSelector(F.selectFormRevision(e.form_revision));if(!h)throw new Error(`Could not find revision ${e.form_revision} for submission ${e.offline_id}.`);const g=(w=F.useAppSelector(F.selectLatestFormRevision(h.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())??"?",T=h.revision===g,b=d.useCallback(()=>{t&&t({submission:e})},[e,t]),C=n.jsx(o.ButtonList.Item,{onClick:b,asChild:!0,children:n.jsxs(o.Flex,{grow:"1",width:"100%",p:"2",gap:"2",justify:"between",children:[n.jsxs(o.Flex,{gap:"2",align:"center",className:ct.stopHorizontalOverflow,children:[n.jsx(o.Avatar,{src:y,size:"1",fallback:v}),n.jsx(o.Text,{size:"2",noWrap:!0,children:s==="creator"?(a||u).username:h.title})]}),n.jsxs(o.Flex,{gap:"2",align:"center",children:[!r&&(h.revision?n.jsx(o.Badge,{variant:"soft",severity:T?"primary":"info",children:r?h.revision.toString():`Revision #${h.revision}`}):!!g&&n.jsx(o.Badge,{children:"Original"})),n.jsx(o.Text,{size:"2",noWrap:!0,children:f})]})]})});return c?c(e,C):C}),Ue=l=>{const i="created_at"in l?l.created_at:l.submitted_at;return new Date(i)},$t=d.memo(function(i){const{formId:e,submissions:t,compact:r=!1,className:s,after:c,variant:u="outline",...a}=i;if(!!e==!!t)throw new Error("Either formId or submissions must be provided, but not both.");const p=F.useAppSelector(t?()=>t:F.selectSubmissionsForForm(e)),f=d.useMemo(()=>p==null?void 0:p.sort((h,g)=>Ue(g).getTime()-Ue(h).getTime()),[p]);return n.jsx(o.ButtonList.Root,{className:F.classNames(ct.submissionsContainer,s),size:"small",variant:u,before:!r&&n.jsxs(o.Text,{severity:"info",children:["There are ",((p==null?void 0:p.length)||0).toString()," submissions of this form."]}),after:c,children:f==null?void 0:f.map((h,g)=>n.jsx(Pt,{submission:h,compact:r,...a},g))})}),Dt=d.memo(function(i){const{name:e,render:t}=i,{submitForm:r}=$.useFormikContext(),[s,c,u]=$.useField(e);return d.useMemo(()=>{const a=p=>u.setValue(p,!1);return t({value:s.value,setValue:a,patchValue:r})},[r,u,s.value,t])}),Vt=d.memo(d.forwardRef((l,i)=>{const{children:e,schema:t,values:r,onPatch:s,onError:c,...u}=l,a=d.useMemo(()=>We(t.fields,r),[t.fields,r]),p=d.useCallback(v=>{const T={};for(const b in v){const C=v[b];C!==a[b]&&C!==void 0&&(T[b]=C)}be(T)&&s(T)},[a,s]),f=d.useCallback(async v=>{const T=await at(t,v);return T&&c(T),T},[t,c]),h=$.useFormik({initialValues:a,onSubmit:p,validate:f,validateOnBlur:!1,validateOnChange:!1}),{errors:g,resetForm:y}=h;return d.useEffect(()=>{be(g)&&y({values:a,errors:{}})},[g,a,y]),n.jsx($.FormikProvider,{value:h,children:n.jsx("form",{...u,ref:i,onSubmit:h.handleSubmit,children:e})})})),ut={...Be,section:K},Bt=d.memo(function(i){const{field:e,setFieldType:t}=i,r=e.fieldTypeName,s=e.fieldTypeDescription,c=e.Icon;return n.jsxs(o.Flex,{gap:"4",align:"center",children:[n.jsx(o.Button,{type:"button",variant:"surface",onClick:t,style:{width:"135px"},children:n.jsxs(o.Flex,{gap:"3",align:"center",grow:"1",children:[n.jsx(c,{}),r]})}),n.jsx(o.Text,{children:s})]})}),ft=[["string","text"],["select","multi-select","upload"],["boolean","date","number","multi-string"]],_t=ft.length-1,Ot=d.memo(function(i){const{setFieldType:e}=i;return n.jsx(o.Flex,{direction:"column",gap:"3",children:ft.map((t,r)=>n.jsxs(o.Flex,{direction:"column",gap:"3",children:[n.jsx(o.Flex,{direction:"column",gap:"2",children:t.map(s=>n.jsx(Bt,{field:Be[s],setFieldType:()=>e(s)},s))}),r<_t&&n.jsx(o.Separator,{size:"4"})]},r))})}),Nt=l=>i=>{if(!(!i||typeof i!="string")&&l.includes(i.trim()))return"This name is already taken."},qt=(l,i)=>{const e=[new k({label:"Label",required:!0,maxLength:200,identifier:"label",fieldValidators:[Nt(l)]}),new R({label:"Description",required:!1,maxLength:1e3,identifier:"description"})];return i==="section"?e:[...e,new Y({label:"Required",description:null,required:!1,identifier:"required"})]},Wt=d.memo(function(i){const{fieldType:e,handleCancel:t,handleCreateField:r,defaultField:s,conditionalSourceFields:c}=i,u=ut[e],a=$.useFormikContext(),p=d.useMemo(()=>{const f=nt(a.values.fields).filter(g=>g!==(s==null?void 0:s.label));let h=qt(f,e);if(u===K){if(c===void 0)throw new Error("Conditional source fields must be provided when changing sections.");h=h.concat(u.getFieldCreationSchema(c))}else{if(!(u.prototype instanceof V))throw new Error(`Field must be an instance of BaseField. Got ${u}.`);h=[...h,...u.getFieldCreationSchema()]}return{fields:h,meta:{readonly:!1},title:null}},[a.values.fields,e,u,s==null?void 0:s.label,c]);return n.jsx(Ce,{schema:p,values:s,onSubmit:r,cancelText:s?void 0:"Back",onCancel:t})}),pe=d.memo(function(i){const{parentPath:e,index:t,children:r,initial:s,editing:c,conditionalSourceFields:u}=i,[a,p]=d.useState(),f=(s==null?void 0:s.type)??a,h=f?ut[f].fieldTypeName:void 0,{setFieldValue:g,values:y}=$.useFormikContext();if(c&&!s)throw new Error("Initial field must be provided if editing is true.");const v=!f&&!c&&!s,T=v?"Choose a field type":`${h} settings`,b=v?"Select a field type to add to this section.":(h==null?void 0:h.toLowerCase())==="section"?"Customize your section":`Customize your ${h==null?void 0:h.toLowerCase()} field.`,C=d.useCallback(()=>p(void 0),[]),w=d.useCallback(I=>{p(void 0),I()},[]),P=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 Q=fe({type:f,...I,identifier:tt(I.identifier,O)}).serialize(),H=J(y,e);if(H===void 0)throw new Error("Parent path must point to an existing field.");let Z;if(!Array.isArray(H))throw new Error("Parent path must point to an array.");c?Z=vt(H,t,Q):Z=et(H,t,Q),g(e,Z).then(),M()},[c,f,y,e,g,t]),z=d.useCallback(I=>v?n.jsx(Ot,{setFieldType:p}):n.jsx(Wt,{conditionalSourceFields:u,handleCancel:C,handleCreateField:M=>P(M,I),fieldType:f,defaultField:s}),[u,C,P,s,v,f]);return n.jsx(o.Dialog,{onCloseInterrupt:w,title:T,description:b,content:z,children:r})}),jt=({children:l})=>n.jsx(n.Fragment,{children:l}),ht=d.memo(function(i){const{remove:e,editProps:t,insertAfterProps:r,duplicateProps:s,type:c}=i,u=d.useMemo(()=>[{Wrapper:pe,wrapperProps:t,Icon:o.Pencil1Icon,text:"Edit"},{Icon:o.TrashIcon,buttonProps:{onClick:e},text:"Delete"},{Wrapper:pe,wrapperProps:s,Icon:o.CopyIcon,text:"Duplicate"},{Wrapper:pe,wrapperProps:r,Icon:o.PlusIcon,text:`Add ${c==="section"?"section":"field"}`}],[s,t,r,e,c]);return n.jsx(o.Box,{display:"block",children:n.jsx(o.DropdownMenu,{trigger:n.jsx(o.IconButton,{variant:"ghost","aria-label":"Actions menu",children:n.jsx(o.DotsVerticalIcon,{})}),closeOnSelect:!1,items:u.map(a=>{var f;const p=a.Wrapper??jt;return{...a.buttonProps,onSelect:(f=a.buttonProps)==null?void 0:f.onClick,content:n.jsx(p,{...a.wrapperProps,children:n.jsxs(o.Flex,{gap:"2",align:"center",children:[n.jsx(a.Icon,{}),a.text]})})}}).filter(a=>a!==null)})})}),Te="form-builder",Ht=d.memo(function(i){const{field:e,index:t,sectionIndex:r,takenLabels:s,remove:c}=i,u=d.useMemo(()=>fe(e),[e]),a=he(u,{formId:Te,disabled:!0}),p=d.useCallback(y=>{if(y.label===null)throw new Error(`Expected a label for field ${y.identifier}`);return{...y,label:$e(y.label,s),identifier:""}},[s]),f=d.useMemo(()=>({index:t,parentPath:`fields.${r}.fields`,initial:e,editing:!0}),[e,t,r]),h=d.useMemo(()=>({parentPath:`fields.${r}.fields`,index:t+1,initial:p(e)}),[p,e,t,r]),g=d.useMemo(()=>({parentPath:`fields.${r}.fields`,index:t+1,initial:void 0}),[t,r]);return n.jsx(U.Draggable,{draggableId:e.identifier,index:t,children:y=>n.jsx(o.Card,{ref:y.innerRef,...y.draggableProps,...y.dragHandleProps,id:`${e.identifier}-card`,mb:"4",children:n.jsxs(o.Flex,{gap:"4",justify:"between",align:"center",children:[a,n.jsx(ht,{remove:c,editProps:f,duplicateProps:h,insertAfterProps:g})]})})})}),Ut=l=>{const{identifier:i,condition:e}=l,t={primary:"var(--gray-a4)",hover:"var(--primary-color)"},[r,s]=d.useState(t.primary),[c,u]=d.useState(0),a=d.useCallback(()=>{s(t.hover),u(1)},[t.hover]),p=d.useCallback(()=>{s(t.primary),u(0)},[t.primary]);return e?n.jsxs(n.Fragment,{children:[n.jsx(Ke,{start:`${i}-card`,end:`${i}-floating-point`,startAnchor:"right",endAnchor:"left",color:r,strokeWidth:1,path:"straight",showHead:!1,zIndex:c,arrowBodyProps:{pointerEvents:"stroke",onMouseEnter:a,onMouseLeave:p}}),n.jsx(Ke,{start:`${i}-floating-point`,end:`${e.identifier}-card`,startAnchor:"left",endAnchor:"right",color:r,strokeWidth:1,path:"grid",gridBreak:"0",showHead:!1,zIndex:c,arrowBodyProps:{pointerEvents:"stroke",onMouseEnter:a,onMouseLeave:p}})]}):null},Gt=d.memo(function(i){var Q,H,Z,A,N,X,Se,Ae,Ee;const{field:e,index:t,dropState:r,conditionalFieldCounts:s}=i,c=(Q=r[e.identifier])==null?void 0:Q.disabled,{setFieldValue:u,values:a}=$.useFormikContext(),p=o.useAlertDialog(),f=nt(a.fields),h=d.useCallback((E,S)=>{for(const D of E){const L=S.indexOf(D);u(`fields.${L}.condition`,null).then(),u(`fields.${L}.conditional`,!1).then()}},[u]),g=d.useCallback(E=>{var L;const S=e.fields[E];if(!S)throw new Error("Could not find field to remove.");const D=[];for(const B of a.fields)((L=B.condition)==null?void 0:L.identifier)===S.identifier&&D.push(B);return{removing:S,affectedSections:D,action:()=>u(`fields.${t}.fields`,ve(e.fields,E))}},[e.fields,a.fields,u,t]),y=d.useCallback(E=>{const{affectedSections:S,action:D,removing:L}=g(E),B=()=>{D().then(),h(S,a.fields)};if(S.length>0){const Ge=S.map(ze=>ze.label).join(", ");return p({title:"Remove condition?",description:`${L.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()},[g,h,a.fields,p]),v=d.useCallback(()=>{const S=e.fields.map((Me,ii)=>g(ii)).flatMap(Me=>Me.affectedSections),D=S.length?"Remove fields and conditions?":"Remove fields?",L=e.fields.length,B=S.map(Me=>Me.label).join(", "),Ge=S.length?`Deleting this section will remove the ${L} field(s) it contains and will remove the conditions from following sections: ${B}`:`Deleting this section will remove the ${L} field(s) it contains.`,ze=ve(a.fields,t),gt=()=>u("fields",ze);if(S.length>0)return p({title:D,description:Ge,severity:"danger",actionText:"Remove",onAction:()=>{gt().then(()=>{h(S,ze)})}});gt().then()},[e.fields,a.fields,t,g,u,p,h]),T=d.useCallback(E=>{if(E.label===null)throw new Error(`Expected a label for field ${E.identifier}`);const S=$e(E.label,f),D=E.fields.map(L=>{const B=$e(L.label,f);return{...L,label:B,identifier:tt(void 0,B)}});return{...E,label:S,fields:D,identifier:""}},[f]),b=d.useMemo(()=>({index:t,parentPath:"fields",initial:e,editing:!0,conditionalSourceFields:we(a.fields,t)}),[e,t,a.fields]),C=d.useMemo(()=>({index:t+1,parentPath:"fields",initial:xe(),conditionalSourceFields:we(a.fields,t+1)}),[t,a.fields]),w=d.useMemo(()=>({parentPath:`fields.${t}.fields`,index:e.fields.length,initial:void 0}),[e.fields.length,t]),P=d.useMemo(()=>({index:t+1,parentPath:"fields",initial:T(e),conditionalSourceFields:we(a.fields,t+1)}),[T,e,t,a.fields]),z=d.useMemo(()=>{var E,S;return(S=it(a.fields,(E=e.condition)==null?void 0:E.identifier))==null?void 0:S.label},[(H=e.condition)==null?void 0:H.identifier,a.fields]),I=Array.isArray((Z=e.condition)==null?void 0:Z.value)?"contains all of":"equals";if(Ie((A=e.condition)==null?void 0:A.value))throw new Error("File values are not supported for conditions.");const M=Array.isArray((N=e.condition)==null?void 0:N.value)?(Se=(X=e.condition)==null?void 0:X.value)==null?void 0:Se.map(E=>typeof E=="string"?E:E.label).join(", "):(Ee=(Ae=e.condition)==null?void 0:Ae.value)==null?void 0:Ee.toString(),O=()=>{const S=s.filter(B=>B!==null).length,D=s[t]??0,L=2/S*D;return n.jsx("div",{id:`${e.identifier}-floating-point`,style:{width:`${2-L}%`,marginLeft:`${L}%`}})};return n.jsx(U.Draggable,{draggableId:e.identifier,index:t,children:E=>n.jsxs(o.Flex,{direction:"row",justify:"center",align:"center",mb:"4",children:[n.jsx(o.Card,{ref:E.innerRef,...E.draggableProps,...E.dragHandleProps,id:`${e.identifier}-card`,style:{flexGrow:"1"},children:n.jsxs(o.Flex,{gap:"3",justify:"between",align:"center",children:[n.jsxs(o.Flex,{direction:"column",gap:"2",grow:"1",children:[n.jsxs(o.Flex,{direction:"column",children:[n.jsx(o.Heading,{as:"h3",size:"3",children:e.label}),n.jsx(o.Text,{className:me.description,children:e.description})]}),e.condition&&n.jsx(o.Text,{size:"1",children:n.jsxs(o.Em,{children:["Display only if ",n.jsx(o.Strong,{children:z})," ",I," ",n.jsx(o.Strong,{children:M})]})}),n.jsx(U.Droppable,{droppableId:e.identifier,type:"SECTION",isDropDisabled:c,children:S=>n.jsxs(o.Flex,{ref:S.innerRef,...S.droppableProps,direction:"column",gap:"0",children:[e.fields.map((D,L)=>n.jsx(Ht,{field:D,index:L,sectionIndex:t,remove:()=>y(L),takenLabels:f},D.identifier)),S.placeholder,n.jsx(pe,{...w,children:n.jsxs(o.Button,{type:"button",variant:"outline",children:[n.jsx(o.PlusIcon,{})," Add a field"]})})]})})]}),n.jsx(ht,{remove:v,insertAfterProps:C,editProps:b,duplicateProps:P,type:"section"})]})}),s.some(S=>S!==null)&&O(),e.condition&&n.jsx(Ut,{identifier:e.identifier,condition:e.condition})]})})}),Kt=(l,i)=>{var t;const e={...l};switch(i.type){case"release":for(const r in e)e[r].disabled=!1;return e;case"hold":for(const r in e)(t=e[r])!=null&&t.conditionFields.has(i.fieldId)&&(e[r].disabled=!0);return e;case"update":return i.state}},Zt=(l,i)=>{if(i)for(let e=0;e<l.length;e++){const t=l[e];if(t){for(const r of t.fields)if(r.identifier===i)return e}}},pt=l=>{var e,t,r;const i={};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=i[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),i[c.identifier]={disabled:!1,conditionFields:a,conditionIndex:Zt(l,(r=c.condition)==null?void 0:r.identifier),index:s,label:c.label}}return i},mt=(l,i)=>{for(const[e,t]of Object.entries(l))if(t.identifier===i)return[t,e]},Yt=d.memo(function(){const{values:i,setFieldValue:e}=$.useFormikContext(),[t,r]=d.useReducer(Kt,i.fields,pt),{showInfo:s}=o.useToast();d.useEffect(()=>{r({type:"update",state:pt(i.fields)})},[r,i.fields]);const c=d.useCallback(f=>{f.type==="SECTION"&&r({type:"hold",fieldId:f.draggableId})},[]),u=d.useCallback(f=>{const{source:h,destination:g,type:y,reason:v,draggableId:T}=f;if(r({type:"release"}),!g||v==="CANCEL")return;if(y==="ROOT"){const z=t[T];if(!z)throw new Error("Could not find section context.");let I=typeof z.conditionIndex<"u"?Math.max(z.conditionIndex+1,g.index):g.index;for(const M of Object.values(t))M.conditionIndex===h.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",Pe(i.fields,h.index,I))}if(y!=="SECTION")throw new Error("Unexpected droppable type.");const[b,C]=mt(i.fields,h.droppableId)??[],[w,P]=mt(i.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`,Pe(b.fields,h.index,g.index)).then();else{const z=b.fields[h.index];if(!z)throw new Error("Could not find field to reorder.");e(`fields.${C}.fields`,ve(b.fields,h.index)).then(),e(`fields.${P}.fields`,et(w.fields,g.index,z)).then()}},[i.fields,e,t,s]),a=d.useMemo(()=>({index:i.fields.length,parentPath:"fields",initial:xe(),conditionalSourceFields:we(i.fields,i.fields.length)}),[i.fields]),p=()=>{let f=1;return i.fields.map(h=>h.conditional?f++:null)};return n.jsx(U.DragDropContext,{onDragStart:c,onDragEnd:u,children:n.jsx(U.Droppable,{droppableId:"droppable",type:"ROOT",children:f=>n.jsxs(o.Flex,{ref:f.innerRef,...f.droppableProps,direction:"column",gap:"0",children:[i.fields.map((h,g)=>n.jsx(Gt,{field:h,index:g,dropState:t,conditionalFieldCounts:p()},h.label)),f.placeholder,n.jsx(pe,{...a,children:n.jsxs(o.Button,{type:"button",variant:"outline",children:[n.jsx(o.PlusIcon,{})," Add a section"]})})]})})})}),Qt={title:"",description:"",fields:[]},Xt=new k({label:"Title",minLength:0,maxLength:100,required:!0,identifier:"title"}),Jt={formId:Te,placeholder:"Give your form a title."},kt=new R({label:"Description",minLength:0,maxLength:1e3,required:!1,identifier:"description"}),Rt={formId:Te,placeholder:"Explain the purpose of this form."},ei=()=>{alert("This is a form preview, your data will not be saved.")},ti=d.memo(d.forwardRef((l,i)=>{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=$.useFormik({initialValues:xt(r)??Qt,validate:u,onSubmit:y=>t(y),validateOnChange:!1,validateOnBlur:!1}),p=d.useMemo(()=>Oe(a.values),[a.values]),f=he(Xt,Jt),h=he(kt,Rt),g=d.useMemo(()=>typeof c=="object"?c:n.jsx(o.Heading,{children:c}),[c]);return n.jsx(o.Tabs.Root,{ref:i,defaultValue:"edit",children:n.jsxs(o.Flex,{direction:"column",gap:"2",children:[n.jsxs(o.Tabs.List,{children:[n.jsx(o.Tabs.Trigger,{value:"edit",children:"Edit"}),n.jsx(o.Tabs.Trigger,{value:"preview",children:"Preview"})]}),n.jsxs(o.Tabs.Content,{value:"edit",children:[g,n.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"," ",n.jsx("em",{children:"Preview"})," tab, but"," ",n.jsx("strong",{children:"field values entered on this page will not be saved."})]}),n.jsx(o.Flex,{asChild:!0,direction:"column",gap:"2",mt:"3",children:n.jsxs("form",{id:Te,onSubmit:a.handleSubmit,children:[n.jsxs($.FormikProvider,{value:a,children:[f,h,n.jsx(Yt,{}),n.jsx(o.Text,{severity:"danger",size:"1",children:typeof a.errors.fields=="string"&&a.errors.fields})]}),n.jsxs(o.Flex,{justify:"end",gap:"2",children:[n.jsx(o.Button,{type:"button",variant:"soft",onClick:e,children:"Cancel"}),n.jsx(o.Button,{type:"submit",disabled:!a.isValid,children:"Save"})]})]})})]}),n.jsx(o.Tabs.Content,{value:"preview",children:n.jsx(Ce,{schema:p,onSubmit:ei})})]})})}));x.BooleanField=Y,x.BooleanInput=Ye,x.DateField=ge,x.DateInput=Xe,x.FieldSection=K,x.FormBrowser=Mt,x.FormBuilder=ti,x.FormRenderer=Ce,x.FormSubmissionBrowser=$t,x.FormSubmissionViewer=zt,x.MultiSelectField=ue,x.MultiSelectInput=st,x.MultiStringField=de,x.MultiStringInput=rt,x.NumberField=G,x.NumberInput=Qe,x.PatchField=Dt,x.PatchFormProvider=Vt,x.SelectField=ce,x.SelectInput=Re,x.StringField=k,x.StringInput=Je,x.TextField=R,x.TextInput=ke,x.deserialize=fe,x.deserializeField=_e,x.formRevisionToSchema=Oe,x.isConditionMet=Ne,x.useFieldInput=he,x.useFieldInputs=qe,x.valueIsFile=Ie,Object.defineProperty(x,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(x,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("react/jsx-runtime"),require("@overmap-ai/blocks"),require("formik"),require("react"),require("@hello-pangea/dnd"),require("@overmap-ai/core"),require("lodash.get"),require("lodash.set"),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"],n):(x=typeof globalThis<"u"?globalThis:x||self,n(x.forms={},x.jsxRuntime,x.blocks,x.formik,x.React,x.dnd,x.core,x.get,x.set,x.Xarrow))})(this,function(x,n,o,$,d,U,F,J,Le,Ke){"use strict";var ni=Object.defineProperty;var ri=(x,n,o)=>n in x?ni(x,n,{enumerable:!0,configurable:!0,writable:!0,value:o}):x[n]=o;var m=(x,n,o)=>(ri(x,typeof n!="symbol"?n+"":n,o),o);class Ye{constructor(i){m(this,"type");m(this,"identifier");m(this,"description");const{description:e=null,identifier:t,type:r}=i;this.identifier=t,this.description=e,this.type=r}getId(){return this.identifier}static deserialize(i){throw new Error(`${this.name} must implement deserialize.`)}_serialize(){if(!this.identifier)throw new Error("Field identifier must be set before serializing.");return{type:this.type,identifier:this.identifier,description:this.description}}}class 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:i,children:e,severity:t,inputId:r,labelId:s,flexProps:c}=l;return n.jsx(o.Flex,{direction:"column",gap:"1",asChild:!0,...c,children:n.jsxs("label",{htmlFor:r,children:[n.jsx(o.Text,{severity:t,id:s,children:i}),e]})})},W=l=>{const{helpText:i,children:e,severity:t}=l;return n.jsxs(o.Flex,{direction:"column",gap:"1",children:[e,n.jsx(o.Flex,{direction:"column",children:n.jsx(o.Text,{size:"1",severity:t,className:me.description,children:i})})]})},j=l=>{const{id:i,field:e,formId:t,...r}=l,[s,c,u]=$.useField(e.getId()),{touched:a}=c,p=c.error??e.description,f=c.error?"danger":void 0,h=i??`${t}-${e.getId()}-input`,g=`${h}-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:p,severity:f,inputId:h,labelId:g,label:y,fieldProps:v,helpers:u,field:e},{...r,"aria-labelledby":g}]},yt=[!0,"true"],Ze=d.memo(function(i){const[{inputId:e,labelId:t,severity:r,helpText:s,label:c,fieldProps:u},a]=j(i),p=o.useSeverityColor(r),f=yt.includes(u.value);return n.jsx(W,{helpText:s,severity:r,children:n.jsx(q,{severity:r,inputId:e,labelId:t,label:c,flexProps:{direction:"row-reverse",justify:"end",align:"center",gap:"2"},children:n.jsx(o.Checkbox,{...a,...u,id:e,color:p,value:f.toString(),checked:f,onCheckedChange:u.onChange,onChange:void 0,onBlur:void 0})})})}),ee=class ee 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 ee(e)}getInput(e){return n.jsx(Ze,{...e,field:this})}};m(ee,"fieldTypeName","Checkbox"),m(ee,"fieldTypeDescription","Perfect for both optional and required yes/no questions."),m(ee,"Icon",o.CheckCircledIcon);let Z=ee;const Qe=d.memo(function(i){const[{inputId:e,labelId:t,severity:r,helpText:s,label:c,fieldProps:u,field:a},p]=j(i),f=o.useSeverityColor(r);return n.jsx(W,{helpText:s,severity:r,children:n.jsx(q,{severity:r,inputId:e,labelId:t,label:c,children:n.jsx(o.TextField.Input,{...p,...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 n.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 G=_;const Xe=d.memo(function(i){const[{inputId:e,labelId:t,severity:r,helpText:s,label:c,fieldProps:u},a]=j(i),p=o.useSeverityColor(r),f=u.value?u.value.split("T")[0]:"";return n.jsx(W,{helpText:s,severity:r,children:n.jsx(q,{severity:r,inputId:e,labelId:t,label:c,children:n.jsx(o.TextField.Input,{...a,...u,type:"date",id:e,color:p,value:f})})})}),te=class te 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 te(e)}getInput(e){return n.jsx(Xe,{field:this,...e})}};m(te,"fieldTypeName","Date"),m(te,"fieldTypeDescription","Allows specifying a date."),m(te,"Icon",o.CalendarIcon);let ge=te;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 G({label:"Minimum length",description:"Minimum number of characters",required:!1,identifier:"minimum_length",minimum:0,maximum:100,formValidators:[this._validateMin],integers:!0}),new G({label:"Maximum length",description:"Maximum number of characters",required:!1,identifier:"maximum_length",minimum:1,maximum:5e3,formValidators:[this._validateMax],integers:!0})]}getFieldValidators(){const e=super.getFieldValidators();return this.minLength&&e.push(t=>{if(this.minLength&&(!t||t.length<this.minLength))return!this.required&&!t?null:`Minimum ${this.minLength} character(s).`}),this.maxLength&&e.push(t=>{if(typeof t=="string"&&this.maxLength&&t.length>this.maxLength)return`Maximum ${this.maxLength} character(s).`}),e}_serialize(){if(!this.identifier)throw new Error("Field identifier must be set before serializing.");return{...super._serialize(),minimum_length:this.minLength,maximum_length:this.maxLength}}}m(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(i){const[{inputId:e,labelId:t,severity:r,helpText:s,label:c,fieldProps:u,field:a},p]=j(i),f=o.useSeverityColor(r);return n.jsx(W,{helpText:s,severity:r,children:n.jsx(q,{severity:r,inputId:e,labelId:t,label:c,children:n.jsx(o.TextField.Input,{...p,...u,type:a.inputType,id:e,color:f})})})}),ie=class ie 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 ie({...c,maxLength:t,minLength:r,inputType:s})}getInput(e){return n.jsx(Je,{field:this,...e})}};m(ie,"fieldTypeName","Short Text"),m(ie,"fieldTypeDescription","Short text fields can hold up to 500 characters on a single line."),m(ie,"Icon",o.InputIcon);let k=ie;const ke=d.memo(function(i){const[{inputId:e,labelId:t,severity:r,helpText:s,label:c,fieldProps:u},a]=j(i);return n.jsx(W,{helpText:s,severity:r,children:n.jsx(q,{severity:r,inputId:e,labelId:t,label:c,children:n.jsx(o.TextArea,{...a,...u,resize:"vertical",id:e,severity:r})})})}),ne=class ne extends ye{constructor(i){const e=i.maxLength?Math.min(5e3,i.maxLength):5e3,t=i.minLength?Math.min(i.minLength,e):void 0;super({...i,maxLength:e,minLength:t,type:"text"})}serialize(){return super._serialize()}static deserialize(i){if(i.type!=="text")throw new Error("Type mismatch.");const{maximum_length:e,minimum_length:t,...r}=i;return new ne({...r,maxLength:e,minLength:t})}getInput(i){return n.jsx(ke,{field:this,...i})}};m(ne,"fieldTypeName","Paragraph"),m(ne,"fieldTypeDescription","Paragraph fields can hold up to 5000 characters and can have multiple lines."),m(ne,"Icon",o.RowsIcon);let R=ne;const Re=d.memo(function(i){const[{inputId:e,labelId:t,severity:r,helpText:s,label:c,fieldProps:u,field:a},p]=j(i),{onChange:f,onBlur:h}=u,g=d.useMemo(()=>a.options.map(v=>({value:v.value,itemContent:v.label})),[a.options]),y=d.useCallback(v=>{f(v),h(v)},[f,h]);return n.jsx(W,{helpText:s,severity:r,children:n.jsx(q,{severity:r,inputId:e,labelId:t,label:c,children:n.jsx(o.Select,{items:g,...u,onValueChange:y,placeholder:"Select one...",id:e,severity:r,...p})})})}),xe=(l="",i=[])=>({type:"section",fields:i,identifier:l,label:null,condition:null,conditional:!1}),xt=l=>{if(!l)return;const i=l.fields;let e=[];const t=[];for(const r of i)r.type==="section"?(e.length>0&&(t.push(xe(`AUTO_section-${i.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 Pe(l,i,e){const t=Array.from(l),[r]=t.splice(i,1);if(!r)throw new Error("Could not find field to reorder.");return t.splice(e,0,r),t}function vt(l,i,e){const t=Array.from(l);return t[i]=e,t}function et(l,i,e){const t=Array.from(l??[]);return t.splice(i,0,e),t}function ve(l,i){const e=Array.from(l);return e.splice(i,1),e}const tt=(l,i)=>{if(typeof l=="string"&&l.length>0)return l;const e=new Date;return`${F.slugify(i)}-${e.getTime()}`},it=(l,i)=>{if(!i)return null;for(const e of l)if(e.type==="section"){const t=it(e.fields,i);if(t)return t}else if(e.identifier===i)return e;return null},we=(l,i)=>l.filter((e,t)=>t<i).flatMap(e=>e.fields),nt=l=>l.flatMap(i=>i.type==="section"?[...i.fields.map(e=>e.label),i.label]:i.label).filter(i=>i!==null),$e=(l,i)=>{let e=1,t=`${l} (${e})`;for(;i.includes(t);)t=`${l} (${++e})`;return t},rt=d.memo(function(i){const[{inputId:e,labelId:t,severity:r,helpText:s,label:c,fieldProps:u},a]=j(i),p=o.useSeverityColor(r),f=d.useMemo(()=>Array.isArray(u.value)?u.value:[],[u.value]),{onChange:h,onBlur:g}=u,y=`${e}-droppable`,{disabled:v}=a,[T,b]=d.useState(""),[C,w]=d.useState(""),P=C||s,z=C?"red":p,I=d.useCallback(E=>{h(E),g(E)},[h,g]),M=d.useCallback(E=>{f.findIndex(N=>N.value===E.target.value.trim())>=0?w("All options must be unique"):E.target.value?w(""):w("Option cannot be empty"),b(E.target.value)},[b,f]),O=d.useCallback(()=>{if(C)return;if(!T.trim())return w("Option cannot be empty");const E=T.trim();I([...f,{value:E,label:E}]),b("")},[T,C,I,f]),Q=d.useCallback(E=>{E.key==="Enter"&&(E.preventDefault(),O())},[O]),H=d.useCallback(E=>{I(ve(f,E))},[f,I]),Y=d.useCallback(E=>{if(!E.destination)return;const N=E.source.index,X=E.destination.index;I(Pe(f,N,X))},[I,f]);return n.jsx(U.DragDropContext,{onDragEnd:Y,children:n.jsxs(o.Flex,{direction:"column",gap:"2",children:[n.jsx(W,{helpText:P,severity:r,children:n.jsx(q,{severity:r,inputId:e,labelId:t,label:c,children:(!v||f.length===0)&&n.jsxs(o.Flex,{gap:"2",children:[n.jsx(o.Box,{grow:"1",children:n.jsx(o.TextField.Input,{placeholder:"Press enter to add a new option",...a,...u,value:T,onChange:M,onKeyDown:Q,id:e,color:z,onBlur:void 0})}),n.jsx(o.IconButton,{type:"button","aria-label":"Add option",disabled:!!C||v,onClick:O,children:n.jsx(o.PlusIcon,{})})]})})}),n.jsx(U.Droppable,{droppableId:y,children:E=>n.jsxs(o.Flex,{...E.droppableProps,ref:E.innerRef,direction:"column",children:[f.map((N,X)=>n.jsx(U.Draggable,{draggableId:`${N.value}-draggable`,index:X,isDragDisabled:v,children:({draggableProps:Se,dragHandleProps:Ae,innerRef:Ee})=>n.jsx(o.Flex,{...Ae,...Se,ref:Ee,gap:"2",align:"center",justify:"between",mb:"1",asChild:!0,children:n.jsxs(o.Badge,{color:"gray",size:"2",children:[n.jsx("span",{children:N.label}),n.jsx(o.IconButton,{size:"small",variant:"ghost",type:"button","aria-label":"Delete option",severity:"info",disabled:v,onClick:()=>H(X),children:n.jsx(o.Cross1Icon,{})})]})})},N.value)),E.placeholder]})})]})})}),re=class re 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 n.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 re(e)}};m(re,"fieldTypeName","Multi-string"),m(re,"fieldTypeDescription","Allows the user to provide multiple unique strings."),m(re,"Icon",o.ListBulletIcon);let de=re;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 oe=class oe extends ot{constructor(i){super({...i,type:"select"})}getValueFromChangeEvent(i){return typeof i=="string"?i:i.target.value}serialize(){return super._serialize()}static deserialize(i){if(i.type!=="select")throw new Error("Type mismatch.");return new oe(i)}getInput(i){return n.jsx(Re,{field:this,...i})}};m(oe,"fieldTypeName","Dropdown"),m(oe,"fieldTypeDescription","Allows the user to select a single option from a list of options."),m(oe,"Icon",o.DropdownMenuIcon);let ce=oe;const wt=l=>l?Array.isArray(l)?l:[l]:[],st=d.memo(function(i){const[{inputId:e,labelId:t,severity:r,helpText:s,label:c,fieldProps:u,field:a},p]=j(i),{onChange:f,onBlur:h}=u,g=d.useMemo(()=>wt(u.value),[u.value]),y=d.useCallback(v=>{f(v),h(v)},[f,h]);return n.jsx(W,{helpText:s,severity:r,children:n.jsx(q,{severity:r,inputId:e,labelId:t,label:c,children:n.jsx(o.MultiSelect,{value:g,onValueChange:y,options:a.options,name:u.name,placeholder:"Select one or more...",id:e,severity:r,...p})})})}),se=class se extends ot{constructor(i){super({...i,type:"multi-select"})}getValueFromChangeEvent(i){if(Array.isArray(i))return i;throw new Error("Expected an array.")}isBlank(i){return super.isBlank(i)||i.length===0}serialize(){return super._serialize()}static deserialize(i){if(i.type!=="multi-select")throw new Error("Type mismatch.");return new se(i)}getInput(i){return n.jsx(st,{field:this,...i})}};m(se,"fieldTypeName","Multi-select"),m(se,"fieldTypeDescription","Allows the user to select a multiple options from a list of options."),m(se,"Icon",o.CheckboxIcon);let ue=se;const Ft=d.memo(function({field:i,...e}){const[{value:t}]=$.useField(i.options.clonedFieldIdentifier),r=d.useMemo(()=>{const s=i.options.getFieldToClone(t);return s?fe(s):null},[i.options,t]);return he(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 n.jsx(t,{field:this,...e})}}m(Fe,"fieldTypeName","Custom"),m(Fe,"fieldTypeDescription","Allows re-rendering of field already in the form");class It extends Fe{constructor(i){super(i,Ft)}}const bt=d.memo(function(i){const{field:e,...t}=i,{label:r,description:s,fields:c,condition:u}=e,{values:a,setFieldValue:p}=$.useFormikContext(),f=u!=null&&u.identifier?J(a,u.identifier):void 0,h=d.useMemo(()=>Ne(u,f),[u,f]);d.useEffect(()=>{if(!h)for(const y of c)p(y.getId(),"").then()},[h,c,p]);const g=qe(c,t);return h?r?n.jsx(o.Card,{children:n.jsxs(o.Flex,{direction:"column",gap:"3",children:[n.jsxs(o.Flex,{direction:"column",children:[n.jsx(o.Heading,{as:"h3",size:"3",children:r}),n.jsx(o.Text,{className:me.description,children:s})]}),g]})}):g:null}),le=class le 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 le({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 It({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 le({...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(J(e,s),e);c&&Le(t,r.getId(),c)}return t}getInput(e){return n.jsx(bt,{field:this,...e})}};m(le,"fieldTypeName","Section"),m(le,"fieldTypeDescription","Sections can be useful for grouping fields together. They can also be conditionally shown or hidden.");let K=le;const Ct={previewImage:"_previewImage_1ig84_1"},De=l=>{const i=["byte","kilobyte","megabyte"];let e=l,t=0;for(;e>1024&&t<i.length-1;)e/=1024,t++;return new Intl.NumberFormat([],{maximumFractionDigits:2,style:"unit",unit:i[t]}).format(e)},Tt=d.memo(function(i){var z;const[{inputId:e,labelId:t,severity:r,helpText:s,label:c,fieldProps:u,field:a},p]=j(i),{onChange:f}=u,h=o.useSeverityColor(r),g=d.useRef(null),{value:y}=u,v=d.useMemo(()=>s||(a.maxFileSize?`Maximum file size: ${De(a.maxFileSize)}`:null),[a.maxFileSize,s]),T=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",P=a.maxFiles>1?C:w;return n.jsxs(o.Flex,{direction:"column",gap:"2",children:[n.jsx(W,{helpText:v,severity:r,children:n.jsxs(q,{severity:r,inputId:e,labelId:t,label:c,children:[n.jsx(o.Flex,{direction:"row",gap:"2",children:n.jsx(o.Box,{width:"max-content",asChild:!0,children:n.jsxs(o.Button,{...p,onClick:T,children:[n.jsx(o.UploadIcon,{})," ",P]})})}),n.jsx("input",{...p,type:"file",ref:g,id:e,accept:(z=a.extensions)==null?void 0:z.join(","),multiple:a.maxFiles>1,color:h,style:{display:"none"},...u,value:""})]})}),Array.isArray(y)&&y.length>0&&n.jsx(o.Flex,{direction:"column",gap:"2",children:y.map((I,M)=>n.jsx(St,{field:a,file:I,onRemove:()=>b(M),disabled:p.disabled},M))})]})}),St=d.memo(function({file:i,field:e,onRemove:t,disabled:r}){const[s,c]=d.useState(null),u=d.useMemo(()=>s&&e.getError([s]),[e,s]),{url:a,name:p,size:f}=d.useMemo(()=>{let h=null,g,y;return s!=null&&s.type.startsWith("image/")&&(h=URL.createObjectURL(s)),s?(g=s.name,y=De(s.size)):(g="Downloading...",y="..."),{url:h,name:g,size:y}},[s]);return d.useEffect(()=>{i instanceof Promise?i.then(c):c(i)},[i]),n.jsx(o.Card,{children:n.jsxs(o.Flex,{direction:{initial:"column",sm:"row"},gap:"3",justify:"between",children:[n.jsxs(o.Flex,{direction:"row",gap:"3",align:"center",grow:"1",shrink:"0",children:[n.jsx(o.IconButton,{severity:"info",variant:"outline","aria-label":`Remove ${p}`,disabled:r,onClick:t,children:n.jsx(o.Cross1Icon,{})}),n.jsxs(o.Flex,{direction:"column",gap:"1",children:[n.jsx(o.Text,{children:p}),n.jsx(o.Text,{size:"1",children:f}),u&&n.jsx(o.Text,{size:"1",severity:"danger",children:u})]})]}),a&&n.jsx("img",{className:Ct.previewImage,src:a,alt:p})]})})}),lt=50*1024*1024,ae=class ae 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 G({label:"How many files can be uploaded?",description:"By default, only one file can be uploaded.",required:!1,minimum:1,maximum:10,identifier:"maximum_files"}),new G({label:"What is the maximum size of each file?",description:"Maximum file size in bytes.",required:!1,identifier:"maximum_size",minimum:1,maximum: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 ${De(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 ae(e)}getInput(e){return n.jsx(Tt,{field:this,...e})}};m(ae,"fieldTypeName","Upload"),m(ae,"fieldTypeDescription","Allows a file to be uploaded."),m(ae,"Icon",o.UploadIcon);let Ve=ae;const Be={date:ge,number:G,boolean:Z,select:ce,string:k,text:R,custom:Fe,upload:Ve,"multi-string":de,"multi-select":ue},_e=l=>{const i=l.type;return Be[i].deserialize(l)},fe=l=>l.type==="section"?K.deserialize(l):_e(l);function Oe(l,i={}){const{readonly:e=!1}=i;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(i=>i instanceof File||i instanceof Promise))}function Ne(l,i){if(!l)return!0;if(Ie(i)||Ie(l.value))throw new Error("Conditions do not support file uploads");const e=Array.isArray(i)?i.map(r=>typeof r=="string"?r:r.value):i,t=Array.isArray(l.value)?l.value.map(r=>typeof r=="string"?r:r.value):l.value;if(Array.isArray(t)&&Array.isArray(e)){for(const r of t)if(!e.includes(r))return!1;return!0}return t===i}const he=(l,i)=>d.useMemo(()=>!i||!l?null:l.getInput(i),[l,i]),qe=(l,i)=>{const e=d.useMemo(()=>l.map(t=>n.jsx("div",{children:t.getInput(i)},t.getId())),[l,i]);return n.jsx(o.Flex,{direction:"column",gap:"2",children:e})},be=l=>Object.keys(l).length>0,at=async(l,i)=>{const e={};for(const t of l.fields)if(t instanceof K){if(t.condition){const{identifier:r}=t.condition;if(!Ne(t.condition,J(i,r)))continue}Object.assign(e,t.getErrors(i))}else{if(!(t instanceof V))throw new Error("Invalid field type");const r=t.getId(),s=t.getError(J(i,r),i);s&&Le(e,r,s)}if(be(e))return e},At=[null,void 0],We=(l,i)=>l.reduce((e,t)=>t instanceof K?{...e,...We(t.fields,i)}:(At.includes(J(e,t.getId()))&&Le(e,t.getId(),""),e),i),Et=()=>{throw new Error("onSubmit must be provided if form is not readonly.")},Ce=d.memo(d.forwardRef((l,i)=>{const{schema:e,values:t={},onSubmit:r=Et,submitText:s="Submit",cancelText:c,onCancel:u,onDirty:a,hideTitle:p=!e.title,hideDescription:f,className:h}=l,{readonly:g}=e.meta,y=d.useMemo(()=>crypto.randomUUID(),[]),v=$.useFormik({initialValues:We(e.fields,t),onSubmit:r,validate:P=>at(e,P),validateOnBlur:!1,validateOnChange:!1}),{dirty:T}=v,b=d.useMemo(()=>typeof e.title=="string"?n.jsx(o.Heading,{children:e.title}):e.title,[e.title]),C=d.useMemo(()=>typeof e.description=="string"?n.jsx(o.Text,{className:me.description,children:e.description}):e.description,[e.description]),w=qe(e.fields,{formId:y,disabled:g});return d.useEffect(()=>{T&&a&&a()},[T,a]),n.jsx($.FormikProvider,{value:v,children:n.jsx(o.Flex,{ref:i,direction:"column",gap:"2",className:h,asChild:!0,children:n.jsxs("form",{id:y,onSubmit:v.handleSubmit,children:[!p&&n.jsx(o.Card,{children:n.jsxs(o.Flex,{direction:"column",gap:"1",children:[b,!f&&C]})}),w,!g&&n.jsxs(o.Flex,{justify:"end",gap:"2",children:[c&&n.jsx(o.Button,{type:"button",variant:"soft",onClick:u,children:c}),n.jsx(o.Button,{type:"submit",disabled:!v.isValid,children:s})]})]})})})})),zt=d.memo(d.forwardRef((l,i)=>{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 p=F.selectSubmissionAttachments(e.offline_id)(c.store.getState())??[],f={};for(const h of p){const g=c.files.fetchFileFromUrl(h.file,h.file_sha1,h.file_name).then(v=>{if(!v.success)throw new Error(`Failed to download attachment ${h.file_name}.`);return v.body}),y=f[h.field_identifier];y?y.push(g):f[h.field_identifier]=[g]}return{...e.values,...f}},[c.files,c.store,e.offline_id,e.values]);return n.jsx(Ce,{ref:i,schema:u,values:a,hideDescription:!t,hideTitle:!r})})),dt={favoriteIcon:"_favoriteIcon_1bixi_1",regularIcon:"_regularIcon_1bixi_9"},je="organization:",He="user:",Mt=d.memo(d.forwardRef((l,i)=>{const{maxResults:e=20,...t}=l,[r,s]=d.useState(""),[c,u]=d.useState(""),{sdk:a}=F.useSDK(),p=d.useMemo(()=>{const w={maxResults:e,searchTerm:r};return c&&(c.startsWith(je)?w.owner_organization=parseInt(c.slice(je.length)):c.startsWith(He)&&(w.owner_user=parseInt(c.slice(He.length)))),w},[r,e,c]),f=F.useAppSelector(F.selectFilteredUserForms(p))??[],h=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(),P={};for(const z of Object.values(h)){const I=F.selectOrganization(z.owner_organization||-1)(w);I&&(P[`${je}${I.id}`]=I.name);const M=F.selectUser(z.owner_user||-1)(w);M&&(P[`${He}${M.id}`]=M.username)}return Object.entries(P).map(([z,I])=>({itemContent:I,value:z}))},[h,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 n.jsxs(o.Flex,{ref:i,direction:"column",gap:"2",children:[n.jsxs(o.Flex,{gap:"2",grow:"1",children:[n.jsx(o.Box,{grow:"1",asChild:!0,children:n.jsx(o.TextField.Root,{size:"3",children:n.jsx(o.TextField.Input,{placeholder:"Filter",value:r,onChange:v})})}),n.jsx(o.Select,{items:y,value:c,onValueChange:u,placeholder:"Owner",size:"large"})]}),f.length>0&&n.jsx(o.ButtonList.Root,{children:f.map(w=>n.jsx(Lt,{...t,form:w,handleToggleFavorite:()=>g(w)},w.offline_id))}),n.jsx(o.Box,{px:"3",children:n.jsx(o.Text,{size:"2",severity:"info",children:C})})]})})),Lt=l=>{var g;const{form:i,onSelectForm:e,isFavoriteEditable:t,handleToggleFavorite:r}=l,s=(g=F.useAppSelector(F.selectOrganization(i.owner_organization||-1)))==null?void 0:g.name,c=F.useAppSelector(F.selectUser(i.owner_user||-1)),u=F.useAppSelector(F.selectCurrentUser).id,a=!!c&&c.id===u,p=s??(a?"You":c==null?void 0:c.username)??"Unknown",f=d.useCallback(y=>{y.stopPropagation(),r()},[r]),h=n.jsx(o.ButtonList.Item,{onClick:()=>e(i),asChild:!0,children:n.jsxs(o.Flex,{justify:"between",gap:"2",py:"2",px:"3",...o.divButtonProps,children:[n.jsxs(o.Flex,{grow:"1",align:"center",gap:"2",children:[n.jsx(o.IconButton,{className:F.classNames(i.favorite?dt.favoriteIcon:dt.regularIcon),variant:"ghost",onClick:f,"aria-label":i.favorite?"Favorite form":"Standard form",disabled:!t,children:i.favorite?n.jsx(o.StarFilledIcon,{}):n.jsx(o.StarIcon,{})}),n.jsx(o.Text,{noWrap:!0,children:i.latestRevision.title}),i.latestRevision.description&&n.jsx(o.QuestionMarkCircledIcon,{})]}),p&&n.jsxs(o.Flex,{align:"center",gap:"2",children:[n.jsx(o.PersonIcon,{})," ",p]})]})});return i.latestRevision.description?n.jsx(o.Tooltip,{content:i.latestRevision.description,children:h},i.offline_id):h},ct={submissionsContainer:"_submissionsContainer_9iirt_1",stopHorizontalOverflow:"_stopHorizontalOverflow_9iirt_6"},Pt=d.memo(function(i){var w;const{submission:e,onSubmissionClick:t,compact:r,labelType:s,rowDecorator:c}=i,u=F.useAppSelector(F.selectCurrentUser),a=F.useAppSelector(F.selectUser("created_by"in e?e.created_by:u.id)),p=Ue(e),f=F.isToday(p)?p.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):F.getLocalDateString(p),h=F.useAppSelector(F.selectFormRevision(e.form_revision));if(!h)throw new Error(`Could not find revision ${e.form_revision} for submission ${e.offline_id}.`);const g=(w=F.useAppSelector(F.selectLatestFormRevision(h.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())??"?",T=h.revision===g,b=d.useCallback(()=>{t&&t({submission:e})},[e,t]),C=n.jsx(o.ButtonList.Item,{onClick:b,asChild:!0,children:n.jsxs(o.Flex,{grow:"1",width:"100%",p:"2",gap:"2",justify:"between",children:[n.jsxs(o.Flex,{gap:"2",align:"center",className:ct.stopHorizontalOverflow,children:[n.jsx(o.Avatar,{src:y,size:"1",fallback:v}),n.jsx(o.Text,{size:"2",noWrap:!0,children:s==="creator"?(a||u).username:h.title})]}),n.jsxs(o.Flex,{gap:"2",align:"center",children:[!r&&(h.revision?n.jsx(o.Badge,{variant:"soft",severity:T?"primary":"info",children:r?h.revision.toString():`Revision #${h.revision}`}):!!g&&n.jsx(o.Badge,{children:"Original"})),n.jsx(o.Text,{size:"2",noWrap:!0,children:f})]})]})});return c?c(e,C):C}),Ue=l=>{const i="created_at"in l?l.created_at:l.submitted_at;return new Date(i)},$t=d.memo(function(i){const{formId:e,submissions:t,compact:r=!1,className:s,after:c,variant:u="outline",...a}=i;if(!!e==!!t)throw new Error("Either formId or submissions must be provided, but not both.");const p=F.useAppSelector(t?()=>t:F.selectSubmissionsForForm(e)),f=d.useMemo(()=>p==null?void 0:p.sort((h,g)=>Ue(g).getTime()-Ue(h).getTime()),[p]);return n.jsx(o.ButtonList.Root,{className:F.classNames(ct.submissionsContainer,s),size:"small",variant:u,before:!r&&n.jsxs(o.Text,{severity:"info",children:["There are ",((p==null?void 0:p.length)||0).toString()," submissions of this form."]}),after:c,children:f==null?void 0:f.map((h,g)=>n.jsx(Pt,{submission:h,compact:r,...a},g))})}),Dt=d.memo(function(i){const{name:e,render:t}=i,{submitForm:r}=$.useFormikContext(),[s,c,u]=$.useField(e);return d.useMemo(()=>{const a=p=>u.setValue(p,!1);return t({value:s.value,setValue:a,patchValue:r})},[r,u,s.value,t])}),Vt=d.memo(d.forwardRef((l,i)=>{const{children:e,schema:t,values:r,onPatch:s,onError:c,...u}=l,a=d.useMemo(()=>We(t.fields,r),[t.fields,r]),p=d.useCallback(v=>{const T={};for(const b in v){const C=v[b];C!==a[b]&&C!==void 0&&(T[b]=C)}be(T)&&s(T)},[a,s]),f=d.useCallback(async v=>{const T=await at(t,v);return T&&c(T),T},[t,c]),h=$.useFormik({initialValues:a,onSubmit:p,validate:f,validateOnBlur:!1,validateOnChange:!1}),{errors:g,resetForm:y}=h;return d.useEffect(()=>{be(g)&&y({values:a,errors:{}})},[g,a,y]),n.jsx($.FormikProvider,{value:h,children:n.jsx("form",{...u,ref:i,onSubmit:h.handleSubmit,children:e})})})),ut={...Be,section:K},Bt=d.memo(function(i){const{field:e,setFieldType:t}=i,r=e.fieldTypeName,s=e.fieldTypeDescription,c=e.Icon;return n.jsxs(o.Flex,{gap:"4",align:"center",children:[n.jsx(o.Button,{type:"button",variant:"surface",onClick:t,style:{width:"135px"},children:n.jsxs(o.Flex,{gap:"3",align:"center",grow:"1",children:[n.jsx(c,{}),r]})}),n.jsx(o.Text,{children:s})]})}),ft=[["string","text"],["select","multi-select","upload"],["boolean","date","number","multi-string"]],_t=ft.length-1,Ot=d.memo(function(i){const{setFieldType:e}=i;return n.jsx(o.Flex,{direction:"column",gap:"3",children:ft.map((t,r)=>n.jsxs(o.Flex,{direction:"column",gap:"3",children:[n.jsx(o.Flex,{direction:"column",gap:"2",children:t.map(s=>n.jsx(Bt,{field:Be[s],setFieldType:()=>e(s)},s))}),r<_t&&n.jsx(o.Separator,{size:"4"})]},r))})}),Nt=l=>i=>{if(!(!i||typeof i!="string")&&l.includes(i.trim()))return"This name is already taken."},qt=(l,i)=>{const e=[new k({label:"Label",required:!0,maxLength:200,identifier:"label",fieldValidators:[Nt(l)]}),new R({label:"Description",required:!1,maxLength:1e3,identifier:"description"})];return i==="section"?e:[...e,new Z({label:"Required",description:null,required:!1,identifier:"required"})]},Wt=d.memo(function(i){const{fieldType:e,handleCancel:t,handleCreateField:r,defaultField:s,conditionalSourceFields:c}=i,u=ut[e],a=$.useFormikContext(),p=d.useMemo(()=>{const f=nt(a.values.fields).filter(g=>g!==(s==null?void 0:s.label));let h=qt(f,e);if(u===K){if(c===void 0)throw new Error("Conditional source fields must be provided when changing sections.");h=h.concat(u.getFieldCreationSchema(c))}else{if(!(u.prototype instanceof V))throw new Error(`Field must be an instance of BaseField. Got ${u}.`);h=[...h,...u.getFieldCreationSchema()]}return{fields:h,meta:{readonly:!1},title:null}},[a.values.fields,e,u,s==null?void 0:s.label,c]);return n.jsx(Ce,{schema:p,values:s,onSubmit:r,cancelText:s?void 0:"Back",onCancel:t})}),pe=d.memo(function(i){const{parentPath:e,index:t,children:r,initial:s,editing:c,conditionalSourceFields:u}=i,[a,p]=d.useState(),f=(s==null?void 0:s.type)??a,h=f?ut[f].fieldTypeName:void 0,{setFieldValue:g,values:y}=$.useFormikContext();if(c&&!s)throw new Error("Initial field must be provided if editing is true.");const v=!f&&!c&&!s,T=v?"Choose a field type":`${h} settings`,b=v?"Select a field type to add to this section.":(h==null?void 0:h.toLowerCase())==="section"?"Customize your section":`Customize your ${h==null?void 0:h.toLowerCase()} field.`,C=d.useCallback(()=>p(void 0),[]),w=d.useCallback(I=>{p(void 0),I()},[]),P=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 Q=fe({type:f,...I,identifier:tt(I.identifier,O)}).serialize(),H=J(y,e);if(H===void 0)throw new Error("Parent path must point to an existing field.");let Y;if(!Array.isArray(H))throw new Error("Parent path must point to an array.");c?Y=vt(H,t,Q):Y=et(H,t,Q),g(e,Y).then(),M()},[c,f,y,e,g,t]),z=d.useCallback(I=>v?n.jsx(Ot,{setFieldType:p}):n.jsx(Wt,{conditionalSourceFields:u,handleCancel:C,handleCreateField:M=>P(M,I),fieldType:f,defaultField:s}),[u,C,P,s,v,f]);return n.jsx(o.Dialog,{onCloseInterrupt:w,title:T,description:b,content:z,children:r})}),jt=({children:l})=>n.jsx(n.Fragment,{children:l}),ht=d.memo(function(i){const{remove:e,editProps:t,insertAfterProps:r,duplicateProps:s,type:c}=i,u=d.useMemo(()=>[{Wrapper:pe,wrapperProps:t,Icon:o.Pencil1Icon,text:"Edit"},{Icon:o.TrashIcon,buttonProps:{onClick:e},text:"Delete"},{Wrapper:pe,wrapperProps:s,Icon:o.CopyIcon,text:"Duplicate"},{Wrapper:pe,wrapperProps:r,Icon:o.PlusIcon,text:`Add ${c==="section"?"section":"field"}`}],[s,t,r,e,c]);return n.jsx(o.Box,{display:"block",children:n.jsx(o.DropdownMenu,{trigger:n.jsx(o.IconButton,{variant:"ghost","aria-label":"Actions menu",children:n.jsx(o.DotsVerticalIcon,{})}),closeOnSelect:!1,items:u.map(a=>{var f;const p=a.Wrapper??jt;return{...a.buttonProps,onSelect:(f=a.buttonProps)==null?void 0:f.onClick,content:n.jsx(p,{...a.wrapperProps,children:n.jsxs(o.Flex,{gap:"2",align:"center",children:[n.jsx(a.Icon,{}),a.text]})})}}).filter(a=>a!==null)})})}),Te="form-builder",Ht=d.memo(function(i){const{field:e,index:t,sectionIndex:r,takenLabels:s,remove:c}=i,u=d.useMemo(()=>fe(e),[e]),a=he(u,{formId:Te,disabled:!0}),p=d.useCallback(y=>{if(y.label===null)throw new Error(`Expected a label for field ${y.identifier}`);return{...y,label:$e(y.label,s),identifier:""}},[s]),f=d.useMemo(()=>({index:t,parentPath:`fields.${r}.fields`,initial:e,editing:!0}),[e,t,r]),h=d.useMemo(()=>({parentPath:`fields.${r}.fields`,index:t+1,initial:p(e)}),[p,e,t,r]),g=d.useMemo(()=>({parentPath:`fields.${r}.fields`,index:t+1,initial:void 0}),[t,r]);return n.jsx(U.Draggable,{draggableId:e.identifier,index:t,children:y=>n.jsx(o.Card,{ref:y.innerRef,...y.draggableProps,...y.dragHandleProps,id:`${e.identifier}-card`,mb:"4",children:n.jsxs(o.Flex,{gap:"4",justify:"between",align:"center",children:[a,n.jsx(ht,{remove:c,editProps:f,duplicateProps:h,insertAfterProps:g})]})})})}),Ut=l=>{const{identifier:i,condition:e}=l,t={primary:"var(--gray-a4)",hover:"var(--primary-color)"},[r,s]=d.useState(t.primary),c=d.useCallback(()=>{s(t.hover)},[t.hover]),u=d.useCallback(()=>{s(t.primary)},[t.primary]);return e?n.jsxs(n.Fragment,{children:[n.jsx(Ke,{start:`${i}-card`,end:`${i}-floating-point`,startAnchor:"right",endAnchor:"left",color:r,strokeWidth:1,path:"straight",showHead:!1,arrowBodyProps:{pointerEvents:"stroke",onMouseEnter:c,onMouseLeave:u}}),n.jsx(Ke,{start:`${i}-floating-point`,end:`${e.identifier}-card`,startAnchor:"left",endAnchor:"right",color:r,strokeWidth:1,path:"grid",gridBreak:"0",showHead:!1,arrowBodyProps:{pointerEvents:"stroke",onMouseEnter:c,onMouseLeave:u}})]}):null},Gt=d.memo(function(i){var Q,H,Y,E,N,X,Se,Ae,Ee;const{field:e,index:t,dropState:r,conditionalFieldCounts:s}=i,c=(Q=r[e.identifier])==null?void 0:Q.disabled,{setFieldValue:u,values:a}=$.useFormikContext(),p=o.useAlertDialog(),f=nt(a.fields),h=d.useCallback((S,A)=>{for(const D of S){const L=A.indexOf(D);u(`fields.${L}.condition`,null).then(),u(`fields.${L}.conditional`,!1).then()}},[u]),g=d.useCallback(S=>{var L;const A=e.fields[S];if(!A)throw new Error("Could not find field to remove.");const D=[];for(const B of a.fields)((L=B.condition)==null?void 0:L.identifier)===A.identifier&&D.push(B);return{removing:A,affectedSections:D,action:()=>u(`fields.${t}.fields`,ve(e.fields,S))}},[e.fields,a.fields,u,t]),y=d.useCallback(S=>{const{affectedSections:A,action:D,removing:L}=g(S),B=()=>{D().then(),h(A,a.fields)};if(A.length>0){const Ge=A.map(ze=>ze.label).join(", ");return p({title:"Remove condition?",description:`${L.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()},[g,h,a.fields,p]),v=d.useCallback(()=>{const A=e.fields.map((Me,ii)=>g(ii)).flatMap(Me=>Me.affectedSections),D=A.length?"Remove fields and conditions?":"Remove fields?",L=e.fields.length,B=A.map(Me=>Me.label).join(", "),Ge=A.length?`Deleting this section will remove the ${L} field(s) it contains and will remove the conditions from following sections: ${B}`:`Deleting this section will remove the ${L} field(s) it contains.`,ze=ve(a.fields,t),gt=()=>u("fields",ze);if(A.length>0)return p({title:D,description:Ge,severity:"danger",actionText:"Remove",onAction:()=>{gt().then(()=>{h(A,ze)})}});gt().then()},[e.fields,a.fields,t,g,u,p,h]),T=d.useCallback(S=>{if(S.label===null)throw new Error(`Expected a label for field ${S.identifier}`);const A=$e(S.label,f),D=S.fields.map(L=>{const B=$e(L.label,f);return{...L,label:B,identifier:tt(void 0,B)}});return{...S,label:A,fields:D,identifier:""}},[f]),b=d.useMemo(()=>({index:t,parentPath:"fields",initial:e,editing:!0,conditionalSourceFields:we(a.fields,t)}),[e,t,a.fields]),C=d.useMemo(()=>({index:t+1,parentPath:"fields",initial:xe(),conditionalSourceFields:we(a.fields,t+1)}),[t,a.fields]),w=d.useMemo(()=>({parentPath:`fields.${t}.fields`,index:e.fields.length,initial:void 0}),[e.fields.length,t]),P=d.useMemo(()=>({index:t+1,parentPath:"fields",initial:T(e),conditionalSourceFields:we(a.fields,t+1)}),[T,e,t,a.fields]),z=d.useMemo(()=>{var S,A;return(A=it(a.fields,(S=e.condition)==null?void 0:S.identifier))==null?void 0:A.label},[(H=e.condition)==null?void 0:H.identifier,a.fields]),I=Array.isArray((Y=e.condition)==null?void 0:Y.value)?"contains all of":"equals";if(Ie((E=e.condition)==null?void 0:E.value))throw new Error("File values are not supported for conditions.");const M=Array.isArray((N=e.condition)==null?void 0:N.value)?(Se=(X=e.condition)==null?void 0:X.value)==null?void 0:Se.map(S=>typeof S=="string"?S:S.label).join(", "):(Ee=(Ae=e.condition)==null?void 0:Ae.value)==null?void 0:Ee.toString(),O=()=>{const A=s.filter(B=>B!==null).length,D=s[t]??0,L=3/A*D;return n.jsx("div",{id:`${e.identifier}-floating-point`,style:{width:`${3-L}%`,marginLeft:`${L}%`}})};return n.jsxs(o.Flex,{direction:"row",justify:"center",align:"center",mb:"4",children:[n.jsx(U.Draggable,{draggableId:e.identifier,index:t,children:S=>n.jsx(o.Card,{ref:S.innerRef,...S.draggableProps,...S.dragHandleProps,id:`${e.identifier}-card`,style:{flexGrow:"1"},children:n.jsxs(o.Flex,{gap:"3",justify:"between",align:"center",children:[n.jsxs(o.Flex,{direction:"column",gap:"2",grow:"1",children:[n.jsxs(o.Flex,{direction:"column",children:[n.jsx(o.Heading,{as:"h3",size:"3",children:e.label}),n.jsx(o.Text,{className:me.description,children:e.description})]}),e.condition&&n.jsx(o.Text,{size:"1",children:n.jsxs(o.Em,{children:["Display only if ",n.jsx(o.Strong,{children:z})," ",I," ",n.jsx(o.Strong,{children:M})]})}),n.jsx(U.Droppable,{droppableId:e.identifier,type:"SECTION",isDropDisabled:c,children:A=>n.jsxs(o.Flex,{ref:A.innerRef,...A.droppableProps,direction:"column",gap:"0",children:[e.fields.map((D,L)=>n.jsx(Ht,{field:D,index:L,sectionIndex:t,remove:()=>y(L),takenLabels:f},D.identifier)),A.placeholder,n.jsx(pe,{...w,children:n.jsxs(o.Button,{type:"button",variant:"outline",children:[n.jsx(o.PlusIcon,{})," Add a field"]})})]})})]}),n.jsx(ht,{remove:v,insertAfterProps:C,editProps:b,duplicateProps:P,type:"section"})]})})}),s.some(S=>S!==null)&&O(),e.condition&&n.jsx(Ut,{identifier:e.identifier,condition:e.condition})]})}),Kt=(l,i)=>{var t;const e={...l};switch(i.type){case"release":for(const r in e)e[r].disabled=!1;return e;case"hold":for(const r in e)(t=e[r])!=null&&t.conditionFields.has(i.fieldId)&&(e[r].disabled=!0);return e;case"update":return i.state}},Yt=(l,i)=>{if(i)for(let e=0;e<l.length;e++){const t=l[e];if(t){for(const r of t.fields)if(r.identifier===i)return e}}},pt=l=>{var e,t,r;const i={};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=i[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),i[c.identifier]={disabled:!1,conditionFields:a,conditionIndex:Yt(l,(r=c.condition)==null?void 0:r.identifier),index:s,label:c.label}}return i},mt=(l,i)=>{for(const[e,t]of Object.entries(l))if(t.identifier===i)return[t,e]},Zt=d.memo(function(){const{values:i,setFieldValue:e}=$.useFormikContext(),[t,r]=d.useReducer(Kt,i.fields,pt),{showInfo:s}=o.useToast();d.useEffect(()=>{r({type:"update",state:pt(i.fields)})},[r,i.fields]);const c=d.useCallback(f=>{f.type==="SECTION"&&r({type:"hold",fieldId:f.draggableId})},[]),u=d.useCallback(f=>{const{source:h,destination:g,type:y,reason:v,draggableId:T}=f;if(r({type:"release"}),!g||v==="CANCEL")return;if(y==="ROOT"){const z=t[T];if(!z)throw new Error("Could not find section context.");let I=typeof z.conditionIndex<"u"?Math.max(z.conditionIndex+1,g.index):g.index;for(const M of Object.values(t))M.conditionIndex===h.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",Pe(i.fields,h.index,I))}if(y!=="SECTION")throw new Error("Unexpected droppable type.");const[b,C]=mt(i.fields,h.droppableId)??[],[w,P]=mt(i.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`,Pe(b.fields,h.index,g.index)).then();else{const z=b.fields[h.index];if(!z)throw new Error("Could not find field to reorder.");e(`fields.${C}.fields`,ve(b.fields,h.index)).then(),e(`fields.${P}.fields`,et(w.fields,g.index,z)).then()}},[i.fields,e,t,s]),a=d.useMemo(()=>({index:i.fields.length,parentPath:"fields",initial:xe(),conditionalSourceFields:we(i.fields,i.fields.length)}),[i.fields]),p=()=>{let f=1;return i.fields.map(h=>h.conditional?f++:null)};return n.jsx(U.DragDropContext,{onDragStart:c,onDragEnd:u,children:n.jsx(U.Droppable,{droppableId:"droppable",type:"ROOT",children:f=>n.jsxs(o.Flex,{ref:f.innerRef,...f.droppableProps,direction:"column",gap:"0",children:[i.fields.map((h,g)=>n.jsx(Gt,{field:h,index:g,dropState:t,conditionalFieldCounts:p()},h.label)),f.placeholder,n.jsx(pe,{...a,children:n.jsxs(o.Button,{type:"button",variant:"outline",children:[n.jsx(o.PlusIcon,{})," Add a section"]})})]})})})}),Qt={title:"",description:"",fields:[]},Xt=new k({label:"Title",minLength:0,maxLength:100,required:!0,identifier:"title"}),Jt={formId:Te,placeholder:"Give your form a title."},kt=new R({label:"Description",minLength:0,maxLength:1e3,required:!1,identifier:"description"}),Rt={formId:Te,placeholder:"Explain the purpose of this form."},ei=()=>{alert("This is a form preview, your data will not be saved.")},ti=d.memo(d.forwardRef((l,i)=>{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=$.useFormik({initialValues:xt(r)??Qt,validate:u,onSubmit:y=>t(y),validateOnChange:!1,validateOnBlur:!1}),p=d.useMemo(()=>Oe(a.values),[a.values]),f=he(Xt,Jt),h=he(kt,Rt),g=d.useMemo(()=>typeof c=="object"?c:n.jsx(o.Heading,{children:c}),[c]);return n.jsx(o.Tabs.Root,{ref:i,defaultValue:"edit",children:n.jsxs(o.Flex,{direction:"column",gap:"2",children:[n.jsxs(o.Tabs.List,{children:[n.jsx(o.Tabs.Trigger,{value:"edit",children:"Edit"}),n.jsx(o.Tabs.Trigger,{value:"preview",children:"Preview"})]}),n.jsxs(o.Tabs.Content,{value:"edit",children:[g,n.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"," ",n.jsx("em",{children:"Preview"})," tab, but"," ",n.jsx("strong",{children:"field values entered on this page will not be saved."})]}),n.jsx(o.Flex,{asChild:!0,direction:"column",gap:"2",mt:"3",children:n.jsxs("form",{id:Te,onSubmit:a.handleSubmit,children:[n.jsxs($.FormikProvider,{value:a,children:[f,h,n.jsx(Zt,{}),n.jsx(o.Text,{severity:"danger",size:"1",children:typeof a.errors.fields=="string"&&a.errors.fields})]}),n.jsxs(o.Flex,{justify:"end",gap:"2",children:[n.jsx(o.Button,{type:"button",variant:"soft",onClick:e,children:"Cancel"}),n.jsx(o.Button,{type:"submit",disabled:!a.isValid,children:"Save"})]})]})})]}),n.jsx(o.Tabs.Content,{value:"preview",children:n.jsx(Ce,{schema:p,onSubmit:ei})})]})})}));x.BooleanField=Z,x.BooleanInput=Ze,x.DateField=ge,x.DateInput=Xe,x.FieldSection=K,x.FormBrowser=Mt,x.FormBuilder=ti,x.FormRenderer=Ce,x.FormSubmissionBrowser=$t,x.FormSubmissionViewer=zt,x.MultiSelectField=ue,x.MultiSelectInput=st,x.MultiStringField=de,x.MultiStringInput=rt,x.NumberField=G,x.NumberInput=Qe,x.PatchField=Dt,x.PatchFormProvider=Vt,x.SelectField=ce,x.SelectInput=Re,x.StringField=k,x.StringInput=Je,x.TextField=R,x.TextInput=ke,x.deserialize=fe,x.deserializeField=_e,x.formRevisionToSchema=Oe,x.isConditionMet=Ne,x.useFieldInput=he,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.15",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"main": "dist/forms.umd.cjs",
|
|
9
9
|
"module": "dist/forms.js",
|