@payloadcms/ui 3.25.0-canary.fd53f68 → 3.26.0-canary.bbb3083
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 -3
- 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 +13 -2
- package/dist/elements/Autosave/index.js.map +1 -1
- package/dist/elements/BulkUpload/DiscardWithoutSaving/index.d.ts.map +1 -1
- package/dist/elements/BulkUpload/DiscardWithoutSaving/index.js +10 -30
- package/dist/elements/BulkUpload/DiscardWithoutSaving/index.js.map +1 -1
- package/dist/elements/BulkUpload/FormsManager/createFormData.d.ts +3 -2
- package/dist/elements/BulkUpload/FormsManager/createFormData.d.ts.map +1 -1
- package/dist/elements/BulkUpload/FormsManager/createFormData.js +19 -2
- package/dist/elements/BulkUpload/FormsManager/createFormData.js.map +1 -1
- package/dist/elements/BulkUpload/FormsManager/index.d.ts.map +1 -1
- package/dist/elements/BulkUpload/FormsManager/index.js +10 -3
- package/dist/elements/BulkUpload/FormsManager/index.js.map +1 -1
- package/dist/elements/DeleteMany/index.d.ts.map +1 -1
- package/dist/elements/DeleteMany/index.js +2 -2
- package/dist/elements/DeleteMany/index.js.map +1 -1
- package/dist/elements/DeleteMany/index.scss +16 -0
- package/dist/elements/EditMany/index.d.ts.map +1 -1
- package/dist/elements/EditMany/index.js +22 -14
- package/dist/elements/EditMany/index.js.map +1 -1
- package/dist/elements/EditMany/index.scss +5 -19
- package/dist/elements/Link/index.d.ts +9 -1
- package/dist/elements/Link/index.d.ts.map +1 -1
- package/dist/elements/Link/index.js +6 -0
- package/dist/elements/Link/index.js.map +1 -1
- package/dist/elements/ListControls/index.d.ts +8 -0
- package/dist/elements/ListControls/index.d.ts.map +1 -1
- package/dist/elements/ListControls/index.js +4 -20
- package/dist/elements/ListControls/index.js.map +1 -1
- package/dist/elements/ListDrawer/DrawerContent.d.ts.map +1 -1
- package/dist/elements/ListDrawer/DrawerContent.js +2 -1
- package/dist/elements/ListDrawer/DrawerContent.js.map +1 -1
- package/dist/elements/ListDrawer/Provider.d.ts +7 -1
- package/dist/elements/ListDrawer/Provider.d.ts.map +1 -1
- package/dist/elements/ListDrawer/Provider.js.map +1 -1
- package/dist/elements/ListSelection/index.d.ts +4 -0
- package/dist/elements/ListSelection/index.d.ts.map +1 -1
- package/dist/elements/ListSelection/index.js +44 -23
- package/dist/elements/ListSelection/index.js.map +1 -1
- package/dist/elements/ListSelection/index.scss +4 -0
- package/dist/elements/Logout/index.d.ts.map +1 -1
- package/dist/elements/Logout/index.js +4 -9
- package/dist/elements/Logout/index.js.map +1 -1
- package/dist/elements/PublishMany/index.d.ts +1 -0
- package/dist/elements/PublishMany/index.d.ts.map +1 -1
- package/dist/elements/PublishMany/index.js +3 -2
- package/dist/elements/PublishMany/index.js.map +1 -1
- package/dist/elements/PublishMany/index.scss +21 -0
- package/dist/elements/TableColumns/RenderDefaultCell/index.d.ts.map +1 -1
- package/dist/elements/TableColumns/RenderDefaultCell/index.js +1 -0
- package/dist/elements/TableColumns/RenderDefaultCell/index.js.map +1 -1
- package/dist/elements/UnpublishMany/index.d.ts +1 -0
- package/dist/elements/UnpublishMany/index.d.ts.map +1 -1
- package/dist/elements/UnpublishMany/index.js +3 -2
- package/dist/elements/UnpublishMany/index.js.map +1 -1
- package/dist/elements/UnpublishMany/index.scss +21 -0
- package/dist/elements/WhereBuilder/field-types.d.ts.map +1 -1
- package/dist/elements/WhereBuilder/field-types.js +9 -5
- package/dist/elements/WhereBuilder/field-types.js.map +1 -1
- package/dist/elements/WhereBuilder/index.d.ts.map +1 -1
- package/dist/elements/WhereBuilder/index.js +11 -10
- package/dist/elements/WhereBuilder/index.js.map +1 -1
- package/dist/exports/client/index.d.ts +3 -1
- 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 -4
- package/dist/fields/JSON/index.d.ts.map +1 -1
- package/dist/fields/JSON/index.js +16 -12
- package/dist/fields/JSON/index.js.map +1 -1
- package/dist/fields/Upload/Input.js +13 -13
- package/dist/fields/Upload/Input.js.map +1 -1
- package/dist/forms/Form/context.d.ts +14 -4
- package/dist/forms/Form/context.d.ts.map +1 -1
- package/dist/forms/Form/context.js +16 -4
- package/dist/forms/Form/context.js.map +1 -1
- package/dist/forms/Form/fieldReducer.d.ts.map +1 -1
- package/dist/forms/Form/fieldReducer.js +30 -14
- package/dist/forms/Form/fieldReducer.js.map +1 -1
- package/dist/forms/Form/index.d.ts.map +1 -1
- package/dist/forms/Form/index.js +39 -10
- 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 -1
- package/dist/forms/Form/types.d.ts.map +1 -1
- package/dist/forms/Form/types.js.map +1 -1
- package/dist/forms/Submit/index.d.ts.map +1 -1
- package/dist/forms/Submit/index.js +3 -2
- package/dist/forms/Submit/index.js.map +1 -1
- package/dist/forms/fieldSchemasToFormState/renderField.d.ts.map +1 -1
- package/dist/forms/fieldSchemasToFormState/renderField.js +2 -0
- package/dist/forms/fieldSchemasToFormState/renderField.js.map +1 -1
- package/dist/forms/useField/index.d.ts +1 -1
- package/dist/forms/useField/index.js +1 -1
- package/dist/forms/useField/index.js.map +1 -1
- package/dist/providers/Root/index.d.ts.map +1 -1
- package/dist/providers/Root/index.js +4 -1
- package/dist/providers/Root/index.js.map +1 -1
- package/dist/providers/UploadHandlers/index.d.ts +21 -0
- package/dist/providers/UploadHandlers/index.d.ts.map +1 -0
- package/dist/providers/UploadHandlers/index.js +72 -0
- package/dist/providers/UploadHandlers/index.js.map +1 -0
- package/dist/styles.css +1 -1
- package/dist/utilities/renderTable.d.ts.map +1 -1
- package/dist/utilities/renderTable.js +2 -1
- package/dist/utilities/renderTable.js.map +1 -1
- package/dist/views/List/ListHeader/index.d.ts +2 -0
- package/dist/views/List/ListHeader/index.d.ts.map +1 -1
- package/dist/views/List/ListHeader/index.js +5 -0
- package/dist/views/List/ListHeader/index.js.map +1 -1
- package/dist/views/List/index.d.ts.map +1 -1
- package/dist/views/List/index.js +8 -19
- package/dist/views/List/index.js.map +1 -1
- package/package.json +6 -6
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,qBAsF5D"}
|
|
@@ -59,7 +59,6 @@ export function AppHeader({
|
|
|
59
59
|
window.removeEventListener('resize', checkIsScrollable);
|
|
60
60
|
};
|
|
61
61
|
}, [Actions]);
|
|
62
|
-
const LinkElement = Link || 'a';
|
|
63
62
|
const ActionComponents = Actions ? Object.values(Actions) : [];
|
|
64
63
|
return /*#__PURE__*/_jsxs("header", {
|
|
65
64
|
className: [baseClass, navOpen && `${baseClass}--nav-open`].filter(Boolean).join(' '),
|
|
@@ -96,14 +95,14 @@ export function AppHeader({
|
|
|
96
95
|
}), localization && /*#__PURE__*/_jsx(LocalizerLabel, {
|
|
97
96
|
ariaLabel: "invisible",
|
|
98
97
|
className: `${baseClass}__localizer-spacing`
|
|
99
|
-
}), /*#__PURE__*/_jsx(
|
|
98
|
+
}), /*#__PURE__*/_jsx(Link, {
|
|
100
99
|
"aria-label": t('authentication:account'),
|
|
101
100
|
className: `${baseClass}__account`,
|
|
102
101
|
href: formatAdminURL({
|
|
103
102
|
adminRoute,
|
|
104
103
|
path: accountRoute
|
|
105
104
|
}),
|
|
106
|
-
prefetch:
|
|
105
|
+
prefetch: false,
|
|
107
106
|
tabIndex: 0,
|
|
108
107
|
children: /*#__PURE__*/_jsx(RenderCustomComponent, {
|
|
109
108
|
CustomComponent: CustomAvatar,
|
|
@@ -1 +1 @@
|
|
|
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","
|
|
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","ActionComponents","Object","values","_jsxs","className","filter","Boolean","join","_jsx","tabIndex","ref","map","Action","i","length","ariaLabel","href","path","prefetch","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 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 <Link\n aria-label={t('authentication:account')}\n className={`${baseClass}__account`}\n href={formatAdminURL({ adminRoute, path: accountRoute })}\n prefetch={false}\n tabIndex={0}\n >\n <RenderCustomComponent CustomComponent={CustomAvatar} Fallback={<Account />} />\n </Link>\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,GA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CAAC/C,OAAA;;;;;qBAKzE+C,IAAA,CAACxC,SAAA;MAAUoC,SAAA,EAAW,GAAG9B,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;AAIzE,OAAO,KAAwD,MAAM,OAAO,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;AAgB5E,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,CAgUpC,CAAA"}
|
|
@@ -5,7 +5,7 @@ import { dequal } from 'dequal/lite';
|
|
|
5
5
|
import { reduceFieldsToValues, versionDefaults } from 'payload/shared';
|
|
6
6
|
import React, { useDeferredValue, useEffect, useRef, useState } from 'react';
|
|
7
7
|
import { toast } from 'sonner';
|
|
8
|
-
import { useAllFormFields, useForm, useFormModified, useFormSubmitted } from '../../forms/Form/context.js';
|
|
8
|
+
import { useAllFormFields, useForm, useFormModified, useFormProcessing, useFormSubmitted } from '../../forms/Form/context.js';
|
|
9
9
|
import { useDebounce } from '../../hooks/useDebounce.js';
|
|
10
10
|
import { useEffectEvent } from '../../hooks/useEffectEvent.js';
|
|
11
11
|
import { useConfig } from '../../providers/Config/index.js';
|
|
@@ -51,9 +51,11 @@ export const Autosave = ({
|
|
|
51
51
|
const {
|
|
52
52
|
dispatchFields,
|
|
53
53
|
isValid,
|
|
54
|
+
setBackgroundProcessing,
|
|
54
55
|
setIsValid,
|
|
55
56
|
setSubmitted
|
|
56
57
|
} = useForm();
|
|
58
|
+
const isFormProcessing = useFormProcessing();
|
|
57
59
|
const [fields] = useAllFormFields();
|
|
58
60
|
const modified = useFormModified();
|
|
59
61
|
const submitted = useFormSubmitted();
|
|
@@ -96,6 +98,12 @@ export const Autosave = ({
|
|
|
96
98
|
if (isProcessingRef.current || queueRef.current.length === 0) {
|
|
97
99
|
return;
|
|
98
100
|
}
|
|
101
|
+
// Do not autosave if the form is already processing (e.g. if the user clicked the publish button
|
|
102
|
+
// right before this autosave runs), as parallel updates could cause conflicts
|
|
103
|
+
if (isFormProcessing) {
|
|
104
|
+
queueRef.current = [];
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
99
107
|
if (!isValidRef.current) {
|
|
100
108
|
// Clear queue so we don't end up in an infinite loop
|
|
101
109
|
queueRef.current = [];
|
|
@@ -106,15 +114,18 @@ export const Autosave = ({
|
|
|
106
114
|
isProcessingRef.current = true;
|
|
107
115
|
const latestAction = queueRef.current[queueRef.current.length - 1];
|
|
108
116
|
queueRef.current = [];
|
|
117
|
+
setBackgroundProcessing(true);
|
|
109
118
|
try {
|
|
110
119
|
await latestAction();
|
|
111
120
|
} finally {
|
|
112
121
|
isProcessingRef.current = false;
|
|
122
|
+
setBackgroundProcessing(false);
|
|
113
123
|
if (queueRef.current.length > 0) {
|
|
114
124
|
await processQueue();
|
|
115
125
|
}
|
|
116
126
|
}
|
|
117
|
-
|
|
127
|
+
setBackgroundProcessing(false);
|
|
128
|
+
}, [isFormProcessing, setBackgroundProcessing]);
|
|
118
129
|
const autosaveTimeoutRef = useRef(null);
|
|
119
130
|
const handleAutosave = useEffectEvent(() => {
|
|
120
131
|
autosaveTimeoutRef.current = undefined;
|
|
@@ -1 +1 @@
|
|
|
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,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AW2F,IAAA,CAACnH,kBAAA,OAChC6C,MAAA,IAAUZ,CAAA,CAAE,mBACZ,CAACY,MAAA,IAAUJ,OAAA,CAAQ3B,cAAA,kBAClBqG,IAAA,CAACtI,KAAA,CAAMuI,QAAQ;gBACZnF,CAAA,CAAE,wBAAwB;QACzBoF,QAAA,EAAUvH,eAAA,CAAgB;UAAEwH,IAAA,EAAMxG,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","useFormProcessing","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","setBackgroundProcessing","setIsValid","setSubmitted","isFormProcessing","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 useFormProcessing,\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, setBackgroundProcessing, setIsValid, setSubmitted } = useForm()\n const isFormProcessing = useFormProcessing()\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 // Do not autosave if the form is already processing (e.g. if the user clicked the publish button\n // right before this autosave runs), as parallel updates could cause conflicts\n if (isFormProcessing) {\n queueRef.current = []\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 setBackgroundProcessing(true)\n try {\n await latestAction()\n } finally {\n isProcessingRef.current = false\n setBackgroundProcessing(false)\n if (queueRef.current.length > 0) {\n await processQueue()\n }\n }\n setBackgroundProcessing(false)\n }, [isFormProcessing, setBackgroundProcessing])\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,iBAAiB,EACjBC,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,oBAAA,GAAuB;AAS7B,OAAO,MAAMC,QAAA,GAA4BA,CAAC;EAAEC,EAAE;EAAEC,UAAU;EAAEC,MAAA,EAAQC;AAAS,CAAE;EAC7E,MAAM;IACJC,MAAA,EAAQ;MACNC,MAAA,EAAQ;QAAEC;MAAG,CAAE;MACfC;IAAS;EACV,CACF,GAAGlB,SAAA;EACJ,MAAM;IACJmB,SAAS;IACTC,qBAAqB;IACrBC,cAAc;IACdC,4BAA4B;IAC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AWhI,MAAA,CAAO;EACxB,MAAMiI,4BAAA,GAA+BjI,MAAA,CAAOL,oBAAA,CAAqBsE,eAAA;EACjE;EACAlE,SAAA,CAAU;IACR;;;IAGA,IAAI,CAACiI,QAAA,CAAS1D,OAAO,EAAE;MACrB0D,QAAA,CAAS1D,OAAO,GAAG;MACnB;IACF;IAEA;;;IAGA,MAAM4D,oBAAA,GAAuBvI,oBAAA,CAAqBsE,eAAA;IAClD,IAAIvE,MAAA,CAAOwI,oBAAA,EAAsBD,4BAAA,GAA+B;MAC9D;IACF;IAEAA,4BAAA,CAA6B3D,OAAO,GAAG4D,oBAAA;IAEvCtD,cAAA;EACF,GAAG,CAACX,eAAA,CAAgB;EAEpB;;;EAGAlE,SAAA,CAAU;IACR,OAAO;MACLmF,qBAAA;IACF;EACF,GAAG,EAAE;EAEL,MAAMA,qBAAA,GAAwBzE,cAAA,CAAe;IAC3C,IAAIkE,kBAAA,CAAmBL,OAAO,EAAE;MAC9B6D,YAAA,CAAaxD,kBAAA,CAAmBL,OAAO;IACzC;IAEAP,SAAA,CAAU;EACZ;EAEA,oBACEqE,KAAA,CAAC;IAAIC,SAAA,EAAWnH,SAAA;eACbyC,eAAA,IAAmB,CAAClB,OAAA,iBAAW6F,IAAA,CAACrH,kBAAA,OAChC+C,MAAA,IAAUZ,CAAA,CAAE,mBACZ,CAACY,MAAA,IAAUJ,OAAA,CAAQ7B,cAAA,kBAClBuG,IAAA,CAACzI,KAAA,CAAM0I,QAAQ;gBACZnF,CAAA,CAAE,wBAAwB;QACzBoF,QAAA,EAAUzH,eAAA,CAAgB;UAAE0H,IAAA,EAAM1G,cAAA;UAAgBoB;QAAK;MACzD;;;AAKV","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/elements/BulkUpload/DiscardWithoutSaving/index.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/elements/BulkUpload/DiscardWithoutSaving/index.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,MAAM,OAAO,CAAA;AAKzB,eAAO,MAAM,0BAA0B,wCAAwC,CAAA;AAE/E,wBAAgB,oBAAoB,sBAyBnC"}
|
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import { c as _c } from "react/compiler-runtime";
|
|
4
|
-
import { jsx as _jsx
|
|
4
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
5
|
import { useModal } from '@faceless-ui/modal';
|
|
6
6
|
import React from 'react';
|
|
7
7
|
import { useTranslation } from '../../../providers/Translation/index.js';
|
|
8
|
-
import {
|
|
9
|
-
import { FullscreenModal } from '../../FullscreenModal/index.js';
|
|
8
|
+
import { ConfirmationModal } from '../../ConfirmationModal/index.js';
|
|
10
9
|
import { useBulkUpload } from '../index.js';
|
|
11
10
|
export const discardBulkUploadModalSlug = 'bulk-upload--discard-without-saving';
|
|
12
|
-
const baseClass = 'leave-without-saving';
|
|
13
11
|
export function DiscardWithoutSaving() {
|
|
14
12
|
const $ = _c(9);
|
|
15
13
|
const {
|
|
@@ -47,32 +45,14 @@ export function DiscardWithoutSaving() {
|
|
|
47
45
|
const onConfirm = t1;
|
|
48
46
|
let t2;
|
|
49
47
|
if ($[5] !== onCancel || $[6] !== onConfirm || $[7] !== t) {
|
|
50
|
-
t2 = _jsx(
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
children: t("general:leaveWithoutSaving")
|
|
59
|
-
}), _jsx("p", {
|
|
60
|
-
children: t("general:changesNotSaved")
|
|
61
|
-
})]
|
|
62
|
-
}), _jsxs("div", {
|
|
63
|
-
className: `${baseClass}__controls`,
|
|
64
|
-
children: [_jsx(Button, {
|
|
65
|
-
buttonStyle: "secondary",
|
|
66
|
-
onClick: onCancel,
|
|
67
|
-
size: "large",
|
|
68
|
-
children: t("general:stayOnThisPage")
|
|
69
|
-
}), _jsx(Button, {
|
|
70
|
-
onClick: onConfirm,
|
|
71
|
-
size: "large",
|
|
72
|
-
children: t("general:leaveAnyway")
|
|
73
|
-
})]
|
|
74
|
-
})]
|
|
75
|
-
})
|
|
48
|
+
t2 = _jsx(ConfirmationModal, {
|
|
49
|
+
body: t("general:changesNotSaved"),
|
|
50
|
+
cancelLabel: t("general:stayOnThisPage"),
|
|
51
|
+
confirmLabel: t("general:leaveAnyway"),
|
|
52
|
+
heading: t("general:leaveWithoutSaving"),
|
|
53
|
+
modalSlug: discardBulkUploadModalSlug,
|
|
54
|
+
onCancel,
|
|
55
|
+
onConfirm
|
|
76
56
|
});
|
|
77
57
|
$[5] = onCancel;
|
|
78
58
|
$[6] = onConfirm;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["c","_c","useModal","React","useTranslation","
|
|
1
|
+
{"version":3,"file":"index.js","names":["c","_c","useModal","React","useTranslation","ConfirmationModal","useBulkUpload","discardBulkUploadModalSlug","DiscardWithoutSaving","$","t","closeModal","drawerSlug","t0","onCancel","t1","onConfirm","t2","_jsx","body","cancelLabel","confirmLabel","heading","modalSlug"],"sources":["../../../../src/elements/BulkUpload/DiscardWithoutSaving/index.tsx"],"sourcesContent":["'use client'\n\nimport { useModal } from '@faceless-ui/modal'\nimport React from 'react'\n\nimport { useTranslation } from '../../../providers/Translation/index.js'\nimport { ConfirmationModal } from '../../ConfirmationModal/index.js'\nimport { useBulkUpload } from '../index.js'\nexport const discardBulkUploadModalSlug = 'bulk-upload--discard-without-saving'\n\nexport function DiscardWithoutSaving() {\n const { t } = useTranslation()\n const { closeModal } = useModal()\n const { drawerSlug } = useBulkUpload()\n\n const onCancel = React.useCallback(() => {\n closeModal(discardBulkUploadModalSlug)\n }, [closeModal])\n\n const onConfirm = React.useCallback(() => {\n closeModal(drawerSlug)\n closeModal(discardBulkUploadModalSlug)\n }, [closeModal, drawerSlug])\n\n return (\n <ConfirmationModal\n body={t('general:changesNotSaved')}\n cancelLabel={t('general:stayOnThisPage')}\n confirmLabel={t('general:leaveAnyway')}\n heading={t('general:leaveWithoutSaving')}\n modalSlug={discardBulkUploadModalSlug}\n onCancel={onCancel}\n onConfirm={onConfirm}\n />\n )\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AAEA,SAASC,QAAQ,QAAQ;AACzB,OAAOC,KAAA,MAAW;AAElB,SAASC,cAAc,QAAQ;AAC/B,SAASC,iBAAiB,QAAQ;AAClC,SAASC,aAAa,QAAQ;AAC9B,OAAO,MAAMC,0BAAA,GAA6B;AAE1C,OAAO,SAAAC,qBAAA;EAAA,MAAAC,CAAA,GAAAR,EAAA;EACL;IAAAS;EAAA,IAAcN,cAAA;EACd;IAAAO;EAAA,IAAuBT,QAAA;EACvB;IAAAU;EAAA,IAAuBN,aAAA;EAAA,IAAAO,EAAA;EAAA,IAAAJ,CAAA,QAAAE,UAAA;IAEYE,EAAA,GAAAA,CAAA;MACjCF,UAAA,CAAAJ,0BAAW;IAAA;IACbE,CAAA,MAAAE,UAAA;IAAAF,CAAA,MAAAI,EAAA;EAAA;IAAAA,EAAA,GAAAJ,CAAA;EAAA;EAFA,MAAAK,QAAA,GAAiBD,EAEF;EAAA,IAAAE,EAAA;EAAA,IAAAN,CAAA,QAAAE,UAAA,IAAAF,CAAA,QAAAG,UAAA;IAEqBG,EAAA,GAAAA,CAAA;MAClCJ,UAAA,CAAWC,UAAA;MACXD,UAAA,CAAAJ,0BAAW;IAAA;IACbE,CAAA,MAAAE,UAAA;IAAAF,CAAA,MAAAG,UAAA;IAAAH,CAAA,MAAAM,EAAA;EAAA;IAAAA,EAAA,GAAAN,CAAA;EAAA;EAHA,MAAAO,SAAA,GAAkBD,EAGS;EAAA,IAAAE,EAAA;EAAA,IAAAR,CAAA,QAAAK,QAAA,IAAAL,CAAA,QAAAO,SAAA,IAAAP,CAAA,QAAAC,CAAA;IAGzBO,EAAA,GAAAC,IAAA,CAAAb,iBAAA;MAAAc,IAAA,EACQT,CAAA,CAAE;MAAAU,WAAA,EACKV,CAAA,CAAE;MAAAW,YAAA,EACDX,CAAA,CAAE;MAAAY,OAAA,EACPZ,CAAA,CAAE;MAAAa,SAAA,EAAAhB,0BAAA;MAAAO,QAAA;MAAAE;IAAA,C;;;;;;;;SAJbC,E","ignoreList":[]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import type { FormState } from 'payload';
|
|
2
|
-
|
|
1
|
+
import type { CollectionSlug, FormState } from 'payload';
|
|
2
|
+
import type { UploadHandlersContext } from '../../../providers/UploadHandlers/index.js';
|
|
3
|
+
export declare function createFormData(formState: FormState, overrides: Record<string, any>, collectionSlug: CollectionSlug, uploadHandler: ReturnType<UploadHandlersContext['getUploadHandler']>): Promise<FormData>;
|
|
3
4
|
//# sourceMappingURL=createFormData.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createFormData.d.ts","sourceRoot":"","sources":["../../../../src/elements/BulkUpload/FormsManager/createFormData.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"createFormData.d.ts","sourceRoot":"","sources":["../../../../src/elements/BulkUpload/FormsManager/createFormData.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,SAAS,CAAA;AAKxD,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4CAA4C,CAAA;AAEvF,wBAAsB,cAAc,CAClC,SAAS,EAAE,SAAc,EACzB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAM,EACnC,cAAc,EAAE,cAAc,EAC9B,aAAa,EAAE,UAAU,CAAC,qBAAqB,CAAC,kBAAkB,CAAC,CAAC,qBAwCrE"}
|
|
@@ -1,11 +1,28 @@
|
|
|
1
1
|
import { serialize } from 'object-to-formdata';
|
|
2
2
|
import { reduceFieldsToValues } from 'payload/shared';
|
|
3
|
-
export function createFormData(formState = {}, overrides = {}) {
|
|
3
|
+
export async function createFormData(formState = {}, overrides = {}, collectionSlug, uploadHandler) {
|
|
4
4
|
const data = reduceFieldsToValues(formState, true);
|
|
5
|
-
|
|
5
|
+
let file = data?.file;
|
|
6
6
|
if (file) {
|
|
7
7
|
delete data.file;
|
|
8
8
|
}
|
|
9
|
+
let clientUploadContext = null;
|
|
10
|
+
if (typeof uploadHandler === 'function') {
|
|
11
|
+
let filename = file.name;
|
|
12
|
+
clientUploadContext = await uploadHandler({
|
|
13
|
+
file,
|
|
14
|
+
updateFilename: value => {
|
|
15
|
+
filename = value;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
file = JSON.stringify({
|
|
19
|
+
clientUploadContext,
|
|
20
|
+
collectionSlug,
|
|
21
|
+
filename,
|
|
22
|
+
mimeType: file.type,
|
|
23
|
+
size: file.size
|
|
24
|
+
});
|
|
25
|
+
}
|
|
9
26
|
const dataWithOverrides = {
|
|
10
27
|
...data,
|
|
11
28
|
...overrides
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createFormData.js","names":["serialize","reduceFieldsToValues","createFormData","formState","overrides","data","file","
|
|
1
|
+
{"version":3,"file":"createFormData.js","names":["serialize","reduceFieldsToValues","createFormData","formState","overrides","collectionSlug","uploadHandler","data","file","clientUploadContext","filename","name","updateFilename","value","JSON","stringify","mimeType","type","size","dataWithOverrides","dataToSerialize","_payload","indices","nullsAsUndefineds"],"sources":["../../../../src/elements/BulkUpload/FormsManager/createFormData.ts"],"sourcesContent":["import type { CollectionSlug, FormState } from 'payload'\n\nimport { serialize } from 'object-to-formdata'\nimport { reduceFieldsToValues } from 'payload/shared'\n\nimport type { UploadHandlersContext } from '../../../providers/UploadHandlers/index.js'\n\nexport async function createFormData(\n formState: FormState = {},\n overrides: Record<string, any> = {},\n collectionSlug: CollectionSlug,\n uploadHandler: ReturnType<UploadHandlersContext['getUploadHandler']>,\n) {\n const data = reduceFieldsToValues(formState, true)\n let file = data?.file\n\n if (file) {\n delete data.file\n }\n\n let clientUploadContext = null\n\n if (typeof uploadHandler === 'function') {\n let filename = file.name\n clientUploadContext = await uploadHandler({\n file,\n updateFilename: (value) => {\n filename = value\n },\n })\n\n file = JSON.stringify({\n clientUploadContext,\n collectionSlug,\n filename,\n mimeType: file.type,\n size: file.size,\n })\n }\n\n const dataWithOverrides = {\n ...data,\n ...overrides,\n }\n\n const dataToSerialize = {\n _payload: JSON.stringify(dataWithOverrides),\n file,\n }\n\n return serialize(dataToSerialize, { indices: true, nullsAsUndefineds: false })\n}\n"],"mappings":"AAEA,SAASA,SAAS,QAAQ;AAC1B,SAASC,oBAAoB,QAAQ;AAIrC,OAAO,eAAeC,eACpBC,SAAA,GAAuB,CAAC,CAAC,EACzBC,SAAA,GAAiC,CAAC,CAAC,EACnCC,cAA8B,EAC9BC,aAAoE;EAEpE,MAAMC,IAAA,GAAON,oBAAA,CAAqBE,SAAA,EAAW;EAC7C,IAAIK,IAAA,GAAOD,IAAA,EAAMC,IAAA;EAEjB,IAAIA,IAAA,EAAM;IACR,OAAOD,IAAA,CAAKC,IAAI;EAClB;EAEA,IAAIC,mBAAA,GAAsB;EAE1B,IAAI,OAAOH,aAAA,KAAkB,YAAY;IACvC,IAAII,QAAA,GAAWF,IAAA,CAAKG,IAAI;IACxBF,mBAAA,GAAsB,MAAMH,aAAA,CAAc;MACxCE,IAAA;MACAI,cAAA,EAAiBC,KAAA;QACfH,QAAA,GAAWG,KAAA;MACb;IACF;IAEAL,IAAA,GAAOM,IAAA,CAAKC,SAAS,CAAC;MACpBN,mBAAA;MACAJ,cAAA;MACAK,QAAA;MACAM,QAAA,EAAUR,IAAA,CAAKS,IAAI;MACnBC,IAAA,EAAMV,IAAA,CAAKU;IACb;EACF;EAEA,MAAMC,iBAAA,GAAoB;IACxB,GAAGZ,IAAI;IACP,GAAGH;EACL;EAEA,MAAMgB,eAAA,GAAkB;IACtBC,QAAA,EAAUP,IAAA,CAAKC,SAAS,CAACI,iBAAA;IACzBX;EACF;EAEA,OAAOR,SAAA,CAAUoB,eAAA,EAAiB;IAAEE,OAAA,EAAS;IAAMC,iBAAA,EAAmB;EAAM;AAC9E","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/elements/BulkUpload/FormsManager/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAa,4BAA4B,EAAE,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/elements/BulkUpload/FormsManager/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAa,4BAA4B,EAAE,MAAM,SAAS,CAAA;AAK3F,OAAO,KAAK,MAAM,OAAO,CAAA;AAGzB,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AAgBzC,KAAK,mBAAmB,GAAG;IACzB,QAAQ,CAAC,WAAW,EAAE,KAAK,CAAC,aAAa,CAAC,CAAA;IAC1C,QAAQ,CAAC,QAAQ,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IACxD,QAAQ,CAAC,cAAc,EAAE,CACvB,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACtC,gBAAgB,CAAC,EAAE,MAAM,IAAI,KAC1B,OAAO,CAAC,IAAI,CAAC,CAAA;IAClB,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAA;IAC/B,QAAQ,CAAC,cAAc,CAAC,EAAE,4BAA4B,CAAA;IACtD,QAAQ,CAAC,aAAa,EAAE,aAAa,CAAA;IACrC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,OAAO,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m';
|
|
6
7
|
import React from 'react';
|
|
7
8
|
import { toast } from 'sonner';
|
|
@@ -10,6 +11,7 @@ import { useConfig } from '../../../providers/Config/index.js';
|
|
|
10
11
|
import { useLocale } from '../../../providers/Locale/index.js';
|
|
11
12
|
import { useServerFunctions } from '../../../providers/ServerFunctions/index.js';
|
|
12
13
|
import { useTranslation } from '../../../providers/Translation/index.js';
|
|
14
|
+
import { useUploadHandlers } from '../../../providers/UploadHandlers/index.js';
|
|
13
15
|
import { hasSavePermission as getHasSavePermission } from '../../../utilities/hasSavePermission.js';
|
|
14
16
|
import { LoadingOverlay } from '../../Loading/index.js';
|
|
15
17
|
import { useLoadingOverlay } from '../../LoadingOverlay/index.js';
|
|
@@ -67,6 +69,9 @@ export function FormsManagerProvider({
|
|
|
67
69
|
getDocumentSlots,
|
|
68
70
|
getFormState
|
|
69
71
|
} = useServerFunctions();
|
|
72
|
+
const {
|
|
73
|
+
getUploadHandler
|
|
74
|
+
} = useUploadHandlers();
|
|
70
75
|
const [documentSlots, setDocumentSlots] = React.useState({});
|
|
71
76
|
const [hasSubmitted, setHasSubmitted] = React.useState(false);
|
|
72
77
|
const [docPermissions, setDocPermissions] = React.useState();
|
|
@@ -96,7 +101,7 @@ export function FormsManagerProvider({
|
|
|
96
101
|
for (let i = 0; i < formsCount; i++) {
|
|
97
102
|
const file = formsRef.current[i].formState.file.value;
|
|
98
103
|
// Skip if already processed
|
|
99
|
-
if (processedFiles.current.has(file) || !file) {
|
|
104
|
+
if (processedFiles.current.has(file) || !file || !isImage(file.type)) {
|
|
100
105
|
continue;
|
|
101
106
|
}
|
|
102
107
|
processedFiles.current.add(file);
|
|
@@ -263,7 +268,9 @@ export function FormsManagerProvider({
|
|
|
263
268
|
total: currentForms.length
|
|
264
269
|
}));
|
|
265
270
|
const req = await fetch(actionURL, {
|
|
266
|
-
body: createFormData(form_0.formState, overrides
|
|
271
|
+
body: await createFormData(form_0.formState, overrides, collectionSlug, getUploadHandler({
|
|
272
|
+
collectionSlug
|
|
273
|
+
})),
|
|
267
274
|
method: 'POST'
|
|
268
275
|
});
|
|
269
276
|
const json_0 = await req.json();
|
|
@@ -336,7 +343,7 @@ export function FormsManagerProvider({
|
|
|
336
343
|
}) => acc + errorCount_2, 0)
|
|
337
344
|
}
|
|
338
345
|
});
|
|
339
|
-
}, [actionURL, activeIndex, forms, onSuccess, t, closeModal, drawerSlug]);
|
|
346
|
+
}, [actionURL, activeIndex, forms, onSuccess, collectionSlug, getUploadHandler, t, closeModal, drawerSlug]);
|
|
340
347
|
const bulkUpdateForm = React.useCallback(async (updatedFields, afterStateUpdate) => {
|
|
341
348
|
for (let i_2 = 0; i_2 < forms.length; i_2++) {
|
|
342
349
|
Object.entries(updatedFields).forEach(([path, value]) => {
|