@digigov/form 2.0.0-555d1027 → 2.0.0-5e7a6790
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 +0 -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 +15 -25
- 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/FormDialog/ArrayDisplay/ArrayDisplay.stories.d.ts +10 -0
- package/FieldArray/FormDialog/ArrayDisplay/ArrayItemDisplay/index.js +97 -0
- package/FieldArray/FormDialog/ArrayDisplay/ArrayItemDisplay/package.json +6 -0
- package/FieldArray/FormDialog/ArrayDisplay/ArrayItemDisplay.d.ts +22 -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__/Default.d.ts +2 -0
- package/FieldArray/FormDialog/ArrayDisplay/__stories__/ReadOnly.d.ts +2 -0
- package/FieldArray/FormDialog/ArrayDisplay/__stories__/Sortable.d.ts +2 -0
- package/FieldArray/FormDialog/ArrayDisplay/index.d.ts +14 -0
- package/FieldArray/FormDialog/ArrayDisplay/index.js +51 -0
- package/FieldArray/FormDialog/ArrayDisplay/index.js.map +7 -0
- package/FieldArray/FormDialog/ArrayDisplay/package.json +6 -0
- package/FieldArray/FormDialog/ArrayEditModal/index.js +149 -0
- package/FieldArray/FormDialog/ArrayEditModal/package.json +6 -0
- package/FieldArray/FormDialog/ArrayEditModal.d.ts +26 -0
- package/FieldArray/FormDialog/ArrayEditModal.js.map +7 -0
- package/FieldArray/FormDialog/index.d.ts +19 -0
- package/FieldArray/FormDialog/index.js +139 -348
- package/FieldArray/FormDialog/index.js.map +7 -0
- package/FieldArray/index.d.ts +4 -2
- package/FieldArray/index.js +28 -54
- package/FieldArray/index.js.map +2 -2
- package/FieldObject/index.d.ts +4 -4
- package/FieldObject/index.js +5 -12
- package/FieldObject/index.js.map +2 -2
- package/Fieldset/FieldsetWithContext.js.map +1 -1
- package/Fieldset/index.d.ts +1 -1
- package/Fieldset/index.js.map +1 -1
- package/Fieldset/types.d.ts +2 -2
- package/FormBuilder/index.d.ts +1 -1
- package/FormBuilder/index.js +155 -130
- 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 +0 -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 +15 -22
- 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/ArrayItemDisplay/index.js +130 -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 +84 -0
- package/cjs/FieldArray/FormDialog/ArrayDisplay/index.js.map +7 -0
- package/cjs/FieldArray/FormDialog/ArrayEditModal/index.js +177 -0
- package/cjs/FieldArray/FormDialog/ArrayEditModal.js.map +7 -0
- package/cjs/FieldArray/FormDialog/index.js +130 -331
- package/cjs/FieldArray/FormDialog/index.js.map +7 -0
- package/cjs/FieldArray/index.js +27 -53
- package/cjs/FieldArray/index.js.map +3 -3
- package/cjs/FieldObject/index.js +5 -9
- package/cjs/FieldObject/index.js.map +2 -2
- package/cjs/Fieldset/FieldsetWithContext.js.map +1 -1
- package/cjs/Fieldset/index.js.map +1 -1
- package/cjs/Fieldset/types.js.map +1 -1
- package/cjs/FormBuilder/index.js +156 -131
- package/cjs/FormBuilder/index.js.map +3 -3
- package/cjs/FormContext.js.map +2 -2
- package/cjs/MultiplicityField/add-objects/index.js +9 -13
- package/cjs/MultiplicityField/add-objects.js.map +2 -2
- package/cjs/MultiplicityField/index.js.map +2 -2
- package/cjs/MultiplicityField/types.js.map +1 -1
- package/cjs/Questions/Questions.js.map +1 -1
- package/cjs/Questions/QuestionsContext.js.map +1 -1
- package/cjs/Questions/Step/Step.js.map +1 -1
- package/cjs/Questions/Step/StepArrayReview.js.map +1 -1
- package/cjs/Questions/Step/StepContext.js.map +1 -1
- package/cjs/Questions/Step/StepDescription.js.map +2 -2
- package/cjs/Questions/Step/StepForm.js.map +1 -1
- package/cjs/Questions/Step/StepQuote.js.map +2 -2
- package/cjs/Questions/Step/StepTitle.js.map +2 -2
- package/cjs/Questions/Step/getAddMoreFields.js.map +1 -1
- package/cjs/Questions/Step/types.js.map +1 -1
- package/cjs/Questions/getNextStep.js.map +1 -1
- package/cjs/Questions/types.js.map +1 -1
- package/cjs/hooks/useFieldFocusManager/index.js +135 -0
- package/cjs/hooks/useFieldFocusManager.js.map +7 -0
- package/cjs/hooks/utils/index.js +98 -0
- package/cjs/hooks/utils.js.map +7 -0
- package/cjs/inputs/AutoCompleteInput/index.js.map +2 -2
- package/cjs/inputs/Checkboxes/index.js +67 -63
- package/cjs/inputs/Checkboxes/index.js.map +2 -2
- package/cjs/inputs/DateInput/index.js +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.map +2 -2
- package/cjs/inputs/ImageInput/index.js.map +1 -1
- package/cjs/inputs/Input/index.js +54 -56
- package/cjs/inputs/Input/index.js.map +2 -2
- package/cjs/inputs/Label/index.js.map +1 -1
- package/cjs/inputs/OtpInput/index.js +36 -31
- package/cjs/inputs/OtpInput/index.js.map +2 -2
- package/cjs/inputs/Radio/index.js +5 -4
- package/cjs/inputs/Radio/index.js.map +3 -3
- package/cjs/inputs/Select/index.js.map +1 -1
- package/cjs/{Field/utils → inputs/registry}/index.js +4 -4
- package/cjs/inputs/registry.js.map +7 -0
- package/cjs/{lazy/index.js → lazy.js} +10 -9
- package/cjs/lazy.js.map +2 -2
- package/cjs/{registry/index.js → registry.js} +23 -13
- package/cjs/registry.js.map +2 -2
- package/cjs/types.js.map +1 -1
- package/cjs/utils.js.map +2 -2
- package/cjs/validators/index.js.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/file.js.map +1 -1
- package/cjs/validators/utils/iban.js.map +1 -1
- package/cjs/validators/utils/image.js.map +1 -1
- package/cjs/validators/utils/index.js.map +1 -1
- package/cjs/validators/utils/int.js.map +1 -1
- package/cjs/validators/utils/number.js.map +1 -1
- package/cjs/validators/utils/otp.js.map +1 -1
- package/cjs/validators/utils/phone.js.map +1 -1
- package/cjs/validators/utils/postal_code.js.map +1 -1
- package/cjs/validators/utils/text_limit.js.map +1 -1
- package/hooks/useFieldFocusManager/index.js +116 -0
- package/hooks/useFieldFocusManager/package.json +6 -0
- package/hooks/useFieldFocusManager.d.ts +25 -0
- package/hooks/useFieldFocusManager.js.map +7 -0
- package/hooks/utils/index.js +73 -0
- package/{Field → hooks}/utils/package.json +1 -1
- package/hooks/utils.d.ts +18 -0
- package/hooks/utils.js.map +7 -0
- package/index.js +1 -1
- package/inputs/AutoCompleteInput/index.d.ts +3 -3
- package/inputs/AutoCompleteInput/index.js +1 -3
- package/inputs/AutoCompleteInput/index.js.map +2 -2
- package/inputs/Checkboxes/index.d.ts +3 -3
- package/inputs/Checkboxes/index.js +67 -63
- package/inputs/Checkboxes/index.js.map +2 -2
- package/inputs/DateInput/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 +1 -4
- package/inputs/FileInput/index.js.map +2 -2
- package/inputs/ImageInput/index.d.ts +2 -2
- package/inputs/ImageInput/index.js.map +1 -1
- package/inputs/Input/index.d.ts +2 -2
- package/inputs/Input/index.js +54 -56
- package/inputs/Input/index.js.map +2 -2
- package/inputs/Label/index.d.ts +1 -1
- package/inputs/Label/index.js.map +1 -1
- package/inputs/OtpInput/index.d.ts +1 -5
- package/inputs/OtpInput/index.js +36 -31
- package/inputs/OtpInput/index.js.map +2 -2
- package/inputs/Radio/index.d.ts +4 -4
- package/inputs/Radio/index.js +5 -4
- package/inputs/Radio/index.js.map +3 -3
- package/inputs/Select/index.d.ts +2 -2
- package/inputs/Select/index.js.map +1 -1
- package/{Field/utils → inputs/registry}/index.js +1 -1
- package/{locales/el → inputs/registry}/package.json +1 -1
- package/{Field/utils/index.d.ts → inputs/registry.d.ts} +2 -1
- package/inputs/registry.js.map +7 -0
- package/lazy/index.js +10 -9
- package/package.json +4 -4
- package/registry/index.js +23 -13
- package/src/Field/ErrorGroup.tsx +3 -3
- package/src/Field/FieldBase.tsx +1 -2
- package/src/Field/FieldBaseContainer.tsx +68 -58
- package/src/Field/FieldConditional.tsx +1 -1
- package/src/Field/index.tsx +15 -33
- 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/FormDialog/ArrayDisplay/ArrayDisplay.stories.js +11 -0
- package/src/FieldArray/FormDialog/ArrayDisplay/ArrayItemDisplay.tsx +165 -0
- package/src/FieldArray/FormDialog/ArrayDisplay/ArrayItemHeader.tsx +15 -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__/Sortable.tsx +93 -0
- package/src/FieldArray/FormDialog/ArrayDisplay/index.tsx +75 -0
- package/src/FieldArray/FormDialog/ArrayEditModal.tsx +233 -0
- package/src/FieldArray/FormDialog/index.tsx +247 -0
- package/src/FieldArray/__tests__/fieldset-multiplicity.spec.tsx +271 -0
- package/src/FieldArray/__tests__/multiplicity-attachment.spec.tsx +280 -0
- package/src/FieldArray/__tests__/multiplicity-required.spec.tsx +131 -0
- package/src/FieldArray/__tests__/nested-fieldset-multiplicity.spec.tsx +627 -0
- package/src/FieldArray/__tests__/preference-multiple-choice.spec.tsx +222 -0
- package/src/FieldArray/index.spec.tsx +355 -0
- package/src/FieldArray/index.tsx +34 -61
- package/src/FieldObject/index.tsx +9 -17
- package/src/Fieldset/FieldsetWithContext.tsx +1 -1
- package/src/Fieldset/index.tsx +1 -1
- package/src/Fieldset/types.tsx +2 -2
- package/src/FormBuilder/index.tsx +188 -142
- package/src/FormBuilder/scenarios.test.tsx +759 -1
- package/src/FormContext.tsx +3 -2
- package/src/MultiplicityField/add-objects.tsx +12 -21
- package/src/MultiplicityField/index.tsx +3 -2
- package/src/MultiplicityField/types.ts +5 -2
- package/src/Questions/Questions.tsx +2 -2
- package/src/Questions/QuestionsContext.tsx +1 -1
- package/src/Questions/Step/Step.tsx +1 -1
- package/src/Questions/Step/StepArrayReview.tsx +2 -2
- package/src/Questions/Step/StepContext.tsx +1 -1
- package/src/Questions/Step/StepDescription.tsx +2 -1
- package/src/Questions/Step/StepForm.tsx +2 -2
- package/src/Questions/Step/StepQuote.tsx +2 -1
- package/src/Questions/Step/StepTitle.tsx +2 -1
- package/src/Questions/Step/getAddMoreFields.tsx +2 -2
- package/src/Questions/Step/types.tsx +1 -1
- package/src/Questions/getNextStep.tsx +1 -1
- package/src/Questions/types.tsx +1 -1
- package/src/hooks/__tests__/useFieldFocusManager.spec.tsx +1079 -0
- package/src/hooks/__tests__/utils.spec.ts +568 -0
- package/src/hooks/useFieldFocusManager.ts +162 -0
- package/src/hooks/utils.ts +122 -0
- package/src/inputs/AutoCompleteInput/index.tsx +4 -6
- package/src/inputs/Checkboxes/index.tsx +95 -87
- package/src/inputs/DateInput/index.tsx +19 -6
- package/src/inputs/DateTimeInput/index.tsx +19 -6
- package/src/inputs/FileInput/index.tsx +9 -7
- package/src/inputs/ImageInput/index.tsx +2 -2
- package/src/inputs/Input/index.tsx +72 -71
- package/src/inputs/Label/index.tsx +1 -1
- package/src/inputs/OtpInput/index.tsx +43 -34
- package/src/inputs/Radio/index.tsx +29 -21
- package/src/inputs/Select/index.tsx +2 -2
- package/src/{Field/utils/index.ts → inputs/registry.ts} +3 -1
- package/src/lazy.js +10 -9
- package/src/registry.js +23 -13
- package/src/types.tsx +12 -5
- package/src/utils.ts +3 -2
- package/src/validators/index.ts +10 -9
- 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/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 +8 -4
- package/types.js.map +1 -1
- package/utils.d.ts +1 -1
- package/utils.js.map +2 -2
- package/validators/index.d.ts +5 -5
- package/validators/index.js.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/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
package/Field/ErrorGroup.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { ErrorOption } from 'react-hook-form';
|
|
3
|
-
import { FieldLabelProps } from '@digigov/form/Field/types';
|
|
4
|
-
import { Breakpoints } from '@digigov/ui/utils/hooks/useScreen';
|
|
2
|
+
import type { ErrorOption } from 'react-hook-form';
|
|
3
|
+
import type { FieldLabelProps } from '@digigov/form/Field/types';
|
|
4
|
+
import type { Breakpoints } from '@digigov/ui/utils/hooks/useScreen';
|
|
5
5
|
interface ErrorGroupContextType {
|
|
6
6
|
setError: (name?: string, label?: FieldLabelProps, error?: ErrorOption) => void;
|
|
7
7
|
}
|
package/Field/ErrorGroup.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Field/ErrorGroup.tsx"],
|
|
4
|
-
"sourcesContent": ["import React, { createContext, useEffect, useState } from 'react';\nimport { ErrorOption } from 'react-hook-form';\nimport { FieldLabelProps } from '@digigov/form/Field/types';\nimport { List, ListItem } from '@digigov/ui/content/List';\nimport { ErrorSummary } from '@digigov/ui/feedback/ErrorSummary';\nimport { useTranslation } from '@digigov/ui/i18n';\nimport { Link } from '@digigov/ui/navigation/Link';\nimport { Heading } from '@digigov/ui/typography/Heading';\nimport { Base } from '@digigov/ui/utils/Base';\nimport { Breakpoints } from '@digigov/ui/utils/hooks/useScreen';\ninterface ErrorGroupContextType {\n setError: (\n name?: string,\n label?: FieldLabelProps,\n error?: ErrorOption\n ) => void;\n}\nexport const ErrorGroupContext = createContext<ErrorGroupContextType | null>(\n null\n);\n\nexport interface ErrorGroupProps {\n children: React.ReactNode;\n screenSize?: Breakpoints | undefined;\n fieldOrder?: any[];\n}\n\nexport const ErrorGroup: React.FC<ErrorGroupProps> = ({\n children,\n screenSize,\n fieldOrder,\n}) => {\n const [errors, setErrors] = useState<ErrorOption>({});\n const { t } = useTranslation();\n const setError = (name, label, error) => {\n if (errors[name] !== error && errors[name]?.message !== error?.message) {\n if (!error?.message) {\n const updatedErrors = { ...errors };\n delete updatedErrors[name];\n setErrors(updatedErrors);\n } else {\n setErrors({\n ...errors,\n [name]: {\n ...error,\n label: label.primary,\n },\n });\n }\n }\n };\n\n useEffect(() => {\n setErrors({});\n }, [screenSize]);\n return (\n <ErrorGroupContext.Provider value={{ setError }}>\n {Object.keys(errors).length !== 0 && (\n <ErrorSummary variant=\"error-group\">\n <Heading size=\"sm\">\n \u03A4\u03B1 \u03C0\u03B1\u03C1\u03B1\u03BA\u03AC\u03C4\u03C9 \u03C0\u03B5\u03B4\u03AF\u03B1 \u03C4\u03B7\u03C2 \u03C6\u03CC\u03C1\u03BC\u03B1\u03C2 \u03B5\u03B9\u03BD\u03B1\u03B9 \u03BB\u03AC\u03B8\u03BF\u03C2.{' '}\n </Heading>\n <List listStyle=\"bullet\">\n {(fieldOrder || Object.keys(errors).reverse())\n .filter((fieldName) => errors[fieldName])\n .map((fieldName, index) => {\n return (\n <ListItem key={index} id={`${fieldName}-error`}>\n <Base as=\"b\">{t(errors[fieldName]?.label)}:</Base>{' '}\n <Link href={`#${fieldName}`}>\n {t(errors[fieldName]?.message)}\n </Link>\n </ListItem>\n );\n })}\n </List>\n </ErrorSummary>\n )}\n {children}\n </ErrorGroupContext.Provider>\n );\n};\n\nexport default ErrorGroup;\n"],
|
|
4
|
+
"sourcesContent": ["import React, { createContext, useEffect, useState } from 'react';\nimport type { ErrorOption } from 'react-hook-form';\nimport type { FieldLabelProps } from '@digigov/form/Field/types';\nimport { List, ListItem } from '@digigov/ui/content/List';\nimport { ErrorSummary } from '@digigov/ui/feedback/ErrorSummary';\nimport { useTranslation } from '@digigov/ui/i18n';\nimport { Link } from '@digigov/ui/navigation/Link';\nimport { Heading } from '@digigov/ui/typography/Heading';\nimport { Base } from '@digigov/ui/utils/Base';\nimport type { Breakpoints } from '@digigov/ui/utils/hooks/useScreen';\ninterface ErrorGroupContextType {\n setError: (\n name?: string,\n label?: FieldLabelProps,\n error?: ErrorOption\n ) => void;\n}\nexport const ErrorGroupContext = createContext<ErrorGroupContextType | null>(\n null\n);\n\nexport interface ErrorGroupProps {\n children: React.ReactNode;\n screenSize?: Breakpoints | undefined;\n fieldOrder?: any[];\n}\n\nexport const ErrorGroup: React.FC<ErrorGroupProps> = ({\n children,\n screenSize,\n fieldOrder,\n}) => {\n const [errors, setErrors] = useState<ErrorOption>({});\n const { t } = useTranslation();\n const setError = (name, label, error) => {\n if (errors[name] !== error && errors[name]?.message !== error?.message) {\n if (!error?.message) {\n const updatedErrors = { ...errors };\n delete updatedErrors[name];\n setErrors(updatedErrors);\n } else {\n setErrors({\n ...errors,\n [name]: {\n ...error,\n label: label.primary,\n },\n });\n }\n }\n };\n\n useEffect(() => {\n setErrors({});\n }, [screenSize]);\n return (\n <ErrorGroupContext.Provider value={{ setError }}>\n {Object.keys(errors).length !== 0 && (\n <ErrorSummary variant=\"error-group\">\n <Heading size=\"sm\">\n \u03A4\u03B1 \u03C0\u03B1\u03C1\u03B1\u03BA\u03AC\u03C4\u03C9 \u03C0\u03B5\u03B4\u03AF\u03B1 \u03C4\u03B7\u03C2 \u03C6\u03CC\u03C1\u03BC\u03B1\u03C2 \u03B5\u03B9\u03BD\u03B1\u03B9 \u03BB\u03AC\u03B8\u03BF\u03C2.{' '}\n </Heading>\n <List listStyle=\"bullet\">\n {(fieldOrder || Object.keys(errors).reverse())\n .filter((fieldName) => errors[fieldName])\n .map((fieldName, index) => {\n return (\n <ListItem key={index} id={`${fieldName}-error`}>\n <Base as=\"b\">{t(errors[fieldName]?.label)}:</Base>{' '}\n <Link href={`#${fieldName}`}>\n {t(errors[fieldName]?.message)}\n </Link>\n </ListItem>\n );\n })}\n </List>\n </ErrorSummary>\n )}\n {children}\n </ErrorGroupContext.Provider>\n );\n};\n\nexport default ErrorGroup;\n"],
|
|
5
5
|
"mappings": "AAAA,OAAO,SAAS,eAAe,WAAW,gBAAgB;AAG1D,SAAS,MAAM,gBAAgB;AAC/B,SAAS,oBAAoB;AAC7B,SAAS,sBAAsB;AAC/B,SAAS,YAAY;AACrB,SAAS,eAAe;AACxB,SAAS,YAAY;AASd,MAAM,oBAAoB;AAAA,EAC/B;AACF;AAQO,MAAM,aAAwC,CAAC;AAAA,EACpD;AAAA,EACA;AAAA,EACA;AACF,MAAM;AACJ,QAAM,CAAC,QAAQ,SAAS,IAAI,SAAsB,CAAC,CAAC;AACpD,QAAM,EAAE,EAAE,IAAI,eAAe;AAC7B,QAAM,WAAW,CAAC,MAAM,OAAO,UAAU;AACvC,QAAI,OAAO,IAAI,MAAM,SAAS,OAAO,IAAI,GAAG,YAAY,OAAO,SAAS;AACtE,UAAI,CAAC,OAAO,SAAS;AACnB,cAAM,gBAAgB,EAAE,GAAG,OAAO;AAClC,eAAO,cAAc,IAAI;AACzB,kBAAU,aAAa;AAAA,MACzB,OAAO;AACL,kBAAU;AAAA,UACR,GAAG;AAAA,UACH,CAAC,IAAI,GAAG;AAAA,YACN,GAAG;AAAA,YACH,OAAO,MAAM;AAAA,UACf;AAAA,QACF,CAAC;AAAA,MACH;AAAA,IACF;AAAA,EACF;AAEA,YAAU,MAAM;AACd,cAAU,CAAC,CAAC;AAAA,EACd,GAAG,CAAC,UAAU,CAAC;AACf,SACE,oCAAC,kBAAkB,UAAlB,EAA2B,OAAO,EAAE,SAAS,KAC3C,OAAO,KAAK,MAAM,EAAE,WAAW,KAC9B,oCAAC,gBAAa,SAAQ,iBACpB,oCAAC,WAAQ,MAAK,QAAK,uNACyB,GAC5C,GACA,oCAAC,QAAK,WAAU,aACZ,cAAc,OAAO,KAAK,MAAM,EAAE,QAAQ,GACzC,OAAO,CAAC,cAAc,OAAO,SAAS,CAAC,EACvC,IAAI,CAAC,WAAW,UAAU;AACzB,WACE,oCAAC,YAAS,KAAK,OAAO,IAAI,GAAG,SAAS,YACpC,oCAAC,QAAK,IAAG,OAAK,EAAE,OAAO,SAAS,GAAG,KAAK,GAAE,GAAC,GAAQ,KACnD,oCAAC,QAAK,MAAM,IAAI,SAAS,MACtB,EAAE,OAAO,SAAS,GAAG,OAAO,CAC/B,CACF;AAAA,EAEJ,CAAC,CACL,CACF,GAED,QACH;AAEJ;AAEA,IAAO,qBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/Field/FieldBase/index.js
CHANGED
package/Field/FieldBase.d.ts
CHANGED
package/Field/FieldBase.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Field/FieldBase.tsx"],
|
|
4
|
-
"sourcesContent": ["import React, { useContext, useEffect } from 'react';\nimport { Controller } from 'react-hook-form';\nimport { ErrorGroupContext } from '@digigov/form/Field/ErrorGroup';\nimport FieldBaseContainer from '@digigov/form/Field/FieldBaseContainer';\nimport { FieldBaseProps } from '@digigov/form/Field/types';\n\nexport const FieldBase: React.FC<FieldBaseProps> = ({\n required,\n name,\n component: Component,\n wrapper,\n control,\n type,\n controlled = false,\n enabled = true,\n editable,\n defaultValue,\n label,\n extra = {},\n layout,\n error,\n register,\n ...componentProps\n}) => {\n const errorGroupContext = useContext(ErrorGroupContext);\n\n useEffect(() => {\n if (errorGroupContext) {\n errorGroupContext.setError(name, label, error);\n }\n }, [error, name, errorGroupContext?.setError]);\n\n if (!enabled) {\n return null;\n }\n\n if (controlled) {\n return (\n <FieldBaseContainer\n label={label}\n layout={layout}\n register={register}\n error={errorGroupContext ? undefined : error}\n hasError={!!error}\n wrapper={wrapper}\n name={name}\n controlled={controlled}\n >\n <Controller\n control={control}\n name={name}\n render={({ field }) => {\n return (\n <Component\n {...field}\n control={control}\n
|
|
5
|
-
"mappings": "AAAA,OAAO,SAAS,YAAY,iBAAiB;AAC7C,SAAS,kBAAkB;AAC3B,SAAS,yBAAyB;AAClC,OAAO,wBAAwB;AAGxB,MAAM,YAAsC,CAAC;AAAA,EAClD;AAAA,EACA;AAAA,EACA,WAAW;AAAA,EACX;AAAA,EACA;AAAA,EACA;AAAA,EACA,aAAa;AAAA,EACb,UAAU;AAAA,EACV;AAAA,EACA;AAAA,EACA;AAAA,EACA,QAAQ,CAAC;AAAA,EACT;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,MAAM;AACJ,QAAM,oBAAoB,WAAW,iBAAiB;AAEtD,YAAU,MAAM;AACd,QAAI,mBAAmB;AACrB,wBAAkB,SAAS,MAAM,OAAO,KAAK;AAAA,IAC/C;AAAA,EACF,GAAG,CAAC,OAAO,MAAM,mBAAmB,QAAQ,CAAC;AAE7C,MAAI,CAAC,SAAS;AACZ,WAAO;AAAA,EACT;AAEA,MAAI,YAAY;AACd,WACE;AAAA,MAAC;AAAA;AAAA,QACC;AAAA,QACA;AAAA,QACA;AAAA,QACA,OAAO,oBAAoB,SAAY;AAAA,QACvC,UAAU,CAAC,CAAC;AAAA,QACZ;AAAA,QACA;AAAA,QACA;AAAA;AAAA,MAEA;AAAA,QAAC;AAAA;AAAA,UACC;AAAA,UACA;AAAA,UACA,QAAQ,CAAC,EAAE,MAAM,MAAM;AACrB,mBACE;AAAA,cAAC;AAAA;AAAA,gBACE,GAAG;AAAA,gBACJ;AAAA,gBACA,
|
|
4
|
+
"sourcesContent": ["import React, { useContext, useEffect } from 'react';\nimport { Controller } from 'react-hook-form';\nimport { ErrorGroupContext } from '@digigov/form/Field/ErrorGroup';\nimport FieldBaseContainer from '@digigov/form/Field/FieldBaseContainer';\nimport type { FieldBaseProps } from '@digigov/form/Field/types';\n\nexport const FieldBase: React.FC<FieldBaseProps> = ({\n required,\n name,\n component: Component,\n wrapper,\n control,\n type,\n controlled = false,\n enabled = true,\n editable,\n defaultValue,\n label,\n extra = {},\n layout,\n error,\n register,\n ...componentProps\n}) => {\n const errorGroupContext = useContext(ErrorGroupContext);\n\n useEffect(() => {\n if (errorGroupContext) {\n errorGroupContext.setError(name, label, error);\n }\n }, [error, name, errorGroupContext?.setError]);\n\n if (!enabled) {\n return null;\n }\n\n if (controlled) {\n return (\n <FieldBaseContainer\n label={label}\n layout={layout}\n register={register}\n error={errorGroupContext ? undefined : error}\n hasError={!!error}\n wrapper={wrapper}\n name={name}\n controlled={controlled}\n >\n <Controller\n control={control}\n name={name}\n render={({ field }) => {\n return (\n <Component\n {...field}\n control={control}\n defaultValue={defaultValue ?? field.value}\n extra={extra}\n error={!!error}\n type={type}\n aria-required={!!required}\n aria-describedby={error && `${name}-error`}\n required={required}\n disabled={editable === false}\n {...componentProps}\n />\n );\n }}\n />\n </FieldBaseContainer>\n );\n }\n\n return (\n <FieldBaseContainer\n label={label}\n layout={layout}\n register={register}\n error={errorGroupContext ? undefined : error}\n hasError={!!error}\n wrapper={wrapper}\n name={name}\n >\n {Component?.render ? (\n <Component\n {...register(name)}\n control={control}\n error={!!error}\n extra={extra}\n type={type}\n aria-required={!!required}\n aria-describedby={error && `${name}-error`}\n required={required}\n disabled={editable === false}\n defaultValue={defaultValue}\n {...componentProps}\n />\n ) : (\n <Component\n {...register(name)}\n register={register}\n control={control}\n error={!!error}\n extra={extra}\n type={type}\n defaultValue={defaultValue}\n aria-required={!!required}\n aria-describedby={error && `${name}-error`}\n required={required}\n disabled={editable === false}\n {...componentProps}\n />\n )}\n </FieldBaseContainer>\n );\n};\n"],
|
|
5
|
+
"mappings": "AAAA,OAAO,SAAS,YAAY,iBAAiB;AAC7C,SAAS,kBAAkB;AAC3B,SAAS,yBAAyB;AAClC,OAAO,wBAAwB;AAGxB,MAAM,YAAsC,CAAC;AAAA,EAClD;AAAA,EACA;AAAA,EACA,WAAW;AAAA,EACX;AAAA,EACA;AAAA,EACA;AAAA,EACA,aAAa;AAAA,EACb,UAAU;AAAA,EACV;AAAA,EACA;AAAA,EACA;AAAA,EACA,QAAQ,CAAC;AAAA,EACT;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,MAAM;AACJ,QAAM,oBAAoB,WAAW,iBAAiB;AAEtD,YAAU,MAAM;AACd,QAAI,mBAAmB;AACrB,wBAAkB,SAAS,MAAM,OAAO,KAAK;AAAA,IAC/C;AAAA,EACF,GAAG,CAAC,OAAO,MAAM,mBAAmB,QAAQ,CAAC;AAE7C,MAAI,CAAC,SAAS;AACZ,WAAO;AAAA,EACT;AAEA,MAAI,YAAY;AACd,WACE;AAAA,MAAC;AAAA;AAAA,QACC;AAAA,QACA;AAAA,QACA;AAAA,QACA,OAAO,oBAAoB,SAAY;AAAA,QACvC,UAAU,CAAC,CAAC;AAAA,QACZ;AAAA,QACA;AAAA,QACA;AAAA;AAAA,MAEA;AAAA,QAAC;AAAA;AAAA,UACC;AAAA,UACA;AAAA,UACA,QAAQ,CAAC,EAAE,MAAM,MAAM;AACrB,mBACE;AAAA,cAAC;AAAA;AAAA,gBACE,GAAG;AAAA,gBACJ;AAAA,gBACA,cAAc,gBAAgB,MAAM;AAAA,gBACpC;AAAA,gBACA,OAAO,CAAC,CAAC;AAAA,gBACT;AAAA,gBACA,iBAAe,CAAC,CAAC;AAAA,gBACjB,oBAAkB,SAAS,GAAG,IAAI;AAAA,gBAClC;AAAA,gBACA,UAAU,aAAa;AAAA,gBACtB,GAAG;AAAA;AAAA,YACN;AAAA,UAEJ;AAAA;AAAA,MACF;AAAA,IACF;AAAA,EAEJ;AAEA,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA;AAAA,MACA;AAAA,MACA,OAAO,oBAAoB,SAAY;AAAA,MACvC,UAAU,CAAC,CAAC;AAAA,MACZ;AAAA,MACA;AAAA;AAAA,IAEC,WAAW,SACV;AAAA,MAAC;AAAA;AAAA,QACE,GAAG,SAAS,IAAI;AAAA,QACjB;AAAA,QACA,OAAO,CAAC,CAAC;AAAA,QACT;AAAA,QACA;AAAA,QACA,iBAAe,CAAC,CAAC;AAAA,QACjB,oBAAkB,SAAS,GAAG,IAAI;AAAA,QAClC;AAAA,QACA,UAAU,aAAa;AAAA,QACvB;AAAA,QACC,GAAG;AAAA;AAAA,IACN,IAEA;AAAA,MAAC;AAAA;AAAA,QACE,GAAG,SAAS,IAAI;AAAA,QACjB;AAAA,QACA;AAAA,QACA,OAAO,CAAC,CAAC;AAAA,QACT;AAAA,QACA;AAAA,QACA;AAAA,QACA,iBAAe,CAAC,CAAC;AAAA,QACjB,oBAAkB,SAAS,GAAG,IAAI;AAAA,QAClC;AAAA,QACA,UAAU,aAAa;AAAA,QACtB,GAAG;AAAA;AAAA,IACN;AAAA,EAEJ;AAEJ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -7,41 +7,43 @@ import FieldsetLegend from "@digigov/react-core/FieldsetLegend";
|
|
|
7
7
|
import LabelContainer from "@digigov/react-core/LabelContainer";
|
|
8
8
|
import { useTranslation } from "@digigov/ui/i18n";
|
|
9
9
|
import { Hint } from "@digigov/ui/typography/Hint";
|
|
10
|
-
const FieldBaseContainer = (
|
|
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
|
-
|
|
10
|
+
const FieldBaseContainer = React.forwardRef(
|
|
11
|
+
({
|
|
12
|
+
name,
|
|
13
|
+
wrapper,
|
|
14
|
+
label,
|
|
15
|
+
children,
|
|
16
|
+
error,
|
|
17
|
+
hasError,
|
|
18
|
+
layout,
|
|
19
|
+
controlled,
|
|
20
|
+
labelSize = "sm"
|
|
21
|
+
}, ref) => {
|
|
22
|
+
const { t } = useTranslation();
|
|
23
|
+
const errorMessage = error?.message.key ? error.message.key : error?.message || "";
|
|
24
|
+
const errorContext = error?.message.context || {};
|
|
25
|
+
if (wrapper === "fieldset") {
|
|
26
|
+
return /* @__PURE__ */ React.createElement(FieldContainer, { error: hasError, ...layout }, /* @__PURE__ */ React.createElement(
|
|
27
|
+
Fieldset,
|
|
28
|
+
{
|
|
29
|
+
ref,
|
|
30
|
+
className: "outline-none",
|
|
31
|
+
...controlled && {
|
|
32
|
+
tabIndex: -1
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
/* @__PURE__ */ React.createElement(FieldsetLegend, { size: labelSize }, label && label.primary),
|
|
36
|
+
label && label.secondary && /* @__PURE__ */ React.createElement(Hint, null, t(label.secondary)),
|
|
37
|
+
error && /* @__PURE__ */ React.createElement(ErrorMessage, { id: `${name}-error` }, t(errorMessage, errorContext)),
|
|
38
|
+
children,
|
|
39
|
+
label && label.hint && /* @__PURE__ */ React.createElement(Hint, { size: "sm" }, label.hint)
|
|
40
|
+
));
|
|
41
|
+
} else {
|
|
42
|
+
return /* @__PURE__ */ React.createElement(FieldContainer, { error: hasError, ...layout }, /* @__PURE__ */ React.createElement(LabelContainer, null, label && /* @__PURE__ */ React.createElement(Label, { label }), error && /* @__PURE__ */ React.createElement(ErrorMessage, { id: `${name}-error` }, t(errorMessage, errorContext)), children, label && label.hint && /* @__PURE__ */ React.createElement(Hint, { size: "sm" }, label.hint)));
|
|
43
|
+
}
|
|
43
44
|
}
|
|
44
|
-
|
|
45
|
+
);
|
|
46
|
+
FieldBaseContainer.displayName = "FieldBaseContainer";
|
|
45
47
|
var FieldBaseContainer_default = FieldBaseContainer;
|
|
46
48
|
export {
|
|
47
49
|
FieldBaseContainer,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { FieldContainerProps } from '@digigov/form/Field/types';
|
|
3
|
-
export declare const FieldBaseContainer: React.
|
|
2
|
+
import type { FieldContainerProps } from '@digigov/form/Field/types';
|
|
3
|
+
export declare const FieldBaseContainer: React.ForwardRefExoticComponent<FieldContainerProps & React.RefAttributes<HTMLFieldSetElement>>;
|
|
4
4
|
export default FieldBaseContainer;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Field/FieldBaseContainer.tsx"],
|
|
4
|
-
"sourcesContent": ["import React from 'react';\nimport { FieldContainerProps } from '@digigov/form/Field/types';\nimport Label from '@digigov/form/inputs/Label';\nimport { ErrorMessage } from '@digigov/react-core/ErrorMessage';\nimport FieldContainer from '@digigov/react-core/FieldContainer';\nimport Fieldset from '@digigov/react-core/Fieldset';\nimport FieldsetLegend from '@digigov/react-core/FieldsetLegend';\nimport LabelContainer from '@digigov/react-core/LabelContainer';\nimport { useTranslation } from '@digigov/ui/i18n';\nimport { Hint } from '@digigov/ui/typography/Hint';\n\nexport const FieldBaseContainer
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import type { ComponentRef } from 'react';\nimport React from 'react';\nimport type { FieldContainerProps } from '@digigov/form/Field/types';\nimport Label from '@digigov/form/inputs/Label';\nimport { ErrorMessage } from '@digigov/react-core/ErrorMessage';\nimport FieldContainer from '@digigov/react-core/FieldContainer';\nimport Fieldset from '@digigov/react-core/Fieldset';\nimport FieldsetLegend from '@digigov/react-core/FieldsetLegend';\nimport LabelContainer from '@digigov/react-core/LabelContainer';\nimport { useTranslation } from '@digigov/ui/i18n';\nimport { Hint } from '@digigov/ui/typography/Hint';\n\nexport const FieldBaseContainer = React.forwardRef<\n ComponentRef<typeof Fieldset>,\n FieldContainerProps\n>(\n (\n {\n name,\n wrapper,\n label,\n children,\n error,\n hasError,\n layout,\n controlled,\n labelSize = 'sm',\n },\n ref\n ) => {\n const { t } = useTranslation();\n const errorMessage = error?.message.key\n ? error.message.key\n : error?.message || '';\n const errorContext = error?.message.context || {};\n if (wrapper === 'fieldset') {\n return (\n <FieldContainer error={hasError} {...layout}>\n <Fieldset\n ref={ref}\n className=\"outline-none\"\n {...(controlled && {\n tabIndex: -1,\n })}\n >\n <FieldsetLegend size={labelSize}>\n {label && label.primary}\n </FieldsetLegend>\n {label && label.secondary && <Hint>{t(label.secondary)}</Hint>}\n {error && (\n <ErrorMessage id={`${name}-error`}>\n {t(errorMessage, errorContext)}\n </ErrorMessage>\n )}\n {children}\n {label && label.hint && <Hint size=\"sm\">{label.hint}</Hint>}\n </Fieldset>\n </FieldContainer>\n );\n } else {\n return (\n <FieldContainer error={hasError} {...layout}>\n <LabelContainer>\n {label && <Label label={label} />}\n {error && (\n <ErrorMessage id={`${name}-error`}>\n {t(errorMessage, errorContext)}\n </ErrorMessage>\n )}\n {children}\n {label && label.hint && <Hint size=\"sm\">{label.hint}</Hint>}\n </LabelContainer>\n </FieldContainer>\n );\n }\n }\n);\n\nFieldBaseContainer.displayName = 'FieldBaseContainer';\n\nexport default FieldBaseContainer;\n"],
|
|
5
|
+
"mappings": "AACA,OAAO,WAAW;AAElB,OAAO,WAAW;AAClB,SAAS,oBAAoB;AAC7B,OAAO,oBAAoB;AAC3B,OAAO,cAAc;AACrB,OAAO,oBAAoB;AAC3B,OAAO,oBAAoB;AAC3B,SAAS,sBAAsB;AAC/B,SAAS,YAAY;AAEd,MAAM,qBAAqB,MAAM;AAAA,EAItC,CACE;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,YAAY;AAAA,EACd,GACA,QACG;AACH,UAAM,EAAE,EAAE,IAAI,eAAe;AAC7B,UAAM,eAAe,OAAO,QAAQ,MAChC,MAAM,QAAQ,MACd,OAAO,WAAW;AACtB,UAAM,eAAe,OAAO,QAAQ,WAAW,CAAC;AAChD,QAAI,YAAY,YAAY;AAC1B,aACE,oCAAC,kBAAe,OAAO,UAAW,GAAG,UACnC;AAAA,QAAC;AAAA;AAAA,UACC;AAAA,UACA,WAAU;AAAA,UACT,GAAI,cAAc;AAAA,YACjB,UAAU;AAAA,UACZ;AAAA;AAAA,QAEA,oCAAC,kBAAe,MAAM,aACnB,SAAS,MAAM,OAClB;AAAA,QACC,SAAS,MAAM,aAAa,oCAAC,YAAM,EAAE,MAAM,SAAS,CAAE;AAAA,QACtD,SACC,oCAAC,gBAAa,IAAI,GAAG,IAAI,YACtB,EAAE,cAAc,YAAY,CAC/B;AAAA,QAED;AAAA,QACA,SAAS,MAAM,QAAQ,oCAAC,QAAK,MAAK,QAAM,MAAM,IAAK;AAAA,MACtD,CACF;AAAA,IAEJ,OAAO;AACL,aACE,oCAAC,kBAAe,OAAO,UAAW,GAAG,UACnC,oCAAC,sBACE,SAAS,oCAAC,SAAM,OAAc,GAC9B,SACC,oCAAC,gBAAa,IAAI,GAAG,IAAI,YACtB,EAAE,cAAc,YAAY,CAC/B,GAED,UACA,SAAS,MAAM,QAAQ,oCAAC,QAAK,MAAK,QAAM,MAAM,IAAK,CACtD,CACF;AAAA,IAEJ;AAAA,EACF;AACF;AAEA,mBAAmB,cAAc;AAEjC,IAAO,6BAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { FieldConditionalProps } from '@digigov/form/Field/types';
|
|
2
|
+
import type { FieldConditionalProps } from '@digigov/form/Field/types';
|
|
3
3
|
export declare const FieldConditional: React.FC<FieldConditionalProps>;
|
|
4
4
|
export default FieldConditional;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Field/FieldConditional.tsx"],
|
|
4
|
-
"sourcesContent": ["import React from 'react';\nimport { useWatch } from 'react-hook-form';\nimport { FieldBase } from '@digigov/form/Field/FieldBase';\nimport {\n ChildFieldMemoProps,\n FieldConditionalProps,\n} from '@digigov/form/Field/types';\nimport { evaluateFieldWithConditions } from '@digigov/form/Field/utils/evaluateFieldWithConditions';\n\nconst ChildFieldMemo = React.memo(\n function ChildField({\n dependencies,\n field,\n control,\n reset,\n resetField,\n register,\n error,\n Field,\n }: ChildFieldMemoProps) {\n const newField = evaluateFieldWithConditions(\n field,\n dependencies as FormData\n );\n return (\n <FieldBase\n {...newField}\n Field={Field}\n name={newField.key}\n reset={reset}\n resetField={resetField}\n control={control}\n register={register}\n error={error}\n />\n );\n },\n (prev, next) => {\n if (!prev || !prev.dependencies) {\n return false;\n }\n if (prev.error !== next.error) {\n return false;\n }\n for (const dep in next.dependencies) {\n if (next.dependencies[dep] !== prev.dependencies[dep]) {\n return false;\n }\n }\n return true;\n }\n);\n\nexport const FieldConditional: React.FC<FieldConditionalProps> = ({\n control,\n field,\n register,\n reset,\n resetField,\n error,\n Field,\n}) => {\n const dependencyKeys = Object.keys(field.condition);\n const dependencyValues = useWatch({\n name: dependencyKeys,\n control,\n });\n const variables = dependencyKeys.reduce(\n (data, fieldKey, index) => ({\n ...data,\n [fieldKey]: dependencyValues[index],\n }),\n {}\n );\n return (\n <ChildFieldMemo\n dependencies={variables}\n field={field}\n control={control}\n register={register}\n reset={reset}\n resetField={resetField}\n error={error}\n Field={Field}\n />\n );\n};\n\nexport default FieldConditional;\n"],
|
|
4
|
+
"sourcesContent": ["import React from 'react';\nimport { useWatch } from 'react-hook-form';\nimport { FieldBase } from '@digigov/form/Field/FieldBase';\nimport type {\n ChildFieldMemoProps,\n FieldConditionalProps,\n} from '@digigov/form/Field/types';\nimport { evaluateFieldWithConditions } from '@digigov/form/Field/utils/evaluateFieldWithConditions';\n\nconst ChildFieldMemo = React.memo(\n function ChildField({\n dependencies,\n field,\n control,\n reset,\n resetField,\n register,\n error,\n Field,\n }: ChildFieldMemoProps) {\n const newField = evaluateFieldWithConditions(\n field,\n dependencies as FormData\n );\n return (\n <FieldBase\n {...newField}\n Field={Field}\n name={newField.key}\n reset={reset}\n resetField={resetField}\n control={control}\n register={register}\n error={error}\n />\n );\n },\n (prev, next) => {\n if (!prev || !prev.dependencies) {\n return false;\n }\n if (prev.error !== next.error) {\n return false;\n }\n for (const dep in next.dependencies) {\n if (next.dependencies[dep] !== prev.dependencies[dep]) {\n return false;\n }\n }\n return true;\n }\n);\n\nexport const FieldConditional: React.FC<FieldConditionalProps> = ({\n control,\n field,\n register,\n reset,\n resetField,\n error,\n Field,\n}) => {\n const dependencyKeys = Object.keys(field.condition);\n const dependencyValues = useWatch({\n name: dependencyKeys,\n control,\n });\n const variables = dependencyKeys.reduce(\n (data, fieldKey, index) => ({\n ...data,\n [fieldKey]: dependencyValues[index],\n }),\n {}\n );\n return (\n <ChildFieldMemo\n dependencies={variables}\n field={field}\n control={control}\n register={register}\n reset={reset}\n resetField={resetField}\n error={error}\n Field={Field}\n />\n );\n};\n\nexport default FieldConditional;\n"],
|
|
5
5
|
"mappings": "AAAA,OAAO,WAAW;AAClB,SAAS,gBAAgB;AACzB,SAAS,iBAAiB;AAK1B,SAAS,mCAAmC;AAE5C,MAAM,iBAAiB,MAAM;AAAA,EAC3B,SAAS,WAAW;AAAA,IAClB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAAwB;AACtB,UAAM,WAAW;AAAA,MACf;AAAA,MACA;AAAA,IACF;AACA,WACE;AAAA,MAAC;AAAA;AAAA,QACE,GAAG;AAAA,QACJ;AAAA,QACA,MAAM,SAAS;AAAA,QACf;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA;AAAA,IACF;AAAA,EAEJ;AAAA,EACA,CAAC,MAAM,SAAS;AACd,QAAI,CAAC,QAAQ,CAAC,KAAK,cAAc;AAC/B,aAAO;AAAA,IACT;AACA,QAAI,KAAK,UAAU,KAAK,OAAO;AAC7B,aAAO;AAAA,IACT;AACA,eAAW,OAAO,KAAK,cAAc;AACnC,UAAI,KAAK,aAAa,GAAG,MAAM,KAAK,aAAa,GAAG,GAAG;AACrD,eAAO;AAAA,MACT;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACF;AAEO,MAAM,mBAAoD,CAAC;AAAA,EAChE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAAM;AACJ,QAAM,iBAAiB,OAAO,KAAK,MAAM,SAAS;AAClD,QAAM,mBAAmB,SAAS;AAAA,IAChC,MAAM;AAAA,IACN;AAAA,EACF,CAAC;AACD,QAAM,YAAY,eAAe;AAAA,IAC/B,CAAC,MAAM,UAAU,WAAW;AAAA,MAC1B,GAAG;AAAA,MACH,CAAC,QAAQ,GAAG,iBAAiB,KAAK;AAAA,IACpC;AAAA,IACA,CAAC;AAAA,EACH;AACA,SACE;AAAA,IAAC;AAAA;AAAA,MACC,cAAc;AAAA,MACd;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA;AAAA,EACF;AAEJ;AAEA,IAAO,2BAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/Field/index.d.ts
CHANGED
package/Field/index.js
CHANGED
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
import React, { useMemo } from "react";
|
|
2
2
|
import { FieldBase } from "@digigov/form/Field/FieldBase";
|
|
3
3
|
import FieldConditional from "@digigov/form/Field/FieldConditional";
|
|
4
|
-
import {
|
|
5
|
-
FIELD_COMPONENTS,
|
|
6
|
-
ALTERNATIVE_COMPONENTS
|
|
7
|
-
} from "@digigov/form/Field/utils";
|
|
8
|
-
import { calculateField } from "@digigov/form/Field/utils/calculateField";
|
|
4
|
+
import { resolveField } from "@digigov/form/Field/utils/resolveField";
|
|
9
5
|
import { useField } from "@digigov/form/Field/utils/useField";
|
|
10
6
|
import FieldArray from "@digigov/form/FieldArray";
|
|
11
7
|
import Multiplicity from "@digigov/form/MultiplicityField";
|
|
@@ -27,21 +23,14 @@ const Field = ({
|
|
|
27
23
|
getValues,
|
|
28
24
|
unregister,
|
|
29
25
|
trigger,
|
|
30
|
-
clearErrors
|
|
26
|
+
clearErrors,
|
|
27
|
+
registerFieldFocus
|
|
31
28
|
} = useField(name, customField?.type ? customField : null);
|
|
32
|
-
const
|
|
33
|
-
() =>
|
|
34
|
-
children,
|
|
35
|
-
field,
|
|
36
|
-
{
|
|
37
|
-
...FIELD_COMPONENTS,
|
|
38
|
-
...componentRegistry
|
|
39
|
-
},
|
|
40
|
-
ALTERNATIVE_COMPONENTS
|
|
41
|
-
),
|
|
29
|
+
const resolvedField = useMemo(
|
|
30
|
+
() => resolveField(children, field, componentRegistry),
|
|
42
31
|
[field]
|
|
43
32
|
);
|
|
44
|
-
if (
|
|
33
|
+
if (resolvedField.condition) {
|
|
45
34
|
return /* @__PURE__ */ React.createElement(
|
|
46
35
|
FieldConditional,
|
|
47
36
|
{
|
|
@@ -49,14 +38,14 @@ const Field = ({
|
|
|
49
38
|
reset,
|
|
50
39
|
resetField,
|
|
51
40
|
register,
|
|
52
|
-
field:
|
|
41
|
+
field: resolvedField,
|
|
53
42
|
error,
|
|
54
43
|
Field
|
|
55
44
|
}
|
|
56
45
|
);
|
|
57
46
|
}
|
|
58
|
-
if (
|
|
59
|
-
|
|
47
|
+
if (resolvedField.type === "array" && !resolvedField.multiplicity) {
|
|
48
|
+
resolvedField.name = name;
|
|
60
49
|
return /* @__PURE__ */ React.createElement(
|
|
61
50
|
FieldArray,
|
|
62
51
|
{
|
|
@@ -71,12 +60,13 @@ const Field = ({
|
|
|
71
60
|
Field,
|
|
72
61
|
reset,
|
|
73
62
|
resetField,
|
|
74
|
-
|
|
63
|
+
registerFieldFocus,
|
|
64
|
+
...resolvedField
|
|
75
65
|
}
|
|
76
66
|
);
|
|
77
67
|
}
|
|
78
|
-
if (
|
|
79
|
-
|
|
68
|
+
if (resolvedField.type === "array" && resolvedField.multiplicity === true) {
|
|
69
|
+
resolvedField.name = name;
|
|
80
70
|
return /* @__PURE__ */ React.createElement(
|
|
81
71
|
Multiplicity,
|
|
82
72
|
{
|
|
@@ -91,7 +81,7 @@ const Field = ({
|
|
|
91
81
|
unregister,
|
|
92
82
|
resetField,
|
|
93
83
|
Field,
|
|
94
|
-
...
|
|
84
|
+
...resolvedField
|
|
95
85
|
}
|
|
96
86
|
);
|
|
97
87
|
}
|
|
@@ -100,7 +90,7 @@ const Field = ({
|
|
|
100
90
|
return /* @__PURE__ */ React.createElement(
|
|
101
91
|
FieldBase,
|
|
102
92
|
{
|
|
103
|
-
...
|
|
93
|
+
...resolvedField,
|
|
104
94
|
editable,
|
|
105
95
|
name,
|
|
106
96
|
control,
|
package/Field/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/Field/index.tsx"],
|
|
4
|
-
"sourcesContent": ["import React, { useMemo } from 'react';\nimport { FieldBase } from '@digigov/form/Field/FieldBase';\nimport FieldConditional from '@digigov/form/Field/FieldConditional';\nimport {
|
|
5
|
-
"mappings": "AAAA,OAAO,SAAS,eAAe;AAC/B,SAAS,iBAAiB;AAC1B,OAAO,sBAAsB;
|
|
4
|
+
"sourcesContent": ["import React, { useMemo } from 'react';\nimport { FieldBase } from '@digigov/form/Field/FieldBase';\nimport FieldConditional from '@digigov/form/Field/FieldConditional';\nimport type { FieldWithCondition, FieldProps } from '@digigov/form/Field/types';\nimport { resolveField } from '@digigov/form/Field/utils/resolveField';\nimport { useField } from '@digigov/form/Field/utils/useField';\nimport FieldArray from '@digigov/form/FieldArray';\nimport Multiplicity from '@digigov/form/MultiplicityField';\nexport const Field: React.FC<FieldProps> = ({\n name,\n children,\n ...customField\n}) => {\n const {\n field,\n control,\n register,\n reset,\n resetField,\n error,\n componentRegistry,\n formState,\n setValue,\n getValues,\n unregister,\n trigger,\n clearErrors,\n registerFieldFocus,\n } = useField(name, customField?.type ? customField : null);\n const resolvedField = useMemo(\n () => resolveField(children, field, componentRegistry),\n [field]\n );\n if (resolvedField.condition) {\n return (\n <FieldConditional\n control={control}\n reset={reset}\n resetField={resetField}\n register={register}\n field={resolvedField as FieldWithCondition}\n error={error}\n Field={Field}\n />\n );\n }\n if (resolvedField.type === 'array' && !resolvedField.multiplicity) {\n resolvedField.name = name;\n return (\n <FieldArray\n control={control}\n trigger={trigger}\n register={register}\n clearErrors={clearErrors}\n error={\n formState.isSubmitted && !formState.isSubmitting ? error : undefined\n }\n getValues={getValues}\n setValue={setValue}\n formState={formState}\n Field={Field}\n reset={reset}\n resetField={resetField}\n registerFieldFocus={registerFieldFocus}\n {...resolvedField}\n />\n );\n }\n if (resolvedField.type === 'array' && resolvedField.multiplicity === true) {\n resolvedField.name = name;\n return (\n <Multiplicity\n control={control}\n register={register}\n trigger={trigger}\n clearErrors={clearErrors}\n error={error}\n formState={formState}\n setValue={setValue}\n getValues={getValues}\n unregister={unregister}\n resetField={resetField}\n Field={Field}\n {...resolvedField}\n />\n );\n }\n const editable =\n customField.editable === false || customField.disabled === true\n ? false\n : true;\n const customError = error ? error : formState?.errors[name];\n return (\n <FieldBase\n {...resolvedField}\n editable={editable}\n name={name}\n control={control}\n register={register}\n reset={reset}\n error={customError}\n resetField={resetField}\n Field={Field}\n />\n );\n};\n\nexport default Field;\n"],
|
|
5
|
+
"mappings": "AAAA,OAAO,SAAS,eAAe;AAC/B,SAAS,iBAAiB;AAC1B,OAAO,sBAAsB;AAE7B,SAAS,oBAAoB;AAC7B,SAAS,gBAAgB;AACzB,OAAO,gBAAgB;AACvB,OAAO,kBAAkB;AAClB,MAAM,QAA8B,CAAC;AAAA,EAC1C;AAAA,EACA;AAAA,EACA,GAAG;AACL,MAAM;AACJ,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI,SAAS,MAAM,aAAa,OAAO,cAAc,IAAI;AACzD,QAAM,gBAAgB;AAAA,IACpB,MAAM,aAAa,UAAU,OAAO,iBAAiB;AAAA,IACrD,CAAC,KAAK;AAAA,EACR;AACA,MAAI,cAAc,WAAW;AAC3B,WACE;AAAA,MAAC;AAAA;AAAA,QACC;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA,OAAO;AAAA,QACP;AAAA,QACA;AAAA;AAAA,IACF;AAAA,EAEJ;AACA,MAAI,cAAc,SAAS,WAAW,CAAC,cAAc,cAAc;AACjE,kBAAc,OAAO;AACrB,WACE;AAAA,MAAC;AAAA;AAAA,QACC;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA,OACE,UAAU,eAAe,CAAC,UAAU,eAAe,QAAQ;AAAA,QAE7D;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACC,GAAG;AAAA;AAAA,IACN;AAAA,EAEJ;AACA,MAAI,cAAc,SAAS,WAAW,cAAc,iBAAiB,MAAM;AACzE,kBAAc,OAAO;AACrB,WACE;AAAA,MAAC;AAAA;AAAA,QACC;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACC,GAAG;AAAA;AAAA,IACN;AAAA,EAEJ;AACA,QAAM,WACJ,YAAY,aAAa,SAAS,YAAY,aAAa,OACvD,QACA;AACN,QAAM,cAAc,QAAQ,QAAQ,WAAW,OAAO,IAAI;AAC1D,SACE;AAAA,IAAC;AAAA;AAAA,MACE,GAAG;AAAA,MACJ;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,OAAO;AAAA,MACP;AAAA,MACA;AAAA;AAAA,EACF;AAEJ;AAEA,IAAO,gBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/Field/types.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { ErrorOption, UseFormReturn, UseFormProps } from 'react-hook-form';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import type { ErrorOption, UseFormReturn, UseFormProps } from 'react-hook-form';
|
|
3
|
+
import type { FieldComponentRegistry } from '@digigov/form/inputs/registry';
|
|
4
|
+
import type { registerFieldFocus } from '@digigov/form/types';
|
|
5
|
+
import type { ValidatorSchema } from '@digigov/form/validators/types';
|
|
6
|
+
import type { FieldsetLegendProps } from '@digigov/ui/form/FieldContainer';
|
|
7
|
+
import type { GridProps } from '@digigov/ui/layouts/Grid';
|
|
6
8
|
export interface FieldLabelProps {
|
|
7
9
|
primary?: string;
|
|
8
10
|
secondary?: string;
|
|
@@ -41,7 +43,7 @@ export interface ChildFieldMemoProps extends FieldConditionalProps {
|
|
|
41
43
|
dependencies: FormData;
|
|
42
44
|
}
|
|
43
45
|
export type FormData = UseFormProps['defaultValues'];
|
|
44
|
-
export interface FieldWithCondition extends Omit<
|
|
46
|
+
export interface FieldWithCondition extends Omit<ResolvedField, 'condition'> {
|
|
45
47
|
condition: Record<string, FieldCondition>;
|
|
46
48
|
}
|
|
47
49
|
export interface FieldConditionalProps {
|
|
@@ -70,8 +72,6 @@ export interface FieldContainerProps {
|
|
|
70
72
|
wrapper?: FieldSpec['wrapper'];
|
|
71
73
|
labelSize?: FieldsetLegendProps['size'];
|
|
72
74
|
}
|
|
73
|
-
export type FieldComponentRegistry = Record<string, FieldComponentItem>;
|
|
74
|
-
export type OmittedFieldSpec = Omit<FieldSpec, 'component'>;
|
|
75
75
|
export type UnknownValue = never | never[];
|
|
76
76
|
export interface ControlledFieldProps {
|
|
77
77
|
type?: string;
|
|
@@ -95,7 +95,7 @@ export interface UncontrolledFieldProps {
|
|
|
95
95
|
disabled?: boolean;
|
|
96
96
|
Field: React.FC<FieldProps>;
|
|
97
97
|
}
|
|
98
|
-
export interface
|
|
98
|
+
export interface ResolvedField extends Omit<FieldSpec, 'component'> {
|
|
99
99
|
name: string;
|
|
100
100
|
component: any;
|
|
101
101
|
defaultValue?: never;
|
|
@@ -103,7 +103,7 @@ export interface CalculatedField extends OmittedFieldSpec {
|
|
|
103
103
|
wrapper?: FieldComponentItem['wrapper'];
|
|
104
104
|
multiplicity?: boolean;
|
|
105
105
|
}
|
|
106
|
-
export interface FieldBaseProps extends
|
|
106
|
+
export interface FieldBaseProps extends ResolvedField {
|
|
107
107
|
control: UseFormReturn['control'];
|
|
108
108
|
register: UseFormReturn['register'];
|
|
109
109
|
reset: UseFormReturn['reset'];
|
|
@@ -129,5 +129,6 @@ export interface UseFieldProps {
|
|
|
129
129
|
trigger: UseFormReturn['trigger'];
|
|
130
130
|
clearErrors: UseFormReturn['clearErrors'];
|
|
131
131
|
error?: ErrorOption;
|
|
132
|
+
registerFieldFocus: registerFieldFocus;
|
|
132
133
|
componentRegistry?: FieldComponentRegistry;
|
|
133
134
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { FieldWithCondition,
|
|
2
|
-
export declare function evaluateFieldWithConditions(field: FieldWithCondition, variables: FormData):
|
|
1
|
+
import type { FieldWithCondition, ResolvedField } from '@digigov/form/Field/types';
|
|
2
|
+
export declare function evaluateFieldWithConditions(field: FieldWithCondition, variables: FormData): ResolvedField;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/Field/utils/evaluateFieldWithConditions.ts"],
|
|
4
|
-
"sourcesContent": ["import {
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import type {\n FieldWithCondition,\n ResolvedField,\n} from '@digigov/form/Field/types';\n\nexport function evaluateFieldWithConditions(\n field: FieldWithCondition,\n variables: FormData\n): ResolvedField {\n const newField = { ...field };\n if (variables) {\n for (const key in variables) {\n if (field.condition[key] && field.condition[key].is) {\n const is = field.condition[key].is;\n if (\n is === variables[key] ||\n (Array.isArray(variables[key]) && variables[key].includes(is))\n ) {\n const then = field.condition[key].then || {};\n for (const attr in then) {\n newField[attr] = then[attr];\n }\n }\n } else if (field.condition[key]) {\n const otherwise = field.condition[key].else || {};\n for (const attr in otherwise) {\n newField[attr] = otherwise[attr];\n }\n }\n }\n }\n return newField;\n}\n"],
|
|
5
|
+
"mappings": "AAKO,SAAS,4BACd,OACA,WACe;AACf,QAAM,WAAW,EAAE,GAAG,MAAM;AAC5B,MAAI,WAAW;AACb,eAAW,OAAO,WAAW;AAC3B,UAAI,MAAM,UAAU,GAAG,KAAK,MAAM,UAAU,GAAG,EAAE,IAAI;AACnD,cAAM,KAAK,MAAM,UAAU,GAAG,EAAE;AAChC,YACE,OAAO,UAAU,GAAG,KACnB,MAAM,QAAQ,UAAU,GAAG,CAAC,KAAK,UAAU,GAAG,EAAE,SAAS,EAAE,GAC5D;AACA,gBAAM,OAAO,MAAM,UAAU,GAAG,EAAE,QAAQ,CAAC;AAC3C,qBAAW,QAAQ,MAAM;AACvB,qBAAS,IAAI,IAAI,KAAK,IAAI;AAAA,UAC5B;AAAA,QACF;AAAA,MACF,WAAW,MAAM,UAAU,GAAG,GAAG;AAC/B,cAAM,YAAY,MAAM,UAAU,GAAG,EAAE,QAAQ,CAAC;AAChD,mBAAW,QAAQ,WAAW;AAC5B,mBAAS,IAAI,IAAI,UAAU,IAAI;AAAA,QACjC;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ALTERNATIVE_COMPONENTS,
|
|
3
|
+
FIELD_COMPONENTS
|
|
4
|
+
} from "@digigov/form/inputs/registry";
|
|
5
|
+
function resolveField(children, field, customComponentRegistry) {
|
|
6
|
+
const fieldComponentRegistry = {
|
|
7
|
+
...FIELD_COMPONENTS,
|
|
8
|
+
...customComponentRegistry ?? {}
|
|
9
|
+
};
|
|
10
|
+
const resolvedField = { ...field };
|
|
11
|
+
if (children) {
|
|
12
|
+
resolvedField.component = children;
|
|
13
|
+
resolvedField.controlled = true;
|
|
14
|
+
} else if (typeof field.component === "function") {
|
|
15
|
+
} else if (!field.component && !field.type) {
|
|
16
|
+
resolvedField.component = fieldComponentRegistry.string.component;
|
|
17
|
+
resolvedField.controlled = fieldComponentRegistry.string?.controlled || false;
|
|
18
|
+
} else if (typeof field?.extra?.component === "string" && ALTERNATIVE_COMPONENTS[field.extra.component]) {
|
|
19
|
+
resolvedField.controlled = ALTERNATIVE_COMPONENTS[field.extra.component]?.controlled || false;
|
|
20
|
+
resolvedField.component = ALTERNATIVE_COMPONENTS[field.extra.component].component;
|
|
21
|
+
resolvedField.wrapper = ALTERNATIVE_COMPONENTS[field.extra.component].wrapper;
|
|
22
|
+
} else if (!field.component && field.type && fieldComponentRegistry[field.type]) {
|
|
23
|
+
resolvedField.component = fieldComponentRegistry[field.type].component;
|
|
24
|
+
resolvedField.wrapper = fieldComponentRegistry[field.type].wrapper;
|
|
25
|
+
resolvedField.controlled = fieldComponentRegistry[field.type]?.controlled || false;
|
|
26
|
+
} else {
|
|
27
|
+
resolvedField.component = fieldComponentRegistry.string.component;
|
|
28
|
+
resolvedField.controlled = fieldComponentRegistry.string?.controlled || false;
|
|
29
|
+
}
|
|
30
|
+
return resolvedField;
|
|
31
|
+
}
|
|
32
|
+
export {
|
|
33
|
+
resolveField
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=resolveField.js.map
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { FieldProps, FieldSpec, ResolvedField } from '@digigov/form/Field/types';
|
|
2
|
+
import { type FieldComponentRegistry } from '@digigov/form/inputs/registry';
|
|
3
|
+
export declare function resolveField(children: FieldProps['children'], field: FieldSpec, customComponentRegistry?: FieldComponentRegistry): ResolvedField;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/Field/utils/resolveField.ts"],
|
|
4
|
+
"sourcesContent": ["import type {\n FieldProps,\n FieldSpec,\n ResolvedField,\n} from '@digigov/form/Field/types';\nimport {\n ALTERNATIVE_COMPONENTS,\n FIELD_COMPONENTS,\n type FieldComponentRegistry,\n} from '@digigov/form/inputs/registry';\n\nexport function resolveField(\n children: FieldProps['children'],\n field: FieldSpec,\n customComponentRegistry?: FieldComponentRegistry\n): ResolvedField {\n const fieldComponentRegistry = {\n ...FIELD_COMPONENTS,\n ...(customComponentRegistry ?? {}),\n };\n\n const resolvedField = { ...field };\n\n if (children) {\n resolvedField.component = children;\n resolvedField.controlled = true;\n } else if (typeof field.component === 'function') {\n // leave as is\n } else if (!field.component && !field.type) {\n resolvedField.component = fieldComponentRegistry.string.component;\n resolvedField.controlled =\n fieldComponentRegistry.string?.controlled || false;\n } else if (\n typeof field?.extra?.component === 'string' &&\n ALTERNATIVE_COMPONENTS[field.extra.component]\n ) {\n resolvedField.controlled =\n ALTERNATIVE_COMPONENTS[field.extra.component]?.controlled || false;\n resolvedField.component =\n ALTERNATIVE_COMPONENTS[field.extra.component].component;\n resolvedField.wrapper =\n ALTERNATIVE_COMPONENTS[field.extra.component].wrapper;\n } else if (\n !field.component &&\n field.type &&\n fieldComponentRegistry[field.type]\n ) {\n resolvedField.component = fieldComponentRegistry[field.type].component;\n resolvedField.wrapper = fieldComponentRegistry[field.type].wrapper;\n resolvedField.controlled =\n fieldComponentRegistry[field.type]?.controlled || false;\n } else {\n resolvedField.component = fieldComponentRegistry.string.component;\n resolvedField.controlled =\n fieldComponentRegistry.string?.controlled || false;\n }\n return resolvedField as ResolvedField;\n}\n"],
|
|
5
|
+
"mappings": "AAKA;AAAA,EACE;AAAA,EACA;AAAA,OAEK;AAEA,SAAS,aACd,UACA,OACA,yBACe;AACf,QAAM,yBAAyB;AAAA,IAC7B,GAAG;AAAA,IACH,GAAI,2BAA2B,CAAC;AAAA,EAClC;AAEA,QAAM,gBAAgB,EAAE,GAAG,MAAM;AAEjC,MAAI,UAAU;AACZ,kBAAc,YAAY;AAC1B,kBAAc,aAAa;AAAA,EAC7B,WAAW,OAAO,MAAM,cAAc,YAAY;AAAA,EAElD,WAAW,CAAC,MAAM,aAAa,CAAC,MAAM,MAAM;AAC1C,kBAAc,YAAY,uBAAuB,OAAO;AACxD,kBAAc,aACZ,uBAAuB,QAAQ,cAAc;AAAA,EACjD,WACE,OAAO,OAAO,OAAO,cAAc,YACnC,uBAAuB,MAAM,MAAM,SAAS,GAC5C;AACA,kBAAc,aACZ,uBAAuB,MAAM,MAAM,SAAS,GAAG,cAAc;AAC/D,kBAAc,YACZ,uBAAuB,MAAM,MAAM,SAAS,EAAE;AAChD,kBAAc,UACZ,uBAAuB,MAAM,MAAM,SAAS,EAAE;AAAA,EAClD,WACE,CAAC,MAAM,aACP,MAAM,QACN,uBAAuB,MAAM,IAAI,GACjC;AACA,kBAAc,YAAY,uBAAuB,MAAM,IAAI,EAAE;AAC7D,kBAAc,UAAU,uBAAuB,MAAM,IAAI,EAAE;AAC3D,kBAAc,aACZ,uBAAuB,MAAM,IAAI,GAAG,cAAc;AAAA,EACtD,OAAO;AACL,kBAAc,YAAY,uBAAuB,OAAO;AACxD,kBAAc,aACZ,uBAAuB,QAAQ,cAAc;AAAA,EACjD;AACA,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -17,7 +17,8 @@ const useField = (name, customField) => {
|
|
|
17
17
|
setValue,
|
|
18
18
|
getValues,
|
|
19
19
|
unregister,
|
|
20
|
-
formState
|
|
20
|
+
formState,
|
|
21
|
+
registerFieldFocus
|
|
21
22
|
} = useContext(FormContext);
|
|
22
23
|
if (!registerField) {
|
|
23
24
|
throw new Error(`
|
|
@@ -55,7 +56,8 @@ const useField = (name, customField) => {
|
|
|
55
56
|
getValues,
|
|
56
57
|
unregister,
|
|
57
58
|
formState,
|
|
58
|
-
error
|
|
59
|
+
error,
|
|
60
|
+
registerFieldFocus
|
|
59
61
|
};
|
|
60
62
|
};
|
|
61
63
|
export {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { FieldSpec, UseFieldProps } from '@digigov/form/Field/types';
|
|
1
|
+
import type { FieldSpec, UseFieldProps } from '@digigov/form/Field/types';
|
|
2
2
|
export declare const useField: (name: string, customField: FieldSpec | null) => UseFieldProps;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/Field/utils/useField.ts"],
|
|
4
|
-
"sourcesContent": ["import { useContext, useMemo } from 'react';\nimport { FieldSpec, UseFieldProps } from '@digigov/form/Field/types';\nimport { FormContext } from '@digigov/form/FormContext';\n\nexport const useField = (\n name: string,\n customField: FieldSpec | null\n): UseFieldProps => {\n const {\n fieldsMap,\n control,\n register,\n reset,\n resetField,\n trigger,\n clearErrors,\n errors,\n registerField,\n watch,\n componentRegistry,\n getFieldState,\n setValue,\n getValues,\n unregister,\n formState,\n } = useContext(FormContext);\n if (!registerField) {\n throw new Error(`\n You can't use the Field component without wrapping it in FormBuilder.\n https://devs.pages.grnet.gr/digigov/digigov-sdk/sdk-docs/forms/create-simple-form/\n `);\n }\n let error = errors[name];\n\n const nameIndexRegex = name.match(/^\\[*(.*?)\\.(\\d+)\\]*$/);\n if (nameIndexRegex) {\n const [, fieldArrayName, indexStr] = nameIndexRegex;\n error = errors[fieldArrayName]?.[Number(indexStr)];\n }\n const nestedNameIndexRegex = name.match(/^\\[*(.*?)\\.(\\d+)\\.(.*?)\\]*$/);\n if (nestedNameIndexRegex) {\n const [, fieldArrayName, indexStr, fieldItemName] = nestedNameIndexRegex;\n error = errors[fieldArrayName]?.[Number(indexStr)]?.[fieldItemName];\n }\n useMemo(\n () => customField?.type && registerField({ ...customField, key: name }),\n [customField, name, registerField]\n );\n return {\n field: customField || fieldsMap[name],\n control,\n register,\n reset,\n resetField,\n trigger,\n watch,\n componentRegistry,\n getFieldState,\n setValue,\n clearErrors,\n getValues,\n unregister,\n formState,\n error,\n };\n};\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,YAAY,eAAe;AAEpC,SAAS,mBAAmB;AAErB,MAAM,WAAW,CACtB,MACA,gBACkB;AAClB,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI,WAAW,WAAW;AAC1B,MAAI,CAAC,eAAe;AAClB,UAAM,IAAI,MAAM;AAAA;AAAA;AAAA,KAGf;AAAA,EACH;AACA,MAAI,QAAQ,OAAO,IAAI;AAEvB,QAAM,iBAAiB,KAAK,MAAM,sBAAsB;AACxD,MAAI,gBAAgB;AAClB,UAAM,CAAC,EAAE,gBAAgB,QAAQ,IAAI;AACrC,YAAQ,OAAO,cAAc,IAAI,OAAO,QAAQ,CAAC;AAAA,EACnD;AACA,QAAM,uBAAuB,KAAK,MAAM,6BAA6B;AACrE,MAAI,sBAAsB;AACxB,UAAM,CAAC,EAAE,gBAAgB,UAAU,aAAa,IAAI;AACpD,YAAQ,OAAO,cAAc,IAAI,OAAO,QAAQ,CAAC,IAAI,aAAa;AAAA,EACpE;AACA;AAAA,IACE,MAAM,aAAa,QAAQ,cAAc,EAAE,GAAG,aAAa,KAAK,KAAK,CAAC;AAAA,IACtE,CAAC,aAAa,MAAM,aAAa;AAAA,EACnC;AACA,SAAO;AAAA,IACL,OAAO,eAAe,UAAU,IAAI;AAAA,IACpC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;",
|
|
4
|
+
"sourcesContent": ["import { useContext, useMemo } from 'react';\nimport type { FieldSpec, UseFieldProps } from '@digigov/form/Field/types';\nimport { FormContext } from '@digigov/form/FormContext';\n\nexport const useField = (\n name: string,\n customField: FieldSpec | null\n): UseFieldProps => {\n const {\n fieldsMap,\n control,\n register,\n reset,\n resetField,\n trigger,\n clearErrors,\n errors,\n registerField,\n watch,\n componentRegistry,\n getFieldState,\n setValue,\n getValues,\n unregister,\n formState,\n registerFieldFocus,\n } = useContext(FormContext);\n if (!registerField) {\n throw new Error(`\n You can't use the Field component without wrapping it in FormBuilder.\n https://devs.pages.grnet.gr/digigov/digigov-sdk/sdk-docs/forms/create-simple-form/\n `);\n }\n let error = errors[name];\n\n const nameIndexRegex = name.match(/^\\[*(.*?)\\.(\\d+)\\]*$/);\n if (nameIndexRegex) {\n const [, fieldArrayName, indexStr] = nameIndexRegex;\n error = errors[fieldArrayName]?.[Number(indexStr)];\n }\n const nestedNameIndexRegex = name.match(/^\\[*(.*?)\\.(\\d+)\\.(.*?)\\]*$/);\n if (nestedNameIndexRegex) {\n const [, fieldArrayName, indexStr, fieldItemName] = nestedNameIndexRegex;\n error = errors[fieldArrayName]?.[Number(indexStr)]?.[fieldItemName];\n }\n useMemo(\n () => customField?.type && registerField({ ...customField, key: name }),\n [customField, name, registerField]\n );\n return {\n field: customField || fieldsMap[name],\n control,\n register,\n reset,\n resetField,\n trigger,\n watch,\n componentRegistry,\n getFieldState,\n setValue,\n clearErrors,\n getValues,\n unregister,\n formState,\n error,\n registerFieldFocus,\n };\n};\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,YAAY,eAAe;AAEpC,SAAS,mBAAmB;AAErB,MAAM,WAAW,CACtB,MACA,gBACkB;AAClB,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI,WAAW,WAAW;AAC1B,MAAI,CAAC,eAAe;AAClB,UAAM,IAAI,MAAM;AAAA;AAAA;AAAA,KAGf;AAAA,EACH;AACA,MAAI,QAAQ,OAAO,IAAI;AAEvB,QAAM,iBAAiB,KAAK,MAAM,sBAAsB;AACxD,MAAI,gBAAgB;AAClB,UAAM,CAAC,EAAE,gBAAgB,QAAQ,IAAI;AACrC,YAAQ,OAAO,cAAc,IAAI,OAAO,QAAQ,CAAC;AAAA,EACnD;AACA,QAAM,uBAAuB,KAAK,MAAM,6BAA6B;AACrE,MAAI,sBAAsB;AACxB,UAAM,CAAC,EAAE,gBAAgB,UAAU,aAAa,IAAI;AACpD,YAAQ,OAAO,cAAc,IAAI,OAAO,QAAQ,CAAC,IAAI,aAAa;AAAA,EACpE;AACA;AAAA,IACE,MAAM,aAAa,QAAQ,cAAc,EAAE,GAAG,aAAa,KAAK,KAAK,CAAC;AAAA,IACtE,CAAC,aAAa,MAAM,aAAa;AAAA,EACnC;AACA,SAAO;AAAA,IACL,OAAO,eAAe,UAAU,IAAI;AAAA,IACpC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|