@digigov/form 2.0.0-rc.17 → 2.0.0-rc.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Field/FieldBase/index.js +1 -0
- package/Field/FieldBase.js.map +2 -2
- package/Field/FieldBaseContainer/index.js +1 -1
- package/Field/FieldBaseContainer.js.map +2 -2
- package/Field/FieldConditional/index.js +8 -4
- package/Field/FieldConditional.js.map +2 -2
- package/Field/index.js +21 -4
- package/Field/index.js.map +2 -2
- package/Field/types.d.ts +39 -3
- package/Field/utils/calculateField/index.js +27 -0
- package/Field/utils/calculateField/package.json +6 -0
- package/Field/utils/calculateField.d.ts +2 -0
- package/Field/utils/calculateField.js.map +7 -0
- package/Field/utils/evaluateFieldWithConditions/index.js +26 -0
- package/Field/utils/evaluateFieldWithConditions/package.json +6 -0
- package/Field/utils/evaluateFieldWithConditions.d.ts +2 -0
- package/Field/utils/evaluateFieldWithConditions.js.map +7 -0
- package/Field/utils/index.d.ts +4 -0
- package/Field/utils/index.js +20 -97
- package/Field/utils/index.js.map +7 -0
- package/Field/utils/useField/index.js +51 -0
- package/{FormBuilder/FormBuilder → Field/utils/useField}/package.json +1 -1
- package/Field/utils/useField.d.ts +2 -0
- package/Field/utils/useField.js.map +7 -0
- package/FieldArray/FieldArray.stories/index.js +4 -1
- package/FieldArray/FieldArray.stories.d.ts +2 -1
- package/FieldArray/FieldArray.stories.js.map +2 -2
- package/FieldArray/__stories__/Default.d.ts +2 -2
- package/FieldArray/__stories__/WithExactLength/index.js +95 -0
- package/FieldArray/__stories__/WithExactLength/package.json +6 -0
- package/FieldArray/__stories__/WithExactLength.d.ts +2 -0
- package/FieldArray/__stories__/WithExactLength.js.map +7 -0
- package/FieldArray/index.d.ts +1 -0
- package/FieldArray/index.js +16 -3
- package/FieldArray/index.js.map +2 -2
- package/FieldObject/index.d.ts +3 -0
- package/FieldObject/index.js +15 -6
- package/FieldObject/index.js.map +2 -2
- package/Fieldset/types.d.ts +2 -0
- package/FormBuilder/FormBuilder.stories/index.js +2 -1
- package/FormBuilder/FormBuilder.stories.d.ts +1 -1
- package/FormBuilder/FormBuilder.stories.js.map +2 -2
- package/FormBuilder/__stories__/Default.d.ts +2 -2
- package/FormBuilder/index.d.ts +8 -1
- package/FormBuilder/index.js +154 -2
- package/FormBuilder/index.js.map +3 -3
- package/MultiplicityField/MultiplicityField.stories/index.js +12 -2
- package/MultiplicityField/MultiplicityField.stories.d.ts +6 -2
- package/MultiplicityField/MultiplicityField.stories.js.map +2 -2
- package/MultiplicityField/__stories__/Default.d.ts +2 -2
- package/MultiplicityField/__stories__/PreviewDisplay.d.ts +2 -2
- package/MultiplicityField/__stories__/WithExactLength/index.js +97 -0
- package/MultiplicityField/__stories__/WithExactLength/package.json +6 -0
- package/MultiplicityField/__stories__/WithExactLength.d.ts +2 -0
- package/MultiplicityField/__stories__/WithExactLength.js.map +7 -0
- package/MultiplicityField/__stories__/WithMaxLength/index.js +100 -0
- package/MultiplicityField/__stories__/WithMaxLength/package.json +6 -0
- package/MultiplicityField/__stories__/WithMaxLength.d.ts +2 -0
- package/MultiplicityField/__stories__/WithMaxLength.js.map +7 -0
- package/MultiplicityField/__stories__/WithMinAndMaxLength/index.js +101 -0
- package/MultiplicityField/__stories__/WithMinAndMaxLength/package.json +6 -0
- package/MultiplicityField/__stories__/WithMinAndMaxLength.d.ts +2 -0
- package/MultiplicityField/__stories__/WithMinAndMaxLength.js.map +7 -0
- package/MultiplicityField/__stories__/WithMinLength/index.js +100 -0
- package/MultiplicityField/__stories__/WithMinLength/package.json +6 -0
- package/MultiplicityField/__stories__/WithMinLength.d.ts +2 -0
- package/MultiplicityField/__stories__/WithMinLength.js.map +7 -0
- package/MultiplicityField/add-objects/index.js +17 -7
- package/MultiplicityField/add-objects.d.ts +2 -1
- package/MultiplicityField/add-objects.js.map +2 -2
- package/MultiplicityField/index.d.ts +2 -19
- package/MultiplicityField/index.js +7 -5
- package/MultiplicityField/index.js.map +2 -2
- package/MultiplicityField/types/index.js +1 -0
- package/MultiplicityField/types/package.json +6 -0
- package/MultiplicityField/types.d.ts +19 -0
- package/MultiplicityField/types.js.map +7 -0
- package/Questions/Questions.stories/index.js +2 -1
- package/Questions/Questions.stories.d.ts +1 -1
- package/Questions/Questions.stories.js.map +2 -2
- package/Questions/Step/StepTitle.d.ts +1 -0
- package/Questions/Step/StepTitle.js.map +2 -2
- package/Questions/Step/index.d.ts +0 -1
- package/Questions/Step/index.js +0 -1
- package/Questions/Step/index.js.map +2 -2
- package/Questions/Step/types.d.ts +2 -0
- package/Questions/__stories__/Default.d.ts +2 -2
- package/Questions/types.d.ts +2 -0
- package/cjs/Field/FieldBase/index.js +1 -0
- package/cjs/Field/FieldBase.js.map +2 -2
- package/cjs/Field/FieldBaseContainer/index.js +3 -3
- package/cjs/Field/FieldBaseContainer.js.map +3 -3
- package/cjs/Field/FieldConditional/index.js +9 -5
- package/cjs/Field/FieldConditional.js.map +2 -2
- package/cjs/Field/index.js +18 -4
- package/cjs/Field/index.js.map +2 -2
- package/cjs/Field/types.js.map +1 -1
- package/cjs/Field/utils/calculateField/index.js +50 -0
- package/cjs/Field/utils/calculateField.js.map +7 -0
- package/cjs/Field/utils/evaluateFieldWithConditions/index.js +49 -0
- package/cjs/Field/utils/evaluateFieldWithConditions.js.map +7 -0
- package/cjs/Field/utils/index.js +22 -99
- package/cjs/Field/utils/index.js.map +7 -0
- package/cjs/Field/utils/useField/index.js +74 -0
- package/cjs/Field/utils/useField.js.map +7 -0
- package/cjs/FieldArray/FieldArray.stories/index.js +6 -3
- package/cjs/FieldArray/FieldArray.stories.js.map +2 -2
- package/cjs/FieldArray/__stories__/WithExactLength/index.js +128 -0
- package/cjs/FieldArray/__stories__/WithExactLength.js.map +7 -0
- package/cjs/FieldArray/index.js +19 -6
- package/cjs/FieldArray/index.js.map +2 -2
- package/cjs/FieldObject/index.js +11 -5
- package/cjs/FieldObject/index.js.map +2 -2
- package/cjs/Fieldset/types.js.map +1 -1
- package/cjs/FormBuilder/FormBuilder.stories/index.js +3 -3
- package/cjs/FormBuilder/FormBuilder.stories.js.map +2 -2
- package/cjs/FormBuilder/index.js +172 -3
- package/cjs/FormBuilder/index.js.map +3 -3
- package/cjs/MultiplicityField/MultiplicityField.stories/index.js +18 -5
- package/cjs/MultiplicityField/MultiplicityField.stories.js.map +2 -2
- package/cjs/MultiplicityField/__stories__/WithExactLength/index.js +130 -0
- package/cjs/MultiplicityField/__stories__/WithExactLength.js.map +7 -0
- package/cjs/MultiplicityField/__stories__/WithMaxLength/index.js +133 -0
- package/cjs/MultiplicityField/__stories__/WithMaxLength.js.map +7 -0
- package/cjs/MultiplicityField/__stories__/WithMinAndMaxLength/index.js +134 -0
- package/cjs/MultiplicityField/__stories__/WithMinAndMaxLength.js.map +7 -0
- package/cjs/MultiplicityField/__stories__/WithMinLength/index.js +133 -0
- package/cjs/MultiplicityField/__stories__/WithMinLength.js.map +7 -0
- package/cjs/MultiplicityField/add-objects/index.js +13 -6
- package/cjs/MultiplicityField/add-objects.js.map +2 -2
- package/cjs/MultiplicityField/index.js +7 -5
- package/cjs/MultiplicityField/index.js.map +2 -2
- package/cjs/MultiplicityField/types/index.js +16 -0
- package/cjs/MultiplicityField/types.js.map +7 -0
- package/cjs/Questions/Questions.stories/index.js +3 -3
- package/cjs/Questions/Questions.stories.js.map +2 -2
- package/cjs/Questions/Step/StepTitle.js.map +2 -2
- package/cjs/Questions/Step/index.js +0 -2
- package/cjs/Questions/Step/index.js.map +2 -2
- package/cjs/Questions/Step/types.js.map +1 -1
- package/cjs/Questions/types.js.map +1 -1
- package/cjs/index.js +10 -2
- package/cjs/index.js.map +2 -2
- package/cjs/inputs/AutoCompleteInput/AutoComplete.stories/index.js +6 -5
- package/cjs/inputs/AutoCompleteInput/AutoComplete.stories.js.map +2 -2
- package/cjs/inputs/AutoCompleteInput/index.js +2 -1
- package/cjs/inputs/AutoCompleteInput/index.js.map +2 -2
- package/cjs/inputs/Checkboxes/Checkboxes.stories/index.js +9 -7
- package/cjs/inputs/Checkboxes/Checkboxes.stories.js.map +2 -2
- package/cjs/inputs/Checkboxes/index.js +3 -3
- package/cjs/inputs/Checkboxes/index.js.map +2 -2
- package/cjs/inputs/DateInput/DateInput.stories/index.js +3 -3
- package/cjs/inputs/DateInput/DateInput.stories.js.map +2 -2
- package/cjs/inputs/FileInput/FileInput.stories/index.js +3 -3
- package/cjs/inputs/FileInput/FileInput.stories.js.map +2 -2
- package/cjs/inputs/ImageInput/ImageInput.stories/index.js +9 -3
- package/cjs/inputs/ImageInput/ImageInput.stories.js.map +2 -2
- package/cjs/inputs/ImageInput/__stories__/WithInvalidImageDimension/index.js +71 -0
- package/cjs/inputs/ImageInput/__stories__/WithInvalidImageDimension.js.map +7 -0
- package/cjs/inputs/ImageInput/__stories__/WithInvalidImageSize/index.js +68 -0
- package/cjs/inputs/ImageInput/__stories__/WithInvalidImageSize.js.map +7 -0
- package/cjs/inputs/ImageInput/index.js +3 -2
- package/cjs/inputs/ImageInput/index.js.map +2 -2
- package/cjs/inputs/Input/Input.stories/index.js +30 -21
- package/cjs/inputs/Input/Input.stories.js.map +2 -2
- package/cjs/inputs/Input/index.js +18 -5
- package/cjs/inputs/Input/index.js.map +3 -3
- package/cjs/inputs/Label/Label.stories/index.js +3 -3
- package/cjs/inputs/Label/Label.stories.js.map +2 -2
- package/cjs/inputs/Label/__stories__/Default/index.js +4 -2
- package/cjs/inputs/Label/__stories__/Default.js.map +3 -3
- package/cjs/inputs/Label/index.js.map +1 -1
- package/cjs/inputs/OtpInput/OtpInput.stories/index.js +3 -3
- package/cjs/inputs/OtpInput/OtpInput.stories.js.map +2 -2
- package/cjs/inputs/Radio/Radio.stories/index.js +9 -7
- package/cjs/inputs/Radio/Radio.stories.js.map +2 -2
- package/cjs/inputs/Radio/__stories__/Conditional.js.map +2 -2
- package/cjs/inputs/Radio/index.js +53 -5
- package/cjs/inputs/Radio/index.js.map +2 -2
- package/cjs/inputs/Select/Select.stories/index.js +3 -3
- package/cjs/inputs/Select/Select.stories.js.map +2 -2
- package/cjs/internal/index.js +4 -84
- package/cjs/internal.js.map +2 -2
- package/cjs/lazy/index.js +21 -17
- package/cjs/lazy.js.map +2 -2
- package/cjs/registry/index.js +8 -2
- package/cjs/registry.js.map +2 -2
- package/cjs/types/index.js +6 -0
- package/cjs/types.js.map +2 -2
- package/cjs/utils/index.js +4 -1
- package/cjs/utils.js.map +2 -2
- package/cjs/validators/utils/phone/index.js +8 -6
- package/cjs/validators/utils/phone.js.map +2 -2
- package/index.d.ts +4 -1
- package/index.js +7 -2
- package/index.js.map +3 -3
- package/inputs/AutoCompleteInput/AutoComplete.stories/index.js +4 -2
- package/inputs/AutoCompleteInput/AutoComplete.stories.d.ts +2 -2
- package/inputs/AutoCompleteInput/AutoComplete.stories.js.map +2 -2
- package/inputs/AutoCompleteInput/__stories__/Default.d.ts +2 -2
- package/inputs/AutoCompleteInput/__stories__/Multiple.d.ts +2 -2
- package/inputs/AutoCompleteInput/index.js +2 -1
- package/inputs/AutoCompleteInput/index.js.map +2 -2
- package/inputs/Checkboxes/Checkboxes.stories/index.js +6 -3
- package/inputs/Checkboxes/Checkboxes.stories.d.ts +3 -3
- package/inputs/Checkboxes/Checkboxes.stories.js.map +2 -2
- package/inputs/Checkboxes/__stories__/Conditional.d.ts +2 -2
- package/inputs/Checkboxes/__stories__/Default.d.ts +2 -2
- package/inputs/Checkboxes/__stories__/WithDivider.d.ts +2 -2
- package/inputs/Checkboxes/index.d.ts +1 -0
- package/inputs/Checkboxes/index.js +3 -3
- package/inputs/Checkboxes/index.js.map +2 -2
- package/inputs/DateInput/DateInput.stories/index.js +2 -1
- package/inputs/DateInput/DateInput.stories.d.ts +1 -1
- package/inputs/DateInput/DateInput.stories.js.map +2 -2
- package/inputs/DateInput/__stories__/Default.d.ts +2 -2
- package/inputs/DateInput/index.d.ts +2 -2
- package/inputs/FileInput/FileInput.stories/index.js +2 -1
- package/inputs/FileInput/FileInput.stories.d.ts +1 -1
- package/inputs/FileInput/FileInput.stories.js.map +2 -2
- package/inputs/FileInput/__stories__/Default.d.ts +2 -2
- package/inputs/ImageInput/ImageInput.stories/index.js +6 -1
- package/inputs/ImageInput/ImageInput.stories.d.ts +3 -1
- package/inputs/ImageInput/ImageInput.stories.js.map +2 -2
- package/inputs/ImageInput/__stories__/Default.d.ts +2 -2
- package/inputs/ImageInput/__stories__/WithInvalidImageDimension/index.js +38 -0
- package/inputs/ImageInput/__stories__/WithInvalidImageDimension/package.json +6 -0
- package/inputs/ImageInput/__stories__/WithInvalidImageDimension.d.ts +3 -0
- package/inputs/ImageInput/__stories__/WithInvalidImageDimension.js.map +7 -0
- package/inputs/ImageInput/__stories__/WithInvalidImageSize/index.js +35 -0
- package/inputs/ImageInput/__stories__/WithInvalidImageSize/package.json +6 -0
- package/inputs/ImageInput/__stories__/WithInvalidImageSize.d.ts +3 -0
- package/inputs/ImageInput/__stories__/WithInvalidImageSize.js.map +7 -0
- package/inputs/ImageInput/index.js +3 -2
- package/inputs/ImageInput/index.js.map +2 -2
- package/inputs/Input/Input.stories/index.js +20 -10
- package/inputs/Input/Input.stories.d.ts +10 -10
- package/inputs/Input/Input.stories.js.map +2 -2
- package/inputs/Input/__stories__/AFM.d.ts +2 -2
- package/inputs/Input/__stories__/Boolean.d.ts +2 -2
- package/inputs/Input/__stories__/IBAN.d.ts +2 -2
- package/inputs/Input/__stories__/Integer.d.ts +2 -2
- package/inputs/Input/__stories__/LandlineNumber.d.ts +2 -2
- package/inputs/Input/__stories__/MobilePhone.d.ts +2 -2
- package/inputs/Input/__stories__/PhoneNumber.d.ts +2 -2
- package/inputs/Input/__stories__/PostalCode.d.ts +2 -2
- package/inputs/Input/__stories__/String.d.ts +2 -2
- package/inputs/Input/__stories__/TextWithLimit.d.ts +2 -2
- package/inputs/Input/index.js +16 -3
- package/inputs/Input/index.js.map +3 -3
- package/inputs/Label/Label.stories/index.js +2 -1
- package/inputs/Label/Label.stories.d.ts +1 -1
- package/inputs/Label/Label.stories.js.map +2 -2
- package/inputs/Label/__stories__/Default/index.js +3 -1
- package/inputs/Label/__stories__/Default.d.ts +2 -2
- package/inputs/Label/__stories__/Default.js.map +2 -2
- package/inputs/Label/index.d.ts +1 -1
- package/inputs/Label/index.js.map +1 -1
- package/inputs/OtpInput/OtpInput.stories/index.js +2 -1
- package/inputs/OtpInput/OtpInput.stories.d.ts +1 -1
- package/inputs/OtpInput/OtpInput.stories.js.map +2 -2
- package/inputs/OtpInput/__stories__/Default.d.ts +2 -2
- package/inputs/OtpInput/index.d.ts +1 -1
- package/inputs/Radio/Radio.stories/index.js +6 -3
- package/inputs/Radio/Radio.stories.d.ts +3 -3
- package/inputs/Radio/Radio.stories.js.map +2 -2
- package/inputs/Radio/__stories__/Conditional.d.ts +2 -2
- package/inputs/Radio/__stories__/Conditional.js.map +2 -2
- package/inputs/Radio/__stories__/Default.d.ts +2 -2
- package/inputs/Radio/__stories__/WithDivider.d.ts +2 -2
- package/inputs/Radio/index.d.ts +5 -0
- package/inputs/Radio/index.js +51 -4
- package/inputs/Radio/index.js.map +2 -2
- package/inputs/Select/Select.stories/index.js +2 -1
- package/inputs/Select/Select.stories.d.ts +1 -1
- package/inputs/Select/Select.stories.js.map +2 -2
- package/inputs/Select/__stories__/Default.d.ts +2 -2
- package/internal/index.js +4 -45
- package/internal.d.ts +2 -31
- package/internal.js.map +3 -3
- package/lazy/index.js +21 -17
- package/lazy.d.ts +36 -29
- package/lazy.js.map +2 -2
- package/package.json +7 -7
- package/registry/index.js +8 -2
- package/registry.d.ts +4 -1
- package/registry.js.map +2 -2
- package/src/Field/FieldBase.tsx +1 -0
- package/src/Field/FieldBaseContainer.tsx +1 -1
- package/src/Field/FieldConditional.tsx +5 -1
- package/src/Field/index.tsx +20 -3
- package/src/Field/types.tsx +67 -3
- package/src/Field/utils/calculateField.ts +49 -0
- package/src/Field/utils/evaluateFieldWithConditions.ts +30 -0
- package/src/Field/utils/index.ts +76 -0
- package/src/Field/utils/useField.ts +54 -0
- package/src/FieldArray/FieldArray.stories.js +2 -1
- package/src/FieldArray/__stories__/WithExactLength.tsx +94 -0
- package/src/FieldArray/index.test.tsx +4 -0
- package/src/FieldArray/index.tsx +12 -2
- package/src/FieldObject/index.tsx +16 -3
- package/src/Fieldset/types.tsx +3 -1
- package/src/FormBuilder/FormBuilder.stories.js +1 -1
- package/src/FormBuilder/index.tsx +178 -1
- package/src/MultiplicityField/MultiplicityField.stories.js +6 -2
- package/src/MultiplicityField/__stories__/WithExactLength.tsx +98 -0
- package/src/MultiplicityField/__stories__/WithMaxLength.tsx +101 -0
- package/src/MultiplicityField/__stories__/WithMinAndMaxLength.tsx +102 -0
- package/src/MultiplicityField/__stories__/WithMinLength.tsx +101 -0
- package/src/MultiplicityField/add-objects.tsx +41 -21
- package/src/MultiplicityField/index.test.tsx +16 -0
- package/src/MultiplicityField/index.tsx +11 -26
- package/src/MultiplicityField/types.ts +22 -0
- package/src/Questions/Questions.stories.js +1 -1
- package/src/Questions/Step/StepTitle.tsx +1 -0
- package/src/Questions/Step/index.ts +0 -1
- package/src/Questions/Step/types.tsx +1 -0
- package/src/Questions/__snapshots__/index.spec.tsx.snap +67 -586
- package/src/Questions/index.spec.tsx +3 -3
- package/src/Questions/types.tsx +1 -0
- package/src/index.ts +4 -1
- package/src/inputs/AutoCompleteInput/AutoComplete.stories.js +2 -2
- package/src/inputs/AutoCompleteInput/index.tsx +3 -2
- package/src/inputs/Checkboxes/Checkboxes.stories.js +3 -3
- package/src/inputs/Checkboxes/index.tsx +27 -24
- package/src/inputs/DateInput/DateInput.stories.js +1 -1
- package/src/inputs/FileInput/FileInput.stories.js +1 -1
- package/src/inputs/ImageInput/ImageInput.stories.js +3 -1
- package/src/inputs/ImageInput/__stories__/WithInvalidImageDimension.tsx +39 -0
- package/src/inputs/ImageInput/__stories__/WithInvalidImageSize.tsx +36 -0
- package/src/inputs/ImageInput/index.test.tsx +8 -0
- package/src/inputs/ImageInput/index.tsx +3 -3
- package/src/inputs/Input/Input.stories.js +10 -10
- package/src/inputs/Input/index.tsx +24 -29
- package/src/inputs/Label/Label.stories.js +1 -1
- package/src/inputs/Label/__stories__/Default.tsx +3 -1
- package/src/inputs/Label/index.tsx +1 -1
- package/src/inputs/OtpInput/OtpInput.stories.js +1 -1
- package/src/inputs/Radio/Radio.stories.js +3 -3
- package/src/inputs/Radio/__stories__/Conditional.tsx +2 -1
- package/src/inputs/Radio/index.test.tsx +17 -16
- package/src/inputs/Radio/index.tsx +72 -7
- package/src/inputs/Select/Select.stories.js +1 -1
- package/src/internal.ts +2 -31
- package/src/lazy.js +21 -17
- package/src/registry.js +8 -2
- package/src/types.tsx +10 -64
- package/src/utils.ts +34 -33
- package/src/validators/utils/phone.ts +62 -71
- package/src/validators/validators.spec.ts +3 -37
- package/types/index.js +1 -0
- package/types.d.ts +5 -34
- package/types.js.map +3 -3
- package/utils/index.js +4 -1
- package/utils.js.map +2 -2
- package/validators/utils/phone/index.js +8 -6
- package/validators/utils/phone.js.map +2 -2
- package/Field/utils.d.ts +0 -5
- package/Field/utils.js.map +0 -7
- package/FormBuilder/FormBuilder/index.js +0 -150
- package/FormBuilder/FormBuilder.d.ts +0 -5
- package/FormBuilder/FormBuilder.js.map +0 -7
- package/cjs/Field/utils.js.map +0 -7
- package/cjs/FormBuilder/FormBuilder/index.js +0 -184
- package/cjs/FormBuilder/FormBuilder.js.map +0 -7
- package/src/Field/utils.ts +0 -191
- package/src/FormBuilder/FormBuilder.tsx +0 -174
package/Field/FieldBase/index.js
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 from 'react';\nimport { Controller } from 'react-hook-form';\nimport FieldBaseContainer from '@digigov/form/Field/FieldBaseContainer';\nimport { FieldBaseProps } from '@digigov/form/Field/types';\n\nexport const FieldBase: React.FC<FieldBaseProps> = (props) => {\n const {\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 } = props;\n if (!enabled) {\n return null;\n }\n if (controlled) {\n return (\n <FieldBaseContainer\n label={label}\n layout={layout}\n error={error}\n wrapper={wrapper}\n name={name}\n >\n <Controller\n control={control}\n name={name}\n render={({ field }) => {\n return (\n <Component\n {...field}\n ref={undefined}\n defaultValue={defaultValue}\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 error={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 {...componentProps}\n />\n ) : (\n <Component\n {...register(name)}\n register={register}\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 ref={undefined}\n {...componentProps}\n />\n )}\n </FieldBaseContainer>\n );\n};\n"],
|
|
5
|
-
"mappings": "AAAA,OAAO,WAAW;AAClB,SAAS,kBAAkB;AAC3B,OAAO,wBAAwB;AAGxB,MAAM,YAAsC,CAAC,UAAU;AAC5D,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA,WAAW;AAAA,IACX;AAAA,IACA;AAAA,IACA;AAAA,IACA,aAAa;AAAA,IACb,UAAU;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IACA,QAAQ,CAAC;AAAA,IACT;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EACL,IAAI;AACJ,MAAI,CAAC,SAAS;AACZ,WAAO;AAAA,EACT;AACA,MAAI,YAAY;AACd,WACE;AAAA,MAAC;AAAA;AAAA,QACC;AAAA,QACA;AAAA,QACA;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,KAAK;AAAA,gBACL;AAAA,gBACA;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;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,QACtB,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,iBAAe,CAAC,CAAC;AAAA,QACjB,oBAAkB,SAAS,GAAG,IAAI;AAAA,QAClC;AAAA,QACA,UAAU,aAAa;AAAA,QACvB,KAAK;AAAA,QACJ,GAAG;AAAA;AAAA,IACN;AAAA,EAEJ;AAEJ;",
|
|
4
|
+
"sourcesContent": ["import React from 'react';\nimport { Controller } from 'react-hook-form';\nimport FieldBaseContainer from '@digigov/form/Field/FieldBaseContainer';\nimport { FieldBaseProps } from '@digigov/form/Field/types';\n\nexport const FieldBase: React.FC<FieldBaseProps> = (props) => {\n const {\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 } = props;\n if (!enabled) {\n return null;\n }\n if (controlled) {\n return (\n <FieldBaseContainer\n label={label}\n layout={layout}\n error={error}\n wrapper={wrapper}\n name={name}\n >\n <Controller\n control={control}\n name={name}\n render={({ field }) => {\n return (\n <Component\n {...field}\n control={control}\n ref={undefined}\n defaultValue={defaultValue}\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 error={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 {...componentProps}\n />\n ) : (\n <Component\n {...register(name)}\n register={register}\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 ref={undefined}\n {...componentProps}\n />\n )}\n </FieldBaseContainer>\n );\n};\n"],
|
|
5
|
+
"mappings": "AAAA,OAAO,WAAW;AAClB,SAAS,kBAAkB;AAC3B,OAAO,wBAAwB;AAGxB,MAAM,YAAsC,CAAC,UAAU;AAC5D,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA,WAAW;AAAA,IACX;AAAA,IACA;AAAA,IACA;AAAA,IACA,aAAa;AAAA,IACb,UAAU;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,IACA,QAAQ,CAAC;AAAA,IACT;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EACL,IAAI;AACJ,MAAI,CAAC,SAAS;AACZ,WAAO;AAAA,EACT;AACA,MAAI,YAAY;AACd,WACE;AAAA,MAAC;AAAA;AAAA,QACC;AAAA,QACA;AAAA,QACA;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,KAAK;AAAA,gBACL;AAAA,gBACA;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;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,QACtB,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,iBAAe,CAAC,CAAC;AAAA,QACjB,oBAAkB,SAAS,GAAG,IAAI;AAAA,QAClC;AAAA,QACA,UAAU,aAAa;AAAA,QACvB,KAAK;AAAA,QACJ,GAAG;AAAA;AAAA,IACN;AAAA,EAEJ;AAEJ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import Label from "@digigov/form/inputs/Label";
|
|
3
|
-
import ErrorMessage from "@digigov/react-core/ErrorMessage";
|
|
3
|
+
import { ErrorMessage } from "@digigov/react-core/ErrorMessage";
|
|
4
4
|
import FieldContainer from "@digigov/react-core/FieldContainer";
|
|
5
5
|
import CoreFieldset from "@digigov/react-core/Fieldset";
|
|
6
6
|
import FieldsetLegend from "@digigov/react-core/FieldsetLegend";
|
|
@@ -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 CoreFieldset from '@digigov/react-core/Fieldset';\nimport FieldsetLegend from '@digigov/react-core/FieldsetLegend';\nimport Hint from '@digigov/react-core/Hint';\nimport LabelContainer from '@digigov/react-core/LabelContainer';\nimport { useTranslation } from '@digigov/ui/i18n';\n\nexport const FieldBaseContainer: React.FC<FieldContainerProps> = ({\n name,\n wrapper,\n label,\n children,\n error,\n layout,\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={!!error} {...layout}>\n <CoreFieldset>\n <FieldsetLegend size=\"sm\">{label && label.primary}</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 </CoreFieldset>\n </FieldContainer>\n );\n } else {\n return (\n <FieldContainer error={!!error} {...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 </LabelContainer>\n </FieldContainer>\n );\n }\n};\n\nexport default FieldBaseContainer;\n"],
|
|
5
|
-
"mappings": "AAAA,OAAO,WAAW;AAElB,OAAO,WAAW;AAClB,
|
|
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 CoreFieldset from '@digigov/react-core/Fieldset';\nimport FieldsetLegend from '@digigov/react-core/FieldsetLegend';\nimport Hint from '@digigov/react-core/Hint';\nimport LabelContainer from '@digigov/react-core/LabelContainer';\nimport { useTranslation } from '@digigov/ui/i18n';\n\nexport const FieldBaseContainer: React.FC<FieldContainerProps> = ({\n name,\n wrapper,\n label,\n children,\n error,\n layout,\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={!!error} {...layout}>\n <CoreFieldset>\n <FieldsetLegend size=\"sm\">{label && label.primary}</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 </CoreFieldset>\n </FieldContainer>\n );\n } else {\n return (\n <FieldContainer error={!!error} {...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 </LabelContainer>\n </FieldContainer>\n );\n }\n};\n\nexport default FieldBaseContainer;\n"],
|
|
5
|
+
"mappings": "AAAA,OAAO,WAAW;AAElB,OAAO,WAAW;AAClB,SAAQ,oBAAmB;AAC3B,OAAO,oBAAoB;AAC3B,OAAO,kBAAkB;AACzB,OAAO,oBAAoB;AAC3B,OAAO,UAAU;AACjB,OAAO,oBAAoB;AAC3B,SAAS,sBAAsB;AAExB,MAAM,qBAAoD,CAAC;AAAA,EAChE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAAM;AACJ,QAAM,EAAE,EAAE,IAAI,eAAe;AAC7B,QAAM,eAAe,OAAO,QAAQ,MAChC,MAAM,QAAQ,MACd,OAAO,WAAW;AACtB,QAAM,eAAe,OAAO,QAAQ,WAAW,CAAC;AAChD,MAAI,YAAY,YAAY;AAC1B,WACE,oCAAC,kBAAe,OAAO,CAAC,CAAC,OAAQ,GAAG,UAClC,oCAAC,oBACC,oCAAC,kBAAe,MAAK,QAAM,SAAS,MAAM,OAAQ,GACjD,SAAS,MAAM,aAAa,oCAAC,YAAM,EAAE,MAAM,SAAS,CAAE,GACtD,SACC,oCAAC,gBAAa,IAAI,GAAG,IAAI,YACtB,EAAE,cAAc,YAAY,CAC/B,GAED,QACH,CACF;AAAA,EAEJ,OAAO;AACL,WACE,oCAAC,kBAAe,OAAO,CAAC,CAAC,OAAQ,GAAG,UAClC,oCAAC,sBACE,SAAS,oCAAC,SAAM,OAAc,GAC9B,SACC,oCAAC,gBAAa,IAAI,GAAG,IAAI,YACtB,EAAE,cAAc,YAAY,CAC/B,GAED,QACH,CACF;AAAA,EAEJ;AACF;AAEA,IAAO,6BAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { useWatch } from "react-hook-form";
|
|
3
3
|
import { FieldBase } from "@digigov/form/Field/FieldBase";
|
|
4
|
-
import { evaluateFieldWithConditions } from "@digigov/form/Field/utils";
|
|
4
|
+
import { evaluateFieldWithConditions } from "@digigov/form/Field/utils/evaluateFieldWithConditions";
|
|
5
5
|
const ChildFieldMemo = React.memo(
|
|
6
6
|
function ChildField({
|
|
7
7
|
dependencies,
|
|
@@ -9,7 +9,8 @@ const ChildFieldMemo = React.memo(
|
|
|
9
9
|
control,
|
|
10
10
|
reset,
|
|
11
11
|
register,
|
|
12
|
-
error
|
|
12
|
+
error,
|
|
13
|
+
Field
|
|
13
14
|
}) {
|
|
14
15
|
const newField = evaluateFieldWithConditions(
|
|
15
16
|
field,
|
|
@@ -19,6 +20,7 @@ const ChildFieldMemo = React.memo(
|
|
|
19
20
|
FieldBase,
|
|
20
21
|
{
|
|
21
22
|
...newField,
|
|
23
|
+
Field,
|
|
22
24
|
name: newField.key,
|
|
23
25
|
reset,
|
|
24
26
|
control,
|
|
@@ -47,7 +49,8 @@ const FieldConditional = ({
|
|
|
47
49
|
field,
|
|
48
50
|
register,
|
|
49
51
|
reset,
|
|
50
|
-
error
|
|
52
|
+
error,
|
|
53
|
+
Field
|
|
51
54
|
}) => {
|
|
52
55
|
const dependencyKeys = Object.keys(field.condition);
|
|
53
56
|
const dependencyValues = useWatch({
|
|
@@ -69,7 +72,8 @@ const FieldConditional = ({
|
|
|
69
72
|
control,
|
|
70
73
|
register,
|
|
71
74
|
reset,
|
|
72
|
-
error
|
|
75
|
+
error,
|
|
76
|
+
Field
|
|
73
77
|
}
|
|
74
78
|
);
|
|
75
79
|
};
|
|
@@ -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';\n\nconst ChildFieldMemo = React.memo(\n function ChildField({\n dependencies,\n field,\n control,\n reset,\n register,\n error,\n }: ChildFieldMemoProps) {\n const newField = evaluateFieldWithConditions(\n field,\n dependencies as FormData\n );\n return (\n <FieldBase\n {...newField}\n name={newField.key}\n reset={reset}\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 error,\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 error={error}\n />\n );\n};\n\nexport default FieldConditional;\n"],
|
|
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,EACF,GAAwB;AACtB,UAAM,WAAW;AAAA,MACf;AAAA,MACA;AAAA,IACF;AACA,WACE;AAAA,MAAC;AAAA;AAAA,QACE,GAAG;AAAA,QACJ,MAAM,SAAS;AAAA,QACf;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;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;AAAA,EACF;AAEJ;AAEA,IAAO,2BAAQ;",
|
|
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 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 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 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 error={error}\n Field={Field}\n />\n );\n};\n\nexport default FieldConditional;\n"],
|
|
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,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;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;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;AAAA,EACF;AAEJ;AAEA,IAAO,2BAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/Field/index.js
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
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 {
|
|
4
|
+
import {
|
|
5
|
+
FIELD_COMPONENTS,
|
|
6
|
+
ALTERNATIVE_COMPONENTS
|
|
7
|
+
} from "@digigov/form/Field/utils";
|
|
8
|
+
import { calculateField } from "@digigov/form/Field/utils/calculateField";
|
|
9
|
+
import { useField } from "@digigov/form/Field/utils/useField";
|
|
5
10
|
import FieldArray from "@digigov/form/FieldArray";
|
|
6
11
|
import Multiplicity from "@digigov/form/MultiplicityField";
|
|
7
12
|
const Field = ({
|
|
@@ -25,7 +30,15 @@ const Field = ({
|
|
|
25
30
|
clearErrors
|
|
26
31
|
} = useField(name, customField?.type ? customField : null);
|
|
27
32
|
const calculatedField = useMemo(
|
|
28
|
-
() => calculateField(
|
|
33
|
+
() => calculateField(
|
|
34
|
+
children,
|
|
35
|
+
field,
|
|
36
|
+
{
|
|
37
|
+
...FIELD_COMPONENTS,
|
|
38
|
+
...componentRegistry
|
|
39
|
+
},
|
|
40
|
+
ALTERNATIVE_COMPONENTS
|
|
41
|
+
),
|
|
29
42
|
[field]
|
|
30
43
|
);
|
|
31
44
|
if (calculatedField.condition) {
|
|
@@ -36,7 +49,8 @@ const Field = ({
|
|
|
36
49
|
reset,
|
|
37
50
|
register,
|
|
38
51
|
field: calculatedField,
|
|
39
|
-
error
|
|
52
|
+
error,
|
|
53
|
+
Field
|
|
40
54
|
}
|
|
41
55
|
);
|
|
42
56
|
}
|
|
@@ -49,6 +63,7 @@ const Field = ({
|
|
|
49
63
|
register,
|
|
50
64
|
error,
|
|
51
65
|
formState,
|
|
66
|
+
Field,
|
|
52
67
|
...calculatedField
|
|
53
68
|
}
|
|
54
69
|
);
|
|
@@ -67,6 +82,7 @@ const Field = ({
|
|
|
67
82
|
setValue,
|
|
68
83
|
getValues,
|
|
69
84
|
unregister,
|
|
85
|
+
Field,
|
|
70
86
|
...calculatedField
|
|
71
87
|
}
|
|
72
88
|
);
|
|
@@ -80,7 +96,8 @@ const Field = ({
|
|
|
80
96
|
control,
|
|
81
97
|
register,
|
|
82
98
|
reset,
|
|
83
|
-
error
|
|
99
|
+
error,
|
|
100
|
+
Field
|
|
84
101
|
}
|
|
85
102
|
);
|
|
86
103
|
};
|
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 {\n FieldWithCondition,\n CalculatedField,\n FieldProps,\n} from '@digigov/form/Field/types';\nimport {
|
|
5
|
-
"mappings": "AAAA,OAAO,SAAS,eAAe;AAC/B,SAAS,iBAAiB;AAC1B,OAAO,sBAAsB;AAM7B,SAAS,
|
|
4
|
+
"sourcesContent": ["import React, { useMemo } from 'react';\nimport { FieldBase } from '@digigov/form/Field/FieldBase';\nimport FieldConditional from '@digigov/form/Field/FieldConditional';\nimport {\n FieldWithCondition,\n CalculatedField,\n FieldProps,\n} from '@digigov/form/Field/types';\nimport {\n FIELD_COMPONENTS,\n ALTERNATIVE_COMPONENTS,\n} from '@digigov/form/Field/utils';\nimport { calculateField } from '@digigov/form/Field/utils/calculateField';\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 disabled,\n children,\n ...customField\n}) => {\n const {\n field,\n control,\n register,\n reset,\n error,\n componentRegistry,\n formState,\n setValue,\n getValues,\n unregister,\n trigger,\n clearErrors,\n } = useField(name, customField?.type ? customField : null);\n const calculatedField: CalculatedField = useMemo(\n () =>\n calculateField(\n children,\n field,\n {\n ...FIELD_COMPONENTS,\n ...componentRegistry,\n },\n ALTERNATIVE_COMPONENTS\n ),\n [field]\n );\n\n if (calculatedField.condition) {\n return (\n <FieldConditional\n control={control}\n reset={reset}\n register={register}\n field={calculatedField as FieldWithCondition}\n error={error}\n Field={Field}\n />\n );\n }\n if (calculatedField.type === 'array' && !calculatedField.multiplicity) {\n calculatedField.name = name;\n return (\n <FieldArray\n control={control}\n register={register}\n error={error}\n formState={formState}\n Field={Field}\n {...calculatedField}\n />\n );\n }\n if (\n calculatedField.type === 'array' &&\n calculatedField.multiplicity === true\n ) {\n calculatedField.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 Field={Field}\n {...calculatedField}\n />\n );\n }\n return (\n <FieldBase\n {...calculatedField}\n name={name}\n disabled={disabled}\n control={control}\n register={register}\n reset={reset}\n error={error}\n Field={Field}\n />\n );\n};\n\nexport default Field;\n"],
|
|
5
|
+
"mappings": "AAAA,OAAO,SAAS,eAAe;AAC/B,SAAS,iBAAiB;AAC1B,OAAO,sBAAsB;AAM7B;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,sBAAsB;AAC/B,SAAS,gBAAgB;AACzB,OAAO,gBAAgB;AACvB,OAAO,kBAAkB;AAClB,MAAM,QAA8B,CAAC;AAAA,EAC1C;AAAA,EACA;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,EACF,IAAI,SAAS,MAAM,aAAa,OAAO,cAAc,IAAI;AACzD,QAAM,kBAAmC;AAAA,IACvC,MACE;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,QACE,GAAG;AAAA,QACH,GAAG;AAAA,MACL;AAAA,MACA;AAAA,IACF;AAAA,IACF,CAAC,KAAK;AAAA,EACR;AAEA,MAAI,gBAAgB,WAAW;AAC7B,WACE;AAAA,MAAC;AAAA;AAAA,QACC;AAAA,QACA;AAAA,QACA;AAAA,QACA,OAAO;AAAA,QACP;AAAA,QACA;AAAA;AAAA,IACF;AAAA,EAEJ;AACA,MAAI,gBAAgB,SAAS,WAAW,CAAC,gBAAgB,cAAc;AACrE,oBAAgB,OAAO;AACvB,WACE;AAAA,MAAC;AAAA;AAAA,QACC;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACC,GAAG;AAAA;AAAA,IACN;AAAA,EAEJ;AACA,MACE,gBAAgB,SAAS,WACzB,gBAAgB,iBAAiB,MACjC;AACA,oBAAgB,OAAO;AACvB,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,QACC,GAAG;AAAA;AAAA,IACN;AAAA,EAEJ;AACA,SACE;AAAA,IAAC;AAAA;AAAA,MACE,GAAG;AAAA,MACJ;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA;AAAA,EACF;AAEJ;AAEA,IAAO,gBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/Field/types.d.ts
CHANGED
|
@@ -1,10 +1,42 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { ErrorOption, UseFormReturn } from 'react-hook-form';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { ErrorOption, UseFormReturn, UseFormProps } from 'react-hook-form';
|
|
3
|
+
import { ValidatorSchema } from '@digigov/form/validators/types';
|
|
4
|
+
import { GridProps } from '@digigov/ui/layouts/Grid';
|
|
5
|
+
export type FieldLabelProps = {
|
|
6
|
+
primary?: string;
|
|
7
|
+
secondary?: string;
|
|
8
|
+
};
|
|
9
|
+
export interface FieldSpec {
|
|
10
|
+
key: string;
|
|
11
|
+
type?: 'int' | 'string' | 'text' | 'boolean' | 'email' | 'uuid4' | 'choice:multiple' | 'choice:single' | 'mobile_phone' | 'date' | 'otp' | 'afm' | 'iban' | 'file' | 'image' | 'postal_code' | 'phone_number' | 'array' | 'object';
|
|
12
|
+
component?: any;
|
|
13
|
+
maxLength?: number;
|
|
14
|
+
condition?: Record<string, FieldCondition>;
|
|
15
|
+
controlled?: boolean;
|
|
16
|
+
label?: FieldLabelProps;
|
|
17
|
+
extra?: {
|
|
18
|
+
[key: string]: any;
|
|
19
|
+
};
|
|
20
|
+
editable?: boolean;
|
|
21
|
+
required?: boolean;
|
|
22
|
+
enabled?: boolean;
|
|
23
|
+
disabled?: boolean;
|
|
24
|
+
layout?: Record<string, GridProps['xs'] | GridProps['sm'] | GridProps['md'] | GridProps['lg'] | GridProps['xl']>;
|
|
25
|
+
validators?: ValidatorSchema[];
|
|
26
|
+
wrapper?: 'label' | 'fieldset';
|
|
27
|
+
maxWidth?: string;
|
|
28
|
+
maxHeight?: string;
|
|
29
|
+
width?: string;
|
|
30
|
+
}
|
|
31
|
+
export interface FieldCondition {
|
|
32
|
+
is: string | string[] | number | number[] | boolean | boolean[];
|
|
33
|
+
then?: Partial<FieldSpec>;
|
|
34
|
+
else?: Partial<FieldSpec>;
|
|
35
|
+
}
|
|
5
36
|
export interface ChildFieldMemoProps extends FieldConditionalProps {
|
|
6
37
|
dependencies: FormData;
|
|
7
38
|
}
|
|
39
|
+
export type FormData = UseFormProps['defaultValues'];
|
|
8
40
|
export interface FieldWithCondition extends Omit<CalculatedField, 'condition'> {
|
|
9
41
|
condition: Record<string, FieldCondition>;
|
|
10
42
|
}
|
|
@@ -14,6 +46,7 @@ export interface FieldConditionalProps {
|
|
|
14
46
|
register: UseFormReturn['register'];
|
|
15
47
|
reset: UseFormReturn['reset'];
|
|
16
48
|
error?: ErrorOption;
|
|
49
|
+
Field: React.FC<FieldProps>;
|
|
17
50
|
}
|
|
18
51
|
export type FieldComponentItem = {
|
|
19
52
|
component: any;
|
|
@@ -41,6 +74,7 @@ export interface ControlledFieldProps {
|
|
|
41
74
|
error?: boolean;
|
|
42
75
|
name?: string;
|
|
43
76
|
disabled?: boolean;
|
|
77
|
+
Field: React.FC<FieldProps>;
|
|
44
78
|
}
|
|
45
79
|
export interface UncontrolledFieldProps {
|
|
46
80
|
name: string;
|
|
@@ -50,6 +84,7 @@ export interface UncontrolledFieldProps {
|
|
|
50
84
|
extra?: Record<string, never>;
|
|
51
85
|
type?: string;
|
|
52
86
|
disabled?: boolean;
|
|
87
|
+
Field: React.FC<FieldProps>;
|
|
53
88
|
}
|
|
54
89
|
export interface CalculatedField extends OmittedFieldSpec {
|
|
55
90
|
name: string;
|
|
@@ -63,6 +98,7 @@ export interface FieldBaseProps extends CalculatedField {
|
|
|
63
98
|
control: UseFormReturn['control'];
|
|
64
99
|
register: UseFormReturn['register'];
|
|
65
100
|
reset: UseFormReturn['reset'];
|
|
101
|
+
Field: React.FC<FieldProps>;
|
|
66
102
|
}
|
|
67
103
|
export interface FieldProps extends FieldSpec {
|
|
68
104
|
name: string;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
function calculateField(children, field, fieldComponentRegistry, alternativeComponents) {
|
|
2
|
+
const calculatedField = { ...field };
|
|
3
|
+
if (children) {
|
|
4
|
+
calculatedField.component = children;
|
|
5
|
+
calculatedField.controlled = true;
|
|
6
|
+
} else if (typeof field.component === "function") {
|
|
7
|
+
} else if (!field.component && !field.type) {
|
|
8
|
+
calculatedField.component = fieldComponentRegistry.string.component;
|
|
9
|
+
calculatedField.controlled = fieldComponentRegistry.string?.controlled || false;
|
|
10
|
+
} else if (typeof field?.extra?.component === "string" && alternativeComponents[field.extra.component]) {
|
|
11
|
+
calculatedField.controlled = alternativeComponents[field.extra.component]?.controlled || false;
|
|
12
|
+
calculatedField.component = alternativeComponents[field.extra.component].component;
|
|
13
|
+
calculatedField.wrapper = alternativeComponents[field.extra.component].wrapper;
|
|
14
|
+
} else if (!field.component && field.type && fieldComponentRegistry[field.type]) {
|
|
15
|
+
calculatedField.component = fieldComponentRegistry[field.type].component;
|
|
16
|
+
calculatedField.wrapper = fieldComponentRegistry[field.type].wrapper;
|
|
17
|
+
calculatedField.controlled = fieldComponentRegistry[field.type]?.controlled || false;
|
|
18
|
+
} else {
|
|
19
|
+
calculatedField.component = fieldComponentRegistry.string.component;
|
|
20
|
+
calculatedField.controlled = fieldComponentRegistry.string?.controlled || false;
|
|
21
|
+
}
|
|
22
|
+
return calculatedField;
|
|
23
|
+
}
|
|
24
|
+
export {
|
|
25
|
+
calculateField
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=calculateField.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { FieldProps, FieldSpec, FieldComponentRegistry, CalculatedField } from '@digigov/form/Field/types';
|
|
2
|
+
export declare function calculateField(children: FieldProps['children'], field: FieldSpec, fieldComponentRegistry: FieldComponentRegistry, alternativeComponents: FieldComponentRegistry): CalculatedField;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/Field/utils/calculateField.ts"],
|
|
4
|
+
"sourcesContent": ["import {\n FieldProps,\n FieldSpec,\n FieldComponentRegistry,\n CalculatedField,\n} from '@digigov/form/Field/types';\n\nexport function calculateField(\n children: FieldProps['children'],\n field: FieldSpec,\n fieldComponentRegistry: FieldComponentRegistry,\n alternativeComponents: FieldComponentRegistry\n): CalculatedField {\n const calculatedField = { ...field };\n if (children) {\n calculatedField.component = children;\n calculatedField.controlled = true;\n } else if (typeof field.component === 'function') {\n // leave as is\n } else if (!field.component && !field.type) {\n calculatedField.component = fieldComponentRegistry.string.component;\n calculatedField.controlled =\n fieldComponentRegistry.string?.controlled || false;\n } else if (\n typeof field?.extra?.component === 'string' &&\n alternativeComponents[field.extra.component]\n ) {\n calculatedField.controlled =\n alternativeComponents[field.extra.component]?.controlled || false;\n calculatedField.component =\n alternativeComponents[field.extra.component].component;\n calculatedField.wrapper =\n alternativeComponents[field.extra.component].wrapper;\n } else if (\n !field.component &&\n field.type &&\n fieldComponentRegistry[field.type]\n ) {\n calculatedField.component = fieldComponentRegistry[field.type].component;\n calculatedField.wrapper = fieldComponentRegistry[field.type].wrapper;\n calculatedField.controlled =\n fieldComponentRegistry[field.type]?.controlled || false;\n } else {\n calculatedField.component = fieldComponentRegistry.string.component;\n calculatedField.controlled =\n fieldComponentRegistry.string?.controlled || false;\n }\n return calculatedField as CalculatedField;\n}\n"],
|
|
5
|
+
"mappings": "AAOO,SAAS,eACd,UACA,OACA,wBACA,uBACiB;AACjB,QAAM,kBAAkB,EAAE,GAAG,MAAM;AACnC,MAAI,UAAU;AACZ,oBAAgB,YAAY;AAC5B,oBAAgB,aAAa;AAAA,EAC/B,WAAW,OAAO,MAAM,cAAc,YAAY;AAAA,EAElD,WAAW,CAAC,MAAM,aAAa,CAAC,MAAM,MAAM;AAC1C,oBAAgB,YAAY,uBAAuB,OAAO;AAC1D,oBAAgB,aACd,uBAAuB,QAAQ,cAAc;AAAA,EACjD,WACE,OAAO,OAAO,OAAO,cAAc,YACnC,sBAAsB,MAAM,MAAM,SAAS,GAC3C;AACA,oBAAgB,aACd,sBAAsB,MAAM,MAAM,SAAS,GAAG,cAAc;AAC9D,oBAAgB,YACd,sBAAsB,MAAM,MAAM,SAAS,EAAE;AAC/C,oBAAgB,UACd,sBAAsB,MAAM,MAAM,SAAS,EAAE;AAAA,EACjD,WACE,CAAC,MAAM,aACP,MAAM,QACN,uBAAuB,MAAM,IAAI,GACjC;AACA,oBAAgB,YAAY,uBAAuB,MAAM,IAAI,EAAE;AAC/D,oBAAgB,UAAU,uBAAuB,MAAM,IAAI,EAAE;AAC7D,oBAAgB,aACd,uBAAuB,MAAM,IAAI,GAAG,cAAc;AAAA,EACtD,OAAO;AACL,oBAAgB,YAAY,uBAAuB,OAAO;AAC1D,oBAAgB,aACd,uBAAuB,QAAQ,cAAc;AAAA,EACjD;AACA,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
function evaluateFieldWithConditions(field, variables) {
|
|
2
|
+
const newField = { ...field };
|
|
3
|
+
if (variables) {
|
|
4
|
+
for (const key in variables) {
|
|
5
|
+
if (field.condition[key] && field.condition[key].is) {
|
|
6
|
+
const is = field.condition[key].is;
|
|
7
|
+
if (is === variables[key] || Array.isArray(variables[key]) && variables[key].includes(is)) {
|
|
8
|
+
const then = field.condition[key].then || {};
|
|
9
|
+
for (const attr in then) {
|
|
10
|
+
newField[attr] = then[attr];
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
} else if (field.condition[key]) {
|
|
14
|
+
const otherwise = field.condition[key].else || {};
|
|
15
|
+
for (const attr in otherwise) {
|
|
16
|
+
newField[attr] = otherwise[attr];
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return newField;
|
|
22
|
+
}
|
|
23
|
+
export {
|
|
24
|
+
evaluateFieldWithConditions
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=evaluateFieldWithConditions.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/Field/utils/evaluateFieldWithConditions.ts"],
|
|
4
|
+
"sourcesContent": ["import { FieldWithCondition, CalculatedField } from '@digigov/form/Field/types';\n\nexport function evaluateFieldWithConditions(\n field: FieldWithCondition,\n variables: FormData\n): CalculatedField {\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": "AAEO,SAAS,4BACd,OACA,WACiB;AACjB,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
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { FieldComponentRegistry } from '@digigov/form/Field/types';
|
|
2
|
+
export declare const FIELD_COMPONENTS: FieldComponentRegistry;
|
|
3
|
+
export declare const ALTERNATIVE_COMPONENTS: FieldComponentRegistry;
|
|
4
|
+
export declare const CONTROLLED_FIELD_COMPONENTS: FieldComponentRegistry;
|
package/Field/utils/index.js
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { FormContext } from "@digigov/form/FormContext";
|
|
1
|
+
import AutoCompleteInput from "@digigov/form/inputs/AutoCompleteInput";
|
|
3
2
|
import Checkboxes from "@digigov/form/inputs/Checkboxes";
|
|
4
3
|
import DateInput from "@digigov/form/inputs/DateInput";
|
|
5
4
|
import FileInput from "@digigov/form/inputs/FileInput";
|
|
6
5
|
import ImageInput from "@digigov/form/inputs/ImageInput";
|
|
7
6
|
import Input from "@digigov/form/inputs/Input";
|
|
8
7
|
import OtpInput from "@digigov/form/inputs/OtpInput";
|
|
9
|
-
import Radio from "@digigov/form/inputs/Radio";
|
|
8
|
+
import Radio, { ControlledRadioButtonsGroup } from "@digigov/form/inputs/Radio";
|
|
10
9
|
import Select from "@digigov/form/inputs/Select";
|
|
11
|
-
import AutoCompleteInput from "@digigov/form/inputs/AutoCompleteInput";
|
|
12
10
|
const FIELD_COMPONENTS = {
|
|
13
11
|
text: {
|
|
14
12
|
component: Input
|
|
@@ -56,100 +54,25 @@ const ALTERNATIVE_COMPONENTS = {
|
|
|
56
54
|
wrapper: "fieldset"
|
|
57
55
|
}
|
|
58
56
|
};
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
} else if (!field.component && field.type && fieldComponentRegistry[field.type]) {
|
|
74
|
-
calculatedField.component = fieldComponentRegistry[field.type].component;
|
|
75
|
-
calculatedField.wrapper = fieldComponentRegistry[field.type].wrapper;
|
|
76
|
-
calculatedField.controlled = fieldComponentRegistry[field.type]?.controlled || false;
|
|
77
|
-
} else {
|
|
78
|
-
calculatedField.component = fieldComponentRegistry.string.component;
|
|
79
|
-
calculatedField.controlled = fieldComponentRegistry.string?.controlled || false;
|
|
80
|
-
}
|
|
81
|
-
return calculatedField;
|
|
82
|
-
}
|
|
83
|
-
const useField = (name, customField) => {
|
|
84
|
-
const {
|
|
85
|
-
fieldsMap,
|
|
86
|
-
control,
|
|
87
|
-
register,
|
|
88
|
-
reset,
|
|
89
|
-
trigger,
|
|
90
|
-
clearErrors,
|
|
91
|
-
errors,
|
|
92
|
-
registerField,
|
|
93
|
-
watch,
|
|
94
|
-
componentRegistry,
|
|
95
|
-
getFieldState,
|
|
96
|
-
setValue,
|
|
97
|
-
getValues,
|
|
98
|
-
unregister,
|
|
99
|
-
formState
|
|
100
|
-
} = useContext(FormContext);
|
|
101
|
-
if (!registerField) {
|
|
102
|
-
throw new Error(`
|
|
103
|
-
You can't use the Field component without wrapping it in FormBuilder.
|
|
104
|
-
https://devs.pages.grnet.gr/digigov/digigov-sdk/sdk-docs/forms/create-simple-form/
|
|
105
|
-
`);
|
|
57
|
+
const CONTROLLED_FIELD_COMPONENTS = {
|
|
58
|
+
...FIELD_COMPONENTS,
|
|
59
|
+
"choice:single": {
|
|
60
|
+
wrapper: "fieldset",
|
|
61
|
+
controlled: true,
|
|
62
|
+
component: ControlledRadioButtonsGroup
|
|
63
|
+
},
|
|
64
|
+
text: {
|
|
65
|
+
component: Input,
|
|
66
|
+
controlled: true
|
|
67
|
+
},
|
|
68
|
+
string: {
|
|
69
|
+
component: Input,
|
|
70
|
+
controlled: true
|
|
106
71
|
}
|
|
107
|
-
useMemo(
|
|
108
|
-
() => customField?.type && registerField({ ...customField, key: name }),
|
|
109
|
-
[customField, name, registerField]
|
|
110
|
-
);
|
|
111
|
-
return {
|
|
112
|
-
field: customField || fieldsMap[name],
|
|
113
|
-
control,
|
|
114
|
-
register,
|
|
115
|
-
reset,
|
|
116
|
-
trigger,
|
|
117
|
-
watch,
|
|
118
|
-
componentRegistry,
|
|
119
|
-
getFieldState,
|
|
120
|
-
setValue,
|
|
121
|
-
clearErrors,
|
|
122
|
-
getValues,
|
|
123
|
-
unregister,
|
|
124
|
-
formState,
|
|
125
|
-
error: errors[name]
|
|
126
|
-
};
|
|
127
72
|
};
|
|
128
|
-
function evaluateFieldWithConditions(field, variables) {
|
|
129
|
-
const newField = { ...field };
|
|
130
|
-
if (variables) {
|
|
131
|
-
for (const key in variables) {
|
|
132
|
-
if (field.condition[key] && field.condition[key].is) {
|
|
133
|
-
const is = field.condition[key].is;
|
|
134
|
-
if (is === variables[key] || Array.isArray(variables[key]) && variables[key].includes(is)) {
|
|
135
|
-
const then = field.condition[key].then || {};
|
|
136
|
-
for (const attr in then) {
|
|
137
|
-
newField[attr] = then[attr];
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
} else if (field.condition[key]) {
|
|
141
|
-
const otherwise = field.condition[key].else || {};
|
|
142
|
-
for (const attr in otherwise) {
|
|
143
|
-
newField[attr] = otherwise[attr];
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
return newField;
|
|
149
|
-
}
|
|
150
73
|
export {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
74
|
+
ALTERNATIVE_COMPONENTS,
|
|
75
|
+
CONTROLLED_FIELD_COMPONENTS,
|
|
76
|
+
FIELD_COMPONENTS
|
|
154
77
|
};
|
|
155
|
-
//# sourceMappingURL=
|
|
78
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/Field/utils/index.ts"],
|
|
4
|
+
"sourcesContent": ["import { FieldComponentRegistry } from '@digigov/form/Field/types';\nimport AutoCompleteInput from '@digigov/form/inputs/AutoCompleteInput';\nimport Checkboxes from '@digigov/form/inputs/Checkboxes';\nimport DateInput from '@digigov/form/inputs/DateInput';\nimport FileInput from '@digigov/form/inputs/FileInput';\nimport ImageInput from '@digigov/form/inputs/ImageInput';\nimport Input from '@digigov/form/inputs/Input';\nimport OtpInput from '@digigov/form/inputs/OtpInput';\nimport Radio, { ControlledRadioButtonsGroup } from '@digigov/form/inputs/Radio';\nimport Select from '@digigov/form/inputs/Select';\n\nexport const FIELD_COMPONENTS: FieldComponentRegistry = {\n text: {\n component: Input,\n },\n string: {\n component: Input,\n },\n file: {\n wrapper: 'fieldset',\n component: FileInput,\n },\n image: {\n wrapper: 'fieldset',\n component: ImageInput,\n },\n date: {\n wrapper: 'fieldset',\n controlled: true,\n component: DateInput,\n },\n otp: {\n wrapper: 'fieldset',\n controlled: true,\n component: OtpInput,\n },\n 'choice:multiple': {\n wrapper: 'fieldset',\n controlled: true,\n component: Checkboxes,\n },\n 'choice:single': {\n wrapper: 'fieldset',\n controlled: false,\n component: Radio,\n },\n};\n\nexport const ALTERNATIVE_COMPONENTS: FieldComponentRegistry = {\n Select: {\n component: Select,\n controlled: false,\n },\n AutoComplete: {\n component: AutoCompleteInput,\n controlled: true,\n wrapper: 'fieldset',\n },\n};\n\nexport const CONTROLLED_FIELD_COMPONENTS: FieldComponentRegistry = {\n ...FIELD_COMPONENTS,\n 'choice:single': {\n wrapper: 'fieldset',\n controlled: true,\n component: ControlledRadioButtonsGroup,\n },\n text: {\n component: Input,\n controlled: true,\n },\n string: {\n component: Input,\n controlled: true,\n },\n};\n"],
|
|
5
|
+
"mappings": "AACA,OAAO,uBAAuB;AAC9B,OAAO,gBAAgB;AACvB,OAAO,eAAe;AACtB,OAAO,eAAe;AACtB,OAAO,gBAAgB;AACvB,OAAO,WAAW;AAClB,OAAO,cAAc;AACrB,OAAO,SAAS,mCAAmC;AACnD,OAAO,YAAY;AAEZ,MAAM,mBAA2C;AAAA,EACtD,MAAM;AAAA,IACJ,WAAW;AAAA,EACb;AAAA,EACA,QAAQ;AAAA,IACN,WAAW;AAAA,EACb;AAAA,EACA,MAAM;AAAA,IACJ,SAAS;AAAA,IACT,WAAW;AAAA,EACb;AAAA,EACA,OAAO;AAAA,IACL,SAAS;AAAA,IACT,WAAW;AAAA,EACb;AAAA,EACA,MAAM;AAAA,IACJ,SAAS;AAAA,IACT,YAAY;AAAA,IACZ,WAAW;AAAA,EACb;AAAA,EACA,KAAK;AAAA,IACH,SAAS;AAAA,IACT,YAAY;AAAA,IACZ,WAAW;AAAA,EACb;AAAA,EACA,mBAAmB;AAAA,IACjB,SAAS;AAAA,IACT,YAAY;AAAA,IACZ,WAAW;AAAA,EACb;AAAA,EACA,iBAAiB;AAAA,IACf,SAAS;AAAA,IACT,YAAY;AAAA,IACZ,WAAW;AAAA,EACb;AACF;AAEO,MAAM,yBAAiD;AAAA,EAC5D,QAAQ;AAAA,IACN,WAAW;AAAA,IACX,YAAY;AAAA,EACd;AAAA,EACA,cAAc;AAAA,IACZ,WAAW;AAAA,IACX,YAAY;AAAA,IACZ,SAAS;AAAA,EACX;AACF;AAEO,MAAM,8BAAsD;AAAA,EACjE,GAAG;AAAA,EACH,iBAAiB;AAAA,IACf,SAAS;AAAA,IACT,YAAY;AAAA,IACZ,WAAW;AAAA,EACb;AAAA,EACA,MAAM;AAAA,IACJ,WAAW;AAAA,IACX,YAAY;AAAA,EACd;AAAA,EACA,QAAQ;AAAA,IACN,WAAW;AAAA,IACX,YAAY;AAAA,EACd;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { useContext, useMemo } from "react";
|
|
2
|
+
import { FormContext } from "@digigov/form/FormContext";
|
|
3
|
+
const useField = (name, customField) => {
|
|
4
|
+
const {
|
|
5
|
+
fieldsMap,
|
|
6
|
+
control,
|
|
7
|
+
register,
|
|
8
|
+
reset,
|
|
9
|
+
trigger,
|
|
10
|
+
clearErrors,
|
|
11
|
+
errors,
|
|
12
|
+
registerField,
|
|
13
|
+
watch,
|
|
14
|
+
componentRegistry,
|
|
15
|
+
getFieldState,
|
|
16
|
+
setValue,
|
|
17
|
+
getValues,
|
|
18
|
+
unregister,
|
|
19
|
+
formState
|
|
20
|
+
} = useContext(FormContext);
|
|
21
|
+
if (!registerField) {
|
|
22
|
+
throw new Error(`
|
|
23
|
+
You can't use the Field component without wrapping it in FormBuilder.
|
|
24
|
+
https://devs.pages.grnet.gr/digigov/digigov-sdk/sdk-docs/forms/create-simple-form/
|
|
25
|
+
`);
|
|
26
|
+
}
|
|
27
|
+
useMemo(
|
|
28
|
+
() => customField?.type && registerField({ ...customField, key: name }),
|
|
29
|
+
[customField, name, registerField]
|
|
30
|
+
);
|
|
31
|
+
return {
|
|
32
|
+
field: customField || fieldsMap[name],
|
|
33
|
+
control,
|
|
34
|
+
register,
|
|
35
|
+
reset,
|
|
36
|
+
trigger,
|
|
37
|
+
watch,
|
|
38
|
+
componentRegistry,
|
|
39
|
+
getFieldState,
|
|
40
|
+
setValue,
|
|
41
|
+
clearErrors,
|
|
42
|
+
getValues,
|
|
43
|
+
unregister,
|
|
44
|
+
formState,
|
|
45
|
+
error: errors[name]
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
export {
|
|
49
|
+
useField
|
|
50
|
+
};
|
|
51
|
+
//# sourceMappingURL=useField.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 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 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\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\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 trigger,\n watch,\n componentRegistry,\n getFieldState,\n setValue,\n clearErrors,\n getValues,\n unregister,\n formState,\n error: errors[name],\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,EACF,IAAI,WAAW,WAAW;AAE1B,MAAI,CAAC,eAAe;AAClB,UAAM,IAAI,MAAM;AAAA;AAAA;AAAA,KAGf;AAAA,EACH;AAEA;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,OAAO,OAAO,IAAI;AAAA,EACpB;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|