@payloadcms/ui 3.51.0-internal.62eeed3 → 3.51.0-internal.886ed9f
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/Autosave/index.d.ts.map +1 -1
- package/dist/elements/Autosave/index.js +102 -28
- package/dist/elements/Autosave/index.js.map +1 -1
- package/dist/elements/CopyToClipboard/index.d.ts.map +1 -1
- package/dist/elements/CopyToClipboard/index.js +33 -78
- package/dist/elements/CopyToClipboard/index.js.map +1 -1
- package/dist/elements/CopyToClipboard/index.scss +8 -0
- package/dist/elements/DocumentDrawer/Provider.d.ts +0 -5
- package/dist/elements/DocumentDrawer/Provider.d.ts.map +1 -1
- package/dist/elements/DocumentDrawer/Provider.js.map +1 -1
- package/dist/elements/Upload/index.d.ts.map +1 -1
- package/dist/elements/Upload/index.js +14 -14
- package/dist/elements/Upload/index.js.map +1 -1
- package/dist/exports/client/index.js +24 -24
- package/dist/exports/client/index.js.map +3 -3
- package/dist/fields/Select/index.js +1 -2
- package/dist/fields/Select/index.js.map +1 -1
- package/dist/forms/Form/index.d.ts.map +1 -1
- package/dist/forms/Form/index.js +7 -17
- package/dist/forms/Form/index.js.map +1 -1
- package/dist/forms/Form/types.d.ts +2 -30
- package/dist/forms/Form/types.d.ts.map +1 -1
- package/dist/forms/Form/types.js.map +1 -1
- package/dist/providers/DocumentInfo/index.d.ts.map +1 -1
- package/dist/providers/DocumentInfo/index.js +8 -7
- package/dist/providers/DocumentInfo/index.js.map +1 -1
- package/dist/providers/DocumentInfo/types.d.ts +5 -16
- package/dist/providers/DocumentInfo/types.d.ts.map +1 -1
- package/dist/providers/DocumentInfo/types.js.map +1 -1
- package/dist/providers/DocumentTitle/index.d.ts.map +1 -1
- package/dist/providers/DocumentTitle/index.js +4 -4
- package/dist/providers/DocumentTitle/index.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/views/Edit/index.d.ts.map +1 -1
- package/dist/views/Edit/index.js +14 -21
- package/dist/views/Edit/index.js.map +1 -1
- package/package.json +5 -5
|
@@ -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;AAqB5E,OAAO,cAAc,CAAA;AAMrB,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,CA0SpC,CAAA"}
|
|
@@ -4,16 +4,19 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
4
4
|
import { dequal } from 'dequal/lite';
|
|
5
5
|
import { reduceFieldsToValues, versionDefaults } from 'payload/shared';
|
|
6
6
|
import React, { useDeferredValue, useEffect, useRef, useState } from 'react';
|
|
7
|
+
import { toast } from 'sonner';
|
|
7
8
|
import { useAllFormFields, useForm, useFormModified, useFormSubmitted } from '../../forms/Form/context.js';
|
|
8
9
|
import { useDebounce } from '../../hooks/useDebounce.js';
|
|
9
10
|
import { useEffectEvent } from '../../hooks/useEffectEvent.js';
|
|
10
11
|
import { useQueues } from '../../hooks/useQueues.js';
|
|
11
12
|
import { useConfig } from '../../providers/Config/index.js';
|
|
13
|
+
import { useDocumentEvents } from '../../providers/DocumentEvents/index.js';
|
|
12
14
|
import { useDocumentInfo } from '../../providers/DocumentInfo/index.js';
|
|
13
15
|
import { useLocale } from '../../providers/Locale/index.js';
|
|
14
16
|
import { useTranslation } from '../../providers/Translation/index.js';
|
|
15
17
|
import { formatTimeToNow } from '../../utilities/formatDocTitle/formatDateTitle.js';
|
|
16
18
|
import { reduceFieldsToValuesWithValidation } from '../../utilities/reduceFieldsToValuesWithValidation.js';
|
|
19
|
+
import { useDocumentDrawerContext } from '../DocumentDrawer/Provider.js';
|
|
17
20
|
import { LeaveWithoutSaving } from '../LeaveWithoutSaving/index.js';
|
|
18
21
|
import './index.scss';
|
|
19
22
|
const baseClass = 'autosave';
|
|
@@ -37,13 +40,22 @@ export const Autosave = ({
|
|
|
37
40
|
incrementVersionCount,
|
|
38
41
|
lastUpdateTime,
|
|
39
42
|
mostRecentVersionIsAutosaved,
|
|
43
|
+
setLastUpdateTime,
|
|
40
44
|
setMostRecentVersionIsAutosaved,
|
|
41
|
-
setUnpublishedVersionCount
|
|
45
|
+
setUnpublishedVersionCount,
|
|
46
|
+
updateSavedDocumentData
|
|
42
47
|
} = useDocumentInfo();
|
|
43
48
|
const {
|
|
49
|
+
onSave: onSaveFromDocumentDrawer
|
|
50
|
+
} = useDocumentDrawerContext();
|
|
51
|
+
const {
|
|
52
|
+
reportUpdate
|
|
53
|
+
} = useDocumentEvents();
|
|
54
|
+
const {
|
|
55
|
+
dispatchFields,
|
|
44
56
|
isValid,
|
|
45
57
|
setBackgroundProcessing,
|
|
46
|
-
|
|
58
|
+
setIsValid
|
|
47
59
|
} = useForm();
|
|
48
60
|
const [formState] = useAllFormFields();
|
|
49
61
|
const modified = useFormModified();
|
|
@@ -114,33 +126,95 @@ export const Autosave = ({
|
|
|
114
126
|
url = `${serverURL}${api}/globals/${entitySlug}?draft=true&autosave=true&locale=${localeRef.current}`;
|
|
115
127
|
method = 'POST';
|
|
116
128
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
129
|
+
if (url) {
|
|
130
|
+
if (modifiedRef.current) {
|
|
131
|
+
const {
|
|
132
|
+
data,
|
|
133
|
+
valid
|
|
134
|
+
} = reduceFieldsToValuesWithValidation(formStateRef.current, true);
|
|
135
|
+
data._status = 'draft';
|
|
136
|
+
const skipSubmission = submitted && !valid && versionsConfig?.drafts && versionsConfig?.drafts?.validate;
|
|
137
|
+
if (!skipSubmission) {
|
|
138
|
+
let res;
|
|
139
|
+
try {
|
|
140
|
+
res = await fetch(url, {
|
|
141
|
+
body: JSON.stringify(data),
|
|
142
|
+
credentials: 'include',
|
|
143
|
+
headers: {
|
|
144
|
+
'Accept-Language': i18n.language,
|
|
145
|
+
'Content-Type': 'application/json'
|
|
146
|
+
},
|
|
147
|
+
method
|
|
148
|
+
});
|
|
149
|
+
} catch (_err) {
|
|
150
|
+
// Swallow Error
|
|
151
|
+
}
|
|
152
|
+
const newDate = new Date();
|
|
153
|
+
// We need to log the time in order to figure out if we need to trigger the state off later
|
|
154
|
+
endTimestamp = newDate.getTime();
|
|
155
|
+
const json = await res.json();
|
|
156
|
+
if (res.status === 200) {
|
|
157
|
+
setLastUpdateTime(newDate.getTime());
|
|
158
|
+
reportUpdate({
|
|
159
|
+
id,
|
|
160
|
+
entitySlug,
|
|
161
|
+
updatedAt: newDate.toISOString()
|
|
162
|
+
});
|
|
163
|
+
// if onSaveFromDocumentDrawer is defined, call it
|
|
164
|
+
if (typeof onSaveFromDocumentDrawer === 'function') {
|
|
165
|
+
void onSaveFromDocumentDrawer({
|
|
166
|
+
...json,
|
|
167
|
+
operation: 'update'
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
if (!mostRecentVersionIsAutosaved) {
|
|
171
|
+
incrementVersionCount();
|
|
172
|
+
setMostRecentVersionIsAutosaved(true);
|
|
173
|
+
setUnpublishedVersionCount(prev => prev + 1);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
if (versionsConfig?.drafts && versionsConfig?.drafts?.validate && json?.errors) {
|
|
177
|
+
if (Array.isArray(json.errors)) {
|
|
178
|
+
const [fieldErrors, nonFieldErrors] = json.errors.reduce(([fieldErrs, nonFieldErrs], err) => {
|
|
179
|
+
const newFieldErrs = [];
|
|
180
|
+
const newNonFieldErrs = [];
|
|
181
|
+
if (err?.message) {
|
|
182
|
+
newNonFieldErrs.push(err);
|
|
183
|
+
}
|
|
184
|
+
if (Array.isArray(err?.data)) {
|
|
185
|
+
err.data.forEach(dataError => {
|
|
186
|
+
if (dataError?.field) {
|
|
187
|
+
newFieldErrs.push(dataError);
|
|
188
|
+
} else {
|
|
189
|
+
newNonFieldErrs.push(dataError);
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
return [[...fieldErrs, ...newFieldErrs], [...nonFieldErrs, ...newNonFieldErrs]];
|
|
194
|
+
}, [[], []]);
|
|
195
|
+
dispatchFields({
|
|
196
|
+
type: 'ADD_SERVER_ERRORS',
|
|
197
|
+
errors: fieldErrors
|
|
198
|
+
});
|
|
199
|
+
nonFieldErrors.forEach(err_0 => {
|
|
200
|
+
toast.error(err_0.message || i18n.t('error:unknown'));
|
|
201
|
+
});
|
|
202
|
+
setIsValid(false);
|
|
203
|
+
hideIndicator();
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
} else {
|
|
207
|
+
// If it's not an error then we can update the document data inside the context
|
|
208
|
+
const document = json?.doc || json?.result;
|
|
209
|
+
// Manually update the data since this function doesn't fire the `submit` function from useForm
|
|
210
|
+
if (document) {
|
|
211
|
+
setIsValid(true);
|
|
212
|
+
updateSavedDocumentData(document);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
hideIndicator();
|
|
216
|
+
}
|
|
139
217
|
}
|
|
140
|
-
const newDate = new Date();
|
|
141
|
-
// We need to log the time in order to figure out if we need to trigger the state off later
|
|
142
|
-
endTimestamp = newDate.getTime();
|
|
143
|
-
hideIndicator();
|
|
144
218
|
}
|
|
145
219
|
}
|
|
146
220
|
}, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["dequal","reduceFieldsToValues","versionDefaults","React","useDeferredValue","useEffect","useRef","useState","useAllFormFields","useForm","useFormModified","useFormSubmitted","useDebounce","useEffectEvent","useQueues","useConfig","useDocumentInfo","useLocale","useTranslation","formatTimeToNow","reduceFieldsToValuesWithValidation","LeaveWithoutSaving","baseClass","minimumAnimationTime","Autosave","id","collection","global","globalDoc","config","routes","api","serverURL","docConfig","incrementVersionCount","lastUpdateTime","mostRecentVersionIsAutosaved","setMostRecentVersionIsAutosaved","setUnpublishedVersionCount","isValid","setBackgroundProcessing","submit","formState","modified","submitted","code","locale","i18n","t","versionsConfig","versions","interval","autosaveInterval","drafts","autosave","validateOnDraft","Boolean","validate","_saving","setSaving","saving","debouncedFormState","formStateRef","modifiedRef","localeRef","current","queueTask","autosaveTimeoutRef","handleAutosave","undefined","startTimestamp","endTimestamp","hideIndicator","setTimeout","stopAutoSaveIndicator","Date","getTime","url","method","entitySlug","slug","valid","skipSubmission","result","action","context","disableFormWhileProcessing","disableSuccessStatus","overrides","_status","skipValidation","res","ok","prev","newDate","afterProcess","beforeProcess","didMount","previousDebouncedData","updatedAt","_","formData","__","prevFormData","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'\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 { useQueues } from '../../hooks/useQueues.js'\nimport { useConfig } from '../../providers/Config/index.js'\nimport { useDocumentInfo } from '../../providers/DocumentInfo/index.js'\nimport { useLocale } from '../../providers/Locale/index.js'\nimport { useTranslation } from '../../providers/Translation/index.js'\nimport { formatTimeToNow } from '../../utilities/formatDocTitle/formatDateTitle.js'\nimport { reduceFieldsToValuesWithValidation } from '../../utilities/reduceFieldsToValuesWithValidation.js'\nimport { LeaveWithoutSaving } from '../LeaveWithoutSaving/index.js'\nimport './index.scss'\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\n const {\n docConfig,\n incrementVersionCount,\n lastUpdateTime,\n mostRecentVersionIsAutosaved,\n setMostRecentVersionIsAutosaved,\n setUnpublishedVersionCount,\n } = useDocumentInfo()\n\n const { isValid, setBackgroundProcessing, submit } = useForm()\n\n const [formState] = 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\n const saving = useDeferredValue(_saving)\n\n const debouncedFormState = useDebounce(formState, interval)\n\n const formStateRef = useRef(formState)\n const modifiedRef = useRef(modified)\n const localeRef = useRef(locale)\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 formStateRef.current = formState\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 { queueTask } = useQueues()\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 queueTask(\n 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 const { valid } = reduceFieldsToValuesWithValidation(formStateRef.current, true)\n\n const skipSubmission =\n submitted && !valid && versionsConfig?.drafts && versionsConfig?.drafts?.validate\n\n if (!skipSubmission && modifiedRef.current && url) {\n const result = await submit({\n action: url,\n context: {\n incrementVersionCount: false,\n },\n disableFormWhileProcessing: false,\n disableSuccessStatus: true,\n method,\n overrides: {\n _status: 'draft',\n },\n skipValidation: versionsConfig?.drafts && !versionsConfig?.drafts?.validate,\n })\n\n if (result && result?.res?.ok && !mostRecentVersionIsAutosaved) {\n incrementVersionCount()\n setMostRecentVersionIsAutosaved(true)\n setUnpublishedVersionCount((prev) => prev + 1)\n }\n\n const newDate = new Date()\n\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 hideIndicator()\n }\n }\n },\n {\n afterProcess: () => {\n setBackgroundProcessing(false)\n },\n beforeProcess: () => {\n setBackgroundProcessing(true)\n },\n },\n )\n })\n\n const didMount = useRef(false)\n const previousDebouncedData = useRef(reduceFieldsToValues(debouncedFormState))\n\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 * Remove `updatedAt` from comparison as it changes on every autosave interval.\n */\n const { updatedAt: _, ...formData } = reduceFieldsToValues(debouncedFormState)\n const { updatedAt: __, ...prevFormData } = previousDebouncedData.current\n\n if (dequal(formData, prevFormData)) {\n return\n }\n\n previousDebouncedData.current = formData\n\n handleAutosave()\n }, [debouncedFormState])\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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C,eAAA,IAAmB,CAAChB,OAAA,iBAAWoE,IAAA,CAACtF,kBAAA,OAChCuC,MAAA,IAAUZ,CAAA,CAAE,mBACZ,CAACY,MAAA,IAAUJ,OAAA,CAAQrB,cAAA,kBAClBwE,IAAA,CAACxG,KAAA,CAAMyG,QAAQ;gBACZ5D,CAAA,CAAE,wBAAwB;QACzB6D,QAAA,EAAU1F,eAAA,CAAgB;UAAE2F,IAAA,EAAM3E,cAAA;UAAgBY;QAAK;MACzD;;;AAKV","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["dequal","reduceFieldsToValues","versionDefaults","React","useDeferredValue","useEffect","useRef","useState","toast","useAllFormFields","useForm","useFormModified","useFormSubmitted","useDebounce","useEffectEvent","useQueues","useConfig","useDocumentEvents","useDocumentInfo","useLocale","useTranslation","formatTimeToNow","reduceFieldsToValuesWithValidation","useDocumentDrawerContext","LeaveWithoutSaving","baseClass","minimumAnimationTime","Autosave","id","collection","global","globalDoc","config","routes","api","serverURL","docConfig","incrementVersionCount","lastUpdateTime","mostRecentVersionIsAutosaved","setLastUpdateTime","setMostRecentVersionIsAutosaved","setUnpublishedVersionCount","updateSavedDocumentData","onSave","onSaveFromDocumentDrawer","reportUpdate","dispatchFields","isValid","setBackgroundProcessing","setIsValid","formState","modified","submitted","code","locale","i18n","t","versionsConfig","versions","interval","autosaveInterval","drafts","autosave","validateOnDraft","Boolean","validate","_saving","setSaving","saving","debouncedFormState","formStateRef","modifiedRef","localeRef","current","queueTask","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","_err","newDate","json","status","updatedAt","toISOString","operation","prev","errors","Array","isArray","fieldErrors","nonFieldErrors","reduce","fieldErrs","nonFieldErrs","err","newFieldErrs","newNonFieldErrs","message","push","forEach","dataError","field","type","error","document","doc","result","afterProcess","beforeProcess","didMount","previousDebouncedData","_","formData","__","prevFormData","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 { useQueues } from '../../hooks/useQueues.js'\nimport { useConfig } from '../../providers/Config/index.js'\nimport { useDocumentEvents } from '../../providers/DocumentEvents/index.js'\nimport { useDocumentInfo } from '../../providers/DocumentInfo/index.js'\nimport { useLocale } from '../../providers/Locale/index.js'\nimport { useTranslation } from '../../providers/Translation/index.js'\nimport { formatTimeToNow } from '../../utilities/formatDocTitle/formatDateTitle.js'\nimport { reduceFieldsToValuesWithValidation } from '../../utilities/reduceFieldsToValuesWithValidation.js'\nimport { useDocumentDrawerContext } from '../DocumentDrawer/Provider.js'\nimport { LeaveWithoutSaving } from '../LeaveWithoutSaving/index.js'\nimport './index.scss'\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\n const {\n docConfig,\n incrementVersionCount,\n lastUpdateTime,\n mostRecentVersionIsAutosaved,\n setLastUpdateTime,\n setMostRecentVersionIsAutosaved,\n setUnpublishedVersionCount,\n updateSavedDocumentData,\n } = useDocumentInfo()\n\n const { onSave: onSaveFromDocumentDrawer } = useDocumentDrawerContext()\n\n const { reportUpdate } = useDocumentEvents()\n const { dispatchFields, isValid, setBackgroundProcessing, setIsValid } = useForm()\n\n const [formState] = 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\n const saving = useDeferredValue(_saving)\n\n const debouncedFormState = useDebounce(formState, interval)\n\n const formStateRef = useRef(formState)\n const modifiedRef = useRef(modified)\n const localeRef = useRef(locale)\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 formStateRef.current = formState\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 { queueTask } = useQueues()\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 queueTask(\n 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(formStateRef.current, true)\n\n data._status = 'draft'\n\n const skipSubmission =\n submitted && !valid && versionsConfig?.drafts && versionsConfig?.drafts?.validate\n\n if (!skipSubmission) {\n let res\n\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 (_err) {\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 const json = await res.json()\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 onSaveFromDocumentDrawer is defined, call it\n if (typeof onSaveFromDocumentDrawer === 'function') {\n void onSaveFromDocumentDrawer({\n ...json,\n operation: 'update',\n })\n }\n\n if (!mostRecentVersionIsAutosaved) {\n incrementVersionCount()\n setMostRecentVersionIsAutosaved(true)\n setUnpublishedVersionCount((prev) => prev + 1)\n }\n }\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 setIsValid(false)\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 updateSavedDocumentData(document)\n }\n }\n\n hideIndicator()\n }\n }\n }\n }\n },\n {\n afterProcess: () => {\n setBackgroundProcessing(false)\n },\n beforeProcess: () => {\n setBackgroundProcessing(true)\n },\n },\n )\n })\n\n const didMount = useRef(false)\n const previousDebouncedData = useRef(reduceFieldsToValues(debouncedFormState))\n\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 * Remove `updatedAt` from comparison as it changes on every autosave interval.\n */\n const { updatedAt: _, ...formData } = reduceFieldsToValues(debouncedFormState)\n const { updatedAt: __, ...prevFormData } = previousDebouncedData.current\n\n if (dequal(formData, prevFormData)) {\n return\n }\n\n previousDebouncedData.current = formData\n\n handleAutosave()\n }, [debouncedFormState])\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}\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]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/elements/CopyToClipboard/index.tsx"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/elements/CopyToClipboard/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAA2B,MAAM,OAAO,CAAA;AAK/C,OAAO,cAAc,CAAA;AAIrB,MAAM,MAAM,KAAK,GAAG;IAClB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAED,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAuC3C,CAAA"}
|
|
@@ -1,99 +1,54 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import { c as _c } from "react/compiler-runtime";
|
|
4
3
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
5
|
-
import React, { useState } from 'react';
|
|
4
|
+
import React, { useRef, useState } from 'react';
|
|
6
5
|
import { CopyIcon } from '../../icons/Copy/index.js';
|
|
7
6
|
import { useTranslation } from '../../providers/Translation/index.js';
|
|
8
7
|
import { Tooltip } from '../Tooltip/index.js';
|
|
9
8
|
import './index.scss';
|
|
10
9
|
const baseClass = 'copy-to-clipboard';
|
|
11
|
-
export const CopyToClipboard =
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
} = t0;
|
|
10
|
+
export const CopyToClipboard = ({
|
|
11
|
+
defaultMessage,
|
|
12
|
+
successMessage,
|
|
13
|
+
value
|
|
14
|
+
}) => {
|
|
15
|
+
const ref = useRef(null);
|
|
18
16
|
const [copied, setCopied] = useState(false);
|
|
19
17
|
const [hovered, setHovered] = useState(false);
|
|
20
18
|
const {
|
|
21
19
|
t
|
|
22
20
|
} = useTranslation();
|
|
23
21
|
if (value) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
let t2;
|
|
36
|
-
let t3;
|
|
37
|
-
if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
|
|
38
|
-
t2 = () => {
|
|
22
|
+
return /*#__PURE__*/_jsxs("button", {
|
|
23
|
+
className: baseClass,
|
|
24
|
+
onClick: () => {
|
|
25
|
+
if (ref && ref.current) {
|
|
26
|
+
ref.current.select();
|
|
27
|
+
ref.current.setSelectionRange(0, value.length + 1);
|
|
28
|
+
document.execCommand('copy');
|
|
29
|
+
setCopied(true);
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
onMouseEnter: () => {
|
|
39
33
|
setHovered(true);
|
|
40
34
|
setCopied(false);
|
|
41
|
-
}
|
|
42
|
-
|
|
35
|
+
},
|
|
36
|
+
onMouseLeave: () => {
|
|
43
37
|
setHovered(false);
|
|
44
38
|
setCopied(false);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
$[12] = successMessage;
|
|
59
|
-
$[13] = t;
|
|
60
|
-
$[14] = t5;
|
|
61
|
-
} else {
|
|
62
|
-
t5 = $[14];
|
|
63
|
-
}
|
|
64
|
-
let t6;
|
|
65
|
-
if ($[15] !== copied || $[16] !== defaultMessage || $[17] !== t) {
|
|
66
|
-
t6 = !copied && (defaultMessage ?? t("general:copy"));
|
|
67
|
-
$[15] = copied;
|
|
68
|
-
$[16] = defaultMessage;
|
|
69
|
-
$[17] = t;
|
|
70
|
-
$[18] = t6;
|
|
71
|
-
} else {
|
|
72
|
-
t6 = $[18];
|
|
73
|
-
}
|
|
74
|
-
t4 = _jsxs("button", {
|
|
75
|
-
className: baseClass,
|
|
76
|
-
onClick: t1,
|
|
77
|
-
onMouseEnter: t2,
|
|
78
|
-
onMouseLeave: t3,
|
|
79
|
-
type: "button",
|
|
80
|
-
children: [_jsx(CopyIcon, {}), _jsxs(Tooltip, {
|
|
81
|
-
delay: copied ? 0 : undefined,
|
|
82
|
-
show: hovered || copied,
|
|
83
|
-
children: [t5, t6]
|
|
84
|
-
})]
|
|
85
|
-
});
|
|
86
|
-
$[4] = copied;
|
|
87
|
-
$[5] = defaultMessage;
|
|
88
|
-
$[6] = hovered;
|
|
89
|
-
$[7] = successMessage;
|
|
90
|
-
$[8] = t;
|
|
91
|
-
$[9] = t1;
|
|
92
|
-
$[10] = t4;
|
|
93
|
-
} else {
|
|
94
|
-
t4 = $[10];
|
|
95
|
-
}
|
|
96
|
-
return t4;
|
|
39
|
+
},
|
|
40
|
+
type: "button",
|
|
41
|
+
children: [/*#__PURE__*/_jsx(CopyIcon, {}), /*#__PURE__*/_jsxs(Tooltip, {
|
|
42
|
+
delay: copied ? 0 : undefined,
|
|
43
|
+
show: hovered || copied,
|
|
44
|
+
children: [copied && (successMessage ?? t('general:copied')), !copied && (defaultMessage ?? t('general:copy'))]
|
|
45
|
+
}), /*#__PURE__*/_jsx("textarea", {
|
|
46
|
+
readOnly: true,
|
|
47
|
+
ref: ref,
|
|
48
|
+
tabIndex: -1,
|
|
49
|
+
value: value
|
|
50
|
+
})]
|
|
51
|
+
});
|
|
97
52
|
}
|
|
98
53
|
return null;
|
|
99
54
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["
|
|
1
|
+
{"version":3,"file":"index.js","names":["React","useRef","useState","CopyIcon","useTranslation","Tooltip","baseClass","CopyToClipboard","defaultMessage","successMessage","value","ref","copied","setCopied","hovered","setHovered","t","_jsxs","className","onClick","current","select","setSelectionRange","length","document","execCommand","onMouseEnter","onMouseLeave","type","_jsx","delay","undefined","show","readOnly","tabIndex"],"sources":["../../../src/elements/CopyToClipboard/index.tsx"],"sourcesContent":["'use client'\nimport React, { useRef, useState } from 'react'\n\nimport { CopyIcon } from '../../icons/Copy/index.js'\nimport { useTranslation } from '../../providers/Translation/index.js'\nimport { Tooltip } from '../Tooltip/index.js'\nimport './index.scss'\n\nconst baseClass = 'copy-to-clipboard'\n\nexport type Props = {\n defaultMessage?: string\n successMessage?: string\n value?: string\n}\n\nexport const CopyToClipboard: React.FC<Props> = ({ defaultMessage, successMessage, value }) => {\n const ref = useRef(null)\n const [copied, setCopied] = useState(false)\n const [hovered, setHovered] = useState(false)\n const { t } = useTranslation()\n\n if (value) {\n return (\n <button\n className={baseClass}\n onClick={() => {\n if (ref && ref.current) {\n ref.current.select()\n ref.current.setSelectionRange(0, value.length + 1)\n document.execCommand('copy')\n setCopied(true)\n }\n }}\n onMouseEnter={() => {\n setHovered(true)\n setCopied(false)\n }}\n onMouseLeave={() => {\n setHovered(false)\n setCopied(false)\n }}\n type=\"button\"\n >\n <CopyIcon />\n <Tooltip delay={copied ? 0 : undefined} show={hovered || copied}>\n {copied && (successMessage ?? t('general:copied'))}\n {!copied && (defaultMessage ?? t('general:copy'))}\n </Tooltip>\n <textarea readOnly ref={ref} tabIndex={-1} value={value} />\n </button>\n )\n }\n\n return null\n}\n"],"mappings":"AAAA;;;AACA,OAAOA,KAAA,IAASC,MAAM,EAAEC,QAAQ,QAAQ;AAExC,SAASC,QAAQ,QAAQ;AACzB,SAASC,cAAc,QAAQ;AAC/B,SAASC,OAAO,QAAQ;AACxB,OAAO;AAEP,MAAMC,SAAA,GAAY;AAQlB,OAAO,MAAMC,eAAA,GAAmCA,CAAC;EAAEC,cAAc;EAAEC,cAAc;EAAEC;AAAK,CAAE;EACxF,MAAMC,GAAA,GAAMV,MAAA,CAAO;EACnB,MAAM,CAACW,MAAA,EAAQC,SAAA,CAAU,GAAGX,QAAA,CAAS;EACrC,MAAM,CAACY,OAAA,EAASC,UAAA,CAAW,GAAGb,QAAA,CAAS;EACvC,MAAM;IAAEc;EAAC,CAAE,GAAGZ,cAAA;EAEd,IAAIM,KAAA,EAAO;IACT,oBACEO,KAAA,CAAC;MACCC,SAAA,EAAWZ,SAAA;MACXa,OAAA,EAASA,CAAA;QACP,IAAIR,GAAA,IAAOA,GAAA,CAAIS,OAAO,EAAE;UACtBT,GAAA,CAAIS,OAAO,CAACC,MAAM;UAClBV,GAAA,CAAIS,OAAO,CAACE,iBAAiB,CAAC,GAAGZ,KAAA,CAAMa,MAAM,GAAG;UAChDC,QAAA,CAASC,WAAW,CAAC;UACrBZ,SAAA,CAAU;QACZ;MACF;MACAa,YAAA,EAAcA,CAAA;QACZX,UAAA,CAAW;QACXF,SAAA,CAAU;MACZ;MACAc,YAAA,EAAcA,CAAA;QACZZ,UAAA,CAAW;QACXF,SAAA,CAAU;MACZ;MACAe,IAAA,EAAK;8BAELC,IAAA,CAAC1B,QAAA,O,aACDc,KAAA,CAACZ,OAAA;QAAQyB,KAAA,EAAOlB,MAAA,GAAS,IAAImB,SAAA;QAAWC,IAAA,EAAMlB,OAAA,IAAWF,MAAA;mBACtDA,MAAA,KAAWH,cAAA,IAAkBO,CAAA,CAAE,iBAAgB,GAC/C,CAACJ,MAAA,KAAWJ,cAAA,IAAkBQ,CAAA,CAAE,eAAc;uBAEjDa,IAAA,CAAC;QAASI,QAAQ;QAACtB,GAAA,EAAKA,GAAA;QAAKuB,QAAA,EAAU,CAAC;QAAGxB,KAAA,EAAOA;;;EAGxD;EAEA,OAAO;AACT","ignoreList":[]}
|
|
@@ -16,11 +16,6 @@ export type DocumentDrawerContextProps = {
|
|
|
16
16
|
}) => Promise<void> | void;
|
|
17
17
|
readonly onSave?: (args: {
|
|
18
18
|
collectionConfig?: ClientCollectionConfig;
|
|
19
|
-
/**
|
|
20
|
-
* @experimental - Note: this property is experimental and may change in the future. Use as your own discretion.
|
|
21
|
-
* If you want to pass additional data to the onSuccess callback, you can use this context object.
|
|
22
|
-
*/
|
|
23
|
-
context?: Record<string, unknown>;
|
|
24
19
|
doc: TypeWithID;
|
|
25
20
|
operation: 'create' | 'update';
|
|
26
21
|
result: Data;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Provider.d.ts","sourceRoot":"","sources":["../../../src/elements/DocumentDrawer/Provider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,IAAI,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAIlF,MAAM,MAAM,0BAA0B,GAAG;IACvC,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAA;IAC9B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC3B,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE;QACzB,gBAAgB,CAAC,EAAE,sBAAsB,CAAA;QACzC,EAAE,EAAE,MAAM,CAAA;KACX,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA;IAE1B,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC,IAAI,EAAE;QAC5B,gBAAgB,CAAC,EAAE,sBAAsB,CAAA;QACzC,GAAG,EAAE,UAAU,CAAA;KAChB,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA;IAC1B,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE;QAC1B,gBAAgB,CAAC,EAAE,sBAAsB,CAAA;QACzC,EAAE,EAAE,MAAM,CAAA;KACX,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA;IAC1B,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE;QACvB,gBAAgB,CAAC,EAAE,sBAAsB,CAAA;QACzC
|
|
1
|
+
{"version":3,"file":"Provider.d.ts","sourceRoot":"","sources":["../../../src/elements/DocumentDrawer/Provider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,I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B,CAG/B,CAAA;AAED,eAAO,MAAM,wBAAwB,QAAO,yBAQ3C,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Provider.js","names":["createContext","use","DocumentDrawerCallbacksContext","DocumentDrawerContextProvider","children","rest","_jsx","value","useDocumentDrawerContext","context","Error"],"sources":["../../../src/elements/DocumentDrawer/Provider.tsx"],"sourcesContent":["import type { ClientCollectionConfig, Data, FormState, TypeWithID } from 'payload'\n\nimport { createContext, use } from 'react'\n\nexport type DocumentDrawerContextProps = {\n readonly clearDoc?: () => void\n readonly drawerSlug: string\n readonly onDelete?: (args: {\n collectionConfig?: ClientCollectionConfig\n id: string\n }) => Promise<void> | void\n /* only available if `redirectAfterDuplicate` is `false` */\n readonly onDuplicate?: (args: {\n collectionConfig?: ClientCollectionConfig\n doc: TypeWithID\n }) => Promise<void> | void\n readonly onRestore?: (args: {\n collectionConfig?: ClientCollectionConfig\n id: string\n }) => Promise<void> | void\n readonly onSave?: (args: {\n collectionConfig?: ClientCollectionConfig\n
|
|
1
|
+
{"version":3,"file":"Provider.js","names":["createContext","use","DocumentDrawerCallbacksContext","DocumentDrawerContextProvider","children","rest","_jsx","value","useDocumentDrawerContext","context","Error"],"sources":["../../../src/elements/DocumentDrawer/Provider.tsx"],"sourcesContent":["import type { ClientCollectionConfig, Data, FormState, TypeWithID } from 'payload'\n\nimport { createContext, use } from 'react'\n\nexport type DocumentDrawerContextProps = {\n readonly clearDoc?: () => void\n readonly drawerSlug: string\n readonly onDelete?: (args: {\n collectionConfig?: ClientCollectionConfig\n id: string\n }) => Promise<void> | void\n /* only available if `redirectAfterDuplicate` is `false` */\n readonly onDuplicate?: (args: {\n collectionConfig?: ClientCollectionConfig\n doc: TypeWithID\n }) => Promise<void> | void\n readonly onRestore?: (args: {\n collectionConfig?: ClientCollectionConfig\n id: string\n }) => Promise<void> | void\n readonly onSave?: (args: {\n collectionConfig?: ClientCollectionConfig\n doc: TypeWithID\n operation: 'create' | 'update'\n result: Data\n }) => Promise<FormState | void> | void\n}\n\nexport type DocumentDrawerContextType = {} & DocumentDrawerContextProps\n\nexport const DocumentDrawerCallbacksContext = createContext({} as DocumentDrawerContextType)\n\nexport const DocumentDrawerContextProvider: React.FC<\n {\n children: React.ReactNode\n } & DocumentDrawerContextProps\n> = ({ children, ...rest }) => {\n return <DocumentDrawerCallbacksContext value={rest}>{children}</DocumentDrawerCallbacksContext>\n}\n\nexport const useDocumentDrawerContext = (): DocumentDrawerContextType => {\n const context = use(DocumentDrawerCallbacksContext)\n\n if (!context) {\n throw new Error('useDocumentDrawerContext must be used within a DocumentDrawerProvider')\n }\n\n return context\n}\n"],"mappings":";AAEA,SAASA,aAAa,EAAEC,GAAG,QAAQ;AA4BnC,OAAO,MAAMC,8BAAA,gBAAiCF,aAAA,CAAc,CAAC;AAE7D,OAAO,MAAMG,6BAAA,GAITA,CAAC;EAAEC,QAAQ;EAAE,GAAGC;AAAA,CAAM;EACxB,oBAAOC,IAAA,CAACJ,8BAAA;IAA+BK,KAAA,EAAOF,IAAA;cAAOD;;AACvD;AAEA,OAAO,MAAMI,wBAAA,GAA2BA,CAAA;EACtC,MAAMC,OAAA,GAAUR,GAAA,CAAIC,8BAAA;EAEpB,IAAI,CAACO,OAAA,EAAS;IACZ,MAAM,IAAIC,KAAA,CAAM;EAClB;EAEA,OAAOD,OAAA;AACT","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/elements/Upload/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,yBAAyB,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAIhF,OAAO,KAA6D,MAAM,OAAO,CAAA;AAiBjF,OAAO,cAAc,CAAA;AAMrB,eAAO,MAAM,cAAc,gBAAgB,CAAA;AAC3C,eAAO,MAAM,eAAe,kBAAkB,CAAA;AAU9C,KAAK,iBAAiB,GAAG;IACvB,QAAQ,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C,CAAA"}
|
|
@@ -170,8 +170,8 @@ export const Upload_v4 = props => {
|
|
|
170
170
|
} = useForm();
|
|
171
171
|
const {
|
|
172
172
|
id,
|
|
173
|
-
data,
|
|
174
173
|
docPermissions,
|
|
174
|
+
savedDocumentData,
|
|
175
175
|
setUploadStatus
|
|
176
176
|
} = useDocumentInfo();
|
|
177
177
|
const isFormSubmitting = useFormProcessing();
|
|
@@ -312,7 +312,7 @@ export const Upload_v4 = props => {
|
|
|
312
312
|
} = uploadConfig;
|
|
313
313
|
const showFocalPoint = focalPoint && (hasImageSizes || hasResizeOptions || focalPointEnabled);
|
|
314
314
|
const acceptMimeTypes = uploadConfig.mimeTypes?.join(', ');
|
|
315
|
-
const imageCacheTag = uploadConfig?.cacheTags &&
|
|
315
|
+
const imageCacheTag = uploadConfig?.cacheTags && savedDocumentData?.updatedAt;
|
|
316
316
|
useEffect(() => {
|
|
317
317
|
const handleControlFileUrl = async () => {
|
|
318
318
|
if (uploadControlFileUrl) {
|
|
@@ -335,17 +335,17 @@ export const Upload_v4 = props => {
|
|
|
335
335
|
children: [/*#__PURE__*/_jsx(FieldError, {
|
|
336
336
|
message: errorMessage,
|
|
337
337
|
showError: showError
|
|
338
|
-
}),
|
|
338
|
+
}), savedDocumentData && savedDocumentData.filename && !removedFile && /*#__PURE__*/_jsx(FileDetails, {
|
|
339
339
|
collectionSlug: collectionSlug,
|
|
340
340
|
customUploadActions: customActions,
|
|
341
|
-
doc:
|
|
341
|
+
doc: savedDocumentData,
|
|
342
342
|
enableAdjustments: showCrop || showFocalPoint,
|
|
343
343
|
handleRemove: canRemoveUpload ? handleFileRemoval : undefined,
|
|
344
344
|
hasImageSizes: hasImageSizes,
|
|
345
345
|
hideRemoveFile: uploadConfig.hideRemoveFile,
|
|
346
346
|
imageCacheTag: imageCacheTag,
|
|
347
347
|
uploadConfig: uploadConfig
|
|
348
|
-
}), (!uploadConfig.hideFileInputOnCreate && !
|
|
348
|
+
}), (!uploadConfig.hideFileInputOnCreate && !savedDocumentData?.filename || removedFile) && /*#__PURE__*/_jsxs("div", {
|
|
349
349
|
className: `${baseClass}__upload`,
|
|
350
350
|
children: [!value && !showUrlInput && /*#__PURE__*/_jsx(Dropzone, {
|
|
351
351
|
onChange: handleFileSelection,
|
|
@@ -450,7 +450,7 @@ export const Upload_v4 = props => {
|
|
|
450
450
|
}), /*#__PURE__*/_jsx(UploadActions, {
|
|
451
451
|
customActions: customActions,
|
|
452
452
|
enableAdjustments: showCrop || showFocalPoint,
|
|
453
|
-
enablePreviewSizes: hasImageSizes &&
|
|
453
|
+
enablePreviewSizes: hasImageSizes && savedDocumentData?.filename && !removedFile,
|
|
454
454
|
mimeType: value.type
|
|
455
455
|
})]
|
|
456
456
|
}), /*#__PURE__*/_jsx(Button, {
|
|
@@ -463,33 +463,33 @@ export const Upload_v4 = props => {
|
|
|
463
463
|
tooltip: t('general:cancel')
|
|
464
464
|
})]
|
|
465
465
|
})]
|
|
466
|
-
}), (value ||
|
|
466
|
+
}), (value || savedDocumentData?.filename) && /*#__PURE__*/_jsx(EditDepthProvider, {
|
|
467
467
|
children: /*#__PURE__*/_jsx(Drawer, {
|
|
468
468
|
Header: null,
|
|
469
469
|
slug: editDrawerSlug,
|
|
470
470
|
children: /*#__PURE__*/_jsx(EditUpload, {
|
|
471
|
-
fileName: value?.name ||
|
|
472
|
-
fileSrc:
|
|
471
|
+
fileName: value?.name || savedDocumentData?.filename,
|
|
472
|
+
fileSrc: savedDocumentData?.url || fileSrc,
|
|
473
473
|
imageCacheTag: imageCacheTag,
|
|
474
474
|
initialCrop: uploadEdits?.crop ?? undefined,
|
|
475
475
|
initialFocalPoint: {
|
|
476
|
-
x: uploadEdits?.focalPoint?.x ||
|
|
477
|
-
y: uploadEdits?.focalPoint?.y ||
|
|
476
|
+
x: uploadEdits?.focalPoint?.x || savedDocumentData?.focalX || 50,
|
|
477
|
+
y: uploadEdits?.focalPoint?.y || savedDocumentData?.focalY || 50
|
|
478
478
|
},
|
|
479
479
|
onSave: onEditsSave,
|
|
480
480
|
showCrop: showCrop,
|
|
481
481
|
showFocalPoint: showFocalPoint
|
|
482
482
|
})
|
|
483
483
|
})
|
|
484
|
-
}),
|
|
484
|
+
}), savedDocumentData && hasImageSizes && /*#__PURE__*/_jsx(Drawer, {
|
|
485
485
|
className: `${baseClass}__previewDrawer`,
|
|
486
486
|
hoverTitle: true,
|
|
487
487
|
slug: sizePreviewSlug,
|
|
488
488
|
title: t('upload:sizesFor', {
|
|
489
|
-
label:
|
|
489
|
+
label: savedDocumentData.filename
|
|
490
490
|
}),
|
|
491
491
|
children: /*#__PURE__*/_jsx(PreviewSizes, {
|
|
492
|
-
doc:
|
|
492
|
+
doc: savedDocumentData,
|
|
493
493
|
imageCacheTag: imageCacheTag,
|
|
494
494
|
uploadConfig: uploadConfig
|
|
495
495
|
})
|