@digigov/form 2.0.0-555d1027 → 2.0.0-5701c39b
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Field/ErrorGroup.d.ts +3 -3
- package/Field/ErrorGroup.js.map +1 -1
- package/Field/FieldBase/index.js +2 -1
- package/Field/FieldBase.d.ts +1 -1
- package/Field/FieldBase.js.map +2 -2
- package/Field/FieldBaseContainer/index.js +36 -34
- package/Field/FieldBaseContainer.d.ts +2 -2
- package/Field/FieldBaseContainer.js.map +2 -2
- package/Field/FieldConditional.d.ts +1 -1
- package/Field/FieldConditional.js.map +1 -1
- package/Field/index.d.ts +1 -1
- package/Field/index.js +16 -26
- package/Field/index.js.map +2 -2
- package/Field/types.d.ts +11 -10
- package/Field/utils/evaluateFieldWithConditions.d.ts +2 -2
- package/Field/utils/evaluateFieldWithConditions.js.map +2 -2
- package/Field/utils/resolveField/index.js +35 -0
- package/Field/utils/{calculateField → resolveField}/package.json +1 -1
- package/Field/utils/resolveField.d.ts +3 -0
- package/Field/utils/resolveField.js.map +7 -0
- package/Field/utils/useField/index.js +4 -2
- package/Field/utils/useField.d.ts +1 -1
- package/Field/utils/useField.js.map +2 -2
- package/FieldArray/BaseFieldArray/index.js +76 -0
- package/{inputs/inputsScenarios → FieldArray/BaseFieldArray}/package.json +1 -1
- package/FieldArray/BaseFieldArray.d.ts +5 -0
- package/FieldArray/BaseFieldArray.js.map +7 -0
- package/FieldArray/FieldArray.stories.d.ts +1 -0
- package/FieldArray/FormDialog/ArrayDisplay/ArrayContainerDisplay/index.js +23 -0
- package/FieldArray/FormDialog/ArrayDisplay/ArrayContainerDisplay/package.json +6 -0
- package/FieldArray/FormDialog/ArrayDisplay/ArrayContainerDisplay.d.ts +9 -0
- package/FieldArray/FormDialog/ArrayDisplay/ArrayContainerDisplay.js.map +7 -0
- package/FieldArray/FormDialog/ArrayDisplay/ArrayDisplay.stories.d.ts +13 -0
- package/FieldArray/FormDialog/ArrayDisplay/ArrayItemDisplay/index.js +184 -0
- package/FieldArray/FormDialog/ArrayDisplay/ArrayItemDisplay/package.json +6 -0
- package/FieldArray/FormDialog/ArrayDisplay/ArrayItemDisplay.d.ts +26 -0
- package/FieldArray/FormDialog/ArrayDisplay/ArrayItemDisplay.js.map +7 -0
- package/FieldArray/FormDialog/ArrayDisplay/ArrayItemHeader/index.js +11 -0
- package/FieldArray/FormDialog/ArrayDisplay/ArrayItemHeader/package.json +6 -0
- package/FieldArray/FormDialog/ArrayDisplay/ArrayItemHeader.d.ts +5 -0
- package/FieldArray/FormDialog/ArrayDisplay/ArrayItemHeader.js.map +7 -0
- package/FieldArray/FormDialog/ArrayDisplay/__stories__/Cards.d.ts +2 -0
- package/FieldArray/FormDialog/ArrayDisplay/__stories__/Default.d.ts +2 -0
- package/FieldArray/FormDialog/ArrayDisplay/__stories__/ReadOnly.d.ts +2 -0
- package/FieldArray/FormDialog/ArrayDisplay/__stories__/ReadOnlyCards.d.ts +2 -0
- package/FieldArray/FormDialog/ArrayDisplay/__stories__/Sortable.d.ts +2 -0
- package/FieldArray/FormDialog/ArrayDisplay/__stories__/SortableCards.d.ts +2 -0
- package/FieldArray/FormDialog/ArrayDisplay/index.d.ts +15 -0
- package/FieldArray/FormDialog/ArrayDisplay/index.js +57 -0
- package/FieldArray/FormDialog/ArrayDisplay/index.js.map +7 -0
- package/FieldArray/FormDialog/ArrayDisplay/package.json +6 -0
- package/FieldArray/FormDialog/ArrayEditModal/index.js +158 -0
- package/FieldArray/FormDialog/ArrayEditModal/package.json +6 -0
- package/FieldArray/FormDialog/ArrayEditModal.d.ts +24 -0
- package/FieldArray/FormDialog/ArrayEditModal.js.map +7 -0
- package/FieldArray/FormDialog/index.d.ts +19 -0
- package/FieldArray/FormDialog/index.js +183 -348
- package/FieldArray/FormDialog/index.js.map +7 -0
- package/FieldArray/__stories__/CardsWithError.d.ts +15 -0
- package/FieldArray/index.d.ts +4 -2
- package/FieldArray/index.js +34 -56
- package/FieldArray/index.js.map +2 -2
- package/FieldObject/index.d.ts +4 -4
- package/FieldObject/index.js +5 -12
- package/FieldObject/index.js.map +2 -2
- package/Fieldset/FieldsetWithContext.js.map +1 -1
- package/Fieldset/index.d.ts +1 -1
- package/Fieldset/index.js.map +1 -1
- package/Fieldset/types.d.ts +2 -2
- package/FormBuilder/index.d.ts +1 -1
- package/FormBuilder/index.js +158 -132
- package/FormBuilder/index.js.map +2 -2
- package/FormContext.d.ts +2 -2
- package/FormContext.js.map +2 -2
- package/MultiplicityField/add-objects/index.js +10 -19
- package/MultiplicityField/add-objects.d.ts +1 -1
- package/MultiplicityField/add-objects.js.map +2 -2
- package/MultiplicityField/index.d.ts +2 -2
- package/MultiplicityField/index.js.map +2 -2
- package/MultiplicityField/types.d.ts +2 -2
- package/Questions/Questions.d.ts +1 -1
- package/Questions/Questions.js.map +1 -1
- package/Questions/QuestionsContext.d.ts +1 -1
- package/Questions/QuestionsContext.js.map +1 -1
- package/Questions/Step/Step.d.ts +1 -1
- package/Questions/Step/Step.js.map +1 -1
- package/Questions/Step/StepArrayReview.d.ts +1 -1
- package/Questions/Step/StepArrayReview.js.map +1 -1
- package/Questions/Step/StepContext.d.ts +1 -1
- package/Questions/Step/StepContext.js.map +1 -1
- package/Questions/Step/StepDescription.d.ts +1 -1
- package/Questions/Step/StepDescription.js.map +2 -2
- package/Questions/Step/StepForm.d.ts +2 -2
- package/Questions/Step/StepForm.js.map +1 -1
- package/Questions/Step/StepQuote.d.ts +1 -1
- package/Questions/Step/StepQuote.js.map +2 -2
- package/Questions/Step/StepTitle.d.ts +1 -1
- package/Questions/Step/StepTitle.js.map +2 -2
- package/Questions/Step/getAddMoreFields.d.ts +2 -2
- package/Questions/Step/getAddMoreFields.js.map +1 -1
- package/Questions/Step/types.d.ts +1 -1
- package/Questions/getNextStep.d.ts +1 -1
- package/Questions/getNextStep.js.map +1 -1
- package/Questions/types.d.ts +1 -1
- package/cjs/Field/ErrorGroup.js.map +1 -1
- package/cjs/Field/FieldBase/index.js +2 -1
- package/cjs/Field/FieldBase.js.map +2 -2
- package/cjs/Field/FieldBaseContainer/index.js +36 -34
- package/cjs/Field/FieldBaseContainer.js.map +2 -2
- package/cjs/Field/FieldConditional.js.map +1 -1
- package/cjs/Field/index.js +16 -23
- package/cjs/Field/index.js.map +2 -2
- package/cjs/Field/types.js.map +1 -1
- package/cjs/Field/utils/evaluateFieldWithConditions.js.map +2 -2
- package/cjs/Field/utils/resolveField/index.js +55 -0
- package/cjs/Field/utils/resolveField.js.map +7 -0
- package/cjs/Field/utils/useField/index.js +4 -2
- package/cjs/Field/utils/useField.js.map +2 -2
- package/cjs/FieldArray/BaseFieldArray/index.js +109 -0
- package/cjs/FieldArray/BaseFieldArray.js.map +7 -0
- package/cjs/FieldArray/FormDialog/ArrayDisplay/ArrayContainerDisplay/index.js +56 -0
- package/cjs/FieldArray/FormDialog/ArrayDisplay/ArrayContainerDisplay.js.map +7 -0
- package/cjs/FieldArray/FormDialog/ArrayDisplay/ArrayItemDisplay/index.js +209 -0
- package/cjs/FieldArray/FormDialog/ArrayDisplay/ArrayItemDisplay.js.map +7 -0
- package/cjs/{locales/el → FieldArray/FormDialog/ArrayDisplay/ArrayItemHeader}/index.js +16 -7
- package/cjs/FieldArray/FormDialog/ArrayDisplay/ArrayItemHeader.js.map +7 -0
- package/cjs/FieldArray/FormDialog/ArrayDisplay/index.js +90 -0
- package/cjs/FieldArray/FormDialog/ArrayDisplay/index.js.map +7 -0
- package/cjs/FieldArray/FormDialog/ArrayEditModal/index.js +186 -0
- package/cjs/FieldArray/FormDialog/ArrayEditModal.js.map +7 -0
- package/cjs/FieldArray/FormDialog/index.js +174 -331
- package/cjs/FieldArray/FormDialog/index.js.map +7 -0
- package/cjs/FieldArray/index.js +33 -55
- package/cjs/FieldArray/index.js.map +3 -3
- package/cjs/FieldObject/index.js +5 -9
- package/cjs/FieldObject/index.js.map +2 -2
- package/cjs/Fieldset/FieldsetWithContext.js.map +1 -1
- package/cjs/Fieldset/index.js.map +1 -1
- package/cjs/Fieldset/types.js.map +1 -1
- package/cjs/FormBuilder/index.js +159 -133
- package/cjs/FormBuilder/index.js.map +3 -3
- package/cjs/FormContext.js.map +2 -2
- package/cjs/MultiplicityField/add-objects/index.js +9 -13
- package/cjs/MultiplicityField/add-objects.js.map +2 -2
- package/cjs/MultiplicityField/index.js.map +2 -2
- package/cjs/MultiplicityField/types.js.map +1 -1
- package/cjs/Questions/Questions.js.map +1 -1
- package/cjs/Questions/QuestionsContext.js.map +1 -1
- package/cjs/Questions/Step/Step.js.map +1 -1
- package/cjs/Questions/Step/StepArrayReview.js.map +1 -1
- package/cjs/Questions/Step/StepContext.js.map +1 -1
- package/cjs/Questions/Step/StepDescription.js.map +2 -2
- package/cjs/Questions/Step/StepForm.js.map +1 -1
- package/cjs/Questions/Step/StepQuote.js.map +2 -2
- package/cjs/Questions/Step/StepTitle.js.map +2 -2
- package/cjs/Questions/Step/getAddMoreFields.js.map +1 -1
- package/cjs/Questions/Step/types.js.map +1 -1
- package/cjs/Questions/getNextStep.js.map +1 -1
- package/cjs/Questions/types.js.map +1 -1
- package/cjs/hooks/useFieldFocusManager/index.js +135 -0
- package/cjs/hooks/useFieldFocusManager.js.map +7 -0
- package/cjs/hooks/utils/index.js +98 -0
- package/cjs/hooks/utils.js.map +7 -0
- package/cjs/inputs/AutoCompleteInput/index.js.map +2 -2
- package/cjs/inputs/Checkboxes/index.js +68 -63
- package/cjs/inputs/Checkboxes/index.js.map +2 -2
- package/cjs/inputs/DateInput/index.js +10 -5
- package/cjs/inputs/DateInput/index.js.map +2 -2
- package/cjs/inputs/DateTimeInput/index.js +10 -5
- package/cjs/inputs/DateTimeInput/index.js.map +2 -2
- package/cjs/inputs/FileInput/index.js +6 -14
- package/cjs/inputs/FileInput/index.js.map +2 -2
- package/cjs/inputs/ImageInput/index.js +4 -4
- package/cjs/inputs/ImageInput/index.js.map +2 -2
- package/cjs/inputs/Input/index.js +5 -4
- package/cjs/inputs/Input/index.js.map +2 -2
- package/cjs/inputs/Label/index.js.map +1 -1
- package/cjs/inputs/OtpInput/index.js +36 -31
- package/cjs/inputs/OtpInput/index.js.map +2 -2
- package/cjs/inputs/Radio/index.js +7 -5
- package/cjs/inputs/Radio/index.js.map +3 -3
- package/cjs/inputs/Select/index.js +2 -2
- package/cjs/inputs/Select/index.js.map +2 -2
- package/cjs/{Field/utils → inputs/registry}/index.js +4 -4
- package/cjs/inputs/registry.js.map +7 -0
- package/cjs/lazy/index.js +12 -9
- package/cjs/lazy.js.map +2 -2
- package/cjs/registry/index.js +25 -11
- package/cjs/registry.js.map +2 -2
- package/cjs/types.js.map +1 -1
- package/cjs/utils/index.js +9 -0
- package/cjs/utils.js.map +2 -2
- package/cjs/validators/index.js +5 -2
- package/cjs/validators/index.js.map +2 -2
- package/cjs/validators/types.js.map +1 -1
- package/cjs/validators/utils/date/index.js +6 -1
- package/cjs/validators/utils/date.js.map +2 -2
- package/cjs/validators/utils/datetime/index.js +6 -1
- package/cjs/validators/utils/datetime.js.map +2 -2
- package/cjs/validators/utils/email/index.js +39 -0
- package/cjs/validators/utils/email.js.map +7 -0
- package/cjs/validators/utils/file.js.map +1 -1
- package/cjs/validators/utils/iban.js.map +1 -1
- package/cjs/validators/utils/image.js.map +1 -1
- package/cjs/validators/utils/index.js.map +1 -1
- package/cjs/validators/utils/int.js.map +1 -1
- package/cjs/validators/utils/number.js.map +1 -1
- package/cjs/validators/utils/otp.js.map +1 -1
- package/cjs/validators/utils/phone.js.map +1 -1
- package/cjs/validators/utils/postal_code.js.map +1 -1
- package/cjs/validators/utils/text_limit.js.map +1 -1
- package/hooks/useFieldFocusManager/index.js +116 -0
- package/hooks/useFieldFocusManager/package.json +6 -0
- package/hooks/useFieldFocusManager.d.ts +25 -0
- package/hooks/useFieldFocusManager.js.map +7 -0
- package/hooks/utils/index.js +73 -0
- package/{Field → hooks}/utils/package.json +1 -1
- package/hooks/utils.d.ts +18 -0
- package/hooks/utils.js.map +7 -0
- package/index.js +1 -1
- package/inputs/AutoCompleteInput/index.d.ts +3 -3
- package/inputs/AutoCompleteInput/index.js +1 -3
- package/inputs/AutoCompleteInput/index.js.map +2 -2
- package/inputs/Checkboxes/index.d.ts +5 -3
- package/inputs/Checkboxes/index.js +68 -63
- package/inputs/Checkboxes/index.js.map +2 -2
- package/inputs/DateInput/index.d.ts +2 -5
- package/inputs/DateInput/index.js +10 -5
- package/inputs/DateInput/index.js.map +2 -2
- package/inputs/DateTimeInput/index.d.ts +2 -5
- package/inputs/DateTimeInput/index.js +10 -5
- package/inputs/DateTimeInput/index.js.map +2 -2
- package/inputs/FileInput/index.d.ts +4 -4
- package/inputs/FileInput/index.js +7 -18
- package/inputs/FileInput/index.js.map +2 -2
- package/inputs/ImageInput/index.d.ts +2 -2
- package/inputs/ImageInput/index.js +4 -4
- package/inputs/ImageInput/index.js.map +2 -2
- package/inputs/Input/index.d.ts +3 -1
- package/inputs/Input/index.js +5 -4
- package/inputs/Input/index.js.map +2 -2
- package/inputs/Label/index.d.ts +1 -1
- package/inputs/Label/index.js.map +1 -1
- package/inputs/OtpInput/index.d.ts +1 -5
- package/inputs/OtpInput/index.js +36 -31
- package/inputs/OtpInput/index.js.map +2 -2
- package/inputs/Radio/index.d.ts +6 -4
- package/inputs/Radio/index.js +7 -5
- package/inputs/Radio/index.js.map +3 -3
- package/inputs/Select/index.d.ts +4 -2
- package/inputs/Select/index.js +2 -2
- package/inputs/Select/index.js.map +2 -2
- package/{Field/utils → inputs/registry}/index.js +1 -1
- package/{locales/el → inputs/registry}/package.json +1 -1
- package/{Field/utils/index.d.ts → inputs/registry.d.ts} +2 -1
- package/inputs/registry.js.map +7 -0
- package/lazy/index.js +12 -9
- package/package.json +4 -4
- package/registry/index.js +25 -11
- package/src/Field/ErrorGroup.tsx +3 -3
- package/src/Field/FieldBase.tsx +3 -2
- package/src/Field/FieldBaseContainer.tsx +68 -58
- package/src/Field/FieldConditional.tsx +1 -1
- package/src/Field/index.tsx +16 -36
- package/src/Field/types.tsx +11 -12
- package/src/Field/utils/evaluateFieldWithConditions.ts +5 -2
- package/src/Field/utils/resolveField.ts +58 -0
- package/src/Field/utils/useField.ts +3 -1
- package/src/FieldArray/BaseFieldArray.tsx +97 -0
- package/src/FieldArray/FieldArray.stories.js +1 -0
- package/src/FieldArray/FormDialog/ArrayDisplay/ArrayContainerDisplay.tsx +45 -0
- package/src/FieldArray/FormDialog/ArrayDisplay/ArrayDisplay.stories.js +14 -0
- package/src/FieldArray/FormDialog/ArrayDisplay/ArrayItemDisplay.tsx +337 -0
- package/src/FieldArray/FormDialog/ArrayDisplay/ArrayItemHeader.tsx +15 -0
- package/src/FieldArray/FormDialog/ArrayDisplay/__stories__/Cards.tsx +88 -0
- package/src/FieldArray/FormDialog/ArrayDisplay/__stories__/Default.tsx +93 -0
- package/src/FieldArray/FormDialog/ArrayDisplay/__stories__/ReadOnly.tsx +79 -0
- package/src/FieldArray/FormDialog/ArrayDisplay/__stories__/ReadOnlyCards.tsx +75 -0
- package/src/FieldArray/FormDialog/ArrayDisplay/__stories__/Sortable.tsx +93 -0
- package/src/FieldArray/FormDialog/ArrayDisplay/__stories__/SortableCards.tsx +88 -0
- package/src/FieldArray/FormDialog/ArrayDisplay/index.test.tsx +44 -0
- package/src/FieldArray/FormDialog/ArrayDisplay/index.tsx +67 -0
- package/src/FieldArray/FormDialog/ArrayEditModal.tsx +241 -0
- package/src/FieldArray/FormDialog/index.tsx +302 -0
- package/src/FieldArray/__stories__/CardsWithError.tsx +124 -0
- package/src/FieldArray/__tests__/fieldset-multiplicity.spec.tsx +271 -0
- package/src/FieldArray/__tests__/multiplicity-attachment.spec.tsx +280 -0
- package/src/FieldArray/__tests__/multiplicity-optional.spec.tsx +232 -0
- package/src/FieldArray/__tests__/multiplicity-required.spec.tsx +170 -0
- package/src/FieldArray/__tests__/nested-fieldset-multiplicity.spec.tsx +627 -0
- package/src/FieldArray/__tests__/preference-multiple-choice.spec.tsx +222 -0
- package/src/FieldArray/index.spec.tsx +355 -0
- package/src/FieldArray/index.test.tsx +4 -0
- package/src/FieldArray/index.tsx +43 -63
- package/src/FieldObject/index.tsx +9 -17
- package/src/Fieldset/FieldsetWithContext.tsx +1 -1
- package/src/Fieldset/index.tsx +1 -1
- package/src/Fieldset/types.tsx +2 -2
- package/src/FormBuilder/index.tsx +190 -144
- package/src/FormBuilder/scenarios.test.tsx +760 -1
- package/src/FormContext.tsx +3 -2
- package/src/MultiplicityField/__stories__/PreviewDisplay.tsx +1 -3
- package/src/MultiplicityField/add-objects.tsx +12 -21
- package/src/MultiplicityField/index.tsx +3 -2
- package/src/MultiplicityField/types.ts +5 -2
- package/src/Questions/Questions.tsx +2 -2
- package/src/Questions/QuestionsContext.tsx +1 -1
- package/src/Questions/Step/Step.tsx +1 -1
- package/src/Questions/Step/StepArrayReview.tsx +2 -2
- package/src/Questions/Step/StepContext.tsx +1 -1
- package/src/Questions/Step/StepDescription.tsx +2 -1
- package/src/Questions/Step/StepForm.tsx +2 -2
- package/src/Questions/Step/StepQuote.tsx +2 -1
- package/src/Questions/Step/StepTitle.tsx +2 -1
- package/src/Questions/Step/getAddMoreFields.tsx +2 -2
- package/src/Questions/Step/types.tsx +1 -1
- package/src/Questions/getNextStep.tsx +1 -1
- package/src/Questions/types.tsx +1 -1
- package/src/hooks/__tests__/useFieldFocusManager.spec.tsx +1079 -0
- package/src/hooks/__tests__/utils.spec.ts +568 -0
- package/src/hooks/useFieldFocusManager.ts +162 -0
- package/src/hooks/utils.ts +122 -0
- package/src/inputs/AutoCompleteInput/index.tsx +4 -6
- package/src/inputs/Checkboxes/index.tsx +98 -87
- package/src/inputs/DateInput/index.tsx +19 -6
- package/src/inputs/DateTimeInput/index.tsx +19 -6
- package/src/inputs/FileInput/index.tsx +15 -21
- package/src/inputs/ImageInput/index.tsx +6 -6
- package/src/inputs/Input/index.tsx +12 -8
- package/src/inputs/Label/index.tsx +1 -1
- package/src/inputs/OtpInput/index.tsx +43 -34
- package/src/inputs/Radio/index.tsx +33 -22
- package/src/inputs/Select/index.tsx +6 -4
- package/src/{Field/utils/index.ts → inputs/registry.ts} +3 -1
- package/src/lazy.js +12 -9
- package/src/registry.js +25 -11
- package/src/types.tsx +13 -5
- package/src/utils.ts +14 -2
- package/src/validators/index.ts +15 -11
- package/src/validators/types.ts +1 -1
- package/src/validators/utils/date.ts +8 -3
- package/src/validators/utils/datetime.ts +8 -3
- package/src/validators/utils/email.ts +11 -0
- package/src/validators/utils/file.ts +2 -2
- package/src/validators/utils/iban.ts +2 -2
- package/src/validators/utils/image.ts +2 -2
- package/src/validators/utils/index.ts +2 -2
- package/src/validators/utils/int.ts +1 -1
- package/src/validators/utils/number.ts +1 -1
- package/src/validators/utils/otp.ts +2 -2
- package/src/validators/utils/phone.ts +2 -2
- package/src/validators/utils/postal_code.ts +2 -2
- package/src/validators/utils/text_limit.ts +2 -2
- package/types.d.ts +9 -4
- package/types.js.map +1 -1
- package/utils/index.js +8 -0
- package/utils.d.ts +2 -1
- package/utils.js.map +2 -2
- package/validators/index.d.ts +5 -5
- package/validators/index.js +5 -2
- package/validators/index.js.map +2 -2
- package/validators/types.d.ts +1 -1
- package/validators/utils/date/index.js +6 -1
- package/validators/utils/date.d.ts +2 -2
- package/validators/utils/date.js.map +2 -2
- package/validators/utils/datetime/index.js +6 -1
- package/validators/utils/datetime.d.ts +2 -2
- package/validators/utils/datetime.js.map +2 -2
- package/validators/utils/email/index.js +16 -0
- package/validators/utils/email/package.json +6 -0
- package/validators/utils/email.d.ts +5 -0
- package/validators/utils/email.js.map +7 -0
- package/validators/utils/file.d.ts +2 -2
- package/validators/utils/file.js.map +1 -1
- package/validators/utils/iban.d.ts +2 -2
- package/validators/utils/iban.js.map +1 -1
- package/validators/utils/image.d.ts +2 -2
- package/validators/utils/image.js.map +1 -1
- package/validators/utils/index.d.ts +2 -2
- package/validators/utils/index.js.map +1 -1
- package/validators/utils/int.d.ts +1 -1
- package/validators/utils/int.js.map +1 -1
- package/validators/utils/number.d.ts +1 -1
- package/validators/utils/number.js.map +1 -1
- package/validators/utils/otp.d.ts +2 -2
- package/validators/utils/otp.js.map +1 -1
- package/validators/utils/phone.d.ts +2 -2
- package/validators/utils/phone.js.map +1 -1
- package/validators/utils/postal_code.d.ts +2 -2
- package/validators/utils/postal_code.js.map +1 -1
- package/validators/utils/text_limit.d.ts +2 -2
- package/validators/utils/text_limit.js.map +1 -1
- package/Field/utils/calculateField/index.js +0 -27
- package/Field/utils/calculateField.d.ts +0 -2
- package/Field/utils/calculateField.js.map +0 -7
- package/Field/utils/index.js.map +0 -7
- package/FieldArray/FormDialog.d.ts +0 -67
- package/FieldArray/FormDialog.js.map +0 -7
- package/FormBuilder/index.test.d.ts +0 -1
- package/FormBuilder/interaction.test.d.ts +0 -1
- package/FormBuilder/scenarios.test.d.ts +0 -88
- package/MultiplicityField/index.test.d.ts +0 -1
- package/Questions/index.spec.d.ts +0 -1
- package/Questions/index.test.d.ts +0 -1
- package/cjs/Field/utils/calculateField/index.js +0 -50
- package/cjs/Field/utils/calculateField.js.map +0 -7
- package/cjs/Field/utils/index.js.map +0 -7
- package/cjs/FieldArray/FormDialog.js.map +0 -7
- package/cjs/inputs/inputsScenarios/index.js +0 -533
- package/cjs/inputs/inputsScenarios.js.map +0 -7
- package/cjs/locales/el.js.map +0 -7
- package/inputs/AutoCompleteInput/index.test.d.ts +0 -1
- package/inputs/Checkboxes/index.test.d.ts +0 -1
- package/inputs/DateInput/index.test.d.ts +0 -1
- package/inputs/DateTimeInput/index.test.d.ts +0 -1
- package/inputs/FileInput/index.test.d.ts +0 -1
- package/inputs/ImageInput/index.test.d.ts +0 -1
- package/inputs/Input/index.test.d.ts +0 -1
- package/inputs/Label/index.test.d.ts +0 -1
- package/inputs/OtpInput/index.test.d.ts +0 -1
- package/inputs/Radio/index.test.d.ts +0 -1
- package/inputs/Select/index.test.d.ts +0 -1
- package/inputs/inputsScenarios/index.js +0 -499
- package/inputs/inputsScenarios.d.ts +0 -296
- package/inputs/inputsScenarios.js.map +0 -7
- package/locales/el/index.js +0 -6
- package/locales/el.d.ts +0 -2
- package/locales/el.js.map +0 -7
- package/src/Field/utils/calculateField.ts +0 -49
- package/src/FieldArray/FormDialog.tsx +0 -568
- package/src/inputs/inputsScenarios.ts +0 -496
- package/src/locales/el.ts +0 -3
- /package/{FieldArray/index.test.d.ts → hooks/__tests__/utils.spec.d.ts} +0 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef } from "react";
|
|
2
|
+
import {
|
|
3
|
+
extractFieldEntries,
|
|
4
|
+
mapElementsToFields,
|
|
5
|
+
sortElementsByPosition
|
|
6
|
+
} from "@digigov/form/hooks/utils";
|
|
7
|
+
function useFieldFocusManager({
|
|
8
|
+
enabled = true,
|
|
9
|
+
control,
|
|
10
|
+
subscribe,
|
|
11
|
+
setFocus
|
|
12
|
+
}) {
|
|
13
|
+
const customFocusableElements = useRef(/* @__PURE__ */ new Map());
|
|
14
|
+
const focusableElements = useRef(/* @__PURE__ */ new Map());
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
if (!enabled) {
|
|
17
|
+
customFocusableElements.current.clear();
|
|
18
|
+
focusableElements.current.clear();
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
}, [enabled]);
|
|
22
|
+
const updateFocusableElements = useCallback(() => {
|
|
23
|
+
focusableElements.current.clear();
|
|
24
|
+
const formElements = extractFieldEntries(control._fields);
|
|
25
|
+
const customFieldRefs = mapElementsToFields(
|
|
26
|
+
customFocusableElements.current
|
|
27
|
+
);
|
|
28
|
+
const customElements = extractFieldEntries(customFieldRefs);
|
|
29
|
+
const combinedElements = new Map(formElements);
|
|
30
|
+
customElements.forEach((element, fieldName) => {
|
|
31
|
+
combinedElements.set(fieldName, element);
|
|
32
|
+
});
|
|
33
|
+
focusableElements.current = sortElementsByPosition(combinedElements);
|
|
34
|
+
}, [control._fields]);
|
|
35
|
+
const registerCustomFocusableElement = useCallback(
|
|
36
|
+
(fieldName, element) => {
|
|
37
|
+
if (fieldName && element) {
|
|
38
|
+
customFocusableElements.current.set(fieldName, element);
|
|
39
|
+
updateFocusableElements();
|
|
40
|
+
}
|
|
41
|
+
return function unregister() {
|
|
42
|
+
customFocusableElements.current.delete(fieldName);
|
|
43
|
+
updateFocusableElements();
|
|
44
|
+
};
|
|
45
|
+
},
|
|
46
|
+
[updateFocusableElements]
|
|
47
|
+
);
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
if (!enabled || !subscribe) return;
|
|
50
|
+
const callback = subscribe({
|
|
51
|
+
formState: {
|
|
52
|
+
errors: true
|
|
53
|
+
// Subscribe to any form state change that might indicate field structure changes
|
|
54
|
+
},
|
|
55
|
+
callback: () => {
|
|
56
|
+
setTimeout(updateFocusableElements, 0);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
updateFocusableElements();
|
|
60
|
+
return () => callback();
|
|
61
|
+
}, [enabled, updateFocusableElements, subscribe]);
|
|
62
|
+
const focusOnError = useCallback(
|
|
63
|
+
(errors) => {
|
|
64
|
+
if (!enabled) return;
|
|
65
|
+
if (!errors || Object.keys(errors).length === 0) return;
|
|
66
|
+
for (const [fieldName, element] of Array.from(
|
|
67
|
+
focusableElements.current
|
|
68
|
+
)) {
|
|
69
|
+
if (hasFieldError(errors, fieldName)) {
|
|
70
|
+
if (element && typeof element.focus === "function") {
|
|
71
|
+
element.focus();
|
|
72
|
+
return;
|
|
73
|
+
} else if (element && element.name) {
|
|
74
|
+
setFocus(fieldName);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
[enabled, setFocus]
|
|
81
|
+
);
|
|
82
|
+
return {
|
|
83
|
+
/**
|
|
84
|
+
* Registers a custom focusable element with the given field name.
|
|
85
|
+
*
|
|
86
|
+
* Returns a callback function to unregister the element by field name.
|
|
87
|
+
*
|
|
88
|
+
* @param fieldName - The name of the field to associate with the element.
|
|
89
|
+
* @param element - The HTML element to register as focusable.
|
|
90
|
+
*/
|
|
91
|
+
registerCustomFocusableElement,
|
|
92
|
+
focusOnError
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
function hasFieldError(errors, fieldName) {
|
|
96
|
+
if (!errors || typeof errors !== "object") return false;
|
|
97
|
+
if (errors[fieldName]) {
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
const keys = fieldName.split(/[.[\]]+/).filter(Boolean);
|
|
101
|
+
let current = errors;
|
|
102
|
+
for (const key of keys) {
|
|
103
|
+
if (current && typeof current === "object") {
|
|
104
|
+
current = current[key];
|
|
105
|
+
} else {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return !!current;
|
|
110
|
+
}
|
|
111
|
+
var useFieldFocusManager_default = useFieldFocusManager;
|
|
112
|
+
export {
|
|
113
|
+
useFieldFocusManager_default as default,
|
|
114
|
+
useFieldFocusManager
|
|
115
|
+
};
|
|
116
|
+
//# sourceMappingURL=useFieldFocusManager.js.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Control, FieldValues, UseFormReturn } from 'react-hook-form';
|
|
2
|
+
export interface UseFieldFocusManagerProps<T extends FieldValues> {
|
|
3
|
+
enabled?: boolean;
|
|
4
|
+
control: Control<T>;
|
|
5
|
+
subscribe: UseFormReturn['subscribe'];
|
|
6
|
+
setFocus: UseFormReturn['setFocus'];
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Custom hook to manage focus on form fields.
|
|
10
|
+
*
|
|
11
|
+
* It collects all focusable elements from the form fields and sorts them according to their position in the DOM.
|
|
12
|
+
*/
|
|
13
|
+
export declare function useFieldFocusManager<T extends FieldValues>({ enabled, control, subscribe, setFocus, }: UseFieldFocusManagerProps<T>): {
|
|
14
|
+
/**
|
|
15
|
+
* Registers a custom focusable element with the given field name.
|
|
16
|
+
*
|
|
17
|
+
* Returns a callback function to unregister the element by field name.
|
|
18
|
+
*
|
|
19
|
+
* @param fieldName - The name of the field to associate with the element.
|
|
20
|
+
* @param element - The HTML element to register as focusable.
|
|
21
|
+
*/
|
|
22
|
+
registerCustomFocusableElement: (fieldName: string, element: HTMLElement) => () => void;
|
|
23
|
+
focusOnError: (errors: Record<string, any>) => void;
|
|
24
|
+
};
|
|
25
|
+
export default useFieldFocusManager;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/hooks/useFieldFocusManager.ts"],
|
|
4
|
+
"sourcesContent": ["import { useCallback, useEffect, useRef } from 'react';\nimport type { Control, FieldValues, Ref, UseFormReturn } from 'react-hook-form';\nimport {\n extractFieldEntries,\n mapElementsToFields,\n sortElementsByPosition,\n} from '@digigov/form/hooks/utils';\n\nexport interface UseFieldFocusManagerProps<T extends FieldValues> {\n enabled?: boolean;\n control: Control<T>;\n subscribe: UseFormReturn['subscribe'];\n setFocus: UseFormReturn['setFocus'];\n}\n\n/**\n * Custom hook to manage focus on form fields.\n *\n * It collects all focusable elements from the form fields and sorts them according to their position in the DOM.\n */\nexport function useFieldFocusManager<T extends FieldValues>({\n enabled = true,\n control,\n subscribe,\n setFocus,\n}: UseFieldFocusManagerProps<T>) {\n /** Array to hold any external focusable elements registered by the user */\n const customFocusableElements = useRef(new Map<string, HTMLElement>());\n /** Map to hold focusable elements by field name */\n const focusableElements = useRef(new Map<string, Ref>());\n\n // When disabled, clear custom focusable elements and focusable elements map\n useEffect(() => {\n if (!enabled) {\n customFocusableElements.current.clear();\n focusableElements.current.clear();\n return;\n }\n }, [enabled]);\n\n const updateFocusableElements = useCallback(() => {\n // Clear existing focusable elements\n focusableElements.current.clear();\n // Extract from form fields\n const formElements = extractFieldEntries(control._fields);\n // Extract from custom elements (convert to FieldRefs format first)\n const customFieldRefs = mapElementsToFields(\n customFocusableElements.current\n );\n const customElements = extractFieldEntries(customFieldRefs);\n\n // Combine both maps\n const combinedElements = new Map(formElements);\n customElements.forEach((element, fieldName) => {\n combinedElements.set(fieldName, element);\n });\n\n // Sort once by DOM position\n focusableElements.current = sortElementsByPosition(combinedElements);\n }, [control._fields]);\n\n // Register / unregister custom focusable elements\n const registerCustomFocusableElement = useCallback(\n (fieldName: string, element: HTMLElement) => {\n if (fieldName && element) {\n customFocusableElements.current.set(fieldName, element);\n updateFocusableElements();\n }\n\n return function unregister() {\n customFocusableElements.current.delete(fieldName);\n updateFocusableElements();\n };\n },\n [updateFocusableElements]\n );\n\n // Collect focusable elements when fields change\n useEffect(() => {\n if (!enabled || !subscribe) return;\n const callback = subscribe({\n formState: {\n errors: true,\n // Subscribe to any form state change that might indicate field structure changes\n },\n callback: () => {\n // Defer to next tick to ensure DOM is updated\n setTimeout(updateFocusableElements, 0);\n },\n });\n\n // Initial update\n updateFocusableElements();\n\n return () => callback();\n }, [enabled, updateFocusableElements, subscribe]);\n\n // Subscribe to errors and focus the first field (according to the DOM) with an error\n const focusOnError = useCallback(\n (errors: Record<string, any>) => {\n if (!enabled) return;\n if (!errors || Object.keys(errors).length === 0) return;\n for (const [fieldName, element] of Array.from(\n focusableElements.current\n )) {\n if (hasFieldError(errors, fieldName)) {\n if (element && typeof element.focus === 'function') {\n element.focus(); // Focus the element directly\n return;\n } else if (element && element.name) {\n setFocus(fieldName); // Field is registered with react-hook-form\n return;\n }\n }\n }\n },\n [enabled, setFocus]\n );\n\n return {\n /**\n * Registers a custom focusable element with the given field name.\n *\n * Returns a callback function to unregister the element by field name.\n *\n * @param fieldName - The name of the field to associate with the element.\n * @param element - The HTML element to register as focusable.\n */\n registerCustomFocusableElement,\n focusOnError,\n };\n}\n\n// Helper function to check for nested field errors\nfunction hasFieldError(\n errors: Record<string, any>,\n fieldName: string\n): boolean {\n if (!errors || typeof errors !== 'object') return false;\n\n // Handle direct field names first\n if (errors[fieldName]) {\n return true;\n }\n\n // Split the field name and traverse the error object\n const keys = fieldName.split(/[.[\\]]+/).filter(Boolean);\n let current = errors;\n\n for (const key of keys) {\n if (current && typeof current === 'object') {\n current = current[key];\n } else {\n return false;\n }\n }\n\n // Check if we found a truthy error value\n return !!current;\n}\n\nexport default useFieldFocusManager;\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,aAAa,WAAW,cAAc;AAE/C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAcA,SAAS,qBAA4C;AAAA,EAC1D,UAAU;AAAA,EACV;AAAA,EACA;AAAA,EACA;AACF,GAAiC;AAE/B,QAAM,0BAA0B,OAAO,oBAAI,IAAyB,CAAC;AAErE,QAAM,oBAAoB,OAAO,oBAAI,IAAiB,CAAC;AAGvD,YAAU,MAAM;AACd,QAAI,CAAC,SAAS;AACZ,8BAAwB,QAAQ,MAAM;AACtC,wBAAkB,QAAQ,MAAM;AAChC;AAAA,IACF;AAAA,EACF,GAAG,CAAC,OAAO,CAAC;AAEZ,QAAM,0BAA0B,YAAY,MAAM;AAEhD,sBAAkB,QAAQ,MAAM;AAEhC,UAAM,eAAe,oBAAoB,QAAQ,OAAO;AAExD,UAAM,kBAAkB;AAAA,MACtB,wBAAwB;AAAA,IAC1B;AACA,UAAM,iBAAiB,oBAAoB,eAAe;AAG1D,UAAM,mBAAmB,IAAI,IAAI,YAAY;AAC7C,mBAAe,QAAQ,CAAC,SAAS,cAAc;AAC7C,uBAAiB,IAAI,WAAW,OAAO;AAAA,IACzC,CAAC;AAGD,sBAAkB,UAAU,uBAAuB,gBAAgB;AAAA,EACrE,GAAG,CAAC,QAAQ,OAAO,CAAC;AAGpB,QAAM,iCAAiC;AAAA,IACrC,CAAC,WAAmB,YAAyB;AAC3C,UAAI,aAAa,SAAS;AACxB,gCAAwB,QAAQ,IAAI,WAAW,OAAO;AACtD,gCAAwB;AAAA,MAC1B;AAEA,aAAO,SAAS,aAAa;AAC3B,gCAAwB,QAAQ,OAAO,SAAS;AAChD,gCAAwB;AAAA,MAC1B;AAAA,IACF;AAAA,IACA,CAAC,uBAAuB;AAAA,EAC1B;AAGA,YAAU,MAAM;AACd,QAAI,CAAC,WAAW,CAAC,UAAW;AAC5B,UAAM,WAAW,UAAU;AAAA,MACzB,WAAW;AAAA,QACT,QAAQ;AAAA;AAAA,MAEV;AAAA,MACA,UAAU,MAAM;AAEd,mBAAW,yBAAyB,CAAC;AAAA,MACvC;AAAA,IACF,CAAC;AAGD,4BAAwB;AAExB,WAAO,MAAM,SAAS;AAAA,EACxB,GAAG,CAAC,SAAS,yBAAyB,SAAS,CAAC;AAGhD,QAAM,eAAe;AAAA,IACnB,CAAC,WAAgC;AAC/B,UAAI,CAAC,QAAS;AACd,UAAI,CAAC,UAAU,OAAO,KAAK,MAAM,EAAE,WAAW,EAAG;AACjD,iBAAW,CAAC,WAAW,OAAO,KAAK,MAAM;AAAA,QACvC,kBAAkB;AAAA,MACpB,GAAG;AACD,YAAI,cAAc,QAAQ,SAAS,GAAG;AACpC,cAAI,WAAW,OAAO,QAAQ,UAAU,YAAY;AAClD,oBAAQ,MAAM;AACd;AAAA,UACF,WAAW,WAAW,QAAQ,MAAM;AAClC,qBAAS,SAAS;AAClB;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,IACA,CAAC,SAAS,QAAQ;AAAA,EACpB;AAEA,SAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IASL;AAAA,IACA;AAAA,EACF;AACF;AAGA,SAAS,cACP,QACA,WACS;AACT,MAAI,CAAC,UAAU,OAAO,WAAW,SAAU,QAAO;AAGlD,MAAI,OAAO,SAAS,GAAG;AACrB,WAAO;AAAA,EACT;AAGA,QAAM,OAAO,UAAU,MAAM,SAAS,EAAE,OAAO,OAAO;AACtD,MAAI,UAAU;AAEd,aAAW,OAAO,MAAM;AACtB,QAAI,WAAW,OAAO,YAAY,UAAU;AAC1C,gBAAU,QAAQ,GAAG;AAAA,IACvB,OAAO;AACL,aAAO;AAAA,IACT;AAAA,EACF;AAGA,SAAO,CAAC,CAAC;AACX;AAEA,IAAO,+BAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
function extractFieldEntries(fields, prefix = "") {
|
|
2
|
+
const elementMap = /* @__PURE__ */ new Map();
|
|
3
|
+
const fieldEntries = Object.entries(fields);
|
|
4
|
+
if (fieldEntries.length === 0) return elementMap;
|
|
5
|
+
Object.entries(fields).forEach(([fieldName, field]) => {
|
|
6
|
+
if (!field) return;
|
|
7
|
+
const fullFieldName = prefix ? `${prefix}.${fieldName}` : fieldName;
|
|
8
|
+
if (isField(field)) {
|
|
9
|
+
const element = field._f.ref;
|
|
10
|
+
if (element) {
|
|
11
|
+
elementMap.set(fullFieldName, element);
|
|
12
|
+
}
|
|
13
|
+
} else if (isFieldRefs(field)) {
|
|
14
|
+
const keys = Object.keys(field);
|
|
15
|
+
const numericKeys = keys.filter((key) => /^\d+$/.test(key));
|
|
16
|
+
const hasNumericKeys = numericKeys.length > 0;
|
|
17
|
+
if (hasNumericKeys) {
|
|
18
|
+
numericKeys.forEach((index) => {
|
|
19
|
+
const arrayItem = field[index];
|
|
20
|
+
if (arrayItem && isFieldRefs(arrayItem)) {
|
|
21
|
+
const nestedEntries = extractFieldEntries(
|
|
22
|
+
arrayItem,
|
|
23
|
+
`${fullFieldName}.${index}`
|
|
24
|
+
);
|
|
25
|
+
nestedEntries.forEach((element, fieldName2) => {
|
|
26
|
+
elementMap.set(fieldName2, element);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
} else {
|
|
31
|
+
const nestedEntries = extractFieldEntries(field, fullFieldName);
|
|
32
|
+
nestedEntries.forEach((element, fieldName2) => {
|
|
33
|
+
elementMap.set(fieldName2, element);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
return elementMap;
|
|
39
|
+
}
|
|
40
|
+
const isField = (fieldRef) => Boolean(
|
|
41
|
+
fieldRef && typeof fieldRef === "object" && "_f" in fieldRef && fieldRef._f && "ref" in fieldRef._f
|
|
42
|
+
);
|
|
43
|
+
const isFieldRefs = (fieldRef) => Boolean(fieldRef && typeof fieldRef === "object" && !isField(fieldRef));
|
|
44
|
+
function sortElementsByPosition(elements) {
|
|
45
|
+
const sortedEntries = Array.from(elements.entries()).sort(([, a], [, b]) => {
|
|
46
|
+
if (isActualHTMLElement(a) && isActualHTMLElement(b)) {
|
|
47
|
+
const aPosition = a.compareDocumentPosition(b);
|
|
48
|
+
if (aPosition & Node.DOCUMENT_POSITION_FOLLOWING) return -1;
|
|
49
|
+
if (aPosition & Node.DOCUMENT_POSITION_PRECEDING) return 1;
|
|
50
|
+
}
|
|
51
|
+
return 0;
|
|
52
|
+
});
|
|
53
|
+
return new Map(sortedEntries);
|
|
54
|
+
}
|
|
55
|
+
const isActualHTMLElement = (ref) => ref instanceof HTMLElement && typeof ref.focus === "function";
|
|
56
|
+
function mapElementsToFields(elements) {
|
|
57
|
+
const fields = {};
|
|
58
|
+
elements.forEach((element, fieldName) => {
|
|
59
|
+
fields[fieldName] = {
|
|
60
|
+
_f: {
|
|
61
|
+
ref: element,
|
|
62
|
+
name: fieldName
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
});
|
|
66
|
+
return fields;
|
|
67
|
+
}
|
|
68
|
+
export {
|
|
69
|
+
extractFieldEntries,
|
|
70
|
+
mapElementsToFields,
|
|
71
|
+
sortElementsByPosition
|
|
72
|
+
};
|
|
73
|
+
//# sourceMappingURL=utils.js.map
|
package/hooks/utils.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Field, FieldRefs, Ref } from 'react-hook-form';
|
|
2
|
+
/**
|
|
3
|
+
* Recursively extracts field entries from nested form field structure.
|
|
4
|
+
* Handles both regular nested objects and array-like structures.
|
|
5
|
+
*/
|
|
6
|
+
export declare function extractFieldEntries(fields: FieldRefs, prefix?: string): Map<string, Ref>;
|
|
7
|
+
/**
|
|
8
|
+
* Sorts a map of HTML elements by their position in the DOM.
|
|
9
|
+
* Elements appearing earlier in the document order come first.
|
|
10
|
+
*/
|
|
11
|
+
export declare function sortElementsByPosition(elements: Map<string, Ref>): Map<string, Ref>;
|
|
12
|
+
/**
|
|
13
|
+
* Maps a collection of HTML elements to a FieldRefs structure.
|
|
14
|
+
*
|
|
15
|
+
* It's not a direct conversion, but rather a way to create a simple FieldRefs
|
|
16
|
+
* structure that can be used with React Hook Form.
|
|
17
|
+
*/
|
|
18
|
+
export declare function mapElementsToFields(elements: Map<string, HTMLElement>): Record<string, Field>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/hooks/utils.ts"],
|
|
4
|
+
"sourcesContent": ["import type { Field, FieldRefs, Ref } from 'react-hook-form';\n\n/**\n * Recursively extracts field entries from nested form field structure.\n * Handles both regular nested objects and array-like structures.\n */\nexport function extractFieldEntries(\n fields: FieldRefs,\n prefix = ''\n): Map<string, Ref> {\n const elementMap = new Map<string, Ref>();\n\n const fieldEntries = Object.entries(fields);\n if (fieldEntries.length === 0) return elementMap;\n\n Object.entries(fields).forEach(([fieldName, field]) => {\n if (!field) return;\n const fullFieldName = prefix ? `${prefix}.${fieldName}` : fieldName;\n\n // Handle direct field with ref\n if (isField(field)) {\n const element = field._f.ref;\n if (element) {\n elementMap.set(fullFieldName, element);\n }\n }\n\n // Handle array fields (numeric keys indicate array indices)\n else if (isFieldRefs(field)) {\n // Check if any keys are numeric (indicating an array structure)\n // Filter out non-numeric keys like '_f' which contains field metadata\n const keys = Object.keys(field);\n const numericKeys = keys.filter((key) => /^\\d+$/.test(key));\n const hasNumericKeys = numericKeys.length > 0;\n\n if (hasNumericKeys) {\n // Process only the numeric array indices, ignore metadata keys like '_f'\n numericKeys.forEach((index) => {\n const arrayItem = field[index];\n if (arrayItem && isFieldRefs(arrayItem)) {\n const nestedEntries = extractFieldEntries(\n arrayItem,\n `${fullFieldName}.${index}`\n );\n // Merge nested entries into main map\n nestedEntries.forEach((element, fieldName) => {\n elementMap.set(fieldName, element);\n });\n }\n });\n } else {\n // Handle regular nested objects\n const nestedEntries = extractFieldEntries(field, fullFieldName);\n // Merge nested entries into main map\n nestedEntries.forEach((element, fieldName) => {\n elementMap.set(fieldName, element);\n });\n }\n }\n });\n\n return elementMap;\n}\n\n/** Type guard to check if a ref is a Field object */\nconst isField = (fieldRef: FieldRefs[keyof FieldRefs]): fieldRef is Field =>\n Boolean(\n fieldRef &&\n typeof fieldRef === 'object' &&\n '_f' in fieldRef &&\n fieldRef._f &&\n 'ref' in fieldRef._f\n );\n\n/** Type guard to check if a ref is a FieldRefs object (nested fields) */\nconst isFieldRefs = (\n fieldRef: FieldRefs[keyof FieldRefs]\n): fieldRef is FieldRefs =>\n Boolean(fieldRef && typeof fieldRef === 'object' && !isField(fieldRef));\n\n/**\n * Sorts a map of HTML elements by their position in the DOM.\n * Elements appearing earlier in the document order come first.\n */\nexport function sortElementsByPosition(\n elements: Map<string, Ref>\n): Map<string, Ref> {\n const sortedEntries = Array.from(elements.entries()).sort(([, a], [, b]) => {\n if (isActualHTMLElement(a) && isActualHTMLElement(b)) {\n const aPosition = a.compareDocumentPosition(b);\n if (aPosition & Node.DOCUMENT_POSITION_FOLLOWING) return -1;\n if (aPosition & Node.DOCUMENT_POSITION_PRECEDING) return 1;\n }\n return 0; // keep original order\n });\n return new Map(sortedEntries);\n}\n\n/** Type guard to check if a ref is an actual HTML element */\nconst isActualHTMLElement = (ref: Ref): ref is Ref & HTMLElement =>\n ref instanceof HTMLElement && typeof ref.focus === 'function';\n\n/**\n * Maps a collection of HTML elements to a FieldRefs structure.\n *\n * It's not a direct conversion, but rather a way to create a simple FieldRefs\n * structure that can be used with React Hook Form.\n */\nexport function mapElementsToFields(\n elements: Map<string, HTMLElement>\n): Record<string, Field> {\n const fields = {};\n elements.forEach((element, fieldName) => {\n fields[fieldName] = {\n _f: {\n ref: element,\n name: fieldName,\n },\n };\n });\n return fields;\n}\n"],
|
|
5
|
+
"mappings": "AAMO,SAAS,oBACd,QACA,SAAS,IACS;AAClB,QAAM,aAAa,oBAAI,IAAiB;AAExC,QAAM,eAAe,OAAO,QAAQ,MAAM;AAC1C,MAAI,aAAa,WAAW,EAAG,QAAO;AAEtC,SAAO,QAAQ,MAAM,EAAE,QAAQ,CAAC,CAAC,WAAW,KAAK,MAAM;AACrD,QAAI,CAAC,MAAO;AACZ,UAAM,gBAAgB,SAAS,GAAG,MAAM,IAAI,SAAS,KAAK;AAG1D,QAAI,QAAQ,KAAK,GAAG;AAClB,YAAM,UAAU,MAAM,GAAG;AACzB,UAAI,SAAS;AACX,mBAAW,IAAI,eAAe,OAAO;AAAA,MACvC;AAAA,IACF,WAGS,YAAY,KAAK,GAAG;AAG3B,YAAM,OAAO,OAAO,KAAK,KAAK;AAC9B,YAAM,cAAc,KAAK,OAAO,CAAC,QAAQ,QAAQ,KAAK,GAAG,CAAC;AAC1D,YAAM,iBAAiB,YAAY,SAAS;AAE5C,UAAI,gBAAgB;AAElB,oBAAY,QAAQ,CAAC,UAAU;AAC7B,gBAAM,YAAY,MAAM,KAAK;AAC7B,cAAI,aAAa,YAAY,SAAS,GAAG;AACvC,kBAAM,gBAAgB;AAAA,cACpB;AAAA,cACA,GAAG,aAAa,IAAI,KAAK;AAAA,YAC3B;AAEA,0BAAc,QAAQ,CAAC,SAASA,eAAc;AAC5C,yBAAW,IAAIA,YAAW,OAAO;AAAA,YACnC,CAAC;AAAA,UACH;AAAA,QACF,CAAC;AAAA,MACH,OAAO;AAEL,cAAM,gBAAgB,oBAAoB,OAAO,aAAa;AAE9D,sBAAc,QAAQ,CAAC,SAASA,eAAc;AAC5C,qBAAW,IAAIA,YAAW,OAAO;AAAA,QACnC,CAAC;AAAA,MACH;AAAA,IACF;AAAA,EACF,CAAC;AAED,SAAO;AACT;AAGA,MAAM,UAAU,CAAC,aACf;AAAA,EACE,YACE,OAAO,aAAa,YACpB,QAAQ,YACR,SAAS,MACT,SAAS,SAAS;AACtB;AAGF,MAAM,cAAc,CAClB,aAEA,QAAQ,YAAY,OAAO,aAAa,YAAY,CAAC,QAAQ,QAAQ,CAAC;AAMjE,SAAS,uBACd,UACkB;AAClB,QAAM,gBAAgB,MAAM,KAAK,SAAS,QAAQ,CAAC,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,MAAM;AAC1E,QAAI,oBAAoB,CAAC,KAAK,oBAAoB,CAAC,GAAG;AACpD,YAAM,YAAY,EAAE,wBAAwB,CAAC;AAC7C,UAAI,YAAY,KAAK,4BAA6B,QAAO;AACzD,UAAI,YAAY,KAAK,4BAA6B,QAAO;AAAA,IAC3D;AACA,WAAO;AAAA,EACT,CAAC;AACD,SAAO,IAAI,IAAI,aAAa;AAC9B;AAGA,MAAM,sBAAsB,CAAC,QAC3B,eAAe,eAAe,OAAO,IAAI,UAAU;AAQ9C,SAAS,oBACd,UACuB;AACvB,QAAM,SAAS,CAAC;AAChB,WAAS,QAAQ,CAAC,SAAS,cAAc;AACvC,WAAO,SAAS,IAAI;AAAA,MAClB,IAAI;AAAA,QACF,KAAK;AAAA,QACL,MAAM;AAAA,MACR;AAAA,IACF;AAAA,EACF,CAAC;AACD,SAAO;AACT;",
|
|
6
|
+
"names": ["fieldName"]
|
|
7
|
+
}
|
package/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { ControlledFieldProps } from '@digigov/form/Field/types';
|
|
3
|
-
import { FieldOptionProps } from '@digigov/form/inputs/Label';
|
|
4
|
-
import { AutoCompleteProps as UIAutoCompleteProps } from '@digigov/ui/form/AutoComplete';
|
|
2
|
+
import type { ControlledFieldProps } from '@digigov/form/Field/types';
|
|
3
|
+
import type { FieldOptionProps } from '@digigov/form/inputs/Label';
|
|
4
|
+
import type { AutoCompleteProps as UIAutoCompleteProps } from '@digigov/ui/form/AutoComplete';
|
|
5
5
|
export interface AutoCompleteInputExtra extends Omit<UIAutoCompleteProps, 'source' | 'id' | 'templates' | 'defaultValue' | 'onConfirm' | 'dropdownArrow'> {
|
|
6
6
|
options: FieldOptionProps[];
|
|
7
7
|
}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import React, { useCallback } from "react";
|
|
2
|
-
import {
|
|
3
|
-
AutoComplete
|
|
4
|
-
} from "@digigov/ui/form/AutoComplete";
|
|
2
|
+
import { AutoComplete } from "@digigov/ui/form/AutoComplete";
|
|
5
3
|
import { Hint } from "@digigov/ui/typography/Hint";
|
|
6
4
|
import { Base } from "@digigov/ui/utils/Base";
|
|
7
5
|
const AutoCompleteInput = ({
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/inputs/AutoCompleteInput/index.tsx"],
|
|
4
|
-
"sourcesContent": ["import React, { useCallback } from 'react';\nimport { ControlledFieldProps } from '@digigov/form/Field/types';\nimport { FieldOptionProps } from '@digigov/form/inputs/Label';\nimport {
|
|
5
|
-
"mappings": "AAAA,OAAO,SAAS,mBAAmB;
|
|
4
|
+
"sourcesContent": ["import React, { useCallback } from 'react';\nimport type { ControlledFieldProps } from '@digigov/form/Field/types';\nimport type { FieldOptionProps } from '@digigov/form/inputs/Label';\nimport type { AutoCompleteProps as UIAutoCompleteProps } from '@digigov/ui/form/AutoComplete';\nimport { AutoComplete } from '@digigov/ui/form/AutoComplete';\nimport { Hint } from '@digigov/ui/typography/Hint';\nimport { Base } from '@digigov/ui/utils/Base';\nexport interface AutoCompleteInputExtra\n extends Omit<\n UIAutoCompleteProps,\n | 'source'\n | 'id'\n | 'templates'\n | 'defaultValue'\n | 'onConfirm'\n | 'dropdownArrow'\n > {\n options: FieldOptionProps[];\n}\n\nexport interface AutoCompleteInputProps\n extends Omit<ControlledFieldProps, 'value' | 'onChange' | 'extra'> {\n extra: AutoCompleteInputExtra;\n value: string;\n onChange: (v: string | string[] | undefined) => void;\n}\n\nexport const AutoCompleteInput: React.FC<AutoCompleteInputProps> = ({\n name,\n type,\n extra: { options },\n onChange,\n value,\n ...props\n}) => {\n const suggest = useCallback(\n function suggest(\n query: string,\n syncResults: (options: any[]) => void\n ): void {\n syncResults(\n query\n ? options.filter(function (option) {\n return (\n `${option.value} ${option.label?.primary || ''} ${\n option.label?.secondary || ''\n }`\n .toLowerCase()\n .indexOf(query.toLowerCase()) !== -1\n );\n })\n : options\n );\n },\n [options]\n );\n\n return (\n <AutoComplete\n multiple={type === 'choice:multiple' ? true : false}\n source={suggest}\n onConfirm={(value) => {\n if (Array.isArray(value)) {\n const selectedValues = value.map((item) => item.value);\n if (selectedValues.length > 0) onChange(selectedValues);\n else onChange(undefined);\n } else {\n onChange(value.value);\n }\n }}\n templates={{\n suggestion({ label, value }) {\n return (\n <Base as=\"div\">\n {(label && label.primary && label.primary) || value}\n {label && label.secondary && <Hint>{label.secondary}</Hint>}\n </Base>\n );\n },\n inputValue: (option) => {\n if (!option) {\n return '';\n }\n return option.label.primary || option.value;\n },\n }}\n {...{\n ...props,\n reset: undefined,\n required: undefined,\n Field: undefined,\n }}\n name={name}\n id={`${name}-id`}\n defaultValue={value}\n />\n );\n};\n\nexport default AutoCompleteInput;\n"],
|
|
5
|
+
"mappings": "AAAA,OAAO,SAAS,mBAAmB;AAInC,SAAS,oBAAoB;AAC7B,SAAS,YAAY;AACrB,SAAS,YAAY;AAqBd,MAAM,oBAAsD,CAAC;AAAA,EAClE;AAAA,EACA;AAAA,EACA,OAAO,EAAE,QAAQ;AAAA,EACjB;AAAA,EACA;AAAA,EACA,GAAG;AACL,MAAM;AACJ,QAAM,UAAU;AAAA,IACd,SAASA,SACP,OACA,aACM;AACN;AAAA,QACE,QACI,QAAQ,OAAO,SAAU,QAAQ;AAC/B,iBACE,GAAG,OAAO,KAAK,IAAI,OAAO,OAAO,WAAW,EAAE,IAC5C,OAAO,OAAO,aAAa,EAC7B,GACG,YAAY,EACZ,QAAQ,MAAM,YAAY,CAAC,MAAM;AAAA,QAExC,CAAC,IACD;AAAA,MACN;AAAA,IACF;AAAA,IACA,CAAC,OAAO;AAAA,EACV;AAEA,SACE;AAAA,IAAC;AAAA;AAAA,MACC,UAAU,SAAS,oBAAoB,OAAO;AAAA,MAC9C,QAAQ;AAAA,MACR,WAAW,CAACC,WAAU;AACpB,YAAI,MAAM,QAAQA,MAAK,GAAG;AACxB,gBAAM,iBAAiBA,OAAM,IAAI,CAAC,SAAS,KAAK,KAAK;AACrD,cAAI,eAAe,SAAS,EAAG,UAAS,cAAc;AAAA,cACjD,UAAS,MAAS;AAAA,QACzB,OAAO;AACL,mBAASA,OAAM,KAAK;AAAA,QACtB;AAAA,MACF;AAAA,MACA,WAAW;AAAA,QACT,WAAW,EAAE,OAAO,OAAAA,OAAM,GAAG;AAC3B,iBACE,oCAAC,QAAK,IAAG,SACL,SAAS,MAAM,WAAW,MAAM,WAAYA,QAC7C,SAAS,MAAM,aAAa,oCAAC,YAAM,MAAM,SAAU,CACtD;AAAA,QAEJ;AAAA,QACA,YAAY,CAAC,WAAW;AACtB,cAAI,CAAC,QAAQ;AACX,mBAAO;AAAA,UACT;AACA,iBAAO,OAAO,MAAM,WAAW,OAAO;AAAA,QACxC;AAAA,MACF;AAAA,MACC,GAAG;AAAA,QACF,GAAG;AAAA,QACH,OAAO;AAAA,QACP,UAAU;AAAA,QACV,OAAO;AAAA,MACT;AAAA,MACA;AAAA,MACA,IAAI,GAAG,IAAI;AAAA,MACX,cAAc;AAAA;AAAA,EAChB;AAEJ;AAEA,IAAO,4BAAQ;",
|
|
6
6
|
"names": ["suggest", "value"]
|
|
7
7
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import type { UseFormReturn } from 'react-hook-form';
|
|
3
|
+
import type { ControlledFieldProps } from '@digigov/form/Field/types';
|
|
4
|
+
import type { FieldOptionProps } from '@digigov/form/inputs/Label';
|
|
4
5
|
export interface CheckboxesProps extends Omit<ControlledFieldProps, 'extra' | 'value'> {
|
|
5
6
|
value?: string[];
|
|
6
7
|
extra: {
|
|
@@ -8,6 +9,7 @@ export interface CheckboxesProps extends Omit<ControlledFieldProps, 'extra' | 'v
|
|
|
8
9
|
options: FieldOptionProps[];
|
|
9
10
|
};
|
|
10
11
|
fieldComponent: React.FC<Omit<ControlledFieldProps, 'value' | 'onChange'>>;
|
|
12
|
+
resetField: UseFormReturn['resetField'];
|
|
11
13
|
}
|
|
12
|
-
export declare const Checkboxes: React.
|
|
14
|
+
export declare const Checkboxes: React.ForwardRefExoticComponent<CheckboxesProps & React.RefAttributes<HTMLInputElement>>;
|
|
13
15
|
export default Checkboxes;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React, { useState } from "react";
|
|
2
|
+
import { omit } from "@digigov/form/utils";
|
|
2
3
|
import {
|
|
3
4
|
Checkbox,
|
|
4
5
|
CheckboxItem,
|
|
@@ -6,70 +7,74 @@ import {
|
|
|
6
7
|
} from "@digigov/ui/form/Checkbox";
|
|
7
8
|
import { useTranslation } from "@digigov/ui/i18n";
|
|
8
9
|
import { Hint } from "@digigov/ui/typography/Hint";
|
|
9
|
-
const Checkboxes = (
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
({
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
show,
|
|
43
|
-
disabled: optionDisabled,
|
|
44
|
-
selected,
|
|
45
|
-
...option
|
|
46
|
-
}, index) => /* @__PURE__ */ React.createElement(React.Fragment, { key: index }, /* @__PURE__ */ React.createElement(
|
|
47
|
-
CheckboxItem,
|
|
48
|
-
{
|
|
49
|
-
key: `${name}.${index}`,
|
|
50
|
-
name: `${name}.${v}`,
|
|
51
|
-
id: `${name}.${v}`,
|
|
10
|
+
const Checkboxes = React.forwardRef(
|
|
11
|
+
({
|
|
12
|
+
name,
|
|
13
|
+
onChange,
|
|
14
|
+
value,
|
|
15
|
+
extra: { options, className },
|
|
16
|
+
disabled,
|
|
17
|
+
Field,
|
|
18
|
+
...props
|
|
19
|
+
}, ref) => {
|
|
20
|
+
if (!value) value = [];
|
|
21
|
+
const handleChange = (optionValue, idx, show) => (evt) => {
|
|
22
|
+
let newValue = [];
|
|
23
|
+
if (evt.currentTarget.checked) {
|
|
24
|
+
newValue = value.concat([optionValue]);
|
|
25
|
+
} else {
|
|
26
|
+
newValue = value.filter((val) => val !== optionValue);
|
|
27
|
+
}
|
|
28
|
+
if (show && show.length > 0) {
|
|
29
|
+
setChecked(
|
|
30
|
+
(items) => items.map((item, index) => index === idx ? !item : item)
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
if (newValue.length === 0) newValue = void 0;
|
|
34
|
+
onChange(newValue);
|
|
35
|
+
};
|
|
36
|
+
const { t } = useTranslation();
|
|
37
|
+
const [checked, setChecked] = useState(
|
|
38
|
+
Array(options.length).fill(false)
|
|
39
|
+
);
|
|
40
|
+
return /* @__PURE__ */ React.createElement(Checkbox, { className }, options.map(
|
|
41
|
+
({
|
|
42
|
+
label,
|
|
52
43
|
value: v,
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
...option
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
44
|
+
show,
|
|
45
|
+
disabled: optionDisabled,
|
|
46
|
+
selected,
|
|
47
|
+
...option
|
|
48
|
+
}, index) => /* @__PURE__ */ React.createElement(React.Fragment, { key: index }, /* @__PURE__ */ React.createElement(
|
|
49
|
+
CheckboxItem,
|
|
50
|
+
{
|
|
51
|
+
ref: index === 0 ? ref : void 0,
|
|
52
|
+
key: `${name}.${index}`,
|
|
53
|
+
name: `${name}.${v}`,
|
|
54
|
+
id: `${name}.${v}`,
|
|
55
|
+
value: v,
|
|
56
|
+
disabled: disabled || optionDisabled,
|
|
57
|
+
checked: value?.includes(v),
|
|
58
|
+
onChange: handleChange(v, index, show),
|
|
59
|
+
...option,
|
|
60
|
+
...{
|
|
61
|
+
...omit(props, ["resetField"]),
|
|
62
|
+
reset: void 0,
|
|
63
|
+
defaultValue: void 0,
|
|
64
|
+
error: void 0,
|
|
65
|
+
onBlur: void 0,
|
|
66
|
+
required: void 0,
|
|
67
|
+
"aria-describedby": void 0,
|
|
68
|
+
type: "checkbox"
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
label && label.primary && t(label.primary) || value,
|
|
72
|
+
label && label.secondary && /* @__PURE__ */ React.createElement(Hint, null, t(label.secondary))
|
|
73
|
+
), !!checked[index] && show && Field && /* @__PURE__ */ React.createElement(CheckboxConditional, null, show.map((fieldName) => /* @__PURE__ */ React.createElement(Field, { name: fieldName, key: fieldName }))), selected && selected())
|
|
74
|
+
));
|
|
75
|
+
}
|
|
76
|
+
);
|
|
77
|
+
Checkboxes.displayName = "Checkboxes";
|
|
73
78
|
var Checkboxes_default = Checkboxes;
|
|
74
79
|
export {
|
|
75
80
|
Checkboxes,
|
|
@@ -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
|
|
5
|
-
"mappings": "AAAA,OAAO,SAAS,gBAAgB;
|
|
4
|
+
"sourcesContent": ["import React, { useState } from 'react';\nimport type { UseFormReturn } from 'react-hook-form';\nimport type { ControlledFieldProps } from '@digigov/form/Field/types';\nimport type { FieldOptionProps } from '@digigov/form/inputs/Label';\nimport { omit } from '@digigov/form/utils';\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 resetField: UseFormReturn['resetField'];\n}\n\nexport const Checkboxes = React.forwardRef<HTMLInputElement, CheckboxesProps>(\n (\n {\n name,\n onChange,\n value,\n extra: { options, className },\n disabled,\n Field,\n ...props\n },\n ref\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 ref={index === 0 ? ref : undefined}\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 ...omit(props, ['resetField']),\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);\n\nCheckboxes.displayName = 'Checkboxes';\n\nexport default Checkboxes;\n"],
|
|
5
|
+
"mappings": "AAAA,OAAO,SAAS,gBAAgB;AAIhC,SAAS,YAAY;AACrB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,sBAAsB;AAC/B,SAAS,YAAY;AAad,MAAM,aAAa,MAAM;AAAA,EAC9B,CACE;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,IACA,OAAO,EAAE,SAAS,UAAU;AAAA,IAC5B;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EACL,GACA,QACG;AACH,QAAI,CAAC,MAAO,SAAQ,CAAC;AACrB,UAAM,eACJ,CAAC,aAAa,KAAK,SACnB,CAAC,QAAc;AACb,UAAI,WAAgB,CAAC;AACrB,UAAI,IAAI,cAAc,SAAS;AAC7B,mBAAW,MAAM,OAAO,CAAC,WAAW,CAAC;AAAA,MACvC,OAAO;AACL,mBAAW,MAAM,OAAO,CAAC,QAAQ,QAAQ,WAAW;AAAA,MACtD;AACA,UAAI,QAAQ,KAAK,SAAS,GAAG;AAC3B;AAAA,UAAW,CAAC,UACV,MAAM,IAAI,CAAC,MAAM,UAAW,UAAU,MAAM,CAAC,OAAO,IAAK;AAAA,QAC3D;AAAA,MACF;AAIA,UAAI,SAAS,WAAW,EAAG,YAAW;AACtC,eAAS,QAAQ;AAAA,IACnB;AACF,UAAM,EAAE,EAAE,IAAI,eAAe;AAC7B,UAAM,CAAC,SAAS,UAAU,IAAI;AAAA,MAC5B,MAAe,QAAQ,MAAM,EAAE,KAAK,KAAK;AAAA,IAC3C;AACA,WACE,oCAAC,YAAS,aACP,QAAQ;AAAA,MACP,CACE;AAAA,QACE;AAAA,QACA,OAAO;AAAA,QACP;AAAA,QACA,UAAU;AAAA,QACV;AAAA,QACA,GAAG;AAAA,MACL,GACA,UAEA,oCAAC,MAAM,UAAN,EAAe,KAAK,SACnB;AAAA,QAAC;AAAA;AAAA,UACC,KAAK,UAAU,IAAI,MAAM;AAAA,UACzB,KAAK,GAAG,IAAI,IAAI,KAAK;AAAA,UACrB,MAAM,GAAG,IAAI,IAAI,CAAC;AAAA,UAClB,IAAI,GAAG,IAAI,IAAI,CAAC;AAAA,UAChB,OAAO;AAAA,UACP,UAAU,YAAY;AAAA,UACtB,SAAS,OAAO,SAAS,CAAC;AAAA,UAC1B,UAAU,aAAa,GAAG,OAAO,IAAI;AAAA,UACpC,GAAG;AAAA,UACH,GAAG;AAAA,YACF,GAAG,KAAK,OAAO,CAAC,YAAY,CAAC;AAAA,YAC7B,OAAO;AAAA,YACP,cAAc;AAAA,YACd,OAAO;AAAA,YACP,QAAQ;AAAA,YACR,UAAU;AAAA,YACV,oBAAoB;AAAA,YACpB,MAAM;AAAA,UACR;AAAA;AAAA,QAEE,SAAS,MAAM,WAAW,EAAE,MAAM,OAAO,KAAM;AAAA,QAChD,SAAS,MAAM,aAAa,oCAAC,YAAM,EAAE,MAAM,SAAS,CAAE;AAAA,MACzD,GAEC,CAAC,CAAC,QAAQ,KAAK,KAAK,QAAQ,SAC3B,oCAAC,2BACE,KAAK,IAAI,CAAC,cACT,oCAAC,SAAM,MAAM,WAAW,KAAK,WAAW,CACzC,CACH,GAED,YAAY,SAAS,CACxB;AAAA,IAEJ,CACF;AAAA,EAEJ;AACF;AAEA,WAAW,cAAc;AAEzB,IAAO,qBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { UncontrolledFieldProps } from '@digigov/form/Field/types';
|
|
2
|
+
import type { UncontrolledFieldProps } from '@digigov/form/Field/types';
|
|
3
3
|
export interface DateInputProps extends Omit<UncontrolledFieldProps, 'extra'> {
|
|
4
4
|
extra?: {
|
|
5
5
|
max?: string;
|
|
6
6
|
min?: string;
|
|
7
7
|
};
|
|
8
8
|
}
|
|
9
|
-
export declare const DateInput:
|
|
10
|
-
[x: string]: any;
|
|
11
|
-
name: any;
|
|
12
|
-
}) => React.JSX.Element;
|
|
9
|
+
export declare const DateInput: React.ForwardRefExoticComponent<Omit<Record<string, any>, "ref"> & React.RefAttributes<HTMLInputElement>>;
|
|
13
10
|
export default DateInput;
|
|
@@ -68,10 +68,13 @@ const makeDate = (val) => {
|
|
|
68
68
|
}
|
|
69
69
|
return "";
|
|
70
70
|
};
|
|
71
|
-
const DatePart = (
|
|
72
|
-
|
|
73
|
-
};
|
|
74
|
-
|
|
71
|
+
const DatePart = React.forwardRef(
|
|
72
|
+
({ label, ...props }, ref) => {
|
|
73
|
+
return /* @__PURE__ */ React.createElement(DateInputItem, { ...props, ref }, label);
|
|
74
|
+
}
|
|
75
|
+
);
|
|
76
|
+
DatePart.displayName = "DatePart";
|
|
77
|
+
const DateInput = React.forwardRef(({ name, ...props }, ref) => {
|
|
75
78
|
const { t } = useTranslation();
|
|
76
79
|
const form = useFormContext();
|
|
77
80
|
useEffect(() => {
|
|
@@ -91,6 +94,7 @@ const DateInput = ({ name, ...props }) => {
|
|
|
91
94
|
return /* @__PURE__ */ React.createElement(DateInputContainer, null, /* @__PURE__ */ React.createElement(
|
|
92
95
|
DatePart,
|
|
93
96
|
{
|
|
97
|
+
ref,
|
|
94
98
|
label: t("form.label.day"),
|
|
95
99
|
onChange: date.setDay,
|
|
96
100
|
onBlur: (e) => {
|
|
@@ -144,7 +148,8 @@ const DateInput = ({ name, ...props }) => {
|
|
|
144
148
|
error: !date.year ? props.error : false
|
|
145
149
|
}
|
|
146
150
|
));
|
|
147
|
-
};
|
|
151
|
+
});
|
|
152
|
+
DateInput.displayName = "DateInput";
|
|
148
153
|
var DateInput_default = DateInput;
|
|
149
154
|
export {
|
|
150
155
|
DateInput,
|