@peers-app/peers-ui 0.33.24 → 0.34.1

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 (108) hide show
  1. package/dist/command-palette/command-palette.js +4 -2
  2. package/dist/components/router.d.ts +1 -0
  3. package/dist/components/router.js +4 -1
  4. package/dist/host-shell/host-shell-consumer.js +8 -0
  5. package/dist/index.d.ts +2 -0
  6. package/dist/index.js +7 -1
  7. package/dist/isolated-screens/config.d.ts +51 -0
  8. package/dist/isolated-screens/config.js +73 -0
  9. package/dist/isolated-screens/frame-autostart.d.ts +1 -0
  10. package/dist/isolated-screens/frame-autostart.js +18 -0
  11. package/dist/isolated-screens/frame-bridge.d.ts +30 -0
  12. package/dist/isolated-screens/frame-bridge.js +113 -0
  13. package/dist/isolated-screens/frame-component.d.ts +6 -0
  14. package/dist/isolated-screens/frame-component.js +20 -0
  15. package/dist/isolated-screens/frame-document.d.ts +28 -0
  16. package/dist/isolated-screens/frame-document.js +77 -0
  17. package/dist/isolated-screens/frame-policy.d.ts +17 -0
  18. package/dist/isolated-screens/frame-policy.js +230 -0
  19. package/dist/isolated-screens/frame-protocol.d.ts +196 -0
  20. package/dist/isolated-screens/frame-protocol.js +150 -0
  21. package/dist/isolated-screens/frame-pvars.d.ts +33 -0
  22. package/dist/isolated-screens/frame-pvars.js +152 -0
  23. package/dist/isolated-screens/frame-realm.d.ts +12 -0
  24. package/dist/isolated-screens/frame-realm.js +31 -0
  25. package/dist/isolated-screens/frame-runtime.d.ts +5 -0
  26. package/dist/isolated-screens/frame-runtime.js +494 -0
  27. package/dist/isolated-screens/frame-storage.d.ts +43 -0
  28. package/dist/isolated-screens/frame-storage.js +85 -0
  29. package/dist/isolated-screens/index.d.ts +3 -0
  30. package/dist/isolated-screens/index.js +13 -0
  31. package/dist/isolated-screens/isolated-screen.d.ts +193 -0
  32. package/dist/isolated-screens/isolated-screen.js +695 -0
  33. package/dist/isolated-screens/piece-frames.d.ts +27 -0
  34. package/dist/isolated-screens/piece-frames.js +351 -0
  35. package/dist/isolated-screens/piece-reach.d.ts +11 -0
  36. package/dist/isolated-screens/piece-reach.js +56 -0
  37. package/dist/isolated-screens/port-channel.d.ts +47 -0
  38. package/dist/isolated-screens/port-channel.js +153 -0
  39. package/dist/isolated-screens/routes-sandbox.d.ts +8 -0
  40. package/dist/isolated-screens/routes-sandbox.js +130 -0
  41. package/dist/isolated-screens/screen-tab-context.d.ts +4 -0
  42. package/dist/isolated-screens/screen-tab-context.js +6 -0
  43. package/dist/isolated-screens/test-ports.d.ts +3 -0
  44. package/dist/isolated-screens/test-ports.js +21 -0
  45. package/dist/isolated-screens/wheel-relay.d.ts +48 -0
  46. package/dist/isolated-screens/wheel-relay.js +186 -0
  47. package/dist/mentions/mentions-client.js +9 -0
  48. package/dist/notifications/index.js +9 -5
  49. package/dist/operator-console/console-copy.d.ts +15 -0
  50. package/dist/operator-console/console-copy.js +97 -0
  51. package/dist/operator-console/console-header.d.ts +33 -0
  52. package/dist/operator-console/console-header.js +67 -0
  53. package/dist/operator-console/console-input.d.ts +20 -0
  54. package/dist/operator-console/console-input.js +313 -0
  55. package/dist/operator-console/console-repl.d.ts +7 -0
  56. package/dist/operator-console/console-repl.js +108 -0
  57. package/dist/operator-console/console-scope.d.ts +45 -0
  58. package/dist/operator-console/console-scope.js +174 -0
  59. package/dist/operator-console/console-screen.d.ts +8 -0
  60. package/dist/operator-console/console-screen.js +32 -0
  61. package/dist/operator-console/console-session.d.ts +106 -0
  62. package/dist/operator-console/console-session.js +567 -0
  63. package/dist/operator-console/console-test-host.d.ts +21 -0
  64. package/dist/operator-console/console-test-host.js +114 -0
  65. package/dist/operator-console/console-theme.d.ts +41 -0
  66. package/dist/operator-console/console-theme.js +55 -0
  67. package/dist/operator-console/console-value.d.ts +27 -0
  68. package/dist/operator-console/console-value.js +291 -0
  69. package/dist/operator-console/operator-console-state.js +3 -1
  70. package/dist/operator-console/operator-console.d.ts +8 -21
  71. package/dist/operator-console/operator-console.js +8 -61
  72. package/dist/root-layout/app-shell-height.d.ts +16 -3
  73. package/dist/root-layout/app-shell-height.js +17 -4
  74. package/dist/root-layout/host-app-menu.d.ts +17 -0
  75. package/dist/root-layout/host-app-menu.js +22 -0
  76. package/dist/root-layout/layouts/full-screen-layout.js +4 -2
  77. package/dist/system-apps/console.app.d.ts +15 -0
  78. package/dist/system-apps/console.app.js +25 -0
  79. package/dist/system-apps/index.d.ts +1 -0
  80. package/dist/system-apps/index.js +6 -1
  81. package/dist/tabs-layout/tabs-layout.js +12 -20
  82. package/dist/tabs-layout/tabs-state.js +39 -16
  83. package/dist/theme.css +32 -5
  84. package/dist/ui-contracts/piece-height.d.ts +18 -0
  85. package/dist/ui-contracts/piece-height.js +15 -0
  86. package/dist/ui-contracts/piece-host.d.ts +24 -1
  87. package/dist/ui-contracts/piece-host.js +53 -2
  88. package/dist/ui-contracts/piece-props.d.ts +16 -0
  89. package/dist/ui-contracts/piece-props.js +39 -0
  90. package/dist/ui-contracts/piece-resolution.d.ts +5 -0
  91. package/dist/ui-contracts/piece-resolution.js +38 -2
  92. package/dist/ui-contracts/piece.d.ts +2 -7
  93. package/dist/ui-contracts/piece.js +22 -37
  94. package/dist/ui-contracts/popover-surface.d.ts +14 -0
  95. package/dist/ui-contracts/popover-surface.js +32 -3
  96. package/dist/ui-inspection/dom-actions.d.ts +23 -0
  97. package/dist/ui-inspection/dom-actions.js +169 -0
  98. package/dist/ui-inspection/dom-inspector.d.ts +20 -0
  99. package/dist/ui-inspection/dom-inspector.js +184 -0
  100. package/dist/ui-inspection/index.d.ts +73 -0
  101. package/dist/ui-inspection/index.js +147 -0
  102. package/dist/ui-router/find-route.d.ts +6 -0
  103. package/dist/ui-router/find-route.js +22 -0
  104. package/dist/ui-router/routes-loader.js +23 -4
  105. package/dist/ui-router/runnable-version.js +3 -0
  106. package/dist/ui-router/ui-loader.d.ts +6 -1
  107. package/dist/ui-router/ui-loader.js +102 -26
  108. package/package.json +3 -3
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.pieceRevision = void 0;
4
+ exports.refreshPieceResolutions = refreshPieceResolutions;
4
5
  exports.setPieceMock = setPieceMock;
5
6
  exports.handleDataContextId = handleDataContextId;
6
7
  exports.resolvePiece = resolvePiece;
@@ -8,6 +9,9 @@ exports.loadPieceComponent = loadPieceComponent;
8
9
  exports.resetPieceResolutions = resetPieceResolutions;
9
10
  const peers_sdk_1 = require("@peers-app/peers-sdk");
10
11
  const globals_1 = require("../globals");
12
+ const config_1 = require("../isolated-screens/config");
13
+ const frame_realm_1 = require("../isolated-screens/frame-realm");
14
+ const piece_frames_1 = require("../isolated-screens/piece-frames");
11
15
  const implement_piece_1 = require("./implement-piece");
12
16
  const piece_host_1 = require("./piece-host");
13
17
  /**
@@ -22,6 +26,13 @@ const bump = () => {
22
26
  resolutions.clear();
23
27
  (0, exports.pieceRevision)((0, exports.pieceRevision)() + 1);
24
28
  };
29
+ /**
30
+ * Drop every resolution kept, and resolve each shown piece again: what Retry on a piece that
31
+ * failed to resolve does. A framed screen's Retry asks the host to do it.
32
+ */
33
+ function refreshPieceResolutions() {
34
+ bump();
35
+ }
25
36
  function watchRevision(dataContextId) {
26
37
  if (!revisionSubscribed) {
27
38
  revisionSubscribed = true;
@@ -33,7 +44,12 @@ function watchRevision(dataContextId) {
33
44
  (0, piece_host_1.watchProviders)(dataContextId, bump);
34
45
  void (0, peers_sdk_1.getUserContext)()
35
46
  .then((userContext) => {
36
- const dataContext = userContext.getDataContext(dataContextId);
47
+ // The group can disappear after resolution starts. Only attach to a live context.
48
+ const dataContext = !dataContextId || dataContextId === userContext.userId
49
+ ? userContext.userDataContext
50
+ : userContext.groupDataContexts.get(dataContextId);
51
+ if (!dataContext)
52
+ return;
37
53
  (0, peers_sdk_1.Packages)(dataContext).dataChanged.subscribe(bump);
38
54
  (0, peers_sdk_1.PackageVersions)(dataContext).dataChanged.subscribe(bump);
39
55
  })
@@ -76,10 +92,24 @@ const resolutions = new Map();
76
92
  * @param dataContextId - The group, from {@link handleDataContextId}.
77
93
  */
78
94
  function resolvePiece(handle, dataContextId) {
95
+ // Inside an isolated screen the host resolves it: the frame can't read the group's packages.
96
+ if ((0, frame_realm_1.isInFrame)()) {
97
+ return (0, piece_frames_1.resolvePieceThroughHost)(handle, dataContextId).catch((error) => ({
98
+ status: "unavailable",
99
+ dataContextId,
100
+ reason: "failed",
101
+ message: error instanceof Error ? error.message : String(error),
102
+ retry: bump,
103
+ }));
104
+ }
79
105
  const key = `${dataContextId}|${(0, implement_piece_1.pieceKey)(handle.contractId, handle.version, handle.name)}|${handle.providerPackageId ?? ""}`;
80
106
  let resolution = resolutions.get(key);
81
107
  if (!resolution) {
82
- watchRevision(dataContextId);
108
+ // A stand-in from `mockPiece` has no provider to follow: a test of the embedder would wait
109
+ // for a host it doesn't have.
110
+ if (!mocks.has((0, implement_piece_1.pieceKey)(handle.contractId, handle.version, handle.name))) {
111
+ watchRevision(dataContextId);
112
+ }
83
113
  resolution = resolveNow(handle, dataContextId).catch((error) => ({
84
114
  status: "unavailable",
85
115
  dataContextId,
@@ -172,6 +202,12 @@ async function loadPieceComponent(available, name) {
172
202
  const mock = mocks.get((0, implement_piece_1.pieceKey)(contractId, version, name));
173
203
  if (mock && available.providerPackageId === "mock")
174
204
  return mock.component;
205
+ // An isolated provider draws in a frame of its own: over a slot inside a framed screen, or in
206
+ // the embedder's box in the host's window. Its bundle never runs in the embedder's realm.
207
+ if ((0, frame_realm_1.isInFrame)())
208
+ return (0, piece_frames_1.slotPieceComponent)(available, name);
209
+ if ((0, config_1.runsIsolated)(available.providerPackageId))
210
+ return (0, piece_frames_1.inlinePieceComponent)(available, name);
175
211
  const pieces = await (0, piece_host_1.loadVersionPieces)(available.dataContextId, available.providerPackageId, available.packageVersionId);
176
212
  const component = pieces.get((0, implement_piece_1.pieceKey)(contractId, version, name));
177
213
  if (!component) {
@@ -1,4 +1,5 @@
1
1
  import React from "react";
2
+ import { type IPieceSize } from "./piece-height";
2
3
  import { type IPieceAvailable } from "./piece-resolution";
3
4
  import { type PopoverAnchor } from "./popover-surface";
4
5
  import type { IPieceHandle, IPieceUnavailable, PieceHandleProps, PieceHandlers } from "./types";
@@ -23,13 +24,7 @@ export type PieceState = {
23
24
  export declare function usePiece(handle: IPieceHandle, options?: {
24
25
  enabled?: boolean;
25
26
  }): PieceState;
26
- /** The size of the box a piece draws in. */
27
- export interface IPieceSize {
28
- /** Width in CSS pixels. */
29
- width: number;
30
- /** Height in CSS pixels. */
31
- height: number;
32
- }
27
+ export type { IPieceSize } from "./piece-height";
33
28
  /**
34
29
  * The size of the box this piece draws in, for a piece that adapts to its box rather than the
35
30
  * window: window breakpoints give the wrong answer inside a panel. Zero until measured.
@@ -42,6 +42,8 @@ const react_1 = __importStar(require("react"));
42
42
  const use_observable_1 = require("../hooks/use-observable");
43
43
  const mentions_client_1 = require("../mentions/mentions-client");
44
44
  const host_ui_contract_1 = require("./host-ui-contract");
45
+ const piece_height_1 = require("./piece-height");
46
+ const piece_props_1 = require("./piece-props");
45
47
  const piece_resolution_1 = require("./piece-resolution");
46
48
  const popover_surface_1 = require("./popover-surface");
47
49
  /**
@@ -73,8 +75,18 @@ function usePiece(handle, options = {}) {
73
75
  void (async () => {
74
76
  const current = handleRef.current;
75
77
  let resolution;
78
+ let resolvedAt;
76
79
  try {
77
- resolution = await (0, piece_resolution_1.resolvePiece)(current, await (0, piece_resolution_1.handleDataContextId)(current));
80
+ const dataContextId = await (0, piece_resolution_1.handleDataContextId)(current);
81
+ // A group getter runs on each render. Its answer can reuse the resolution already
82
+ // shown, including in a frame where resolving again would make a host round trip.
83
+ resolution =
84
+ found?.key === key &&
85
+ found.revision === revision &&
86
+ found.resolution.dataContextId === dataContextId
87
+ ? found.resolution
88
+ : await (0, piece_resolution_1.resolvePiece)(current, dataContextId);
89
+ resolvedAt = revision;
78
90
  }
79
91
  catch (error) {
80
92
  resolution = {
@@ -87,9 +99,7 @@ function usePiece(handle, options = {}) {
87
99
  // A failed group getter has no cached resolution, and the render showing its failure
88
100
  // checks again: keep the failure shown, even if its message differs, so a getter that
89
101
  // keeps failing settles instead of rendering and checking without end.
90
- if (found?.key === key &&
91
- found.resolution.status === "unavailable" &&
92
- found.resolution.dataContextId === "") {
102
+ if (found?.key === key && found.revision === undefined) {
93
103
  resolution = found.resolution;
94
104
  }
95
105
  }
@@ -97,9 +107,11 @@ function usePiece(handle, options = {}) {
97
107
  return;
98
108
  answered.current = check;
99
109
  // Resolutions are cached, so an unchanged one keeps this state and renders nothing new.
100
- setFound((previous) => previous?.key === key && previous.resolution === resolution
110
+ setFound((previous) => previous?.key === key &&
111
+ previous.revision === resolvedAt &&
112
+ previous.resolution === resolution
101
113
  ? previous
102
- : { key, resolution });
114
+ : { key, revision: resolvedAt, resolution });
103
115
  })();
104
116
  }, [key, revision, enabled, groupCheck]);
105
117
  if (!enabled)
@@ -112,13 +124,12 @@ function usePiece(handle, options = {}) {
112
124
  const { status: _status, dataContextId: _dc, ...unavailable } = resolution;
113
125
  return { status: "unavailable", ...unavailable };
114
126
  }
115
- const PieceSizeContext = (0, react_1.createContext)({ width: 0, height: 0 });
116
127
  /**
117
128
  * The size of the box this piece draws in, for a piece that adapts to its box rather than the
118
129
  * window: window breakpoints give the wrong answer inside a panel. Zero until measured.
119
130
  */
120
131
  function usePieceSize() {
121
- return (0, react_1.useContext)(PieceSizeContext);
132
+ return (0, react_1.useContext)(piece_height_1.PieceSizeContext);
122
133
  }
123
134
  /** How deep pieces can be drawn inside pieces. */
124
135
  const MAX_PIECE_DEPTH = 4;
@@ -173,7 +184,7 @@ function Piece(props) {
173
184
  const closeRef = (0, react_1.useRef)(props.onClose);
174
185
  closeRef.current = props.onClose;
175
186
  const emit = (0, react_1.useMemo)(() => (available ? emitters(available.piece, onRef) : undefined), [available?.piece]);
176
- const checked = (0, react_1.useMemo)(() => (available ? checkProps(props.props, available.piece) : undefined), [available?.piece, props.props, attempt]);
187
+ const checked = (0, react_1.useMemo)(() => (available ? (0, piece_props_1.checkPieceProps)(props.props, available.piece) : undefined), [available?.piece, props.props, attempt]);
177
188
  if (isPopover && !props.open)
178
189
  return null;
179
190
  const retry = () => setAttempt((value) => value + 1);
@@ -216,36 +227,10 @@ function Piece(props) {
216
227
  const Component = current.component;
217
228
  const body = ((0, jsx_runtime_1.jsx)(PieceErrorBoundary, { resetKey: Component, name: props.of.name, onRetry: retry, render: (value) => unavailable(value, true), children: (0, jsx_runtime_1.jsx)(PieceAncestry.Provider, { value: inside, children: (0, jsx_runtime_1.jsx)(Component, { props: checked?.value ?? {}, emit: emit ?? {}, close: () => closeRef.current?.(), groupId: available.dataContextId }) }) }, attempt));
218
229
  if (isPopover) {
219
- return ((0, jsx_runtime_1.jsx)(popover_surface_1.PopoverSurface, { anchor: props.anchor, label: props.label, onClose: () => closeRef.current?.(), children: body }));
230
+ return ((0, jsx_runtime_1.jsx)(popover_surface_1.PopoverSurface, { anchor: props.anchor, label: props.label, onClose: () => closeRef.current?.(), children: (0, jsx_runtime_1.jsx)(piece_height_1.PieceHeightContext.Provider, { value: "content", children: body }) }));
220
231
  }
221
232
  return ((0, jsx_runtime_1.jsx)(PieceBox, { label: props.label, height: props.height ?? "fill", contractId: props.of.contractId, name: props.of.name, children: body }));
222
233
  }
223
- /** Props as a piece gets them: a plain-data copy, checked against the declared props. */
224
- function checkProps(value, piece) {
225
- let snapshot;
226
- try {
227
- snapshot = (0, peers_sdk_1.snapshotPackageValue)(value ?? {});
228
- }
229
- catch (error) {
230
- return {
231
- error: `Props must be plain data (ids, options, short text): ${error instanceof Error ? error.message : String(error)}`,
232
- };
233
- }
234
- if (!snapshot || typeof snapshot !== "object" || Array.isArray(snapshot)) {
235
- return { error: "Props must be an object" };
236
- }
237
- // Every shape the declaration gives, nested fields and allowed values included: the embedder
238
- // was built against this version, so a misfit is its mistake.
239
- const parsed = (0, peers_sdk_1.fieldsToShapeSchema)(piece.propsFields).passthrough().safeParse(snapshot);
240
- if (!parsed.success) {
241
- return {
242
- error: `Props don't fit piece "${piece.name}": ${parsed.error.issues
243
- .map((issue) => `${issue.path.join(".") || "props"} ${issue.message}`)
244
- .join("; ")}`,
245
- };
246
- }
247
- return { value: parsed.data };
248
- }
249
234
  /**
250
235
  * The emit functions a piece's component gets: each declared emit, checked against its payload
251
236
  * fields and passed to the embedder's handler; `open`, which the host handles unless the
@@ -311,7 +296,7 @@ function PieceBox(props) {
311
296
  flexDirection: "column",
312
297
  overflow: "auto",
313
298
  }
314
- : undefined, children: (0, jsx_runtime_1.jsx)(PieceSizeContext.Provider, { value: size, children: props.children }) }));
299
+ : undefined, children: (0, jsx_runtime_1.jsx)(piece_height_1.PieceHeightContext.Provider, { value: props.height, children: (0, jsx_runtime_1.jsx)(piece_height_1.PieceSizeContext.Provider, { value: size, children: props.children }) }) }));
315
300
  }
316
301
  /** The embedder's loading placeholder. */
317
302
  function PieceLoading({ render }) {
@@ -3,10 +3,24 @@ import type React from "react";
3
3
  export type PopoverAnchor = HTMLElement | null | undefined | {
4
4
  readonly current: HTMLElement | null;
5
5
  } | Pick<DOMRect, "top" | "left" | "bottom" | "right" | "width" | "height">;
6
+ /**
7
+ * A pointer went down in another frame: a package's frame, or the host's window. A click inside
8
+ * a frame never reaches the document around it, so the host relays one as this event, dispatched
9
+ * where the click was as far as this document can tell (the frame's element, a piece's slot, or
10
+ * the body). A surface treats it as it treats `mousedown`.
11
+ */
12
+ export declare const FRAME_POINTER_EVENT = "peers-frame-pointerdown";
13
+ /**
14
+ * Whether this is drawn inside a popover surface. A piece drawn in a frame of its own reads it
15
+ * to take its content's width, since a surface is as wide as what's in it.
16
+ */
17
+ export declare function useInsidePopoverSurface(): boolean;
6
18
  /**
7
19
  * A surface that floats above every screen, placed below its anchor (above it when there's no
8
20
  * room) and kept inside the window. While open it holds the keyboard: focus moves into it, Tab
9
21
  * stays in it, Escape or a click outside closes it, and focus goes back to the anchor after.
22
+ * Escape and clicks inside a piece's frame reach it too: the host relays them
23
+ * ({@link FRAME_POINTER_EVENT}, and Escape as a `keydown` on the piece's frame or slot).
10
24
  *
11
25
  * @param props.anchor - Where it opens from.
12
26
  * @param props.onClose - Called on Escape or a click outside.
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FRAME_POINTER_EVENT = void 0;
4
+ exports.useInsidePopoverSurface = useInsidePopoverSurface;
3
5
  exports.PopoverSurface = PopoverSurface;
4
6
  const jsx_runtime_1 = require("react/jsx-runtime");
5
7
  const react_1 = require("react");
@@ -33,6 +35,20 @@ function tabStops(surface) {
33
35
  }
34
36
  /** The surface a popover is opened from, when a piece in one opens it. */
35
37
  const ParentSurface = (0, react_1.createContext)(undefined);
38
+ /**
39
+ * A pointer went down in another frame: a package's frame, or the host's window. A click inside
40
+ * a frame never reaches the document around it, so the host relays one as this event, dispatched
41
+ * where the click was as far as this document can tell (the frame's element, a piece's slot, or
42
+ * the body). A surface treats it as it treats `mousedown`.
43
+ */
44
+ exports.FRAME_POINTER_EVENT = "peers-frame-pointerdown";
45
+ /**
46
+ * Whether this is drawn inside a popover surface. A piece drawn in a frame of its own reads it
47
+ * to take its content's width, since a surface is as wide as what's in it.
48
+ */
49
+ function useInsidePopoverSurface() {
50
+ return (0, react_1.useContext)(ParentSurface) !== undefined;
51
+ }
36
52
  /**
37
53
  * Whether `target` is in a popover opened from `box`, directly or through others: a click there
38
54
  * isn't outside `box`. Each surface names the one it was opened from.
@@ -55,6 +71,8 @@ function inOpenedSurface(box, target) {
55
71
  * A surface that floats above every screen, placed below its anchor (above it when there's no
56
72
  * room) and kept inside the window. While open it holds the keyboard: focus moves into it, Tab
57
73
  * stays in it, Escape or a click outside closes it, and focus goes back to the anchor after.
74
+ * Escape and clicks inside a piece's frame reach it too: the host relays them
75
+ * ({@link FRAME_POINTER_EVENT}, and Escape as a `keydown` on the piece's frame or slot).
58
76
  *
59
77
  * @param props.anchor - Where it opens from.
60
78
  * @param props.onClose - Called on Escape or a click outside.
@@ -106,18 +124,29 @@ function PopoverSurface(props) {
106
124
  const box = surface.current;
107
125
  const first = box ? tabStops(box)[0] : undefined;
108
126
  (first ?? box)?.focus();
127
+ let outsideRelay = false;
109
128
  const onPointerDown = (event) => {
110
129
  const target = event.target;
111
- if (!target || box?.contains(target) || anchorElement(anchor)?.contains(target)) {
130
+ if (!target ||
131
+ box?.contains(target) ||
132
+ anchorElement(anchor)?.contains(target) ||
133
+ (box && inOpenedSurface(box, target))) {
134
+ // The embedder may have kept the surface open after an earlier outside press.
135
+ outsideRelay = false;
112
136
  return;
113
137
  }
114
- if (box && inOpenedSurface(box, target))
115
- return;
138
+ outsideRelay = event.type === exports.FRAME_POINTER_EVENT;
116
139
  closeRef.current();
117
140
  };
118
141
  document.addEventListener("mousedown", onPointerDown, true);
142
+ document.addEventListener(exports.FRAME_POINTER_EVENT, onPointerDown, true);
119
143
  return () => {
120
144
  document.removeEventListener("mousedown", onPointerDown, true);
145
+ document.removeEventListener(exports.FRAME_POINTER_EVENT, onPointerDown, true);
146
+ // A frame's focus() can steal focus from the field the user pressed. Check when the
147
+ // surface actually closes, since the user can also return by keyboard while it stays open.
148
+ if (outsideRelay && !document.hasFocus())
149
+ return;
121
150
  // Back to where the user was, unless focus already moved somewhere else on purpose.
122
151
  if (!document.activeElement ||
123
152
  document.activeElement === document.body ||
@@ -0,0 +1,23 @@
1
+ /**
2
+ * What `peers ui click`, `set` and `scroll` do to one document. The host's window runs them, and
3
+ * so does each isolated package screen's frame for its own document (`ui-inspection/index.ts`
4
+ * sends an action to the frame its selector names).
5
+ */
6
+ import type { IUIActionResult, IUIScrollInput } from "@peers-app/peers-sdk";
7
+ type ActionResult = IUIActionResult;
8
+ /**
9
+ * Click an element by selector
10
+ */
11
+ export declare function doClick(selector: string): ActionResult;
12
+ /**
13
+ * Set text in an input element
14
+ */
15
+ export declare function doSet(selector: string, text: string, options?: {
16
+ clear?: boolean;
17
+ pressEnter?: boolean;
18
+ }): ActionResult;
19
+ /**
20
+ * Scroll the page or a specific element
21
+ */
22
+ export declare function doScroll(options: IUIScrollInput): ActionResult;
23
+ export {};
@@ -0,0 +1,169 @@
1
+ "use strict";
2
+ /**
3
+ * What `peers ui click`, `set` and `scroll` do to one document. The host's window runs them, and
4
+ * so does each isolated package screen's frame for its own document (`ui-inspection/index.ts`
5
+ * sends an action to the frame its selector names).
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.doClick = doClick;
9
+ exports.doSet = doSet;
10
+ exports.doScroll = doScroll;
11
+ /**
12
+ * Find an element by selector
13
+ */
14
+ function findElement(selector) {
15
+ try {
16
+ return document.querySelector(selector);
17
+ }
18
+ catch {
19
+ // An invalid selector matches nothing.
20
+ return null;
21
+ }
22
+ }
23
+ /**
24
+ * Click an element by selector
25
+ */
26
+ function doClick(selector) {
27
+ const element = findElement(selector);
28
+ if (!element) {
29
+ return { success: false, error: `Element not found: ${selector}` };
30
+ }
31
+ // Check if element is visible
32
+ const style = getComputedStyle(element);
33
+ if (style.display === "none" || style.visibility === "hidden") {
34
+ return { success: false, error: `Element is hidden: ${selector}` };
35
+ }
36
+ // Check if element is disabled
37
+ if (element.hasAttribute("disabled") || element.getAttribute("aria-disabled") === "true") {
38
+ return { success: false, error: `Element is disabled: ${selector}` };
39
+ }
40
+ // Scroll element into view if needed
41
+ element.scrollIntoView({ behavior: "instant", block: "center" });
42
+ // Focus the element first (for accessibility)
43
+ element.focus();
44
+ // Dispatch click event
45
+ element.click();
46
+ return { success: true };
47
+ }
48
+ /**
49
+ * Write an input's value through the element type's own `value` setter, as typing does. React
50
+ * tracks a controlled input's value by wrapping the element's setter, so assigning `el.value`
51
+ * directly records the new text as already seen and the `input` event then calls no `onChange`.
52
+ */
53
+ function setNativeValue(element, value) {
54
+ const prototype = element instanceof HTMLTextAreaElement
55
+ ? HTMLTextAreaElement.prototype
56
+ : HTMLInputElement.prototype;
57
+ const setter = Object.getOwnPropertyDescriptor(prototype, "value")?.set;
58
+ if (setter) {
59
+ setter.call(element, value);
60
+ }
61
+ else {
62
+ element.value = value;
63
+ }
64
+ }
65
+ /**
66
+ * Set text in an input element
67
+ */
68
+ function doSet(selector, text, options) {
69
+ const element = findElement(selector);
70
+ if (!element) {
71
+ return { success: false, error: `Element not found: ${selector}` };
72
+ }
73
+ // Check if it's an input-like element
74
+ const isInput = element instanceof HTMLInputElement ||
75
+ element instanceof HTMLTextAreaElement ||
76
+ element.isContentEditable;
77
+ if (!isInput) {
78
+ return { success: false, error: `Element is not an input: ${selector}` };
79
+ }
80
+ // Check if element is disabled
81
+ if (element.hasAttribute("disabled") || element.getAttribute("aria-disabled") === "true") {
82
+ return { success: false, error: `Element is disabled: ${selector}` };
83
+ }
84
+ // Scroll into view and focus
85
+ element.scrollIntoView({ behavior: "instant", block: "center" });
86
+ element.focus();
87
+ // Handle contentEditable elements differently
88
+ if (element.isContentEditable) {
89
+ if (options?.clear) {
90
+ element.textContent = "";
91
+ }
92
+ // Insert text at cursor or append
93
+ // execCommand triggers its own input events, so we don't need to dispatch separately
94
+ document.execCommand("insertText", false, text);
95
+ }
96
+ else {
97
+ // Standard input/textarea
98
+ const inputEl = element;
99
+ // Set the value
100
+ setNativeValue(inputEl, options?.clear ? text : inputEl.value + text);
101
+ // Dispatch input event to trigger React/Vue/etc state updates
102
+ inputEl.dispatchEvent(new InputEvent("input", { bubbles: true, data: text }));
103
+ inputEl.dispatchEvent(new Event("change", { bubbles: true }));
104
+ }
105
+ // Press Enter if requested
106
+ if (options?.pressEnter) {
107
+ element.dispatchEvent(new KeyboardEvent("keydown", {
108
+ key: "Enter",
109
+ code: "Enter",
110
+ keyCode: 13,
111
+ bubbles: true,
112
+ }));
113
+ element.dispatchEvent(new KeyboardEvent("keypress", {
114
+ key: "Enter",
115
+ code: "Enter",
116
+ keyCode: 13,
117
+ bubbles: true,
118
+ }));
119
+ element.dispatchEvent(new KeyboardEvent("keyup", {
120
+ key: "Enter",
121
+ code: "Enter",
122
+ keyCode: 13,
123
+ bubbles: true,
124
+ }));
125
+ }
126
+ return { success: true };
127
+ }
128
+ /**
129
+ * Scroll the page or a specific element
130
+ */
131
+ function doScroll(options) {
132
+ const { selector, x, y, direction, amount = 300 } = options;
133
+ // Determine scroll target
134
+ let target = window;
135
+ if (selector) {
136
+ const element = findElement(selector);
137
+ if (!element) {
138
+ return { success: false, error: `Element not found: ${selector}` };
139
+ }
140
+ target = element;
141
+ }
142
+ // Calculate scroll position
143
+ let scrollX = x ?? 0;
144
+ let scrollY = y ?? 0;
145
+ if (direction) {
146
+ switch (direction) {
147
+ case "up":
148
+ scrollY = -amount;
149
+ break;
150
+ case "down":
151
+ scrollY = amount;
152
+ break;
153
+ case "left":
154
+ scrollX = -amount;
155
+ break;
156
+ case "right":
157
+ scrollX = amount;
158
+ break;
159
+ }
160
+ }
161
+ // Perform scroll
162
+ if (target === window) {
163
+ window.scrollBy({ left: scrollX, top: scrollY, behavior: "smooth" });
164
+ }
165
+ else {
166
+ target.scrollBy({ left: scrollX, top: scrollY, behavior: "smooth" });
167
+ }
168
+ return { success: true };
169
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * What `peers ui inspect` reads of one document: its visible text and interactive elements. The
3
+ * host's window runs it, and so does each isolated package screen's frame for its own document
4
+ * (`ui-inspection/index.ts` merges them).
5
+ */
6
+ import type { IUIState } from "@peers-app/peers-sdk";
7
+ /**
8
+ * Check if an element or any of its ancestors is hidden
9
+ * This handles cases where a parent container has display:none (like inactive tabs)
10
+ */
11
+ export declare function isElementHidden(el: Element | null): boolean;
12
+ /**
13
+ * Read this document's UI state for `peers ui inspect`: its route, visible text and interactive
14
+ * elements. It doesn't look inside frames; `inspectUI` does that.
15
+ *
16
+ * @param options.includeRects - Include each element's rectangle, in this window's coordinates.
17
+ */
18
+ export declare function getDocumentUIState(options?: {
19
+ includeRects?: boolean;
20
+ }): IUIState;