@gloom-sh/terminal 0.20.22 → 0.20.23
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/src/account/heard-from-question.tsx +6 -4
- package/src/account/heard-from.ts +3 -4
- package/src/api-client/exchange-announcements.ts +2 -2
- package/src/api-client/heard-from.ts +5 -7
- package/src/api-client/ownership-disclosures.ts +38 -5
- package/src/api-client/types/ticker-data.ts +3 -1
- package/src/architecture/dom-cell-metrics-allowlist.json +2 -2
- package/src/cli/commands/market.ts +5 -3
- package/src/cli/commands/overview.ts +7 -9
- package/src/cli/listing-arg.ts +45 -18
- package/src/cli/pane-functions/catalog-snapshot.json +2 -2
- package/src/cli/pane-functions/data.ts +3 -1
- package/src/cli/pane-functions/freshness.ts +6 -1
- package/src/cli/pane-functions/function-help.ts +0 -2
- package/src/cli/pane-functions/market-session.ts +12 -2
- package/src/cli/pane-functions/screenshot-payload.ts +3 -1
- package/src/cli/symbol-list.ts +52 -14
- package/src/cli/ticker-resolution.ts +133 -38
- package/src/components/chart/composite/composite-chart.tsx +12 -0
- package/src/components/chart/composite/types.ts +18 -0
- package/src/components/chart/composite/use-composite-chart-keyboard.ts +38 -15
- package/src/components/chart-table/header.tsx +11 -5
- package/src/components/chart-table/selection.ts +20 -1
- package/src/components/data-table/view.tsx +2 -0
- package/src/components/feed-data-table/stack-view.tsx +85 -5
- package/src/components/layout/pane/header.tsx +12 -30
- package/src/components/ticker/badge/index.tsx +9 -4
- package/src/components/ticker/badge/list.tsx +3 -1
- package/src/components/ui/data-table/index.tsx +7 -1
- package/src/components/ui/data-table/muted-row.tsx +47 -0
- package/src/components/ui/data-table/opentui/index.tsx +42 -11
- package/src/components/ui/data-table/spill.ts +36 -0
- package/src/components/ui/data-table/types.ts +17 -1
- package/src/components/ui/data-table/use-column-order.ts +11 -0
- package/src/components/ui/icon.tsx +50 -3
- package/src/components/ui/list-view.tsx +2 -2
- package/src/components/ui/table-layout.ts +32 -0
- package/src/components/ui/terminal-hover-label.tsx +49 -0
- package/src/components/use-pinned-moment.ts +222 -13
- package/src/core/state/app/state.ts +11 -2
- package/src/core/state/app/types.ts +2 -1
- package/src/data/sqlite/access.ts +14 -1
- package/src/data/sqlite/checkpointer.ts +2 -2
- package/src/data/sqlite/database.ts +4 -0
- package/src/docs/snapshot.json +180 -26
- package/src/i18n/es.ts +1 -0
- package/src/i18n/ja.ts +1 -0
- package/src/i18n/ko.ts +1 -0
- package/src/i18n/zh-cn.ts +1 -0
- package/src/i18n/zh-tw.ts +1 -0
- package/src/market-data/market/freshness.ts +2 -2
- package/src/market-data/market/globex-day.ts +14 -0
- package/src/market-data/published-us-sessions.ts +3 -2
- package/src/market-data/quotes/live-valuation.ts +4 -2
- package/src/market-data/quotes/metadata.ts +48 -5
- package/src/market-data/quotes/regular-session-valuation.ts +12 -1
- package/src/plugins/builtin/alerts/history-pane.tsx +19 -3
- package/src/plugins/builtin/broker-trading/orders.tsx +4 -2
- package/src/plugins/builtin/chat/attachments/desktop.tsx +46 -12
- package/src/plugins/builtin/chat/channels.ts +5 -2
- package/src/plugins/builtin/chat/content/composer-runtime.ts +64 -65
- package/src/plugins/builtin/chat/content/footer.tsx +17 -7
- package/src/plugins/builtin/chat/content/index.tsx +108 -36
- package/src/plugins/builtin/chat/content/new-dm-dialog.tsx +21 -8
- package/src/plugins/builtin/chat/content/selection-runtime.ts +16 -0
- package/src/plugins/builtin/chat/content/shortcuts.ts +3 -0
- package/src/plugins/builtin/chat/content/snapshot.ts +37 -13
- package/src/plugins/builtin/chat/content/transcript.tsx +12 -0
- package/src/plugins/builtin/chat/content/types.ts +2 -0
- package/src/plugins/builtin/chat/controller/channels.ts +15 -15
- package/src/plugins/builtin/chat/controller/index.ts +140 -34
- package/src/plugins/builtin/chat/controller/lifecycle.ts +8 -12
- package/src/plugins/builtin/chat/controller/persistence.ts +32 -4
- package/src/plugins/builtin/chat/controller/send.ts +41 -17
- package/src/plugins/builtin/chat/controller/session-runtime.ts +28 -27
- package/src/plugins/builtin/chat/controller/state.ts +17 -8
- package/src/plugins/builtin/chat/controller/storage.ts +41 -4
- package/src/plugins/builtin/chat/controller/view.ts +6 -3
- package/src/plugins/builtin/chat/index.tsx +1 -1
- package/src/plugins/builtin/chat/layout.ts +8 -1
- package/src/plugins/builtin/chat/message/desktop.tsx +15 -11
- package/src/plugins/builtin/chat/message/header.tsx +112 -30
- package/src/plugins/builtin/chat/message/reactions.tsx +10 -11
- package/src/plugins/builtin/chat/message/render-state.ts +4 -2
- package/src/plugins/builtin/chat/message/terminal.tsx +13 -15
- package/src/plugins/builtin/chat/message/types.ts +5 -0
- package/src/plugins/builtin/cloud-tweets/table.tsx +25 -2
- package/src/plugins/builtin/company-kpis/model.ts +11 -3
- package/src/plugins/builtin/correlation/compute.ts +6 -1
- package/src/plugins/builtin/custom-view/loader.ts +95 -34
- package/src/plugins/builtin/custom-view/pane.tsx +31 -41
- package/src/plugins/builtin/custom-view/table.ts +201 -0
- package/src/plugins/builtin/dividend-yield/client.ts +14 -17
- package/src/plugins/builtin/dividend-yield/headless.ts +0 -1
- package/src/plugins/builtin/dividend-yield/model.ts +45 -6
- package/src/plugins/builtin/dividend-yield/pane.tsx +70 -7
- package/src/plugins/builtin/dividend-yield/types.ts +2 -3
- package/src/plugins/builtin/dividend-yield/view.ts +22 -2
- package/src/plugins/builtin/econ/calendar-model.ts +135 -0
- package/src/plugins/builtin/econ/columns.ts +132 -0
- package/src/plugins/builtin/econ/index.tsx +25 -65
- package/src/plugins/builtin/holders/disclosures-view.tsx +9 -6
- package/src/plugins/builtin/holders/disclosures.ts +20 -6
- package/src/plugins/builtin/holders/headless.ts +2 -2
- package/src/plugins/builtin/ipo-calendar/model.ts +30 -1
- package/src/plugins/builtin/ipo-calendar/pane.tsx +7 -3
- package/src/plugins/builtin/kelly-sizer/headless.ts +9 -4
- package/src/plugins/builtin/kelly-sizer/pane.tsx +19 -9
- package/src/plugins/builtin/kelly-sizer/units.ts +26 -0
- package/src/plugins/builtin/market-halts/pane.tsx +14 -2
- package/src/plugins/builtin/news/wire/news/row.ts +5 -12
- package/src/plugins/builtin/news/wire/news/table.tsx +32 -41
- package/src/plugins/builtin/pe-band/headless.ts +1 -1
- package/src/plugins/builtin/pe-band/model.ts +41 -18
- package/src/plugins/builtin/pe-band/pane.tsx +6 -5
- package/src/plugins/builtin/perps/equity-row.tsx +4 -6
- package/src/plugins/builtin/perps/markets-section.tsx +19 -15
- package/src/plugins/builtin/perps/model.ts +10 -2
- package/src/plugins/builtin/portfolio-list/cli/import-positions.ts +6 -18
- package/src/plugins/builtin/portfolio-list/cli/portfolio-command.ts +1 -1
- package/src/plugins/builtin/portfolio-list/pane/purchase-date-fx.ts +1 -1
- package/src/plugins/builtin/portfolio-list/positions-import/index.tsx +1 -1
- package/src/plugins/builtin/portfolio-list/positions-import/lookup.ts +28 -57
- package/src/plugins/builtin/research/event-data.ts +3 -1
- package/src/plugins/builtin/research/event-model.ts +17 -15
- package/src/plugins/builtin/research/relative-valuation-columns.ts +19 -6
- package/src/plugins/builtin/research/relative-valuation-headless.ts +1 -1
- package/src/plugins/builtin/scanner/flow-pane.tsx +10 -0
- package/src/plugins/builtin/sec/exchange-filings.ts +32 -7
- package/src/plugins/builtin/sec/headless.ts +8 -8
- package/src/plugins/builtin/sec/index.tsx +69 -29
- package/src/plugins/builtin/shared/report-freshness.ts +4 -1
- package/src/plugins/builtin/ticker-detail/financials/aggregation.ts +1 -2
- package/src/plugins/builtin/ticker-detail/financials/exchange-table.tsx +61 -0
- package/src/plugins/builtin/ticker-detail/financials/model.ts +38 -4
- package/src/plugins/builtin/ticker-detail/financials/ratio-table.tsx +9 -2
- package/src/plugins/builtin/ticker-detail/financials/tab.tsx +68 -39
- package/src/plugins/builtin/ticker-detail/headless.ts +4 -1
- package/src/plugins/builtin/ticker-detail/overview/model.ts +61 -15
- package/src/plugins/builtin/ticker-detail/overview-tab.tsx +5 -0
- package/src/plugins/builtin/time-sales/model.ts +16 -9
- package/src/plugins/builtin/time-sales/pane.tsx +27 -24
- package/src/plugins/builtin/treasury-daily/client.ts +43 -9
- package/src/plugins/builtin/treasury-daily/pane.tsx +48 -27
- package/src/plugins/builtin/treasury-daily/resource.ts +33 -0
- package/src/portfolio/positions-import/parse.ts +14 -6
- package/src/portfolio/positions-import/plan.ts +3 -2
- package/src/react/async-resource.ts +3 -1
- package/src/renderers/dom/data-table/index.tsx +40 -0
- package/src/renderers/dom/data-table/row.tsx +39 -3
- package/src/renderers/dom/desktop/icons.tsx +147 -3
- package/src/renderers/dom/desktop/popover.tsx +2 -2
- package/src/renderers/dom/host/media-surface.tsx +204 -45
- package/src/renderers/dom/host/tabs.tsx +1 -0
- package/src/renderers/dom/styles.css +14 -2
- package/src/renderers/electrobun/bun/desktop/backend.ts +2 -0
- package/src/renderers/electrobun/bun/desktop/rpc-timing.ts +9 -3
- package/src/renderers/electrobun/shared/protocol.ts +2 -0
- package/src/renderers/electrobun/view/backend-rpc.ts +5 -2
- package/src/renderers/electrobun/view/rpc-timeout.ts +44 -3
- package/src/sources/gloomberb-cloud/index.ts +8 -7
- package/src/sources/gloomberb-cloud/normalizers.ts +7 -2
- package/src/sources/listing-symbols.ts +7 -1
- package/src/sources/provider-router/cache.ts +5 -4
- package/src/sources/provider-router/financials.ts +40 -18
- package/src/state/app/tab-cursor.ts +47 -6
- package/src/telemetry/stall-clocks.ts +3 -0
- package/src/telemetry/stall-reports.ts +12 -3
- package/src/telemetry/windows-process-activity.ts +41 -0
- package/src/telemetry/windows-time.ts +32 -0
- package/src/test-support/scoped-earnings.ts +24 -0
- package/src/tickers/terminal-codes.ts +1 -6
- package/src/time-series/daily-valuation.ts +13 -6
- package/src/time-series/filed-trailing-eps.ts +16 -3
- package/src/time-series/fundamentals/current-valuation.ts +8 -0
- package/src/time-series/fundamentals/historical-valuation.ts +20 -0
- package/src/time-series/fundamentals/series.ts +13 -1
- package/src/time-series/valuation-currency.ts +2 -0
- package/src/types/financials.ts +46 -10
- package/src/ui/dialog-context.ts +8 -0
- package/src/utils/datetime-format.ts +23 -1
- package/src/utils/declared-dividends.ts +12 -2
- package/src/utils/exchange-announcements.ts +4 -1
- package/src/utils/exchange-notation.generated.ts +3 -1
- package/src/utils/exchanges.ts +2 -1
- package/src/utils/fundamentals.ts +1 -0
- package/src/utils/main-thread-stall.ts +9 -1
- package/src/utils/rpc-timeout-error.ts +36 -11
- package/src/utils/sec.ts +3 -1
- package/src/utils/share-multiples.ts +1 -1
- package/src/utils/stall-process-activity.ts +70 -0
- package/src/utils/statement-scope.ts +103 -0
- package/src/utils/trailing-eps.ts +1 -1
- package/src/utils/zoned-date-time.ts +1 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MISSING_VALUE } from "../../../utils/format";
|
|
2
|
-
import { useCallback,
|
|
2
|
+
import { useCallback, useMemo, useRef, useState } from "react";
|
|
3
3
|
import { Box } from "../../../ui";
|
|
4
4
|
import { usePaneSettingValue, useShortcut } from "../../../public/react";
|
|
5
5
|
import { createDataTableCsv } from "../../../components/data-table/export";
|
|
@@ -12,8 +12,8 @@ import { canonicalExchange } from "../../../utils/exchanges";
|
|
|
12
12
|
import { listingIdentity } from "../shared/ticker-request";
|
|
13
13
|
import { SignInWall } from "../cloud/auth-actions";
|
|
14
14
|
import { isCloudSessionRequired, useResearchCloudSession } from "../shared/research-cloud-session";
|
|
15
|
-
import { newestFirst, quoteKey, quoteSpread, stickyTapePriceDigits, tapeClockNewYork, tapeConditionWords, tapePrice, tapeQuantity, tapeStampNewYork, tapeStatistics, tapeTicks, tapeTime,
|
|
16
|
-
import {
|
|
15
|
+
import { newestFirst, quoteKey, quoteSpread, stickyTapePriceDigits, tapeClockNewYork, tapeConditionWords, tapePrice, tapeQuantity, tapeStampNewYork, tapeStatistics, tapeTicks, tapeTime, tapeAfterMoment, tapeMoment, tapeTimeOrder, tapeVenue, tradeKey, type TapeDigits } from "./model";
|
|
16
|
+
import { usePinnedList } from "../../../components/use-pinned-moment";
|
|
17
17
|
import { useTape } from "./use-tape";
|
|
18
18
|
import { lastSessionNote } from "./window";
|
|
19
19
|
|
|
@@ -44,6 +44,11 @@ const QUOTES: DataTableColumn[] = [
|
|
|
44
44
|
const QUOTE_DROP_ORDER = [["bidExchange", "askExchange"], ["bidSize", "askSize"]];
|
|
45
45
|
const rank = (value: number | null) => value == null ? `pctl ${MISSING_VALUE}` : `${value.toFixed(0)} pctl`;
|
|
46
46
|
type TapeRow = { id: string; trade?: TapeTrade; quote?: TapeQuote };
|
|
47
|
+
const tapeRowId = (row: TapeRow) => row.id;
|
|
48
|
+
const rowTime = (row: TapeRow) => (row.trade ?? row.quote)!.timestamp;
|
|
49
|
+
const tapeRowMoment = (row: TapeRow) => tapeMoment(rowTime(row));
|
|
50
|
+
const tapeRowAfter = (row: TapeRow, at: number) => tapeAfterMoment(rowTime(row), at);
|
|
51
|
+
const tapeRowOrder = (a: TapeRow, b: TapeRow) => tapeTimeOrder(rowTime(a), rowTime(b));
|
|
47
52
|
|
|
48
53
|
export function TimeSalesPane(props: PaneProps) {
|
|
49
54
|
const { symbol, ticker } = usePaneTicker();
|
|
@@ -73,24 +78,22 @@ function TimeSalesView({ width, height, focused, symbol, exchange }: PaneProps &
|
|
|
73
78
|
: newestFirst(data.trades).map((trade) => ({ id: tradeKey(trade), trade })), [data, tab]);
|
|
74
79
|
// A crosshair pinned in the tab picks the print at that moment out of the
|
|
75
80
|
// tape and mutes the later ones, on the same nanosecond comparison; a
|
|
76
|
-
// moment before the tape's window
|
|
77
|
-
//
|
|
78
|
-
//
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
const pinnedBeforeTape = pinKey !== null && rows.length > 0 && pinnedRow === null;
|
|
93
|
-
const laterThanPin = (row: TapeRow) => pinKey !== null && tapeAfter(rowTime(row), pinKey);
|
|
81
|
+
// moment before the tape's window selects its first print, to the
|
|
82
|
+
// nanosecond, and says so. The
|
|
83
|
+
// selection follows the pin when it moves or the tab changes, not on each
|
|
84
|
+
// new print, so a streaming tape never pulls away a row the user picked
|
|
85
|
+
// (another listing remounts).
|
|
86
|
+
const { beforeRows: pinnedBeforeTape, isAfterPin } = usePinnedList<TapeRow>("time-sales:pin", {
|
|
87
|
+
enabled: !detail,
|
|
88
|
+
rows,
|
|
89
|
+
getId: tapeRowId,
|
|
90
|
+
moment: tapeRowMoment,
|
|
91
|
+
isAfter: tapeRowAfter,
|
|
92
|
+
order: tapeRowOrder,
|
|
93
|
+
selectedId: selected,
|
|
94
|
+
select: setSelected,
|
|
95
|
+
followKey: tab,
|
|
96
|
+
});
|
|
94
97
|
const spreads = useMemo(() => {
|
|
95
98
|
const quotes = data?.quotes ?? [];
|
|
96
99
|
const bps = quotes.map((quote) => quoteSpread(quote)).filter((spread) => spread.state === "normal" && spread.bps != null).map((spread) => spread.bps!).sort((a, b) => a - b);
|
|
@@ -141,14 +144,14 @@ function TimeSalesView({ width, height, focused, symbol, exchange }: PaneProps &
|
|
|
141
144
|
: column.id === "size" ? tapeQuantity(trade.size) : column.id === "venue" ? tapeVenue(trade.exchange)
|
|
142
145
|
: column.id === "conditions" ? tapeConditionWords(trade.conditions) : trade.tape,
|
|
143
146
|
// Price by tick, as on a tape; a block print lights the rest of its row.
|
|
144
|
-
color:
|
|
147
|
+
color: column.id === "price" ? tick === "up" ? colors.positive : tick === "down" ? colors.negative : colors.text
|
|
145
148
|
: trade.size >= 10_000 ? colors.warning : colors.textMuted };
|
|
146
149
|
}
|
|
147
150
|
const quote = row.quote!, spread = quoteSpread(quote);
|
|
148
151
|
return { text: column.id === "time" ? tapeClockNewYork(quote.timestamp) : column.id === "bid" ? tapePrice(quote.bid, quoteDigits) : column.id === "ask" ? tapePrice(quote.ask, quoteDigits)
|
|
149
152
|
: column.id === "bidSize" ? tapeQuantity(quote.bidSize) : column.id === "askSize" ? tapeQuantity(quote.askSize)
|
|
150
153
|
: column.id === "bidExchange" ? tapeVenue(quote.bidExchange) : column.id === "askExchange" ? tapeVenue(quote.askExchange)
|
|
151
|
-
: spread.bps == null ? MISSING_VALUE : spread.bps.toFixed(2), color:
|
|
154
|
+
: spread.bps == null ? MISSING_VALUE : spread.bps.toFixed(2), color: spread.state === "normal" ? colors.text : colors.warning };
|
|
152
155
|
};
|
|
153
156
|
if (!data && isCloudSessionRequired(resource.error)) return <SignInWall placement="time-sales-signin" action="view time and sales" needsVerification={session.needsVerification} />;
|
|
154
157
|
return <Box width={width} height={height} flexDirection="column">
|
|
@@ -172,7 +175,7 @@ function TimeSalesView({ width, height, focused, symbol, exchange }: PaneProps &
|
|
|
172
175
|
]),
|
|
173
176
|
...(data.session.high != null && data.session.low != null ? [{ id: "session", label: "Session", value: `${tapePrice(data.session.low, sessionDigits)} to ${tapePrice(data.session.high, sessionDigits)}` }] : []),
|
|
174
177
|
]} />}
|
|
175
|
-
renderCell={renderCell} exportCsv={() => createDataTableCsv({ columns: tab === "quotes" ? QUOTES : TRADES, items: rows, renderCell })}
|
|
178
|
+
renderCell={renderCell} isRowMuted={isAfterPin} exportCsv={() => createDataTableCsv({ columns: tab === "quotes" ? QUOTES : TRADES, items: rows, renderCell })}
|
|
176
179
|
emptyStateTitle="No observations in this window." /> : null}
|
|
177
180
|
</PaneStatusBody>
|
|
178
181
|
</Box>;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ApiRequestError, sourceDidNotAnswer } from "../../../api-client/errors";
|
|
2
|
+
import { OperationTimeoutError, signalWithTimeout } from "../../../utils/async-deadline";
|
|
3
|
+
import { readCalendarDate } from "../../../utils/calendar-date";
|
|
2
4
|
import { httpFetch } from "../../../utils/http-transport";
|
|
3
5
|
import { numericOrNull, scalarTextOrNull } from "../../../utils/guards";
|
|
4
6
|
import { cashLineLabel, type CashAccount, type DebtDay, type OperatingCash, type TgaClose } from "./model";
|
|
@@ -26,7 +28,7 @@ export interface TreasuryDaily {
|
|
|
26
28
|
|
|
27
29
|
function recordDate(value: unknown): string | null {
|
|
28
30
|
const date = scalarTextOrNull(value);
|
|
29
|
-
return date &&
|
|
31
|
+
return date && readCalendarDate(date) === date ? date : null;
|
|
30
32
|
}
|
|
31
33
|
|
|
32
34
|
function isBusinessDay(iso: string): boolean {
|
|
@@ -109,15 +111,42 @@ function parseDebtToPenny(payload: unknown): DebtDay[] {
|
|
|
109
111
|
async function readJson(url: string, label: string, signal: AbortSignal | undefined, timeoutMs: number): Promise<unknown> {
|
|
110
112
|
const deadline = signalWithTimeout(signal, timeoutMs);
|
|
111
113
|
try {
|
|
114
|
+
deadline.throwIfAborted();
|
|
112
115
|
const response = await httpFetch(url, { headers: { Accept: "application/json" }, signal: deadline });
|
|
113
|
-
if (!response.ok) throw new
|
|
114
|
-
|
|
116
|
+
if (!response.ok) throw new ApiRequestError(`${label} request failed (${response.status})`, response.status);
|
|
117
|
+
const payload = await response.json() as unknown;
|
|
118
|
+
deadline.throwIfAborted();
|
|
119
|
+
return payload;
|
|
115
120
|
} catch (error) {
|
|
116
|
-
|
|
121
|
+
signal?.throwIfAborted();
|
|
122
|
+
if (deadline.aborted) throw new OperationTimeoutError(`${label} request timed out after ${Math.round(timeoutMs / 1000)} s`);
|
|
117
123
|
throw error;
|
|
118
124
|
}
|
|
119
125
|
}
|
|
120
126
|
|
|
127
|
+
const readCash = (signal?: AbortSignal, timeoutMs = FETCH_TIMEOUT_MS) => readJson(CASH_URL, "Treasury cash", signal, timeoutMs);
|
|
128
|
+
const readDebt = (signal?: AbortSignal, timeoutMs = FETCH_TIMEOUT_MS) => readJson(DEBT_URL, "Treasury debt", signal, timeoutMs);
|
|
129
|
+
const readTga = (signal?: AbortSignal, timeoutMs = FETCH_TIMEOUT_MS) => readJson(TGA_HISTORY_URL, "Treasury account history", signal, timeoutMs).then(parseTgaHistory);
|
|
130
|
+
|
|
131
|
+
export async function fetchTreasuryCash(signal: AbortSignal, timeoutMs?: number): Promise<OperatingCash> {
|
|
132
|
+
const cash = parseOperatingCash(await readCash(signal, timeoutMs));
|
|
133
|
+
if (!cash.rows.some(({ today, month }) => today !== null || month !== null)) throw sourceDidNotAnswer("No published cash figures received");
|
|
134
|
+
return cash;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export async function fetchTreasuryDebt(signal: AbortSignal, timeoutMs?: number): Promise<DebtDay[]> {
|
|
138
|
+
const debt = parseDebtToPenny(await readDebt(signal, timeoutMs));
|
|
139
|
+
const published = debt.filter(({ heldByPublic, intragovernmental, total }) => heldByPublic !== null || intragovernmental !== null || total !== null);
|
|
140
|
+
if (!published.length) throw sourceDidNotAnswer("No published debt figures received");
|
|
141
|
+
return published;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export async function fetchTreasuryHistory(signal: AbortSignal, timeoutMs?: number): Promise<TgaClose[]> {
|
|
145
|
+
const history = await readTga(signal, timeoutMs);
|
|
146
|
+
if (!history.length) throw sourceDidNotAnswer("No closing balance history received");
|
|
147
|
+
return history;
|
|
148
|
+
}
|
|
149
|
+
|
|
121
150
|
/**
|
|
122
151
|
* The latest day's cash lines and the last 20 days of debt, with the account's
|
|
123
152
|
* closing balance history unless `history` is off (a report that does not draw it).
|
|
@@ -128,13 +157,18 @@ export async function fetchTreasuryDaily(
|
|
|
128
157
|
{ history = true, timeoutMs = FETCH_TIMEOUT_MS }: { history?: boolean; timeoutMs?: number } = {},
|
|
129
158
|
): Promise<TreasuryDaily> {
|
|
130
159
|
const [cash, debt, tga] = await Promise.all([
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
history ?
|
|
160
|
+
readCash(signal, timeoutMs),
|
|
161
|
+
readDebt(signal, timeoutMs),
|
|
162
|
+
history ? readTga(signal, timeoutMs).then(
|
|
134
163
|
(closes) => ({ closes }),
|
|
135
164
|
(error: unknown) => ({ closes: [] as TgaClose[], error: error instanceof Error ? error.message : String(error) }),
|
|
136
165
|
) : { closes: [] as TgaClose[] },
|
|
137
|
-
])
|
|
166
|
+
]).catch((error: unknown) => {
|
|
167
|
+
if (error === signal?.reason && signal?.aborted) throw error;
|
|
168
|
+
if (error instanceof ApiRequestError || error instanceof OperationTimeoutError) throw new Error(error.message);
|
|
169
|
+
throw error;
|
|
170
|
+
});
|
|
171
|
+
signal?.throwIfAborted();
|
|
138
172
|
return {
|
|
139
173
|
cash: parseOperatingCash(cash),
|
|
140
174
|
debt: parseDebtToPenny(debt),
|
|
@@ -15,13 +15,14 @@ import { spanAxisFormatter } from "../../../components/chart-table";
|
|
|
15
15
|
import { useChartViewReset } from "../../../components/chart/core/view-reset";
|
|
16
16
|
import { scalarPoint, staticSeries } from "../../../components/chart/static/series";
|
|
17
17
|
import { handleRefreshKey, usePaneRefreshKey } from "../../../components/data-table/table-pane";
|
|
18
|
-
import {
|
|
18
|
+
import { STALE_SEGMENT } from "../../../components/layout/pane/status-footer";
|
|
19
|
+
import { useAutoRefresh, usePluginPaneState } from "../../../public/react";
|
|
19
20
|
import { useThemeColors } from "../../../theme/theme-context";
|
|
20
21
|
import type { PaneProps } from "../../../types/plugin";
|
|
21
22
|
import { Box } from "../../../ui";
|
|
22
23
|
import { formatNumber } from "../../../utils/format";
|
|
23
24
|
import { isPlainKeyboardEvent } from "../../../utils/keyboard";
|
|
24
|
-
import {
|
|
25
|
+
import { useTreasuryDailyResources } from "./resource";
|
|
25
26
|
import {
|
|
26
27
|
CASH_COLUMNS,
|
|
27
28
|
DEBT_COLUMNS,
|
|
@@ -54,24 +55,19 @@ function scaledCell(value: number | null, text: string, muted: string): DataTabl
|
|
|
54
55
|
|
|
55
56
|
export function TreasuryDailyPane({ width, height, focused }: PaneProps) {
|
|
56
57
|
const colors = useThemeColors();
|
|
57
|
-
const
|
|
58
|
-
const resource = useAsyncResource(request);
|
|
58
|
+
const { cash, debt, history } = useTreasuryDailyResources();
|
|
59
59
|
const [storedTab, setTab] = usePluginPaneState<string>("tab", "cash");
|
|
60
60
|
const tab: TreasuryTab = storedTab === "debt" ? "debt" : "cash";
|
|
61
|
-
const
|
|
62
|
-
const cashRows = data?.
|
|
63
|
-
const debtRows = data
|
|
61
|
+
const active = tab === "cash" ? cash : debt;
|
|
62
|
+
const cashRows = cash.data?.rows ?? EMPTY_CASH;
|
|
63
|
+
const debtRows = debt.data ?? EMPTY_DEBT;
|
|
64
64
|
const activeRows = tab === "cash" ? cashRows : debtRows;
|
|
65
|
-
const recordDate = tab === "cash" ? data?.
|
|
65
|
+
const recordDate = tab === "cash" ? cash.data?.recordDate ?? null : debtRows[0]?.date ?? null;
|
|
66
66
|
const [storedRange, setStoredRange] = usePluginPaneState<string>("range", "1Y");
|
|
67
67
|
const range = tgaRange(storedRange);
|
|
68
68
|
const resetChartView = useChartViewReset();
|
|
69
69
|
const [selectedId, setSelectedId] = useState<string | null>(null);
|
|
70
70
|
const resolvedId = activeRows.some((row) => row.id === selectedId) ? selectedId : activeRows[0]?.id ?? null;
|
|
71
|
-
const info = useMemo(
|
|
72
|
-
() => (recordDate ? [{ id: "record-date", parts: [{ text: recordDate, tone: "muted" as const }] }] : []),
|
|
73
|
-
[recordDate],
|
|
74
|
-
);
|
|
75
71
|
const { strip, rows: tabRows } = usePaneTabs({
|
|
76
72
|
tabs: TREASURY_TABS,
|
|
77
73
|
activeValue: tab,
|
|
@@ -79,30 +75,55 @@ export function TreasuryDailyPane({ width, height, focused }: PaneProps) {
|
|
|
79
75
|
focused,
|
|
80
76
|
dense: true,
|
|
81
77
|
});
|
|
82
|
-
|
|
83
|
-
const
|
|
78
|
+
const resources = [cash, debt, history];
|
|
79
|
+
const lastUpdated = resources.every((section) => section.updatedAt !== null && section.savedAt === null && !section.error)
|
|
80
|
+
? Math.min(...resources.map((section) => section.updatedAt!)) : null;
|
|
81
|
+
const refresh = useCallback(() => {
|
|
82
|
+
cash.reload();
|
|
83
|
+
debt.reload();
|
|
84
|
+
history.reload();
|
|
85
|
+
}, [cash.reload, debt.reload, history.reload]);
|
|
86
|
+
useAutoRefresh(lastUpdated, refresh);
|
|
84
87
|
usePaneRefreshKey(refresh, { focused });
|
|
88
|
+
const subject = tab === "cash" ? "Treasury cash" : "Treasury debt";
|
|
89
|
+
const activeError = active.data ? null : active.error;
|
|
90
|
+
const activeLoading = !active.data && active.loading;
|
|
91
|
+
const historyDate = tab === "cash" && history.savedAt !== null ? history.data?.at(-1)?.date : undefined;
|
|
92
|
+
const partial = resources.some((section) => section.error) && resources.some((section) => section.data);
|
|
93
|
+
const stale = active.savedAt !== null;
|
|
94
|
+
const info = useMemo(() => [
|
|
95
|
+
...(recordDate ? [{ id: "record-date", capture: partial || stale, parts: [{ text: recordDate, tone: "muted" as const }] }] : []),
|
|
96
|
+
...(stale ? [{ ...STALE_SEGMENT, capture: true }] : []),
|
|
97
|
+
...(historyDate ? [{ id: "history-date", capture: true, parts: [{ text: `History stale · ${historyDate}`, tone: "warning" as const }] }] : []),
|
|
98
|
+
...(partial ? [{ id: "partial", capture: true, parts: [{ text: "partial", tone: "warning" as const }] }] : []),
|
|
99
|
+
], [historyDate, partial, recordDate, stale]);
|
|
85
100
|
usePaneStatusFooter({
|
|
86
101
|
registrationId: TREASURY_DAILY_PANE_ID,
|
|
87
|
-
loading:
|
|
88
|
-
error:
|
|
102
|
+
loading: active.loading,
|
|
103
|
+
error: activeError,
|
|
89
104
|
info,
|
|
90
105
|
});
|
|
91
106
|
usePaneNoticeFooter({
|
|
92
|
-
registrationId: `${TREASURY_DAILY_PANE_ID}:
|
|
93
|
-
focused
|
|
94
|
-
notices:
|
|
107
|
+
registrationId: `${TREASURY_DAILY_PANE_ID}:warnings`,
|
|
108
|
+
focused,
|
|
109
|
+
notices: [
|
|
110
|
+
{ label: "Cash", section: cash, bodyError: tab === "cash" && activeError },
|
|
111
|
+
{ label: "Debt", section: debt, bodyError: tab === "debt" && activeError },
|
|
112
|
+
{ label: "Closing balance history", section: history, bodyError: false },
|
|
113
|
+
].flatMap(({ label, section, bodyError }) => section.error && !bodyError
|
|
114
|
+
? [`${label} ${section.data ? "refresh failed; showing saved data" : "unavailable"}: ${section.error}`]
|
|
115
|
+
: []),
|
|
95
116
|
});
|
|
96
117
|
|
|
97
118
|
// The closing balance the table's last line states for the day, drawn over the range chosen.
|
|
98
119
|
const series = useMemo(() => {
|
|
99
|
-
const closes = tgaClosesInRange(data
|
|
120
|
+
const closes = tgaClosesInRange(history.data ?? [], range);
|
|
100
121
|
return closes.length < 2 ? [] : [staticSeries(
|
|
101
122
|
closes.map((close) => scalarPoint(new Date(`${close.date}T00:00:00Z`), close.millions / 1_000)),
|
|
102
123
|
{ id: "tga-closing-balance", label: TGA_SERIES_LABEL, color: colors.positive, calendarSpaced: true },
|
|
103
124
|
)];
|
|
104
|
-
}, [colors.positive, data
|
|
105
|
-
const chart: ChartTableChart | null = data
|
|
125
|
+
}, [colors.positive, history.data, range]);
|
|
126
|
+
const chart: ChartTableChart | null = !history.data ? null : {
|
|
106
127
|
series,
|
|
107
128
|
formatValue: formatBillionsLevel,
|
|
108
129
|
formatAxisValue: formatBillionsAxis,
|
|
@@ -136,16 +157,15 @@ export function TreasuryDailyPane({ width, height, focused }: PaneProps) {
|
|
|
136
157
|
}, [colors.textMuted]);
|
|
137
158
|
|
|
138
159
|
let body = null;
|
|
139
|
-
if (
|
|
160
|
+
if (activeLoading && (tab === "debt" || !chart)) {
|
|
140
161
|
body = <PaneStatusBody loading align="center" />;
|
|
141
|
-
} else if (
|
|
142
|
-
body = <PaneStatusBody error={resource.error} subject="Treasury cash and debt" />;
|
|
143
|
-
} else if (data && tab === "cash") {
|
|
162
|
+
} else if (tab === "cash") {
|
|
144
163
|
body = (
|
|
145
164
|
<DataTableView<CashAccount, CashColumn>
|
|
146
165
|
focused={focused}
|
|
147
166
|
rootWidth={width}
|
|
148
167
|
rootHeight={bodyHeight}
|
|
168
|
+
status={{ loading: activeLoading, error: activeError, subject }}
|
|
149
169
|
rootBefore={chart ? (
|
|
150
170
|
<ChartTableHeader
|
|
151
171
|
width={width}
|
|
@@ -186,12 +206,13 @@ export function TreasuryDailyPane({ width, height, focused }: PaneProps) {
|
|
|
186
206
|
emptyStateTitle="No cash balance for this day."
|
|
187
207
|
/>
|
|
188
208
|
);
|
|
189
|
-
} else
|
|
209
|
+
} else {
|
|
190
210
|
body = (
|
|
191
211
|
<DataTableView<DebtDay, DebtColumn>
|
|
192
212
|
focused={focused}
|
|
193
213
|
rootWidth={width}
|
|
194
214
|
rootHeight={bodyHeight}
|
|
215
|
+
status={{ error: activeError, subject }}
|
|
195
216
|
columns={DEBT_COLUMNS}
|
|
196
217
|
items={debtRows}
|
|
197
218
|
sortColumnId={null}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef } from "react";
|
|
2
|
+
import { isTransientFailure } from "../../../api-client/errors";
|
|
3
|
+
import { useAsyncResource } from "../../../public/react";
|
|
4
|
+
import { fetchTreasuryCash, fetchTreasuryDebt, fetchTreasuryHistory } from "./client";
|
|
5
|
+
import { TREASURY_DAILY_PANE_ID } from "./model";
|
|
6
|
+
|
|
7
|
+
function useStatementSection<T>(section: string, read: (signal: AbortSignal, timeoutMs?: number) => Promise<T>, timeoutMs?: number) {
|
|
8
|
+
const pending = useRef<AbortController | null>(null);
|
|
9
|
+
useEffect(() => () => pending.current?.abort(), []);
|
|
10
|
+
const load = useCallback(async () => {
|
|
11
|
+
pending.current?.abort();
|
|
12
|
+
const controller = new AbortController();
|
|
13
|
+
pending.current = controller;
|
|
14
|
+
try {
|
|
15
|
+
return await read(controller.signal, timeoutMs);
|
|
16
|
+
} finally {
|
|
17
|
+
if (pending.current === controller) pending.current = null;
|
|
18
|
+
}
|
|
19
|
+
}, [read, timeoutMs]);
|
|
20
|
+
return useAsyncResource(load, {
|
|
21
|
+
savedCopy: { key: [TREASURY_DAILY_PANE_ID, section] },
|
|
22
|
+
clearOnError: (error) => !isTransientFailure(error),
|
|
23
|
+
showSavedCopyFooter: false,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function useTreasuryDailyResources(timeoutMs?: number) {
|
|
28
|
+
return {
|
|
29
|
+
cash: useStatementSection("cash", fetchTreasuryCash, timeoutMs),
|
|
30
|
+
debt: useStatementSection("debt", fetchTreasuryDebt, timeoutMs),
|
|
31
|
+
history: useStatementSection("history", fetchTreasuryHistory, timeoutMs),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
@@ -33,6 +33,8 @@ export const POSITIONS_EXPORT_BROKERS = ["Fidelity", "Schwab", "Vanguard", "E*TR
|
|
|
33
33
|
export interface FilePosition {
|
|
34
34
|
/** The symbol as the file writes it, cleaned of marks (BRK/B reads BRK.B). */
|
|
35
35
|
symbol: string;
|
|
36
|
+
/** Unambiguous lookup spelling: a broker's DUAL/N is class N, not the Reuters code DUAL.N. */
|
|
37
|
+
lookupSymbol: string;
|
|
36
38
|
description: string | null;
|
|
37
39
|
/** Signed: a negative count is a short. */
|
|
38
40
|
shares: number;
|
|
@@ -394,18 +396,19 @@ function readCurrency(text: string): string | null {
|
|
|
394
396
|
return /^[A-Z]{3}$/.test(code) && isCurrencyCode(code) ? code : null;
|
|
395
397
|
}
|
|
396
398
|
|
|
397
|
-
/** The symbol cleaned of the marks exports add
|
|
399
|
+
/** The symbol cleaned of the marks exports add, such as Fidelity's `**` core money market. */
|
|
398
400
|
function cleanSymbol(text: string): string {
|
|
399
401
|
// Too long for a ticker: kept as written, so it is skipped as not one.
|
|
400
402
|
if (text.length > MAX_SYMBOL_CELL) return text.trim().toUpperCase();
|
|
401
403
|
const symbol = text.trim().replace(/\*+$/, "").toUpperCase();
|
|
402
404
|
if (!symbol || /^-+$/.test(symbol) || /^n\/?a$/i.test(symbol)) return "";
|
|
403
|
-
return symbol
|
|
405
|
+
return symbol;
|
|
404
406
|
}
|
|
405
407
|
|
|
406
408
|
interface ReadRow {
|
|
407
409
|
line: number;
|
|
408
410
|
symbol: string;
|
|
411
|
+
lookupSymbol: string;
|
|
409
412
|
description: string | null;
|
|
410
413
|
shares: number;
|
|
411
414
|
avgCost: number | null;
|
|
@@ -437,11 +440,14 @@ function readRow(record: CsvRecord, header: Header, options: RowOptions): RowRea
|
|
|
437
440
|
const type = cell("securityType");
|
|
438
441
|
const lead = rawSymbol || filled[0]!.trim();
|
|
439
442
|
if (TOTAL_ROW.test(lead) || (!rawSymbol && description && TOTAL_ROW.test(description))) return { kind: "ignored" };
|
|
440
|
-
const
|
|
443
|
+
const cleaned = cleanSymbol(rawSymbol);
|
|
444
|
+
const symbol = cleaned.replace(/\//g, ".");
|
|
441
445
|
const label = clip((symbol ? rawSymbol : description) || lead);
|
|
442
446
|
const skip = (kind: keyof typeof SKIP_REASONS): RowReading => ({
|
|
443
447
|
kind: "skipped",
|
|
444
|
-
skipped: { line, label, reason: SKIP_REASONS[kind], kind,
|
|
448
|
+
skipped: { line, label, reason: SKIP_REASONS[kind], kind,
|
|
449
|
+
symbol: kind === "option" ? (rawSymbol && rawSymbol.length <= MAX_SYMBOL_CELL ? rawSymbol : null)
|
|
450
|
+
: symbol && symbol.length <= MAX_SYMBOL_CELL ? symbol : null },
|
|
445
451
|
});
|
|
446
452
|
if (PENDING_ROW.test(rawSymbol) || (!rawSymbol && description && PENDING_ROW.test(description))) return skip("pending");
|
|
447
453
|
const upper = rawSymbol.trim().toUpperCase();
|
|
@@ -474,6 +480,7 @@ function readRow(record: CsvRecord, header: Header, options: RowOptions): RowRea
|
|
|
474
480
|
row: {
|
|
475
481
|
line,
|
|
476
482
|
symbol,
|
|
483
|
+
lookupSymbol: cleaned.replace(/^([A-Z0-9]+)\/([A-Z])(?=:|$)/, "$1-$2").replace(/\//g, "."),
|
|
477
484
|
description,
|
|
478
485
|
shares,
|
|
479
486
|
avgCost,
|
|
@@ -506,6 +513,7 @@ function mergeRows(rows: readonly ReadRow[]): { position: FilePosition } | { ski
|
|
|
506
513
|
return {
|
|
507
514
|
position: {
|
|
508
515
|
symbol: first.symbol,
|
|
516
|
+
lookupSymbol: first.lookupSymbol,
|
|
509
517
|
description: rows.find((row) => row.description)?.description ?? null,
|
|
510
518
|
shares,
|
|
511
519
|
avgCost,
|
|
@@ -662,9 +670,9 @@ export function parsePositionsFile(text: string, now = new Date()): PositionsFil
|
|
|
662
670
|
const reading = readRow(record, section.header, options);
|
|
663
671
|
if (reading.kind === "skipped") skipped.push(reading.skipped);
|
|
664
672
|
if (reading.kind !== "position") continue;
|
|
665
|
-
const rows = bySymbol.get(reading.row.
|
|
673
|
+
const rows = bySymbol.get(reading.row.lookupSymbol) ?? [];
|
|
666
674
|
rows.push(reading.row);
|
|
667
|
-
bySymbol.set(reading.row.
|
|
675
|
+
bySymbol.set(reading.row.lookupSymbol, rows);
|
|
668
676
|
}
|
|
669
677
|
}
|
|
670
678
|
if (bySymbol.size > MAX_IMPORT_POSITIONS) {
|
|
@@ -113,6 +113,7 @@ function combine(positions: readonly FilePosition[]): FilePosition | { kind: Ski
|
|
|
113
113
|
const dates = positions.map((position) => position.dateAcquired).filter((date): date is string => !!date).sort();
|
|
114
114
|
return {
|
|
115
115
|
symbol: positions[0]!.symbol,
|
|
116
|
+
lookupSymbol: positions[0]!.lookupSymbol,
|
|
116
117
|
description: positions.find((position) => position.description)?.description ?? null,
|
|
117
118
|
shares,
|
|
118
119
|
avgCost,
|
|
@@ -151,7 +152,7 @@ export function buildPositionsImportPlan({
|
|
|
151
152
|
const skipped: SkippedFileRow[] = [...file.skipped];
|
|
152
153
|
const groups = new Map<string, { ticker: TickerRecord; positions: FilePosition[]; notes: string[] }>();
|
|
153
154
|
for (const position of file.positions) {
|
|
154
|
-
const resolution = resolutions.get(position.
|
|
155
|
+
const resolution = resolutions.get(position.lookupSymbol);
|
|
155
156
|
if (!resolution || "error" in resolution) {
|
|
156
157
|
skipped.push({ line: position.lines[0]!, label: position.symbol, reason: resolution?.error ?? "not looked up", kind: "lookup", symbol: position.symbol });
|
|
157
158
|
continue;
|
|
@@ -186,7 +187,7 @@ export function buildPositionsImportPlan({
|
|
|
186
187
|
}
|
|
187
188
|
if (prefill && prefill.lotCount > 1) notes.push(`its ${prefill.lotCount} lots become one position`);
|
|
188
189
|
rows.push({
|
|
189
|
-
symbols: group.positions.map((position) => position.symbol),
|
|
190
|
+
symbols: [...new Set(group.positions.map((position) => position.symbol))],
|
|
190
191
|
ticker: holding ?? group.ticker,
|
|
191
192
|
shares: combined.shares,
|
|
192
193
|
avgCost: keptCost ? keptCost.avgCost! : combined.avgCost,
|
|
@@ -48,6 +48,8 @@ export function useAsyncResource<T>(
|
|
|
48
48
|
* depends on, so a copy is only ever shown for the same question.
|
|
49
49
|
*/
|
|
50
50
|
savedCopy?: SavedCopyKey | null;
|
|
51
|
+
/** A pane with multiple resources can label its own section-specific saved data. */
|
|
52
|
+
showSavedCopyFooter?: boolean;
|
|
51
53
|
shouldSave?: (data: T) => boolean;
|
|
52
54
|
/** The request is identified, but its live inputs are not ready yet. */
|
|
53
55
|
deferLoad?: boolean;
|
|
@@ -148,7 +150,7 @@ export function useAsyncResource<T>(
|
|
|
148
150
|
const reloadAndWait = useCallback(() => settle(true), [settle]);
|
|
149
151
|
const { data, error, updatedAt, savedAt } = view;
|
|
150
152
|
const loading = view.loading && !deferLoad;
|
|
151
|
-
useSavedCopyFooter(savedAt, loading || deferLoad);
|
|
153
|
+
useSavedCopyFooter(options.showSavedCopyFooter === false ? null : savedAt, loading || deferLoad);
|
|
152
154
|
useEffect(() => {
|
|
153
155
|
if (deferLoad || !loader) return;
|
|
154
156
|
const invalidate = () => { generation.current += 1; };
|
|
@@ -289,6 +289,8 @@ export function WebDataTable<T, C extends DataTableColumn = DataTableColumn>({
|
|
|
289
289
|
if (nextValue > 0) reportViewportWidthRef.current?.(nextValue);
|
|
290
290
|
}, []);
|
|
291
291
|
const scheduleViewportWidthMeasure = useRafCallback(measureViewportWidth);
|
|
292
|
+
// Which columns the body's edges cut (below), read again whenever the body changes size.
|
|
293
|
+
const measureCutColumnsRef = useRef<(sync: boolean) => void>(() => {});
|
|
292
294
|
// Measured before the first paint, so the table is never drawn with columns it is about to give up.
|
|
293
295
|
useLayoutEffect(measureViewportWidth, [measureViewportWidth]);
|
|
294
296
|
|
|
@@ -300,6 +302,7 @@ export function WebDataTable<T, C extends DataTableColumn = DataTableColumn>({
|
|
|
300
302
|
const measure = () => {
|
|
301
303
|
scheduleViewportWidthMeasure();
|
|
302
304
|
scheduleVisibleRangeMeasure();
|
|
305
|
+
measureCutColumnsRef.current(false);
|
|
303
306
|
};
|
|
304
307
|
// While the pointer resizes the pane, its columns stretch by CSS and the
|
|
305
308
|
// pane renders the table at the new size a few times a second; measuring
|
|
@@ -421,6 +424,40 @@ export function WebDataTable<T, C extends DataTableColumn = DataTableColumn>({
|
|
|
421
424
|
// No further than puts its left edge beside what stays (the frozen column, or the table's own edge).
|
|
422
425
|
if (overRight > 0) body.scrollLeft += Math.min(overRight + inset, rect.left - bounds.left - stays);
|
|
423
426
|
}, [columns, freezeFirstColumn, horizontalScrollEnabled, scrollToColumn]);
|
|
427
|
+
// The columns the body's edges cut, read off the page as the terminal reads them off its viewport: a name reads on
|
|
428
|
+
// into the next column's blank only where both show whole (tableCellSpill), so a name beside a column half out of
|
|
429
|
+
// view keeps its ellipsis in view. Null while every column shows whole. The body cuts columns where the table
|
|
430
|
+
// scrolls sideways, and where it does not but its columns are as wide as the body or wider: tracks kept at their
|
|
431
|
+
// set widths (`fillAvailableWidth={false}`) run past it, scrolling or not.
|
|
432
|
+
const columnsMayBeCut = horizontalScrollEnabled || tableWidth >= viewportWidth;
|
|
433
|
+
const [cutColumns, setCutColumns] = useState<readonly boolean[] | null>(null);
|
|
434
|
+
const cutColumnsRef = useRef(cutColumns);
|
|
435
|
+
const measuredScrollLeftRef = useRef<number | null>(null);
|
|
436
|
+
const measureCutColumns = useCallback((sync: boolean) => {
|
|
437
|
+
const body = bodyElementRef.current;
|
|
438
|
+
let next: boolean[] | null = null;
|
|
439
|
+
// A table narrower than its body reads nothing off the page: every column of it shows whole.
|
|
440
|
+
if (body && columnsMayBeCut) {
|
|
441
|
+
measuredScrollLeftRef.current = body.scrollLeft;
|
|
442
|
+
const left = body.getBoundingClientRect().left + body.clientLeft;
|
|
443
|
+
const right = left + body.clientWidth;
|
|
444
|
+
const cut = Array.from(body.querySelectorAll<HTMLElement>('[data-gloom-role="data-table-header-cell"]'), (cell) => {
|
|
445
|
+
const rect = cell.getBoundingClientRect();
|
|
446
|
+
// Half a pixel either way is the page rounding a column that shows whole.
|
|
447
|
+
return rect.left < left - 0.5 || rect.right > right + 0.5;
|
|
448
|
+
});
|
|
449
|
+
if (cut.includes(true)) next = cut;
|
|
450
|
+
}
|
|
451
|
+
const current = cutColumnsRef.current;
|
|
452
|
+
if (current === next || (current && next && current.length === next.length && current.every((value, index) => value === next[index]))) return;
|
|
453
|
+
cutColumnsRef.current = next;
|
|
454
|
+
// From a scroll, before the frame shows a name running on under the edge.
|
|
455
|
+
if (sync) flushSync(() => setCutColumns(next));
|
|
456
|
+
else setCutColumns(next);
|
|
457
|
+
}, [columnsMayBeCut]);
|
|
458
|
+
measureCutColumnsRef.current = measureCutColumns;
|
|
459
|
+
// Set only on a change: a state update from a layout effect costs the render a second commit.
|
|
460
|
+
useLayoutEffect(() => { measureCutColumns(false); }, [columns, gridTemplateColumns, measureCutColumns, pinned, viewportWidth]);
|
|
424
461
|
const hiddenColumns = items.length ? hiddenTableColumnDisclosure(columns) : null;
|
|
425
462
|
const disclosureHeight = hiddenColumns ? headerPx : 0;
|
|
426
463
|
// A frozen first column already covers what scrolls under it, so the left
|
|
@@ -517,6 +554,8 @@ export function WebDataTable<T, C extends DataTableColumn = DataTableColumn>({
|
|
|
517
554
|
if (!pinned && left > 0) flushSync(() => setFrozenScrollLeft(left));
|
|
518
555
|
else setFrozenScrollLeft(left);
|
|
519
556
|
}
|
|
557
|
+
// A scroll down or up moves no column past an edge: only a sideways one is measured.
|
|
558
|
+
if (columnsMayBeCut && event.currentTarget.scrollLeft !== measuredScrollLeftRef.current) measureCutColumns(true);
|
|
520
559
|
const controlledOffset = controlledScrollOffsetRef.current;
|
|
521
560
|
controlledScrollOffsetRef.current = null;
|
|
522
561
|
if (controlledOffset
|
|
@@ -595,6 +634,7 @@ export function WebDataTable<T, C extends DataTableColumn = DataTableColumn>({
|
|
|
595
634
|
// Only a frozen first column scrolled past places itself by it: every
|
|
596
635
|
// other row stays memoized when the viewport changes width.
|
|
597
636
|
viewportWidth={pinned && frozenScrollLeft > 0 ? viewportWidth : 0}
|
|
637
|
+
cutColumns={cutColumns}
|
|
598
638
|
columnGap={columnGap}
|
|
599
639
|
horizontalPadding={horizontalPadding}
|
|
600
640
|
focusPane={focusPane}
|