@payloadcms/ui 3.24.0-canary.72057b1 → 3.24.0-canary.80e034e
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/elements/AppHeader/index.d.ts.map +1 -1
- package/dist/elements/AppHeader/index.js +2 -4
- package/dist/elements/AppHeader/index.js.map +1 -1
- package/dist/elements/Autosave/index.d.ts.map +1 -1
- package/dist/elements/Autosave/index.js +143 -108
- package/dist/elements/Autosave/index.js.map +1 -1
- package/dist/elements/Banner/index.d.ts.map +1 -1
- package/dist/elements/Banner/index.js +1 -2
- package/dist/elements/Banner/index.js.map +1 -1
- package/dist/elements/BulkUpload/EditForm/index.d.ts.map +1 -1
- package/dist/elements/BulkUpload/EditForm/index.js +6 -2
- package/dist/elements/BulkUpload/EditForm/index.js.map +1 -1
- package/dist/elements/BulkUpload/EditMany/DrawerContent.d.ts.map +1 -1
- package/dist/elements/BulkUpload/EditMany/DrawerContent.js +22 -20
- package/dist/elements/BulkUpload/EditMany/DrawerContent.js.map +1 -1
- package/dist/elements/Button/index.d.ts.map +1 -1
- package/dist/elements/Button/index.js +12 -12
- package/dist/elements/Button/index.js.map +1 -1
- package/dist/elements/Button/index.scss +21 -5
- package/dist/elements/Button/types.d.ts +5 -0
- package/dist/elements/Button/types.d.ts.map +1 -1
- package/dist/elements/Button/types.js.map +1 -1
- package/dist/elements/Card/index.d.ts +7 -3
- package/dist/elements/Card/index.d.ts.map +1 -1
- package/dist/elements/Card/index.js +0 -2
- package/dist/elements/Card/index.js.map +1 -1
- package/dist/elements/ConfirmationModal/index.d.ts +16 -0
- package/dist/elements/ConfirmationModal/index.d.ts.map +1 -0
- package/dist/elements/ConfirmationModal/index.js +158 -0
- package/dist/elements/ConfirmationModal/index.js.map +1 -0
- package/dist/elements/{GenerateConfirmation → ConfirmationModal}/index.scss +1 -1
- package/dist/elements/CopyLocaleData/index.d.ts.map +1 -1
- package/dist/elements/CopyLocaleData/index.js +220 -99
- package/dist/elements/CopyLocaleData/index.js.map +1 -1
- package/dist/elements/DatePicker/DatePicker.d.ts.map +1 -1
- package/dist/elements/DatePicker/DatePicker.js +2 -0
- package/dist/elements/DatePicker/DatePicker.js.map +1 -1
- package/dist/elements/DatePicker/types.d.ts +1 -0
- package/dist/elements/DatePicker/types.d.ts.map +1 -1
- package/dist/elements/DatePicker/types.js.map +1 -1
- package/dist/elements/DeleteDocument/index.d.ts.map +1 -1
- package/dist/elements/DeleteDocument/index.js +37 -81
- package/dist/elements/DeleteDocument/index.js.map +1 -1
- package/dist/elements/DeleteDocument/index.scss +0 -29
- package/dist/elements/DeleteMany/index.d.ts.map +1 -1
- package/dist/elements/DeleteMany/index.js +17 -44
- package/dist/elements/DeleteMany/index.js.map +1 -1
- package/dist/elements/DeleteMany/index.scss +0 -29
- package/dist/elements/DocumentControls/index.d.ts.map +1 -1
- package/dist/elements/DocumentControls/index.js.map +1 -1
- package/dist/elements/DocumentLocked/index.d.ts.map +1 -1
- package/dist/elements/DocumentLocked/index.js +67 -39
- package/dist/elements/DocumentLocked/index.js.map +1 -1
- package/dist/elements/DocumentTakeOver/index.d.ts.map +1 -1
- package/dist/elements/DocumentTakeOver/index.js +28 -12
- package/dist/elements/DocumentTakeOver/index.js.map +1 -1
- package/dist/elements/DuplicateDocument/index.d.ts +0 -1
- package/dist/elements/DuplicateDocument/index.d.ts.map +1 -1
- package/dist/elements/DuplicateDocument/index.js +31 -56
- package/dist/elements/DuplicateDocument/index.js.map +1 -1
- package/dist/elements/EditMany/DrawerContent.d.ts.map +1 -1
- package/dist/elements/EditMany/DrawerContent.js +3 -2
- package/dist/elements/EditMany/DrawerContent.js.map +1 -1
- package/dist/elements/EditUpload/index.js +1 -1
- package/dist/elements/EditUpload/index.js.map +1 -1
- package/dist/elements/FileDetails/DraggableFileDetails/index.d.ts +1 -0
- package/dist/elements/FileDetails/DraggableFileDetails/index.d.ts.map +1 -1
- package/dist/elements/FileDetails/DraggableFileDetails/index.js +19 -17
- package/dist/elements/FileDetails/DraggableFileDetails/index.js.map +1 -1
- package/dist/elements/FileDetails/StaticFileDetails/index.d.ts +1 -0
- package/dist/elements/FileDetails/StaticFileDetails/index.d.ts.map +1 -1
- package/dist/elements/FileDetails/StaticFileDetails/index.js +2 -1
- package/dist/elements/FileDetails/StaticFileDetails/index.js.map +1 -1
- package/dist/elements/FileDetails/index.d.ts +1 -0
- package/dist/elements/FileDetails/index.d.ts.map +1 -1
- package/dist/elements/FileDetails/index.js.map +1 -1
- package/dist/elements/GenerateConfirmation/index.d.ts +1 -2
- package/dist/elements/GenerateConfirmation/index.d.ts.map +1 -1
- package/dist/elements/GenerateConfirmation/index.js +23 -47
- package/dist/elements/GenerateConfirmation/index.js.map +1 -1
- package/dist/elements/LeaveWithoutSaving/index.d.ts +0 -1
- package/dist/elements/LeaveWithoutSaving/index.d.ts.map +1 -1
- package/dist/elements/LeaveWithoutSaving/index.js +56 -113
- package/dist/elements/LeaveWithoutSaving/index.js.map +1 -1
- package/dist/elements/LeaveWithoutSaving/usePreventLeave.d.ts.map +1 -1
- package/dist/elements/LeaveWithoutSaving/usePreventLeave.js +6 -2
- package/dist/elements/LeaveWithoutSaving/usePreventLeave.js.map +1 -1
- package/dist/elements/Link/formatUrl.d.ts +4 -0
- package/dist/elements/Link/formatUrl.d.ts.map +1 -0
- package/dist/elements/Link/formatUrl.js +87 -0
- package/dist/elements/Link/formatUrl.js.map +1 -0
- package/dist/elements/Link/index.d.ts +6 -0
- package/dist/elements/Link/index.d.ts.map +1 -0
- package/dist/elements/Link/index.js +58 -0
- package/dist/elements/Link/index.js.map +1 -0
- package/dist/elements/ListControls/index.d.ts +1 -0
- package/dist/elements/ListControls/index.d.ts.map +1 -1
- package/dist/elements/ListControls/index.js +14 -0
- package/dist/elements/ListControls/index.js.map +1 -1
- package/dist/elements/ListControls/index.scss +5 -0
- package/dist/elements/Localizer/LocalizerLabel/index.d.ts.map +1 -1
- package/dist/elements/Localizer/LocalizerLabel/index.js +11 -8
- package/dist/elements/Localizer/LocalizerLabel/index.js.map +1 -1
- package/dist/elements/Localizer/index.d.ts.map +1 -1
- package/dist/elements/Localizer/index.js +2 -0
- package/dist/elements/Localizer/index.js.map +1 -1
- package/dist/elements/Logout/index.d.ts +5 -0
- package/dist/elements/Logout/index.d.ts.map +1 -1
- package/dist/elements/Logout/index.js +10 -13
- package/dist/elements/Logout/index.js.map +1 -1
- package/dist/elements/Nav/context.d.ts.map +1 -1
- package/dist/elements/Nav/context.js +3 -1
- package/dist/elements/Nav/context.js.map +1 -1
- package/dist/elements/Pill/index.d.ts.map +1 -1
- package/dist/elements/Pill/index.js +1 -2
- package/dist/elements/Pill/index.js.map +1 -1
- package/dist/elements/Popup/PopupButtonList/index.d.ts.map +1 -1
- package/dist/elements/Popup/PopupButtonList/index.js +1 -2
- package/dist/elements/Popup/PopupButtonList/index.js.map +1 -1
- package/dist/elements/Popup/index.d.ts +1 -0
- package/dist/elements/Popup/index.d.ts.map +1 -1
- package/dist/elements/Popup/index.js +2 -0
- package/dist/elements/Popup/index.js.map +1 -1
- package/dist/elements/PreviewButton/index.d.ts +2 -1
- package/dist/elements/PreviewButton/index.d.ts.map +1 -1
- package/dist/elements/PreviewButton/index.js +2 -2
- package/dist/elements/PreviewButton/index.js.map +1 -1
- package/dist/elements/PreviewSizes/index.js +1 -1
- package/dist/elements/PreviewSizes/index.js.map +1 -1
- package/dist/elements/PublishButton/ScheduleDrawer/buildUpcomingColumns.d.ts +1 -2
- package/dist/elements/PublishButton/ScheduleDrawer/buildUpcomingColumns.d.ts.map +1 -1
- package/dist/elements/PublishButton/ScheduleDrawer/buildUpcomingColumns.js.map +1 -1
- package/dist/elements/PublishButton/ScheduleDrawer/index.d.ts +2 -0
- package/dist/elements/PublishButton/ScheduleDrawer/index.d.ts.map +1 -1
- package/dist/elements/PublishButton/ScheduleDrawer/index.js +6 -2
- package/dist/elements/PublishButton/ScheduleDrawer/index.js.map +1 -1
- package/dist/elements/PublishButton/index.d.ts +2 -3
- package/dist/elements/PublishButton/index.d.ts.map +1 -1
- package/dist/elements/PublishButton/index.js +20 -17
- package/dist/elements/PublishButton/index.js.map +1 -1
- package/dist/elements/PublishMany/index.d.ts +0 -1
- package/dist/elements/PublishMany/index.d.ts.map +1 -1
- package/dist/elements/PublishMany/index.js +19 -45
- package/dist/elements/PublishMany/index.js.map +1 -1
- package/dist/elements/RelationshipTable/index.d.ts +7 -2
- package/dist/elements/RelationshipTable/index.d.ts.map +1 -1
- package/dist/elements/RelationshipTable/index.js +69 -23
- package/dist/elements/RelationshipTable/index.js.map +1 -1
- package/dist/elements/RelationshipTable/index.scss +6 -0
- package/dist/elements/SaveButton/index.d.ts +2 -3
- package/dist/elements/SaveButton/index.d.ts.map +1 -1
- package/dist/elements/SaveButton/index.js +3 -3
- package/dist/elements/SaveButton/index.js.map +1 -1
- package/dist/elements/SaveDraftButton/index.d.ts +2 -1
- package/dist/elements/SaveDraftButton/index.d.ts.map +1 -1
- package/dist/elements/SaveDraftButton/index.js +2 -2
- package/dist/elements/SaveDraftButton/index.js.map +1 -1
- package/dist/elements/Status/index.d.ts.map +1 -1
- package/dist/elements/Status/index.js +173 -154
- package/dist/elements/Status/index.js.map +1 -1
- package/dist/elements/Status/index.scss +0 -41
- package/dist/elements/StayLoggedIn/index.d.ts +0 -1
- package/dist/elements/StayLoggedIn/index.d.ts.map +1 -1
- package/dist/elements/StayLoggedIn/index.js +48 -75
- package/dist/elements/StayLoggedIn/index.js.map +1 -1
- package/dist/elements/StepNav/index.d.ts +5 -0
- package/dist/elements/StepNav/index.d.ts.map +1 -1
- package/dist/elements/StepNav/index.js +18 -25
- package/dist/elements/StepNav/index.js.map +1 -1
- package/dist/elements/Table/DefaultCell/fields/Blocks/index.d.ts.map +1 -1
- package/dist/elements/Table/DefaultCell/fields/Blocks/index.js +12 -4
- package/dist/elements/Table/DefaultCell/fields/Blocks/index.js.map +1 -1
- package/dist/elements/Table/DefaultCell/index.d.ts.map +1 -1
- package/dist/elements/Table/DefaultCell/index.js +1 -2
- package/dist/elements/Table/DefaultCell/index.js.map +1 -1
- package/dist/elements/Table/index.d.ts +1 -9
- package/dist/elements/Table/index.d.ts.map +1 -1
- package/dist/elements/Table/index.js.map +1 -1
- package/dist/elements/TableColumns/buildColumnState.d.ts +1 -2
- package/dist/elements/TableColumns/buildColumnState.d.ts.map +1 -1
- package/dist/elements/TableColumns/buildColumnState.js.map +1 -1
- package/dist/elements/TableColumns/buildPolymorphicColumnState.d.ts +20 -0
- package/dist/elements/TableColumns/buildPolymorphicColumnState.d.ts.map +1 -0
- package/dist/elements/TableColumns/buildPolymorphicColumnState.js +200 -0
- package/dist/elements/TableColumns/buildPolymorphicColumnState.js.map +1 -0
- package/dist/elements/TableColumns/index.d.ts +2 -3
- package/dist/elements/TableColumns/index.d.ts.map +1 -1
- package/dist/elements/TableColumns/index.js +4 -3
- package/dist/elements/TableColumns/index.js.map +1 -1
- package/dist/elements/Thumbnail/index.js +2 -2
- package/dist/elements/Thumbnail/index.js.map +1 -1
- package/dist/elements/UnpublishMany/index.d.ts +1 -2
- package/dist/elements/UnpublishMany/index.d.ts.map +1 -1
- package/dist/elements/UnpublishMany/index.js +14 -42
- package/dist/elements/UnpublishMany/index.js.map +1 -1
- package/dist/elements/Upload/index.d.ts.map +1 -1
- package/dist/elements/Upload/index.js +5 -1
- package/dist/elements/Upload/index.js.map +1 -1
- package/dist/elements/ViewDescription/index.d.ts +2 -5
- package/dist/elements/ViewDescription/index.d.ts.map +1 -1
- package/dist/elements/ViewDescription/index.js +2 -2
- package/dist/elements/ViewDescription/index.js.map +1 -1
- package/dist/exports/client/{CodeEditor-BMYVMDNZ.js → CodeEditor-L6GW2VQ6.js} +2 -2
- package/dist/exports/client/{CodeEditor-BMYVMDNZ.js.map → CodeEditor-L6GW2VQ6.js.map} +0 -1
- package/dist/exports/client/{DatePicker-THCU4KZJ.js → DatePicker-HHQ6TPOW.js} +2 -2
- package/dist/exports/client/{DatePicker-THCU4KZJ.js.map → DatePicker-HHQ6TPOW.js.map} +0 -1
- package/dist/exports/client/chunk-5LKBKI4T.js.map +0 -1
- package/dist/exports/client/{chunk-EG3ZOHFS.js → chunk-IMEQ6NKQ.js} +2 -2
- package/dist/exports/client/{chunk-EG3ZOHFS.js.map → chunk-IMEQ6NKQ.js.map} +3 -4
- package/dist/exports/client/chunk-ZZDNSFEW.js +26 -0
- package/dist/exports/client/{chunk-CQQHQHCB.js.map → chunk-ZZDNSFEW.js.map} +4 -5
- package/dist/exports/client/index.d.ts +49 -4
- package/dist/exports/client/index.d.ts.map +1 -1
- package/dist/exports/client/index.js +23 -23
- package/dist/exports/client/index.js.map +4 -5
- package/dist/fields/Array/index.d.ts.map +1 -1
- package/dist/fields/Array/index.js +1 -2
- package/dist/fields/Array/index.js.map +1 -1
- package/dist/fields/Blocks/BlockRow.d.ts +1 -1
- package/dist/fields/Blocks/BlockRow.d.ts.map +1 -1
- package/dist/fields/Blocks/BlockRow.js.map +1 -1
- package/dist/fields/Blocks/BlocksDrawer/index.d.ts +1 -1
- package/dist/fields/Blocks/BlocksDrawer/index.d.ts.map +1 -1
- package/dist/fields/Blocks/BlocksDrawer/index.js +31 -23
- package/dist/fields/Blocks/BlocksDrawer/index.js.map +1 -1
- package/dist/fields/Blocks/RowActions.d.ts +1 -1
- package/dist/fields/Blocks/RowActions.d.ts.map +1 -1
- package/dist/fields/Blocks/RowActions.js.map +1 -1
- package/dist/fields/Blocks/index.d.ts.map +1 -1
- package/dist/fields/Blocks/index.js +6 -4
- package/dist/fields/Blocks/index.js.map +1 -1
- package/dist/fields/DateTime/index.d.ts.map +1 -1
- package/dist/fields/DateTime/index.js +24 -6
- package/dist/fields/DateTime/index.js.map +1 -1
- package/dist/fields/JSON/index.d.ts.map +1 -1
- package/dist/fields/JSON/index.js +5 -6
- package/dist/fields/JSON/index.js.map +1 -1
- package/dist/fields/Join/index.d.ts.map +1 -1
- package/dist/fields/Join/index.js +28 -7
- package/dist/fields/Join/index.js.map +1 -1
- package/dist/fields/Relationship/optionsReducer.d.ts.map +1 -1
- package/dist/fields/Relationship/optionsReducer.js +1 -0
- package/dist/fields/Relationship/optionsReducer.js.map +1 -1
- package/dist/fields/Select/Input.d.ts.map +1 -1
- package/dist/fields/Select/Input.js +2 -0
- package/dist/fields/Select/Input.js.map +1 -1
- package/dist/fields/Tabs/Tab/index.scss +2 -1
- package/dist/fields/Upload/Input.d.ts +1 -0
- package/dist/fields/Upload/Input.d.ts.map +1 -1
- package/dist/fields/Upload/Input.js.map +1 -1
- package/dist/fields/Upload/RelationshipContent/index.js +1 -1
- package/dist/fields/Upload/RelationshipContent/index.js.map +1 -1
- package/dist/forms/Form/index.d.ts.map +1 -1
- package/dist/forms/Form/index.js +24 -9
- package/dist/forms/Form/index.js.map +1 -1
- package/dist/forms/Form/initContextState.d.ts.map +1 -1
- package/dist/forms/Form/initContextState.js +2 -0
- package/dist/forms/Form/initContextState.js.map +1 -1
- package/dist/forms/Form/types.d.ts +6 -0
- package/dist/forms/Form/types.d.ts.map +1 -1
- package/dist/forms/Form/types.js.map +1 -1
- package/dist/forms/fieldSchemasToFormState/addFieldStatePromise.d.ts.map +1 -1
- package/dist/forms/fieldSchemasToFormState/addFieldStatePromise.js +2 -1
- package/dist/forms/fieldSchemasToFormState/addFieldStatePromise.js.map +1 -1
- package/dist/forms/fieldSchemasToFormState/calculateDefaultValues/promise.d.ts.map +1 -1
- package/dist/forms/fieldSchemasToFormState/calculateDefaultValues/promise.js +1 -1
- package/dist/forms/fieldSchemasToFormState/calculateDefaultValues/promise.js.map +1 -1
- package/dist/forms/fieldSchemasToFormState/renderField.d.ts.map +1 -1
- package/dist/forms/fieldSchemasToFormState/renderField.js +2 -1
- package/dist/forms/fieldSchemasToFormState/renderField.js.map +1 -1
- package/dist/icons/Dots/index.d.ts +7 -0
- package/dist/icons/Dots/index.d.ts.map +1 -0
- package/dist/icons/Dots/index.js +12 -0
- package/dist/icons/Dots/index.js.map +1 -0
- package/dist/icons/Dots/index.scss +27 -0
- package/dist/providers/Auth/index.d.ts.map +1 -1
- package/dist/providers/Auth/index.js +9 -13
- package/dist/providers/Auth/index.js.map +1 -1
- package/dist/providers/Config/index.d.ts +2 -2
- package/dist/providers/Config/index.d.ts.map +1 -1
- package/dist/providers/Config/index.js +17 -2
- package/dist/providers/Config/index.js.map +1 -1
- package/dist/providers/ListQuery/index.d.ts.map +1 -1
- package/dist/providers/ListQuery/index.js +2 -1
- package/dist/providers/ListQuery/index.js.map +1 -1
- package/dist/providers/Root/index.d.ts.map +1 -1
- package/dist/providers/Root/index.js +44 -41
- package/dist/providers/Root/index.js.map +1 -1
- package/dist/providers/RouteTransition/ProgressBar/index.d.ts +17 -0
- package/dist/providers/RouteTransition/ProgressBar/index.d.ts.map +1 -0
- package/dist/providers/RouteTransition/ProgressBar/index.js +104 -0
- package/dist/providers/RouteTransition/ProgressBar/index.js.map +1 -0
- package/dist/providers/RouteTransition/ProgressBar/index.scss +21 -0
- package/dist/providers/RouteTransition/index.d.ts +51 -0
- package/dist/providers/RouteTransition/index.d.ts.map +1 -0
- package/dist/providers/RouteTransition/index.js +133 -0
- package/dist/providers/RouteTransition/index.js.map +1 -0
- package/dist/providers/Selection/index.d.ts.map +1 -1
- package/dist/providers/Selection/index.js +5 -6
- package/dist/providers/Selection/index.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/utilities/buildClientFieldSchemaMap/traverseFields.d.ts.map +1 -1
- package/dist/utilities/buildClientFieldSchemaMap/traverseFields.js +3 -1
- package/dist/utilities/buildClientFieldSchemaMap/traverseFields.js.map +1 -1
- package/dist/utilities/buildFieldSchemaMap/traverseFields.d.ts.map +1 -1
- package/dist/utilities/buildFieldSchemaMap/traverseFields.js +4 -1
- package/dist/utilities/buildFieldSchemaMap/traverseFields.js.map +1 -1
- package/dist/utilities/buildTableState.d.ts +1 -2
- package/dist/utilities/buildTableState.d.ts.map +1 -1
- package/dist/utilities/buildTableState.js +72 -19
- package/dist/utilities/buildTableState.js.map +1 -1
- package/dist/utilities/copyDataFromLocale.d.ts.map +1 -1
- package/dist/utilities/copyDataFromLocale.js +22 -18
- package/dist/utilities/copyDataFromLocale.js.map +1 -1
- package/dist/utilities/getClientConfig.js.map +1 -1
- package/dist/utilities/handleFormStateLocking.d.ts.map +1 -1
- package/dist/utilities/handleFormStateLocking.js +3 -6
- package/dist/utilities/handleFormStateLocking.js.map +1 -1
- package/dist/utilities/renderTable.d.ts +6 -4
- package/dist/utilities/renderTable.d.ts.map +1 -1
- package/dist/utilities/renderTable.js +49 -54
- package/dist/utilities/renderTable.js.map +1 -1
- package/dist/views/Edit/Auth/index.d.ts.map +1 -1
- package/dist/views/Edit/Auth/index.js +56 -55
- package/dist/views/Edit/Auth/index.js.map +1 -1
- package/dist/views/Edit/index.d.ts +2 -2
- package/dist/views/Edit/index.d.ts.map +1 -1
- package/dist/views/Edit/index.js +8 -4
- package/dist/views/Edit/index.js.map +1 -1
- package/dist/views/List/ListHeader/index.d.ts.map +1 -1
- package/dist/views/List/ListHeader/index.js +1 -4
- package/dist/views/List/ListHeader/index.js.map +1 -1
- package/dist/views/List/index.d.ts +2 -25
- package/dist/views/List/index.d.ts.map +1 -1
- package/dist/views/List/index.js +6 -6
- package/dist/views/List/index.js.map +1 -1
- package/dist/views/List/types.d.ts +1 -18
- package/dist/views/List/types.d.ts.map +1 -1
- package/dist/views/List/types.js.map +1 -1
- package/package.json +5 -5
- package/dist/elements/DuplicateDocument/index.scss +0 -42
- package/dist/elements/LeaveWithoutSaving/index.scss +0 -39
- package/dist/elements/PublishMany/index.scss +0 -39
- package/dist/elements/StayLoggedIn/index.scss +0 -40
- package/dist/elements/UnpublishMany/index.scss +0 -39
- package/dist/exports/client/chunk-CQQHQHCB.js +0 -26
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/elements/AppHeader/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/elements/AppHeader/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAsC,MAAM,OAAO,CAAA;AAe1D,OAAO,cAAc,CAAA;AAIrB,KAAK,KAAK,GAAG;IACX,YAAY,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC9B,UAAU,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;CAC7B,CAAA;AACD,wBAAgB,SAAS,CAAC,EAAE,YAAY,EAAE,UAAU,EAAE,EAAE,KAAK,qBAwF5D"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
4
|
-
import LinkWithDefault from 'next/link.js';
|
|
5
4
|
import React, { useEffect, useRef, useState } from 'react';
|
|
6
5
|
import { Account } from '../../graphics/Account/index.js';
|
|
7
6
|
import { useActions } from '../../providers/Actions/index.js';
|
|
@@ -9,6 +8,7 @@ import { useConfig } from '../../providers/Config/index.js';
|
|
|
9
8
|
import { useTranslation } from '../../providers/Translation/index.js';
|
|
10
9
|
import { formatAdminURL } from '../../utilities/formatAdminURL.js';
|
|
11
10
|
import { Hamburger } from '../Hamburger/index.js';
|
|
11
|
+
import { Link } from '../Link/index.js';
|
|
12
12
|
import { Localizer } from '../Localizer/index.js';
|
|
13
13
|
import { LocalizerLabel } from '../Localizer/LocalizerLabel/index.js';
|
|
14
14
|
import { useNav } from '../Nav/context.js';
|
|
@@ -59,7 +59,6 @@ export function AppHeader({
|
|
|
59
59
|
window.removeEventListener('resize', checkIsScrollable);
|
|
60
60
|
};
|
|
61
61
|
}, [Actions]);
|
|
62
|
-
const Link = LinkWithDefault.default;
|
|
63
62
|
const LinkElement = Link || 'a';
|
|
64
63
|
const ActionComponents = Actions ? Object.values(Actions) : [];
|
|
65
64
|
return /*#__PURE__*/_jsxs("header", {
|
|
@@ -80,8 +79,7 @@ export function AppHeader({
|
|
|
80
79
|
className: `${baseClass}__step-nav-wrapper`,
|
|
81
80
|
children: /*#__PURE__*/_jsx(StepNav, {
|
|
82
81
|
className: `${baseClass}__step-nav`,
|
|
83
|
-
CustomIcon: CustomIcon
|
|
84
|
-
Link: Link
|
|
82
|
+
CustomIcon: CustomIcon
|
|
85
83
|
})
|
|
86
84
|
}), /*#__PURE__*/_jsxs("div", {
|
|
87
85
|
className: `${baseClass}__actions-wrapper`,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["
|
|
1
|
+
{"version":3,"file":"index.js","names":["React","useEffect","useRef","useState","Account","useActions","useConfig","useTranslation","formatAdminURL","Hamburger","Link","Localizer","LocalizerLabel","useNav","NavToggler","RenderCustomComponent","StepNav","baseClass","AppHeader","CustomAvatar","CustomIcon","t","Actions","config","admin","routes","account","accountRoute","localization","adminRoute","navOpen","customControlsRef","isScrollable","setIsScrollable","checkIsScrollable","el","current","scrollable","scrollWidth","clientWidth","window","addEventListener","removeEventListener","LinkElement","ActionComponents","Object","values","_jsxs","className","filter","Boolean","join","_jsx","tabIndex","ref","map","Action","i","length","ariaLabel","href","path","prefetch","undefined","CustomComponent","Fallback"],"sources":["../../../src/elements/AppHeader/index.tsx"],"sourcesContent":["'use client'\nimport React, { useEffect, useRef, useState } from 'react'\n\nimport { Account } from '../../graphics/Account/index.js'\nimport { useActions } from '../../providers/Actions/index.js'\nimport { useConfig } from '../../providers/Config/index.js'\nimport { useTranslation } from '../../providers/Translation/index.js'\nimport { formatAdminURL } from '../../utilities/formatAdminURL.js'\nimport { Hamburger } from '../Hamburger/index.js'\nimport { Link } from '../Link/index.js'\nimport { Localizer } from '../Localizer/index.js'\nimport { LocalizerLabel } from '../Localizer/LocalizerLabel/index.js'\nimport { useNav } from '../Nav/context.js'\nimport { NavToggler } from '../Nav/NavToggler/index.js'\nimport { RenderCustomComponent } from '../RenderCustomComponent/index.js'\nimport { StepNav } from '../StepNav/index.js'\nimport './index.scss'\n\nconst baseClass = 'app-header'\n\ntype Props = {\n CustomAvatar?: React.ReactNode\n CustomIcon?: React.ReactNode\n}\nexport function AppHeader({ CustomAvatar, CustomIcon }: Props) {\n const { t } = useTranslation()\n\n const { Actions } = useActions()\n\n const {\n config: {\n admin: {\n routes: { account: accountRoute },\n },\n localization,\n routes: { admin: adminRoute },\n },\n } = useConfig()\n\n const { navOpen } = useNav()\n\n const customControlsRef = useRef<HTMLDivElement>(null)\n const [isScrollable, setIsScrollable] = useState(false)\n\n useEffect(() => {\n const checkIsScrollable = () => {\n const el = customControlsRef.current\n if (el) {\n const scrollable = el.scrollWidth > el.clientWidth\n setIsScrollable(scrollable)\n }\n }\n\n checkIsScrollable()\n window.addEventListener('resize', checkIsScrollable)\n\n return () => {\n window.removeEventListener('resize', checkIsScrollable)\n }\n }, [Actions])\n\n const LinkElement = Link || 'a'\n\n const ActionComponents = Actions ? Object.values(Actions) : []\n\n return (\n <header className={[baseClass, navOpen && `${baseClass}--nav-open`].filter(Boolean).join(' ')}>\n <div className={`${baseClass}__bg`} />\n <div className={`${baseClass}__content`}>\n <div className={`${baseClass}__wrapper`}>\n <NavToggler className={`${baseClass}__mobile-nav-toggler`} tabIndex={-1}>\n <Hamburger />\n </NavToggler>\n <div className={`${baseClass}__controls-wrapper`}>\n <div className={`${baseClass}__step-nav-wrapper`}>\n <StepNav className={`${baseClass}__step-nav`} CustomIcon={CustomIcon} />\n </div>\n <div className={`${baseClass}__actions-wrapper`}>\n <div className={`${baseClass}__actions`} ref={customControlsRef}>\n {ActionComponents.map((Action, i) => (\n <div\n className={\n isScrollable && i === ActionComponents.length - 1\n ? `${baseClass}__last-action`\n : ''\n }\n key={i}\n >\n {Action}\n </div>\n ))}\n </div>\n {isScrollable && <div className={`${baseClass}__gradient-placeholder`} />}\n </div>\n {localization && (\n <LocalizerLabel ariaLabel=\"invisible\" className={`${baseClass}__localizer-spacing`} />\n )}\n <LinkElement\n aria-label={t('authentication:account')}\n className={`${baseClass}__account`}\n href={formatAdminURL({ adminRoute, path: accountRoute })}\n prefetch={Link ? false : undefined}\n tabIndex={0}\n >\n <RenderCustomComponent CustomComponent={CustomAvatar} Fallback={<Account />} />\n </LinkElement>\n </div>\n </div>\n </div>\n <Localizer className={`${baseClass}__localizer`} />\n </header>\n )\n}\n"],"mappings":"AAAA;;;AACA,OAAOA,KAAA,IAASC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ;AAEnD,SAASC,OAAO,QAAQ;AACxB,SAASC,UAAU,QAAQ;AAC3B,SAASC,SAAS,QAAQ;AAC1B,SAASC,cAAc,QAAQ;AAC/B,SAASC,cAAc,QAAQ;AAC/B,SAASC,SAAS,QAAQ;AAC1B,SAASC,IAAI,QAAQ;AACrB,SAASC,SAAS,QAAQ;AAC1B,SAASC,cAAc,QAAQ;AAC/B,SAASC,MAAM,QAAQ;AACvB,SAASC,UAAU,QAAQ;AAC3B,SAASC,qBAAqB,QAAQ;AACtC,SAASC,OAAO,QAAQ;AACxB,OAAO;AAEP,MAAMC,SAAA,GAAY;AAMlB,OAAO,SAASC,UAAU;EAAEC,YAAY;EAAEC;AAAU,CAAS;EAC3D,MAAM;IAAEC;EAAC,CAAE,GAAGd,cAAA;EAEd,MAAM;IAAEe;EAAO,CAAE,GAAGjB,UAAA;EAEpB,MAAM;IACJkB,MAAA,EAAQ;MACNC,KAAA,EAAO;QACLC,MAAA,EAAQ;UAAEC,OAAA,EAASC;QAAY;MAAE,CAClC;MACDC,YAAY;MACZH,MAAA,EAAQ;QAAED,KAAA,EAAOK;MAAU;IAAE;EAC9B,CACF,GAAGvB,SAAA;EAEJ,MAAM;IAAEwB;EAAO,CAAE,GAAGjB,MAAA;EAEpB,MAAMkB,iBAAA,GAAoB7B,MAAA,CAAuB;EACjD,MAAM,CAAC8B,YAAA,EAAcC,eAAA,CAAgB,GAAG9B,QAAA,CAAS;EAEjDF,SAAA,CAAU;IACR,MAAMiC,iBAAA,GAAoBA,CAAA;MACxB,MAAMC,EAAA,GAAKJ,iBAAA,CAAkBK,OAAO;MACpC,IAAID,EAAA,EAA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AoB;cAAEqC,GAAA,EAAKvB,iBAAA;wBAC3Ca,gBAAA,CAAiBW,GAAG,CAAC,CAACC,MAAA,EAAQC,CAAA,kBAC7BL,IAAA,CAAC;gBACCJ,SAAA,EACEhB,YAAA,IAAgByB,CAAA,KAAMb,gBAAA,CAAiBc,MAAM,GAAG,IAC5C,GAAGzC,SAAA,eAAwB,GAC3B;0BAILuC;iBAFIC,CAAA;gBAMVzB,YAAA,iBAAgBoB,IAAA,CAAC;cAAIJ,SAAA,EAAW,GAAG/B,SAAA;;cAErCW,YAAA,iBACCwB,IAAA,CAACxC,cAAA;YAAe+C,SAAA,EAAU;YAAYX,SAAA,EAAW,GAAG/B,SAAA;2BAEtDmC,IAAA,CAACT,WAAA;YACC,cAAYtB,CAAA,CAAE;YACd2B,SAAA,EAAW,GAAG/B,SAAA,WAAoB;YAClC2C,IAAA,EAAMpD,cAAA,CAAe;cAAEqB,UAAA;cAAYgC,IAAA,EAAMlC;YAAa;YACtDmC,QAAA,EAAUpD,IAAA,GAAO,QAAQqD,SAAA;YACzBV,QAAA,EAAU;sBAEV,aAAAD,IAAA,CAACrC,qBAAA;cAAsBiD,eAAA,EAAiB7C,YAAA;cAAc8C,QAAA,eAAUb,IAAA,CAAChD,OAAA;;;;;qBAKzEgD,IAAA,CAACzC,SAAA;MAAUqC,SAAA,EAAW,GAAG/B,SAAA;;;AAG/B","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/elements/Autosave/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/elements/Autosave/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAIzE,OAAO,KAAwD,MAAM,OAAO,CAAA;AAe5E,OAAO,cAAc,CAAA;AAUrB,MAAM,MAAM,KAAK,GAAG;IAClB,UAAU,CAAC,EAAE,sBAAsB,CAAA;IACnC,MAAM,CAAC,EAAE,kBAAkB,CAAA;IAC3B,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACpB,qBAAqB,EAAE,MAAM,CAAA;CAC9B,CAAA;AAED,eAAO,MAAM,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAqTpC,CAAA"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
4
|
+
import { dequal } from 'dequal/lite';
|
|
5
|
+
import { reduceFieldsToValues, versionDefaults } from 'payload/shared';
|
|
6
|
+
import React, { useDeferredValue, useEffect, useRef, useState } from 'react';
|
|
6
7
|
import { toast } from 'sonner';
|
|
7
8
|
import { useAllFormFields, useForm, useFormModified, useFormSubmitted } from '../../forms/Form/context.js';
|
|
8
9
|
import { useDebounce } from '../../hooks/useDebounce.js';
|
|
@@ -11,10 +12,11 @@ import { useConfig } from '../../providers/Config/index.js';
|
|
|
11
12
|
import { useDocumentEvents } from '../../providers/DocumentEvents/index.js';
|
|
12
13
|
import { useDocumentInfo } from '../../providers/DocumentInfo/index.js';
|
|
13
14
|
import { useLocale } from '../../providers/Locale/index.js';
|
|
14
|
-
import { useTranslation } from '../../providers/Translation/index.js';
|
|
15
15
|
import './index.scss';
|
|
16
|
+
import { useTranslation } from '../../providers/Translation/index.js';
|
|
16
17
|
import { formatTimeToNow } from '../../utilities/formatDate.js';
|
|
17
18
|
import { reduceFieldsToValuesWithValidation } from '../../utilities/reduceFieldsToValuesWithValidation.js';
|
|
19
|
+
import { LeaveWithoutSaving } from '../LeaveWithoutSaving/index.js';
|
|
18
20
|
const baseClass = 'autosave';
|
|
19
21
|
// The minimum time the saving state should be shown
|
|
20
22
|
const minimumAnimationTime = 1000;
|
|
@@ -48,12 +50,13 @@ export const Autosave = ({
|
|
|
48
50
|
} = useDocumentEvents();
|
|
49
51
|
const {
|
|
50
52
|
dispatchFields,
|
|
53
|
+
isValid,
|
|
54
|
+
setIsValid,
|
|
51
55
|
setSubmitted
|
|
52
56
|
} = useForm();
|
|
53
|
-
const submitted = useFormSubmitted();
|
|
54
|
-
const versionsConfig = docConfig?.versions;
|
|
55
57
|
const [fields] = useAllFormFields();
|
|
56
58
|
const modified = useFormModified();
|
|
59
|
+
const submitted = useFormSubmitted();
|
|
57
60
|
const {
|
|
58
61
|
code: locale
|
|
59
62
|
} = useLocale();
|
|
@@ -61,17 +64,23 @@ export const Autosave = ({
|
|
|
61
64
|
i18n,
|
|
62
65
|
t
|
|
63
66
|
} = useTranslation();
|
|
67
|
+
const versionsConfig = docConfig?.versions;
|
|
64
68
|
let interval = versionDefaults.autosaveInterval;
|
|
65
69
|
if (versionsConfig.drafts && versionsConfig.drafts.autosave) {
|
|
66
70
|
interval = versionsConfig.drafts.autosave.interval;
|
|
67
71
|
}
|
|
68
|
-
const
|
|
72
|
+
const validateOnDraft = Boolean(docConfig?.versions?.drafts && docConfig?.versions?.drafts.validate);
|
|
73
|
+
const [_saving, setSaving] = useState(false);
|
|
74
|
+
const saving = useDeferredValue(_saving);
|
|
69
75
|
const debouncedFields = useDebounce(fields, interval);
|
|
70
76
|
const fieldRef = useRef(fields);
|
|
71
77
|
const modifiedRef = useRef(modified);
|
|
72
78
|
const localeRef = useRef(locale);
|
|
73
|
-
|
|
74
|
-
|
|
79
|
+
/**
|
|
80
|
+
* Track the validation internally so Autosave can determine when to run queue processing again
|
|
81
|
+
* Helps us prevent infinite loops when the queue is processing and the form is invalid
|
|
82
|
+
*/
|
|
83
|
+
const isValidRef = useRef(isValid);
|
|
75
84
|
// Store fields in ref so the autosave func
|
|
76
85
|
// can always retrieve the most to date copies
|
|
77
86
|
// after the timeout has executed
|
|
@@ -87,6 +96,13 @@ export const Autosave = ({
|
|
|
87
96
|
if (isProcessingRef.current || queueRef.current.length === 0) {
|
|
88
97
|
return;
|
|
89
98
|
}
|
|
99
|
+
if (!isValidRef.current) {
|
|
100
|
+
// Clear queue so we don't end up in an infinite loop
|
|
101
|
+
queueRef.current = [];
|
|
102
|
+
// Reset internal validation state so queue processing can run again
|
|
103
|
+
isValidRef.current = true;
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
90
106
|
isProcessingRef.current = true;
|
|
91
107
|
const latestAction = queueRef.current[queueRef.current.length - 1];
|
|
92
108
|
queueRef.current = [];
|
|
@@ -99,12 +115,22 @@ export const Autosave = ({
|
|
|
99
115
|
}
|
|
100
116
|
}
|
|
101
117
|
}, []);
|
|
118
|
+
const autosaveTimeoutRef = useRef(null);
|
|
102
119
|
const handleAutosave = useEffectEvent(() => {
|
|
103
|
-
|
|
104
|
-
let autosaveTimeout = undefined;
|
|
120
|
+
autosaveTimeoutRef.current = undefined;
|
|
105
121
|
// We need to log the time in order to figure out if we need to trigger the state off later
|
|
106
122
|
let startTimestamp = undefined;
|
|
107
123
|
let endTimestamp = undefined;
|
|
124
|
+
const hideIndicator = () => {
|
|
125
|
+
// If request was faster than minimum animation time, animate the difference
|
|
126
|
+
if (endTimestamp - startTimestamp < minimumAnimationTime) {
|
|
127
|
+
autosaveTimeoutRef.current = setTimeout(() => {
|
|
128
|
+
setSaving(false);
|
|
129
|
+
}, minimumAnimationTime - (endTimestamp - startTimestamp));
|
|
130
|
+
} else {
|
|
131
|
+
stopAutoSaveIndicator();
|
|
132
|
+
}
|
|
133
|
+
};
|
|
108
134
|
const autosave = async () => {
|
|
109
135
|
if (modified) {
|
|
110
136
|
startTimestamp = new Date().getTime();
|
|
@@ -127,88 +153,86 @@ export const Autosave = ({
|
|
|
127
153
|
const {
|
|
128
154
|
data,
|
|
129
155
|
valid
|
|
130
|
-
} =
|
|
131
|
-
...reduceFieldsToValuesWithValidation(fieldRef.current, true)
|
|
132
|
-
};
|
|
156
|
+
} = reduceFieldsToValuesWithValidation(fieldRef.current, true);
|
|
133
157
|
data._status = 'draft';
|
|
134
158
|
const skipSubmission = submitted && !valid && versionsConfig?.drafts && versionsConfig?.drafts?.validate;
|
|
135
|
-
if (!skipSubmission) {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
'
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
159
|
+
if (!skipSubmission && isValidRef.current) {
|
|
160
|
+
let res;
|
|
161
|
+
try {
|
|
162
|
+
res = await fetch(url, {
|
|
163
|
+
body: JSON.stringify(data),
|
|
164
|
+
credentials: 'include',
|
|
165
|
+
headers: {
|
|
166
|
+
'Accept-Language': i18n.language,
|
|
167
|
+
'Content-Type': 'application/json'
|
|
168
|
+
},
|
|
169
|
+
method
|
|
170
|
+
});
|
|
171
|
+
} catch (error) {
|
|
172
|
+
// Swallow Error
|
|
173
|
+
}
|
|
174
|
+
const newDate = new Date();
|
|
175
|
+
// We need to log the time in order to figure out if we need to trigger the state off later
|
|
176
|
+
endTimestamp = newDate.getTime();
|
|
177
|
+
if (res.status === 200) {
|
|
178
|
+
setLastUpdateTime(newDate.getTime());
|
|
179
|
+
reportUpdate({
|
|
180
|
+
id,
|
|
181
|
+
entitySlug,
|
|
182
|
+
updatedAt: newDate.toISOString()
|
|
183
|
+
});
|
|
184
|
+
if (!mostRecentVersionIsAutosaved) {
|
|
185
|
+
incrementVersionCount();
|
|
186
|
+
setMostRecentVersionIsAutosaved(true);
|
|
187
|
+
setUnpublishedVersionCount(prev => prev + 1);
|
|
161
188
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
const document = json?.doc || json?.result;
|
|
197
|
-
// Manually update the data since this function doesn't fire the `submit` function from useForm
|
|
198
|
-
if (document) {
|
|
199
|
-
updateSavedDocumentData(document);
|
|
200
|
-
}
|
|
189
|
+
}
|
|
190
|
+
const json = await res.json();
|
|
191
|
+
if (versionsConfig?.drafts && versionsConfig?.drafts?.validate && json?.errors) {
|
|
192
|
+
if (Array.isArray(json.errors)) {
|
|
193
|
+
const [fieldErrors, nonFieldErrors] = json.errors.reduce(([fieldErrs, nonFieldErrs], err) => {
|
|
194
|
+
const newFieldErrs = [];
|
|
195
|
+
const newNonFieldErrs = [];
|
|
196
|
+
if (err?.message) {
|
|
197
|
+
newNonFieldErrs.push(err);
|
|
198
|
+
}
|
|
199
|
+
if (Array.isArray(err?.data)) {
|
|
200
|
+
err.data.forEach(dataError => {
|
|
201
|
+
if (dataError?.field) {
|
|
202
|
+
newFieldErrs.push(dataError);
|
|
203
|
+
} else {
|
|
204
|
+
newNonFieldErrs.push(dataError);
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
return [[...fieldErrs, ...newFieldErrs], [...nonFieldErrs, ...newNonFieldErrs]];
|
|
209
|
+
}, [[], []]);
|
|
210
|
+
dispatchFields({
|
|
211
|
+
type: 'ADD_SERVER_ERRORS',
|
|
212
|
+
errors: fieldErrors
|
|
213
|
+
});
|
|
214
|
+
nonFieldErrors.forEach(err_0 => {
|
|
215
|
+
toast.error(err_0.message || i18n.t('error:unknown'));
|
|
216
|
+
});
|
|
217
|
+
// Set valid to false internally so the queue doesn't process
|
|
218
|
+
isValidRef.current = false;
|
|
219
|
+
setIsValid(false);
|
|
220
|
+
setSubmitted(true);
|
|
221
|
+
hideIndicator();
|
|
222
|
+
return;
|
|
201
223
|
}
|
|
202
|
-
}
|
|
203
|
-
// If
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
224
|
+
} else {
|
|
225
|
+
// If it's not an error then we can update the document data inside the context
|
|
226
|
+
const document = json?.doc || json?.result;
|
|
227
|
+
// Manually update the data since this function doesn't fire the `submit` function from useForm
|
|
228
|
+
if (document) {
|
|
229
|
+
setIsValid(true);
|
|
230
|
+
// Reset internal state allowing the queue to process
|
|
231
|
+
isValidRef.current = true;
|
|
232
|
+
updateSavedDocumentData(document);
|
|
210
233
|
}
|
|
211
|
-
}
|
|
234
|
+
}
|
|
235
|
+
hideIndicator();
|
|
212
236
|
}
|
|
213
237
|
}
|
|
214
238
|
}
|
|
@@ -216,34 +240,45 @@ export const Autosave = ({
|
|
|
216
240
|
};
|
|
217
241
|
queueRef.current.push(autosave);
|
|
218
242
|
void processQueue();
|
|
219
|
-
return {
|
|
220
|
-
abortController,
|
|
221
|
-
autosaveTimeout
|
|
222
|
-
};
|
|
223
243
|
});
|
|
244
|
+
const didMount = useRef(false);
|
|
245
|
+
const previousDebouncedFieldValues = useRef(reduceFieldsToValues(debouncedFields));
|
|
224
246
|
// When debounced fields change, autosave
|
|
225
247
|
useEffect(() => {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
248
|
+
/**
|
|
249
|
+
* Ensure autosave doesn't run on mount
|
|
250
|
+
*/
|
|
251
|
+
if (!didMount.current) {
|
|
252
|
+
didMount.current = true;
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Ensure autosave only runs if the form data changes, not every time the entire form state changes
|
|
257
|
+
*/
|
|
258
|
+
const debouncedFieldValues = reduceFieldsToValues(debouncedFields);
|
|
259
|
+
if (dequal(debouncedFieldValues, previousDebouncedFieldValues)) {
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
previousDebouncedFieldValues.current = debouncedFieldValues;
|
|
263
|
+
handleAutosave();
|
|
264
|
+
}, [debouncedFields]);
|
|
265
|
+
/**
|
|
266
|
+
* If component unmounts, clear the autosave timeout
|
|
267
|
+
*/
|
|
268
|
+
useEffect(() => {
|
|
230
269
|
return () => {
|
|
231
|
-
|
|
232
|
-
clearTimeout(autosaveTimeout_0);
|
|
233
|
-
}
|
|
234
|
-
if (abortController_0.signal) {
|
|
235
|
-
try {
|
|
236
|
-
abortController_0.abort('Autosave closed early.');
|
|
237
|
-
} catch (error) {
|
|
238
|
-
// swallow error
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
setSaving(false);
|
|
270
|
+
stopAutoSaveIndicator();
|
|
242
271
|
};
|
|
243
|
-
}, [
|
|
272
|
+
}, []);
|
|
273
|
+
const stopAutoSaveIndicator = useEffectEvent(() => {
|
|
274
|
+
if (autosaveTimeoutRef.current) {
|
|
275
|
+
clearTimeout(autosaveTimeoutRef.current);
|
|
276
|
+
}
|
|
277
|
+
setSaving(false);
|
|
278
|
+
});
|
|
244
279
|
return /*#__PURE__*/_jsxs("div", {
|
|
245
280
|
className: baseClass,
|
|
246
|
-
children: [saving && t('general:saving'), !saving && Boolean(lastUpdateTime) && /*#__PURE__*/_jsx(React.Fragment, {
|
|
281
|
+
children: [validateOnDraft && !isValid && /*#__PURE__*/_jsx(LeaveWithoutSaving, {}), saving && t('general:saving'), !saving && Boolean(lastUpdateTime) && /*#__PURE__*/_jsx(React.Fragment, {
|
|
247
282
|
children: t('version:lastSavedAgo', {
|
|
248
283
|
distance: formatTimeToNow({
|
|
249
284
|
date: lastUpdateTime,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["versionDefaults","React","useEffect","useRef","useState","toast","useAllFormFields","useForm","useFormModified","useFormSubmitted","useDebounce","useEffectEvent","useConfig","useDocumentEvents","useDocumentInfo","useLocale","useTranslation","formatTimeToNow","reduceFieldsToValuesWithValidation","baseClass","minimumAnimationTime","Autosave","id","collection","global","globalDoc","config","routes","api","serverURL","docConfig","incrementVersionCount","lastUpdateTime","mostRecentVersionIsAutosaved","setLastUpdateTime","setMostRecentVersionIsAutosaved","setUnpublishedVersionCount","updateSavedDocumentData","queueRef","isProcessingRef","reportUpdate","dispatchFields","setSubmitted","submitted","versionsConfig","versions","fields","modified","code","locale","i18n","t","interval","autosaveInterval","drafts","autosave","saving","setSaving","debouncedFields","fieldRef","modifiedRef","localeRef","debouncedRef","current","processQueue","useCallback","length","latestAction","handleAutosave","abortController","AbortController","autosaveTimeout","undefined","startTimestamp","endTimestamp","Date","getTime","url","method","entitySlug","slug","data","valid","_status","skipSubmission","validate","fetch","body","JSON","stringify","credentials","headers","language","signal","then","res","newDate","status","updatedAt","toISOString","prev","json","errors","Array","isArray","fieldErrors","nonFieldErrors","reduce","fieldErrs","nonFieldErrs","err","newFieldErrs","newNonFieldErrs","message","push","forEach","dataError","field","type","error","document","doc","result","setTimeout","clearTimeout","abort","_jsxs","className","Boolean","_jsx","Fragment","distance","date"],"sources":["../../../src/elements/Autosave/index.tsx"],"sourcesContent":["'use client'\n// TODO: abstract the `next/navigation` dependency out from this component\nimport type { ClientCollectionConfig, ClientGlobalConfig } from 'payload'\n\nimport { versionDefaults } from 'payload/shared'\nimport React, { useEffect, useRef, useState } from 'react'\nimport { toast } from 'sonner'\n\nimport {\n useAllFormFields,\n useForm,\n useFormModified,\n useFormSubmitted,\n} from '../../forms/Form/context.js'\nimport { useDebounce } from '../../hooks/useDebounce.js'\nimport { useEffectEvent } from '../../hooks/useEffectEvent.js'\nimport { useConfig } from '../../providers/Config/index.js'\nimport { useDocumentEvents } from '../../providers/DocumentEvents/index.js'\nimport { useDocumentInfo } from '../../providers/DocumentInfo/index.js'\nimport { useLocale } from '../../providers/Locale/index.js'\nimport { useTranslation } from '../../providers/Translation/index.js'\nimport './index.scss'\nimport { formatTimeToNow } from '../../utilities/formatDate.js'\nimport { reduceFieldsToValuesWithValidation } from '../../utilities/reduceFieldsToValuesWithValidation.js'\n\nconst baseClass = 'autosave'\n// The minimum time the saving state should be shown\nconst minimumAnimationTime = 1000\n\nexport type Props = {\n collection?: ClientCollectionConfig\n global?: ClientGlobalConfig\n id?: number | string\n publishedDocUpdatedAt: string\n}\n\nexport const Autosave: React.FC<Props> = ({ id, collection, global: globalDoc }) => {\n const {\n config: {\n routes: { api },\n serverURL,\n },\n } = useConfig()\n const {\n docConfig,\n incrementVersionCount,\n lastUpdateTime,\n mostRecentVersionIsAutosaved,\n setLastUpdateTime,\n setMostRecentVersionIsAutosaved,\n setUnpublishedVersionCount,\n updateSavedDocumentData,\n } = useDocumentInfo()\n const queueRef = useRef([])\n const isProcessingRef = useRef(false)\n\n const { reportUpdate } = useDocumentEvents()\n const { dispatchFields, setSubmitted } = useForm()\n const submitted = useFormSubmitted()\n const versionsConfig = docConfig?.versions\n\n const [fields] = useAllFormFields()\n const modified = useFormModified()\n const { code: locale } = useLocale()\n const { i18n, t } = useTranslation()\n\n let interval = versionDefaults.autosaveInterval\n if (versionsConfig.drafts && versionsConfig.drafts.autosave) {\n interval = versionsConfig.drafts.autosave.interval\n }\n\n const [saving, setSaving] = useState(false)\n const debouncedFields = useDebounce(fields, interval)\n const fieldRef = useRef(fields)\n const modifiedRef = useRef(modified)\n const localeRef = useRef(locale)\n const debouncedRef = useRef(debouncedFields)\n\n debouncedRef.current = debouncedFields\n\n // Store fields in ref so the autosave func\n // can always retrieve the most to date copies\n // after the timeout has executed\n fieldRef.current = fields\n\n // Store modified in ref so the autosave func\n // can bail out if modified becomes false while\n // timing out during autosave\n modifiedRef.current = modified\n\n // Store locale in ref so the autosave func\n // can always retrieve the most to date locale\n localeRef.current = locale\n\n const processQueue = React.useCallback(async () => {\n if (isProcessingRef.current || queueRef.current.length === 0) {\n return\n }\n\n isProcessingRef.current = true\n const latestAction = queueRef.current[queueRef.current.length - 1]\n queueRef.current = []\n\n try {\n await latestAction()\n } finally {\n isProcessingRef.current = false\n if (queueRef.current.length > 0) {\n await processQueue()\n }\n }\n }, [])\n\n const handleAutosave = useEffectEvent(() => {\n const abortController = new AbortController()\n let autosaveTimeout = undefined\n // We need to log the time in order to figure out if we need to trigger the state off later\n let startTimestamp = undefined\n let endTimestamp = undefined\n\n const autosave = async () => {\n if (modified) {\n startTimestamp = new Date().getTime()\n\n setSaving(true)\n\n let url: string\n let method: string\n let entitySlug: string\n\n if (collection && id) {\n entitySlug = collection.slug\n url = `${serverURL}${api}/${entitySlug}/${id}?draft=true&autosave=true&locale=${localeRef.current}`\n method = 'PATCH'\n }\n\n if (globalDoc) {\n entitySlug = globalDoc.slug\n url = `${serverURL}${api}/globals/${entitySlug}?draft=true&autosave=true&locale=${localeRef.current}`\n method = 'POST'\n }\n\n if (url) {\n if (modifiedRef.current) {\n const { data, valid } = {\n ...reduceFieldsToValuesWithValidation(fieldRef.current, true),\n }\n data._status = 'draft'\n const skipSubmission =\n submitted && !valid && versionsConfig?.drafts && versionsConfig?.drafts?.validate\n\n if (!skipSubmission) {\n await fetch(url, {\n body: JSON.stringify(data),\n credentials: 'include',\n headers: {\n 'Accept-Language': i18n.language,\n 'Content-Type': 'application/json',\n },\n method,\n signal: abortController.signal,\n })\n .then((res) => {\n const newDate = new Date()\n // We need to log the time in order to figure out if we need to trigger the state off later\n endTimestamp = newDate.getTime()\n\n if (res.status === 200) {\n setLastUpdateTime(newDate.getTime())\n\n reportUpdate({\n id,\n entitySlug,\n updatedAt: newDate.toISOString(),\n })\n\n if (!mostRecentVersionIsAutosaved) {\n incrementVersionCount()\n setMostRecentVersionIsAutosaved(true)\n setUnpublishedVersionCount((prev) => prev + 1)\n }\n }\n\n return res.json()\n })\n .then((json) => {\n if (versionsConfig?.drafts && versionsConfig?.drafts?.validate && json?.errors) {\n if (Array.isArray(json.errors)) {\n const [fieldErrors, nonFieldErrors] = json.errors.reduce(\n ([fieldErrs, nonFieldErrs], err) => {\n const newFieldErrs = []\n const newNonFieldErrs = []\n\n if (err?.message) {\n newNonFieldErrs.push(err)\n }\n\n if (Array.isArray(err?.data)) {\n err.data.forEach((dataError) => {\n if (dataError?.field) {\n newFieldErrs.push(dataError)\n } else {\n newNonFieldErrs.push(dataError)\n }\n })\n }\n\n return [\n [...fieldErrs, ...newFieldErrs],\n [...nonFieldErrs, ...newNonFieldErrs],\n ]\n },\n [[], []],\n )\n\n dispatchFields({\n type: 'ADD_SERVER_ERRORS',\n errors: fieldErrors,\n })\n\n nonFieldErrors.forEach((err) => {\n toast.error(err.message || i18n.t('error:unknown'))\n })\n\n setSubmitted(true)\n setSaving(false)\n return\n }\n } else {\n // If it's not an error then we can update the document data inside the context\n const document = json?.doc || json?.result\n\n // Manually update the data since this function doesn't fire the `submit` function from useForm\n if (document) {\n updateSavedDocumentData(document)\n }\n }\n })\n .then(() => {\n // If request was faster than minimum animation time, animate the difference\n if (endTimestamp - startTimestamp < minimumAnimationTime) {\n autosaveTimeout = setTimeout(\n () => {\n setSaving(false)\n },\n minimumAnimationTime - (endTimestamp - startTimestamp),\n )\n } else {\n setSaving(false)\n }\n })\n }\n }\n }\n }\n }\n\n queueRef.current.push(autosave)\n void processQueue()\n\n return { abortController, autosaveTimeout }\n })\n\n // When debounced fields change, autosave\n useEffect(() => {\n const { abortController, autosaveTimeout } = handleAutosave()\n\n return () => {\n if (autosaveTimeout) {\n clearTimeout(autosaveTimeout)\n }\n if (abortController.signal) {\n try {\n abortController.abort('Autosave closed early.')\n } catch (error) {\n // swallow error\n }\n }\n setSaving(false)\n }\n }, [debouncedFields])\n\n return (\n <div className={baseClass}>\n {saving && t('general:saving')}\n {!saving && Boolean(lastUpdateTime) && (\n <React.Fragment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CAAU;gBACZ;cACF;YACJ;UACF;QACF;MACF;IACF;IAEAnB,QAAA,CAASyB,OAAO,CAACmD,IAAI,CAAC3D,QAAA;IACtB,KAAKS,YAAA;IAEL,OAAO;MAAEK,eAAA;MAAiBE;IAAgB;EAC5C;EAEA;EACArE,SAAA,CAAU;IACR,MAAM;MAAEmE,eAAe,EAAfA,iBAAe;MAAEE,eAAe,EAAfA;IAAe,CAAE,GAAGH,cAAA;IAE7C,OAAO;MACL,IAAIG,iBAAA,EAAiB;QACnBqD,YAAA,CAAarD,iBAAA;MACf;MACA,IAAIF,iBAAA,CAAgBwB,MAAM,EAAE;QAC1B,IAAI;UACFxB,iBAAA,CAAgBwD,KAAK,CAAC;QACxB,EAAE,OAAON,KAAA,EAAO;UACd;QAAA;MAEJ;MACA9D,SAAA,CAAU;IACZ;EACF,GAAG,CAACC,eAAA,CAAgB;EAEpB,oBACEoE,KAAA,CAAC;IAAIC,SAAA,EAAW5G,SAAA;eACbqC,MAAA,IAAUL,CAAA,CAAE,mBACZ,CAACK,MAAA,IAAUwE,OAAA,CAAQhG,cAAA,kBAClBiG,IAAA,CAAChI,KAAA,CAAMiI,QAAQ;gBACZ/E,CAAA,CAAE,wBAAwB;QACzBgF,QAAA,EAAUlH,eAAA,CAAgB;UAAEmH,IAAA,EAAMpG,cAAA;UAAgBkB;QAAK;MACzD;;;AAKV","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["dequal","reduceFieldsToValues","versionDefaults","React","useDeferredValue","useEffect","useRef","useState","toast","useAllFormFields","useForm","useFormModified","useFormSubmitted","useDebounce","useEffectEvent","useConfig","useDocumentEvents","useDocumentInfo","useLocale","useTranslation","formatTimeToNow","reduceFieldsToValuesWithValidation","LeaveWithoutSaving","baseClass","minimumAnimationTime","Autosave","id","collection","global","globalDoc","config","routes","api","serverURL","docConfig","incrementVersionCount","lastUpdateTime","mostRecentVersionIsAutosaved","setLastUpdateTime","setMostRecentVersionIsAutosaved","setUnpublishedVersionCount","updateSavedDocumentData","queueRef","isProcessingRef","reportUpdate","dispatchFields","isValid","setIsValid","setSubmitted","fields","modified","submitted","code","locale","i18n","t","versionsConfig","versions","interval","autosaveInterval","drafts","autosave","validateOnDraft","Boolean","validate","_saving","setSaving","saving","debouncedFields","fieldRef","modifiedRef","localeRef","isValidRef","current","processQueue","useCallback","length","latestAction","autosaveTimeoutRef","handleAutosave","undefined","startTimestamp","endTimestamp","hideIndicator","setTimeout","stopAutoSaveIndicator","Date","getTime","url","method","entitySlug","slug","data","valid","_status","skipSubmission","res","fetch","body","JSON","stringify","credentials","headers","language","error","newDate","status","updatedAt","toISOString","prev","json","errors","Array","isArray","fieldErrors","nonFieldErrors","reduce","fieldErrs","nonFieldErrs","err","newFieldErrs","newNonFieldErrs","message","push","forEach","dataError","field","type","document","doc","result","didMount","previousDebouncedFieldValues","debouncedFieldValues","clearTimeout","_jsxs","className","_jsx","Fragment","distance","date"],"sources":["../../../src/elements/Autosave/index.tsx"],"sourcesContent":["'use client'\n// TODO: abstract the `next/navigation` dependency out from this component\nimport type { ClientCollectionConfig, ClientGlobalConfig } from 'payload'\n\nimport { dequal } from 'dequal/lite'\nimport { reduceFieldsToValues, versionDefaults } from 'payload/shared'\nimport React, { useDeferredValue, useEffect, useRef, useState } from 'react'\nimport { toast } from 'sonner'\n\nimport {\n useAllFormFields,\n useForm,\n useFormModified,\n useFormSubmitted,\n} from '../../forms/Form/context.js'\nimport { useDebounce } from '../../hooks/useDebounce.js'\nimport { useEffectEvent } from '../../hooks/useEffectEvent.js'\nimport { useConfig } from '../../providers/Config/index.js'\nimport { useDocumentEvents } from '../../providers/DocumentEvents/index.js'\nimport { useDocumentInfo } from '../../providers/DocumentInfo/index.js'\nimport { useLocale } from '../../providers/Locale/index.js'\nimport './index.scss'\nimport { useTranslation } from '../../providers/Translation/index.js'\nimport { formatTimeToNow } from '../../utilities/formatDate.js'\nimport { reduceFieldsToValuesWithValidation } from '../../utilities/reduceFieldsToValuesWithValidation.js'\nimport { LeaveWithoutSaving } from '../LeaveWithoutSaving/index.js'\n\nconst baseClass = 'autosave'\n// The minimum time the saving state should be shown\nconst minimumAnimationTime = 1000\n\nexport type Props = {\n collection?: ClientCollectionConfig\n global?: ClientGlobalConfig\n id?: number | string\n publishedDocUpdatedAt: string\n}\n\nexport const Autosave: React.FC<Props> = ({ id, collection, global: globalDoc }) => {\n const {\n config: {\n routes: { api },\n serverURL,\n },\n } = useConfig()\n const {\n docConfig,\n incrementVersionCount,\n lastUpdateTime,\n mostRecentVersionIsAutosaved,\n setLastUpdateTime,\n setMostRecentVersionIsAutosaved,\n setUnpublishedVersionCount,\n updateSavedDocumentData,\n } = useDocumentInfo()\n const queueRef = useRef([])\n const isProcessingRef = useRef(false)\n\n const { reportUpdate } = useDocumentEvents()\n const { dispatchFields, isValid, setIsValid, setSubmitted } = useForm()\n\n const [fields] = useAllFormFields()\n const modified = useFormModified()\n const submitted = useFormSubmitted()\n\n const { code: locale } = useLocale()\n const { i18n, t } = useTranslation()\n\n const versionsConfig = docConfig?.versions\n let interval = versionDefaults.autosaveInterval\n\n if (versionsConfig.drafts && versionsConfig.drafts.autosave) {\n interval = versionsConfig.drafts.autosave.interval\n }\n\n const validateOnDraft = Boolean(\n docConfig?.versions?.drafts && docConfig?.versions?.drafts.validate,\n )\n\n const [_saving, setSaving] = useState(false)\n const saving = useDeferredValue(_saving)\n const debouncedFields = useDebounce(fields, interval)\n const fieldRef = useRef(fields)\n const modifiedRef = useRef(modified)\n const localeRef = useRef(locale)\n /**\n * Track the validation internally so Autosave can determine when to run queue processing again\n * Helps us prevent infinite loops when the queue is processing and the form is invalid\n */\n const isValidRef = useRef(isValid)\n\n // Store fields in ref so the autosave func\n // can always retrieve the most to date copies\n // after the timeout has executed\n fieldRef.current = fields\n\n // Store modified in ref so the autosave func\n // can bail out if modified becomes false while\n // timing out during autosave\n modifiedRef.current = modified\n\n // Store locale in ref so the autosave func\n // can always retrieve the most to date locale\n localeRef.current = locale\n\n const processQueue = React.useCallback(async () => {\n if (isProcessingRef.current || queueRef.current.length === 0) {\n return\n }\n\n if (!isValidRef.current) {\n // Clear queue so we don't end up in an infinite loop\n queueRef.current = []\n // Reset internal validation state so queue processing can run again\n isValidRef.current = true\n return\n }\n isProcessingRef.current = true\n\n const latestAction = queueRef.current[queueRef.current.length - 1]\n queueRef.current = []\n\n try {\n await latestAction()\n } finally {\n isProcessingRef.current = false\n if (queueRef.current.length > 0) {\n await processQueue()\n }\n }\n }, [])\n\n const autosaveTimeoutRef = useRef<NodeJS.Timeout | null>(null)\n\n const handleAutosave = useEffectEvent(() => {\n autosaveTimeoutRef.current = undefined\n // We need to log the time in order to figure out if we need to trigger the state off later\n let startTimestamp = undefined\n let endTimestamp = undefined\n\n const hideIndicator = () => {\n // If request was faster than minimum animation time, animate the difference\n if (endTimestamp - startTimestamp < minimumAnimationTime) {\n autosaveTimeoutRef.current = setTimeout(\n () => {\n setSaving(false)\n },\n minimumAnimationTime - (endTimestamp - startTimestamp),\n )\n } else {\n stopAutoSaveIndicator()\n }\n }\n\n const autosave = async () => {\n if (modified) {\n startTimestamp = new Date().getTime()\n\n setSaving(true)\n\n let url: string\n let method: string\n let entitySlug: string\n\n if (collection && id) {\n entitySlug = collection.slug\n url = `${serverURL}${api}/${entitySlug}/${id}?draft=true&autosave=true&locale=${localeRef.current}`\n method = 'PATCH'\n }\n\n if (globalDoc) {\n entitySlug = globalDoc.slug\n url = `${serverURL}${api}/globals/${entitySlug}?draft=true&autosave=true&locale=${localeRef.current}`\n method = 'POST'\n }\n\n if (url) {\n if (modifiedRef.current) {\n const { data, valid } = reduceFieldsToValuesWithValidation(fieldRef.current, true)\n\n data._status = 'draft'\n\n const skipSubmission =\n submitted && !valid && versionsConfig?.drafts && versionsConfig?.drafts?.validate\n\n if (!skipSubmission && isValidRef.current) {\n let res\n try {\n res = await fetch(url, {\n body: JSON.stringify(data),\n credentials: 'include',\n headers: {\n 'Accept-Language': i18n.language,\n 'Content-Type': 'application/json',\n },\n method,\n })\n } catch (error) {\n // Swallow Error\n }\n\n const newDate = new Date()\n // We need to log the time in order to figure out if we need to trigger the state off later\n endTimestamp = newDate.getTime()\n\n if (res.status === 200) {\n setLastUpdateTime(newDate.getTime())\n\n reportUpdate({\n id,\n entitySlug,\n updatedAt: newDate.toISOString(),\n })\n\n if (!mostRecentVersionIsAutosaved) {\n incrementVersionCount()\n setMostRecentVersionIsAutosaved(true)\n setUnpublishedVersionCount((prev) => prev + 1)\n }\n }\n const json = await res.json()\n\n if (versionsConfig?.drafts && versionsConfig?.drafts?.validate && json?.errors) {\n if (Array.isArray(json.errors)) {\n const [fieldErrors, nonFieldErrors] = json.errors.reduce(\n ([fieldErrs, nonFieldErrs], err) => {\n const newFieldErrs = []\n const newNonFieldErrs = []\n\n if (err?.message) {\n newNonFieldErrs.push(err)\n }\n\n if (Array.isArray(err?.data)) {\n err.data.forEach((dataError) => {\n if (dataError?.field) {\n newFieldErrs.push(dataError)\n } else {\n newNonFieldErrs.push(dataError)\n }\n })\n }\n\n return [\n [...fieldErrs, ...newFieldErrs],\n [...nonFieldErrs, ...newNonFieldErrs],\n ]\n },\n [[], []],\n )\n\n dispatchFields({\n type: 'ADD_SERVER_ERRORS',\n errors: fieldErrors,\n })\n\n nonFieldErrors.forEach((err) => {\n toast.error(err.message || i18n.t('error:unknown'))\n })\n\n // Set valid to false internally so the queue doesn't process\n isValidRef.current = false\n setIsValid(false)\n setSubmitted(true)\n hideIndicator()\n return\n }\n } else {\n // If it's not an error then we can update the document data inside the context\n const document = json?.doc || json?.result\n\n // Manually update the data since this function doesn't fire the `submit` function from useForm\n if (document) {\n setIsValid(true)\n\n // Reset internal state allowing the queue to process\n isValidRef.current = true\n updateSavedDocumentData(document)\n }\n }\n\n hideIndicator()\n }\n }\n }\n }\n }\n\n queueRef.current.push(autosave)\n void processQueue()\n })\n\n const didMount = useRef(false)\n const previousDebouncedFieldValues = useRef(reduceFieldsToValues(debouncedFields))\n // When debounced fields change, autosave\n useEffect(() => {\n /**\n * Ensure autosave doesn't run on mount\n */\n if (!didMount.current) {\n didMount.current = true\n return\n }\n\n /**\n * Ensure autosave only runs if the form data changes, not every time the entire form state changes\n */\n const debouncedFieldValues = reduceFieldsToValues(debouncedFields)\n if (dequal(debouncedFieldValues, previousDebouncedFieldValues)) {\n return\n }\n\n previousDebouncedFieldValues.current = debouncedFieldValues\n\n handleAutosave()\n }, [debouncedFields])\n\n /**\n * If component unmounts, clear the autosave timeout\n */\n useEffect(() => {\n return () => {\n stopAutoSaveIndicator()\n }\n }, [])\n\n const stopAutoSaveIndicator = useEffectEvent(() => {\n if (autosaveTimeoutRef.current) {\n clearTimeout(autosaveTimeoutRef.current)\n }\n\n setSaving(false)\n })\n\n return (\n <div className={baseClass}>\n {validateOnDraft && !isValid && <LeaveWithoutSaving />}\n {saving && t('general:saving')}\n {!saving && Boolean(lastUpdateTime) && (\n <React.Fragment>\n {t('version:lastSavedAgo', {\n distance: formatTimeToNow({ date: lastUpdateTime, i18n }),\n })}\n </React.Fragment>\n )}\n </div>\n )\n}\n"],"mappings":"AAAA;;;AAIA,SAASA,MAAM,QAAQ;AACvB,SAASC,oBAAoB,EAAEC,eAAe,QAAQ;AACtD,OAAOC,KAAA,IAASC,gBAAgB,EAAEC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ;AACrE,SAASC,KAAK,QAAQ;AAEtB,SACEC,gBAAgB,EAChBC,OAAO,EACPC,eAAe,EACfC,gBAAgB,QACX;AACP,SAASC,WAAW,QAAQ;AAC5B,SAASC,cAAc,QAAQ;AAC/B,SAASC,SAAS,QAAQ;AAC1B,SAASC,iBAAiB,QAAQ;AAClC,SAASC,eAAe,QAAQ;AAChC,SAASC,SAAS,QAAQ;AAC1B,OAAO;AACP,SAASC,cAAc,QAAQ;AAC/B,SAASC,eAAe,QAAQ;AAChC,SAASC,kCAAkC,QAAQ;AACnD,SAASC,kBAAkB,QAAQ;AAEnC,MAAMC,SAAA,GAAY;AAClB;AACA,MAAMC,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O,KAAK,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/elements/Banner/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AAEvC,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,cAAc,CAAA;AAKrB,KAAK,OAAO,GAAG,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAA;AAE1C,MAAM,MAAM,KAAK,GAAG,QAAQ,CAAC;IAC3B,SAAS,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;IAC5B,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,IAAI,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IACtB,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,EAAE,CAAC,EAAE,MAAM,CAAA;IACX,IAAI,CAAC,EAAE,SAAS,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS,CAAA;CAChD,CAAC,CAAA;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,EAAE,EAAE,MAAM,CAAA;CACX,CAAA;AAED,eAAO,MAAM,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAqClC,CAAA"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
4
|
-
import LinkImport from 'next/link.js'; // TODO: abstract this out to support all routers
|
|
5
4
|
import React from 'react';
|
|
6
5
|
import './index.scss';
|
|
7
|
-
|
|
6
|
+
import { Link } from '../Link/index.js';
|
|
8
7
|
const baseClass = 'banner';
|
|
9
8
|
export const Banner = ({
|
|
10
9
|
type = 'default',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["
|
|
1
|
+
{"version":3,"file":"index.js","names":["React","Link","baseClass","Banner","type","alignIcon","children","className","icon","onClick","to","classes","filter","Boolean","join","RenderedType","_jsxs","href","_jsx","Fragment"],"sources":["../../../src/elements/Banner/index.tsx"],"sourcesContent":["'use client'\nimport type { MouseEvent } from 'react'\n\nimport React from 'react'\n\nimport './index.scss'\nimport { Link } from '../Link/index.js'\n\nconst baseClass = 'banner'\n\ntype onClick = (event: MouseEvent) => void\n\nexport type Props = Readonly<{\n alignIcon?: 'left' | 'right'\n children?: React.ReactNode\n className?: string\n icon?: React.ReactNode\n onClick?: onClick\n to?: string\n type?: 'default' | 'error' | 'info' | 'success'\n}>\n\nexport type RenderedTypeProps = {\n children?: React.ReactNode\n className?: string\n onClick?: onClick\n to: string\n}\n\nexport const Banner: React.FC<Props> = ({\n type = 'default',\n alignIcon = 'right',\n children,\n className,\n icon,\n onClick,\n to,\n}) => {\n const classes = [\n baseClass,\n `${baseClass}--type-${type}`,\n className && className,\n to && `${baseClass}--has-link`,\n (to || onClick) && `${baseClass}--has-action`,\n icon && `${baseClass}--has-icon`,\n icon && `${baseClass}--align-icon-${alignIcon}`,\n ]\n .filter(Boolean)\n .join(' ')\n\n let RenderedType: React.ComponentType<RenderedTypeProps> | React.ElementType = 'div'\n\n if (onClick && !to) {\n RenderedType = 'button'\n }\n if (to) {\n RenderedType = Link\n }\n\n return (\n <RenderedType className={classes} href={to || null} onClick={onClick}>\n {icon && alignIcon === 'left' && <React.Fragment>{icon}</React.Fragment>}\n <span className={`${baseClass}__content`}>{children}</span>\n {icon && alignIcon === 'right' && <React.Fragment>{icon}</React.Fragment>}\n </RenderedType>\n )\n}\n"],"mappings":"AAAA;;;AAGA,OAAOA,KAAA,MAAW;AAElB,OAAO;AACP,SAASC,IAAI,QAAQ;AAErB,MAAMC,SAAA,GAAY;AAqBlB,OAAO,MAAMC,MAAA,GAA0BA,CAAC;EACtCC,IAAA,GAAO,SAAS;EAChBC,SAAA,GAAY,OAAO;EACnBC,QAAQ;EACRC,SAAS;EACTC,IAAI;EACJC,OAAO;EACPC;AAAE,CACH;EACC,MAAMC,OAAA,GAAU,CACdT,SAAA,EACA,GAAGA,SAAA,UAAmBE,IAAA,EAAM,EAC5BG,SAAA,IAAaA,SAAA,EACbG,EAAA,IAAM,GAAGR,SAAA,YAAqB,EAC7B,CAAAQ,EAAA,IAAMD,OAAM,KAAM,GAAGP,SAAA,cAAuB,EAC7CM,IAAA,IAAQ,GAAGN,SAAA,YAAqB,EAChCM,IAAA,IAAQ,GAAGN,SAAA,gBAAyBG,SAAA,EAAW,CAChD,CACEO,MAAM,CAACC,OAAA,EACPC,IAAI,CAAC;EAER,IAAIC,YAAA,GAA2E;EAE/E,IAAIN,OAAA,IAAW,CAACC,EAAA,EAAI;IAClBK,YAAA,GAAe;EACjB;EACA,IAAIL,EAAA,EAAI;IACNK,YAAA,GAAed,IAAA;EACjB;EAEA,oBACEe,KAAA,CAACD,YAAA;IAAaR,SAAA,EAAWI,OAAA;IAASM,IAAA,EAAMP,EAAA,IAAM;IAAMD,OAAA,EAASA,OAAA;eAC1DD,IAAA,IAAQH,SAAA,KAAc,uBAAUa,IAAA,CAAClB,KAAA,CAAMmB,QAAQ;gBAAEX;qBAClDU,IAAA,CAAC;MAAKX,SAAA,EAAW,GAAGL,SAAA,WAAoB;gBAAGI;QAC1CE,IAAA,IAAQH,SAAA,KAAc,wBAAWa,IAAA,CAAClB,KAAA,CAAMmB,QAAQ;gBAAEX;;;AAGzD","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/elements/BulkUpload/EditForm/index.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAiC,MAAM,OAAO,CAAA;AAErD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/elements/BulkUpload/EditForm/index.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAiC,MAAM,OAAO,CAAA;AAErD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAoB/C,OAAO,cAAc,CAAA;AAQrB,wBAAgB,QAAQ,CAAC,EAAE,SAAS,EAAE,EAAE,aAAa,qBAoJpD"}
|
|
@@ -10,6 +10,7 @@ import { useDocumentEvents } from '../../../providers/DocumentEvents/index.js';
|
|
|
10
10
|
import { useDocumentInfo } from '../../../providers/DocumentInfo/index.js';
|
|
11
11
|
import { useEditDepth } from '../../../providers/EditDepth/index.js';
|
|
12
12
|
import { OperationProvider } from '../../../providers/Operation/index.js';
|
|
13
|
+
import { useRouteTransition } from '../../../providers/RouteTransition/index.js';
|
|
13
14
|
import { useServerFunctions } from '../../../providers/ServerFunctions/index.js';
|
|
14
15
|
import { useUploadEdits } from '../../../providers/UploadEdits/index.js';
|
|
15
16
|
import { abortAndIgnore, handleAbortRef } from '../../../utilities/abortAndIgnore.js';
|
|
@@ -65,6 +66,9 @@ export function EditForm({
|
|
|
65
66
|
const {
|
|
66
67
|
resetUploadEdits
|
|
67
68
|
} = useUploadEdits();
|
|
69
|
+
const {
|
|
70
|
+
startRouteTransition
|
|
71
|
+
} = useRouteTransition();
|
|
68
72
|
const locale = params.get('locale');
|
|
69
73
|
const collectionSlug = collectionConfig.slug;
|
|
70
74
|
const [schemaPath] = React.useState(collectionSlug);
|
|
@@ -85,11 +89,11 @@ export function EditForm({
|
|
|
85
89
|
adminRoute,
|
|
86
90
|
path: `/collections/${collectionSlug}/${json?.doc?.id}${locale ? `?locale=${locale}` : ''}`
|
|
87
91
|
});
|
|
88
|
-
router.push(redirectRoute);
|
|
92
|
+
startRouteTransition(() => router.push(redirectRoute));
|
|
89
93
|
} else {
|
|
90
94
|
resetUploadEdits();
|
|
91
95
|
}
|
|
92
|
-
}, [adminRoute, collectionSlug, depth, isEditing, locale, onSaveFromContext, reportUpdate, resetUploadEdits, router]);
|
|
96
|
+
}, [adminRoute, collectionSlug, depth, isEditing, locale, onSaveFromContext, reportUpdate, resetUploadEdits, router, startRouteTransition]);
|
|
93
97
|
const onChange = useCallback(async ({
|
|
94
98
|
formState: prevFormState,
|
|
95
99
|
submitted: submitted_0
|