@peers-app/peers-ui 0.33.24 → 0.34.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/command-palette/command-palette.js +4 -2
- package/dist/components/router.d.ts +1 -0
- package/dist/components/router.js +4 -1
- package/dist/host-shell/host-shell-consumer.js +8 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +7 -1
- package/dist/isolated-screens/config.d.ts +51 -0
- package/dist/isolated-screens/config.js +73 -0
- package/dist/isolated-screens/frame-autostart.d.ts +1 -0
- package/dist/isolated-screens/frame-autostart.js +18 -0
- package/dist/isolated-screens/frame-bridge.d.ts +30 -0
- package/dist/isolated-screens/frame-bridge.js +113 -0
- package/dist/isolated-screens/frame-component.d.ts +6 -0
- package/dist/isolated-screens/frame-component.js +20 -0
- package/dist/isolated-screens/frame-document.d.ts +26 -0
- package/dist/isolated-screens/frame-document.js +69 -0
- package/dist/isolated-screens/frame-policy.d.ts +17 -0
- package/dist/isolated-screens/frame-policy.js +230 -0
- package/dist/isolated-screens/frame-protocol.d.ts +185 -0
- package/dist/isolated-screens/frame-protocol.js +139 -0
- package/dist/isolated-screens/frame-pvars.d.ts +33 -0
- package/dist/isolated-screens/frame-pvars.js +152 -0
- package/dist/isolated-screens/frame-realm.d.ts +12 -0
- package/dist/isolated-screens/frame-realm.js +31 -0
- package/dist/isolated-screens/frame-runtime.d.ts +5 -0
- package/dist/isolated-screens/frame-runtime.js +416 -0
- package/dist/isolated-screens/frame-storage.d.ts +43 -0
- package/dist/isolated-screens/frame-storage.js +85 -0
- package/dist/isolated-screens/index.d.ts +3 -0
- package/dist/isolated-screens/index.js +13 -0
- package/dist/isolated-screens/isolated-screen.d.ts +191 -0
- package/dist/isolated-screens/isolated-screen.js +684 -0
- package/dist/isolated-screens/piece-frames.d.ts +27 -0
- package/dist/isolated-screens/piece-frames.js +311 -0
- package/dist/isolated-screens/piece-reach.d.ts +11 -0
- package/dist/isolated-screens/piece-reach.js +56 -0
- package/dist/isolated-screens/port-channel.d.ts +47 -0
- package/dist/isolated-screens/port-channel.js +153 -0
- package/dist/isolated-screens/routes-sandbox.d.ts +8 -0
- package/dist/isolated-screens/routes-sandbox.js +130 -0
- package/dist/isolated-screens/screen-tab-context.d.ts +4 -0
- package/dist/isolated-screens/screen-tab-context.js +6 -0
- package/dist/isolated-screens/test-ports.d.ts +3 -0
- package/dist/isolated-screens/test-ports.js +21 -0
- package/dist/mentions/mentions-client.js +9 -0
- package/dist/notifications/index.js +9 -5
- package/dist/operator-console/console-copy.d.ts +15 -0
- package/dist/operator-console/console-copy.js +97 -0
- package/dist/operator-console/console-header.d.ts +33 -0
- package/dist/operator-console/console-header.js +67 -0
- package/dist/operator-console/console-input.d.ts +20 -0
- package/dist/operator-console/console-input.js +313 -0
- package/dist/operator-console/console-repl.d.ts +7 -0
- package/dist/operator-console/console-repl.js +108 -0
- package/dist/operator-console/console-scope.d.ts +45 -0
- package/dist/operator-console/console-scope.js +174 -0
- package/dist/operator-console/console-screen.d.ts +8 -0
- package/dist/operator-console/console-screen.js +32 -0
- package/dist/operator-console/console-session.d.ts +106 -0
- package/dist/operator-console/console-session.js +567 -0
- package/dist/operator-console/console-test-host.d.ts +21 -0
- package/dist/operator-console/console-test-host.js +114 -0
- package/dist/operator-console/console-theme.d.ts +41 -0
- package/dist/operator-console/console-theme.js +55 -0
- package/dist/operator-console/console-value.d.ts +27 -0
- package/dist/operator-console/console-value.js +291 -0
- package/dist/operator-console/operator-console-state.js +3 -1
- package/dist/operator-console/operator-console.d.ts +8 -21
- package/dist/operator-console/operator-console.js +8 -61
- package/dist/root-layout/app-shell-height.d.ts +16 -3
- package/dist/root-layout/app-shell-height.js +17 -4
- package/dist/root-layout/host-app-menu.d.ts +17 -0
- package/dist/root-layout/host-app-menu.js +22 -0
- package/dist/root-layout/layouts/full-screen-layout.js +4 -2
- package/dist/system-apps/console.app.d.ts +15 -0
- package/dist/system-apps/console.app.js +25 -0
- package/dist/system-apps/index.d.ts +1 -0
- package/dist/system-apps/index.js +6 -1
- package/dist/tabs-layout/tabs-layout.js +12 -20
- package/dist/tabs-layout/tabs-state.js +39 -16
- package/dist/theme.css +32 -5
- package/dist/ui-contracts/piece-height.d.ts +18 -0
- package/dist/ui-contracts/piece-height.js +15 -0
- package/dist/ui-contracts/piece-host.d.ts +24 -1
- package/dist/ui-contracts/piece-host.js +53 -2
- package/dist/ui-contracts/piece-props.d.ts +16 -0
- package/dist/ui-contracts/piece-props.js +39 -0
- package/dist/ui-contracts/piece-resolution.d.ts +5 -0
- package/dist/ui-contracts/piece-resolution.js +38 -2
- package/dist/ui-contracts/piece.d.ts +2 -7
- package/dist/ui-contracts/piece.js +22 -37
- package/dist/ui-contracts/popover-surface.d.ts +14 -0
- package/dist/ui-contracts/popover-surface.js +32 -3
- package/dist/ui-inspection/dom-actions.d.ts +23 -0
- package/dist/ui-inspection/dom-actions.js +169 -0
- package/dist/ui-inspection/dom-inspector.d.ts +20 -0
- package/dist/ui-inspection/dom-inspector.js +184 -0
- package/dist/ui-inspection/index.d.ts +73 -0
- package/dist/ui-inspection/index.js +147 -0
- package/dist/ui-router/find-route.d.ts +6 -0
- package/dist/ui-router/find-route.js +22 -0
- package/dist/ui-router/routes-loader.js +23 -4
- package/dist/ui-router/runnable-version.js +3 -0
- package/dist/ui-router/ui-loader.d.ts +6 -1
- package/dist/ui-router/ui-loader.js +102 -26
- package/package.json +3 -3
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SCREEN_READABLE_PVARS = void 0;
|
|
4
|
+
exports.createFrameRpc = createFrameRpc;
|
|
5
|
+
const peers_sdk_1 = require("@peers-app/peers-sdk");
|
|
6
|
+
const lodash_1 = require("lodash");
|
|
7
|
+
/**
|
|
8
|
+
* What an isolated package screen may do through the legacy RPC surface (`rpcServerCalls`).
|
|
9
|
+
*
|
|
10
|
+
* In the shared window every screen had all of it: any method of any table in any context,
|
|
11
|
+
* `dbQuery`, `encryptData`, other devices' tools. A screen in a frame keeps only what screens
|
|
12
|
+
* still read that way, until those reads move to contracts:
|
|
13
|
+
*
|
|
14
|
+
* - **Reads** (`get`, `list`, `count`, `findOne`) of the tables screens use to know the user's
|
|
15
|
+
* groups, members, contacts, devices and installed packages.
|
|
16
|
+
* - **Its own package's tables,** read and written, as the legacy table API lets its own code do.
|
|
17
|
+
* - **Persistent variables Peers keeps for every screen** (this device, the active group, the
|
|
18
|
+
* theme), read only. A package's own variables don't come this way: the frame's SDK asks the
|
|
19
|
+
* host for them, and they're stored under the package's id (`frame-pvars.ts`).
|
|
20
|
+
* - **Data events** of those tables, for `dataChanged`.
|
|
21
|
+
*
|
|
22
|
+
* Everything else is refused with an error naming the call.
|
|
23
|
+
*/
|
|
24
|
+
/** Table methods a screen may call on the shared tables: reads only. */
|
|
25
|
+
const READ_METHODS = new Set(["get", "list", "count", "findOne"]);
|
|
26
|
+
const OWN_TABLE_METHODS = new Set([
|
|
27
|
+
...READ_METHODS,
|
|
28
|
+
"save",
|
|
29
|
+
"insert",
|
|
30
|
+
"update",
|
|
31
|
+
"delete",
|
|
32
|
+
]);
|
|
33
|
+
/** Persistent variables every screen may read through the table. */
|
|
34
|
+
exports.SCREEN_READABLE_PVARS = new Set([
|
|
35
|
+
"thisDeviceId",
|
|
36
|
+
"currentlyActiveGroupId",
|
|
37
|
+
"colorMode",
|
|
38
|
+
"colorModePreference",
|
|
39
|
+
]);
|
|
40
|
+
const readablePvarFilter = {
|
|
41
|
+
name: { $in: [...exports.SCREEN_READABLE_PVARS] },
|
|
42
|
+
isSecret: { $ne: true },
|
|
43
|
+
};
|
|
44
|
+
let sharedTables;
|
|
45
|
+
let pvarsTable;
|
|
46
|
+
/** The full names of the tables screens read, worked out once from the SDK's definitions. */
|
|
47
|
+
function sharedTableNames() {
|
|
48
|
+
if (!sharedTables || !pvarsTable) {
|
|
49
|
+
pvarsTable = (0, peers_sdk_1.PersistentVars)().tableName;
|
|
50
|
+
sharedTables = new Set([
|
|
51
|
+
(0, peers_sdk_1.Groups)().tableName,
|
|
52
|
+
(0, peers_sdk_1.GroupMembers)().tableName,
|
|
53
|
+
(0, peers_sdk_1.Users)().tableName,
|
|
54
|
+
(0, peers_sdk_1.Devices)().tableName,
|
|
55
|
+
(0, peers_sdk_1.Packages)().tableName,
|
|
56
|
+
(0, peers_sdk_1.PackageVersions)().tableName,
|
|
57
|
+
pvarsTable,
|
|
58
|
+
]);
|
|
59
|
+
}
|
|
60
|
+
return { shared: sharedTables, pvars: pvarsTable };
|
|
61
|
+
}
|
|
62
|
+
/** Whether a table is the package's own: package tables' full names end with the package's id. */
|
|
63
|
+
function isOwnTable(packageId, tableName) {
|
|
64
|
+
return tableName.endsWith(`_${packageId}`);
|
|
65
|
+
}
|
|
66
|
+
function refuse(packageId, what) {
|
|
67
|
+
throw new Error(`Permission denied: an isolated screen of package ${packageId} can't ${what}`);
|
|
68
|
+
}
|
|
69
|
+
function readablePvarRow(row) {
|
|
70
|
+
const pvar = row;
|
|
71
|
+
return typeof pvar?.name === "string" && !pvar.isSecret && exports.SCREEN_READABLE_PVARS.has(pvar.name);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Call one table method for a screen, in a context the user belongs to. The id is checked
|
|
75
|
+
* against the user's current groups first, so a screen can't reopen a context by naming it.
|
|
76
|
+
*
|
|
77
|
+
* On a host that runs Peers in its own window (the PWA) the table is called directly: its
|
|
78
|
+
* `rpcServerCalls.tableMethodCall` caps the calls in flight at five, and a screen's start makes
|
|
79
|
+
* more than that at once. Elsewhere (Electron) the window's call goes to the main process.
|
|
80
|
+
*/
|
|
81
|
+
async function hostTableCall(dataContextId, tableName, methodName, ...args) {
|
|
82
|
+
const userContext = await (0, peers_sdk_1.getUserContext)();
|
|
83
|
+
const contextId = dataContextId || userContext.userId;
|
|
84
|
+
if (contextId !== userContext.userId && !userContext.groupIds().includes(contextId)) {
|
|
85
|
+
throw new Error(`Permission denied: data context '${contextId}' is not available here`);
|
|
86
|
+
}
|
|
87
|
+
if (!(0, peers_sdk_1.isSingleProcessClient)()) {
|
|
88
|
+
return peers_sdk_1.rpcServerCalls.tableMethodCall(contextId, tableName, methodName, ...args);
|
|
89
|
+
}
|
|
90
|
+
(0, peers_sdk_1.checkRemoteTableSaveOptions)(methodName, args);
|
|
91
|
+
const table = userContext
|
|
92
|
+
.getDataContext(contextId)
|
|
93
|
+
.tableContainer.getTable(tableName);
|
|
94
|
+
const method = table[methodName];
|
|
95
|
+
if (typeof method !== "function") {
|
|
96
|
+
throw new Error(`Method ${methodName} not found on table ${tableName}`);
|
|
97
|
+
}
|
|
98
|
+
return (method.__original ?? method).call(table, ...args);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Serve one isolated screen's legacy RPC calls.
|
|
102
|
+
*
|
|
103
|
+
* @param packageId - The screen's package.
|
|
104
|
+
* @param sendEvent - Hands the screen a data event it subscribed to.
|
|
105
|
+
*/
|
|
106
|
+
function createFrameRpc(packageId, sendEvent) {
|
|
107
|
+
const names = new Map();
|
|
108
|
+
const prefixes = new Map();
|
|
109
|
+
const { pvars } = sharedTableNames();
|
|
110
|
+
// An exact and a prefix subscription can both match one event; the host hands each the same
|
|
111
|
+
// event object, so the screen gets it once, as the window did.
|
|
112
|
+
const sent = new WeakSet();
|
|
113
|
+
const sendOnce = (event) => {
|
|
114
|
+
if (sent.has(event))
|
|
115
|
+
return;
|
|
116
|
+
sent.add(event);
|
|
117
|
+
sendEvent(event);
|
|
118
|
+
};
|
|
119
|
+
const forwardPvar = (event) => {
|
|
120
|
+
const row = event.data?.dataObject;
|
|
121
|
+
if (readablePvarRow(row))
|
|
122
|
+
sendOnce(event);
|
|
123
|
+
};
|
|
124
|
+
const watch = (map, key, start) => {
|
|
125
|
+
// A table name can itself contain "_DataChanged". Only the final suffix names the event.
|
|
126
|
+
const table = typeof key === "string" && /^(.+)_DataChanged(?:_[A-Za-z0-9]*)?$/s.exec(key)?.[1];
|
|
127
|
+
if (!table || !(sharedTableNames().shared.has(table) || isOwnTable(packageId, table))) {
|
|
128
|
+
refuse(packageId, `watch ${key}`);
|
|
129
|
+
}
|
|
130
|
+
const entry = map.get(key);
|
|
131
|
+
if (entry) {
|
|
132
|
+
entry.count++;
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
map.set(key, { count: 1, stop: start(table === pvars ? forwardPvar : sendOnce) });
|
|
136
|
+
};
|
|
137
|
+
const unwatch = (map, key) => {
|
|
138
|
+
const entry = map.get(key);
|
|
139
|
+
if (!entry)
|
|
140
|
+
return;
|
|
141
|
+
entry.count--;
|
|
142
|
+
if (entry.count <= 0) {
|
|
143
|
+
entry.stop();
|
|
144
|
+
map.delete(key);
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
const tableCall = async (args) => {
|
|
148
|
+
const [dataContextId, tableName, methodName, ...rest] = args;
|
|
149
|
+
if (typeof tableName !== "string" || typeof methodName !== "string") {
|
|
150
|
+
refuse(packageId, "call a table without naming it");
|
|
151
|
+
}
|
|
152
|
+
// The RPC receiver's getDataContext creates an unknown group on lookup.
|
|
153
|
+
const user = (0, peers_sdk_1.peekUserContext)();
|
|
154
|
+
if (!user ||
|
|
155
|
+
(dataContextId && dataContextId !== user.userId && !user.groupDataContexts.has(dataContextId))) {
|
|
156
|
+
refuse(packageId, `access data context ${dataContextId}`);
|
|
157
|
+
}
|
|
158
|
+
if (isOwnTable(packageId, tableName)) {
|
|
159
|
+
if (!OWN_TABLE_METHODS.has(methodName))
|
|
160
|
+
refuse(packageId, `call ${tableName}.${methodName}`);
|
|
161
|
+
return hostTableCall(dataContextId, tableName, methodName, ...rest);
|
|
162
|
+
}
|
|
163
|
+
const { shared } = sharedTableNames();
|
|
164
|
+
if (!shared.has(tableName) || !READ_METHODS.has(methodName)) {
|
|
165
|
+
refuse(packageId, `call ${tableName}.${methodName}`);
|
|
166
|
+
}
|
|
167
|
+
if (tableName === pvars && methodName !== "get") {
|
|
168
|
+
// Limit the query before the table counts, pages or checks uniqueness. A list's
|
|
169
|
+
// options.filter takes precedence over its positional filter in the SQL data source.
|
|
170
|
+
const options = methodName === "list" ? rest[1] : undefined;
|
|
171
|
+
rest[0] = { $and: [readablePvarFilter, options?.filter ?? rest[0] ?? {}] };
|
|
172
|
+
if (options && typeof options === "object" && "filter" in options) {
|
|
173
|
+
rest[1] = { ...options, filter: rest[0] };
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
const result = await hostTableCall(dataContextId, tableName, methodName, ...rest);
|
|
177
|
+
if (tableName !== pvars || methodName === "count")
|
|
178
|
+
return result;
|
|
179
|
+
// Persistent variables: only the ones every screen may read.
|
|
180
|
+
if (methodName === "list")
|
|
181
|
+
return result.filter(readablePvarRow);
|
|
182
|
+
return readablePvarRow(result) ? result : undefined;
|
|
183
|
+
};
|
|
184
|
+
return {
|
|
185
|
+
async call(name, args) {
|
|
186
|
+
switch (name) {
|
|
187
|
+
case "tableMethodCall":
|
|
188
|
+
return tableCall(args);
|
|
189
|
+
case "subscribeEvents":
|
|
190
|
+
for (const eventName of args[0] ?? []) {
|
|
191
|
+
watch(names, eventName, (forward) => (0, peers_sdk_1.subscribe)(eventName, forward).unsubscribe);
|
|
192
|
+
}
|
|
193
|
+
return;
|
|
194
|
+
case "unsubscribeEvents":
|
|
195
|
+
for (const eventName of args[0] ?? [])
|
|
196
|
+
unwatch(names, eventName);
|
|
197
|
+
return;
|
|
198
|
+
case "subscribePrefixes":
|
|
199
|
+
for (const prefix of args[0] ?? []) {
|
|
200
|
+
watch(prefixes, prefix, (forward) => {
|
|
201
|
+
const start = prefix.endsWith("_DataChanged") ? `${prefix}_` : prefix;
|
|
202
|
+
// Only the context id can follow, even when another table starts with this prefix.
|
|
203
|
+
const pattern = new RegExp(`^${(0, lodash_1.escapeRegExp)(start)}[A-Za-z0-9]*$`);
|
|
204
|
+
const stopPrefix = (0, peers_sdk_1.subscribePrefix)(start);
|
|
205
|
+
const subscription = (0, peers_sdk_1.subscribe)((event) => pattern.test(event.name), forward);
|
|
206
|
+
return () => {
|
|
207
|
+
subscription.unsubscribe();
|
|
208
|
+
stopPrefix();
|
|
209
|
+
};
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
return;
|
|
213
|
+
case "unsubscribePrefixes":
|
|
214
|
+
for (const prefix of args[0] ?? [])
|
|
215
|
+
unwatch(prefixes, prefix);
|
|
216
|
+
return;
|
|
217
|
+
case "flushDatabases":
|
|
218
|
+
return;
|
|
219
|
+
default:
|
|
220
|
+
refuse(packageId, `call ${name}`);
|
|
221
|
+
}
|
|
222
|
+
},
|
|
223
|
+
dispose() {
|
|
224
|
+
for (const entry of [...names.values(), ...prefixes.values()])
|
|
225
|
+
entry.stop();
|
|
226
|
+
names.clear();
|
|
227
|
+
prefixes.clear();
|
|
228
|
+
},
|
|
229
|
+
};
|
|
230
|
+
}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What crosses between an isolated package screen's frame and its host, by message type. The
|
|
3
|
+
* host owns every decision: the frame asks, and the host answers or refuses.
|
|
4
|
+
*
|
|
5
|
+
* The frame's document is a tiny `srcdoc` page (`frameDocument` in `frame-document.ts`). It says
|
|
6
|
+
* hello to its parent once; the host, which made the frame, answers with the frame runtime's
|
|
7
|
+
* source and a `MessagePort`. Everything after that goes over the port, so a message can't be
|
|
8
|
+
* forged by another frame.
|
|
9
|
+
*/
|
|
10
|
+
/** Light or dark, as the host's theme resolved it. */
|
|
11
|
+
export type FrameColorMode = "light" | "dark";
|
|
12
|
+
/** What the host tells a frame when it starts, and again when the screen changes. */
|
|
13
|
+
export interface IFrameInit {
|
|
14
|
+
/** The package whose screen this frame shows. */
|
|
15
|
+
packageId: string;
|
|
16
|
+
/** The package's name, for errors. */
|
|
17
|
+
packageName: string;
|
|
18
|
+
/** The version whose UI bundle runs here. */
|
|
19
|
+
packageVersionId: string;
|
|
20
|
+
/** The signed-in user. */
|
|
21
|
+
userId: string;
|
|
22
|
+
/** This device. */
|
|
23
|
+
deviceId: string;
|
|
24
|
+
/** The UI bundle's code, checked by the host against the version's hash. */
|
|
25
|
+
bundleCode: string;
|
|
26
|
+
/** The UI to show, from the bundle's `exportUIs`, for a screen. */
|
|
27
|
+
peersUIId?: string;
|
|
28
|
+
/** Props for it: data only. */
|
|
29
|
+
props: Record<string, unknown>;
|
|
30
|
+
/**
|
|
31
|
+
* For a piece's frame instead of a screen's: the piece to draw (its key, from `pieceKey`), the
|
|
32
|
+
* group it was embedded for, and whether it takes its own height (`content`), which the frame
|
|
33
|
+
* then reports.
|
|
34
|
+
*/
|
|
35
|
+
piece?: {
|
|
36
|
+
key: string;
|
|
37
|
+
groupId: string;
|
|
38
|
+
height: "fill" | "content";
|
|
39
|
+
/**
|
|
40
|
+
* For a piece in a popover, which is as wide as what's in it: the piece takes its content's
|
|
41
|
+
* width, up to this many pixels, and the frame reports it with its height.
|
|
42
|
+
*/
|
|
43
|
+
width?: number;
|
|
44
|
+
/** The emits the embedder's version declares: the piece's `emit` has these, and `open`. */
|
|
45
|
+
emits?: string[];
|
|
46
|
+
};
|
|
47
|
+
/** The tab's path. */
|
|
48
|
+
path: string;
|
|
49
|
+
/** The host's theme. */
|
|
50
|
+
colorMode: FrameColorMode;
|
|
51
|
+
/** The package's own `localStorage` entries, by key. */
|
|
52
|
+
storage: Record<string, string>;
|
|
53
|
+
/**
|
|
54
|
+
* Entries from before screens were isolated, read when the package has no entry of its own
|
|
55
|
+
* under that key. Temporary: see `frame-storage.ts`.
|
|
56
|
+
*/
|
|
57
|
+
legacyStorage: Record<string, string>;
|
|
58
|
+
}
|
|
59
|
+
/** A request the frame makes of the host, by name. */
|
|
60
|
+
export declare const FrameRequest: {
|
|
61
|
+
/** A legacy RPC call (`rpcServerCalls`), checked by the host's policy. */
|
|
62
|
+
readonly rpc: "rpc";
|
|
63
|
+
/** A contract call on the frame's own session: `{ channel, args }`. */
|
|
64
|
+
readonly contractEmit: "contract.emit";
|
|
65
|
+
/** Bind a persistent variable: `{ bindingId, request }` → its value. */
|
|
66
|
+
readonly pvarBind: "pvar.bind";
|
|
67
|
+
/** Write one: `{ bindingId, value }`. */
|
|
68
|
+
readonly pvarWrite: "pvar.write";
|
|
69
|
+
/** Delete one: `{ bindingId }`. */
|
|
70
|
+
readonly pvarDelete: "pvar.delete";
|
|
71
|
+
/** Navigate the frame's tab: `{ path }`. */
|
|
72
|
+
readonly navigate: "nav.navigate";
|
|
73
|
+
/** Open a path in a tab, as `goToTabPath` does: `{ path, title?, iconClassName? }`. */
|
|
74
|
+
readonly goToTabPath: "nav.goToTabPath";
|
|
75
|
+
/** Set the frame's tab title: `{ title }`. */
|
|
76
|
+
readonly setTitle: "nav.setTitle";
|
|
77
|
+
/** Close the frame's tab. */
|
|
78
|
+
readonly closeTab: "nav.closeTab";
|
|
79
|
+
/** Open a link outside Peers: `{ url }`. */
|
|
80
|
+
readonly openLink: "nav.openLink";
|
|
81
|
+
/** Open a mentioned record: the mention's `{ kind, id, groupId? }`. */
|
|
82
|
+
readonly openMention: "nav.openMention";
|
|
83
|
+
/** Who draws a piece the screen embeds: `{ handle, dataContextId }` → a piece resolution. */
|
|
84
|
+
readonly pieceResolve: "piece.resolve";
|
|
85
|
+
/**
|
|
86
|
+
* Draw a piece over a slot of the screen: `{ slotId, handle, dataContextId, props, height,
|
|
87
|
+
* width? }`. The host makes the piece's frame, acting as its provider, and places it over the
|
|
88
|
+
* slot.
|
|
89
|
+
*/
|
|
90
|
+
readonly pieceMount: "piece.mount";
|
|
91
|
+
/**
|
|
92
|
+
* The user asked to retry a piece the host couldn't resolve: the host drops the resolutions it
|
|
93
|
+
* keeps, as Retry does in its own window, and every screen resolves its pieces again.
|
|
94
|
+
*/
|
|
95
|
+
readonly pieceRetry: "piece.retry";
|
|
96
|
+
};
|
|
97
|
+
/** A notification the frame sends the host, by name. */
|
|
98
|
+
export declare const FrameNotice: {
|
|
99
|
+
/** The runtime has started and waits for its init. */
|
|
100
|
+
readonly ready: "frame.ready";
|
|
101
|
+
/** The screen rendered. */
|
|
102
|
+
readonly rendered: "frame.rendered";
|
|
103
|
+
/** The screen failed to load or threw: `{ message }`. */
|
|
104
|
+
readonly failed: "frame.failed";
|
|
105
|
+
/** A `localStorage` change: `{ key, value }`, `value` null for a removal, or `{ clear: true }`. */
|
|
106
|
+
readonly storage: "storage.set";
|
|
107
|
+
/**
|
|
108
|
+
* A key pressed inside the frame with ⌘ or Ctrl that the screen left alone (not
|
|
109
|
+
* `defaultPrevented`): the key event's fields. The host dispatches it on its own document, so
|
|
110
|
+
* its shortcuts (the command palette, tab switching, the console) work from inside a screen.
|
|
111
|
+
* A piece's frame also sends Escape that the piece left alone, which the host hands to its
|
|
112
|
+
* embedder, so a popover closes.
|
|
113
|
+
*/
|
|
114
|
+
readonly key: "keys.forward";
|
|
115
|
+
/** A console warning or error from the screen, for the host's logs: `{ level, message }`. */
|
|
116
|
+
readonly log: "frame.log";
|
|
117
|
+
/** A piece slot moved or changed size: `{ slotId, rect }`, in the frame's coordinates. */
|
|
118
|
+
readonly pieceRect: "piece.rect";
|
|
119
|
+
/** A piece slot's props changed: `{ slotId, props }`. */
|
|
120
|
+
readonly pieceProps: "piece.props";
|
|
121
|
+
/** A piece slot went away: `{ slotId }`. */
|
|
122
|
+
readonly pieceUnmount: "piece.unmount";
|
|
123
|
+
/** From a piece's frame: it emitted `{ name, payload }`. */
|
|
124
|
+
readonly pieceEmit: "piece.emit";
|
|
125
|
+
/** From a piece's frame: it asked to close. */
|
|
126
|
+
readonly pieceClose: "piece.close";
|
|
127
|
+
/**
|
|
128
|
+
* From a piece's frame that takes its own height: its content's height, `{ height }`, and its
|
|
129
|
+
* width, `{ width }`, when it takes its content's width too.
|
|
130
|
+
*/
|
|
131
|
+
readonly size: "frame.size";
|
|
132
|
+
/**
|
|
133
|
+
* A pointer went down in the frame. A click inside a frame never reaches the documents around
|
|
134
|
+
* it, so the host tells every other frame, and its own window, for their popovers.
|
|
135
|
+
*/
|
|
136
|
+
readonly pointerDown: "pointer.down";
|
|
137
|
+
/** The user asked to start a screen that failed to load again: the host makes a new frame. */
|
|
138
|
+
readonly restart: "frame.restart";
|
|
139
|
+
};
|
|
140
|
+
/** A request the host makes of the frame, by name. */
|
|
141
|
+
export declare const HostRequest: {
|
|
142
|
+
/** Start, or show another UI: an {@link IFrameInit}. */
|
|
143
|
+
readonly init: "init";
|
|
144
|
+
/** Inspect the frame's UI for `peers ui inspect`: the same input the host's inspector takes. */
|
|
145
|
+
readonly inspect: "ui.inspect";
|
|
146
|
+
/** Drive the frame's UI for `peers ui click/set/scroll`: `{ operation, input }`. */
|
|
147
|
+
readonly act: "ui.act";
|
|
148
|
+
};
|
|
149
|
+
/** A notification the host sends the frame, by name. */
|
|
150
|
+
export declare const HostNotice: {
|
|
151
|
+
/** The theme changed: `{ colorMode }`. */
|
|
152
|
+
readonly theme: "theme";
|
|
153
|
+
/** A contract notification on the frame's session: `{ channel, args }`. */
|
|
154
|
+
readonly contract: "contract.notify";
|
|
155
|
+
/** The frame's session reconnected without its subscriptions: its clients subscribe again. */
|
|
156
|
+
readonly contractReset: "contract.reset";
|
|
157
|
+
/** A data event the frame subscribed to: the event. */
|
|
158
|
+
readonly event: "event";
|
|
159
|
+
/** A persistent variable changed: `{ bindingId, value }`. */
|
|
160
|
+
readonly pvarChanged: "pvar.changed";
|
|
161
|
+
/** A piece the screen embeds emitted: `{ slotId, name, payload }`. */
|
|
162
|
+
readonly pieceEmit: "piece.emit";
|
|
163
|
+
/** A piece the screen embeds asked to close: `{ slotId }`. */
|
|
164
|
+
readonly pieceClose: "piece.close";
|
|
165
|
+
/**
|
|
166
|
+
* A piece the screen embeds, which takes its own height, is now `{ slotId, height }` tall, and
|
|
167
|
+
* `width` wide when it takes its content's width.
|
|
168
|
+
*/
|
|
169
|
+
readonly pieceSize: "piece.size";
|
|
170
|
+
/**
|
|
171
|
+
* Escape was pressed in a piece the screen embeds, and the piece left it alone: `{ slotId, key,
|
|
172
|
+
* code }`. The frame dispatches it on the slot, where it reaches a popover around it.
|
|
173
|
+
*/
|
|
174
|
+
readonly pieceKey: "piece.key";
|
|
175
|
+
/**
|
|
176
|
+
* A pointer went down outside this frame: in the host's window, or in another frame. `slotId`
|
|
177
|
+
* names this frame's piece slot when it was inside the piece drawn over it. The frame
|
|
178
|
+
* dispatches `FRAME_POINTER_EVENT` there (or on its body), for its popovers.
|
|
179
|
+
*/
|
|
180
|
+
readonly outsidePointerDown: "pointer.outside";
|
|
181
|
+
/** A piece the screen embeds couldn't be drawn: `{ slotId, message }`. */
|
|
182
|
+
readonly pieceFailed: "piece.failed";
|
|
183
|
+
/** Something a piece resolution depends on changed: the screen resolves its pieces again. */
|
|
184
|
+
readonly pieceRevision: "piece.revision";
|
|
185
|
+
};
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* What crosses between an isolated package screen's frame and its host, by message type. The
|
|
4
|
+
* host owns every decision: the frame asks, and the host answers or refuses.
|
|
5
|
+
*
|
|
6
|
+
* The frame's document is a tiny `srcdoc` page (`frameDocument` in `frame-document.ts`). It says
|
|
7
|
+
* hello to its parent once; the host, which made the frame, answers with the frame runtime's
|
|
8
|
+
* source and a `MessagePort`. Everything after that goes over the port, so a message can't be
|
|
9
|
+
* forged by another frame.
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.HostNotice = exports.HostRequest = exports.FrameNotice = exports.FrameRequest = void 0;
|
|
13
|
+
/** A request the frame makes of the host, by name. */
|
|
14
|
+
exports.FrameRequest = {
|
|
15
|
+
/** A legacy RPC call (`rpcServerCalls`), checked by the host's policy. */
|
|
16
|
+
rpc: "rpc",
|
|
17
|
+
/** A contract call on the frame's own session: `{ channel, args }`. */
|
|
18
|
+
contractEmit: "contract.emit",
|
|
19
|
+
/** Bind a persistent variable: `{ bindingId, request }` → its value. */
|
|
20
|
+
pvarBind: "pvar.bind",
|
|
21
|
+
/** Write one: `{ bindingId, value }`. */
|
|
22
|
+
pvarWrite: "pvar.write",
|
|
23
|
+
/** Delete one: `{ bindingId }`. */
|
|
24
|
+
pvarDelete: "pvar.delete",
|
|
25
|
+
/** Navigate the frame's tab: `{ path }`. */
|
|
26
|
+
navigate: "nav.navigate",
|
|
27
|
+
/** Open a path in a tab, as `goToTabPath` does: `{ path, title?, iconClassName? }`. */
|
|
28
|
+
goToTabPath: "nav.goToTabPath",
|
|
29
|
+
/** Set the frame's tab title: `{ title }`. */
|
|
30
|
+
setTitle: "nav.setTitle",
|
|
31
|
+
/** Close the frame's tab. */
|
|
32
|
+
closeTab: "nav.closeTab",
|
|
33
|
+
/** Open a link outside Peers: `{ url }`. */
|
|
34
|
+
openLink: "nav.openLink",
|
|
35
|
+
/** Open a mentioned record: the mention's `{ kind, id, groupId? }`. */
|
|
36
|
+
openMention: "nav.openMention",
|
|
37
|
+
/** Who draws a piece the screen embeds: `{ handle, dataContextId }` → a piece resolution. */
|
|
38
|
+
pieceResolve: "piece.resolve",
|
|
39
|
+
/**
|
|
40
|
+
* Draw a piece over a slot of the screen: `{ slotId, handle, dataContextId, props, height,
|
|
41
|
+
* width? }`. The host makes the piece's frame, acting as its provider, and places it over the
|
|
42
|
+
* slot.
|
|
43
|
+
*/
|
|
44
|
+
pieceMount: "piece.mount",
|
|
45
|
+
/**
|
|
46
|
+
* The user asked to retry a piece the host couldn't resolve: the host drops the resolutions it
|
|
47
|
+
* keeps, as Retry does in its own window, and every screen resolves its pieces again.
|
|
48
|
+
*/
|
|
49
|
+
pieceRetry: "piece.retry",
|
|
50
|
+
};
|
|
51
|
+
/** A notification the frame sends the host, by name. */
|
|
52
|
+
exports.FrameNotice = {
|
|
53
|
+
/** The runtime has started and waits for its init. */
|
|
54
|
+
ready: "frame.ready",
|
|
55
|
+
/** The screen rendered. */
|
|
56
|
+
rendered: "frame.rendered",
|
|
57
|
+
/** The screen failed to load or threw: `{ message }`. */
|
|
58
|
+
failed: "frame.failed",
|
|
59
|
+
/** A `localStorage` change: `{ key, value }`, `value` null for a removal, or `{ clear: true }`. */
|
|
60
|
+
storage: "storage.set",
|
|
61
|
+
/**
|
|
62
|
+
* A key pressed inside the frame with ⌘ or Ctrl that the screen left alone (not
|
|
63
|
+
* `defaultPrevented`): the key event's fields. The host dispatches it on its own document, so
|
|
64
|
+
* its shortcuts (the command palette, tab switching, the console) work from inside a screen.
|
|
65
|
+
* A piece's frame also sends Escape that the piece left alone, which the host hands to its
|
|
66
|
+
* embedder, so a popover closes.
|
|
67
|
+
*/
|
|
68
|
+
key: "keys.forward",
|
|
69
|
+
/** A console warning or error from the screen, for the host's logs: `{ level, message }`. */
|
|
70
|
+
log: "frame.log",
|
|
71
|
+
/** A piece slot moved or changed size: `{ slotId, rect }`, in the frame's coordinates. */
|
|
72
|
+
pieceRect: "piece.rect",
|
|
73
|
+
/** A piece slot's props changed: `{ slotId, props }`. */
|
|
74
|
+
pieceProps: "piece.props",
|
|
75
|
+
/** A piece slot went away: `{ slotId }`. */
|
|
76
|
+
pieceUnmount: "piece.unmount",
|
|
77
|
+
/** From a piece's frame: it emitted `{ name, payload }`. */
|
|
78
|
+
pieceEmit: "piece.emit",
|
|
79
|
+
/** From a piece's frame: it asked to close. */
|
|
80
|
+
pieceClose: "piece.close",
|
|
81
|
+
/**
|
|
82
|
+
* From a piece's frame that takes its own height: its content's height, `{ height }`, and its
|
|
83
|
+
* width, `{ width }`, when it takes its content's width too.
|
|
84
|
+
*/
|
|
85
|
+
size: "frame.size",
|
|
86
|
+
/**
|
|
87
|
+
* A pointer went down in the frame. A click inside a frame never reaches the documents around
|
|
88
|
+
* it, so the host tells every other frame, and its own window, for their popovers.
|
|
89
|
+
*/
|
|
90
|
+
pointerDown: "pointer.down",
|
|
91
|
+
/** The user asked to start a screen that failed to load again: the host makes a new frame. */
|
|
92
|
+
restart: "frame.restart",
|
|
93
|
+
};
|
|
94
|
+
/** A request the host makes of the frame, by name. */
|
|
95
|
+
exports.HostRequest = {
|
|
96
|
+
/** Start, or show another UI: an {@link IFrameInit}. */
|
|
97
|
+
init: "init",
|
|
98
|
+
/** Inspect the frame's UI for `peers ui inspect`: the same input the host's inspector takes. */
|
|
99
|
+
inspect: "ui.inspect",
|
|
100
|
+
/** Drive the frame's UI for `peers ui click/set/scroll`: `{ operation, input }`. */
|
|
101
|
+
act: "ui.act",
|
|
102
|
+
};
|
|
103
|
+
/** A notification the host sends the frame, by name. */
|
|
104
|
+
exports.HostNotice = {
|
|
105
|
+
/** The theme changed: `{ colorMode }`. */
|
|
106
|
+
theme: "theme",
|
|
107
|
+
/** A contract notification on the frame's session: `{ channel, args }`. */
|
|
108
|
+
contract: "contract.notify",
|
|
109
|
+
/** The frame's session reconnected without its subscriptions: its clients subscribe again. */
|
|
110
|
+
contractReset: "contract.reset",
|
|
111
|
+
/** A data event the frame subscribed to: the event. */
|
|
112
|
+
event: "event",
|
|
113
|
+
/** A persistent variable changed: `{ bindingId, value }`. */
|
|
114
|
+
pvarChanged: "pvar.changed",
|
|
115
|
+
/** A piece the screen embeds emitted: `{ slotId, name, payload }`. */
|
|
116
|
+
pieceEmit: "piece.emit",
|
|
117
|
+
/** A piece the screen embeds asked to close: `{ slotId }`. */
|
|
118
|
+
pieceClose: "piece.close",
|
|
119
|
+
/**
|
|
120
|
+
* A piece the screen embeds, which takes its own height, is now `{ slotId, height }` tall, and
|
|
121
|
+
* `width` wide when it takes its content's width.
|
|
122
|
+
*/
|
|
123
|
+
pieceSize: "piece.size",
|
|
124
|
+
/**
|
|
125
|
+
* Escape was pressed in a piece the screen embeds, and the piece left it alone: `{ slotId, key,
|
|
126
|
+
* code }`. The frame dispatches it on the slot, where it reaches a popover around it.
|
|
127
|
+
*/
|
|
128
|
+
pieceKey: "piece.key",
|
|
129
|
+
/**
|
|
130
|
+
* A pointer went down outside this frame: in the host's window, or in another frame. `slotId`
|
|
131
|
+
* names this frame's piece slot when it was inside the piece drawn over it. The frame
|
|
132
|
+
* dispatches `FRAME_POINTER_EVENT` there (or on its body), for its popovers.
|
|
133
|
+
*/
|
|
134
|
+
outsidePointerDown: "pointer.outside",
|
|
135
|
+
/** A piece the screen embeds couldn't be drawn: `{ slotId, message }`. */
|
|
136
|
+
pieceFailed: "piece.failed",
|
|
137
|
+
/** Something a piece resolution depends on changed: the screen resolves its pieces again. */
|
|
138
|
+
pieceRevision: "piece.revision",
|
|
139
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type IPersistentVarBackendRequest, type Observable } from "@peers-app/peers-sdk";
|
|
2
|
+
/** What the pvar service needs from the screen's host. */
|
|
3
|
+
export interface IFramePvarHost {
|
|
4
|
+
/** The screen's package. */
|
|
5
|
+
packageId: string;
|
|
6
|
+
/** The screen's tab path. */
|
|
7
|
+
tabPath: Observable<string>;
|
|
8
|
+
/** Navigate the screen's tab. */
|
|
9
|
+
navigate(path: string): void;
|
|
10
|
+
/** Tell the frame a bound variable's new value. */
|
|
11
|
+
changed(bindingId: string, value: unknown): void;
|
|
12
|
+
}
|
|
13
|
+
/** One screen's bound variables. */
|
|
14
|
+
export interface IFramePvarService {
|
|
15
|
+
bind(input: {
|
|
16
|
+
bindingId: string;
|
|
17
|
+
request: IPersistentVarBackendRequest;
|
|
18
|
+
}): Promise<unknown>;
|
|
19
|
+
write(input: {
|
|
20
|
+
bindingId: string;
|
|
21
|
+
value: unknown;
|
|
22
|
+
}): Promise<void>;
|
|
23
|
+
delete(input: {
|
|
24
|
+
bindingId: string;
|
|
25
|
+
}): Promise<void>;
|
|
26
|
+
dispose(): void;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Serve one isolated screen's persistent variables.
|
|
30
|
+
*
|
|
31
|
+
* @param host - The screen's package, tab path and channel.
|
|
32
|
+
*/
|
|
33
|
+
export declare function createFramePvarService(host: IFramePvarHost): IFramePvarService;
|