@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
@@ -45,6 +45,9 @@ const hooks_1 = require("../hooks");
45
45
  const package_waiting_1 = require("../screens/packages/package-waiting");
46
46
  const packages_ipc_1 = require("../screens/packages/packages-ipc");
47
47
  require("../ui-defaults");
48
+ const config_1 = require("../isolated-screens/config");
49
+ const frame_realm_1 = require("../isolated-screens/frame-realm");
50
+ const isolated_screen_1 = require("../isolated-screens/isolated-screen");
48
51
  const piece_host_1 = require("../ui-contracts/piece-host");
49
52
  const bundle_files_1 = require("./bundle-files");
50
53
  const find_route_1 = require("./find-route");
@@ -119,7 +122,7 @@ const UIRouter = (props) => {
119
122
  if (!matchingRoute) {
120
123
  return undefined;
121
124
  }
122
- return ((0, jsx_runtime_1.jsx)(UILoader, { peersUIId: matchingRoute.peersUIId, props: props.props, screen: context.uiCategory === "screen" }));
125
+ return ((0, jsx_runtime_1.jsx)(UILoader, { peersUIId: matchingRoute.peersUIId, props: props.props, screen: context.uiCategory === "screen", path: props.tabPath ?? context.path }));
123
126
  };
124
127
  exports.UIRouter = UIRouter;
125
128
  /**
@@ -136,8 +139,25 @@ const UILoader = (args) => {
136
139
  const props = { ...args.props, __lastPackageReload: lastReloadTime };
137
140
  // Keep the same loader ancestor after the bundle enters the cache. Replacing it
138
141
  // on a path change would unmount the screen before its navigation guard can run.
139
- return (0, jsx_runtime_1.jsx)(UIAsyncLoader, { peersUIId: peersUIId, props: props, screen: args.screen }, peersUIId);
142
+ return ((0, jsx_runtime_1.jsx)(UIAsyncLoader, { peersUIId: peersUIId, props: props, screen: args.screen, path: args.path }, peersUIId));
140
143
  };
144
+ /**
145
+ * The package that owns a UI id, from the registered routes. Two packages registering one id
146
+ * (UI ids are random, so only on purpose) is refused rather than resolved, so a package can't
147
+ * take over another's UI by registering its id.
148
+ *
149
+ * @returns The owner, or the packages that claim it when more than one does.
150
+ */
151
+ function uiOwner(routes, peersUIId) {
152
+ const owners = [
153
+ ...new Set(routes.filter((r) => r.peersUIId === peersUIId).map((r) => r.packageId)),
154
+ ];
155
+ if (owners.length > 1) {
156
+ console.error(`UI ${peersUIId} is registered by more than one package: ${owners.join(", ")}`);
157
+ return { claimedBy: owners };
158
+ }
159
+ return { packageId: owners[0] };
160
+ }
141
161
  /** Each package's latest UI bundle load, by package id. */
142
162
  const uiLoads = {};
143
163
  /**
@@ -157,7 +177,12 @@ async function readUIBundle(pkg, servingPackageVersionId) {
157
177
  (0, peers_sdk_1.assertPackageBundleIntegrity)(selected.pv, "ui", bundleCode);
158
178
  }
159
179
  return bundleCode
160
- ? { code: bundleCode, packageVersionId: selected.pv.packageVersionId, uiBundleFileId }
180
+ ? {
181
+ code: bundleCode,
182
+ packageVersionId: selected.pv.packageVersionId,
183
+ uiBundleFileId,
184
+ dataContextId: selected.dataContext.dataContextId,
185
+ }
161
186
  : undefined;
162
187
  }
163
188
  /**
@@ -217,7 +242,8 @@ const UIAsyncLoader = (props) => {
217
242
  const [loaded, setLoaded] = (0, react_1.useState)();
218
243
  const [loadError, setLoadError] = react_1.default.useState(null);
219
244
  const allRoutes = _window.getPeersUIRoutes();
220
- const uiPackageId = allRoutes.find((r) => r.peersUIId === peersUIId)?.packageId;
245
+ const owner = uiOwner(allRoutes, peersUIId);
246
+ const uiPackageId = owner.packageId;
221
247
  (0, hooks_1.useObservable)(routes_loader_1.allPackages);
222
248
  const pkg = (0, routes_loader_1.allPackages)().find((p) => p.packageId === uiPackageId);
223
249
  // A screen of a package that waits for a contract it requires shows why, and runs none of the
@@ -229,12 +255,16 @@ const UIAsyncLoader = (props) => {
229
255
  const gate = (0, packages_ipc_1.usePackageScreenGate)(pkg?.packageId);
230
256
  const waiting = !!gate.missing;
231
257
  const serving = gate.servingPackageVersionId;
258
+ // A package screen runs in a frame of its own, and its bundle never runs in this window.
259
+ const isolated = !!props.screen && (0, config_1.runsIsolated)(pkg?.packageId);
232
260
  const read = (0, react_1.useRef)();
233
261
  (0, react_1.useEffect)(() => {
234
262
  // A read made before the package was known to wait is dropped: by the time it starts, its
235
263
  // selected version or its synced bundle may have changed.
236
264
  if (waiting)
237
265
  read.current = undefined;
266
+ if (isolated)
267
+ return;
238
268
  if (!pkg || peersUIs[peersUIId]?.content || pkg.packageId in uiLoads || waiting)
239
269
  return;
240
270
  if (read.current?.packageId === pkg.packageId && read.current.serving === serving)
@@ -243,9 +273,9 @@ const UIAsyncLoader = (props) => {
243
273
  // A failed read is reported when the bundle is loaded, if it ever is.
244
274
  bundle.catch(() => undefined);
245
275
  read.current = { packageId: pkg.packageId, serving, bundle };
246
- }, [peersUIId, pkg, waiting, serving]);
276
+ }, [peersUIId, pkg, waiting, serving, isolated]);
247
277
  (0, react_1.useEffect)(() => {
248
- if (!pkg || !gate.ready || waiting)
278
+ if (!pkg || !gate.ready || waiting || isolated)
249
279
  return;
250
280
  // UI on hand is kept when it's this version's: loaded for it, or built in.
251
281
  const current = uiLoads[pkg.packageId];
@@ -266,10 +296,16 @@ const UIAsyncLoader = (props) => {
266
296
  console.error(`Failed to load UI bundle for package ${pkgRef.name}:`, error);
267
297
  setLoadError(error);
268
298
  });
269
- }, [peersUIId, pkg?.packageId, pkg?.name, pkg, gate.ready, waiting, serving]);
299
+ }, [peersUIId, pkg?.packageId, pkg?.name, pkg, gate.ready, waiting, serving, isolated]);
270
300
  if (pkg && gate.missing) {
271
301
  return props.screen ? ((0, jsx_runtime_1.jsx)(package_waiting_1.PackageWaitingScreen, { packageId: pkg.packageId, missing: gate.missing })) : ((0, jsx_runtime_1.jsx)(package_waiting_1.PackageWaitingNotice, { packageId: pkg.packageId, missing: gate.missing }));
272
302
  }
303
+ if (isolated && pkg) {
304
+ return gate.ready ? ((0, jsx_runtime_1.jsx)(IsolatedScreenLoader, { pkg: pkg, serving: serving, peersUIId: peersUIId, props: props.props, path: props.path ?? "" }, pkg.packageId)) : ((0, jsx_runtime_1.jsx)(loading_indicator_1.LoadingIndicator, {}));
305
+ }
306
+ if (owner.claimedBy) {
307
+ return ((0, jsx_runtime_1.jsxs)("div", { className: "text-danger small", children: ["More than one package registers the UI ", peersUIId, ", so none of them is shown."] }));
308
+ }
273
309
  if (!peersUI?.content && !pkg) {
274
310
  return (0, jsx_runtime_1.jsxs)("div", { children: ["Could not find package that owns peersUIId ", peersUIId] });
275
311
  }
@@ -341,6 +377,41 @@ const UIAsyncLoader = (props) => {
341
377
  return (0, jsx_runtime_1.jsx)("div", { children: "Component not found" });
342
378
  }
343
379
  };
380
+ /**
381
+ * Read a package screen's UI bundle and show it in a frame of its own. It reads the bundle again
382
+ * when the package's row changes (a new version, a reload). A new version, file or data context
383
+ * gets a new frame.
384
+ */
385
+ function IsolatedScreenLoader(props) {
386
+ const { pkg, serving } = props;
387
+ const [read, setRead] = (0, react_1.useState)();
388
+ // Retry reads the bundle again, as a newly paired device may not have it synced yet.
389
+ const [attempt, setAttempt] = (0, react_1.useState)(0);
390
+ (0, react_1.useEffect)(() => {
391
+ let cancelled = false;
392
+ readUIBundle(pkg, serving).then((bundle) => {
393
+ if (!cancelled)
394
+ setRead(bundle ?? new Error(`${pkg.name} has no UI bundle`));
395
+ }, (error) => {
396
+ if (!cancelled)
397
+ setRead(error instanceof Error ? error : new Error(String(error)));
398
+ });
399
+ return () => {
400
+ cancelled = true;
401
+ };
402
+ }, [pkg, serving, attempt]);
403
+ if (!read)
404
+ return (0, jsx_runtime_1.jsx)(loading_indicator_1.LoadingIndicator, {});
405
+ if (read instanceof Error) {
406
+ return ((0, jsx_runtime_1.jsx)("div", { className: "p-3", children: (0, jsx_runtime_1.jsxs)("div", { className: "alert alert-danger", children: [(0, jsx_runtime_1.jsxs)("div", { className: "fw-semibold", children: [pkg.name, "'s screen couldn't load."] }), (0, jsx_runtime_1.jsx)("div", { className: "small text-break", children: read.message }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-sm btn-outline-danger mt-2", onClick: () => {
407
+ setRead(undefined);
408
+ setAttempt((value) => value + 1);
409
+ }, children: "Retry" })] }) }));
410
+ }
411
+ // Data only: the loader's own reload marker stays behind.
412
+ const { __lastPackageReload: _reload, ...screenProps } = props.props;
413
+ return ((0, jsx_runtime_1.jsx)(isolated_screen_1.IsolatedScreen, { pkg: pkg, bundle: read, peersUIId: props.peersUIId, props: screenProps, path: props.path }, `${read.packageVersionId}:${read.uiBundleFileId}:${read.dataContextId}`));
414
+ }
344
415
  let _window;
345
416
  if (typeof window !== "undefined") {
346
417
  _window = window;
@@ -348,7 +419,9 @@ if (typeof window !== "undefined") {
348
419
  let uiRoutes = [];
349
420
  Object.defineProperty(window, "registerPeersUIRoute", {
350
421
  value: (route) => {
351
- uiRoutes = uiRoutes.filter((r) => !(r.peersUIId === route.peersUIId));
422
+ // A package replaces only its own route for a UI id. Another package registering the same
423
+ // id doesn't take it over: `uiOwner` then refuses the id for embedding by id.
424
+ uiRoutes = uiRoutes.filter((r) => !(r.peersUIId === route.peersUIId && r.packageId === route.packageId));
352
425
  uiRoutes.push(route);
353
426
  uiRoutes = (0, lodash_1.orderBy)(uiRoutes, (r) => r.priority ?? 0, "desc");
354
427
  },
@@ -374,8 +447,8 @@ if (typeof window !== "undefined") {
374
447
  });
375
448
  }
376
449
  }
377
- /** Package id used when peers-ui registers its own built-in screens. */
378
- exports.peersSystemPackageId = "000peers0system000package";
450
+ /** Package id used when peers-ui registers its own built-in screens. No installed package may use it. */
451
+ exports.peersSystemPackageId = find_route_1.SYSTEM_PACKAGE_ID;
379
452
  /**
380
453
  * This is meant to make it easy to register components that are internal to peers
381
454
  */
@@ -422,20 +495,23 @@ function subscribeToPrefs(packageId) {
422
495
  uiPrefsSubscribed.add(packageId);
423
496
  (0, runnable_version_1.onDeviceSelectionChanged)(packageId, () => reloadPackage(packageId));
424
497
  }
425
- (0, peers_sdk_1.getUserContext)().then((_userContext) => {
426
- for (const packageId of Object.keys(uiLoads)) {
427
- subscribeToPrefs(packageId);
428
- }
429
- (0, peers_sdk_1.Packages)().dataChanged.subscribe(async (evt) => {
430
- const pkg = evt.dataObject;
431
- if (!(pkg.packageId in uiLoads))
432
- return;
433
- subscribeToPrefs(pkg.packageId);
434
- reloadPackage(pkg.packageId);
435
- });
436
- // A promotion changes only the selected version's row, and can let a refused screen load.
437
- (0, runnable_version_1.onSelectedPackageVersionChanged)((packageId) => {
438
- if (packageId in uiLoads)
439
- reloadPackage(packageId);
498
+ // The window owns bundle reloads. Each frame receives the selected bundle from that window.
499
+ if (!(0, frame_realm_1.isInFrame)()) {
500
+ (0, peers_sdk_1.getUserContext)().then(() => {
501
+ for (const packageId of Object.keys(uiLoads)) {
502
+ subscribeToPrefs(packageId);
503
+ }
504
+ (0, peers_sdk_1.Packages)().dataChanged.subscribe(async (evt) => {
505
+ const pkg = evt.dataObject;
506
+ if (!(pkg.packageId in uiLoads))
507
+ return;
508
+ subscribeToPrefs(pkg.packageId);
509
+ reloadPackage(pkg.packageId);
510
+ });
511
+ // A promotion changes only the selected version's row, and can let a refused screen load.
512
+ (0, runnable_version_1.onSelectedPackageVersionChanged)((packageId) => {
513
+ if (packageId in uiLoads)
514
+ reloadPackage(packageId);
515
+ });
440
516
  });
441
- });
517
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peers-app/peers-ui",
3
- "version": "0.33.24",
3
+ "version": "0.34.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/peers-app/peers-ui.git"
@@ -36,7 +36,7 @@
36
36
  "lint:fix": "biome check --write ."
37
37
  },
38
38
  "peerDependencies": {
39
- "@peers-app/peers-sdk": "^0.33.24",
39
+ "@peers-app/peers-sdk": "^0.34.1",
40
40
  "bootstrap": "^5.3.3",
41
41
  "react": "^18.0.0",
42
42
  "react-dom": "^18.0.0"
@@ -47,7 +47,7 @@
47
47
  "@babel/preset-react": "^7.24.1",
48
48
  "@babel/preset-typescript": "^7.27.1",
49
49
  "@biomejs/biome": "2.3.11",
50
- "@peers-app/peers-sdk": "0.33.24",
50
+ "@peers-app/peers-sdk": "0.34.1",
51
51
  "@testing-library/dom": "^10.4.0",
52
52
  "@testing-library/jest-dom": "^6.6.3",
53
53
  "@testing-library/react": "^16.3.0",