@preprio/toolkit 0.6.0-alpha.9 → 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.
- package/README.md +111 -1363
- package/dist/astro/index.cjs +1555 -182
- package/dist/astro/index.d.cts +201 -1
- package/dist/astro/index.d.ts +201 -1
- package/dist/astro/index.js +1557 -29
- package/dist/{chunk-5QIWVDP2.js → chunk-33GWVTRJ.js} +1 -1
- package/dist/chunk-A2J7R4LR.js +256 -0
- package/dist/{chunk-WQBKQG4R.js → chunk-DSJ22P6J.js} +6 -1
- package/dist/chunk-KM2GME62.js +1255 -0
- package/dist/chunk-UTKH7DOI.js +58 -0
- package/dist/chunk-V7MCHPE7.js +85 -0
- package/dist/{chunk-J66UOCK6.js → chunk-WBMN4L7G.js} +1680 -579
- package/dist/chunk-Y7JWV7WV.js +374 -0
- package/dist/codegen/index.cjs +82 -0
- package/dist/codegen/index.d.cts +70 -0
- package/dist/codegen/index.d.ts +70 -0
- package/dist/codegen/index.js +64 -0
- package/dist/index.cjs +3729 -553
- package/dist/index.d.cts +403 -19
- package/dist/index.d.ts +403 -19
- package/dist/index.js +345 -24
- package/dist/live-preview-HCBNBC6C.js +19 -0
- package/dist/nextjs/components.cjs +1872 -754
- package/dist/nextjs/components.d.cts +5 -51
- package/dist/nextjs/components.d.ts +5 -51
- package/dist/nextjs/components.js +8 -299
- package/dist/nextjs/index.cjs +1228 -181
- package/dist/nextjs/index.d.cts +247 -92
- package/dist/nextjs/index.d.ts +247 -92
- package/dist/nextjs/index.js +1629 -111
- package/dist/nextjs/live-action.cjs +298 -0
- package/dist/nextjs/live-action.d.cts +12 -0
- package/dist/nextjs/live-action.d.ts +12 -0
- package/dist/nextjs/live-action.js +68 -0
- package/dist/nextjs/live.cjs +2010 -0
- package/dist/nextjs/live.d.cts +54 -0
- package/dist/nextjs/live.d.ts +54 -0
- package/dist/nextjs/live.js +287 -0
- package/dist/nuxt/chunk-5RBZPRQN.js +350 -0
- package/dist/nuxt/chunk-LUKVPOJ2.js +32 -0
- package/dist/nuxt/index.cjs +15 -16
- package/dist/nuxt/index.d.cts +167 -6
- package/dist/nuxt/index.d.ts +167 -6
- package/dist/nuxt/index.js +402 -15
- package/dist/nuxt/live-preview-KO4IKWTX.js +1234 -0
- package/dist/nuxt/live.cjs +1928 -0
- package/dist/nuxt/live.d.cts +45 -0
- package/dist/nuxt/live.d.ts +45 -0
- package/dist/nuxt/live.js +216 -0
- package/dist/{types-BYH9XqmN.d.cts → pixel-DqU7NvgW.d.cts} +102 -5
- package/dist/{types-BYH9XqmN.d.ts → pixel-DqU7NvgW.d.ts} +102 -5
- package/dist/react/components.cjs +1865 -480
- package/dist/react/components.d.cts +43 -8
- package/dist/react/components.d.ts +43 -8
- package/dist/react/components.js +1865 -480
- package/dist/sveltekit/chunk-5RBZPRQN.js +350 -0
- package/dist/sveltekit/chunk-LUKVPOJ2.js +32 -0
- package/dist/sveltekit/index.cjs +15 -16
- package/dist/sveltekit/index.d.cts +111 -10
- package/dist/sveltekit/index.d.ts +111 -10
- package/dist/sveltekit/index.js +398 -15
- package/dist/sveltekit/live-preview-KO4IKWTX.js +1234 -0
- package/dist/sveltekit/live.cjs +1940 -0
- package/dist/sveltekit/live.d.cts +61 -0
- package/dist/sveltekit/live.d.ts +61 -0
- package/dist/sveltekit/live.js +220 -0
- package/package.json +132 -71
- package/src/astro/PreprToolbar.astro +7 -1
- package/src/astro/PreprTrackingPixel.astro +2 -4
- package/src/nuxt/PreprToolbar.vue +12 -1
- package/src/nuxt/PreprTrackingPixel.vue +2 -4
- package/src/sveltekit/PreprToolbar.svelte +17 -2
- package/src/sveltekit/PreprTrackingPixel.svelte +2 -4
- package/dist/astro/chunk-UN4JADNU.js +0 -173
- package/dist/astro/graphql.cjs +0 -1078
- package/dist/astro/graphql.d.cts +0 -300
- package/dist/astro/graphql.d.ts +0 -300
- package/dist/astro/graphql.js +0 -984
- package/dist/astro/index-XT_z-RYT.d.cts +0 -130
- package/dist/astro/index-XT_z-RYT.d.ts +0 -130
- package/dist/chunk-3NCEVJJ3.js +0 -10
- package/dist/chunk-S5RWVMDJ.js +0 -148
- package/dist/chunk-XL4Y7FGW.js +0 -499
- package/dist/graphql/codegen.cjs +0 -557
- package/dist/graphql/codegen.d.cts +0 -23
- package/dist/graphql/codegen.d.ts +0 -23
- package/dist/graphql/codegen.js +0 -99
- package/dist/graphql.cjs +0 -1020
- package/dist/graphql.d.cts +0 -335
- package/dist/graphql.d.ts +0 -335
- package/dist/graphql.js +0 -448
- package/dist/nextjs/chunk-CMV6ZP6E.js +0 -549
- package/dist/nextjs/graphql.cjs +0 -1836
- package/dist/nextjs/graphql.d.cts +0 -498
- package/dist/nextjs/graphql.d.ts +0 -498
- package/dist/nextjs/graphql.js +0 -1422
- package/dist/nextjs/server-BL-sqZvu.d.cts +0 -156
- package/dist/nextjs/server-BL-sqZvu.d.ts +0 -156
- package/dist/nuxt/chunk-XWOABVMW.js +0 -417
- package/dist/nuxt/graphql.cjs +0 -1085
- package/dist/nuxt/graphql.d.cts +0 -297
- package/dist/nuxt/graphql.d.ts +0 -297
- package/dist/nuxt/graphql.js +0 -985
- package/dist/nuxt/server-8v6OHbsw.d.cts +0 -158
- package/dist/nuxt/server-8v6OHbsw.d.ts +0 -158
- package/dist/pixel-DwW7cXJm.d.cts +0 -49
- package/dist/pixel-DwW7cXJm.d.ts +0 -49
- package/dist/server-Brr1UgtW.d.ts +0 -59
- package/dist/server-DJuS3YU0.d.cts +0 -59
- package/dist/sveltekit/chunk-3S5RA6G5.js +0 -413
- package/dist/sveltekit/graphql.cjs +0 -1091
- package/dist/sveltekit/graphql.d.cts +0 -302
- package/dist/sveltekit/graphql.d.ts +0 -302
- package/dist/sveltekit/graphql.js +0 -991
- package/dist/sveltekit/server-CO847mEV.d.cts +0 -98
- package/dist/sveltekit/server-CO847mEV.d.ts +0 -98
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Ref, ComputedRef } from 'vue';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* What `normalizeQuery` accepts as the query: GraphQL source text, a parsed
|
|
5
|
+
* `DocumentNode` (from `graphql-tag`, Apollo or GraphQL Code Generator), or a
|
|
6
|
+
* string-like object such as codegen's `TypedDocumentString`.
|
|
7
|
+
*/
|
|
8
|
+
type QueryInput = string | {
|
|
9
|
+
kind: 'Document';
|
|
10
|
+
} | {
|
|
11
|
+
toString(): string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
interface UseNormalizedQueryOptions {
|
|
15
|
+
/**
|
|
16
|
+
* Pass your preview flag; never `true` on a production deployment.
|
|
17
|
+
* Defaults to false: the data is returned unchanged.
|
|
18
|
+
*/
|
|
19
|
+
enabled?: boolean;
|
|
20
|
+
/** Called when the editor saves, e.g. `refresh` from `useAsyncData`. */
|
|
21
|
+
onSave?: () => void;
|
|
22
|
+
/** Exact editor origins, replacing the `*.prepr.io` default. */
|
|
23
|
+
allowedEditorOrigins?: string[];
|
|
24
|
+
/** See the toolbar's `strictMode`. */
|
|
25
|
+
strictMode?: boolean;
|
|
26
|
+
/** Which operation to use when the query document holds more than one. */
|
|
27
|
+
operationName?: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Show the Prepr editor's unsaved changes in a Nuxt page, applied in the
|
|
31
|
+
* browser while the editor types:
|
|
32
|
+
*
|
|
33
|
+
* ```ts
|
|
34
|
+
* const page = useNormalizedQuery(GetPageDocument, data, {
|
|
35
|
+
* enabled: isPreview,
|
|
36
|
+
* onSave: refresh,
|
|
37
|
+
* });
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* Returns the data unchanged on the server and outside the editor iframe.
|
|
41
|
+
* Select `_id` on every item and component that should update.
|
|
42
|
+
*/
|
|
43
|
+
declare function useNormalizedQuery<T>(query: QueryInput, data: Ref<T> | T, options?: UseNormalizedQueryOptions): ComputedRef<T>;
|
|
44
|
+
|
|
45
|
+
export { type UseNormalizedQueryOptions, useNormalizedQuery };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Ref, ComputedRef } from 'vue';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* What `normalizeQuery` accepts as the query: GraphQL source text, a parsed
|
|
5
|
+
* `DocumentNode` (from `graphql-tag`, Apollo or GraphQL Code Generator), or a
|
|
6
|
+
* string-like object such as codegen's `TypedDocumentString`.
|
|
7
|
+
*/
|
|
8
|
+
type QueryInput = string | {
|
|
9
|
+
kind: 'Document';
|
|
10
|
+
} | {
|
|
11
|
+
toString(): string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
interface UseNormalizedQueryOptions {
|
|
15
|
+
/**
|
|
16
|
+
* Pass your preview flag; never `true` on a production deployment.
|
|
17
|
+
* Defaults to false: the data is returned unchanged.
|
|
18
|
+
*/
|
|
19
|
+
enabled?: boolean;
|
|
20
|
+
/** Called when the editor saves, e.g. `refresh` from `useAsyncData`. */
|
|
21
|
+
onSave?: () => void;
|
|
22
|
+
/** Exact editor origins, replacing the `*.prepr.io` default. */
|
|
23
|
+
allowedEditorOrigins?: string[];
|
|
24
|
+
/** See the toolbar's `strictMode`. */
|
|
25
|
+
strictMode?: boolean;
|
|
26
|
+
/** Which operation to use when the query document holds more than one. */
|
|
27
|
+
operationName?: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Show the Prepr editor's unsaved changes in a Nuxt page, applied in the
|
|
31
|
+
* browser while the editor types:
|
|
32
|
+
*
|
|
33
|
+
* ```ts
|
|
34
|
+
* const page = useNormalizedQuery(GetPageDocument, data, {
|
|
35
|
+
* enabled: isPreview,
|
|
36
|
+
* onSave: refresh,
|
|
37
|
+
* });
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* Returns the data unchanged on the server and outside the editor iframe.
|
|
41
|
+
* Select `_id` on every item and component that should update.
|
|
42
|
+
*/
|
|
43
|
+
declare function useNormalizedQuery<T>(query: QueryInput, data: Ref<T> | T, options?: UseNormalizedQueryOptions): ComputedRef<T>;
|
|
44
|
+
|
|
45
|
+
export { type UseNormalizedQueryOptions, useNormalizedQuery };
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import {
|
|
2
|
+
collectFields,
|
|
3
|
+
isObject,
|
|
4
|
+
readQueryDocument
|
|
5
|
+
} from "./chunk-5RBZPRQN.js";
|
|
6
|
+
|
|
7
|
+
// src/nuxt/live.ts
|
|
8
|
+
import {
|
|
9
|
+
computed,
|
|
10
|
+
getCurrentScope,
|
|
11
|
+
onScopeDispose,
|
|
12
|
+
shallowRef,
|
|
13
|
+
unref
|
|
14
|
+
} from "vue";
|
|
15
|
+
|
|
16
|
+
// src/core/live-preview/edit-links.ts
|
|
17
|
+
import {
|
|
18
|
+
vercelStegaCombine,
|
|
19
|
+
vercelStegaDecode,
|
|
20
|
+
vercelStegaSplit
|
|
21
|
+
} from "@vercel/stega";
|
|
22
|
+
var ENTRY_PARAM = "entry";
|
|
23
|
+
var TOP_LEVEL_ENTRY = /^[A-Za-z0-9_]+\.\d+$/;
|
|
24
|
+
function entryIdOf(element) {
|
|
25
|
+
if (!isObject(element)) return void 0;
|
|
26
|
+
if (typeof element._id === "string") return element._id;
|
|
27
|
+
if (element.__typename !== "Assets" || !Array.isArray(element.items)) {
|
|
28
|
+
return void 0;
|
|
29
|
+
}
|
|
30
|
+
const first = element.items[0];
|
|
31
|
+
return isObject(first) && typeof first._id === "string" ? first._id : void 0;
|
|
32
|
+
}
|
|
33
|
+
function annotate(value, ctx) {
|
|
34
|
+
if (!ctx.entryId) return value;
|
|
35
|
+
const { cleaned, encoded } = vercelStegaSplit(value);
|
|
36
|
+
if (!encoded) return value;
|
|
37
|
+
let payload;
|
|
38
|
+
try {
|
|
39
|
+
payload = vercelStegaDecode(encoded);
|
|
40
|
+
} catch {
|
|
41
|
+
return value;
|
|
42
|
+
}
|
|
43
|
+
if (typeof payload?.href !== "string") return value;
|
|
44
|
+
let url;
|
|
45
|
+
try {
|
|
46
|
+
url = new URL(payload.href);
|
|
47
|
+
} catch {
|
|
48
|
+
return value;
|
|
49
|
+
}
|
|
50
|
+
if (url.searchParams.has(ENTRY_PARAM)) return value;
|
|
51
|
+
url.searchParams.set(ENTRY_PARAM, ctx.entryId);
|
|
52
|
+
const itemId = decodeURIComponent(url.pathname.split("/").pop() ?? "");
|
|
53
|
+
if (!url.searchParams.has("field") && ctx.entryField && TOP_LEVEL_ENTRY.test(ctx.entryField) && itemId === ctx.entryOwnerId) {
|
|
54
|
+
url.searchParams.set("field", ctx.entryField);
|
|
55
|
+
}
|
|
56
|
+
return vercelStegaCombine(
|
|
57
|
+
cleaned,
|
|
58
|
+
{ ...payload, href: url.toString() },
|
|
59
|
+
false
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
function walk(value, selections, ctx) {
|
|
63
|
+
if (typeof value === "string") return annotate(value, ctx);
|
|
64
|
+
if (Array.isArray(value)) {
|
|
65
|
+
let changed2 = false;
|
|
66
|
+
const next2 = value.map((element, index) => {
|
|
67
|
+
const path = [...ctx.path, String(index)];
|
|
68
|
+
const entryId = ctx.inAssets ? void 0 : entryIdOf(element);
|
|
69
|
+
const entry = entryId ? {
|
|
70
|
+
entryId,
|
|
71
|
+
entryField: ctx.ownerId ? path.join(".") : void 0,
|
|
72
|
+
entryOwnerId: ctx.ownerId,
|
|
73
|
+
inAssets: isObject(element) && element._id === void 0
|
|
74
|
+
} : {};
|
|
75
|
+
const out = walk(element, selections, { ...ctx, ...entry, path });
|
|
76
|
+
if (out !== element) changed2 = true;
|
|
77
|
+
return out;
|
|
78
|
+
});
|
|
79
|
+
return changed2 ? next2 : value;
|
|
80
|
+
}
|
|
81
|
+
if (!isObject(value)) return value;
|
|
82
|
+
const id = typeof value._id === "string" ? value._id : void 0;
|
|
83
|
+
const typename = typeof value.__typename === "string" ? value.__typename : void 0;
|
|
84
|
+
const fields = ctx.doc && selections ? collectFields(selections, typename, ctx.doc) : null;
|
|
85
|
+
let changed = false;
|
|
86
|
+
const next = {};
|
|
87
|
+
for (const [key, child] of Object.entries(value)) {
|
|
88
|
+
const field = fields?.get(key);
|
|
89
|
+
const name = field?.name ?? key;
|
|
90
|
+
const out = walk(child, field?.selections ?? null, {
|
|
91
|
+
...ctx,
|
|
92
|
+
ownerId: id ?? ctx.ownerId,
|
|
93
|
+
path: id ? [name] : [...ctx.path, name]
|
|
94
|
+
});
|
|
95
|
+
if (out !== child) changed = true;
|
|
96
|
+
next[key] = out;
|
|
97
|
+
}
|
|
98
|
+
return changed ? next : value;
|
|
99
|
+
}
|
|
100
|
+
function annotateEditLinks(result, query, operationName) {
|
|
101
|
+
let doc = null;
|
|
102
|
+
if (query !== void 0) {
|
|
103
|
+
try {
|
|
104
|
+
doc = readQueryDocument(query, operationName);
|
|
105
|
+
} catch {
|
|
106
|
+
doc = null;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return walk(result, doc?.operation ?? null, { doc, path: [] });
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// src/core/live-preview/test-reset.ts
|
|
113
|
+
var resets = /* @__PURE__ */ new Set();
|
|
114
|
+
function onTestReset(reset) {
|
|
115
|
+
resets.add(reset);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// src/core/live-preview/starter.ts
|
|
119
|
+
function isFramed() {
|
|
120
|
+
return typeof window !== "undefined" && window.self !== window.top;
|
|
121
|
+
}
|
|
122
|
+
function createLiveStarter(options = {}) {
|
|
123
|
+
let starting = null;
|
|
124
|
+
let store = null;
|
|
125
|
+
let bridge = null;
|
|
126
|
+
let allowedEditorOrigins;
|
|
127
|
+
let strictMode = false;
|
|
128
|
+
const startListeners = /* @__PURE__ */ new Set();
|
|
129
|
+
onTestReset(() => {
|
|
130
|
+
bridge?.stop();
|
|
131
|
+
bridge = null;
|
|
132
|
+
store = null;
|
|
133
|
+
starting = null;
|
|
134
|
+
startListeners.clear();
|
|
135
|
+
allowedEditorOrigins = void 0;
|
|
136
|
+
strictMode = false;
|
|
137
|
+
options.onReset?.();
|
|
138
|
+
});
|
|
139
|
+
return {
|
|
140
|
+
configure(config) {
|
|
141
|
+
if (config.strictMode) strictMode = true;
|
|
142
|
+
if (config.allowedEditorOrigins) {
|
|
143
|
+
allowedEditorOrigins = [...config.allowedEditorOrigins];
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
start() {
|
|
147
|
+
starting ?? (starting = import("./live-preview-KO4IKWTX.js").then((runtime) => {
|
|
148
|
+
const started = runtime.createLiveStore(options.storeOptions?.());
|
|
149
|
+
options.onStart?.(started, runtime);
|
|
150
|
+
bridge = runtime.createLiveBridge(started, {
|
|
151
|
+
allowedEditorOrigins: () => allowedEditorOrigins,
|
|
152
|
+
strictMode: () => strictMode
|
|
153
|
+
});
|
|
154
|
+
bridge.start();
|
|
155
|
+
store = started;
|
|
156
|
+
startListeners.forEach((listener) => listener(started));
|
|
157
|
+
startListeners.clear();
|
|
158
|
+
return started;
|
|
159
|
+
}));
|
|
160
|
+
return starting;
|
|
161
|
+
},
|
|
162
|
+
whenLive(listener) {
|
|
163
|
+
if (store) {
|
|
164
|
+
listener(store);
|
|
165
|
+
return () => {
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
startListeners.add(listener);
|
|
169
|
+
return () => startListeners.delete(listener);
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// src/nuxt/live.ts
|
|
175
|
+
var applyLog = null;
|
|
176
|
+
var log = shallowRef([]);
|
|
177
|
+
var live = createLiveStarter({
|
|
178
|
+
onStart(store, runtime) {
|
|
179
|
+
applyLog = runtime.applyPatchLog;
|
|
180
|
+
store.onLogChange((next) => {
|
|
181
|
+
log.value = next;
|
|
182
|
+
});
|
|
183
|
+
},
|
|
184
|
+
onReset() {
|
|
185
|
+
applyLog = null;
|
|
186
|
+
log.value = [];
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
function useNormalizedQuery(query, data, options = {}) {
|
|
190
|
+
if (!options.enabled) return computed(() => unref(data));
|
|
191
|
+
const { operationName } = options;
|
|
192
|
+
const annotated = computed(
|
|
193
|
+
() => annotateEditLinks(unref(data), query, operationName)
|
|
194
|
+
);
|
|
195
|
+
if (!isFramed()) return annotated;
|
|
196
|
+
live.configure(options);
|
|
197
|
+
void live.start();
|
|
198
|
+
if (options.onSave && getCurrentScope()) {
|
|
199
|
+
const onSave = options.onSave;
|
|
200
|
+
let offInvalidate = null;
|
|
201
|
+
const stopWaiting = live.whenLive((started) => {
|
|
202
|
+
offInvalidate = started.onInvalidate(() => onSave());
|
|
203
|
+
});
|
|
204
|
+
onScopeDispose(() => {
|
|
205
|
+
stopWaiting();
|
|
206
|
+
offInvalidate?.();
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
return computed(() => {
|
|
210
|
+
const value = annotated.value;
|
|
211
|
+
return log.value.length && applyLog ? applyLog(query, value, log.value, operationName) : value;
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
export {
|
|
215
|
+
useNormalizedQuery
|
|
216
|
+
};
|
|
@@ -2,9 +2,12 @@ type Dictionary = Record<string, unknown>;
|
|
|
2
2
|
declare const dictionaries: {
|
|
3
3
|
en: Dictionary;
|
|
4
4
|
nl: Dictionary;
|
|
5
|
+
fr: Dictionary;
|
|
6
|
+
de: Dictionary;
|
|
5
7
|
};
|
|
6
8
|
type Locale = keyof typeof dictionaries;
|
|
7
9
|
|
|
10
|
+
/** A segment from Prepr, as listed in the toolbar's segment picker. */
|
|
8
11
|
interface PreprSegment {
|
|
9
12
|
readonly _id: string;
|
|
10
13
|
readonly name: string;
|
|
@@ -39,8 +42,14 @@ interface ResolvedPreprFeatures {
|
|
|
39
42
|
readonly abTesting: boolean;
|
|
40
43
|
readonly editMode: boolean;
|
|
41
44
|
}
|
|
45
|
+
/** Options shared by the toolbar and the preview runtime. */
|
|
42
46
|
interface PreprToolbarOptions {
|
|
47
|
+
/** Log what the toolkit does to the browser console. Default `false`. */
|
|
43
48
|
debug?: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Language of the toolbar and the visual editor labels. Defaults to the
|
|
51
|
+
* first supported browser language, then English.
|
|
52
|
+
*/
|
|
44
53
|
locale?: Locale;
|
|
45
54
|
/** Disable features app-wide. Pass the same object to the middleware. */
|
|
46
55
|
features?: PreprFeatures;
|
|
@@ -64,10 +73,24 @@ interface PreprPreviewOptions extends PreprToolbarOptions {
|
|
|
64
73
|
*/
|
|
65
74
|
ui?: boolean;
|
|
66
75
|
/**
|
|
67
|
-
* Replace the `*.prepr.io` editor-origin wildcard with an exact list.
|
|
68
|
-
* Intended for self-hosted
|
|
76
|
+
* Replace the `*.prepr.io` editor-origin wildcard with an exact list, e.g.
|
|
77
|
+
* `['http://acme.localhost:8000']`. Intended for self-hosted or locally run
|
|
78
|
+
* editors; when set, the wildcard no longer applies. Entries are compared to
|
|
79
|
+
* the editor's origin exactly: scheme, host and port.
|
|
80
|
+
*
|
|
81
|
+
* `['*']` accepts any editor origin. Use it for development only: any page
|
|
82
|
+
* that frames the preview can then switch on preview and edit mode and
|
|
83
|
+
* receives the field-edit events, which carry content item ids.
|
|
69
84
|
*/
|
|
70
85
|
allowedEditorOrigins?: string[];
|
|
86
|
+
/**
|
|
87
|
+
* Set when your preview token uses GraphQL strict mode, where required
|
|
88
|
+
* fields are never null. The editor then holds back new entries until
|
|
89
|
+
* their required fields are filled, and never sends a cleared required
|
|
90
|
+
* field as null. Applies to live preview on the same page as well, so the
|
|
91
|
+
* live preview helpers do not need their own `strictMode`.
|
|
92
|
+
*/
|
|
93
|
+
strictMode?: boolean;
|
|
71
94
|
/**
|
|
72
95
|
* Strip the invisible stega characters out of visible text at runtime.
|
|
73
96
|
* Default `true`.
|
|
@@ -83,6 +106,10 @@ interface PreprPreviewOptions extends PreprToolbarOptions {
|
|
|
83
106
|
*/
|
|
84
107
|
autoClean?: boolean;
|
|
85
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* The data the toolbar shows. `getToolbarProps` builds it on the server from
|
|
111
|
+
* the request headers.
|
|
112
|
+
*/
|
|
86
113
|
interface PreprToolbarProps {
|
|
87
114
|
/**
|
|
88
115
|
* Server-resolved active segment. Optional: omit it with `segments`
|
|
@@ -108,10 +135,26 @@ interface PreprToolbarProps {
|
|
|
108
135
|
interface PreprToolbarComponentProps extends PreprToolbarProps {
|
|
109
136
|
options?: PreprPreviewOptions;
|
|
110
137
|
}
|
|
138
|
+
/**
|
|
139
|
+
* Header names the Prepr API expects; the casing must match exactly.
|
|
140
|
+
*
|
|
141
|
+
* @deprecated Unused by the toolkit; use the keys of `PreprHeaders`.
|
|
142
|
+
*/
|
|
111
143
|
type PreprHeaderName = 'prepr-customer-id' | 'Prepr-Segments' | 'Prepr-ABtesting' | 'User-Agent' | 'Prepr-User-Agent';
|
|
144
|
+
/** The two sides of an A/B test. */
|
|
112
145
|
type PreprVariant = 'A' | 'B';
|
|
146
|
+
/** @deprecated Unused by the toolkit; kept so existing imports compile. */
|
|
113
147
|
type PreprEnvironment = 'preview' | 'production';
|
|
114
|
-
|
|
148
|
+
/**
|
|
149
|
+
* Events the preview announces: as a `prepr_preview_bar` `CustomEvent` on
|
|
150
|
+
* `window`, and to the Prepr editor when the page runs inside it.
|
|
151
|
+
*/
|
|
152
|
+
type PreprEventType = 'segment_changed' | 'variant_changed' | 'edit_mode_toggled' | 'preview_mode_toggled' | 'getScrollPosition' | 'loaded' | 'field_edit_requested' | 'live_ready' | 'navigation_blocked';
|
|
153
|
+
/**
|
|
154
|
+
* The headers to send with a Prepr GraphQL request so the API personalizes
|
|
155
|
+
* the response for this visitor. `getPreprHeaders` returns them; spread them
|
|
156
|
+
* into the request's `headers`.
|
|
157
|
+
*/
|
|
115
158
|
interface PreprHeaders {
|
|
116
159
|
readonly 'prepr-customer-id'?: string;
|
|
117
160
|
readonly 'Prepr-Segments'?: string;
|
|
@@ -132,6 +175,60 @@ interface PreprHeaders {
|
|
|
132
175
|
readonly 'Prepr-User-Agent'?: string;
|
|
133
176
|
readonly 'Prepr-Package'?: string;
|
|
134
177
|
}
|
|
135
|
-
|
|
178
|
+
/** Why a `PreprError` was thrown; read it from `error.code`. */
|
|
179
|
+
type PreprErrorCode = 'INVALID_TOKEN' | 'MISSING_TOKEN' | 'HTTP_ERROR' | 'FETCH_ERROR' | 'INVALID_RESPONSE' | 'CONTEXT_ERROR';
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Loader + typed facade for Prepr's CDN tracking pixel, so consumers don't have
|
|
183
|
+
* to paste a `<script>` tag. The pixel itself lives on the CDN; this only sets
|
|
184
|
+
* up the handoff.
|
|
185
|
+
*
|
|
186
|
+
* The CDN script expects a queue stub to already exist when it loads, so the
|
|
187
|
+
* contract must be reproduced exactly:
|
|
188
|
+
* - `window.prepr` pushes `arguments` onto `.queue` until the real script
|
|
189
|
+
* lands and replaces `.process`.
|
|
190
|
+
* - `.t` must be a `Date.now()` timestamp.
|
|
191
|
+
* - The tag is inserted async, `src` cache-busted every 24h via
|
|
192
|
+
* `Math.ceil(Date.now() / cacheTime) * cacheTime`.
|
|
193
|
+
*/
|
|
194
|
+
/** Config for the Prepr tracking pixel, passed to `loadTrackingPixel`. */
|
|
195
|
+
interface PreprPixelConfig {
|
|
196
|
+
destinations?: {
|
|
197
|
+
/** Also push tracked events to Google Tag Manager's `dataLayer`. */
|
|
198
|
+
googleTagManager?: boolean;
|
|
199
|
+
};
|
|
200
|
+
/**
|
|
201
|
+
* How much of a personalized or A/B element must be in view to count as an
|
|
202
|
+
* impression, as the pixel defines it.
|
|
203
|
+
*/
|
|
204
|
+
variantImpressionThreshold?: number;
|
|
205
|
+
}
|
|
206
|
+
type PreprQueueArgs = unknown[];
|
|
207
|
+
interface PreprQueueFn {
|
|
208
|
+
(...args: PreprQueueArgs): void;
|
|
209
|
+
queue: PreprQueueArgs[];
|
|
210
|
+
t: number;
|
|
211
|
+
process?: (...args: PreprQueueArgs) => void;
|
|
212
|
+
}
|
|
213
|
+
declare global {
|
|
214
|
+
interface Window {
|
|
215
|
+
prepr?: PreprQueueFn;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Install the queue stub, inject the pixel script, then queue
|
|
220
|
+
* `('init', trackingId, config?)` and `('event', 'pageload')` in that order.
|
|
221
|
+
*
|
|
222
|
+
* Idempotent, and a no-op outside a browser.
|
|
223
|
+
*/
|
|
224
|
+
declare function loadTrackingPixel(trackingId: string, config?: PreprPixelConfig): void;
|
|
225
|
+
/**
|
|
226
|
+
* Send a tracking event through `window.prepr`. Only depends on `window.prepr`
|
|
227
|
+
* existing, never on how it got installed. Warns once and returns quietly when
|
|
228
|
+
* no pixel is present.
|
|
229
|
+
*/
|
|
230
|
+
declare function trackEvent(name: string, data?: string | Record<string, unknown>): void;
|
|
231
|
+
/** Loader-independent like `trackEvent`; warns once if no pixel is installed. */
|
|
232
|
+
declare function setTrackingParam(key: string, value: string): void;
|
|
136
233
|
|
|
137
|
-
export type
|
|
234
|
+
export { type Locale as L, type PreprFeatures as P, type ResolvedPreprFeatures as R, type PreprSegment as a, type PreprVariant as b, type PreprToolbarProps as c, type PreprPreviewOptions as d, type PreprErrorCode as e, type PreprHeaders as f, type PreprEnvironment as g, type PreprEventType as h, type PreprFeatureConfig as i, type PreprHeaderName as j, type PreprPixelConfig as k, type PreprToolbarComponentProps as l, type PreprToolbarOptions as m, loadTrackingPixel as n, setTrackingParam as s, trackEvent as t };
|
|
@@ -2,9 +2,12 @@ type Dictionary = Record<string, unknown>;
|
|
|
2
2
|
declare const dictionaries: {
|
|
3
3
|
en: Dictionary;
|
|
4
4
|
nl: Dictionary;
|
|
5
|
+
fr: Dictionary;
|
|
6
|
+
de: Dictionary;
|
|
5
7
|
};
|
|
6
8
|
type Locale = keyof typeof dictionaries;
|
|
7
9
|
|
|
10
|
+
/** A segment from Prepr, as listed in the toolbar's segment picker. */
|
|
8
11
|
interface PreprSegment {
|
|
9
12
|
readonly _id: string;
|
|
10
13
|
readonly name: string;
|
|
@@ -39,8 +42,14 @@ interface ResolvedPreprFeatures {
|
|
|
39
42
|
readonly abTesting: boolean;
|
|
40
43
|
readonly editMode: boolean;
|
|
41
44
|
}
|
|
45
|
+
/** Options shared by the toolbar and the preview runtime. */
|
|
42
46
|
interface PreprToolbarOptions {
|
|
47
|
+
/** Log what the toolkit does to the browser console. Default `false`. */
|
|
43
48
|
debug?: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Language of the toolbar and the visual editor labels. Defaults to the
|
|
51
|
+
* first supported browser language, then English.
|
|
52
|
+
*/
|
|
44
53
|
locale?: Locale;
|
|
45
54
|
/** Disable features app-wide. Pass the same object to the middleware. */
|
|
46
55
|
features?: PreprFeatures;
|
|
@@ -64,10 +73,24 @@ interface PreprPreviewOptions extends PreprToolbarOptions {
|
|
|
64
73
|
*/
|
|
65
74
|
ui?: boolean;
|
|
66
75
|
/**
|
|
67
|
-
* Replace the `*.prepr.io` editor-origin wildcard with an exact list.
|
|
68
|
-
* Intended for self-hosted
|
|
76
|
+
* Replace the `*.prepr.io` editor-origin wildcard with an exact list, e.g.
|
|
77
|
+
* `['http://acme.localhost:8000']`. Intended for self-hosted or locally run
|
|
78
|
+
* editors; when set, the wildcard no longer applies. Entries are compared to
|
|
79
|
+
* the editor's origin exactly: scheme, host and port.
|
|
80
|
+
*
|
|
81
|
+
* `['*']` accepts any editor origin. Use it for development only: any page
|
|
82
|
+
* that frames the preview can then switch on preview and edit mode and
|
|
83
|
+
* receives the field-edit events, which carry content item ids.
|
|
69
84
|
*/
|
|
70
85
|
allowedEditorOrigins?: string[];
|
|
86
|
+
/**
|
|
87
|
+
* Set when your preview token uses GraphQL strict mode, where required
|
|
88
|
+
* fields are never null. The editor then holds back new entries until
|
|
89
|
+
* their required fields are filled, and never sends a cleared required
|
|
90
|
+
* field as null. Applies to live preview on the same page as well, so the
|
|
91
|
+
* live preview helpers do not need their own `strictMode`.
|
|
92
|
+
*/
|
|
93
|
+
strictMode?: boolean;
|
|
71
94
|
/**
|
|
72
95
|
* Strip the invisible stega characters out of visible text at runtime.
|
|
73
96
|
* Default `true`.
|
|
@@ -83,6 +106,10 @@ interface PreprPreviewOptions extends PreprToolbarOptions {
|
|
|
83
106
|
*/
|
|
84
107
|
autoClean?: boolean;
|
|
85
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* The data the toolbar shows. `getToolbarProps` builds it on the server from
|
|
111
|
+
* the request headers.
|
|
112
|
+
*/
|
|
86
113
|
interface PreprToolbarProps {
|
|
87
114
|
/**
|
|
88
115
|
* Server-resolved active segment. Optional: omit it with `segments`
|
|
@@ -108,10 +135,26 @@ interface PreprToolbarProps {
|
|
|
108
135
|
interface PreprToolbarComponentProps extends PreprToolbarProps {
|
|
109
136
|
options?: PreprPreviewOptions;
|
|
110
137
|
}
|
|
138
|
+
/**
|
|
139
|
+
* Header names the Prepr API expects; the casing must match exactly.
|
|
140
|
+
*
|
|
141
|
+
* @deprecated Unused by the toolkit; use the keys of `PreprHeaders`.
|
|
142
|
+
*/
|
|
111
143
|
type PreprHeaderName = 'prepr-customer-id' | 'Prepr-Segments' | 'Prepr-ABtesting' | 'User-Agent' | 'Prepr-User-Agent';
|
|
144
|
+
/** The two sides of an A/B test. */
|
|
112
145
|
type PreprVariant = 'A' | 'B';
|
|
146
|
+
/** @deprecated Unused by the toolkit; kept so existing imports compile. */
|
|
113
147
|
type PreprEnvironment = 'preview' | 'production';
|
|
114
|
-
|
|
148
|
+
/**
|
|
149
|
+
* Events the preview announces: as a `prepr_preview_bar` `CustomEvent` on
|
|
150
|
+
* `window`, and to the Prepr editor when the page runs inside it.
|
|
151
|
+
*/
|
|
152
|
+
type PreprEventType = 'segment_changed' | 'variant_changed' | 'edit_mode_toggled' | 'preview_mode_toggled' | 'getScrollPosition' | 'loaded' | 'field_edit_requested' | 'live_ready' | 'navigation_blocked';
|
|
153
|
+
/**
|
|
154
|
+
* The headers to send with a Prepr GraphQL request so the API personalizes
|
|
155
|
+
* the response for this visitor. `getPreprHeaders` returns them; spread them
|
|
156
|
+
* into the request's `headers`.
|
|
157
|
+
*/
|
|
115
158
|
interface PreprHeaders {
|
|
116
159
|
readonly 'prepr-customer-id'?: string;
|
|
117
160
|
readonly 'Prepr-Segments'?: string;
|
|
@@ -132,6 +175,60 @@ interface PreprHeaders {
|
|
|
132
175
|
readonly 'Prepr-User-Agent'?: string;
|
|
133
176
|
readonly 'Prepr-Package'?: string;
|
|
134
177
|
}
|
|
135
|
-
|
|
178
|
+
/** Why a `PreprError` was thrown; read it from `error.code`. */
|
|
179
|
+
type PreprErrorCode = 'INVALID_TOKEN' | 'MISSING_TOKEN' | 'HTTP_ERROR' | 'FETCH_ERROR' | 'INVALID_RESPONSE' | 'CONTEXT_ERROR';
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Loader + typed facade for Prepr's CDN tracking pixel, so consumers don't have
|
|
183
|
+
* to paste a `<script>` tag. The pixel itself lives on the CDN; this only sets
|
|
184
|
+
* up the handoff.
|
|
185
|
+
*
|
|
186
|
+
* The CDN script expects a queue stub to already exist when it loads, so the
|
|
187
|
+
* contract must be reproduced exactly:
|
|
188
|
+
* - `window.prepr` pushes `arguments` onto `.queue` until the real script
|
|
189
|
+
* lands and replaces `.process`.
|
|
190
|
+
* - `.t` must be a `Date.now()` timestamp.
|
|
191
|
+
* - The tag is inserted async, `src` cache-busted every 24h via
|
|
192
|
+
* `Math.ceil(Date.now() / cacheTime) * cacheTime`.
|
|
193
|
+
*/
|
|
194
|
+
/** Config for the Prepr tracking pixel, passed to `loadTrackingPixel`. */
|
|
195
|
+
interface PreprPixelConfig {
|
|
196
|
+
destinations?: {
|
|
197
|
+
/** Also push tracked events to Google Tag Manager's `dataLayer`. */
|
|
198
|
+
googleTagManager?: boolean;
|
|
199
|
+
};
|
|
200
|
+
/**
|
|
201
|
+
* How much of a personalized or A/B element must be in view to count as an
|
|
202
|
+
* impression, as the pixel defines it.
|
|
203
|
+
*/
|
|
204
|
+
variantImpressionThreshold?: number;
|
|
205
|
+
}
|
|
206
|
+
type PreprQueueArgs = unknown[];
|
|
207
|
+
interface PreprQueueFn {
|
|
208
|
+
(...args: PreprQueueArgs): void;
|
|
209
|
+
queue: PreprQueueArgs[];
|
|
210
|
+
t: number;
|
|
211
|
+
process?: (...args: PreprQueueArgs) => void;
|
|
212
|
+
}
|
|
213
|
+
declare global {
|
|
214
|
+
interface Window {
|
|
215
|
+
prepr?: PreprQueueFn;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Install the queue stub, inject the pixel script, then queue
|
|
220
|
+
* `('init', trackingId, config?)` and `('event', 'pageload')` in that order.
|
|
221
|
+
*
|
|
222
|
+
* Idempotent, and a no-op outside a browser.
|
|
223
|
+
*/
|
|
224
|
+
declare function loadTrackingPixel(trackingId: string, config?: PreprPixelConfig): void;
|
|
225
|
+
/**
|
|
226
|
+
* Send a tracking event through `window.prepr`. Only depends on `window.prepr`
|
|
227
|
+
* existing, never on how it got installed. Warns once and returns quietly when
|
|
228
|
+
* no pixel is present.
|
|
229
|
+
*/
|
|
230
|
+
declare function trackEvent(name: string, data?: string | Record<string, unknown>): void;
|
|
231
|
+
/** Loader-independent like `trackEvent`; warns once if no pixel is installed. */
|
|
232
|
+
declare function setTrackingParam(key: string, value: string): void;
|
|
136
233
|
|
|
137
|
-
export type
|
|
234
|
+
export { type Locale as L, type PreprFeatures as P, type ResolvedPreprFeatures as R, type PreprSegment as a, type PreprVariant as b, type PreprToolbarProps as c, type PreprPreviewOptions as d, type PreprErrorCode as e, type PreprHeaders as f, type PreprEnvironment as g, type PreprEventType as h, type PreprFeatureConfig as i, type PreprHeaderName as j, type PreprPixelConfig as k, type PreprToolbarComponentProps as l, type PreprToolbarOptions as m, loadTrackingPixel as n, setTrackingParam as s, trackEvent as t };
|