@joryio/web-sdk 1.4.0-beta.7 → 1.4.0-beta.9
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 +10 -0
- package/dist/core/config.d.ts +1 -1
- package/dist/core/editor-gate.d.ts +2 -0
- package/dist/core/editor-gate.d.ts.map +1 -1
- package/dist/core/page-context.d.ts +13 -0
- package/dist/core/page-context.d.ts.map +1 -1
- package/dist/core/page-edits.d.ts +26 -0
- package/dist/core/page-edits.d.ts.map +1 -1
- package/dist/core/placements.d.ts +34 -0
- package/dist/core/placements.d.ts.map +1 -1
- package/dist/core/sdk.d.ts +5 -0
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/show-when.d.ts +42 -0
- package/dist/core/show-when.d.ts.map +1 -0
- package/dist/editor/editor-strings.d.ts +11 -0
- package/dist/editor/editor-strings.d.ts.map +1 -1
- package/dist/editor/editor-ui.d.ts +4 -1
- package/dist/editor/editor-ui.d.ts.map +1 -1
- package/dist/editor/liquid-field.d.ts +1 -0
- package/dist/editor/liquid-field.d.ts.map +1 -1
- package/dist/editor/visual-editor.d.ts +25 -2
- package/dist/editor/visual-editor.d.ts.map +1 -1
- package/dist/index.d.mts +25 -3
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/joryio-cards-ui.min.js +1 -1
- package/dist/joryio-cards-ui.min.js.map +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 +631 -26
- package/dist/joryio.min.js +2 -2
- package/dist/joryio.min.js.map +1 -1
- package/dist/joryio.mjs +631 -27
- package/dist/joryio.umd.js +631 -26
- package/package.json +1 -1
- package/src/core/config.ts +1 -1
- package/src/core/editor-gate.ts +21 -0
- package/src/core/page-context.ts +84 -1
- package/src/core/page-edits.ts +149 -5
- package/src/core/placements.ts +373 -6
- package/src/core/sdk.ts +79 -1
- package/src/core/show-when.ts +159 -0
- package/src/editor/editor-strings.ts +11 -0
- package/src/editor/editor-ui.ts +15 -1
- package/src/editor/liquid-field.ts +17 -2
- package/src/editor/visual-editor.ts +350 -75
- package/src/index.ts +4 -0
package/src/core/sdk.ts
CHANGED
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { PageEditManager } from './page-edits';
|
|
7
|
-
import { EditorGate, editorRequested } from './editor-gate';
|
|
7
|
+
import { EditorGate, editorFrame, editorRequested } from './editor-gate';
|
|
8
8
|
import { PageContextTracker } from './page-context';
|
|
9
|
+
import { ShowWhenMoments, type RecheckEvent } from './show-when';
|
|
9
10
|
import { InitConfig, ResolvedConfig, resolveConfig, SDK_VERSION } from './config';
|
|
10
11
|
import { StorageManager } from './storage';
|
|
11
12
|
import { SessionManager, SESSION_ID_KEY } from './session';
|
|
@@ -269,6 +270,10 @@ export class JoryioSDK {
|
|
|
269
270
|
// Created with the instance, so setLinkHandler works before init().
|
|
270
271
|
private links = new LinkRouter((error) => this.logger?.error('Your link handler threw; the link opens as without one:', error));
|
|
271
272
|
private pageContext!: PageContextTracker;
|
|
273
|
+
/** Show when (D465): this page view's moments and this visit's event names, for placements and page edits. */
|
|
274
|
+
private showWhen!: ShowWhenMoments;
|
|
275
|
+
/** Show when re-checks waiting for their event to reach the server (see recheckShowWhen). */
|
|
276
|
+
private pendingRechecks: Array<{ event: RecheckEvent; keys: string[]; edits: boolean; who: string; at: number }> = [];
|
|
272
277
|
private pageEdits!: PageEditManager;
|
|
273
278
|
private editor: EditorGate | null = null;
|
|
274
279
|
/** Feature flags + remote config (flags.ts). */
|
|
@@ -349,6 +354,9 @@ export class JoryioSDK {
|
|
|
349
354
|
// eslint-disable-next-line no-console -- the logger is silent by default and this is the reason nothing works
|
|
350
355
|
console.error(`[Joryio] SDK not started: ${keyProblem}. Calls on this instance are ignored.`);
|
|
351
356
|
this.disabled = true;
|
|
357
|
+
} else if (editorFrame()) {
|
|
358
|
+
// The page editor's Mobile view (a frame in the editor tab): a preview, not a visit - nothing is sent or applied.
|
|
359
|
+
this.disabled = true;
|
|
352
360
|
}
|
|
353
361
|
|
|
354
362
|
// Resolve config with defaults
|
|
@@ -555,6 +563,11 @@ export class JoryioSDK {
|
|
|
555
563
|
// UTM page rules (D444 Phase 4 follow-up): the UTM this SDK already recorded, when capture is on.
|
|
556
564
|
this.pageContext.setUtmSource(() => (this.config.captureUTM && this.utm ? this.utm.getUTMData() : null));
|
|
557
565
|
this.inapp.setPageContext(this.pageContext);
|
|
566
|
+
this.showWhen = new ShowWhenMoments(this.pageContext, () => this.session.getSessionId(), this.config.sdkKey);
|
|
567
|
+
// A re-check belongs to its page view: a route change drops the waiting ones.
|
|
568
|
+
this.pageContext.onSignal((s) => {
|
|
569
|
+
if (s.type === 'page_change') this.pendingRechecks = [];
|
|
570
|
+
});
|
|
558
571
|
|
|
559
572
|
this.placements = new PlacementManager(
|
|
560
573
|
this.config.apiEndpoint,
|
|
@@ -579,6 +592,7 @@ export class JoryioSDK {
|
|
|
579
592
|
this.network,
|
|
580
593
|
);
|
|
581
594
|
this.placements.setPageContext(this.pageContext);
|
|
595
|
+
this.placements.setShowWhen(this.showWhen);
|
|
582
596
|
|
|
583
597
|
// Page edits (D444 Phase 4): selector edits from page-edit campaigns.
|
|
584
598
|
this.pageEdits = new PageEditManager(
|
|
@@ -595,6 +609,7 @@ export class JoryioSDK {
|
|
|
595
609
|
this.network,
|
|
596
610
|
);
|
|
597
611
|
this.pageEdits.setPageContext(this.pageContext);
|
|
612
|
+
this.pageEdits.setShowWhen(this.showWhen);
|
|
598
613
|
|
|
599
614
|
this.cards = new CardManager(
|
|
600
615
|
this.config.apiEndpoint,
|
|
@@ -678,6 +693,8 @@ export class JoryioSDK {
|
|
|
678
693
|
try {
|
|
679
694
|
return await this.flushEvents(events, identify);
|
|
680
695
|
} finally {
|
|
696
|
+
// A batch settled: re-checks whose event has now left the queue go (after the queue's own bookkeeping).
|
|
697
|
+
if (this.pendingRechecks.length) setTimeout(() => this.runRechecks(), 0);
|
|
681
698
|
// A logged-out user's token lives as long as their leftovers (D-a).
|
|
682
699
|
this.scheduleRetiredTokenPrune();
|
|
683
700
|
}
|
|
@@ -1078,6 +1095,7 @@ export class JoryioSDK {
|
|
|
1078
1095
|
this.network.switchUser(userId);
|
|
1079
1096
|
this.identity.adopt(anonymousId, userId);
|
|
1080
1097
|
this.placements.invalidate();
|
|
1098
|
+
this.pendingRechecks = []; // never run a re-check queued for another person or consent
|
|
1081
1099
|
// Another person: the anonymous visitor's card state goes too.
|
|
1082
1100
|
this.cards.invalidate(true);
|
|
1083
1101
|
this.pageEdits?.invalidate();
|
|
@@ -1472,6 +1490,7 @@ export class JoryioSDK {
|
|
|
1472
1490
|
// Placement answers too: a grant turns generic answers personal, a
|
|
1473
1491
|
// refusal turns personal answers generic.
|
|
1474
1492
|
this.placements?.invalidate();
|
|
1493
|
+
this.pendingRechecks = []; // never run a re-check queued for another person or consent
|
|
1475
1494
|
// The card feed is asked for only with consent: a grant fetches it, a refusal empties it.
|
|
1476
1495
|
this.cards?.invalidate(false);
|
|
1477
1496
|
// Consent changed: the stored site settings go too (as every per-workspace store).
|
|
@@ -1872,6 +1891,9 @@ export class JoryioSDK {
|
|
|
1872
1891
|
try {
|
|
1873
1892
|
this.inapp?.onEventTracked(eventName, eventProperties);
|
|
1874
1893
|
this.placements?.onEventTracked(eventName, eventProperties);
|
|
1894
|
+
// Show when: content held for this event shows now, and the answers that depend on it are asked again.
|
|
1895
|
+
this.showWhen?.noteEvent(eventName);
|
|
1896
|
+
this.recheckShowWhen(eventName, processedEvent);
|
|
1875
1897
|
} catch (error) {
|
|
1876
1898
|
this.logger.error('In-app trigger evaluation failed:', error);
|
|
1877
1899
|
}
|
|
@@ -1898,6 +1920,57 @@ export class JoryioSDK {
|
|
|
1898
1920
|
}
|
|
1899
1921
|
}
|
|
1900
1922
|
|
|
1923
|
+
/**
|
|
1924
|
+
* Show when (D465): `eventName` was tracked and an answer depends on it
|
|
1925
|
+
* (`recheckOn`, or held content waiting on it). The re-check never reaches
|
|
1926
|
+
* the server before the event: the queue is flushed (after any flush in
|
|
1927
|
+
* progress), and those placement keys and this page's edits are asked again
|
|
1928
|
+
* only once the event has left the queue - delivered - past the 30 s
|
|
1929
|
+
* placement limit, once per (key or page, event) per page view. A failed
|
|
1930
|
+
* flush keeps it waiting; it runs once, after the next flush that delivers
|
|
1931
|
+
* the event. The request carries the event (`recheckEvent`), so the server
|
|
1932
|
+
* counts it even before its own write of the event lands.
|
|
1933
|
+
*/
|
|
1934
|
+
private recheckShowWhen(eventName: string, queued: QueuedEvent): void {
|
|
1935
|
+
const keys = this.placements?.recheckKeysFor(eventName) || [];
|
|
1936
|
+
const edits = !!this.pageEdits?.claimRecheck(eventName);
|
|
1937
|
+
if (!keys.length && !edits) return;
|
|
1938
|
+
const event: RecheckEvent = { name: eventName, eventId: queued.eventId, properties: { ...(queued.properties || {}) } };
|
|
1939
|
+
// Stamped with who it is for (identity, consent, page); at most 20, the oldest dropped.
|
|
1940
|
+
this.pendingRechecks.push({ event, keys, edits, who: this.recheckOwner(), at: Date.now() });
|
|
1941
|
+
if (this.pendingRechecks.length > 20) this.pendingRechecks.shift();
|
|
1942
|
+
void this.queue
|
|
1943
|
+
.flush(false, true)
|
|
1944
|
+
.catch(() => undefined)
|
|
1945
|
+
.then(() => this.runRechecks());
|
|
1946
|
+
}
|
|
1947
|
+
|
|
1948
|
+
/** Who a re-check is for: the visitor, the consent and the page it was queued on. */
|
|
1949
|
+
private recheckOwner(): string {
|
|
1950
|
+
return [this.identity.getUserId() || '', this.identity.getAnonymousId(), this.placementConsent() || '', this.pageContext?.current().url || ''].join('\u0000');
|
|
1951
|
+
}
|
|
1952
|
+
|
|
1953
|
+
/**
|
|
1954
|
+
* Run the waiting re-checks whose event is no longer queued or in flight.
|
|
1955
|
+
* One queued for another person, consent or page, or older than 60 s, is
|
|
1956
|
+
* dropped - its event (and properties) never ride on someone else's request.
|
|
1957
|
+
*/
|
|
1958
|
+
private runRechecks(): void {
|
|
1959
|
+
if (!this.pendingRechecks.length || !this.isInitialized) return;
|
|
1960
|
+
const owner = this.recheckOwner();
|
|
1961
|
+
const now = Date.now();
|
|
1962
|
+
this.pendingRechecks = this.pendingRechecks.filter((r) => r.who === owner && now - r.at <= 60_000);
|
|
1963
|
+
const waiting = new Set([...this.queue.getQueuedEvents(), ...this.queue.getInflightEvents()].map((e) => e.eventId));
|
|
1964
|
+
const due = this.pendingRechecks.filter((r) => !waiting.has(r.event.eventId));
|
|
1965
|
+
if (!due.length) return;
|
|
1966
|
+
this.pendingRechecks = this.pendingRechecks.filter((r) => waiting.has(r.event.eventId));
|
|
1967
|
+
if (!this.canSend()) return;
|
|
1968
|
+
for (const r of due) {
|
|
1969
|
+
if (r.keys.length) void this.placements.recheck(r.keys, r.event);
|
|
1970
|
+
if (r.edits) this.pageEdits.recheck(r.event);
|
|
1971
|
+
}
|
|
1972
|
+
}
|
|
1973
|
+
|
|
1901
1974
|
/**
|
|
1902
1975
|
* Identify a user.
|
|
1903
1976
|
*
|
|
@@ -1951,6 +2024,7 @@ export class JoryioSDK {
|
|
|
1951
2024
|
if (previousUserId !== userId) {
|
|
1952
2025
|
this.inapp.invalidate();
|
|
1953
2026
|
this.placements.invalidate();
|
|
2027
|
+
this.pendingRechecks = []; // never run a re-check queued for another person or consent
|
|
1954
2028
|
this.cards.invalidate(true);
|
|
1955
2029
|
this.pageEdits?.invalidate();
|
|
1956
2030
|
this.flags.onIdentityChanged();
|
|
@@ -2518,6 +2592,7 @@ export class JoryioSDK {
|
|
|
2518
2592
|
this.flags.onIdentityChanged();
|
|
2519
2593
|
this.network.setCurrentUserId(this.identity.getUserId());
|
|
2520
2594
|
this.placements.invalidate();
|
|
2595
|
+
this.pendingRechecks = []; // never run a re-check queued for another person or consent
|
|
2521
2596
|
this.cards.invalidate(true);
|
|
2522
2597
|
// reset / resetTo: the stored site settings go too (identify keeps them - the same for every visitor).
|
|
2523
2598
|
this.pageEdits?.invalidate({ siteSettings: true });
|
|
@@ -2630,6 +2705,7 @@ export class JoryioSDK {
|
|
|
2630
2705
|
this.flags.onIdentityChanged();
|
|
2631
2706
|
this.network.setCurrentUserId(null);
|
|
2632
2707
|
this.placements.invalidate();
|
|
2708
|
+
this.pendingRechecks = []; // never run a re-check queued for another person or consent
|
|
2633
2709
|
this.cards?.invalidate(true);
|
|
2634
2710
|
this.pageEdits?.invalidate({ siteSettings: true });
|
|
2635
2711
|
this.utm.reset();
|
|
@@ -3690,6 +3766,8 @@ export class JoryioSDK {
|
|
|
3690
3766
|
this.cards.destroy();
|
|
3691
3767
|
this.pageEdits?.destroy();
|
|
3692
3768
|
this.editor?.stop();
|
|
3769
|
+
this.showWhen?.destroy();
|
|
3770
|
+
this.pendingRechecks = [];
|
|
3693
3771
|
this.pageContext?.destroy();
|
|
3694
3772
|
this.flags.destroy();
|
|
3695
3773
|
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* "Show when" (BACKLOG D465): the moment a Placement or Web personalization
|
|
3
|
+
* campaign's content is revealed in a page view. The content is fetched as
|
|
4
|
+
* before and HELD; it is revealed at its moment and then stays for that page
|
|
5
|
+
* view. A route change (SPA) starts the moment again.
|
|
6
|
+
*
|
|
7
|
+
* { kind: 'load' } the page loads (default; also: no field)
|
|
8
|
+
* { kind: 'seconds', seconds: 1..3600 } visible seconds on the page (like `time_on_page`)
|
|
9
|
+
* { kind: 'scroll', percent: 1..100 } share of the page scrolled (like `scroll_depth`)
|
|
10
|
+
* { kind: 'exit' } exit intent (like `exit_intent`): the pointer leaves through the top; touch: a fast scroll up
|
|
11
|
+
* { kind: 'event', event: '<name>' } the event was tracked in this visit (SDK session)
|
|
12
|
+
*
|
|
13
|
+
* The page moments are the PageContextTracker's own progress (the same clock
|
|
14
|
+
* the overlay page triggers use, reset on a route change); the visit's event
|
|
15
|
+
* names are kept here, in memory and sessionStorage, per SDK session id.
|
|
16
|
+
*
|
|
17
|
+
* Names and wire values are the backend's (common/show-when.ts) and the same
|
|
18
|
+
* on every Joryio SDK (pinned by sdk-show-when-parity.spec.ts).
|
|
19
|
+
*/
|
|
20
|
+
import { bucketHash } from '../utils/bucket-hash';
|
|
21
|
+
import type { PageContextTracker } from './page-context';
|
|
22
|
+
|
|
23
|
+
export const SHOW_WHEN_KINDS = ['load', 'seconds', 'scroll', 'exit', 'event'] as const;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The just-tracked event a show-when re-check request carries
|
|
27
|
+
* (`recheckEvent`): the server counts it as arrived in the audience
|
|
28
|
+
* conditions, so the re-check never races the event's own write.
|
|
29
|
+
*/
|
|
30
|
+
export interface RecheckEvent {
|
|
31
|
+
name: string;
|
|
32
|
+
eventId: string;
|
|
33
|
+
properties: Record<string, unknown>;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export type ShowWhenKind = (typeof SHOW_WHEN_KINDS)[number];
|
|
37
|
+
export type ShowWhen =
|
|
38
|
+
| { kind: 'load' }
|
|
39
|
+
| { kind: 'seconds'; seconds: number }
|
|
40
|
+
| { kind: 'scroll'; percent: number }
|
|
41
|
+
| { kind: 'exit' }
|
|
42
|
+
| { kind: 'event'; event: string };
|
|
43
|
+
|
|
44
|
+
const intIn = (v: unknown, min: number, max: number): v is number => typeof v === 'number' && Number.isInteger(v) && v >= min && v <= max;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The served value as this SDK honours it: absent = `load`; null = unknown
|
|
48
|
+
* kind or invalid value - such content is never shown (never "on load").
|
|
49
|
+
*/
|
|
50
|
+
export function parseShowWhen(raw: unknown): ShowWhen | null {
|
|
51
|
+
if (raw === undefined || raw === null) return { kind: 'load' };
|
|
52
|
+
if (typeof raw !== 'object') return null;
|
|
53
|
+
const o = raw as Record<string, unknown>;
|
|
54
|
+
switch (o.kind) {
|
|
55
|
+
case 'load':
|
|
56
|
+
case 'exit':
|
|
57
|
+
return { kind: o.kind };
|
|
58
|
+
case 'seconds':
|
|
59
|
+
return intIn(o.seconds, 1, 3600) ? { kind: 'seconds', seconds: o.seconds } : null;
|
|
60
|
+
case 'scroll':
|
|
61
|
+
return intIn(o.percent, 1, 100) ? { kind: 'scroll', percent: o.percent } : null;
|
|
62
|
+
case 'event': {
|
|
63
|
+
const e = typeof o.event === 'string' ? o.event.trim() : '';
|
|
64
|
+
return e && e.length <= 255 ? { kind: 'event', event: e } : null;
|
|
65
|
+
}
|
|
66
|
+
default:
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** True for content that waits for a moment (valid or not): it is held, or never shown. */
|
|
72
|
+
export const isDeferred = (raw: unknown): boolean => parseShowWhen(raw)?.kind !== 'load';
|
|
73
|
+
|
|
74
|
+
/** Event names that make the SDK ask again (the answer's `recheckOn`): strings of 1-255 characters. */
|
|
75
|
+
export function eventNames(raw: unknown, max = 50): string[] {
|
|
76
|
+
return Array.isArray(raw) ? raw.filter((e): e is string => typeof e === 'string' && e.length > 0 && e.length <= 255).slice(0, max) : [];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const MAX_EVENTS = 200;
|
|
80
|
+
|
|
81
|
+
/** The moments of this page view and the event names of this visit. One per SDK. */
|
|
82
|
+
export class ShowWhenMoments {
|
|
83
|
+
private events = new Set<string>();
|
|
84
|
+
private sid: string | null | undefined = undefined;
|
|
85
|
+
private listeners = new Set<() => void>();
|
|
86
|
+
private off: (() => void) | null;
|
|
87
|
+
private readonly store: string;
|
|
88
|
+
|
|
89
|
+
constructor(
|
|
90
|
+
private page: Pick<PageContextTracker, 'progress' | 'onSignal'> | null,
|
|
91
|
+
private sessionId: () => string | null,
|
|
92
|
+
sdkKey: string,
|
|
93
|
+
) {
|
|
94
|
+
this.store = `jry_show_when_${bucketHash(sdkKey).toString(36)}`;
|
|
95
|
+
// Every page signal (a second of visible time, a deeper scroll, exit intent, a route change) may bring a moment.
|
|
96
|
+
this.off = page ? page.onSignal(() => this.emit()) : null;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Has this moment come in the current page view? `load` always; null (invalid) never. */
|
|
100
|
+
met(sw: ShowWhen | null): boolean {
|
|
101
|
+
if (!sw) return false;
|
|
102
|
+
if (sw.kind === 'load') return true;
|
|
103
|
+
if (sw.kind === 'event') return this.visitEvents().has(sw.event);
|
|
104
|
+
const p = this.page?.progress();
|
|
105
|
+
if (!p) return false;
|
|
106
|
+
return sw.kind === 'seconds' ? p.seconds >= sw.seconds : sw.kind === 'scroll' ? p.scrollPercent >= sw.percent : p.exitIntent;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** An event was tracked: remember its name for this visit and re-check every held content. */
|
|
110
|
+
noteEvent(name: string): void {
|
|
111
|
+
const events = this.visitEvents();
|
|
112
|
+
if (!events.has(name) && events.size < MAX_EVENTS) {
|
|
113
|
+
events.add(name);
|
|
114
|
+
try {
|
|
115
|
+
sessionStorage.setItem(this.store, JSON.stringify({ sid: this.sid, names: Array.from(events) }));
|
|
116
|
+
} catch {
|
|
117
|
+
/* storage blocked: memory only, this page */
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
this.emit();
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Called whenever a moment may have come. */
|
|
124
|
+
onChange(cb: () => void): () => void {
|
|
125
|
+
this.listeners.add(cb);
|
|
126
|
+
return () => this.listeners.delete(cb);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
destroy(): void {
|
|
130
|
+
this.off?.();
|
|
131
|
+
this.listeners.clear();
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** The event names tracked in the current SDK session (a new session starts empty). */
|
|
135
|
+
private visitEvents(): Set<string> {
|
|
136
|
+
const sid = this.sessionId();
|
|
137
|
+
if (sid !== this.sid) {
|
|
138
|
+
this.sid = sid;
|
|
139
|
+
this.events = new Set();
|
|
140
|
+
try {
|
|
141
|
+
const raw = JSON.parse(sessionStorage.getItem(this.store) || 'null');
|
|
142
|
+
if (raw && sid && raw.sid === sid) this.events = new Set(eventNames(raw.names, MAX_EVENTS));
|
|
143
|
+
} catch {
|
|
144
|
+
/* ignore */
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return this.events;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
private emit(): void {
|
|
151
|
+
for (const cb of Array.from(this.listeners)) {
|
|
152
|
+
try {
|
|
153
|
+
cb();
|
|
154
|
+
} catch {
|
|
155
|
+
/* a listener never breaks the others */
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
@@ -50,6 +50,8 @@ export const EDITOR_STRINGS = {
|
|
|
50
50
|
more: 'More…',
|
|
51
51
|
search: 'Search fields',
|
|
52
52
|
noMatch: 'No matching fields',
|
|
53
|
+
groupProfile: 'Profile',
|
|
54
|
+
groupCustom: 'Custom fields',
|
|
53
55
|
rawNote: 'Shown as code: this text uses Liquid beyond profile fields and fallbacks.',
|
|
54
56
|
newLink: 'New link address',
|
|
55
57
|
newImage: 'New image address',
|
|
@@ -70,6 +72,15 @@ export const EDITOR_STRINGS = {
|
|
|
70
72
|
posPrepend: 'Inside, at the start',
|
|
71
73
|
posAppend: 'Inside, at the end',
|
|
72
74
|
slotPreview: 'Content slot',
|
|
75
|
+
view: 'View',
|
|
76
|
+
viewDesktop: 'Desktop',
|
|
77
|
+
viewMobile: 'Mobile',
|
|
78
|
+
appliesTo: 'Applies to',
|
|
79
|
+
devAll: 'All devices',
|
|
80
|
+
devMobile: 'Mobile only',
|
|
81
|
+
devDesktop: 'Desktop only',
|
|
82
|
+
deviceHidden: 'Not shown in this view - switch to the other view to see it.',
|
|
83
|
+
frameBlocked: 'This site does not allow itself to be shown in a frame, so the mobile view cannot open. Make this window narrower than 768 px to see and edit the mobile layout.',
|
|
73
84
|
css: 'CSS selector',
|
|
74
85
|
cssHelp: 'For developers. Matches {n} on this page.',
|
|
75
86
|
cssBad: 'Not a selector this page can use.',
|
package/src/editor/editor-ui.ts
CHANGED
|
@@ -36,6 +36,8 @@ const ICONS = {
|
|
|
36
36
|
chevron: ['m9 18 6-6-6-6'],
|
|
37
37
|
check: ['M20 6 9 17l-5-5'],
|
|
38
38
|
close: ['M18 6 6 18M6 6l12 12'],
|
|
39
|
+
desktop: ['M3 4h18v12H3z', 'M8 20h8M12 16v4'],
|
|
40
|
+
mobile: ['M7 2h10v20H7z', 'M11 18h2'],
|
|
39
41
|
};
|
|
40
42
|
export type IconName = keyof typeof ICONS;
|
|
41
43
|
|
|
@@ -56,6 +58,8 @@ export const HOST_STYLE = 'all:initial !important;position:fixed !important;top:
|
|
|
56
58
|
/** A preview element the editor puts IN the page (a slot, a hidden-element note): its own shadow root too. */
|
|
57
59
|
export const PREVIEW_HOST_STYLE = 'all:initial !important;display:block !important;margin:10px 0 !important';
|
|
58
60
|
|
|
61
|
+
/** The editor's Mobile view width in CSS pixels (a common phone; below the 768 px breakpoint). */
|
|
62
|
+
export const MOBILE_FRAME_WIDTH = 390;
|
|
59
63
|
const FONT = 'Inter,system-ui,-apple-system,"Segoe UI",Roboto,sans-serif';
|
|
60
64
|
const MONO = 'ui-monospace,"SF Mono",Menlo,monospace';
|
|
61
65
|
|
|
@@ -148,9 +152,10 @@ input.slotin{border-color:#7A6CFF}
|
|
|
148
152
|
.chips{display:flex;flex-wrap:wrap;gap:6px;margin-top:8px;align-items:center}
|
|
149
153
|
.chips span{font-size:11.5px;color:#6B7280;margin-inline-end:2px}
|
|
150
154
|
.vc{font-family:${MONO};font-size:11.5px;padding:3px 8px;border-radius:6px;border:1px solid #E5EAF2;background:#F8FAFC;color:#3A4060}
|
|
155
|
+
.vc.ui{font-family:${FONT};font-weight:600;letter-spacing:normal}
|
|
151
156
|
.pk{margin-top:8px;border:1px solid #E5EAF2;border-radius:10px;padding:6px;background:#fff;box-shadow:0 8px 24px rgba(10,18,64,.1)}
|
|
152
157
|
.pk input{height:34px}
|
|
153
|
-
.pk [role=listbox]{max-height:220px;overflow:auto;margin-top:
|
|
158
|
+
.pk [role=listbox]{position:relative;max-height:220px;overflow:auto;overflow-anchor:none;margin-top:6px;padding-top:2px}
|
|
154
159
|
.pk .g{font-size:10.5px;font-weight:700;color:#6B7280;text-transform:uppercase;letter-spacing:.4px;padding:8px 8px 3px}
|
|
155
160
|
.pk .o{display:flex;justify-content:space-between;align-items:baseline;gap:8px;padding:6px 8px;border-radius:7px;font-size:12.5px;cursor:pointer}
|
|
156
161
|
.pk .o[aria-selected=true],.pk .o:hover{background:#E5F9F6}
|
|
@@ -164,6 +169,15 @@ input.slotin{border-color:#7A6CFF}
|
|
|
164
169
|
.seg{display:grid;grid-template-columns:1fr 1fr 1fr;gap:4px;background:#F3F5FA;border-radius:9px;padding:3px}
|
|
165
170
|
.seg button{border:0;background:transparent;border-radius:7px;padding:6px 4px;font-size:12px;color:#3A4060}
|
|
166
171
|
.seg button[aria-checked=true]{background:#fff;color:#0A1240;font-weight:600;box-shadow:0 1px 2px rgba(10,18,64,.08)}
|
|
172
|
+
.vw{display:inline-flex;gap:2px;background:#1B245A;border-radius:8px;padding:2px}
|
|
173
|
+
.vw button{height:28px;width:30px;border:0;border-radius:6px;background:transparent;color:#A8AEC1;display:grid;place-items:center}
|
|
174
|
+
.vw button[aria-checked=true]{background:#31D6C8;color:#071342}
|
|
175
|
+
.bdg{margin-inline-start:auto;font-size:10.5px;font-weight:600;padding:2px 7px;border-radius:999px;background:#F4F2FF;color:#4C3FD1;white-space:nowrap}
|
|
176
|
+
.dv.top{margin-bottom:18px;padding:10px;border-radius:10px;background:#F4F2FF}
|
|
177
|
+
.stage{position:fixed;inset:0;background:#E9ECF3;display:flex;justify-content:center;align-items:flex-start;padding:16px 16px 76px}
|
|
178
|
+
.r.open .stage{inset-inline-end:380px}
|
|
179
|
+
.stage iframe{width:${MOBILE_FRAME_WIDTH}px;max-width:100%;height:100%;border:0;border-radius:18px;background:#fff;box-shadow:0 12px 32px rgba(10,18,64,.18)}
|
|
180
|
+
.fnote{max-width:360px;margin-top:40px}
|
|
167
181
|
.css{margin-top:20px;display:inline-flex;align-items:center;gap:6px;border:0;background:transparent;padding:0;color:#6B7280;font-size:12px}
|
|
168
182
|
.ft{padding:12px 18px;border-top:1px solid #E5EAF2;display:flex;gap:10px;background:#F8FAFC}
|
|
169
183
|
.cancel{height:38px;padding:0 14px;border-radius:10px;border:1px solid #E5EAF2;background:#fff;color:#242B3A;font-size:13px;font-weight:600}
|
|
@@ -35,6 +35,8 @@ export interface LiquidField {
|
|
|
35
35
|
insert(tag: string): void;
|
|
36
36
|
/** Close a pill's fallback popover; true when one was open. */
|
|
37
37
|
closePop(): boolean;
|
|
38
|
+
/** Open the fallback popover of the (first) pill of this variable path; false when there is none. */
|
|
39
|
+
openPill(path: string): boolean;
|
|
38
40
|
}
|
|
39
41
|
|
|
40
42
|
/** The words of a pill's fallback popover: `title` has `{name}`, the field's label. */
|
|
@@ -154,7 +156,7 @@ export function liquidField(opts: {
|
|
|
154
156
|
const input = h('input', { dir: 'auto', 'data-j': 'fallback', 'aria-label': title, maxlength: '200' });
|
|
155
157
|
input.value = varFallback(v.src) || '';
|
|
156
158
|
const err = h('div', { class: 'err', 'data-j': 'fallback-error', role: 'alert' });
|
|
157
|
-
const done = h('button', { class: 'vc', type: 'button', 'data-j': 'fallback-done' }, words.done);
|
|
159
|
+
const done = h('button', { class: 'vc ui', type: 'button', 'data-j': 'fallback-done' }, words.done);
|
|
158
160
|
const p = h('div', { class: 'pk fbp', role: 'dialog', 'aria-label': title, 'data-j': 'fallback-pop' }, h('label', { class: 'lbl' }, title), input, err, h('div', { class: 'help2' }, words.help), done);
|
|
159
161
|
const finish = () => {
|
|
160
162
|
closePop();
|
|
@@ -183,6 +185,11 @@ export function liquidField(opts: {
|
|
|
183
185
|
}
|
|
184
186
|
});
|
|
185
187
|
done.addEventListener('click', finish);
|
|
188
|
+
// Focus leaving the popover (Tab away, a click elsewhere) closes it.
|
|
189
|
+
p.addEventListener('focusout', (e) => {
|
|
190
|
+
const to = e.relatedTarget as Node | null;
|
|
191
|
+
if (pop === p && (!to || !p.contains(to))) closePop();
|
|
192
|
+
});
|
|
186
193
|
pop = p;
|
|
187
194
|
el.appendChild(p);
|
|
188
195
|
input.focus();
|
|
@@ -297,5 +304,13 @@ export function liquidField(opts: {
|
|
|
297
304
|
emit();
|
|
298
305
|
};
|
|
299
306
|
|
|
300
|
-
|
|
307
|
+
const openPill = (path: string): boolean => {
|
|
308
|
+
if (!box || box.tagName !== 'DIV') return false;
|
|
309
|
+
const target = Array.from(box.querySelectorAll(`[${PILL_ATTR}]`)).filter((n) => n.getAttribute('data-path') === path)[0] as HTMLElement | undefined;
|
|
310
|
+
if (!target) return false;
|
|
311
|
+
openPop(target);
|
|
312
|
+
return true;
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
return { el, set, insert, closePop, openPill };
|
|
301
316
|
}
|