@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.
- package/dist/apps-home/app-menu.d.ts +1 -2
- package/dist/apps-home/app-menu.js +29 -25
- package/dist/command-palette/command-palette-ui.js +13 -12
- package/dist/components/autocomplete-chips.d.ts +18 -0
- package/dist/components/autocomplete-chips.js +49 -0
- package/dist/components/autocomplete.d.ts +88 -0
- package/dist/components/autocomplete.js +346 -0
- package/dist/components/confirm-button.d.ts +26 -0
- package/dist/components/confirm-button.js +55 -0
- package/dist/components/data-grid/autocomplete.d.ts +1 -31
- package/dist/components/data-grid/autocomplete.js +5 -197
- package/dist/components/empty-state.d.ts +16 -0
- package/dist/components/empty-state.js +16 -0
- package/dist/components/group-switcher.d.ts +3 -3
- package/dist/components/group-switcher.js +22 -17
- package/dist/components/inline-create-form.d.ts +22 -0
- package/dist/components/inline-create-form.js +56 -0
- package/dist/components/list-row.d.ts +33 -0
- package/dist/components/list-row.js +30 -0
- package/dist/components/list-screen.d.ts +31 -3
- package/dist/components/list-screen.js +61 -28
- package/dist/components/markdown-editor/format-bar.js +15 -40
- package/dist/components/markdown-editor/link-plugin.js +38 -9
- package/dist/components/markdown-editor/selection-bar-place.d.ts +37 -0
- package/dist/components/markdown-editor/selection-bar-place.js +107 -0
- package/dist/components/menu-button.d.ts +34 -0
- package/dist/components/menu-button.js +66 -0
- package/dist/components/screen-header.d.ts +35 -0
- package/dist/components/screen-header.js +30 -0
- package/dist/components/search-field.d.ts +22 -0
- package/dist/components/search-field.js +22 -0
- package/dist/components/segmented-control.d.ts +25 -0
- package/dist/components/segmented-control.js +18 -0
- package/dist/components/typeahead.d.ts +9 -0
- package/dist/components/typeahead.js +7 -0
- package/dist/groups/groups-client.d.ts +23 -1
- package/dist/groups/groups-client.js +31 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +14 -1
- package/dist/isolated-screens/config.js +1 -9
- package/dist/isolated-screens/folder-picker-control.d.ts +57 -0
- package/dist/isolated-screens/folder-picker-control.js +217 -0
- package/dist/isolated-screens/folder-picker-host.d.ts +57 -0
- package/dist/isolated-screens/folder-picker-host.js +178 -0
- package/dist/isolated-screens/folder-picker-protocol.d.ts +75 -0
- package/dist/isolated-screens/folder-picker-protocol.js +104 -0
- package/dist/isolated-screens/frame-bridge.js +8 -0
- package/dist/isolated-screens/frame-document.js +2 -1
- package/dist/isolated-screens/frame-microphone.d.ts +55 -0
- package/dist/isolated-screens/frame-microphone.js +265 -0
- package/dist/isolated-screens/frame-permissions.d.ts +19 -0
- package/dist/isolated-screens/frame-permissions.js +32 -0
- package/dist/isolated-screens/frame-protocol.d.ts +26 -0
- package/dist/isolated-screens/frame-protocol.js +9 -0
- package/dist/isolated-screens/frame-pvars.d.ts +27 -0
- package/dist/isolated-screens/frame-pvars.js +101 -14
- package/dist/isolated-screens/global-widgets.d.ts +1 -2
- package/dist/isolated-screens/index.d.ts +2 -0
- package/dist/isolated-screens/index.js +3 -1
- package/dist/isolated-screens/isolated-screen.d.ts +21 -0
- package/dist/isolated-screens/isolated-screen.js +88 -5
- package/dist/isolated-screens/local-folder-picker.d.ts +55 -0
- package/dist/isolated-screens/local-folder-picker.js +143 -0
- package/dist/isolated-screens/microphone-host.d.ts +110 -0
- package/dist/isolated-screens/microphone-host.js +397 -0
- package/dist/isolated-screens/microphone-prompt.d.ts +20 -0
- package/dist/isolated-screens/microphone-prompt.js +60 -0
- package/dist/isolated-screens/piece-frames.js +5 -94
- package/dist/isolated-screens/piece-reach.d.ts +1 -0
- package/dist/isolated-screens/port-channel.d.ts +21 -11
- package/dist/isolated-screens/port-channel.js +15 -5
- package/dist/isolated-screens/slot-rect.d.ts +38 -0
- package/dist/isolated-screens/slot-rect.js +121 -0
- package/dist/isolated-screens/test-ports.d.ts +17 -0
- package/dist/isolated-screens/test-ports.js +25 -3
- package/dist/mentions/mention-chooser.js +1 -1
- package/dist/notifications/notifications-screen.js +1 -1
- package/dist/screens/data-explorer/data-explorer.d.ts +1 -0
- package/dist/screens/data-explorer/data-explorer.js +28 -10
- package/dist/screens/data-explorer/query-executor.d.ts +1 -0
- package/dist/screens/data-explorer/query-executor.js +3 -1
- package/dist/screens/groups/group-list.d.ts +13 -3
- package/dist/screens/groups/group-list.js +88 -11
- package/dist/screens/identity/identity-routes.d.ts +16 -0
- package/dist/screens/identity/identity-routes.js +27 -10
- package/dist/screens/identity/identity-screen.js +4 -1
- package/dist/screens/invites/activity-view.d.ts +3 -1
- package/dist/screens/invites/activity-view.js +7 -3
- package/dist/screens/invites/pending-invites-list.d.ts +8 -4
- package/dist/screens/invites/pending-invites-list.js +44 -45
- package/dist/screens/network-viewer/graph/network-graph-controls.js +3 -3
- package/dist/screens/packages/local-folder-grants-panel.d.ts +2 -0
- package/dist/screens/packages/local-folder-grants-panel.js +1 -1
- package/dist/screens/packages/package-info.js +2 -1
- package/dist/screens/packages/package-list.d.ts +2 -2
- package/dist/screens/packages/package-list.js +89 -105
- package/dist/screens/packages/package-microphone-panel.d.ts +14 -0
- package/dist/screens/packages/package-microphone-panel.js +62 -0
- package/dist/screens/packages/package-runtime-status.d.ts +10 -2
- package/dist/screens/packages/package-runtime-status.js +17 -4
- package/dist/screens/peer-types/peer-type-details.js +3 -2
- package/dist/screens/peer-types/peer-type-list.d.ts +1 -1
- package/dist/screens/peer-types/peer-type-list.js +4 -4
- package/dist/screens/settings/settings-page.js +1 -4
- package/dist/screens/tools/tool-details.js +2 -1
- package/dist/screens/tools/tool-list.d.ts +1 -1
- package/dist/screens/tools/tool-list.js +22 -60
- package/dist/screens/variables/variable-details.js +5 -4
- package/dist/screens/variables/variable-list.d.ts +17 -0
- package/dist/screens/variables/variable-list.js +72 -28
- package/dist/tabs-layout/network-status-details.d.ts +4 -4
- package/dist/tabs-layout/network-status-details.js +6 -5
- package/dist/tabs-layout/network-status-indicator.d.ts +1 -0
- package/dist/tabs-layout/network-status-indicator.js +1 -0
- package/dist/tabs-layout/tab-bar-shortcuts.d.ts +46 -0
- package/dist/tabs-layout/tab-bar-shortcuts.js +140 -0
- package/dist/tabs-layout/tabs-layout.js +11 -9
- package/dist/theme.css +326 -6
- package/dist/ui-contracts/popover-surface.d.ts +3 -0
- package/dist/ui-contracts/popover-surface.js +6 -3
- package/dist/ui-defaults/list-screen.js +10 -4
- package/package.json +3 -3
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type IContractPiece, type IPackage, type Observable } from "@peers-app/peers-sdk";
|
|
2
2
|
import { type IPieceBundle } from "../ui-contracts/piece-host";
|
|
3
|
+
import { type IFolderPickerHost, type IFolderPickerSlot } from "./folder-picker-host";
|
|
3
4
|
import { type IWidgetPlacement } from "./frame-protocol";
|
|
4
5
|
/**
|
|
5
6
|
* The host side of an isolated package screen: the frame, and everything the host does for it.
|
|
@@ -135,6 +136,10 @@ declare class FrameSession {
|
|
|
135
136
|
private init?;
|
|
136
137
|
/** The commands this frame added to the host's palette, by their id there. */
|
|
137
138
|
private readonly commands;
|
|
139
|
+
/** Peers' folder pickers this frame placed, which its component draws over it. */
|
|
140
|
+
readonly folderPickers: IFolderPickerHost;
|
|
141
|
+
/** The package's reason for the microphone, read once from its stored manifest. */
|
|
142
|
+
private microphoneDeclared?;
|
|
138
143
|
constructor(opts: {
|
|
139
144
|
port: MessagePort;
|
|
140
145
|
frameId: string;
|
|
@@ -150,6 +155,8 @@ declare class FrameSession {
|
|
|
150
155
|
widgetPlacement: () => IWidgetPlacement | undefined;
|
|
151
156
|
/** The pieces this frame embeds, drawn over it by its component. */
|
|
152
157
|
slots: Observable<IPieceSlot[]>;
|
|
158
|
+
/** Peers' folder pickers this frame placed, drawn over it by its component. */
|
|
159
|
+
folderSlots: Observable<IFolderPickerSlot[]>;
|
|
153
160
|
/** For a piece drawn over a framed screen's slot: that screen, and the slot. */
|
|
154
161
|
slotOf?: SlotLink;
|
|
155
162
|
/** Make a new frame, as Retry on a screen that failed to load asks. */
|
|
@@ -161,6 +168,14 @@ declare class FrameSession {
|
|
|
161
168
|
* as a click in their slot; the rest as one outside.
|
|
162
169
|
*/
|
|
163
170
|
private pointerDown;
|
|
171
|
+
/** Whether this session's frame is the one the host made with `frameId`. */
|
|
172
|
+
isFrame(frameId: string): boolean;
|
|
173
|
+
/**
|
|
174
|
+
* Tell every frame about a press in this frame, or, with `ownSlot`, on what the host draws over
|
|
175
|
+
* that slot of this frame (Peers' folder picker): inside the slots it's drawn over, outside
|
|
176
|
+
* everywhere else.
|
|
177
|
+
*/
|
|
178
|
+
relayPointerDown(ownSlot?: string): void;
|
|
164
179
|
/**
|
|
165
180
|
* Tell this frame a pointer went down outside it: in the piece drawn over `slotId` when it's
|
|
166
181
|
* given, elsewhere when it isn't.
|
|
@@ -205,6 +220,12 @@ declare class FrameSession {
|
|
|
205
220
|
setPath(path: string): void;
|
|
206
221
|
/** Whether the frame has been told what to show. */
|
|
207
222
|
get started(): boolean;
|
|
223
|
+
/**
|
|
224
|
+
* Why the frame's package listens, from the manifest this device stored for its version
|
|
225
|
+
* (`pkg.microphone`); `undefined` when it doesn't declare the microphone, or the version has no
|
|
226
|
+
* stored manifest (a folder-loaded build).
|
|
227
|
+
*/
|
|
228
|
+
private microphoneReason;
|
|
208
229
|
dispose(): void;
|
|
209
230
|
}
|
|
210
231
|
/**
|
|
@@ -18,11 +18,14 @@ const piece_resolution_1 = require("../ui-contracts/piece-resolution");
|
|
|
18
18
|
const popover_surface_1 = require("../ui-contracts/popover-surface");
|
|
19
19
|
const ui_inspection_1 = require("../ui-inspection");
|
|
20
20
|
const config_1 = require("./config");
|
|
21
|
+
const folder_picker_control_1 = require("./folder-picker-control");
|
|
22
|
+
const folder_picker_host_1 = require("./folder-picker-host");
|
|
21
23
|
const frame_component_1 = require("./frame-component");
|
|
22
24
|
const frame_document_1 = require("./frame-document");
|
|
23
25
|
const frame_policy_1 = require("./frame-policy");
|
|
24
26
|
const frame_protocol_1 = require("./frame-protocol");
|
|
25
27
|
const frame_pvars_1 = require("./frame-pvars");
|
|
28
|
+
const microphone_host_1 = require("./microphone-host");
|
|
26
29
|
const piece_reach_1 = require("./piece-reach");
|
|
27
30
|
const port_channel_1 = require("./port-channel");
|
|
28
31
|
const screen_tab_context_1 = require("./screen-tab-context");
|
|
@@ -219,8 +222,22 @@ const liveSessions = new Set();
|
|
|
219
222
|
* (Safari before 16), since an unsupported value would show the cut-away part.
|
|
220
223
|
*/
|
|
221
224
|
const FRAME_OVERFLOW = typeof CSS !== "undefined" && CSS.supports?.("overflow", "clip") ? "clip" : "hidden";
|
|
222
|
-
/**
|
|
223
|
-
|
|
225
|
+
/**
|
|
226
|
+
* A click in the host's own window is outside every frame, except on Peers' folder picker drawn
|
|
227
|
+
* over a frame's slot, or in its ▾ menu: that's inside the slot, so a popover around it in the
|
|
228
|
+
* frame stays open.
|
|
229
|
+
*/
|
|
230
|
+
function relayHostPointers(event) {
|
|
231
|
+
const target = event.target instanceof Element ? event.target : null;
|
|
232
|
+
const picker = (0, folder_picker_control_1.folderPickerPressAt)(target);
|
|
233
|
+
if (picker) {
|
|
234
|
+
for (const session of liveSessions) {
|
|
235
|
+
if (session.isFrame(picker.frameId)) {
|
|
236
|
+
session.relayPointerDown(picker.slotId);
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
224
241
|
for (const session of liveSessions)
|
|
225
242
|
session.pointerOutside();
|
|
226
243
|
}
|
|
@@ -236,10 +253,19 @@ class FrameSession {
|
|
|
236
253
|
init;
|
|
237
254
|
/** The commands this frame added to the host's palette, by their id there. */
|
|
238
255
|
commands = new Set();
|
|
256
|
+
/** Peers' folder pickers this frame placed, which its component draws over it. */
|
|
257
|
+
folderPickers;
|
|
258
|
+
/** The package's reason for the microphone, read once from its stored manifest. */
|
|
259
|
+
microphoneDeclared;
|
|
239
260
|
constructor(opts) {
|
|
240
261
|
this.opts = opts;
|
|
241
262
|
const { pkg } = opts;
|
|
242
263
|
this.channel = (0, port_channel_1.openPortChannel)(opts.port);
|
|
264
|
+
this.folderPickers = (0, folder_picker_host_1.installFolderPickerHost)(this.channel, {
|
|
265
|
+
slots: opts.folderSlots,
|
|
266
|
+
hasFocus: () => document.activeElement === opts.element,
|
|
267
|
+
});
|
|
268
|
+
this.disposers.push(() => this.folderPickers.dispose());
|
|
243
269
|
this.rpc = (0, frame_policy_1.createFrameRpc)(pkg.packageId, (event) => this.channel.notify(frame_protocol_1.HostNotice.event, event));
|
|
244
270
|
this.pvars = (0, frame_pvars_1.createFramePvarService)({
|
|
245
271
|
packageId: pkg.packageId,
|
|
@@ -259,14 +285,28 @@ class FrameSession {
|
|
|
259
285
|
*/
|
|
260
286
|
pointerDown() {
|
|
261
287
|
this.opts.element.dispatchEvent(new Event(popover_surface_1.FRAME_POINTER_EVENT, { bubbles: true }));
|
|
288
|
+
this.relayPointerDown();
|
|
289
|
+
}
|
|
290
|
+
/** Whether this session's frame is the one the host made with `frameId`. */
|
|
291
|
+
isFrame(frameId) {
|
|
292
|
+
return this.opts.frameId === frameId;
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Tell every frame about a press in this frame, or, with `ownSlot`, on what the host draws over
|
|
296
|
+
* that slot of this frame (Peers' folder picker): inside the slots it's drawn over, outside
|
|
297
|
+
* everywhere else.
|
|
298
|
+
*/
|
|
299
|
+
relayPointerDown(ownSlot) {
|
|
262
300
|
const inside = new Map();
|
|
301
|
+
if (ownSlot)
|
|
302
|
+
inside.set(this, ownSlot);
|
|
263
303
|
let link = this.opts.slotOf?.();
|
|
264
304
|
for (let depth = 0; link?.session && depth < 16; depth++) {
|
|
265
305
|
inside.set(link.session, link.slotId);
|
|
266
306
|
link = link.session.opts.slotOf?.();
|
|
267
307
|
}
|
|
268
308
|
for (const session of liveSessions) {
|
|
269
|
-
if (session !== this)
|
|
309
|
+
if (session !== this || ownSlot)
|
|
270
310
|
session.pointerOutside(inside.get(session));
|
|
271
311
|
}
|
|
272
312
|
}
|
|
@@ -466,6 +506,27 @@ class FrameSession {
|
|
|
466
506
|
opts.pieceEvents()?.onWheel?.(deltaX, deltaY);
|
|
467
507
|
});
|
|
468
508
|
channel.onNotify(frame_protocol_1.FrameNotice.restart, () => opts.restart());
|
|
509
|
+
// The microphone, which the frame can't open: the host opens it and streams the sound in.
|
|
510
|
+
channel.onRequest(frame_protocol_1.FrameRequest.microphoneOpen, async (input, ports) => {
|
|
511
|
+
const [port, ...unused] = ports ?? [];
|
|
512
|
+
for (const extra of unused)
|
|
513
|
+
extra.close();
|
|
514
|
+
const reason = await this.microphoneReason();
|
|
515
|
+
if (!liveSessions.has(this)) {
|
|
516
|
+
port?.close();
|
|
517
|
+
throw new Error("AbortError: The screen closed");
|
|
518
|
+
}
|
|
519
|
+
return (0, microphone_host_1.openFrameMicrophone)({
|
|
520
|
+
frameId: opts.frameId,
|
|
521
|
+
packageId: pkg.packageId,
|
|
522
|
+
packageName: pkg.name,
|
|
523
|
+
reason,
|
|
524
|
+
streamId: String(input?.streamId),
|
|
525
|
+
request: input?.request,
|
|
526
|
+
port,
|
|
527
|
+
});
|
|
528
|
+
});
|
|
529
|
+
channel.onNotify(frame_protocol_1.FrameNotice.microphoneClose, (input) => (0, microphone_host_1.closeFrameMicrophone)(opts.frameId, String(input?.streamId)));
|
|
469
530
|
// A frame that embeds pieces: the host resolves them and draws each in a frame of its own,
|
|
470
531
|
// acting as its provider, over the slot the frame reports.
|
|
471
532
|
channel.onRequest(frame_protocol_1.FrameRequest.pieceResolve, async ({ handle, dataContextId }) => this.resolvePieceFor(handle, dataContextId));
|
|
@@ -723,7 +784,25 @@ class FrameSession {
|
|
|
723
784
|
get started() {
|
|
724
785
|
return this.init !== undefined;
|
|
725
786
|
}
|
|
787
|
+
/**
|
|
788
|
+
* Why the frame's package listens, from the manifest this device stored for its version
|
|
789
|
+
* (`pkg.microphone`); `undefined` when it doesn't declare the microphone, or the version has no
|
|
790
|
+
* stored manifest (a folder-loaded build).
|
|
791
|
+
*/
|
|
792
|
+
microphoneReason() {
|
|
793
|
+
this.microphoneDeclared ??= (0, piece_reach_1.readStoredManifest)(this.opts.bundle.dataContextId, this.opts.bundle.packageVersionId).then((manifest) => {
|
|
794
|
+
if (manifest?.packageId !== this.opts.pkg.packageId)
|
|
795
|
+
return undefined;
|
|
796
|
+
const reason = manifest.microphone?.reason;
|
|
797
|
+
return typeof reason === "string" && reason.trim() ? reason : undefined;
|
|
798
|
+
}, () => {
|
|
799
|
+
this.microphoneDeclared = undefined;
|
|
800
|
+
return undefined;
|
|
801
|
+
});
|
|
802
|
+
return this.microphoneDeclared;
|
|
803
|
+
}
|
|
726
804
|
dispose() {
|
|
805
|
+
(0, microphone_host_1.closeFrameMicrophones)(this.opts.frameId);
|
|
727
806
|
for (const hostId of [...this.commands])
|
|
728
807
|
this.unregisterCommand(hostId);
|
|
729
808
|
liveSessions.delete(this);
|
|
@@ -777,6 +856,8 @@ function PackageFrameElement(props) {
|
|
|
777
856
|
const [failure, setFailure] = (0, react_1.useState)();
|
|
778
857
|
const [slots] = (0, react_1.useState)(() => (0, peers_sdk_1.observable)([]));
|
|
779
858
|
const [shownSlots] = (0, hooks_1.useObservable)(slots);
|
|
859
|
+
const [folderSlots] = (0, react_1.useState)(() => (0, peers_sdk_1.observable)([]));
|
|
860
|
+
const [shownFolderSlots] = (0, hooks_1.useObservable)(folderSlots);
|
|
780
861
|
const latest = (0, react_1.useRef)(props);
|
|
781
862
|
latest.current = props;
|
|
782
863
|
const onReplaced = (0, react_1.useRef)(props.onReplaced);
|
|
@@ -834,6 +915,7 @@ function PackageFrameElement(props) {
|
|
|
834
915
|
widgetEvents: () => widgetRef.current?.events,
|
|
835
916
|
widgetPlacement: () => widgetRef.current?.placement,
|
|
836
917
|
slots,
|
|
918
|
+
folderSlots,
|
|
837
919
|
slotOf: () => latest.current.slotOf?.(),
|
|
838
920
|
restart: () => onReplaced.current(),
|
|
839
921
|
});
|
|
@@ -851,13 +933,14 @@ function PackageFrameElement(props) {
|
|
|
851
933
|
sessionRef.current?.dispose();
|
|
852
934
|
sessionRef.current = undefined;
|
|
853
935
|
slots([]);
|
|
936
|
+
folderSlots([]);
|
|
854
937
|
// A widget's box and its hold on the pointer were this frame's: the frame that replaces it
|
|
855
938
|
// (its document was replaced, or a new version came) starts unmeasured, as a first
|
|
856
939
|
// one does, and can't inherit a drag it never saw end.
|
|
857
940
|
widgetRef.current?.events.onCapture(false);
|
|
858
941
|
widgetRef.current?.events.onBox(undefined);
|
|
859
942
|
};
|
|
860
|
-
}, [frameId, slots]);
|
|
943
|
+
}, [frameId, slots, folderSlots]);
|
|
861
944
|
// Another UI of the package, new props or a new path: the same frame shows it.
|
|
862
945
|
(0, react_1.useEffect)(() => {
|
|
863
946
|
const session = sessionRef.current;
|
|
@@ -903,7 +986,7 @@ function PackageFrameElement(props) {
|
|
|
903
986
|
return ((0, jsx_runtime_1.jsxs)("div", { className: "peers-package-frame", style: { position: "relative", width: "100%", height: "100%", overflow: FRAME_OVERFLOW }, children: [(0, jsx_runtime_1.jsx)("iframe", { ref: frameRef, title: props.label,
|
|
904
987
|
// Over a slot, the slot takes Tab in the piece's place and hands focus in; a widget that
|
|
905
988
|
// draws nothing is no Tab stop.
|
|
906
|
-
tabIndex: props.slotOf || (props.widget && !props.widget.interactive) ? -1 : undefined, srcDoc: srcDoc, sandbox: "allow-scripts allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-downloads", allow: "clipboard-read; clipboard-write; fullscreen; autoplay", "data-peers-frame": frameId, "data-peers-package": pkg.packageId, className: frameClass, style: frameStyle }), shownSlots.map((slot) => ((0, jsx_runtime_1.jsx)(PieceSlotFrame, { slot: slot, session: sessionRef }, slot.slotId)))] }));
|
|
989
|
+
tabIndex: props.slotOf || (props.widget && !props.widget.interactive) ? -1 : undefined, srcDoc: srcDoc, sandbox: "allow-scripts allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-downloads", allow: "clipboard-read; clipboard-write; fullscreen; autoplay", "data-peers-frame": frameId, "data-peers-package": pkg.packageId, className: frameClass, style: frameStyle }), shownSlots.map((slot) => ((0, jsx_runtime_1.jsx)(PieceSlotFrame, { slot: slot, session: sessionRef }, slot.slotId))), shownFolderSlots.map((slot) => ((0, jsx_runtime_1.jsx)(folder_picker_host_1.FolderPickerOverSlot, { slot: slot, frameId: frameId, packageId: pkg.packageId, session: sessionRef }, slot.slotId)))] }));
|
|
907
990
|
}
|
|
908
991
|
/**
|
|
909
992
|
* A piece a framed screen embeds, drawn over the slot the screen reports: a frame of its own,
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { type ILocalFolderGrantInfo, type LocalFolderMode, type LocalFolderPick } from "@peers-app/peers-sdk";
|
|
2
|
+
import { type FolderPickerVariant } from "./folder-picker-protocol";
|
|
3
|
+
/** What {@link LocalFolderPicker} takes. */
|
|
4
|
+
export interface ILocalFolderPickerProps {
|
|
5
|
+
/** The group the folder is for: the package uses it there. */
|
|
6
|
+
groupId: string;
|
|
7
|
+
/** What the package may do with it: `"readwrite"` (the default) or `"read"`. */
|
|
8
|
+
mode?: LocalFolderMode;
|
|
9
|
+
/**
|
|
10
|
+
* `"folder"` (the default), or `"files"`: one or more files in one folder, granted read-only and
|
|
11
|
+
* covering only those files.
|
|
12
|
+
*/
|
|
13
|
+
pick?: LocalFolderPick;
|
|
14
|
+
/** The button's text. Defaults to "Choose a folder…" or "Choose files…"; 80 characters at most. */
|
|
15
|
+
label?: string;
|
|
16
|
+
/** A Bootstrap icon name for the button (`folder-plus`), or `null` for none. */
|
|
17
|
+
icon?: string | null;
|
|
18
|
+
/** Bootstrap's button variant: `primary` (the default), `secondary`, `outline-…` or `link`. */
|
|
19
|
+
variant?: FolderPickerVariant;
|
|
20
|
+
/** Bootstrap's button size. */
|
|
21
|
+
size?: "sm" | "lg";
|
|
22
|
+
/**
|
|
23
|
+
* A ▾ beside the button listing the folders this package already has on this device, in any
|
|
24
|
+
* group, so the person can use one here without the picker. Folders only.
|
|
25
|
+
*/
|
|
26
|
+
offerExisting?: boolean;
|
|
27
|
+
disabled?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* The package the grant is for, for a screen that runs in Peers' window rather than a frame of
|
|
30
|
+
* its own. In a frame Peers grants it to the screen's own package and ignores this.
|
|
31
|
+
*/
|
|
32
|
+
packageId?: string;
|
|
33
|
+
/** The person picked, and the grant is made: its id is what the package's code uses. */
|
|
34
|
+
onPicked: (grant: ILocalFolderGrantInfo) => void;
|
|
35
|
+
/** The grant failed. Cancelling the picker calls neither. */
|
|
36
|
+
onError?: (message: string) => void;
|
|
37
|
+
/** Classes for the box around the button. */
|
|
38
|
+
className?: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* A button that asks for a folder (or files) on this device for the package, drawn by Peers: a
|
|
42
|
+
* click opens the OS picker, and Peers grants what the person picks to the package through System
|
|
43
|
+
* Local Folders, then calls `onPicked` with the grant. A package can't make a grant itself, so this
|
|
44
|
+
* is how its screen gets one. Like a browser's `<input type="file">`, the screen places it and
|
|
45
|
+
* gets the result, but can't click it or choose the folder.
|
|
46
|
+
*
|
|
47
|
+
* In a screen's frame it's an empty slot, as big as the button, which Peers covers with its own
|
|
48
|
+
* button. Where Peers can't reach this device's folders (the web app), the click reports why
|
|
49
|
+
* through `onError`. To hide it, don't render it or give it `display: none`: `visibility: hidden`
|
|
50
|
+
* or `opacity: 0` leaves the slot's box, and Peers' button over it.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* <LocalFolderPicker groupId={groupId} label="Choose a folder" onPicked={(grant) => use(grant.grantId)} />
|
|
54
|
+
*/
|
|
55
|
+
export declare function LocalFolderPicker(props: ILocalFolderPickerProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LocalFolderPicker = LocalFolderPicker;
|
|
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 popover_surface_1 = require("../ui-contracts/popover-surface");
|
|
8
|
+
const focus_relay_1 = require("./focus-relay");
|
|
9
|
+
const folder_picker_control_1 = require("./folder-picker-control");
|
|
10
|
+
const folder_picker_protocol_1 = require("./folder-picker-protocol");
|
|
11
|
+
const frame_protocol_1 = require("./frame-protocol");
|
|
12
|
+
const frame_realm_1 = require("./frame-realm");
|
|
13
|
+
const slot_rect_1 = require("./slot-rect");
|
|
14
|
+
function errorText(error) {
|
|
15
|
+
return error instanceof Error ? error.message : String(error);
|
|
16
|
+
}
|
|
17
|
+
function requestOf(props) {
|
|
18
|
+
return {
|
|
19
|
+
groupId: props.groupId,
|
|
20
|
+
mode: props.mode,
|
|
21
|
+
pick: props.pick,
|
|
22
|
+
label: props.label,
|
|
23
|
+
icon: props.icon,
|
|
24
|
+
variant: props.variant,
|
|
25
|
+
size: props.size,
|
|
26
|
+
offerExisting: props.offerExisting,
|
|
27
|
+
disabled: props.disabled,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* A button that asks for a folder (or files) on this device for the package, drawn by Peers: a
|
|
32
|
+
* click opens the OS picker, and Peers grants what the person picks to the package through System
|
|
33
|
+
* Local Folders, then calls `onPicked` with the grant. A package can't make a grant itself, so this
|
|
34
|
+
* is how its screen gets one. Like a browser's `<input type="file">`, the screen places it and
|
|
35
|
+
* gets the result, but can't click it or choose the folder.
|
|
36
|
+
*
|
|
37
|
+
* In a screen's frame it's an empty slot, as big as the button, which Peers covers with its own
|
|
38
|
+
* button. Where Peers can't reach this device's folders (the web app), the click reports why
|
|
39
|
+
* through `onError`. To hide it, don't render it or give it `display: none`: `visibility: hidden`
|
|
40
|
+
* or `opacity: 0` leaves the slot's box, and Peers' button over it.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* <LocalFolderPicker groupId={groupId} label="Choose a folder" onPicked={(grant) => use(grant.grantId)} />
|
|
44
|
+
*/
|
|
45
|
+
function LocalFolderPicker(props) {
|
|
46
|
+
const host = (0, frame_realm_1.frameHost)();
|
|
47
|
+
const request = (0, folder_picker_protocol_1.toFolderPickerRequest)(requestOf(props));
|
|
48
|
+
if ("error" in request) {
|
|
49
|
+
return (0, jsx_runtime_1.jsx)("span", { className: "text-danger small", children: request.error });
|
|
50
|
+
}
|
|
51
|
+
return host ? ((0, jsx_runtime_1.jsx)(SlotPicker, { ...props, host: host, request: request })) : (
|
|
52
|
+
// The same box around the button as a frame's slot, so `className` lays it out alike.
|
|
53
|
+
(0, jsx_runtime_1.jsx)("span", { className: boxClass(props.className), children: (0, jsx_runtime_1.jsx)(folder_picker_control_1.FolderPickerControl, { request: request, packageId: props.packageId, onPicked: props.onPicked, onFailed: (message) => props.onError ? props.onError(message) : console.warn(`Folder picker: ${message}`) }) }));
|
|
54
|
+
}
|
|
55
|
+
/** The box around the button: inline, as the button is, with the screen's classes. */
|
|
56
|
+
function boxClass(className) {
|
|
57
|
+
return `d-inline-block${className ? ` ${className}` : ""}`;
|
|
58
|
+
}
|
|
59
|
+
/** In a framed screen: the slot the host draws its picker over. */
|
|
60
|
+
function SlotPicker(props) {
|
|
61
|
+
const { host, request } = props;
|
|
62
|
+
const slotRef = (0, react_1.useRef)(null);
|
|
63
|
+
const latest = (0, react_1.useRef)(props);
|
|
64
|
+
latest.current = props;
|
|
65
|
+
// The slot the host holds for this mount, once its mount request has been answered.
|
|
66
|
+
const mounted = (0, react_1.useRef)();
|
|
67
|
+
const requestKey = JSON.stringify(request);
|
|
68
|
+
(0, react_1.useEffect)(() => {
|
|
69
|
+
// Each mount is a slot of its own, so a late answer to an earlier one never touches it.
|
|
70
|
+
const slotId = (0, peers_sdk_1.newid)();
|
|
71
|
+
let active = true;
|
|
72
|
+
let stopWatching;
|
|
73
|
+
const mine = (payload) => payload?.slotId === slotId;
|
|
74
|
+
const failed = (message) => latest.current.onError
|
|
75
|
+
? latest.current.onError(message)
|
|
76
|
+
: console.warn(`Folder picker: ${message}`);
|
|
77
|
+
const stops = [
|
|
78
|
+
host.onNotify(folder_picker_protocol_1.FolderPickerMessage.picked, (payload) => {
|
|
79
|
+
if (mine(payload))
|
|
80
|
+
latest.current.onPicked(payload.grant);
|
|
81
|
+
}),
|
|
82
|
+
host.onNotify(folder_picker_protocol_1.FolderPickerMessage.failed, (payload) => {
|
|
83
|
+
if (mine(payload))
|
|
84
|
+
failed(String(payload.message));
|
|
85
|
+
}),
|
|
86
|
+
// A press on the host's buttons over this slot, or in their ▾ menu, is inside the slot: a
|
|
87
|
+
// popover around it stays open.
|
|
88
|
+
host.onNotify(frame_protocol_1.HostNotice.outsidePointerDown, (payload) => {
|
|
89
|
+
if (mine(payload)) {
|
|
90
|
+
slotRef.current?.dispatchEvent(new Event(popover_surface_1.FRAME_POINTER_EVENT, { bubbles: true }));
|
|
91
|
+
}
|
|
92
|
+
}),
|
|
93
|
+
// Tab left the host's buttons over this slot: on to the control after it, or before it.
|
|
94
|
+
host.onNotify(frame_protocol_1.HostNotice.pieceFocusLeave, (payload) => {
|
|
95
|
+
const slot = slotRef.current;
|
|
96
|
+
if (!mine(payload) || !slot || !document.hasFocus())
|
|
97
|
+
return;
|
|
98
|
+
(0, focus_relay_1.focusBeside)(slot, payload.direction === "previous" ? "previous" : "next");
|
|
99
|
+
}),
|
|
100
|
+
];
|
|
101
|
+
host.request(folder_picker_protocol_1.FolderPickerMessage.mount, { slotId, request: requestOf(latest.current) }).then(() => {
|
|
102
|
+
// Gone while the host drew it: the host holds it only now.
|
|
103
|
+
if (!active)
|
|
104
|
+
return host.notify(folder_picker_protocol_1.FolderPickerMessage.unmount, { slotId });
|
|
105
|
+
mounted.current = slotId;
|
|
106
|
+
// Tab (or autofocus) that reached the slot before the host held it goes on now.
|
|
107
|
+
if (document.hasFocus() && document.activeElement === slotRef.current) {
|
|
108
|
+
host.notify(folder_picker_protocol_1.FolderPickerMessage.focus, { slotId, edge: "first" });
|
|
109
|
+
}
|
|
110
|
+
stopWatching = (0, slot_rect_1.watchSlotRect)(() => slotRef.current, (rect, clip) => host.notify(folder_picker_protocol_1.FolderPickerMessage.rect, { slotId, rect, clip }));
|
|
111
|
+
if (JSON.stringify(latest.current.request) !== requestKey) {
|
|
112
|
+
host.notify(folder_picker_protocol_1.FolderPickerMessage.change, { slotId, request: requestOf(latest.current) });
|
|
113
|
+
}
|
|
114
|
+
}, (error) => active && failed(errorText(error)));
|
|
115
|
+
return () => {
|
|
116
|
+
active = false;
|
|
117
|
+
if (mounted.current === slotId) {
|
|
118
|
+
mounted.current = undefined;
|
|
119
|
+
host.notify(folder_picker_protocol_1.FolderPickerMessage.unmount, { slotId });
|
|
120
|
+
}
|
|
121
|
+
for (const stop of stops)
|
|
122
|
+
stop();
|
|
123
|
+
stopWatching?.();
|
|
124
|
+
};
|
|
125
|
+
}, [host]);
|
|
126
|
+
// Until the host holds the slot, its mount sends the request that's current when it does.
|
|
127
|
+
(0, react_1.useEffect)(() => {
|
|
128
|
+
const slotId = mounted.current;
|
|
129
|
+
if (slotId)
|
|
130
|
+
host.notify(folder_picker_protocol_1.FolderPickerMessage.change, { slotId, request: requestOf(latest.current) });
|
|
131
|
+
}, [requestKey, host]);
|
|
132
|
+
return (
|
|
133
|
+
// It stands in for Peers' button, which the host draws over it, in the screen's Tab order:
|
|
134
|
+
// Tab stops here, and the host moves focus on to its button.
|
|
135
|
+
// biome-ignore lint/a11y/useSemanticElements: a stand-in, not a control: the host's button takes the focus and the click.
|
|
136
|
+
(0, jsx_runtime_1.jsx)("span", { ref: slotRef, role: "button", "data-peers-folder-picker-slot": "", className: boxClass(props.className), "aria-label": request.label, "aria-disabled": request.disabled || undefined, tabIndex: request.disabled ? -1 : 0, onFocus: (event) => {
|
|
137
|
+
const slotId = mounted.current;
|
|
138
|
+
if (event.target !== event.currentTarget || !slotId)
|
|
139
|
+
return;
|
|
140
|
+
const edge = (0, focus_relay_1.edgeEnteredFrom)(event.currentTarget, event.relatedTarget);
|
|
141
|
+
host.notify(folder_picker_protocol_1.FolderPickerMessage.focus, { slotId, edge });
|
|
142
|
+
}, children: (0, jsx_runtime_1.jsx)(folder_picker_control_1.FolderPickerFace, { request: request }) }));
|
|
143
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import type { IFrameMicrophoneOpened, IFrameMicrophoneRequest } from "./frame-protocol";
|
|
2
|
+
/**
|
|
3
|
+
* The microphone for package screens in frames.
|
|
4
|
+
*
|
|
5
|
+
* A frame's opaque origin can't open the microphone: Chromium and WebKit refuse `getUserMedia`
|
|
6
|
+
* there, even with `allow="microphone"`. So the host opens it, once for each set of processing
|
|
7
|
+
* options however many screens listen, and an AudioWorklet copies each block of 128 samples into
|
|
8
|
+
* every screen stream's `MessagePort`. The blocks go from the host's audio thread to the frame's,
|
|
9
|
+
* so neither main thread handles the sound. The frame plays them into a `MediaStream`, which its
|
|
10
|
+
* `getUserMedia` returns (`frame-microphone.ts`).
|
|
11
|
+
*
|
|
12
|
+
* A package gets it only when its manifest declares it (`pkg.microphone`, with a reason) and the
|
|
13
|
+
* person allows it on this device. Peers asks once per package and keeps the answer either way.
|
|
14
|
+
* The microphone closes when the last stream on it stops, or its screen closes.
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* The host's AudioWorklet module, the tap: copies each block of the microphone to every stream's
|
|
18
|
+
* port, since the engine reuses its input buffers. The copy is transferred, with one transfer
|
|
19
|
+
* list reused, so a block allocates only its copies. Exported for its tests.
|
|
20
|
+
*/
|
|
21
|
+
export declare const TAP_MODULE = "\nclass PeersMicrophoneTap extends AudioWorkletProcessor {\n constructor() {\n super();\n this.outs = new Map();\n this.transfer = [null];\n this.port.onmessage = (event) => {\n const message = event.data;\n if (message.type === \"add\") {\n this.outs.set(message.id, message.port);\n } else if (message.type === \"remove\") {\n const port = this.outs.get(message.id);\n this.outs.delete(message.id);\n if (port) port.close();\n }\n };\n }\n process(inputs) {\n const channel = inputs[0] && inputs[0][0];\n if (channel) {\n for (const port of this.outs.values()) {\n const copy = channel.slice();\n this.transfer[0] = copy.buffer;\n port.postMessage(copy, this.transfer);\n }\n }\n return true;\n }\n}\nregisterProcessor(\"peers-microphone-tap\", PeersMicrophoneTap);\n";
|
|
22
|
+
/** One open microphone, and the audio graph that taps it. */
|
|
23
|
+
export interface IMicrophoneCapture {
|
|
24
|
+
/** The rate its blocks are at, in Hz. */
|
|
25
|
+
readonly sampleRate: number;
|
|
26
|
+
/** The microphone track's settings a screen may read ({@link sharedTrackSettings}). */
|
|
27
|
+
readonly settings: MediaTrackSettings;
|
|
28
|
+
/** Send its sound down `port`, as stream `id`. */
|
|
29
|
+
add(id: string, port: MessagePort): void;
|
|
30
|
+
/** Stop sending to stream `id`, and close its port. */
|
|
31
|
+
remove(id: string): void;
|
|
32
|
+
/** Stop the microphone. */
|
|
33
|
+
close(): void;
|
|
34
|
+
/** Call `listener` once if the microphone stops by itself (unplugged, or taken away). */
|
|
35
|
+
onEnded?(listener: () => void): void;
|
|
36
|
+
}
|
|
37
|
+
/** Opens the microphone with a screen's processing options. */
|
|
38
|
+
export type MicrophoneCaptureFactory = (request: IFrameMicrophoneRequest) => Promise<IMicrophoneCapture>;
|
|
39
|
+
/**
|
|
40
|
+
* A test seam: replace how the host opens the microphone. Without an argument, the real one is
|
|
41
|
+
* back.
|
|
42
|
+
*
|
|
43
|
+
* @param factory - Opens a capture for a request.
|
|
44
|
+
*/
|
|
45
|
+
export declare function setMicrophoneCaptureForTests(factory?: MicrophoneCaptureFactory): void;
|
|
46
|
+
/**
|
|
47
|
+
* Whether a package may use the microphone on this device: the person's answer, or, the first
|
|
48
|
+
* time, the one they give now. Closing the question refuses this once, without keeping it.
|
|
49
|
+
*
|
|
50
|
+
* @param packageId - The package.
|
|
51
|
+
* @param packageName - Its name, for the question.
|
|
52
|
+
* @param reason - Why it listens, from its declaration.
|
|
53
|
+
*/
|
|
54
|
+
export declare function microphoneAllowedFor(packageId: string, packageName: string, reason: string): Promise<boolean>;
|
|
55
|
+
/** Keeps what a screen may choose: the processing switches and a sensible rate. */
|
|
56
|
+
export declare function normalizeMicrophoneRequest(value: unknown): IFrameMicrophoneRequest;
|
|
57
|
+
/**
|
|
58
|
+
* Open the microphone for one of a frame's `getUserMedia` streams, and send its sound down
|
|
59
|
+
* `port`. Refused, with the port closed, unless the package declares the microphone and the
|
|
60
|
+
* person allows it on this device.
|
|
61
|
+
*
|
|
62
|
+
* @param input.frameId - The frame.
|
|
63
|
+
* @param input.packageId - Its package.
|
|
64
|
+
* @param input.packageName - The package's name, for the question.
|
|
65
|
+
* @param input.reason - Why it listens, from its stored manifest; `undefined` when it doesn't
|
|
66
|
+
* declare the microphone.
|
|
67
|
+
* @param input.streamId - The frame's id for the stream.
|
|
68
|
+
* @param input.request - The processing it asked for, as the frame sent it.
|
|
69
|
+
* @param input.port - Where the sound goes.
|
|
70
|
+
* @returns the rate the sound is at
|
|
71
|
+
*/
|
|
72
|
+
export declare function openFrameMicrophone(input: {
|
|
73
|
+
frameId: string;
|
|
74
|
+
packageId: string;
|
|
75
|
+
packageName: string;
|
|
76
|
+
reason: string | undefined;
|
|
77
|
+
streamId: string;
|
|
78
|
+
request: unknown;
|
|
79
|
+
port: MessagePort | undefined;
|
|
80
|
+
}): Promise<IFrameMicrophoneOpened>;
|
|
81
|
+
/**
|
|
82
|
+
* Stop sending sound to one of a frame's streams. The microphone closes with its last stream.
|
|
83
|
+
*
|
|
84
|
+
* @param frameId - The frame.
|
|
85
|
+
* @param streamId - The frame's id for the stream.
|
|
86
|
+
*/
|
|
87
|
+
export declare function closeFrameMicrophone(frameId: string, streamId: string): void;
|
|
88
|
+
/**
|
|
89
|
+
* Stop every stream a frame has open, as its screen closes.
|
|
90
|
+
*
|
|
91
|
+
* @param frameId - The frame.
|
|
92
|
+
*/
|
|
93
|
+
export declare function closeFrameMicrophones(frameId: string): void;
|
|
94
|
+
/**
|
|
95
|
+
* Change a package's answer on this device, as its details' switch and Ask again do. Unless it's
|
|
96
|
+
* now allowed, every stream its screens have open or are opening stops: the screen hears silence.
|
|
97
|
+
*
|
|
98
|
+
* @param packageId - The package.
|
|
99
|
+
* @param allowed - `true` to allow, `false` to refuse, `undefined` to ask again.
|
|
100
|
+
*/
|
|
101
|
+
export declare function changeMicrophoneAnswer(packageId: string, allowed: boolean | undefined): void;
|
|
102
|
+
/** Whether any screen's stream has the microphone open. */
|
|
103
|
+
export declare function microphoneInUse(): boolean;
|
|
104
|
+
/**
|
|
105
|
+
* The microphone track's settings that a screen's stream reports, so a screen that keeps settings
|
|
106
|
+
* per microphone (Voice Hub's acoustic profiles) finds the same device id as in the window.
|
|
107
|
+
*
|
|
108
|
+
* @param track - The host's microphone track.
|
|
109
|
+
*/
|
|
110
|
+
export declare function sharedTrackSettings(track: MediaStreamTrack | undefined): MediaTrackSettings;
|