@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
@@ -0,0 +1,152 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createFramePvarService = createFramePvarService;
4
+ const peers_sdk_1 = require("@peers-app/peers-sdk");
5
+ const lodash_1 = require("lodash");
6
+ /**
7
+ * The host side of an isolated screen's persistent variables.
8
+ *
9
+ * A screen's frame asks the host for every variable its code (and peers-ui's, inside the frame)
10
+ * declares. The host answers in one of three ways:
11
+ *
12
+ * - `mainContentPath` is the screen's tab path; writing it navigates the tab.
13
+ * - A few variables Peers keeps for every screen (this device, the active group, the theme, the
14
+ * open tabs) are the host's own, read only. A write is ignored, and the frame is told the
15
+ * host's value again.
16
+ * - Every other variable is the package's own, stored under the package's id
17
+ * (`<packageId>_<name>`), as a variable its worker declares is. A name that already starts
18
+ * with the package's id is used as it is.
19
+ *
20
+ * Secret variables aren't served to screens.
21
+ */
22
+ /** Host variables every screen reads, and none writes. */
23
+ const HOST_READ_ONLY_PVARS = new Map([
24
+ ["thisDeviceId", "device"],
25
+ ["currentlyActiveGroupId", "device"],
26
+ ["colorMode", "device"],
27
+ ["colorModePreference", "device"],
28
+ ["activeTabs", "groupDevice"],
29
+ ["activeTabId", "groupDevice"],
30
+ ["tabHistory", "groupDevice"],
31
+ ]);
32
+ /** The variable that is the screen's tab path. */
33
+ const TAB_PATH_PVAR = "mainContentPath";
34
+ function makeVar(scope, name, defaultValue, dataContext) {
35
+ const opts = {
36
+ ...(defaultValue !== undefined ? { defaultValue } : {}),
37
+ ...(dataContext ? { dataContext } : {}),
38
+ };
39
+ switch (scope) {
40
+ case "device":
41
+ return (0, peers_sdk_1.deviceVar)(name, opts);
42
+ case "user":
43
+ return (0, peers_sdk_1.userVar)(name, opts);
44
+ case "group":
45
+ return (0, peers_sdk_1.groupVar)(name, opts);
46
+ case "groupDevice":
47
+ return (0, peers_sdk_1.groupDeviceVar)(name, opts);
48
+ case "groupUser":
49
+ return (0, peers_sdk_1.groupUserVar)(name, opts);
50
+ }
51
+ }
52
+ async function pinnedDataContext(dataContextId) {
53
+ if (!dataContextId)
54
+ return undefined;
55
+ const userContext = await (0, peers_sdk_1.getUserContext)();
56
+ if (dataContextId !== userContext.userId && !userContext.groupIds().includes(dataContextId)) {
57
+ throw new Error(`Permission denied: data context '${dataContextId}' is not available here`);
58
+ }
59
+ return userContext.getDataContext(dataContextId);
60
+ }
61
+ /**
62
+ * Serve one isolated screen's persistent variables.
63
+ *
64
+ * @param host - The screen's package, tab path and channel.
65
+ */
66
+ function createFramePvarService(host) {
67
+ const bindings = new Map();
68
+ // A bind still loading when the screen closes must not start following its variable after.
69
+ let disposed = false;
70
+ const bindTabPath = (bindingId) => {
71
+ if (disposed)
72
+ return undefined;
73
+ const subscription = host.tabPath.subscribe((path) => host.changed(bindingId, path));
74
+ bindings.set(bindingId, {
75
+ write: async (value) => {
76
+ if (typeof value === "string" && value !== host.tabPath())
77
+ host.navigate(value);
78
+ },
79
+ delete: async () => undefined,
80
+ stop: () => subscription.dispose(),
81
+ });
82
+ return host.tabPath();
83
+ };
84
+ const bindVar = async (bindingId, variable, readOnly) => {
85
+ await variable.loadingPromise;
86
+ if (disposed)
87
+ return undefined;
88
+ const subscription = variable.subscribe((value) => host.changed(bindingId, value));
89
+ bindings.set(bindingId, {
90
+ write: async (value) => {
91
+ if (readOnly) {
92
+ // The host's own: the frame goes back to the host's value.
93
+ if (!(0, lodash_1.isEqual)(value, variable()))
94
+ host.changed(bindingId, variable());
95
+ return;
96
+ }
97
+ variable(value);
98
+ await variable.loadingPromise;
99
+ },
100
+ delete: async () => {
101
+ if (!readOnly)
102
+ await variable.delete();
103
+ },
104
+ stop: () => subscription.dispose(),
105
+ });
106
+ return variable();
107
+ };
108
+ return {
109
+ async bind({ bindingId, request }) {
110
+ bindings.get(bindingId)?.stop();
111
+ const { name, scope } = request;
112
+ if (request.isSecret) {
113
+ throw new Error(`Permission denied: screens can't use secret variables (${name})`);
114
+ }
115
+ if (name === TAB_PATH_PVAR)
116
+ return bindTabPath(bindingId);
117
+ const dataContext = await pinnedDataContext(request.dataContextId);
118
+ if (disposed)
119
+ return undefined;
120
+ const hostScope = HOST_READ_ONLY_PVARS.get(name);
121
+ if (hostScope) {
122
+ // The SDK migrates stored rows on a scope mismatch, even for a caller that only reads.
123
+ if (scope !== hostScope) {
124
+ throw new Error(`Permission denied: ${name} is a ${hostScope} variable`);
125
+ }
126
+ return bindVar(bindingId, makeVar(hostScope, name, undefined, dataContext), true);
127
+ }
128
+ const stored = name.startsWith(`${host.packageId}_`)
129
+ ? name
130
+ : (0, peers_sdk_1.packageScopedPersistentVarName)(host.packageId, name);
131
+ return bindVar(bindingId, makeVar(scope, stored, request.defaultValue, dataContext), false);
132
+ },
133
+ async write({ bindingId, value }) {
134
+ const binding = bindings.get(bindingId);
135
+ if (!binding)
136
+ throw new Error("That variable isn't bound");
137
+ await binding.write(value);
138
+ },
139
+ async delete({ bindingId }) {
140
+ const binding = bindings.get(bindingId);
141
+ if (!binding)
142
+ throw new Error("That variable isn't bound");
143
+ await binding.delete();
144
+ },
145
+ dispose() {
146
+ disposed = true;
147
+ for (const binding of bindings.values())
148
+ binding.stop();
149
+ bindings.clear();
150
+ },
151
+ };
152
+ }
@@ -0,0 +1,12 @@
1
+ import type { IPortChannel } from "./port-channel";
2
+ /** The channel to the host, inside a package screen's frame; `undefined` in the host's window. */
3
+ export declare function frameHost(): IPortChannel | undefined;
4
+ /** Whether this realm is a package screen's frame. */
5
+ export declare function isInFrame(): boolean;
6
+ /**
7
+ * Mark this realm as a package screen's frame. Only the frame bridge calls it, once, before any
8
+ * package code runs.
9
+ *
10
+ * @param hostChannel - The channel to the host, or `undefined` to clear it (tests).
11
+ */
12
+ export declare function setFrameHost(hostChannel: IPortChannel | undefined): void;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.frameHost = frameHost;
4
+ exports.isInFrame = isInFrame;
5
+ exports.setFrameHost = setFrameHost;
6
+ /**
7
+ * Whether this realm is an isolated package screen's frame, and its channel to the host.
8
+ *
9
+ * peers-ui runs in two kinds of realm: the host's window, which draws the shell and owns the tabs,
10
+ * and each package screen's frame. A few of its functions do something different in a frame:
11
+ * navigation, tab titles, opening links and mentions ask the host instead of changing host state
12
+ * the frame can't reach. They call {@link frameHost} to tell which realm they're in.
13
+ */
14
+ let channel;
15
+ /** The channel to the host, inside a package screen's frame; `undefined` in the host's window. */
16
+ function frameHost() {
17
+ return channel;
18
+ }
19
+ /** Whether this realm is a package screen's frame. */
20
+ function isInFrame() {
21
+ return channel !== undefined;
22
+ }
23
+ /**
24
+ * Mark this realm as a package screen's frame. Only the frame bridge calls it, once, before any
25
+ * package code runs.
26
+ *
27
+ * @param hostChannel - The channel to the host, or `undefined` to clear it (tests).
28
+ */
29
+ function setFrameHost(hostChannel) {
30
+ channel = hostChannel;
31
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Start the frame runtime. The frame's entry calls it once, after the bridge is installed and
3
+ * the window's `React`, `PeersSDK`, `PeersUI` and `zod` globals are set.
4
+ */
5
+ export declare function startFrameRuntime(): void;