@digigov/form 2.0.0-a402a664 → 2.0.0-aa380ec7
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 +3 -3
- package/Field/ErrorGroup.js.map +1 -1
- package/Field/FieldBase/index.js +1 -2
- package/Field/FieldBase.d.ts +1 -1
- package/Field/FieldBase.js.map +2 -2
- package/Field/FieldBaseContainer/index.js +36 -19
- package/Field/FieldBaseContainer.d.ts +2 -2
- package/Field/FieldBaseContainer.js.map +2 -2
- package/Field/FieldConditional.d.ts +1 -1
- package/Field/FieldConditional.js.map +1 -1
- package/Field/index.d.ts +1 -1
- package/Field/index.js +16 -26
- package/Field/index.js.map +2 -2
- package/Field/types.d.ts +11 -10
- 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 +4 -2
- package/Field/utils/useField.d.ts +1 -1
- package/Field/utils/useField.js.map +2 -2
- package/FieldArray/BaseFieldArray/index.js +76 -0
- package/{inputs/inputsScenarios → FieldArray/BaseFieldArray}/package.json +1 -1
- package/FieldArray/BaseFieldArray.d.ts +5 -0
- package/FieldArray/BaseFieldArray.js.map +7 -0
- package/FieldArray/FieldArray.stories.d.ts +1 -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/FieldArray/FormDialog/ArrayDisplay/package.json +6 -0
- package/FieldArray/FormDialog/ArrayEditModal/index.js +156 -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 +181 -347
- package/FieldArray/FormDialog/index.js.map +7 -0
- package/FieldArray/__stories__/CardsWithError.d.ts +15 -0
- package/FieldArray/index.d.ts +4 -2
- package/FieldArray/index.js +34 -56
- package/FieldArray/index.js.map +2 -2
- package/FieldObject/index.d.ts +4 -4
- package/FieldObject/index.js +5 -12
- 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/index.d.ts +1 -1
- package/FormBuilder/index.js +155 -131
- package/FormBuilder/index.js.map +2 -2
- package/FormContext.d.ts +2 -2
- package/FormContext.js.map +2 -2
- package/MultiplicityField/add-objects/index.js +10 -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.map +2 -2
- package/MultiplicityField/types.d.ts +2 -2
- package/Questions/Questions.d.ts +1 -1
- package/Questions/Questions.js.map +1 -1
- 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/getNextStep.d.ts +1 -1
- package/Questions/getNextStep.js.map +1 -1
- package/Questions/types.d.ts +1 -1
- package/cjs/Field/ErrorGroup.js.map +1 -1
- package/cjs/Field/FieldBase/index.js +1 -2
- package/cjs/Field/FieldBase.js.map +2 -2
- package/cjs/Field/FieldBaseContainer/index.js +36 -19
- package/cjs/Field/FieldBaseContainer.js.map +2 -2
- package/cjs/Field/FieldConditional.js.map +1 -1
- package/cjs/Field/index.js +16 -23
- 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 +4 -2
- 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 +184 -0
- package/cjs/FieldArray/FormDialog/ArrayEditModal.js.map +7 -0
- package/cjs/FieldArray/FormDialog/index.js +172 -330
- package/cjs/FieldArray/FormDialog/index.js.map +7 -0
- package/cjs/FieldArray/index.js +33 -55
- package/cjs/FieldArray/index.js.map +3 -3
- package/cjs/FieldObject/index.js +5 -9
- 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 +156 -132
- package/cjs/FormBuilder/index.js.map +3 -3
- package/cjs/FormContext.js.map +2 -2
- package/cjs/MultiplicityField/add-objects/index.js +9 -13
- package/cjs/MultiplicityField/add-objects.js.map +2 -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 -63
- package/cjs/inputs/Checkboxes/index.js.map +2 -2
- package/cjs/inputs/DateInput/index.js +36 -16
- package/cjs/inputs/DateInput/index.js.map +2 -2
- package/cjs/inputs/DateTimeInput/index.js +64 -38
- package/cjs/inputs/DateTimeInput/index.js.map +2 -2
- package/cjs/inputs/FileInput/index.js +42 -24
- package/cjs/inputs/FileInput/index.js.map +2 -2
- package/cjs/inputs/ImageInput/index.js.map +1 -1
- package/cjs/inputs/Input/index.js +54 -56
- 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 -31
- 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.map +1 -1
- package/cjs/{Field/utils → inputs/registry}/index.js +4 -4
- package/cjs/inputs/registry.js.map +7 -0
- package/cjs/{lazy/index.js → lazy.js} +14 -11
- package/cjs/lazy.js.map +2 -2
- package/cjs/{registry/index.js → registry.js} +33 -19
- package/cjs/registry.js.map +2 -2
- package/cjs/types.js.map +1 -1
- package/cjs/utils.js.map +2 -2
- package/cjs/validators/index.js +6 -3
- package/cjs/validators/index.js.map +2 -2
- package/cjs/validators/types.js.map +1 -1
- 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.js.map +1 -1
- package/cjs/validators/utils/iban.js.map +1 -1
- package/cjs/validators/utils/image.js.map +1 -1
- package/cjs/validators/utils/index.js.map +1 -1
- package/cjs/validators/utils/int.js.map +1 -1
- package/cjs/validators/utils/number.js.map +1 -1
- 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/index.d.ts +3 -3
- package/inputs/AutoCompleteInput/index.js +1 -3
- package/inputs/AutoCompleteInput/index.js.map +2 -2
- package/inputs/Checkboxes/index.d.ts +3 -3
- package/inputs/Checkboxes/index.js +67 -63
- package/inputs/Checkboxes/index.js.map +2 -2
- package/inputs/DateInput/DateInput.stories.d.ts +4 -0
- 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 +37 -17
- package/inputs/DateInput/index.js.map +2 -2
- package/inputs/DateTimeInput/DateTimeInput.stories.d.ts +8 -3
- 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 +65 -39
- package/inputs/DateTimeInput/index.js.map +2 -2
- package/inputs/FileInput/index.d.ts +8 -4
- package/inputs/FileInput/index.js +44 -29
- package/inputs/FileInput/index.js.map +2 -2
- package/inputs/ImageInput/index.d.ts +2 -2
- package/inputs/ImageInput/index.js.map +1 -1
- package/inputs/Input/index.d.ts +2 -2
- package/inputs/Input/index.js +54 -56
- package/inputs/Input/index.js.map +2 -2
- package/inputs/Label/index.d.ts +1 -1
- package/inputs/Label/index.js.map +1 -1
- package/inputs/OtpInput/index.d.ts +1 -5
- package/inputs/OtpInput/index.js +36 -31
- package/inputs/OtpInput/index.js.map +2 -2
- 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/index.d.ts +2 -2
- package/inputs/Select/index.js.map +1 -1
- package/{Field/utils → inputs/registry}/index.js +1 -1
- 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 +14 -11
- package/package.json +4 -4
- package/registry/index.js +33 -19
- package/src/Field/ErrorGroup.tsx +3 -3
- package/src/Field/FieldBase.tsx +2 -3
- package/src/Field/FieldBaseContainer.tsx +68 -51
- package/src/Field/FieldConditional.tsx +1 -1
- package/src/Field/index.tsx +16 -36
- package/src/Field/types.tsx +11 -12
- package/src/Field/utils/evaluateFieldWithConditions.ts +5 -2
- package/src/Field/utils/resolveField.ts +58 -0
- package/src/Field/utils/useField.ts +3 -1
- 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 +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 +242 -0
- package/src/FieldArray/FormDialog/index.tsx +299 -0
- package/src/FieldArray/__stories__/CardsWithError.tsx +124 -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-required.spec.tsx +131 -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 +43 -63
- package/src/FieldObject/index.tsx +9 -17
- package/src/Fieldset/FieldsetWithContext.tsx +1 -1
- package/src/Fieldset/index.tsx +1 -1
- package/src/Fieldset/types.tsx +2 -2
- package/src/FormBuilder/index.tsx +188 -143
- package/src/FormBuilder/scenarios.test.tsx +760 -1
- package/src/FormContext.tsx +3 -2
- package/src/MultiplicityField/add-objects.tsx +12 -21
- package/src/MultiplicityField/index.tsx +3 -2
- package/src/MultiplicityField/types.ts +5 -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/index.tsx +4 -6
- package/src/inputs/Checkboxes/index.tsx +95 -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/index.test.tsx +16 -0
- package/src/inputs/DateInput/index.tsx +49 -18
- 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/index.test.tsx +16 -0
- package/src/inputs/DateTimeInput/index.tsx +77 -40
- package/src/inputs/FileInput/index.tsx +76 -43
- package/src/inputs/ImageInput/index.tsx +2 -2
- package/src/inputs/Input/index.tsx +72 -71
- package/src/inputs/Label/index.tsx +1 -1
- package/src/inputs/OtpInput/index.tsx +43 -34
- package/src/inputs/Radio/index.tsx +29 -21
- package/src/inputs/Select/index.tsx +2 -2
- package/src/{Field/utils/index.ts → inputs/registry.ts} +3 -1
- package/src/lazy.js +14 -11
- package/src/registry.js +33 -19
- package/src/types.tsx +13 -5
- package/src/utils.ts +3 -2
- package/src/validators/index.ts +16 -12
- package/src/validators/types.ts +1 -1
- 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 +2 -2
- package/src/validators/utils/iban.ts +2 -2
- package/src/validators/utils/image.ts +2 -2
- package/src/validators/utils/index.ts +2 -2
- 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 +9 -4
- package/types.js.map +1 -1
- package/utils.d.ts +1 -1
- package/utils.js.map +2 -2
- package/validators/index.d.ts +5 -5
- package/validators/index.js +6 -3
- package/validators/index.js.map +2 -2
- package/validators/types.d.ts +1 -1
- 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.d.ts +2 -2
- package/validators/utils/file.js.map +1 -1
- 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 +2 -2
- package/validators/utils/index.js.map +1 -1
- package/validators/utils/int.d.ts +1 -1
- package/validators/utils/int.js.map +1 -1
- package/validators/utils/number.d.ts +1 -1
- package/validators/utils/number.js.map +1 -1
- 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 -66
- package/FieldArray/FormDialog.js.map +0 -7
- package/FormBuilder/index.test.d.ts +0 -1
- package/FormBuilder/interaction.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/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/index.test.d.ts +0 -1
- package/inputs/Input/index.test.d.ts +0 -1
- 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 -565
- 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/src/validators/index.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { MutableRefObject
|
|
1
|
+
import type { MutableRefObject } from 'react';
|
|
2
|
+
import { useMemo } from 'react';
|
|
2
3
|
import * as yup from 'yup';
|
|
3
|
-
import { AnyObjectSchema, StringSchema } from 'yup';
|
|
4
|
-
import { RequiredArraySchema } from 'yup/lib/array';
|
|
5
|
-
import Lazy from 'yup/lib/Lazy';
|
|
6
|
-
import { MixedSchema } from 'yup/lib/mixed';
|
|
7
|
-
import { TypeOfShape, AssertsShape } from 'yup/lib/object';
|
|
8
|
-
import { AnyObject } from 'yup/lib/types';
|
|
9
|
-
import { FieldSpec } from '@digigov/form/types';
|
|
10
|
-
import { ValidatorSchema } from '@digigov/form/validators/types';
|
|
4
|
+
import type { AnyObjectSchema, StringSchema } from 'yup';
|
|
5
|
+
import type { RequiredArraySchema } from 'yup/lib/array';
|
|
6
|
+
import type Lazy from 'yup/lib/Lazy';
|
|
7
|
+
import type { MixedSchema } from 'yup/lib/mixed';
|
|
8
|
+
import type { TypeOfShape, AssertsShape } from 'yup/lib/object';
|
|
9
|
+
import type { AnyObject } from 'yup/lib/types';
|
|
10
|
+
import type { FieldSpec } from '@digigov/form/types';
|
|
11
|
+
import type { ValidatorSchema } from '@digigov/form/validators/types';
|
|
11
12
|
import {
|
|
12
13
|
getYupObjectShape,
|
|
13
14
|
AFM_VALIDATOR,
|
|
@@ -28,6 +29,7 @@ import {
|
|
|
28
29
|
LATER_THAN_DATETIME_VALIDATOR,
|
|
29
30
|
EARLIER_THAN_DATETIME_VALIDATOR,
|
|
30
31
|
} from '@digigov/form/validators/utils';
|
|
32
|
+
import { EMAIL_VALIDATOR } from '@digigov/form/validators/utils/email';
|
|
31
33
|
import { INT_VALIDATOR } from '@digigov/form/validators/utils/int';
|
|
32
34
|
import { NUMBER_VALIDATOR } from '@digigov/form/validators/utils/number';
|
|
33
35
|
|
|
@@ -103,12 +105,14 @@ export const getYUPTypeMap = (
|
|
|
103
105
|
key: 'form.error.array.min',
|
|
104
106
|
context: {
|
|
105
107
|
min: field.extra.min,
|
|
108
|
+
max: field.extra.max || undefined,
|
|
106
109
|
},
|
|
107
110
|
});
|
|
108
111
|
if (field.extra.max)
|
|
109
112
|
arrayValidator = arrayValidator.max(field.extra.max, {
|
|
110
113
|
key: 'form.error.array.max',
|
|
111
114
|
context: {
|
|
115
|
+
min: field.extra.min || undefined,
|
|
112
116
|
max: field.extra.max,
|
|
113
117
|
},
|
|
114
118
|
});
|
|
@@ -133,8 +137,8 @@ export const getYUPTypeMap = (
|
|
|
133
137
|
.test(INT_VALIDATOR()),
|
|
134
138
|
email: (field): yup.StringSchema =>
|
|
135
139
|
field.trim
|
|
136
|
-
? yup.string().trim().
|
|
137
|
-
: yup.string().
|
|
140
|
+
? yup.string().trim().test(EMAIL_VALIDATOR)
|
|
141
|
+
: yup.string().test(EMAIL_VALIDATOR),
|
|
138
142
|
afm: (field): yup.StringSchema =>
|
|
139
143
|
field.trim
|
|
140
144
|
? yup.string().trim().test(AFM_VALIDATOR)
|
|
@@ -239,5 +243,5 @@ export function useValidationSchema(
|
|
|
239
243
|
return useMemo(() => {
|
|
240
244
|
const yupTypeMap = getYUPTypeMap(validatorRegistry);
|
|
241
245
|
return getYupObjectShape(fields, yupTypeMap, validatorRegistry);
|
|
242
|
-
}, []);
|
|
246
|
+
}, [fields, validatorRegistry]);
|
|
243
247
|
}
|
package/src/validators/types.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;
|
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
import dayjs from 'dayjs';
|
|
2
2
|
import customParseFormat from 'dayjs/plugin/customParseFormat';
|
|
3
|
-
import { FieldSpec } from '@digigov/form/types';
|
|
4
|
-
import { ValidatorSchema } from '@digigov/form/validators/types';
|
|
3
|
+
import type { FieldSpec } from '@digigov/form/types';
|
|
4
|
+
import type { ValidatorSchema } from '@digigov/form/validators/types';
|
|
5
5
|
|
|
6
6
|
dayjs.extend(customParseFormat);
|
|
7
7
|
|
|
8
8
|
const VALID_DATE_FORMATS = ['DD/MM/YYYY'];
|
|
9
9
|
const DATE_CACHE = {};
|
|
10
|
+
const onlyNumbersRegex = /^\d+$/;
|
|
10
11
|
|
|
11
12
|
const getDate = (v: string) => {
|
|
12
13
|
return DATE_CACHE[v] ? DATE_CACHE[v] : dayjs(v, VALID_DATE_FORMATS, true);
|
|
13
14
|
};
|
|
14
15
|
|
|
16
|
+
const getDaysInMonth = (month: number, year: number): number => {
|
|
17
|
+
return dayjs(`${year}-${month}-01`).daysInMonth(); // e.g. 29 for Feb 2024
|
|
18
|
+
};
|
|
19
|
+
|
|
15
20
|
// Function to check partial date completion
|
|
16
21
|
const checkPartialDate = (value: string) => {
|
|
17
|
-
console.log("value.split('/')", value.split('/'));
|
|
18
22
|
const [day, month, year] = value.split('/');
|
|
19
23
|
if (day && !month && !year) {
|
|
20
24
|
return 'form.error.date.invalid_month_year';
|
|
@@ -33,9 +37,29 @@ const checkPartialDate = (value: string) => {
|
|
|
33
37
|
}
|
|
34
38
|
if (!day && month && year) {
|
|
35
39
|
return 'form.error.date.invalid_day';
|
|
36
|
-
} else {
|
|
37
|
-
return 'form.error.date.invalid';
|
|
38
40
|
}
|
|
41
|
+
if (day && month) {
|
|
42
|
+
const dayNum = parseInt(day);
|
|
43
|
+
const monthNum = parseInt(month);
|
|
44
|
+
const validYear = onlyNumbersRegex.test(year) ? year : undefined;
|
|
45
|
+
if (!validYear || year.length < 4) {
|
|
46
|
+
return 'form.error.date.invalid';
|
|
47
|
+
}
|
|
48
|
+
const yearNum = parseInt(validYear);
|
|
49
|
+
const maxDay = getDaysInMonth(monthNum, yearNum);
|
|
50
|
+
if (dayNum < 1 || dayNum > maxDay) {
|
|
51
|
+
return {
|
|
52
|
+
key: 'form.error.date.invalid_day_range',
|
|
53
|
+
context: {
|
|
54
|
+
maxDay: maxDay,
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
if (monthNum < 1 || monthNum > 12) {
|
|
59
|
+
return 'form.error.datetime.invalid_month_range';
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return 'form.error.date.invalid';
|
|
39
63
|
};
|
|
40
64
|
|
|
41
65
|
export const LATER_THAN_VALIDATOR = (field: FieldSpec): ValidatorSchema => {
|
|
@@ -96,7 +120,7 @@ export const EARLIER_THAN_VALIDATOR = (field: FieldSpec): ValidatorSchema => {
|
|
|
96
120
|
|
|
97
121
|
export const DATE_VALIDATOR = {
|
|
98
122
|
name: 'date-validator',
|
|
99
|
-
message: (v): string => {
|
|
123
|
+
message: (v): string | object => {
|
|
100
124
|
return checkPartialDate(v.value);
|
|
101
125
|
},
|
|
102
126
|
test: function (value: string) {
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import dayjs from 'dayjs';
|
|
2
2
|
import customParseFormat from 'dayjs/plugin/customParseFormat';
|
|
3
|
-
import { FieldSpec } from '@digigov/form/types';
|
|
4
|
-
import { ValidatorSchema } from '@digigov/form/validators/types';
|
|
3
|
+
import type { FieldSpec } from '@digigov/form/types';
|
|
4
|
+
import type { ValidatorSchema } from '@digigov/form/validators/types';
|
|
5
5
|
|
|
6
6
|
dayjs.extend(customParseFormat);
|
|
7
7
|
|
|
8
8
|
const VALID_DATETIME_FORMATS = ['DD/MM/YYYY HH:mm'];
|
|
9
9
|
const DATETIME_CACHE = {};
|
|
10
|
+
const onlyNumbersRegex = /^\d+$/;
|
|
10
11
|
|
|
11
12
|
const getDateTime = (v: string) => {
|
|
12
13
|
return DATETIME_CACHE[v]
|
|
@@ -14,54 +15,145 @@ const getDateTime = (v: string) => {
|
|
|
14
15
|
: dayjs(v, VALID_DATETIME_FORMATS, true);
|
|
15
16
|
};
|
|
16
17
|
|
|
17
|
-
|
|
18
|
+
const getDaysInMonth = (month: number, year: number): number => {
|
|
19
|
+
return dayjs(`${year}-${month}-01`).daysInMonth(); // e.g. 29 for Feb 2024
|
|
20
|
+
};
|
|
21
|
+
|
|
18
22
|
const checkPartialDateTime = (value: string) => {
|
|
19
23
|
const [datePart, timePart] = value.split(' ');
|
|
20
|
-
const [day, month, year] = datePart
|
|
21
|
-
const [hours, minutes] = timePart
|
|
24
|
+
const [day, month, year] = datePart?.split('/') ?? [];
|
|
25
|
+
const [hours, minutes] = timePart?.split(':') ?? [];
|
|
26
|
+
|
|
27
|
+
const hasDay = Boolean(day);
|
|
28
|
+
const hasMonth = Boolean(month);
|
|
29
|
+
const hasYear = Boolean(year);
|
|
30
|
+
const hasHours = Boolean(hours);
|
|
31
|
+
const hasMinutes = Boolean(minutes);
|
|
22
32
|
|
|
23
|
-
|
|
24
|
-
|
|
33
|
+
if (hasDay && !hasMonth && !hasYear && !hasHours && !hasMinutes) {
|
|
34
|
+
return 'form.error.datetime.invalid_month_year_hours_minutes';
|
|
35
|
+
}
|
|
36
|
+
if (!hasDay && hasMonth && !hasYear && !hasHours && !hasMinutes) {
|
|
37
|
+
return 'form.error.datetime.invalid_day_year_hours_minutes';
|
|
38
|
+
}
|
|
39
|
+
if (!hasDay && !hasMonth && hasYear && !hasHours && !hasMinutes) {
|
|
40
|
+
return 'form.error.datetime.invalid_day_month_hours_minutes';
|
|
41
|
+
}
|
|
42
|
+
if (hasDay && hasMonth && !hasYear && !hasHours && !hasMinutes) {
|
|
43
|
+
return 'form.error.datetime.invalid_year_hours_minutes';
|
|
44
|
+
}
|
|
45
|
+
if (hasDay && !hasMonth && hasYear && !hasHours && !hasMinutes) {
|
|
46
|
+
return 'form.error.datetime.invalid_month_hours_minutes';
|
|
47
|
+
}
|
|
48
|
+
if (!hasDay && hasMonth && hasYear && !hasHours && !hasMinutes) {
|
|
49
|
+
return 'form.error.datetime.invalid_day_hours_minutes';
|
|
50
|
+
}
|
|
51
|
+
if (hasDay && hasMonth && hasYear && !hasHours && !hasMinutes) {
|
|
52
|
+
return 'form.error.datetime.invalid__hours_minutes';
|
|
53
|
+
}
|
|
54
|
+
if (hasDay && hasMonth && hasYear && hasHours && !hasMinutes) {
|
|
55
|
+
return 'form.error.datetime.invalid_minutes';
|
|
56
|
+
}
|
|
57
|
+
if (hasDay && hasMonth && hasYear && !hasHours && hasMinutes) {
|
|
58
|
+
return 'form.error.datetime.invalid_hours';
|
|
59
|
+
}
|
|
60
|
+
if (hasDay && !hasMonth && !hasYear && hasHours && !hasMinutes) {
|
|
61
|
+
return 'form.error.datetime.invalid_month_year_minutes';
|
|
62
|
+
}
|
|
63
|
+
if (hasDay && !hasMonth && !hasYear && !hasHours && hasMinutes) {
|
|
64
|
+
return 'form.error.datetime.invalid_month_year_hours';
|
|
65
|
+
}
|
|
66
|
+
if (hasDay && !hasMonth && !hasYear && hasHours && hasMinutes) {
|
|
25
67
|
return 'form.error.datetime.invalid_month_year';
|
|
26
68
|
}
|
|
27
|
-
if (!
|
|
69
|
+
if (!hasDay && hasMonth && !hasYear && hasHours && !hasMinutes) {
|
|
70
|
+
return 'form.error.datetime.invalid_day_year_minutes';
|
|
71
|
+
}
|
|
72
|
+
if (!hasDay && hasMonth && !hasYear && !hasHours && hasMinutes) {
|
|
73
|
+
return 'form.error.datetime.invalid_day_year_hours';
|
|
74
|
+
}
|
|
75
|
+
if (!hasDay && hasMonth && !hasYear && hasHours && hasMinutes) {
|
|
28
76
|
return 'form.error.datetime.invalid_day_year';
|
|
29
77
|
}
|
|
30
|
-
if (!
|
|
78
|
+
if (!hasDay && !hasMonth && hasYear && hasHours && !hasMinutes) {
|
|
79
|
+
return 'form.error.datetime.invalid_day_month_minutes';
|
|
80
|
+
}
|
|
81
|
+
if (!hasDay && !hasMonth && hasYear && !hasHours && hasMinutes) {
|
|
82
|
+
return 'form.error.datetime.invalid_day_month_hours';
|
|
83
|
+
}
|
|
84
|
+
if (!hasDay && !hasMonth && hasYear && hasHours && hasMinutes) {
|
|
31
85
|
return 'form.error.datetime.invalid_day_month';
|
|
32
86
|
}
|
|
33
|
-
if (
|
|
87
|
+
if (!hasDay && !hasMonth && !hasYear && hasHours && hasMinutes) {
|
|
88
|
+
return 'form.error.datetime.invalid_day_month_year';
|
|
89
|
+
}
|
|
90
|
+
if (!hasDay && !hasMonth && !hasYear && !hasHours && hasMinutes) {
|
|
91
|
+
return 'form.error.datetime.invalid_day_month_year_hours';
|
|
92
|
+
}
|
|
93
|
+
if (hasDay && hasMonth && !hasYear && hasHours && !hasMinutes) {
|
|
94
|
+
return 'form.error.datetime.invalid_year_minutes';
|
|
95
|
+
}
|
|
96
|
+
if (hasDay && hasMonth && !hasYear && !hasHours && hasMinutes) {
|
|
97
|
+
return 'form.error.datetime.invalid_year_hours';
|
|
98
|
+
}
|
|
99
|
+
if (hasDay && hasMonth && !hasYear && hasHours && hasMinutes) {
|
|
34
100
|
return 'form.error.datetime.invalid_year';
|
|
35
101
|
}
|
|
36
|
-
if (
|
|
102
|
+
if (hasDay && !hasMonth && hasYear && hasHours && !hasMinutes) {
|
|
103
|
+
return 'form.error.datetime.invalid_month_minutes';
|
|
104
|
+
}
|
|
105
|
+
if (hasDay && !hasMonth && hasYear && !hasHours && hasMinutes) {
|
|
106
|
+
return 'form.error.datetime.invalid_month_hours';
|
|
107
|
+
}
|
|
108
|
+
if (hasDay && !hasMonth && hasYear && hasHours && hasMinutes) {
|
|
37
109
|
return 'form.error.datetime.invalid_month';
|
|
38
110
|
}
|
|
39
|
-
if (!
|
|
111
|
+
if (!hasDay && hasMonth && hasYear && hasHours && !hasMinutes) {
|
|
112
|
+
return 'form.error.datetime.invalid_day_minutes';
|
|
113
|
+
}
|
|
114
|
+
if (!hasDay && hasMonth && hasYear && !hasHours && hasMinutes) {
|
|
115
|
+
return 'form.error.datetime.invalid_day_hours';
|
|
116
|
+
}
|
|
117
|
+
if (!hasDay && hasMonth && hasYear && hasHours && hasMinutes) {
|
|
40
118
|
return 'form.error.datetime.invalid_day';
|
|
41
119
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
120
|
+
if (!hasDay && !hasMonth && !hasYear && hasHours && !hasMinutes) {
|
|
121
|
+
return 'form.error.datetime.invalid_day_month_year_minutes';
|
|
122
|
+
}
|
|
123
|
+
if (hasDay && hasMonth && hasYear && !hasHours && !hasMinutes) {
|
|
124
|
+
return 'form.error.datetime.invalid_hours_minutes';
|
|
125
|
+
}
|
|
126
|
+
if (day && month) {
|
|
127
|
+
const dayNum = parseInt(day);
|
|
128
|
+
const monthNum = parseInt(month);
|
|
129
|
+
const validYear = onlyNumbersRegex.test(year) ? year : undefined;
|
|
130
|
+
if (!validYear || year.length < 4) {
|
|
131
|
+
return 'form.error.datetime.invalid';
|
|
46
132
|
}
|
|
47
|
-
|
|
48
|
-
|
|
133
|
+
const yearNum = parseInt(validYear);
|
|
134
|
+
const maxDay = getDaysInMonth(monthNum, yearNum);
|
|
135
|
+
if (dayNum < 1 || dayNum > maxDay) {
|
|
136
|
+
return {
|
|
137
|
+
key: 'form.error.datetime.invalid_day_range',
|
|
138
|
+
context: {
|
|
139
|
+
maxDay: maxDay,
|
|
140
|
+
},
|
|
141
|
+
};
|
|
49
142
|
}
|
|
50
|
-
if (
|
|
51
|
-
return 'form.error.datetime.
|
|
143
|
+
if (monthNum < 1 || monthNum > 12) {
|
|
144
|
+
return 'form.error.datetime.invalid_month_range';
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (hours && minutes) {
|
|
148
|
+
const hoursNum = parseInt(hours);
|
|
149
|
+
const minutesNum = parseInt(minutes);
|
|
150
|
+
if (hoursNum < 0 || hoursNum > 23) {
|
|
151
|
+
return 'form.error.datetime.invalid_hours_range';
|
|
52
152
|
}
|
|
53
|
-
if (
|
|
54
|
-
|
|
55
|
-
const minutesNum = parseInt(minutes);
|
|
56
|
-
if (hoursNum < 0 || hoursNum > 23) {
|
|
57
|
-
return 'form.error.datetime.invalid_hours_range';
|
|
58
|
-
}
|
|
59
|
-
if (minutesNum < 0 || minutesNum > 59) {
|
|
60
|
-
return 'form.error.datetime.invalid_minutes_range';
|
|
61
|
-
}
|
|
153
|
+
if (minutesNum < 0 || minutesNum > 59) {
|
|
154
|
+
return 'form.error.datetime.invalid_minutes_range';
|
|
62
155
|
}
|
|
63
156
|
}
|
|
64
|
-
|
|
65
157
|
return 'form.error.datetime.invalid';
|
|
66
158
|
};
|
|
67
159
|
|
|
@@ -119,7 +211,7 @@ export const EARLIER_THAN_DATETIME_VALIDATOR = (
|
|
|
119
211
|
|
|
120
212
|
export const DATETIME_VALIDATOR = {
|
|
121
213
|
name: 'datetime-validator',
|
|
122
|
-
message: (v): string => {
|
|
214
|
+
message: (v): string | object => {
|
|
123
215
|
return checkPartialDateTime(v.value);
|
|
124
216
|
},
|
|
125
217
|
test: function (value: string) {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const EMAIL_VALIDATOR = {
|
|
2
|
+
name: 'email-validator',
|
|
3
|
+
message: 'form.error.email',
|
|
4
|
+
test: (value: string): boolean => {
|
|
5
|
+
if (!value) return true;
|
|
6
|
+
const EMAIL_REGEX =
|
|
7
|
+
// eslint-disable-next-line no-useless-escape
|
|
8
|
+
/^(([^<>()\[\]\\.,;:\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,}))$/;
|
|
9
|
+
return EMAIL_REGEX.test(value);
|
|
10
|
+
},
|
|
11
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FieldSpec } from '@digigov/form/types';
|
|
2
|
-
import { ValidatorSchema } from '@digigov/form/validators/types';
|
|
1
|
+
import type { FieldSpec } from '@digigov/form/types';
|
|
2
|
+
import type { ValidatorSchema } from '@digigov/form/validators/types';
|
|
3
3
|
|
|
4
4
|
const DEFAULT_FILE_MAX_SIZE = 10000000;
|
|
5
5
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FieldSpec } from '@digigov/form/types';
|
|
2
|
-
import { ValidatorSchema } from '@digigov/form/validators/types';
|
|
1
|
+
import type { FieldSpec } from '@digigov/form/types';
|
|
2
|
+
import type { ValidatorSchema } from '@digigov/form/validators/types';
|
|
3
3
|
export function validateIban(value: string, countryCode: string): boolean {
|
|
4
4
|
value = value.replace(/\s/g, '').replace(/-/g, '');
|
|
5
5
|
if (value.match(/^[0-9]*$/i)) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FieldSpec } from '@digigov/form/types';
|
|
2
|
-
import { ValidatorSchema } from '@digigov/form/validators/types';
|
|
1
|
+
import type { FieldSpec } from '@digigov/form/types';
|
|
2
|
+
import type { ValidatorSchema } from '@digigov/form/validators/types';
|
|
3
3
|
|
|
4
4
|
const DEFAULT_IMAGE_MAX_HEIGHT_SIZE = 2000;
|
|
5
5
|
const DEFAULT_IMAGE_MAX_WIDTH_SIZE = 2000;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as yup from 'yup';
|
|
2
|
-
import { FieldSpec } from '@digigov/form/types';
|
|
3
|
-
import { ValidatorSchema } from '@digigov/form/validators/types';
|
|
2
|
+
import type { FieldSpec } from '@digigov/form/types';
|
|
3
|
+
import type { ValidatorSchema } from '@digigov/form/validators/types';
|
|
4
4
|
|
|
5
5
|
export * from '@digigov/form/validators/utils/afm';
|
|
6
6
|
export * from '@digigov/form/validators/utils/amka';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FieldSpec } from '@digigov/form/types';
|
|
2
|
-
import { ValidatorSchema } from '@digigov/form/validators/types';
|
|
1
|
+
import type { FieldSpec } from '@digigov/form/types';
|
|
2
|
+
import type { ValidatorSchema } from '@digigov/form/validators/types';
|
|
3
3
|
export function validateOtp(value: string, maxLength: number): boolean {
|
|
4
4
|
if (value.length === maxLength) {
|
|
5
5
|
return true;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FieldSpec } from '@digigov/form/types';
|
|
2
|
-
import { ValidatorSchema } from '@digigov/form/validators/types';
|
|
1
|
+
import type { FieldSpec } from '@digigov/form/types';
|
|
2
|
+
import type { ValidatorSchema } from '@digigov/form/validators/types';
|
|
3
3
|
|
|
4
4
|
export type PhoneNumberType = 'landline' | 'mobile' | null;
|
|
5
5
|
// add more countries from here libphonenumber-js/metadata.full.json
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FieldSpec } from '@digigov/form/types';
|
|
2
|
-
import { ValidatorSchema } from '@digigov/form/validators/types';
|
|
1
|
+
import type { FieldSpec } from '@digigov/form/types';
|
|
2
|
+
import type { ValidatorSchema } from '@digigov/form/validators/types';
|
|
3
3
|
|
|
4
4
|
const CODE_REGEX = /^[12345678][0-9]{4}$/;
|
|
5
5
|
export function validatePostalCode(
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FieldSpec } from '@digigov/form/types';
|
|
2
|
-
import { ValidatorSchema } from '@digigov/form/validators/types';
|
|
1
|
+
import type { FieldSpec } from '@digigov/form/types';
|
|
2
|
+
import type { ValidatorSchema } from '@digigov/form/validators/types';
|
|
3
3
|
|
|
4
4
|
export function validateText(value: string, min: number, max: number): boolean {
|
|
5
5
|
let validator;
|
package/types.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { UseFormReturn, UseFormProps, ErrorOption } from 'react-hook-form';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import type { UseFormReturn, UseFormProps, ErrorOption } from 'react-hook-form';
|
|
2
|
+
import type { FieldLabelProps, FieldSpec, FormData } from '@digigov/form/Field/types';
|
|
3
|
+
import type { FieldComponentRegistry } from '@digigov/form/inputs/registry';
|
|
4
|
+
import type { ValidatorSchema } from '@digigov/form/validators/types';
|
|
4
5
|
export * from '@digigov/form/Field/types';
|
|
5
6
|
export interface FieldError {
|
|
6
7
|
message: string;
|
|
@@ -11,25 +12,29 @@ export interface FieldsetSpec {
|
|
|
11
12
|
label?: FieldLabelProps;
|
|
12
13
|
body?: React.ReactNode;
|
|
13
14
|
}
|
|
15
|
+
export type registerFieldFocus = (fieldName: string, element: HTMLElement) => (name: string) => void;
|
|
14
16
|
export interface FormContextProps {
|
|
15
17
|
fieldsetsMap?: Record<string, FieldsetSpec>;
|
|
16
18
|
fieldsMap: Record<string, FieldSpec>;
|
|
17
19
|
control: UseFormReturn['control'];
|
|
18
20
|
register: UseFormReturn['register'];
|
|
19
21
|
trigger: UseFormReturn['trigger'];
|
|
22
|
+
setError: UseFormReturn['setError'];
|
|
20
23
|
clearErrors: UseFormReturn['clearErrors'];
|
|
21
24
|
watch: UseFormReturn['watch'];
|
|
22
25
|
getFieldState: UseFormReturn['getFieldState'];
|
|
23
26
|
setValue: UseFormReturn['setValue'];
|
|
24
27
|
getValues: UseFormReturn['getValues'];
|
|
28
|
+
getValuesFromParentForm?: UseFormReturn['getValues'];
|
|
25
29
|
unregister: UseFormReturn['unregister'];
|
|
26
30
|
formState: UseFormReturn['formState'];
|
|
27
31
|
reset: UseFormReturn['reset'];
|
|
28
32
|
resetField: UseFormReturn['resetField'];
|
|
29
33
|
registerField: (field: FieldSpec) => void;
|
|
34
|
+
registerFieldFocus: registerFieldFocus;
|
|
30
35
|
errors: UseFormReturn['formState']['errors'];
|
|
31
36
|
componentRegistry?: FieldComponentRegistry;
|
|
32
|
-
submit: () => Promise<void
|
|
37
|
+
submit: () => Promise<void> | void;
|
|
33
38
|
}
|
|
34
39
|
export interface FormBuilderProps {
|
|
35
40
|
fields?: FieldSpec[];
|
package/types.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/types.tsx"],
|
|
4
|
-
"sourcesContent": ["import { UseFormReturn, UseFormProps, ErrorOption } from 'react-hook-form';\nimport {\n
|
|
4
|
+
"sourcesContent": ["import type { UseFormReturn, UseFormProps, ErrorOption } from 'react-hook-form';\nimport type {\n FieldLabelProps,\n FieldSpec,\n FormData,\n} from '@digigov/form/Field/types';\nimport type { FieldComponentRegistry } from '@digigov/form/inputs/registry';\nimport type { ValidatorSchema } from '@digigov/form/validators/types';\nexport * from '@digigov/form/Field/types';\nexport interface FieldError {\n message: string;\n}\n\nexport interface FieldsetSpec {\n key: string;\n fields: string[];\n label?: FieldLabelProps;\n body?: React.ReactNode;\n}\n\nexport type registerFieldFocus = (\n fieldName: string,\n element: HTMLElement\n) => (name: string) => void;\n\nexport interface FormContextProps {\n fieldsetsMap?: Record<string, FieldsetSpec>;\n fieldsMap: Record<string, FieldSpec>;\n control: UseFormReturn['control'];\n register: UseFormReturn['register'];\n trigger: UseFormReturn['trigger'];\n setError: UseFormReturn['setError'];\n clearErrors: UseFormReturn['clearErrors'];\n watch: UseFormReturn['watch'];\n getFieldState: UseFormReturn['getFieldState'];\n setValue: UseFormReturn['setValue'];\n getValues: UseFormReturn['getValues'];\n getValuesFromParentForm?: UseFormReturn['getValues'];\n unregister: UseFormReturn['unregister'];\n formState: UseFormReturn['formState'];\n reset: UseFormReturn['reset'];\n resetField: UseFormReturn['resetField'];\n registerField: (field: FieldSpec) => void;\n registerFieldFocus: registerFieldFocus;\n errors: UseFormReturn['formState']['errors'];\n componentRegistry?: FieldComponentRegistry;\n submit: () => Promise<void> | void;\n}\n\nexport interface FormBuilderProps {\n fields?: FieldSpec[];\n fieldsets?: FieldsetSpec[];\n initial?: FormData;\n onSubmit?: (data: FormData) => void | null | FieldError[];\n mode?: UseFormProps['mode'];\n reValidateMode?: UseFormProps['reValidateMode'];\n criteriaMode?: UseFormProps['criteriaMode'];\n children?: React.ReactNode;\n shouldFocusError?: boolean;\n auto?: boolean;\n validatorRegistry?: Record<string, ValidatorSchema[]>;\n componentRegistry?: FieldComponentRegistry;\n grid?: boolean;\n controlledFieldsOnly?: boolean;\n errors?: ErrorOption;\n}\n\nexport interface FormBaseProps\n extends Omit<FormBuilderProps, 'fields' | 'fieldsets' | 'auto'> {\n fieldsetsMap?: Record<string, FieldsetSpec>;\n fieldsMap: Record<string, FieldSpec>;\n registerField: (field: FieldSpec) => void;\n resolver: any;\n}\n"],
|
|
5
5
|
"mappings": "AAQA,cAAc;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/utils.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FieldError } from 'react-hook-form';
|
|
1
|
+
import type { FieldError } from 'react-hook-form';
|
|
2
2
|
export declare const yupResolver: (schema: any, schemaOptions?: any, resolverOptions?: any) => (values: any, context: any, options: any) => Promise<{
|
|
3
3
|
values: any;
|
|
4
4
|
errors: {};
|
package/utils.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/utils.ts"],
|
|
4
|
-
"sourcesContent": ["import { validateFieldsNatively } from '@hookform/resolvers';\nimport {
|
|
5
|
-
"mappings": "AAAA,SAAS,8BAA8B;
|
|
4
|
+
"sourcesContent": ["import { validateFieldsNatively } from '@hookform/resolvers';\nimport type { FieldError } from 'react-hook-form';\nimport { appendErrors } from 'react-hook-form';\nimport type * as Yup from 'yup';\n\n/**\n * Why `path!` ? because it could be `undefined` in some case\n * https://github.com/jquense/yup#validationerrorerrors-string--arraystring-value-any-path-string\n */\nconst parseErrorSchema = (\n error: Yup.ValidationError,\n validateAllFieldCriteria: boolean\n) => {\n return (error.inner || []).reduce<Record<string, FieldError>>(\n (previous, error) => {\n error.path = error.path?.replace(/\\[([0-9]+)\\]/g, '.$1');\n // error.path = error.path?.replace(/\\[\"(.*?)\"\\]/g, '$1');\n if (!previous[error.path!]) {\n previous[error.path!] = { message: error.message, type: error.type! };\n }\n\n if (validateAllFieldCriteria) {\n const types = previous[error.path!].types;\n const messages = types && types[error.type!];\n\n previous[error.path!] = appendErrors(\n error.path!,\n validateAllFieldCriteria,\n previous,\n error.type!,\n messages\n ? ([] as string[]).concat(messages as string[], error.message)\n : error.message\n ) as FieldError;\n }\n\n return previous;\n },\n {}\n );\n};\nfunction isPlainObject(obj) {\n return (\n typeof obj === 'object' &&\n obj !== null &&\n Object.prototype.toString.call(obj) === '[object Object]'\n );\n}\nfunction flattenObject(obj, prefix = '') {\n return Object.keys(obj).reduce((acc, key) => {\n const prefixedKey = prefix ? `${prefix}.${key}` : key;\n\n if (isPlainObject(obj[key])) {\n Object.assign(acc, flattenObject(obj[key], prefixedKey));\n } else {\n acc[prefixedKey] = obj[key];\n }\n\n return acc;\n }, {});\n}\n\nexport const yupResolver =\n (schema: any, schemaOptions: any = {}, resolverOptions: any = {}) =>\n async (values, context, options) => {\n try {\n if (schemaOptions.context && process.env.NODE_ENV === 'development') {\n console.warn(\n \"You should not used the yup options context. Please, use the 'useForm' context object instead\"\n );\n }\n\n const result = await schema[\n resolverOptions.mode === 'sync' ? 'validateSync' : 'validate'\n ](\n flattenObject(values),\n Object.assign({ abortEarly: false }, schemaOptions, { context })\n );\n\n if (options.shouldUseNativeValidation)\n validateFieldsNatively({}, options);\n\n return {\n values: resolverOptions.rawValues ? values : result,\n errors: {},\n };\n } catch (e) {\n if (!e.inner) {\n throw e;\n }\n\n return {\n values: {},\n errors: parseErrorSchema(\n e,\n !options.shouldUseNativeValidation && options.criteriaMode === 'all'\n ),\n options,\n };\n }\n };\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,8BAA8B;AAEvC,SAAS,oBAAoB;AAO7B,MAAM,mBAAmB,CACvB,OACA,6BACG;AACH,UAAQ,MAAM,SAAS,CAAC,GAAG;AAAA,IACzB,CAAC,UAAUA,WAAU;AACnB,MAAAA,OAAM,OAAOA,OAAM,MAAM,QAAQ,iBAAiB,KAAK;AAEvD,UAAI,CAAC,SAASA,OAAM,IAAK,GAAG;AAC1B,iBAASA,OAAM,IAAK,IAAI,EAAE,SAASA,OAAM,SAAS,MAAMA,OAAM,KAAM;AAAA,MACtE;AAEA,UAAI,0BAA0B;AAC5B,cAAM,QAAQ,SAASA,OAAM,IAAK,EAAE;AACpC,cAAM,WAAW,SAAS,MAAMA,OAAM,IAAK;AAE3C,iBAASA,OAAM,IAAK,IAAI;AAAA,UACtBA,OAAM;AAAA,UACN;AAAA,UACA;AAAA,UACAA,OAAM;AAAA,UACN,WACK,CAAC,EAAe,OAAO,UAAsBA,OAAM,OAAO,IAC3DA,OAAM;AAAA,QACZ;AAAA,MACF;AAEA,aAAO;AAAA,IACT;AAAA,IACA,CAAC;AAAA,EACH;AACF;AACA,SAAS,cAAc,KAAK;AAC1B,SACE,OAAO,QAAQ,YACf,QAAQ,QACR,OAAO,UAAU,SAAS,KAAK,GAAG,MAAM;AAE5C;AACA,SAAS,cAAc,KAAK,SAAS,IAAI;AACvC,SAAO,OAAO,KAAK,GAAG,EAAE,OAAO,CAAC,KAAK,QAAQ;AAC3C,UAAM,cAAc,SAAS,GAAG,MAAM,IAAI,GAAG,KAAK;AAElD,QAAI,cAAc,IAAI,GAAG,CAAC,GAAG;AAC3B,aAAO,OAAO,KAAK,cAAc,IAAI,GAAG,GAAG,WAAW,CAAC;AAAA,IACzD,OAAO;AACL,UAAI,WAAW,IAAI,IAAI,GAAG;AAAA,IAC5B;AAEA,WAAO;AAAA,EACT,GAAG,CAAC,CAAC;AACP;AAEO,MAAM,cACX,CAAC,QAAa,gBAAqB,CAAC,GAAG,kBAAuB,CAAC,MAC/D,OAAO,QAAQ,SAAS,YAAY;AAClC,MAAI;AACF,QAAI,cAAc,WAAW,QAAQ,IAAI,aAAa,eAAe;AACnE,cAAQ;AAAA,QACN;AAAA,MACF;AAAA,IACF;AAEA,UAAM,SAAS,MAAM,OACnB,gBAAgB,SAAS,SAAS,iBAAiB,UACrD;AAAA,MACE,cAAc,MAAM;AAAA,MACpB,OAAO,OAAO,EAAE,YAAY,MAAM,GAAG,eAAe,EAAE,QAAQ,CAAC;AAAA,IACjE;AAEA,QAAI,QAAQ;AACV,6BAAuB,CAAC,GAAG,OAAO;AAEpC,WAAO;AAAA,MACL,QAAQ,gBAAgB,YAAY,SAAS;AAAA,MAC7C,QAAQ,CAAC;AAAA,IACX;AAAA,EACF,SAAS,GAAG;AACV,QAAI,CAAC,EAAE,OAAO;AACZ,YAAM;AAAA,IACR;AAEA,WAAO;AAAA,MACL,QAAQ,CAAC;AAAA,MACT,QAAQ;AAAA,QACN;AAAA,QACA,CAAC,QAAQ,6BAA6B,QAAQ,iBAAiB;AAAA,MACjE;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
6
|
"names": ["error"]
|
|
7
7
|
}
|
package/validators/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { MutableRefObject } from 'react';
|
|
2
|
-
import { AnyObjectSchema } from 'yup';
|
|
3
|
-
import Lazy from 'yup/lib/Lazy';
|
|
4
|
-
import { FieldSpec } from '@digigov/form/types';
|
|
5
|
-
import { ValidatorSchema } from '@digigov/form/validators/types';
|
|
1
|
+
import type { MutableRefObject } from 'react';
|
|
2
|
+
import type { AnyObjectSchema } from 'yup';
|
|
3
|
+
import type Lazy from 'yup/lib/Lazy';
|
|
4
|
+
import type { FieldSpec } from '@digigov/form/types';
|
|
5
|
+
import type { ValidatorSchema } from '@digigov/form/validators/types';
|
|
6
6
|
export declare const getYUPTypeMap: (validatorRegistry?: Record<string, any>) => Record<string, any>;
|
|
7
7
|
export interface MutableRefObjectProps {
|
|
8
8
|
}
|
package/validators/index.js
CHANGED
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
LATER_THAN_DATETIME_VALIDATOR,
|
|
21
21
|
EARLIER_THAN_DATETIME_VALIDATOR
|
|
22
22
|
} from "@digigov/form/validators/utils";
|
|
23
|
+
import { EMAIL_VALIDATOR } from "@digigov/form/validators/utils/email";
|
|
23
24
|
import { INT_VALIDATOR } from "@digigov/form/validators/utils/int";
|
|
24
25
|
import { NUMBER_VALIDATOR } from "@digigov/form/validators/utils/number";
|
|
25
26
|
const getYUPTypeMap = (validatorRegistry) => {
|
|
@@ -67,13 +68,15 @@ const getYUPTypeMap = (validatorRegistry) => {
|
|
|
67
68
|
arrayValidator = arrayValidator.min(field.extra.min, {
|
|
68
69
|
key: "form.error.array.min",
|
|
69
70
|
context: {
|
|
70
|
-
min: field.extra.min
|
|
71
|
+
min: field.extra.min,
|
|
72
|
+
max: field.extra.max || void 0
|
|
71
73
|
}
|
|
72
74
|
});
|
|
73
75
|
if (field.extra.max)
|
|
74
76
|
arrayValidator = arrayValidator.max(field.extra.max, {
|
|
75
77
|
key: "form.error.array.max",
|
|
76
78
|
context: {
|
|
79
|
+
min: field.extra.min || void 0,
|
|
77
80
|
max: field.extra.max
|
|
78
81
|
}
|
|
79
82
|
});
|
|
@@ -86,7 +89,7 @@ const getYUPTypeMap = (validatorRegistry) => {
|
|
|
86
89
|
},
|
|
87
90
|
number: () => yup.mixed().transform((_, val) => val !== "" ? Number(val) : void 0).test(NUMBER_VALIDATOR()),
|
|
88
91
|
int: () => yup.mixed().transform((_, val) => val !== "" ? Number(val) : void 0).test(NUMBER_VALIDATOR()).test(INT_VALIDATOR()),
|
|
89
|
-
email: (field) => field.trim ? yup.string().trim().
|
|
92
|
+
email: (field) => field.trim ? yup.string().trim().test(EMAIL_VALIDATOR) : yup.string().test(EMAIL_VALIDATOR),
|
|
90
93
|
afm: (field) => field.trim ? yup.string().trim().test(AFM_VALIDATOR) : yup.string().test(AFM_VALIDATOR),
|
|
91
94
|
amka: (field) => field.trim ? yup.string().trim().test(AMKA_VALIDATOR) : yup.string().test(AMKA_VALIDATOR),
|
|
92
95
|
uuid4: (field) => field.trim ? yup.string().trim().test(UUID4_VALIDATOR) : yup.string().test(UUID4_VALIDATOR),
|
|
@@ -141,7 +144,7 @@ function useValidationSchema(fields, validatorRegistry) {
|
|
|
141
144
|
return useMemo(() => {
|
|
142
145
|
const yupTypeMap = getYUPTypeMap(validatorRegistry);
|
|
143
146
|
return getYupObjectShape(fields, yupTypeMap, validatorRegistry);
|
|
144
|
-
}, []);
|
|
147
|
+
}, [fields, validatorRegistry]);
|
|
145
148
|
}
|
|
146
149
|
export {
|
|
147
150
|
getYUPTypeMap,
|