@vtex/country-forms 1.1.0 → 1.2.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/CHANGELOG.md +29 -1
- package/dist/{BRA-PMVV6KOM.js → BRA-CWGYPPBD.js} +43 -27
- package/dist/BRA-CWGYPPBD.js.map +1 -0
- package/dist/{BRA-ZBZXE5II.mjs → BRA-R2DBJTZ2.mjs} +43 -27
- package/dist/BRA-R2DBJTZ2.mjs.map +1 -0
- package/dist/CAN-RDQPFPZU.mjs +127 -0
- package/dist/CAN-RDQPFPZU.mjs.map +1 -0
- package/dist/CAN-ZJQJFUW4.js +129 -0
- package/dist/CAN-ZJQJFUW4.js.map +1 -0
- package/dist/MEX-6CJCALY3.js +125 -0
- package/dist/MEX-6CJCALY3.js.map +1 -0
- package/dist/MEX-ZQL7ZS3G.mjs +123 -0
- package/dist/MEX-ZQL7ZS3G.mjs.map +1 -0
- package/dist/USA-2QW25XAI.mjs +128 -0
- package/dist/USA-2QW25XAI.mjs.map +1 -0
- package/dist/USA-MWP4SDGW.js +130 -0
- package/dist/USA-MWP4SDGW.js.map +1 -0
- package/dist/{bra-MHTXSNLA.js → bra-DQO5W7HB.js} +7 -15
- package/dist/bra-DQO5W7HB.js.map +1 -0
- package/dist/{bra-ILOTR4AN.mjs → bra-MJUXI46I.mjs} +4 -15
- package/dist/bra-MJUXI46I.mjs.map +1 -0
- package/dist/can-3MOZIOGB.js +65 -0
- package/dist/can-3MOZIOGB.js.map +1 -0
- package/dist/can-DKTB2M6I.mjs +41 -0
- package/dist/can-DKTB2M6I.mjs.map +1 -0
- package/dist/can-LLWX4LC2.js +48 -0
- package/dist/can-LLWX4LC2.js.map +1 -0
- package/dist/can-OONXPDKH.mjs +59 -0
- package/dist/can-OONXPDKH.mjs.map +1 -0
- package/dist/chunk-B2XPLIJU.mjs +19 -0
- package/dist/chunk-B2XPLIJU.mjs.map +1 -0
- package/dist/chunk-ZQQPNXLP.js +21 -0
- package/dist/chunk-ZQQPNXLP.js.map +1 -0
- package/dist/common-E4IN3G46.mjs +4 -0
- package/dist/common-E4IN3G46.mjs.map +1 -0
- package/dist/common-LFDTUEMM.js +13 -0
- package/dist/common-LFDTUEMM.js.map +1 -0
- package/dist/{en-US-YW7UYXNB.mjs → en-US-KHII5INO.mjs} +22 -2
- package/dist/en-US-KHII5INO.mjs.map +1 -0
- package/dist/{en-US-RLEM27ZZ.js → en-US-RCNO3BZC.js} +22 -2
- package/dist/en-US-RCNO3BZC.js.map +1 -0
- package/dist/{es-MX-K5MWKMJW.js → es-MX-IGOEW2P4.js} +22 -2
- package/dist/es-MX-IGOEW2P4.js.map +1 -0
- package/dist/{es-MX-AGRGVXRK.mjs → es-MX-R24GRBU5.mjs} +22 -2
- package/dist/es-MX-R24GRBU5.mjs.map +1 -0
- package/dist/{fr-FR-KWQ3MPP5.mjs → fr-FR-N4WJAN23.mjs} +22 -2
- package/dist/fr-FR-N4WJAN23.mjs.map +1 -0
- package/dist/{fr-FR-LJIPE6BH.js → fr-FR-WZBI6O4O.js} +22 -2
- package/dist/fr-FR-WZBI6O4O.js.map +1 -0
- package/dist/index.d.mts +178 -7
- package/dist/index.d.ts +178 -7
- package/dist/index.js +109 -37
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +104 -38
- package/dist/index.mjs.map +1 -1
- package/dist/mex-AMEX6IHY.mjs +108 -0
- package/dist/mex-AMEX6IHY.mjs.map +1 -0
- package/dist/mex-DYWVMWB6.js +38 -0
- package/dist/mex-DYWVMWB6.js.map +1 -0
- package/dist/mex-VX3Y5I6I.mjs +33 -0
- package/dist/mex-VX3Y5I6I.mjs.map +1 -0
- package/dist/mex-Y56WV2L7.js +114 -0
- package/dist/mex-Y56WV2L7.js.map +1 -0
- package/dist/{pt-BR-P2RZ3X3H.mjs → pt-BR-PIBP3JHL.mjs} +25 -2
- package/dist/pt-BR-PIBP3JHL.mjs.map +1 -0
- package/dist/{pt-BR-74IZNREP.js → pt-BR-ZDM55ITO.js} +25 -2
- package/dist/pt-BR-ZDM55ITO.js.map +1 -0
- package/dist/usa-AC7YPVS3.mjs +52 -0
- package/dist/usa-AC7YPVS3.mjs.map +1 -0
- package/dist/usa-B6NCCTF6.js +61 -0
- package/dist/usa-B6NCCTF6.js.map +1 -0
- package/dist/usa-LOOP7MRM.mjs +55 -0
- package/dist/usa-LOOP7MRM.mjs.map +1 -0
- package/dist/usa-OQ44AFEI.js +61 -0
- package/dist/usa-OQ44AFEI.js.map +1 -0
- package/package.json +1 -1
- package/dist/BRA-PMVV6KOM.js.map +0 -1
- package/dist/BRA-ZBZXE5II.mjs.map +0 -1
- package/dist/bra-ILOTR4AN.mjs.map +0 -1
- package/dist/bra-MHTXSNLA.js.map +0 -1
- package/dist/can-7TMYDEJF.mjs +0 -17
- package/dist/can-7TMYDEJF.mjs.map +0 -1
- package/dist/can-B5ME2ZFN.js +0 -20
- package/dist/can-B5ME2ZFN.js.map +0 -1
- package/dist/can-FGNN5MZS.mjs +0 -19
- package/dist/can-FGNN5MZS.mjs.map +0 -1
- package/dist/can-LLJ4A5Y5.js +0 -21
- package/dist/can-LLJ4A5Y5.js.map +0 -1
- package/dist/en-US-RLEM27ZZ.js.map +0 -1
- package/dist/en-US-YW7UYXNB.mjs.map +0 -1
- package/dist/es-MX-AGRGVXRK.mjs.map +0 -1
- package/dist/es-MX-K5MWKMJW.js.map +0 -1
- package/dist/fr-FR-KWQ3MPP5.mjs.map +0 -1
- package/dist/fr-FR-LJIPE6BH.js.map +0 -1
- package/dist/mex-5BKCF6LS.js +0 -21
- package/dist/mex-5BKCF6LS.js.map +0 -1
- package/dist/mex-G3HMNBBF.mjs +0 -19
- package/dist/mex-G3HMNBBF.mjs.map +0 -1
- package/dist/pt-BR-74IZNREP.js.map +0 -1
- package/dist/pt-BR-P2RZ3X3H.mjs.map +0 -1
- package/dist/usa-3AM7UFVG.js +0 -20
- package/dist/usa-3AM7UFVG.js.map +0 -1
- package/dist/usa-I7DK2CTL.mjs +0 -18
- package/dist/usa-I7DK2CTL.mjs.map +0 -1
- package/dist/usa-LXT6WW64.js +0 -21
- package/dist/usa-LXT6WW64.js.map +0 -1
- package/dist/usa-ZD5OWGAD.mjs +0 -18
- package/dist/usa-ZD5OWGAD.mjs.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -188,6 +188,93 @@ interface FieldDefinition {
|
|
|
188
188
|
* }
|
|
189
189
|
*/
|
|
190
190
|
conditionalOptions?: Record<string, SelectOption[] | string>;
|
|
191
|
+
/**
|
|
192
|
+
* Map from a controller field's value to a validator name for this field.
|
|
193
|
+
* Used when a single field validates differently depending on another field's
|
|
194
|
+
* selection — e.g. a `document` field validated as a CPF for individuals and as
|
|
195
|
+
* a CNPJ for businesses.
|
|
196
|
+
*
|
|
197
|
+
* Requires {@link FieldDefinition.dependsOn} to identify the controller field.
|
|
198
|
+
* When a matching key exists for the current controller value, it overrides
|
|
199
|
+
* {@link ValidationRules.customValidator}. Resolve the effective validator with
|
|
200
|
+
* `resolveFieldValidator(field, values)`.
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* dependsOn: "personType"
|
|
204
|
+
* conditionalValidator: { individual: "validateCPF", business: "validateCNPJ" }
|
|
205
|
+
*
|
|
206
|
+
* @remarks
|
|
207
|
+
* Declaring this property also opts the field into automatic reset: `setValue`
|
|
208
|
+
* clears the field's value to `''` whenever the controller ({@link FieldDefinition.dependsOn})
|
|
209
|
+
* changes, because the validation domain — and therefore any previously entered
|
|
210
|
+
* value — is no longer guaranteed to be valid (e.g. a CPF is not a valid CNPJ).
|
|
211
|
+
* If a future field needs a conditional validator *without* this reset, add a
|
|
212
|
+
* dedicated opt-out flag rather than relying on the absence of this behavior.
|
|
213
|
+
*/
|
|
214
|
+
conditionalValidator?: Record<string, string>;
|
|
215
|
+
/**
|
|
216
|
+
* Map from a controller field's value to a format function name for this field.
|
|
217
|
+
* Same semantics as {@link FieldDefinition.conditionalValidator} but for the mask
|
|
218
|
+
* applied on display. Overrides {@link FieldDefinition.formatRef} when a key
|
|
219
|
+
* matches. Resolve the effective ref with `resolveFieldFormatRef(field, values)`.
|
|
220
|
+
*
|
|
221
|
+
* A missing key falls back to {@link FieldDefinition.formatRef} (or identity when
|
|
222
|
+
* neither is set), so a controller value with no mask is valid.
|
|
223
|
+
*
|
|
224
|
+
* @example
|
|
225
|
+
* dependsOn: "personType"
|
|
226
|
+
* conditionalFormatRef: { individual: "formatCPF", business: "formatCNPJ" }
|
|
227
|
+
*/
|
|
228
|
+
conditionalFormatRef?: Record<string, string>;
|
|
229
|
+
/**
|
|
230
|
+
* Map from a controller field's value to an unformat function name for this field.
|
|
231
|
+
* Symmetric to {@link FieldDefinition.conditionalFormatRef}. Overrides
|
|
232
|
+
* {@link FieldDefinition.unformatRef} when a key matches. Resolve the effective ref
|
|
233
|
+
* with `resolveFieldUnformatRef(field, values)`.
|
|
234
|
+
*
|
|
235
|
+
* @example
|
|
236
|
+
* dependsOn: "personType"
|
|
237
|
+
* conditionalUnformatRef: { individual: "unformatCPF", business: "unformatCNPJ" }
|
|
238
|
+
*/
|
|
239
|
+
conditionalUnformatRef?: Record<string, string>;
|
|
240
|
+
/**
|
|
241
|
+
* Map from a controller field's value to an {@link InputMode} for this field.
|
|
242
|
+
* Same semantics as {@link FieldDefinition.conditionalValidator} but for the
|
|
243
|
+
* mobile virtual-keyboard hint. Overrides {@link FieldDefinition.inputMode} when
|
|
244
|
+
* a key matches. Resolve the effective value with `resolveFieldInputMode(field, values)`.
|
|
245
|
+
*
|
|
246
|
+
* Useful when a single field expects different input per controller value — e.g.
|
|
247
|
+
* a numeric keyboard for a numeric CPF (individual) but a text keyboard for an
|
|
248
|
+
* alphanumeric CNPJ (business).
|
|
249
|
+
*
|
|
250
|
+
* @example
|
|
251
|
+
* dependsOn: "personType"
|
|
252
|
+
* conditionalInputMode: { individual: "numeric", business: "text" }
|
|
253
|
+
*/
|
|
254
|
+
conditionalInputMode?: Record<string, InputMode>;
|
|
255
|
+
/**
|
|
256
|
+
* Name of the sibling field that drives {@link FieldDefinition.derivedValue}.
|
|
257
|
+
*
|
|
258
|
+
* A field with `derivedFrom` is **data-only**: its value is computed automatically
|
|
259
|
+
* from the controller and it is never rendered (excluded from `getVisibleFields`)
|
|
260
|
+
* nor validated. It exists so the form state matches the API payload shape — e.g.
|
|
261
|
+
* a `documentType` field derived from `personType` so submissions carry both
|
|
262
|
+
* `document` and `documentType`.
|
|
263
|
+
*
|
|
264
|
+
* @example "personType"
|
|
265
|
+
*/
|
|
266
|
+
derivedFrom?: string;
|
|
267
|
+
/**
|
|
268
|
+
* Map from the {@link FieldDefinition.derivedFrom} controller value to this
|
|
269
|
+
* field's automatically-maintained value. `createFormState` seeds it and
|
|
270
|
+
* `setValue` recomputes it whenever the controller changes. A controller value
|
|
271
|
+
* with no entry resolves to `""`.
|
|
272
|
+
*
|
|
273
|
+
* @example
|
|
274
|
+
* derivedFrom: "personType"
|
|
275
|
+
* derivedValue: { individual: "cpf", business: "cnpj" }
|
|
276
|
+
*/
|
|
277
|
+
derivedValue?: Record<string, string>;
|
|
191
278
|
/**
|
|
192
279
|
* Declarative visibility condition.
|
|
193
280
|
* When present, the field is shown and validated only while the condition is `true`.
|
|
@@ -214,8 +301,9 @@ interface FieldDefinition {
|
|
|
214
301
|
conditionalPlaceholder?: Record<string, string>;
|
|
215
302
|
/**
|
|
216
303
|
* Name of the sibling field that drives {@link FieldDefinition.conditionalLabel},
|
|
217
|
-
* {@link FieldDefinition.conditionalPlaceholder},
|
|
218
|
-
* {@link FieldDefinition.
|
|
304
|
+
* {@link FieldDefinition.conditionalPlaceholder}, {@link FieldDefinition.conditionalOptions},
|
|
305
|
+
* {@link FieldDefinition.conditionalValidator}, {@link FieldDefinition.conditionalFormatRef},
|
|
306
|
+
* {@link FieldDefinition.conditionalUnformatRef}, and {@link FieldDefinition.conditionalInputMode}.
|
|
219
307
|
* Required when any of those properties is set.
|
|
220
308
|
* @example "personType", "state"
|
|
221
309
|
*/
|
|
@@ -467,9 +555,15 @@ declare function createFormState(schema: FormSchema, defaults?: Partial<FormValu
|
|
|
467
555
|
* The updated field is automatically marked as `touched: true`.
|
|
468
556
|
*
|
|
469
557
|
* When the changed field is referenced by another field's `dependsOn` and that
|
|
470
|
-
* field has `conditionalOptions`, the dependent field's
|
|
471
|
-
* reset to `''`. This prevents stale values when the
|
|
472
|
-
*
|
|
558
|
+
* field has `conditionalOptions` or `conditionalValidator`, the dependent field's
|
|
559
|
+
* value is automatically reset to `''`. This prevents stale values when the
|
|
560
|
+
* controller field changes — e.g. selecting a different state clears the previously
|
|
561
|
+
* selected city, or switching `personType` clears the `document` whose validator
|
|
562
|
+
* (CPF vs CNPJ) just changed.
|
|
563
|
+
*
|
|
564
|
+
* Derived, data-only fields ({@link FieldDefinition.derivedFrom}) referencing the
|
|
565
|
+
* changed field are recomputed from their `derivedValue` map (e.g. `documentType`
|
|
566
|
+
* follows `personType`).
|
|
473
567
|
*
|
|
474
568
|
* Existing errors are preserved so the consumer can decide when to re-validate.
|
|
475
569
|
* To clear all errors after a change, spread: `{ ...setValue(state, schema, f, v), errors: {} }`.
|
|
@@ -687,6 +781,83 @@ declare function unformatValue(ref: string | undefined, value: string): string;
|
|
|
687
781
|
*/
|
|
688
782
|
declare function resolveFieldOptions(field: FieldDefinition, values: FormValues): SelectOption[] | null;
|
|
689
783
|
|
|
784
|
+
/**
|
|
785
|
+
* @module engine/resolveField
|
|
786
|
+
*
|
|
787
|
+
* Resolvers for fields whose label, placeholder, validator, or mask change based
|
|
788
|
+
* on a sibling controller field (declared via `dependsOn`).
|
|
789
|
+
*
|
|
790
|
+
* These mirror {@link resolveFieldOptions}: each resolver looks up the controller
|
|
791
|
+
* value in the field's conditional map and falls back to the field's static
|
|
792
|
+
* property when no entry matches. They let a single field — e.g. a `document`
|
|
793
|
+
* field — behave as a CPF for individuals and a CNPJ for businesses without the
|
|
794
|
+
* consumer hard-coding the mapping.
|
|
795
|
+
*/
|
|
796
|
+
|
|
797
|
+
/**
|
|
798
|
+
* Resolves the effective i18n label **key** for a field given the current values.
|
|
799
|
+
*
|
|
800
|
+
* Resolution order:
|
|
801
|
+
* 1) `conditionalLabel` entry matching `values[dependsOn]`
|
|
802
|
+
* 2) `field.label` fallback
|
|
803
|
+
*
|
|
804
|
+
* @returns The i18n key to pass to `resolveLabel`.
|
|
805
|
+
*/
|
|
806
|
+
declare function resolveFieldLabel(field: FieldDefinition, values: FormValues): string;
|
|
807
|
+
/**
|
|
808
|
+
* Resolves the effective i18n placeholder **key** for a field, or `undefined`
|
|
809
|
+
* when the field has neither a conditional nor a static placeholder.
|
|
810
|
+
*
|
|
811
|
+
* Resolution order:
|
|
812
|
+
* 1) `conditionalPlaceholder` entry matching `values[dependsOn]`
|
|
813
|
+
* 2) `field.placeholder` fallback
|
|
814
|
+
*/
|
|
815
|
+
declare function resolveFieldPlaceholder(field: FieldDefinition, values: FormValues): string | undefined;
|
|
816
|
+
/**
|
|
817
|
+
* Resolves the effective validator name for a field given the current values.
|
|
818
|
+
*
|
|
819
|
+
* Resolution order:
|
|
820
|
+
* 1) `conditionalValidator` entry matching `values[dependsOn]`
|
|
821
|
+
* 2) `field.validation.customValidator` fallback
|
|
822
|
+
*
|
|
823
|
+
* @returns The validator name to resolve from the rules registry, or `undefined`
|
|
824
|
+
* when the field has no custom validator for the current controller value.
|
|
825
|
+
*/
|
|
826
|
+
declare function resolveFieldValidator(field: FieldDefinition, values: FormValues): string | undefined;
|
|
827
|
+
/**
|
|
828
|
+
* Resolves the effective format function name for a field given the current values.
|
|
829
|
+
*
|
|
830
|
+
* Resolution order:
|
|
831
|
+
* 1) `conditionalFormatRef` entry matching `values[dependsOn]`
|
|
832
|
+
* 2) `field.formatRef` fallback
|
|
833
|
+
*
|
|
834
|
+
* Pass the result to `formatValue(ref, raw)`; `undefined` yields identity.
|
|
835
|
+
*/
|
|
836
|
+
declare function resolveFieldFormatRef(field: FieldDefinition, values: FormValues): string | undefined;
|
|
837
|
+
/**
|
|
838
|
+
* Resolves the effective unformat function name for a field given the current values.
|
|
839
|
+
*
|
|
840
|
+
* Resolution order:
|
|
841
|
+
* 1) `conditionalUnformatRef` entry matching `values[dependsOn]`
|
|
842
|
+
* 2) `field.unformatRef` fallback
|
|
843
|
+
*
|
|
844
|
+
* Pass the result to `unformatValue(ref, display)`; `undefined` yields identity.
|
|
845
|
+
*/
|
|
846
|
+
declare function resolveFieldUnformatRef(field: FieldDefinition, values: FormValues): string | undefined;
|
|
847
|
+
/**
|
|
848
|
+
* Resolves the effective `inputMode` (mobile keyboard hint) for a field given
|
|
849
|
+
* the current values.
|
|
850
|
+
*
|
|
851
|
+
* Resolution order:
|
|
852
|
+
* 1) `conditionalInputMode` entry matching `values[dependsOn]`
|
|
853
|
+
* 2) `field.inputMode` fallback
|
|
854
|
+
*
|
|
855
|
+
* Lets a single field hint a different virtual keyboard per controller value —
|
|
856
|
+
* e.g. a `document` field that is numeric for an individual (CPF) and text for a
|
|
857
|
+
* business (alphanumeric CNPJ).
|
|
858
|
+
*/
|
|
859
|
+
declare function resolveFieldInputMode(field: FieldDefinition, values: FormValues): InputMode | undefined;
|
|
860
|
+
|
|
690
861
|
/**
|
|
691
862
|
* Dynamic import map for address schemas.
|
|
692
863
|
* Each country is loaded on demand via `import()` for code-splitting.
|
|
@@ -724,7 +895,7 @@ declare const SUPPORTED_ADDRESS_COUNTRIES: readonly string[];
|
|
|
724
895
|
*
|
|
725
896
|
* @example
|
|
726
897
|
* import { SUPPORTED_PERSONAL_DATA_COUNTRIES } from '@vtex/country-forms'
|
|
727
|
-
* // currently supported countries: → ['BRA']
|
|
898
|
+
* // currently supported countries: → ['BRA', 'CAN', 'USA']
|
|
728
899
|
*/
|
|
729
900
|
declare const SUPPORTED_PERSONAL_DATA_COUNTRIES: readonly string[];
|
|
730
901
|
|
|
@@ -875,4 +1046,4 @@ declare const SUPPORTED_LOCALES: readonly ["en-US", "es-MX", "fr-FR", "pt-BR"];
|
|
|
875
1046
|
/** Union of BCP 47 tags with dedicated built-in bundles. */
|
|
876
1047
|
type SupportedLocale = (typeof SUPPORTED_LOCALES)[number];
|
|
877
1048
|
|
|
878
|
-
export { type ConditionalOperator, type ConditionalVisibility, type FieldDefinition, type FieldType, type FormErrors, type FormSchema, type FormState, type FormType, type FormValues, type FormatFn, type I18nBundle, type I18nOverrides, type I18nParams, type InputMode, SUPPORTED_ADDRESS_COUNTRIES, SUPPORTED_LOCALES, SUPPORTED_PERSONAL_DATA_COUNTRIES, type SelectOption, type SupportedLocale, type UnformatFn, type ValidationErrors, type ValidationRules, type ValidatorFn, createFormState, formatValue, getVisibleFields, loadLocale, loadSchema, resolveFieldOptions, resolveLabel, setValue, unformatValue, validate };
|
|
1049
|
+
export { type ConditionalOperator, type ConditionalVisibility, type FieldDefinition, type FieldType, type FormErrors, type FormSchema, type FormState, type FormType, type FormValues, type FormatFn, type I18nBundle, type I18nOverrides, type I18nParams, type InputMode, SUPPORTED_ADDRESS_COUNTRIES, SUPPORTED_LOCALES, SUPPORTED_PERSONAL_DATA_COUNTRIES, type SelectOption, type SupportedLocale, type UnformatFn, type ValidationErrors, type ValidationRules, type ValidatorFn, createFormState, formatValue, getVisibleFields, loadLocale, loadSchema, resolveFieldFormatRef, resolveFieldInputMode, resolveFieldLabel, resolveFieldOptions, resolveFieldPlaceholder, resolveFieldUnformatRef, resolveFieldValidator, resolveLabel, setValue, unformatValue, validate };
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var chunkYB6VNXLI_js = require('./chunk-YB6VNXLI.js');
|
|
4
|
-
var chunkCFX5EF4R_js = require('./chunk-CFX5EF4R.js');
|
|
5
4
|
var chunkBQPGLWMB_js = require('./chunk-BQPGLWMB.js');
|
|
5
|
+
var chunkCFX5EF4R_js = require('./chunk-CFX5EF4R.js');
|
|
6
6
|
|
|
7
7
|
// src/engine/createFormState.ts
|
|
8
8
|
function createFormState(schema, defaults) {
|
|
@@ -12,6 +12,12 @@ function createFormState(schema, defaults) {
|
|
|
12
12
|
values[field.name] = defaults?.[field.name] ?? "";
|
|
13
13
|
touched[field.name] = false;
|
|
14
14
|
}
|
|
15
|
+
for (const field of schema.fields) {
|
|
16
|
+
if (field.derivedFrom !== void 0) {
|
|
17
|
+
const controllerValue = values[field.derivedFrom] ?? "";
|
|
18
|
+
values[field.name] = field.derivedValue?.[controllerValue] ?? "";
|
|
19
|
+
}
|
|
20
|
+
}
|
|
15
21
|
return { values, errors: {}, touched };
|
|
16
22
|
}
|
|
17
23
|
|
|
@@ -23,9 +29,12 @@ function setValue(state, schema, fieldName, value) {
|
|
|
23
29
|
touched: { ...state.touched, [fieldName]: true }
|
|
24
30
|
};
|
|
25
31
|
for (const field of schema.fields) {
|
|
26
|
-
if (field.dependsOn === fieldName && field.conditionalOptions !== void 0) {
|
|
32
|
+
if (field.dependsOn === fieldName && (field.conditionalOptions !== void 0 || field.conditionalValidator !== void 0)) {
|
|
27
33
|
next.values[field.name] = "";
|
|
28
34
|
}
|
|
35
|
+
if (field.derivedFrom === fieldName) {
|
|
36
|
+
next.values[field.name] = field.derivedValue?.[value] ?? "";
|
|
37
|
+
}
|
|
29
38
|
}
|
|
30
39
|
return next;
|
|
31
40
|
}
|
|
@@ -35,6 +44,9 @@ function getVisibleFields(schema, values) {
|
|
|
35
44
|
return schema.fields.filter((field) => isFieldVisible(field, values));
|
|
36
45
|
}
|
|
37
46
|
function isFieldVisible(field, values) {
|
|
47
|
+
if (field.derivedFrom !== void 0) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
38
50
|
if (field.conditionalVisibility === void 0) {
|
|
39
51
|
return true;
|
|
40
52
|
}
|
|
@@ -58,6 +70,33 @@ function evaluateCondition(condition, values) {
|
|
|
58
70
|
}
|
|
59
71
|
}
|
|
60
72
|
|
|
73
|
+
// src/engine/resolveField.ts
|
|
74
|
+
function resolveConditional(field, map, values) {
|
|
75
|
+
if (field.dependsOn === void 0 || map === void 0) {
|
|
76
|
+
return void 0;
|
|
77
|
+
}
|
|
78
|
+
const controllerValue = values[field.dependsOn] ?? "";
|
|
79
|
+
return Object.prototype.hasOwnProperty.call(map, controllerValue) ? map[controllerValue] : void 0;
|
|
80
|
+
}
|
|
81
|
+
function resolveFieldLabel(field, values) {
|
|
82
|
+
return resolveConditional(field, field.conditionalLabel, values) ?? field.label;
|
|
83
|
+
}
|
|
84
|
+
function resolveFieldPlaceholder(field, values) {
|
|
85
|
+
return resolveConditional(field, field.conditionalPlaceholder, values) ?? field.placeholder;
|
|
86
|
+
}
|
|
87
|
+
function resolveFieldValidator(field, values) {
|
|
88
|
+
return resolveConditional(field, field.conditionalValidator, values) ?? field.validation?.customValidator;
|
|
89
|
+
}
|
|
90
|
+
function resolveFieldFormatRef(field, values) {
|
|
91
|
+
return resolveConditional(field, field.conditionalFormatRef, values) ?? field.formatRef;
|
|
92
|
+
}
|
|
93
|
+
function resolveFieldUnformatRef(field, values) {
|
|
94
|
+
return resolveConditional(field, field.conditionalUnformatRef, values) ?? field.unformatRef;
|
|
95
|
+
}
|
|
96
|
+
function resolveFieldInputMode(field, values) {
|
|
97
|
+
return resolveConditional(field, field.conditionalInputMode, values) ?? field.inputMode;
|
|
98
|
+
}
|
|
99
|
+
|
|
61
100
|
// src/engine/validate.ts
|
|
62
101
|
var VALIDATION_REQUIRED_KEY = "country-forms.validation.required";
|
|
63
102
|
var VALIDATION_INVALID_KEY = "country-forms.validation.invalid";
|
|
@@ -65,14 +104,14 @@ function validate(state, schema) {
|
|
|
65
104
|
const errors = {};
|
|
66
105
|
for (const field of getVisibleFields(schema, state.values)) {
|
|
67
106
|
const value = state.values[field.name] ?? "";
|
|
68
|
-
const error = validateField(field, value);
|
|
107
|
+
const error = validateField(field, value, state.values);
|
|
69
108
|
if (error !== null) {
|
|
70
109
|
errors[field.name] = error;
|
|
71
110
|
}
|
|
72
111
|
}
|
|
73
112
|
return errors;
|
|
74
113
|
}
|
|
75
|
-
function validateField(field, value) {
|
|
114
|
+
function validateField(field, value, values) {
|
|
76
115
|
const trimmed = value.trim();
|
|
77
116
|
if (field.required && trimmed === "") {
|
|
78
117
|
return VALIDATION_REQUIRED_KEY;
|
|
@@ -81,23 +120,23 @@ function validateField(field, value) {
|
|
|
81
120
|
return null;
|
|
82
121
|
}
|
|
83
122
|
const rules = field.validation;
|
|
84
|
-
if (
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
return rules.pattern.message;
|
|
123
|
+
if (rules) {
|
|
124
|
+
if (rules.minLength !== void 0 && value.length < rules.minLength.value) {
|
|
125
|
+
return rules.minLength.message;
|
|
126
|
+
}
|
|
127
|
+
if (rules.maxLength !== void 0 && value.length > rules.maxLength.value) {
|
|
128
|
+
return rules.maxLength.message;
|
|
129
|
+
}
|
|
130
|
+
if (rules.pattern !== void 0) {
|
|
131
|
+
const regex = new RegExp(rules.pattern.value);
|
|
132
|
+
if (!regex.test(value)) {
|
|
133
|
+
return rules.pattern.message;
|
|
134
|
+
}
|
|
97
135
|
}
|
|
98
136
|
}
|
|
99
|
-
|
|
100
|
-
|
|
137
|
+
const customValidator = resolveFieldValidator(field, values);
|
|
138
|
+
if (customValidator !== void 0) {
|
|
139
|
+
const fn = chunkCFX5EF4R_js.resolveValidator(customValidator);
|
|
101
140
|
const result = fn(value);
|
|
102
141
|
if (result === true) {
|
|
103
142
|
return null;
|
|
@@ -226,7 +265,7 @@ async function loadAddressSchema(iso3) {
|
|
|
226
265
|
case "BRA": {
|
|
227
266
|
const [{ default: schema }] = await Promise.all([
|
|
228
267
|
import('./BRA-VIVRV7X7.js'),
|
|
229
|
-
import('./bra-
|
|
268
|
+
import('./bra-DQO5W7HB.js'),
|
|
230
269
|
import('./bra-KEBYAD75.js'),
|
|
231
270
|
import('./bra-states-SQMU4WTB.js')
|
|
232
271
|
]);
|
|
@@ -235,8 +274,8 @@ async function loadAddressSchema(iso3) {
|
|
|
235
274
|
case "CAN": {
|
|
236
275
|
const [{ default: schema }] = await Promise.all([
|
|
237
276
|
import('./CAN-NGS6AUBG.js'),
|
|
238
|
-
import('./can-
|
|
239
|
-
import('./can-
|
|
277
|
+
import('./can-3MOZIOGB.js'),
|
|
278
|
+
import('./can-LLWX4LC2.js'),
|
|
240
279
|
import('./can-provinces-6NOHMW37.js')
|
|
241
280
|
]);
|
|
242
281
|
return schema;
|
|
@@ -244,7 +283,7 @@ async function loadAddressSchema(iso3) {
|
|
|
244
283
|
case "MEX": {
|
|
245
284
|
const [{ default: schema }] = await Promise.all([
|
|
246
285
|
import('./MEX-3PMZHDQP.js'),
|
|
247
|
-
import('./mex-
|
|
286
|
+
import('./mex-Y56WV2L7.js'),
|
|
248
287
|
import('./mex-states-GTCRN4NS.js')
|
|
249
288
|
]);
|
|
250
289
|
return schema;
|
|
@@ -252,8 +291,8 @@ async function loadAddressSchema(iso3) {
|
|
|
252
291
|
case "USA": {
|
|
253
292
|
const [{ default: schema }] = await Promise.all([
|
|
254
293
|
import('./USA-UBWW5NQB.js'),
|
|
255
|
-
import('./usa-
|
|
256
|
-
import('./usa-
|
|
294
|
+
import('./usa-B6NCCTF6.js'),
|
|
295
|
+
import('./usa-OQ44AFEI.js'),
|
|
257
296
|
import('./usa-states-EBFT4LUQ.js')
|
|
258
297
|
]);
|
|
259
298
|
return schema;
|
|
@@ -264,17 +303,44 @@ async function loadAddressSchema(iso3) {
|
|
|
264
303
|
}
|
|
265
304
|
|
|
266
305
|
// src/schemas/personal-data/loader.ts
|
|
267
|
-
var SUPPORTED_PERSONAL_DATA_COUNTRIES = ["BRA"];
|
|
306
|
+
var SUPPORTED_PERSONAL_DATA_COUNTRIES = ["BRA", "CAN", "MEX", "USA"];
|
|
268
307
|
async function loadPersonalDataSchema(iso3) {
|
|
269
308
|
switch (iso3) {
|
|
270
309
|
case "BRA": {
|
|
271
310
|
const [{ default: schema }] = await Promise.all([
|
|
272
|
-
import('./BRA-
|
|
273
|
-
import('./bra-
|
|
311
|
+
import('./BRA-CWGYPPBD.js'),
|
|
312
|
+
import('./bra-DQO5W7HB.js'),
|
|
274
313
|
import('./bra-KEBYAD75.js')
|
|
275
314
|
]);
|
|
276
315
|
return schema;
|
|
277
316
|
}
|
|
317
|
+
case "CAN": {
|
|
318
|
+
const [{ default: schema }] = await Promise.all([
|
|
319
|
+
import('./CAN-ZJQJFUW4.js'),
|
|
320
|
+
import('./common-LFDTUEMM.js'),
|
|
321
|
+
import('./can-3MOZIOGB.js'),
|
|
322
|
+
import('./can-LLWX4LC2.js')
|
|
323
|
+
]);
|
|
324
|
+
return schema;
|
|
325
|
+
}
|
|
326
|
+
case "MEX": {
|
|
327
|
+
const [{ default: schema }] = await Promise.all([
|
|
328
|
+
import('./MEX-6CJCALY3.js'),
|
|
329
|
+
import('./common-LFDTUEMM.js'),
|
|
330
|
+
import('./mex-Y56WV2L7.js'),
|
|
331
|
+
import('./mex-DYWVMWB6.js')
|
|
332
|
+
]);
|
|
333
|
+
return schema;
|
|
334
|
+
}
|
|
335
|
+
case "USA": {
|
|
336
|
+
const [{ default: schema }] = await Promise.all([
|
|
337
|
+
import('./USA-MWP4SDGW.js'),
|
|
338
|
+
import('./common-LFDTUEMM.js'),
|
|
339
|
+
import('./usa-B6NCCTF6.js'),
|
|
340
|
+
import('./usa-OQ44AFEI.js')
|
|
341
|
+
]);
|
|
342
|
+
return schema;
|
|
343
|
+
}
|
|
278
344
|
default:
|
|
279
345
|
return createFallbackSchema(iso3, "personal-data");
|
|
280
346
|
}
|
|
@@ -294,26 +360,26 @@ async function loadSchema(iso3, formType) {
|
|
|
294
360
|
async function loadLocale(locale) {
|
|
295
361
|
switch (locale) {
|
|
296
362
|
case "en-US":
|
|
297
|
-
return import('./en-US-
|
|
363
|
+
return import('./en-US-RCNO3BZC.js').then((m) => m.default);
|
|
298
364
|
case "es-MX":
|
|
299
|
-
return import('./es-MX-
|
|
365
|
+
return import('./es-MX-IGOEW2P4.js').then((m) => m.default);
|
|
300
366
|
case "fr-FR":
|
|
301
|
-
return import('./fr-FR-
|
|
367
|
+
return import('./fr-FR-WZBI6O4O.js').then((m) => m.default);
|
|
302
368
|
case "pt-BR":
|
|
303
|
-
return import('./pt-BR-
|
|
369
|
+
return import('./pt-BR-ZDM55ITO.js').then((m) => m.default);
|
|
304
370
|
}
|
|
305
371
|
const lang = locale.split("-")[0]?.toLowerCase();
|
|
306
372
|
switch (lang) {
|
|
307
373
|
case "en":
|
|
308
|
-
return import('./en-US-
|
|
374
|
+
return import('./en-US-RCNO3BZC.js').then((m) => m.default);
|
|
309
375
|
case "es":
|
|
310
|
-
return import('./es-MX-
|
|
376
|
+
return import('./es-MX-IGOEW2P4.js').then((m) => m.default);
|
|
311
377
|
case "fr":
|
|
312
|
-
return import('./fr-FR-
|
|
378
|
+
return import('./fr-FR-WZBI6O4O.js').then((m) => m.default);
|
|
313
379
|
case "pt":
|
|
314
|
-
return import('./pt-BR-
|
|
380
|
+
return import('./pt-BR-ZDM55ITO.js').then((m) => m.default);
|
|
315
381
|
default:
|
|
316
|
-
return import('./en-US-
|
|
382
|
+
return import('./en-US-RCNO3BZC.js').then((m) => m.default);
|
|
317
383
|
}
|
|
318
384
|
}
|
|
319
385
|
|
|
@@ -351,7 +417,13 @@ exports.formatValue = formatValue;
|
|
|
351
417
|
exports.getVisibleFields = getVisibleFields;
|
|
352
418
|
exports.loadLocale = loadLocale;
|
|
353
419
|
exports.loadSchema = loadSchema;
|
|
420
|
+
exports.resolveFieldFormatRef = resolveFieldFormatRef;
|
|
421
|
+
exports.resolveFieldInputMode = resolveFieldInputMode;
|
|
422
|
+
exports.resolveFieldLabel = resolveFieldLabel;
|
|
354
423
|
exports.resolveFieldOptions = resolveFieldOptions;
|
|
424
|
+
exports.resolveFieldPlaceholder = resolveFieldPlaceholder;
|
|
425
|
+
exports.resolveFieldUnformatRef = resolveFieldUnformatRef;
|
|
426
|
+
exports.resolveFieldValidator = resolveFieldValidator;
|
|
355
427
|
exports.resolveLabel = resolveLabel;
|
|
356
428
|
exports.setValue = setValue;
|
|
357
429
|
exports.unformatValue = unformatValue;
|