@digigov/form 2.0.0-13876dba → 2.0.0-16fbe090
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.d.ts +4 -4
- package/Field/ErrorGroup.js +53 -0
- package/Field/FieldBase.d.ts +1 -1
- package/Field/FieldBase.js +77 -0
- package/Field/FieldBaseContainer.d.ts +2 -2
- package/Field/FieldBaseContainer.js +43 -0
- package/Field/FieldConditional.d.ts +1 -1
- package/Field/FieldConditional.js +45 -0
- package/Field/index.d.ts +1 -1
- package/Field/index.js +70 -112
- package/Field/types.d.ts +22 -12
- package/Field/types.js +0 -0
- package/Field/utils/evaluateFieldWithConditions.d.ts +2 -2
- package/Field/utils/evaluateFieldWithConditions.js +19 -0
- package/Field/utils/resolveField.d.ts +3 -0
- package/Field/utils/resolveField.js +32 -0
- package/Field/utils/useField.d.ts +1 -1
- package/Field/utils/useField.js +47 -0
- package/FieldArray/BaseFieldArray.d.ts +5 -0
- package/FieldArray/BaseFieldArray.js +46 -0
- package/FieldArray/FormDialog/ArrayDisplay/ArrayContainerDisplay.d.ts +9 -0
- package/FieldArray/FormDialog/ArrayDisplay/ArrayContainerDisplay.js +13 -0
- package/FieldArray/FormDialog/ArrayDisplay/ArrayItemDisplay.d.ts +26 -0
- package/FieldArray/FormDialog/ArrayDisplay/ArrayItemDisplay.js +117 -0
- package/FieldArray/FormDialog/ArrayDisplay/ArrayItemHeader.d.ts +5 -0
- package/FieldArray/FormDialog/ArrayDisplay/ArrayItemHeader.js +6 -0
- package/FieldArray/FormDialog/ArrayDisplay/index.d.ts +15 -0
- package/FieldArray/FormDialog/ArrayDisplay/index.js +32 -0
- package/FieldArray/FormDialog/ArrayEditModal.d.ts +24 -0
- package/FieldArray/FormDialog/ArrayEditModal.js +138 -0
- package/FieldArray/FormDialog/index.d.ts +19 -0
- package/FieldArray/FormDialog/index.js +191 -271
- package/FieldArray/index.d.ts +5 -2
- package/FieldArray/index.js +62 -106
- package/FieldObject/index.d.ts +7 -4
- package/FieldObject/index.js +51 -72
- package/Fieldset/FieldsetWithContext.js +27 -0
- package/Fieldset/index.d.ts +1 -1
- package/Fieldset/index.js +18 -30
- package/Fieldset/types.d.ts +2 -2
- package/Fieldset/types.js +0 -0
- package/FormBuilder/index.d.ts +2 -2
- package/FormBuilder/index.js +233 -231
- package/FormContext.d.ts +3 -2
- package/FormContext.js +7 -0
- package/MultiplicityField/add-objects.d.ts +2 -2
- package/MultiplicityField/add-objects.js +107 -0
- package/MultiplicityField/index.d.ts +2 -2
- package/MultiplicityField/index.js +81 -116
- package/MultiplicityField/types.d.ts +3 -2
- package/MultiplicityField/types.js +0 -0
- package/Questions/Questions.d.ts +1 -1
- package/Questions/Questions.js +48 -0
- package/Questions/QuestionsContext.d.ts +1 -1
- package/Questions/QuestionsContext.js +10 -0
- package/Questions/Step/ReviewStep.js +32 -0
- package/Questions/Step/Step.d.ts +1 -1
- package/Questions/Step/Step.js +39 -0
- package/Questions/Step/StepArrayReview.d.ts +1 -1
- package/Questions/Step/StepArrayReview.js +35 -0
- package/Questions/Step/StepContext.d.ts +1 -1
- package/Questions/Step/StepContext.js +28 -0
- package/Questions/Step/StepDescription.d.ts +1 -1
- package/Questions/Step/StepDescription.js +18 -0
- package/Questions/Step/StepForm.d.ts +2 -2
- package/Questions/Step/StepForm.js +29 -0
- package/Questions/Step/StepQuote.d.ts +1 -1
- package/Questions/Step/StepQuote.js +5 -0
- package/Questions/Step/StepTitle.d.ts +1 -1
- package/Questions/Step/StepTitle.js +25 -0
- package/Questions/Step/getAddMoreFields.d.ts +2 -2
- package/Questions/Step/getAddMoreFields.js +24 -0
- package/Questions/Step/index.d.ts +11 -11
- package/Questions/Step/index.js +13 -16
- package/Questions/Step/types.d.ts +1 -1
- package/Questions/Step/types.js +0 -0
- package/Questions/getNextStep.d.ts +1 -1
- package/Questions/getNextStep.js +13 -0
- package/Questions/index.d.ts +2 -2
- package/Questions/index.js +4 -7
- package/Questions/types.d.ts +1 -1
- package/Questions/types.js +0 -0
- package/hooks/useFieldFocusManager.d.ts +25 -0
- package/hooks/useFieldFocusManager.js +83 -0
- package/hooks/utils.d.ts +18 -0
- package/hooks/utils.js +60 -0
- package/index.d.ts +5 -5
- package/index.js +8 -13
- package/inputs/AutoCompleteInput/index.d.ts +3 -3
- package/inputs/AutoCompleteInput/index.js +38 -62
- package/inputs/Checkboxes/index.d.ts +5 -3
- package/inputs/Checkboxes/index.js +50 -78
- package/inputs/DateInput/index.d.ts +2 -5
- package/inputs/DateInput/index.js +125 -117
- package/inputs/DateTimeInput/index.d.ts +2 -5
- package/inputs/DateTimeInput/index.js +179 -170
- package/inputs/FileInput/index.d.ts +12 -5
- package/inputs/FileInput/index.js +58 -59
- package/inputs/ImageInput/index.d.ts +10 -2
- package/inputs/ImageInput/index.js +84 -53
- package/inputs/Input/index.d.ts +5 -2
- package/inputs/Input/index.js +60 -69
- package/inputs/Label/index.d.ts +1 -1
- package/inputs/Label/index.js +13 -16
- package/inputs/OtpInput/index.d.ts +1 -5
- package/inputs/OtpInput/index.js +117 -141
- package/inputs/Radio/index.d.ts +6 -4
- package/inputs/Radio/index.js +71 -102
- package/inputs/Select/index.d.ts +6 -3
- package/inputs/Select/index.js +23 -31
- package/inputs/index.d.ts +9 -9
- package/inputs/index.js +10 -21
- package/{Field/utils/index.d.ts → inputs/registry.d.ts} +2 -1
- package/inputs/registry.js +80 -0
- package/internal.d.ts +5 -5
- package/internal.js +6 -0
- package/lazy.d.ts +97 -0
- package/lazy.js +163 -0
- package/package.json +12 -12
- package/registry.d.ts +82 -0
- package/registry.js +170 -0
- package/src/Field/ErrorGroup.tsx +4 -4
- package/src/Field/FieldBase.tsx +9 -4
- package/src/Field/FieldBaseContainer.tsx +69 -48
- package/src/Field/FieldConditional.tsx +5 -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 +1 -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 +337 -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 +241 -0
- package/src/FieldArray/FormDialog/index.tsx +302 -0
- package/src/FieldArray/__stories__/CardsWithError.tsx +124 -0
- package/src/FieldArray/__stories__/WithModal.tsx +3 -2
- 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 +4 -0
- package/src/FieldArray/index.tsx +49 -73
- package/src/FieldObject/index.tsx +36 -31
- package/src/Fieldset/FieldsetWithContext.tsx +1 -1
- package/src/Fieldset/index.tsx +1 -1
- package/src/Fieldset/types.tsx +2 -2
- package/src/FormBuilder/doc.mdx +1 -1
- package/src/FormBuilder/index.tsx +197 -146
- package/src/FormBuilder/scenarios.test.tsx +806 -9
- package/src/FormContext.tsx +7 -2
- package/src/MultiplicityField/__stories__/PreviewDisplay.tsx +1 -3
- package/src/MultiplicityField/add-objects.tsx +14 -21
- package/src/MultiplicityField/index.tsx +6 -2
- package/src/MultiplicityField/types.ts +6 -2
- 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/getNextStep.tsx +1 -1
- package/src/Questions/types.tsx +1 -1
- 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/doc.mdx +2 -2
- package/src/inputs/AutoCompleteInput/index.tsx +4 -6
- package/src/inputs/Checkboxes/doc.mdx +3 -3
- package/src/inputs/Checkboxes/index.tsx +98 -91
- package/src/inputs/DateInput/DateInput.stories.js +4 -0
- 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/doc.mdx +1 -1
- package/src/inputs/DateInput/index.test.tsx +16 -0
- package/src/inputs/DateInput/index.tsx +65 -20
- package/src/inputs/DateTimeInput/DateTimeInput.stories.js +9 -6
- 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/doc.mdx +1 -1
- package/src/inputs/DateTimeInput/index.test.tsx +16 -0
- package/src/inputs/DateTimeInput/index.tsx +92 -40
- package/src/inputs/FileInput/FileInput.stories.js +1 -0
- package/src/inputs/FileInput/__stories__/WithBorderAndLink.tsx +34 -0
- package/src/inputs/FileInput/doc.mdx +1 -1
- package/src/inputs/FileInput/index.test.tsx +4 -0
- package/src/inputs/FileInput/index.tsx +83 -47
- package/src/inputs/ImageInput/ImageInput.stories.js +2 -1
- package/src/inputs/ImageInput/__stories__/MaxSize.tsx +2 -1
- package/src/inputs/ImageInput/__stories__/WithInitialValues.tsx +45 -0
- package/src/inputs/ImageInput/__stories__/logo.d.ts +4 -0
- package/src/inputs/ImageInput/__stories__/logo.png +0 -0
- package/src/inputs/ImageInput/doc.mdx +3 -3
- package/src/inputs/ImageInput/index.test.tsx +21 -17
- package/src/inputs/ImageInput/index.tsx +102 -50
- package/src/inputs/Input/Input.stories.js +3 -0
- package/src/inputs/Input/__stories__/AMKA.tsx +23 -0
- package/src/inputs/Input/__stories__/Email.tsx +23 -0
- package/src/inputs/Input/__stories__/Rate.tsx +25 -0
- package/src/inputs/Input/doc.mdx +10 -10
- package/src/inputs/Input/index.test.tsx +12 -0
- package/src/inputs/Input/index.tsx +19 -10
- package/src/inputs/Label/doc.mdx +1 -1
- package/src/inputs/Label/index.tsx +1 -1
- package/src/inputs/OtpInput/doc.mdx +1 -1
- package/src/inputs/OtpInput/index.tsx +43 -34
- package/src/inputs/Radio/doc.mdx +3 -3
- package/src/inputs/Radio/index.tsx +33 -22
- package/src/inputs/Select/doc.mdx +1 -1
- package/src/inputs/Select/index.tsx +12 -7
- package/src/{Field/utils/index.ts → inputs/registry.ts} +5 -1
- package/{lazy/index.js → src/lazy.ts} +8 -29
- package/{registry/index.js → src/registry.ts} +33 -19
- package/src/types.tsx +14 -5
- package/src/utils.ts +41 -8
- package/src/validators/index.ts +50 -17
- 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 +13 -6
- package/src/validators/utils/int.ts +1 -1
- package/src/validators/utils/number.ts +1 -1
- 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 +11 -5
- package/types.js +1 -0
- package/utils.d.ts +4 -1
- package/utils.js +56 -0
- package/validators/index.d.ts +6 -6
- package/validators/index.js +112 -139
- package/validators/types.d.ts +1 -1
- package/validators/types.js +0 -0
- package/validators/utils/afm.js +19 -0
- package/validators/utils/amka.d.ts +6 -0
- package/validators/utils/amka.js +27 -0
- package/validators/utils/date.d.ts +3 -3
- package/validators/utils/date.js +95 -0
- package/validators/utils/datetime.d.ts +3 -3
- package/validators/utils/datetime.js +121 -0
- package/validators/utils/email.d.ts +5 -0
- package/validators/utils/email.js +10 -0
- package/validators/utils/file.d.ts +2 -2
- package/validators/utils/file.js +31 -0
- package/validators/utils/iban.d.ts +2 -2
- package/validators/utils/iban.js +104 -0
- package/validators/utils/image.d.ts +2 -2
- package/validators/utils/image.js +65 -0
- package/validators/utils/index.d.ts +14 -13
- package/validators/utils/index.js +59 -90
- package/validators/utils/int.d.ts +1 -1
- package/validators/utils/int.js +13 -0
- package/validators/utils/number.d.ts +1 -1
- package/validators/utils/number.js +12 -0
- package/validators/utils/otp.d.ts +2 -2
- package/validators/utils/otp.js +21 -0
- package/validators/utils/phone.d.ts +2 -2
- package/validators/utils/phone.js +198 -0
- package/validators/utils/postal_code.d.ts +2 -2
- package/validators/utils/postal_code.js +18 -0
- package/validators/utils/text_limit.d.ts +2 -2
- package/validators/utils/text_limit.js +34 -0
- package/validators/utils/uuid4.js +14 -0
- package/Field/ErrorGroup/index.js +0 -48
- package/Field/ErrorGroup/package.json +0 -6
- package/Field/ErrorGroup.js.map +0 -7
- package/Field/FieldBase/index.js +0 -117
- package/Field/FieldBase/package.json +0 -6
- package/Field/FieldBase.js.map +0 -7
- package/Field/FieldBaseContainer/index.js +0 -33
- package/Field/FieldBaseContainer/package.json +0 -6
- package/Field/FieldBaseContainer.js.map +0 -7
- package/Field/FieldConditional/index.js +0 -85
- package/Field/FieldConditional/package.json +0 -6
- package/Field/FieldConditional.js.map +0 -7
- package/Field/index.js.map +0 -7
- package/Field/package.json +0 -6
- package/Field/types/index.js +0 -1
- package/Field/types/package.json +0 -6
- package/Field/types.js.map +0 -7
- package/Field/utils/calculateField/index.js +0 -27
- package/Field/utils/calculateField/package.json +0 -6
- package/Field/utils/calculateField.d.ts +0 -2
- package/Field/utils/calculateField.js.map +0 -7
- package/Field/utils/evaluateFieldWithConditions/index.js +0 -26
- package/Field/utils/evaluateFieldWithConditions/package.json +0 -6
- package/Field/utils/evaluateFieldWithConditions.js.map +0 -7
- package/Field/utils/index.js +0 -84
- package/Field/utils/index.js.map +0 -7
- package/Field/utils/package.json +0 -6
- package/Field/utils/useField/index.js +0 -57
- package/Field/utils/useField/package.json +0 -6
- package/Field/utils/useField.js.map +0 -7
- package/FieldArray/FieldArray.stories.d.ts +0 -10
- package/FieldArray/FormDialog/package.json +0 -6
- package/FieldArray/FormDialog.d.ts +0 -53
- package/FieldArray/FormDialog.js.map +0 -7
- package/FieldArray/__stories__/Default.d.ts +0 -2
- package/FieldArray/__stories__/WithExactLength.d.ts +0 -2
- package/FieldArray/__stories__/WithModal.d.ts +0 -2
- package/FieldArray/index.js.map +0 -7
- package/FieldArray/index.test.d.ts +0 -1
- package/FieldArray/package.json +0 -6
- package/FieldObject/index.js.map +0 -7
- package/FieldObject/package.json +0 -6
- package/Fieldset/FieldsetWithContext/index.js +0 -31
- package/Fieldset/FieldsetWithContext/package.json +0 -6
- package/Fieldset/FieldsetWithContext.js.map +0 -7
- package/Fieldset/index.js.map +0 -7
- package/Fieldset/package.json +0 -6
- package/Fieldset/types/index.js +0 -1
- package/Fieldset/types/package.json +0 -6
- package/Fieldset/types.js.map +0 -7
- package/Form.stories.d.ts +0 -4
- package/FormBuilder/FormBuilder.stories.d.ts +0 -12
- package/FormBuilder/__stories__/AutoErrorGrouping.d.ts +0 -3
- package/FormBuilder/__stories__/Default.d.ts +0 -3
- package/FormBuilder/__stories__/ErrorGrouping.d.ts +0 -3
- package/FormBuilder/index.js.map +0 -7
- package/FormBuilder/index.test.d.ts +0 -1
- package/FormBuilder/interaction.test.d.ts +0 -1
- package/FormBuilder/package.json +0 -6
- package/FormBuilder/scenarios.test.d.ts +0 -88
- package/FormContext/index.js +0 -9
- package/FormContext/package.json +0 -6
- package/FormContext.js.map +0 -7
- package/MultiplicityField/MultiplicityField.stories.d.ts +0 -15
- package/MultiplicityField/__stories__/Default.d.ts +0 -2
- package/MultiplicityField/__stories__/PreviewDisplay.d.ts +0 -2
- package/MultiplicityField/__stories__/WithExactLength.d.ts +0 -2
- package/MultiplicityField/__stories__/WithMaxLength.d.ts +0 -2
- package/MultiplicityField/__stories__/WithMinAndMaxLength.d.ts +0 -2
- package/MultiplicityField/__stories__/WithMinLength.d.ts +0 -2
- package/MultiplicityField/add-objects/index.js +0 -153
- package/MultiplicityField/add-objects/package.json +0 -6
- package/MultiplicityField/add-objects.js.map +0 -7
- package/MultiplicityField/index.js.map +0 -7
- package/MultiplicityField/index.test.d.ts +0 -1
- package/MultiplicityField/package.json +0 -6
- package/MultiplicityField/types/index.js +0 -1
- package/MultiplicityField/types/package.json +0 -6
- package/MultiplicityField/types.js.map +0 -7
- package/Questions/Questions/index.js +0 -67
- package/Questions/Questions/package.json +0 -6
- package/Questions/Questions.js.map +0 -7
- package/Questions/Questions.stories.d.ts +0 -10
- package/Questions/QuestionsContext/index.js +0 -11
- package/Questions/QuestionsContext/package.json +0 -6
- package/Questions/QuestionsContext.js.map +0 -7
- package/Questions/Step/ReviewStep/index.js +0 -38
- package/Questions/Step/ReviewStep/package.json +0 -6
- package/Questions/Step/ReviewStep.js.map +0 -7
- package/Questions/Step/Step/index.js +0 -54
- package/Questions/Step/Step/package.json +0 -6
- package/Questions/Step/Step.js.map +0 -7
- package/Questions/Step/StepArrayReview/index.js +0 -42
- package/Questions/Step/StepArrayReview/package.json +0 -6
- package/Questions/Step/StepArrayReview.js.map +0 -7
- package/Questions/Step/StepContext/index.js +0 -23
- package/Questions/Step/StepContext/package.json +0 -6
- package/Questions/Step/StepContext.js.map +0 -7
- package/Questions/Step/StepDescription/index.js +0 -24
- package/Questions/Step/StepDescription/package.json +0 -6
- package/Questions/Step/StepDescription.js.map +0 -7
- package/Questions/Step/StepForm/index.js +0 -34
- package/Questions/Step/StepForm/package.json +0 -6
- package/Questions/Step/StepForm.js.map +0 -7
- package/Questions/Step/StepQuote/index.js +0 -11
- package/Questions/Step/StepQuote/package.json +0 -6
- package/Questions/Step/StepQuote.js.map +0 -7
- package/Questions/Step/StepTitle/index.js +0 -44
- package/Questions/Step/StepTitle/package.json +0 -6
- package/Questions/Step/StepTitle.js.map +0 -7
- package/Questions/Step/getAddMoreFields/index.js +0 -29
- package/Questions/Step/getAddMoreFields/package.json +0 -6
- package/Questions/Step/getAddMoreFields.js.map +0 -7
- package/Questions/Step/index.js.map +0 -7
- package/Questions/Step/package.json +0 -6
- package/Questions/Step/types/index.js +0 -1
- package/Questions/Step/types/package.json +0 -6
- package/Questions/Step/types.js.map +0 -7
- package/Questions/__stories__/Default.d.ts +0 -3
- package/Questions/getNextStep/index.js +0 -22
- package/Questions/getNextStep/package.json +0 -6
- package/Questions/getNextStep.js.map +0 -7
- package/Questions/index.js.map +0 -7
- package/Questions/index.spec.d.ts +0 -1
- package/Questions/index.test.d.ts +0 -1
- package/Questions/package.json +0 -6
- package/Questions/types/index.js +0 -1
- package/Questions/types/package.json +0 -6
- package/Questions/types.js.map +0 -7
- package/cjs/Field/ErrorGroup/index.js +0 -82
- package/cjs/Field/ErrorGroup.js.map +0 -7
- package/cjs/Field/FieldBase/index.js +0 -150
- package/cjs/Field/FieldBase.js.map +0 -7
- package/cjs/Field/FieldBaseContainer/index.js +0 -66
- package/cjs/Field/FieldBaseContainer.js.map +0 -7
- package/cjs/Field/FieldConditional/index.js +0 -118
- package/cjs/Field/FieldConditional.js.map +0 -7
- package/cjs/Field/index.js +0 -144
- package/cjs/Field/index.js.map +0 -7
- package/cjs/Field/types/index.js +0 -16
- package/cjs/Field/types.js.map +0 -7
- package/cjs/Field/utils/calculateField/index.js +0 -50
- package/cjs/Field/utils/calculateField.js.map +0 -7
- package/cjs/Field/utils/evaluateFieldWithConditions/index.js +0 -49
- package/cjs/Field/utils/evaluateFieldWithConditions.js.map +0 -7
- package/cjs/Field/utils/index.js +0 -119
- package/cjs/Field/utils/index.js.map +0 -7
- package/cjs/Field/utils/useField/index.js +0 -80
- package/cjs/Field/utils/useField.js.map +0 -7
- package/cjs/FieldArray/FormDialog/index.js +0 -301
- package/cjs/FieldArray/FormDialog.js.map +0 -7
- package/cjs/FieldArray/index.js +0 -143
- package/cjs/FieldArray/index.js.map +0 -7
- package/cjs/FieldObject/index.js +0 -106
- package/cjs/FieldObject/index.js.map +0 -7
- package/cjs/Fieldset/FieldsetWithContext/index.js +0 -59
- package/cjs/Fieldset/FieldsetWithContext.js.map +0 -7
- package/cjs/Fieldset/index.js +0 -66
- package/cjs/Fieldset/index.js.map +0 -7
- package/cjs/Fieldset/types/index.js +0 -16
- package/cjs/Fieldset/types.js.map +0 -7
- package/cjs/FormBuilder/index.js +0 -273
- package/cjs/FormBuilder/index.js.map +0 -7
- package/cjs/FormContext/index.js +0 -32
- package/cjs/FormContext.js.map +0 -7
- package/cjs/MultiplicityField/add-objects/index.js +0 -181
- package/cjs/MultiplicityField/add-objects.js.map +0 -7
- package/cjs/MultiplicityField/index.js +0 -150
- package/cjs/MultiplicityField/index.js.map +0 -7
- package/cjs/MultiplicityField/types/index.js +0 -16
- package/cjs/MultiplicityField/types.js.map +0 -7
- package/cjs/Questions/Questions/index.js +0 -100
- package/cjs/Questions/Questions.js.map +0 -7
- package/cjs/Questions/QuestionsContext/index.js +0 -34
- package/cjs/Questions/QuestionsContext.js.map +0 -7
- package/cjs/Questions/Step/ReviewStep/index.js +0 -65
- package/cjs/Questions/Step/ReviewStep.js.map +0 -7
- package/cjs/Questions/Step/Step/index.js +0 -87
- package/cjs/Questions/Step/Step.js.map +0 -7
- package/cjs/Questions/Step/StepArrayReview/index.js +0 -67
- package/cjs/Questions/Step/StepArrayReview.js.map +0 -7
- package/cjs/Questions/Step/StepContext/index.js +0 -46
- package/cjs/Questions/Step/StepContext.js.map +0 -7
- package/cjs/Questions/Step/StepDescription/index.js +0 -58
- package/cjs/Questions/Step/StepDescription.js.map +0 -7
- package/cjs/Questions/Step/StepForm/index.js +0 -67
- package/cjs/Questions/Step/StepForm.js.map +0 -7
- package/cjs/Questions/Step/StepQuote/index.js +0 -44
- package/cjs/Questions/Step/StepQuote.js.map +0 -7
- package/cjs/Questions/Step/StepTitle/index.js +0 -76
- package/cjs/Questions/Step/StepTitle.js.map +0 -7
- package/cjs/Questions/Step/getAddMoreFields/index.js +0 -52
- package/cjs/Questions/Step/getAddMoreFields.js.map +0 -7
- package/cjs/Questions/Step/index.js +0 -59
- package/cjs/Questions/Step/index.js.map +0 -7
- package/cjs/Questions/Step/types/index.js +0 -16
- package/cjs/Questions/Step/types.js.map +0 -7
- package/cjs/Questions/getNextStep/index.js +0 -45
- package/cjs/Questions/getNextStep.js.map +0 -7
- package/cjs/Questions/index.js +0 -31
- package/cjs/Questions/index.js.map +0 -7
- package/cjs/Questions/types/index.js +0 -16
- package/cjs/Questions/types.js.map +0 -7
- package/cjs/index.js +0 -49
- package/cjs/index.js.map +0 -7
- package/cjs/inputs/AutoCompleteInput/index.js +0 -98
- package/cjs/inputs/AutoCompleteInput/index.js.map +0 -7
- package/cjs/inputs/Checkboxes/index.js +0 -107
- package/cjs/inputs/Checkboxes/index.js.map +0 -7
- package/cjs/inputs/DateInput/index.js +0 -156
- package/cjs/inputs/DateInput/index.js.map +0 -7
- package/cjs/inputs/DateTimeInput/index.js +0 -211
- package/cjs/inputs/DateTimeInput/index.js.map +0 -7
- package/cjs/inputs/FileInput/index.js +0 -95
- package/cjs/inputs/FileInput/index.js.map +0 -7
- package/cjs/inputs/ImageInput/index.js +0 -99
- package/cjs/inputs/ImageInput/index.js.map +0 -7
- package/cjs/inputs/Input/index.js +0 -111
- package/cjs/inputs/Input/index.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/Label/index.js +0 -50
- package/cjs/inputs/Label/index.js.map +0 -7
- package/cjs/inputs/OtpInput/index.js +0 -181
- package/cjs/inputs/OtpInput/index.js.map +0 -7
- package/cjs/inputs/Radio/index.js +0 -134
- package/cjs/inputs/Radio/index.js.map +0 -7
- package/cjs/inputs/Select/index.js +0 -62
- package/cjs/inputs/Select/index.js.map +0 -7
- package/cjs/inputs/index.js +0 -62
- package/cjs/inputs/index.js.map +0 -7
- package/cjs/inputs/inputsScenarios/index.js +0 -533
- package/cjs/inputs/inputsScenarios.js.map +0 -7
- package/cjs/internal/index.js +0 -38
- package/cjs/internal.js.map +0 -7
- package/cjs/lazy/index.js +0 -110
- package/cjs/lazy.js.map +0 -7
- package/cjs/locales/el/index.js +0 -35
- package/cjs/locales/el.js.map +0 -7
- package/cjs/registry/index.js +0 -195
- package/cjs/registry.js.map +0 -7
- package/cjs/types/index.js +0 -22
- package/cjs/types.js.map +0 -7
- package/cjs/utils/index.js +0 -83
- package/cjs/utils.js.map +0 -7
- package/cjs/validators/index.js +0 -160
- package/cjs/validators/index.js.map +0 -7
- package/cjs/validators/types/index.js +0 -16
- package/cjs/validators/types.js.map +0 -7
- package/cjs/validators/utils/afm/index.js +0 -55
- package/cjs/validators/utils/afm.js.map +0 -7
- package/cjs/validators/utils/date/index.js +0 -138
- package/cjs/validators/utils/date.js.map +0 -7
- package/cjs/validators/utils/datetime/index.js +0 -151
- package/cjs/validators/utils/datetime.js.map +0 -7
- package/cjs/validators/utils/file/index.js +0 -48
- package/cjs/validators/utils/file.js.map +0 -7
- package/cjs/validators/utils/iban/index.js +0 -142
- package/cjs/validators/utils/iban.js.map +0 -7
- package/cjs/validators/utils/image/index.js +0 -102
- package/cjs/validators/utils/image.js.map +0 -7
- package/cjs/validators/utils/index.js +0 -144
- package/cjs/validators/utils/index.js.map +0 -7
- package/cjs/validators/utils/int/index.js +0 -48
- package/cjs/validators/utils/int.js.map +0 -7
- package/cjs/validators/utils/number/index.js +0 -44
- package/cjs/validators/utils/number.js.map +0 -7
- package/cjs/validators/utils/otp/index.js +0 -54
- package/cjs/validators/utils/otp.js.map +0 -7
- package/cjs/validators/utils/phone/index.js +0 -198
- package/cjs/validators/utils/phone.js.map +0 -7
- package/cjs/validators/utils/postal_code/index.js +0 -54
- package/cjs/validators/utils/postal_code.js.map +0 -7
- package/cjs/validators/utils/text_limit/index.js +0 -69
- package/cjs/validators/utils/text_limit.js.map +0 -7
- package/cjs/validators/utils/uuid4/index.js +0 -46
- package/cjs/validators/utils/uuid4.js.map +0 -7
- package/index.js.map +0 -7
- package/inputs/AutoCompleteInput/AutoComplete.stories.d.ts +0 -11
- package/inputs/AutoCompleteInput/__stories__/Default.d.ts +0 -3
- package/inputs/AutoCompleteInput/__stories__/Multiple.d.ts +0 -3
- package/inputs/AutoCompleteInput/index.js.map +0 -7
- package/inputs/AutoCompleteInput/index.test.d.ts +0 -1
- package/inputs/AutoCompleteInput/package.json +0 -6
- package/inputs/Checkboxes/Checkboxes.stories.d.ts +0 -12
- package/inputs/Checkboxes/__stories__/Conditional.d.ts +0 -3
- package/inputs/Checkboxes/__stories__/Default.d.ts +0 -3
- package/inputs/Checkboxes/__stories__/WithDivider.d.ts +0 -3
- package/inputs/Checkboxes/index.js.map +0 -7
- package/inputs/Checkboxes/index.test.d.ts +0 -1
- package/inputs/Checkboxes/package.json +0 -6
- package/inputs/DateInput/DateInput.stories.d.ts +0 -10
- package/inputs/DateInput/__stories__/Default.d.ts +0 -3
- package/inputs/DateInput/index.js.map +0 -7
- package/inputs/DateInput/index.test.d.ts +0 -1
- package/inputs/DateInput/package.json +0 -6
- package/inputs/DateTimeInput/DateTimeInput.stories.d.ts +0 -9
- package/inputs/DateTimeInput/__stories__/Default.d.ts +0 -3
- package/inputs/DateTimeInput/index.js.map +0 -7
- package/inputs/DateTimeInput/index.test.d.ts +0 -1
- package/inputs/DateTimeInput/package.json +0 -6
- package/inputs/FileInput/FileInput.stories.d.ts +0 -10
- package/inputs/FileInput/__stories__/Default.d.ts +0 -3
- package/inputs/FileInput/index.js.map +0 -7
- package/inputs/FileInput/index.test.d.ts +0 -1
- package/inputs/FileInput/package.json +0 -6
- package/inputs/ImageInput/ImageInput.stories.d.ts +0 -12
- package/inputs/ImageInput/__stories__/Default.d.ts +0 -3
- package/inputs/ImageInput/__stories__/MaxSize.d.ts +0 -3
- package/inputs/ImageInput/__stories__/WithInvalidImageDimension.d.ts +0 -3
- package/inputs/ImageInput/index.js.map +0 -7
- package/inputs/ImageInput/index.test.d.ts +0 -1
- package/inputs/ImageInput/package.json +0 -6
- package/inputs/Input/Input.stories.d.ts +0 -20
- package/inputs/Input/__stories__/AFM.d.ts +0 -3
- package/inputs/Input/__stories__/Boolean.d.ts +0 -3
- package/inputs/Input/__stories__/IBAN.d.ts +0 -3
- package/inputs/Input/__stories__/Integer.d.ts +0 -3
- package/inputs/Input/__stories__/LandlineNumber.d.ts +0 -3
- package/inputs/Input/__stories__/MobilePhone.d.ts +0 -3
- package/inputs/Input/__stories__/PhoneNumber.d.ts +0 -3
- package/inputs/Input/__stories__/PostalCode.d.ts +0 -3
- package/inputs/Input/__stories__/String.d.ts +0 -3
- package/inputs/Input/__stories__/StringWithTrimValidation.d.ts +0 -3
- package/inputs/Input/__stories__/TextWithLimit.d.ts +0 -3
- package/inputs/Input/index.js.map +0 -7
- package/inputs/Input/index.test.d.ts +0 -1
- package/inputs/Input/inputsInputScenarios/index.js +0 -406
- package/inputs/Input/inputsInputScenarios/package.json +0 -6
- package/inputs/Input/inputsInputScenarios.d.ts +0 -57
- package/inputs/Input/inputsInputScenarios.js.map +0 -7
- package/inputs/Input/package.json +0 -6
- package/inputs/Label/Label.stories.d.ts +0 -10
- package/inputs/Label/__stories__/Default.d.ts +0 -3
- package/inputs/Label/index.js.map +0 -7
- package/inputs/Label/index.test.d.ts +0 -1
- package/inputs/Label/package.json +0 -6
- package/inputs/OtpInput/OtpInput.stories.d.ts +0 -10
- package/inputs/OtpInput/__stories__/Default.d.ts +0 -3
- package/inputs/OtpInput/index.js.map +0 -7
- package/inputs/OtpInput/index.test.d.ts +0 -1
- package/inputs/OtpInput/package.json +0 -6
- package/inputs/Radio/Radio.stories.d.ts +0 -12
- package/inputs/Radio/__stories__/Conditional.d.ts +0 -3
- package/inputs/Radio/__stories__/Default.d.ts +0 -3
- package/inputs/Radio/__stories__/WithDivider.d.ts +0 -3
- package/inputs/Radio/index.js.map +0 -7
- package/inputs/Radio/index.test.d.ts +0 -1
- package/inputs/Radio/package.json +0 -6
- package/inputs/Select/Select.stories.d.ts +0 -10
- package/inputs/Select/__stories__/Default.d.ts +0 -3
- package/inputs/Select/index.js.map +0 -7
- package/inputs/Select/index.test.d.ts +0 -1
- package/inputs/Select/package.json +0 -6
- package/inputs/index.js.map +0 -7
- package/inputs/inputsScenarios/index.js +0 -499
- package/inputs/inputsScenarios/package.json +0 -6
- package/inputs/inputsScenarios.d.ts +0 -296
- package/inputs/inputsScenarios.js.map +0 -7
- package/inputs/package.json +0 -6
- package/internal/index.js +0 -10
- package/internal/package.json +0 -6
- package/internal.js.map +0 -7
- package/lazy/package.json +0 -6
- package/locales/el/index.js +0 -6
- package/locales/el/package.json +0 -6
- package/locales/el.d.ts +0 -2
- package/locales/el.js.map +0 -7
- package/registry/package.json +0 -6
- package/src/Field/utils/calculateField.ts +0 -49
- package/src/FieldArray/FormDialog.tsx +0 -378
- package/src/inputs/Input/inputsInputScenarios.ts +0 -404
- package/src/inputs/inputsScenarios.ts +0 -496
- package/src/lazy.js +0 -77
- package/src/locales/el.ts +0 -3
- package/src/registry.js +0 -165
- package/types/index.js +0 -2
- package/types/package.json +0 -6
- package/types.js.map +0 -7
- package/utils/index.js +0 -60
- package/utils/package.json +0 -6
- package/utils.js.map +0 -7
- package/validators/index.js.map +0 -7
- package/validators/package.json +0 -6
- package/validators/types/index.js +0 -1
- package/validators/types/package.json +0 -6
- package/validators/types.js.map +0 -7
- package/validators/utils/afm/index.js +0 -31
- package/validators/utils/afm/package.json +0 -6
- package/validators/utils/afm.js.map +0 -7
- package/validators/utils/date/index.js +0 -103
- package/validators/utils/date/package.json +0 -6
- package/validators/utils/date.js.map +0 -7
- package/validators/utils/datetime/index.js +0 -116
- package/validators/utils/datetime/package.json +0 -6
- package/validators/utils/datetime.js.map +0 -7
- package/validators/utils/file/index.js +0 -25
- package/validators/utils/file/package.json +0 -6
- package/validators/utils/file.js.map +0 -7
- package/validators/utils/iban/index.js +0 -118
- package/validators/utils/iban/package.json +0 -6
- package/validators/utils/iban.js.map +0 -7
- package/validators/utils/image/index.js +0 -79
- package/validators/utils/image/package.json +0 -6
- package/validators/utils/image.js.map +0 -7
- package/validators/utils/index.js.map +0 -7
- package/validators/utils/int/index.js +0 -24
- package/validators/utils/int/package.json +0 -6
- package/validators/utils/int.js.map +0 -7
- package/validators/utils/number/index.js +0 -20
- package/validators/utils/number/package.json +0 -6
- package/validators/utils/number.js.map +0 -7
- package/validators/utils/otp/index.js +0 -30
- package/validators/utils/otp/package.json +0 -6
- package/validators/utils/otp.js.map +0 -7
- package/validators/utils/package.json +0 -6
- package/validators/utils/phone/index.js +0 -172
- package/validators/utils/phone/package.json +0 -6
- package/validators/utils/phone.js.map +0 -7
- package/validators/utils/postal_code/index.js +0 -30
- package/validators/utils/postal_code/package.json +0 -6
- package/validators/utils/postal_code.js.map +0 -7
- package/validators/utils/text_limit/index.js +0 -45
- package/validators/utils/text_limit/package.json +0 -6
- package/validators/utils/text_limit.js.map +0 -7
- package/validators/utils/uuid4/index.js +0 -22
- package/validators/utils/uuid4/package.json +0 -6
- package/validators/utils/uuid4.js.map +0 -7
- package/validators/validators.spec.d.ts +0 -1
package/validators/index.js
CHANGED
|
@@ -1,144 +1,117 @@
|
|
|
1
1
|
import { useMemo } from "react";
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
2
|
+
import { array, boolean as external_yup_boolean, mixed, number, string } from "yup";
|
|
3
|
+
import { AFM_VALIDATOR, AMKA_VALIDATOR, DATETIME_VALIDATOR, DATE_VALIDATOR, EARLIER_THAN_DATETIME_VALIDATOR, EARLIER_THAN_VALIDATOR, FILE_MAX_SIZE_VALIDATOR, IBAN_VALIDATOR, IMAGE_DIMENSION_VALIDATOR, LATER_THAN_DATETIME_VALIDATOR, LATER_THAN_VALIDATOR, MOBILE_PHONE_VALIDATOR, OTP_VALIDATOR, PHONE_NUMBER_VALIDATOR, POSTALCODE_VALIDATOR, TEXT_LIMIT_VALIDATOR, UUID4_VALIDATOR, getYupObjectShape } from "./utils/index.js";
|
|
4
|
+
import { EMAIL_VALIDATOR } from "./utils/email.js";
|
|
5
|
+
import { INT_VALIDATOR } from "./utils/int.js";
|
|
6
|
+
import { NUMBER_VALIDATOR } from "./utils/number.js";
|
|
7
|
+
const getYUPTypeMap = (validatorRegistry)=>{
|
|
8
|
+
const yupTypeMap = {
|
|
9
|
+
file: (field)=>mixed().transform((value)=>{
|
|
10
|
+
if (!value || 0 === value.length) return null;
|
|
11
|
+
return value;
|
|
12
|
+
}).nullable().test(FILE_MAX_SIZE_VALIDATOR(field)),
|
|
13
|
+
string: (field)=>{
|
|
14
|
+
if (field.trim) return string().trim();
|
|
15
|
+
return string();
|
|
16
|
+
},
|
|
17
|
+
boolean: ()=>external_yup_boolean().nullable().transform((value)=>{
|
|
18
|
+
if ('' === value || 'string' == typeof value) return null;
|
|
19
|
+
if ('boolean' == typeof value) return value;
|
|
20
|
+
if (0 === value || 1 === value) return Boolean(value);
|
|
21
|
+
return value;
|
|
22
|
+
}),
|
|
23
|
+
object: (field)=>getYupObjectShape(field.extra.fields, yupTypeMap),
|
|
24
|
+
rate: (field)=>{
|
|
25
|
+
const min = field?.min ? field.min : 0;
|
|
26
|
+
const max = field?.max ? field.max : 100;
|
|
27
|
+
return number().transform((v, o)=>'' === o ? null : v).nullable().notRequired().integer({
|
|
28
|
+
key: 'form.error.positive_integer_number'
|
|
29
|
+
}).min(min, {
|
|
30
|
+
key: 'form.error.rate.rate_percent',
|
|
31
|
+
context: {
|
|
32
|
+
min: min,
|
|
33
|
+
max: max
|
|
34
|
+
}
|
|
35
|
+
}).max(max, {
|
|
36
|
+
key: 'form.error.rate.rate_percent',
|
|
37
|
+
context: {
|
|
38
|
+
min: min,
|
|
39
|
+
max: max
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
},
|
|
43
|
+
array: (field)=>{
|
|
44
|
+
if ('object' == typeof field.extra.of) {
|
|
45
|
+
if (field.required) field.extra.min = 1;
|
|
46
|
+
let arrayValidator = array().nullable().of(yupTypeMap[field.extra.of.type](field.extra.of));
|
|
47
|
+
if (field.extra.length) arrayValidator = arrayValidator.length(field.extra.length, {
|
|
48
|
+
key: 'form.error.array.length',
|
|
49
|
+
context: {
|
|
50
|
+
length: field.extra.length
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
if (field.extra.min) arrayValidator = arrayValidator.min(field.extra.min, {
|
|
54
|
+
key: 'form.error.array.min',
|
|
55
|
+
context: {
|
|
56
|
+
min: field.extra.min,
|
|
57
|
+
max: field.extra.max || void 0
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
if (field.extra.max) arrayValidator = arrayValidator.max(field.extra.max, {
|
|
61
|
+
key: 'form.error.array.max',
|
|
62
|
+
context: {
|
|
63
|
+
min: field.extra.min || void 0,
|
|
64
|
+
max: field.extra.max
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
return arrayValidator;
|
|
60
68
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
if (!value.length || value.length === 0) {
|
|
100
|
-
return null;
|
|
101
|
-
}
|
|
102
|
-
return value;
|
|
103
|
-
}).nullable().test(FILE_MAX_SIZE_VALIDATOR(field)).test(IMAGE_DIMENSION_VALIDATOR(field));
|
|
104
|
-
},
|
|
105
|
-
postal_code: (field) => field.trim ? yup.string().trim().test(POSTALCODE_VALIDATOR(field)) : yup.string().test(POSTALCODE_VALIDATOR(field)),
|
|
106
|
-
mobile_phone: (field) => field.trim ? yup.string().trim().test(MOBILE_PHONE_VALIDATOR) : yup.string().test(MOBILE_PHONE_VALIDATOR),
|
|
107
|
-
phone_number: (field) => field.trim ? yup.string().trim().test(PHONE_NUMBER_VALIDATOR(field)) : yup.string().test(PHONE_NUMBER_VALIDATOR(field)),
|
|
108
|
-
"choice:multiple": () => yup.array().of(yup.string()).nullable(),
|
|
109
|
-
"choice:single": () => yup.string().nullable(),
|
|
110
|
-
date: (field) => {
|
|
111
|
-
let schema = yup.string().nullable();
|
|
112
|
-
if (field?.extra?.min) {
|
|
113
|
-
schema = schema.test(LATER_THAN_VALIDATOR(field));
|
|
114
|
-
}
|
|
115
|
-
if (field?.extra?.max) {
|
|
116
|
-
schema = schema.test(EARLIER_THAN_VALIDATOR(field));
|
|
117
|
-
} else {
|
|
118
|
-
schema = schema.test(DATE_VALIDATOR);
|
|
119
|
-
}
|
|
120
|
-
return schema;
|
|
121
|
-
},
|
|
122
|
-
datetime: (field) => {
|
|
123
|
-
if (field?.extra?.min) {
|
|
124
|
-
return yup.string().test(LATER_THAN_DATETIME_VALIDATOR(field));
|
|
125
|
-
}
|
|
126
|
-
if (field?.extra?.max) {
|
|
127
|
-
return yup.string().test(EARLIER_THAN_DATETIME_VALIDATOR(field));
|
|
128
|
-
}
|
|
129
|
-
return yup.string().test(DATETIME_VALIDATOR);
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
return yupTypeMap;
|
|
69
|
+
if ('string' == typeof field.extra.of) return array().of(yupTypeMap[field.extra.of]());
|
|
70
|
+
return array().of(string());
|
|
71
|
+
},
|
|
72
|
+
number: ()=>mixed().transform((_, val)=>'' !== val ? Number(val) : void 0).test(NUMBER_VALIDATOR()),
|
|
73
|
+
int: ()=>mixed().transform((_, val)=>'' !== val ? Number(val) : void 0).test(NUMBER_VALIDATOR()).test(INT_VALIDATOR()),
|
|
74
|
+
email: (field)=>field.trim ? string().trim().test(EMAIL_VALIDATOR) : string().test(EMAIL_VALIDATOR),
|
|
75
|
+
afm: (field)=>field.trim ? string().trim().test(AFM_VALIDATOR) : string().test(AFM_VALIDATOR),
|
|
76
|
+
amka: (field)=>field.trim ? string().trim().test(AMKA_VALIDATOR) : string().test(AMKA_VALIDATOR),
|
|
77
|
+
uuid4: (field)=>field.trim ? string().trim().test(UUID4_VALIDATOR) : string().test(UUID4_VALIDATOR),
|
|
78
|
+
iban: (field)=>field.trim ? string().trim().test(IBAN_VALIDATOR(field)) : string().trim().test(IBAN_VALIDATOR(field)),
|
|
79
|
+
otp: (field)=>string().trim().test(OTP_VALIDATOR(field)),
|
|
80
|
+
text: (field)=>{
|
|
81
|
+
if (field?.extra?.limit?.max || !!field?.extra?.limit?.min) return field.trim ? string().trim().test(TEXT_LIMIT_VALIDATOR(field)) : string().test(TEXT_LIMIT_VALIDATOR(field));
|
|
82
|
+
return field.trim ? string().trim() : string();
|
|
83
|
+
},
|
|
84
|
+
image: (field)=>mixed().transform((value)=>{
|
|
85
|
+
if (!value.length || 0 === value.length) return null;
|
|
86
|
+
return value;
|
|
87
|
+
}).nullable().test(FILE_MAX_SIZE_VALIDATOR(field)).test(IMAGE_DIMENSION_VALIDATOR(field)),
|
|
88
|
+
postal_code: (field)=>field.trim ? string().trim().test(POSTALCODE_VALIDATOR(field)) : string().test(POSTALCODE_VALIDATOR(field)),
|
|
89
|
+
mobile_phone: (field)=>field.trim ? string().trim().test(MOBILE_PHONE_VALIDATOR) : string().test(MOBILE_PHONE_VALIDATOR),
|
|
90
|
+
phone_number: (field)=>field.trim ? string().trim().test(PHONE_NUMBER_VALIDATOR(field)) : string().test(PHONE_NUMBER_VALIDATOR(field)),
|
|
91
|
+
'choice:multiple': ()=>array().of(string()).nullable(),
|
|
92
|
+
'choice:single': ()=>string().nullable(),
|
|
93
|
+
date: (field)=>{
|
|
94
|
+
let schema = string().nullable();
|
|
95
|
+
if (field?.extra?.min) schema = schema.test(LATER_THAN_VALIDATOR(field));
|
|
96
|
+
schema = field?.extra?.max ? schema.test(EARLIER_THAN_VALIDATOR(field)) : schema.test(DATE_VALIDATOR);
|
|
97
|
+
return schema;
|
|
98
|
+
},
|
|
99
|
+
datetime: (field)=>{
|
|
100
|
+
if (field?.extra?.min) return string().test(LATER_THAN_DATETIME_VALIDATOR(field));
|
|
101
|
+
if (field?.extra?.max) return string().test(EARLIER_THAN_DATETIME_VALIDATOR(field));
|
|
102
|
+
return string().test(DATETIME_VALIDATOR);
|
|
103
|
+
},
|
|
104
|
+
...validatorRegistry
|
|
105
|
+
};
|
|
106
|
+
return yupTypeMap;
|
|
133
107
|
};
|
|
134
108
|
function useValidationSchema(fields, validatorRegistry) {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
109
|
+
return useMemo(()=>{
|
|
110
|
+
const yupTypeMap = getYUPTypeMap(validatorRegistry);
|
|
111
|
+
return getYupObjectShape(fields, yupTypeMap, validatorRegistry);
|
|
112
|
+
}, [
|
|
113
|
+
fields,
|
|
114
|
+
validatorRegistry
|
|
115
|
+
]);
|
|
139
116
|
}
|
|
140
|
-
export {
|
|
141
|
-
getYUPTypeMap,
|
|
142
|
-
useValidationSchema
|
|
143
|
-
};
|
|
144
|
-
//# sourceMappingURL=index.js.map
|
|
117
|
+
export { getYUPTypeMap, useValidationSchema };
|
package/validators/types.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import * as yup from 'yup';
|
|
1
|
+
import type * as yup from 'yup';
|
|
2
2
|
export type ValidatorSchema = yup.TestConfig;
|
|
File without changes
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
function validateAFM(afm) {
|
|
2
|
+
if (9 !== afm.length) return false;
|
|
3
|
+
if (!/^\d+$/.test(afm)) return false;
|
|
4
|
+
if (afm === '0'.repeat(9)) return false;
|
|
5
|
+
const sum = afm.substring(0, 8).split('').reduce((s, v, i)=>s + (parseInt(v) << 8 - i), 0);
|
|
6
|
+
const calc = sum % 11;
|
|
7
|
+
const d9 = parseInt(afm[8]);
|
|
8
|
+
const valid = calc % 10 === d9;
|
|
9
|
+
return valid;
|
|
10
|
+
}
|
|
11
|
+
const AFM_VALIDATOR = {
|
|
12
|
+
name: 'afm-validator',
|
|
13
|
+
message: 'form.error.afm',
|
|
14
|
+
test: (value)=>{
|
|
15
|
+
if (value) return validateAFM(value);
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
export { AFM_VALIDATOR, validateAFM };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
function digitSum(number) {
|
|
2
|
+
const sum = number > 9 ? 1 : 0;
|
|
3
|
+
return sum + number % 10;
|
|
4
|
+
}
|
|
5
|
+
function validateAMKA(amka) {
|
|
6
|
+
amka = String(amka);
|
|
7
|
+
const checkDigitIndex = amka.length - 1;
|
|
8
|
+
let sum = 0;
|
|
9
|
+
amka.substring(0, checkDigitIndex).split('').reverse().forEach(function(value, index) {
|
|
10
|
+
const weight = (index + 1) % 2 + 1;
|
|
11
|
+
sum += digitSum(parseInt(value, 10) * weight);
|
|
12
|
+
});
|
|
13
|
+
const sumMod10 = sum % 10;
|
|
14
|
+
if (0 === sumMod10) return '0' === amka.substring(checkDigitIndex);
|
|
15
|
+
return amka.substring(checkDigitIndex) === 10 - sumMod10 + '';
|
|
16
|
+
}
|
|
17
|
+
const AMKA_VALIDATOR = {
|
|
18
|
+
name: 'amka-validator',
|
|
19
|
+
message: 'form.error.amka',
|
|
20
|
+
test: (value)=>{
|
|
21
|
+
if (!value) return true;
|
|
22
|
+
const AMKA_REGEX = /^[0-9]{11}$/;
|
|
23
|
+
if (!AMKA_REGEX.test(value) || '00000000000' === value) return false;
|
|
24
|
+
return validateAMKA(value);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
export { AMKA_VALIDATOR, validateAMKA };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { FieldSpec } from '
|
|
2
|
-
import { ValidatorSchema } from '
|
|
1
|
+
import type { FieldSpec } from '../../types.js';
|
|
2
|
+
import type { ValidatorSchema } from '../types.js';
|
|
3
3
|
export declare const LATER_THAN_VALIDATOR: (field: FieldSpec) => ValidatorSchema;
|
|
4
4
|
export declare const EARLIER_THAN_VALIDATOR: (field: FieldSpec) => ValidatorSchema;
|
|
5
5
|
export declare const DATE_VALIDATOR: {
|
|
6
6
|
name: string;
|
|
7
|
-
message: (v: any) => string;
|
|
7
|
+
message: (v: any) => string | object;
|
|
8
8
|
test: (value: string) => any;
|
|
9
9
|
};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import dayjs from "dayjs";
|
|
2
|
+
import customParseFormat from "dayjs/plugin/customParseFormat.js";
|
|
3
|
+
dayjs.extend(customParseFormat);
|
|
4
|
+
const VALID_DATE_FORMATS = [
|
|
5
|
+
'DD/MM/YYYY'
|
|
6
|
+
];
|
|
7
|
+
const DATE_CACHE = {};
|
|
8
|
+
const onlyNumbersRegex = /^\d+$/;
|
|
9
|
+
const getDate = (v)=>DATE_CACHE[v] ? DATE_CACHE[v] : dayjs(v, VALID_DATE_FORMATS, true);
|
|
10
|
+
const getDaysInMonth = (month, year)=>dayjs(`${year}-${month}-01`).daysInMonth();
|
|
11
|
+
const checkPartialDate = (value)=>{
|
|
12
|
+
const [day, month, year] = value.split('/');
|
|
13
|
+
if (day && !month && !year) return 'form.error.date.invalid_month_year';
|
|
14
|
+
if (!day && month && !year) return 'form.error.date.invalid_day_year';
|
|
15
|
+
if (!day && !month && year) return 'form.error.date.invalid_day_month';
|
|
16
|
+
if (day && month && !year) return 'form.error.date.invalid_year';
|
|
17
|
+
if (day && !month && year) return 'form.error.date.invalid_month';
|
|
18
|
+
if (!day && month && year) return 'form.error.date.invalid_day';
|
|
19
|
+
if (day && month) {
|
|
20
|
+
const dayNum = parseInt(day);
|
|
21
|
+
const monthNum = parseInt(month);
|
|
22
|
+
const validYear = onlyNumbersRegex.test(year) ? year : void 0;
|
|
23
|
+
if (!validYear || year.length < 4) return 'form.error.date.invalid';
|
|
24
|
+
const yearNum = parseInt(validYear);
|
|
25
|
+
const maxDay = getDaysInMonth(monthNum, yearNum);
|
|
26
|
+
if (dayNum < 1 || dayNum > maxDay) return {
|
|
27
|
+
key: 'form.error.date.invalid_day_range',
|
|
28
|
+
context: {
|
|
29
|
+
maxDay: maxDay
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
if (monthNum < 1 || monthNum > 12) return 'form.error.datetime.invalid_month_range';
|
|
33
|
+
}
|
|
34
|
+
return 'form.error.date.invalid';
|
|
35
|
+
};
|
|
36
|
+
const LATER_THAN_VALIDATOR = (field)=>{
|
|
37
|
+
let minDate;
|
|
38
|
+
const params = field.extra || {};
|
|
39
|
+
if ('now' === params.min) {
|
|
40
|
+
const today = new Date();
|
|
41
|
+
minDate = new Date(today);
|
|
42
|
+
} else minDate = getDate(params.min).toDate();
|
|
43
|
+
const minPreviousDate = new Date(minDate);
|
|
44
|
+
minPreviousDate.setDate(minDate.getDate() - 1);
|
|
45
|
+
return {
|
|
46
|
+
name: 'later-than',
|
|
47
|
+
message: {
|
|
48
|
+
key: 'form.error.date.later_than',
|
|
49
|
+
context: {
|
|
50
|
+
minDate: minPreviousDate.toLocaleDateString()
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
test: function(value) {
|
|
54
|
+
if (!value) return true;
|
|
55
|
+
const date = getDate(value);
|
|
56
|
+
const isValid = +date.toDate() > +minDate;
|
|
57
|
+
return isValid;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
const EARLIER_THAN_VALIDATOR = (field)=>{
|
|
62
|
+
let maxDate;
|
|
63
|
+
const params = field.extra || {};
|
|
64
|
+
if ('now' === params.max) {
|
|
65
|
+
const today = new Date();
|
|
66
|
+
maxDate = new Date(today);
|
|
67
|
+
} else maxDate = getDate(params.max).toDate();
|
|
68
|
+
const maxNextDate = new Date(maxDate);
|
|
69
|
+
maxNextDate.setDate(maxDate.getDate() + 1);
|
|
70
|
+
return {
|
|
71
|
+
name: 'earlier-than',
|
|
72
|
+
message: {
|
|
73
|
+
key: 'form.error.date.earlier_than',
|
|
74
|
+
context: {
|
|
75
|
+
maxDate: maxNextDate.toLocaleDateString()
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
test: function(value) {
|
|
79
|
+
if (!value) return true;
|
|
80
|
+
const date = getDate(value);
|
|
81
|
+
const isValid = +date.toDate() < +maxDate;
|
|
82
|
+
return isValid;
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
const DATE_VALIDATOR = {
|
|
87
|
+
name: 'date-validator',
|
|
88
|
+
message: (v)=>checkPartialDate(v.value),
|
|
89
|
+
test: function(value) {
|
|
90
|
+
if (!value) return true;
|
|
91
|
+
const date = getDate(value);
|
|
92
|
+
return date.isValid();
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
export { DATE_VALIDATOR, EARLIER_THAN_VALIDATOR, LATER_THAN_VALIDATOR };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { FieldSpec } from '
|
|
2
|
-
import { ValidatorSchema } from '
|
|
1
|
+
import type { FieldSpec } from '../../types.js';
|
|
2
|
+
import type { ValidatorSchema } from '../types.js';
|
|
3
3
|
export declare const LATER_THAN_DATETIME_VALIDATOR: (field: FieldSpec) => ValidatorSchema;
|
|
4
4
|
export declare const EARLIER_THAN_DATETIME_VALIDATOR: (field: FieldSpec) => ValidatorSchema;
|
|
5
5
|
export declare const DATETIME_VALIDATOR: {
|
|
6
6
|
name: string;
|
|
7
|
-
message: (v: any) => string;
|
|
7
|
+
message: (v: any) => string | object;
|
|
8
8
|
test: (value: string) => any;
|
|
9
9
|
};
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import dayjs from "dayjs";
|
|
2
|
+
import customParseFormat from "dayjs/plugin/customParseFormat.js";
|
|
3
|
+
dayjs.extend(customParseFormat);
|
|
4
|
+
const VALID_DATETIME_FORMATS = [
|
|
5
|
+
'DD/MM/YYYY HH:mm'
|
|
6
|
+
];
|
|
7
|
+
const DATETIME_CACHE = {};
|
|
8
|
+
const onlyNumbersRegex = /^\d+$/;
|
|
9
|
+
const getDateTime = (v)=>DATETIME_CACHE[v] ? DATETIME_CACHE[v] : dayjs(v, VALID_DATETIME_FORMATS, true);
|
|
10
|
+
const getDaysInMonth = (month, year)=>dayjs(`${year}-${month}-01`).daysInMonth();
|
|
11
|
+
const checkPartialDateTime = (value)=>{
|
|
12
|
+
const [datePart, timePart] = value.split(' ');
|
|
13
|
+
const [day, month, year] = datePart?.split('/') ?? [];
|
|
14
|
+
const [hours, minutes] = timePart?.split(':') ?? [];
|
|
15
|
+
const hasDay = Boolean(day);
|
|
16
|
+
const hasMonth = Boolean(month);
|
|
17
|
+
const hasYear = Boolean(year);
|
|
18
|
+
const hasHours = Boolean(hours);
|
|
19
|
+
const hasMinutes = Boolean(minutes);
|
|
20
|
+
if (hasDay && !hasMonth && !hasYear && !hasHours && !hasMinutes) return 'form.error.datetime.invalid_month_year_hours_minutes';
|
|
21
|
+
if (!hasDay && hasMonth && !hasYear && !hasHours && !hasMinutes) return 'form.error.datetime.invalid_day_year_hours_minutes';
|
|
22
|
+
if (!hasDay && !hasMonth && hasYear && !hasHours && !hasMinutes) return 'form.error.datetime.invalid_day_month_hours_minutes';
|
|
23
|
+
if (hasDay && hasMonth && !hasYear && !hasHours && !hasMinutes) return 'form.error.datetime.invalid_year_hours_minutes';
|
|
24
|
+
if (hasDay && !hasMonth && hasYear && !hasHours && !hasMinutes) return 'form.error.datetime.invalid_month_hours_minutes';
|
|
25
|
+
if (!hasDay && hasMonth && hasYear && !hasHours && !hasMinutes) return 'form.error.datetime.invalid_day_hours_minutes';
|
|
26
|
+
if (hasDay && hasMonth && hasYear && !hasHours && !hasMinutes) return 'form.error.datetime.invalid__hours_minutes';
|
|
27
|
+
if (hasDay && hasMonth && hasYear && hasHours && !hasMinutes) return 'form.error.datetime.invalid_minutes';
|
|
28
|
+
if (hasDay && hasMonth && hasYear && !hasHours && hasMinutes) return 'form.error.datetime.invalid_hours';
|
|
29
|
+
if (hasDay && !hasMonth && !hasYear && hasHours && !hasMinutes) return 'form.error.datetime.invalid_month_year_minutes';
|
|
30
|
+
if (hasDay && !hasMonth && !hasYear && !hasHours && hasMinutes) return 'form.error.datetime.invalid_month_year_hours';
|
|
31
|
+
if (hasDay && !hasMonth && !hasYear && hasHours && hasMinutes) return 'form.error.datetime.invalid_month_year';
|
|
32
|
+
if (!hasDay && hasMonth && !hasYear && hasHours && !hasMinutes) return 'form.error.datetime.invalid_day_year_minutes';
|
|
33
|
+
if (!hasDay && hasMonth && !hasYear && !hasHours && hasMinutes) return 'form.error.datetime.invalid_day_year_hours';
|
|
34
|
+
if (!hasDay && hasMonth && !hasYear && hasHours && hasMinutes) return 'form.error.datetime.invalid_day_year';
|
|
35
|
+
if (!hasDay && !hasMonth && hasYear && hasHours && !hasMinutes) return 'form.error.datetime.invalid_day_month_minutes';
|
|
36
|
+
if (!hasDay && !hasMonth && hasYear && !hasHours && hasMinutes) return 'form.error.datetime.invalid_day_month_hours';
|
|
37
|
+
if (!hasDay && !hasMonth && hasYear && hasHours && hasMinutes) return 'form.error.datetime.invalid_day_month';
|
|
38
|
+
if (!hasDay && !hasMonth && !hasYear && hasHours && hasMinutes) return 'form.error.datetime.invalid_day_month_year';
|
|
39
|
+
if (!hasDay && !hasMonth && !hasYear && !hasHours && hasMinutes) return 'form.error.datetime.invalid_day_month_year_hours';
|
|
40
|
+
if (hasDay && hasMonth && !hasYear && hasHours && !hasMinutes) return 'form.error.datetime.invalid_year_minutes';
|
|
41
|
+
if (hasDay && hasMonth && !hasYear && !hasHours && hasMinutes) return 'form.error.datetime.invalid_year_hours';
|
|
42
|
+
if (hasDay && hasMonth && !hasYear && hasHours && hasMinutes) return 'form.error.datetime.invalid_year';
|
|
43
|
+
if (hasDay && !hasMonth && hasYear && hasHours && !hasMinutes) return 'form.error.datetime.invalid_month_minutes';
|
|
44
|
+
if (hasDay && !hasMonth && hasYear && !hasHours && hasMinutes) return 'form.error.datetime.invalid_month_hours';
|
|
45
|
+
if (hasDay && !hasMonth && hasYear && hasHours && hasMinutes) return 'form.error.datetime.invalid_month';
|
|
46
|
+
if (!hasDay && hasMonth && hasYear && hasHours && !hasMinutes) return 'form.error.datetime.invalid_day_minutes';
|
|
47
|
+
if (!hasDay && hasMonth && hasYear && !hasHours && hasMinutes) return 'form.error.datetime.invalid_day_hours';
|
|
48
|
+
if (!hasDay && hasMonth && hasYear && hasHours && hasMinutes) return 'form.error.datetime.invalid_day';
|
|
49
|
+
if (!hasDay && !hasMonth && !hasYear && hasHours && !hasMinutes) return 'form.error.datetime.invalid_day_month_year_minutes';
|
|
50
|
+
if (hasDay && hasMonth && hasYear && !hasHours && !hasMinutes) return 'form.error.datetime.invalid_hours_minutes';
|
|
51
|
+
if (day && month) {
|
|
52
|
+
const dayNum = parseInt(day);
|
|
53
|
+
const monthNum = parseInt(month);
|
|
54
|
+
const validYear = onlyNumbersRegex.test(year) ? year : void 0;
|
|
55
|
+
if (!validYear || year.length < 4) return 'form.error.datetime.invalid';
|
|
56
|
+
const yearNum = parseInt(validYear);
|
|
57
|
+
const maxDay = getDaysInMonth(monthNum, yearNum);
|
|
58
|
+
if (dayNum < 1 || dayNum > maxDay) return {
|
|
59
|
+
key: 'form.error.datetime.invalid_day_range',
|
|
60
|
+
context: {
|
|
61
|
+
maxDay: maxDay
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
if (monthNum < 1 || monthNum > 12) return 'form.error.datetime.invalid_month_range';
|
|
65
|
+
}
|
|
66
|
+
if (hours && minutes) {
|
|
67
|
+
const hoursNum = parseInt(hours);
|
|
68
|
+
const minutesNum = parseInt(minutes);
|
|
69
|
+
if (hoursNum < 0 || hoursNum > 23) return 'form.error.datetime.invalid_hours_range';
|
|
70
|
+
if (minutesNum < 0 || minutesNum > 59) return 'form.error.datetime.invalid_minutes_range';
|
|
71
|
+
}
|
|
72
|
+
return 'form.error.datetime.invalid';
|
|
73
|
+
};
|
|
74
|
+
const LATER_THAN_DATETIME_VALIDATOR = (field)=>{
|
|
75
|
+
let minDateTime;
|
|
76
|
+
const params = field.extra || {};
|
|
77
|
+
minDateTime = 'now' === params.min ? dayjs() : getDateTime(params.min);
|
|
78
|
+
return {
|
|
79
|
+
name: 'later-than-datetime',
|
|
80
|
+
message: {
|
|
81
|
+
key: 'form.error.datetime.later_than',
|
|
82
|
+
context: {
|
|
83
|
+
minDateTime: minDateTime.format('DD/MM/YYYY HH:mm')
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
test: function(value) {
|
|
87
|
+
if (!value) return true;
|
|
88
|
+
const datetime = getDateTime(value);
|
|
89
|
+
return datetime.isValid() && datetime.isAfter(minDateTime);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
const EARLIER_THAN_DATETIME_VALIDATOR = (field)=>{
|
|
94
|
+
let maxDateTime;
|
|
95
|
+
const params = field.extra || {};
|
|
96
|
+
maxDateTime = 'now' === params.max ? dayjs() : getDateTime(params.max);
|
|
97
|
+
return {
|
|
98
|
+
name: 'earlier-than-datetime',
|
|
99
|
+
message: {
|
|
100
|
+
key: 'form.error.datetime.earlier_than',
|
|
101
|
+
context: {
|
|
102
|
+
maxDateTime: maxDateTime.format('DD/MM/YYYY HH:mm')
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
test: function(value) {
|
|
106
|
+
if (!value) return true;
|
|
107
|
+
const datetime = getDateTime(value);
|
|
108
|
+
return datetime.isValid() && datetime.isBefore(maxDateTime);
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
const DATETIME_VALIDATOR = {
|
|
113
|
+
name: 'datetime-validator',
|
|
114
|
+
message: (v)=>checkPartialDateTime(v.value),
|
|
115
|
+
test: function(value) {
|
|
116
|
+
if (!value) return true;
|
|
117
|
+
const datetime = getDateTime(value);
|
|
118
|
+
return datetime.isValid();
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
export { DATETIME_VALIDATOR, EARLIER_THAN_DATETIME_VALIDATOR, LATER_THAN_DATETIME_VALIDATOR };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
const EMAIL_VALIDATOR = {
|
|
2
|
+
name: 'email-validator',
|
|
3
|
+
message: 'form.error.email',
|
|
4
|
+
test: (value)=>{
|
|
5
|
+
if (!value) return true;
|
|
6
|
+
const EMAIL_REGEX = /^(([^<>()\[\]\\.,;:\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,}))$/;
|
|
7
|
+
return EMAIL_REGEX.test(value);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
export { EMAIL_VALIDATOR };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { FieldSpec } from '
|
|
2
|
-
import { ValidatorSchema } from '
|
|
1
|
+
import type { FieldSpec } from '../../types.js';
|
|
2
|
+
import type { ValidatorSchema } from '../types.js';
|
|
3
3
|
export declare const FILE_MAX_SIZE_VALIDATOR: (field: FieldSpec) => ValidatorSchema;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const DEFAULT_FILE_MAX_SIZE = 10000000;
|
|
2
|
+
const FILE_MAX_SIZE_VALIDATOR = (field)=>{
|
|
3
|
+
const maxSizeInBytes = field?.extra?.limit?.maxSize || DEFAULT_FILE_MAX_SIZE;
|
|
4
|
+
let maxSizeTransformed = maxSizeInBytes / 1048576;
|
|
5
|
+
let maxSizeText = 'MB';
|
|
6
|
+
if (0 === Math.round(maxSizeTransformed)) {
|
|
7
|
+
maxSizeTransformed = Math.round(maxSizeInBytes / 1024);
|
|
8
|
+
maxSizeText = 'KB';
|
|
9
|
+
}
|
|
10
|
+
if (0 === Math.round(maxSizeTransformed)) {
|
|
11
|
+
maxSizeTransformed = maxSizeInBytes;
|
|
12
|
+
maxSizeText = 'Bytes';
|
|
13
|
+
}
|
|
14
|
+
return {
|
|
15
|
+
name: 'file-max-size-validator',
|
|
16
|
+
message: {
|
|
17
|
+
key: 'file' === field.type ? 'form.error.file_size' : 'form.error.image_size',
|
|
18
|
+
context: {
|
|
19
|
+
maxSize: `${maxSizeTransformed} ${maxSizeText}`
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
test: (value)=>{
|
|
23
|
+
if (value) for (const file of Array.from(value)){
|
|
24
|
+
const maxSize = field?.extra?.limit?.maxSize || DEFAULT_FILE_MAX_SIZE;
|
|
25
|
+
if (file.size > maxSize) return false;
|
|
26
|
+
}
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
export { FILE_MAX_SIZE_VALIDATOR };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FieldSpec } from '
|
|
2
|
-
import { ValidatorSchema } from '
|
|
1
|
+
import type { FieldSpec } from '../../types.js';
|
|
2
|
+
import type { ValidatorSchema } from '../types.js';
|
|
3
3
|
export declare function validateIban(value: string, countryCode: string): boolean;
|
|
4
4
|
export declare const IBAN_VALIDATOR: (field: FieldSpec) => ValidatorSchema;
|