@payloadcms/ui 4.0.0-internal.b6f3b9a → 4.0.0-internal.b8e7c89
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.css +1 -0
- package/dist/elements/AppHeader/index.js +1 -1
- package/dist/elements/AppHeader/index.js.map +1 -1
- package/dist/elements/ArrayAction/index.d.ts +1 -0
- package/dist/elements/ArrayAction/index.d.ts.map +1 -1
- package/dist/elements/ArrayAction/index.js +45 -32
- package/dist/elements/ArrayAction/index.js.map +1 -1
- package/dist/elements/Autosave/index.d.ts.map +1 -1
- package/dist/elements/Autosave/index.js +2 -3
- package/dist/elements/Autosave/index.js.map +1 -1
- package/dist/elements/BulkUpload/AddFilesView/index.css +10 -4
- package/dist/elements/BulkUpload/AddFilesView/index.d.ts.map +1 -1
- package/dist/elements/BulkUpload/AddFilesView/index.js +71 -51
- package/dist/elements/BulkUpload/AddFilesView/index.js.map +1 -1
- package/dist/elements/BulkUpload/FormsManager/index.d.ts.map +1 -1
- package/dist/elements/BulkUpload/FormsManager/index.js +2 -3
- package/dist/elements/BulkUpload/FormsManager/index.js.map +1 -1
- package/dist/elements/Button/index.css +2 -2
- package/dist/elements/Button/index.d.ts.map +1 -1
- package/dist/elements/Button/index.js +2 -0
- package/dist/elements/Button/index.js.map +1 -1
- package/dist/elements/ClipboardAction/mergeFormStateFromClipboard.d.ts +10 -0
- package/dist/elements/ClipboardAction/mergeFormStateFromClipboard.d.ts.map +1 -1
- package/dist/elements/ClipboardAction/mergeFormStateFromClipboard.js +65 -3
- package/dist/elements/ClipboardAction/mergeFormStateFromClipboard.js.map +1 -1
- package/dist/elements/ClipboardAction/mergeFormStateFromClipboard.spec.js +345 -1
- package/dist/elements/ClipboardAction/mergeFormStateFromClipboard.spec.js.map +1 -1
- package/dist/elements/CopyLocaleData/index.d.ts.map +1 -1
- package/dist/elements/CopyLocaleData/index.js +8 -9
- package/dist/elements/CopyLocaleData/index.js.map +1 -1
- package/dist/elements/CopyToClipboard/index.d.ts +1 -0
- package/dist/elements/CopyToClipboard/index.d.ts.map +1 -1
- package/dist/elements/CopyToClipboard/index.js +10 -8
- package/dist/elements/CopyToClipboard/index.js.map +1 -1
- package/dist/elements/DeleteMany/index.d.ts.map +1 -1
- package/dist/elements/DeleteMany/index.js +2 -3
- package/dist/elements/DeleteMany/index.js.map +1 -1
- package/dist/elements/Drawer/index.css +10 -4
- package/dist/elements/Dropzone/index.css +10 -4
- package/dist/elements/DuplicateDocument/SelectLocalesDrawer/index.js +3 -2
- package/dist/elements/DuplicateDocument/SelectLocalesDrawer/index.js.map +1 -1
- package/dist/elements/DuplicateDocument/index.d.ts.map +1 -1
- package/dist/elements/DuplicateDocument/index.js +2 -3
- 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 +2 -3
- package/dist/elements/EditMany/DrawerContent.js.map +1 -1
- package/dist/elements/FileManager/FileToolbar/index.d.ts.map +1 -1
- package/dist/elements/FileManager/FileToolbar/index.js +3 -0
- package/dist/elements/FileManager/FileToolbar/index.js.map +1 -1
- package/dist/elements/FileManager/index.css +0 -30
- package/dist/elements/FileManager/index.d.ts.map +1 -1
- package/dist/elements/FileManager/index.js +379 -287
- package/dist/elements/FileManager/index.js.map +1 -1
- package/dist/elements/Hierarchy/MoveMany/index.d.ts.map +1 -1
- package/dist/elements/Hierarchy/MoveMany/index.js +2 -3
- package/dist/elements/Hierarchy/MoveMany/index.js.map +1 -1
- package/dist/elements/Hierarchy/Search/useHierarchySearch.d.ts.map +1 -1
- package/dist/elements/Hierarchy/Search/useHierarchySearch.js +2 -3
- package/dist/elements/Hierarchy/Search/useHierarchySearch.js.map +1 -1
- package/dist/elements/IDLabel/index.css +6 -0
- package/dist/elements/IDLabel/index.d.ts +1 -1
- package/dist/elements/IDLabel/index.d.ts.map +1 -1
- package/dist/elements/IDLabel/index.js +16 -21
- package/dist/elements/IDLabel/index.js.map +1 -1
- package/dist/elements/ListHeader/TitleActions/ListBulkUploadButton.d.ts +1 -7
- package/dist/elements/ListHeader/TitleActions/ListBulkUploadButton.d.ts.map +1 -1
- package/dist/elements/ListHeader/TitleActions/ListBulkUploadButton.js +26 -32
- package/dist/elements/ListHeader/TitleActions/ListBulkUploadButton.js.map +1 -1
- package/dist/elements/ListHeader/TitleActions/ListEmptyTrashButton.d.ts.map +1 -1
- package/dist/elements/ListHeader/TitleActions/ListEmptyTrashButton.js +2 -3
- package/dist/elements/ListHeader/TitleActions/ListEmptyTrashButton.js.map +1 -1
- package/dist/elements/LivePreview/Window/index.js +1 -1
- package/dist/elements/LivePreview/Window/index.js.map +1 -1
- package/dist/elements/Localizer/index.js +1 -1
- package/dist/elements/Localizer/index.js.map +1 -1
- package/dist/elements/Popup/PopupButtonList/index.css +1 -1
- package/dist/elements/Popup/index.js +1 -1
- package/dist/elements/Popup/index.js.map +1 -1
- package/dist/elements/PublishButton/ScheduleDrawer/index.d.ts.map +1 -1
- package/dist/elements/PublishButton/ScheduleDrawer/index.js +9 -31
- package/dist/elements/PublishButton/ScheduleDrawer/index.js.map +1 -1
- package/dist/elements/PublishButton/ScheduleDrawer/types.d.ts +1 -1
- package/dist/elements/PublishButton/ScheduleDrawer/types.d.ts.map +1 -1
- package/dist/elements/PublishButton/ScheduleDrawer/types.js.map +1 -1
- package/dist/elements/PublishButton/index.d.ts.map +1 -1
- package/dist/elements/PublishButton/index.js +5 -6
- package/dist/elements/PublishButton/index.js.map +1 -1
- package/dist/elements/PublishMany/DrawerContent.d.ts.map +1 -1
- package/dist/elements/PublishMany/DrawerContent.js +2 -3
- package/dist/elements/PublishMany/DrawerContent.js.map +1 -1
- package/dist/elements/QueryPresets/QueryPresetBar/index.js +1 -3
- package/dist/elements/QueryPresets/QueryPresetBar/index.js.map +1 -1
- package/dist/elements/RelationshipTable/index.d.ts.map +1 -1
- package/dist/elements/RelationshipTable/index.js +5 -2
- package/dist/elements/RelationshipTable/index.js.map +1 -1
- package/dist/elements/RestoreMany/index.d.ts.map +1 -1
- package/dist/elements/RestoreMany/index.js +2 -3
- package/dist/elements/RestoreMany/index.js.map +1 -1
- package/dist/elements/SaveDraftButton/index.d.ts.map +1 -1
- package/dist/elements/SaveDraftButton/index.js +2 -3
- package/dist/elements/SaveDraftButton/index.js.map +1 -1
- package/dist/elements/SortHeader/index.d.ts.map +1 -1
- package/dist/elements/SortHeader/index.js +29 -26
- package/dist/elements/SortHeader/index.js.map +1 -1
- package/dist/elements/Status/index.d.ts.map +1 -1
- package/dist/elements/Status/index.js +2 -3
- package/dist/elements/Status/index.js.map +1 -1
- package/dist/elements/StepNav/index.css +64 -14
- package/dist/elements/StepNav/index.d.ts.map +1 -1
- package/dist/elements/StepNav/index.js +143 -69
- package/dist/elements/StepNav/index.js.map +1 -1
- package/dist/elements/Table/DefaultCell/index.d.ts.map +1 -1
- package/dist/elements/Table/DefaultCell/index.js +3 -11
- package/dist/elements/Table/DefaultCell/index.js.map +1 -1
- package/dist/elements/Table/OrderableTable.d.ts.map +1 -1
- package/dist/elements/Table/OrderableTable.js +2 -3
- package/dist/elements/Table/OrderableTable.js.map +1 -1
- package/dist/elements/Table/RelationshipProvider/index.d.ts.map +1 -1
- package/dist/elements/Table/RelationshipProvider/index.js +2 -3
- package/dist/elements/Table/RelationshipProvider/index.js.map +1 -1
- package/dist/elements/UnpublishButton/index.d.ts.map +1 -1
- package/dist/elements/UnpublishButton/index.js +3 -4
- package/dist/elements/UnpublishButton/index.js.map +1 -1
- package/dist/elements/UnpublishMany/DrawerContent.d.ts.map +1 -1
- package/dist/elements/UnpublishMany/DrawerContent.js +2 -3
- package/dist/elements/UnpublishMany/DrawerContent.js.map +1 -1
- package/dist/elements/Upload/UploadFromURLModal/index.d.ts +1 -1
- package/dist/elements/Upload/UploadFromURLModal/index.d.ts.map +1 -1
- package/dist/elements/Upload/UploadFromURLModal/index.js.map +1 -1
- package/dist/elements/Upload/index.css +39 -32
- package/dist/elements/Upload/index.d.ts.map +1 -1
- package/dist/elements/Upload/index.js +37 -99
- package/dist/elements/Upload/index.js.map +1 -1
- package/dist/elements/Upload/usePasteFromClipboard.d.ts +14 -0
- package/dist/elements/Upload/usePasteFromClipboard.d.ts.map +1 -0
- package/dist/elements/Upload/usePasteFromClipboard.js +93 -0
- package/dist/elements/Upload/usePasteFromClipboard.js.map +1 -0
- package/dist/elements/Upload/useUploadFromUrl.d.ts +20 -0
- package/dist/elements/Upload/useUploadFromUrl.d.ts.map +1 -0
- package/dist/elements/Upload/useUploadFromUrl.js +201 -0
- package/dist/elements/Upload/useUploadFromUrl.js.map +1 -0
- package/dist/elements/UploadDropzoneContent/index.css +31 -0
- package/dist/elements/UploadDropzoneContent/index.d.ts +17 -0
- package/dist/elements/UploadDropzoneContent/index.d.ts.map +1 -0
- package/dist/elements/UploadDropzoneContent/index.js +62 -0
- package/dist/elements/UploadDropzoneContent/index.js.map +1 -0
- package/dist/elements/WhereBuilder/Condition/Relationship/index.js +1 -1
- package/dist/elements/WhereBuilder/Condition/Relationship/index.js.map +1 -1
- package/dist/elements/WhereBuilder/conditionValue.d.ts +32 -0
- package/dist/elements/WhereBuilder/conditionValue.d.ts.map +1 -0
- package/dist/elements/WhereBuilder/conditionValue.js +32 -0
- package/dist/elements/WhereBuilder/conditionValue.js.map +1 -0
- package/dist/elements/WhereBuilder/conditionValue.spec.js +65 -0
- package/dist/elements/WhereBuilder/conditionValue.spec.js.map +1 -0
- package/dist/elements/WhereBuilder/index.d.ts.map +1 -1
- package/dist/elements/WhereBuilder/index.js +15 -4
- package/dist/elements/WhereBuilder/index.js.map +1 -1
- package/dist/exports/client/index.d.ts +2 -1
- package/dist/exports/client/index.d.ts.map +1 -1
- package/dist/exports/client/index.js +1 -1
- package/dist/exports/client/index.js.map +3 -3
- package/dist/fields/Array/ArrayRow.d.ts +1 -0
- package/dist/fields/Array/ArrayRow.d.ts.map +1 -1
- package/dist/fields/Array/ArrayRow.js +2 -0
- package/dist/fields/Array/ArrayRow.js.map +1 -1
- package/dist/fields/Array/index.d.ts.map +1 -1
- package/dist/fields/Array/index.js +40 -13
- package/dist/fields/Array/index.js.map +1 -1
- package/dist/fields/Blocks/BlockRow.d.ts +1 -0
- package/dist/fields/Blocks/BlockRow.d.ts.map +1 -1
- package/dist/fields/Blocks/BlockRow.js +2 -0
- package/dist/fields/Blocks/BlockRow.js.map +1 -1
- package/dist/fields/Blocks/RowActions.d.ts +1 -0
- package/dist/fields/Blocks/RowActions.d.ts.map +1 -1
- package/dist/fields/Blocks/RowActions.js +22 -19
- 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 +37 -10
- package/dist/fields/Blocks/index.js.map +1 -1
- package/dist/fields/FieldLabel/index.d.ts.map +1 -1
- package/dist/fields/FieldLabel/index.js +4 -5
- package/dist/fields/FieldLabel/index.js.map +1 -1
- package/dist/fields/Relationship/Input.d.ts.map +1 -1
- package/dist/fields/Relationship/Input.js +2 -3
- package/dist/fields/Relationship/Input.js.map +1 -1
- package/dist/fields/Slug/index.d.ts.map +1 -1
- package/dist/fields/Slug/index.js +2 -3
- package/dist/fields/Slug/index.js.map +1 -1
- package/dist/fields/Upload/Input.d.ts.map +1 -1
- package/dist/fields/Upload/Input.js +46 -19
- package/dist/fields/Upload/Input.js.map +1 -1
- package/dist/fields/Upload/Input.spec.js +242 -0
- package/dist/fields/Upload/Input.spec.js.map +1 -0
- package/dist/fields/shared/index.d.ts +1 -1
- package/dist/fields/shared/index.d.ts.map +1 -1
- package/dist/fields/shared/index.js.map +1 -1
- package/dist/forms/Form/index.d.ts.map +1 -1
- package/dist/forms/Form/index.js +6 -4
- package/dist/forms/Form/index.js.map +1 -1
- package/dist/forms/NullifyField/index.d.ts.map +1 -1
- package/dist/forms/NullifyField/index.js +2 -3
- package/dist/forms/NullifyField/index.js.map +1 -1
- package/dist/forms/fieldSchemasToFormState/addFieldStatePromise.d.ts.map +1 -1
- package/dist/forms/fieldSchemasToFormState/addFieldStatePromise.js +1 -0
- package/dist/forms/fieldSchemasToFormState/addFieldStatePromise.js.map +1 -1
- package/dist/hooks/usePayloadAPI.d.ts.map +1 -1
- package/dist/hooks/usePayloadAPI.js +2 -3
- package/dist/hooks/usePayloadAPI.js.map +1 -1
- package/dist/icons/Edit/index.d.ts +0 -1
- package/dist/icons/Edit/index.d.ts.map +1 -1
- package/dist/icons/Edit/index.js +4 -4
- package/dist/icons/Edit/index.js.map +1 -1
- package/dist/providers/Actions/index.d.ts +1 -0
- package/dist/providers/Actions/index.d.ts.map +1 -1
- package/dist/providers/Actions/index.js +43 -11
- package/dist/providers/Actions/index.js.map +1 -1
- package/dist/providers/Auth/AuthSessionDebug/index.css +48 -0
- package/dist/providers/Auth/AuthSessionDebug/index.d.ts +13 -0
- package/dist/providers/Auth/AuthSessionDebug/index.d.ts.map +1 -0
- package/dist/providers/Auth/AuthSessionDebug/index.js +93 -0
- package/dist/providers/Auth/AuthSessionDebug/index.js.map +1 -0
- package/dist/providers/Auth/AuthSessionDebug/utilities.d.ts +21 -0
- package/dist/providers/Auth/AuthSessionDebug/utilities.d.ts.map +1 -0
- package/dist/providers/Auth/AuthSessionDebug/utilities.js +53 -0
- package/dist/providers/Auth/AuthSessionDebug/utilities.js.map +1 -0
- package/dist/providers/Auth/authSessionRequests.d.ts +27 -0
- package/dist/providers/Auth/authSessionRequests.d.ts.map +1 -0
- package/dist/providers/Auth/authSessionRequests.js +119 -0
- package/dist/providers/Auth/authSessionRequests.js.map +1 -0
- package/dist/providers/Auth/authSessionRequests.spec.js +121 -0
- package/dist/providers/Auth/authSessionRequests.spec.js.map +1 -0
- package/dist/providers/Auth/index.d.ts +2 -56
- package/dist/providers/Auth/index.d.ts.map +1 -1
- package/dist/providers/Auth/index.js +283 -135
- package/dist/providers/Auth/index.js.map +1 -1
- package/dist/providers/Auth/sessionActivity.d.ts +23 -0
- package/dist/providers/Auth/sessionActivity.d.ts.map +1 -0
- package/dist/providers/Auth/sessionActivity.js +49 -0
- package/dist/providers/Auth/sessionActivity.js.map +1 -0
- package/dist/providers/Auth/sessionActivity.spec.js +44 -0
- package/dist/providers/Auth/sessionActivity.spec.js.map +1 -0
- package/dist/providers/Auth/sessionTiming.d.ts +11 -0
- package/dist/providers/Auth/sessionTiming.d.ts.map +1 -0
- package/dist/providers/Auth/sessionTiming.js +18 -0
- package/dist/providers/Auth/sessionTiming.js.map +1 -0
- package/dist/providers/Auth/tabSessionSync/index.d.ts +17 -0
- package/dist/providers/Auth/tabSessionSync/index.d.ts.map +1 -0
- package/dist/providers/Auth/tabSessionSync/index.js +263 -0
- package/dist/providers/Auth/tabSessionSync/index.js.map +1 -0
- package/dist/providers/Auth/tabSessionSync/index.spec.js +463 -0
- package/dist/providers/Auth/tabSessionSync/index.spec.js.map +1 -0
- package/dist/providers/Auth/tabSessionSync/types.d.ts +107 -0
- package/dist/providers/Auth/tabSessionSync/types.d.ts.map +1 -0
- package/dist/providers/Auth/tabSessionSync/types.js +6 -0
- package/dist/providers/Auth/tabSessionSync/types.js.map +1 -0
- package/dist/providers/Auth/tabSessionSync/useTabSessionSync.d.ts +11 -0
- package/dist/providers/Auth/tabSessionSync/useTabSessionSync.d.ts.map +1 -0
- package/dist/providers/Auth/tabSessionSync/useTabSessionSync.js +90 -0
- package/dist/providers/Auth/tabSessionSync/useTabSessionSync.js.map +1 -0
- package/dist/providers/Auth/tabSessionSync/utilities.d.ts +26 -0
- package/dist/providers/Auth/tabSessionSync/utilities.d.ts.map +1 -0
- package/dist/providers/Auth/tabSessionSync/utilities.js +159 -0
- package/dist/providers/Auth/tabSessionSync/utilities.js.map +1 -0
- package/dist/providers/Auth/types.d.ts +65 -0
- package/dist/providers/Auth/types.d.ts.map +1 -0
- package/dist/providers/Auth/types.js +2 -0
- package/dist/providers/Auth/types.js.map +1 -0
- package/dist/providers/Auth/useAuthSessionTimers.d.ts +26 -0
- package/dist/providers/Auth/useAuthSessionTimers.d.ts.map +1 -0
- package/dist/providers/Auth/useAuthSessionTimers.js +203 -0
- package/dist/providers/Auth/useAuthSessionTimers.js.map +1 -0
- package/dist/providers/Auth/useAuthSessionTimers.spec.js +311 -0
- package/dist/providers/Auth/useAuthSessionTimers.spec.js.map +1 -0
- package/dist/providers/DocumentInfo/index.d.ts.map +1 -1
- package/dist/providers/DocumentInfo/index.js +2 -3
- package/dist/providers/DocumentInfo/index.js.map +1 -1
- package/dist/providers/FormErrorHandler/index.d.ts +5 -1
- package/dist/providers/FormErrorHandler/index.d.ts.map +1 -1
- package/dist/providers/FormErrorHandler/index.js.map +1 -1
- package/dist/providers/LivePreview/index.d.ts.map +1 -1
- package/dist/providers/LivePreview/index.js +13 -6
- package/dist/providers/LivePreview/index.js.map +1 -1
- package/dist/providers/Locale/index.d.ts +1 -5
- package/dist/providers/Locale/index.d.ts.map +1 -1
- package/dist/providers/Locale/index.js +64 -137
- package/dist/providers/Locale/index.js.map +1 -1
- package/dist/providers/RouteTransition/ProgressBar/index.js +4 -1
- package/dist/providers/RouteTransition/ProgressBar/index.js.map +1 -1
- package/dist/providers/RouteTransition/ProgressBar/index.spec.js +44 -0
- package/dist/providers/RouteTransition/ProgressBar/index.spec.js.map +1 -0
- package/dist/providers/RouteTransition/index.d.ts +2 -2
- package/dist/providers/RouteTransition/index.d.ts.map +1 -1
- package/dist/providers/RouteTransition/index.js +10 -10
- package/dist/providers/RouteTransition/index.js.map +1 -1
- package/dist/providers/Selection/index.d.ts.map +1 -1
- package/dist/providers/Selection/index.js +2 -3
- package/dist/providers/Selection/index.js.map +1 -1
- package/dist/providers/ServerFunctions/index.d.ts +5 -1
- package/dist/providers/ServerFunctions/index.d.ts.map +1 -1
- package/dist/providers/ServerFunctions/index.js +15 -0
- package/dist/providers/ServerFunctions/index.js.map +1 -1
- package/dist/providers/TableColumns/buildColumnState/index.d.ts.map +1 -1
- package/dist/providers/TableColumns/buildColumnState/index.js +0 -1
- package/dist/providers/TableColumns/buildColumnState/index.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/templates/Default/index.d.ts +1 -0
- package/dist/templates/Default/index.d.ts.map +1 -1
- package/dist/templates/Default/index.js +2 -0
- package/dist/templates/Default/index.js.map +1 -1
- package/dist/utilities/formatAbsoluteURL.d.ts +1 -1
- package/dist/utilities/formatAbsoluteURL.d.ts.map +1 -1
- package/dist/utilities/formatAbsoluteURL.js +18 -8
- package/dist/utilities/formatAbsoluteURL.js.map +1 -1
- package/dist/utilities/formatAbsoluteURL.spec.js +27 -0
- package/dist/utilities/formatAbsoluteURL.spec.js.map +1 -0
- package/dist/utilities/formatMetadata.d.ts.map +1 -1
- package/dist/utilities/formatMetadata.js +0 -5
- package/dist/utilities/formatMetadata.js.map +1 -1
- package/dist/utilities/getFilesFromClipboard.d.ts +10 -0
- package/dist/utilities/getFilesFromClipboard.d.ts.map +1 -0
- package/dist/utilities/getFilesFromClipboard.js +49 -0
- package/dist/utilities/getFilesFromClipboard.js.map +1 -0
- package/dist/utilities/getHasScheduledPublish.d.ts +2 -3
- package/dist/utilities/getHasScheduledPublish.d.ts.map +1 -1
- package/dist/utilities/getHasScheduledPublish.js +2 -5
- package/dist/utilities/getHasScheduledPublish.js.map +1 -1
- package/dist/utilities/isAbsoluteURL.d.ts +3 -0
- package/dist/utilities/isAbsoluteURL.d.ts.map +1 -0
- package/dist/utilities/isAbsoluteURL.js +15 -0
- package/dist/utilities/isAbsoluteURL.js.map +1 -0
- package/dist/utilities/isAbsoluteURL.spec.js +11 -0
- package/dist/utilities/isAbsoluteURL.spec.js.map +1 -0
- package/dist/utilities/isHttpURL.d.ts +3 -0
- package/dist/utilities/isHttpURL.d.ts.map +1 -0
- package/dist/utilities/isHttpURL.js +12 -0
- package/dist/utilities/isHttpURL.js.map +1 -0
- package/dist/utilities/isHttpURL.spec.js +25 -0
- package/dist/utilities/isHttpURL.spec.js.map +1 -0
- package/dist/utilities/schedulePublishHandler.d.ts +8 -1
- package/dist/utilities/schedulePublishHandler.d.ts.map +1 -1
- package/dist/utilities/schedulePublishHandler.js +68 -4
- package/dist/utilities/schedulePublishHandler.js.map +1 -1
- package/dist/utilities/serverFunctionRegistry.d.ts.map +1 -1
- package/dist/utilities/serverFunctionRegistry.js +2 -1
- package/dist/utilities/serverFunctionRegistry.js.map +1 -1
- package/dist/utilities/slugify.d.ts.map +1 -1
- package/dist/utilities/slugify.js +3 -0
- package/dist/utilities/slugify.js.map +1 -1
- package/dist/views/API/index.client.d.ts.map +1 -1
- package/dist/views/API/index.client.js +2 -3
- package/dist/views/API/index.client.js.map +1 -1
- package/dist/views/Dashboard/Default/ModularDashboard/DashboardStepNav.d.ts.map +1 -1
- package/dist/views/Dashboard/Default/ModularDashboard/DashboardStepNav.js +3 -2
- package/dist/views/Dashboard/Default/ModularDashboard/DashboardStepNav.js.map +1 -1
- package/dist/views/Dashboard/Default/ModularDashboard/WidgetEditControl.d.ts.map +1 -1
- package/dist/views/Dashboard/Default/ModularDashboard/WidgetEditControl.js +7 -7
- package/dist/views/Dashboard/Default/ModularDashboard/WidgetEditControl.js.map +1 -1
- package/dist/views/Dashboard/Default/ModularDashboard/index.client.d.ts.map +1 -1
- package/dist/views/Dashboard/Default/ModularDashboard/index.client.js +104 -66
- package/dist/views/Dashboard/Default/ModularDashboard/index.client.js.map +1 -1
- package/dist/views/Dashboard/Default/ModularDashboard/index.css +33 -140
- package/dist/views/Document/index.d.ts.map +1 -1
- package/dist/views/Document/index.js +1 -2
- package/dist/views/Document/index.js.map +1 -1
- package/dist/views/Edit/SetDocumentTitle/index.d.ts.map +1 -1
- package/dist/views/Edit/SetDocumentTitle/index.js +4 -1
- package/dist/views/Edit/SetDocumentTitle/index.js.map +1 -1
- package/dist/views/Edit/index.d.ts.map +1 -1
- package/dist/views/Edit/index.js +3 -2
- package/dist/views/Edit/index.js.map +1 -1
- package/dist/views/List/ListHeader/index.d.ts +1 -10
- package/dist/views/List/ListHeader/index.d.ts.map +1 -1
- package/dist/views/List/ListHeader/index.js +1 -3
- package/dist/views/List/ListHeader/index.js.map +1 -1
- package/dist/views/List/index.client.d.ts.map +1 -1
- package/dist/views/List/index.client.js +0 -14
- package/dist/views/List/index.client.js.map +1 -1
- package/dist/views/List/index.css +5 -0
- package/dist/views/Root/getCustomCollectionViewByRoute.d.ts.map +1 -1
- package/dist/views/Root/getCustomCollectionViewByRoute.js.map +1 -1
- package/dist/views/Root/getCustomGlobalViewByRoute.d.ts.map +1 -1
- package/dist/views/Root/getCustomGlobalViewByRoute.js.map +1 -1
- package/dist/views/Root/getCustomViewByKey.d.ts.map +1 -1
- package/dist/views/Root/getCustomViewByKey.js.map +1 -1
- package/dist/views/Root/index.d.ts.map +1 -1
- package/dist/views/Root/index.js +1 -0
- package/dist/views/Root/index.js.map +1 -1
- package/dist/views/Version/Default/SetStepNav.d.ts.map +1 -1
- package/dist/views/Version/Default/SetStepNav.js +10 -13
- package/dist/views/Version/Default/SetStepNav.js.map +1 -1
- package/dist/views/Version/Default/index.d.ts.map +1 -1
- package/dist/views/Version/Default/index.js +12 -13
- package/dist/views/Version/Default/index.js.map +1 -1
- package/dist/views/Version/RenderFieldsToDiff/DiffCollapser/index.d.ts +1 -0
- package/dist/views/Version/RenderFieldsToDiff/DiffCollapser/index.d.ts.map +1 -1
- package/dist/views/Version/RenderFieldsToDiff/DiffCollapser/index.js +56 -50
- package/dist/views/Version/RenderFieldsToDiff/DiffCollapser/index.js.map +1 -1
- package/dist/views/Version/RenderFieldsToDiff/buildVersionFields.d.ts.map +1 -1
- package/dist/views/Version/RenderFieldsToDiff/buildVersionFields.js +41 -27
- package/dist/views/Version/RenderFieldsToDiff/buildVersionFields.js.map +1 -1
- package/dist/views/Version/RenderFieldsToDiff/buildVersionFields.spec.js +258 -0
- package/dist/views/Version/RenderFieldsToDiff/buildVersionFields.spec.js.map +1 -0
- package/dist/views/Version/RenderFieldsToDiff/fields/Iterable/index.d.ts.map +1 -1
- package/dist/views/Version/RenderFieldsToDiff/fields/Iterable/index.js +10 -0
- package/dist/views/Version/RenderFieldsToDiff/fields/Iterable/index.js.map +1 -1
- package/dist/views/Version/RenderFieldsToDiff/utilities/countChangedFields.d.ts.map +1 -1
- package/dist/views/Version/RenderFieldsToDiff/utilities/countChangedFields.js +33 -1
- package/dist/views/Version/RenderFieldsToDiff/utilities/countChangedFields.js.map +1 -1
- package/dist/views/Version/RenderFieldsToDiff/utilities/countChangedFields.spec.js +56 -2
- package/dist/views/Version/RenderFieldsToDiff/utilities/countChangedFields.spec.js.map +1 -1
- package/dist/views/Version/RenderFieldsToDiff/utilities/getFieldsForRowComparison.d.ts +8 -2
- package/dist/views/Version/RenderFieldsToDiff/utilities/getFieldsForRowComparison.d.ts.map +1 -1
- package/dist/views/Version/RenderFieldsToDiff/utilities/getFieldsForRowComparison.js +17 -19
- package/dist/views/Version/RenderFieldsToDiff/utilities/getFieldsForRowComparison.js.map +1 -1
- package/dist/views/Version/RenderFieldsToDiff/utilities/getFieldsForRowComparison.spec.js +3 -13
- package/dist/views/Version/RenderFieldsToDiff/utilities/getFieldsForRowComparison.spec.js.map +1 -1
- package/dist/views/Version/generateVersionViewMetadata.js.map +1 -1
- package/dist/views/Versions/VersionPillLabel/VersionPillLabel.d.ts.map +1 -1
- package/dist/views/Versions/VersionPillLabel/VersionPillLabel.js +2 -3
- package/dist/views/Versions/VersionPillLabel/VersionPillLabel.js.map +1 -1
- package/dist/views/Versions/generateVersionsViewMetadata.js.map +1 -1
- package/package.json +5 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["DndContext","React","useCallback","useEffect","useId","useMemo","useRef","useState","usePopupWindow","useDocumentInfo","usePreferences","formatAbsoluteURL","customCollisionDetection","LivePreviewContext","sizeReducer","LivePreviewProvider","breakpoints","incomingBreakpoints","children","isLivePreviewEnabled","isLivePreviewing","incomingIsLivePreviewing","isPreviewEnabled","previewURL","previewURLFromProps","typeofLivePreviewURL","url","urlFromProps","_setIsLivePreviewing","shouldRenderIframe","setShouldRenderIframe","setIsLivePreviewing","livePreviewing","name","height","label","width","setURL","setPreviewURL","isPopupOpen","openPopupWindow","popupRef","eventType","appIsReady","setAppIsReady","lastReadyAt","setLastReadyAt","collectionSlug","globalSlug","isFirstRender","setPreference","iframeRef","isExpanded","setIsExpanded","loadedURL","setLoadedURL","zoom","setZoom","position","setPosition","x","y","size","setSize","useReducer","measuredDeviceSize","setMeasuredDeviceSize","breakpoint","setBreakpoint","setLivePreviewURL","_incomingURL","incomingURL","handleDragEnd","ev","over","id","newPos","delta","setWidth","type","value","setHeight","foundBreakpoint","find","bp","handleMessage","event","startsWith","origin","data","ready","Date","now","window","addEventListener","removeEventListener","current","editViewType","dndContextID","_jsx","setToolbarPosition","toolbarPosition","collisionDetection","onDragEnd"],"sources":["../../../src/providers/LivePreview/index.tsx"],"sourcesContent":["'use client'\nimport type { CollectionPreferences, LivePreviewConfig, LivePreviewURLType } from 'payload'\n\nimport { DndContext } from '@dnd-kit/core'\nimport React, { useCallback, useEffect, useId, useMemo, useRef, useState } from 'react'\n\nimport type { LivePreviewContextType } from './context.js'\n\nimport { usePopupWindow } from '../../hooks/usePopupWindow.js'\nimport { useDocumentInfo } from '../../providers/DocumentInfo/index.js'\nimport { usePreferences } from '../../providers/Preferences/index.js'\nimport { formatAbsoluteURL } from '../../utilities/formatAbsoluteURL.js'\nimport { customCollisionDetection } from './collisionDetection.js'\nimport { LivePreviewContext } from './context.js'\nimport { sizeReducer } from './sizeReducer.js'\n\nexport type LivePreviewProviderProps = {\n appIsReady?: boolean\n breakpoints?: LivePreviewConfig['breakpoints']\n children: React.ReactNode\n deviceSize?: {\n height: number\n width: number\n }\n isLivePreviewEnabled?: boolean\n isLivePreviewing: boolean\n /**\n * This specifically relates to `admin.preview` function in the config instead of live preview.\n */\n isPreviewEnabled?: boolean\n /**\n * This specifically relates to `admin.preview` function in the config instead of live preview.\n */\n previewURL?: string\n} & Pick<LivePreviewContextType, 'typeofLivePreviewURL' | 'url'>\n\nexport const LivePreviewProvider: React.FC<LivePreviewProviderProps> = ({\n breakpoints: incomingBreakpoints,\n children,\n isLivePreviewEnabled,\n isLivePreviewing: incomingIsLivePreviewing,\n isPreviewEnabled,\n previewURL: previewURLFromProps,\n typeofLivePreviewURL,\n url: urlFromProps,\n}) => {\n const [isLivePreviewing, _setIsLivePreviewing] =\n useState<LivePreviewContextType['isLivePreviewing']>(incomingIsLivePreviewing)\n\n const [shouldRenderIframe, setShouldRenderIframe] =\n useState<LivePreviewContextType['shouldRenderIframe']>(isLivePreviewing)\n\n /**\n * Rendering the iframe is a one-way event, e.g. defer load and never unmount.\n * This way, subsequent toggles will appear to load instantly.\n */\n const setIsLivePreviewing = useCallback<LivePreviewContextType['setIsLivePreviewing']>(\n (livePreviewing) => {\n if (livePreviewing) {\n setShouldRenderIframe(true)\n }\n\n _setIsLivePreviewing(livePreviewing)\n },\n [],\n )\n\n const breakpoints: LivePreviewConfig['breakpoints'] = useMemo(\n () => [\n ...(incomingBreakpoints || []),\n {\n name: 'responsive',\n height: '100%',\n label: 'Responsive',\n width: '100%',\n },\n ],\n [incomingBreakpoints],\n )\n\n const [url, setURL] = useState<string>('')\n const [previewURL, setPreviewURL] = useState<string>(previewURLFromProps)\n\n const { isPopupOpen, openPopupWindow, popupRef } = usePopupWindow({\n eventType: 'payload-live-preview',\n url,\n })\n\n const [appIsReady, setAppIsReady] = useState(false)\n // Tracks when any preview (iframe or popup) signals it's ready\n // Used to trigger an initial sync to newly opened previews\n const [lastReadyAt, setLastReadyAt] = useState<number>(0)\n\n const { collectionSlug, globalSlug } = useDocumentInfo()\n\n const isFirstRender = useRef(true)\n\n const { setPreference } = usePreferences()\n\n const iframeRef = React.useRef<HTMLIFrameElement>(null)\n\n const [isExpanded, setIsExpanded] = useState(false)\n\n const [loadedURL, setLoadedURL] = useState<string>()\n\n const [zoom, setZoom] = useState(1)\n\n const [position, setPosition] = useState({ x: 0, y: 0 })\n\n const [size, setSize] = React.useReducer(sizeReducer, { height: 0, width: 0 })\n\n const [measuredDeviceSize, setMeasuredDeviceSize] = useState({\n height: 0,\n width: 0,\n })\n\n const [breakpoint, setBreakpoint] =\n React.useState<LivePreviewConfig['breakpoints'][0]['name']>('responsive')\n\n /**\n * A \"middleware\" callback fn that does some additional work before `setURL`.\n * This is what we provide through context, bc it:\n * - ensures the URL is absolute\n * - resets `appIsReady` to `false` while the new URL is loading\n */\n const setLivePreviewURL = useCallback<LivePreviewContextType['setURL']>(\n (_incomingURL) => {\n let incomingURL: LivePreviewURLType\n\n if (typeof _incomingURL === 'string') {\n incomingURL = formatAbsoluteURL(_incomingURL)\n }\n\n if (!incomingURL) {\n setIsLivePreviewing(false)\n }\n\n if (incomingURL !== url) {\n setAppIsReady(false)\n setURL(incomingURL)\n }\n },\n [setIsLivePreviewing, url],\n )\n\n /**\n * `url` needs to be relative to the window, which cannot be done on initial render.\n */\n useEffect(() => {\n if (typeof urlFromProps === 'string') {\n setURL(formatAbsoluteURL(urlFromProps))\n }\n }, [urlFromProps])\n\n // The toolbar needs to freely drag and drop around the page\n const handleDragEnd = (ev) => {\n // only update position if the toolbar is completely within the preview area\n // otherwise reset it back to the previous position\n // TODO: reset to the nearest edge of the preview area\n if (ev.over && ev.over.id === 'live-preview-area') {\n const newPos = {\n x: position.x + ev.delta.x,\n y: position.y + ev.delta.y,\n }\n\n setPosition(newPos)\n } else {\n // reset\n }\n }\n\n const setWidth = useCallback(\n (width) => {\n setSize({ type: 'width', value: width })\n },\n [setSize],\n )\n\n const setHeight = useCallback(\n (height) => {\n setSize({ type: 'height', value: height })\n },\n [setSize],\n )\n\n // explicitly set new width and height when as new breakpoints are selected\n // exclude `custom` breakpoint as it is handled by the `setWidth` and `setHeight` directly\n useEffect(() => {\n const foundBreakpoint = breakpoints?.find((bp) => bp.name === breakpoint)\n\n if (\n foundBreakpoint &&\n breakpoint !== 'responsive' &&\n breakpoint !== 'custom' &&\n typeof foundBreakpoint?.width === 'number' &&\n typeof foundBreakpoint?.height === 'number'\n ) {\n setSize({\n type: 'reset',\n value: {\n height: foundBreakpoint.height,\n width: foundBreakpoint.width,\n },\n })\n }\n }, [breakpoint, breakpoints])\n\n /**\n * Receive the `ready` message from the popup window\n * This indicates that the app is ready to receive `window.postMessage` events\n * This is also the only cross-origin way of detecting when a popup window has loaded\n * Unlike iframe elements which have an `onLoad` handler, there is no way to access `window.open` on popups\n */\n useEffect(() => {\n const handleMessage = (event: MessageEvent) => {\n if (\n url?.startsWith(event.origin) &&\n event.data &&\n typeof event.data === 'object' &&\n event.data.type === 'payload-live-preview'\n ) {\n if (event.data.ready) {\n setAppIsReady(true)\n setLastReadyAt(Date.now())\n }\n }\n }\n\n window.addEventListener('message', handleMessage)\n\n return () => {\n window.removeEventListener('message', handleMessage)\n }\n }, [url])\n\n useEffect(() => {\n if (isFirstRender.current) {\n isFirstRender.current = false\n return\n }\n\n void setPreference<CollectionPreferences>(\n collectionSlug ? `collection-${collectionSlug}` : `global-${globalSlug}`,\n {\n editViewType: isLivePreviewing ? 'live-preview' : 'default',\n },\n true,\n )\n }, [isLivePreviewing, setPreference, collectionSlug, globalSlug])\n\n const dndContextID = useId()\n\n return (\n <LivePreviewContext\n value={{\n appIsReady,\n breakpoint,\n breakpoints,\n iframeRef,\n isExpanded,\n isLivePreviewEnabled,\n isLivePreviewing,\n isPopupOpen,\n isPreviewEnabled,\n lastReadyAt,\n loadedURL,\n measuredDeviceSize,\n openPopupWindow,\n popupRef,\n previewURL,\n setBreakpoint,\n setHeight,\n setIsExpanded,\n setIsLivePreviewing,\n setLoadedURL,\n setMeasuredDeviceSize,\n setPreviewURL,\n setSize,\n setToolbarPosition: setPosition,\n setURL: setLivePreviewURL,\n setWidth,\n setZoom,\n shouldRenderIframe,\n size,\n toolbarPosition: position,\n typeofLivePreviewURL,\n url,\n zoom,\n }}\n >\n <DndContext\n collisionDetection={customCollisionDetection}\n // Provide stable ID to fix hydration issues: https://github.com/clauderic/dnd-kit/issues/926\n id={dndContextID}\n onDragEnd={handleDragEnd}\n >\n {children}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ACE+F,IAAA,CAACtF,kBAAA;IACCmE,KAAA,EAAO;MACLrC,UAAA;MACAwB,UAAA;MACAnD,WAAA;MACAmC,SAAA;MACAC,UAAA;MACAjC,oBAAA;MACAC,gBAAA;MACAmB,WAAA;MACAjB,gBAAA;MACAuB,WAAA;MACAS,SAAA;MACAW,kBAAA;MACAzB,eAAA;MACAC,QAAA;MACAlB,UAAA;MACA6C,aAAA;MACAa,SAAA;MACA5B,aAAA;MACAtB,mBAAA;MACAwB,YAAA;MACAW,qBAAA;MACA5B,aAAA;MACAyB,OAAA;MACAqC,kBAAA,EAAoBzC,WAAA;MACpBtB,MAAA,EAAQgC,iBAAA;MACRS,QAAA;MACArB,OAAA;MACA5B,kBAAA;MACAiC,IAAA;MACAuC,eAAA,EAAiB3C,QAAA;MACjBjC,oBAAA;MACAC,GAAA;MACA8B;IACF;cAEA,aAAA2C,IAAA,CAACnG,UAAA;MACCsG,kBAAA,EAAoB1F,wBAAA;MACpB;MACA+D,EAAA,EAAIuB,YAAA;MACJK,SAAA,EAAW/B,aAAA;gBAEVtD;;;AAIT","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["DndContext","React","useCallback","useEffect","useId","useMemo","useRef","useState","usePopupWindow","useDocumentInfo","usePreferences","formatAbsoluteURL","isHttpURL","customCollisionDetection","LivePreviewContext","sizeReducer","LivePreviewProvider","breakpoints","incomingBreakpoints","children","isLivePreviewEnabled","isLivePreviewing","incomingIsLivePreviewing","isPreviewEnabled","previewURL","previewURLFromProps","typeofLivePreviewURL","url","urlFromProps","_setIsLivePreviewing","shouldRenderIframe","setShouldRenderIframe","setIsLivePreviewing","livePreviewing","name","height","label","width","setURL","_setPreviewURL","setPreviewURL","incomingURL","undefined","isPopupOpen","openPopupWindow","popupRef","eventType","appIsReady","setAppIsReady","lastReadyAt","setLastReadyAt","collectionSlug","globalSlug","isFirstRender","setPreference","iframeRef","isExpanded","setIsExpanded","loadedURL","setLoadedURL","zoom","setZoom","position","setPosition","x","y","size","setSize","useReducer","measuredDeviceSize","setMeasuredDeviceSize","breakpoint","setBreakpoint","setLivePreviewURL","_incomingURL","handleDragEnd","ev","over","id","newPos","delta","setWidth","type","value","setHeight","foundBreakpoint","find","bp","handleMessage","event","startsWith","origin","data","ready","Date","now","window","addEventListener","removeEventListener","current","editViewType","dndContextID","_jsx","setToolbarPosition","toolbarPosition","collisionDetection","onDragEnd"],"sources":["../../../src/providers/LivePreview/index.tsx"],"sourcesContent":["'use client'\nimport type { CollectionPreferences, LivePreviewConfig, LivePreviewURLType } from 'payload'\n\nimport { DndContext } from '@dnd-kit/core'\nimport React, { useCallback, useEffect, useId, useMemo, useRef, useState } from 'react'\n\nimport type { LivePreviewContextType } from './context.js'\n\nimport { usePopupWindow } from '../../hooks/usePopupWindow.js'\nimport { useDocumentInfo } from '../../providers/DocumentInfo/index.js'\nimport { usePreferences } from '../../providers/Preferences/index.js'\nimport { formatAbsoluteURL } from '../../utilities/formatAbsoluteURL.js'\nimport { isHttpURL } from '../../utilities/isHttpURL.js'\nimport { customCollisionDetection } from './collisionDetection.js'\nimport { LivePreviewContext } from './context.js'\nimport { sizeReducer } from './sizeReducer.js'\n\nexport type LivePreviewProviderProps = {\n appIsReady?: boolean\n breakpoints?: LivePreviewConfig['breakpoints']\n children: React.ReactNode\n deviceSize?: {\n height: number\n width: number\n }\n isLivePreviewEnabled?: boolean\n isLivePreviewing: boolean\n /**\n * This specifically relates to `admin.preview` function in the config instead of live preview.\n */\n isPreviewEnabled?: boolean\n /**\n * This specifically relates to `admin.preview` function in the config instead of live preview.\n */\n previewURL?: string\n} & Pick<LivePreviewContextType, 'typeofLivePreviewURL' | 'url'>\n\nexport const LivePreviewProvider: React.FC<LivePreviewProviderProps> = ({\n breakpoints: incomingBreakpoints,\n children,\n isLivePreviewEnabled,\n isLivePreviewing: incomingIsLivePreviewing,\n isPreviewEnabled,\n previewURL: previewURLFromProps,\n typeofLivePreviewURL,\n url: urlFromProps,\n}) => {\n const [isLivePreviewing, _setIsLivePreviewing] =\n useState<LivePreviewContextType['isLivePreviewing']>(incomingIsLivePreviewing)\n\n const [shouldRenderIframe, setShouldRenderIframe] =\n useState<LivePreviewContextType['shouldRenderIframe']>(isLivePreviewing)\n\n /**\n * Rendering the iframe is a one-way event, e.g. defer load and never unmount.\n * This way, subsequent toggles will appear to load instantly.\n */\n const setIsLivePreviewing = useCallback<LivePreviewContextType['setIsLivePreviewing']>(\n (livePreviewing) => {\n if (livePreviewing) {\n setShouldRenderIframe(true)\n }\n\n _setIsLivePreviewing(livePreviewing)\n },\n [],\n )\n\n const breakpoints: LivePreviewConfig['breakpoints'] = useMemo(\n () => [\n ...(incomingBreakpoints || []),\n {\n name: 'responsive',\n height: '100%',\n label: 'Responsive',\n width: '100%',\n },\n ],\n [incomingBreakpoints],\n )\n\n const [url, setURL] = useState<string>('')\n const [previewURL, _setPreviewURL] = useState<string>()\n\n const setPreviewURL = useCallback<LivePreviewContextType['setPreviewURL']>((incomingURL) => {\n _setPreviewURL(isHttpURL(incomingURL) ? incomingURL : undefined)\n }, [])\n\n useEffect(() => {\n setPreviewURL(previewURLFromProps)\n }, [previewURLFromProps, setPreviewURL])\n\n const { isPopupOpen, openPopupWindow, popupRef } = usePopupWindow({\n eventType: 'payload-live-preview',\n url,\n })\n\n const [appIsReady, setAppIsReady] = useState(false)\n // Tracks when any preview (iframe or popup) signals it's ready\n // Used to trigger an initial sync to newly opened previews\n const [lastReadyAt, setLastReadyAt] = useState<number>(0)\n\n const { collectionSlug, globalSlug } = useDocumentInfo()\n\n const isFirstRender = useRef(true)\n\n const { setPreference } = usePreferences()\n\n const iframeRef = React.useRef<HTMLIFrameElement>(null)\n\n const [isExpanded, setIsExpanded] = useState(false)\n\n const [loadedURL, setLoadedURL] = useState<string>()\n\n const [zoom, setZoom] = useState(1)\n\n const [position, setPosition] = useState({ x: 0, y: 0 })\n\n const [size, setSize] = React.useReducer(sizeReducer, { height: 0, width: 0 })\n\n const [measuredDeviceSize, setMeasuredDeviceSize] = useState({\n height: 0,\n width: 0,\n })\n\n const [breakpoint, setBreakpoint] =\n React.useState<LivePreviewConfig['breakpoints'][0]['name']>('responsive')\n\n /**\n * A \"middleware\" callback fn that does some additional work before `setURL`.\n * This is what we provide through context, bc it:\n * - ensures the URL is absolute\n * - resets `appIsReady` to `false` while the new URL is loading\n */\n const setLivePreviewURL = useCallback<LivePreviewContextType['setURL']>(\n (_incomingURL) => {\n let incomingURL: LivePreviewURLType\n\n if (typeof _incomingURL === 'string') {\n incomingURL = formatAbsoluteURL(_incomingURL)\n }\n\n if (!incomingURL) {\n setIsLivePreviewing(false)\n }\n\n if (incomingURL !== url) {\n setAppIsReady(false)\n setURL(incomingURL)\n }\n },\n [setIsLivePreviewing, url],\n )\n\n /**\n * `url` needs to be relative to the window, which cannot be done on initial render.\n */\n useEffect(() => {\n if (typeof urlFromProps === 'string') {\n setURL(formatAbsoluteURL(urlFromProps))\n }\n }, [urlFromProps])\n\n // The toolbar needs to freely drag and drop around the page\n const handleDragEnd = (ev) => {\n // only update position if the toolbar is completely within the preview area\n // otherwise reset it back to the previous position\n // TODO: reset to the nearest edge of the preview area\n if (ev.over && ev.over.id === 'live-preview-area') {\n const newPos = {\n x: position.x + ev.delta.x,\n y: position.y + ev.delta.y,\n }\n\n setPosition(newPos)\n } else {\n // reset\n }\n }\n\n const setWidth = useCallback(\n (width) => {\n setSize({ type: 'width', value: width })\n },\n [setSize],\n )\n\n const setHeight = useCallback(\n (height) => {\n setSize({ type: 'height', value: height })\n },\n [setSize],\n )\n\n // explicitly set new width and height when as new breakpoints are selected\n // exclude `custom` breakpoint as it is handled by the `setWidth` and `setHeight` directly\n useEffect(() => {\n const foundBreakpoint = breakpoints?.find((bp) => bp.name === breakpoint)\n\n if (\n foundBreakpoint &&\n breakpoint !== 'responsive' &&\n breakpoint !== 'custom' &&\n typeof foundBreakpoint?.width === 'number' &&\n typeof foundBreakpoint?.height === 'number'\n ) {\n setSize({\n type: 'reset',\n value: {\n height: foundBreakpoint.height,\n width: foundBreakpoint.width,\n },\n })\n }\n }, [breakpoint, breakpoints])\n\n /**\n * Receive the `ready` message from the popup window\n * This indicates that the app is ready to receive `window.postMessage` events\n * This is also the only cross-origin way of detecting when a popup window has loaded\n * Unlike iframe elements which have an `onLoad` handler, there is no way to access `window.open` on popups\n */\n useEffect(() => {\n const handleMessage = (event: MessageEvent) => {\n if (\n url?.startsWith(event.origin) &&\n event.data &&\n typeof event.data === 'object' &&\n event.data.type === 'payload-live-preview'\n ) {\n if (event.data.ready) {\n setAppIsReady(true)\n setLastReadyAt(Date.now())\n }\n }\n }\n\n window.addEventListener('message', handleMessage)\n\n return () => {\n window.removeEventListener('message', handleMessage)\n }\n }, [url])\n\n useEffect(() => {\n if (isFirstRender.current) {\n isFirstRender.current = false\n return\n }\n\n void setPreference<CollectionPreferences>(\n collectionSlug ? `collection-${collectionSlug}` : `global-${globalSlug}`,\n {\n editViewType: isLivePreviewing ? 'live-preview' : 'default',\n },\n true,\n )\n }, [isLivePreviewing, setPreference, collectionSlug, globalSlug])\n\n const dndContextID = useId()\n\n return (\n <LivePreviewContext\n value={{\n appIsReady,\n breakpoint,\n breakpoints,\n iframeRef,\n isExpanded,\n isLivePreviewEnabled,\n isLivePreviewing,\n isPopupOpen,\n isPreviewEnabled,\n lastReadyAt,\n loadedURL,\n measuredDeviceSize,\n openPopupWindow,\n popupRef,\n previewURL,\n setBreakpoint,\n setHeight,\n setIsExpanded,\n setIsLivePreviewing,\n setLoadedURL,\n setMeasuredDeviceSize,\n setPreviewURL,\n setSize,\n setToolbarPosition: setPosition,\n setURL: setLivePreviewURL,\n setWidth,\n setZoom,\n shouldRenderIframe,\n size,\n toolbarPosition: position,\n typeofLivePreviewURL,\n url,\n zoom,\n }}\n >\n <DndContext\n collisionDetection={customCollisionDetection}\n // Provide stable ID to fix hydration issues: https://github.com/clauderic/dnd-kit/issues/926\n id={dndContextID}\n onDragEnd={handleDragEnd}\n >\n {children}\n </DndContext>\n </LivePreviewContext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B,GAAG,UAAUC,UAAA,EAAY,EACxE;MACEgD,YAAA,EAAc/E,gBAAA,GAAmB,iBAAiB;IACpD,GACA;EAEJ,GAAG,CAACA,gBAAA,EAAkBiC,aAAA,EAAeH,cAAA,EAAgBC,UAAA,CAAW;EAEhE,MAAMiD,YAAA,GAAejG,KAAA;EAErB,oBACEkG,IAAA,CAACxF,kBAAA;IACCqE,KAAA,EAAO;MACLpC,UAAA;MACAwB,UAAA;MACAtD,WAAA;MACAsC,SAAA;MACAC,UAAA;MACApC,oBAAA;MACAC,gBAAA;MACAsB,WAAA;MACApB,gBAAA;MACA0B,WAAA;MACAS,SAAA;MACAW,kBAAA;MACAzB,eAAA;MACAC,QAAA;MACArB,UAAA;MACAgD,aAAA;MACAY,SAAA;MACA3B,aAAA;MACAzB,mBAAA;MACA2B,YAAA;MACAW,qBAAA;MACA9B,aAAA;MACA2B,OAAA;MACAoC,kBAAA,EAAoBxC,WAAA;MACpBzB,MAAA,EAAQmC,iBAAA;MACRQ,QAAA;MACApB,OAAA;MACA/B,kBAAA;MACAoC,IAAA;MACAsC,eAAA,EAAiB1C,QAAA;MACjBpC,oBAAA;MACAC,GAAA;MACAiC;IACF;cAEA,aAAA0C,IAAA,CAACtG,UAAA;MACCyG,kBAAA,EAAoB5F,wBAAA;MACpB;MACAiE,EAAA,EAAIuB,YAAA;MACJK,SAAA,EAAW/B,aAAA;gBAEVxD;;;AAIT","ignoreList":[]}
|
|
@@ -12,9 +12,5 @@ export declare const useLocaleLoading: () => {
|
|
|
12
12
|
localeIsLoading: boolean;
|
|
13
13
|
setLocaleIsLoading: (_: boolean) => any;
|
|
14
14
|
};
|
|
15
|
-
|
|
16
|
-
* TODO: V4
|
|
17
|
-
* The return type of the `useLocale` hook will change in v4. It will return `null | Locale` instead of `false | {} | Locale`.
|
|
18
|
-
*/
|
|
19
|
-
export declare const useLocale: () => Locale;
|
|
15
|
+
export declare const useLocale: () => Locale | null;
|
|
20
16
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/Locale/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAGrC,OAAO,KAA0D,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/Locale/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAGrC,OAAO,KAA0D,MAAM,OAAO,CAAA;AAU9E,eAAO,MAAM,oBAAoB;;4BAEP,OAAO;EAC/B,CAAA;AAcF,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,EAAE,CAAC;IAAE,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,CAAA;CAAE,CAsF5F,CAAA;AAED,eAAO,MAAM,gBAAgB;;4BAvGH,OAAO;CAuG8B,CAAA;AAE/D,eAAO,MAAM,SAAS,QAAO,MAAM,GAAG,IAA0B,CAAA"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import { c as _c } from "react/compiler-runtime";
|
|
4
3
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
4
|
import { formatAdminURL } from 'payload/shared';
|
|
6
5
|
import React, { createContext, use, useEffect, useRef, useState } from 'react';
|
|
@@ -8,7 +7,8 @@ import { findLocaleFromCode } from '../../utilities/findLocaleFromCode.js';
|
|
|
8
7
|
import { useAuth } from '../Auth/index.js';
|
|
9
8
|
import { useConfig } from '../Config/index.js';
|
|
10
9
|
import { useSearchParams } from '../RouterAdapter/index.js';
|
|
11
|
-
|
|
10
|
+
import { useRouteTransition } from '../RouteTransition/index.js';
|
|
11
|
+
const LocaleContext = /*#__PURE__*/createContext(null);
|
|
12
12
|
export const LocaleLoadingContext = /*#__PURE__*/createContext({
|
|
13
13
|
localeIsLoading: false,
|
|
14
14
|
setLocaleIsLoading: _ => undefined
|
|
@@ -20,151 +20,78 @@ const fetchPreferences = async (key, baseURL) => await fetch(`${baseURL}/payload
|
|
|
20
20
|
},
|
|
21
21
|
method: 'GET'
|
|
22
22
|
})?.then(res => res.json());
|
|
23
|
-
export const LocaleProvider =
|
|
24
|
-
|
|
23
|
+
export const LocaleProvider = ({
|
|
24
|
+
children,
|
|
25
|
+
/**
|
|
26
|
+
The `locale` prop originates from the root layout, which does not have access to search params
|
|
27
|
+
This component uses the `useSearchParams` hook to get the locale from the URL as precedence over this prop
|
|
28
|
+
This prop does not update as the user navigates the site, because the root layout does not re-render
|
|
29
|
+
*/
|
|
30
|
+
locale: initialLocaleFromPrefs
|
|
31
|
+
}) => {
|
|
25
32
|
const {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
33
|
+
config: {
|
|
34
|
+
localization = false,
|
|
35
|
+
routes: {
|
|
36
|
+
api: apiRoute
|
|
37
|
+
}
|
|
38
|
+
}
|
|
31
39
|
} = useConfig();
|
|
32
|
-
const {
|
|
33
|
-
localization: t2,
|
|
34
|
-
routes: t3
|
|
35
|
-
} = t1;
|
|
36
|
-
const localization = t2 === undefined ? false : t2;
|
|
37
|
-
const {
|
|
38
|
-
api: apiRoute
|
|
39
|
-
} = t3;
|
|
40
40
|
const {
|
|
41
41
|
user
|
|
42
42
|
} = useAuth();
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
let t6;
|
|
55
|
-
if ($[2] !== defaultLocale || $[3] !== initialLocaleFromPrefs || $[4] !== localeFromParams || $[5] !== localization) {
|
|
56
|
-
t6 = () => {
|
|
57
|
-
if (!localization || localization && !localization.locales.length) {
|
|
58
|
-
return {};
|
|
59
|
-
}
|
|
60
|
-
return findLocaleFromCode(localization, localeFromParams) || findLocaleFromCode(localization, initialLocaleFromPrefs) || findLocaleFromCode(localization, defaultLocale) || findLocaleFromCode(localization, localization.locales[0].code);
|
|
61
|
-
};
|
|
62
|
-
$[2] = defaultLocale;
|
|
63
|
-
$[3] = initialLocaleFromPrefs;
|
|
64
|
-
$[4] = localeFromParams;
|
|
65
|
-
$[5] = localization;
|
|
66
|
-
$[6] = t6;
|
|
67
|
-
} else {
|
|
68
|
-
t6 = $[6];
|
|
69
|
-
}
|
|
70
|
-
const [locale, setLocale] = React.useState(t6);
|
|
43
|
+
const {
|
|
44
|
+
isTransitioning
|
|
45
|
+
} = useRouteTransition();
|
|
46
|
+
const defaultLocale = localization ? localization.defaultLocale : 'en';
|
|
47
|
+
const localeFromParams = useSearchParams().get('locale');
|
|
48
|
+
const [locale, setLocale] = React.useState(() => {
|
|
49
|
+
if (!localization || localization && !localization.locales.length) {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
return findLocaleFromCode(localization, localeFromParams) || findLocaleFromCode(localization, initialLocaleFromPrefs) || findLocaleFromCode(localization, defaultLocale) || findLocaleFromCode(localization, localization.locales[0].code);
|
|
53
|
+
});
|
|
71
54
|
const [isLoading, setLocaleIsLoading] = useState(false);
|
|
72
55
|
const prevLocale = useRef(locale);
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
if (locale.code !== prevLocale.current.code) {
|
|
78
|
-
setLocaleIsLoading(false);
|
|
79
|
-
}
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
// Keep fields disabled until the new locale's document state finishes loading.
|
|
58
|
+
if (locale?.code !== prevLocale.current?.code && !isTransitioning) {
|
|
59
|
+
setLocaleIsLoading(false);
|
|
80
60
|
prevLocale.current = locale;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
} else {
|
|
100
|
-
t9 = $[11];
|
|
101
|
-
}
|
|
102
|
-
const fetchURL = t9;
|
|
103
|
-
let t10;
|
|
104
|
-
if ($[12] !== defaultLocale || $[13] !== fetchURL || $[14] !== localeFromParams || $[15] !== localization || $[16] !== user?.id) {
|
|
105
|
-
t10 = () => {
|
|
106
|
-
const resetLocale = async function resetLocale() {
|
|
107
|
-
if (localization && user?.id) {
|
|
108
|
-
const localeToUse = localeFromParams || (await fetchPreferences("locale", fetchURL)?.then(_temp));
|
|
109
|
-
const newLocale = findLocaleFromCode(localization, localeToUse) || findLocaleFromCode(localization, defaultLocale) || findLocaleFromCode(localization, localization?.locales?.[0]?.code);
|
|
110
|
-
if (newLocale) {
|
|
111
|
-
setLocale(newLocale);
|
|
112
|
-
}
|
|
61
|
+
}
|
|
62
|
+
}, [isTransitioning, locale]);
|
|
63
|
+
const fetchURL = formatAdminURL({
|
|
64
|
+
apiRoute,
|
|
65
|
+
path: ''
|
|
66
|
+
});
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
/**
|
|
69
|
+
* This effect should only run when `localeFromParams` changes, i.e. when the user clicks an anchor link
|
|
70
|
+
* The root layout, which sends the initial locale from prefs, will not re-render as the user navigates the site
|
|
71
|
+
* For this reason, we need to fetch the locale from prefs if the search params clears the `locale` query param
|
|
72
|
+
*/
|
|
73
|
+
async function resetLocale() {
|
|
74
|
+
if (localization && user?.id) {
|
|
75
|
+
const localeToUse = localeFromParams || (await fetchPreferences('locale', fetchURL)?.then(res => res.value));
|
|
76
|
+
const newLocale = findLocaleFromCode(localization, localeToUse) || findLocaleFromCode(localization, defaultLocale) || findLocaleFromCode(localization, localization?.locales?.[0]?.code);
|
|
77
|
+
if (newLocale) {
|
|
78
|
+
setLocale(newLocale);
|
|
113
79
|
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
if ($[18] !== defaultLocale || $[19] !== fetchURL || $[20] !== localeFromParams || $[21] !== localization || $[22] !== t11) {
|
|
129
|
-
t12 = [defaultLocale, localization, fetchURL, localeFromParams, t11];
|
|
130
|
-
$[18] = defaultLocale;
|
|
131
|
-
$[19] = fetchURL;
|
|
132
|
-
$[20] = localeFromParams;
|
|
133
|
-
$[21] = localization;
|
|
134
|
-
$[22] = t11;
|
|
135
|
-
$[23] = t12;
|
|
136
|
-
} else {
|
|
137
|
-
t12 = $[23];
|
|
138
|
-
}
|
|
139
|
-
useEffect(t10, t12);
|
|
140
|
-
let t13;
|
|
141
|
-
if ($[24] !== children || $[25] !== isLoading || $[26] !== locale) {
|
|
142
|
-
t13 = _jsx(LocaleContext, {
|
|
143
|
-
value: locale,
|
|
144
|
-
children: _jsx(LocaleLoadingContext, {
|
|
145
|
-
value: {
|
|
146
|
-
localeIsLoading: isLoading,
|
|
147
|
-
setLocaleIsLoading
|
|
148
|
-
},
|
|
149
|
-
children
|
|
150
|
-
})
|
|
151
|
-
});
|
|
152
|
-
$[24] = children;
|
|
153
|
-
$[25] = isLoading;
|
|
154
|
-
$[26] = locale;
|
|
155
|
-
$[27] = t13;
|
|
156
|
-
} else {
|
|
157
|
-
t13 = $[27];
|
|
158
|
-
}
|
|
159
|
-
return t13;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
void resetLocale();
|
|
83
|
+
}, [defaultLocale, localization, fetchURL, localeFromParams, user?.id]);
|
|
84
|
+
return /*#__PURE__*/_jsx(LocaleContext, {
|
|
85
|
+
value: locale,
|
|
86
|
+
children: /*#__PURE__*/_jsx(LocaleLoadingContext, {
|
|
87
|
+
value: {
|
|
88
|
+
localeIsLoading: isLoading,
|
|
89
|
+
setLocaleIsLoading
|
|
90
|
+
},
|
|
91
|
+
children: children
|
|
92
|
+
})
|
|
93
|
+
});
|
|
160
94
|
};
|
|
161
95
|
export const useLocaleLoading = () => use(LocaleLoadingContext);
|
|
162
|
-
/**
|
|
163
|
-
* TODO: V4
|
|
164
|
-
* The return type of the `useLocale` hook will change in v4. It will return `null | Locale` instead of `false | {} | Locale`.
|
|
165
|
-
*/
|
|
166
96
|
export const useLocale = () => use(LocaleContext);
|
|
167
|
-
function _temp(res) {
|
|
168
|
-
return res.value;
|
|
169
|
-
}
|
|
170
97
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["
|
|
1
|
+
{"version":3,"file":"index.js","names":["formatAdminURL","React","createContext","use","useEffect","useRef","useState","findLocaleFromCode","useAuth","useConfig","useSearchParams","useRouteTransition","LocaleContext","LocaleLoadingContext","localeIsLoading","setLocaleIsLoading","_","undefined","fetchPreferences","key","baseURL","fetch","credentials","headers","method","then","res","json","LocaleProvider","children","locale","initialLocaleFromPrefs","config","localization","routes","api","apiRoute","user","isTransitioning","defaultLocale","localeFromParams","get","setLocale","locales","length","code","isLoading","prevLocale","current","fetchURL","path","resetLocale","id","localeToUse","value","newLocale","_jsx","useLocaleLoading","useLocale"],"sources":["../../../src/providers/Locale/index.tsx"],"sourcesContent":["'use client'\n\nimport type { Locale } from 'payload'\n\nimport { formatAdminURL } from 'payload/shared'\nimport React, { createContext, use, useEffect, useRef, useState } from 'react'\n\nimport { findLocaleFromCode } from '../../utilities/findLocaleFromCode.js'\nimport { useAuth } from '../Auth/index.js'\nimport { useConfig } from '../Config/index.js'\nimport { useSearchParams } from '../RouterAdapter/index.js'\nimport { useRouteTransition } from '../RouteTransition/index.js'\n\nconst LocaleContext = createContext<Locale | null>(null)\n\nexport const LocaleLoadingContext = createContext({\n localeIsLoading: false,\n setLocaleIsLoading: (_: boolean) => undefined,\n})\n\nconst fetchPreferences = async <T extends Record<string, unknown> | string>(\n key: string,\n baseURL: string,\n): Promise<{ id: string; value: T }> =>\n await fetch(`${baseURL}/payload-preferences/${key}`, {\n credentials: 'include',\n headers: {\n 'Content-Type': 'application/json',\n },\n method: 'GET',\n })?.then((res) => res.json() as Promise<{ id: string; value: T }>)\n\nexport const LocaleProvider: React.FC<{ children?: React.ReactNode; locale?: Locale['code'] }> = ({\n children,\n /**\n The `locale` prop originates from the root layout, which does not have access to search params\n This component uses the `useSearchParams` hook to get the locale from the URL as precedence over this prop\n This prop does not update as the user navigates the site, because the root layout does not re-render\n */\n locale: initialLocaleFromPrefs,\n}) => {\n const {\n config: {\n localization = false,\n routes: { api: apiRoute },\n },\n } = useConfig()\n\n const { user } = useAuth()\n const { isTransitioning } = useRouteTransition()\n\n const defaultLocale = localization ? localization.defaultLocale : 'en'\n\n const localeFromParams = useSearchParams().get('locale')\n\n const [locale, setLocale] = React.useState<Locale | null>(() => {\n if (!localization || (localization && !localization.locales.length)) {\n return null\n }\n\n return (\n findLocaleFromCode(localization, localeFromParams) ||\n findLocaleFromCode(localization, initialLocaleFromPrefs) ||\n findLocaleFromCode(localization, defaultLocale) ||\n findLocaleFromCode(localization, localization.locales[0].code)\n )\n })\n\n const [isLoading, setLocaleIsLoading] = useState(false)\n\n const prevLocale = useRef<Locale | null>(locale)\n\n useEffect(() => {\n // Keep fields disabled until the new locale's document state finishes loading.\n if (locale?.code !== prevLocale.current?.code && !isTransitioning) {\n setLocaleIsLoading(false)\n prevLocale.current = locale\n }\n }, [isTransitioning, locale])\n\n const fetchURL = formatAdminURL({\n apiRoute,\n path: '',\n })\n\n useEffect(() => {\n /**\n * This effect should only run when `localeFromParams` changes, i.e. when the user clicks an anchor link\n * The root layout, which sends the initial locale from prefs, will not re-render as the user navigates the site\n * For this reason, we need to fetch the locale from prefs if the search params clears the `locale` query param\n */\n async function resetLocale() {\n if (localization && user?.id) {\n const localeToUse =\n localeFromParams ||\n (await fetchPreferences<Locale['code']>('locale', fetchURL)?.then((res) => res.value))\n\n const newLocale =\n findLocaleFromCode(localization, localeToUse) ||\n findLocaleFromCode(localization, defaultLocale) ||\n findLocaleFromCode(localization, localization?.locales?.[0]?.code)\n\n if (newLocale) {\n setLocale(newLocale)\n }\n }\n }\n\n void resetLocale()\n }, [defaultLocale, localization, fetchURL, localeFromParams, user?.id])\n\n return (\n <LocaleContext value={locale}>\n <LocaleLoadingContext value={{ localeIsLoading: isLoading, setLocaleIsLoading }}>\n {children}\n </LocaleLoadingContext>\n </LocaleContext>\n )\n}\n\nexport const useLocaleLoading = () => use(LocaleLoadingContext)\n\nexport const useLocale = (): Locale | null => use(LocaleContext)\n"],"mappings":"AAAA;;;AAIA,SAASA,cAAc,QAAQ;AAC/B,OAAOC,KAAA,IAASC,aAAa,EAAEC,GAAG,EAAEC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ;AAEvE,SAASC,kBAAkB,QAAQ;AACnC,SAASC,OAAO,QAAQ;AACxB,SAASC,SAAS,QAAQ;AAC1B,SAASC,eAAe,QAAQ;AAChC,SAASC,kBAAkB,QAAQ;AAEnC,MAAMC,aAAA,gBAAgBV,aAAA,CAA6B;AAEnD,OAAO,MAAMW,oBAAA,gBAAuBX,aAAA,CAAc;EAChDY,eAAA,EAAiB;EACjBC,kBAAA,EAAqBC,CAAA,IAAeC;AACtC;AAEA,MAAMC,gBAAA,GAAmB,MAAAA,CACvBC,GAAA,EACAC,OAAA,KAEA,MAAMC,KAAA,CAAM,GAAGD,OAAA,wBAA+BD,GAAA,EAAK,EAAE;EACnDG,WAAA,EAAa;EACbC,OAAA,EAAS;IACP,gBAAgB;EAClB;EACAC,MAAA,EAAQ;AACV,IAAIC,IAAA,CAAMC,GAAA,IAAQA,GAAA,CAAIC,IAAI;AAE5B,OAAO,MAAMC,cAAA,GAAoFA,CAAC;EAChGC,QAAQ;EACR;;;;;EAKAC,MAAA,EAAQC;AAAsB,CAC/B;EACC,MAAM;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KA,eAAe+C,YAAA;MACb,IAAIlB,YAAA,IAAgBI,IAAA,EAAMe,EAAA,EAAI;QAC5B,MAAMC,WAAA,GACJb,gBAAA,KACC,MAAMtB,gBAAA,CAAiC,UAAU+B,QAAA,GAAWxB,IAAA,CAAMC,GAAA,IAAQA,GAAA,CAAI4B,KAAK;QAEtF,MAAMC,SAAA,GACJhD,kBAAA,CAAmB0B,YAAA,EAAcoB,WAAA,KACjC9C,kBAAA,CAAmB0B,YAAA,EAAcM,aAAA,KACjChC,kBAAA,CAAmB0B,YAAA,EAAcA,YAAA,EAAcU,OAAA,GAAU,EAAE,EAAEE,IAAA;QAE/D,IAAIU,SAAA,EAAW;UACbb,SAAA,CAAUa,SAAA;QACZ;MACF;IACF;IAEA,KAAKJ,WAAA;EACP,GAAG,CAACZ,aAAA,EAAeN,YAAA,EAAcgB,QAAA,EAAUT,gBAAA,EAAkBH,IAAA,EAAMe,EAAA,CAAG;EAEtE,oBACEI,IAAA,CAAC5C,aAAA;IAAc0C,KAAA,EAAOxB,MAAA;cACpB,aAAA0B,IAAA,CAAC3C,oBAAA;MAAqByC,KAAA,EAAO;QAAExC,eAAA,EAAiBgC,SAAA;QAAW/B;MAAmB;gBAC3Ec;;;AAIT;AAEA,OAAO,MAAM4B,gBAAA,GAAmBA,CAAA,KAAMtD,GAAA,CAAIU,oBAAA;AAE1C,OAAO,MAAM6C,SAAA,GAAYA,CAAA,KAAqBvD,GAAA,CAAIS,aAAA","ignoreList":[]}
|
|
@@ -46,7 +46,7 @@ export const ProgressBar = () => {
|
|
|
46
46
|
}
|
|
47
47
|
} else {
|
|
48
48
|
shouldDelayProgress.current = true;
|
|
49
|
-
setProgressToShow(
|
|
49
|
+
setProgressToShow(_temp);
|
|
50
50
|
clearTimerID = setTimeout(() => {
|
|
51
51
|
setProgressToShow(null);
|
|
52
52
|
}, transitionDuration * 2);
|
|
@@ -101,4 +101,7 @@ export const ProgressBar = () => {
|
|
|
101
101
|
}
|
|
102
102
|
return null;
|
|
103
103
|
};
|
|
104
|
+
function _temp(currentProgress) {
|
|
105
|
+
return currentProgress === null ? null : 1;
|
|
106
|
+
}
|
|
104
107
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["c","_c","React","useEffect","useRef","useRouteTransition","transitionDuration","baseClass","initialDelay","ProgressBar","$","isTransitioning","transitionProgress","progressToShow","setProgressToShow","useState","shouldDelayProgress","t0","t1","clearTimerID","delayTimerID","current","clearTimeout","t2","t3","filter","Boolean","t4","join","t5","_jsx","className","style","children","width"],"sources":["../../../../src/providers/RouteTransition/ProgressBar/index.tsx"],"sourcesContent":["'use client'\nimport React, { useEffect, useRef } from 'react'\n\nimport { useRouteTransition } from '../index.js'\nimport './index.css'\n\nconst transitionDuration = 200\nconst baseClass = 'progress-bar'\nconst initialDelay = 150\n\n/**\n * Renders a progress bar that shows the progress of a route transition.\n * Place this at the root of your application, inside of the `RouteTransitionProvider`.\n * When a transition is triggered, the progress bar will show the progress of that transition and exit when the transition is complete.\n * @returns A progress bar that shows the progress of a route transition\n * @example\n * import { RouteTransitionProvider, ProgressBar, Link } from '@payloadcms/ui'\n * const App = () => (\n * <RouteTransitionProvider>\n * <ProgressBar />\n * <Link href=\"/somewhere\">Go Somewhere</Link>\n * </RouteTransitionProvider>\n */\nexport const ProgressBar = () => {\n const { isTransitioning, transitionProgress } = useRouteTransition()\n const [progressToShow, setProgressToShow] = React.useState<null | number>(null)\n const shouldDelayProgress = useRef(true)\n\n useEffect(() => {\n let clearTimerID: NodeJS.Timeout\n let delayTimerID: NodeJS.Timeout\n\n if (isTransitioning) {\n if (shouldDelayProgress.current) {\n delayTimerID = setTimeout(() => {\n setProgressToShow(transitionProgress)\n shouldDelayProgress.current = false\n }, initialDelay)\n } else {\n setProgressToShow(transitionProgress)\n }\n } else {\n shouldDelayProgress.current = true\n\n // Fast forward to 100% when the transition is complete\n // Then fade out the progress bar directly after\n setProgressToShow(1)\n\n // Wait for CSS transition to finish before hiding the progress bar\n // This includes both the fast-forward to 100% and the subsequent fade-out\n clearTimerID = setTimeout(() => {\n setProgressToShow(null)\n }, transitionDuration * 2)\n }\n\n return () => {\n clearTimeout(clearTimerID)\n clearTimeout(delayTimerID)\n }\n }, [isTransitioning, transitionProgress])\n\n if (typeof progressToShow === 'number') {\n return (\n <div\n className={[baseClass, progressToShow === 1 && `${baseClass}--fade-out`]\n .filter(Boolean)\n .join(' ')}\n style={{\n // @ts-expect-error - TS doesn't like custom CSS properties\n '--transition-duration': `${transitionDuration}ms`,\n }}\n >\n <div\n className={`${baseClass}__progress`}\n style={{\n width: `${(progressToShow || 0) * 100}%`,\n }}\n />\n </div>\n )\n }\n\n return null\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AACA,OAAOC,KAAA,IAASC,SAAS,EAAEC,MAAM,QAAQ;AAEzC,SAASC,kBAAkB,QAAQ;AACnC,OAAO;AAEP,MAAMC,kBAAA,GAAqB;AAC3B,MAAMC,SAAA,GAAY;AAClB,MAAMC,YAAA,GAAe;AAErB;;;;;;;;;;;;;AAaA,OAAO,MAAMC,WAAA,GAAcA,CAAA;EAAA,MAAAC,CAAA,GAAAT,EAAA;EACzB;IAAAU,eAAA;IAAAC;EAAA,IAAgDP,kBAAA;EAChD,OAAAQ,cAAA,EAAAC,iBAAA,IAA4CZ,KAAA,CAAAa,QAAA,KAA8B;EAC1E,MAAAC,mBAAA,GAA4BZ,MAAA,KAAO;EAAA,IAAAa,EAAA;EAAA,IAAAC,EAAA;EAAA,IAAAR,CAAA,QAAAC,eAAA,IAAAD,CAAA,QAAAE,kBAAA;IAEzBK,EAAA,GAAAA,CAAA;MACJE,GAAA,CAAAA,YAAA;MACAC,GAAA,CAAAA,YAAA;MAAA,IAEAT,eAAA;QAAA,IACEK,mBAAA,CAAAK,OAAA;UACFD,YAAA,CAAAA,CAAA,CAAeA,aAAA,CAAAA,EAAA,CAAAA;YACbN,iBAAA,CAAkBF,kBAAA;YAClBI,mBAAA,CAAAK,OAAA;UAAA,GAAAb,YACC;QAHH;UAKAM,iBAAA,CAAkBF,kBAAA;QAAA;MAAA;QAGpBI,mBAAA,CAAAK,OAAA;QAIAP,iBAAA,
|
|
1
|
+
{"version":3,"file":"index.js","names":["c","_c","React","useEffect","useRef","useRouteTransition","transitionDuration","baseClass","initialDelay","ProgressBar","$","isTransitioning","transitionProgress","progressToShow","setProgressToShow","useState","shouldDelayProgress","t0","t1","clearTimerID","delayTimerID","current","_temp","clearTimeout","t2","t3","filter","Boolean","t4","join","t5","_jsx","className","style","children","width","currentProgress"],"sources":["../../../../src/providers/RouteTransition/ProgressBar/index.tsx"],"sourcesContent":["'use client'\nimport React, { useEffect, useRef } from 'react'\n\nimport { useRouteTransition } from '../index.js'\nimport './index.css'\n\nconst transitionDuration = 200\nconst baseClass = 'progress-bar'\nconst initialDelay = 150\n\n/**\n * Renders a progress bar that shows the progress of a route transition.\n * Place this at the root of your application, inside of the `RouteTransitionProvider`.\n * When a transition is triggered, the progress bar will show the progress of that transition and exit when the transition is complete.\n * @returns A progress bar that shows the progress of a route transition\n * @example\n * import { RouteTransitionProvider, ProgressBar, Link } from '@payloadcms/ui'\n * const App = () => (\n * <RouteTransitionProvider>\n * <ProgressBar />\n * <Link href=\"/somewhere\">Go Somewhere</Link>\n * </RouteTransitionProvider>\n */\nexport const ProgressBar = () => {\n const { isTransitioning, transitionProgress } = useRouteTransition()\n const [progressToShow, setProgressToShow] = React.useState<null | number>(null)\n const shouldDelayProgress = useRef(true)\n\n useEffect(() => {\n let clearTimerID: NodeJS.Timeout\n let delayTimerID: NodeJS.Timeout\n\n if (isTransitioning) {\n if (shouldDelayProgress.current) {\n delayTimerID = setTimeout(() => {\n setProgressToShow(transitionProgress)\n shouldDelayProgress.current = false\n }, initialDelay)\n } else {\n setProgressToShow(transitionProgress)\n }\n } else {\n shouldDelayProgress.current = true\n\n // Fast forward to 100% when the transition is complete\n // Then fade out the progress bar directly after\n setProgressToShow((currentProgress) => (currentProgress === null ? null : 1))\n\n // Wait for CSS transition to finish before hiding the progress bar\n // This includes both the fast-forward to 100% and the subsequent fade-out\n clearTimerID = setTimeout(() => {\n setProgressToShow(null)\n }, transitionDuration * 2)\n }\n\n return () => {\n clearTimeout(clearTimerID)\n clearTimeout(delayTimerID)\n }\n }, [isTransitioning, transitionProgress])\n\n if (typeof progressToShow === 'number') {\n return (\n <div\n className={[baseClass, progressToShow === 1 && `${baseClass}--fade-out`]\n .filter(Boolean)\n .join(' ')}\n style={{\n // @ts-expect-error - TS doesn't like custom CSS properties\n '--transition-duration': `${transitionDuration}ms`,\n }}\n >\n <div\n className={`${baseClass}__progress`}\n style={{\n width: `${(progressToShow || 0) * 100}%`,\n }}\n />\n </div>\n )\n }\n\n return null\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AACA,OAAOC,KAAA,IAASC,SAAS,EAAEC,MAAM,QAAQ;AAEzC,SAASC,kBAAkB,QAAQ;AACnC,OAAO;AAEP,MAAMC,kBAAA,GAAqB;AAC3B,MAAMC,SAAA,GAAY;AAClB,MAAMC,YAAA,GAAe;AAErB;;;;;;;;;;;;;AAaA,OAAO,MAAMC,WAAA,GAAcA,CAAA;EAAA,MAAAC,CAAA,GAAAT,EAAA;EACzB;IAAAU,eAAA;IAAAC;EAAA,IAAgDP,kBAAA;EAChD,OAAAQ,cAAA,EAAAC,iBAAA,IAA4CZ,KAAA,CAAAa,QAAA,KAA8B;EAC1E,MAAAC,mBAAA,GAA4BZ,MAAA,KAAO;EAAA,IAAAa,EAAA;EAAA,IAAAC,EAAA;EAAA,IAAAR,CAAA,QAAAC,eAAA,IAAAD,CAAA,QAAAE,kBAAA;IAEzBK,EAAA,GAAAA,CAAA;MACJE,GAAA,CAAAA,YAAA;MACAC,GAAA,CAAAA,YAAA;MAAA,IAEAT,eAAA;QAAA,IACEK,mBAAA,CAAAK,OAAA;UACFD,YAAA,CAAAA,CAAA,CAAeA,aA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H,IAAA,CAAC;UAAAC,SAAA,EACY,GAAAzB,SAAA,YAAwB;UAAA0B,KAAA;YAAAE,KAAA,EAE1B,GAAG,CAACtB,cAAA,KAAkB,OAAK;UAAM;QAAA,C;;;;;;;;WAZ9CiB,E;;;CAoBN;AA5D2B,SAAAR,MAAAc,eAAA;EAAA,OAuBmBA,eAAA,SAAoB,WAAc;AAAA","ignoreList":[]}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// @vitest-environment happy-dom
|
|
2
|
+
import { act, createElement, useEffect } from 'react';
|
|
3
|
+
import { createRoot } from 'react-dom/client';
|
|
4
|
+
import { afterEach, beforeEach, expect, test, vi } from 'vitest';
|
|
5
|
+
import { RouteTransitionProvider, useRouteTransition } from '../index.js';
|
|
6
|
+
import { ProgressBar } from './index.js';
|
|
7
|
+
let container;
|
|
8
|
+
let root;
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
globalThis.IS_REACT_ACT_ENVIRONMENT = true;
|
|
11
|
+
container = document.createElement('div');
|
|
12
|
+
document.body.appendChild(container);
|
|
13
|
+
root = createRoot(container);
|
|
14
|
+
});
|
|
15
|
+
afterEach(() => {
|
|
16
|
+
act(() => root.unmount());
|
|
17
|
+
container.remove();
|
|
18
|
+
vi.useRealTimers();
|
|
19
|
+
});
|
|
20
|
+
test('does not show progress for transitions that finish before the initial delay', async () => {
|
|
21
|
+
vi.useFakeTimers();
|
|
22
|
+
const FastTransition = () => {
|
|
23
|
+
const {
|
|
24
|
+
holdRouteTransition
|
|
25
|
+
} = useRouteTransition();
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
const releaseRouteTransition = holdRouteTransition();
|
|
28
|
+
const timeout = setTimeout(releaseRouteTransition, 50);
|
|
29
|
+
return () => {
|
|
30
|
+
clearTimeout(timeout);
|
|
31
|
+
releaseRouteTransition();
|
|
32
|
+
};
|
|
33
|
+
}, [holdRouteTransition]);
|
|
34
|
+
return null;
|
|
35
|
+
};
|
|
36
|
+
await act(async () => {
|
|
37
|
+
root.render(createElement(RouteTransitionProvider, null, createElement(ProgressBar), createElement(FastTransition)));
|
|
38
|
+
});
|
|
39
|
+
await act(async () => {
|
|
40
|
+
await vi.advanceTimersByTimeAsync(50);
|
|
41
|
+
});
|
|
42
|
+
expect(container.querySelector('.progress-bar')).toBeNull();
|
|
43
|
+
});
|
|
44
|
+
//# sourceMappingURL=index.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.spec.js","names":["act","createElement","useEffect","createRoot","afterEach","beforeEach","expect","test","vi","RouteTransitionProvider","useRouteTransition","ProgressBar","container","root","globalThis","IS_REACT_ACT_ENVIRONMENT","document","body","appendChild","unmount","remove","useRealTimers","useFakeTimers","FastTransition","holdRouteTransition","releaseRouteTransition","timeout","setTimeout","clearTimeout","render","advanceTimersByTimeAsync","querySelector","toBeNull"],"sources":["../../../../src/providers/RouteTransition/ProgressBar/index.spec.ts"],"sourcesContent":["// @vitest-environment happy-dom\n\nimport { act, createElement, useEffect } from 'react'\nimport { createRoot, type Root } from 'react-dom/client'\nimport { afterEach, beforeEach, expect, test, vi } from 'vitest'\n\nimport { RouteTransitionProvider, useRouteTransition } from '../index.js'\nimport { ProgressBar } from './index.js'\n\nlet container: HTMLDivElement\nlet root: Root\n\nbeforeEach(() => {\n globalThis.IS_REACT_ACT_ENVIRONMENT = true\n container = document.createElement('div')\n document.body.appendChild(container)\n root = createRoot(container)\n})\n\nafterEach(() => {\n act(() => root.unmount())\n container.remove()\n vi.useRealTimers()\n})\n\ntest('does not show progress for transitions that finish before the initial delay', async () => {\n vi.useFakeTimers()\n\n const FastTransition = () => {\n const { holdRouteTransition } = useRouteTransition()\n\n useEffect(() => {\n const releaseRouteTransition = holdRouteTransition()\n const timeout = setTimeout(releaseRouteTransition, 50)\n\n return () => {\n clearTimeout(timeout)\n releaseRouteTransition()\n }\n }, [holdRouteTransition])\n\n return null\n }\n\n await act(async () => {\n root.render(\n createElement(\n RouteTransitionProvider,\n null,\n createElement(ProgressBar),\n createElement(FastTransition),\n ),\n )\n })\n\n await act(async () => {\n await vi.advanceTimersByTimeAsync(50)\n })\n\n expect(container.querySelector('.progress-bar')).toBeNull()\n})\n"],"mappings":"AAAA;AAEA,SAASA,GAAG,EAAEC,aAAa,EAAEC,SAAS,QAAQ;AAC9C,SAASC,UAAU,QAAmB;AACtC,SAASC,SAAS,EAAEC,UAAU,EAAEC,MAAM,EAAEC,IAAI,EAAEC,EAAE,QAAQ;AAExD,SAASC,uBAAuB,EAAEC,kBAAkB,QAAQ;AAC5D,SAASC,WAAW,QAAQ;AAE5B,IAAIC,SAAA;AACJ,IAAIC,IAAA;AAEJR,UAAA,CAAW;EACTS,UAAA,CAAWC,wBAAwB,GAAG;EACtCH,SAAA,GAAYI,QAAA,CAASf,aAAa,CAAC;EACnCe,QAAA,CAASC,IAAI,CAACC,WAAW,CAACN,SAAA;EAC1BC,IAAA,GAAOV,UAAA,CAAWS,SAAA;AACpB;AAEAR,SAAA,CAAU;EACRJ,GAAA,CAAI,MAAMa,IAAA,CAAKM,OAAO;EACtBP,SAAA,CAAUQ,MAAM;EAChBZ,EAAA,CAAGa,aAAa;AAClB;AAEAd,IAAA,CAAK,+EAA+E;EAClFC,EAAA,CAAGc,aAAa;EAEhB,MAAMC,cAAA,GAAiBA,CAAA;IACrB,MAAM;MAAEC;IAAmB,CAAE,GAAGd,kBAAA;IAEhCR,SAAA,CAAU;MACR,MAAMuB,sBAAA,GAAyBD,mBAAA;MAC/B,MAAME,OAAA,GAAUC,UAAA,CAAWF,sBAAA,EAAwB;MAEnD,OAAO;QACLG,YAAA,CAAaF,OAAA;QACbD,sBAAA;MACF;IACF,GAAG,CAACD,mBAAA,CAAoB;IAExB,OAAO;EACT;EAEA,MAAMxB,GAAA,CAAI;IACRa,IAAA,CAAKgB,MAAM,CACT5B,aAAA,CACEQ,uBAAA,EACA,MACAR,aAAA,CAAcU,WAAA,GACdV,aAAA,CAAcsB,cAAA;EAGpB;EAEA,MAAMvB,GAAA,CAAI;IACR,MAAMQ,EAAA,CAAGsB,wBAAwB,CAAC;EACpC;EAEAxB,MAAA,CAAOM,SAAA,CAAUmB,aAAa,CAAC,kBAAkBC,QAAQ;AAC3D","ignoreList":[]}
|
|
@@ -21,8 +21,8 @@ type RouteTransitionProps = {
|
|
|
21
21
|
};
|
|
22
22
|
type StartRouteTransition = (callback?: () => void) => void;
|
|
23
23
|
type RouteTransitionContextValue = {
|
|
24
|
-
/** Keeps the
|
|
25
|
-
|
|
24
|
+
/** Keeps the transition active until the returned release function is called. */
|
|
25
|
+
holdRouteTransition: () => () => void;
|
|
26
26
|
isTransitioning: boolean;
|
|
27
27
|
startRouteTransition: StartRouteTransition;
|
|
28
28
|
transitionProgress: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/RouteTransition/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAyE,MAAM,OAAO,CAAA;AAE7F;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,uBAAuB,EAAE,KAAK,CAAC,EAAE,CAAC,oBAAoB,CAqFlE,CAAA;AAED,KAAK,oBAAoB,GAAG;IAC1B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAC1B,CAAA;AAED,KAAK,oBAAoB,GAAG,CAAC,QAAQ,CAAC,EAAE,MAAM,IAAI,KAAK,IAAI,CAAA;AAE3D,KAAK,2BAA2B,GAAG;IACjC
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/RouteTransition/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAyE,MAAM,OAAO,CAAA;AAE7F;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,uBAAuB,EAAE,KAAK,CAAC,EAAE,CAAC,oBAAoB,CAqFlE,CAAA;AAED,KAAK,oBAAoB,GAAG;IAC1B,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CAC1B,CAAA;AAED,KAAK,oBAAoB,GAAG,CAAC,QAAQ,CAAC,EAAE,MAAM,IAAI,KAAK,IAAI,CAAA;AAE3D,KAAK,2BAA2B,GAAG;IACjC,iFAAiF;IACjF,mBAAmB,EAAE,MAAM,MAAM,IAAI,CAAA;IACrC,eAAe,EAAE,OAAO,CAAA;IACxB,oBAAoB,EAAE,oBAAoB,CAAA;IAC1C,kBAAkB,EAAE,MAAM,CAAA;CAC3B,CAAA;AAcD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,kBAAkB,mCAA0C,CAAA"}
|
|
@@ -25,9 +25,9 @@ export const RouteTransitionProvider = t0 => {
|
|
|
25
25
|
children
|
|
26
26
|
} = t0;
|
|
27
27
|
const [isOptimisticallyTransitioning, setIsOptimisticallyTransitioning] = useOptimistic(false);
|
|
28
|
-
const [
|
|
28
|
+
const [activeRouteTransitionHolds, setActiveRouteTransitionHolds] = React.useState(0);
|
|
29
29
|
const [transitionProgress, setTransitionProgress] = React.useState(0);
|
|
30
|
-
const isTransitioning = isOptimisticallyTransitioning ||
|
|
30
|
+
const isTransitioning = isOptimisticallyTransitioning || activeRouteTransitionHolds > 0;
|
|
31
31
|
const transitionProgressRef = useRef(transitionProgress);
|
|
32
32
|
const timerID = useRef(null);
|
|
33
33
|
let t1;
|
|
@@ -86,26 +86,26 @@ export const RouteTransitionProvider = t0 => {
|
|
|
86
86
|
let t5;
|
|
87
87
|
if ($[6] === Symbol.for("react.memo_cache_sentinel")) {
|
|
88
88
|
t5 = () => {
|
|
89
|
-
let
|
|
90
|
-
|
|
89
|
+
let hasReleased = false;
|
|
90
|
+
setActiveRouteTransitionHolds(_temp);
|
|
91
91
|
return () => {
|
|
92
|
-
if (
|
|
92
|
+
if (hasReleased) {
|
|
93
93
|
return;
|
|
94
94
|
}
|
|
95
|
-
|
|
96
|
-
|
|
95
|
+
hasReleased = true;
|
|
96
|
+
setActiveRouteTransitionHolds(_temp2);
|
|
97
97
|
};
|
|
98
98
|
};
|
|
99
99
|
$[6] = t5;
|
|
100
100
|
} else {
|
|
101
101
|
t5 = $[6];
|
|
102
102
|
}
|
|
103
|
-
const
|
|
103
|
+
const holdRouteTransition = t5;
|
|
104
104
|
let t6;
|
|
105
105
|
if ($[7] !== children || $[8] !== isTransitioning || $[9] !== startRouteTransition || $[10] !== transitionProgress) {
|
|
106
106
|
t6 = _jsx(RouteTransitionContext, {
|
|
107
107
|
value: {
|
|
108
|
-
|
|
108
|
+
holdRouteTransition,
|
|
109
109
|
isTransitioning,
|
|
110
110
|
startRouteTransition,
|
|
111
111
|
transitionProgress
|
|
@@ -123,7 +123,7 @@ export const RouteTransitionProvider = t0 => {
|
|
|
123
123
|
return t6;
|
|
124
124
|
};
|
|
125
125
|
const RouteTransitionContext = /*#__PURE__*/React.createContext({
|
|
126
|
-
|
|
126
|
+
holdRouteTransition: () => () => undefined,
|
|
127
127
|
isTransitioning: false,
|
|
128
128
|
// Default implementation: just call the callback directly (no transition animation)
|
|
129
129
|
startRouteTransition: callback => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["c","_c","React","startTransition","useCallback","useEffect","useOptimistic","useRef","RouteTransitionProvider","t0","$","children","isOptimisticallyTransitioning","setIsOptimisticallyTransitioning","
|
|
1
|
+
{"version":3,"file":"index.js","names":["c","_c","React","startTransition","useCallback","useEffect","useOptimistic","useRef","RouteTransitionProvider","t0","$","children","isOptimisticallyTransitioning","setIsOptimisticallyTransitioning","activeRouteTransitionHolds","setActiveRouteTransitionHolds","useState","transitionProgress","setTransitionProgress","isTransitioning","transitionProgressRef","timerID","t1","Symbol","for","current","setInterval","newProgress","Math","random","pow","log","initiateProgress","t2","t3","clearInterval","t4","callback","startRouteTransition","t5","hasReleased","_temp","_temp2","holdRouteTransition","t6","_jsx","RouteTransitionContext","value","createContext","undefined","useRouteTransition","use","count","count_0","max"],"sources":["../../../src/providers/RouteTransition/index.tsx"],"sourcesContent":["'use client'\nimport React, { startTransition, useCallback, useEffect, useOptimistic, useRef } from 'react'\n\n/**\n * Route transitions are useful in showing immediate visual feedback to the user when navigating between pages. This is especially useful on slow networks when navigating to data heavy or process intensive pages.\n * To use route transitions, place the `RouteTransitionProvider` at the root of your application, outside of the `ProgressBar` component.\n * To trigger a route transition, use the `Link` component from `@payloadcms/ui`,\n * or wrap a callback function with the `startRouteTransition` method.\n * To gain access to the `RouteTransitionContext`, call the `useRouteTransition` hook in your component.\n * @returns A context provider with methods and state for transitioning between routes, including `isTransitioning`, `startRouteTransition`, and `transitionProgress`.\n * @example\n * import { RouteTransitionProvider, ProgressBar, Link } from '@payloadcms/ui'\n * const App = () => (\n * <RouteTransitionProvider>\n * <ProgressBar />\n * <Link href=\"/somewhere\">Go Somewhere</Link>\n * </RouteTransitionProvider>\n * )\n */\nexport const RouteTransitionProvider: React.FC<RouteTransitionProps> = ({ children }) => {\n const [isOptimisticallyTransitioning, setIsOptimisticallyTransitioning] = useOptimistic(false)\n const [activeRouteTransitionHolds, setActiveRouteTransitionHolds] = React.useState(0)\n const [transitionProgress, setTransitionProgress] = React.useState<number>(0)\n const isTransitioning = isOptimisticallyTransitioning || activeRouteTransitionHolds > 0\n\n const transitionProgressRef = useRef(transitionProgress)\n\n const timerID = useRef(null)\n\n const initiateProgress = useCallback(() => {\n timerID.current = setInterval(() => {\n // randomly update progress using an exponential curve\n // cap the progress to ensure it never fully reaches completion\n // accelerate quickly then decelerate slowly\n const maxProgress = 0.93\n const jumpFactor = 0.2 // lower to reduce jumps in progress\n const growthFactor = 0.75 // adjust to control acceleration\n const slowdownFactor = 0.75 // adjust to control deceleration\n\n const newProgress =\n transitionProgressRef.current +\n (maxProgress - transitionProgressRef.current) *\n Math.random() *\n jumpFactor *\n Math.pow(Math.log(1 + (1 - transitionProgressRef.current) * growthFactor), slowdownFactor)\n\n setTransitionProgress(newProgress)\n transitionProgressRef.current = newProgress\n }, 250) // every n ms, update progress\n }, [])\n\n useEffect(() => {\n setTransitionProgress(0)\n transitionProgressRef.current = 0\n\n if (isTransitioning) {\n initiateProgress()\n } else {\n if (timerID.current) {\n clearInterval(timerID.current)\n }\n }\n }, [isTransitioning, initiateProgress])\n\n const startRouteTransition: StartRouteTransition = useCallback(\n (callback?: () => void) => {\n startTransition(() => {\n setIsOptimisticallyTransitioning(true)\n\n if (typeof callback === 'function') {\n callback()\n }\n })\n },\n [setIsOptimisticallyTransitioning],\n )\n\n const holdRouteTransition = useCallback(() => {\n let hasReleased = false\n\n setActiveRouteTransitionHolds((count) => count + 1)\n\n return () => {\n if (hasReleased) {\n return\n }\n\n hasReleased = true\n setActiveRouteTransitionHolds((count) => Math.max(0, count - 1))\n }\n }, [])\n\n return (\n <RouteTransitionContext\n value={{\n holdRouteTransition,\n isTransitioning,\n startRouteTransition,\n transitionProgress,\n }}\n >\n {children}\n </RouteTransitionContext>\n )\n}\n\ntype RouteTransitionProps = {\n children: React.ReactNode\n}\n\ntype StartRouteTransition = (callback?: () => void) => void\n\ntype RouteTransitionContextValue = {\n /** Keeps the transition active until the returned release function is called. */\n holdRouteTransition: () => () => void\n isTransitioning: boolean\n startRouteTransition: StartRouteTransition\n transitionProgress: number\n}\n\nconst RouteTransitionContext = React.createContext<RouteTransitionContextValue>({\n holdRouteTransition: () => () => undefined,\n isTransitioning: false,\n // Default implementation: just call the callback directly (no transition animation)\n startRouteTransition: (callback) => {\n if (typeof callback === 'function') {\n callback()\n }\n },\n transitionProgress: 0,\n})\n\n/**\n * Use this hook to access the `RouteTransitionContext` provided by the `RouteTransitionProvider`.\n * To start a transition, fire the `startRouteTransition` method with a provided callback to run while the transition takes place.\n * @returns The `RouteTransitionContext` needed for transitioning between routes, including `isTransitioning`, `startRouteTransition`, and `transitionProgress`.\n * @example\n * 'use client'\n * import React, { useCallback } from 'react'\n * import { useTransition, useRouter } from '@payloadcms/ui'\n *\n * const MyComponent: React.FC = () => {\n * const router = useRouter()\n * const { startRouteTransition } = useRouteTransition()\n *\n * const redirectSomewhere = useCallback(() => {\n * startRouteTransition(() => router.push('/somew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