@flipdish/ui-library 0.52.0 → 0.53.1
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/dist/components/atoms/CloseButton/index.cjs +1 -0
- package/dist/components/atoms/CloseButton/index.cjs.map +1 -1
- package/dist/components/atoms/CloseButton/index.d.ts.map +1 -1
- package/dist/components/atoms/CloseButton/index.js +1 -0
- package/dist/components/atoms/CloseButton/index.js.map +1 -1
- 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/index.cjs +26 -6
- package/dist/components/forms/Form/index.cjs.map +1 -1
- package/dist/components/forms/Form/index.d.ts +9 -2
- package/dist/components/forms/Form/index.d.ts.map +1 -1
- package/dist/components/forms/Form/index.js +27 -8
- package/dist/components/forms/Form/index.js.map +1 -1
- package/dist/components/forms/FormFooter/index.cjs +1 -1
- package/dist/components/forms/FormFooter/index.cjs.map +1 -1
- package/dist/components/forms/FormFooter/index.d.ts +4 -0
- package/dist/components/forms/FormFooter/index.d.ts.map +1 -1
- package/dist/components/forms/FormFooter/index.js +1 -1
- package/dist/components/forms/FormFooter/index.js.map +1 -1
- 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/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/useFormField.cjs +8 -3
- package/dist/components/forms/__internal__/formField/hooks/useFormField.cjs.map +1 -1
- package/dist/components/forms/__internal__/formField/hooks/useFormField.d.ts +1 -1
- package/dist/components/forms/__internal__/formField/hooks/useFormField.d.ts.map +1 -1
- package/dist/components/forms/__internal__/formField/hooks/useFormField.js +8 -3
- package/dist/components/forms/__internal__/formField/hooks/useFormField.js.map +1 -1
- 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__/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.map +1 -1
- package/dist/components/forms/fields/FormCheckbox/index.d.ts +4 -1
- package/dist/components/forms/fields/FormCheckbox/index.d.ts.map +1 -1
- package/dist/components/forms/fields/FormCheckbox/index.js.map +1 -1
- package/dist/components/forms/fields/FormCheckboxGroup/index.cjs.map +1 -1
- package/dist/components/forms/fields/FormCheckboxGroup/index.d.ts +4 -1
- package/dist/components/forms/fields/FormCheckboxGroup/index.d.ts.map +1 -1
- package/dist/components/forms/fields/FormCheckboxGroup/index.js.map +1 -1
- package/dist/components/forms/fields/FormColorPicker/index.cjs.map +1 -1
- package/dist/components/forms/fields/FormColorPicker/index.d.ts +4 -1
- package/dist/components/forms/fields/FormColorPicker/index.d.ts.map +1 -1
- package/dist/components/forms/fields/FormColorPicker/index.js.map +1 -1
- package/dist/components/forms/fields/FormDatePicker/index.cjs.map +1 -1
- package/dist/components/forms/fields/FormDatePicker/index.d.ts +4 -1
- package/dist/components/forms/fields/FormDatePicker/index.d.ts.map +1 -1
- package/dist/components/forms/fields/FormDatePicker/index.js.map +1 -1
- package/dist/components/forms/fields/FormInput/index.cjs.map +1 -1
- package/dist/components/forms/fields/FormInput/index.d.ts +4 -1
- package/dist/components/forms/fields/FormInput/index.d.ts.map +1 -1
- package/dist/components/forms/fields/FormInput/index.js.map +1 -1
- package/dist/components/forms/fields/FormMultiSelect/index.cjs.map +1 -1
- package/dist/components/forms/fields/FormMultiSelect/index.d.ts +4 -1
- package/dist/components/forms/fields/FormMultiSelect/index.d.ts.map +1 -1
- package/dist/components/forms/fields/FormMultiSelect/index.js.map +1 -1
- package/dist/components/forms/fields/FormRadioCardGroup/index.cjs.map +1 -1
- package/dist/components/forms/fields/FormRadioCardGroup/index.d.ts +4 -1
- package/dist/components/forms/fields/FormRadioCardGroup/index.d.ts.map +1 -1
- package/dist/components/forms/fields/FormRadioCardGroup/index.js.map +1 -1
- package/dist/components/forms/fields/FormRadioGroup/index.cjs.map +1 -1
- package/dist/components/forms/fields/FormRadioGroup/index.d.ts +4 -1
- package/dist/components/forms/fields/FormRadioGroup/index.d.ts.map +1 -1
- package/dist/components/forms/fields/FormRadioGroup/index.js.map +1 -1
- package/dist/components/forms/fields/FormSelect/index.cjs.map +1 -1
- package/dist/components/forms/fields/FormSelect/index.d.ts +4 -1
- package/dist/components/forms/fields/FormSelect/index.d.ts.map +1 -1
- package/dist/components/forms/fields/FormSelect/index.js.map +1 -1
- package/dist/components/forms/fields/FormSlider/index.cjs.map +1 -1
- package/dist/components/forms/fields/FormSlider/index.d.ts +4 -1
- package/dist/components/forms/fields/FormSlider/index.d.ts.map +1 -1
- package/dist/components/forms/fields/FormSlider/index.js.map +1 -1
- package/dist/components/forms/fields/FormTextArea/index.cjs.map +1 -1
- package/dist/components/forms/fields/FormTextArea/index.d.ts +4 -1
- package/dist/components/forms/fields/FormTextArea/index.d.ts.map +1 -1
- package/dist/components/forms/fields/FormTextArea/index.js.map +1 -1
- package/dist/components/forms/fields/FormToggle/index.cjs.map +1 -1
- package/dist/components/forms/fields/FormToggle/index.d.ts +4 -1
- package/dist/components/forms/fields/FormToggle/index.d.ts.map +1 -1
- package/dist/components/forms/fields/FormToggle/index.js.map +1 -1
- package/dist/components/forms/validation/hooks/useSchemaResolver.cjs +7 -2
- package/dist/components/forms/validation/hooks/useSchemaResolver.cjs.map +1 -1
- package/dist/components/forms/validation/hooks/useSchemaResolver.d.ts +2 -1
- package/dist/components/forms/validation/hooks/useSchemaResolver.d.ts.map +1 -1
- package/dist/components/forms/validation/hooks/useSchemaResolver.js +8 -3
- package/dist/components/forms/validation/hooks/useSchemaResolver.js.map +1 -1
- package/dist/components/forms/validation/index.cjs +112 -8
- package/dist/components/forms/validation/index.cjs.map +1 -1
- package/dist/components/forms/validation/index.d.ts +71 -7
- package/dist/components/forms/validation/index.d.ts.map +1 -1
- package/dist/components/forms/validation/index.js +110 -9
- package/dist/components/forms/validation/index.js.map +1 -1
- package/dist/components/forms/validation/utilities/validation.utils.cjs +30 -0
- package/dist/components/forms/validation/utilities/validation.utils.cjs.map +1 -1
- package/dist/components/forms/validation/utilities/validation.utils.d.ts +18 -0
- package/dist/components/forms/validation/utilities/validation.utils.d.ts.map +1 -1
- package/dist/components/forms/validation/utilities/validation.utils.js +29 -1
- package/dist/components/forms/validation/utilities/validation.utils.js.map +1 -1
- package/dist/components/molecules/Dropdown/components/DropdownSelectionIndicator.cjs +29 -0
- package/dist/components/molecules/Dropdown/components/DropdownSelectionIndicator.cjs.map +1 -0
- package/dist/components/molecules/Dropdown/components/DropdownSelectionIndicator.d.ts +9 -0
- package/dist/components/molecules/Dropdown/components/DropdownSelectionIndicator.d.ts.map +1 -0
- package/dist/components/molecules/Dropdown/components/DropdownSelectionIndicator.js +27 -0
- package/dist/components/molecules/Dropdown/components/DropdownSelectionIndicator.js.map +1 -0
- package/dist/components/molecules/Dropdown/index.cjs +4 -30
- package/dist/components/molecules/Dropdown/index.cjs.map +1 -1
- package/dist/components/molecules/Dropdown/index.d.ts +1 -1
- package/dist/components/molecules/Dropdown/index.d.ts.map +1 -1
- package/dist/components/molecules/Dropdown/index.js +6 -32
- package/dist/components/molecules/Dropdown/index.js.map +1 -1
- package/dist/components/molecules/Dropdown/utilities/dropdown.utils.cjs +24 -0
- package/dist/components/molecules/Dropdown/utilities/dropdown.utils.cjs.map +1 -0
- package/dist/components/molecules/Dropdown/utilities/dropdown.utils.d.ts +10 -0
- package/dist/components/molecules/Dropdown/utilities/dropdown.utils.d.ts.map +1 -0
- package/dist/components/molecules/Dropdown/utilities/dropdown.utils.js +22 -0
- package/dist/components/molecules/Dropdown/utilities/dropdown.utils.js.map +1 -0
- 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 +19 -0
- package/dist/localization/en.json.cjs.map +1 -1
- package/dist/localization/en.json.js +18 -1
- package/dist/localization/en.json.js.map +1 -1
- package/dist/native/components/forms/FormSaveErrorAlert/index.d.ts +12 -0
- package/dist/native/components/forms/FormUnsavedChangesModal/index.d.ts +12 -0
- package/dist/native/utilities/colorUtils/index.d.ts +12 -0
- package/dist/utilities/__internal__/builtInTextUtils/builtInText.utils.d.ts +1 -1
- package/dist/utilities/__internal__/builtInTextUtils/builtInText.utils.d.ts.map +1 -1
- 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 +1 -1
|
@@ -16,6 +16,7 @@ const themes = {
|
|
|
16
16
|
light: 'text-fg-quaternary hover:bg-primary_hover hover:text-fg-quaternary_hover focus-visible:outline-2 focus-visible:outline-offset-2 outline-focus-ring',
|
|
17
17
|
dark: 'text-fg-white/70 hover:text-fg-white hover:bg-white/20 focus-visible:outline-2 focus-visible:outline-offset-2 outline-focus-ring',
|
|
18
18
|
};
|
|
19
|
+
// Comment to test native pipeline - please remove
|
|
19
20
|
/**
|
|
20
21
|
* Icon-only button that renders an × icon for dismissing overlays, toasts,
|
|
21
22
|
* banners, and drawers. Always supply a `label` for screen readers.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../../../src/components/atoms/CloseButton/index.tsx"],"sourcesContent":[null],"names":["useResolvedTestId","_jsx","AriaButton","cx","CloseIcon"],"mappings":";;;;;;;;AAOA,MAAM,KAAK,GAAG;IACZ,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE;IACtC,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE;IACtC,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE;IACvC,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE;CACxC;AAED,MAAM,MAAM,GAAG;AACb,IAAA,KAAK,EACH,oJAAoJ;AACtJ,IAAA,IAAI,EAAE,kIAAkI;CACzI;AAaD;;;;;AAKG;AACI,MAAM,WAAW,GAAG,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,GAAG,IAAI,EAAE,KAAK,GAAG,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,GAAG,UAAU,EAAoB,KAAI;AAC5I,IAAA,MAAM,iBAAiB,GAAGA,6BAAiB,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,cAAc,EAAE,CAAC;AAEtH,IAAA,QACEC,cAAA,CAACC,0BAAU,EAAA,EAAA,GACL,UAAU,EAAA,aAAA,EACD,iBAAiB,EAAA,YAAA,EAClB,KAAK,IAAI,OAAO,EAC5B,SAAS,EAAE,CAAC,KAAK,KACfC,KAAE,CACA,yHAAyH,EACzH,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAChB,MAAM,CAAC,KAAK,CAAC,EACb,OAAO,SAAS,KAAK,UAAU,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,SAAS,CAC/D,EAAA,QAAA,EAGHF,eAACG,SAAS,EAAA,EAAA,aAAA,EAAa,MAAM,EAAC,SAAS,EAAED,KAAE,CAAC,iCAAiC,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,EAAA,CAAI,EAAA,CACzF;AAEjB;;"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../../../src/components/atoms/CloseButton/index.tsx"],"sourcesContent":[null],"names":["useResolvedTestId","_jsx","AriaButton","cx","CloseIcon"],"mappings":";;;;;;;;AAOA,MAAM,KAAK,GAAG;IACZ,EAAE,EAAE,EAAE,IAAI,E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,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/atoms/CloseButton/index.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAwB,KAAK,WAAW,IAAI,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAelG,MAAM,WAAW,gBAAiB,SAAQ,eAAe;IACvD,yGAAyG;IACzG,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IACzB,2CAA2C;IAC3C,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;IACjC,yEAAyE;IACzE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,mEAAmE;IACnE,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/atoms/CloseButton/index.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAwB,KAAK,WAAW,IAAI,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAelG,MAAM,WAAW,gBAAiB,SAAQ,eAAe;IACvD,yGAAyG;IACzG,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IACzB,2CAA2C;IAC3C,IAAI,CAAC,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;IACjC,yEAAyE;IACzE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,mEAAmE;IACnE,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAID;;;;;GAKG;AACH,eAAO,MAAM,WAAW,GAAI,6EAA8F,gBAAgB,gCAoBzI,CAAC"}
|
|
@@ -14,6 +14,7 @@ const themes = {
|
|
|
14
14
|
light: 'text-fg-quaternary hover:bg-primary_hover hover:text-fg-quaternary_hover focus-visible:outline-2 focus-visible:outline-offset-2 outline-focus-ring',
|
|
15
15
|
dark: 'text-fg-white/70 hover:text-fg-white hover:bg-white/20 focus-visible:outline-2 focus-visible:outline-offset-2 outline-focus-ring',
|
|
16
16
|
};
|
|
17
|
+
// Comment to test native pipeline - please remove
|
|
17
18
|
/**
|
|
18
19
|
* Icon-only button that renders an × icon for dismissing overlays, toasts,
|
|
19
20
|
* banners, and drawers. Always supply a `label` for screen readers.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../src/components/atoms/CloseButton/index.tsx"],"sourcesContent":[null],"names":["_jsx","AriaButton","CloseIcon"],"mappings":";;;;;;AAOA,MAAM,KAAK,GAAG;IACZ,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE;IACtC,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE;IACtC,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE;IACvC,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE;CACxC;AAED,MAAM,MAAM,GAAG;AACb,IAAA,KAAK,EACH,oJAAoJ;AACtJ,IAAA,IAAI,EAAE,kIAAkI;CACzI;AAaD;;;;;AAKG;AACI,MAAM,WAAW,GAAG,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,GAAG,IAAI,EAAE,KAAK,GAAG,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,GAAG,UAAU,EAAoB,KAAI;AAC5I,IAAA,MAAM,iBAAiB,GAAG,iBAAiB,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,cAAc,EAAE,CAAC;AAEtH,IAAA,QACEA,GAAA,CAACC,MAAU,EAAA,EAAA,GACL,UAAU,EAAA,aAAA,EACD,iBAAiB,EAAA,YAAA,EAClB,KAAK,IAAI,OAAO,EAC5B,SAAS,EAAE,CAAC,KAAK,KACf,EAAE,CACA,yHAAyH,EACzH,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAChB,MAAM,CAAC,KAAK,CAAC,EACb,OAAO,SAAS,KAAK,UAAU,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,SAAS,CAC/D,EAAA,QAAA,EAGHD,IAACE,CAAS,EAAA,EAAA,aAAA,EAAa,MAAM,EAAC,SAAS,EAAE,EAAE,CAAC,iCAAiC,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,EAAA,CAAI,EAAA,CACzF;AAEjB;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../src/components/atoms/CloseButton/index.tsx"],"sourcesContent":[null],"names":["_jsx","AriaButton","CloseIcon"],"mappings":";;;;;;AAOA,MAAM,KAAK,GAAG;IACZ,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE;IACtC,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE;IACtC,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE;IACvC,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE;CACxC;AAED,MAAM,MAAM,GAAG;AACb,IAAA,KAAK,EACH,oJAAoJ;AACtJ,IAAA,IAAI,EAAE,kIAAkI;CACzI;AAaD;AAEA;;;;;AAKG;AACI,MAAM,WAAW,GAAG,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,GAAG,IAAI,EAAE,KAAK,GAAG,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,GAAG,UAAU,EAAoB,KAAI;AAC5I,IAAA,MAAM,iBAAiB,GAAG,iBAAiB,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,cAAc,EAAE,CAAC;AAEtH,IAAA,QACEA,GAAA,CAACC,MAAU,EAAA,EAAA,GACL,UAAU,EAAA,aAAA,EACD,iBAAiB,EAAA,YAAA,EAClB,KAAK,IAAI,OAAO,EAC5B,SAAS,EAAE,CAAC,KAAK,KACf,EAAE,CACA,yHAAyH,EACzH,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAChB,MAAM,CAAC,KAAK,CAAC,EACb,OAAO,SAAS,KAAK,UAAU,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,SAAS,CAC/D,EAAA,QAAA,EAGHD,IAACE,CAAS,EAAA,EAAA,aAAA,EAAa,MAAM,EAAC,SAAS,EAAE,EAAE,CAAC,iCAAiC,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,EAAA,CAAI,EAAA,CACzF;AAEjB;;"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var React = require('react');
|
|
4
|
+
var useForm = require('../useForm.cjs');
|
|
5
|
+
|
|
6
|
+
// A refetch brings newer values: the fields the user has edited keep the draft, the rest follow the server. The errors
|
|
7
|
+
// on screen and the dirty flag stay too, or a refetch would hide a rejection and switch Save off for a moment.
|
|
8
|
+
const FOLLOW_REFETCH = { keepDirtyValues: true, keepErrors: true, keepDirty: true };
|
|
9
|
+
// A save and Discard start the form again: `resetOptions` reaches each `reset` call, and would keep the edits and errors.
|
|
10
|
+
const START_AGAIN = { keepDirtyValues: false, keepErrors: false, keepDirty: false };
|
|
11
|
+
// A mapper written for the server's rejections may not expect a network failure, and one that threw would leave the save in flight for good.
|
|
12
|
+
const rejectedFieldOf = (fieldErrorOf, error) => {
|
|
13
|
+
try {
|
|
14
|
+
return fieldErrorOf?.(error);
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Creates a form that waits on Save, and owns what happens around the save: it starts again from what was saved, keeps
|
|
22
|
+
* a draft through a refetch, holds a refetch that lands mid-save, and reports a failure beside Save or beneath the field
|
|
23
|
+
* the server rejected. Use it in place of `useForm` for a form with `FormFooter`, mounted once per record: give the
|
|
24
|
+
* form's component a `key` of the record's id, so another record never inherits this one's save.
|
|
25
|
+
*
|
|
26
|
+
* @param options Every option this module's `useForm` takes except `resetOptions`, with `save` and `fieldErrorOf`; see
|
|
27
|
+
* `UseSaveFormOptions`. Pass the loaded record as `values`, so the fields the user has not edited follow a refetch.
|
|
28
|
+
* @returns The form and its save state, with one handler per action; see `UseSaveFormReturn`. "Try again" has none:
|
|
29
|
+
* `FormSaveErrorAlert` submits the form itself, as Save does.
|
|
30
|
+
*/
|
|
31
|
+
// biome-ignore lint/suspicious/noExplicitAny: mirrors react-hook-form's own `TContext = any`, so the two signatures stay interchangeable
|
|
32
|
+
const useSaveForm = ({ save, fieldErrorOf, values, ...options }) => {
|
|
33
|
+
const [saveState, setSaveState] = React.useState({ status: 'idle' });
|
|
34
|
+
const isSaving = saveState.status === 'saving';
|
|
35
|
+
const form = useForm.useForm({
|
|
36
|
+
...options,
|
|
37
|
+
// Held while a save is in flight: a refetch landing then would reset the form, which ends the lock on its fields.
|
|
38
|
+
values: isSaving ? undefined : values,
|
|
39
|
+
resetOptions: FOLLOW_REFETCH,
|
|
40
|
+
});
|
|
41
|
+
const { reset, setError, getValues } = form;
|
|
42
|
+
const { isDirty, errors } = form.formState;
|
|
43
|
+
// The saved check ends with the next edit, for good: undoing that edit by hand must not bring it back with nothing saved.
|
|
44
|
+
const hasSaved = saveState.status === 'saved';
|
|
45
|
+
React.useEffect(() => {
|
|
46
|
+
if (isDirty && hasSaved)
|
|
47
|
+
setSaveState({ status: 'idle' });
|
|
48
|
+
}, [isDirty, hasSaved]);
|
|
49
|
+
const rejectedField = saveState.status === 'failed' ? saveState.rejectedField : undefined;
|
|
50
|
+
// Set once the save has settled, not as it fails: the fields are still locked then, and a locked control refuses focus.
|
|
51
|
+
React.useEffect(() => {
|
|
52
|
+
if (rejectedField)
|
|
53
|
+
setError(rejectedField.field, { type: 'server', message: rejectedField.message }, { shouldFocus: true });
|
|
54
|
+
}, [rejectedField, setError]);
|
|
55
|
+
// Awaited by `Form`, so the form counts as submitting until the save lands, which locks its fields.
|
|
56
|
+
const submit = async (submitted) => {
|
|
57
|
+
setSaveState({ status: 'saving' });
|
|
58
|
+
try {
|
|
59
|
+
await save(submitted);
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
return setSaveState({ status: 'failed', error, rejectedField: rejectedFieldOf(fieldErrorOf, error) });
|
|
63
|
+
}
|
|
64
|
+
// What the form holds is what was sent: the resolved value may be any shape, and the saved record arrives through `values`.
|
|
65
|
+
reset(getValues(), START_AGAIN);
|
|
66
|
+
return setSaveState({ status: 'saved' });
|
|
67
|
+
};
|
|
68
|
+
const discard = () => {
|
|
69
|
+
// Mid-save it would end the hold on `values`, and a refetch landing then would unlock the fields.
|
|
70
|
+
if (isSaving)
|
|
71
|
+
return;
|
|
72
|
+
reset(undefined, START_AGAIN);
|
|
73
|
+
setSaveState({ status: 'idle' });
|
|
74
|
+
};
|
|
75
|
+
// Only a failure is dismissed: clearing a save in flight would end the hold on `values` too.
|
|
76
|
+
const dismissSaveError = () => setSaveState((current) => (current.status === 'failed' ? { status: 'idle' } : current));
|
|
77
|
+
const hasErrors = Object.keys(errors).length > 0;
|
|
78
|
+
const hasSaveError = saveState.status === 'failed' && !rejectedField;
|
|
79
|
+
return {
|
|
80
|
+
form,
|
|
81
|
+
submit,
|
|
82
|
+
discard,
|
|
83
|
+
isSaving,
|
|
84
|
+
// The saved check lasts until the next edit, or until an error shows.
|
|
85
|
+
isSaved: hasSaved && !isDirty && !hasErrors,
|
|
86
|
+
hasSaveError,
|
|
87
|
+
saveError: saveState.status === 'failed' && hasSaveError ? saveState.error : undefined,
|
|
88
|
+
dismissSaveError,
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
exports.useSaveForm = useSaveForm;
|
|
93
|
+
//# sourceMappingURL=useSaveForm.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSaveForm.cjs","sources":["../../../../../../src/components/forms/Form/hooks/useSaveForm/useSaveForm.ts"],"sourcesContent":[null],"names":["useState","useForm","useEffect"],"mappings":";;;;;AAsDA;AACA;AACA,MAAM,cAAc,GAAG,EAAE,eAAe,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE;AAEnF;AACA,MAAM,WAAW,GAAG,EAAE,eAAe,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE;AAEnF;AACA,MAAM,eAAe,GAAG,CACtB,YAAyD,EACzD,KAAc,KACyB;AACvC,IAAA,IAAI;AACF,QAAA,OAAO,YAAY,GAAG,KAAK,CAAC;IAC9B;AAAE,IAAA,MAAM;AACN,QAAA,OAAO,SAAS;IAClB;AACF,CAAC;AAED;;;;;;;;;;AAUG;AACH;AACO,MAAM,WAAW,GAAG,CAAqF,EAC9G,IAAI,EACJ,YAAY,EACZ,MAAM,EACN,GAAG,OAAO,EAC2C,KAAyD;AAC9G,IAAA,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAGA,cAAQ,CAAqB,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;AAClF,IAAA,MAAM,QAAQ,GAAG,SAAS,CAAC,MAAM,KAAK,QAAQ;IAE9C,MAAM,IAAI,GAAGC,eAAO,CAAmC;AACrD,QAAA,GAAG,OAAO;;QAEV,MAAM,EAAE,QAAQ,GAAG,SAAS,GAAG,MAAM;AACrC,QAAA,YAAY,EAAE,cAAc;AAC7B,KAAA,CAAC;IACF,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,IAAI;IAC3C,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,SAAS;;AAG1C,IAAA,MAAM,QAAQ,GAAG,SAAS,CAAC,MAAM,KAAK,OAAO;IAC7CC,eAAS,CAAC,MAAK;QACb,IAAI,OAAO,IAAI,QAAQ;AAAE,YAAA,YAAY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AQ,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,CAAC;AAEtH,IAAA,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,GAAG,CAAC;IAChD,MAAM,YAAY,GAAG,SAAS,CAAC,MAAM,KAAK,QAAQ,IAAI,CAAC,aAAa;IAEpE,OAAO;QACL,IAAI;QACJ,MAAM;QACN,OAAO;QACP,QAAQ;;AAER,QAAA,OAAO,EAAE,QAAQ,IAAI,CAAC,OAAO,IAAI,CAAC,SAAS;QAC3C,YAAY;AACZ,QAAA,SAAS,EAAE,SAAS,CAAC,MAAM,KAAK,QAAQ,IAAI,YAAY,GAAG,SAAS,CAAC,KAAK,GAAG,SAAS;QACtF,gBAAgB;KACjB;AACH;;"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { FieldPath, FieldValues, SubmitHandler, UseFormProps, UseFormReturn } from 'react-hook-form';
|
|
2
|
+
/** A field the server rejected, which the form shows beneath that field in place of a failed-save alert. */
|
|
3
|
+
export interface SaveFieldError<TValues extends FieldValues> {
|
|
4
|
+
/** The rejected field's path in the form values. */
|
|
5
|
+
field: FieldPath<TValues>;
|
|
6
|
+
/** The server's message, shown beneath the field. */
|
|
7
|
+
message: string;
|
|
8
|
+
}
|
|
9
|
+
export interface UseSaveFormOptions<TValues extends FieldValues = FieldValues, TContext = any, TSubmitValues = TValues> extends Omit<UseFormProps<TValues, TContext, TSubmitValues>, 'resetOptions'> {
|
|
10
|
+
/**
|
|
11
|
+
* Sends the validated values, such as a mutation's `mutateAsync`; reject to report a failed save. What it resolves
|
|
12
|
+
* with is not read: the form starts again from what it holds, and a record the server changed on the way in reaches
|
|
13
|
+
* it through `values`. Resolve only once `values` holds the saved record: one that lands mid-save is taken as the
|
|
14
|
+
* saved one when the save succeeds, so a record read before the save would show as saved.
|
|
15
|
+
*/
|
|
16
|
+
save: (values: TSubmitValues) => Promise<unknown>;
|
|
17
|
+
/**
|
|
18
|
+
* Picks the field a failed save rejected, from what `save` rejected with. Return `undefined` for any other failure,
|
|
19
|
+
* and for a field the form does not show: that one is reported as a failed save, since no field can show it. One that
|
|
20
|
+
* throws is treated the same way.
|
|
21
|
+
*/
|
|
22
|
+
fieldErrorOf?: (error: unknown) => SaveFieldError<TValues> | undefined;
|
|
23
|
+
}
|
|
24
|
+
export interface UseSaveFormReturn<TValues extends FieldValues = FieldValues, TContext = any, TSubmitValues = TValues> {
|
|
25
|
+
/** The form, for `Form`'s `form` prop. */
|
|
26
|
+
form: UseFormReturn<TValues, TContext, TSubmitValues>;
|
|
27
|
+
/** Saves the validated values, for `Form`'s `onSubmit`. It never rejects: a failure shows in `hasSaveError` or beneath a field. */
|
|
28
|
+
submit: SubmitHandler<TSubmitValues>;
|
|
29
|
+
/** Puts the form back to what was loaded or last saved and clears a failed save, for `FormFooter`'s `onDiscard`. Ignored while a save is in flight. */
|
|
30
|
+
discard: () => void;
|
|
31
|
+
/** Whether a save is in flight. */
|
|
32
|
+
isSaving: boolean;
|
|
33
|
+
/** Whether the last save succeeded and nothing has changed since, for `FormFooter`'s `isSaved`. */
|
|
34
|
+
isSaved: boolean;
|
|
35
|
+
/** Whether the last save failed outright, which is when to render `FormSaveErrorAlert`. `false` when a field took the rejection. */
|
|
36
|
+
hasSaveError: boolean;
|
|
37
|
+
/** What `save` rejected with while `hasSaveError` is `true`, to read the server's reason from. */
|
|
38
|
+
saveError: unknown;
|
|
39
|
+
/** Clears a failed save, for `FormSaveErrorAlert`'s `onDismiss`. */
|
|
40
|
+
dismissSaveError: () => void;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Creates a form that waits on Save, and owns what happens around the save: it starts again from what was saved, keeps
|
|
44
|
+
* a draft through a refetch, holds a refetch that lands mid-save, and reports a failure beside Save or beneath the field
|
|
45
|
+
* the server rejected. Use it in place of `useForm` for a form with `FormFooter`, mounted once per record: give the
|
|
46
|
+
* form's component a `key` of the record's id, so another record never inherits this one's save.
|
|
47
|
+
*
|
|
48
|
+
* @param options Every option this module's `useForm` takes except `resetOptions`, with `save` and `fieldErrorOf`; see
|
|
49
|
+
* `UseSaveFormOptions`. Pass the loaded record as `values`, so the fields the user has not edited follow a refetch.
|
|
50
|
+
* @returns The form and its save state, with one handler per action; see `UseSaveFormReturn`. "Try again" has none:
|
|
51
|
+
* `FormSaveErrorAlert` submits the form itself, as Save does.
|
|
52
|
+
*/
|
|
53
|
+
export declare const useSaveForm: <TValues extends FieldValues = FieldValues, TContext = any, TSubmitValues = TValues>({ save, fieldErrorOf, values, ...options }: UseSaveFormOptions<TValues, TContext, TSubmitValues>) => UseSaveFormReturn<TValues, TContext, TSubmitValues>;
|
|
54
|
+
//# sourceMappingURL=useSaveForm.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSaveForm.d.ts","sourceRoot":"","sources":["../../../../../../src/components/forms/Form/hooks/useSaveForm/useSaveForm.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,aAAa,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAG1G,4GAA4G;AAC5G,MAAM,WAAW,cAAc,CAAC,OAAO,SAAS,WAAW;IACzD,oDAAoD;IACpD,KAAK,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC;IAC1B,qDAAqD;IACrD,OAAO,EAAE,MAAM,CAAC;CACjB;AAGD,MAAM,WAAW,kBAAkB,CAAC,OAAO,SAAS,WAAW,GAAG,WAAW,EAAE,QAAQ,GAAG,GAAG,EAAE,aAAa,GAAG,OAAO,CACpH,SAAQ,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,QAAQ,EAAE,aAAa,CAAC,EAAE,cAAc,CAAC;IAC5E;;;;;OAKG;IACH,IAAI,EAAE,CAAC,MAAM,EAAE,aAAa,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IAClD;;;;OAIG;IACH,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,cAAc,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC;CACxE;AAGD,MAAM,WAAW,iBAAiB,CAAC,OAAO,SAAS,WAAW,GAAG,WAAW,EAAE,QAAQ,GAAG,GAAG,EAAE,aAAa,GAAG,OAAO;IACnH,0CAA0C;IAC1C,IAAI,EAAE,aAAa,CAAC,OAAO,EAAE,QAAQ,EAAE,aAAa,CAAC,CAAC;IACtD,mIAAmI;IACnI,MAAM,EAAE,aAAa,CAAC,aAAa,CAAC,CAAC;IACrC,uJAAuJ;IACvJ,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,mCAAmC;IACnC,QAAQ,EAAE,OAAO,CAAC;IAClB,mGAAmG;IACnG,OAAO,EAAE,OAAO,CAAC;IACjB,oIAAoI;IACpI,YAAY,EAAE,OAAO,CAAC;IACtB,kGAAkG;IAClG,SAAS,EAAE,OAAO,CAAC;IACnB,oEAAoE;IACpE,gBAAgB,EAAE,MAAM,IAAI,CAAC;CAC9B;AAyBD;;;;;;;;;;GAUG;AAEH,eAAO,MAAM,WAAW,GAAI,OAAO,SAAS,WAAW,GAAG,WAAW,EAAE,QAAQ,GAAG,GAAG,EAAE,aAAa,GAAG,OAAO,EAAE,4CAK7G,kBAAkB,CAAC,OAAO,EAAE,QAAQ,EAAE,aAAa,CAAC,KAAG,iBAAiB,CAAC,OAAO,EAAE,QAAQ,EAAE,aAAa,CA4D3G,CAAC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
|
+
import { useForm } from '../useForm.js';
|
|
3
|
+
|
|
4
|
+
// A refetch brings newer values: the fields the user has edited keep the draft, the rest follow the server. The errors
|
|
5
|
+
// on screen and the dirty flag stay too, or a refetch would hide a rejection and switch Save off for a moment.
|
|
6
|
+
const FOLLOW_REFETCH = { keepDirtyValues: true, keepErrors: true, keepDirty: true };
|
|
7
|
+
// A save and Discard start the form again: `resetOptions` reaches each `reset` call, and would keep the edits and errors.
|
|
8
|
+
const START_AGAIN = { keepDirtyValues: false, keepErrors: false, keepDirty: false };
|
|
9
|
+
// A mapper written for the server's rejections may not expect a network failure, and one that threw would leave the save in flight for good.
|
|
10
|
+
const rejectedFieldOf = (fieldErrorOf, error) => {
|
|
11
|
+
try {
|
|
12
|
+
return fieldErrorOf?.(error);
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Creates a form that waits on Save, and owns what happens around the save: it starts again from what was saved, keeps
|
|
20
|
+
* a draft through a refetch, holds a refetch that lands mid-save, and reports a failure beside Save or beneath the field
|
|
21
|
+
* the server rejected. Use it in place of `useForm` for a form with `FormFooter`, mounted once per record: give the
|
|
22
|
+
* form's component a `key` of the record's id, so another record never inherits this one's save.
|
|
23
|
+
*
|
|
24
|
+
* @param options Every option this module's `useForm` takes except `resetOptions`, with `save` and `fieldErrorOf`; see
|
|
25
|
+
* `UseSaveFormOptions`. Pass the loaded record as `values`, so the fields the user has not edited follow a refetch.
|
|
26
|
+
* @returns The form and its save state, with one handler per action; see `UseSaveFormReturn`. "Try again" has none:
|
|
27
|
+
* `FormSaveErrorAlert` submits the form itself, as Save does.
|
|
28
|
+
*/
|
|
29
|
+
// biome-ignore lint/suspicious/noExplicitAny: mirrors react-hook-form's own `TContext = any`, so the two signatures stay interchangeable
|
|
30
|
+
const useSaveForm = ({ save, fieldErrorOf, values, ...options }) => {
|
|
31
|
+
const [saveState, setSaveState] = useState({ status: 'idle' });
|
|
32
|
+
const isSaving = saveState.status === 'saving';
|
|
33
|
+
const form = useForm({
|
|
34
|
+
...options,
|
|
35
|
+
// Held while a save is in flight: a refetch landing then would reset the form, which ends the lock on its fields.
|
|
36
|
+
values: isSaving ? undefined : values,
|
|
37
|
+
resetOptions: FOLLOW_REFETCH,
|
|
38
|
+
});
|
|
39
|
+
const { reset, setError, getValues } = form;
|
|
40
|
+
const { isDirty, errors } = form.formState;
|
|
41
|
+
// The saved check ends with the next edit, for good: undoing that edit by hand must not bring it back with nothing saved.
|
|
42
|
+
const hasSaved = saveState.status === 'saved';
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
if (isDirty && hasSaved)
|
|
45
|
+
setSaveState({ status: 'idle' });
|
|
46
|
+
}, [isDirty, hasSaved]);
|
|
47
|
+
const rejectedField = saveState.status === 'failed' ? saveState.rejectedField : undefined;
|
|
48
|
+
// Set once the save has settled, not as it fails: the fields are still locked then, and a locked control refuses focus.
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
if (rejectedField)
|
|
51
|
+
setError(rejectedField.field, { type: 'server', message: rejectedField.message }, { shouldFocus: true });
|
|
52
|
+
}, [rejectedField, setError]);
|
|
53
|
+
// Awaited by `Form`, so the form counts as submitting until the save lands, which locks its fields.
|
|
54
|
+
const submit = async (submitted) => {
|
|
55
|
+
setSaveState({ status: 'saving' });
|
|
56
|
+
try {
|
|
57
|
+
await save(submitted);
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
return setSaveState({ status: 'failed', error, rejectedField: rejectedFieldOf(fieldErrorOf, error) });
|
|
61
|
+
}
|
|
62
|
+
// What the form holds is what was sent: the resolved value may be any shape, and the saved record arrives through `values`.
|
|
63
|
+
reset(getValues(), START_AGAIN);
|
|
64
|
+
return setSaveState({ status: 'saved' });
|
|
65
|
+
};
|
|
66
|
+
const discard = () => {
|
|
67
|
+
// Mid-save it would end the hold on `values`, and a refetch landing then would unlock the fields.
|
|
68
|
+
if (isSaving)
|
|
69
|
+
return;
|
|
70
|
+
reset(undefined, START_AGAIN);
|
|
71
|
+
setSaveState({ status: 'idle' });
|
|
72
|
+
};
|
|
73
|
+
// Only a failure is dismissed: clearing a save in flight would end the hold on `values` too.
|
|
74
|
+
const dismissSaveError = () => setSaveState((current) => (current.status === 'failed' ? { status: 'idle' } : current));
|
|
75
|
+
const hasErrors = Object.keys(errors).length > 0;
|
|
76
|
+
const hasSaveError = saveState.status === 'failed' && !rejectedField;
|
|
77
|
+
return {
|
|
78
|
+
form,
|
|
79
|
+
submit,
|
|
80
|
+
discard,
|
|
81
|
+
isSaving,
|
|
82
|
+
// The saved check lasts until the next edit, or until an error shows.
|
|
83
|
+
isSaved: hasSaved && !isDirty && !hasErrors,
|
|
84
|
+
hasSaveError,
|
|
85
|
+
saveError: saveState.status === 'failed' && hasSaveError ? saveState.error : undefined,
|
|
86
|
+
dismissSaveError,
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
export { useSaveForm };
|
|
91
|
+
//# sourceMappingURL=useSaveForm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSaveForm.js","sources":["../../../../../../src/components/forms/Form/hooks/useSaveForm/useSaveForm.ts"],"sourcesContent":[null],"names":[],"mappings":";;;AAsDA;AACA;AACA,MAAM,cAAc,GAAG,EAAE,eAAe,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE;AAEnF;AACA,MAAM,WAAW,GAAG,EAAE,eAAe,EAAE,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE;AAEnF;AACA,MAAM,eAAe,GAAG,CACtB,YAAyD,EACzD,KAAc,KACyB;AACvC,IAAA,IAAI;AACF,QAAA,OAAO,YAAY,GAAG,KAAK,CAAC;IAC9B;AAAE,IAAA,MAAM;AACN,QAAA,OAAO,SAAS;IAClB;AACF,CAAC;AAED;;;;;;;;;;AAUG;AACH;AACO,MAAM,WAAW,GAAG,CAAqF,EAC9G,IAAI,EACJ,YAAY,EACZ,MAAM,EACN,GAAG,OAAO,EAC2C,KAAyD;AAC9G,IAAA,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAAqB,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;AAClF,IAAA,MAAM,QAAQ,GAAG,SAAS,CAAC,MAAM,KAA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C,EAAE,CAAC;QACvG;;AAEA,QAAA,KAAK,CAAC,SAAS,EAAE,EAAE,WAAW,CAAC;QAC/B,OAAO,YAAY,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;AAC1C,IAAA,CAAC;IACD,MAAM,OAAO,GAAG,MAAK;;AAEnB,QAAA,IAAI,QAAQ;YAAE;AACd,QAAA,KAAK,CAAC,SAAS,EAAE,WAAW,CAAC;AAC7B,QAAA,YAAY,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC;AAClC,IAAA,CAAC;;AAED,IAAA,MAAM,gBAAgB,GAAG,MAAM,YAAY,CAAC,CAAC,OAAO,MAAM,OAAO,CAAC,MAAM,KAAK,QAAQ,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,CAAC;AAEtH,IAAA,MAAM,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,GAAG,CAAC;IAChD,MAAM,YAAY,GAAG,SAAS,CAAC,MAAM,KAAK,QAAQ,IAAI,CAAC,aAAa;IAEpE,OAAO;QACL,IAAI;QACJ,MAAM;QACN,OAAO;QACP,QAAQ;;AAER,QAAA,OAAO,EAAE,QAAQ,IAAI,CAAC,OAAO,IAAI,CAAC,SAAS;QAC3C,YAAY;AACZ,QAAA,SAAS,EAAE,SAAS,CAAC,MAAM,KAAK,QAAQ,IAAI,YAAY,GAAG,SAAS,CAAC,KAAK,GAAG,SAAS;QACtF,gBAAgB;KACjB;AACH;;"}
|
|
@@ -8,10 +8,17 @@ var reactHookForm = require('react-hook-form');
|
|
|
8
8
|
var FieldElements_context = require('../__internal__/formField/providers/FieldElements.context.cjs');
|
|
9
9
|
var fieldElements_utils = require('../__internal__/formField/utilities/fieldElements.utils.cjs');
|
|
10
10
|
var formFocus_utils = require('../__internal__/formField/utilities/formFocus.utils.cjs');
|
|
11
|
+
var FormSubmit_context = require('../__internal__/formSubmit/providers/FormSubmit.context.cjs');
|
|
11
12
|
var useSubmitInTurn = require('./hooks/useSubmitInTurn/useSubmitInTurn.cjs');
|
|
12
13
|
var formSubmit_utils = require('./utilities/formSubmit.utils.cjs');
|
|
13
14
|
var useForm = require('./hooks/useForm.cjs');
|
|
15
|
+
var useSaveForm = require('./hooks/useSaveForm/useSaveForm.cjs');
|
|
14
16
|
|
|
17
|
+
/** Wraps a form's fields and marks them busy while the form submits, which is when they lock themselves. */
|
|
18
|
+
const FormFields = (props) => {
|
|
19
|
+
const { isSubmitting } = reactHookForm.useFormState();
|
|
20
|
+
return jsxRuntime.jsx("div", { ...props, "aria-busy": isSubmitting });
|
|
21
|
+
};
|
|
15
22
|
/**
|
|
16
23
|
* The `<form>` around `Form*` fields: it provides the react-hook-form form to them, leaves validation to the schema,
|
|
17
24
|
* focuses the first invalid field in page order after a failed submit, and ignores a second submit while one is running.
|
|
@@ -19,9 +26,20 @@ var useForm = require('./hooks/useForm.cjs');
|
|
|
19
26
|
*
|
|
20
27
|
* @summary form element that provides a react-hook-form form to its fields
|
|
21
28
|
*/
|
|
22
|
-
const Form = ({ form, onSubmit, onInvalid, className, children, 'data-testid': dataTestId, ...formProps }) => {
|
|
29
|
+
const Form = ({ form, onSubmit, onInvalid, ref, className, children, 'data-testid': dataTestId, ...formProps }) => {
|
|
23
30
|
const formTestId = testIdUtils.useResolvedTestId({ testId: dataTestId, segment: 'form', rootName: 'form' });
|
|
24
31
|
const [fieldElements] = React.useState(fieldElements_utils.createFieldElements);
|
|
32
|
+
// Kept beside the caller's ref: a retry inside the form submits this element, whether or not the caller holds one.
|
|
33
|
+
const formElement = React.useRef(null);
|
|
34
|
+
const setFormElement = React.useCallback((element) => {
|
|
35
|
+
formElement.current = element;
|
|
36
|
+
if (typeof ref === 'function')
|
|
37
|
+
return ref(element);
|
|
38
|
+
if (ref)
|
|
39
|
+
ref.current = element;
|
|
40
|
+
return undefined;
|
|
41
|
+
}, [ref]);
|
|
42
|
+
const requestSubmit = React.useCallback(() => formElement.current?.requestSubmit(), []);
|
|
25
43
|
// The focus lands once the submit is over: react-hook-form moves it on a timer, and a control the submit disabled
|
|
26
44
|
// takes it only when it is enabled again. `onInvalid` is therefore not told where focus is.
|
|
27
45
|
const focusFirstInvalid = (errors, event) => {
|
|
@@ -31,13 +49,15 @@ const Form = ({ form, onSubmit, onInvalid, className, children, 'data-testid': d
|
|
|
31
49
|
return onInvalid?.(errors, event);
|
|
32
50
|
};
|
|
33
51
|
const submit = useSubmitInTurn.useSubmitInTurn(formSubmit_utils.submitAfterValidations(form, onSubmit, focusFirstInvalid));
|
|
34
|
-
return (jsxRuntime.jsx(reactHookForm.FormProvider, { ...form, children: jsxRuntime.jsx(FieldElements_context.FieldElementsContext, { value: fieldElements, children: jsxRuntime.jsx("form", { ...formProps,
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
52
|
+
return (jsxRuntime.jsx(reactHookForm.FormProvider, { ...form, children: jsxRuntime.jsx(FieldElements_context.FieldElementsContext, { value: fieldElements, children: jsxRuntime.jsx(FormSubmit_context.FormSubmitContext, { value: requestSubmit, children: jsxRuntime.jsx("form", { ...formProps, ref: setFormElement,
|
|
53
|
+
// The schema validates; the browser's own checks (`type="email"`, `required`) would block the submit before it runs.
|
|
54
|
+
noValidate: true,
|
|
55
|
+
// Focusable from code only: a control that turns itself off, such as Discard, hands focus here so it is not lost.
|
|
56
|
+
tabIndex: -1, onSubmit: submit, "data-testid": formTestId, className: cx.cx('outline-focus-ring focus-visible:outline-2 focus-visible:outline-offset-2', className), children: children }) }) }) }));
|
|
39
57
|
};
|
|
58
|
+
Form.Fields = FormFields;
|
|
40
59
|
|
|
41
60
|
exports.useForm = useForm.useForm;
|
|
61
|
+
exports.useSaveForm = useSaveForm.useSaveForm;
|
|
42
62
|
exports.Form = Form;
|
|
43
63
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../../../src/components/forms/Form/index.tsx"],"sourcesContent":[null],"names":["useResolvedTestId","useState","createFieldElements","firstInvalidFieldOnPage","useSubmitInTurn","submitAfterValidations","
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../../../src/components/forms/Form/index.tsx"],"sourcesContent":[null],"names":["useFormState","_jsx","useResolvedTestId","useState","createFieldElements","useRef","useCallback","firstInvalidFieldOnPage","useSubmitInTurn","submitAfterValidations","FormProvider","FieldElementsContext","FormSubmitContext","cx"],"mappings":";;;;;;;;;;;;;;;;AAgDA;AACA,MAAM,UAAU,GAAG,CAAC,KAAsB,KAAI;AAC5C,IAAA,MAAM,EAAE,YAAY,EAAE,GAAGA,0BAAY,EAAE;AAEvC,IAAA,OAAOC,cAAA,CAAA,KAAA,EAAA,EAAA,GAAS,KAAK,EAAA,WAAA,EAAa,YAAY,GAAI;AACpD,CAAC;AAED;;;;;;AAMG;AACI,MAAM,IAAI,GAAG,CAAqE,EACvF,IAAI,EACJ,QAAQ,EACR,SAAS,EACT,GAAG,EACH,SAAS,EACT,QAAQ,EACR,aAAa,EAAE,UAAU,EACzB,GAAG,SAAS,EACsB,KAAI;AACtC,IAAA,MAAM,UAAU,GAAGC,6BAAiB,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;IAC/F,MAAM,CAAC,aAAa,CAAC,GAAGC,cAAQ,CAACC,uCAAmB,CAAC;;AAGrD,IAAA,MAAM,WAAW,GAAGC,YAAM,CAAyB,IAAI,CAAC;AACxD,IAAA,MAAM,cAAc,GAAGC,iBAAW,CAChC,CAAC,OAA+B,KAAI;AAClC,QAAA,WAAW,CAAC,OAAO,GAAG,OAAO;QAC7B,IAAI,OAAO,GAAG,KAAK,UAAU;AAAE,YAAA,OAAO,GAAG,CAAC,OAAO,CAAC;AAClD,QAAA,IAAI,GAAG;AAAE,YAAA,GAAG,CAAC,OAAO,GAAG,OAAO;AAC9B,QAAA,OAAO,SAAS;AAClB,IAAA,CAAC,EACD,CAAC,GAAG,CAAC,CACN;AACD,IAAA,MAAM,aAAa,GAAGA,iBAAW,CAAC,MAAM,WAAW,CAAC,OAAO,EAAE,aAAa,EAAE,EAAE,EAAE,CAAC;;;AAIjF,IAAA,MAAM,iBAAiB,GAAgC,CAAC,MAAM,EAAE,KAAK,KAAI;QACvE,MAAM,KAAK,GAAGC,uCAAuB,CAAC,MAAM,EAAE,aAAa,CAAC,QAAQ,CAAC;AACrE,QAAA,IAAI,KAAK;AAAE,YAAA,IAAI,CAAC,QAAQ,CAAC,KAA2B,CAAC;AACrD,QAAA,OAAO,SAAS,GAAG,MAAM,EAAE,KAAK,CAAC;AACnC,IAAA,CAAC;AAED,IAAA,MAAM,MAAM,GAAGC,+BAAe,CAACC,uCAAsB,CAAC,IAAI,EAAE,QAAQ,EAAE,iBAAiB,CAAC,CAAC;IAEzF,QACER,cAAA,CAACS,0BAAY,EAAA,EAAA,GAAK,IAAI,YACpBT,cAAA,CAACU,0CAAoB,EAAA,EAAC,KAAK,EAAE,aAAa,YACxCV,cAAA,CAACW,oCAAiB,EAAA,EAAC,KAAK,EAAE,aAAa,EAAA,QAAA,EACrCX,cAAA,CAAA,MAAA,EAAA,EAAA,GACM,SAAS,EACb,GAAG,EAAE,cAAc;;oBAEnB,UAAU,EAAA,IAAA;;oBAEV,QAAQ,EAAE,EAAE,EACZ,QAAQ,EAAE,MAAM,EAAA,aAAA,EACH,UAAU,EACvB,SAAS,EAAEY,KAAE,CAAC,2EAA2E,EAAE,SAAS,CAAC,EAAA,QAAA,EAEpG,QAAQ,EAAA,CACJ,EAAA,CACW,EAAA,CACC,EAAA,CACV;AAEnB;AAEA,IAAI,CAAC,MAAM,GAAG,UAAU;;;;"}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { type ComponentProps, type Ref } from 'react';
|
|
2
2
|
import { type FieldValues, type SubmitErrorHandler, type SubmitHandler, type UseFormReturn } from 'react-hook-form';
|
|
3
3
|
export { useForm } from './hooks/useForm';
|
|
4
|
+
export type { SaveFieldError, UseSaveFormOptions, UseSaveFormReturn } from './hooks/useSaveForm/useSaveForm';
|
|
5
|
+
export { useSaveForm } from './hooks/useSaveForm/useSaveForm';
|
|
4
6
|
export interface FormProps<TValues extends FieldValues = FieldValues, TSubmitValues = TValues> extends Omit<ComponentProps<'form'>, 'onSubmit' | 'onInvalid' | 'noValidate' | 'ref'> {
|
|
5
7
|
/**
|
|
6
|
-
* The form from this module's `useForm`; every `Form*` field and `FormFooter` beneath reads it. One from
|
|
8
|
+
* The form from this module's `useForm` or `useSaveForm`; every `Form*` field and `FormFooter` beneath reads it. One from
|
|
7
9
|
* react-hook-form's own `useForm` needs `mode` and `reValidateMode` set to `'onBlur'` and `shouldFocusError` to `false`.
|
|
8
10
|
*/
|
|
9
11
|
form: UseFormReturn<TValues, any, TSubmitValues>;
|
|
@@ -19,6 +21,8 @@ export interface FormProps<TValues extends FieldValues = FieldValues, TSubmitVal
|
|
|
19
21
|
/** Overrides the `data-testid` (defaults to `fd-form`). */
|
|
20
22
|
'data-testid'?: string;
|
|
21
23
|
}
|
|
24
|
+
export interface FormFieldsProps extends Omit<ComponentProps<'div'>, 'aria-busy'> {
|
|
25
|
+
}
|
|
22
26
|
/**
|
|
23
27
|
* The `<form>` around `Form*` fields: it provides the react-hook-form form to them, leaves validation to the schema,
|
|
24
28
|
* focuses the first invalid field in page order after a failed submit, and ignores a second submit while one is running.
|
|
@@ -26,5 +30,8 @@ export interface FormProps<TValues extends FieldValues = FieldValues, TSubmitVal
|
|
|
26
30
|
*
|
|
27
31
|
* @summary form element that provides a react-hook-form form to its fields
|
|
28
32
|
*/
|
|
29
|
-
export declare const Form:
|
|
33
|
+
export declare const Form: {
|
|
34
|
+
<TValues extends FieldValues = FieldValues, TSubmitValues = TValues>({ form, onSubmit, onInvalid, ref, className, children, "data-testid": dataTestId, ...formProps }: FormProps<TValues, TSubmitValues>): import("react").JSX.Element;
|
|
35
|
+
Fields: (props: FormFieldsProps) => import("react").JSX.Element;
|
|
36
|
+
};
|
|
30
37
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/forms/Form/index.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,GAAG,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/forms/Form/index.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,GAAG,EAAiC,MAAM,OAAO,CAAC;AACrF,OAAO,EAEL,KAAK,WAAW,EAEhB,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAClB,KAAK,aAAa,EAEnB,MAAM,iBAAiB,CAAC;AAQzB,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,YAAY,EAAE,cAAc,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AAC7G,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAE9D,MAAM,WAAW,SAAS,CAAC,OAAO,SAAS,WAAW,GAAG,WAAW,EAAE,aAAa,GAAG,OAAO,CAC3F,SAAQ,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,UAAU,GAAG,WAAW,GAAG,YAAY,GAAG,KAAK,CAAC;IACrF;;;OAGG;IAEH,IAAI,EAAE,aAAa,CAAC,OAAO,EAAE,GAAG,EAAE,aAAa,CAAC,CAAC;IACjD;;;OAGG;IACH,QAAQ,EAAE,aAAa,CAAC,aAAa,CAAC,CAAC;IACvC,4GAA4G;IAC5G,SAAS,CAAC,EAAE,kBAAkB,CAAC,OAAO,CAAC,CAAC;IACxC,mCAAmC;IACnC,GAAG,CAAC,EAAE,GAAG,CAAC,eAAe,CAAC,CAAC;IAC3B,2DAA2D;IAC3D,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,eAAgB,SAAQ,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE,WAAW,CAAC;CAAG;AASpF;;;;;;GAMG;AACH,eAAO,MAAM,IAAI;KAAI,OAAO,SAAS,WAAW,gBAAgB,aAAa,8GAS1E,SAAS,CAAC,OAAO,EAAE,aAAa,CAAC;oBAtBT,eAAe;CAsEzC,CAAC"}
|
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
2
|
import { cx } from '@flipdish/ui-library/utilities/cx';
|
|
3
3
|
import { useResolvedTestId } from '@flipdish/ui-library/utilities/testIdUtils';
|
|
4
|
-
import { useState } from 'react';
|
|
5
|
-
import { FormProvider } from 'react-hook-form';
|
|
4
|
+
import { useState, useRef, useCallback } from 'react';
|
|
5
|
+
import { FormProvider, useFormState } from 'react-hook-form';
|
|
6
6
|
import { FieldElementsContext } from '../__internal__/formField/providers/FieldElements.context.js';
|
|
7
7
|
import { createFieldElements } from '../__internal__/formField/utilities/fieldElements.utils.js';
|
|
8
8
|
import { firstInvalidFieldOnPage } from '../__internal__/formField/utilities/formFocus.utils.js';
|
|
9
|
+
import { FormSubmitContext } from '../__internal__/formSubmit/providers/FormSubmit.context.js';
|
|
9
10
|
import { useSubmitInTurn } from './hooks/useSubmitInTurn/useSubmitInTurn.js';
|
|
10
11
|
import { submitAfterValidations } from './utilities/formSubmit.utils.js';
|
|
11
12
|
export { useForm } from './hooks/useForm.js';
|
|
13
|
+
export { useSaveForm } from './hooks/useSaveForm/useSaveForm.js';
|
|
12
14
|
|
|
15
|
+
/** Wraps a form's fields and marks them busy while the form submits, which is when they lock themselves. */
|
|
16
|
+
const FormFields = (props) => {
|
|
17
|
+
const { isSubmitting } = useFormState();
|
|
18
|
+
return jsx("div", { ...props, "aria-busy": isSubmitting });
|
|
19
|
+
};
|
|
13
20
|
/**
|
|
14
21
|
* The `<form>` around `Form*` fields: it provides the react-hook-form form to them, leaves validation to the schema,
|
|
15
22
|
* focuses the first invalid field in page order after a failed submit, and ignores a second submit while one is running.
|
|
@@ -17,9 +24,20 @@ export { useForm } from './hooks/useForm.js';
|
|
|
17
24
|
*
|
|
18
25
|
* @summary form element that provides a react-hook-form form to its fields
|
|
19
26
|
*/
|
|
20
|
-
const Form = ({ form, onSubmit, onInvalid, className, children, 'data-testid': dataTestId, ...formProps }) => {
|
|
27
|
+
const Form = ({ form, onSubmit, onInvalid, ref, className, children, 'data-testid': dataTestId, ...formProps }) => {
|
|
21
28
|
const formTestId = useResolvedTestId({ testId: dataTestId, segment: 'form', rootName: 'form' });
|
|
22
29
|
const [fieldElements] = useState(createFieldElements);
|
|
30
|
+
// Kept beside the caller's ref: a retry inside the form submits this element, whether or not the caller holds one.
|
|
31
|
+
const formElement = useRef(null);
|
|
32
|
+
const setFormElement = useCallback((element) => {
|
|
33
|
+
formElement.current = element;
|
|
34
|
+
if (typeof ref === 'function')
|
|
35
|
+
return ref(element);
|
|
36
|
+
if (ref)
|
|
37
|
+
ref.current = element;
|
|
38
|
+
return undefined;
|
|
39
|
+
}, [ref]);
|
|
40
|
+
const requestSubmit = useCallback(() => formElement.current?.requestSubmit(), []);
|
|
23
41
|
// The focus lands once the submit is over: react-hook-form moves it on a timer, and a control the submit disabled
|
|
24
42
|
// takes it only when it is enabled again. `onInvalid` is therefore not told where focus is.
|
|
25
43
|
const focusFirstInvalid = (errors, event) => {
|
|
@@ -29,12 +47,13 @@ const Form = ({ form, onSubmit, onInvalid, className, children, 'data-testid': d
|
|
|
29
47
|
return onInvalid?.(errors, event);
|
|
30
48
|
};
|
|
31
49
|
const submit = useSubmitInTurn(submitAfterValidations(form, onSubmit, focusFirstInvalid));
|
|
32
|
-
return (jsx(FormProvider, { ...form, children: jsx(FieldElementsContext, { value: fieldElements, children: jsx("form", { ...formProps,
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
50
|
+
return (jsx(FormProvider, { ...form, children: jsx(FieldElementsContext, { value: fieldElements, children: jsx(FormSubmitContext, { value: requestSubmit, children: jsx("form", { ...formProps, ref: setFormElement,
|
|
51
|
+
// The schema validates; the browser's own checks (`type="email"`, `required`) would block the submit before it runs.
|
|
52
|
+
noValidate: true,
|
|
53
|
+
// Focusable from code only: a control that turns itself off, such as Discard, hands focus here so it is not lost.
|
|
54
|
+
tabIndex: -1, onSubmit: submit, "data-testid": formTestId, className: cx('outline-focus-ring focus-visible:outline-2 focus-visible:outline-offset-2', className), children: children }) }) }) }));
|
|
37
55
|
};
|
|
56
|
+
Form.Fields = FormFields;
|
|
38
57
|
|
|
39
58
|
export { Form };
|
|
40
59
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../src/components/forms/Form/index.tsx"],"sourcesContent":[null],"names":["_jsx"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../src/components/forms/Form/index.tsx"],"sourcesContent":[null],"names":["_jsx"],"mappings":";;;;;;;;;;;;;;AAgDA;AACA,MAAM,UAAU,GAAG,CAAC,KAAsB,KAAI;AAC5C,IAAA,MAAM,EAAE,YAAY,EAAE,GAAG,YAAY,EAAE;AAEvC,IAAA,OAAOA,GAAA,CAAA,KAAA,EAAA,EAAA,GAAS,KAAK,EAAA,WAAA,EAAa,YAAY,GAAI;AACpD,CAAC;AAED;;;;;;AAMG;AACI,MAAM,IAAI,GAAG,CAAqE,EACvF,IAAI,EACJ,QAAQ,EACR,SAAS,EACT,GAAG,EACH,SAAS,EACT,QAAQ,EACR,aAAa,EAAE,UAAU,EACzB,GAAG,SAAS,EACsB,KAAI;AACtC,IAAA,MAAM,UAAU,GAAG,iBAAiB,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC;IAC/F,MAAM,CAAC,aAAa,CAAC,GAAG,QAAQ,CAAC,mBAAmB,CAAC;;AAGrD,IAAA,MAAM,WAAW,GAAG,MAA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AE,SAAS,CAAC,EAAA,QAAA,EAEpG,QAAQ,EAAA,CACJ,EAAA,CACW,EAAA,CACC,EAAA,CACV;AAEnB;AAEA,IAAI,CAAC,MAAM,GAAG,UAAU;;"}
|
|
@@ -34,7 +34,7 @@ const FormFooter = ({ onDiscard, isSaved = false, destructiveAction, isDirty: is
|
|
|
34
34
|
return (
|
|
35
35
|
// On a phone the buttons stack full width in the order they sit in a row on a wider screen: the destructive action,
|
|
36
36
|
// Discard, then Save last.
|
|
37
|
-
jsxRuntime.jsxs(SectionFooter.SectionFooter.Root, { ref: originRef, "data-testid": rootTestId, className: "flex-col items-stretch gap-3 sm:flex-row sm:flex-wrap sm:items-center sm:gap-5", children: [destructiveAction && (jsxRuntime.jsx(Button.Button, { color: "secondary-destructive", size: "md", iconLeading: uiIcons.Trash01, isDisabled: isSaving, onPress: destructiveAction.confirmation ? confirmation.open : destructiveAction.onPress, "data-testid": testIdUtils.joinTestId(rootTestId, 'destructive-action'), children: destructiveAction.label })), destructiveAction?.confirmation && (jsxRuntime.jsx(Modals.ConfirmationModal, { isOpen: confirmation.isOpen, onOpenChange: confirmation.onOpenChange, title: destructiveAction.confirmation.title, description: destructiveAction.confirmation.description, confirmLabel: destructiveAction.label, onConfirm: confirmation.confirm, isConfirming: confirmation.isConfirming, isDestructive: true, "data-testid": testIdUtils.joinTestId(rootTestId, 'destructive-confirmation') })), jsxRuntime.jsxs(SectionFooter.SectionFooter.Actions, { className: "flex-none flex-col items-stretch sm:flex-1 sm:flex-row sm:flex-wrap sm:items-center", children: [jsxRuntime.jsx("output", { className: "sr-only", children: isSaved && 'Changes saved' }), jsxRuntime.jsx(Button.Button, { color: "secondary", size: "md", iconLeading: uiIcons.ReverseLeft, isDisabled: !isDirty || isSaving, onPress: discard, "data-testid": testIdUtils.joinTestId(rootTestId, 'discard'), children: "Discard" }), jsxRuntime.jsx(Button.Button, { type: "submit", color: "primary", size: "md", iconLeading: uiIcons.Save01, isDisabled: hasErrors, isLoading: isSaving, showTextWhileLoading: true, isSuccess: isSaved, "data-testid": testIdUtils.joinTestId(rootTestId, 'save'), children: "Save" })] })] }));
|
|
37
|
+
jsxRuntime.jsxs(SectionFooter.SectionFooter.Root, { ref: originRef, "data-testid": rootTestId, className: "flex-col items-stretch gap-3 sm:flex-row sm:flex-wrap sm:items-center sm:gap-5", children: [destructiveAction && (jsxRuntime.jsx(Button.Button, { color: "secondary-destructive", size: "md", iconLeading: uiIcons.Trash01, isDisabled: isSaving, isLoading: destructiveAction.isPending, showTextWhileLoading: true, onPress: destructiveAction.confirmation ? confirmation.open : destructiveAction.onPress, "data-testid": testIdUtils.joinTestId(rootTestId, 'destructive-action'), children: destructiveAction.label })), destructiveAction?.confirmation && (jsxRuntime.jsx(Modals.ConfirmationModal, { isOpen: confirmation.isOpen, onOpenChange: confirmation.onOpenChange, title: destructiveAction.confirmation.title, description: destructiveAction.confirmation.description, confirmLabel: destructiveAction.label, onConfirm: confirmation.confirm, isConfirming: confirmation.isConfirming, isDestructive: true, "data-testid": testIdUtils.joinTestId(rootTestId, 'destructive-confirmation') })), jsxRuntime.jsxs(SectionFooter.SectionFooter.Actions, { className: "flex-none flex-col items-stretch sm:flex-1 sm:flex-row sm:flex-wrap sm:items-center", children: [jsxRuntime.jsx("output", { className: "sr-only", children: isSaved && 'Changes saved' }), jsxRuntime.jsx(Button.Button, { color: "secondary", size: "md", iconLeading: uiIcons.ReverseLeft, isDisabled: !isDirty || isSaving, onPress: discard, "data-testid": testIdUtils.joinTestId(rootTestId, 'discard'), children: "Discard" }), jsxRuntime.jsx(Button.Button, { type: "submit", color: "primary", size: "md", iconLeading: uiIcons.Save01, isDisabled: hasErrors, isLoading: isSaving, showTextWhileLoading: true, isSuccess: isSaved, "data-testid": testIdUtils.joinTestId(rootTestId, 'save'), children: "Save" })] })] }));
|
|
38
38
|
};
|
|
39
39
|
|
|
40
40
|
exports.FormFooter = FormFooter;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../../../src/components/forms/FormFooter/index.tsx"],"sourcesContent":[null],"names":["useFormState","useHasFieldError","useResolvedTestId","useReturnFocus","useDestructiveConfirmation","_jsxs","SectionFooter","_jsx","Button","Trash01","joinTestId","ConfirmationModal","ReverseLeft","Save01"],"mappings":";;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../../../src/components/forms/FormFooter/index.tsx"],"sourcesContent":[null],"names":["useFormState","useHasFieldError","useResolvedTestId","useReturnFocus","useDestructiveConfirmation","_jsxs","SectionFooter","_jsx","Button","Trash01","joinTestId","ConfirmationModal","ReverseLeft","Save01"],"mappings":";;;;;;;;;;;;;AAiEA;;;;;AAKG;AACI,MAAM,UAAU,GAAG,CAAC,EACzB,SAAS,EACT,OAAO,GAAG,KAAK,EACf,iBAAiB,EACjB,OAAO,EAAE,WAAW,EACpB,SAAS,EAAE,aAAa,EACxB,QAAQ,EAAE,YAAY,EACtB,aAAa,EAAE,UAAU,GACT,KAAI;AACpB,IAAA,MAAM,SAAS,GAAGA,0BAAY,EAAE;AAChC,IAAA,MAAM,OAAO,GAAG,WAAW,IAAI,SAAS,CAAC,OAAO;AAChD,IAAA,MAAM,gBAAgB,GAAGC,iCAAgB,EAAE;AAC3C,IAAA,MAAM,SAAS,GAAG,aAAa,IAAI,gBAAgB;AACnD,IAAA,MAAM,QAAQ,GAAG,YAAY,IAAI,SAAS,CAAC,YAAY;AACvD,IAAA,MAAM,UAAU,GAAGC,6BAAiB,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,aAAa,EAAE,CAAC;AAC7G,IAAA,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,GAAGC,6BAAc,CAAiB,uBAAuB,EAAE,MAAM,CAAC;IAClG,MAAM,YAAY,GAAGC,qDAA0B,CAAC,iBAAiB,EAAE,SAAS,CAAC;;IAG7E,MAAM,OAAO,GAAG,MAAK;AACnB,QAAA,WAAW,EAAE;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K,EAAC,WAAW,EACjB,IAAI,EAAC,IAAI,EACT,WAAW,EAAEI,mBAAW,EACxB,UAAU,EAAE,CAAC,OAAO,IAAI,QAAQ,EAChC,OAAO,EAAE,OAAO,EAAA,aAAA,EACHF,sBAAU,CAAC,UAAU,EAAE,SAAS,CAAC,EAAA,QAAA,EAAA,SAAA,EAAA,CAGvC,EAETH,eAACC,aAAM,EAAA,EACL,IAAI,EAAC,QAAQ,EACb,KAAK,EAAC,SAAS,EACf,IAAI,EAAC,IAAI,EACT,WAAW,EAAEK,cAAM,EACnB,UAAU,EAAE,SAAS,EACrB,SAAS,EAAE,QAAQ,EACnB,oBAAoB,EAAA,IAAA,EACpB,SAAS,EAAE,OAAO,EAAA,aAAA,EACLH,sBAAU,CAAC,UAAU,EAAE,MAAM,CAAC,EAAA,QAAA,EAAA,MAAA,EAAA,CAGpC,CAAA,EAAA,CACa,CAAA,EAAA,CACL;AAEzB;;"}
|
|
@@ -13,6 +13,8 @@ export interface FormFooterConfirmedAction {
|
|
|
13
13
|
confirmation: FormFooterConfirmation;
|
|
14
14
|
/** Runs once the user confirms. Return the action's promise and the dialog shows it loading, then closes when it settles. */
|
|
15
15
|
onConfirm: () => unknown;
|
|
16
|
+
/** Whether the action is running where the footer cannot see it, such as a retry from an alert: the button shows it loading and holds a second press. */
|
|
17
|
+
isPending?: boolean;
|
|
16
18
|
onPress?: never;
|
|
17
19
|
}
|
|
18
20
|
/** A destructive action the app confirms itself, for a removal that needs more than a yes or no. */
|
|
@@ -21,6 +23,8 @@ export interface FormFooterOwnAction {
|
|
|
21
23
|
label: string;
|
|
22
24
|
/** Runs on press; open your own dialog here, since the footer does not ask. */
|
|
23
25
|
onPress: () => void;
|
|
26
|
+
/** Whether the action is running where the footer cannot see it, such as a retry from an alert: the button shows it loading and holds a second press. */
|
|
27
|
+
isPending?: boolean;
|
|
24
28
|
confirmation?: never;
|
|
25
29
|
onConfirm?: never;
|
|
26
30
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/forms/FormFooter/index.tsx"],"names":[],"mappings":"AAYA,qEAAqE;AACrE,MAAM,WAAW,sBAAsB;IACrC,6DAA6D;IAC7D,KAAK,EAAE,MAAM,CAAC;IACd,kDAAkD;IAClD,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,2HAA2H;AAC3H,MAAM,WAAW,yBAAyB;IACxC,2GAA2G;IAC3G,KAAK,EAAE,MAAM,CAAC;IACd,+CAA+C;IAC/C,YAAY,EAAE,sBAAsB,CAAC;IACrC,6HAA6H;IAC7H,SAAS,EAAE,MAAM,OAAO,CAAC;IACzB,OAAO,CAAC,EAAE,KAAK,CAAC;CACjB;AAED,oGAAoG;AACpG,MAAM,WAAW,mBAAmB;IAClC,gEAAgE;IAChE,KAAK,EAAE,MAAM,CAAC;IACd,+EAA+E;IAC/E,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,YAAY,CAAC,EAAE,KAAK,CAAC;IACrB,SAAS,CAAC,EAAE,KAAK,CAAC;CACnB;AAED,+EAA+E;AAC/E,MAAM,MAAM,2BAA2B,GAAG,yBAAyB,GAAG,mBAAmB,CAAC;AAE1F,MAAM,WAAW,eAAe;IAC9B,0GAA0G;IAC1G,SAAS,EAAE,MAAM,IAAI,CAAC;IACtB,0HAA0H;IAC1H,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,8JAA8J;IAC9J,iBAAiB,CAAC,EAAE,2BAA2B,CAAC;IAChD,0DAA0D;IAC1D,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,kKAAkK;IAClK,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,2IAA2I;IAC3I,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,0GAA0G;IAC1G,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;;;GAKG;AACH,eAAO,MAAM,UAAU,GAAI,+IAQxB,eAAe,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sour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,eAAO,MAAM,UAAU,GAAI,+IAQxB,eAAe,gCAiFjB,CAAC"}
|
|
@@ -32,7 +32,7 @@ const FormFooter = ({ onDiscard, isSaved = false, destructiveAction, isDirty: is
|
|
|
32
32
|
return (
|
|
33
33
|
// On a phone the buttons stack full width in the order they sit in a row on a wider screen: the destructive action,
|
|
34
34
|
// Discard, then Save last.
|
|
35
|
-
jsxs(SectionFooter.Root, { ref: originRef, "data-testid": rootTestId, className: "flex-col items-stretch gap-3 sm:flex-row sm:flex-wrap sm:items-center sm:gap-5", children: [destructiveAction && (jsx(Button, { color: "secondary-destructive", size: "md", iconLeading: Trash01, isDisabled: isSaving, onPress: destructiveAction.confirmation ? confirmation.open : destructiveAction.onPress, "data-testid": joinTestId(rootTestId, 'destructive-action'), children: destructiveAction.label })), destructiveAction?.confirmation && (jsx(ConfirmationModal, { isOpen: confirmation.isOpen, onOpenChange: confirmation.onOpenChange, title: destructiveAction.confirmation.title, description: destructiveAction.confirmation.description, confirmLabel: destructiveAction.label, onConfirm: confirmation.confirm, isConfirming: confirmation.isConfirming, isDestructive: true, "data-testid": joinTestId(rootTestId, 'destructive-confirmation') })), jsxs(SectionFooter.Actions, { className: "flex-none flex-col items-stretch sm:flex-1 sm:flex-row sm:flex-wrap sm:items-center", children: [jsx("output", { className: "sr-only", children: isSaved && 'Changes saved' }), jsx(Button, { color: "secondary", size: "md", iconLeading: ReverseLeft, isDisabled: !isDirty || isSaving, onPress: discard, "data-testid": joinTestId(rootTestId, 'discard'), children: "Discard" }), jsx(Button, { type: "submit", color: "primary", size: "md", iconLeading: Save01, isDisabled: hasErrors, isLoading: isSaving, showTextWhileLoading: true, isSuccess: isSaved, "data-testid": joinTestId(rootTestId, 'save'), children: "Save" })] })] }));
|
|
35
|
+
jsxs(SectionFooter.Root, { ref: originRef, "data-testid": rootTestId, className: "flex-col items-stretch gap-3 sm:flex-row sm:flex-wrap sm:items-center sm:gap-5", children: [destructiveAction && (jsx(Button, { color: "secondary-destructive", size: "md", iconLeading: Trash01, isDisabled: isSaving, isLoading: destructiveAction.isPending, showTextWhileLoading: true, onPress: destructiveAction.confirmation ? confirmation.open : destructiveAction.onPress, "data-testid": joinTestId(rootTestId, 'destructive-action'), children: destructiveAction.label })), destructiveAction?.confirmation && (jsx(ConfirmationModal, { isOpen: confirmation.isOpen, onOpenChange: confirmation.onOpenChange, title: destructiveAction.confirmation.title, description: destructiveAction.confirmation.description, confirmLabel: destructiveAction.label, onConfirm: confirmation.confirm, isConfirming: confirmation.isConfirming, isDestructive: true, "data-testid": joinTestId(rootTestId, 'destructive-confirmation') })), jsxs(SectionFooter.Actions, { className: "flex-none flex-col items-stretch sm:flex-1 sm:flex-row sm:flex-wrap sm:items-center", children: [jsx("output", { className: "sr-only", children: isSaved && 'Changes saved' }), jsx(Button, { color: "secondary", size: "md", iconLeading: ReverseLeft, isDisabled: !isDirty || isSaving, onPress: discard, "data-testid": joinTestId(rootTestId, 'discard'), children: "Discard" }), jsx(Button, { type: "submit", color: "primary", size: "md", iconLeading: Save01, isDisabled: hasErrors, isLoading: isSaving, showTextWhileLoading: true, isSuccess: isSaved, "data-testid": joinTestId(rootTestId, 'save'), children: "Save" })] })] }));
|
|
36
36
|
};
|
|
37
37
|
|
|
38
38
|
export { FormFooter };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../src/components/forms/FormFooter/index.tsx"],"sourcesContent":[null],"names":["_jsxs","_jsx"],"mappings":";;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../src/components/forms/FormFooter/index.tsx"],"sourcesContent":[null],"names":["_jsxs","_jsx"],"mappings":";;;;;;;;;;;AAiEA;;;;;AAKG;AACI,MAAM,UAAU,GAAG,CAAC,EACzB,SAAS,EACT,OAAO,GAAG,KAAK,EACf,iBAAiB,EACjB,OAAO,EAAE,WAAW,EACpB,SAAS,EAAE,aAAa,EACxB,QAAQ,EAAE,YAAY,EACtB,aAAa,EAAE,UAAU,GACT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