@gloom-sh/terminal 0.20.9 → 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/auth.ts +6 -0
- package/src/api-client/data.ts +1 -0
- package/src/api-client/earnings.ts +15 -0
- package/src/api-client/index.ts +14 -3
- 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/api-client/types/account.ts +10 -0
- package/src/api-client/types/billing.ts +10 -0
- package/src/api-client/types/econ.ts +19 -7
- package/src/api-client/types/market.ts +7 -0
- package/src/api-client/types/screener.ts +2 -0
- 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/cli/commands/market.ts +18 -8
- package/src/cli/commands/overview.ts +26 -7
- package/src/cli/commands/ticker.ts +40 -15
- package/src/cli/desktop-pane-shot.ts +39 -0
- package/src/cli/errors.ts +20 -3
- package/src/cli/fx-pair.ts +11 -2
- package/src/cli/history-rows.ts +34 -3
- package/src/cli/index.ts +1 -1
- package/src/cli/listing-arg.ts +51 -13
- package/src/cli/pane-functions/headless.ts +4 -2
- package/src/cli/pane-functions/index.ts +1 -0
- package/src/cli/pane-functions/resolver.ts +2 -1
- package/src/cli/pane-functions/screenshot-assessment.ts +73 -5
- package/src/cli/pane-functions/screenshot-types.ts +4 -0
- package/src/components/chart/composite/chart-layout.ts +7 -4
- package/src/components/chart/composite/composite-chart.tsx +6 -16
- package/src/components/chart/composite/toolbar.tsx +258 -82
- package/src/components/chart/composite/use-composite-chart-keyboard.ts +5 -6
- 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/list/model.ts +13 -0
- 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/command-bar/routes/ticker-search/actions.ts +2 -0
- package/src/components/command-bar/routes/ticker-search/results.ts +15 -8
- package/src/components/command-bar/surface/index.tsx +10 -5
- package/src/components/command-bar/workflow/alert.ts +21 -7
- 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/table-pane.ts +3 -1
- 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 +88 -21
- 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/metric-treemap/heat-surface.tsx +2 -1
- package/src/components/metric-treemap/index.tsx +3 -2
- package/src/components/ticker/list-table-view.tsx +5 -0
- package/src/components/ui/confirm-dialog.tsx +253 -7
- package/src/components/ui/data-table/column-order.ts +180 -0
- package/src/components/ui/data-table/index.tsx +13 -2
- 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 +56 -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/list-view.tsx +4 -3
- package/src/components/ui/status.tsx +9 -6
- package/src/components/ui/table-layout.ts +120 -0
- package/src/docs/snapshot.json +39 -2
- package/src/i18n/es.ts +14 -0
- package/src/i18n/ja.ts +14 -0
- package/src/i18n/ko.ts +14 -0
- package/src/i18n/zh-cn.ts +14 -0
- package/src/i18n/zh-tw.ts +14 -0
- package/src/market-data/coordinator/index.ts +4 -3
- package/src/market-data/coordinator/quotes.ts +12 -4
- package/src/market-data/fx-closes.ts +14 -2
- package/src/market-data/market/change-basis.ts +35 -1
- package/src/market-data/market/status.ts +37 -0
- package/src/market-data/performance.ts +4 -1
- package/src/market-data/quotes/freshness.ts +12 -0
- package/src/market-data/quotes/live-valuation.ts +26 -3
- package/src/market-data/quotes/regular-session-valuation.ts +1 -1
- package/src/market-data/realized-volatility.ts +3 -0
- package/src/market-data/us-bond-market.ts +115 -0
- package/src/plugins/builtin/account-management/invite-row.tsx +54 -0
- package/src/plugins/builtin/account-management/keyboard.ts +3 -0
- package/src/plugins/builtin/account-management/model.ts +1 -0
- package/src/plugins/builtin/account-management/pane.tsx +51 -5
- package/src/plugins/builtin/account-management/trial-cancel.ts +32 -7
- 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/pane-session.ts +94 -0
- package/src/plugins/builtin/cloud/askg/pane.tsx +40 -83
- package/src/plugins/builtin/cloud/askg/tool-timeline.tsx +2 -0
- package/src/plugins/builtin/congress-trades/pane.tsx +8 -2
- package/src/plugins/builtin/correlation/compute.ts +4 -3
- package/src/plugins/builtin/earnings/board-model.ts +33 -0
- package/src/plugins/builtin/earnings/board-table.ts +50 -11
- package/src/plugins/builtin/earnings/board.tsx +29 -13
- package/src/plugins/builtin/earnings/calendar.tsx +15 -3
- package/src/plugins/builtin/earnings/client.ts +4 -1
- package/src/plugins/builtin/earnings/headless.ts +27 -14
- package/src/plugins/builtin/econ/calendar-source.ts +3 -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/help/index.tsx +1 -1
- package/src/plugins/builtin/holders/pane.tsx +30 -20
- package/src/plugins/builtin/ipo-calendar/model.ts +3 -3
- package/src/plugins/builtin/iv-history/events.ts +5 -0
- package/src/plugins/builtin/iv-history/headless.ts +19 -12
- package/src/plugins/builtin/kelly-sizer/sections.tsx +2 -0
- package/src/plugins/builtin/macro-day/headless.ts +27 -8
- package/src/plugins/builtin/macro-day/model.ts +17 -4
- package/src/plugins/builtin/macro-day/releases.ts +36 -15
- package/src/plugins/builtin/market-halts/model.ts +3 -2
- package/src/plugins/builtin/market-movers/headless.ts +2 -1
- package/src/plugins/builtin/market-movers/index.tsx +3 -2
- package/src/plugins/builtin/market-movers/model.ts +75 -22
- package/src/plugins/builtin/market-movers/screener.ts +2 -1
- package/src/plugins/builtin/market-movers/table.ts +7 -5
- package/src/plugins/builtin/options/view.tsx +2 -0
- package/src/plugins/builtin/options-scenario/pane.tsx +2 -1
- package/src/plugins/builtin/pe-band/model.ts +4 -0
- package/src/plugins/builtin/perps/cascade-tabs.tsx +2 -1
- package/src/plugins/builtin/portfolio-list/cell-version.ts +4 -4
- package/src/plugins/builtin/portfolio-list/cli/render.ts +9 -4
- package/src/plugins/builtin/portfolio-list/pane/index.tsx +15 -1
- package/src/plugins/builtin/portfolio-list/summary/index.tsx +24 -7
- package/src/plugins/builtin/portfolio-list/summary/totals.ts +40 -11
- package/src/plugins/builtin/portfolio-list/table.tsx +18 -1
- package/src/plugins/builtin/rate-path/pane.tsx +2 -0
- package/src/plugins/builtin/research/analyst-headless.ts +9 -1
- package/src/plugins/builtin/research/analyst-pane.tsx +10 -4
- package/src/plugins/builtin/research/client.ts +25 -1
- package/src/plugins/builtin/research/corporate-actions-pane.tsx +2 -1
- package/src/plugins/builtin/research/event-model.ts +3 -13
- package/src/plugins/builtin/research/event-sources.ts +3 -1
- 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/short-interest/headless.ts +2 -0
- package/src/plugins/builtin/short-interest/publications-headless.ts +2 -0
- package/src/plugins/builtin/short-interest/watch-headless.ts +1 -0
- 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/headless.ts +5 -1
- package/src/plugins/builtin/yield-curve/index.tsx +7 -1
- package/src/portfolio/column-values.ts +47 -14
- package/src/portfolio/return-metrics.ts +4 -2
- 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/host/image-surface.tsx +19 -9
- package/src/renderers/dom/host/input.tsx +4 -0
- package/src/renderers/dom/styles.css +22 -0
- package/src/renderers/electrobun/view/cli-pane-shot-entry.tsx +23 -1
- 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/sources/gloomberb-cloud/normalizers.ts +2 -0
- package/src/sources/provider-errors.ts +12 -0
- package/src/sources/provider-router/index.ts +12 -4
- package/src/state/app/context/index.tsx +22 -0
- package/src/state/pane-session.ts +145 -0
- package/src/test-support/app-store.ts +24 -1
- package/src/tickers/search/home-listing.ts +44 -1
- package/src/tickers/search/index.ts +5 -2
- package/src/tickers/search/ranking.ts +7 -7
- package/src/tickers/us-listing.ts +11 -5
- package/src/time-series/base-series.ts +7 -1
- package/src/time-series/fundamentals/current-valuation.ts +8 -0
- package/src/time-series/fundamentals/series.ts +6 -0
- package/src/time-series/live-quotes.ts +3 -9
- package/src/time-series/resolve.ts +1 -0
- package/src/types/financials.ts +20 -0
- package/src/types/headless.ts +9 -0
- package/src/ui/host.tsx +20 -0
- package/src/ui/pointer-drag.ts +11 -2
- package/src/utils/exchanges.ts +13 -8
- package/src/utils/fundamentals.ts +14 -3
- package/src/utils/price-earnings.ts +17 -10
- package/src/utils/price-history-integrity.ts +15 -0
- package/src/utils/reason-codes.ts +79 -0
- package/src/utils/share-multiples.cases.json +1667 -0
- package/src/utils/share-multiples.ts +384 -0
- package/src/utils/untrusted-text.ts +11 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** @jsxImportSource react */
|
|
2
|
-
import { memo, type CSSProperties, type ReactNode } from "react";
|
|
2
|
+
import { memo, type CSSProperties, type MouseEvent as ReactMouseEvent, type ReactNode } from "react";
|
|
3
3
|
import { TextAttributes } from "../../../ui/host";
|
|
4
4
|
import { DisclosureMarker } from "../../../components/ui/disclosure-marker";
|
|
5
5
|
import type {
|
|
@@ -84,6 +84,9 @@ export function WebDataTableHeader<C extends DataTableColumn>({
|
|
|
84
84
|
onTableMouseDown,
|
|
85
85
|
gridTemplateColumns,
|
|
86
86
|
onHeaderClick,
|
|
87
|
+
onMovableHeaderPress,
|
|
88
|
+
anchoredColumns = 1,
|
|
89
|
+
draggedColumn = null,
|
|
87
90
|
sortColumnId,
|
|
88
91
|
sortDirection,
|
|
89
92
|
}: {
|
|
@@ -97,6 +100,11 @@ export function WebDataTableHeader<C extends DataTableColumn>({
|
|
|
97
100
|
onTableMouseDown?: (event: any) => void;
|
|
98
101
|
gridTemplateColumns: string;
|
|
99
102
|
onHeaderClick?: (columnId: string) => void;
|
|
103
|
+
/** A left press on a header past the anchored ones, which sorts on release or drags the column (useWebColumnDrag). */
|
|
104
|
+
onMovableHeaderPress?: (columnId: string, index: number, event: ReactMouseEvent<HTMLElement>) => void;
|
|
105
|
+
anchoredColumns?: number;
|
|
106
|
+
/** The column being dragged, drawn lifted. */
|
|
107
|
+
draggedColumn?: number | null;
|
|
100
108
|
sortColumnId: string | null;
|
|
101
109
|
sortDirection: "asc" | "desc";
|
|
102
110
|
}) {
|
|
@@ -125,11 +133,21 @@ export function WebDataTableHeader<C extends DataTableColumn>({
|
|
|
125
133
|
{columns.map((column, columnIndex) => {
|
|
126
134
|
const isSorted = sortColumnId === column.id;
|
|
127
135
|
const color = isSorted ? CSS_TEXT : column.headerColor ?? CSS_TEXT_DIM;
|
|
136
|
+
const pressMovable = columnIndex >= anchoredColumns ? onMovableHeaderPress : undefined;
|
|
137
|
+
const movable = pressMovable !== undefined;
|
|
138
|
+
const sortOnPress = onHeaderClick ? (event: ReactMouseEvent<HTMLElement>) => {
|
|
139
|
+
focusPane();
|
|
140
|
+
onTableMouseDown?.(event);
|
|
141
|
+
event.preventDefault();
|
|
142
|
+
onHeaderClick(column.id);
|
|
143
|
+
} : undefined;
|
|
128
144
|
return (
|
|
129
145
|
<div
|
|
130
146
|
key={column.id}
|
|
131
147
|
data-gloom-role="data-table-header-cell"
|
|
132
|
-
data-gloom-interactive={onHeaderClick ? "true" : undefined}
|
|
148
|
+
data-gloom-interactive={onHeaderClick || movable ? "true" : undefined}
|
|
149
|
+
data-gloom-movable={movable ? "true" : undefined}
|
|
150
|
+
data-gloom-dragging={draggedColumn === columnIndex ? "true" : undefined}
|
|
133
151
|
data-gloom-tinted={column.headerColor ? "true" : undefined}
|
|
134
152
|
style={{
|
|
135
153
|
minWidth: 0,
|
|
@@ -152,12 +170,16 @@ export function WebDataTableHeader<C extends DataTableColumn>({
|
|
|
152
170
|
backgroundColor: column.headerBackgroundColor ?? CSS_PANEL,
|
|
153
171
|
boxShadow: freezeFirstColumn && columnIndex === 0 ? `-${inlinePaddingPx(horizontalPadding)}px 0 0 ${column.headerBackgroundColor ?? CSS_PANEL}, ${columnGap * WEB_CELL_WIDTH}px 0 0 ${column.headerBackgroundColor ?? CSS_PANEL}` : undefined,
|
|
154
172
|
}}
|
|
155
|
-
onMouseDown={
|
|
173
|
+
onMouseDown={pressMovable ? (event) => {
|
|
174
|
+
if (event.button !== 0) {
|
|
175
|
+
sortOnPress?.(event);
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
156
178
|
focusPane();
|
|
157
179
|
onTableMouseDown?.(event);
|
|
158
180
|
event.preventDefault();
|
|
159
|
-
|
|
160
|
-
} :
|
|
181
|
+
pressMovable(column.id, columnIndex, event);
|
|
182
|
+
} : sortOnPress}
|
|
161
183
|
>
|
|
162
184
|
{column.headerLeading !== undefined ? <Leading>{column.headerLeading}</Leading> : null}
|
|
163
185
|
<span
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** @jsxImportSource react */
|
|
2
|
-
import { useState, type CSSProperties, type ReactNode } from "react";
|
|
2
|
+
import { useLayoutEffect, useRef, useState, type CSSProperties, type ReactNode } from "react";
|
|
3
3
|
import type { ImageSurfaceProps } from "../../../ui/host";
|
|
4
4
|
import { cleanDomProps, commonStyle } from "./style";
|
|
5
5
|
|
|
@@ -11,8 +11,6 @@ type ImageStatus = "loading" | "loaded" | "failed";
|
|
|
11
11
|
* empty box while it asks again.
|
|
12
12
|
*/
|
|
13
13
|
const failedImages = new Set<string>();
|
|
14
|
-
/** Images that loaded this session: a row scrolled back into view draws its picture on its first frame, not its stand-in. */
|
|
15
|
-
const loadedImages = new Set<string>();
|
|
16
14
|
const IMAGES_KEPT = 2_000;
|
|
17
15
|
|
|
18
16
|
function remember(images: Set<string>, src: string): void {
|
|
@@ -20,9 +18,17 @@ function remember(images: Set<string>, src: string): void {
|
|
|
20
18
|
images.add(src);
|
|
21
19
|
}
|
|
22
20
|
|
|
21
|
+
/**
|
|
22
|
+
* Every new image element starts loading, even for a picture that loaded
|
|
23
|
+
* before: what counts is whether this element has it to draw. One the
|
|
24
|
+
* browser still holds is complete at once, so a row scrolled back into view
|
|
25
|
+
* draws it on its first frame (see the layout effect); one it has to fetch
|
|
26
|
+
* again keeps the stand-in until it arrives. A loaded status carried over
|
|
27
|
+
* from another element drew the white plate behind an image not yet there,
|
|
28
|
+
* a blank white square in the desktop app for as long as the fetch took.
|
|
29
|
+
*/
|
|
23
30
|
function initialStatus(src: string): ImageStatus {
|
|
24
|
-
|
|
25
|
-
return loadedImages.has(src) ? "loaded" : "loading";
|
|
31
|
+
return failedImages.has(src) ? "failed" : "loading";
|
|
26
32
|
}
|
|
27
33
|
|
|
28
34
|
/**
|
|
@@ -37,6 +43,12 @@ export function WebImageSurface({ children, src, alt = "", objectFit = "contain"
|
|
|
37
43
|
// Keyed by the address it describes, so a row that takes another logo starts that one's own load.
|
|
38
44
|
const [known, setKnown] = useState<{ src: string; status: ImageStatus }>(() => ({ src: imageSrc, status: initialStatus(imageSrc) }));
|
|
39
45
|
const status = known.src === imageSrc ? known.status : initialStatus(imageSrc);
|
|
46
|
+
const imageRef = useRef<HTMLImageElement | null>(null);
|
|
47
|
+
// Before the frame is painted: a picture the browser already holds is drawn at once, not after its stand-in.
|
|
48
|
+
useLayoutEffect(() => {
|
|
49
|
+
const image = imageRef.current;
|
|
50
|
+
if (status === "loading" && image?.complete && image.naturalWidth > 0) setKnown({ src: imageSrc, status: "loaded" });
|
|
51
|
+
}, [imageSrc, status]);
|
|
40
52
|
const baseStyle = commonStyle(props);
|
|
41
53
|
const waiting = fallbackWhileLoading && status === "loading";
|
|
42
54
|
return (
|
|
@@ -53,13 +65,11 @@ export function WebImageSurface({ children, src, alt = "", objectFit = "contain"
|
|
|
53
65
|
<>
|
|
54
66
|
<img
|
|
55
67
|
key={imageSrc}
|
|
68
|
+
ref={imageRef}
|
|
56
69
|
src={imageSrc}
|
|
57
70
|
alt={alt}
|
|
58
71
|
draggable={false}
|
|
59
|
-
onLoad={() => {
|
|
60
|
-
remember(loadedImages, imageSrc);
|
|
61
|
-
setKnown({ src: imageSrc, status: "loaded" });
|
|
62
|
-
}}
|
|
72
|
+
onLoad={() => setKnown({ src: imageSrc, status: "loaded" })}
|
|
63
73
|
onError={() => {
|
|
64
74
|
remember(failedImages, imageSrc);
|
|
65
75
|
setKnown({ src: imageSrc, status: "failed" });
|
|
@@ -328,6 +328,10 @@ function useWebEditable<T extends HTMLInputElement | HTMLTextAreaElement>(
|
|
|
328
328
|
setCursorOffset: applyCursorOffset,
|
|
329
329
|
focus: () => elementRef.current?.focus(),
|
|
330
330
|
blur: () => elementRef.current?.blur(),
|
|
331
|
+
get focused() {
|
|
332
|
+
const element = elementRef.current;
|
|
333
|
+
return element != null && element.ownerDocument.activeElement === element;
|
|
334
|
+
},
|
|
331
335
|
};
|
|
332
336
|
|
|
333
337
|
const elementProps = {
|
|
@@ -1694,6 +1694,28 @@ html[data-gloom-screenshot="true"] [data-gloom-role="chart-watermark"] {
|
|
|
1694
1694
|
color: var(--gloom-text) !important;
|
|
1695
1695
|
}
|
|
1696
1696
|
|
|
1697
|
+
/* A header that moves its column takes the grab cursor, as a tab that
|
|
1698
|
+
reorders does. Dragged, it takes the hover fill and its label brightens,
|
|
1699
|
+
and an accent line through the header and rows marks the gap it drops
|
|
1700
|
+
into (renderers/dom/data-table/column-drag.ts). */
|
|
1701
|
+
[data-gloom-role="data-table-header-cell"][data-gloom-movable="true"] { cursor: grab; }
|
|
1702
|
+
[data-gloom-role="data-table-header-cell"][data-gloom-dragging="true"] {
|
|
1703
|
+
background-image: linear-gradient(var(--gloom-hover-fill), var(--gloom-hover-fill));
|
|
1704
|
+
}
|
|
1705
|
+
[data-gloom-role="data-table-header-cell"][data-gloom-dragging="true"] > * {
|
|
1706
|
+
color: var(--gloom-text-bright) !important;
|
|
1707
|
+
}
|
|
1708
|
+
[data-gloom-role="data-table-drop-indicator"] {
|
|
1709
|
+
position: absolute;
|
|
1710
|
+
top: 0;
|
|
1711
|
+
bottom: 0;
|
|
1712
|
+
width: 2px;
|
|
1713
|
+
transform: translateX(-50%);
|
|
1714
|
+
z-index: 4;
|
|
1715
|
+
pointer-events: none;
|
|
1716
|
+
background: var(--gloom-accent);
|
|
1717
|
+
}
|
|
1718
|
+
|
|
1697
1719
|
/* A link is the text around it, underlined (external-link.tsx); the pointer or keyboard focus brightens it. */
|
|
1698
1720
|
[data-gloom-link="true"] { text-underline-offset: 2px; }
|
|
1699
1721
|
[data-gloom-link="true"]:is(:hover, :focus-visible) { color: var(--gloom-link-hover) !important; }
|
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
} from "../../../cli/desktop-pane-shot-routes";
|
|
25
25
|
import { openShotApiSocket, type ShotApiSocketSend } from "./cli-pane-shot-socket";
|
|
26
26
|
import { instrumentFromTicker } from "../../../market-data/request-types";
|
|
27
|
+
import { buildQuoteKey, instrumentFromQuoteTarget } from "../../../market-data/selectors";
|
|
27
28
|
import type { RendererHost } from "../../../ui/host";
|
|
28
29
|
import { DomHostProviders } from "../../dom/dom-host-providers";
|
|
29
30
|
import { webUiHost } from "./ui-host";
|
|
@@ -328,6 +329,8 @@ function waitForShotReadiness(): () => void {
|
|
|
328
329
|
|
|
329
330
|
function createShotDataProvider(payload: DesktopPaneShotPayload): DataProvider {
|
|
330
331
|
const cloudProvider = createGloomberbCloudProvider();
|
|
332
|
+
// The instruments a stream subscription has had its one frame for.
|
|
333
|
+
const streamedQuotes = new Set<string>();
|
|
331
334
|
const bridge: Partial<DataProvider> = {
|
|
332
335
|
id: payload.marketDataProviderId ?? cloudProvider.id,
|
|
333
336
|
getQuote: (symbol, exchange, context) => requestShotMarketData<Quote>("getQuote", [symbol, exchange, context]),
|
|
@@ -371,7 +374,26 @@ function createShotDataProvider(payload: DesktopPaneShotPayload): DataProvider {
|
|
|
371
374
|
getSecFilingDocuments: (filing) => requestShotMarketData<SecFilingDocument[]>("getSecFilingDocuments", [filing]),
|
|
372
375
|
getSecFilingContent: (filing) => requestShotMarketData<string | null>("getSecFilingContent", [filing]),
|
|
373
376
|
getEarningsCalendar: (symbols) => requestShotMarketData<EarningsEvent[]>("getEarningsCalendar", [symbols]).then(reviveEarningsEvents),
|
|
374
|
-
subscribeQuotes: (
|
|
377
|
+
subscribeQuotes: (targets, onQuote) => {
|
|
378
|
+
// A capture has no stream. Each target gets the quote a poll reads, once,
|
|
379
|
+
// so a pane that streams its rows (Market Movers with live on) shows them
|
|
380
|
+
// as its user sees them, not as its list alone draws them.
|
|
381
|
+
const fresh = targets.filter((target) => {
|
|
382
|
+
const key = buildQuoteKey(instrumentFromQuoteTarget(target));
|
|
383
|
+
if (streamedQuotes.has(key)) return false;
|
|
384
|
+
streamedQuotes.add(key);
|
|
385
|
+
return true;
|
|
386
|
+
});
|
|
387
|
+
if (fresh.length > 0) {
|
|
388
|
+
void requestShotMarketData<QuoteBatchResult[]>("getQuotesBatch", [fresh, {}])
|
|
389
|
+
.then((results) => results.forEach((result, index) => {
|
|
390
|
+
const target = fresh[index];
|
|
391
|
+
if (target && result?.quote) onQuote(target, result.quote);
|
|
392
|
+
}))
|
|
393
|
+
.catch(logFailure("desktop-pane-shot", "Could not load the quotes a pane streams for a screenshot"));
|
|
394
|
+
}
|
|
395
|
+
return () => {};
|
|
396
|
+
},
|
|
375
397
|
};
|
|
376
398
|
const fallback = new Proxy(cloudProvider, {
|
|
377
399
|
get(target, property) {
|
|
@@ -133,6 +133,7 @@ export const OpenTuiChartSurface = forwardRef<unknown, ChartSurfaceProps>(functi
|
|
|
133
133
|
bitmap: strip.bitmap,
|
|
134
134
|
bitmapKey: `${strip.key}@${stripRect.x}:${stripRect.y}:${stripRect.width}x${stripRect.height}`,
|
|
135
135
|
imageZIndex: CROSSHAIR_Z_INDEX,
|
|
136
|
+
anchor: { ...target.anchor, region: strip.rect },
|
|
136
137
|
});
|
|
137
138
|
});
|
|
138
139
|
renderer.requestRender();
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Renderable, RGBA, type CliRenderer } from "@opentui/core";
|
|
2
|
+
import type { NativeFrameHits } from "../../ui/host";
|
|
3
|
+
|
|
4
|
+
function filled(color: unknown): boolean {
|
|
5
|
+
return color instanceof RGBA && color.a > 0;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The terminal's hit grid as the image layer reads it: every renderable the
|
|
10
|
+
* frame drew claims its cells, the one drawn last on top, so it says what
|
|
11
|
+
* covers a kitty image whichever pane, menu, toast or bar drew it.
|
|
12
|
+
*/
|
|
13
|
+
export function createFrameHits(renderer: CliRenderer): NativeFrameHits {
|
|
14
|
+
return {
|
|
15
|
+
at(x, y) {
|
|
16
|
+
if (renderer.isDestroyed) return null;
|
|
17
|
+
return Renderable.renderablesByNumber.get(renderer.hitTest(x, y)) ?? null;
|
|
18
|
+
},
|
|
19
|
+
paints(renderable) {
|
|
20
|
+
const node = renderable as { backgroundColor?: unknown; bg?: unknown };
|
|
21
|
+
return filled(node.backgroundColor) || filled(node.bg);
|
|
22
|
+
},
|
|
23
|
+
attached(renderable) {
|
|
24
|
+
let node = renderable as { parent?: unknown; isDestroyed?: boolean } | null;
|
|
25
|
+
if (!node || node.isDestroyed) return false;
|
|
26
|
+
for (let depth = 0; node && depth < 512; depth += 1) {
|
|
27
|
+
if (node === renderer.root) return true;
|
|
28
|
+
node = (node.parent ?? null) as typeof node;
|
|
29
|
+
}
|
|
30
|
+
return false;
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -13,6 +13,7 @@ import { installInteractionPerformanceRecorder } from "./interaction-performance
|
|
|
13
13
|
import { provideKittyServices } from "./kitty-services";
|
|
14
14
|
import { setTerminalReportsControlKeys } from "../../app/keybindings/terminal-keys";
|
|
15
15
|
import { captureRendererFrame } from "./frame-capture";
|
|
16
|
+
import { createFrameHits } from "./frame-hits";
|
|
16
17
|
import {
|
|
17
18
|
createTimerFrameDriver,
|
|
18
19
|
installMarketDataFrameDriver,
|
|
@@ -245,6 +246,7 @@ export async function createOpenTuiHost(): Promise<OpenTuiHost> {
|
|
|
245
246
|
removePostProcessFn: (processFn) => renderer.removePostProcessFn(processFn as any),
|
|
246
247
|
copyToClipboardOSC52: (text) => renderer.copyToClipboardOSC52(text),
|
|
247
248
|
captureFrame: () => captureRendererFrame(renderer),
|
|
249
|
+
frameHits: createFrameHits(renderer),
|
|
248
250
|
async capturePaneImage(rect) {
|
|
249
251
|
if (renderer.isDestroyed) throw new Error("The terminal has closed.");
|
|
250
252
|
// Loaded on first use: the glyph atlas is only needed for a picture.
|
|
@@ -6,7 +6,12 @@ import {
|
|
|
6
6
|
type CellRect,
|
|
7
7
|
type NativeChartBitmap,
|
|
8
8
|
} from "../../components/chart/native/chart-rasterizer";
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
getNativeSurfaceManager,
|
|
11
|
+
insetCellRect,
|
|
12
|
+
type CellInsets,
|
|
13
|
+
type NativeSurfaceAnchor,
|
|
14
|
+
} from "../../components/chart/native/surface/manager";
|
|
10
15
|
import {
|
|
11
16
|
getRenderableCellRect,
|
|
12
17
|
resolveNativeSurfaceVisibleRect,
|
|
@@ -32,38 +37,24 @@ export interface NativeSurfaceTarget {
|
|
|
32
37
|
pixelHeight: number;
|
|
33
38
|
/** The source key plus the pixel size, so a resize uploads a fresh bitmap. */
|
|
34
39
|
bitmapKey: string;
|
|
40
|
+
/** The box drawn over, which the image layer measures again after every frame. */
|
|
41
|
+
anchor: NativeSurfaceAnchor;
|
|
35
42
|
}
|
|
36
43
|
|
|
37
|
-
export
|
|
38
|
-
top: number;
|
|
39
|
-
right: number;
|
|
40
|
-
bottom: number;
|
|
41
|
-
left: number;
|
|
42
|
-
}
|
|
44
|
+
export type { CellInsets };
|
|
43
45
|
|
|
44
46
|
function sameTarget(left: NativeSurfaceTarget | null, right: NativeSurfaceTarget | null): boolean {
|
|
45
47
|
if (left === right) return true;
|
|
46
48
|
if (!left || !right) return false;
|
|
47
49
|
return left.bitmapKey === right.bitmapKey
|
|
50
|
+
&& left.anchor.renderable === right.anchor.renderable
|
|
51
|
+
&& left.anchor.insets === right.anchor.insets
|
|
48
52
|
&& left.pixelWidth === right.pixelWidth
|
|
49
53
|
&& left.pixelHeight === right.pixelHeight
|
|
50
54
|
&& sameCellRect(left.rect, right.rect)
|
|
51
55
|
&& sameCellRect(left.visibleRect, right.visibleRect);
|
|
52
56
|
}
|
|
53
57
|
|
|
54
|
-
function insetRect(rect: CellRect, insets: CellInsets | undefined): CellRect | null {
|
|
55
|
-
if (!insets) return rect;
|
|
56
|
-
const width = rect.width - insets.left - insets.right;
|
|
57
|
-
const height = rect.height - insets.top - insets.bottom;
|
|
58
|
-
if (width <= 0 || height <= 0) return null;
|
|
59
|
-
return {
|
|
60
|
-
x: rect.x + insets.left,
|
|
61
|
-
y: rect.y + insets.top,
|
|
62
|
-
width,
|
|
63
|
-
height,
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
|
|
67
58
|
/**
|
|
68
59
|
* Where a terminal image surface should draw, re-measured on every lifecycle
|
|
69
60
|
* pass so it follows layout, scrolling and clipping.
|
|
@@ -96,7 +87,7 @@ export function useNativeSurfaceTarget(
|
|
|
96
87
|
let mountTimer: Timer | null = null;
|
|
97
88
|
const previousLifecyclePass = renderable.onLifecyclePass;
|
|
98
89
|
const syncTarget = () => {
|
|
99
|
-
const rect =
|
|
90
|
+
const rect = insetCellRect(getRenderableCellRect(renderable), insets);
|
|
100
91
|
if (!rect || !renderer.resolution || renderer.terminalWidth <= 0 || renderer.terminalHeight <= 0) {
|
|
101
92
|
setTarget((current) => (current === null ? current : null));
|
|
102
93
|
return;
|
|
@@ -110,6 +101,7 @@ export function useNativeSurfaceTarget(
|
|
|
110
101
|
pixelWidth: size.pixelWidth,
|
|
111
102
|
pixelHeight: size.pixelHeight,
|
|
112
103
|
bitmapKey: `${sourceKey}:${size.pixelWidth}x${size.pixelHeight}`,
|
|
104
|
+
anchor: { renderable, insets },
|
|
113
105
|
};
|
|
114
106
|
setTarget((current) => (sameTarget(current, nextTarget) ? current : nextTarget));
|
|
115
107
|
};
|
|
@@ -170,6 +162,7 @@ export function useNativeSurface(
|
|
|
170
162
|
visibleRect: target.visibleRect,
|
|
171
163
|
bitmap,
|
|
172
164
|
bitmapKey: target.bitmapKey,
|
|
165
|
+
anchor: target.anchor,
|
|
173
166
|
});
|
|
174
167
|
renderer.requestRender();
|
|
175
168
|
}, [bitmap, nativeSurfaceManager, paneId, renderer, surfaceId, target]);
|
|
@@ -9,6 +9,7 @@ import { AppDialogBridge } from "../../app/dialog-bridge";
|
|
|
9
9
|
import { OpenTuiDialogHostProvider } from "./dialog-host";
|
|
10
10
|
import { OpenTuiInputHostProvider } from "./input-host";
|
|
11
11
|
import { provideKittyServices } from "./kitty-services";
|
|
12
|
+
import { createFrameHits } from "./frame-hits";
|
|
12
13
|
import { captureRendererFrame } from "./frame-capture";
|
|
13
14
|
import { openTuiToastHost } from "./toast-host";
|
|
14
15
|
import { openTuiUiHost } from "./ui-host";
|
|
@@ -90,6 +91,8 @@ function createTestNativeRendererHost(renderer: any): NativeRendererHost {
|
|
|
90
91
|
}
|
|
91
92
|
// What a feedback report and Ask Gloom read from the screen, as the app's host gives it.
|
|
92
93
|
if (typeof renderer.captureFrame !== "function") renderer.captureFrame = () => captureRendererFrame(renderer);
|
|
94
|
+
// What covers a kitty image, as the app's host reads it.
|
|
95
|
+
if (!renderer.frameHits) renderer.frameHits = createFrameHits(renderer);
|
|
93
96
|
return provideKittyServices(renderer as NativeRendererHost);
|
|
94
97
|
}
|
|
95
98
|
|
|
@@ -284,6 +284,8 @@ export function mapPricePoint(
|
|
|
284
284
|
...(typeof point.rescaled === "number" && Number.isFinite(point.rescaled) && point.rescaled > 0 && point.rescaled !== 1
|
|
285
285
|
? { rescaled: point.rescaled } : {}),
|
|
286
286
|
...(typeof point.contract === "string" && FUTURES_CONTRACT_CODE.test(point.contract) ? { contract: point.contract } : {}),
|
|
287
|
+
...(point.closeRebuilt === true ? { closeRebuilt: true } : {}),
|
|
288
|
+
...(point.closeCopied === true ? { closeCopied: true } : {}),
|
|
287
289
|
};
|
|
288
290
|
}
|
|
289
291
|
|
|
@@ -195,6 +195,18 @@ export function isNoSourceAnswer(error: unknown): boolean {
|
|
|
195
195
|
return error instanceof Error && !(error instanceof ProviderBusyError) && isNoProviderMessage(error.message);
|
|
196
196
|
}
|
|
197
197
|
|
|
198
|
+
/**
|
|
199
|
+
* A source that answered it has nothing for a listing it knows: a miss that
|
|
200
|
+
* does not say the symbol is unknown, or one that crossed the desktop or
|
|
201
|
+
* screenshot bridge, which carries only its message, the service's bare
|
|
202
|
+
* NO_DATA. A source that failed, and a symbol no source knows, are not.
|
|
203
|
+
*/
|
|
204
|
+
export function isNoDataAnswer(error: unknown): boolean {
|
|
205
|
+
if (error instanceof Error && error.message.trim() === "NO_DATA") return true;
|
|
206
|
+
return isProviderMiss(error) && !error.notFound && !/^(?:NOT_FOUND|BAD_MAPPING)$/.test(error.message.trim())
|
|
207
|
+
&& notATickerSymbol(error.message) === null;
|
|
208
|
+
}
|
|
209
|
+
|
|
198
210
|
export function shouldLogProviderError(error: unknown): boolean {
|
|
199
211
|
if (isProviderMiss(error)) return false;
|
|
200
212
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -56,6 +56,7 @@ import { collectCapabilityRouteSources, mergeRouteSourcesById, normalizeRouteSou
|
|
|
56
56
|
import type { ProviderRouterCoreDeps } from "./route-types";
|
|
57
57
|
import { withProviderConnectionHealth } from "./connection-health";
|
|
58
58
|
import { withFiledTrailingEps } from "../../time-series/filed-trailing-eps";
|
|
59
|
+
import { withShareMultiples } from "../../utils/share-multiples";
|
|
59
60
|
import {
|
|
60
61
|
contextFromCachedTarget,
|
|
61
62
|
getBrokerCandidates,
|
|
@@ -66,6 +67,13 @@ import {
|
|
|
66
67
|
type BrokerCandidate,
|
|
67
68
|
} from "./brokers";
|
|
68
69
|
|
|
70
|
+
/**
|
|
71
|
+
* One trailing EPS and P/E for every view of a listing: the filed quarters', as PEB and GE read them
|
|
72
|
+
* (withFiledTrailingEps), and none where the price over it is no multiple of the share (withShareMultiples).
|
|
73
|
+
*/
|
|
74
|
+
const withTrailingMultiples = <T extends Parameters<typeof withFiledTrailingEps>[0] & Parameters<typeof withShareMultiples>[0]>(financials: T): T =>
|
|
75
|
+
withShareMultiples(withFiledTrailingEps(financials));
|
|
76
|
+
|
|
69
77
|
const providerLog = debugLog.createLogger("asset-data-router");
|
|
70
78
|
|
|
71
79
|
/**
|
|
@@ -216,7 +224,7 @@ export class AssetDataRouter implements DataProvider {
|
|
|
216
224
|
for (const target of valid) {
|
|
217
225
|
const key = target.symbol.toUpperCase();
|
|
218
226
|
const financials = cached.get(key);
|
|
219
|
-
if (financials) cached.set(key,
|
|
227
|
+
if (financials) cached.set(key, withTrailingMultiples(this.knownFinancials(financials, listingOf(target, contextFromCachedTarget(target)))));
|
|
220
228
|
}
|
|
221
229
|
return cached;
|
|
222
230
|
}
|
|
@@ -268,7 +276,7 @@ export class AssetDataRouter implements DataProvider {
|
|
|
268
276
|
const results = answered.map((result) => {
|
|
269
277
|
if (!result.financials) return result;
|
|
270
278
|
const quoted = result.financials.quote ? this.withDatedQuote(result.financials, dated[next++]!, listingOfResult(result)) : result.financials;
|
|
271
|
-
const financials =
|
|
279
|
+
const financials = withTrailingMultiples(quoted);
|
|
272
280
|
return financials === result.financials ? result : { ...result, financials };
|
|
273
281
|
});
|
|
274
282
|
const restored = new Map(results.map((result) => {
|
|
@@ -283,11 +291,11 @@ export class AssetDataRouter implements DataProvider {
|
|
|
283
291
|
const { context, datesChangeBasis } = splitDating(requestContext);
|
|
284
292
|
exchange = this.resolvePublicExchange(ticker, exchange, context);
|
|
285
293
|
const financials = await this.financialRoutes.getTickerFinancials(ticker, exchange, context);
|
|
286
|
-
if (!financials.quote) return
|
|
294
|
+
if (!financials.quote) return withTrailingMultiples(financials);
|
|
287
295
|
const listing = listingOf({ symbol: ticker, exchange }, context);
|
|
288
296
|
const [quote] = await this.datedAnswers([{ quote: financials.quote, listing }], datesChangeBasis);
|
|
289
297
|
// One trailing EPS and P/E for every view of the listing: the filed quarters', as PEB and GE read them.
|
|
290
|
-
return
|
|
298
|
+
return withTrailingMultiples(this.withDatedQuote(financials, quote!, listing));
|
|
291
299
|
}
|
|
292
300
|
|
|
293
301
|
async getQuote(ticker: string, exchange?: string, requestContext?: MarketDataRequestContext): Promise<Quote> {
|
|
@@ -376,6 +376,28 @@ export function useUpdatePaneSettings(paneId?: string) {
|
|
|
376
376
|
}, [scopedPaneId, updateLayout]);
|
|
377
377
|
}
|
|
378
378
|
|
|
379
|
+
/**
|
|
380
|
+
* Rewrites one setting of a pane that may be absent (a table drawn outside a
|
|
381
|
+
* pane): `update` gets its value and returns the next one, `undefined` to
|
|
382
|
+
* remove it, or the same value to leave the layout alone.
|
|
383
|
+
*/
|
|
384
|
+
export function useOptionalPaneSettingUpdater(paneId: string | null, key: string) {
|
|
385
|
+
const updateLayout = useUpdatePaneLayout();
|
|
386
|
+
return useCallback((update: (value: unknown) => unknown) => {
|
|
387
|
+
if (!paneId) return;
|
|
388
|
+
updateLayout((layout) => {
|
|
389
|
+
const pane = findPaneInstance(layout, paneId);
|
|
390
|
+
if (!pane) return layout;
|
|
391
|
+
const current = pane.settings?.[key];
|
|
392
|
+
const next = update(current);
|
|
393
|
+
if (Object.is(next, current)) return layout;
|
|
394
|
+
if (next !== undefined) return setPaneSetting(layout, paneId, key, next);
|
|
395
|
+
const { [key]: _removed, ...rest } = pane.settings ?? {};
|
|
396
|
+
return setPaneSettings(layout, paneId, Object.keys(rest).length > 0 ? rest : undefined);
|
|
397
|
+
});
|
|
398
|
+
}, [key, paneId, updateLayout]);
|
|
399
|
+
}
|
|
400
|
+
|
|
379
401
|
function useScopedPaneId(paneId?: string): string {
|
|
380
402
|
const contextId = useOptionalPaneInstanceId();
|
|
381
403
|
const id = paneId ?? contextId;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useCallback,
|
|
3
|
+
useEffect,
|
|
4
|
+
useMemo,
|
|
5
|
+
useSyncExternalStore,
|
|
6
|
+
type SetStateAction,
|
|
7
|
+
} from "react";
|
|
8
|
+
import { useOptionalPaneInstanceId } from "./app/context";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Memory a pane keeps for as long as the pane exists, rather than for as long
|
|
12
|
+
* as it is mounted.
|
|
13
|
+
*
|
|
14
|
+
* Docking, floating, stacking or fullscreening a pane draws it in another
|
|
15
|
+
* place in the tree, so its component mounts again. What it shows has to come
|
|
16
|
+
* back on the first frame: a pane that reads it from component state, or has to
|
|
17
|
+
* fetch it again, draws its empty state in between and loses the selection.
|
|
18
|
+
* What the user chose and can save belongs in pane state (`usePluginPaneState`,
|
|
19
|
+
* `usePaneSettingValue`); this holds what cannot be saved or must not be: a
|
|
20
|
+
* live conversation with its answer still coming in, a transcript, a draft.
|
|
21
|
+
* It is in memory only, so a relaunch starts without it, and a shared layout
|
|
22
|
+
* never carries it.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* How long a pane's memory outlives its last mounted view. A move between the
|
|
27
|
+
* dock and a floating window mounts the new view in the commit that unmounts
|
|
28
|
+
* the old one; a closed pane never mounts again, and its memory is released
|
|
29
|
+
* after this.
|
|
30
|
+
*/
|
|
31
|
+
export const PANE_SESSION_GRACE_MS = 2_000;
|
|
32
|
+
|
|
33
|
+
interface SessionEntry {
|
|
34
|
+
id: string;
|
|
35
|
+
value: unknown;
|
|
36
|
+
dispose: ((value: never) => void) | undefined;
|
|
37
|
+
holders: number;
|
|
38
|
+
timer: ReturnType<typeof setTimeout> | null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const sessions = new Map<string, SessionEntry>();
|
|
42
|
+
|
|
43
|
+
function scheduleRelease(entry: SessionEntry): void {
|
|
44
|
+
if (entry.timer) clearTimeout(entry.timer);
|
|
45
|
+
entry.timer = setTimeout(() => {
|
|
46
|
+
entry.timer = null;
|
|
47
|
+
if (entry.holders > 0 || sessions.get(entry.id) !== entry) return;
|
|
48
|
+
sessions.delete(entry.id);
|
|
49
|
+
entry.dispose?.(entry.value as never);
|
|
50
|
+
}, PANE_SESSION_GRACE_MS);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Finds a pane's session or makes it. One a render makes and nothing mounts is released like any other. */
|
|
54
|
+
function acquire<T>(paneId: string, key: string, create: () => T, dispose: ((value: T) => void) | undefined): SessionEntry {
|
|
55
|
+
const id = `${paneId}\u0000${key}`;
|
|
56
|
+
const existing = sessions.get(id);
|
|
57
|
+
if (existing) return existing;
|
|
58
|
+
const entry: SessionEntry = { id, value: create(), dispose: dispose as SessionEntry["dispose"], holders: 0, timer: null };
|
|
59
|
+
sessions.set(id, entry);
|
|
60
|
+
scheduleRelease(entry);
|
|
61
|
+
return entry;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Test hook: releases every pane's memory now, so one test's panes never start on another's. */
|
|
65
|
+
export function resetPaneSessionsForTests(): void {
|
|
66
|
+
for (const entry of [...sessions.values()]) {
|
|
67
|
+
if (entry.timer) clearTimeout(entry.timer);
|
|
68
|
+
entry.timer = null;
|
|
69
|
+
sessions.delete(entry.id);
|
|
70
|
+
entry.dispose?.(entry.value as never);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function useScopedPaneId(paneId?: string): string {
|
|
75
|
+
const contextId = useOptionalPaneInstanceId();
|
|
76
|
+
const scoped = paneId ?? contextId;
|
|
77
|
+
if (!scoped) throw new Error("A pane session requires a pane id or PaneInstanceProvider");
|
|
78
|
+
return scoped;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* An object that lives as long as the pane does: the same one in every view
|
|
83
|
+
* the pane is drawn in, made by `create` the first time. `dispose` runs once
|
|
84
|
+
* the pane has had no mounted view for the grace period (the pane was closed).
|
|
85
|
+
* Read it during render; it never changes identity while the pane exists.
|
|
86
|
+
*/
|
|
87
|
+
export function usePaneSession<T>(
|
|
88
|
+
key: string,
|
|
89
|
+
create: () => T,
|
|
90
|
+
dispose?: (value: T) => void,
|
|
91
|
+
paneId?: string,
|
|
92
|
+
): T {
|
|
93
|
+
const scopedPaneId = useScopedPaneId(paneId);
|
|
94
|
+
const entry = useMemo(() => acquire(scopedPaneId, key, create, dispose), [scopedPaneId, key]);
|
|
95
|
+
useEffect(() => {
|
|
96
|
+
entry.holders += 1;
|
|
97
|
+
if (entry.timer) {
|
|
98
|
+
clearTimeout(entry.timer);
|
|
99
|
+
entry.timer = null;
|
|
100
|
+
}
|
|
101
|
+
return () => {
|
|
102
|
+
entry.holders -= 1;
|
|
103
|
+
if (entry.holders <= 0) scheduleRelease(entry);
|
|
104
|
+
};
|
|
105
|
+
}, [entry]);
|
|
106
|
+
return entry.value as T;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
interface StateBox<T> {
|
|
110
|
+
value: T;
|
|
111
|
+
listeners: Set<() => void>;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* `useState` for a selection or draft that cannot be saved with the pane: the
|
|
116
|
+
* value is kept for the pane, so the view mounted after a dock change starts on
|
|
117
|
+
* it. A setter held by the view it unmounted still lands, on the value the new
|
|
118
|
+
* view reads. See `usePaneSession` for what belongs here and what belongs in
|
|
119
|
+
* pane state.
|
|
120
|
+
*/
|
|
121
|
+
export function usePaneSessionState<T>(
|
|
122
|
+
key: string,
|
|
123
|
+
initial: T | (() => T),
|
|
124
|
+
paneId?: string,
|
|
125
|
+
): [T, (value: SetStateAction<T>) => void] {
|
|
126
|
+
const box = usePaneSession<StateBox<T>>(key, () => ({
|
|
127
|
+
value: typeof initial === "function" ? (initial as () => T)() : initial,
|
|
128
|
+
listeners: new Set(),
|
|
129
|
+
}), undefined, paneId);
|
|
130
|
+
const subscribe = useCallback((listener: () => void) => {
|
|
131
|
+
box.listeners.add(listener);
|
|
132
|
+
return () => {
|
|
133
|
+
box.listeners.delete(listener);
|
|
134
|
+
};
|
|
135
|
+
}, [box]);
|
|
136
|
+
const getSnapshot = useCallback(() => box.value, [box]);
|
|
137
|
+
const value = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
138
|
+
const setValue = useCallback((next: SetStateAction<T>) => {
|
|
139
|
+
const resolved = typeof next === "function" ? (next as (previous: T) => T)(box.value) : next;
|
|
140
|
+
if (Object.is(resolved, box.value)) return;
|
|
141
|
+
box.value = resolved;
|
|
142
|
+
for (const listener of [...box.listeners]) listener();
|
|
143
|
+
}, [box]);
|
|
144
|
+
return [value, setValue];
|
|
145
|
+
}
|