@foundrykit/history-plugin 0.0.0-stage → 0.1.0
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 +59 -2
- package/dist/exports/client.d.ts +1 -0
- package/dist/exports/client.js +3 -0
- package/dist/exports/client.js.map +1 -0
- package/dist/exports/rsc.d.ts +1 -0
- package/dist/exports/rsc.js +3 -0
- package/dist/exports/rsc.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +120 -0
- package/dist/index.js.map +1 -0
- package/dist/timeline.d.ts +37 -0
- package/dist/timeline.js +84 -0
- package/dist/timeline.js.map +1 -0
- package/dist/timeline.test.d.ts +1 -0
- package/dist/views/TimelineView.d.ts +4 -0
- package/dist/views/TimelineView.js +223 -0
- package/dist/views/TimelineView.js.map +1 -0
- package/dist/views/index.scss +63 -0
- package/package.json +107 -4
package/README.md
CHANGED
|
@@ -1,3 +1,60 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @foundrykit/history-plugin
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Version history for Payload CMS 3: who made each version, a timeline of what changed, and a link
|
|
4
|
+
straight into Payload's compare view.
|
|
5
|
+
|
|
6
|
+
## Setup
|
|
7
|
+
|
|
8
|
+
```ts
|
|
9
|
+
import { historyPlugin } from '@foundrykit/history-plugin'
|
|
10
|
+
|
|
11
|
+
export default buildConfig({
|
|
12
|
+
plugins: [
|
|
13
|
+
// Tracks every collection and global with versions turned on.
|
|
14
|
+
historyPlugin(),
|
|
15
|
+
// Or name them:
|
|
16
|
+
// historyPlugin({ collections: ['pages'], globals: ['settings'] }),
|
|
17
|
+
],
|
|
18
|
+
})
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Run `payload generate:importmap` afterwards.
|
|
22
|
+
|
|
23
|
+
## What it does
|
|
24
|
+
|
|
25
|
+
- **Records the author.** Each tracked collection and global gets a read-only **Last edited by**
|
|
26
|
+
field (`updatedBy`), set to whoever saves. Versions copy the whole document, so every version
|
|
27
|
+
carries its author, and Payload's compare view shows it next to the other changes. Anything sent
|
|
28
|
+
in `updatedBy` is ignored. Saves with no admin user, such as scripts or the public site, record
|
|
29
|
+
no author. Versions saved before the plugin was installed show "Unknown".
|
|
30
|
+
- **Replaces the Versions tab with a timeline.** Each entry shows:
|
|
31
|
+
- who saved it, and how long ago
|
|
32
|
+
- the kind of save: published, draft, autosave or saved
|
|
33
|
+
- what changed, for example "Changed Title, Layout (+2 blocks)"
|
|
34
|
+
|
|
35
|
+
A run of autosaves by one person is grouped into one entry. **View** opens Payload's compare
|
|
36
|
+
view for that version, which already has a "Modified only" toggle and a restore button.
|
|
37
|
+
|
|
38
|
+
- **Keeps history private.** Reading versions needs a login _and_ the collection's or global's own
|
|
39
|
+
read access. Payload's default only needs a login. This matters with
|
|
40
|
+
`@foundrykit/permissions-plugin`: someone without `area.read` can't see the history either. If a
|
|
41
|
+
read rule returns a query, such as "only shared memos", the same query limits which versions can
|
|
42
|
+
be read.
|
|
43
|
+
Sites that set `access.readVersions` themselves keep their own rule.
|
|
44
|
+
|
|
45
|
+
The plugin stops with an error if a tracked collection or global already has an `updatedBy`
|
|
46
|
+
field, or if you name one that doesn't have versions turned on.
|
|
47
|
+
|
|
48
|
+
## Development
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
pnpm install
|
|
52
|
+
pnpm dev # dev app on http://localhost:3000/admin (dev@payloadcms.com / test)
|
|
53
|
+
pnpm test # unit, integration and e2e (set E2E_PORT if 3000 is taken)
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Releasing
|
|
57
|
+
|
|
58
|
+
Run `pnpm release` on `prod`. It bumps the version, updates the changelog and pushes a `v*` tag.
|
|
59
|
+
The tag triggers `.github/workflows/publish.yml`, which publishes to npm through trusted
|
|
60
|
+
publishing, so no npm token is stored locally or in GitHub.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/exports/client.ts"],"sourcesContent":["export {}\n"],"names":[],"mappings":"AAAA,WAAS"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { TimelineView } from '../views/TimelineView.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/exports/rsc.ts"],"sourcesContent":["export { TimelineView } from '../views/TimelineView.js'\n"],"names":["TimelineView"],"mappings":"AAAA,SAASA,YAAY,QAAQ,2BAA0B"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Config } from 'payload';
|
|
2
|
+
export { AUTHOR_FIELD } from './timeline.js';
|
|
3
|
+
export type HistoryPluginConfig = {
|
|
4
|
+
/** Collections to track. Defaults to every collection with versions. */
|
|
5
|
+
collections?: string[];
|
|
6
|
+
/** Globals to track. Defaults to every global with versions. */
|
|
7
|
+
globals?: string[];
|
|
8
|
+
};
|
|
9
|
+
export declare const historyPlugin: (options?: HistoryPluginConfig) => (config: Config) => Config;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { AUTHOR_FIELD } from './timeline.js';
|
|
2
|
+
export { AUTHOR_FIELD } from './timeline.js';
|
|
3
|
+
const TIMELINE = '@foundrykit/history-plugin/rsc#TimelineView';
|
|
4
|
+
/** Uses the timeline as the versions tab, unless the site already replaced it. */ const withTimeline = (views)=>({
|
|
5
|
+
...views,
|
|
6
|
+
edit: {
|
|
7
|
+
...views?.edit,
|
|
8
|
+
versions: views?.edit?.versions ?? {
|
|
9
|
+
Component: TIMELINE
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
const authorField = (usersSlug)=>({
|
|
14
|
+
name: AUTHOR_FIELD,
|
|
15
|
+
type: 'relationship',
|
|
16
|
+
admin: {
|
|
17
|
+
position: 'sidebar',
|
|
18
|
+
readOnly: true
|
|
19
|
+
},
|
|
20
|
+
hooks: {
|
|
21
|
+
// Always the person saving, whatever was sent. Saves with no admin user (scripts, the
|
|
22
|
+
// public site) record no author.
|
|
23
|
+
beforeChange: [
|
|
24
|
+
({ req })=>req.user?.collection === usersSlug ? req.user.id : null
|
|
25
|
+
]
|
|
26
|
+
},
|
|
27
|
+
label: 'Last edited by',
|
|
28
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion -- a union once a site generates types
|
|
29
|
+
relationTo: usersSlug
|
|
30
|
+
});
|
|
31
|
+
/**
|
|
32
|
+
* Version history needs a login and the entity's own read access. Payload's default only needs
|
|
33
|
+
* a login, so a site gating reads (for example with the permissions plugin) would leak history.
|
|
34
|
+
* The entity's read access is looked up at request time, so plugin order doesn't matter.
|
|
35
|
+
*/ /** Rewrites a read query on documents into the same query on their versions. */ const toVersionsWhere = (where)=>Object.fromEntries(Object.entries(where).map(([key, value])=>key === 'and' || key === 'or' ? [
|
|
36
|
+
key,
|
|
37
|
+
value.map(toVersionsWhere)
|
|
38
|
+
] : [
|
|
39
|
+
key === 'id' ? 'parent' : `version.${key}`,
|
|
40
|
+
value
|
|
41
|
+
]));
|
|
42
|
+
const readVersions = (getRead)=>async (args)=>{
|
|
43
|
+
if (!args.req.user) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
const read = getRead(args.req.payload);
|
|
47
|
+
const result = read ? await read(args) : true;
|
|
48
|
+
// A query limits which documents can be read, so it limits which versions can be read too.
|
|
49
|
+
return typeof result === 'boolean' ? result : toVersionsWhere(result);
|
|
50
|
+
};
|
|
51
|
+
const checkTracked = (kind, wanted, versioned)=>{
|
|
52
|
+
for (const slug of wanted ?? []){
|
|
53
|
+
if (!versioned.includes(slug)) {
|
|
54
|
+
throw new Error(`history: ${kind} "${slug}" doesn't exist or has versions turned off`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return new Set(wanted ?? versioned);
|
|
58
|
+
};
|
|
59
|
+
const checkNoAuthorField = (slug, fields)=>{
|
|
60
|
+
if (fields.some((field)=>'name' in field && field.name === AUTHOR_FIELD)) {
|
|
61
|
+
throw new Error(`history: "${slug}" already has a "${AUTHOR_FIELD}" field`);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
const trackCollection = (collection, usersSlug)=>{
|
|
65
|
+
checkNoAuthorField(collection.slug, collection.fields);
|
|
66
|
+
return {
|
|
67
|
+
...collection,
|
|
68
|
+
access: {
|
|
69
|
+
...collection.access,
|
|
70
|
+
readVersions: collection.access?.readVersions ?? readVersions((payload)=>// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion -- a union once a site generates types
|
|
71
|
+
payload.collections[collection.slug]?.config.access.read)
|
|
72
|
+
},
|
|
73
|
+
admin: {
|
|
74
|
+
...collection.admin,
|
|
75
|
+
components: {
|
|
76
|
+
...collection.admin?.components,
|
|
77
|
+
views: withTimeline(collection.admin?.components?.views)
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
fields: [
|
|
81
|
+
...collection.fields,
|
|
82
|
+
authorField(usersSlug)
|
|
83
|
+
]
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
const trackGlobal = (global, usersSlug)=>{
|
|
87
|
+
checkNoAuthorField(global.slug, global.fields);
|
|
88
|
+
return {
|
|
89
|
+
...global,
|
|
90
|
+
access: {
|
|
91
|
+
...global.access,
|
|
92
|
+
readVersions: global.access?.readVersions ?? readVersions((payload)=>payload.config.globals.find((g)=>g.slug === global.slug)?.access.read)
|
|
93
|
+
},
|
|
94
|
+
admin: {
|
|
95
|
+
...global.admin,
|
|
96
|
+
components: {
|
|
97
|
+
...global.admin?.components,
|
|
98
|
+
views: withTimeline(global.admin?.components?.views)
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
fields: [
|
|
102
|
+
...global.fields,
|
|
103
|
+
authorField(usersSlug)
|
|
104
|
+
]
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
export const historyPlugin = (options = {})=>(config)=>{
|
|
108
|
+
const usersSlug = config.admin?.user ?? 'users';
|
|
109
|
+
const collections = config.collections ?? [];
|
|
110
|
+
const globals = config.globals ?? [];
|
|
111
|
+
const trackedCollections = checkTracked('collection', options.collections, collections.filter((c)=>c.versions).map((c)=>c.slug));
|
|
112
|
+
const trackedGlobals = checkTracked('global', options.globals, globals.filter((g)=>g.versions).map((g)=>g.slug));
|
|
113
|
+
return {
|
|
114
|
+
...config,
|
|
115
|
+
collections: collections.map((c)=>trackedCollections.has(c.slug) ? trackCollection(c, usersSlug) : c),
|
|
116
|
+
globals: globals.map((g)=>trackedGlobals.has(g.slug) ? trackGlobal(g, usersSlug) : g)
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type {\n Access,\n AccessArgs,\n CollectionConfig,\n CollectionSlug,\n Config,\n Field,\n GlobalConfig,\n Payload,\n Where,\n} from 'payload'\n\nimport { AUTHOR_FIELD } from './timeline.js'\n\nexport { AUTHOR_FIELD } from './timeline.js'\n\nexport type HistoryPluginConfig = {\n /** Collections to track. Defaults to every collection with versions. */\n collections?: string[]\n /** Globals to track. Defaults to every global with versions. */\n globals?: string[]\n}\n\nconst TIMELINE = '@foundrykit/history-plugin/rsc#TimelineView'\n\ntype Views = NonNullable<NonNullable<CollectionConfig['admin']>['components']>['views']\n\n/** Uses the timeline as the versions tab, unless the site already replaced it. */\nconst withTimeline = (views: Views): Views => ({\n ...views,\n edit: {\n ...views?.edit,\n versions: views?.edit?.versions ?? { Component: TIMELINE },\n } as NonNullable<Views>['edit'],\n})\n\nconst authorField = (usersSlug: string): Field => ({\n name: AUTHOR_FIELD,\n type: 'relationship',\n admin: { position: 'sidebar', readOnly: true },\n hooks: {\n // Always the person saving, whatever was sent. Saves with no admin user (scripts, the\n // public site) record no author.\n beforeChange: [({ req }) => (req.user?.collection === usersSlug ? req.user.id : null)],\n },\n label: 'Last edited by',\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion -- a union once a site generates types\n relationTo: usersSlug as CollectionSlug,\n})\n\n/**\n * Version history needs a login and the entity's own read access. Payload's default only needs\n * a login, so a site gating reads (for example with the permissions plugin) would leak history.\n * The entity's read access is looked up at request time, so plugin order doesn't matter.\n */\n/** Rewrites a read query on documents into the same query on their versions. */\nconst toVersionsWhere = (where: Where): Where =>\n Object.fromEntries(\n Object.entries(where).map(([key, value]) =>\n key === 'and' || key === 'or'\n ? [key, (value as Where[]).map(toVersionsWhere)]\n : [key === 'id' ? 'parent' : `version.${key}`, value],\n ),\n )\n\nconst readVersions =\n (getRead: (payload: Payload) => Access | undefined): Access =>\n async (args: AccessArgs) => {\n if (!args.req.user) {\n return false\n }\n const read = getRead(args.req.payload)\n const result = read ? await read(args) : true\n // A query limits which documents can be read, so it limits which versions can be read too.\n return typeof result === 'boolean' ? result : toVersionsWhere(result)\n }\n\nconst checkTracked = (kind: string, wanted: string[] | undefined, versioned: string[]) => {\n for (const slug of wanted ?? []) {\n if (!versioned.includes(slug)) {\n throw new Error(`history: ${kind} \"${slug}\" doesn't exist or has versions turned off`)\n }\n }\n return new Set(wanted ?? versioned)\n}\n\nconst checkNoAuthorField = (slug: string, fields: Field[]) => {\n if (fields.some((field) => 'name' in field && field.name === AUTHOR_FIELD)) {\n throw new Error(`history: \"${slug}\" already has a \"${AUTHOR_FIELD}\" field`)\n }\n}\n\nconst trackCollection = (collection: CollectionConfig, usersSlug: string): CollectionConfig => {\n checkNoAuthorField(collection.slug, collection.fields)\n return {\n ...collection,\n access: {\n ...collection.access,\n readVersions:\n collection.access?.readVersions ??\n readVersions(\n (payload) =>\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion -- a union once a site generates types\n payload.collections[collection.slug as CollectionSlug]?.config.access.read,\n ),\n },\n admin: {\n ...collection.admin,\n components: {\n ...collection.admin?.components,\n views: withTimeline(collection.admin?.components?.views),\n },\n },\n fields: [...collection.fields, authorField(usersSlug)],\n }\n}\n\nconst trackGlobal = (global: GlobalConfig, usersSlug: string): GlobalConfig => {\n checkNoAuthorField(global.slug, global.fields)\n return {\n ...global,\n access: {\n ...global.access,\n readVersions:\n global.access?.readVersions ??\n readVersions(\n (payload) => payload.config.globals.find((g) => g.slug === global.slug)?.access.read,\n ),\n },\n admin: {\n ...global.admin,\n components: {\n ...global.admin?.components,\n views: withTimeline(global.admin?.components?.views),\n },\n },\n fields: [...global.fields, authorField(usersSlug)],\n }\n}\n\nexport const historyPlugin =\n (options: HistoryPluginConfig = {}) =>\n (config: Config): Config => {\n const usersSlug = config.admin?.user ?? 'users'\n const collections = config.collections ?? []\n const globals = config.globals ?? []\n\n const trackedCollections = checkTracked(\n 'collection',\n options.collections,\n collections.filter((c) => c.versions).map((c) => c.slug),\n )\n const trackedGlobals = checkTracked(\n 'global',\n options.globals,\n globals.filter((g) => g.versions).map((g) => g.slug),\n )\n\n return {\n ...config,\n collections: collections.map((c) =>\n trackedCollections.has(c.slug) ? trackCollection(c, usersSlug) : c,\n ),\n globals: globals.map((g) => (trackedGlobals.has(g.slug) ? trackGlobal(g, usersSlug) : g)),\n }\n }\n"],"names":["AUTHOR_FIELD","TIMELINE","withTimeline","views","edit","versions","Component","authorField","usersSlug","name","type","admin","position","readOnly","hooks","beforeChange","req","user","collection","id","label","relationTo","toVersionsWhere","where","Object","fromEntries","entries","map","key","value","readVersions","getRead","args","read","payload","result","checkTracked","kind","wanted","versioned","slug","includes","Error","Set","checkNoAuthorField","fields","some","field","trackCollection","access","collections","config","components","trackGlobal","global","globals","find","g","historyPlugin","options","trackedCollections","filter","c","trackedGlobals","has"],"mappings":"AAYA,SAASA,YAAY,QAAQ,gBAAe;AAE5C,SAASA,YAAY,QAAQ,gBAAe;AAS5C,MAAMC,WAAW;AAIjB,gFAAgF,GAChF,MAAMC,eAAe,CAACC,QAAyB,CAAA;QAC7C,GAAGA,KAAK;QACRC,MAAM;YACJ,GAAGD,OAAOC,IAAI;YACdC,UAAUF,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,OAAO3C,KAAK,EAAEyC,YAAYjD;YAChD;QACF;QACA0C,QAAQ;eAAIS,OAAOT,MAAM;YAAEtC,YAAYC;SAAW;IACpD;AACF;AAEA,OAAO,MAAMkD,gBACX,CAACC,UAA+B,CAAC,CAAC,GAClC,CAACR;QACC,MAAM3C,YAAY2C,OAAOxC,KAAK,EAAEM,QAAQ;QACxC,MAAMiC,cAAcC,OAAOD,WAAW,IAAI,EAAE;QAC5C,MAAMK,UAAUJ,OAAOI,OAAO,IAAI,EAAE;QAEpC,MAAMK,qBAAqBxB,aACzB,cACAuB,QAAQT,WAAW,EACnBA,YAAYW,MAAM,CAAC,CAACC,IAAMA,EAAEzD,QAAQ,EAAEsB,GAAG,CAAC,CAACmC,IAAMA,EAAEtB,IAAI;QAEzD,MAAMuB,iBAAiB3B,aACrB,UACAuB,QAAQJ,OAAO,EACfA,QAAQM,MAAM,CAAC,CAACJ,IAAMA,EAAEpD,QAAQ,EAAEsB,GAAG,CAAC,CAAC8B,IAAMA,EAAEjB,IAAI;QAGrD,OAAO;YACL,GAAGW,MAAM;YACTD,aAAaA,YAAYvB,GAAG,CAAC,CAACmC,IAC5BF,mBAAmBI,GAAG,CAACF,EAAEtB,IAAI,IAAIQ,gBAAgBc,GAAGtD,aAAasD;YAEnEP,SAASA,QAAQ5B,GAAG,CAAC,CAAC8B,IAAOM,eAAeC,GAAG,CAACP,EAAEjB,IAAI,IAAIa,YAAYI,GAAGjD,aAAaiD;QACxF;IACF,EAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { FlattenedField } from 'payload';
|
|
2
|
+
export declare const AUTHOR_FIELD = "updatedBy";
|
|
3
|
+
type ID = number | string;
|
|
4
|
+
export type RawVersion = {
|
|
5
|
+
autosave?: boolean;
|
|
6
|
+
id: ID;
|
|
7
|
+
latest?: boolean;
|
|
8
|
+
updatedAt: string;
|
|
9
|
+
version: Record<string, unknown>;
|
|
10
|
+
};
|
|
11
|
+
export type Kind = 'autosave' | 'draft' | 'published' | 'saved';
|
|
12
|
+
export type Entry = {
|
|
13
|
+
author: ID | null;
|
|
14
|
+
/** One label per changed field, e.g. "Title" or "Layout (+2 blocks)". */
|
|
15
|
+
changes: string[];
|
|
16
|
+
/** How many versions were merged into this entry (consecutive autosaves). */
|
|
17
|
+
count: number;
|
|
18
|
+
/** The first version, which has no earlier one to compare with. */
|
|
19
|
+
created: boolean;
|
|
20
|
+
id: ID;
|
|
21
|
+
kind: Kind;
|
|
22
|
+
latest: boolean;
|
|
23
|
+
updatedAt: string;
|
|
24
|
+
};
|
|
25
|
+
/** Labels for the top-level fields that differ between two version snapshots. */
|
|
26
|
+
export declare const changedFields: (fields: FlattenedField[], before: Record<string, unknown>, after: Record<string, unknown>) => string[];
|
|
27
|
+
/**
|
|
28
|
+
* Turns versions (newest first) into timeline entries. `older` is the version just before the
|
|
29
|
+
* last one on this page, used to work out what that one changed.
|
|
30
|
+
*/
|
|
31
|
+
export declare const buildTimeline: ({ drafts, fields, older, versions, }: {
|
|
32
|
+
drafts: boolean;
|
|
33
|
+
fields: FlattenedField[];
|
|
34
|
+
older?: RawVersion;
|
|
35
|
+
versions: RawVersion[];
|
|
36
|
+
}) => Entry[];
|
|
37
|
+
export {};
|
package/dist/timeline.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
export const AUTHOR_FIELD = 'updatedBy';
|
|
2
|
+
/** Bookkeeping fields every version has; they never count as a change. */ const IGNORED = new Set([
|
|
3
|
+
'_status',
|
|
4
|
+
AUTHOR_FIELD,
|
|
5
|
+
'createdAt',
|
|
6
|
+
'id',
|
|
7
|
+
'updatedAt'
|
|
8
|
+
]);
|
|
9
|
+
const kindOf = (v, drafts)=>{
|
|
10
|
+
if (v.autosave) {
|
|
11
|
+
return 'autosave';
|
|
12
|
+
}
|
|
13
|
+
if (!drafts) {
|
|
14
|
+
return 'saved';
|
|
15
|
+
}
|
|
16
|
+
return v.version._status === 'published' ? 'published' : 'draft';
|
|
17
|
+
};
|
|
18
|
+
const plural = (n, word)=>`${n} ${word}${n === 1 ? '' : 's'}`;
|
|
19
|
+
/** Labels for the top-level fields that differ between two version snapshots. */ export const changedFields = (fields, before, after)=>fields.flatMap((field)=>{
|
|
20
|
+
if (IGNORED.has(field.name)) {
|
|
21
|
+
return [];
|
|
22
|
+
}
|
|
23
|
+
const a = before[field.name];
|
|
24
|
+
const b = after[field.name];
|
|
25
|
+
if (JSON.stringify(a ?? null) === JSON.stringify(b ?? null)) {
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
28
|
+
const label = typeof field.label === 'string' ? field.label : field.name;
|
|
29
|
+
if ((field.type === 'blocks' || field.type === 'array') && Array.isArray(b)) {
|
|
30
|
+
const diff = b.length - (Array.isArray(a) ? a.length : 0);
|
|
31
|
+
const unit = field.type === 'blocks' ? 'block' : 'row';
|
|
32
|
+
if (diff > 0) {
|
|
33
|
+
return [
|
|
34
|
+
`${label} (+${plural(diff, unit)})`
|
|
35
|
+
];
|
|
36
|
+
}
|
|
37
|
+
if (diff < 0) {
|
|
38
|
+
return [
|
|
39
|
+
`${label} (−${plural(-diff, unit)})`
|
|
40
|
+
];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return [
|
|
44
|
+
label
|
|
45
|
+
];
|
|
46
|
+
});
|
|
47
|
+
/**
|
|
48
|
+
* Turns versions (newest first) into timeline entries. `older` is the version just before the
|
|
49
|
+
* last one on this page, used to work out what that one changed.
|
|
50
|
+
*/ export const buildTimeline = ({ drafts, fields, older, versions })=>{
|
|
51
|
+
const authorOf = (v)=>v.version[AUTHOR_FIELD] ?? null;
|
|
52
|
+
// A run of autosaves by one person reads as one edit, so group them first.
|
|
53
|
+
const groups = [];
|
|
54
|
+
for (const v of versions){
|
|
55
|
+
const group = groups.at(-1);
|
|
56
|
+
const head = group?.[0];
|
|
57
|
+
if (head && head.autosave && v.autosave && String(authorOf(head)) === String(authorOf(v))) {
|
|
58
|
+
group.push(v);
|
|
59
|
+
} else {
|
|
60
|
+
groups.push([
|
|
61
|
+
v
|
|
62
|
+
]);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
let seen = 0;
|
|
66
|
+
return groups.map((group)=>{
|
|
67
|
+
seen += group.length;
|
|
68
|
+
const newest = group[0];
|
|
69
|
+
// What the whole group changed: compare the newest with the version before the oldest.
|
|
70
|
+
const previous = versions[seen] ?? older;
|
|
71
|
+
return {
|
|
72
|
+
id: newest.id,
|
|
73
|
+
author: authorOf(newest),
|
|
74
|
+
changes: previous ? changedFields(fields, previous.version, newest.version) : [],
|
|
75
|
+
count: group.length,
|
|
76
|
+
created: !previous,
|
|
77
|
+
kind: kindOf(newest, drafts),
|
|
78
|
+
latest: Boolean(newest.latest),
|
|
79
|
+
updatedAt: newest.updatedAt
|
|
80
|
+
};
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
//# sourceMappingURL=timeline.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/timeline.ts"],"sourcesContent":["import type { FlattenedField } from 'payload'\n\nexport const AUTHOR_FIELD = 'updatedBy'\n\n/** Bookkeeping fields every version has; they never count as a change. */\nconst IGNORED = new Set(['_status', AUTHOR_FIELD, 'createdAt', 'id', 'updatedAt'])\n\ntype ID = number | string\n\nexport type RawVersion = {\n autosave?: boolean\n id: ID\n latest?: boolean\n updatedAt: string\n version: Record<string, unknown>\n}\n\nexport type Kind = 'autosave' | 'draft' | 'published' | 'saved'\n\nexport type Entry = {\n author: ID | null\n /** One label per changed field, e.g. \"Title\" or \"Layout (+2 blocks)\". */\n changes: string[]\n /** How many versions were merged into this entry (consecutive autosaves). */\n count: number\n /** The first version, which has no earlier one to compare with. */\n created: boolean\n id: ID\n kind: Kind\n latest: boolean\n updatedAt: string\n}\n\nconst kindOf = (v: RawVersion, drafts: boolean): Kind => {\n if (v.autosave) {\n return 'autosave'\n }\n if (!drafts) {\n return 'saved'\n }\n return v.version._status === 'published' ? 'published' : 'draft'\n}\n\nconst plural = (n: number, word: string) => `${n} ${word}${n === 1 ? '' : 's'}`\n\n/** Labels for the top-level fields that differ between two version snapshots. */\nexport const changedFields = (\n fields: FlattenedField[],\n before: Record<string, unknown>,\n after: Record<string, unknown>,\n): string[] =>\n fields.flatMap((field) => {\n if (IGNORED.has(field.name)) {\n return []\n }\n const a = before[field.name]\n const b = after[field.name]\n if (JSON.stringify(a ?? null) === JSON.stringify(b ?? null)) {\n return []\n }\n const label = typeof field.label === 'string' ? field.label : field.name\n if ((field.type === 'blocks' || field.type === 'array') && Array.isArray(b)) {\n const diff = b.length - (Array.isArray(a) ? a.length : 0)\n const unit = field.type === 'blocks' ? 'block' : 'row'\n if (diff > 0) {\n return [`${label} (+${plural(diff, unit)})`]\n }\n if (diff < 0) {\n return [`${label} (−${plural(-diff, unit)})`]\n }\n }\n return [label]\n })\n\n/**\n * Turns versions (newest first) into timeline entries. `older` is the version just before the\n * last one on this page, used to work out what that one changed.\n */\nexport const buildTimeline = ({\n drafts,\n fields,\n older,\n versions,\n}: {\n drafts: boolean\n fields: FlattenedField[]\n older?: RawVersion\n versions: RawVersion[]\n}): Entry[] => {\n const authorOf = (v: RawVersion) => (v.version[AUTHOR_FIELD] as ID | null | undefined) ?? null\n\n // A run of autosaves by one person reads as one edit, so group them first.\n const groups: RawVersion[][] = []\n for (const v of versions) {\n const group = groups.at(-1)\n const head = group?.[0]\n if (head && head.autosave && v.autosave && String(authorOf(head)) === String(authorOf(v))) {\n group.push(v)\n } else {\n groups.push([v])\n }\n }\n\n let seen = 0\n return groups.map((group) => {\n seen += group.length\n const newest = group[0]\n // What the whole group changed: compare the newest with the version before the oldest.\n const previous = versions[seen] ?? older\n return {\n id: newest.id,\n author: authorOf(newest),\n changes: previous ? changedFields(fields, previous.version, newest.version) : [],\n count: group.length,\n created: !previous,\n kind: kindOf(newest, drafts),\n latest: Boolean(newest.latest),\n updatedAt: newest.updatedAt,\n }\n })\n}\n"],"names":["AUTHOR_FIELD","IGNORED","Set","kindOf","v","drafts","autosave","version","_status","plural","n","word","changedFields","fields","before","after","flatMap","field","has","name","a","b","JSON","stringify","label","type","Array","isArray","diff","length","unit","buildTimeline","older","versions","authorOf","groups","group","at","head","String","push","seen","map","newest","previous","id","author","changes","count","created","kind","latest","Boolean","updatedAt"],"mappings":"AAEA,OAAO,MAAMA,eAAe,YAAW;AAEvC,wEAAwE,GACxE,MAAMC,UAAU,IAAIC,IAAI;IAAC;IAAWF;IAAc;IAAa;IAAM;CAAY;AA4BjF,MAAMG,SAAS,CAACC,GAAeC;IAC7B,IAAID,EAAEE,QAAQ,EAAE;QACd,OAAO;IACT;IACA,IAAI,CAACD,QAAQ;QACX,OAAO;IACT;IACA,OAAOD,EAAEG,OAAO,CAACC,OAAO,KAAK,cAAc,cAAc;AAC3D;AAEA,MAAMC,SAAS,CAACC,GAAWC,OAAiB,GAAGD,EAAE,CAAC,EAAEC,OAAOD,MAAM,IAAI,KAAK,KAAK;AAE/E,+EAA+E,GAC/E,OAAO,MAAME,gBAAgB,CAC3BC,QACAC,QACAC,QAEAF,OAAOG,OAAO,CAAC,CAACC;QACd,IAAIhB,QAAQiB,GAAG,CAACD,MAAME,IAAI,GAAG;YAC3B,OAAO,EAAE;QACX;QACA,MAAMC,IAAIN,MAAM,CAACG,MAAME,IAAI,CAAC;QAC5B,MAAME,IAAIN,KAAK,CAACE,MAAME,IAAI,CAAC;QAC3B,IAAIG,KAAKC,SAAS,CAACH,KAAK,UAAUE,KAAKC,SAAS,CAACF,KAAK,OAAO;YAC3D,OAAO,EAAE;QACX;QACA,MAAMG,QAAQ,OAAOP,MAAMO,KAAK,KAAK,WAAWP,MAAMO,KAAK,GAAGP,MAAME,IAAI;QACxE,IAAI,AAACF,CAAAA,MAAMQ,IAAI,KAAK,YAAYR,MAAMQ,IAAI,KAAK,OAAM,KAAMC,MAAMC,OAAO,CAACN,IAAI;YAC3E,MAAMO,OAAOP,EAAEQ,MAAM,GAAIH,CAAAA,MAAMC,OAAO,CAACP,K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AAI,EAAE;YAChFyC,OAAOZ,MAAMP,MAAM;YACnBoB,SAAS,CAACL;YACVM,MAAM/C,OAAOwC,QAAQtC;YACrB8C,QAAQC,QAAQT,OAAOQ,MAAM;YAC7BE,WAAWV,OAAOU,SAAS;QAC7B;IACF;AACF,EAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { DocumentViewServerProps } from 'payload';
|
|
2
|
+
import './index.scss';
|
|
3
|
+
/** Replaces Payload's versions table with a timeline: who, when, what kind of save, what changed. */
|
|
4
|
+
export declare const TimelineView: ({ initPageResult, searchParams }: DocumentViewServerProps) => Promise<import("react/jsx-runtime").JSX.Element>;
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { Gutter, Pill, SetDocumentStepNav } from '@payloadcms/ui';
|
|
3
|
+
import { notFound } from 'next/navigation.js';
|
|
4
|
+
import { formatAdminURL } from 'payload/shared';
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import { buildTimeline } from '../timeline.js';
|
|
7
|
+
import './index.scss';
|
|
8
|
+
const PER_PAGE = 25;
|
|
9
|
+
const KIND_LABELS = {
|
|
10
|
+
autosave: 'Autosave',
|
|
11
|
+
draft: 'Draft',
|
|
12
|
+
published: 'Published',
|
|
13
|
+
saved: 'Saved'
|
|
14
|
+
};
|
|
15
|
+
const initials = (label)=>label.split(/[\s@.]+/).filter(Boolean).slice(0, 2).map((part)=>part[0].toUpperCase()).join('');
|
|
16
|
+
const UNITS = [
|
|
17
|
+
[
|
|
18
|
+
'year',
|
|
19
|
+
365 * 24 * 3600
|
|
20
|
+
],
|
|
21
|
+
[
|
|
22
|
+
'month',
|
|
23
|
+
30 * 24 * 3600
|
|
24
|
+
],
|
|
25
|
+
[
|
|
26
|
+
'week',
|
|
27
|
+
7 * 24 * 3600
|
|
28
|
+
],
|
|
29
|
+
[
|
|
30
|
+
'day',
|
|
31
|
+
24 * 3600
|
|
32
|
+
],
|
|
33
|
+
[
|
|
34
|
+
'hour',
|
|
35
|
+
3600
|
|
36
|
+
],
|
|
37
|
+
[
|
|
38
|
+
'minute',
|
|
39
|
+
60
|
|
40
|
+
]
|
|
41
|
+
];
|
|
42
|
+
const timeAgo = (iso, locale)=>{
|
|
43
|
+
const seconds = (Date.parse(iso) - Date.now()) / 1000;
|
|
44
|
+
const format = new Intl.RelativeTimeFormat(locale, {
|
|
45
|
+
numeric: 'auto'
|
|
46
|
+
});
|
|
47
|
+
for (const [unit, size] of UNITS){
|
|
48
|
+
if (Math.abs(seconds) >= size) {
|
|
49
|
+
return format.format(Math.round(seconds / size), unit);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return format.format(0, 'minute');
|
|
53
|
+
};
|
|
54
|
+
const describe = (entry)=>{
|
|
55
|
+
if (entry.created) {
|
|
56
|
+
return 'Created';
|
|
57
|
+
}
|
|
58
|
+
if (!entry.changes.length) {
|
|
59
|
+
return 'No content changes';
|
|
60
|
+
}
|
|
61
|
+
return `Changed ${entry.changes.join(', ')}`;
|
|
62
|
+
};
|
|
63
|
+
/** Replaces Payload's versions table with a timeline: who, when, what kind of save, what changed. */ export const TimelineView = async ({ initPageResult, searchParams })=>{
|
|
64
|
+
const { collectionConfig, docID, globalConfig, req } = initPageResult;
|
|
65
|
+
const { payload, user } = req;
|
|
66
|
+
const entity = collectionConfig ?? globalConfig;
|
|
67
|
+
if (!entity) {
|
|
68
|
+
return notFound();
|
|
69
|
+
}
|
|
70
|
+
const page = Math.max(1, Number(searchParams?.page) || 1);
|
|
71
|
+
// One extra version, so the last entry on the page can be compared with the one before it.
|
|
72
|
+
// ponytail: offset paging by over-fetching; fine for hundreds of versions, switch to a
|
|
73
|
+
// cursor on updatedAt if documents get thousands.
|
|
74
|
+
const skip = (page - 1) * PER_PAGE;
|
|
75
|
+
const query = {
|
|
76
|
+
depth: 0,
|
|
77
|
+
limit: skip + PER_PAGE + 1,
|
|
78
|
+
overrideAccess: false,
|
|
79
|
+
req,
|
|
80
|
+
sort: '-updatedAt',
|
|
81
|
+
user
|
|
82
|
+
};
|
|
83
|
+
const result = collectionConfig ? await payload.findVersions({
|
|
84
|
+
...query,
|
|
85
|
+
collection: collectionConfig.slug,
|
|
86
|
+
where: {
|
|
87
|
+
parent: {
|
|
88
|
+
equals: docID
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}) : await payload.findGlobalVersions({
|
|
92
|
+
...query,
|
|
93
|
+
slug: globalConfig.slug
|
|
94
|
+
});
|
|
95
|
+
const docs = result.docs.slice(skip);
|
|
96
|
+
const versions = docs.slice(0, PER_PAGE);
|
|
97
|
+
const hasMore = docs.length > PER_PAGE;
|
|
98
|
+
const entries = buildTimeline({
|
|
99
|
+
drafts: Boolean(entity.versions && entity.versions.drafts),
|
|
100
|
+
fields: entity.flattenedFields,
|
|
101
|
+
older: docs[PER_PAGE],
|
|
102
|
+
versions
|
|
103
|
+
});
|
|
104
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion -- a union once a site generates types
|
|
105
|
+
const usersSlug = payload.config.admin.user;
|
|
106
|
+
const titleField = payload.collections[usersSlug]?.config.admin.useAsTitle ?? 'email';
|
|
107
|
+
const authorIDs = [
|
|
108
|
+
...new Set(entries.map((e)=>e.author).filter((id)=>id !== null))
|
|
109
|
+
];
|
|
110
|
+
const authors = authorIDs.length ? (await payload.find({
|
|
111
|
+
collection: usersSlug,
|
|
112
|
+
depth: 0,
|
|
113
|
+
limit: authorIDs.length,
|
|
114
|
+
overrideAccess: true,
|
|
115
|
+
pagination: false,
|
|
116
|
+
req,
|
|
117
|
+
where: {
|
|
118
|
+
id: {
|
|
119
|
+
in: authorIDs
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
})).docs : [];
|
|
123
|
+
const nameOf = (id)=>{
|
|
124
|
+
const author = authors.find((a)=>String(a.id) === String(id));
|
|
125
|
+
if (!author) {
|
|
126
|
+
return id === null ? 'Unknown' : 'Deleted user';
|
|
127
|
+
}
|
|
128
|
+
return String(author[titleField] || author.email || author.id);
|
|
129
|
+
};
|
|
130
|
+
const base = collectionConfig ? `/collections/${collectionConfig.slug}/${docID}/versions` : `/globals/${globalConfig.slug}/versions`;
|
|
131
|
+
const url = (path)=>formatAdminURL({
|
|
132
|
+
adminRoute: payload.config.routes.admin,
|
|
133
|
+
path
|
|
134
|
+
});
|
|
135
|
+
const label = collectionConfig ? typeof collectionConfig.labels.plural === 'string' ? collectionConfig.labels.plural : collectionConfig.slug : typeof globalConfig.label === 'string' ? globalConfig.label : globalConfig.slug;
|
|
136
|
+
return /*#__PURE__*/ _jsxs(_Fragment, {
|
|
137
|
+
children: [
|
|
138
|
+
/*#__PURE__*/ _jsx(SetDocumentStepNav, {
|
|
139
|
+
collectionSlug: collectionConfig?.slug,
|
|
140
|
+
globalSlug: globalConfig?.slug,
|
|
141
|
+
id: docID,
|
|
142
|
+
pluralLabel: label,
|
|
143
|
+
useAsTitle: collectionConfig?.admin.useAsTitle ?? globalConfig?.slug,
|
|
144
|
+
view: "Versions"
|
|
145
|
+
}),
|
|
146
|
+
/*#__PURE__*/ _jsx("main", {
|
|
147
|
+
className: "history",
|
|
148
|
+
children: /*#__PURE__*/ _jsxs(Gutter, {
|
|
149
|
+
children: [
|
|
150
|
+
entries.length === 0 ? /*#__PURE__*/ _jsx("p", {
|
|
151
|
+
children: "No versions yet."
|
|
152
|
+
}) : /*#__PURE__*/ _jsx("ol", {
|
|
153
|
+
className: "history__list",
|
|
154
|
+
children: entries.map((entry)=>{
|
|
155
|
+
const name = nameOf(entry.author);
|
|
156
|
+
return /*#__PURE__*/ _jsxs("li", {
|
|
157
|
+
className: "history__entry",
|
|
158
|
+
children: [
|
|
159
|
+
/*#__PURE__*/ _jsx("span", {
|
|
160
|
+
"aria-hidden": true,
|
|
161
|
+
className: "history__avatar",
|
|
162
|
+
children: initials(name)
|
|
163
|
+
}),
|
|
164
|
+
/*#__PURE__*/ _jsxs("div", {
|
|
165
|
+
className: "history__body",
|
|
166
|
+
children: [
|
|
167
|
+
/*#__PURE__*/ _jsxs("div", {
|
|
168
|
+
className: "history__meta",
|
|
169
|
+
children: [
|
|
170
|
+
/*#__PURE__*/ _jsx("strong", {
|
|
171
|
+
children: name
|
|
172
|
+
}),
|
|
173
|
+
/*#__PURE__*/ _jsx("time", {
|
|
174
|
+
dateTime: entry.updatedAt,
|
|
175
|
+
title: entry.updatedAt,
|
|
176
|
+
children: timeAgo(entry.updatedAt, req.i18n.language)
|
|
177
|
+
}),
|
|
178
|
+
/*#__PURE__*/ _jsx(Pill, {
|
|
179
|
+
size: "small",
|
|
180
|
+
children: entry.count > 1 ? `${entry.count} autosaves` : KIND_LABELS[entry.kind]
|
|
181
|
+
}),
|
|
182
|
+
entry.latest && /*#__PURE__*/ _jsx(Pill, {
|
|
183
|
+
size: "small",
|
|
184
|
+
children: "Latest"
|
|
185
|
+
})
|
|
186
|
+
]
|
|
187
|
+
}),
|
|
188
|
+
/*#__PURE__*/ _jsx("div", {
|
|
189
|
+
className: "history__changes",
|
|
190
|
+
children: describe(entry)
|
|
191
|
+
})
|
|
192
|
+
]
|
|
193
|
+
}),
|
|
194
|
+
/*#__PURE__*/ _jsx("a", {
|
|
195
|
+
className: "history__compare",
|
|
196
|
+
href: url(`${base}/${entry.id}`),
|
|
197
|
+
children: "View"
|
|
198
|
+
})
|
|
199
|
+
]
|
|
200
|
+
}, entry.id);
|
|
201
|
+
})
|
|
202
|
+
}),
|
|
203
|
+
(page > 1 || hasMore) && /*#__PURE__*/ _jsxs("nav", {
|
|
204
|
+
className: "history__pages",
|
|
205
|
+
children: [
|
|
206
|
+
page > 1 && /*#__PURE__*/ _jsx("a", {
|
|
207
|
+
href: `?page=${page - 1}`,
|
|
208
|
+
children: "Newer"
|
|
209
|
+
}),
|
|
210
|
+
hasMore && /*#__PURE__*/ _jsx("a", {
|
|
211
|
+
href: `?page=${page + 1}`,
|
|
212
|
+
children: "Older"
|
|
213
|
+
})
|
|
214
|
+
]
|
|
215
|
+
})
|
|
216
|
+
]
|
|
217
|
+
})
|
|
218
|
+
})
|
|
219
|
+
]
|
|
220
|
+
});
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
//# sourceMappingURL=TimelineView.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/views/TimelineView.tsx"],"sourcesContent":["import type { CollectionSlug, DocumentViewServerProps } from 'payload'\n\nimport { Gutter, Pill, SetDocumentStepNav } from '@payloadcms/ui'\nimport { notFound } from 'next/navigation.js'\nimport { formatAdminURL } from 'payload/shared'\nimport React from 'react'\n\nimport type { Entry, Kind, RawVersion } from '../timeline.js'\n\nimport { buildTimeline } from '../timeline.js'\nimport './index.scss'\n\nconst PER_PAGE = 25\n\nconst KIND_LABELS: Record<Kind, string> = {\n autosave: 'Autosave',\n draft: 'Draft',\n published: 'Published',\n saved: 'Saved',\n}\n\nconst initials = (label: string) =>\n label\n .split(/[\\s@.]+/)\n .filter(Boolean)\n .slice(0, 2)\n .map((part) => part[0].toUpperCase())\n .join('')\n\nconst UNITS: [Intl.RelativeTimeFormatUnit, number][] = [\n ['year', 365 * 24 * 3600],\n ['month', 30 * 24 * 3600],\n ['week', 7 * 24 * 3600],\n ['day', 24 * 3600],\n ['hour', 3600],\n ['minute', 60],\n]\n\nconst timeAgo = (iso: string, locale: string) => {\n const seconds = (Date.parse(iso) - Date.now()) / 1000\n const format = new Intl.RelativeTimeFormat(locale, { numeric: 'auto' })\n for (const [unit, size] of UNITS) {\n if (Math.abs(seconds) >= size) {\n return format.format(Math.round(seconds / size), unit)\n }\n }\n return format.format(0, 'minute')\n}\n\nconst describe = (entry: Entry) => {\n if (entry.created) {\n return 'Created'\n }\n if (!entry.changes.length) {\n return 'No content changes'\n }\n return `Changed ${entry.changes.join(', ')}`\n}\n\n/** Replaces Payload's versions table with a timeline: who, when, what kind of save, what changed. */\nexport const TimelineView = async ({ initPageResult, searchParams }: DocumentViewServerProps) => {\n const { collectionConfig, docID, globalConfig, req } = initPageResult\n const { payload, user } = req\n const entity = collectionConfig ?? globalConfig\n if (!entity) {\n return notFound()\n }\n const page = Math.max(1, Number(searchParams?.page) || 1)\n\n // One extra version, so the last entry on the page can be compared with the one before it.\n // ponytail: offset paging by over-fetching; fine for hundreds of versions, switch to a\n // cursor on updatedAt if documents get thousands.\n const skip = (page - 1) * PER_PAGE\n const query = {\n depth: 0,\n limit: skip + PER_PAGE + 1,\n overrideAccess: false,\n req,\n sort: '-updatedAt',\n user,\n } as const\n const result = collectionConfig\n ? await payload.findVersions({\n ...query,\n collection: collectionConfig.slug,\n where: { parent: { equals: docID } },\n })\n : await payload.findGlobalVersions({ ...query, slug: globalConfig!.slug })\n const docs = (result.docs as unknown as RawVersion[]).slice(skip)\n const versions = docs.slice(0, PER_PAGE)\n const hasMore = docs.length > PER_PAGE\n\n const entries = buildTimeline({\n drafts: Boolean(entity.versions && entity.versions.drafts),\n fields: entity.flattenedFields,\n older: docs[PER_PAGE],\n versions,\n })\n\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion -- a union once a site generates types\n const usersSlug = payload.config.admin.user as CollectionSlug\n const titleField = payload.collections[usersSlug]?.config.admin.useAsTitle ?? 'email'\n const authorIDs = [...new Set(entries.map((e) => e.author).filter((id) => id !== null))]\n const authors = authorIDs.length\n ? (\n await payload.find({\n collection: usersSlug,\n depth: 0,\n limit: authorIDs.length,\n overrideAccess: true,\n pagination: false,\n req,\n where: { id: { in: authorIDs } },\n })\n ).docs\n : []\n const nameOf = (id: Entry['author']) => {\n const author = authors.find((a) => String(a.id) === String(id)) as\n Record<string, unknown> | undefined\n if (!author) {\n return id === null ? 'Unknown' : 'Deleted user'\n }\n return String(author[titleField] || author.email || author.id)\n }\n\n const base: `/${string}` = collectionConfig\n ? `/collections/${collectionConfig.slug}/${docID}/versions`\n : `/globals/${globalConfig!.slug}/versions`\n const url = (path: `/${string}`) =>\n formatAdminURL({ adminRoute: payload.config.routes.admin, path })\n const label = collectionConfig\n ? typeof collectionConfig.labels.plural === 'string'\n ? collectionConfig.labels.plural\n : collectionConfig.slug\n : typeof globalConfig!.label === 'string'\n ? globalConfig!.label\n : globalConfig!.slug\n\n return (\n <>\n <SetDocumentStepNav\n collectionSlug={collectionConfig?.slug}\n globalSlug={globalConfig?.slug}\n id={docID}\n pluralLabel={label}\n useAsTitle={collectionConfig?.admin.useAsTitle ?? globalConfig?.slug}\n view=\"Versions\"\n />\n <main className=\"history\">\n <Gutter>\n {entries.length === 0 ? (\n <p>No versions yet.</p>\n ) : (\n <ol className=\"history__list\">\n {entries.map((entry) => {\n const name = nameOf(entry.author)\n return (\n <li className=\"history__entry\" key={entry.id}>\n <span aria-hidden className=\"history__avatar\">\n {initials(name)}\n </span>\n <div className=\"history__body\">\n <div className=\"history__meta\">\n <strong>{name}</strong>\n <time dateTime={entry.updatedAt} title={entry.updatedAt}>\n {timeAgo(entry.updatedAt, req.i18n.language)}\n </time>\n <Pill size=\"small\">\n {entry.count > 1 ? `${entry.count} autosaves` : KIND_LABELS[entry.kind]}\n </Pill>\n {entry.latest && <Pill size=\"small\">Latest</Pill>}\n </div>\n <div className=\"history__changes\">{describe(entry)}</div>\n </div>\n {/* A plain link: Payload's client-side Link didn't navigate from this view. */}\n <a className=\"history__compare\" href={url(`${base}/${entry.id}`)}>\n View\n </a>\n </li>\n )\n })}\n </ol>\n )}\n {(page > 1 || hasMore) && (\n <nav className=\"history__pages\">\n {page > 1 && <a href={`?page=${page - 1}`}>Newer</a>}\n {hasMore && <a href={`?page=${page + 1}`}>Older</a>}\n </nav>\n )}\n </Gutter>\n </main>\n </>\n )\n}\n"],"names":["Gutter","Pill","SetDocumentStepNav","notFound","formatAdminURL","React","buildTimeline","PER_PAGE","KIND_LABELS","autosave","draft","published","saved","initials","label","split","filter","Boolean","slice","map","part","toUpperCase","join","UNITS","timeAgo","iso","locale","seconds","Date","parse","now","format","Intl","RelativeTimeFormat","numeric","unit","size","Math","abs","round","describe","entry","created","changes","length","TimelineView","initPageResult","searchParams","collectionConfig","docID","globalConfig","req","payload","user","entity","page","max","Number","skip","query","depth","limit","overrideAccess","sort","result","findVersions","collection","slug","where","parent","equals","findGlobalVersions","docs","versions","hasMore","entries","drafts","fields","flattenedFields","older","usersSlug","config","admin","titleField","collections","useAsTitle","authorIDs","Set","e","author","id","authors","find","pagination","in","nameOf","a","String","email","base","url","path","adminRoute","routes","labels","plural","collectionSlug","globalSlug","pluralLabel","view","main","className","p","ol","name","li","span","aria-hidden","div","strong","time","dateTime","updatedAt","title","i18n","language","count","kind","latest","href","nav"],"mappings":";AAEA,SAASA,MAAM,EAAEC,IAAI,EAAEC,kBAAkB,QAAQ,iBAAgB;AACjE,SAASC,QAAQ,QAAQ,qBAAoB;AAC7C,SAASC,cAAc,QAAQ,iBAAgB;AAC/C,OAAOC,WAAW,QAAO;AAIzB,SAASC,aAAa,QAAQ,iBAAgB;AAC9C,OAAO,eAAc;AAErB,MAAMC,WAAW;AAEjB,MAAMC,cAAoC;IACxCC,UAAU;IACVC,OAAO;IACPC,WAAW;IACXC,OAAO;AACT;AAEA,MAAMC,WAAW,CAACC,QAChBA,MACGC,KAAK,CAAC,WACNC,MAAM,CAACC,SACPC,KAAK,CAAC,GAAG,GACTC,GAAG,CAAC,CAACC,OAASA,IAAI,CAAC,EAAE,CAACC,WAAW,IACjCC,IAAI,CAAC;AAEV,MAAMC,QAAiD;IACrD;QAAC;QAAQ,MAAM,KAAK;KAAK;IACzB;QAAC;QAAS,KAAK,KAAK;KAAK;IACzB;QAAC;QAAQ,IAAI,KAAK;KAAK;IACvB;QAAC;QAAO,KAAK;KAAK;IAClB;QAAC;QAAQ;KAAK;IACd;QAAC;QAAU;KAAG;CACf;AAED,MAAMC,UAAU,CAACC,KAAaC;IAC5B,MAAMC,UAAU,AAACC,CAAAA,KAAKC,KAAK,CAACJ,OAAOG,KAAKE,GAAG,EA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AAIyE,IAAI,CAACC,QAAQ;;sEAE7C,KAAC5H;4DAAKmC,MAAK;sEACRK,MAAMqF,KAAK,GAAG,IAAI,GAAGrF,MAAMqF,KAAK,CAAC,UAAU,CAAC,GAAGtH,WAAW,CAACiC,MAAMsF,IAAI,CAAC;;wDAExEtF,MAAMuF,MAAM,kBAAI,KAAC/H;4DAAKmC,MAAK;sEAAQ;;;;8DAEtC,KAACkF;oDAAIP,WAAU;8DAAoBvE,SAASC;;;;sDAG9C,KAACuD;4CAAEe,WAAU;4CAAmBkB,MAAM7B,IAAI,GAAGD,KAAK,CAAC,EAAE1D,MAAMiD,EAAE,EAAE;sDAAG;;;mCAlBhCjD,MAAMiD,EAAE;4BAuBhD;;wBAGFnC,CAAAA,OAAO,KAAKmB,OAAM,mBAClB,MAACwD;4BAAInB,WAAU;;gCACZxD,OAAO,mBAAK,KAACyC;oCAAEiC,MAAM,CAAC,MAAM,EAAE1E,OAAO,GAAG;8CAAE;;gCAC1CmB,yBAAW,KAACsB;oCAAEiC,MAAM,CAAC,MAAM,EAAE1E,OAAO,GAAG;8CAAE;;;;;;;;;AAOxD,EAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// Uses the admin theme's variables so it follows light/dark mode.
|
|
2
|
+
|
|
3
|
+
.history {
|
|
4
|
+
padding-bottom: calc(var(--base) * 4);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.history__list {
|
|
8
|
+
list-style: none;
|
|
9
|
+
margin: 0;
|
|
10
|
+
padding: 0;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.history__entry {
|
|
14
|
+
align-items: center;
|
|
15
|
+
border-bottom: 1px solid var(--theme-elevation-100);
|
|
16
|
+
display: flex;
|
|
17
|
+
gap: var(--base);
|
|
18
|
+
padding: calc(var(--base) * 0.75) 0;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.history__avatar {
|
|
22
|
+
align-items: center;
|
|
23
|
+
background: var(--theme-elevation-150);
|
|
24
|
+
border-radius: 50%;
|
|
25
|
+
display: inline-flex;
|
|
26
|
+
flex-shrink: 0;
|
|
27
|
+
font-size: 0.75em;
|
|
28
|
+
height: 32px;
|
|
29
|
+
justify-content: center;
|
|
30
|
+
width: 32px;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.history__body {
|
|
34
|
+
flex: 1;
|
|
35
|
+
min-width: 0;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.history__meta {
|
|
39
|
+
align-items: center;
|
|
40
|
+
display: flex;
|
|
41
|
+
flex-wrap: wrap;
|
|
42
|
+
gap: calc(var(--base) * 0.5);
|
|
43
|
+
|
|
44
|
+
time {
|
|
45
|
+
color: var(--theme-elevation-500);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.history__changes {
|
|
50
|
+
color: var(--theme-elevation-600);
|
|
51
|
+
margin-top: calc(var(--base) * 0.25);
|
|
52
|
+
overflow-wrap: anywhere;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.history__compare {
|
|
56
|
+
flex-shrink: 0;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.history__pages {
|
|
60
|
+
display: flex;
|
|
61
|
+
gap: var(--base);
|
|
62
|
+
margin-top: var(--base);
|
|
63
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,109 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@foundrykit/history-plugin",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Version history for Payload CMS 3: who made each version, a timeline of changes and a clearer compare view",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/umi-labs/history-plugin.git"
|
|
9
|
+
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"default": "./dist/index.js"
|
|
16
|
+
},
|
|
17
|
+
"./client": {
|
|
18
|
+
"import": "./dist/exports/client.js",
|
|
19
|
+
"types": "./dist/exports/client.d.ts",
|
|
20
|
+
"default": "./dist/exports/client.js"
|
|
21
|
+
},
|
|
22
|
+
"./rsc": {
|
|
23
|
+
"import": "./dist/exports/rsc.js",
|
|
24
|
+
"types": "./dist/exports/rsc.d.ts",
|
|
25
|
+
"default": "./dist/exports/rsc.js"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"main": "./dist/index.js",
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"files": [
|
|
31
|
+
"dist"
|
|
32
|
+
],
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "pnpm copyfiles && pnpm build:types && pnpm build:swc",
|
|
35
|
+
"build:swc": "swc ./src -d ./dist --config-file .swcrc --strip-leading-paths --ignore \"**/*.test.ts\"",
|
|
36
|
+
"build:types": "tsc --outDir dist --rootDir ./src",
|
|
37
|
+
"clean": "rimraf {dist,*.tsbuildinfo}",
|
|
38
|
+
"copyfiles": "copyfiles -u 1 \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png,json}\" dist/",
|
|
39
|
+
"dev": "next dev dev --turbo",
|
|
40
|
+
"dev:generate-importmap": "pnpm dev:payload generate:importmap",
|
|
41
|
+
"dev:generate-types": "pnpm dev:payload generate:types",
|
|
42
|
+
"dev:payload": "cross-env PAYLOAD_CONFIG_PATH=./dev/payload.config.ts payload",
|
|
43
|
+
"generate:importmap": "pnpm dev:generate-importmap",
|
|
44
|
+
"generate:types": "pnpm dev:generate-types",
|
|
45
|
+
"lint": "eslint",
|
|
46
|
+
"lint:fix": "eslint ./src --fix",
|
|
47
|
+
"prepublishOnly": "pnpm build && node scripts/verify-pack.mjs",
|
|
48
|
+
"verify:pack": "node scripts/verify-pack.mjs",
|
|
49
|
+
"release": "release-it",
|
|
50
|
+
"release:dry": "release-it --dry-run",
|
|
51
|
+
"test": "pnpm test:unit && pnpm test:int && pnpm test:e2e",
|
|
52
|
+
"test:unit": "vitest run src",
|
|
53
|
+
"test:e2e": "playwright test",
|
|
54
|
+
"test:int": "vitest run dev/int.spec.ts"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@eslint/eslintrc": "^3.2.0",
|
|
58
|
+
"@payloadcms/db-mongodb": "3.84.1",
|
|
59
|
+
"@payloadcms/eslint-config": "3.28.0",
|
|
60
|
+
"@payloadcms/next": "3.84.1",
|
|
61
|
+
"@payloadcms/ui": "3.84.1",
|
|
62
|
+
"@playwright/test": "1.58.2",
|
|
63
|
+
"@release-it/conventional-changelog": "^11.0.0",
|
|
64
|
+
"@swc-node/register": "1.10.9",
|
|
65
|
+
"@swc/cli": "0.6.0",
|
|
66
|
+
"@types/node": "22.19.9",
|
|
67
|
+
"@types/react": "19.2.14",
|
|
68
|
+
"@types/react-dom": "19.2.3",
|
|
69
|
+
"copyfiles": "2.4.1",
|
|
70
|
+
"cross-env": "^7.0.3",
|
|
71
|
+
"eslint": "^9.23.0",
|
|
72
|
+
"eslint-config-next": "16.2.6",
|
|
73
|
+
"graphql": "^16.8.1",
|
|
74
|
+
"mongodb-memory-server": "10.1.4",
|
|
75
|
+
"next": "16.2.6",
|
|
76
|
+
"payload": "3.84.1",
|
|
77
|
+
"prettier": "^3.4.2",
|
|
78
|
+
"react": "19.2.6",
|
|
79
|
+
"react-dom": "19.2.6",
|
|
80
|
+
"release-it": "^20.0.1",
|
|
81
|
+
"rimraf": "3.0.2",
|
|
82
|
+
"sharp": "0.34.2",
|
|
83
|
+
"typescript": "5.7.3",
|
|
84
|
+
"vite-tsconfig-paths": "6.0.5",
|
|
85
|
+
"vitest": "4.0.18"
|
|
86
|
+
},
|
|
87
|
+
"peerDependencies": {
|
|
88
|
+
"@payloadcms/next": "^3.84.1",
|
|
89
|
+
"@payloadcms/ui": "^3.84.1",
|
|
90
|
+
"next": ">=15",
|
|
91
|
+
"payload": "^3.84.1",
|
|
92
|
+
"react": "^19"
|
|
93
|
+
},
|
|
94
|
+
"engines": {
|
|
95
|
+
"node": "^18.20.2 || >=20.9.0",
|
|
96
|
+
"pnpm": "^9 || ^10"
|
|
97
|
+
},
|
|
98
|
+
"publishConfig": {
|
|
99
|
+
"access": "public"
|
|
100
|
+
},
|
|
101
|
+
"pnpm": {
|
|
102
|
+
"onlyBuiltDependencies": [
|
|
103
|
+
"sharp",
|
|
104
|
+
"esbuild",
|
|
105
|
+
"unrs-resolver"
|
|
106
|
+
]
|
|
107
|
+
},
|
|
108
|
+
"registry": "https://registry.npmjs.org/"
|
|
109
|
+
}
|