@preprio/toolkit 0.6.0-alpha.9 → 1.0.0-rc.2

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-A2J7R4LR.js +256 -0
  7. package/dist/{chunk-5QIWVDP2.js → chunk-DBKZWOXA.js} +1 -1
  8. package/dist/{chunk-WQBKQG4R.js → chunk-EWXBE3JD.js} +6 -1
  9. package/dist/chunk-KM2GME62.js +1255 -0
  10. package/dist/{chunk-J66UOCK6.js → chunk-LJA5K4KM.js} +1680 -579
  11. package/dist/chunk-UTKH7DOI.js +58 -0
  12. package/dist/chunk-V7MCHPE7.js +85 -0
  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 -754
  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 -299
  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-UN4JADNU.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-S5RWVMDJ.js +0 -148
  83. package/dist/chunk-XL4Y7FGW.js +0 -499
  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-CMV6ZP6E.js +0 -549
  93. package/dist/nextjs/graphql.cjs +0 -1836
  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 -1422
  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-XWOABVMW.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-3S5RA6G5.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
@@ -0,0 +1,61 @@
1
+ /**
2
+ * What `normalizeQuery` accepts as the query: GraphQL source text, a parsed
3
+ * `DocumentNode` (from `graphql-tag`, Apollo or GraphQL Code Generator), or a
4
+ * string-like object such as codegen's `TypedDocumentString`.
5
+ */
6
+ type QueryInput = string | {
7
+ kind: 'Document';
8
+ } | {
9
+ toString(): string;
10
+ };
11
+
12
+ interface NormalizedQueryOptions {
13
+ /**
14
+ * Pass your preview flag; never `true` on a production deployment.
15
+ * Defaults to false: the data is returned unchanged.
16
+ */
17
+ enabled?: boolean;
18
+ /** Called when the editor saves, e.g. `invalidateAll` from `$app/navigation`. */
19
+ onSave?: () => void;
20
+ /** Exact editor origins, replacing the `*.prepr.io` default. */
21
+ allowedEditorOrigins?: string[];
22
+ /** See the toolbar's `strictMode`. */
23
+ strictMode?: boolean;
24
+ /** Which operation to use when the query document holds more than one. */
25
+ operationName?: string;
26
+ }
27
+ /**
28
+ * Svelte's store contract, written out so this module needs no build-time
29
+ * dependency on `svelte`. Read it with `$store` in a component.
30
+ */
31
+ interface NormalizedQueryStore<T> {
32
+ subscribe(run: (value: T) => void): () => void;
33
+ }
34
+ /**
35
+ * Show the Prepr editor's unsaved changes in a SvelteKit page, applied in the
36
+ * browser while the editor types:
37
+ *
38
+ * ```svelte
39
+ * <script lang="ts">
40
+ * import { invalidateAll } from '$app/navigation';
41
+ * import { normalizedQuery } from '@preprio/toolkit/sveltekit/live';
42
+ *
43
+ * let { data } = $props();
44
+ * const result = $derived(
45
+ * normalizedQuery(GetPageDocument, data.result, {
46
+ * enabled: data.preview,
47
+ * onSave: invalidateAll,
48
+ * }),
49
+ * );
50
+ * </script>
51
+ *
52
+ * <h1>{$result.Page.title}</h1>
53
+ * ```
54
+ *
55
+ * Returns a store that holds the data unchanged on the server and outside
56
+ * the editor iframe. Select `_id` on every item and component that should
57
+ * update.
58
+ */
59
+ declare function normalizedQuery<T>(query: QueryInput, data: T, options?: NormalizedQueryOptions): NormalizedQueryStore<T>;
60
+
61
+ export { type NormalizedQueryOptions, type NormalizedQueryStore, normalizedQuery };
@@ -0,0 +1,61 @@
1
+ /**
2
+ * What `normalizeQuery` accepts as the query: GraphQL source text, a parsed
3
+ * `DocumentNode` (from `graphql-tag`, Apollo or GraphQL Code Generator), or a
4
+ * string-like object such as codegen's `TypedDocumentString`.
5
+ */
6
+ type QueryInput = string | {
7
+ kind: 'Document';
8
+ } | {
9
+ toString(): string;
10
+ };
11
+
12
+ interface NormalizedQueryOptions {
13
+ /**
14
+ * Pass your preview flag; never `true` on a production deployment.
15
+ * Defaults to false: the data is returned unchanged.
16
+ */
17
+ enabled?: boolean;
18
+ /** Called when the editor saves, e.g. `invalidateAll` from `$app/navigation`. */
19
+ onSave?: () => void;
20
+ /** Exact editor origins, replacing the `*.prepr.io` default. */
21
+ allowedEditorOrigins?: string[];
22
+ /** See the toolbar's `strictMode`. */
23
+ strictMode?: boolean;
24
+ /** Which operation to use when the query document holds more than one. */
25
+ operationName?: string;
26
+ }
27
+ /**
28
+ * Svelte's store contract, written out so this module needs no build-time
29
+ * dependency on `svelte`. Read it with `$store` in a component.
30
+ */
31
+ interface NormalizedQueryStore<T> {
32
+ subscribe(run: (value: T) => void): () => void;
33
+ }
34
+ /**
35
+ * Show the Prepr editor's unsaved changes in a SvelteKit page, applied in the
36
+ * browser while the editor types:
37
+ *
38
+ * ```svelte
39
+ * <script lang="ts">
40
+ * import { invalidateAll } from '$app/navigation';
41
+ * import { normalizedQuery } from '@preprio/toolkit/sveltekit/live';
42
+ *
43
+ * let { data } = $props();
44
+ * const result = $derived(
45
+ * normalizedQuery(GetPageDocument, data.result, {
46
+ * enabled: data.preview,
47
+ * onSave: invalidateAll,
48
+ * }),
49
+ * );
50
+ * </script>
51
+ *
52
+ * <h1>{$result.Page.title}</h1>
53
+ * ```
54
+ *
55
+ * Returns a store that holds the data unchanged on the server and outside
56
+ * the editor iframe. Select `_id` on every item and component that should
57
+ * update.
58
+ */
59
+ declare function normalizedQuery<T>(query: QueryInput, data: T, options?: NormalizedQueryOptions): NormalizedQueryStore<T>;
60
+
61
+ export { type NormalizedQueryOptions, type NormalizedQueryStore, normalizedQuery };
@@ -0,0 +1,220 @@
1
+ import {
2
+ collectFields,
3
+ isObject,
4
+ readQueryDocument
5
+ } from "./chunk-5RBZPRQN.js";
6
+
7
+ // src/core/live-preview/edit-links.ts
8
+ import {
9
+ vercelStegaCombine,
10
+ vercelStegaDecode,
11
+ vercelStegaSplit
12
+ } from "@vercel/stega";
13
+ var ENTRY_PARAM = "entry";
14
+ var TOP_LEVEL_ENTRY = /^[A-Za-z0-9_]+\.\d+$/;
15
+ function entryIdOf(element) {
16
+ if (!isObject(element)) return void 0;
17
+ if (typeof element._id === "string") return element._id;
18
+ if (element.__typename !== "Assets" || !Array.isArray(element.items)) {
19
+ return void 0;
20
+ }
21
+ const first = element.items[0];
22
+ return isObject(first) && typeof first._id === "string" ? first._id : void 0;
23
+ }
24
+ function annotate(value, ctx) {
25
+ if (!ctx.entryId) return value;
26
+ const { cleaned, encoded } = vercelStegaSplit(value);
27
+ if (!encoded) return value;
28
+ let payload;
29
+ try {
30
+ payload = vercelStegaDecode(encoded);
31
+ } catch {
32
+ return value;
33
+ }
34
+ if (typeof payload?.href !== "string") return value;
35
+ let url;
36
+ try {
37
+ url = new URL(payload.href);
38
+ } catch {
39
+ return value;
40
+ }
41
+ if (url.searchParams.has(ENTRY_PARAM)) return value;
42
+ url.searchParams.set(ENTRY_PARAM, ctx.entryId);
43
+ const itemId = decodeURIComponent(url.pathname.split("/").pop() ?? "");
44
+ if (!url.searchParams.has("field") && ctx.entryField && TOP_LEVEL_ENTRY.test(ctx.entryField) && itemId === ctx.entryOwnerId) {
45
+ url.searchParams.set("field", ctx.entryField);
46
+ }
47
+ return vercelStegaCombine(
48
+ cleaned,
49
+ { ...payload, href: url.toString() },
50
+ false
51
+ );
52
+ }
53
+ function walk(value, selections, ctx) {
54
+ if (typeof value === "string") return annotate(value, ctx);
55
+ if (Array.isArray(value)) {
56
+ let changed2 = false;
57
+ const next2 = value.map((element, index) => {
58
+ const path = [...ctx.path, String(index)];
59
+ const entryId = ctx.inAssets ? void 0 : entryIdOf(element);
60
+ const entry = entryId ? {
61
+ entryId,
62
+ entryField: ctx.ownerId ? path.join(".") : void 0,
63
+ entryOwnerId: ctx.ownerId,
64
+ inAssets: isObject(element) && element._id === void 0
65
+ } : {};
66
+ const out = walk(element, selections, { ...ctx, ...entry, path });
67
+ if (out !== element) changed2 = true;
68
+ return out;
69
+ });
70
+ return changed2 ? next2 : value;
71
+ }
72
+ if (!isObject(value)) return value;
73
+ const id = typeof value._id === "string" ? value._id : void 0;
74
+ const typename = typeof value.__typename === "string" ? value.__typename : void 0;
75
+ const fields = ctx.doc && selections ? collectFields(selections, typename, ctx.doc) : null;
76
+ let changed = false;
77
+ const next = {};
78
+ for (const [key, child] of Object.entries(value)) {
79
+ const field = fields?.get(key);
80
+ const name = field?.name ?? key;
81
+ const out = walk(child, field?.selections ?? null, {
82
+ ...ctx,
83
+ ownerId: id ?? ctx.ownerId,
84
+ path: id ? [name] : [...ctx.path, name]
85
+ });
86
+ if (out !== child) changed = true;
87
+ next[key] = out;
88
+ }
89
+ return changed ? next : value;
90
+ }
91
+ function annotateEditLinks(result, query, operationName) {
92
+ let doc = null;
93
+ if (query !== void 0) {
94
+ try {
95
+ doc = readQueryDocument(query, operationName);
96
+ } catch {
97
+ doc = null;
98
+ }
99
+ }
100
+ return walk(result, doc?.operation ?? null, { doc, path: [] });
101
+ }
102
+
103
+ // src/core/live-preview/test-reset.ts
104
+ var resets = /* @__PURE__ */ new Set();
105
+ function onTestReset(reset) {
106
+ resets.add(reset);
107
+ }
108
+
109
+ // src/core/live-preview/starter.ts
110
+ function isFramed() {
111
+ return typeof window !== "undefined" && window.self !== window.top;
112
+ }
113
+ function createLiveStarter(options = {}) {
114
+ let starting = null;
115
+ let store = null;
116
+ let bridge = null;
117
+ let allowedEditorOrigins;
118
+ let strictMode = false;
119
+ const startListeners = /* @__PURE__ */ new Set();
120
+ onTestReset(() => {
121
+ bridge?.stop();
122
+ bridge = null;
123
+ store = null;
124
+ starting = null;
125
+ startListeners.clear();
126
+ allowedEditorOrigins = void 0;
127
+ strictMode = false;
128
+ options.onReset?.();
129
+ });
130
+ return {
131
+ configure(config) {
132
+ if (config.strictMode) strictMode = true;
133
+ if (config.allowedEditorOrigins) {
134
+ allowedEditorOrigins = [...config.allowedEditorOrigins];
135
+ }
136
+ },
137
+ start() {
138
+ starting ?? (starting = import("./live-preview-KO4IKWTX.js").then((runtime) => {
139
+ const started = runtime.createLiveStore(options.storeOptions?.());
140
+ options.onStart?.(started, runtime);
141
+ bridge = runtime.createLiveBridge(started, {
142
+ allowedEditorOrigins: () => allowedEditorOrigins,
143
+ strictMode: () => strictMode
144
+ });
145
+ bridge.start();
146
+ store = started;
147
+ startListeners.forEach((listener) => listener(started));
148
+ startListeners.clear();
149
+ return started;
150
+ }));
151
+ return starting;
152
+ },
153
+ whenLive(listener) {
154
+ if (store) {
155
+ listener(store);
156
+ return () => {
157
+ };
158
+ }
159
+ startListeners.add(listener);
160
+ return () => startListeners.delete(listener);
161
+ }
162
+ };
163
+ }
164
+
165
+ // src/sveltekit/live.ts
166
+ var applyLog = null;
167
+ var log = [];
168
+ var logListeners = /* @__PURE__ */ new Set();
169
+ var live = createLiveStarter({
170
+ onStart(store, runtime) {
171
+ applyLog = runtime.applyPatchLog;
172
+ store.onLogChange((next) => {
173
+ log = next;
174
+ logListeners.forEach((listener) => listener());
175
+ });
176
+ },
177
+ onReset() {
178
+ applyLog = null;
179
+ log = [];
180
+ logListeners.clear();
181
+ }
182
+ });
183
+ function constant(value) {
184
+ return {
185
+ subscribe(run) {
186
+ run(value);
187
+ return () => {
188
+ };
189
+ }
190
+ };
191
+ }
192
+ function normalizedQuery(query, data, options = {}) {
193
+ if (!options.enabled) return constant(data);
194
+ const { operationName } = options;
195
+ const annotated = annotateEditLinks(data, query, operationName);
196
+ if (!isFramed()) return constant(annotated);
197
+ live.configure(options);
198
+ void live.start();
199
+ const current = () => log.length && applyLog ? applyLog(query, annotated, log, operationName) : annotated;
200
+ return {
201
+ subscribe(run) {
202
+ run(current());
203
+ const onLog = () => run(current());
204
+ logListeners.add(onLog);
205
+ let offInvalidate = null;
206
+ const stopWaiting = options.onSave ? live.whenLive((started) => {
207
+ offInvalidate = started.onInvalidate(() => options.onSave?.());
208
+ }) : () => {
209
+ };
210
+ return () => {
211
+ logListeners.delete(onLog);
212
+ stopWaiting();
213
+ offInvalidate?.();
214
+ };
215
+ }
216
+ };
217
+ }
218
+ export {
219
+ normalizedQuery
220
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@preprio/toolkit",
3
- "version": "0.6.0-alpha.9",
3
+ "version": "1.0.0-rc.2",
4
4
  "description": "Prepr personalization, A/B testing and preview toolkit for React, Next.js, Nuxt, Astro, SvelteKit and Express",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Prepr B.V. (https://prepr.io)",
@@ -35,86 +35,146 @@
35
35
  "sideEffects": false,
36
36
  "exports": {
37
37
  ".": {
38
- "types": "./dist/index.d.ts",
39
- "import": "./dist/index.js",
40
- "require": "./dist/index.cjs"
41
- },
42
- "./graphql": {
43
- "types": "./dist/graphql.d.ts",
44
- "import": "./dist/graphql.js",
45
- "require": "./dist/graphql.cjs"
46
- },
47
- "./graphql/codegen": {
48
- "types": "./dist/graphql/codegen.d.ts",
49
- "import": "./dist/graphql/codegen.js",
50
- "require": "./dist/graphql/codegen.cjs"
38
+ "import": {
39
+ "types": "./dist/index.d.ts",
40
+ "default": "./dist/index.js"
41
+ },
42
+ "require": {
43
+ "types": "./dist/index.d.cts",
44
+ "default": "./dist/index.cjs"
45
+ }
51
46
  },
52
47
  "./react": {
53
- "types": "./dist/react/index.d.ts",
54
- "import": "./dist/react/index.js",
55
- "require": "./dist/react/index.cjs"
48
+ "import": {
49
+ "types": "./dist/react/index.d.ts",
50
+ "default": "./dist/react/index.js"
51
+ },
52
+ "require": {
53
+ "types": "./dist/react/index.d.cts",
54
+ "default": "./dist/react/index.cjs"
55
+ }
56
56
  },
57
57
  "./react/components": {
58
- "types": "./dist/react/components.d.ts",
59
- "import": "./dist/react/components.js",
60
- "require": "./dist/react/components.cjs"
58
+ "import": {
59
+ "types": "./dist/react/components.d.ts",
60
+ "default": "./dist/react/components.js"
61
+ },
62
+ "require": {
63
+ "types": "./dist/react/components.d.cts",
64
+ "default": "./dist/react/components.cjs"
65
+ }
61
66
  },
62
67
  "./nextjs": {
63
- "types": "./dist/nextjs/index.d.ts",
64
- "import": "./dist/nextjs/index.js",
65
- "require": "./dist/nextjs/index.cjs"
66
- },
67
- "./nextjs/graphql": {
68
- "types": "./dist/nextjs/graphql.d.ts",
69
- "import": "./dist/nextjs/graphql.js",
70
- "require": "./dist/nextjs/graphql.cjs"
68
+ "import": {
69
+ "types": "./dist/nextjs/index.d.ts",
70
+ "default": "./dist/nextjs/index.js"
71
+ },
72
+ "require": {
73
+ "types": "./dist/nextjs/index.d.cts",
74
+ "default": "./dist/nextjs/index.cjs"
75
+ }
71
76
  },
72
77
  "./json-script": {
73
- "types": "./dist/json-script.d.ts",
74
- "import": "./dist/json-script.js",
75
- "require": "./dist/json-script.cjs"
78
+ "import": {
79
+ "types": "./dist/json-script.d.ts",
80
+ "default": "./dist/json-script.js"
81
+ },
82
+ "require": {
83
+ "types": "./dist/json-script.d.cts",
84
+ "default": "./dist/json-script.cjs"
85
+ }
76
86
  },
77
87
  "./nextjs/components": {
78
- "types": "./dist/nextjs/components.d.ts",
79
- "import": "./dist/nextjs/components.js",
80
- "require": "./dist/nextjs/components.cjs"
88
+ "import": {
89
+ "types": "./dist/nextjs/components.d.ts",
90
+ "default": "./dist/nextjs/components.js"
91
+ },
92
+ "require": {
93
+ "types": "./dist/nextjs/components.d.cts",
94
+ "default": "./dist/nextjs/components.cjs"
95
+ }
81
96
  },
82
97
  "./nextjs/image-loader": {
83
- "types": "./dist/nextjs/image-loader.d.ts",
84
- "import": "./dist/nextjs/image-loader.js",
85
- "require": "./dist/nextjs/image-loader.cjs"
98
+ "import": {
99
+ "types": "./dist/nextjs/image-loader.d.ts",
100
+ "default": "./dist/nextjs/image-loader.js"
101
+ },
102
+ "require": {
103
+ "types": "./dist/nextjs/image-loader.d.cts",
104
+ "default": "./dist/nextjs/image-loader.cjs"
105
+ }
106
+ },
107
+ "./nextjs/live": {
108
+ "import": {
109
+ "types": "./dist/nextjs/live.d.ts",
110
+ "default": "./dist/nextjs/live.js"
111
+ },
112
+ "require": {
113
+ "types": "./dist/nextjs/live.d.cts",
114
+ "default": "./dist/nextjs/live.cjs"
115
+ }
86
116
  },
87
117
  "./astro": {
88
- "types": "./dist/astro/index.d.ts",
89
- "import": "./dist/astro/index.js",
90
- "require": "./dist/astro/index.cjs"
91
- },
92
- "./astro/graphql": {
93
- "types": "./dist/astro/graphql.d.ts",
94
- "import": "./dist/astro/graphql.js",
95
- "require": "./dist/astro/graphql.cjs"
118
+ "import": {
119
+ "types": "./dist/astro/index.d.ts",
120
+ "default": "./dist/astro/index.js"
121
+ },
122
+ "require": {
123
+ "types": "./dist/astro/index.d.cts",
124
+ "default": "./dist/astro/index.cjs"
125
+ }
96
126
  },
97
127
  "./astro/components/*": "./src/astro/*.astro",
98
- "./sveltekit": {
99
- "types": "./dist/sveltekit/index.d.ts",
100
- "import": "./dist/sveltekit/index.js",
101
- "require": "./dist/sveltekit/index.cjs"
128
+ "./codegen": {
129
+ "import": {
130
+ "types": "./dist/codegen/index.d.ts",
131
+ "default": "./dist/codegen/index.js"
132
+ },
133
+ "require": {
134
+ "types": "./dist/codegen/index.d.cts",
135
+ "default": "./dist/codegen/index.cjs"
136
+ }
102
137
  },
103
- "./sveltekit/graphql": {
104
- "types": "./dist/sveltekit/graphql.d.ts",
105
- "import": "./dist/sveltekit/graphql.js",
106
- "require": "./dist/sveltekit/graphql.cjs"
138
+ "./sveltekit": {
139
+ "import": {
140
+ "types": "./dist/sveltekit/index.d.ts",
141
+ "default": "./dist/sveltekit/index.js"
142
+ },
143
+ "require": {
144
+ "types": "./dist/sveltekit/index.d.cts",
145
+ "default": "./dist/sveltekit/index.cjs"
146
+ }
147
+ },
148
+ "./sveltekit/live": {
149
+ "import": {
150
+ "types": "./dist/sveltekit/live.d.ts",
151
+ "default": "./dist/sveltekit/live.js"
152
+ },
153
+ "require": {
154
+ "types": "./dist/sveltekit/live.d.cts",
155
+ "default": "./dist/sveltekit/live.cjs"
156
+ }
107
157
  },
108
158
  "./sveltekit/components/*": "./src/sveltekit/*.svelte",
109
159
  "./nuxt": {
110
- "types": "./dist/nuxt/index.d.ts",
111
- "import": "./dist/nuxt/index.js",
112
- "require": "./dist/nuxt/index.cjs"
113
- },
114
- "./nuxt/graphql": {
115
- "types": "./dist/nuxt/graphql.d.ts",
116
- "import": "./dist/nuxt/graphql.js",
117
- "require": "./dist/nuxt/graphql.cjs"
160
+ "import": {
161
+ "types": "./dist/nuxt/index.d.ts",
162
+ "default": "./dist/nuxt/index.js"
163
+ },
164
+ "require": {
165
+ "types": "./dist/nuxt/index.d.cts",
166
+ "default": "./dist/nuxt/index.cjs"
167
+ }
168
+ },
169
+ "./nuxt/live": {
170
+ "import": {
171
+ "types": "./dist/nuxt/live.d.ts",
172
+ "default": "./dist/nuxt/live.js"
173
+ },
174
+ "require": {
175
+ "types": "./dist/nuxt/live.d.cts",
176
+ "default": "./dist/nuxt/live.cjs"
177
+ }
118
178
  },
119
179
  "./nuxt/components/*": "./src/nuxt/*.vue"
120
180
  },
@@ -132,11 +192,12 @@
132
192
  "build": "tsup",
133
193
  "postbuild": "node scripts/check-exports.mjs",
134
194
  "test": "vitest run",
195
+ "test:e2e": "pnpm build && vitest run --config vitest.e2e.config.ts",
135
196
  "typecheck": "tsc --noEmit"
136
197
  },
137
198
  "dependencies": {
138
199
  "@vercel/stega": "^1.1.0",
139
- "preact": "^10.29.7"
200
+ "preact": "^10.29.8"
140
201
  },
141
202
  "peerDependencies": {
142
203
  "graphql": ">=16",
@@ -167,18 +228,18 @@
167
228
  }
168
229
  },
169
230
  "devDependencies": {
170
- "@types/node": "^22.20.1",
171
- "@types/react": "^19.2.17",
172
- "@types/react-dom": "^19.2.3",
173
- "browserslist": "^4.28.7",
231
+ "@types/node": "^22.20.5",
232
+ "@types/react": "^19.3.0",
233
+ "@types/react-dom": "^19.3.0",
234
+ "browserslist": "^4.29.5",
174
235
  "graphql": "^16.14.2",
175
- "happy-dom": "^20.11.1",
236
+ "happy-dom": "^21.0.4",
176
237
  "lightningcss": "^1.33.0",
177
- "next": "^16.2.12",
178
- "react": "^19.2.8",
179
- "react-dom": "^19.2.8",
238
+ "next": "^16.4.3",
239
+ "react": "^19.3.1",
240
+ "react-dom": "^19.3.1",
180
241
  "tsup": "^8.5.1",
181
242
  "typescript": "^5.9.3",
182
- "vitest": "^4.1.10"
243
+ "vitest": "^4.1.12"
183
244
  }
184
245
  }
@@ -50,11 +50,17 @@ const payload = {
50
50
  />
51
51
 
52
52
  <script>
53
- import { createPreprPreview } from '@preprio/toolkit';
53
+ import { createPreprPreview, startHtmlLivePreview } from '@preprio/toolkit';
54
54
 
55
55
  const el = document.querySelector('script[data-prepr-toolbar-props]');
56
56
  if (el?.textContent) {
57
57
  const { props, options } = JSON.parse(el.textContent);
58
58
  createPreprPreview({ props, options });
59
+ // Inside the Prepr editor: re-render the page with the editor's unsaved
60
+ // changes while they type (see `normalizeQuery`). A no-op elsewhere.
61
+ startHtmlLivePreview({
62
+ allowedEditorOrigins: options?.allowedEditorOrigins,
63
+ strictMode: options?.strictMode,
64
+ });
59
65
  }
60
66
  </script>
@@ -14,14 +14,12 @@
14
14
  * from '@preprio/toolkit'` would fail to resolve in the browser. See
15
15
  * `PreprToolbar.astro` for the full explanation.
16
16
  */
17
+ import type { PreprPixelConfig } from '@preprio/toolkit';
17
18
  import { serializeForScriptTag } from '@preprio/toolkit/json-script';
18
19
 
19
20
  interface Props {
20
21
  id: string;
21
- config?: {
22
- destinations?: { googleTagManager?: boolean };
23
- variantImpressionThreshold?: number;
24
- };
22
+ config?: PreprPixelConfig;
25
23
  }
26
24
 
27
25
  const { id, config } = Astro.props as Props;
@@ -8,7 +8,10 @@
8
8
  */
9
9
  import { onMounted, onUnmounted } from 'vue';
10
10
  import { createPreprPreview } from '@preprio/toolkit';
11
- import type { PreprToolbarComponentProps } from '@preprio/toolkit';
11
+ import type {
12
+ PreprNavigationAdapter,
13
+ PreprToolbarComponentProps,
14
+ } from '@preprio/toolkit';
12
15
 
13
16
  const props = defineProps<{
14
17
  activeSegment?: PreprToolbarComponentProps['activeSegment'];
@@ -16,6 +19,13 @@ const props = defineProps<{
16
19
  segments?: PreprToolbarComponentProps['segments'];
17
20
  data?: PreprToolbarComponentProps['data'];
18
21
  options?: PreprToolbarComponentProps['options'];
22
+ /**
23
+ * How the toolbar changes the URL when a segment or variant is picked.
24
+ * Defaults to a full page load; pass the app's router for a soft
25
+ * navigation, e.g. `{ navigate: (url) => navigateTo(url), currentPath: () =>
26
+ * route.fullPath }` with `route` from `useRoute()`.
27
+ */
28
+ navigation?: PreprNavigationAdapter;
19
29
  }>();
20
30
 
21
31
  let controller: ReturnType<typeof createPreprPreview> | null = null;
@@ -29,6 +39,7 @@ onMounted(() => {
29
39
  data: props.data,
30
40
  },
31
41
  options: props.options,
42
+ navigation: props.navigation,
32
43
  });
33
44
  });
34
45