@preprio/toolkit 0.5.0-rc.1 → 0.6.0-alpha.0
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 +300 -19
- package/dist/astro/chunk-3UVUDDNY.js +173 -0
- package/dist/astro/graphql.cjs +983 -0
- package/dist/astro/graphql.d.cts +231 -0
- package/dist/astro/graphql.d.ts +231 -0
- package/dist/astro/graphql.js +893 -0
- package/dist/astro/index-XT_z-RYT.d.cts +130 -0
- package/dist/astro/index-XT_z-RYT.d.ts +130 -0
- package/dist/astro/index.cjs +14 -1
- package/dist/astro/index.d.cts +1 -120
- package/dist/astro/index.d.ts +1 -120
- package/dist/astro/index.js +15 -153
- package/dist/{chunk-4JNKYIEV.js → chunk-BJ2LBLWO.js} +69 -268
- package/dist/chunk-DGZA7KX7.js +172 -0
- package/dist/chunk-YR7P4IWE.js +187 -0
- package/dist/graphql.cjs +894 -0
- package/dist/graphql.d.cts +231 -0
- package/dist/graphql.d.ts +231 -0
- package/dist/graphql.js +787 -0
- package/dist/index.cjs +74 -111
- package/dist/index.d.cts +11 -62
- package/dist/index.d.ts +11 -62
- package/dist/index.js +23 -167
- package/dist/nextjs/chunk-U4HXENF7.js +231 -0
- package/dist/nextjs/components.cjs +188 -114
- package/dist/nextjs/components.d.cts +33 -2
- package/dist/nextjs/components.d.ts +33 -2
- package/dist/nextjs/components.js +132 -4
- package/dist/nextjs/graphql.cjs +1315 -0
- package/dist/nextjs/graphql.d.cts +361 -0
- package/dist/nextjs/graphql.d.ts +361 -0
- package/dist/nextjs/graphql.js +1218 -0
- package/dist/nextjs/index.cjs +126 -6
- package/dist/nextjs/index.d.cts +53 -141
- package/dist/nextjs/index.d.ts +53 -141
- package/dist/nextjs/index.js +113 -203
- package/dist/nextjs/server-CjpELYvq.d.cts +156 -0
- package/dist/nextjs/server-CjpELYvq.d.ts +156 -0
- package/dist/nuxt/chunk-P6ENNAEE.js +417 -0
- package/dist/nuxt/graphql.cjs +990 -0
- package/dist/nuxt/graphql.d.cts +228 -0
- package/dist/nuxt/graphql.d.ts +228 -0
- package/dist/nuxt/graphql.js +894 -0
- package/dist/nuxt/index.cjs +14 -1
- package/dist/nuxt/index.d.cts +3 -148
- package/dist/nuxt/index.d.ts +3 -148
- package/dist/nuxt/index.js +15 -391
- package/dist/nuxt/server-8v6OHbsw.d.cts +158 -0
- package/dist/nuxt/server-8v6OHbsw.d.ts +158 -0
- package/dist/pixel-DwW7cXJm.d.cts +49 -0
- package/dist/pixel-DwW7cXJm.d.ts +49 -0
- package/dist/react/components.cjs +86 -112
- package/dist/react/components.js +86 -112
- package/dist/server-Brr1UgtW.d.ts +59 -0
- package/dist/server-DJuS3YU0.d.cts +59 -0
- package/dist/sveltekit/chunk-FSARVMG5.js +413 -0
- package/dist/sveltekit/graphql.cjs +996 -0
- package/dist/sveltekit/graphql.d.cts +233 -0
- package/dist/sveltekit/graphql.d.ts +233 -0
- package/dist/sveltekit/graphql.js +900 -0
- package/dist/sveltekit/index.cjs +14 -1
- package/dist/sveltekit/index.d.cts +3 -88
- package/dist/sveltekit/index.d.ts +3 -88
- package/dist/sveltekit/index.js +15 -387
- package/dist/sveltekit/server-CO847mEV.d.cts +98 -0
- package/dist/sveltekit/server-CO847mEV.d.ts +98 -0
- package/dist/{pixel-e1fUWl2Y.d.cts → types-BYH9XqmN.d.cts} +2 -50
- package/dist/{pixel-e1fUWl2Y.d.ts → types-BYH9XqmN.d.ts} +2 -50
- package/package.json +31 -1
|
@@ -1,161 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
editMode: isEnabled(features?.editMode)
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
var ALL_FEATURES_ENABLED = Object.freeze({
|
|
17
|
-
segments: true,
|
|
18
|
-
abTesting: true,
|
|
19
|
-
editMode: true
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
// src/core/stega/clean.ts
|
|
23
|
-
import { vercelStegaClean, vercelStegaDecode } from "@vercel/stega";
|
|
24
|
-
|
|
25
|
-
// src/core/utils.ts
|
|
26
|
-
var trustedParentOrigin = null;
|
|
27
|
-
function setTrustedParentOrigin(origin) {
|
|
28
|
-
trustedParentOrigin = origin;
|
|
29
|
-
}
|
|
30
|
-
function sendPreprEvent(event, data, options) {
|
|
31
|
-
if (typeof window !== "undefined") {
|
|
32
|
-
const message = {
|
|
33
|
-
name: "prepr_preview_bar",
|
|
34
|
-
event,
|
|
35
|
-
...data
|
|
36
|
-
};
|
|
37
|
-
window.dispatchEvent(
|
|
38
|
-
new CustomEvent("prepr_preview_bar", { detail: message })
|
|
39
|
-
);
|
|
40
|
-
if (window.parent && window.parent !== window) {
|
|
41
|
-
if (trustedParentOrigin) {
|
|
42
|
-
window.parent.postMessage(message, trustedParentOrigin);
|
|
43
|
-
} else if (options?.allowUntrustedTarget) {
|
|
44
|
-
window.parent.postMessage(message, "*");
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
var DebugLogger = class {
|
|
50
|
-
constructor(options) {
|
|
51
|
-
this.options = {
|
|
52
|
-
prefix: "[Prepr]",
|
|
53
|
-
...options
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
// A local `enabled` wins; otherwise defer to the global logger so scoped
|
|
57
|
-
// loggers created before initDebugLogger() still pick up the setting.
|
|
58
|
-
isEnabled() {
|
|
59
|
-
if (this.options.enabled !== void 0) {
|
|
60
|
-
return this.options.enabled;
|
|
61
|
-
}
|
|
62
|
-
return globalDebugLogger?.options?.enabled ?? false;
|
|
63
|
-
}
|
|
64
|
-
log(message, ...args) {
|
|
65
|
-
if (!this.isEnabled()) return;
|
|
66
|
-
const prefix = this.options.prefix;
|
|
67
|
-
console.log(`${prefix} ${message}`, ...args);
|
|
68
|
-
}
|
|
69
|
-
warn(message, ...args) {
|
|
70
|
-
if (!this.isEnabled()) return;
|
|
71
|
-
const prefix = this.options.prefix;
|
|
72
|
-
console.warn(`${prefix} ${message}`, ...args);
|
|
73
|
-
}
|
|
74
|
-
error(message, ...args) {
|
|
75
|
-
if (!this.isEnabled()) return;
|
|
76
|
-
const prefix = this.options.prefix;
|
|
77
|
-
console.error(`${prefix} ${message}`, ...args);
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
var globalDebugLogger = null;
|
|
81
|
-
function initDebugLogger(enabled = false) {
|
|
82
|
-
globalDebugLogger = new DebugLogger({ enabled });
|
|
83
|
-
}
|
|
84
|
-
function createScopedLogger(scopeName) {
|
|
85
|
-
return new DebugLogger({
|
|
86
|
-
prefix: `[Prepr][${scopeName}]`
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
function throttle(func, delay) {
|
|
90
|
-
let timeoutId = null;
|
|
91
|
-
let lastExecTime = 0;
|
|
92
|
-
const throttledFunc = ((...args) => {
|
|
93
|
-
const currentTime = Date.now();
|
|
94
|
-
const timeSinceLastExec = currentTime - lastExecTime;
|
|
95
|
-
if (timeSinceLastExec >= delay) {
|
|
96
|
-
func(...args);
|
|
97
|
-
lastExecTime = currentTime;
|
|
98
|
-
} else {
|
|
99
|
-
if (timeoutId) {
|
|
100
|
-
clearTimeout(timeoutId);
|
|
101
|
-
}
|
|
102
|
-
timeoutId = setTimeout(() => {
|
|
103
|
-
func(...args);
|
|
104
|
-
lastExecTime = Date.now();
|
|
105
|
-
timeoutId = null;
|
|
106
|
-
}, delay - timeSinceLastExec);
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
throttledFunc.cancel = () => {
|
|
110
|
-
if (timeoutId) {
|
|
111
|
-
clearTimeout(timeoutId);
|
|
112
|
-
timeoutId = null;
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
return throttledFunc;
|
|
116
|
-
}
|
|
117
|
-
function createElementCache(query, ttl = 1e3) {
|
|
118
|
-
let cache = null;
|
|
119
|
-
let lastCacheTime = 0;
|
|
120
|
-
return () => {
|
|
121
|
-
const now = Date.now();
|
|
122
|
-
if (!cache || now - lastCacheTime > ttl) {
|
|
123
|
-
cache = document.querySelectorAll(query);
|
|
124
|
-
lastCacheTime = now;
|
|
125
|
-
}
|
|
126
|
-
return cache;
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// src/core/stega/clean.ts
|
|
131
|
-
var debug = createScopedLogger("stega:clean");
|
|
132
|
-
function stegaClean(text) {
|
|
133
|
-
if (!text) return text;
|
|
134
|
-
return vercelStegaClean(text);
|
|
135
|
-
}
|
|
136
|
-
function decodeStega(str) {
|
|
137
|
-
if (!str) return null;
|
|
138
|
-
try {
|
|
139
|
-
const decoded = vercelStegaDecode(str);
|
|
140
|
-
if (decoded?.href) {
|
|
141
|
-
return decoded;
|
|
142
|
-
}
|
|
143
|
-
} catch (error) {
|
|
144
|
-
debug.log("error decoding stega data", error);
|
|
145
|
-
const match = str.match(/{"origin.*?}/);
|
|
146
|
-
if (match) {
|
|
147
|
-
try {
|
|
148
|
-
const decodedMatch = vercelStegaDecode(match[0]);
|
|
149
|
-
if (decodedMatch?.href) {
|
|
150
|
-
return decodedMatch;
|
|
151
|
-
}
|
|
152
|
-
} catch (innerError) {
|
|
153
|
-
debug.log("error decoding stega regex match", innerError);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
return null;
|
|
158
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
ALL_FEATURES_ENABLED,
|
|
3
|
+
VERSION,
|
|
4
|
+
createElementCache,
|
|
5
|
+
createScopedLogger,
|
|
6
|
+
decodeStega,
|
|
7
|
+
initDebugLogger,
|
|
8
|
+
resolveFeatures,
|
|
9
|
+
sendPreprEvent,
|
|
10
|
+
setTrustedParentOrigin,
|
|
11
|
+
throttle
|
|
12
|
+
} from "./chunk-DGZA7KX7.js";
|
|
159
13
|
|
|
160
14
|
// src/core/stega/dom.ts
|
|
161
15
|
var IGNORED_ANCESTORS = "script, style, noscript";
|
|
@@ -186,37 +40,14 @@ function isRenderedElement(element) {
|
|
|
186
40
|
if (!style) return true;
|
|
187
41
|
return style.visibility !== "hidden" && style.display !== "none";
|
|
188
42
|
}
|
|
189
|
-
function parseEditHref(href) {
|
|
190
|
-
try {
|
|
191
|
-
const url = new URL(href, window.location.origin);
|
|
192
|
-
return {
|
|
193
|
-
id: url.pathname.split("/").pop() || void 0,
|
|
194
|
-
field: url.searchParams.get("field") || void 0,
|
|
195
|
-
locale: url.searchParams.get("locale") || void 0
|
|
196
|
-
};
|
|
197
|
-
} catch {
|
|
198
|
-
return {};
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
function setOrRemove(element, name, value) {
|
|
202
|
-
if (value) {
|
|
203
|
-
element.setAttribute(name, value);
|
|
204
|
-
} else {
|
|
205
|
-
element.removeAttribute(name);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
43
|
function tagEncodedElement(element, decoded) {
|
|
209
44
|
element.setAttribute("data-prepr-encoded", "");
|
|
210
45
|
element.setAttribute("data-prepr-href", decoded.href);
|
|
211
46
|
element.setAttribute("data-prepr-origin", decoded.origin);
|
|
212
|
-
const { id, field, locale } = parseEditHref(decoded.href);
|
|
213
|
-
setOrRemove(element, "data-prepr-id", id);
|
|
214
|
-
setOrRemove(element, "data-prepr-field", field);
|
|
215
|
-
setOrRemove(element, "data-prepr-locale", locale);
|
|
216
47
|
}
|
|
217
48
|
|
|
218
49
|
// src/core/stega/elements.ts
|
|
219
|
-
var
|
|
50
|
+
var debug = createScopedLogger("stega:elements");
|
|
220
51
|
var StegaElements = class {
|
|
221
52
|
constructor(decode = decodeStega) {
|
|
222
53
|
this.observer = null;
|
|
@@ -261,7 +92,7 @@ var StegaElements = class {
|
|
|
261
92
|
walkTextNodes(document.body, (textNode) => {
|
|
262
93
|
if (this.tagFromTextNode(textNode)) encodedCount++;
|
|
263
94
|
});
|
|
264
|
-
|
|
95
|
+
debug.log("document scan complete, encoded", encodedCount, "elements");
|
|
265
96
|
this.elements = document.querySelectorAll("[data-prepr-encoded]");
|
|
266
97
|
}
|
|
267
98
|
/** `onUpdate` fires after each debounced batch, for refreshing derived state. */
|
|
@@ -317,9 +148,6 @@ var StegaElements = class {
|
|
|
317
148
|
element.removeAttribute("data-prepr-encoded");
|
|
318
149
|
element.removeAttribute("data-prepr-href");
|
|
319
150
|
element.removeAttribute("data-prepr-origin");
|
|
320
|
-
element.removeAttribute("data-prepr-id");
|
|
321
|
-
element.removeAttribute("data-prepr-field");
|
|
322
|
-
element.removeAttribute("data-prepr-locale");
|
|
323
151
|
element.classList.remove("prepr-overlay-active");
|
|
324
152
|
});
|
|
325
153
|
this.elements = void 0;
|
|
@@ -327,7 +155,7 @@ var StegaElements = class {
|
|
|
327
155
|
};
|
|
328
156
|
|
|
329
157
|
// src/core/stega/overlay.ts
|
|
330
|
-
var
|
|
158
|
+
var debug2 = createScopedLogger("stega:overlay");
|
|
331
159
|
var StegaOverlay = class {
|
|
332
160
|
constructor(onEdit) {
|
|
333
161
|
this.overlay = null;
|
|
@@ -372,8 +200,7 @@ var StegaOverlay = class {
|
|
|
372
200
|
const origin = element.getAttribute("data-prepr-origin");
|
|
373
201
|
const id = element.getAttribute("data-prepr-id") ?? void 0;
|
|
374
202
|
const field = element.getAttribute("data-prepr-field") ?? void 0;
|
|
375
|
-
|
|
376
|
-
debug3.log("showing overlay", { href, origin });
|
|
203
|
+
debug2.log("showing overlay", { href, origin });
|
|
377
204
|
const overlay = this.overlay;
|
|
378
205
|
overlay.style.display = "block";
|
|
379
206
|
overlay.style.top = `${rect.top + window.scrollY - 2}px`;
|
|
@@ -405,7 +232,7 @@ var StegaOverlay = class {
|
|
|
405
232
|
tooltip.style.left = `${left}px`;
|
|
406
233
|
});
|
|
407
234
|
tooltip.onclick = () => {
|
|
408
|
-
this.onEdit({ href, origin, id, field
|
|
235
|
+
this.onEdit({ href, origin, id, field });
|
|
409
236
|
};
|
|
410
237
|
}
|
|
411
238
|
this.currentElement = element;
|
|
@@ -445,7 +272,7 @@ var StegaOverlay = class {
|
|
|
445
272
|
};
|
|
446
273
|
|
|
447
274
|
// src/core/stega/proximity.ts
|
|
448
|
-
var
|
|
275
|
+
var debug3 = createScopedLogger("stega:proximity");
|
|
449
276
|
var StegaProximity = class {
|
|
450
277
|
constructor() {
|
|
451
278
|
this.highlighted = /* @__PURE__ */ new Set();
|
|
@@ -480,9 +307,9 @@ var StegaProximity = class {
|
|
|
480
307
|
);
|
|
481
308
|
const nodes = this.getEncodedElements();
|
|
482
309
|
nodes.forEach((el) => this.observer.observe(el));
|
|
483
|
-
|
|
310
|
+
debug3.log("observing", nodes.length, "encoded elements");
|
|
484
311
|
} catch (error) {
|
|
485
|
-
|
|
312
|
+
debug3.log("error setting up IntersectionObserver", error);
|
|
486
313
|
}
|
|
487
314
|
}
|
|
488
315
|
stopObserving() {
|
|
@@ -552,7 +379,7 @@ function removeStegaStyles() {
|
|
|
552
379
|
}
|
|
553
380
|
|
|
554
381
|
// src/core/stega/scan.ts
|
|
555
|
-
var
|
|
382
|
+
var debug4 = createScopedLogger("stega:scan");
|
|
556
383
|
var EDITOR_MODE_STYLES = "[data-prepr-encoded]{cursor:pointer}";
|
|
557
384
|
function createStegaController(opts) {
|
|
558
385
|
const tooltipEnabled = opts.tooltip ?? true;
|
|
@@ -585,13 +412,12 @@ function createStegaController(opts) {
|
|
|
585
412
|
href: encoded.getAttribute("data-prepr-href") ?? "",
|
|
586
413
|
origin: encoded.getAttribute("data-prepr-origin") ?? "",
|
|
587
414
|
id: encoded.getAttribute("data-prepr-id") ?? void 0,
|
|
588
|
-
field: encoded.getAttribute("data-prepr-field") ?? void 0
|
|
589
|
-
locale: encoded.getAttribute("data-prepr-locale") ?? void 0
|
|
415
|
+
field: encoded.getAttribute("data-prepr-field") ?? void 0
|
|
590
416
|
});
|
|
591
417
|
};
|
|
592
418
|
const start = () => {
|
|
593
419
|
if (initialized) {
|
|
594
|
-
|
|
420
|
+
debug4.log("already initialized, skipping setup");
|
|
595
421
|
return;
|
|
596
422
|
}
|
|
597
423
|
if (!tooltipEnabled) {
|
|
@@ -601,7 +427,7 @@ function createStegaController(opts) {
|
|
|
601
427
|
});
|
|
602
428
|
document.addEventListener("click", handleClick, { capture: true });
|
|
603
429
|
initialized = true;
|
|
604
|
-
|
|
430
|
+
debug4.log("stega controller started (editor mode)");
|
|
605
431
|
return;
|
|
606
432
|
}
|
|
607
433
|
injectStegaStyles();
|
|
@@ -632,7 +458,7 @@ function createStegaController(opts) {
|
|
|
632
458
|
passive: true
|
|
633
459
|
});
|
|
634
460
|
initialized = true;
|
|
635
|
-
|
|
461
|
+
debug4.log("stega controller started");
|
|
636
462
|
};
|
|
637
463
|
const stop = () => {
|
|
638
464
|
if (!initialized) return;
|
|
@@ -641,7 +467,7 @@ function createStegaController(opts) {
|
|
|
641
467
|
elements.cleanup();
|
|
642
468
|
removeStegaStyles();
|
|
643
469
|
initialized = false;
|
|
644
|
-
|
|
470
|
+
debug4.log("stega controller stopped (editor mode)");
|
|
645
471
|
return;
|
|
646
472
|
}
|
|
647
473
|
if (throttledMouseMove) {
|
|
@@ -661,14 +487,15 @@ function createStegaController(opts) {
|
|
|
661
487
|
elements.cleanup();
|
|
662
488
|
removeStegaStyles();
|
|
663
489
|
initialized = false;
|
|
664
|
-
|
|
490
|
+
debug4.log("stega controller stopped");
|
|
665
491
|
};
|
|
666
492
|
return { start, stop };
|
|
667
493
|
}
|
|
668
494
|
|
|
669
495
|
// src/core/stega/auto-clean.ts
|
|
670
496
|
import { vercelStegaSplit } from "@vercel/stega";
|
|
671
|
-
var
|
|
497
|
+
var debug5 = createScopedLogger("stega:auto-clean");
|
|
498
|
+
var HYDRATION_RETRY_MS = 100;
|
|
672
499
|
function createStegaAutoClean(options) {
|
|
673
500
|
const stripText = options?.enabled ?? true;
|
|
674
501
|
let observer = null;
|
|
@@ -677,8 +504,29 @@ function createStegaAutoClean(options) {
|
|
|
677
504
|
let pendingHidden = /* @__PURE__ */ new Set();
|
|
678
505
|
let pendingDirty = /* @__PURE__ */ new Set();
|
|
679
506
|
let debounceTimeout = null;
|
|
507
|
+
const isHydrated = options?.isHydrated;
|
|
508
|
+
let pendingHydration = /* @__PURE__ */ new Set();
|
|
509
|
+
let hydrationTimeout = null;
|
|
510
|
+
function retryPendingHydration() {
|
|
511
|
+
hydrationTimeout = null;
|
|
512
|
+
processing = true;
|
|
513
|
+
const batch = [...pendingHydration];
|
|
514
|
+
pendingHydration.clear();
|
|
515
|
+
batch.forEach((textNode) => {
|
|
516
|
+
if (textNode.isConnected) cleanTextNode(textNode);
|
|
517
|
+
});
|
|
518
|
+
processing = false;
|
|
519
|
+
}
|
|
680
520
|
function cleanTextNode(textNode) {
|
|
681
521
|
if (isIgnoredTextNode(textNode)) return false;
|
|
522
|
+
if (isHydrated && !isHydrated(textNode)) {
|
|
523
|
+
pendingHydration.add(textNode);
|
|
524
|
+
hydrationTimeout ?? (hydrationTimeout = setTimeout(
|
|
525
|
+
retryPendingHydration,
|
|
526
|
+
HYDRATION_RETRY_MS
|
|
527
|
+
));
|
|
528
|
+
return false;
|
|
529
|
+
}
|
|
682
530
|
const textContent = textNode.textContent;
|
|
683
531
|
const info = cleaned.get(textNode);
|
|
684
532
|
const settled = stripText ? info?.cleaned : info?.original;
|
|
@@ -711,7 +559,7 @@ function createStegaAutoClean(options) {
|
|
|
711
559
|
}
|
|
712
560
|
pendingHidden.add(textNode);
|
|
713
561
|
} catch (error) {
|
|
714
|
-
|
|
562
|
+
debug5.log("error cleaning text node", error);
|
|
715
563
|
}
|
|
716
564
|
return false;
|
|
717
565
|
}
|
|
@@ -797,13 +645,17 @@ function createStegaAutoClean(options) {
|
|
|
797
645
|
if (observer || typeof window === "undefined") return;
|
|
798
646
|
scanAndClean();
|
|
799
647
|
setupObserver();
|
|
800
|
-
|
|
648
|
+
debug5.log("stega auto-clean started");
|
|
801
649
|
}
|
|
802
650
|
function stop() {
|
|
803
651
|
if (debounceTimeout) {
|
|
804
652
|
clearTimeout(debounceTimeout);
|
|
805
653
|
debounceTimeout = null;
|
|
806
654
|
}
|
|
655
|
+
if (hydrationTimeout) {
|
|
656
|
+
clearTimeout(hydrationTimeout);
|
|
657
|
+
hydrationTimeout = null;
|
|
658
|
+
}
|
|
807
659
|
if (observer) {
|
|
808
660
|
observer.disconnect();
|
|
809
661
|
observer = null;
|
|
@@ -811,43 +663,12 @@ function createStegaAutoClean(options) {
|
|
|
811
663
|
cleaned = /* @__PURE__ */ new WeakMap();
|
|
812
664
|
pendingHidden = /* @__PURE__ */ new Set();
|
|
813
665
|
pendingDirty = /* @__PURE__ */ new Set();
|
|
814
|
-
|
|
666
|
+
pendingHydration = /* @__PURE__ */ new Set();
|
|
667
|
+
debug5.log("stega auto-clean stopped");
|
|
815
668
|
}
|
|
816
669
|
return { start, stop };
|
|
817
670
|
}
|
|
818
671
|
|
|
819
|
-
// src/core/stega/scroll-to-field.ts
|
|
820
|
-
var debug7 = createScopedLogger("stega:scroll");
|
|
821
|
-
var FLASH_DURATION_MS = 1200;
|
|
822
|
-
var flashTimeout = null;
|
|
823
|
-
function scrollToField(request) {
|
|
824
|
-
const { field, id } = request;
|
|
825
|
-
if (!field) return false;
|
|
826
|
-
const candidates = document.querySelectorAll(
|
|
827
|
-
"[data-prepr-encoded]"
|
|
828
|
-
);
|
|
829
|
-
let target = null;
|
|
830
|
-
for (const candidate of candidates) {
|
|
831
|
-
if (candidate.getAttribute("data-prepr-field") !== field) continue;
|
|
832
|
-
if (id && candidate.getAttribute("data-prepr-id") !== id) continue;
|
|
833
|
-
target = candidate;
|
|
834
|
-
break;
|
|
835
|
-
}
|
|
836
|
-
if (!target) {
|
|
837
|
-
debug7.log("no element found for field", field);
|
|
838
|
-
return false;
|
|
839
|
-
}
|
|
840
|
-
target.scrollIntoView({ behavior: "smooth", block: "center" });
|
|
841
|
-
if (flashTimeout) clearTimeout(flashTimeout);
|
|
842
|
-
document.querySelectorAll(".prepr-overlay-active").forEach((el) => el.classList.remove("prepr-overlay-active"));
|
|
843
|
-
target.classList.add("prepr-overlay-active");
|
|
844
|
-
flashTimeout = setTimeout(() => {
|
|
845
|
-
target.classList.remove("prepr-overlay-active");
|
|
846
|
-
flashTimeout = null;
|
|
847
|
-
}, FLASH_DURATION_MS);
|
|
848
|
-
return true;
|
|
849
|
-
}
|
|
850
|
-
|
|
851
672
|
// src/core/store.ts
|
|
852
673
|
var DEFAULT_STATE = {
|
|
853
674
|
locale: "en",
|
|
@@ -2004,7 +1825,6 @@ function t2(key, locale, vars) {
|
|
|
2004
1825
|
}
|
|
2005
1826
|
|
|
2006
1827
|
// src/core/iframe-bridge.ts
|
|
2007
|
-
var debug8 = createScopedLogger("iframe-bridge");
|
|
2008
1828
|
var EDITOR_BASE_DOMAIN = "prepr.io";
|
|
2009
1829
|
function isAllowedEditorOrigin(origin, allowed) {
|
|
2010
1830
|
if (allowed) return allowed.includes(origin);
|
|
@@ -2022,7 +1842,6 @@ function isAllowedEditorOrigin(origin, allowed) {
|
|
|
2022
1842
|
}
|
|
2023
1843
|
function createIframeBridge(store, options = {}) {
|
|
2024
1844
|
const allowedOrigins = options.allowedEditorOrigins;
|
|
2025
|
-
const onScrollToField = options.onScrollToField;
|
|
2026
1845
|
let parentOrigin = null;
|
|
2027
1846
|
const onKeyDown = (event) => {
|
|
2028
1847
|
const key = event.key.toLowerCase();
|
|
@@ -2046,15 +1865,6 @@ function createIframeBridge(store, options = {}) {
|
|
|
2046
1865
|
const currentScrollY = window.scrollY || document.documentElement.scrollTop;
|
|
2047
1866
|
sendPreprEvent("getScrollPosition", { value: currentScrollY });
|
|
2048
1867
|
}
|
|
2049
|
-
if (data?.event === "prepr:scrollToField") {
|
|
2050
|
-
if (typeof data.field !== "string" || !data.field) return;
|
|
2051
|
-
if (data.id !== void 0 && typeof data.id !== "string") return;
|
|
2052
|
-
try {
|
|
2053
|
-
onScrollToField?.({ field: data.field, id: data.id });
|
|
2054
|
-
} catch (error) {
|
|
2055
|
-
debug8.warn("scrollToField handler failed", error);
|
|
2056
|
-
}
|
|
2057
|
-
}
|
|
2058
1868
|
};
|
|
2059
1869
|
return {
|
|
2060
1870
|
start() {
|
|
@@ -2173,7 +1983,7 @@ function splitPath(full) {
|
|
|
2173
1983
|
}
|
|
2174
1984
|
|
|
2175
1985
|
// src/core/create-preview.ts
|
|
2176
|
-
var
|
|
1986
|
+
var debug6 = createScopedLogger("create-preview");
|
|
2177
1987
|
var controllerStores = /* @__PURE__ */ new WeakMap();
|
|
2178
1988
|
function defaultNavigation() {
|
|
2179
1989
|
return {
|
|
@@ -2215,7 +2025,7 @@ function createPreprPreview(opts = {}) {
|
|
|
2215
2025
|
const search = new URLSearchParams(window.location.search);
|
|
2216
2026
|
const hideBar = search.get(PARAM_HIDE_BAR) === "true";
|
|
2217
2027
|
if (hideBar) {
|
|
2218
|
-
|
|
2028
|
+
debug6.log(`${PARAM_HIDE_BAR}=true \u2014 no visible toolbar`);
|
|
2219
2029
|
}
|
|
2220
2030
|
const mountUi = (options?.ui ?? true) && !isIframe && !hideBar;
|
|
2221
2031
|
const locale = resolveLocale(options);
|
|
@@ -2251,17 +2061,18 @@ function createPreprPreview(opts = {}) {
|
|
|
2251
2061
|
tooltip: mountUi,
|
|
2252
2062
|
// In the editor, ask the parent to focus the field instead of opening a new
|
|
2253
2063
|
// tab. Standalone previews keep the window.open behaviour.
|
|
2254
|
-
onEdit: ({ href, id, field
|
|
2064
|
+
onEdit: ({ href, origin, id, field }) => {
|
|
2255
2065
|
const safeHref = href ? safeEditUrl(href) : null;
|
|
2256
2066
|
if (href && !safeHref) {
|
|
2257
|
-
|
|
2067
|
+
debug6.warn("ignored edit request with unsupported href scheme");
|
|
2258
2068
|
return;
|
|
2259
2069
|
}
|
|
2260
2070
|
if (isIframe) {
|
|
2261
2071
|
sendPreprEvent("field_edit_requested", {
|
|
2072
|
+
href: safeHref ?? void 0,
|
|
2073
|
+
origin,
|
|
2262
2074
|
id,
|
|
2263
|
-
field
|
|
2264
|
-
locale: contentLocale
|
|
2075
|
+
field
|
|
2265
2076
|
});
|
|
2266
2077
|
} else if (safeHref) {
|
|
2267
2078
|
window.open(safeHref, "_blank", "noopener,noreferrer");
|
|
@@ -2269,7 +2080,8 @@ function createPreprPreview(opts = {}) {
|
|
|
2269
2080
|
}
|
|
2270
2081
|
});
|
|
2271
2082
|
const autoClean = createStegaAutoClean({
|
|
2272
|
-
enabled: options?.autoClean
|
|
2083
|
+
enabled: options?.autoClean,
|
|
2084
|
+
isHydrated: opts.isHydrated
|
|
2273
2085
|
});
|
|
2274
2086
|
autoClean.start();
|
|
2275
2087
|
const handleChange = createChangeHandler({
|
|
@@ -2288,15 +2100,7 @@ function createPreprPreview(opts = {}) {
|
|
|
2288
2100
|
handleChange(before, state);
|
|
2289
2101
|
});
|
|
2290
2102
|
const bridge = createIframeBridge(store, {
|
|
2291
|
-
allowedEditorOrigins: options?.allowedEditorOrigins
|
|
2292
|
-
// The editor selecting a field scrolls the matching element into view. The
|
|
2293
|
-
// lookup relies on the attributes the stega scan writes, so it finds
|
|
2294
|
-
// nothing until encoded content has been tagged.
|
|
2295
|
-
onScrollToField: ({ field, id }) => {
|
|
2296
|
-
if (!scrollToField({ field, id })) {
|
|
2297
|
-
debug9.log("no element on this page renders field", field);
|
|
2298
|
-
}
|
|
2299
|
-
}
|
|
2103
|
+
allowedEditorOrigins: options?.allowedEditorOrigins
|
|
2300
2104
|
});
|
|
2301
2105
|
sendPreprEvent(
|
|
2302
2106
|
"getScrollPosition",
|
|
@@ -2316,7 +2120,7 @@ function createPreprPreview(opts = {}) {
|
|
|
2316
2120
|
bridge.stop();
|
|
2317
2121
|
}
|
|
2318
2122
|
el?.remove();
|
|
2319
|
-
|
|
2123
|
+
debug6.log("preview destroyed");
|
|
2320
2124
|
}
|
|
2321
2125
|
const controller = { destroy };
|
|
2322
2126
|
controllerStores.set(controller, store);
|
|
@@ -2389,8 +2193,6 @@ function setTrackingParam(key, value) {
|
|
|
2389
2193
|
}
|
|
2390
2194
|
|
|
2391
2195
|
export {
|
|
2392
|
-
VERSION,
|
|
2393
|
-
resolveFeatures,
|
|
2394
2196
|
COOKIE_PREVIEW_MODE,
|
|
2395
2197
|
COOKIE_SEGMENT,
|
|
2396
2198
|
COOKIE_VARIANT,
|
|
@@ -2400,7 +2202,6 @@ export {
|
|
|
2400
2202
|
PARAM_VARIANT,
|
|
2401
2203
|
PARAM_HIDE_BAR,
|
|
2402
2204
|
ONE_YEAR_SECONDS,
|
|
2403
|
-
stegaClean,
|
|
2404
2205
|
createToolbarStore,
|
|
2405
2206
|
PreprToolbarElement,
|
|
2406
2207
|
definePreprToolbar,
|