@peers-app/peers-ui 0.34.14 → 0.34.15

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 (122) hide show
  1. package/dist/apps-home/app-menu.d.ts +1 -2
  2. package/dist/apps-home/app-menu.js +29 -25
  3. package/dist/command-palette/command-palette-ui.js +13 -12
  4. package/dist/components/autocomplete-chips.d.ts +18 -0
  5. package/dist/components/autocomplete-chips.js +49 -0
  6. package/dist/components/autocomplete.d.ts +88 -0
  7. package/dist/components/autocomplete.js +346 -0
  8. package/dist/components/confirm-button.d.ts +26 -0
  9. package/dist/components/confirm-button.js +55 -0
  10. package/dist/components/data-grid/autocomplete.d.ts +1 -31
  11. package/dist/components/data-grid/autocomplete.js +5 -197
  12. package/dist/components/empty-state.d.ts +16 -0
  13. package/dist/components/empty-state.js +16 -0
  14. package/dist/components/group-switcher.d.ts +3 -3
  15. package/dist/components/group-switcher.js +22 -17
  16. package/dist/components/inline-create-form.d.ts +22 -0
  17. package/dist/components/inline-create-form.js +56 -0
  18. package/dist/components/list-row.d.ts +33 -0
  19. package/dist/components/list-row.js +30 -0
  20. package/dist/components/list-screen.d.ts +31 -3
  21. package/dist/components/list-screen.js +61 -28
  22. package/dist/components/markdown-editor/format-bar.js +15 -40
  23. package/dist/components/markdown-editor/link-plugin.js +38 -9
  24. package/dist/components/markdown-editor/selection-bar-place.d.ts +37 -0
  25. package/dist/components/markdown-editor/selection-bar-place.js +107 -0
  26. package/dist/components/menu-button.d.ts +34 -0
  27. package/dist/components/menu-button.js +66 -0
  28. package/dist/components/screen-header.d.ts +35 -0
  29. package/dist/components/screen-header.js +30 -0
  30. package/dist/components/search-field.d.ts +22 -0
  31. package/dist/components/search-field.js +22 -0
  32. package/dist/components/segmented-control.d.ts +25 -0
  33. package/dist/components/segmented-control.js +18 -0
  34. package/dist/components/typeahead.d.ts +9 -0
  35. package/dist/components/typeahead.js +7 -0
  36. package/dist/groups/groups-client.d.ts +23 -1
  37. package/dist/groups/groups-client.js +31 -0
  38. package/dist/index.d.ts +10 -0
  39. package/dist/index.js +14 -1
  40. package/dist/isolated-screens/config.js +1 -9
  41. package/dist/isolated-screens/folder-picker-control.d.ts +57 -0
  42. package/dist/isolated-screens/folder-picker-control.js +217 -0
  43. package/dist/isolated-screens/folder-picker-host.d.ts +57 -0
  44. package/dist/isolated-screens/folder-picker-host.js +178 -0
  45. package/dist/isolated-screens/folder-picker-protocol.d.ts +75 -0
  46. package/dist/isolated-screens/folder-picker-protocol.js +104 -0
  47. package/dist/isolated-screens/frame-bridge.js +8 -0
  48. package/dist/isolated-screens/frame-document.js +2 -1
  49. package/dist/isolated-screens/frame-microphone.d.ts +55 -0
  50. package/dist/isolated-screens/frame-microphone.js +265 -0
  51. package/dist/isolated-screens/frame-permissions.d.ts +19 -0
  52. package/dist/isolated-screens/frame-permissions.js +32 -0
  53. package/dist/isolated-screens/frame-protocol.d.ts +26 -0
  54. package/dist/isolated-screens/frame-protocol.js +9 -0
  55. package/dist/isolated-screens/frame-pvars.d.ts +27 -0
  56. package/dist/isolated-screens/frame-pvars.js +101 -14
  57. package/dist/isolated-screens/global-widgets.d.ts +1 -2
  58. package/dist/isolated-screens/index.d.ts +2 -0
  59. package/dist/isolated-screens/index.js +3 -1
  60. package/dist/isolated-screens/isolated-screen.d.ts +21 -0
  61. package/dist/isolated-screens/isolated-screen.js +88 -5
  62. package/dist/isolated-screens/local-folder-picker.d.ts +55 -0
  63. package/dist/isolated-screens/local-folder-picker.js +143 -0
  64. package/dist/isolated-screens/microphone-host.d.ts +110 -0
  65. package/dist/isolated-screens/microphone-host.js +397 -0
  66. package/dist/isolated-screens/microphone-prompt.d.ts +20 -0
  67. package/dist/isolated-screens/microphone-prompt.js +60 -0
  68. package/dist/isolated-screens/piece-frames.js +5 -94
  69. package/dist/isolated-screens/piece-reach.d.ts +1 -0
  70. package/dist/isolated-screens/port-channel.d.ts +21 -11
  71. package/dist/isolated-screens/port-channel.js +15 -5
  72. package/dist/isolated-screens/slot-rect.d.ts +38 -0
  73. package/dist/isolated-screens/slot-rect.js +121 -0
  74. package/dist/isolated-screens/test-ports.d.ts +17 -0
  75. package/dist/isolated-screens/test-ports.js +25 -3
  76. package/dist/mentions/mention-chooser.js +1 -1
  77. package/dist/notifications/notifications-screen.js +1 -1
  78. package/dist/screens/data-explorer/data-explorer.d.ts +1 -0
  79. package/dist/screens/data-explorer/data-explorer.js +28 -10
  80. package/dist/screens/data-explorer/query-executor.d.ts +1 -0
  81. package/dist/screens/data-explorer/query-executor.js +3 -1
  82. package/dist/screens/groups/group-list.d.ts +13 -3
  83. package/dist/screens/groups/group-list.js +88 -11
  84. package/dist/screens/identity/identity-routes.d.ts +16 -0
  85. package/dist/screens/identity/identity-routes.js +27 -10
  86. package/dist/screens/identity/identity-screen.js +4 -1
  87. package/dist/screens/invites/activity-view.d.ts +3 -1
  88. package/dist/screens/invites/activity-view.js +7 -3
  89. package/dist/screens/invites/pending-invites-list.d.ts +8 -4
  90. package/dist/screens/invites/pending-invites-list.js +44 -45
  91. package/dist/screens/network-viewer/graph/network-graph-controls.js +3 -3
  92. package/dist/screens/packages/local-folder-grants-panel.d.ts +2 -0
  93. package/dist/screens/packages/local-folder-grants-panel.js +1 -1
  94. package/dist/screens/packages/package-info.js +2 -1
  95. package/dist/screens/packages/package-list.d.ts +2 -2
  96. package/dist/screens/packages/package-list.js +89 -105
  97. package/dist/screens/packages/package-microphone-panel.d.ts +14 -0
  98. package/dist/screens/packages/package-microphone-panel.js +62 -0
  99. package/dist/screens/packages/package-runtime-status.d.ts +10 -2
  100. package/dist/screens/packages/package-runtime-status.js +17 -4
  101. package/dist/screens/peer-types/peer-type-details.js +3 -2
  102. package/dist/screens/peer-types/peer-type-list.d.ts +1 -1
  103. package/dist/screens/peer-types/peer-type-list.js +4 -4
  104. package/dist/screens/settings/settings-page.js +1 -4
  105. package/dist/screens/tools/tool-details.js +2 -1
  106. package/dist/screens/tools/tool-list.d.ts +1 -1
  107. package/dist/screens/tools/tool-list.js +22 -60
  108. package/dist/screens/variables/variable-details.js +5 -4
  109. package/dist/screens/variables/variable-list.d.ts +17 -0
  110. package/dist/screens/variables/variable-list.js +72 -28
  111. package/dist/tabs-layout/network-status-details.d.ts +4 -4
  112. package/dist/tabs-layout/network-status-details.js +6 -5
  113. package/dist/tabs-layout/network-status-indicator.d.ts +1 -0
  114. package/dist/tabs-layout/network-status-indicator.js +1 -0
  115. package/dist/tabs-layout/tab-bar-shortcuts.d.ts +46 -0
  116. package/dist/tabs-layout/tab-bar-shortcuts.js +140 -0
  117. package/dist/tabs-layout/tabs-layout.js +11 -9
  118. package/dist/theme.css +326 -6
  119. package/dist/ui-contracts/popover-surface.d.ts +3 -0
  120. package/dist/ui-contracts/popover-surface.js +6 -3
  121. package/dist/ui-defaults/list-screen.js +10 -4
  122. package/package.json +3 -3
@@ -0,0 +1,178 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.installFolderPickerHost = installFolderPickerHost;
4
+ exports.FolderPickerOverSlot = FolderPickerOverSlot;
5
+ const jsx_runtime_1 = require("react/jsx-runtime");
6
+ const peers_sdk_1 = require("@peers-app/peers-sdk");
7
+ const react_1 = require("react");
8
+ const folder_picker_control_1 = require("./folder-picker-control");
9
+ const folder_picker_protocol_1 = require("./folder-picker-protocol");
10
+ /** The most pickers one frame may place at once. */
11
+ const MAX_SLOTS = 64;
12
+ /** How long focus that reached a slot waits for the host to draw its buttons. */
13
+ const PENDING_FOCUS_MS = 1000;
14
+ function finite(values) {
15
+ return values.every((n) => typeof n === "number" && Number.isFinite(n));
16
+ }
17
+ /** A box as a frame reports it, refused unless it's four finite numbers. */
18
+ function toRect(value) {
19
+ const r = value;
20
+ if (!r || !finite([r.x, r.y, r.width, r.height]))
21
+ return undefined;
22
+ return {
23
+ x: r.x,
24
+ y: r.y,
25
+ width: r.width,
26
+ height: r.height,
27
+ };
28
+ }
29
+ function toClip(value) {
30
+ const r = value;
31
+ if (!r || !finite([r.top, r.right, r.bottom, r.left]))
32
+ return undefined;
33
+ return {
34
+ top: r.top,
35
+ right: r.right,
36
+ bottom: r.bottom,
37
+ left: r.left,
38
+ };
39
+ }
40
+ /**
41
+ * Check a request from a frame, and that its group is one the person is in here.
42
+ *
43
+ * @throws When it isn't a request the host draws.
44
+ */
45
+ function checkedRequest(value) {
46
+ const request = (0, folder_picker_protocol_1.toFolderPickerRequest)(value);
47
+ if ("error" in request)
48
+ throw new Error(request.error);
49
+ const user = (0, peers_sdk_1.peekUserContext)();
50
+ if (!user || (request.groupId !== user.userId && !user.groupDataContexts.has(request.groupId))) {
51
+ throw new Error("That group isn't available to this screen");
52
+ }
53
+ return request;
54
+ }
55
+ /**
56
+ * Listen to a frame's folder picker messages.
57
+ *
58
+ * @param channel - The frame's channel.
59
+ * @param opts.slots - The frame's pickers, which its component draws.
60
+ * @param opts.hasFocus - Whether the frame still has the focus: focus the user moved elsewhere
61
+ * before a notice arrived stays there.
62
+ */
63
+ function installFolderPickerHost(channel, opts) {
64
+ const { slots } = opts;
65
+ const controls = new Map();
66
+ // Focus that reached a slot before the host drew its buttons: given to them once they're drawn,
67
+ // if that's soon (the screen may have moved focus on since), and the frame still has the focus.
68
+ const pendingFocus = new Map();
69
+ const update = (slotId, change) => {
70
+ const list = slots();
71
+ const index = list.findIndex((slot) => slot.slotId === slotId);
72
+ if (index < 0)
73
+ return;
74
+ const next = [...list];
75
+ next[index] = change(list[index]);
76
+ slots(next);
77
+ };
78
+ // The handlers last as long as the channel: the frame's session closes it when it ends.
79
+ channel.onRequest(folder_picker_protocol_1.FolderPickerMessage.mount, (input) => {
80
+ const slotId = input?.slotId;
81
+ if (typeof slotId !== "string" || !slotId || slotId.length > 64) {
82
+ throw new Error("That isn't a folder picker slot");
83
+ }
84
+ const request = checkedRequest(input?.request);
85
+ const others = slots().filter((slot) => slot.slotId !== slotId);
86
+ if (others.length >= MAX_SLOTS)
87
+ throw new Error("Too many folder pickers on one screen");
88
+ slots([...others, { slotId, request }]);
89
+ });
90
+ channel.onNotify(folder_picker_protocol_1.FolderPickerMessage.rect, (payload) => update(payload?.slotId, (slot) => ({
91
+ ...slot,
92
+ rect: toRect(payload?.rect),
93
+ clip: toClip(payload?.clip),
94
+ })));
95
+ channel.onNotify(folder_picker_protocol_1.FolderPickerMessage.change, (payload) => {
96
+ let request;
97
+ try {
98
+ request = checkedRequest(payload?.request);
99
+ }
100
+ catch (error) {
101
+ update(payload?.slotId, (slot) => ({
102
+ ...slot,
103
+ request: { ...slot.request, disabled: true },
104
+ }));
105
+ const message = error instanceof Error ? error.message : String(error);
106
+ channel.notify(folder_picker_protocol_1.FolderPickerMessage.failed, { slotId: payload?.slotId, message });
107
+ return;
108
+ }
109
+ update(payload?.slotId, (slot) => ({ ...slot, request }));
110
+ });
111
+ channel.onNotify(folder_picker_protocol_1.FolderPickerMessage.unmount, (payload) => {
112
+ slots(slots().filter((slot) => slot.slotId !== payload?.slotId));
113
+ if (typeof payload?.slotId === "string")
114
+ pendingFocus.delete(payload.slotId);
115
+ });
116
+ channel.onNotify(folder_picker_protocol_1.FolderPickerMessage.focus, (payload) => {
117
+ if (!opts.hasFocus() || typeof payload?.slotId !== "string")
118
+ return;
119
+ const edge = payload.edge === "last" ? "last" : "first";
120
+ const control = controls.get(payload.slotId);
121
+ if (!control && !slots().some((slot) => slot.slotId === payload.slotId))
122
+ return;
123
+ // Reaching another picker supersedes the earlier handoff, even if it draws first.
124
+ pendingFocus.clear();
125
+ if (control)
126
+ control.focus(edge);
127
+ else
128
+ pendingFocus.set(payload.slotId, { edge, at: Date.now() });
129
+ });
130
+ return {
131
+ register(slotId, control) {
132
+ if (!control) {
133
+ controls.delete(slotId);
134
+ return;
135
+ }
136
+ controls.set(slotId, control);
137
+ const pending = pendingFocus.get(slotId);
138
+ pendingFocus.delete(slotId);
139
+ if (pending && Date.now() - pending.at < PENDING_FOCUS_MS && opts.hasFocus()) {
140
+ control.focus(pending.edge);
141
+ }
142
+ },
143
+ dispose() {
144
+ controls.clear();
145
+ pendingFocus.clear();
146
+ },
147
+ };
148
+ }
149
+ /**
150
+ * Peers' folder picker buttons over a framed screen's slot, placed and clipped where the slot
151
+ * shows. What's picked is granted to `packageId`, the frame's package.
152
+ */
153
+ function FolderPickerOverSlot(props) {
154
+ const { slot, frameId, packageId, session } = props;
155
+ const { slotId, rect, clip } = slot;
156
+ const control = (0, react_1.useRef)(null);
157
+ const place = (0, react_1.useMemo)(() => ({ frameId, slotId }), [frameId, slotId]);
158
+ (0, react_1.useEffect)(() => {
159
+ const host = session.current?.folderPickers;
160
+ host?.register(slotId, control.current);
161
+ return () => host?.register(slotId, null);
162
+ }, [session, slotId, rect !== undefined]);
163
+ if (!rect)
164
+ return null;
165
+ return ((0, jsx_runtime_1.jsx)("div", { "data-peers-folder-picker-frame": frameId, "data-peers-folder-picker-slot": slotId, style: {
166
+ position: "absolute",
167
+ left: rect.x,
168
+ top: rect.y,
169
+ width: rect.width,
170
+ height: rect.height,
171
+ ...(clip
172
+ ? { clipPath: `inset(${clip.top}px ${clip.right}px ${clip.bottom}px ${clip.left}px)` }
173
+ : {}),
174
+ }, children: (0, jsx_runtime_1.jsx)(folder_picker_control_1.FolderPickerControl, { ref: control, request: slot.request, packageId: packageId, onPicked: (grant) => session.current?.slotNotify(folder_picker_protocol_1.FolderPickerMessage.picked, { slotId, grant }), onFailed: (message) => session.current?.slotNotify(folder_picker_protocol_1.FolderPickerMessage.failed, { slotId, message }), overSlot: {
175
+ onTabOut: (direction) => session.current?.focusBack(slotId, direction),
176
+ place,
177
+ } }) }));
178
+ }
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Peers' folder picker in a framed screen: what crosses between the screen's frame and its host.
3
+ *
4
+ * A package can't make a folder grant: System Local Folders refuses package callers, its screens
5
+ * included. Instead its screen places {@link LocalFolderPicker} where the button goes. In a frame
6
+ * that's an empty slot, which the host covers with a button it draws itself, in its own window,
7
+ * so the screen's code can't click it or fake it. A click opens the OS picker, and the host grants
8
+ * what the person picks to the screen's own package and sends the screen the grant. As a browser
9
+ * does for `<input type="file">`: the page asks, the browser draws the control and the picker,
10
+ * and the page gets only what was picked.
11
+ *
12
+ * The slot's box goes to the host as a piece slot's does (`slot-rect.ts`), and Tab moves through
13
+ * the host's button as it does through a piece's frame.
14
+ */
15
+ import type { ILocalFolderGrantInfo, LocalFolderMode, LocalFolderPick } from "@peers-app/peers-sdk";
16
+ /** The messages, by name. */
17
+ export declare const FolderPickerMessage: {
18
+ /** Frame → host request: draw the picker over a slot, `{ slotId, request }`. */
19
+ readonly mount: "folder-picker.mount";
20
+ /** Frame → host: the slot moved, `{ slotId, rect, clip }`, in the frame's coordinates. */
21
+ readonly rect: "folder-picker.rect";
22
+ /** Frame → host: the screen changed what it asks for, `{ slotId, request }`. */
23
+ readonly change: "folder-picker.change";
24
+ /** Frame → host: the slot went away, `{ slotId }`. */
25
+ readonly unmount: "folder-picker.unmount";
26
+ /**
27
+ * Frame → host: Tab reached the slot, `{ slotId, edge }`, `edge` being `"first"` from before it
28
+ * or `"last"` from after it. The host focuses its first or last button.
29
+ */
30
+ readonly focus: "folder-picker.focus";
31
+ /** Host → frame: the person picked, and the grant is made, `{ slotId, grant }`. */
32
+ readonly picked: "folder-picker.picked";
33
+ /** Host → frame: the grant failed, `{ slotId, message }`. Cancelling the picker isn't a failure. */
34
+ readonly failed: "folder-picker.failed";
35
+ };
36
+ /** The button's look: Bootstrap's button variants. */
37
+ export type FolderPickerVariant = "primary" | "secondary" | "outline-primary" | "outline-secondary" | "link";
38
+ /** The longest label the host draws. */
39
+ export declare const FOLDER_PICKER_LABEL_MAX = 80;
40
+ /** What a screen asks Peers' folder picker for. Every field is data, checked by the host. */
41
+ export interface IFolderPickerRequest {
42
+ /** The group the grant is for. */
43
+ groupId: string;
44
+ /** What the package may do in it. Picked files are always read-only. */
45
+ mode: LocalFolderMode;
46
+ /** A folder, or one or more files in one folder. */
47
+ pick: LocalFolderPick;
48
+ /** The button's text. */
49
+ label: string;
50
+ /** A Bootstrap icon name for the button (`folder-plus`), or none. */
51
+ icon?: string;
52
+ variant: FolderPickerVariant;
53
+ size?: "sm" | "lg";
54
+ /**
55
+ * A ▾ beside the button that lists the folders this package already has on this device, in
56
+ * any group, so the person can use one of them here without the picker. Folders only.
57
+ */
58
+ offerExisting: boolean;
59
+ disabled: boolean;
60
+ }
61
+ /** The label when the screen gives none. */
62
+ export declare function defaultFolderPickerLabel(pick: LocalFolderPick): string;
63
+ /** The icon when the screen gives none. */
64
+ export declare function defaultFolderPickerIcon(pick: LocalFolderPick): string;
65
+ /**
66
+ * Check what a frame sent as a picker request: only the fields above, each of its type.
67
+ *
68
+ * @param value - From the frame.
69
+ * @returns The request, or why it was refused.
70
+ */
71
+ export declare function toFolderPickerRequest(value: unknown): IFolderPickerRequest | {
72
+ error: string;
73
+ };
74
+ /** What the host sends back with `picked`: the grant, as `requestGrant` returns it. */
75
+ export type FolderPickerResult = ILocalFolderGrantInfo;
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ /**
3
+ * Peers' folder picker in a framed screen: what crosses between the screen's frame and its host.
4
+ *
5
+ * A package can't make a folder grant: System Local Folders refuses package callers, its screens
6
+ * included. Instead its screen places {@link LocalFolderPicker} where the button goes. In a frame
7
+ * that's an empty slot, which the host covers with a button it draws itself, in its own window,
8
+ * so the screen's code can't click it or fake it. A click opens the OS picker, and the host grants
9
+ * what the person picks to the screen's own package and sends the screen the grant. As a browser
10
+ * does for `<input type="file">`: the page asks, the browser draws the control and the picker,
11
+ * and the page gets only what was picked.
12
+ *
13
+ * The slot's box goes to the host as a piece slot's does (`slot-rect.ts`), and Tab moves through
14
+ * the host's button as it does through a piece's frame.
15
+ */
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.FOLDER_PICKER_LABEL_MAX = exports.FolderPickerMessage = void 0;
18
+ exports.defaultFolderPickerLabel = defaultFolderPickerLabel;
19
+ exports.defaultFolderPickerIcon = defaultFolderPickerIcon;
20
+ exports.toFolderPickerRequest = toFolderPickerRequest;
21
+ /** The messages, by name. */
22
+ exports.FolderPickerMessage = {
23
+ /** Frame → host request: draw the picker over a slot, `{ slotId, request }`. */
24
+ mount: "folder-picker.mount",
25
+ /** Frame → host: the slot moved, `{ slotId, rect, clip }`, in the frame's coordinates. */
26
+ rect: "folder-picker.rect",
27
+ /** Frame → host: the screen changed what it asks for, `{ slotId, request }`. */
28
+ change: "folder-picker.change",
29
+ /** Frame → host: the slot went away, `{ slotId }`. */
30
+ unmount: "folder-picker.unmount",
31
+ /**
32
+ * Frame → host: Tab reached the slot, `{ slotId, edge }`, `edge` being `"first"` from before it
33
+ * or `"last"` from after it. The host focuses its first or last button.
34
+ */
35
+ focus: "folder-picker.focus",
36
+ /** Host → frame: the person picked, and the grant is made, `{ slotId, grant }`. */
37
+ picked: "folder-picker.picked",
38
+ /** Host → frame: the grant failed, `{ slotId, message }`. Cancelling the picker isn't a failure. */
39
+ failed: "folder-picker.failed",
40
+ };
41
+ const VARIANTS = [
42
+ "primary",
43
+ "secondary",
44
+ "outline-primary",
45
+ "outline-secondary",
46
+ "link",
47
+ ];
48
+ /** The longest label the host draws. */
49
+ exports.FOLDER_PICKER_LABEL_MAX = 80;
50
+ /** The label when the screen gives none. */
51
+ function defaultFolderPickerLabel(pick) {
52
+ return pick === "files" ? "Choose files…" : "Choose a folder…";
53
+ }
54
+ /** The icon when the screen gives none. */
55
+ function defaultFolderPickerIcon(pick) {
56
+ return pick === "files" ? "file-earmark-arrow-up" : "folder2-open";
57
+ }
58
+ /**
59
+ * Check what a frame sent as a picker request: only the fields above, each of its type.
60
+ *
61
+ * @param value - From the frame.
62
+ * @returns The request, or why it was refused.
63
+ */
64
+ function toFolderPickerRequest(value) {
65
+ const r = value;
66
+ if (!r || typeof r !== "object")
67
+ return { error: "A folder picker needs a request" };
68
+ if (typeof r.groupId !== "string" || !r.groupId) {
69
+ return { error: "A folder picker needs a groupId" };
70
+ }
71
+ const mode = r.mode ?? "readwrite";
72
+ if (mode !== "read" && mode !== "readwrite") {
73
+ return { error: 'mode must be "read" or "readwrite"' };
74
+ }
75
+ const pick = r.pick ?? "folder";
76
+ if (pick !== "folder" && pick !== "files")
77
+ return { error: 'pick must be "folder" or "files"' };
78
+ const label = r.label ?? defaultFolderPickerLabel(pick);
79
+ if (typeof label !== "string" || !label.trim() || label.length > exports.FOLDER_PICKER_LABEL_MAX) {
80
+ return { error: `label must be text of 1 to ${exports.FOLDER_PICKER_LABEL_MAX} characters` };
81
+ }
82
+ const icon = r.icon === undefined ? defaultFolderPickerIcon(pick) : r.icon;
83
+ if (icon !== null && (typeof icon !== "string" || !/^[a-z0-9-]{1,64}$/.test(icon))) {
84
+ return { error: "icon must be a Bootstrap icon name" };
85
+ }
86
+ const variant = r.variant ?? "primary";
87
+ if (!VARIANTS.includes(variant)) {
88
+ return { error: `variant must be one of ${VARIANTS.join(", ")}` };
89
+ }
90
+ if (r.size !== undefined && r.size !== "sm" && r.size !== "lg") {
91
+ return { error: 'size must be "sm" or "lg"' };
92
+ }
93
+ return {
94
+ groupId: r.groupId,
95
+ mode,
96
+ pick,
97
+ label,
98
+ ...(icon ? { icon } : {}),
99
+ variant: variant,
100
+ ...(r.size ? { size: r.size } : {}),
101
+ offerExisting: r.offerExisting === true && pick === "folder",
102
+ disabled: r.disabled === true,
103
+ };
104
+ }
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.frameBridge = frameBridge;
4
4
  exports.installFrameBridge = installFrameBridge;
5
5
  const peers_sdk_1 = require("@peers-app/peers-sdk");
6
+ const frame_microphone_1 = require("./frame-microphone");
6
7
  const frame_protocol_1 = require("./frame-protocol");
7
8
  const frame_realm_1 = require("./frame-realm");
8
9
  const frame_storage_1 = require("./frame-storage");
@@ -107,6 +108,13 @@ function installFrameBridge(port, win = window) {
107
108
  console.warn(`[frame] couldn't replace ${name}`, error);
108
109
  }
109
110
  }
111
+ // The microphone comes from the host, since the frame's origin can't open it.
112
+ try {
113
+ (0, frame_microphone_1.installFrameMicrophone)(host);
114
+ }
115
+ catch (error) {
116
+ console.warn("[frame] couldn't install the microphone", error);
117
+ }
110
118
  (0, peers_sdk_1.notifyClientConnected)();
111
119
  installed = { host, storage };
112
120
  return installed;
@@ -30,7 +30,8 @@ exports.FRAME_PORT_GLOBAL = "__peersFramePort";
30
30
  /** The frame's content security policy. */
31
31
  exports.FRAME_CSP = [
32
32
  "default-src 'none'",
33
- "script-src 'unsafe-inline' 'unsafe-eval' blob:",
33
+ // `data:` for worklet modules: WebKit refuses a `blob:` one in an opaque-origin frame.
34
+ "script-src 'unsafe-inline' 'unsafe-eval' blob: data:",
34
35
  "style-src 'unsafe-inline'",
35
36
  "img-src data: blob: https: http:",
36
37
  "media-src data: blob: https: http:",
@@ -0,0 +1,55 @@
1
+ import { type IFrameMicrophoneRequest } from "./frame-protocol";
2
+ import type { IPortChannel } from "./port-channel";
3
+ /**
4
+ * A screen's `navigator.mediaDevices.getUserMedia` in its frame. The frame's opaque origin can't
5
+ * open the microphone, so the host does (`microphone-host.ts`) and sends its sound here, 128
6
+ * samples at a time, from its audio thread to this frame's over a `MessagePort`. A small
7
+ * AudioWorklet plays them into a `MediaStreamAudioDestinationNode`, and the screen gets that
8
+ * node's stream: it works with an `AudioContext`, a `MediaRecorder` or a WebRTC connection as a
9
+ * microphone's stream does. Only audio: the camera is refused.
10
+ */
11
+ /**
12
+ * The frame's AudioWorklet module: plays the host's blocks. It waits for two before it starts,
13
+ * and again after it runs dry; past 60 ms queued it drops the oldest down to 30 ms, so a stall
14
+ * doesn't leave the sound late. A whole block is copied out without a view, so playing one
15
+ * allocates nothing. Exported for its tests.
16
+ */
17
+ export declare const SOURCE_MODULE = "\nclass PeersMicrophoneSource extends AudioWorkletProcessor {\n constructor() {\n super();\n this.queue = [];\n this.offset = 0;\n this.primed = false;\n this.most = Math.ceil((0.06 * sampleRate) / 128);\n this.keep = Math.ceil(this.most / 2);\n this.port.onmessage = (event) => {\n const port = event.data && event.data.port;\n if (!port) return;\n port.onmessage = (message) => {\n this.queue.push(message.data);\n if (this.queue.length > this.most) {\n this.queue.splice(0, this.queue.length - this.keep);\n this.offset = 0;\n }\n };\n };\n }\n process(_inputs, outputs) {\n const out = outputs[0][0];\n if (!this.primed) {\n if (this.queue.length < 2) return true;\n this.primed = true;\n }\n let written = 0;\n while (written < out.length && this.queue.length) {\n const block = this.queue[0];\n const count = Math.min(out.length - written, block.length - this.offset);\n if (this.offset === 0 && count === block.length) out.set(block, written);\n else out.set(block.subarray(this.offset, this.offset + count), written);\n written += count;\n this.offset += count;\n if (this.offset >= block.length) {\n this.queue.shift();\n this.offset = 0;\n }\n }\n if (written < out.length) this.primed = false;\n return true;\n }\n}\nregisterProcessor(\"peers-microphone-source\", PeersMicrophoneSource);\n";
18
+ /**
19
+ * Give the frame's `getUserMedia` the host's microphone. The frame runtime calls it once, with
20
+ * its channel to the host.
21
+ *
22
+ * @param channel - The frame's channel to the host.
23
+ */
24
+ export declare function installFrameMicrophone(channel: IPortChannel): void;
25
+ /**
26
+ * What a screen's audio constraints ask the host for.
27
+ *
28
+ * @param audio - `true`, or the audio track's constraints.
29
+ */
30
+ export declare function frameMicrophoneRequest(audio: boolean | MediaTrackConstraints): IFrameMicrophoneRequest;
31
+ /**
32
+ * The host's refusal as the `DOMException` a browser's `getUserMedia` throws: its message starts
33
+ * with the exception's name (`NotAllowedError: …`).
34
+ *
35
+ * @param error - What the host's request rejected with.
36
+ */
37
+ export declare function microphoneError(error: unknown): DOMException;
38
+ /**
39
+ * Open a stream of the host's microphone, as `getUserMedia({ audio })` does.
40
+ *
41
+ * @param channel - The frame's channel to the host.
42
+ * @param constraints - What the screen passed `getUserMedia`.
43
+ */
44
+ export declare function openFrameMicrophoneStream(channel: IPortChannel, constraints?: MediaStreamConstraints): Promise<MediaStream>;
45
+ /**
46
+ * Call `release` once every track of `stream`, and every copy made of one (`clone`, the stream's
47
+ * `clone`), has stopped. Stopping a track of a destination node's stream doesn't tell anyone, so
48
+ * `stop` is wrapped. Each track, copies too, reports the host microphone's `settings` from
49
+ * `getSettings` as its own.
50
+ *
51
+ * @param stream - The stream the screen gets.
52
+ * @param release - Called once, when the last track stops.
53
+ * @param settings - The host microphone track's settings.
54
+ */
55
+ export declare function releaseWhenStopped(stream: MediaStream, release: () => void, settings?: MediaTrackSettings): void;