@peers-app/peers-ui 0.34.5 → 0.34.7

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.
Files changed (36) hide show
  1. package/dist/components/group-switcher.js +30 -2
  2. package/dist/components/markdown-editor/editor.d.ts +5 -4
  3. package/dist/components/markdown-editor/editor.js +10 -145
  4. package/dist/components/markdown-editor/lexical-editor.d.ts +3 -0
  5. package/dist/components/markdown-editor/lexical-editor.js +153 -0
  6. package/dist/components/markdown-render.d.ts +8 -0
  7. package/dist/components/markdown-render.js +143 -0
  8. package/dist/components/markdown-with-mentions.d.ts +1 -1
  9. package/dist/components/markdown-with-mentions.js +7 -129
  10. package/dist/components/trust-level-dropdown.d.ts +6 -1
  11. package/dist/components/trust-level-dropdown.js +43 -14
  12. package/dist/components/use-close-on-outside-press.d.ts +19 -0
  13. package/dist/components/use-close-on-outside-press.js +54 -0
  14. package/dist/isolated-screens/focus-relay.d.ts +24 -0
  15. package/dist/isolated-screens/focus-relay.js +104 -0
  16. package/dist/isolated-screens/frame-document.d.ts +7 -0
  17. package/dist/isolated-screens/frame-document.js +11 -1
  18. package/dist/isolated-screens/frame-protocol.d.ts +26 -0
  19. package/dist/isolated-screens/frame-protocol.js +21 -0
  20. package/dist/isolated-screens/frame-runtime.js +47 -14
  21. package/dist/isolated-screens/isolated-screen.d.ts +6 -0
  22. package/dist/isolated-screens/isolated-screen.js +40 -3
  23. package/dist/isolated-screens/piece-frames.js +57 -5
  24. package/dist/isolated-screens/piece-reach.js +17 -6
  25. package/dist/lazy-module.d.ts +17 -0
  26. package/dist/lazy-module.js +26 -0
  27. package/dist/notifications/notification-bell.js +2 -18
  28. package/dist/operator-console/console-session.js +1 -9
  29. package/dist/screens/groups/group-members.js +7 -17
  30. package/dist/screens/invites/accept-invite.js +15 -4
  31. package/dist/tabs-layout/network-status-indicator.js +2 -21
  32. package/dist/theme.css +8 -0
  33. package/dist/ui-contracts/piece-height.d.ts +8 -2
  34. package/dist/ui-contracts/piece-height.js +6 -1
  35. package/dist/ui-contracts/piece.js +1 -1
  36. package/package.json +4 -3
@@ -1,140 +1,20 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __importDefault = (this && this.__importDefault) || function (mod) {
36
- return (mod && mod.__esModule) ? mod : { "default": mod };
37
- };
38
2
  Object.defineProperty(exports, "__esModule", { value: true });
39
3
  exports.MarkdownWithMentions = void 0;
40
4
  exports.mentionUrlTransform = mentionUrlTransform;
41
- const jsx_runtime_1 = require("react/jsx-runtime");
42
- const peers_sdk_1 = require("@peers-app/peers-sdk");
43
- const react_1 = __importDefault(require("react"));
44
- const react_markdown_1 = __importStar(require("react-markdown"));
45
- const remark_gfm_1 = __importDefault(require("remark-gfm"));
46
- const host_shell_consumer_1 = require("../host-shell/host-shell-consumer");
47
- const mention_chip_1 = require("../mentions/mention-chip");
48
- /** The text in some rendered markdown children. */
49
- function textOf(children) {
50
- return react_1.default.Children.toArray(children)
51
- .map((child) => {
52
- if (typeof child === "string" || typeof child === "number")
53
- return String(child);
54
- if (react_1.default.isValidElement(child)) {
55
- return textOf(child.props.children);
56
- }
57
- return "";
58
- })
59
- .join("");
60
- }
61
- /** A link: a mention becomes a chip, and a web link opens in the system browser. */
62
- const LinkRenderer = (props) => {
63
- const { href } = props;
64
- const mention = href ? (0, peers_sdk_1.parseMentionUrl)(href) : undefined;
65
- if (mention)
66
- return (0, jsx_runtime_1.jsx)(mention_chip_1.MentionChip, { ...mention, label: textOf(props.children) });
67
- return ((0, jsx_runtime_1.jsx)("a", { href: href, onClick: (e) => {
68
- if (href?.startsWith("http")) {
69
- e.preventDefault();
70
- void (0, host_shell_consumer_1.openOnHost)(href);
71
- }
72
- }, children: props.children }));
73
- };
5
+ const react_1 = require("react");
6
+ const lazy_module_1 = require("../lazy-module");
74
7
  /**
75
- * An image. `![label](peers://…)` is a mention typed right after a `!` ("Thanks![Plan](…)"),
76
- * which the editor shows as `!` and a chip, so it renders the same here.
8
+ * react-markdown, remark-gfm and the renderers, loaded the first time markdown is drawn (or
9
+ * `mentionUrlTransform` is called).
77
10
  */
78
- const ImageRenderer = ({ node: _node, src, alt, ...props }) => {
79
- const mention = typeof src === "string" ? (0, peers_sdk_1.parseMentionUrl)(src) : undefined;
80
- if (mention) {
81
- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: ["!", (0, jsx_runtime_1.jsx)(mention_chip_1.MentionChip, { ...mention, label: alt ?? "" })] }));
82
- }
83
- return (0, jsx_runtime_1.jsx)("img", { src: src, alt: alt, ...props });
84
- };
85
- /** Text with the older `<$kind:Name:id>` mentions turned into chips (a name alone without an id). */
86
- const processTextWithMentions = (text) => {
87
- const parts = [];
88
- const regex = new RegExp((0, peers_sdk_1.mentionRegex)().source, "g");
89
- let lastIndex = 0;
90
- for (const match of text.matchAll(regex)) {
91
- const at = match.index ?? 0;
92
- if (at > lastIndex)
93
- parts.push(text.slice(lastIndex, at));
94
- const [, , kind, name, id] = match;
95
- const label = name.replace(/_/g, " ");
96
- const ref = id ? (0, peers_sdk_1.parseMentionUrl)(`peers://${kind.toLowerCase()}/${id}`) : undefined;
97
- parts.push(ref ? (0, jsx_runtime_1.jsx)(mention_chip_1.MentionChip, { ...ref, label: label }, at) : label);
98
- lastIndex = at + match[0].length;
99
- }
100
- if (lastIndex < text.length)
101
- parts.push(text.slice(lastIndex));
102
- return parts;
103
- };
104
- const createElementWithMentions = (Element) => {
105
- return ({ node: _node, ...props }) => {
106
- return ((0, jsx_runtime_1.jsx)(Element, { ...props, children: react_1.default.Children.map(props.children, (child) => {
107
- if (typeof child === "string") {
108
- return processTextWithMentions(child);
109
- }
110
- return child;
111
- }) }));
112
- };
113
- };
114
- const components = {
115
- p: createElementWithMentions("p"),
116
- h1: createElementWithMentions("h1"),
117
- h2: createElementWithMentions("h2"),
118
- h3: createElementWithMentions("h3"),
119
- h4: createElementWithMentions("h4"),
120
- h5: createElementWithMentions("h5"),
121
- h6: createElementWithMentions("h6"),
122
- li: createElementWithMentions("li"),
123
- a: LinkRenderer,
124
- img: ImageRenderer,
125
- strong: createElementWithMentions("strong"),
126
- em: createElementWithMentions("em"),
127
- blockquote: createElementWithMentions("blockquote"),
128
- code: createElementWithMentions("code"),
129
- td: createElementWithMentions("td"),
130
- th: createElementWithMentions("th"),
131
- };
11
+ const markdownRender = (0, lazy_module_1.lazyModule)(() => require("./markdown-render"));
132
12
  /**
133
13
  * Keep `peers://` mention links; every other URL gets react-markdown's default treatment, which
134
14
  * blanks `javascript:` and other unsafe schemes in text other members wrote.
135
15
  */
136
16
  function mentionUrlTransform(url) {
137
- return (0, peers_sdk_1.parseMentionUrl)(url) ? url : (0, react_markdown_1.defaultUrlTransform)(url);
17
+ return markdownRender().mentionUrlTransform(url);
138
18
  }
139
19
  /**
140
20
  * Render markdown (GitHub-flavored) with mentions (`[label](peers://<kind>/<id>)`, and the
@@ -144,7 +24,5 @@ function mentionUrlTransform(url) {
144
24
  * @param props.content - The markdown.
145
25
  * @param props.groupId - The group the text belongs to: mentions resolve there first.
146
26
  */
147
- const MarkdownWithMentions = ({ content, groupId, }) => ((0, jsx_runtime_1.jsx)(mention_chip_1.MentionGroupContext.Provider, { value: groupId, children: (0, jsx_runtime_1.jsx)("div", { className: "markdown", children: (0, jsx_runtime_1.jsx)(react_markdown_1.default, { remarkPlugins: [remark_gfm_1.default], urlTransform: mentionUrlTransform,
148
- // @ts-expect-error react-markdown's component props are narrower than these wrappers
149
- components: components, children: content }) }) }));
27
+ const MarkdownWithMentions = (props) => (0, react_1.createElement)(markdownRender().MarkdownRender, props);
150
28
  exports.MarkdownWithMentions = MarkdownWithMentions;
@@ -5,6 +5,11 @@ interface TrustLevelDropdownProps {
5
5
  onChange?: (newLevel: TrustLevel) => void;
6
6
  type?: "user" | "device";
7
7
  }
8
- /** Select a context-scoped user or device trust level, including the full-access Self grant. */
8
+ /**
9
+ * Select a context-scoped user or device trust level, including the full-access Self grant.
10
+ * Without a level set it shows the default (`getUserTrust`), marked as such, and once one is set
11
+ * it offers Use the default, which clears it. The signed-in user, in their Personal, is always
12
+ * Self, so for them it only shows Self.
13
+ */
9
14
  export declare const TrustLevelDropdown: ({ userId, dataContext, onChange, type, }: TrustLevelDropdownProps) => import("react/jsx-runtime").JSX.Element;
10
15
  export {};
@@ -5,10 +5,27 @@ 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 loading_indicator_1 = require("./loading-indicator");
8
- /** Select a context-scoped user or device trust level, including the full-access Self grant. */
8
+ /** The context the dropdown reads and writes: the one given, else the user's Personal. */
9
+ async function contextFor(dataContext) {
10
+ return dataContext || (await (0, peers_sdk_1.getUserContext)()).userDataContext;
11
+ }
12
+ /** The user's trust there, the default included. */
13
+ async function readTrust(userId, dataContext) {
14
+ return (0, peers_sdk_1.getUserTrust)(await contextFor(dataContext), userId);
15
+ }
16
+ /**
17
+ * Select a context-scoped user or device trust level, including the full-access Self grant.
18
+ * Without a level set it shows the default (`getUserTrust`), marked as such, and once one is set
19
+ * it offers Use the default, which clears it. The signed-in user, in their Personal, is always
20
+ * Self, so for them it only shows Self.
21
+ */
9
22
  const TrustLevelDropdown = ({ userId, dataContext, onChange, type = "user", }) => {
10
- const [trustLevel, setTrustLevelState] = (0, react_1.useState)(peers_sdk_1.TrustLevel.Unknown);
23
+ const [trust, setTrust] = (0, react_1.useState)({
24
+ level: peers_sdk_1.TrustLevel.Unknown,
25
+ explicit: false,
26
+ });
11
27
  const [loading, setLoading] = (0, react_1.useState)(true);
28
+ const trustLevel = trust.level;
12
29
  const allTrustLevelConfigs = [
13
30
  {
14
31
  value: peers_sdk_1.TrustLevel.Self,
@@ -44,24 +61,32 @@ const TrustLevelDropdown = ({ userId, dataContext, onChange, type = "user", }) =
44
61
  // Filter configs based on type
45
62
  const trustLevelConfigs = allTrustLevelConfigs.filter((config) => !config.showFor || config.showFor === type);
46
63
  (0, react_1.useEffect)(() => {
47
- async function loadTrustLevel() {
48
- const userContext = await (0, peers_sdk_1.getUserContext)();
49
- const contextToUse = dataContext || userContext.userDataContext;
50
- const level = await (0, peers_sdk_1.getUserTrustLevel)(contextToUse, userId);
51
- setTrustLevelState(level);
64
+ let current = true;
65
+ void readTrust(userId, dataContext).then((read) => {
66
+ if (!current)
67
+ return;
68
+ setTrust(read);
52
69
  setLoading(false);
53
- }
54
- loadTrustLevel();
70
+ });
71
+ return () => {
72
+ current = false;
73
+ };
55
74
  }, [userId, dataContext]);
56
75
  async function handleTrustLevelChange(newLevel) {
57
- const userContext = await (0, peers_sdk_1.getUserContext)();
58
- const contextToUse = dataContext || userContext.userDataContext;
59
- await (0, peers_sdk_1.setUserTrustLevel)(userId, newLevel, contextToUse);
60
- setTrustLevelState(newLevel);
76
+ await (0, peers_sdk_1.setUserTrustLevel)(userId, newLevel, await contextFor(dataContext));
77
+ setTrust({ level: newLevel, explicit: true });
61
78
  if (onChange) {
62
79
  onChange(newLevel);
63
80
  }
64
81
  }
82
+ /** Clear the level set here, so the default applies again. */
83
+ async function restoreDefault() {
84
+ const context = await contextFor(dataContext);
85
+ await (0, peers_sdk_1.UserTrustLevels)(context).delete(userId);
86
+ const restored = await (0, peers_sdk_1.getUserTrust)(context, userId);
87
+ setTrust(restored);
88
+ onChange?.(restored.level);
89
+ }
65
90
  // Find current config
66
91
  const sortedConfigs = trustLevelConfigs.sort((a, b) => a.value - b.value);
67
92
  let currentConfig = { color: "secondary", icon: "bi-shield", text: "Unknown" };
@@ -76,6 +101,10 @@ const TrustLevelDropdown = ({ userId, dataContext, onChange, type = "user", }) =
76
101
  if (loading) {
77
102
  return (0, jsx_runtime_1.jsx)(loading_indicator_1.LoadingIndicator, {});
78
103
  }
79
- return ((0, jsx_runtime_1.jsxs)("div", { className: "dropdown", children: [(0, jsx_runtime_1.jsxs)("button", { className: `btn btn-sm btn-${currentConfig.color} dropdown-toggle d-flex align-items-center gap-1`, type: "button", "data-bs-toggle": "dropdown", "data-bs-auto-close": "true", "data-bs-popper-config": '{"strategy":"fixed"}', "aria-expanded": "false", children: [(0, jsx_runtime_1.jsx)("i", { className: currentConfig.icon }), currentConfig.text] }), (0, jsx_runtime_1.jsx)("ul", { className: "dropdown-menu", children: trustLevelConfigs.map((config) => ((0, jsx_runtime_1.jsx)("li", { children: (0, jsx_runtime_1.jsx)("button", { className: "dropdown-item p-2", onClick: () => handleTrustLevelChange(config.value), children: (0, jsx_runtime_1.jsxs)("span", { className: `badge bg-${config.color} d-flex align-items-center gap-2 w-100 py-2 px-3 fs-6 ${trustLevel === config.value ? "border border-dark border-2" : ""}`, children: [(0, jsx_runtime_1.jsx)("i", { className: config.icon }), config.text] }) }) }, config.value))) })] }));
104
+ // The signed-in user in their Personal: Self whatever is chosen, so there's nothing to choose.
105
+ if (trustLevel === peers_sdk_1.TrustLevel.Self && !trust.explicit) {
106
+ return ((0, jsx_runtime_1.jsxs)("span", { className: `btn btn-sm btn-${currentConfig.color} disabled d-inline-flex align-items-center gap-1`, "aria-disabled": "true", children: [(0, jsx_runtime_1.jsx)("i", { className: currentConfig.icon }), currentConfig.text] }));
107
+ }
108
+ return ((0, jsx_runtime_1.jsxs)("div", { className: "dropdown", children: [(0, jsx_runtime_1.jsxs)("button", { className: `btn btn-sm btn-${currentConfig.color} dropdown-toggle d-flex align-items-center gap-1`, type: "button", "data-bs-toggle": "dropdown", "data-bs-auto-close": "true", "data-bs-popper-config": '{"strategy":"fixed"}', "aria-expanded": "false", children: [(0, jsx_runtime_1.jsx)("i", { className: currentConfig.icon }), currentConfig.text, !trust.explicit && " (default)"] }), trust.knownFrom && ((0, jsx_runtime_1.jsxs)("small", { className: "text-muted d-block mt-1", children: ["Known from ", trust.knownFrom.toLocaleDateString()] })), (0, jsx_runtime_1.jsxs)("ul", { className: "dropdown-menu", children: [trustLevelConfigs.map((config) => ((0, jsx_runtime_1.jsx)("li", { children: (0, jsx_runtime_1.jsx)("button", { className: "dropdown-item p-2", onClick: () => handleTrustLevelChange(config.value), children: (0, jsx_runtime_1.jsxs)("span", { className: `badge bg-${config.color} d-flex align-items-center gap-2 w-100 py-2 px-3 fs-6 ${trustLevel === config.value ? "border border-dark border-2" : ""}`, children: [(0, jsx_runtime_1.jsx)("i", { className: config.icon }), config.text] }) }) }, config.value))), trust.explicit && ((0, jsx_runtime_1.jsx)("li", { children: (0, jsx_runtime_1.jsx)("button", { className: "dropdown-item p-2", onClick: () => void restoreDefault(), children: "Use the default" }) }))] })] }));
80
109
  };
81
110
  exports.TrustLevelDropdown = TrustLevelDropdown;
@@ -0,0 +1,19 @@
1
+ import type React from "react";
2
+ /**
3
+ * The class on `<html>` while a shell popover is open. In the desktop app it stops the tab
4
+ * strip's empty space from moving the window (`theme.css`), since a press there never reaches
5
+ * the page, so it can close the popover instead, as a press beside a native menu does.
6
+ */
7
+ export declare const WINDOW_DRAG_PAUSED_CLASS = "peers-window-drag-paused";
8
+ /**
9
+ * Close a shell popover, while it's open, on Escape or a press outside `containerRef`. A press
10
+ * inside an app counts as outside: apps draw in frames, whose own `mousedown` never reaches the
11
+ * shell's document, so the host relays it as {@link FRAME_POINTER_EVENT} on the frame's element.
12
+ * So does a press on the tab strip's empty space: while it's open, that space doesn't move the
13
+ * window ({@link WINDOW_DRAG_PAUSED_CLASS}).
14
+ *
15
+ * @param containerRef - The popover and the button that opens it. A press in here keeps it open.
16
+ * @param open - Whether the popover is open. Nothing is listened to while it's closed.
17
+ * @param onClose - Called on each outside press or Escape.
18
+ */
19
+ export declare function useCloseOnOutsidePress(containerRef: React.RefObject<HTMLElement | null>, open: boolean, onClose: () => void): void;
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WINDOW_DRAG_PAUSED_CLASS = void 0;
4
+ exports.useCloseOnOutsidePress = useCloseOnOutsidePress;
5
+ const react_1 = require("react");
6
+ const popover_surface_1 = require("../ui-contracts/popover-surface");
7
+ /**
8
+ * The class on `<html>` while a shell popover is open. In the desktop app it stops the tab
9
+ * strip's empty space from moving the window (`theme.css`), since a press there never reaches
10
+ * the page, so it can close the popover instead, as a press beside a native menu does.
11
+ */
12
+ exports.WINDOW_DRAG_PAUSED_CLASS = "peers-window-drag-paused";
13
+ /** How many shell popovers are open, so the window's drag comes back only when the last closes. */
14
+ let popoversOpen = 0;
15
+ /**
16
+ * Close a shell popover, while it's open, on Escape or a press outside `containerRef`. A press
17
+ * inside an app counts as outside: apps draw in frames, whose own `mousedown` never reaches the
18
+ * shell's document, so the host relays it as {@link FRAME_POINTER_EVENT} on the frame's element.
19
+ * So does a press on the tab strip's empty space: while it's open, that space doesn't move the
20
+ * window ({@link WINDOW_DRAG_PAUSED_CLASS}).
21
+ *
22
+ * @param containerRef - The popover and the button that opens it. A press in here keeps it open.
23
+ * @param open - Whether the popover is open. Nothing is listened to while it's closed.
24
+ * @param onClose - Called on each outside press or Escape.
25
+ */
26
+ function useCloseOnOutsidePress(containerRef, open, onClose) {
27
+ const closeRef = (0, react_1.useRef)(onClose);
28
+ closeRef.current = onClose;
29
+ (0, react_1.useEffect)(() => {
30
+ if (!open)
31
+ return;
32
+ const closeOutside = (event) => {
33
+ if (!containerRef.current?.contains(event.target))
34
+ closeRef.current();
35
+ };
36
+ const closeOnEscape = (event) => {
37
+ if (event.key === "Escape")
38
+ closeRef.current();
39
+ };
40
+ document.addEventListener("mousedown", closeOutside);
41
+ document.addEventListener(popover_surface_1.FRAME_POINTER_EVENT, closeOutside);
42
+ document.addEventListener("keydown", closeOnEscape);
43
+ popoversOpen++;
44
+ document.documentElement.classList.add(exports.WINDOW_DRAG_PAUSED_CLASS);
45
+ return () => {
46
+ document.removeEventListener("mousedown", closeOutside);
47
+ document.removeEventListener(popover_surface_1.FRAME_POINTER_EVENT, closeOutside);
48
+ document.removeEventListener("keydown", closeOnEscape);
49
+ popoversOpen--;
50
+ if (popoversOpen === 0)
51
+ document.documentElement.classList.remove(exports.WINDOW_DRAG_PAUSED_CLASS);
52
+ };
53
+ }, [open, containerRef]);
54
+ }
@@ -0,0 +1,24 @@
1
+ /** Which end of a piece focus enters at: its first control (Tab) or its last (Shift+Tab). */
2
+ export type FocusEdge = "first" | "last";
3
+ /** Which way focus leaves a piece: to the control after its slot, or the one before it. */
4
+ export type FocusDirection = "next" | "previous";
5
+ /** The elements Tab stops at in a document, in document order (positive tabindex aside). */
6
+ export declare function tabbables(doc: Document): HTMLElement[];
7
+ /**
8
+ * Focus a document's first or last control.
9
+ *
10
+ * @returns Whether it had one.
11
+ */
12
+ export declare function focusEdge(doc: Document, edge: FocusEdge): boolean;
13
+ /**
14
+ * Whether Tab (or Shift+Tab) on the focused element leaves the document's controls: from its last
15
+ * control, its first, or from nothing focusable.
16
+ */
17
+ export declare function tabLeaves(doc: Document, backwards: boolean): boolean;
18
+ /** The edge focus enters a slot at, from the element focus came from. */
19
+ export declare function edgeEnteredFrom(slot: Element, from: Element | null): FocusEdge;
20
+ /**
21
+ * Focus the control after (or before) a slot in its document, leaving the slot itself out. With
22
+ * none there, focus leaves the slot.
23
+ */
24
+ export declare function focusBeside(slot: HTMLElement, direction: FocusDirection): void;
@@ -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
- (0, eval)(data.runtime);
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
  })();
@@ -43,6 +43,11 @@ 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;
46
51
  };
47
52
  /** The tab's path. */
48
53
  path: string;
@@ -124,6 +129,18 @@ export declare const FrameNotice: {
124
129
  readonly pieceEmit: "piece.emit";
125
130
  /** From a piece's frame: it asked to close. */
126
131
  readonly pieceClose: "piece.close";
132
+ /** From a piece's frame: it has drawn its piece, so the embedder's loading view can go. */
133
+ readonly pieceDrawn: "piece.drawn";
134
+ /**
135
+ * From a screen: Tab reached a piece's slot, `{ slotId, edge }` (`first` with Tab, `last` with
136
+ * Shift+Tab). The host moves focus into the piece's frame drawn over it.
137
+ */
138
+ readonly pieceFocus: "piece.focus";
139
+ /**
140
+ * From a piece's frame drawn over a slot: Tab left its last control, or Shift+Tab its first,
141
+ * `{ direction }` (`next` or `previous`). The host hands focus back to the screen.
142
+ */
143
+ readonly focusLeave: "focus.leave";
127
144
  /**
128
145
  * From a piece's frame that takes its own height: its content's height, `{ height }`, and its
129
146
  * width, `{ width }`, when it takes its content's width too.
@@ -168,6 +185,15 @@ export declare const HostNotice: {
168
185
  readonly pieceEmit: "piece.emit";
169
186
  /** A piece the screen embeds asked to close: `{ slotId }`. */
170
187
  readonly pieceClose: "piece.close";
188
+ /** A piece the screen embeds has drawn: `{ slotId }`. Its loading view can go. */
189
+ readonly pieceDrawn: "piece.drawn";
190
+ /** To a piece's frame: focus came in from its screen, `{ edge }`: its first or last control. */
191
+ readonly focusEdge: "focus.edge";
192
+ /**
193
+ * To a screen: Tab left the piece over `slotId`, `{ slotId, direction }`. The screen focuses
194
+ * the control after the slot (`next`) or before it (`previous`).
195
+ */
196
+ readonly pieceFocusLeave: "piece.focus-leave";
171
197
  /**
172
198
  * A piece the screen embeds, which takes its own height, is now `{ slotId, height }` tall, and
173
199
  * `width` wide when it takes its content's width.
@@ -78,6 +78,18 @@ exports.FrameNotice = {
78
78
  pieceEmit: "piece.emit",
79
79
  /** From a piece's frame: it asked to close. */
80
80
  pieceClose: "piece.close",
81
+ /** From a piece's frame: it has drawn its piece, so the embedder's loading view can go. */
82
+ pieceDrawn: "piece.drawn",
83
+ /**
84
+ * From a screen: Tab reached a piece's slot, `{ slotId, edge }` (`first` with Tab, `last` with
85
+ * Shift+Tab). The host moves focus into the piece's frame drawn over it.
86
+ */
87
+ pieceFocus: "piece.focus",
88
+ /**
89
+ * From a piece's frame drawn over a slot: Tab left its last control, or Shift+Tab its first,
90
+ * `{ direction }` (`next` or `previous`). The host hands focus back to the screen.
91
+ */
92
+ focusLeave: "focus.leave",
81
93
  /**
82
94
  * From a piece's frame that takes its own height: its content's height, `{ height }`, and its
83
95
  * width, `{ width }`, when it takes its content's width too.
@@ -122,6 +134,15 @@ exports.HostNotice = {
122
134
  pieceEmit: "piece.emit",
123
135
  /** A piece the screen embeds asked to close: `{ slotId }`. */
124
136
  pieceClose: "piece.close",
137
+ /** A piece the screen embeds has drawn: `{ slotId }`. Its loading view can go. */
138
+ pieceDrawn: "piece.drawn",
139
+ /** To a piece's frame: focus came in from its screen, `{ edge }`: its first or last control. */
140
+ focusEdge: "focus.edge",
141
+ /**
142
+ * To a screen: Tab left the piece over `slotId`, `{ slotId, direction }`. The screen focuses
143
+ * the control after the slot (`next`) or before it (`previous`).
144
+ */
145
+ pieceFocusLeave: "piece.focus-leave",
125
146
  /**
126
147
  * A piece the screen embeds, which takes its own height, is now `{ slotId, height }` tall, and
127
148
  * `width` wide when it takes its content's width.