payload-nested-docs-page-tree 1.6.0 → 1.6.1
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/README.md +14 -5
- package/dist/components/PageTreeLocaleStatusBadges.js +3 -2
- package/dist/components/PageTreeLocaleStatusBadges.js.map +1 -1
- package/dist/types.d.ts +5 -1
- package/dist/types.js.map +1 -1
- package/dist/utilities/localeStatus.js +13 -8
- package/dist/utilities/localeStatus.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -393,15 +393,18 @@ pnpm add /path/payload-nested-docs-page-tree-*.tgz
|
|
|
393
393
|
### Locale badge visibility
|
|
394
394
|
|
|
395
395
|
With localized status badges enabled, the optional top-level
|
|
396
|
-
`localeBadgeVisibility: ({ doc, locale, req }) => boolean` callback decides which
|
|
397
|
-
badges are visible. It runs only on the server
|
|
398
|
-
|
|
396
|
+
`localeBadgeVisibility: ({ doc, publishedDoc, locale, req }) => boolean` callback decides which
|
|
397
|
+
badges are visible. It runs only on the server and receives the latest draft as
|
|
398
|
+
`doc` and the current document as `publishedDoc` when readable. Both contain all
|
|
399
|
+
locales and respect the current user's read access. Check each locale's status
|
|
400
|
+
before treating current content as published. This lets visibility follow published
|
|
401
|
+
content independently of pending draft changes. Returning false hides the badge
|
|
399
402
|
from both sight and assistive technology while preserving its aligned slot,
|
|
400
403
|
including when that locale is selected. Publication status is unchanged.
|
|
401
404
|
|
|
402
405
|
Without a callback, all locale badges remain visible. When configured, the existing
|
|
403
|
-
batched draft
|
|
404
|
-
queries are added. The callback and document content are not passed to the client.
|
|
406
|
+
two batched queries read the draft and current document content needed by the
|
|
407
|
+
callback; no per-row queries are added. The callback and document content are not passed to the client.
|
|
405
408
|
Project-specific inheritance or detachment rules belong in the consuming app.
|
|
406
409
|
|
|
407
410
|
The optional top-level
|
|
@@ -412,3 +415,9 @@ all locales. Check the current document's locale status before treating its cont
|
|
|
412
415
|
as published. This callback loads content in the same two access-controlled batched
|
|
413
416
|
queries; no document content or callbacks are passed to the client. It never writes
|
|
414
417
|
publication state. Without it, the plugin's normal status behavior is unchanged.
|
|
418
|
+
|
|
419
|
+
The status callback can also return `{ status, label }` to override one locale's
|
|
420
|
+
display text while retaining its publication status and status color. The label is
|
|
421
|
+
used in the badge's accessible name and, for the active locale, its visible text.
|
|
422
|
+
The resolved label is also exposed as `data-label` for custom styling. Existing
|
|
423
|
+
callbacks returning a status string continue to work.
|
|
@@ -10,9 +10,9 @@ export function PageTreeLocaleStatusBadges({ badgeConfig, collectionSlug, docID,
|
|
|
10
10
|
const { t } = useTranslation();
|
|
11
11
|
return /*#__PURE__*/ _jsx("span", {
|
|
12
12
|
className: "pages-hierarchy-locale-statuses",
|
|
13
|
-
children: statuses.map(({ locale: code, status, visible })=>{
|
|
13
|
+
children: statuses.map(({ label: customLabel, locale: code, status, visible })=>{
|
|
14
14
|
const active = code === locale?.code;
|
|
15
|
-
const label = getPageTreeBadgeLabel({
|
|
15
|
+
const label = customLabel?.trim() || getPageTreeBadgeLabel({
|
|
16
16
|
badgeLabels: badgeConfig.labels,
|
|
17
17
|
status,
|
|
18
18
|
t
|
|
@@ -37,6 +37,7 @@ export function PageTreeLocaleStatusBadges({ badgeConfig, collectionSlug, docID,
|
|
|
37
37
|
className: `pages-hierarchy-status-badge pages-hierarchy-status-badge--${status} pages-hierarchy-locale-status-badge`,
|
|
38
38
|
"data-active": active ? 'true' : 'false',
|
|
39
39
|
"data-custom-color": color ? 'true' : undefined,
|
|
40
|
+
"data-label": label,
|
|
40
41
|
"data-locale": code,
|
|
41
42
|
"data-status": status,
|
|
42
43
|
href: href,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/components/PageTreeLocaleStatusBadges.tsx"],"sourcesContent":["'use client'\n\nimport { useConfig, useLocale, useTranslation } from '@payloadcms/ui'\nimport { formatAdminURL } from 'payload/shared'\nimport React from 'react'\n\nimport type { NestedDocsPageTreePluginResolvedBadgeConfig, PageTreeLocaleStatus } from '../types.js'\n\nimport { getPageTreeBadgeColor, getPageTreeBadgeLabel } from '../utilities/status.js'\n\nexport function PageTreeLocaleStatusBadges({\n badgeConfig,\n collectionSlug,\n docID,\n statuses,\n}: {\n badgeConfig: NestedDocsPageTreePluginResolvedBadgeConfig\n collectionSlug?: string\n docID?: number | string\n statuses: PageTreeLocaleStatus[]\n}) {\n const { config } = useConfig()\n const locale = useLocale()\n const { t } = useTranslation()\n\n return (\n <span className=\"pages-hierarchy-locale-statuses\">\n {statuses.map(({ locale: code, status, visible }) => {\n const active = code === locale?.code\n const label
|
|
1
|
+
{"version":3,"sources":["../../src/components/PageTreeLocaleStatusBadges.tsx"],"sourcesContent":["'use client'\n\nimport { useConfig, useLocale, useTranslation } from '@payloadcms/ui'\nimport { formatAdminURL } from 'payload/shared'\nimport React from 'react'\n\nimport type { NestedDocsPageTreePluginResolvedBadgeConfig, PageTreeLocaleStatus } from '../types.js'\n\nimport { getPageTreeBadgeColor, getPageTreeBadgeLabel } from '../utilities/status.js'\n\nexport function PageTreeLocaleStatusBadges({\n badgeConfig,\n collectionSlug,\n docID,\n statuses,\n}: {\n badgeConfig: NestedDocsPageTreePluginResolvedBadgeConfig\n collectionSlug?: string\n docID?: number | string\n statuses: PageTreeLocaleStatus[]\n}) {\n const { config } = useConfig()\n const locale = useLocale()\n const { t } = useTranslation()\n\n return (\n <span className=\"pages-hierarchy-locale-statuses\">\n {statuses.map(({ label: customLabel, locale: code, status, visible }) => {\n const active = code === locale?.code\n const label =\n customLabel?.trim() ||\n getPageTreeBadgeLabel({ badgeLabels: badgeConfig.labels, status, t })\n const color = getPageTreeBadgeColor({ badgeColors: badgeConfig.colors, status })\n\n const href =\n visible !== false && collectionSlug && docID !== undefined\n ? formatAdminURL({\n adminRoute: config.routes.admin,\n includeBasePath: true,\n path: `/collections/${encodeURIComponent(collectionSlug)}/${encodeURIComponent(docID)}?${new URLSearchParams({ locale: code })}`,\n })\n : undefined\n const Badge = href ? 'a' : 'span'\n\n return (\n <span\n className={`pages-hierarchy-locale-status-slot${active ? ' pages-hierarchy-locale-status-slot--active' : ''}`}\n key={code}\n >\n <Badge\n aria-hidden={visible === false ? true : undefined}\n aria-label={`${code.toUpperCase()}: ${label}`}\n className={`pages-hierarchy-status-badge pages-hierarchy-status-badge--${status} pages-hierarchy-locale-status-badge`}\n data-active={active ? 'true' : 'false'}\n data-custom-color={color ? 'true' : undefined}\n data-label={label}\n data-locale={code}\n data-status={status}\n href={href}\n onClick={href ? (event: React.MouseEvent) => event.stopPropagation() : undefined}\n onPointerDown={\n href ? (event: React.PointerEvent) => event.stopPropagation() : undefined\n }\n role={href ? undefined : 'img'}\n style={{\n ...(color ? ({ '--page-tree-badge-base': color } as React.CSSProperties) : {}),\n ...(visible === false ? { visibility: 'hidden' } : {}),\n }}\n >\n <span className=\"pages-hierarchy-locale-status-badge__code\">\n {code.toUpperCase()}\n </span>\n {active && (\n <>\n <span\n aria-hidden=\"true\"\n className=\"pages-hierarchy-locale-status-badge__separator\"\n >\n ·\n </span>\n <span className=\"pages-hierarchy-locale-status-badge__label\">{label}</span>\n </>\n )}\n </Badge>\n </span>\n )\n })}\n </span>\n )\n}\n"],"names":["useConfig","useLocale","useTranslation","formatAdminURL","React","getPageTreeBadgeColor","getPageTreeBadgeLabel","PageTreeLocaleStatusBadges","badgeConfig","collectionSlug","docID","statuses","config","locale","t","span","className","map","label","customLabel","code","status","visible","active","trim","badgeLabels","labels","color","badgeColors","colors","href","undefined","adminRoute","routes","admin","includeBasePath","path","encodeURIComponent","URLSearchParams","Badge","aria-hidden","aria-label","toUpperCase","data-active","data-custom-color","data-label","data-locale","data-status","onClick","event","stopPropagation","onPointerDown","role","style","visibility"],"mappings":"AAAA;;AAEA,SAASA,SAAS,EAAEC,SAAS,EAAEC,cAAc,QAAQ,iBAAgB;AACrE,SAASC,cAAc,QAAQ,iBAAgB;AAC/C,OAAOC,WAAW,QAAO;AAIzB,SAASC,qBAAqB,EAAEC,qBAAqB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oBACNkB,SAASlB,OAAO,CAACmB,QAA4BA,MAAMC,eAAe,KAAKnB;oBACvEoB,eACErB,OAAO,CAACmB,QAA8BA,MAAMC,eAAe,KAAKnB;oBAElEqB,MAAMtB,OAAOC,YAAY;oBACzBsB,OAAO;wBACL,GAAI1B,QAAS;4BAAE,0BAA0BA;wBAAM,IAA4B,CAAC,CAAC;wBAC7E,GAAIL,YAAY,QAAQ;4BAAEgC,YAAY;wBAAS,IAAI,CAAC,CAAC;oBACvD;;sCAEA,KAACvC;4BAAKC,WAAU;sCACbI,KAAKsB,WAAW;;wBAElBnB,wBACC;;8CACE,KAACR;oCACCyB,eAAY;oCACZxB,WAAU;8CACX;;8CAGD,KAACD;oCAAKC,WAAU;8CAA8CE;;;;;;eAjC/DE;QAuCX;;AAGN"}
|
package/dist/types.d.ts
CHANGED
|
@@ -25,6 +25,8 @@ export type PageTreeLocaleBadgeVisibility = (args: {
|
|
|
25
25
|
/** Latest draft document with all locales, read with the current user's access. */
|
|
26
26
|
doc: Record<string, unknown>;
|
|
27
27
|
locale: string;
|
|
28
|
+
/** Current document, if readable. Check its locale status before treating it as published. */
|
|
29
|
+
publishedDoc?: Record<string, unknown>;
|
|
28
30
|
req: PayloadRequest;
|
|
29
31
|
}) => boolean;
|
|
30
32
|
export type PageTreeLocaleBadgeStatus = (args: {
|
|
@@ -35,7 +37,7 @@ export type PageTreeLocaleBadgeStatus = (args: {
|
|
|
35
37
|
publishedDoc?: Record<string, unknown>;
|
|
36
38
|
req: PayloadRequest;
|
|
37
39
|
status: PageTreeLocaleStatus['status'];
|
|
38
|
-
}) => PageTreeLocaleStatus['status']
|
|
40
|
+
}) => PageTreeLocaleStatus['status'] | Pick<PageTreeLocaleStatus, 'status' | 'label'>;
|
|
39
41
|
export type NestedDocsPageTreePluginConfig = {
|
|
40
42
|
badges?: NestedDocsPageTreePluginBadgeConfig;
|
|
41
43
|
/** Opt in to status badge links. Preview uses the collection's admin.preview. */
|
|
@@ -106,6 +108,8 @@ export type PageTreeStatusLinks = {
|
|
|
106
108
|
publicURL?: string;
|
|
107
109
|
};
|
|
108
110
|
export type PageTreeLocaleStatus = {
|
|
111
|
+
/** Optional display label; publication status remains separate. */
|
|
112
|
+
label?: string;
|
|
109
113
|
locale: string;
|
|
110
114
|
status: 'changed' | 'draft' | 'published' | 'unknown';
|
|
111
115
|
visible?: boolean;
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { CollectionSlug, PayloadRequest } from 'payload'\n\nimport type { NestedDocsPageTreePluginDiagnosticsConfig } from './utilities/diagnostics.js'\n\nexport type {\n NestedDocsPageTreePluginDiagnosticEvent,\n NestedDocsPageTreePluginDiagnosticsConfig,\n} from './utilities/diagnostics.js'\n\nexport const nestedDocsPageTreePluginBadgeStatuses = ['published', 'changed', 'draft'] as const\n\nexport type NestedDocsPageTreePluginBadgeStatus =\n (typeof nestedDocsPageTreePluginBadgeStatuses)[number]\n\nexport type NestedDocsPageTreePluginBadgeMap = Partial<\n Record<NestedDocsPageTreePluginBadgeStatus, string>\n>\n\nexport type NestedDocsPageTreePluginBadgeConfig = {\n colors?: NestedDocsPageTreePluginBadgeMap\n labels?: NestedDocsPageTreePluginBadgeMap\n /** Show locale badges when the collection enables localized draft status. */\n locales?: boolean\n}\n\nexport type NestedDocsPageTreePluginResolvedBadgeConfig = {\n colors: NestedDocsPageTreePluginBadgeMap\n labels: NestedDocsPageTreePluginBadgeMap\n locales?: boolean\n}\n\nexport type NestedDocsPageTreePluginHomeIndicatorConfig =\n | {\n collections?: CollectionSlug[]\n }\n | false\n\nexport type NestedDocsPageTreePluginResolvedHomeIndicatorConfig = {\n enabled: boolean\n}\n\nexport type PageTreeLocaleBadgeVisibility = (args: {\n /** Latest draft document with all locales, read with the current user's access. */\n doc: Record<string, unknown>\n locale: string\n req: PayloadRequest\n}) => boolean\n\nexport type PageTreeLocaleBadgeStatus = (args: {\n /** Latest draft document with all locales, read with the current user's access. */\n doc: Record<string, unknown>\n locale: string\n /** Current document, if readable. Check its locale status before treating it as published. */\n publishedDoc?: Record<string, unknown>\n req: PayloadRequest\n status: PageTreeLocaleStatus['status']\n}) => PageTreeLocaleStatus['status']
|
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { CollectionSlug, PayloadRequest } from 'payload'\n\nimport type { NestedDocsPageTreePluginDiagnosticsConfig } from './utilities/diagnostics.js'\n\nexport type {\n NestedDocsPageTreePluginDiagnosticEvent,\n NestedDocsPageTreePluginDiagnosticsConfig,\n} from './utilities/diagnostics.js'\n\nexport const nestedDocsPageTreePluginBadgeStatuses = ['published', 'changed', 'draft'] as const\n\nexport type NestedDocsPageTreePluginBadgeStatus =\n (typeof nestedDocsPageTreePluginBadgeStatuses)[number]\n\nexport type NestedDocsPageTreePluginBadgeMap = Partial<\n Record<NestedDocsPageTreePluginBadgeStatus, string>\n>\n\nexport type NestedDocsPageTreePluginBadgeConfig = {\n colors?: NestedDocsPageTreePluginBadgeMap\n labels?: NestedDocsPageTreePluginBadgeMap\n /** Show locale badges when the collection enables localized draft status. */\n locales?: boolean\n}\n\nexport type NestedDocsPageTreePluginResolvedBadgeConfig = {\n colors: NestedDocsPageTreePluginBadgeMap\n labels: NestedDocsPageTreePluginBadgeMap\n locales?: boolean\n}\n\nexport type NestedDocsPageTreePluginHomeIndicatorConfig =\n | {\n collections?: CollectionSlug[]\n }\n | false\n\nexport type NestedDocsPageTreePluginResolvedHomeIndicatorConfig = {\n enabled: boolean\n}\n\nexport type PageTreeLocaleBadgeVisibility = (args: {\n /** Latest draft document with all locales, read with the current user's access. */\n doc: Record<string, unknown>\n locale: string\n /** Current document, if readable. Check its locale status before treating it as published. */\n publishedDoc?: Record<string, unknown>\n req: PayloadRequest\n}) => boolean\n\nexport type PageTreeLocaleBadgeStatus = (args: {\n /** Latest draft document with all locales, read with the current user's access. */\n doc: Record<string, unknown>\n locale: string\n /** Current document, if readable. Check its locale status before treating it as published. */\n publishedDoc?: Record<string, unknown>\n req: PayloadRequest\n status: PageTreeLocaleStatus['status']\n}) => PageTreeLocaleStatus['status'] | Pick<PageTreeLocaleStatus, 'status' | 'label'>\n\nexport type NestedDocsPageTreePluginConfig = {\n badges?: NestedDocsPageTreePluginBadgeConfig\n /** Opt in to status badge links. Preview uses the collection's admin.preview. */\n badgesLinks?: NestedDocsPageTreePluginBadgesLinks\n breadcrumbsFieldSlug?: string\n collections: CollectionSlug[]\n defaultLimit?: number\n /**\n * When set, the plugin emits structured diagnostic events for page-tree\n * triggered moves, including before/after snapshots of the published main row.\n * Disabled by default. Pass `true` to log to `console`, or pass an object\n * with a custom `logger` to route events elsewhere.\n */\n diagnostics?: NestedDocsPageTreePluginDiagnosticsConfig\n disabled?: boolean\n hideBreadcrumbs?: boolean\n homeIndicator?: NestedDocsPageTreePluginHomeIndicatorConfig\n /** Server-only display override. Does not change stored publication status. */\n localeBadgeStatus?: PageTreeLocaleBadgeStatus\n /** Server-only rule. False hides the badge while preserving its aligned slot. */\n localeBadgeVisibility?: PageTreeLocaleBadgeVisibility\n parentFieldSlug?: string\n /**\n * Publish a hierarchy move immediately instead of staging it as a draft - but\n * ONLY when the moved document had no unpublished changes before the move (its\n * latest version is already published). A document with pending draft edits (a\n * \"changed\" or draft-only doc) always stays staged, so in-progress edits are\n * never published as a side effect of a move. Only affects collections with\n * drafts enabled; collections without drafts move live regardless.\n *\n * Disabled by default: every move is staged as a draft and the live URL/path\n * changes only when the document is next published.\n *\n * @default false\n */\n publishOnMove?: boolean\n}\n\nexport type NestedDocsPageTreePluginCollectionCustom = {\n badges: NestedDocsPageTreePluginResolvedBadgeConfig\n badgesLinks?: NestedDocsPageTreePluginBadgesLinks\n breadcrumbsFieldSlug: string\n defaultLimit: number\n hideBreadcrumbs: boolean\n homeIndicator: NestedDocsPageTreePluginResolvedHomeIndicatorConfig\n localeBadgeStatus?: PageTreeLocaleBadgeStatus\n localeBadgeVisibility?: PageTreeLocaleBadgeVisibility\n parentFieldSlug: string\n}\n\nexport type PageTreeLiveURL<TRequest = PayloadRequest> = (args: {\n collectionSlug: string\n /** Published document read with the current user's access, at depth 0. */\n doc: PageTreeSourceDoc\n locale?: string\n /** Published document's last breadcrumb URL, when available. */\n path?: string\n req: TRequest\n}) => null | Promise<null | string | undefined> | string | undefined\n\nexport type NestedDocsPageTreePluginBadgesLinks<TRequest = PayloadRequest> = {\n /** Which links to offer for a draft with a published version. @default 'both' */\n draftHasPublishedVersion?: 'both' | 'live' | 'preview'\n /** Website base URL, or a server-only callback returning the final live URL. */\n liveURL?: PageTreeLiveURL<TRequest> | string\n /** Show live link and preview eye icons. When false, 'both' keeps an external-link preview action. @default true */\n showIcons?: boolean\n}\n\nexport type PageTreeStatusLinks = {\n previewURL?: string\n publicURL?: string\n}\n\nexport type PageTreeLocaleStatus = {\n /** Optional display label; publication status remains separate. */\n label?: string\n locale: string\n status: 'changed' | 'draft' | 'published' | 'unknown'\n visible?: boolean\n}\n\nexport type PageTreeSourceDoc = {\n __pageTreeLocaleStatuses?: PageTreeLocaleStatus[]\n __pageTreeStatusLinks?: PageTreeStatusLinks\n _displayStatus?: null | string\n _status?: null | string\n id?: number | string\n slug?: null | string\n} & Record<string, unknown>\n\nexport const nestedDocsPageTreePluginCustomKey = 'nestedDocsPageTreePlugin'\n\n/**\n * Set on Payload's hook context for every page-tree write that leaves the\n * published site unchanged: sibling reorders, and parent moves staged as\n * drafts. Deploy/revalidate hooks read it to skip rebuilds they do not need.\n *\n * It is deliberately NOT set when `publishOnMove` publishes a move, because\n * that move changed the live URL of the page and its descendants and the site\n * does need rebuilding. That way one guard covers every configuration:\n *\n * ```ts\n * if (req.context?.[pageTreeMoveContextKey]) return\n * ```\n *\n * Note the flag describes the *effect* of the write, not its kind - it is\n * absent on published moves even though those are still page-tree moves. Use\n * `pageTreeWriteContextKey` when you need \"was this a page-tree write at all\".\n */\nexport const pageTreeMoveContextKey = 'pageTreeMove'\n\n/**\n * Internal: set on every page-tree write regardless of whether it published.\n * Diagnostics uses it so that published moves are still traced, which is the\n * case most worth observing. Not part of the public API.\n */\nexport const pageTreeWriteContextKey = 'pageTreeWrite'\n\nexport type PageTreeMoveContext = {\n [pageTreeMoveContextKey]?: boolean\n [pageTreeWriteContextKey]?: boolean\n}\n"],"names":["nestedDocsPageTreePluginBadgeStatuses","nestedDocsPageTreePluginCustomKey","pageTreeMoveContextKey","pageTreeWriteContextKey"],"mappings":"AASA,OAAO,MAAMA,wCAAwC;IAAC;IAAa;IAAW;CAAQ,CAAS;AA8I/F,OAAO,MAAMC,oCAAoC,2BAA0B;AAE3E;;;;;;;;;;;;;;;;CAgBC,GACD,OAAO,MAAMC,yBAAyB,eAAc;AAEpD;;;;CAIC,GACD,OAAO,MAAMC,0BAA0B,gBAAe"}
|
|
@@ -30,7 +30,7 @@ export async function withPageTreeLocaleStatuses({ collectionSlug, docs, localeB
|
|
|
30
30
|
}
|
|
31
31
|
},
|
|
32
32
|
// Only opt-in callbacks need document content. Keep the two batched queries.
|
|
33
|
-
select: localeBadgeStatus ||
|
|
33
|
+
select: localeBadgeStatus || localeBadgeVisibility ? undefined : {
|
|
34
34
|
id: true,
|
|
35
35
|
_status: true
|
|
36
36
|
},
|
|
@@ -59,22 +59,27 @@ export async function withPageTreeLocaleStatuses({ collectionSlug, docs, localeB
|
|
|
59
59
|
_displayStatus: draft === 'draft' && current === 'published' ? 'changed' : undefined,
|
|
60
60
|
_status: draft
|
|
61
61
|
});
|
|
62
|
+
const displayStatus = localeBadgeStatus && draftDoc ? localeBadgeStatus({
|
|
63
|
+
doc: draftDoc,
|
|
64
|
+
locale,
|
|
65
|
+
publishedDoc,
|
|
66
|
+
req,
|
|
67
|
+
status
|
|
68
|
+
}) : status;
|
|
62
69
|
return {
|
|
63
70
|
locale,
|
|
64
71
|
...localeBadgeVisibility ? {
|
|
65
72
|
visible: Boolean(draftDoc && localeBadgeVisibility({
|
|
66
73
|
doc: draftDoc,
|
|
67
74
|
locale,
|
|
75
|
+
publishedDoc,
|
|
68
76
|
req
|
|
69
77
|
}))
|
|
70
78
|
} : {},
|
|
71
|
-
status:
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
req,
|
|
76
|
-
status
|
|
77
|
-
}) : status
|
|
79
|
+
status: typeof displayStatus === 'string' ? displayStatus : displayStatus.status,
|
|
80
|
+
...typeof displayStatus === 'object' && displayStatus.label ? {
|
|
81
|
+
label: displayStatus.label
|
|
82
|
+
} : {}
|
|
78
83
|
};
|
|
79
84
|
})
|
|
80
85
|
}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/localeStatus.ts"],"sourcesContent":["import type { CollectionSlug, Payload, PayloadRequest } from 'payload'\n\nimport type {\n PageTreeLocaleBadgeStatus,\n PageTreeLocaleBadgeVisibility,\n PageTreeSourceDoc,\n} from '../types.js'\n\nimport { getPageTreeDisplayStatus } from './status.js'\n\nfunction readLocaleStatus(value: unknown, locale: string): string | undefined {\n if (!value || typeof value !== 'object' || Array.isArray(value)) {\n return undefined\n }\n const status = (value as Record<string, unknown>)[locale]\n return typeof status === 'string' ? status : undefined\n}\n\nexport async function withPageTreeLocaleStatuses({\n collectionSlug,\n docs,\n localeBadgeStatus,\n localeBadgeVisibility,\n locales,\n payload,\n req,\n}: {\n collectionSlug: CollectionSlug\n docs: PageTreeSourceDoc[]\n localeBadgeStatus?: PageTreeLocaleBadgeStatus\n localeBadgeVisibility?: PageTreeLocaleBadgeVisibility\n locales: string[]\n payload: Payload\n req: PayloadRequest\n}): Promise<PageTreeSourceDoc[]> {\n const ids = docs\n .map(({ id }) => id)\n .filter((id): id is number | string => typeof id === 'number' || typeof id === 'string')\n\n if (!ids.length || !locales.length) {\n return docs\n }\n\n const [draftResult, currentResult] = await Promise.all(\n [true, false].map((draft) =>\n payload.find({\n collection: collectionSlug,\n depth: 0,\n draft,\n fallbackLocale: false,\n locale: 'all',\n overrideAccess: false,\n pagination: false,\n // Payload mutates the request locale for Local API calls.\n req: { ...req, query: { ...req.query } },\n // Only opt-in callbacks need document content. Keep the two batched queries.\n select:\n localeBadgeStatus ||
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/localeStatus.ts"],"sourcesContent":["import type { CollectionSlug, Payload, PayloadRequest } from 'payload'\n\nimport type {\n PageTreeLocaleBadgeStatus,\n PageTreeLocaleBadgeVisibility,\n PageTreeSourceDoc,\n} from '../types.js'\n\nimport { getPageTreeDisplayStatus } from './status.js'\n\nfunction readLocaleStatus(value: unknown, locale: string): string | undefined {\n if (!value || typeof value !== 'object' || Array.isArray(value)) {\n return undefined\n }\n const status = (value as Record<string, unknown>)[locale]\n return typeof status === 'string' ? status : undefined\n}\n\nexport async function withPageTreeLocaleStatuses({\n collectionSlug,\n docs,\n localeBadgeStatus,\n localeBadgeVisibility,\n locales,\n payload,\n req,\n}: {\n collectionSlug: CollectionSlug\n docs: PageTreeSourceDoc[]\n localeBadgeStatus?: PageTreeLocaleBadgeStatus\n localeBadgeVisibility?: PageTreeLocaleBadgeVisibility\n locales: string[]\n payload: Payload\n req: PayloadRequest\n}): Promise<PageTreeSourceDoc[]> {\n const ids = docs\n .map(({ id }) => id)\n .filter((id): id is number | string => typeof id === 'number' || typeof id === 'string')\n\n if (!ids.length || !locales.length) {\n return docs\n }\n\n const [draftResult, currentResult] = await Promise.all(\n [true, false].map((draft) =>\n payload.find({\n collection: collectionSlug,\n depth: 0,\n draft,\n fallbackLocale: false,\n locale: 'all',\n overrideAccess: false,\n pagination: false,\n // Payload mutates the request locale for Local API calls.\n req: { ...req, query: { ...req.query } },\n // Only opt-in callbacks need document content. Keep the two batched queries.\n select:\n localeBadgeStatus || localeBadgeVisibility ? undefined : { id: true, _status: true },\n where: { id: { in: ids } },\n }),\n ),\n )\n const draftByID = new Map(draftResult.docs.map((doc) => [String(doc.id), doc]))\n const currentByID = new Map(currentResult.docs.map((doc) => [String(doc.id), doc]))\n\n return docs.map((doc) => ({\n ...doc,\n __pageTreeLocaleStatuses: locales.map((locale) => {\n const draftDoc = draftByID.get(String(doc.id))\n const draft = readLocaleStatus(draftDoc?._status, locale)\n const publishedDoc = currentByID.get(String(doc.id))\n const current = readLocaleStatus(publishedDoc?._status, locale)\n const status = getPageTreeDisplayStatus({\n _displayStatus: draft === 'draft' && current === 'published' ? 'changed' : undefined,\n _status: draft,\n })\n const displayStatus =\n localeBadgeStatus && draftDoc\n ? localeBadgeStatus({ doc: draftDoc, locale, publishedDoc, req, status })\n : status\n return {\n locale,\n ...(localeBadgeVisibility\n ? {\n visible: Boolean(\n draftDoc && localeBadgeVisibility({ doc: draftDoc, locale, publishedDoc, req }),\n ),\n }\n : {}),\n status: typeof displayStatus === 'string' ? displayStatus : displayStatus.status,\n ...(typeof displayStatus === 'object' && displayStatus.label\n ? { label: displayStatus.label }\n : {}),\n }\n }),\n }))\n}\n"],"names":["getPageTreeDisplayStatus","readLocaleStatus","value","locale","Array","isArray","undefined","status","withPageTreeLocaleStatuses","collectionSlug","docs","localeBadgeStatus","localeBadgeVisibility","locales","payload","req","ids","map","id","filter","length","draftResult","currentResult","Promise","all","draft","find","collection","depth","fallbackLocale","overrideAccess","pagination","query","select","_status","where","in","draftByID","Map","doc","String","currentByID","__pageTreeLocaleStatuses","draftDoc","get","publishedDoc","current","_displayStatus","displayStatus","visible","Boolean","label"],"mappings":"AAQA,SAASA,wBAAwB,QAAQ,cAAa;AAEtD,SAASC,iBAAiBC,KAAc,EAAEC,MAAc;IACtD,IAAI,CAACD,SAAS,OAAOA,UAAU,YAAYE,MAAMC,OAAO,CAACH,QAAQ;QAC/D,OAAOI;IACT;IACA,MAAMC,SAAS,AAACL,KAAiC,CAACC,OAAO;IACzD,OAAO,OAAOI,WAAW,WAAWA,SAASD;AAC/C;AAEA,OAAO,eAAeE,2BAA2B,EAC/CC,cAAc,EACdC,IAAI,EACJC,iBAAiB,EACjBC,qBAAqB,EACrBC,OAAO,EACPC,OAAO,EACPC,GAAG,EASJ;IACC,MAAMC,MAAMN,KACT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