@digigov/form 2.0.0-a32ad9b2 → 2.0.0-abd768eb
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/FieldBase/index.js +7 -2
- package/Field/FieldBase.js.map +2 -2
- package/Field/FieldBaseContainer/index.js +37 -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 +10 -4
- package/Field/index.js.map +2 -2
- package/Field/types.d.ts +10 -3
- package/Field/utils/index.js +3 -1
- package/Field/utils/index.js.map +2 -2
- package/Field/utils/useField/index.js +8 -1
- package/Field/utils/useField.js.map +2 -2
- package/FieldArray/FormDialog/index.js +314 -196
- package/FieldArray/FormDialog.d.ts +20 -7
- package/FieldArray/FormDialog.js.map +3 -3
- package/FieldArray/__stories__/Default.d.ts +1 -1
- package/FieldArray/__stories__/WithExactLength.d.ts +1 -1
- package/FieldArray/__stories__/WithModal.d.ts +1 -1
- package/FieldArray/index.d.ts +1 -0
- package/FieldArray/index.js +32 -8
- package/FieldArray/index.js.map +2 -2
- package/FieldObject/index.d.ts +3 -0
- package/FieldObject/index.js +26 -15
- package/FieldObject/index.js.map +2 -2
- package/FormBuilder/FormBuilder.stories.d.ts +2 -0
- package/FormBuilder/__stories__/AutoErrorGrouping.d.ts +1 -1
- package/FormBuilder/__stories__/Default.d.ts +1 -1
- package/FormBuilder/__stories__/ErrorGrouping.d.ts +1 -1
- package/FormBuilder/index.d.ts +1 -1
- package/FormBuilder/index.js +11 -7
- package/FormBuilder/index.js.map +2 -2
- 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 +2 -0
- package/MultiplicityField/add-objects.js.map +2 -2
- package/MultiplicityField/index.js +4 -1
- package/MultiplicityField/index.js.map +2 -2
- package/MultiplicityField/types.d.ts +1 -0
- package/Questions/Questions.stories.d.ts +2 -0
- package/Questions/__stories__/Default.d.ts +1 -1
- package/cjs/Field/FieldBase/index.js +7 -2
- package/cjs/Field/FieldBase.js.map +2 -2
- package/cjs/Field/FieldBaseContainer/index.js +36 -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 +10 -4
- package/cjs/Field/index.js.map +2 -2
- package/cjs/Field/types.js.map +1 -1
- package/cjs/Field/utils/index.js +3 -1
- package/cjs/Field/utils/index.js.map +2 -2
- package/cjs/Field/utils/useField/index.js +8 -1
- package/cjs/Field/utils/useField.js.map +2 -2
- package/cjs/FieldArray/FormDialog/index.js +309 -194
- package/cjs/FieldArray/FormDialog.js.map +3 -3
- package/cjs/FieldArray/index.js +31 -7
- package/cjs/FieldArray/index.js.map +2 -2
- package/cjs/FieldObject/index.js +26 -15
- package/cjs/FieldObject/index.js.map +2 -2
- package/cjs/FormBuilder/index.js +11 -7
- package/cjs/FormBuilder/index.js.map +2 -2
- package/cjs/FormContext/index.js +7 -2
- package/cjs/FormContext.js.map +2 -2
- package/cjs/MultiplicityField/add-objects/index.js +2 -0
- package/cjs/MultiplicityField/add-objects.js.map +2 -2
- package/cjs/MultiplicityField/index.js +4 -1
- package/cjs/MultiplicityField/index.js.map +2 -2
- package/cjs/MultiplicityField/types.js.map +1 -1
- package/cjs/inputs/Checkboxes/index.js +2 -2
- package/cjs/inputs/Checkboxes/index.js.map +2 -2
- package/cjs/inputs/DateInput/index.js +41 -14
- package/cjs/inputs/DateInput/index.js.map +2 -2
- package/cjs/inputs/DateTimeInput/index.js +68 -34
- package/cjs/inputs/DateTimeInput/index.js.map +2 -2
- package/cjs/inputs/FileInput/index.js +52 -29
- package/cjs/inputs/FileInput/index.js.map +2 -2
- package/cjs/inputs/ImageInput/__stories__/logo.d/index.js +1 -0
- package/cjs/inputs/ImageInput/__stories__/logo.d.js.map +7 -0
- package/cjs/inputs/ImageInput/index.js +41 -10
- package/cjs/inputs/ImageInput/index.js.map +2 -2
- package/cjs/inputs/Input/index.js +4 -4
- package/cjs/inputs/Input/index.js.map +2 -2
- package/cjs/inputs/Select/index.js +4 -3
- package/cjs/inputs/Select/index.js.map +2 -2
- package/cjs/inputs/inputsScenarios/index.js +2 -2
- package/cjs/inputs/inputsScenarios.js.map +2 -2
- package/cjs/lazy/index.js +2 -1
- package/cjs/lazy.js.map +2 -2
- package/cjs/registry/index.js +6 -6
- package/cjs/registry.js.map +2 -2
- package/cjs/types.js.map +1 -1
- package/cjs/utils/index.js +20 -6
- package/cjs/utils.js.map +2 -2
- package/cjs/validators/index.js +11 -6
- package/cjs/validators/index.js.map +2 -2
- package/cjs/validators/utils/amka/index.js +60 -0
- package/cjs/validators/utils/amka.js.map +7 -0
- package/cjs/validators/utils/date/index.js +26 -3
- package/cjs/validators/utils/date.js.map +2 -2
- package/cjs/validators/utils/datetime/index.js +118 -24
- package/cjs/validators/utils/datetime.js.map +2 -2
- package/cjs/validators/utils/file/index.js +30 -17
- package/cjs/validators/utils/file.js.map +2 -2
- package/cjs/validators/utils/index.js +5 -1
- package/cjs/validators/utils/index.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/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.js +2 -2
- 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.js +42 -15
- package/inputs/DateInput/index.js.map +2 -2
- package/inputs/DateTimeInput/DateTimeInput.stories.d.ts +10 -3
- package/inputs/DateTimeInput/__stories__/Default.d.ts +1 -1
- package/inputs/DateTimeInput/__stories__/WithDefaultValue.d.ts +3 -0
- package/inputs/DateTimeInput/__stories__/WithInitialValue.d.ts +3 -0
- package/inputs/DateTimeInput/__stories__/WithWrongDefaultValue.d.ts +3 -0
- package/inputs/DateTimeInput/__stories__/WithWrongInitialValue.d.ts +3 -0
- package/inputs/DateTimeInput/index.js +69 -35
- package/inputs/DateTimeInput/index.js.map +2 -2
- package/inputs/FileInput/FileInput.stories.d.ts +3 -0
- package/inputs/FileInput/__stories__/Default.d.ts +1 -1
- package/inputs/FileInput/__stories__/WithBorderAndLink.d.ts +3 -0
- package/inputs/FileInput/index.d.ts +11 -4
- package/inputs/FileInput/index.js +57 -31
- package/inputs/FileInput/index.js.map +2 -2
- package/inputs/ImageInput/ImageInput.stories.d.ts +4 -1
- package/inputs/ImageInput/__stories__/Default.d.ts +1 -1
- package/inputs/ImageInput/__stories__/MaxSize.d.ts +1 -1
- package/inputs/ImageInput/__stories__/WithInitialValues.d.ts +3 -0
- package/inputs/ImageInput/__stories__/WithInvalidImageDimension.d.ts +1 -1
- package/inputs/ImageInput/__stories__/logo.d/index.js +1 -0
- package/inputs/ImageInput/__stories__/logo.d/package.json +6 -0
- package/inputs/ImageInput/__stories__/logo.d.js.map +7 -0
- package/inputs/ImageInput/index.d.ts +9 -1
- package/inputs/ImageInput/index.js +42 -11
- package/inputs/ImageInput/index.js.map +2 -2
- package/inputs/Input/Input.stories.d.ts +4 -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 +1 -1
- package/inputs/Input/__stories__/TextWithLimit.d.ts +1 -1
- package/inputs/Input/index.d.ts +2 -1
- package/inputs/Input/index.js +4 -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/OtpInput/OtpInput.stories.d.ts +2 -0
- package/inputs/OtpInput/__stories__/Default.d.ts +1 -1
- 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/Select/Select.stories.d.ts +2 -0
- package/inputs/Select/__stories__/Default.d.ts +1 -1
- package/inputs/Select/index.d.ts +2 -1
- package/inputs/Select/index.js +4 -3
- package/inputs/Select/index.js.map +2 -2
- package/inputs/inputsScenarios/index.js +2 -2
- package/inputs/inputsScenarios.d.ts +1 -1
- package/inputs/inputsScenarios.js.map +2 -2
- package/lazy/index.js +2 -1
- package/package.json +4 -4
- package/registry/index.js +6 -6
- package/src/Field/FieldBase.tsx +6 -1
- package/src/Field/FieldBaseContainer.tsx +68 -48
- package/src/Field/FieldConditional.tsx +4 -0
- package/src/Field/index.tsx +15 -5
- package/src/Field/types.tsx +11 -3
- package/src/Field/utils/index.ts +2 -0
- package/src/Field/utils/useField.ts +9 -1
- package/src/FieldArray/FormDialog.tsx +430 -243
- package/src/FieldArray/__stories__/Default.tsx +1 -1
- package/src/FieldArray/__stories__/WithExactLength.tsx +1 -1
- package/src/FieldArray/__stories__/WithModal.tsx +4 -3
- package/src/FieldArray/index.tsx +53 -30
- package/src/FieldObject/index.tsx +33 -18
- package/src/FormBuilder/FormBuilder.stories.js +3 -0
- package/src/FormBuilder/__stories__/AutoErrorGrouping.tsx +1 -1
- package/src/FormBuilder/__stories__/Default.tsx +1 -1
- package/src/FormBuilder/__stories__/ErrorGrouping.tsx +1 -1
- package/src/FormBuilder/index.tsx +12 -7
- package/src/FormBuilder/scenarios.test.tsx +763 -5
- package/src/FormContext.tsx +5 -1
- 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 +2 -0
- package/src/MultiplicityField/index.tsx +3 -0
- package/src/MultiplicityField/types.ts +1 -0
- package/src/Questions/Questions.stories.js +3 -0
- package/src/Questions/__stories__/Default.tsx +1 -1
- package/src/inputs/AutoCompleteInput/AutoComplete.stories.js +3 -0
- package/src/inputs/AutoCompleteInput/__stories__/Default.tsx +1 -1
- package/src/inputs/AutoCompleteInput/__stories__/Multiple.tsx +1 -1
- package/src/inputs/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.tsx +2 -6
- package/src/inputs/DateInput/DateInput.stories.js +7 -0
- package/src/inputs/DateInput/__stories__/Default.tsx +1 -1
- package/src/inputs/DateInput/__stories__/WithDefaultValue.tsx +26 -0
- package/src/inputs/DateInput/__stories__/WithInitialValue.tsx +28 -0
- package/src/inputs/DateInput/__stories__/WithWrongDefaultValue.tsx +26 -0
- package/src/inputs/DateInput/__stories__/WithWrongInitialValue.tsx +28 -0
- package/src/inputs/DateInput/index.test.tsx +16 -0
- package/src/inputs/DateInput/index.tsx +46 -14
- package/src/inputs/DateTimeInput/DateTimeInput.stories.js +12 -6
- package/src/inputs/DateTimeInput/__stories__/Default.tsx +1 -1
- package/src/inputs/DateTimeInput/__stories__/WithDefaultValue.tsx +26 -0
- package/src/inputs/DateTimeInput/__stories__/WithInitialValue.tsx +28 -0
- package/src/inputs/DateTimeInput/__stories__/WithWrongDefaultValue.tsx +26 -0
- package/src/inputs/DateTimeInput/__stories__/WithWrongInitialValue.tsx +28 -0
- package/src/inputs/DateTimeInput/index.test.tsx +16 -0
- package/src/inputs/DateTimeInput/index.tsx +73 -34
- package/src/inputs/FileInput/FileInput.stories.js +4 -0
- package/src/inputs/FileInput/__stories__/Default.tsx +1 -1
- package/src/inputs/FileInput/__stories__/WithBorderAndLink.tsx +34 -0
- package/src/inputs/FileInput/index.test.tsx +4 -0
- package/src/inputs/FileInput/index.tsx +90 -48
- package/src/inputs/ImageInput/ImageInput.stories.js +5 -1
- package/src/inputs/ImageInput/__stories__/Default.tsx +1 -1
- package/src/inputs/ImageInput/__stories__/MaxSize.tsx +3 -2
- package/src/inputs/ImageInput/__stories__/WithInitialValues.tsx +45 -0
- package/src/inputs/ImageInput/__stories__/WithInvalidImageDimension.tsx +1 -1
- package/src/inputs/ImageInput/__stories__/logo.d.ts +4 -0
- package/src/inputs/ImageInput/__stories__/logo.png +0 -0
- package/src/inputs/ImageInput/index.test.tsx +21 -17
- package/src/inputs/ImageInput/index.tsx +100 -48
- package/src/inputs/Input/Input.stories.js +5 -0
- package/src/inputs/Input/__stories__/AFM.tsx +1 -1
- package/src/inputs/Input/__stories__/AMKA.tsx +23 -0
- package/src/inputs/Input/__stories__/Boolean.tsx +1 -1
- package/src/inputs/Input/__stories__/Email.tsx +23 -0
- package/src/inputs/Input/__stories__/IBAN.tsx +1 -1
- package/src/inputs/Input/__stories__/Integer.tsx +1 -1
- package/src/inputs/Input/__stories__/LandlineNumber.tsx +1 -1
- package/src/inputs/Input/__stories__/MobilePhone.tsx +1 -1
- package/src/inputs/Input/__stories__/PhoneNumber.tsx +1 -1
- package/src/inputs/Input/__stories__/PostalCode.tsx +1 -1
- package/src/inputs/Input/__stories__/String.tsx +1 -1
- package/src/inputs/Input/__stories__/StringWithTrimValidation.tsx +1 -1
- package/src/inputs/Input/__stories__/TextWithLimit.tsx +1 -1
- package/src/inputs/Input/index.test.tsx +8 -0
- package/src/inputs/Input/index.tsx +5 -3
- package/src/inputs/Label/Label.stories.js +3 -0
- package/src/inputs/Label/__stories__/Default.tsx +1 -1
- package/src/inputs/OtpInput/OtpInput.stories.js +3 -0
- package/src/inputs/OtpInput/__stories__/Default.tsx +1 -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/Select/Select.stories.js +3 -0
- package/src/inputs/Select/__stories__/Default.tsx +1 -1
- package/src/inputs/Select/index.tsx +7 -4
- package/src/inputs/inputsScenarios.ts +2 -2
- package/src/lazy.js +2 -1
- package/src/registry.js +6 -6
- package/src/types.tsx +2 -1
- package/src/utils.ts +27 -6
- package/src/validators/index.ts +17 -6
- package/src/validators/utils/amka.ts +39 -0
- package/src/validators/utils/date.ts +28 -4
- package/src/validators/utils/datetime.ts +121 -29
- package/src/validators/utils/file.ts +33 -19
- package/src/validators/utils/index.ts +4 -1
- package/types.d.ts +2 -1
- package/types.js.map +1 -1
- package/utils/index.js +20 -6
- package/utils.d.ts +2 -0
- package/utils.js.map +2 -2
- package/validators/index.d.ts +1 -1
- package/validators/index.js +12 -6
- package/validators/index.js.map +2 -2
- package/validators/utils/amka/index.js +36 -0
- package/{inputs/Input/inputsInputScenarios → 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 +26 -3
- package/validators/utils/date.d.ts +1 -1
- package/validators/utils/date.js.map +2 -2
- package/validators/utils/datetime/index.js +118 -24
- package/validators/utils/datetime.d.ts +1 -1
- package/validators/utils/datetime.js.map +2 -2
- package/validators/utils/file/index.js +30 -17
- package/validators/utils/file.js.map +2 -2
- package/validators/utils/index.d.ts +1 -0
- package/validators/utils/index.js +4 -1
- package/validators/utils/index.js.map +2 -2
- package/cjs/inputs/Input/inputsInputScenarios/index.js +0 -439
- package/cjs/inputs/Input/inputsInputScenarios.js.map +0 -7
- package/inputs/Input/inputsInputScenarios/index.js +0 -406
- package/inputs/Input/inputsInputScenarios.d.ts +0 -57
- package/inputs/Input/inputsInputScenarios.js.map +0 -7
- package/src/inputs/Input/inputsInputScenarios.ts +0 -404
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/validators/utils/date.ts"],
|
|
4
|
-
"sourcesContent": ["import dayjs from 'dayjs';\nimport customParseFormat from 'dayjs/plugin/customParseFormat';\nimport { FieldSpec } from '@digigov/form/types';\nimport { ValidatorSchema } from '@digigov/form/validators/types';\n\ndayjs.extend(customParseFormat);\n\nconst VALID_DATE_FORMATS = ['DD/MM/YYYY'];\nconst DATE_CACHE = {};\n\nconst getDate = (v: string) => {\n return DATE_CACHE[v] ? DATE_CACHE[v] : dayjs(v, VALID_DATE_FORMATS, true);\n};\n\n// Function to check partial date completion\nconst checkPartialDate = (value: string) => {\n
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkB;AAClB,+BAA8B;AAI9B,aAAAA,QAAM,OAAO,yBAAAC,OAAiB;AAE9B,MAAM,qBAAqB,CAAC,YAAY;AACxC,MAAM,aAAa,CAAC;
|
|
4
|
+
"sourcesContent": ["import dayjs from 'dayjs';\nimport customParseFormat from 'dayjs/plugin/customParseFormat';\nimport { FieldSpec } from '@digigov/form/types';\nimport { ValidatorSchema } from '@digigov/form/validators/types';\n\ndayjs.extend(customParseFormat);\n\nconst VALID_DATE_FORMATS = ['DD/MM/YYYY'];\nconst DATE_CACHE = {};\nconst onlyNumbersRegex = /^\\d+$/;\n\nconst getDate = (v: string) => {\n return DATE_CACHE[v] ? DATE_CACHE[v] : dayjs(v, VALID_DATE_FORMATS, true);\n};\n\nconst getDaysInMonth = (month: number, year: number): number => {\n return dayjs(`${year}-${month}-01`).daysInMonth(); // e.g. 29 for Feb 2024\n};\n\n// Function to check partial date completion\nconst checkPartialDate = (value: string) => {\n const [day, month, year] = value.split('/');\n if (day && !month && !year) {\n return 'form.error.date.invalid_month_year';\n }\n if (!day && month && !year) {\n return 'form.error.date.invalid_day_year';\n }\n if (!day && !month && year) {\n return 'form.error.date.invalid_day_month';\n }\n if (day && month && !year) {\n return 'form.error.date.invalid_year';\n }\n if (day && !month && year) {\n return 'form.error.date.invalid_month';\n }\n if (!day && month && year) {\n return 'form.error.date.invalid_day';\n }\n if (day && month) {\n const dayNum = parseInt(day);\n const monthNum = parseInt(month);\n const validYear = onlyNumbersRegex.test(year) ? year : undefined;\n if (!validYear || year.length < 4) {\n return 'form.error.date.invalid';\n }\n const yearNum = parseInt(validYear);\n const maxDay = getDaysInMonth(monthNum, yearNum);\n if (dayNum < 1 || dayNum > maxDay) {\n return {\n key: 'form.error.date.invalid_day_range',\n context: {\n maxDay: maxDay,\n },\n };\n }\n if (monthNum < 1 || monthNum > 12) {\n return 'form.error.datetime.invalid_month_range';\n }\n }\n return 'form.error.date.invalid';\n};\n\nexport const LATER_THAN_VALIDATOR = (field: FieldSpec): ValidatorSchema => {\n let minDate;\n const params = field.extra || {};\n if (params.min === 'now') {\n const today = new Date();\n minDate = new Date(today);\n } else {\n minDate = getDate(params.min).toDate();\n }\n const minPreviousDate = new Date(minDate);\n minPreviousDate.setDate(minDate.getDate() - 1);\n return {\n name: 'later-than',\n message: {\n key: 'form.error.date.later_than',\n context: {\n minDate: minPreviousDate.toLocaleDateString(),\n },\n },\n test: function (value: string) {\n if (!value) return true;\n const date = getDate(value);\n const isValid = +date.toDate() > +minDate;\n return isValid;\n },\n };\n};\n\nexport const EARLIER_THAN_VALIDATOR = (field: FieldSpec): ValidatorSchema => {\n let maxDate;\n const params = field.extra || {};\n if (params.max === 'now') {\n const today = new Date();\n maxDate = new Date(today);\n } else {\n maxDate = getDate(params.max).toDate();\n }\n const maxNextDate = new Date(maxDate);\n maxNextDate.setDate(maxDate.getDate() + 1);\n return {\n name: 'earlier-than',\n message: {\n key: 'form.error.date.earlier_than',\n context: {\n maxDate: maxNextDate.toLocaleDateString(),\n },\n },\n test: function (value: string) {\n if (!value) return true;\n const date = getDate(value);\n const isValid = +date.toDate() < +maxDate;\n return isValid;\n },\n };\n};\n\nexport const DATE_VALIDATOR = {\n name: 'date-validator',\n message: (v): string | object => {\n return checkPartialDate(v.value);\n },\n test: function (value: string) {\n if (!value) return true;\n const date = getDate(value);\n return date.isValid();\n },\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;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F;AAAA,IACA,MAAM,SAAU,OAAe;AAC7B,UAAI,CAAC,MAAO,QAAO;AACnB,YAAM,OAAO,QAAQ,KAAK;AAC1B,YAAM,UAAU,CAAC,KAAK,OAAO,IAAI,CAAC;AAClC,aAAO;AAAA,IACT;AAAA,EACF;AACF;AAEO,MAAM,iBAAiB;AAAA,EAC5B,MAAM;AAAA,EACN,SAAS,CAAC,MAAuB;AAC/B,WAAO,iBAAiB,EAAE,KAAK;AAAA,EACjC;AAAA,EACA,MAAM,SAAU,OAAe;AAC7B,QAAI,CAAC,MAAO,QAAO;AACnB,UAAM,OAAO,QAAQ,KAAK;AAC1B,WAAO,KAAK,QAAQ;AAAA,EACtB;AACF;",
|
|
6
6
|
"names": ["dayjs", "customParseFormat"]
|
|
7
7
|
}
|
|
@@ -37,50 +37,144 @@ var import_customParseFormat = __toESM(require("dayjs/plugin/customParseFormat")
|
|
|
37
37
|
import_dayjs.default.extend(import_customParseFormat.default);
|
|
38
38
|
const VALID_DATETIME_FORMATS = ["DD/MM/YYYY HH:mm"];
|
|
39
39
|
const DATETIME_CACHE = {};
|
|
40
|
+
const onlyNumbersRegex = /^\d+$/;
|
|
40
41
|
const getDateTime = (v) => {
|
|
41
42
|
return DATETIME_CACHE[v] ? DATETIME_CACHE[v] : (0, import_dayjs.default)(v, VALID_DATETIME_FORMATS, true);
|
|
42
43
|
};
|
|
44
|
+
const getDaysInMonth = (month, year) => {
|
|
45
|
+
return (0, import_dayjs.default)(`${year}-${month}-01`).daysInMonth();
|
|
46
|
+
};
|
|
43
47
|
const checkPartialDateTime = (value) => {
|
|
44
48
|
const [datePart, timePart] = value.split(" ");
|
|
45
|
-
const [day, month, year] = datePart
|
|
46
|
-
const [hours, minutes] = timePart
|
|
47
|
-
|
|
49
|
+
const [day, month, year] = datePart?.split("/") ?? [];
|
|
50
|
+
const [hours, minutes] = timePart?.split(":") ?? [];
|
|
51
|
+
const hasDay = Boolean(day);
|
|
52
|
+
const hasMonth = Boolean(month);
|
|
53
|
+
const hasYear = Boolean(year);
|
|
54
|
+
const hasHours = Boolean(hours);
|
|
55
|
+
const hasMinutes = Boolean(minutes);
|
|
56
|
+
if (hasDay && !hasMonth && !hasYear && !hasHours && !hasMinutes) {
|
|
57
|
+
return "form.error.datetime.invalid_month_year_hours_minutes";
|
|
58
|
+
}
|
|
59
|
+
if (!hasDay && hasMonth && !hasYear && !hasHours && !hasMinutes) {
|
|
60
|
+
return "form.error.datetime.invalid_day_year_hours_minutes";
|
|
61
|
+
}
|
|
62
|
+
if (!hasDay && !hasMonth && hasYear && !hasHours && !hasMinutes) {
|
|
63
|
+
return "form.error.datetime.invalid_day_month_hours_minutes";
|
|
64
|
+
}
|
|
65
|
+
if (hasDay && hasMonth && !hasYear && !hasHours && !hasMinutes) {
|
|
66
|
+
return "form.error.datetime.invalid_year_hours_minutes";
|
|
67
|
+
}
|
|
68
|
+
if (hasDay && !hasMonth && hasYear && !hasHours && !hasMinutes) {
|
|
69
|
+
return "form.error.datetime.invalid_month_hours_minutes";
|
|
70
|
+
}
|
|
71
|
+
if (!hasDay && hasMonth && hasYear && !hasHours && !hasMinutes) {
|
|
72
|
+
return "form.error.datetime.invalid_day_hours_minutes";
|
|
73
|
+
}
|
|
74
|
+
if (hasDay && hasMonth && hasYear && !hasHours && !hasMinutes) {
|
|
75
|
+
return "form.error.datetime.invalid__hours_minutes";
|
|
76
|
+
}
|
|
77
|
+
if (hasDay && hasMonth && hasYear && hasHours && !hasMinutes) {
|
|
78
|
+
return "form.error.datetime.invalid_minutes";
|
|
79
|
+
}
|
|
80
|
+
if (hasDay && hasMonth && hasYear && !hasHours && hasMinutes) {
|
|
81
|
+
return "form.error.datetime.invalid_hours";
|
|
82
|
+
}
|
|
83
|
+
if (hasDay && !hasMonth && !hasYear && hasHours && !hasMinutes) {
|
|
84
|
+
return "form.error.datetime.invalid_month_year_minutes";
|
|
85
|
+
}
|
|
86
|
+
if (hasDay && !hasMonth && !hasYear && !hasHours && hasMinutes) {
|
|
87
|
+
return "form.error.datetime.invalid_month_year_hours";
|
|
88
|
+
}
|
|
89
|
+
if (hasDay && !hasMonth && !hasYear && hasHours && hasMinutes) {
|
|
48
90
|
return "form.error.datetime.invalid_month_year";
|
|
49
91
|
}
|
|
50
|
-
if (!
|
|
92
|
+
if (!hasDay && hasMonth && !hasYear && hasHours && !hasMinutes) {
|
|
93
|
+
return "form.error.datetime.invalid_day_year_minutes";
|
|
94
|
+
}
|
|
95
|
+
if (!hasDay && hasMonth && !hasYear && !hasHours && hasMinutes) {
|
|
96
|
+
return "form.error.datetime.invalid_day_year_hours";
|
|
97
|
+
}
|
|
98
|
+
if (!hasDay && hasMonth && !hasYear && hasHours && hasMinutes) {
|
|
51
99
|
return "form.error.datetime.invalid_day_year";
|
|
52
100
|
}
|
|
53
|
-
if (!
|
|
101
|
+
if (!hasDay && !hasMonth && hasYear && hasHours && !hasMinutes) {
|
|
102
|
+
return "form.error.datetime.invalid_day_month_minutes";
|
|
103
|
+
}
|
|
104
|
+
if (!hasDay && !hasMonth && hasYear && !hasHours && hasMinutes) {
|
|
105
|
+
return "form.error.datetime.invalid_day_month_hours";
|
|
106
|
+
}
|
|
107
|
+
if (!hasDay && !hasMonth && hasYear && hasHours && hasMinutes) {
|
|
54
108
|
return "form.error.datetime.invalid_day_month";
|
|
55
109
|
}
|
|
56
|
-
if (
|
|
110
|
+
if (!hasDay && !hasMonth && !hasYear && hasHours && hasMinutes) {
|
|
111
|
+
return "form.error.datetime.invalid_day_month_year";
|
|
112
|
+
}
|
|
113
|
+
if (!hasDay && !hasMonth && !hasYear && !hasHours && hasMinutes) {
|
|
114
|
+
return "form.error.datetime.invalid_day_month_year_hours";
|
|
115
|
+
}
|
|
116
|
+
if (hasDay && hasMonth && !hasYear && hasHours && !hasMinutes) {
|
|
117
|
+
return "form.error.datetime.invalid_year_minutes";
|
|
118
|
+
}
|
|
119
|
+
if (hasDay && hasMonth && !hasYear && !hasHours && hasMinutes) {
|
|
120
|
+
return "form.error.datetime.invalid_year_hours";
|
|
121
|
+
}
|
|
122
|
+
if (hasDay && hasMonth && !hasYear && hasHours && hasMinutes) {
|
|
57
123
|
return "form.error.datetime.invalid_year";
|
|
58
124
|
}
|
|
59
|
-
if (
|
|
125
|
+
if (hasDay && !hasMonth && hasYear && hasHours && !hasMinutes) {
|
|
126
|
+
return "form.error.datetime.invalid_month_minutes";
|
|
127
|
+
}
|
|
128
|
+
if (hasDay && !hasMonth && hasYear && !hasHours && hasMinutes) {
|
|
129
|
+
return "form.error.datetime.invalid_month_hours";
|
|
130
|
+
}
|
|
131
|
+
if (hasDay && !hasMonth && hasYear && hasHours && hasMinutes) {
|
|
60
132
|
return "form.error.datetime.invalid_month";
|
|
61
133
|
}
|
|
62
|
-
if (!
|
|
134
|
+
if (!hasDay && hasMonth && hasYear && hasHours && !hasMinutes) {
|
|
135
|
+
return "form.error.datetime.invalid_day_minutes";
|
|
136
|
+
}
|
|
137
|
+
if (!hasDay && hasMonth && hasYear && !hasHours && hasMinutes) {
|
|
138
|
+
return "form.error.datetime.invalid_day_hours";
|
|
139
|
+
}
|
|
140
|
+
if (!hasDay && hasMonth && hasYear && hasHours && hasMinutes) {
|
|
63
141
|
return "form.error.datetime.invalid_day";
|
|
64
142
|
}
|
|
65
|
-
if (
|
|
66
|
-
|
|
67
|
-
|
|
143
|
+
if (!hasDay && !hasMonth && !hasYear && hasHours && !hasMinutes) {
|
|
144
|
+
return "form.error.datetime.invalid_day_month_year_minutes";
|
|
145
|
+
}
|
|
146
|
+
if (hasDay && hasMonth && hasYear && !hasHours && !hasMinutes) {
|
|
147
|
+
return "form.error.datetime.invalid_hours_minutes";
|
|
148
|
+
}
|
|
149
|
+
if (day && month) {
|
|
150
|
+
const dayNum = parseInt(day);
|
|
151
|
+
const monthNum = parseInt(month);
|
|
152
|
+
const validYear = onlyNumbersRegex.test(year) ? year : void 0;
|
|
153
|
+
if (!validYear || year.length < 4) {
|
|
154
|
+
return "form.error.datetime.invalid";
|
|
68
155
|
}
|
|
69
|
-
|
|
70
|
-
|
|
156
|
+
const yearNum = parseInt(validYear);
|
|
157
|
+
const maxDay = getDaysInMonth(monthNum, yearNum);
|
|
158
|
+
if (dayNum < 1 || dayNum > maxDay) {
|
|
159
|
+
return {
|
|
160
|
+
key: "form.error.datetime.invalid_day_range",
|
|
161
|
+
context: {
|
|
162
|
+
maxDay
|
|
163
|
+
}
|
|
164
|
+
};
|
|
71
165
|
}
|
|
72
|
-
if (
|
|
73
|
-
return "form.error.datetime.
|
|
166
|
+
if (monthNum < 1 || monthNum > 12) {
|
|
167
|
+
return "form.error.datetime.invalid_month_range";
|
|
74
168
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
169
|
+
}
|
|
170
|
+
if (hours && minutes) {
|
|
171
|
+
const hoursNum = parseInt(hours);
|
|
172
|
+
const minutesNum = parseInt(minutes);
|
|
173
|
+
if (hoursNum < 0 || hoursNum > 23) {
|
|
174
|
+
return "form.error.datetime.invalid_hours_range";
|
|
175
|
+
}
|
|
176
|
+
if (minutesNum < 0 || minutesNum > 59) {
|
|
177
|
+
return "form.error.datetime.invalid_minutes_range";
|
|
84
178
|
}
|
|
85
179
|
}
|
|
86
180
|
return "form.error.datetime.invalid";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/validators/utils/datetime.ts"],
|
|
4
|
-
"sourcesContent": ["import dayjs from 'dayjs';\nimport customParseFormat from 'dayjs/plugin/customParseFormat';\nimport { FieldSpec } from '@digigov/form/types';\nimport { ValidatorSchema } from '@digigov/form/validators/types';\n\ndayjs.extend(customParseFormat);\n\nconst VALID_DATETIME_FORMATS = ['DD/MM/YYYY HH:mm'];\nconst DATETIME_CACHE = {};\n\nconst getDateTime = (v: string) => {\n return DATETIME_CACHE[v]\n ? DATETIME_CACHE[v]\n : dayjs(v, VALID_DATETIME_FORMATS, true);\n};\n\n//
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkB;AAClB,+BAA8B;AAI9B,aAAAA,QAAM,OAAO,yBAAAC,OAAiB;AAE9B,MAAM,yBAAyB,CAAC,kBAAkB;AAClD,MAAM,iBAAiB,CAAC;
|
|
4
|
+
"sourcesContent": ["import dayjs from 'dayjs';\nimport customParseFormat from 'dayjs/plugin/customParseFormat';\nimport { 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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAkB;AAClB,+BAA8B;AAI9B,aAAAA,QAAM,OAAO,yBAAAC,OAAiB;AAE9B,MAAM,yBAAyB,CAAC,kBAAkB;AAClD,MAAM,iBAAiB,CAAC;AACxB,MAAM,mBAAmB;AAEzB,MAAM,cAAc,CAAC,MAAc;AACjC,SAAO,eAAe,CAAC,IAC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ACnB,UAAM,WAAW,YAAY,KAAK;AAClC,WAAO,SAAS,QAAQ;AAAA,EAC1B;AACF;",
|
|
6
6
|
"names": ["dayjs", "customParseFormat"]
|
|
7
7
|
}
|
|
@@ -21,26 +21,39 @@ __export(file_exports, {
|
|
|
21
21
|
});
|
|
22
22
|
module.exports = __toCommonJS(file_exports);
|
|
23
23
|
const DEFAULT_FILE_MAX_SIZE = 1e7;
|
|
24
|
-
const FILE_MAX_SIZE_VALIDATOR = (field) =>
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
24
|
+
const FILE_MAX_SIZE_VALIDATOR = (field) => {
|
|
25
|
+
const maxSizeInBytes = field?.extra?.limit?.maxSize || DEFAULT_FILE_MAX_SIZE;
|
|
26
|
+
let maxSizeTransformed = maxSizeInBytes / (1024 * 1024);
|
|
27
|
+
let maxSizeText = "MB";
|
|
28
|
+
if (Math.round(maxSizeTransformed) === 0) {
|
|
29
|
+
maxSizeTransformed = Math.round(maxSizeInBytes / 1024);
|
|
30
|
+
maxSizeText = "KB";
|
|
31
|
+
}
|
|
32
|
+
if (Math.round(maxSizeTransformed) === 0) {
|
|
33
|
+
maxSizeTransformed = maxSizeInBytes;
|
|
34
|
+
maxSizeText = "Bytes";
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
name: "file-max-size-validator",
|
|
38
|
+
message: {
|
|
39
|
+
key: field.type === "file" ? "form.error.file_size" : "form.error.image_size",
|
|
40
|
+
context: {
|
|
41
|
+
maxSize: `${maxSizeTransformed} ${maxSizeText}`
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
test: (value) => {
|
|
45
|
+
if (value) {
|
|
46
|
+
for (const file of Array.from(value)) {
|
|
47
|
+
const maxSize = field?.extra?.limit?.maxSize || DEFAULT_FILE_MAX_SIZE;
|
|
48
|
+
if (file.size > maxSize) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
38
51
|
}
|
|
39
52
|
}
|
|
53
|
+
return true;
|
|
40
54
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
});
|
|
55
|
+
};
|
|
56
|
+
};
|
|
44
57
|
// Annotate the CommonJS export names for ESM import in node:
|
|
45
58
|
0 && (module.exports = {
|
|
46
59
|
FILE_MAX_SIZE_VALIDATOR
|
|
@@ -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": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;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": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;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
|
}
|
|
@@ -35,6 +35,7 @@ __export(utils_exports, {
|
|
|
35
35
|
module.exports = __toCommonJS(utils_exports);
|
|
36
36
|
var yup = __toESM(require("yup"));
|
|
37
37
|
__reExport(utils_exports, require("@digigov/form/validators/utils/afm"), module.exports);
|
|
38
|
+
__reExport(utils_exports, require("@digigov/form/validators/utils/amka"), module.exports);
|
|
38
39
|
__reExport(utils_exports, require("@digigov/form/validators/utils/file"), module.exports);
|
|
39
40
|
__reExport(utils_exports, require("@digigov/form/validators/utils/iban"), module.exports);
|
|
40
41
|
__reExport(utils_exports, require("@digigov/form/validators/utils/otp"), module.exports);
|
|
@@ -117,7 +118,9 @@ function getYupObjectShape(fields, yupTypeMap, validatorRegistry) {
|
|
|
117
118
|
}
|
|
118
119
|
return yup.lazy(function() {
|
|
119
120
|
const fieldSchemas = computeShape(
|
|
120
|
-
Object.values(fields.current)
|
|
121
|
+
Object.values(fields.current).filter(
|
|
122
|
+
(f) => !f.key.includes(".")
|
|
123
|
+
),
|
|
121
124
|
yupTypeMap,
|
|
122
125
|
validatorRegistry
|
|
123
126
|
);
|
|
@@ -130,6 +133,7 @@ function getYupObjectShape(fields, yupTypeMap, validatorRegistry) {
|
|
|
130
133
|
getYupField,
|
|
131
134
|
getYupObjectShape,
|
|
132
135
|
...require("@digigov/form/validators/utils/afm"),
|
|
136
|
+
...require("@digigov/form/validators/utils/amka"),
|
|
133
137
|
...require("@digigov/form/validators/utils/file"),
|
|
134
138
|
...require("@digigov/form/validators/utils/iban"),
|
|
135
139
|
...require("@digigov/form/validators/utils/otp"),
|
|
@@ -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';\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),\n yupTypeMap,\n validatorRegistry\n );\n return yup.object().shape(fieldSchemas);\n });\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,UAAqB;AAIrB,0BAAc,+CAJd;AAKA,0BAAc,gDALd;AAMA,0BAAc,gDANd;AAOA,0BAAc
|
|
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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,UAAqB;AAIrB,0BAAc,+CAJd;AAKA,0BAAc,gDALd;AAMA,0BAAc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
|
18
18
|
if (!value) value = [];
|
|
19
19
|
const handleChange = (optionValue, idx, show) => (evt) => {
|
|
20
|
-
let newValue;
|
|
20
|
+
let newValue = [];
|
|
21
21
|
if (evt.currentTarget.checked) {
|
|
22
22
|
newValue = value.concat([optionValue]);
|
|
23
23
|
} else {
|
|
@@ -58,9 +58,9 @@ const Checkboxes = ({
|
|
|
58
58
|
...props,
|
|
59
59
|
reset: void 0,
|
|
60
60
|
defaultValue: void 0,
|
|
61
|
+
error: void 0,
|
|
61
62
|
onBlur: void 0,
|
|
62
63
|
required: void 0,
|
|
63
|
-
Field: void 0,
|
|
64
64
|
"aria-describedby": void 0,
|
|
65
65
|
type: "checkbox"
|
|
66
66
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/inputs/Checkboxes/index.tsx"],
|
|
4
|
-
"sourcesContent": ["import React, { useState } from 'react';\nimport { ControlledFieldProps } from '@digigov/form/Field/types';\nimport { FieldOptionProps } from '@digigov/form/inputs/Label';\nimport {\n Checkbox,\n CheckboxItem,\n CheckboxConditional,\n} from '@digigov/ui/form/Checkbox';\nimport { useTranslation } from '@digigov/ui/i18n';\nimport { Hint } from '@digigov/ui/typography/Hint';\n\nexport interface CheckboxesProps\n extends Omit<ControlledFieldProps, 'extra' | 'value'> {\n value?: string[];\n extra: {\n className?: string;\n options: FieldOptionProps[];\n };\n fieldComponent: React.FC<Omit<ControlledFieldProps, 'value' | 'onChange'>>;\n}\n\nexport const Checkboxes: React.FC<CheckboxesProps> = ({\n name,\n onChange,\n value,\n extra: { options, className },\n disabled,\n Field,\n ...props\n}) => {\n if (!value) value = [];\n const handleChange =\n (optionValue, idx, show) =>\n (evt): void => {\n let newValue;\n if (evt.currentTarget.checked) {\n
|
|
5
|
-
"mappings": "AAAA,OAAO,SAAS,gBAAgB;AAGhC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,sBAAsB;AAC/B,SAAS,YAAY;AAYd,MAAM,aAAwC,CAAC;AAAA,EACpD;AAAA,EACA;AAAA,EACA;AAAA,EACA,OAAO,EAAE,SAAS,UAAU;AAAA,EAC5B;AAAA,EACA;AAAA,EACA,GAAG;AACL,MAAM;AACJ,MAAI,CAAC,MAAO,SAAQ,CAAC;AACrB,QAAM,eACJ,CAAC,aAAa,KAAK,SACnB,CAAC,QAAc;AACb,QAAI;
|
|
4
|
+
"sourcesContent": ["import React, { useState } from 'react';\nimport { ControlledFieldProps } from '@digigov/form/Field/types';\nimport { FieldOptionProps } from '@digigov/form/inputs/Label';\nimport {\n Checkbox,\n CheckboxItem,\n CheckboxConditional,\n} from '@digigov/ui/form/Checkbox';\nimport { useTranslation } from '@digigov/ui/i18n';\nimport { Hint } from '@digigov/ui/typography/Hint';\n\nexport interface CheckboxesProps\n extends Omit<ControlledFieldProps, 'extra' | 'value'> {\n value?: string[];\n extra: {\n className?: string;\n options: FieldOptionProps[];\n };\n fieldComponent: React.FC<Omit<ControlledFieldProps, 'value' | 'onChange'>>;\n}\n\nexport const Checkboxes: React.FC<CheckboxesProps> = ({\n name,\n onChange,\n value,\n extra: { options, className },\n disabled,\n Field,\n ...props\n}) => {\n if (!value) value = [];\n const handleChange =\n (optionValue, idx, show) =>\n (evt): void => {\n let newValue: any = [];\n if (evt.currentTarget.checked) {\n newValue = value.concat([optionValue]);\n } else {\n newValue = value.filter((val) => val !== optionValue);\n }\n if (show && show.length > 0) {\n setChecked((items) =>\n items.map((item, index) => (index === idx ? !item : item))\n );\n }\n\n // reset value to undefined instead of an empty array\n // so the error state mechanism can throw validation errors\n if (newValue.length === 0) newValue = undefined;\n onChange(newValue);\n };\n const { t } = useTranslation();\n const [checked, setChecked] = useState(\n Array<boolean>(options.length).fill(false)\n );\n return (\n <Checkbox className={className}>\n {options.map(\n (\n {\n label,\n value: v,\n show,\n disabled: optionDisabled,\n selected,\n ...option\n },\n index\n ) => (\n <React.Fragment key={index}>\n <CheckboxItem\n key={`${name}.${index}`}\n name={`${name}.${v}`}\n id={`${name}.${v}`}\n value={v}\n disabled={disabled || optionDisabled}\n checked={value?.includes(v)}\n onChange={handleChange(v, index, show)}\n {...option}\n {...{\n ...props,\n reset: undefined,\n defaultValue: undefined,\n error: undefined,\n onBlur: undefined,\n required: undefined,\n 'aria-describedby': undefined,\n type: 'checkbox',\n }}\n >\n {(label && label.primary && t(label.primary)) || value}\n {label && label.secondary && <Hint>{t(label.secondary)}</Hint>}\n </CheckboxItem>\n\n {!!checked[index] && show && Field && (\n <CheckboxConditional>\n {show.map((fieldName) => (\n <Field name={fieldName} key={fieldName} />\n ))}\n </CheckboxConditional>\n )}\n {selected && selected()}\n </React.Fragment>\n )\n )}\n </Checkbox>\n );\n};\n\nexport default Checkboxes;\n"],
|
|
5
|
+
"mappings": "AAAA,OAAO,SAAS,gBAAgB;AAGhC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,sBAAsB;AAC/B,SAAS,YAAY;AAYd,MAAM,aAAwC,CAAC;AAAA,EACpD;AAAA,EACA;AAAA,EACA;AAAA,EACA,OAAO,EAAE,SAAS,UAAU;AAAA,EAC5B;AAAA,EACA;AAAA,EACA,GAAG;AACL,MAAM;AACJ,MAAI,CAAC,MAAO,SAAQ,CAAC;AACrB,QAAM,eACJ,CAAC,aAAa,KAAK,SACnB,CAAC,QAAc;AACb,QAAI,WAAgB,CAAC;AACrB,QAAI,IAAI,cAAc,SAAS;AAC7B,iBAAW,MAAM,OAAO,CAAC,WAAW,CAAC;AAAA,IACvC,OAAO;AACL,iBAAW,MAAM,OAAO,CAAC,QAAQ,QAAQ,WAAW;AAAA,IACtD;AACA,QAAI,QAAQ,KAAK,SAAS,GAAG;AAC3B;AAAA,QAAW,CAAC,UACV,MAAM,IAAI,CAAC,MAAM,UAAW,UAAU,MAAM,CAAC,OAAO,IAAK;AAAA,MAC3D;AAAA,IACF;AAIA,QAAI,SAAS,WAAW,EAAG,YAAW;AACt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
|
|
2
2
|
export let title: string;
|
|
3
3
|
export { DateInput as component };
|
|
4
|
+
export let tags: string[];
|
|
5
|
+
export { doc as markdown };
|
|
4
6
|
export let displayName: string;
|
|
5
7
|
}
|
|
6
8
|
export default _default;
|
|
7
9
|
export { Default } from "@digigov/form/inputs/DateInput/__stories__/Default";
|
|
10
|
+
export { WithDefaultValue } from "@digigov/form/inputs/DateInput/__stories__/WithDefaultValue";
|
|
11
|
+
export { WithWrongDefaultValue } from "@digigov/form/inputs/DateInput/__stories__/WithWrongDefaultValue";
|
|
12
|
+
export { WithInitialValue } from "@digigov/form/inputs/DateInput/__stories__/WithInitialValue";
|
|
13
|
+
export { WithWrongInitialValue } from "@digigov/form/inputs/DateInput/__stories__/WithWrongInitialValue";
|
|
8
14
|
import DateInput from '@digigov/form/inputs/DateInput';
|