@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
package/dist/index.js
CHANGED
|
@@ -1,27 +1,14 @@
|
|
|
1
1
|
import {
|
|
2
|
-
COOKIE_HUBSPOT,
|
|
3
|
-
COOKIE_PREVIEW_MODE,
|
|
4
|
-
COOKIE_SEGMENT,
|
|
5
|
-
COOKIE_UID,
|
|
6
|
-
COOKIE_VARIANT,
|
|
7
|
-
ONE_YEAR_SECONDS,
|
|
8
|
-
PARAM_HIDE_BAR,
|
|
9
|
-
PARAM_SEGMENT,
|
|
10
|
-
PARAM_VARIANT,
|
|
11
2
|
PreprToolbarElement,
|
|
12
3
|
createPreprPreview,
|
|
13
4
|
createToolbarStore,
|
|
5
|
+
decodeStega,
|
|
14
6
|
definePreprToolbar,
|
|
15
7
|
loadTrackingPixel,
|
|
16
8
|
setTrackingParam,
|
|
9
|
+
stegaClean,
|
|
17
10
|
trackEvent
|
|
18
|
-
} from "./chunk-
|
|
19
|
-
import {
|
|
20
|
-
isPersonalizedResponse
|
|
21
|
-
} from "./chunk-3NCEVJJ3.js";
|
|
22
|
-
import {
|
|
23
|
-
stegaClean
|
|
24
|
-
} from "./chunk-S5RWVMDJ.js";
|
|
11
|
+
} from "./chunk-WBMN4L7G.js";
|
|
25
12
|
import {
|
|
26
13
|
PreprError,
|
|
27
14
|
extractAccessToken,
|
|
@@ -32,11 +19,333 @@ import {
|
|
|
32
19
|
getPreprUUIDFromHeaders,
|
|
33
20
|
getToolbarPropsFromHeaders,
|
|
34
21
|
validatePreprToken
|
|
35
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-DSJ22P6J.js";
|
|
36
23
|
import {
|
|
37
24
|
VERSION,
|
|
38
25
|
resolveFeatures
|
|
39
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-33GWVTRJ.js";
|
|
27
|
+
import {
|
|
28
|
+
createLiveBridge,
|
|
29
|
+
createLiveStore
|
|
30
|
+
} from "./chunk-A2J7R4LR.js";
|
|
31
|
+
import "./chunk-Y7JWV7WV.js";
|
|
32
|
+
import {
|
|
33
|
+
COOKIE_HUBSPOT,
|
|
34
|
+
COOKIE_PREVIEW_MODE,
|
|
35
|
+
COOKIE_SEGMENT,
|
|
36
|
+
COOKIE_UID,
|
|
37
|
+
COOKIE_VARIANT,
|
|
38
|
+
HEADER_LIVE_RENDER,
|
|
39
|
+
ONE_YEAR_SECONDS,
|
|
40
|
+
PARAM_HIDE_BAR,
|
|
41
|
+
PARAM_SEGMENT,
|
|
42
|
+
PARAM_VARIANT,
|
|
43
|
+
TOOLBAR_TAG
|
|
44
|
+
} from "./chunk-UTKH7DOI.js";
|
|
45
|
+
import {
|
|
46
|
+
collectFields,
|
|
47
|
+
isObject,
|
|
48
|
+
normalizeQuery,
|
|
49
|
+
parsePatchLog,
|
|
50
|
+
readQueryDocument
|
|
51
|
+
} from "./chunk-KM2GME62.js";
|
|
52
|
+
import {
|
|
53
|
+
createScopedLogger
|
|
54
|
+
} from "./chunk-V7MCHPE7.js";
|
|
55
|
+
|
|
56
|
+
// src/core/preview-attrs.ts
|
|
57
|
+
function previewAttrs(target, options) {
|
|
58
|
+
if (!options.enabled || !target?.id || !target.field) return {};
|
|
59
|
+
const attrs = {
|
|
60
|
+
"data-prepr-encoded": "",
|
|
61
|
+
"data-prepr-id": target.id,
|
|
62
|
+
"data-prepr-field": target.field
|
|
63
|
+
};
|
|
64
|
+
if (target.locale) attrs["data-prepr-locale"] = target.locale;
|
|
65
|
+
if (target.entryId) attrs["data-prepr-entry-id"] = target.entryId;
|
|
66
|
+
return attrs;
|
|
67
|
+
}
|
|
68
|
+
var URL_BASE = "https://prepr.invalid";
|
|
69
|
+
function stegaTarget(value, options = {}) {
|
|
70
|
+
const decoded = value ? decodeStega(value) : null;
|
|
71
|
+
if (!decoded) return null;
|
|
72
|
+
let url;
|
|
73
|
+
let id;
|
|
74
|
+
try {
|
|
75
|
+
url = new URL(decoded.href, URL_BASE);
|
|
76
|
+
id = decodeURIComponent(url.pathname.split("/").pop() ?? "");
|
|
77
|
+
} catch {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
const field = url.searchParams.get("field");
|
|
81
|
+
if (!id || !field) return null;
|
|
82
|
+
return {
|
|
83
|
+
id,
|
|
84
|
+
field: options.field ? `${field.slice(0, field.lastIndexOf(".") + 1)}${options.field}` : field,
|
|
85
|
+
locale: url.searchParams.get("locale")
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// src/core/live-preview/edit-links.ts
|
|
90
|
+
import {
|
|
91
|
+
vercelStegaCombine,
|
|
92
|
+
vercelStegaDecode,
|
|
93
|
+
vercelStegaSplit
|
|
94
|
+
} from "@vercel/stega";
|
|
95
|
+
var ENTRY_PARAM = "entry";
|
|
96
|
+
var TOP_LEVEL_ENTRY = /^[A-Za-z0-9_]+\.\d+$/;
|
|
97
|
+
function entryIdOf(element) {
|
|
98
|
+
if (!isObject(element)) return void 0;
|
|
99
|
+
if (typeof element._id === "string") return element._id;
|
|
100
|
+
if (element.__typename !== "Assets" || !Array.isArray(element.items)) {
|
|
101
|
+
return void 0;
|
|
102
|
+
}
|
|
103
|
+
const first = element.items[0];
|
|
104
|
+
return isObject(first) && typeof first._id === "string" ? first._id : void 0;
|
|
105
|
+
}
|
|
106
|
+
function annotate(value, ctx) {
|
|
107
|
+
if (!ctx.entryId) return value;
|
|
108
|
+
const { cleaned, encoded } = vercelStegaSplit(value);
|
|
109
|
+
if (!encoded) return value;
|
|
110
|
+
let payload;
|
|
111
|
+
try {
|
|
112
|
+
payload = vercelStegaDecode(encoded);
|
|
113
|
+
} catch {
|
|
114
|
+
return value;
|
|
115
|
+
}
|
|
116
|
+
if (typeof payload?.href !== "string") return value;
|
|
117
|
+
let url;
|
|
118
|
+
try {
|
|
119
|
+
url = new URL(payload.href);
|
|
120
|
+
} catch {
|
|
121
|
+
return value;
|
|
122
|
+
}
|
|
123
|
+
if (url.searchParams.has(ENTRY_PARAM)) return value;
|
|
124
|
+
url.searchParams.set(ENTRY_PARAM, ctx.entryId);
|
|
125
|
+
const itemId = decodeURIComponent(url.pathname.split("/").pop() ?? "");
|
|
126
|
+
if (!url.searchParams.has("field") && ctx.entryField && TOP_LEVEL_ENTRY.test(ctx.entryField) && itemId === ctx.entryOwnerId) {
|
|
127
|
+
url.searchParams.set("field", ctx.entryField);
|
|
128
|
+
}
|
|
129
|
+
return vercelStegaCombine(
|
|
130
|
+
cleaned,
|
|
131
|
+
{ ...payload, href: url.toString() },
|
|
132
|
+
false
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
function walk(value, selections, ctx) {
|
|
136
|
+
if (typeof value === "string") return annotate(value, ctx);
|
|
137
|
+
if (Array.isArray(value)) {
|
|
138
|
+
let changed2 = false;
|
|
139
|
+
const next2 = value.map((element, index) => {
|
|
140
|
+
const path = [...ctx.path, String(index)];
|
|
141
|
+
const entryId = ctx.inAssets ? void 0 : entryIdOf(element);
|
|
142
|
+
const entry = entryId ? {
|
|
143
|
+
entryId,
|
|
144
|
+
entryField: ctx.ownerId ? path.join(".") : void 0,
|
|
145
|
+
entryOwnerId: ctx.ownerId,
|
|
146
|
+
inAssets: isObject(element) && element._id === void 0
|
|
147
|
+
} : {};
|
|
148
|
+
const out = walk(element, selections, { ...ctx, ...entry, path });
|
|
149
|
+
if (out !== element) changed2 = true;
|
|
150
|
+
return out;
|
|
151
|
+
});
|
|
152
|
+
return changed2 ? next2 : value;
|
|
153
|
+
}
|
|
154
|
+
if (!isObject(value)) return value;
|
|
155
|
+
const id = typeof value._id === "string" ? value._id : void 0;
|
|
156
|
+
const typename = typeof value.__typename === "string" ? value.__typename : void 0;
|
|
157
|
+
const fields = ctx.doc && selections ? collectFields(selections, typename, ctx.doc) : null;
|
|
158
|
+
let changed = false;
|
|
159
|
+
const next = {};
|
|
160
|
+
for (const [key, child] of Object.entries(value)) {
|
|
161
|
+
const field = fields?.get(key);
|
|
162
|
+
const name = field?.name ?? key;
|
|
163
|
+
const out = walk(child, field?.selections ?? null, {
|
|
164
|
+
...ctx,
|
|
165
|
+
ownerId: id ?? ctx.ownerId,
|
|
166
|
+
path: id ? [name] : [...ctx.path, name]
|
|
167
|
+
});
|
|
168
|
+
if (out !== child) changed = true;
|
|
169
|
+
next[key] = out;
|
|
170
|
+
}
|
|
171
|
+
return changed ? next : value;
|
|
172
|
+
}
|
|
173
|
+
function annotateEditLinks(result, query, operationName) {
|
|
174
|
+
let doc = null;
|
|
175
|
+
if (query !== void 0) {
|
|
176
|
+
try {
|
|
177
|
+
doc = readQueryDocument(query, operationName);
|
|
178
|
+
} catch {
|
|
179
|
+
doc = null;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return walk(result, doc?.operation ?? null, { doc, path: [] });
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// src/core/live-preview/morph.ts
|
|
186
|
+
function morphElement(current, next) {
|
|
187
|
+
syncAttributes(current, next);
|
|
188
|
+
morphChildren(current, next);
|
|
189
|
+
}
|
|
190
|
+
var SKIP_ATTR = "data-prepr-morph-skip";
|
|
191
|
+
var RUNTIME_ATTR_PREFIXES = ["data-prepr-"];
|
|
192
|
+
function isRuntimeAttribute(name) {
|
|
193
|
+
return RUNTIME_ATTR_PREFIXES.some((prefix) => name.startsWith(prefix));
|
|
194
|
+
}
|
|
195
|
+
function syncAttributes(current, next) {
|
|
196
|
+
for (const { name } of Array.from(current.attributes)) {
|
|
197
|
+
if (!next.hasAttribute(name) && !isRuntimeAttribute(name)) {
|
|
198
|
+
current.removeAttribute(name);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
for (const { name, value } of Array.from(next.attributes)) {
|
|
202
|
+
if (current.getAttribute(name) !== value) current.setAttribute(name, value);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
function isSkipped(node) {
|
|
206
|
+
return node.nodeType === Node.ELEMENT_NODE && (node.hasAttribute(SKIP_ATTR) || node.localName === TOOLBAR_TAG);
|
|
207
|
+
}
|
|
208
|
+
function sameKind(a, b) {
|
|
209
|
+
if (a.nodeType !== b.nodeType) return false;
|
|
210
|
+
if (a.nodeType !== Node.ELEMENT_NODE) return true;
|
|
211
|
+
const ea = a;
|
|
212
|
+
const eb = b;
|
|
213
|
+
return ea.localName === eb.localName && ea.id === eb.id;
|
|
214
|
+
}
|
|
215
|
+
function morphChildren(current, next) {
|
|
216
|
+
const wanted = Array.from(next.childNodes).filter((n) => !isSkipped(n));
|
|
217
|
+
const existing = Array.from(current.childNodes).filter((n) => !isSkipped(n));
|
|
218
|
+
wanted.forEach((target, i) => {
|
|
219
|
+
const node = existing[i];
|
|
220
|
+
if (node && sameKind(node, target)) {
|
|
221
|
+
if (node.nodeType === Node.ELEMENT_NODE) {
|
|
222
|
+
const element = node;
|
|
223
|
+
if (element.localName === "script") return;
|
|
224
|
+
if (element.localName === "astro-island" && !element.isEqualNode(target)) {
|
|
225
|
+
element.replaceWith(adopt(target, current));
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
morphElement(element, target);
|
|
229
|
+
} else if (node.nodeValue !== target.nodeValue) {
|
|
230
|
+
node.nodeValue = target.nodeValue;
|
|
231
|
+
}
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
const replacement = adopt(target, current);
|
|
235
|
+
if (node) node.replaceWith(replacement);
|
|
236
|
+
else current.appendChild(replacement);
|
|
237
|
+
});
|
|
238
|
+
for (const extra of existing.slice(wanted.length)) extra.remove();
|
|
239
|
+
}
|
|
240
|
+
function adopt(node, parent) {
|
|
241
|
+
const copy = parent.ownerDocument.importNode(node, true);
|
|
242
|
+
if (copy.nodeType === Node.ELEMENT_NODE) {
|
|
243
|
+
const element = copy;
|
|
244
|
+
const scripts = element.localName === "script" ? [element] : Array.from(element.querySelectorAll("script"));
|
|
245
|
+
scripts.forEach((s) => s.setAttribute("data-prepr-morphed", ""));
|
|
246
|
+
}
|
|
247
|
+
return copy;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
// src/core/live-preview/html-live.ts
|
|
251
|
+
var debug = createScopedLogger("live-preview:html");
|
|
252
|
+
var COMPLETE_DOCUMENT = /<\/html>\s*$/i;
|
|
253
|
+
var SYNC_DEBOUNCE_MS = 150;
|
|
254
|
+
function startHtmlLivePreview(options = {}) {
|
|
255
|
+
if (typeof window === "undefined" || window.self === window.top) {
|
|
256
|
+
return { stop() {
|
|
257
|
+
} };
|
|
258
|
+
}
|
|
259
|
+
const store = createLiveStore();
|
|
260
|
+
const bridge = createLiveBridge(store, {
|
|
261
|
+
allowedEditorOrigins: () => options.allowedEditorOrigins,
|
|
262
|
+
strictMode: () => options.strictMode
|
|
263
|
+
});
|
|
264
|
+
bridge.start();
|
|
265
|
+
let timer = null;
|
|
266
|
+
let inFlight = false;
|
|
267
|
+
let pending = null;
|
|
268
|
+
let stopped = false;
|
|
269
|
+
const render = async (log) => {
|
|
270
|
+
inFlight = true;
|
|
271
|
+
try {
|
|
272
|
+
const response = await fetch(window.location.href, {
|
|
273
|
+
method: log.length ? "POST" : "GET",
|
|
274
|
+
headers: log.length ? { "Content-Type": "application/json", [HEADER_LIVE_RENDER]: "1" } : {},
|
|
275
|
+
body: log.length ? JSON.stringify({ log }) : void 0,
|
|
276
|
+
credentials: "same-origin",
|
|
277
|
+
cache: "no-store"
|
|
278
|
+
});
|
|
279
|
+
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
|
280
|
+
const html = await response.text();
|
|
281
|
+
if (stopped) return;
|
|
282
|
+
if (!COMPLETE_DOCUMENT.test(html)) {
|
|
283
|
+
throw new Error("incomplete page; a component failed to render");
|
|
284
|
+
}
|
|
285
|
+
const next = new DOMParser().parseFromString(html, "text/html");
|
|
286
|
+
if (next.title && next.title !== document.title)
|
|
287
|
+
document.title = next.title;
|
|
288
|
+
morphElement(document.body, next.body);
|
|
289
|
+
} catch (error) {
|
|
290
|
+
debug.log("re-render failed", error);
|
|
291
|
+
} finally {
|
|
292
|
+
inFlight = false;
|
|
293
|
+
}
|
|
294
|
+
if (pending && !stopped) {
|
|
295
|
+
const queued = pending;
|
|
296
|
+
pending = null;
|
|
297
|
+
void render(queued);
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
const schedule = (log) => {
|
|
301
|
+
if (timer) clearTimeout(timer);
|
|
302
|
+
timer = setTimeout(() => {
|
|
303
|
+
timer = null;
|
|
304
|
+
if (inFlight) pending = log;
|
|
305
|
+
else void render(log);
|
|
306
|
+
}, SYNC_DEBOUNCE_MS);
|
|
307
|
+
};
|
|
308
|
+
const offLog = store.onLogChange((log) => {
|
|
309
|
+
if (log.length) schedule(log);
|
|
310
|
+
});
|
|
311
|
+
const offInvalidate = store.onInvalidate(() => schedule([]));
|
|
312
|
+
return {
|
|
313
|
+
stop() {
|
|
314
|
+
stopped = true;
|
|
315
|
+
if (timer) clearTimeout(timer);
|
|
316
|
+
offLog();
|
|
317
|
+
offInvalidate();
|
|
318
|
+
bridge.stop();
|
|
319
|
+
}
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// src/core/live-preview/live-request.ts
|
|
324
|
+
var MAX_BODY_BYTES = 1e6;
|
|
325
|
+
function requestOrigin(request) {
|
|
326
|
+
const url = new URL(request.url);
|
|
327
|
+
const proto = request.headers.get("x-forwarded-proto")?.split(",")[0]?.trim();
|
|
328
|
+
if (proto === "https" || proto === "http") url.protocol = `${proto}:`;
|
|
329
|
+
return url.origin;
|
|
330
|
+
}
|
|
331
|
+
async function readLiveLogFromRequest(request) {
|
|
332
|
+
try {
|
|
333
|
+
if (request.method !== "POST") return [];
|
|
334
|
+
if (request.headers.get(HEADER_LIVE_RENDER) !== "1") return [];
|
|
335
|
+
const origin = request.headers.get("origin");
|
|
336
|
+
if (!origin || origin !== requestOrigin(request)) return [];
|
|
337
|
+
const type = request.headers.get("content-type") ?? "";
|
|
338
|
+
if (!type.toLowerCase().startsWith("application/json")) return [];
|
|
339
|
+
const length = Number(request.headers.get("content-length") ?? "0");
|
|
340
|
+
if (length > MAX_BODY_BYTES) return [];
|
|
341
|
+
const text = await request.clone().text();
|
|
342
|
+
if (text.length > MAX_BODY_BYTES) return [];
|
|
343
|
+
const body = JSON.parse(text);
|
|
344
|
+
return parsePatchLog(body?.log);
|
|
345
|
+
} catch {
|
|
346
|
+
return [];
|
|
347
|
+
}
|
|
348
|
+
}
|
|
40
349
|
|
|
41
350
|
// src/core/middleware.ts
|
|
42
351
|
var UTM_PARAMS = [
|
|
@@ -47,6 +356,16 @@ var UTM_PARAMS = [
|
|
|
47
356
|
"utm_campaign"
|
|
48
357
|
];
|
|
49
358
|
var MAX_HEADER_VALUE_LENGTH = 2048;
|
|
359
|
+
function randomUUID() {
|
|
360
|
+
if (typeof crypto.randomUUID === "function") return crypto.randomUUID();
|
|
361
|
+
const bytes = crypto.getRandomValues(new Uint8Array(16));
|
|
362
|
+
bytes[6] = bytes[6] & 15 | 64;
|
|
363
|
+
bytes[8] = bytes[8] & 63 | 128;
|
|
364
|
+
const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join(
|
|
365
|
+
""
|
|
366
|
+
);
|
|
367
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
368
|
+
}
|
|
50
369
|
function sanitizeHeaderValue(value) {
|
|
51
370
|
const stripped = value.replace(/[\u0000-\u001f\u007f]/g, "");
|
|
52
371
|
return stripped.length > MAX_HEADER_VALUE_LENGTH ? stripped.slice(0, MAX_HEADER_VALUE_LENGTH) : stripped;
|
|
@@ -121,7 +440,7 @@ function processFrameworkRequest(request, opts, framework) {
|
|
|
121
440
|
}
|
|
122
441
|
let uid = sanitizeHeaderValue(requestCookies.get(COOKIE_UID) ?? "");
|
|
123
442
|
if (!uid) {
|
|
124
|
-
uid =
|
|
443
|
+
uid = randomUUID();
|
|
125
444
|
responseCookies.push({
|
|
126
445
|
name: COOKIE_UID,
|
|
127
446
|
value: uid,
|
|
@@ -190,16 +509,13 @@ function processFrameworkRequest(request, opts, framework) {
|
|
|
190
509
|
});
|
|
191
510
|
}
|
|
192
511
|
}
|
|
193
|
-
if (requestHeaders.has("Prepr-Segments")) {
|
|
194
|
-
requestHeaders.delete("Prepr-Customer-Id");
|
|
195
|
-
requestHeaders.delete("Prepr-Customer-Id-Created");
|
|
196
|
-
}
|
|
197
512
|
return { requestHeaders, responseCookies };
|
|
198
513
|
}
|
|
199
514
|
export {
|
|
200
515
|
PreprError,
|
|
201
516
|
PreprToolbarElement,
|
|
202
517
|
VERSION,
|
|
518
|
+
annotateEditLinks,
|
|
203
519
|
createPreprPreview,
|
|
204
520
|
createToolbarStore,
|
|
205
521
|
definePreprToolbar,
|
|
@@ -210,12 +526,17 @@ export {
|
|
|
210
526
|
getPreprHeadersFromHeaders,
|
|
211
527
|
getPreprUUIDFromHeaders,
|
|
212
528
|
getToolbarPropsFromHeaders,
|
|
213
|
-
isPersonalizedResponse,
|
|
214
529
|
loadTrackingPixel,
|
|
530
|
+
normalizeQuery,
|
|
531
|
+
parsePatchLog,
|
|
532
|
+
previewAttrs,
|
|
215
533
|
processPreprRequest,
|
|
534
|
+
readLiveLogFromRequest,
|
|
216
535
|
resolveFeatures,
|
|
217
536
|
setTrackingParam,
|
|
537
|
+
startHtmlLivePreview,
|
|
218
538
|
stegaClean,
|
|
539
|
+
stegaTarget,
|
|
219
540
|
trackEvent,
|
|
220
541
|
validatePreprToken
|
|
221
542
|
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createLiveBridge,
|
|
3
|
+
createLiveStore
|
|
4
|
+
} from "./chunk-A2J7R4LR.js";
|
|
5
|
+
import "./chunk-Y7JWV7WV.js";
|
|
6
|
+
import "./chunk-UTKH7DOI.js";
|
|
7
|
+
import {
|
|
8
|
+
applyPatchLog,
|
|
9
|
+
normalizeQuery,
|
|
10
|
+
parsePatchLog
|
|
11
|
+
} from "./chunk-KM2GME62.js";
|
|
12
|
+
import "./chunk-V7MCHPE7.js";
|
|
13
|
+
export {
|
|
14
|
+
applyPatchLog,
|
|
15
|
+
createLiveBridge,
|
|
16
|
+
createLiveStore,
|
|
17
|
+
normalizeQuery,
|
|
18
|
+
parsePatchLog
|
|
19
|
+
};
|