payload-flat-pages 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/LICENSE +21 -0
- package/README.md +312 -2
- package/dist/admin/ContentPreview.d.ts +9 -0
- package/dist/admin/ContentPreview.js +22 -0
- package/dist/admin/ContentPreview.js.map +1 -0
- package/dist/admin/DiffView.d.ts +8 -0
- package/dist/admin/DiffView.js +99 -0
- package/dist/admin/DiffView.js.map +1 -0
- package/dist/admin/DraftsView.d.ts +20 -0
- package/dist/admin/DraftsView.js +252 -0
- package/dist/admin/DraftsView.js.map +1 -0
- package/dist/admin/EditView.d.ts +2 -0
- package/dist/admin/EditView.js +43 -0
- package/dist/admin/EditView.js.map +1 -0
- package/dist/admin/ListView.d.ts +2 -0
- package/dist/admin/ListView.js +94 -0
- package/dist/admin/ListView.js.map +1 -0
- package/dist/admin/NavLinks.d.ts +7 -0
- package/dist/admin/NavLinks.js +19 -0
- package/dist/admin/NavLinks.js.map +1 -0
- package/dist/admin/PageEditor.d.ts +14 -0
- package/dist/admin/PageEditor.js +629 -0
- package/dist/admin/PageEditor.js.map +1 -0
- package/dist/admin/PreviewPane.d.ts +7 -0
- package/dist/admin/PreviewPane.js +156 -0
- package/dist/admin/PreviewPane.js.map +1 -0
- package/dist/admin/VersionsView.d.ts +18 -0
- package/dist/admin/VersionsView.js +224 -0
- package/dist/admin/VersionsView.js.map +1 -0
- package/dist/admin/api.d.ts +16 -0
- package/dist/admin/api.js +29 -0
- package/dist/admin/api.js.map +1 -0
- package/dist/admin/editor.css +477 -0
- package/dist/admin/fields.d.ts +23 -0
- package/dist/admin/fields.js +344 -0
- package/dist/admin/fields.js.map +1 -0
- package/dist/admin/frameSize.d.ts +17 -0
- package/dist/admin/frameSize.js +30 -0
- package/dist/admin/frameSize.js.map +1 -0
- package/dist/admin/image.d.ts +23 -0
- package/dist/admin/image.js +53 -0
- package/dist/admin/image.js.map +1 -0
- package/dist/admin/mediaURL.d.ts +9 -0
- package/dist/admin/mediaURL.js +34 -0
- package/dist/admin/mediaURL.js.map +1 -0
- package/dist/admin/previewBridge.d.ts +20 -0
- package/dist/admin/previewBridge.js +58 -0
- package/dist/admin/previewBridge.js.map +1 -0
- package/dist/admin/shell.d.ts +8 -0
- package/dist/admin/shell.js +30 -0
- package/dist/admin/shell.js.map +1 -0
- package/dist/content/diff.d.ts +42 -0
- package/dist/content/diff.js +183 -0
- package/dist/content/diff.js.map +1 -0
- package/dist/content/labels.d.ts +2 -0
- package/dist/content/labels.js +3 -0
- package/dist/content/labels.js.map +1 -0
- package/dist/content/normalize.d.ts +7 -0
- package/dist/content/normalize.js +86 -0
- package/dist/content/normalize.js.map +1 -0
- package/dist/content/seo.d.ts +4 -0
- package/dist/content/seo.js +51 -0
- package/dist/content/seo.js.map +1 -0
- package/dist/content/summary.d.ts +2 -0
- package/dist/content/summary.js +24 -0
- package/dist/content/summary.js.map +1 -0
- package/dist/content/validate.d.ts +5 -0
- package/dist/content/validate.js +114 -0
- package/dist/content/validate.js.map +1 -0
- package/dist/endpoints/pages.d.ts +3 -0
- package/dist/endpoints/pages.js +255 -0
- package/dist/endpoints/pages.js.map +1 -0
- 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 +2 -0
- package/dist/exports/rsc.js +4 -0
- package/dist/exports/rsc.js.map +1 -0
- package/dist/exports/site-client.d.ts +1 -0
- package/dist/exports/site-client.js +4 -0
- package/dist/exports/site-client.js.map +1 -0
- package/dist/exports/site.d.ts +1 -0
- package/dist/exports/site.js +3 -0
- package/dist/exports/site.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +65 -0
- package/dist/index.js.map +1 -0
- package/dist/options.d.ts +34 -0
- package/dist/options.js +52 -0
- package/dist/options.js.map +1 -0
- package/dist/site/index.d.ts +10 -0
- package/dist/site/index.js +27 -0
- package/dist/site/index.js.map +1 -0
- package/dist/site/useLivePage.d.ts +13 -0
- package/dist/site/useLivePage.js +59 -0
- package/dist/site/useLivePage.js.map +1 -0
- package/dist/storage/encoding.d.ts +4 -0
- package/dist/storage/encoding.js +12 -0
- package/dist/storage/encoding.js.map +1 -0
- package/dist/storage/fs.d.ts +6 -0
- package/dist/storage/fs.js +92 -0
- package/dist/storage/fs.js.map +1 -0
- package/dist/storage/paths.d.ts +2 -0
- package/dist/storage/paths.js +12 -0
- package/dist/storage/paths.js.map +1 -0
- package/dist/storage/types.d.ts +36 -0
- package/dist/storage/types.js +18 -0
- package/dist/storage/types.js.map +1 -0
- package/dist/types.d.ts +103 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/versions/collections.d.ts +5 -0
- package/dist/versions/collections.js +76 -0
- package/dist/versions/collections.js.map +1 -0
- package/dist/versions/repo.d.ts +14 -0
- package/dist/versions/repo.js +180 -0
- package/dist/versions/repo.js.map +1 -0
- package/dist/versions/rules.d.ts +21 -0
- package/dist/versions/rules.js +37 -0
- package/dist/versions/rules.js.map +1 -0
- package/dist/versions/service.d.ts +88 -0
- package/dist/versions/service.js +270 -0
- package/dist/versions/service.js.map +1 -0
- package/package.json +108 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 David S. Figueroa
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,313 @@
|
|
|
1
|
-
#
|
|
1
|
+
# payload-flat-pages
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A Payload CMS 3 plugin for pages that developers lay out and editors fill in. You define the
|
|
4
|
+
sections and pages in code. Editors get a form for each page under **Site pages** in the admin,
|
|
5
|
+
with a live preview of the site next to it. Published pages are saved as JSON files in your repo,
|
|
6
|
+
so your site reads plain files and never queries the database to render them.
|
|
7
|
+
|
|
8
|
+
Drafts and the version history live in your Payload database. Editors save drafts as often as they
|
|
9
|
+
like, compare any version with the live page, restore an old version, and publish when the page is
|
|
10
|
+
ready.
|
|
11
|
+
|
|
12
|
+
## How it works
|
|
13
|
+
|
|
14
|
+
```
|
|
15
|
+
Editor runs the admin locally ──Publish──▶ content/pages/home.json on that machine
|
|
16
|
+
│
|
|
17
|
+
git commit + deploy (like any code change)
|
|
18
|
+
▼
|
|
19
|
+
Live site reads home.json
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Everyone who edits pages runs the site on their own machine, with their own local database. Save
|
|
23
|
+
draft writes only to that database. Publish writes `content/pages/<slug>.json` and any new images
|
|
24
|
+
to `public/content-media/`. You then commit those files and deploy them the same way you ship
|
|
25
|
+
code, and git keeps the history of what went live.
|
|
26
|
+
|
|
27
|
+
Because each person has their own database, drafts are private to the machine they were saved on,
|
|
28
|
+
much like uncommitted edits. A teammate sees your changes once you publish, commit and push them.
|
|
29
|
+
If a `git pull` changes a page you have a draft of, the editor tells you the live page changed and
|
|
30
|
+
lets you compare and rebase your draft before you publish.
|
|
31
|
+
|
|
32
|
+
Publishing from a deployed admin is not supported. Most hosts (Vercel, Cloudflare Workers, other
|
|
33
|
+
serverless platforms) can't write files, and a file written on a server would be overwritten by the
|
|
34
|
+
next deploy anyway. If someone clicks Publish there, they see: "This server can't write content
|
|
35
|
+
files. Publish from a local copy of the site and commit the files." Saving drafts still works.
|
|
36
|
+
|
|
37
|
+
## Install
|
|
38
|
+
|
|
39
|
+
```sh
|
|
40
|
+
pnpm add payload-flat-pages
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
// payload.config.ts
|
|
45
|
+
import { flatPages } from 'payload-flat-pages'
|
|
46
|
+
|
|
47
|
+
import { home, sections } from './flatPages'
|
|
48
|
+
|
|
49
|
+
export default buildConfig({
|
|
50
|
+
plugins: [
|
|
51
|
+
flatPages({
|
|
52
|
+
sections: [...sections],
|
|
53
|
+
pages: [home],
|
|
54
|
+
livePreviewURL: ({ slug }) => (slug === 'home' ? '/' : `/${slug}`),
|
|
55
|
+
}),
|
|
56
|
+
],
|
|
57
|
+
})
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
The plugin adds the **Site pages** group to the admin sidebar, a list view at
|
|
61
|
+
`/admin/site-pages` and an editor at `/admin/site-pages/:slug`. It also adds two hidden
|
|
62
|
+
collections, `flat-pages-versions` and `flat-pages-media`. If you use a SQL adapter (Postgres,
|
|
63
|
+
SQLite, D1), create and run a migration after installing or upgrading:
|
|
64
|
+
|
|
65
|
+
```sh
|
|
66
|
+
pnpm payload migrate:create
|
|
67
|
+
pnpm payload migrate
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Defining sections and pages
|
|
71
|
+
|
|
72
|
+
A section is a type: a named set of fields. A page is a list of section instances, each with an
|
|
73
|
+
`id` and the `type` (the section's `slug`) it uses. The same section type can appear on a page
|
|
74
|
+
more than once under different ids.
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
// flatPages.ts
|
|
78
|
+
import type { PageDefinition, SectionData, SectionDefinition } from 'payload-flat-pages'
|
|
79
|
+
|
|
80
|
+
export const hero = {
|
|
81
|
+
slug: 'hero',
|
|
82
|
+
label: 'Hero',
|
|
83
|
+
summaryField: 'heading',
|
|
84
|
+
fields: [
|
|
85
|
+
{ name: 'heading', type: 'text', required: true, maxLength: 80 },
|
|
86
|
+
{ name: 'text', type: 'richText' },
|
|
87
|
+
{ name: 'image', type: 'image' },
|
|
88
|
+
{ name: 'cta', type: 'link' },
|
|
89
|
+
],
|
|
90
|
+
} as const satisfies SectionDefinition
|
|
91
|
+
|
|
92
|
+
export type HeroData = SectionData<typeof hero>
|
|
93
|
+
|
|
94
|
+
export const sections = [hero] as const satisfies readonly SectionDefinition[]
|
|
95
|
+
|
|
96
|
+
export const home = {
|
|
97
|
+
slug: 'home',
|
|
98
|
+
label: 'Home',
|
|
99
|
+
sections: [{ id: 'hero', type: 'hero' }],
|
|
100
|
+
} as const satisfies PageDefinition
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Write definitions with `as const satisfies SectionDefinition` so that `SectionData<typeof hero>`
|
|
104
|
+
gives your components the exact field types.
|
|
105
|
+
|
|
106
|
+
Section ids must match `/^[a-z0-9-]+$/` because they become part of image filenames. The plugin
|
|
107
|
+
checks this at startup and throws if one doesn't.
|
|
108
|
+
|
|
109
|
+
`summaryField` names a top-level field whose value is shown when the section is collapsed in the
|
|
110
|
+
editor. Without it, the editor uses the first non-empty text field, or the item count of the first
|
|
111
|
+
array.
|
|
112
|
+
|
|
113
|
+
### Field types
|
|
114
|
+
|
|
115
|
+
| `type` | Stored as | Notes |
|
|
116
|
+
| ---------- | -------------------------------- | ------------------------------------------------------------------ |
|
|
117
|
+
| `text` | `string` | Single line. Supports `maxLength`. |
|
|
118
|
+
| `textarea` | `string` | Multi-line. Supports `maxLength`. |
|
|
119
|
+
| `richText` | `string` | Markdown, not Lexical JSON. Supports `maxLength`. |
|
|
120
|
+
| `image` | `string \| null` | Public path of a WebP file. See [Images](#images). |
|
|
121
|
+
| `link` | `{ label: string; url: string }` | URL must be `/path`, `#anchor`, `http(s)://`, `mailto:` or `tel:`. |
|
|
122
|
+
| `checkbox` | `boolean` | |
|
|
123
|
+
| `select` | `string` | Needs `options: { label, value }[]`. |
|
|
124
|
+
| `group` | nested object | Needs `fields`. |
|
|
125
|
+
| `array` | list of nested objects | Needs `fields`. Supports `minRows` and `maxRows`. |
|
|
126
|
+
|
|
127
|
+
Every field takes a `name` and an optional `label`, and most take `required`. `text`, `textarea`,
|
|
128
|
+
`richText` and `image` also accept `admin.description` for help text under the field.
|
|
129
|
+
|
|
130
|
+
Every page also has an SEO tab with a title, description, share image and its alt text, a
|
|
131
|
+
canonical URL, and a "Hide this page from search engines" checkbox.
|
|
132
|
+
|
|
133
|
+
## Rendering pages on your site
|
|
134
|
+
|
|
135
|
+
```ts
|
|
136
|
+
import { getPage, sectionAttrs, seoMetadata } from 'payload-flat-pages/site'
|
|
137
|
+
import { useLivePage } from 'payload-flat-pages/site-client'
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
`getPage(page, sections, raw)` takes the parsed JSON file and returns `{ sections, seo }` with
|
|
141
|
+
every defined section filled in, using empty defaults for anything missing. Import the JSON file
|
|
142
|
+
statically so it is bundled with the page.
|
|
143
|
+
|
|
144
|
+
`seoMetadata(content.seo)` returns Next.js `Metadata` for the page. Empty fields are left out, so
|
|
145
|
+
your layout's defaults still apply. Set `metadataBase` in your root layout so relative image and
|
|
146
|
+
canonical URLs become absolute.
|
|
147
|
+
|
|
148
|
+
`sectionAttrs(id)` returns `{ 'data-section': id }`. Spread it on each section's root element and
|
|
149
|
+
clicking that section in the preview opens its fields in the editor.
|
|
150
|
+
|
|
151
|
+
`useLivePage(initial, { allowedOrigins })` is a client hook. On the live site it returns
|
|
152
|
+
`initial`. When the page is shown inside the editor's preview, it returns the editor's unsaved
|
|
153
|
+
content instead, so the preview updates as the editor types.
|
|
154
|
+
|
|
155
|
+
```tsx
|
|
156
|
+
// app/page.tsx
|
|
157
|
+
import { getPage, seoMetadata } from 'payload-flat-pages/site'
|
|
158
|
+
|
|
159
|
+
import homeJson from '../content/pages/home.json'
|
|
160
|
+
import { home, sections } from '../flatPages'
|
|
161
|
+
import { HomeSections } from './HomeSections'
|
|
162
|
+
|
|
163
|
+
const content = getPage(home, sections, homeJson)
|
|
164
|
+
|
|
165
|
+
export const metadata = seoMetadata(content.seo)
|
|
166
|
+
|
|
167
|
+
export default function Home() {
|
|
168
|
+
return <HomeSections initial={content} />
|
|
169
|
+
}
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
```tsx
|
|
173
|
+
// app/HomeSections.tsx
|
|
174
|
+
'use client'
|
|
175
|
+
|
|
176
|
+
import type { PageContent } from 'payload-flat-pages'
|
|
177
|
+
import { sectionAttrs } from 'payload-flat-pages/site'
|
|
178
|
+
import { useLivePage } from 'payload-flat-pages/site-client'
|
|
179
|
+
|
|
180
|
+
import type { HeroData } from '../flatPages'
|
|
181
|
+
|
|
182
|
+
export function HomeSections({ initial }: { initial: PageContent }) {
|
|
183
|
+
const { sections } = useLivePage(initial)
|
|
184
|
+
const hero = sections.hero as HeroData
|
|
185
|
+
return (
|
|
186
|
+
<section {...sectionAttrs('hero')}>
|
|
187
|
+
<h1>{hero.heading}</h1>
|
|
188
|
+
</section>
|
|
189
|
+
)
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
By default the hook only listens to an editor on the site's own origin. If your admin runs on a
|
|
194
|
+
different origin, list it in `allowedOrigins`. Messages from any other framing page are ignored.
|
|
195
|
+
The option is read once, on mount.
|
|
196
|
+
|
|
197
|
+
You should also limit who can put your site in a frame. Send
|
|
198
|
+
`Content-Security-Policy: frame-ancestors <admin origin>`, and `X-Frame-Options: SAMEORIGIN` if
|
|
199
|
+
the admin is on the same origin. When it is, `livePreviewURL` can be a relative path.
|
|
200
|
+
|
|
201
|
+
## Options
|
|
202
|
+
|
|
203
|
+
| Option | Type | Default | Description |
|
|
204
|
+
| -------------------- | ---------------------------- | -------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
205
|
+
| `sections` | `SectionDefinition[]` | required | The section types and their fields. |
|
|
206
|
+
| `pages` | `PageDefinition[]` | required | The editable pages and the sections on each. |
|
|
207
|
+
| `livePreviewURL` | `({ slug }) => string` | unset (no preview) | URL of the page to show in the preview frame. May be relative. |
|
|
208
|
+
| `previewBreakpoints` | `{ label, width, height }[]` | Desktop, Tablet, Mobile | Screen sizes offered above the preview besides Fit. Pass `[]` for Fit only. |
|
|
209
|
+
| `contentDir` | `string` | `content/pages` | Folder for the page JSON files, relative to `rootDir`. |
|
|
210
|
+
| `mediaDir` | `string` | `public/content-media` | Folder that published images are written to, relative to `rootDir`. |
|
|
211
|
+
| `mediaPublicPath` | `string` | `/content-media` | URL prefix images are served from. Image values in the JSON are stored as `<mediaPublicPath>/<file>`. |
|
|
212
|
+
| `rootDir` | `string` | the directory the app started in | Base for `contentDir` and `mediaDir`. Set it if the app is started from another folder, for example `next dev apps/site` from a monorepo root. |
|
|
213
|
+
| `adminGroupLabel` | `string` | `Site pages` | Label of the sidebar group. |
|
|
214
|
+
| `disabled` | `boolean` | `false` | Return the config unchanged. |
|
|
215
|
+
|
|
216
|
+
`rootDir` should be the folder that holds your `content/` and `public/` folders. To make it
|
|
217
|
+
independent of where the app is started, resolve it from the config file:
|
|
218
|
+
|
|
219
|
+
```ts
|
|
220
|
+
// apps/site/src/payload.config.ts
|
|
221
|
+
import path from 'node:path'
|
|
222
|
+
import { fileURLToPath } from 'node:url'
|
|
223
|
+
|
|
224
|
+
const dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
225
|
+
|
|
226
|
+
flatPages({ sections, pages, rootDir: path.resolve(dirname, '..') })
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
## Editing and publishing
|
|
230
|
+
|
|
231
|
+
Save draft stores the page in the database and nothing goes live. Each page has one draft at a
|
|
232
|
+
time. Publish writes the draft to the page's JSON file. When any page has a draft, the page list
|
|
233
|
+
shows a Drafts tab where you can publish or discard several pages at once.
|
|
234
|
+
|
|
235
|
+
Every save and every publish is kept as a version, up to the newest 50 per page plus the newest
|
|
236
|
+
published one. The Versions tab shows what changed field by field, compared with the live page or
|
|
237
|
+
with any other version, and a preview of the version. Restoring a version makes it the current
|
|
238
|
+
draft. It does not publish it.
|
|
239
|
+
|
|
240
|
+
If two people edit the same page in the same admin, the second save is rejected with "This page
|
|
241
|
+
was changed since you opened it — reload to see the latest", so nobody overwrites someone else's
|
|
242
|
+
draft without seeing it.
|
|
243
|
+
|
|
244
|
+
The server validates every save: required fields, `maxLength`, row counts and link URLs. Errors
|
|
245
|
+
show on the field that caused them.
|
|
246
|
+
|
|
247
|
+
Sections and pages that are in the JSON but not in your config are kept as they are when a page is
|
|
248
|
+
saved, and so are unknown keys inside known sections.
|
|
249
|
+
|
|
250
|
+
### Images
|
|
251
|
+
|
|
252
|
+
The editor resizes images in the browser to at most 2400px on the longest side and converts them
|
|
253
|
+
to WebP. It never scales an image up. Files are named `<page>-<section id>-<hash>.webp`. Each
|
|
254
|
+
image can be at most 1 MB after conversion, and a single save can add at most 20.
|
|
255
|
+
|
|
256
|
+
While a page is a draft its images are stored in the database. Publishing writes them to
|
|
257
|
+
`mediaDir`. Commit them along with the page's JSON file.
|
|
258
|
+
|
|
259
|
+
## Adopting it in an existing site
|
|
260
|
+
|
|
261
|
+
The plugin doesn't touch your existing collections, so you can move one page at a time:
|
|
262
|
+
|
|
263
|
+
1. Define the sections for one page, for example `home`, and add it to `pages`.
|
|
264
|
+
2. Open it under Site pages and publish once to create `content/pages/home.json`. An empty file
|
|
265
|
+
also works, since missing sections and fields get empty defaults.
|
|
266
|
+
3. Render that page from the JSON with `getPage` instead of from your collection.
|
|
267
|
+
4. Leave the other pages where they are until you move them.
|
|
268
|
+
|
|
269
|
+
## Exports
|
|
270
|
+
|
|
271
|
+
| Import | Contents |
|
|
272
|
+
| ----------------------------------- | ----------------------------------------------------------------------- |
|
|
273
|
+
| `payload-flat-pages` | `flatPages`, `getStore`, and the option, section and page types. |
|
|
274
|
+
| `payload-flat-pages/site` | `getPage`, `sectionAttrs`, `seoMetadata`. Safe in server components. |
|
|
275
|
+
| `payload-flat-pages/site-client` | `useLivePage`, for client components. |
|
|
276
|
+
| `payload-flat-pages/rsc`, `/client` | Admin components the plugin registers. You don't import these yourself. |
|
|
277
|
+
|
|
278
|
+
`getStore(options).read(slug)` reads a published page from disk, using the options from
|
|
279
|
+
`config.custom.flatPages`. It only works where the JSON files exist at runtime, which on serverless
|
|
280
|
+
hosts usually means they don't. Importing the JSON, as shown above, works everywhere.
|
|
281
|
+
|
|
282
|
+
## API
|
|
283
|
+
|
|
284
|
+
The admin uses these routes under `/api/flat-pages/`. Only users of your admin user collection
|
|
285
|
+
can call them.
|
|
286
|
+
|
|
287
|
+
- `GET` and `POST pages/:slug`, `POST pages/:slug/discard`, `GET pages/:slug/versions`
|
|
288
|
+
- `GET versions/:id`, `POST versions/:id/restore`
|
|
289
|
+
- `GET drafts`, `POST publish`, `GET media/:filename`
|
|
290
|
+
|
|
291
|
+
`POST publish` takes `{ pages: [{ slug, expectedVersion }] }`, where `expectedVersion` is the draft
|
|
292
|
+
id the user was looking at. If any of the pages has a newer draft, nothing is published and the
|
|
293
|
+
response is a 409.
|
|
294
|
+
|
|
295
|
+
## Development
|
|
296
|
+
|
|
297
|
+
```sh
|
|
298
|
+
pnpm install
|
|
299
|
+
pnpm dev # the test app in ./dev
|
|
300
|
+
pnpm test:int # typecheck, unit and integration tests
|
|
301
|
+
pnpm test:e2e # Playwright tests
|
|
302
|
+
pnpm lint
|
|
303
|
+
pnpm build # builds the plugin into dist/
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
`pnpm dev` serves http://localhost:3000/admin. Log in as `dev@payloadcms.com` with the password
|
|
307
|
+
`test` and open Site pages. Without `dev/.env` the app uses an in-memory MongoDB that is wiped on
|
|
308
|
+
restart. To keep your data, copy `dev/.env.example` to `dev/.env` and point `DATABASE_URL` at a
|
|
309
|
+
MongoDB you run.
|
|
310
|
+
|
|
311
|
+
## License
|
|
312
|
+
|
|
313
|
+
MIT
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { PageContent, PreviewBreakpoint } from '../types.js';
|
|
2
|
+
/** Read-only preview of saved content (a version or a draft) over the preview bridge. */
|
|
3
|
+
export declare function ContentPreview({ apiRoute, breakpoints, content, mediaPublicPath, previewURL, }: {
|
|
4
|
+
apiRoute: string;
|
|
5
|
+
breakpoints: PreviewBreakpoint[];
|
|
6
|
+
content: PageContent;
|
|
7
|
+
mediaPublicPath: string;
|
|
8
|
+
previewURL: string;
|
|
9
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import React, { useMemo, useRef } from 'react';
|
|
4
|
+
import { withMediaURLs } from './mediaURL.js';
|
|
5
|
+
import { usePreviewBridge } from './previewBridge.js';
|
|
6
|
+
import { PreviewPane } from './PreviewPane.js';
|
|
7
|
+
/** Read-only preview of saved content (a version or a draft) over the preview bridge. */ export function ContentPreview({ apiRoute, breakpoints, content, mediaPublicPath, previewURL }) {
|
|
8
|
+
const frame = useRef(null);
|
|
9
|
+
const shown = useMemo(()=>withMediaURLs(content, mediaPublicPath, apiRoute, new Map()), [
|
|
10
|
+
apiRoute,
|
|
11
|
+
content,
|
|
12
|
+
mediaPublicPath
|
|
13
|
+
]);
|
|
14
|
+
usePreviewBridge(frame, previewURL, shown, ()=>{});
|
|
15
|
+
return /*#__PURE__*/ _jsx(PreviewPane, {
|
|
16
|
+
breakpoints: breakpoints,
|
|
17
|
+
frame: frame,
|
|
18
|
+
url: previewURL
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
//# sourceMappingURL=ContentPreview.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/admin/ContentPreview.tsx"],"sourcesContent":["'use client'\n\nimport React, { useMemo, useRef } from 'react'\n\nimport type { PageContent, PreviewBreakpoint } from '../types.js'\n\nimport { withMediaURLs } from './mediaURL.js'\nimport { usePreviewBridge } from './previewBridge.js'\nimport { PreviewPane } from './PreviewPane.js'\n\n/** Read-only preview of saved content (a version or a draft) over the preview bridge. */\nexport function ContentPreview({\n apiRoute,\n breakpoints,\n content,\n mediaPublicPath,\n previewURL,\n}: {\n apiRoute: string\n breakpoints: PreviewBreakpoint[]\n content: PageContent\n mediaPublicPath: string\n previewURL: string\n}) {\n const frame = useRef<HTMLIFrameElement>(null)\n const shown = useMemo(\n () => withMediaURLs(content, mediaPublicPath, apiRoute, new Map()),\n [apiRoute, content, mediaPublicPath],\n )\n usePreviewBridge(frame, previewURL, shown, () => {})\n return <PreviewPane breakpoints={breakpoints} frame={frame} url={previewURL} />\n}\n"],"names":["React","useMemo","useRef","withMediaURLs","usePreviewBridge","PreviewPane","ContentPreview","apiRoute","breakpoints","content","mediaPublicPath","previewURL","frame","shown","Map","url"],"mappings":"AAAA;;AAEA,OAAOA,SAASC,OAAO,EAAEC,MAAM,QAAQ,QAAO;AAI9C,SAASC,aAAa,QAAQ,gBAAe;AAC7C,SAASC,gBAAgB,QAAQ,qBAAoB;AACrD,SAASC,WAAW,QAAQ,mBAAkB;AAE9C,uFAAuF,GACvF,OAAO,SAASC,eAAe,EAC7BC,QAAQ,EACRC,WAAW,EACXC,OAAO,EACPC,eAAe,EACfC,UAAU,EAOX;IACC,MAAMC,QAAQV,OAA0B;IACxC,MAAMW,QAAQZ,QACZ,IAAME,cAAcM,SAASC,iBAAiBH,UAAU,IAAIO,QAC5D;QAACP;QAAUE;QAASC;KAAgB;IAEtCN,iBAAiBQ,OAAOD,YAAYE,OAAO,KAAO;IAClD,qBAAO,KAACR;QAAYG,aAAaA;QAAaI,OAAOA;QAAOG,KAAKJ;;AACnE"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { SectionDiff } from '../content/diff.js';
|
|
2
|
+
type Props = {
|
|
3
|
+
apiRoute: string;
|
|
4
|
+
diffs: SectionDiff[];
|
|
5
|
+
mediaPublicPath: string;
|
|
6
|
+
};
|
|
7
|
+
export declare function DiffView({ apiRoute, diffs, mediaPublicPath }: Props): import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { wordDiff } from '../content/diff.js';
|
|
5
|
+
import { mediaURL } from './mediaURL.js';
|
|
6
|
+
export function DiffView({ apiRoute, diffs, mediaPublicPath }) {
|
|
7
|
+
if (!diffs.length) {
|
|
8
|
+
return /*#__PURE__*/ _jsx("p", {
|
|
9
|
+
className: "pb-empty",
|
|
10
|
+
children: "No differences."
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
return /*#__PURE__*/ _jsx("div", {
|
|
14
|
+
className: "pb-diff",
|
|
15
|
+
children: diffs.map((d)=>/*#__PURE__*/ _jsxs("section", {
|
|
16
|
+
className: "pb-diff__section",
|
|
17
|
+
children: [
|
|
18
|
+
/*#__PURE__*/ _jsx("h3", {
|
|
19
|
+
children: d.label
|
|
20
|
+
}),
|
|
21
|
+
/*#__PURE__*/ _jsx(Changes, {
|
|
22
|
+
apiRoute: apiRoute,
|
|
23
|
+
changes: d.changes,
|
|
24
|
+
mediaPublicPath: mediaPublicPath
|
|
25
|
+
})
|
|
26
|
+
]
|
|
27
|
+
}, d.id))
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
function Changes({ apiRoute, changes, mediaPublicPath }) {
|
|
31
|
+
const thumb = (value)=>{
|
|
32
|
+
const src = value && (mediaURL(value, mediaPublicPath, apiRoute, new Map()) ?? value);
|
|
33
|
+
return src ? /*#__PURE__*/ _jsx("img", {
|
|
34
|
+
alt: "",
|
|
35
|
+
src: src
|
|
36
|
+
}) : /*#__PURE__*/ _jsx("span", {
|
|
37
|
+
className: "pb-diff__none",
|
|
38
|
+
children: "No image"
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
return /*#__PURE__*/ _jsx(_Fragment, {
|
|
42
|
+
children: changes.map((c)=>/*#__PURE__*/ _jsxs("div", {
|
|
43
|
+
className: "pb-diff__field",
|
|
44
|
+
children: [
|
|
45
|
+
/*#__PURE__*/ _jsx("h4", {
|
|
46
|
+
children: c.label
|
|
47
|
+
}),
|
|
48
|
+
c.kind === 'text' && /*#__PURE__*/ _jsx("p", {
|
|
49
|
+
className: "pb-diff__text",
|
|
50
|
+
children: wordDiff(c.before, c.after).map((p, i)=>p.op === 'del' ? /*#__PURE__*/ _jsx("del", {
|
|
51
|
+
children: p.text
|
|
52
|
+
}, i) : p.op === 'add' ? /*#__PURE__*/ _jsx("ins", {
|
|
53
|
+
children: p.text
|
|
54
|
+
}, i) : /*#__PURE__*/ _jsx("span", {
|
|
55
|
+
children: p.text
|
|
56
|
+
}, i))
|
|
57
|
+
}),
|
|
58
|
+
c.kind === 'value' && /*#__PURE__*/ _jsxs("p", {
|
|
59
|
+
className: "pb-diff__text",
|
|
60
|
+
children: [
|
|
61
|
+
/*#__PURE__*/ _jsx("del", {
|
|
62
|
+
children: c.before
|
|
63
|
+
}),
|
|
64
|
+
" ",
|
|
65
|
+
/*#__PURE__*/ _jsx("ins", {
|
|
66
|
+
children: c.after
|
|
67
|
+
})
|
|
68
|
+
]
|
|
69
|
+
}),
|
|
70
|
+
c.kind === 'image' && /*#__PURE__*/ _jsxs("div", {
|
|
71
|
+
className: "pb-diff__images",
|
|
72
|
+
children: [
|
|
73
|
+
thumb(c.before),
|
|
74
|
+
/*#__PURE__*/ _jsx("span", {
|
|
75
|
+
"aria-hidden": true,
|
|
76
|
+
children: "→"
|
|
77
|
+
}),
|
|
78
|
+
thumb(c.after)
|
|
79
|
+
]
|
|
80
|
+
}),
|
|
81
|
+
c.kind === 'array' && c.items.map((item)=>/*#__PURE__*/ _jsxs("div", {
|
|
82
|
+
className: "pb-diff__item",
|
|
83
|
+
children: [
|
|
84
|
+
/*#__PURE__*/ _jsx("h5", {
|
|
85
|
+
children: `Item ${item.index + 1} — ${item.status}`
|
|
86
|
+
}),
|
|
87
|
+
/*#__PURE__*/ _jsx(Changes, {
|
|
88
|
+
apiRoute: apiRoute,
|
|
89
|
+
changes: item.changes,
|
|
90
|
+
mediaPublicPath: mediaPublicPath
|
|
91
|
+
})
|
|
92
|
+
]
|
|
93
|
+
}, item.index))
|
|
94
|
+
]
|
|
95
|
+
}, c.path))
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
//# sourceMappingURL=DiffView.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/admin/DiffView.tsx"],"sourcesContent":["'use client'\n\nimport React from 'react'\n\nimport type { FieldChange, SectionDiff } from '../content/diff.js'\n\nimport { wordDiff } from '../content/diff.js'\nimport { mediaURL } from './mediaURL.js'\n\ntype Props = { apiRoute: string; diffs: SectionDiff[]; mediaPublicPath: string }\n\nexport function DiffView({ apiRoute, diffs, mediaPublicPath }: Props) {\n if (!diffs.length) {\n return <p className=\"pb-empty\">No differences.</p>\n }\n return (\n <div className=\"pb-diff\">\n {diffs.map((d) => (\n <section className=\"pb-diff__section\" key={d.id}>\n <h3>{d.label}</h3>\n <Changes apiRoute={apiRoute} changes={d.changes} mediaPublicPath={mediaPublicPath} />\n </section>\n ))}\n </div>\n )\n}\n\nfunction Changes({\n apiRoute,\n changes,\n mediaPublicPath,\n}: { changes: FieldChange[] } & Omit<Props, 'diffs'>) {\n const thumb = (value: null | string) => {\n const src = value && (mediaURL(value, mediaPublicPath, apiRoute, new Map()) ?? value)\n return src ? <img alt=\"\" src={src} /> : <span className=\"pb-diff__none\">No image</span>\n }\n return (\n <>\n {changes.map((c) => (\n <div className=\"pb-diff__field\" key={c.path}>\n <h4>{c.label}</h4>\n {c.kind === 'text' && (\n <p className=\"pb-diff__text\">\n {wordDiff(c.before, c.after).map((p, i) =>\n p.op === 'del' ? (\n <del key={i}>{p.text}</del>\n ) : p.op === 'add' ? (\n <ins key={i}>{p.text}</ins>\n ) : (\n <span key={i}>{p.text}</span>\n ),\n )}\n </p>\n )}\n {c.kind === 'value' && (\n <p className=\"pb-diff__text\">\n <del>{c.before}</del> <ins>{c.after}</ins>\n </p>\n )}\n {c.kind === 'image' && (\n <div className=\"pb-diff__images\">\n {thumb(c.before)}\n <span aria-hidden>→</span>\n {thumb(c.after)}\n </div>\n )}\n {c.kind === 'array' &&\n c.items.map((item) => (\n <div className=\"pb-diff__item\" key={item.index}>\n <h5>{`Item ${item.index + 1} — ${item.status}`}</h5>\n <Changes\n apiRoute={apiRoute}\n changes={item.changes}\n mediaPublicPath={mediaPublicPath}\n />\n </div>\n ))}\n </div>\n ))}\n </>\n )\n}\n"],"names":["React","wordDiff","mediaURL","DiffView","apiRoute","diffs","mediaPublicPath","length","p","className","div","map","d","section","h3","label","Changes","changes","id","thumb","value","src","Map","img","alt","span","c","h4","kind","before","after","i","op","del","text","ins","aria-hidden","items","item","h5","index","status","path"],"mappings":"AAAA;;AAEA,OAAOA,WAAW,QAAO;AAIzB,SAASC,QAAQ,QAAQ,qBAAoB;AAC7C,SAASC,QAAQ,QAAQ,gBAAe;AAIxC,OAAO,SAASC,SAAS,EAAEC,QAAQ,EAAEC,KAAK,EAAEC,eAAe,EAAS;IAClE,IAAI,CAACD,MAAME,MAAM,EAAE;QACjB,qBAAO,KAACC;YAAEC,WAAU;sBAAW;;IACjC;IACA,qBACE,KAACC;QAAID,WAAU;kBACZJ,MAAMM,GAAG,CAAC,CAACC,kBACV,MAACC;gBAAQJ,WAAU;;kCACjB,KAACK;kCAAIF,EAAEG,KAAK;;kCACZ,KAACC;wBAAQZ,UAAUA;wBAAUa,SAASL,EAAEK,OAAO;wBAAEX,iBAAiBA;;;eAFzBM,EAAEM,EAAE;;AAOvD;AAEA,SAASF,QAAQ,EACfZ,QAAQ,EACRa,OAAO,EACPX,eAAe,EACmC;IAClD,MAAMa,QAAQ,CAACC;QACb,MAAMC,MAAMD,SAAUlB,CAAAA,SAASkB,OAAOd,iBAAiBF,UAAU,IAAIkB,UAAUF,KAAI;QACnF,OAAOC,oBAAM,KAACE;YAAIC,KAAI;YAAGH,KAAKA;2BAAU,KAACI;YAAKhB,WAAU;sBAAgB;;IAC1E;IACA,qBACE;kBACGQ,QAAQN,GAAG,CAAC,CAACe,kBACZ,MAAChB;gBAAID,WAAU;;kCACb,KAACkB;kCAAID,EAAEX,KAAK;;oBACXW,EAAEE,IAAI,KAAK,wBACV,KAACpB;wBAAEC,WAAU;kCACVR,SAASyB,EAAEG,MAAM,EAAEH,EAAEI,KAAK,EAAEnB,GAAG,CAAC,CAACH,GAAGuB,IACnCvB,EAAEwB,EAAE,KAAK,sBACP,KAACC;0CAAazB,EAAE0B,IAAI;+BAAVH,KACRvB,EAAEwB,EAAE,KAAK,sBACX,KAACG;0CAAa3B,EAAE0B,IAAI;+BAAVH,mBAEV,KAACN;0CAAcjB,EAAE0B,IAAI;+BAAVH;;oBAKlBL,EAAEE,IAAI,KAAK,yBACV,MAACpB;wBAAEC,WAAU;;0CACX,KAACwB;0CAAKP,EAAEG,MAAM;;4BAAO;0CAAC,KAACM;0CAAKT,EAAEI,KAAK;;;;oBAGtCJ,EAAEE,IAAI,KAAK,yBACV,MAAClB;wBAAID,WAAU;;4BACZU,MAAMO,EAAEG,MAAM;0CACf,KAACJ;gCAAKW,aAAW;0CAAC;;4BACjBjB,MAAMO,EAAEI,KAAK;;;oBAGjBJ,EAAEE,IAAI,KAAK,WACVF,EAAEW,KAAK,CAAC1B,GAAG,CAAC,CAAC2B,qBACX,MAAC5B;4BAAID,WAAU;;8CACb,KAAC8B;8CAAI,CAAC,KAAK,EAAED,KAAKE,KAAK,GAAG,EAAE,GAAG,EAAEF,KAAKG,MAAM,EAAE;;8CAC9C,KAACzB;oCACCZ,UAAUA;oCACVa,SAASqB,KAAKrB,OAAO;oCACrBX,iBAAiBA;;;2BALegC,KAAKE,KAAK;;eA7Bfd,EAAEgB,IAAI;;AA0CnD"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { PreviewBreakpoint } from '../types.js';
|
|
3
|
+
import type { DraftSummary } from '../versions/service.js';
|
|
4
|
+
type Props = {
|
|
5
|
+
apiRoute: string;
|
|
6
|
+
breakpoints: PreviewBreakpoint[];
|
|
7
|
+
drafts: DraftSummary[];
|
|
8
|
+
editURL: Record<string, string>;
|
|
9
|
+
mediaPublicPath: string;
|
|
10
|
+
previewURLs: Record<string, null | string>;
|
|
11
|
+
};
|
|
12
|
+
/** `Pages | Drafts (n)` tabs; the server renders both panes, this only switches them. */
|
|
13
|
+
export declare function ListTabs({ children, count, drafts, initial, }: {
|
|
14
|
+
children: React.ReactNode;
|
|
15
|
+
count: number;
|
|
16
|
+
drafts: React.ReactNode;
|
|
17
|
+
initial: 'drafts' | 'pages';
|
|
18
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
19
|
+
export declare function DraftsView({ apiRoute, breakpoints, drafts, editURL, mediaPublicPath, previewURLs, }: Props): import("react/jsx-runtime").JSX.Element;
|
|
20
|
+
export {};
|