@preprio/toolkit 0.4.3 → 0.5.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -8
- package/dist/astro/index.cjs +1 -1
- package/dist/astro/index.js +1 -1
- package/dist/{chunk-H7VA7NGY.js → chunk-FLPNN3CV.js} +98 -14
- package/dist/index.cjs +118 -34
- package/dist/index.d.cts +16 -4
- package/dist/index.d.ts +16 -4
- package/dist/index.js +1 -1
- package/dist/nextjs/components.cjs +118 -34
- package/dist/nextjs/components.d.cts +1 -1
- package/dist/nextjs/components.d.ts +1 -1
- package/dist/nextjs/components.js +1 -1
- package/dist/nextjs/index.cjs +1 -1
- package/dist/nextjs/index.d.cts +8 -2
- package/dist/nextjs/index.d.ts +8 -2
- package/dist/nextjs/index.js +1 -1
- package/dist/nuxt/index.cjs +1 -1
- package/dist/nuxt/index.js +1 -1
- package/dist/{pixel-e1fUWl2Y.d.cts → pixel-B3oQNbZ3.d.cts} +8 -2
- package/dist/{pixel-e1fUWl2Y.d.ts → pixel-B3oQNbZ3.d.ts} +8 -2
- package/dist/react/components.cjs +118 -34
- package/dist/react/components.d.cts +8 -2
- package/dist/react/components.d.ts +8 -2
- package/dist/react/components.js +118 -34
- package/dist/sveltekit/index.cjs +1 -1
- package/dist/sveltekit/index.js +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { P as PreprFeatures, R as ResolvedPreprFeatures, L as Locale, a as PreprSegment, b as PreprVariant, c as PreprToolbarProps, d as PreprPreviewOptions, e as PreprErrorCode, f as PreprHeaders } from './pixel-
|
|
2
|
-
export { g as PreprEnvironment, h as PreprEventType, i as PreprFeatureConfig, j as PreprHeaderName, k as PreprPixelConfig, l as PreprToolbarComponentProps, m as PreprToolbarOptions, n as loadTrackingPixel, s as setTrackingParam, t as trackEvent } from './pixel-
|
|
1
|
+
import { P as PreprFeatures, R as ResolvedPreprFeatures, L as Locale, a as PreprSegment, b as PreprVariant, c as PreprToolbarProps, d as PreprPreviewOptions, e as PreprErrorCode, f as PreprHeaders } from './pixel-B3oQNbZ3.cjs';
|
|
2
|
+
export { g as PreprEnvironment, h as PreprEventType, i as PreprFeatureConfig, j as PreprHeaderName, k as PreprPixelConfig, l as PreprToolbarComponentProps, m as PreprToolbarOptions, n as loadTrackingPixel, s as setTrackingParam, t as trackEvent } from './pixel-B3oQNbZ3.cjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Package version; must match package.json. Lives in its own leaf module so
|
|
6
6
|
* core can import it without cycling through the barrel.
|
|
7
7
|
*/
|
|
8
|
-
declare const VERSION = "0.
|
|
8
|
+
declare const VERSION = "0.5.0-rc.2";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Resolve a `PreprFeatures` bag to plain booleans, defaulting every omitted key
|
|
@@ -137,12 +137,24 @@ declare class PreprToolbarElement extends HTMLElementBase {
|
|
|
137
137
|
/** Idempotent, including across bundles that each try to define the element. */
|
|
138
138
|
declare function definePreprToolbar(): void;
|
|
139
139
|
|
|
140
|
+
/** Which field the editor asked the preview to bring on screen. */
|
|
141
|
+
interface ScrollToFieldMessage {
|
|
142
|
+
field: string;
|
|
143
|
+
id?: string;
|
|
144
|
+
}
|
|
140
145
|
interface IframeBridgeOptions {
|
|
141
146
|
/**
|
|
142
147
|
* Replace the `*.prepr.io` wildcard with an exact origin list. Intended for
|
|
143
|
-
* self-hosted editors; when set, the wildcard no longer applies.
|
|
148
|
+
* self-hosted editors; when set, the wildcard no longer applies. `['*']`
|
|
149
|
+
* accepts any editor origin — see `PreprPreviewOptions.allowedEditorOrigins`.
|
|
144
150
|
*/
|
|
145
151
|
allowedEditorOrigins?: string[];
|
|
152
|
+
/**
|
|
153
|
+
* Called when the editor selects a field and wants the preview to scroll to
|
|
154
|
+
* it. Only fires for messages from the handshaked editor origin. The bridge
|
|
155
|
+
* stays free of DOM lookups: the preview runtime supplies `scrollToField`.
|
|
156
|
+
*/
|
|
157
|
+
onScrollToField?: (message: ScrollToFieldMessage) => void;
|
|
146
158
|
}
|
|
147
159
|
|
|
148
160
|
/** Error thrown by the token helpers and the segments fetch. */
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { P as PreprFeatures, R as ResolvedPreprFeatures, L as Locale, a as PreprSegment, b as PreprVariant, c as PreprToolbarProps, d as PreprPreviewOptions, e as PreprErrorCode, f as PreprHeaders } from './pixel-
|
|
2
|
-
export { g as PreprEnvironment, h as PreprEventType, i as PreprFeatureConfig, j as PreprHeaderName, k as PreprPixelConfig, l as PreprToolbarComponentProps, m as PreprToolbarOptions, n as loadTrackingPixel, s as setTrackingParam, t as trackEvent } from './pixel-
|
|
1
|
+
import { P as PreprFeatures, R as ResolvedPreprFeatures, L as Locale, a as PreprSegment, b as PreprVariant, c as PreprToolbarProps, d as PreprPreviewOptions, e as PreprErrorCode, f as PreprHeaders } from './pixel-B3oQNbZ3.js';
|
|
2
|
+
export { g as PreprEnvironment, h as PreprEventType, i as PreprFeatureConfig, j as PreprHeaderName, k as PreprPixelConfig, l as PreprToolbarComponentProps, m as PreprToolbarOptions, n as loadTrackingPixel, s as setTrackingParam, t as trackEvent } from './pixel-B3oQNbZ3.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Package version; must match package.json. Lives in its own leaf module so
|
|
6
6
|
* core can import it without cycling through the barrel.
|
|
7
7
|
*/
|
|
8
|
-
declare const VERSION = "0.
|
|
8
|
+
declare const VERSION = "0.5.0-rc.2";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Resolve a `PreprFeatures` bag to plain booleans, defaulting every omitted key
|
|
@@ -137,12 +137,24 @@ declare class PreprToolbarElement extends HTMLElementBase {
|
|
|
137
137
|
/** Idempotent, including across bundles that each try to define the element. */
|
|
138
138
|
declare function definePreprToolbar(): void;
|
|
139
139
|
|
|
140
|
+
/** Which field the editor asked the preview to bring on screen. */
|
|
141
|
+
interface ScrollToFieldMessage {
|
|
142
|
+
field: string;
|
|
143
|
+
id?: string;
|
|
144
|
+
}
|
|
140
145
|
interface IframeBridgeOptions {
|
|
141
146
|
/**
|
|
142
147
|
* Replace the `*.prepr.io` wildcard with an exact origin list. Intended for
|
|
143
|
-
* self-hosted editors; when set, the wildcard no longer applies.
|
|
148
|
+
* self-hosted editors; when set, the wildcard no longer applies. `['*']`
|
|
149
|
+
* accepts any editor origin — see `PreprPreviewOptions.allowedEditorOrigins`.
|
|
144
150
|
*/
|
|
145
151
|
allowedEditorOrigins?: string[];
|
|
152
|
+
/**
|
|
153
|
+
* Called when the editor selects a field and wants the preview to scroll to
|
|
154
|
+
* it. Only fires for messages from the handshaked editor origin. The bridge
|
|
155
|
+
* stays free of DOM lookups: the preview runtime supplies `scrollToField`.
|
|
156
|
+
*/
|
|
157
|
+
onScrollToField?: (message: ScrollToFieldMessage) => void;
|
|
146
158
|
}
|
|
147
159
|
|
|
148
160
|
/** Error thrown by the token helpers and the segments fetch. */
|
package/dist/index.js
CHANGED
|
@@ -292,9 +292,13 @@ function createElementCache(query, ttl = 1e3) {
|
|
|
292
292
|
}
|
|
293
293
|
|
|
294
294
|
// src/core/iframe-bridge.ts
|
|
295
|
+
var debug = createScopedLogger("iframe-bridge");
|
|
295
296
|
var EDITOR_BASE_DOMAIN = "prepr.io";
|
|
296
297
|
function isAllowedEditorOrigin(origin, allowed) {
|
|
297
|
-
if (allowed)
|
|
298
|
+
if (allowed) {
|
|
299
|
+
if (allowed.includes("*")) return origin !== "null";
|
|
300
|
+
return allowed.includes(origin);
|
|
301
|
+
}
|
|
298
302
|
let url;
|
|
299
303
|
try {
|
|
300
304
|
url = new URL(origin);
|
|
@@ -309,6 +313,7 @@ function isAllowedEditorOrigin(origin, allowed) {
|
|
|
309
313
|
}
|
|
310
314
|
function createIframeBridge(store, options = {}) {
|
|
311
315
|
const allowedOrigins = options.allowedEditorOrigins;
|
|
316
|
+
const onScrollToField = options.onScrollToField;
|
|
312
317
|
let parentOrigin = null;
|
|
313
318
|
const onKeyDown = (event) => {
|
|
314
319
|
const key = event.key.toLowerCase();
|
|
@@ -318,7 +323,10 @@ function createIframeBridge(store, options = {}) {
|
|
|
318
323
|
const onMessage = (evt) => {
|
|
319
324
|
const data = evt?.data;
|
|
320
325
|
if (data?.event === "prepr:initVE" && !parentOrigin) {
|
|
321
|
-
if (!isAllowedEditorOrigin(evt.origin, allowedOrigins))
|
|
326
|
+
if (!isAllowedEditorOrigin(evt.origin, allowedOrigins)) {
|
|
327
|
+
debug.warn("ignored editor handshake from origin", evt.origin);
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
322
330
|
parentOrigin = evt.origin;
|
|
323
331
|
setTrustedParentOrigin(parentOrigin);
|
|
324
332
|
if (data.scrollPosition != null) {
|
|
@@ -332,6 +340,15 @@ function createIframeBridge(store, options = {}) {
|
|
|
332
340
|
const currentScrollY = window.scrollY || document.documentElement.scrollTop;
|
|
333
341
|
sendPreprEvent("getScrollPosition", { value: currentScrollY });
|
|
334
342
|
}
|
|
343
|
+
if (data?.event === "prepr:scrollToField") {
|
|
344
|
+
if (typeof data.field !== "string" || !data.field) return;
|
|
345
|
+
if (data.id !== void 0 && typeof data.id !== "string") return;
|
|
346
|
+
try {
|
|
347
|
+
onScrollToField?.({ field: data.field, id: data.id });
|
|
348
|
+
} catch (error) {
|
|
349
|
+
debug.warn("scrollToField handler failed", error);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
335
352
|
};
|
|
336
353
|
return {
|
|
337
354
|
start() {
|
|
@@ -356,7 +373,7 @@ var import_stega2 = require("@vercel/stega");
|
|
|
356
373
|
|
|
357
374
|
// src/core/stega/clean.ts
|
|
358
375
|
var import_stega = require("@vercel/stega");
|
|
359
|
-
var
|
|
376
|
+
var debug2 = createScopedLogger("stega:clean");
|
|
360
377
|
function decodeStega(str) {
|
|
361
378
|
if (!str) return null;
|
|
362
379
|
try {
|
|
@@ -365,7 +382,7 @@ function decodeStega(str) {
|
|
|
365
382
|
return decoded;
|
|
366
383
|
}
|
|
367
384
|
} catch (error) {
|
|
368
|
-
|
|
385
|
+
debug2.log("error decoding stega data", error);
|
|
369
386
|
const match = str.match(/{"origin.*?}/);
|
|
370
387
|
if (match) {
|
|
371
388
|
try {
|
|
@@ -374,7 +391,7 @@ function decodeStega(str) {
|
|
|
374
391
|
return decodedMatch;
|
|
375
392
|
}
|
|
376
393
|
} catch (innerError) {
|
|
377
|
-
|
|
394
|
+
debug2.log("error decoding stega regex match", innerError);
|
|
378
395
|
}
|
|
379
396
|
}
|
|
380
397
|
}
|
|
@@ -410,14 +427,37 @@ function isRenderedElement(element) {
|
|
|
410
427
|
if (!style) return true;
|
|
411
428
|
return style.visibility !== "hidden" && style.display !== "none";
|
|
412
429
|
}
|
|
430
|
+
function parseEditHref(href) {
|
|
431
|
+
try {
|
|
432
|
+
const url = new URL(href, window.location.origin);
|
|
433
|
+
return {
|
|
434
|
+
id: url.pathname.split("/").pop() || void 0,
|
|
435
|
+
field: url.searchParams.get("field") || void 0,
|
|
436
|
+
locale: url.searchParams.get("locale") || void 0
|
|
437
|
+
};
|
|
438
|
+
} catch {
|
|
439
|
+
return {};
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
function setOrRemove(element, name, value) {
|
|
443
|
+
if (value) {
|
|
444
|
+
element.setAttribute(name, value);
|
|
445
|
+
} else {
|
|
446
|
+
element.removeAttribute(name);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
413
449
|
function tagEncodedElement(element, decoded) {
|
|
414
450
|
element.setAttribute("data-prepr-encoded", "");
|
|
415
451
|
element.setAttribute("data-prepr-href", decoded.href);
|
|
416
452
|
element.setAttribute("data-prepr-origin", decoded.origin);
|
|
453
|
+
const { id, field, locale } = parseEditHref(decoded.href);
|
|
454
|
+
setOrRemove(element, "data-prepr-id", id);
|
|
455
|
+
setOrRemove(element, "data-prepr-field", field);
|
|
456
|
+
setOrRemove(element, "data-prepr-locale", locale);
|
|
417
457
|
}
|
|
418
458
|
|
|
419
459
|
// src/core/stega/auto-clean.ts
|
|
420
|
-
var
|
|
460
|
+
var debug3 = createScopedLogger("stega:auto-clean");
|
|
421
461
|
function createStegaAutoClean(options) {
|
|
422
462
|
const stripText = options?.enabled ?? true;
|
|
423
463
|
let observer = null;
|
|
@@ -460,7 +500,7 @@ function createStegaAutoClean(options) {
|
|
|
460
500
|
}
|
|
461
501
|
pendingHidden.add(textNode);
|
|
462
502
|
} catch (error) {
|
|
463
|
-
|
|
503
|
+
debug3.log("error cleaning text node", error);
|
|
464
504
|
}
|
|
465
505
|
return false;
|
|
466
506
|
}
|
|
@@ -546,7 +586,7 @@ function createStegaAutoClean(options) {
|
|
|
546
586
|
if (observer || typeof window === "undefined") return;
|
|
547
587
|
scanAndClean();
|
|
548
588
|
setupObserver();
|
|
549
|
-
|
|
589
|
+
debug3.log("stega auto-clean started");
|
|
550
590
|
}
|
|
551
591
|
function stop() {
|
|
552
592
|
if (debounceTimeout) {
|
|
@@ -560,13 +600,13 @@ function createStegaAutoClean(options) {
|
|
|
560
600
|
cleaned = /* @__PURE__ */ new WeakMap();
|
|
561
601
|
pendingHidden = /* @__PURE__ */ new Set();
|
|
562
602
|
pendingDirty = /* @__PURE__ */ new Set();
|
|
563
|
-
|
|
603
|
+
debug3.log("stega auto-clean stopped");
|
|
564
604
|
}
|
|
565
605
|
return { start, stop };
|
|
566
606
|
}
|
|
567
607
|
|
|
568
608
|
// src/core/stega/elements.ts
|
|
569
|
-
var
|
|
609
|
+
var debug4 = createScopedLogger("stega:elements");
|
|
570
610
|
var StegaElements = class {
|
|
571
611
|
constructor(decode = decodeStega) {
|
|
572
612
|
this.observer = null;
|
|
@@ -611,7 +651,7 @@ var StegaElements = class {
|
|
|
611
651
|
walkTextNodes(document.body, (textNode) => {
|
|
612
652
|
if (this.tagFromTextNode(textNode)) encodedCount++;
|
|
613
653
|
});
|
|
614
|
-
|
|
654
|
+
debug4.log("document scan complete, encoded", encodedCount, "elements");
|
|
615
655
|
this.elements = document.querySelectorAll("[data-prepr-encoded]");
|
|
616
656
|
}
|
|
617
657
|
/** `onUpdate` fires after each debounced batch, for refreshing derived state. */
|
|
@@ -667,6 +707,9 @@ var StegaElements = class {
|
|
|
667
707
|
element.removeAttribute("data-prepr-encoded");
|
|
668
708
|
element.removeAttribute("data-prepr-href");
|
|
669
709
|
element.removeAttribute("data-prepr-origin");
|
|
710
|
+
element.removeAttribute("data-prepr-id");
|
|
711
|
+
element.removeAttribute("data-prepr-field");
|
|
712
|
+
element.removeAttribute("data-prepr-locale");
|
|
670
713
|
element.classList.remove("prepr-overlay-active");
|
|
671
714
|
});
|
|
672
715
|
this.elements = void 0;
|
|
@@ -674,7 +717,7 @@ var StegaElements = class {
|
|
|
674
717
|
};
|
|
675
718
|
|
|
676
719
|
// src/core/stega/overlay.ts
|
|
677
|
-
var
|
|
720
|
+
var debug5 = createScopedLogger("stega:overlay");
|
|
678
721
|
var StegaOverlay = class {
|
|
679
722
|
constructor(onEdit) {
|
|
680
723
|
this.overlay = null;
|
|
@@ -719,7 +762,8 @@ var StegaOverlay = class {
|
|
|
719
762
|
const origin = element.getAttribute("data-prepr-origin");
|
|
720
763
|
const id = element.getAttribute("data-prepr-id") ?? void 0;
|
|
721
764
|
const field = element.getAttribute("data-prepr-field") ?? void 0;
|
|
722
|
-
|
|
765
|
+
const locale = element.getAttribute("data-prepr-locale") ?? void 0;
|
|
766
|
+
debug5.log("showing overlay", { href, origin });
|
|
723
767
|
const overlay = this.overlay;
|
|
724
768
|
overlay.style.display = "block";
|
|
725
769
|
overlay.style.top = `${rect.top + window.scrollY - 2}px`;
|
|
@@ -751,7 +795,7 @@ var StegaOverlay = class {
|
|
|
751
795
|
tooltip.style.left = `${left}px`;
|
|
752
796
|
});
|
|
753
797
|
tooltip.onclick = () => {
|
|
754
|
-
this.onEdit({ href, origin, id, field });
|
|
798
|
+
this.onEdit({ href, origin, id, field, locale });
|
|
755
799
|
};
|
|
756
800
|
}
|
|
757
801
|
this.currentElement = element;
|
|
@@ -791,7 +835,7 @@ var StegaOverlay = class {
|
|
|
791
835
|
};
|
|
792
836
|
|
|
793
837
|
// src/core/stega/proximity.ts
|
|
794
|
-
var
|
|
838
|
+
var debug6 = createScopedLogger("stega:proximity");
|
|
795
839
|
var StegaProximity = class {
|
|
796
840
|
constructor() {
|
|
797
841
|
this.highlighted = /* @__PURE__ */ new Set();
|
|
@@ -826,9 +870,9 @@ var StegaProximity = class {
|
|
|
826
870
|
);
|
|
827
871
|
const nodes = this.getEncodedElements();
|
|
828
872
|
nodes.forEach((el) => this.observer.observe(el));
|
|
829
|
-
|
|
873
|
+
debug6.log("observing", nodes.length, "encoded elements");
|
|
830
874
|
} catch (error) {
|
|
831
|
-
|
|
875
|
+
debug6.log("error setting up IntersectionObserver", error);
|
|
832
876
|
}
|
|
833
877
|
}
|
|
834
878
|
stopObserving() {
|
|
@@ -898,7 +942,7 @@ function removeStegaStyles() {
|
|
|
898
942
|
}
|
|
899
943
|
|
|
900
944
|
// src/core/stega/scan.ts
|
|
901
|
-
var
|
|
945
|
+
var debug7 = createScopedLogger("stega:scan");
|
|
902
946
|
var EDITOR_MODE_STYLES = "[data-prepr-encoded]{cursor:pointer}";
|
|
903
947
|
function createStegaController(opts) {
|
|
904
948
|
const tooltipEnabled = opts.tooltip ?? true;
|
|
@@ -931,12 +975,13 @@ function createStegaController(opts) {
|
|
|
931
975
|
href: encoded.getAttribute("data-prepr-href") ?? "",
|
|
932
976
|
origin: encoded.getAttribute("data-prepr-origin") ?? "",
|
|
933
977
|
id: encoded.getAttribute("data-prepr-id") ?? void 0,
|
|
934
|
-
field: encoded.getAttribute("data-prepr-field") ?? void 0
|
|
978
|
+
field: encoded.getAttribute("data-prepr-field") ?? void 0,
|
|
979
|
+
locale: encoded.getAttribute("data-prepr-locale") ?? void 0
|
|
935
980
|
});
|
|
936
981
|
};
|
|
937
982
|
const start = () => {
|
|
938
983
|
if (initialized) {
|
|
939
|
-
|
|
984
|
+
debug7.log("already initialized, skipping setup");
|
|
940
985
|
return;
|
|
941
986
|
}
|
|
942
987
|
if (!tooltipEnabled) {
|
|
@@ -946,7 +991,7 @@ function createStegaController(opts) {
|
|
|
946
991
|
});
|
|
947
992
|
document.addEventListener("click", handleClick, { capture: true });
|
|
948
993
|
initialized = true;
|
|
949
|
-
|
|
994
|
+
debug7.log("stega controller started (editor mode)");
|
|
950
995
|
return;
|
|
951
996
|
}
|
|
952
997
|
injectStegaStyles();
|
|
@@ -977,7 +1022,7 @@ function createStegaController(opts) {
|
|
|
977
1022
|
passive: true
|
|
978
1023
|
});
|
|
979
1024
|
initialized = true;
|
|
980
|
-
|
|
1025
|
+
debug7.log("stega controller started");
|
|
981
1026
|
};
|
|
982
1027
|
const stop = () => {
|
|
983
1028
|
if (!initialized) return;
|
|
@@ -986,7 +1031,7 @@ function createStegaController(opts) {
|
|
|
986
1031
|
elements.cleanup();
|
|
987
1032
|
removeStegaStyles();
|
|
988
1033
|
initialized = false;
|
|
989
|
-
|
|
1034
|
+
debug7.log("stega controller stopped (editor mode)");
|
|
990
1035
|
return;
|
|
991
1036
|
}
|
|
992
1037
|
if (throttledMouseMove) {
|
|
@@ -1006,11 +1051,43 @@ function createStegaController(opts) {
|
|
|
1006
1051
|
elements.cleanup();
|
|
1007
1052
|
removeStegaStyles();
|
|
1008
1053
|
initialized = false;
|
|
1009
|
-
|
|
1054
|
+
debug7.log("stega controller stopped");
|
|
1010
1055
|
};
|
|
1011
1056
|
return { start, stop };
|
|
1012
1057
|
}
|
|
1013
1058
|
|
|
1059
|
+
// src/core/stega/scroll-to-field.ts
|
|
1060
|
+
var debug8 = createScopedLogger("stega:scroll");
|
|
1061
|
+
var FLASH_DURATION_MS = 1200;
|
|
1062
|
+
var flashTimeout = null;
|
|
1063
|
+
function scrollToField(request) {
|
|
1064
|
+
const { field, id } = request;
|
|
1065
|
+
if (!field) return false;
|
|
1066
|
+
const candidates = document.querySelectorAll(
|
|
1067
|
+
"[data-prepr-encoded]"
|
|
1068
|
+
);
|
|
1069
|
+
let target = null;
|
|
1070
|
+
for (const candidate of candidates) {
|
|
1071
|
+
if (candidate.getAttribute("data-prepr-field") !== field) continue;
|
|
1072
|
+
if (id && candidate.getAttribute("data-prepr-id") !== id) continue;
|
|
1073
|
+
target = candidate;
|
|
1074
|
+
break;
|
|
1075
|
+
}
|
|
1076
|
+
if (!target) {
|
|
1077
|
+
debug8.log("no element found for field", field);
|
|
1078
|
+
return false;
|
|
1079
|
+
}
|
|
1080
|
+
target.scrollIntoView({ behavior: "smooth", block: "center" });
|
|
1081
|
+
if (flashTimeout) clearTimeout(flashTimeout);
|
|
1082
|
+
document.querySelectorAll(".prepr-overlay-active").forEach((el) => el.classList.remove("prepr-overlay-active"));
|
|
1083
|
+
target.classList.add("prepr-overlay-active");
|
|
1084
|
+
flashTimeout = setTimeout(() => {
|
|
1085
|
+
target.classList.remove("prepr-overlay-active");
|
|
1086
|
+
flashTimeout = null;
|
|
1087
|
+
}, FLASH_DURATION_MS);
|
|
1088
|
+
return true;
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1014
1091
|
// src/core/store.ts
|
|
1015
1092
|
var DEFAULT_STATE = {
|
|
1016
1093
|
locale: "en",
|
|
@@ -2123,7 +2200,7 @@ function definePreprToolbar() {
|
|
|
2123
2200
|
}
|
|
2124
2201
|
|
|
2125
2202
|
// src/core/create-preview.ts
|
|
2126
|
-
var
|
|
2203
|
+
var debug9 = createScopedLogger("create-preview");
|
|
2127
2204
|
var controllerStores = /* @__PURE__ */ new WeakMap();
|
|
2128
2205
|
function defaultNavigation() {
|
|
2129
2206
|
return {
|
|
@@ -2165,7 +2242,7 @@ function createPreprPreview(opts = {}) {
|
|
|
2165
2242
|
const search = new URLSearchParams(window.location.search);
|
|
2166
2243
|
const hideBar = search.get(PARAM_HIDE_BAR) === "true";
|
|
2167
2244
|
if (hideBar) {
|
|
2168
|
-
|
|
2245
|
+
debug9.log(`${PARAM_HIDE_BAR}=true \u2014 no visible toolbar`);
|
|
2169
2246
|
}
|
|
2170
2247
|
const mountUi = (options?.ui ?? true) && !isIframe && !hideBar;
|
|
2171
2248
|
const locale = resolveLocale(options);
|
|
@@ -2201,18 +2278,17 @@ function createPreprPreview(opts = {}) {
|
|
|
2201
2278
|
tooltip: mountUi,
|
|
2202
2279
|
// In the editor, ask the parent to focus the field instead of opening a new
|
|
2203
2280
|
// tab. Standalone previews keep the window.open behaviour.
|
|
2204
|
-
onEdit: ({ href,
|
|
2281
|
+
onEdit: ({ href, id, field, locale: contentLocale }) => {
|
|
2205
2282
|
const safeHref = href ? safeEditUrl(href) : null;
|
|
2206
2283
|
if (href && !safeHref) {
|
|
2207
|
-
|
|
2284
|
+
debug9.warn("ignored edit request with unsupported href scheme");
|
|
2208
2285
|
return;
|
|
2209
2286
|
}
|
|
2210
2287
|
if (isIframe) {
|
|
2211
2288
|
sendPreprEvent("field_edit_requested", {
|
|
2212
|
-
href: safeHref ?? void 0,
|
|
2213
|
-
origin,
|
|
2214
2289
|
id,
|
|
2215
|
-
field
|
|
2290
|
+
field,
|
|
2291
|
+
locale: contentLocale
|
|
2216
2292
|
});
|
|
2217
2293
|
} else if (safeHref) {
|
|
2218
2294
|
window.open(safeHref, "_blank", "noopener,noreferrer");
|
|
@@ -2239,7 +2315,15 @@ function createPreprPreview(opts = {}) {
|
|
|
2239
2315
|
handleChange(before, state);
|
|
2240
2316
|
});
|
|
2241
2317
|
const bridge = createIframeBridge(store, {
|
|
2242
|
-
allowedEditorOrigins: options?.allowedEditorOrigins
|
|
2318
|
+
allowedEditorOrigins: options?.allowedEditorOrigins,
|
|
2319
|
+
// The editor selecting a field scrolls the matching element into view. The
|
|
2320
|
+
// lookup relies on the attributes the stega scan writes, so it finds
|
|
2321
|
+
// nothing until encoded content has been tagged.
|
|
2322
|
+
onScrollToField: ({ field, id }) => {
|
|
2323
|
+
if (!scrollToField({ field, id })) {
|
|
2324
|
+
debug9.log("no element on this page renders field", field);
|
|
2325
|
+
}
|
|
2326
|
+
}
|
|
2243
2327
|
});
|
|
2244
2328
|
sendPreprEvent(
|
|
2245
2329
|
"getScrollPosition",
|
|
@@ -2259,7 +2343,7 @@ function createPreprPreview(opts = {}) {
|
|
|
2259
2343
|
bridge.stop();
|
|
2260
2344
|
}
|
|
2261
2345
|
el?.remove();
|
|
2262
|
-
|
|
2346
|
+
debug9.log("preview destroyed");
|
|
2263
2347
|
}
|
|
2264
2348
|
const controller = { destroy };
|
|
2265
2349
|
controllerStores.set(controller, store);
|
|
@@ -2270,7 +2354,7 @@ function createPreprPreview(opts = {}) {
|
|
|
2270
2354
|
var import_react = require("react");
|
|
2271
2355
|
|
|
2272
2356
|
// src/version.ts
|
|
2273
|
-
var VERSION = "0.
|
|
2357
|
+
var VERSION = "0.5.0-rc.2";
|
|
2274
2358
|
|
|
2275
2359
|
// src/core/pixel.ts
|
|
2276
2360
|
var PIXEL_SCRIPT_URL = "https://cdn.tracking.prepr.io/js/prepr.min.js";
|
package/dist/nextjs/index.cjs
CHANGED
package/dist/nextjs/index.d.cts
CHANGED
|
@@ -60,8 +60,14 @@ interface PreprPreviewOptions extends PreprToolbarOptions {
|
|
|
60
60
|
*/
|
|
61
61
|
ui?: boolean;
|
|
62
62
|
/**
|
|
63
|
-
* Replace the `*.prepr.io` editor-origin wildcard with an exact list.
|
|
64
|
-
* Intended for self-hosted
|
|
63
|
+
* Replace the `*.prepr.io` editor-origin wildcard with an exact list, e.g.
|
|
64
|
+
* `['http://acme.localhost:8000']`. Intended for self-hosted or locally run
|
|
65
|
+
* editors; when set, the wildcard no longer applies. Entries are compared to
|
|
66
|
+
* the editor's origin exactly: scheme, host and port.
|
|
67
|
+
*
|
|
68
|
+
* `['*']` accepts any editor origin. Use it for development only: any page
|
|
69
|
+
* that frames the preview can then switch on preview and edit mode and
|
|
70
|
+
* receives the field-edit events, which carry content item ids.
|
|
65
71
|
*/
|
|
66
72
|
allowedEditorOrigins?: string[];
|
|
67
73
|
/**
|
package/dist/nextjs/index.d.ts
CHANGED
|
@@ -60,8 +60,14 @@ interface PreprPreviewOptions extends PreprToolbarOptions {
|
|
|
60
60
|
*/
|
|
61
61
|
ui?: boolean;
|
|
62
62
|
/**
|
|
63
|
-
* Replace the `*.prepr.io` editor-origin wildcard with an exact list.
|
|
64
|
-
* Intended for self-hosted
|
|
63
|
+
* Replace the `*.prepr.io` editor-origin wildcard with an exact list, e.g.
|
|
64
|
+
* `['http://acme.localhost:8000']`. Intended for self-hosted or locally run
|
|
65
|
+
* editors; when set, the wildcard no longer applies. Entries are compared to
|
|
66
|
+
* the editor's origin exactly: scheme, host and port.
|
|
67
|
+
*
|
|
68
|
+
* `['*']` accepts any editor origin. Use it for development only: any page
|
|
69
|
+
* that frames the preview can then switch on preview and edit mode and
|
|
70
|
+
* receives the field-edit events, which carry content item ids.
|
|
65
71
|
*/
|
|
66
72
|
allowedEditorOrigins?: string[];
|
|
67
73
|
/**
|
package/dist/nextjs/index.js
CHANGED
package/dist/nuxt/index.cjs
CHANGED
package/dist/nuxt/index.js
CHANGED
|
@@ -64,8 +64,14 @@ interface PreprPreviewOptions extends PreprToolbarOptions {
|
|
|
64
64
|
*/
|
|
65
65
|
ui?: boolean;
|
|
66
66
|
/**
|
|
67
|
-
* Replace the `*.prepr.io` editor-origin wildcard with an exact list.
|
|
68
|
-
* Intended for self-hosted
|
|
67
|
+
* Replace the `*.prepr.io` editor-origin wildcard with an exact list, e.g.
|
|
68
|
+
* `['http://acme.localhost:8000']`. Intended for self-hosted or locally run
|
|
69
|
+
* editors; when set, the wildcard no longer applies. Entries are compared to
|
|
70
|
+
* the editor's origin exactly: scheme, host and port.
|
|
71
|
+
*
|
|
72
|
+
* `['*']` accepts any editor origin. Use it for development only: any page
|
|
73
|
+
* that frames the preview can then switch on preview and edit mode and
|
|
74
|
+
* receives the field-edit events, which carry content item ids.
|
|
69
75
|
*/
|
|
70
76
|
allowedEditorOrigins?: string[];
|
|
71
77
|
/**
|
|
@@ -64,8 +64,14 @@ interface PreprPreviewOptions extends PreprToolbarOptions {
|
|
|
64
64
|
*/
|
|
65
65
|
ui?: boolean;
|
|
66
66
|
/**
|
|
67
|
-
* Replace the `*.prepr.io` editor-origin wildcard with an exact list.
|
|
68
|
-
* Intended for self-hosted
|
|
67
|
+
* Replace the `*.prepr.io` editor-origin wildcard with an exact list, e.g.
|
|
68
|
+
* `['http://acme.localhost:8000']`. Intended for self-hosted or locally run
|
|
69
|
+
* editors; when set, the wildcard no longer applies. Entries are compared to
|
|
70
|
+
* the editor's origin exactly: scheme, host and port.
|
|
71
|
+
*
|
|
72
|
+
* `['*']` accepts any editor origin. Use it for development only: any page
|
|
73
|
+
* that frames the preview can then switch on preview and edit mode and
|
|
74
|
+
* receives the field-edit events, which carry content item ids.
|
|
69
75
|
*/
|
|
70
76
|
allowedEditorOrigins?: string[];
|
|
71
77
|
/**
|