@gloom-sh/terminal 0.20.10 → 0.20.11
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.
- package/package.json +1 -1
- package/patches/@opentui%2Fcore@0.3.2.patch +16 -0
- package/src/api-client/socket-connection.ts +355 -0
- package/src/api-client/socket-features.ts +75 -0
- package/src/api-client/socket-frames.ts +161 -0
- package/src/api-client/socket-listeners.ts +207 -0
- package/src/api-client/socket-quotes.ts +332 -0
- package/src/api-client/socket.ts +150 -983
- package/src/brokers/signed-in/adapter.ts +19 -5
- package/src/brokers/signed-in/client.ts +13 -1
- package/src/brokers/signed-in/sign-in-dialog.tsx +33 -9
- package/src/components/chart/native/kitty/manager.ts +2 -0
- package/src/components/chart/native/surface/manager.ts +211 -11
- package/src/components/command-bar/panel/index.tsx +2 -13
- package/src/components/command-bar/panel/layout.ts +1 -7
- package/src/components/command-bar/panel/runtime.ts +0 -1
- package/src/components/command-bar/panel/types.ts +0 -2
- package/src/components/data-table/column-menu.tsx +89 -0
- package/src/components/data-table/sort-menu.tsx +9 -2
- package/src/components/data-table/view.tsx +33 -6
- package/src/components/form-modal/content.tsx +10 -0
- package/src/components/index.ts +1 -1
- package/src/components/layout/pane/footer/index.tsx +25 -11
- package/src/components/layout/pane/footer/model.ts +62 -20
- package/src/components/layout/pane/sidebar.tsx +125 -15
- package/src/components/layout/shell/active-drag.ts +18 -13
- package/src/components/layout/shell/drag/magnets.ts +34 -18
- package/src/components/ticker/list-table-view.tsx +5 -0
- package/src/components/ui/data-table/column-order.ts +180 -0
- package/src/components/ui/data-table/index.tsx +12 -1
- package/src/components/ui/data-table/opentui/index.tsx +267 -23
- package/src/components/ui/data-table/opentui/model.ts +43 -4
- package/src/components/ui/data-table/types.ts +49 -0
- package/src/components/ui/data-table/use-column-order.ts +135 -0
- package/src/components/ui/index.ts +1 -1
- package/src/components/ui/table-layout.ts +120 -0
- package/src/docs/snapshot.json +3 -2
- package/src/i18n/es.ts +2 -0
- package/src/i18n/ja.ts +2 -0
- package/src/i18n/ko.ts +2 -0
- package/src/i18n/zh-cn.ts +2 -0
- package/src/i18n/zh-tw.ts +2 -0
- package/src/market-data/coordinator/index.ts +4 -3
- package/src/market-data/coordinator/quotes.ts +12 -4
- package/src/market-data/quotes/freshness.ts +12 -0
- package/src/market-data/quotes/live-valuation.ts +1 -1
- package/src/market-data/quotes/regular-session-valuation.ts +1 -1
- package/src/plugins/builtin/broker-manager/detail.tsx +5 -3
- package/src/plugins/builtin/broker-manager/index.tsx +6 -6
- package/src/plugins/builtin/broker-manager/model.ts +15 -6
- package/src/plugins/builtin/broker-manager/pane-actions.tsx +11 -4
- package/src/plugins/builtin/broker-manager/sign-in-end.ts +50 -19
- package/src/plugins/builtin/broker-manager/table.ts +10 -4
- package/src/plugins/builtin/chat/sidebar.tsx +33 -16
- package/src/plugins/builtin/cloud/askg/tool-timeline.tsx +2 -0
- package/src/plugins/builtin/equity-screener/live.ts +74 -18
- package/src/plugins/builtin/equity-screener/model.ts +19 -4
- package/src/plugins/builtin/equity-screener/pane.tsx +19 -14
- package/src/plugins/builtin/equity-screener/refresh-anchor.ts +45 -0
- package/src/plugins/builtin/equity-screener/results.ts +22 -2
- package/src/plugins/builtin/equity-screener/screen-check.ts +9 -3
- package/src/plugins/builtin/futures/index.tsx +15 -1
- package/src/plugins/builtin/futures/table.tsx +1 -1
- package/src/plugins/builtin/fx-matrix/index.tsx +2 -0
- package/src/plugins/builtin/holders/pane.tsx +30 -20
- package/src/plugins/builtin/iv-history/events.ts +5 -0
- package/src/plugins/builtin/iv-history/headless.ts +7 -2
- package/src/plugins/builtin/kelly-sizer/sections.tsx +2 -0
- package/src/plugins/builtin/macro-day/headless.ts +12 -3
- package/src/plugins/builtin/options/view.tsx +2 -0
- package/src/plugins/builtin/options-scenario/pane.tsx +2 -1
- package/src/plugins/builtin/perps/cascade-tabs.tsx +2 -1
- package/src/plugins/builtin/portfolio-list/pane/index.tsx +13 -0
- package/src/plugins/builtin/portfolio-list/table.tsx +5 -0
- package/src/plugins/builtin/rate-path/pane.tsx +2 -0
- package/src/plugins/builtin/revenue-breakdown/pane.tsx +2 -0
- package/src/plugins/builtin/reverse-dcf/pane.tsx +2 -1
- package/src/plugins/builtin/seasonality/pane.tsx +2 -1
- package/src/plugins/builtin/thirteenf/pane.tsx +2 -0
- package/src/plugins/builtin/ticker-detail/financials/model.ts +28 -6
- package/src/plugins/builtin/ticker-detail/financials/ratio-table.tsx +26 -9
- package/src/plugins/builtin/ticker-detail/financials/tab.tsx +58 -35
- package/src/plugins/builtin/vol-surface/heat-grid.tsx +2 -1
- package/src/plugins/builtin/vol-surface/pane.tsx +2 -1
- package/src/plugins/builtin/world-indices/index.tsx +5 -1
- package/src/plugins/builtin/yield-curve/index.tsx +2 -1
- package/src/renderers/dom/data-table/column-drag.ts +147 -0
- package/src/renderers/dom/data-table/index.tsx +22 -0
- package/src/renderers/dom/data-table/row.tsx +27 -5
- package/src/renderers/dom/styles.css +22 -0
- package/src/renderers/opentui/chart-surface.tsx +1 -0
- package/src/renderers/opentui/frame-hits.ts +33 -0
- package/src/renderers/opentui/host.tsx +2 -0
- package/src/renderers/opentui/native-surface.ts +14 -21
- package/src/renderers/opentui/test-utils.tsx +3 -0
- package/src/state/app/context/index.tsx +22 -0
- package/src/test-support/app-store.ts +24 -1
- package/src/time-series/live-quotes.ts +3 -9
- package/src/ui/host.tsx +18 -0
- package/src/ui/pointer-drag.ts +11 -2
- package/src/utils/fundamentals.ts +14 -3
- package/src/utils/share-multiples.cases.json +780 -2
- package/src/utils/share-multiples.ts +154 -24
|
@@ -50,6 +50,23 @@ function brokerReason(lastError: string | null | undefined): string | null {
|
|
|
50
50
|
return described.replace(/[\s.]+$/, "").slice(0, 200) || null;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
+
/**
|
|
54
|
+
* What a profile says once the broker ended its sign-in, and to connect again.
|
|
55
|
+
* A broker that keeps one AI app per account (IBKR) ends Gloom's grant when
|
|
56
|
+
* another app is connected to the account, and says only "Invalid
|
|
57
|
+
* authorization status"; that one is said in plain words. A broker the app
|
|
58
|
+
* does not know yet counts as one, since only IBKR says it.
|
|
59
|
+
*/
|
|
60
|
+
function signInEndedMessage(name: string, lastError: string | null | undefined, singleConnection = true): string {
|
|
61
|
+
if (singleConnection && /invalid authorization status/i.test(lastError ?? "")) {
|
|
62
|
+
return `${name} disconnected Gloom, most often because another AI app was connected to the same account, and ${name} allows one at a time. Press Connect in Brokers.`;
|
|
63
|
+
}
|
|
64
|
+
const reason = brokerReason(lastError);
|
|
65
|
+
return reason
|
|
66
|
+
? `${name} needs you to sign in again: ${reason}. Press Connect in Brokers.`
|
|
67
|
+
: `Press Connect in Brokers to sign in to ${name}.`;
|
|
68
|
+
}
|
|
69
|
+
|
|
53
70
|
/** Gloom holds no live sign-in for the broker: only connecting again helps. */
|
|
54
71
|
class SignInNeededError extends Error {}
|
|
55
72
|
|
|
@@ -520,11 +537,8 @@ export function createSignedInBrokerAdapter(overrides: Partial<SignedInBrokerAda
|
|
|
520
537
|
const connection = await get<SignedInBrokerConnection>(instance, "");
|
|
521
538
|
canTrade.set(instance.id, connection.status === "connected" && connection.canTrade === true);
|
|
522
539
|
if (connection.status !== "connected") {
|
|
523
|
-
const
|
|
524
|
-
|
|
525
|
-
throw new SignInNeededError(reason
|
|
526
|
-
? `${name} needs you to sign in again: ${reason}. Press Connect in Brokers.`
|
|
527
|
-
: `Press Connect in Brokers to sign in to ${name}.`);
|
|
540
|
+
const singleConnection = deps.findBroker(signedInBrokerId(instance))?.capabilities.singleConnection;
|
|
541
|
+
throw new SignInNeededError(signInEndedMessage(brokerName(instance), connection.lastError, singleConnection !== false));
|
|
528
542
|
}
|
|
529
543
|
});
|
|
530
544
|
},
|
|
@@ -49,12 +49,24 @@ export interface SignedInBrokerConnection {
|
|
|
49
49
|
* The three fields below are absent from a Gloom server that predates them.
|
|
50
50
|
*/
|
|
51
51
|
expiresAt?: string | null;
|
|
52
|
-
/** Within
|
|
52
|
+
/** Within Gloom's warning window before `expiresAt` (two days), or past it: time to renew. */
|
|
53
53
|
expiresSoon?: boolean;
|
|
54
54
|
/** Why the broker ended the sign-in, in its own words. Null while connected. */
|
|
55
55
|
lastError?: string | null;
|
|
56
|
+
/**
|
|
57
|
+
* Whether the broker keeps one connection per account and will ask to
|
|
58
|
+
* replace the Gloom connection it lists for this one on the next sign-in:
|
|
59
|
+
* while it is live, or after the broker ended it on its clock. `may` when
|
|
60
|
+
* Gloom cannot tell an end from the user removing Gloom at the broker;
|
|
61
|
+
* null when it will not ask (none, or another app took the account).
|
|
62
|
+
* Absent from a Gloom server that predates it.
|
|
63
|
+
*/
|
|
64
|
+
replacePrompt?: BrokerReplacePrompt | null;
|
|
56
65
|
}
|
|
57
66
|
|
|
67
|
+
/** What a single-connection broker asks about the Gloom connection it lists, on a new sign-in. */
|
|
68
|
+
export type BrokerReplacePrompt = "will" | "may";
|
|
69
|
+
|
|
58
70
|
/** Public: the list does not depend on the user, so Add Broker can show it signed out. */
|
|
59
71
|
export function listSignedInBrokers(): Promise<{ connectors: SignedInBroker[] }> {
|
|
60
72
|
return apiClient.brokerRequest("connectors", "");
|
|
@@ -22,7 +22,7 @@ import { useDialog, useDialogKeyboard, type DialogApi, type PromptContext } from
|
|
|
22
22
|
import { isPlainKey } from "../../utils/keyboard";
|
|
23
23
|
import { wrapTextLines } from "../../utils/text-wrap";
|
|
24
24
|
import { DeviceSignInDialog } from "../../account/device-signin-dialog";
|
|
25
|
-
import type { SignedInBroker } from "./client";
|
|
25
|
+
import type { BrokerReplacePrompt, SignedInBroker } from "./client";
|
|
26
26
|
import {
|
|
27
27
|
BrokerSignInController,
|
|
28
28
|
runBrokerSignIn,
|
|
@@ -53,8 +53,18 @@ export const BROKER_CONNECT_SUBTITLE = "Continue in your browser.";
|
|
|
53
53
|
/** The key every connect surface takes for a fresh link, as the desktop shows it. */
|
|
54
54
|
export const BROKER_CONNECT_NEW_LINK = { key: "r", label: "new link" };
|
|
55
55
|
|
|
56
|
-
/**
|
|
57
|
-
|
|
56
|
+
/**
|
|
57
|
+
* Under the panel: the broker's own note, or what connecting a single-connection
|
|
58
|
+
* broker does to other apps. When the broker will ask to replace the Gloom
|
|
59
|
+
* connection it already lists (`replace`, as Gloom says), the note says to
|
|
60
|
+
* choose that before the user gets there; `may` when Gloom cannot tell.
|
|
61
|
+
*/
|
|
62
|
+
export function brokerSignInNote(broker: SignedInBroker, replace: BrokerReplacePrompt | null = null): string | null {
|
|
63
|
+
if (replace && broker.capabilities.singleConnection) {
|
|
64
|
+
return replace === "will"
|
|
65
|
+
? tf("{broker} will ask to replace your existing Gloom connection. Choose to replace it.", { broker: broker.name })
|
|
66
|
+
: tf("{broker} may ask to replace your existing Gloom connection. If it does, choose to replace it.", { broker: broker.name });
|
|
67
|
+
}
|
|
58
68
|
return broker.capabilities.signupNote
|
|
59
69
|
?? (broker.capabilities.singleConnection
|
|
60
70
|
? tf("Other AI apps linked to {broker} get disconnected. Connect them to Gloom instead.", { broker: broker.name })
|
|
@@ -125,8 +135,8 @@ export async function promptGloomSignIn(dialog: DialogApi): Promise<boolean> {
|
|
|
125
135
|
*/
|
|
126
136
|
const TERMINAL_DIALOG_ROWS = 12;
|
|
127
137
|
const DESKTOP_DIALOG_ROWS = 10;
|
|
128
|
-
/** Columns the terminal's full dialog takes from the window: margins, border and padding. */
|
|
129
|
-
const TERMINAL_DIALOG_INSET =
|
|
138
|
+
/** Columns the terminal's full dialog takes from the window: margins (4), border (2) and padding (4). */
|
|
139
|
+
const TERMINAL_DIALOG_INSET = 10;
|
|
130
140
|
/** Cells the desktop dialog's padding takes from its width. */
|
|
131
141
|
const DESKTOP_DIALOG_INSET = 4;
|
|
132
142
|
|
|
@@ -136,7 +146,13 @@ function BrokerSignInDialog({
|
|
|
136
146
|
broker,
|
|
137
147
|
write,
|
|
138
148
|
renew,
|
|
139
|
-
|
|
149
|
+
replace,
|
|
150
|
+
}: PromptContext<BrokerSignInOutcome> & {
|
|
151
|
+
broker: SignedInBroker;
|
|
152
|
+
write: boolean;
|
|
153
|
+
renew: boolean;
|
|
154
|
+
replace: BrokerReplacePrompt | null;
|
|
155
|
+
}) {
|
|
140
156
|
useAppLanguage();
|
|
141
157
|
const { nativePaneChrome } = useUiCapabilities();
|
|
142
158
|
const { width: termWidth, height: termHeight } = useViewport();
|
|
@@ -169,6 +185,7 @@ function BrokerSignInDialog({
|
|
|
169
185
|
snapshot={snapshot}
|
|
170
186
|
height={Math.max(4, termHeight - DESKTOP_DIALOG_ROWS)}
|
|
171
187
|
width={FORM_DIALOG_WIDTH - DESKTOP_DIALOG_INSET}
|
|
188
|
+
replace={replace}
|
|
172
189
|
/>
|
|
173
190
|
<Box style={{ marginTop: "var(--gloom-space-md)" }}>
|
|
174
191
|
<DialogActions alignEnd hints={{ keys: [BROKER_CONNECT_NEW_LINK] }}>
|
|
@@ -194,6 +211,7 @@ function BrokerSignInDialog({
|
|
|
194
211
|
snapshot={snapshot}
|
|
195
212
|
height={Math.max(4, termHeight - TERMINAL_DIALOG_ROWS)}
|
|
196
213
|
width={Math.max(10, termWidth - TERMINAL_DIALOG_INSET)}
|
|
214
|
+
replace={replace}
|
|
197
215
|
/>
|
|
198
216
|
<Box height={1} />
|
|
199
217
|
<Box height={1}>
|
|
@@ -221,6 +239,7 @@ export function BrokerConnectView({
|
|
|
221
239
|
height,
|
|
222
240
|
width,
|
|
223
241
|
browserKey = true,
|
|
242
|
+
replace = null,
|
|
224
243
|
}: {
|
|
225
244
|
broker: SignedInBroker;
|
|
226
245
|
snapshot: BrokerSignInSnapshot;
|
|
@@ -230,11 +249,13 @@ export function BrokerConnectView({
|
|
|
230
249
|
width: number;
|
|
231
250
|
/** Whether `b` opens the link now. */
|
|
232
251
|
browserKey?: boolean;
|
|
252
|
+
/** Whether the broker will or may ask to replace the Gloom connection it lists: the note says to choose that. */
|
|
253
|
+
replace?: BrokerReplacePrompt | null;
|
|
233
254
|
}) {
|
|
234
255
|
useAppLanguage();
|
|
235
256
|
const colors = useThemeColors();
|
|
236
257
|
const desktop = useUiCapabilities().nativePaneChrome === true;
|
|
237
|
-
const note = brokerSignInNote(broker);
|
|
258
|
+
const note = brokerSignInNote(broker, replace);
|
|
238
259
|
const noteLines = note ? wrapTextLines(note, Math.max(10, desktop ? Math.min(width, NOTE_MEASURE) : width)) : [];
|
|
239
260
|
// The note goes under the panel, which gets the rows left.
|
|
240
261
|
const noteRows = note ? 1 + noteLines.length : 0;
|
|
@@ -275,6 +296,8 @@ export interface BrokerSignInRequest {
|
|
|
275
296
|
write?: boolean;
|
|
276
297
|
/** Sign in again although the broker is connected. */
|
|
277
298
|
renew?: boolean;
|
|
299
|
+
/** Whether the broker will or may ask to replace the Gloom connection it lists, as Gloom says. */
|
|
300
|
+
replace?: BrokerReplacePrompt | null;
|
|
278
301
|
resolve: (connected: boolean) => void;
|
|
279
302
|
}
|
|
280
303
|
|
|
@@ -288,12 +311,12 @@ const requestListeners = new Set<(request: BrokerSignInRequest) => void>();
|
|
|
288
311
|
*/
|
|
289
312
|
export function requestBrokerSignIn(
|
|
290
313
|
broker: SignedInBroker,
|
|
291
|
-
options: { write?: boolean; renew?: boolean } = {},
|
|
314
|
+
options: { write?: boolean; renew?: boolean; replace?: BrokerReplacePrompt | null } = {},
|
|
292
315
|
): Promise<boolean> {
|
|
293
316
|
if (requestListeners.size === 0) return Promise.resolve(false);
|
|
294
317
|
return new Promise((resolve) => {
|
|
295
318
|
const write = options.write ?? Boolean(broker.capabilities.orders);
|
|
296
|
-
for (const listener of requestListeners) listener({ broker, write, renew: options.renew, resolve });
|
|
319
|
+
for (const listener of requestListeners) listener({ broker, write, renew: options.renew, replace: options.replace, resolve });
|
|
297
320
|
});
|
|
298
321
|
}
|
|
299
322
|
|
|
@@ -320,6 +343,7 @@ export function BrokerSignInDialogHost() {
|
|
|
320
343
|
broker={broker}
|
|
321
344
|
write={write}
|
|
322
345
|
renew={renew}
|
|
346
|
+
replace={request.replace ?? null}
|
|
323
347
|
/>
|
|
324
348
|
),
|
|
325
349
|
}) ?? "cancelled",
|
|
@@ -122,7 +122,9 @@ export class KittyImageManager {
|
|
|
122
122
|
this.lastPlacementKeys = placements.map(serializePlacement);
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
+
/** Deletes the image on screen, once: a chart hidden or covered every frame writes nothing more. */
|
|
125
126
|
clear() {
|
|
127
|
+
if (this.activeSlot === null) return;
|
|
126
128
|
writeRendererRaw(
|
|
127
129
|
this.renderer,
|
|
128
130
|
`${encodeKittyDeleteImage(this.imageIds[0])}${encodeKittyDeleteImage(this.imageIds[1])}`,
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
type NativeChartBitmap,
|
|
9
9
|
} from "../chart-rasterizer";
|
|
10
10
|
import { KittyImageManager } from "../kitty/manager";
|
|
11
|
+
import { getRenderableCellRect, resolveNativeSurfaceVisibleRect, type NativeSurfaceRenderableNode } from "./visibility";
|
|
11
12
|
|
|
12
13
|
export interface NativePaneLayer {
|
|
13
14
|
paneId: string;
|
|
@@ -29,6 +30,28 @@ export interface NativeLocalOccluder {
|
|
|
29
30
|
rect: CellRect;
|
|
30
31
|
}
|
|
31
32
|
|
|
33
|
+
export interface CellInsets {
|
|
34
|
+
top: number;
|
|
35
|
+
right: number;
|
|
36
|
+
bottom: number;
|
|
37
|
+
left: number;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The box an image draws over. After every frame the terminal shows, the
|
|
42
|
+
* image is measured again from it and kept off every cell something else drew
|
|
43
|
+
* on top of it, so it follows the layout, scrolling and clipping of that frame,
|
|
44
|
+
* goes when the box leaves the screen, and never shows over a window, menu,
|
|
45
|
+
* bar or toast that covers it.
|
|
46
|
+
*/
|
|
47
|
+
export interface NativeSurfaceAnchor {
|
|
48
|
+
renderable: NativeSurfaceRenderableNode;
|
|
49
|
+
/** Cells kept clear inside the box, as a border or padding does. */
|
|
50
|
+
insets?: CellInsets;
|
|
51
|
+
/** Part of the inset box, from its top-left cell: a crosshair strip over its chart. */
|
|
52
|
+
region?: CellRect;
|
|
53
|
+
}
|
|
54
|
+
|
|
32
55
|
export interface NativeSurfaceSnapshot {
|
|
33
56
|
id: string;
|
|
34
57
|
paneId: string;
|
|
@@ -38,6 +61,7 @@ export interface NativeSurfaceSnapshot {
|
|
|
38
61
|
bitmapKey: string;
|
|
39
62
|
/** Kitty stacking order; defaults to the plot layer. */
|
|
40
63
|
imageZIndex?: number;
|
|
64
|
+
anchor?: NativeSurfaceAnchor;
|
|
41
65
|
}
|
|
42
66
|
|
|
43
67
|
interface SurfaceEntry {
|
|
@@ -89,15 +113,150 @@ function sameWindowState(a: NativeWindowState, b: NativeWindowState): boolean {
|
|
|
89
113
|
return true;
|
|
90
114
|
}
|
|
91
115
|
|
|
116
|
+
function sameInsets(a: CellInsets | undefined, b: CellInsets | undefined): boolean {
|
|
117
|
+
if (a === b) return true;
|
|
118
|
+
if (!a || !b) return false;
|
|
119
|
+
return a.top === b.top && a.right === b.right && a.bottom === b.bottom && a.left === b.left;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function sameAnchor(a: NativeSurfaceAnchor | undefined, b: NativeSurfaceAnchor | undefined): boolean {
|
|
123
|
+
if (a === b) return true;
|
|
124
|
+
if (!a || !b) return false;
|
|
125
|
+
return a.renderable === b.renderable
|
|
126
|
+
&& sameInsets(a.insets, b.insets)
|
|
127
|
+
&& sameCellRect(a.region ?? null, b.region ?? null);
|
|
128
|
+
}
|
|
129
|
+
|
|
92
130
|
function sameSnapshot(a: NativeSurfaceSnapshot, b: NativeSurfaceSnapshot): boolean {
|
|
93
131
|
return a.id === b.id
|
|
94
132
|
&& a.paneId === b.paneId
|
|
95
133
|
&& a.bitmapKey === b.bitmapKey
|
|
96
134
|
&& a.imageZIndex === b.imageZIndex
|
|
135
|
+
&& sameAnchor(a.anchor, b.anchor)
|
|
97
136
|
&& sameCellRect(a.rect, b.rect)
|
|
98
137
|
&& sameCellRect(a.visibleRect, b.visibleRect);
|
|
99
138
|
}
|
|
100
139
|
|
|
140
|
+
export function insetCellRect(rect: CellRect, insets: CellInsets | undefined): CellRect | null {
|
|
141
|
+
if (!insets) return rect;
|
|
142
|
+
const width = rect.width - insets.left - insets.right;
|
|
143
|
+
const height = rect.height - insets.top - insets.bottom;
|
|
144
|
+
if (width <= 0 || height <= 0) return null;
|
|
145
|
+
return { x: rect.x + insets.left, y: rect.y + insets.top, width, height };
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Where an anchored image is in the frame just drawn: its box (or the part of
|
|
150
|
+
* it the region names) and the cells of it its ancestors leave on screen, none
|
|
151
|
+
* once the box is hidden, destroyed or out of the tree.
|
|
152
|
+
*/
|
|
153
|
+
function measureNativeSurfaceAnchor(
|
|
154
|
+
anchor: NativeSurfaceAnchor,
|
|
155
|
+
terminalWidth: number,
|
|
156
|
+
terminalHeight: number,
|
|
157
|
+
attached: (renderable: unknown) => boolean,
|
|
158
|
+
): { rect: CellRect; visibleRect: CellRect | null } | null {
|
|
159
|
+
const box = insetCellRect(getRenderableCellRect(anchor.renderable), anchor.insets);
|
|
160
|
+
if (!box) return null;
|
|
161
|
+
const rect = anchor.region
|
|
162
|
+
? { x: box.x + anchor.region.x, y: box.y + anchor.region.y, width: anchor.region.width, height: anchor.region.height }
|
|
163
|
+
: box;
|
|
164
|
+
if (!attached(anchor.renderable)) return { rect, visibleRect: null };
|
|
165
|
+
const outer = resolveNativeSurfaceVisibleRect(anchor.renderable, terminalWidth, terminalHeight);
|
|
166
|
+
return { rect, visibleRect: outer ? intersectCellRects(rect, outer) : null };
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** The renderable a pane window carries its pane id on. */
|
|
170
|
+
const PANE_ID_PROPERTY = "data-gloom-pane-id";
|
|
171
|
+
const MAX_ANCESTOR_DEPTH = 256;
|
|
172
|
+
/** More pieces than this means something scattered covers the image: it is hidden instead. */
|
|
173
|
+
const MAX_UNCOVERED_FRAGMENTS = 128;
|
|
174
|
+
|
|
175
|
+
type ParentedNode = { parent?: unknown } | null | undefined;
|
|
176
|
+
|
|
177
|
+
function parentOf(node: unknown): unknown {
|
|
178
|
+
return node && typeof node === "object" ? (node as ParentedNode)?.parent ?? null : null;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Whether a renderable the frame drew on top of an anchored image covers it.
|
|
183
|
+
* The image's own pane draws over its charts on purpose (legends, toolbars,
|
|
184
|
+
* axis labels): only its explicit local occluders cut those. Anything else
|
|
185
|
+
* covers the image where it or a box it sits in fills its cells, up to the
|
|
186
|
+
* first box the image also sits in: a window, a menu, a bar, a toast. A
|
|
187
|
+
* see-through layer (a click catcher) does not, and text without a background
|
|
188
|
+
* draws over the image anyway.
|
|
189
|
+
*/
|
|
190
|
+
function createCoverTest(
|
|
191
|
+
anchor: NativeSurfaceRenderableNode,
|
|
192
|
+
paints: (renderable: unknown) => boolean,
|
|
193
|
+
): (hit: unknown) => boolean {
|
|
194
|
+
// The image's ancestors up to its pane window hold its own pane's drawing;
|
|
195
|
+
// the ones above it hold everything else.
|
|
196
|
+
const chain: unknown[] = [];
|
|
197
|
+
let home = -1;
|
|
198
|
+
let node = parentOf(anchor);
|
|
199
|
+
for (let depth = 0; node && depth < MAX_ANCESTOR_DEPTH; depth += 1) {
|
|
200
|
+
chain.push(node);
|
|
201
|
+
if (home < 0 && typeof (node as Record<string, unknown>)[PANE_ID_PROPERTY] === "string") home = chain.length - 1;
|
|
202
|
+
node = parentOf(node);
|
|
203
|
+
}
|
|
204
|
+
// Outside any pane, what the image's own component draws beside it is its own.
|
|
205
|
+
if (home < 0) home = chain.length > 0 ? 0 : -1;
|
|
206
|
+
const own = new Set<unknown>([anchor, ...chain.slice(0, home + 1)]);
|
|
207
|
+
const shared = new Set<unknown>(chain.slice(home + 1));
|
|
208
|
+
const known = new Map<unknown, boolean>();
|
|
209
|
+
return (hit) => {
|
|
210
|
+
if (hit == null || hit === anchor) return false;
|
|
211
|
+
const cached = known.get(hit);
|
|
212
|
+
if (cached !== undefined) return cached;
|
|
213
|
+
let covers = false;
|
|
214
|
+
let current: unknown = hit;
|
|
215
|
+
for (let depth = 0; current && depth < MAX_ANCESTOR_DEPTH; depth += 1) {
|
|
216
|
+
if (own.has(current)) {
|
|
217
|
+
covers = false;
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
if (shared.has(current)) break;
|
|
221
|
+
if (paints(current)) covers = true;
|
|
222
|
+
current = parentOf(current);
|
|
223
|
+
}
|
|
224
|
+
known.set(hit, covers);
|
|
225
|
+
return covers;
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* The cells of `rect` nothing covers, as rectangles: runs of uncovered cells
|
|
231
|
+
* row by row, a run that lines up with the one above it extending it down.
|
|
232
|
+
*/
|
|
233
|
+
function uncoveredCellRects(rect: CellRect, covered: (x: number, y: number) => boolean): CellRect[] {
|
|
234
|
+
const done: CellRect[] = [];
|
|
235
|
+
let open: CellRect[] = [];
|
|
236
|
+
const right = rect.x + rect.width;
|
|
237
|
+
for (let y = rect.y; y < rect.y + rect.height; y += 1) {
|
|
238
|
+
const next: CellRect[] = [];
|
|
239
|
+
let start = -1;
|
|
240
|
+
for (let x = rect.x; x <= right; x += 1) {
|
|
241
|
+
const free = x < right && !covered(x, y);
|
|
242
|
+
if (free && start < 0) start = x;
|
|
243
|
+
if (!free && start >= 0) {
|
|
244
|
+
const above = open.find((candidate) => candidate.x === start && candidate.x + candidate.width === x);
|
|
245
|
+
if (above) {
|
|
246
|
+
above.height += 1;
|
|
247
|
+
next.push(above);
|
|
248
|
+
} else {
|
|
249
|
+
next.push({ x: start, y, width: x - start, height: 1 });
|
|
250
|
+
}
|
|
251
|
+
start = -1;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
for (const candidate of open) if (!next.includes(candidate)) done.push(candidate);
|
|
255
|
+
open = next;
|
|
256
|
+
}
|
|
257
|
+
return [...done, ...open];
|
|
258
|
+
}
|
|
259
|
+
|
|
101
260
|
export function computeSurfaceVisibleFragments(
|
|
102
261
|
rect: CellRect,
|
|
103
262
|
visibleRect: CellRect | null,
|
|
@@ -126,7 +285,16 @@ export class NativeSurfaceManager {
|
|
|
126
285
|
private readonly surfaces = new Map<string, SurfaceEntry>();
|
|
127
286
|
private readonly localOccluders = new Map<string, NativeLocalOccluder>();
|
|
128
287
|
|
|
129
|
-
|
|
288
|
+
private readonly onFrame = () => {
|
|
289
|
+
if (this.surfaces.size === 0) return;
|
|
290
|
+
this.frameSync();
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
constructor(private readonly renderer: CliRenderer) {
|
|
294
|
+
// Only a terminal host reports what its frames drew; then every frame it
|
|
295
|
+
// shows re-measures the anchored images and re-cuts them all.
|
|
296
|
+
if (renderer.frameHits && typeof renderer.on === "function") renderer.on("frame", this.onFrame);
|
|
297
|
+
}
|
|
130
298
|
|
|
131
299
|
setWindowState(windowState: NativeWindowState) {
|
|
132
300
|
if (sameWindowState(this.windowState, windowState)) {
|
|
@@ -139,7 +307,10 @@ export class NativeSurfaceManager {
|
|
|
139
307
|
this.syncAll();
|
|
140
308
|
}
|
|
141
309
|
|
|
142
|
-
upsertSurface(
|
|
310
|
+
upsertSurface(incoming: NativeSurfaceSnapshot) {
|
|
311
|
+
// An anchored image goes where its box is in the frame on screen, which
|
|
312
|
+
// the rect React measured before that frame's layout can trail.
|
|
313
|
+
const snapshot = this.onScreen(incoming);
|
|
143
314
|
const existing = this.surfaces.get(snapshot.id);
|
|
144
315
|
if (existing) {
|
|
145
316
|
if (sameSnapshot(existing.snapshot, snapshot)) {
|
|
@@ -208,21 +379,56 @@ export class NativeSurfaceManager {
|
|
|
208
379
|
return [...this.surfaces.values()]
|
|
209
380
|
.map(({ snapshot }) => ({ snapshot, zIndex: this.paneZIndex(snapshot.paneId) }))
|
|
210
381
|
.sort((a, b) => a.zIndex - b.zIndex || (a.snapshot.imageZIndex ?? 0) - (b.snapshot.imageZIndex ?? 0))
|
|
211
|
-
.map(({ snapshot
|
|
382
|
+
.map(({ snapshot }) => ({
|
|
212
383
|
rect: snapshot.rect,
|
|
213
|
-
fragments:
|
|
384
|
+
fragments: this.visibleFragments(snapshot, occluders),
|
|
214
385
|
bitmap: snapshot.bitmap,
|
|
215
386
|
}))
|
|
216
387
|
.filter((image) => image.fragments.length > 0);
|
|
217
388
|
}
|
|
218
389
|
|
|
219
390
|
destroy() {
|
|
391
|
+
if (this.renderer.frameHits && typeof this.renderer.off === "function") this.renderer.off("frame", this.onFrame);
|
|
220
392
|
for (const id of [...this.surfaces.keys()]) {
|
|
221
393
|
this.removeSurface(id);
|
|
222
394
|
}
|
|
223
395
|
this.localOccluders.clear();
|
|
224
396
|
}
|
|
225
397
|
|
|
398
|
+
/** After a frame: each anchored image where its box is now, each image off what now covers it. */
|
|
399
|
+
private frameSync() {
|
|
400
|
+
for (const entry of this.surfaces.values()) {
|
|
401
|
+
entry.snapshot = this.onScreen(entry.snapshot);
|
|
402
|
+
this.syncSurface(entry);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
/** An anchored snapshot measured from its box as the frame on screen laid it out. */
|
|
407
|
+
private onScreen(snapshot: NativeSurfaceSnapshot): NativeSurfaceSnapshot {
|
|
408
|
+
const attached = this.renderer.frameHits?.attached;
|
|
409
|
+
if (!snapshot.anchor || !attached) return snapshot;
|
|
410
|
+
const measured = measureNativeSurfaceAnchor(snapshot.anchor, this.renderer.terminalWidth, this.renderer.terminalHeight, attached);
|
|
411
|
+
if (!measured) return snapshot.visibleRect === null ? snapshot : { ...snapshot, visibleRect: null };
|
|
412
|
+
if (sameCellRect(measured.rect, snapshot.rect) && sameCellRect(measured.visibleRect, snapshot.visibleRect)) return snapshot;
|
|
413
|
+
return { ...snapshot, rect: measured.rect, visibleRect: measured.visibleRect };
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/** The cells of an image left to show: its visible rect, less the layout's occluders and whatever the frame drew over it. */
|
|
417
|
+
private visibleFragments(snapshot: NativeSurfaceSnapshot, occluders: NativeOccluder[]): CellRect[] {
|
|
418
|
+
const fragments = computeSurfaceVisibleFragments(
|
|
419
|
+
snapshot.rect,
|
|
420
|
+
snapshot.visibleRect,
|
|
421
|
+
this.paneZIndex(snapshot.paneId),
|
|
422
|
+
snapshot.paneId,
|
|
423
|
+
occluders,
|
|
424
|
+
);
|
|
425
|
+
const hits = this.renderer.frameHits;
|
|
426
|
+
if (!hits || !snapshot.anchor || fragments.length === 0) return fragments;
|
|
427
|
+
const covers = createCoverTest(snapshot.anchor.renderable, hits.paints);
|
|
428
|
+
const uncovered = fragments.flatMap((fragment) => uncoveredCellRects(fragment, (x, y) => covers(hits.at(x, y))));
|
|
429
|
+
return uncovered.length > MAX_UNCOVERED_FRAGMENTS ? [] : uncovered.sort(compareRects);
|
|
430
|
+
}
|
|
431
|
+
|
|
226
432
|
private paneZIndex(paneId: string): number {
|
|
227
433
|
return this.windowState.paneLayers.find((layer) => layer.paneId === paneId)?.zIndex ?? 0;
|
|
228
434
|
}
|
|
@@ -249,13 +455,7 @@ export class NativeSurfaceManager {
|
|
|
249
455
|
return;
|
|
250
456
|
}
|
|
251
457
|
|
|
252
|
-
const fragments =
|
|
253
|
-
entry.snapshot.rect,
|
|
254
|
-
entry.snapshot.visibleRect,
|
|
255
|
-
this.paneZIndex(entry.snapshot.paneId),
|
|
256
|
-
entry.snapshot.paneId,
|
|
257
|
-
this.resolvedOccluders(),
|
|
258
|
-
);
|
|
458
|
+
const fragments = this.visibleFragments(entry.snapshot, this.resolvedOccluders());
|
|
259
459
|
|
|
260
460
|
const placements = computeNativePlacements(
|
|
261
461
|
entry.snapshot.rect,
|
|
@@ -65,7 +65,6 @@ export function CommandBarPanel({
|
|
|
65
65
|
onThemeCommit,
|
|
66
66
|
onThemePreview,
|
|
67
67
|
panelBounds,
|
|
68
|
-
clearBounds = null,
|
|
69
68
|
queryDisplayWidth,
|
|
70
69
|
rootGhostSuffix,
|
|
71
70
|
rootShortcutFeedback,
|
|
@@ -136,6 +135,8 @@ export function CommandBarPanel({
|
|
|
136
135
|
return (
|
|
137
136
|
// The click-away overlay starts where the sheet does: the header above it
|
|
138
137
|
// holds the bar's input, and a click there must reach it, not close the bar.
|
|
138
|
+
// It draws nothing: the panes beside and below the sheet stay as they are,
|
|
139
|
+
// a chart image among them too, and only the sheet covers them.
|
|
139
140
|
<Box
|
|
140
141
|
position="absolute"
|
|
141
142
|
top={panelBounds.y}
|
|
@@ -149,18 +150,6 @@ export function CommandBarPanel({
|
|
|
149
150
|
onOverlayClose();
|
|
150
151
|
}}
|
|
151
152
|
>
|
|
152
|
-
{/* The terminal sheet's rows are its own, edge to edge: no piece of a pane shows at its sides. */}
|
|
153
|
-
{clearBounds && (
|
|
154
|
-
<Box
|
|
155
|
-
position="absolute"
|
|
156
|
-
top={clearBounds.y}
|
|
157
|
-
left={clearBounds.x}
|
|
158
|
-
width={clearBounds.width}
|
|
159
|
-
height={clearBounds.height}
|
|
160
|
-
backgroundColor={palette.panelBg}
|
|
161
|
-
zIndex={100}
|
|
162
|
-
/>
|
|
163
|
-
)}
|
|
164
153
|
<Box
|
|
165
154
|
position="absolute"
|
|
166
155
|
top={0}
|
|
@@ -27,13 +27,8 @@ export interface CommandBarPanelLayout {
|
|
|
27
27
|
listBodyHeight: number;
|
|
28
28
|
nativeOccluderRect: LayoutBounds;
|
|
29
29
|
nativePanelPaddingColumns: number;
|
|
30
|
+
/** The sheet, the one thing the open bar covers: the panes beside and below it stay as they are. */
|
|
30
31
|
panelBounds: LayoutBounds;
|
|
31
|
-
/**
|
|
32
|
-
* The rows the terminal sheet clears behind it, relative to its top, edge
|
|
33
|
-
* to edge: a pane cut by the sheet's sides shows only pieces of its words
|
|
34
|
-
* and borders. Null on the desktop, whose sheet is a floating surface.
|
|
35
|
-
*/
|
|
36
|
-
clearBounds: LayoutBounds | null;
|
|
37
32
|
queryDisplayWidth: number;
|
|
38
33
|
labelWidth: number;
|
|
39
34
|
trailingWidth: number;
|
|
@@ -154,7 +149,6 @@ export function resolveCommandBarPanelLayout({
|
|
|
154
149
|
width: barWidth,
|
|
155
150
|
height: barHeight,
|
|
156
151
|
},
|
|
157
|
-
clearBounds: nativePaneChrome ? null : { x: 0, y: 0, width: termWidth, height: barHeight },
|
|
158
152
|
queryDisplayWidth,
|
|
159
153
|
labelWidth,
|
|
160
154
|
trailingWidth,
|
|
@@ -214,7 +214,6 @@ export function useCommandBarPanelRuntime({
|
|
|
214
214
|
onThemeCommit: handleThemeCommit,
|
|
215
215
|
onThemePreview: applyThemePreview,
|
|
216
216
|
panelBounds: panelLayout.panelBounds,
|
|
217
|
-
clearBounds: panelLayout.clearBounds,
|
|
218
217
|
queryDisplayWidth: panelLayout.queryDisplayWidth,
|
|
219
218
|
rootGhostSuffix,
|
|
220
219
|
rootShortcutFeedback,
|
|
@@ -30,8 +30,6 @@ export interface CommandBarPanelProps {
|
|
|
30
30
|
onThemeCommit: (themeId: string) => void;
|
|
31
31
|
onThemePreview: (themeId: string | null) => void;
|
|
32
32
|
panelBounds: LayoutBounds;
|
|
33
|
-
/** What the terminal sheet clears behind it (see CommandBarPanelLayout); null on the desktop. */
|
|
34
|
-
clearBounds?: LayoutBounds | null;
|
|
35
33
|
queryDisplayWidth: number;
|
|
36
34
|
rootGhostSuffix: string | null;
|
|
37
35
|
rootShortcutFeedback: string | null;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { useMemo, useRef } from "react";
|
|
2
|
+
import { t, tf } from "../../i18n";
|
|
3
|
+
import type { ContextMenuItem } from "../../types/context-menu";
|
|
4
|
+
import { useOptionalDialog, type PromptContext } from "../../ui/dialog";
|
|
5
|
+
import { logFailure } from "../../utils/log-failure";
|
|
6
|
+
import { ChoiceDialog } from "../ui/choice-dialog";
|
|
7
|
+
import type { DataTableColumn } from "../ui";
|
|
8
|
+
|
|
9
|
+
const NO_ITEMS: readonly ContextMenuItem[] = [];
|
|
10
|
+
|
|
11
|
+
function columnName(column: DataTableColumn): string {
|
|
12
|
+
return column.label.trim() || column.title || column.id;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The pane menu's column entries while the table is focused: "Move Column…"
|
|
17
|
+
* does a header drag from the keyboard (a column, then the one it should
|
|
18
|
+
* follow), and "Reset Columns" puts the pane's own order back once the reader
|
|
19
|
+
* has changed it.
|
|
20
|
+
*/
|
|
21
|
+
export function useDataTableColumnMenuItems({
|
|
22
|
+
enabled,
|
|
23
|
+
columns,
|
|
24
|
+
anchoredColumns,
|
|
25
|
+
onColumnMove,
|
|
26
|
+
customized,
|
|
27
|
+
reset,
|
|
28
|
+
}: {
|
|
29
|
+
enabled: boolean;
|
|
30
|
+
columns: readonly DataTableColumn[];
|
|
31
|
+
anchoredColumns: number;
|
|
32
|
+
onColumnMove?: (columnId: string, toIndex: number) => void;
|
|
33
|
+
customized: boolean;
|
|
34
|
+
reset: () => void;
|
|
35
|
+
}): readonly ContextMenuItem[] {
|
|
36
|
+
const dialog = useOptionalDialog();
|
|
37
|
+
const latest = useRef({ columns, anchoredColumns, onColumnMove });
|
|
38
|
+
latest.current = { columns, anchoredColumns, onColumnMove };
|
|
39
|
+
const movable = !!onColumnMove && columns.length - anchoredColumns >= 2;
|
|
40
|
+
|
|
41
|
+
return useMemo(() => {
|
|
42
|
+
if (!enabled || !movable) return NO_ITEMS;
|
|
43
|
+
const move = async () => {
|
|
44
|
+
if (!dialog) return;
|
|
45
|
+
const current = latest.current;
|
|
46
|
+
const columnId = await dialog.prompt<string>({
|
|
47
|
+
closeOnClickOutside: true,
|
|
48
|
+
content: (ctx: PromptContext<string>) => (
|
|
49
|
+
<ChoiceDialog
|
|
50
|
+
{...ctx}
|
|
51
|
+
title={t("Move Column")}
|
|
52
|
+
choices={current.columns.slice(current.anchoredColumns).map((column) => ({ id: column.id, label: columnName(column) }))}
|
|
53
|
+
/>
|
|
54
|
+
),
|
|
55
|
+
});
|
|
56
|
+
const from = current.columns.findIndex((column) => column.id === columnId);
|
|
57
|
+
if (!columnId || from < 0) return;
|
|
58
|
+
// After the column it should follow: the one it follows now is chosen to begin with.
|
|
59
|
+
const others = current.columns.filter((column) => column.id !== columnId);
|
|
60
|
+
const start = Math.max(0, current.anchoredColumns - 1);
|
|
61
|
+
const target = await dialog.prompt<string>({
|
|
62
|
+
closeOnClickOutside: true,
|
|
63
|
+
content: (ctx: PromptContext<string>) => (
|
|
64
|
+
<ChoiceDialog
|
|
65
|
+
{...ctx}
|
|
66
|
+
title={tf("Move {column}", { column: columnName(current.columns[from]!) })}
|
|
67
|
+
selectedChoiceId={String(from)}
|
|
68
|
+
choices={[
|
|
69
|
+
...current.anchoredColumns === 0 ? [{ id: "0", label: t("First") }] : [],
|
|
70
|
+
...others.slice(start).map((column, index) => ({
|
|
71
|
+
id: String(start + index + 1),
|
|
72
|
+
label: tf("After {column}", { column: columnName(column) }),
|
|
73
|
+
})),
|
|
74
|
+
]}
|
|
75
|
+
/>
|
|
76
|
+
),
|
|
77
|
+
});
|
|
78
|
+
if (target) latest.current.onColumnMove?.(columnId, Number(target));
|
|
79
|
+
};
|
|
80
|
+
return [
|
|
81
|
+
...dialog ? [{
|
|
82
|
+
id: "move-column",
|
|
83
|
+
label: "Move Column…",
|
|
84
|
+
onSelect: () => move().catch(logFailure("data-table", "Move Column failed")),
|
|
85
|
+
}] : [],
|
|
86
|
+
...customized ? [{ id: "reset-columns", label: "Reset Columns", onSelect: reset }] : [],
|
|
87
|
+
];
|
|
88
|
+
}, [customized, dialog, enabled, movable, reset]);
|
|
89
|
+
}
|