@joryio/web-sdk 1.4.0-beta.5 → 1.4.0-beta.7
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/CHANGELOG.md +12 -0
- package/dist/core/config.d.ts +1 -1
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/page-edits.d.ts +1 -1
- package/dist/core/page-edits.d.ts.map +1 -1
- package/dist/core/sdk-host-files.d.ts +1 -1
- package/dist/core/sdk-host-files.d.ts.map +1 -1
- package/dist/editor/editor-model.d.ts +21 -0
- package/dist/editor/editor-model.d.ts.map +1 -0
- package/dist/editor/editor-strings.d.ts +89 -0
- package/dist/editor/editor-strings.d.ts.map +1 -0
- package/dist/editor/editor-ui.d.ts +26 -0
- package/dist/editor/editor-ui.d.ts.map +1 -0
- package/dist/editor/liquid-field.d.ts +22 -0
- package/dist/editor/liquid-field.d.ts.map +1 -0
- package/dist/editor/visual-editor.d.ts +65 -8
- package/dist/editor/visual-editor.d.ts.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/joryio-cards-ui.min.js +1 -1
- package/dist/joryio-editor.min.js +2 -2
- package/dist/joryio-editor.min.js.map +1 -1
- package/dist/joryio-sw.js +1 -1
- package/dist/joryio.cjs.js +48 -31
- package/dist/joryio.min.js +2 -2
- package/dist/joryio.min.js.map +1 -1
- package/dist/joryio.mjs +48 -31
- package/dist/joryio.umd.js +48 -31
- package/package.json +1 -1
- package/src/core/config.ts +1 -1
- package/src/core/page-edits.ts +43 -22
- package/src/core/sdk-host-files.ts +15 -10
- package/src/editor/editor-model.ts +153 -0
- package/src/editor/editor-strings.ts +112 -0
- package/src/editor/editor-ui.ts +173 -0
- package/src/editor/liquid-field.ts +301 -0
- package/src/editor/visual-editor.ts +1032 -105
package/dist/joryio.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Joryio Web SDK v1.4.0-beta.
|
|
2
|
+
* Joryio Web SDK v1.4.0-beta.7
|
|
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.7';
|
|
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
|
-
|
|
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
|
-
|
|
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 (
|
|
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
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
if (
|
|
1309
|
-
|
|
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 (
|
|
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 =
|
|
1420
|
-
const exact = `${SDK_HOST}/web/${
|
|
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
|
|
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) {
|
package/dist/joryio.umd.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Joryio Web SDK v1.4.0-beta.
|
|
2
|
+
* Joryio Web SDK v1.4.0-beta.7
|
|
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.7';
|
|
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
|
-
|
|
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
|
-
|
|
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 (
|
|
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
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
if (
|
|
1312
|
-
|
|
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 (
|
|
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 =
|
|
1423
|
-
const exact = `${SDK_HOST}/web/${
|
|
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
|
|
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
package/src/core/config.ts
CHANGED
|
@@ -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.7'; // 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
|
package/src/core/page-edits.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
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.
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
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 =
|
|
73
|
-
const exact = `${SDK_HOST}/web/${
|
|
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
|
|
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,153 @@
|
|
|
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
|
+
/**
|
|
14
|
+
* A fallback as a Liquid string literal. Liquid has no escape inside a
|
|
15
|
+
* literal, so: double quotes; single quotes when the text has a `"`; with
|
|
16
|
+
* both, single quotes and each `'` as the typographic apostrophe (U+2019),
|
|
17
|
+
* so nothing the marketer typed disappears.
|
|
18
|
+
*/
|
|
19
|
+
export const quoted = (fallback: string): string =>
|
|
20
|
+
!fallback.includes('"') ? `"${fallback}"` : !fallback.includes("'") ? `'${fallback}'` : `'${fallback.replace(/'/g, '\u2019')}'`;
|
|
21
|
+
|
|
22
|
+
/** A fallback is plain text: no Liquid in it, one line, at most 200 characters. */
|
|
23
|
+
export const isPlainFallback = (v: string): boolean => v.length <= 200 && !/\{[{%]|[}%]\}|[\r\n]/.test(v);
|
|
24
|
+
|
|
25
|
+
/** The `| default:` value of ONE variable's Liquid (`{{ user.x | default: "y" }}`), or null. */
|
|
26
|
+
export function varFallback(src: string): string | null {
|
|
27
|
+
const m = /^\{\{-?([\s\S]*?)-?\}\}$/.exec((src || '').trim());
|
|
28
|
+
const d = m && DEFAULT_FILTER.exec(m[1].trim());
|
|
29
|
+
return d ? unquote(d[1]) : null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** ONE variable's Liquid with `fallback` as its own `| default:` (an empty one removes it); its path is kept. */
|
|
33
|
+
export function setVarFallback(src: string, fallback: string): string {
|
|
34
|
+
const m = /^\{\{-?\s*([A-Za-z_][A-Za-z0-9_.]*)/.exec((src || '').trim());
|
|
35
|
+
return m ? pathTag(m[1], fallback.trim() || null) : src;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** The Liquid of one profile field: defaults are `user.<name>`, custom attributes `user.custom.<name>`. */
|
|
39
|
+
export const variableTag = (name: string, custom: boolean, fallback?: string | null): string => pathTag(custom ? `user.custom.${name}` : `user.${name}`, fallback);
|
|
40
|
+
|
|
41
|
+
/** The Liquid of one variable by its path (`user.firstName`, the catalog's `key`). */
|
|
42
|
+
export const pathTag = (path: string, fallback?: string | null): string => (fallback ? `{{ ${path} | default: ${quoted(fallback)} }}` : `{{ ${path} }}`);
|
|
43
|
+
|
|
44
|
+
/** A Liquid variable path: dotted identifiers (`user.custom.city`). */
|
|
45
|
+
export const VAR_PATH = /^[A-Za-z_][A-Za-z0-9_]{0,63}(\.[A-Za-z_][A-Za-z0-9_]{0,63}){0,4}$/;
|
|
46
|
+
|
|
47
|
+
/** A variable the editor shows as a placeholder pill: its field name, and (in the text field) its exact Liquid. */
|
|
48
|
+
export interface LiquidVar {
|
|
49
|
+
name: string;
|
|
50
|
+
path: string;
|
|
51
|
+
src: string;
|
|
52
|
+
}
|
|
53
|
+
export type LiquidPart = string | LiquidVar;
|
|
54
|
+
|
|
55
|
+
const pathName = (path: string) => path.replace(/^user\.(custom\.)?/, '');
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* What the page shows while editing: each `{{ path ... }}` becomes the
|
|
59
|
+
* sample value the dashboard sent for that path (its known visitor), else
|
|
60
|
+
* the fallback (what an unknown visitor sees), else a placeholder pill with
|
|
61
|
+
* the field name (`{ name }`), so an empty spot is still visible and never
|
|
62
|
+
* mistaken for page text.
|
|
63
|
+
*/
|
|
64
|
+
export function previewParts(value: string, sample: Record<string, string>): LiquidPart[] {
|
|
65
|
+
const out: LiquidPart[] = [];
|
|
66
|
+
const re = new RegExp(OUTPUT_TAG.source, 'g');
|
|
67
|
+
let last = 0;
|
|
68
|
+
let m: RegExpExecArray | null;
|
|
69
|
+
const text = (s: string) => {
|
|
70
|
+
if (!s) return;
|
|
71
|
+
if (typeof out[out.length - 1] === 'string') out[out.length - 1] += s;
|
|
72
|
+
else out.push(s);
|
|
73
|
+
};
|
|
74
|
+
value = value || '';
|
|
75
|
+
while ((m = re.exec(value))) {
|
|
76
|
+
text(value.slice(last, m.index));
|
|
77
|
+
last = re.lastIndex;
|
|
78
|
+
const expr = m[1].trim();
|
|
79
|
+
const path = expr.split('|')[0].trim();
|
|
80
|
+
const d = DEFAULT_FILTER.exec(expr);
|
|
81
|
+
if (Object.prototype.hasOwnProperty.call(sample, path) && sample[path] !== '') text(sample[path]);
|
|
82
|
+
else if (d && unquote(d[1])) text(unquote(d[1]));
|
|
83
|
+
else out.push({ name: pathName(path), path, src: m[0] });
|
|
84
|
+
}
|
|
85
|
+
text(value.slice(last));
|
|
86
|
+
return out;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** previewParts as plain text (a pill as `[name]`). */
|
|
90
|
+
export const previewText = (value: string, sample: Record<string, string>): string => previewParts(value, sample).map((p) => (typeof p === 'string' ? p : `[${p.name}]`)).join('');
|
|
91
|
+
|
|
92
|
+
/** A variable path with at most a quoted `| default:` - what the text field shows as a pill. */
|
|
93
|
+
const SIMPLE_VAR = /^\{\{-?\s*([A-Za-z_][A-Za-z0-9_]*(?:\.[A-Za-z_][A-Za-z0-9_]*)*)\s*(?:\|\s*default\s*:\s*(?:"[^"]*"|'[^']*')\s*)?-?\}\}$/;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* The text field's view of a text: plain parts and variables (each with its
|
|
97
|
+
* exact Liquid, so the text round-trips byte for byte), or null when it holds
|
|
98
|
+
* Liquid a pill cannot show (a tag like `{% if %}`, a filter other than
|
|
99
|
+
* `default`, a stray brace pair) - the field then stays raw text.
|
|
100
|
+
*/
|
|
101
|
+
export function liquidParts(value: string): LiquidPart[] | null {
|
|
102
|
+
const out: LiquidPart[] = [];
|
|
103
|
+
const re = new RegExp(OUTPUT_TAG.source, 'g');
|
|
104
|
+
let last = 0;
|
|
105
|
+
let m: RegExpExecArray | null;
|
|
106
|
+
value = value || '';
|
|
107
|
+
while ((m = re.exec(value))) {
|
|
108
|
+
const v = SIMPLE_VAR.exec(m[0]);
|
|
109
|
+
if (!v) return null;
|
|
110
|
+
if (m.index > last) out.push(value.slice(last, m.index));
|
|
111
|
+
out.push({ name: pathName(v[1]), path: v[1], src: m[0] });
|
|
112
|
+
last = re.lastIndex;
|
|
113
|
+
}
|
|
114
|
+
if (last < value.length) out.push(value.slice(last));
|
|
115
|
+
return out.some((p) => typeof p === 'string' && /\{[{%]|[}%]\}/.test(p)) ? null : out;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** A slot name as a placement key: lowercase, anything else -> `_`, no leading/trailing `_`, at most 64. */
|
|
119
|
+
export function slugify(name: string): string {
|
|
120
|
+
return (name || '')
|
|
121
|
+
.toLowerCase()
|
|
122
|
+
.trim()
|
|
123
|
+
.replace(/[^a-z0-9]+/g, '_')
|
|
124
|
+
.replace(/^_+|_+$/g, '')
|
|
125
|
+
.slice(0, 64)
|
|
126
|
+
.replace(/_+$/, '');
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** A new edit id, the dashboard's format (`e` + 8 base-36 characters). */
|
|
130
|
+
export const newEditId = (): string => `e${Math.random().toString(36).slice(2, 10).padEnd(8, '0')}`;
|
|
131
|
+
|
|
132
|
+
/** The friendly name of an element, by tag (or the selector's last tag when the element is not on the page). */
|
|
133
|
+
export function kindKey(tagOrSelector: string, isSelector = false): EditorStringKey {
|
|
134
|
+
let t = (tagOrSelector || '').toLowerCase();
|
|
135
|
+
if (isSelector) {
|
|
136
|
+
const parts = t.trim().split(/[\s>+~]+/).filter(Boolean);
|
|
137
|
+
const m = /^[a-z][a-z0-9]*/.exec(parts[parts.length - 1] || '');
|
|
138
|
+
t = m ? m[0] : '';
|
|
139
|
+
}
|
|
140
|
+
if (/^h[1-6]$/.test(t)) return 'kHeading';
|
|
141
|
+
if (/^(p|span|strong|em|small|label|blockquote|b|i)$/.test(t)) return 'kText';
|
|
142
|
+
if (t === 'a') return 'kLink';
|
|
143
|
+
if (t === 'button') return 'kButton';
|
|
144
|
+
if (t === 'img' || t === 'picture') return 'kImage';
|
|
145
|
+
if (/^(ul|ol|li)$/.test(t)) return 'kList';
|
|
146
|
+
if (t === 'main') return 'kMain';
|
|
147
|
+
if (t === 'header') return 'kHeader';
|
|
148
|
+
if (t === 'footer') return 'kFooter';
|
|
149
|
+
if (t === 'nav') return 'kNav';
|
|
150
|
+
if (t === 'form') return 'kForm';
|
|
151
|
+
if (/^(section|div|article|aside)$/.test(t)) return 'kSection';
|
|
152
|
+
return 'kElement';
|
|
153
|
+
}
|