@flipdish/ui-library 0.51.0 → 0.53.0
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/README.md +17 -16
- package/dist/components/atoms/Checkbox/index.cjs +4 -2
- package/dist/components/atoms/Checkbox/index.cjs.map +1 -1
- package/dist/components/atoms/Checkbox/index.d.ts.map +1 -1
- package/dist/components/atoms/Checkbox/index.js +4 -2
- package/dist/components/atoms/Checkbox/index.js.map +1 -1
- package/dist/components/atoms/Slider/index.cjs +2 -2
- package/dist/components/atoms/Slider/index.cjs.map +1 -1
- package/dist/components/atoms/Slider/index.d.ts +3 -1
- package/dist/components/atoms/Slider/index.d.ts.map +1 -1
- package/dist/components/atoms/Slider/index.js +2 -2
- package/dist/components/atoms/Slider/index.js.map +1 -1
- package/dist/components/forms/Form/hooks/useForm.cjs +26 -0
- package/dist/components/forms/Form/hooks/useForm.cjs.map +1 -0
- package/dist/components/forms/Form/hooks/useForm.d.ts +13 -0
- package/dist/components/forms/Form/hooks/useForm.d.ts.map +1 -0
- package/dist/components/forms/Form/hooks/useForm.js +24 -0
- package/dist/components/forms/Form/hooks/useForm.js.map +1 -0
- package/dist/components/forms/Form/hooks/useSaveForm/useSaveForm.cjs +93 -0
- package/dist/components/forms/Form/hooks/useSaveForm/useSaveForm.cjs.map +1 -0
- package/dist/components/forms/Form/hooks/useSaveForm/useSaveForm.d.ts +54 -0
- package/dist/components/forms/Form/hooks/useSaveForm/useSaveForm.d.ts.map +1 -0
- package/dist/components/forms/Form/hooks/useSaveForm/useSaveForm.js +91 -0
- package/dist/components/forms/Form/hooks/useSaveForm/useSaveForm.js.map +1 -0
- package/dist/components/forms/Form/hooks/useSubmitInTurn/useSubmitInTurn.cjs +28 -0
- package/dist/components/forms/Form/hooks/useSubmitInTurn/useSubmitInTurn.cjs.map +1 -0
- package/dist/components/forms/Form/hooks/useSubmitInTurn/useSubmitInTurn.d.ts +10 -0
- package/dist/components/forms/Form/hooks/useSubmitInTurn/useSubmitInTurn.d.ts.map +1 -0
- package/dist/components/forms/Form/hooks/useSubmitInTurn/useSubmitInTurn.js +26 -0
- package/dist/components/forms/Form/hooks/useSubmitInTurn/useSubmitInTurn.js.map +1 -0
- package/dist/components/forms/Form/index.cjs +63 -0
- package/dist/components/forms/Form/index.cjs.map +1 -0
- package/dist/components/forms/Form/index.d.ts +37 -0
- package/dist/components/forms/Form/index.d.ts.map +1 -0
- package/dist/components/forms/Form/index.js +59 -0
- package/dist/components/forms/Form/index.js.map +1 -0
- package/dist/components/forms/Form/utilities/formSubmit.utils.cjs +23 -0
- package/dist/components/forms/Form/utilities/formSubmit.utils.cjs.map +1 -0
- package/dist/components/forms/Form/utilities/formSubmit.utils.d.ts +14 -0
- package/dist/components/forms/Form/utilities/formSubmit.utils.d.ts.map +1 -0
- package/dist/components/forms/Form/utilities/formSubmit.utils.js +21 -0
- package/dist/components/forms/Form/utilities/formSubmit.utils.js.map +1 -0
- package/dist/components/forms/FormFooter/hooks/useDestructiveConfirmation.cjs +39 -0
- package/dist/components/forms/FormFooter/hooks/useDestructiveConfirmation.cjs.map +1 -0
- package/dist/components/forms/FormFooter/hooks/useDestructiveConfirmation.d.ts +17 -0
- package/dist/components/forms/FormFooter/hooks/useDestructiveConfirmation.d.ts.map +1 -0
- package/dist/components/forms/FormFooter/hooks/useDestructiveConfirmation.js +37 -0
- package/dist/components/forms/FormFooter/hooks/useDestructiveConfirmation.js.map +1 -0
- package/dist/components/forms/FormFooter/hooks/useHasFieldError.cjs +26 -0
- package/dist/components/forms/FormFooter/hooks/useHasFieldError.cjs.map +1 -0
- package/dist/components/forms/FormFooter/hooks/useHasFieldError.d.ts +9 -0
- package/dist/components/forms/FormFooter/hooks/useHasFieldError.d.ts.map +1 -0
- package/dist/components/forms/FormFooter/hooks/useHasFieldError.js +24 -0
- package/dist/components/forms/FormFooter/hooks/useHasFieldError.js.map +1 -0
- package/dist/components/forms/FormFooter/index.cjs +41 -0
- package/dist/components/forms/FormFooter/index.cjs.map +1 -0
- package/dist/components/forms/FormFooter/index.d.ts +56 -0
- package/dist/components/forms/FormFooter/index.d.ts.map +1 -0
- package/dist/components/forms/FormFooter/index.js +39 -0
- package/dist/components/forms/FormFooter/index.js.map +1 -0
- package/dist/components/forms/FormFooter/utilities/formFooter.utils.cjs +21 -0
- package/dist/components/forms/FormFooter/utilities/formFooter.utils.cjs.map +1 -0
- package/dist/components/forms/FormFooter/utilities/formFooter.utils.d.ts +12 -0
- package/dist/components/forms/FormFooter/utilities/formFooter.utils.d.ts.map +1 -0
- package/dist/components/forms/FormFooter/utilities/formFooter.utils.js +19 -0
- package/dist/components/forms/FormFooter/utilities/formFooter.utils.js.map +1 -0
- package/dist/components/forms/FormSaveErrorAlert/index.cjs +28 -0
- package/dist/components/forms/FormSaveErrorAlert/index.cjs.map +1 -0
- package/dist/components/forms/FormSaveErrorAlert/index.d.ts +18 -0
- package/dist/components/forms/FormSaveErrorAlert/index.d.ts.map +1 -0
- package/dist/components/forms/FormSaveErrorAlert/index.js +26 -0
- package/dist/components/forms/FormSaveErrorAlert/index.js.map +1 -0
- package/dist/components/forms/FormSection/FormSection.styles.cjs +15 -0
- package/dist/components/forms/FormSection/FormSection.styles.cjs.map +1 -0
- package/dist/components/forms/FormSection/FormSection.styles.d.ts +9 -0
- package/dist/components/forms/FormSection/FormSection.styles.d.ts.map +1 -0
- package/dist/components/forms/FormSection/FormSection.styles.js +13 -0
- package/dist/components/forms/FormSection/FormSection.styles.js.map +1 -0
- package/dist/components/forms/FormSection/index.cjs +43 -0
- package/dist/components/forms/FormSection/index.cjs.map +1 -0
- package/dist/components/forms/FormSection/index.d.ts +41 -0
- package/dist/components/forms/FormSection/index.d.ts.map +1 -0
- package/dist/components/forms/FormSection/index.js +41 -0
- package/dist/components/forms/FormSection/index.js.map +1 -0
- package/dist/components/forms/FormUnsavedChangesModal/index.cjs +24 -0
- package/dist/components/forms/FormUnsavedChangesModal/index.cjs.map +1 -0
- package/dist/components/forms/FormUnsavedChangesModal/index.d.ts +14 -0
- package/dist/components/forms/FormUnsavedChangesModal/index.d.ts.map +1 -0
- package/dist/components/forms/FormUnsavedChangesModal/index.js +22 -0
- package/dist/components/forms/FormUnsavedChangesModal/index.js.map +1 -0
- package/dist/components/forms/__internal__/formField/hooks/useFocusTarget.cjs +28 -0
- package/dist/components/forms/__internal__/formField/hooks/useFocusTarget.cjs.map +1 -0
- package/dist/components/forms/__internal__/formField/hooks/useFocusTarget.d.ts +12 -0
- package/dist/components/forms/__internal__/formField/hooks/useFocusTarget.d.ts.map +1 -0
- package/dist/components/forms/__internal__/formField/hooks/useFocusTarget.js +26 -0
- package/dist/components/forms/__internal__/formField/hooks/useFocusTarget.js.map +1 -0
- package/dist/components/forms/__internal__/formField/hooks/useFocusThroughSubmit.cjs +68 -0
- package/dist/components/forms/__internal__/formField/hooks/useFocusThroughSubmit.cjs.map +1 -0
- package/dist/components/forms/__internal__/formField/hooks/useFocusThroughSubmit.d.ts +26 -0
- package/dist/components/forms/__internal__/formField/hooks/useFocusThroughSubmit.d.ts.map +1 -0
- package/dist/components/forms/__internal__/formField/hooks/useFocusThroughSubmit.js +66 -0
- package/dist/components/forms/__internal__/formField/hooks/useFocusThroughSubmit.js.map +1 -0
- package/dist/components/forms/__internal__/formField/hooks/useFormField.cjs +147 -0
- package/dist/components/forms/__internal__/formField/hooks/useFormField.cjs.map +1 -0
- package/dist/components/forms/__internal__/formField/hooks/useFormField.d.ts +35 -0
- package/dist/components/forms/__internal__/formField/hooks/useFormField.d.ts.map +1 -0
- package/dist/components/forms/__internal__/formField/hooks/useFormField.js +145 -0
- package/dist/components/forms/__internal__/formField/hooks/useFormField.js.map +1 -0
- package/dist/components/forms/__internal__/formField/providers/FieldElements.context.cjs +12 -0
- package/dist/components/forms/__internal__/formField/providers/FieldElements.context.cjs.map +1 -0
- package/dist/components/forms/__internal__/formField/providers/FieldElements.context.d.ts +7 -0
- package/dist/components/forms/__internal__/formField/providers/FieldElements.context.d.ts.map +1 -0
- package/dist/components/forms/__internal__/formField/providers/FieldElements.context.js +10 -0
- package/dist/components/forms/__internal__/formField/providers/FieldElements.context.js.map +1 -0
- package/dist/components/forms/__internal__/formField/utilities/fieldDependents.utils.cjs +47 -0
- package/dist/components/forms/__internal__/formField/utilities/fieldDependents.utils.cjs.map +1 -0
- package/dist/components/forms/__internal__/formField/utilities/fieldDependents.utils.d.ts +26 -0
- package/dist/components/forms/__internal__/formField/utilities/fieldDependents.utils.d.ts.map +1 -0
- package/dist/components/forms/__internal__/formField/utilities/fieldDependents.utils.js +43 -0
- package/dist/components/forms/__internal__/formField/utilities/fieldDependents.utils.js.map +1 -0
- package/dist/components/forms/__internal__/formField/utilities/fieldElements.utils.cjs +39 -0
- package/dist/components/forms/__internal__/formField/utilities/fieldElements.utils.cjs.map +1 -0
- package/dist/components/forms/__internal__/formField/utilities/fieldElements.utils.d.ts +21 -0
- package/dist/components/forms/__internal__/formField/utilities/fieldElements.utils.d.ts.map +1 -0
- package/dist/components/forms/__internal__/formField/utilities/fieldElements.utils.js +37 -0
- package/dist/components/forms/__internal__/formField/utilities/fieldElements.utils.js.map +1 -0
- package/dist/components/forms/__internal__/formField/utilities/fieldValue.utils.cjs +40 -0
- package/dist/components/forms/__internal__/formField/utilities/fieldValue.utils.cjs.map +1 -0
- package/dist/components/forms/__internal__/formField/utilities/fieldValue.utils.d.ts +18 -0
- package/dist/components/forms/__internal__/formField/utilities/fieldValue.utils.d.ts.map +1 -0
- package/dist/components/forms/__internal__/formField/utilities/fieldValue.utils.js +37 -0
- package/dist/components/forms/__internal__/formField/utilities/fieldValue.utils.js.map +1 -0
- package/dist/components/forms/__internal__/formField/utilities/formFocus.utils.cjs +21 -0
- package/dist/components/forms/__internal__/formField/utilities/formFocus.utils.cjs.map +1 -0
- package/dist/components/forms/__internal__/formField/utilities/formFocus.utils.d.ts +11 -0
- package/dist/components/forms/__internal__/formField/utilities/formFocus.utils.d.ts.map +1 -0
- package/dist/components/forms/__internal__/formField/utilities/formFocus.utils.js +19 -0
- package/dist/components/forms/__internal__/formField/utilities/formFocus.utils.js.map +1 -0
- package/dist/components/forms/__internal__/formField/utilities/validationQueue.utils.cjs +128 -0
- package/dist/components/forms/__internal__/formField/utilities/validationQueue.utils.cjs.map +1 -0
- package/dist/components/forms/__internal__/formField/utilities/validationQueue.utils.d.ts +72 -0
- package/dist/components/forms/__internal__/formField/utilities/validationQueue.utils.d.ts.map +1 -0
- package/dist/components/forms/__internal__/formField/utilities/validationQueue.utils.js +121 -0
- package/dist/components/forms/__internal__/formField/utilities/validationQueue.utils.js.map +1 -0
- package/dist/components/forms/__internal__/formSubmit/providers/FormSubmit.context.cjs +12 -0
- package/dist/components/forms/__internal__/formSubmit/providers/FormSubmit.context.cjs.map +1 -0
- package/dist/components/forms/__internal__/formSubmit/providers/FormSubmit.context.d.ts +6 -0
- package/dist/components/forms/__internal__/formSubmit/providers/FormSubmit.context.d.ts.map +1 -0
- package/dist/components/forms/__internal__/formSubmit/providers/FormSubmit.context.js +10 -0
- package/dist/components/forms/__internal__/formSubmit/providers/FormSubmit.context.js.map +1 -0
- package/dist/components/forms/fields/FormCheckbox/index.cjs +34 -0
- package/dist/components/forms/fields/FormCheckbox/index.cjs.map +1 -0
- package/dist/components/forms/fields/FormCheckbox/index.d.ts +19 -0
- package/dist/components/forms/fields/FormCheckbox/index.d.ts.map +1 -0
- package/dist/components/forms/fields/FormCheckbox/index.js +32 -0
- package/dist/components/forms/fields/FormCheckbox/index.js.map +1 -0
- package/dist/components/forms/fields/FormCheckboxGroup/index.cjs +33 -0
- package/dist/components/forms/fields/FormCheckboxGroup/index.cjs.map +1 -0
- package/dist/components/forms/fields/FormCheckboxGroup/index.d.ts +19 -0
- package/dist/components/forms/fields/FormCheckboxGroup/index.d.ts.map +1 -0
- package/dist/components/forms/fields/FormCheckboxGroup/index.js +31 -0
- package/dist/components/forms/fields/FormCheckboxGroup/index.js.map +1 -0
- package/dist/components/forms/fields/FormColorPicker/hooks/useEmptyFieldValue.cjs +26 -0
- package/dist/components/forms/fields/FormColorPicker/hooks/useEmptyFieldValue.cjs.map +1 -0
- package/dist/components/forms/fields/FormColorPicker/hooks/useEmptyFieldValue.d.ts +11 -0
- package/dist/components/forms/fields/FormColorPicker/hooks/useEmptyFieldValue.d.ts.map +1 -0
- package/dist/components/forms/fields/FormColorPicker/hooks/useEmptyFieldValue.js +24 -0
- package/dist/components/forms/fields/FormColorPicker/hooks/useEmptyFieldValue.js.map +1 -0
- package/dist/components/forms/fields/FormColorPicker/index.cjs +33 -0
- package/dist/components/forms/fields/FormColorPicker/index.cjs.map +1 -0
- package/dist/components/forms/fields/FormColorPicker/index.d.ts +24 -0
- package/dist/components/forms/fields/FormColorPicker/index.d.ts.map +1 -0
- package/dist/components/forms/fields/FormColorPicker/index.js +31 -0
- package/dist/components/forms/fields/FormColorPicker/index.js.map +1 -0
- package/dist/components/forms/fields/FormColorPicker/utilities/formColorPicker.utils.cjs +20 -0
- package/dist/components/forms/fields/FormColorPicker/utilities/formColorPicker.utils.cjs.map +1 -0
- package/dist/components/forms/fields/FormColorPicker/utilities/formColorPicker.utils.d.ts +17 -0
- package/dist/components/forms/fields/FormColorPicker/utilities/formColorPicker.utils.d.ts.map +1 -0
- package/dist/components/forms/fields/FormColorPicker/utilities/formColorPicker.utils.js +18 -0
- package/dist/components/forms/fields/FormColorPicker/utilities/formColorPicker.utils.js.map +1 -0
- package/dist/components/forms/fields/FormDatePicker/index.cjs +35 -0
- package/dist/components/forms/fields/FormDatePicker/index.cjs.map +1 -0
- package/dist/components/forms/fields/FormDatePicker/index.d.ts +20 -0
- package/dist/components/forms/fields/FormDatePicker/index.d.ts.map +1 -0
- package/dist/components/forms/fields/FormDatePicker/index.js +33 -0
- package/dist/components/forms/fields/FormDatePicker/index.js.map +1 -0
- package/dist/components/forms/fields/FormDatePicker/utilities/formDatePicker.utils.cjs +23 -0
- package/dist/components/forms/fields/FormDatePicker/utilities/formDatePicker.utils.cjs.map +1 -0
- package/dist/components/forms/fields/FormDatePicker/utilities/formDatePicker.utils.d.ts +9 -0
- package/dist/components/forms/fields/FormDatePicker/utilities/formDatePicker.utils.d.ts.map +1 -0
- package/dist/components/forms/fields/FormDatePicker/utilities/formDatePicker.utils.js +21 -0
- package/dist/components/forms/fields/FormDatePicker/utilities/formDatePicker.utils.js.map +1 -0
- package/dist/components/forms/fields/FormInput/index.cjs +27 -0
- package/dist/components/forms/fields/FormInput/index.cjs.map +1 -0
- package/dist/components/forms/fields/FormInput/index.d.ts +19 -0
- package/dist/components/forms/fields/FormInput/index.d.ts.map +1 -0
- package/dist/components/forms/fields/FormInput/index.js +25 -0
- package/dist/components/forms/fields/FormInput/index.js.map +1 -0
- package/dist/components/forms/fields/FormMultiSelect/index.cjs +44 -0
- package/dist/components/forms/fields/FormMultiSelect/index.cjs.map +1 -0
- package/dist/components/forms/fields/FormMultiSelect/index.d.ts +20 -0
- package/dist/components/forms/fields/FormMultiSelect/index.d.ts.map +1 -0
- package/dist/components/forms/fields/FormMultiSelect/index.js +42 -0
- package/dist/components/forms/fields/FormMultiSelect/index.js.map +1 -0
- package/dist/components/forms/fields/FormRadioCardGroup/index.cjs +36 -0
- package/dist/components/forms/fields/FormRadioCardGroup/index.cjs.map +1 -0
- package/dist/components/forms/fields/FormRadioCardGroup/index.d.ts +32 -0
- package/dist/components/forms/fields/FormRadioCardGroup/index.d.ts.map +1 -0
- package/dist/components/forms/fields/FormRadioCardGroup/index.js +34 -0
- package/dist/components/forms/fields/FormRadioCardGroup/index.js.map +1 -0
- package/dist/components/forms/fields/FormRadioGroup/index.cjs +31 -0
- package/dist/components/forms/fields/FormRadioGroup/index.cjs.map +1 -0
- package/dist/components/forms/fields/FormRadioGroup/index.d.ts +20 -0
- package/dist/components/forms/fields/FormRadioGroup/index.d.ts.map +1 -0
- package/dist/components/forms/fields/FormRadioGroup/index.js +29 -0
- package/dist/components/forms/fields/FormRadioGroup/index.js.map +1 -0
- package/dist/components/forms/fields/FormSelect/index.cjs +30 -0
- package/dist/components/forms/fields/FormSelect/index.cjs.map +1 -0
- package/dist/components/forms/fields/FormSelect/index.d.ts +19 -0
- package/dist/components/forms/fields/FormSelect/index.d.ts.map +1 -0
- package/dist/components/forms/fields/FormSelect/index.js +28 -0
- package/dist/components/forms/fields/FormSelect/index.js.map +1 -0
- package/dist/components/forms/fields/FormSlider/index.cjs +43 -0
- package/dist/components/forms/fields/FormSlider/index.cjs.map +1 -0
- package/dist/components/forms/fields/FormSlider/index.d.ts +20 -0
- package/dist/components/forms/fields/FormSlider/index.d.ts.map +1 -0
- package/dist/components/forms/fields/FormSlider/index.js +41 -0
- package/dist/components/forms/fields/FormSlider/index.js.map +1 -0
- package/dist/components/forms/fields/FormTextArea/index.cjs +27 -0
- package/dist/components/forms/fields/FormTextArea/index.cjs.map +1 -0
- package/dist/components/forms/fields/FormTextArea/index.d.ts +19 -0
- package/dist/components/forms/fields/FormTextArea/index.d.ts.map +1 -0
- package/dist/components/forms/fields/FormTextArea/index.js +25 -0
- package/dist/components/forms/fields/FormTextArea/index.js.map +1 -0
- package/dist/components/forms/fields/FormToggle/index.cjs +32 -0
- package/dist/components/forms/fields/FormToggle/index.cjs.map +1 -0
- package/dist/components/forms/fields/FormToggle/index.d.ts +19 -0
- package/dist/components/forms/fields/FormToggle/index.d.ts.map +1 -0
- package/dist/components/forms/fields/FormToggle/index.js +30 -0
- package/dist/components/forms/fields/FormToggle/index.js.map +1 -0
- package/dist/components/forms/validation/hooks/useSchemaResolver.cjs +44 -0
- package/dist/components/forms/validation/hooks/useSchemaResolver.cjs.map +1 -0
- package/dist/components/forms/validation/hooks/useSchemaResolver.d.ts +16 -0
- package/dist/components/forms/validation/hooks/useSchemaResolver.d.ts.map +1 -0
- package/dist/components/forms/validation/hooks/useSchemaResolver.js +42 -0
- package/dist/components/forms/validation/hooks/useSchemaResolver.js.map +1 -0
- package/dist/components/forms/validation/index.cjs +413 -0
- package/dist/components/forms/validation/index.cjs.map +1 -0
- package/dist/components/forms/validation/index.d.ts +278 -0
- package/dist/components/forms/validation/index.d.ts.map +1 -0
- package/dist/components/forms/validation/index.js +394 -0
- package/dist/components/forms/validation/index.js.map +1 -0
- package/dist/components/forms/validation/utilities/validation.utils.cjs +72 -0
- package/dist/components/forms/validation/utilities/validation.utils.cjs.map +1 -0
- package/dist/components/forms/validation/utilities/validation.utils.d.ts +38 -0
- package/dist/components/forms/validation/utilities/validation.utils.d.ts.map +1 -0
- package/dist/components/forms/validation/utilities/validation.utils.js +67 -0
- package/dist/components/forms/validation/utilities/validation.utils.js.map +1 -0
- package/dist/components/forms/validation/validation.types.d.ts +8 -0
- package/dist/components/forms/validation/validation.types.d.ts.map +1 -0
- package/dist/components/organisms/ColorPicker/components/ColorPickerField.cjs +13 -3
- package/dist/components/organisms/ColorPicker/components/ColorPickerField.cjs.map +1 -1
- package/dist/components/organisms/ColorPicker/components/ColorPickerField.d.ts +1 -1
- package/dist/components/organisms/ColorPicker/components/ColorPickerField.d.ts.map +1 -1
- package/dist/components/organisms/ColorPicker/components/ColorPickerField.js +13 -3
- package/dist/components/organisms/ColorPicker/components/ColorPickerField.js.map +1 -1
- package/dist/components/organisms/ColorPicker/hooks/useColorFieldEdit.cjs +2 -2
- package/dist/components/organisms/ColorPicker/hooks/useColorFieldEdit.cjs.map +1 -1
- package/dist/components/organisms/ColorPicker/hooks/useColorFieldEdit.d.ts +1 -0
- package/dist/components/organisms/ColorPicker/hooks/useColorFieldEdit.d.ts.map +1 -1
- package/dist/components/organisms/ColorPicker/hooks/useColorFieldEdit.js +2 -2
- package/dist/components/organisms/ColorPicker/hooks/useColorFieldEdit.js.map +1 -1
- package/dist/components/organisms/ColorPicker/hooks/useCssColorField.cjs +1 -1
- package/dist/components/organisms/ColorPicker/hooks/useCssColorField.js +1 -1
- package/dist/components/organisms/ColorPicker/index.cjs +1 -1
- package/dist/components/organisms/ColorPicker/index.d.ts.map +1 -1
- package/dist/components/organisms/ColorPicker/index.js +1 -1
- package/dist/components/organisms/ColorPicker/providers/ColorPicker.provider.d.ts +1 -1
- package/dist/components/organisms/ColorPicker/providers/ColorPicker.provider.d.ts.map +1 -1
- package/dist/components/organisms/ColorPicker/utilities/colorPicker.utils.cjs.map +1 -0
- package/dist/components/organisms/ColorPicker/utilities/colorPicker.utils.d.ts.map +1 -0
- package/dist/components/organisms/ColorPicker/utilities/colorPicker.utils.js.map +1 -0
- package/dist/components/organisms/GradientPicker/components/GradientStopRow.cjs +1 -1
- package/dist/components/organisms/GradientPicker/components/GradientStopRow.js +1 -1
- package/dist/hooks/useFocusAfterRetry/index.cjs +7 -3
- package/dist/hooks/useFocusAfterRetry/index.cjs.map +1 -1
- package/dist/hooks/useFocusAfterRetry/index.d.ts +8 -2
- package/dist/hooks/useFocusAfterRetry/index.d.ts.map +1 -1
- package/dist/hooks/useFocusAfterRetry/index.js +7 -3
- package/dist/hooks/useFocusAfterRetry/index.js.map +1 -1
- package/dist/localization/en.json.cjs +117 -0
- package/dist/localization/en.json.cjs.map +1 -0
- package/dist/localization/en.json.js +98 -0
- package/dist/localization/en.json.js.map +1 -0
- package/dist/native/components/forms/Form/index.d.ts +12 -0
- package/dist/native/components/forms/FormFooter/index.d.ts +12 -0
- package/dist/native/components/forms/FormSaveErrorAlert/index.d.ts +12 -0
- package/dist/native/components/forms/FormSection/index.d.ts +12 -0
- package/dist/native/components/forms/FormUnsavedChangesModal/index.d.ts +12 -0
- package/dist/native/components/forms/fields/FormCheckbox/index.d.ts +12 -0
- package/dist/native/components/forms/fields/FormCheckboxGroup/index.d.ts +12 -0
- package/dist/native/components/forms/fields/FormColorPicker/index.d.ts +12 -0
- package/dist/native/components/forms/fields/FormDatePicker/index.d.ts +12 -0
- package/dist/native/components/forms/fields/FormInput/index.d.ts +12 -0
- package/dist/native/components/forms/fields/FormMultiSelect/index.d.ts +12 -0
- package/dist/native/components/forms/fields/FormRadioCardGroup/index.d.ts +12 -0
- package/dist/native/components/forms/fields/FormRadioGroup/index.d.ts +12 -0
- package/dist/native/components/forms/fields/FormSelect/index.d.ts +12 -0
- package/dist/native/components/forms/fields/FormSlider/index.d.ts +12 -0
- package/dist/native/components/forms/fields/FormTextArea/index.d.ts +12 -0
- package/dist/native/components/forms/fields/FormToggle/index.d.ts +12 -0
- package/dist/native/components/forms/validation/index.d.ts +12 -0
- package/dist/native/utilities/colorUtils/index.d.ts +12 -0
- package/dist/providers/UnsavedChangesGuardProvider/index.cjs +1 -1
- package/dist/providers/UnsavedChangesGuardProvider/index.js +1 -1
- package/dist/providers/UnsavedChangesGuardProvider/utilities/unsavedChangesGuard.utils.cjs.map +1 -0
- package/dist/providers/UnsavedChangesGuardProvider/{unsavedChangesGuard.utils.d.ts → utilities/unsavedChangesGuard.utils.d.ts} +1 -1
- package/dist/providers/UnsavedChangesGuardProvider/utilities/unsavedChangesGuard.utils.d.ts.map +1 -0
- package/dist/providers/UnsavedChangesGuardProvider/utilities/unsavedChangesGuard.utils.js.map +1 -0
- package/dist/utilities/__internal__/builtInTextUtils/builtInText.utils.cjs +74 -0
- package/dist/utilities/__internal__/builtInTextUtils/builtInText.utils.cjs.map +1 -0
- package/dist/utilities/__internal__/builtInTextUtils/builtInText.utils.d.ts +51 -0
- package/dist/utilities/__internal__/builtInTextUtils/builtInText.utils.d.ts.map +1 -0
- package/dist/utilities/__internal__/builtInTextUtils/builtInText.utils.js +68 -0
- package/dist/utilities/__internal__/builtInTextUtils/builtInText.utils.js.map +1 -0
- package/dist/utilities/colorUtils/index.cjs +24 -0
- package/dist/utilities/colorUtils/index.cjs.map +1 -0
- package/dist/utilities/colorUtils/index.d.ts +8 -0
- package/dist/utilities/colorUtils/index.d.ts.map +1 -0
- package/dist/utilities/colorUtils/index.js +22 -0
- package/dist/utilities/colorUtils/index.js.map +1 -0
- package/package.json +41 -6
- package/dist/components/organisms/ColorPicker/colorPicker.utils.cjs.map +0 -1
- package/dist/components/organisms/ColorPicker/colorPicker.utils.d.ts.map +0 -1
- package/dist/components/organisms/ColorPicker/colorPicker.utils.js.map +0 -1
- package/dist/providers/UnsavedChangesGuardProvider/unsavedChangesGuard.utils.cjs.map +0 -1
- package/dist/providers/UnsavedChangesGuardProvider/unsavedChangesGuard.utils.d.ts.map +0 -1
- package/dist/providers/UnsavedChangesGuardProvider/unsavedChangesGuard.utils.js.map +0 -1
- /package/dist/components/organisms/ColorPicker/{colorPicker.utils.cjs → utilities/colorPicker.utils.cjs} +0 -0
- /package/dist/components/organisms/ColorPicker/{colorPicker.utils.d.ts → utilities/colorPicker.utils.d.ts} +0 -0
- /package/dist/components/organisms/ColorPicker/{colorPicker.utils.js → utilities/colorPicker.utils.js} +0 -0
- /package/dist/providers/UnsavedChangesGuardProvider/{unsavedChangesGuard.utils.cjs → utilities/unsavedChangesGuard.utils.cjs} +0 -0
- /package/dist/providers/UnsavedChangesGuardProvider/{unsavedChangesGuard.utils.js → utilities/unsavedChangesGuard.utils.js} +0 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
4
|
+
var Toggle = require('@flipdish/ui-library/components/atoms/Toggle');
|
|
5
|
+
var useFocusTarget = require('../../__internal__/formField/hooks/useFocusTarget.cjs');
|
|
6
|
+
var useFormField = require('../../__internal__/formField/hooks/useFormField.cjs');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A `Toggle` bound to a react-hook-form field: flipping it writes a boolean to the form and validates it at once, and
|
|
10
|
+
* the field's error shows in place of `hint`. Use it for a single on or off setting in a form built with react-hook-form.
|
|
11
|
+
*
|
|
12
|
+
* @summary toggle bound to a react-hook-form field
|
|
13
|
+
*/
|
|
14
|
+
const FormToggle = ({ name, revalidates, hint, ...toggleProps }) => {
|
|
15
|
+
const { value, ref, onCommit, onBlur, isInvalid, errorMessage, isDisabled, isLocked } = useFormField.useFormField(name, revalidates);
|
|
16
|
+
// react-aria's switch sets `aria-invalid` on its input from `isInvalid`, which the types of `Switch` leave out.
|
|
17
|
+
const invalidProps = { isInvalid };
|
|
18
|
+
// `Toggle` takes no ref, so a layout-neutral wrapper hands the form the input inside it.
|
|
19
|
+
const focusRef = useFocusTarget.useFocusTarget(ref, 'input');
|
|
20
|
+
return (jsxRuntime.jsx("div", { ref: focusRef, className: "contents", children: jsxRuntime.jsx(Toggle.Toggle, { ...toggleProps, ...invalidProps, name: name,
|
|
21
|
+
// An unset field is `undefined`, which would flip the toggle between uncontrolled and controlled.
|
|
22
|
+
isSelected: value ?? false, onChange: onCommit, onBlur: onBlur, isDisabled: toggleProps.isDisabled || isDisabled,
|
|
23
|
+
// Read-only while the form submits: the field keeps its focus and its value, and nothing typed meanwhile is lost to the save.
|
|
24
|
+
isReadOnly: toggleProps.isReadOnly || isLocked,
|
|
25
|
+
// The control gives its hint no error colour, so the message brings its own.
|
|
26
|
+
hint: errorMessage ? (
|
|
27
|
+
// An alert, since the error can appear while focus stays on the control, where a changed label is not announced.
|
|
28
|
+
jsxRuntime.jsx("span", { role: "alert", className: "text-error-primary", children: errorMessage })) : (hint) }) }));
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
exports.FormToggle = FormToggle;
|
|
32
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../../../../src/components/forms/fields/FormToggle/index.tsx"],"sourcesContent":[null],"names":["useFormField","useFocusTarget","_jsx","Toggle"],"mappings":";;;;;;;AAkBA;;;;;AAKG;AACI,MAAM,UAAU,GAAG,CAA4C,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,WAAW,EAA4B,KAAI;IAC7I,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAGA,yBAAY,CAAmB,IAAI,EAAE,WAAW,CAAC;;AAEzI,IAAA,MAAM,YAAY,GAAG,EAAE,SAAS,EAA0B;;IAE1D,MAAM,QAAQ,GAAGC,6BAAc,CAAC,GAAG,EAAE,OAAO,CAAC;AAE7C,IAAA,QACEC,cAAA,CAAA,KAAA,EAAA,EAAK,GAAG,EAAE,QAAQ,EAAE,SAAS,EAAC,UAAU,YACtCA,cAAA,CAACC,aAAM,OACD,WAAW,EAAA,GACX,YAAY,EAChB,IAAI,EAAE,IAAI;;AAEV,YAAA,UAAU,EAAE,KAAK,IAAI,KAAK,EAC1B,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,WAAW,CAAC,UAAU,IAAI,UAAU;;AAEhD,YAAA,UAAU,EAAE,WAAW,CAAC,UAAU,IAAI,QAAQ;;AAE9C,YAAA,IAAI,EACF,YAAY;;YAEVD,cAAA,CAAA,MAAA,EAAA,EAAM,IAAI,EAAC,OAAO,EAAC,SAAS,EAAC,oBAAoB,YAC9C,YAAY,EAAA,CACR,KAEP,IAAI,CACL,EAAA,CAEH,EAAA,CACE;AAEV;;"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type ToggleProps } from '@flipdish/ui-library/components/atoms/Toggle';
|
|
2
|
+
import type { FieldPath, FieldValues } from 'react-hook-form';
|
|
3
|
+
export interface FormToggleProps<TValues extends FieldValues = FieldValues> extends Omit<ToggleProps, 'name' | 'isSelected' | 'defaultSelected' | 'onChange' | 'onBlur' | 'ref'> {
|
|
4
|
+
/** The field's path in the form values, such as `isPublished` or `notifications.email`. */
|
|
5
|
+
name: FieldPath<TValues>;
|
|
6
|
+
/**
|
|
7
|
+
* Other fields to re-validate when this changes. A `crossFieldRules` rule validated through `useSchemaResolver` names them
|
|
8
|
+
* itself, so pass this only for a rule written another way, such as a zod `superRefine` in the same schema, or for a nested field.
|
|
9
|
+
*/
|
|
10
|
+
revalidates?: FieldPath<TValues> | FieldPath<TValues>[];
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* A `Toggle` bound to a react-hook-form field: flipping it writes a boolean to the form and validates it at once, and
|
|
14
|
+
* the field's error shows in place of `hint`. Use it for a single on or off setting in a form built with react-hook-form.
|
|
15
|
+
*
|
|
16
|
+
* @summary toggle bound to a react-hook-form field
|
|
17
|
+
*/
|
|
18
|
+
export declare const FormToggle: <TValues extends FieldValues = FieldValues>({ name, revalidates, hint, ...toggleProps }: FormToggleProps<TValues>) => import("react").JSX.Element;
|
|
19
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/forms/fields/FormToggle/index.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAU,KAAK,WAAW,EAAE,MAAM,8CAA8C,CAAC;AACxF,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAI9D,MAAM,WAAW,eAAe,CAAC,OAAO,SAAS,WAAW,GAAG,WAAW,CACxE,SAAQ,IAAI,CAAC,WAAW,EAAE,MAAM,GAAG,YAAY,GAAG,iBAAiB,GAAG,UAAU,GAAG,QAAQ,GAAG,KAAK,CAAC;IACpG,2FAA2F;IAC3F,IAAI,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC;IACzB;;;OAGG;IACH,WAAW,CAAC,EAAE,SAAS,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC;CACzD;AAED;;;;;GAKG;AACH,eAAO,MAAM,UAAU,GAAI,OAAO,SAAS,WAAW,GAAG,WAAW,EAAE,6CAA6C,eAAe,CAAC,OAAO,CAAC,gCAkC1I,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { Toggle } from '@flipdish/ui-library/components/atoms/Toggle';
|
|
3
|
+
import { useFocusTarget } from '../../__internal__/formField/hooks/useFocusTarget.js';
|
|
4
|
+
import { useFormField } from '../../__internal__/formField/hooks/useFormField.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A `Toggle` bound to a react-hook-form field: flipping it writes a boolean to the form and validates it at once, and
|
|
8
|
+
* the field's error shows in place of `hint`. Use it for a single on or off setting in a form built with react-hook-form.
|
|
9
|
+
*
|
|
10
|
+
* @summary toggle bound to a react-hook-form field
|
|
11
|
+
*/
|
|
12
|
+
const FormToggle = ({ name, revalidates, hint, ...toggleProps }) => {
|
|
13
|
+
const { value, ref, onCommit, onBlur, isInvalid, errorMessage, isDisabled, isLocked } = useFormField(name, revalidates);
|
|
14
|
+
// react-aria's switch sets `aria-invalid` on its input from `isInvalid`, which the types of `Switch` leave out.
|
|
15
|
+
const invalidProps = { isInvalid };
|
|
16
|
+
// `Toggle` takes no ref, so a layout-neutral wrapper hands the form the input inside it.
|
|
17
|
+
const focusRef = useFocusTarget(ref, 'input');
|
|
18
|
+
return (jsx("div", { ref: focusRef, className: "contents", children: jsx(Toggle, { ...toggleProps, ...invalidProps, name: name,
|
|
19
|
+
// An unset field is `undefined`, which would flip the toggle between uncontrolled and controlled.
|
|
20
|
+
isSelected: value ?? false, onChange: onCommit, onBlur: onBlur, isDisabled: toggleProps.isDisabled || isDisabled,
|
|
21
|
+
// Read-only while the form submits: the field keeps its focus and its value, and nothing typed meanwhile is lost to the save.
|
|
22
|
+
isReadOnly: toggleProps.isReadOnly || isLocked,
|
|
23
|
+
// The control gives its hint no error colour, so the message brings its own.
|
|
24
|
+
hint: errorMessage ? (
|
|
25
|
+
// An alert, since the error can appear while focus stays on the control, where a changed label is not announced.
|
|
26
|
+
jsx("span", { role: "alert", className: "text-error-primary", children: errorMessage })) : (hint) }) }));
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export { FormToggle };
|
|
30
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../../src/components/forms/fields/FormToggle/index.tsx"],"sourcesContent":[null],"names":["_jsx"],"mappings":";;;;;AAkBA;;;;;AAKG;AACI,MAAM,UAAU,GAAG,CAA4C,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,GAAG,WAAW,EAA4B,KAAI;IAC7I,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,GAAG,YAAY,CAAmB,IAAI,EAAE,WAAW,CAAC;;AAEzI,IAAA,MAAM,YAAY,GAAG,EAAE,SAAS,EAA0B;;IAE1D,MAAM,QAAQ,GAAG,cAAc,CAAC,GAAG,EAAE,OAAO,CAAC;AAE7C,IAAA,QACEA,GAAA,CAAA,KAAA,EAAA,EAAK,GAAG,EAAE,QAAQ,EAAE,SAAS,EAAC,UAAU,YACtCA,GAAA,CAAC,MAAM,OACD,WAAW,EAAA,GACX,YAAY,EAChB,IAAI,EAAE,IAAI;;AAEV,YAAA,UAAU,EAAE,KAAK,IAAI,KAAK,EAC1B,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,WAAW,CAAC,UAAU,IAAI,UAAU;;AAEhD,YAAA,UAAU,EAAE,WAAW,CAAC,UAAU,IAAI,QAAQ;;AAE9C,YAAA,IAAI,EACF,YAAY;;YAEVA,GAAA,CAAA,MAAA,EAAA,EAAM,IAAI,EAAC,OAAO,EAAC,SAAS,EAAC,oBAAoB,YAC9C,YAAY,EAAA,CACR,KAEP,IAAI,CACL,EAAA,CAEH,EAAA,CACE;AAEV;;"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var resolvers = require('@hookform/resolvers');
|
|
4
|
+
var React = require('react');
|
|
5
|
+
var fieldDependents_utils = require('../../__internal__/formField/utilities/fieldDependents.utils.cjs');
|
|
6
|
+
var validation_utils = require('../utilities/validation.utils.cjs');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Validates a form with its zod schema and shows each rule's message as text: the message goes through the app's
|
|
10
|
+
* `translate` with the rule's values, such as `{ min: 2 }`, so a schema keeps translation keys as its messages. Use it
|
|
11
|
+
* as `useForm`'s `resolver` in place of `zodResolver`.
|
|
12
|
+
*
|
|
13
|
+
* @param schema The form's zod schema.
|
|
14
|
+
* @param translate The app's translation function, called with a message and the values for its placeholders. Without
|
|
15
|
+
* one a message is shown as written, with its `{name}` placeholders filled.
|
|
16
|
+
* @returns The `resolver` for `useForm`. A field shows the message of the first rule it breaks, and the `Form*` fields
|
|
17
|
+
* read from it which fields the schema's `crossFieldRules` tie together.
|
|
18
|
+
*/
|
|
19
|
+
const useSchemaResolver = (schema, translate) => React.useMemo(() => {
|
|
20
|
+
// An app's `translate` often takes only its own keys; a message it does not know comes back as written.
|
|
21
|
+
const toText = validation_utils.messageText(translate);
|
|
22
|
+
const resolver = async (values, _context, options) => {
|
|
23
|
+
const result = await schema.safeParseAsync(values);
|
|
24
|
+
if (result.success) {
|
|
25
|
+
// Clears the message a failed parse left on each input, or the browser goes on calling a corrected field invalid.
|
|
26
|
+
if (options.shouldUseNativeValidation)
|
|
27
|
+
resolvers.validateFieldsNatively({}, options);
|
|
28
|
+
return { values: result.data, errors: {} };
|
|
29
|
+
}
|
|
30
|
+
// No prototype: a field named `toString` would otherwise look as if it already had an error, and lose its own.
|
|
31
|
+
const errors = Object.create(null);
|
|
32
|
+
for (const issue of result.error.issues) {
|
|
33
|
+
const path = issue.path.join('.');
|
|
34
|
+
errors[path] ?? (errors[path] = { type: issue.code, message: toText(issue.message, validation_utils.valuesOf(issue)) });
|
|
35
|
+
}
|
|
36
|
+
return { values: {}, errors: resolvers.toNestErrors(errors, options) };
|
|
37
|
+
};
|
|
38
|
+
// The form holds this resolver and never the schema, so the fields read which of them a rule ties together from here.
|
|
39
|
+
fieldDependents_utils.recordDependents(resolver, validation_utils.crossFieldDependentsOf(schema));
|
|
40
|
+
return resolver;
|
|
41
|
+
}, [schema, translate]);
|
|
42
|
+
|
|
43
|
+
exports.useSchemaResolver = useSchemaResolver;
|
|
44
|
+
//# sourceMappingURL=useSchemaResolver.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSchemaResolver.cjs","sources":["../../../../../src/components/forms/validation/hooks/useSchemaResolver.ts"],"sourcesContent":[null],"names":["useMemo","messageText","validateFieldsNatively","valuesOf","toNestErrors","recordDependents","crossFieldDependentsOf"],"mappings":";;;;;;;AAQA;;;;;;;;;;AAUG;AACI,MAAM,iBAAiB,GAAG,CAC/B,MAAe,EACf,SAAyD,KAEzDA,aAAO,CAAC,MAAK;;AAEX,IAAA,MAAM,MAAM,GAAGC,4BAAW,CAAC,SAAkC,CAAC;IAE9D,MAAM,QAAQ,GAA2D,OAAO,MAAM,EAAE,QAAQ,EAAE,OAAO,KAAI;QAC3G,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC;AAClD,QAAA,IAAI,MAAM,CAAC,OAAO,EAAE;;YAElB,IAAI,OAAO,CAAC,yBAAyB;AAAE,gBAAAC,gCAAsB,CAAC,EAAE,EAAE,OAAO,CAAC;YAC1E,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE;QAC5C;;QAGA,MAAM,MAAM,GAA+B,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;QAC9D,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE;YACvC,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;AACjC,YAAA,MAAM,CAAC,IAAI,CAAA,KAAX,MAAM,CAAC,IAAI,CAAA,GAAM,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,OAAO,EAAEC,yBAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAA;QACxF;AACA,QAAA,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAEC,sBAAY,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE;AAC9D,IAAA,CAAC;;IAEDC,sCAAgB,CAAC,QAAQ,EAAEC,uCAAsB,CAAC,MAAM,CAAC,CAAC;AAC1D,IAAA,OAAO,QAAQ;AACjB,CAAC,EAAE,CAAC,MAAM,EAAE,SAAS,CAAC;;"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { FieldValues, Resolver } from 'react-hook-form';
|
|
2
|
+
import type { z } from 'zod';
|
|
3
|
+
import type { MessageValues } from '../validation.types';
|
|
4
|
+
/**
|
|
5
|
+
* Validates a form with its zod schema and shows each rule's message as text: the message goes through the app's
|
|
6
|
+
* `translate` with the rule's values, such as `{ min: 2 }`, so a schema keeps translation keys as its messages. Use it
|
|
7
|
+
* as `useForm`'s `resolver` in place of `zodResolver`.
|
|
8
|
+
*
|
|
9
|
+
* @param schema The form's zod schema.
|
|
10
|
+
* @param translate The app's translation function, called with a message and the values for its placeholders. Without
|
|
11
|
+
* one a message is shown as written, with its `{name}` placeholders filled.
|
|
12
|
+
* @returns The `resolver` for `useForm`. A field shows the message of the first rule it breaks, and the `Form*` fields
|
|
13
|
+
* read from it which fields the schema's `crossFieldRules` tie together.
|
|
14
|
+
*/
|
|
15
|
+
export declare const useSchemaResolver: <TSchema extends z.ZodType<FieldValues, FieldValues>, TKey extends string = string>(schema: TSchema, translate?: (key: TKey, values?: MessageValues) => string) => Resolver<z.input<TSchema>, unknown, z.output<TSchema>>;
|
|
16
|
+
//# sourceMappingURL=useSchemaResolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSchemaResolver.d.ts","sourceRoot":"","sources":["../../../../../src/components/forms/validation/hooks/useSchemaResolver.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAc,WAAW,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AACzE,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAG7B,OAAO,KAAK,EAAE,aAAa,EAAa,MAAM,qBAAqB,CAAC;AAEpE;;;;;;;;;;GAUG;AACH,eAAO,MAAM,iBAAiB,GAAI,OAAO,SAAS,CAAC,CAAC,OAAO,CAAC,WAAW,EAAE,WAAW,CAAC,EAAE,IAAI,SAAS,MAAM,GAAG,MAAM,EACjH,QAAQ,OAAO,EACf,YAAY,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,EAAE,aAAa,KAAK,MAAM,KACxD,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAwB/B,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { validateFieldsNatively, toNestErrors } from '@hookform/resolvers';
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
import { recordDependents } from '../../__internal__/formField/utilities/fieldDependents.utils.js';
|
|
4
|
+
import { crossFieldDependentsOf, valuesOf, messageText } from '../utilities/validation.utils.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Validates a form with its zod schema and shows each rule's message as text: the message goes through the app's
|
|
8
|
+
* `translate` with the rule's values, such as `{ min: 2 }`, so a schema keeps translation keys as its messages. Use it
|
|
9
|
+
* as `useForm`'s `resolver` in place of `zodResolver`.
|
|
10
|
+
*
|
|
11
|
+
* @param schema The form's zod schema.
|
|
12
|
+
* @param translate The app's translation function, called with a message and the values for its placeholders. Without
|
|
13
|
+
* one a message is shown as written, with its `{name}` placeholders filled.
|
|
14
|
+
* @returns The `resolver` for `useForm`. A field shows the message of the first rule it breaks, and the `Form*` fields
|
|
15
|
+
* read from it which fields the schema's `crossFieldRules` tie together.
|
|
16
|
+
*/
|
|
17
|
+
const useSchemaResolver = (schema, translate) => useMemo(() => {
|
|
18
|
+
// An app's `translate` often takes only its own keys; a message it does not know comes back as written.
|
|
19
|
+
const toText = messageText(translate);
|
|
20
|
+
const resolver = async (values, _context, options) => {
|
|
21
|
+
const result = await schema.safeParseAsync(values);
|
|
22
|
+
if (result.success) {
|
|
23
|
+
// Clears the message a failed parse left on each input, or the browser goes on calling a corrected field invalid.
|
|
24
|
+
if (options.shouldUseNativeValidation)
|
|
25
|
+
validateFieldsNatively({}, options);
|
|
26
|
+
return { values: result.data, errors: {} };
|
|
27
|
+
}
|
|
28
|
+
// No prototype: a field named `toString` would otherwise look as if it already had an error, and lose its own.
|
|
29
|
+
const errors = Object.create(null);
|
|
30
|
+
for (const issue of result.error.issues) {
|
|
31
|
+
const path = issue.path.join('.');
|
|
32
|
+
errors[path] ?? (errors[path] = { type: issue.code, message: toText(issue.message, valuesOf(issue)) });
|
|
33
|
+
}
|
|
34
|
+
return { values: {}, errors: toNestErrors(errors, options) };
|
|
35
|
+
};
|
|
36
|
+
// The form holds this resolver and never the schema, so the fields read which of them a rule ties together from here.
|
|
37
|
+
recordDependents(resolver, crossFieldDependentsOf(schema));
|
|
38
|
+
return resolver;
|
|
39
|
+
}, [schema, translate]);
|
|
40
|
+
|
|
41
|
+
export { useSchemaResolver };
|
|
42
|
+
//# sourceMappingURL=useSchemaResolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSchemaResolver.js","sources":["../../../../../src/components/forms/validation/hooks/useSchemaResolver.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;AAQA;;;;;;;;;;AAUG;AACI,MAAM,iBAAiB,GAAG,CAC/B,MAAe,EACf,SAAyD,KAEzD,OAAO,CAAC,MAAK;;AAEX,IAAA,MAAM,MAAM,GAAG,WAAW,CAAC,SAAkC,CAAC;IAE9D,MAAM,QAAQ,GAA2D,OAAO,MAAM,EAAE,QAAQ,EAAE,OAAO,KAAI;QAC3G,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC;AAClD,QAAA,IAAI,MAAM,CAAC,OAAO,EAAE;;YAElB,IAAI,OAAO,CAAC,yBAAyB;AAAE,gBAAA,sBAAsB,CAAC,EAAE,EAAE,OAAO,CAAC;YAC1E,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE;QAC5C;;QAGA,MAAM,MAAM,GAA+B,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;QAC9D,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE;YACvC,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;AACjC,YAAA,MAAM,CAAC,IAAI,CAAA,KAAX,MAAM,CAAC,IAAI,CAAA,GAAM,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAA;QACxF;AACA,QAAA,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,YAAY,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE;AAC9D,IAAA,CAAC;;IAED,gBAAgB,CAAC,QAAQ,EAAE,sBAAsB,CAAC,MAAM,CAAC,CAAC;AAC1D,IAAA,OAAO,QAAQ;AACjB,CAAC,EAAE,CAAC,MAAM,EAAE,SAAS,CAAC;;"}
|
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var zod = require('zod');
|
|
4
|
+
var builtInText_utils = require('../../../utilities/__internal__/builtInTextUtils/builtInText.utils.cjs');
|
|
5
|
+
var validation_utils = require('./utilities/validation.utils.cjs');
|
|
6
|
+
var useSchemaResolver = require('./hooks/useSchemaResolver.cjs');
|
|
7
|
+
|
|
8
|
+
// A decimal amount of zero or more with at most two decimal places, such as 15 or 12.50.
|
|
9
|
+
const AMOUNT = /^\d+(\.\d{1,2})?$/;
|
|
10
|
+
const NUMBER = /^-?\d+(\.\d+)?$/;
|
|
11
|
+
const WHOLE_NUMBER = /^-?\d+$/;
|
|
12
|
+
const DIGITS = /^\d+$/;
|
|
13
|
+
const HEX_COLOUR = /^#[0-9a-f]{6}$/i;
|
|
14
|
+
const HEX_COLOUR_WITH_ALPHA = /^#(?:[0-9a-f]{6}|[0-9a-f]{8})$/i;
|
|
15
|
+
/**
|
|
16
|
+
* Accepts a phone number that is plausible to dial: digits with optional spaces, brackets, dashes and a leading `+`.
|
|
17
|
+
*
|
|
18
|
+
* @param phone The number as typed.
|
|
19
|
+
* @returns `true` when it has 7 to 15 digits and nothing else but those separators.
|
|
20
|
+
*/
|
|
21
|
+
const isPlausiblePhone = (phone) => {
|
|
22
|
+
const digits = phone.replace(/\D/g, '');
|
|
23
|
+
return /^\+?[\d\s()-]+$/.test(phone) && digits.length >= 7 && digits.length <= 15;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Reads a rule's limit and the message for breaking it.
|
|
27
|
+
*
|
|
28
|
+
* @param rule The limit, alone or with its message.
|
|
29
|
+
* @param defaultId The library message shown when the rule names none.
|
|
30
|
+
* @returns The limit and the message to show.
|
|
31
|
+
*/
|
|
32
|
+
const limitOf = (rule, defaultId) => Array.isArray(rule) ? rule : [rule, builtInText_utils.builtInTextTemplate(defaultId)];
|
|
33
|
+
/**
|
|
34
|
+
* Reads the message for an empty field.
|
|
35
|
+
*
|
|
36
|
+
* @param required The field's `required` rule.
|
|
37
|
+
* @param defaultId The library message shown when the rule names none.
|
|
38
|
+
* @returns The message to show, or `undefined` for an optional field.
|
|
39
|
+
*/
|
|
40
|
+
const requiredMessage = (required, defaultId = 'This_field_is_required') => {
|
|
41
|
+
if (typeof required === 'string')
|
|
42
|
+
return required || undefined;
|
|
43
|
+
return required ? builtInText_utils.builtInTextTemplate(defaultId) : undefined;
|
|
44
|
+
};
|
|
45
|
+
const POSTCODE = 'Enter_a_postcode_such_as_{example}';
|
|
46
|
+
const ZIP_CODE = { pattern: /^\d{5}(?:-\d{4})?$/, messageId: 'Enter_a_ZIP_code_such_as_{example}' };
|
|
47
|
+
// The shapes the API's address forms accept, not proof a postcode exists: the address service checks that when the order is placed.
|
|
48
|
+
const POSTCODE_RULES = {
|
|
49
|
+
IE: { pattern: /^(?:[AC-FHKNPRTV-Y]\d{2}|D6W)\s?[0-9AC-FHKNPRTV-Y]{4}$/i, messageId: 'Enter_an_Eircode_such_as_D02_X285', example: 'D02 X285' },
|
|
50
|
+
GB: {
|
|
51
|
+
pattern: /^(?:[A-Z][A-HJ-Y]?\d[A-Z\d]?\s?\d[A-Z]{2}|GIR\s?0AA)$/i,
|
|
52
|
+
messageId: 'Enter_a_UK_postcode_such_as_SW1A_1AA',
|
|
53
|
+
example: 'SW1A 1AA',
|
|
54
|
+
},
|
|
55
|
+
US: { ...ZIP_CODE, example: '10001' },
|
|
56
|
+
CA: {
|
|
57
|
+
pattern: /^[ABCEGHJ-NPRSTVXY]\d[ABCEGHJ-NPRSTV-Z][ -]?\d[ABCEGHJ-NPRSTV-Z]\d$/i,
|
|
58
|
+
messageId: 'Enter_a_postal_code_such_as_{example}',
|
|
59
|
+
example: 'K1A 0B1',
|
|
60
|
+
},
|
|
61
|
+
FR: { pattern: /^(?:[Ff]-)?(?:2[AB]|\d{2})\d{3}$/, messageId: POSTCODE, example: '75001' },
|
|
62
|
+
DE: { pattern: /^(?:0[1-46-9]\d{3}|[1-357-9]\d{4}|4[0-24-9]\d{3}|6[013-9]\d{3})$/, messageId: POSTCODE, example: '10115' },
|
|
63
|
+
ES: { pattern: /^(?:0[1-9]|[1-4]\d|5[0-2])\d{3}$/, messageId: POSTCODE, example: '28013' },
|
|
64
|
+
IT: { pattern: /^\d{5}$/, messageId: POSTCODE, example: '00184' },
|
|
65
|
+
PT: { pattern: /^\d{4}(?:-\d{3})?$/, messageId: POSTCODE, example: '1000-205' },
|
|
66
|
+
PR: { ...ZIP_CODE, example: '00901' },
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Adds a rule that an empty value passes: an empty value is `required`'s to report, so the field shows one message and
|
|
70
|
+
* an optional field may stay empty.
|
|
71
|
+
*
|
|
72
|
+
* @param schema The string schema to add the rule to.
|
|
73
|
+
* @param isValid Whether a value that is not empty is acceptable.
|
|
74
|
+
* @param message The message for one that is not.
|
|
75
|
+
* @param params The values the message's placeholders may use.
|
|
76
|
+
* @returns The schema with the rule added.
|
|
77
|
+
*/
|
|
78
|
+
const unlessEmpty = (schema, isValid, message, params) => schema.refine((value) => value === '' || isValid(value), { message, params });
|
|
79
|
+
/**
|
|
80
|
+
* The rules for a text field, such as `FormInput` or `FormTextArea`. Spaces around the value are dropped before the
|
|
81
|
+
* rules run and from the validated value.
|
|
82
|
+
*
|
|
83
|
+
* @param options The rules to apply; a rule given without a message shows the library's default. None makes any text valid.
|
|
84
|
+
* @returns A zod string schema, which takes further zod rules.
|
|
85
|
+
*/
|
|
86
|
+
const text = ({ required, min, max, pattern } = {}) => {
|
|
87
|
+
let schema = zod.z.string().trim();
|
|
88
|
+
const emptyMessage = requiredMessage(required);
|
|
89
|
+
if (emptyMessage)
|
|
90
|
+
schema = schema.min(1, emptyMessage);
|
|
91
|
+
if (min !== undefined) {
|
|
92
|
+
const [limit, message] = limitOf(min, 'Enter_{min}_or_more_characters');
|
|
93
|
+
schema = unlessEmpty(schema, (value) => value.length >= limit, message, { min: limit });
|
|
94
|
+
}
|
|
95
|
+
if (max !== undefined)
|
|
96
|
+
schema = schema.max(...limitOf(max, 'Enter_{max}_characters_or_fewer'));
|
|
97
|
+
if (pattern) {
|
|
98
|
+
const [shape, message] = limitOf(pattern, 'Enter_a_valid_value');
|
|
99
|
+
// A pattern with the `g` or `y` flag starts each test where its last one ended, so it is put back to the start.
|
|
100
|
+
const matches = (value) => {
|
|
101
|
+
shape.lastIndex = 0;
|
|
102
|
+
return shape.test(value);
|
|
103
|
+
};
|
|
104
|
+
schema = unlessEmpty(schema, matches, message);
|
|
105
|
+
}
|
|
106
|
+
return schema;
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* The rules for an email address.
|
|
110
|
+
*
|
|
111
|
+
* @param messages `invalid` for a value that is not an email address, and `required` to refuse an empty one; each has a default, and without `required` the field is optional.
|
|
112
|
+
* @returns A zod string schema whose validated value is the trimmed address.
|
|
113
|
+
*/
|
|
114
|
+
const email = ({ required, invalid = builtInText_utils.builtInTextTemplate('Enter_a_valid_email_address') } = {}) => unlessEmpty(text({ required }), (value) => zod.z.email().safeParse(value).success, invalid);
|
|
115
|
+
/**
|
|
116
|
+
* The rules for a web address.
|
|
117
|
+
*
|
|
118
|
+
* @param messages `invalid` for a value that is not an `http` or `https` address, and `required` to refuse an empty one; each has a default, and without `required` the field is optional.
|
|
119
|
+
* @returns A zod string schema whose validated value is the trimmed address.
|
|
120
|
+
*/
|
|
121
|
+
const url = ({ required, invalid = builtInText_utils.builtInTextTemplate('Enter_a_valid_web_address') } = {}) => unlessEmpty(text({ required }), (value) => zod.z.httpUrl().safeParse(value).success, invalid);
|
|
122
|
+
/**
|
|
123
|
+
* The rules for a phone number: 7 to 15 digits, with optional spaces, brackets, dashes and a leading `+`. It checks the
|
|
124
|
+
* number is plausible to dial, not that it exists.
|
|
125
|
+
*
|
|
126
|
+
* @param messages `invalid` for a value that is not such a number, and `required` to refuse an empty one; each has a default, and without `required` the field is optional.
|
|
127
|
+
* @returns A zod string schema whose validated value is the trimmed number, as typed.
|
|
128
|
+
*/
|
|
129
|
+
const phone = ({ required, invalid = builtInText_utils.builtInTextTemplate('Enter_a_valid_phone_number') } = {}) => unlessEmpty(text({ required }), isPlausiblePhone, invalid);
|
|
130
|
+
/**
|
|
131
|
+
* The rules for a postcode of one country, such as an Eircode in Ireland or a ZIP code in the United States. It checks
|
|
132
|
+
* the shape, not that the address exists. For a country the user picks in the same form, use `postcodeError` in a cross-field rule.
|
|
133
|
+
*
|
|
134
|
+
* @param options The `country` whose shape is required, `invalid` for a value that does not have it, which may show a fitting postcode as `{example}`, and `required` to refuse an empty one; each message has a default, and without `required` the field is optional.
|
|
135
|
+
* @returns A zod string schema whose validated value is the trimmed postcode.
|
|
136
|
+
*/
|
|
137
|
+
const postcode = ({ country, required, invalid = builtInText_utils.builtInTextTemplate(POSTCODE_RULES[country].messageId) }) => unlessEmpty(text({ required }), (value) => POSTCODE_RULES[country].pattern.test(value), invalid, { example: POSTCODE_RULES[country].example });
|
|
138
|
+
/**
|
|
139
|
+
* Checks a postcode against the shape its country uses, for a `crossFieldRules` `check` where the country is another
|
|
140
|
+
* field of the form.
|
|
141
|
+
*
|
|
142
|
+
* @param country The address's country, which decides the shape.
|
|
143
|
+
* @param value The postcode as typed; surrounding spaces and letter case do not matter.
|
|
144
|
+
* @returns The library's default message for the country with the example it shows, or `undefined` when the postcode
|
|
145
|
+
* fits it or is empty, which the field's own `required` rule reports.
|
|
146
|
+
*/
|
|
147
|
+
const postcodeError = (country, value) => {
|
|
148
|
+
const trimmed = value.trim();
|
|
149
|
+
if (!trimmed)
|
|
150
|
+
return undefined;
|
|
151
|
+
const { pattern, messageId, example } = POSTCODE_RULES[country];
|
|
152
|
+
return pattern.test(trimmed) ? undefined : { key: builtInText_utils.builtInTextTemplate(messageId), values: { example } };
|
|
153
|
+
};
|
|
154
|
+
/**
|
|
155
|
+
* The rules shared by every number typed into a text field: its format first, then the range it must sit in.
|
|
156
|
+
*
|
|
157
|
+
* @param format The shape a value must have to count as a number here.
|
|
158
|
+
* @param formatMessage The message for a value that does not have it.
|
|
159
|
+
* @param options Whether the field is required, and the smallest and largest number allowed.
|
|
160
|
+
* @returns A zod string schema; the validated value stays the text typed.
|
|
161
|
+
*/
|
|
162
|
+
const numeric = (format, formatMessage, { required, min, max }) => {
|
|
163
|
+
let schema = text({ required, pattern: [format, formatMessage] });
|
|
164
|
+
// A value that is not a number is the format's to report, so the range passes it.
|
|
165
|
+
const inRange = (isWithin) => (value) => !format.test(value) || isWithin(Number(value));
|
|
166
|
+
if (min !== undefined) {
|
|
167
|
+
const [limit, message] = limitOf(min, 'Enter_{min}_or_more');
|
|
168
|
+
schema = unlessEmpty(schema, inRange((value) => value >= limit), message, { min: limit });
|
|
169
|
+
}
|
|
170
|
+
if (max !== undefined) {
|
|
171
|
+
const [limit, message] = limitOf(max, 'Enter_{max}_or_less');
|
|
172
|
+
schema = unlessEmpty(schema, inRange((value) => value <= limit), message, { max: limit });
|
|
173
|
+
}
|
|
174
|
+
return schema;
|
|
175
|
+
};
|
|
176
|
+
/**
|
|
177
|
+
* The rules for a money amount typed into a text field: zero or more, with at most two decimal places.
|
|
178
|
+
*
|
|
179
|
+
* @param options `invalid` for a value that is not such an amount, the optional `min` and `max` it must sit between, and
|
|
180
|
+
* `required` to refuse an empty value; each message has a default, and without `required` the field is optional.
|
|
181
|
+
* @returns A zod string schema; the validated value stays the text typed, such as `'12.50'`.
|
|
182
|
+
*/
|
|
183
|
+
const amount = ({ invalid = builtInText_utils.builtInTextTemplate('Enter_a_valid_amount'), ...options } = {}) => numeric(AMOUNT, invalid, options);
|
|
184
|
+
/**
|
|
185
|
+
* The rules for a number typed into a text field, such as a quantity or a percentage.
|
|
186
|
+
*
|
|
187
|
+
* @param options `invalid` for a value that is not a number, the optional `min` and `max` it must sit between, `isWhole` to
|
|
188
|
+
* refuse a decimal, and `required` to refuse an empty value; each message has a default, and without `required` the field is optional.
|
|
189
|
+
* @returns A zod string schema; the validated value stays the text typed, so convert it with `Number` when saving.
|
|
190
|
+
*/
|
|
191
|
+
const number = ({ invalid, isWhole = false, ...options } = {}) => numeric(isWhole ? WHOLE_NUMBER : NUMBER, invalid ?? builtInText_utils.builtInTextTemplate(isWhole ? 'Enter_a_whole_number' : 'Enter_a_number'), options);
|
|
192
|
+
/**
|
|
193
|
+
* The rules for a code made only of digits, such as a PIN, a verification code or an account number. Unlike `number`
|
|
194
|
+
* it keeps leading zeros, takes no sign or decimal point, and limits how many digits there are.
|
|
195
|
+
*
|
|
196
|
+
* @param options `invalid` for a value with anything but digits, the `length` it must have or the `min` and `max` digits it
|
|
197
|
+
* may have, and `required` to refuse an empty value; each message has a default, and without `required` the field is optional.
|
|
198
|
+
* @returns A zod string schema; the validated value is the digits as typed.
|
|
199
|
+
*/
|
|
200
|
+
const digits = ({ required, invalid = builtInText_utils.builtInTextTemplate('Enter_digits_only'), length, min, max } = {}) => {
|
|
201
|
+
let schema = text({ required, pattern: [DIGITS, invalid] });
|
|
202
|
+
// A value with something other than digits is `invalid`'s to report, so the counts pass it.
|
|
203
|
+
const counted = (isAllowed) => (value) => !DIGITS.test(value) || isAllowed(value.length);
|
|
204
|
+
const rules = [
|
|
205
|
+
{ rule: length, id: 'Enter_{length}_digits', name: 'length', isAllowed: (count, limit) => count === limit },
|
|
206
|
+
{ rule: min, id: 'Enter_{min}_or_more_characters', name: 'min', isAllowed: (count, limit) => count >= limit },
|
|
207
|
+
{ rule: max, id: 'Enter_{max}_characters_or_fewer', name: 'max', isAllowed: (count, limit) => count <= limit },
|
|
208
|
+
];
|
|
209
|
+
for (const { rule, id, name, isAllowed } of rules) {
|
|
210
|
+
if (rule === undefined)
|
|
211
|
+
continue;
|
|
212
|
+
const [limit, message] = limitOf(rule, id);
|
|
213
|
+
schema = unlessEmpty(schema, counted((count) => isAllowed(count, limit)), message, { [name]: limit });
|
|
214
|
+
}
|
|
215
|
+
return schema;
|
|
216
|
+
};
|
|
217
|
+
/**
|
|
218
|
+
* The rule for a box the user must tick or a switch they must turn on, such as accepting terms with `FormCheckbox`.
|
|
219
|
+
*
|
|
220
|
+
* @param required The message while it is off; the library's default without it.
|
|
221
|
+
* @returns A zod boolean schema, which only `true` passes.
|
|
222
|
+
*/
|
|
223
|
+
const checked = (required = builtInText_utils.builtInTextTemplate('Select_this_box_to_continue')) => zod.z.boolean().refine((value) => value, required);
|
|
224
|
+
const requiredColour = (isColour, required, invalid) =>
|
|
225
|
+
// The message is given to the type check as well: `null` is not a string, and zod's own wording for that is not for users.
|
|
226
|
+
zod.z
|
|
227
|
+
.string(required)
|
|
228
|
+
.min(1, required)
|
|
229
|
+
.refine((value) => !value || isColour(value), invalid);
|
|
230
|
+
const optionalColour = (isColour, invalid) => zod.z
|
|
231
|
+
.string()
|
|
232
|
+
.nullish()
|
|
233
|
+
.refine((value) => !value || isColour(value), invalid);
|
|
234
|
+
/**
|
|
235
|
+
* The rules for a colour held as a hex string, as `FormColorPicker` writes it. A field with no colour is one holding
|
|
236
|
+
* `null`, `undefined` or `''`: the picker writes back whichever of them the form itself uses for an empty field.
|
|
237
|
+
*
|
|
238
|
+
* @param options `required` to refuse a field with no colour, the message for a value that is not a hex colour, and whether a see-through colour passes.
|
|
239
|
+
* @returns A zod schema of a string, which also takes `null` and `undefined` unless the colour is required.
|
|
240
|
+
*/
|
|
241
|
+
const hexColour = (({ required, invalid = builtInText_utils.builtInTextTemplate('Enter_a_valid_colour'), isAlphaAllowed = false, } = {}) => {
|
|
242
|
+
const pattern = isAlphaAllowed ? HEX_COLOUR_WITH_ALPHA : HEX_COLOUR;
|
|
243
|
+
const isColour = (value) => pattern.test(value);
|
|
244
|
+
const emptyMessage = requiredMessage(required);
|
|
245
|
+
return emptyMessage ? requiredColour(isColour, emptyMessage, invalid) : optionalColour(isColour, invalid);
|
|
246
|
+
// The schema follows `required`, which only the two call shapes above can say.
|
|
247
|
+
});
|
|
248
|
+
/**
|
|
249
|
+
* Today's date in a time zone, as the ISO date string a `date` rule compares with. Use it for a limit that follows the
|
|
250
|
+
* calendar of the record being edited, such as a property's, and not the calendar of whoever is editing it.
|
|
251
|
+
*
|
|
252
|
+
* @param timeZone The IANA time zone, such as `Europe/Dublin`; without one, or with an empty one, the browser's. A name
|
|
253
|
+
* `Intl` does not know throws a `RangeError`, so validate a zone the user picks before it reaches here.
|
|
254
|
+
* @param now The moment to read the date at; the current time unless a test fixes it.
|
|
255
|
+
* @returns That date as `YYYY-MM-DD`.
|
|
256
|
+
*/
|
|
257
|
+
const todayIn = (timeZone, now = new Date()) => {
|
|
258
|
+
// Read part by part: no locale's own date format is promised to stay `YYYY-MM-DD`.
|
|
259
|
+
const parts = new Intl.DateTimeFormat('en-US', {
|
|
260
|
+
timeZone: timeZone || undefined,
|
|
261
|
+
calendar: 'gregory',
|
|
262
|
+
numberingSystem: 'latn',
|
|
263
|
+
year: 'numeric',
|
|
264
|
+
month: '2-digit',
|
|
265
|
+
day: '2-digit',
|
|
266
|
+
}).formatToParts(now);
|
|
267
|
+
const part = (type) => parts.find((entry) => entry.type === type)?.value ?? '';
|
|
268
|
+
return `${part('year')}-${part('month')}-${part('day')}`;
|
|
269
|
+
};
|
|
270
|
+
/**
|
|
271
|
+
* The rules for a date held as an ISO date string (`YYYY-MM-DD`) or `null`, as `FormDatePicker` writes it.
|
|
272
|
+
*
|
|
273
|
+
* @param options `required` to refuse a field with no date, and the optional `min` and `max` it must sit between. A limit
|
|
274
|
+
* may be a function, read at each validation, for one that moves such as today: `min: () => todayIn()`. A default message
|
|
275
|
+
* shows the limit as a date, such as `13 Nov 2026`.
|
|
276
|
+
* @returns A zod schema of a string or `null`.
|
|
277
|
+
*/
|
|
278
|
+
const date = ({ required, min, max } = {}) => {
|
|
279
|
+
const read = (limit) => (typeof limit === 'function' ? limit() : limit);
|
|
280
|
+
let schema = zod.z.string().nullable();
|
|
281
|
+
const emptyMessage = requiredMessage(required);
|
|
282
|
+
if (emptyMessage)
|
|
283
|
+
schema = schema.refine((value) => Boolean(value), emptyMessage);
|
|
284
|
+
const earliest = min && limitOf(min, 'Choose_a_date_on_or_after_{min}');
|
|
285
|
+
const latest = max && limitOf(max, 'Choose_a_date_on_or_before_{max}');
|
|
286
|
+
return schema.superRefine((value, context) => {
|
|
287
|
+
if (!value)
|
|
288
|
+
return;
|
|
289
|
+
// ISO dates of the same length sort as their text. A limit is read here, so one that moves is current.
|
|
290
|
+
// Only the date is compared, of the value and of a limit alike: one given with a time would sort after that same date.
|
|
291
|
+
const from = earliest && read(earliest[0])?.slice(0, 10);
|
|
292
|
+
const to = latest && read(latest[0])?.slice(0, 10);
|
|
293
|
+
const day = value.slice(0, 10);
|
|
294
|
+
if (earliest && from && day < from)
|
|
295
|
+
context.addIssue({ code: 'custom', message: earliest[1], params: { min: from } });
|
|
296
|
+
if (latest && to && day > to)
|
|
297
|
+
context.addIssue({ code: 'custom', message: latest[1], params: { max: to } });
|
|
298
|
+
});
|
|
299
|
+
};
|
|
300
|
+
/**
|
|
301
|
+
* The rules for a field that holds one of a fixed set of ids, such as `FormSelect` or `FormRadioGroup`.
|
|
302
|
+
*
|
|
303
|
+
* @param options Every id the field may hold.
|
|
304
|
+
* @param required The message for a field with no choice, or a value outside `options`; the library's default without it.
|
|
305
|
+
* @returns A zod enum schema, so the validated value is typed as one of `options`.
|
|
306
|
+
*/
|
|
307
|
+
const oneOf = (options, required = builtInText_utils.builtInTextTemplate('Choose_an_option')) => zod.z.enum(options, required);
|
|
308
|
+
/**
|
|
309
|
+
* Adds the size rules of a list that needs at least one entry.
|
|
310
|
+
*
|
|
311
|
+
* @param list The array schema to add the rules to.
|
|
312
|
+
* @param options The message for an empty list, and the most entries allowed.
|
|
313
|
+
* @returns The schema with the rules added.
|
|
314
|
+
*/
|
|
315
|
+
const sized = (list, { required = builtInText_utils.builtInTextTemplate('Choose_at_least_one_option'), max }) => {
|
|
316
|
+
const atLeastOneEntry = list.min(1, required);
|
|
317
|
+
return max === undefined ? atLeastOneEntry : atLeastOneEntry.max(...limitOf(max, 'Choose_{max}_or_fewer'));
|
|
318
|
+
};
|
|
319
|
+
/**
|
|
320
|
+
* The rules for a field that holds a list of any strings and needs at least one entry, such as a `FormMultiSelect`
|
|
321
|
+
* whose items are loaded.
|
|
322
|
+
*
|
|
323
|
+
* @param options `required` for an empty list and the optional `max` entries it may hold; each message has a default.
|
|
324
|
+
* @returns A zod array schema.
|
|
325
|
+
*/
|
|
326
|
+
const atLeastOne = (options = {}) => sized(zod.z.array(zod.z.string()), options);
|
|
327
|
+
/**
|
|
328
|
+
* The rules for a field that holds a list from a fixed set of ids and needs at least one entry, such as
|
|
329
|
+
* `FormCheckboxGroup`.
|
|
330
|
+
*
|
|
331
|
+
* @param ids Every id the list may hold.
|
|
332
|
+
* @param options `required` for an empty list and the optional `max` entries it may hold; each message has a default.
|
|
333
|
+
* @returns A zod array schema, so the validated value is typed as a list of `ids`.
|
|
334
|
+
*/
|
|
335
|
+
const atLeastOneOf = (ids, options = {}) => sized(zod.z.array(zod.z.enum(ids)), options);
|
|
336
|
+
// Marks an issue a cross-field rule raised. A later rule that reads the field it sits on still runs: that field did not fail its own rules.
|
|
337
|
+
const CROSS_FIELD = 'crossField';
|
|
338
|
+
/**
|
|
339
|
+
* Turns a conditional rule into the cross-field rule that runs it: the field's extra rules are checked only while the
|
|
340
|
+
* condition holds, and the first one broken gives the message.
|
|
341
|
+
*
|
|
342
|
+
* @param rule The rule as written in the schema.
|
|
343
|
+
* @returns A cross-field rule, unchanged when it already was one.
|
|
344
|
+
*/
|
|
345
|
+
const asCrossFieldRule = (rule) => {
|
|
346
|
+
if (rule.check !== undefined)
|
|
347
|
+
return rule;
|
|
348
|
+
const { when, reportsOn, reads = [], rules } = rule;
|
|
349
|
+
const applies = (values) => (typeof when === 'function' ? when(values) : values[when] === true);
|
|
350
|
+
return {
|
|
351
|
+
reads: [...new Set([...(typeof when === 'function' ? [] : [when]), reportsOn, ...reads])],
|
|
352
|
+
reportsOn,
|
|
353
|
+
check: (values) => {
|
|
354
|
+
if (!applies(values))
|
|
355
|
+
return undefined;
|
|
356
|
+
const result = (rules instanceof zod.z.ZodType ? rules : rules(values)).safeParse(values[reportsOn]);
|
|
357
|
+
if (result.success)
|
|
358
|
+
return undefined;
|
|
359
|
+
const [issue] = result.error.issues;
|
|
360
|
+
return { key: issue.message, values: validation_utils.valuesOf(issue) };
|
|
361
|
+
},
|
|
362
|
+
};
|
|
363
|
+
};
|
|
364
|
+
/**
|
|
365
|
+
* Adds the rules that read more than one field, such as a postcode whose shape depends on the country, or a date that
|
|
366
|
+
* is needed only while a toggle is on. Each rule runs as soon as the fields it reads are valid: left to itself zod
|
|
367
|
+
* skips it while any field in the form fails, so its error would only show on a second save. In a form validated
|
|
368
|
+
* through `useSchemaResolver`, a `Form*` field a rule reads re-validates the field the rule reports on as it changes.
|
|
369
|
+
* That holds for a schema refined further, but not for one wrapped afterwards, as `.transform()` and `.optional()` do.
|
|
370
|
+
*
|
|
371
|
+
* @param schema The object schema holding each field's own rules.
|
|
372
|
+
* @param rules The rules to add, in the order they should run: a `check` of your own, or `when` and the `rules` a field
|
|
373
|
+
* must also pass while it holds.
|
|
374
|
+
* @returns The same schema with the rules applied; its `shape` and value type are unchanged.
|
|
375
|
+
*/
|
|
376
|
+
const crossFieldRules = (schema, ...rules) => rules.map(asCrossFieldRule).reduce((refining, { reads, reportsOn, check }) => {
|
|
377
|
+
const readNames = reads;
|
|
378
|
+
const refined = refining.superRefine((values, context) => {
|
|
379
|
+
const result = check(values);
|
|
380
|
+
if (!result)
|
|
381
|
+
return;
|
|
382
|
+
const { key, values: params } = typeof result === 'string' ? { key: result, values: undefined } : result;
|
|
383
|
+
context.addIssue({ code: 'custom', message: key, path: [reportsOn], params, [CROSS_FIELD]: true });
|
|
384
|
+
},
|
|
385
|
+
// Read from the issues the fields have raised, never by parsing the values again: they are already the fields'
|
|
386
|
+
// output, which a field that transforms its value would reject, and a field with an async rule cannot be parsed in step.
|
|
387
|
+
// An issue with no path is the object's own, such as a nested group that is missing: there are no fields to read.
|
|
388
|
+
{
|
|
389
|
+
when: ({ issues }) => !issues.some((issue) => !(CROSS_FIELD in issue) && (!issue.path?.length || readNames.includes(issue.path[0]))),
|
|
390
|
+
});
|
|
391
|
+
validation_utils.noteCrossFieldRule(refined, reads, reportsOn);
|
|
392
|
+
return refined;
|
|
393
|
+
}, schema);
|
|
394
|
+
|
|
395
|
+
exports.useSchemaResolver = useSchemaResolver.useSchemaResolver;
|
|
396
|
+
exports.amount = amount;
|
|
397
|
+
exports.atLeastOne = atLeastOne;
|
|
398
|
+
exports.atLeastOneOf = atLeastOneOf;
|
|
399
|
+
exports.checked = checked;
|
|
400
|
+
exports.crossFieldRules = crossFieldRules;
|
|
401
|
+
exports.date = date;
|
|
402
|
+
exports.digits = digits;
|
|
403
|
+
exports.email = email;
|
|
404
|
+
exports.hexColour = hexColour;
|
|
405
|
+
exports.number = number;
|
|
406
|
+
exports.oneOf = oneOf;
|
|
407
|
+
exports.phone = phone;
|
|
408
|
+
exports.postcode = postcode;
|
|
409
|
+
exports.postcodeError = postcodeError;
|
|
410
|
+
exports.text = text;
|
|
411
|
+
exports.todayIn = todayIn;
|
|
412
|
+
exports.url = url;
|
|
413
|
+
//# sourceMappingURL=index.cjs.map
|