@peers-app/peers-ui 0.34.13 → 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 (126) 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/delegates/acts-for-you-panel.d.ts +2 -1
  37. package/dist/delegates/acts-for-you-panel.js +46 -17
  38. package/dist/delegates/delegate-request-dialog.d.ts +3 -1
  39. package/dist/delegates/delegate-request-dialog.js +6 -3
  40. package/dist/groups/groups-client.d.ts +23 -1
  41. package/dist/groups/groups-client.js +31 -0
  42. package/dist/index.d.ts +10 -0
  43. package/dist/index.js +14 -1
  44. package/dist/isolated-screens/config.js +1 -9
  45. package/dist/isolated-screens/folder-picker-control.d.ts +57 -0
  46. package/dist/isolated-screens/folder-picker-control.js +217 -0
  47. package/dist/isolated-screens/folder-picker-host.d.ts +57 -0
  48. package/dist/isolated-screens/folder-picker-host.js +178 -0
  49. package/dist/isolated-screens/folder-picker-protocol.d.ts +75 -0
  50. package/dist/isolated-screens/folder-picker-protocol.js +104 -0
  51. package/dist/isolated-screens/frame-bridge.js +8 -0
  52. package/dist/isolated-screens/frame-document.js +2 -1
  53. package/dist/isolated-screens/frame-microphone.d.ts +55 -0
  54. package/dist/isolated-screens/frame-microphone.js +265 -0
  55. package/dist/isolated-screens/frame-permissions.d.ts +19 -0
  56. package/dist/isolated-screens/frame-permissions.js +32 -0
  57. package/dist/isolated-screens/frame-protocol.d.ts +26 -0
  58. package/dist/isolated-screens/frame-protocol.js +9 -0
  59. package/dist/isolated-screens/frame-pvars.d.ts +27 -0
  60. package/dist/isolated-screens/frame-pvars.js +101 -14
  61. package/dist/isolated-screens/global-widgets.d.ts +1 -2
  62. package/dist/isolated-screens/index.d.ts +2 -0
  63. package/dist/isolated-screens/index.js +3 -1
  64. package/dist/isolated-screens/isolated-screen.d.ts +21 -0
  65. package/dist/isolated-screens/isolated-screen.js +88 -5
  66. package/dist/isolated-screens/local-folder-picker.d.ts +55 -0
  67. package/dist/isolated-screens/local-folder-picker.js +143 -0
  68. package/dist/isolated-screens/microphone-host.d.ts +110 -0
  69. package/dist/isolated-screens/microphone-host.js +397 -0
  70. package/dist/isolated-screens/microphone-prompt.d.ts +20 -0
  71. package/dist/isolated-screens/microphone-prompt.js +60 -0
  72. package/dist/isolated-screens/piece-frames.js +5 -94
  73. package/dist/isolated-screens/piece-reach.d.ts +1 -0
  74. package/dist/isolated-screens/port-channel.d.ts +21 -11
  75. package/dist/isolated-screens/port-channel.js +15 -5
  76. package/dist/isolated-screens/slot-rect.d.ts +38 -0
  77. package/dist/isolated-screens/slot-rect.js +121 -0
  78. package/dist/isolated-screens/test-ports.d.ts +17 -0
  79. package/dist/isolated-screens/test-ports.js +25 -3
  80. package/dist/mentions/mention-chooser.js +1 -1
  81. package/dist/notifications/notifications-screen.js +1 -1
  82. package/dist/screens/data-explorer/data-explorer.d.ts +1 -0
  83. package/dist/screens/data-explorer/data-explorer.js +28 -10
  84. package/dist/screens/data-explorer/query-executor.d.ts +1 -0
  85. package/dist/screens/data-explorer/query-executor.js +3 -1
  86. package/dist/screens/groups/group-list.d.ts +13 -3
  87. package/dist/screens/groups/group-list.js +88 -11
  88. package/dist/screens/identity/identity-routes.d.ts +16 -0
  89. package/dist/screens/identity/identity-routes.js +27 -10
  90. package/dist/screens/identity/identity-screen.js +4 -1
  91. package/dist/screens/invites/activity-view.d.ts +3 -1
  92. package/dist/screens/invites/activity-view.js +7 -3
  93. package/dist/screens/invites/pending-invites-list.d.ts +8 -4
  94. package/dist/screens/invites/pending-invites-list.js +44 -45
  95. package/dist/screens/network-viewer/graph/network-graph-controls.js +3 -3
  96. package/dist/screens/packages/local-folder-grants-panel.d.ts +2 -0
  97. package/dist/screens/packages/local-folder-grants-panel.js +1 -1
  98. package/dist/screens/packages/package-info.js +2 -1
  99. package/dist/screens/packages/package-list.d.ts +2 -2
  100. package/dist/screens/packages/package-list.js +89 -105
  101. package/dist/screens/packages/package-microphone-panel.d.ts +14 -0
  102. package/dist/screens/packages/package-microphone-panel.js +62 -0
  103. package/dist/screens/packages/package-runtime-status.d.ts +10 -2
  104. package/dist/screens/packages/package-runtime-status.js +17 -4
  105. package/dist/screens/peer-types/peer-type-details.js +3 -2
  106. package/dist/screens/peer-types/peer-type-list.d.ts +1 -1
  107. package/dist/screens/peer-types/peer-type-list.js +4 -4
  108. package/dist/screens/settings/settings-page.js +1 -4
  109. package/dist/screens/tools/tool-details.js +2 -1
  110. package/dist/screens/tools/tool-list.d.ts +1 -1
  111. package/dist/screens/tools/tool-list.js +22 -60
  112. package/dist/screens/variables/variable-details.js +5 -4
  113. package/dist/screens/variables/variable-list.d.ts +17 -0
  114. package/dist/screens/variables/variable-list.js +72 -28
  115. package/dist/tabs-layout/network-status-details.d.ts +4 -4
  116. package/dist/tabs-layout/network-status-details.js +6 -5
  117. package/dist/tabs-layout/network-status-indicator.d.ts +1 -0
  118. package/dist/tabs-layout/network-status-indicator.js +1 -0
  119. package/dist/tabs-layout/tab-bar-shortcuts.d.ts +46 -0
  120. package/dist/tabs-layout/tab-bar-shortcuts.js +140 -0
  121. package/dist/tabs-layout/tabs-layout.js +11 -9
  122. package/dist/theme.css +326 -6
  123. package/dist/ui-contracts/popover-surface.d.ts +3 -0
  124. package/dist/ui-contracts/popover-surface.js +6 -3
  125. package/dist/ui-defaults/list-screen.js +10 -4
  126. package/package.json +3 -3
@@ -0,0 +1,217 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FolderPickerControl = void 0;
4
+ exports.FolderPickerFace = FolderPickerFace;
5
+ exports.folderPickerPressAt = folderPickerPressAt;
6
+ exports.existingFolders = existingFolders;
7
+ const jsx_runtime_1 = require("react/jsx-runtime");
8
+ const peers_sdk_1 = require("@peers-app/peers-sdk");
9
+ const react_1 = require("react");
10
+ const group_names_1 = require("../notifications/group-names");
11
+ const local_folders_ipc_1 = require("../screens/packages/local-folders-ipc");
12
+ const popover_surface_1 = require("../ui-contracts/popover-surface");
13
+ /**
14
+ * The buttons of Peers' folder picker, drawn by Peers: over a framed screen's slot by its host
15
+ * (`folder-picker-host.tsx`), or in the window for a screen that runs there
16
+ * (`local-folder-picker.tsx`). A click opens the OS picker and grants what's picked to the
17
+ * package; the ▾ lists folders the package already has on this device.
18
+ */
19
+ /** Why a grant failed, in words for the person. A host without System Local Folders says so. */
20
+ function errorText(error) {
21
+ const message = error instanceof Error ? error.message : String(error);
22
+ // A transport may wrap the provider's message.
23
+ return /No contract provider registered for \S+|Permission denied: contract \S+ is not available locally/i.test(message)
24
+ ? "Folders on this device need the Peers desktop app"
25
+ : message;
26
+ }
27
+ /** The picker can be cancelled. A file validation error includes the name the person picked. */
28
+ function grantError(error) {
29
+ const message = error instanceof Error ? error.message : String(error);
30
+ // checkGrantFiles includes the filename verbatim in these diagnostics. It can contain the
31
+ // entire cancellation or missing-provider message, including any apparent wrapper.
32
+ if (/Not a file name: |files names [\s\S]* twice| is not (?:an available|a regular) file| cannot be opened under its normalized name/.test(message))
33
+ return message;
34
+ if (/\b(?:file|folder) selection was cancelled\b/i.test(message))
35
+ return undefined;
36
+ return errorText(message);
37
+ }
38
+ function buttonClass(request) {
39
+ return `btn btn-${request.variant}${request.size ? ` btn-${request.size}` : ""}`;
40
+ }
41
+ /**
42
+ * The picker's look, with nothing to click: a framed screen's slot draws it hidden, so the slot is
43
+ * as big as the buttons the host draws over it.
44
+ */
45
+ function FolderPickerFace(props) {
46
+ const { request } = props;
47
+ return ((0, jsx_runtime_1.jsxs)("span", { className: "btn-group", "aria-hidden": "true", style: { visibility: "hidden" }, children: [(0, jsx_runtime_1.jsxs)("span", { className: buttonClass(request), children: [request.icon ? (0, jsx_runtime_1.jsx)("i", { className: `bi bi-${request.icon} me-1` }) : null, request.label] }), request.offerExisting ? ((0, jsx_runtime_1.jsx)("span", { className: `${buttonClass(request)} dropdown-toggle dropdown-toggle-split` })) : null] }));
48
+ }
49
+ /**
50
+ * The attributes that mark what Peers draws for a picker over a frame's slot (its buttons, and its
51
+ * ▾ menu, which sits elsewhere in the window), so a press there counts as inside that slot.
52
+ */
53
+ function placeMarks(place) {
54
+ return place
55
+ ? {
56
+ "data-peers-folder-picker-frame": place.frameId,
57
+ "data-peers-folder-picker-slot": place.slotId,
58
+ }
59
+ : {};
60
+ }
61
+ /**
62
+ * The picker a press in the host's window landed on, if any: on its buttons or in its ▾ menu.
63
+ *
64
+ * @param target - The press's target.
65
+ */
66
+ function folderPickerPressAt(target) {
67
+ const marked = target?.closest("[data-peers-folder-picker-frame]");
68
+ const frameId = marked?.dataset.peersFolderPickerFrame;
69
+ const slotId = marked?.dataset.peersFolderPickerSlot;
70
+ return frameId && slotId ? { frameId, slotId } : undefined;
71
+ }
72
+ /**
73
+ * The folders a package has on this device that a request may use: whole folders, at least as
74
+ * writable as asked for.
75
+ */
76
+ function existingFolders(grants, packageId, request) {
77
+ const byPath = new Map();
78
+ for (const grant of grants) {
79
+ if (grant.packageId !== packageId || grant.files !== undefined)
80
+ continue;
81
+ if (request.mode === "readwrite" && grant.mode !== "readwrite")
82
+ continue;
83
+ const known = byPath.get(grant.absolutePath);
84
+ if (known) {
85
+ if (!known.groupIds.includes(grant.groupId))
86
+ known.groupIds.push(grant.groupId);
87
+ }
88
+ else
89
+ byPath.set(grant.absolutePath, {
90
+ absolutePath: grant.absolutePath,
91
+ groupIds: [grant.groupId],
92
+ });
93
+ }
94
+ return [...byPath.values()].sort((a, b) => a.absolutePath.localeCompare(b.absolutePath));
95
+ }
96
+ function folderName(absolutePath) {
97
+ const parts = absolutePath.split(absolutePath.startsWith("/") ? "/" : /[\\/]/).filter(Boolean);
98
+ return parts[parts.length - 1] ?? absolutePath;
99
+ }
100
+ /** The ▾ menu: the package's folders on this device, then the picker. */
101
+ function ExistingFoldersMenu(props) {
102
+ const names = (0, group_names_1.useGroupNames)();
103
+ const { grants, packageId, mode, anchor } = props;
104
+ const close = (0, react_1.useRef)(props.onClose);
105
+ close.current = props.onClose;
106
+ // The menu sits outside the screen, so it stays up when the screen's tab is switched away or the
107
+ // ▾ scrolls out of sight: close it then, so it can't act for a screen the person can't see.
108
+ (0, react_1.useEffect)(() => {
109
+ if (!anchor || typeof IntersectionObserver === "undefined")
110
+ return;
111
+ // Touching the clip edge can still count as intersecting with zero area. A positive
112
+ // threshold makes crossing from a visible sliver to zero observable too.
113
+ const watch = new IntersectionObserver((entries) => {
114
+ if (entries.some((entry) => !entry.isIntersecting || entry.intersectionRatio === 0)) {
115
+ close.current();
116
+ }
117
+ }, { threshold: Number.EPSILON });
118
+ watch.observe(anchor);
119
+ return () => watch.disconnect();
120
+ }, [anchor]);
121
+ // A mode change can make a listed folder ineligible. Moving the slot keeps the same choices.
122
+ const folders = (0, react_1.useMemo)(() => (Array.isArray(grants) ? existingFolders(grants, packageId, { mode }) : grants), [grants, packageId, mode]);
123
+ return ((0, jsx_runtime_1.jsx)(popover_surface_1.PopoverSurface, { anchor: props.anchor, onClose: props.onClose, label: "Folders", children: (0, jsx_runtime_1.jsx)("div", { ...placeMarks(props.place), style: { maxHeight: "inherit" }, children: (0, jsx_runtime_1.jsxs)("div", { className: "dropdown-menu show position-static shadow", style: { maxWidth: 420, maxHeight: "inherit", overflowY: "auto" }, children: [folders === undefined ? ((0, jsx_runtime_1.jsx)("div", { className: "dropdown-item-text text-body-secondary small", children: "Loading\u2026" })) : typeof folders === "string" ? ((0, jsx_runtime_1.jsx)("div", { className: "dropdown-item-text text-danger small", children: folders })) : folders.length === 0 ? ((0, jsx_runtime_1.jsx)("div", { className: "dropdown-item-text text-body-secondary small", children: "No folders to choose from yet" })) : (folders.map((folder) => ((0, jsx_runtime_1.jsxs)("button", { type: "button", className: "dropdown-item", title: folder.absolutePath, onClick: () => props.onChoose(folder.absolutePath), children: [(0, jsx_runtime_1.jsx)("i", { className: "bi bi-folder me-2" }), folderName(folder.absolutePath), (0, jsx_runtime_1.jsx)("span", { className: "text-body-secondary small ms-2", children: folder.groupIds.map((id) => names.get(id) ?? "another group").join(", ") })] }, folder.absolutePath)))), (0, jsx_runtime_1.jsx)("div", { className: "dropdown-divider" }), (0, jsx_runtime_1.jsxs)("button", { type: "button", className: "dropdown-item", onClick: () => props.onChoose(undefined), children: [(0, jsx_runtime_1.jsx)("i", { className: "bi bi-folder2-open me-2" }), "Another folder\u2026"] })] }) }) }));
124
+ }
125
+ /**
126
+ * Peers' folder picker buttons. A click opens the OS picker (or uses a folder from the ▾ menu) and
127
+ * grants it with System Local Folders, as the person, for `packageId`.
128
+ */
129
+ exports.FolderPickerControl = (0, react_1.forwardRef)(function FolderPickerControl(props, ref) {
130
+ const { request, packageId, overSlot } = props;
131
+ const main = (0, react_1.useRef)(null);
132
+ const caret = (0, react_1.useRef)(null);
133
+ const [busy, setBusy] = (0, react_1.useState)(false);
134
+ // The ▾ menu: closed, loading, why it couldn't load, or the package's grants on this device.
135
+ const [menu, setMenu] = (0, react_1.useState)(false);
136
+ const latest = (0, react_1.useRef)(props);
137
+ latest.current = props;
138
+ (0, react_1.useImperativeHandle)(ref, () => ({
139
+ focus: (edge) => (edge === "last" && caret.current ? caret.current : main.current)?.focus(),
140
+ }));
141
+ async function grant(absolutePath) {
142
+ if (request.disabled || busy)
143
+ return;
144
+ setBusy(true);
145
+ const input = {
146
+ groupId: request.groupId,
147
+ mode: request.mode,
148
+ ...(packageId ? { packageId } : {}),
149
+ ...(absolutePath ? { absolutePath } : request.pick === "files" ? { pick: "files" } : {}),
150
+ };
151
+ let granted;
152
+ try {
153
+ granted = await local_folders_ipc_1.localFoldersConsumer.get().then(({ tools }) => {
154
+ // Membership can change after the frame mounts its slot.
155
+ if (overSlot &&
156
+ request.groupId !== (0, peers_sdk_1.peekUserContext)()?.userId &&
157
+ !(0, peers_sdk_1.peekUserContext)()?.groupDataContexts.has(request.groupId)) {
158
+ throw new Error("That group isn't available to this screen");
159
+ }
160
+ return tools.requestGrant(input);
161
+ });
162
+ }
163
+ catch (error) {
164
+ const message = grantError(error);
165
+ if (message !== undefined)
166
+ latest.current.onFailed(message);
167
+ return;
168
+ }
169
+ finally {
170
+ setBusy(false);
171
+ }
172
+ try {
173
+ latest.current.onPicked(granted);
174
+ }
175
+ catch (error) {
176
+ // A shared-window callback can throw here. The grant has already succeeded.
177
+ console.error("Folder picker onPicked failed", error);
178
+ }
179
+ }
180
+ async function openMenu() {
181
+ setMenu(undefined);
182
+ try {
183
+ const { grants } = await (await local_folders_ipc_1.localFoldersConsumer.get()).tools.listGrants();
184
+ setMenu((open) => (open === false ? open : grants));
185
+ }
186
+ catch (error) {
187
+ setMenu((open) => (open === false ? open : errorText(error)));
188
+ latest.current.onFailed(errorText(error));
189
+ }
190
+ }
191
+ // Over a slot the buttons take no Tab stops in the window: Tab moves between them here, and
192
+ // out of them back to the screen around the slot.
193
+ const onTab = (event, on) => {
194
+ if (!overSlot || event.key !== "Tab")
195
+ return;
196
+ event.preventDefault();
197
+ if (on === "main" && !event.shiftKey && caret.current)
198
+ caret.current.focus();
199
+ else if (on === "caret" && event.shiftKey)
200
+ main.current?.focus();
201
+ else
202
+ overSlot.onTabOut(event.shiftKey ? "previous" : "next");
203
+ };
204
+ const disabled = request.disabled || busy;
205
+ // A ▾ menu that can't show is closed, not hidden: only the person's click on ▾ opens it again,
206
+ // so a screen that disables the picker and enables it again can't put a named folder, focused,
207
+ // under the person's next key press or click.
208
+ if (menu !== false && (disabled || !request.offerExisting))
209
+ setMenu(false);
210
+ const fill = overSlot
211
+ ? { width: "100%", height: "100%" }
212
+ : undefined;
213
+ return ((0, jsx_runtime_1.jsxs)("span", { className: "btn-group", style: fill, children: [(0, jsx_runtime_1.jsxs)("button", { ref: main, type: "button", className: buttonClass(request), disabled: disabled, "aria-busy": busy || undefined, tabIndex: overSlot ? -1 : undefined, onKeyDown: (event) => onTab(event, "main"), onClick: () => void grant(undefined), children: [request.icon ? (0, jsx_runtime_1.jsx)("i", { className: `bi bi-${request.icon} me-1` }) : null, request.label] }), request.offerExisting ? ((0, jsx_runtime_1.jsx)("button", { ref: caret, type: "button", className: `${buttonClass(request)} dropdown-toggle dropdown-toggle-split`, disabled: disabled, "aria-label": "Folders this app already uses", "aria-expanded": !disabled && menu !== false, tabIndex: overSlot ? -1 : undefined, onKeyDown: (event) => onTab(event, "caret"), onClick: () => (menu === false ? void openMenu() : setMenu(false)) })) : null, menu !== false && request.offerExisting && !disabled ? ((0, jsx_runtime_1.jsx)(ExistingFoldersMenu, { anchor: caret.current, grants: menu, packageId: packageId, mode: request.mode, place: overSlot?.place, onClose: () => setMenu(false), onChoose: (absolutePath) => {
214
+ setMenu(false);
215
+ void grant(absolutePath);
216
+ } })) : null] }));
217
+ });
@@ -0,0 +1,57 @@
1
+ import { type Observable } from "@peers-app/peers-sdk";
2
+ import type React from "react";
3
+ import { type IFolderPickerControlHandle } from "./folder-picker-control";
4
+ import { type IFolderPickerRequest } from "./folder-picker-protocol";
5
+ import type { IPortChannel } from "./port-channel";
6
+ import type { ISlotClip, ISlotRect } from "./slot-rect";
7
+ /**
8
+ * The host's side of Peers' folder picker in a framed screen (`folder-picker-protocol.ts`): it
9
+ * keeps the screen's picker slots, and draws its own buttons over them. The grant is made for the
10
+ * frame's package, which the host knows; nothing the screen sends names it.
11
+ */
12
+ /** One picker a framed screen placed: what it asks for, and where its slot is. */
13
+ export interface IFolderPickerSlot {
14
+ slotId: string;
15
+ request: IFolderPickerRequest;
16
+ /** Where the slot is, in the frame's coordinates, and the part of it that shows. */
17
+ rect?: ISlotRect;
18
+ clip?: ISlotClip;
19
+ }
20
+ /** The host's folder pickers for one frame: what its session keeps. */
21
+ export interface IFolderPickerHost {
22
+ /** A picker drawn over a slot registers its buttons, so focus from the screen reaches them. */
23
+ register(slotId: string, control: IFolderPickerControlHandle | null): void;
24
+ /** Stop listening to the frame. */
25
+ dispose(): void;
26
+ }
27
+ /**
28
+ * Listen to a frame's folder picker messages.
29
+ *
30
+ * @param channel - The frame's channel.
31
+ * @param opts.slots - The frame's pickers, which its component draws.
32
+ * @param opts.hasFocus - Whether the frame still has the focus: focus the user moved elsewhere
33
+ * before a notice arrived stays there.
34
+ */
35
+ export declare function installFolderPickerHost(channel: IPortChannel, opts: {
36
+ slots: Observable<IFolderPickerSlot[]>;
37
+ hasFocus: () => boolean;
38
+ }): IFolderPickerHost;
39
+ /** What a picker over a slot needs from its frame's session. */
40
+ export interface IFolderPickerSession {
41
+ readonly folderPickers: IFolderPickerHost;
42
+ /** Send the frame a notice. */
43
+ slotNotify(type: string, payload: Record<string, unknown>): void;
44
+ /** Hand focus back to the screen, beside the slot. */
45
+ focusBack(slotId: string, direction: "next" | "previous"): void;
46
+ }
47
+ /**
48
+ * Peers' folder picker buttons over a framed screen's slot, placed and clipped where the slot
49
+ * shows. What's picked is granted to `packageId`, the frame's package.
50
+ */
51
+ export declare function FolderPickerOverSlot(props: {
52
+ slot: IFolderPickerSlot;
53
+ /** The host's id for the frame that placed the picker. */
54
+ frameId: string;
55
+ packageId: string;
56
+ session: React.MutableRefObject<IFolderPickerSession | undefined>;
57
+ }): import("react/jsx-runtime").JSX.Element | null;
@@ -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:",