@peers-app/peers-ui 0.33.24 → 0.34.0

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 (106) 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 +26 -0
  16. package/dist/isolated-screens/frame-document.js +69 -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 +185 -0
  20. package/dist/isolated-screens/frame-protocol.js +139 -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 +416 -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 +191 -0
  32. package/dist/isolated-screens/isolated-screen.js +684 -0
  33. package/dist/isolated-screens/piece-frames.d.ts +27 -0
  34. package/dist/isolated-screens/piece-frames.js +311 -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/mentions/mentions-client.js +9 -0
  46. package/dist/notifications/index.js +9 -5
  47. package/dist/operator-console/console-copy.d.ts +15 -0
  48. package/dist/operator-console/console-copy.js +97 -0
  49. package/dist/operator-console/console-header.d.ts +33 -0
  50. package/dist/operator-console/console-header.js +67 -0
  51. package/dist/operator-console/console-input.d.ts +20 -0
  52. package/dist/operator-console/console-input.js +313 -0
  53. package/dist/operator-console/console-repl.d.ts +7 -0
  54. package/dist/operator-console/console-repl.js +108 -0
  55. package/dist/operator-console/console-scope.d.ts +45 -0
  56. package/dist/operator-console/console-scope.js +174 -0
  57. package/dist/operator-console/console-screen.d.ts +8 -0
  58. package/dist/operator-console/console-screen.js +32 -0
  59. package/dist/operator-console/console-session.d.ts +106 -0
  60. package/dist/operator-console/console-session.js +567 -0
  61. package/dist/operator-console/console-test-host.d.ts +21 -0
  62. package/dist/operator-console/console-test-host.js +114 -0
  63. package/dist/operator-console/console-theme.d.ts +41 -0
  64. package/dist/operator-console/console-theme.js +55 -0
  65. package/dist/operator-console/console-value.d.ts +27 -0
  66. package/dist/operator-console/console-value.js +291 -0
  67. package/dist/operator-console/operator-console-state.js +3 -1
  68. package/dist/operator-console/operator-console.d.ts +8 -21
  69. package/dist/operator-console/operator-console.js +8 -61
  70. package/dist/root-layout/app-shell-height.d.ts +16 -3
  71. package/dist/root-layout/app-shell-height.js +17 -4
  72. package/dist/root-layout/host-app-menu.d.ts +17 -0
  73. package/dist/root-layout/host-app-menu.js +22 -0
  74. package/dist/root-layout/layouts/full-screen-layout.js +4 -2
  75. package/dist/system-apps/console.app.d.ts +15 -0
  76. package/dist/system-apps/console.app.js +25 -0
  77. package/dist/system-apps/index.d.ts +1 -0
  78. package/dist/system-apps/index.js +6 -1
  79. package/dist/tabs-layout/tabs-layout.js +12 -20
  80. package/dist/tabs-layout/tabs-state.js +39 -16
  81. package/dist/theme.css +32 -5
  82. package/dist/ui-contracts/piece-height.d.ts +18 -0
  83. package/dist/ui-contracts/piece-height.js +15 -0
  84. package/dist/ui-contracts/piece-host.d.ts +24 -1
  85. package/dist/ui-contracts/piece-host.js +53 -2
  86. package/dist/ui-contracts/piece-props.d.ts +16 -0
  87. package/dist/ui-contracts/piece-props.js +39 -0
  88. package/dist/ui-contracts/piece-resolution.d.ts +5 -0
  89. package/dist/ui-contracts/piece-resolution.js +38 -2
  90. package/dist/ui-contracts/piece.d.ts +2 -7
  91. package/dist/ui-contracts/piece.js +22 -37
  92. package/dist/ui-contracts/popover-surface.d.ts +14 -0
  93. package/dist/ui-contracts/popover-surface.js +32 -3
  94. package/dist/ui-inspection/dom-actions.d.ts +23 -0
  95. package/dist/ui-inspection/dom-actions.js +169 -0
  96. package/dist/ui-inspection/dom-inspector.d.ts +20 -0
  97. package/dist/ui-inspection/dom-inspector.js +184 -0
  98. package/dist/ui-inspection/index.d.ts +73 -0
  99. package/dist/ui-inspection/index.js +147 -0
  100. package/dist/ui-router/find-route.d.ts +6 -0
  101. package/dist/ui-router/find-route.js +22 -0
  102. package/dist/ui-router/routes-loader.js +23 -4
  103. package/dist/ui-router/runnable-version.js +3 -0
  104. package/dist/ui-router/ui-loader.d.ts +6 -1
  105. package/dist/ui-router/ui-loader.js +102 -26
  106. package/package.json +3 -3
@@ -0,0 +1,313 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConsoleInput = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ /**
6
+ * The Console's input: code with completion, a grey line saying which argument the cursor is at
7
+ * (`describeTask(taskId, subtaskDepth?, …)`, with the field a value fills in bold), and history.
8
+ *
9
+ * Keys: Enter runs (and adds a line while a bracket is still open); Shift+Enter adds a line; Tab
10
+ * completes; ↑ and ↓ move through the completions when they're open, and through history on the
11
+ * first and last line; Escape closes the completions; Ctrl+L clears the output; Ctrl+C with
12
+ * nothing selected empties the input.
13
+ */
14
+ const repl_1 = require("@peers-app/peers-sdk/repl");
15
+ const react_1 = require("react");
16
+ const hooks_1 = require("../hooks");
17
+ const console_session_1 = require("./console-session");
18
+ const console_theme_1 = require("./console-theme");
19
+ /** The completion list shows this many items before it scrolls. */
20
+ const VISIBLE_ITEMS = 8;
21
+ /** The input grows to this many lines before it scrolls. */
22
+ const MAX_LINES = 12;
23
+ /** Whether a completion list is worth showing: something other than the word already typed. */
24
+ function worthShowing(code, cursor, items, from) {
25
+ const word = code.slice(from, cursor);
26
+ return items.length > 0 && !(items.length === 1 && items[0].name === word);
27
+ }
28
+ /**
29
+ * The Console's input line.
30
+ *
31
+ * @param props.context The data context's name, shown as the prompt.
32
+ * @param props.ready Whether the contracts are loaded: completion waits for them.
33
+ */
34
+ exports.ConsoleInput = (0, react_1.forwardRef)(function ConsoleInput({ context, ready }, ref) {
35
+ const theme = (0, console_theme_1.useConsoleTheme)();
36
+ const [code, setCode] = (0, hooks_1.useObservable)(console_session_1.consoleDraft);
37
+ const [completion, setCompletion] = (0, react_1.useState)();
38
+ const [hint, setHint] = (0, react_1.useState)();
39
+ const history = (0, react_1.useRef)({ draft: "" });
40
+ const input = (0, react_1.useRef)(null);
41
+ const pendingCursor = (0, react_1.useRef)();
42
+ /**
43
+ * The draft as this input last set it. A different one came from outside: "Edit it again", or
44
+ * the other surface's input (the Console app and the panel share the draft).
45
+ */
46
+ const own = (0, react_1.useRef)(code);
47
+ /** The text and cursor the hint was worked out for, so a keystroke works it out once. */
48
+ const hinted = (0, react_1.useRef)();
49
+ const setDraft = (text) => {
50
+ own.current = text;
51
+ setCode(text);
52
+ };
53
+ (0, react_1.useLayoutEffect)(() => {
54
+ if (pendingCursor.current === undefined || !input.current)
55
+ return;
56
+ input.current.setSelectionRange(pendingCursor.current, pendingCursor.current);
57
+ pendingCursor.current = undefined;
58
+ });
59
+ // The hint can change when the contracts load or the group changes.
60
+ (0, react_1.useEffect)(() => {
61
+ setCompletion(undefined);
62
+ hinted.current = undefined;
63
+ if (ready && input.current)
64
+ refreshHint(code, input.current.selectionStart);
65
+ // eslint-disable-next-line react-hooks/exhaustive-deps
66
+ }, [ready, context]);
67
+ // A draft set from outside: its hint, and, when this input has the focus ("Edit it again"
68
+ // focuses it first), the caret at its end. Focus never moves here, so typing in the other
69
+ // surface's input stays there.
70
+ (0, react_1.useEffect)(() => {
71
+ if (code === own.current)
72
+ return;
73
+ own.current = code;
74
+ history.current = { draft: "" };
75
+ setCompletion(undefined);
76
+ const element = input.current;
77
+ if (!element)
78
+ return;
79
+ if (element.ownerDocument.activeElement === element)
80
+ element.setSelectionRange(code.length, code.length);
81
+ refreshHint(code, code.length);
82
+ // eslint-disable-next-line react-hooks/exhaustive-deps
83
+ }, [code]);
84
+ const refreshHint = (text, cursor) => {
85
+ if (hinted.current?.text === text && hinted.current.cursor === cursor)
86
+ return;
87
+ hinted.current = { text, cursor };
88
+ setHint(text.trim() ? (0, repl_1.signatureAt)(console_session_1.consoleScope, text, cursor) : undefined);
89
+ };
90
+ const showCompletions = (text, cursor, explicit) => {
91
+ const found = ready ? (0, repl_1.completeAt)(console_session_1.consoleScope, text, cursor) : undefined;
92
+ if (found && worthShowing(text, cursor, found.items, found.from)) {
93
+ if (explicit && found.items.length === 1) {
94
+ accept(found.items[0], found.from, text, cursor);
95
+ return true;
96
+ }
97
+ setCompletion({ ...found, selected: 0 });
98
+ return true;
99
+ }
100
+ setCompletion(undefined);
101
+ return false;
102
+ };
103
+ const replace = (text, cursor) => {
104
+ if (text === code) {
105
+ input.current?.setSelectionRange(cursor, cursor);
106
+ }
107
+ else {
108
+ pendingCursor.current = cursor;
109
+ setDraft(text);
110
+ }
111
+ refreshHint(text, cursor);
112
+ };
113
+ const accept = (item, from, text = code, cursor = caret()) => {
114
+ const rest = text.slice(cursor).replace(/^[\w$]+/, "");
115
+ const insert = item.kind === "field" && !/^\s*:/.test(rest) ? `${item.name}: ` : item.name;
116
+ setCompletion(undefined);
117
+ replace(text.slice(0, from) + insert + rest, from + insert.length);
118
+ };
119
+ const caret = () => input.current?.selectionStart ?? code.length;
120
+ const run = () => {
121
+ const text = code;
122
+ history.current = { draft: "" };
123
+ setCompletion(undefined);
124
+ hinted.current = undefined;
125
+ setHint(undefined);
126
+ setDraft("");
127
+ (0, console_session_1.runInConsole)(text);
128
+ };
129
+ const recall = (step) => {
130
+ const past = (0, console_session_1.consoleHistory)() ?? [];
131
+ const state = history.current;
132
+ if (!past.length)
133
+ return false;
134
+ let index;
135
+ if (step < 0) {
136
+ if (state.index === undefined)
137
+ state.draft = code;
138
+ index = Math.max(0, (state.index ?? past.length) - 1);
139
+ }
140
+ else {
141
+ if (state.index === undefined)
142
+ return false;
143
+ index = state.index + 1 >= past.length ? undefined : state.index + 1;
144
+ }
145
+ state.index = index;
146
+ const text = index === undefined ? state.draft : past[index];
147
+ setCompletion(undefined);
148
+ replace(text, text.length);
149
+ return true;
150
+ };
151
+ const onKeyDown = (event) => {
152
+ if (event.nativeEvent.isComposing || event.nativeEvent.keyCode === 229)
153
+ return;
154
+ const target = event.currentTarget;
155
+ const cursor = target.selectionStart;
156
+ if (completion) {
157
+ const count = completion.items.length;
158
+ if (event.key === "ArrowDown" || event.key === "ArrowUp") {
159
+ event.preventDefault();
160
+ const step = event.key === "ArrowDown" ? 1 : -1;
161
+ setCompletion({ ...completion, selected: (completion.selected + step + count) % count });
162
+ return;
163
+ }
164
+ if (event.key === "Tab") {
165
+ event.preventDefault();
166
+ accept(completion.items[completion.selected], completion.from);
167
+ return;
168
+ }
169
+ if (event.key === "Escape") {
170
+ event.preventDefault();
171
+ setCompletion(undefined);
172
+ return;
173
+ }
174
+ }
175
+ if (event.key === "Tab" && !event.shiftKey) {
176
+ event.preventDefault();
177
+ if (!showCompletions(code, cursor, true)) {
178
+ replace(`${code.slice(0, cursor)} ${code.slice(target.selectionEnd)}`, cursor + 2);
179
+ }
180
+ return;
181
+ }
182
+ if (event.key === "Enter" && !event.shiftKey && !event.altKey) {
183
+ if ((0, repl_1.needsMoreInput)(code))
184
+ return;
185
+ event.preventDefault();
186
+ run();
187
+ return;
188
+ }
189
+ const onFirstLine = !code.slice(0, cursor).includes("\n");
190
+ const onLastLine = !code.slice(target.selectionEnd).includes("\n");
191
+ if (event.key === "ArrowUp" && !event.shiftKey && onFirstLine && recall(-1)) {
192
+ event.preventDefault();
193
+ return;
194
+ }
195
+ if (event.key === "ArrowDown" && !event.shiftKey && onLastLine && recall(1)) {
196
+ event.preventDefault();
197
+ return;
198
+ }
199
+ if (event.ctrlKey && !event.metaKey && event.key.toLowerCase() === "l") {
200
+ event.preventDefault();
201
+ (0, console_session_1.clearConsole)();
202
+ return;
203
+ }
204
+ if (event.ctrlKey &&
205
+ !event.metaKey &&
206
+ event.key.toLowerCase() === "c" &&
207
+ target.selectionStart === target.selectionEnd) {
208
+ event.preventDefault();
209
+ history.current = { draft: "" };
210
+ setCompletion(undefined);
211
+ replace("", 0);
212
+ }
213
+ };
214
+ const onChange = (event) => {
215
+ const text = event.target.value;
216
+ const cursor = event.target.selectionStart;
217
+ const typed = text.length > code.length && /[\w$.]/.test(text[cursor - 1] ?? "");
218
+ setDraft(text);
219
+ refreshHint(text, cursor);
220
+ if (typed)
221
+ showCompletions(text, cursor, false);
222
+ else
223
+ setCompletion(undefined);
224
+ };
225
+ const onSelect = (event) => {
226
+ const cursor = event.currentTarget.selectionStart;
227
+ refreshHint(code, cursor);
228
+ if (completion &&
229
+ (cursor < completion.from || /[^\w$]/.test(code.slice(completion.from, cursor))))
230
+ setCompletion(undefined);
231
+ };
232
+ const lines = Math.min(MAX_LINES, code.split("\n").length);
233
+ return ((0, jsx_runtime_1.jsxs)("div", { style: { position: "relative", borderTop: `1px solid ${theme.border}`, flex: "0 0 auto" }, children: [completion && ((0, jsx_runtime_1.jsx)(CompletionList, { completion: completion, theme: theme, onPick: (item) => accept(item, completion.from) })), hint && (0, jsx_runtime_1.jsx)(SignatureLine, { hint: hint, theme: theme }), (0, jsx_runtime_1.jsxs)("div", { style: { display: "flex", alignItems: "flex-start", padding: "4px 8px" }, children: [(0, jsx_runtime_1.jsxs)("span", { style: {
234
+ color: theme.muted,
235
+ whiteSpace: "nowrap",
236
+ paddingRight: "6px",
237
+ lineHeight: "1.5",
238
+ }, children: [context, " \u203A"] }), (0, jsx_runtime_1.jsx)("textarea", { ref: (element) => {
239
+ input.current = element;
240
+ if (typeof ref === "function")
241
+ ref(element);
242
+ else if (ref)
243
+ ref.current = element;
244
+ }, "aria-label": "Console input", value: code, rows: lines, spellCheck: false, autoCapitalize: "off", autoComplete: "off", autoCorrect: "off",
245
+ // biome-ignore lint/a11y/noAutofocus: the panel opens to type in it
246
+ autoFocus: true, placeholder: ready ? "Tasks.tasks.list() · help()" : "Loading contracts…", onKeyDown: onKeyDown, onChange: onChange, onSelect: onSelect, onFocus: onSelect, onBlur: () => setCompletion(undefined), style: {
247
+ flex: "1 1 auto",
248
+ resize: "none",
249
+ border: "none",
250
+ outline: "none",
251
+ background: "transparent",
252
+ color: theme.text,
253
+ fontFamily: console_theme_1.CONSOLE_FONT,
254
+ fontSize: "inherit",
255
+ lineHeight: "1.5",
256
+ padding: 0,
257
+ overflowY: lines >= MAX_LINES ? "auto" : "hidden",
258
+ } })] })] }));
259
+ });
260
+ /** The grey line above the input: the call, the field the cursor's value fills, and what it is. */
261
+ const SignatureLine = ({ hint, theme, }) => {
262
+ const { call, active, inObject } = hint;
263
+ const object = call.objectArgument && inObject;
264
+ const current = active === undefined ? undefined : call.params[active];
265
+ const past = !object && active === undefined && call.params.length > 0;
266
+ return ((0, jsx_runtime_1.jsxs)("div", { "data-testid": "console-signature", style: {
267
+ color: theme.muted,
268
+ padding: "3px 8px 0",
269
+ lineHeight: "1.45",
270
+ whiteSpace: "pre-wrap",
271
+ }, children: [(0, jsx_runtime_1.jsxs)("div", { children: [call.name, object ? "({ " : "(", call.params.map((param, index) => ((0, jsx_runtime_1.jsxs)("span", { children: [index > 0 && ", ", (0, jsx_runtime_1.jsxs)("span", { style: index === active ? { color: theme.text, fontWeight: 600 } : undefined, "aria-current": index === active ? "true" : undefined, children: [param.name, param.optional ? "?" : ""] })] }, param.name))), object ? " })" : ")", past && ((0, jsx_runtime_1.jsx)("span", { style: { color: theme.warn }, children: ` ${call.name} takes ${call.params.length} value${call.params.length === 1 ? "" : "s"}` }))] }), current ? ((0, jsx_runtime_1.jsxs)("div", { children: [current.name, ": ", String(current.type), current.isArray ? "[]" : "", current.optional ? " (optional)" : "", current.description ? ` ${current.description}` : ""] })) : (call.description && (0, jsx_runtime_1.jsx)("div", { children: call.description }))] }));
272
+ };
273
+ /** The completions, above the input; the selected one is highlighted. */
274
+ const CompletionList = ({ completion, theme, onPick }) => {
275
+ const list = (0, react_1.useRef)(null);
276
+ (0, react_1.useLayoutEffect)(() => {
277
+ const selected = list.current?.children[completion.selected];
278
+ selected?.scrollIntoView?.({ block: "nearest" });
279
+ }, [completion.selected]);
280
+ return ((0, jsx_runtime_1.jsx)("div", { ref: list, role: "listbox", "aria-label": "Completions", style: {
281
+ position: "absolute",
282
+ bottom: "100%",
283
+ left: "8px",
284
+ minWidth: "280px",
285
+ maxWidth: "min(640px, 90%)",
286
+ maxHeight: `${VISIBLE_ITEMS * 22}px`,
287
+ overflowY: "auto",
288
+ background: theme.headerBg,
289
+ border: `1px solid ${theme.border}`,
290
+ borderRadius: "4px",
291
+ boxShadow: "0 4px 12px rgba(0, 0, 0, 0.25)",
292
+ zIndex: 10,
293
+ }, children: completion.items.map((item, index) => ((0, jsx_runtime_1.jsxs)("div", { role: "option", tabIndex: -1, "aria-selected": index === completion.selected,
294
+ // Before the input's blur closes the list.
295
+ onMouseDown: (event) => {
296
+ event.preventDefault();
297
+ onPick(item);
298
+ }, style: {
299
+ display: "flex",
300
+ alignItems: "baseline",
301
+ gap: "8px",
302
+ padding: "1px 8px",
303
+ lineHeight: "20px",
304
+ cursor: "pointer",
305
+ background: index === completion.selected ? theme.hover : undefined,
306
+ }, children: [(0, jsx_runtime_1.jsx)("span", { style: { color: theme.text, whiteSpace: "nowrap" }, children: item.name }), (0, jsx_runtime_1.jsx)("span", { style: { color: theme.muted, fontSize: "11px", whiteSpace: "nowrap" }, children: item.kind }), item.detail && ((0, jsx_runtime_1.jsx)("span", { style: {
307
+ color: theme.muted,
308
+ overflow: "hidden",
309
+ textOverflow: "ellipsis",
310
+ whiteSpace: "nowrap",
311
+ marginLeft: "auto",
312
+ }, children: item.detail }))] }, item.name))) }));
313
+ };
@@ -0,0 +1,7 @@
1
+ /**
2
+ * The Console's body: what the person ran and what it gave, oldest first, above the input.
3
+ * Contracts are globals here, as at `peers repl`.
4
+ */
5
+ import type React from "react";
6
+ /** The Console's REPL: its output and its input. Starts the session the first time it shows. */
7
+ export declare const ConsoleRepl: React.FC;
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConsoleRepl = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const react_1 = require("react");
6
+ const hooks_1 = require("../hooks");
7
+ const console_input_1 = require("./console-input");
8
+ const console_session_1 = require("./console-session");
9
+ const console_theme_1 = require("./console-theme");
10
+ const console_value_1 = require("./console-value");
11
+ /** Within this many pixels of the bottom, new output keeps the view at the bottom. */
12
+ const STICK_PX = 24;
13
+ /** The Console's REPL: its output and its input. Starts the session the first time it shows. */
14
+ const ConsoleRepl = () => {
15
+ const theme = (0, console_theme_1.useConsoleTheme)();
16
+ const [blocks] = (0, hooks_1.useObservable)(console_session_1.consoleBlocks);
17
+ const [context] = (0, hooks_1.useObservable)(console_session_1.consoleContext);
18
+ const [ready] = (0, hooks_1.useObservable)(console_session_1.consoleReady);
19
+ const output = (0, react_1.useRef)(null);
20
+ const input = (0, react_1.useRef)(null);
21
+ const stick = (0, react_1.useRef)(true);
22
+ (0, react_1.useEffect)(() => {
23
+ (0, console_session_1.startConsole)().catch(() => {
24
+ // Shown in the output.
25
+ });
26
+ }, []);
27
+ (0, react_1.useLayoutEffect)(() => {
28
+ if (stick.current && output.current)
29
+ output.current.scrollTop = output.current.scrollHeight;
30
+ }, [blocks]);
31
+ const editAgain = (code) => {
32
+ const element = input.current;
33
+ if (element && (0, console_session_1.consoleDraft)() === code) {
34
+ // Refresh the hint on focus even if clicking the button left the input focused.
35
+ element.blur();
36
+ element.setSelectionRange(code.length, code.length);
37
+ element.focus();
38
+ }
39
+ else {
40
+ // Focused first, so this surface's input (not the other's) takes the caret to the end.
41
+ element?.focus();
42
+ (0, console_session_1.consoleDraft)(code);
43
+ }
44
+ };
45
+ return ((0, jsx_runtime_1.jsxs)("div", { style: {
46
+ display: "flex",
47
+ flexDirection: "column",
48
+ height: "100%",
49
+ minHeight: 0,
50
+ fontFamily: console_theme_1.CONSOLE_FONT,
51
+ fontSize: "12.5px",
52
+ }, children: [(0, jsx_runtime_1.jsxs)("div", { ref: output, role: "log", "aria-label": "Console output", onScroll: (event) => {
53
+ const element = event.currentTarget;
54
+ stick.current =
55
+ element.scrollHeight - element.scrollTop - element.clientHeight < STICK_PX;
56
+ }, onMouseUp: (event) => {
57
+ // A click on the output, not a selection or a button, goes back to typing.
58
+ const selection = window.getSelection();
59
+ if ((!selection || selection.isCollapsed) &&
60
+ !event.target.closest("button, a, details"))
61
+ input.current?.focus();
62
+ }, style: { flex: "1 1 auto", minHeight: 0, overflowY: "auto", padding: "4px 8px" }, children: [!blocks.length && ((0, jsx_runtime_1.jsx)("div", { style: { color: theme.muted, padding: "4px 0" }, children: ready
63
+ ? "Contracts are globals here: Tasks, contracts(), help()."
64
+ : "Loading contracts…" })), blocks.map((block) => ((0, jsx_runtime_1.jsx)(Block, { block: block, theme: theme, onEdit: editAgain }, block.id)))] }), (0, jsx_runtime_1.jsx)(console_input_1.ConsoleInput, { ref: input, context: context, ready: ready })] }));
65
+ };
66
+ exports.ConsoleRepl = ConsoleRepl;
67
+ /** One block of output: an entry, a print, or a line from the Console. */
68
+ const Block = ({ block, theme, onEdit }) => {
69
+ if (block.type === "info") {
70
+ return ((0, jsx_runtime_1.jsx)("div", { style: { color: block.tone === "error" ? theme.error : theme.muted, padding: "2px 0" }, children: block.text }));
71
+ }
72
+ if (block.type === "print")
73
+ return (0, jsx_runtime_1.jsx)(Print, { print: block, theme: theme });
74
+ return (0, jsx_runtime_1.jsx)(Entry, { entry: block, theme: theme, onEdit: onEdit });
75
+ };
76
+ /** What `print` or `console.log` was given, side by side. */
77
+ const Print = ({ print, theme }) => {
78
+ const color = print.level === "error" ? theme.error : print.level === "warn" ? theme.warn : undefined;
79
+ return ((0, jsx_runtime_1.jsx)("div", { style: { color, padding: "2px 0", display: "flex", flexWrap: "wrap", gap: "0 0.6em" }, children: print.values.map((value, index) => (
80
+ // biome-ignore lint/suspicious/noArrayIndexKey: a print's values have no key of their own
81
+ (0, jsx_runtime_1.jsx)("div", { style: { maxWidth: "100%" }, children: (0, jsx_runtime_1.jsx)(console_value_1.ConsoleValue, { value: value }) }, index))) }));
82
+ };
83
+ /** Code that ran, and what it gave. */
84
+ const Entry = ({ entry, theme, onEdit }) => {
85
+ const [copied, setCopied] = (0, react_1.useState)(false);
86
+ const copy = () => {
87
+ const text = entry.status === "failed" ? (entry.error?.message ?? "") : (0, console_value_1.copyText)(entry.value);
88
+ void navigator.clipboard?.writeText(text).then(() => {
89
+ setCopied(true);
90
+ setTimeout(() => setCopied(false), 1200);
91
+ });
92
+ };
93
+ const link = {
94
+ border: "none",
95
+ background: "none",
96
+ padding: 0,
97
+ font: "inherit",
98
+ color: theme.accent,
99
+ cursor: "pointer",
100
+ };
101
+ return ((0, jsx_runtime_1.jsxs)("div", { "data-testid": "console-entry", style: { padding: "4px 0", borderBottom: `1px solid ${theme.border}` }, children: [(0, jsx_runtime_1.jsxs)("div", { style: { display: "flex", alignItems: "flex-start", gap: "6px" }, children: [(0, jsx_runtime_1.jsxs)("span", { style: { color: theme.muted, whiteSpace: "nowrap" }, children: [entry.context, " \u203A"] }), (0, jsx_runtime_1.jsx)("pre", { style: { ...console_theme_1.CONSOLE_PRE_STYLE, flex: "1 1 auto" }, children: entry.code }), (0, jsx_runtime_1.jsxs)("span", { style: { color: theme.muted, whiteSpace: "nowrap", display: "flex", gap: "8px" }, children: [entry.ms !== undefined && (0, jsx_runtime_1.jsx)("span", { title: "How long it took", children: formatMs(entry.ms) }), (0, jsx_runtime_1.jsx)("button", { type: "button", style: { ...link, color: theme.muted }, title: "Edit it again", onClick: () => onEdit(entry.code), children: (0, jsx_runtime_1.jsx)("i", { className: "bi-arrow-return-left" }) }), (entry.status === "done" || entry.status === "failed") && ((0, jsx_runtime_1.jsx)("button", { type: "button", style: { ...link, color: theme.muted }, title: entry.status === "failed" ? "Copy the error" : "Copy the result", onClick: copy, children: (0, jsx_runtime_1.jsx)("i", { className: copied ? "bi-check2" : "bi-clipboard" }) }))] })] }), (0, jsx_runtime_1.jsxs)("div", { style: { paddingTop: "2px" }, children: [entry.status === "running" && ((0, jsx_runtime_1.jsxs)("div", { style: { color: theme.muted }, children: [(0, jsx_runtime_1.jsx)("span", { className: "spinner-border spinner-border-sm", style: { width: "0.8em", height: "0.8em", marginRight: "6px" } }), "running \u00B7", " ", (0, jsx_runtime_1.jsx)("button", { type: "button", style: link, onClick: () => (0, console_session_1.stopWaiting)(entry.id), children: "stop waiting" })] })), entry.status === "stopped" && ((0, jsx_runtime_1.jsx)("div", { style: { color: theme.muted }, children: entry.ms === undefined
102
+ ? "Stopped before it ran."
103
+ : "Stopped waiting. Its calls may still finish on the host." })), entry.prints?.map((print) => ((0, jsx_runtime_1.jsx)(Print, { print: print, theme: theme }, print.id))), entry.status === "done" && (0, jsx_runtime_1.jsx)(console_value_1.ConsoleValue, { value: entry.value }), entry.status === "failed" && entry.error && ((0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("pre", { style: { ...console_theme_1.CONSOLE_PRE_STYLE, color: theme.error }, children: entry.error.message }), entry.error.hint && (0, jsx_runtime_1.jsx)("div", { style: { color: theme.warn }, children: entry.error.hint }), entry.error.stack && ((0, jsx_runtime_1.jsxs)("details", { children: [(0, jsx_runtime_1.jsx)("summary", { style: { color: theme.muted, cursor: "pointer" }, children: "stack" }), (0, jsx_runtime_1.jsx)("pre", { style: { ...console_theme_1.CONSOLE_PRE_STYLE, color: theme.muted }, children: entry.error.stack })] }))] }))] })] }));
104
+ };
105
+ /** A duration: `340 ms`, `2.4 s`. */
106
+ function formatMs(ms) {
107
+ return ms < 1000 ? `${ms} ms` : `${(ms / 1000).toFixed(1)} s`;
108
+ }
@@ -0,0 +1,45 @@
1
+ /**
2
+ * The Console's scope: the names code typed at the Console can use, and how that code runs.
3
+ *
4
+ * Code runs in the page, with the person's own authority, as the body of an async function
5
+ * inside `with` over a proxy. Through the proxy the code sees the contract globals, the
6
+ * helpers, the person's own variables and the standard JavaScript globals, and none of the
7
+ * page's: `window`, `document` and the app's globals aren't names here, and an assignment to a
8
+ * new name lands in the scope, not on the page. That keeps typed names apart from the app's.
9
+ * It isn't a security boundary, and doesn't need to be: the person already has the app's
10
+ * authority. Code a model writes runs in Operator's locked-down worker instead.
11
+ */
12
+ import { type IAssistScope } from "@peers-app/peers-sdk/repl";
13
+ /**
14
+ * The globals code at the Console can use: the language's own, and the web's that a prompt
15
+ * needs (timers, `fetch`, `URL`, text encoding). Not `window`, `document` or `globalThis`.
16
+ */
17
+ export declare const CONSOLE_GLOBAL_NAMES: readonly string[];
18
+ /**
19
+ * The names code at the Console sees, and the evaluator that runs it. Declarations and
20
+ * assignments persist from one entry to the next, and `$` is the last result that wasn't
21
+ * `undefined`.
22
+ */
23
+ export declare class ConsoleScope implements IAssistScope {
24
+ #private;
25
+ /** What the code sees beyond the globals: the helpers, the contract globals and its own names. */
26
+ readonly values: Record<string, unknown>;
27
+ /** @param globalNames The globals the code may use. */
28
+ constructor(globalNames?: readonly string[]);
29
+ /** Every name code can use at its top: its own, `$`, and the globals. */
30
+ names(): string[];
31
+ /**
32
+ * A name's value, without running anything: the scope's own, or a global's. A getter the
33
+ * person defined on the scope (through `this`) isn't called; `$` is the Console's own.
34
+ */
35
+ get(name: string): unknown;
36
+ /**
37
+ * Run code typed at the Console. Its calls are awaited, its declarations kept, and its last
38
+ * expression is its value.
39
+ *
40
+ * @param code What the person typed.
41
+ * @returns The value of its last expression, or `undefined`.
42
+ * @throws What the code throws, or a SyntaxError when it doesn't parse.
43
+ */
44
+ evaluate(code: string): Promise<unknown>;
45
+ }
@@ -0,0 +1,174 @@
1
+ "use strict";
2
+ /**
3
+ * The Console's scope: the names code typed at the Console can use, and how that code runs.
4
+ *
5
+ * Code runs in the page, with the person's own authority, as the body of an async function
6
+ * inside `with` over a proxy. Through the proxy the code sees the contract globals, the
7
+ * helpers, the person's own variables and the standard JavaScript globals, and none of the
8
+ * page's: `window`, `document` and the app's globals aren't names here, and an assignment to a
9
+ * new name lands in the scope, not on the page. That keeps typed names apart from the app's.
10
+ * It isn't a security boundary, and doesn't need to be: the person already has the app's
11
+ * authority. Code a model writes runs in Operator's locked-down worker instead.
12
+ */
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.ConsoleScope = exports.CONSOLE_GLOBAL_NAMES = void 0;
15
+ const repl_1 = require("@peers-app/peers-sdk/repl");
16
+ /**
17
+ * The globals code at the Console can use: the language's own, and the web's that a prompt
18
+ * needs (timers, `fetch`, `URL`, text encoding). Not `window`, `document` or `globalThis`.
19
+ */
20
+ exports.CONSOLE_GLOBAL_NAMES = [
21
+ "undefined",
22
+ "NaN",
23
+ "Infinity",
24
+ "Object",
25
+ "Function",
26
+ "Array",
27
+ "Number",
28
+ "String",
29
+ "Boolean",
30
+ "Symbol",
31
+ "BigInt",
32
+ "Date",
33
+ "RegExp",
34
+ "Error",
35
+ "AggregateError",
36
+ "EvalError",
37
+ "RangeError",
38
+ "ReferenceError",
39
+ "SyntaxError",
40
+ "TypeError",
41
+ "URIError",
42
+ "Promise",
43
+ "Proxy",
44
+ "Reflect",
45
+ "JSON",
46
+ "Math",
47
+ "Intl",
48
+ "Map",
49
+ "Set",
50
+ "WeakMap",
51
+ "WeakSet",
52
+ "WeakRef",
53
+ "ArrayBuffer",
54
+ "DataView",
55
+ "Int8Array",
56
+ "Uint8Array",
57
+ "Uint8ClampedArray",
58
+ "Int16Array",
59
+ "Uint16Array",
60
+ "Int32Array",
61
+ "Uint32Array",
62
+ "Float32Array",
63
+ "Float64Array",
64
+ "BigInt64Array",
65
+ "BigUint64Array",
66
+ "parseInt",
67
+ "parseFloat",
68
+ "isNaN",
69
+ "isFinite",
70
+ "encodeURI",
71
+ "encodeURIComponent",
72
+ "decodeURI",
73
+ "decodeURIComponent",
74
+ "setTimeout",
75
+ "clearTimeout",
76
+ "setInterval",
77
+ "clearInterval",
78
+ "queueMicrotask",
79
+ "structuredClone",
80
+ "fetch",
81
+ "URL",
82
+ "URLSearchParams",
83
+ "TextEncoder",
84
+ "TextDecoder",
85
+ "AbortController",
86
+ "atob",
87
+ "btoa",
88
+ "crypto",
89
+ ];
90
+ /** Web functions that must be called on the window, not as plain functions. */
91
+ const BOUND = new Set([
92
+ "setTimeout",
93
+ "clearTimeout",
94
+ "setInterval",
95
+ "clearInterval",
96
+ "queueMicrotask",
97
+ "structuredClone",
98
+ "fetch",
99
+ "atob",
100
+ "btoa",
101
+ ]);
102
+ /**
103
+ * The names code at the Console sees, and the evaluator that runs it. Declarations and
104
+ * assignments persist from one entry to the next, and `$` is the last result that wasn't
105
+ * `undefined`.
106
+ */
107
+ class ConsoleScope {
108
+ /** What the code sees beyond the globals: the helpers, the contract globals and its own names. */
109
+ values = Object.create(null);
110
+ #globals;
111
+ #proxy;
112
+ /** @param globalNames The globals the code may use. */
113
+ constructor(globalNames = exports.CONSOLE_GLOBAL_NAMES) {
114
+ const page = globalThis;
115
+ this.#globals = new Map(globalNames
116
+ .filter((name) => name in page)
117
+ .map((name) => {
118
+ const value = page[name];
119
+ return [
120
+ name,
121
+ BOUND.has(name) && typeof value === "function" ? value.bind(globalThis) : value,
122
+ ];
123
+ }));
124
+ (0, repl_1.defineLastResult)(this.values);
125
+ this.#proxy = new Proxy(this.values, {
126
+ // Every name is the scope's, so an assignment to a new one lands here, not on the page.
127
+ has: (_target, key) => typeof key === "string",
128
+ get: (target, key) => {
129
+ // `with` reads Symbol.unscopables; no name is hidden from it.
130
+ if (typeof key === "symbol")
131
+ return undefined;
132
+ if (key in target)
133
+ return Reflect.get(target, key);
134
+ if (this.#globals.has(key))
135
+ return this.#globals.get(key);
136
+ throw new ReferenceError(`${key} is not defined`);
137
+ },
138
+ set: (target, key, value) => Reflect.set(target, key, value),
139
+ });
140
+ }
141
+ /** Every name code can use at its top: its own, `$`, and the globals. */
142
+ names() {
143
+ return [...Object.keys(this.values), "$", ...this.#globals.keys()];
144
+ }
145
+ /**
146
+ * A name's value, without running anything: the scope's own, or a global's. A getter the
147
+ * person defined on the scope (through `this`) isn't called; `$` is the Console's own.
148
+ */
149
+ get(name) {
150
+ // `this` at the top is the scope (see evaluate), so `this.` completes its names.
151
+ if (name === "this")
152
+ return this.values;
153
+ const own = Object.getOwnPropertyDescriptor(this.values, name);
154
+ if (!own)
155
+ return this.#globals.get(name);
156
+ return "value" in own || name === "$" ? this.values[name] : undefined;
157
+ }
158
+ /**
159
+ * Run code typed at the Console. Its calls are awaited, its declarations kept, and its last
160
+ * expression is its value.
161
+ *
162
+ * @param code What the person typed.
163
+ * @returns The value of its last expression, or `undefined`.
164
+ * @throws What the code throws, or a SyntaxError when it doesn't parse.
165
+ */
166
+ async evaluate(code) {
167
+ const body = (0, repl_1.asyncBody)(code, { lastResult: true, keepDeclarations: true });
168
+ // Local bindings must resolve before the with proxy, including var in blocks and loops.
169
+ const run = new Function("__consoleScope", `with (__consoleScope) { return (async () => {\n${body}\n})(); }`);
170
+ // `this` at the top is the scope, as it's the REPL's global in Node, not the page's window.
171
+ return run.call(this.values, this.#proxy);
172
+ }
173
+ }
174
+ exports.ConsoleScope = ConsoleScope;
@@ -0,0 +1,8 @@
1
+ /**
2
+ * The Console app: the Console's prompt full screen, so it opens like any other app, whatever
3
+ * the layout. It shares its session with the Tabs + Console layout's panel: the same output,
4
+ * variables, group and draft.
5
+ */
6
+ import type React from "react";
7
+ /** The Console as a screen: its header over its REPL, filling the tab. */
8
+ export declare const ConsoleScreen: React.FC;