@payloadcms/next 3.72.0-canary.1 → 3.72.0-canary.3
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/prod/styles.css +1 -1
- package/dist/views/API/index.client.d.ts.map +1 -1
- package/dist/views/API/index.client.js +4 -2
- package/dist/views/API/index.client.js.map +1 -1
- package/dist/views/Document/getVersions.d.ts.map +1 -1
- package/dist/views/Document/getVersions.js +49 -26
- package/dist/views/Document/getVersions.js.map +1 -1
- package/dist/views/Version/VersionPillLabel/VersionPillLabel.d.ts +5 -9
- package/dist/views/Version/VersionPillLabel/VersionPillLabel.d.ts.map +1 -1
- package/dist/views/Version/VersionPillLabel/VersionPillLabel.js.map +1 -1
- package/dist/views/Version/VersionPillLabel/getVersionLabel.d.ts +8 -2
- package/dist/views/Version/VersionPillLabel/getVersionLabel.d.ts.map +1 -1
- package/dist/views/Version/VersionPillLabel/getVersionLabel.js +27 -14
- package/dist/views/Version/VersionPillLabel/getVersionLabel.js.map +1 -1
- package/dist/views/Version/index.js +1 -1
- package/dist/views/Version/index.js.map +1 -1
- package/dist/views/Versions/buildColumns.d.ts +2 -8
- package/dist/views/Versions/buildColumns.d.ts.map +1 -1
- package/dist/views/Versions/buildColumns.js.map +1 -1
- package/dist/views/Versions/cells/AutosaveCell/index.d.ts +7 -9
- package/dist/views/Versions/cells/AutosaveCell/index.d.ts.map +1 -1
- package/dist/views/Versions/cells/AutosaveCell/index.js.map +1 -1
- package/dist/views/Versions/index.d.ts.map +1 -1
- package/dist/views/Versions/index.js +25 -4
- package/dist/views/Versions/index.js.map +1 -1
- package/package.json +6 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.client.d.ts","sourceRoot":"","sources":["../../../src/views/API/index.client.tsx"],"names":[],"mappings":"AAkBA,OAAO,cAAc,CAAA;AAGrB,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAO9B,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,
|
|
1
|
+
{"version":3,"file":"index.client.d.ts","sourceRoot":"","sources":["../../../src/views/API/index.client.tsx"],"names":[],"mappings":"AAkBA,OAAO,cAAc,CAAA;AAGrB,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAO9B,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EA+LjC,CAAA"}
|
|
@@ -30,7 +30,8 @@ export const APIViewClient = () => {
|
|
|
30
30
|
localization,
|
|
31
31
|
routes: {
|
|
32
32
|
api: apiRoute
|
|
33
|
-
}
|
|
33
|
+
},
|
|
34
|
+
serverURL
|
|
34
35
|
},
|
|
35
36
|
getEntityConfig
|
|
36
37
|
} = useConfig();
|
|
@@ -69,7 +70,8 @@ export const APIViewClient = () => {
|
|
|
69
70
|
}).toString();
|
|
70
71
|
const fetchURL = formatAdminURL({
|
|
71
72
|
apiRoute,
|
|
72
|
-
path: `${docEndpoint}?${params}
|
|
73
|
+
path: `${docEndpoint}?${params}`,
|
|
74
|
+
serverURL: serverURL || window.location.origin
|
|
73
75
|
});
|
|
74
76
|
React.useEffect(() => {
|
|
75
77
|
const fetchData = async () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.client.js","names":["CheckboxField","CopyToClipboard","Form","Gutter","MinimizeMaximizeIcon","NumberField","SetDocumentStepNav","toast","useConfig","useDocumentInfo","useLocale","useTranslation","useSearchParams","formatAdminURL","hasDraftsEnabled","React","LocaleSelector","RenderJSON","baseClass","APIViewClient","id","collectionSlug","globalSlug","initialData","isTrashed","searchParams","i18n","t","code","config","defaultDepth","localization","routes","api","apiRoute","getEntityConfig","collectionConfig","globalConfig","localeOptions","locales","map","locale","label","value","draftsEnabled","docEndpoint","undefined","data","setData","useState","draft","setDraft","get","setLocale","depth","setDepth","toString","authenticated","setAuthenticated","fullscreen","setFullscreen","trashParam","deletedAt","params","URLSearchParams","String","trash","fetchURL","path","useEffect","fetchData","res","fetch","credentials","headers","language","method","json","error","console","_jsxs","className","filter","Boolean","join","right","_jsx","globalLabel","pluralLabel","labels","plural","useAsTitle","admin","view","href","rel","target","initialState","initialValue","valid","Number","field","name","onChange","step","max","min","onClick","type","isMinimized","object"],"sources":["../../../src/views/API/index.client.tsx"],"sourcesContent":["'use client'\n\nimport {\n CheckboxField,\n CopyToClipboard,\n Form,\n Gutter,\n MinimizeMaximizeIcon,\n NumberField,\n SetDocumentStepNav,\n toast,\n useConfig,\n useDocumentInfo,\n useLocale,\n useTranslation,\n} from '@payloadcms/ui'\nimport { useSearchParams } from 'next/navigation.js'\n\nimport './index.scss'\n\nimport { formatAdminURL, hasDraftsEnabled } from 'payload/shared'\nimport * as React from 'react'\n\nimport { LocaleSelector } from './LocaleSelector/index.js'\nimport { RenderJSON } from './RenderJSON/index.js'\n\nconst baseClass = 'query-inspector'\n\nexport const APIViewClient: React.FC = () => {\n const { id, collectionSlug, globalSlug, initialData, isTrashed } = useDocumentInfo()\n\n const searchParams = useSearchParams()\n const { i18n, t } = useTranslation()\n const { code } = useLocale()\n\n const {\n config: {\n defaultDepth,\n localization,\n routes: { api: apiRoute },\n },\n getEntityConfig,\n } = useConfig()\n\n const collectionConfig = getEntityConfig({ collectionSlug })\n const globalConfig = getEntityConfig({ globalSlug })\n\n const localeOptions =\n localization &&\n localization.locales.map((locale) => ({ label: locale.label, value: locale.code }))\n\n let draftsEnabled: boolean = false\n let docEndpoint: `/${string}` = undefined\n\n if (collectionConfig) {\n draftsEnabled = hasDraftsEnabled(collectionConfig)\n docEndpoint = `/${collectionSlug}/${id}`\n }\n\n if (globalConfig) {\n draftsEnabled = hasDraftsEnabled(globalConfig)\n docEndpoint = `/globals/${globalSlug}`\n }\n\n const [data, setData] = React.useState<any>(initialData)\n const [draft, setDraft] = React.useState<boolean>(searchParams.get('draft') === 'true')\n const [locale, setLocale] = React.useState<string>(searchParams?.get('locale') || code)\n const [depth, setDepth] = React.useState<string>(\n searchParams.get('depth') || defaultDepth.toString(),\n )\n const [authenticated, setAuthenticated] = React.useState<boolean>(true)\n const [fullscreen, setFullscreen] = React.useState<boolean>(false)\n\n const trashParam = typeof initialData?.deletedAt === 'string'\n\n const params = new URLSearchParams({\n depth,\n draft: String(draft),\n locale,\n trash: trashParam ? 'true' : 'false',\n }).toString()\n\n const fetchURL = formatAdminURL({\n apiRoute,\n path: `${docEndpoint}?${params}`,\n })\n\n React.useEffect(() => {\n const fetchData = async () => {\n try {\n const res = await fetch(fetchURL, {\n credentials: authenticated ? 'include' : 'omit',\n headers: {\n 'Accept-Language': i18n.language,\n },\n method: 'GET',\n })\n\n try {\n const json = await res.json()\n setData(json)\n } catch (error) {\n toast.error('Error parsing response')\n console.error(error) // eslint-disable-line no-console\n }\n } catch (error) {\n toast.error('Error making request')\n console.error(error) // eslint-disable-line no-console\n }\n }\n\n void fetchData()\n }, [i18n.language, fetchURL, authenticated])\n\n return (\n <Gutter\n className={[baseClass, fullscreen && `${baseClass}--fullscreen`].filter(Boolean).join(' ')}\n right={false}\n >\n <SetDocumentStepNav\n collectionSlug={collectionSlug}\n globalLabel={globalConfig?.label}\n globalSlug={globalSlug}\n id={id}\n isTrashed={isTrashed}\n pluralLabel={collectionConfig ? collectionConfig?.labels?.plural : undefined}\n useAsTitle={collectionConfig ? collectionConfig?.admin?.useAsTitle : undefined}\n view=\"API\"\n />\n <div className={`${baseClass}__configuration`}>\n <div className={`${baseClass}__api-url`}>\n <span className={`${baseClass}__label`}>\n API URL <CopyToClipboard value={fetchURL} />\n </span>\n <a href={fetchURL} rel=\"noopener noreferrer\" target=\"_blank\">\n {fetchURL}\n </a>\n </div>\n <Form\n initialState={{\n authenticated: {\n initialValue: authenticated || false,\n valid: true,\n value: authenticated || false,\n },\n depth: {\n initialValue: Number(depth || 0),\n valid: true,\n value: Number(depth || 0),\n },\n draft: {\n initialValue: draft || false,\n valid: true,\n value: draft || false,\n },\n locale: {\n initialValue: locale,\n valid: true,\n value: locale,\n },\n }}\n >\n <div className={`${baseClass}__form-fields`}>\n <div className={`${baseClass}__filter-query-checkboxes`}>\n {draftsEnabled && (\n <CheckboxField\n field={{\n name: 'draft',\n label: t('version:draft'),\n }}\n onChange={() => setDraft(!draft)}\n path=\"draft\"\n />\n )}\n <CheckboxField\n field={{\n name: 'authenticated',\n label: t('authentication:authenticated'),\n }}\n onChange={() => setAuthenticated(!authenticated)}\n path=\"authenticated\"\n />\n </div>\n {localeOptions && <LocaleSelector localeOptions={localeOptions} onChange={setLocale} />}\n <NumberField\n field={{\n name: 'depth',\n admin: {\n step: 1,\n },\n label: t('general:depth'),\n max: 10,\n min: 0,\n }}\n onChange={(value) => setDepth(value?.toString())}\n path=\"depth\"\n />\n </div>\n </Form>\n </div>\n <div className={`${baseClass}__results-wrapper`}>\n <div className={`${baseClass}__toggle-fullscreen-button-container`}>\n <button\n aria-label=\"toggle fullscreen\"\n className={`${baseClass}__toggle-fullscreen-button`}\n onClick={() => setFullscreen(!fullscreen)}\n type=\"button\"\n >\n <MinimizeMaximizeIcon isMinimized={!fullscreen} />\n </button>\n </div>\n <div className={`${baseClass}__results`}>\n <RenderJSON object={data} />\n </div>\n </div>\n </Gutter>\n )\n}\n"],"mappings":"AAAA;;;AAEA,SACEA,aAAa,EACbC,eAAe,EACfC,IAAI,EACJC,MAAM,EACNC,oBAAoB,EACpBC,WAAW,EACXC,kBAAkB,EAClBC,KAAK,EACLC,SAAS,EACTC,eAAe,EACfC,SAAS,EACTC,cAAc,QACT;AACP,SAASC,eAAe,QAAQ;AAIhC,SAASC,cAAc,EAAEC,gBAAgB,QAAQ;AACjD,YAAYC,KAAA,MAAW;AAEvB,SAASC,cAAc,QAAQ;AAC/B,SAASC,UAAU,QAAQ;AAE3B,MAAMC,SAAA,GAAY;AAElB,OAAO,MAAMC,aAAA,GAA0BA,CAAA;EACrC,MAAM;IAAEC,EAAE;IAAEC,cAAc;IAAEC,UAAU;IAAEC,WAAW;IAAEC;EAAS,CAAE,GAAGf,eAAA;EAEnE,MAAMgB,YAAA,GAAeb,eAAA;EACrB,MAAM;IAAE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AA,sCAA+C;kBAChE,aAAAoE,IAAA,CAAC;UACC,cAAW;UACXL,SAAA,EAAW,GAAG/D,SAAA,4BAAqC;UACnDyF,OAAA,EAASA,CAAA,KAAM/C,aAAA,CAAc,CAACD,UAAA;UAC9BiD,IAAA,EAAK;oBAEL,aAAAtB,IAAA,CAAClF,oBAAA;YAAqByG,WAAA,EAAa,CAAClD;;;uBAGxC2B,IAAA,CAAC;QAAIL,SAAA,EAAW,GAAG/D,SAAA,WAAoB;kBACrC,aAAAoE,IAAA,CAACrE,UAAA;UAAW6F,MAAA,EAAQ/D;;;;;AAK9B","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"index.client.js","names":["CheckboxField","CopyToClipboard","Form","Gutter","MinimizeMaximizeIcon","NumberField","SetDocumentStepNav","toast","useConfig","useDocumentInfo","useLocale","useTranslation","useSearchParams","formatAdminURL","hasDraftsEnabled","React","LocaleSelector","RenderJSON","baseClass","APIViewClient","id","collectionSlug","globalSlug","initialData","isTrashed","searchParams","i18n","t","code","config","defaultDepth","localization","routes","api","apiRoute","serverURL","getEntityConfig","collectionConfig","globalConfig","localeOptions","locales","map","locale","label","value","draftsEnabled","docEndpoint","undefined","data","setData","useState","draft","setDraft","get","setLocale","depth","setDepth","toString","authenticated","setAuthenticated","fullscreen","setFullscreen","trashParam","deletedAt","params","URLSearchParams","String","trash","fetchURL","path","window","location","origin","useEffect","fetchData","res","fetch","credentials","headers","language","method","json","error","console","_jsxs","className","filter","Boolean","join","right","_jsx","globalLabel","pluralLabel","labels","plural","useAsTitle","admin","view","href","rel","target","initialState","initialValue","valid","Number","field","name","onChange","step","max","min","onClick","type","isMinimized","object"],"sources":["../../../src/views/API/index.client.tsx"],"sourcesContent":["'use client'\n\nimport {\n CheckboxField,\n CopyToClipboard,\n Form,\n Gutter,\n MinimizeMaximizeIcon,\n NumberField,\n SetDocumentStepNav,\n toast,\n useConfig,\n useDocumentInfo,\n useLocale,\n useTranslation,\n} from '@payloadcms/ui'\nimport { useSearchParams } from 'next/navigation.js'\n\nimport './index.scss'\n\nimport { formatAdminURL, hasDraftsEnabled } from 'payload/shared'\nimport * as React from 'react'\n\nimport { LocaleSelector } from './LocaleSelector/index.js'\nimport { RenderJSON } from './RenderJSON/index.js'\n\nconst baseClass = 'query-inspector'\n\nexport const APIViewClient: React.FC = () => {\n const { id, collectionSlug, globalSlug, initialData, isTrashed } = useDocumentInfo()\n\n const searchParams = useSearchParams()\n const { i18n, t } = useTranslation()\n const { code } = useLocale()\n\n const {\n config: {\n defaultDepth,\n localization,\n routes: { api: apiRoute },\n serverURL,\n },\n getEntityConfig,\n } = useConfig()\n\n const collectionConfig = getEntityConfig({ collectionSlug })\n const globalConfig = getEntityConfig({ globalSlug })\n\n const localeOptions =\n localization &&\n localization.locales.map((locale) => ({ label: locale.label, value: locale.code }))\n\n let draftsEnabled: boolean = false\n let docEndpoint: `/${string}` = undefined\n\n if (collectionConfig) {\n draftsEnabled = hasDraftsEnabled(collectionConfig)\n docEndpoint = `/${collectionSlug}/${id}`\n }\n\n if (globalConfig) {\n draftsEnabled = hasDraftsEnabled(globalConfig)\n docEndpoint = `/globals/${globalSlug}`\n }\n\n const [data, setData] = React.useState<any>(initialData)\n const [draft, setDraft] = React.useState<boolean>(searchParams.get('draft') === 'true')\n const [locale, setLocale] = React.useState<string>(searchParams?.get('locale') || code)\n const [depth, setDepth] = React.useState<string>(\n searchParams.get('depth') || defaultDepth.toString(),\n )\n const [authenticated, setAuthenticated] = React.useState<boolean>(true)\n const [fullscreen, setFullscreen] = React.useState<boolean>(false)\n\n const trashParam = typeof initialData?.deletedAt === 'string'\n\n const params = new URLSearchParams({\n depth,\n draft: String(draft),\n locale,\n trash: trashParam ? 'true' : 'false',\n }).toString()\n\n const fetchURL = formatAdminURL({\n apiRoute,\n path: `${docEndpoint}?${params}`,\n serverURL: serverURL || window.location.origin,\n })\n\n React.useEffect(() => {\n const fetchData = async () => {\n try {\n const res = await fetch(fetchURL, {\n credentials: authenticated ? 'include' : 'omit',\n headers: {\n 'Accept-Language': i18n.language,\n },\n method: 'GET',\n })\n\n try {\n const json = await res.json()\n setData(json)\n } catch (error) {\n toast.error('Error parsing response')\n console.error(error) // eslint-disable-line no-console\n }\n } catch (error) {\n toast.error('Error making request')\n console.error(error) // eslint-disable-line no-console\n }\n }\n\n void fetchData()\n }, [i18n.language, fetchURL, authenticated])\n\n return (\n <Gutter\n className={[baseClass, fullscreen && `${baseClass}--fullscreen`].filter(Boolean).join(' ')}\n right={false}\n >\n <SetDocumentStepNav\n collectionSlug={collectionSlug}\n globalLabel={globalConfig?.label}\n globalSlug={globalSlug}\n id={id}\n isTrashed={isTrashed}\n pluralLabel={collectionConfig ? collectionConfig?.labels?.plural : undefined}\n useAsTitle={collectionConfig ? collectionConfig?.admin?.useAsTitle : undefined}\n view=\"API\"\n />\n <div className={`${baseClass}__configuration`}>\n <div className={`${baseClass}__api-url`}>\n <span className={`${baseClass}__label`}>\n API URL <CopyToClipboard value={fetchURL} />\n </span>\n <a href={fetchURL} rel=\"noopener noreferrer\" target=\"_blank\">\n {fetchURL}\n </a>\n </div>\n <Form\n initialState={{\n authenticated: {\n initialValue: authenticated || false,\n valid: true,\n value: authenticated || false,\n },\n depth: {\n initialValue: Number(depth || 0),\n valid: true,\n value: Number(depth || 0),\n },\n draft: {\n initialValue: draft || false,\n valid: true,\n value: draft || false,\n },\n locale: {\n initialValue: locale,\n valid: true,\n value: locale,\n },\n }}\n >\n <div className={`${baseClass}__form-fields`}>\n <div className={`${baseClass}__filter-query-checkboxes`}>\n {draftsEnabled && (\n <CheckboxField\n field={{\n name: 'draft',\n label: t('version:draft'),\n }}\n onChange={() => setDraft(!draft)}\n path=\"draft\"\n />\n )}\n <CheckboxField\n field={{\n name: 'authenticated',\n label: t('authentication:authenticated'),\n }}\n onChange={() => setAuthenticated(!authenticated)}\n path=\"authenticated\"\n />\n </div>\n {localeOptions && <LocaleSelector localeOptions={localeOptions} onChange={setLocale} />}\n <NumberField\n field={{\n name: 'depth',\n admin: {\n step: 1,\n },\n label: t('general:depth'),\n max: 10,\n min: 0,\n }}\n onChange={(value) => setDepth(value?.toString())}\n path=\"depth\"\n />\n </div>\n </Form>\n </div>\n <div className={`${baseClass}__results-wrapper`}>\n <div className={`${baseClass}__toggle-fullscreen-button-container`}>\n <button\n aria-label=\"toggle fullscreen\"\n className={`${baseClass}__toggle-fullscreen-button`}\n onClick={() => setFullscreen(!fullscreen)}\n type=\"button\"\n >\n <MinimizeMaximizeIcon isMinimized={!fullscreen} />\n </button>\n </div>\n <div className={`${baseClass}__results`}>\n <RenderJSON object={data} />\n </div>\n </div>\n </Gutter>\n )\n}\n"],"mappings":"AAAA;;;AAEA,SACEA,aAAa,EACbC,eAAe,EACfC,IAAI,EACJC,MAAM,EACNC,oBAAoB,EACpBC,WAAW,EACXC,kBAAkB,EAClBC,KAAK,EACLC,SAAS,EACTC,eAAe,EACfC,SAAS,EACTC,cAAc,QACT;AACP,SAASC,eAAe,QAAQ;AAIhC,SAASC,cAAc,EAAEC,gBAAgB,QAAQ;AACjD,YAAYC,KAAA,MAAW;AAEvB,SAASC,cAAc,QAAQ;AAC/B,SAASC,UAAU,QAAQ;AAE3B,MAAMC,SAAA,GAAY;AAElB,OAAO,MAAMC,aAAA,GAA0BA,CAAA;EACrC,MAAM;IAAEC,EAAE;IAAEC,cAAc;IAAEC,UAAU;IAAEC,WAAW;IAAEC;EAAS,CAAE,GAAGf,eAAA;EAEnE,MAAMgB,YAAA,GAAeb,eAAA;EACrB,MAAM;IAAEc,IAAI;IAAEC;EAAC,CAAE,GAAGhB,cAAA;EACpB,MAAM;IAAEiB;EAAI,CAAE,GAAGlB,SAAA;EAEjB,MAAM;IACJmB,MAAA,EAAQ;MACNC,YAAY;MACZC,YAAY;MACZC,MAAA,EAAQ;QAAEC,GAAA,EAAKC;MAAQ,CAAE;MACzBC;IAAS,CACV;IACDC;EAAe,CAChB,GAAG5B,SAAA;EAEJ,MAAM6B,gBAAA,GAAmBD,eAAA,CAAg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AA;YAAqB6G,WAAA,EAAa,CAACrD;;;uBAGxC8B,IAAA,CAAC;QAAIL,SAAA,EAAW,GAAGnE,SAAA,WAAoB;kBACrC,aAAAwE,IAAA,CAACzE,UAAA;UAAWiG,MAAA,EAAQlE;;;;;AAK9B","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getVersions.d.ts","sourceRoot":"","sources":["../../../src/views/Document/getVersions.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,OAAO,EACZ,KAAK,yBAAyB,EAC9B,KAAK,4BAA4B,EACjC,KAAK,qBAAqB,EAC1B,KAAK,SAAS,EACf,MAAM,SAAS,CAAA;AAGhB,KAAK,IAAI,GAAG;IACV,gBAAgB,CAAC,EAAE,yBAAyB,CAAA;IAC5C;;;;;OAKG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IACzB,cAAc,EAAE,4BAA4B,CAAA;IAC5C,YAAY,CAAC,EAAE,qBAAqB,CAAA;IACpC,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACpB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,OAAO,CAAA;IAChB,IAAI,EAAE,SAAS,CAAA;CAChB,CAAA;AAED,KAAK,MAAM,GAAG,OAAO,CAAC;IACpB,eAAe,EAAE,OAAO,CAAA;IACxB,4BAA4B,EAAE,OAAO,CAAA;IACrC,uBAAuB,EAAE,MAAM,CAAA;IAC/B,YAAY,EAAE,MAAM,CAAA;CACrB,CAAC,CAAA;AAKF,eAAO,MAAM,WAAW,+FASrB,IAAI,KAAG,
|
|
1
|
+
{"version":3,"file":"getVersions.d.ts","sourceRoot":"","sources":["../../../src/views/Document/getVersions.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,OAAO,EACZ,KAAK,yBAAyB,EAC9B,KAAK,4BAA4B,EACjC,KAAK,qBAAqB,EAC1B,KAAK,SAAS,EACf,MAAM,SAAS,CAAA;AAGhB,KAAK,IAAI,GAAG;IACV,gBAAgB,CAAC,EAAE,yBAAyB,CAAA;IAC5C;;;;;OAKG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IACzB,cAAc,EAAE,4BAA4B,CAAA;IAC5C,YAAY,CAAC,EAAE,qBAAqB,CAAA;IACpC,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACpB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,EAAE,OAAO,CAAA;IAChB,IAAI,EAAE,SAAS,CAAA;CAChB,CAAA;AAED,KAAK,MAAM,GAAG,OAAO,CAAC;IACpB,eAAe,EAAE,OAAO,CAAA;IACxB,4BAA4B,EAAE,OAAO,CAAA;IACrC,uBAAuB,EAAE,MAAM,CAAA;IAC/B,YAAY,EAAE,MAAM,CAAA;CACrB,CAAC,CAAA;AAKF,eAAO,MAAM,WAAW,+FASrB,IAAI,KAAG,MA8QT,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { sanitizeID } from '@payloadcms/ui/shared';
|
|
1
|
+
import { sanitizeID, traverseForLocalizedFields } from '@payloadcms/ui/shared';
|
|
2
2
|
import { combineQueries, extractAccessFromPermission } from 'payload';
|
|
3
3
|
import { hasAutosaveEnabled, hasDraftsEnabled } from 'payload/shared';
|
|
4
4
|
// TODO: in the future, we can parallelize some of these queries
|
|
@@ -22,10 +22,12 @@ export const getVersions = async ({
|
|
|
22
22
|
let versionCount = 0;
|
|
23
23
|
const entityConfig = collectionConfig || globalConfig;
|
|
24
24
|
const versionsConfig = entityConfig?.versions;
|
|
25
|
+
const hasLocalizedFields = traverseForLocalizedFields(entityConfig.fields);
|
|
26
|
+
const localizedDraftsEnabled = hasDraftsEnabled(entityConfig) && typeof payload.config.localization === 'object' && hasLocalizedFields;
|
|
25
27
|
const shouldFetchVersions = Boolean(versionsConfig && docPermissions?.readVersions);
|
|
26
28
|
if (!shouldFetchVersions) {
|
|
27
29
|
// Without readVersions permission, determine published status from the _status field
|
|
28
|
-
const hasPublishedDoc = doc?._status !== 'draft';
|
|
30
|
+
const hasPublishedDoc = localizedDraftsEnabled ? doc?._status === 'published' : doc?._status !== 'draft';
|
|
29
31
|
return {
|
|
30
32
|
hasPublishedDoc,
|
|
31
33
|
mostRecentVersionIsAutosaved,
|
|
@@ -59,15 +61,9 @@ export const getVersions = async ({
|
|
|
59
61
|
user,
|
|
60
62
|
where: {
|
|
61
63
|
and: [{
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
}, {
|
|
67
|
-
_status: {
|
|
68
|
-
exists: false
|
|
69
|
-
}
|
|
70
|
-
}]
|
|
64
|
+
_status: {
|
|
65
|
+
equals: 'published'
|
|
66
|
+
}
|
|
71
67
|
}, {
|
|
72
68
|
id: {
|
|
73
69
|
equals: id
|
|
@@ -80,21 +76,30 @@ export const getVersions = async ({
|
|
|
80
76
|
hasPublishedDoc = true;
|
|
81
77
|
}
|
|
82
78
|
if (hasAutosaveEnabled(collectionConfig)) {
|
|
79
|
+
const where = {
|
|
80
|
+
and: [{
|
|
81
|
+
parent: {
|
|
82
|
+
equals: id
|
|
83
|
+
}
|
|
84
|
+
}]
|
|
85
|
+
};
|
|
86
|
+
if (localizedDraftsEnabled) {
|
|
87
|
+
where.and.push({
|
|
88
|
+
snapshot: {
|
|
89
|
+
not_equals: true
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
83
93
|
const mostRecentVersion = await payload.findVersions({
|
|
84
94
|
collection: collectionConfig.slug,
|
|
85
95
|
depth: 0,
|
|
86
96
|
limit: 1,
|
|
97
|
+
locale,
|
|
87
98
|
select: {
|
|
88
99
|
autosave: true
|
|
89
100
|
},
|
|
90
101
|
user,
|
|
91
|
-
where: combineQueries(
|
|
92
|
-
and: [{
|
|
93
|
-
parent: {
|
|
94
|
-
equals: id
|
|
95
|
-
}
|
|
96
|
-
}]
|
|
97
|
-
}, extractAccessFromPermission(docPermissions.readVersions))
|
|
102
|
+
where: combineQueries(where, extractAccessFromPermission(docPermissions.readVersions))
|
|
98
103
|
});
|
|
99
104
|
if (mostRecentVersion.docs[0] && 'autosave' in mostRecentVersion.docs[0] && mostRecentVersion.docs[0].autosave) {
|
|
100
105
|
mostRecentVersionIsAutosaved = true;
|
|
@@ -105,6 +110,7 @@ export const getVersions = async ({
|
|
|
105
110
|
totalDocs: unpublishedVersionCount
|
|
106
111
|
} = await payload.countVersions({
|
|
107
112
|
collection: collectionConfig.slug,
|
|
113
|
+
locale,
|
|
108
114
|
user,
|
|
109
115
|
where: combineQueries({
|
|
110
116
|
and: [{
|
|
@@ -124,19 +130,28 @@ export const getVersions = async ({
|
|
|
124
130
|
}));
|
|
125
131
|
}
|
|
126
132
|
}
|
|
133
|
+
const countVersionsWhere = {
|
|
134
|
+
and: [{
|
|
135
|
+
parent: {
|
|
136
|
+
equals: id
|
|
137
|
+
}
|
|
138
|
+
}]
|
|
139
|
+
};
|
|
140
|
+
if (localizedDraftsEnabled) {
|
|
141
|
+
countVersionsWhere.and.push({
|
|
142
|
+
snapshot: {
|
|
143
|
+
not_equals: true
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
}
|
|
127
147
|
({
|
|
128
148
|
totalDocs: versionCount
|
|
129
149
|
} = await payload.countVersions({
|
|
130
150
|
collection: collectionConfig.slug,
|
|
131
151
|
depth: 0,
|
|
152
|
+
locale,
|
|
132
153
|
user,
|
|
133
|
-
where: combineQueries(
|
|
134
|
-
and: [{
|
|
135
|
-
parent: {
|
|
136
|
-
equals: id
|
|
137
|
-
}
|
|
138
|
-
}]
|
|
139
|
-
}, extractAccessFromPermission(docPermissions.readVersions))
|
|
154
|
+
where: combineQueries(countVersionsWhere, extractAccessFromPermission(docPermissions.readVersions))
|
|
140
155
|
}));
|
|
141
156
|
}
|
|
142
157
|
if (globalConfig) {
|
|
@@ -162,6 +177,7 @@ export const getVersions = async ({
|
|
|
162
177
|
const mostRecentVersion = await payload.findGlobalVersions({
|
|
163
178
|
slug: globalConfig.slug,
|
|
164
179
|
limit: 1,
|
|
180
|
+
locale,
|
|
165
181
|
select: {
|
|
166
182
|
autosave: true
|
|
167
183
|
},
|
|
@@ -177,6 +193,7 @@ export const getVersions = async ({
|
|
|
177
193
|
} = await payload.countGlobalVersions({
|
|
178
194
|
depth: 0,
|
|
179
195
|
global: globalConfig.slug,
|
|
196
|
+
locale,
|
|
180
197
|
user,
|
|
181
198
|
where: combineQueries({
|
|
182
199
|
and: [{
|
|
@@ -197,7 +214,13 @@ export const getVersions = async ({
|
|
|
197
214
|
} = await payload.countGlobalVersions({
|
|
198
215
|
depth: 0,
|
|
199
216
|
global: globalConfig.slug,
|
|
200
|
-
|
|
217
|
+
locale,
|
|
218
|
+
user,
|
|
219
|
+
where: localizedDraftsEnabled ? {
|
|
220
|
+
snapshot: {
|
|
221
|
+
not_equals: true
|
|
222
|
+
}
|
|
223
|
+
} : undefined
|
|
201
224
|
}));
|
|
202
225
|
}
|
|
203
226
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getVersions.js","names":["sanitizeID","combineQueries","extractAccessFromPermission","hasAutosaveEnabled","hasDraftsEnabled","getVersions","id","idArg","collectionConfig","doc","docPermissions","globalConfig","locale","payload","user","publishedDoc","hasPublishedDoc","mostRecentVersionIsAutosaved","unpublishedVersionCount","versionCount","entityConfig","versionsConfig","versions","shouldFetchVersions","Boolean","readVersions","_status","find","collection","slug","depth","limit","undefined","pagination","select","updatedAt","where","and","or","equals","exists","docs","mostRecentVersion","findVersions","autosave","parent","totalDocs","countVersions","greater_than","findGlobal","findGlobalVersions","countGlobalVersions","global"],"sources":["../../../src/views/Document/getVersions.ts"],"sourcesContent":["import { sanitizeID } from '@payloadcms/ui/shared'\nimport {\n combineQueries,\n extractAccessFromPermission,\n type Payload,\n type SanitizedCollectionConfig,\n type SanitizedDocumentPermissions,\n type SanitizedGlobalConfig,\n type TypedUser,\n} from 'payload'\nimport { hasAutosaveEnabled, hasDraftsEnabled } from 'payload/shared'\n\ntype Args = {\n collectionConfig?: SanitizedCollectionConfig\n /**\n * Optional - performance optimization.\n * If a document has been fetched before fetching versions, pass it here.\n * If this document is set to published, we can skip the query to find out if a published document exists,\n * as the passed in document is proof of its existence.\n */\n doc?: Record<string, any>\n docPermissions: SanitizedDocumentPermissions\n globalConfig?: SanitizedGlobalConfig\n id?: number | string\n locale?: string\n payload: Payload\n user: TypedUser\n}\n\ntype Result = Promise<{\n hasPublishedDoc: boolean\n mostRecentVersionIsAutosaved: boolean\n unpublishedVersionCount: number\n versionCount: number\n}>\n\n// TODO: in the future, we can parallelize some of these queries\n// this will speed up the API by ~30-100ms or so\n// Note from the future: I have attempted parallelizing these queries, but it made this function almost 2x slower.\nexport const getVersions = async ({\n id: idArg,\n collectionConfig,\n doc,\n docPermissions,\n globalConfig,\n locale,\n payload,\n user,\n}: Args): Result => {\n const id = sanitizeID(idArg)\n let publishedDoc\n let hasPublishedDoc = false\n let mostRecentVersionIsAutosaved = false\n let unpublishedVersionCount = 0\n let versionCount = 0\n\n const entityConfig = collectionConfig || globalConfig\n const versionsConfig = entityConfig?.versions\n\n const shouldFetchVersions = Boolean(versionsConfig && docPermissions?.readVersions)\n\n if (!shouldFetchVersions) {\n // Without readVersions permission, determine published status from the _status field\n const hasPublishedDoc = doc?._status !== 'draft'\n\n return {\n hasPublishedDoc,\n mostRecentVersionIsAutosaved,\n unpublishedVersionCount,\n versionCount,\n }\n }\n\n if (collectionConfig) {\n if (!id) {\n return {\n hasPublishedDoc,\n mostRecentVersionIsAutosaved,\n unpublishedVersionCount,\n versionCount,\n }\n }\n\n if (hasDraftsEnabled(collectionConfig)) {\n // Find out if a published document exists\n if (doc?._status === 'published') {\n publishedDoc = doc\n } else {\n publishedDoc = (\n await payload.find({\n collection: collectionConfig.slug,\n depth: 0,\n limit: 1,\n locale: locale || undefined,\n pagination: false,\n select: {\n updatedAt: true,\n },\n user,\n where: {\n and: [\n {\n or: [\n {\n _status: {\n equals: 'published',\n },\n },\n {\n _status: {\n exists: false,\n },\n },\n ],\n },\n {\n id: {\n equals: id,\n },\n },\n ],\n },\n })\n )?.docs?.[0]\n }\n\n if (publishedDoc) {\n hasPublishedDoc = true\n }\n\n if (hasAutosaveEnabled(collectionConfig)) {\n const mostRecentVersion = await payload.findVersions({\n collection: collectionConfig.slug,\n depth: 0,\n limit: 1,\n select: {\n autosave: true,\n },\n user,\n where: combineQueries(\n {\n and: [\n {\n parent: {\n equals: id,\n },\n },\n ],\n },\n extractAccessFromPermission(docPermissions.readVersions),\n ),\n })\n\n if (\n mostRecentVersion.docs[0] &&\n 'autosave' in mostRecentVersion.docs[0] &&\n mostRecentVersion.docs[0].autosave\n ) {\n mostRecentVersionIsAutosaved = true\n }\n }\n\n if (publishedDoc?.updatedAt) {\n ;({ totalDocs: unpublishedVersionCount } = await payload.countVersions({\n collection: collectionConfig.slug,\n user,\n where: combineQueries(\n {\n and: [\n {\n parent: {\n equals: id,\n },\n },\n {\n 'version._status': {\n equals: 'draft',\n },\n },\n {\n updatedAt: {\n greater_than: publishedDoc.updatedAt,\n },\n },\n ],\n },\n extractAccessFromPermission(docPermissions.readVersions),\n ),\n }))\n }\n }\n\n ;({ totalDocs: versionCount } = await payload.countVersions({\n collection: collectionConfig.slug,\n depth: 0,\n user,\n where: combineQueries(\n {\n and: [\n {\n parent: {\n equals: id,\n },\n },\n ],\n },\n extractAccessFromPermission(docPermissions.readVersions),\n ),\n }))\n }\n\n if (globalConfig) {\n // Find out if a published document exists\n if (hasDraftsEnabled(globalConfig)) {\n if (doc?._status === 'published') {\n publishedDoc = doc\n } else {\n publishedDoc = await payload.findGlobal({\n slug: globalConfig.slug,\n depth: 0,\n locale,\n select: {\n updatedAt: true,\n },\n user,\n })\n }\n\n if (publishedDoc?._status === 'published') {\n hasPublishedDoc = true\n }\n\n if (hasAutosaveEnabled(globalConfig)) {\n const mostRecentVersion = await payload.findGlobalVersions({\n slug: globalConfig.slug,\n limit: 1,\n select: {\n autosave: true,\n },\n user,\n })\n\n if (\n mostRecentVersion.docs[0] &&\n 'autosave' in mostRecentVersion.docs[0] &&\n mostRecentVersion.docs[0].autosave\n ) {\n mostRecentVersionIsAutosaved = true\n }\n }\n\n if (publishedDoc?.updatedAt) {\n ;({ totalDocs: unpublishedVersionCount } = await payload.countGlobalVersions({\n depth: 0,\n global: globalConfig.slug,\n user,\n where: combineQueries(\n {\n and: [\n {\n 'version._status': {\n equals: 'draft',\n },\n },\n {\n updatedAt: {\n greater_than: publishedDoc.updatedAt,\n },\n },\n ],\n },\n extractAccessFromPermission(docPermissions.readVersions),\n ),\n }))\n }\n }\n\n ;({ totalDocs: versionCount } = await payload.countGlobalVersions({\n depth: 0,\n global: globalConfig.slug,\n user,\n }))\n }\n\n return {\n hasPublishedDoc,\n mostRecentVersionIsAutosaved,\n unpublishedVersionCount,\n versionCount,\n }\n}\n"],"mappings":"AAAA,SAASA,UAAU,QAAQ;AAC3B,SACEC,cAAc,EACdC,2BAA2B,QAMtB;AACP,SAASC,kBAAkB,EAAEC,gBAAgB,QAAQ;AA0BrD;AACA;AACA;AACA,OAAO,MAAMC,WAAA,GAAc,MAAAA,CAAO;EAChCC,EAAA,EAAIC,KAAK;EACTC,gBAAgB;EAChBC,GAAG;EACHC,cAAc;EACdC,YAAY;EACZC,MAAM;EACNC,OAAO;EACPC;AAAI,CACC;EACL,MAAMR,EAAA,GAAKN,UAAA,CAAWO,KAAA;EACtB,IAAIQ,YAAA;EACJ,IAAIC,eAAA,GAAkB;EACtB,IAAIC,4BAAA,GAA+B;EACnC,IAAIC,uBAAA,GAA0B;EAC9B,IAAIC,YAAA,GAAe;EAEnB,MAAMC,YAAA,GAAeZ,gBAAA,IAAoBG,YAAA;EACzC,MAAMU,cAAA,GAAiBD,YAAA,EAAcE,QAAA;EAErC,MAAMC,mBAAA,GAAsBC,OAAA,CAAQH,cAAA,IAAkBX,cAAA,EAAgBe,YAAA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EAAW3B;IAAY,CAAE,GAAG,MAAMN,OAAA,CAAQsC,mBAAmB,CAAC;MAChErB,KAAA,EAAO;MACPsB,MAAA,EAAQzC,YAAA,CAAakB,IAAI;MACzBf;IACF,EAAC;EACH;EAEA,OAAO;IACLE,eAAA;IACAC,4BAAA;IACAC,uBAAA;IACAC;EACF;AACF","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"getVersions.js","names":["sanitizeID","traverseForLocalizedFields","combineQueries","extractAccessFromPermission","hasAutosaveEnabled","hasDraftsEnabled","getVersions","id","idArg","collectionConfig","doc","docPermissions","globalConfig","locale","payload","user","publishedDoc","hasPublishedDoc","mostRecentVersionIsAutosaved","unpublishedVersionCount","versionCount","entityConfig","versionsConfig","versions","hasLocalizedFields","fields","localizedDraftsEnabled","config","localization","shouldFetchVersions","Boolean","readVersions","_status","find","collection","slug","depth","limit","undefined","pagination","select","updatedAt","where","and","equals","docs","parent","push","snapshot","not_equals","mostRecentVersion","findVersions","autosave","totalDocs","countVersions","greater_than","countVersionsWhere","findGlobal","findGlobalVersions","countGlobalVersions","global"],"sources":["../../../src/views/Document/getVersions.ts"],"sourcesContent":["import { sanitizeID, traverseForLocalizedFields } from '@payloadcms/ui/shared'\nimport {\n combineQueries,\n extractAccessFromPermission,\n type Payload,\n type SanitizedCollectionConfig,\n type SanitizedDocumentPermissions,\n type SanitizedGlobalConfig,\n type TypedUser,\n} from 'payload'\nimport { hasAutosaveEnabled, hasDraftsEnabled } from 'payload/shared'\n\ntype Args = {\n collectionConfig?: SanitizedCollectionConfig\n /**\n * Optional - performance optimization.\n * If a document has been fetched before fetching versions, pass it here.\n * If this document is set to published, we can skip the query to find out if a published document exists,\n * as the passed in document is proof of its existence.\n */\n doc?: Record<string, any>\n docPermissions: SanitizedDocumentPermissions\n globalConfig?: SanitizedGlobalConfig\n id?: number | string\n locale?: string\n payload: Payload\n user: TypedUser\n}\n\ntype Result = Promise<{\n hasPublishedDoc: boolean\n mostRecentVersionIsAutosaved: boolean\n unpublishedVersionCount: number\n versionCount: number\n}>\n\n// TODO: in the future, we can parallelize some of these queries\n// this will speed up the API by ~30-100ms or so\n// Note from the future: I have attempted parallelizing these queries, but it made this function almost 2x slower.\nexport const getVersions = async ({\n id: idArg,\n collectionConfig,\n doc,\n docPermissions,\n globalConfig,\n locale,\n payload,\n user,\n}: Args): Result => {\n const id = sanitizeID(idArg)\n let publishedDoc\n let hasPublishedDoc = false\n let mostRecentVersionIsAutosaved = false\n let unpublishedVersionCount = 0\n let versionCount = 0\n\n const entityConfig = collectionConfig || globalConfig\n const versionsConfig = entityConfig?.versions\n const hasLocalizedFields = traverseForLocalizedFields(entityConfig.fields)\n const localizedDraftsEnabled =\n hasDraftsEnabled(entityConfig) &&\n typeof payload.config.localization === 'object' &&\n hasLocalizedFields\n\n const shouldFetchVersions = Boolean(versionsConfig && docPermissions?.readVersions)\n\n if (!shouldFetchVersions) {\n // Without readVersions permission, determine published status from the _status field\n const hasPublishedDoc = localizedDraftsEnabled\n ? doc?._status === 'published'\n : doc?._status !== 'draft'\n\n return {\n hasPublishedDoc,\n mostRecentVersionIsAutosaved,\n unpublishedVersionCount,\n versionCount,\n }\n }\n\n if (collectionConfig) {\n if (!id) {\n return {\n hasPublishedDoc,\n mostRecentVersionIsAutosaved,\n unpublishedVersionCount,\n versionCount,\n }\n }\n\n if (hasDraftsEnabled(collectionConfig)) {\n // Find out if a published document exists\n if (doc?._status === 'published') {\n publishedDoc = doc\n } else {\n publishedDoc = (\n await payload.find({\n collection: collectionConfig.slug,\n depth: 0,\n limit: 1,\n locale: locale || undefined,\n pagination: false,\n select: {\n updatedAt: true,\n },\n user,\n where: {\n and: [\n {\n _status: {\n equals: 'published',\n },\n },\n {\n id: {\n equals: id,\n },\n },\n ],\n },\n })\n )?.docs?.[0]\n }\n\n if (publishedDoc) {\n hasPublishedDoc = true\n }\n\n if (hasAutosaveEnabled(collectionConfig)) {\n const where: Record<string, any> = {\n and: [\n {\n parent: {\n equals: id,\n },\n },\n ],\n }\n\n if (localizedDraftsEnabled) {\n where.and.push({\n snapshot: {\n not_equals: true,\n },\n })\n }\n\n const mostRecentVersion = await payload.findVersions({\n collection: collectionConfig.slug,\n depth: 0,\n limit: 1,\n locale,\n select: {\n autosave: true,\n },\n user,\n where: combineQueries(where, extractAccessFromPermission(docPermissions.readVersions)),\n })\n\n if (\n mostRecentVersion.docs[0] &&\n 'autosave' in mostRecentVersion.docs[0] &&\n mostRecentVersion.docs[0].autosave\n ) {\n mostRecentVersionIsAutosaved = true\n }\n }\n\n if (publishedDoc?.updatedAt) {\n ;({ totalDocs: unpublishedVersionCount } = await payload.countVersions({\n collection: collectionConfig.slug,\n locale,\n user,\n where: combineQueries(\n {\n and: [\n {\n parent: {\n equals: id,\n },\n },\n {\n 'version._status': {\n equals: 'draft',\n },\n },\n {\n updatedAt: {\n greater_than: publishedDoc.updatedAt,\n },\n },\n ],\n },\n extractAccessFromPermission(docPermissions.readVersions),\n ),\n }))\n }\n }\n\n const countVersionsWhere: Record<string, any> = {\n and: [\n {\n parent: {\n equals: id,\n },\n },\n ],\n }\n\n if (localizedDraftsEnabled) {\n countVersionsWhere.and.push({\n snapshot: {\n not_equals: true,\n },\n })\n }\n\n ;({ totalDocs: versionCount } = await payload.countVersions({\n collection: collectionConfig.slug,\n depth: 0,\n locale,\n user,\n where: combineQueries(\n countVersionsWhere,\n extractAccessFromPermission(docPermissions.readVersions),\n ),\n }))\n }\n\n if (globalConfig) {\n // Find out if a published document exists\n if (hasDraftsEnabled(globalConfig)) {\n if (doc?._status === 'published') {\n publishedDoc = doc\n } else {\n publishedDoc = await payload.findGlobal({\n slug: globalConfig.slug,\n depth: 0,\n locale,\n select: {\n updatedAt: true,\n },\n user,\n })\n }\n\n if (publishedDoc?._status === 'published') {\n hasPublishedDoc = true\n }\n\n if (hasAutosaveEnabled(globalConfig)) {\n const mostRecentVersion = await payload.findGlobalVersions({\n slug: globalConfig.slug,\n limit: 1,\n locale,\n select: {\n autosave: true,\n },\n user,\n })\n\n if (\n mostRecentVersion.docs[0] &&\n 'autosave' in mostRecentVersion.docs[0] &&\n mostRecentVersion.docs[0].autosave\n ) {\n mostRecentVersionIsAutosaved = true\n }\n }\n\n if (publishedDoc?.updatedAt) {\n ;({ totalDocs: unpublishedVersionCount } = await payload.countGlobalVersions({\n depth: 0,\n global: globalConfig.slug,\n locale,\n user,\n where: combineQueries(\n {\n and: [\n {\n 'version._status': {\n equals: 'draft',\n },\n },\n {\n updatedAt: {\n greater_than: publishedDoc.updatedAt,\n },\n },\n ],\n },\n extractAccessFromPermission(docPermissions.readVersions),\n ),\n }))\n }\n }\n\n ;({ totalDocs: versionCount } = await payload.countGlobalVersions({\n depth: 0,\n global: globalConfig.slug,\n locale,\n user,\n where: localizedDraftsEnabled\n ? {\n snapshot: {\n not_equals: true,\n },\n }\n : undefined,\n }))\n }\n\n return {\n hasPublishedDoc,\n mostRecentVersionIsAutosaved,\n unpublishedVersionCount,\n versionCount,\n }\n}\n"],"mappings":"AAAA,SAASA,UAAU,EAAEC,0BAA0B,QAAQ;AACvD,SACEC,cAAc,EACdC,2BAA2B,QAMtB;AACP,SAASC,kBAAkB,EAAEC,gBAAgB,QAAQ;AA0BrD;AACA;AACA;AACA,OAAO,MAAMC,WAAA,GAAc,MAAAA,CAAO;EAChCC,EAAA,EAAIC,KAAK;EACTC,gBAAgB;EAChBC,GAAG;EACHC,cAAc;EACdC,YAAY;EACZC,MAAM;EACNC,OAAO;EACPC;AAAI,CACC;EACL,MAAMR,EAAA,GAAKP,UAAA,CAAWQ,KAAA;EACtB,IAAIQ,YAAA;EACJ,IAAIC,eAAA,GAAkB;EACtB,IAAIC,4BAAA,GAA+B;EACnC,IAAIC,uBAAA,GAA0B;EAC9B,IAAIC,YAAA,GAAe;EAEnB,MAAMC,YAAA,GAAeZ,gBAAA,IAAoBG,YAAA;EACzC,MAAMU,cAAA,GAAiBD,YAAA,EAAcE,QAAA;EACrC,MAAMC,kBAAA,GAAqBvB,0BAAA,CAA2B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AAC,EAAE,IACvCK,iBAAA,CAAkBL,IAAI,CAAC,EAAE,CAACO,QAAQ,EAClC;UACAlC,4BAAA,GAA+B;QACjC;MACF;MAEA,IAAIF,YAAA,EAAcyB,SAAA,EAAW;QACzB;UAAEY,SAAA,EAAWlC;QAAuB,CAAE,GAAG,MAAML,OAAA,CAAQ6C,mBAAmB,CAAC;UAC3EvB,KAAA,EAAO;UACPwB,MAAA,EAAQhD,YAAA,CAAauB,IAAI;UACzBtB,MAAA;UACAE,IAAA;UACA2B,KAAA,EAAOxC,cAAA,CACL;YACEyC,GAAA,EAAK,CACH;cACE,mBAAmB;gBACjBC,MAAA,EAAQ;cACV;YACF,GACA;cACEH,SAAA,EAAW;gBACTc,YAAA,EAAcvC,YAAA,CAAayB;cAC7B;YACF;UAEJ,GACAtC,2BAAA,CAA4BQ,cAAA,CAAeoB,YAAY;QAE3D,EAAC;MACH;IACF;IAEE;MAAEsB,SAAA,EAAWjC;IAAY,CAAE,GAAG,MAAMN,OAAA,CAAQ6C,mBAAmB,CAAC;MAChEvB,KAAA,EAAO;MACPwB,MAAA,EAAQhD,YAAA,CAAauB,IAAI;MACzBtB,MAAA;MACAE,IAAA;MACA2B,KAAA,EAAOhB,sBAAA,GACH;QACEsB,QAAA,EAAU;UACRC,UAAA,EAAY;QACd;MACF,IACAX;IACN,EAAC;EACH;EAEA,OAAO;IACLrB,eAAA;IACAC,4BAAA;IACAC,uBAAA;IACAC;EACF;AACF","ignoreList":[]}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
+
import type { TypeWithVersion } from 'payload';
|
|
1
2
|
import React from 'react';
|
|
2
3
|
import './index.scss';
|
|
3
4
|
export declare const VersionPillLabel: React.FC<{
|
|
4
|
-
currentlyPublishedVersion?:
|
|
5
|
-
id: number | string;
|
|
6
|
-
updatedAt: string;
|
|
7
|
-
};
|
|
5
|
+
currentlyPublishedVersion?: TypeWithVersion<any>;
|
|
8
6
|
disableDate?: boolean;
|
|
9
7
|
doc: {
|
|
10
8
|
[key: string]: unknown;
|
|
@@ -13,7 +11,8 @@ export declare const VersionPillLabel: React.FC<{
|
|
|
13
11
|
updatedAt?: string;
|
|
14
12
|
version: {
|
|
15
13
|
[key: string]: unknown;
|
|
16
|
-
_status:
|
|
14
|
+
_status: 'draft' | 'published';
|
|
15
|
+
updatedAt: string;
|
|
17
16
|
};
|
|
18
17
|
};
|
|
19
18
|
/**
|
|
@@ -27,9 +26,6 @@ export declare const VersionPillLabel: React.FC<{
|
|
|
27
26
|
*/
|
|
28
27
|
labelStyle?: 'pill' | 'text';
|
|
29
28
|
labelSuffix?: React.ReactNode;
|
|
30
|
-
latestDraftVersion?:
|
|
31
|
-
id: number | string;
|
|
32
|
-
updatedAt: string;
|
|
33
|
-
};
|
|
29
|
+
latestDraftVersion?: TypeWithVersion<any>;
|
|
34
30
|
}>;
|
|
35
31
|
//# sourceMappingURL=VersionPillLabel.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VersionPillLabel.d.ts","sourceRoot":"","sources":["../../../../src/views/Version/VersionPillLabel/VersionPillLabel.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"VersionPillLabel.d.ts","sourceRoot":"","sources":["../../../../src/views/Version/VersionPillLabel/VersionPillLabel.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAI9C,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,cAAc,CAAA;AAarB,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,EAAE,CAAC;IACtC,yBAAyB,CAAC,EAAE,eAAe,CAAC,GAAG,CAAC,CAAA;IAChD,WAAW,CAAC,EAAE,OAAO,CAAA;IAErB,GAAG,EAAE;QACH,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;QACtB,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;QACnB,eAAe,CAAC,EAAE,MAAM,CAAA;QACxB,SAAS,CAAC,EAAE,MAAM,CAAA;QAClB,OAAO,EAAE;YACP,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;YACtB,OAAO,EAAE,OAAO,GAAG,WAAW,CAAA;YAC9B,SAAS,EAAE,MAAM,CAAA;SAClB,CAAA;KACF,CAAA;IACD;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,aAAa,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC/B;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IAC5B,WAAW,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC7B,kBAAkB,CAAC,EAAE,eAAe,CAAC,GAAG,CAAC,CAAA;CAC1C,CAsEA,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VersionPillLabel.js","names":["c","_c","Pill","useConfig","useTranslation","formatDate","React","getVersionLabel","baseClass","renderPill","label","pillStyle","_jsx","size","VersionPillLabel","t0","$","currentlyPublishedVersion","disableDate","t1","doc","labelFirst","t2","labelOverride","labelStyle","t3","labelSuffix","latestDraftVersion","undefined","config","t4","admin","t5","localization","dateFormat","i18n","t","t6","version","labelText","_jsxs","children","showDate","updatedAt","formattedDate","date","pattern","localeCode","Array","isArray","publishedLocale","locale","locales","find","loc","code","localeLabel","language","className","Fragment"],"sources":["../../../../src/views/Version/VersionPillLabel/VersionPillLabel.tsx"],"sourcesContent":["'use client'\n\nimport { Pill, useConfig, useTranslation } from '@payloadcms/ui'\nimport { formatDate } from '@payloadcms/ui/shared'\nimport React from 'react'\n\nimport './index.scss'\nimport { getVersionLabel } from './getVersionLabel.js'\n\nconst baseClass = 'version-pill-label'\n\nconst renderPill = (label: React.ReactNode, pillStyle: Parameters<typeof Pill>[0]['pillStyle']) => {\n return (\n <Pill pillStyle={pillStyle} size=\"small\">\n {label}\n </Pill>\n )\n}\n\nexport const VersionPillLabel: React.FC<{\n currentlyPublishedVersion?:
|
|
1
|
+
{"version":3,"file":"VersionPillLabel.js","names":["c","_c","Pill","useConfig","useTranslation","formatDate","React","getVersionLabel","baseClass","renderPill","label","pillStyle","_jsx","size","VersionPillLabel","t0","$","currentlyPublishedVersion","disableDate","t1","doc","labelFirst","t2","labelOverride","labelStyle","t3","labelSuffix","latestDraftVersion","undefined","config","t4","admin","t5","localization","dateFormat","i18n","t","t6","version","labelText","_jsxs","children","showDate","updatedAt","formattedDate","date","pattern","localeCode","Array","isArray","publishedLocale","locale","locales","find","loc","code","localeLabel","language","className","Fragment"],"sources":["../../../../src/views/Version/VersionPillLabel/VersionPillLabel.tsx"],"sourcesContent":["'use client'\n\nimport type { TypeWithVersion } from 'payload'\n\nimport { Pill, useConfig, useTranslation } from '@payloadcms/ui'\nimport { formatDate } from '@payloadcms/ui/shared'\nimport React from 'react'\n\nimport './index.scss'\nimport { getVersionLabel } from './getVersionLabel.js'\n\nconst baseClass = 'version-pill-label'\n\nconst renderPill = (label: React.ReactNode, pillStyle: Parameters<typeof Pill>[0]['pillStyle']) => {\n return (\n <Pill pillStyle={pillStyle} size=\"small\">\n {label}\n </Pill>\n )\n}\n\nexport const VersionPillLabel: React.FC<{\n currentlyPublishedVersion?: TypeWithVersion<any>\n disableDate?: boolean\n\n doc: {\n [key: string]: unknown\n id: number | string\n publishedLocale?: string\n updatedAt?: string\n version: {\n [key: string]: unknown\n _status: 'draft' | 'published'\n updatedAt: string\n }\n }\n /**\n * By default, the date is displayed first, followed by the version label.\n * @default false\n */\n labelFirst?: boolean\n labelOverride?: React.ReactNode\n /**\n * @default 'pill'\n */\n labelStyle?: 'pill' | 'text'\n labelSuffix?: React.ReactNode\n latestDraftVersion?: TypeWithVersion<any>\n}> = ({\n currentlyPublishedVersion,\n disableDate = false,\n doc,\n labelFirst = false,\n labelOverride,\n labelStyle = 'pill',\n labelSuffix,\n latestDraftVersion,\n}) => {\n const {\n config: {\n admin: { dateFormat },\n localization,\n },\n } = useConfig()\n const { i18n, t } = useTranslation()\n\n const { label, pillStyle } = getVersionLabel({\n currentlyPublishedVersion,\n latestDraftVersion,\n t,\n version: doc,\n })\n const labelText: React.ReactNode = (\n <span>\n {labelOverride || label}\n {labelSuffix}\n </span>\n )\n\n const showDate = !disableDate && doc.updatedAt\n const formattedDate = showDate\n ? formatDate({ date: doc.updatedAt, i18n, pattern: dateFormat })\n : null\n\n const localeCode = Array.isArray(doc.publishedLocale)\n ? doc.publishedLocale[0]\n : doc.publishedLocale\n\n const locale =\n localization && localization?.locales\n ? localization.locales.find((loc) => loc.code === localeCode)\n : null\n const localeLabel = locale ? locale?.label?.[i18n?.language] || locale?.label : null\n\n return (\n <div className={baseClass}>\n {labelFirst ? (\n <React.Fragment>\n {labelStyle === 'pill' ? (\n renderPill(labelText, pillStyle)\n ) : (\n <span className={`${baseClass}-text`}>{labelText}</span>\n )}\n {showDate && <span className={`${baseClass}-date`}>{formattedDate}</span>}\n </React.Fragment>\n ) : (\n <React.Fragment>\n {showDate && <span className={`${baseClass}-date`}>{formattedDate}</span>}\n {labelStyle === 'pill' ? (\n renderPill(labelText, pillStyle)\n ) : (\n <span className={`${baseClass}-text`}>{labelText}</span>\n )}\n </React.Fragment>\n )}\n {localeLabel && <Pill size=\"small\">{localeLabel}</Pill>}\n </div>\n )\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AAIA,SAASC,IAAI,EAAEC,SAAS,EAAEC,cAAc,QAAQ;AAChD,SAASC,UAAU,QAAQ;AAC3B,OAAOC,KAAA,MAAW;AAGlB,SAASC,eAAe,QAAQ;AAEhC,MAAMC,SAAA,GAAY;AAElB,MAAMC,UAAA,GAAaA,CAACC,KAAA,EAAwBC,SAAA;EAC1C,oBACEC,IAAA,CAACV,IAAA;IAAKS,SAAA,EAAWA,SAAA;IAAWE,IAAA,EAAK;cAC9BH;;AAGP;AAEA,OAAO,MAAMI,gBAAA,GA2BRC,EAAA;EAAA,MAAAC,CAAA,GAAAf,EAAA;EAAC;IAAAgB,yBAA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;UAAAiC,QAAA,EAAGF;QAAA,C;UAI5CiB,WAAA,IAAe5C,IAAA,CAAAV,IAAA;QAAAW,IAAA,EAAW;QAAA4B,QAAA,EAASe;MAAA,C;;;;;;;;;;;;;;;;;;SApBtCnB,E;CAuBJ","ignoreList":[]}
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import type { TFunction } from '@payloadcms/translations';
|
|
2
|
-
import type
|
|
2
|
+
import { type Pill } from '@payloadcms/ui';
|
|
3
3
|
type Args = {
|
|
4
4
|
currentlyPublishedVersion?: {
|
|
5
5
|
id: number | string;
|
|
6
|
+
publishedLocale?: string;
|
|
6
7
|
updatedAt: string;
|
|
8
|
+
version: {
|
|
9
|
+
updatedAt: string;
|
|
10
|
+
};
|
|
7
11
|
};
|
|
8
12
|
latestDraftVersion?: {
|
|
9
13
|
id: number | string;
|
|
@@ -12,8 +16,10 @@ type Args = {
|
|
|
12
16
|
t: TFunction;
|
|
13
17
|
version: {
|
|
14
18
|
id: number | string;
|
|
19
|
+
publishedLocale?: string;
|
|
15
20
|
version: {
|
|
16
|
-
_status?:
|
|
21
|
+
_status?: 'draft' | 'published';
|
|
22
|
+
updatedAt: string;
|
|
17
23
|
};
|
|
18
24
|
};
|
|
19
25
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getVersionLabel.d.ts","sourceRoot":"","sources":["../../../../src/views/Version/VersionPillLabel/getVersionLabel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;
|
|
1
|
+
{"version":3,"file":"getVersionLabel.d.ts","sourceRoot":"","sources":["../../../../src/views/Version/VersionPillLabel/getVersionLabel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AAEzD,OAAO,EAAE,KAAK,IAAI,EAAa,MAAM,gBAAgB,CAAA;AAErD,KAAK,IAAI,GAAG;IACV,yBAAyB,CAAC,EAAE;QAC1B,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;QACnB,eAAe,CAAC,EAAE,MAAM,CAAA;QACxB,SAAS,EAAE,MAAM,CAAA;QACjB,OAAO,EAAE;YACP,SAAS,EAAE,MAAM,CAAA;SAClB,CAAA;KACF,CAAA;IACD,kBAAkB,CAAC,EAAE;QACnB,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;QACnB,SAAS,EAAE,MAAM,CAAA;KAClB,CAAA;IACD,CAAC,EAAE,SAAS,CAAA;IACZ,OAAO,EAAE;QACP,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;QACnB,eAAe,CAAC,EAAE,MAAM,CAAA;QACxB,OAAO,EAAE;YAAE,OAAO,CAAC,EAAE,OAAO,GAAG,WAAW,CAAC;YAAC,SAAS,EAAE,MAAM,CAAA;SAAE,CAAA;KAChE,CAAA;CACF,CAAA;AAED;;;GAGG;AACH,wBAAgB,eAAe,CAAC,EAC9B,yBAAyB,EACzB,kBAAkB,EAClB,CAAC,EACD,OAAO,GACR,EAAE,IAAI,GAAG;IACR,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,cAAc,GAAG,oBAAoB,GAAG,OAAO,GAAG,qBAAqB,GAAG,WAAW,CAAA;IAC3F,SAAS,EAAE,UAAU,CAAC,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAA;CACnD,CA8CA"}
|
|
@@ -1,34 +1,47 @@
|
|
|
1
|
+
import { useLocale } from '@payloadcms/ui';
|
|
1
2
|
/**
|
|
2
3
|
* Gets the appropriate version label and version pill styling
|
|
3
4
|
* given existing versions and the current version status.
|
|
4
|
-
*/
|
|
5
|
+
*/
|
|
6
|
+
export function getVersionLabel({
|
|
5
7
|
currentlyPublishedVersion,
|
|
6
8
|
latestDraftVersion,
|
|
7
9
|
t,
|
|
8
10
|
version
|
|
9
11
|
}) {
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
+
const {
|
|
13
|
+
code: currentLocale
|
|
14
|
+
} = useLocale();
|
|
15
|
+
const status = version.version._status;
|
|
16
|
+
if (status === 'draft') {
|
|
17
|
+
const publishedNewerThanDraft = currentlyPublishedVersion?.updatedAt > latestDraftVersion?.updatedAt;
|
|
12
18
|
if (publishedNewerThanDraft) {
|
|
13
19
|
return {
|
|
14
20
|
name: 'draft',
|
|
15
21
|
label: t('version:draft'),
|
|
16
22
|
pillStyle: 'light'
|
|
17
23
|
};
|
|
18
|
-
} else {
|
|
19
|
-
return {
|
|
20
|
-
name: version.id === latestDraftVersion?.id ? 'currentDraft' : 'draft',
|
|
21
|
-
label: version.id === latestDraftVersion?.id ? t('version:currentDraft') : t('version:draft'),
|
|
22
|
-
pillStyle: 'light'
|
|
23
|
-
};
|
|
24
24
|
}
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
const isCurrentDraft = version.id === latestDraftVersion?.id;
|
|
26
|
+
return {
|
|
27
|
+
name: isCurrentDraft ? 'currentDraft' : 'draft',
|
|
28
|
+
label: isCurrentDraft ? t('version:currentDraft') : t('version:draft'),
|
|
29
|
+
pillStyle: 'light'
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
const publishedInAnotherLocale = status === 'published' && version.publishedLocale && currentLocale !== version.publishedLocale;
|
|
33
|
+
if (publishedInAnotherLocale) {
|
|
27
34
|
return {
|
|
28
|
-
name:
|
|
29
|
-
label:
|
|
30
|
-
pillStyle:
|
|
35
|
+
name: 'currentDraft',
|
|
36
|
+
label: t('version:currentDraft'),
|
|
37
|
+
pillStyle: 'light'
|
|
31
38
|
};
|
|
32
39
|
}
|
|
40
|
+
const isCurrentlyPublished = currentlyPublishedVersion && version.id === currentlyPublishedVersion.id;
|
|
41
|
+
return {
|
|
42
|
+
name: isCurrentlyPublished ? 'currentlyPublished' : 'previouslyPublished',
|
|
43
|
+
label: isCurrentlyPublished ? t('version:currentlyPublished') : t('version:previouslyPublished'),
|
|
44
|
+
pillStyle: isCurrentlyPublished ? 'success' : 'light'
|
|
45
|
+
};
|
|
33
46
|
}
|
|
34
47
|
//# sourceMappingURL=getVersionLabel.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getVersionLabel.js","names":["getVersionLabel","currentlyPublishedVersion","latestDraftVersion","t","version","
|
|
1
|
+
{"version":3,"file":"getVersionLabel.js","names":["useLocale","getVersionLabel","currentlyPublishedVersion","latestDraftVersion","t","version","code","currentLocale","status","_status","publishedNewerThanDraft","updatedAt","name","label","pillStyle","isCurrentDraft","id","publishedInAnotherLocale","publishedLocale","isCurrentlyPublished"],"sources":["../../../../src/views/Version/VersionPillLabel/getVersionLabel.ts"],"sourcesContent":["import type { TFunction } from '@payloadcms/translations'\n\nimport { type Pill, useLocale } from '@payloadcms/ui'\n\ntype Args = {\n currentlyPublishedVersion?: {\n id: number | string\n publishedLocale?: string\n updatedAt: string\n version: {\n updatedAt: string\n }\n }\n latestDraftVersion?: {\n id: number | string\n updatedAt: string\n }\n t: TFunction\n version: {\n id: number | string\n publishedLocale?: string\n version: { _status?: 'draft' | 'published'; updatedAt: string }\n }\n}\n\n/**\n * Gets the appropriate version label and version pill styling\n * given existing versions and the current version status.\n */\nexport function getVersionLabel({\n currentlyPublishedVersion,\n latestDraftVersion,\n t,\n version,\n}: Args): {\n label: string\n name: 'currentDraft' | 'currentlyPublished' | 'draft' | 'previouslyPublished' | 'published'\n pillStyle: Parameters<typeof Pill>[0]['pillStyle']\n} {\n const { code: currentLocale } = useLocale()\n const status = version.version._status\n\n if (status === 'draft') {\n const publishedNewerThanDraft =\n currentlyPublishedVersion?.updatedAt > latestDraftVersion?.updatedAt\n\n if (publishedNewerThanDraft) {\n return {\n name: 'draft',\n label: t('version:draft'),\n pillStyle: 'light',\n }\n }\n\n const isCurrentDraft = version.id === latestDraftVersion?.id\n\n return {\n name: isCurrentDraft ? 'currentDraft' : 'draft',\n label: isCurrentDraft ? t('version:currentDraft') : t('version:draft'),\n pillStyle: 'light',\n }\n }\n\n const publishedInAnotherLocale =\n status === 'published' && version.publishedLocale && currentLocale !== version.publishedLocale\n\n if (publishedInAnotherLocale) {\n return {\n name: 'currentDraft',\n label: t('version:currentDraft'),\n pillStyle: 'light',\n }\n }\n\n const isCurrentlyPublished =\n currentlyPublishedVersion && version.id === currentlyPublishedVersion.id\n\n return {\n name: isCurrentlyPublished ? 'currentlyPublished' : 'previouslyPublished',\n label: isCurrentlyPublished\n ? t('version:currentlyPublished')\n : t('version:previouslyPublished'),\n pillStyle: isCurrentlyPublished ? 'success' : 'light',\n }\n}\n"],"mappings":"AAEA,SAAoBA,SAAS,QAAQ;AAuBrC;;;;AAIA,OAAO,SAASC,gBAAgB;EAC9BC,yBAAyB;EACzBC,kBAAkB;EAClBC,CAAC;EACDC;AAAO,CACF;EAKL,MAAM;IAAEC,IAAA,EAAMC;EAAa,CAAE,GAAGP,SAAA;EAChC,MAAMQ,MAAA,GAASH,OAAA,CAAQA,OAAO,CAACI,OAAO;EAEtC,IAAID,MAAA,KAAW,SAAS;IACtB,MAAME,uBAAA,GACJR,yBAAA,EAA2BS,SAAA,GAAYR,kBAAA,EAAoBQ,SAAA;IAE7D,IAAID,uBAAA,EAAyB;MAC3B,OAAO;QACLE,IAAA,EAAM;QACNC,KAAA,EAAOT,CAAA,CAAE;QACTU,SAAA,EAAW;MACb;IACF;IAEA,MAAMC,cAAA,GAAiBV,OAAA,CAAQW,EAAE,KAAKb,kBAAA,EAAoBa,EAAA;IAE1D,OAAO;MACLJ,IAAA,EAAMG,cAAA,GAAiB,iBAAiB;MACxCF,KAAA,EAAOE,cAAA,GAAiBX,CAAA,CAAE,0BAA0BA,CAAA,CAAE;MACtDU,SAAA,EAAW;IACb;EACF;EAEA,MAAMG,wBAAA,GACJT,MAAA,KAAW,eAAeH,OAAA,CAAQa,eAAe,IAAIX,aAAA,KAAkBF,OAAA,CAAQa,eAAe;EAEhG,IAAID,wBAAA,EAA0B;IAC5B,OAAO;MACLL,IAAA,EAAM;MACNC,KAAA,EAAOT,CAAA,CAAE;M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