@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
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ErrorOption, UseFormReturn } from 'react-hook-form';
|
|
3
|
+
import type { FieldProps } from '@digigov/form/Field/types';
|
|
4
|
+
export interface FormDialogProps extends FieldProps {
|
|
5
|
+
control: UseFormReturn['control'];
|
|
6
|
+
trigger: UseFormReturn['trigger'];
|
|
7
|
+
register: UseFormReturn['register'];
|
|
8
|
+
clearErrors: UseFormReturn['clearErrors'];
|
|
9
|
+
formState: UseFormReturn['formState'];
|
|
10
|
+
error?: ErrorOption;
|
|
11
|
+
getValues: UseFormReturn['getValues'];
|
|
12
|
+
setValue: UseFormReturn['setValue'];
|
|
13
|
+
reset: UseFormReturn['reset'];
|
|
14
|
+
resetField?: UseFormReturn['resetField'];
|
|
15
|
+
sortable: boolean;
|
|
16
|
+
Field: React.FC<FieldProps>;
|
|
17
|
+
}
|
|
18
|
+
export declare const FormDialog: React.ForwardRefExoticComponent<FormDialogProps & React.RefAttributes<HTMLButtonElement>>;
|
|
19
|
+
export default FormDialog;
|
|
@@ -1,121 +1,135 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
ModalHeading,
|
|
13
|
-
useModal
|
|
14
|
-
} from "@digigov/ui/app/Modal";
|
|
15
|
-
import {
|
|
16
|
-
Table,
|
|
17
|
-
TableBody,
|
|
18
|
-
TableContainer,
|
|
19
|
-
TableDataCell,
|
|
20
|
-
TableHead,
|
|
21
|
-
TableHeadCell,
|
|
22
|
-
TableRow
|
|
23
|
-
} from "@digigov/ui/content";
|
|
1
|
+
import React, {
|
|
2
|
+
useCallback,
|
|
3
|
+
useEffect,
|
|
4
|
+
useMemo,
|
|
5
|
+
useRef,
|
|
6
|
+
useState
|
|
7
|
+
} from "react";
|
|
8
|
+
import { useFieldArray } from "react-hook-form";
|
|
9
|
+
import { ArrayDisplay } from "@digigov/form/FieldArray/FormDialog/ArrayDisplay";
|
|
10
|
+
import { ArrayEditModal } from "@digigov/form/FieldArray/FormDialog/ArrayEditModal";
|
|
11
|
+
import { useModal } from "@digigov/ui/app/Modal";
|
|
24
12
|
import { Button } from "@digigov/ui/form/Button";
|
|
25
|
-
import { Grid, Stack } from "@digigov/ui/layouts";
|
|
26
|
-
import Heading from "@digigov/ui/typography/Heading";
|
|
27
13
|
import { Hint } from "@digigov/ui/typography/Hint";
|
|
28
14
|
const FormDialog = React.forwardRef(
|
|
29
|
-
|
|
30
|
-
name,
|
|
31
|
-
trigger,
|
|
32
|
-
register,
|
|
15
|
+
({
|
|
16
|
+
name: fieldArrayName,
|
|
33
17
|
control,
|
|
34
|
-
formState,
|
|
35
18
|
error,
|
|
36
19
|
getValues,
|
|
37
20
|
Field,
|
|
38
|
-
reset,
|
|
39
21
|
sortable,
|
|
40
22
|
...customField
|
|
41
|
-
}, ref) {
|
|
23
|
+
}, ref) => {
|
|
42
24
|
const [isAppending, setIsAppending] = useState(false);
|
|
43
|
-
const [
|
|
25
|
+
const [editingIndex, setEditingIndex] = useState(0);
|
|
44
26
|
const { fields, append, remove, update, move } = useFieldArray({
|
|
45
27
|
control,
|
|
46
|
-
name
|
|
28
|
+
name: fieldArrayName
|
|
47
29
|
});
|
|
48
30
|
const { open, close, registerModal } = useModal();
|
|
49
|
-
const currentLength = fields.length
|
|
50
|
-
const
|
|
31
|
+
const currentLength = fields.length;
|
|
32
|
+
const arrayItemName = isAppending ? `${fieldArrayName}.${currentLength}` : `${fieldArrayName}.${editingIndex}`;
|
|
51
33
|
useEffect(() => {
|
|
52
34
|
if (isAppending) {
|
|
53
|
-
|
|
54
|
-
open(`modal-${name}`);
|
|
35
|
+
open(`modal-${fieldArrayName}`);
|
|
55
36
|
}
|
|
56
|
-
}, [isAppending]);
|
|
57
|
-
const
|
|
58
|
-
if (!error) {
|
|
59
|
-
const values2 = getValues(currentName);
|
|
60
|
-
if (typeof values2 === "object") {
|
|
61
|
-
valuesRef.current = { ...values2 };
|
|
62
|
-
} else {
|
|
63
|
-
valuesRef.current = values2;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
const values = getValues(name);
|
|
37
|
+
}, [isAppending, fieldArrayName, open]);
|
|
38
|
+
const fieldArrayValues = getValues(fieldArrayName);
|
|
67
39
|
const ofField = {
|
|
68
40
|
...customField.extra?.of,
|
|
69
|
-
name:
|
|
41
|
+
name: arrayItemName
|
|
70
42
|
};
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
43
|
+
if (ofField.type !== "object") {
|
|
44
|
+
ofField.name = ofField.key ?? fieldArrayName;
|
|
45
|
+
ofField.key = ofField.key ?? fieldArrayName;
|
|
46
|
+
}
|
|
47
|
+
const defaultValue = useMemo(() => {
|
|
48
|
+
if (isAppending) {
|
|
49
|
+
if (ofField.type === "object") return ofField.defaultValue;
|
|
50
|
+
else return { [ofField.name]: ofField.defaultValue };
|
|
51
|
+
}
|
|
52
|
+
if (ofField.type === "object") return getValues(ofField.name);
|
|
53
|
+
else return { [ofField.name]: fieldArrayValues?.[editingIndex] };
|
|
54
|
+
}, [
|
|
55
|
+
editingIndex,
|
|
56
|
+
fieldArrayValues,
|
|
57
|
+
getValues,
|
|
58
|
+
isAppending,
|
|
59
|
+
ofField.defaultValue,
|
|
60
|
+
ofField.name,
|
|
61
|
+
ofField.type
|
|
62
|
+
]);
|
|
63
|
+
const hasCommitedValues = fields.length > 0 || !!fieldArrayValues?.length;
|
|
64
|
+
const title = useMemo(() => {
|
|
65
|
+
if (!customField.extra?.label.object.title) return null;
|
|
66
|
+
let title2 = customField.extra.label.object.title;
|
|
67
|
+
if (customField.extra.label.object.titleNumbering)
|
|
68
|
+
title2 += ` ${currentLength + 1}`;
|
|
69
|
+
return title2;
|
|
70
|
+
}, [
|
|
71
|
+
currentLength,
|
|
72
|
+
customField.extra?.label.object.title,
|
|
73
|
+
customField.extra?.label.object.titleNumbering
|
|
74
|
+
]);
|
|
75
|
+
const focusReturnRef = useRef(null);
|
|
76
|
+
const closeModal = useCallback(() => {
|
|
77
|
+
close();
|
|
78
|
+
if (focusReturnRef.current) {
|
|
79
|
+
focusReturnRef.current.focus();
|
|
80
|
+
focusReturnRef.current = null;
|
|
81
|
+
}
|
|
82
|
+
}, [close]);
|
|
83
|
+
const handleEditOrAppend = useCallback(
|
|
84
|
+
(data) => {
|
|
85
|
+
if (isAppending) {
|
|
86
|
+
setIsAppending(false);
|
|
87
|
+
if (ofField.type === "object") append(data);
|
|
88
|
+
else if (data) append(data[ofField.key ?? fieldArrayName]);
|
|
89
|
+
} else {
|
|
90
|
+
if (ofField.type === "object") update(editingIndex, data);
|
|
91
|
+
else if (data)
|
|
92
|
+
update(editingIndex, data[ofField.key ?? fieldArrayName]);
|
|
93
|
+
}
|
|
94
|
+
closeModal();
|
|
95
|
+
},
|
|
96
|
+
[
|
|
97
|
+
append,
|
|
98
|
+
closeModal,
|
|
99
|
+
editingIndex,
|
|
100
|
+
fieldArrayName,
|
|
101
|
+
isAppending,
|
|
102
|
+
ofField.key,
|
|
103
|
+
ofField.type,
|
|
104
|
+
update
|
|
105
|
+
]
|
|
106
|
+
);
|
|
107
|
+
const handleCancel = useCallback(() => {
|
|
108
|
+
if (isAppending) setIsAppending(false);
|
|
109
|
+
closeModal();
|
|
110
|
+
}, [closeModal, isAppending]);
|
|
111
|
+
const handleEdit = useCallback(
|
|
112
|
+
(index) => {
|
|
113
|
+
if (document.activeElement instanceof HTMLElement) {
|
|
114
|
+
focusReturnRef.current = document.activeElement;
|
|
115
|
+
}
|
|
116
|
+
setEditingIndex(index);
|
|
117
|
+
open(`modal-${fieldArrayName}`);
|
|
118
|
+
},
|
|
119
|
+
[fieldArrayName, open]
|
|
120
|
+
);
|
|
121
|
+
const handleAddClick = useCallback((ev) => {
|
|
122
|
+
ev.preventDefault();
|
|
123
|
+
if (document.activeElement instanceof HTMLElement) {
|
|
124
|
+
focusReturnRef.current = document.activeElement;
|
|
125
|
+
}
|
|
126
|
+
setIsAppending(true);
|
|
127
|
+
}, []);
|
|
128
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, !hasCommitedValues && /* @__PURE__ */ React.createElement(Hint, { ...customField.extra?.label.object?.nothing_added_props }, customField.extra?.label.object?.nothing_added), /* @__PURE__ */ React.createElement(
|
|
129
|
+
ArrayEditModal,
|
|
76
130
|
{
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
name,
|
|
80
|
-
defaultValue,
|
|
81
|
-
currentName,
|
|
82
|
-
editOrAppend: async () => {
|
|
83
|
-
const hasNoErrors = await trigger(
|
|
84
|
-
ofField.type === "object" ? ofField.extra.fields.map(({ key }) => `${currentName}.${key}`) : currentName
|
|
85
|
-
);
|
|
86
|
-
if (!hasNoErrors) {
|
|
87
|
-
update(currentIndex, valuesRef.current);
|
|
88
|
-
}
|
|
89
|
-
if (hasNoErrors) {
|
|
90
|
-
const newValues = getValues(currentName);
|
|
91
|
-
if (isAppending) {
|
|
92
|
-
setIsAppending(false);
|
|
93
|
-
}
|
|
94
|
-
if (newValues === "") {
|
|
95
|
-
remove(currentIndex);
|
|
96
|
-
} else {
|
|
97
|
-
update(currentIndex, newValues);
|
|
98
|
-
}
|
|
99
|
-
close();
|
|
100
|
-
}
|
|
101
|
-
},
|
|
102
|
-
cancel: () => {
|
|
103
|
-
if (isAppending) {
|
|
104
|
-
setIsAppending(false);
|
|
105
|
-
remove(currentIndex);
|
|
106
|
-
close();
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
update(currentIndex, valuesRef.current);
|
|
110
|
-
reset(void 0, {
|
|
111
|
-
keepTouched: true,
|
|
112
|
-
keepDefaultValues: true,
|
|
113
|
-
keepIsValid: true,
|
|
114
|
-
keepIsSubmitted: true,
|
|
115
|
-
keepValues: true
|
|
116
|
-
});
|
|
117
|
-
close();
|
|
118
|
-
},
|
|
131
|
+
editOrAppend: handleEditOrAppend,
|
|
132
|
+
cancel: handleCancel,
|
|
119
133
|
type: isAppending ? "append" : "edit",
|
|
120
134
|
appendLabel: customField.extra?.label.object.append.label,
|
|
121
135
|
appendProps: customField.extra?.label.object.append.props,
|
|
@@ -123,95 +137,43 @@ const FormDialog = React.forwardRef(
|
|
|
123
137
|
editProps: customField.extra?.label.object.edit.props,
|
|
124
138
|
cancelLabel: customField.extra?.label.object.cancel.label,
|
|
125
139
|
cancelProps: customField.extra?.label.object.cancel.props,
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
defaultValue: defaultValue || void 0,
|
|
133
|
-
error: error && error[currentIndex],
|
|
134
|
-
formState,
|
|
135
|
-
register,
|
|
136
|
-
control,
|
|
137
|
-
...ofField,
|
|
138
|
-
key: currentName,
|
|
139
|
-
Field
|
|
140
|
-
}
|
|
141
|
-
) : /* @__PURE__ */ React.createElement(
|
|
140
|
+
ofField,
|
|
141
|
+
title,
|
|
142
|
+
hint: customField.label?.secondary,
|
|
143
|
+
name: fieldArrayName,
|
|
144
|
+
defaultValue: defaultValue || void 0,
|
|
145
|
+
arrayItemName,
|
|
142
146
|
Field,
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
))
|
|
150
|
-
), !noValuesCommitted && /* @__PURE__ */ React.createElement(TableContainer, { ...customField.extra?.tableContainer }, /* @__PURE__ */ React.createElement(
|
|
151
|
-
Table,
|
|
147
|
+
error: error && error[editingIndex],
|
|
148
|
+
currentIndex: editingIndex,
|
|
149
|
+
...registerModal(`modal-${fieldArrayName}`)
|
|
150
|
+
}
|
|
151
|
+
), hasCommitedValues && /* @__PURE__ */ React.createElement(
|
|
152
|
+
ArrayDisplay,
|
|
152
153
|
{
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
/* @__PURE__ */ React.createElement(TableBody, null, !noValuesCommitted && values?.map?.((field, index) => {
|
|
164
|
-
return /* @__PURE__ */ React.createElement(
|
|
165
|
-
ArrayItemDisplay,
|
|
166
|
-
{
|
|
167
|
-
key: index,
|
|
168
|
-
name: `${name}.${index}`,
|
|
169
|
-
register,
|
|
170
|
-
index,
|
|
171
|
-
isFirst: index === 0,
|
|
172
|
-
isLast: index === values.length - 1,
|
|
173
|
-
data: field,
|
|
174
|
-
edit: () => {
|
|
175
|
-
setCurrentIndex(index);
|
|
176
|
-
open(`modal-${name}`);
|
|
177
|
-
},
|
|
178
|
-
stackProps: customField?.extra?.stackProps,
|
|
179
|
-
wordBreak: customField?.extra?.wordBreak,
|
|
180
|
-
valueDisplay: customField?.extra?.valueDisplay,
|
|
181
|
-
remove: () => {
|
|
182
|
-
remove(index);
|
|
183
|
-
},
|
|
184
|
-
border: customField.extra?.border,
|
|
185
|
-
move,
|
|
186
|
-
sortable,
|
|
187
|
-
disabledEdit: sortable ? true : customField.extra?.noEdit ?? false,
|
|
188
|
-
disabledDelete: customField.extra?.noDelete ?? false,
|
|
189
|
-
disabled: customField?.editable === false
|
|
190
|
-
}
|
|
191
|
-
);
|
|
192
|
-
}))
|
|
193
|
-
)), customField.extra?.editVariant !== "display" && /* @__PURE__ */ React.createElement(
|
|
154
|
+
fieldArrayName,
|
|
155
|
+
fieldArrayValues,
|
|
156
|
+
ofField,
|
|
157
|
+
customField,
|
|
158
|
+
onEdit: handleEdit,
|
|
159
|
+
onRemove: remove,
|
|
160
|
+
move,
|
|
161
|
+
sortable
|
|
162
|
+
}
|
|
163
|
+
), customField.extra?.editVariant !== "display" && /* @__PURE__ */ React.createElement(
|
|
194
164
|
"div",
|
|
195
165
|
{
|
|
196
|
-
className: customField.extra?.label.object?.addButtonVariant === "link" ? "px-2 py-2 bg-gray-200 border-t border-b border-gray-400" : ""
|
|
166
|
+
className: customField.extra?.label.object?.addButtonVariant === "link" ? "my-2 px-2 py-2 bg-gray-200 border-t border-b border-gray-400" : ""
|
|
197
167
|
},
|
|
198
168
|
/* @__PURE__ */ React.createElement(
|
|
199
169
|
Button,
|
|
200
170
|
{
|
|
171
|
+
ref,
|
|
201
172
|
type: "button",
|
|
202
|
-
name: `${
|
|
173
|
+
name: `${fieldArrayName}-add-object`,
|
|
203
174
|
color: "secondary",
|
|
204
175
|
variant: customField.extra?.label.object?.addButtonVariant,
|
|
205
|
-
onClick:
|
|
206
|
-
ev.preventDefault();
|
|
207
|
-
if (customField?.extra?.of?.type === "object") {
|
|
208
|
-
append({});
|
|
209
|
-
} else {
|
|
210
|
-
append("");
|
|
211
|
-
}
|
|
212
|
-
setCurrentIndex(currentLength + 1);
|
|
213
|
-
setIsAppending(true);
|
|
214
|
-
},
|
|
176
|
+
onClick: handleAddClick,
|
|
215
177
|
disabled: customField?.editable === false || customField.extra?.editVariant === "noinput" || fields.length >= (customField.extra?.max ?? Number.MAX_VALUE)
|
|
216
178
|
},
|
|
217
179
|
customField.extra?.label.object?.add
|
|
@@ -219,181 +181,10 @@ const FormDialog = React.forwardRef(
|
|
|
219
181
|
));
|
|
220
182
|
}
|
|
221
183
|
);
|
|
222
|
-
|
|
223
|
-
type,
|
|
224
|
-
currentName,
|
|
225
|
-
title,
|
|
226
|
-
hint,
|
|
227
|
-
defaultValue,
|
|
228
|
-
editOrAppend,
|
|
229
|
-
cancel,
|
|
230
|
-
control,
|
|
231
|
-
addTitle,
|
|
232
|
-
editLabel,
|
|
233
|
-
editProps,
|
|
234
|
-
appendLabel,
|
|
235
|
-
appendProps,
|
|
236
|
-
cancelLabel,
|
|
237
|
-
cancelProps,
|
|
238
|
-
children,
|
|
239
|
-
...props
|
|
240
|
-
}, ref) {
|
|
241
|
-
const value = useWatch({
|
|
242
|
-
control,
|
|
243
|
-
name: currentName,
|
|
244
|
-
defaultValue
|
|
245
|
-
});
|
|
246
|
-
const disabled = value === void 0 || value === null || value === "";
|
|
247
|
-
return /* @__PURE__ */ React.createElement(
|
|
248
|
-
Modal,
|
|
249
|
-
{
|
|
250
|
-
...props,
|
|
251
|
-
ref,
|
|
252
|
-
"aria-labelledby": "modal-label"
|
|
253
|
-
},
|
|
254
|
-
/* @__PURE__ */ React.createElement(ModalHeading, { id: "modal-label" }, title ? title : type === "edit" ? "\u0395\u03C0\u03B5\u03BE\u03B5\u03C1\u03B3\u03B1\u03C3\u03AF\u03B1" : addTitle || "\u03A0\u03C1\u03BF\u03C3\u03B8\u03AE\u03BA\u03B7"),
|
|
255
|
-
/* @__PURE__ */ React.createElement(ModalContent, null, hint && /* @__PURE__ */ React.createElement(Hint, null, hint), children),
|
|
256
|
-
/* @__PURE__ */ React.createElement(ModalAction, null, type === "edit" ? /* @__PURE__ */ React.createElement(
|
|
257
|
-
Button,
|
|
258
|
-
{
|
|
259
|
-
color: "secondary",
|
|
260
|
-
...editProps,
|
|
261
|
-
type: "button",
|
|
262
|
-
onClick: (e) => {
|
|
263
|
-
e.preventDefault();
|
|
264
|
-
editOrAppend();
|
|
265
|
-
},
|
|
266
|
-
disabled
|
|
267
|
-
},
|
|
268
|
-
editLabel || "\u0391\u03C0\u03BF\u03B8\u03AE\u03BA\u03B5\u03C5\u03C3\u03B7"
|
|
269
|
-
) : /* @__PURE__ */ React.createElement(
|
|
270
|
-
Button,
|
|
271
|
-
{
|
|
272
|
-
color: "primary",
|
|
273
|
-
...appendProps,
|
|
274
|
-
type: "button",
|
|
275
|
-
onClick: (e) => {
|
|
276
|
-
e.preventDefault();
|
|
277
|
-
editOrAppend();
|
|
278
|
-
},
|
|
279
|
-
disabled
|
|
280
|
-
},
|
|
281
|
-
appendLabel || "\u03A0\u03C1\u03BF\u03C3\u03B8\u03AE\u03BA\u03B7"
|
|
282
|
-
), /* @__PURE__ */ React.createElement(
|
|
283
|
-
Button,
|
|
284
|
-
{
|
|
285
|
-
variant: "link",
|
|
286
|
-
type: "button",
|
|
287
|
-
...cancelProps,
|
|
288
|
-
onClick: (e) => {
|
|
289
|
-
e.preventDefault();
|
|
290
|
-
cancel();
|
|
291
|
-
}
|
|
292
|
-
},
|
|
293
|
-
cancelLabel || "\u0391\u03BA\u03CD\u03C1\u03C9\u03C3\u03B7"
|
|
294
|
-
))
|
|
295
|
-
);
|
|
296
|
-
});
|
|
297
|
-
const ArrayItemHeader = ({ labels, disabled }) => {
|
|
298
|
-
return /* @__PURE__ */ React.createElement(TableHead, null, /* @__PURE__ */ React.createElement(TableRow, null, labels.map((label, index) => {
|
|
299
|
-
return /* @__PURE__ */ React.createElement(TableHeadCell, { key: index }, label);
|
|
300
|
-
}), !disabled && /* @__PURE__ */ React.createElement(TableHeadCell, null, "\u0395\u03BD\u03AD\u03C1\u03B3\u03B5\u03B9\u03B5\u03C2")));
|
|
301
|
-
};
|
|
302
|
-
const ArrayItemDisplay = ({
|
|
303
|
-
name,
|
|
304
|
-
data,
|
|
305
|
-
register,
|
|
306
|
-
edit,
|
|
307
|
-
remove,
|
|
308
|
-
disabledEdit,
|
|
309
|
-
disabledDelete,
|
|
310
|
-
disabled,
|
|
311
|
-
sortable,
|
|
312
|
-
index,
|
|
313
|
-
isFirst,
|
|
314
|
-
isLast,
|
|
315
|
-
move,
|
|
316
|
-
valueDisplay,
|
|
317
|
-
border = true,
|
|
318
|
-
wordBreak = "break-all",
|
|
319
|
-
stackProps = {
|
|
320
|
-
spacing: 4,
|
|
321
|
-
alignItems: "flex-end",
|
|
322
|
-
justifyContent: "flex-end",
|
|
323
|
-
direction: "column"
|
|
324
|
-
}
|
|
325
|
-
}) => {
|
|
326
|
-
if (data === void 0 || data === null) {
|
|
327
|
-
return null;
|
|
328
|
-
}
|
|
329
|
-
if (Object.keys(data).length === 0 || Object.keys(data).length === 1 && data.id) {
|
|
330
|
-
return null;
|
|
331
|
-
}
|
|
332
|
-
delete data.id;
|
|
333
|
-
const values = typeof data === "string" ? [data] : Object.values(data || {});
|
|
334
|
-
const borderVariant = border === false || sortable ? "none" : "border";
|
|
335
|
-
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(TableRow, { ...register(name) }, values?.map?.((value, valueIndex) => {
|
|
336
|
-
return /* @__PURE__ */ React.createElement(
|
|
337
|
-
TableDataCell,
|
|
338
|
-
{
|
|
339
|
-
key: valueIndex,
|
|
340
|
-
variant: borderVariant,
|
|
341
|
-
wordBreak,
|
|
342
|
-
pb: sortable ? 0 : void 0,
|
|
343
|
-
pt: sortable ? 4 : void 0
|
|
344
|
-
},
|
|
345
|
-
sortable && valueIndex === 0 && /* @__PURE__ */ React.createElement(Heading, { size: "sm", className: "mb-2" }, "\u0395\u03C0\u03B9\u03BB\u03BF\u03B3\u03AE #", index + 1),
|
|
346
|
-
value?.name || (Array.isArray(value) ? value.join("\n") : valueDisplay ? valueDisplay(value) : value) || ""
|
|
347
|
-
);
|
|
348
|
-
}), disabled === true || disabledEdit === true && disabledDelete === true ? null : /* @__PURE__ */ React.createElement(TableDataCell, { variant: borderVariant }, /* @__PURE__ */ React.createElement(Stack, { ...stackProps }, disabledEdit !== true && /* @__PURE__ */ React.createElement(
|
|
349
|
-
Button,
|
|
350
|
-
{
|
|
351
|
-
variant: "link",
|
|
352
|
-
type: "button",
|
|
353
|
-
onClick: () => {
|
|
354
|
-
edit(name);
|
|
355
|
-
}
|
|
356
|
-
},
|
|
357
|
-
"\u0395\u03C0\u03B5\u03BE\u03B5\u03C1\u03B3\u03B1\u03C3\u03AF\u03B1"
|
|
358
|
-
), disabledDelete !== true && /* @__PURE__ */ React.createElement(
|
|
359
|
-
Button,
|
|
360
|
-
{
|
|
361
|
-
variant: "link",
|
|
362
|
-
type: "button",
|
|
363
|
-
onClick: () => remove(name)
|
|
364
|
-
},
|
|
365
|
-
"\u0394\u03B9\u03B1\u03B3\u03C1\u03B1\u03C6\u03AE"
|
|
366
|
-
)))), sortable && /* @__PURE__ */ React.createElement(TableRow, null, /* @__PURE__ */ React.createElement(
|
|
367
|
-
TableDataCell,
|
|
368
|
-
{
|
|
369
|
-
variant: isLast ? "none" : "border",
|
|
370
|
-
colSpan: disabled === true || disabledEdit === true && disabledDelete === true ? values.length : values.length + 1
|
|
371
|
-
},
|
|
372
|
-
sortable && !disabled && !(isFirst && isLast) && /* @__PURE__ */ React.createElement(Grid, { xs: 12, mt: 2 }, "\u039C\u03B5\u03C4\u03B1\u03BA\u03AF\u03BD\u03B7\u03C3\u03B7", " ", !isFirst && /* @__PURE__ */ React.createElement(React.Fragment, null, "\u03C0\u03C1\u03BF\u03C2 \u03C4\u03B1", " ", /* @__PURE__ */ React.createElement(
|
|
373
|
-
Button,
|
|
374
|
-
{
|
|
375
|
-
type: "button",
|
|
376
|
-
variant: "link",
|
|
377
|
-
onClick: () => move(index, index - 1)
|
|
378
|
-
},
|
|
379
|
-
"\u03C0\u03AC\u03BD\u03C9"
|
|
380
|
-
)), !isFirst && !isLast && " \u03AE ", !isLast && /* @__PURE__ */ React.createElement(React.Fragment, null, "\u03C0\u03C1\u03BF\u03C2 \u03C4\u03B1", " ", /* @__PURE__ */ React.createElement(
|
|
381
|
-
Button,
|
|
382
|
-
{
|
|
383
|
-
type: "button",
|
|
384
|
-
variant: "link",
|
|
385
|
-
onClick: () => move(index, index + 1)
|
|
386
|
-
},
|
|
387
|
-
"\u03BA\u03AC\u03C4\u03C9"
|
|
388
|
-
)))
|
|
389
|
-
)));
|
|
390
|
-
};
|
|
184
|
+
FormDialog.displayName = "FormDialog";
|
|
391
185
|
var FormDialog_default = FormDialog;
|
|
392
186
|
export {
|
|
393
|
-
ArrayItemDisplay,
|
|
394
|
-
ArrayItemHeader,
|
|
395
|
-
ArrayItemModal,
|
|
396
187
|
FormDialog,
|
|
397
188
|
FormDialog_default as default
|
|
398
189
|
};
|
|
399
|
-
//# sourceMappingURL=
|
|
190
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/FieldArray/FormDialog/index.tsx"],
|
|
4
|
+
"sourcesContent": ["import React, {\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport type { ErrorOption, UseFormReturn } from 'react-hook-form';\nimport { useFieldArray } from 'react-hook-form';\nimport type { FieldProps, FormData } from '@digigov/form/Field/types';\nimport { ArrayDisplay } from '@digigov/form/FieldArray/FormDialog/ArrayDisplay';\nimport { ArrayEditModal } from '@digigov/form/FieldArray/FormDialog/ArrayEditModal';\nimport { useModal } from '@digigov/ui/app/Modal';\nimport { Button } from '@digigov/ui/form/Button';\nimport { Hint } from '@digigov/ui/typography/Hint';\n\nexport interface FormDialogProps extends FieldProps {\n control: UseFormReturn['control'];\n trigger: UseFormReturn['trigger'];\n register: UseFormReturn['register'];\n clearErrors: UseFormReturn['clearErrors'];\n formState: UseFormReturn['formState'];\n error?: ErrorOption;\n getValues: UseFormReturn['getValues'];\n setValue: UseFormReturn['setValue'];\n reset: UseFormReturn['reset'];\n resetField?: UseFormReturn['resetField'];\n sortable: boolean;\n Field: React.FC<FieldProps>;\n}\n\nexport const FormDialog = React.forwardRef<HTMLButtonElement, FormDialogProps>(\n (\n {\n name: fieldArrayName,\n control,\n error,\n getValues,\n Field,\n sortable,\n ...customField\n },\n ref\n ) => {\n const [isAppending, setIsAppending] = useState(false);\n const [editingIndex, setEditingIndex] = useState(0);\n const { fields, append, remove, update, move } = useFieldArray({\n control,\n name: fieldArrayName,\n });\n const { open, close, registerModal } = useModal();\n const currentLength = fields.length;\n const arrayItemName = isAppending\n ? `${fieldArrayName}.${currentLength}`\n : `${fieldArrayName}.${editingIndex}`;\n\n useEffect(() => {\n if (isAppending) {\n open(`modal-${fieldArrayName}`);\n }\n }, [isAppending, fieldArrayName, open]);\n\n const fieldArrayValues = getValues(fieldArrayName);\n const ofField = {\n ...customField.extra?.of,\n name: arrayItemName,\n };\n if (ofField.type !== 'object') {\n ofField.name = ofField.key ?? fieldArrayName;\n ofField.key = ofField.key ?? fieldArrayName;\n }\n\n const defaultValue = useMemo(() => {\n // If appending, use default value from field spec\n if (isAppending) {\n if (ofField.type === 'object') return ofField.defaultValue;\n else return { [ofField.name]: ofField.defaultValue };\n }\n\n if (ofField.type === 'object') return getValues(ofField.name);\n else return { [ofField.name]: fieldArrayValues?.[editingIndex] };\n }, [\n editingIndex,\n fieldArrayValues,\n getValues,\n isAppending,\n ofField.defaultValue,\n ofField.name,\n ofField.type,\n ]);\n\n const hasCommitedValues = fields.length > 0 || !!fieldArrayValues?.length;\n\n const title = useMemo(() => {\n if (!customField.extra?.label.object.title) return null;\n\n let title = customField.extra.label.object.title;\n if (customField.extra.label.object.titleNumbering)\n title += ` ${currentLength + 1}`;\n\n return title;\n }, [\n currentLength,\n customField.extra?.label.object.title,\n customField.extra?.label.object.titleNumbering,\n ]);\n\n const focusReturnRef = useRef<HTMLElement | null>(null);\n\n /** Handle closing the modal and restoring focus */\n const closeModal = useCallback(() => {\n close();\n // Return focus to the element that was focused before the modal opened\n if (focusReturnRef.current) {\n focusReturnRef.current.focus();\n focusReturnRef.current = null;\n }\n }, [close]);\n\n /** Handle modal form submission */\n const handleEditOrAppend = useCallback(\n (data: FormData) => {\n if (isAppending) {\n setIsAppending(false);\n if (ofField.type === 'object') append(data);\n else if (data) append(data[ofField.key ?? fieldArrayName]);\n } else {\n if (ofField.type === 'object') update(editingIndex, data);\n else if (data)\n update(editingIndex, data[ofField.key ?? fieldArrayName]);\n }\n closeModal();\n },\n [\n append,\n closeModal,\n editingIndex,\n fieldArrayName,\n isAppending,\n ofField.key,\n ofField.type,\n update,\n ]\n );\n\n /** Handle cancelling the modal operation */\n const handleCancel = useCallback(() => {\n if (isAppending) setIsAppending(false);\n closeModal();\n }, [closeModal, isAppending]);\n\n /** Handle opening the modal to edit an existing item */\n const handleEdit = useCallback(\n (index: number) => {\n // Store the currently focused element to restore focus later\n if (document.activeElement instanceof HTMLElement) {\n focusReturnRef.current = document.activeElement;\n }\n setEditingIndex(index);\n open(`modal-${fieldArrayName}`);\n },\n [fieldArrayName, open]\n );\n\n /** Handle opening the modal to add a new item */\n const handleAddClick = useCallback((ev: React.MouseEvent) => {\n ev.preventDefault();\n // Store the currently focused element to restore focus later\n if (document.activeElement instanceof HTMLElement) {\n focusReturnRef.current = document.activeElement;\n }\n setIsAppending(true);\n }, []);\n\n return (\n <>\n {!hasCommitedValues && (\n <Hint {...customField.extra?.label.object?.nothing_added_props}>\n {customField.extra?.label.object?.nothing_added}\n </Hint>\n )}\n <ArrayEditModal\n editOrAppend={handleEditOrAppend}\n cancel={handleCancel}\n type={isAppending ? 'append' : 'edit'}\n appendLabel={customField.extra?.label.object.append.label}\n appendProps={customField.extra?.label.object.append.props}\n editLabel={customField.extra?.label.object.edit.label}\n editProps={customField.extra?.label.object.edit.props}\n cancelLabel={customField.extra?.label.object.cancel.label}\n cancelProps={customField.extra?.label.object.cancel.props}\n ofField={ofField}\n title={title}\n hint={customField.label?.secondary}\n name={fieldArrayName}\n defaultValue={defaultValue || undefined}\n arrayItemName={arrayItemName}\n Field={Field}\n error={error && error[editingIndex]}\n currentIndex={editingIndex}\n {...registerModal(`modal-${fieldArrayName}`)}\n />\n {hasCommitedValues && (\n <ArrayDisplay\n fieldArrayName={fieldArrayName}\n fieldArrayValues={fieldArrayValues}\n ofField={ofField}\n customField={customField}\n onEdit={handleEdit}\n onRemove={remove}\n move={move}\n sortable={sortable}\n />\n )}\n {customField.extra?.editVariant !== 'display' && (\n <div\n className={\n customField.extra?.label.object?.addButtonVariant === 'link'\n ? 'my-2 px-2 py-2 bg-gray-200 border-t border-b border-gray-400'\n : ''\n }\n >\n <Button\n ref={ref}\n type=\"button\"\n name={`${fieldArrayName}-add-object`}\n color=\"secondary\"\n variant={customField.extra?.label.object?.addButtonVariant}\n onClick={handleAddClick}\n disabled={\n customField?.editable === false ||\n customField.extra?.editVariant === 'noinput' ||\n fields.length >= (customField.extra?.max ?? Number.MAX_VALUE)\n }\n >\n {customField.extra?.label.object?.add}\n </Button>\n </div>\n )}\n </>\n );\n }\n);\n\nFormDialog.displayName = 'FormDialog';\n\nexport default FormDialog;\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
|
+
"names": ["title"]
|
|
7
|
+
}
|
package/FieldArray/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { ErrorOption, UseFormReturn } from 'react-hook-form';
|
|
3
|
-
import { FieldProps } from '@digigov/form/Field/types';
|
|
2
|
+
import type { ErrorOption, UseFormReturn } from 'react-hook-form';
|
|
3
|
+
import type { FieldProps } from '@digigov/form/Field/types';
|
|
4
|
+
import type { registerFieldFocus } from '@digigov/form/types';
|
|
4
5
|
export interface FieldArrayProps extends FieldProps {
|
|
5
6
|
control: UseFormReturn['control'];
|
|
6
7
|
trigger: UseFormReturn['trigger'];
|
|
@@ -13,6 +14,7 @@ export interface FieldArrayProps extends FieldProps {
|
|
|
13
14
|
reset: UseFormReturn['reset'];
|
|
14
15
|
resetField?: UseFormReturn['resetField'];
|
|
15
16
|
Field: React.FC<FieldProps>;
|
|
17
|
+
registerFieldFocus: registerFieldFocus;
|
|
16
18
|
}
|
|
17
19
|
export declare const FieldArray: React.FC<FieldArrayProps>;
|
|
18
20
|
export default FieldArray;
|