payload-live-preview 1.8.0 → 2.0.0-beta.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.
Files changed (98) hide show
  1. package/README.md +301 -93
  2. package/dist/adapters/astro/PreviewBoundary.astro +66 -0
  3. package/dist/adapters/astro/RichText.astro +6 -0
  4. package/dist/adapters/astro/index.d.ts +165 -134
  5. package/dist/adapters/astro/index.js +1 -1
  6. package/dist/adapters/astro/index.js.map +1 -1
  7. package/dist/adapters/astro/middleware-entry.d.ts +4 -9
  8. package/dist/adapters/astro/middleware-entry.js +1 -1
  9. package/dist/adapters/astro/middleware-entry.js.map +1 -1
  10. package/dist/adapters/nextjs/index.d.ts +13 -80
  11. package/dist/adapters/nextjs/index.js +1 -1
  12. package/dist/adapters/nextjs/index.js.map +1 -1
  13. package/dist/adapters/nuxt/index.d.ts +46 -106
  14. package/dist/adapters/nuxt/index.js +1 -1
  15. package/dist/adapters/nuxt/index.js.map +1 -1
  16. package/dist/adapters/sveltekit/index.d.ts +10 -75
  17. package/dist/adapters/sveltekit/index.js +1 -1
  18. package/dist/adapters/sveltekit/index.js.map +1 -1
  19. package/dist/client.cjs +2 -0
  20. package/dist/client.cjs.map +1 -0
  21. package/dist/client.d.cts +747 -0
  22. package/dist/client.d.ts +747 -0
  23. package/dist/client.js +2 -0
  24. package/dist/client.js.map +1 -0
  25. package/dist/codegen-astro.d.ts +5 -27
  26. package/dist/codegen-astro.js +1 -1
  27. package/dist/codegen-astro.js.map +1 -1
  28. package/dist/codegen-cli.d.ts +3 -16
  29. package/dist/codegen-cli.js +1 -1
  30. package/dist/codegen-cli.js.map +1 -1
  31. package/dist/codegen.cjs +1 -1
  32. package/dist/codegen.cjs.map +1 -1
  33. package/dist/codegen.d.cts +37 -124
  34. package/dist/codegen.d.ts +37 -124
  35. package/dist/codegen.js +1 -1
  36. package/dist/codegen.js.map +1 -1
  37. package/dist/core.cjs +1 -1
  38. package/dist/core.cjs.map +1 -1
  39. package/dist/core.d.cts +647 -1100
  40. package/dist/core.d.ts +647 -1100
  41. package/dist/core.js +1 -1
  42. package/dist/core.js.map +1 -1
  43. package/dist/doctor-cli.d.ts +3 -28
  44. package/dist/doctor-cli.js +1 -1
  45. package/dist/doctor-cli.js.map +1 -1
  46. package/dist/doctor.d.ts +16 -32
  47. package/dist/doctor.js +1 -1
  48. package/dist/doctor.js.map +1 -1
  49. package/dist/fragment.cjs +2 -0
  50. package/dist/fragment.cjs.map +1 -0
  51. package/dist/fragment.d.cts +333 -0
  52. package/dist/fragment.d.ts +333 -0
  53. package/dist/fragment.js +2 -0
  54. package/dist/fragment.js.map +1 -0
  55. package/dist/index.cjs +1 -1
  56. package/dist/index.cjs.map +1 -1
  57. package/dist/index.d.cts +885 -1531
  58. package/dist/index.d.ts +885 -1531
  59. package/dist/index.js +1 -1
  60. package/dist/index.js.map +1 -1
  61. package/dist/lexical.cjs +2 -0
  62. package/dist/lexical.cjs.map +1 -0
  63. package/dist/lexical.d.cts +90 -0
  64. package/dist/lexical.d.ts +90 -0
  65. package/dist/lexical.js +2 -0
  66. package/dist/lexical.js.map +1 -0
  67. package/dist/middleware-CEPsY1P7.d.ts +40 -0
  68. package/dist/migrate.d.ts +73 -0
  69. package/dist/migrate.js +2 -0
  70. package/dist/migrate.js.map +1 -0
  71. package/dist/options-CEzzfHJu.d.ts +197 -0
  72. package/dist/payload.cjs +1 -1
  73. package/dist/payload.cjs.map +1 -1
  74. package/dist/payload.d.cts +11 -80
  75. package/dist/payload.d.ts +11 -80
  76. package/dist/payload.js +1 -1
  77. package/dist/payload.js.map +1 -1
  78. package/dist/plugins.cjs +2 -0
  79. package/dist/plugins.cjs.map +1 -0
  80. package/dist/plugins.d.cts +509 -0
  81. package/dist/plugins.d.ts +509 -0
  82. package/dist/plugins.js +2 -0
  83. package/dist/plugins.js.map +1 -0
  84. package/dist/{probe-tMHdim5y.d.ts → probe-CYtvj_Lm.d.ts} +43 -77
  85. package/dist/server.cjs +2 -0
  86. package/dist/server.cjs.map +1 -0
  87. package/dist/server.d.cts +435 -0
  88. package/dist/server.d.ts +435 -0
  89. package/dist/server.js +2 -0
  90. package/dist/server.js.map +1 -0
  91. package/dist/structural.cjs +3 -0
  92. package/dist/structural.cjs.map +1 -0
  93. package/dist/structural.d.cts +243 -0
  94. package/dist/structural.d.ts +243 -0
  95. package/dist/structural.js +3 -0
  96. package/dist/structural.js.map +1 -0
  97. package/package.json +86 -7
  98. package/dist/middleware-DD4Hwomt.d.ts +0 -189
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "payload-live-preview",
3
- "version": "1.8.0",
3
+ "version": "2.0.0-beta.0",
4
4
  "description": "Live preview for Payload CMS in Astro and any SSR/static frontend (SvelteKit, Nuxt, Next.js, plain HTML). Patches the DOM live, no rebuild.",
5
5
  "author": "relative23",
6
6
  "license": "MIT",
7
7
  "type": "module",
8
- "packageManager": "npm@11.16.0",
8
+ "packageManager": "npm@12.0.2",
9
9
  "main": "./dist/index.cjs",
10
10
  "module": "./dist/index.js",
11
11
  "types": "./dist/index.d.ts",
@@ -76,6 +76,12 @@
76
76
  "default": "./dist/doctor.js"
77
77
  }
78
78
  },
79
+ "./migrate": {
80
+ "import": {
81
+ "types": "./dist/migrate.d.ts",
82
+ "default": "./dist/migrate.js"
83
+ }
84
+ },
79
85
  "./payload": {
80
86
  "import": {
81
87
  "types": "./dist/payload.d.ts",
@@ -86,7 +92,68 @@
86
92
  "default": "./dist/payload.cjs"
87
93
  }
88
94
  },
95
+ "./server": {
96
+ "import": {
97
+ "types": "./dist/server.d.ts",
98
+ "default": "./dist/server.js"
99
+ },
100
+ "require": {
101
+ "types": "./dist/server.d.cts",
102
+ "default": "./dist/server.cjs"
103
+ }
104
+ },
105
+ "./client": {
106
+ "import": {
107
+ "types": "./dist/client.d.ts",
108
+ "default": "./dist/client.js"
109
+ },
110
+ "require": {
111
+ "types": "./dist/client.d.cts",
112
+ "default": "./dist/client.cjs"
113
+ }
114
+ },
115
+ "./structural": {
116
+ "import": {
117
+ "types": "./dist/structural.d.ts",
118
+ "default": "./dist/structural.js"
119
+ },
120
+ "require": {
121
+ "types": "./dist/structural.d.cts",
122
+ "default": "./dist/structural.cjs"
123
+ }
124
+ },
125
+ "./lexical": {
126
+ "import": {
127
+ "types": "./dist/lexical.d.ts",
128
+ "default": "./dist/lexical.js"
129
+ },
130
+ "require": {
131
+ "types": "./dist/lexical.d.cts",
132
+ "default": "./dist/lexical.cjs"
133
+ }
134
+ },
135
+ "./plugins": {
136
+ "import": {
137
+ "types": "./dist/plugins.d.ts",
138
+ "default": "./dist/plugins.js"
139
+ },
140
+ "require": {
141
+ "types": "./dist/plugins.d.cts",
142
+ "default": "./dist/plugins.cjs"
143
+ }
144
+ },
145
+ "./fragment": {
146
+ "import": {
147
+ "types": "./dist/fragment.d.ts",
148
+ "default": "./dist/fragment.js"
149
+ },
150
+ "require": {
151
+ "types": "./dist/fragment.d.cts",
152
+ "default": "./dist/fragment.cjs"
153
+ }
154
+ },
89
155
  "./astro/RichText.astro": "./dist/adapters/astro/RichText.astro",
156
+ "./astro/PreviewBoundary.astro": "./dist/adapters/astro/PreviewBoundary.astro",
90
157
  "./astro/middleware-entry": {
91
158
  "import": {
92
159
  "types": "./dist/adapters/astro/middleware-entry.d.ts",
@@ -106,25 +173,34 @@
106
173
  "sideEffects": false,
107
174
  "scripts": {
108
175
  "build:runtime": "tsx scripts/build-runtime.ts",
109
- "build": "npm run build:runtime && tsx scripts/build-dist.ts && npm run build:assets && npm run test:bundle",
110
- "build:assets": "node -e \"require('node:fs').copyFileSync('src/adapters/astro/RichText.astro','dist/adapters/astro/RichText.astro')\"",
176
+ "build": "npm run build:runtime && tsx scripts/build-dist.ts && npm run build:assets && npm run test:bundle && npm run test:treeshake && npm run test:edge",
177
+ "build:assets": "node -e \"const fs=require('node:fs');for(const f of ['RichText','PreviewBoundary'])fs.copyFileSync('src/adapters/astro/'+f+'.astro','dist/adapters/astro/'+f+'.astro')\"",
111
178
  "dev": "tsup --watch",
179
+ "pretest": "npm run build:runtime",
112
180
  "test": "vitest run",
113
181
  "test:watch": "vitest",
114
182
  "test:unit": "vitest run tests/unit",
115
183
  "test:integration": "vitest run tests/integration",
116
184
  "test:e2e": "playwright test",
185
+ "check:fixtures": "tsx scripts/check-fixture-freshness.ts",
117
186
  "test:e2e:real-payload": "playwright test --config playwright.real-payload.config.ts",
118
187
  "test:a11y": "playwright test tests/e2e/specs/accessibility.spec.ts",
119
188
  "test:soak": "playwright test --config playwright.soak.config.ts",
189
+ "test:browser-bench": "playwright test --config playwright.bench.config.ts",
120
190
  "test:bench": "vitest bench tests/benchmarks",
121
191
  "test:bench:codspeed": "vitest bench --run --config vitest.bench.config.ts",
122
192
  "test:bundle": "tsx scripts/check-bundle-size.ts",
193
+ "test:treeshake": "tsx scripts/check-tree-shaking.ts",
194
+ "test:edge": "NODE_OPTIONS='--experimental-vm-modules --no-warnings' tsx scripts/check-edge-runtime.ts",
195
+ "compat:check": "tsx scripts/compat-table.ts --check",
196
+ "compat:write": "tsx scripts/compat-table.ts --write",
123
197
  "test:package": "tsx scripts/check-package.ts",
198
+ "audit:gate": "tsx scripts/audit-gate.ts",
199
+ "test:smoke": "tsx scripts/post-publish-smoke.ts",
124
200
  "test:coverage": "vitest run --coverage",
125
201
  "test:coverage:diff": "tsx scripts/coverage-policy.ts",
126
202
  "test:policy": "tsx scripts/test-policy.ts",
127
- "test:architecture": "tsx scripts/architecture-policy.ts && tsx scripts/quality-workflow-policy.ts && knip --no-progress --treat-config-hints-as-errors",
203
+ "test:architecture": "tsx scripts/architecture-policy.ts && tsx scripts/workflow-contracts.ts && tsx scripts/docs-contracts.ts && knip --no-progress --treat-config-hints-as-errors",
128
204
  "test:property": "vitest run tests/unit/property",
129
205
  "test:mutation": "stryker run stryker.config.js",
130
206
  "test:mutation:policy:pr": "tsx scripts/mutation-policy.ts --policy quality/mutation-policy-pr.json --report test-results/stryker-pr.json",
@@ -141,7 +217,8 @@
141
217
  "prepublishOnly": "npm run build && npm run check && npm run format:check && npm run test:package",
142
218
  "changeset": "changeset",
143
219
  "version": "changeset version && tsx scripts/sync-lockfile-metadata.ts",
144
- "release": "tsx scripts/publish-artifact.ts"
220
+ "release": "tsx scripts/publish-artifact.ts",
221
+ "test:docs": "tsx scripts/docs-contracts.ts"
145
222
  },
146
223
  "devDependencies": {
147
224
  "@arethetypeswrong/cli": "^0.18.5",
@@ -171,7 +248,9 @@
171
248
  "tsx": "^4.23.12",
172
249
  "typescript": "^5.9.3",
173
250
  "typescript-eslint": "^8.67.0",
174
- "vitest": "^4.1.10"
251
+ "vite": "^7.3.6",
252
+ "vitest": "^4.1.10",
253
+ "yaml": "^2.9.0"
175
254
  },
176
255
  "overrides": {
177
256
  "qs": "6.15.3",
@@ -1,189 +0,0 @@
1
- /**
2
- * Public types for the Astro adapter.
3
- *
4
- * @module @adapters/astro/types
5
- */
6
- interface LivePreviewAstroOptions {
7
- /**
8
- * How the integration wires the preview:
9
- *
10
- * - `'inline'` (default) — bake the runtime into every page at
11
- * build time. For `output: 'static'` projects.
12
- * - `'loader'` — inject a few hundred bytes that check the preview
13
- * context and fetch the runtime as a hashed, SRI-verified asset only
14
- * when it is one. Also for `output: 'static'`, and the better choice
15
- * there: `'inline'` charges every ordinary visitor ~21 KB gzip for a
16
- * feature only an editor uses.
17
- * - `'middleware'` — auto-register the preview middleware:
18
- * request-time injection into requests with preview intent,
19
- * plus `frame-ancestors` CSP management. For `output: 'server'`.
20
- * (`shouldInject` is unsupported here — options serialize into
21
- * the build.)
22
- *
23
- * Intent signals are not authorization. If either response change
24
- * must be access-controlled, compose `createLivePreviewMiddleware()`
25
- * manually after an application-owned server-side authorization.
26
- */
27
- readonly mode?: 'inline' | 'loader' | 'middleware';
28
- /**
29
- * Allowed Payload admin origin(s) for inbound browser messages and
30
- * the optional Referer intent signal. This does not authenticate the
31
- * incoming HTTP request or authorize draft access.
32
- */
33
- readonly allowedOrigins?: readonly string[];
34
- /**
35
- * Payload server origin, e.g. `https://cms.example.com`. When set,
36
- * incoming updates are re-fetched through the Payload REST API so
37
- * relationship/upload fields render populated instead of as bare
38
- * IDs. Strongly recommended for Payload 3.x.
39
- */
40
- readonly serverURL?: string;
41
- /** REST API route prefix used with `serverURL`. Defaults to `/api`. */
42
- readonly apiRoute?: string;
43
- /** Population depth used with `serverURL`. Defaults to `1`. */
44
- readonly mergeDepth?: number;
45
- /**
46
- * Auto-inject the inline preview script. Default `true`. Disable to
47
- * embed the script manually via `renderLivePreviewScript()`.
48
- */
49
- readonly autoInject?: boolean;
50
- /**
51
- * When the middleware injects the script (integration-based
52
- * injection is always build-time and unaffected):
53
- *
54
- * - `'preview-only'` (default) — only into responses carrying a
55
- * preview-intent signal (`?preview=true` / `?draft=true` query,
56
- * `Sec-Fetch-Dest: iframe`, or a referer from `allowedOrigins`).
57
- * These client-controlled signals are a delivery optimisation,
58
- * not authorization.
59
- * - `'always'` — into every HTML response.
60
- */
61
- readonly inject?: 'preview-only' | 'always';
62
- /**
63
- * Query parameters that mark a request as a preview (values `true`
64
- * or `1`). Default: `['preview', 'draft', 'livePreview']`.
65
- */
66
- readonly previewQueryParams?: readonly string[];
67
- /**
68
- * Which signals count as preview intent. Default: all three
69
- * (`query`, `fetch-dest`, `referer`). Restrict to `['query']` when
70
- * an unsolicited iframe load must never trigger preview handling
71
- * (e.g. sites that serve `frame-ancestors 'none'` and only allow
72
- * preview via the explicit `?preview=true` URL).
73
- */
74
- readonly previewSignals?: readonly ('query' | 'fetch-dest' | 'referer')[];
75
- /**
76
- * Restrict script injection to requests where this function returns
77
- * `true`. Applied on top of the `inject` mode. This is a synchronous
78
- * route/content filter, not authentication, and it does not suppress
79
- * the adapter's CSP handling. Perform authorization before invoking
80
- * the middleware.
81
- */
82
- readonly shouldInject?: (request: Request) => boolean;
83
- /**
84
- * Content-Security-Policy management on responses carrying preview
85
- * intent. The adapter does not authenticate those requests; invoke
86
- * it only after authorization when this policy change is privileged:
87
- *
88
- * - `'frame-ancestors'` (default) — merge a `frame-ancestors`
89
- * directive allowing the admin origins to embed the page.
90
- * Existing CSP directives are preserved (union merge).
91
- * - `'full'` — additionally manage `script-src` with a
92
- * per-request nonce. Only useful when your whole page is
93
- * nonce-disciplined; see `strictDynamic`.
94
- * - `false` — never touch CSP headers.
95
- *
96
- * `true` is accepted as a legacy alias for `'frame-ancestors'`.
97
- */
98
- readonly manageCsp?: boolean | 'frame-ancestors' | 'full';
99
- /**
100
- * Add `'strict-dynamic'` to the managed `script-src` (only with
101
- * `manageCsp: 'full'`). ⚠️ Under CSP 3 this makes browsers ignore
102
- * `'self'` and host sources — every script on the page must then
103
- * carry the nonce or be loaded by a nonce-carrying script. Astro's
104
- * own hydration scripts do NOT carry it, so leave this off unless
105
- * you know your page is fully nonce-disciplined. Default `false`.
106
- */
107
- readonly strictDynamic?: boolean;
108
- /**
109
- * Extra `frame-ancestors` sources to merge with the auto-detected
110
- * ones. Always includes `'self'` and every entry in `allowedOrigins`.
111
- */
112
- readonly frameAncestorsExtra?: readonly string[];
113
- /**
114
- * Extra `script-src` sources (e.g., a CDN) appended after the nonce
115
- * (only with `manageCsp: 'full'`).
116
- */
117
- readonly scriptSrcExtra?: readonly string[];
118
- /** Enable verbose debug logging in the injected client. Defaults to `false`. */
119
- readonly debug?: boolean;
120
- /**
121
- * Debounce window for incoming updates. Default: 50 ms.
122
- */
123
- readonly debounceMs?: number;
124
- /**
125
- * Heartbeat timeout in ms. Default `0` (disabled — the Payload admin
126
- * sends no keepalive, so an idle timeout would cause false
127
- * disconnects).
128
- */
129
- readonly heartbeatMs?: number;
130
- }
131
-
132
- /**
133
- * Astro middleware for Payload Live Preview.
134
- *
135
- * Responsibilities (per request):
136
- *
137
- * 1. Generate a per-response CSP nonce and stash it on
138
- * `Astro.locals.livePreviewNonce` so consumers can reference it.
139
- * 2. On requests carrying **preview intent** (see
140
- * `isPreviewRequest`), rewrite the HTML response to inject the
141
- * live-preview `<script>` tag.
142
- * 3. On those requests, merge `frame-ancestors` into the
143
- * `Content-Security-Policy` header so the Payload admin may embed
144
- * the page. Full `script-src` nonce management is opt-in via
145
- * `manageCsp: 'full'`.
146
- *
147
- * The intent signals are client-controlled and this middleware does
148
- * not authenticate them. For protected preview responses, first verify
149
- * an application-owned server session or short-lived authorization,
150
- * then invoke this middleware with that same decision also governing
151
- * draft reads, credentials, and cache policy. `shouldInject` filters
152
- * script insertion only; it is not an authorization boundary and does
153
- * not disable CSP handling.
154
- *
155
- * Prerendered pages are skipped entirely: Astro runs middleware at
156
- * build time for those, where per-request nonces and response headers
157
- * are meaningless.
158
- *
159
- * @module @adapters/astro/middleware
160
- */
161
-
162
- type MiddlewareNext = () => Promise<Response>;
163
- interface MiddlewareContext {
164
- readonly request: Request;
165
- readonly locals: Record<string, unknown>;
166
- /** Present in Astro ≥ 5: `true` while prerendering at build time. */
167
- readonly isPrerendered?: boolean;
168
- }
169
- type LivePreviewMiddleware = (context: MiddlewareContext, next: MiddlewareNext) => Promise<Response>;
170
- /**
171
- * Key on `Astro.locals` carrying the request-scoped nonce. Consumers
172
- * can read `Astro.locals.livePreviewNonce` from `.astro` templates to
173
- * set the `nonce` attribute on their own scripts.
174
- */
175
- declare const NONCE_LOCALS_KEY = "livePreviewNonce";
176
- /**
177
- * Build the Astro-compatible middleware. Register it in
178
- * `src/middleware.ts`:
179
- *
180
- * ```ts
181
- * import { createLivePreviewMiddleware } from 'payload-live-preview/astro';
182
- * export const onRequest = createLivePreviewMiddleware({
183
- * allowedOrigins: [import.meta.env.PUBLIC_PAYLOAD_ADMIN_ORIGIN],
184
- * });
185
- * ```
186
- */
187
- declare function createLivePreviewMiddleware(options?: LivePreviewAstroOptions): LivePreviewMiddleware;
188
-
189
- export { type LivePreviewAstroOptions as L, NONCE_LOCALS_KEY as N, type LivePreviewMiddleware as a, createLivePreviewMiddleware as c };