@preprio/toolkit 0.5.0-rc.1 → 0.5.0-rc.3

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 (50) hide show
  1. package/README.md +207 -10
  2. package/dist/astro/index.cjs +1174 -1
  3. package/dist/astro/index.d.cts +47 -1
  4. package/dist/astro/index.d.ts +47 -1
  5. package/dist/astro/index.js +1177 -1
  6. package/dist/chunk-42Z2VW7G.js +1161 -0
  7. package/dist/chunk-6WY3MWCX.js +246 -0
  8. package/dist/chunk-MDAV2FLM.js +26 -0
  9. package/dist/{chunk-4JNKYIEV.js → chunk-PP3O7RB4.js} +1370 -617
  10. package/dist/chunk-S3VT4UWM.js +75 -0
  11. package/dist/chunk-SXUDBGLZ.js +184 -0
  12. package/dist/chunk-URXSDJOU.js +356 -0
  13. package/dist/index.cjs +3113 -391
  14. package/dist/index.d.cts +240 -5
  15. package/dist/index.d.ts +240 -5
  16. package/dist/index.js +189 -149
  17. package/dist/live-preview-EADA3ZL4.js +18 -0
  18. package/dist/nextjs/components.cjs +1530 -361
  19. package/dist/nextjs/components.d.cts +1 -1
  20. package/dist/nextjs/components.d.ts +1 -1
  21. package/dist/nextjs/components.js +4 -1
  22. package/dist/nextjs/index.cjs +1065 -6
  23. package/dist/nextjs/index.d.cts +81 -3
  24. package/dist/nextjs/index.d.ts +81 -3
  25. package/dist/nextjs/index.js +1059 -7
  26. package/dist/nextjs/live-action.cjs +285 -0
  27. package/dist/nextjs/live-action.d.cts +12 -0
  28. package/dist/nextjs/live-action.d.ts +12 -0
  29. package/dist/nextjs/live-action.js +68 -0
  30. package/dist/nextjs/live.cjs +1838 -0
  31. package/dist/nextjs/live.d.cts +52 -0
  32. package/dist/nextjs/live.d.ts +52 -0
  33. package/dist/nextjs/live.js +265 -0
  34. package/dist/nuxt/index.cjs +1 -1
  35. package/dist/nuxt/index.js +1 -1
  36. package/dist/nuxt/live-preview-PTEC3GPC.js +1462 -0
  37. package/dist/nuxt/live.cjs +1662 -0
  38. package/dist/nuxt/live.d.cts +43 -0
  39. package/dist/nuxt/live.d.ts +43 -0
  40. package/dist/nuxt/live.js +94 -0
  41. package/dist/{pixel-e1fUWl2Y.d.cts → pixel-CX422dCO.d.cts} +18 -3
  42. package/dist/{pixel-e1fUWl2Y.d.ts → pixel-CX422dCO.d.ts} +18 -3
  43. package/dist/react/components.cjs +1530 -361
  44. package/dist/react/components.d.cts +17 -2
  45. package/dist/react/components.d.ts +17 -2
  46. package/dist/react/components.js +1530 -361
  47. package/dist/sveltekit/index.cjs +1 -1
  48. package/dist/sveltekit/index.js +1 -1
  49. package/package.json +12 -1
  50. package/src/astro/PreprToolbar.astro +7 -1
@@ -4,6 +4,8 @@ type Dictionary = Record<string, unknown>;
4
4
  declare const dictionaries: {
5
5
  en: Dictionary;
6
6
  nl: Dictionary;
7
+ fr: Dictionary;
8
+ de: Dictionary;
7
9
  };
8
10
  type Locale = keyof typeof dictionaries;
9
11
 
@@ -60,10 +62,23 @@ interface PreprPreviewOptions extends PreprToolbarOptions {
60
62
  */
61
63
  ui?: boolean;
62
64
  /**
63
- * Replace the `*.prepr.io` editor-origin wildcard with an exact list.
64
- * Intended for self-hosted editors; when set, the wildcard no longer applies.
65
+ * Replace the `*.prepr.io` editor-origin wildcard with an exact list, e.g.
66
+ * `['http://acme.localhost:8000']`. Intended for self-hosted or locally run
67
+ * editors; when set, the wildcard no longer applies. Entries are compared to
68
+ * the editor's origin exactly: scheme, host and port.
69
+ *
70
+ * `['*']` accepts any editor origin. Use it for development only: any page
71
+ * that frames the preview can then switch on preview and edit mode and
72
+ * receives the field-edit events, which carry content item ids.
65
73
  */
66
74
  allowedEditorOrigins?: string[];
75
+ /**
76
+ * Set when your preview token uses GraphQL strict mode, where required
77
+ * fields are never null. The editor then holds back new entries until
78
+ * their required fields are filled, and never sends a cleared required
79
+ * field as null.
80
+ */
81
+ strictMode?: boolean;
67
82
  /**
68
83
  * Strip the invisible stega characters out of visible text at runtime.
69
84
  * Default `true`.
@@ -148,6 +163,17 @@ interface PreprMiddlewareOptions {
148
163
  declare function createPreprMiddleware(request: NextRequest, options?: PreprMiddlewareOptions): NextResponse;
149
164
  declare function createPreprMiddleware(request: NextRequest, response: NextResponse, options?: PreprMiddlewareOptions): NextResponse;
150
165
 
166
+ /**
167
+ * What `normalizeQuery` accepts as the query: GraphQL source text, a parsed
168
+ * `DocumentNode` (from `graphql-tag`, Apollo or GraphQL Code Generator), or a
169
+ * string-like object such as codegen's `TypedDocumentString`.
170
+ */
171
+ type QueryInput = string | {
172
+ kind: 'Document';
173
+ } | {
174
+ toString(): string;
175
+ };
176
+
151
177
  /** Prepr Customer ID for the current request. Server-only. */
152
178
  declare function getPreprUUID(): Promise<string | null>;
153
179
  /** Active segment for the current request. Server-only. */
@@ -168,6 +194,28 @@ declare function getPreprHeaders(): Promise<PreprHeaders>;
168
194
  * bad or missing token can't crash the host app.
169
195
  */
170
196
  declare function getToolbarProps(token: string, features?: PreprFeatures): Promise<PreprToolbarProps>;
197
+ interface NextNormalizeQueryOptions {
198
+ /**
199
+ * Pass the same preview flag as the middleware; never `true` on a
200
+ * production deployment. When false (the default) the request is not read,
201
+ * so static and ISR pages stay static.
202
+ */
203
+ enabled?: boolean;
204
+ /** Which operation to use when the document holds more than one. */
205
+ operationName?: string;
206
+ }
207
+ /**
208
+ * Show the Prepr editor's unsaved changes in server components: pass the
209
+ * query and its result, and render what comes back.
210
+ *
211
+ * ```ts
212
+ * const page = await normalizeQuery(GetPageDocument, data, { enabled: isPreview });
213
+ * ```
214
+ *
215
+ * Needs `PreprRefresh` mounted, and `_id` selected on every item and
216
+ * component that should update. Server-only; Next.js 16+.
217
+ */
218
+ declare function normalizeQuery<T>(query: QueryInput, result: T, options?: NextNormalizeQueryOptions): Promise<T>;
171
219
 
172
220
  /** Error thrown by the token helpers and the segments fetch. */
173
221
  declare class PreprError extends Error {
@@ -242,4 +290,34 @@ declare function PreprTrackingPixel({ id, config, }: PreprTrackingPixelProps): n
242
290
  */
243
291
  declare function PreprToolbar({ options, ...props }: PreprToolbarComponentProps): null;
244
292
 
245
- export { PreprError, type PreprMiddlewareOptions, PreprToolbar, PreprTrackingPixel, type PreprTrackingPixelProps, createPreprMiddleware, extractAccessToken, getActiveSegment, getActiveVariant, getPreprHeaders, getPreprUUID, getToolbarProps, validatePreprToken };
293
+ /** Executes a registered query. `query` is opaque — string or DocumentNode. */
294
+ interface LiveFetcher {
295
+ (query: unknown, variables?: Record<string, unknown>): Promise<unknown>;
296
+ }
297
+
298
+ interface LivePreviewConfig {
299
+ /**
300
+ * Pass your preview flag; never `true` on a production deployment.
301
+ * Defaults to false: nothing starts and `useLive` is a passthrough.
302
+ */
303
+ enabled?: boolean;
304
+ /** Runs registered queries against Prepr GraphQL in preview mode. */
305
+ fetcher?: LiveFetcher;
306
+ /** Exact editor origins, replacing the `*.prepr.io` default. */
307
+ allowedEditorOrigins?: string[];
308
+ /** Your preview token uses GraphQL strict mode; see the toolbar option. */
309
+ strictMode?: boolean;
310
+ }
311
+ interface PreprRefreshProps {
312
+ /** Pass your preview flag; never `true` on a production deployment. */
313
+ enabled?: boolean;
314
+ /** Your preview token uses GraphQL strict mode; see the toolbar option. */
315
+ strictMode?: boolean;
316
+ }
317
+ interface UseLiveOptions {
318
+ /** Query (string or DocumentNode) passed as-is to the fetcher. */
319
+ query?: unknown;
320
+ variables?: Record<string, unknown>;
321
+ }
322
+
323
+ export { type LiveFetcher, type LivePreviewConfig, type NextNormalizeQueryOptions, PreprError, type PreprMiddlewareOptions, type PreprRefreshProps, PreprToolbar, PreprTrackingPixel, type PreprTrackingPixelProps, type UseLiveOptions, createPreprMiddleware, extractAccessToken, getActiveSegment, getActiveVariant, getPreprHeaders, getPreprUUID, getToolbarProps, normalizeQuery, validatePreprToken };
@@ -4,6 +4,8 @@ type Dictionary = Record<string, unknown>;
4
4
  declare const dictionaries: {
5
5
  en: Dictionary;
6
6
  nl: Dictionary;
7
+ fr: Dictionary;
8
+ de: Dictionary;
7
9
  };
8
10
  type Locale = keyof typeof dictionaries;
9
11
 
@@ -60,10 +62,23 @@ interface PreprPreviewOptions extends PreprToolbarOptions {
60
62
  */
61
63
  ui?: boolean;
62
64
  /**
63
- * Replace the `*.prepr.io` editor-origin wildcard with an exact list.
64
- * Intended for self-hosted editors; when set, the wildcard no longer applies.
65
+ * Replace the `*.prepr.io` editor-origin wildcard with an exact list, e.g.
66
+ * `['http://acme.localhost:8000']`. Intended for self-hosted or locally run
67
+ * editors; when set, the wildcard no longer applies. Entries are compared to
68
+ * the editor's origin exactly: scheme, host and port.
69
+ *
70
+ * `['*']` accepts any editor origin. Use it for development only: any page
71
+ * that frames the preview can then switch on preview and edit mode and
72
+ * receives the field-edit events, which carry content item ids.
65
73
  */
66
74
  allowedEditorOrigins?: string[];
75
+ /**
76
+ * Set when your preview token uses GraphQL strict mode, where required
77
+ * fields are never null. The editor then holds back new entries until
78
+ * their required fields are filled, and never sends a cleared required
79
+ * field as null.
80
+ */
81
+ strictMode?: boolean;
67
82
  /**
68
83
  * Strip the invisible stega characters out of visible text at runtime.
69
84
  * Default `true`.
@@ -148,6 +163,17 @@ interface PreprMiddlewareOptions {
148
163
  declare function createPreprMiddleware(request: NextRequest, options?: PreprMiddlewareOptions): NextResponse;
149
164
  declare function createPreprMiddleware(request: NextRequest, response: NextResponse, options?: PreprMiddlewareOptions): NextResponse;
150
165
 
166
+ /**
167
+ * What `normalizeQuery` accepts as the query: GraphQL source text, a parsed
168
+ * `DocumentNode` (from `graphql-tag`, Apollo or GraphQL Code Generator), or a
169
+ * string-like object such as codegen's `TypedDocumentString`.
170
+ */
171
+ type QueryInput = string | {
172
+ kind: 'Document';
173
+ } | {
174
+ toString(): string;
175
+ };
176
+
151
177
  /** Prepr Customer ID for the current request. Server-only. */
152
178
  declare function getPreprUUID(): Promise<string | null>;
153
179
  /** Active segment for the current request. Server-only. */
@@ -168,6 +194,28 @@ declare function getPreprHeaders(): Promise<PreprHeaders>;
168
194
  * bad or missing token can't crash the host app.
169
195
  */
170
196
  declare function getToolbarProps(token: string, features?: PreprFeatures): Promise<PreprToolbarProps>;
197
+ interface NextNormalizeQueryOptions {
198
+ /**
199
+ * Pass the same preview flag as the middleware; never `true` on a
200
+ * production deployment. When false (the default) the request is not read,
201
+ * so static and ISR pages stay static.
202
+ */
203
+ enabled?: boolean;
204
+ /** Which operation to use when the document holds more than one. */
205
+ operationName?: string;
206
+ }
207
+ /**
208
+ * Show the Prepr editor's unsaved changes in server components: pass the
209
+ * query and its result, and render what comes back.
210
+ *
211
+ * ```ts
212
+ * const page = await normalizeQuery(GetPageDocument, data, { enabled: isPreview });
213
+ * ```
214
+ *
215
+ * Needs `PreprRefresh` mounted, and `_id` selected on every item and
216
+ * component that should update. Server-only; Next.js 16+.
217
+ */
218
+ declare function normalizeQuery<T>(query: QueryInput, result: T, options?: NextNormalizeQueryOptions): Promise<T>;
171
219
 
172
220
  /** Error thrown by the token helpers and the segments fetch. */
173
221
  declare class PreprError extends Error {
@@ -242,4 +290,34 @@ declare function PreprTrackingPixel({ id, config, }: PreprTrackingPixelProps): n
242
290
  */
243
291
  declare function PreprToolbar({ options, ...props }: PreprToolbarComponentProps): null;
244
292
 
245
- export { PreprError, type PreprMiddlewareOptions, PreprToolbar, PreprTrackingPixel, type PreprTrackingPixelProps, createPreprMiddleware, extractAccessToken, getActiveSegment, getActiveVariant, getPreprHeaders, getPreprUUID, getToolbarProps, validatePreprToken };
293
+ /** Executes a registered query. `query` is opaque — string or DocumentNode. */
294
+ interface LiveFetcher {
295
+ (query: unknown, variables?: Record<string, unknown>): Promise<unknown>;
296
+ }
297
+
298
+ interface LivePreviewConfig {
299
+ /**
300
+ * Pass your preview flag; never `true` on a production deployment.
301
+ * Defaults to false: nothing starts and `useLive` is a passthrough.
302
+ */
303
+ enabled?: boolean;
304
+ /** Runs registered queries against Prepr GraphQL in preview mode. */
305
+ fetcher?: LiveFetcher;
306
+ /** Exact editor origins, replacing the `*.prepr.io` default. */
307
+ allowedEditorOrigins?: string[];
308
+ /** Your preview token uses GraphQL strict mode; see the toolbar option. */
309
+ strictMode?: boolean;
310
+ }
311
+ interface PreprRefreshProps {
312
+ /** Pass your preview flag; never `true` on a production deployment. */
313
+ enabled?: boolean;
314
+ /** Your preview token uses GraphQL strict mode; see the toolbar option. */
315
+ strictMode?: boolean;
316
+ }
317
+ interface UseLiveOptions {
318
+ /** Query (string or DocumentNode) passed as-is to the fetcher. */
319
+ query?: unknown;
320
+ variables?: Record<string, unknown>;
321
+ }
322
+
323
+ export { type LiveFetcher, type LivePreviewConfig, type NextNormalizeQueryOptions, PreprError, type PreprMiddlewareOptions, type PreprRefreshProps, PreprToolbar, PreprTrackingPixel, type PreprTrackingPixelProps, type UseLiveOptions, createPreprMiddleware, extractAccessToken, getActiveSegment, getActiveVariant, getPreprHeaders, getPreprUUID, getToolbarProps, normalizeQuery, validatePreprToken };