@gramlot/gramlot 0.2.16 → 0.2.18
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/assets/branding/app-icon.png +0 -0
- package/dist/gramlot.js +1413 -235
- package/dist/gramlot.min.js +74 -17
- package/package.json +9 -5
- package/src/binding/ask-dialog.js +108 -0
- package/src/binding/providers.js +41 -6
- package/src/binding/remote.js +19 -20
- package/src/binding/runtime.js +38 -2
- package/src/builder/gramlot-builder.js +21 -3
- package/src/builder/source.js +18 -5
- package/src/builder/webcomponent.json +51 -0
- package/src/frame-messages.js +177 -0
- package/src/gramlot.d.ts +14 -0
- package/src/gramlot.js +9 -1
- package/src/handlers/rpc-handler.js +2 -0
- package/src/handlers/source-handler.js +1 -0
- package/src/handlers/subscriptions-handler.js +103 -0
- package/src/index-page-runtime.d.ts +11 -0
- package/src/index-page-runtime.js +287 -0
- package/src/index-page-styles.js +2 -0
- package/src/index-theme.js +5 -0
- package/src/index.d.ts +4 -1
- package/src/index.js +3 -0
- package/src/inout.js +3 -1
- package/src/references.d.ts +5 -0
- package/src/references.js +23 -1
- package/src/renderer/attributes.js +14 -3
- package/src/renderer/gramlot-html-renderer.js +9 -2
- package/src/renderer/gramlot-renderer.js +5 -1
- package/src/renderer/gramlot-svg-renderer.js +2 -1
- package/src/server/conformance.js +22 -2
- package/src/server/gramlot-server.d.ts +1 -0
- package/src/server/gramlot-server.js +12 -0
- package/src/server/index-page.d.ts +14 -0
- package/src/server/index-page.js +102 -0
- package/src/server/page-base.js +88 -0
- package/src/server/page.d.ts +8 -2
- package/src/server/page.js +3 -76
- package/src/view/button.js +17 -3
- package/src/view/html.js +4 -3
- package/src/webcomponent.js +13 -0
- package/themes/gramlot-base/README.md +8 -0
- package/themes/gramlot-compact/README.md +49 -0
- package/themes/gramlot-compact/theme.css +57 -0
- package/themes/gramlot-index/theme.css +51 -0
- package/tools/gramlot-tools-inspector.js +1733 -0
- package/tools/inspector-agent.js +252 -0
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import {toTytx, fromTytx} from '@genrojs/tytx';
|
|
2
|
+
import {SourceBagNode, sourceTarget} from '@genrojs/builders';
|
|
3
|
+
import {assertTransportData} from './references.js';
|
|
4
|
+
|
|
5
|
+
const TYPE = 'gramlot:publish';
|
|
6
|
+
|
|
7
|
+
/** Direct parent/child transport. Every message crosses postMessage, even same-origin. */
|
|
8
|
+
export class FrameMessages {
|
|
9
|
+
#app;
|
|
10
|
+
#window;
|
|
11
|
+
#document;
|
|
12
|
+
#session = Array.from(crypto.getRandomValues(new Uint8Array(16)), byte => byte.toString(16).padStart(2, '0')).join('');
|
|
13
|
+
#peers = new Map();
|
|
14
|
+
#closed = false;
|
|
15
|
+
#listener;
|
|
16
|
+
#load;
|
|
17
|
+
#hide;
|
|
18
|
+
#show;
|
|
19
|
+
|
|
20
|
+
constructor(app, document) {
|
|
21
|
+
this.#app = app;
|
|
22
|
+
this.#document = document;
|
|
23
|
+
this.#window = document.defaultView;
|
|
24
|
+
this.#listener = event => this.#receive(event);
|
|
25
|
+
this.#load = event => {
|
|
26
|
+
if (event.target?.localName !== 'iframe') return;
|
|
27
|
+
const peer = this.#child(event.target);
|
|
28
|
+
if (!peer) return;
|
|
29
|
+
this.#forget(peer.window);
|
|
30
|
+
this.#send(peer, {kind: 'hello'});
|
|
31
|
+
};
|
|
32
|
+
this.#window.addEventListener('message', this.#listener);
|
|
33
|
+
this.#hide = () => this.#disconnect();
|
|
34
|
+
this.#show = () => this.ready();
|
|
35
|
+
this.#window.addEventListener('pagehide', this.#hide);
|
|
36
|
+
this.#window.addEventListener('pageshow', this.#show);
|
|
37
|
+
document.addEventListener('load', this.#load, true);
|
|
38
|
+
const parent = this.#parent();
|
|
39
|
+
if (parent) this.#send(parent, {kind: 'hello'});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
ready() {
|
|
43
|
+
if (this.#closed || this.#app.state !== 'started') return;
|
|
44
|
+
const parent = this.#parent();
|
|
45
|
+
if (parent) this.#send(parent, {kind: 'ready'});
|
|
46
|
+
for (const frame of this.#document.getElementsByTagName('iframe')) {
|
|
47
|
+
const child = this.#child(frame);
|
|
48
|
+
if (child) this.#send(child, {kind: 'hello'});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Preflight before local dispatch: no queue or silent fallback for an unavailable page. */
|
|
53
|
+
prepare(descriptor, payload) {
|
|
54
|
+
const peers = [];
|
|
55
|
+
if (descriptor.parent) {
|
|
56
|
+
const parent = this.#parent();
|
|
57
|
+
if (!parent) throw new Error('This page has no parent frame');
|
|
58
|
+
peers.push(parent);
|
|
59
|
+
}
|
|
60
|
+
if (descriptor.iframe !== undefined) {
|
|
61
|
+
const target = descriptor.iframe;
|
|
62
|
+
const node = sourceTarget(target);
|
|
63
|
+
const frame = typeof target === 'string'
|
|
64
|
+
? this.#document.getElementById(target)
|
|
65
|
+
: node instanceof SourceBagNode ? this.#app.dom.getDomNode(node) : null;
|
|
66
|
+
const child = this.#child(frame);
|
|
67
|
+
if (!child) throw new Error('iframe destination must be an active Gramlot iframe ID or Source reference');
|
|
68
|
+
peers.push(child);
|
|
69
|
+
}
|
|
70
|
+
const destinations = peers.map(peer => {
|
|
71
|
+
const connection = this.#peers.get(peer.window);
|
|
72
|
+
if (!connection || connection.origin !== peer.origin) throw new Error('Destination page is not ready');
|
|
73
|
+
return {...peer, session: connection.session};
|
|
74
|
+
});
|
|
75
|
+
assertTransportData(payload);
|
|
76
|
+
const wire = toTytx(payload);
|
|
77
|
+
return () => {
|
|
78
|
+
if (this.#closed) return;
|
|
79
|
+
for (const peer of destinations) {
|
|
80
|
+
const current = this.#peer(peer.window);
|
|
81
|
+
if (!current || current.origin !== peer.origin || this.#peers.get(peer.window)?.session !== peer.session) {
|
|
82
|
+
throw new Error('Destination page disconnected before publication');
|
|
83
|
+
}
|
|
84
|
+
this.#send(peer, {kind: 'publish', recipient: peer.session, topic: descriptor.topic, wire});
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
dispose() {
|
|
90
|
+
if (this.#closed) return;
|
|
91
|
+
this.#disconnect();
|
|
92
|
+
this.#closed = true;
|
|
93
|
+
this.#window.removeEventListener('message', this.#listener);
|
|
94
|
+
this.#window.removeEventListener('pagehide', this.#hide);
|
|
95
|
+
this.#window.removeEventListener('pageshow', this.#show);
|
|
96
|
+
this.#document.removeEventListener('load', this.#load, true);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
#disconnect() {
|
|
100
|
+
for (const [window, peer] of this.#peers) this.#send({window, origin: peer.origin}, {kind: 'close'});
|
|
101
|
+
for (const window of this.#peers.keys()) this.#forget(window);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
#forget(window) {
|
|
105
|
+
this.#peers.get(window)?.release?.();
|
|
106
|
+
this.#peers.delete(window);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
#remember(peer, session) {
|
|
110
|
+
this.#forget(peer.window);
|
|
111
|
+
const connection = {session, origin: peer.origin};
|
|
112
|
+
if (peer.node) connection.release = this.#app.src.binding.bindingFor(peer.node).track(() => {
|
|
113
|
+
this.#send(peer, {kind: 'close'});
|
|
114
|
+
this.#forget(peer.window);
|
|
115
|
+
});
|
|
116
|
+
this.#peers.set(peer.window, connection);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
#receive(event) {
|
|
120
|
+
if (this.#closed || event.data?.type !== TYPE) return;
|
|
121
|
+
const peer = this.#peer(event.source);
|
|
122
|
+
if (!peer || event.origin !== peer.origin) return;
|
|
123
|
+
const message = event.data;
|
|
124
|
+
if (typeof message.session !== 'string' || !message.session) return;
|
|
125
|
+
if (message.kind === 'hello') {
|
|
126
|
+
this.#forget(peer.window);
|
|
127
|
+
if (message.ready === true) this.#remember(peer, message.session);
|
|
128
|
+
if (this.#app.state === 'started') this.#send(peer, {kind: 'ready'});
|
|
129
|
+
} else if (message.kind === 'ready') {
|
|
130
|
+
const changed = this.#peers.get(peer.window)?.session !== message.session;
|
|
131
|
+
this.#remember(peer, message.session);
|
|
132
|
+
if (changed && this.#app.state === 'started') this.#send(peer, {kind: 'ready'});
|
|
133
|
+
} else if (message.kind === 'close') {
|
|
134
|
+
if (this.#peers.get(peer.window)?.session === message.session) this.#forget(peer.window);
|
|
135
|
+
} else if (message.kind === 'publish') {
|
|
136
|
+
if (this.#app.state !== 'started' || message.recipient !== this.#session
|
|
137
|
+
|| this.#peers.get(peer.window)?.session !== message.session) return;
|
|
138
|
+
if (typeof message.topic !== 'string' || !message.topic || typeof message.wire !== 'string') return;
|
|
139
|
+
// Dispatch only in this receiving page; never retransmit the routing descriptor.
|
|
140
|
+
this.#app.publish(message.topic, fromTytx(message.wire));
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
#send(peer, message) {
|
|
145
|
+
peer.window.postMessage({type: TYPE, session: this.#session, ready: this.#app.state === 'started', ...message}, peer.origin === 'null' ? '*' : peer.origin);
|
|
146
|
+
}
|
|
147
|
+
#parent() {
|
|
148
|
+
const parent = this.#window.parent;
|
|
149
|
+
if (parent === this.#window) return null;
|
|
150
|
+
return {window: parent, origin: this.#origin(this.#document.referrer || this.#document.baseURI)};
|
|
151
|
+
}
|
|
152
|
+
#child(frame) {
|
|
153
|
+
if (frame?.localName !== 'iframe' || !frame.isConnected || !frame.contentWindow) return null;
|
|
154
|
+
const node = this.#app.dom.getBaseSourceNode(frame);
|
|
155
|
+
if (!node || !this.#app.src.binding.bindingFor(node)
|
|
156
|
+
|| this.#app.dom.getDomNode(node) !== frame) return null;
|
|
157
|
+
const sandbox = frame.getAttribute('sandbox');
|
|
158
|
+
const opaque = sandbox !== null && !sandbox.split(/\s+/).includes('allow-same-origin');
|
|
159
|
+
const origin = opaque ? 'null' : this.#origin(frame.hasAttribute('srcdoc')
|
|
160
|
+
? this.#document.baseURI : frame.getAttribute('src') || this.#document.baseURI);
|
|
161
|
+
return {window: frame.contentWindow, origin, node};
|
|
162
|
+
}
|
|
163
|
+
#origin(address) {
|
|
164
|
+
const url = new URL(address, this.#document.baseURI);
|
|
165
|
+
// Chromium's URL.origin can be file://, while MessageEvent.origin is null.
|
|
166
|
+
return url.protocol === 'file:' ? 'null' : url.origin;
|
|
167
|
+
}
|
|
168
|
+
#peer(window) {
|
|
169
|
+
const parent = this.#parent();
|
|
170
|
+
if (parent?.window === window) return parent;
|
|
171
|
+
for (const frame of this.#document.getElementsByTagName('iframe')) {
|
|
172
|
+
const child = this.#child(frame);
|
|
173
|
+
if (child?.window === window) return child;
|
|
174
|
+
}
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
}
|
package/src/gramlot.d.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import type {DomElement, DomDocument, DomEvent, DomWindow} from './dom.d.ts';
|
|
7
7
|
import type {Bag} from '@genrojs/bag';
|
|
8
|
+
import type {SourceBagNode} from '@genrojs/builders';
|
|
8
9
|
import type {RpcTransport} from './handlers/rpc-handler.js';
|
|
9
10
|
import type {SourceHandler} from './handlers/source-handler.js';
|
|
10
11
|
import type {RpcHandler} from './handlers/rpc-handler.js';
|
|
@@ -36,6 +37,13 @@ export interface GramlotOptions {
|
|
|
36
37
|
/** The lifecycle state of a `Gramlot` instance. */
|
|
37
38
|
export type GramlotState = 'ready' | 'loading' | 'started' | 'failed' | 'disposed';
|
|
38
39
|
|
|
40
|
+
/** Opaque registration returned by subscribe; meaningful only to its owning page. */
|
|
41
|
+
export interface SubscriptionHandle { readonly __subscriptionHandle: unique symbol; }
|
|
42
|
+
|
|
43
|
+
/** Legacy-shaped publication. Frame forwarding follows synchronous local delivery. */
|
|
44
|
+
export type Publication = string | {topic: string; nodeId: string} |
|
|
45
|
+
{topic: string; parent?: boolean; iframe?: string | SourceBagNode};
|
|
46
|
+
|
|
39
47
|
/** One Gramlot page: lifecycle, Data and the four proxies `src`, `rpc`, `dom`, `utl`. */
|
|
40
48
|
export class Gramlot {
|
|
41
49
|
/** The id of the server page. */
|
|
@@ -66,6 +74,12 @@ export class Gramlot {
|
|
|
66
74
|
pagehide?: (event: DomEvent) => void;
|
|
67
75
|
/** Create the page instance; the construction order is the one of the source plan. */
|
|
68
76
|
constructor(options?: GramlotOptions);
|
|
77
|
+
/** Publish one named payload; forwarding uses postMessage and requires a ready page. */
|
|
78
|
+
publish(topic: Publication, payload?: Record<string, unknown>): void;
|
|
79
|
+
/** Subscribe to a local page topic, synchronously in registration order. */
|
|
80
|
+
subscribe(topic: string, callback: (payload: Record<string, unknown>) => unknown): SubscriptionHandle;
|
|
81
|
+
/** Remove a registration; repeating removal of an owned handle is harmless. */
|
|
82
|
+
unsubscribe(registration: SubscriptionHandle): void;
|
|
69
83
|
/** Load `main` from the server and mount it; resolves with the instance. */
|
|
70
84
|
start(): Promise<Gramlot>;
|
|
71
85
|
/** Request `main` from the transport and mount it. */
|
package/src/gramlot.js
CHANGED
|
@@ -8,6 +8,7 @@ import {HttpTransport} from './http-transport.js';
|
|
|
8
8
|
import {SourceHandler} from './handlers/source-handler.js';
|
|
9
9
|
import {RpcHandler} from './handlers/rpc-handler.js';
|
|
10
10
|
import {DomHandler} from './handlers/dom-handler.js';
|
|
11
|
+
import {SubscriptionsHandler} from './handlers/subscriptions-handler.js';
|
|
11
12
|
import {UtilitiesHandler} from './handlers/utilities-handler.js';
|
|
12
13
|
|
|
13
14
|
/**
|
|
@@ -16,8 +17,9 @@ import {UtilitiesHandler} from './handlers/utilities-handler.js';
|
|
|
16
17
|
*/
|
|
17
18
|
export class Gramlot {
|
|
18
19
|
constructor({pageId, rpcUrl = '/gramlot/rpc', closeUrl = '/gramlot/close', rootId = 'gramlot-root', capabilities = [],
|
|
19
|
-
element = null, document = globalThis.document, transport = null, collections = []} = {}) {
|
|
20
|
+
element = null, document = element?.ownerDocument ?? globalThis.document, transport = null, collections = []} = {}) {
|
|
20
21
|
this.pageId = pageId;
|
|
22
|
+
Object.defineProperty(this, '_subscriptions', {value: new SubscriptionsHandler(this)});
|
|
21
23
|
this.capabilities = Object.freeze([...capabilities]);
|
|
22
24
|
this.src = new SourceHandler(this, {collections, destination: element ?? document.getElementById(rootId)});
|
|
23
25
|
this.data = this.src.builder.data;
|
|
@@ -25,6 +27,7 @@ export class Gramlot {
|
|
|
25
27
|
this.dom = new DomHandler(this);
|
|
26
28
|
this.utl = new UtilitiesHandler(this, document);
|
|
27
29
|
this.state = 'ready';
|
|
30
|
+
this._subscriptions.attach(document);
|
|
28
31
|
this.abort = new AbortController();
|
|
29
32
|
if (this.rpc.transport instanceof HttpTransport) {
|
|
30
33
|
this.pagehide = event => { if (!event.persisted) this.dispose({beacon: true}); };
|
|
@@ -32,6 +35,10 @@ export class Gramlot {
|
|
|
32
35
|
this.window = document.defaultView;
|
|
33
36
|
}
|
|
34
37
|
}
|
|
38
|
+
publish(topic, payload = {}) { return this._subscriptions.publish(topic, payload); }
|
|
39
|
+
subscribe(topic, callback) { return this._subscriptions.subscribe(topic, callback); }
|
|
40
|
+
unsubscribe(registration) { this._subscriptions.unsubscribe(registration); }
|
|
41
|
+
|
|
35
42
|
start() {
|
|
36
43
|
if (this.state === 'disposed') return Promise.reject(new Error('Gramlot is disposed'));
|
|
37
44
|
if (!this.rpc.transport) return Promise.reject(new Error('This Gramlot instance has no server transport'));
|
|
@@ -54,6 +61,7 @@ export class Gramlot {
|
|
|
54
61
|
dispose({beacon = false} = {}) {
|
|
55
62
|
if (this.state === 'disposed') return;
|
|
56
63
|
this.state = 'disposed';
|
|
64
|
+
this._subscriptions.dispose();
|
|
57
65
|
if (this.pagehide) this.window.removeEventListener('pagehide', this.pagehide);
|
|
58
66
|
this.abort.abort();
|
|
59
67
|
for (const request of this.rpc.remoteRequests.values()) request.controller.abort();
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
import {fromTytx, toTytx} from '@genrojs/tytx';
|
|
8
8
|
import {Handler} from './handler.js';
|
|
9
9
|
import {HttpTransport} from '../http-transport.js';
|
|
10
|
+
import {assertTransportData} from '../references.js';
|
|
10
11
|
|
|
11
12
|
/** A request id: 16 random bytes as 32 hex characters; getRandomValues, unlike randomUUID,
|
|
12
13
|
* exists outside secure contexts too. */
|
|
@@ -35,6 +36,7 @@ export class RpcHandler extends Handler {
|
|
|
35
36
|
/** Send one envelope of `contentType` to `name` with `params`; resolves with the value or rejects with an RpcError. */
|
|
36
37
|
async call(contentType, name, params = {}, {signal} = {}) {
|
|
37
38
|
if (!this.transport?.call) throw new Error(`rpc '${name}' is unavailable without a server transport`);
|
|
39
|
+
assertTransportData(params);
|
|
38
40
|
const id = requestId();
|
|
39
41
|
const text = toTytx({id, pageId: this.gramlot.pageId, contentType, name, params});
|
|
40
42
|
const response = fromTytx(await this.transport.call(text, signal));
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import {FrameMessages} from '../frame-messages.js';
|
|
2
|
+
import {Handler} from './handler.js';
|
|
3
|
+
import {sourceTarget} from '@genrojs/builders';
|
|
4
|
+
|
|
5
|
+
/** Page topics and Source self-topics. Owned privately by one Gramlot instance. */
|
|
6
|
+
export class SubscriptionsHandler extends Handler {
|
|
7
|
+
#topics = new Map();
|
|
8
|
+
#handles = new WeakSet();
|
|
9
|
+
#nodeIds = new WeakMap();
|
|
10
|
+
#sequence = 0;
|
|
11
|
+
#closed = false;
|
|
12
|
+
#frames;
|
|
13
|
+
|
|
14
|
+
attach(document) { this.#frames = new FrameMessages(this.gramlot, document); }
|
|
15
|
+
ready() { this.#frames.ready(); }
|
|
16
|
+
|
|
17
|
+
subscribe(topic, callback) {
|
|
18
|
+
this.#requireOpen();
|
|
19
|
+
this.#requireTopic(topic);
|
|
20
|
+
if (typeof callback !== 'function') throw new TypeError('subscribe requires a callback');
|
|
21
|
+
const handle = Object.freeze({});
|
|
22
|
+
this.#handles.add(handle);
|
|
23
|
+
if (!this.#topics.has(topic)) this.#topics.set(topic, new Map());
|
|
24
|
+
this.#topics.get(topic).set(handle, callback);
|
|
25
|
+
return handle;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
unsubscribe(handle) {
|
|
29
|
+
if (!this.#handles.has(handle)) throw new TypeError('Unknown subscription registration');
|
|
30
|
+
for (const [topic, callbacks] of this.#topics) {
|
|
31
|
+
if (callbacks.delete(handle) && !callbacks.size) this.#topics.delete(topic);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
publish(topic, payload = {}) {
|
|
36
|
+
this.#requireOpen();
|
|
37
|
+
if (!payload || typeof payload !== 'object' || Array.isArray(payload)) {
|
|
38
|
+
throw new TypeError('publish requires one object of named data');
|
|
39
|
+
}
|
|
40
|
+
if (typeof topic === 'string') return this.#deliver(topic, payload);
|
|
41
|
+
if (!topic || typeof topic !== 'object' || Array.isArray(topic)) {
|
|
42
|
+
throw new TypeError('publish requires a topic string or descriptor');
|
|
43
|
+
}
|
|
44
|
+
const keys = Object.keys(topic);
|
|
45
|
+
if (keys.some(key => !['topic', 'nodeId', 'parent', 'iframe'].includes(key))) {
|
|
46
|
+
throw new Error('This publication route is not implemented yet');
|
|
47
|
+
}
|
|
48
|
+
this.#requireTopic(topic.topic);
|
|
49
|
+
if (topic.parent !== undefined && typeof topic.parent !== 'boolean') throw new TypeError('parent must be boolean');
|
|
50
|
+
if (topic.iframe === '*') throw new Error('Recursive iframe broadcast is not implemented yet');
|
|
51
|
+
if ((topic.parent || topic.iframe !== undefined) && Object.hasOwn(topic, 'nodeId')) {
|
|
52
|
+
throw new Error('Interframe node addressing is not implemented yet');
|
|
53
|
+
}
|
|
54
|
+
const forward = topic.parent || topic.iframe !== undefined ? this.#frames.prepare(topic, payload) : null;
|
|
55
|
+
if (Object.hasOwn(topic, 'nodeId')) {
|
|
56
|
+
const node = this.gramlot.src.binding.nodeIds.get(topic.nodeId);
|
|
57
|
+
if (!node) throw new Error(`node_id not found: ${topic.nodeId}`);
|
|
58
|
+
return this.publishNode(node, topic.topic, payload);
|
|
59
|
+
}
|
|
60
|
+
this.#deliver(topic.topic, payload);
|
|
61
|
+
forward?.();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
topicFor(node, topic) {
|
|
65
|
+
this.#requireTopic(topic);
|
|
66
|
+
node = sourceTarget(node);
|
|
67
|
+
const binding = this.gramlot.src.binding.bindingFor(node);
|
|
68
|
+
if (!binding || binding.closed) throw new Error('Topic target is not an active Source node of this page');
|
|
69
|
+
let id = node.getAttr('node_id');
|
|
70
|
+
if (id == null) {
|
|
71
|
+
if (!this.#nodeIds.has(node)) this.#nodeIds.set(node, `gramlot-self-${++this.#sequence}`);
|
|
72
|
+
id = this.#nodeIds.get(node);
|
|
73
|
+
}
|
|
74
|
+
return `${id}_${topic}`;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
publishNode(node, topic, payload = {}) {
|
|
78
|
+
return this.publish(this.topicFor(node, topic), payload);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
dispose() {
|
|
82
|
+
this.#closed = true;
|
|
83
|
+
this.#frames.dispose();
|
|
84
|
+
this.#topics.clear();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
#deliver(topic, payload) {
|
|
88
|
+
this.#requireTopic(topic);
|
|
89
|
+
const callbacks = this.#topics.get(topic);
|
|
90
|
+
if (!callbacks) return;
|
|
91
|
+
// Synchronous, ordered, no retention/equality suppression; exceptions propagate.
|
|
92
|
+
for (const [handle, callback] of [...callbacks]) {
|
|
93
|
+
if (this.#closed) break;
|
|
94
|
+
if (callbacks.has(handle)) callback(payload);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
#requireTopic(topic) {
|
|
98
|
+
if (typeof topic !== 'string' || !topic) throw new TypeError('A topic must be a nonempty string');
|
|
99
|
+
}
|
|
100
|
+
#requireOpen() {
|
|
101
|
+
if (this.#closed) throw new Error('Gramlot subscriptions are disposed');
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export function mountIndexPage(renderer: any, root: any,
|
|
2
|
+
onSelection?: (entries: Map<string, any>, active: string) => void,
|
|
3
|
+
prepareEntry?: (entry: any, context: any) => void): {dispose(): void};
|
|
4
|
+
/** Re-export as Logic, or delegate indexMount from an application's Logic. */
|
|
5
|
+
export class IndexLogic {
|
|
6
|
+
indexMount(node: any, args: {shell_id: string}): void;
|
|
7
|
+
}
|
|
8
|
+
export const THEME_READY: string;
|
|
9
|
+
export const THEME_SET: string;
|
|
10
|
+
export const THEMES: Set<string>;
|
|
11
|
+
export const APPEARANCES: Set<string>;
|