@digigov/form 2.0.0-rc.7 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +113 -3
- package/Field/ErrorGroup.d.ts +15 -0
- 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 -68
- package/Field/types.d.ts +61 -11
- package/Field/utils/evaluateFieldWithConditions.d.ts +2 -0
- 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 +2 -0
- 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 +134 -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 +199 -0
- package/FieldArray/index.d.ts +11 -2
- package/FieldArray/index.js +65 -60
- package/FieldObject/index.d.ts +11 -3
- package/FieldObject/index.js +53 -52
- package/Fieldset/FieldsetWithContext.js +27 -0
- package/Fieldset/index.d.ts +2 -2
- package/Fieldset/index.js +18 -32
- package/Fieldset/types.d.ts +3 -2
- package/FormBuilder/index.d.ts +8 -1
- package/FormBuilder/index.js +239 -2
- package/FormContext.d.ts +3 -2
- package/FormContext.js +7 -0
- package/MultiplicityField/add-objects.d.ts +3 -2
- package/MultiplicityField/add-objects.js +107 -0
- package/MultiplicityField/index.d.ts +2 -19
- package/MultiplicityField/index.js +84 -111
- package/MultiplicityField/types.d.ts +19 -0
- package/Questions/Questions.d.ts +1 -1
- package/Questions/Questions.js +48 -0
- package/Questions/QuestionsContext.d.ts +1 -2
- 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 -2
- 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 +2 -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 -12
- package/Questions/Step/index.js +13 -13
- package/Questions/Step/types.d.ts +2 -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 -3
- package/Questions/types.d.ts +2 -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 -2
- package/index.js +8 -4
- package/inputs/AutoCompleteInput/index.d.ts +5 -5
- package/inputs/AutoCompleteInput/index.js +42 -44
- package/inputs/Checkboxes/index.d.ts +7 -4
- package/inputs/Checkboxes/index.js +50 -91
- package/inputs/DateInput/index.d.ts +3 -7
- package/inputs/DateInput/index.js +128 -125
- package/inputs/DateTimeInput/index.d.ts +10 -0
- package/inputs/DateTimeInput/index.js +190 -0
- package/inputs/FileInput/index.d.ts +18 -2
- package/inputs/FileInput/index.js +59 -56
- package/inputs/ImageInput/index.d.ts +10 -2
- package/inputs/ImageInput/index.js +94 -74
- package/inputs/Input/index.d.ts +5 -2
- package/inputs/Input/index.js +67 -67
- package/inputs/Label/index.d.ts +2 -4
- package/inputs/Label/index.js +13 -21
- package/inputs/OtpInput/index.d.ts +1 -5
- package/inputs/OtpInput/index.js +122 -139
- package/inputs/Radio/index.d.ts +10 -3
- package/inputs/Radio/index.js +72 -56
- package/inputs/Select/index.d.ts +7 -4
- package/inputs/Select/index.js +23 -30
- package/inputs/index.d.ts +9 -9
- package/inputs/index.js +10 -9
- package/inputs/registry.d.ts +5 -0
- package/inputs/registry.js +80 -0
- package/internal.d.ts +5 -34
- package/internal.js +6 -0
- package/lazy.d.ts +93 -65
- package/lazy.js +163 -0
- package/package.json +12 -13
- package/registry.d.ts +45 -27
- package/registry.js +170 -0
- package/src/Field/ErrorGroup.tsx +84 -0
- package/src/Field/FieldBase.tsx +43 -25
- package/src/Field/FieldBaseContainer.tsx +71 -47
- package/src/Field/FieldConditional.tsx +10 -2
- package/src/Field/doc.mdx +207 -0
- package/src/Field/index.tsx +37 -23
- package/src/Field/types.tsx +92 -13
- package/src/Field/utils/evaluateFieldWithConditions.ts +33 -0
- package/src/Field/utils/resolveField.ts +58 -0
- package/src/Field/utils/useField.ts +68 -0
- package/src/FieldArray/BaseFieldArray.tsx +97 -0
- package/src/FieldArray/FieldArray.stories.js +4 -2
- 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 +370 -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 +110 -0
- package/src/FieldArray/__stories__/Default.tsx +2 -1
- package/src/FieldArray/__stories__/TableWithError.tsx +111 -0
- package/src/FieldArray/__stories__/WithExactLength.tsx +2 -1
- package/src/FieldArray/__stories__/WithModal.tsx +188 -0
- package/src/FieldArray/__tests__/fieldset-multiplicity.spec.tsx +271 -0
- package/src/FieldArray/__tests__/multiplicity-attachment.spec.tsx +280 -0
- package/src/FieldArray/__tests__/multiplicity-optional.spec.tsx +232 -0
- package/src/FieldArray/__tests__/multiplicity-required.spec.tsx +170 -0
- package/src/FieldArray/__tests__/nested-fieldset-multiplicity.spec.tsx +627 -0
- package/src/FieldArray/__tests__/preference-multiple-choice.spec.tsx +222 -0
- package/src/FieldArray/index.spec.tsx +355 -0
- package/src/FieldArray/index.test.tsx +43 -0
- package/src/FieldArray/index.tsx +84 -55
- package/src/FieldObject/index.tsx +53 -27
- package/src/Fieldset/FieldsetWithContext.tsx +1 -1
- package/src/Fieldset/index.tsx +6 -6
- package/src/Fieldset/types.tsx +5 -3
- package/src/FormBuilder/FormBuilder.stories.js +6 -1
- package/src/FormBuilder/__stories__/AutoErrorGrouping.tsx +63 -0
- package/src/FormBuilder/__stories__/Default.tsx +1 -1
- package/src/FormBuilder/__stories__/ErrorGrouping.tsx +43 -0
- package/src/FormBuilder/{FormBuilder.mdx → doc.mdx} +27 -35
- package/src/FormBuilder/index.test.tsx +32 -0
- package/src/FormBuilder/index.tsx +314 -1
- package/src/FormBuilder/interaction.test.tsx +40 -0
- package/src/FormBuilder/scenarios.test.tsx +2775 -0
- package/src/FormContext.tsx +7 -3
- package/src/MultiplicityField/MultiplicityField.stories.js +9 -6
- package/src/MultiplicityField/__stories__/Default.tsx +1 -1
- package/src/MultiplicityField/__stories__/PreviewDisplay.tsx +4 -6
- package/src/MultiplicityField/__stories__/WithExactLength.tsx +2 -2
- package/src/MultiplicityField/__stories__/WithMaxLength.tsx +2 -2
- package/src/MultiplicityField/__stories__/WithMinAndMaxLength.tsx +2 -2
- package/src/MultiplicityField/__stories__/WithMinLength.tsx +2 -2
- package/src/MultiplicityField/add-objects.tsx +39 -30
- package/{cjs/MultiplicityField/MultiplicityField.mdx → src/MultiplicityField/doc.mdx} +112 -98
- package/src/MultiplicityField/index.test.tsx +44 -0
- package/src/MultiplicityField/index.tsx +25 -34
- package/src/MultiplicityField/types.ts +25 -0
- package/src/Questions/Questions.stories.js +4 -1
- package/src/Questions/Questions.tsx +6 -6
- package/src/Questions/QuestionsContext.tsx +1 -1
- package/src/Questions/Step/Step.tsx +1 -1
- package/src/Questions/Step/StepArrayReview.tsx +3 -3
- 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 +6 -3
- package/src/Questions/Step/getAddMoreFields.tsx +2 -2
- package/src/Questions/Step/index.ts +0 -1
- package/src/Questions/Step/types.tsx +2 -1
- package/src/Questions/__snapshots__/index.spec.tsx.snap +74 -587
- package/src/Questions/__stories__/Default.tsx +1 -1
- package/{Questions/index.mdx → src/Questions/doc.mdx} +34 -57
- package/src/Questions/getNextStep.tsx +1 -1
- package/src/Questions/index.spec.tsx +17 -5
- package/src/Questions/index.test.tsx +24 -0
- package/src/Questions/types.tsx +2 -1
- package/src/create-simple-form.mdx +2 -6
- package/src/{index.mdx → doc.mdx} +29 -18
- 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/index.ts +4 -1
- package/src/inputs/AutoCompleteInput/AutoComplete.stories.js +5 -2
- package/src/inputs/AutoCompleteInput/__stories__/Default.tsx +3 -11
- package/src/inputs/AutoCompleteInput/__stories__/Multiple.tsx +3 -10
- package/{cjs/inputs/AutoCompleteInput/index.mdx → src/inputs/AutoCompleteInput/doc.mdx} +2 -13
- package/src/inputs/AutoCompleteInput/index.test.tsx +28 -0
- package/src/inputs/AutoCompleteInput/index.tsx +49 -35
- package/src/inputs/Checkboxes/Checkboxes.stories.js +6 -3
- package/src/inputs/Checkboxes/__stories__/Conditional.tsx +1 -1
- package/src/inputs/Checkboxes/__stories__/Default.tsx +1 -1
- package/src/inputs/Checkboxes/__stories__/WithDivider.tsx +1 -1
- package/src/inputs/Checkboxes/{index.mdx → doc.mdx} +5 -15
- package/src/inputs/Checkboxes/index.test.tsx +32 -0
- package/src/inputs/Checkboxes/index.tsx +106 -92
- package/src/inputs/DateInput/DateInput.stories.js +8 -1
- package/src/inputs/DateInput/__stories__/Default.tsx +17 -16
- 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.mdx → doc.mdx} +1 -8
- package/src/inputs/DateInput/index.test.tsx +40 -0
- package/src/inputs/DateInput/index.tsx +77 -27
- package/src/inputs/DateTimeInput/DateTimeInput.stories.js +14 -0
- package/src/inputs/DateTimeInput/__stories__/Default.tsx +25 -0
- 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 +16 -0
- package/src/inputs/DateTimeInput/index.test.tsx +40 -0
- package/src/inputs/DateTimeInput/index.tsx +246 -0
- package/src/inputs/FileInput/FileInput.stories.js +5 -1
- package/src/inputs/FileInput/__stories__/Default.tsx +1 -1
- package/src/inputs/FileInput/__stories__/WithBorderAndLink.tsx +34 -0
- package/{inputs/FileInput/index.mdx → src/inputs/FileInput/doc.mdx} +1 -5
- package/src/inputs/FileInput/index.test.tsx +28 -0
- package/src/inputs/FileInput/index.tsx +102 -43
- package/src/inputs/ImageInput/ImageInput.stories.js +7 -3
- package/src/inputs/ImageInput/__stories__/Default.tsx +1 -1
- package/src/inputs/ImageInput/__stories__/{WithInvalidImageSize.tsx → MaxSize.tsx} +5 -3
- package/src/inputs/ImageInput/__stories__/WithInitialValues.tsx +45 -0
- package/src/inputs/ImageInput/__stories__/WithInvalidImageDimension.tsx +3 -1
- 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 +23 -0
- package/src/inputs/ImageInput/index.test.tsx +36 -0
- package/src/inputs/ImageInput/index.tsx +105 -52
- package/src/inputs/Input/Input.stories.js +17 -10
- package/src/inputs/Input/__stories__/AFM.tsx +1 -1
- package/src/inputs/Input/__stories__/AMKA.tsx +23 -0
- package/src/inputs/Input/__stories__/Boolean.tsx +1 -1
- package/src/inputs/Input/__stories__/Email.tsx +23 -0
- package/src/inputs/Input/__stories__/IBAN.tsx +1 -1
- package/src/inputs/Input/__stories__/Integer.tsx +1 -1
- package/src/inputs/Input/__stories__/LandlineNumber.tsx +3 -2
- package/src/inputs/Input/__stories__/MobilePhone.tsx +2 -1
- package/src/inputs/Input/__stories__/PhoneNumber.tsx +2 -1
- package/src/inputs/Input/__stories__/PostalCode.tsx +2 -1
- package/src/inputs/Input/__stories__/Rate.tsx +25 -0
- package/src/inputs/Input/__stories__/{Default.tsx → String.tsx} +2 -2
- package/src/inputs/Input/__stories__/StringWithTrimValidation.tsx +26 -0
- package/src/inputs/Input/__stories__/{TextWithCharacterLimit.tsx → TextWithLimit.tsx} +3 -2
- package/src/inputs/Input/doc.mdx +56 -0
- package/src/inputs/Input/index.test.tsx +76 -0
- package/src/inputs/Input/index.tsx +55 -35
- package/src/inputs/Label/Label.stories.js +4 -1
- package/src/inputs/Label/__stories__/Default.tsx +4 -2
- package/src/inputs/Label/doc.mdx +14 -0
- package/src/inputs/Label/index.test.tsx +24 -0
- package/src/inputs/Label/index.tsx +4 -11
- package/src/inputs/OtpInput/OtpInput.stories.js +4 -1
- package/src/inputs/OtpInput/__stories__/Default.tsx +1 -1
- package/{cjs/inputs/OtpInput/index.mdx → src/inputs/OtpInput/doc.mdx} +1 -8
- package/src/inputs/OtpInput/index.test.tsx +24 -0
- package/src/inputs/OtpInput/index.tsx +45 -34
- package/src/inputs/Radio/Radio.stories.js +6 -3
- package/src/inputs/Radio/__stories__/Conditional.tsx +3 -2
- package/src/inputs/Radio/__stories__/Default.tsx +1 -1
- package/src/inputs/Radio/__stories__/WithDivider.tsx +1 -1
- package/{cjs/inputs/Radio/index.mdx → src/inputs/Radio/doc.mdx} +5 -15
- package/src/inputs/Radio/index.test.tsx +32 -0
- package/src/inputs/Radio/index.tsx +93 -12
- package/src/inputs/Select/Select.stories.js +4 -1
- package/src/inputs/Select/__stories__/Default.tsx +1 -1
- package/src/inputs/Select/{index.mdx → doc.mdx} +1 -5
- package/src/inputs/Select/index.test.tsx +24 -0
- package/src/inputs/Select/index.tsx +22 -9
- package/src/inputs/registry.ts +86 -0
- package/src/installation.mdx +2 -5
- package/src/internal.ts +2 -31
- package/src/lazy.ts +56 -0
- package/src/registry.ts +179 -0
- package/src/types.tsx +21 -65
- package/src/utils.ts +67 -33
- package/src/validators/index.ts +138 -99
- package/src/validators/types.ts +1 -1
- package/src/validators/utils/amka.ts +39 -0
- package/src/validators/utils/date.ts +131 -0
- package/src/validators/utils/datetime.ts +222 -0
- package/src/validators/utils/email.ts +11 -0
- package/src/validators/utils/file.ts +35 -19
- package/src/validators/utils/iban.ts +2 -2
- package/src/validators/utils/image.ts +2 -2
- package/src/validators/utils/index.ts +15 -6
- package/src/validators/utils/int.ts +2 -2
- package/src/validators/utils/number.ts +2 -2
- package/src/validators/utils/otp.ts +2 -2
- package/src/validators/utils/phone.ts +65 -74
- package/src/validators/utils/postal_code.ts +3 -3
- package/src/validators/utils/text_limit.ts +2 -2
- package/src/validators/utils/uuid4.ts +2 -1
- package/src/validators/validators.spec.ts +6 -40
- package/types.d.ts +14 -37
- 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 +115 -180
- 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 +9 -0
- package/validators/utils/date.js +95 -0
- package/validators/utils/datetime.d.ts +9 -0
- 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 -11
- package/validators/utils/index.js +62 -85
- 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 +3 -3
- package/validators/utils/phone.js +198 -0
- package/validators/utils/postal_code.d.ts +3 -3
- 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/FieldBase/index.js +0 -82
- package/Field/FieldBase/package.json +0 -6
- package/Field/FieldBaseContainer/index.js +0 -40
- package/Field/FieldBaseContainer/package.json +0 -6
- package/Field/FieldConditional/index.js +0 -59
- package/Field/FieldConditional/package.json +0 -6
- package/Field/index.mdx +0 -6
- package/Field/package.json +0 -6
- package/Field/types/index.js +0 -1
- package/Field/types/package.json +0 -6
- package/Field/utils/index.js +0 -153
- package/Field/utils/package.json +0 -6
- package/Field/utils.d.ts +0 -5
- package/FieldArray/FieldArray.stories/index.js +0 -8
- package/FieldArray/FieldArray.stories/package.json +0 -6
- package/FieldArray/FieldArray.stories.d.ts +0 -9
- package/FieldArray/FieldArray.stories.playwright.json +0 -353
- package/FieldArray/__stories__/Default/index.js +0 -88
- package/FieldArray/__stories__/Default/package.json +0 -6
- package/FieldArray/__stories__/Default.d.ts +0 -2
- package/FieldArray/__stories__/WithExactLength/index.js +0 -88
- package/FieldArray/__stories__/WithExactLength/package.json +0 -6
- package/FieldArray/__stories__/WithExactLength.d.ts +0 -2
- package/FieldArray/package.json +0 -6
- package/FieldObject/package.json +0 -6
- package/Fieldset/FieldsetWithContext/index.js +0 -35
- package/Fieldset/FieldsetWithContext/package.json +0 -6
- package/Fieldset/package.json +0 -6
- package/Fieldset/types/index.js +0 -1
- package/Fieldset/types/package.json +0 -6
- package/Form.stories/index.js +0 -3
- package/Form.stories/package.json +0 -6
- package/Form.stories.d.ts +0 -4
- package/FormBuilder/FormBuilder/index.js +0 -152
- package/FormBuilder/FormBuilder/package.json +0 -6
- package/FormBuilder/FormBuilder.d.ts +0 -5
- package/FormBuilder/FormBuilder.mdx +0 -256
- package/FormBuilder/FormBuilder.stories/index.js +0 -7
- package/FormBuilder/FormBuilder.stories/package.json +0 -6
- package/FormBuilder/FormBuilder.stories.d.ts +0 -8
- package/FormBuilder/FormBuilder.stories.playwright.json +0 -52
- package/FormBuilder/__stories__/Default/index.js +0 -26
- package/FormBuilder/__stories__/Default/package.json +0 -6
- package/FormBuilder/__stories__/Default.d.ts +0 -3
- package/FormBuilder/package.json +0 -6
- package/FormContext/index.js +0 -5
- package/FormContext/package.json +0 -6
- package/MultiplicityField/MultiplicityField.mdx +0 -590
- package/MultiplicityField/MultiplicityField.stories/index.js +0 -12
- package/MultiplicityField/MultiplicityField.stories/package.json +0 -6
- package/MultiplicityField/MultiplicityField.stories.d.ts +0 -13
- package/MultiplicityField/MultiplicityField.stories.playwright.json +0 -1370
- package/MultiplicityField/__stories__/Default/index.js +0 -95
- package/MultiplicityField/__stories__/Default/package.json +0 -6
- package/MultiplicityField/__stories__/Default.d.ts +0 -2
- package/MultiplicityField/__stories__/PreviewDisplay/index.js +0 -72
- package/MultiplicityField/__stories__/PreviewDisplay/package.json +0 -6
- package/MultiplicityField/__stories__/PreviewDisplay.d.ts +0 -2
- package/MultiplicityField/__stories__/WithExactLength/index.js +0 -90
- package/MultiplicityField/__stories__/WithExactLength/package.json +0 -6
- package/MultiplicityField/__stories__/WithExactLength.d.ts +0 -2
- package/MultiplicityField/__stories__/WithMaxLength/index.js +0 -93
- package/MultiplicityField/__stories__/WithMaxLength/package.json +0 -6
- package/MultiplicityField/__stories__/WithMaxLength.d.ts +0 -2
- package/MultiplicityField/__stories__/WithMinAndMaxLength/index.js +0 -94
- package/MultiplicityField/__stories__/WithMinAndMaxLength/package.json +0 -6
- package/MultiplicityField/__stories__/WithMinAndMaxLength.d.ts +0 -2
- package/MultiplicityField/__stories__/WithMinLength/index.js +0 -93
- package/MultiplicityField/__stories__/WithMinLength/package.json +0 -6
- package/MultiplicityField/__stories__/WithMinLength.d.ts +0 -2
- package/MultiplicityField/add-objects/index.js +0 -148
- package/MultiplicityField/add-objects/package.json +0 -6
- package/MultiplicityField/package.json +0 -6
- package/Questions/Questions/index.js +0 -75
- package/Questions/Questions/package.json +0 -6
- package/Questions/Questions.stories/index.js +0 -7
- package/Questions/Questions.stories/package.json +0 -6
- package/Questions/Questions.stories.d.ts +0 -8
- package/Questions/QuestionsContext/index.js +0 -11
- package/Questions/QuestionsContext/package.json +0 -6
- package/Questions/Step/ReviewStep/index.js +0 -50
- package/Questions/Step/ReviewStep/package.json +0 -6
- package/Questions/Step/Step/index.js +0 -62
- package/Questions/Step/Step/package.json +0 -6
- package/Questions/Step/StepArrayReview/index.js +0 -46
- package/Questions/Step/StepArrayReview/package.json +0 -6
- package/Questions/Step/StepContext/index.js +0 -27
- package/Questions/Step/StepContext/package.json +0 -6
- package/Questions/Step/StepDescription/index.js +0 -24
- package/Questions/Step/StepDescription/package.json +0 -6
- package/Questions/Step/StepForm/index.js +0 -44
- package/Questions/Step/StepForm/package.json +0 -6
- package/Questions/Step/StepQuote/index.js +0 -10
- package/Questions/Step/StepQuote/package.json +0 -6
- package/Questions/Step/StepTitle/index.js +0 -41
- package/Questions/Step/StepTitle/package.json +0 -6
- package/Questions/Step/getAddMoreFields/index.js +0 -21
- package/Questions/Step/getAddMoreFields/package.json +0 -6
- 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/__snapshots__/index.spec.tsx.snap +0 -596
- package/Questions/__stories__/Default/index.js +0 -102
- package/Questions/__stories__/Default/package.json +0 -6
- package/Questions/__stories__/Default.d.ts +0 -3
- package/Questions/getNextStep/index.js +0 -20
- package/Questions/getNextStep/package.json +0 -6
- package/Questions/index.spec/index.js +0 -59
- package/Questions/index.spec/package.json +0 -6
- package/Questions/index.spec.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/cjs/Field/FieldBase/index.js +0 -89
- package/cjs/Field/FieldBaseContainer/index.js +0 -47
- package/cjs/Field/FieldConditional/index.js +0 -66
- package/cjs/Field/index.js +0 -80
- package/cjs/Field/index.mdx +0 -6
- package/cjs/Field/types/index.js +0 -5
- package/cjs/Field/utils/index.js +0 -162
- package/cjs/FieldArray/FieldArray.stories/index.js +0 -38
- package/cjs/FieldArray/FieldArray.stories.playwright.json +0 -353
- package/cjs/FieldArray/__stories__/Default/index.js +0 -98
- package/cjs/FieldArray/__stories__/WithExactLength/index.js +0 -98
- package/cjs/FieldArray/index.js +0 -68
- package/cjs/FieldObject/index.js +0 -64
- package/cjs/Fieldset/FieldsetWithContext/index.js +0 -45
- package/cjs/Fieldset/index.js +0 -44
- package/cjs/Fieldset/types/index.js +0 -5
- package/cjs/Form.stories/index.js +0 -9
- package/cjs/FormBuilder/FormBuilder/index.js +0 -162
- package/cjs/FormBuilder/FormBuilder.mdx +0 -256
- package/cjs/FormBuilder/FormBuilder.stories/index.js +0 -26
- package/cjs/FormBuilder/FormBuilder.stories.playwright.json +0 -52
- package/cjs/FormBuilder/__stories__/Default/index.js +0 -36
- package/cjs/FormBuilder/index.js +0 -8
- package/cjs/FormContext/index.js +0 -11
- package/cjs/MultiplicityField/MultiplicityField.stories/index.js +0 -86
- package/cjs/MultiplicityField/MultiplicityField.stories.playwright.json +0 -1370
- package/cjs/MultiplicityField/__stories__/Default/index.js +0 -105
- package/cjs/MultiplicityField/__stories__/PreviewDisplay/index.js +0 -82
- package/cjs/MultiplicityField/__stories__/WithExactLength/index.js +0 -100
- package/cjs/MultiplicityField/__stories__/WithMaxLength/index.js +0 -103
- package/cjs/MultiplicityField/__stories__/WithMinAndMaxLength/index.js +0 -104
- package/cjs/MultiplicityField/__stories__/WithMinLength/index.js +0 -103
- package/cjs/MultiplicityField/add-objects/index.js +0 -155
- package/cjs/MultiplicityField/index.js +0 -123
- package/cjs/Questions/Questions/index.js +0 -85
- package/cjs/Questions/Questions.stories/index.js +0 -26
- package/cjs/Questions/QuestionsContext/index.js +0 -17
- package/cjs/Questions/Step/ReviewStep/index.js +0 -60
- package/cjs/Questions/Step/Step/index.js +0 -72
- package/cjs/Questions/Step/StepArrayReview/index.js +0 -56
- package/cjs/Questions/Step/StepContext/index.js +0 -33
- package/cjs/Questions/Step/StepDescription/index.js +0 -34
- package/cjs/Questions/Step/StepForm/index.js +0 -54
- package/cjs/Questions/Step/StepQuote/index.js +0 -17
- package/cjs/Questions/Step/StepTitle/index.js +0 -51
- package/cjs/Questions/Step/getAddMoreFields/index.js +0 -27
- package/cjs/Questions/Step/index.js +0 -143
- package/cjs/Questions/Step/types/index.js +0 -5
- package/cjs/Questions/__snapshots__/index.spec.tsx.snap +0 -596
- package/cjs/Questions/__stories__/Default/index.js +0 -113
- package/cjs/Questions/getNextStep/index.js +0 -26
- package/cjs/Questions/index.js +0 -21
- package/cjs/Questions/index.mdx +0 -415
- package/cjs/Questions/index.spec/index.js +0 -63
- package/cjs/Questions/types/index.js +0 -5
- package/cjs/create-simple-form.mdx +0 -539
- package/cjs/index.js +0 -22
- package/cjs/index.mdx +0 -51
- package/cjs/inputs/AutoCompleteInput/AutoComplete.stories/index.js +0 -38
- package/cjs/inputs/AutoCompleteInput/__stories__/Default/index.js +0 -51
- package/cjs/inputs/AutoCompleteInput/__stories__/Multiple/index.js +0 -52
- package/cjs/inputs/AutoCompleteInput/index.js +0 -55
- package/cjs/inputs/Checkboxes/Checkboxes.stories/index.js +0 -50
- package/cjs/inputs/Checkboxes/Checkboxes.stories.playwright.json +0 -85
- package/cjs/inputs/Checkboxes/__stories__/Conditional/index.js +0 -103
- package/cjs/inputs/Checkboxes/__stories__/Default/index.js +0 -50
- package/cjs/inputs/Checkboxes/__stories__/WithDivider/index.js +0 -51
- package/cjs/inputs/Checkboxes/index.js +0 -101
- package/cjs/inputs/Checkboxes/index.mdx +0 -33
- package/cjs/inputs/DateInput/DateInput.stories/index.js +0 -26
- package/cjs/inputs/DateInput/DateInput.stories.playwright.json +0 -72
- package/cjs/inputs/DateInput/__stories__/Default/index.js +0 -33
- package/cjs/inputs/DateInput/index.js +0 -141
- package/cjs/inputs/DateInput/index.mdx +0 -23
- package/cjs/inputs/FileInput/FileInput.stories/index.js +0 -26
- package/cjs/inputs/FileInput/FileInput.stories.playwright.json +0 -75
- package/cjs/inputs/FileInput/__stories__/Default/index.js +0 -30
- package/cjs/inputs/FileInput/index.js +0 -68
- package/cjs/inputs/FileInput/index.mdx +0 -19
- package/cjs/inputs/ImageInput/ImageInput.stories/index.js +0 -50
- package/cjs/inputs/ImageInput/ImageInput.stories.playwright.json +0 -77
- package/cjs/inputs/ImageInput/__stories__/Default/index.js +0 -38
- package/cjs/inputs/ImageInput/__stories__/WithInvalidImageDimension/index.js +0 -46
- package/cjs/inputs/ImageInput/__stories__/WithInvalidImageSize/index.js +0 -43
- package/cjs/inputs/ImageInput/index.js +0 -86
- package/cjs/inputs/ImageInput/index.mdx +0 -19
- package/cjs/inputs/Input/Input.stories/index.js +0 -134
- package/cjs/inputs/Input/Input.stories.playwright.json +0 -376
- package/cjs/inputs/Input/__stories__/AFM/index.js +0 -32
- package/cjs/inputs/Input/__stories__/Boolean/index.js +0 -33
- package/cjs/inputs/Input/__stories__/Default/index.js +0 -33
- package/cjs/inputs/Input/__stories__/IBAN/index.js +0 -33
- package/cjs/inputs/Input/__stories__/Integer/index.js +0 -41
- package/cjs/inputs/Input/__stories__/LandlineNumber/index.js +0 -36
- package/cjs/inputs/Input/__stories__/MobilePhone/index.js +0 -36
- package/cjs/inputs/Input/__stories__/PhoneNumber/index.js +0 -35
- package/cjs/inputs/Input/__stories__/PostalCode/index.js +0 -35
- package/cjs/inputs/Input/__stories__/TextWithCharacterLimit/index.js +0 -39
- package/cjs/inputs/Input/index.js +0 -76
- package/cjs/inputs/Input/index.mdx +0 -95
- package/cjs/inputs/Label/Label.stories/index.js +0 -26
- package/cjs/inputs/Label/Label.stories.playwright.json +0 -40
- package/cjs/inputs/Label/__stories__/Default/index.js +0 -37
- package/cjs/inputs/Label/index.js +0 -29
- package/cjs/inputs/OtpInput/OtpInput.stories/index.js +0 -26
- package/cjs/inputs/OtpInput/__stories__/Default/index.js +0 -39
- package/cjs/inputs/OtpInput/index.js +0 -151
- package/cjs/inputs/Radio/Radio.stories/index.js +0 -50
- package/cjs/inputs/Radio/Radio.stories.playwright.json +0 -73
- package/cjs/inputs/Radio/__stories__/Conditional/index.js +0 -103
- package/cjs/inputs/Radio/__stories__/Default/index.js +0 -55
- package/cjs/inputs/Radio/__stories__/WithDivider/index.js +0 -56
- package/cjs/inputs/Radio/index.js +0 -64
- package/cjs/inputs/Select/Select.stories/index.js +0 -26
- package/cjs/inputs/Select/Select.stories.playwright.json +0 -22
- package/cjs/inputs/Select/__stories__/Default/index.js +0 -61
- package/cjs/inputs/Select/index.js +0 -38
- package/cjs/inputs/Select/index.mdx +0 -17
- package/cjs/inputs/index.js +0 -69
- package/cjs/installation.mdx +0 -68
- package/cjs/internal/index.js +0 -348
- package/cjs/lazy/index.js +0 -517
- package/cjs/registry/index.js +0 -147
- package/cjs/types/index.js +0 -5
- package/cjs/utils/index.js +0 -87
- package/cjs/validators/index.js +0 -193
- package/cjs/validators/types/index.js +0 -5
- package/cjs/validators/utils/afm/index.js +0 -38
- package/cjs/validators/utils/file/index.js +0 -43
- package/cjs/validators/utils/iban/index.js +0 -123
- package/cjs/validators/utils/image/index.js +0 -126
- package/cjs/validators/utils/index.js +0 -204
- package/cjs/validators/utils/int/index.js +0 -26
- package/cjs/validators/utils/number/index.js +0 -22
- package/cjs/validators/utils/otp/index.js +0 -32
- package/cjs/validators/utils/phone/index.js +0 -143
- package/cjs/validators/utils/postal_code/index.js +0 -34
- package/cjs/validators/utils/text_limit/index.js +0 -54
- package/cjs/validators/utils/uuid4/index.js +0 -25
- package/cjs/validators/validators.spec/index.js +0 -87
- package/create-simple-form.mdx +0 -539
- package/index.mdx +0 -51
- package/inputs/AutoCompleteInput/AutoComplete.stories/index.js +0 -8
- package/inputs/AutoCompleteInput/AutoComplete.stories/package.json +0 -6
- package/inputs/AutoCompleteInput/AutoComplete.stories.d.ts +0 -9
- package/inputs/AutoCompleteInput/__stories__/Default/index.js +0 -44
- package/inputs/AutoCompleteInput/__stories__/Default/package.json +0 -6
- package/inputs/AutoCompleteInput/__stories__/Default.d.ts +0 -3
- package/inputs/AutoCompleteInput/__stories__/Multiple/index.js +0 -45
- package/inputs/AutoCompleteInput/__stories__/Multiple/package.json +0 -6
- package/inputs/AutoCompleteInput/__stories__/Multiple.d.ts +0 -3
- package/inputs/AutoCompleteInput/index.mdx +0 -29
- package/inputs/AutoCompleteInput/package.json +0 -6
- package/inputs/Checkboxes/Checkboxes.stories/index.js +0 -9
- package/inputs/Checkboxes/Checkboxes.stories/package.json +0 -6
- package/inputs/Checkboxes/Checkboxes.stories.d.ts +0 -10
- package/inputs/Checkboxes/Checkboxes.stories.playwright.json +0 -85
- package/inputs/Checkboxes/__stories__/Conditional/index.js +0 -93
- package/inputs/Checkboxes/__stories__/Conditional/package.json +0 -6
- package/inputs/Checkboxes/__stories__/Conditional.d.ts +0 -3
- package/inputs/Checkboxes/__stories__/Default/index.js +0 -40
- package/inputs/Checkboxes/__stories__/Default/package.json +0 -6
- package/inputs/Checkboxes/__stories__/Default.d.ts +0 -3
- package/inputs/Checkboxes/__stories__/WithDivider/index.js +0 -41
- package/inputs/Checkboxes/__stories__/WithDivider/package.json +0 -6
- package/inputs/Checkboxes/__stories__/WithDivider.d.ts +0 -3
- package/inputs/Checkboxes/index.mdx +0 -33
- package/inputs/Checkboxes/package.json +0 -6
- package/inputs/DateInput/DateInput.stories/index.js +0 -7
- package/inputs/DateInput/DateInput.stories/package.json +0 -6
- package/inputs/DateInput/DateInput.stories.d.ts +0 -8
- package/inputs/DateInput/DateInput.stories.playwright.json +0 -72
- package/inputs/DateInput/__stories__/Default/index.js +0 -23
- package/inputs/DateInput/__stories__/Default/package.json +0 -6
- package/inputs/DateInput/__stories__/Default.d.ts +0 -3
- package/inputs/DateInput/index.mdx +0 -23
- package/inputs/DateInput/package.json +0 -6
- package/inputs/FileInput/FileInput.stories/index.js +0 -7
- package/inputs/FileInput/FileInput.stories/package.json +0 -6
- package/inputs/FileInput/FileInput.stories.d.ts +0 -8
- package/inputs/FileInput/FileInput.stories.playwright.json +0 -75
- package/inputs/FileInput/__stories__/Default/index.js +0 -20
- package/inputs/FileInput/__stories__/Default/package.json +0 -6
- package/inputs/FileInput/__stories__/Default.d.ts +0 -3
- package/inputs/FileInput/package.json +0 -6
- package/inputs/ImageInput/ImageInput.stories/index.js +0 -9
- package/inputs/ImageInput/ImageInput.stories/package.json +0 -6
- package/inputs/ImageInput/ImageInput.stories.d.ts +0 -10
- package/inputs/ImageInput/ImageInput.stories.playwright.json +0 -77
- package/inputs/ImageInput/__stories__/Default/index.js +0 -28
- package/inputs/ImageInput/__stories__/Default/package.json +0 -6
- package/inputs/ImageInput/__stories__/Default.d.ts +0 -3
- package/inputs/ImageInput/__stories__/WithInvalidImageDimension/index.js +0 -36
- package/inputs/ImageInput/__stories__/WithInvalidImageDimension/package.json +0 -6
- package/inputs/ImageInput/__stories__/WithInvalidImageDimension.d.ts +0 -3
- package/inputs/ImageInput/__stories__/WithInvalidImageSize/index.js +0 -33
- package/inputs/ImageInput/__stories__/WithInvalidImageSize/package.json +0 -6
- package/inputs/ImageInput/__stories__/WithInvalidImageSize.d.ts +0 -3
- package/inputs/ImageInput/index.mdx +0 -19
- package/inputs/ImageInput/package.json +0 -6
- package/inputs/Input/Input.stories/index.js +0 -16
- package/inputs/Input/Input.stories/package.json +0 -6
- package/inputs/Input/Input.stories.d.ts +0 -17
- package/inputs/Input/Input.stories.playwright.json +0 -376
- package/inputs/Input/__stories__/AFM/index.js +0 -22
- package/inputs/Input/__stories__/AFM/package.json +0 -6
- package/inputs/Input/__stories__/AFM.d.ts +0 -3
- package/inputs/Input/__stories__/Boolean/index.js +0 -23
- package/inputs/Input/__stories__/Boolean/package.json +0 -6
- package/inputs/Input/__stories__/Boolean.d.ts +0 -3
- package/inputs/Input/__stories__/Default/index.js +0 -23
- package/inputs/Input/__stories__/Default/package.json +0 -6
- package/inputs/Input/__stories__/Default.d.ts +0 -3
- package/inputs/Input/__stories__/IBAN/index.js +0 -23
- package/inputs/Input/__stories__/IBAN/package.json +0 -6
- package/inputs/Input/__stories__/IBAN.d.ts +0 -3
- package/inputs/Input/__stories__/Integer/index.js +0 -31
- package/inputs/Input/__stories__/Integer/package.json +0 -6
- package/inputs/Input/__stories__/Integer.d.ts +0 -3
- package/inputs/Input/__stories__/LandlineNumber/index.js +0 -26
- package/inputs/Input/__stories__/LandlineNumber/package.json +0 -6
- package/inputs/Input/__stories__/LandlineNumber.d.ts +0 -3
- package/inputs/Input/__stories__/MobilePhone/index.js +0 -26
- package/inputs/Input/__stories__/MobilePhone/package.json +0 -6
- package/inputs/Input/__stories__/MobilePhone.d.ts +0 -3
- package/inputs/Input/__stories__/PhoneNumber/index.js +0 -25
- package/inputs/Input/__stories__/PhoneNumber/package.json +0 -6
- package/inputs/Input/__stories__/PhoneNumber.d.ts +0 -3
- package/inputs/Input/__stories__/PostalCode/index.js +0 -25
- package/inputs/Input/__stories__/PostalCode/package.json +0 -6
- package/inputs/Input/__stories__/PostalCode.d.ts +0 -3
- package/inputs/Input/__stories__/TextWithCharacterLimit/index.js +0 -29
- package/inputs/Input/__stories__/TextWithCharacterLimit/package.json +0 -6
- package/inputs/Input/__stories__/TextWithCharacterLimit.d.ts +0 -3
- package/inputs/Input/index.mdx +0 -95
- package/inputs/Input/package.json +0 -6
- package/inputs/Label/Label.stories/index.js +0 -7
- package/inputs/Label/Label.stories/package.json +0 -6
- package/inputs/Label/Label.stories.d.ts +0 -8
- package/inputs/Label/Label.stories.playwright.json +0 -40
- package/inputs/Label/__stories__/Default/index.js +0 -27
- package/inputs/Label/__stories__/Default/package.json +0 -6
- package/inputs/Label/__stories__/Default.d.ts +0 -3
- package/inputs/Label/package.json +0 -6
- package/inputs/OtpInput/OtpInput.stories/index.js +0 -7
- package/inputs/OtpInput/OtpInput.stories/package.json +0 -6
- package/inputs/OtpInput/OtpInput.stories.d.ts +0 -8
- package/inputs/OtpInput/__stories__/Default/index.js +0 -29
- package/inputs/OtpInput/__stories__/Default/package.json +0 -6
- package/inputs/OtpInput/__stories__/Default.d.ts +0 -3
- package/inputs/OtpInput/index.mdx +0 -23
- package/inputs/OtpInput/package.json +0 -6
- package/inputs/Radio/Radio.stories/index.js +0 -9
- package/inputs/Radio/Radio.stories/package.json +0 -6
- package/inputs/Radio/Radio.stories.d.ts +0 -10
- package/inputs/Radio/Radio.stories.playwright.json +0 -73
- package/inputs/Radio/__stories__/Conditional/index.js +0 -93
- package/inputs/Radio/__stories__/Conditional/package.json +0 -6
- package/inputs/Radio/__stories__/Conditional.d.ts +0 -3
- package/inputs/Radio/__stories__/Default/index.js +0 -45
- package/inputs/Radio/__stories__/Default/package.json +0 -6
- package/inputs/Radio/__stories__/Default.d.ts +0 -3
- package/inputs/Radio/__stories__/WithDivider/index.js +0 -46
- package/inputs/Radio/__stories__/WithDivider/package.json +0 -6
- package/inputs/Radio/__stories__/WithDivider.d.ts +0 -3
- package/inputs/Radio/index.mdx +0 -33
- package/inputs/Radio/package.json +0 -6
- package/inputs/Select/Select.stories/index.js +0 -7
- package/inputs/Select/Select.stories/package.json +0 -6
- package/inputs/Select/Select.stories.d.ts +0 -8
- package/inputs/Select/Select.stories.playwright.json +0 -22
- package/inputs/Select/__stories__/Default/index.js +0 -51
- package/inputs/Select/__stories__/Default/package.json +0 -6
- package/inputs/Select/__stories__/Default.d.ts +0 -3
- package/inputs/Select/index.mdx +0 -17
- package/inputs/Select/package.json +0 -6
- package/inputs/package.json +0 -6
- package/installation.mdx +0 -68
- package/internal/index.js +0 -34
- package/internal/package.json +0 -6
- package/lazy/index.js +0 -395
- package/lazy/package.json +0 -6
- package/registry/index.js +0 -138
- package/registry/package.json +0 -6
- package/src/Field/index.mdx +0 -6
- package/src/Field/utils.ts +0 -191
- package/src/FieldArray/FieldArray.stories.playwright.json +0 -353
- package/src/FormBuilder/FormBuilder.stories.playwright.json +0 -52
- package/src/FormBuilder/FormBuilder.tsx +0 -166
- package/src/MultiplicityField/MultiplicityField.mdx +0 -590
- package/src/MultiplicityField/MultiplicityField.stories.playwright.json +0 -1370
- package/src/Questions/index.mdx +0 -415
- package/src/inputs/AutoCompleteInput/index.mdx +0 -29
- package/src/inputs/Checkboxes/Checkboxes.stories.playwright.json +0 -85
- package/src/inputs/DateInput/DateInput.stories.playwright.json +0 -72
- package/src/inputs/FileInput/FileInput.stories.playwright.json +0 -75
- package/src/inputs/FileInput/index.mdx +0 -19
- package/src/inputs/ImageInput/ImageInput.stories.playwright.json +0 -77
- package/src/inputs/ImageInput/index.mdx +0 -19
- package/src/inputs/Input/Input.stories.playwright.json +0 -376
- package/src/inputs/Input/index.mdx +0 -95
- package/src/inputs/Label/Label.stories.playwright.json +0 -40
- package/src/inputs/OtpInput/index.mdx +0 -23
- package/src/inputs/Radio/Radio.stories.playwright.json +0 -73
- package/src/inputs/Radio/index.mdx +0 -33
- package/src/inputs/Select/Select.stories.playwright.json +0 -22
- package/src/lazy.js +0 -60
- package/src/registry.js +0 -145
- package/types/index.js +0 -1
- package/types/package.json +0 -6
- package/utils/index.js +0 -80
- package/utils/package.json +0 -6
- package/validators/package.json +0 -6
- package/validators/types/index.js +0 -1
- package/validators/types/package.json +0 -6
- package/validators/utils/afm/index.js +0 -31
- package/validators/utils/afm/package.json +0 -6
- package/validators/utils/file/index.js +0 -37
- package/validators/utils/file/package.json +0 -6
- package/validators/utils/iban/index.js +0 -116
- package/validators/utils/iban/package.json +0 -6
- package/validators/utils/image/index.js +0 -119
- package/validators/utils/image/package.json +0 -6
- package/validators/utils/int/index.js +0 -19
- package/validators/utils/int/package.json +0 -6
- package/validators/utils/number/index.js +0 -15
- package/validators/utils/number/package.json +0 -6
- package/validators/utils/otp/index.js +0 -25
- package/validators/utils/otp/package.json +0 -6
- package/validators/utils/package.json +0 -6
- package/validators/utils/phone/index.js +0 -134
- package/validators/utils/phone/package.json +0 -6
- package/validators/utils/postal_code/index.js +0 -27
- package/validators/utils/postal_code/package.json +0 -6
- package/validators/utils/text_limit/index.js +0 -47
- package/validators/utils/text_limit/package.json +0 -6
- package/validators/utils/uuid4/index.js +0 -18
- package/validators/utils/uuid4/package.json +0 -6
- package/validators/validators.spec/index.js +0 -85
- package/validators/validators.spec/package.json +0 -6
- package/validators/validators.spec.d.ts +0 -1
- /package/{cjs/inputs/Label/index.mdx → Field/types.js} +0 -0
- /package/{inputs/Label/index.mdx → Fieldset/types.js} +0 -0
- /package/{src/inputs/Label/index.mdx → MultiplicityField/types.js} +0 -0
package/src/validators/index.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import { MutableRefObject
|
|
2
|
-
import
|
|
3
|
-
import customParseFormat from 'dayjs/plugin/customParseFormat';
|
|
1
|
+
import type { MutableRefObject } from 'react';
|
|
2
|
+
import { useMemo } from 'react';
|
|
4
3
|
import * as yup from 'yup';
|
|
5
|
-
import { AnyObjectSchema, StringSchema } from 'yup';
|
|
6
|
-
import { RequiredArraySchema } from 'yup/lib/array';
|
|
7
|
-
import Lazy from 'yup/lib/Lazy';
|
|
8
|
-
import { MixedSchema } from 'yup/lib/mixed';
|
|
9
|
-
import { TypeOfShape, AssertsShape } from 'yup/lib/object';
|
|
10
|
-
import { AnyObject } from 'yup/lib/types';
|
|
11
|
-
import { FieldSpec } from '@digigov/form/types';
|
|
12
|
-
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';
|
|
13
12
|
import {
|
|
14
13
|
getYupObjectShape,
|
|
15
14
|
AFM_VALIDATOR,
|
|
15
|
+
AMKA_VALIDATOR,
|
|
16
16
|
FILE_MAX_SIZE_VALIDATOR,
|
|
17
17
|
IBAN_VALIDATOR,
|
|
18
18
|
OTP_VALIDATOR,
|
|
@@ -22,24 +22,26 @@ import {
|
|
|
22
22
|
POSTALCODE_VALIDATOR,
|
|
23
23
|
UUID4_VALIDATOR,
|
|
24
24
|
IMAGE_DIMENSION_VALIDATOR,
|
|
25
|
+
DATE_VALIDATOR,
|
|
26
|
+
LATER_THAN_VALIDATOR,
|
|
27
|
+
EARLIER_THAN_VALIDATOR,
|
|
28
|
+
DATETIME_VALIDATOR,
|
|
29
|
+
LATER_THAN_DATETIME_VALIDATOR,
|
|
30
|
+
EARLIER_THAN_DATETIME_VALIDATOR,
|
|
25
31
|
} from '@digigov/form/validators/utils';
|
|
32
|
+
import { EMAIL_VALIDATOR } from '@digigov/form/validators/utils/email';
|
|
26
33
|
import { INT_VALIDATOR } from '@digigov/form/validators/utils/int';
|
|
27
34
|
import { NUMBER_VALIDATOR } from '@digigov/form/validators/utils/number';
|
|
28
|
-
dayjs.extend(customParseFormat);
|
|
29
35
|
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return DATE_CACHE[v] ? DATE_CACHE[v] : dayjs(v, VALID_DATE_FORMATS, true);
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
export const getYUPTypeMap = (): Record<string, any> => {
|
|
36
|
+
export const getYUPTypeMap = (
|
|
37
|
+
validatorRegistry?: Record<string, any>
|
|
38
|
+
): Record<string, any> => {
|
|
37
39
|
const yupTypeMap = {
|
|
38
40
|
file: (field): MixedSchema => {
|
|
39
41
|
return yup
|
|
40
42
|
.mixed()
|
|
41
43
|
.transform((value) => {
|
|
42
|
-
if (!value.length) {
|
|
44
|
+
if (!value || value.length === 0) {
|
|
43
45
|
return null;
|
|
44
46
|
}
|
|
45
47
|
return value;
|
|
@@ -47,8 +49,28 @@ export const getYUPTypeMap = (): Record<string, any> => {
|
|
|
47
49
|
.nullable()
|
|
48
50
|
.test(FILE_MAX_SIZE_VALIDATOR(field));
|
|
49
51
|
},
|
|
50
|
-
string: yup.
|
|
51
|
-
|
|
52
|
+
string: (field): yup.StringSchema => {
|
|
53
|
+
if (field.trim) {
|
|
54
|
+
return yup.string().trim();
|
|
55
|
+
} else {
|
|
56
|
+
return yup.string();
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
boolean: (): yup.BooleanSchema<
|
|
60
|
+
boolean | null | undefined,
|
|
61
|
+
AnyObject,
|
|
62
|
+
boolean | null | undefined
|
|
63
|
+
> => {
|
|
64
|
+
return yup
|
|
65
|
+
.boolean()
|
|
66
|
+
.nullable()
|
|
67
|
+
.transform((value) => {
|
|
68
|
+
if (value === '' || typeof value === 'string') return null;
|
|
69
|
+
if (typeof value === 'boolean') return value;
|
|
70
|
+
if (value === 0 || value === 1) return Boolean(value);
|
|
71
|
+
return value;
|
|
72
|
+
});
|
|
73
|
+
},
|
|
52
74
|
object: (
|
|
53
75
|
field
|
|
54
76
|
):
|
|
@@ -56,6 +78,24 @@ export const getYUPTypeMap = (): Record<string, any> => {
|
|
|
56
78
|
| Lazy<any, unknown> => {
|
|
57
79
|
return getYupObjectShape(field.extra.fields, yupTypeMap);
|
|
58
80
|
},
|
|
81
|
+
rate: (field) => {
|
|
82
|
+
const min = field?.min ? field.min : 0;
|
|
83
|
+
const max = field?.max ? field.max : 100;
|
|
84
|
+
return yup
|
|
85
|
+
.number()
|
|
86
|
+
.transform((v, o) => (o === '' ? null : v))
|
|
87
|
+
.nullable()
|
|
88
|
+
.notRequired()
|
|
89
|
+
.integer({ key: 'form.error.positive_integer_number' })
|
|
90
|
+
.min(min, {
|
|
91
|
+
key: 'form.error.rate.rate_percent',
|
|
92
|
+
context: { min: min, max: max },
|
|
93
|
+
})
|
|
94
|
+
.max(max, {
|
|
95
|
+
key: 'form.error.rate.rate_percent',
|
|
96
|
+
context: { min: min, max: max },
|
|
97
|
+
});
|
|
98
|
+
},
|
|
59
99
|
array: (
|
|
60
100
|
field
|
|
61
101
|
):
|
|
@@ -64,10 +104,13 @@ export const getYUPTypeMap = (): Record<string, any> => {
|
|
|
64
104
|
if (typeof field.extra.of === 'object') {
|
|
65
105
|
// else if the field is an object then it is a scalar type
|
|
66
106
|
// eg. number, string etc.
|
|
107
|
+
if (field.required) {
|
|
108
|
+
field.extra.min = 1;
|
|
109
|
+
}
|
|
67
110
|
let arrayValidator = yup
|
|
68
111
|
.array()
|
|
69
|
-
.
|
|
70
|
-
.
|
|
112
|
+
.nullable()
|
|
113
|
+
.of(yupTypeMap[field.extra.of.type](field.extra.of));
|
|
71
114
|
if (field.extra.length)
|
|
72
115
|
arrayValidator = arrayValidator.length(field.extra.length, {
|
|
73
116
|
key: 'form.error.array.length',
|
|
@@ -80,12 +123,14 @@ export const getYUPTypeMap = (): Record<string, any> => {
|
|
|
80
123
|
key: 'form.error.array.min',
|
|
81
124
|
context: {
|
|
82
125
|
min: field.extra.min,
|
|
126
|
+
max: field.extra.max || undefined,
|
|
83
127
|
},
|
|
84
128
|
});
|
|
85
129
|
if (field.extra.max)
|
|
86
130
|
arrayValidator = arrayValidator.max(field.extra.max, {
|
|
87
131
|
key: 'form.error.array.max',
|
|
88
132
|
context: {
|
|
133
|
+
min: field.extra.min || undefined,
|
|
89
134
|
max: field.extra.max,
|
|
90
135
|
},
|
|
91
136
|
});
|
|
@@ -97,22 +142,46 @@ export const getYUPTypeMap = (): Record<string, any> => {
|
|
|
97
142
|
return yup.array().of(yup.string());
|
|
98
143
|
}
|
|
99
144
|
},
|
|
145
|
+
number: (): MixedSchema =>
|
|
146
|
+
yup
|
|
147
|
+
.mixed()
|
|
148
|
+
.transform((_, val) => (val !== '' ? Number(val) : undefined))
|
|
149
|
+
.test(NUMBER_VALIDATOR()),
|
|
100
150
|
int: (): MixedSchema =>
|
|
101
151
|
yup
|
|
102
152
|
.mixed()
|
|
103
|
-
.transform((_, val) => (val !== '' ? Number(val) :
|
|
153
|
+
.transform((_, val) => (val !== '' ? Number(val) : undefined))
|
|
104
154
|
.test(NUMBER_VALIDATOR())
|
|
105
155
|
.test(INT_VALIDATOR()),
|
|
106
|
-
email: (): yup.StringSchema =>
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
156
|
+
email: (field): yup.StringSchema =>
|
|
157
|
+
field.trim
|
|
158
|
+
? yup.string().trim().test(EMAIL_VALIDATOR)
|
|
159
|
+
: yup.string().test(EMAIL_VALIDATOR),
|
|
160
|
+
afm: (field): yup.StringSchema =>
|
|
161
|
+
field.trim
|
|
162
|
+
? yup.string().trim().test(AFM_VALIDATOR)
|
|
163
|
+
: yup.string().test(AFM_VALIDATOR),
|
|
164
|
+
amka: (field): yup.StringSchema =>
|
|
165
|
+
field.trim
|
|
166
|
+
? yup.string().trim().test(AMKA_VALIDATOR)
|
|
167
|
+
: yup.string().test(AMKA_VALIDATOR),
|
|
168
|
+
uuid4: (field): yup.StringSchema =>
|
|
169
|
+
field.trim
|
|
170
|
+
? yup.string().trim().test(UUID4_VALIDATOR)
|
|
171
|
+
: yup.string().test(UUID4_VALIDATOR),
|
|
172
|
+
iban: (field): yup.StringSchema =>
|
|
173
|
+
field.trim
|
|
174
|
+
? yup.string().trim().test(IBAN_VALIDATOR(field))
|
|
175
|
+
: yup.string().trim().test(IBAN_VALIDATOR(field)),
|
|
176
|
+
otp: (field): yup.StringSchema =>
|
|
177
|
+
yup.string().trim().test(OTP_VALIDATOR(field)),
|
|
111
178
|
text: (field): yup.StringSchema => {
|
|
112
179
|
if (field?.extra?.limit?.max || !!field?.extra?.limit?.min) {
|
|
113
|
-
return
|
|
180
|
+
return field.trim
|
|
181
|
+
? yup.string().trim().test(TEXT_LIMIT_VALIDATOR(field))
|
|
182
|
+
: yup.string().test(TEXT_LIMIT_VALIDATOR(field));
|
|
114
183
|
} else {
|
|
115
|
-
return yup.string();
|
|
184
|
+
return field.trim ? yup.string().trim() : yup.string();
|
|
116
185
|
}
|
|
117
186
|
},
|
|
118
187
|
image: (field): MixedSchema => {
|
|
@@ -129,11 +198,17 @@ export const getYUPTypeMap = (): Record<string, any> => {
|
|
|
129
198
|
.test(IMAGE_DIMENSION_VALIDATOR(field));
|
|
130
199
|
},
|
|
131
200
|
postal_code: (field): yup.StringSchema =>
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
201
|
+
field.trim
|
|
202
|
+
? yup.string().trim().test(POSTALCODE_VALIDATOR(field))
|
|
203
|
+
: yup.string().test(POSTALCODE_VALIDATOR(field)),
|
|
204
|
+
mobile_phone: (field): yup.StringSchema =>
|
|
205
|
+
field.trim
|
|
206
|
+
? yup.string().trim().test(MOBILE_PHONE_VALIDATOR)
|
|
207
|
+
: yup.string().test(MOBILE_PHONE_VALIDATOR),
|
|
135
208
|
phone_number: (field): yup.StringSchema =>
|
|
136
|
-
|
|
209
|
+
field.trim
|
|
210
|
+
? yup.string().trim().test(PHONE_NUMBER_VALIDATOR(field))
|
|
211
|
+
: yup.string().test(PHONE_NUMBER_VALIDATOR(field)),
|
|
137
212
|
'choice:multiple': (): yup.ArraySchema<
|
|
138
213
|
yup.StringSchema<string | undefined, AnyObject, string | undefined>,
|
|
139
214
|
AnyObject,
|
|
@@ -145,70 +220,34 @@ export const getYUPTypeMap = (): Record<string, any> => {
|
|
|
145
220
|
AnyObject,
|
|
146
221
|
string | null | undefined
|
|
147
222
|
> => yup.string().nullable(),
|
|
148
|
-
date: (
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
if (params.max) {
|
|
159
|
-
let maxDate;
|
|
160
|
-
if (params.max === 'now') {
|
|
161
|
-
const today = new Date();
|
|
162
|
-
maxDate = new Date(today);
|
|
163
|
-
} else {
|
|
164
|
-
maxDate = getDate(params.max).toDate();
|
|
165
|
-
}
|
|
166
|
-
const maxNextDate = new Date(maxDate);
|
|
167
|
-
maxNextDate.setDate(maxDate.getDate() + 1);
|
|
168
|
-
simpleDate = simpleDate.test({
|
|
169
|
-
name: 'earlier-than',
|
|
170
|
-
message: {
|
|
171
|
-
key: 'form.error.date.earlier_than',
|
|
172
|
-
context: {
|
|
173
|
-
maxDate: maxNextDate.toLocaleDateString(),
|
|
174
|
-
},
|
|
175
|
-
},
|
|
176
|
-
test: function (value) {
|
|
177
|
-
if (!value) return true;
|
|
178
|
-
const date = getDate(value);
|
|
179
|
-
const isValid = +date.toDate() < +maxDate;
|
|
180
|
-
return isValid;
|
|
181
|
-
},
|
|
182
|
-
});
|
|
223
|
+
date: (
|
|
224
|
+
field
|
|
225
|
+
): yup.StringSchema<
|
|
226
|
+
string | null | undefined,
|
|
227
|
+
AnyObject,
|
|
228
|
+
string | null | undefined
|
|
229
|
+
> => {
|
|
230
|
+
let schema = yup.string().nullable();
|
|
231
|
+
if (field?.extra?.min) {
|
|
232
|
+
schema = schema.test(LATER_THAN_VALIDATOR(field));
|
|
183
233
|
}
|
|
184
|
-
if (
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
key: 'form.error.date.later_than',
|
|
198
|
-
context: {
|
|
199
|
-
minDate: minPreviousDate.toLocaleDateString(),
|
|
200
|
-
},
|
|
201
|
-
},
|
|
202
|
-
test: function (value) {
|
|
203
|
-
if (!value) return true;
|
|
204
|
-
const date = getDate(value);
|
|
205
|
-
const isValid = +date.toDate() > +minDate;
|
|
206
|
-
return isValid;
|
|
207
|
-
},
|
|
208
|
-
});
|
|
234
|
+
if (field?.extra?.max) {
|
|
235
|
+
schema = schema.test(EARLIER_THAN_VALIDATOR(field));
|
|
236
|
+
} else {
|
|
237
|
+
schema = schema.test(DATE_VALIDATOR);
|
|
238
|
+
}
|
|
239
|
+
return schema;
|
|
240
|
+
},
|
|
241
|
+
datetime: (field): yup.StringSchema => {
|
|
242
|
+
if (field?.extra?.min) {
|
|
243
|
+
return yup.string().test(LATER_THAN_DATETIME_VALIDATOR(field));
|
|
244
|
+
}
|
|
245
|
+
if (field?.extra?.max) {
|
|
246
|
+
return yup.string().test(EARLIER_THAN_DATETIME_VALIDATOR(field));
|
|
209
247
|
}
|
|
210
|
-
return
|
|
248
|
+
return yup.string().test(DATETIME_VALIDATOR);
|
|
211
249
|
},
|
|
250
|
+
...validatorRegistry,
|
|
212
251
|
};
|
|
213
252
|
return yupTypeMap;
|
|
214
253
|
};
|
|
@@ -220,7 +259,7 @@ export function useValidationSchema(
|
|
|
220
259
|
validatorRegistry?: Record<string, ValidatorSchema[]>
|
|
221
260
|
): Lazy<any, unknown> | AnyObjectSchema | void {
|
|
222
261
|
return useMemo(() => {
|
|
223
|
-
const yupTypeMap = getYUPTypeMap();
|
|
262
|
+
const yupTypeMap = getYUPTypeMap(validatorRegistry);
|
|
224
263
|
return getYupObjectShape(fields, yupTypeMap, validatorRegistry);
|
|
225
|
-
}, []);
|
|
264
|
+
}, [fields, validatorRegistry]);
|
|
226
265
|
}
|
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;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
function digitSum(number) {
|
|
2
|
+
const sum = number > 9 ? 1 : 0;
|
|
3
|
+
return sum + (number % 10);
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export function validateAMKA(amka: string): boolean {
|
|
7
|
+
// Validate that the last digit is the correct check digit (created using the
|
|
8
|
+
// Luhn algorithm https://en.wikipedia.org/wiki/Luhn_algorithm).
|
|
9
|
+
amka = String(amka);
|
|
10
|
+
const checkDigitIndex = amka.length - 1;
|
|
11
|
+
let sum = 0;
|
|
12
|
+
amka
|
|
13
|
+
.substring(0, checkDigitIndex)
|
|
14
|
+
.split('')
|
|
15
|
+
.reverse()
|
|
16
|
+
.forEach(function (value, index) {
|
|
17
|
+
const weight = ((index + 1) % 2) + 1;
|
|
18
|
+
sum += digitSum(parseInt(value, 10) * weight);
|
|
19
|
+
});
|
|
20
|
+
const sumMod10 = sum % 10;
|
|
21
|
+
if (sumMod10 === 0) {
|
|
22
|
+
return amka.substring(checkDigitIndex) === '0';
|
|
23
|
+
} else {
|
|
24
|
+
return amka.substring(checkDigitIndex) === 10 - sumMod10 + '';
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const AMKA_VALIDATOR = {
|
|
29
|
+
name: 'amka-validator',
|
|
30
|
+
message: 'form.error.amka',
|
|
31
|
+
test: (value): boolean => {
|
|
32
|
+
if (!value) return true;
|
|
33
|
+
const AMKA_REGEX = /^[0-9]{11}$/;
|
|
34
|
+
if (!AMKA_REGEX.test(value) || value === '00000000000') {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
return validateAMKA(value);
|
|
38
|
+
},
|
|
39
|
+
};
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import dayjs from 'dayjs';
|
|
2
|
+
import customParseFormat from 'dayjs/plugin/customParseFormat';
|
|
3
|
+
import type { FieldSpec } from '@digigov/form/types';
|
|
4
|
+
import type { ValidatorSchema } from '@digigov/form/validators/types';
|
|
5
|
+
|
|
6
|
+
dayjs.extend(customParseFormat);
|
|
7
|
+
|
|
8
|
+
const VALID_DATE_FORMATS = ['DD/MM/YYYY'];
|
|
9
|
+
const DATE_CACHE = {};
|
|
10
|
+
const onlyNumbersRegex = /^\d+$/;
|
|
11
|
+
|
|
12
|
+
const getDate = (v: string) => {
|
|
13
|
+
return DATE_CACHE[v] ? DATE_CACHE[v] : dayjs(v, VALID_DATE_FORMATS, true);
|
|
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
|
+
|
|
20
|
+
// Function to check partial date completion
|
|
21
|
+
const checkPartialDate = (value: string) => {
|
|
22
|
+
const [day, month, year] = value.split('/');
|
|
23
|
+
if (day && !month && !year) {
|
|
24
|
+
return 'form.error.date.invalid_month_year';
|
|
25
|
+
}
|
|
26
|
+
if (!day && month && !year) {
|
|
27
|
+
return 'form.error.date.invalid_day_year';
|
|
28
|
+
}
|
|
29
|
+
if (!day && !month && year) {
|
|
30
|
+
return 'form.error.date.invalid_day_month';
|
|
31
|
+
}
|
|
32
|
+
if (day && month && !year) {
|
|
33
|
+
return 'form.error.date.invalid_year';
|
|
34
|
+
}
|
|
35
|
+
if (day && !month && year) {
|
|
36
|
+
return 'form.error.date.invalid_month';
|
|
37
|
+
}
|
|
38
|
+
if (!day && month && year) {
|
|
39
|
+
return 'form.error.date.invalid_day';
|
|
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';
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export const LATER_THAN_VALIDATOR = (field: FieldSpec): ValidatorSchema => {
|
|
66
|
+
let minDate;
|
|
67
|
+
const params = field.extra || {};
|
|
68
|
+
if (params.min === 'now') {
|
|
69
|
+
const today = new Date();
|
|
70
|
+
minDate = new Date(today);
|
|
71
|
+
} else {
|
|
72
|
+
minDate = getDate(params.min).toDate();
|
|
73
|
+
}
|
|
74
|
+
const minPreviousDate = new Date(minDate);
|
|
75
|
+
minPreviousDate.setDate(minDate.getDate() - 1);
|
|
76
|
+
return {
|
|
77
|
+
name: 'later-than',
|
|
78
|
+
message: {
|
|
79
|
+
key: 'form.error.date.later_than',
|
|
80
|
+
context: {
|
|
81
|
+
minDate: minPreviousDate.toLocaleDateString(),
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
test: function (value: string) {
|
|
85
|
+
if (!value) return true;
|
|
86
|
+
const date = getDate(value);
|
|
87
|
+
const isValid = +date.toDate() > +minDate;
|
|
88
|
+
return isValid;
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
export const EARLIER_THAN_VALIDATOR = (field: FieldSpec): ValidatorSchema => {
|
|
94
|
+
let maxDate;
|
|
95
|
+
const params = field.extra || {};
|
|
96
|
+
if (params.max === 'now') {
|
|
97
|
+
const today = new Date();
|
|
98
|
+
maxDate = new Date(today);
|
|
99
|
+
} else {
|
|
100
|
+
maxDate = getDate(params.max).toDate();
|
|
101
|
+
}
|
|
102
|
+
const maxNextDate = new Date(maxDate);
|
|
103
|
+
maxNextDate.setDate(maxDate.getDate() + 1);
|
|
104
|
+
return {
|
|
105
|
+
name: 'earlier-than',
|
|
106
|
+
message: {
|
|
107
|
+
key: 'form.error.date.earlier_than',
|
|
108
|
+
context: {
|
|
109
|
+
maxDate: maxNextDate.toLocaleDateString(),
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
test: function (value: string) {
|
|
113
|
+
if (!value) return true;
|
|
114
|
+
const date = getDate(value);
|
|
115
|
+
const isValid = +date.toDate() < +maxDate;
|
|
116
|
+
return isValid;
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
export const DATE_VALIDATOR = {
|
|
122
|
+
name: 'date-validator',
|
|
123
|
+
message: (v): string | object => {
|
|
124
|
+
return checkPartialDate(v.value);
|
|
125
|
+
},
|
|
126
|
+
test: function (value: string) {
|
|
127
|
+
if (!value) return true;
|
|
128
|
+
const date = getDate(value);
|
|
129
|
+
return date.isValid();
|
|
130
|
+
},
|
|
131
|
+
};
|