@digigov/form 2.0.0-d0adc9fb → 2.0.0-d2ffc726
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/Field/ErrorGroup/index.js +48 -0
- package/{inputs/inputsScenarios → Field/ErrorGroup}/package.json +1 -1
- package/Field/ErrorGroup.d.ts +15 -0
- package/Field/ErrorGroup.js.map +7 -0
- package/Field/FieldBase/index.js +37 -26
- package/Field/FieldBase.d.ts +1 -1
- package/Field/FieldBase.js.map +2 -2
- package/Field/FieldBaseContainer/index.js +37 -17
- package/Field/FieldBaseContainer.d.ts +2 -2
- package/Field/FieldBaseContainer.js.map +2 -2
- package/Field/FieldConditional/index.js +4 -0
- package/Field/FieldConditional.d.ts +1 -1
- package/Field/FieldConditional.js.map +2 -2
- package/Field/index.d.ts +1 -1
- package/Field/index.js +24 -28
- package/Field/index.js.map +2 -2
- package/Field/types.d.ts +23 -12
- package/Field/utils/evaluateFieldWithConditions.d.ts +2 -2
- package/Field/utils/evaluateFieldWithConditions.js.map +2 -2
- package/Field/utils/resolveField/index.js +35 -0
- package/Field/utils/{calculateField → resolveField}/package.json +1 -1
- package/Field/utils/resolveField.d.ts +3 -0
- package/Field/utils/resolveField.js.map +7 -0
- package/Field/utils/useField/index.js +12 -3
- package/Field/utils/useField.d.ts +1 -1
- package/Field/utils/useField.js.map +2 -2
- package/FieldArray/BaseFieldArray/index.js +76 -0
- package/FieldArray/BaseFieldArray/package.json +6 -0
- package/FieldArray/BaseFieldArray.d.ts +5 -0
- package/FieldArray/BaseFieldArray.js.map +7 -0
- package/FieldArray/FieldArray.stories.d.ts +2 -0
- package/FieldArray/FormDialog/ArrayDisplay/ArrayContainerDisplay/index.js +23 -0
- package/FieldArray/FormDialog/ArrayDisplay/ArrayContainerDisplay/package.json +6 -0
- package/FieldArray/FormDialog/ArrayDisplay/ArrayContainerDisplay.d.ts +9 -0
- package/FieldArray/FormDialog/ArrayDisplay/ArrayContainerDisplay.js.map +7 -0
- package/FieldArray/FormDialog/ArrayDisplay/ArrayDisplay.stories.d.ts +13 -0
- package/FieldArray/FormDialog/ArrayDisplay/ArrayItemDisplay/index.js +184 -0
- package/FieldArray/FormDialog/ArrayDisplay/ArrayItemDisplay/package.json +6 -0
- package/FieldArray/FormDialog/ArrayDisplay/ArrayItemDisplay.d.ts +26 -0
- package/FieldArray/FormDialog/ArrayDisplay/ArrayItemDisplay.js.map +7 -0
- package/FieldArray/FormDialog/ArrayDisplay/ArrayItemHeader/index.js +11 -0
- package/FieldArray/FormDialog/ArrayDisplay/ArrayItemHeader/package.json +6 -0
- package/FieldArray/FormDialog/ArrayDisplay/ArrayItemHeader.d.ts +5 -0
- package/FieldArray/FormDialog/ArrayDisplay/ArrayItemHeader.js.map +7 -0
- package/FieldArray/FormDialog/ArrayDisplay/__stories__/Cards.d.ts +2 -0
- package/FieldArray/FormDialog/ArrayDisplay/__stories__/Default.d.ts +2 -0
- package/FieldArray/FormDialog/ArrayDisplay/__stories__/ReadOnly.d.ts +2 -0
- package/FieldArray/FormDialog/ArrayDisplay/__stories__/ReadOnlyCards.d.ts +2 -0
- package/FieldArray/FormDialog/ArrayDisplay/__stories__/Sortable.d.ts +2 -0
- package/FieldArray/FormDialog/ArrayDisplay/__stories__/SortableCards.d.ts +2 -0
- package/FieldArray/FormDialog/ArrayDisplay/index.d.ts +15 -0
- package/FieldArray/FormDialog/ArrayDisplay/index.js +57 -0
- package/FieldArray/FormDialog/ArrayDisplay/index.js.map +7 -0
- package/{inputs/Input/inputsInputScenarios → FieldArray/FormDialog/ArrayDisplay}/package.json +1 -1
- package/FieldArray/FormDialog/ArrayEditModal/index.js +158 -0
- package/FieldArray/FormDialog/ArrayEditModal/package.json +6 -0
- package/FieldArray/FormDialog/ArrayEditModal.d.ts +26 -0
- package/FieldArray/FormDialog/ArrayEditModal.js.map +7 -0
- package/FieldArray/FormDialog/index.d.ts +19 -0
- package/FieldArray/FormDialog/index.js +213 -257
- package/FieldArray/FormDialog/index.js.map +7 -0
- package/FieldArray/__stories__/CardsWithError.d.ts +15 -0
- package/FieldArray/__stories__/Default.d.ts +1 -1
- package/FieldArray/__stories__/WithExactLength.d.ts +1 -1
- package/FieldArray/__stories__/WithModal.d.ts +2 -0
- package/FieldArray/index.d.ts +5 -2
- package/FieldArray/index.js +41 -57
- package/FieldArray/index.js.map +2 -2
- package/FieldObject/index.d.ts +7 -4
- package/FieldObject/index.js +30 -27
- package/FieldObject/index.js.map +2 -2
- package/Fieldset/FieldsetWithContext.js.map +1 -1
- package/Fieldset/index.d.ts +1 -1
- package/Fieldset/index.js.map +1 -1
- package/Fieldset/types.d.ts +2 -2
- package/FormBuilder/FormBuilder.stories.d.ts +4 -0
- package/FormBuilder/__stories__/AutoErrorGrouping.d.ts +3 -0
- package/FormBuilder/__stories__/Default.d.ts +1 -1
- package/FormBuilder/__stories__/ErrorGrouping.d.ts +3 -0
- package/FormBuilder/index.d.ts +2 -2
- package/FormBuilder/index.js +186 -80
- package/FormBuilder/index.js.map +2 -2
- package/FormContext/index.js +6 -2
- package/FormContext.d.ts +3 -2
- package/FormContext.js.map +2 -2
- package/MultiplicityField/MultiplicityField.stories.d.ts +2 -0
- package/MultiplicityField/__stories__/Default.d.ts +1 -1
- package/MultiplicityField/__stories__/PreviewDisplay.d.ts +1 -1
- package/MultiplicityField/__stories__/WithExactLength.d.ts +1 -1
- package/MultiplicityField/__stories__/WithMaxLength.d.ts +1 -1
- package/MultiplicityField/__stories__/WithMinAndMaxLength.d.ts +1 -1
- package/MultiplicityField/__stories__/WithMinLength.d.ts +1 -1
- package/MultiplicityField/add-objects/index.js +12 -19
- package/MultiplicityField/add-objects.d.ts +1 -1
- package/MultiplicityField/add-objects.js.map +2 -2
- package/MultiplicityField/index.d.ts +2 -2
- package/MultiplicityField/index.js +6 -2
- package/MultiplicityField/index.js.map +2 -2
- package/MultiplicityField/types.d.ts +3 -2
- package/Questions/Questions.d.ts +1 -1
- package/Questions/Questions.js.map +1 -1
- package/Questions/Questions.stories.d.ts +2 -0
- package/Questions/QuestionsContext.d.ts +1 -1
- package/Questions/QuestionsContext.js.map +1 -1
- package/Questions/Step/Step.d.ts +1 -1
- package/Questions/Step/Step.js.map +1 -1
- package/Questions/Step/StepArrayReview.d.ts +1 -1
- package/Questions/Step/StepArrayReview.js.map +1 -1
- package/Questions/Step/StepContext.d.ts +1 -1
- package/Questions/Step/StepContext.js.map +1 -1
- package/Questions/Step/StepDescription.d.ts +1 -1
- package/Questions/Step/StepDescription.js.map +2 -2
- package/Questions/Step/StepForm.d.ts +2 -2
- package/Questions/Step/StepForm.js.map +1 -1
- package/Questions/Step/StepQuote.d.ts +1 -1
- package/Questions/Step/StepQuote.js.map +2 -2
- package/Questions/Step/StepTitle.d.ts +1 -1
- package/Questions/Step/StepTitle.js.map +2 -2
- package/Questions/Step/getAddMoreFields.d.ts +2 -2
- package/Questions/Step/getAddMoreFields.js.map +1 -1
- package/Questions/Step/types.d.ts +1 -1
- package/Questions/__stories__/Default.d.ts +1 -1
- package/Questions/getNextStep.d.ts +1 -1
- package/Questions/getNextStep.js.map +1 -1
- package/Questions/types.d.ts +1 -1
- package/cjs/Field/ErrorGroup/index.js +82 -0
- package/cjs/Field/ErrorGroup.js.map +7 -0
- package/cjs/Field/FieldBase/index.js +36 -25
- package/cjs/Field/FieldBase.js.map +2 -2
- package/cjs/Field/FieldBaseContainer/index.js +36 -16
- package/cjs/Field/FieldBaseContainer.js.map +3 -3
- package/cjs/Field/FieldConditional/index.js +4 -0
- package/cjs/Field/FieldConditional.js.map +2 -2
- package/cjs/Field/index.js +24 -25
- package/cjs/Field/index.js.map +2 -2
- package/cjs/Field/types.js.map +1 -1
- package/cjs/Field/utils/evaluateFieldWithConditions.js.map +2 -2
- package/cjs/Field/utils/resolveField/index.js +55 -0
- package/cjs/Field/utils/resolveField.js.map +7 -0
- package/cjs/Field/utils/useField/index.js +12 -3
- package/cjs/Field/utils/useField.js.map +2 -2
- package/cjs/FieldArray/BaseFieldArray/index.js +109 -0
- package/cjs/FieldArray/BaseFieldArray.js.map +7 -0
- package/cjs/FieldArray/FormDialog/ArrayDisplay/ArrayContainerDisplay/index.js +56 -0
- package/cjs/FieldArray/FormDialog/ArrayDisplay/ArrayContainerDisplay.js.map +7 -0
- package/cjs/FieldArray/FormDialog/ArrayDisplay/ArrayItemDisplay/index.js +209 -0
- package/cjs/FieldArray/FormDialog/ArrayDisplay/ArrayItemDisplay.js.map +7 -0
- package/cjs/{locales/el → FieldArray/FormDialog/ArrayDisplay/ArrayItemHeader}/index.js +16 -7
- package/cjs/FieldArray/FormDialog/ArrayDisplay/ArrayItemHeader.js.map +7 -0
- package/cjs/FieldArray/FormDialog/ArrayDisplay/index.js +90 -0
- package/cjs/FieldArray/FormDialog/ArrayDisplay/index.js.map +7 -0
- package/cjs/FieldArray/FormDialog/ArrayEditModal/index.js +186 -0
- package/cjs/FieldArray/FormDialog/ArrayEditModal.js.map +7 -0
- package/cjs/FieldArray/FormDialog/index.js +204 -243
- package/cjs/FieldArray/FormDialog/index.js.map +7 -0
- package/cjs/FieldArray/index.js +40 -56
- package/cjs/FieldArray/index.js.map +3 -3
- package/cjs/FieldObject/index.js +30 -24
- package/cjs/FieldObject/index.js.map +2 -2
- package/cjs/Fieldset/FieldsetWithContext.js.map +1 -1
- package/cjs/Fieldset/index.js.map +1 -1
- package/cjs/Fieldset/types.js.map +1 -1
- package/cjs/FormBuilder/index.js +188 -82
- package/cjs/FormBuilder/index.js.map +3 -3
- package/cjs/FormContext/index.js +7 -2
- package/cjs/FormContext.js.map +2 -2
- package/cjs/MultiplicityField/add-objects/index.js +11 -13
- package/cjs/MultiplicityField/add-objects.js.map +2 -2
- package/cjs/MultiplicityField/index.js +6 -2
- package/cjs/MultiplicityField/index.js.map +2 -2
- package/cjs/MultiplicityField/types.js.map +1 -1
- package/cjs/Questions/Questions.js.map +1 -1
- package/cjs/Questions/QuestionsContext.js.map +1 -1
- package/cjs/Questions/Step/Step.js.map +1 -1
- package/cjs/Questions/Step/StepArrayReview.js.map +1 -1
- package/cjs/Questions/Step/StepContext.js.map +1 -1
- package/cjs/Questions/Step/StepDescription.js.map +2 -2
- package/cjs/Questions/Step/StepForm.js.map +1 -1
- package/cjs/Questions/Step/StepQuote.js.map +2 -2
- package/cjs/Questions/Step/StepTitle.js.map +2 -2
- package/cjs/Questions/Step/getAddMoreFields.js.map +1 -1
- package/cjs/Questions/Step/types.js.map +1 -1
- package/cjs/Questions/getNextStep.js.map +1 -1
- package/cjs/Questions/types.js.map +1 -1
- package/cjs/hooks/useFieldFocusManager/index.js +135 -0
- package/cjs/hooks/useFieldFocusManager.js.map +7 -0
- package/cjs/hooks/utils/index.js +98 -0
- package/cjs/hooks/utils.js.map +7 -0
- package/cjs/inputs/AutoCompleteInput/index.js.map +2 -2
- package/cjs/inputs/Checkboxes/index.js +67 -62
- package/cjs/inputs/Checkboxes/index.js.map +2 -2
- package/cjs/inputs/DateInput/index.js +54 -19
- package/cjs/inputs/DateInput/index.js.map +2 -2
- package/cjs/inputs/DateTimeInput/index.js +83 -39
- package/cjs/inputs/DateTimeInput/index.js.map +2 -2
- package/cjs/inputs/FileInput/index.js +68 -30
- package/cjs/inputs/FileInput/index.js.map +2 -2
- package/cjs/inputs/ImageInput/__stories__/logo.d/index.js +1 -0
- package/cjs/inputs/ImageInput/__stories__/logo.d.js.map +7 -0
- package/cjs/inputs/ImageInput/index.js +42 -10
- package/cjs/inputs/ImageInput/index.js.map +2 -2
- package/cjs/inputs/Input/index.js +55 -55
- package/cjs/inputs/Input/index.js.map +2 -2
- package/cjs/inputs/Label/index.js.map +1 -1
- package/cjs/inputs/OtpInput/index.js +36 -30
- package/cjs/inputs/OtpInput/index.js.map +2 -2
- package/cjs/inputs/Radio/index.js +5 -4
- package/cjs/inputs/Radio/index.js.map +3 -3
- package/cjs/inputs/Select/index.js +5 -3
- package/cjs/inputs/Select/index.js.map +2 -2
- package/cjs/{Field/utils → inputs/registry}/index.js +7 -5
- package/cjs/inputs/registry.js.map +7 -0
- package/cjs/lazy/index.js +16 -10
- package/cjs/lazy.js.map +2 -2
- package/cjs/registry/index.js +31 -15
- package/cjs/registry.js.map +2 -2
- package/cjs/types.js.map +1 -1
- package/cjs/utils/index.js +20 -6
- package/cjs/utils.js.map +2 -2
- package/cjs/validators/index.js +33 -19
- package/cjs/validators/index.js.map +2 -2
- package/cjs/validators/types.js.map +1 -1
- package/cjs/validators/utils/amka/index.js +60 -0
- package/cjs/validators/utils/amka.js.map +7 -0
- package/cjs/validators/utils/date/index.js +26 -3
- package/cjs/validators/utils/date.js.map +2 -2
- package/cjs/validators/utils/datetime/index.js +118 -24
- package/cjs/validators/utils/datetime.js.map +2 -2
- package/cjs/validators/utils/email/index.js +39 -0
- package/cjs/validators/utils/email.js.map +7 -0
- package/cjs/validators/utils/file/index.js +30 -17
- package/cjs/validators/utils/file.js.map +2 -2
- package/cjs/validators/utils/iban.js.map +1 -1
- package/cjs/validators/utils/image.js.map +1 -1
- package/cjs/validators/utils/index.js +5 -1
- package/cjs/validators/utils/index.js.map +2 -2
- package/cjs/validators/utils/int/index.js +1 -1
- package/cjs/validators/utils/int.js.map +2 -2
- package/cjs/validators/utils/number/index.js +1 -1
- package/cjs/validators/utils/number.js.map +2 -2
- package/cjs/validators/utils/otp.js.map +1 -1
- package/cjs/validators/utils/phone.js.map +1 -1
- package/cjs/validators/utils/postal_code.js.map +1 -1
- package/cjs/validators/utils/text_limit.js.map +1 -1
- package/hooks/useFieldFocusManager/index.js +116 -0
- package/hooks/useFieldFocusManager/package.json +6 -0
- package/hooks/useFieldFocusManager.d.ts +25 -0
- package/hooks/useFieldFocusManager.js.map +7 -0
- package/hooks/utils/index.js +73 -0
- package/{Field → hooks}/utils/package.json +1 -1
- package/hooks/utils.d.ts +18 -0
- package/hooks/utils.js.map +7 -0
- package/index.js +1 -1
- package/inputs/AutoCompleteInput/AutoComplete.stories.d.ts +2 -0
- package/inputs/AutoCompleteInput/__stories__/Default.d.ts +1 -1
- package/inputs/AutoCompleteInput/__stories__/Multiple.d.ts +1 -1
- package/inputs/AutoCompleteInput/index.d.ts +3 -3
- package/inputs/AutoCompleteInput/index.js +1 -3
- package/inputs/AutoCompleteInput/index.js.map +2 -2
- package/inputs/Checkboxes/Checkboxes.stories.d.ts +2 -0
- package/inputs/Checkboxes/__stories__/Conditional.d.ts +1 -1
- package/inputs/Checkboxes/__stories__/Default.d.ts +1 -1
- package/inputs/Checkboxes/__stories__/WithDivider.d.ts +1 -1
- package/inputs/Checkboxes/index.d.ts +3 -3
- package/inputs/Checkboxes/index.js +67 -62
- package/inputs/Checkboxes/index.js.map +2 -2
- package/inputs/DateInput/DateInput.stories.d.ts +6 -0
- package/inputs/DateInput/__stories__/Default.d.ts +1 -1
- package/inputs/DateInput/__stories__/WithDefaultValue.d.ts +3 -0
- package/inputs/DateInput/__stories__/WithInitialValue.d.ts +3 -0
- package/inputs/DateInput/__stories__/WithWrongDefaultValue.d.ts +3 -0
- package/inputs/DateInput/__stories__/WithWrongInitialValue.d.ts +3 -0
- package/inputs/DateInput/index.d.ts +2 -5
- package/inputs/DateInput/index.js +55 -20
- package/inputs/DateInput/index.js.map +2 -2
- package/inputs/DateTimeInput/DateTimeInput.stories.d.ts +10 -3
- package/inputs/DateTimeInput/__stories__/Default.d.ts +1 -1
- package/inputs/DateTimeInput/__stories__/WithDefaultValue.d.ts +3 -0
- package/inputs/DateTimeInput/__stories__/WithInitialValue.d.ts +3 -0
- package/inputs/DateTimeInput/__stories__/WithWrongDefaultValue.d.ts +3 -0
- package/inputs/DateTimeInput/__stories__/WithWrongInitialValue.d.ts +3 -0
- package/inputs/DateTimeInput/index.d.ts +2 -5
- package/inputs/DateTimeInput/index.js +84 -40
- package/inputs/DateTimeInput/index.js.map +2 -2
- package/inputs/FileInput/FileInput.stories.d.ts +3 -0
- package/inputs/FileInput/__stories__/Default.d.ts +1 -1
- package/inputs/FileInput/__stories__/WithBorderAndLink.d.ts +3 -0
- package/inputs/FileInput/index.d.ts +18 -2
- package/inputs/FileInput/index.js +69 -31
- package/inputs/FileInput/index.js.map +2 -2
- package/inputs/ImageInput/ImageInput.stories.d.ts +4 -1
- package/inputs/ImageInput/__stories__/Default.d.ts +1 -1
- package/inputs/ImageInput/__stories__/MaxSize.d.ts +1 -1
- package/inputs/ImageInput/__stories__/WithInitialValues.d.ts +3 -0
- package/inputs/ImageInput/__stories__/WithInvalidImageDimension.d.ts +1 -1
- package/inputs/ImageInput/__stories__/logo.d/index.js +1 -0
- package/inputs/ImageInput/__stories__/logo.d/package.json +6 -0
- package/inputs/ImageInput/__stories__/logo.d.js.map +7 -0
- package/inputs/ImageInput/index.d.ts +10 -2
- package/inputs/ImageInput/index.js +43 -11
- package/inputs/ImageInput/index.js.map +2 -2
- package/inputs/Input/Input.stories.d.ts +5 -0
- package/inputs/Input/__stories__/AFM.d.ts +1 -1
- package/inputs/Input/__stories__/AMKA.d.ts +3 -0
- package/inputs/Input/__stories__/Boolean.d.ts +1 -1
- package/inputs/Input/__stories__/Email.d.ts +3 -0
- package/inputs/Input/__stories__/IBAN.d.ts +1 -1
- package/inputs/Input/__stories__/Integer.d.ts +1 -1
- package/inputs/Input/__stories__/LandlineNumber.d.ts +1 -1
- package/inputs/Input/__stories__/MobilePhone.d.ts +1 -1
- package/inputs/Input/__stories__/PhoneNumber.d.ts +1 -1
- package/inputs/Input/__stories__/PostalCode.d.ts +1 -1
- package/inputs/Input/__stories__/String.d.ts +1 -1
- package/inputs/Input/__stories__/StringWithTrimValidation.d.ts +3 -0
- package/inputs/Input/__stories__/TextWithLimit.d.ts +1 -1
- package/inputs/Input/index.d.ts +4 -3
- package/inputs/Input/index.js +55 -55
- package/inputs/Input/index.js.map +2 -2
- package/inputs/Label/Label.stories.d.ts +2 -0
- package/inputs/Label/__stories__/Default.d.ts +1 -1
- package/inputs/Label/index.d.ts +1 -1
- package/inputs/Label/index.js.map +1 -1
- package/inputs/OtpInput/OtpInput.stories.d.ts +2 -0
- package/inputs/OtpInput/__stories__/Default.d.ts +1 -1
- package/inputs/OtpInput/index.d.ts +1 -5
- package/inputs/OtpInput/index.js +36 -30
- package/inputs/OtpInput/index.js.map +2 -2
- package/inputs/Radio/Radio.stories.d.ts +2 -0
- package/inputs/Radio/__stories__/Conditional.d.ts +1 -1
- package/inputs/Radio/__stories__/Default.d.ts +1 -1
- package/inputs/Radio/__stories__/WithDivider.d.ts +1 -1
- package/inputs/Radio/index.d.ts +4 -4
- package/inputs/Radio/index.js +5 -4
- package/inputs/Radio/index.js.map +3 -3
- package/inputs/Select/Select.stories.d.ts +2 -0
- package/inputs/Select/__stories__/Default.d.ts +1 -1
- package/inputs/Select/index.d.ts +4 -3
- package/inputs/Select/index.js +5 -3
- package/inputs/Select/index.js.map +2 -2
- package/{Field/utils → inputs/registry}/index.js +4 -2
- package/{locales/el → inputs/registry}/package.json +1 -1
- package/{Field/utils/index.d.ts → inputs/registry.d.ts} +2 -1
- package/inputs/registry.js.map +7 -0
- package/lazy/index.js +16 -10
- package/package.json +8 -8
- package/registry/index.js +31 -15
- package/src/Field/ErrorGroup.tsx +84 -0
- package/src/Field/FieldBase.tsx +40 -26
- package/src/Field/FieldBaseContainer.tsx +69 -47
- package/src/Field/FieldConditional.tsx +5 -1
- package/src/Field/doc.mdx +202 -1
- package/src/Field/index.tsx +27 -37
- package/src/Field/types.tsx +24 -14
- package/src/Field/utils/evaluateFieldWithConditions.ts +5 -2
- package/src/Field/utils/resolveField.ts +58 -0
- package/src/Field/utils/useField.ts +12 -2
- package/src/FieldArray/BaseFieldArray.tsx +97 -0
- package/src/FieldArray/FieldArray.stories.js +2 -0
- package/src/FieldArray/FormDialog/ArrayDisplay/ArrayContainerDisplay.tsx +45 -0
- package/src/FieldArray/FormDialog/ArrayDisplay/ArrayDisplay.stories.js +14 -0
- package/src/FieldArray/FormDialog/ArrayDisplay/ArrayItemDisplay.tsx +335 -0
- package/src/FieldArray/FormDialog/ArrayDisplay/ArrayItemHeader.tsx +15 -0
- package/src/FieldArray/FormDialog/ArrayDisplay/__stories__/Cards.tsx +88 -0
- package/src/FieldArray/FormDialog/ArrayDisplay/__stories__/Default.tsx +93 -0
- package/src/FieldArray/FormDialog/ArrayDisplay/__stories__/ReadOnly.tsx +79 -0
- package/src/FieldArray/FormDialog/ArrayDisplay/__stories__/ReadOnlyCards.tsx +75 -0
- package/src/FieldArray/FormDialog/ArrayDisplay/__stories__/Sortable.tsx +93 -0
- package/src/FieldArray/FormDialog/ArrayDisplay/__stories__/SortableCards.tsx +88 -0
- package/src/FieldArray/FormDialog/ArrayDisplay/index.test.tsx +44 -0
- package/src/FieldArray/FormDialog/ArrayDisplay/index.tsx +67 -0
- package/src/FieldArray/FormDialog/ArrayEditModal.tsx +243 -0
- package/src/FieldArray/FormDialog/index.tsx +304 -0
- package/src/FieldArray/__stories__/CardsWithError.tsx +124 -0
- package/src/FieldArray/__stories__/Default.tsx +1 -1
- package/src/FieldArray/__stories__/WithExactLength.tsx +15 -78
- package/src/FieldArray/__stories__/WithModal.tsx +160 -0
- package/src/FieldArray/__tests__/fieldset-multiplicity.spec.tsx +271 -0
- package/src/FieldArray/__tests__/multiplicity-attachment.spec.tsx +280 -0
- package/src/FieldArray/__tests__/multiplicity-optional.spec.tsx +232 -0
- package/src/FieldArray/__tests__/multiplicity-required.spec.tsx +170 -0
- package/src/FieldArray/__tests__/nested-fieldset-multiplicity.spec.tsx +627 -0
- package/src/FieldArray/__tests__/preference-multiple-choice.spec.tsx +222 -0
- package/src/FieldArray/index.spec.tsx +355 -0
- package/src/FieldArray/index.test.tsx +12 -0
- package/src/FieldArray/index.tsx +49 -72
- package/src/FieldObject/index.tsx +40 -34
- package/src/Fieldset/FieldsetWithContext.tsx +1 -1
- package/src/Fieldset/index.tsx +1 -1
- package/src/Fieldset/types.tsx +2 -2
- package/src/FormBuilder/FormBuilder.stories.js +5 -0
- package/src/FormBuilder/__stories__/AutoErrorGrouping.tsx +63 -0
- package/src/FormBuilder/__stories__/Default.tsx +1 -1
- package/src/FormBuilder/__stories__/ErrorGrouping.tsx +43 -0
- package/src/FormBuilder/doc.mdx +9 -4
- package/src/FormBuilder/index.test.tsx +12 -0
- package/src/FormBuilder/index.tsx +223 -89
- package/src/FormBuilder/interaction.test.tsx +40 -0
- package/src/FormBuilder/scenarios.test.tsx +1002 -129
- package/src/FormContext.tsx +7 -2
- package/src/MultiplicityField/MultiplicityField.stories.js +3 -0
- package/src/MultiplicityField/__stories__/Default.tsx +1 -1
- package/src/MultiplicityField/__stories__/PreviewDisplay.tsx +1 -1
- package/src/MultiplicityField/__stories__/WithExactLength.tsx +1 -1
- package/src/MultiplicityField/__stories__/WithMaxLength.tsx +1 -1
- package/src/MultiplicityField/__stories__/WithMinAndMaxLength.tsx +1 -1
- package/src/MultiplicityField/__stories__/WithMinLength.tsx +1 -1
- package/src/MultiplicityField/add-objects.tsx +14 -21
- package/src/MultiplicityField/doc.mdx +101 -83
- package/src/MultiplicityField/index.test.tsx +4 -0
- package/src/MultiplicityField/index.tsx +8 -3
- package/src/MultiplicityField/types.ts +6 -2
- package/src/Questions/Questions.stories.js +3 -0
- package/src/Questions/Questions.tsx +2 -2
- package/src/Questions/QuestionsContext.tsx +1 -1
- package/src/Questions/Step/Step.tsx +1 -1
- package/src/Questions/Step/StepArrayReview.tsx +2 -2
- package/src/Questions/Step/StepContext.tsx +1 -1
- package/src/Questions/Step/StepDescription.tsx +2 -1
- package/src/Questions/Step/StepForm.tsx +2 -2
- package/src/Questions/Step/StepQuote.tsx +2 -1
- package/src/Questions/Step/StepTitle.tsx +2 -1
- package/src/Questions/Step/getAddMoreFields.tsx +2 -2
- package/src/Questions/Step/types.tsx +1 -1
- package/src/Questions/__snapshots__/index.spec.tsx.snap +3 -1
- package/src/Questions/__stories__/Default.tsx +1 -1
- package/src/Questions/doc.mdx +21 -41
- package/src/Questions/getNextStep.tsx +1 -1
- package/src/Questions/index.spec.tsx +8 -0
- package/src/Questions/index.test.tsx +4 -0
- package/src/Questions/types.tsx +1 -1
- package/src/doc.mdx +26 -11
- package/src/hooks/__tests__/useFieldFocusManager.spec.tsx +1079 -0
- package/src/hooks/__tests__/utils.spec.ts +568 -0
- package/src/hooks/useFieldFocusManager.ts +162 -0
- package/src/hooks/utils.ts +122 -0
- package/src/inputs/AutoCompleteInput/AutoComplete.stories.js +3 -0
- package/src/inputs/AutoCompleteInput/__stories__/Default.tsx +1 -1
- package/src/inputs/AutoCompleteInput/__stories__/Multiple.tsx +1 -1
- package/src/inputs/AutoCompleteInput/index.test.tsx +4 -0
- package/src/inputs/AutoCompleteInput/index.tsx +4 -6
- package/src/inputs/Checkboxes/Checkboxes.stories.js +3 -0
- package/src/inputs/Checkboxes/__stories__/Conditional.tsx +1 -1
- package/src/inputs/Checkboxes/__stories__/Default.tsx +1 -1
- package/src/inputs/Checkboxes/__stories__/WithDivider.tsx +1 -1
- package/src/inputs/Checkboxes/index.test.tsx +4 -0
- package/src/inputs/Checkboxes/index.tsx +95 -90
- package/src/inputs/DateInput/DateInput.stories.js +7 -0
- package/src/inputs/DateInput/__stories__/Default.tsx +1 -1
- package/src/inputs/DateInput/__stories__/WithDefaultValue.tsx +26 -0
- package/src/inputs/DateInput/__stories__/WithInitialValue.tsx +28 -0
- package/src/inputs/DateInput/__stories__/WithWrongDefaultValue.tsx +26 -0
- package/src/inputs/DateInput/__stories__/WithWrongInitialValue.tsx +28 -0
- package/src/inputs/DateInput/index.test.tsx +20 -0
- package/src/inputs/DateInput/index.tsx +68 -20
- package/src/inputs/DateTimeInput/DateTimeInput.stories.js +12 -6
- package/src/inputs/DateTimeInput/__stories__/Default.tsx +1 -1
- package/src/inputs/DateTimeInput/__stories__/WithDefaultValue.tsx +26 -0
- package/src/inputs/DateTimeInput/__stories__/WithInitialValue.tsx +28 -0
- package/src/inputs/DateTimeInput/__stories__/WithWrongDefaultValue.tsx +26 -0
- package/src/inputs/DateTimeInput/__stories__/WithWrongInitialValue.tsx +28 -0
- package/src/inputs/DateTimeInput/index.test.tsx +27 -5
- package/src/inputs/DateTimeInput/index.tsx +97 -40
- package/src/inputs/FileInput/FileInput.stories.js +4 -0
- package/src/inputs/FileInput/__stories__/Default.tsx +1 -1
- package/src/inputs/FileInput/__stories__/WithBorderAndLink.tsx +34 -0
- package/src/inputs/FileInput/index.test.tsx +8 -0
- package/src/inputs/FileInput/index.tsx +106 -38
- package/src/inputs/ImageInput/ImageInput.stories.js +5 -1
- package/src/inputs/ImageInput/__stories__/Default.tsx +1 -1
- package/src/inputs/ImageInput/__stories__/MaxSize.tsx +3 -2
- package/src/inputs/ImageInput/__stories__/{WithInvalidImageSize.tsx → WithInitialValues.tsx} +12 -3
- package/src/inputs/ImageInput/__stories__/WithInvalidImageDimension.tsx +1 -1
- package/src/inputs/ImageInput/__stories__/logo.d.ts +4 -0
- package/src/inputs/ImageInput/__stories__/logo.png +0 -0
- package/src/inputs/ImageInput/index.test.tsx +8 -4
- package/src/inputs/ImageInput/index.tsx +101 -48
- package/src/inputs/Input/Input.stories.js +6 -0
- package/src/inputs/Input/__stories__/AFM.tsx +1 -1
- package/src/inputs/Input/__stories__/AMKA.tsx +23 -0
- package/src/inputs/Input/__stories__/Boolean.tsx +1 -1
- package/src/inputs/Input/__stories__/Email.tsx +23 -0
- package/src/inputs/Input/__stories__/IBAN.tsx +1 -1
- package/src/inputs/Input/__stories__/Integer.tsx +1 -1
- package/src/inputs/Input/__stories__/LandlineNumber.tsx +1 -1
- package/src/inputs/Input/__stories__/MobilePhone.tsx +1 -1
- package/src/inputs/Input/__stories__/PhoneNumber.tsx +1 -1
- package/src/inputs/Input/__stories__/PostalCode.tsx +1 -1
- package/src/inputs/Input/__stories__/String.tsx +1 -1
- package/src/inputs/Input/__stories__/StringWithTrimValidation.tsx +26 -0
- package/src/inputs/Input/__stories__/TextWithLimit.tsx +2 -1
- package/src/inputs/Input/index.test.tsx +16 -0
- package/src/inputs/Input/index.tsx +76 -71
- package/src/inputs/Label/Label.stories.js +3 -0
- package/src/inputs/Label/__stories__/Default.tsx +1 -1
- package/src/inputs/Label/index.test.tsx +4 -0
- package/src/inputs/Label/index.tsx +1 -1
- package/src/inputs/OtpInput/OtpInput.stories.js +3 -0
- package/src/inputs/OtpInput/__stories__/Default.tsx +1 -1
- package/src/inputs/OtpInput/index.test.tsx +4 -0
- package/src/inputs/OtpInput/index.tsx +43 -33
- package/src/inputs/Radio/Radio.stories.js +3 -0
- package/src/inputs/Radio/__stories__/Conditional.tsx +1 -1
- package/src/inputs/Radio/__stories__/Default.tsx +1 -1
- package/src/inputs/Radio/__stories__/WithDivider.tsx +1 -1
- package/src/inputs/Radio/index.test.tsx +4 -0
- package/src/inputs/Radio/index.tsx +29 -21
- package/src/inputs/Select/Select.stories.js +3 -0
- package/src/inputs/Select/__stories__/Default.tsx +1 -1
- package/src/inputs/Select/index.test.tsx +4 -0
- package/src/inputs/Select/index.tsx +10 -6
- package/src/{Field/utils/index.ts → inputs/registry.ts} +5 -1
- package/src/lazy.js +16 -10
- package/src/registry.js +31 -15
- package/src/types.tsx +14 -5
- package/src/utils.ts +30 -8
- package/src/validators/index.ts +68 -28
- package/src/validators/types.ts +1 -1
- package/src/validators/utils/amka.ts +39 -0
- package/src/validators/utils/date.ts +30 -6
- package/src/validators/utils/datetime.ts +123 -31
- package/src/validators/utils/email.ts +11 -0
- package/src/validators/utils/file.ts +35 -21
- package/src/validators/utils/iban.ts +2 -2
- package/src/validators/utils/image.ts +2 -2
- package/src/validators/utils/index.ts +6 -3
- package/src/validators/utils/int.ts +2 -2
- package/src/validators/utils/number.ts +2 -2
- package/src/validators/utils/otp.ts +2 -2
- package/src/validators/utils/phone.ts +2 -2
- package/src/validators/utils/postal_code.ts +2 -2
- package/src/validators/utils/text_limit.ts +2 -2
- package/types.d.ts +10 -4
- package/types.js.map +1 -1
- package/utils/index.js +20 -6
- package/utils.d.ts +3 -1
- package/utils.js.map +2 -2
- package/validators/index.d.ts +6 -6
- package/validators/index.js +34 -19
- package/validators/index.js.map +2 -2
- package/validators/types.d.ts +1 -1
- package/validators/utils/amka/index.js +36 -0
- package/validators/utils/amka/package.json +6 -0
- package/validators/utils/amka.d.ts +6 -0
- package/validators/utils/amka.js.map +7 -0
- package/validators/utils/date/index.js +26 -3
- package/validators/utils/date.d.ts +3 -3
- package/validators/utils/date.js.map +2 -2
- package/validators/utils/datetime/index.js +118 -24
- package/validators/utils/datetime.d.ts +3 -3
- package/validators/utils/datetime.js.map +2 -2
- package/validators/utils/email/index.js +16 -0
- package/validators/utils/email/package.json +6 -0
- package/validators/utils/email.d.ts +5 -0
- package/validators/utils/email.js.map +7 -0
- package/validators/utils/file/index.js +30 -17
- package/validators/utils/file.d.ts +2 -2
- package/validators/utils/file.js.map +2 -2
- package/validators/utils/iban.d.ts +2 -2
- package/validators/utils/iban.js.map +1 -1
- package/validators/utils/image.d.ts +2 -2
- package/validators/utils/image.js.map +1 -1
- package/validators/utils/index.d.ts +3 -2
- package/validators/utils/index.js +4 -1
- package/validators/utils/index.js.map +2 -2
- package/validators/utils/int/index.js +1 -1
- package/validators/utils/int.d.ts +1 -1
- package/validators/utils/int.js.map +2 -2
- package/validators/utils/number/index.js +1 -1
- package/validators/utils/number.d.ts +1 -1
- package/validators/utils/number.js.map +2 -2
- package/validators/utils/otp.d.ts +2 -2
- package/validators/utils/otp.js.map +1 -1
- package/validators/utils/phone.d.ts +2 -2
- package/validators/utils/phone.js.map +1 -1
- package/validators/utils/postal_code.d.ts +2 -2
- package/validators/utils/postal_code.js.map +1 -1
- package/validators/utils/text_limit.d.ts +2 -2
- package/validators/utils/text_limit.js.map +1 -1
- package/Field/utils/calculateField/index.js +0 -27
- package/Field/utils/calculateField.d.ts +0 -2
- package/Field/utils/calculateField.js.map +0 -7
- package/Field/utils/index.js.map +0 -7
- package/FieldArray/FormDialog.d.ts +0 -53
- package/FieldArray/FormDialog.js.map +0 -7
- package/FormBuilder/index.test.d.ts +0 -1
- package/FormBuilder/scenarios.test.d.ts +0 -88
- package/MultiplicityField/index.test.d.ts +0 -1
- package/Questions/index.spec.d.ts +0 -1
- package/Questions/index.test.d.ts +0 -1
- package/cjs/Field/utils/calculateField/index.js +0 -50
- package/cjs/Field/utils/calculateField.js.map +0 -7
- package/cjs/Field/utils/index.js.map +0 -7
- package/cjs/FieldArray/FormDialog.js.map +0 -7
- package/cjs/inputs/Input/inputsInputScenarios/index.js +0 -439
- package/cjs/inputs/Input/inputsInputScenarios.js.map +0 -7
- package/cjs/inputs/inputsScenarios/index.js +0 -533
- package/cjs/inputs/inputsScenarios.js.map +0 -7
- package/cjs/locales/el.js.map +0 -7
- package/inputs/AutoCompleteInput/index.test.d.ts +0 -1
- package/inputs/Checkboxes/index.test.d.ts +0 -1
- package/inputs/DateInput/index.test.d.ts +0 -1
- package/inputs/DateTimeInput/index.test.d.ts +0 -1
- package/inputs/FileInput/index.test.d.ts +0 -1
- package/inputs/ImageInput/__stories__/WithInvalidImageSize.d.ts +0 -3
- package/inputs/ImageInput/index.test.d.ts +0 -1
- package/inputs/Input/index.test.d.ts +0 -1
- package/inputs/Input/inputsInputScenarios/index.js +0 -406
- package/inputs/Input/inputsInputScenarios.d.ts +0 -57
- package/inputs/Input/inputsInputScenarios.js.map +0 -7
- package/inputs/Label/index.test.d.ts +0 -1
- package/inputs/OtpInput/index.test.d.ts +0 -1
- package/inputs/Radio/index.test.d.ts +0 -1
- package/inputs/Select/index.test.d.ts +0 -1
- package/inputs/inputsScenarios/index.js +0 -499
- package/inputs/inputsScenarios.d.ts +0 -296
- package/inputs/inputsScenarios.js.map +0 -7
- package/locales/el/index.js +0 -6
- package/locales/el.d.ts +0 -2
- package/locales/el.js.map +0 -7
- package/src/Field/utils/calculateField.ts +0 -49
- package/src/FieldArray/FormDialog.tsx +0 -379
- package/src/inputs/Input/inputsInputScenarios.ts +0 -404
- package/src/inputs/inputsScenarios.ts +0 -496
- package/src/locales/el.ts +0 -3
- /package/{FieldArray/index.test.d.ts → hooks/__tests__/utils.spec.d.ts} +0 -0
package/cjs/validators/index.js
CHANGED
|
@@ -34,19 +34,26 @@ module.exports = __toCommonJS(validators_exports);
|
|
|
34
34
|
var import_react = require("react");
|
|
35
35
|
var yup = __toESM(require("yup"));
|
|
36
36
|
var import_utils = require("@digigov/form/validators/utils");
|
|
37
|
+
var import_email = require("@digigov/form/validators/utils/email");
|
|
37
38
|
var import_int = require("@digigov/form/validators/utils/int");
|
|
38
39
|
var import_number = require("@digigov/form/validators/utils/number");
|
|
39
|
-
const getYUPTypeMap = () => {
|
|
40
|
+
const getYUPTypeMap = (validatorRegistry) => {
|
|
40
41
|
const yupTypeMap = {
|
|
41
42
|
file: (field) => {
|
|
42
43
|
return yup.mixed().transform((value) => {
|
|
43
|
-
if (!value.length) {
|
|
44
|
+
if (!value || value.length === 0) {
|
|
44
45
|
return null;
|
|
45
46
|
}
|
|
46
47
|
return value;
|
|
47
48
|
}).nullable().test((0, import_utils.FILE_MAX_SIZE_VALIDATOR)(field));
|
|
48
49
|
},
|
|
49
|
-
string: () =>
|
|
50
|
+
string: (field) => {
|
|
51
|
+
if (field.trim) {
|
|
52
|
+
return yup.string().trim();
|
|
53
|
+
} else {
|
|
54
|
+
return yup.string();
|
|
55
|
+
}
|
|
56
|
+
},
|
|
50
57
|
boolean: () => {
|
|
51
58
|
return yup.boolean().nullable().transform((value) => {
|
|
52
59
|
if (value === "" || typeof value === "string") return null;
|
|
@@ -60,7 +67,10 @@ const getYUPTypeMap = () => {
|
|
|
60
67
|
},
|
|
61
68
|
array: (field) => {
|
|
62
69
|
if (typeof field.extra.of === "object") {
|
|
63
|
-
|
|
70
|
+
if (field.required) {
|
|
71
|
+
field.extra.min = 1;
|
|
72
|
+
}
|
|
73
|
+
let arrayValidator = yup.array().nullable().of(yupTypeMap[field.extra.of.type](field.extra.of));
|
|
64
74
|
if (field.extra.length)
|
|
65
75
|
arrayValidator = arrayValidator.length(field.extra.length, {
|
|
66
76
|
key: "form.error.array.length",
|
|
@@ -72,13 +82,15 @@ const getYUPTypeMap = () => {
|
|
|
72
82
|
arrayValidator = arrayValidator.min(field.extra.min, {
|
|
73
83
|
key: "form.error.array.min",
|
|
74
84
|
context: {
|
|
75
|
-
min: field.extra.min
|
|
85
|
+
min: field.extra.min,
|
|
86
|
+
max: field.extra.max || void 0
|
|
76
87
|
}
|
|
77
88
|
});
|
|
78
89
|
if (field.extra.max)
|
|
79
90
|
arrayValidator = arrayValidator.max(field.extra.max, {
|
|
80
91
|
key: "form.error.array.max",
|
|
81
92
|
context: {
|
|
93
|
+
min: field.extra.min || void 0,
|
|
82
94
|
max: field.extra.max
|
|
83
95
|
}
|
|
84
96
|
});
|
|
@@ -89,18 +101,19 @@ const getYUPTypeMap = () => {
|
|
|
89
101
|
return yup.array().of(yup.string());
|
|
90
102
|
}
|
|
91
103
|
},
|
|
92
|
-
number: () => yup.mixed().transform((_, val) => val !== "" ? Number(val) :
|
|
93
|
-
int: () => yup.mixed().transform((_, val) => val !== "" ? Number(val) :
|
|
94
|
-
email: () => yup.string().
|
|
95
|
-
afm: () => yup.string().trim().test(import_utils.AFM_VALIDATOR),
|
|
96
|
-
|
|
97
|
-
|
|
104
|
+
number: () => yup.mixed().transform((_, val) => val !== "" ? Number(val) : void 0).test((0, import_number.NUMBER_VALIDATOR)()),
|
|
105
|
+
int: () => yup.mixed().transform((_, val) => val !== "" ? Number(val) : void 0).test((0, import_number.NUMBER_VALIDATOR)()).test((0, import_int.INT_VALIDATOR)()),
|
|
106
|
+
email: (field) => field.trim ? yup.string().trim().test(import_email.EMAIL_VALIDATOR) : yup.string().test(import_email.EMAIL_VALIDATOR),
|
|
107
|
+
afm: (field) => field.trim ? yup.string().trim().test(import_utils.AFM_VALIDATOR) : yup.string().test(import_utils.AFM_VALIDATOR),
|
|
108
|
+
amka: (field) => field.trim ? yup.string().trim().test(import_utils.AMKA_VALIDATOR) : yup.string().test(import_utils.AMKA_VALIDATOR),
|
|
109
|
+
uuid4: (field) => field.trim ? yup.string().trim().test(import_utils.UUID4_VALIDATOR) : yup.string().test(import_utils.UUID4_VALIDATOR),
|
|
110
|
+
iban: (field) => field.trim ? yup.string().trim().test((0, import_utils.IBAN_VALIDATOR)(field)) : yup.string().trim().test((0, import_utils.IBAN_VALIDATOR)(field)),
|
|
98
111
|
otp: (field) => yup.string().trim().test((0, import_utils.OTP_VALIDATOR)(field)),
|
|
99
112
|
text: (field) => {
|
|
100
113
|
if (field?.extra?.limit?.max || !!field?.extra?.limit?.min) {
|
|
101
|
-
return yup.string().test((0, import_utils.TEXT_LIMIT_VALIDATOR)(field));
|
|
114
|
+
return field.trim ? yup.string().trim().test((0, import_utils.TEXT_LIMIT_VALIDATOR)(field)) : yup.string().test((0, import_utils.TEXT_LIMIT_VALIDATOR)(field));
|
|
102
115
|
} else {
|
|
103
|
-
return yup.string();
|
|
116
|
+
return field.trim ? yup.string().trim() : yup.string();
|
|
104
117
|
}
|
|
105
118
|
},
|
|
106
119
|
image: (field) => {
|
|
@@ -111,9 +124,9 @@ const getYUPTypeMap = () => {
|
|
|
111
124
|
return value;
|
|
112
125
|
}).nullable().test((0, import_utils.FILE_MAX_SIZE_VALIDATOR)(field)).test((0, import_utils.IMAGE_DIMENSION_VALIDATOR)(field));
|
|
113
126
|
},
|
|
114
|
-
postal_code: (field) => yup.string().trim().test((0, import_utils.POSTALCODE_VALIDATOR)(field)),
|
|
115
|
-
mobile_phone: () => yup.string().trim().test(import_utils.MOBILE_PHONE_VALIDATOR),
|
|
116
|
-
phone_number: (field) => yup.string().trim().test((0, import_utils.PHONE_NUMBER_VALIDATOR)(field)),
|
|
127
|
+
postal_code: (field) => field.trim ? yup.string().trim().test((0, import_utils.POSTALCODE_VALIDATOR)(field)) : yup.string().test((0, import_utils.POSTALCODE_VALIDATOR)(field)),
|
|
128
|
+
mobile_phone: (field) => field.trim ? yup.string().trim().test(import_utils.MOBILE_PHONE_VALIDATOR) : yup.string().test(import_utils.MOBILE_PHONE_VALIDATOR),
|
|
129
|
+
phone_number: (field) => field.trim ? yup.string().trim().test((0, import_utils.PHONE_NUMBER_VALIDATOR)(field)) : yup.string().test((0, import_utils.PHONE_NUMBER_VALIDATOR)(field)),
|
|
117
130
|
"choice:multiple": () => yup.array().of(yup.string()).nullable(),
|
|
118
131
|
"choice:single": () => yup.string().nullable(),
|
|
119
132
|
date: (field) => {
|
|
@@ -136,15 +149,16 @@ const getYUPTypeMap = () => {
|
|
|
136
149
|
return yup.string().test((0, import_utils.EARLIER_THAN_DATETIME_VALIDATOR)(field));
|
|
137
150
|
}
|
|
138
151
|
return yup.string().test(import_utils.DATETIME_VALIDATOR);
|
|
139
|
-
}
|
|
152
|
+
},
|
|
153
|
+
...validatorRegistry
|
|
140
154
|
};
|
|
141
155
|
return yupTypeMap;
|
|
142
156
|
};
|
|
143
157
|
function useValidationSchema(fields, validatorRegistry) {
|
|
144
158
|
return (0, import_react.useMemo)(() => {
|
|
145
|
-
const yupTypeMap = getYUPTypeMap();
|
|
159
|
+
const yupTypeMap = getYUPTypeMap(validatorRegistry);
|
|
146
160
|
return (0, import_utils.getYupObjectShape)(fields, yupTypeMap, validatorRegistry);
|
|
147
|
-
}, []);
|
|
161
|
+
}, [fields, validatorRegistry]);
|
|
148
162
|
}
|
|
149
163
|
// Annotate the CommonJS export names for ESM import in node:
|
|
150
164
|
0 && (module.exports = {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/validators/index.ts"],
|
|
4
|
-
"sourcesContent": ["import { MutableRefObject
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["import type { MutableRefObject } from 'react';\nimport { useMemo } from 'react';\nimport * as yup from 'yup';\nimport type { AnyObjectSchema, StringSchema } from 'yup';\nimport type { RequiredArraySchema } from 'yup/lib/array';\nimport type Lazy from 'yup/lib/Lazy';\nimport type { MixedSchema } from 'yup/lib/mixed';\nimport type { TypeOfShape, AssertsShape } from 'yup/lib/object';\nimport type { AnyObject } from 'yup/lib/types';\nimport type { FieldSpec } from '@digigov/form/types';\nimport type { ValidatorSchema } from '@digigov/form/validators/types';\nimport {\n getYupObjectShape,\n AFM_VALIDATOR,\n AMKA_VALIDATOR,\n FILE_MAX_SIZE_VALIDATOR,\n IBAN_VALIDATOR,\n OTP_VALIDATOR,\n MOBILE_PHONE_VALIDATOR,\n PHONE_NUMBER_VALIDATOR,\n TEXT_LIMIT_VALIDATOR,\n POSTALCODE_VALIDATOR,\n UUID4_VALIDATOR,\n IMAGE_DIMENSION_VALIDATOR,\n DATE_VALIDATOR,\n LATER_THAN_VALIDATOR,\n EARLIER_THAN_VALIDATOR,\n DATETIME_VALIDATOR,\n LATER_THAN_DATETIME_VALIDATOR,\n EARLIER_THAN_DATETIME_VALIDATOR,\n} from '@digigov/form/validators/utils';\nimport { EMAIL_VALIDATOR } from '@digigov/form/validators/utils/email';\nimport { INT_VALIDATOR } from '@digigov/form/validators/utils/int';\nimport { NUMBER_VALIDATOR } from '@digigov/form/validators/utils/number';\n\nexport const getYUPTypeMap = (\n validatorRegistry?: Record<string, any>\n): Record<string, any> => {\n const yupTypeMap = {\n file: (field): MixedSchema => {\n return yup\n .mixed()\n .transform((value) => {\n if (!value || value.length === 0) {\n return null;\n }\n return value;\n })\n .nullable()\n .test(FILE_MAX_SIZE_VALIDATOR(field));\n },\n string: (field): yup.StringSchema => {\n if (field.trim) {\n return yup.string().trim();\n } else {\n return yup.string();\n }\n },\n boolean: (): yup.BooleanSchema<\n boolean | null | undefined,\n AnyObject,\n boolean | null | undefined\n > => {\n return yup\n .boolean()\n .nullable()\n .transform((value) => {\n if (value === '' || typeof value === 'string') return null;\n if (typeof value === 'boolean') return value;\n if (value === 0 || value === 1) return Boolean(value);\n return value;\n });\n },\n object: (\n field\n ):\n | yup.ObjectSchema<any, AnyObject, TypeOfShape<any>, AssertsShape<any>>\n | Lazy<any, unknown> => {\n return getYupObjectShape(field.extra.fields, yupTypeMap);\n },\n array: (\n field\n ):\n | yup.ArraySchema<any, AnyObject, any[] | undefined>\n | RequiredArraySchema<any, AnyObject, any[] | undefined> => {\n if (typeof field.extra.of === 'object') {\n // else if the field is an object then it is a scalar type\n // eg. number, string etc.\n if (field.required) {\n field.extra.min = 1;\n }\n let arrayValidator = yup\n .array()\n .nullable()\n .of(yupTypeMap[field.extra.of.type](field.extra.of));\n if (field.extra.length)\n arrayValidator = arrayValidator.length(field.extra.length, {\n key: 'form.error.array.length',\n context: {\n length: field.extra.length,\n },\n });\n if (field.extra.min)\n arrayValidator = arrayValidator.min(field.extra.min, {\n key: 'form.error.array.min',\n context: {\n min: field.extra.min,\n max: field.extra.max || undefined,\n },\n });\n if (field.extra.max)\n arrayValidator = arrayValidator.max(field.extra.max, {\n key: 'form.error.array.max',\n context: {\n min: field.extra.min || undefined,\n max: field.extra.max,\n },\n });\n return arrayValidator;\n } else if (typeof field.extra.of === 'string') {\n return yup.array().of(yupTypeMap[field.extra.of]());\n } else {\n // in any other case it will be string\n return yup.array().of(yup.string());\n }\n },\n number: (): MixedSchema =>\n yup\n .mixed()\n .transform((_, val) => (val !== '' ? Number(val) : undefined))\n .test(NUMBER_VALIDATOR()),\n int: (): MixedSchema =>\n yup\n .mixed()\n .transform((_, val) => (val !== '' ? Number(val) : undefined))\n .test(NUMBER_VALIDATOR())\n .test(INT_VALIDATOR()),\n email: (field): yup.StringSchema =>\n field.trim\n ? yup.string().trim().test(EMAIL_VALIDATOR)\n : yup.string().test(EMAIL_VALIDATOR),\n afm: (field): yup.StringSchema =>\n field.trim\n ? yup.string().trim().test(AFM_VALIDATOR)\n : yup.string().test(AFM_VALIDATOR),\n amka: (field): yup.StringSchema =>\n field.trim\n ? yup.string().trim().test(AMKA_VALIDATOR)\n : yup.string().test(AMKA_VALIDATOR),\n uuid4: (field): yup.StringSchema =>\n field.trim\n ? yup.string().trim().test(UUID4_VALIDATOR)\n : yup.string().test(UUID4_VALIDATOR),\n iban: (field): yup.StringSchema =>\n field.trim\n ? yup.string().trim().test(IBAN_VALIDATOR(field))\n : yup.string().trim().test(IBAN_VALIDATOR(field)),\n otp: (field): yup.StringSchema =>\n yup.string().trim().test(OTP_VALIDATOR(field)),\n text: (field): yup.StringSchema => {\n if (field?.extra?.limit?.max || !!field?.extra?.limit?.min) {\n return field.trim\n ? yup.string().trim().test(TEXT_LIMIT_VALIDATOR(field))\n : yup.string().test(TEXT_LIMIT_VALIDATOR(field));\n } else {\n return field.trim ? yup.string().trim() : yup.string();\n }\n },\n image: (field): MixedSchema => {\n return yup\n .mixed()\n .transform((value) => {\n if (!value.length || value.length === 0) {\n return null;\n }\n return value;\n })\n .nullable()\n .test(FILE_MAX_SIZE_VALIDATOR(field))\n .test(IMAGE_DIMENSION_VALIDATOR(field));\n },\n postal_code: (field): yup.StringSchema =>\n field.trim\n ? yup.string().trim().test(POSTALCODE_VALIDATOR(field))\n : yup.string().test(POSTALCODE_VALIDATOR(field)),\n mobile_phone: (field): yup.StringSchema =>\n field.trim\n ? yup.string().trim().test(MOBILE_PHONE_VALIDATOR)\n : yup.string().test(MOBILE_PHONE_VALIDATOR),\n phone_number: (field): yup.StringSchema =>\n field.trim\n ? yup.string().trim().test(PHONE_NUMBER_VALIDATOR(field))\n : yup.string().test(PHONE_NUMBER_VALIDATOR(field)),\n 'choice:multiple': (): yup.ArraySchema<\n yup.StringSchema<string | undefined, AnyObject, string | undefined>,\n AnyObject,\n (string | undefined)[] | null | undefined,\n (string | undefined)[] | null | undefined\n > => yup.array().of(yup.string()).nullable(),\n 'choice:single': (): StringSchema<\n string | null | undefined,\n AnyObject,\n string | null | undefined\n > => yup.string().nullable(),\n date: (\n field\n ): yup.StringSchema<\n string | null | undefined,\n AnyObject,\n string | null | undefined\n > => {\n let schema = yup.string().nullable();\n if (field?.extra?.min) {\n schema = schema.test(LATER_THAN_VALIDATOR(field));\n }\n if (field?.extra?.max) {\n schema = schema.test(EARLIER_THAN_VALIDATOR(field));\n } else {\n schema = schema.test(DATE_VALIDATOR);\n }\n return schema;\n },\n datetime: (field): yup.StringSchema => {\n if (field?.extra?.min) {\n return yup.string().test(LATER_THAN_DATETIME_VALIDATOR(field));\n }\n if (field?.extra?.max) {\n return yup.string().test(EARLIER_THAN_DATETIME_VALIDATOR(field));\n }\n return yup.string().test(DATETIME_VALIDATOR);\n },\n ...validatorRegistry,\n };\n return yupTypeMap;\n};\n\nexport interface MutableRefObjectProps {}\n// Create a yup validation schema from given fields input\nexport function useValidationSchema(\n fields: FieldSpec[] | MutableRefObject<MutableRefObjectProps>,\n validatorRegistry?: Record<string, ValidatorSchema[]>\n): Lazy<any, unknown> | AnyObjectSchema | void {\n return useMemo(() => {\n const yupTypeMap = getYUPTypeMap(validatorRegistry);\n return getYupObjectShape(fields, yupTypeMap, validatorRegistry);\n }, [fields, validatorRegistry]);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAwB;AACxB,UAAqB;AASrB,mBAmBO;AACP,mBAAgC;AAChC,iBAA8B;AAC9B,oBAAiC;AAE1B,MAAM,gBAAgB,CAC3B,sBACwB;AACxB,QAAM,aAAa;AAAA,IACjB,MAAM,CAAC,UAAuB;AAC5B,aAAO,IACJ,MAAM,EACN,UAAU,CAAC,UAAU;AACpB,YAAI,CAAC,SAAS,MAAM,WAAW,GAAG;AAChC,iBAAO;AAAA,QACT;AACA,eAAO;AAAA,MACT,CAAC,EACA,SAAS,EACT,SAAK,sCAAwB,KAAK,CAAC;AAAA,IACxC;AAAA,IACA,QAAQ,CAAC,UAA4B;AACnC,UAAI,MAAM,MAAM;AACd,eAAO,IAAI,OAAO,EAAE,KAAK;AAAA,MAC3B,OAAO;AACL,eAAO,IAAI,OAAO;AAAA,MACpB;AAAA,IACF;AAAA,IACA,SAAS,MAIJ;AACH,aAAO,IACJ,QAAQ,EACR,SAAS,EACT,UAAU,CAAC,UAAU;AACpB,YAAI,UAAU,MAAM,OAAO,UAAU,SAAU,QAAO;AACtD,Y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,MACrC;AACA,aAAO;AAAA,IACT;AAAA,IACA,UAAU,CAAC,UAA4B;AACrC,UAAI,OAAO,OAAO,KAAK;AACrB,eAAO,IAAI,OAAO,EAAE,SAAK,4CAA8B,KAAK,CAAC;AAAA,MAC/D;AACA,UAAI,OAAO,OAAO,KAAK;AACrB,eAAO,IAAI,OAAO,EAAE,SAAK,8CAAgC,KAAK,CAAC;AAAA,MACjE;AACA,aAAO,IAAI,OAAO,EAAE,KAAK,+BAAkB;AAAA,IAC7C;AAAA,IACA,GAAG;AAAA,EACL;AACA,SAAO;AACT;AAIO,SAAS,oBACd,QACA,mBAC6C;AAC7C,aAAO,sBAAQ,MAAM;AACnB,UAAM,aAAa,cAAc,iBAAiB;AAClD,eAAO,gCAAkB,QAAQ,YAAY,iBAAiB;AAAA,EAChE,GAAG,CAAC,QAAQ,iBAAiB,CAAC;AAChC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/validators/types.ts"],
|
|
4
|
-
"sourcesContent": ["import * as yup from 'yup';\nexport type ValidatorSchema = yup.TestConfig;\n"],
|
|
4
|
+
"sourcesContent": ["import type * as yup from 'yup';\nexport type ValidatorSchema = yup.TestConfig;\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;AAAA;AAAA;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var amka_exports = {};
|
|
19
|
+
__export(amka_exports, {
|
|
20
|
+
AMKA_VALIDATOR: () => AMKA_VALIDATOR,
|
|
21
|
+
validateAMKA: () => validateAMKA
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(amka_exports);
|
|
24
|
+
function digitSum(number) {
|
|
25
|
+
const sum = number > 9 ? 1 : 0;
|
|
26
|
+
return sum + number % 10;
|
|
27
|
+
}
|
|
28
|
+
function validateAMKA(amka) {
|
|
29
|
+
amka = String(amka);
|
|
30
|
+
const checkDigitIndex = amka.length - 1;
|
|
31
|
+
let sum = 0;
|
|
32
|
+
amka.substring(0, checkDigitIndex).split("").reverse().forEach(function(value, index) {
|
|
33
|
+
const weight = (index + 1) % 2 + 1;
|
|
34
|
+
sum += digitSum(parseInt(value, 10) * weight);
|
|
35
|
+
});
|
|
36
|
+
const sumMod10 = sum % 10;
|
|
37
|
+
if (sumMod10 === 0) {
|
|
38
|
+
return amka.substring(checkDigitIndex) === "0";
|
|
39
|
+
} else {
|
|
40
|
+
return amka.substring(checkDigitIndex) === 10 - sumMod10 + "";
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const AMKA_VALIDATOR = {
|
|
44
|
+
name: "amka-validator",
|
|
45
|
+
message: "form.error.amka",
|
|
46
|
+
test: (value) => {
|
|
47
|
+
if (!value) return true;
|
|
48
|
+
const AMKA_REGEX = /^[0-9]{11}$/;
|
|
49
|
+
if (!AMKA_REGEX.test(value) || value === "00000000000") {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
return validateAMKA(value);
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
56
|
+
0 && (module.exports = {
|
|
57
|
+
AMKA_VALIDATOR,
|
|
58
|
+
validateAMKA
|
|
59
|
+
});
|
|
60
|
+
//# sourceMappingURL=amka.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/validators/utils/amka.ts"],
|
|
4
|
+
"sourcesContent": ["function digitSum(number) {\n const sum = number > 9 ? 1 : 0;\n return sum + (number % 10);\n}\n\nexport function validateAMKA(amka: string): boolean {\n // Validate that the last digit is the correct check digit (created using the\n // Luhn algorithm https://en.wikipedia.org/wiki/Luhn_algorithm).\n amka = String(amka);\n const checkDigitIndex = amka.length - 1;\n let sum = 0;\n amka\n .substring(0, checkDigitIndex)\n .split('')\n .reverse()\n .forEach(function (value, index) {\n const weight = ((index + 1) % 2) + 1;\n sum += digitSum(parseInt(value, 10) * weight);\n });\n const sumMod10 = sum % 10;\n if (sumMod10 === 0) {\n return amka.substring(checkDigitIndex) === '0';\n } else {\n return amka.substring(checkDigitIndex) === 10 - sumMod10 + '';\n }\n}\n\nexport const AMKA_VALIDATOR = {\n name: 'amka-validator',\n message: 'form.error.amka',\n test: (value): boolean => {\n if (!value) return true;\n const AMKA_REGEX = /^[0-9]{11}$/;\n if (!AMKA_REGEX.test(value) || value === '00000000000') {\n return false;\n }\n return validateAMKA(value);\n },\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,SAAS,SAAS,QAAQ;AACxB,QAAM,MAAM,SAAS,IAAI,IAAI;AAC7B,SAAO,MAAO,SAAS;AACzB;AAEO,SAAS,aAAa,MAAuB;AAGlD,SAAO,OAAO,IAAI;AAClB,QAAM,kBAAkB,KAAK,SAAS;AACtC,MAAI,MAAM;AACV,OACG,UAAU,GAAG,eAAe,EAC5B,MAAM,EAAE,EACR,QAAQ,EACR,QAAQ,SAAU,OAAO,OAAO;AAC/B,UAAM,UAAW,QAAQ,KAAK,IAAK;AACnC,WAAO,SAAS,SAAS,OAAO,EAAE,IAAI,MAAM;AAAA,EAC9C,CAAC;AACH,QAAM,WAAW,MAAM;AACvB,MAAI,aAAa,GAAG;AAClB,WAAO,KAAK,UAAU,eAAe,MAAM;AAAA,EAC7C,OAAO;AACL,WAAO,KAAK,UAAU,eAAe,MAAM,KAAK,WAAW;AAAA,EAC7D;AACF;AAEO,MAAM,iBAAiB;AAAA,EAC5B,MAAM;AAAA,EACN,SAAS;AAAA,EACT,MAAM,CAAC,UAAmB;AACxB,QAAI,CAAC,MAAO,QAAO;AACnB,UAAM,aAAa;AACnB,QAAI,CAAC,WAAW,KAAK,KAAK,KAAK,UAAU,eAAe;AACtD,aAAO;AAAA,IACT;AACA,WAAO,aAAa,KAAK;AAAA,EAC3B;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -37,11 +37,14 @@ var import_customParseFormat = __toESM(require("dayjs/plugin/customParseFormat")
|
|
|
37
37
|
import_dayjs.default.extend(import_customParseFormat.default);
|
|
38
38
|
const VALID_DATE_FORMATS = ["DD/MM/YYYY"];
|
|
39
39
|
const DATE_CACHE = {};
|
|
40
|
+
const onlyNumbersRegex = /^\d+$/;
|
|
40
41
|
const getDate = (v) => {
|
|
41
42
|
return DATE_CACHE[v] ? DATE_CACHE[v] : (0, import_dayjs.default)(v, VALID_DATE_FORMATS, true);
|
|
42
43
|
};
|
|
44
|
+
const getDaysInMonth = (month, year) => {
|
|
45
|
+
return (0, import_dayjs.default)(`${year}-${month}-01`).daysInMonth();
|
|
46
|
+
};
|
|
43
47
|
const checkPartialDate = (value) => {
|
|
44
|
-
console.log("value.split('/')", value.split("/"));
|
|
45
48
|
const [day, month, year] = value.split("/");
|
|
46
49
|
if (day && !month && !year) {
|
|
47
50
|
return "form.error.date.invalid_month_year";
|
|
@@ -60,9 +63,29 @@ const checkPartialDate = (value) => {
|
|
|
60
63
|
}
|
|
61
64
|
if (!day && month && year) {
|
|
62
65
|
return "form.error.date.invalid_day";
|
|
63
|
-
} else {
|
|
64
|
-
return "form.error.date.invalid";
|
|
65
66
|
}
|
|
67
|
+
if (day && month) {
|
|
68
|
+
const dayNum = parseInt(day);
|
|
69
|
+
const monthNum = parseInt(month);
|
|
70
|
+
const validYear = onlyNumbersRegex.test(year) ? year : void 0;
|
|
71
|
+
if (!validYear || year.length < 4) {
|
|
72
|
+
return "form.error.date.invalid";
|
|
73
|
+
}
|
|
74
|
+
const yearNum = parseInt(validYear);
|
|
75
|
+
const maxDay = getDaysInMonth(monthNum, yearNum);
|
|
76
|
+
if (dayNum < 1 || dayNum > maxDay) {
|
|
77
|
+
return {
|
|
78
|
+
key: "form.error.date.invalid_day_range",
|
|
79
|
+
context: {
|
|
80
|
+
maxDay
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
if (monthNum < 1 || monthNum > 12) {
|
|
85
|
+
return "form.error.datetime.invalid_month_range";
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return "form.error.date.invalid";
|
|
66
89
|
};
|
|
67
90
|
const LATER_THAN_VALIDATOR = (field) => {
|
|
68
91
|
let minDate;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/validators/utils/date.ts"],
|
|
4
|
-
"sourcesContent": ["import dayjs from 'dayjs';\nimport customParseFormat from 'dayjs/plugin/customParseFormat';\nimport { FieldSpec } from '@digigov/form/types';\nimport { ValidatorSchema } from '@digigov/form/validators/types';\n\ndayjs.extend(customParseFormat);\n\nconst VALID_DATE_FORMATS = ['DD/MM/YYYY'];\nconst DATE_CACHE = {};\n\nconst getDate = (v: string) => {\n return DATE_CACHE[v] ? DATE_CACHE[v] : dayjs(v, VALID_DATE_FORMATS, true);\n};\n\n// Function to check partial date completion\nconst checkPartialDate = (value: string) => {\n
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkB;AAClB,+BAA8B;AAI9B,aAAAA,QAAM,OAAO,yBAAAC,OAAiB;AAE9B,MAAM,qBAAqB,CAAC,YAAY;AACxC,MAAM,aAAa,CAAC;
|
|
4
|
+
"sourcesContent": ["import dayjs from 'dayjs';\nimport customParseFormat from 'dayjs/plugin/customParseFormat';\nimport type { FieldSpec } from '@digigov/form/types';\nimport type { ValidatorSchema } from '@digigov/form/validators/types';\n\ndayjs.extend(customParseFormat);\n\nconst VALID_DATE_FORMATS = ['DD/MM/YYYY'];\nconst DATE_CACHE = {};\nconst onlyNumbersRegex = /^\\d+$/;\n\nconst getDate = (v: string) => {\n return DATE_CACHE[v] ? DATE_CACHE[v] : dayjs(v, VALID_DATE_FORMATS, true);\n};\n\nconst getDaysInMonth = (month: number, year: number): number => {\n return dayjs(`${year}-${month}-01`).daysInMonth(); // e.g. 29 for Feb 2024\n};\n\n// Function to check partial date completion\nconst checkPartialDate = (value: string) => {\n const [day, month, year] = value.split('/');\n if (day && !month && !year) {\n return 'form.error.date.invalid_month_year';\n }\n if (!day && month && !year) {\n return 'form.error.date.invalid_day_year';\n }\n if (!day && !month && year) {\n return 'form.error.date.invalid_day_month';\n }\n if (day && month && !year) {\n return 'form.error.date.invalid_year';\n }\n if (day && !month && year) {\n return 'form.error.date.invalid_month';\n }\n if (!day && month && year) {\n return 'form.error.date.invalid_day';\n }\n if (day && month) {\n const dayNum = parseInt(day);\n const monthNum = parseInt(month);\n const validYear = onlyNumbersRegex.test(year) ? year : undefined;\n if (!validYear || year.length < 4) {\n return 'form.error.date.invalid';\n }\n const yearNum = parseInt(validYear);\n const maxDay = getDaysInMonth(monthNum, yearNum);\n if (dayNum < 1 || dayNum > maxDay) {\n return {\n key: 'form.error.date.invalid_day_range',\n context: {\n maxDay: maxDay,\n },\n };\n }\n if (monthNum < 1 || monthNum > 12) {\n return 'form.error.datetime.invalid_month_range';\n }\n }\n return 'form.error.date.invalid';\n};\n\nexport const LATER_THAN_VALIDATOR = (field: FieldSpec): ValidatorSchema => {\n let minDate;\n const params = field.extra || {};\n if (params.min === 'now') {\n const today = new Date();\n minDate = new Date(today);\n } else {\n minDate = getDate(params.min).toDate();\n }\n const minPreviousDate = new Date(minDate);\n minPreviousDate.setDate(minDate.getDate() - 1);\n return {\n name: 'later-than',\n message: {\n key: 'form.error.date.later_than',\n context: {\n minDate: minPreviousDate.toLocaleDateString(),\n },\n },\n test: function (value: string) {\n if (!value) return true;\n const date = getDate(value);\n const isValid = +date.toDate() > +minDate;\n return isValid;\n },\n };\n};\n\nexport const EARLIER_THAN_VALIDATOR = (field: FieldSpec): ValidatorSchema => {\n let maxDate;\n const params = field.extra || {};\n if (params.max === 'now') {\n const today = new Date();\n maxDate = new Date(today);\n } else {\n maxDate = getDate(params.max).toDate();\n }\n const maxNextDate = new Date(maxDate);\n maxNextDate.setDate(maxDate.getDate() + 1);\n return {\n name: 'earlier-than',\n message: {\n key: 'form.error.date.earlier_than',\n context: {\n maxDate: maxNextDate.toLocaleDateString(),\n },\n },\n test: function (value: string) {\n if (!value) return true;\n const date = getDate(value);\n const isValid = +date.toDate() < +maxDate;\n return isValid;\n },\n };\n};\n\nexport const DATE_VALIDATOR = {\n name: 'date-validator',\n message: (v): string | object => {\n return checkPartialDate(v.value);\n },\n test: function (value: string) {\n if (!value) return true;\n const date = getDate(value);\n return date.isValid();\n },\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkB;AAClB,+BAA8B;AAI9B,aAAAA,QAAM,OAAO,yBAAAC,OAAiB;AAE9B,MAAM,qBAAqB,CAAC,YAAY;AACxC,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O,IAAI,CAAC;AAClC,aAAO;AAAA,IACT;AAAA,EACF;AACF;AAEO,MAAM,iBAAiB;AAAA,EAC5B,MAAM;AAAA,EACN,SAAS,CAAC,MAAuB;AAC/B,WAAO,iBAAiB,EAAE,KAAK;AAAA,EACjC;AAAA,EACA,MAAM,SAAU,OAAe;AAC7B,QAAI,CAAC,MAAO,QAAO;AACnB,UAAM,OAAO,QAAQ,KAAK;AAC1B,WAAO,KAAK,QAAQ;AAAA,EACtB;AACF;",
|
|
6
6
|
"names": ["dayjs", "customParseFormat"]
|
|
7
7
|
}
|
|
@@ -37,50 +37,144 @@ var import_customParseFormat = __toESM(require("dayjs/plugin/customParseFormat")
|
|
|
37
37
|
import_dayjs.default.extend(import_customParseFormat.default);
|
|
38
38
|
const VALID_DATETIME_FORMATS = ["DD/MM/YYYY HH:mm"];
|
|
39
39
|
const DATETIME_CACHE = {};
|
|
40
|
+
const onlyNumbersRegex = /^\d+$/;
|
|
40
41
|
const getDateTime = (v) => {
|
|
41
42
|
return DATETIME_CACHE[v] ? DATETIME_CACHE[v] : (0, import_dayjs.default)(v, VALID_DATETIME_FORMATS, true);
|
|
42
43
|
};
|
|
44
|
+
const getDaysInMonth = (month, year) => {
|
|
45
|
+
return (0, import_dayjs.default)(`${year}-${month}-01`).daysInMonth();
|
|
46
|
+
};
|
|
43
47
|
const checkPartialDateTime = (value) => {
|
|
44
48
|
const [datePart, timePart] = value.split(" ");
|
|
45
|
-
const [day, month, year] = datePart
|
|
46
|
-
const [hours, minutes] = timePart
|
|
47
|
-
|
|
49
|
+
const [day, month, year] = datePart?.split("/") ?? [];
|
|
50
|
+
const [hours, minutes] = timePart?.split(":") ?? [];
|
|
51
|
+
const hasDay = Boolean(day);
|
|
52
|
+
const hasMonth = Boolean(month);
|
|
53
|
+
const hasYear = Boolean(year);
|
|
54
|
+
const hasHours = Boolean(hours);
|
|
55
|
+
const hasMinutes = Boolean(minutes);
|
|
56
|
+
if (hasDay && !hasMonth && !hasYear && !hasHours && !hasMinutes) {
|
|
57
|
+
return "form.error.datetime.invalid_month_year_hours_minutes";
|
|
58
|
+
}
|
|
59
|
+
if (!hasDay && hasMonth && !hasYear && !hasHours && !hasMinutes) {
|
|
60
|
+
return "form.error.datetime.invalid_day_year_hours_minutes";
|
|
61
|
+
}
|
|
62
|
+
if (!hasDay && !hasMonth && hasYear && !hasHours && !hasMinutes) {
|
|
63
|
+
return "form.error.datetime.invalid_day_month_hours_minutes";
|
|
64
|
+
}
|
|
65
|
+
if (hasDay && hasMonth && !hasYear && !hasHours && !hasMinutes) {
|
|
66
|
+
return "form.error.datetime.invalid_year_hours_minutes";
|
|
67
|
+
}
|
|
68
|
+
if (hasDay && !hasMonth && hasYear && !hasHours && !hasMinutes) {
|
|
69
|
+
return "form.error.datetime.invalid_month_hours_minutes";
|
|
70
|
+
}
|
|
71
|
+
if (!hasDay && hasMonth && hasYear && !hasHours && !hasMinutes) {
|
|
72
|
+
return "form.error.datetime.invalid_day_hours_minutes";
|
|
73
|
+
}
|
|
74
|
+
if (hasDay && hasMonth && hasYear && !hasHours && !hasMinutes) {
|
|
75
|
+
return "form.error.datetime.invalid__hours_minutes";
|
|
76
|
+
}
|
|
77
|
+
if (hasDay && hasMonth && hasYear && hasHours && !hasMinutes) {
|
|
78
|
+
return "form.error.datetime.invalid_minutes";
|
|
79
|
+
}
|
|
80
|
+
if (hasDay && hasMonth && hasYear && !hasHours && hasMinutes) {
|
|
81
|
+
return "form.error.datetime.invalid_hours";
|
|
82
|
+
}
|
|
83
|
+
if (hasDay && !hasMonth && !hasYear && hasHours && !hasMinutes) {
|
|
84
|
+
return "form.error.datetime.invalid_month_year_minutes";
|
|
85
|
+
}
|
|
86
|
+
if (hasDay && !hasMonth && !hasYear && !hasHours && hasMinutes) {
|
|
87
|
+
return "form.error.datetime.invalid_month_year_hours";
|
|
88
|
+
}
|
|
89
|
+
if (hasDay && !hasMonth && !hasYear && hasHours && hasMinutes) {
|
|
48
90
|
return "form.error.datetime.invalid_month_year";
|
|
49
91
|
}
|
|
50
|
-
if (!
|
|
92
|
+
if (!hasDay && hasMonth && !hasYear && hasHours && !hasMinutes) {
|
|
93
|
+
return "form.error.datetime.invalid_day_year_minutes";
|
|
94
|
+
}
|
|
95
|
+
if (!hasDay && hasMonth && !hasYear && !hasHours && hasMinutes) {
|
|
96
|
+
return "form.error.datetime.invalid_day_year_hours";
|
|
97
|
+
}
|
|
98
|
+
if (!hasDay && hasMonth && !hasYear && hasHours && hasMinutes) {
|
|
51
99
|
return "form.error.datetime.invalid_day_year";
|
|
52
100
|
}
|
|
53
|
-
if (!
|
|
101
|
+
if (!hasDay && !hasMonth && hasYear && hasHours && !hasMinutes) {
|
|
102
|
+
return "form.error.datetime.invalid_day_month_minutes";
|
|
103
|
+
}
|
|
104
|
+
if (!hasDay && !hasMonth && hasYear && !hasHours && hasMinutes) {
|
|
105
|
+
return "form.error.datetime.invalid_day_month_hours";
|
|
106
|
+
}
|
|
107
|
+
if (!hasDay && !hasMonth && hasYear && hasHours && hasMinutes) {
|
|
54
108
|
return "form.error.datetime.invalid_day_month";
|
|
55
109
|
}
|
|
56
|
-
if (
|
|
110
|
+
if (!hasDay && !hasMonth && !hasYear && hasHours && hasMinutes) {
|
|
111
|
+
return "form.error.datetime.invalid_day_month_year";
|
|
112
|
+
}
|
|
113
|
+
if (!hasDay && !hasMonth && !hasYear && !hasHours && hasMinutes) {
|
|
114
|
+
return "form.error.datetime.invalid_day_month_year_hours";
|
|
115
|
+
}
|
|
116
|
+
if (hasDay && hasMonth && !hasYear && hasHours && !hasMinutes) {
|
|
117
|
+
return "form.error.datetime.invalid_year_minutes";
|
|
118
|
+
}
|
|
119
|
+
if (hasDay && hasMonth && !hasYear && !hasHours && hasMinutes) {
|
|
120
|
+
return "form.error.datetime.invalid_year_hours";
|
|
121
|
+
}
|
|
122
|
+
if (hasDay && hasMonth && !hasYear && hasHours && hasMinutes) {
|
|
57
123
|
return "form.error.datetime.invalid_year";
|
|
58
124
|
}
|
|
59
|
-
if (
|
|
125
|
+
if (hasDay && !hasMonth && hasYear && hasHours && !hasMinutes) {
|
|
126
|
+
return "form.error.datetime.invalid_month_minutes";
|
|
127
|
+
}
|
|
128
|
+
if (hasDay && !hasMonth && hasYear && !hasHours && hasMinutes) {
|
|
129
|
+
return "form.error.datetime.invalid_month_hours";
|
|
130
|
+
}
|
|
131
|
+
if (hasDay && !hasMonth && hasYear && hasHours && hasMinutes) {
|
|
60
132
|
return "form.error.datetime.invalid_month";
|
|
61
133
|
}
|
|
62
|
-
if (!
|
|
134
|
+
if (!hasDay && hasMonth && hasYear && hasHours && !hasMinutes) {
|
|
135
|
+
return "form.error.datetime.invalid_day_minutes";
|
|
136
|
+
}
|
|
137
|
+
if (!hasDay && hasMonth && hasYear && !hasHours && hasMinutes) {
|
|
138
|
+
return "form.error.datetime.invalid_day_hours";
|
|
139
|
+
}
|
|
140
|
+
if (!hasDay && hasMonth && hasYear && hasHours && hasMinutes) {
|
|
63
141
|
return "form.error.datetime.invalid_day";
|
|
64
142
|
}
|
|
65
|
-
if (
|
|
66
|
-
|
|
67
|
-
|
|
143
|
+
if (!hasDay && !hasMonth && !hasYear && hasHours && !hasMinutes) {
|
|
144
|
+
return "form.error.datetime.invalid_day_month_year_minutes";
|
|
145
|
+
}
|
|
146
|
+
if (hasDay && hasMonth && hasYear && !hasHours && !hasMinutes) {
|
|
147
|
+
return "form.error.datetime.invalid_hours_minutes";
|
|
148
|
+
}
|
|
149
|
+
if (day && month) {
|
|
150
|
+
const dayNum = parseInt(day);
|
|
151
|
+
const monthNum = parseInt(month);
|
|
152
|
+
const validYear = onlyNumbersRegex.test(year) ? year : void 0;
|
|
153
|
+
if (!validYear || year.length < 4) {
|
|
154
|
+
return "form.error.datetime.invalid";
|
|
68
155
|
}
|
|
69
|
-
|
|
70
|
-
|
|
156
|
+
const yearNum = parseInt(validYear);
|
|
157
|
+
const maxDay = getDaysInMonth(monthNum, yearNum);
|
|
158
|
+
if (dayNum < 1 || dayNum > maxDay) {
|
|
159
|
+
return {
|
|
160
|
+
key: "form.error.datetime.invalid_day_range",
|
|
161
|
+
context: {
|
|
162
|
+
maxDay
|
|
163
|
+
}
|
|
164
|
+
};
|
|
71
165
|
}
|
|
72
|
-
if (
|
|
73
|
-
return "form.error.datetime.
|
|
166
|
+
if (monthNum < 1 || monthNum > 12) {
|
|
167
|
+
return "form.error.datetime.invalid_month_range";
|
|
74
168
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
169
|
+
}
|
|
170
|
+
if (hours && minutes) {
|
|
171
|
+
const hoursNum = parseInt(hours);
|
|
172
|
+
const minutesNum = parseInt(minutes);
|
|
173
|
+
if (hoursNum < 0 || hoursNum > 23) {
|
|
174
|
+
return "form.error.datetime.invalid_hours_range";
|
|
175
|
+
}
|
|
176
|
+
if (minutesNum < 0 || minutesNum > 59) {
|
|
177
|
+
return "form.error.datetime.invalid_minutes_range";
|
|
84
178
|
}
|
|
85
179
|
}
|
|
86
180
|
return "form.error.datetime.invalid";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/validators/utils/datetime.ts"],
|
|
4
|
-
"sourcesContent": ["import dayjs from 'dayjs';\nimport customParseFormat from 'dayjs/plugin/customParseFormat';\nimport { FieldSpec } from '@digigov/form/types';\nimport { ValidatorSchema } from '@digigov/form/validators/types';\n\ndayjs.extend(customParseFormat);\n\nconst VALID_DATETIME_FORMATS = ['DD/MM/YYYY HH:mm'];\nconst DATETIME_CACHE = {};\n\nconst getDateTime = (v: string) => {\n return DATETIME_CACHE[v]\n ? DATETIME_CACHE[v]\n : dayjs(v, VALID_DATETIME_FORMATS, true);\n};\n\n//
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkB;AAClB,+BAA8B;AAI9B,aAAAA,QAAM,OAAO,yBAAAC,OAAiB;AAE9B,MAAM,yBAAyB,CAAC,kBAAkB;AAClD,MAAM,iBAAiB,CAAC;
|
|
4
|
+
"sourcesContent": ["import dayjs from 'dayjs';\nimport customParseFormat from 'dayjs/plugin/customParseFormat';\nimport type { FieldSpec } from '@digigov/form/types';\nimport type { ValidatorSchema } from '@digigov/form/validators/types';\n\ndayjs.extend(customParseFormat);\n\nconst VALID_DATETIME_FORMATS = ['DD/MM/YYYY HH:mm'];\nconst DATETIME_CACHE = {};\nconst onlyNumbersRegex = /^\\d+$/;\n\nconst getDateTime = (v: string) => {\n return DATETIME_CACHE[v]\n ? DATETIME_CACHE[v]\n : dayjs(v, VALID_DATETIME_FORMATS, true);\n};\n\nconst getDaysInMonth = (month: number, year: number): number => {\n return dayjs(`${year}-${month}-01`).daysInMonth(); // e.g. 29 for Feb 2024\n};\n\nconst checkPartialDateTime = (value: string) => {\n const [datePart, timePart] = value.split(' ');\n const [day, month, year] = datePart?.split('/') ?? [];\n const [hours, minutes] = timePart?.split(':') ?? [];\n\n const hasDay = Boolean(day);\n const hasMonth = Boolean(month);\n const hasYear = Boolean(year);\n const hasHours = Boolean(hours);\n const hasMinutes = Boolean(minutes);\n\n if (hasDay && !hasMonth && !hasYear && !hasHours && !hasMinutes) {\n return 'form.error.datetime.invalid_month_year_hours_minutes';\n }\n if (!hasDay && hasMonth && !hasYear && !hasHours && !hasMinutes) {\n return 'form.error.datetime.invalid_day_year_hours_minutes';\n }\n if (!hasDay && !hasMonth && hasYear && !hasHours && !hasMinutes) {\n return 'form.error.datetime.invalid_day_month_hours_minutes';\n }\n if (hasDay && hasMonth && !hasYear && !hasHours && !hasMinutes) {\n return 'form.error.datetime.invalid_year_hours_minutes';\n }\n if (hasDay && !hasMonth && hasYear && !hasHours && !hasMinutes) {\n return 'form.error.datetime.invalid_month_hours_minutes';\n }\n if (!hasDay && hasMonth && hasYear && !hasHours && !hasMinutes) {\n return 'form.error.datetime.invalid_day_hours_minutes';\n }\n if (hasDay && hasMonth && hasYear && !hasHours && !hasMinutes) {\n return 'form.error.datetime.invalid__hours_minutes';\n }\n if (hasDay && hasMonth && hasYear && hasHours && !hasMinutes) {\n return 'form.error.datetime.invalid_minutes';\n }\n if (hasDay && hasMonth && hasYear && !hasHours && hasMinutes) {\n return 'form.error.datetime.invalid_hours';\n }\n if (hasDay && !hasMonth && !hasYear && hasHours && !hasMinutes) {\n return 'form.error.datetime.invalid_month_year_minutes';\n }\n if (hasDay && !hasMonth && !hasYear && !hasHours && hasMinutes) {\n return 'form.error.datetime.invalid_month_year_hours';\n }\n if (hasDay && !hasMonth && !hasYear && hasHours && hasMinutes) {\n return 'form.error.datetime.invalid_month_year';\n }\n if (!hasDay && hasMonth && !hasYear && hasHours && !hasMinutes) {\n return 'form.error.datetime.invalid_day_year_minutes';\n }\n if (!hasDay && hasMonth && !hasYear && !hasHours && hasMinutes) {\n return 'form.error.datetime.invalid_day_year_hours';\n }\n if (!hasDay && hasMonth && !hasYear && hasHours && hasMinutes) {\n return 'form.error.datetime.invalid_day_year';\n }\n if (!hasDay && !hasMonth && hasYear && hasHours && !hasMinutes) {\n return 'form.error.datetime.invalid_day_month_minutes';\n }\n if (!hasDay && !hasMonth && hasYear && !hasHours && hasMinutes) {\n return 'form.error.datetime.invalid_day_month_hours';\n }\n if (!hasDay && !hasMonth && hasYear && hasHours && hasMinutes) {\n return 'form.error.datetime.invalid_day_month';\n }\n if (!hasDay && !hasMonth && !hasYear && hasHours && hasMinutes) {\n return 'form.error.datetime.invalid_day_month_year';\n }\n if (!hasDay && !hasMonth && !hasYear && !hasHours && hasMinutes) {\n return 'form.error.datetime.invalid_day_month_year_hours';\n }\n if (hasDay && hasMonth && !hasYear && hasHours && !hasMinutes) {\n return 'form.error.datetime.invalid_year_minutes';\n }\n if (hasDay && hasMonth && !hasYear && !hasHours && hasMinutes) {\n return 'form.error.datetime.invalid_year_hours';\n }\n if (hasDay && hasMonth && !hasYear && hasHours && hasMinutes) {\n return 'form.error.datetime.invalid_year';\n }\n if (hasDay && !hasMonth && hasYear && hasHours && !hasMinutes) {\n return 'form.error.datetime.invalid_month_minutes';\n }\n if (hasDay && !hasMonth && hasYear && !hasHours && hasMinutes) {\n return 'form.error.datetime.invalid_month_hours';\n }\n if (hasDay && !hasMonth && hasYear && hasHours && hasMinutes) {\n return 'form.error.datetime.invalid_month';\n }\n if (!hasDay && hasMonth && hasYear && hasHours && !hasMinutes) {\n return 'form.error.datetime.invalid_day_minutes';\n }\n if (!hasDay && hasMonth && hasYear && !hasHours && hasMinutes) {\n return 'form.error.datetime.invalid_day_hours';\n }\n if (!hasDay && hasMonth && hasYear && hasHours && hasMinutes) {\n return 'form.error.datetime.invalid_day';\n }\n if (!hasDay && !hasMonth && !hasYear && hasHours && !hasMinutes) {\n return 'form.error.datetime.invalid_day_month_year_minutes';\n }\n if (hasDay && hasMonth && hasYear && !hasHours && !hasMinutes) {\n return 'form.error.datetime.invalid_hours_minutes';\n }\n if (day && month) {\n const dayNum = parseInt(day);\n const monthNum = parseInt(month);\n const validYear = onlyNumbersRegex.test(year) ? year : undefined;\n if (!validYear || year.length < 4) {\n return 'form.error.datetime.invalid';\n }\n const yearNum = parseInt(validYear);\n const maxDay = getDaysInMonth(monthNum, yearNum);\n if (dayNum < 1 || dayNum > maxDay) {\n return {\n key: 'form.error.datetime.invalid_day_range',\n context: {\n maxDay: maxDay,\n },\n };\n }\n if (monthNum < 1 || monthNum > 12) {\n return 'form.error.datetime.invalid_month_range';\n }\n }\n if (hours && minutes) {\n const hoursNum = parseInt(hours);\n const minutesNum = parseInt(minutes);\n if (hoursNum < 0 || hoursNum > 23) {\n return 'form.error.datetime.invalid_hours_range';\n }\n if (minutesNum < 0 || minutesNum > 59) {\n return 'form.error.datetime.invalid_minutes_range';\n }\n }\n return 'form.error.datetime.invalid';\n};\n\nexport const LATER_THAN_DATETIME_VALIDATOR = (\n field: FieldSpec\n): ValidatorSchema => {\n let minDateTime;\n const params = field.extra || {};\n if (params.min === 'now') {\n minDateTime = dayjs();\n } else {\n minDateTime = getDateTime(params.min);\n }\n return {\n name: 'later-than-datetime',\n message: {\n key: 'form.error.datetime.later_than',\n context: {\n minDateTime: minDateTime.format('DD/MM/YYYY HH:mm'),\n },\n },\n test: function (value: string) {\n if (!value) return true;\n const datetime = getDateTime(value);\n return datetime.isValid() && datetime.isAfter(minDateTime);\n },\n };\n};\n\nexport const EARLIER_THAN_DATETIME_VALIDATOR = (\n field: FieldSpec\n): ValidatorSchema => {\n let maxDateTime;\n const params = field.extra || {};\n if (params.max === 'now') {\n maxDateTime = dayjs();\n } else {\n maxDateTime = getDateTime(params.max);\n }\n return {\n name: 'earlier-than-datetime',\n message: {\n key: 'form.error.datetime.earlier_than',\n context: {\n maxDateTime: maxDateTime.format('DD/MM/YYYY HH:mm'),\n },\n },\n test: function (value: string) {\n if (!value) return true;\n const datetime = getDateTime(value);\n return datetime.isValid() && datetime.isBefore(maxDateTime);\n },\n };\n};\n\nexport const DATETIME_VALIDATOR = {\n name: 'datetime-validator',\n message: (v): string | object => {\n return checkPartialDateTime(v.value);\n },\n test: function (value: string) {\n if (!value) return true;\n const datetime = getDateTime(value);\n return datetime.isValid();\n },\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkB;AAClB,+BAA8B;AAI9B,aAAAA,QAAM,OAAO,yBAAAC,OAAiB;AAE9B,MAAM,yBAAyB,CAAC,kBAAkB;AAClD,MAAM,iBAAiB,CAAC;AACxB,MAAM,mBAAmB;AAEzB,MAAM,cAAc,CAAC,MAAc;AACjC,SAAO,eAAe,CAAC,IACnB,eAAe,CAAC,QAChB,aAAAD,SAAM,GAAG,wBAAwB,IAAI;AAC3C;AAEA,MAAM,iBAAiB,CAAC,OAAe,SAAyB;AAC9D,aAAO,aAAAA,SAA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
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var email_exports = {};
|
|
19
|
+
__export(email_exports, {
|
|
20
|
+
EMAIL_VALIDATOR: () => EMAIL_VALIDATOR
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(email_exports);
|
|
23
|
+
const EMAIL_VALIDATOR = {
|
|
24
|
+
name: "email-validator",
|
|
25
|
+
message: "form.error.email",
|
|
26
|
+
test: (value) => {
|
|
27
|
+
if (!value) return true;
|
|
28
|
+
const EMAIL_REGEX = (
|
|
29
|
+
// eslint-disable-next-line no-useless-escape
|
|
30
|
+
/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
|
|
31
|
+
);
|
|
32
|
+
return EMAIL_REGEX.test(value);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
36
|
+
0 && (module.exports = {
|
|
37
|
+
EMAIL_VALIDATOR
|
|
38
|
+
});
|
|
39
|
+
//# sourceMappingURL=email.js.map
|