@joryio/web-sdk 1.4.0-beta.4 → 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.
Files changed (52) hide show
  1. package/CHANGELOG.md +11 -3
  2. package/dist/core/cards.d.ts +2 -1
  3. package/dist/core/cards.d.ts.map +1 -1
  4. package/dist/core/config.d.ts +1 -1
  5. package/dist/core/config.d.ts.map +1 -1
  6. package/dist/core/flags.d.ts +2 -1
  7. package/dist/core/flags.d.ts.map +1 -1
  8. package/dist/core/page-edits.d.ts +1 -1
  9. package/dist/core/page-edits.d.ts.map +1 -1
  10. package/dist/core/placements.d.ts +2 -1
  11. package/dist/core/placements.d.ts.map +1 -1
  12. package/dist/core/sdk-host-files.d.ts +1 -1
  13. package/dist/core/sdk-host-files.d.ts.map +1 -1
  14. package/dist/core/sdk.d.ts +4 -3
  15. package/dist/core/sdk.d.ts.map +1 -1
  16. package/dist/core/subscription.d.ts +6 -0
  17. package/dist/core/subscription.d.ts.map +1 -0
  18. package/dist/editor/editor-model.d.ts +13 -0
  19. package/dist/editor/editor-model.d.ts.map +1 -0
  20. package/dist/editor/editor-strings.d.ts +79 -0
  21. package/dist/editor/editor-strings.d.ts.map +1 -0
  22. package/dist/editor/editor-ui.d.ts +25 -0
  23. package/dist/editor/editor-ui.d.ts.map +1 -0
  24. package/dist/editor/visual-editor.d.ts +59 -8
  25. package/dist/editor/visual-editor.d.ts.map +1 -1
  26. package/dist/index.d.mts +10 -5
  27. package/dist/index.d.ts +1 -0
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/joryio-cards-ui.min.js +1 -1
  30. package/dist/joryio-cards-ui.min.js.map +1 -1
  31. package/dist/joryio-editor.min.js +2 -2
  32. package/dist/joryio-editor.min.js.map +1 -1
  33. package/dist/joryio-sw.js +1 -1
  34. package/dist/joryio.cjs.js +83 -46
  35. package/dist/joryio.min.js +2 -2
  36. package/dist/joryio.min.js.map +1 -1
  37. package/dist/joryio.mjs +83 -46
  38. package/dist/joryio.umd.js +83 -46
  39. package/package.json +1 -1
  40. package/src/core/cards.ts +10 -7
  41. package/src/core/config.ts +1 -1
  42. package/src/core/flags.ts +10 -4
  43. package/src/core/page-edits.ts +43 -22
  44. package/src/core/placements.ts +10 -7
  45. package/src/core/sdk-host-files.ts +15 -10
  46. package/src/core/sdk.ts +14 -9
  47. package/src/core/subscription.ts +27 -0
  48. package/src/editor/editor-model.ts +102 -0
  49. package/src/editor/editor-strings.ts +102 -0
  50. package/src/editor/editor-ui.ts +145 -0
  51. package/src/editor/visual-editor.ts +815 -105
  52. package/src/index.ts +2 -0
@@ -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
  }
@@ -32,6 +32,7 @@
32
32
  * only when `allowHtmlJsInAppMessages` is on.
33
33
  */
34
34
 
35
+ import { JoryioSubscription, joryioSubscription } from './subscription';
35
36
  import { bucketHash } from '../utils/bucket-hash';
36
37
  import { currentPageUrl, PAGE_CONTEXT_CAPABILITY, type PageContextTracker } from './page-context';
37
38
  import { Logger } from '../utils/logger';
@@ -488,13 +489,15 @@ export class PlacementManager {
488
489
  await this.fetchKeys(wanted, true);
489
490
  }
490
491
 
491
- /** Called with the placements that changed after each answer. Returns an unsubscribe. */
492
- onPlacementsUpdated(callback: PlacementsUpdatedCallback): () => void {
493
- if (typeof callback !== 'function') return () => undefined;
494
- this.listeners.add(callback);
495
- return () => {
496
- this.listeners.delete(callback);
497
- };
492
+ /** Called with the placements that changed after each answer. Returns a JoryioSubscription. */
493
+ onPlacementsUpdated(callback: PlacementsUpdatedCallback): JoryioSubscription {
494
+ if (typeof callback !== 'function') return joryioSubscription(() => undefined);
495
+ // One entry per subscription, so the same function subscribed twice is two subscriptions.
496
+ const entry: PlacementsUpdatedCallback = (placements) => callback(placements);
497
+ this.listeners.add(entry);
498
+ return joryioSubscription(() => {
499
+ this.listeners.delete(entry);
500
+ });
498
501
  }
499
502
 
500
503
  /** Mount every `[data-joryio-placement]` element on the page, now and as the page changes. */
@@ -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
 
package/src/core/sdk.ts CHANGED
@@ -23,6 +23,7 @@ import { UTMManager } from './utm';
23
23
  import { InAppMessagingManager, InAppCampaign } from './inapp';
24
24
  import { PlacementManager, Placement, PlacementHandle, InsertPlacementOptions, PlacementsUpdatedCallback, PlacementConsent } from './placements';
25
25
  import { CardManager, Card, CardFeed, CardFeedHandle, CardsUpdatedCallback, GetCardsOptions, MountCardFeedOptions } from './cards';
26
+ import { JoryioSubscription, joryioSubscription } from './subscription';
26
27
  import { LinkRouter, JoryioLinkHandler } from './links';
27
28
  import { FlagsManager, FlagsUpdatedCallback } from './flags';
28
29
  import { User } from './user';
@@ -3483,11 +3484,11 @@ export class JoryioSDK {
3483
3484
  await this.placements.refreshPlacements(placementKeys);
3484
3485
  }
3485
3486
 
3486
- /** Called with the placements whose content changed. Returns an unsubscribe function. */
3487
- onPlacementsUpdated(callback: PlacementsUpdatedCallback): () => void {
3487
+ /** Called with the placements whose content changed. Returns a JoryioSubscription: `cancel()` it to stop (calling it is the same). */
3488
+ onPlacementsUpdated(callback: PlacementsUpdatedCallback): JoryioSubscription {
3488
3489
  if (!this.isInitialized) {
3489
3490
  this.logger.error('SDK not initialized');
3490
- return () => undefined;
3491
+ return joryioSubscription(() => undefined);
3491
3492
  }
3492
3493
  return this.placements.onPlacementsUpdated(callback);
3493
3494
  }
@@ -3542,11 +3543,15 @@ export class JoryioSDK {
3542
3543
  await this.cards.refreshCards();
3543
3544
  }
3544
3545
 
3545
- /** Called with the whole feed whenever it changes. Returns an unsubscribe function. */
3546
- onCardsUpdated(callback: CardsUpdatedCallback): () => void {
3546
+ /**
3547
+ * Called with the whole feed whenever it changes - the way to keep a feed UI
3548
+ * of your own up to date. Returns a JoryioSubscription: `cancel()` it to stop
3549
+ * (calling it, `sub()`, is the same).
3550
+ */
3551
+ onCardsUpdated(callback: CardsUpdatedCallback): JoryioSubscription {
3547
3552
  if (!this.isInitialized) {
3548
3553
  this.logger.error('SDK not initialized');
3549
- return () => undefined;
3554
+ return joryioSubscription(() => undefined);
3550
3555
  }
3551
3556
  return this.cards.onCardsUpdated(callback);
3552
3557
  }
@@ -3611,11 +3616,11 @@ export class JoryioSDK {
3611
3616
  await this.flags.refreshFlags();
3612
3617
  }
3613
3618
 
3614
- /** Called with the keys whose value changed. Returns an unsubscribe function. */
3615
- onFlagsUpdated(callback: FlagsUpdatedCallback): () => void {
3619
+ /** Called with the keys whose value changed. Returns a JoryioSubscription: `cancel()` it to stop (calling it is the same). */
3620
+ onFlagsUpdated(callback: FlagsUpdatedCallback): JoryioSubscription {
3616
3621
  if (!this.isInitialized) {
3617
3622
  this.logger.error('SDK not initialized');
3618
- return () => undefined;
3623
+ return joryioSubscription(() => undefined);
3619
3624
  }
3620
3625
  return this.flags.onFlagsUpdated(callback);
3621
3626
  }
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Returned by every `on...Updated` listener - `onCardsUpdated`,
3
+ * `onPlacementsUpdated` and `onFlagsUpdated`: `cancel()` stops the updates.
4
+ * It is also callable, `sub()` being `sub.cancel()`, so code that called the
5
+ * returned function keeps working. Cancelling twice is harmless.
6
+ *
7
+ * One type with the same name and the same `cancel()` on every Joryio SDK
8
+ * (iOS, Android, React Native; Unity `JoryioSubscription.Cancel()`), pinned by
9
+ * the backend's SDK parity spec.
10
+ */
11
+ export interface JoryioSubscription {
12
+ (): void;
13
+ cancel(): void;
14
+ }
15
+
16
+ /** A JoryioSubscription that runs `stop` once. */
17
+ export function joryioSubscription(stop: () => void): JoryioSubscription {
18
+ let done = false;
19
+ const cancel = (): void => {
20
+ if (done) return;
21
+ done = true;
22
+ stop();
23
+ };
24
+ const sub = (() => cancel()) as JoryioSubscription;
25
+ sub.cancel = cancel;
26
+ return sub;
27
+ }
@@ -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
+ }
@@ -0,0 +1,102 @@
1
+ /**
2
+ * The editor's words. English is built in; the dashboard sends the same keys
3
+ * in the marketer's language with `joryio:editor-context` (`strings`, plus
4
+ * `dir` for Hebrew and Arabic), so the five dashboard locales reach the
5
+ * editor without shipping every translation to the customer's site. A key
6
+ * the dashboard does not send stays English. `{name}` placeholders are
7
+ * filled with text, never parsed as HTML.
8
+ */
9
+ export const EDITOR_STRINGS = {
10
+ title: 'Joryio editor',
11
+ variant: 'Variant {name}',
12
+ hintPoint: 'Point at anything on the page',
13
+ hintEditing: 'Editing · changes show live',
14
+ editsOne: '1 edit',
15
+ editsMany: '{n} edits',
16
+ noEdits: 'No edits yet.',
17
+ undo: 'Undo last edit',
18
+ undoOffline: 'Undo is available once the Joryio dashboard is connected',
19
+ saveReturn: 'Save & return to Joryio',
20
+ clickToEdit: 'click to edit',
21
+ helpTitle: 'Not the right box?',
22
+ helpUp: 'Select the section around it',
23
+ helpDown: 'Select something inside it',
24
+ helpClickKey: 'Click',
25
+ helpClick: 'Edit this one',
26
+ dismiss: 'Dismiss',
27
+ page: 'Page',
28
+ up: 'Select the element around it',
29
+ down: 'Select the first element inside it',
30
+ matchOne: '1 match on page',
31
+ matchMany: 'Matches {n} - all will change',
32
+ matchNone: 'Not found',
33
+ whatToDo: 'What do you want to do?',
34
+ actText: 'Change text',
35
+ actLink: 'Change link',
36
+ actImage: 'Change image',
37
+ actHide: 'Hide it',
38
+ actSlot: 'Add content slot',
39
+ noText: 'No text here',
40
+ notLink: 'Not a link',
41
+ notImage: 'Not an image',
42
+ newText: 'New text',
43
+ was: 'Was: "{value}"',
44
+ insert: 'Insert',
45
+ fallback: 'If a value is missing',
46
+ fallbackHelp: "Shown to visitors we don't know yet.",
47
+ newLink: 'New link address',
48
+ newImage: 'New image address',
49
+ urlBad: 'Enter an address starting with https:// (or http://).',
50
+ hideNote: "The {kind} is removed for people in this campaign's audience. Everyone else still sees it.",
51
+ hiddenFor: 'Hidden for this audience',
52
+ slotName: 'Slot name',
53
+ savedAs: 'Saved as',
54
+ slotHelp: 'Filled by a Placement campaign or a journey step.',
55
+ slotEmpty: 'Enter a name for the slot.',
56
+ where: 'Where',
57
+ posBefore: 'Above it',
58
+ posAfter: 'Below it',
59
+ posReplace: 'Instead of it',
60
+ posPrepend: 'Inside, at the start',
61
+ posAppend: 'Inside, at the end',
62
+ slotPreview: 'Content slot',
63
+ css: 'CSS selector',
64
+ cssHelp: 'For developers. Matches {n} on this page.',
65
+ cssBad: 'Not a selector this page can use.',
66
+ cancel: 'Cancel',
67
+ save: 'Save · {action}',
68
+ noSelector: 'This element has no stable selector. Choose the element around it (arrow up) or another one.',
69
+ kHeading: 'Heading',
70
+ kText: 'Text',
71
+ kLink: 'Link',
72
+ kButton: 'Button',
73
+ kImage: 'Image',
74
+ kList: 'List',
75
+ kSection: 'Section',
76
+ kMain: 'Main',
77
+ kHeader: 'Header',
78
+ kFooter: 'Footer',
79
+ kNav: 'Navigation',
80
+ kForm: 'Form',
81
+ kElement: 'Element',
82
+ };
83
+
84
+ export type EditorStringKey = keyof typeof EDITOR_STRINGS;
85
+ export type EditorStrings = Record<EditorStringKey, string>;
86
+
87
+ /** The built-in English, with the dashboard's translations over it (strings only, at most 500 characters each). */
88
+ export function mergeStrings(over: unknown): EditorStrings {
89
+ const out: EditorStrings = { ...EDITOR_STRINGS };
90
+ if (over && typeof over === 'object') {
91
+ for (const k of Object.keys(EDITOR_STRINGS) as EditorStringKey[]) {
92
+ const v = (over as Record<string, unknown>)[k];
93
+ if (typeof v === 'string' && v.trim() && v.length <= 500) out[k] = v;
94
+ }
95
+ }
96
+ return out;
97
+ }
98
+
99
+ /** `{name}` placeholders filled in; the result is only ever set as text. */
100
+ export function fill(text: string, vars: Record<string, string | number> = {}): string {
101
+ return text.replace(/\{(\w+)\}/g, (m, k: string) => (k in vars ? String(vars[k]) : m));
102
+ }
@@ -0,0 +1,145 @@
1
+ /**
2
+ * Building blocks of the editor's UI: an element helper that only ever sets
3
+ * attributes and text (never HTML), the icons (fixed SVG paths), and the
4
+ * stylesheet. Everything lives inside the editor's shadow root, so the
5
+ * site's CSS cannot restyle it and this CSS cannot reach the site.
6
+ *
7
+ * Colours are the Joryio product tokens of the design handoff
8
+ * (design_handoff_web_personalization, joryio-tokens.css): navy #071342,
9
+ * teal #31D6C8 / #00A99A, slot lavender #7A6CFF, light panel like the app.
10
+ */
11
+
12
+ type Kid = Node | string | null | undefined | false;
13
+
14
+ export function h<K extends keyof HTMLElementTagNameMap>(tag: K, attrs?: Record<string, string | boolean | undefined> | null, ...kids: Kid[]): HTMLElementTagNameMap[K] {
15
+ const el = document.createElement(tag);
16
+ for (const [k, v] of Object.entries(attrs || {})) {
17
+ if (v === undefined || v === false) continue;
18
+ el.setAttribute(k, v === true ? '' : v);
19
+ }
20
+ for (const kid of kids) if (kid !== null && kid !== undefined && kid !== false) el.appendChild(typeof kid === 'string' ? document.createTextNode(kid) : kid);
21
+ return el;
22
+ }
23
+
24
+ const SVG_NS = 'http://www.w3.org/2000/svg';
25
+ const ICONS = {
26
+ text: ['M4 7V5h16v2M9 19h6M12 5v14'],
27
+ link: ['M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71', 'M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71'],
28
+ image: ['M3 5h18v14H3z', 'm3 16 5-5 4 4 3-3 6 6', 'M15.5 8.5h.01'],
29
+ hide: ['M9.88 9.88a3 3 0 1 0 4.24 4.24', 'M10.73 5.08A10.4 10.4 0 0 1 12 5c7 0 10 7 10 7a13.2 13.2 0 0 1-1.67 2.68', 'M6.61 6.61A13.5 13.5 0 0 0 2 12s3 7 10 7a9.7 9.7 0 0 0 5.39-1.61', 'm2 2 20 20'],
30
+ slot: ['M3 3h18v18H3z', 'M7 9h10v6H7z'],
31
+ undo: ['M3 7v6h6', 'M21 17a9 9 0 0 0-15-6.7L3 13'],
32
+ up: ['m18 15-6-6-6 6'],
33
+ down: ['m6 9 6 6 6-6'],
34
+ cursor: ['m4 4 7.07 17 2.51-7.39L21 11.07z'],
35
+ code: ['m16 18 6-6-6-6M8 6l-6 6 6 6'],
36
+ chevron: ['m9 18 6-6-6-6'],
37
+ check: ['M20 6 9 17l-5-5'],
38
+ close: ['M18 6 6 18M6 6l12 12'],
39
+ };
40
+ export type IconName = keyof typeof ICONS;
41
+
42
+ export function icon(name: IconName, size = 15): SVGSVGElement {
43
+ const s = document.createElementNS(SVG_NS, 'svg');
44
+ for (const [k, v] of Object.entries({ width: String(size), height: String(size), viewBox: '0 0 24 24', fill: 'none', stroke: 'currentColor', 'stroke-width': '1.9', 'stroke-linecap': 'round', 'stroke-linejoin': 'round', 'aria-hidden': 'true' })) s.setAttribute(k, v);
45
+ for (const d of ICONS[name]) {
46
+ const p = document.createElementNS(SVG_NS, 'path');
47
+ p.setAttribute('d', d);
48
+ s.appendChild(p);
49
+ }
50
+ return s as SVGSVGElement;
51
+ }
52
+
53
+ /** The host element's own inline style: nothing of the site's CSS reaches inside, and the host takes no room. */
54
+ export const HOST_STYLE = 'all:initial !important;position:fixed !important;top:0 !important;left:0 !important;width:0 !important;height:0 !important;z-index:2147483647 !important;display:block !important';
55
+
56
+ /** A preview element the editor puts IN the page (a slot, a hidden-element note): its own shadow root too. */
57
+ export const PREVIEW_HOST_STYLE = 'all:initial !important;display:block !important;margin:10px 0 !important';
58
+
59
+ const FONT = 'Inter,system-ui,-apple-system,"Segoe UI",Roboto,sans-serif';
60
+ const MONO = 'ui-monospace,"SF Mono",Menlo,monospace';
61
+
62
+ export const PREVIEW_CSS = `.s,.x{font:12.5px/1.4 ${FONT};border-radius:10px;padding:14px 16px;text-align:center}.s{border:2px dashed #7A6CFF;background:#F4F2FF;color:#4C3FD1}.s b{font-weight:700}.s code{font-family:${MONO}}.s div{font-size:11.5px;color:#6B5FD9;margin-top:3px}.x{border:1.5px dashed #F04438;background:#FEF3F2;color:#B42318;text-align:start;padding:10px 12px;font-size:12px}`;
63
+
64
+ export const EDITOR_CSS = `
65
+ *{box-sizing:border-box}
66
+ .r{font:13px/1.4 ${FONT};color:#242B3A;-webkit-font-smoothing:antialiased}
67
+ button{font:inherit;color:inherit;cursor:pointer}
68
+ button:disabled{cursor:not-allowed}
69
+ button:focus-visible,input:focus-visible,textarea:focus-visible{outline:2px solid #31D6C8;outline-offset:1px}
70
+ .box{position:fixed;pointer-events:none;border:2px dashed #00A99A;background:rgba(0,169,154,.07);border-radius:4px;display:none}
71
+ .box.sel{border-style:solid;background:rgba(0,169,154,.04)}
72
+ .chip{position:absolute;bottom:100%;inset-inline-start:-2px;margin-bottom:2px;background:#00A99A;color:#fff;font-size:11px;font-weight:600;padding:3px 8px;border-radius:6px 6px 6px 0;white-space:nowrap;max-width:60vw;overflow:hidden;text-overflow:ellipsis}
73
+ .help{position:fixed;top:16px;inset-inline-end:16px;width:240px;background:#fff;border:1px solid #E5EAF2;border-radius:10px;box-shadow:0 8px 24px rgba(10,18,64,.14);padding:10px 12px}
74
+ .help h3{margin:0 0 6px;font-size:11px;font-weight:700;color:#6B7280;letter-spacing:.5px;text-transform:uppercase}
75
+ .help .row{display:flex;align-items:center;gap:8px;font-size:12px;padding:3px 0}
76
+ .kbd{min-width:38px;text-align:center;font-size:11px;font-weight:600;border:1px solid #E5EAF2;border-radius:5px;padding:1px 5px;background:#F8FAFC}
77
+ .help .x{position:absolute;top:6px;inset-inline-end:6px;border:0;background:none;color:#8990A8;padding:2px;display:grid}
78
+ .dock{position:fixed;bottom:20px;left:50%;transform:translateX(-50%);display:flex;align-items:center;gap:6px;background:#071342;color:#fff;border-radius:14px;padding:7px 7px 7px 14px;box-shadow:0 12px 32px rgba(10,18,64,.35);white-space:nowrap;max-width:calc(100vw - 24px)}
79
+ .r.open .dock{left:calc(50% - 190px)}
80
+ .r.open[dir=rtl] .dock{left:calc(50% + 190px)}
81
+ .logo{width:22px;height:22px;border-radius:6px;background:#fff;color:#071342;display:grid;place-items:center;font-weight:800;font-size:13px;flex:none}
82
+ .name{font-size:12.5px;font-weight:600;margin-inline-start:4px;overflow:hidden;text-overflow:ellipsis;max-width:200px}
83
+ .sub{font-size:12px;color:#A8AEC1;overflow:hidden;text-overflow:ellipsis;max-width:220px}
84
+ .sep{width:1px;height:22px;background:#2A3366;margin:0 8px;flex:none}
85
+ .hint{font-size:12px;color:#C9CEDD;display:inline-flex;align-items:center;gap:6px}
86
+ .hint svg{color:#31D6C8}
87
+ .db{display:inline-flex;align-items:center;gap:6px;height:32px;padding:0 10px;border-radius:8px;border:0;background:#1B245A;color:#fff;font-size:12.5px;font-weight:600}
88
+ .ib{height:32px;width:32px;border-radius:8px;border:0;background:transparent;color:#fff;display:grid;place-items:center}
89
+ .ib:disabled{color:#4A527A}
90
+ .go{height:32px;padding:0 14px;border-radius:8px;border:0;background:#31D6C8;color:#071342;font-size:12.5px;font-weight:700}
91
+ .pop{position:absolute;bottom:calc(100% + 10px);left:0;right:0;min-width:280px;max-height:50vh;overflow:auto;background:#fff;color:#242B3A;border-radius:12px;border:1px solid #E5EAF2;box-shadow:0 12px 32px rgba(10,18,64,.18);padding:6px;white-space:normal}
92
+ .pop .e{display:flex;align-items:center;gap:10px;width:100%;padding:8px 10px;border:0;background:none;border-radius:8px;font-size:12.5px;text-align:start}
93
+ .pop .e:hover{background:#F8FAFC}
94
+ .pop .empty{padding:12px;font-size:12.5px;color:#6B7280}
95
+ .num{width:20px;height:20px;border-radius:99px;background:#071342;color:#fff;font-size:11px;font-weight:700;display:grid;place-items:center;flex:none}
96
+ .panel{position:fixed;top:0;bottom:0;inset-inline-end:0;width:380px;max-width:100vw;background:#fff;border-inline-start:1px solid #E5EAF2;box-shadow:-8px 0 24px rgba(10,18,64,.06);display:flex;flex-direction:column}
97
+ .hd{padding:16px 18px 14px;border-bottom:1px solid #E5EAF2}
98
+ .crumbs{display:flex;align-items:center;flex-wrap:wrap;gap:4px;font-size:11.5px;color:#6B7280;margin-bottom:6px}
99
+ .crumbs svg{color:#A8AEC1}
100
+ .crumb{border:0;background:transparent;color:#6B7280;font-weight:500;font-size:11.5px;padding:2px 6px;border-radius:5px}
101
+ .crumb.cur{background:#E5F9F6;color:#0F766E;font-weight:600}
102
+ .nav{margin-inline-start:auto;display:flex;gap:2px}
103
+ .nav button{border:1px solid #E5EAF2;background:#fff;border-radius:6px;width:24px;height:22px;display:grid;place-items:center;color:#3A4060;padding:0}
104
+ .nav button:disabled{opacity:.4}
105
+ .tr{display:flex;align-items:center;gap:10px}
106
+ .title{font-size:17px;font-weight:700;color:#0A1240;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;min-width:0}
107
+ .pill{margin-inline-start:auto;display:inline-flex;align-items:center;gap:4px;font-size:11.5px;font-weight:600;padding:3px 8px;border-radius:999px;white-space:nowrap;flex:none}
108
+ .pill.ok{background:#E5F9F6;color:#0F766E}
109
+ .pill.many{background:#FFF7E6;color:#92400E}
110
+ .pill.none{background:#FEF3F2;color:#B42318}
111
+ .bd{padding:16px 18px;overflow:auto;flex:1}
112
+ .lbl{display:block;font-size:12.5px;font-weight:600;color:#242B3A;margin-bottom:8px}
113
+ .tiles{display:grid;grid-template-columns:1fr 1fr;gap:8px;margin-bottom:18px}
114
+ .tile{display:flex;align-items:center;gap:9px;padding:10px 11px;border-radius:10px;text-align:start;background:#fff;border:1.5px solid #E5EAF2;color:#3A4060}
115
+ .tile[aria-checked=true]{background:#E5F9F6;border-color:#00C8B7;color:#0F766E}
116
+ .tile.slot[aria-checked=true]{background:#F4F2FF;border-color:#7A6CFF;color:#4C3FD1}
117
+ .tile:disabled{opacity:.55}
118
+ .tile b{display:block;font-size:12.5px;font-weight:600;color:#0A1240}
119
+ .tile small{display:block;font-size:10.5px;color:#6B7280}
120
+ .fr{display:flex;align-items:baseline;margin-bottom:8px}
121
+ .fr .lbl{margin:0}
122
+ .was{margin-inline-start:auto;font-size:11.5px;color:#6B7280;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;max-width:55%}
123
+ textarea,input{width:100%;font:inherit;font-size:13.5px;color:#0F1424;padding:10px 12px;border-radius:10px;border:1.5px solid #E5EAF2;background:#fff;outline:none}
124
+ textarea{line-height:1.5;resize:vertical;border-color:#00C8B7}
125
+ input{height:40px;padding:0 12px}
126
+ input.slotin{border-color:#7A6CFF}
127
+ input.mono{font-family:${MONO};font-size:12px;height:36px;background:#F8FAFC;border-width:1px}
128
+ .chips{display:flex;flex-wrap:wrap;gap:6px;margin-top:8px;align-items:center}
129
+ .chips span{font-size:11.5px;color:#6B7280;margin-inline-end:2px}
130
+ .vc{font-family:${MONO};font-size:11.5px;padding:3px 8px;border-radius:6px;border:1px solid #E5EAF2;background:#F8FAFC;color:#3A4060}
131
+ .help2{font-size:11.5px;color:#6B7280;margin-top:5px}
132
+ .err{font-size:11.5px;color:#B42318;margin-top:5px}
133
+ .mt{margin-top:14px}
134
+ .note{background:#FFF7E6;border:1px solid #FCD34D;border-radius:10px;padding:10px 12px;font-size:12.5px;color:#92400E;line-height:1.5}
135
+ .key{font-family:${MONO};color:#4C3FD1;background:#F4F2FF;padding:1px 6px;border-radius:4px}
136
+ .seg{display:grid;grid-template-columns:1fr 1fr 1fr;gap:4px;background:#F3F5FA;border-radius:9px;padding:3px}
137
+ .seg button{border:0;background:transparent;border-radius:7px;padding:6px 4px;font-size:12px;color:#3A4060}
138
+ .seg button[aria-checked=true]{background:#fff;color:#0A1240;font-weight:600;box-shadow:0 1px 2px rgba(10,18,64,.08)}
139
+ .css{margin-top:20px;display:inline-flex;align-items:center;gap:6px;border:0;background:transparent;padding:0;color:#6B7280;font-size:12px}
140
+ .ft{padding:12px 18px;border-top:1px solid #E5EAF2;display:flex;gap:10px;background:#F8FAFC}
141
+ .cancel{height:38px;padding:0 14px;border-radius:10px;border:1px solid #E5EAF2;background:#fff;color:#242B3A;font-size:13px;font-weight:600}
142
+ .save{flex:1;height:38px;border-radius:10px;border:0;background:#071342;color:#fff;font-size:13px;font-weight:600;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
143
+ .save:disabled{opacity:.45}
144
+ @media (max-width:760px){.r.open .dock{display:none}.help{display:none}}
145
+ `;