@digigov/form 2.0.0-daaf7bdf → 2.0.0-e20fed09
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Field/ErrorGroup/index.js +48 -0
- package/{Form.stories → Field/ErrorGroup}/package.json +1 -1
- package/Field/ErrorGroup.d.ts +15 -0
- package/Field/ErrorGroup.js.map +7 -0
- package/Field/FieldBase/index.js +37 -25
- package/Field/FieldBase.js.map +2 -2
- package/Field/FieldBaseContainer/index.js +38 -18
- package/Field/FieldBaseContainer.d.ts +1 -1
- package/Field/FieldBaseContainer.js.map +2 -2
- package/Field/FieldConditional/index.js +4 -0
- package/Field/FieldConditional.js.map +2 -2
- package/Field/index.js +15 -4
- package/Field/index.js.map +2 -2
- package/Field/types.d.ts +21 -10
- package/Field/utils/index.js +9 -1
- package/Field/utils/index.js.map +2 -2
- package/Field/utils/useField/index.js +14 -1
- package/Field/utils/useField.js.map +2 -2
- package/FieldArray/FieldArray.stories.d.ts +1 -0
- package/FieldArray/FormDialog/index.js +397 -0
- package/{Questions/Questions.stories → FieldArray/FormDialog}/package.json +1 -1
- package/FieldArray/FormDialog.d.ts +66 -0
- package/FieldArray/FormDialog.js.map +7 -0
- package/FieldArray/__stories__/Default.d.ts +1 -1
- package/FieldArray/__stories__/WithExactLength.d.ts +1 -1
- package/FieldArray/__stories__/WithModal.d.ts +2 -0
- package/FieldArray/index.d.ts +6 -0
- package/FieldArray/index.js +87 -29
- package/FieldArray/index.js.map +2 -2
- package/FieldObject/index.d.ts +5 -0
- package/FieldObject/index.js +32 -17
- package/FieldObject/index.js.map +2 -2
- package/Fieldset/index.d.ts +1 -1
- package/Fieldset/index.js +5 -5
- package/Fieldset/index.js.map +2 -2
- package/Fieldset/types.d.ts +2 -2
- package/FormBuilder/FormBuilder.stories.d.ts +4 -0
- package/FormBuilder/__stories__/AutoErrorGrouping.d.ts +3 -0
- package/FormBuilder/__stories__/Default.d.ts +1 -1
- package/FormBuilder/__stories__/ErrorGrouping.d.ts +3 -0
- package/FormBuilder/index.d.ts +1 -1
- package/FormBuilder/index.js +94 -11
- package/FormBuilder/index.js.map +2 -2
- package/FormBuilder/interaction.test.d.ts +1 -0
- package/FormContext/index.js +6 -2
- package/FormContext.d.ts +1 -0
- package/FormContext.js.map +2 -2
- package/MultiplicityField/MultiplicityField.stories.d.ts +2 -0
- package/MultiplicityField/__stories__/Default.d.ts +1 -1
- package/MultiplicityField/__stories__/PreviewDisplay.d.ts +1 -1
- package/MultiplicityField/__stories__/WithExactLength.d.ts +1 -1
- package/MultiplicityField/__stories__/WithMaxLength.d.ts +1 -1
- package/MultiplicityField/__stories__/WithMinAndMaxLength.d.ts +1 -1
- package/MultiplicityField/__stories__/WithMinLength.d.ts +1 -1
- package/MultiplicityField/add-objects/index.js +10 -6
- package/MultiplicityField/add-objects.js.map +2 -2
- package/MultiplicityField/index.js +17 -11
- package/MultiplicityField/index.js.map +2 -2
- package/MultiplicityField/types.d.ts +2 -2
- package/Questions/Questions/index.js +5 -4
- package/Questions/Questions.js.map +2 -2
- package/Questions/Questions.stories.d.ts +2 -0
- package/Questions/Step/StepArrayReview.js.map +2 -2
- package/Questions/Step/StepTitle/index.js +4 -3
- package/Questions/Step/StepTitle.d.ts +1 -1
- package/Questions/Step/StepTitle.js.map +2 -2
- package/Questions/__stories__/Default.d.ts +1 -1
- package/cjs/Field/ErrorGroup/index.js +82 -0
- package/cjs/Field/ErrorGroup.js.map +7 -0
- package/cjs/Field/FieldBase/index.js +36 -24
- package/cjs/Field/FieldBase.js.map +2 -2
- package/cjs/Field/FieldBaseContainer/index.js +37 -17
- package/cjs/Field/FieldBaseContainer.js.map +3 -3
- package/cjs/Field/FieldConditional/index.js +4 -0
- package/cjs/Field/FieldConditional.js.map +2 -2
- package/cjs/Field/index.js +15 -4
- package/cjs/Field/index.js.map +2 -2
- package/cjs/Field/types.js.map +1 -1
- package/cjs/Field/utils/index.js +9 -1
- package/cjs/Field/utils/index.js.map +3 -3
- package/cjs/Field/utils/useField/index.js +14 -1
- package/cjs/Field/utils/useField.js.map +2 -2
- package/cjs/FieldArray/FormDialog/index.js +416 -0
- package/cjs/FieldArray/FormDialog.js.map +7 -0
- package/cjs/FieldArray/index.js +85 -27
- package/cjs/FieldArray/index.js.map +3 -3
- package/cjs/FieldObject/index.js +32 -17
- package/cjs/FieldObject/index.js.map +3 -3
- package/cjs/Fieldset/index.js +10 -10
- package/cjs/Fieldset/index.js.map +3 -3
- package/cjs/Fieldset/types.js.map +1 -1
- package/cjs/FormBuilder/index.js +94 -11
- package/cjs/FormBuilder/index.js.map +3 -3
- package/cjs/FormContext/index.js +9 -4
- package/cjs/FormContext.js.map +3 -3
- package/cjs/MultiplicityField/add-objects/index.js +14 -10
- package/cjs/MultiplicityField/add-objects.js.map +3 -3
- package/cjs/MultiplicityField/index.js +16 -15
- package/cjs/MultiplicityField/index.js.map +3 -3
- package/cjs/MultiplicityField/types.js.map +1 -1
- package/cjs/Questions/Questions/index.js +5 -4
- package/cjs/Questions/Questions.js.map +2 -2
- package/cjs/Questions/Step/StepArrayReview.js.map +2 -2
- package/cjs/Questions/Step/StepTitle/index.js +5 -5
- package/cjs/Questions/Step/StepTitle.js.map +3 -3
- package/cjs/inputs/AutoCompleteInput/index.js +8 -7
- package/cjs/inputs/AutoCompleteInput/index.js.map +3 -3
- package/cjs/inputs/Checkboxes/index.js +9 -9
- package/cjs/inputs/Checkboxes/index.js.map +3 -3
- package/cjs/inputs/DateInput/index.js +51 -22
- package/cjs/inputs/DateInput/index.js.map +3 -3
- package/cjs/inputs/DateTimeInput/index.js +245 -0
- package/cjs/inputs/DateTimeInput/index.js.map +7 -0
- package/cjs/inputs/FileInput/index.js +72 -35
- package/cjs/inputs/FileInput/index.js.map +3 -3
- package/cjs/inputs/ImageInput/__stories__/logo.d/index.js +1 -0
- package/cjs/inputs/ImageInput/__stories__/logo.d.js.map +7 -0
- package/cjs/inputs/ImageInput/index.js +54 -18
- package/cjs/inputs/ImageInput/index.js.map +3 -3
- package/cjs/inputs/Input/index.js +12 -4
- package/cjs/inputs/Input/index.js.map +2 -2
- package/cjs/inputs/Label/index.js +3 -3
- package/cjs/inputs/Label/index.js.map +3 -3
- package/cjs/inputs/OtpInput/index.js +1 -0
- package/cjs/inputs/OtpInput/index.js.map +2 -2
- package/cjs/inputs/Radio/index.js +12 -13
- package/cjs/inputs/Radio/index.js.map +3 -3
- package/cjs/inputs/Select/index.js +11 -5
- package/cjs/inputs/Select/index.js.map +3 -3
- package/cjs/inputs/inputsScenarios/index.js +6 -12
- package/cjs/inputs/inputsScenarios.js.map +2 -2
- package/cjs/{lazy/index.js → lazy.js} +49 -35
- package/cjs/lazy.js.map +3 -3
- package/cjs/locales/el.js.map +1 -1
- package/cjs/{registry/index.js → registry.js} +72 -62
- package/cjs/registry.js.map +3 -3
- package/cjs/types.js.map +1 -1
- package/cjs/utils/index.js +22 -7
- package/cjs/utils.js.map +2 -2
- package/cjs/validators/index.js +55 -85
- package/cjs/validators/index.js.map +3 -3
- package/cjs/validators/utils/amka/index.js +60 -0
- package/cjs/validators/utils/amka.js.map +7 -0
- package/cjs/validators/utils/date/index.js +161 -0
- package/cjs/validators/utils/date.js.map +7 -0
- package/cjs/validators/utils/datetime/index.js +245 -0
- package/cjs/validators/utils/datetime.js.map +7 -0
- package/cjs/validators/utils/file/index.js +30 -17
- package/cjs/validators/utils/file.js.map +2 -2
- package/cjs/validators/utils/index.js +10 -2
- package/cjs/validators/utils/index.js.map +2 -2
- package/cjs/validators/utils/int/index.js +1 -1
- package/cjs/validators/utils/int.js.map +2 -2
- package/cjs/validators/utils/number/index.js +1 -1
- package/cjs/validators/utils/number.js.map +2 -2
- package/cjs/validators/utils/phone.js.map +2 -2
- package/cjs/validators/utils/postal_code.js.map +1 -1
- package/cjs/validators/utils/uuid4.js.map +2 -2
- package/index.js +1 -1
- package/inputs/AutoCompleteInput/AutoComplete.stories.d.ts +2 -0
- package/inputs/AutoCompleteInput/__stories__/Default.d.ts +1 -1
- package/inputs/AutoCompleteInput/__stories__/Multiple.d.ts +1 -1
- package/inputs/AutoCompleteInput/index.d.ts +1 -1
- package/inputs/AutoCompleteInput/index.js +10 -7
- package/inputs/AutoCompleteInput/index.js.map +2 -2
- package/inputs/Checkboxes/Checkboxes.stories.d.ts +2 -0
- package/inputs/Checkboxes/__stories__/Conditional.d.ts +1 -1
- package/inputs/Checkboxes/__stories__/Default.d.ts +1 -1
- package/inputs/Checkboxes/__stories__/WithDivider.d.ts +1 -1
- package/inputs/Checkboxes/index.d.ts +1 -1
- package/inputs/Checkboxes/index.js +10 -6
- package/inputs/Checkboxes/index.js.map +2 -2
- package/inputs/DateInput/DateInput.stories.d.ts +6 -0
- package/inputs/DateInput/__stories__/Default.d.ts +1 -1
- package/inputs/DateInput/__stories__/WithDefaultValue.d.ts +3 -0
- package/inputs/DateInput/__stories__/WithInitialValue.d.ts +3 -0
- package/inputs/DateInput/__stories__/WithWrongDefaultValue.d.ts +3 -0
- package/inputs/DateInput/__stories__/WithWrongInitialValue.d.ts +3 -0
- package/inputs/DateInput/index.d.ts +1 -2
- package/inputs/DateInput/index.js +54 -22
- package/inputs/DateInput/index.js.map +2 -2
- package/inputs/DateTimeInput/DateTimeInput.stories.d.ts +14 -0
- package/inputs/DateTimeInput/__stories__/Default.d.ts +3 -0
- 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 +13 -0
- package/inputs/DateTimeInput/index.js +215 -0
- package/inputs/DateTimeInput/index.js.map +7 -0
- package/inputs/DateTimeInput/index.test.d.ts +1 -0
- package/inputs/{Input/Input.stories → DateTimeInput}/package.json +1 -1
- package/inputs/FileInput/FileInput.stories.d.ts +3 -0
- package/inputs/FileInput/__stories__/Default.d.ts +1 -1
- package/inputs/FileInput/__stories__/WithBorderAndLink.d.ts +3 -0
- package/inputs/FileInput/index.d.ts +17 -1
- package/inputs/FileInput/index.js +76 -36
- package/inputs/FileInput/index.js.map +2 -2
- package/inputs/ImageInput/ImageInput.stories.d.ts +4 -1
- package/inputs/ImageInput/__stories__/Default.d.ts +1 -1
- package/inputs/ImageInput/__stories__/MaxSize.d.ts +1 -1
- package/inputs/ImageInput/__stories__/WithInitialValues.d.ts +3 -0
- package/inputs/ImageInput/__stories__/WithInvalidImageDimension.d.ts +1 -1
- package/inputs/ImageInput/__stories__/logo.d/index.js +1 -0
- package/inputs/{DateInput/__stories__/Default → ImageInput/__stories__/logo.d}/package.json +1 -1
- package/inputs/ImageInput/__stories__/logo.d.js.map +7 -0
- package/inputs/ImageInput/index.d.ts +9 -1
- package/inputs/ImageInput/index.js +54 -18
- package/inputs/ImageInput/index.js.map +2 -2
- package/inputs/Input/Input.stories.d.ts +5 -0
- package/inputs/Input/__stories__/AFM.d.ts +1 -1
- package/inputs/Input/__stories__/AMKA.d.ts +3 -0
- package/inputs/Input/__stories__/Boolean.d.ts +1 -1
- package/inputs/Input/__stories__/Email.d.ts +3 -0
- package/inputs/Input/__stories__/IBAN.d.ts +1 -1
- package/inputs/Input/__stories__/Integer.d.ts +1 -1
- package/inputs/Input/__stories__/LandlineNumber.d.ts +1 -1
- package/inputs/Input/__stories__/MobilePhone.d.ts +1 -1
- package/inputs/Input/__stories__/PhoneNumber.d.ts +1 -1
- package/inputs/Input/__stories__/PostalCode.d.ts +1 -1
- package/inputs/Input/__stories__/String.d.ts +1 -1
- package/inputs/Input/__stories__/StringWithTrimValidation.d.ts +3 -0
- package/inputs/Input/__stories__/TextWithLimit.d.ts +1 -1
- package/inputs/Input/index.d.ts +2 -1
- package/inputs/Input/index.js +12 -4
- package/inputs/Input/index.js.map +2 -2
- package/inputs/Label/Label.stories.d.ts +2 -0
- package/inputs/Label/__stories__/Default.d.ts +1 -1
- package/inputs/Label/index.d.ts +0 -2
- package/inputs/Label/index.js +2 -2
- package/inputs/Label/index.js.map +2 -2
- package/inputs/OtpInput/OtpInput.stories.d.ts +2 -0
- package/inputs/OtpInput/__stories__/Default.d.ts +1 -1
- package/inputs/OtpInput/index.js +1 -0
- package/inputs/OtpInput/index.js.map +2 -2
- package/inputs/Radio/Radio.stories.d.ts +2 -0
- package/inputs/Radio/__stories__/Conditional.d.ts +1 -1
- package/inputs/Radio/__stories__/Default.d.ts +1 -1
- package/inputs/Radio/__stories__/WithDivider.d.ts +1 -1
- package/inputs/Radio/index.d.ts +1 -1
- package/inputs/Radio/index.js +8 -5
- package/inputs/Radio/index.js.map +2 -2
- package/inputs/Select/Select.stories.d.ts +2 -0
- package/inputs/Select/__stories__/Default.d.ts +1 -1
- package/inputs/Select/index.d.ts +3 -2
- package/inputs/Select/index.js +13 -4
- package/inputs/Select/index.js.map +2 -2
- package/inputs/inputsScenarios/index.js +6 -12
- package/inputs/inputsScenarios.d.ts +1 -1
- package/inputs/inputsScenarios.js.map +2 -2
- package/lazy/index.js +77 -67
- package/locales/el.js.map +1 -1
- package/package.json +8 -8
- package/registry/index.js +116 -107
- package/src/Field/ErrorGroup.tsx +84 -0
- package/src/Field/FieldBase.tsx +39 -24
- package/src/Field/FieldBaseContainer.tsx +70 -47
- package/src/Field/FieldConditional.tsx +6 -2
- package/src/Field/doc.mdx +207 -0
- package/src/Field/index.tsx +20 -5
- package/src/Field/types.tsx +42 -29
- package/src/Field/utils/index.ts +8 -0
- package/src/Field/utils/useField.ts +14 -2
- package/src/FieldArray/FieldArray.stories.js +1 -0
- package/src/FieldArray/FormDialog.tsx +565 -0
- package/src/FieldArray/__stories__/Default.tsx +2 -1
- package/src/FieldArray/__stories__/WithExactLength.tsx +2 -1
- package/src/FieldArray/__stories__/WithModal.tsx +160 -0
- package/src/FieldArray/index.test.tsx +8 -0
- package/src/FieldArray/index.tsx +119 -54
- package/src/FieldObject/index.tsx +41 -20
- package/src/Fieldset/index.tsx +5 -5
- package/src/Fieldset/types.tsx +2 -2
- package/src/FormBuilder/FormBuilder.stories.js +5 -0
- package/src/FormBuilder/__stories__/AutoErrorGrouping.tsx +63 -0
- package/src/FormBuilder/__stories__/Default.tsx +1 -1
- package/src/FormBuilder/__stories__/ErrorGrouping.tsx +43 -0
- package/src/FormBuilder/{FormBuilder.mdx → doc.mdx} +27 -35
- package/src/FormBuilder/index.test.tsx +12 -0
- package/src/FormBuilder/index.tsx +104 -14
- package/src/FormBuilder/interaction.test.tsx +40 -0
- package/src/FormBuilder/scenarios.test.tsx +1002 -130
- package/src/FormContext.tsx +5 -2
- package/src/MultiplicityField/MultiplicityField.stories.js +3 -0
- package/src/MultiplicityField/__stories__/Default.tsx +1 -1
- package/src/MultiplicityField/__stories__/PreviewDisplay.tsx +1 -1
- package/src/MultiplicityField/__stories__/WithExactLength.tsx +1 -1
- package/src/MultiplicityField/__stories__/WithMaxLength.tsx +1 -1
- package/src/MultiplicityField/__stories__/WithMinAndMaxLength.tsx +1 -1
- package/src/MultiplicityField/__stories__/WithMinLength.tsx +1 -1
- package/src/MultiplicityField/add-objects.tsx +11 -9
- package/src/MultiplicityField/{MultiplicityField.mdx → doc.mdx} +112 -98
- package/src/MultiplicityField/index.test.tsx +4 -0
- package/src/MultiplicityField/index.tsx +17 -12
- package/src/MultiplicityField/types.ts +2 -2
- package/src/Questions/Questions.stories.js +3 -0
- package/src/Questions/Questions.tsx +4 -4
- package/src/Questions/Step/StepArrayReview.tsx +1 -1
- package/src/Questions/Step/StepTitle.tsx +4 -3
- package/src/Questions/__snapshots__/index.spec.tsx.snap +11 -5
- package/src/Questions/__stories__/Default.tsx +1 -1
- package/src/Questions/{index.mdx → doc.mdx} +30 -53
- package/src/Questions/index.spec.tsx +14 -2
- package/src/Questions/index.test.tsx +4 -0
- package/src/create-simple-form.mdx +2 -6
- package/src/{index.mdx → doc.mdx} +29 -18
- package/src/inputs/AutoCompleteInput/AutoComplete.stories.js +3 -0
- package/src/inputs/AutoCompleteInput/__stories__/Default.tsx +3 -11
- package/src/inputs/AutoCompleteInput/__stories__/Multiple.tsx +2 -8
- package/src/inputs/AutoCompleteInput/{index.mdx → doc.mdx} +2 -13
- package/src/inputs/AutoCompleteInput/index.test.tsx +4 -0
- package/src/inputs/AutoCompleteInput/index.tsx +32 -28
- package/src/inputs/Checkboxes/Checkboxes.stories.js +3 -0
- package/src/inputs/Checkboxes/__stories__/Conditional.tsx +1 -1
- package/src/inputs/Checkboxes/__stories__/Default.tsx +1 -1
- package/src/inputs/Checkboxes/__stories__/WithDivider.tsx +1 -1
- package/src/inputs/Checkboxes/{index.mdx → doc.mdx} +5 -15
- package/src/inputs/Checkboxes/index.test.tsx +4 -0
- package/src/inputs/Checkboxes/index.tsx +28 -28
- package/src/inputs/DateInput/DateInput.stories.js +7 -0
- package/src/inputs/DateInput/__stories__/Default.tsx +8 -13
- 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 +20 -0
- package/src/inputs/DateInput/index.tsx +58 -21
- 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 +233 -0
- package/src/inputs/FileInput/FileInput.stories.js +4 -0
- package/src/inputs/FileInput/__stories__/Default.tsx +1 -1
- package/src/inputs/FileInput/__stories__/WithBorderAndLink.tsx +34 -0
- package/src/inputs/FileInput/{index.mdx → doc.mdx} +1 -5
- package/src/inputs/FileInput/index.test.tsx +8 -0
- package/src/inputs/FileInput/index.tsx +106 -41
- package/src/inputs/ImageInput/ImageInput.stories.js +5 -2
- package/src/inputs/ImageInput/__stories__/Default.tsx +1 -1
- package/src/inputs/ImageInput/__stories__/MaxSize.tsx +5 -4
- package/src/inputs/ImageInput/__stories__/{WithInvalidImageSize.tsx → WithInitialValues.tsx} +12 -3
- 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 +8 -4
- package/src/inputs/ImageInput/index.tsx +103 -50
- package/src/inputs/Input/Input.stories.js +6 -0
- package/src/inputs/Input/__stories__/AFM.tsx +1 -1
- package/src/inputs/Input/__stories__/AMKA.tsx +23 -0
- package/src/inputs/Input/__stories__/Boolean.tsx +1 -1
- package/src/inputs/Input/__stories__/Email.tsx +23 -0
- package/src/inputs/Input/__stories__/IBAN.tsx +1 -1
- package/src/inputs/Input/__stories__/Integer.tsx +1 -1
- package/src/inputs/Input/__stories__/LandlineNumber.tsx +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__/String.tsx +1 -1
- package/src/inputs/Input/__stories__/StringWithTrimValidation.tsx +26 -0
- package/src/inputs/Input/__stories__/TextWithLimit.tsx +2 -1
- package/src/inputs/Input/doc.mdx +56 -0
- package/src/inputs/Input/index.test.tsx +16 -0
- package/src/inputs/Input/index.tsx +30 -12
- package/src/inputs/Label/Label.stories.js +3 -0
- package/src/inputs/Label/__stories__/Default.tsx +1 -1
- package/src/inputs/Label/doc.mdx +14 -0
- package/src/inputs/Label/index.test.tsx +4 -0
- package/src/inputs/Label/index.tsx +2 -6
- package/src/inputs/OtpInput/OtpInput.stories.js +3 -0
- package/src/inputs/OtpInput/__stories__/Default.tsx +1 -1
- package/src/inputs/OtpInput/{index.mdx → doc.mdx} +1 -8
- package/src/inputs/OtpInput/index.test.tsx +4 -0
- package/src/inputs/OtpInput/index.tsx +3 -1
- package/src/inputs/Radio/Radio.stories.js +3 -0
- package/src/inputs/Radio/__stories__/Conditional.tsx +1 -1
- package/src/inputs/Radio/__stories__/Default.tsx +1 -1
- package/src/inputs/Radio/__stories__/WithDivider.tsx +1 -1
- package/src/inputs/Radio/{index.mdx → doc.mdx} +5 -15
- package/src/inputs/Radio/index.test.tsx +4 -0
- package/src/inputs/Radio/index.tsx +59 -56
- package/src/inputs/Select/Select.stories.js +3 -0
- 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 +4 -0
- package/src/inputs/Select/index.tsx +18 -7
- package/src/inputs/inputsScenarios.ts +36 -42
- package/src/installation.mdx +2 -5
- package/src/lazy.js +77 -64
- package/src/locales/el.ts +1 -1
- package/src/registry.js +108 -100
- package/src/types.tsx +4 -3
- package/src/utils.ts +29 -8
- package/src/validators/index.ts +103 -91
- 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/file.ts +33 -17
- package/src/validators/utils/index.ts +6 -1
- package/src/validators/utils/int.ts +1 -1
- package/src/validators/utils/number.ts +1 -1
- package/src/validators/utils/phone.ts +1 -1
- package/src/validators/utils/postal_code.ts +1 -1
- package/src/validators/utils/uuid4.ts +2 -1
- package/src/validators/validators.spec.ts +3 -3
- package/types.d.ts +4 -3
- package/types.js.map +1 -1
- package/utils/index.js +22 -7
- package/utils.d.ts +2 -0
- package/utils.js.map +2 -2
- package/validators/index.d.ts +1 -1
- package/validators/index.js +63 -86
- package/validators/index.js.map +2 -2
- package/validators/utils/amka/index.js +36 -0
- package/{FieldArray/FieldArray.stories → validators/utils/amka}/package.json +1 -1
- package/validators/utils/amka.d.ts +6 -0
- package/validators/utils/amka.js.map +7 -0
- package/validators/utils/date/index.js +126 -0
- package/validators/utils/date/package.json +6 -0
- package/validators/utils/date.d.ts +9 -0
- package/validators/utils/date.js.map +7 -0
- package/validators/utils/datetime/index.js +210 -0
- package/validators/utils/datetime/package.json +6 -0
- package/validators/utils/datetime.d.ts +9 -0
- package/validators/utils/datetime.js.map +7 -0
- package/validators/utils/file/index.js +30 -17
- package/validators/utils/file.js.map +2 -2
- package/validators/utils/index.d.ts +3 -0
- package/validators/utils/index.js +6 -1
- package/validators/utils/index.js.map +2 -2
- package/validators/utils/int/index.js +1 -1
- package/validators/utils/int.js.map +2 -2
- package/validators/utils/number/index.js +1 -1
- package/validators/utils/number.js.map +2 -2
- package/validators/utils/phone.d.ts +1 -1
- package/validators/utils/phone.js.map +2 -2
- package/validators/utils/postal_code.d.ts +1 -1
- package/validators/utils/postal_code.js.map +1 -1
- package/validators/utils/uuid4.js.map +2 -2
- package/FieldArray/FieldArray.stories/index.js +0 -14
- package/FieldArray/FieldArray.stories.js.map +0 -7
- package/FieldArray/__stories__/Default/index.js +0 -95
- package/FieldArray/__stories__/Default/package.json +0 -6
- package/FieldArray/__stories__/Default.js.map +0 -7
- package/FieldArray/__stories__/WithExactLength/index.js +0 -95
- package/FieldArray/__stories__/WithExactLength/package.json +0 -6
- package/FieldArray/__stories__/WithExactLength.js.map +0 -7
- package/Form.stories/index.js +0 -7
- package/Form.stories.js.map +0 -7
- package/FormBuilder/FormBuilder.stories/index.js +0 -12
- package/FormBuilder/FormBuilder.stories/package.json +0 -6
- package/FormBuilder/FormBuilder.stories.js.map +0 -7
- package/FormBuilder/__stories__/Default/index.js +0 -32
- package/FormBuilder/__stories__/Default/package.json +0 -6
- package/FormBuilder/__stories__/Default.js.map +0 -7
- package/MultiplicityField/MultiplicityField.stories/index.js +0 -22
- package/MultiplicityField/MultiplicityField.stories/package.json +0 -6
- package/MultiplicityField/MultiplicityField.stories.js.map +0 -7
- package/MultiplicityField/__stories__/Default/index.js +0 -100
- package/MultiplicityField/__stories__/Default/package.json +0 -6
- package/MultiplicityField/__stories__/Default.js.map +0 -7
- package/MultiplicityField/__stories__/PreviewDisplay/index.js +0 -70
- package/MultiplicityField/__stories__/PreviewDisplay/package.json +0 -6
- package/MultiplicityField/__stories__/PreviewDisplay.js.map +0 -7
- package/MultiplicityField/__stories__/WithExactLength/index.js +0 -97
- package/MultiplicityField/__stories__/WithExactLength/package.json +0 -6
- package/MultiplicityField/__stories__/WithExactLength.js.map +0 -7
- package/MultiplicityField/__stories__/WithMaxLength/index.js +0 -100
- package/MultiplicityField/__stories__/WithMaxLength/package.json +0 -6
- package/MultiplicityField/__stories__/WithMaxLength.js.map +0 -7
- package/MultiplicityField/__stories__/WithMinAndMaxLength/index.js +0 -101
- package/MultiplicityField/__stories__/WithMinAndMaxLength/package.json +0 -6
- package/MultiplicityField/__stories__/WithMinAndMaxLength.js.map +0 -7
- package/MultiplicityField/__stories__/WithMinLength/index.js +0 -100
- package/MultiplicityField/__stories__/WithMinLength/package.json +0 -6
- package/MultiplicityField/__stories__/WithMinLength.js.map +0 -7
- package/Questions/Questions.stories/index.js +0 -12
- package/Questions/Questions.stories.js.map +0 -7
- package/Questions/__stories__/Default/index.js +0 -108
- package/Questions/__stories__/Default/package.json +0 -6
- package/Questions/__stories__/Default.js.map +0 -7
- package/cjs/FieldArray/FieldArray.stories/index.js +0 -48
- package/cjs/FieldArray/FieldArray.stories.js.map +0 -7
- package/cjs/FieldArray/__stories__/Default/index.js +0 -128
- package/cjs/FieldArray/__stories__/Default.js.map +0 -7
- package/cjs/FieldArray/__stories__/WithExactLength/index.js +0 -128
- package/cjs/FieldArray/__stories__/WithExactLength.js.map +0 -7
- package/cjs/Form.stories/index.js +0 -26
- package/cjs/Form.stories.js.map +0 -7
- package/cjs/FormBuilder/FormBuilder.stories/index.js +0 -45
- package/cjs/FormBuilder/FormBuilder.stories.js.map +0 -7
- package/cjs/FormBuilder/__stories__/Default/index.js +0 -65
- package/cjs/FormBuilder/__stories__/Default.js.map +0 -7
- package/cjs/MultiplicityField/MultiplicityField.stories/index.js +0 -60
- package/cjs/MultiplicityField/MultiplicityField.stories.js.map +0 -7
- package/cjs/MultiplicityField/__stories__/Default/index.js +0 -133
- package/cjs/MultiplicityField/__stories__/Default.js.map +0 -7
- package/cjs/MultiplicityField/__stories__/PreviewDisplay/index.js +0 -86
- package/cjs/MultiplicityField/__stories__/PreviewDisplay.js.map +0 -7
- package/cjs/MultiplicityField/__stories__/WithExactLength/index.js +0 -130
- package/cjs/MultiplicityField/__stories__/WithExactLength.js.map +0 -7
- package/cjs/MultiplicityField/__stories__/WithMaxLength/index.js +0 -133
- package/cjs/MultiplicityField/__stories__/WithMaxLength.js.map +0 -7
- package/cjs/MultiplicityField/__stories__/WithMinAndMaxLength/index.js +0 -134
- package/cjs/MultiplicityField/__stories__/WithMinAndMaxLength.js.map +0 -7
- package/cjs/MultiplicityField/__stories__/WithMinLength/index.js +0 -133
- package/cjs/MultiplicityField/__stories__/WithMinLength.js.map +0 -7
- package/cjs/Questions/Questions.stories/index.js +0 -45
- package/cjs/Questions/Questions.stories.js.map +0 -7
- package/cjs/Questions/__stories__/Default/index.js +0 -136
- package/cjs/Questions/__stories__/Default.js.map +0 -7
- package/cjs/inputs/AutoCompleteInput/AutoComplete.stories/index.js +0 -48
- package/cjs/inputs/AutoCompleteInput/AutoComplete.stories.js.map +0 -7
- package/cjs/inputs/AutoCompleteInput/__stories__/Default/index.js +0 -83
- package/cjs/inputs/AutoCompleteInput/__stories__/Default.js.map +0 -7
- package/cjs/inputs/AutoCompleteInput/__stories__/Multiple/index.js +0 -83
- package/cjs/inputs/AutoCompleteInput/__stories__/Multiple.js.map +0 -7
- package/cjs/inputs/Checkboxes/Checkboxes.stories/index.js +0 -51
- package/cjs/inputs/Checkboxes/Checkboxes.stories.js.map +0 -7
- package/cjs/inputs/Checkboxes/__stories__/Conditional/index.js +0 -133
- package/cjs/inputs/Checkboxes/__stories__/Conditional.js.map +0 -7
- package/cjs/inputs/Checkboxes/__stories__/Default/index.js +0 -77
- package/cjs/inputs/Checkboxes/__stories__/Default.js.map +0 -7
- package/cjs/inputs/Checkboxes/__stories__/WithDivider/index.js +0 -78
- package/cjs/inputs/Checkboxes/__stories__/WithDivider.js.map +0 -7
- package/cjs/inputs/DateInput/DateInput.stories/index.js +0 -45
- package/cjs/inputs/DateInput/DateInput.stories.js.map +0 -7
- package/cjs/inputs/DateInput/__stories__/Default/index.js +0 -61
- package/cjs/inputs/DateInput/__stories__/Default.js.map +0 -7
- package/cjs/inputs/FileInput/FileInput.stories/index.js +0 -45
- package/cjs/inputs/FileInput/FileInput.stories.js.map +0 -7
- package/cjs/inputs/FileInput/__stories__/Default/index.js +0 -61
- package/cjs/inputs/FileInput/__stories__/Default.js.map +0 -7
- package/cjs/inputs/ImageInput/ImageInput.stories/index.js +0 -51
- package/cjs/inputs/ImageInput/ImageInput.stories.js.map +0 -7
- package/cjs/inputs/ImageInput/__stories__/Default/index.js +0 -63
- package/cjs/inputs/ImageInput/__stories__/Default.js.map +0 -7
- package/cjs/inputs/ImageInput/__stories__/MaxSize/index.js +0 -69
- package/cjs/inputs/ImageInput/__stories__/MaxSize.js.map +0 -7
- package/cjs/inputs/ImageInput/__stories__/WithInvalidImageDimension/index.js +0 -71
- package/cjs/inputs/ImageInput/__stories__/WithInvalidImageDimension.js.map +0 -7
- package/cjs/inputs/ImageInput/__stories__/WithInvalidImageSize/index.js +0 -68
- package/cjs/inputs/ImageInput/__stories__/WithInvalidImageSize.js.map +0 -7
- package/cjs/inputs/Input/Input.stories/index.js +0 -72
- package/cjs/inputs/Input/Input.stories.js.map +0 -7
- package/cjs/inputs/Input/__stories__/AFM/index.js +0 -63
- package/cjs/inputs/Input/__stories__/AFM.js.map +0 -7
- package/cjs/inputs/Input/__stories__/Boolean/index.js +0 -64
- package/cjs/inputs/Input/__stories__/Boolean.js.map +0 -7
- package/cjs/inputs/Input/__stories__/IBAN/index.js +0 -64
- package/cjs/inputs/Input/__stories__/IBAN.js.map +0 -7
- package/cjs/inputs/Input/__stories__/Integer/index.js +0 -78
- package/cjs/inputs/Input/__stories__/Integer.js.map +0 -7
- package/cjs/inputs/Input/__stories__/LandlineNumber/index.js +0 -67
- package/cjs/inputs/Input/__stories__/LandlineNumber.js.map +0 -7
- package/cjs/inputs/Input/__stories__/MobilePhone/index.js +0 -67
- package/cjs/inputs/Input/__stories__/MobilePhone.js.map +0 -7
- package/cjs/inputs/Input/__stories__/PhoneNumber/index.js +0 -66
- package/cjs/inputs/Input/__stories__/PhoneNumber.js.map +0 -7
- package/cjs/inputs/Input/__stories__/PostalCode/index.js +0 -64
- package/cjs/inputs/Input/__stories__/PostalCode.js.map +0 -7
- package/cjs/inputs/Input/__stories__/String/index.js +0 -64
- package/cjs/inputs/Input/__stories__/String.js.map +0 -7
- package/cjs/inputs/Input/__stories__/TextWithLimit/index.js +0 -64
- package/cjs/inputs/Input/__stories__/TextWithLimit.js.map +0 -7
- package/cjs/inputs/Input/inputsInputScenarios/index.js +0 -439
- package/cjs/inputs/Input/inputsInputScenarios.js.map +0 -7
- package/cjs/inputs/Label/Label.stories/index.js +0 -45
- package/cjs/inputs/Label/Label.stories.js.map +0 -7
- package/cjs/inputs/Label/__stories__/Default/index.js +0 -72
- package/cjs/inputs/Label/__stories__/Default.js.map +0 -7
- package/cjs/inputs/OtpInput/OtpInput.stories/index.js +0 -45
- package/cjs/inputs/OtpInput/OtpInput.stories.js.map +0 -7
- package/cjs/inputs/OtpInput/__stories__/Default/index.js +0 -64
- package/cjs/inputs/OtpInput/__stories__/Default.js.map +0 -7
- package/cjs/inputs/Radio/Radio.stories/index.js +0 -51
- package/cjs/inputs/Radio/Radio.stories.js.map +0 -7
- package/cjs/inputs/Radio/__stories__/Conditional/index.js +0 -133
- package/cjs/inputs/Radio/__stories__/Conditional.js.map +0 -7
- package/cjs/inputs/Radio/__stories__/Default/index.js +0 -81
- package/cjs/inputs/Radio/__stories__/Default.js.map +0 -7
- package/cjs/inputs/Radio/__stories__/WithDivider/index.js +0 -82
- package/cjs/inputs/Radio/__stories__/WithDivider.js.map +0 -7
- package/cjs/inputs/Select/Select.stories/index.js +0 -45
- package/cjs/inputs/Select/Select.stories.js.map +0 -7
- package/cjs/inputs/Select/__stories__/Default/index.js +0 -86
- package/cjs/inputs/Select/__stories__/Default.js.map +0 -7
- package/inputs/AutoCompleteInput/AutoComplete.stories/index.js +0 -14
- package/inputs/AutoCompleteInput/AutoComplete.stories/package.json +0 -6
- package/inputs/AutoCompleteInput/AutoComplete.stories.js.map +0 -7
- package/inputs/AutoCompleteInput/__stories__/Default/index.js +0 -50
- package/inputs/AutoCompleteInput/__stories__/Default/package.json +0 -6
- package/inputs/AutoCompleteInput/__stories__/Default.js.map +0 -7
- package/inputs/AutoCompleteInput/__stories__/Multiple/index.js +0 -50
- package/inputs/AutoCompleteInput/__stories__/Multiple/package.json +0 -6
- package/inputs/AutoCompleteInput/__stories__/Multiple.js.map +0 -7
- package/inputs/Checkboxes/Checkboxes.stories/index.js +0 -16
- package/inputs/Checkboxes/Checkboxes.stories/package.json +0 -6
- package/inputs/Checkboxes/Checkboxes.stories.js.map +0 -7
- package/inputs/Checkboxes/__stories__/Conditional/index.js +0 -100
- package/inputs/Checkboxes/__stories__/Conditional/package.json +0 -6
- package/inputs/Checkboxes/__stories__/Conditional.js.map +0 -7
- package/inputs/Checkboxes/__stories__/Default/index.js +0 -44
- package/inputs/Checkboxes/__stories__/Default/package.json +0 -6
- package/inputs/Checkboxes/__stories__/Default.js.map +0 -7
- package/inputs/Checkboxes/__stories__/WithDivider/index.js +0 -45
- package/inputs/Checkboxes/__stories__/WithDivider/package.json +0 -6
- package/inputs/Checkboxes/__stories__/WithDivider.js.map +0 -7
- package/inputs/DateInput/DateInput.stories/index.js +0 -12
- package/inputs/DateInput/DateInput.stories/package.json +0 -6
- package/inputs/DateInput/DateInput.stories.js.map +0 -7
- package/inputs/DateInput/__stories__/Default/index.js +0 -28
- package/inputs/DateInput/__stories__/Default.js.map +0 -7
- package/inputs/FileInput/FileInput.stories/index.js +0 -12
- package/inputs/FileInput/FileInput.stories/package.json +0 -6
- package/inputs/FileInput/FileInput.stories.js.map +0 -7
- package/inputs/FileInput/__stories__/Default/index.js +0 -28
- package/inputs/FileInput/__stories__/Default/package.json +0 -6
- package/inputs/FileInput/__stories__/Default.js.map +0 -7
- package/inputs/ImageInput/ImageInput.stories/index.js +0 -16
- package/inputs/ImageInput/ImageInput.stories/package.json +0 -6
- package/inputs/ImageInput/ImageInput.stories.js.map +0 -7
- package/inputs/ImageInput/__stories__/Default/index.js +0 -30
- package/inputs/ImageInput/__stories__/Default/package.json +0 -6
- package/inputs/ImageInput/__stories__/Default.js.map +0 -7
- package/inputs/ImageInput/__stories__/MaxSize/index.js +0 -36
- package/inputs/ImageInput/__stories__/MaxSize/package.json +0 -6
- package/inputs/ImageInput/__stories__/MaxSize.js.map +0 -7
- package/inputs/ImageInput/__stories__/WithInvalidImageDimension/index.js +0 -38
- package/inputs/ImageInput/__stories__/WithInvalidImageDimension/package.json +0 -6
- package/inputs/ImageInput/__stories__/WithInvalidImageDimension.js.map +0 -7
- package/inputs/ImageInput/__stories__/WithInvalidImageSize/index.js +0 -35
- package/inputs/ImageInput/__stories__/WithInvalidImageSize/package.json +0 -6
- package/inputs/ImageInput/__stories__/WithInvalidImageSize.d.ts +0 -3
- package/inputs/ImageInput/__stories__/WithInvalidImageSize.js.map +0 -7
- package/inputs/Input/Input.stories/index.js +0 -30
- package/inputs/Input/Input.stories.js.map +0 -7
- package/inputs/Input/__stories__/AFM/index.js +0 -30
- package/inputs/Input/__stories__/AFM/package.json +0 -6
- package/inputs/Input/__stories__/AFM.js.map +0 -7
- package/inputs/Input/__stories__/Boolean/index.js +0 -31
- package/inputs/Input/__stories__/Boolean/package.json +0 -6
- package/inputs/Input/__stories__/Boolean.js.map +0 -7
- package/inputs/Input/__stories__/IBAN/index.js +0 -31
- package/inputs/Input/__stories__/IBAN/package.json +0 -6
- package/inputs/Input/__stories__/IBAN.js.map +0 -7
- package/inputs/Input/__stories__/Integer/index.js +0 -45
- package/inputs/Input/__stories__/Integer/package.json +0 -6
- package/inputs/Input/__stories__/Integer.js.map +0 -7
- package/inputs/Input/__stories__/LandlineNumber/index.js +0 -34
- package/inputs/Input/__stories__/LandlineNumber/package.json +0 -6
- package/inputs/Input/__stories__/LandlineNumber.js.map +0 -7
- package/inputs/Input/__stories__/MobilePhone/index.js +0 -34
- package/inputs/Input/__stories__/MobilePhone/package.json +0 -6
- package/inputs/Input/__stories__/MobilePhone.js.map +0 -7
- package/inputs/Input/__stories__/PhoneNumber/index.js +0 -33
- package/inputs/Input/__stories__/PhoneNumber/package.json +0 -6
- package/inputs/Input/__stories__/PhoneNumber.js.map +0 -7
- package/inputs/Input/__stories__/PostalCode/index.js +0 -31
- package/inputs/Input/__stories__/PostalCode/package.json +0 -6
- package/inputs/Input/__stories__/PostalCode.js.map +0 -7
- package/inputs/Input/__stories__/String/index.js +0 -31
- package/inputs/Input/__stories__/String/package.json +0 -6
- package/inputs/Input/__stories__/String.js.map +0 -7
- package/inputs/Input/__stories__/TextWithLimit/index.js +0 -31
- package/inputs/Input/__stories__/TextWithLimit/package.json +0 -6
- package/inputs/Input/__stories__/TextWithLimit.js.map +0 -7
- package/inputs/Input/inputsInputScenarios/index.js +0 -406
- package/inputs/Input/inputsInputScenarios/package.json +0 -6
- package/inputs/Input/inputsInputScenarios.d.ts +0 -57
- package/inputs/Input/inputsInputScenarios.js.map +0 -7
- package/inputs/Label/Label.stories/index.js +0 -12
- package/inputs/Label/Label.stories/package.json +0 -6
- package/inputs/Label/Label.stories.js.map +0 -7
- package/inputs/Label/__stories__/Default/index.js +0 -39
- package/inputs/Label/__stories__/Default/package.json +0 -6
- package/inputs/Label/__stories__/Default.js.map +0 -7
- package/inputs/OtpInput/OtpInput.stories/index.js +0 -12
- package/inputs/OtpInput/OtpInput.stories/package.json +0 -6
- package/inputs/OtpInput/OtpInput.stories.js.map +0 -7
- package/inputs/OtpInput/__stories__/Default/index.js +0 -31
- package/inputs/OtpInput/__stories__/Default/package.json +0 -6
- package/inputs/OtpInput/__stories__/Default.js.map +0 -7
- package/inputs/Radio/Radio.stories/index.js +0 -16
- package/inputs/Radio/Radio.stories/package.json +0 -6
- package/inputs/Radio/Radio.stories.js.map +0 -7
- package/inputs/Radio/__stories__/Conditional/index.js +0 -100
- package/inputs/Radio/__stories__/Conditional/package.json +0 -6
- package/inputs/Radio/__stories__/Conditional.js.map +0 -7
- package/inputs/Radio/__stories__/Default/index.js +0 -48
- package/inputs/Radio/__stories__/Default/package.json +0 -6
- package/inputs/Radio/__stories__/Default.js.map +0 -7
- package/inputs/Radio/__stories__/WithDivider/index.js +0 -49
- package/inputs/Radio/__stories__/WithDivider/package.json +0 -6
- package/inputs/Radio/__stories__/WithDivider.js.map +0 -7
- package/inputs/Select/Select.stories/index.js +0 -12
- package/inputs/Select/Select.stories/package.json +0 -6
- package/inputs/Select/Select.stories.js.map +0 -7
- package/inputs/Select/__stories__/Default/index.js +0 -53
- package/inputs/Select/__stories__/Default/package.json +0 -6
- package/inputs/Select/__stories__/Default.js.map +0 -7
- package/lazy.d.ts +0 -77
- package/lazy.js.map +0 -7
- package/registry.d.ts +0 -70
- package/registry.js.map +0 -7
- package/src/Field/index.mdx +0 -6
- package/src/inputs/ImageInput/index.mdx +0 -19
- package/src/inputs/Input/index.mdx +0 -95
- package/src/inputs/Input/inputsInputScenarios.ts +0 -405
- package/src/inputs/Label/index.mdx +0 -0
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import dayjs from "dayjs";
|
|
2
|
+
import customParseFormat from "dayjs/plugin/customParseFormat";
|
|
3
|
+
dayjs.extend(customParseFormat);
|
|
4
|
+
const VALID_DATETIME_FORMATS = ["DD/MM/YYYY HH:mm"];
|
|
5
|
+
const DATETIME_CACHE = {};
|
|
6
|
+
const onlyNumbersRegex = /^\d+$/;
|
|
7
|
+
const getDateTime = (v) => {
|
|
8
|
+
return DATETIME_CACHE[v] ? DATETIME_CACHE[v] : dayjs(v, VALID_DATETIME_FORMATS, true);
|
|
9
|
+
};
|
|
10
|
+
const getDaysInMonth = (month, year) => {
|
|
11
|
+
return dayjs(`${year}-${month}-01`).daysInMonth();
|
|
12
|
+
};
|
|
13
|
+
const checkPartialDateTime = (value) => {
|
|
14
|
+
const [datePart, timePart] = value.split(" ");
|
|
15
|
+
const [day, month, year] = datePart?.split("/") ?? [];
|
|
16
|
+
const [hours, minutes] = timePart?.split(":") ?? [];
|
|
17
|
+
const hasDay = Boolean(day);
|
|
18
|
+
const hasMonth = Boolean(month);
|
|
19
|
+
const hasYear = Boolean(year);
|
|
20
|
+
const hasHours = Boolean(hours);
|
|
21
|
+
const hasMinutes = Boolean(minutes);
|
|
22
|
+
if (hasDay && !hasMonth && !hasYear && !hasHours && !hasMinutes) {
|
|
23
|
+
return "form.error.datetime.invalid_month_year_hours_minutes";
|
|
24
|
+
}
|
|
25
|
+
if (!hasDay && hasMonth && !hasYear && !hasHours && !hasMinutes) {
|
|
26
|
+
return "form.error.datetime.invalid_day_year_hours_minutes";
|
|
27
|
+
}
|
|
28
|
+
if (!hasDay && !hasMonth && hasYear && !hasHours && !hasMinutes) {
|
|
29
|
+
return "form.error.datetime.invalid_day_month_hours_minutes";
|
|
30
|
+
}
|
|
31
|
+
if (hasDay && hasMonth && !hasYear && !hasHours && !hasMinutes) {
|
|
32
|
+
return "form.error.datetime.invalid_year_hours_minutes";
|
|
33
|
+
}
|
|
34
|
+
if (hasDay && !hasMonth && hasYear && !hasHours && !hasMinutes) {
|
|
35
|
+
return "form.error.datetime.invalid_month_hours_minutes";
|
|
36
|
+
}
|
|
37
|
+
if (!hasDay && hasMonth && hasYear && !hasHours && !hasMinutes) {
|
|
38
|
+
return "form.error.datetime.invalid_day_hours_minutes";
|
|
39
|
+
}
|
|
40
|
+
if (hasDay && hasMonth && hasYear && !hasHours && !hasMinutes) {
|
|
41
|
+
return "form.error.datetime.invalid__hours_minutes";
|
|
42
|
+
}
|
|
43
|
+
if (hasDay && hasMonth && hasYear && hasHours && !hasMinutes) {
|
|
44
|
+
return "form.error.datetime.invalid_minutes";
|
|
45
|
+
}
|
|
46
|
+
if (hasDay && hasMonth && hasYear && !hasHours && hasMinutes) {
|
|
47
|
+
return "form.error.datetime.invalid_hours";
|
|
48
|
+
}
|
|
49
|
+
if (hasDay && !hasMonth && !hasYear && hasHours && !hasMinutes) {
|
|
50
|
+
return "form.error.datetime.invalid_month_year_minutes";
|
|
51
|
+
}
|
|
52
|
+
if (hasDay && !hasMonth && !hasYear && !hasHours && hasMinutes) {
|
|
53
|
+
return "form.error.datetime.invalid_month_year_hours";
|
|
54
|
+
}
|
|
55
|
+
if (hasDay && !hasMonth && !hasYear && hasHours && hasMinutes) {
|
|
56
|
+
return "form.error.datetime.invalid_month_year";
|
|
57
|
+
}
|
|
58
|
+
if (!hasDay && hasMonth && !hasYear && hasHours && !hasMinutes) {
|
|
59
|
+
return "form.error.datetime.invalid_day_year_minutes";
|
|
60
|
+
}
|
|
61
|
+
if (!hasDay && hasMonth && !hasYear && !hasHours && hasMinutes) {
|
|
62
|
+
return "form.error.datetime.invalid_day_year_hours";
|
|
63
|
+
}
|
|
64
|
+
if (!hasDay && hasMonth && !hasYear && hasHours && hasMinutes) {
|
|
65
|
+
return "form.error.datetime.invalid_day_year";
|
|
66
|
+
}
|
|
67
|
+
if (!hasDay && !hasMonth && hasYear && hasHours && !hasMinutes) {
|
|
68
|
+
return "form.error.datetime.invalid_day_month_minutes";
|
|
69
|
+
}
|
|
70
|
+
if (!hasDay && !hasMonth && hasYear && !hasHours && hasMinutes) {
|
|
71
|
+
return "form.error.datetime.invalid_day_month_hours";
|
|
72
|
+
}
|
|
73
|
+
if (!hasDay && !hasMonth && hasYear && hasHours && hasMinutes) {
|
|
74
|
+
return "form.error.datetime.invalid_day_month";
|
|
75
|
+
}
|
|
76
|
+
if (!hasDay && !hasMonth && !hasYear && hasHours && hasMinutes) {
|
|
77
|
+
return "form.error.datetime.invalid_day_month_year";
|
|
78
|
+
}
|
|
79
|
+
if (!hasDay && !hasMonth && !hasYear && !hasHours && hasMinutes) {
|
|
80
|
+
return "form.error.datetime.invalid_day_month_year_hours";
|
|
81
|
+
}
|
|
82
|
+
if (hasDay && hasMonth && !hasYear && hasHours && !hasMinutes) {
|
|
83
|
+
return "form.error.datetime.invalid_year_minutes";
|
|
84
|
+
}
|
|
85
|
+
if (hasDay && hasMonth && !hasYear && !hasHours && hasMinutes) {
|
|
86
|
+
return "form.error.datetime.invalid_year_hours";
|
|
87
|
+
}
|
|
88
|
+
if (hasDay && hasMonth && !hasYear && hasHours && hasMinutes) {
|
|
89
|
+
return "form.error.datetime.invalid_year";
|
|
90
|
+
}
|
|
91
|
+
if (hasDay && !hasMonth && hasYear && hasHours && !hasMinutes) {
|
|
92
|
+
return "form.error.datetime.invalid_month_minutes";
|
|
93
|
+
}
|
|
94
|
+
if (hasDay && !hasMonth && hasYear && !hasHours && hasMinutes) {
|
|
95
|
+
return "form.error.datetime.invalid_month_hours";
|
|
96
|
+
}
|
|
97
|
+
if (hasDay && !hasMonth && hasYear && hasHours && hasMinutes) {
|
|
98
|
+
return "form.error.datetime.invalid_month";
|
|
99
|
+
}
|
|
100
|
+
if (!hasDay && hasMonth && hasYear && hasHours && !hasMinutes) {
|
|
101
|
+
return "form.error.datetime.invalid_day_minutes";
|
|
102
|
+
}
|
|
103
|
+
if (!hasDay && hasMonth && hasYear && !hasHours && hasMinutes) {
|
|
104
|
+
return "form.error.datetime.invalid_day_hours";
|
|
105
|
+
}
|
|
106
|
+
if (!hasDay && hasMonth && hasYear && hasHours && hasMinutes) {
|
|
107
|
+
return "form.error.datetime.invalid_day";
|
|
108
|
+
}
|
|
109
|
+
if (!hasDay && !hasMonth && !hasYear && hasHours && !hasMinutes) {
|
|
110
|
+
return "form.error.datetime.invalid_day_month_year_minutes";
|
|
111
|
+
}
|
|
112
|
+
if (hasDay && hasMonth && hasYear && !hasHours && !hasMinutes) {
|
|
113
|
+
return "form.error.datetime.invalid_hours_minutes";
|
|
114
|
+
}
|
|
115
|
+
if (day && month) {
|
|
116
|
+
const dayNum = parseInt(day);
|
|
117
|
+
const monthNum = parseInt(month);
|
|
118
|
+
const validYear = onlyNumbersRegex.test(year) ? year : void 0;
|
|
119
|
+
if (!validYear || year.length < 4) {
|
|
120
|
+
return "form.error.datetime.invalid";
|
|
121
|
+
}
|
|
122
|
+
const yearNum = parseInt(validYear);
|
|
123
|
+
const maxDay = getDaysInMonth(monthNum, yearNum);
|
|
124
|
+
if (dayNum < 1 || dayNum > maxDay) {
|
|
125
|
+
return {
|
|
126
|
+
key: "form.error.datetime.invalid_day_range",
|
|
127
|
+
context: {
|
|
128
|
+
maxDay
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
if (monthNum < 1 || monthNum > 12) {
|
|
133
|
+
return "form.error.datetime.invalid_month_range";
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if (hours && minutes) {
|
|
137
|
+
const hoursNum = parseInt(hours);
|
|
138
|
+
const minutesNum = parseInt(minutes);
|
|
139
|
+
if (hoursNum < 0 || hoursNum > 23) {
|
|
140
|
+
return "form.error.datetime.invalid_hours_range";
|
|
141
|
+
}
|
|
142
|
+
if (minutesNum < 0 || minutesNum > 59) {
|
|
143
|
+
return "form.error.datetime.invalid_minutes_range";
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return "form.error.datetime.invalid";
|
|
147
|
+
};
|
|
148
|
+
const LATER_THAN_DATETIME_VALIDATOR = (field) => {
|
|
149
|
+
let minDateTime;
|
|
150
|
+
const params = field.extra || {};
|
|
151
|
+
if (params.min === "now") {
|
|
152
|
+
minDateTime = dayjs();
|
|
153
|
+
} else {
|
|
154
|
+
minDateTime = getDateTime(params.min);
|
|
155
|
+
}
|
|
156
|
+
return {
|
|
157
|
+
name: "later-than-datetime",
|
|
158
|
+
message: {
|
|
159
|
+
key: "form.error.datetime.later_than",
|
|
160
|
+
context: {
|
|
161
|
+
minDateTime: minDateTime.format("DD/MM/YYYY HH:mm")
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
test: function(value) {
|
|
165
|
+
if (!value) return true;
|
|
166
|
+
const datetime = getDateTime(value);
|
|
167
|
+
return datetime.isValid() && datetime.isAfter(minDateTime);
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
};
|
|
171
|
+
const EARLIER_THAN_DATETIME_VALIDATOR = (field) => {
|
|
172
|
+
let maxDateTime;
|
|
173
|
+
const params = field.extra || {};
|
|
174
|
+
if (params.max === "now") {
|
|
175
|
+
maxDateTime = dayjs();
|
|
176
|
+
} else {
|
|
177
|
+
maxDateTime = getDateTime(params.max);
|
|
178
|
+
}
|
|
179
|
+
return {
|
|
180
|
+
name: "earlier-than-datetime",
|
|
181
|
+
message: {
|
|
182
|
+
key: "form.error.datetime.earlier_than",
|
|
183
|
+
context: {
|
|
184
|
+
maxDateTime: maxDateTime.format("DD/MM/YYYY HH:mm")
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
test: function(value) {
|
|
188
|
+
if (!value) return true;
|
|
189
|
+
const datetime = getDateTime(value);
|
|
190
|
+
return datetime.isValid() && datetime.isBefore(maxDateTime);
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
};
|
|
194
|
+
const DATETIME_VALIDATOR = {
|
|
195
|
+
name: "datetime-validator",
|
|
196
|
+
message: (v) => {
|
|
197
|
+
return checkPartialDateTime(v.value);
|
|
198
|
+
},
|
|
199
|
+
test: function(value) {
|
|
200
|
+
if (!value) return true;
|
|
201
|
+
const datetime = getDateTime(value);
|
|
202
|
+
return datetime.isValid();
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
export {
|
|
206
|
+
DATETIME_VALIDATOR,
|
|
207
|
+
EARLIER_THAN_DATETIME_VALIDATOR,
|
|
208
|
+
LATER_THAN_DATETIME_VALIDATOR
|
|
209
|
+
};
|
|
210
|
+
//# sourceMappingURL=datetime.js.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { FieldSpec } from '@digigov/form/types';
|
|
2
|
+
import { ValidatorSchema } from '@digigov/form/validators/types';
|
|
3
|
+
export declare const LATER_THAN_DATETIME_VALIDATOR: (field: FieldSpec) => ValidatorSchema;
|
|
4
|
+
export declare const EARLIER_THAN_DATETIME_VALIDATOR: (field: FieldSpec) => ValidatorSchema;
|
|
5
|
+
export declare const DATETIME_VALIDATOR: {
|
|
6
|
+
name: string;
|
|
7
|
+
message: (v: any) => string | object;
|
|
8
|
+
test: (value: string) => any;
|
|
9
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/validators/utils/datetime.ts"],
|
|
4
|
+
"sourcesContent": ["import dayjs from 'dayjs';\nimport customParseFormat from 'dayjs/plugin/customParseFormat';\nimport { FieldSpec } from '@digigov/form/types';\nimport { ValidatorSchema } from '@digigov/form/validators/types';\n\ndayjs.extend(customParseFormat);\n\nconst VALID_DATETIME_FORMATS = ['DD/MM/YYYY HH:mm'];\nconst DATETIME_CACHE = {};\nconst onlyNumbersRegex = /^\\d+$/;\n\nconst getDateTime = (v: string) => {\n return DATETIME_CACHE[v]\n ? DATETIME_CACHE[v]\n : dayjs(v, VALID_DATETIME_FORMATS, true);\n};\n\nconst getDaysInMonth = (month: number, year: number): number => {\n return dayjs(`${year}-${month}-01`).daysInMonth(); // e.g. 29 for Feb 2024\n};\n\nconst checkPartialDateTime = (value: string) => {\n const [datePart, timePart] = value.split(' ');\n const [day, month, year] = datePart?.split('/') ?? [];\n const [hours, minutes] = timePart?.split(':') ?? [];\n\n const hasDay = Boolean(day);\n const hasMonth = Boolean(month);\n const hasYear = Boolean(year);\n const hasHours = Boolean(hours);\n const hasMinutes = Boolean(minutes);\n\n if (hasDay && !hasMonth && !hasYear && !hasHours && !hasMinutes) {\n return 'form.error.datetime.invalid_month_year_hours_minutes';\n }\n if (!hasDay && hasMonth && !hasYear && !hasHours && !hasMinutes) {\n return 'form.error.datetime.invalid_day_year_hours_minutes';\n }\n if (!hasDay && !hasMonth && hasYear && !hasHours && !hasMinutes) {\n return 'form.error.datetime.invalid_day_month_hours_minutes';\n }\n if (hasDay && hasMonth && !hasYear && !hasHours && !hasMinutes) {\n return 'form.error.datetime.invalid_year_hours_minutes';\n }\n if (hasDay && !hasMonth && hasYear && !hasHours && !hasMinutes) {\n return 'form.error.datetime.invalid_month_hours_minutes';\n }\n if (!hasDay && hasMonth && hasYear && !hasHours && !hasMinutes) {\n return 'form.error.datetime.invalid_day_hours_minutes';\n }\n if (hasDay && hasMonth && hasYear && !hasHours && !hasMinutes) {\n return 'form.error.datetime.invalid__hours_minutes';\n }\n if (hasDay && hasMonth && hasYear && hasHours && !hasMinutes) {\n return 'form.error.datetime.invalid_minutes';\n }\n if (hasDay && hasMonth && hasYear && !hasHours && hasMinutes) {\n return 'form.error.datetime.invalid_hours';\n }\n if (hasDay && !hasMonth && !hasYear && hasHours && !hasMinutes) {\n return 'form.error.datetime.invalid_month_year_minutes';\n }\n if (hasDay && !hasMonth && !hasYear && !hasHours && hasMinutes) {\n return 'form.error.datetime.invalid_month_year_hours';\n }\n if (hasDay && !hasMonth && !hasYear && hasHours && hasMinutes) {\n return 'form.error.datetime.invalid_month_year';\n }\n if (!hasDay && hasMonth && !hasYear && hasHours && !hasMinutes) {\n return 'form.error.datetime.invalid_day_year_minutes';\n }\n if (!hasDay && hasMonth && !hasYear && !hasHours && hasMinutes) {\n return 'form.error.datetime.invalid_day_year_hours';\n }\n if (!hasDay && hasMonth && !hasYear && hasHours && hasMinutes) {\n return 'form.error.datetime.invalid_day_year';\n }\n if (!hasDay && !hasMonth && hasYear && hasHours && !hasMinutes) {\n return 'form.error.datetime.invalid_day_month_minutes';\n }\n if (!hasDay && !hasMonth && hasYear && !hasHours && hasMinutes) {\n return 'form.error.datetime.invalid_day_month_hours';\n }\n if (!hasDay && !hasMonth && hasYear && hasHours && hasMinutes) {\n return 'form.error.datetime.invalid_day_month';\n }\n if (!hasDay && !hasMonth && !hasYear && hasHours && hasMinutes) {\n return 'form.error.datetime.invalid_day_month_year';\n }\n if (!hasDay && !hasMonth && !hasYear && !hasHours && hasMinutes) {\n return 'form.error.datetime.invalid_day_month_year_hours';\n }\n if (hasDay && hasMonth && !hasYear && hasHours && !hasMinutes) {\n return 'form.error.datetime.invalid_year_minutes';\n }\n if (hasDay && hasMonth && !hasYear && !hasHours && hasMinutes) {\n return 'form.error.datetime.invalid_year_hours';\n }\n if (hasDay && hasMonth && !hasYear && hasHours && hasMinutes) {\n return 'form.error.datetime.invalid_year';\n }\n if (hasDay && !hasMonth && hasYear && hasHours && !hasMinutes) {\n return 'form.error.datetime.invalid_month_minutes';\n }\n if (hasDay && !hasMonth && hasYear && !hasHours && hasMinutes) {\n return 'form.error.datetime.invalid_month_hours';\n }\n if (hasDay && !hasMonth && hasYear && hasHours && hasMinutes) {\n return 'form.error.datetime.invalid_month';\n }\n if (!hasDay && hasMonth && hasYear && hasHours && !hasMinutes) {\n return 'form.error.datetime.invalid_day_minutes';\n }\n if (!hasDay && hasMonth && hasYear && !hasHours && hasMinutes) {\n return 'form.error.datetime.invalid_day_hours';\n }\n if (!hasDay && hasMonth && hasYear && hasHours && hasMinutes) {\n return 'form.error.datetime.invalid_day';\n }\n if (!hasDay && !hasMonth && !hasYear && hasHours && !hasMinutes) {\n return 'form.error.datetime.invalid_day_month_year_minutes';\n }\n if (hasDay && hasMonth && hasYear && !hasHours && !hasMinutes) {\n return 'form.error.datetime.invalid_hours_minutes';\n }\n if (day && month) {\n const dayNum = parseInt(day);\n const monthNum = parseInt(month);\n const validYear = onlyNumbersRegex.test(year) ? year : undefined;\n if (!validYear || year.length < 4) {\n return 'form.error.datetime.invalid';\n }\n const yearNum = parseInt(validYear);\n const maxDay = getDaysInMonth(monthNum, yearNum);\n if (dayNum < 1 || dayNum > maxDay) {\n return {\n key: 'form.error.datetime.invalid_day_range',\n context: {\n maxDay: maxDay,\n },\n };\n }\n if (monthNum < 1 || monthNum > 12) {\n return 'form.error.datetime.invalid_month_range';\n }\n }\n if (hours && minutes) {\n const hoursNum = parseInt(hours);\n const minutesNum = parseInt(minutes);\n if (hoursNum < 0 || hoursNum > 23) {\n return 'form.error.datetime.invalid_hours_range';\n }\n if (minutesNum < 0 || minutesNum > 59) {\n return 'form.error.datetime.invalid_minutes_range';\n }\n }\n return 'form.error.datetime.invalid';\n};\n\nexport const LATER_THAN_DATETIME_VALIDATOR = (\n field: FieldSpec\n): ValidatorSchema => {\n let minDateTime;\n const params = field.extra || {};\n if (params.min === 'now') {\n minDateTime = dayjs();\n } else {\n minDateTime = getDateTime(params.min);\n }\n return {\n name: 'later-than-datetime',\n message: {\n key: 'form.error.datetime.later_than',\n context: {\n minDateTime: minDateTime.format('DD/MM/YYYY HH:mm'),\n },\n },\n test: function (value: string) {\n if (!value) return true;\n const datetime = getDateTime(value);\n return datetime.isValid() && datetime.isAfter(minDateTime);\n },\n };\n};\n\nexport const EARLIER_THAN_DATETIME_VALIDATOR = (\n field: FieldSpec\n): ValidatorSchema => {\n let maxDateTime;\n const params = field.extra || {};\n if (params.max === 'now') {\n maxDateTime = dayjs();\n } else {\n maxDateTime = getDateTime(params.max);\n }\n return {\n name: 'earlier-than-datetime',\n message: {\n key: 'form.error.datetime.earlier_than',\n context: {\n maxDateTime: maxDateTime.format('DD/MM/YYYY HH:mm'),\n },\n },\n test: function (value: string) {\n if (!value) return true;\n const datetime = getDateTime(value);\n return datetime.isValid() && datetime.isBefore(maxDateTime);\n },\n };\n};\n\nexport const DATETIME_VALIDATOR = {\n name: 'datetime-validator',\n message: (v): string | object => {\n return checkPartialDateTime(v.value);\n },\n test: function (value: string) {\n if (!value) return true;\n const datetime = getDateTime(value);\n return datetime.isValid();\n },\n};\n"],
|
|
5
|
+
"mappings": "AAAA,OAAO,WAAW;AAClB,OAAO,uBAAuB;AAI9B,MAAM,OAAO,iBAAiB;AAE9B,MAAM,yBAAyB,CAAC,kBAAkB;AAClD,MAAM,iBAAiB,CAAC;AACxB,MAAM,mBAAmB;AAEzB,MAAM,cAAc,CAAC,MAAc;AACjC,SAAO,eAAe,CAAC,IACnB,eAAe,CAAC,IAChB,MAAM,GAAG,wBAAwB,IAAI;AAC3C;AAEA,MAAM,iBAAiB,CAAC,OAAe,SAAyB;AAC9D,SAAO,MAAM,GAAG,IAAI,IAAI,KAAK,KAAK,EAAE,YAAY;AAClD;AAEA,MAAM,uBAAuB,CAAC,UAAkB;AAC9C,QAAM,CAAC,UAAU,QAAQ,IAAI,MAAM,MAAM,GAAG;AAC5C,QAAM,CAAC,KAAK,OAAO,IAAI,IAAI,UAAU,MAAM,GAAG,KAAK,CAAC;AACpD,QAAM,CAAC,OAAO,OAAO,IAAI,UAAU,MAAM,GAAG,KAAK,CAAC;AAElD,QAAM,SAAS,QAAQ,GAAG;AAC1B,QAAM,WAAW,QAAQ,KAAK;AAC9B,QAAM,UAAU,QAAQ,IAAI;AAC5B,QAAM,WAAW,QAAQ,KAAK;AAC9B,QAAM,aAAa,QAAQ,OAAO;AAElC,MAAI,UAAU,CAAC,YAAY,CAAC,WAAW,CAAC,YAAY,CAAC,YAAY;AAC/D,WAAO;AAAA,EACT;AACA,MAAI,CAAC,UAAU,YAAY,CAAC,WAAW,CAAC,YAAY,CAAC,YAAY;AAC/D,WAAO;AAAA,EACT;AACA,MAAI,CAAC,UAAU,CAAC,YAAY,WAAW,CAAC,YAAY,CAAC,YAAY;AAC/D,WAAO;AAAA,EACT;AACA,MAAI,UAAU,YAAY,CAAC,WAAW,CAAC,YAAY,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,MAAM,SAAU,OAAe;AAC7B,UAAI,CAAC,MAAO,QAAO;AACnB,YAAM,WAAW,YAAY,KAAK;AAClC,aAAO,SAAS,QAAQ,KAAK,SAAS,SAAS,WAAW;AAAA,IAC5D;AAAA,EACF;AACF;AAEO,MAAM,qBAAqB;AAAA,EAChC,MAAM;AAAA,EACN,SAAS,CAAC,MAAuB;AAC/B,WAAO,qBAAqB,EAAE,KAAK;AAAA,EACrC;AAAA,EACA,MAAM,SAAU,OAAe;AAC7B,QAAI,CAAC,MAAO,QAAO;AACnB,UAAM,WAAW,YAAY,KAAK;AAClC,WAAO,SAAS,QAAQ;AAAA,EAC1B;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,24 +1,37 @@
|
|
|
1
1
|
const DEFAULT_FILE_MAX_SIZE = 1e7;
|
|
2
|
-
const FILE_MAX_SIZE_VALIDATOR = (field) =>
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
2
|
+
const FILE_MAX_SIZE_VALIDATOR = (field) => {
|
|
3
|
+
const maxSizeInBytes = field?.extra?.limit?.maxSize || DEFAULT_FILE_MAX_SIZE;
|
|
4
|
+
let maxSizeTransformed = maxSizeInBytes / (1024 * 1024);
|
|
5
|
+
let maxSizeText = "MB";
|
|
6
|
+
if (Math.round(maxSizeTransformed) === 0) {
|
|
7
|
+
maxSizeTransformed = Math.round(maxSizeInBytes / 1024);
|
|
8
|
+
maxSizeText = "KB";
|
|
9
|
+
}
|
|
10
|
+
if (Math.round(maxSizeTransformed) === 0) {
|
|
11
|
+
maxSizeTransformed = maxSizeInBytes;
|
|
12
|
+
maxSizeText = "Bytes";
|
|
13
|
+
}
|
|
14
|
+
return {
|
|
15
|
+
name: "file-max-size-validator",
|
|
16
|
+
message: {
|
|
17
|
+
key: field.type === "file" ? "form.error.file_size" : "form.error.image_size",
|
|
18
|
+
context: {
|
|
19
|
+
maxSize: `${maxSizeTransformed} ${maxSizeText}`
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
test: (value) => {
|
|
23
|
+
if (value) {
|
|
24
|
+
for (const file of Array.from(value)) {
|
|
25
|
+
const maxSize = field?.extra?.limit?.maxSize || DEFAULT_FILE_MAX_SIZE;
|
|
26
|
+
if (file.size > maxSize) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
16
29
|
}
|
|
17
30
|
}
|
|
31
|
+
return true;
|
|
18
32
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
});
|
|
33
|
+
};
|
|
34
|
+
};
|
|
22
35
|
export {
|
|
23
36
|
FILE_MAX_SIZE_VALIDATOR
|
|
24
37
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/validators/utils/file.ts"],
|
|
4
|
-
"sourcesContent": ["import { FieldSpec } from '@digigov/form/types';\nimport { ValidatorSchema } from '@digigov/form/validators/types';\n\nconst DEFAULT_FILE_MAX_SIZE = 10000000;\n\nexport const FILE_MAX_SIZE_VALIDATOR = (field: FieldSpec): ValidatorSchema => ({\n name: 'file-max-size-validator',\n
|
|
5
|
-
"mappings": "AAGA,MAAM,wBAAwB;AAEvB,MAAM,0BAA0B,CAAC,
|
|
4
|
+
"sourcesContent": ["import { FieldSpec } from '@digigov/form/types';\nimport { ValidatorSchema } from '@digigov/form/validators/types';\n\nconst DEFAULT_FILE_MAX_SIZE = 10000000;\n\nexport const FILE_MAX_SIZE_VALIDATOR = (field: FieldSpec): ValidatorSchema => {\n const maxSizeInBytes = field?.extra?.limit?.maxSize || DEFAULT_FILE_MAX_SIZE;\n let maxSizeTransformed = maxSizeInBytes / (1024 * 1024); // In MB\n let maxSizeText = 'MB';\n if (Math.round(maxSizeTransformed) === 0) {\n maxSizeTransformed = Math.round(maxSizeInBytes / 1024);\n maxSizeText = 'KB';\n }\n if (Math.round(maxSizeTransformed) === 0) {\n maxSizeTransformed = maxSizeInBytes;\n maxSizeText = 'Bytes';\n }\n return {\n name: 'file-max-size-validator',\n message: {\n key:\n field.type === 'file'\n ? 'form.error.file_size'\n : 'form.error.image_size',\n context: {\n maxSize: `${maxSizeTransformed} ${maxSizeText}`,\n },\n },\n test: (value: File[]): boolean => {\n if (value) {\n for (const file of Array.from(value)) {\n const maxSize = field?.extra?.limit?.maxSize || DEFAULT_FILE_MAX_SIZE;\n if (file.size > maxSize) {\n return false;\n }\n }\n }\n return true;\n },\n };\n};\n"],
|
|
5
|
+
"mappings": "AAGA,MAAM,wBAAwB;AAEvB,MAAM,0BAA0B,CAAC,UAAsC;AAC5E,QAAM,iBAAiB,OAAO,OAAO,OAAO,WAAW;AACvD,MAAI,qBAAqB,kBAAkB,OAAO;AAClD,MAAI,cAAc;AAClB,MAAI,KAAK,MAAM,kBAAkB,MAAM,GAAG;AACxC,yBAAqB,KAAK,MAAM,iBAAiB,IAAI;AACrD,kBAAc;AAAA,EAChB;AACA,MAAI,KAAK,MAAM,kBAAkB,MAAM,GAAG;AACxC,yBAAqB;AACrB,kBAAc;AAAA,EAChB;AACA,SAAO;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,MACP,KACE,MAAM,SAAS,SACX,yBACA;AAAA,MACN,SAAS;AAAA,QACP,SAAS,GAAG,kBAAkB,IAAI,WAAW;AAAA,MAC/C;AAAA,IACF;AAAA,IACA,MAAM,CAAC,UAA2B;AAChC,UAAI,OAAO;AACT,mBAAW,QAAQ,MAAM,KAAK,KAAK,GAAG;AACpC,gBAAM,UAAU,OAAO,OAAO,OAAO,WAAW;AAChD,cAAI,KAAK,OAAO,SAAS;AACvB,mBAAO;AAAA,UACT;AAAA,QACF;AAAA,MACF;AACA,aAAO;AAAA,IACT;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -2,6 +2,7 @@ import * as yup from 'yup';
|
|
|
2
2
|
import { FieldSpec } from '@digigov/form/types';
|
|
3
3
|
import { ValidatorSchema } from '@digigov/form/validators/types';
|
|
4
4
|
export * from '@digigov/form/validators/utils/afm';
|
|
5
|
+
export * from '@digigov/form/validators/utils/amka';
|
|
5
6
|
export * from '@digigov/form/validators/utils/file';
|
|
6
7
|
export * from '@digigov/form/validators/utils/iban';
|
|
7
8
|
export * from '@digigov/form/validators/utils/otp';
|
|
@@ -10,6 +11,8 @@ export * from '@digigov/form/validators/utils/phone';
|
|
|
10
11
|
export * from '@digigov/form/validators/utils/postal_code';
|
|
11
12
|
export * from '@digigov/form/validators/utils/uuid4';
|
|
12
13
|
export * from '@digigov/form/validators/utils/text_limit';
|
|
14
|
+
export * from '@digigov/form/validators/utils/date';
|
|
15
|
+
export * from '@digigov/form/validators/utils/datetime';
|
|
13
16
|
export declare function getYupField(field: FieldSpec, yupTypeMap: Record<string, any>): any;
|
|
14
17
|
export declare function computeShape(fields: FieldSpec[], yupTypeMap: Record<string, ValidatorSchema>, validatorRegistry: Record<string, ValidatorSchema[]> | undefined): {};
|
|
15
18
|
export declare function getYupObjectShape(fields: FieldSpec[] | any, yupTypeMap: Record<string, any>, validatorRegistry?: Record<string, ValidatorSchema[]>): yup.ObjectSchema<{
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as yup from "yup";
|
|
2
2
|
export * from "@digigov/form/validators/utils/afm";
|
|
3
|
+
export * from "@digigov/form/validators/utils/amka";
|
|
3
4
|
export * from "@digigov/form/validators/utils/file";
|
|
4
5
|
export * from "@digigov/form/validators/utils/iban";
|
|
5
6
|
export * from "@digigov/form/validators/utils/otp";
|
|
@@ -8,6 +9,8 @@ export * from "@digigov/form/validators/utils/phone";
|
|
|
8
9
|
export * from "@digigov/form/validators/utils/postal_code";
|
|
9
10
|
export * from "@digigov/form/validators/utils/uuid4";
|
|
10
11
|
export * from "@digigov/form/validators/utils/text_limit";
|
|
12
|
+
export * from "@digigov/form/validators/utils/date";
|
|
13
|
+
export * from "@digigov/form/validators/utils/datetime";
|
|
11
14
|
function getYupField(field, yupTypeMap) {
|
|
12
15
|
const yupField = yupTypeMap[field?.type || "string"] || yupTypeMap["string"];
|
|
13
16
|
return yupField(field);
|
|
@@ -80,7 +83,9 @@ function getYupObjectShape(fields, yupTypeMap, validatorRegistry) {
|
|
|
80
83
|
}
|
|
81
84
|
return yup.lazy(function() {
|
|
82
85
|
const fieldSchemas = computeShape(
|
|
83
|
-
Object.values(fields.current)
|
|
86
|
+
Object.values(fields.current).filter(
|
|
87
|
+
(f) => !f.key.includes(".")
|
|
88
|
+
),
|
|
84
89
|
yupTypeMap,
|
|
85
90
|
validatorRegistry
|
|
86
91
|
);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/validators/utils/index.ts"],
|
|
4
|
-
"sourcesContent": ["import * as yup from 'yup';\nimport { FieldSpec } from '@digigov/form/types';\nimport { ValidatorSchema } from '@digigov/form/validators/types';\n\nexport * from '@digigov/form/validators/utils/afm';\nexport * from '@digigov/form/validators/utils/file';\nexport * from '@digigov/form/validators/utils/iban';\nexport * from '@digigov/form/validators/utils/otp';\nexport * from '@digigov/form/validators/utils/image';\nexport * from '@digigov/form/validators/utils/phone';\nexport * from '@digigov/form/validators/utils/postal_code';\nexport * from '@digigov/form/validators/utils/uuid4';\nexport * from '@digigov/form/validators/utils/text_limit';\n\nexport function getYupField(field: FieldSpec, yupTypeMap: Record<string, any>) {\n const yupField = yupTypeMap[field?.type || 'string'] || yupTypeMap['string'];\n return yupField(field);\n}\nexport function computeShape(\n fields: FieldSpec[],\n yupTypeMap: Record<string, ValidatorSchema>,\n validatorRegistry: Record<string, ValidatorSchema[]> | undefined\n) {\n const fieldSchemas = {};\n const objectFields: Record<string, FieldSpec[]> = {};\n fields.forEach((field) => {\n let yupField = getYupField(field, yupTypeMap);\n if (field.condition) {\n for (const key in field.condition) {\n let then: any, otherwise: any;\n if (field.condition[key].then) {\n if (field.condition[key].then?.required === false) {\n then = yupField.nullable();\n } else if (field.condition[key].then?.required === true) {\n then = yupField.nullable().required('form.error.required');\n }\n }\n if (field.condition[key].else) {\n if (field.condition[key].else?.required === false) {\n otherwise = yupField.nullable();\n } else if (field.condition[key].else?.required === true) {\n otherwise = yupField.nullable().required('form.error.required');\n }\n }\n if (then || otherwise) {\n yupField = yupField.when(key, {\n is: (val) => {\n //@ts-ignore\n const is = field.condition[key].is;\n if (is === val || (Array.isArray(val) && val.includes(is))) {\n return true;\n } else {\n return false;\n }\n },\n then,\n otherwise,\n });\n }\n }\n } else if (field.required) {\n yupField = yupField.nullable().required('form.error.required');\n }\n if (validatorRegistry && field.type && validatorRegistry[field.type]) {\n validatorRegistry[field.type].forEach((validator: any) => {\n yupField = yupField.test(validator);\n });\n }\n if (field.validators) {\n field.validators.forEach((validator) => {\n yupField = yupField.test(validator);\n });\n }\n fieldSchemas[field.key] = yupField;\n });\n for (const objectKey in objectFields) {\n fieldSchemas[objectKey] = getYupObjectShape(\n objectFields[objectKey],\n yupTypeMap,\n validatorRegistry\n );\n }\n return fieldSchemas;\n}\n\nexport function getYupObjectShape(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n fields: FieldSpec[] | any,\n yupTypeMap: Record<string, any>,\n validatorRegistry?: Record<string, ValidatorSchema[]>\n) {\n if (!fields.current) {\n const fieldSchemas = computeShape(fields, yupTypeMap, validatorRegistry);\n return yup.object().shape(fieldSchemas);\n }\n\n return yup.lazy(function () {\n const fieldSchemas = computeShape(\n Object.values(fields.current),\n yupTypeMap,\n validatorRegistry\n );\n return yup.object().shape(fieldSchemas);\n });\n}\n"],
|
|
5
|
-
"mappings": "AAAA,YAAY,SAAS;AAIrB,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAEP,SAAS,YAAY,OAAkB,YAAiC;A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IAC/D;AACA,QAAI,qBAAqB,MAAM,QAAQ,kBAAkB,MAAM,IAAI,GAAG;AACpE,wBAAkB,MAAM,IAAI,EAAE,QAAQ,CAAC,cAAmB;AACxD,mBAAW,SAAS,KAAK,SAAS;AAAA,MACpC,CAAC;AAAA,IACH;AACA,QAAI,MAAM,YAAY;AACpB,YAAM,WAAW,QAAQ,CAAC,cAAc;AACtC,mBAAW,SAAS,KAAK,SAAS;AAAA,MACpC,CAAC;AAAA,IACH;AACA,iBAAa,MAAM,GAAG,IAAI;AAAA,EAC5B,CAAC;AACD,aAAW,aAAa,cAAc;AACpC,iBAAa,SAAS,IAAI;AAAA,MACxB,aAAa,SAAS;AAAA,MACtB;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;AAEO,SAAS,kBAEd,QACA,YACA,mBACA;AACA,MAAI,CAAC,OAAO,SAAS;AACnB,UAAM,eAAe,aAAa,QAAQ,YAAY,iBAAiB;AACvE,WAAO,IAAI,OAAO,EAAE,MAAM,YAAY;AAAA,EACxC;AAEA,SAAO,IAAI,KAAK,WAAY;AAC1B,UAAM,eAAe;AAAA,MACnB,OAAO,OAAO,OAAO,OAAO;AAAA,
|
|
4
|
+
"sourcesContent": ["import * as yup from 'yup';\nimport { FieldSpec } from '@digigov/form/types';\nimport { ValidatorSchema } from '@digigov/form/validators/types';\n\nexport * from '@digigov/form/validators/utils/afm';\nexport * from '@digigov/form/validators/utils/amka';\nexport * from '@digigov/form/validators/utils/file';\nexport * from '@digigov/form/validators/utils/iban';\nexport * from '@digigov/form/validators/utils/otp';\nexport * from '@digigov/form/validators/utils/image';\nexport * from '@digigov/form/validators/utils/phone';\nexport * from '@digigov/form/validators/utils/postal_code';\nexport * from '@digigov/form/validators/utils/uuid4';\nexport * from '@digigov/form/validators/utils/text_limit';\nexport * from '@digigov/form/validators/utils/date';\nexport * from '@digigov/form/validators/utils/datetime';\n\nexport function getYupField(field: FieldSpec, yupTypeMap: Record<string, any>) {\n const yupField = yupTypeMap[field?.type || 'string'] || yupTypeMap['string'];\n return yupField(field);\n}\nexport function computeShape(\n fields: FieldSpec[],\n yupTypeMap: Record<string, ValidatorSchema>,\n validatorRegistry: Record<string, ValidatorSchema[]> | undefined\n) {\n const fieldSchemas = {};\n const objectFields: Record<string, FieldSpec[]> = {};\n fields.forEach((field) => {\n let yupField = getYupField(field, yupTypeMap);\n if (field.condition) {\n for (const key in field.condition) {\n let then: any, otherwise: any;\n if (field.condition[key].then) {\n if (field.condition[key].then?.required === false) {\n then = yupField.nullable();\n } else if (field.condition[key].then?.required === true) {\n then = yupField.nullable().required('form.error.required');\n }\n }\n if (field.condition[key].else) {\n if (field.condition[key].else?.required === false) {\n otherwise = yupField.nullable();\n } else if (field.condition[key].else?.required === true) {\n otherwise = yupField.nullable().required('form.error.required');\n }\n }\n if (then || otherwise) {\n yupField = yupField.when(key, {\n is: (val) => {\n //@ts-ignore\n const is = field.condition[key].is;\n if (is === val || (Array.isArray(val) && val.includes(is))) {\n return true;\n } else {\n return false;\n }\n },\n then,\n otherwise,\n });\n }\n }\n } else if (field.required) {\n yupField = yupField.nullable().required('form.error.required');\n }\n if (validatorRegistry && field.type && validatorRegistry[field.type]) {\n validatorRegistry[field.type].forEach((validator: any) => {\n yupField = yupField.test(validator);\n });\n }\n if (field.validators) {\n field.validators.forEach((validator) => {\n yupField = yupField.test(validator);\n });\n }\n fieldSchemas[field.key] = yupField;\n });\n for (const objectKey in objectFields) {\n fieldSchemas[objectKey] = getYupObjectShape(\n objectFields[objectKey],\n yupTypeMap,\n validatorRegistry\n );\n }\n return fieldSchemas;\n}\n\nexport function getYupObjectShape(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n fields: FieldSpec[] | any,\n yupTypeMap: Record<string, any>,\n validatorRegistry?: Record<string, ValidatorSchema[]>\n) {\n if (!fields.current) {\n const fieldSchemas = computeShape(fields, yupTypeMap, validatorRegistry);\n return yup.object().shape(fieldSchemas);\n }\n\n return yup.lazy(function () {\n const fieldSchemas = computeShape(\n Object.values(fields.current).filter(\n (f: FieldSpec) => !f.key.includes('.')\n ) as FieldSpec[],\n yupTypeMap,\n validatorRegistry\n );\n return yup.object().shape(fieldSchemas);\n });\n}\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,SAAS;AAIrB,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AAEP,SAAS,YAAY,OAAkB,YAAiC;AAC7E,QAAM,WAAW,WAAW,OAAO,QAAQ,QAAQ,KAAK,WAAW,QAAQ;AAC3E,SAAO,SAAS,KAAK;AACvB;AACO,SAAS,aACd,QACA,YACA,mBACA;AACA,QAAM,eAAe,CAAC;AACtB,QAAM,eAA4C,CAAC;AACnD,SAAO,QAAQ,CAAC,UAAU;AACxB,QAAI,WAAW,YAAY,OAAO,UAAU;AAC5C,QAAI,MAAM,WAAW;AACnB,iBAAW,OAAO,MAAM,WAAW;AACjC,YAAI,MAAW;AACf,YAAI,MAAM,UAAU,GAAG,EAAE,MAAM;AAC7B,cAAI,MAAM,UAAU,GAAG,EAAE,MAAM,aAAa,OAAO;AACjD,mBAAO,SAAS,SAAS;AAAA,UAC3B,WAAW,MAAM,UAAU,GAAG,EAAE,MAAM,aAAa,MAAM;AACvD,mBAAO,SAAS,SAAS,EAAE,SAAS,qBAAqB;AAAA,UAC3D;AAAA,QACF;AACA,YAAI,MAAM,UAAU,GAAG,EAAE,MAAM;AAC7B,cAAI,MAAM,UAAU,GAAG,EAAE,MAAM,aAAa,OAAO;AACjD,wBAAY,SAAS,SAAS;AAAA,UAChC,WAAW,MAAM,UAAU,GAAG,EAAE,MAAM,aAAa,MAAM;AACvD,wBAAY,SAAS,SAAS,EAAE,SAAS,qBAAqB;AAAA,UAChE;AAAA,QACF;AACA,YAAI,QAAQ,WAAW;AACrB,qBAAW,SAAS,KAAK,KAAK;AAAA,YAC5B,IAAI,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C;AACH;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/validators/utils/int.ts"],
|
|
4
|
-
"sourcesContent": ["import { ValidatorSchema } from '@digigov/form/validators/types';\n\nexport function validateIntNumber(number: number): boolean {\n if (number === undefined) {\n return false;\n } else {\n return Number.isInteger(number) && Number(number) > 0;\n }\n}\n\nexport const INT_VALIDATOR = (): ValidatorSchema => {\n return {\n name: 'int-validator',\n message: 'form.error.positive_integer_number',\n test: (value: number): boolean => {\n if (value ===
|
|
5
|
-
"mappings": "AAEO,SAAS,kBAAkB,QAAyB;AACzD,MAAI,WAAW,QAAW;AACxB,WAAO;AAAA,EACT,OAAO;AACL,WAAO,OAAO,UAAU,MAAM,KAAK,OAAO,MAAM,IAAI;AAAA,EACtD;AACF;AAEO,MAAM,gBAAgB,MAAuB;AAClD,SAAO;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,IACT,MAAM,CAAC,UAA2B;AAChC,UAAI,UAAU,
|
|
4
|
+
"sourcesContent": ["import { ValidatorSchema } from '@digigov/form/validators/types';\n\nexport function validateIntNumber(number: number): boolean {\n if (number === undefined) {\n return false;\n } else {\n return Number.isInteger(number) && Number(number) > 0;\n }\n}\n\nexport const INT_VALIDATOR = (): ValidatorSchema => {\n return {\n name: 'int-validator',\n message: 'form.error.positive_integer_number',\n test: (value: number): boolean => {\n if (value === undefined) {\n return true;\n }\n return validateIntNumber(value);\n },\n };\n};\n"],
|
|
5
|
+
"mappings": "AAEO,SAAS,kBAAkB,QAAyB;AACzD,MAAI,WAAW,QAAW;AACxB,WAAO;AAAA,EACT,OAAO;AACL,WAAO,OAAO,UAAU,MAAM,KAAK,OAAO,MAAM,IAAI;AAAA,EACtD;AACF;AAEO,MAAM,gBAAgB,MAAuB;AAClD,SAAO;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,IACT,MAAM,CAAC,UAA2B;AAChC,UAAI,UAAU,QAAW;AACvB,eAAO;AAAA,MACT;AACA,aAAO,kBAAkB,KAAK;AAAA,IAChC;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/validators/utils/number.ts"],
|
|
4
|
-
"sourcesContent": ["import { ValidatorSchema } from '@digigov/form/validators/types';\n\nexport function validateNumber(number: number): boolean {\n return !Number.isNaN(number);\n}\n\nexport const NUMBER_VALIDATOR = (): ValidatorSchema => {\n return {\n name: 'number-validator',\n message: 'form.error.number',\n test: (value: number): boolean => {\n if (value ===
|
|
5
|
-
"mappings": "AAEO,SAAS,eAAe,QAAyB;AACtD,SAAO,CAAC,OAAO,MAAM,MAAM;AAC7B;AAEO,MAAM,mBAAmB,MAAuB;AACrD,SAAO;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,IACT,MAAM,CAAC,UAA2B;AAChC,UAAI,UAAU,
|
|
4
|
+
"sourcesContent": ["import { ValidatorSchema } from '@digigov/form/validators/types';\n\nexport function validateNumber(number: number): boolean {\n return !Number.isNaN(number);\n}\n\nexport const NUMBER_VALIDATOR = (): ValidatorSchema => {\n return {\n name: 'number-validator',\n message: 'form.error.number',\n test: (value: number): boolean => {\n if (value === undefined) {\n return true;\n }\n return validateNumber(value);\n },\n };\n};\n"],
|
|
5
|
+
"mappings": "AAEO,SAAS,eAAe,QAAyB;AACtD,SAAO,CAAC,OAAO,MAAM,MAAM;AAC7B;AAEO,MAAM,mBAAmB,MAAuB;AACrD,SAAO;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,IACT,MAAM,CAAC,UAA2B;AAChC,UAAI,UAAU,QAAW;AACvB,eAAO;AAAA,MACT;AACA,aAAO,eAAe,KAAK;AAAA,IAC7B;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -2,7 +2,7 @@ import { FieldSpec } from '@digigov/form/types';
|
|
|
2
2
|
import { ValidatorSchema } from '@digigov/form/validators/types';
|
|
3
3
|
export type PhoneNumberType = 'landline' | 'mobile' | null;
|
|
4
4
|
export declare function discoverPhoneType(phoneNumber: string, config: any): string;
|
|
5
|
-
export declare function validatePhoneNumber(phoneNumber: string, countries?:
|
|
5
|
+
export declare function validatePhoneNumber(phoneNumber: string, countries?: string[], typeOfPhoneNumber?: PhoneNumberType): boolean;
|
|
6
6
|
export declare const MOBILE_PHONE_VALIDATOR: {
|
|
7
7
|
name: string;
|
|
8
8
|
message: string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/validators/utils/phone.ts"],
|
|
4
|
-
"sourcesContent": ["import { FieldSpec } from '@digigov/form/types';\nimport { ValidatorSchema } from '@digigov/form/validators/types';\n\nexport type PhoneNumberType = 'landline' | 'mobile' | null;\n// add more countries from here libphonenumber-js/metadata.full.json\nconst countryPhoneData = {\n GR: [\n '30',\n '00',\n '5005000\\\\d{3}|8\\\\d{9,11}|(?:[269]\\\\d|70)\\\\d{8}',\n [10, 11, 12],\n [\n ['(\\\\d{2})(\\\\d{4})(\\\\d{4})', '$1 $2 $3', ['21|7']],\n [\n '(\\\\d{4})(\\\\d{6})',\n '$1 $2',\n ['2(?:2|3[2-57-9]|4[2-469]|5[2-59]|6[2-9]|7[2-69]|8[2-49])|5'],\n ],\n ['(\\\\d{3})(\\\\d{3})(\\\\d{4})', '$1 $2 $3', ['[2689]']],\n ['(\\\\d{3})(\\\\d{3,4})(\\\\d{5})', '$1 $2 $3', ['8']],\n ],\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n [\n [\n '2(?:1\\\\d\\\\d|2(?:2[1-46-9]|[36][1-8]|4[1-7]|5[1-4]|7[1-5]|[89][1-9])|3(?:1\\\\d|2[1-57]|[35][1-3]|4[13]|7[1-7]|8[124-6]|9[1-79])|4(?:1\\\\d|2[1-8]|3[1-4]|4[13-5]|6[1-578]|9[1-5])|5(?:1\\\\d|[29][1-4]|3[1-5]|4[124]|5[1-6])|6(?:1\\\\d|[269][1-6]|3[1245]|4[1-7]|5[13-9]|7[14]|8[1-5])|7(?:1\\\\d|2[1-5]|3[1-6]|4[1-7]|5[1-57]|6[135]|9[125-7])|8(?:1\\\\d|2[1-5]|[34][1-4]|9[1-57]))\\\\d{6}',\n [10],\n ],\n ['68[57-9]\\\\d{7}|(?:69|94)\\\\d{8}', [10]],\n ['800\\\\d{7,9}'],\n ['90[19]\\\\d{7}', [10]],\n ['70\\\\d{8}', [10]],\n 0,\n ['5005000\\\\d{3}', [10]],\n 0,\n 0,\n ['8(?:0[16]|12|[27]5|50)\\\\d{7}', [10]],\n ],\n ],\n};\n\nfunction expandPhoneNumberStructure(compressed) {\n const countries = Object.keys(compressed);\n const expanded: any = {};\n for (const country of countries) {\n expanded[country] = {\n fixedLine: {\n possibleLengths: {\n _national: compressed[country][3].map(String),\n },\n nationalNumberPattern: compressed[country][11][0][0],\n },\n mobile: {\n nationalNumberPattern: compressed[country][11][1][0],\n },\n tollFree: {\n nationalNumberPattern: compressed[country][11][2][0],\n },\n premiumRate: {\n nationalNumberPattern: compressed[country][11][3][0],\n },\n sharedCost: {\n nationalNumberPattern: compressed[country][11][9][0],\n },\n personalNumber: {\n nationalNumberPattern: compressed[country][11][4][0],\n },\n uan: {\n nationalNumberPattern: compressed[country][11][6][0],\n },\n id: country,\n countryCode: compressed[country][0],\n internationalPrefix: compressed[country][1],\n };\n }\n return expanded;\n}\nconst PHONENUMBER_SPEC = expandPhoneNumberStructure(countryPhoneData);\nexport function discoverPhoneType(phoneNumber: string, config: any): string {\n const cleanNumber = phoneNumber\n .replace(/\\D/g, '')\n .replace(/\\s/g, '')\n .replace(/^\\+/, '')\n .replace(new RegExp('^' + config.internationalPrefix, ''), '')\n .replace(new RegExp('^' + config.countryCode, ''), '');\n const categories = {\n landline: config.fixedLine,\n mobile: config.mobile,\n 'toll-free': config.tollFree,\n 'premium-rate': config.premiumRate,\n };\n\n for (const [categoryName, categoryDetails] of Object.entries(categories)) {\n const pattern = new RegExp(\n '^(' + categoryDetails.nationalNumberPattern.replace(/\\s/g, '') + ')$',\n ''\n );\n if (cleanNumber.match(pattern)) {\n return categoryName; // Returns the category name if the number matches the pattern\n }\n }\n\n // If no category matches, return 'Unknown'\n return 'unknown';\n}\nfunction getNumberType(phoneNumber: string, country: string) {\n const spec = PHONENUMBER_SPEC[country.toUpperCase()];\n if (!spec) {\n throw new Error(`Country ${country} is not supported`);\n }\n const type = discoverPhoneType(phoneNumber, spec);\n return type;\n}\n\nfunction isPhoneNumberValid(\n phoneNumber: string,\n countries: string[],\n types = ['mobile', 'landline']\n) {\n return countries.some((country) => {\n const numberType = getNumberType(phoneNumber, country);\n if (numberType && types.includes(numberType)) {\n return true;\n }\n return false;\n });\n}\nfunction isNumberOfType(phoneNumber: string, country: string, type: string) {\n const numberType = getNumberType(phoneNumber, country);\n if (numberType === type) {\n return true;\n }\n return false;\n}\nexport function validatePhoneNumber(\n phoneNumber: string,\n countries:
|
|
5
|
-
"mappings": "AAKA,MAAM,mBAAmB;AAAA,EACvB,IAAI;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,IACA,CAAC,IAAI,IAAI,EAAE;AAAA,IACX;AAAA,MACE,CAAC,4BAA4B,YAAY,CAAC,MAAM,CAAC;AAAA,MACjD;AAAA,QACE;AAAA,QACA;AAAA,QACA,CAAC,4DAA4D;AAAA,MAC/D;AAAA,MACA,CAAC,4BAA4B,YAAY,CAAC,QAAQ,CAAC;AAAA,MACnD,CAAC,8BAA8B,YAAY,CAAC,GAAG,CAAC;AAAA,IAClD;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,MACE;AAAA,QACE;AAAA,QACA,CAAC,EAAE;AAAA,MACL;AAAA,MACA,CAAC,kCAAkC,CAA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qB,SAAiB,MAAc;AAC1E,QAAM,aAAa,cAAc,aAAa,OAAO;AACrD,MAAI,eAAe,MAAM;AACvB,WAAO;AAAA,EACT;AACA,SAAO;AACT;AACO,SAAS,oBACd,aACA,
|
|
4
|
+
"sourcesContent": ["import { FieldSpec } from '@digigov/form/types';\nimport { ValidatorSchema } from '@digigov/form/validators/types';\n\nexport type PhoneNumberType = 'landline' | 'mobile' | null;\n// add more countries from here libphonenumber-js/metadata.full.json\nconst countryPhoneData = {\n GR: [\n '30',\n '00',\n '5005000\\\\d{3}|8\\\\d{9,11}|(?:[269]\\\\d|70)\\\\d{8}',\n [10, 11, 12],\n [\n ['(\\\\d{2})(\\\\d{4})(\\\\d{4})', '$1 $2 $3', ['21|7']],\n [\n '(\\\\d{4})(\\\\d{6})',\n '$1 $2',\n ['2(?:2|3[2-57-9]|4[2-469]|5[2-59]|6[2-9]|7[2-69]|8[2-49])|5'],\n ],\n ['(\\\\d{3})(\\\\d{3})(\\\\d{4})', '$1 $2 $3', ['[2689]']],\n ['(\\\\d{3})(\\\\d{3,4})(\\\\d{5})', '$1 $2 $3', ['8']],\n ],\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n [\n [\n '2(?:1\\\\d\\\\d|2(?:2[1-46-9]|[36][1-8]|4[1-7]|5[1-4]|7[1-5]|[89][1-9])|3(?:1\\\\d|2[1-57]|[35][1-3]|4[13]|7[1-7]|8[124-6]|9[1-79])|4(?:1\\\\d|2[1-8]|3[1-4]|4[13-5]|6[1-578]|9[1-5])|5(?:1\\\\d|[29][1-4]|3[1-5]|4[124]|5[1-6])|6(?:1\\\\d|[269][1-6]|3[1245]|4[1-7]|5[13-9]|7[14]|8[1-5])|7(?:1\\\\d|2[1-5]|3[1-6]|4[1-7]|5[1-57]|6[135]|9[125-7])|8(?:1\\\\d|2[1-5]|[34][1-4]|9[1-57]))\\\\d{6}',\n [10],\n ],\n ['68[57-9]\\\\d{7}|(?:69|94)\\\\d{8}', [10]],\n ['800\\\\d{7,9}'],\n ['90[19]\\\\d{7}', [10]],\n ['70\\\\d{8}', [10]],\n 0,\n ['5005000\\\\d{3}', [10]],\n 0,\n 0,\n ['8(?:0[16]|12|[27]5|50)\\\\d{7}', [10]],\n ],\n ],\n};\n\nfunction expandPhoneNumberStructure(compressed) {\n const countries = Object.keys(compressed);\n const expanded: any = {};\n for (const country of countries) {\n expanded[country] = {\n fixedLine: {\n possibleLengths: {\n _national: compressed[country][3].map(String),\n },\n nationalNumberPattern: compressed[country][11][0][0],\n },\n mobile: {\n nationalNumberPattern: compressed[country][11][1][0],\n },\n tollFree: {\n nationalNumberPattern: compressed[country][11][2][0],\n },\n premiumRate: {\n nationalNumberPattern: compressed[country][11][3][0],\n },\n sharedCost: {\n nationalNumberPattern: compressed[country][11][9][0],\n },\n personalNumber: {\n nationalNumberPattern: compressed[country][11][4][0],\n },\n uan: {\n nationalNumberPattern: compressed[country][11][6][0],\n },\n id: country,\n countryCode: compressed[country][0],\n internationalPrefix: compressed[country][1],\n };\n }\n return expanded;\n}\nconst PHONENUMBER_SPEC = expandPhoneNumberStructure(countryPhoneData);\nexport function discoverPhoneType(phoneNumber: string, config: any): string {\n const cleanNumber = phoneNumber\n .replace(/\\D/g, '')\n .replace(/\\s/g, '')\n .replace(/^\\+/, '')\n .replace(new RegExp('^' + config.internationalPrefix, ''), '')\n .replace(new RegExp('^' + config.countryCode, ''), '');\n const categories = {\n landline: config.fixedLine,\n mobile: config.mobile,\n 'toll-free': config.tollFree,\n 'premium-rate': config.premiumRate,\n };\n\n for (const [categoryName, categoryDetails] of Object.entries(categories)) {\n const pattern = new RegExp(\n '^(' + categoryDetails.nationalNumberPattern.replace(/\\s/g, '') + ')$',\n ''\n );\n if (cleanNumber.match(pattern)) {\n return categoryName; // Returns the category name if the number matches the pattern\n }\n }\n\n // If no category matches, return 'Unknown'\n return 'unknown';\n}\nfunction getNumberType(phoneNumber: string, country: string) {\n const spec = PHONENUMBER_SPEC[country.toUpperCase()];\n if (!spec) {\n throw new Error(`Country ${country} is not supported`);\n }\n const type = discoverPhoneType(phoneNumber, spec);\n return type;\n}\n\nfunction isPhoneNumberValid(\n phoneNumber: string,\n countries: string[],\n types = ['mobile', 'landline']\n) {\n return countries.some((country) => {\n const numberType = getNumberType(phoneNumber, country);\n if (numberType && types.includes(numberType)) {\n return true;\n }\n return false;\n });\n}\nfunction isNumberOfType(phoneNumber: string, country: string, type: string) {\n const numberType = getNumberType(phoneNumber, country);\n if (numberType === type) {\n return true;\n }\n return false;\n}\nexport function validatePhoneNumber(\n phoneNumber: string,\n countries: string[] = ['gr'],\n typeOfPhoneNumber?: PhoneNumberType\n): boolean {\n if (!countries || countries.length === 0) {\n return true;\n }\n return isPhoneNumberValid(\n phoneNumber,\n countries,\n typeOfPhoneNumber ? [typeOfPhoneNumber] : undefined\n );\n}\n\nfunction validateMobile(value): boolean {\n return isNumberOfType(value, 'gr', 'mobile');\n}\n\nexport const MOBILE_PHONE_VALIDATOR = {\n name: 'mobile-phone-validator',\n message: 'form.error.mobile_phone',\n test: (value): boolean => {\n if (value) {\n return validateMobile(value);\n }\n return true;\n },\n};\n\nexport const PHONE_NUMBER_VALIDATOR = (field: FieldSpec): ValidatorSchema => {\n const countryCodes = field?.extra?.countries;\n const typeOfPhone: PhoneNumberType | null = field?.extra?.phoneType;\n return {\n name: 'phone-number-validator',\n message: (): string => {\n if (typeOfPhone === 'mobile') {\n return 'form.error.mobile_phone';\n }\n if (typeOfPhone === 'landline') {\n return 'form.error.landline';\n } else {\n return 'form.error.phone_number';\n }\n },\n test: (value: string): boolean => {\n if (!value) {\n return true;\n }\n return validatePhoneNumber(value, countryCodes, typeOfPhone);\n },\n };\n};\n"],
|
|
5
|
+
"mappings": "AAKA,MAAM,mBAAmB;AAAA,EACvB,IAAI;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,IACA,CAAC,IAAI,IAAI,EAAE;AAAA,IACX;AAAA,MACE,CAAC,4BAA4B,YAAY,CAAC,MAAM,CAAC;AAAA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AAC,OAAO;AACV,eAAO;AAAA,MACT;AACA,aAAO,oBAAoB,OAAO,cAAc,WAAW;AAAA,IAC7D;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { FieldSpec } from '@digigov/form/types';
|
|
2
2
|
import { ValidatorSchema } from '@digigov/form/validators/types';
|
|
3
|
-
export declare function validatePostalCode(number: string, countries:
|
|
3
|
+
export declare function validatePostalCode(number: string, countries: string[]): boolean;
|
|
4
4
|
export declare const POSTALCODE_VALIDATOR: (field: FieldSpec) => ValidatorSchema;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/validators/utils/postal_code.ts"],
|
|
4
|
-
"sourcesContent": ["import { FieldSpec } from '@digigov/form/types';\nimport { ValidatorSchema } from '@digigov/form/validators/types';\n\nconst CODE_REGEX = /^[12345678][0-9]{4}$/;\nexport function validatePostalCode(\n number: string,\n countries:
|
|
4
|
+
"sourcesContent": ["import { FieldSpec } from '@digigov/form/types';\nimport { ValidatorSchema } from '@digigov/form/validators/types';\n\nconst CODE_REGEX = /^[12345678][0-9]{4}$/;\nexport function validatePostalCode(\n number: string,\n countries: string[]\n): boolean {\n if (!countries) {\n return false;\n } else {\n if (countries.length === 1 && countries[0].toUpperCase() === 'GR') {\n // Greek postal code must be 5 digits long and shouldn't start with 0 or 9.\n return CODE_REGEX.test(number);\n } else {\n return true;\n }\n }\n}\n\nexport const POSTALCODE_VALIDATOR = (field: FieldSpec): ValidatorSchema => {\n const countryCode = field?.extra?.countries;\n return {\n name: 'postal-code-validator',\n message: 'form.error.postalCode',\n test: (value: string): boolean => {\n if (!value) {\n return true;\n }\n return validatePostalCode(value, countryCode);\n },\n };\n};\n"],
|
|
5
5
|
"mappings": "AAGA,MAAM,aAAa;AACZ,SAAS,mBACd,QACA,WACS;AACT,MAAI,CAAC,WAAW;AACd,WAAO;AAAA,EACT,OAAO;AACL,QAAI,UAAU,WAAW,KAAK,UAAU,CAAC,EAAE,YAAY,MAAM,MAAM;AAEjE,aAAO,WAAW,KAAK,MAAM;AAAA,IAC/B,OAAO;AACL,aAAO;AAAA,IACT;AAAA,EACF;AACF;AAEO,MAAM,uBAAuB,CAAC,UAAsC;AACzE,QAAM,cAAc,OAAO,OAAO;AAClC,SAAO;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,IACT,MAAM,CAAC,UAA2B;AAChC,UAAI,CAAC,OAAO;AACV,eAAO;AAAA,MACT;AACA,aAAO,mBAAmB,OAAO,WAAW;AAAA,IAC9C;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/validators/utils/uuid4.ts"],
|
|
4
|
-
"sourcesContent": ["const UUID4_PATTERN
|
|
5
|
-
"mappings": "AAAA,MAAM,
|
|
4
|
+
"sourcesContent": ["const UUID4_PATTERN =\n /^[0-9A-F]{8}-[0-9A-F]{4}-[4][0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$/i;\n\nexport function validateUUID4(uuid4: string): boolean {\n if (uuid4.length !== 36) {\n // This uuid4 should be 36 characters long\n return false;\n }\n\n return UUID4_PATTERN.test(uuid4);\n}\n\nexport const UUID4_VALIDATOR = {\n name: 'uuid4-validator',\n message: 'form.error.uuid4',\n test: (value): boolean => {\n if (value) {\n return validateUUID4(value);\n }\n return true;\n },\n};\n"],
|
|
5
|
+
"mappings": "AAAA,MAAM,gBACJ;AAEK,SAAS,cAAc,OAAwB;AACpD,MAAI,MAAM,WAAW,IAAI;AAEvB,WAAO;AAAA,EACT;AAEA,SAAO,cAAc,KAAK,KAAK;AACjC;AAEO,MAAM,kBAAkB;AAAA,EAC7B,MAAM;AAAA,EACN,SAAS;AAAA,EACT,MAAM,CAAC,UAAmB;AACxB,QAAI,OAAO;AACT,aAAO,cAAc,KAAK;AAAA,IAC5B;AACA,WAAO;AAAA,EACT;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import FieldArray from "@digigov/form/FieldArray";
|
|
2
|
-
var FieldArray_stories_default = {
|
|
3
|
-
title: "Digigov Form/FieldArray",
|
|
4
|
-
component: FieldArray,
|
|
5
|
-
displayName: "FieldArray"
|
|
6
|
-
};
|
|
7
|
-
import { Default } from "@digigov/form/FieldArray/__stories__/Default";
|
|
8
|
-
import { WithExactLength } from "@digigov/form/FieldArray/__stories__/WithExactLength";
|
|
9
|
-
export {
|
|
10
|
-
Default,
|
|
11
|
-
WithExactLength,
|
|
12
|
-
FieldArray_stories_default as default
|
|
13
|
-
};
|
|
14
|
-
//# sourceMappingURL=FieldArray.stories.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../src/FieldArray/FieldArray.stories.js"],
|
|
4
|
-
"sourcesContent": ["import FieldArray from '@digigov/form/FieldArray';\nexport default {\n title: 'Digigov Form/FieldArray',\n component: FieldArray,\n displayName: 'FieldArray',\n};\nexport { Default } from '@digigov/form/FieldArray/__stories__/Default';\nexport { WithExactLength } from '@digigov/form/FieldArray/__stories__/WithExactLength';\n"],
|
|
5
|
-
"mappings": "AAAA,OAAO,gBAAgB;AACvB,IAAO,6BAAQ;AAAA,EACb,OAAO;AAAA,EACP,WAAW;AAAA,EACX,aAAa;AACf;AACA,SAAS,eAAe;AACxB,SAAS,uBAAuB;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|