@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.
Files changed (56) hide show
  1. package/dist/command-palette/command-palette-ui.js +14 -14
  2. package/dist/command-palette/command-palette.d.ts +10 -3
  3. package/dist/command-palette/command-palette.js +60 -6
  4. package/dist/command-palette/frame-commands.d.ts +37 -0
  5. package/dist/command-palette/frame-commands.js +43 -0
  6. package/dist/components/markdown-editor/editor.d.ts +5 -4
  7. package/dist/components/markdown-editor/editor.js +10 -145
  8. package/dist/components/markdown-editor/lexical-editor.d.ts +3 -0
  9. package/dist/components/markdown-editor/lexical-editor.js +153 -0
  10. package/dist/components/markdown-render.d.ts +8 -0
  11. package/dist/components/markdown-render.js +143 -0
  12. package/dist/components/markdown-with-mentions.d.ts +1 -1
  13. package/dist/components/markdown-with-mentions.js +7 -129
  14. package/dist/components/trust-level-dropdown.d.ts +6 -1
  15. package/dist/components/trust-level-dropdown.js +43 -14
  16. package/dist/globals.d.ts +13 -2
  17. package/dist/globals.js +24 -2
  18. package/dist/index.d.ts +2 -1
  19. package/dist/index.js +9 -1
  20. package/dist/isolated-screens/config.js +1 -5
  21. package/dist/isolated-screens/focus-relay.d.ts +24 -0
  22. package/dist/isolated-screens/focus-relay.js +104 -0
  23. package/dist/isolated-screens/frame-document.d.ts +7 -0
  24. package/dist/isolated-screens/frame-document.js +11 -1
  25. package/dist/isolated-screens/frame-permissions.d.ts +11 -0
  26. package/dist/isolated-screens/frame-permissions.js +33 -0
  27. package/dist/isolated-screens/frame-protocol.d.ts +90 -0
  28. package/dist/isolated-screens/frame-protocol.js +49 -0
  29. package/dist/isolated-screens/frame-runtime.js +115 -16
  30. package/dist/isolated-screens/frame-viewport.d.ts +9 -0
  31. package/dist/isolated-screens/frame-viewport.js +36 -0
  32. package/dist/isolated-screens/global-widgets.d.ts +74 -0
  33. package/dist/isolated-screens/global-widgets.js +270 -0
  34. package/dist/isolated-screens/isolated-screen.d.ts +57 -1
  35. package/dist/isolated-screens/isolated-screen.js +266 -15
  36. package/dist/isolated-screens/piece-frames.js +57 -5
  37. package/dist/isolated-screens/piece-reach.d.ts +24 -0
  38. package/dist/isolated-screens/piece-reach.js +40 -13
  39. package/dist/isolated-screens/widget-box.d.ts +48 -0
  40. package/dist/isolated-screens/widget-box.js +193 -0
  41. package/dist/lazy-module.d.ts +17 -0
  42. package/dist/lazy-module.js +26 -0
  43. package/dist/operator-console/console-session.js +1 -9
  44. package/dist/operator-console/operator-console-state.js +5 -1
  45. package/dist/root-layout/root-layout-host.js +3 -1
  46. package/dist/screens/groups/group-members.js +7 -17
  47. package/dist/screens/invites/accept-invite.js +15 -4
  48. package/dist/screens/packages/package-info.js +2 -1
  49. package/dist/screens/packages/package-widgets-panel.d.ts +15 -0
  50. package/dist/screens/packages/package-widgets-panel.js +64 -0
  51. package/dist/tabs-layout/tabs-state.d.ts +5 -2
  52. package/dist/tabs-layout/tabs-state.js +41 -17
  53. package/dist/ui-contracts/piece-height.d.ts +8 -2
  54. package/dist/ui-contracts/piece-height.js +6 -1
  55. package/dist/ui-contracts/piece.js +1 -1
  56. package/package.json +4 -3
@@ -0,0 +1,48 @@
1
+ import { type IWidgetPlacement } from "./frame-protocol";
2
+ import type { IPortChannel } from "./port-channel";
3
+ /**
4
+ * A global widget's frame, measuring what it draws: the host places the frame over just that
5
+ * box, so the rest of the window stays the apps'.
6
+ *
7
+ * The box is the union of what's painted: elements with a background, a border, a shadow, text
8
+ * of their own, or that are controls, images or media; a box that clips its content (a scroll
9
+ * box) counts whole and isn't looked into. A `position: fixed` element that takes clicks counts
10
+ * too, painted or not: a menu's transparent click-catcher over the window is there to take the
11
+ * click that closes the menu. Layout-only containers aren't counted, so a full-width wrapper
12
+ * around a corner button doesn't make the box the window's width. The box grows by
13
+ * {@link BOX_MARGIN} for shadows, and is reported in the window's coordinates.
14
+ */
15
+ /** A rectangle in the window's coordinates. */
16
+ export interface IWidgetBox {
17
+ x: number;
18
+ y: number;
19
+ width: number;
20
+ height: number;
21
+ }
22
+ /** Room around what's painted, in px, for shadows and focus rings. */
23
+ export declare const BOX_MARGIN = 8;
24
+ /**
25
+ * The box a frame's content covers, in the frame's viewport coordinates, or `undefined` when it
26
+ * draws nothing.
27
+ *
28
+ * @param root - Where to look: the frame's body.
29
+ */
30
+ export declare function paintedBox(root: Element): IWidgetBox | undefined;
31
+ /**
32
+ * The box to report: what's painted, moved into the window's coordinates by where the frame is,
33
+ * grown by the margin, rounded out to whole pixels and kept inside the window.
34
+ *
35
+ * @param painted - From {@link paintedBox}.
36
+ * @param placement - Where the host put the frame.
37
+ */
38
+ export declare function windowBox(painted: IWidgetBox | undefined, placement: IWidgetPlacement): IWidgetBox | null;
39
+ /**
40
+ * In a global widget's frame: report the box its content covers whenever it may have changed (the
41
+ * DOM or a style changed, the frame moved or resized, a transition ended), and when an element in
42
+ * it captures the pointer or lets it go. Mutations, not animation frames, drive it: a browser may
43
+ * stop rendering a frame that shows next to nothing.
44
+ *
45
+ * @param host - The channel to the host.
46
+ * @param where - Where the host has put the frame now.
47
+ */
48
+ export declare function startWidgetBoxReports(host: IPortChannel, where: () => IWidgetPlacement | undefined): () => void;
@@ -0,0 +1,193 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BOX_MARGIN = void 0;
4
+ exports.paintedBox = paintedBox;
5
+ exports.windowBox = windowBox;
6
+ exports.startWidgetBoxReports = startWidgetBoxReports;
7
+ const frame_protocol_1 = require("./frame-protocol");
8
+ /** Room around what's painted, in px, for shadows and focus rings. */
9
+ exports.BOX_MARGIN = 8;
10
+ /** Elements past this many aren't looked at: a widget that big is measured by what's found. */
11
+ const MAX_ELEMENTS = 3000;
12
+ /** Elements that paint by being what they are. */
13
+ const PAINTED_TAGS = new Set([
14
+ "IMG",
15
+ "SVG",
16
+ "CANVAS",
17
+ "VIDEO",
18
+ "AUDIO",
19
+ "IFRAME",
20
+ "INPUT",
21
+ "TEXTAREA",
22
+ "SELECT",
23
+ "BUTTON",
24
+ "PROGRESS",
25
+ "METER",
26
+ "HR",
27
+ ]);
28
+ function transparent(color) {
29
+ return (color === "transparent" ||
30
+ color === "" ||
31
+ /^rgba\(.*,\s*0\)$/.test(color) ||
32
+ /^rgba\(.*\/\s*0\)$/.test(color));
33
+ }
34
+ function hasOwnText(element) {
35
+ for (const node of element.childNodes) {
36
+ if (node.nodeType === Node.TEXT_NODE && node.textContent?.trim())
37
+ return true;
38
+ }
39
+ return false;
40
+ }
41
+ function paints(element, style) {
42
+ if (PAINTED_TAGS.has(element.tagName.toUpperCase()))
43
+ return true;
44
+ if (style.position === "fixed" && style.pointerEvents !== "none")
45
+ return true;
46
+ const image = style.backgroundImage;
47
+ if (!transparent(style.backgroundColor) || (image !== "" && image !== "none"))
48
+ return true;
49
+ if (style.boxShadow !== "none" && style.boxShadow !== "")
50
+ return true;
51
+ for (const side of ["Top", "Right", "Bottom", "Left"]) {
52
+ const width = Number.parseFloat(style[`border${side}Width`]);
53
+ if (width > 0 && style[`border${side}Style`] !== "none")
54
+ return true;
55
+ }
56
+ return hasOwnText(element);
57
+ }
58
+ /** Overflow values that cut what's outside the box. */
59
+ const CLIPPING = new Set(["hidden", "clip", "auto", "scroll"]);
60
+ function clips(style) {
61
+ return (CLIPPING.has(style.overflowX) || CLIPPING.has(style.overflowY) || CLIPPING.has(style.overflow));
62
+ }
63
+ /**
64
+ * The box a frame's content covers, in the frame's viewport coordinates, or `undefined` when it
65
+ * draws nothing.
66
+ *
67
+ * @param root - Where to look: the frame's body.
68
+ */
69
+ function paintedBox(root) {
70
+ let left = Number.POSITIVE_INFINITY;
71
+ let top = Number.POSITIVE_INFINITY;
72
+ let right = Number.NEGATIVE_INFINITY;
73
+ let bottom = Number.NEGATIVE_INFINITY;
74
+ let seen = 0;
75
+ const add = (rect) => {
76
+ if (rect.width <= 0 || rect.height <= 0)
77
+ return;
78
+ left = Math.min(left, rect.left);
79
+ top = Math.min(top, rect.top);
80
+ right = Math.max(right, rect.right);
81
+ bottom = Math.max(bottom, rect.bottom);
82
+ };
83
+ const visitChildren = (parent) => {
84
+ for (const element of parent.children) {
85
+ if (seen >= MAX_ELEMENTS)
86
+ return;
87
+ seen++;
88
+ const tag = element.tagName.toUpperCase();
89
+ if (tag === "SCRIPT" || tag === "STYLE" || tag === "TEMPLATE")
90
+ continue;
91
+ const style = getComputedStyle(element);
92
+ if (style.display === "none" || style.visibility === "hidden")
93
+ continue;
94
+ if (Number.parseFloat(style.opacity) === 0)
95
+ continue;
96
+ const rect = element.getBoundingClientRect();
97
+ if (clips(style) && rect.width > 0 && rect.height > 0) {
98
+ add(rect);
99
+ continue;
100
+ }
101
+ if (paints(element, style))
102
+ add(rect);
103
+ visitChildren(element);
104
+ }
105
+ };
106
+ visitChildren(root);
107
+ if (left === Number.POSITIVE_INFINITY)
108
+ return undefined;
109
+ return { x: left, y: top, width: right - left, height: bottom - top };
110
+ }
111
+ /**
112
+ * The box to report: what's painted, moved into the window's coordinates by where the frame is,
113
+ * grown by the margin, rounded out to whole pixels and kept inside the window.
114
+ *
115
+ * @param painted - From {@link paintedBox}.
116
+ * @param placement - Where the host put the frame.
117
+ */
118
+ function windowBox(painted, placement) {
119
+ if (!painted)
120
+ return null;
121
+ const left = Math.max(0, Math.floor(painted.x + placement.x - exports.BOX_MARGIN));
122
+ const top = Math.max(0, Math.floor(painted.y + placement.y - exports.BOX_MARGIN));
123
+ const right = Math.min(placement.viewportWidth, Math.ceil(painted.x + placement.x + painted.width + exports.BOX_MARGIN));
124
+ const bottom = Math.min(placement.viewportHeight, Math.ceil(painted.y + placement.y + painted.height + exports.BOX_MARGIN));
125
+ if (right <= left || bottom <= top)
126
+ return null;
127
+ return { x: left, y: top, width: right - left, height: bottom - top };
128
+ }
129
+ /** How soon after a change the box is measured again, in ms: changes in a burst measure once. */
130
+ const MEASURE_DELAY_MS = 16;
131
+ /**
132
+ * In a global widget's frame: report the box its content covers whenever it may have changed (the
133
+ * DOM or a style changed, the frame moved or resized, a transition ended), and when an element in
134
+ * it captures the pointer or lets it go. Mutations, not animation frames, drive it: a browser may
135
+ * stop rendering a frame that shows next to nothing.
136
+ *
137
+ * @param host - The channel to the host.
138
+ * @param where - Where the host has put the frame now.
139
+ */
140
+ function startWidgetBoxReports(host, where) {
141
+ let last = "";
142
+ let timer;
143
+ const measure = () => {
144
+ timer = undefined;
145
+ const placement = where();
146
+ if (!placement)
147
+ return;
148
+ const box = windowBox(paintedBox(document.body), placement);
149
+ const key = JSON.stringify(box);
150
+ if (key === last)
151
+ return;
152
+ last = key;
153
+ host.notify(frame_protocol_1.FrameNotice.widgetBox, { box });
154
+ };
155
+ const soon = () => {
156
+ if (timer === undefined)
157
+ timer = setTimeout(measure, MEASURE_DELAY_MS);
158
+ };
159
+ // The body's own style changes when the host moves the frame: measured again too.
160
+ const mutations = new MutationObserver(soon);
161
+ mutations.observe(document.body, {
162
+ subtree: true,
163
+ childList: true,
164
+ attributes: true,
165
+ characterData: true,
166
+ });
167
+ const resizes = typeof ResizeObserver === "undefined" ? undefined : new ResizeObserver(soon);
168
+ resizes?.observe(document.body);
169
+ window.addEventListener("resize", soon);
170
+ window.addEventListener("transitionend", soon, true);
171
+ // An image getting its size changes no DOM, but its box. Its load doesn't bubble, and never
172
+ // reaches the window, even while capturing: the document's capture sees it. (A video sends
173
+ // `loadedmetadata` instead, which isn't listened for.)
174
+ document.addEventListener("load", soon, true);
175
+ window.addEventListener("animationend", soon, true);
176
+ const captured = () => host.notify(frame_protocol_1.FrameNotice.widgetCapture, { active: true });
177
+ const released = () => host.notify(frame_protocol_1.FrameNotice.widgetCapture, { active: false });
178
+ window.addEventListener("gotpointercapture", captured, true);
179
+ window.addEventListener("lostpointercapture", released, true);
180
+ soon();
181
+ return () => {
182
+ if (timer !== undefined)
183
+ clearTimeout(timer);
184
+ mutations.disconnect();
185
+ resizes?.disconnect();
186
+ window.removeEventListener("resize", soon);
187
+ window.removeEventListener("transitionend", soon, true);
188
+ document.removeEventListener("load", soon, true);
189
+ window.removeEventListener("animationend", soon, true);
190
+ window.removeEventListener("gotpointercapture", captured, true);
191
+ window.removeEventListener("lostpointercapture", released, true);
192
+ };
193
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Defer loading a module until it's first needed, so code most screens never use (the editor,
3
+ * the markdown renderer) isn't compiled and run when peers-ui loads. Every isolated screen and
4
+ * piece is a frame that loads peers-ui on its own, so whatever loads up front, every frame pays.
5
+ *
6
+ * `load` is a `require` inside a function. A bundler then runs that module on the first call:
7
+ * webpack (Electron) and esbuild for any module, Rollup (the PWA) for CommonJS ones only. Rollup
8
+ * runs ES modules (Lexical, react-markdown) up front wherever they're required.
9
+ *
10
+ * A module that throws while loading isn't loaded again: the bundlers keep what it had exported
11
+ * when it threw, so the component fails to draw until the page reloads (the screen's error
12
+ * boundary shows it). Under Jest and Node, the next call tries again.
13
+ *
14
+ * @param load - Loads the module, as `() => require("./x") as typeof import("./x")`.
15
+ * @returns A function that loads the module the first time it's called and returns it after.
16
+ */
17
+ export declare function lazyModule<T>(load: () => T): () => T;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.lazyModule = lazyModule;
4
+ /**
5
+ * Defer loading a module until it's first needed, so code most screens never use (the editor,
6
+ * the markdown renderer) isn't compiled and run when peers-ui loads. Every isolated screen and
7
+ * piece is a frame that loads peers-ui on its own, so whatever loads up front, every frame pays.
8
+ *
9
+ * `load` is a `require` inside a function. A bundler then runs that module on the first call:
10
+ * webpack (Electron) and esbuild for any module, Rollup (the PWA) for CommonJS ones only. Rollup
11
+ * runs ES modules (Lexical, react-markdown) up front wherever they're required.
12
+ *
13
+ * A module that throws while loading isn't loaded again: the bundlers keep what it had exported
14
+ * when it threw, so the component fails to draw until the page reloads (the screen's error
15
+ * boundary shows it). Under Jest and Node, the next call tries again.
16
+ *
17
+ * @param load - Loads the module, as `() => require("./x") as typeof import("./x")`.
18
+ * @returns A function that loads the module the first time it's called and returns it after.
19
+ */
20
+ function lazyModule(load) {
21
+ let loaded;
22
+ return () => {
23
+ loaded ??= { module: load() };
24
+ return loaded.module;
25
+ };
26
+ }
@@ -193,15 +193,6 @@ for (const [name, params] of Object.entries(CONSOLE_PARAMS)) {
193
193
  }
194
194
  /** The Console's own helpers, beside the session's, with their argument hints. */
195
195
  const consoleHelpers = {
196
- help: (0, repl_1.withCallInfo)(function help() {
197
- return CONSOLE_HELP_TEXT;
198
- }, {
199
- name: "help",
200
- kind: "helper",
201
- params: [],
202
- objectArgument: false,
203
- description: "How contracts, these helpers and the Console's keys are used.",
204
- }),
205
196
  print: (0, repl_1.withCallInfo)(function print(...values) {
206
197
  consolePrint(...values);
207
198
  }, {
@@ -240,6 +231,7 @@ async function open(transport) {
240
231
  scope: exports.consoleScope.values,
241
232
  print: (value) => printAt("log", [value], undefined),
242
233
  reserved: [...console_scope_1.CONSOLE_GLOBAL_NAMES, "print", "console", "clear", "$"],
234
+ helpText: CONSOLE_HELP_TEXT,
243
235
  });
244
236
  next.onChange = () => {
245
237
  (0, exports.consoleContext)(next.contextName);
@@ -70,7 +70,11 @@ function setConsoleSize(size) {
70
70
  * platforms (matching VS Code / Cursor). Intentionally not Cmd on macOS.
71
71
  */
72
72
  function handleKeyDown(event) {
73
- if (event.ctrlKey && !event.metaKey && !event.altKey && event.code === "Backquote") {
73
+ if (event.ctrlKey &&
74
+ !event.metaKey &&
75
+ !event.altKey &&
76
+ event.code === "Backquote" &&
77
+ !event.defaultPrevented) {
74
78
  event.preventDefault();
75
79
  toggleConsole();
76
80
  }
@@ -20,6 +20,8 @@ const react_1 = require("react");
20
20
  const command_palette_ui_1 = require("../command-palette/command-palette-ui");
21
21
  const globals_1 = require("../globals");
22
22
  const hooks_1 = require("../hooks");
23
+ const config_1 = require("../isolated-screens/config");
24
+ const global_widgets_1 = require("../isolated-screens/global-widgets");
23
25
  const identity_ipc_1 = require("../screens/device-pairing/identity-ipc");
24
26
  const identity_routes_1 = require("../screens/identity/identity-routes");
25
27
  const invite_capture_1 = require("../screens/invites/invite-capture");
@@ -116,5 +118,5 @@ function RootLayoutBootstrap(props) {
116
118
  document.getElementById("appLoadingDiv")?.remove();
117
119
  const layout = (0, root_layout_registry_1.getRootLayout)(layoutId ?? root_layout_registry_1.DEFAULT_ROOT_LAYOUT_ID) ?? (0, root_layout_registry_1.getRootLayout)(root_layout_registry_1.DEFAULT_ROOT_LAYOUT_ID);
118
120
  const Body = layout?.Component;
119
- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [Body && (0, jsx_runtime_1.jsx)(Body, {}), (0, jsx_runtime_1.jsx)(command_palette_ui_1.CommandPaletteOverlay, {}), overlays.map(({ id, Component }) => ((0, jsx_runtime_1.jsx)(Component, {}, id))), showWelcomeModal && ((0, jsx_runtime_1.jsx)(welcome_modal_1.WelcomeModal, { colorMode: _colorMode, onClose: () => setShowWelcomeModal(false) }))] }));
121
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [Body && (0, jsx_runtime_1.jsx)(Body, {}), (0, jsx_runtime_1.jsx)(command_palette_ui_1.CommandPaletteOverlay, {}), overlays.map(({ id, Component }) => ((0, jsx_runtime_1.jsx)(Component, {}, id))), (0, config_1.isolatedScreensHost)() ? (0, jsx_runtime_1.jsx)(global_widgets_1.GlobalWidgetsLayer, {}) : null, showWelcomeModal && ((0, jsx_runtime_1.jsx)(welcome_modal_1.WelcomeModal, { colorMode: _colorMode, onClose: () => setShowWelcomeModal(false) }))] }));
120
122
  }
@@ -25,9 +25,14 @@ const GroupMembersUI = (props) => {
25
25
  const members = await groupMembersTable.list({ deleted: { $ne: true } });
26
26
  // Get user details for each member using the group context
27
27
  const membersWithUsers = await Promise.all(members.map(async (member) => {
28
+ // A member whose profile or trust can't be read is listed by id, as one with no
29
+ // profile is, rather than leaving the whole list unloaded.
28
30
  const user = await (0, peers_sdk_1.getUserById)(member.userId, {
29
31
  currentDataContext: groupDataContext,
30
32
  includeTrustLevel: true,
33
+ }).catch((err) => {
34
+ console.error(`Failed to read group member ${member.userId}:`, err);
35
+ return undefined;
31
36
  });
32
37
  // If user found from external source, save to current group
33
38
  if (user && user.source !== "currentDataContext") {
@@ -46,22 +51,6 @@ const GroupMembersUI = (props) => {
46
51
  console.error("Failed to save user to group context:", saveErr);
47
52
  }
48
53
  }
49
- // TODO don't do it this way!!! Use group-specific trust level fetching
50
- if (user && !user.trustLevel) {
51
- const userCursor = await (0, peers_sdk_1.usersCursor)({ userId: member.userId }, { includeTrustLevel: true });
52
- const _user = await userCursor.next();
53
- user.trustLevel = _user?.trustLevel || user.trustLevel || peers_sdk_1.TrustLevel.Unknown;
54
- }
55
- // // Fetch trust level for this user in the group context
56
- // if (user) {
57
- // try {
58
- // const trustLevel = await getUserTrustLevel(groupDataContext, user.userId);
59
- // user.trustLevel = trustLevel;
60
- // } catch (err) {
61
- // console.error('Failed to get trust level:', err);
62
- // user.trustLevel = TrustLevel.Unknown;
63
- // }
64
- // }
65
54
  return {
66
55
  member,
67
56
  user: user || null,
@@ -89,9 +78,10 @@ const GroupMembersUI = (props) => {
89
78
  if (!group) {
90
79
  return null;
91
80
  }
92
- // Try to get founder user details
81
+ // Try to get founder user details. The banner shows only the name, so no trust is read.
93
82
  const founderUser = await (0, peers_sdk_1.getUserById)(group.founderUserId, {
94
83
  currentDataContext: groupDataContext,
84
+ includeTrustLevel: false,
95
85
  });
96
86
  return {
97
87
  group,
@@ -8,8 +8,13 @@ const qr_scanner_1 = require("../../components/qr-scanner");
8
8
  const globals_1 = require("../../globals");
9
9
  const invite_capture_1 = require("./invite-capture");
10
10
  const invites_ipc_1 = require("./invites-ipc");
11
+ /**
12
+ * The trust choices for a new contact. The first, `""`, sets no level, so they follow the default:
13
+ * New User for their first week, then Known (see `getUserTrust`). The others set a level.
14
+ */
11
15
  const TRUST_OPTIONS = [
12
- { value: peers_sdk_1.TrustLevel.NewUser, label: "New user (default)" },
16
+ { value: "", label: "Default: New user for a week, then Known" },
17
+ { value: peers_sdk_1.TrustLevel.NewUser, label: "New user" },
13
18
  { value: peers_sdk_1.TrustLevel.Known, label: "Known" },
14
19
  { value: peers_sdk_1.TrustLevel.Trusted, label: "Trusted" },
15
20
  ];
@@ -42,7 +47,7 @@ function AcceptInvite(props) {
42
47
  const [scanning, setScanning] = (0, react_1.useState)(false);
43
48
  const [preview, setPreview] = (0, react_1.useState)(undefined);
44
49
  const [result, setResult] = (0, react_1.useState)(undefined);
45
- const [trustLevel, setTrustLevel] = (0, react_1.useState)(peers_sdk_1.TrustLevel.NewUser);
50
+ const [trustLevel, setTrustLevel] = (0, react_1.useState)(undefined);
46
51
  const [busy, setBusy] = (0, react_1.useState)(false);
47
52
  const [error, setError] = (0, react_1.useState)("");
48
53
  const runPreview = (0, react_1.useCallback)(async (token) => {
@@ -51,6 +56,7 @@ function AcceptInvite(props) {
51
56
  try {
52
57
  const tools = await (0, invites_ipc_1.inviteTools)();
53
58
  const response = await tools.previewInvite({ token });
59
+ setTrustLevel(undefined);
54
60
  setPreview(response.preview);
55
61
  setText(token);
56
62
  }
@@ -120,7 +126,10 @@ function AcceptInvite(props) {
120
126
  setBusy(true);
121
127
  try {
122
128
  const tools = await (0, invites_ipc_1.inviteTools)();
123
- const response = await tools.acceptInvite({ token: text, trustLevel });
129
+ const response = await tools.acceptInvite({
130
+ token: text,
131
+ ...(preview?.knownContact || trustLevel === undefined ? {} : { trustLevel }),
132
+ });
124
133
  setResult(response.result);
125
134
  }
126
135
  catch (err) {
@@ -149,7 +158,9 @@ function AcceptInvite(props) {
149
158
  setError(message);
150
159
  } }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-outline-secondary mt-3", onClick: () => setScanning(false), children: "Cancel" })] }));
151
160
  }
152
- return ((0, jsx_runtime_1.jsx)("div", { style: { maxWidth: 520, margin: "0 auto" }, children: preview ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(PreviewCard, { preview: preview }), !preview.knownContact ? ((0, jsx_runtime_1.jsxs)("div", { className: "mb-3", children: [(0, jsx_runtime_1.jsxs)("label", { htmlFor: "invite-trust", className: "form-label small text-muted mb-1", children: ["Trust level for ", preview.inviter.displayName || "this contact"] }), (0, jsx_runtime_1.jsx)("select", { id: "invite-trust", className: "form-select form-select-sm", value: trustLevel, onChange: (event) => setTrustLevel(Number(event.target.value)), disabled: busy, children: TRUST_OPTIONS.map((option) => ((0, jsx_runtime_1.jsx)("option", { value: option.value, children: option.label }, option.value))) })] })) : null, error ? (0, jsx_runtime_1.jsx)("div", { className: "alert alert-danger py-2", children: error }) : null, (0, jsx_runtime_1.jsxs)("div", { className: "d-flex gap-2", children: [(0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-primary", disabled: busy || preview.expired || preview.group?.alreadyMember, onClick: () => void accept(), children: busy ? "Working…" : preview.type === "group" ? "Join" : "Accept" }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-outline-secondary", onClick: reset, children: "Back" })] })] })) : ((0, jsx_runtime_1.jsxs)("form", { onSubmit: (event) => {
161
+ return ((0, jsx_runtime_1.jsx)("div", { style: { maxWidth: 520, margin: "0 auto" }, children: preview ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(PreviewCard, { preview: preview }), !preview.knownContact ? ((0, jsx_runtime_1.jsxs)("div", { className: "mb-3", children: [(0, jsx_runtime_1.jsxs)("label", { htmlFor: "invite-trust", className: "form-label small text-muted mb-1", children: ["Trust level for ", preview.inviter.displayName || "this contact"] }), (0, jsx_runtime_1.jsx)("select", { id: "invite-trust", className: "form-select form-select-sm", value: trustLevel ?? "", onChange: (event) => setTrustLevel(event.target.value === ""
162
+ ? undefined
163
+ : Number(event.target.value)), disabled: busy, children: TRUST_OPTIONS.map((option) => ((0, jsx_runtime_1.jsx)("option", { value: option.value, children: option.label }, option.value))) })] })) : null, error ? (0, jsx_runtime_1.jsx)("div", { className: "alert alert-danger py-2", children: error }) : null, (0, jsx_runtime_1.jsxs)("div", { className: "d-flex gap-2", children: [(0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-primary", disabled: busy || preview.expired || preview.group?.alreadyMember, onClick: () => void accept(), children: busy ? "Working…" : preview.type === "group" ? "Join" : "Accept" }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-outline-secondary", onClick: reset, children: "Back" })] })] })) : ((0, jsx_runtime_1.jsxs)("form", { onSubmit: (event) => {
153
164
  event.preventDefault();
154
165
  void runPreview(text);
155
166
  }, children: [(0, jsx_runtime_1.jsx)("label", { htmlFor: "invite-text", className: "form-label", children: "Paste an invite link or code" }), (0, jsx_runtime_1.jsx)("textarea", { id: "invite-text", className: "form-control font-monospace mb-2", rows: 3, value: text, onChange: (event) => setText(event.target.value), placeholder: "https://peers.app/i#\u2026", disabled: busy, spellCheck: false }), error ? (0, jsx_runtime_1.jsx)("div", { className: "alert alert-danger py-2", children: error }) : null, (0, jsx_runtime_1.jsxs)("div", { className: "d-flex gap-2", children: [(0, jsx_runtime_1.jsx)("button", { type: "submit", className: "btn btn-primary", disabled: busy || !text.trim(), children: busy ? "Checking…" : "Continue" }), (0, qr_scanner_1.canScanQr)() ? ((0, jsx_runtime_1.jsxs)("button", { type: "button", className: "btn btn-outline-primary", disabled: busy, onClick: () => setScanning(true), children: [(0, jsx_runtime_1.jsx)("i", { className: "bi bi-qr-code-scan me-1" }), "Scan QR"] })) : null] })] })) }));
@@ -10,6 +10,7 @@ const acts_for_you_panel_1 = require("../../delegates/acts-for-you-panel");
10
10
  const hooks_1 = require("../../hooks");
11
11
  const host_shell_consumer_1 = require("../../host-shell/host-shell-consumer");
12
12
  const package_network_panel_1 = require("./package-network-panel");
13
+ const package_widgets_panel_1 = require("./package-widgets-panel");
13
14
  /** Info tab for the package details screen. */
14
15
  const PackageInfo = (props) => {
15
16
  const { pkg } = props;
@@ -121,6 +122,6 @@ const PackageInfo = (props) => {
121
122
  await (0, peers_sdk_1.updatePackagePrefs)(pkg.packageId, {
122
123
  followTags: val === "stable" ? "stable" : val,
123
124
  });
124
- }, children: [(0, jsx_runtime_1.jsx)("option", { value: "stable", children: "Stable" }), (0, jsx_runtime_1.jsx)("option", { value: "stable,beta", children: "Stable + Beta" })] })] })] }))] }), (0, jsx_runtime_1.jsxs)("div", { className: "mt-2", children: [(0, jsx_runtime_1.jsx)("hr", {}), (0, jsx_runtime_1.jsxs)("small", { children: ["Description:", (0, jsx_runtime_1.jsx)(tooltip_1.Tooltip, { markdownContent: `This should be edited in the package's README.md. It will automatically update when you restart Peers or reload the package.` })] }), (0, jsx_runtime_1.jsx)(markdown_with_mentions_1.MarkdownWithMentions, { content: pkg.description || "" })] }), (0, jsx_runtime_1.jsx)(package_network_panel_1.PackageNetworkPanel, { packageId: pkg.packageId }), (0, jsx_runtime_1.jsx)(acts_for_you_panel_1.ActsForYouPanel, { packageId: pkg.packageId, packageName: pkg.name || pkg.packageId })] }));
125
+ }, children: [(0, jsx_runtime_1.jsx)("option", { value: "stable", children: "Stable" }), (0, jsx_runtime_1.jsx)("option", { value: "stable,beta", children: "Stable + Beta" })] })] })] }))] }), (0, jsx_runtime_1.jsxs)("div", { className: "mt-2", children: [(0, jsx_runtime_1.jsx)("hr", {}), (0, jsx_runtime_1.jsxs)("small", { children: ["Description:", (0, jsx_runtime_1.jsx)(tooltip_1.Tooltip, { markdownContent: `This should be edited in the package's README.md. It will automatically update when you restart Peers or reload the package.` })] }), (0, jsx_runtime_1.jsx)(markdown_with_mentions_1.MarkdownWithMentions, { content: pkg.description || "" })] }), (0, jsx_runtime_1.jsx)(package_network_panel_1.PackageNetworkPanel, { packageId: pkg.packageId }), (0, jsx_runtime_1.jsx)(package_widgets_panel_1.PackageWidgetsPanel, { packageId: pkg.packageId, packageName: pkg.name || pkg.packageId, packageVersionId: activeVersionId }), (0, jsx_runtime_1.jsx)(acts_for_you_panel_1.ActsForYouPanel, { packageId: pkg.packageId, packageName: pkg.name || pkg.packageId })] }));
125
126
  };
126
127
  exports.PackageInfo = PackageInfo;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * A package's widgets over every app, each with an on/off switch for this device: the ones the
3
+ * manifest this device stored for the selected version declares, and the ones Peers draws now
4
+ * (from the version running in Personal, which may be an older one while an update waits). Shows
5
+ * nothing for a package with neither.
6
+ *
7
+ * @param props.packageId - The package.
8
+ * @param props.packageName - Its name.
9
+ * @param props.packageVersionId - The selected version in the group the screen shows.
10
+ */
11
+ export declare function PackageWidgetsPanel(props: {
12
+ packageId: string;
13
+ packageName: string;
14
+ packageVersionId?: string;
15
+ }): import("react/jsx-runtime").JSX.Element | null;
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PackageWidgetsPanel = PackageWidgetsPanel;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const peers_sdk_1 = require("@peers-app/peers-sdk");
6
+ const react_1 = require("react");
7
+ const hooks_1 = require("../../hooks");
8
+ const frame_permissions_1 = require("../../isolated-screens/frame-permissions");
9
+ const global_widgets_1 = require("../../isolated-screens/global-widgets");
10
+ const piece_reach_1 = require("../../isolated-screens/piece-reach");
11
+ /**
12
+ * A package's widgets over every app, each with an on/off switch for this device: the ones the
13
+ * manifest this device stored for the selected version declares, and the ones Peers draws now
14
+ * (from the version running in Personal, which may be an older one while an update waits). Shows
15
+ * nothing for a package with neither.
16
+ *
17
+ * @param props.packageId - The package.
18
+ * @param props.packageName - Its name.
19
+ * @param props.packageVersionId - The selected version in the group the screen shows.
20
+ */
21
+ function PackageWidgetsPanel(props) {
22
+ const { packageId, packageVersionId } = props;
23
+ const [declared, setDeclared] = (0, react_1.useState)([]);
24
+ const [off] = (0, hooks_1.useObservable)(frame_permissions_1.globalWidgetsOff);
25
+ const [listed] = (0, hooks_1.useObservable)(global_widgets_1.listedGlobalWidgets);
26
+ (0, react_1.useEffect)(() => {
27
+ let cancelled = false;
28
+ setDeclared([]);
29
+ if (!packageVersionId)
30
+ return;
31
+ void (async () => {
32
+ try {
33
+ const { dataContextId } = await (0, peers_sdk_1.getDefaultDataContext)();
34
+ const manifest = await (0, piece_reach_1.readStoredManifest)(dataContextId, packageVersionId);
35
+ // A stale selection can name another package's version.
36
+ if (!cancelled && manifest?.packageId === packageId) {
37
+ setDeclared((0, global_widgets_1.widgetsDeclaredIn)(manifest));
38
+ }
39
+ }
40
+ catch {
41
+ if (!cancelled)
42
+ setDeclared([]);
43
+ }
44
+ })();
45
+ return () => {
46
+ cancelled = true;
47
+ };
48
+ }, [packageId, packageVersionId]);
49
+ const widgets = new Map();
50
+ for (const entry of listed ?? []) {
51
+ if (entry.packageId === packageId)
52
+ widgets.set(entry.widget.id, entry.widget);
53
+ }
54
+ for (const widget of declared)
55
+ if (!widgets.has(widget.id))
56
+ widgets.set(widget.id, widget);
57
+ if (!widgets.size)
58
+ return null;
59
+ const hidden = new Set(Array.isArray(off) ? off : []);
60
+ return ((0, jsx_runtime_1.jsxs)("div", { className: "mt-2", "data-package-widgets": packageId, children: [(0, jsx_runtime_1.jsx)("hr", {}), (0, jsx_runtime_1.jsx)("small", { children: "Over every app (this device):" }), [...widgets.values()].map((widget) => {
61
+ const id = `widget-${packageId}-${widget.id}`;
62
+ return ((0, jsx_runtime_1.jsxs)("div", { className: "form-check form-switch", children: [(0, jsx_runtime_1.jsx)("input", { id: id, className: "form-check-input", type: "checkbox", checked: !hidden.has(`${packageId}:${widget.id}`), onChange: (event) => (0, frame_permissions_1.setGlobalWidgetOn)(packageId, widget.id, event.target.checked) }), (0, jsx_runtime_1.jsx)("label", { className: "form-check-label", htmlFor: id, children: widget.title })] }, widget.id));
63
+ }), (0, jsx_runtime_1.jsxs)("div", { className: "form-text", children: ["Drawn from the copy of ", props.packageName, " in your Personal group."] })] }));
64
+ }
@@ -2,11 +2,14 @@ import { type IAppNav, type Observable } from "@peers-app/peers-sdk";
2
2
  import { type IPackageWithNavs } from "../ui-router/routes-loader";
3
3
  import { type TabState } from "./tab-order";
4
4
  export { launcherApp, normalizeTabHistory, previousAppTabId, type TabState, tabsByRecentUse, } from "./tab-order";
5
- /** Open tabs. Writes through to device storage after the initial restore. */
5
+ /**
6
+ * Open tabs. Writes through to device storage after the initial restore. In a package's frame
7
+ * they're the host's, read only, and follow it.
8
+ */
6
9
  export declare const activeTabs: Observable<TabState[]> & {
7
10
  loadingPromise: Promise<void>;
8
11
  };
9
- /** Id of the tab whose path is showing. */
12
+ /** Id of the tab whose path is showing. In a package's frame, the host's, kept current. */
10
13
  export declare const activeTabId: Observable<string> & {
11
14
  loadingPromise: Promise<void>;
12
15
  };