@overmap-ai/forms 1.0.32 → 1.0.33-condition-optimizations.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/form/UUIDPromise/UUIDPromise.d.ts +3 -3
- package/dist/form/builder/Root.d.ts +1 -1
- package/dist/form/builder/components/FieldBuilder.d.ts +1 -1
- package/dist/form/conditions/BaseCondition/BaseCondition.d.ts +4 -2
- package/dist/form/conditions/BooleanFieldCondition/BooleanFieldCondition.d.ts +1 -1
- package/dist/form/conditions/CheckboxListFieldCondition/CheckboxListFieldCondition.d.ts +1 -1
- package/dist/form/conditions/ConditionManager/ConditionManager.d.ts +1 -1
- package/dist/form/conditions/ConditionManager/hooks.d.ts +1 -1
- package/dist/form/conditions/DateFieldCondition/DateFieldCondition.d.ts +2 -2
- package/dist/form/conditions/MultiSelectFieldCondition/MultiSelectFieldCondition.d.ts +1 -1
- package/dist/form/conditions/MultiStringFieldCondition/MultiStringFieldCondition.d.ts +1 -1
- package/dist/form/conditions/NumberFieldCondition/NumberFieldCondition.d.ts +1 -1
- package/dist/form/conditions/OTPFieldCondition/OTPFieldCondition.d.ts +1 -1
- package/dist/form/conditions/PassFailFieldCondition/PassFailFieldCondition.d.ts +1 -1
- package/dist/form/conditions/RadioFieldCondition/RadioFieldCondition.d.ts +1 -1
- package/dist/form/conditions/RatingFieldCondition/RatingFieldCondition.d.ts +1 -1
- package/dist/form/conditions/ScanFieldCondition/ScanFieldCondition.d.ts +1 -1
- package/dist/form/conditions/StringFieldCondition/StringFieldCondition.d.ts +1 -1
- package/dist/form/conditions/TextFieldCondition/TextFieldCondition.d.ts +1 -1
- package/dist/form/conditions/UploadFieldCondition/UploadFieldCondition.d.ts +2 -2
- package/dist/form/conditions/utils.d.ts +1 -3
- package/dist/form/fields/BaseField/BaseField.d.ts +1 -1
- package/dist/form/fields/BaseFormElement/BaseFormElement.d.ts +1 -1
- package/dist/form/fields/BaseOptionsField/BaseOptionsField.d.ts +1 -1
- package/dist/form/fields/BaseStringField/BaseStringField.d.ts +1 -1
- package/dist/form/fields/BooleanField/BooleanField.d.ts +1 -1
- package/dist/form/fields/BooleanField/BooleanInput.d.ts +1 -1
- package/dist/form/fields/CheckboxListField/CheckboxListField.d.ts +1 -1
- package/dist/form/fields/DateField/DateField.d.ts +1 -1
- package/dist/form/fields/DateField/DateInput.d.ts +1 -1
- package/dist/form/fields/FieldSection/FieldSection.d.ts +3 -3
- package/dist/form/fields/MultiSelectField/MultiSelectField.d.ts +1 -1
- package/dist/form/fields/MultiSelectField/MultiSelectInput.d.ts +1 -1
- package/dist/form/fields/MultiStringField/MultiStringField.d.ts +1 -1
- package/dist/form/fields/MultiStringField/MultiStringInput.d.ts +1 -1
- package/dist/form/fields/NumberField/NumberField.d.ts +1 -1
- package/dist/form/fields/NumberField/NumberInput.d.ts +1 -1
- package/dist/form/fields/OneTimePasswordField/OTPField.d.ts +1 -1
- package/dist/form/fields/OneTimePasswordField/typings.d.ts +1 -1
- package/dist/form/fields/PassFailField/PassFailField.d.ts +1 -1
- package/dist/form/fields/PassFailField/PassFailInput.d.ts +1 -1
- package/dist/form/fields/PassFailField/typings.d.ts +1 -1
- package/dist/form/fields/RadioField/RadioField.d.ts +1 -1
- package/dist/form/fields/RadioField/RadioInput.d.ts +1 -1
- package/dist/form/fields/RatingField/RatingField.d.ts +1 -1
- package/dist/form/fields/RatingField/RatingInput.d.ts +1 -1
- package/dist/form/fields/ScanField/ScanField.d.ts +1 -1
- package/dist/form/fields/ScanField/ScanInput.d.ts +1 -1
- package/dist/form/fields/SelectField/SelectField.d.ts +1 -1
- package/dist/form/fields/SelectField/SelectInput.d.ts +1 -1
- package/dist/form/fields/StringField/StringField.d.ts +1 -1
- package/dist/form/fields/StringField/StringInput.d.ts +1 -1
- package/dist/form/fields/TextField/TextField.d.ts +1 -1
- package/dist/form/fields/TextField/TextInput.d.ts +1 -1
- package/dist/form/fields/UploadField/UploadField.d.ts +1 -1
- package/dist/form/fields/UploadField/UploadInput.d.ts +1 -1
- package/dist/form/fields/components/InputWithLabel.d.ts +1 -1
- package/dist/form/fields/constants.d.ts +1 -1
- package/dist/form/fields/hooks.d.ts +1 -1
- package/dist/form/fields/typings.d.ts +3 -3
- package/dist/form/fields/utils.d.ts +1 -1
- package/dist/form/modifiers/conditionModifier.d.ts +3 -3
- package/dist/form/modifiers/typings.d.ts +2 -0
- package/dist/form/schema/FieldSchema.d.ts +1 -1
- package/dist/form/utils.d.ts +1 -2
- package/dist/forms.js +224 -239
- package/dist/forms.js.map +1 -0
- package/dist/forms.umd.cjs +223 -238
- package/dist/forms.umd.cjs.map +1 -0
- package/package.json +37 -49
package/dist/forms.js
CHANGED
|
@@ -2,7 +2,7 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
3
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
4
|
import { jsxs, jsx, Fragment as Fragment$1 } from "react/jsx-runtime";
|
|
5
|
-
import { Card, LuIcon, Text, Spinner, Overlay, ButtonGroup, Tooltip, IconButton, Separator, Input, Badge, Checkbox, CheckboxGroup, Popover, Button, DayPicker, Menu, OneTimePasswordField, RadioGroup, TextArea, Rating, stopPropagation, Heading,
|
|
5
|
+
import { Card, LuIcon, Text, Spinner, Overlay, ButtonGroup, Tooltip, IconButton, Separator, Input, Badge, Checkbox, CheckboxGroup, Popover, Button, DayPicker, Menu, OneTimePasswordField, RadioGroup, TextArea, Rating, stopPropagation, Heading, toast, ToggleGroup } from "@overmap-ai/blocks";
|
|
6
6
|
import { cx } from "class-variance-authority";
|
|
7
7
|
import { forwardRef, createElement, memo, createContext, useContext, useRef, useCallback, useState, useEffect, useMemo, Fragment, use, useLayoutEffect, useId } from "react";
|
|
8
8
|
import "@xyflow/react/dist/style.css";
|
|
@@ -825,7 +825,7 @@ const ImageViewerProvider = memo((props) => {
|
|
|
825
825
|
] });
|
|
826
826
|
});
|
|
827
827
|
ImageViewerProvider.displayName = "FileViewerProvider";
|
|
828
|
-
const InputWithLabel = (props) => {
|
|
828
|
+
const InputWithLabel = memo((props) => {
|
|
829
829
|
const { className, label, children, severity, inputId, labelId, image } = props;
|
|
830
830
|
const [resolvedImage, setResolvedImage] = useState(void 0);
|
|
831
831
|
const openImageViewer = useImageViewer();
|
|
@@ -857,7 +857,7 @@ const InputWithLabel = (props) => {
|
|
|
857
857
|
!!label && /* @__PURE__ */ jsx("label", { className: cx(className, "w-max max-w-full"), htmlFor: inputId, children: /* @__PURE__ */ jsx(Text, { accentColor: color, size: "sm", id: labelId, className: "text-wrap", children: label }) }),
|
|
858
858
|
children
|
|
859
859
|
] });
|
|
860
|
-
};
|
|
860
|
+
});
|
|
861
861
|
const InputWithLabelAndHelpText = (props) => {
|
|
862
862
|
const { children, ...restProps } = props;
|
|
863
863
|
return /* @__PURE__ */ jsx(InputWithHelpText, { ...restProps, children });
|
|
@@ -884,14 +884,14 @@ const useFormikInput = (props) => {
|
|
|
884
884
|
const label = field.required ? `${field.label} *` : field.label;
|
|
885
885
|
const fieldPropsWithValidation = useMemo(() => {
|
|
886
886
|
const handleChange = (value) => {
|
|
887
|
-
helpers.setValue(value, false)
|
|
887
|
+
void helpers.setValue(value, false);
|
|
888
888
|
onValuesChange == null ? void 0 : onValuesChange(field.identifier, value);
|
|
889
889
|
if (touched || !field.onlyValidateAfterTouched) {
|
|
890
890
|
helpers.setError(field.getError(value));
|
|
891
891
|
}
|
|
892
892
|
};
|
|
893
893
|
const handleBlur = (value) => {
|
|
894
|
-
void helpers.setTouched(true, false)
|
|
894
|
+
void helpers.setTouched(true, false);
|
|
895
895
|
helpers.setError(field.getError(value));
|
|
896
896
|
};
|
|
897
897
|
return {
|
|
@@ -1165,7 +1165,9 @@ const _MultiStringField = class _MultiStringField extends BaseField {
|
|
|
1165
1165
|
return [];
|
|
1166
1166
|
}
|
|
1167
1167
|
areValuesEqual(value1, value2) {
|
|
1168
|
-
|
|
1168
|
+
const value1Set = new Set(value1);
|
|
1169
|
+
const value2Set = new Set(value2);
|
|
1170
|
+
return value1Set.size === value2Set.size && value1Set.isSubsetOf(value2Set);
|
|
1169
1171
|
}
|
|
1170
1172
|
};
|
|
1171
1173
|
__publicField(_MultiStringField, "fieldTypeName", "Multi-string");
|
|
@@ -1699,7 +1701,9 @@ const _CheckboxListField = class _CheckboxListField extends BaseOptionsField {
|
|
|
1699
1701
|
return [];
|
|
1700
1702
|
}
|
|
1701
1703
|
areValuesEqual(value1, value2) {
|
|
1702
|
-
|
|
1704
|
+
const value1Set = new Set(value1);
|
|
1705
|
+
const value2Set = new Set(value2);
|
|
1706
|
+
return value1Set.size === value2Set.size && value1Set.isSubsetOf(value2Set);
|
|
1703
1707
|
}
|
|
1704
1708
|
};
|
|
1705
1709
|
__publicField(_CheckboxListField, "fieldTypeName", "Checkbox list");
|
|
@@ -1939,7 +1943,9 @@ const _MultiSelectField = class _MultiSelectField extends BaseOptionsField {
|
|
|
1939
1943
|
return [];
|
|
1940
1944
|
}
|
|
1941
1945
|
areValuesEqual(value1, value2) {
|
|
1942
|
-
|
|
1946
|
+
const value1Set = new Set(value1);
|
|
1947
|
+
const value2Set = new Set(value2);
|
|
1948
|
+
return value1Set.size === value2Set.size && value1Set.isSubsetOf(value2Set);
|
|
1943
1949
|
}
|
|
1944
1950
|
};
|
|
1945
1951
|
__publicField(_MultiSelectField, "fieldTypeName", "Multi-select");
|
|
@@ -2175,7 +2181,7 @@ const _OTPField = class _OTPField extends BaseField {
|
|
|
2175
2181
|
const validators = super.getFieldValidators();
|
|
2176
2182
|
const length = this.length;
|
|
2177
2183
|
validators.push((value) => {
|
|
2178
|
-
if (!this.isValueBlank(value) &&
|
|
2184
|
+
if (!this.isValueBlank(value) && value.length != length) {
|
|
2179
2185
|
return `Must be ${length} characters.`;
|
|
2180
2186
|
}
|
|
2181
2187
|
});
|
|
@@ -2280,6 +2286,7 @@ class UUIDPromise extends Promise {
|
|
|
2280
2286
|
Promise.resolve(promise).then(resolve).catch(reject);
|
|
2281
2287
|
}, uuid);
|
|
2282
2288
|
}
|
|
2289
|
+
// oxlint-disable-next-line no-thenable
|
|
2283
2290
|
then(onFulfilled, onRejected) {
|
|
2284
2291
|
const promise = super.then(onFulfilled, onRejected);
|
|
2285
2292
|
promise.uuid = this.uuid;
|
|
@@ -2301,9 +2308,9 @@ function isFileAndPromiseArray(value) {
|
|
|
2301
2308
|
return value.every((item) => item instanceof UUIDPromise || item instanceof UUIDFile);
|
|
2302
2309
|
}
|
|
2303
2310
|
function areFileAndPromiseArraysEqual(value1, value2) {
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
return
|
|
2311
|
+
const value1Set = new Set(value1.map(({ uuid }) => uuid));
|
|
2312
|
+
const value2Set = new Set(value2.map(({ uuid }) => uuid));
|
|
2313
|
+
return value1Set.size === value2Set.size && value1Set.isSubsetOf(value2Set);
|
|
2307
2314
|
}
|
|
2308
2315
|
const ImageCard = memo(
|
|
2309
2316
|
forwardRef((props, forwardedRef) => {
|
|
@@ -2497,7 +2504,7 @@ const PassFailInput = memo((props) => {
|
|
|
2497
2504
|
const handleRemoveFile = useCallback(
|
|
2498
2505
|
(index) => {
|
|
2499
2506
|
const files = [...value.files];
|
|
2500
|
-
files.splice(index, 1);
|
|
2507
|
+
void files.splice(index, 1);
|
|
2501
2508
|
onChange({
|
|
2502
2509
|
...value,
|
|
2503
2510
|
files
|
|
@@ -25371,7 +25378,6 @@ var PDF417CodewordDecoder = (
|
|
|
25371
25378
|
return PDF417CodewordDecoder2;
|
|
25372
25379
|
}()
|
|
25373
25380
|
);
|
|
25374
|
-
const global$1 = typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {};
|
|
25375
25381
|
var PDF417ResultMetadata = (
|
|
25376
25382
|
/** @class */
|
|
25377
25383
|
function() {
|
|
@@ -25666,8 +25672,8 @@ function getBigIntConstructor() {
|
|
|
25666
25672
|
if (typeof window !== "undefined") {
|
|
25667
25673
|
return window["BigInt"] || null;
|
|
25668
25674
|
}
|
|
25669
|
-
if (typeof global
|
|
25670
|
-
return global
|
|
25675
|
+
if (typeof global !== "undefined") {
|
|
25676
|
+
return global["BigInt"] || null;
|
|
25671
25677
|
}
|
|
25672
25678
|
if (typeof self !== "undefined") {
|
|
25673
25679
|
return self["BigInt"] || null;
|
|
@@ -31161,7 +31167,15 @@ const SCANNER_HINTS = /* @__PURE__ */ new Map([
|
|
|
31161
31167
|
]
|
|
31162
31168
|
]);
|
|
31163
31169
|
const Scanner = memo((props) => {
|
|
31164
|
-
const {
|
|
31170
|
+
const {
|
|
31171
|
+
children,
|
|
31172
|
+
open,
|
|
31173
|
+
onOpenChange,
|
|
31174
|
+
// oxlint-disable-line unbound-method
|
|
31175
|
+
defaultOpen,
|
|
31176
|
+
modal,
|
|
31177
|
+
...rest
|
|
31178
|
+
} = props;
|
|
31165
31179
|
return /* @__PURE__ */ jsxs(Overlay.Root, { open, onOpenChange, defaultOpen, modal, children: [
|
|
31166
31180
|
!!children && /* @__PURE__ */ jsx(Overlay.Trigger, { asChild: true, children }),
|
|
31167
31181
|
/* @__PURE__ */ jsxs(Overlay.Content, { children: [
|
|
@@ -31569,7 +31583,7 @@ const UploadInput = memo((props) => {
|
|
|
31569
31583
|
const handleRemove = useCallback(
|
|
31570
31584
|
(index) => {
|
|
31571
31585
|
const files = [...value];
|
|
31572
|
-
files.splice(index, 1);
|
|
31586
|
+
void files.splice(index, 1);
|
|
31573
31587
|
onChange(files);
|
|
31574
31588
|
},
|
|
31575
31589
|
[value, onChange]
|
|
@@ -31842,12 +31856,12 @@ class ConditionModifier {
|
|
|
31842
31856
|
constructor(config) {
|
|
31843
31857
|
__publicField(this, "id");
|
|
31844
31858
|
__publicField(this, "label");
|
|
31845
|
-
__publicField(this, "
|
|
31859
|
+
__publicField(this, "getApplyFn");
|
|
31846
31860
|
__publicField(this, "serialize");
|
|
31847
31861
|
__publicField(this, "deserialize");
|
|
31848
|
-
const { id,
|
|
31862
|
+
const { id, getApplyFn, label, serialize, deserialize: deserialize2 } = config;
|
|
31849
31863
|
this.id = id;
|
|
31850
|
-
this.
|
|
31864
|
+
this.getApplyFn = getApplyFn;
|
|
31851
31865
|
this.label = label;
|
|
31852
31866
|
this.serialize = serialize;
|
|
31853
31867
|
this.deserialize = deserialize2;
|
|
@@ -31859,40 +31873,34 @@ class ConditionModifier {
|
|
|
31859
31873
|
const BooleanEqualsConditionModifier = ConditionModifier.create({
|
|
31860
31874
|
id: "nullable-boolean-equals",
|
|
31861
31875
|
label: "is",
|
|
31862
|
-
|
|
31876
|
+
getApplyFn: (filterValue) => (value) => value === filterValue,
|
|
31863
31877
|
serialize: (filterValue) => filterValue,
|
|
31864
31878
|
deserialize: (filterValue) => filterValue
|
|
31865
31879
|
});
|
|
31866
31880
|
const BooleanNotEqualsConditionModifier = ConditionModifier.create({
|
|
31867
31881
|
id: "nullable-boolean-not-equals",
|
|
31868
31882
|
label: "is not",
|
|
31869
|
-
|
|
31883
|
+
getApplyFn: (filterValue) => (value) => value !== filterValue,
|
|
31870
31884
|
serialize: (filterValue) => filterValue,
|
|
31871
31885
|
deserialize: (filterValue) => filterValue
|
|
31872
31886
|
});
|
|
31873
31887
|
const DateEqualsConditionModifier = ConditionModifier.create({
|
|
31874
31888
|
id: "date-equals",
|
|
31875
|
-
|
|
31876
|
-
return value.getTime() === filterValue.getTime();
|
|
31877
|
-
},
|
|
31889
|
+
getApplyFn: (filterValue) => (value) => value.getTime() === filterValue.getTime(),
|
|
31878
31890
|
label: "is",
|
|
31879
31891
|
serialize: (filterValue) => filterValue.toISOString(),
|
|
31880
31892
|
deserialize: (filterValue) => new Date(filterValue)
|
|
31881
31893
|
});
|
|
31882
31894
|
const DateNotEqualsConditionModifier = ConditionModifier.create({
|
|
31883
31895
|
id: "date-not-equals",
|
|
31884
|
-
|
|
31885
|
-
return value.getTime() !== filterValue.getTime();
|
|
31886
|
-
},
|
|
31896
|
+
getApplyFn: (filterValue) => (value) => value.getTime() !== filterValue.getTime(),
|
|
31887
31897
|
label: "is not",
|
|
31888
31898
|
serialize: (filterValue) => filterValue.toISOString(),
|
|
31889
31899
|
deserialize: (filterValue) => new Date(filterValue)
|
|
31890
31900
|
});
|
|
31891
31901
|
const DateBeforeConditionModifier = ConditionModifier.create({
|
|
31892
31902
|
id: "date-before",
|
|
31893
|
-
|
|
31894
|
-
return value.getTime() < filterValue.getTime();
|
|
31895
|
-
},
|
|
31903
|
+
getApplyFn: (filterValue) => (value) => value.getTime() < filterValue.getTime(),
|
|
31896
31904
|
label: "before",
|
|
31897
31905
|
serialize: (filterValue) => filterValue.toISOString(),
|
|
31898
31906
|
deserialize: (filterValue) => new Date(filterValue)
|
|
@@ -31900,16 +31908,14 @@ const DateBeforeConditionModifier = ConditionModifier.create({
|
|
|
31900
31908
|
const DateAfterConditionModifier = ConditionModifier.create({
|
|
31901
31909
|
id: "date-after",
|
|
31902
31910
|
label: "after",
|
|
31903
|
-
|
|
31904
|
-
return value.getTime() > filterValue.getTime();
|
|
31905
|
-
},
|
|
31911
|
+
getApplyFn: (filterValue) => (value) => value.getTime() > filterValue.getTime(),
|
|
31906
31912
|
serialize: (filterValue) => filterValue.toISOString(),
|
|
31907
31913
|
deserialize: (filterValue) => new Date(filterValue)
|
|
31908
31914
|
});
|
|
31909
31915
|
const DateRangeInConditionModifier = ConditionModifier.create({
|
|
31910
31916
|
id: "date-range-in",
|
|
31911
31917
|
label: "in between",
|
|
31912
|
-
|
|
31918
|
+
getApplyFn: (filterValue) => (value) => {
|
|
31913
31919
|
if ((filterValue == null ? void 0 : filterValue.from) && filterValue.from.getTime() > value.getTime()) return false;
|
|
31914
31920
|
if ((filterValue == null ? void 0 : filterValue.to) && filterValue.to.getTime() < value.getTime()) return false;
|
|
31915
31921
|
return true;
|
|
@@ -31931,7 +31937,7 @@ const DateRangeInConditionModifier = ConditionModifier.create({
|
|
|
31931
31937
|
const DateRangeNotInConditionModifier = ConditionModifier.create({
|
|
31932
31938
|
id: "date-range-not-in",
|
|
31933
31939
|
label: "not in between",
|
|
31934
|
-
|
|
31940
|
+
getApplyFn: (filterValue) => (value) => {
|
|
31935
31941
|
if ((filterValue == null ? void 0 : filterValue.from) && filterValue.from.getTime() > value.getTime()) return true;
|
|
31936
31942
|
if ((filterValue == null ? void 0 : filterValue.to) && filterValue.to.getTime() < value.getTime()) return true;
|
|
31937
31943
|
return false;
|
|
@@ -31953,74 +31959,62 @@ const DateRangeNotInConditionModifier = ConditionModifier.create({
|
|
|
31953
31959
|
const HasFilesConditionModifier = ConditionModifier.create({
|
|
31954
31960
|
id: "has-files",
|
|
31955
31961
|
label: "is",
|
|
31956
|
-
|
|
31962
|
+
getApplyFn: (_filterValue) => (value) => value.length > 0,
|
|
31957
31963
|
serialize: (filterValue) => filterValue,
|
|
31958
31964
|
deserialize: (filterValue) => filterValue
|
|
31959
31965
|
});
|
|
31960
31966
|
const DoesNotHaveFilesConditionModifier = ConditionModifier.create({
|
|
31961
31967
|
id: "does-not-have-files",
|
|
31962
31968
|
label: "is not",
|
|
31963
|
-
|
|
31969
|
+
getApplyFn: (_filterValue) => (value) => value.length === 0,
|
|
31964
31970
|
serialize: (filterValue) => filterValue,
|
|
31965
31971
|
deserialize: (filterValue) => filterValue
|
|
31966
31972
|
});
|
|
31967
31973
|
const NumberEqualsConditionModifier = ConditionModifier.create({
|
|
31968
31974
|
id: "number-equals",
|
|
31969
|
-
|
|
31970
|
-
return value === filterValue;
|
|
31971
|
-
},
|
|
31975
|
+
getApplyFn: (filterValue) => (value) => value === filterValue,
|
|
31972
31976
|
label: "is",
|
|
31973
31977
|
serialize: (filterValue) => filterValue,
|
|
31974
31978
|
deserialize: (filterValue) => filterValue
|
|
31975
31979
|
});
|
|
31976
31980
|
const NumberNotEqualsConditionModifier = ConditionModifier.create({
|
|
31977
31981
|
id: "number-not-equals",
|
|
31978
|
-
|
|
31979
|
-
return value !== filterValue;
|
|
31980
|
-
},
|
|
31982
|
+
getApplyFn: (filterValue) => (value) => value !== filterValue,
|
|
31981
31983
|
label: "is not",
|
|
31982
31984
|
serialize: (filterValue) => filterValue,
|
|
31983
31985
|
deserialize: (filterValue) => filterValue
|
|
31984
31986
|
});
|
|
31985
31987
|
const NumberLessThanConditionModifier = ConditionModifier.create({
|
|
31986
31988
|
id: "number-less-than",
|
|
31987
|
-
|
|
31988
|
-
return value < filterValue;
|
|
31989
|
-
},
|
|
31989
|
+
getApplyFn: (filterValue) => (value) => value < filterValue,
|
|
31990
31990
|
label: "is less than",
|
|
31991
31991
|
serialize: (filterValue) => filterValue,
|
|
31992
31992
|
deserialize: (filterValue) => filterValue
|
|
31993
31993
|
});
|
|
31994
31994
|
const NumberLessThanOrEqualsConditionModifier = ConditionModifier.create({
|
|
31995
31995
|
id: "number-less-than-or-equals",
|
|
31996
|
-
|
|
31997
|
-
return value <= filterValue;
|
|
31998
|
-
},
|
|
31996
|
+
getApplyFn: (filterValue) => (value) => value <= filterValue,
|
|
31999
31997
|
label: "is less than or equal to",
|
|
32000
31998
|
serialize: (filterValue) => filterValue,
|
|
32001
31999
|
deserialize: (filterValue) => filterValue
|
|
32002
32000
|
});
|
|
32003
32001
|
const NumberGreaterThanConditionModifier = ConditionModifier.create({
|
|
32004
32002
|
id: "number-greater-than",
|
|
32005
|
-
|
|
32006
|
-
return value > filterValue;
|
|
32007
|
-
},
|
|
32003
|
+
getApplyFn: (filterValue) => (value) => value > filterValue,
|
|
32008
32004
|
label: "is greater than",
|
|
32009
32005
|
serialize: (filterValue) => filterValue,
|
|
32010
32006
|
deserialize: (filterValue) => filterValue
|
|
32011
32007
|
});
|
|
32012
32008
|
const NumberGreaterThanOrEqualsConditionModifier = ConditionModifier.create({
|
|
32013
32009
|
id: "number-greater-than-or-equals",
|
|
32014
|
-
|
|
32015
|
-
return value >= filterValue;
|
|
32016
|
-
},
|
|
32010
|
+
getApplyFn: (filterValue) => (value) => value >= filterValue,
|
|
32017
32011
|
label: "is greater than or equal to",
|
|
32018
32012
|
serialize: (filterValue) => filterValue,
|
|
32019
32013
|
deserialize: (filterValue) => filterValue
|
|
32020
32014
|
});
|
|
32021
32015
|
const NumberRangeInConditionModifier = ConditionModifier.create({
|
|
32022
32016
|
id: "number-range-in",
|
|
32023
|
-
|
|
32017
|
+
getApplyFn: (filterValue) => (value) => {
|
|
32024
32018
|
if (filterValue.to && value > filterValue.to) return false;
|
|
32025
32019
|
if (filterValue.from && value < filterValue.from) return false;
|
|
32026
32020
|
return true;
|
|
@@ -32031,7 +32025,7 @@ const NumberRangeInConditionModifier = ConditionModifier.create({
|
|
|
32031
32025
|
});
|
|
32032
32026
|
const NumberRangeNotInConditionModifier = ConditionModifier.create({
|
|
32033
32027
|
id: "number-range-not-in",
|
|
32034
|
-
|
|
32028
|
+
getApplyFn: (filterValue) => (value) => {
|
|
32035
32029
|
if (filterValue.to && value > filterValue.to) return true;
|
|
32036
32030
|
if (filterValue.from && value < filterValue.from) return true;
|
|
32037
32031
|
return false;
|
|
@@ -32042,26 +32036,23 @@ const NumberRangeNotInConditionModifier = ConditionModifier.create({
|
|
|
32042
32036
|
});
|
|
32043
32037
|
const PassFailEqualsConditionModifier = ConditionModifier.create({
|
|
32044
32038
|
id: "pass-fail-equals",
|
|
32045
|
-
|
|
32046
|
-
return value === filterValue;
|
|
32047
|
-
},
|
|
32039
|
+
getApplyFn: (filterValue) => (value) => value === filterValue,
|
|
32048
32040
|
label: "is",
|
|
32049
32041
|
serialize: (filterValue) => filterValue,
|
|
32050
32042
|
deserialize: (filterValue) => filterValue
|
|
32051
32043
|
});
|
|
32052
32044
|
const PassFailNotEqualsConditionModifier = ConditionModifier.create({
|
|
32053
32045
|
id: "pass-fail-not-equals",
|
|
32054
|
-
|
|
32055
|
-
return value !== filterValue;
|
|
32056
|
-
},
|
|
32046
|
+
getApplyFn: (filterValue) => (value) => value !== filterValue,
|
|
32057
32047
|
label: "is not",
|
|
32058
32048
|
serialize: (filterValue) => filterValue,
|
|
32059
32049
|
deserialize: (filterValue) => filterValue
|
|
32060
32050
|
});
|
|
32061
32051
|
const PassFailArrayIncludesConditionModifier = ConditionModifier.create({
|
|
32062
32052
|
id: "pass-fail-array-includes",
|
|
32063
|
-
|
|
32064
|
-
|
|
32053
|
+
getApplyFn: (filterValue) => {
|
|
32054
|
+
const filterValueSet = new Set(filterValue);
|
|
32055
|
+
return (value) => filterValueSet.has(value);
|
|
32065
32056
|
},
|
|
32066
32057
|
label: "is any of",
|
|
32067
32058
|
serialize: (filterValue) => filterValue,
|
|
@@ -32069,8 +32060,9 @@ const PassFailArrayIncludesConditionModifier = ConditionModifier.create({
|
|
|
32069
32060
|
});
|
|
32070
32061
|
const PassFailArrayExcludesConditionModifier = ConditionModifier.create({
|
|
32071
32062
|
id: "pass-fail-array-excludes",
|
|
32072
|
-
|
|
32073
|
-
|
|
32063
|
+
getApplyFn: (filterValue) => {
|
|
32064
|
+
const filterValueSet = new Set(filterValue);
|
|
32065
|
+
return (value) => !filterValueSet.has(value);
|
|
32074
32066
|
},
|
|
32075
32067
|
label: "is none of",
|
|
32076
32068
|
serialize: (filterValue) => filterValue,
|
|
@@ -32078,44 +32070,37 @@ const PassFailArrayExcludesConditionModifier = ConditionModifier.create({
|
|
|
32078
32070
|
});
|
|
32079
32071
|
const StringEqualsConditionModifier = ConditionModifier.create({
|
|
32080
32072
|
id: "nullable-string-equals",
|
|
32081
|
-
|
|
32082
|
-
return value === filterValue;
|
|
32083
|
-
},
|
|
32073
|
+
getApplyFn: (filterValue) => (value) => value === filterValue,
|
|
32084
32074
|
label: "is",
|
|
32085
32075
|
serialize: (filterValue) => filterValue,
|
|
32086
32076
|
deserialize: (filterValue) => filterValue
|
|
32087
32077
|
});
|
|
32088
32078
|
const StringNotEqualsConditionModifier = ConditionModifier.create({
|
|
32089
32079
|
id: "nullable-string-not-equals",
|
|
32090
|
-
|
|
32091
|
-
return value !== filterValue;
|
|
32092
|
-
},
|
|
32080
|
+
getApplyFn: (filterValue) => (value) => value !== filterValue,
|
|
32093
32081
|
label: "is not",
|
|
32094
32082
|
serialize: (filterValue) => filterValue,
|
|
32095
32083
|
deserialize: (filterValue) => filterValue
|
|
32096
32084
|
});
|
|
32097
32085
|
const StringIncludesConditionModifier = ConditionModifier.create({
|
|
32098
32086
|
id: "string-includes",
|
|
32099
|
-
|
|
32100
|
-
return value.includes(filterValue);
|
|
32101
|
-
},
|
|
32087
|
+
getApplyFn: (filterValue) => (value) => value.includes(filterValue),
|
|
32102
32088
|
label: "includes",
|
|
32103
32089
|
serialize: (filterValue) => filterValue,
|
|
32104
32090
|
deserialize: (filterValue) => filterValue
|
|
32105
32091
|
});
|
|
32106
32092
|
const StringExcludesConditionModifier = ConditionModifier.create({
|
|
32107
32093
|
id: "string-excludes",
|
|
32108
|
-
|
|
32109
|
-
return !value.includes(filterValue);
|
|
32110
|
-
},
|
|
32094
|
+
getApplyFn: (filterValue) => (value) => !value.includes(filterValue),
|
|
32111
32095
|
label: "does not include",
|
|
32112
32096
|
serialize: (filterValue) => filterValue,
|
|
32113
32097
|
deserialize: (filterValue) => filterValue
|
|
32114
32098
|
});
|
|
32115
32099
|
const StringArrayIncludesConditionModifier = ConditionModifier.create({
|
|
32116
32100
|
id: "string-array-includes",
|
|
32117
|
-
|
|
32118
|
-
|
|
32101
|
+
getApplyFn: (filterValue) => {
|
|
32102
|
+
const filterValueSet = new Set(filterValue);
|
|
32103
|
+
return (value) => filterValueSet.has(value);
|
|
32119
32104
|
},
|
|
32120
32105
|
label: "is any of",
|
|
32121
32106
|
serialize: (filterValue) => filterValue,
|
|
@@ -32123,8 +32108,9 @@ const StringArrayIncludesConditionModifier = ConditionModifier.create({
|
|
|
32123
32108
|
});
|
|
32124
32109
|
const StringArrayExcludesConditionModifier = ConditionModifier.create({
|
|
32125
32110
|
id: "string-array-excludes",
|
|
32126
|
-
|
|
32127
|
-
|
|
32111
|
+
getApplyFn: (filterValue) => {
|
|
32112
|
+
const filterValueSet = new Set(filterValue);
|
|
32113
|
+
return (value) => !filterValueSet.has(value);
|
|
32128
32114
|
},
|
|
32129
32115
|
label: "is none of",
|
|
32130
32116
|
serialize: (filterValue) => filterValue,
|
|
@@ -32132,8 +32118,12 @@ const StringArrayExcludesConditionModifier = ConditionModifier.create({
|
|
|
32132
32118
|
});
|
|
32133
32119
|
const StringArrayEveryConditionModifier = ConditionModifier.create({
|
|
32134
32120
|
id: "string-array-every",
|
|
32135
|
-
|
|
32136
|
-
|
|
32121
|
+
getApplyFn: (filterValue) => {
|
|
32122
|
+
const filterValueSet = new Set(filterValue);
|
|
32123
|
+
return (value) => {
|
|
32124
|
+
const valueSet = new Set(value);
|
|
32125
|
+
return filterValueSet.isSubsetOf(valueSet);
|
|
32126
|
+
};
|
|
32137
32127
|
},
|
|
32138
32128
|
label: "has all of",
|
|
32139
32129
|
serialize: (filterValue) => filterValue,
|
|
@@ -32141,8 +32131,12 @@ const StringArrayEveryConditionModifier = ConditionModifier.create({
|
|
|
32141
32131
|
});
|
|
32142
32132
|
const StringArraySomeConditionModifier = ConditionModifier.create({
|
|
32143
32133
|
id: "string-array-some",
|
|
32144
|
-
|
|
32145
|
-
|
|
32134
|
+
getApplyFn: (filterValue) => {
|
|
32135
|
+
const filterValueSet = new Set(filterValue);
|
|
32136
|
+
return (value) => {
|
|
32137
|
+
const valueSet = new Set(value);
|
|
32138
|
+
return !filterValueSet.isDisjointFrom(valueSet);
|
|
32139
|
+
};
|
|
32146
32140
|
},
|
|
32147
32141
|
label: "has any of",
|
|
32148
32142
|
serialize: (filterValue) => filterValue,
|
|
@@ -32150,8 +32144,12 @@ const StringArraySomeConditionModifier = ConditionModifier.create({
|
|
|
32150
32144
|
});
|
|
32151
32145
|
const StringArrayNoneConditionModifier = ConditionModifier.create({
|
|
32152
32146
|
id: "string-array-none",
|
|
32153
|
-
|
|
32154
|
-
|
|
32147
|
+
getApplyFn: (filterValue) => {
|
|
32148
|
+
const filterValueSet = new Set(filterValue);
|
|
32149
|
+
return (value) => {
|
|
32150
|
+
const valueSet = new Set(value);
|
|
32151
|
+
return filterValueSet.isDisjointFrom(valueSet);
|
|
32152
|
+
};
|
|
32155
32153
|
},
|
|
32156
32154
|
label: "has none of",
|
|
32157
32155
|
serialize: (filterValue) => filterValue,
|
|
@@ -32159,10 +32157,12 @@ const StringArrayNoneConditionModifier = ConditionModifier.create({
|
|
|
32159
32157
|
});
|
|
32160
32158
|
const StringArrayEqualsConditionModifier = ConditionModifier.create({
|
|
32161
32159
|
id: "string-array-equals",
|
|
32162
|
-
|
|
32163
|
-
|
|
32164
|
-
|
|
32165
|
-
|
|
32160
|
+
getApplyFn: (filterValue) => {
|
|
32161
|
+
const filterValueSet = new Set(filterValue);
|
|
32162
|
+
return (value) => {
|
|
32163
|
+
const valueSet = new Set(value);
|
|
32164
|
+
return filterValueSet.size === valueSet.size && valueSet.isSubsetOf(filterValueSet);
|
|
32165
|
+
};
|
|
32166
32166
|
},
|
|
32167
32167
|
label: "is",
|
|
32168
32168
|
serialize: (filterValue) => filterValue,
|
|
@@ -32170,10 +32170,12 @@ const StringArrayEqualsConditionModifier = ConditionModifier.create({
|
|
|
32170
32170
|
});
|
|
32171
32171
|
const StringArrayNotEqualsConditionModifier = ConditionModifier.create({
|
|
32172
32172
|
id: "string-array-not-equals",
|
|
32173
|
-
|
|
32174
|
-
|
|
32175
|
-
|
|
32176
|
-
|
|
32173
|
+
getApplyFn: (filterValue) => {
|
|
32174
|
+
const filterValueSet = new Set(filterValue);
|
|
32175
|
+
return (value) => {
|
|
32176
|
+
const valueSet = new Set(value);
|
|
32177
|
+
return filterValueSet.size !== valueSet.size || !valueSet.isSubsetOf(filterValueSet);
|
|
32178
|
+
};
|
|
32177
32179
|
},
|
|
32178
32180
|
label: "is not",
|
|
32179
32181
|
serialize: (filterValue) => filterValue,
|
|
@@ -32212,14 +32214,20 @@ class BaseCondition extends Observable {
|
|
|
32212
32214
|
__publicField(this, "getConditionModifiers", () => {
|
|
32213
32215
|
return Object.entries(this.modifiers);
|
|
32214
32216
|
});
|
|
32215
|
-
__publicField(this, "
|
|
32217
|
+
__publicField(this, "accessorFn", (values) => {
|
|
32218
|
+
return values[this.field.identifier];
|
|
32219
|
+
});
|
|
32220
|
+
__publicField(this, "getApplyFn", () => {
|
|
32216
32221
|
const modifier = this.modifiers[this.conditionModifier];
|
|
32217
32222
|
const conditionValue = this.getConditionValue();
|
|
32218
|
-
|
|
32219
|
-
|
|
32220
|
-
|
|
32221
|
-
|
|
32222
|
-
|
|
32223
|
+
const conditionValueInvalid = conditionValue === void 0 || !modifier.isConditionValueValid(conditionValue);
|
|
32224
|
+
const applyFn = modifier.modifier.getApplyFn(conditionValue);
|
|
32225
|
+
return (value) => {
|
|
32226
|
+
if (conditionValueInvalid) return true;
|
|
32227
|
+
const transformedValue = this.transformValue(value);
|
|
32228
|
+
if (!modifier.isValueValid(transformedValue)) return false;
|
|
32229
|
+
return applyFn(transformedValue);
|
|
32230
|
+
};
|
|
32223
32231
|
});
|
|
32224
32232
|
this.id = id;
|
|
32225
32233
|
this.field = field;
|
|
@@ -32711,6 +32719,55 @@ class CheckboxListFieldCondition extends BaseCondition {
|
|
|
32711
32719
|
return /* @__PURE__ */ jsx(CheckboxListFieldConditionCell, { condition: this, ...props }, this.id);
|
|
32712
32720
|
}
|
|
32713
32721
|
}
|
|
32722
|
+
class ConditionManager extends Observable {
|
|
32723
|
+
constructor(conditions) {
|
|
32724
|
+
super();
|
|
32725
|
+
__publicField(this, "conditions");
|
|
32726
|
+
__publicField(this, "conditionObserver", () => {
|
|
32727
|
+
this.conditions = [...this.conditions];
|
|
32728
|
+
this.notify(this);
|
|
32729
|
+
});
|
|
32730
|
+
__publicField(this, "initConditions", (conditions) => {
|
|
32731
|
+
for (const c of conditions) c.observe(this.conditionObserver);
|
|
32732
|
+
return conditions;
|
|
32733
|
+
});
|
|
32734
|
+
this.conditions = this.initConditions(conditions);
|
|
32735
|
+
}
|
|
32736
|
+
getConditions() {
|
|
32737
|
+
return this.conditions;
|
|
32738
|
+
}
|
|
32739
|
+
addCondition(condition) {
|
|
32740
|
+
this.conditions = this.initConditions([...this.conditions, condition]);
|
|
32741
|
+
this.notify(this);
|
|
32742
|
+
}
|
|
32743
|
+
addConditions(conditions) {
|
|
32744
|
+
this.conditions = this.initConditions([...this.conditions, ...conditions]);
|
|
32745
|
+
this.notify(this);
|
|
32746
|
+
}
|
|
32747
|
+
removeCondition(condition) {
|
|
32748
|
+
this.conditions = this.initConditions(this.conditions.filter((c) => c.id !== condition.id));
|
|
32749
|
+
this.notify(this);
|
|
32750
|
+
}
|
|
32751
|
+
removeConditions(conditions) {
|
|
32752
|
+
const conditionIds = new Set(conditions.map((c) => c.id));
|
|
32753
|
+
this.conditions = this.initConditions(this.conditions.filter((c) => !conditionIds.has(c.id)));
|
|
32754
|
+
this.notify(this);
|
|
32755
|
+
}
|
|
32756
|
+
applyConditions(values) {
|
|
32757
|
+
if (this.conditions.length === 0) return true;
|
|
32758
|
+
const applyAndAccessorFns = this.conditions.map((condition) => [condition.getApplyFn(), condition.accessorFn]);
|
|
32759
|
+
return applyAndAccessorFns.every(([applyFn, accessorFn]) => {
|
|
32760
|
+
return applyFn(accessorFn(values));
|
|
32761
|
+
});
|
|
32762
|
+
}
|
|
32763
|
+
}
|
|
32764
|
+
const useConditionManager = (conditions, onConditionsChange) => {
|
|
32765
|
+
return useMemo(() => {
|
|
32766
|
+
const ret = new ConditionManager(conditions);
|
|
32767
|
+
ret.observe((conditionManager) => onConditionsChange(conditionManager.getConditions()));
|
|
32768
|
+
return ret;
|
|
32769
|
+
}, [conditions, onConditionsChange]);
|
|
32770
|
+
};
|
|
32714
32771
|
const DateFieldConditionCell = (props) => {
|
|
32715
32772
|
const { condition, onRemove } = props;
|
|
32716
32773
|
const conditionValue = condition.getConditionValue();
|
|
@@ -34028,56 +34085,6 @@ const deserializeConditions = (fields, serializedConditions) => {
|
|
|
34028
34085
|
(serializedCondition) => deserializeCondition(fieldsMapping[serializedCondition.fieldId], serializedCondition)
|
|
34029
34086
|
);
|
|
34030
34087
|
};
|
|
34031
|
-
const applyConditions = (conditions, values) => {
|
|
34032
|
-
return conditions.length > 0 ? conditions.every((condition) => {
|
|
34033
|
-
return condition.apply(values[condition.field.identifier]);
|
|
34034
|
-
}) : true;
|
|
34035
|
-
};
|
|
34036
|
-
class ConditionManager extends Observable {
|
|
34037
|
-
constructor(conditions) {
|
|
34038
|
-
super();
|
|
34039
|
-
__publicField(this, "conditions");
|
|
34040
|
-
__publicField(this, "conditionObserver", () => {
|
|
34041
|
-
this.conditions = [...this.conditions];
|
|
34042
|
-
this.notify(this);
|
|
34043
|
-
});
|
|
34044
|
-
__publicField(this, "initConditions", (conditions) => {
|
|
34045
|
-
for (const c of conditions) c.observe(this.conditionObserver);
|
|
34046
|
-
return conditions;
|
|
34047
|
-
});
|
|
34048
|
-
this.conditions = this.initConditions(conditions);
|
|
34049
|
-
}
|
|
34050
|
-
getConditions() {
|
|
34051
|
-
return this.conditions;
|
|
34052
|
-
}
|
|
34053
|
-
addCondition(condition) {
|
|
34054
|
-
this.conditions = this.initConditions([...this.conditions, condition]);
|
|
34055
|
-
this.notify(this);
|
|
34056
|
-
}
|
|
34057
|
-
addConditions(conditions) {
|
|
34058
|
-
this.conditions = this.initConditions([...this.conditions, ...conditions]);
|
|
34059
|
-
this.notify(this);
|
|
34060
|
-
}
|
|
34061
|
-
removeCondition(condition) {
|
|
34062
|
-
this.conditions = this.initConditions(this.conditions.filter((c) => c.id !== condition.id));
|
|
34063
|
-
this.notify(this);
|
|
34064
|
-
}
|
|
34065
|
-
removeConditions(conditions) {
|
|
34066
|
-
const conditionIds = new Set(conditions.map((c) => c.id));
|
|
34067
|
-
this.conditions = this.initConditions(this.conditions.filter((c) => !conditionIds.has(c.id)));
|
|
34068
|
-
this.notify(this);
|
|
34069
|
-
}
|
|
34070
|
-
applyConditions(values) {
|
|
34071
|
-
return applyConditions(this.conditions, values);
|
|
34072
|
-
}
|
|
34073
|
-
}
|
|
34074
|
-
const useConditionManager = (conditions, onConditionsChange) => {
|
|
34075
|
-
return useMemo(() => {
|
|
34076
|
-
const ret = new ConditionManager(conditions);
|
|
34077
|
-
ret.observe((conditionManager) => onConditionsChange(conditionManager.getConditions()));
|
|
34078
|
-
return ret;
|
|
34079
|
-
}, [conditions, onConditionsChange]);
|
|
34080
|
-
};
|
|
34081
34088
|
const deserializeField = (serializedField) => {
|
|
34082
34089
|
return FieldTypeToClsMapping[serializedField.type].deserialize(serializedField);
|
|
34083
34090
|
};
|
|
@@ -34247,9 +34254,11 @@ const FieldSectionLayout = memo((props) => {
|
|
|
34247
34254
|
}, [fieldSections, section.identifier]);
|
|
34248
34255
|
const conditionMet = useMemo(() => {
|
|
34249
34256
|
if (conditionalSections.length === 0) return true;
|
|
34250
|
-
return conditionalSections.some(
|
|
34251
|
-
|
|
34252
|
-
|
|
34257
|
+
return conditionalSections.some((conditionalSection) => {
|
|
34258
|
+
const conditions = conditionalSection.getConditions(section.identifier);
|
|
34259
|
+
const conditionManager = new ConditionManager(conditions);
|
|
34260
|
+
return conditionManager.applyConditions(values);
|
|
34261
|
+
});
|
|
34253
34262
|
}, [conditionalSections, section, values]);
|
|
34254
34263
|
const inputs = useFieldInputs(section.fields, rest);
|
|
34255
34264
|
if (!conditionMet) return null;
|
|
@@ -34309,14 +34318,6 @@ const _FieldSection = class _FieldSection extends BaseFormElement {
|
|
|
34309
34318
|
fields: this.fields.map((field) => field.serialize())
|
|
34310
34319
|
};
|
|
34311
34320
|
}
|
|
34312
|
-
static deserialize(data) {
|
|
34313
|
-
const fields = data.fields.map(deserializeField);
|
|
34314
|
-
const conditions = {};
|
|
34315
|
-
for (const [sectionId, serializedConditions] of Object.entries(data.conditions)) {
|
|
34316
|
-
conditions[sectionId] = deserializeConditions(fields, serializedConditions);
|
|
34317
|
-
}
|
|
34318
|
-
return new _FieldSection({ ...data, fields, conditions });
|
|
34319
|
-
}
|
|
34320
34321
|
getOptions() {
|
|
34321
34322
|
return {
|
|
34322
34323
|
...super.getOptions(),
|
|
@@ -34412,7 +34413,10 @@ const _FieldSection = class _FieldSection extends BaseFormElement {
|
|
|
34412
34413
|
return new Set(Object.keys(this.conditions));
|
|
34413
34414
|
}
|
|
34414
34415
|
addConditional(identifier) {
|
|
34415
|
-
this.conditions = this.initConditions({
|
|
34416
|
+
this.conditions = this.initConditions({
|
|
34417
|
+
...this.conditions,
|
|
34418
|
+
[identifier]: []
|
|
34419
|
+
});
|
|
34416
34420
|
this.notify(this);
|
|
34417
34421
|
}
|
|
34418
34422
|
removeConditional(identifier) {
|
|
@@ -34428,6 +34432,14 @@ const _FieldSection = class _FieldSection extends BaseFormElement {
|
|
|
34428
34432
|
};
|
|
34429
34433
|
__publicField(_FieldSection, "fieldTypeName", "Section");
|
|
34430
34434
|
__publicField(_FieldSection, "fieldTypeDescription", "Sections can be useful for grouping fields together. They can also be conditionally shown or hidden.");
|
|
34435
|
+
__publicField(_FieldSection, "deserialize", (data) => {
|
|
34436
|
+
const fields = data.fields.map(deserializeField);
|
|
34437
|
+
const conditions = {};
|
|
34438
|
+
for (const [sectionId, serializedConditions] of Object.entries(data.conditions)) {
|
|
34439
|
+
conditions[sectionId] = deserializeConditions(fields, serializedConditions);
|
|
34440
|
+
}
|
|
34441
|
+
return new _FieldSection({ ...data, fields, conditions });
|
|
34442
|
+
});
|
|
34431
34443
|
let FieldSection = _FieldSection;
|
|
34432
34444
|
class FieldSchema extends Observable {
|
|
34433
34445
|
constructor(fields) {
|
|
@@ -34894,7 +34906,6 @@ const FieldBuilder = memo((props) => {
|
|
|
34894
34906
|
FieldBuilder.displayName = "FieldBuilder";
|
|
34895
34907
|
const FieldBuilderWithActions = memo((props) => {
|
|
34896
34908
|
const { field, fieldSection, fieldIndex, sectionIndex } = props;
|
|
34897
|
-
const { showError } = useToast();
|
|
34898
34909
|
const fileInputRef = useRef(null);
|
|
34899
34910
|
const parentPath = `fields.${sectionIndex}.fields`;
|
|
34900
34911
|
const handleAddField = useCallback(
|
|
@@ -34920,7 +34931,7 @@ const FieldBuilderWithActions = memo((props) => {
|
|
|
34920
34931
|
const file = files.item(0);
|
|
34921
34932
|
if (!file) return;
|
|
34922
34933
|
if (file.size > maxFileSizeB) {
|
|
34923
|
-
|
|
34934
|
+
toast.error({
|
|
34924
34935
|
title: "File upload error",
|
|
34925
34936
|
description: `The file ${file.name} exceeded the maximum file size`
|
|
34926
34937
|
});
|
|
@@ -34930,7 +34941,7 @@ const FieldBuilderWithActions = memo((props) => {
|
|
|
34930
34941
|
image: file
|
|
34931
34942
|
});
|
|
34932
34943
|
},
|
|
34933
|
-
[field
|
|
34944
|
+
[field]
|
|
34934
34945
|
);
|
|
34935
34946
|
const handleMoveUp = useCallback(() => {
|
|
34936
34947
|
moveField("up");
|
|
@@ -35665,9 +35676,12 @@ const validateFields = (fields, values) => {
|
|
|
35665
35676
|
for (const field of fields) {
|
|
35666
35677
|
if (field instanceof FieldSection) {
|
|
35667
35678
|
const conditionalSections = sectionElements.filter((section) => field.identifier in section.conditions);
|
|
35668
|
-
|
|
35669
|
-
|
|
35670
|
-
|
|
35679
|
+
if (conditionalSections.length === 0) continue;
|
|
35680
|
+
const conditionMet = conditionalSections.some((conditionalSection) => {
|
|
35681
|
+
const conditions = conditionalSection.getConditions(field.identifier);
|
|
35682
|
+
const conditionManager = new ConditionManager(conditions);
|
|
35683
|
+
return conditionManager.applyConditions(values);
|
|
35684
|
+
});
|
|
35671
35685
|
if (!conditionMet) continue;
|
|
35672
35686
|
Object.assign(errors, field.getErrors(values));
|
|
35673
35687
|
} else {
|
|
@@ -35681,34 +35695,10 @@ const validateFields = (fields, values) => {
|
|
|
35681
35695
|
}
|
|
35682
35696
|
if (Object.keys(errors).length > 0) return errors;
|
|
35683
35697
|
};
|
|
35684
|
-
const cleanFields = (fields, values) => {
|
|
35685
|
-
const errors = {};
|
|
35686
|
-
const sectionElements = fields.filter((f) => f instanceof FieldSection);
|
|
35687
|
-
for (const field of fields) {
|
|
35688
|
-
if (field instanceof FieldSection) {
|
|
35689
|
-
const conditionalSections = sectionElements.filter((section) => field.identifier in section.conditions);
|
|
35690
|
-
const conditionMet = conditionalSections.length > 0 ? conditionalSections.some(
|
|
35691
|
-
(conditionalSection) => applyConditions(conditionalSection.getConditions(field.identifier), values)
|
|
35692
|
-
) : true;
|
|
35693
|
-
if (conditionMet) continue;
|
|
35694
|
-
} else {
|
|
35695
|
-
if (!(field instanceof BaseField)) {
|
|
35696
|
-
throw new Error("Invalid field type");
|
|
35697
|
-
}
|
|
35698
|
-
const id = field.identifier;
|
|
35699
|
-
const error = field.getError(get(values, id));
|
|
35700
|
-
if (error) set(errors, id, error);
|
|
35701
|
-
}
|
|
35702
|
-
}
|
|
35703
|
-
if (Object.keys(errors).length > 0) return errors;
|
|
35704
|
-
};
|
|
35705
35698
|
const separateImagesFromFields = async (fields) => {
|
|
35706
35699
|
const images = {};
|
|
35707
35700
|
const newFields = [];
|
|
35708
35701
|
for (const section of fields) {
|
|
35709
|
-
if (section.type !== "section") {
|
|
35710
|
-
throw new Error(`Expected ISerializedField type to be a section. Got ${section.type} instead.`);
|
|
35711
|
-
}
|
|
35712
35702
|
const { fields: sectionFields } = section;
|
|
35713
35703
|
const newSectionFields = [];
|
|
35714
35704
|
for (const field of sectionFields) {
|
|
@@ -35764,9 +35754,9 @@ const FormRenderer = memo(
|
|
|
35764
35754
|
}, [schema.fields, values]);
|
|
35765
35755
|
const handleSubmit = useCallback(
|
|
35766
35756
|
(values2) => {
|
|
35767
|
-
onSubmit == null ? void 0 : onSubmit(
|
|
35757
|
+
void (onSubmit == null ? void 0 : onSubmit(
|
|
35768
35758
|
excludeUnchangedFields ? changedFieldValues(flattenFields(schema.fields), initialValues, values2) : values2
|
|
35769
|
-
);
|
|
35759
|
+
));
|
|
35770
35760
|
},
|
|
35771
35761
|
[excludeUnchangedFields, initialValues, onSubmit, schema.fields]
|
|
35772
35762
|
);
|
|
@@ -35876,43 +35866,39 @@ const FormBuilderRoot = memo((props) => {
|
|
|
35876
35866
|
enableReinitialize = false,
|
|
35877
35867
|
disableRequiredFields = false
|
|
35878
35868
|
} = props;
|
|
35879
|
-
const
|
|
35880
|
-
|
|
35881
|
-
|
|
35882
|
-
|
|
35883
|
-
|
|
35884
|
-
|
|
35885
|
-
|
|
35886
|
-
|
|
35887
|
-
|
|
35888
|
-
|
|
35889
|
-
|
|
35890
|
-
const
|
|
35891
|
-
|
|
35892
|
-
|
|
35893
|
-
|
|
35894
|
-
|
|
35895
|
-
|
|
35896
|
-
|
|
35897
|
-
|
|
35898
|
-
|
|
35899
|
-
|
|
35900
|
-
|
|
35901
|
-
|
|
35902
|
-
|
|
35903
|
-
|
|
35904
|
-
|
|
35905
|
-
|
|
35906
|
-
|
|
35907
|
-
|
|
35908
|
-
|
|
35909
|
-
|
|
35910
|
-
|
|
35911
|
-
|
|
35912
|
-
}
|
|
35913
|
-
},
|
|
35914
|
-
[showError]
|
|
35915
|
-
);
|
|
35869
|
+
const validate = useCallback((form) => {
|
|
35870
|
+
var _a2;
|
|
35871
|
+
const errors = {};
|
|
35872
|
+
if (!form.title) {
|
|
35873
|
+
errors.title = "Title is required.";
|
|
35874
|
+
}
|
|
35875
|
+
if (!form.fields || form.fields.length === 0) {
|
|
35876
|
+
errors.fields = "At least one field is required.";
|
|
35877
|
+
}
|
|
35878
|
+
const fieldsToValidate = [];
|
|
35879
|
+
for (const [sectionIndex, section] of form.fields.entries())
|
|
35880
|
+
for (const [fieldIndex, field] of section.fields.entries()) {
|
|
35881
|
+
const fieldSettings = ((_a2 = getFieldCreationSchema(field.type, `fields.${sectionIndex}.fields.${fieldIndex}`)) == null ? void 0 : _a2.map(
|
|
35882
|
+
({ field: field2 }) => field2
|
|
35883
|
+
)) ?? [];
|
|
35884
|
+
fieldsToValidate.push(...fieldSettings);
|
|
35885
|
+
}
|
|
35886
|
+
const values = {};
|
|
35887
|
+
for (const field of fieldsToValidate) {
|
|
35888
|
+
values[field.identifier] = get(form, field.identifier);
|
|
35889
|
+
}
|
|
35890
|
+
const fieldErrors = validateFields(fieldsToValidate, values);
|
|
35891
|
+
if (fieldErrors) {
|
|
35892
|
+
errors.fields = fieldErrors.fields;
|
|
35893
|
+
}
|
|
35894
|
+
if (Object.keys(errors).length > 0) {
|
|
35895
|
+
toast.error({
|
|
35896
|
+
title: "Some form settings are invalid",
|
|
35897
|
+
description: "Please check settings highlighted in red."
|
|
35898
|
+
});
|
|
35899
|
+
return errors;
|
|
35900
|
+
}
|
|
35901
|
+
}, []);
|
|
35916
35902
|
const initialValues = useMemo(
|
|
35917
35903
|
() => ({
|
|
35918
35904
|
title: initialTitle ?? "",
|
|
@@ -35931,7 +35917,7 @@ const FormBuilderRoot = memo((props) => {
|
|
|
35931
35917
|
});
|
|
35932
35918
|
const observer = useCallback(
|
|
35933
35919
|
(fieldSchema) => {
|
|
35934
|
-
formik.setFieldValue("fields", fieldSchema.serialize());
|
|
35920
|
+
void formik.setFieldValue("fields", fieldSchema.serialize());
|
|
35935
35921
|
},
|
|
35936
35922
|
[formik]
|
|
35937
35923
|
);
|
|
@@ -36078,13 +36064,11 @@ export {
|
|
|
36078
36064
|
UploadFieldCondition,
|
|
36079
36065
|
UploadFieldConditionCell,
|
|
36080
36066
|
UploadInput,
|
|
36081
|
-
applyConditions,
|
|
36082
36067
|
areFileAndPromiseArraysEqual,
|
|
36083
36068
|
arePassFieldValuesEqual,
|
|
36084
36069
|
awaitFilesAndPromises,
|
|
36085
36070
|
changedFieldValues,
|
|
36086
36071
|
cleanFieldValues,
|
|
36087
|
-
cleanFields,
|
|
36088
36072
|
cleanSerializedFieldValues,
|
|
36089
36073
|
createCondition,
|
|
36090
36074
|
createConditionModifierConfig,
|
|
@@ -36125,3 +36109,4 @@ export {
|
|
|
36125
36109
|
useScanner,
|
|
36126
36110
|
validateFields
|
|
36127
36111
|
};
|
|
36112
|
+
//# sourceMappingURL=forms.js.map
|