@payloadcms/ui 3.90.1 → 3.90.2
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/BulkUpload/FormsManager/index.d.ts.map +1 -1
- package/dist/elements/BulkUpload/FormsManager/index.js +12 -7
- package/dist/elements/BulkUpload/FormsManager/index.js.map +1 -1
- package/dist/exports/client/index.js +12 -12
- package/dist/exports/client/index.js.map +3 -3
- package/dist/providers/DocumentInfo/index.d.ts.map +1 -1
- package/dist/providers/DocumentInfo/index.js +30 -19
- package/dist/providers/DocumentInfo/index.js.map +1 -1
- package/dist/providers/Locale/index.d.ts.map +1 -1
- package/dist/providers/Locale/index.js +36 -45
- package/dist/providers/Locale/index.js.map +1 -1
- package/dist/providers/UploadHandlers/index.d.ts.map +1 -1
- package/dist/providers/UploadHandlers/index.js +24 -59
- package/dist/providers/UploadHandlers/index.js.map +1 -1
- package/dist/providers/UploadHandlers/index.spec.js +63 -0
- package/dist/providers/UploadHandlers/index.spec.js.map +1 -0
- package/package.json +5 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/DocumentInfo/index.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAgF,MAAM,OAAO,CAAA;AAEpG,OAAO,KAAK,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAgBxE,mBAAmB,YAAY,CAAA;AAE/B,eAAO,MAAM,eAAe,QAAO,mBAAmC,CAAA;AA+
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/DocumentInfo/index.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAgF,MAAM,OAAO,CAAA;AAEpG,OAAO,KAAK,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAgBxE,mBAAmB,YAAY,CAAA;AAE/B,eAAO,MAAM,eAAe,QAAO,mBAAmC,CAAA;AA+ZtE,eAAO,MAAM,oBAAoB,EAAE,KAAK,CAAC,EAAE,CACzC;IACE,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;CACnC,GAAG,iBAAiB,CAOtB,CAAA"}
|
|
@@ -115,10 +115,6 @@ const DocumentInfo = ({
|
|
|
115
115
|
localeIsLoading
|
|
116
116
|
} = useLocaleLoading();
|
|
117
117
|
const isInitializing = useMemo(() => initialState === undefined || initialData === undefined || localeIsLoading, [initialData, initialState, localeIsLoading]);
|
|
118
|
-
const baseAPIPath = formatAdminURL({
|
|
119
|
-
apiRoute: api,
|
|
120
|
-
path: ''
|
|
121
|
-
});
|
|
122
118
|
let slug;
|
|
123
119
|
let pluralType;
|
|
124
120
|
let preferencesKey;
|
|
@@ -141,7 +137,10 @@ const DocumentInfo = ({
|
|
|
141
137
|
}
|
|
142
138
|
try {
|
|
143
139
|
const isGlobal = slug_0 === globalSlug;
|
|
144
|
-
const request = await requests.get(
|
|
140
|
+
const request = await requests.get(formatAdminURL({
|
|
141
|
+
apiRoute: api,
|
|
142
|
+
path: '/payload-locked-documents'
|
|
143
|
+
}), {
|
|
145
144
|
credentials: 'include',
|
|
146
145
|
params: isGlobal ? {
|
|
147
146
|
'where[globalSlug][equals]': slug_0
|
|
@@ -155,7 +154,10 @@ const DocumentInfo = ({
|
|
|
155
154
|
} = await request.json();
|
|
156
155
|
if (docs?.length > 0) {
|
|
157
156
|
const lockID = docs[0].id;
|
|
158
|
-
await requests.delete(
|
|
157
|
+
await requests.delete(formatAdminURL({
|
|
158
|
+
apiRoute: api,
|
|
159
|
+
path: `/payload-locked-documents/${lockID}`
|
|
160
|
+
}), {
|
|
159
161
|
credentials: 'include',
|
|
160
162
|
headers: {
|
|
161
163
|
'Content-Type': 'application/json'
|
|
@@ -167,7 +169,7 @@ const DocumentInfo = ({
|
|
|
167
169
|
// eslint-disable-next-line no-console
|
|
168
170
|
console.error('Failed to unlock the document', error);
|
|
169
171
|
}
|
|
170
|
-
}, [
|
|
172
|
+
}, [api, globalSlug, setDocumentIsLocked, hasLockedDocumentsCollection]);
|
|
171
173
|
const updateDocumentEditor = useCallback(async (docID_0, slug_1, user) => {
|
|
172
174
|
// Check if the locked-documents collection exists before making API calls
|
|
173
175
|
if (!hasLockedDocumentsCollection) {
|
|
@@ -176,7 +178,10 @@ const DocumentInfo = ({
|
|
|
176
178
|
try {
|
|
177
179
|
const isGlobal_0 = slug_1 === globalSlug;
|
|
178
180
|
// Check if the document is already locked
|
|
179
|
-
const request_0 = await requests.get(
|
|
181
|
+
const request_0 = await requests.get(formatAdminURL({
|
|
182
|
+
apiRoute: api,
|
|
183
|
+
path: '/payload-locked-documents'
|
|
184
|
+
}), {
|
|
180
185
|
credentials: 'include',
|
|
181
186
|
params: isGlobal_0 ? {
|
|
182
187
|
'where[globalSlug][equals]': slug_1
|
|
@@ -198,7 +203,10 @@ const DocumentInfo = ({
|
|
|
198
203
|
value: user
|
|
199
204
|
};
|
|
200
205
|
// Send a patch request to update the _lastEdited info
|
|
201
|
-
await requests.patch(
|
|
206
|
+
await requests.patch(formatAdminURL({
|
|
207
|
+
apiRoute: api,
|
|
208
|
+
path: `/payload-locked-documents/${lockID_0}`
|
|
209
|
+
}), {
|
|
202
210
|
body: JSON.stringify({
|
|
203
211
|
user: userData
|
|
204
212
|
}),
|
|
@@ -212,7 +220,7 @@ const DocumentInfo = ({
|
|
|
212
220
|
// eslint-disable-next-line no-console
|
|
213
221
|
console.error('Failed to update the document editor', error_0);
|
|
214
222
|
}
|
|
215
|
-
}, [
|
|
223
|
+
}, [api, globalSlug, hasLockedDocumentsCollection]);
|
|
216
224
|
const getDocPermissions = useGetDocPermissions({
|
|
217
225
|
id: id,
|
|
218
226
|
api,
|
|
@@ -295,15 +303,18 @@ const DocumentInfo = ({
|
|
|
295
303
|
}, []);
|
|
296
304
|
const action = React.useMemo(() => {
|
|
297
305
|
const docPath = `${pluralType === 'globals' ? `/globals` : ''}/${slug}${id ? `/${id}` : ''}`;
|
|
298
|
-
return
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
306
|
+
return formatAdminURL({
|
|
307
|
+
apiRoute: api,
|
|
308
|
+
path: `${docPath}${qs.stringify({
|
|
309
|
+
depth: 0,
|
|
310
|
+
'fallback-locale': 'null',
|
|
311
|
+
locale,
|
|
312
|
+
uploadEdits: uploadEdits || undefined
|
|
313
|
+
}, {
|
|
314
|
+
addQueryPrefix: true
|
|
315
|
+
})}`
|
|
316
|
+
});
|
|
317
|
+
}, [api, locale, pluralType, id, slug, uploadEdits]);
|
|
307
318
|
const value = {
|
|
308
319
|
...props,
|
|
309
320
|
action,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["formatAdminURL","qs","React","createContext","use","useCallback","useEffect","useMemo","useRef","useState","useControllableState","useAuth","requests","formatDocTitle","useConfig","DocumentTitleProvider","useLocale","useLocaleLoading","usePreferences","useTranslation","UploadEditsProvider","useUploadEdits","useGetDocPermissions","Context","useDocumentInfo","DocumentInfo","children","props","id","collectionSlug","currentEditor","currentEditorFromProps","docPermissions","docPermissionsFromProps","globalSlug","hasPublishedDoc","hasPublishedDocFromProps","hasPublishPermission","hasPublishPermissionFromProps","hasSavePermission","hasSavePermissionFromProps","initialData","initialState","isLocked","isLockedFromProps","lastUpdateTime","lastUpdateTimeFromProps","mostRecentVersionIsAutosaved","mostRecentVersionIsAutosavedFromProps","unpublishedVersionCount","unpublishedVersionCountFromProps","versionCount","versionCountFromProps","setDocPermissions","setHasSavePermission","setHasPublishPermission","permissions","config","admin","dateFormat","collections","routes","api","getEntityConfig","collectionConfig","globalConfig","hasLockedDocumentsCollection","some","collection","slug","abortControllerRef","AbortController","docConfig","i18n","uploadEdits","title","setDocumentTitle","data","fallback","toString","setMostRecentVersionIsAutosaved","setVersionCount","setHasPublishedDoc","setUnpublishedVersionCount","documentIsLocked","setDocumentIsLocked","setCurrentEditor","setLastUpdateTime","setData","uploadStatus","setUploadStatus","documentLockState","hasShownLockedModal","user","updateUploadStatus","status","getPreference","setPreference","code","locale","localeIsLoading","isInitializing","undefined","baseAPIPath","apiRoute","path","pluralType","preferencesKey","unlockDocument","docID","isGlobal","request","get","credentials","params","docs","json","length","lockID","delete","headers","error","console","updateDocumentEditor","userData","relationTo","value","patch","body","JSON","stringify","getDocPermissions","getDocPreferences","setDocFieldPreferences","fieldPreferences","allPreferences","fields","e","incrementVersionCount","newCount","versions","maxPerDoc","Math","min","max","re1","current","abort","_err","action","docPath","depth","addQueryPrefix","savedDocumentData","updateSavedDocumentData","_jsx","DocumentInfoProvider"],"sources":["../../../src/providers/DocumentInfo/index.tsx"],"sourcesContent":["'use client'\nimport type { ClientUser, DocumentPreferences } from 'payload'\n\nimport { formatAdminURL } from 'payload/shared'\nimport * as qs from 'qs-esm'\nimport React, { createContext, use, useCallback, useEffect, useMemo, useRef, useState } from 'react'\n\nimport type { DocumentInfoContext, DocumentInfoProps } from './types.js'\n\nimport { useControllableState } from '../../hooks/useControllableState.js'\nimport { useAuth } from '../../providers/Auth/index.js'\nimport { requests } from '../../utilities/api.js'\nimport { formatDocTitle } from '../../utilities/formatDocTitle/index.js'\nimport { useConfig } from '../Config/index.js'\nimport { DocumentTitleProvider } from '../DocumentTitle/index.js'\nimport { useLocale, useLocaleLoading } from '../Locale/index.js'\nimport { usePreferences } from '../Preferences/index.js'\nimport { useTranslation } from '../Translation/index.js'\nimport { UploadEditsProvider, useUploadEdits } from '../UploadEdits/index.js'\nimport { useGetDocPermissions } from './useGetDocPermissions.js'\n\nconst Context = createContext({} as DocumentInfoContext)\n\nexport type * from './types.js'\n\nexport const useDocumentInfo = (): DocumentInfoContext => use(Context)\n\nconst DocumentInfo: React.FC<\n {\n readonly children: React.ReactNode\n } & DocumentInfoProps\n> = ({ children, ...props }) => {\n const {\n id,\n collectionSlug,\n currentEditor: currentEditorFromProps,\n docPermissions: docPermissionsFromProps,\n globalSlug,\n hasPublishedDoc: hasPublishedDocFromProps,\n hasPublishPermission: hasPublishPermissionFromProps,\n hasSavePermission: hasSavePermissionFromProps,\n initialData,\n initialState,\n isLocked: isLockedFromProps,\n lastUpdateTime: lastUpdateTimeFromProps,\n mostRecentVersionIsAutosaved: mostRecentVersionIsAutosavedFromProps,\n unpublishedVersionCount: unpublishedVersionCountFromProps,\n versionCount: versionCountFromProps,\n } = props\n\n const [docPermissions, setDocPermissions] = useControllableState(docPermissionsFromProps)\n\n const [hasSavePermission, setHasSavePermission] = useControllableState(hasSavePermissionFromProps)\n\n const [hasPublishPermission, setHasPublishPermission] = useControllableState(\n hasPublishPermissionFromProps,\n )\n\n const { permissions } = useAuth()\n\n const {\n config: {\n admin: { dateFormat },\n collections,\n routes: { api },\n },\n getEntityConfig,\n } = useConfig()\n\n const collectionConfig = getEntityConfig({ collectionSlug })\n const globalConfig = getEntityConfig({ globalSlug })\n\n // Check if the locked-documents collection exists in the config\n const hasLockedDocumentsCollection = collections.some(\n (collection) => collection.slug === 'payload-locked-documents',\n )\n\n const abortControllerRef = useRef(new AbortController())\n const docConfig = collectionConfig || globalConfig\n\n const { i18n } = useTranslation()\n\n const { uploadEdits } = useUploadEdits()\n\n /**\n * @deprecated This state will be removed in v4.\n * This is for performance reasons. Use the `DocumentTitleContext` instead.\n */\n const [title, setDocumentTitle] = useState(() =>\n formatDocTitle({\n collectionConfig,\n data: { ...(initialData || {}), id },\n dateFormat,\n fallback: id?.toString(),\n globalConfig,\n i18n,\n }),\n )\n\n const [mostRecentVersionIsAutosaved, setMostRecentVersionIsAutosaved] = useState(\n mostRecentVersionIsAutosavedFromProps,\n )\n\n const [versionCount, setVersionCount] = useState(versionCountFromProps)\n\n const [hasPublishedDoc, setHasPublishedDoc] = useState(hasPublishedDocFromProps)\n\n const [unpublishedVersionCount, setUnpublishedVersionCount] = useState(\n unpublishedVersionCountFromProps,\n )\n\n const [documentIsLocked, setDocumentIsLocked] = useControllableState<boolean | undefined>(\n isLockedFromProps,\n )\n\n const [currentEditor, setCurrentEditor] = useControllableState<ClientUser | null>(\n currentEditorFromProps,\n )\n const [lastUpdateTime, setLastUpdateTime] = useControllableState<number>(lastUpdateTimeFromProps)\n\n const [data, setData] = useControllableState(initialData)\n\n const [uploadStatus, setUploadStatus] = useControllableState<'failed' | 'idle' | 'uploading'>(\n 'idle',\n )\n\n const documentLockState = useRef<{\n hasShownLockedModal: boolean\n isLocked: boolean\n user: ClientUser | number | string\n } | null>({\n hasShownLockedModal: false,\n isLocked: false,\n user: null,\n })\n\n const updateUploadStatus = useCallback(\n (status: 'failed' | 'idle' | 'uploading') => {\n setUploadStatus(status)\n },\n [setUploadStatus],\n )\n\n const { getPreference, setPreference } = usePreferences()\n const { code: locale } = useLocale()\n const { localeIsLoading } = useLocaleLoading()\n\n const isInitializing = useMemo(\n () => initialState === undefined || initialData === undefined || localeIsLoading,\n [initialData, initialState, localeIsLoading],\n )\n\n const baseAPIPath = formatAdminURL({\n apiRoute: api,\n path: '',\n })\n\n let slug: string\n let pluralType: 'collections' | 'globals'\n let preferencesKey: string\n\n if (globalSlug) {\n slug = globalSlug\n pluralType = 'globals'\n preferencesKey = `global-${slug}`\n }\n\n if (collectionSlug) {\n slug = collectionSlug\n pluralType = 'collections'\n\n if (id) {\n preferencesKey = `collection-${slug}-${id}`\n }\n }\n\n const unlockDocument = useCallback(\n async (docID: number | string, slug: string) => {\n // Check if the locked-documents collection exists before making API calls\n if (!hasLockedDocumentsCollection) {\n return\n }\n\n try {\n const isGlobal = slug === globalSlug\n\n const request = await requests.get(`${baseAPIPath}/payload-locked-documents`, {\n credentials: 'include',\n params: isGlobal\n ? {\n 'where[globalSlug][equals]': slug,\n }\n : {\n 'where[document.relationTo][equals]': slug,\n 'where[document.value][equals]': docID,\n },\n })\n\n const { docs } = await request.json()\n\n if (docs?.length > 0) {\n const lockID = docs[0].id\n await requests.delete(`${baseAPIPath}/payload-locked-documents/${lockID}`, {\n credentials: 'include',\n headers: {\n 'Content-Type': 'application/json',\n },\n })\n setDocumentIsLocked(false)\n }\n } catch (error) {\n // eslint-disable-next-line no-console\n console.error('Failed to unlock the document', error)\n }\n },\n [baseAPIPath, globalSlug, setDocumentIsLocked, hasLockedDocumentsCollection],\n )\n\n const updateDocumentEditor = useCallback(\n async (docID: number | string, slug: string, user: ClientUser | number | string) => {\n // Check if the locked-documents collection exists before making API calls\n if (!hasLockedDocumentsCollection) {\n return\n }\n\n try {\n const isGlobal = slug === globalSlug\n\n // Check if the document is already locked\n const request = await requests.get(`${baseAPIPath}/payload-locked-documents`, {\n credentials: 'include',\n params: isGlobal\n ? {\n 'where[globalSlug][equals]': slug,\n }\n : {\n 'where[document.relationTo][equals]': slug,\n 'where[document.value][equals]': docID,\n },\n })\n\n const { docs } = await request.json()\n\n if (docs?.length > 0) {\n const lockID = docs[0].id\n\n const userData =\n typeof user === 'object'\n ? { relationTo: user.collection, value: user.id }\n : { relationTo: 'users', value: user }\n\n // Send a patch request to update the _lastEdited info\n await requests.patch(`${baseAPIPath}/payload-locked-documents/${lockID}`, {\n body: JSON.stringify({\n user: userData,\n }),\n credentials: 'include',\n headers: {\n 'Content-Type': 'application/json',\n },\n })\n }\n } catch (error) {\n // eslint-disable-next-line no-console\n console.error('Failed to update the document editor', error)\n }\n },\n [baseAPIPath, globalSlug, hasLockedDocumentsCollection],\n )\n\n const getDocPermissions = useGetDocPermissions({\n id: id as string,\n api,\n collectionSlug,\n globalSlug,\n i18n,\n locale,\n permissions,\n setDocPermissions,\n setHasPublishPermission,\n setHasSavePermission,\n })\n\n const getDocPreferences = useCallback(() => {\n return getPreference<DocumentPreferences>(preferencesKey)\n }, [getPreference, preferencesKey])\n\n const setDocFieldPreferences = useCallback<DocumentInfoContext['setDocFieldPreferences']>(\n async (path, fieldPreferences) => {\n const allPreferences = await getDocPreferences()\n\n if (preferencesKey) {\n try {\n await setPreference(preferencesKey, {\n ...allPreferences,\n fields: {\n ...(allPreferences?.fields || {}),\n [path]: {\n ...allPreferences?.fields?.[path],\n ...fieldPreferences,\n },\n },\n })\n } catch (e) {\n console.error(e) // eslint-disable-line no-console\n }\n }\n },\n [setPreference, preferencesKey, getDocPreferences],\n )\n\n const incrementVersionCount = useCallback(() => {\n const newCount = versionCount + 1\n if (collectionConfig && collectionConfig.versions) {\n if (collectionConfig.versions.maxPerDoc > 0) {\n setVersionCount(Math.min(newCount, collectionConfig.versions.maxPerDoc))\n } else {\n setVersionCount(newCount)\n }\n } else if (globalConfig && globalConfig.versions) {\n if (globalConfig.versions.max > 0) {\n setVersionCount(Math.min(newCount, globalConfig.versions.max))\n } else {\n setVersionCount(newCount)\n }\n }\n }, [collectionConfig, globalConfig, versionCount])\n\n /**\n * @todo: Remove this in v4\n * Users should use the `DocumentTitleContext` instead.\n */\n useEffect(() => {\n setDocumentTitle(\n formatDocTitle({\n collectionConfig,\n data: { ...data, id },\n dateFormat,\n fallback: id?.toString(),\n globalConfig,\n i18n,\n }),\n )\n }, [collectionConfig, globalConfig, data, dateFormat, i18n, id])\n\n // clean on unmount\n useEffect(() => {\n const re1 = abortControllerRef.current\n\n return () => {\n if (re1) {\n try {\n re1.abort()\n } catch (_err) {\n // swallow error\n }\n }\n }\n }, [])\n\n const action: string = React.useMemo(() => {\n const docPath = `${pluralType === 'globals' ? `/globals` : ''}/${slug}${id ? `/${id}` : ''}`\n\n return `${baseAPIPath}${docPath}${qs.stringify(\n {\n depth: 0,\n 'fallback-locale': 'null',\n locale,\n uploadEdits: uploadEdits || undefined,\n },\n {\n addQueryPrefix: true,\n },\n )}`\n }, [baseAPIPath, locale, pluralType, id, slug, uploadEdits])\n\n const value: DocumentInfoContext = {\n ...props,\n action,\n currentEditor,\n data,\n docConfig,\n docPermissions,\n documentIsLocked,\n documentLockState,\n getDocPermissions,\n getDocPreferences,\n hasPublishedDoc,\n hasPublishPermission,\n hasSavePermission,\n incrementVersionCount,\n initialData,\n initialState,\n isInitializing,\n lastUpdateTime,\n mostRecentVersionIsAutosaved,\n preferencesKey,\n savedDocumentData: data,\n setCurrentEditor,\n setData,\n setDocFieldPreferences,\n setDocumentIsLocked,\n setDocumentTitle,\n setHasPublishedDoc,\n setLastUpdateTime,\n setMostRecentVersionIsAutosaved,\n setUnpublishedVersionCount,\n setUploadStatus: updateUploadStatus,\n title,\n unlockDocument,\n unpublishedVersionCount,\n updateDocumentEditor,\n updateSavedDocumentData: setData,\n uploadStatus,\n versionCount,\n }\n\n return (\n <Context value={value}>\n <DocumentTitleProvider>{children}</DocumentTitleProvider>\n </Context>\n )\n}\n\nexport const DocumentInfoProvider: React.FC<\n {\n readonly children: React.ReactNode\n } & DocumentInfoProps\n> = (props) => {\n return (\n <UploadEditsProvider>\n <DocumentInfo {...props} />\n </UploadEditsProvider>\n )\n}\n"],"mappings":"AAAA;;;AAGA,SAASA,cAAc,QAAQ;AAC/B,YAAYC,EAAA,MAAQ;AACpB,OAAOC,KAAA,IAASC,aAAa,EAAEC,GAAG,EAAEC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ;AAI7F,SAASC,oBAAoB,QAAQ;AACrC,SAASC,OAAO,QAAQ;AACxB,SAASC,QAAQ,QAAQ;AACzB,SAASC,cAAc,QAAQ;AAC/B,SAASC,SAAS,QAAQ;AAC1B,SAASC,qBAAqB,QAAQ;AACtC,SAASC,SAAS,EAAEC,gBAAgB,QAAQ;AAC5C,SAASC,cAAc,QAAQ;AAC/B,SAASC,cAAc,QAAQ;AAC/B,SAASC,mBAAmB,EAAEC,cAAc,QAAQ;AACpD,SAASC,oBAAoB,QAAQ;AAErC,MAAMC,OAAA,gBAAUpB,aAAA,CAAc,CAAC;AAI/B,OAAO,MAAMqB,eAAA,GAAkBA,CAAA,KAA2BpB,GAAA,CAAImB,OAAA;AAE9D,MAAME,YAAA,GAIFA,CAAC;EAAEC,QAAQ;EAAE,GAAGC;AAAA,CAAO;EACzB,MAAM;IACJC,EAAE;IACFC,cAAc;IACdC,aAAA,EAAe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AAA;MAAc,GAAGE;;;AAGxB","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["formatAdminURL","qs","React","createContext","use","useCallback","useEffect","useMemo","useRef","useState","useControllableState","useAuth","requests","formatDocTitle","useConfig","DocumentTitleProvider","useLocale","useLocaleLoading","usePreferences","useTranslation","UploadEditsProvider","useUploadEdits","useGetDocPermissions","Context","useDocumentInfo","DocumentInfo","children","props","id","collectionSlug","currentEditor","currentEditorFromProps","docPermissions","docPermissionsFromProps","globalSlug","hasPublishedDoc","hasPublishedDocFromProps","hasPublishPermission","hasPublishPermissionFromProps","hasSavePermission","hasSavePermissionFromProps","initialData","initialState","isLocked","isLockedFromProps","lastUpdateTime","lastUpdateTimeFromProps","mostRecentVersionIsAutosaved","mostRecentVersionIsAutosavedFromProps","unpublishedVersionCount","unpublishedVersionCountFromProps","versionCount","versionCountFromProps","setDocPermissions","setHasSavePermission","setHasPublishPermission","permissions","config","admin","dateFormat","collections","routes","api","getEntityConfig","collectionConfig","globalConfig","hasLockedDocumentsCollection","some","collection","slug","abortControllerRef","AbortController","docConfig","i18n","uploadEdits","title","setDocumentTitle","data","fallback","toString","setMostRecentVersionIsAutosaved","setVersionCount","setHasPublishedDoc","setUnpublishedVersionCount","documentIsLocked","setDocumentIsLocked","setCurrentEditor","setLastUpdateTime","setData","uploadStatus","setUploadStatus","documentLockState","hasShownLockedModal","user","updateUploadStatus","status","getPreference","setPreference","code","locale","localeIsLoading","isInitializing","undefined","pluralType","preferencesKey","unlockDocument","docID","isGlobal","request","get","apiRoute","path","credentials","params","docs","json","length","lockID","delete","headers","error","console","updateDocumentEditor","userData","relationTo","value","patch","body","JSON","stringify","getDocPermissions","getDocPreferences","setDocFieldPreferences","fieldPreferences","allPreferences","fields","e","incrementVersionCount","newCount","versions","maxPerDoc","Math","min","max","re1","current","abort","_err","action","docPath","depth","addQueryPrefix","savedDocumentData","updateSavedDocumentData","_jsx","DocumentInfoProvider"],"sources":["../../../src/providers/DocumentInfo/index.tsx"],"sourcesContent":["'use client'\nimport type { ClientUser, DocumentPreferences } from 'payload'\n\nimport { formatAdminURL } from 'payload/shared'\nimport * as qs from 'qs-esm'\nimport React, { createContext, use, useCallback, useEffect, useMemo, useRef, useState } from 'react'\n\nimport type { DocumentInfoContext, DocumentInfoProps } from './types.js'\n\nimport { useControllableState } from '../../hooks/useControllableState.js'\nimport { useAuth } from '../../providers/Auth/index.js'\nimport { requests } from '../../utilities/api.js'\nimport { formatDocTitle } from '../../utilities/formatDocTitle/index.js'\nimport { useConfig } from '../Config/index.js'\nimport { DocumentTitleProvider } from '../DocumentTitle/index.js'\nimport { useLocale, useLocaleLoading } from '../Locale/index.js'\nimport { usePreferences } from '../Preferences/index.js'\nimport { useTranslation } from '../Translation/index.js'\nimport { UploadEditsProvider, useUploadEdits } from '../UploadEdits/index.js'\nimport { useGetDocPermissions } from './useGetDocPermissions.js'\n\nconst Context = createContext({} as DocumentInfoContext)\n\nexport type * from './types.js'\n\nexport const useDocumentInfo = (): DocumentInfoContext => use(Context)\n\nconst DocumentInfo: React.FC<\n {\n readonly children: React.ReactNode\n } & DocumentInfoProps\n> = ({ children, ...props }) => {\n const {\n id,\n collectionSlug,\n currentEditor: currentEditorFromProps,\n docPermissions: docPermissionsFromProps,\n globalSlug,\n hasPublishedDoc: hasPublishedDocFromProps,\n hasPublishPermission: hasPublishPermissionFromProps,\n hasSavePermission: hasSavePermissionFromProps,\n initialData,\n initialState,\n isLocked: isLockedFromProps,\n lastUpdateTime: lastUpdateTimeFromProps,\n mostRecentVersionIsAutosaved: mostRecentVersionIsAutosavedFromProps,\n unpublishedVersionCount: unpublishedVersionCountFromProps,\n versionCount: versionCountFromProps,\n } = props\n\n const [docPermissions, setDocPermissions] = useControllableState(docPermissionsFromProps)\n\n const [hasSavePermission, setHasSavePermission] = useControllableState(hasSavePermissionFromProps)\n\n const [hasPublishPermission, setHasPublishPermission] = useControllableState(\n hasPublishPermissionFromProps,\n )\n\n const { permissions } = useAuth()\n\n const {\n config: {\n admin: { dateFormat },\n collections,\n routes: { api },\n },\n getEntityConfig,\n } = useConfig()\n\n const collectionConfig = getEntityConfig({ collectionSlug })\n const globalConfig = getEntityConfig({ globalSlug })\n\n // Check if the locked-documents collection exists in the config\n const hasLockedDocumentsCollection = collections.some(\n (collection) => collection.slug === 'payload-locked-documents',\n )\n\n const abortControllerRef = useRef(new AbortController())\n const docConfig = collectionConfig || globalConfig\n\n const { i18n } = useTranslation()\n\n const { uploadEdits } = useUploadEdits()\n\n /**\n * @deprecated This state will be removed in v4.\n * This is for performance reasons. Use the `DocumentTitleContext` instead.\n */\n const [title, setDocumentTitle] = useState(() =>\n formatDocTitle({\n collectionConfig,\n data: { ...(initialData || {}), id },\n dateFormat,\n fallback: id?.toString(),\n globalConfig,\n i18n,\n }),\n )\n\n const [mostRecentVersionIsAutosaved, setMostRecentVersionIsAutosaved] = useState(\n mostRecentVersionIsAutosavedFromProps,\n )\n\n const [versionCount, setVersionCount] = useState(versionCountFromProps)\n\n const [hasPublishedDoc, setHasPublishedDoc] = useState(hasPublishedDocFromProps)\n\n const [unpublishedVersionCount, setUnpublishedVersionCount] = useState(\n unpublishedVersionCountFromProps,\n )\n\n const [documentIsLocked, setDocumentIsLocked] = useControllableState<boolean | undefined>(\n isLockedFromProps,\n )\n\n const [currentEditor, setCurrentEditor] = useControllableState<ClientUser | null>(\n currentEditorFromProps,\n )\n const [lastUpdateTime, setLastUpdateTime] = useControllableState<number>(lastUpdateTimeFromProps)\n\n const [data, setData] = useControllableState(initialData)\n\n const [uploadStatus, setUploadStatus] = useControllableState<'failed' | 'idle' | 'uploading'>(\n 'idle',\n )\n\n const documentLockState = useRef<{\n hasShownLockedModal: boolean\n isLocked: boolean\n user: ClientUser | number | string\n } | null>({\n hasShownLockedModal: false,\n isLocked: false,\n user: null,\n })\n\n const updateUploadStatus = useCallback(\n (status: 'failed' | 'idle' | 'uploading') => {\n setUploadStatus(status)\n },\n [setUploadStatus],\n )\n\n const { getPreference, setPreference } = usePreferences()\n const { code: locale } = useLocale()\n const { localeIsLoading } = useLocaleLoading()\n\n const isInitializing = useMemo(\n () => initialState === undefined || initialData === undefined || localeIsLoading,\n [initialData, initialState, localeIsLoading],\n )\n\n let slug: string\n let pluralType: 'collections' | 'globals'\n let preferencesKey: string\n\n if (globalSlug) {\n slug = globalSlug\n pluralType = 'globals'\n preferencesKey = `global-${slug}`\n }\n\n if (collectionSlug) {\n slug = collectionSlug\n pluralType = 'collections'\n\n if (id) {\n preferencesKey = `collection-${slug}-${id}`\n }\n }\n\n const unlockDocument = useCallback(\n async (docID: number | string, slug: string) => {\n // Check if the locked-documents collection exists before making API calls\n if (!hasLockedDocumentsCollection) {\n return\n }\n\n try {\n const isGlobal = slug === globalSlug\n\n const request = await requests.get(\n formatAdminURL({ apiRoute: api, path: '/payload-locked-documents' }),\n {\n credentials: 'include',\n params: isGlobal\n ? {\n 'where[globalSlug][equals]': slug,\n }\n : {\n 'where[document.relationTo][equals]': slug,\n 'where[document.value][equals]': docID,\n },\n },\n )\n\n const { docs } = await request.json()\n\n if (docs?.length > 0) {\n const lockID = docs[0].id\n await requests.delete(\n formatAdminURL({\n apiRoute: api,\n path: `/payload-locked-documents/${lockID}`,\n }),\n {\n credentials: 'include',\n headers: {\n 'Content-Type': 'application/json',\n },\n },\n )\n setDocumentIsLocked(false)\n }\n } catch (error) {\n // eslint-disable-next-line no-console\n console.error('Failed to unlock the document', error)\n }\n },\n [api, globalSlug, setDocumentIsLocked, hasLockedDocumentsCollection],\n )\n\n const updateDocumentEditor = useCallback(\n async (docID: number | string, slug: string, user: ClientUser | number | string) => {\n // Check if the locked-documents collection exists before making API calls\n if (!hasLockedDocumentsCollection) {\n return\n }\n\n try {\n const isGlobal = slug === globalSlug\n\n // Check if the document is already locked\n const request = await requests.get(\n formatAdminURL({ apiRoute: api, path: '/payload-locked-documents' }),\n {\n credentials: 'include',\n params: isGlobal\n ? {\n 'where[globalSlug][equals]': slug,\n }\n : {\n 'where[document.relationTo][equals]': slug,\n 'where[document.value][equals]': docID,\n },\n },\n )\n\n const { docs } = await request.json()\n\n if (docs?.length > 0) {\n const lockID = docs[0].id\n\n const userData =\n typeof user === 'object'\n ? { relationTo: user.collection, value: user.id }\n : { relationTo: 'users', value: user }\n\n // Send a patch request to update the _lastEdited info\n await requests.patch(\n formatAdminURL({\n apiRoute: api,\n path: `/payload-locked-documents/${lockID}`,\n }),\n {\n body: JSON.stringify({\n user: userData,\n }),\n credentials: 'include',\n headers: {\n 'Content-Type': 'application/json',\n },\n },\n )\n }\n } catch (error) {\n // eslint-disable-next-line no-console\n console.error('Failed to update the document editor', error)\n }\n },\n [api, globalSlug, hasLockedDocumentsCollection],\n )\n\n const getDocPermissions = useGetDocPermissions({\n id: id as string,\n api,\n collectionSlug,\n globalSlug,\n i18n,\n locale,\n permissions,\n setDocPermissions,\n setHasPublishPermission,\n setHasSavePermission,\n })\n\n const getDocPreferences = useCallback(() => {\n return getPreference<DocumentPreferences>(preferencesKey)\n }, [getPreference, preferencesKey])\n\n const setDocFieldPreferences = useCallback<DocumentInfoContext['setDocFieldPreferences']>(\n async (path, fieldPreferences) => {\n const allPreferences = await getDocPreferences()\n\n if (preferencesKey) {\n try {\n await setPreference(preferencesKey, {\n ...allPreferences,\n fields: {\n ...(allPreferences?.fields || {}),\n [path]: {\n ...allPreferences?.fields?.[path],\n ...fieldPreferences,\n },\n },\n })\n } catch (e) {\n console.error(e) // eslint-disable-line no-console\n }\n }\n },\n [setPreference, preferencesKey, getDocPreferences],\n )\n\n const incrementVersionCount = useCallback(() => {\n const newCount = versionCount + 1\n if (collectionConfig && collectionConfig.versions) {\n if (collectionConfig.versions.maxPerDoc > 0) {\n setVersionCount(Math.min(newCount, collectionConfig.versions.maxPerDoc))\n } else {\n setVersionCount(newCount)\n }\n } else if (globalConfig && globalConfig.versions) {\n if (globalConfig.versions.max > 0) {\n setVersionCount(Math.min(newCount, globalConfig.versions.max))\n } else {\n setVersionCount(newCount)\n }\n }\n }, [collectionConfig, globalConfig, versionCount])\n\n /**\n * @todo: Remove this in v4\n * Users should use the `DocumentTitleContext` instead.\n */\n useEffect(() => {\n setDocumentTitle(\n formatDocTitle({\n collectionConfig,\n data: { ...data, id },\n dateFormat,\n fallback: id?.toString(),\n globalConfig,\n i18n,\n }),\n )\n }, [collectionConfig, globalConfig, data, dateFormat, i18n, id])\n\n // clean on unmount\n useEffect(() => {\n const re1 = abortControllerRef.current\n\n return () => {\n if (re1) {\n try {\n re1.abort()\n } catch (_err) {\n // swallow error\n }\n }\n }\n }, [])\n\n const action: string = React.useMemo(() => {\n const docPath: `/${string}` = `${pluralType === 'globals' ? `/globals` : ''}/${slug}${id ? `/${id}` : ''}`\n\n return formatAdminURL({\n apiRoute: api,\n path: `${docPath}${qs.stringify(\n {\n depth: 0,\n 'fallback-locale': 'null',\n locale,\n uploadEdits: uploadEdits || undefined,\n },\n {\n addQueryPrefix: true,\n },\n )}`,\n })\n }, [api, locale, pluralType, id, slug, uploadEdits])\n\n const value: DocumentInfoContext = {\n ...props,\n action,\n currentEditor,\n data,\n docConfig,\n docPermissions,\n documentIsLocked,\n documentLockState,\n getDocPermissions,\n getDocPreferences,\n hasPublishedDoc,\n hasPublishPermission,\n hasSavePermission,\n incrementVersionCount,\n initialData,\n initialState,\n isInitializing,\n lastUpdateTime,\n mostRecentVersionIsAutosaved,\n preferencesKey,\n savedDocumentData: data,\n setCurrentEditor,\n setData,\n setDocFieldPreferences,\n setDocumentIsLocked,\n setDocumentTitle,\n setHasPublishedDoc,\n setLastUpdateTime,\n setMostRecentVersionIsAutosaved,\n setUnpublishedVersionCount,\n setUploadStatus: updateUploadStatus,\n title,\n unlockDocument,\n unpublishedVersionCount,\n updateDocumentEditor,\n updateSavedDocumentData: setData,\n uploadStatus,\n versionCount,\n }\n\n return (\n <Context value={value}>\n <DocumentTitleProvider>{children}</DocumentTitleProvider>\n </Context>\n )\n}\n\nexport const DocumentInfoProvider: React.FC<\n {\n readonly children: React.ReactNode\n } & Doc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AA,EAAaA,WAAA,IAAe4B;MAC9B,GACA;QACEiD,cAAA,EAAgB;MAClB;IAEJ;EACF,GAAG,CAACzF,GAAA,EAAKqC,MAAA,EAAQI,UAAA,EAAY3E,EAAA,EAAIyC,IAAA,EAAMK,WAAA,CAAY;EAEnD,MAAMmD,KAAA,GAA6B;IACjC,GAAGlG,KAAK;IACRyH,MAAA;IACAtH,aAAA;IACA+C,IAAA;IACAL,SAAA;IACAxC,cAAA;IACAoD,gBAAA;IACAO,iBAAA;IACAuC,iBAAA;IACAC,iBAAA;IACAhG,eAAA;IACAE,oBAAA;IACAE,iBAAA;IACAkG,qBAAA;IACAhG,WAAA;IACAC,YAAA;IACA2D,cAAA;IACAxD,cAAA;IACAE,4BAAA;IACAyD,cAAA;IACAgD,iBAAA,EAAmB3E,IAAA;IACnBS,gBAAA;IACAE,OAAA;IACA4C,sBAAA;IACA/C,mBAAA;IACAT,gBAAA;IACAM,kBAAA;IACAK,iBAAA;IACAP,+BAAA;IACAG,0BAAA;IACAO,eAAA,EAAiBI,kBAAA;IACjBnB,KAAA;IACA8B,cAAA;IACAxD,uBAAA;IACAyE,oBAAA;IACA+B,uBAAA,EAAyBjE,OAAA;IACzBC,YAAA;IACAtC;EACF;EAEA,oBACEuG,IAAA,CAACnI,OAAA;IAAQsG,KAAA,EAAOA,KAAA;cACd,aAAA6B,IAAA,CAAC3I,qBAAA;gBAAuBW;;;AAG9B;AAEA,OAAO,MAAMiI,oBAAA,GAIRhI,KAAA;EACH,oBACE+H,IAAA,CAACtI,mBAAA;cACC,aAAAsI,IAAA,CAACjI,YAAA;MAAc,GAAGE;;;AAGxB","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/Locale/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAIrC,OAAO,KAA0D,MAAM,OAAO,CAAA;AAQ9E,eAAO,MAAM,oBAAoB;;4BAEP,OAAO;EAC/B,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/Locale/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAA;AAIrC,OAAO,KAA0D,MAAM,OAAO,CAAA;AAQ9E,eAAO,MAAM,oBAAoB;;4BAEP,OAAO;EAC/B,CAAA;AAoBF,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,EAAE,CAAC;IAAE,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,CAAA;CAAE,CAuF5F,CAAA;AAED,eAAO,MAAM,gBAAgB;;4BA9GH,OAAO;CA8G8B,CAAA;AAE/D;;;GAGG;AACH,eAAO,MAAM,SAAS,QAAO,MAA4B,CAAA"}
|
|
@@ -13,7 +13,10 @@ export const LocaleLoadingContext = /*#__PURE__*/createContext({
|
|
|
13
13
|
localeIsLoading: false,
|
|
14
14
|
setLocaleIsLoading: _ => undefined
|
|
15
15
|
});
|
|
16
|
-
const fetchPreferences = async (key,
|
|
16
|
+
const fetchPreferences = async (key, apiRoute) => await fetch(formatAdminURL({
|
|
17
|
+
apiRoute,
|
|
18
|
+
path: `/payload-preferences/${key}`
|
|
19
|
+
}), {
|
|
17
20
|
credentials: 'include',
|
|
18
21
|
headers: {
|
|
19
22
|
'Content-Type': 'application/json'
|
|
@@ -21,7 +24,7 @@ const fetchPreferences = async (key, baseURL) => await fetch(`${baseURL}/payload
|
|
|
21
24
|
method: 'GET'
|
|
22
25
|
})?.then(res => res.json());
|
|
23
26
|
export const LocaleProvider = t0 => {
|
|
24
|
-
const $ = _c(
|
|
27
|
+
const $ = _c(26);
|
|
25
28
|
const {
|
|
26
29
|
children,
|
|
27
30
|
locale: initialLocaleFromPrefs
|
|
@@ -89,23 +92,11 @@ export const LocaleProvider = t0 => {
|
|
|
89
92
|
}
|
|
90
93
|
useEffect(t7, t8);
|
|
91
94
|
let t9;
|
|
92
|
-
if ($[10] !== apiRoute) {
|
|
93
|
-
t9 =
|
|
94
|
-
apiRoute,
|
|
95
|
-
path: ""
|
|
96
|
-
});
|
|
97
|
-
$[10] = apiRoute;
|
|
98
|
-
$[11] = t9;
|
|
99
|
-
} else {
|
|
100
|
-
t9 = $[11];
|
|
101
|
-
}
|
|
102
|
-
const fetchURL = t9;
|
|
103
|
-
let t10;
|
|
104
|
-
if ($[12] !== defaultLocale || $[13] !== fetchURL || $[14] !== localeFromParams || $[15] !== localization || $[16] !== user?.id) {
|
|
105
|
-
t10 = () => {
|
|
95
|
+
if ($[10] !== apiRoute || $[11] !== defaultLocale || $[12] !== localeFromParams || $[13] !== localization || $[14] !== user?.id) {
|
|
96
|
+
t9 = () => {
|
|
106
97
|
const resetLocale = async function resetLocale() {
|
|
107
98
|
if (localization && user?.id) {
|
|
108
|
-
const localeToUse = localeFromParams || (await fetchPreferences("locale",
|
|
99
|
+
const localeToUse = localeFromParams || (await fetchPreferences("locale", apiRoute)?.then(_temp));
|
|
109
100
|
const newLocale = findLocaleFromCode(localization, localeToUse) || findLocaleFromCode(localization, defaultLocale) || findLocaleFromCode(localization, localization?.locales?.[0]?.code);
|
|
110
101
|
if (newLocale) {
|
|
111
102
|
setLocale(newLocale);
|
|
@@ -114,32 +105,32 @@ export const LocaleProvider = t0 => {
|
|
|
114
105
|
};
|
|
115
106
|
resetLocale();
|
|
116
107
|
};
|
|
117
|
-
$[
|
|
118
|
-
$[
|
|
119
|
-
$[
|
|
120
|
-
$[
|
|
121
|
-
$[
|
|
122
|
-
$[
|
|
108
|
+
$[10] = apiRoute;
|
|
109
|
+
$[11] = defaultLocale;
|
|
110
|
+
$[12] = localeFromParams;
|
|
111
|
+
$[13] = localization;
|
|
112
|
+
$[14] = user?.id;
|
|
113
|
+
$[15] = t9;
|
|
123
114
|
} else {
|
|
124
|
-
|
|
115
|
+
t9 = $[15];
|
|
125
116
|
}
|
|
126
|
-
const
|
|
127
|
-
let
|
|
128
|
-
if ($[
|
|
129
|
-
|
|
130
|
-
$[
|
|
131
|
-
$[
|
|
132
|
-
$[
|
|
133
|
-
$[
|
|
134
|
-
$[
|
|
135
|
-
$[
|
|
117
|
+
const t10 = user?.id;
|
|
118
|
+
let t11;
|
|
119
|
+
if ($[16] !== apiRoute || $[17] !== defaultLocale || $[18] !== localeFromParams || $[19] !== localization || $[20] !== t10) {
|
|
120
|
+
t11 = [apiRoute, defaultLocale, localization, localeFromParams, t10];
|
|
121
|
+
$[16] = apiRoute;
|
|
122
|
+
$[17] = defaultLocale;
|
|
123
|
+
$[18] = localeFromParams;
|
|
124
|
+
$[19] = localization;
|
|
125
|
+
$[20] = t10;
|
|
126
|
+
$[21] = t11;
|
|
136
127
|
} else {
|
|
137
|
-
|
|
128
|
+
t11 = $[21];
|
|
138
129
|
}
|
|
139
|
-
useEffect(
|
|
140
|
-
let
|
|
141
|
-
if ($[
|
|
142
|
-
|
|
130
|
+
useEffect(t9, t11);
|
|
131
|
+
let t12;
|
|
132
|
+
if ($[22] !== children || $[23] !== isLoading || $[24] !== locale) {
|
|
133
|
+
t12 = _jsx(LocaleContext, {
|
|
143
134
|
value: locale,
|
|
144
135
|
children: _jsx(LocaleLoadingContext, {
|
|
145
136
|
value: {
|
|
@@ -149,14 +140,14 @@ export const LocaleProvider = t0 => {
|
|
|
149
140
|
children
|
|
150
141
|
})
|
|
151
142
|
});
|
|
152
|
-
$[
|
|
153
|
-
$[
|
|
154
|
-
$[
|
|
155
|
-
$[
|
|
143
|
+
$[22] = children;
|
|
144
|
+
$[23] = isLoading;
|
|
145
|
+
$[24] = locale;
|
|
146
|
+
$[25] = t12;
|
|
156
147
|
} else {
|
|
157
|
-
|
|
148
|
+
t12 = $[25];
|
|
158
149
|
}
|
|
159
|
-
return
|
|
150
|
+
return t12;
|
|
160
151
|
};
|
|
161
152
|
export const useLocaleLoading = () => use(LocaleLoadingContext);
|
|
162
153
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["c","_c","useSearchParams","formatAdminURL","React","createContext","use","useEffect","useRef","useState","findLocaleFromCode","useAuth","useConfig","LocaleContext","LocaleLoadingContext","localeIsLoading","setLocaleIsLoading","_","undefined","fetchPreferences","key","
|
|
1
|
+
{"version":3,"file":"index.js","names":["c","_c","useSearchParams","formatAdminURL","React","createContext","use","useEffect","useRef","useState","findLocaleFromCode","useAuth","useConfig","LocaleContext","LocaleLoadingContext","localeIsLoading","setLocaleIsLoading","_","undefined","fetchPreferences","key","apiRoute","fetch","path","credentials","headers","method","then","res","json","LocaleProvider","t0","$","children","locale","initialLocaleFromPrefs","config","t1","localization","t2","routes","t3","api","user","defaultLocale","t4","t5","get","localeFromParams","t6","locales","length","code","setLocale","isLoading","prevLocale","t7","t8","current","t9","id","resetLocale","localeToUse","_temp","newLocale","t10","t11","t12","_jsx","value","useLocaleLoading","useLocale"],"sources":["../../../src/providers/Locale/index.tsx"],"sourcesContent":["'use client'\n\nimport type { Locale } from 'payload'\n\nimport { useSearchParams } from 'next/navigation.js'\nimport { formatAdminURL } from 'payload/shared'\nimport React, { createContext, use, useEffect, useRef, useState } from 'react'\n\nimport { findLocaleFromCode } from '../../utilities/findLocaleFromCode.js'\nimport { useAuth } from '../Auth/index.js'\nimport { useConfig } from '../Config/index.js'\n\nconst LocaleContext = createContext({} as Locale)\n\nexport const LocaleLoadingContext = createContext({\n localeIsLoading: false,\n setLocaleIsLoading: (_: boolean) => undefined,\n})\n\nconst fetchPreferences = async <T extends Record<string, unknown> | string>(\n key: string,\n apiRoute: string,\n): Promise<{ id: string; value: T }> =>\n await fetch(\n formatAdminURL({\n apiRoute,\n path: `/payload-preferences/${key}`,\n }),\n {\n credentials: 'include',\n headers: {\n 'Content-Type': 'application/json',\n },\n method: 'GET',\n },\n )?.then((res) => res.json() as Promise<{ id: string; value: T }>)\n\nexport const LocaleProvider: React.FC<{ children?: React.ReactNode; locale?: Locale['code'] }> = ({\n children,\n /**\n The `locale` prop originates from the root layout, which does not have access to search params\n This component uses the `useSearchParams` hook to get the locale from the URL as precedence over this prop\n This prop does not update as the user navigates the site, because the root layout does not re-render\n */\n locale: initialLocaleFromPrefs,\n}) => {\n const {\n config: {\n localization = false,\n routes: { api: apiRoute },\n },\n } = useConfig()\n\n const { user } = useAuth()\n\n const defaultLocale = localization ? localization.defaultLocale : 'en'\n\n const localeFromParams = useSearchParams().get('locale')\n\n const [locale, setLocale] = React.useState<Locale>(() => {\n if (!localization || (localization && !localization.locales.length)) {\n // TODO: return null V4\n return {} as Locale\n }\n\n return (\n findLocaleFromCode(localization, localeFromParams) ||\n findLocaleFromCode(localization, initialLocaleFromPrefs) ||\n findLocaleFromCode(localization, defaultLocale) ||\n findLocaleFromCode(localization, localization.locales[0].code)\n )\n })\n\n const [isLoading, setLocaleIsLoading] = useState(false)\n\n const prevLocale = useRef<Locale>(locale)\n\n useEffect(() => {\n /**\n * We need to set `isLoading` back to false once the locale is detected to be different\n * This happens when the user clicks an anchor link which appends the `?locale=` query param\n * This triggers a client-side navigation, which re-renders the page with the new locale\n * In Next.js, local state is persisted during this type of navigation because components are not unmounted\n */\n if (locale.code !== prevLocale.current.code) {\n setLocaleIsLoading(false)\n }\n\n prevLocale.current = locale\n }, [locale])\n\n useEffect(() => {\n /**\n * This effect should only run when `localeFromParams` changes, i.e. when the user clicks an anchor link\n * The root layout, which sends the initial locale from prefs, will not re-render as the user navigates the site\n * For this reason, we need to fetch the locale from prefs if the search params clears the `locale` query param\n */\n async function resetLocale() {\n if (localization && user?.id) {\n const localeToUse =\n localeFromParams ||\n (await fetchPreferences<Locale['code']>('locale', apiRoute)?.then((res) => res.value))\n\n const newLocale =\n findLocaleFromCode(localization, localeToUse) ||\n findLocaleFromCode(localization, defaultLocale) ||\n findLocaleFromCode(localization, localization?.locales?.[0]?.code)\n\n if (newLocale) {\n setLocale(newLocale)\n }\n }\n }\n\n void resetLocale()\n }, [apiRoute, defaultLocale, localization, localeFromParams, user?.id])\n\n return (\n <LocaleContext value={locale}>\n <LocaleLoadingContext value={{ localeIsLoading: isLoading, setLocaleIsLoading }}>\n {children}\n </LocaleLoadingContext>\n </LocaleContext>\n )\n}\n\nexport const useLocaleLoading = () => use(LocaleLoadingContext)\n\n/**\n * TODO: V4\n * The return type of the `useLocale` hook will change in v4. It will return `null | Locale` instead of `false | {} | Locale`.\n */\nexport const useLocale = (): Locale => use(LocaleContext)\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AAIA,SAASC,eAAe,QAAQ;AAChC,SAASC,cAAc,QAAQ;AAC/B,OAAOC,KAAA,IAASC,aAAa,EAAEC,GAAG,EAAEC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ;AAEvE,SAASC,kBAAkB,QAAQ;AACnC,SAASC,OAAO,QAAQ;AACxB,SAASC,SAAS,QAAQ;AAE1B,MAAMC,aAAA,gBAAgBR,aAAA,CAAc,CAAC;AAErC,OAAO,MAAMS,oBAAA,gBAAuBT,aAAA,CAAc;EAChDU,eAAA,EAAiB;EACjBC,kBAAA,EAAqBC,CAAA,IAAeC;AACtC;AAEA,MAAMC,gBAAA,GAAmB,MAAAA,CACvBC,GAAA,EACAC,QAAA,KAEA,MAAMC,KAAA,CACJnB,cAAA,CAAe;EACbkB,QAAA;EACAE,IAAA,EAAM,wBAAwBH,GAAA;AAChC,IACA;EACEI,WAAA,EAAa;EACbC,OAAA,EAAS;IACP,gBAAgB;EAClB;EACAC,MAAA,EAAQ;AACV,IACCC,IAAA,CAAMC,GAAA,IAAQA,GAAA,CAAIC,IAAI;AAE3B,OAAO,MAAMC,cAAA,GAAoFC,EAAA;EAAA,MAAAC,CAAA,GAAA/B,EAAA;EAAC;IAAAgC,QAAA;IAAAC,MAAA,EAAAC;EAAA,IAAAJ,EAQjG;EACC;IAAAK,MAAA,EAAAC;EAAA,IAKIzB,SAAA;EAJM;IAAA0B,YAAA,EAAAC,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AIA,OAAO,MAAMyD,SAAA,GAAYA,CAAA,KAAcjE,GAAA,CAAIO,aAAA;AA/FsD,SAAAkD,MAAAnC,GAAA;EAAA,OAgEZA,GAAA,CAAAyC,KAAA;AAAA","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/UploadHandlers/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAEnD,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/providers/UploadHandlers/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAEnD,OAAO,KAAuC,MAAM,OAAO,CAAA;AAE3D,KAAK,aAAa,GAAG,CAAC,IAAI,EAAE;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,IAAI,EAAE,IAAI,CAAA;IACV,cAAc,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,IAAI,CAAA;CAC3C,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;AAEtB,MAAM,MAAM,qBAAqB,GAAG;IAClC,gBAAgB,EAAE,CAAC,IAAI,EAAE;QAAE,cAAc,EAAE,oBAAoB,CAAA;KAAE,KAAK,IAAI,GAAG,aAAa,CAAA;IAC1F,gBAAgB,EAAE,CAAC,IAAI,EAAE;QACvB,cAAc,EAAE,oBAAoB,CAAA;QACpC,OAAO,EAAE,aAAa,CAAA;KACvB,KAAK,OAAO,CAAA;CACd,CAAA;AAID,eAAO,MAAM,sBAAsB;;uBAuBlC,CAAA;AAED,eAAO,MAAM,iBAAiB,QAAO,qBAQpC,CAAA"}
|
|
@@ -1,63 +1,31 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import { c as _c } from "react/compiler-runtime";
|
|
4
3
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
-
import React, {
|
|
4
|
+
import React, { useCallback, useMemo, useRef } from 'react';
|
|
6
5
|
const Context = /*#__PURE__*/React.createContext(null);
|
|
7
|
-
export const UploadHandlersProvider =
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const {
|
|
31
|
-
collectionSlug: collectionSlug_0,
|
|
32
|
-
handler
|
|
33
|
-
} = t3;
|
|
34
|
-
setUploadHandlers(uploadHandlers_0 => {
|
|
35
|
-
const clone = new Map(uploadHandlers_0);
|
|
36
|
-
clone.set(collectionSlug_0, handler);
|
|
37
|
-
return clone;
|
|
38
|
-
});
|
|
39
|
-
};
|
|
40
|
-
$[2] = t2;
|
|
41
|
-
} else {
|
|
42
|
-
t2 = $[2];
|
|
43
|
-
}
|
|
44
|
-
const setUploadHandler = t2;
|
|
45
|
-
let t3;
|
|
46
|
-
if ($[3] !== children || $[4] !== getUploadHandler) {
|
|
47
|
-
t3 = _jsx(Context, {
|
|
48
|
-
value: {
|
|
49
|
-
getUploadHandler,
|
|
50
|
-
setUploadHandler
|
|
51
|
-
},
|
|
52
|
-
children
|
|
53
|
-
});
|
|
54
|
-
$[3] = children;
|
|
55
|
-
$[4] = getUploadHandler;
|
|
56
|
-
$[5] = t3;
|
|
57
|
-
} else {
|
|
58
|
-
t3 = $[5];
|
|
59
|
-
}
|
|
60
|
-
return t3;
|
|
6
|
+
export const UploadHandlersProvider = ({
|
|
7
|
+
children
|
|
8
|
+
}) => {
|
|
9
|
+
const uploadHandlers = useRef(new Map());
|
|
10
|
+
const getUploadHandler = useCallback(({
|
|
11
|
+
collectionSlug
|
|
12
|
+
}) => {
|
|
13
|
+
return uploadHandlers.current.get(collectionSlug);
|
|
14
|
+
}, []);
|
|
15
|
+
const setUploadHandler = useCallback(({
|
|
16
|
+
collectionSlug: collectionSlug_0,
|
|
17
|
+
handler
|
|
18
|
+
}) => {
|
|
19
|
+
uploadHandlers.current.set(collectionSlug_0, handler);
|
|
20
|
+
}, []);
|
|
21
|
+
const value = useMemo(() => ({
|
|
22
|
+
getUploadHandler,
|
|
23
|
+
setUploadHandler
|
|
24
|
+
}), [getUploadHandler, setUploadHandler]);
|
|
25
|
+
return /*#__PURE__*/_jsx(Context, {
|
|
26
|
+
value: value,
|
|
27
|
+
children: children
|
|
28
|
+
});
|
|
61
29
|
};
|
|
62
30
|
export const useUploadHandlers = () => {
|
|
63
31
|
const context = React.use(Context);
|
|
@@ -66,7 +34,4 @@ export const useUploadHandlers = () => {
|
|
|
66
34
|
}
|
|
67
35
|
return context;
|
|
68
36
|
};
|
|
69
|
-
function _temp() {
|
|
70
|
-
return new Map();
|
|
71
|
-
}
|
|
72
37
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["
|
|
1
|
+
{"version":3,"file":"index.js","names":["React","useCallback","useMemo","useRef","Context","createContext","UploadHandlersProvider","children","uploadHandlers","Map","getUploadHandler","collectionSlug","current","get","setUploadHandler","handler","set","value","_jsx","useUploadHandlers","context","use","Error"],"sources":["../../../src/providers/UploadHandlers/index.tsx"],"sourcesContent":["'use client'\nimport type { UploadCollectionSlug } from 'payload'\n\nimport React, { useCallback, useMemo, useRef } from 'react'\n\ntype UploadHandler = (args: {\n docPrefix?: string\n file: File\n updateFilename: (filename: string) => void\n}) => Promise<unknown>\n\nexport type UploadHandlersContext = {\n getUploadHandler: (args: { collectionSlug: UploadCollectionSlug }) => null | UploadHandler\n setUploadHandler: (args: {\n collectionSlug: UploadCollectionSlug\n handler: UploadHandler\n }) => unknown\n}\n\nconst Context = React.createContext<null | UploadHandlersContext>(null)\n\nexport const UploadHandlersProvider = ({ children }) => {\n const uploadHandlers = useRef<Map<UploadCollectionSlug, UploadHandler>>(new Map())\n\n const getUploadHandler = useCallback<UploadHandlersContext['getUploadHandler']>(\n ({ collectionSlug }) => {\n return uploadHandlers.current.get(collectionSlug)\n },\n [],\n )\n\n const setUploadHandler = useCallback<UploadHandlersContext['setUploadHandler']>(\n ({ collectionSlug, handler }) => {\n uploadHandlers.current.set(collectionSlug, handler)\n },\n [],\n )\n\n const value = useMemo<UploadHandlersContext>(\n () => ({ getUploadHandler, setUploadHandler }),\n [getUploadHandler, setUploadHandler],\n )\n\n return <Context value={value}>{children}</Context>\n}\n\nexport const useUploadHandlers = (): UploadHandlersContext => {\n const context = React.use(Context)\n\n if (context === null) {\n throw new Error('useUploadHandlers must be used within UploadHandlersProvider')\n }\n\n return context\n}\n"],"mappings":"AAAA;;;AAGA,OAAOA,KAAA,IAASC,WAAW,EAAEC,OAAO,EAAEC,MAAM,QAAQ;AAgBpD,MAAMC,OAAA,gBAAUJ,KAAA,CAAMK,aAAa,CAA+B;AAElE,OAAO,MAAMC,sBAAA,GAAyBA,CAAC;EAAEC;AAAQ,CAAE;EACjD,MAAMC,cAAA,GAAiBL,MAAA,CAAiD,IAAIM,GAAA;EAE5E,MAAMC,gBAAA,GAAmBT,WAAA,CACvB,CAAC;IAAEU;EAAc,CAAE;IACjB,OAAOH,cAAA,CAAeI,OAAO,CAACC,GAAG,CAACF,cAAA;EACpC,GACA,EAAE;EAGJ,MAAMG,gBAAA,GAAmBb,WAAA,CACvB,CAAC;IAAEU,cAAc,EAAdA,gBAAc;IAAEI;EAAO,CAAE;IAC1BP,cAAA,CAAeI,OAAO,CAACI,GAAG,CAACL,gBAAA,EAAgBI,OAAA;EAC7C,GACA,EAAE;EAGJ,MAAME,KAAA,GAAQf,OAAA,CACZ,OAAO;IAAEQ,gBAAA;IAAkBI;EAAiB,IAC5C,CAACJ,gBAAA,EAAkBI,gBAAA,CAAiB;EAGtC,oBAAOI,IAAA,CAACd,OAAA;IAAQa,KAAA,EAAOA,KAAA;cAAQV;;AACjC;AAEA,OAAO,MAAMY,iBAAA,GAAoBA,CAAA;EAC/B,MAAMC,OAAA,GAAUpB,KAAA,CAAMqB,GAAG,CAACjB,OAAA;EAE1B,IAAIgB,OAAA,KAAY,MAAM;IACpB,MAAM,IAAIE,KAAA,CAAM;EAClB;EAEA,OAAOF,OAAA;AACT","ignoreList":[]}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// @vitest-environment jsdom
|
|
2
|
+
import React, { act, useEffect, useEffectEvent } from 'react';
|
|
3
|
+
import { createRoot } from 'react-dom/client';
|
|
4
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
5
|
+
import { UploadHandlersProvider, useUploadHandlers } from './index.js';
|
|
6
|
+
const reactActEnvironment = globalThis;
|
|
7
|
+
reactActEnvironment.IS_REACT_ACT_ENVIRONMENT = true;
|
|
8
|
+
describe('UploadHandlersProvider', () => {
|
|
9
|
+
it('registers many upload handlers without rerendering context consumers', async () => {
|
|
10
|
+
const collectionSlugs = Array.from({
|
|
11
|
+
length: 50
|
|
12
|
+
}, (_, index) => `upload-${index}`);
|
|
13
|
+
const container = document.createElement('div');
|
|
14
|
+
const handler = vi.fn(async () => undefined);
|
|
15
|
+
const root = createRoot(container);
|
|
16
|
+
let context;
|
|
17
|
+
let contextConsumerRenderCount = 0;
|
|
18
|
+
document.body.appendChild(container);
|
|
19
|
+
const RegisterUploadHandler = ({
|
|
20
|
+
collectionSlug
|
|
21
|
+
}) => {
|
|
22
|
+
const {
|
|
23
|
+
setUploadHandler
|
|
24
|
+
} = useUploadHandlers();
|
|
25
|
+
const registerUploadHandler = useEffectEvent(() => {
|
|
26
|
+
setUploadHandler({
|
|
27
|
+
collectionSlug,
|
|
28
|
+
handler
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
registerUploadHandler();
|
|
33
|
+
}, []);
|
|
34
|
+
return null;
|
|
35
|
+
};
|
|
36
|
+
const ContextConsumer = () => {
|
|
37
|
+
context = useUploadHandlers();
|
|
38
|
+
contextConsumerRenderCount++;
|
|
39
|
+
return null;
|
|
40
|
+
};
|
|
41
|
+
try {
|
|
42
|
+
await act(async () => {
|
|
43
|
+
root.render(React.createElement(UploadHandlersProvider, null, ...collectionSlugs.map(collectionSlug => React.createElement(RegisterUploadHandler, {
|
|
44
|
+
collectionSlug,
|
|
45
|
+
key: collectionSlug
|
|
46
|
+
})), React.createElement(ContextConsumer)));
|
|
47
|
+
});
|
|
48
|
+
expect(contextConsumerRenderCount).toBe(1);
|
|
49
|
+
expect(context).toBeDefined();
|
|
50
|
+
for (const collectionSlug of collectionSlugs) {
|
|
51
|
+
expect(context?.getUploadHandler({
|
|
52
|
+
collectionSlug
|
|
53
|
+
})).toBe(handler);
|
|
54
|
+
}
|
|
55
|
+
} finally {
|
|
56
|
+
await act(async () => {
|
|
57
|
+
root.unmount();
|
|
58
|
+
});
|
|
59
|
+
container.remove();
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
//# sourceMappingURL=index.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.spec.js","names":["React","act","useEffect","useEffectEvent","createRoot","describe","expect","it","vi","UploadHandlersProvider","useUploadHandlers","reactActEnvironment","globalThis","IS_REACT_ACT_ENVIRONMENT","collectionSlugs","Array","from","length","_","index","container","document","createElement","handler","fn","undefined","root","context","contextConsumerRenderCount","body","appendChild","RegisterUploadHandler","collectionSlug","setUploadHandler","registerUploadHandler","ContextConsumer","render","map","key","toBe","toBeDefined","getUploadHandler","unmount","remove"],"sources":["../../../src/providers/UploadHandlers/index.spec.ts"],"sourcesContent":["// @vitest-environment jsdom\n\nimport type { UploadCollectionSlug } from 'payload'\n\nimport React, { act, useEffect, useEffectEvent } from 'react'\nimport { createRoot } from 'react-dom/client'\nimport { describe, expect, it, vi } from 'vitest'\n\nimport type { UploadHandlersContext } from './index.js'\n\nimport { UploadHandlersProvider, useUploadHandlers } from './index.js'\n\nconst reactActEnvironment = globalThis as typeof globalThis & {\n IS_REACT_ACT_ENVIRONMENT: boolean\n}\n\nreactActEnvironment.IS_REACT_ACT_ENVIRONMENT = true\n\ndescribe('UploadHandlersProvider', () => {\n it('registers many upload handlers without rerendering context consumers', async () => {\n const collectionSlugs = Array.from(\n { length: 50 },\n (_, index) => `upload-${index}` as UploadCollectionSlug,\n )\n const container = document.createElement('div')\n const handler = vi.fn(async () => undefined)\n const root = createRoot(container)\n let context: undefined | UploadHandlersContext\n let contextConsumerRenderCount = 0\n\n document.body.appendChild(container)\n\n const RegisterUploadHandler = ({\n collectionSlug,\n }: {\n collectionSlug: UploadCollectionSlug\n }) => {\n const { setUploadHandler } = useUploadHandlers()\n const registerUploadHandler = useEffectEvent(() => {\n setUploadHandler({ collectionSlug, handler })\n })\n\n useEffect(() => {\n registerUploadHandler()\n }, [])\n\n return null\n }\n\n const ContextConsumer = () => {\n context = useUploadHandlers()\n contextConsumerRenderCount++\n\n return null\n }\n\n try {\n await act(async () => {\n root.render(\n React.createElement(\n UploadHandlersProvider,\n null,\n ...collectionSlugs.map((collectionSlug) =>\n React.createElement(RegisterUploadHandler, {\n collectionSlug,\n key: collectionSlug,\n }),\n ),\n React.createElement(ContextConsumer),\n ),\n )\n })\n\n expect(contextConsumerRenderCount).toBe(1)\n expect(context).toBeDefined()\n\n for (const collectionSlug of collectionSlugs) {\n expect(context?.getUploadHandler({ collectionSlug })).toBe(handler)\n }\n } finally {\n await act(async () => {\n root.unmount()\n })\n container.remove()\n }\n })\n})\n"],"mappings":"AAAA;AAIA,OAAOA,KAAA,IAASC,GAAG,EAAEC,SAAS,EAAEC,cAAc,QAAQ;AACtD,SAASC,UAAU,QAAQ;AAC3B,SAASC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,EAAEC,EAAE,QAAQ;AAIzC,SAASC,sBAAsB,EAAEC,iBAAiB,QAAQ;AAE1D,M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