@peers-app/peers-ui 0.34.6 → 0.34.8
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-ui.js +14 -14
- package/dist/command-palette/command-palette.d.ts +10 -3
- package/dist/command-palette/command-palette.js +60 -6
- package/dist/command-palette/frame-commands.d.ts +37 -0
- package/dist/command-palette/frame-commands.js +43 -0
- package/dist/components/markdown-editor/editor.d.ts +5 -4
- package/dist/components/markdown-editor/editor.js +10 -145
- package/dist/components/markdown-editor/lexical-editor.d.ts +3 -0
- package/dist/components/markdown-editor/lexical-editor.js +153 -0
- package/dist/components/markdown-render.d.ts +8 -0
- package/dist/components/markdown-render.js +143 -0
- package/dist/components/markdown-with-mentions.d.ts +1 -1
- package/dist/components/markdown-with-mentions.js +7 -129
- package/dist/components/trust-level-dropdown.d.ts +6 -1
- package/dist/components/trust-level-dropdown.js +43 -14
- package/dist/globals.d.ts +13 -2
- package/dist/globals.js +24 -2
- package/dist/index.d.ts +2 -1
- package/dist/index.js +9 -1
- package/dist/isolated-screens/config.js +1 -5
- package/dist/isolated-screens/focus-relay.d.ts +24 -0
- package/dist/isolated-screens/focus-relay.js +104 -0
- package/dist/isolated-screens/frame-document.d.ts +7 -0
- package/dist/isolated-screens/frame-document.js +11 -1
- package/dist/isolated-screens/frame-permissions.d.ts +11 -0
- package/dist/isolated-screens/frame-permissions.js +33 -0
- package/dist/isolated-screens/frame-protocol.d.ts +90 -0
- package/dist/isolated-screens/frame-protocol.js +49 -0
- package/dist/isolated-screens/frame-runtime.js +115 -16
- package/dist/isolated-screens/frame-viewport.d.ts +9 -0
- package/dist/isolated-screens/frame-viewport.js +36 -0
- package/dist/isolated-screens/global-widgets.d.ts +74 -0
- package/dist/isolated-screens/global-widgets.js +270 -0
- package/dist/isolated-screens/isolated-screen.d.ts +57 -1
- package/dist/isolated-screens/isolated-screen.js +266 -15
- package/dist/isolated-screens/piece-frames.js +57 -5
- package/dist/isolated-screens/piece-reach.d.ts +24 -0
- package/dist/isolated-screens/piece-reach.js +40 -13
- package/dist/isolated-screens/widget-box.d.ts +48 -0
- package/dist/isolated-screens/widget-box.js +193 -0
- package/dist/lazy-module.d.ts +17 -0
- package/dist/lazy-module.js +26 -0
- package/dist/operator-console/console-session.js +1 -9
- package/dist/operator-console/operator-console-state.js +5 -1
- package/dist/root-layout/root-layout-host.js +3 -1
- package/dist/screens/groups/group-members.js +7 -17
- package/dist/screens/invites/accept-invite.js +15 -4
- package/dist/screens/packages/package-info.js +2 -1
- package/dist/screens/packages/package-widgets-panel.d.ts +15 -0
- package/dist/screens/packages/package-widgets-panel.js +64 -0
- package/dist/tabs-layout/tabs-state.d.ts +5 -2
- package/dist/tabs-layout/tabs-state.js +41 -17
- package/dist/ui-contracts/piece-height.d.ts +8 -2
- package/dist/ui-contracts/piece-height.js +6 -1
- package/dist/ui-contracts/piece.js +1 -1
- package/package.json +4 -3
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Tab across a piece drawn over a framed screen's slot. The host draws the piece's frame beside
|
|
3
|
+
// the screen's frame, not inside it, so the browser's Tab order skips from the control before the
|
|
4
|
+
// slot to the control after it. The screen's slot takes focus in its place and the host moves it
|
|
5
|
+
// into the piece's frame; the piece's frame hands it back when Tab leaves its first or last
|
|
6
|
+
// control (frame-protocol.ts: `pieceFocus`, `focusEdge`, `focusLeave`, `pieceFocusLeave`).
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.tabbables = tabbables;
|
|
9
|
+
exports.focusEdge = focusEdge;
|
|
10
|
+
exports.tabLeaves = tabLeaves;
|
|
11
|
+
exports.edgeEnteredFrom = edgeEnteredFrom;
|
|
12
|
+
exports.focusBeside = focusBeside;
|
|
13
|
+
// A named radio group with a selection has one stop. Unselected groups are :indeterminate.
|
|
14
|
+
const TABBABLE = `:is(
|
|
15
|
+
a[href], area[href], button, input, select, textarea, iframe, details > summary:first-of-type,
|
|
16
|
+
[contenteditable='true'], [contenteditable='plaintext-only'], [contenteditable=''], [tabindex]
|
|
17
|
+
):not(:disabled, input[type='hidden'], [inert], [inert] *)` +
|
|
18
|
+
":not(input[type='radio'][name]:not([name=''], :checked, :indeterminate))";
|
|
19
|
+
/** The elements Tab stops at in a document, in document order (positive tabindex aside). */
|
|
20
|
+
function tabbables(doc) {
|
|
21
|
+
return [...doc.querySelectorAll(TABBABLE)].filter((element) => {
|
|
22
|
+
// An editing host is a native Tab stop even when its implicit tabIndex reads as -1.
|
|
23
|
+
if (element.tabIndex < 0 &&
|
|
24
|
+
(!element.hasAttribute("contenteditable") ||
|
|
25
|
+
element.hasAttribute("tabindex") ||
|
|
26
|
+
element.parentElement?.isContentEditable)) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
return (element.checkVisibility?.({ checkVisibilityCSS: true }) ??
|
|
30
|
+
(element.getClientRects().length > 0 && getComputedStyle(element).visibility === "visible"));
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Focus a document's first or last control.
|
|
35
|
+
*
|
|
36
|
+
* @returns Whether it had one.
|
|
37
|
+
*/
|
|
38
|
+
function focusEdge(doc, edge) {
|
|
39
|
+
const all = tabbables(doc);
|
|
40
|
+
const target = edge === "first" ? all[0] : all[all.length - 1];
|
|
41
|
+
target?.focus();
|
|
42
|
+
return target !== undefined;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Whether Tab (or Shift+Tab) on the focused element leaves the document's controls: from its last
|
|
46
|
+
* control, its first, or from nothing focusable.
|
|
47
|
+
*/
|
|
48
|
+
function tabLeaves(doc, backwards) {
|
|
49
|
+
const all = tabbables(doc);
|
|
50
|
+
if (all.length === 0)
|
|
51
|
+
return true;
|
|
52
|
+
const active = doc.activeElement;
|
|
53
|
+
const direction = backwards ? Node.DOCUMENT_POSITION_PRECEDING : Node.DOCUMENT_POSITION_FOLLOWING;
|
|
54
|
+
if (!active || active === doc.body || active === doc.documentElement) {
|
|
55
|
+
// A click or Shift+click on text puts the selection's focus at the clicked end, and a text
|
|
56
|
+
// field that is blurred or removed leaves it at the field's place in its parent. It
|
|
57
|
+
// approximates the browser's Tab starting point, which can differ after a drag.
|
|
58
|
+
// With no selection in the body, let the browser choose the next control.
|
|
59
|
+
const selection = doc.getSelection();
|
|
60
|
+
const from = selection?.focusNode;
|
|
61
|
+
if (!selection || !from || !doc.body.contains(from))
|
|
62
|
+
return false;
|
|
63
|
+
// A point, not a node: in an element, the offset says which children come before it. A stop
|
|
64
|
+
// around the point is on neither side.
|
|
65
|
+
const point = doc.createRange();
|
|
66
|
+
point.setStart(from, selection.focusOffset);
|
|
67
|
+
return !all.some((stop) => backwards
|
|
68
|
+
? point.comparePoint(stop, stop.childNodes.length) < 0
|
|
69
|
+
: point.comparePoint(stop, 0) > 0);
|
|
70
|
+
}
|
|
71
|
+
// When no radio is selected yet, Tab enters the group at either end, then skips its peers.
|
|
72
|
+
if (active instanceof HTMLInputElement &&
|
|
73
|
+
active.type === "radio" &&
|
|
74
|
+
active.name &&
|
|
75
|
+
!active.checked) {
|
|
76
|
+
return !all.some((stop) => (active.compareDocumentPosition(stop) & direction) !== 0 &&
|
|
77
|
+
!(stop instanceof HTMLInputElement &&
|
|
78
|
+
stop.type === "radio" &&
|
|
79
|
+
stop.name === active.name &&
|
|
80
|
+
stop.form === active.form));
|
|
81
|
+
}
|
|
82
|
+
// A click can focus a control with tabindex=-1. Tab resumes at its position in the document.
|
|
83
|
+
return !all.some((stop) => (active.compareDocumentPosition(stop) & direction) !== 0);
|
|
84
|
+
}
|
|
85
|
+
/** The edge focus enters a slot at, from the element focus came from. */
|
|
86
|
+
function edgeEnteredFrom(slot, from) {
|
|
87
|
+
// DOCUMENT_POSITION_FOLLOWING: `from` comes after the slot, so Shift+Tab brought focus back.
|
|
88
|
+
return from && slot.compareDocumentPosition(from) & Node.DOCUMENT_POSITION_FOLLOWING
|
|
89
|
+
? "last"
|
|
90
|
+
: "first";
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Focus the control after (or before) a slot in its document, leaving the slot itself out. With
|
|
94
|
+
* none there, focus leaves the slot.
|
|
95
|
+
*/
|
|
96
|
+
function focusBeside(slot, direction) {
|
|
97
|
+
const all = tabbables(slot.ownerDocument).filter((element) => element === slot || !slot.contains(element));
|
|
98
|
+
const at = all.indexOf(slot);
|
|
99
|
+
const target = at === -1 ? undefined : all[direction === "next" ? at + 1 : at - 1];
|
|
100
|
+
if (target)
|
|
101
|
+
target.focus();
|
|
102
|
+
else
|
|
103
|
+
slot.blur();
|
|
104
|
+
}
|
|
@@ -9,6 +9,13 @@
|
|
|
9
9
|
* The script says hello to the parent once. The host, which made the frame and knows its window,
|
|
10
10
|
* answers with the frame runtime's source and a `MessagePort`; the script keeps the port where the
|
|
11
11
|
* runtime's first module finds it and runs the source. A second boot is ignored.
|
|
12
|
+
*
|
|
13
|
+
* The source runs as a script element, not through `eval`. Every frame gets the same source, and
|
|
14
|
+
* Chromium compiles a script once for all the frames in its process, where it compiles each
|
|
15
|
+
* frame's `eval` again: a frame after the first starts in about a fifth of the time (35 ms
|
|
16
|
+
* instead of 175 here). WebKit reuses the compiled code either way.
|
|
17
|
+
* The script has run once it's in the document, so it's taken out again: its text would
|
|
18
|
+
* otherwise keep a copy of the runtime's source in every frame (about 7 MB each).
|
|
12
19
|
*/
|
|
13
20
|
/** The message a frame's document sends its parent when it's ready to boot. */
|
|
14
21
|
export declare const FRAME_HELLO = "peers-frame-hello";
|
|
@@ -10,6 +10,13 @@
|
|
|
10
10
|
* The script says hello to the parent once. The host, which made the frame and knows its window,
|
|
11
11
|
* answers with the frame runtime's source and a `MessagePort`; the script keeps the port where the
|
|
12
12
|
* runtime's first module finds it and runs the source. A second boot is ignored.
|
|
13
|
+
*
|
|
14
|
+
* The source runs as a script element, not through `eval`. Every frame gets the same source, and
|
|
15
|
+
* Chromium compiles a script once for all the frames in its process, where it compiles each
|
|
16
|
+
* frame's `eval` again: a frame after the first starts in about a fifth of the time (35 ms
|
|
17
|
+
* instead of 175 here). WebKit reuses the compiled code either way.
|
|
18
|
+
* The script has run once it's in the document, so it's taken out again: its text would
|
|
19
|
+
* otherwise keep a copy of the runtime's source in every frame (about 7 MB each).
|
|
13
20
|
*/
|
|
14
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
22
|
exports.FRAME_CSP = exports.FRAME_PORT_GLOBAL = exports.FRAME_BOOT = exports.FRAME_HELLO = void 0;
|
|
@@ -67,7 +74,10 @@ ${surface}
|
|
|
67
74
|
if (booted || event.source !== parent || !data || data.type !== "${exports.FRAME_BOOT}") return;
|
|
68
75
|
booted = true;
|
|
69
76
|
window.${exports.FRAME_PORT_GLOBAL} = event.ports[0];
|
|
70
|
-
|
|
77
|
+
var script = document.createElement("script");
|
|
78
|
+
script.textContent = data.runtime;
|
|
79
|
+
document.head.appendChild(script);
|
|
80
|
+
script.remove();
|
|
71
81
|
});
|
|
72
82
|
parent.postMessage({ type: "${exports.FRAME_HELLO}" }, "*");
|
|
73
83
|
})();
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type Observable } from "@peers-app/peers-sdk";
|
|
2
|
+
/** The global widgets turned off on this device, as `<packageId>:<widgetId>`. */
|
|
3
|
+
export declare const globalWidgetsOff: Observable<string[]>;
|
|
4
|
+
/**
|
|
5
|
+
* Turn one of a package's global widgets off on this device, or back on.
|
|
6
|
+
*
|
|
7
|
+
* @param packageId - The package.
|
|
8
|
+
* @param widgetId - The widget's id in it.
|
|
9
|
+
* @param on - Whether it shows.
|
|
10
|
+
*/
|
|
11
|
+
export declare function setGlobalWidgetOn(packageId: string, widgetId: string, on: boolean): void;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.globalWidgetsOff = void 0;
|
|
4
|
+
exports.setGlobalWidgetOn = setGlobalWidgetOn;
|
|
5
|
+
const peers_sdk_1 = require("@peers-app/peers-sdk");
|
|
6
|
+
const frame_realm_1 = require("./frame-realm");
|
|
7
|
+
// What the person chose for packages' global widgets on this device. Peers' own variables: a
|
|
8
|
+
// package's frame can't read or write them, since its variables are stored under its own id.
|
|
9
|
+
/**
|
|
10
|
+
* One of Peers' own device lists, in the window. Every package's frame loads this module too
|
|
11
|
+
* (it's part of peers-ui) but never reads these, so there it's a plain list, and the frame's
|
|
12
|
+
* start doesn't ask the host for variables it has no use for.
|
|
13
|
+
*
|
|
14
|
+
* @param name - The variable's name.
|
|
15
|
+
*/
|
|
16
|
+
function hostDeviceList(name) {
|
|
17
|
+
return (0, frame_realm_1.isInFrame)() ? (0, peers_sdk_1.observable)([]) : (0, peers_sdk_1.deviceVar)(name, { defaultValue: [] });
|
|
18
|
+
}
|
|
19
|
+
/** The global widgets turned off on this device, as `<packageId>:<widgetId>`. */
|
|
20
|
+
exports.globalWidgetsOff = hostDeviceList("globalWidgetsOff");
|
|
21
|
+
/**
|
|
22
|
+
* Turn one of a package's global widgets off on this device, or back on.
|
|
23
|
+
*
|
|
24
|
+
* @param packageId - The package.
|
|
25
|
+
* @param widgetId - The widget's id in it.
|
|
26
|
+
* @param on - Whether it shows.
|
|
27
|
+
*/
|
|
28
|
+
function setGlobalWidgetOn(packageId, widgetId, on) {
|
|
29
|
+
const key = `${packageId}:${widgetId}`;
|
|
30
|
+
const current = Array.isArray((0, exports.globalWidgetsOff)()) ? (0, exports.globalWidgetsOff)() : [];
|
|
31
|
+
const without = current.filter((entry) => entry !== key);
|
|
32
|
+
(0, exports.globalWidgetsOff)(on ? without : [...without, key]);
|
|
33
|
+
}
|
|
@@ -43,6 +43,19 @@ export interface IFrameInit {
|
|
|
43
43
|
width?: number;
|
|
44
44
|
/** The emits the embedder's version declares: the piece's `emit` has these, and `open`. */
|
|
45
45
|
emits?: string[];
|
|
46
|
+
/**
|
|
47
|
+
* Drawn over a framed screen's slot: Tab leaving its first or last control goes back to the
|
|
48
|
+
* screen through the host (`focusLeave`), and the host moves focus in (`focusEdge`).
|
|
49
|
+
*/
|
|
50
|
+
overSlot?: boolean;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* For a global widget's frame instead of a screen's: the widget's id in its package, and where
|
|
54
|
+
* the host put the frame (see {@link IWidgetPlacement}). The UI to draw is `peersUIId`.
|
|
55
|
+
*/
|
|
56
|
+
widget?: {
|
|
57
|
+
id: string;
|
|
58
|
+
placement: IWidgetPlacement;
|
|
46
59
|
};
|
|
47
60
|
/** The tab's path. */
|
|
48
61
|
path: string;
|
|
@@ -56,6 +69,34 @@ export interface IFrameInit {
|
|
|
56
69
|
*/
|
|
57
70
|
legacyStorage: Record<string, string>;
|
|
58
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* Where the host put a global widget's frame, in the window's coordinates, and the window's size.
|
|
74
|
+
* The widget's frame lays its content out as if it were the whole window, shifted by `x` and `y`,
|
|
75
|
+
* so `position: fixed` in the widget means the window.
|
|
76
|
+
*/
|
|
77
|
+
export interface IWidgetPlacement {
|
|
78
|
+
x: number;
|
|
79
|
+
y: number;
|
|
80
|
+
width: number;
|
|
81
|
+
height: number;
|
|
82
|
+
/** The window's width. */
|
|
83
|
+
viewportWidth: number;
|
|
84
|
+
/** The window's height. */
|
|
85
|
+
viewportHeight: number;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* A command a package's frame adds to the command palette: everything but its action. It's listed
|
|
89
|
+
* under its package's name, whatever category the frame gives it.
|
|
90
|
+
*/
|
|
91
|
+
export interface IFrameCommand {
|
|
92
|
+
/** Its id within the package. */
|
|
93
|
+
id: string;
|
|
94
|
+
label: string;
|
|
95
|
+
description?: string;
|
|
96
|
+
/** As `Command.shortcut`: `Cmd+J` and the like, with ⌘ or Ctrl. */
|
|
97
|
+
shortcut?: string;
|
|
98
|
+
iconClassName?: string;
|
|
99
|
+
}
|
|
59
100
|
/** A request the frame makes of the host, by name. */
|
|
60
101
|
export declare const FrameRequest: {
|
|
61
102
|
/** A legacy RPC call (`rpcServerCalls`), checked by the host's policy. */
|
|
@@ -93,6 +134,18 @@ export declare const FrameRequest: {
|
|
|
93
134
|
* keeps, as Retry does in its own window, and every screen resolves its pieces again.
|
|
94
135
|
*/
|
|
95
136
|
readonly pieceRetry: "piece.retry";
|
|
137
|
+
/**
|
|
138
|
+
* Add a command to the host's command palette, as the frame's package: an
|
|
139
|
+
* {@link IFrameCommand}. The host runs it by telling this frame (`command.run`).
|
|
140
|
+
*/
|
|
141
|
+
readonly commandRegister: "command.register";
|
|
142
|
+
/** Remove one of the frame's commands: `{ id }`. */
|
|
143
|
+
readonly commandUnregister: "command.unregister";
|
|
144
|
+
/**
|
|
145
|
+
* Run one of the frame's package's commands, which another of the package's frames registered
|
|
146
|
+
* (a screen asking its global widget to open): `{ id }`.
|
|
147
|
+
*/
|
|
148
|
+
readonly commandRun: "command.run";
|
|
96
149
|
};
|
|
97
150
|
/** A notification the frame sends the host, by name. */
|
|
98
151
|
export declare const FrameNotice: {
|
|
@@ -124,6 +177,18 @@ export declare const FrameNotice: {
|
|
|
124
177
|
readonly pieceEmit: "piece.emit";
|
|
125
178
|
/** From a piece's frame: it asked to close. */
|
|
126
179
|
readonly pieceClose: "piece.close";
|
|
180
|
+
/** From a piece's frame: it has drawn its piece, so the embedder's loading view can go. */
|
|
181
|
+
readonly pieceDrawn: "piece.drawn";
|
|
182
|
+
/**
|
|
183
|
+
* From a screen: Tab reached a piece's slot, `{ slotId, edge }` (`first` with Tab, `last` with
|
|
184
|
+
* Shift+Tab). The host moves focus into the piece's frame drawn over it.
|
|
185
|
+
*/
|
|
186
|
+
readonly pieceFocus: "piece.focus";
|
|
187
|
+
/**
|
|
188
|
+
* From a piece's frame drawn over a slot: Tab left its last control, or Shift+Tab its first,
|
|
189
|
+
* `{ direction }` (`next` or `previous`). The host hands focus back to the screen.
|
|
190
|
+
*/
|
|
191
|
+
readonly focusLeave: "focus.leave";
|
|
127
192
|
/**
|
|
128
193
|
* From a piece's frame that takes its own height: its content's height, `{ height }`, and its
|
|
129
194
|
* width, `{ width }`, when it takes its content's width too.
|
|
@@ -142,6 +207,18 @@ export declare const FrameNotice: {
|
|
|
142
207
|
readonly wheel: "frame.wheel";
|
|
143
208
|
/** The user asked to start a screen that failed to load again: the host makes a new frame. */
|
|
144
209
|
readonly restart: "frame.restart";
|
|
210
|
+
/**
|
|
211
|
+
* From a global widget's frame: the box its content covers, in the window's coordinates,
|
|
212
|
+
* `{ box: { x, y, width, height } }`, or `{ box: null }` when it draws nothing. The host puts the
|
|
213
|
+
* frame over that box.
|
|
214
|
+
*/
|
|
215
|
+
readonly widgetBox: "widget.box";
|
|
216
|
+
/**
|
|
217
|
+
* From a global widget's frame: an element in it captured the pointer (`{ active: true }`, a drag
|
|
218
|
+
* started) or let it go (`{ active: false }`). While it holds it, the frame covers the window,
|
|
219
|
+
* so the drag doesn't lose the pointer at the frame's edge.
|
|
220
|
+
*/
|
|
221
|
+
readonly widgetCapture: "widget.capture";
|
|
145
222
|
};
|
|
146
223
|
/** A request the host makes of the frame, by name. */
|
|
147
224
|
export declare const HostRequest: {
|
|
@@ -168,6 +245,15 @@ export declare const HostNotice: {
|
|
|
168
245
|
readonly pieceEmit: "piece.emit";
|
|
169
246
|
/** A piece the screen embeds asked to close: `{ slotId }`. */
|
|
170
247
|
readonly pieceClose: "piece.close";
|
|
248
|
+
/** A piece the screen embeds has drawn: `{ slotId }`. Its loading view can go. */
|
|
249
|
+
readonly pieceDrawn: "piece.drawn";
|
|
250
|
+
/** To a piece's frame: focus came in from its screen, `{ edge }`: its first or last control. */
|
|
251
|
+
readonly focusEdge: "focus.edge";
|
|
252
|
+
/**
|
|
253
|
+
* To a screen: Tab left the piece over `slotId`, `{ slotId, direction }`. The screen focuses
|
|
254
|
+
* the control after the slot (`next`) or before it (`previous`).
|
|
255
|
+
*/
|
|
256
|
+
readonly pieceFocusLeave: "piece.focus-leave";
|
|
171
257
|
/**
|
|
172
258
|
* A piece the screen embeds, which takes its own height, is now `{ slotId, height }` tall, and
|
|
173
259
|
* `width` wide when it takes its content's width.
|
|
@@ -193,4 +279,8 @@ export declare const HostNotice: {
|
|
|
193
279
|
readonly pieceWheel: "piece.wheel";
|
|
194
280
|
/** Something a piece resolution depends on changed: the screen resolves its pieces again. */
|
|
195
281
|
readonly pieceRevision: "piece.revision";
|
|
282
|
+
/** A global widget's frame moved: an {@link IWidgetPlacement}. */
|
|
283
|
+
readonly widgetPlacement: "widget.placement";
|
|
284
|
+
/** Run one of the frame's commands: `{ id }`. */
|
|
285
|
+
readonly commandRun: "command.run";
|
|
196
286
|
};
|
|
@@ -47,6 +47,18 @@ exports.FrameRequest = {
|
|
|
47
47
|
* keeps, as Retry does in its own window, and every screen resolves its pieces again.
|
|
48
48
|
*/
|
|
49
49
|
pieceRetry: "piece.retry",
|
|
50
|
+
/**
|
|
51
|
+
* Add a command to the host's command palette, as the frame's package: an
|
|
52
|
+
* {@link IFrameCommand}. The host runs it by telling this frame (`command.run`).
|
|
53
|
+
*/
|
|
54
|
+
commandRegister: "command.register",
|
|
55
|
+
/** Remove one of the frame's commands: `{ id }`. */
|
|
56
|
+
commandUnregister: "command.unregister",
|
|
57
|
+
/**
|
|
58
|
+
* Run one of the frame's package's commands, which another of the package's frames registered
|
|
59
|
+
* (a screen asking its global widget to open): `{ id }`.
|
|
60
|
+
*/
|
|
61
|
+
commandRun: "command.run",
|
|
50
62
|
};
|
|
51
63
|
/** A notification the frame sends the host, by name. */
|
|
52
64
|
exports.FrameNotice = {
|
|
@@ -78,6 +90,18 @@ exports.FrameNotice = {
|
|
|
78
90
|
pieceEmit: "piece.emit",
|
|
79
91
|
/** From a piece's frame: it asked to close. */
|
|
80
92
|
pieceClose: "piece.close",
|
|
93
|
+
/** From a piece's frame: it has drawn its piece, so the embedder's loading view can go. */
|
|
94
|
+
pieceDrawn: "piece.drawn",
|
|
95
|
+
/**
|
|
96
|
+
* From a screen: Tab reached a piece's slot, `{ slotId, edge }` (`first` with Tab, `last` with
|
|
97
|
+
* Shift+Tab). The host moves focus into the piece's frame drawn over it.
|
|
98
|
+
*/
|
|
99
|
+
pieceFocus: "piece.focus",
|
|
100
|
+
/**
|
|
101
|
+
* From a piece's frame drawn over a slot: Tab left its last control, or Shift+Tab its first,
|
|
102
|
+
* `{ direction }` (`next` or `previous`). The host hands focus back to the screen.
|
|
103
|
+
*/
|
|
104
|
+
focusLeave: "focus.leave",
|
|
81
105
|
/**
|
|
82
106
|
* From a piece's frame that takes its own height: its content's height, `{ height }`, and its
|
|
83
107
|
* width, `{ width }`, when it takes its content's width too.
|
|
@@ -96,6 +120,18 @@ exports.FrameNotice = {
|
|
|
96
120
|
wheel: "frame.wheel",
|
|
97
121
|
/** The user asked to start a screen that failed to load again: the host makes a new frame. */
|
|
98
122
|
restart: "frame.restart",
|
|
123
|
+
/**
|
|
124
|
+
* From a global widget's frame: the box its content covers, in the window's coordinates,
|
|
125
|
+
* `{ box: { x, y, width, height } }`, or `{ box: null }` when it draws nothing. The host puts the
|
|
126
|
+
* frame over that box.
|
|
127
|
+
*/
|
|
128
|
+
widgetBox: "widget.box",
|
|
129
|
+
/**
|
|
130
|
+
* From a global widget's frame: an element in it captured the pointer (`{ active: true }`, a drag
|
|
131
|
+
* started) or let it go (`{ active: false }`). While it holds it, the frame covers the window,
|
|
132
|
+
* so the drag doesn't lose the pointer at the frame's edge.
|
|
133
|
+
*/
|
|
134
|
+
widgetCapture: "widget.capture",
|
|
99
135
|
};
|
|
100
136
|
/** A request the host makes of the frame, by name. */
|
|
101
137
|
exports.HostRequest = {
|
|
@@ -122,6 +158,15 @@ exports.HostNotice = {
|
|
|
122
158
|
pieceEmit: "piece.emit",
|
|
123
159
|
/** A piece the screen embeds asked to close: `{ slotId }`. */
|
|
124
160
|
pieceClose: "piece.close",
|
|
161
|
+
/** A piece the screen embeds has drawn: `{ slotId }`. Its loading view can go. */
|
|
162
|
+
pieceDrawn: "piece.drawn",
|
|
163
|
+
/** To a piece's frame: focus came in from its screen, `{ edge }`: its first or last control. */
|
|
164
|
+
focusEdge: "focus.edge",
|
|
165
|
+
/**
|
|
166
|
+
* To a screen: Tab left the piece over `slotId`, `{ slotId, direction }`. The screen focuses
|
|
167
|
+
* the control after the slot (`next`) or before it (`previous`).
|
|
168
|
+
*/
|
|
169
|
+
pieceFocusLeave: "piece.focus-leave",
|
|
125
170
|
/**
|
|
126
171
|
* A piece the screen embeds, which takes its own height, is now `{ slotId, height }` tall, and
|
|
127
172
|
* `width` wide when it takes its content's width.
|
|
@@ -147,4 +192,8 @@ exports.HostNotice = {
|
|
|
147
192
|
pieceWheel: "piece.wheel",
|
|
148
193
|
/** Something a piece resolution depends on changed: the screen resolves its pieces again. */
|
|
149
194
|
pieceRevision: "piece.revision",
|
|
195
|
+
/** A global widget's frame moved: an {@link IWidgetPlacement}. */
|
|
196
|
+
widgetPlacement: "widget.placement",
|
|
197
|
+
/** Run one of the frame's commands: `{ id }`. */
|
|
198
|
+
commandRun: "command.run",
|
|
150
199
|
};
|
|
@@ -5,6 +5,7 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
5
5
|
const peers_sdk_1 = require("@peers-app/peers-sdk");
|
|
6
6
|
const react_1 = require("react");
|
|
7
7
|
const client_1 = require("react-dom/client");
|
|
8
|
+
const frame_commands_1 = require("../command-palette/frame-commands");
|
|
8
9
|
const globals_1 = require("../globals");
|
|
9
10
|
const hooks_1 = require("../hooks");
|
|
10
11
|
const global_overlays_1 = require("../root-layout/global-overlays");
|
|
@@ -13,9 +14,12 @@ const piece_height_1 = require("../ui-contracts/piece-height");
|
|
|
13
14
|
const piece_resolution_1 = require("../ui-contracts/piece-resolution");
|
|
14
15
|
const popover_surface_1 = require("../ui-contracts/popover-surface");
|
|
15
16
|
const ui_inspection_1 = require("../ui-inspection");
|
|
17
|
+
const focus_relay_1 = require("./focus-relay");
|
|
16
18
|
const frame_bridge_1 = require("./frame-bridge");
|
|
17
19
|
const frame_protocol_1 = require("./frame-protocol");
|
|
20
|
+
const frame_viewport_1 = require("./frame-viewport");
|
|
18
21
|
const wheel_relay_1 = require("./wheel-relay");
|
|
22
|
+
const widget_box_1 = require("./widget-box");
|
|
19
23
|
let root;
|
|
20
24
|
let setScreen;
|
|
21
25
|
let pending = { props: {} };
|
|
@@ -24,6 +28,12 @@ const pieces = new Map();
|
|
|
24
28
|
let loadedVersionId;
|
|
25
29
|
/** Whether this frame draws a piece, whose Escape and wheel go to its embedder. */
|
|
26
30
|
let drawsPiece = false;
|
|
31
|
+
/** Whether this frame's piece is drawn over a framed screen's slot, so Tab out goes through the host. */
|
|
32
|
+
let relaysTab = false;
|
|
33
|
+
/** Whether this frame draws a global widget, over the window. */
|
|
34
|
+
let drawsWidget = false;
|
|
35
|
+
/** For a global widget's frame: where the host put it. */
|
|
36
|
+
let placement;
|
|
27
37
|
/**
|
|
28
38
|
* Apply the host's theme. The starting document uses the theme attribute for its color scheme
|
|
29
39
|
* and keeps a piece's background transparent across page color updates.
|
|
@@ -31,7 +41,7 @@ let drawsPiece = false;
|
|
|
31
41
|
function applyTheme(mode) {
|
|
32
42
|
const html = document.documentElement;
|
|
33
43
|
html.setAttribute("data-bs-theme", mode);
|
|
34
|
-
if (drawsPiece)
|
|
44
|
+
if (drawsPiece || drawsWidget)
|
|
35
45
|
return;
|
|
36
46
|
const background = mode === "dark" ? "rgb(33, 37, 41)" : "";
|
|
37
47
|
html.style.backgroundColor = background;
|
|
@@ -89,6 +99,10 @@ function FrameScreen(props) {
|
|
|
89
99
|
if (!state.ui)
|
|
90
100
|
return null;
|
|
91
101
|
const Screen = state.ui.content;
|
|
102
|
+
if (state.widget) {
|
|
103
|
+
// A global widget draws over the window: no tab's box around it, and no package overlays.
|
|
104
|
+
return ((0, jsx_runtime_1.jsx)(ScreenErrorBoundary, { packageName: props.packageName, onError: (message) => props.host.notify(frame_protocol_1.FrameNotice.failed, { message }), children: (0, jsx_runtime_1.jsx)(Screen, { ...state.props }) }));
|
|
105
|
+
}
|
|
92
106
|
// The same box a tab draws around a screen in the host, so a screen's CSS that cancels the
|
|
93
107
|
// tab's padding (`.p-3 > .x-app`) still lines up.
|
|
94
108
|
return ((0, jsx_runtime_1.jsx)("div", { className: `h-100 overflow-auto ${desktop ? "p-3" : "p-2"}`, children: (0, jsx_runtime_1.jsxs)(ScreenErrorBoundary, { packageName: props.packageName, onError: (message) => props.host.notify(frame_protocol_1.FrameNotice.failed, { message }), children: [(0, jsx_runtime_1.jsx)(Screen, { ...state.props }), (0, jsx_runtime_1.jsx)(FrameOverlays, {})] }) }));
|
|
@@ -116,6 +130,19 @@ function frameEmitters(host, names) {
|
|
|
116
130
|
function PieceInFrame(props) {
|
|
117
131
|
const { host, piece } = props;
|
|
118
132
|
const emit = (0, react_1.useMemo)(() => frameEmitters(host, piece.emits), [host, piece.emits.join("\n")]);
|
|
133
|
+
// Once the piece's first render is on the page, the embedder's loading view can go.
|
|
134
|
+
(0, react_1.useEffect)(() => {
|
|
135
|
+
host.notify(frame_protocol_1.FrameNotice.pieceDrawn);
|
|
136
|
+
}, [host]);
|
|
137
|
+
// A piece in a popover paints the popover's background, from its first render: over a slot the
|
|
138
|
+
// host leaves the frame clear until then (isolated-screen.tsx), and the slot paints it instead.
|
|
139
|
+
(0, react_1.useLayoutEffect)(() => {
|
|
140
|
+
if (piece.width === undefined)
|
|
141
|
+
return;
|
|
142
|
+
const html = document.documentElement;
|
|
143
|
+
html.classList.add("bg-body");
|
|
144
|
+
return () => html.classList.remove("bg-body");
|
|
145
|
+
}, [piece.width]);
|
|
119
146
|
const Component = piece.component;
|
|
120
147
|
return ((0, jsx_runtime_1.jsx)(PieceRoot, { host: host, height: piece.height, width: piece.width, children: (0, jsx_runtime_1.jsx)(ScreenErrorBoundary, { packageName: props.packageName, onError: (message) => host.notify(frame_protocol_1.FrameNotice.failed, { message }), children: (0, jsx_runtime_1.jsx)(Component, { props: props.props, emit: emit, close: () => host.notify(frame_protocol_1.FrameNotice.pieceClose), groupId: piece.groupId }) }) }));
|
|
121
148
|
}
|
|
@@ -123,11 +150,13 @@ function PieceInFrame(props) {
|
|
|
123
150
|
* The box a framed piece draws in: measured for `usePieceSize`, and, for a piece that takes its
|
|
124
151
|
* own height (and in a popover its width), reported to the host. The size lives here, apart from
|
|
125
152
|
* the piece, so a resize re-renders only what reads it, as `<Piece>`'s box does in the window.
|
|
153
|
+
* The frame of a piece that takes its own height never scrolls (`holdFrameViewport`).
|
|
126
154
|
*/
|
|
127
155
|
function PieceRoot(props) {
|
|
128
156
|
const { host, height: mode, width: maxWidth } = props;
|
|
129
157
|
const rootRef = (0, react_1.useRef)(null);
|
|
130
158
|
const [size, setSize] = (0, react_1.useState)({ width: 0, height: 0 });
|
|
159
|
+
(0, react_1.useEffect)(() => (mode === "content" ? (0, frame_viewport_1.holdFrameViewport)() : undefined), [mode]);
|
|
131
160
|
(0, react_1.useEffect)(() => {
|
|
132
161
|
const root = rootRef.current;
|
|
133
162
|
if (!root)
|
|
@@ -199,9 +228,35 @@ async function runBundle(init) {
|
|
|
199
228
|
}
|
|
200
229
|
/** Numbers each init, so an older one that finishes later doesn't replace a newer one's screen. */
|
|
201
230
|
let latestInit = 0;
|
|
231
|
+
/**
|
|
232
|
+
* Put a global widget's frame where the host says: the body lays out as the whole window and is
|
|
233
|
+
* shifted back by where the frame is, and, being transformed, holds the frame's `position: fixed`
|
|
234
|
+
* elements, portals included. So a widget's `position: fixed` means the window.
|
|
235
|
+
*/
|
|
236
|
+
function placeWidget(next) {
|
|
237
|
+
placement = next;
|
|
238
|
+
(0, globals_1.followHostViewport)(next.viewportWidth, next.viewportHeight);
|
|
239
|
+
const html = document.documentElement;
|
|
240
|
+
html.style.overflow = "hidden";
|
|
241
|
+
const body = document.body.style;
|
|
242
|
+
body.position = "fixed";
|
|
243
|
+
body.margin = "0";
|
|
244
|
+
body.left = `${-next.x}px`;
|
|
245
|
+
body.top = `${-next.y}px`;
|
|
246
|
+
body.width = `${next.viewportWidth}px`;
|
|
247
|
+
body.height = `${next.viewportHeight}px`;
|
|
248
|
+
body.transform = "translate(0, 0)";
|
|
249
|
+
}
|
|
202
250
|
async function handleInit(host, init) {
|
|
203
251
|
const thisInit = ++latestInit;
|
|
204
252
|
drawsPiece = init.piece !== undefined;
|
|
253
|
+
relaysTab = init.piece?.overSlot === true;
|
|
254
|
+
const firstWidgetInit = init.widget !== undefined && !drawsWidget;
|
|
255
|
+
drawsWidget = init.widget !== undefined;
|
|
256
|
+
if (init.widget)
|
|
257
|
+
placeWidget(init.widget.placement);
|
|
258
|
+
if (firstWidgetInit)
|
|
259
|
+
(0, widget_box_1.startWidgetBoxReports)(host, () => placement);
|
|
205
260
|
const firstInit = !root;
|
|
206
261
|
if (firstInit) {
|
|
207
262
|
const bridge = (0, frame_bridge_1.frameBridge)();
|
|
@@ -269,7 +324,7 @@ async function handleInit(host, init) {
|
|
|
269
324
|
host.notify(frame_protocol_1.FrameNotice.failed, { message });
|
|
270
325
|
return;
|
|
271
326
|
}
|
|
272
|
-
show({ ui, props: init.props });
|
|
327
|
+
show({ ui, props: init.props, ...(init.widget ? { widget: true } : {}) });
|
|
273
328
|
}
|
|
274
329
|
/** Links to the web open outside Peers, and `#` links navigate the tab, through the host. */
|
|
275
330
|
function installLinkHandling(host) {
|
|
@@ -325,27 +380,43 @@ function isHostShortcut(event) {
|
|
|
325
380
|
* embedder. A popover inside the frame stops its own Escape before it gets here; a listener the
|
|
326
381
|
* piece added after this one can still take it, so it's sent once the event has reached them all.
|
|
327
382
|
* With ⌘ or Ctrl held, Escape is a shortcut like the others (Ctrl+Escape cancels the host's tab
|
|
328
|
-
* switcher).
|
|
383
|
+
* switcher). In a piece drawn over a slot, an unhandled Tab at an edge goes back to the screen.
|
|
329
384
|
*/
|
|
330
385
|
function installKeyForwarding(host) {
|
|
386
|
+
host.onNotify(frame_protocol_1.HostNotice.focusEdge, (payload) => {
|
|
387
|
+
// The host focused this frame as it sent this. Focus the user moved since (a click on a host
|
|
388
|
+
// field) stays where it is: a frame without focus can still take it with `.focus()`.
|
|
389
|
+
if (!relaysTab || !document.hasFocus())
|
|
390
|
+
return;
|
|
391
|
+
const edge = payload?.edge === "last" ? "last" : "first";
|
|
392
|
+
// Nothing to focus: Tab goes straight on past the piece.
|
|
393
|
+
if (!(0, focus_relay_1.focusEdge)(document, edge)) {
|
|
394
|
+
host.notify(frame_protocol_1.FrameNotice.focusLeave, { direction: edge === "first" ? "next" : "previous" });
|
|
395
|
+
}
|
|
396
|
+
});
|
|
331
397
|
const forward = (event) => {
|
|
332
398
|
if (event.defaultPrevented)
|
|
333
399
|
return;
|
|
334
|
-
if (event.key === "Escape" &&
|
|
335
|
-
drawsPiece &&
|
|
336
|
-
event.type === "keydown" &&
|
|
337
|
-
!event.metaKey &&
|
|
338
|
-
!event.ctrlKey) {
|
|
339
|
-
setTimeout(() => {
|
|
340
|
-
if (event.defaultPrevented)
|
|
341
|
-
return;
|
|
342
|
-
host.notify(frame_protocol_1.FrameNotice.key, { type: event.type, key: event.key, code: event.code });
|
|
343
|
-
}, 0);
|
|
344
|
-
return;
|
|
345
|
-
}
|
|
346
400
|
const modifierKey = event.key === "Control" || event.key === "Meta";
|
|
347
|
-
if (!(event.metaKey || event.ctrlKey || modifierKey))
|
|
401
|
+
if (!(event.metaKey || event.ctrlKey || modifierKey)) {
|
|
402
|
+
if (!drawsPiece || event.type !== "keydown")
|
|
403
|
+
return;
|
|
404
|
+
if (event.key === "Escape") {
|
|
405
|
+
setTimeout(() => {
|
|
406
|
+
if (event.defaultPrevented)
|
|
407
|
+
return;
|
|
408
|
+
host.notify(frame_protocol_1.FrameNotice.key, { type: event.type, key: event.key, code: event.code });
|
|
409
|
+
}, 0);
|
|
410
|
+
}
|
|
411
|
+
else if (event.key === "Tab" &&
|
|
412
|
+
relaysTab &&
|
|
413
|
+
!event.altKey &&
|
|
414
|
+
(0, focus_relay_1.tabLeaves)(document, event.shiftKey)) {
|
|
415
|
+
event.preventDefault();
|
|
416
|
+
host.notify(frame_protocol_1.FrameNotice.focusLeave, { direction: event.shiftKey ? "previous" : "next" });
|
|
417
|
+
}
|
|
348
418
|
return;
|
|
419
|
+
}
|
|
349
420
|
if (isHostShortcut(event))
|
|
350
421
|
event.preventDefault();
|
|
351
422
|
host.notify(frame_protocol_1.FrameNotice.key, {
|
|
@@ -440,6 +511,16 @@ function installWheelRelay(host) {
|
|
|
440
511
|
scheduled = requestAnimationFrame(flush);
|
|
441
512
|
}, { capture: true, passive: true });
|
|
442
513
|
}
|
|
514
|
+
/** A placement as the host sends it: six finite numbers, sizes not negative. */
|
|
515
|
+
function isPlacement(value) {
|
|
516
|
+
const p = value;
|
|
517
|
+
if (!p)
|
|
518
|
+
return false;
|
|
519
|
+
const nums = [p.x, p.y, p.width, p.height, p.viewportWidth, p.viewportHeight];
|
|
520
|
+
return (nums.every((n) => typeof n === "number" && Number.isFinite(n)) &&
|
|
521
|
+
p.width >= 0 &&
|
|
522
|
+
p.height >= 0);
|
|
523
|
+
}
|
|
443
524
|
/** The screen's warnings and errors also go to the host, whose console the Console app reads. */
|
|
444
525
|
function installConsoleForwarding(host) {
|
|
445
526
|
for (const level of ["warn", "error"]) {
|
|
@@ -479,6 +560,24 @@ function startFrameRuntime() {
|
|
|
479
560
|
host.onNotify(frame_protocol_1.HostNotice.theme, ({ colorMode }) => applyTheme(colorMode));
|
|
480
561
|
// The host resolves the screen's pieces; when what they depend on changes, they resolve again.
|
|
481
562
|
host.onNotify(frame_protocol_1.HostNotice.pieceRevision, () => (0, piece_resolution_1.pieceRevision)((0, piece_resolution_1.pieceRevision)() + 1));
|
|
563
|
+
host.onNotify(frame_protocol_1.HostNotice.widgetPlacement, (next) => {
|
|
564
|
+
if (drawsWidget && isPlacement(next))
|
|
565
|
+
placeWidget(next);
|
|
566
|
+
});
|
|
567
|
+
// The package's commands go to the host's palette, which runs them by telling this frame.
|
|
568
|
+
(0, frame_commands_1.bridgeCommandsToHost)({
|
|
569
|
+
register: (command) => void host
|
|
570
|
+
.request(frame_protocol_1.FrameRequest.commandRegister, command)
|
|
571
|
+
.catch((error) => console.warn(`Couldn't add the command ${command.id}`, error)),
|
|
572
|
+
unregister: (commandId) => void host.request(frame_protocol_1.FrameRequest.commandUnregister, { id: commandId }).catch(() => undefined),
|
|
573
|
+
run: (commandId) => void host
|
|
574
|
+
.request(frame_protocol_1.FrameRequest.commandRun, { id: commandId })
|
|
575
|
+
.catch((error) => console.warn(`Couldn't run the command ${commandId}`, error)),
|
|
576
|
+
});
|
|
577
|
+
host.onNotify(frame_protocol_1.HostNotice.commandRun, ({ id }) => {
|
|
578
|
+
if (typeof id === "string")
|
|
579
|
+
(0, frame_commands_1.runFrameCommand)(id);
|
|
580
|
+
});
|
|
482
581
|
installLinkHandling(host);
|
|
483
582
|
installKeyForwarding(host);
|
|
484
583
|
installPointerRelay(host);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keep this frame's viewport from scrolling: no scrollbar, and a scroll made by script (such as
|
|
3
|
+
* `scrollIntoView` on an option drawn past the frame's edge) is put back at once, since the user
|
|
4
|
+
* couldn't scroll back from it.
|
|
5
|
+
*
|
|
6
|
+
* @param doc - The frame's document.
|
|
7
|
+
* @returns A function that lets the viewport scroll again.
|
|
8
|
+
*/
|
|
9
|
+
export declare function holdFrameViewport(doc?: Document): () => void;
|