@wix/form-public 0.40.0 → 0.41.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/index.cjs CHANGED
@@ -15836,6 +15836,9 @@ var import_extends = __toESM(require_extends());
15836
15836
  init_esm();
15837
15837
 
15838
15838
  // ../../node_modules/@wix/bi-logger-forms-platform-uou/dist/esm/v2/index.js
15839
+ function formFieldEdit(params) {
15840
+ return { evid: 1002, src: 156, endpoint: "forms-platform-uou", params };
15841
+ }
15839
15842
  function formFieldFocus(params) {
15840
15843
  return { evid: 1004, src: 156, endpoint: "forms-platform-uou", params };
15841
15844
  }
@@ -18556,180 +18559,662 @@ var validateBirthdate = (_ref) => {
18556
18559
  return void 0;
18557
18560
  };
18558
18561
 
18559
- // ../../node_modules/fast-equals/dist/esm/index.mjs
18560
- var getOwnPropertyNames = Object.getOwnPropertyNames;
18561
- var getOwnPropertySymbols = Object.getOwnPropertySymbols;
18562
- var hasOwnProperty = Object.prototype.hasOwnProperty;
18563
- function combineComparators(comparatorA, comparatorB) {
18564
- return function isEqual(a, b, state) {
18565
- return comparatorA(a, b, state) && comparatorB(a, b, state);
18566
- };
18562
+ // ../form-viewer/dist/esm/services/utils.js
18563
+ var RATING_VALUES = [1, 2, 3, 4, 5];
18564
+ function isObject3(value) {
18565
+ return typeof value === "object" && !Array.isArray(value) && value !== null;
18567
18566
  }
18568
- function createIsCircular(areItemsEqual) {
18569
- return function isCircular(a, b, state) {
18570
- if (!a || !b || typeof a !== "object" || typeof b !== "object") {
18571
- return areItemsEqual(a, b, state);
18572
- }
18573
- var cache = state.cache;
18574
- var cachedA = cache.get(a);
18575
- var cachedB = cache.get(b);
18576
- if (cachedA && cachedB) {
18577
- return cachedA === b && cachedB === a;
18578
- }
18579
- cache.set(a, b);
18580
- cache.set(b, a);
18581
- var result2 = areItemsEqual(a, b, state);
18582
- cache.delete(a);
18583
- cache.delete(b);
18584
- return result2;
18585
- };
18567
+ function isString(value) {
18568
+ return typeof value === "string";
18586
18569
  }
18587
- function getStrictProperties(object) {
18588
- return getOwnPropertyNames(object).concat(getOwnPropertySymbols(object));
18570
+ function isNumber(value) {
18571
+ return typeof value === "number" && !Number.isNaN(value);
18589
18572
  }
18590
- var hasOwn = Object.hasOwn || (function(object, property) {
18591
- return hasOwnProperty.call(object, property);
18592
- });
18593
- function sameValueZeroEqual(a, b) {
18594
- return a === b || !a && !b && a !== a && b !== b;
18573
+ function isRating(value) {
18574
+ return typeof value === "number" && RATING_VALUES.includes(value);
18595
18575
  }
18596
- var PREACT_VNODE = "__v";
18597
- var PREACT_OWNER = "__o";
18598
- var REACT_OWNER = "_owner";
18599
- var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
18600
- var keys = Object.keys;
18601
- function areArraysEqual(a, b, state) {
18602
- var index = a.length;
18603
- if (b.length !== index) {
18604
- return false;
18605
- }
18606
- while (index-- > 0) {
18607
- if (!state.equals(a[index], b[index], index, index, a, b, state)) {
18608
- return false;
18576
+
18577
+ // ../form-viewer/dist/esm/services/has-multiline-address.js
18578
+ var hasMultilineAddress = (form, { excludeEcomAddress } = {
18579
+ excludeEcomAddress: false
18580
+ }) => {
18581
+ const fields = [...form?.fields || [], ...form?.deletedFields || []];
18582
+ return fields.some((field) => field.view?.fieldType === "MULTILINE_ADDRESS" || field.view?.fieldType === "BOOKINGS_ADDRESS" || !excludeEcomAddress && field.view?.fieldType === "ECOM_ADDRESS");
18583
+ };
18584
+
18585
+ // ../form-viewer/dist/esm/services/validation.js
18586
+ var removeFalsyValues = (values = {}) => {
18587
+ return Object.keys(values).reduce((withoutFalsy, target) => {
18588
+ const value = values[target];
18589
+ if (value === "" || typeof value === "undefined" || value === null) {
18590
+ return withoutFalsy;
18591
+ }
18592
+ if (Array.isArray(value) && !value.length) {
18593
+ return withoutFalsy;
18594
+ }
18595
+ if (isObject3(value)) {
18596
+ withoutFalsy[target] = removeFalsyValues(value);
18597
+ } else {
18598
+ withoutFalsy[target] = value;
18609
18599
  }
18600
+ return withoutFalsy;
18601
+ }, {});
18602
+ };
18603
+ var getFormValidator = async (form, addressTemplates, validationMode) => {
18604
+ const [{ FormValidator: FormValidator2 }, { MultilineAddressToolkit: MultilineAddressToolkit2 }] = await Promise.all([
18605
+ Promise.resolve().then(() => (init_esm(), esm_exports)),
18606
+ Promise.resolve().then(() => (init_esm2(), esm_exports2))
18607
+ ]);
18608
+ if (addressTemplates?.length) {
18609
+ const addressForms = addressTemplates.map((template) => template.template);
18610
+ const addressToolkit = new MultilineAddressToolkit2(addressForms);
18611
+ return new FormValidator2([form], validationMode, false, addressToolkit.getFormForValidation, addressToolkit.normalizeEmptyValues, true);
18610
18612
  }
18611
- return true;
18612
- }
18613
- function areDatesEqual(a, b) {
18614
- return sameValueZeroEqual(a.getTime(), b.getTime());
18615
- }
18616
- function areErrorsEqual(a, b) {
18617
- return a.name === b.name && a.message === b.message && a.cause === b.cause && a.stack === b.stack;
18618
- }
18619
- function areFunctionsEqual(a, b) {
18620
- return a === b;
18621
- }
18622
- function areMapsEqual(a, b, state) {
18623
- var size = a.size;
18624
- if (size !== b.size) {
18625
- return false;
18613
+ return new FormValidator2([form], validationMode, void 0, void 0, void 0, true);
18614
+ };
18615
+ var validate = async (form, values, addressTemplates, validationMode) => {
18616
+ if (!form.id) {
18617
+ return;
18626
18618
  }
18627
- if (!size) {
18628
- return true;
18619
+ const formValidator = await getFormValidator(form, addressTemplates, validationMode);
18620
+ return formValidator.validate(form.id, hasMultilineAddress(form, { excludeEcomAddress: true }) ? values : removeFalsyValues(values));
18621
+ };
18622
+ var validateFields = async (form, values, addressTemplates, validationMode) => {
18623
+ if (!form.id) {
18624
+ return;
18629
18625
  }
18630
- var matchedIndices = new Array(size);
18631
- var aIterable = a.entries();
18632
- var aResult;
18633
- var bResult;
18634
- var index = 0;
18635
- while (aResult = aIterable.next()) {
18636
- if (aResult.done) {
18637
- break;
18638
- }
18639
- var bIterable = b.entries();
18640
- var hasMatch = false;
18641
- var matchIndex = 0;
18642
- while (bResult = bIterable.next()) {
18643
- if (bResult.done) {
18644
- break;
18626
+ const formValidator = await getFormValidator(form, addressTemplates, validationMode);
18627
+ return formValidator.validateFields(form.id, hasMultilineAddress(form) ? values : removeFalsyValues(values));
18628
+ };
18629
+
18630
+ // ../form-viewer/dist/esm/services/apply-nested-forms.js
18631
+ function applyNestedForms(form, nestedFormsById) {
18632
+ if (!form.nestedForms && !nestedFormsById) {
18633
+ return form;
18634
+ }
18635
+ const nestedFormsByTarget = getNestedFormsByTarget(form);
18636
+ return {
18637
+ ...form,
18638
+ fields: form.fields?.map((field) => {
18639
+ const fieldTarget = field.target;
18640
+ if (!fieldTarget) {
18641
+ return field;
18645
18642
  }
18646
- if (matchedIndices[matchIndex]) {
18647
- matchIndex++;
18648
- continue;
18643
+ const nestedFormId = field.nestedFormId;
18644
+ if (!nestedFormId) {
18645
+ return field;
18649
18646
  }
18650
- var aEntry = aResult.value;
18651
- var bEntry = bResult.value;
18652
- if (state.equals(aEntry[0], bEntry[0], index, matchIndex, a, b, state) && state.equals(aEntry[1], bEntry[1], aEntry[0], bEntry[0], a, b, state)) {
18653
- hasMatch = matchedIndices[matchIndex] = true;
18654
- break;
18647
+ const nestedForm = nestedFormsByTarget?.[fieldTarget] ?? nestedFormsById?.[nestedFormId];
18648
+ if (nestedForm) {
18649
+ return { ...field, view: { ...field.view, form: nestedForm } };
18655
18650
  }
18656
- matchIndex++;
18657
- }
18658
- if (!hasMatch) {
18659
- return false;
18660
- }
18661
- index++;
18662
- }
18663
- return true;
18664
- }
18665
- var areNumbersEqual = sameValueZeroEqual;
18666
- function areObjectsEqual(a, b, state) {
18667
- var properties = keys(a);
18668
- var index = properties.length;
18669
- if (keys(b).length !== index) {
18670
- return false;
18671
- }
18672
- while (index-- > 0) {
18673
- if (!isPropertyEqual(a, b, state, properties[index])) {
18674
- return false;
18675
- }
18676
- }
18677
- return true;
18651
+ return field;
18652
+ })
18653
+ };
18678
18654
  }
18679
- function areObjectsEqualStrict(a, b, state) {
18680
- var properties = getStrictProperties(a);
18681
- var index = properties.length;
18682
- if (getStrictProperties(b).length !== index) {
18683
- return false;
18684
- }
18685
- var property;
18686
- var descriptorA;
18687
- var descriptorB;
18688
- while (index-- > 0) {
18689
- property = properties[index];
18690
- if (!isPropertyEqual(a, b, state, property)) {
18691
- return false;
18655
+ function getNestedFormsByTarget(form) {
18656
+ return form.nestedForms?.reduce((byTarget, { targets, form: nestedForm }) => {
18657
+ if (!nestedForm || !targets) {
18658
+ return byTarget;
18692
18659
  }
18693
- descriptorA = getOwnPropertyDescriptor(a, property);
18694
- descriptorB = getOwnPropertyDescriptor(b, property);
18695
- if ((descriptorA || descriptorB) && (!descriptorA || !descriptorB || descriptorA.configurable !== descriptorB.configurable || descriptorA.enumerable !== descriptorB.enumerable || descriptorA.writable !== descriptorB.writable)) {
18696
- return false;
18660
+ for (const target of targets) {
18661
+ byTarget[target] = nestedForm;
18697
18662
  }
18698
- }
18699
- return true;
18700
- }
18701
- function arePrimitiveWrappersEqual(a, b) {
18702
- return sameValueZeroEqual(a.valueOf(), b.valueOf());
18663
+ return byTarget;
18664
+ }, {});
18703
18665
  }
18704
- function areRegExpsEqual(a, b) {
18705
- return a.source === b.source && a.flags === b.flags;
18666
+ function getNestedFormArray(formsByTarget) {
18667
+ return Object.keys(formsByTarget).map((target) => {
18668
+ return { targets: [target], form: formsByTarget[target] };
18669
+ });
18706
18670
  }
18707
- function areSetsEqual(a, b, state) {
18708
- var size = a.size;
18709
- if (size !== b.size) {
18710
- return false;
18711
- }
18712
- if (!size) {
18713
- return true;
18714
- }
18715
- var matchedIndices = new Array(size);
18716
- var aIterable = a.values();
18717
- var aResult;
18718
- var bResult;
18719
- while (aResult = aIterable.next()) {
18720
- if (aResult.done) {
18721
- break;
18671
+
18672
+ // ../form-viewer/dist/esm/services/additional-field-validation.js
18673
+ var runAdditionalValidation = ({ form, values, externalData }) => {
18674
+ const additionalErrors = form.fields?.reduce((acc, field) => {
18675
+ const fieldTarget = field.target;
18676
+ if (!fieldTarget) {
18677
+ return acc;
18722
18678
  }
18723
- var bIterable = b.values();
18724
- var hasMatch = false;
18725
- var matchIndex = 0;
18726
- while (bResult = bIterable.next()) {
18727
- if (bResult.done) {
18728
- break;
18729
- }
18730
- if (!matchedIndices[matchIndex] && state.equals(aResult.value, bResult.value, aResult.value, bResult.value, a, b, state)) {
18731
- hasMatch = matchedIndices[matchIndex] = true;
18732
- break;
18679
+ const fieldType = field?.view?.fieldType;
18680
+ const fieldValue = values[fieldTarget];
18681
+ const validateField = ADDITIONAL_FIELD_VALIDATION[fieldType];
18682
+ const error = validateField?.({
18683
+ value: fieldValue,
18684
+ target: fieldTarget,
18685
+ externalData
18686
+ });
18687
+ if (error) {
18688
+ acc[fieldTarget] = error;
18689
+ }
18690
+ return acc;
18691
+ }, {});
18692
+ return additionalErrors;
18693
+ };
18694
+ var ADDITIONAL_FIELD_VALIDATION = {
18695
+ [FIELD_TYPES.TEXT_INPUT]: null,
18696
+ [FIELD_TYPES.CHECKBOX_GROUP]: null,
18697
+ [FIELD_TYPES.RADIO_GROUP]: null,
18698
+ [FIELD_TYPES.DONATION]: null,
18699
+ [FIELD_TYPES.DROPDOWN]: null,
18700
+ [FIELD_TYPES.URL_INPUT]: null,
18701
+ [FIELD_TYPES.NUMBER_INPUT]: null,
18702
+ [FIELD_TYPES.QUIZ_NUMBER]: null,
18703
+ [FIELD_TYPES.QUIZ_SHORT_TEXT]: null,
18704
+ [FIELD_TYPES.QUIZ_LONG_TEXT]: null,
18705
+ [FIELD_TYPES.QUIZ_MULTI_CHOICE]: null,
18706
+ [FIELD_TYPES.QUIZ_IMAGE_CHOICE]: null,
18707
+ [FIELD_TYPES.QUIZ_SINGLE_CHOICE]: null,
18708
+ [FIELD_TYPES.QUIZ_FILE_UPLOAD]: null,
18709
+ [FIELD_TYPES.FILE_UPLOAD]: null,
18710
+ [FIELD_TYPES.SIGNATURE]: null,
18711
+ [FIELD_TYPES.CONTACTS_EMAIL]: null,
18712
+ [FIELD_TYPES.CONTACTS_PHONE]: null,
18713
+ [FIELD_TYPES.CHECKBOX]: null,
18714
+ [FIELD_TYPES.DATE_INPUT]: null,
18715
+ [FIELD_TYPES.DATE_TIME_INPUT]: null,
18716
+ [FIELD_TYPES.TIME_INPUT]: null,
18717
+ [FIELD_TYPES.DATE_PICKER]: null,
18718
+ [FIELD_TYPES.CONTACTS_COMPANY]: null,
18719
+ [FIELD_TYPES.CONTACTS_POSITION]: null,
18720
+ [FIELD_TYPES.CONTACTS_TAX_ID]: null,
18721
+ [FIELD_TYPES.CONTACTS_FIRST_NAME]: null,
18722
+ [FIELD_TYPES.CONTACTS_LAST_NAME]: null,
18723
+ [FIELD_TYPES.CONTACTS_ADDRESS]: null,
18724
+ [FIELD_TYPES.CONTACTS_BIRTHDATE]: validateBirthdate,
18725
+ [FIELD_TYPES.TEXT_AREA]: null,
18726
+ [FIELD_TYPES.CONTACTS_SUBSCRIBE]: null,
18727
+ [FIELD_TYPES.NESTED_FORM]: null,
18728
+ [FIELD_TYPES.MULTILINE_ADDRESS]: null,
18729
+ [FIELD_TYPES.MLA_COUNTRY]: null,
18730
+ [FIELD_TYPES.MLA_CITY]: null,
18731
+ [FIELD_TYPES.MLA_ADDRESS_LINE]: null,
18732
+ [FIELD_TYPES.MLA_ADDRESS_LINE_2]: null,
18733
+ [FIELD_TYPES.MLA_POSTAL_CODE]: null,
18734
+ [FIELD_TYPES.MLA_SUBDIVISION]: null,
18735
+ [FIELD_TYPES.MLA_STREET_NAME]: null,
18736
+ [FIELD_TYPES.MLA_STREET_NUMBER]: null,
18737
+ [FIELD_TYPES.MLA_APARTMENT]: null,
18738
+ [FIELD_TYPES.FULL_NAME_FIRST_NAME]: null,
18739
+ [FIELD_TYPES.FULL_NAME_LAST_NAME]: null,
18740
+ [FIELD_TYPES.FULL_NAME]: null,
18741
+ [FIELD_TYPES.DEXT_TEXT_INPUT]: null,
18742
+ [FIELD_TYPES.DEXT_NUMBER_INPUT]: null,
18743
+ [FIELD_TYPES.DEXT_CHECKBOX]: null,
18744
+ [FIELD_TYPES.DEXT_CHECKBOX_GROUP]: null,
18745
+ [FIELD_TYPES.DEXT_TAGS]: null,
18746
+ [FIELD_TYPES.DEXT_RATING_INPUT]: null,
18747
+ [FIELD_TYPES.ECOM_ADDITIONAL_INFO]: null,
18748
+ [FIELD_TYPES.ECOM_ADDRESS]: null,
18749
+ [FIELD_TYPES.ECOM_PHONE]: null,
18750
+ [FIELD_TYPES.ECOM_FULL_NAME]: null,
18751
+ [FIELD_TYPES.ECOM_COMPANY_NAME]: null,
18752
+ [FIELD_TYPES.ECOM_EMAIL]: null,
18753
+ [FIELD_TYPES.ECOM_SUBSCRIPTION]: null,
18754
+ [FIELD_TYPES.DEXT_TEXT_AREA]: null,
18755
+ [FIELD_TYPES.DEXT_DROPDOWN]: null,
18756
+ [FIELD_TYPES.DEXT_RADIO_GROUP]: null,
18757
+ [FIELD_TYPES.DEXT_URL_INPUT]: null,
18758
+ [FIELD_TYPES.DEXT_EMAIL]: null,
18759
+ [FIELD_TYPES.DEXT_PHONE]: null,
18760
+ [FIELD_TYPES.DEXT_DATE_PICKER]: null,
18761
+ [FIELD_TYPES.VAT_ID]: validateVatID,
18762
+ [FIELD_TYPES.PRODUCT_LIST]: null,
18763
+ [FIELD_TYPES.RATING_INPUT]: null,
18764
+ [FIELD_TYPES.TAGS]: null,
18765
+ [FIELD_TYPES.PAYMENT_INPUT]: null,
18766
+ [FIELD_TYPES.FIXED_PAYMENT]: null,
18767
+ [FIELD_TYPES.BOOKINGS_FIRST_NAME]: null,
18768
+ [FIELD_TYPES.BOOKINGS_LAST_NAME]: null,
18769
+ [FIELD_TYPES.BOOKINGS_EMAIL]: null,
18770
+ [FIELD_TYPES.BOOKINGS_PHONE]: null,
18771
+ [FIELD_TYPES.BOOKINGS_ADDRESS]: null,
18772
+ [FIELD_TYPES.APPOINTMENT]: null,
18773
+ [FIELD_TYPES.IDENTITY_PASSWORD]: null,
18774
+ [FIELD_TYPES.SERVICES_DROPDOWN]: null,
18775
+ [FIELD_TYPES.SERVICES_MULTI_CHOICE]: null,
18776
+ [FIELD_TYPES.EVENTS_RSVP]: null,
18777
+ [FIELD_TYPES.EVENTS_REPEATER]: null
18778
+ };
18779
+
18780
+ // ../form-viewer/dist/esm/services/get-field-errors.js
18781
+ var getFieldErrors = async (fieldsToValidate, form, addressTemplates, externalData, validationMode) => {
18782
+ const formValues = fieldsToValidate.reduce((acc, field) => setValue(acc, field.path, field.value), {});
18783
+ const result2 = await validateFields(form, formValues, addressTemplates, validationMode);
18784
+ const _errors = result2?.errors || [];
18785
+ const additionalErrors = runAdditionalValidation({
18786
+ form,
18787
+ values: formValues,
18788
+ externalData
18789
+ });
18790
+ const allErrors = mergeErrors({ errors: _errors, additionalErrors });
18791
+ const fieldErrors = allErrors.filter((error) => findErrorByNormalizedPath(fieldsToValidate, error.errorPath));
18792
+ return fieldErrors;
18793
+ };
18794
+ var findErrorByNormalizedPath = (fieldsToValidate, errorPath) => {
18795
+ const path = errorPath.split("/").length > 2 ? errorPath.split("/").at(0) : errorPath;
18796
+ return !!fieldsToValidate.find((field) => path === field.path);
18797
+ };
18798
+ function setValue(object, path, value) {
18799
+ const delimiter = "/";
18800
+ const decomposedPath = path.split(delimiter);
18801
+ const base = decomposedPath[0];
18802
+ if (base === void 0) {
18803
+ return object;
18804
+ }
18805
+ if (!object.hasOwnProperty(base)) {
18806
+ object[base] = {};
18807
+ }
18808
+ value = decomposedPath.length <= 1 ? value : setValue(object[base], decomposedPath.slice(1).join(delimiter), value);
18809
+ return {
18810
+ ...object,
18811
+ [base]: value
18812
+ };
18813
+ }
18814
+ var mergeErrors = ({ errors, additionalErrors }) => {
18815
+ const errorsToAdd = [];
18816
+ if (additionalErrors) {
18817
+ Object.keys(additionalErrors).forEach((fieldTarget) => {
18818
+ const errorExists = errors.find((error) => error.errorPath === fieldTarget);
18819
+ if (!errorExists) {
18820
+ errorsToAdd.push(additionalErrors[fieldTarget]);
18821
+ }
18822
+ });
18823
+ }
18824
+ return [...errors, ...errorsToAdd];
18825
+ };
18826
+
18827
+ // ../form-viewer/dist/esm/services/form-overrides.js
18828
+ function applyFormOverrides(form, overrides, recursive = true) {
18829
+ const nestedFormsByTarget = getNestedFormsByTarget(form);
18830
+ const fields = (form.fields ?? []).map((field) => {
18831
+ const override = getOverride({
18832
+ id: field.id,
18833
+ target: field.target,
18834
+ overrides
18835
+ });
18836
+ if (!override) {
18837
+ return field;
18838
+ }
18839
+ if (field.target && field.nestedFormId && recursive) {
18840
+ const nestedForm = nestedFormsByTarget?.[field.target];
18841
+ if (nestedForm) {
18842
+ nestedFormsByTarget[field.target] = applyFormOverrides(nestedForm, override, false);
18843
+ }
18844
+ return field;
18845
+ }
18846
+ let validation = field.validation;
18847
+ let options = {};
18848
+ if (Array.isArray(override.countries)) {
18849
+ validation = {
18850
+ ...validation,
18851
+ string: {
18852
+ ...validation?.string,
18853
+ enum: override.countries
18854
+ }
18855
+ };
18856
+ options = override.countries ? {
18857
+ options: override.countries?.map((country) => ({ value: country }))
18858
+ } : {};
18859
+ }
18860
+ if (field.view?.fieldType === "MULTILINE_ADDRESS") {
18861
+ return applyMultilineAddressOverrides({
18862
+ field,
18863
+ override
18864
+ });
18865
+ }
18866
+ return {
18867
+ ...field,
18868
+ ...pick(override, "hidden"),
18869
+ ...pick(override, "readOnly"),
18870
+ view: {
18871
+ ...field.view,
18872
+ ...pick(override, "label"),
18873
+ ...pick(override, "autocomplete"),
18874
+ ...pick(override, "disabled"),
18875
+ ...options
18876
+ },
18877
+ validation: {
18878
+ ...validation,
18879
+ ...pick(override, "required")
18880
+ }
18881
+ };
18882
+ });
18883
+ const nestedForms = nestedFormsByTarget ? getNestedFormArray(nestedFormsByTarget) : void 0;
18884
+ return {
18885
+ ...form,
18886
+ fields,
18887
+ ...nestedForms ? { nestedForms } : {}
18888
+ };
18889
+ }
18890
+ function pick(override, key) {
18891
+ return override.hasOwnProperty(key) ? { [key]: override[key] } : {};
18892
+ }
18893
+ var getOverride = ({ target, id, overrides }) => {
18894
+ if (target && target in overrides) {
18895
+ return overrides[target];
18896
+ }
18897
+ if (id && id in overrides) {
18898
+ return overrides[id];
18899
+ }
18900
+ return void 0;
18901
+ };
18902
+ var applyAddressFieldOverride = (fieldName, override, multilineAddressOptionsFields, multilineAddressFieldSettings) => {
18903
+ const fieldOverride = override[fieldName];
18904
+ if (!fieldOverride) {
18905
+ return {
18906
+ multilineAddressOptionsFields,
18907
+ multilineAddressFieldSettings
18908
+ };
18909
+ }
18910
+ return {
18911
+ multilineAddressOptionsFields: {
18912
+ ...multilineAddressOptionsFields,
18913
+ [fieldName]: {
18914
+ required: fieldOverride.required
18915
+ }
18916
+ },
18917
+ multilineAddressFieldSettings: {
18918
+ ...multilineAddressFieldSettings,
18919
+ [fieldName]: {
18920
+ ...multilineAddressFieldSettings?.[fieldName],
18921
+ show: !fieldOverride.hidden
18922
+ }
18923
+ }
18924
+ };
18925
+ };
18926
+ var ADDRESS_FIELD_NAMES = [
18927
+ "addressLine",
18928
+ "addressLine2",
18929
+ "streetName",
18930
+ "streetNumber",
18931
+ "city",
18932
+ "postalCode",
18933
+ "subdivision",
18934
+ "country",
18935
+ "apartment"
18936
+ ];
18937
+ var applyMultilineAddressOverrides = ({ field, override }) => {
18938
+ const finalState = ADDRESS_FIELD_NAMES.reduce((state, fieldName) => applyAddressFieldOverride(fieldName, override, state.multilineAddressOptionsFields ?? {}, state.multilineAddressFieldSettings ?? {}), {
18939
+ multilineAddressOptionsFields: field.validation?.predefined?.multilineAddressOptions?.fields,
18940
+ multilineAddressFieldSettings: field.view?.fieldSettings
18941
+ });
18942
+ const autocompleteEnabled = (override.addressLine?.autocomplete || override.streetName?.autocomplete) ?? true;
18943
+ const multilineAddressOptions = {
18944
+ ...field.validation?.predefined?.multilineAddressOptions,
18945
+ fields: {
18946
+ ...field.validation?.predefined?.multilineAddressOptions?.fields,
18947
+ ...finalState.multilineAddressOptionsFields
18948
+ },
18949
+ ...Array.isArray(override.countries) && override.countries.length > 0 ? { allowedCountries: override.countries } : {}
18950
+ };
18951
+ return {
18952
+ ...field,
18953
+ view: {
18954
+ ...field.view,
18955
+ fieldSettings: {
18956
+ ...field.view?.fieldSettings,
18957
+ ...finalState.multilineAddressFieldSettings
18958
+ },
18959
+ autocompleteEnabled
18960
+ },
18961
+ validation: {
18962
+ ...field.validation,
18963
+ predefined: {
18964
+ ...field.validation?.predefined,
18965
+ multilineAddressOptions
18966
+ }
18967
+ }
18968
+ };
18969
+ };
18970
+
18971
+ // ../form-viewer/dist/esm/hooks/use-validation.js
18972
+ var useValidation = ({ form, errorsRef, setErrors, validationMode }) => {
18973
+ const { addressTemplates } = useAddressForms();
18974
+ const externalData = useExternalData();
18975
+ const validateFields2 = React14.useCallback(async (newValues) => {
18976
+ const result2 = await validate(form, newValues, addressTemplates, validationMode);
18977
+ const _errors = result2?.errors || [];
18978
+ const additionalErrors = runAdditionalValidation({
18979
+ form,
18980
+ values: newValues,
18981
+ externalData
18982
+ });
18983
+ const allErrors = mergeErrors({ errors: _errors, additionalErrors });
18984
+ setErrors(allErrors);
18985
+ return allErrors;
18986
+ }, [form, setErrors, addressTemplates, externalData, validationMode]);
18987
+ const handleFieldValidation = React14.useCallback(async (fieldsToValidate) => {
18988
+ const fieldErrors = await getFieldErrors(fieldsToValidate, form, addressTemplates, externalData, validationMode);
18989
+ const otherErrors = (errorsRef.current ?? []).filter((error) => {
18990
+ return !findErrorByNormalizedPath(fieldsToValidate, error.errorPath);
18991
+ });
18992
+ const allErrors = [...otherErrors, ...fieldErrors];
18993
+ setErrors(allErrors);
18994
+ return allErrors;
18995
+ }, [
18996
+ errorsRef,
18997
+ form,
18998
+ setErrors,
18999
+ addressTemplates,
19000
+ externalData,
19001
+ validationMode
19002
+ ]);
19003
+ const validateStep = React14.useCallback(async (stepId, newValues) => {
19004
+ const items = form?.steps?.find((step) => step.id === stepId)?.layout?.large?.items || [];
19005
+ const validationErrors = await Promise.all(items.map(async (item) => {
19006
+ const field = form?.fields?.find((_field) => _field.id === item.fieldId);
19007
+ const fieldValidationResult = field?.target ? await handleFieldValidation([
19008
+ {
19009
+ path: field.target,
19010
+ value: newValues[field.target]
19011
+ }
19012
+ ]) : [];
19013
+ return fieldValidationResult;
19014
+ }));
19015
+ const validationErrorsFlatten = validationErrors.flat();
19016
+ setErrors(validationErrorsFlatten);
19017
+ return !validationErrorsFlatten.length;
19018
+ }, [form, setErrors, handleFieldValidation]);
19019
+ return { validateFields: validateFields2, validateStep, handleFieldValidation };
19020
+ };
19021
+ var SubmitStatusContext = React14.createContext(void 0);
19022
+ var SubmitStatusProvider = ({ children }) => {
19023
+ const [submitSuccessMessage, setSubmitSuccessMessage] = React14.useState();
19024
+ const [submitFailureCode, setSubmitFailureCode] = React14.useState();
19025
+ const [submitFailureMessage, setSubmitFailureMessage] = React14.useState();
19026
+ const value = React14.useMemo(() => ({
19027
+ submitSuccessMessage,
19028
+ submitFailureCode,
19029
+ submitFailureMessage,
19030
+ setSubmitSuccessMessage,
19031
+ setSubmitFailureCode,
19032
+ setSubmitFailureMessage
19033
+ }), [submitSuccessMessage, submitFailureCode, submitFailureMessage]);
19034
+ return React14__default.default.createElement(SubmitStatusContext.Provider, { value }, children);
19035
+ };
19036
+ var useSubmitStatus = () => {
19037
+ const context = React14.useContext(SubmitStatusContext);
19038
+ if (context === void 0) {
19039
+ throw new Error("useSubmitStatus must be used within a SubmitStatusProvider");
19040
+ }
19041
+ return context;
19042
+ };
19043
+
19044
+ // ../../node_modules/fast-equals/dist/esm/index.mjs
19045
+ var getOwnPropertyNames = Object.getOwnPropertyNames;
19046
+ var getOwnPropertySymbols = Object.getOwnPropertySymbols;
19047
+ var hasOwnProperty = Object.prototype.hasOwnProperty;
19048
+ function combineComparators(comparatorA, comparatorB) {
19049
+ return function isEqual(a, b, state) {
19050
+ return comparatorA(a, b, state) && comparatorB(a, b, state);
19051
+ };
19052
+ }
19053
+ function createIsCircular(areItemsEqual) {
19054
+ return function isCircular(a, b, state) {
19055
+ if (!a || !b || typeof a !== "object" || typeof b !== "object") {
19056
+ return areItemsEqual(a, b, state);
19057
+ }
19058
+ var cache = state.cache;
19059
+ var cachedA = cache.get(a);
19060
+ var cachedB = cache.get(b);
19061
+ if (cachedA && cachedB) {
19062
+ return cachedA === b && cachedB === a;
19063
+ }
19064
+ cache.set(a, b);
19065
+ cache.set(b, a);
19066
+ var result2 = areItemsEqual(a, b, state);
19067
+ cache.delete(a);
19068
+ cache.delete(b);
19069
+ return result2;
19070
+ };
19071
+ }
19072
+ function getStrictProperties(object) {
19073
+ return getOwnPropertyNames(object).concat(getOwnPropertySymbols(object));
19074
+ }
19075
+ var hasOwn = Object.hasOwn || (function(object, property) {
19076
+ return hasOwnProperty.call(object, property);
19077
+ });
19078
+ function sameValueZeroEqual(a, b) {
19079
+ return a === b || !a && !b && a !== a && b !== b;
19080
+ }
19081
+ var PREACT_VNODE = "__v";
19082
+ var PREACT_OWNER = "__o";
19083
+ var REACT_OWNER = "_owner";
19084
+ var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
19085
+ var keys = Object.keys;
19086
+ function areArraysEqual(a, b, state) {
19087
+ var index = a.length;
19088
+ if (b.length !== index) {
19089
+ return false;
19090
+ }
19091
+ while (index-- > 0) {
19092
+ if (!state.equals(a[index], b[index], index, index, a, b, state)) {
19093
+ return false;
19094
+ }
19095
+ }
19096
+ return true;
19097
+ }
19098
+ function areDatesEqual(a, b) {
19099
+ return sameValueZeroEqual(a.getTime(), b.getTime());
19100
+ }
19101
+ function areErrorsEqual(a, b) {
19102
+ return a.name === b.name && a.message === b.message && a.cause === b.cause && a.stack === b.stack;
19103
+ }
19104
+ function areFunctionsEqual(a, b) {
19105
+ return a === b;
19106
+ }
19107
+ function areMapsEqual(a, b, state) {
19108
+ var size = a.size;
19109
+ if (size !== b.size) {
19110
+ return false;
19111
+ }
19112
+ if (!size) {
19113
+ return true;
19114
+ }
19115
+ var matchedIndices = new Array(size);
19116
+ var aIterable = a.entries();
19117
+ var aResult;
19118
+ var bResult;
19119
+ var index = 0;
19120
+ while (aResult = aIterable.next()) {
19121
+ if (aResult.done) {
19122
+ break;
19123
+ }
19124
+ var bIterable = b.entries();
19125
+ var hasMatch = false;
19126
+ var matchIndex = 0;
19127
+ while (bResult = bIterable.next()) {
19128
+ if (bResult.done) {
19129
+ break;
19130
+ }
19131
+ if (matchedIndices[matchIndex]) {
19132
+ matchIndex++;
19133
+ continue;
19134
+ }
19135
+ var aEntry = aResult.value;
19136
+ var bEntry = bResult.value;
19137
+ if (state.equals(aEntry[0], bEntry[0], index, matchIndex, a, b, state) && state.equals(aEntry[1], bEntry[1], aEntry[0], bEntry[0], a, b, state)) {
19138
+ hasMatch = matchedIndices[matchIndex] = true;
19139
+ break;
19140
+ }
19141
+ matchIndex++;
19142
+ }
19143
+ if (!hasMatch) {
19144
+ return false;
19145
+ }
19146
+ index++;
19147
+ }
19148
+ return true;
19149
+ }
19150
+ var areNumbersEqual = sameValueZeroEqual;
19151
+ function areObjectsEqual(a, b, state) {
19152
+ var properties = keys(a);
19153
+ var index = properties.length;
19154
+ if (keys(b).length !== index) {
19155
+ return false;
19156
+ }
19157
+ while (index-- > 0) {
19158
+ if (!isPropertyEqual(a, b, state, properties[index])) {
19159
+ return false;
19160
+ }
19161
+ }
19162
+ return true;
19163
+ }
19164
+ function areObjectsEqualStrict(a, b, state) {
19165
+ var properties = getStrictProperties(a);
19166
+ var index = properties.length;
19167
+ if (getStrictProperties(b).length !== index) {
19168
+ return false;
19169
+ }
19170
+ var property;
19171
+ var descriptorA;
19172
+ var descriptorB;
19173
+ while (index-- > 0) {
19174
+ property = properties[index];
19175
+ if (!isPropertyEqual(a, b, state, property)) {
19176
+ return false;
19177
+ }
19178
+ descriptorA = getOwnPropertyDescriptor(a, property);
19179
+ descriptorB = getOwnPropertyDescriptor(b, property);
19180
+ if ((descriptorA || descriptorB) && (!descriptorA || !descriptorB || descriptorA.configurable !== descriptorB.configurable || descriptorA.enumerable !== descriptorB.enumerable || descriptorA.writable !== descriptorB.writable)) {
19181
+ return false;
19182
+ }
19183
+ }
19184
+ return true;
19185
+ }
19186
+ function arePrimitiveWrappersEqual(a, b) {
19187
+ return sameValueZeroEqual(a.valueOf(), b.valueOf());
19188
+ }
19189
+ function areRegExpsEqual(a, b) {
19190
+ return a.source === b.source && a.flags === b.flags;
19191
+ }
19192
+ function areSetsEqual(a, b, state) {
19193
+ var size = a.size;
19194
+ if (size !== b.size) {
19195
+ return false;
19196
+ }
19197
+ if (!size) {
19198
+ return true;
19199
+ }
19200
+ var matchedIndices = new Array(size);
19201
+ var aIterable = a.values();
19202
+ var aResult;
19203
+ var bResult;
19204
+ while (aResult = aIterable.next()) {
19205
+ if (aResult.done) {
19206
+ break;
19207
+ }
19208
+ var bIterable = b.values();
19209
+ var hasMatch = false;
19210
+ var matchIndex = 0;
19211
+ while (bResult = bIterable.next()) {
19212
+ if (bResult.done) {
19213
+ break;
19214
+ }
19215
+ if (!matchedIndices[matchIndex] && state.equals(aResult.value, bResult.value, aResult.value, bResult.value, a, b, state)) {
19216
+ hasMatch = matchedIndices[matchIndex] = true;
19217
+ break;
18733
19218
  }
18734
19219
  matchIndex++;
18735
19220
  }
@@ -19011,979 +19496,570 @@ function asUtcDate(value) {
19011
19496
  return null;
19012
19497
  }
19013
19498
  }
19014
- function getNumberValuesToCompare(...values) {
19015
- return values.map((value) => {
19016
- if (typeof value === "string") {
19017
- return getDateUtcTimestamp(value);
19018
- }
19019
- if (typeof value === "number") {
19020
- return value;
19021
- }
19022
- if (isProductSubmission(value)) {
19023
- return getProductPrice(value);
19024
- }
19025
- return null;
19026
- });
19027
- }
19028
- function getDateUtcTimestamp(givenValue) {
19029
- const givenDate = asUtcDate(givenValue);
19030
- return givenDate ? givenDate.getTime() : null;
19031
- }
19032
- function getProductPrice(givenValue) {
19033
- return givenValue[0].price;
19034
- }
19035
- function isObject3(givenValue) {
19036
- return typeof givenValue === "object" && !Array.isArray(givenValue) && givenValue !== null;
19037
- }
19038
- var isArrayOfNumbers = (value) => {
19039
- return value.every((item) => typeof item === "number");
19040
- };
19041
- function isProductSubmission(value) {
19042
- return Array.isArray(value) && value.every((element) => isObject3(element) && "productId" in element && "price" in element && "quantity" in element);
19043
- }
19044
- function isValueEmpty(givenValue) {
19045
- return givenValue === void 0 || givenValue === null || givenValue === "";
19046
- }
19047
- function isValidCondition(rule, fields = []) {
19048
- if (rule === void 0) {
19049
- return true;
19050
- }
19051
- const rulesOrConditions = getRulesOrConditions(rule);
19052
- if (!rulesOrConditions.length) {
19053
- return false;
19054
- }
19055
- return rulesOrConditions.every((conditionOrRule) => {
19056
- if (isCondition(conditionOrRule)) {
19057
- return fields?.some((field) => field.id === conditionOrRule.fact);
19058
- }
19059
- return isValidCondition(conditionOrRule, fields);
19060
- });
19061
- }
19062
- function isFormRuleValid(formRule, formSchema) {
19063
- if (!formRule || !formRule?.overrides?.length || !formSchema) {
19064
- return false;
19065
- }
19066
- const { fieldsV2, fields, nestedForms, formFields } = formSchema;
19067
- const fieldsToCheck = (fields ?? []).concat(fieldsV2 ?? []).concat(formFields ?? []);
19068
- const conditionValid = isValidCondition(formRule.condition, fieldsToCheck);
19069
- const overrideValid = formRule?.overrides.some((override) => {
19070
- if (override.entityType === OverrideEntityType.FORM) {
19071
- return formSchema.id === override.entityId || nestedForms?.some((nestedForm) => nestedForm.form?.id === override.entityId);
19072
- }
19073
- const wasFieldFound = (fieldsToCheck?.map((f) => f.id) ?? []).includes(override.entityId);
19074
- return override.entityId ? wasFieldFound : false;
19075
- });
19076
- return conditionValid && overrideValid;
19077
- }
19078
-
19079
- // ../form-conditions/dist/esm/lib/transform-path-to-v2.js
19080
- var supportedPaths = [
19081
- "hidden",
19082
- "validation.required",
19083
- "validation.string.enum",
19084
- "validation.boolean.enum",
19085
- "validation.predefined.multilineAddressOptions.fields",
19086
- "view.options",
19087
- "view.countryCode"
19088
- ];
19089
- var fieldPathMapToPlatfomized = {
19090
- hidden: ["hidden"],
19091
- "validation.required": ["inputOptions.required"],
19092
- "validation.string.enum": ["inputOptions.stringOptions.validation.enum"],
19093
- "validation.boolean.enum": ["inputOptions.booleanOptions.validation.enum"],
19094
- "view.options": [
19095
- "inputOptions.stringOptions.radioGroupOptions.options",
19096
- "inputOptions.stringOptions.dropdownOptions.options",
19097
- "inputOptions.arrayOptions.checkboxGroupOptions.options"
19098
- ],
19099
- "view.countryCode": []
19100
- };
19101
-
19102
- // ../form-conditions/dist/esm/lib/apply-item-properties-override.js
19103
- var PATH_SEPARATOR = ".";
19104
- function applyItemPropertiesOverride(formSchema, rule) {
19105
- if (rule.overrides) {
19106
- const overriddenFormSchema = applyFormOverride(formSchema, mapOverridesByItem(rule.overrides, isFormOverride, isSupportedFormPath));
19107
- return {
19108
- ...overriddenFormSchema,
19109
- fields: applyItemsOverride(overriddenFormSchema.fields ?? [], mapOverridesByItem(rule.overrides, isFieldOverride, isSupportedFieldPath)),
19110
- ...overriddenFormSchema.fieldsV2 && {
19111
- fieldsV2: applyItemsOverride(overriddenFormSchema.fieldsV2 ?? [], mapOverridesV2ByItem(rule.overrides, isFieldOverride))
19112
- },
19113
- ...overriddenFormSchema.formFields && {
19114
- formFields: applyItemsOverride(overriddenFormSchema.formFields ?? [], mapOverridesV2ByItem(rule.overrides, isFieldOverride))
19115
- }
19116
- };
19117
- }
19118
- return formSchema;
19119
- }
19120
- function applyItemsOverride(items, formItemOverrides) {
19121
- return items.map((formField) => {
19122
- const fieldOverrides = formItemOverrides[asRequired2(formField.id)] || [];
19123
- return fieldOverrides.reduce((acc, override) => setToValue(acc, override.path, override.value), formField);
19124
- });
19125
- }
19126
- function applyFormOverride(formSchema, formItemOverrides) {
19127
- const formOverrides = Object.values(formItemOverrides).flat();
19128
- return formOverrides.reduce((acc, override) => setToValue(acc, override.path, override.value), formSchema);
19129
- }
19130
- function mapOverridesByItem(overrideItems, isOverride, isSupportedPath) {
19131
- return overrideItems.filter(isOverride).reduce((acc, overrideItem) => {
19132
- const entityId = asRequired2(overrideItem.entityId);
19133
- const overrides = Object.entries(overrideItem.valueChanges ?? {}).filter(([path]) => isSupportedPath(path)).map(([path, value]) => ({
19134
- path: path.split(PATH_SEPARATOR),
19135
- value
19136
- }));
19137
- acc[entityId] = [...acc[entityId] || [], ...overrides];
19138
- return acc;
19139
- }, {});
19140
- }
19141
- function mapOverridesV2ByItem(overrideItems, isOverride) {
19142
- return overrideItems.filter(isOverride).reduce((acc, overrideItem) => {
19143
- const entityId = asRequired2(overrideItem.entityId);
19144
- const overrides = Object.entries(overrideItem.valueChanges ?? {}).flatMap(([path, value]) => {
19145
- const resolvedV2Paths = fieldPathMapToPlatfomized[path] || [];
19146
- return resolvedV2Paths.map((pathV2) => [pathV2, value]);
19147
- }).map(([path, value]) => ({
19148
- path: path.split(PATH_SEPARATOR),
19149
- value
19150
- }));
19151
- acc[entityId] = [...acc[entityId] || [], ...overrides];
19152
- return acc;
19153
- }, {});
19154
- }
19155
- function setToValue(obj, pathProps, value) {
19156
- if (value !== void 0 && obj !== void 0) {
19157
- const [prop, ...rest] = pathProps;
19158
- if (rest.length) {
19159
- const valueToSet = setToValue(obj[prop], rest, value);
19160
- if (valueToSet !== void 0) {
19161
- return {
19162
- ...obj,
19163
- [prop]: valueToSet
19164
- };
19165
- }
19166
- return obj;
19167
- }
19168
- return {
19169
- ...obj,
19170
- [prop]: value
19171
- };
19172
- }
19173
- return obj;
19174
- }
19175
- function isFieldOverride(override) {
19176
- return override.entityType === OverrideEntityType.FIELD;
19177
- }
19178
- function isFormOverride(override) {
19179
- return override.entityType === OverrideEntityType.FORM;
19180
- }
19181
- function isSupportedFieldPath(path) {
19182
- return supportedPaths.includes(path);
19183
- }
19184
- function isSupportedFormPath(path) {
19185
- return ["fields", "steps"].includes(path);
19186
- }
19187
-
19188
- // ../form-conditions/dist/esm/lib/evaluate-override-condition.js
19189
- var import_js_rules_engine2 = __toESM(require_dist5());
19190
-
19191
- // ../form-conditions/dist/esm/lib/set-up-operators.js
19192
- var import_js_rules_engine = __toESM(require_dist5());
19193
-
19194
- // ../form-conditions/dist/esm/lib/operators/between.js
19195
- function valueIsBetween(givenValue, expectedValue) {
19196
- if (isValueEmpty(givenValue)) {
19197
- return false;
19198
- }
19199
- if (!Array.isArray(expectedValue) || expectedValue.length !== 2) {
19200
- throw new Error("Expected value should be array of two elements");
19201
- }
19202
- const values = getNumberValuesToCompare(givenValue, expectedValue[0], expectedValue[1]);
19203
- if (isArrayOfNumbers(values)) {
19204
- const [given, firstBound, secondBound] = values;
19205
- return between(given, Math.min(firstBound, secondBound), Math.max(firstBound, secondBound));
19206
- }
19207
- throw new Error(`Between operator: Unsupported values to compare ${givenValue}, ${JSON.stringify(expectedValue)}`);
19208
- }
19209
-
19210
- // ../form-conditions/dist/esm/lib/operators/greater-than.js
19211
- function valueIsGreaterThan(givenValue, expectedValue, orEqual = false) {
19212
- if (isValueEmpty(givenValue)) {
19213
- return false;
19214
- }
19215
- const values = getNumberValuesToCompare(givenValue, expectedValue);
19216
- if (isArrayOfNumbers(values)) {
19217
- const [given, expected] = values;
19218
- return greaterThan(given, expected, orEqual);
19219
- }
19220
- throw new Error(`GreaterThan operator: Unsupported values to compare ${givenValue}, ${expectedValue}`);
19221
- }
19222
-
19223
- // ../form-conditions/dist/esm/lib/operators/less-than.js
19224
- function valueIsLessThan(givenValue, expectedValue, orEqual = false) {
19225
- if (isValueEmpty(givenValue)) {
19226
- return false;
19227
- }
19228
- const values = getNumberValuesToCompare(givenValue, expectedValue);
19229
- if (isArrayOfNumbers(values)) {
19230
- const [given, expected] = values;
19231
- return lessThan(given, expected, orEqual);
19232
- }
19233
- throw new Error(`LessThan operator: Unsupported values to compare ${givenValue}, ${expectedValue}`);
19234
- }
19235
-
19236
- // ../form-conditions/dist/esm/lib/operators/contains.js
19237
- function valueContains(givenValue, expectedValue) {
19238
- if (isValueEmpty(givenValue)) {
19239
- return false;
19240
- }
19241
- if (isObject3(givenValue)) {
19242
- return Object.values(givenValue).includes(expectedValue);
19243
- }
19244
- if (Array.isArray(givenValue) || typeof givenValue === "string") {
19245
- return givenValue.indexOf(expectedValue) > -1;
19246
- }
19247
- throw new Error(`Contains operator: Unsupported values to compare ${JSON.stringify(givenValue)}, ${JSON.stringify(expectedValue)}`);
19248
- }
19249
-
19250
- // ../form-conditions/dist/esm/lib/operators/array-equals.js
19251
- function arrayEquals(givenValue, expectedValue) {
19252
- if (isValueEmpty(givenValue)) {
19253
- return false;
19254
- }
19255
- if (!Array.isArray(givenValue) || !Array.isArray(expectedValue)) {
19256
- throw new Error(`All operator: Unsupported values to compare ${JSON.stringify(givenValue)}, ${JSON.stringify(expectedValue)}`);
19257
- }
19258
- if (givenValue.length !== expectedValue.length) {
19259
- return false;
19260
- }
19261
- if (isProductSubmission(givenValue)) {
19262
- return equals(givenValue.map((product) => product.productId), expectedValue);
19263
- }
19264
- return equals(givenValue, expectedValue);
19499
+ function getNumberValuesToCompare(...values) {
19500
+ return values.map((value) => {
19501
+ if (typeof value === "string") {
19502
+ return getDateUtcTimestamp(value);
19503
+ }
19504
+ if (typeof value === "number") {
19505
+ return value;
19506
+ }
19507
+ if (isProductSubmission(value)) {
19508
+ return getProductPrice(value);
19509
+ }
19510
+ return null;
19511
+ });
19265
19512
  }
19266
- function equals(givenValue, expectedValue) {
19267
- return expectedValue.every((v) => givenValue.includes(v));
19513
+ function getDateUtcTimestamp(givenValue) {
19514
+ const givenDate = asUtcDate(givenValue);
19515
+ return givenDate ? givenDate.getTime() : null;
19268
19516
  }
19269
-
19270
- // ../form-conditions/dist/esm/lib/operators/any.js
19271
- function valueContainsAny(_givenValue, expectedValue) {
19272
- if (isValueEmpty(_givenValue)) {
19273
- return false;
19274
- }
19275
- const givenValue = Array.isArray(_givenValue) ? _givenValue : [_givenValue];
19276
- if (!Array.isArray(givenValue) || !Array.isArray(expectedValue)) {
19277
- throw new Error(`Any operator: Unsupported values to compare ${JSON.stringify(givenValue)}, ${JSON.stringify(expectedValue)}`);
19278
- }
19279
- if (isProductSubmission(givenValue)) {
19280
- return any(givenValue.map((product) => product.productId), expectedValue);
19281
- }
19282
- return any(givenValue, expectedValue);
19517
+ function getProductPrice(givenValue) {
19518
+ return givenValue[0].price;
19283
19519
  }
19284
- function any(givenValue, expectedValue) {
19285
- return givenValue.some((v) => expectedValue.includes(v));
19520
+ function isObject4(givenValue) {
19521
+ return typeof givenValue === "object" && !Array.isArray(givenValue) && givenValue !== null;
19286
19522
  }
19287
-
19288
- // ../form-conditions/dist/esm/lib/operators/in.js
19289
- function valueIn(givenValue, expectedValue) {
19290
- if (isObject3(expectedValue)) {
19291
- return Object.values(expectedValue).includes(givenValue);
19292
- }
19293
- if (Array.isArray(expectedValue) || typeof expectedValue === "string") {
19294
- return expectedValue.indexOf(givenValue) > -1;
19295
- }
19296
- throw new Error(`In operator: Unsupported values to compare ${JSON.stringify(givenValue)}, ${JSON.stringify(expectedValue)}`);
19523
+ var isArrayOfNumbers = (value) => {
19524
+ return value.every((item) => typeof item === "number");
19525
+ };
19526
+ function isProductSubmission(value) {
19527
+ return Array.isArray(value) && value.every((element) => isObject4(element) && "productId" in element && "price" in element && "quantity" in element);
19297
19528
  }
19298
-
19299
- // ../form-conditions/dist/esm/lib/condition-operators.js
19300
- var ConditionOperators;
19301
- (function(ConditionOperators2) {
19302
- ConditionOperators2["equal"] = "equal";
19303
- ConditionOperators2["notEqual"] = "notEqual";
19304
- ConditionOperators2["notEmpty"] = "notEmpty";
19305
- ConditionOperators2["empty"] = "empty";
19306
- ConditionOperators2["contains"] = "contains";
19307
- ConditionOperators2["notContains"] = "notContains";
19308
- ConditionOperators2["greaterThanOrEqual"] = "greaterThanOrEqual";
19309
- ConditionOperators2["greaterThan"] = "greaterThan";
19310
- ConditionOperators2["afterOrEqual"] = "afterOrEqual";
19311
- ConditionOperators2["after"] = "after";
19312
- ConditionOperators2["lessThanOrEqual"] = "lessThanOrEqual";
19313
- ConditionOperators2["lessThan"] = "lessThan";
19314
- ConditionOperators2["beforeOrEqual"] = "beforeOrEqual";
19315
- ConditionOperators2["before"] = "before";
19316
- ConditionOperators2["between"] = "between";
19317
- ConditionOperators2["any"] = "any";
19318
- ConditionOperators2["arrayEqual"] = "arrayEqual";
19319
- ConditionOperators2["arrayNotEqual"] = "arrayNotEqual";
19320
- ConditionOperators2["checked"] = "checked";
19321
- ConditionOperators2["notChecked"] = "notChecked";
19322
- ConditionOperators2["in"] = "in";
19323
- ConditionOperators2["notIn"] = "notIn";
19324
- ConditionOperators2["isDateNewerThan"] = "isDateNewerThan";
19325
- ConditionOperators2["isDateOlderThan"] = "isDateOlderThan";
19326
- ConditionOperators2["isDateNewerThanOrEqual"] = "isDateNewerThanOrEqual";
19327
- ConditionOperators2["isDateOlderThanOrEqual"] = "isDateOlderThanOrEqual";
19328
- })(ConditionOperators || (ConditionOperators = {}));
19329
-
19330
- // ../form-conditions/dist/esm/lib/operators/checked.js
19331
- function checked(givenValue) {
19332
- return Boolean(givenValue);
19529
+ function isValueEmpty(givenValue) {
19530
+ return givenValue === void 0 || givenValue === null || givenValue === "";
19333
19531
  }
19334
-
19335
- // ../form-conditions/dist/esm/lib/operators/equal.js
19336
- function valueEqual(givenValue, expectedValue) {
19337
- if (isProductSubmission(givenValue)) {
19338
- return getProductPrice(givenValue) === expectedValue;
19532
+ function isValidCondition(rule, fields = []) {
19533
+ if (rule === void 0) {
19534
+ return true;
19339
19535
  }
19340
- return givenValue === expectedValue;
19341
- }
19342
-
19343
- // ../form-conditions/dist/esm/lib/operators/is-date-newer-than.js
19344
- var import_dayjs2 = __toESM(require_dayjs_min());
19345
- var import_isSameOrAfter = __toESM(require_isSameOrAfter());
19346
- function valueIsDateNewerThan(givenValue, expectedValue, { orEqual = false, dateFactory = () => /* @__PURE__ */ new Date() } = {}) {
19347
- import_dayjs2.default.extend(import_isSameOrAfter.default);
19348
- if (isValueEmpty(givenValue)) {
19536
+ const rulesOrConditions = getRulesOrConditions(rule);
19537
+ if (!rulesOrConditions.length) {
19349
19538
  return false;
19350
19539
  }
19351
- if (!Array.isArray(expectedValue) || expectedValue.length !== 2) {
19352
- throw new Error("Expected value should be array of two elements");
19353
- }
19354
- const values = getNumberValuesToCompare(givenValue, expectedValue[0]);
19355
- const unit = expectedValue[1];
19356
- switch (unit) {
19357
- case "day":
19358
- case "month":
19359
- if (isArrayOfNumbers(values)) {
19360
- const [given, units] = values;
19361
- const date = (0, import_dayjs2.default)(given);
19362
- const nowUnitsAdded = (0, import_dayjs2.default)(dateFactory()).add(units, unit);
19363
- if (orEqual) {
19364
- return date.isSameOrAfter(nowUnitsAdded, "day");
19365
- }
19366
- return date.isAfter(nowUnitsAdded, "day");
19367
- }
19368
- }
19369
- throw new Error(`IsDateNewerThan operator: Unsupported values to compare ${givenValue}, ${expectedValue}`);
19540
+ return rulesOrConditions.every((conditionOrRule) => {
19541
+ if (isCondition(conditionOrRule)) {
19542
+ return fields?.some((field) => field.id === conditionOrRule.fact);
19543
+ }
19544
+ return isValidCondition(conditionOrRule, fields);
19545
+ });
19370
19546
  }
19371
-
19372
- // ../form-conditions/dist/esm/lib/operators/is-date-older-than.js
19373
- var import_dayjs3 = __toESM(require_dayjs_min());
19374
- var import_isSameOrBefore = __toESM(require_isSameOrBefore());
19375
- function valueIsDateOlderThan(givenValue, expectedValue, { orEqual = false, dateFactory = () => /* @__PURE__ */ new Date() } = {}) {
19376
- import_dayjs3.default.extend(import_isSameOrBefore.default);
19377
- if (isValueEmpty(givenValue)) {
19547
+ function isFormRuleValid(formRule, formSchema) {
19548
+ if (!formRule || !formRule?.overrides?.length || !formSchema) {
19378
19549
  return false;
19379
19550
  }
19380
- if (!Array.isArray(expectedValue) || expectedValue.length !== 2) {
19381
- throw new Error("Expected value should be array of two elements");
19382
- }
19383
- const values = getNumberValuesToCompare(givenValue, expectedValue[0]);
19384
- const unit = expectedValue[1];
19385
- switch (unit) {
19386
- case "day":
19387
- case "month":
19388
- if (isArrayOfNumbers(values)) {
19389
- const [given, units] = values;
19390
- const date = (0, import_dayjs3.default)(given);
19391
- const nowUnitsAdded = (0, import_dayjs3.default)(dateFactory()).add(-units, unit);
19392
- if (orEqual) {
19393
- return date.isSameOrBefore(nowUnitsAdded, "day");
19394
- }
19395
- return date.isBefore(nowUnitsAdded, "day");
19396
- }
19397
- }
19398
- throw new Error(`IsDateOlderThan operator: Unsupported values to compare ${givenValue}, ${expectedValue}`);
19399
- }
19400
-
19401
- // ../form-conditions/dist/esm/lib/set-up-operators.js
19402
- function setUpOperators(defaultEngine2, dateFactory) {
19403
- const operators = [
19404
- new import_js_rules_engine.Operator(ConditionOperators.empty, (value) => valueIsMissing(value)),
19405
- new import_js_rules_engine.Operator(ConditionOperators.notEmpty, (value) => !valueIsMissing(value)),
19406
- new import_js_rules_engine.Operator(ConditionOperators.between, (givenValue, expectedValue) => valueIsBetween(givenValue, expectedValue)),
19407
- new import_js_rules_engine.Operator(ConditionOperators.greaterThan, (givenValue, expectedValue) => valueIsGreaterThan(givenValue, expectedValue)),
19408
- new import_js_rules_engine.Operator(ConditionOperators.after, (givenValue, expectedValue) => valueIsGreaterThan(givenValue, expectedValue)),
19409
- new import_js_rules_engine.Operator(ConditionOperators.greaterThanOrEqual, (givenValue, expectedValue) => valueIsGreaterThan(givenValue, expectedValue, true)),
19410
- new import_js_rules_engine.Operator(ConditionOperators.afterOrEqual, (givenValue, expectedValue) => valueIsGreaterThan(givenValue, expectedValue, true)),
19411
- new import_js_rules_engine.Operator(ConditionOperators.lessThan, (givenValue, expectedValue) => valueIsLessThan(givenValue, expectedValue)),
19412
- new import_js_rules_engine.Operator(ConditionOperators.before, (givenValue, expectedValue) => valueIsLessThan(givenValue, expectedValue)),
19413
- new import_js_rules_engine.Operator(ConditionOperators.lessThanOrEqual, (givenValue, expectedValue) => valueIsLessThan(givenValue, expectedValue, true)),
19414
- new import_js_rules_engine.Operator(ConditionOperators.beforeOrEqual, (givenValue, expectedValue) => valueIsLessThan(givenValue, expectedValue, true)),
19415
- new import_js_rules_engine.Operator(ConditionOperators.contains, (givenValue, expectedValue) => valueContains(givenValue, expectedValue)),
19416
- new import_js_rules_engine.Operator(ConditionOperators.equal, (givenValue, expectedValue) => valueEqual(givenValue, expectedValue)),
19417
- new import_js_rules_engine.Operator(ConditionOperators.notEqual, (givenValue, expectedValue) => !valueEqual(givenValue, expectedValue)),
19418
- new import_js_rules_engine.Operator(ConditionOperators.notContains, (givenValue, expectedValue) => !valueContains(givenValue, expectedValue)),
19419
- new import_js_rules_engine.Operator(ConditionOperators.arrayEqual, (givenValue, expectedValue) => arrayEquals(givenValue, expectedValue)),
19420
- new import_js_rules_engine.Operator(ConditionOperators.arrayNotEqual, (givenValue, expectedValue) => !arrayEquals(givenValue, expectedValue)),
19421
- new import_js_rules_engine.Operator(ConditionOperators.checked, checked),
19422
- new import_js_rules_engine.Operator(ConditionOperators.notChecked, (givenValue) => !checked(givenValue)),
19423
- new import_js_rules_engine.Operator(ConditionOperators.any, (givenValue, expectedValue) => valueContainsAny(givenValue, expectedValue)),
19424
- new import_js_rules_engine.Operator(ConditionOperators.in, (givenValue, expectedValue) => valueIn(givenValue, expectedValue)),
19425
- new import_js_rules_engine.Operator(ConditionOperators.notIn, (givenValue, expectedValue) => !valueIn(givenValue, expectedValue)),
19426
- new import_js_rules_engine.Operator(ConditionOperators.isDateNewerThan, (givenValue, expectedValue) => valueIsDateNewerThan(givenValue, expectedValue, { dateFactory })),
19427
- new import_js_rules_engine.Operator(ConditionOperators.isDateOlderThan, (givenValue, expectedValue) => valueIsDateOlderThan(givenValue, expectedValue, { dateFactory })),
19428
- new import_js_rules_engine.Operator(ConditionOperators.isDateNewerThanOrEqual, (givenValue, expectedValue) => valueIsDateNewerThan(givenValue, expectedValue, {
19429
- orEqual: true,
19430
- dateFactory
19431
- })),
19432
- new import_js_rules_engine.Operator(ConditionOperators.isDateOlderThanOrEqual, (givenValue, expectedValue) => valueIsDateOlderThan(givenValue, expectedValue, {
19433
- orEqual: true,
19434
- dateFactory
19435
- }))
19436
- ];
19437
- operators.forEach((operator) => {
19438
- defaultEngine2.removeOperator(operator.name);
19439
- defaultEngine2.addOperator(operator);
19551
+ const { fieldsV2, fields, nestedForms, formFields } = formSchema;
19552
+ const fieldsToCheck = (fields ?? []).concat(fieldsV2 ?? []).concat(formFields ?? []);
19553
+ const conditionValid = isValidCondition(formRule.condition, fieldsToCheck);
19554
+ const overrideValid = formRule?.overrides.some((override) => {
19555
+ if (override.entityType === OverrideEntityType.FORM) {
19556
+ return formSchema.id === override.entityId || nestedForms?.some((nestedForm) => nestedForm.form?.id === override.entityId);
19557
+ }
19558
+ const wasFieldFound = (fieldsToCheck?.map((f) => f.id) ?? []).includes(override.entityId);
19559
+ return override.entityId ? wasFieldFound : false;
19440
19560
  });
19561
+ return conditionValid && overrideValid;
19441
19562
  }
19442
19563
 
19443
- // ../form-conditions/dist/esm/lib/evaluate-override-condition.js
19444
- function evaluateOverrideConditionFactory(dateFactory = () => /* @__PURE__ */ new Date()) {
19445
- setUpOperators(import_js_rules_engine2.defaultEngine, dateFactory);
19446
- return function evaluateOverrideCondition(override, submission = {}) {
19447
- if (override.condition) {
19448
- try {
19449
- const rule = getRule(override.condition);
19450
- return rule.evaluate(submission);
19451
- } catch (e) {
19452
- console.error(e);
19453
- return false;
19564
+ // ../form-conditions/dist/esm/lib/transform-path-to-v2.js
19565
+ var supportedPaths = [
19566
+ "hidden",
19567
+ "validation.required",
19568
+ "validation.string.enum",
19569
+ "validation.boolean.enum",
19570
+ "validation.predefined.multilineAddressOptions.fields",
19571
+ "view.options",
19572
+ "view.countryCode"
19573
+ ];
19574
+ var fieldPathMapToPlatfomized = {
19575
+ hidden: ["hidden"],
19576
+ "validation.required": ["inputOptions.required"],
19577
+ "validation.string.enum": ["inputOptions.stringOptions.validation.enum"],
19578
+ "validation.boolean.enum": ["inputOptions.booleanOptions.validation.enum"],
19579
+ "view.options": [
19580
+ "inputOptions.stringOptions.radioGroupOptions.options",
19581
+ "inputOptions.stringOptions.dropdownOptions.options",
19582
+ "inputOptions.arrayOptions.checkboxGroupOptions.options"
19583
+ ],
19584
+ "view.countryCode": []
19585
+ };
19586
+
19587
+ // ../form-conditions/dist/esm/lib/apply-item-properties-override.js
19588
+ var PATH_SEPARATOR = ".";
19589
+ function applyItemPropertiesOverride(formSchema, rule) {
19590
+ if (rule.overrides) {
19591
+ const overriddenFormSchema = applyFormOverride(formSchema, mapOverridesByItem(rule.overrides, isFormOverride, isSupportedFormPath));
19592
+ return {
19593
+ ...overriddenFormSchema,
19594
+ fields: applyItemsOverride(overriddenFormSchema.fields ?? [], mapOverridesByItem(rule.overrides, isFieldOverride, isSupportedFieldPath)),
19595
+ ...overriddenFormSchema.fieldsV2 && {
19596
+ fieldsV2: applyItemsOverride(overriddenFormSchema.fieldsV2 ?? [], mapOverridesV2ByItem(rule.overrides, isFieldOverride))
19597
+ },
19598
+ ...overriddenFormSchema.formFields && {
19599
+ formFields: applyItemsOverride(overriddenFormSchema.formFields ?? [], mapOverridesV2ByItem(rule.overrides, isFieldOverride))
19454
19600
  }
19455
- }
19456
- return true;
19457
- };
19458
- function getRule(condition) {
19459
- return new import_js_rules_engine2.Rule(condition);
19601
+ };
19460
19602
  }
19603
+ return formSchema;
19461
19604
  }
19462
-
19463
- // ../form-mapper/dist/esm/lib/submission-mapper.js
19464
- function mapByIds(submission, form) {
19465
- return mapBy(submission, form, "id");
19605
+ function applyItemsOverride(items, formItemOverrides) {
19606
+ return items.map((formField) => {
19607
+ const fieldOverrides = formItemOverrides[asRequired2(formField.id)] || [];
19608
+ return fieldOverrides.reduce((acc, override) => setToValue(acc, override.path, override.value), formField);
19609
+ });
19466
19610
  }
19467
- function mapBy(submission, form, by) {
19468
- const from = "target" ;
19469
- const fields = (form?.fields?.length ?? 0) > 0 ? form?.fields ?? [] : (form?.formFields?.length ?? 0) > 0 ? form?.formFields ?? [] : form?.fieldsV2 ?? [];
19470
- const getIdOrTarget = (field, _by) => {
19471
- if (_by === "id") {
19472
- return field[_by];
19473
- } else if ("inputOptions" in field) {
19474
- return field.inputOptions?.target;
19475
- } else {
19476
- return field.target;
19477
- }
19478
- };
19479
- return fields.reduce((acc, field) => {
19480
- const source = getIdOrTarget(field, from);
19481
- const destination = getIdOrTarget(field, by);
19482
- if (source && destination && source !== destination && acc.hasOwnProperty(source)) {
19483
- acc[destination] = acc[source];
19484
- const { [source]: omitted, ...rest } = acc;
19485
- acc = rest;
19486
- }
19611
+ function applyFormOverride(formSchema, formItemOverrides) {
19612
+ const formOverrides = Object.values(formItemOverrides).flat();
19613
+ return formOverrides.reduce((acc, override) => setToValue(acc, override.path, override.value), formSchema);
19614
+ }
19615
+ function mapOverridesByItem(overrideItems, isOverride, isSupportedPath) {
19616
+ return overrideItems.filter(isOverride).reduce((acc, overrideItem) => {
19617
+ const entityId = asRequired2(overrideItem.entityId);
19618
+ const overrides = Object.entries(overrideItem.valueChanges ?? {}).filter(([path]) => isSupportedPath(path)).map(([path, value]) => ({
19619
+ path: path.split(PATH_SEPARATOR),
19620
+ value
19621
+ }));
19622
+ acc[entityId] = [...acc[entityId] || [], ...overrides];
19487
19623
  return acc;
19488
- }, { ...submission });
19624
+ }, {});
19489
19625
  }
19490
-
19491
- // ../form-conditions/dist/esm/lib/apply-overrides.js
19492
- function applyOverrides(formSchema, submission) {
19493
- const nestedForms = (formSchema?.nestedForms || []).flatMap(({ targets, form }) => (targets || []).map((target) => ({
19494
- form: applyFormOverrides(asRequired2(form), (submission || {})[target]),
19495
- targets: [target]
19496
- })));
19497
- return { ...applyFormOverrides(formSchema, submission), nestedForms };
19626
+ function mapOverridesV2ByItem(overrideItems, isOverride) {
19627
+ return overrideItems.filter(isOverride).reduce((acc, overrideItem) => {
19628
+ const entityId = asRequired2(overrideItem.entityId);
19629
+ const overrides = Object.entries(overrideItem.valueChanges ?? {}).flatMap(([path, value]) => {
19630
+ const resolvedV2Paths = fieldPathMapToPlatfomized[path] || [];
19631
+ return resolvedV2Paths.map((pathV2) => [pathV2, value]);
19632
+ }).map(([path, value]) => ({
19633
+ path: path.split(PATH_SEPARATOR),
19634
+ value
19635
+ }));
19636
+ acc[entityId] = [...acc[entityId] || [], ...overrides];
19637
+ return acc;
19638
+ }, {});
19498
19639
  }
19499
- function applyFormOverrides(formSchema, submission) {
19500
- const submissionsById = mapByIds(submission, formSchema);
19501
- const { rules } = formSchema;
19502
- if (rules) {
19503
- return rules.filter((rule) => isFormRuleValid(rule, formSchema)).filter((rule) => evaluateOverrideConditionFactory()(rule, submissionsById)).reduce((form, rule) => applyItemPropertiesOverride(form, rule), formSchema);
19640
+ function setToValue(obj, pathProps, value) {
19641
+ if (value !== void 0 && obj !== void 0) {
19642
+ const [prop, ...rest] = pathProps;
19643
+ if (rest.length) {
19644
+ const valueToSet = setToValue(obj[prop], rest, value);
19645
+ if (valueToSet !== void 0) {
19646
+ return {
19647
+ ...obj,
19648
+ [prop]: valueToSet
19649
+ };
19650
+ }
19651
+ return obj;
19652
+ }
19653
+ return {
19654
+ ...obj,
19655
+ [prop]: value
19656
+ };
19504
19657
  }
19505
- return formSchema;
19658
+ return obj;
19506
19659
  }
19507
-
19508
- // ../nested-form-overrides/dist/esm/lib/array-utils.js
19509
- function partition(items, condition) {
19510
- return items.reduce(([truthy, falsy], element) => {
19511
- if (condition(element)) {
19512
- truthy.push(element);
19513
- } else {
19514
- falsy.push(element);
19515
- }
19516
- return [truthy, falsy];
19517
- }, [[], []]);
19660
+ function isFieldOverride(override) {
19661
+ return override.entityType === OverrideEntityType.FIELD;
19518
19662
  }
19519
- function mapBy2(items, keyFn) {
19520
- return items.reduce((acc, item) => {
19521
- acc[keyFn(item)] = item;
19522
- return acc;
19523
- }, {});
19663
+ function isFormOverride(override) {
19664
+ return override.entityType === OverrideEntityType.FORM;
19524
19665
  }
19525
-
19526
- // ../nested-form-overrides/dist/esm/lib/lang-utils.js
19527
- function isDefined2(value) {
19528
- return !(value === null || value === void 0);
19666
+ function isSupportedFieldPath(path) {
19667
+ return supportedPaths.includes(path);
19529
19668
  }
19530
-
19531
- // ../nested-form-overrides/dist/esm/lib/object-utils.js
19532
- function isEmpty(object) {
19533
- return Boolean(object) && Boolean(Object.keys(object).length);
19669
+ function isSupportedFormPath(path) {
19670
+ return ["fields", "steps"].includes(path);
19534
19671
  }
19535
19672
 
19536
- // ../nested-form-overrides/dist/esm/lib/nested-form-overrides.js
19537
- function applyNestedFormOverrides(parentForm) {
19538
- const fieldsWithFormOverrides = parentForm.fields.filter((field) => isEmpty(field.nestedFormOverrides?.fieldOverrides));
19539
- const fieldsWithFormOverridesByTarget = mapBy2(fieldsWithFormOverrides, (field) => field.target);
19540
- const nestedForms = (parentForm.nestedForms || []).reduce((acc, { targets, form } = {}) => {
19541
- const [targetsWithOverride, targetsWithoutOverride] = partition(targets, (target) => Boolean(fieldsWithFormOverridesByTarget[target]));
19542
- const nestedFormsWithOverrides = targetsWithOverride.map((target) => ({
19543
- targets: [target],
19544
- form: applyOverrides2(form, fieldsWithFormOverridesByTarget[target].nestedFormOverrides)
19545
- }));
19546
- const nestedFormsWithoutOverrides = targetsWithoutOverride.length ? [{ targets: targetsWithoutOverride, form }] : [];
19547
- return [
19548
- ...acc,
19549
- ...nestedFormsWithoutOverrides,
19550
- ...nestedFormsWithOverrides
19551
- ];
19552
- }, []);
19553
- return { ...parentForm, nestedForms };
19673
+ // ../form-conditions/dist/esm/lib/evaluate-override-condition.js
19674
+ var import_js_rules_engine2 = __toESM(require_dist5());
19675
+
19676
+ // ../form-conditions/dist/esm/lib/set-up-operators.js
19677
+ var import_js_rules_engine = __toESM(require_dist5());
19678
+
19679
+ // ../form-conditions/dist/esm/lib/operators/between.js
19680
+ function valueIsBetween(givenValue, expectedValue) {
19681
+ if (isValueEmpty(givenValue)) {
19682
+ return false;
19683
+ }
19684
+ if (!Array.isArray(expectedValue) || expectedValue.length !== 2) {
19685
+ throw new Error("Expected value should be array of two elements");
19686
+ }
19687
+ const values = getNumberValuesToCompare(givenValue, expectedValue[0], expectedValue[1]);
19688
+ if (isArrayOfNumbers(values)) {
19689
+ const [given, firstBound, secondBound] = values;
19690
+ return between(given, Math.min(firstBound, secondBound), Math.max(firstBound, secondBound));
19691
+ }
19692
+ throw new Error(`Between operator: Unsupported values to compare ${givenValue}, ${JSON.stringify(expectedValue)}`);
19554
19693
  }
19555
- function applyOverrides2(form, overrides) {
19556
- const fieldOverrides = overrides.fieldOverrides;
19557
- return {
19558
- ...form,
19559
- fields: form.fields.map((field) => {
19560
- const { hidden: hiddenOverride, required: requiredOverride } = fieldOverrides[field.id] || {};
19561
- return {
19562
- ...field,
19563
- ...isDefined2(hiddenOverride) && { hidden: hiddenOverride },
19564
- ...isDefined2(requiredOverride) && isDefined2(field.validation) && {
19565
- validation: {
19566
- ...field.validation,
19567
- required: requiredOverride
19568
- }
19569
- }
19570
- };
19571
- })
19572
- };
19694
+
19695
+ // ../form-conditions/dist/esm/lib/operators/greater-than.js
19696
+ function valueIsGreaterThan(givenValue, expectedValue, orEqual = false) {
19697
+ if (isValueEmpty(givenValue)) {
19698
+ return false;
19699
+ }
19700
+ const values = getNumberValuesToCompare(givenValue, expectedValue);
19701
+ if (isArrayOfNumbers(values)) {
19702
+ const [given, expected] = values;
19703
+ return greaterThan(given, expected, orEqual);
19704
+ }
19705
+ throw new Error(`GreaterThan operator: Unsupported values to compare ${givenValue}, ${expectedValue}`);
19573
19706
  }
19574
19707
 
19575
- // ../form-viewer/dist/esm/services/utils.js
19576
- var RATING_VALUES = [1, 2, 3, 4, 5];
19577
- function isObject4(value) {
19578
- return typeof value === "object" && !Array.isArray(value) && value !== null;
19708
+ // ../form-conditions/dist/esm/lib/operators/less-than.js
19709
+ function valueIsLessThan(givenValue, expectedValue, orEqual = false) {
19710
+ if (isValueEmpty(givenValue)) {
19711
+ return false;
19712
+ }
19713
+ const values = getNumberValuesToCompare(givenValue, expectedValue);
19714
+ if (isArrayOfNumbers(values)) {
19715
+ const [given, expected] = values;
19716
+ return lessThan(given, expected, orEqual);
19717
+ }
19718
+ throw new Error(`LessThan operator: Unsupported values to compare ${givenValue}, ${expectedValue}`);
19579
19719
  }
19580
- function isString(value) {
19581
- return typeof value === "string";
19720
+
19721
+ // ../form-conditions/dist/esm/lib/operators/contains.js
19722
+ function valueContains(givenValue, expectedValue) {
19723
+ if (isValueEmpty(givenValue)) {
19724
+ return false;
19725
+ }
19726
+ if (isObject4(givenValue)) {
19727
+ return Object.values(givenValue).includes(expectedValue);
19728
+ }
19729
+ if (Array.isArray(givenValue) || typeof givenValue === "string") {
19730
+ return givenValue.indexOf(expectedValue) > -1;
19731
+ }
19732
+ throw new Error(`Contains operator: Unsupported values to compare ${JSON.stringify(givenValue)}, ${JSON.stringify(expectedValue)}`);
19582
19733
  }
19583
- function isNumber(value) {
19584
- return typeof value === "number" && !Number.isNaN(value);
19734
+
19735
+ // ../form-conditions/dist/esm/lib/operators/array-equals.js
19736
+ function arrayEquals(givenValue, expectedValue) {
19737
+ if (isValueEmpty(givenValue)) {
19738
+ return false;
19739
+ }
19740
+ if (!Array.isArray(givenValue) || !Array.isArray(expectedValue)) {
19741
+ throw new Error(`All operator: Unsupported values to compare ${JSON.stringify(givenValue)}, ${JSON.stringify(expectedValue)}`);
19742
+ }
19743
+ if (givenValue.length !== expectedValue.length) {
19744
+ return false;
19745
+ }
19746
+ if (isProductSubmission(givenValue)) {
19747
+ return equals(givenValue.map((product) => product.productId), expectedValue);
19748
+ }
19749
+ return equals(givenValue, expectedValue);
19585
19750
  }
19586
- function isRating(value) {
19587
- return typeof value === "number" && RATING_VALUES.includes(value);
19751
+ function equals(givenValue, expectedValue) {
19752
+ return expectedValue.every((v) => givenValue.includes(v));
19588
19753
  }
19589
19754
 
19590
- // ../form-viewer/dist/esm/services/has-multiline-address.js
19591
- var hasMultilineAddress = (form, { excludeEcomAddress } = {
19592
- excludeEcomAddress: false
19593
- }) => {
19594
- const fields = [...form?.fields || [], ...form?.deletedFields || []];
19595
- return fields.some((field) => field.view?.fieldType === "MULTILINE_ADDRESS" || field.view?.fieldType === "BOOKINGS_ADDRESS" || !excludeEcomAddress && field.view?.fieldType === "ECOM_ADDRESS");
19596
- };
19597
-
19598
- // ../form-viewer/dist/esm/services/validation.js
19599
- var removeFalsyValues = (values = {}) => {
19600
- return Object.keys(values).reduce((withoutFalsy, target) => {
19601
- const value = values[target];
19602
- if (value === "" || typeof value === "undefined" || value === null) {
19603
- return withoutFalsy;
19604
- }
19605
- if (Array.isArray(value) && !value.length) {
19606
- return withoutFalsy;
19607
- }
19608
- if (isObject4(value)) {
19609
- withoutFalsy[target] = removeFalsyValues(value);
19610
- } else {
19611
- withoutFalsy[target] = value;
19612
- }
19613
- return withoutFalsy;
19614
- }, {});
19615
- };
19616
- var getFormValidator = async (form, addressTemplates, validationMode) => {
19617
- const [{ FormValidator: FormValidator2 }, { MultilineAddressToolkit: MultilineAddressToolkit2 }] = await Promise.all([
19618
- Promise.resolve().then(() => (init_esm(), esm_exports)),
19619
- Promise.resolve().then(() => (init_esm2(), esm_exports2))
19620
- ]);
19621
- if (addressTemplates?.length) {
19622
- const addressForms = addressTemplates.map((template) => template.template);
19623
- const addressToolkit = new MultilineAddressToolkit2(addressForms);
19624
- return new FormValidator2([form], validationMode, false, addressToolkit.getFormForValidation, addressToolkit.normalizeEmptyValues, true);
19755
+ // ../form-conditions/dist/esm/lib/operators/any.js
19756
+ function valueContainsAny(_givenValue, expectedValue) {
19757
+ if (isValueEmpty(_givenValue)) {
19758
+ return false;
19625
19759
  }
19626
- return new FormValidator2([form], validationMode, void 0, void 0, void 0, true);
19627
- };
19628
- var validate = async (form, values, addressTemplates, validationMode) => {
19629
- if (!form.id) {
19630
- return;
19760
+ const givenValue = Array.isArray(_givenValue) ? _givenValue : [_givenValue];
19761
+ if (!Array.isArray(givenValue) || !Array.isArray(expectedValue)) {
19762
+ throw new Error(`Any operator: Unsupported values to compare ${JSON.stringify(givenValue)}, ${JSON.stringify(expectedValue)}`);
19631
19763
  }
19632
- const formValidator = await getFormValidator(form, addressTemplates, validationMode);
19633
- return formValidator.validate(form.id, hasMultilineAddress(form, { excludeEcomAddress: true }) ? values : removeFalsyValues(values));
19634
- };
19635
- var validateFields = async (form, values, addressTemplates, validationMode) => {
19636
- if (!form.id) {
19637
- return;
19764
+ if (isProductSubmission(givenValue)) {
19765
+ return any(givenValue.map((product) => product.productId), expectedValue);
19638
19766
  }
19639
- const formValidator = await getFormValidator(form, addressTemplates, validationMode);
19640
- return formValidator.validateFields(form.id, hasMultilineAddress(form) ? values : removeFalsyValues(values));
19641
- };
19767
+ return any(givenValue, expectedValue);
19768
+ }
19769
+ function any(givenValue, expectedValue) {
19770
+ return givenValue.some((v) => expectedValue.includes(v));
19771
+ }
19642
19772
 
19643
- // ../form-viewer/dist/esm/services/apply-nested-forms.js
19644
- function applyNestedForms(form, nestedFormsById) {
19645
- if (!form.nestedForms && !nestedFormsById) {
19646
- return form;
19773
+ // ../form-conditions/dist/esm/lib/operators/in.js
19774
+ function valueIn(givenValue, expectedValue) {
19775
+ if (isObject4(expectedValue)) {
19776
+ return Object.values(expectedValue).includes(givenValue);
19647
19777
  }
19648
- const nestedFormsByTarget = getNestedFormsByTarget(form);
19649
- return {
19650
- ...form,
19651
- fields: form.fields?.map((field) => {
19652
- const fieldTarget = field.target;
19653
- if (!fieldTarget) {
19654
- return field;
19655
- }
19656
- const nestedFormId = field.nestedFormId;
19657
- if (!nestedFormId) {
19658
- return field;
19659
- }
19660
- const nestedForm = nestedFormsByTarget?.[fieldTarget] ?? nestedFormsById?.[nestedFormId];
19661
- if (nestedForm) {
19662
- return { ...field, view: { ...field.view, form: nestedForm } };
19663
- }
19664
- return field;
19665
- })
19666
- };
19667
- }
19668
- function getNestedFormsByTarget(form) {
19669
- return form.nestedForms?.reduce((byTarget, { targets, form: nestedForm }) => {
19670
- if (!nestedForm || !targets) {
19671
- return byTarget;
19672
- }
19673
- for (const target of targets) {
19674
- byTarget[target] = nestedForm;
19675
- }
19676
- return byTarget;
19677
- }, {});
19778
+ if (Array.isArray(expectedValue) || typeof expectedValue === "string") {
19779
+ return expectedValue.indexOf(givenValue) > -1;
19780
+ }
19781
+ throw new Error(`In operator: Unsupported values to compare ${JSON.stringify(givenValue)}, ${JSON.stringify(expectedValue)}`);
19678
19782
  }
19679
- function getNestedFormArray(formsByTarget) {
19680
- return Object.keys(formsByTarget).map((target) => {
19681
- return { targets: [target], form: formsByTarget[target] };
19682
- });
19783
+
19784
+ // ../form-conditions/dist/esm/lib/condition-operators.js
19785
+ var ConditionOperators;
19786
+ (function(ConditionOperators2) {
19787
+ ConditionOperators2["equal"] = "equal";
19788
+ ConditionOperators2["notEqual"] = "notEqual";
19789
+ ConditionOperators2["notEmpty"] = "notEmpty";
19790
+ ConditionOperators2["empty"] = "empty";
19791
+ ConditionOperators2["contains"] = "contains";
19792
+ ConditionOperators2["notContains"] = "notContains";
19793
+ ConditionOperators2["greaterThanOrEqual"] = "greaterThanOrEqual";
19794
+ ConditionOperators2["greaterThan"] = "greaterThan";
19795
+ ConditionOperators2["afterOrEqual"] = "afterOrEqual";
19796
+ ConditionOperators2["after"] = "after";
19797
+ ConditionOperators2["lessThanOrEqual"] = "lessThanOrEqual";
19798
+ ConditionOperators2["lessThan"] = "lessThan";
19799
+ ConditionOperators2["beforeOrEqual"] = "beforeOrEqual";
19800
+ ConditionOperators2["before"] = "before";
19801
+ ConditionOperators2["between"] = "between";
19802
+ ConditionOperators2["any"] = "any";
19803
+ ConditionOperators2["arrayEqual"] = "arrayEqual";
19804
+ ConditionOperators2["arrayNotEqual"] = "arrayNotEqual";
19805
+ ConditionOperators2["checked"] = "checked";
19806
+ ConditionOperators2["notChecked"] = "notChecked";
19807
+ ConditionOperators2["in"] = "in";
19808
+ ConditionOperators2["notIn"] = "notIn";
19809
+ ConditionOperators2["isDateNewerThan"] = "isDateNewerThan";
19810
+ ConditionOperators2["isDateOlderThan"] = "isDateOlderThan";
19811
+ ConditionOperators2["isDateNewerThanOrEqual"] = "isDateNewerThanOrEqual";
19812
+ ConditionOperators2["isDateOlderThanOrEqual"] = "isDateOlderThanOrEqual";
19813
+ })(ConditionOperators || (ConditionOperators = {}));
19814
+
19815
+ // ../form-conditions/dist/esm/lib/operators/checked.js
19816
+ function checked(givenValue) {
19817
+ return Boolean(givenValue);
19683
19818
  }
19684
19819
 
19685
- // ../form-viewer/dist/esm/services/additional-field-validation.js
19686
- var runAdditionalValidation = ({ form, values, externalData }) => {
19687
- const additionalErrors = form.fields?.reduce((acc, field) => {
19688
- const fieldTarget = field.target;
19689
- if (!fieldTarget) {
19690
- return acc;
19691
- }
19692
- const fieldType = field?.view?.fieldType;
19693
- const fieldValue = values[fieldTarget];
19694
- const validateField = ADDITIONAL_FIELD_VALIDATION[fieldType];
19695
- const error = validateField?.({
19696
- value: fieldValue,
19697
- target: fieldTarget,
19698
- externalData
19699
- });
19700
- if (error) {
19701
- acc[fieldTarget] = error;
19702
- }
19703
- return acc;
19704
- }, {});
19705
- return additionalErrors;
19706
- };
19707
- var ADDITIONAL_FIELD_VALIDATION = {
19708
- [FIELD_TYPES.TEXT_INPUT]: null,
19709
- [FIELD_TYPES.CHECKBOX_GROUP]: null,
19710
- [FIELD_TYPES.RADIO_GROUP]: null,
19711
- [FIELD_TYPES.DONATION]: null,
19712
- [FIELD_TYPES.DROPDOWN]: null,
19713
- [FIELD_TYPES.URL_INPUT]: null,
19714
- [FIELD_TYPES.NUMBER_INPUT]: null,
19715
- [FIELD_TYPES.QUIZ_NUMBER]: null,
19716
- [FIELD_TYPES.QUIZ_SHORT_TEXT]: null,
19717
- [FIELD_TYPES.QUIZ_LONG_TEXT]: null,
19718
- [FIELD_TYPES.QUIZ_MULTI_CHOICE]: null,
19719
- [FIELD_TYPES.QUIZ_IMAGE_CHOICE]: null,
19720
- [FIELD_TYPES.QUIZ_SINGLE_CHOICE]: null,
19721
- [FIELD_TYPES.QUIZ_FILE_UPLOAD]: null,
19722
- [FIELD_TYPES.FILE_UPLOAD]: null,
19723
- [FIELD_TYPES.SIGNATURE]: null,
19724
- [FIELD_TYPES.CONTACTS_EMAIL]: null,
19725
- [FIELD_TYPES.CONTACTS_PHONE]: null,
19726
- [FIELD_TYPES.CHECKBOX]: null,
19727
- [FIELD_TYPES.DATE_INPUT]: null,
19728
- [FIELD_TYPES.DATE_TIME_INPUT]: null,
19729
- [FIELD_TYPES.TIME_INPUT]: null,
19730
- [FIELD_TYPES.DATE_PICKER]: null,
19731
- [FIELD_TYPES.CONTACTS_COMPANY]: null,
19732
- [FIELD_TYPES.CONTACTS_POSITION]: null,
19733
- [FIELD_TYPES.CONTACTS_TAX_ID]: null,
19734
- [FIELD_TYPES.CONTACTS_FIRST_NAME]: null,
19735
- [FIELD_TYPES.CONTACTS_LAST_NAME]: null,
19736
- [FIELD_TYPES.CONTACTS_ADDRESS]: null,
19737
- [FIELD_TYPES.CONTACTS_BIRTHDATE]: validateBirthdate,
19738
- [FIELD_TYPES.TEXT_AREA]: null,
19739
- [FIELD_TYPES.CONTACTS_SUBSCRIBE]: null,
19740
- [FIELD_TYPES.NESTED_FORM]: null,
19741
- [FIELD_TYPES.MULTILINE_ADDRESS]: null,
19742
- [FIELD_TYPES.MLA_COUNTRY]: null,
19743
- [FIELD_TYPES.MLA_CITY]: null,
19744
- [FIELD_TYPES.MLA_ADDRESS_LINE]: null,
19745
- [FIELD_TYPES.MLA_ADDRESS_LINE_2]: null,
19746
- [FIELD_TYPES.MLA_POSTAL_CODE]: null,
19747
- [FIELD_TYPES.MLA_SUBDIVISION]: null,
19748
- [FIELD_TYPES.MLA_STREET_NAME]: null,
19749
- [FIELD_TYPES.MLA_STREET_NUMBER]: null,
19750
- [FIELD_TYPES.MLA_APARTMENT]: null,
19751
- [FIELD_TYPES.FULL_NAME_FIRST_NAME]: null,
19752
- [FIELD_TYPES.FULL_NAME_LAST_NAME]: null,
19753
- [FIELD_TYPES.FULL_NAME]: null,
19754
- [FIELD_TYPES.DEXT_TEXT_INPUT]: null,
19755
- [FIELD_TYPES.DEXT_NUMBER_INPUT]: null,
19756
- [FIELD_TYPES.DEXT_CHECKBOX]: null,
19757
- [FIELD_TYPES.DEXT_CHECKBOX_GROUP]: null,
19758
- [FIELD_TYPES.DEXT_TAGS]: null,
19759
- [FIELD_TYPES.DEXT_RATING_INPUT]: null,
19760
- [FIELD_TYPES.ECOM_ADDITIONAL_INFO]: null,
19761
- [FIELD_TYPES.ECOM_ADDRESS]: null,
19762
- [FIELD_TYPES.ECOM_PHONE]: null,
19763
- [FIELD_TYPES.ECOM_FULL_NAME]: null,
19764
- [FIELD_TYPES.ECOM_COMPANY_NAME]: null,
19765
- [FIELD_TYPES.ECOM_EMAIL]: null,
19766
- [FIELD_TYPES.ECOM_SUBSCRIPTION]: null,
19767
- [FIELD_TYPES.DEXT_TEXT_AREA]: null,
19768
- [FIELD_TYPES.DEXT_DROPDOWN]: null,
19769
- [FIELD_TYPES.DEXT_RADIO_GROUP]: null,
19770
- [FIELD_TYPES.DEXT_URL_INPUT]: null,
19771
- [FIELD_TYPES.DEXT_EMAIL]: null,
19772
- [FIELD_TYPES.DEXT_PHONE]: null,
19773
- [FIELD_TYPES.DEXT_DATE_PICKER]: null,
19774
- [FIELD_TYPES.VAT_ID]: validateVatID,
19775
- [FIELD_TYPES.PRODUCT_LIST]: null,
19776
- [FIELD_TYPES.RATING_INPUT]: null,
19777
- [FIELD_TYPES.TAGS]: null,
19778
- [FIELD_TYPES.PAYMENT_INPUT]: null,
19779
- [FIELD_TYPES.FIXED_PAYMENT]: null,
19780
- [FIELD_TYPES.BOOKINGS_FIRST_NAME]: null,
19781
- [FIELD_TYPES.BOOKINGS_LAST_NAME]: null,
19782
- [FIELD_TYPES.BOOKINGS_EMAIL]: null,
19783
- [FIELD_TYPES.BOOKINGS_PHONE]: null,
19784
- [FIELD_TYPES.BOOKINGS_ADDRESS]: null,
19785
- [FIELD_TYPES.APPOINTMENT]: null,
19786
- [FIELD_TYPES.IDENTITY_PASSWORD]: null,
19787
- [FIELD_TYPES.SERVICES_DROPDOWN]: null,
19788
- [FIELD_TYPES.SERVICES_MULTI_CHOICE]: null,
19789
- [FIELD_TYPES.EVENTS_RSVP]: null,
19790
- [FIELD_TYPES.EVENTS_REPEATER]: null
19791
- };
19820
+ // ../form-conditions/dist/esm/lib/operators/equal.js
19821
+ function valueEqual(givenValue, expectedValue) {
19822
+ if (isProductSubmission(givenValue)) {
19823
+ return getProductPrice(givenValue) === expectedValue;
19824
+ }
19825
+ return givenValue === expectedValue;
19826
+ }
19792
19827
 
19793
- // ../form-viewer/dist/esm/services/get-field-errors.js
19794
- var getFieldErrors = async (fieldsToValidate, form, addressTemplates, externalData, validationMode) => {
19795
- const formValues = fieldsToValidate.reduce((acc, field) => setValue(acc, field.path, field.value), {});
19796
- const result2 = await validateFields(form, formValues, addressTemplates, validationMode);
19797
- const _errors = result2?.errors || [];
19798
- const additionalErrors = runAdditionalValidation({
19799
- form,
19800
- values: formValues,
19801
- externalData
19802
- });
19803
- const allErrors = mergeErrors({ errors: _errors, additionalErrors });
19804
- const fieldErrors = allErrors.filter((error) => findErrorByNormalizedPath(fieldsToValidate, error.errorPath));
19805
- return fieldErrors;
19806
- };
19807
- var findErrorByNormalizedPath = (fieldsToValidate, errorPath) => {
19808
- const path = errorPath.split("/").length > 2 ? errorPath.split("/").at(0) : errorPath;
19809
- return !!fieldsToValidate.find((field) => path === field.path);
19810
- };
19811
- function setValue(object, path, value) {
19812
- const delimiter = "/";
19813
- const decomposedPath = path.split(delimiter);
19814
- const base = decomposedPath[0];
19815
- if (base === void 0) {
19816
- return object;
19828
+ // ../form-conditions/dist/esm/lib/operators/is-date-newer-than.js
19829
+ var import_dayjs2 = __toESM(require_dayjs_min());
19830
+ var import_isSameOrAfter = __toESM(require_isSameOrAfter());
19831
+ function valueIsDateNewerThan(givenValue, expectedValue, { orEqual = false, dateFactory = () => /* @__PURE__ */ new Date() } = {}) {
19832
+ import_dayjs2.default.extend(import_isSameOrAfter.default);
19833
+ if (isValueEmpty(givenValue)) {
19834
+ return false;
19817
19835
  }
19818
- if (!object.hasOwnProperty(base)) {
19819
- object[base] = {};
19836
+ if (!Array.isArray(expectedValue) || expectedValue.length !== 2) {
19837
+ throw new Error("Expected value should be array of two elements");
19820
19838
  }
19821
- value = decomposedPath.length <= 1 ? value : setValue(object[base], decomposedPath.slice(1).join(delimiter), value);
19822
- return {
19823
- ...object,
19824
- [base]: value
19825
- };
19826
- }
19827
- var mergeErrors = ({ errors, additionalErrors }) => {
19828
- const errorsToAdd = [];
19829
- if (additionalErrors) {
19830
- Object.keys(additionalErrors).forEach((fieldTarget) => {
19831
- const errorExists = errors.find((error) => error.errorPath === fieldTarget);
19832
- if (!errorExists) {
19833
- errorsToAdd.push(additionalErrors[fieldTarget]);
19839
+ const values = getNumberValuesToCompare(givenValue, expectedValue[0]);
19840
+ const unit = expectedValue[1];
19841
+ switch (unit) {
19842
+ case "day":
19843
+ case "month":
19844
+ if (isArrayOfNumbers(values)) {
19845
+ const [given, units] = values;
19846
+ const date = (0, import_dayjs2.default)(given);
19847
+ const nowUnitsAdded = (0, import_dayjs2.default)(dateFactory()).add(units, unit);
19848
+ if (orEqual) {
19849
+ return date.isSameOrAfter(nowUnitsAdded, "day");
19850
+ }
19851
+ return date.isAfter(nowUnitsAdded, "day");
19834
19852
  }
19835
- });
19836
19853
  }
19837
- return [...errors, ...errorsToAdd];
19838
- };
19854
+ throw new Error(`IsDateNewerThan operator: Unsupported values to compare ${givenValue}, ${expectedValue}`);
19855
+ }
19839
19856
 
19840
- // ../form-viewer/dist/esm/services/form-overrides.js
19841
- function applyFormOverrides2(form, overrides, recursive = true) {
19842
- const nestedFormsByTarget = getNestedFormsByTarget(form);
19843
- const fields = (form.fields ?? []).map((field) => {
19844
- const override = getOverride({
19845
- id: field.id,
19846
- target: field.target,
19847
- overrides
19848
- });
19849
- if (!override) {
19850
- return field;
19851
- }
19852
- if (field.target && field.nestedFormId && recursive) {
19853
- const nestedForm = nestedFormsByTarget?.[field.target];
19854
- if (nestedForm) {
19855
- nestedFormsByTarget[field.target] = applyFormOverrides2(nestedForm, override, false);
19856
- }
19857
- return field;
19858
- }
19859
- let validation = field.validation;
19860
- let options = {};
19861
- if (Array.isArray(override.countries)) {
19862
- validation = {
19863
- ...validation,
19864
- string: {
19865
- ...validation?.string,
19866
- enum: override.countries
19857
+ // ../form-conditions/dist/esm/lib/operators/is-date-older-than.js
19858
+ var import_dayjs3 = __toESM(require_dayjs_min());
19859
+ var import_isSameOrBefore = __toESM(require_isSameOrBefore());
19860
+ function valueIsDateOlderThan(givenValue, expectedValue, { orEqual = false, dateFactory = () => /* @__PURE__ */ new Date() } = {}) {
19861
+ import_dayjs3.default.extend(import_isSameOrBefore.default);
19862
+ if (isValueEmpty(givenValue)) {
19863
+ return false;
19864
+ }
19865
+ if (!Array.isArray(expectedValue) || expectedValue.length !== 2) {
19866
+ throw new Error("Expected value should be array of two elements");
19867
+ }
19868
+ const values = getNumberValuesToCompare(givenValue, expectedValue[0]);
19869
+ const unit = expectedValue[1];
19870
+ switch (unit) {
19871
+ case "day":
19872
+ case "month":
19873
+ if (isArrayOfNumbers(values)) {
19874
+ const [given, units] = values;
19875
+ const date = (0, import_dayjs3.default)(given);
19876
+ const nowUnitsAdded = (0, import_dayjs3.default)(dateFactory()).add(-units, unit);
19877
+ if (orEqual) {
19878
+ return date.isSameOrBefore(nowUnitsAdded, "day");
19867
19879
  }
19868
- };
19869
- options = override.countries ? {
19870
- options: override.countries?.map((country) => ({ value: country }))
19871
- } : {};
19872
- }
19873
- if (field.view?.fieldType === "MULTILINE_ADDRESS") {
19874
- return applyMultilineAddressOverrides({
19875
- field,
19876
- override
19877
- });
19878
- }
19879
- return {
19880
- ...field,
19881
- ...pick(override, "hidden"),
19882
- ...pick(override, "readOnly"),
19883
- view: {
19884
- ...field.view,
19885
- ...pick(override, "label"),
19886
- ...pick(override, "autocomplete"),
19887
- ...pick(override, "disabled"),
19888
- ...options
19889
- },
19890
- validation: {
19891
- ...validation,
19892
- ...pick(override, "required")
19880
+ return date.isBefore(nowUnitsAdded, "day");
19893
19881
  }
19894
- };
19882
+ }
19883
+ throw new Error(`IsDateOlderThan operator: Unsupported values to compare ${givenValue}, ${expectedValue}`);
19884
+ }
19885
+
19886
+ // ../form-conditions/dist/esm/lib/set-up-operators.js
19887
+ function setUpOperators(defaultEngine2, dateFactory) {
19888
+ const operators = [
19889
+ new import_js_rules_engine.Operator(ConditionOperators.empty, (value) => valueIsMissing(value)),
19890
+ new import_js_rules_engine.Operator(ConditionOperators.notEmpty, (value) => !valueIsMissing(value)),
19891
+ new import_js_rules_engine.Operator(ConditionOperators.between, (givenValue, expectedValue) => valueIsBetween(givenValue, expectedValue)),
19892
+ new import_js_rules_engine.Operator(ConditionOperators.greaterThan, (givenValue, expectedValue) => valueIsGreaterThan(givenValue, expectedValue)),
19893
+ new import_js_rules_engine.Operator(ConditionOperators.after, (givenValue, expectedValue) => valueIsGreaterThan(givenValue, expectedValue)),
19894
+ new import_js_rules_engine.Operator(ConditionOperators.greaterThanOrEqual, (givenValue, expectedValue) => valueIsGreaterThan(givenValue, expectedValue, true)),
19895
+ new import_js_rules_engine.Operator(ConditionOperators.afterOrEqual, (givenValue, expectedValue) => valueIsGreaterThan(givenValue, expectedValue, true)),
19896
+ new import_js_rules_engine.Operator(ConditionOperators.lessThan, (givenValue, expectedValue) => valueIsLessThan(givenValue, expectedValue)),
19897
+ new import_js_rules_engine.Operator(ConditionOperators.before, (givenValue, expectedValue) => valueIsLessThan(givenValue, expectedValue)),
19898
+ new import_js_rules_engine.Operator(ConditionOperators.lessThanOrEqual, (givenValue, expectedValue) => valueIsLessThan(givenValue, expectedValue, true)),
19899
+ new import_js_rules_engine.Operator(ConditionOperators.beforeOrEqual, (givenValue, expectedValue) => valueIsLessThan(givenValue, expectedValue, true)),
19900
+ new import_js_rules_engine.Operator(ConditionOperators.contains, (givenValue, expectedValue) => valueContains(givenValue, expectedValue)),
19901
+ new import_js_rules_engine.Operator(ConditionOperators.equal, (givenValue, expectedValue) => valueEqual(givenValue, expectedValue)),
19902
+ new import_js_rules_engine.Operator(ConditionOperators.notEqual, (givenValue, expectedValue) => !valueEqual(givenValue, expectedValue)),
19903
+ new import_js_rules_engine.Operator(ConditionOperators.notContains, (givenValue, expectedValue) => !valueContains(givenValue, expectedValue)),
19904
+ new import_js_rules_engine.Operator(ConditionOperators.arrayEqual, (givenValue, expectedValue) => arrayEquals(givenValue, expectedValue)),
19905
+ new import_js_rules_engine.Operator(ConditionOperators.arrayNotEqual, (givenValue, expectedValue) => !arrayEquals(givenValue, expectedValue)),
19906
+ new import_js_rules_engine.Operator(ConditionOperators.checked, checked),
19907
+ new import_js_rules_engine.Operator(ConditionOperators.notChecked, (givenValue) => !checked(givenValue)),
19908
+ new import_js_rules_engine.Operator(ConditionOperators.any, (givenValue, expectedValue) => valueContainsAny(givenValue, expectedValue)),
19909
+ new import_js_rules_engine.Operator(ConditionOperators.in, (givenValue, expectedValue) => valueIn(givenValue, expectedValue)),
19910
+ new import_js_rules_engine.Operator(ConditionOperators.notIn, (givenValue, expectedValue) => !valueIn(givenValue, expectedValue)),
19911
+ new import_js_rules_engine.Operator(ConditionOperators.isDateNewerThan, (givenValue, expectedValue) => valueIsDateNewerThan(givenValue, expectedValue, { dateFactory })),
19912
+ new import_js_rules_engine.Operator(ConditionOperators.isDateOlderThan, (givenValue, expectedValue) => valueIsDateOlderThan(givenValue, expectedValue, { dateFactory })),
19913
+ new import_js_rules_engine.Operator(ConditionOperators.isDateNewerThanOrEqual, (givenValue, expectedValue) => valueIsDateNewerThan(givenValue, expectedValue, {
19914
+ orEqual: true,
19915
+ dateFactory
19916
+ })),
19917
+ new import_js_rules_engine.Operator(ConditionOperators.isDateOlderThanOrEqual, (givenValue, expectedValue) => valueIsDateOlderThan(givenValue, expectedValue, {
19918
+ orEqual: true,
19919
+ dateFactory
19920
+ }))
19921
+ ];
19922
+ operators.forEach((operator) => {
19923
+ defaultEngine2.removeOperator(operator.name);
19924
+ defaultEngine2.addOperator(operator);
19895
19925
  });
19896
- const nestedForms = nestedFormsByTarget ? getNestedFormArray(nestedFormsByTarget) : void 0;
19897
- return {
19898
- ...form,
19899
- fields,
19900
- ...nestedForms ? { nestedForms } : {}
19926
+ }
19927
+
19928
+ // ../form-conditions/dist/esm/lib/evaluate-override-condition.js
19929
+ function evaluateOverrideConditionFactory(dateFactory = () => /* @__PURE__ */ new Date()) {
19930
+ setUpOperators(import_js_rules_engine2.defaultEngine, dateFactory);
19931
+ return function evaluateOverrideCondition(override, submission = {}) {
19932
+ if (override.condition) {
19933
+ try {
19934
+ const rule = getRule(override.condition);
19935
+ return rule.evaluate(submission);
19936
+ } catch (e) {
19937
+ console.error(e);
19938
+ return false;
19939
+ }
19940
+ }
19941
+ return true;
19901
19942
  };
19943
+ function getRule(condition) {
19944
+ return new import_js_rules_engine2.Rule(condition);
19945
+ }
19902
19946
  }
19903
- function pick(override, key) {
19904
- return override.hasOwnProperty(key) ? { [key]: override[key] } : {};
19947
+
19948
+ // ../form-mapper/dist/esm/lib/submission-mapper.js
19949
+ function mapByIds(submission, form) {
19950
+ return mapBy(submission, form, "id");
19905
19951
  }
19906
- var getOverride = ({ target, id, overrides }) => {
19907
- if (target && target in overrides) {
19908
- return overrides[target];
19909
- }
19910
- if (id && id in overrides) {
19911
- return overrides[id];
19912
- }
19913
- return void 0;
19914
- };
19915
- var applyAddressFieldOverride = (fieldName, override, multilineAddressOptionsFields, multilineAddressFieldSettings) => {
19916
- const fieldOverride = override[fieldName];
19917
- if (!fieldOverride) {
19918
- return {
19919
- multilineAddressOptionsFields,
19920
- multilineAddressFieldSettings
19921
- };
19922
- }
19923
- return {
19924
- multilineAddressOptionsFields: {
19925
- ...multilineAddressOptionsFields,
19926
- [fieldName]: {
19927
- required: fieldOverride.required
19928
- }
19929
- },
19930
- multilineAddressFieldSettings: {
19931
- ...multilineAddressFieldSettings,
19932
- [fieldName]: {
19933
- ...multilineAddressFieldSettings?.[fieldName],
19934
- show: !fieldOverride.hidden
19935
- }
19952
+ function mapBy(submission, form, by) {
19953
+ const from = "target" ;
19954
+ const fields = (form?.fields?.length ?? 0) > 0 ? form?.fields ?? [] : (form?.formFields?.length ?? 0) > 0 ? form?.formFields ?? [] : form?.fieldsV2 ?? [];
19955
+ const getIdOrTarget = (field, _by) => {
19956
+ if (_by === "id") {
19957
+ return field[_by];
19958
+ } else if ("inputOptions" in field) {
19959
+ return field.inputOptions?.target;
19960
+ } else {
19961
+ return field.target;
19936
19962
  }
19937
19963
  };
19938
- };
19939
- var ADDRESS_FIELD_NAMES = [
19940
- "addressLine",
19941
- "addressLine2",
19942
- "streetName",
19943
- "streetNumber",
19944
- "city",
19945
- "postalCode",
19946
- "subdivision",
19947
- "country",
19948
- "apartment"
19949
- ];
19950
- var applyMultilineAddressOverrides = ({ field, override }) => {
19951
- const finalState = ADDRESS_FIELD_NAMES.reduce((state, fieldName) => applyAddressFieldOverride(fieldName, override, state.multilineAddressOptionsFields ?? {}, state.multilineAddressFieldSettings ?? {}), {
19952
- multilineAddressOptionsFields: field.validation?.predefined?.multilineAddressOptions?.fields,
19953
- multilineAddressFieldSettings: field.view?.fieldSettings
19954
- });
19955
- const autocompleteEnabled = (override.addressLine?.autocomplete || override.streetName?.autocomplete) ?? true;
19956
- const multilineAddressOptions = {
19957
- ...field.validation?.predefined?.multilineAddressOptions,
19958
- fields: {
19959
- ...field.validation?.predefined?.multilineAddressOptions?.fields,
19960
- ...finalState.multilineAddressOptionsFields
19961
- },
19962
- ...Array.isArray(override.countries) && override.countries.length > 0 ? { allowedCountries: override.countries } : {}
19963
- };
19964
- return {
19965
- ...field,
19966
- view: {
19967
- ...field.view,
19968
- fieldSettings: {
19969
- ...field.view?.fieldSettings,
19970
- ...finalState.multilineAddressFieldSettings
19971
- },
19972
- autocompleteEnabled
19973
- },
19974
- validation: {
19975
- ...field.validation,
19976
- predefined: {
19977
- ...field.validation?.predefined,
19978
- multilineAddressOptions
19979
- }
19964
+ return fields.reduce((acc, field) => {
19965
+ const source = getIdOrTarget(field, from);
19966
+ const destination = getIdOrTarget(field, by);
19967
+ if (source && destination && source !== destination && acc.hasOwnProperty(source)) {
19968
+ acc[destination] = acc[source];
19969
+ const { [source]: omitted, ...rest } = acc;
19970
+ acc = rest;
19971
+ }
19972
+ return acc;
19973
+ }, { ...submission });
19974
+ }
19975
+
19976
+ // ../form-conditions/dist/esm/lib/apply-overrides.js
19977
+ function applyOverrides(formSchema, submission) {
19978
+ const nestedForms = (formSchema?.nestedForms || []).flatMap(({ targets, form }) => (targets || []).map((target) => ({
19979
+ form: applyFormOverrides2(asRequired2(form), (submission || {})[target]),
19980
+ targets: [target]
19981
+ })));
19982
+ return { ...applyFormOverrides2(formSchema, submission), nestedForms };
19983
+ }
19984
+ function applyFormOverrides2(formSchema, submission) {
19985
+ const submissionsById = mapByIds(submission, formSchema);
19986
+ const { rules } = formSchema;
19987
+ if (rules) {
19988
+ return rules.filter((rule) => isFormRuleValid(rule, formSchema)).filter((rule) => evaluateOverrideConditionFactory()(rule, submissionsById)).reduce((form, rule) => applyItemPropertiesOverride(form, rule), formSchema);
19989
+ }
19990
+ return formSchema;
19991
+ }
19992
+
19993
+ // ../nested-form-overrides/dist/esm/lib/array-utils.js
19994
+ function partition(items, condition) {
19995
+ return items.reduce(([truthy, falsy], element) => {
19996
+ if (condition(element)) {
19997
+ truthy.push(element);
19998
+ } else {
19999
+ falsy.push(element);
19980
20000
  }
20001
+ return [truthy, falsy];
20002
+ }, [[], []]);
20003
+ }
20004
+ function mapBy2(items, keyFn) {
20005
+ return items.reduce((acc, item) => {
20006
+ acc[keyFn(item)] = item;
20007
+ return acc;
20008
+ }, {});
20009
+ }
20010
+
20011
+ // ../nested-form-overrides/dist/esm/lib/lang-utils.js
20012
+ function isDefined2(value) {
20013
+ return !(value === null || value === void 0);
20014
+ }
20015
+
20016
+ // ../nested-form-overrides/dist/esm/lib/object-utils.js
20017
+ function isEmpty(object) {
20018
+ return Boolean(object) && Boolean(Object.keys(object).length);
20019
+ }
20020
+
20021
+ // ../nested-form-overrides/dist/esm/lib/nested-form-overrides.js
20022
+ function applyNestedFormOverrides(parentForm) {
20023
+ const fieldsWithFormOverrides = parentForm.fields.filter((field) => isEmpty(field.nestedFormOverrides?.fieldOverrides));
20024
+ const fieldsWithFormOverridesByTarget = mapBy2(fieldsWithFormOverrides, (field) => field.target);
20025
+ const nestedForms = (parentForm.nestedForms || []).reduce((acc, { targets, form } = {}) => {
20026
+ const [targetsWithOverride, targetsWithoutOverride] = partition(targets, (target) => Boolean(fieldsWithFormOverridesByTarget[target]));
20027
+ const nestedFormsWithOverrides = targetsWithOverride.map((target) => ({
20028
+ targets: [target],
20029
+ form: applyOverrides2(form, fieldsWithFormOverridesByTarget[target].nestedFormOverrides)
20030
+ }));
20031
+ const nestedFormsWithoutOverrides = targetsWithoutOverride.length ? [{ targets: targetsWithoutOverride, form }] : [];
20032
+ return [
20033
+ ...acc,
20034
+ ...nestedFormsWithoutOverrides,
20035
+ ...nestedFormsWithOverrides
20036
+ ];
20037
+ }, []);
20038
+ return { ...parentForm, nestedForms };
20039
+ }
20040
+ function applyOverrides2(form, overrides) {
20041
+ const fieldOverrides = overrides.fieldOverrides;
20042
+ return {
20043
+ ...form,
20044
+ fields: form.fields.map((field) => {
20045
+ const { hidden: hiddenOverride, required: requiredOverride } = fieldOverrides[field.id] || {};
20046
+ return {
20047
+ ...field,
20048
+ ...isDefined2(hiddenOverride) && { hidden: hiddenOverride },
20049
+ ...isDefined2(requiredOverride) && isDefined2(field.validation) && {
20050
+ validation: {
20051
+ ...field.validation,
20052
+ required: requiredOverride
20053
+ }
20054
+ }
20055
+ };
20056
+ })
19981
20057
  };
19982
- };
20058
+ }
19983
20059
 
19984
20060
  // ../form-viewer/dist/esm/components/form/all-overrides.js
19985
20061
  function applyAllOverrides(form, values, overrides) {
19986
- return applyNestedForms(applyFormOverrides2(applyNestedFormOverrides(applyOverrides(form, values)), overrides ?? {}));
20062
+ return applyNestedForms(applyFormOverrides(applyNestedFormOverrides(applyOverrides(form, values)), overrides ?? {}));
19987
20063
  }
19988
20064
 
19989
20065
  // ../form-viewer/dist/esm/components/form/clear-fields.js
@@ -20028,7 +20104,7 @@ function findHiddenTargets(form) {
20028
20104
  }, []);
20029
20105
  }
20030
20106
 
20031
- // ../form-viewer/dist/esm/components/form/form-values.js
20107
+ // ../form-viewer/dist/esm/hooks/form-values.js
20032
20108
  var fillEmptyValues = (form, values, recursive = true) => {
20033
20109
  if (!form?.fields) {
20034
20110
  return {};
@@ -20066,7 +20142,7 @@ var getStepIndex = (stepId, steps) => {
20066
20142
  return 0;
20067
20143
  };
20068
20144
 
20069
- // ../form-viewer/dist/esm/components/form/normalize-values.js
20145
+ // ../form-viewer/dist/esm/hooks/use-form-values/normalize-values.js
20070
20146
  init_types_impl();
20071
20147
  init_esm2();
20072
20148
  var normalizeValues = (form, values, recursive = true, config) => {
@@ -20232,7 +20308,7 @@ function acceptOnlyValidProducts({ field, fieldValue }) {
20232
20308
  return EMPTY_VALUE;
20233
20309
  }
20234
20310
  const validProducts = fieldValue.filter((productValue) => {
20235
- const hasAllProps = isObject4(productValue) && productValue.hasOwnProperty("productId") && productValue.hasOwnProperty("price") && productValue.hasOwnProperty("quantity");
20311
+ const hasAllProps = isObject3(productValue) && productValue.hasOwnProperty("productId") && productValue.hasOwnProperty("price") && productValue.hasOwnProperty("quantity");
20236
20312
  if (!hasAllProps) {
20237
20313
  return false;
20238
20314
  }
@@ -20268,7 +20344,7 @@ function normalizeVatIDValue({ fieldValue }) {
20268
20344
  if (isEmptyValue) {
20269
20345
  return fieldValue;
20270
20346
  }
20271
- if (fieldValue && isObject4(fieldValue) && fieldValue.hasOwnProperty("id")) {
20347
+ if (fieldValue && isObject3(fieldValue) && fieldValue.hasOwnProperty("id")) {
20272
20348
  if (fieldValue.hasOwnProperty("type")) {
20273
20349
  const type = getVatIDType(vatID.id);
20274
20350
  return { id: vatID.id, type };
@@ -20364,7 +20440,7 @@ function normalizeRepeater({ field, fieldValue, config }) {
20364
20440
  fields: nestedFields
20365
20441
  };
20366
20442
  const normalizedValues = fieldValue.map((values) => {
20367
- if (!isObject4(values)) {
20443
+ if (!isObject3(values)) {
20368
20444
  return {};
20369
20445
  }
20370
20446
  const normalized = normalizeValues(nestedForm, values, false, config);
@@ -20373,7 +20449,7 @@ function normalizeRepeater({ field, fieldValue, config }) {
20373
20449
  return normalizedValues;
20374
20450
  }
20375
20451
 
20376
- // ../form-viewer/dist/esm/components/form/use-form-values.js
20452
+ // ../form-viewer/dist/esm/hooks/use-form-values/use-form-values.js
20377
20453
  var useFormValues = (form, values, onChange, config) => {
20378
20454
  const normalizedValues = React14.useMemo(() => normalizeValues(form, fillEmptyValues(form, values), true, config), [form, values, config]);
20379
20455
  React14.useEffect(() => {
@@ -20384,22 +20460,6 @@ var useFormValues = (form, values, onChange, config) => {
20384
20460
  }, [values, normalizedValues, onChange]);
20385
20461
  return normalizedValues;
20386
20462
  };
20387
- var useFormView2 = (form, stepId, breakpoint) => {
20388
- const { isMobile } = useConfig();
20389
- const experiments = useExperiments();
20390
- const useFieldsV2 = experiments.isExperimentEnabled(EXPERIMENTS.USE_FIELDS_V2);
20391
- return React14.useMemo(() => {
20392
- return (form?.steps || []).filter((step) => !stepId || stepId === step.id).map((step) => {
20393
- return createFormView({
20394
- form,
20395
- stepId: step.id,
20396
- isMobile,
20397
- breakpoint,
20398
- useFieldsV2
20399
- });
20400
- });
20401
- }, [form, stepId, isMobile, breakpoint, useFieldsV2]);
20402
- };
20403
20463
  var useScrollToFirstError = ({ form, handleStepChange, currentStepId }) => {
20404
20464
  const { setFocusedFieldId } = useFocusedField();
20405
20465
  const scrollToFirstError = React14.useCallback((errors) => {
@@ -20438,10 +20498,10 @@ function submitFormClick(params) {
20438
20498
  return { evid: 1003, src: 156, endpoint: "", params };
20439
20499
  }
20440
20500
 
20441
- // ../form-viewer/dist/esm/components/form/use-submit.js
20501
+ // ../form-viewer/dist/esm/hooks/use-submit/use-submit.js
20442
20502
  init_types_impl();
20443
20503
 
20444
- // ../form-viewer/dist/esm/components/submit-status-message/utils.js
20504
+ // ../form-viewer/dist/esm/hooks/use-submit/utils.js
20445
20505
  init_types_impl();
20446
20506
  var redirectToExternalUrl = (redirectOptions) => {
20447
20507
  const urlWithoutProtocol = redirectOptions?.redirectUrl?.replace(/^https?:\/\//, "");
@@ -20486,28 +20546,6 @@ var getCheckoutMessage = (text) => {
20486
20546
  }
20487
20547
  };
20488
20548
  };
20489
- var SubmitStatusContext = React14.createContext(void 0);
20490
- var SubmitStatusProvider = ({ children }) => {
20491
- const [submitSuccessMessage, setSubmitSuccessMessage] = React14.useState();
20492
- const [submitFailureCode, setSubmitFailureCode] = React14.useState();
20493
- const [submitFailureMessage, setSubmitFailureMessage] = React14.useState();
20494
- const value = React14.useMemo(() => ({
20495
- submitSuccessMessage,
20496
- submitFailureCode,
20497
- submitFailureMessage,
20498
- setSubmitSuccessMessage,
20499
- setSubmitFailureCode,
20500
- setSubmitFailureMessage
20501
- }), [submitSuccessMessage, submitFailureCode, submitFailureMessage]);
20502
- return React14__default.default.createElement(SubmitStatusContext.Provider, { value }, children);
20503
- };
20504
- var useSubmitStatus = () => {
20505
- const context = React14.useContext(SubmitStatusContext);
20506
- if (context === void 0) {
20507
- throw new Error("useSubmitStatus must be used within a SubmitStatusProvider");
20508
- }
20509
- return context;
20510
- };
20511
20549
 
20512
20550
  // ../form-viewer/dist/esm/features/monitoring/interactions.js
20513
20551
  var INTERACTIONS = {
@@ -20515,7 +20553,7 @@ var INTERACTIONS = {
20515
20553
  SUBMIT_FORM: "wix.forms.submit-form"
20516
20554
  };
20517
20555
 
20518
- // ../form-viewer/dist/esm/components/form/use-submit.js
20556
+ // ../form-viewer/dist/esm/types/bi.js
20519
20557
  var BiFormSubmissionStatus;
20520
20558
  (function(BiFormSubmissionStatus2) {
20521
20559
  BiFormSubmissionStatus2["INIT"] = "INITIATE_SUBMISSION";
@@ -20523,6 +20561,8 @@ var BiFormSubmissionStatus;
20523
20561
  BiFormSubmissionStatus2["FAILURE"] = "FAILURE";
20524
20562
  BiFormSubmissionStatus2["SUCCESS"] = "SUCCESS";
20525
20563
  })(BiFormSubmissionStatus || (BiFormSubmissionStatus = {}));
20564
+
20565
+ // ../form-viewer/dist/esm/hooks/use-submit/use-submit.js
20526
20566
  var useSubmit = ({ validateAndScrollToError, submitAction, onSubmit, onSubmitSuccess, onSubmitFailure, resetFormValues, values, submitSettings, handleStepChange, navigateToCheckout, onValidate, handleScrollToFirstError }) => {
20527
20567
  const { setSubmitSuccessMessage, setSubmitFailureCode, setSubmitFailureMessage } = useSubmitStatus();
20528
20568
  const { t } = useTranslation();
@@ -20610,72 +20650,194 @@ var useSubmit = ({ validateAndScrollToError, submitAction, onSubmit, onSubmitSuc
20610
20650
  handleSubmitSuccess(response);
20611
20651
  resetFormValues?.();
20612
20652
  }
20613
- return response;
20614
- }, [
20615
- validateAndScrollToError,
20616
- values,
20617
- onSubmit,
20618
- reportSubmitFormBi,
20619
- panorama,
20653
+ return response;
20654
+ }, [
20655
+ validateAndScrollToError,
20656
+ values,
20657
+ onSubmit,
20658
+ reportSubmitFormBi,
20659
+ panorama,
20660
+ submitAction,
20661
+ onSubmitFailure,
20662
+ handleCustomErrorMessages,
20663
+ handleSubmitFailure,
20664
+ onSubmitSuccess,
20665
+ fireSubmitSuccess,
20666
+ handleSubmitSuccess,
20667
+ resetFormValues
20668
+ ]);
20669
+ return { submitForm };
20670
+ };
20671
+ var useFormView2 = (form, stepId, breakpoint) => {
20672
+ const { isMobile } = useConfig();
20673
+ const experiments = useExperiments();
20674
+ const useFieldsV2 = experiments.isExperimentEnabled(EXPERIMENTS.USE_FIELDS_V2);
20675
+ return React14.useMemo(() => {
20676
+ return (form?.steps || []).filter((step) => !stepId || stepId === step.id).map((step) => {
20677
+ return createFormView({
20678
+ form,
20679
+ stepId: step.id,
20680
+ isMobile,
20681
+ breakpoint,
20682
+ useFieldsV2
20683
+ });
20684
+ });
20685
+ }, [form, stepId, isMobile, breakpoint, useFieldsV2]);
20686
+ };
20687
+ var useReportFieldEdit = (form) => {
20688
+ const lastChangedFields = React14.useRef([]);
20689
+ const bi = useBi();
20690
+ return (changedValues) => {
20691
+ const changedFieldTargets = Object.keys(changedValues);
20692
+ const isEditingDifferentFields = changedFieldTargets.length !== lastChangedFields.current.length || changedFieldTargets.some((target, index) => target !== lastChangedFields.current[index]);
20693
+ if (isEditingDifferentFields) {
20694
+ lastChangedFields.current = changedFieldTargets;
20695
+ changedFieldTargets.forEach((target) => {
20696
+ const changedField = form?.fields?.find((field) => field.target === target);
20697
+ bi.report(formFieldEdit({
20698
+ field_id: changedField?.id,
20699
+ field_label: changedField?.view?.label,
20700
+ field_target: changedField?.target || void 0
20701
+ }));
20702
+ });
20703
+ }
20704
+ };
20705
+ };
20706
+
20707
+ // ../form-viewer/dist/esm/hooks/use-form.js
20708
+ var useForm2 = ({ form: paramForm, values: paramValues, stepId, onStepIdChange, onChange, errors, onValidate, onSubmit, onSubmitSuccess, onSubmitFailure, enableScrollToFirstError = true, forwardedRef, overrides, actions, config, breakpoint, validationMode, fieldMap, inProgress }) => {
20709
+ const formWithOverrides = React14.useMemo(() => applyAllOverrides(paramForm, paramValues, overrides), [paramForm, paramValues, overrides]);
20710
+ const formId = formWithOverrides.id;
20711
+ const { setFocusedFieldId } = useFocusedField();
20712
+ const normalizedValues = useFormValues(formWithOverrides, paramValues, onChange, config);
20713
+ const valuesRef = React14.useRef(normalizedValues);
20714
+ valuesRef.current = normalizedValues;
20715
+ const errorsRef = React14.useRef(errors);
20716
+ errorsRef.current = errors;
20717
+ const reportFieldEdit = useReportFieldEdit(formWithOverrides);
20718
+ const onFieldChange = (target, newValue) => {
20719
+ const oldValues = valuesRef.current;
20720
+ const oldErrors = errorsRef.current;
20721
+ if (!deepEqual(newValue, oldValues[target])) {
20722
+ reportFieldEdit({
20723
+ [target]: newValue
20724
+ });
20725
+ const newValues = {
20726
+ ...oldValues,
20727
+ [target]: newValue
20728
+ };
20729
+ const cleared = clearFieldsWhenHiddenByRule(paramForm, overrides, oldValues, newValues, oldErrors);
20730
+ onChange(cleared.values);
20731
+ onValidate(cleared.errors);
20732
+ }
20733
+ };
20734
+ const _onValidate = (newErrors) => {
20735
+ onValidate(newErrors);
20736
+ };
20737
+ const formViews = useFormView2(formWithOverrides, stepId, breakpoint);
20738
+ const currentView = formViews[0];
20739
+ const { validateFields: validateFields2, validateStep, handleFieldValidation } = useValidation({
20740
+ form: formWithOverrides,
20741
+ errorsRef,
20742
+ setErrors: _onValidate,
20743
+ validationMode
20744
+ });
20745
+ const handleStepChange = React14.useCallback((step) => {
20746
+ const newStepId = formWithOverrides.steps?.[step]?.id;
20747
+ if (newStepId) {
20748
+ const firstFieldInStep = getSortedFields(formWithOverrides, {
20749
+ stepId: newStepId
20750
+ })[0];
20751
+ onStepIdChange?.(newStepId);
20752
+ setFocusedFieldId(firstFieldInStep?.id);
20753
+ }
20754
+ }, [formWithOverrides, onStepIdChange, setFocusedFieldId]);
20755
+ const { scrollToFirstError, handleScrollToFirstError } = useScrollToFirstError({
20756
+ form: formWithOverrides,
20757
+ handleStepChange,
20758
+ currentStepId: stepId
20759
+ });
20760
+ const resetFormValues = React14.useCallback(() => {
20761
+ onChange(fillEmptyValues(formWithOverrides, {}));
20762
+ }, [formWithOverrides, onChange]);
20763
+ const validateAndScrollToError = React14.useCallback(async (values) => {
20764
+ const validationErrors = await validateFields2(values);
20765
+ if (validationErrors && validationErrors.length) {
20766
+ handleScrollToFirstError(validationErrors);
20767
+ }
20768
+ return validationErrors;
20769
+ }, [validateFields2, handleScrollToFirstError]);
20770
+ const submitAction = React14.useCallback(async (values) => {
20771
+ const response = await actions?.submitForm?.(formId, values);
20772
+ return response?.submission;
20773
+ }, [actions, formId]);
20774
+ const { submitForm } = useSubmit({
20620
20775
  submitAction,
20621
- onSubmitFailure,
20622
- handleCustomErrorMessages,
20623
- handleSubmitFailure,
20776
+ onSubmit,
20624
20777
  onSubmitSuccess,
20625
- fireSubmitSuccess,
20626
- handleSubmitSuccess,
20627
- resetFormValues
20628
- ]);
20629
- return { submitForm };
20630
- };
20631
- var useValidation = ({ form, errorsRef, setErrors, validationMode }) => {
20632
- const { addressTemplates } = useAddressForms();
20633
- const externalData = useExternalData();
20634
- const validateFields2 = React14.useCallback(async (newValues) => {
20635
- const result2 = await validate(form, newValues, addressTemplates, validationMode);
20636
- const _errors = result2?.errors || [];
20637
- const additionalErrors = runAdditionalValidation({
20638
- form,
20639
- values: newValues,
20640
- externalData
20641
- });
20642
- const allErrors = mergeErrors({ errors: _errors, additionalErrors });
20643
- setErrors(allErrors);
20644
- return allErrors;
20645
- }, [form, setErrors, addressTemplates, externalData, validationMode]);
20646
- const handleFieldValidation = React14.useCallback(async (fieldsToValidate) => {
20647
- const fieldErrors = await getFieldErrors(fieldsToValidate, form, addressTemplates, externalData, validationMode);
20648
- const otherErrors = (errorsRef.current ?? []).filter((error) => {
20649
- return !findErrorByNormalizedPath(fieldsToValidate, error.errorPath);
20650
- });
20651
- const allErrors = [...otherErrors, ...fieldErrors];
20652
- setErrors(allErrors);
20653
- return allErrors;
20654
- }, [
20655
- errorsRef,
20656
- form,
20657
- setErrors,
20658
- addressTemplates,
20659
- externalData,
20660
- validationMode
20661
- ]);
20662
- const validateStep = React14.useCallback(async (stepId, newValues) => {
20663
- const items = form?.steps?.find((step) => step.id === stepId)?.layout?.large?.items || [];
20664
- const validationErrors = await Promise.all(items.map(async (item) => {
20665
- const field = form?.fields?.find((_field) => _field.id === item.fieldId);
20666
- const fieldValidationResult = field?.target ? await handleFieldValidation([
20667
- {
20668
- path: field.target,
20669
- value: newValues[field.target]
20778
+ onSubmitFailure,
20779
+ resetFormValues,
20780
+ validateAndScrollToError,
20781
+ values: normalizedValues,
20782
+ submitSettings: formWithOverrides.submitSettings,
20783
+ navigateToCheckout: actions?.navigateToCheckout,
20784
+ handleStepChange,
20785
+ onValidate: _onValidate,
20786
+ handleScrollToFirstError
20787
+ });
20788
+ React14.useImperativeHandle(forwardedRef, () => ({
20789
+ submit: submitForm,
20790
+ validate: async () => {
20791
+ const validationErrors = await validateFields2(normalizedValues);
20792
+ if (validationErrors && validationErrors.length > 0) {
20793
+ if (enableScrollToFirstError) {
20794
+ scrollToFirstError(validationErrors);
20670
20795
  }
20671
- ]) : [];
20672
- return fieldValidationResult;
20673
- }));
20674
- const validationErrorsFlatten = validationErrors.flat();
20675
- setErrors(validationErrorsFlatten);
20676
- return !validationErrorsFlatten.length;
20677
- }, [form, setErrors, handleFieldValidation]);
20678
- return { validateFields: validateFields2, validateStep, handleFieldValidation };
20796
+ return false;
20797
+ }
20798
+ return true;
20799
+ },
20800
+ validateStep: (step) => validateStep(step, normalizedValues)
20801
+ }), [
20802
+ submitForm,
20803
+ validateStep,
20804
+ validateFields2,
20805
+ normalizedValues,
20806
+ enableScrollToFirstError,
20807
+ scrollToFirstError
20808
+ ]);
20809
+ const currentStep = getStepIndex(stepId, formWithOverrides.steps);
20810
+ const setNextStep = React14.useCallback(() => handleStepChange(currentStep + 1), [currentStep, handleStepChange]);
20811
+ const setPreviousStep = React14.useCallback(() => handleStepChange(currentStep - 1), [currentStep, handleStepChange]);
20812
+ const fieldActions = React14.useMemo(() => actions ? {
20813
+ actions: { ...actions, submitForm, setNextStep, setPreviousStep },
20814
+ formId,
20815
+ inProgress
20816
+ } : { actions: { submitForm, setNextStep, setPreviousStep } }, [actions, formId, inProgress, submitForm, setNextStep, setPreviousStep]);
20817
+ const formFields = createFormFields({
20818
+ form: currentView,
20819
+ formSchema: formWithOverrides,
20820
+ values: normalizedValues,
20821
+ onFieldChange,
20822
+ errors,
20823
+ FieldLayout: DefaultFieldLayout,
20824
+ fields: fieldMap,
20825
+ validateFields: handleFieldValidation,
20826
+ fieldActions
20827
+ });
20828
+ return {
20829
+ currentView,
20830
+ formViews,
20831
+ normalizedValues,
20832
+ onFieldChange,
20833
+ errors,
20834
+ formFields,
20835
+ handleFieldValidation,
20836
+ formWithOverrides,
20837
+ currentStep,
20838
+ fieldActions,
20839
+ submitForm
20840
+ };
20679
20841
  };
20680
20842
  var dummyBi = {
20681
20843
  log: () => Promise.resolve(),
@@ -20813,127 +20975,6 @@ var FormViewerProvider = ({ i18n, bi, biFormFillSessionId, form, isMobile, isEdi
20813
20975
  )
20814
20976
  );
20815
20977
  };
20816
- var useForm2 = ({ form: paramForm, values: paramValues, stepId, onStepIdChange, onChange, errors, onValidate, enableScrollToFirstError = true, forwardedRef, overrides, actions, config, breakpoint, validationMode, fieldMap }) => {
20817
- const formWithOverrides = React14.useMemo(() => applyAllOverrides(paramForm, paramValues, overrides), [paramForm, paramValues, overrides]);
20818
- const formId = formWithOverrides.id;
20819
- const { setFocusedFieldId } = useFocusedField();
20820
- const normalizedValues = useFormValues(formWithOverrides, paramValues, onChange, config);
20821
- const valuesRef = React14.useRef(normalizedValues);
20822
- valuesRef.current = normalizedValues;
20823
- const errorsRef = React14.useRef(errors);
20824
- errorsRef.current = errors;
20825
- const onFieldChange = (target, newValue) => {
20826
- const oldValues = valuesRef.current;
20827
- const oldErrors = errorsRef.current;
20828
- if (!deepEqual(newValue, oldValues[target])) {
20829
- const newValues = {
20830
- ...oldValues,
20831
- [target]: newValue
20832
- };
20833
- const cleared = clearFieldsWhenHiddenByRule(paramForm, overrides, oldValues, newValues, oldErrors);
20834
- onChange(cleared.values);
20835
- onValidate(cleared.errors);
20836
- }
20837
- };
20838
- const _onValidate = (newErrors) => {
20839
- onValidate(newErrors);
20840
- };
20841
- const formViews = useFormView2(formWithOverrides, stepId, breakpoint);
20842
- const currentView = formViews[0];
20843
- const { validateFields: validateFields2, validateStep, handleFieldValidation } = useValidation({
20844
- form: formWithOverrides,
20845
- errorsRef,
20846
- setErrors: _onValidate,
20847
- validationMode
20848
- });
20849
- const handleStepChange = React14.useCallback((step) => {
20850
- const newStepId = formWithOverrides.steps?.[step]?.id;
20851
- if (newStepId) {
20852
- const firstFieldInStep = getSortedFields(formWithOverrides, {
20853
- stepId: newStepId
20854
- })[0];
20855
- onStepIdChange?.(newStepId);
20856
- setFocusedFieldId(firstFieldInStep?.id);
20857
- }
20858
- }, [formWithOverrides, onStepIdChange, setFocusedFieldId]);
20859
- const { scrollToFirstError, handleScrollToFirstError } = useScrollToFirstError({
20860
- form: formWithOverrides,
20861
- handleStepChange,
20862
- currentStepId: stepId
20863
- });
20864
- const resetFormValues = React14.useCallback(() => {
20865
- onChange(fillEmptyValues(formWithOverrides, {}));
20866
- }, [formWithOverrides, onChange]);
20867
- const validateAndScrollToError = React14.useCallback(async (values) => {
20868
- const validationErrors = await validateFields2(values);
20869
- if (validationErrors && validationErrors.length) {
20870
- handleScrollToFirstError(validationErrors);
20871
- }
20872
- return validationErrors;
20873
- }, [validateFields2, handleScrollToFirstError]);
20874
- const submitAction = React14.useCallback(async (values) => {
20875
- const response = await actions?.submitForm?.(formId, values);
20876
- return response?.submission;
20877
- }, [actions, formId]);
20878
- const { submitForm } = useSubmit({
20879
- submitAction,
20880
- resetFormValues,
20881
- validateAndScrollToError,
20882
- values: normalizedValues,
20883
- submitSettings: formWithOverrides.submitSettings,
20884
- navigateToCheckout: actions?.navigateToCheckout,
20885
- handleStepChange,
20886
- onValidate: _onValidate,
20887
- handleScrollToFirstError
20888
- });
20889
- React14.useImperativeHandle(forwardedRef, () => ({
20890
- submit: submitForm,
20891
- validate: async () => {
20892
- const validationErrors = await validateFields2(normalizedValues);
20893
- if (validationErrors && validationErrors.length > 0) {
20894
- if (enableScrollToFirstError) {
20895
- scrollToFirstError(validationErrors);
20896
- }
20897
- return false;
20898
- }
20899
- return true;
20900
- },
20901
- validateStep: (step) => validateStep(step, normalizedValues)
20902
- }), [
20903
- submitForm,
20904
- validateStep,
20905
- validateFields2,
20906
- normalizedValues,
20907
- enableScrollToFirstError,
20908
- scrollToFirstError
20909
- ]);
20910
- const currentStep = getStepIndex(stepId, formWithOverrides.steps);
20911
- const setNextStep = React14.useCallback(() => handleStepChange(currentStep + 1), [currentStep, handleStepChange]);
20912
- const setPreviousStep = React14.useCallback(() => handleStepChange(currentStep - 1), [currentStep, handleStepChange]);
20913
- const fieldActions = React14.useMemo(() => actions ? {
20914
- actions: { ...actions, submitForm, setNextStep, setPreviousStep },
20915
- formId,
20916
- inProgress: false
20917
- } : { actions: { submitForm, setNextStep, setPreviousStep } }, [actions, formId, submitForm, setNextStep, setPreviousStep]);
20918
- const formFields = createFormFields({
20919
- form: currentView,
20920
- formSchema: formWithOverrides,
20921
- values: normalizedValues,
20922
- onFieldChange,
20923
- errors,
20924
- FieldLayout: DefaultFieldLayout,
20925
- fields: fieldMap,
20926
- validateFields: handleFieldValidation,
20927
- fieldActions
20928
- });
20929
- return {
20930
- currentView,
20931
- normalizedValues,
20932
- onFieldChange,
20933
- errors,
20934
- formFields
20935
- };
20936
- };
20937
20978
  function normalizeSchema(obj) {
20938
20979
  if (Array.isArray(obj)) {
20939
20980
  return obj.map(normalizeSchema);