@peers-app/peers-ui 0.33.23 → 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 +24 -3
- package/dist/root-layout/app-shell-height.js +25 -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 +7 -1
- package/dist/root-layout/layouts/tabs-with-console-layout.js +1 -1
- 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 +13 -20
- package/dist/tabs-layout/tabs-state.js +39 -16
- package/dist/theme.css +66 -0
- 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,27 @@
|
|
|
1
|
+
import type React from "react";
|
|
2
|
+
import type { IPieceAvailable, PieceResolution } from "../ui-contracts/piece-resolution";
|
|
3
|
+
import type { IPieceHandle, PieceComponent } from "../ui-contracts/types";
|
|
4
|
+
/**
|
|
5
|
+
* Inside a framed screen: ask the host who draws a piece.
|
|
6
|
+
*
|
|
7
|
+
* @param handle - The piece.
|
|
8
|
+
* @param dataContextId - The group.
|
|
9
|
+
*/
|
|
10
|
+
export declare function resolvePieceThroughHost(handle: IPieceHandle, dataContextId: string): Promise<PieceResolution>;
|
|
11
|
+
/**
|
|
12
|
+
* In the host's window: the component that draws a piece in a frame for its provider.
|
|
13
|
+
*
|
|
14
|
+
* @param available - The resolution.
|
|
15
|
+
* @param name - The piece's name.
|
|
16
|
+
*/
|
|
17
|
+
export declare function inlinePieceComponent(available: IPieceAvailable, name: string): PieceComponent;
|
|
18
|
+
/**
|
|
19
|
+
* Inside a framed screen: the component that holds a slot for a piece, which the host draws over
|
|
20
|
+
* it in a frame for the provider.
|
|
21
|
+
*
|
|
22
|
+
* @param available - The resolution, from {@link resolvePieceThroughHost}.
|
|
23
|
+
* @param name - The piece's name.
|
|
24
|
+
*/
|
|
25
|
+
export declare function slotPieceComponent(available: IPieceAvailable, name: string): PieceComponent;
|
|
26
|
+
/** Whether a component from {@link inlinePieceComponent} or {@link slotPieceComponent}: for tests. */
|
|
27
|
+
export declare function isFramedPieceComponent(component: React.ComponentType<unknown>): boolean;
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolvePieceThroughHost = resolvePieceThroughHost;
|
|
4
|
+
exports.inlinePieceComponent = inlinePieceComponent;
|
|
5
|
+
exports.slotPieceComponent = slotPieceComponent;
|
|
6
|
+
exports.isFramedPieceComponent = isFramedPieceComponent;
|
|
7
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
|
+
const peers_sdk_1 = require("@peers-app/peers-sdk");
|
|
9
|
+
const react_1 = require("react");
|
|
10
|
+
const implement_piece_1 = require("../ui-contracts/implement-piece");
|
|
11
|
+
const piece_height_1 = require("../ui-contracts/piece-height");
|
|
12
|
+
const piece_host_1 = require("../ui-contracts/piece-host");
|
|
13
|
+
const popover_surface_1 = require("../ui-contracts/popover-surface");
|
|
14
|
+
const frame_component_1 = require("./frame-component");
|
|
15
|
+
const frame_protocol_1 = require("./frame-protocol");
|
|
16
|
+
const frame_realm_1 = require("./frame-realm");
|
|
17
|
+
/**
|
|
18
|
+
* Inside a framed screen: ask the host who draws a piece.
|
|
19
|
+
*
|
|
20
|
+
* @param handle - The piece.
|
|
21
|
+
* @param dataContextId - The group.
|
|
22
|
+
*/
|
|
23
|
+
async function resolvePieceThroughHost(handle, dataContextId) {
|
|
24
|
+
const host = (0, frame_realm_1.frameHost)();
|
|
25
|
+
if (!host)
|
|
26
|
+
throw new Error("Not in an isolated screen");
|
|
27
|
+
const requested = {
|
|
28
|
+
contractId: handle.contractId,
|
|
29
|
+
version: handle.version,
|
|
30
|
+
name: handle.name,
|
|
31
|
+
...(handle.providerPackageId ? { providerPackageId: handle.providerPackageId } : {}),
|
|
32
|
+
};
|
|
33
|
+
const resolution = await host.request(frame_protocol_1.FrameRequest.pieceResolve, {
|
|
34
|
+
handle: { kind: "piece-handle", ...requested },
|
|
35
|
+
dataContextId,
|
|
36
|
+
});
|
|
37
|
+
if (resolution.status === "available")
|
|
38
|
+
return { ...resolution, requested };
|
|
39
|
+
// The host keeps its answer, so Retry asks it to look again rather than asking for the same one.
|
|
40
|
+
if (resolution.reason === "failed") {
|
|
41
|
+
return {
|
|
42
|
+
...resolution,
|
|
43
|
+
retry: () => void host.request(frame_protocol_1.FrameRequest.pieceRetry).catch(() => undefined),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
return resolution;
|
|
47
|
+
}
|
|
48
|
+
function errorText(error) {
|
|
49
|
+
return error instanceof Error ? error.message : String(error);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The most a piece in a popover may be wide: a popover is as wide as what's in it, and a frame
|
|
53
|
+
* has no width of its own, so the piece takes its content's width, up to this.
|
|
54
|
+
*/
|
|
55
|
+
function popoverMaxWidth() {
|
|
56
|
+
return Math.max(160, Math.min(640, window.innerWidth - 16));
|
|
57
|
+
}
|
|
58
|
+
/** A popover piece's width until its frame first reports one: a frame's default width. */
|
|
59
|
+
function popoverStartWidth(max) {
|
|
60
|
+
return Math.min(300, max);
|
|
61
|
+
}
|
|
62
|
+
/** Escape a piece's frame left alone, dispatched where a popover around the piece hears it. */
|
|
63
|
+
function dispatchEscape(target, key) {
|
|
64
|
+
if (!target || key?.key !== "Escape")
|
|
65
|
+
return;
|
|
66
|
+
target.dispatchEvent(new KeyboardEvent("keydown", {
|
|
67
|
+
key: "Escape",
|
|
68
|
+
code: typeof key.code === "string" ? key.code : "Escape",
|
|
69
|
+
bubbles: true,
|
|
70
|
+
cancelable: true,
|
|
71
|
+
}));
|
|
72
|
+
}
|
|
73
|
+
const inlineComponents = new Map();
|
|
74
|
+
/**
|
|
75
|
+
* In the host's window: the component that draws a piece in a frame for its provider.
|
|
76
|
+
*
|
|
77
|
+
* @param available - The resolution.
|
|
78
|
+
* @param name - The piece's name.
|
|
79
|
+
*/
|
|
80
|
+
function inlinePieceComponent(available, name) {
|
|
81
|
+
const { contractId, version } = available.implementation;
|
|
82
|
+
// One implementation can serve embedder versions with different declared emits.
|
|
83
|
+
const emits = available.piece.emits.map((emit) => emit.name);
|
|
84
|
+
const key = `${available.dataContextId}|${available.providerPackageId}|${available.packageVersionId}|${(0, implement_piece_1.pieceKey)(contractId, version, name)}|${JSON.stringify(emits)}`;
|
|
85
|
+
const known = inlineComponents.get(key);
|
|
86
|
+
if (known)
|
|
87
|
+
return known;
|
|
88
|
+
function InlineFramedPiece(props) {
|
|
89
|
+
const mode = (0, react_1.useContext)(piece_height_1.PieceHeightContext);
|
|
90
|
+
const inPopover = (0, popover_surface_1.useInsidePopoverSurface)() && mode === "content";
|
|
91
|
+
const [maxWidth] = (0, react_1.useState)(popoverMaxWidth);
|
|
92
|
+
const box = (0, react_1.useRef)(null);
|
|
93
|
+
const [bundle, setBundle] = (0, react_1.useState)();
|
|
94
|
+
const [size, setSize] = (0, react_1.useState)();
|
|
95
|
+
const [failed, setFailed] = (0, react_1.useState)();
|
|
96
|
+
const latest = (0, react_1.useRef)(props);
|
|
97
|
+
latest.current = props;
|
|
98
|
+
(0, react_1.useEffect)(() => {
|
|
99
|
+
let cancelled = false;
|
|
100
|
+
(0, piece_host_1.readVersionBundle)(available.dataContextId, available.providerPackageId, available.packageVersionId).then((read) => !cancelled && setBundle(read), (error) => !cancelled && setBundle(error instanceof Error ? error : new Error(errorText(error))));
|
|
101
|
+
return () => {
|
|
102
|
+
cancelled = true;
|
|
103
|
+
};
|
|
104
|
+
}, []);
|
|
105
|
+
const content = (0, react_1.useMemo)(() => ({
|
|
106
|
+
kind: "piece",
|
|
107
|
+
key: (0, implement_piece_1.pieceKey)(contractId, version, name),
|
|
108
|
+
props: props.props,
|
|
109
|
+
groupId: props.groupId,
|
|
110
|
+
height: mode,
|
|
111
|
+
...(inPopover ? { width: maxWidth } : {}),
|
|
112
|
+
emits,
|
|
113
|
+
}), [JSON.stringify(props.props), props.groupId, mode, inPopover, maxWidth]);
|
|
114
|
+
const events = (0, react_1.useMemo)(() => ({
|
|
115
|
+
onEmit: (emitted, payload) => latest.current.emit[emitted]?.(payload),
|
|
116
|
+
onClose: () => latest.current.close(),
|
|
117
|
+
onSize: (height, width) => setSize({ height, width }),
|
|
118
|
+
onFailed: (message) => setFailed(message),
|
|
119
|
+
// On the frame's box, inside any popover around it.
|
|
120
|
+
onKey: (key) => dispatchEscape(box.current, key),
|
|
121
|
+
}), []);
|
|
122
|
+
// The piece's error boundary shows the failure, with Retry.
|
|
123
|
+
if (bundle instanceof Error)
|
|
124
|
+
throw bundle;
|
|
125
|
+
if (failed !== undefined)
|
|
126
|
+
throw new Error(failed);
|
|
127
|
+
if (!bundle)
|
|
128
|
+
return ((0, jsx_runtime_1.jsx)("div", { className: "peers-piece-loading", "aria-busy": "true", style: { minHeight: 24, width: inPopover ? popoverStartWidth(maxWidth) : undefined } }));
|
|
129
|
+
const PackageFrame = (0, frame_component_1.packageFrameComponent)();
|
|
130
|
+
return ((0, jsx_runtime_1.jsx)("div", { ref: box, style: {
|
|
131
|
+
width: inPopover ? (size?.width ?? popoverStartWidth(maxWidth)) : "100%",
|
|
132
|
+
height: mode === "content" ? (size?.height ?? 24) : "100%",
|
|
133
|
+
}, children: (0, jsx_runtime_1.jsx)(PackageFrame, { pkg: bundle.pkg, bundle: bundle, content: content, pieceEvents: events, label: bundle.pkg.name }) }));
|
|
134
|
+
}
|
|
135
|
+
const component = InlineFramedPiece;
|
|
136
|
+
inlineComponents.set(key, component);
|
|
137
|
+
return component;
|
|
138
|
+
}
|
|
139
|
+
/** The part of a slot that shows: its rectangle cut by every scrolling box around it. */
|
|
140
|
+
function visibleClip(element, rect) {
|
|
141
|
+
let top = rect.top;
|
|
142
|
+
let left = rect.left;
|
|
143
|
+
let bottom = rect.bottom;
|
|
144
|
+
let right = rect.right;
|
|
145
|
+
for (let parent = element.parentElement; parent; parent = parent.parentElement) {
|
|
146
|
+
const style = getComputedStyle(parent);
|
|
147
|
+
if (style.overflowX === "visible" && style.overflowY === "visible")
|
|
148
|
+
continue;
|
|
149
|
+
const box = parent.getBoundingClientRect();
|
|
150
|
+
if (style.overflowY !== "visible") {
|
|
151
|
+
top = Math.max(top, box.top);
|
|
152
|
+
bottom = Math.min(bottom, box.bottom);
|
|
153
|
+
}
|
|
154
|
+
if (style.overflowX !== "visible") {
|
|
155
|
+
left = Math.max(left, box.left);
|
|
156
|
+
right = Math.min(right, box.right);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
top = Math.max(top, 0);
|
|
160
|
+
left = Math.max(left, 0);
|
|
161
|
+
bottom = Math.min(bottom, window.innerHeight);
|
|
162
|
+
right = Math.min(right, window.innerWidth);
|
|
163
|
+
return {
|
|
164
|
+
top: Math.max(0, top - rect.top),
|
|
165
|
+
left: Math.max(0, left - rect.left),
|
|
166
|
+
bottom: Math.max(0, rect.bottom - bottom),
|
|
167
|
+
right: Math.max(0, rect.right - right),
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
const slotComponents = new Map();
|
|
171
|
+
/**
|
|
172
|
+
* Inside a framed screen: the component that holds a slot for a piece, which the host draws over
|
|
173
|
+
* it in a frame for the provider.
|
|
174
|
+
*
|
|
175
|
+
* @param available - The resolution, from {@link resolvePieceThroughHost}.
|
|
176
|
+
* @param name - The piece's name.
|
|
177
|
+
*/
|
|
178
|
+
function slotPieceComponent(available, name) {
|
|
179
|
+
const requested = available.requested;
|
|
180
|
+
const key = `${available.dataContextId}|${available.providerPackageId}|${available.packageVersionId}|${requested?.contractId}@${requested?.version}/${name}|${requested?.providerPackageId ?? ""}`;
|
|
181
|
+
const known = slotComponents.get(key);
|
|
182
|
+
if (known)
|
|
183
|
+
return known;
|
|
184
|
+
function SlotFramedPiece(props) {
|
|
185
|
+
const host = (0, frame_realm_1.frameHost)();
|
|
186
|
+
const mode = (0, react_1.useContext)(piece_height_1.PieceHeightContext);
|
|
187
|
+
const inPopover = (0, popover_surface_1.useInsidePopoverSurface)() && mode === "content";
|
|
188
|
+
const [maxWidth] = (0, react_1.useState)(popoverMaxWidth);
|
|
189
|
+
const slotRef = (0, react_1.useRef)(null);
|
|
190
|
+
const [size, setSize] = (0, react_1.useState)();
|
|
191
|
+
const [failed, setFailed] = (0, react_1.useState)();
|
|
192
|
+
const latest = (0, react_1.useRef)(props);
|
|
193
|
+
latest.current = props;
|
|
194
|
+
// The slot the host holds for this mount, once its mount request has been answered.
|
|
195
|
+
const mounted = (0, react_1.useRef)();
|
|
196
|
+
const propsKey = JSON.stringify(props.props);
|
|
197
|
+
(0, react_1.useEffect)(() => {
|
|
198
|
+
if (!host)
|
|
199
|
+
return;
|
|
200
|
+
// Each mount is a slot of its own, so a late answer to an earlier one never touches it.
|
|
201
|
+
const slotId = (0, peers_sdk_1.newid)();
|
|
202
|
+
let active = true;
|
|
203
|
+
const mine = (payload) => payload?.slotId === slotId;
|
|
204
|
+
const stops = [
|
|
205
|
+
host.onNotify(frame_protocol_1.HostNotice.pieceEmit, (payload) => {
|
|
206
|
+
if (mine(payload))
|
|
207
|
+
latest.current.emit[payload.name]?.(payload.payload);
|
|
208
|
+
}),
|
|
209
|
+
host.onNotify(frame_protocol_1.HostNotice.pieceClose, (payload) => {
|
|
210
|
+
if (mine(payload))
|
|
211
|
+
latest.current.close();
|
|
212
|
+
}),
|
|
213
|
+
host.onNotify(frame_protocol_1.HostNotice.pieceSize, (payload) => {
|
|
214
|
+
if (mine(payload))
|
|
215
|
+
setSize({ height: payload.height, width: payload.width });
|
|
216
|
+
}),
|
|
217
|
+
host.onNotify(frame_protocol_1.HostNotice.pieceFailed, (payload) => {
|
|
218
|
+
if (mine(payload))
|
|
219
|
+
setFailed(payload.message);
|
|
220
|
+
}),
|
|
221
|
+
// Escape and clicks in the piece's frame reach a popover around the slot from here.
|
|
222
|
+
host.onNotify(frame_protocol_1.HostNotice.pieceKey, (payload) => {
|
|
223
|
+
if (mine(payload))
|
|
224
|
+
dispatchEscape(slotRef.current, payload);
|
|
225
|
+
}),
|
|
226
|
+
host.onNotify(frame_protocol_1.HostNotice.outsidePointerDown, (payload) => {
|
|
227
|
+
if (mine(payload ?? {})) {
|
|
228
|
+
slotRef.current?.dispatchEvent(new Event(popover_surface_1.FRAME_POINTER_EVENT, { bubbles: true }));
|
|
229
|
+
}
|
|
230
|
+
}),
|
|
231
|
+
];
|
|
232
|
+
host
|
|
233
|
+
.request(frame_protocol_1.FrameRequest.pieceMount, {
|
|
234
|
+
slotId,
|
|
235
|
+
handle: { kind: "piece-handle", ...requested, name },
|
|
236
|
+
dataContextId: available.dataContextId,
|
|
237
|
+
props: latest.current.props,
|
|
238
|
+
height: mode,
|
|
239
|
+
...(inPopover ? { width: maxWidth } : {}),
|
|
240
|
+
})
|
|
241
|
+
.then(() => {
|
|
242
|
+
// Closed while the host drew it: the host holds it only now.
|
|
243
|
+
if (!active)
|
|
244
|
+
return host.notify(frame_protocol_1.FrameNotice.pieceUnmount, { slotId });
|
|
245
|
+
mounted.current = slotId;
|
|
246
|
+
schedule();
|
|
247
|
+
if (slotRef.current)
|
|
248
|
+
resize.observe(slotRef.current);
|
|
249
|
+
resize.observe(document.body);
|
|
250
|
+
window.addEventListener("resize", schedule);
|
|
251
|
+
document.addEventListener("scroll", schedule, true);
|
|
252
|
+
if (JSON.stringify(latest.current.props) !== propsKey) {
|
|
253
|
+
host.notify(frame_protocol_1.FrameNotice.pieceProps, { slotId, props: latest.current.props });
|
|
254
|
+
}
|
|
255
|
+
}, (error) => active && setFailed(errorText(error)));
|
|
256
|
+
// Where the slot is, sent once per animation frame while anything moves it.
|
|
257
|
+
let scheduled = 0;
|
|
258
|
+
const report = () => {
|
|
259
|
+
scheduled = 0;
|
|
260
|
+
const element = slotRef.current;
|
|
261
|
+
if (!element)
|
|
262
|
+
return;
|
|
263
|
+
const rect = element.getBoundingClientRect();
|
|
264
|
+
host.notify(frame_protocol_1.FrameNotice.pieceRect, {
|
|
265
|
+
slotId,
|
|
266
|
+
rect: { x: rect.left, y: rect.top, width: rect.width, height: rect.height },
|
|
267
|
+
clip: visibleClip(element, rect),
|
|
268
|
+
});
|
|
269
|
+
};
|
|
270
|
+
const schedule = () => {
|
|
271
|
+
if (!scheduled)
|
|
272
|
+
scheduled = requestAnimationFrame(report);
|
|
273
|
+
};
|
|
274
|
+
const resize = new ResizeObserver(schedule);
|
|
275
|
+
return () => {
|
|
276
|
+
active = false;
|
|
277
|
+
if (mounted.current === slotId) {
|
|
278
|
+
mounted.current = undefined;
|
|
279
|
+
host.notify(frame_protocol_1.FrameNotice.pieceUnmount, { slotId });
|
|
280
|
+
}
|
|
281
|
+
for (const stop of stops)
|
|
282
|
+
stop();
|
|
283
|
+
if (scheduled)
|
|
284
|
+
cancelAnimationFrame(scheduled);
|
|
285
|
+
resize.disconnect();
|
|
286
|
+
window.removeEventListener("resize", schedule);
|
|
287
|
+
document.removeEventListener("scroll", schedule, true);
|
|
288
|
+
};
|
|
289
|
+
}, [host, mode, inPopover, maxWidth]);
|
|
290
|
+
// Until the host holds the slot, its mount sends the props that are current when it does.
|
|
291
|
+
(0, react_1.useEffect)(() => {
|
|
292
|
+
const slotId = mounted.current;
|
|
293
|
+
if (slotId)
|
|
294
|
+
host?.notify(frame_protocol_1.FrameNotice.pieceProps, { slotId, props: latest.current.props });
|
|
295
|
+
}, [propsKey, host]);
|
|
296
|
+
// The piece's error boundary shows the failure, with Retry.
|
|
297
|
+
if (failed !== undefined)
|
|
298
|
+
throw new Error(failed);
|
|
299
|
+
return ((0, jsx_runtime_1.jsx)("div", { ref: slotRef, "data-peers-piece-slot": "", style: {
|
|
300
|
+
width: inPopover ? (size?.width ?? popoverStartWidth(maxWidth)) : "100%",
|
|
301
|
+
height: mode === "content" ? (size?.height ?? 24) : "100%",
|
|
302
|
+
} }));
|
|
303
|
+
}
|
|
304
|
+
const component = SlotFramedPiece;
|
|
305
|
+
slotComponents.set(key, component);
|
|
306
|
+
return component;
|
|
307
|
+
}
|
|
308
|
+
/** Whether a component from {@link inlinePieceComponent} or {@link slotPieceComponent}: for tests. */
|
|
309
|
+
function isFramedPieceComponent(component) {
|
|
310
|
+
return [...inlineComponents.values(), ...slotComponents.values()].includes(component);
|
|
311
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether the screen's package version declares a UI contract version.
|
|
3
|
+
*
|
|
4
|
+
* @param bundle - The screen's version, and the context its row is in.
|
|
5
|
+
* @param contractId - The UI contract.
|
|
6
|
+
* @param version - Its version.
|
|
7
|
+
*/
|
|
8
|
+
export declare function consumesUIContract(bundle: {
|
|
9
|
+
packageVersionId: string;
|
|
10
|
+
dataContextId: string;
|
|
11
|
+
}, contractId: string, version: number): Promise<boolean>;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.consumesUIContract = consumesUIContract;
|
|
4
|
+
const peers_sdk_1 = require("@peers-app/peers-sdk");
|
|
5
|
+
/**
|
|
6
|
+
* Whether a framed screen's package may embed a UI contract's pieces: it consumes that UI
|
|
7
|
+
* contract version (`pkg.consumes`, kept in the manifest's `uiConsumes`), or provides it itself.
|
|
8
|
+
* Read from the manifest this device stored for the screen's version, once per version.
|
|
9
|
+
*/
|
|
10
|
+
const known = new Map();
|
|
11
|
+
async function readDeclared(bundle) {
|
|
12
|
+
const user = await (0, peers_sdk_1.getUserContext)();
|
|
13
|
+
const dataContext = bundle.dataContextId === user.userId
|
|
14
|
+
? user.userDataContext
|
|
15
|
+
: user.groupDataContexts.get(bundle.dataContextId);
|
|
16
|
+
if (!dataContext)
|
|
17
|
+
throw new Error("The screen's package group is no longer available");
|
|
18
|
+
const [pv, row] = await Promise.all([
|
|
19
|
+
(0, peers_sdk_1.PackageVersions)(dataContext).get(bundle.packageVersionId),
|
|
20
|
+
(0, peers_sdk_1.PackageVersionManifests)(dataContext).get(bundle.packageVersionId),
|
|
21
|
+
]);
|
|
22
|
+
const declared = new Set();
|
|
23
|
+
if (!pv ||
|
|
24
|
+
!row ||
|
|
25
|
+
row.format !== peers_sdk_1.PACKAGE_VERSION_MANIFEST_FORMAT ||
|
|
26
|
+
row.packageId !== pv.packageId ||
|
|
27
|
+
row.packageBundleFileHash !== pv.packageBundleFileHash) {
|
|
28
|
+
return declared;
|
|
29
|
+
}
|
|
30
|
+
const manifest = JSON.parse(row.manifest);
|
|
31
|
+
if (!manifest || manifest.packageId !== pv.packageId || manifest.version !== pv.version)
|
|
32
|
+
return declared;
|
|
33
|
+
for (const entry of manifest.uiConsumes ?? [])
|
|
34
|
+
declared.add(`${entry.contractId}@${entry.version}`);
|
|
35
|
+
for (const entry of (0, peers_sdk_1.providedContracts)(manifest.uiProvides ?? [])) {
|
|
36
|
+
declared.add(`${entry.contractId}@${entry.version}`);
|
|
37
|
+
}
|
|
38
|
+
return declared;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Whether the screen's package version declares a UI contract version.
|
|
42
|
+
*
|
|
43
|
+
* @param bundle - The screen's version, and the context its row is in.
|
|
44
|
+
* @param contractId - The UI contract.
|
|
45
|
+
* @param version - Its version.
|
|
46
|
+
*/
|
|
47
|
+
async function consumesUIContract(bundle, contractId, version) {
|
|
48
|
+
const key = `${bundle.dataContextId}:${bundle.packageVersionId}`;
|
|
49
|
+
let declared = known.get(key);
|
|
50
|
+
if (!declared) {
|
|
51
|
+
declared = readDeclared(bundle);
|
|
52
|
+
known.set(key, declared);
|
|
53
|
+
declared.catch(() => known.delete(key));
|
|
54
|
+
}
|
|
55
|
+
return (await declared).has(`${contractId}@${version}`);
|
|
56
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Requests and notifications over one `MessagePort`, between a package screen's frame and its
|
|
3
|
+
* host. Payloads are encoded as the UI socket encodes them (`toJSON`, keeping bytes), so dates,
|
|
4
|
+
* `undefined` and byte arrays arrive as they were sent, and nothing the structured clone can't
|
|
5
|
+
* copy (a function, a DOM node) crosses.
|
|
6
|
+
*/
|
|
7
|
+
/** The smallest port the channel needs: a `MessagePort`, or one end of a test pair. */
|
|
8
|
+
export interface IPortLike {
|
|
9
|
+
postMessage(message: unknown): void;
|
|
10
|
+
addEventListener(type: "message", listener: (event: {
|
|
11
|
+
data: unknown;
|
|
12
|
+
}) => void): void;
|
|
13
|
+
removeEventListener(type: "message", listener: (event: {
|
|
14
|
+
data: unknown;
|
|
15
|
+
}) => void): void;
|
|
16
|
+
start?(): void;
|
|
17
|
+
close?(): void;
|
|
18
|
+
}
|
|
19
|
+
/** A request handler: its result, or what it throws, goes back to the asker. */
|
|
20
|
+
export type PortRequestHandler = (payload: any) => unknown | Promise<unknown>;
|
|
21
|
+
/** A notification handler. */
|
|
22
|
+
export type PortNotifyHandler = (payload: any) => void;
|
|
23
|
+
/** Requests and notifications over one port. */
|
|
24
|
+
export interface IPortChannel {
|
|
25
|
+
/** Ask the other side, and wait for its answer. Rejects with the error it threw. */
|
|
26
|
+
request<T = unknown>(type: string, payload?: unknown): Promise<T>;
|
|
27
|
+
/** Tell the other side something, without waiting. */
|
|
28
|
+
notify(type: string, payload?: unknown): void;
|
|
29
|
+
/** Answer one type of request. Returns a function that stops answering. */
|
|
30
|
+
onRequest(type: string, handler: PortRequestHandler): () => void;
|
|
31
|
+
/** Listen to one type of notification. Returns a function that stops listening. */
|
|
32
|
+
onNotify(type: string, handler: PortNotifyHandler): () => void;
|
|
33
|
+
/** Stop: pending requests reject, and nothing more is sent or handled. */
|
|
34
|
+
close(): void;
|
|
35
|
+
/** Whether {@link close} ran. */
|
|
36
|
+
readonly closed: boolean;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Open a channel on a port. Each side opens one on its end.
|
|
40
|
+
*
|
|
41
|
+
* @param port - The port; the channel starts it.
|
|
42
|
+
* @param opts.onUnknownRequest - Called for a request type nothing answers (the asker gets an
|
|
43
|
+
* error either way).
|
|
44
|
+
*/
|
|
45
|
+
export declare function openPortChannel(port: IPortLike, opts?: {
|
|
46
|
+
onUnknownRequest?: (type: string) => void;
|
|
47
|
+
}): IPortChannel;
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.openPortChannel = openPortChannel;
|
|
4
|
+
const peers_sdk_1 = require("@peers-app/peers-sdk");
|
|
5
|
+
function errorMessage(error) {
|
|
6
|
+
if (error instanceof Error)
|
|
7
|
+
return error.message;
|
|
8
|
+
if (typeof error === "string")
|
|
9
|
+
return error;
|
|
10
|
+
try {
|
|
11
|
+
return JSON.stringify(error);
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return String(error);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Open a channel on a port. Each side opens one on its end.
|
|
19
|
+
*
|
|
20
|
+
* @param port - The port; the channel starts it.
|
|
21
|
+
* @param opts.onUnknownRequest - Called for a request type nothing answers (the asker gets an
|
|
22
|
+
* error either way).
|
|
23
|
+
*/
|
|
24
|
+
function openPortChannel(port, opts = {}) {
|
|
25
|
+
let nextId = 1;
|
|
26
|
+
let closed = false;
|
|
27
|
+
const pending = new Map();
|
|
28
|
+
const requestHandlers = new Map();
|
|
29
|
+
const notifyHandlers = new Map();
|
|
30
|
+
const post = (message) => {
|
|
31
|
+
if (closed)
|
|
32
|
+
return;
|
|
33
|
+
port.postMessage(message);
|
|
34
|
+
};
|
|
35
|
+
const listener = (event) => {
|
|
36
|
+
if (closed)
|
|
37
|
+
return;
|
|
38
|
+
const message = event.data;
|
|
39
|
+
if (!message || typeof message !== "object")
|
|
40
|
+
return;
|
|
41
|
+
if (message.kind === "response") {
|
|
42
|
+
const entry = pending.get(message.id);
|
|
43
|
+
if (!entry)
|
|
44
|
+
return;
|
|
45
|
+
pending.delete(message.id);
|
|
46
|
+
if (message.ok) {
|
|
47
|
+
try {
|
|
48
|
+
entry.resolve((0, peers_sdk_1.fromJSON)(message.value));
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
entry.reject(error instanceof Error ? error : new Error(errorMessage(error)));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
entry.reject(new Error(message.error ?? "Request failed"));
|
|
56
|
+
}
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (message.kind === "notify") {
|
|
60
|
+
const handlers = notifyHandlers.get(message.type);
|
|
61
|
+
if (!handlers)
|
|
62
|
+
return;
|
|
63
|
+
const payload = (0, peers_sdk_1.fromJSON)(message.payload);
|
|
64
|
+
for (const handler of handlers) {
|
|
65
|
+
try {
|
|
66
|
+
handler(payload);
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
console.error(`[frame] notification '${message.type}' failed`, error);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (message.kind === "request") {
|
|
75
|
+
const { id, type } = message;
|
|
76
|
+
const handler = requestHandlers.get(type);
|
|
77
|
+
if (!handler) {
|
|
78
|
+
post({ kind: "response", id, ok: false, error: `Unknown request: ${type}` });
|
|
79
|
+
try {
|
|
80
|
+
opts.onUnknownRequest?.(type);
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
console.error(`[frame] reporting unknown request '${type}' failed`, error);
|
|
84
|
+
}
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
void (async () => {
|
|
88
|
+
try {
|
|
89
|
+
const value = await handler((0, peers_sdk_1.fromJSON)(message.payload));
|
|
90
|
+
post({ kind: "response", id, ok: true, value: (0, peers_sdk_1.toJSONKeepingBytes)(value) });
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
post({ kind: "response", id, ok: false, error: errorMessage(error) });
|
|
94
|
+
}
|
|
95
|
+
})();
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
port.addEventListener("message", listener);
|
|
99
|
+
port.start?.();
|
|
100
|
+
return {
|
|
101
|
+
request(type, payload) {
|
|
102
|
+
if (closed)
|
|
103
|
+
return Promise.reject(new Error("The frame's channel is closed"));
|
|
104
|
+
const id = nextId++;
|
|
105
|
+
return new Promise((resolve, reject) => {
|
|
106
|
+
pending.set(id, { resolve, reject });
|
|
107
|
+
try {
|
|
108
|
+
post({ kind: "request", id, type, payload: (0, peers_sdk_1.toJSONKeepingBytes)(payload) });
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
pending.delete(id);
|
|
112
|
+
reject(error instanceof Error ? error : new Error(errorMessage(error)));
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
},
|
|
116
|
+
notify(type, payload) {
|
|
117
|
+
post({ kind: "notify", type, payload: (0, peers_sdk_1.toJSONKeepingBytes)(payload) });
|
|
118
|
+
},
|
|
119
|
+
onRequest(type, handler) {
|
|
120
|
+
requestHandlers.set(type, handler);
|
|
121
|
+
return () => {
|
|
122
|
+
if (requestHandlers.get(type) === handler)
|
|
123
|
+
requestHandlers.delete(type);
|
|
124
|
+
};
|
|
125
|
+
},
|
|
126
|
+
onNotify(type, handler) {
|
|
127
|
+
let handlers = notifyHandlers.get(type);
|
|
128
|
+
if (!handlers) {
|
|
129
|
+
handlers = new Set();
|
|
130
|
+
notifyHandlers.set(type, handlers);
|
|
131
|
+
}
|
|
132
|
+
handlers.add(handler);
|
|
133
|
+
return () => {
|
|
134
|
+
handlers?.delete(handler);
|
|
135
|
+
};
|
|
136
|
+
},
|
|
137
|
+
close() {
|
|
138
|
+
if (closed)
|
|
139
|
+
return;
|
|
140
|
+
closed = true;
|
|
141
|
+
port.removeEventListener("message", listener);
|
|
142
|
+
for (const entry of pending.values())
|
|
143
|
+
entry.reject(new Error("The frame closed"));
|
|
144
|
+
pending.clear();
|
|
145
|
+
requestHandlers.clear();
|
|
146
|
+
notifyHandlers.clear();
|
|
147
|
+
port.close?.();
|
|
148
|
+
},
|
|
149
|
+
get closed() {
|
|
150
|
+
return closed;
|
|
151
|
+
},
|
|
152
|
+
};
|
|
153
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { IPeersUIRoute } from "@peers-app/peers-sdk";
|
|
2
|
+
/**
|
|
3
|
+
* Run one package's routes bundle in the sandbox and return its routes, stamped with the package.
|
|
4
|
+
*
|
|
5
|
+
* @param packageId - The package whose bundle it is.
|
|
6
|
+
* @param code - The bundle, checked by the caller.
|
|
7
|
+
*/
|
|
8
|
+
export declare function evaluateRoutesBundle(packageId: string, code: string): Promise<IPeersUIRoute[]>;
|