@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
@@ -79,6 +79,17 @@ interface PreprMiddlewareOptions {
79
79
  version?: string;
80
80
  }
81
81
 
82
+ /**
83
+ * What `normalizeQuery` accepts as the query: GraphQL source text, a parsed
84
+ * `DocumentNode` (from `graphql-tag`, Apollo or GraphQL Code Generator), or a
85
+ * string-like object such as codegen's `TypedDocumentString`.
86
+ */
87
+ type QueryInput = string | {
88
+ kind: 'Document';
89
+ } | {
90
+ toString(): string;
91
+ };
92
+
82
93
  /**
83
94
  * Structural stand-in for Astro's `APIContext`, so this package needs no
84
95
  * build-time dependency on `astro`. Only the fields `onPreprRequest` uses.
@@ -87,6 +98,8 @@ interface AstroLikeContext {
87
98
  request: Request;
88
99
  /** Unused; typed loosely so passing the real Astro context still checks. */
89
100
  cookies?: unknown;
101
+ /** Per-request storage; carries the editor's unsaved changes in preview. */
102
+ locals?: object;
90
103
  }
91
104
  /** Astro middleware's `next()` — resolves to the `Response` from downstream. */
92
105
  type AstroNext = () => Promise<Response>;
@@ -116,5 +129,38 @@ declare function getPreprHeaders(headers: Headers): PreprHeaders;
116
129
  * its own.
117
130
  */
118
131
  declare function getToolbarProps(headers: Headers, token: string, features?: PreprFeatures): Promise<PreprToolbarProps>;
132
+ interface AstroNormalizeQueryOptions {
133
+ /**
134
+ * Whether this render may show unsaved editor changes. Pass your preview
135
+ * flag, and never `true` on a production deployment. When false (the
136
+ * default) the result is returned untouched.
137
+ */
138
+ enabled?: boolean;
139
+ /** `Astro.locals`, where `onPreprRequest` leaves the editor's changes. */
140
+ locals?: object;
141
+ /** Which operation to use when the document holds more than one. */
142
+ operationName?: string;
143
+ }
144
+ /**
145
+ * Show the Prepr editor's unsaved changes on a server-rendered Astro page:
146
+ * pass the query and the result you fetched (with any client), and render
147
+ * what comes back.
148
+ *
149
+ * ```astro
150
+ * ---
151
+ * const data = await fetchFromPrepr(GetPageDocument, { slug });
152
+ * const page = normalizeQuery(GetPageDocument, data, {
153
+ * enabled: preview,
154
+ * locals: Astro.locals,
155
+ * });
156
+ * ---
157
+ * ```
158
+ *
159
+ * Needs `onPreprRequest` with `preview: true` in your middleware and
160
+ * `PreprToolbar.astro` on the page; the toolbar re-requests the page with
161
+ * the editor's changes while they type. Select `_id` on every item and
162
+ * component that should update.
163
+ */
164
+ declare function normalizeQuery<T>(query: QueryInput, result: T, options?: AstroNormalizeQueryOptions): T;
119
165
 
120
- export { type AstroLikeContext, type AstroNext, type PreprMiddlewareOptions, getActiveSegment, getActiveVariant, getPreprHeaders, getPreprUUID, getToolbarProps, onPreprRequest };
166
+ export { type AstroLikeContext, type AstroNext, type AstroNormalizeQueryOptions, type PreprMiddlewareOptions, getActiveSegment, getActiveVariant, getPreprHeaders, getPreprUUID, getToolbarProps, normalizeQuery, onPreprRequest };
@@ -79,6 +79,17 @@ interface PreprMiddlewareOptions {
79
79
  version?: string;
80
80
  }
81
81
 
82
+ /**
83
+ * What `normalizeQuery` accepts as the query: GraphQL source text, a parsed
84
+ * `DocumentNode` (from `graphql-tag`, Apollo or GraphQL Code Generator), or a
85
+ * string-like object such as codegen's `TypedDocumentString`.
86
+ */
87
+ type QueryInput = string | {
88
+ kind: 'Document';
89
+ } | {
90
+ toString(): string;
91
+ };
92
+
82
93
  /**
83
94
  * Structural stand-in for Astro's `APIContext`, so this package needs no
84
95
  * build-time dependency on `astro`. Only the fields `onPreprRequest` uses.
@@ -87,6 +98,8 @@ interface AstroLikeContext {
87
98
  request: Request;
88
99
  /** Unused; typed loosely so passing the real Astro context still checks. */
89
100
  cookies?: unknown;
101
+ /** Per-request storage; carries the editor's unsaved changes in preview. */
102
+ locals?: object;
90
103
  }
91
104
  /** Astro middleware's `next()` — resolves to the `Response` from downstream. */
92
105
  type AstroNext = () => Promise<Response>;
@@ -116,5 +129,38 @@ declare function getPreprHeaders(headers: Headers): PreprHeaders;
116
129
  * its own.
117
130
  */
118
131
  declare function getToolbarProps(headers: Headers, token: string, features?: PreprFeatures): Promise<PreprToolbarProps>;
132
+ interface AstroNormalizeQueryOptions {
133
+ /**
134
+ * Whether this render may show unsaved editor changes. Pass your preview
135
+ * flag, and never `true` on a production deployment. When false (the
136
+ * default) the result is returned untouched.
137
+ */
138
+ enabled?: boolean;
139
+ /** `Astro.locals`, where `onPreprRequest` leaves the editor's changes. */
140
+ locals?: object;
141
+ /** Which operation to use when the document holds more than one. */
142
+ operationName?: string;
143
+ }
144
+ /**
145
+ * Show the Prepr editor's unsaved changes on a server-rendered Astro page:
146
+ * pass the query and the result you fetched (with any client), and render
147
+ * what comes back.
148
+ *
149
+ * ```astro
150
+ * ---
151
+ * const data = await fetchFromPrepr(GetPageDocument, { slug });
152
+ * const page = normalizeQuery(GetPageDocument, data, {
153
+ * enabled: preview,
154
+ * locals: Astro.locals,
155
+ * });
156
+ * ---
157
+ * ```
158
+ *
159
+ * Needs `onPreprRequest` with `preview: true` in your middleware and
160
+ * `PreprToolbar.astro` on the page; the toolbar re-requests the page with
161
+ * the editor's changes while they type. Select `_id` on every item and
162
+ * component that should update.
163
+ */
164
+ declare function normalizeQuery<T>(query: QueryInput, result: T, options?: AstroNormalizeQueryOptions): T;
119
165
 
120
- export { type AstroLikeContext, type AstroNext, type PreprMiddlewareOptions, getActiveSegment, getActiveVariant, getPreprHeaders, getPreprUUID, getToolbarProps, onPreprRequest };
166
+ export { type AstroLikeContext, type AstroNext, type AstroNormalizeQueryOptions, type PreprMiddlewareOptions, getActiveSegment, getActiveVariant, getPreprHeaders, getPreprUUID, getToolbarProps, normalizeQuery, onPreprRequest };