@joryio/web-sdk 1.4.0-beta.6 → 1.4.0-beta.8

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.
Files changed (37) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/core/config.d.ts +1 -1
  3. package/dist/core/editor-gate.d.ts +2 -0
  4. package/dist/core/editor-gate.d.ts.map +1 -1
  5. package/dist/core/page-edits.d.ts +13 -0
  6. package/dist/core/page-edits.d.ts.map +1 -1
  7. package/dist/core/sdk.d.ts.map +1 -1
  8. package/dist/editor/editor-model.d.ts +16 -8
  9. package/dist/editor/editor-model.d.ts.map +1 -1
  10. package/dist/editor/editor-strings.d.ts +22 -1
  11. package/dist/editor/editor-strings.d.ts.map +1 -1
  12. package/dist/editor/editor-ui.d.ts +6 -2
  13. package/dist/editor/editor-ui.d.ts.map +1 -1
  14. package/dist/editor/liquid-field.d.ts +23 -0
  15. package/dist/editor/liquid-field.d.ts.map +1 -0
  16. package/dist/editor/visual-editor.d.ts +31 -2
  17. package/dist/editor/visual-editor.d.ts.map +1 -1
  18. package/dist/index.d.mts +1 -1
  19. package/dist/joryio-cards-ui.min.js +1 -1
  20. package/dist/joryio-editor.min.js +2 -2
  21. package/dist/joryio-editor.min.js.map +1 -1
  22. package/dist/joryio-sw.js +1 -1
  23. package/dist/joryio.cjs.js +68 -8
  24. package/dist/joryio.min.js +2 -2
  25. package/dist/joryio.min.js.map +1 -1
  26. package/dist/joryio.mjs +68 -8
  27. package/dist/joryio.umd.js +68 -8
  28. package/package.json +1 -1
  29. package/src/core/config.ts +1 -1
  30. package/src/core/editor-gate.ts +21 -0
  31. package/src/core/page-edits.ts +70 -3
  32. package/src/core/sdk.ts +4 -1
  33. package/src/editor/editor-model.ts +89 -38
  34. package/src/editor/editor-strings.ts +22 -1
  35. package/src/editor/editor-ui.ts +47 -5
  36. package/src/editor/liquid-field.ts +316 -0
  37. package/src/editor/visual-editor.ts +616 -124
package/dist/joryio-sw.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Joryio Web SDK v1.4.0-beta.6
2
+ * Joryio Web SDK v1.4.0-beta.8
3
3
  * (c) 2026 Joryio. All rights reserved.
4
4
  * @license Commercial - see https://github.com/joryio/joryio-web-sdk/blob/main/LICENSE
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Joryio Web SDK v1.4.0-beta.6
2
+ * Joryio Web SDK v1.4.0-beta.8
3
3
  * (c) 2026 Joryio. All rights reserved.
4
4
  * @license Commercial - see https://github.com/joryio/joryio-web-sdk/blob/main/LICENSE
5
5
  */
@@ -29,7 +29,7 @@ function bucketHash(input) {
29
29
  return fmix32(hash >>> 0);
30
30
  }
31
31
 
32
- const SDK_VERSION = '1.4.0-beta.6';
32
+ const SDK_VERSION = '1.4.0-beta.8';
33
33
  const SDK_PLATFORM_HEADER = 'X-Joryio-SDK';
34
34
  const SDK_VERSION_HEADER = 'X-Joryio-SDK-Version';
35
35
  const SDK_PLATFORM = 'web';
@@ -552,6 +552,19 @@ function pageTriggerMet(trigger, signal, progress) {
552
552
 
553
553
  const PAGE_EDIT_POSITIONS = ['before', 'after', 'prepend', 'append', 'replace'];
554
554
  const PAGE_EDITS_CAPABILITY = 'page_edits';
555
+ const PAGE_EDIT_DEVICES = ['all', 'mobile', 'desktop'];
556
+ const PAGE_EDIT_DEVICE_CAPABILITY = 'page_edit_device';
557
+ const PAGE_EDIT_MOBILE_BREAKPOINT = 768;
558
+ const PAGE_EDIT_MOBILE_QUERY = '(max-width: 767.98px)';
559
+ function isMobileViewport(win = window) {
560
+ try {
561
+ return typeof win.matchMedia === 'function' ? win.matchMedia(PAGE_EDIT_MOBILE_QUERY).matches : win.innerWidth < PAGE_EDIT_MOBILE_BREAKPOINT;
562
+ }
563
+ catch (_a) {
564
+ return false;
565
+ }
566
+ }
567
+ const editShowsOn = (e, mobile) => !e.device || e.device === 'all' || (e.device === 'mobile') === mobile;
555
568
  const PAGE_EDIT_ANTI_FLICKER_MS = 300;
556
569
  const MAX_SELECTOR_LENGTH = 500;
557
570
  const MAX_TEXT_LENGTH = 2000;
@@ -574,13 +587,14 @@ const SERVER_ORIG_ATTR = 'data-joryio-orig';
574
587
  const SERVER_SPOT_ATTR = 'data-joryio-server-spot';
575
588
  const SERVER_MARKER_VERSION = 1;
576
589
  const sameEdit = (a, b) => {
577
- var _a, _b, _c, _d, _e, _f;
590
+ var _a, _b, _c, _d, _e, _f, _g, _h;
578
591
  return a.id === b.id &&
579
592
  a.selector === b.selector &&
580
593
  a.operation === b.operation &&
581
594
  ((_a = a.value) !== null && _a !== void 0 ? _a : null) === ((_b = b.value) !== null && _b !== void 0 ? _b : null) &&
582
595
  ((_c = a.placementKey) !== null && _c !== void 0 ? _c : null) === ((_d = b.placementKey) !== null && _d !== void 0 ? _d : null) &&
583
596
  ((_e = a.position) !== null && _e !== void 0 ? _e : null) === ((_f = b.position) !== null && _f !== void 0 ? _f : null) &&
597
+ ((_g = a.device) !== null && _g !== void 0 ? _g : null) === ((_h = b.device) !== null && _h !== void 0 ? _h : null) &&
584
598
  !b.personalized;
585
599
  };
586
600
  function serverMarkerElement() {
@@ -707,7 +721,10 @@ function isSafeEditUrl(url) {
707
721
  function trustedEdit(e) {
708
722
  if (!e || typeof e !== 'object' || typeof e.id !== 'string' || !isSafeSelector(e.selector))
709
723
  return null;
710
- const base = Object.assign({ id: e.id, selector: e.selector.trim() }, (e.personalized === true ? { personalized: true } : {}));
724
+ const device = e.device;
725
+ if (device != null && !PAGE_EDIT_DEVICES.includes(device))
726
+ return null;
727
+ const base = Object.assign(Object.assign({ id: e.id, selector: e.selector.trim() }, (device === 'mobile' || device === 'desktop' ? { device: device } : {})), (e.personalized === true ? { personalized: true } : {}));
711
728
  switch (e.operation) {
712
729
  case 'hide':
713
730
  return Object.assign(Object.assign({}, base), { operation: 'hide' });
@@ -746,6 +763,8 @@ class PageEditManager {
746
763
  this.server = null;
747
764
  this.serverUrl = null;
748
765
  this.generation = 0;
766
+ this.mobile = false;
767
+ this.offMedia = null;
749
768
  this.started = false;
750
769
  this.destroyed = false;
751
770
  this.stores = pageEditsStorageKeys(sdkKey);
@@ -769,6 +788,7 @@ class PageEditManager {
769
788
  }
770
789
  }
771
790
  start() {
791
+ var _a;
772
792
  if (this.started || this.destroyed || typeof document === 'undefined')
773
793
  return;
774
794
  this.started = true;
@@ -776,8 +796,28 @@ class PageEditManager {
776
796
  this.observer = new MutationObserver(() => this.schedule());
777
797
  this.observer.observe(document.documentElement, { childList: true, subtree: true });
778
798
  }
799
+ this.mobile = isMobileViewport();
800
+ const mq = typeof window.matchMedia === 'function' ? window.matchMedia(PAGE_EDIT_MOBILE_QUERY) : null;
801
+ if (mq) {
802
+ const onChange = () => this.viewportChanged();
803
+ if (mq.addEventListener)
804
+ mq.addEventListener('change', onChange);
805
+ else
806
+ (_a = mq.addListener) === null || _a === void 0 ? void 0 : _a.call(mq, onChange);
807
+ this.offMedia = () => { var _a; return (mq.removeEventListener ? mq.removeEventListener('change', onChange) : (_a = mq.removeListener) === null || _a === void 0 ? void 0 : _a.call(mq, onChange)); };
808
+ }
779
809
  this.loadPage();
780
810
  }
811
+ viewportChanged() {
812
+ const mobile = isMobileViewport();
813
+ if (this.destroyed || mobile === this.mobile)
814
+ return;
815
+ this.mobile = mobile;
816
+ if (!this.experiences.some((x) => x.edits.some((e) => e.device)))
817
+ return;
818
+ this.revertAll();
819
+ this.applyAll();
820
+ }
781
821
  invalidate(opts = {}) {
782
822
  this.generation++;
783
823
  this.reported.clear();
@@ -792,10 +832,12 @@ class PageEditManager {
792
832
  this.loadPage();
793
833
  }
794
834
  destroy() {
795
- var _a, _b;
835
+ var _a, _b, _c;
796
836
  this.destroyed = true;
797
837
  (_a = this.pageUnsubscribe) === null || _a === void 0 ? void 0 : _a.call(this);
798
- (_b = this.observer) === null || _b === void 0 ? void 0 : _b.disconnect();
838
+ (_b = this.offMedia) === null || _b === void 0 ? void 0 : _b.call(this);
839
+ this.offMedia = null;
840
+ (_c = this.observer) === null || _c === void 0 ? void 0 : _c.disconnect();
799
841
  this.observer = null;
800
842
  this.revertAll();
801
843
  this.showAll();
@@ -957,7 +999,7 @@ class PageEditManager {
957
999
  const personal = consent === 'granted';
958
1000
  const userId = personal ? this.identity.getUserId() : null;
959
1001
  const anonymousId = personal ? this.identity.getAnonymousId() : null;
960
- const body = Object.assign(Object.assign(Object.assign(Object.assign({}, (userId ? { userId } : {})), (anonymousId ? { anonymousId } : {})), (personal ? { sessionId: this.session.getSessionId() } : {})), { deviceType: 'web', locale: typeof navigator !== 'undefined' ? navigator.language : undefined, capabilities: [PAGE_CONTEXT_CAPABILITY, PAGE_EDITS_CAPABILITY], trackingConsent: consent, context: this.page ? this.page.current() : { url, pageVariables: {}, dataLayer: {} } });
1002
+ const body = Object.assign(Object.assign(Object.assign(Object.assign({}, (userId ? { userId } : {})), (anonymousId ? { anonymousId } : {})), (personal ? { sessionId: this.session.getSessionId() } : {})), { deviceType: 'web', locale: typeof navigator !== 'undefined' ? navigator.language : undefined, capabilities: [PAGE_CONTEXT_CAPABILITY, PAGE_EDITS_CAPABILITY, PAGE_EDIT_DEVICE_CAPABILITY], trackingConsent: consent, context: this.page ? this.page.current() : { url, pageVariables: {}, dataLayer: {} } });
961
1003
  const controller = typeof AbortController !== 'undefined' ? new AbortController() : null;
962
1004
  const timeout = setTimeout(() => controller === null || controller === void 0 ? void 0 : controller.abort(), (_a = this.runtime.requestTimeoutMs) !== null && _a !== void 0 ? _a : 10000);
963
1005
  try {
@@ -1017,6 +1059,8 @@ class PageEditManager {
1017
1059
  }
1018
1060
  let landed = false;
1019
1061
  for (const edit of x.edits) {
1062
+ if (!editShowsOn(edit, this.mobile))
1063
+ continue;
1020
1064
  const token = `${x.wire.id}:${edit.id}`;
1021
1065
  const server = this.serverEdits().get(token);
1022
1066
  const byServer = !!server && server.variantId === ((_b = x.wire.variantId) !== null && _b !== void 0 ? _b : null) && sameEdit(server.edit, edit);
@@ -1164,7 +1208,7 @@ class PageEditManager {
1164
1208
  return `${this.identity.getUserId() || ''}|${this.identity.getAnonymousId()}`;
1165
1209
  }
1166
1210
  remember(url, experiences, ttlSeconds) {
1167
- const selectors = [...new Set(experiences.flatMap((x) => (x.wire.isControl ? [] : x.edits.map((e) => e.selector))))];
1211
+ const selectors = [...new Set(experiences.flatMap((x) => (x.wire.isControl ? [] : x.edits.filter((e) => editShowsOn(e, this.mobile)).map((e) => e.selector))))];
1168
1212
  try {
1169
1213
  const all = JSON.parse(localStorage.getItem(this.stores.selectors) || '{}') || {};
1170
1214
  delete all[url];
@@ -1481,6 +1525,19 @@ function editorRequested() {
1481
1525
  return false;
1482
1526
  }
1483
1527
  }
1528
+ const EDITOR_FRAME_FLAG = 'frame';
1529
+ function editorFrame() {
1530
+ try {
1531
+ if (typeof window === 'undefined' || window.parent === window)
1532
+ return false;
1533
+ if (new URLSearchParams(window.location.search).get(EDITOR_QUERY_FLAG) !== EDITOR_FRAME_FLAG)
1534
+ return false;
1535
+ return !!window.parent[EDITOR_GLOBAL];
1536
+ }
1537
+ catch (_a) {
1538
+ return false;
1539
+ }
1540
+ }
1484
1541
  function loadScript(src) {
1485
1542
  return loadSdkScript(src, 'data-joryio-editor');
1486
1543
  }
@@ -9339,6 +9396,9 @@ class JoryioSDK {
9339
9396
  console.error(`[Joryio] SDK not started: ${keyProblem}. Calls on this instance are ignored.`);
9340
9397
  this.disabled = true;
9341
9398
  }
9399
+ else if (editorFrame()) {
9400
+ this.disabled = true;
9401
+ }
9342
9402
  this.config = resolveConfig(keyProblem
9343
9403
  ? Object.assign(Object.assign({}, (config && typeof config === 'object' ? config : {})), { sdkKey: 'jry_sdk_invalid', optOut: false }) : config);
9344
9404
  this.logger = new Logger(this.config.loggingEnabled, this.config.logLevel);