payload-nested-docs-page-tree 1.2.4 → 1.4.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 +356 -222
- package/dist/components/PageTreeContext.d.ts +13 -1
- package/dist/components/PageTreeContext.js +11 -1
- package/dist/components/PageTreeContext.js.map +1 -1
- package/dist/components/PageTreeListView.client.d.ts +4 -5
- package/dist/components/PageTreeListView.client.js +668 -128
- package/dist/components/PageTreeListView.client.js.map +1 -1
- package/dist/components/PageTreeListView.module.css +399 -376
- package/dist/components/PageTreeListView.server.js +18 -28
- package/dist/components/PageTreeListView.server.js.map +1 -1
- package/dist/components/PageTreeTitleCell.js +80 -18
- package/dist/components/PageTreeTitleCell.js.map +1 -1
- package/dist/endpoints/createMovePageEndpoint.d.ts +3 -0
- package/dist/endpoints/createMovePageEndpoint.js +186 -125
- package/dist/endpoints/createMovePageEndpoint.js.map +1 -1
- package/dist/endpoints/createReorderPageEndpoint.d.ts +8 -0
- package/dist/endpoints/createReorderPageEndpoint.js +706 -0
- package/dist/endpoints/createReorderPageEndpoint.js.map +1 -0
- package/dist/endpoints/shared.d.ts +40 -0
- package/dist/endpoints/shared.js +93 -0
- package/dist/endpoints/shared.js.map +1 -0
- package/dist/index.js +110 -27
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +47 -2
- package/dist/types.js +22 -3
- package/dist/types.js.map +1 -1
- package/dist/utilities/diagnostics.d.ts +42 -0
- package/dist/utilities/diagnostics.js +83 -0
- package/dist/utilities/diagnostics.js.map +1 -0
- package/dist/utilities/dropTargets.d.ts +2 -2
- package/dist/utilities/dropTargets.js +9 -7
- package/dist/utilities/dropTargets.js.map +1 -1
- package/dist/utilities/moveValidation.js.map +1 -1
- package/dist/utilities/pageTree.js +4 -6
- package/dist/utilities/pageTree.js.map +1 -1
- package/dist/utilities/pageTreeCollision.d.ts +6 -0
- package/dist/utilities/pageTreeCollision.js +39 -4
- package/dist/utilities/pageTreeCollision.js.map +1 -1
- package/dist/utilities/pageTreeConfig.js.map +1 -1
- package/dist/utilities/status.d.ts +1 -1
- package/dist/utilities/status.js +7 -3
- package/dist/utilities/status.js.map +1 -1
- package/package.json +54 -32
package/README.md
CHANGED
|
@@ -1,222 +1,356 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
Companion admin plugin for [`@payloadcms/plugin-nested-docs`](https://payloadcms.com/docs/plugins/nested-docs).
|
|
4
|
-
|
|
5
|
-
<p align="center">
|
|
6
|
-
<img alt="Page tree
|
|
7
|
-
</p>
|
|
8
|
-
|
|
9
|
-
Adds a nested tree list view for nested docs collections in Payload admin, with
|
|
10
|
-
|
|
11
|
-
It works alongside `@payloadcms/plugin-nested-docs`. It does not replace nested docs persistence, breadcrumbs generation, or routing.
|
|
12
|
-
|
|
13
|
-
Tested with Payload `3.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
## Install
|
|
17
|
-
|
|
18
|
-
```bash
|
|
19
|
-
pnpm add payload-nested-docs-page-tree
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
## Quick Setup
|
|
23
|
-
|
|
24
|
-
`@payloadcms/plugin-nested-docs` should already be installed, and each target collection should already have:
|
|
25
|
-
|
|
26
|
-
- a nested docs parent field
|
|
27
|
-
- a nested docs breadcrumbs field
|
|
28
|
-
- a top-level `admin.useAsTitle` field
|
|
29
|
-
|
|
30
|
-
Add `nestedDocsPageTreePlugin(...)` right after `nestedDocsPlugin(...)`:
|
|
31
|
-
|
|
32
|
-
```ts
|
|
33
|
-
import { nestedDocsPlugin } from '@payloadcms/plugin-nested-docs'
|
|
34
|
-
import { nestedDocsPageTreePlugin } from 'payload-nested-docs-page-tree'
|
|
35
|
-
|
|
36
|
-
export const plugins = [
|
|
37
|
-
nestedDocsPlugin({
|
|
38
|
-
// your existing nested docs config
|
|
39
|
-
}),
|
|
40
|
-
nestedDocsPageTreePlugin({
|
|
41
|
-
collections: ['pages'],
|
|
42
|
-
}),
|
|
43
|
-
]
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
```bash
|
|
49
|
-
payload generate:importmap
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
## What It Adds
|
|
53
|
-
|
|
54
|
-
- replaces the collection list view with a nested tree table
|
|
55
|
-
-
|
|
56
|
-
-
|
|
57
|
-
-
|
|
58
|
-
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
- `
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
```
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
1
|
+
# payload-nested-docs-page-tree
|
|
2
|
+
|
|
3
|
+
Companion admin plugin for [`@payloadcms/plugin-nested-docs`](https://payloadcms.com/docs/plugins/nested-docs).
|
|
4
|
+
|
|
5
|
+
<p align="center">
|
|
6
|
+
<img alt="Page tree admin overview" src="assets/page-tree-admin-overview.png" width="100%" />
|
|
7
|
+
</p>
|
|
8
|
+
|
|
9
|
+
Adds a nested tree list view for nested docs collections in Payload admin, with visual hierarchy shading, live URL path previews, separate reorder and parent-move interactions, and status badges for published / changed / draft documents.
|
|
10
|
+
|
|
11
|
+
It works alongside `@payloadcms/plugin-nested-docs`. It does not replace nested docs persistence, breadcrumbs generation, or routing.
|
|
12
|
+
|
|
13
|
+
Tested with Payload `3.81` and Next.js `16.2`.
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
## Install
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
pnpm add payload-nested-docs-page-tree
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Quick Setup
|
|
23
|
+
|
|
24
|
+
`@payloadcms/plugin-nested-docs` should already be installed, and each target collection should already have:
|
|
25
|
+
|
|
26
|
+
- a nested docs parent field
|
|
27
|
+
- a nested docs breadcrumbs field
|
|
28
|
+
- a top-level `admin.useAsTitle` field
|
|
29
|
+
|
|
30
|
+
Add `nestedDocsPageTreePlugin(...)` right after `nestedDocsPlugin(...)`:
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import { nestedDocsPlugin } from '@payloadcms/plugin-nested-docs'
|
|
34
|
+
import { nestedDocsPageTreePlugin } from 'payload-nested-docs-page-tree'
|
|
35
|
+
|
|
36
|
+
export const plugins = [
|
|
37
|
+
nestedDocsPlugin({
|
|
38
|
+
// your existing nested docs config
|
|
39
|
+
}),
|
|
40
|
+
nestedDocsPageTreePlugin({
|
|
41
|
+
collections: ['pages'],
|
|
42
|
+
}),
|
|
43
|
+
]
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Refresh the admin import map:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
payload generate:importmap
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## What It Adds
|
|
53
|
+
|
|
54
|
+
- replaces the collection list view with a nested tree table
|
|
55
|
+
- adds visual hierarchy shading for nested pages
|
|
56
|
+
- shows the live URL path for each page
|
|
57
|
+
- preserves sorting, filters, pagination, bulk selection, and row actions
|
|
58
|
+
- adds `POST /:id/move` for intentional parent changes
|
|
59
|
+
- adds `POST /:id/reorder` for orderable-only sibling reordering
|
|
60
|
+
- keeps reorder drags scoped to the same parent or root level
|
|
61
|
+
- marks the root page with slug `home` using a home icon on the title link
|
|
62
|
+
- hides the read-only breadcrumbs field by default
|
|
63
|
+
|
|
64
|
+
## Feature Preview
|
|
65
|
+
|
|
66
|
+
### Visual hierarchy shading
|
|
67
|
+
|
|
68
|
+
<p align="center">
|
|
69
|
+
<img alt="Visual hierarchy shading for nested pages" src="assets/visual-hierarchy-shading.png" width="100%" />
|
|
70
|
+
</p>
|
|
71
|
+
|
|
72
|
+
### Homepage icon
|
|
73
|
+
|
|
74
|
+
<p align="center">
|
|
75
|
+
<img alt="Homepage icon in the page tree" src="assets/homepage-icon.png" width="100%" />
|
|
76
|
+
</p>
|
|
77
|
+
|
|
78
|
+
### Live URL path preview
|
|
79
|
+
|
|
80
|
+
<p align="center">
|
|
81
|
+
<img alt="Live URL path preview in the page tree" src="assets/live-url-path-preview.png" width="100%" />
|
|
82
|
+
</p>
|
|
83
|
+
|
|
84
|
+
## Drag-And-Drop Modes
|
|
85
|
+
|
|
86
|
+
Parent moves and orderable reordering are separate interactions.
|
|
87
|
+
|
|
88
|
+
For collections using Payload `orderable`, the reorder handle is shown only when the current sort is the orderable field. Reordering only changes the order key and is limited to documents under the same parent, or documents at the root level. A reorder drag cannot change a document's parent.
|
|
89
|
+
|
|
90
|
+
https://github.com/user-attachments/assets/b25ffa1a-a6bd-45cf-bce8-56ba6cdf7e72
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
Parent moves are hidden by default because they change the page hierarchy. Editors can enable the parent-move handle with the `Edit Hierarchy` button when they intentionally want to move pages between parents. Drag a page onto another page to make it a child of that page. Drag it between root pages to move it back to the root level.
|
|
95
|
+
|
|
96
|
+
Edit hierarchy mode
|
|
97
|
+
|
|
98
|
+
https://github.com/user-attachments/assets/618d5e53-5918-40be-9932-0f516e5e82ba
|
|
99
|
+
|
|
100
|
+
Parent move to child
|
|
101
|
+
|
|
102
|
+
https://github.com/user-attachments/assets/4cb25109-e515-4955-8503-39fddac0020f
|
|
103
|
+
|
|
104
|
+
Parent move back to root
|
|
105
|
+
|
|
106
|
+
https://github.com/user-attachments/assets/470cb5b3-61c8-4b5b-a6e4-5e855f58a0e4
|
|
107
|
+
|
|
108
|
+
Same-parent reorder guard
|
|
109
|
+
|
|
110
|
+
https://github.com/user-attachments/assets/2513ff04-192e-4fdf-808f-6004f55d871c
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
Internally, parent moves call this plugin's `/:id/move` endpoint. That endpoint updates the nested docs parent field through Payload's local API, while `@payloadcms/plugin-nested-docs` continues to own parent and breadcrumb behavior through its normal fields and hooks.
|
|
116
|
+
|
|
117
|
+
### Publishing moves
|
|
118
|
+
|
|
119
|
+
On a drafts-enabled collection a move is written through the drafts system, so by default it is staged as a **draft**: the tree updates immediately and the page shows a `changed` badge, but the live URL/path changes only when the page is next published. This is the safe default — publishing a move for a page that also has other pending edits would publish those edits too.
|
|
120
|
+
|
|
121
|
+
Set `publishOnMove: true` to publish a move as soon as it happens — but only when it is safe to:
|
|
122
|
+
|
|
123
|
+
```ts
|
|
124
|
+
nestedDocsPageTreePlugin({
|
|
125
|
+
collections: ['pages'],
|
|
126
|
+
publishOnMove: true,
|
|
127
|
+
})
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
With `publishOnMove` enabled, a move is published immediately **only if the moved page had no unpublished changes beforehand** (its latest version was already published). If the page has pending draft edits (a `changed` or draft-only page), the move stays staged exactly as before, so in-progress edits are never published as a side effect of a move. Collections without drafts always move live and are unaffected by this option.
|
|
131
|
+
|
|
132
|
+
Publishing a move also republishes the moved page's descendants, so their live URLs follow the new parent. Since the live site really did change, a published move **does** trigger your deploy hook, once for the whole subtree - see [Deploy Hooks](#the-fix). Reorders and staged moves still do not. You do not need to change your hook when enabling this option.
|
|
133
|
+
|
|
134
|
+
On a localized collection the parent field is shared across locales but breadcrumbs are not: publishing a move recomputes breadcrumbs only for the locale the move was made in, so other locales keep their previous URL until they are next published. If that matters for your setup, leave `publishOnMove` off.
|
|
135
|
+
|
|
136
|
+
## Home Indicator
|
|
137
|
+
|
|
138
|
+
By default, the home icon is enabled only for the `pages` collection.
|
|
139
|
+
|
|
140
|
+
```ts
|
|
141
|
+
nestedDocsPageTreePlugin({
|
|
142
|
+
collections: ['pages'],
|
|
143
|
+
})
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
For custom page collection slugs, pass an exact allow-list:
|
|
147
|
+
|
|
148
|
+
```ts
|
|
149
|
+
nestedDocsPageTreePlugin({
|
|
150
|
+
collections: ['page-tree', 'categories'],
|
|
151
|
+
homeIndicator: {
|
|
152
|
+
collections: ['page-tree'],
|
|
153
|
+
},
|
|
154
|
+
})
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
To disable the home icon everywhere:
|
|
158
|
+
|
|
159
|
+
```ts
|
|
160
|
+
nestedDocsPageTreePlugin({
|
|
161
|
+
collections: ['pages'],
|
|
162
|
+
homeIndicator: false,
|
|
163
|
+
})
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## Status Badges
|
|
167
|
+
|
|
168
|
+
The tree view supports three document states:
|
|
169
|
+
|
|
170
|
+
- `published`: live and up to date
|
|
171
|
+
- `changed`: live, but has unpublished changes
|
|
172
|
+
- `draft`: not published
|
|
173
|
+
|
|
174
|
+
Badge colors use Payload theme colors by default. To override badge labels or status colors, pass a `badges` object. Custom colors are treated as one base color per status and are adapted for both light and dark Payload themes:
|
|
175
|
+
|
|
176
|
+
<p align="center">
|
|
177
|
+
<img alt="Custom status badges in the page tree" src="assets/custom-status-badges.png" width="100%" />
|
|
178
|
+
</p>
|
|
179
|
+
|
|
180
|
+
```ts
|
|
181
|
+
nestedDocsPageTreePlugin({
|
|
182
|
+
collections: ['pages'],
|
|
183
|
+
badges: {
|
|
184
|
+
colors: {
|
|
185
|
+
// Example: use a custom green / blue / orange palette.
|
|
186
|
+
published: '#bbf3b0',
|
|
187
|
+
changed: '#b9eaf3',
|
|
188
|
+
draft: '#f8d5a7',
|
|
189
|
+
},
|
|
190
|
+
labels: {
|
|
191
|
+
// Example: use custom labels for states.
|
|
192
|
+
published: 'Live',
|
|
193
|
+
changed: 'Has Changes',
|
|
194
|
+
draft: 'Draft Only',
|
|
195
|
+
},
|
|
196
|
+
},
|
|
197
|
+
}),
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
`labels` and `colors` are optional partial overrides. Missing entries fall back to the built-in Payload-themed defaults for published, changed, and draft states.
|
|
201
|
+
|
|
202
|
+
## Configuration
|
|
203
|
+
|
|
204
|
+
- `collections`: target collection slugs
|
|
205
|
+
- `parentFieldSlug`: defaults to `'parent'`
|
|
206
|
+
- `breadcrumbsFieldSlug`: defaults to `'breadcrumbs'`
|
|
207
|
+
- `defaultLimit`: defaults to `100`
|
|
208
|
+
- `hideBreadcrumbs`: defaults to `true`
|
|
209
|
+
- `disabled`: defaults to `false`
|
|
210
|
+
- `homeIndicator`: defaults to `{ collections: ['pages'] }`; set to `false` to disable
|
|
211
|
+
- `publishOnMove`: defaults to `false`. When `true`, a move is published immediately if the moved page had no unpublished changes; pages with pending edits stay staged. See [Publishing moves](#publishing-moves).
|
|
212
|
+
- `badges`: optional label and color overrides for `published`, `changed`, and `draft`
|
|
213
|
+
- `diagnostics`: defaults to `false`. Enables structured diagnostic logging for tree-related publish/draft regressions; see below.
|
|
214
|
+
|
|
215
|
+
## Diagnostics Mode
|
|
216
|
+
|
|
217
|
+
If a page-tree move or reorder is doing something unexpected, enable diagnostics and reproduce. Each page-tree-triggered write emits one or more structured events on the dev server stdout:
|
|
218
|
+
|
|
219
|
+
<p align="center">
|
|
220
|
+
<img alt="Diagnostics mode structured logs" src="assets/diagnostics-mode-logs.png" width="100%" />
|
|
221
|
+
</p>
|
|
222
|
+
|
|
223
|
+
```ts
|
|
224
|
+
nestedDocsPageTreePlugin({
|
|
225
|
+
collections: ['pages'],
|
|
226
|
+
diagnostics: true,
|
|
227
|
+
})
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
Or with a custom sink:
|
|
231
|
+
|
|
232
|
+
```ts
|
|
233
|
+
nestedDocsPageTreePlugin({
|
|
234
|
+
collections: ['pages'],
|
|
235
|
+
diagnostics: {
|
|
236
|
+
enabled: true,
|
|
237
|
+
logger: (event) => req.payload.logger.info({ pageTree: event }),
|
|
238
|
+
},
|
|
239
|
+
})
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
Each event is one line tagged `[payload-nested-docs-page-tree]` followed by the event source (`move-endpoint:enter`, `move-endpoint:ok`, `move-endpoint:error`, `reorder-endpoint:enter`, `reorder-endpoint:ok`, `reorder-endpoint:error`, `page-tree-change:after`, `page-tree-change:status-flip`) and a JSON payload that includes:
|
|
243
|
+
|
|
244
|
+
- `flow`: id shared by every event for one logical operation
|
|
245
|
+
- `publishedMainRowBefore` / `publishedMainRowAfter`: fresh reads of the public/published row (`draft: false`)
|
|
246
|
+
- `before` / `after` / `changed`: projected diffs for `_status`, the parent field, and the orderable field when present
|
|
247
|
+
|
|
248
|
+
If the published main row goes from `published` to anything else as a result of a page-tree change, the plugin additionally emits a `page-tree-change:status-flip` WARN line.
|
|
249
|
+
|
|
250
|
+
Diagnostics is opt-in and adds extra reads per operation. Leave it off in production unless you are actively investigating.
|
|
251
|
+
|
|
252
|
+
## Drag-And-Drop Is Triggering A Deploy?
|
|
253
|
+
|
|
254
|
+
A drag-and-drop parent move calls `payload.update()` on the draft only. The published version of the live site is never touched. So in most setups, dragging a page does not trigger any rebuild and you can skip this section.
|
|
255
|
+
|
|
256
|
+
### When you can skip this section
|
|
257
|
+
|
|
258
|
+
- The default Payload website template on Vercel (or any host using Next.js ISR), with drafts and autosave on. The template's `afterChange` hook only calls `revalidatePath` and `revalidateTag` from `next/cache`. Those just clear the edge cache. They do not trigger a Vercel build, do not consume build minutes, and do not change what visitors see when the published HTML has not changed.
|
|
259
|
+
- Any setup where your `afterChange` hooks only do in-process cache work (`revalidatePath`, `revalidateTag`, in-memory caches, etc.).
|
|
260
|
+
|
|
261
|
+
### When you need the one-line fix
|
|
262
|
+
|
|
263
|
+
You need the fix if **you** wrote an `afterChange` hook that calls something external or expensive on every save. Common cases:
|
|
264
|
+
|
|
265
|
+
- **Cloudflare Pages / Netlify / Vercel Deploy Hooks** (`fetch(DEPLOY_HOOK_URL)`) - these trigger full rebuilds and burn build minutes.
|
|
266
|
+
- **GitHub Actions** `repository_dispatch` triggers.
|
|
267
|
+
- **Manually-invoked SSG rebuilds**.
|
|
268
|
+
- **Publish notifications** (email, Slack) on status transitions.
|
|
269
|
+
- **Heavy search reindex jobs** (Algolia, Meilisearch full-document push).
|
|
270
|
+
|
|
271
|
+
Why a tree move trips these: a typical deploy hook fires when `previousDoc?._status === 'published'` so that it catches unpublish events too. A tree move on a published doc can match that condition, but the live site has not actually changed. Without the fix, every drag can fire your deploy.
|
|
272
|
+
|
|
273
|
+
### The fix
|
|
274
|
+
|
|
275
|
+
Add one line at the top of your hook. The plugin sets a flag on Payload's [hook context](https://payloadcms.com/docs/hooks/context) for every page-tree write that leaves the live site unchanged, and your hook reads it to bail out early:
|
|
276
|
+
|
|
277
|
+
```ts
|
|
278
|
+
import { pageTreeMoveContextKey } from 'payload-nested-docs-page-tree'
|
|
279
|
+
|
|
280
|
+
// at the top of your afterChange hook:
|
|
281
|
+
if (req.context?.[pageTreeMoveContextKey]) return
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
The rule is simply **rebuild when the live site changed**, so this one line stays correct in every configuration:
|
|
285
|
+
|
|
286
|
+
| What the editor did in the tree | Live site changed? | Your deploy hook |
|
|
287
|
+
| --- | --- | --- |
|
|
288
|
+
| Reordered siblings | no - only the order key was written | does not fire |
|
|
289
|
+
| Moved a page, default settings | no - the move is staged as a draft | does not fire |
|
|
290
|
+
| Moved a page with [`publishOnMove`](#publishing-moves) on | yes - the page and its descendants have new URLs | fires once |
|
|
291
|
+
|
|
292
|
+
Only the last row publishes anything, which is why it is the only row that rebuilds. It fires once for the whole subtree, not once per descendant. Enabling `publishOnMove` needs no change to your hook - the same line already does the right thing.
|
|
293
|
+
|
|
294
|
+
To rebuild after **every** page-tree drag, including reorders, just leave the guard out. That also rebuilds on staged moves, which change nothing live.
|
|
295
|
+
|
|
296
|
+
This goes in **your** hook - the one that calls the deploy webhook. Not in any of the template's stock files.
|
|
297
|
+
|
|
298
|
+
Full example:
|
|
299
|
+
|
|
300
|
+
```ts
|
|
301
|
+
import type { CollectionAfterChangeHook } from 'payload'
|
|
302
|
+
|
|
303
|
+
import { pageTreeMoveContextKey } from 'payload-nested-docs-page-tree'
|
|
304
|
+
|
|
305
|
+
export const triggerDeployOnPublishedChange: CollectionAfterChangeHook = async ({
|
|
306
|
+
doc,
|
|
307
|
+
previousDoc,
|
|
308
|
+
req,
|
|
309
|
+
}) => {
|
|
310
|
+
// -- plugin opt-out --
|
|
311
|
+
if (req.context?.[pageTreeMoveContextKey]) return
|
|
312
|
+
|
|
313
|
+
// -- your deploy logic (example) --
|
|
314
|
+
// Fire on publish, republish, or unpublish - every transition the live site cares about.
|
|
315
|
+
if (doc._status === 'published' || previousDoc?._status === 'published') {
|
|
316
|
+
// POST to your Cloudflare / Netlify / Vercel deploy hook here
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
See `dev/lib/rebuild.ts` for the full Cloudflare deploy hook example used by the dev playground.
|
|
322
|
+
|
|
323
|
+
## Development
|
|
324
|
+
|
|
325
|
+
For local plugin development, use the internal `dev/` app:
|
|
326
|
+
|
|
327
|
+
```bash
|
|
328
|
+
pnpm install
|
|
329
|
+
pnpm dev
|
|
330
|
+
pnpm generate:types
|
|
331
|
+
pnpm generate:importmap
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
Plugin source is in `src/`. The internal test app is in `dev/`.
|
|
335
|
+
|
|
336
|
+
For checks:
|
|
337
|
+
|
|
338
|
+
```bash
|
|
339
|
+
pnpm test:int
|
|
340
|
+
pnpm exec tsc --noEmit
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
## Test in Another Project
|
|
344
|
+
|
|
345
|
+
For release validation, test the packed artifact instead of a live source-folder dependency:
|
|
346
|
+
|
|
347
|
+
```bash
|
|
348
|
+
pnpm build
|
|
349
|
+
pnpm pack
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
Then in the external consumer app:
|
|
353
|
+
|
|
354
|
+
```bash
|
|
355
|
+
pnpm add /path/payload-nested-docs-page-tree-*.tgz
|
|
356
|
+
```
|
|
@@ -1,15 +1,27 @@
|
|
|
1
|
+
import type { DraggableAttributes, DraggableSyntheticListeners } from '@dnd-kit/core';
|
|
1
2
|
import React from 'react';
|
|
2
3
|
type PageTreeContextValue = {
|
|
3
4
|
activeDragRowID: null | string;
|
|
4
5
|
canMoveDocs: boolean;
|
|
5
6
|
collapsedIDs: ReadonlySet<string>;
|
|
6
|
-
|
|
7
|
+
parentMoveEnabled: boolean;
|
|
7
8
|
pendingMoveRowID: null | string;
|
|
8
9
|
toggleRow: (rowID: string) => void;
|
|
9
10
|
};
|
|
11
|
+
type PageTreeRowDndContextValue = {
|
|
12
|
+
isOrderDragging: boolean;
|
|
13
|
+
orderHandleAttributes: DraggableAttributes;
|
|
14
|
+
orderHandleListeners: DraggableSyntheticListeners;
|
|
15
|
+
orderHandleRef: (element: HTMLElement | null) => void;
|
|
16
|
+
};
|
|
10
17
|
export declare function PageTreeProvider({ children, value, }: {
|
|
11
18
|
children: React.ReactNode;
|
|
12
19
|
value: PageTreeContextValue;
|
|
13
20
|
}): import("react/jsx-runtime").JSX.Element;
|
|
21
|
+
export declare function PageTreeRowDndProvider({ children, value, }: {
|
|
22
|
+
children: React.ReactNode;
|
|
23
|
+
value: PageTreeRowDndContextValue;
|
|
24
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
14
25
|
export declare function usePageTree(): PageTreeContextValue;
|
|
26
|
+
export declare function usePageTreeRowDnd(): null | PageTreeRowDndContextValue;
|
|
15
27
|
export {};
|
|
@@ -2,12 +2,19 @@
|
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import React from 'react';
|
|
4
4
|
const PageTreeContext = /*#__PURE__*/ React.createContext(null);
|
|
5
|
+
const PageTreeRowDndContext = /*#__PURE__*/ React.createContext(null);
|
|
5
6
|
export function PageTreeProvider({ children, value }) {
|
|
6
7
|
return /*#__PURE__*/ _jsx(PageTreeContext.Provider, {
|
|
7
8
|
value: value,
|
|
8
9
|
children: children
|
|
9
10
|
});
|
|
10
11
|
}
|
|
12
|
+
export function PageTreeRowDndProvider({ children, value }) {
|
|
13
|
+
return /*#__PURE__*/ _jsx(PageTreeRowDndContext.Provider, {
|
|
14
|
+
value: value,
|
|
15
|
+
children: children
|
|
16
|
+
});
|
|
17
|
+
}
|
|
11
18
|
export function usePageTree() {
|
|
12
19
|
const context = React.useContext(PageTreeContext);
|
|
13
20
|
if (!context) {
|
|
@@ -15,12 +22,15 @@ export function usePageTree() {
|
|
|
15
22
|
activeDragRowID: null,
|
|
16
23
|
canMoveDocs: false,
|
|
17
24
|
collapsedIDs: new Set(),
|
|
18
|
-
|
|
25
|
+
parentMoveEnabled: false,
|
|
19
26
|
pendingMoveRowID: null,
|
|
20
27
|
toggleRow: ()=>{}
|
|
21
28
|
};
|
|
22
29
|
}
|
|
23
30
|
return context;
|
|
24
31
|
}
|
|
32
|
+
export function usePageTreeRowDnd() {
|
|
33
|
+
return React.useContext(PageTreeRowDndContext);
|
|
34
|
+
}
|
|
25
35
|
|
|
26
36
|
//# sourceMappingURL=PageTreeContext.js.map
|