@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.mjs 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
  */
@@ -25,7 +25,7 @@ function bucketHash(input) {
25
25
  return fmix32(hash >>> 0);
26
26
  }
27
27
 
28
- const SDK_VERSION = '1.4.0-beta.6';
28
+ const SDK_VERSION = '1.4.0-beta.8';
29
29
  const SDK_PLATFORM_HEADER = 'X-Joryio-SDK';
30
30
  const SDK_VERSION_HEADER = 'X-Joryio-SDK-Version';
31
31
  const SDK_PLATFORM = 'web';
@@ -548,6 +548,19 @@ function pageTriggerMet(trigger, signal, progress) {
548
548
 
549
549
  const PAGE_EDIT_POSITIONS = ['before', 'after', 'prepend', 'append', 'replace'];
550
550
  const PAGE_EDITS_CAPABILITY = 'page_edits';
551
+ const PAGE_EDIT_DEVICES = ['all', 'mobile', 'desktop'];
552
+ const PAGE_EDIT_DEVICE_CAPABILITY = 'page_edit_device';
553
+ const PAGE_EDIT_MOBILE_BREAKPOINT = 768;
554
+ const PAGE_EDIT_MOBILE_QUERY = '(max-width: 767.98px)';
555
+ function isMobileViewport(win = window) {
556
+ try {
557
+ return typeof win.matchMedia === 'function' ? win.matchMedia(PAGE_EDIT_MOBILE_QUERY).matches : win.innerWidth < PAGE_EDIT_MOBILE_BREAKPOINT;
558
+ }
559
+ catch (_a) {
560
+ return false;
561
+ }
562
+ }
563
+ const editShowsOn = (e, mobile) => !e.device || e.device === 'all' || (e.device === 'mobile') === mobile;
551
564
  const PAGE_EDIT_ANTI_FLICKER_MS = 300;
552
565
  const MAX_SELECTOR_LENGTH = 500;
553
566
  const MAX_TEXT_LENGTH = 2000;
@@ -570,13 +583,14 @@ const SERVER_ORIG_ATTR = 'data-joryio-orig';
570
583
  const SERVER_SPOT_ATTR = 'data-joryio-server-spot';
571
584
  const SERVER_MARKER_VERSION = 1;
572
585
  const sameEdit = (a, b) => {
573
- var _a, _b, _c, _d, _e, _f;
586
+ var _a, _b, _c, _d, _e, _f, _g, _h;
574
587
  return a.id === b.id &&
575
588
  a.selector === b.selector &&
576
589
  a.operation === b.operation &&
577
590
  ((_a = a.value) !== null && _a !== void 0 ? _a : null) === ((_b = b.value) !== null && _b !== void 0 ? _b : null) &&
578
591
  ((_c = a.placementKey) !== null && _c !== void 0 ? _c : null) === ((_d = b.placementKey) !== null && _d !== void 0 ? _d : null) &&
579
592
  ((_e = a.position) !== null && _e !== void 0 ? _e : null) === ((_f = b.position) !== null && _f !== void 0 ? _f : null) &&
593
+ ((_g = a.device) !== null && _g !== void 0 ? _g : null) === ((_h = b.device) !== null && _h !== void 0 ? _h : null) &&
580
594
  !b.personalized;
581
595
  };
582
596
  function serverMarkerElement() {
@@ -703,7 +717,10 @@ function isSafeEditUrl(url) {
703
717
  function trustedEdit(e) {
704
718
  if (!e || typeof e !== 'object' || typeof e.id !== 'string' || !isSafeSelector(e.selector))
705
719
  return null;
706
- const base = Object.assign({ id: e.id, selector: e.selector.trim() }, (e.personalized === true ? { personalized: true } : {}));
720
+ const device = e.device;
721
+ if (device != null && !PAGE_EDIT_DEVICES.includes(device))
722
+ return null;
723
+ const base = Object.assign(Object.assign({ id: e.id, selector: e.selector.trim() }, (device === 'mobile' || device === 'desktop' ? { device: device } : {})), (e.personalized === true ? { personalized: true } : {}));
707
724
  switch (e.operation) {
708
725
  case 'hide':
709
726
  return Object.assign(Object.assign({}, base), { operation: 'hide' });
@@ -742,6 +759,8 @@ class PageEditManager {
742
759
  this.server = null;
743
760
  this.serverUrl = null;
744
761
  this.generation = 0;
762
+ this.mobile = false;
763
+ this.offMedia = null;
745
764
  this.started = false;
746
765
  this.destroyed = false;
747
766
  this.stores = pageEditsStorageKeys(sdkKey);
@@ -765,6 +784,7 @@ class PageEditManager {
765
784
  }
766
785
  }
767
786
  start() {
787
+ var _a;
768
788
  if (this.started || this.destroyed || typeof document === 'undefined')
769
789
  return;
770
790
  this.started = true;
@@ -772,8 +792,28 @@ class PageEditManager {
772
792
  this.observer = new MutationObserver(() => this.schedule());
773
793
  this.observer.observe(document.documentElement, { childList: true, subtree: true });
774
794
  }
795
+ this.mobile = isMobileViewport();
796
+ const mq = typeof window.matchMedia === 'function' ? window.matchMedia(PAGE_EDIT_MOBILE_QUERY) : null;
797
+ if (mq) {
798
+ const onChange = () => this.viewportChanged();
799
+ if (mq.addEventListener)
800
+ mq.addEventListener('change', onChange);
801
+ else
802
+ (_a = mq.addListener) === null || _a === void 0 ? void 0 : _a.call(mq, onChange);
803
+ this.offMedia = () => { var _a; return (mq.removeEventListener ? mq.removeEventListener('change', onChange) : (_a = mq.removeListener) === null || _a === void 0 ? void 0 : _a.call(mq, onChange)); };
804
+ }
775
805
  this.loadPage();
776
806
  }
807
+ viewportChanged() {
808
+ const mobile = isMobileViewport();
809
+ if (this.destroyed || mobile === this.mobile)
810
+ return;
811
+ this.mobile = mobile;
812
+ if (!this.experiences.some((x) => x.edits.some((e) => e.device)))
813
+ return;
814
+ this.revertAll();
815
+ this.applyAll();
816
+ }
777
817
  invalidate(opts = {}) {
778
818
  this.generation++;
779
819
  this.reported.clear();
@@ -788,10 +828,12 @@ class PageEditManager {
788
828
  this.loadPage();
789
829
  }
790
830
  destroy() {
791
- var _a, _b;
831
+ var _a, _b, _c;
792
832
  this.destroyed = true;
793
833
  (_a = this.pageUnsubscribe) === null || _a === void 0 ? void 0 : _a.call(this);
794
- (_b = this.observer) === null || _b === void 0 ? void 0 : _b.disconnect();
834
+ (_b = this.offMedia) === null || _b === void 0 ? void 0 : _b.call(this);
835
+ this.offMedia = null;
836
+ (_c = this.observer) === null || _c === void 0 ? void 0 : _c.disconnect();
795
837
  this.observer = null;
796
838
  this.revertAll();
797
839
  this.showAll();
@@ -953,7 +995,7 @@ class PageEditManager {
953
995
  const personal = consent === 'granted';
954
996
  const userId = personal ? this.identity.getUserId() : null;
955
997
  const anonymousId = personal ? this.identity.getAnonymousId() : null;
956
- 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: {} } });
998
+ 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: {} } });
957
999
  const controller = typeof AbortController !== 'undefined' ? new AbortController() : null;
958
1000
  const timeout = setTimeout(() => controller === null || controller === void 0 ? void 0 : controller.abort(), (_a = this.runtime.requestTimeoutMs) !== null && _a !== void 0 ? _a : 10000);
959
1001
  try {
@@ -1013,6 +1055,8 @@ class PageEditManager {
1013
1055
  }
1014
1056
  let landed = false;
1015
1057
  for (const edit of x.edits) {
1058
+ if (!editShowsOn(edit, this.mobile))
1059
+ continue;
1016
1060
  const token = `${x.wire.id}:${edit.id}`;
1017
1061
  const server = this.serverEdits().get(token);
1018
1062
  const byServer = !!server && server.variantId === ((_b = x.wire.variantId) !== null && _b !== void 0 ? _b : null) && sameEdit(server.edit, edit);
@@ -1160,7 +1204,7 @@ class PageEditManager {
1160
1204
  return `${this.identity.getUserId() || ''}|${this.identity.getAnonymousId()}`;
1161
1205
  }
1162
1206
  remember(url, experiences, ttlSeconds) {
1163
- const selectors = [...new Set(experiences.flatMap((x) => (x.wire.isControl ? [] : x.edits.map((e) => e.selector))))];
1207
+ const selectors = [...new Set(experiences.flatMap((x) => (x.wire.isControl ? [] : x.edits.filter((e) => editShowsOn(e, this.mobile)).map((e) => e.selector))))];
1164
1208
  try {
1165
1209
  const all = JSON.parse(localStorage.getItem(this.stores.selectors) || '{}') || {};
1166
1210
  delete all[url];
@@ -1477,6 +1521,19 @@ function editorRequested() {
1477
1521
  return false;
1478
1522
  }
1479
1523
  }
1524
+ const EDITOR_FRAME_FLAG = 'frame';
1525
+ function editorFrame() {
1526
+ try {
1527
+ if (typeof window === 'undefined' || window.parent === window)
1528
+ return false;
1529
+ if (new URLSearchParams(window.location.search).get(EDITOR_QUERY_FLAG) !== EDITOR_FRAME_FLAG)
1530
+ return false;
1531
+ return !!window.parent[EDITOR_GLOBAL];
1532
+ }
1533
+ catch (_a) {
1534
+ return false;
1535
+ }
1536
+ }
1480
1537
  function loadScript(src) {
1481
1538
  return loadSdkScript(src, 'data-joryio-editor');
1482
1539
  }
@@ -9335,6 +9392,9 @@ class JoryioSDK {
9335
9392
  console.error(`[Joryio] SDK not started: ${keyProblem}. Calls on this instance are ignored.`);
9336
9393
  this.disabled = true;
9337
9394
  }
9395
+ else if (editorFrame()) {
9396
+ this.disabled = true;
9397
+ }
9338
9398
  this.config = resolveConfig(keyProblem
9339
9399
  ? Object.assign(Object.assign({}, (config && typeof config === 'object' ? config : {})), { sdkKey: 'jry_sdk_invalid', optOut: false }) : config);
9340
9400
  this.logger = new Logger(this.config.loggingEnabled, this.config.logLevel);
@@ -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
  */
@@ -28,7 +28,7 @@ var JoryioSDK = (function (exports) {
28
28
  return fmix32(hash >>> 0);
29
29
  }
30
30
 
31
- const SDK_VERSION = '1.4.0-beta.6';
31
+ const SDK_VERSION = '1.4.0-beta.8';
32
32
  const SDK_PLATFORM_HEADER = 'X-Joryio-SDK';
33
33
  const SDK_VERSION_HEADER = 'X-Joryio-SDK-Version';
34
34
  const SDK_PLATFORM = 'web';
@@ -551,6 +551,19 @@ var JoryioSDK = (function (exports) {
551
551
 
552
552
  const PAGE_EDIT_POSITIONS = ['before', 'after', 'prepend', 'append', 'replace'];
553
553
  const PAGE_EDITS_CAPABILITY = 'page_edits';
554
+ const PAGE_EDIT_DEVICES = ['all', 'mobile', 'desktop'];
555
+ const PAGE_EDIT_DEVICE_CAPABILITY = 'page_edit_device';
556
+ const PAGE_EDIT_MOBILE_BREAKPOINT = 768;
557
+ const PAGE_EDIT_MOBILE_QUERY = '(max-width: 767.98px)';
558
+ function isMobileViewport(win = window) {
559
+ try {
560
+ return typeof win.matchMedia === 'function' ? win.matchMedia(PAGE_EDIT_MOBILE_QUERY).matches : win.innerWidth < PAGE_EDIT_MOBILE_BREAKPOINT;
561
+ }
562
+ catch (_a) {
563
+ return false;
564
+ }
565
+ }
566
+ const editShowsOn = (e, mobile) => !e.device || e.device === 'all' || (e.device === 'mobile') === mobile;
554
567
  const PAGE_EDIT_ANTI_FLICKER_MS = 300;
555
568
  const MAX_SELECTOR_LENGTH = 500;
556
569
  const MAX_TEXT_LENGTH = 2000;
@@ -573,13 +586,14 @@ var JoryioSDK = (function (exports) {
573
586
  const SERVER_SPOT_ATTR = 'data-joryio-server-spot';
574
587
  const SERVER_MARKER_VERSION = 1;
575
588
  const sameEdit = (a, b) => {
576
- var _a, _b, _c, _d, _e, _f;
589
+ var _a, _b, _c, _d, _e, _f, _g, _h;
577
590
  return a.id === b.id &&
578
591
  a.selector === b.selector &&
579
592
  a.operation === b.operation &&
580
593
  ((_a = a.value) !== null && _a !== void 0 ? _a : null) === ((_b = b.value) !== null && _b !== void 0 ? _b : null) &&
581
594
  ((_c = a.placementKey) !== null && _c !== void 0 ? _c : null) === ((_d = b.placementKey) !== null && _d !== void 0 ? _d : null) &&
582
595
  ((_e = a.position) !== null && _e !== void 0 ? _e : null) === ((_f = b.position) !== null && _f !== void 0 ? _f : null) &&
596
+ ((_g = a.device) !== null && _g !== void 0 ? _g : null) === ((_h = b.device) !== null && _h !== void 0 ? _h : null) &&
583
597
  !b.personalized;
584
598
  };
585
599
  function serverMarkerElement() {
@@ -706,7 +720,10 @@ var JoryioSDK = (function (exports) {
706
720
  function trustedEdit(e) {
707
721
  if (!e || typeof e !== 'object' || typeof e.id !== 'string' || !isSafeSelector(e.selector))
708
722
  return null;
709
- const base = Object.assign({ id: e.id, selector: e.selector.trim() }, (e.personalized === true ? { personalized: true } : {}));
723
+ const device = e.device;
724
+ if (device != null && !PAGE_EDIT_DEVICES.includes(device))
725
+ return null;
726
+ const base = Object.assign(Object.assign({ id: e.id, selector: e.selector.trim() }, (device === 'mobile' || device === 'desktop' ? { device: device } : {})), (e.personalized === true ? { personalized: true } : {}));
710
727
  switch (e.operation) {
711
728
  case 'hide':
712
729
  return Object.assign(Object.assign({}, base), { operation: 'hide' });
@@ -745,6 +762,8 @@ var JoryioSDK = (function (exports) {
745
762
  this.server = null;
746
763
  this.serverUrl = null;
747
764
  this.generation = 0;
765
+ this.mobile = false;
766
+ this.offMedia = null;
748
767
  this.started = false;
749
768
  this.destroyed = false;
750
769
  this.stores = pageEditsStorageKeys(sdkKey);
@@ -768,6 +787,7 @@ var JoryioSDK = (function (exports) {
768
787
  }
769
788
  }
770
789
  start() {
790
+ var _a;
771
791
  if (this.started || this.destroyed || typeof document === 'undefined')
772
792
  return;
773
793
  this.started = true;
@@ -775,8 +795,28 @@ var JoryioSDK = (function (exports) {
775
795
  this.observer = new MutationObserver(() => this.schedule());
776
796
  this.observer.observe(document.documentElement, { childList: true, subtree: true });
777
797
  }
798
+ this.mobile = isMobileViewport();
799
+ const mq = typeof window.matchMedia === 'function' ? window.matchMedia(PAGE_EDIT_MOBILE_QUERY) : null;
800
+ if (mq) {
801
+ const onChange = () => this.viewportChanged();
802
+ if (mq.addEventListener)
803
+ mq.addEventListener('change', onChange);
804
+ else
805
+ (_a = mq.addListener) === null || _a === void 0 ? void 0 : _a.call(mq, onChange);
806
+ this.offMedia = () => { var _a; return (mq.removeEventListener ? mq.removeEventListener('change', onChange) : (_a = mq.removeListener) === null || _a === void 0 ? void 0 : _a.call(mq, onChange)); };
807
+ }
778
808
  this.loadPage();
779
809
  }
810
+ viewportChanged() {
811
+ const mobile = isMobileViewport();
812
+ if (this.destroyed || mobile === this.mobile)
813
+ return;
814
+ this.mobile = mobile;
815
+ if (!this.experiences.some((x) => x.edits.some((e) => e.device)))
816
+ return;
817
+ this.revertAll();
818
+ this.applyAll();
819
+ }
780
820
  invalidate(opts = {}) {
781
821
  this.generation++;
782
822
  this.reported.clear();
@@ -791,10 +831,12 @@ var JoryioSDK = (function (exports) {
791
831
  this.loadPage();
792
832
  }
793
833
  destroy() {
794
- var _a, _b;
834
+ var _a, _b, _c;
795
835
  this.destroyed = true;
796
836
  (_a = this.pageUnsubscribe) === null || _a === void 0 ? void 0 : _a.call(this);
797
- (_b = this.observer) === null || _b === void 0 ? void 0 : _b.disconnect();
837
+ (_b = this.offMedia) === null || _b === void 0 ? void 0 : _b.call(this);
838
+ this.offMedia = null;
839
+ (_c = this.observer) === null || _c === void 0 ? void 0 : _c.disconnect();
798
840
  this.observer = null;
799
841
  this.revertAll();
800
842
  this.showAll();
@@ -956,7 +998,7 @@ var JoryioSDK = (function (exports) {
956
998
  const personal = consent === 'granted';
957
999
  const userId = personal ? this.identity.getUserId() : null;
958
1000
  const anonymousId = personal ? this.identity.getAnonymousId() : null;
959
- 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: {} } });
1001
+ 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: {} } });
960
1002
  const controller = typeof AbortController !== 'undefined' ? new AbortController() : null;
961
1003
  const timeout = setTimeout(() => controller === null || controller === void 0 ? void 0 : controller.abort(), (_a = this.runtime.requestTimeoutMs) !== null && _a !== void 0 ? _a : 10000);
962
1004
  try {
@@ -1016,6 +1058,8 @@ var JoryioSDK = (function (exports) {
1016
1058
  }
1017
1059
  let landed = false;
1018
1060
  for (const edit of x.edits) {
1061
+ if (!editShowsOn(edit, this.mobile))
1062
+ continue;
1019
1063
  const token = `${x.wire.id}:${edit.id}`;
1020
1064
  const server = this.serverEdits().get(token);
1021
1065
  const byServer = !!server && server.variantId === ((_b = x.wire.variantId) !== null && _b !== void 0 ? _b : null) && sameEdit(server.edit, edit);
@@ -1163,7 +1207,7 @@ var JoryioSDK = (function (exports) {
1163
1207
  return `${this.identity.getUserId() || ''}|${this.identity.getAnonymousId()}`;
1164
1208
  }
1165
1209
  remember(url, experiences, ttlSeconds) {
1166
- const selectors = [...new Set(experiences.flatMap((x) => (x.wire.isControl ? [] : x.edits.map((e) => e.selector))))];
1210
+ const selectors = [...new Set(experiences.flatMap((x) => (x.wire.isControl ? [] : x.edits.filter((e) => editShowsOn(e, this.mobile)).map((e) => e.selector))))];
1167
1211
  try {
1168
1212
  const all = JSON.parse(localStorage.getItem(this.stores.selectors) || '{}') || {};
1169
1213
  delete all[url];
@@ -1480,6 +1524,19 @@ var JoryioSDK = (function (exports) {
1480
1524
  return false;
1481
1525
  }
1482
1526
  }
1527
+ const EDITOR_FRAME_FLAG = 'frame';
1528
+ function editorFrame() {
1529
+ try {
1530
+ if (typeof window === 'undefined' || window.parent === window)
1531
+ return false;
1532
+ if (new URLSearchParams(window.location.search).get(EDITOR_QUERY_FLAG) !== EDITOR_FRAME_FLAG)
1533
+ return false;
1534
+ return !!window.parent[EDITOR_GLOBAL];
1535
+ }
1536
+ catch (_a) {
1537
+ return false;
1538
+ }
1539
+ }
1483
1540
  function loadScript(src) {
1484
1541
  return loadSdkScript(src, 'data-joryio-editor');
1485
1542
  }
@@ -9338,6 +9395,9 @@ var JoryioSDK = (function (exports) {
9338
9395
  console.error(`[Joryio] SDK not started: ${keyProblem}. Calls on this instance are ignored.`);
9339
9396
  this.disabled = true;
9340
9397
  }
9398
+ else if (editorFrame()) {
9399
+ this.disabled = true;
9400
+ }
9341
9401
  this.config = resolveConfig(keyProblem
9342
9402
  ? Object.assign(Object.assign({}, (config && typeof config === 'object' ? config : {})), { sdkKey: 'jry_sdk_invalid', optOut: false }) : config);
9343
9403
  this.logger = new Logger(this.config.loggingEnabled, this.config.logLevel);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@joryio/web-sdk",
3
- "version": "1.4.0-beta.6",
3
+ "version": "1.4.0-beta.8",
4
4
  "description": "Joryio Web Tracking SDK - Lightweight analytics and event tracking",
5
5
  "main": "dist/joryio.cjs.js",
6
6
  "module": "dist/joryio.mjs",
@@ -2,7 +2,7 @@
2
2
  * SDK Configuration Types and Defaults
3
3
  */
4
4
 
5
- export const SDK_VERSION = '1.4.0-beta.6'; // keep in sync with package.json (sdk-version-parity.spec.ts pins it)
5
+ export const SDK_VERSION = '1.4.0-beta.8'; // keep in sync with package.json (sdk-version-parity.spec.ts pins it)
6
6
 
7
7
  /**
8
8
  * Sent on EVERY request to the API, so the dashboard can show which SDK
@@ -60,6 +60,27 @@ export function editorRequested(): boolean {
60
60
  }
61
61
  }
62
62
 
63
+ /** The flag's value on the editor's own Mobile view (a frame of the page at phone width, 1.4.0-beta.8). */
64
+ export const EDITOR_FRAME_FLAG = 'frame';
65
+
66
+ /**
67
+ * True in the editor's Mobile view: a same-origin frame of the page, opened
68
+ * with `?joryio_editor=frame` by the editor running in its parent tab. The
69
+ * SDK there is inert (no page view, no in-app message, no page edit): the
70
+ * frame is a preview the editor draws on, not a visit. A frame on another
71
+ * origin, or one whose parent is not a running editor, is a normal page.
72
+ */
73
+ export function editorFrame(): boolean {
74
+ try {
75
+ if (typeof window === 'undefined' || window.parent === window) return false;
76
+ if (new URLSearchParams(window.location.search).get(EDITOR_QUERY_FLAG) !== EDITOR_FRAME_FLAG) return false;
77
+ // Reading the parent's global throws across origins.
78
+ return !!(window.parent as any)[EDITOR_GLOBAL];
79
+ } catch {
80
+ return false;
81
+ }
82
+ }
83
+
63
84
  function loadScript(src: string): Promise<void> {
64
85
  return loadSdkScript(src, 'data-joryio-editor');
65
86
  }
@@ -24,6 +24,16 @@
24
24
  * element appears (MutationObserver); personalized edits apply when the
25
25
  * answer arrives and are never stored.
26
26
  * - A route change undoes this page's edits and applies the next page's.
27
+ * - Per device (1.4.0-beta.8): an edit may carry `device: 'mobile' | 'desktop'`
28
+ * (absent or `all` = every device, as before). Mobile = a viewport narrower
29
+ * than PAGE_EDIT_MOBILE_BREAKPOINT (768) CSS pixels, the one number the
30
+ * backend, the dashboard and the editor use too. An edit for the other
31
+ * device is not applied; when the viewport crosses the breakpoint (a
32
+ * resize, a turned phone) every edit is undone and the ones for the new
33
+ * width applied again, so a desktop and a mobile edit of one element never
34
+ * fight. The SDK says it understands this with the capability
35
+ * `page_edit_device`; the server sends an SDK without it no per-device
36
+ * edit at all (an older build would apply both versions everywhere).
27
37
  * - Exposure: `in_app.displayed` once an edit of the experience landed on an
28
38
  * element; a control visitor reports `in_app.control_viewed` once one of
29
39
  * the control's selectors is on the page.
@@ -52,6 +62,26 @@ export const PAGE_EDIT_OPERATIONS = ['replace_text', 'replace_image', 'replace_l
52
62
  /** `replace` ("Instead of it"): the element is hidden and the spot takes its place, right after it. */
53
63
  export const PAGE_EDIT_POSITIONS = ['before', 'after', 'prepend', 'append', 'replace'] as const;
54
64
  export const PAGE_EDITS_CAPABILITY = 'page_edits';
65
+ /** Which viewport an edit is for; absent = `all`. */
66
+ export const PAGE_EDIT_DEVICES = ['all', 'mobile', 'desktop'] as const;
67
+ /** Sent with `page_edits` by a build that applies an edit only on its device. */
68
+ export const PAGE_EDIT_DEVICE_CAPABILITY = 'page_edit_device';
69
+ /** Mobile = viewport width below this many CSS pixels (backend PAGE_EDIT_MOBILE_BREAKPOINT, the dashboard, the editor). */
70
+ export const PAGE_EDIT_MOBILE_BREAKPOINT = 768;
71
+ export const PAGE_EDIT_MOBILE_QUERY = '(max-width: 767.98px)';
72
+ export type PageEditDevice = (typeof PAGE_EDIT_DEVICES)[number];
73
+
74
+ /** True when this window is a mobile viewport (below the breakpoint). */
75
+ export function isMobileViewport(win: Window = window): boolean {
76
+ try {
77
+ return typeof win.matchMedia === 'function' ? win.matchMedia(PAGE_EDIT_MOBILE_QUERY).matches : win.innerWidth < PAGE_EDIT_MOBILE_BREAKPOINT;
78
+ } catch {
79
+ return false;
80
+ }
81
+ }
82
+
83
+ /** An edit shows on this viewport: no device, `all`, or the viewport's own. */
84
+ export const editShowsOn = (e: { device?: string }, mobile: boolean): boolean => !e.device || e.device === 'all' || (e.device === 'mobile') === mobile;
55
85
  /** The longest edited elements stay hidden while the SDK waits. Never the whole body. */
56
86
  export const PAGE_EDIT_ANTI_FLICKER_MS = 300;
57
87
 
@@ -114,6 +144,7 @@ const sameEdit = (a: PageEditWire, b: PageEditWire): boolean =>
114
144
  (a.value ?? null) === (b.value ?? null) &&
115
145
  (a.placementKey ?? null) === (b.placementKey ?? null) &&
116
146
  (a.position ?? null) === (b.position ?? null) &&
147
+ (a.device ?? null) === (b.device ?? null) &&
117
148
  !b.personalized;
118
149
 
119
150
  function serverMarkerElement(): HTMLScriptElement | null {
@@ -241,6 +272,8 @@ export interface PageEditWire {
241
272
  value?: string;
242
273
  placementKey?: string;
243
274
  position?: PageEditPosition;
275
+ /** Only this viewport (`mobile` / `desktop`); absent = every device. */
276
+ device?: 'mobile' | 'desktop';
244
277
  personalized?: true;
245
278
  }
246
279
 
@@ -296,7 +329,15 @@ export function isSafeEditUrl(url: unknown): url is string {
296
329
  /** The edit as this SDK will apply it, or null - an edit it does not trust is skipped whole. */
297
330
  export function trustedEdit(e: any): PageEditWire | null {
298
331
  if (!e || typeof e !== 'object' || typeof e.id !== 'string' || !isSafeSelector(e.selector)) return null;
299
- const base = { id: e.id, selector: e.selector.trim(), ...(e.personalized === true ? { personalized: true as const } : {}) };
332
+ // A device this build does not know is skipped whole, never applied everywhere.
333
+ const device = e.device;
334
+ if (device != null && !(PAGE_EDIT_DEVICES as readonly unknown[]).includes(device)) return null;
335
+ const base = {
336
+ id: e.id,
337
+ selector: e.selector.trim(),
338
+ ...(device === 'mobile' || device === 'desktop' ? { device: device as 'mobile' | 'desktop' } : {}),
339
+ ...(e.personalized === true ? { personalized: true as const } : {}),
340
+ };
300
341
  switch (e.operation) {
301
342
  case 'hide':
302
343
  return { ...base, operation: 'hide' };
@@ -352,6 +393,9 @@ export class PageEditManager {
352
393
  /** The page those were written for: a route change elsewhere undoes them. */
353
394
  private serverUrl: string | null = null;
354
395
  private generation = 0;
396
+ /** The viewport the applied edits were chosen for (true = mobile). */
397
+ private mobile = false;
398
+ private offMedia: (() => void) | null = null;
355
399
  private started = false;
356
400
  private destroyed = false;
357
401
 
@@ -393,9 +437,27 @@ export class PageEditManager {
393
437
  this.observer = new MutationObserver(() => this.schedule());
394
438
  this.observer.observe(document.documentElement, { childList: true, subtree: true });
395
439
  }
440
+ this.mobile = isMobileViewport();
441
+ // The breakpoint crossed (resize, a turned phone): undo, and apply what fits the new width.
442
+ const mq = typeof window.matchMedia === 'function' ? window.matchMedia(PAGE_EDIT_MOBILE_QUERY) : null;
443
+ if (mq) {
444
+ const onChange = () => this.viewportChanged();
445
+ if (mq.addEventListener) mq.addEventListener('change', onChange);
446
+ else mq.addListener?.(onChange);
447
+ this.offMedia = () => (mq.removeEventListener ? mq.removeEventListener('change', onChange) : mq.removeListener?.(onChange));
448
+ }
396
449
  this.loadPage();
397
450
  }
398
451
 
452
+ private viewportChanged(): void {
453
+ const mobile = isMobileViewport();
454
+ if (this.destroyed || mobile === this.mobile) return;
455
+ this.mobile = mobile;
456
+ if (!this.experiences.some((x) => x.edits.some((e) => e.device))) return;
457
+ this.revertAll();
458
+ this.applyAll();
459
+ }
460
+
399
461
  /**
400
462
  * The audience changed (identify, reset, consent): forget this visitor's
401
463
  * answers and ask again. `siteSettings: true` (reset, wipeData, a consent
@@ -417,6 +479,8 @@ export class PageEditManager {
417
479
  destroy(): void {
418
480
  this.destroyed = true;
419
481
  this.pageUnsubscribe?.();
482
+ this.offMedia?.();
483
+ this.offMedia = null;
420
484
  this.observer?.disconnect();
421
485
  this.observer = null;
422
486
  this.revertAll();
@@ -609,7 +673,7 @@ export class PageEditManager {
609
673
  ...(personal ? { sessionId: this.session.getSessionId() } : {}),
610
674
  deviceType: 'web',
611
675
  locale: typeof navigator !== 'undefined' ? navigator.language : undefined,
612
- capabilities: [PAGE_CONTEXT_CAPABILITY, PAGE_EDITS_CAPABILITY],
676
+ capabilities: [PAGE_CONTEXT_CAPABILITY, PAGE_EDITS_CAPABILITY, PAGE_EDIT_DEVICE_CAPABILITY],
613
677
  trackingConsent: consent,
614
678
  context: this.page ? this.page.current() : { url, pageVariables: {}, dataLayer: {} },
615
679
  };
@@ -678,6 +742,8 @@ export class PageEditManager {
678
742
  }
679
743
  let landed = false;
680
744
  for (const edit of x.edits) {
745
+ // Another device's edit: not on this viewport (applied when the width crosses the breakpoint).
746
+ if (!editShowsOn(edit, this.mobile)) continue;
681
747
  const token = `${x.wire.id}:${edit.id}`;
682
748
  const server = this.serverEdits().get(token);
683
749
  const byServer = !!server && server.variantId === (x.wire.variantId ?? null) && sameEdit(server.edit, edit);
@@ -825,7 +891,8 @@ export class PageEditManager {
825
891
  }
826
892
 
827
893
  private remember(url: string, experiences: Experience[], ttlSeconds?: number): void {
828
- const selectors = [...new Set(experiences.flatMap((x) => (x.wire.isControl ? [] : x.edits.map((e) => e.selector))))];
894
+ // Held back next time: only what this viewport shows.
895
+ const selectors = [...new Set(experiences.flatMap((x) => (x.wire.isControl ? [] : x.edits.filter((e) => editShowsOn(e, this.mobile)).map((e) => e.selector))))];
829
896
  try {
830
897
  const all = JSON.parse(localStorage.getItem(this.stores.selectors) || '{}') || {};
831
898
  delete all[url];
package/src/core/sdk.ts CHANGED
@@ -4,7 +4,7 @@
4
4
  */
5
5
 
6
6
  import { PageEditManager } from './page-edits';
7
- import { EditorGate, editorRequested } from './editor-gate';
7
+ import { EditorGate, editorFrame, editorRequested } from './editor-gate';
8
8
  import { PageContextTracker } from './page-context';
9
9
  import { InitConfig, ResolvedConfig, resolveConfig, SDK_VERSION } from './config';
10
10
  import { StorageManager } from './storage';
@@ -349,6 +349,9 @@ export class JoryioSDK {
349
349
  // eslint-disable-next-line no-console -- the logger is silent by default and this is the reason nothing works
350
350
  console.error(`[Joryio] SDK not started: ${keyProblem}. Calls on this instance are ignored.`);
351
351
  this.disabled = true;
352
+ } else if (editorFrame()) {
353
+ // The page editor's Mobile view (a frame in the editor tab): a preview, not a visit - nothing is sent or applied.
354
+ this.disabled = true;
352
355
  }
353
356
 
354
357
  // Resolve config with defaults