@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
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SECRET_VAR_MASK = void 0;
3
4
  exports.createFramePvarService = createFramePvarService;
4
5
  const peers_sdk_1 = require("@peers-app/peers-sdk");
5
6
  const lodash_1 = require("lodash");
@@ -17,8 +18,23 @@ const lodash_1 = require("lodash");
17
18
  * (`<packageId>_<name>`), as a variable its worker declares is. A name that already starts
18
19
  * with the package's id is used as it is.
19
20
  *
20
- * Secret variables aren't served to screens.
21
+ * A screen can set and delete its package's secret variables (an API key from its settings), but
22
+ * never read one: it reads {@link SECRET_VAR_MASK} while the variable is set, and its value only
23
+ * while it's empty.
21
24
  */
25
+ /**
26
+ * What a screen reads for one of its package's secret variables while it's set, in place of the
27
+ * value. Writing it back changes nothing.
28
+ */
29
+ exports.SECRET_VAR_MASK = "••••••••";
30
+ /** Whether a secret's value is empty: what a screen writes to clear it. */
31
+ function isEmptySecret(value) {
32
+ return value === undefined || value === null || value === "";
33
+ }
34
+ /** A secret's value as a screen sees it: the mask, or an empty value as it is. */
35
+ function maskSecret(value) {
36
+ return isEmptySecret(value) ? value : exports.SECRET_VAR_MASK;
37
+ }
22
38
  /** Host variables every screen reads, and none writes. */
23
39
  const HOST_READ_ONLY_PVARS = new Map([
24
40
  ["thisDeviceId", "device"],
@@ -31,10 +47,11 @@ const HOST_READ_ONLY_PVARS = new Map([
31
47
  ]);
32
48
  /** The variable that is the screen's tab path. */
33
49
  const TAB_PATH_PVAR = "mainContentPath";
34
- function makeVar(scope, name, defaultValue, dataContext) {
50
+ function makeVar(scope, name, defaultValue, dataContext, isSecret = false) {
35
51
  const opts = {
36
52
  ...(defaultValue !== undefined ? { defaultValue } : {}),
37
53
  ...(dataContext ? { dataContext } : {}),
54
+ ...(isSecret ? { isSecret: true } : {}),
38
55
  };
39
56
  switch (scope) {
40
57
  case "device":
@@ -73,7 +90,9 @@ function createFramePvarService(host) {
73
90
  const subscription = host.tabPath.subscribe((path) => host.changed(bindingId, path));
74
91
  bindings.set(bindingId, {
75
92
  write: async (value) => {
76
- if (typeof value === "string" && value !== host.tabPath())
93
+ if (value === exports.SECRET_VAR_MASK)
94
+ host.changed(bindingId, host.tabPath());
95
+ else if (typeof value === "string" && value !== host.tabPath())
77
96
  host.navigate(value);
78
97
  },
79
98
  delete: async () => undefined,
@@ -81,36 +100,103 @@ function createFramePvarService(host) {
81
100
  });
82
101
  return host.tabPath();
83
102
  };
84
- const bindVar = async (bindingId, variable, readOnly) => {
103
+ const bindVar = async (bindingId, variable, mode, defaultValue) => {
85
104
  await variable.loadingPromise;
86
105
  if (disposed)
87
106
  return undefined;
88
- const subscription = variable.subscribe((value) => host.changed(bindingId, value));
107
+ // Also honor secrecy the SDK found in the variable's stored row, as it is now: a plain binding
108
+ // is write-only while its row is secret (synced from a device where it's secret, or marked
109
+ // secret in Variables), and plain again when the variable moves to a plain row (a group-
110
+ // dependent variable in another group). The SDK takes a row's secrecy before it publishes the
111
+ // row's value, and subscribers run as the value is published.
112
+ const isWriteOnly = () => mode === "writeOnlySecret" || (mode === "readWrite" && variable.isSecret?.() === true);
113
+ const shown = (value) => (isWriteOnly() ? maskSecret(value) : value);
114
+ const initial = shown(variable());
115
+ // A secret's screen hears when it becomes set or empty (however empty is represented), not
116
+ // when another value replaces it.
117
+ let lastShown = initial;
118
+ const sendCurrent = () => {
119
+ // A write reply may be the first time the screen sees a change in secrecy.
120
+ lastShown = shown(variable());
121
+ host.changed(bindingId, lastShown);
122
+ };
123
+ const subscription = variable.subscribe((value) => {
124
+ const hidden = isWriteOnly();
125
+ const next = hidden ? maskSecret(value) : value;
126
+ if (hidden && (next === lastShown || (isEmptySecret(next) && isEmptySecret(lastShown)))) {
127
+ return;
128
+ }
129
+ lastShown = next;
130
+ host.changed(bindingId, next);
131
+ });
132
+ // The SDK stores an empty secret encrypted, which reads as set, so clearing one deletes it.
133
+ // If deletion didn't update a variable with no default, clear its in-memory value too. One
134
+ // already back at its declared default is left there: writing `undefined` would save a row.
135
+ const clearSecret = async () => {
136
+ const before = variable();
137
+ await variable.delete();
138
+ const after = variable();
139
+ if (after === before && !isEmptySecret(after) && !(0, lodash_1.isEqual)(after, defaultValue)) {
140
+ variable(undefined);
141
+ }
142
+ };
89
143
  bindings.set(bindingId, {
90
144
  write: async (value) => {
91
- if (readOnly) {
145
+ if (mode === "readOnly") {
92
146
  // The host's own: the frame goes back to the host's value.
93
147
  if (!(0, lodash_1.isEqual)(value, variable()))
94
148
  host.changed(bindingId, variable());
95
149
  return;
96
150
  }
97
- variable(value);
98
- await variable.loadingPromise;
151
+ // The mask a screen was shown, written back, never changes anything: not the secret, and
152
+ // not a plain value it was shown in place of (a form still holding the mask after its
153
+ // variable turned plain). The screen gets what it should show back.
154
+ if (value === exports.SECRET_VAR_MASK) {
155
+ sendCurrent();
156
+ return;
157
+ }
158
+ if (!isWriteOnly()) {
159
+ const current = variable(value);
160
+ // An equal write sends no notice. The screen may still have the previous group's mask.
161
+ if (!Object.is(current, lastShown))
162
+ sendCurrent();
163
+ await variable.loadingPromise;
164
+ return;
165
+ }
166
+ if (isEmptySecret(value))
167
+ await clearSecret();
168
+ else {
169
+ variable(value);
170
+ await variable.loadingPromise;
171
+ }
172
+ // The screen that wrote it holds what it wrote: it gets the mask, or the empty value, back.
173
+ sendCurrent();
99
174
  },
100
175
  delete: async () => {
101
- if (!readOnly)
176
+ if (mode === "readOnly")
177
+ return;
178
+ if (!isWriteOnly()) {
102
179
  await variable.delete();
180
+ // The frame now shows its default. Equal to the previous group's masked default, it sent
181
+ // no notice; only the declared default is sent, never a value left in memory.
182
+ if ((0, lodash_1.isEqual)(variable(), defaultValue) && !Object.is(shown(variable()), lastShown)) {
183
+ sendCurrent();
184
+ }
185
+ return;
186
+ }
187
+ await clearSecret();
188
+ sendCurrent();
103
189
  },
104
190
  stop: () => subscription.dispose(),
105
191
  });
106
- return variable();
192
+ return initial;
107
193
  };
108
194
  return {
109
195
  async bind({ bindingId, request }) {
110
196
  bindings.get(bindingId)?.stop();
111
197
  const { name, scope } = request;
112
- if (request.isSecret) {
113
- throw new Error(`Permission denied: screens can't use secret variables (${name})`);
198
+ if (request.isSecret && (name === TAB_PATH_PVAR || HOST_READ_ONLY_PVARS.has(name))) {
199
+ throw new Error(`Permission denied: ${name} isn't a secret variable`);
114
200
  }
115
201
  if (name === TAB_PATH_PVAR)
116
202
  return bindTabPath(bindingId);
@@ -123,12 +209,13 @@ function createFramePvarService(host) {
123
209
  if (scope !== hostScope) {
124
210
  throw new Error(`Permission denied: ${name} is a ${hostScope} variable`);
125
211
  }
126
- return bindVar(bindingId, makeVar(hostScope, name, undefined, dataContext), true);
212
+ return bindVar(bindingId, makeVar(hostScope, name, undefined, dataContext), "readOnly");
127
213
  }
128
214
  const stored = name.startsWith(`${host.packageId}_`)
129
215
  ? name
130
216
  : (0, peers_sdk_1.packageScopedPersistentVarName)(host.packageId, name);
131
- return bindVar(bindingId, makeVar(scope, stored, request.defaultValue, dataContext), false);
217
+ const variable = makeVar(scope, stored, request.defaultValue, dataContext, request.isSecret === true);
218
+ return bindVar(bindingId, variable, request.isSecret === true ? "writeOnlySecret" : "readWrite", request.defaultValue);
132
219
  },
133
220
  async write({ bindingId, value }) {
134
221
  const binding = bindings.get(bindingId);
@@ -15,8 +15,7 @@ import type { IWidgetBox } from "./widget-box";
15
15
  * turns a widget off on a device in the package's details.
16
16
  *
17
17
  * A package still on the shared-window list (`SHARED_WINDOW_PACKAGES`) draws its widgets in the
18
- * window instead, as its screens do: Operator, whose assistant needs the microphone, which a
19
- * frame's opaque origin can't open.
18
+ * window instead, as its screens do.
20
19
  */
21
20
  /** A widget to draw: its package's running version in Personal, and the widget's declaration. */
22
21
  export interface IGlobalWidgetEntry {
@@ -1,3 +1,5 @@
1
1
  export { configureIsolatedScreens, type IIsolatedScreensHost, runsIsolated, SHARED_WINDOW_PACKAGES, } from "./config";
2
+ export type { FolderPickerVariant } from "./folder-picker-protocol";
2
3
  export { isInFrame } from "./frame-realm";
3
4
  export { startFrameRuntime } from "./frame-runtime";
5
+ export { type ILocalFolderPickerProps, LocalFolderPicker } from "./local-folder-picker";
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.startFrameRuntime = exports.isInFrame = exports.SHARED_WINDOW_PACKAGES = exports.runsIsolated = exports.configureIsolatedScreens = void 0;
3
+ exports.LocalFolderPicker = exports.startFrameRuntime = exports.isInFrame = exports.SHARED_WINDOW_PACKAGES = exports.runsIsolated = exports.configureIsolatedScreens = void 0;
4
4
  // Isolated package screens: each package's screen runs in a sandboxed frame of its own.
5
5
  // Hosts turn it on with configureIsolatedScreens; docs/Packages/isolated-screens.md.
6
6
  var config_1 = require("./config");
@@ -11,3 +11,5 @@ var frame_realm_1 = require("./frame-realm");
11
11
  Object.defineProperty(exports, "isInFrame", { enumerable: true, get: function () { return frame_realm_1.isInFrame; } });
12
12
  var frame_runtime_1 = require("./frame-runtime");
13
13
  Object.defineProperty(exports, "startFrameRuntime", { enumerable: true, get: function () { return frame_runtime_1.startFrameRuntime; } });
14
+ var local_folder_picker_1 = require("./local-folder-picker");
15
+ Object.defineProperty(exports, "LocalFolderPicker", { enumerable: true, get: function () { return local_folder_picker_1.LocalFolderPicker; } });
@@ -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
- /** A click in the host's own window is outside every frame. */
223
- function relayHostPointers() {
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
+ }