@preprio/toolkit 0.5.0-rc.2 → 0.5.0-rc.4

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 +209 -10
  2. package/dist/astro/index.cjs +1194 -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 +1197 -1
  6. package/dist/chunk-46ISDRHT.js +26 -0
  7. package/dist/chunk-74KY5EAM.js +1219 -0
  8. package/dist/chunk-AHBN6FQP.js +184 -0
  9. package/dist/{chunk-FLPNN3CV.js → chunk-PDNCNTDB.js} +1370 -623
  10. package/dist/chunk-S3VT4UWM.js +75 -0
  11. package/dist/chunk-TG6N3C22.js +246 -0
  12. package/dist/chunk-URXSDJOU.js +356 -0
  13. package/dist/index.cjs +3166 -392
  14. package/dist/index.d.cts +238 -4
  15. package/dist/index.d.ts +238 -4
  16. package/dist/index.js +189 -149
  17. package/dist/live-preview-H4643QYF.js +18 -0
  18. package/dist/nextjs/components.cjs +1522 -359
  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 +1085 -6
  23. package/dist/nextjs/index.d.cts +73 -1
  24. package/dist/nextjs/index.d.ts +73 -1
  25. package/dist/nextjs/index.js +1079 -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 +1896 -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-O2ZTJNW4.js +1520 -0
  37. package/dist/nuxt/live.cjs +1720 -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-B3oQNbZ3.d.cts → pixel-CX422dCO.d.cts} +10 -1
  42. package/dist/{pixel-B3oQNbZ3.d.ts → pixel-CX422dCO.d.ts} +10 -1
  43. package/dist/react/components.cjs +1522 -359
  44. package/dist/react/components.d.cts +9 -0
  45. package/dist/react/components.d.ts +9 -0
  46. package/dist/react/components.js +1522 -359
  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
 
@@ -70,6 +72,13 @@ interface PreprPreviewOptions extends PreprToolbarOptions {
70
72
  * receives the field-edit events, which carry content item ids.
71
73
  */
72
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;
73
82
  /**
74
83
  * Strip the invisible stega characters out of visible text at runtime.
75
84
  * Default `true`.
@@ -154,6 +163,17 @@ interface PreprMiddlewareOptions {
154
163
  declare function createPreprMiddleware(request: NextRequest, options?: PreprMiddlewareOptions): NextResponse;
155
164
  declare function createPreprMiddleware(request: NextRequest, response: NextResponse, options?: PreprMiddlewareOptions): NextResponse;
156
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
+
157
177
  /** Prepr Customer ID for the current request. Server-only. */
158
178
  declare function getPreprUUID(): Promise<string | null>;
159
179
  /** Active segment for the current request. Server-only. */
@@ -174,6 +194,28 @@ declare function getPreprHeaders(): Promise<PreprHeaders>;
174
194
  * bad or missing token can't crash the host app.
175
195
  */
176
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>;
177
219
 
178
220
  /** Error thrown by the token helpers and the segments fetch. */
179
221
  declare class PreprError extends Error {
@@ -248,4 +290,34 @@ declare function PreprTrackingPixel({ id, config, }: PreprTrackingPixelProps): n
248
290
  */
249
291
  declare function PreprToolbar({ options, ...props }: PreprToolbarComponentProps): null;
250
292
 
251
- 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
 
@@ -70,6 +72,13 @@ interface PreprPreviewOptions extends PreprToolbarOptions {
70
72
  * receives the field-edit events, which carry content item ids.
71
73
  */
72
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;
73
82
  /**
74
83
  * Strip the invisible stega characters out of visible text at runtime.
75
84
  * Default `true`.
@@ -154,6 +163,17 @@ interface PreprMiddlewareOptions {
154
163
  declare function createPreprMiddleware(request: NextRequest, options?: PreprMiddlewareOptions): NextResponse;
155
164
  declare function createPreprMiddleware(request: NextRequest, response: NextResponse, options?: PreprMiddlewareOptions): NextResponse;
156
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
+
157
177
  /** Prepr Customer ID for the current request. Server-only. */
158
178
  declare function getPreprUUID(): Promise<string | null>;
159
179
  /** Active segment for the current request. Server-only. */
@@ -174,6 +194,28 @@ declare function getPreprHeaders(): Promise<PreprHeaders>;
174
194
  * bad or missing token can't crash the host app.
175
195
  */
176
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>;
177
219
 
178
220
  /** Error thrown by the token helpers and the segments fetch. */
179
221
  declare class PreprError extends Error {
@@ -248,4 +290,34 @@ declare function PreprTrackingPixel({ id, config, }: PreprTrackingPixelProps): n
248
290
  */
249
291
  declare function PreprToolbar({ options, ...props }: PreprToolbarComponentProps): null;
250
292
 
251
- 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 };