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

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/dist/joryio.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Joryio Web SDK v1.4.0-beta.5
2
+ * Joryio Web SDK v1.4.0-beta.6
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';
28
+ const SDK_VERSION = '1.4.0-beta.6';
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';
@@ -546,7 +546,7 @@ function pageTriggerMet(trigger, signal, progress) {
546
546
  }
547
547
  }
548
548
 
549
- const PAGE_EDIT_POSITIONS = ['before', 'after', 'prepend', 'append'];
549
+ const PAGE_EDIT_POSITIONS = ['before', 'after', 'prepend', 'append', 'replace'];
550
550
  const PAGE_EDITS_CAPABILITY = 'page_edits';
551
551
  const PAGE_EDIT_ANTI_FLICKER_MS = 300;
552
552
  const MAX_SELECTOR_LENGTH = 500;
@@ -602,6 +602,27 @@ function safeRestoredUrl(v) {
602
602
  }
603
603
  const safeRestoredSrcset = (v) => typeof v === 'string' && v.split(',').every((c) => !c.trim() || safeRestoredUrl(c.trim().split(/\s+/)[0]) !== null) ? v : null;
604
604
  const HIDE_DECLARATION = 'display:none !important';
605
+ function hideElement(h) {
606
+ const display = h.style.getPropertyValue('display');
607
+ const priority = h.style.getPropertyPriority('display');
608
+ h.style.setProperty('display', 'none', 'important');
609
+ return () => (display ? h.style.setProperty('display', display, priority) : h.style.removeProperty('display'));
610
+ }
611
+ function undoServerHide(el, orig) {
612
+ var _a;
613
+ const current = el.getAttribute('style') || '';
614
+ const before = typeof orig.style === 'string' ? orig.style : null;
615
+ const base = before === null ? '' : before.trim().replace(/;+$/, '');
616
+ if (current === (base ? base + ';' : '') + HIDE_DECLARATION) {
617
+ if (before === null)
618
+ el.removeAttribute('style');
619
+ else
620
+ el.setAttribute('style', before);
621
+ }
622
+ else if (((_a = el.style) === null || _a === void 0 ? void 0 : _a.getPropertyValue('display')) === 'none') {
623
+ el.style.removeProperty('display');
624
+ }
625
+ }
605
626
  const RESTORE_ELEMENTS = new Set(['A', 'ABBR', 'B', 'BDI', 'BDO', 'BR', 'CITE', 'CODE', 'DATA', 'DEL', 'DFN', 'EM', 'I', 'IMG', 'INS', 'KBD', 'MARK', 'Q', 'S', 'SAMP', 'SMALL', 'SPAN', 'STRONG', 'SUB', 'SUP', 'TIME', 'U', 'VAR', 'WBR']);
606
627
  const RESTORE_ATTRIBUTES = new Set(['class', 'id', 'title', 'lang', 'dir', 'alt', 'width', 'height', 'datetime', 'href', 'src', 'srcset', 'rel', 'target']);
607
628
  const MAX_RESTORE_NODES = 500;
@@ -1063,19 +1084,21 @@ class PageEditManager {
1063
1084
  el.setAttribute('href', edit.value);
1064
1085
  return () => (href === null ? el.removeAttribute('href') : el.setAttribute('href', href));
1065
1086
  }
1066
- case 'hide': {
1067
- const display = h.style.getPropertyValue('display');
1068
- const priority = h.style.getPropertyPriority('display');
1069
- h.style.setProperty('display', 'none', 'important');
1070
- return () => (display ? h.style.setProperty('display', display, priority) : h.style.removeProperty('display'));
1071
- }
1087
+ case 'hide':
1088
+ return hideElement(h);
1072
1089
  case 'insert_placement': {
1073
1090
  const spot = document.createElement('div');
1074
1091
  spot.setAttribute('data-joryio-placement', edit.placementKey);
1075
1092
  spot.setAttribute('data-joryio-edit', edit.id);
1076
1093
  const where = edit.position === 'before' ? 'beforebegin' : edit.position === 'prepend' ? 'afterbegin' : edit.position === 'append' ? 'beforeend' : 'afterend';
1077
1094
  el.insertAdjacentElement(where, spot);
1078
- return () => spot.remove();
1095
+ if (edit.position !== 'replace')
1096
+ return () => spot.remove();
1097
+ const show = hideElement(h);
1098
+ return () => {
1099
+ spot.remove();
1100
+ show();
1101
+ };
1079
1102
  }
1080
1103
  default:
1081
1104
  return null;
@@ -1256,7 +1279,6 @@ class PageEditManager {
1256
1279
  }
1257
1280
  }
1258
1281
  undoServerEdit(token, edit) {
1259
- var _a;
1260
1282
  for (const el of Array.from(document.querySelectorAll(`[${SERVER_APPLIED_ATTR}]`))) {
1261
1283
  const tokens = tokensOf(el);
1262
1284
  if (!tokens.includes(token))
@@ -1265,7 +1287,7 @@ class PageEditManager {
1265
1287
  try {
1266
1288
  all = JSON.parse(el.getAttribute(SERVER_ORIG_ATTR) || '{}') || {};
1267
1289
  }
1268
- catch (_b) {
1290
+ catch (_a) {
1269
1291
  all = {};
1270
1292
  }
1271
1293
  const orig = all[token] || {};
@@ -1301,26 +1323,18 @@ class PageEditManager {
1301
1323
  el.setAttribute('href', href);
1302
1324
  }
1303
1325
  break;
1304
- case 'hide': {
1305
- const current = el.getAttribute('style') || '';
1306
- const before = typeof orig.style === 'string' ? orig.style : null;
1307
- const base = before === null ? '' : before.trim().replace(/;+$/, '');
1308
- if (current === (base ? base + ';' : '') + HIDE_DECLARATION) {
1309
- if (before === null)
1310
- el.removeAttribute('style');
1311
- else
1312
- el.setAttribute('style', before);
1313
- }
1314
- else if (((_a = el.style) === null || _a === void 0 ? void 0 : _a.getPropertyValue('display')) === 'none') {
1315
- el.style.removeProperty('display');
1316
- }
1326
+ case 'hide':
1327
+ undoServerHide(el, orig);
1328
+ break;
1329
+ case 'insert_placement':
1330
+ if (edit.position === 'replace')
1331
+ undoServerHide(el, orig);
1317
1332
  break;
1318
- }
1319
1333
  default:
1320
1334
  break;
1321
1335
  }
1322
1336
  }
1323
- catch (_c) {
1337
+ catch (_b) {
1324
1338
  }
1325
1339
  const left = tokens.filter((t) => t !== token);
1326
1340
  if (left.length)
@@ -1413,13 +1427,16 @@ function readOwnFolder() {
1413
1427
  return null;
1414
1428
  }
1415
1429
  const OWN_FOLDER = readOwnFolder();
1416
- function sdkHostFileUrls(file, override, ownFolder = OWN_FOLDER) {
1430
+ function sdkHostFileUrls(file, override, ownFolder = OWN_FOLDER, version = SDK_VERSION) {
1417
1431
  if (override)
1418
1432
  return [override];
1419
- const major = SDK_VERSION.split('.')[0];
1420
- const exact = `${SDK_HOST}/web/${SDK_VERSION}/${file}`;
1433
+ const major = version.split('.')[0];
1434
+ const exact = `${SDK_HOST}/web/${version}/${file}`;
1421
1435
  const channel = `${SDK_HOST}/web/${major}/${file}`;
1422
- const urls = ownFolder && ownFolder !== `${SDK_HOST}/web/${major}/` ? [`${ownFolder}${file}`, exact, channel] : [exact, channel];
1436
+ const prerelease = version.includes('-');
1437
+ let urls = ownFolder && ownFolder !== `${SDK_HOST}/web/${major}/` ? [`${ownFolder}${file}`, exact, channel] : [exact, channel];
1438
+ if (prerelease)
1439
+ urls = urls.filter((u) => u !== channel);
1423
1440
  return urls.filter((u, i) => urls.indexOf(u) === i);
1424
1441
  }
1425
1442
  function loadSdkScript(src, marker) {
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Joryio Web SDK v1.4.0-beta.5
2
+ * Joryio Web SDK v1.4.0-beta.6
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';
31
+ const SDK_VERSION = '1.4.0-beta.6';
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';
@@ -549,7 +549,7 @@ var JoryioSDK = (function (exports) {
549
549
  }
550
550
  }
551
551
 
552
- const PAGE_EDIT_POSITIONS = ['before', 'after', 'prepend', 'append'];
552
+ const PAGE_EDIT_POSITIONS = ['before', 'after', 'prepend', 'append', 'replace'];
553
553
  const PAGE_EDITS_CAPABILITY = 'page_edits';
554
554
  const PAGE_EDIT_ANTI_FLICKER_MS = 300;
555
555
  const MAX_SELECTOR_LENGTH = 500;
@@ -605,6 +605,27 @@ var JoryioSDK = (function (exports) {
605
605
  }
606
606
  const safeRestoredSrcset = (v) => typeof v === 'string' && v.split(',').every((c) => !c.trim() || safeRestoredUrl(c.trim().split(/\s+/)[0]) !== null) ? v : null;
607
607
  const HIDE_DECLARATION = 'display:none !important';
608
+ function hideElement(h) {
609
+ const display = h.style.getPropertyValue('display');
610
+ const priority = h.style.getPropertyPriority('display');
611
+ h.style.setProperty('display', 'none', 'important');
612
+ return () => (display ? h.style.setProperty('display', display, priority) : h.style.removeProperty('display'));
613
+ }
614
+ function undoServerHide(el, orig) {
615
+ var _a;
616
+ const current = el.getAttribute('style') || '';
617
+ const before = typeof orig.style === 'string' ? orig.style : null;
618
+ const base = before === null ? '' : before.trim().replace(/;+$/, '');
619
+ if (current === (base ? base + ';' : '') + HIDE_DECLARATION) {
620
+ if (before === null)
621
+ el.removeAttribute('style');
622
+ else
623
+ el.setAttribute('style', before);
624
+ }
625
+ else if (((_a = el.style) === null || _a === void 0 ? void 0 : _a.getPropertyValue('display')) === 'none') {
626
+ el.style.removeProperty('display');
627
+ }
628
+ }
608
629
  const RESTORE_ELEMENTS = new Set(['A', 'ABBR', 'B', 'BDI', 'BDO', 'BR', 'CITE', 'CODE', 'DATA', 'DEL', 'DFN', 'EM', 'I', 'IMG', 'INS', 'KBD', 'MARK', 'Q', 'S', 'SAMP', 'SMALL', 'SPAN', 'STRONG', 'SUB', 'SUP', 'TIME', 'U', 'VAR', 'WBR']);
609
630
  const RESTORE_ATTRIBUTES = new Set(['class', 'id', 'title', 'lang', 'dir', 'alt', 'width', 'height', 'datetime', 'href', 'src', 'srcset', 'rel', 'target']);
610
631
  const MAX_RESTORE_NODES = 500;
@@ -1066,19 +1087,21 @@ var JoryioSDK = (function (exports) {
1066
1087
  el.setAttribute('href', edit.value);
1067
1088
  return () => (href === null ? el.removeAttribute('href') : el.setAttribute('href', href));
1068
1089
  }
1069
- case 'hide': {
1070
- const display = h.style.getPropertyValue('display');
1071
- const priority = h.style.getPropertyPriority('display');
1072
- h.style.setProperty('display', 'none', 'important');
1073
- return () => (display ? h.style.setProperty('display', display, priority) : h.style.removeProperty('display'));
1074
- }
1090
+ case 'hide':
1091
+ return hideElement(h);
1075
1092
  case 'insert_placement': {
1076
1093
  const spot = document.createElement('div');
1077
1094
  spot.setAttribute('data-joryio-placement', edit.placementKey);
1078
1095
  spot.setAttribute('data-joryio-edit', edit.id);
1079
1096
  const where = edit.position === 'before' ? 'beforebegin' : edit.position === 'prepend' ? 'afterbegin' : edit.position === 'append' ? 'beforeend' : 'afterend';
1080
1097
  el.insertAdjacentElement(where, spot);
1081
- return () => spot.remove();
1098
+ if (edit.position !== 'replace')
1099
+ return () => spot.remove();
1100
+ const show = hideElement(h);
1101
+ return () => {
1102
+ spot.remove();
1103
+ show();
1104
+ };
1082
1105
  }
1083
1106
  default:
1084
1107
  return null;
@@ -1259,7 +1282,6 @@ var JoryioSDK = (function (exports) {
1259
1282
  }
1260
1283
  }
1261
1284
  undoServerEdit(token, edit) {
1262
- var _a;
1263
1285
  for (const el of Array.from(document.querySelectorAll(`[${SERVER_APPLIED_ATTR}]`))) {
1264
1286
  const tokens = tokensOf(el);
1265
1287
  if (!tokens.includes(token))
@@ -1268,7 +1290,7 @@ var JoryioSDK = (function (exports) {
1268
1290
  try {
1269
1291
  all = JSON.parse(el.getAttribute(SERVER_ORIG_ATTR) || '{}') || {};
1270
1292
  }
1271
- catch (_b) {
1293
+ catch (_a) {
1272
1294
  all = {};
1273
1295
  }
1274
1296
  const orig = all[token] || {};
@@ -1304,26 +1326,18 @@ var JoryioSDK = (function (exports) {
1304
1326
  el.setAttribute('href', href);
1305
1327
  }
1306
1328
  break;
1307
- case 'hide': {
1308
- const current = el.getAttribute('style') || '';
1309
- const before = typeof orig.style === 'string' ? orig.style : null;
1310
- const base = before === null ? '' : before.trim().replace(/;+$/, '');
1311
- if (current === (base ? base + ';' : '') + HIDE_DECLARATION) {
1312
- if (before === null)
1313
- el.removeAttribute('style');
1314
- else
1315
- el.setAttribute('style', before);
1316
- }
1317
- else if (((_a = el.style) === null || _a === void 0 ? void 0 : _a.getPropertyValue('display')) === 'none') {
1318
- el.style.removeProperty('display');
1319
- }
1329
+ case 'hide':
1330
+ undoServerHide(el, orig);
1331
+ break;
1332
+ case 'insert_placement':
1333
+ if (edit.position === 'replace')
1334
+ undoServerHide(el, orig);
1320
1335
  break;
1321
- }
1322
1336
  default:
1323
1337
  break;
1324
1338
  }
1325
1339
  }
1326
- catch (_c) {
1340
+ catch (_b) {
1327
1341
  }
1328
1342
  const left = tokens.filter((t) => t !== token);
1329
1343
  if (left.length)
@@ -1416,13 +1430,16 @@ var JoryioSDK = (function (exports) {
1416
1430
  return null;
1417
1431
  }
1418
1432
  const OWN_FOLDER = readOwnFolder();
1419
- function sdkHostFileUrls(file, override, ownFolder = OWN_FOLDER) {
1433
+ function sdkHostFileUrls(file, override, ownFolder = OWN_FOLDER, version = SDK_VERSION) {
1420
1434
  if (override)
1421
1435
  return [override];
1422
- const major = SDK_VERSION.split('.')[0];
1423
- const exact = `${SDK_HOST}/web/${SDK_VERSION}/${file}`;
1436
+ const major = version.split('.')[0];
1437
+ const exact = `${SDK_HOST}/web/${version}/${file}`;
1424
1438
  const channel = `${SDK_HOST}/web/${major}/${file}`;
1425
- const urls = ownFolder && ownFolder !== `${SDK_HOST}/web/${major}/` ? [`${ownFolder}${file}`, exact, channel] : [exact, channel];
1439
+ const prerelease = version.includes('-');
1440
+ let urls = ownFolder && ownFolder !== `${SDK_HOST}/web/${major}/` ? [`${ownFolder}${file}`, exact, channel] : [exact, channel];
1441
+ if (prerelease)
1442
+ urls = urls.filter((u) => u !== channel);
1426
1443
  return urls.filter((u, i) => urls.indexOf(u) === i);
1427
1444
  }
1428
1445
  function loadSdkScript(src, marker) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@joryio/web-sdk",
3
- "version": "1.4.0-beta.5",
3
+ "version": "1.4.0-beta.6",
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'; // keep in sync with package.json (sdk-version-parity.spec.ts pins it)
5
+ export const SDK_VERSION = '1.4.0-beta.6'; // 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
@@ -49,7 +49,8 @@ import { sdkIdentityHeaders } from './config';
49
49
  import { currentPageUrl, PAGE_CONTEXT_CAPABILITY, type PageContextTracker } from './page-context';
50
50
 
51
51
  export const PAGE_EDIT_OPERATIONS = ['replace_text', 'replace_image', 'replace_link', 'hide', 'insert_placement'] as const;
52
- export const PAGE_EDIT_POSITIONS = ['before', 'after', 'prepend', 'append'] as const;
52
+ /** `replace` ("Instead of it"): the element is hidden and the spot takes its place, right after it. */
53
+ export const PAGE_EDIT_POSITIONS = ['before', 'after', 'prepend', 'append', 'replace'] as const;
53
54
  export const PAGE_EDITS_CAPABILITY = 'page_edits';
54
55
  /** The longest edited elements stay hidden while the SDK waits. Never the whole body. */
55
56
  export const PAGE_EDIT_ANTI_FLICKER_MS = 300;
@@ -142,6 +143,32 @@ const safeRestoredSrcset = (v: unknown): string | null =>
142
143
 
143
144
  const HIDE_DECLARATION = 'display:none !important';
144
145
 
146
+ /** Hide one element (display:none !important); returns how to show it again as it was. */
147
+ function hideElement(h: HTMLElement): () => void {
148
+ const display = h.style.getPropertyValue('display');
149
+ const priority = h.style.getPropertyPriority('display');
150
+ h.style.setProperty('display', 'none', 'important');
151
+ return () => (display ? h.style.setProperty('display', display, priority) : h.style.removeProperty('display'));
152
+ }
153
+
154
+ /**
155
+ * Undo a hide the server wrote (`hide`, and `insert_placement` at `replace`).
156
+ * Never a style string from the marker: the original is put back only when
157
+ * the attribute is exactly it plus the server's one declaration; otherwise
158
+ * that one declaration is removed.
159
+ */
160
+ function undoServerHide(el: Element, orig: Record<string, any>): void {
161
+ const current = el.getAttribute('style') || '';
162
+ const before = typeof orig.style === 'string' ? orig.style : null;
163
+ const base = before === null ? '' : before.trim().replace(/;+$/, '');
164
+ if (current === (base ? base + ';' : '') + HIDE_DECLARATION) {
165
+ if (before === null) el.removeAttribute('style');
166
+ else el.setAttribute('style', before);
167
+ } else if ((el as HTMLElement).style?.getPropertyValue('display') === 'none') {
168
+ (el as HTMLElement).style.removeProperty('display');
169
+ }
170
+ }
171
+
145
172
  /**
146
173
  * Inline text markup a replaced element's original content may come back with.
147
174
  * Everything else is unwrapped to its text (its children are kept, checked the same way):
@@ -717,12 +744,8 @@ export class PageEditManager {
717
744
  el.setAttribute('href', edit.value!);
718
745
  return () => (href === null ? el.removeAttribute('href') : el.setAttribute('href', href));
719
746
  }
720
- case 'hide': {
721
- const display = h.style.getPropertyValue('display');
722
- const priority = h.style.getPropertyPriority('display');
723
- h.style.setProperty('display', 'none', 'important');
724
- return () => (display ? h.style.setProperty('display', display, priority) : h.style.removeProperty('display'));
725
- }
747
+ case 'hide':
748
+ return hideElement(h);
726
749
  case 'insert_placement': {
727
750
  const spot = document.createElement('div');
728
751
  spot.setAttribute('data-joryio-placement', edit.placementKey!);
@@ -730,7 +753,13 @@ export class PageEditManager {
730
753
  const where: InsertPosition =
731
754
  edit.position === 'before' ? 'beforebegin' : edit.position === 'prepend' ? 'afterbegin' : edit.position === 'append' ? 'beforeend' : 'afterend';
732
755
  el.insertAdjacentElement(where, spot);
733
- return () => spot.remove();
756
+ if (edit.position !== 'replace') return () => spot.remove();
757
+ // "Instead of it": the spot sits where the element was, the element is hidden.
758
+ const show = hideElement(h);
759
+ return () => {
760
+ spot.remove();
761
+ show();
762
+ };
734
763
  }
735
764
  default:
736
765
  return null;
@@ -955,21 +984,13 @@ export class PageEditManager {
955
984
  else el.setAttribute('href', href);
956
985
  }
957
986
  break;
958
- case 'hide': {
959
- // Never a style string from the marker: the original is put back only when the
960
- // attribute is exactly it plus the server's one declaration; otherwise that one
961
- // declaration is removed.
962
- const current = el.getAttribute('style') || '';
963
- const before = typeof orig.style === 'string' ? orig.style : null;
964
- const base = before === null ? '' : before.trim().replace(/;+$/, '');
965
- if (current === (base ? base + ';' : '') + HIDE_DECLARATION) {
966
- if (before === null) el.removeAttribute('style');
967
- else el.setAttribute('style', before);
968
- } else if ((el as HTMLElement).style?.getPropertyValue('display') === 'none') {
969
- (el as HTMLElement).style.removeProperty('display');
970
- }
987
+ case 'hide':
988
+ undoServerHide(el, orig);
989
+ break;
990
+ case 'insert_placement':
991
+ // "Instead of it" also hid the element (the spot itself is removed below).
992
+ if (edit.position === 'replace') undoServerHide(el, orig);
971
993
  break;
972
- }
973
994
  default:
974
995
  break;
975
996
  }
@@ -56,23 +56,28 @@ const OWN_FOLDER = readOwnFolder();
56
56
  /**
57
57
  * Where a lazily loaded file comes from, in order:
58
58
  * 1. the folder the core itself was loaded from (`coreFolderOf`), so a core
59
- * from `sdk.joryio.com/web/1.4.0-beta.4/` (a beta, whose SDK_VERSION
60
- * still says 1.4.0) or from the npm package's `dist/` on a CDN loads the
61
- * side files of the same build - unless that folder is the major channel
62
- * `sdk.joryio.com/web/<major>/`, which moves: then 2 goes first;
59
+ * from `sdk.joryio.com/web/1.4.0-beta.6/` or from the npm package's
60
+ * `dist/` on a CDN loads the side files of the same build - unless that
61
+ * folder is the major channel `sdk.joryio.com/web/<major>/`, which moves:
62
+ * then 2 goes first;
63
63
  * 2. the exact SDK version's folder on the SDK host (immutable, the same
64
- * build as this core);
64
+ * build as this core). A beta's SDK_VERSION is the beta's own version
65
+ * (from 1.4.0-beta.6 the release build stamps it), so this is
66
+ * `web/1.4.0-beta.6/`, the only folder a beta is published to;
65
67
  * 3. the major channel, as a fallback (a version not on the CDN, such as a
66
- * local build).
68
+ * local build) - never for a pre-release: the channel carries finals
69
+ * only, so a beta would get the previous final's side files.
67
70
  * An init option (`editorScriptUrl`, `cardsUiScriptUrl`) replaces all of
68
71
  * them, for a self-hosted SDK.
69
72
  */
70
- export function sdkHostFileUrls(file: string, override?: string, ownFolder: string | null = OWN_FOLDER): string[] {
73
+ export function sdkHostFileUrls(file: string, override?: string, ownFolder: string | null = OWN_FOLDER, version: string = SDK_VERSION): string[] {
71
74
  if (override) return [override];
72
- const major = SDK_VERSION.split('.')[0];
73
- const exact = `${SDK_HOST}/web/${SDK_VERSION}/${file}`;
75
+ const major = version.split('.')[0];
76
+ const exact = `${SDK_HOST}/web/${version}/${file}`;
74
77
  const channel = `${SDK_HOST}/web/${major}/${file}`;
75
- const urls = ownFolder && ownFolder !== `${SDK_HOST}/web/${major}/` ? [`${ownFolder}${file}`, exact, channel] : [exact, channel];
78
+ const prerelease = version.includes('-');
79
+ let urls = ownFolder && ownFolder !== `${SDK_HOST}/web/${major}/` ? [`${ownFolder}${file}`, exact, channel] : [exact, channel];
80
+ if (prerelease) urls = urls.filter((u) => u !== channel);
76
81
  return urls.filter((u, i) => urls.indexOf(u) === i);
77
82
  }
78
83
 
@@ -0,0 +1,102 @@
1
+ /**
2
+ * The editor's pure parts: the Liquid of a personalized text (the same
3
+ * `{{ user.<field> | default: "..." }}` the dashboard writes, packages/frontend
4
+ * src/lib/web-experience.ts), the slot-name slug, the friendly element kind,
5
+ * and the live-preview rendering of an edit's text.
6
+ */
7
+ import type { EditorStringKey } from './editor-strings';
8
+
9
+ const OUTPUT_TAG = /\{\{-?([\s\S]*?)-?\}\}/g;
10
+ const DEFAULT_FILTER = /\|\s*default\s*:\s*("[^"]*"|'[^']*'|[^|}]*?)\s*(?=\||$)/;
11
+ const unquote = (v: string) => v.trim().replace(/^(["'])([\s\S]*)\1$/, '$2');
12
+
13
+ /** The `{{ ... }}` outputs of a text: the expression and its `| default:` value, if any. */
14
+ export function liquidOutputs(value: string): Array<{ expr: string; fallback: string | null }> {
15
+ const out: Array<{ expr: string; fallback: string | null }> = [];
16
+ const re = new RegExp(OUTPUT_TAG.source, 'g');
17
+ let m: RegExpExecArray | null;
18
+ while ((m = re.exec(value || ''))) {
19
+ const expr = m[1].trim();
20
+ const d = DEFAULT_FILTER.exec(expr);
21
+ out.push({ expr, fallback: d ? unquote(d[1]) : null });
22
+ }
23
+ return out;
24
+ }
25
+
26
+ /** "If a value is missing": the first default of the text's variables; '' when none has one; null when it has no variable. */
27
+ export function textFallback(value: string): string | null {
28
+ const outs = liquidOutputs(value);
29
+ if (!outs.length) return null;
30
+ const withOne = outs.filter((o) => o.fallback !== null)[0];
31
+ return withOne ? (withOne.fallback as string) : '';
32
+ }
33
+
34
+ const quoted = (fallback: string) => (fallback.includes('"') ? `'${fallback.replace(/'/g, '')}'` : `"${fallback}"`);
35
+
36
+ /** Every `{{ ... }}` of the text with `fallback` as its `| default:` (an empty fallback removes it). */
37
+ export function setTextFallback(value: string, fallback: string): string {
38
+ return (value || '').replace(new RegExp(OUTPUT_TAG.source, 'g'), (_m, inner: string) => {
39
+ const expr = inner.trim().replace(new RegExp(DEFAULT_FILTER.source, 'g'), '').trim();
40
+ return fallback ? `{{ ${expr} | default: ${quoted(fallback)} }}` : `{{ ${expr} }}`;
41
+ });
42
+ }
43
+
44
+ /** The Liquid of one profile field: defaults are `user.<name>`, custom attributes `user.custom.<name>`. */
45
+ export function variableTag(name: string, custom: boolean, fallback?: string | null): string {
46
+ const path = custom ? `user.custom.${name}` : `user.${name}`;
47
+ return fallback ? `{{ ${path} | default: ${quoted(fallback)} }}` : `{{ ${path} }}`;
48
+ }
49
+
50
+ /**
51
+ * What the page shows while editing: each `{{ path ... }}` becomes the
52
+ * sample value the dashboard sent for that path (its known visitor), else
53
+ * the fallback (what an unknown visitor sees), else the field name in
54
+ * brackets so an empty spot is still visible.
55
+ */
56
+ export function previewText(value: string, sample: Record<string, string>): string {
57
+ return (value || '').replace(new RegExp(OUTPUT_TAG.source, 'g'), (_m, inner: string) => {
58
+ const expr = inner.trim();
59
+ const path = expr.split('|')[0].trim();
60
+ const d = DEFAULT_FILTER.exec(expr);
61
+ if (Object.prototype.hasOwnProperty.call(sample, path) && sample[path] !== '') return sample[path];
62
+ if (d && unquote(d[1])) return unquote(d[1]);
63
+ return `[${path.replace(/^user\.(custom\.)?/, '')}]`;
64
+ });
65
+ }
66
+
67
+ /** A slot name as a placement key: lowercase, anything else -> `_`, no leading/trailing `_`, at most 64. */
68
+ export function slugify(name: string): string {
69
+ return (name || '')
70
+ .toLowerCase()
71
+ .trim()
72
+ .replace(/[^a-z0-9]+/g, '_')
73
+ .replace(/^_+|_+$/g, '')
74
+ .slice(0, 64)
75
+ .replace(/_+$/, '');
76
+ }
77
+
78
+ /** A new edit id, the dashboard's format (`e` + 8 base-36 characters). */
79
+ export const newEditId = (): string => `e${Math.random().toString(36).slice(2, 10).padEnd(8, '0')}`;
80
+
81
+ /** The friendly name of an element, by tag (or the selector's last tag when the element is not on the page). */
82
+ export function kindKey(tagOrSelector: string, isSelector = false): EditorStringKey {
83
+ let t = (tagOrSelector || '').toLowerCase();
84
+ if (isSelector) {
85
+ const parts = t.trim().split(/[\s>+~]+/).filter(Boolean);
86
+ const m = /^[a-z][a-z0-9]*/.exec(parts[parts.length - 1] || '');
87
+ t = m ? m[0] : '';
88
+ }
89
+ if (/^h[1-6]$/.test(t)) return 'kHeading';
90
+ if (/^(p|span|strong|em|small|label|blockquote|b|i)$/.test(t)) return 'kText';
91
+ if (t === 'a') return 'kLink';
92
+ if (t === 'button') return 'kButton';
93
+ if (t === 'img' || t === 'picture') return 'kImage';
94
+ if (/^(ul|ol|li)$/.test(t)) return 'kList';
95
+ if (t === 'main') return 'kMain';
96
+ if (t === 'header') return 'kHeader';
97
+ if (t === 'footer') return 'kFooter';
98
+ if (t === 'nav') return 'kNav';
99
+ if (t === 'form') return 'kForm';
100
+ if (/^(section|div|article|aside)$/.test(t)) return 'kSection';
101
+ return 'kElement';
102
+ }