@wix/himalaya-cli 0.1713.0 → 0.1715.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/sdk/webview/src/dispatcher.d.ts +4 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/sdk/webview/src/index.d.ts +14 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/sdk/webview/src/site-events.d.ts +54 -0
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/sdk/webview-page/src/capabilities.generated.d.ts +1 -1
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/sdk/webview-page/src/client.d.ts +24 -1
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/sdk/webview-page/src/index.d.ts +7 -1
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/core.mjs +2 -1
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/sdui.mjs +2 -1
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/webview-page.mjs +21 -2
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/webview.mjs +208 -1
- package/dist/browser-plane/assets.json +5 -5
- package/dist/browser-plane/preview-deferred/{eebfb701744c8f130b659a79b33f563c2a47f5104d624fe7e108a064dce68d1b.bin → beb47fb3bdf1fe461bde8322263c72e10006079380c5551599c470308b4d3e31.bin} +1 -1
- package/dist/browser-plane/sw.js +1 -1
- package/dist/cli.mjs +260 -214
- package/dist/preview-assets.generated.bin +0 -0
- package/guides/capabilities.md +1 -1
- package/guides/release-notes.md +16 -0
- package/guides/sdk-reference.json +29 -1
- package/guides/webview-page-sdk.md +47 -0
- package/package.json +2 -2
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type SiteEvent, type SiteSnapshot } from "./site-events.js";
|
|
1
2
|
export type WebViewRuntime = {
|
|
2
3
|
postToPage(msg: unknown, instanceId?: string): void;
|
|
3
4
|
onPageMessage(cb: (msg: unknown, instanceId?: unknown) => void): void;
|
|
@@ -72,6 +73,9 @@ export interface PageDispatcher {
|
|
|
72
73
|
addNamespace(namespace: string, handlers: Readonly<Record<string, PageRequestHandler>>): void;
|
|
73
74
|
subscribeLifecycle(cb: (e: PageLifecycleEvent) => void): () => void;
|
|
74
75
|
subscribeConsole(cb: (e: PageConsoleEvent) => void): () => void;
|
|
76
|
+
/** RFC 0079 §7 phase 5 — site events of site-trusted pages (and page reports). */
|
|
77
|
+
subscribeSite(cb: (e: SiteEvent) => void): () => void;
|
|
78
|
+
siteState(instanceId: string): SiteSnapshot | undefined;
|
|
75
79
|
post(instanceId: string, msg: unknown): void;
|
|
76
80
|
emit(target: string, event: string, data: unknown): void;
|
|
77
81
|
openStream(instanceId: string, requestId: string): PageStream;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { type ExposedPageCapability, type PageConsoleEvent, type PageLifecycleEvent, type PageRequestHandler, type PageStream } from "./dispatcher.js";
|
|
2
2
|
export { PAGE_HANDSHAKE_CAPABILITY, PAGE_HANDSHAKE_METHOD, type ExposedPageCapability, type PageCapabilityRequest, type PageCapabilityResponse, type PageConsoleEvent, type PageCtx, type PageLifecycleEvent, type PageRequestHandler, type PageStream, } from "./dispatcher.js";
|
|
3
|
+
export type { SiteEvent, SiteEventName, SiteEventSource, SiteRoute, SiteSnapshot } from "./site-events.js";
|
|
4
|
+
import type { SiteEvent, SiteSnapshot } from "./site-events.js";
|
|
3
5
|
/**
|
|
4
6
|
* Push a message from the worker to the hosting webview page. Delivered to every
|
|
5
7
|
* `window.HimalayaWorker.onMessage(cb)` handler the page registered. `msg` is
|
|
@@ -46,6 +48,18 @@ export declare function onPageLifecycle(cb: (e: PageLifecycleEvent) => void): ()
|
|
|
46
48
|
* these, so never treat them as host events. Returns an unsubscribe function.
|
|
47
49
|
*/
|
|
48
50
|
export declare function onPageConsole(cb: (e: PageConsoleEvent) => void): () => void;
|
|
51
|
+
/**
|
|
52
|
+
* Observe site events of the screen's SITE-TRUSTED page (a `role: "primary"`,
|
|
53
|
+
* `bridge: "worker"` site WebView on the site baked into the app): `title`, `route` and `member` from
|
|
54
|
+
* the host, `cart` from the binary's Wix adapter (best effort: `null` is unknown, hide a badge), and
|
|
55
|
+
* whatever the page reports itself with `himalaya.site.report(…)`. Precedence per field: host >
|
|
56
|
+
* adapter > page. Each event carries the merged `state`; the host re-sends a `snapshot` whenever the
|
|
57
|
+
* channel attaches (a mount, a return to the site after leaving it). Without a site-trusted bridge
|
|
58
|
+
* nothing is emitted. Returns an unsubscribe function.
|
|
59
|
+
*/
|
|
60
|
+
export declare function onSiteEvent(cb: (e: SiteEvent) => void): () => void;
|
|
61
|
+
/** The merged site snapshot of one page instance, or `undefined` before anything was heard from it. */
|
|
62
|
+
export declare function siteState(instanceId: string): SiteSnapshot | undefined;
|
|
49
63
|
/**
|
|
50
64
|
* Expose selected typed @himalaya/* modules to the hosting page.
|
|
51
65
|
*
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export type SiteEventName = "title" | "route" | "cart" | "member" | "snapshot";
|
|
2
|
+
export type SiteEventSource = "host" | "adapter" | "page";
|
|
3
|
+
export interface SiteRoute {
|
|
4
|
+
/** The path inside the trusted site, from its root: `/book-online`. Never a URL outside the site. */
|
|
5
|
+
path: string;
|
|
6
|
+
/** `""` or `"?…"`, at most 512 characters; never a fragment. */
|
|
7
|
+
search: string;
|
|
8
|
+
}
|
|
9
|
+
/** What the worker knows about one site-trusted page. `null` is unknown. */
|
|
10
|
+
export interface SiteSnapshot {
|
|
11
|
+
title: string | null;
|
|
12
|
+
route: SiteRoute | null;
|
|
13
|
+
/** Visitor cart item count, 0–999. `null` when unknown (no cart icon, unreadable, no adapter): hide a badge. */
|
|
14
|
+
cart: number | null;
|
|
15
|
+
/** Whether a member is signed in to the WEBSITE (may differ from the native identity). */
|
|
16
|
+
member: boolean | null;
|
|
17
|
+
}
|
|
18
|
+
export interface SiteEvent {
|
|
19
|
+
instanceId: string;
|
|
20
|
+
event: SiteEventName;
|
|
21
|
+
/** `title` → `{ title }`, `route` → `{ path, search, sameDocument }`, `cart` → `{ count }`,
|
|
22
|
+
* `member` → `{ signedIn }`, `snapshot` → the snapshot. */
|
|
23
|
+
data: unknown;
|
|
24
|
+
source: SiteEventSource;
|
|
25
|
+
/** The merged snapshot after this event (a copy). */
|
|
26
|
+
state: SiteSnapshot;
|
|
27
|
+
}
|
|
28
|
+
export declare const SITE_TITLE_MAX = 200;
|
|
29
|
+
export declare const SITE_SEARCH_MAX = 512;
|
|
30
|
+
export declare const SITE_PATH_MAX = 512;
|
|
31
|
+
export declare const SITE_CART_MAX = 999;
|
|
32
|
+
/** A title: whitespace collapsed, trimmed, at most 200 code points; empty or not a string → null. */
|
|
33
|
+
export declare function normalizeSiteTitle(raw: unknown): string | null;
|
|
34
|
+
/** A cart count: an integer 0–999 (larger is 999); anything else → null (unknown). */
|
|
35
|
+
export declare function normalizeSiteCart(raw: unknown): number | null;
|
|
36
|
+
export declare function normalizeSiteMember(raw: unknown): boolean | null;
|
|
37
|
+
/**
|
|
38
|
+
* A route: `{ path, search }` from the host, or a page's `"/path?query#hash"` string. The path must
|
|
39
|
+
* start with `/` (a path inside the site, never a URL); the fragment is dropped; search is `""` or
|
|
40
|
+
* starts with `?`; both are capped.
|
|
41
|
+
*/
|
|
42
|
+
export declare function normalizeSiteRoute(raw: unknown): SiteRoute | null;
|
|
43
|
+
export interface SiteEventsStore {
|
|
44
|
+
/** A host-primitive envelope (`sys: "site"`). Returns the events to deliver. */
|
|
45
|
+
host(envelope: unknown, instanceId: string): SiteEvent[];
|
|
46
|
+
/** A page-primitive report (`sys: "site"`, `ev: "report"`). Returns the events to deliver. */
|
|
47
|
+
page(message: unknown, instanceId: string): SiteEvent[];
|
|
48
|
+
/** A new document: the old one's page reports are stale. */
|
|
49
|
+
documentEnded(instanceId: string): void;
|
|
50
|
+
unmounted(instanceId: string): void;
|
|
51
|
+
snapshot(instanceId: string): SiteSnapshot | undefined;
|
|
52
|
+
}
|
|
53
|
+
/** Per-instance merged site state, with host > adapter > page precedence. */
|
|
54
|
+
export declare function createSiteEventsStore(): SiteEventsStore;
|
|
@@ -100,5 +100,5 @@ export interface HimalayaPageCapabilities {
|
|
|
100
100
|
/** `window.himalaya` and the package's `himalaya` export: the namespaces plus the client's own members. */
|
|
101
101
|
export type HimalayaPageSdk = HimalayaPageCapabilities & {
|
|
102
102
|
readonly version: 1;
|
|
103
|
-
} & Readonly<Pick<PageClient, "call" | "on" | "enabledCapabilities" | "isEnabled" | "probe">>;
|
|
103
|
+
} & Readonly<Pick<PageClient, "call" | "on" | "enabledCapabilities" | "isEnabled" | "probe" | "site">>;
|
|
104
104
|
export {};
|
|
@@ -44,6 +44,27 @@ export interface HimalayaWorkerBridge {
|
|
|
44
44
|
onMessage(handler: (message: unknown) => void): void;
|
|
45
45
|
}
|
|
46
46
|
export type PageEventHandler = (data: unknown) => void;
|
|
47
|
+
/**
|
|
48
|
+
* What a page may report about its own site. Each field is optional; `null`
|
|
49
|
+
* means unknown. The worker merges it with what the host reports, and the host always wins: a page
|
|
50
|
+
* can add `cart` and the website's `member` (Base44 and other sites, where the host has no signal),
|
|
51
|
+
* but never overrides the host's title, route or member.
|
|
52
|
+
*/
|
|
53
|
+
export interface SiteReport {
|
|
54
|
+
/** The page's title (at most 200 characters, whitespace collapsed). */
|
|
55
|
+
title?: string | null;
|
|
56
|
+
/** The path inside the site, `"/path?query"` (never a URL; the fragment is dropped). */
|
|
57
|
+
route?: string | null;
|
|
58
|
+
/** Visitor cart item count, an integer 0–999; `null` is unknown. */
|
|
59
|
+
cart?: number | null;
|
|
60
|
+
/** Whether a member is signed in to the website. */
|
|
61
|
+
member?: boolean | null;
|
|
62
|
+
}
|
|
63
|
+
export interface PageSite {
|
|
64
|
+
/** Report site facts to the companion worker (fire-and-forget; no answer, no timeout). Returns
|
|
65
|
+
* whether the bridge took it: `false` outside the app or when the native bridge refused it. */
|
|
66
|
+
report(fields: SiteReport): boolean;
|
|
67
|
+
}
|
|
47
68
|
export interface PageClient {
|
|
48
69
|
call<T>(capability: string, method: string, args?: unknown[], timeoutMs?: number): Promise<T>;
|
|
49
70
|
/** Subscribe to `namespace.event` pushed by the worker. Returns the unsubscribe function. */
|
|
@@ -53,10 +74,12 @@ export interface PageClient {
|
|
|
53
74
|
probe(capability: string, method: string, args?: unknown[], timeoutMs?: number): Promise<boolean>;
|
|
54
75
|
/** `himalaya.<capability>` — a proxy whose members call, plus `.on(event, cb)`. */
|
|
55
76
|
namespace(capability: string): object;
|
|
77
|
+
/** `himalaya.site` — report facts about the page's own site to the worker. */
|
|
78
|
+
site: PageSite;
|
|
56
79
|
/**
|
|
57
80
|
* Merge this client into a host's `himalaya` object (the RFC 0038 shim's) and return what to
|
|
58
81
|
* install as `window.himalaya`: `target` gains `call`, `on`, `enabledCapabilities`, `isEnabled`,
|
|
59
|
-
* `probe` and `version`, is frozen, and any other name resolves to a namespace proxy. Existing
|
|
82
|
+
* `probe`, `site` and `version`, is frozen, and any other name resolves to a namespace proxy. Existing
|
|
60
83
|
* members of `target` (e.g. the shim's `general`) win.
|
|
61
84
|
*/
|
|
62
85
|
merge<T extends object>(target: T): T;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { HimalayaPageSdk } from "./capabilities.generated.js";
|
|
2
2
|
export type { HimalayaPageCapabilities, HimalayaPageSdk } from "./capabilities.generated.js";
|
|
3
3
|
import { type PageEventHandler } from "./client.js";
|
|
4
|
-
export type { PageEventHandler, WebViewPageError, WebViewPageEvent, WebViewPageRequest, WebViewPageResponse, WebViewPageStreamEnvelope, } from "./client.js";
|
|
4
|
+
export type { PageEventHandler, PageSite, SiteReport, WebViewPageError, WebViewPageEvent, WebViewPageRequest, WebViewPageResponse, WebViewPageStreamEnvelope, } from "./client.js";
|
|
5
5
|
/** Invoke one method through the companion worker. Primarily useful to generated bindings.
|
|
6
6
|
* A call that shows native UI (a permission prompt, the share sheet) answers only when the user
|
|
7
7
|
* is done with it: pass a long `timeoutMs` (e.g. 120_000) rather than the 30-second default.
|
|
@@ -31,6 +31,12 @@ export declare function probe(capability: string, method: string, args?: unknown
|
|
|
31
31
|
* injected client, so `himalaya.call/on/probe/…` are the client's members here too.
|
|
32
32
|
*/
|
|
33
33
|
export declare const himalaya: HimalayaPageSdk;
|
|
34
|
+
/**
|
|
35
|
+
* Report site facts the host cannot see (Base44 and other sites): `cart`, the
|
|
36
|
+
* website's `member`, and — only where no host reports them — `title` and `route`. Fire-and-forget;
|
|
37
|
+
* the host's own title, route and member always win. Same as `himalaya.site.report(fields)`.
|
|
38
|
+
*/
|
|
39
|
+
export declare const site: import("./client.js").PageSite;
|
|
34
40
|
/** Convenience named export; equivalent to `himalaya.health`. */
|
|
35
41
|
export declare const health: {
|
|
36
42
|
readonly healthError: (code: import("@wix/himalaya/health").HealthErrorCode, message: string) => import("@wix/himalaya/health").HealthError;
|
|
@@ -15165,7 +15165,8 @@ function sitePageNode(site, page, opts) {
|
|
|
15165
15165
|
if (page.bridge !== void 0 && page.bridge !== "worker") {
|
|
15166
15166
|
throw new Error(`site page bridge ${JSON.stringify(page.bridge)} must be "worker" or unset`);
|
|
15167
15167
|
}
|
|
15168
|
-
|
|
15168
|
+
const adapter = page.bridge === "worker" && site.kind === "wix" ? { hostedSiteAdapter: "wix" } : {};
|
|
15169
|
+
return primarySiteWebView(url, { ...siteWebViewPreset(site), ...adapter, ...page.webView ?? {} }, opts?.id ?? SITE_PAGE_NODE_ID, page.title, [], page.bridge);
|
|
15169
15170
|
}
|
|
15170
15171
|
function isDesugarableSiteScreen(descriptor) {
|
|
15171
15172
|
return !!descriptor && descriptor.renderer === "webview_native_bridge" && typeof descriptor.url === "string" && descriptor.url !== "" && descriptor.logicBundle === void 0 && descriptor.webViewConfig?.internalLinksAsScreens !== true;
|
|
@@ -8491,7 +8491,8 @@ function sitePageNode(site, page, opts) {
|
|
|
8491
8491
|
if (page.bridge !== void 0 && page.bridge !== "worker") {
|
|
8492
8492
|
throw new Error(`site page bridge ${JSON.stringify(page.bridge)} must be "worker" or unset`);
|
|
8493
8493
|
}
|
|
8494
|
-
|
|
8494
|
+
const adapter = page.bridge === "worker" && site.kind === "wix" ? { hostedSiteAdapter: "wix" } : {};
|
|
8495
|
+
return primarySiteWebView(url, { ...siteWebViewPreset(site), ...adapter, ...page.webView ?? {} }, opts?.id ?? SITE_PAGE_NODE_ID, page.title, [], page.bridge);
|
|
8495
8496
|
}
|
|
8496
8497
|
|
|
8497
8498
|
// ../../core/ts/src/rich-content-limits.generated.ts
|
|
@@ -247,8 +247,25 @@ function createPageClient(getBridge) {
|
|
|
247
247
|
return member;
|
|
248
248
|
}
|
|
249
249
|
const namespace = (capability) => pageMember(capability, []);
|
|
250
|
+
const SITE_FIELDS = ["title", "route", "cart", "member"];
|
|
251
|
+
const site2 = Object.freeze({
|
|
252
|
+
report(fields) {
|
|
253
|
+
const bridge = currentBridge();
|
|
254
|
+
if (!bridge || !fields || typeof fields !== "object") return false;
|
|
255
|
+
const data = {};
|
|
256
|
+
for (const name of SITE_FIELDS) {
|
|
257
|
+
if (Object.prototype.hasOwnProperty.call(fields, name)) data[name] = fields[name];
|
|
258
|
+
}
|
|
259
|
+
if (Object.keys(data).length === 0) return false;
|
|
260
|
+
try {
|
|
261
|
+
return bridge.post({ v: 1, sys: "site", ev: "report", data }) === true;
|
|
262
|
+
} catch {
|
|
263
|
+
return false;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
});
|
|
250
267
|
function merge(target) {
|
|
251
|
-
const own = { call: call2, on: on2, enabledCapabilities: enabledCapabilities2, isEnabled: isEnabled2, probe: probe2, version: 1 };
|
|
268
|
+
const own = { call: call2, on: on2, enabledCapabilities: enabledCapabilities2, isEnabled: isEnabled2, probe: probe2, site: site2, version: 1 };
|
|
252
269
|
for (const name of Object.keys(own)) {
|
|
253
270
|
if (!Object.prototype.hasOwnProperty.call(target, name)) {
|
|
254
271
|
Object.defineProperty(target, name, { value: own[name], enumerable: true, writable: false, configurable: false });
|
|
@@ -263,7 +280,7 @@ function createPageClient(getBridge) {
|
|
|
263
280
|
}
|
|
264
281
|
});
|
|
265
282
|
}
|
|
266
|
-
return { call: call2, on: on2, enabledCapabilities: enabledCapabilities2, isEnabled: isEnabled2, probe: probe2, namespace, merge };
|
|
283
|
+
return { call: call2, on: on2, enabledCapabilities: enabledCapabilities2, isEnabled: isEnabled2, probe: probe2, namespace, site: site2, merge };
|
|
267
284
|
}
|
|
268
285
|
|
|
269
286
|
// ../../core/sdk/webview-page/src/webTransport.ts
|
|
@@ -506,6 +523,7 @@ function probe(capability, method, args = [], timeoutMs = 3e3) {
|
|
|
506
523
|
return client.probe(capability, method, args, timeoutMs);
|
|
507
524
|
}
|
|
508
525
|
var himalaya = client.merge({});
|
|
526
|
+
var site = client.site;
|
|
509
527
|
var health = himalaya.health;
|
|
510
528
|
var version = 1;
|
|
511
529
|
export {
|
|
@@ -516,6 +534,7 @@ export {
|
|
|
516
534
|
isEnabled,
|
|
517
535
|
on,
|
|
518
536
|
probe,
|
|
537
|
+
site,
|
|
519
538
|
version
|
|
520
539
|
};
|
|
521
540
|
//# sourceMappingURL=webview-page.mjs.map
|
|
@@ -1,7 +1,169 @@
|
|
|
1
|
+
// ../../core/sdk/webview/src/site-events.ts
|
|
2
|
+
var SITE_TITLE_MAX = 200;
|
|
3
|
+
var SITE_SEARCH_MAX = 512;
|
|
4
|
+
var SITE_PATH_MAX = 512;
|
|
5
|
+
var SITE_CART_MAX = 999;
|
|
6
|
+
var RANK = { page: 1, adapter: 2, host: 3 };
|
|
7
|
+
var FIELDS = ["title", "route", "cart", "member"];
|
|
8
|
+
function capCodePoints(s, max) {
|
|
9
|
+
const points = Array.from(s);
|
|
10
|
+
return points.length > max ? points.slice(0, max).join("") : s;
|
|
11
|
+
}
|
|
12
|
+
function normalizeSiteTitle(raw) {
|
|
13
|
+
if (typeof raw !== "string") return null;
|
|
14
|
+
const t = capCodePoints(raw.replace(/\s+/g, " ").trim(), SITE_TITLE_MAX).trim();
|
|
15
|
+
return t ? t : null;
|
|
16
|
+
}
|
|
17
|
+
function normalizeSiteCart(raw) {
|
|
18
|
+
if (typeof raw !== "number" || !Number.isInteger(raw) || raw < 0) return null;
|
|
19
|
+
return Math.min(raw, SITE_CART_MAX);
|
|
20
|
+
}
|
|
21
|
+
function normalizeSiteMember(raw) {
|
|
22
|
+
return typeof raw === "boolean" ? raw : null;
|
|
23
|
+
}
|
|
24
|
+
function normalizeSiteRoute(raw) {
|
|
25
|
+
let path;
|
|
26
|
+
let search = "";
|
|
27
|
+
if (typeof raw === "string") {
|
|
28
|
+
const noHash = raw.split("#")[0];
|
|
29
|
+
const q = noHash.indexOf("?");
|
|
30
|
+
path = q < 0 ? noHash : noHash.slice(0, q);
|
|
31
|
+
search = q < 0 ? "" : noHash.slice(q);
|
|
32
|
+
} else if (raw && typeof raw === "object" && !Array.isArray(raw)) {
|
|
33
|
+
path = raw.path;
|
|
34
|
+
search = raw.search ?? "";
|
|
35
|
+
}
|
|
36
|
+
if (typeof path !== "string" || !path.startsWith("/") || path.startsWith("//") || /[\s\\]/.test(path)) return null;
|
|
37
|
+
if (typeof search !== "string") return null;
|
|
38
|
+
if (search && !search.startsWith("?")) search = `?${search}`;
|
|
39
|
+
const s = search.split("#")[0];
|
|
40
|
+
return { path: capCodePoints(path, SITE_PATH_MAX), search: s === "?" ? "" : capCodePoints(s, SITE_SEARCH_MAX) };
|
|
41
|
+
}
|
|
42
|
+
function normalizeField(field, raw) {
|
|
43
|
+
switch (field) {
|
|
44
|
+
case "title":
|
|
45
|
+
return normalizeSiteTitle(raw);
|
|
46
|
+
case "route":
|
|
47
|
+
return normalizeSiteRoute(raw);
|
|
48
|
+
case "cart":
|
|
49
|
+
return normalizeSiteCart(raw);
|
|
50
|
+
case "member":
|
|
51
|
+
return normalizeSiteMember(raw);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function eventData(ev, value, sameDocument) {
|
|
55
|
+
switch (ev) {
|
|
56
|
+
case "title":
|
|
57
|
+
return { title: value };
|
|
58
|
+
case "route":
|
|
59
|
+
return value ? { ...value, sameDocument } : null;
|
|
60
|
+
case "cart":
|
|
61
|
+
return { count: value };
|
|
62
|
+
case "member":
|
|
63
|
+
return { signedIn: value };
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
var emptySlots = () => ({
|
|
67
|
+
title: { value: null, rank: 0 },
|
|
68
|
+
route: { value: null, rank: 0 },
|
|
69
|
+
cart: { value: null, rank: 0 },
|
|
70
|
+
member: { value: null, rank: 0 }
|
|
71
|
+
});
|
|
72
|
+
function snapshotOf(state) {
|
|
73
|
+
const route = state.slots.route.value;
|
|
74
|
+
return {
|
|
75
|
+
title: state.slots.title.value,
|
|
76
|
+
route: route ? { path: route.path, search: route.search } : null,
|
|
77
|
+
cart: state.slots.cart.value,
|
|
78
|
+
member: state.slots.member.value
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function apply(slot, value, rank) {
|
|
82
|
+
if (value === null) {
|
|
83
|
+
if (slot.rank !== rank || slot.value === null) return false;
|
|
84
|
+
slot.value = null;
|
|
85
|
+
slot.rank = 0;
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
if (slot.value !== null && rank < slot.rank) return false;
|
|
89
|
+
const changed = JSON.stringify(slot.value) !== JSON.stringify(value);
|
|
90
|
+
slot.value = value;
|
|
91
|
+
slot.rank = rank;
|
|
92
|
+
return changed;
|
|
93
|
+
}
|
|
94
|
+
var HOST_FIELD_SOURCE = { title: "host", route: "host", cart: "adapter", member: "host" };
|
|
95
|
+
function createSiteEventsStore() {
|
|
96
|
+
const instances = /* @__PURE__ */ new Map();
|
|
97
|
+
const stateFor = (instanceId) => {
|
|
98
|
+
let s = instances.get(instanceId);
|
|
99
|
+
if (!s) instances.set(instanceId, s = { slots: emptySlots() });
|
|
100
|
+
return s;
|
|
101
|
+
};
|
|
102
|
+
function host(envelope, instanceId) {
|
|
103
|
+
const e = envelope;
|
|
104
|
+
if (!e || typeof e !== "object" || e.v !== 1 || e.sys !== "site") return [];
|
|
105
|
+
const ev = e.ev;
|
|
106
|
+
if (ev !== "snapshot" && !FIELDS.includes(ev)) return [];
|
|
107
|
+
const src = e.src === "adapter" ? "adapter" : "host";
|
|
108
|
+
const s = stateFor(instanceId);
|
|
109
|
+
const snap = e.state && typeof e.state === "object" && !Array.isArray(e.state) ? e.state : null;
|
|
110
|
+
if (snap) {
|
|
111
|
+
for (const field2 of FIELDS) {
|
|
112
|
+
if (field2 in snap) apply(s.slots[field2], normalizeField(field2, snap[field2]), RANK[HOST_FIELD_SOURCE[field2]]);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
if (ev === "snapshot") {
|
|
116
|
+
return [{ instanceId, event: "snapshot", data: snapshotOf(s), source: src, state: snapshotOf(s) }];
|
|
117
|
+
}
|
|
118
|
+
const field = ev;
|
|
119
|
+
const d = e.data && typeof e.data === "object" ? e.data : {};
|
|
120
|
+
const raw = field === "title" ? d.title : field === "route" ? d : field === "cart" ? d.count : d.signedIn;
|
|
121
|
+
const value = normalizeField(field, raw);
|
|
122
|
+
if (!snap) apply(s.slots[field], value, RANK[src]);
|
|
123
|
+
const sameDocument = field === "route" && d.sameDocument === true;
|
|
124
|
+
return [{ instanceId, event: field, data: eventData(field, s.slots[field].value, sameDocument), source: src, state: snapshotOf(s) }];
|
|
125
|
+
}
|
|
126
|
+
function page(message, instanceId) {
|
|
127
|
+
const m = message;
|
|
128
|
+
if (!m || typeof m !== "object" || m.v !== 1 || m.sys !== "site" || m.ev !== "report") return [];
|
|
129
|
+
const data = m.data && typeof m.data === "object" && !Array.isArray(m.data) ? m.data : null;
|
|
130
|
+
if (!data) return [];
|
|
131
|
+
const s = stateFor(instanceId);
|
|
132
|
+
const out = [];
|
|
133
|
+
for (const field of FIELDS) {
|
|
134
|
+
if (!Object.prototype.hasOwnProperty.call(data, field)) continue;
|
|
135
|
+
const value = normalizeField(field, data[field]);
|
|
136
|
+
if (value === null && data[field] !== null) continue;
|
|
137
|
+
if (!apply(s.slots[field], value, RANK.page)) continue;
|
|
138
|
+
out.push({ instanceId, event: field, data: eventData(field, s.slots[field].value, false), source: "page", state: snapshotOf(s) });
|
|
139
|
+
}
|
|
140
|
+
return out;
|
|
141
|
+
}
|
|
142
|
+
function documentEnded(instanceId) {
|
|
143
|
+
const s = instances.get(instanceId);
|
|
144
|
+
if (!s) return;
|
|
145
|
+
for (const field of FIELDS) {
|
|
146
|
+
if (s.slots[field].rank === RANK.page) s.slots[field] = { value: null, rank: 0 };
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return {
|
|
150
|
+
host,
|
|
151
|
+
page,
|
|
152
|
+
documentEnded,
|
|
153
|
+
unmounted: (instanceId) => {
|
|
154
|
+
instances.delete(instanceId);
|
|
155
|
+
},
|
|
156
|
+
snapshot: (instanceId) => {
|
|
157
|
+
const s = instances.get(instanceId);
|
|
158
|
+
return s ? snapshotOf(s) : void 0;
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
|
|
1
163
|
// ../../core/sdk/webview/src/dispatcher.ts
|
|
2
164
|
var PAGE_HANDSHAKE_CAPABILITY = "himalaya";
|
|
3
165
|
var PAGE_HANDSHAKE_METHOD = "capabilities";
|
|
4
|
-
var RESERVED_NAMESPACES = /* @__PURE__ */ new Set(["call", "on", "probe", "version", "then", "constructor", "general"]);
|
|
166
|
+
var RESERVED_NAMESPACES = /* @__PURE__ */ new Set(["call", "on", "probe", "version", "then", "constructor", "general", "site"]);
|
|
5
167
|
var UNREACHABLE_SEGMENTS = /* @__PURE__ */ new Set(["then", "toString", "valueOf"]);
|
|
6
168
|
var NAMESPACE_PATTERN = /^[a-z][a-z0-9_]{0,63}$/;
|
|
7
169
|
var METHOD_PATTERN = /^[A-Za-z][A-Za-z0-9_]{0,63}(?:\.[A-Za-z][A-Za-z0-9_]{0,63}){0,3}$/;
|
|
@@ -39,6 +201,8 @@ function createPageDispatcher(runtime2) {
|
|
|
39
201
|
const gone = /* @__PURE__ */ new Set();
|
|
40
202
|
const lifecycleSubscribers = /* @__PURE__ */ new Set();
|
|
41
203
|
const consoleSubscribers = /* @__PURE__ */ new Set();
|
|
204
|
+
const siteSubscribers = /* @__PURE__ */ new Set();
|
|
205
|
+
const site = createSiteEventsStore();
|
|
42
206
|
const instanceAware = () => typeof runtime2.onPageLifecycle === "function";
|
|
43
207
|
const register = runtime2.onPageMessage;
|
|
44
208
|
try {
|
|
@@ -122,6 +286,27 @@ function createPageDispatcher(runtime2) {
|
|
|
122
286
|
consoleSubscribers.delete(cb);
|
|
123
287
|
};
|
|
124
288
|
}
|
|
289
|
+
function subscribeSite(cb) {
|
|
290
|
+
siteSubscribers.add(cb);
|
|
291
|
+
install();
|
|
292
|
+
return () => {
|
|
293
|
+
siteSubscribers.delete(cb);
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
function siteState2(instanceId) {
|
|
297
|
+
install();
|
|
298
|
+
return site.snapshot(instanceOf(instanceId));
|
|
299
|
+
}
|
|
300
|
+
function deliverSite(events) {
|
|
301
|
+
for (const event of events) {
|
|
302
|
+
for (const cb of [...siteSubscribers]) {
|
|
303
|
+
try {
|
|
304
|
+
cb(event);
|
|
305
|
+
} catch {
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
125
310
|
function post(instanceId, msg) {
|
|
126
311
|
if (instanceAware()) runtime2.postToPage(msg, instanceId);
|
|
127
312
|
else if (instanceId === "") runtime2.postToPage(msg);
|
|
@@ -223,6 +408,10 @@ function createPageDispatcher(runtime2) {
|
|
|
223
408
|
const sys = msg && typeof msg === "object" && msg.v === 1 ? msg.sys : void 0;
|
|
224
409
|
if (sys === "cancel") return cancel(instanceId, msg.sid);
|
|
225
410
|
if (sys === "console") return forwardConsole(instanceId, msg);
|
|
411
|
+
if (sys === "site") {
|
|
412
|
+
if (!gone.has(instanceId)) deliverSite(site.page(msg, instanceId));
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
226
415
|
const dead = gone.has(instanceId);
|
|
227
416
|
if (!dead) live.add(instanceId);
|
|
228
417
|
const request = exposed.size > 0 || namespaces.size > 0 ? pageRequest(msg) : null;
|
|
@@ -394,6 +583,11 @@ function createPageDispatcher(runtime2) {
|
|
|
394
583
|
}
|
|
395
584
|
}
|
|
396
585
|
const e = envelope;
|
|
586
|
+
if (e && typeof e === "object" && e.v === 1 && e.sys === "site") {
|
|
587
|
+
const siteInstance = typeof stamped === "string" ? stamped : instanceOf(e.iid);
|
|
588
|
+
if (!gone.has(siteInstance)) deliverSite(site.host(e, siteInstance));
|
|
589
|
+
return;
|
|
590
|
+
}
|
|
397
591
|
if (!e || typeof e !== "object" || e.v !== 1 || e.sys !== "lifecycle" || typeof e.state !== "string") return;
|
|
398
592
|
const instanceId = typeof stamped === "string" ? stamped : instanceOf(e.iid);
|
|
399
593
|
switch (e.state) {
|
|
@@ -419,9 +613,11 @@ function createPageDispatcher(runtime2) {
|
|
|
419
613
|
case "crashed":
|
|
420
614
|
crashed.add(instanceId);
|
|
421
615
|
endDocument(instanceId);
|
|
616
|
+
site.documentEnded(instanceId);
|
|
422
617
|
break;
|
|
423
618
|
case "reloaded":
|
|
424
619
|
if (!crashed.delete(instanceId)) endDocument(instanceId);
|
|
620
|
+
site.documentEnded(instanceId);
|
|
425
621
|
break;
|
|
426
622
|
case "unmounted":
|
|
427
623
|
unmount(instanceId);
|
|
@@ -451,6 +647,7 @@ function createPageDispatcher(runtime2) {
|
|
|
451
647
|
gone.add(instanceId);
|
|
452
648
|
crashed.delete(instanceId);
|
|
453
649
|
endDocument(instanceId);
|
|
650
|
+
site.unmounted(instanceId);
|
|
454
651
|
}
|
|
455
652
|
return {
|
|
456
653
|
runtime: runtime2,
|
|
@@ -462,6 +659,8 @@ function createPageDispatcher(runtime2) {
|
|
|
462
659
|
addNamespace,
|
|
463
660
|
subscribeLifecycle,
|
|
464
661
|
subscribeConsole,
|
|
662
|
+
subscribeSite,
|
|
663
|
+
siteState: siteState2,
|
|
465
664
|
post,
|
|
466
665
|
emit,
|
|
467
666
|
openStream
|
|
@@ -518,6 +717,12 @@ function onPageLifecycle(cb) {
|
|
|
518
717
|
function onPageConsole(cb) {
|
|
519
718
|
return dispatcher().subscribeConsole(cb);
|
|
520
719
|
}
|
|
720
|
+
function onSiteEvent(cb) {
|
|
721
|
+
return dispatcher().subscribeSite(cb);
|
|
722
|
+
}
|
|
723
|
+
function siteState(instanceId) {
|
|
724
|
+
return dispatcher().siteState(instanceId);
|
|
725
|
+
}
|
|
521
726
|
function exposeCapabilitiesToPage(capabilities) {
|
|
522
727
|
dispatcher().expose(capabilities);
|
|
523
728
|
}
|
|
@@ -531,8 +736,10 @@ export {
|
|
|
531
736
|
onPageLifecycle,
|
|
532
737
|
onPageMessage,
|
|
533
738
|
onPageRequest,
|
|
739
|
+
onSiteEvent,
|
|
534
740
|
openPageStream,
|
|
535
741
|
postToPage,
|
|
742
|
+
siteState,
|
|
536
743
|
version
|
|
537
744
|
};
|
|
538
745
|
//# sourceMappingURL=webview.mjs.map
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"files": [
|
|
3
3
|
{
|
|
4
4
|
"name": "sw.js",
|
|
5
|
-
"bytes":
|
|
5
|
+
"bytes": 2544442
|
|
6
6
|
},
|
|
7
7
|
{
|
|
8
8
|
"name": "host.html",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"bytes": 23064
|
|
22
22
|
},
|
|
23
23
|
{
|
|
24
|
-
"name": "preview-deferred/
|
|
24
|
+
"name": "preview-deferred/beb47fb3bdf1fe461bde8322263c72e10006079380c5551599c470308b4d3e31.bin",
|
|
25
25
|
"bytes": 488215
|
|
26
26
|
},
|
|
27
27
|
{
|
|
@@ -79,10 +79,10 @@
|
|
|
79
79
|
],
|
|
80
80
|
"deferred": [
|
|
81
81
|
{
|
|
82
|
-
"key": "assets/pdf-
|
|
82
|
+
"key": "assets/pdf-BuGHh8Xx.js",
|
|
83
83
|
"contentType": "application/javascript; charset=utf-8",
|
|
84
|
-
"sha256": "
|
|
85
|
-
"file": "preview-deferred/
|
|
84
|
+
"sha256": "beb47fb3bdf1fe461bde8322263c72e10006079380c5551599c470308b4d3e31",
|
|
85
|
+
"file": "preview-deferred/beb47fb3bdf1fe461bde8322263c72e10006079380c5551599c470308b4d3e31.bin"
|
|
86
86
|
},
|
|
87
87
|
{
|
|
88
88
|
"key": "assets/pdf.worker.min-BGnVRhRG.js",
|