@preprio/toolkit 0.6.0-alpha.8 → 1.0.0-rc.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.
Files changed (116) hide show
  1. package/README.md +111 -1363
  2. package/dist/astro/index.cjs +1555 -182
  3. package/dist/astro/index.d.cts +201 -1
  4. package/dist/astro/index.d.ts +201 -1
  5. package/dist/astro/index.js +1557 -29
  6. package/dist/{chunk-ATPB7GEC.js → chunk-33GWVTRJ.js} +1 -1
  7. package/dist/chunk-A2J7R4LR.js +256 -0
  8. package/dist/{chunk-T7ESBVBI.js → chunk-DSJ22P6J.js} +6 -1
  9. package/dist/chunk-KM2GME62.js +1255 -0
  10. package/dist/chunk-UTKH7DOI.js +58 -0
  11. package/dist/chunk-V7MCHPE7.js +85 -0
  12. package/dist/{chunk-2QGUP7VQ.js → chunk-WBMN4L7G.js} +1680 -579
  13. package/dist/chunk-Y7JWV7WV.js +374 -0
  14. package/dist/codegen/index.cjs +82 -0
  15. package/dist/codegen/index.d.cts +70 -0
  16. package/dist/codegen/index.d.ts +70 -0
  17. package/dist/codegen/index.js +64 -0
  18. package/dist/index.cjs +3729 -553
  19. package/dist/index.d.cts +403 -19
  20. package/dist/index.d.ts +403 -19
  21. package/dist/index.js +345 -24
  22. package/dist/live-preview-HCBNBC6C.js +19 -0
  23. package/dist/nextjs/components.cjs +1872 -729
  24. package/dist/nextjs/components.d.cts +5 -51
  25. package/dist/nextjs/components.d.ts +5 -51
  26. package/dist/nextjs/components.js +8 -274
  27. package/dist/nextjs/index.cjs +1228 -181
  28. package/dist/nextjs/index.d.cts +247 -92
  29. package/dist/nextjs/index.d.ts +247 -92
  30. package/dist/nextjs/index.js +1629 -111
  31. package/dist/nextjs/live-action.cjs +298 -0
  32. package/dist/nextjs/live-action.d.cts +12 -0
  33. package/dist/nextjs/live-action.d.ts +12 -0
  34. package/dist/nextjs/live-action.js +68 -0
  35. package/dist/nextjs/live.cjs +2010 -0
  36. package/dist/nextjs/live.d.cts +54 -0
  37. package/dist/nextjs/live.d.ts +54 -0
  38. package/dist/nextjs/live.js +287 -0
  39. package/dist/nuxt/chunk-5RBZPRQN.js +350 -0
  40. package/dist/nuxt/chunk-LUKVPOJ2.js +32 -0
  41. package/dist/nuxt/index.cjs +15 -16
  42. package/dist/nuxt/index.d.cts +167 -6
  43. package/dist/nuxt/index.d.ts +167 -6
  44. package/dist/nuxt/index.js +402 -15
  45. package/dist/nuxt/live-preview-KO4IKWTX.js +1234 -0
  46. package/dist/nuxt/live.cjs +1928 -0
  47. package/dist/nuxt/live.d.cts +45 -0
  48. package/dist/nuxt/live.d.ts +45 -0
  49. package/dist/nuxt/live.js +216 -0
  50. package/dist/{types-BYH9XqmN.d.cts → pixel-DqU7NvgW.d.cts} +102 -5
  51. package/dist/{types-BYH9XqmN.d.ts → pixel-DqU7NvgW.d.ts} +102 -5
  52. package/dist/react/components.cjs +1865 -480
  53. package/dist/react/components.d.cts +43 -8
  54. package/dist/react/components.d.ts +43 -8
  55. package/dist/react/components.js +1865 -480
  56. package/dist/sveltekit/chunk-5RBZPRQN.js +350 -0
  57. package/dist/sveltekit/chunk-LUKVPOJ2.js +32 -0
  58. package/dist/sveltekit/index.cjs +15 -16
  59. package/dist/sveltekit/index.d.cts +111 -10
  60. package/dist/sveltekit/index.d.ts +111 -10
  61. package/dist/sveltekit/index.js +398 -15
  62. package/dist/sveltekit/live-preview-KO4IKWTX.js +1234 -0
  63. package/dist/sveltekit/live.cjs +1940 -0
  64. package/dist/sveltekit/live.d.cts +61 -0
  65. package/dist/sveltekit/live.d.ts +61 -0
  66. package/dist/sveltekit/live.js +220 -0
  67. package/package.json +132 -71
  68. package/src/astro/PreprToolbar.astro +7 -1
  69. package/src/astro/PreprTrackingPixel.astro +2 -4
  70. package/src/nuxt/PreprToolbar.vue +12 -1
  71. package/src/nuxt/PreprTrackingPixel.vue +2 -4
  72. package/src/sveltekit/PreprToolbar.svelte +17 -2
  73. package/src/sveltekit/PreprTrackingPixel.svelte +2 -4
  74. package/dist/astro/chunk-R2YPGDVU.js +0 -173
  75. package/dist/astro/graphql.cjs +0 -1078
  76. package/dist/astro/graphql.d.cts +0 -300
  77. package/dist/astro/graphql.d.ts +0 -300
  78. package/dist/astro/graphql.js +0 -984
  79. package/dist/astro/index-XT_z-RYT.d.cts +0 -130
  80. package/dist/astro/index-XT_z-RYT.d.ts +0 -130
  81. package/dist/chunk-3NCEVJJ3.js +0 -10
  82. package/dist/chunk-OY7OKO6Q.js +0 -499
  83. package/dist/chunk-S5RWVMDJ.js +0 -148
  84. package/dist/graphql/codegen.cjs +0 -557
  85. package/dist/graphql/codegen.d.cts +0 -23
  86. package/dist/graphql/codegen.d.ts +0 -23
  87. package/dist/graphql/codegen.js +0 -99
  88. package/dist/graphql.cjs +0 -1020
  89. package/dist/graphql.d.cts +0 -335
  90. package/dist/graphql.d.ts +0 -335
  91. package/dist/graphql.js +0 -448
  92. package/dist/nextjs/chunk-O2SBSBDG.js +0 -549
  93. package/dist/nextjs/graphql.cjs +0 -1811
  94. package/dist/nextjs/graphql.d.cts +0 -498
  95. package/dist/nextjs/graphql.d.ts +0 -498
  96. package/dist/nextjs/graphql.js +0 -1397
  97. package/dist/nextjs/server-BL-sqZvu.d.cts +0 -156
  98. package/dist/nextjs/server-BL-sqZvu.d.ts +0 -156
  99. package/dist/nuxt/chunk-SX3MSVPK.js +0 -417
  100. package/dist/nuxt/graphql.cjs +0 -1085
  101. package/dist/nuxt/graphql.d.cts +0 -297
  102. package/dist/nuxt/graphql.d.ts +0 -297
  103. package/dist/nuxt/graphql.js +0 -985
  104. package/dist/nuxt/server-8v6OHbsw.d.cts +0 -158
  105. package/dist/nuxt/server-8v6OHbsw.d.ts +0 -158
  106. package/dist/pixel-DwW7cXJm.d.cts +0 -49
  107. package/dist/pixel-DwW7cXJm.d.ts +0 -49
  108. package/dist/server-Brr1UgtW.d.ts +0 -59
  109. package/dist/server-DJuS3YU0.d.cts +0 -59
  110. package/dist/sveltekit/chunk-UOASSHZO.js +0 -413
  111. package/dist/sveltekit/graphql.cjs +0 -1091
  112. package/dist/sveltekit/graphql.d.cts +0 -302
  113. package/dist/sveltekit/graphql.d.ts +0 -302
  114. package/dist/sveltekit/graphql.js +0 -991
  115. package/dist/sveltekit/server-CO847mEV.d.cts +0 -98
  116. package/dist/sveltekit/server-CO847mEV.d.ts +0 -98
package/dist/index.d.ts CHANGED
@@ -1,21 +1,27 @@
1
- import { b as PreprFeatures, R as ResolvedPreprFeatures, L as Locale, c as PreprSegment, d as PreprVariant, e as PreprToolbarProps, f as PreprPreviewOptions } from './types-BYH9XqmN.js';
2
- export { g as PreprEnvironment, a as PreprErrorCode, h as PreprEventType, i as PreprFeatureConfig, j as PreprHeaderName, P as PreprHeaders, k as PreprToolbarComponentProps, l as PreprToolbarOptions } from './types-BYH9XqmN.js';
3
- export { P as PreprError, e as extractAccessToken, g as getActiveSegmentFromHeaders, a as getActiveVariantFromHeaders, b as getPreprEnvironmentSegments, c as getPreprHeadersFromHeaders, d as getPreprUUIDFromHeaders, f as getToolbarPropsFromHeaders, i as isPersonalizedResponse, v as validatePreprToken } from './server-Brr1UgtW.js';
4
- export { P as PreprPixelConfig, l as loadTrackingPixel, s as setTrackingParam, t as trackEvent } from './pixel-DwW7cXJm.js';
1
+ import { P as PreprFeatures, R as ResolvedPreprFeatures, L as Locale, a as PreprSegment, b as PreprVariant, c as PreprToolbarProps, d as PreprPreviewOptions, e as PreprErrorCode, f as PreprHeaders } from './pixel-DqU7NvgW.js';
2
+ export { g as PreprEnvironment, h as PreprEventType, i as PreprFeatureConfig, j as PreprHeaderName, k as PreprPixelConfig, l as PreprToolbarComponentProps, m as PreprToolbarOptions, n as loadTrackingPixel, s as setTrackingParam, t as trackEvent } from './pixel-DqU7NvgW.js';
5
3
 
6
4
  /**
7
5
  * Package version; must match package.json. Lives in its own leaf module so
8
6
  * core can import it without cycling through the barrel.
9
7
  */
10
- declare const VERSION = "0.6.0-alpha.8";
8
+ declare const VERSION = "1.0.0-rc.1";
11
9
 
12
10
  /**
13
11
  * Resolve a `PreprFeatures` bag to plain booleans, defaulting every omitted key
14
12
  * to enabled. Shared by the toolbar and the middleware so both sides agree on
15
13
  * what a given config means.
14
+ *
15
+ * Low-level: only needed when building on `processPreprRequest` or the
16
+ * toolbar store directly.
16
17
  */
17
18
  declare function resolveFeatures(features?: PreprFeatures): ResolvedPreprFeatures;
18
19
 
20
+ /**
21
+ * Everything the toolbar shows and the preview runtime acts on. Part of the
22
+ * low-level toolbar API; a site that mounts the toolbar through
23
+ * `createPreprPreview` or a framework component never touches it.
24
+ */
19
25
  interface ToolbarState {
20
26
  locale: Locale;
21
27
  segments: PreprSegment[];
@@ -31,15 +37,21 @@ interface ToolbarState {
31
37
  */
32
38
  features: ResolvedPreprFeatures;
33
39
  }
40
+ /** Holds a `ToolbarState` and notifies subscribers of every change. */
34
41
  interface ToolbarStore {
35
42
  get(): ToolbarState;
43
+ /** Merges `patch` into the state; subscribers run only on a real change. */
36
44
  set(patch: Partial<ToolbarState>): void;
45
+ /** Returns a function that removes the subscription. */
37
46
  subscribe(fn: (s: ToolbarState) => void): () => void;
38
47
  }
39
48
  /**
40
49
  * Framework-free store for toolbar state. Deliberately pure: it holds state and
41
50
  * notifies subscribers, nothing else. Cookies, postMessage and reloads are side
42
- * effects owned by the mount controller (create-preview.ts).
51
+ * effects owned by `createPreprPreview`.
52
+ *
53
+ * Low-level: only needed to drive a `PreprToolbarElement` by hand.
54
+ * `createPreprPreview` creates and wires one for you.
43
55
  */
44
56
  declare function createToolbarStore(initial?: Partial<ToolbarState>): ToolbarStore;
45
57
 
@@ -47,11 +59,14 @@ declare function createToolbarStore(initial?: Partial<ToolbarState>): ToolbarSto
47
59
  declare function stegaClean(text: string): string;
48
60
 
49
61
  /**
50
- * Navigation seam that keeps the controller framework-free. Next.js/Astro inject
51
- * their router here; the default uses `window.location`.
62
+ * How the toolbar changes the URL when a segment or variant is picked. The
63
+ * default does a full page load through `window.location`; pass the app's
64
+ * router for a soft navigation.
52
65
  */
53
66
  interface PreprNavigationAdapter {
67
+ /** Go to `url`, a path with query string on the current origin. */
54
68
  navigate(url: string): void;
69
+ /** The current path including its query string. */
55
70
  currentPath(): string;
56
71
  /**
57
72
  * Refresh after a preview-mode toggle. Defaults to `window.location.reload()`;
@@ -59,6 +74,7 @@ interface PreprNavigationAdapter {
59
74
  */
60
75
  reload?(): void;
61
76
  }
77
+ /** Arguments of `createPreprPreview`. */
62
78
  interface CreatePreprPreviewOptions {
63
79
  /**
64
80
  * Toolbar data. Optional: a headless preview (`ui: false`) that only wants
@@ -66,14 +82,12 @@ interface CreatePreprPreviewOptions {
66
82
  */
67
83
  props?: PreprToolbarProps;
68
84
  options?: PreprPreviewOptions;
85
+ /** Defaults to full page loads through `window.location`. */
69
86
  navigation?: PreprNavigationAdapter;
70
- /**
71
- * @internal Supplied by framework wrappers so stega stripping waits until
72
- * the framework has hydrated the text it would change.
73
- */
74
- isHydrated?: (node: Text) => boolean;
75
87
  }
88
+ /** Handle on a running preview, returned by `createPreprPreview`. */
76
89
  interface PreprPreviewController {
90
+ /** Removes the toolbar and every listener the preview added. */
77
91
  destroy(): void;
78
92
  }
79
93
  /**
@@ -95,12 +109,16 @@ type Translate = (key: string) => string;
95
109
  declare const HTMLElementBase: typeof HTMLElement;
96
110
  /**
97
111
  * `<prepr-toolbar>` — the toolbar UI, in a shadow root so its CSS neither leaks
98
- * into nor is affected by the host page. Markup is Preact JSX in `panel.tsx`.
112
+ * into nor is affected by the host page.
113
+ *
114
+ * Low-level: `createPreprPreview` and the framework components create, connect
115
+ * and remove this element for you. Use it directly only to drive the toolbar
116
+ * from your own `ToolbarStore`.
99
117
  *
100
118
  * This element is the controller: it owns interaction state (listbox open,
101
119
  * keyboard nav, tooltip positioning, outside-click) and writes back ONLY via
102
- * `store.set(...)`. Cookies/postMessage/navigation belong to create-preview.ts,
103
- * which subscribes to the same store.
120
+ * `store.set(...)`. Cookies, postMessage and navigation belong to
121
+ * `createPreprPreview`, which subscribes to the same store.
104
122
  *
105
123
  * State reaches `<Panel>` as a prop rather than internal Preact state, so every
106
124
  * `render()` diffs synchronously against the shadow root.
@@ -114,6 +132,11 @@ declare class PreprToolbarElement extends HTMLElementBase {
114
132
  private readonly handlers;
115
133
  /** Idempotent: calling connect twice re-wires to the (possibly new) store. */
116
134
  connect(store: ToolbarStore, t: Translate): void;
135
+ /**
136
+ * Re-wires a toolbar that was detached and attached again, e.g. when a
137
+ * framework replaces `<body>` on navigation and the element is moved back.
138
+ */
139
+ connectedCallback(): void;
117
140
  disconnectedCallback(): void;
118
141
  private get state();
119
142
  private set;
@@ -141,20 +164,377 @@ declare class PreprToolbarElement extends HTMLElementBase {
141
164
  private searchInput;
142
165
  private chooseSegment;
143
166
  }
144
- /** Idempotent, including across bundles that each try to define the element. */
167
+ /**
168
+ * Registers the `<prepr-toolbar>` custom element. Idempotent, including across
169
+ * bundles that each try to define it. `createPreprPreview` calls it for you.
170
+ */
145
171
  declare function definePreprToolbar(): void;
146
172
 
173
+ /** Which field the editor asked the preview to bring on screen. */
174
+ interface ScrollToFieldMessage {
175
+ field: string;
176
+ id?: string;
177
+ /** Item within a list field value: the n-th `<li>` of a rich text list. */
178
+ block?: number;
179
+ /** The entry's `data-prepr-entry-id`, preferred over `field` when present. */
180
+ entryId?: string;
181
+ /**
182
+ * The same field with stack entries named by id instead of position, as
183
+ * on entries added before save, whose position changes until then.
184
+ */
185
+ fieldById?: string;
186
+ }
187
+ /** A content item the open item links to, and the field that links it. */
188
+ interface EditorReference {
189
+ id: string;
190
+ field: string;
191
+ }
192
+ /**
193
+ * An image asset used by the open item: where its field is, and the part of
194
+ * its CDN URL that identifies it whatever size the page renders it at.
195
+ */
196
+ interface EditorAsset {
197
+ key: string;
198
+ /** Field path in the editor, as stega text carries it. */
199
+ field: string;
200
+ /** The Dynamic Content entry that holds the asset. */
201
+ entryId?: string;
202
+ }
203
+ /** What the editor told the preview when the handshake completed. */
204
+ interface EditorHandshake {
205
+ /**
206
+ * The content item open in the editor. Absent when the editor does not
207
+ * send one, in which case every tagged element counts as part of it.
208
+ */
209
+ itemId?: string;
210
+ /**
211
+ * Items the open item references. Absent when the editor does not send
212
+ * them, in which case other items are not split into linked and unrelated.
213
+ */
214
+ referencedIds?: EditorReference[];
215
+ /**
216
+ * `_id`s of component instances inside the open item. Content tagged with
217
+ * one of them (`previewAttrs` on a component's image) belongs to the open
218
+ * item, not to another one.
219
+ */
220
+ componentIds?: string[];
221
+ /**
222
+ * The language of the editor's own interface. Absent when the editor does
223
+ * not send one or sends a language the toolkit has no translations for.
224
+ */
225
+ uiLocale?: Locale;
226
+ /**
227
+ * The editor asks before the preview leaves the page: navigations are
228
+ * stopped and reported as `navigation_blocked`, and
229
+ * `prepr:allowNavigation` follows one. Absent for editors that do not
230
+ * handle `navigation_blocked`.
231
+ */
232
+ navigationGuard?: boolean;
233
+ /**
234
+ * Image assets of the open item. Absent when the editor does not send
235
+ * them, in which case images are only editable where the page tags them.
236
+ */
237
+ assets?: EditorAsset[];
238
+ }
239
+ /**
240
+ * Options of the bridge between the preview and the Prepr editor that frames
241
+ * it. `createPreprPreview` runs the bridge; the type is exported for reference.
242
+ */
147
243
  interface IframeBridgeOptions {
148
244
  /**
149
245
  * Replace the `*.prepr.io` wildcard with an exact origin list. Intended for
150
- * self-hosted editors; when set, the wildcard no longer applies.
246
+ * self-hosted editors; when set, the wildcard no longer applies. `['*']`
247
+ * accepts any editor origin — see `PreprPreviewOptions.allowedEditorOrigins`.
151
248
  */
152
249
  allowedEditorOrigins?: string[];
250
+ /**
251
+ * Called when the editor selects a field and wants the preview to scroll to
252
+ * it. Only fires for messages from the handshaked editor origin. The bridge
253
+ * stays free of DOM lookups: the preview runtime supplies `scrollToField`.
254
+ */
255
+ onScrollToField?: (message: ScrollToFieldMessage) => void;
256
+ /**
257
+ * Called once the editor handshake is accepted, with the id of the content
258
+ * item open in the editor when the editor sends one. Lets the preview tell
259
+ * that item's fields apart from other items rendered on the same page
260
+ * (navigation, an author card, related posts).
261
+ */
262
+ onHandshake?: (handshake: EditorHandshake) => void;
263
+ /** The editor's reference list changed (`prepr:references`). */
264
+ onReferences?: (referencedIds: EditorReference[], componentIds?: string[]) => void;
265
+ /** The editor's asset list changed (`assets` on `prepr:references`). */
266
+ onAssets?: (assets: EditorAsset[]) => void;
267
+ /**
268
+ * The editor confirmed leaving the page for `href` after a
269
+ * `navigation_blocked` (`prepr:allowNavigation`). `href` is a non-empty
270
+ * string; its scheme is not checked here.
271
+ */
272
+ onAllowNavigation?: (href: string) => void;
273
+ /**
274
+ * The editor saved the open item (`prepr:itemChanged`), with that item's
275
+ * id. The page shows stored content from its next render on.
276
+ */
277
+ onItemChanged?: (itemId: string) => void;
153
278
  }
154
279
 
280
+ /** The field an element shows, for `previewAttrs`. */
281
+ interface PreviewAttrsTarget {
282
+ /** `_id` of the content item or component that owns the field. */
283
+ id: string | null | undefined;
284
+ /** API field name, or a dotted path below the item (`content.3`). */
285
+ field: string;
286
+ /** Locale of the rendered value, when the site knows it. */
287
+ locale?: string | null;
288
+ /** Site-side id of one entry in a list-like field (`data-prepr-entry-id`). */
289
+ entryId?: string | null;
290
+ }
291
+ /** Options of `previewAttrs`. */
292
+ interface PreviewAttrsOptions {
293
+ /**
294
+ * Whether to emit the attributes at all. Pass `true` only for preview or
295
+ * draft renders, so production HTML carries no edit metadata.
296
+ */
297
+ enabled: boolean;
298
+ }
299
+ /**
300
+ * Attributes that make an element click-to-edit in the Prepr visual editor,
301
+ * for values that carry no hidden edit link of their own: images, videos,
302
+ * anything rendered from a URL. Spread them onto the element that renders
303
+ * the field:
304
+ *
305
+ * ```tsx
306
+ * <figure {...previewAttrs({ id: post._id, field: 'cover_image' }, { enabled: isPreview })}>
307
+ * ```
308
+ *
309
+ * Returns an empty object when disabled or when there is no target or id, so
310
+ * it is safe to spread unconditionally.
311
+ */
312
+ declare function previewAttrs(target: PreviewAttrsTarget | null | undefined, options: PreviewAttrsOptions): Record<string, string>;
313
+ /** Options of `stegaTarget`. */
314
+ interface StegaTargetOptions {
315
+ /**
316
+ * A field next to the encoded one, in the same item or component, to target
317
+ * instead: a dotted path that replaces the encoded field's last segment
318
+ * (`products`, or `products.items.2` for one entry of it).
319
+ */
320
+ field?: string;
321
+ }
322
+ /**
323
+ * The edit target behind a text value Prepr returned with a hidden edit link,
324
+ * for {@link previewAttrs}. Reach for it when the field to edit carries no
325
+ * link of its own, such as remote content or a list of references, but a
326
+ * text field of the same component does: the component's title points the
327
+ * way to its `products`.
328
+ *
329
+ * ```tsx
330
+ * const products = stegaTarget(block.title, { field: 'products' });
331
+ * <article {...previewAttrs(products, { enabled: isPreview })}>
332
+ * ```
333
+ *
334
+ * Returns null for a value without an edit link (a production render, or a
335
+ * value Prepr does not encode). Works on the server and in the browser.
336
+ */
337
+ declare function stegaTarget(value: string | null | undefined, options?: StegaTargetOptions): PreviewAttrsTarget | null;
338
+
339
+ /** Values a push may write. Everything else goes through refetch. */
340
+ type LiveScalar = string | number | boolean;
341
+ /** A structured field value, such as an asset. */
342
+ interface LiveObject {
343
+ [key: string]: LiveScalar | null | LiveObject;
344
+ }
345
+ /** Anything a `prepr:fieldChange` may carry. */
346
+ type LiveValue = LiveScalar | null | LiveObject | LiveObject[];
347
+ /** One entry of a `prepr:listChange`, in the editor's order. */
348
+ interface LiveListEntry {
349
+ /** Stored id, or a temporary `tmp:` id for an entry added before save. */
350
+ _id: string;
351
+ __typename?: string;
352
+ /** Text entries only. */
353
+ body?: string;
354
+ format?: string | null;
355
+ /** A new entry's type as the editor names it (`Side by side`). */
356
+ typeName?: string;
357
+ /** A new entry's field values, shaped as the API returns them. */
358
+ fields?: Record<string, unknown>;
359
+ }
360
+
361
+ /** The open item and a field path in the editor's id-based convention. */
362
+ interface LiveEditTarget {
363
+ item: string;
364
+ field: string;
365
+ }
366
+
367
+ /**
368
+ * One unsaved change from the Prepr editor: the `_id` of the item (or stack
369
+ * entry) that owns the field, and the field's API name or a dotted path below
370
+ * it (`content.headline_style`, `content.3.body`).
371
+ */
372
+ type LivePatch = {
373
+ type: 'field';
374
+ itemId: string;
375
+ field: string;
376
+ value: LiveValue;
377
+ /** Edit-link target for text that has none yet (an unsaved entry). */
378
+ edit?: LiveEditTarget;
379
+ } | {
380
+ type: 'list';
381
+ itemId: string;
382
+ field: string;
383
+ entries: LiveListEntry[];
384
+ };
385
+ /**
386
+ * Validate a patch log from an untrusted source (a request body, a cookie).
387
+ * Accepts the array or its JSON text, drops malformed entries, never throws.
388
+ */
389
+ declare function parsePatchLog(raw: unknown): LivePatch[];
390
+
391
+ /**
392
+ * What `normalizeQuery` accepts as the query: GraphQL source text, a parsed
393
+ * `DocumentNode` (from `graphql-tag`, Apollo or GraphQL Code Generator), or a
394
+ * string-like object such as codegen's `TypedDocumentString`.
395
+ */
396
+ type QueryInput = string | {
397
+ kind: 'Document';
398
+ } | {
399
+ toString(): string;
400
+ };
401
+
402
+ /** Options of `normalizeQuery`. */
403
+ interface NormalizeQueryOptions {
404
+ /**
405
+ * The editor's unsaved changes, oldest first. Treated as hostile: malformed
406
+ * entries are dropped.
407
+ */
408
+ log?: unknown;
409
+ /** Which operation to use when the document holds more than one. */
410
+ operationName?: string;
411
+ }
412
+ /**
413
+ * Apply the Prepr editor's unsaved changes to a GraphQL result, so the page
414
+ * renders them before the editor saves. Pass the query that produced the
415
+ * result (`{ data }` or just `data`):
416
+ *
417
+ * ```ts
418
+ * const page = normalizeQuery(GetPageDocument, data, { log });
419
+ * ```
420
+ *
421
+ * The query maps fields to response keys, so changes land under aliases and
422
+ * on every place the same item appears; fields not in the query are left
423
+ * alone. Select `_id` on every item and component that should update.
424
+ * Without a log the query is not parsed and the result is returned as-is.
425
+ * Never throws.
426
+ */
427
+ declare function normalizeQuery<T>(query: QueryInput, result: T, options?: NormalizeQueryOptions): T;
428
+
429
+ /**
430
+ * Adds the list entry each piece of text belongs to (a dynamic content
431
+ * entry, a repeated component) to its hidden edit link, so the visual editor
432
+ * can find the entry by id without `data-prepr-entry-id` on the page. A
433
+ * `Text` entry's link, which names no field, also gets the entry's field
434
+ * path, so `data-prepr-edit-target` is not needed to name it.
435
+ *
436
+ * Needs `_id` on the entries. Returns the result itself when nothing
437
+ * changed. Pass the query to name fields by their API name under aliases.
438
+ */
439
+ declare function annotateEditLinks<T>(result: T, query?: QueryInput, operationName?: string): T;
440
+
441
+ /** Options of `startHtmlLivePreview`. */
442
+ interface HtmlLivePreviewOptions {
443
+ /**
444
+ * Replace the `*.prepr.io` editor-origin wildcard with an exact list, as
445
+ * the toolbar's option of the same name.
446
+ */
447
+ allowedEditorOrigins?: string[];
448
+ /** See the toolbar's `strictMode`. */
449
+ strictMode?: boolean;
450
+ }
451
+ /** Handle on a running HTML live preview. */
452
+ interface HtmlLivePreview {
453
+ /** Stops listening to the editor; the page keeps its current content. */
454
+ stop(): void;
455
+ }
456
+ /**
457
+ * Live preview for server-rendered pages without a client framework (Astro,
458
+ * or any HTML-first site): while an editor types, the page is requested
459
+ * again from the server with the unsaved changes in the request body, and
460
+ * only the parts of the DOM that changed are updated. On save the page is
461
+ * requested without changes. The server applies them with `normalizeQuery`;
462
+ * see `readLiveLogFromRequest`.
463
+ *
464
+ * A no-op outside the Prepr editor's preview iframe.
465
+ */
466
+ declare function startHtmlLivePreview(options?: HtmlLivePreviewOptions): HtmlLivePreview;
467
+
468
+ /**
469
+ * The editor's unsaved changes carried by a live-preview re-render request
470
+ * (sent by `startHtmlLivePreview`), or an empty list for any other request.
471
+ *
472
+ * Accepted only from a same-origin `POST` with the live-preview header and a
473
+ * JSON body, so a link, a form on another site or a cacheable `GET` can never
474
+ * inject changes. Call it only when the site runs in preview, and mark the
475
+ * response uncacheable (`Cache-Control: private, no-store`) whenever it
476
+ * returns changes. Never throws.
477
+ */
478
+ declare function readLiveLogFromRequest(request: Request): Promise<LivePatch[]>;
479
+
480
+ /** Error thrown by the token helpers and the segments fetch. */
481
+ declare class PreprError extends Error {
482
+ readonly code: PreprErrorCode;
483
+ readonly context?: string | undefined;
484
+ readonly originalError?: Error | undefined;
485
+ constructor(message: string, code: PreprErrorCode, context?: string | undefined, originalError?: Error | undefined);
486
+ }
487
+ /** Prepr Customer ID, or null if the middleware did not run for this request. */
488
+ declare function getPreprUUIDFromHeaders(headers: Headers): string | null;
489
+ /** Active segment ID, or null when no segment is selected. */
490
+ declare function getActiveSegmentFromHeaders(headers: Headers): string | null;
491
+ /** Active A/B variant (`'A'`/`'B'`), or null when no test is running. */
492
+ declare function getActiveVariantFromHeaders(headers: Headers): string | null;
493
+ /**
494
+ * Collect the Prepr headers into a `PreprHeaders`. Lookups are case-insensitive
495
+ * per the Fetch spec, but the returned keys use the declared casing.
496
+ */
497
+ declare function getPreprHeadersFromHeaders(headers: Headers): PreprHeaders;
498
+ /**
499
+ * Asserts `token` is the full `https://graphql.prepr.io/<token>` URL.
500
+ * @throws PreprError if the token is missing or not an HTTPS URL.
501
+ */
502
+ declare function validatePreprToken(token: string): void;
503
+ /**
504
+ * Pulls the access token out of a GraphQL URL: `https://graphql.prepr.io/abc123`
505
+ * -> `abc123`.
506
+ * @throws PreprError if the URL is not a valid `graphql.prepr.io` URL.
507
+ */
508
+ declare function extractAccessToken(graphqlUrl: string): string;
509
+ /**
510
+ * Fetches the environment's segments from the Prepr API.
511
+ *
512
+ * `token` must be a Prepr GraphQL URL with scope 'segments'.
513
+ * @throws PreprError if the token is invalid or the request fails.
514
+ */
515
+ declare function getPreprEnvironmentSegments(token: string): Promise<PreprSegment[]>;
516
+ /**
517
+ * Never throws: a failed segments fetch yields an empty list so the toolbar
518
+ * still renders. The list is returned under both `segments` and the deprecated
519
+ * `data` alias.
520
+ *
521
+ * Pass the same `features` object you give the toolbar and the middleware: with
522
+ * segments disabled the `_Segments` request is skipped entirely, saving a
523
+ * round-trip per page.
524
+ */
525
+ declare function getToolbarPropsFromHeaders(headers: Headers, token: string, features?: PreprFeatures): Promise<PreprToolbarProps>;
526
+
527
+ /**
528
+ * A cookie the Prepr middleware wants set on the response. The framework
529
+ * wrappers write these for you; with `processPreprRequest` you write them
530
+ * yourself, and must carry over `sameSite` and `secure` or the preview cookies
531
+ * are dropped inside the Prepr editor's iframe.
532
+ */
155
533
  interface CookieSpec {
156
534
  name: string;
535
+ /** Unencoded; apply `encodeURIComponent` when writing the header. */
157
536
  value: string;
537
+ /** Lifetime in seconds. */
158
538
  maxAge: number;
159
539
  path: string;
160
540
  /**
@@ -167,10 +547,14 @@ interface CookieSpec {
167
547
  /** Adds `Secure`. Required by browsers alongside `SameSite=None`. */
168
548
  secure?: boolean;
169
549
  }
550
+ /** What `processPreprRequest` computed for one request. */
170
551
  interface PreprMiddlewareResult {
552
+ /** The request's headers plus the Prepr headers; forward these downstream. */
171
553
  requestHeaders: Headers;
554
+ /** Cookies to set on the response. */
172
555
  responseCookies: CookieSpec[];
173
556
  }
557
+ /** Options for the Prepr middleware of every framework. */
174
558
  interface PreprMiddlewareOptions {
175
559
  /** Enable preview-mode headers (segment/AB overrides, preview bar). */
176
560
  preview?: boolean;
@@ -190,4 +574,4 @@ interface PreprMiddlewareOptions {
190
574
  */
191
575
  declare function processPreprRequest(request: Request, opts?: PreprMiddlewareOptions): PreprMiddlewareResult;
192
576
 
193
- export { type CookieSpec, type CreatePreprPreviewOptions, type IframeBridgeOptions, PreprFeatures, type PreprMiddlewareOptions, type PreprMiddlewareResult, type PreprNavigationAdapter, type PreprPreviewController, PreprPreviewOptions, PreprSegment, PreprToolbarElement, PreprToolbarProps, PreprVariant, ResolvedPreprFeatures, type ToolbarState, type ToolbarStore, VERSION, createPreprPreview, createToolbarStore, definePreprToolbar, processPreprRequest, resolveFeatures, stegaClean };
577
+ export { type CookieSpec, type CreatePreprPreviewOptions, type EditorAsset, type EditorHandshake, type EditorReference, type HtmlLivePreview, type HtmlLivePreviewOptions, type IframeBridgeOptions, type LiveEditTarget, type LiveListEntry, type LiveObject, type LivePatch, type LiveScalar, type LiveValue, Locale, type NormalizeQueryOptions, PreprError, PreprErrorCode, PreprFeatures, PreprHeaders, type PreprMiddlewareOptions, type PreprMiddlewareResult, type PreprNavigationAdapter, type PreprPreviewController, PreprPreviewOptions, PreprSegment, PreprToolbarElement, PreprToolbarProps, PreprVariant, type PreviewAttrsOptions, type PreviewAttrsTarget, type QueryInput, ResolvedPreprFeatures, type ScrollToFieldMessage, type StegaTargetOptions, type ToolbarState, type ToolbarStore, VERSION, annotateEditLinks, createPreprPreview, createToolbarStore, definePreprToolbar, extractAccessToken, getActiveSegmentFromHeaders, getActiveVariantFromHeaders, getPreprEnvironmentSegments, getPreprHeadersFromHeaders, getPreprUUIDFromHeaders, getToolbarPropsFromHeaders, normalizeQuery, parsePatchLog, previewAttrs, processPreprRequest, readLiveLogFromRequest, resolveFeatures, startHtmlLivePreview, stegaClean, stegaTarget, validatePreprToken };