@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
|
@@ -291,7 +291,6 @@ function createElementCache(query, ttl = 1e3) {
|
|
|
291
291
|
}
|
|
292
292
|
|
|
293
293
|
// src/core/iframe-bridge.ts
|
|
294
|
-
var debug = createScopedLogger("iframe-bridge");
|
|
295
294
|
var EDITOR_BASE_DOMAIN = "prepr.io";
|
|
296
295
|
function isAllowedEditorOrigin(origin, allowed) {
|
|
297
296
|
if (allowed) return allowed.includes(origin);
|
|
@@ -309,7 +308,6 @@ function isAllowedEditorOrigin(origin, allowed) {
|
|
|
309
308
|
}
|
|
310
309
|
function createIframeBridge(store, options = {}) {
|
|
311
310
|
const allowedOrigins = options.allowedEditorOrigins;
|
|
312
|
-
const onScrollToField = options.onScrollToField;
|
|
313
311
|
let parentOrigin = null;
|
|
314
312
|
const onKeyDown = (event) => {
|
|
315
313
|
const key = event.key.toLowerCase();
|
|
@@ -333,15 +331,6 @@ function createIframeBridge(store, options = {}) {
|
|
|
333
331
|
const currentScrollY = window.scrollY || document.documentElement.scrollTop;
|
|
334
332
|
sendPreprEvent("getScrollPosition", { value: currentScrollY });
|
|
335
333
|
}
|
|
336
|
-
if (data?.event === "prepr:scrollToField") {
|
|
337
|
-
if (typeof data.field !== "string" || !data.field) return;
|
|
338
|
-
if (data.id !== void 0 && typeof data.id !== "string") return;
|
|
339
|
-
try {
|
|
340
|
-
onScrollToField?.({ field: data.field, id: data.id });
|
|
341
|
-
} catch (error) {
|
|
342
|
-
debug.warn("scrollToField handler failed", error);
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
334
|
};
|
|
346
335
|
return {
|
|
347
336
|
start() {
|
|
@@ -366,7 +355,7 @@ var import_stega2 = require("@vercel/stega");
|
|
|
366
355
|
|
|
367
356
|
// src/core/stega/clean.ts
|
|
368
357
|
var import_stega = require("@vercel/stega");
|
|
369
|
-
var
|
|
358
|
+
var debug = createScopedLogger("stega:clean");
|
|
370
359
|
function decodeStega(str) {
|
|
371
360
|
if (!str) return null;
|
|
372
361
|
try {
|
|
@@ -375,7 +364,7 @@ function decodeStega(str) {
|
|
|
375
364
|
return decoded;
|
|
376
365
|
}
|
|
377
366
|
} catch (error) {
|
|
378
|
-
|
|
367
|
+
debug.log("error decoding stega data", error);
|
|
379
368
|
const match = str.match(/{"origin.*?}/);
|
|
380
369
|
if (match) {
|
|
381
370
|
try {
|
|
@@ -384,7 +373,7 @@ function decodeStega(str) {
|
|
|
384
373
|
return decodedMatch;
|
|
385
374
|
}
|
|
386
375
|
} catch (innerError) {
|
|
387
|
-
|
|
376
|
+
debug.log("error decoding stega regex match", innerError);
|
|
388
377
|
}
|
|
389
378
|
}
|
|
390
379
|
}
|
|
@@ -420,37 +409,15 @@ function isRenderedElement(element) {
|
|
|
420
409
|
if (!style) return true;
|
|
421
410
|
return style.visibility !== "hidden" && style.display !== "none";
|
|
422
411
|
}
|
|
423
|
-
function parseEditHref(href) {
|
|
424
|
-
try {
|
|
425
|
-
const url = new URL(href, window.location.origin);
|
|
426
|
-
return {
|
|
427
|
-
id: url.pathname.split("/").pop() || void 0,
|
|
428
|
-
field: url.searchParams.get("field") || void 0,
|
|
429
|
-
locale: url.searchParams.get("locale") || void 0
|
|
430
|
-
};
|
|
431
|
-
} catch {
|
|
432
|
-
return {};
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
function setOrRemove(element, name, value) {
|
|
436
|
-
if (value) {
|
|
437
|
-
element.setAttribute(name, value);
|
|
438
|
-
} else {
|
|
439
|
-
element.removeAttribute(name);
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
412
|
function tagEncodedElement(element, decoded) {
|
|
443
413
|
element.setAttribute("data-prepr-encoded", "");
|
|
444
414
|
element.setAttribute("data-prepr-href", decoded.href);
|
|
445
415
|
element.setAttribute("data-prepr-origin", decoded.origin);
|
|
446
|
-
const { id, field, locale } = parseEditHref(decoded.href);
|
|
447
|
-
setOrRemove(element, "data-prepr-id", id);
|
|
448
|
-
setOrRemove(element, "data-prepr-field", field);
|
|
449
|
-
setOrRemove(element, "data-prepr-locale", locale);
|
|
450
416
|
}
|
|
451
417
|
|
|
452
418
|
// src/core/stega/auto-clean.ts
|
|
453
|
-
var
|
|
419
|
+
var debug2 = createScopedLogger("stega:auto-clean");
|
|
420
|
+
var HYDRATION_RETRY_MS = 100;
|
|
454
421
|
function createStegaAutoClean(options) {
|
|
455
422
|
const stripText = options?.enabled ?? true;
|
|
456
423
|
let observer = null;
|
|
@@ -459,8 +426,29 @@ function createStegaAutoClean(options) {
|
|
|
459
426
|
let pendingHidden = /* @__PURE__ */ new Set();
|
|
460
427
|
let pendingDirty = /* @__PURE__ */ new Set();
|
|
461
428
|
let debounceTimeout = null;
|
|
429
|
+
const isHydrated = options?.isHydrated;
|
|
430
|
+
let pendingHydration = /* @__PURE__ */ new Set();
|
|
431
|
+
let hydrationTimeout = null;
|
|
432
|
+
function retryPendingHydration() {
|
|
433
|
+
hydrationTimeout = null;
|
|
434
|
+
processing = true;
|
|
435
|
+
const batch = [...pendingHydration];
|
|
436
|
+
pendingHydration.clear();
|
|
437
|
+
batch.forEach((textNode) => {
|
|
438
|
+
if (textNode.isConnected) cleanTextNode(textNode);
|
|
439
|
+
});
|
|
440
|
+
processing = false;
|
|
441
|
+
}
|
|
462
442
|
function cleanTextNode(textNode) {
|
|
463
443
|
if (isIgnoredTextNode(textNode)) return false;
|
|
444
|
+
if (isHydrated && !isHydrated(textNode)) {
|
|
445
|
+
pendingHydration.add(textNode);
|
|
446
|
+
hydrationTimeout ?? (hydrationTimeout = setTimeout(
|
|
447
|
+
retryPendingHydration,
|
|
448
|
+
HYDRATION_RETRY_MS
|
|
449
|
+
));
|
|
450
|
+
return false;
|
|
451
|
+
}
|
|
464
452
|
const textContent = textNode.textContent;
|
|
465
453
|
const info = cleaned.get(textNode);
|
|
466
454
|
const settled = stripText ? info?.cleaned : info?.original;
|
|
@@ -493,7 +481,7 @@ function createStegaAutoClean(options) {
|
|
|
493
481
|
}
|
|
494
482
|
pendingHidden.add(textNode);
|
|
495
483
|
} catch (error) {
|
|
496
|
-
|
|
484
|
+
debug2.log("error cleaning text node", error);
|
|
497
485
|
}
|
|
498
486
|
return false;
|
|
499
487
|
}
|
|
@@ -579,13 +567,17 @@ function createStegaAutoClean(options) {
|
|
|
579
567
|
if (observer || typeof window === "undefined") return;
|
|
580
568
|
scanAndClean();
|
|
581
569
|
setupObserver();
|
|
582
|
-
|
|
570
|
+
debug2.log("stega auto-clean started");
|
|
583
571
|
}
|
|
584
572
|
function stop() {
|
|
585
573
|
if (debounceTimeout) {
|
|
586
574
|
clearTimeout(debounceTimeout);
|
|
587
575
|
debounceTimeout = null;
|
|
588
576
|
}
|
|
577
|
+
if (hydrationTimeout) {
|
|
578
|
+
clearTimeout(hydrationTimeout);
|
|
579
|
+
hydrationTimeout = null;
|
|
580
|
+
}
|
|
589
581
|
if (observer) {
|
|
590
582
|
observer.disconnect();
|
|
591
583
|
observer = null;
|
|
@@ -593,13 +585,14 @@ function createStegaAutoClean(options) {
|
|
|
593
585
|
cleaned = /* @__PURE__ */ new WeakMap();
|
|
594
586
|
pendingHidden = /* @__PURE__ */ new Set();
|
|
595
587
|
pendingDirty = /* @__PURE__ */ new Set();
|
|
596
|
-
|
|
588
|
+
pendingHydration = /* @__PURE__ */ new Set();
|
|
589
|
+
debug2.log("stega auto-clean stopped");
|
|
597
590
|
}
|
|
598
591
|
return { start, stop };
|
|
599
592
|
}
|
|
600
593
|
|
|
601
594
|
// src/core/stega/elements.ts
|
|
602
|
-
var
|
|
595
|
+
var debug3 = createScopedLogger("stega:elements");
|
|
603
596
|
var StegaElements = class {
|
|
604
597
|
constructor(decode = decodeStega) {
|
|
605
598
|
this.observer = null;
|
|
@@ -644,7 +637,7 @@ var StegaElements = class {
|
|
|
644
637
|
walkTextNodes(document.body, (textNode) => {
|
|
645
638
|
if (this.tagFromTextNode(textNode)) encodedCount++;
|
|
646
639
|
});
|
|
647
|
-
|
|
640
|
+
debug3.log("document scan complete, encoded", encodedCount, "elements");
|
|
648
641
|
this.elements = document.querySelectorAll("[data-prepr-encoded]");
|
|
649
642
|
}
|
|
650
643
|
/** `onUpdate` fires after each debounced batch, for refreshing derived state. */
|
|
@@ -700,9 +693,6 @@ var StegaElements = class {
|
|
|
700
693
|
element.removeAttribute("data-prepr-encoded");
|
|
701
694
|
element.removeAttribute("data-prepr-href");
|
|
702
695
|
element.removeAttribute("data-prepr-origin");
|
|
703
|
-
element.removeAttribute("data-prepr-id");
|
|
704
|
-
element.removeAttribute("data-prepr-field");
|
|
705
|
-
element.removeAttribute("data-prepr-locale");
|
|
706
696
|
element.classList.remove("prepr-overlay-active");
|
|
707
697
|
});
|
|
708
698
|
this.elements = void 0;
|
|
@@ -710,7 +700,7 @@ var StegaElements = class {
|
|
|
710
700
|
};
|
|
711
701
|
|
|
712
702
|
// src/core/stega/overlay.ts
|
|
713
|
-
var
|
|
703
|
+
var debug4 = createScopedLogger("stega:overlay");
|
|
714
704
|
var StegaOverlay = class {
|
|
715
705
|
constructor(onEdit) {
|
|
716
706
|
this.overlay = null;
|
|
@@ -755,8 +745,7 @@ var StegaOverlay = class {
|
|
|
755
745
|
const origin = element.getAttribute("data-prepr-origin");
|
|
756
746
|
const id = element.getAttribute("data-prepr-id") ?? void 0;
|
|
757
747
|
const field = element.getAttribute("data-prepr-field") ?? void 0;
|
|
758
|
-
|
|
759
|
-
debug5.log("showing overlay", { href, origin });
|
|
748
|
+
debug4.log("showing overlay", { href, origin });
|
|
760
749
|
const overlay = this.overlay;
|
|
761
750
|
overlay.style.display = "block";
|
|
762
751
|
overlay.style.top = `${rect.top + window.scrollY - 2}px`;
|
|
@@ -788,7 +777,7 @@ var StegaOverlay = class {
|
|
|
788
777
|
tooltip.style.left = `${left}px`;
|
|
789
778
|
});
|
|
790
779
|
tooltip.onclick = () => {
|
|
791
|
-
this.onEdit({ href, origin, id, field
|
|
780
|
+
this.onEdit({ href, origin, id, field });
|
|
792
781
|
};
|
|
793
782
|
}
|
|
794
783
|
this.currentElement = element;
|
|
@@ -828,7 +817,7 @@ var StegaOverlay = class {
|
|
|
828
817
|
};
|
|
829
818
|
|
|
830
819
|
// src/core/stega/proximity.ts
|
|
831
|
-
var
|
|
820
|
+
var debug5 = createScopedLogger("stega:proximity");
|
|
832
821
|
var StegaProximity = class {
|
|
833
822
|
constructor() {
|
|
834
823
|
this.highlighted = /* @__PURE__ */ new Set();
|
|
@@ -863,9 +852,9 @@ var StegaProximity = class {
|
|
|
863
852
|
);
|
|
864
853
|
const nodes = this.getEncodedElements();
|
|
865
854
|
nodes.forEach((el) => this.observer.observe(el));
|
|
866
|
-
|
|
855
|
+
debug5.log("observing", nodes.length, "encoded elements");
|
|
867
856
|
} catch (error) {
|
|
868
|
-
|
|
857
|
+
debug5.log("error setting up IntersectionObserver", error);
|
|
869
858
|
}
|
|
870
859
|
}
|
|
871
860
|
stopObserving() {
|
|
@@ -935,7 +924,7 @@ function removeStegaStyles() {
|
|
|
935
924
|
}
|
|
936
925
|
|
|
937
926
|
// src/core/stega/scan.ts
|
|
938
|
-
var
|
|
927
|
+
var debug6 = createScopedLogger("stega:scan");
|
|
939
928
|
var EDITOR_MODE_STYLES = "[data-prepr-encoded]{cursor:pointer}";
|
|
940
929
|
function createStegaController(opts) {
|
|
941
930
|
const tooltipEnabled = opts.tooltip ?? true;
|
|
@@ -968,13 +957,12 @@ function createStegaController(opts) {
|
|
|
968
957
|
href: encoded.getAttribute("data-prepr-href") ?? "",
|
|
969
958
|
origin: encoded.getAttribute("data-prepr-origin") ?? "",
|
|
970
959
|
id: encoded.getAttribute("data-prepr-id") ?? void 0,
|
|
971
|
-
field: encoded.getAttribute("data-prepr-field") ?? void 0
|
|
972
|
-
locale: encoded.getAttribute("data-prepr-locale") ?? void 0
|
|
960
|
+
field: encoded.getAttribute("data-prepr-field") ?? void 0
|
|
973
961
|
});
|
|
974
962
|
};
|
|
975
963
|
const start = () => {
|
|
976
964
|
if (initialized) {
|
|
977
|
-
|
|
965
|
+
debug6.log("already initialized, skipping setup");
|
|
978
966
|
return;
|
|
979
967
|
}
|
|
980
968
|
if (!tooltipEnabled) {
|
|
@@ -984,7 +972,7 @@ function createStegaController(opts) {
|
|
|
984
972
|
});
|
|
985
973
|
document.addEventListener("click", handleClick, { capture: true });
|
|
986
974
|
initialized = true;
|
|
987
|
-
|
|
975
|
+
debug6.log("stega controller started (editor mode)");
|
|
988
976
|
return;
|
|
989
977
|
}
|
|
990
978
|
injectStegaStyles();
|
|
@@ -1015,7 +1003,7 @@ function createStegaController(opts) {
|
|
|
1015
1003
|
passive: true
|
|
1016
1004
|
});
|
|
1017
1005
|
initialized = true;
|
|
1018
|
-
|
|
1006
|
+
debug6.log("stega controller started");
|
|
1019
1007
|
};
|
|
1020
1008
|
const stop = () => {
|
|
1021
1009
|
if (!initialized) return;
|
|
@@ -1024,7 +1012,7 @@ function createStegaController(opts) {
|
|
|
1024
1012
|
elements.cleanup();
|
|
1025
1013
|
removeStegaStyles();
|
|
1026
1014
|
initialized = false;
|
|
1027
|
-
|
|
1015
|
+
debug6.log("stega controller stopped (editor mode)");
|
|
1028
1016
|
return;
|
|
1029
1017
|
}
|
|
1030
1018
|
if (throttledMouseMove) {
|
|
@@ -1044,43 +1032,11 @@ function createStegaController(opts) {
|
|
|
1044
1032
|
elements.cleanup();
|
|
1045
1033
|
removeStegaStyles();
|
|
1046
1034
|
initialized = false;
|
|
1047
|
-
|
|
1035
|
+
debug6.log("stega controller stopped");
|
|
1048
1036
|
};
|
|
1049
1037
|
return { start, stop };
|
|
1050
1038
|
}
|
|
1051
1039
|
|
|
1052
|
-
// src/core/stega/scroll-to-field.ts
|
|
1053
|
-
var debug8 = createScopedLogger("stega:scroll");
|
|
1054
|
-
var FLASH_DURATION_MS = 1200;
|
|
1055
|
-
var flashTimeout = null;
|
|
1056
|
-
function scrollToField(request) {
|
|
1057
|
-
const { field, id } = request;
|
|
1058
|
-
if (!field) return false;
|
|
1059
|
-
const candidates = document.querySelectorAll(
|
|
1060
|
-
"[data-prepr-encoded]"
|
|
1061
|
-
);
|
|
1062
|
-
let target = null;
|
|
1063
|
-
for (const candidate of candidates) {
|
|
1064
|
-
if (candidate.getAttribute("data-prepr-field") !== field) continue;
|
|
1065
|
-
if (id && candidate.getAttribute("data-prepr-id") !== id) continue;
|
|
1066
|
-
target = candidate;
|
|
1067
|
-
break;
|
|
1068
|
-
}
|
|
1069
|
-
if (!target) {
|
|
1070
|
-
debug8.log("no element found for field", field);
|
|
1071
|
-
return false;
|
|
1072
|
-
}
|
|
1073
|
-
target.scrollIntoView({ behavior: "smooth", block: "center" });
|
|
1074
|
-
if (flashTimeout) clearTimeout(flashTimeout);
|
|
1075
|
-
document.querySelectorAll(".prepr-overlay-active").forEach((el) => el.classList.remove("prepr-overlay-active"));
|
|
1076
|
-
target.classList.add("prepr-overlay-active");
|
|
1077
|
-
flashTimeout = setTimeout(() => {
|
|
1078
|
-
target.classList.remove("prepr-overlay-active");
|
|
1079
|
-
flashTimeout = null;
|
|
1080
|
-
}, FLASH_DURATION_MS);
|
|
1081
|
-
return true;
|
|
1082
|
-
}
|
|
1083
|
-
|
|
1084
1040
|
// src/core/store.ts
|
|
1085
1041
|
var DEFAULT_STATE = {
|
|
1086
1042
|
locale: "en",
|
|
@@ -2193,7 +2149,7 @@ function definePreprToolbar() {
|
|
|
2193
2149
|
}
|
|
2194
2150
|
|
|
2195
2151
|
// src/core/create-preview.ts
|
|
2196
|
-
var
|
|
2152
|
+
var debug7 = createScopedLogger("create-preview");
|
|
2197
2153
|
var controllerStores = /* @__PURE__ */ new WeakMap();
|
|
2198
2154
|
function defaultNavigation() {
|
|
2199
2155
|
return {
|
|
@@ -2235,7 +2191,7 @@ function createPreprPreview(opts = {}) {
|
|
|
2235
2191
|
const search = new URLSearchParams(window.location.search);
|
|
2236
2192
|
const hideBar = search.get(PARAM_HIDE_BAR) === "true";
|
|
2237
2193
|
if (hideBar) {
|
|
2238
|
-
|
|
2194
|
+
debug7.log(`${PARAM_HIDE_BAR}=true \u2014 no visible toolbar`);
|
|
2239
2195
|
}
|
|
2240
2196
|
const mountUi = (options?.ui ?? true) && !isIframe && !hideBar;
|
|
2241
2197
|
const locale = resolveLocale(options);
|
|
@@ -2271,17 +2227,18 @@ function createPreprPreview(opts = {}) {
|
|
|
2271
2227
|
tooltip: mountUi,
|
|
2272
2228
|
// In the editor, ask the parent to focus the field instead of opening a new
|
|
2273
2229
|
// tab. Standalone previews keep the window.open behaviour.
|
|
2274
|
-
onEdit: ({ href, id, field
|
|
2230
|
+
onEdit: ({ href, origin, id, field }) => {
|
|
2275
2231
|
const safeHref = href ? safeEditUrl(href) : null;
|
|
2276
2232
|
if (href && !safeHref) {
|
|
2277
|
-
|
|
2233
|
+
debug7.warn("ignored edit request with unsupported href scheme");
|
|
2278
2234
|
return;
|
|
2279
2235
|
}
|
|
2280
2236
|
if (isIframe) {
|
|
2281
2237
|
sendPreprEvent("field_edit_requested", {
|
|
2238
|
+
href: safeHref ?? void 0,
|
|
2239
|
+
origin,
|
|
2282
2240
|
id,
|
|
2283
|
-
field
|
|
2284
|
-
locale: contentLocale
|
|
2241
|
+
field
|
|
2285
2242
|
});
|
|
2286
2243
|
} else if (safeHref) {
|
|
2287
2244
|
window.open(safeHref, "_blank", "noopener,noreferrer");
|
|
@@ -2289,7 +2246,8 @@ function createPreprPreview(opts = {}) {
|
|
|
2289
2246
|
}
|
|
2290
2247
|
});
|
|
2291
2248
|
const autoClean = createStegaAutoClean({
|
|
2292
|
-
enabled: options?.autoClean
|
|
2249
|
+
enabled: options?.autoClean,
|
|
2250
|
+
isHydrated: opts.isHydrated
|
|
2293
2251
|
});
|
|
2294
2252
|
autoClean.start();
|
|
2295
2253
|
const handleChange = createChangeHandler({
|
|
@@ -2308,15 +2266,7 @@ function createPreprPreview(opts = {}) {
|
|
|
2308
2266
|
handleChange(before, state);
|
|
2309
2267
|
});
|
|
2310
2268
|
const bridge = createIframeBridge(store, {
|
|
2311
|
-
allowedEditorOrigins: options?.allowedEditorOrigins
|
|
2312
|
-
// The editor selecting a field scrolls the matching element into view. The
|
|
2313
|
-
// lookup relies on the attributes the stega scan writes, so it finds
|
|
2314
|
-
// nothing until encoded content has been tagged.
|
|
2315
|
-
onScrollToField: ({ field, id }) => {
|
|
2316
|
-
if (!scrollToField({ field, id })) {
|
|
2317
|
-
debug9.log("no element on this page renders field", field);
|
|
2318
|
-
}
|
|
2319
|
-
}
|
|
2269
|
+
allowedEditorOrigins: options?.allowedEditorOrigins
|
|
2320
2270
|
});
|
|
2321
2271
|
sendPreprEvent(
|
|
2322
2272
|
"getScrollPosition",
|
|
@@ -2336,15 +2286,34 @@ function createPreprPreview(opts = {}) {
|
|
|
2336
2286
|
bridge.stop();
|
|
2337
2287
|
}
|
|
2338
2288
|
el?.remove();
|
|
2339
|
-
|
|
2289
|
+
debug7.log("preview destroyed");
|
|
2340
2290
|
}
|
|
2341
2291
|
const controller = { destroy };
|
|
2342
2292
|
controllerStores.set(controller, store);
|
|
2343
2293
|
return controller;
|
|
2344
2294
|
}
|
|
2345
2295
|
|
|
2296
|
+
// src/react/hydration.ts
|
|
2297
|
+
var PROPS_KEY_PREFIX = "__reactProps$";
|
|
2298
|
+
function reactProps(element) {
|
|
2299
|
+
for (const key of Object.keys(element)) {
|
|
2300
|
+
if (key.startsWith(PROPS_KEY_PREFIX)) {
|
|
2301
|
+
return element[key];
|
|
2302
|
+
}
|
|
2303
|
+
}
|
|
2304
|
+
return void 0;
|
|
2305
|
+
}
|
|
2306
|
+
function isReactHydrated(text) {
|
|
2307
|
+
for (let el = text.parentElement; el; el = el.parentElement) {
|
|
2308
|
+
const props = reactProps(el);
|
|
2309
|
+
if (!props) continue;
|
|
2310
|
+
return el === text.parentElement || props.dangerouslySetInnerHTML != null;
|
|
2311
|
+
}
|
|
2312
|
+
return true;
|
|
2313
|
+
}
|
|
2314
|
+
|
|
2346
2315
|
// src/version.ts
|
|
2347
|
-
var VERSION = "0.
|
|
2316
|
+
var VERSION = "0.6.0-alpha.0";
|
|
2348
2317
|
|
|
2349
2318
|
// src/core/pixel.ts
|
|
2350
2319
|
var PIXEL_SCRIPT_URL = "https://cdn.tracking.prepr.io/js/prepr.min.js";
|
|
@@ -2392,7 +2361,12 @@ function PreprPreview({
|
|
|
2392
2361
|
...props
|
|
2393
2362
|
}) {
|
|
2394
2363
|
(0, import_react.useEffect)(() => {
|
|
2395
|
-
const preview = createPreprPreview({
|
|
2364
|
+
const preview = createPreprPreview({
|
|
2365
|
+
props,
|
|
2366
|
+
options,
|
|
2367
|
+
navigation,
|
|
2368
|
+
isHydrated: isReactHydrated
|
|
2369
|
+
});
|
|
2396
2370
|
return () => preview.destroy();
|
|
2397
2371
|
}, []);
|
|
2398
2372
|
return null;
|