@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.
Files changed (103) hide show
  1. package/package.json +1 -1
  2. package/patches/@opentui%2Fcore@0.3.2.patch +16 -0
  3. package/src/api-client/socket-connection.ts +355 -0
  4. package/src/api-client/socket-features.ts +75 -0
  5. package/src/api-client/socket-frames.ts +161 -0
  6. package/src/api-client/socket-listeners.ts +207 -0
  7. package/src/api-client/socket-quotes.ts +332 -0
  8. package/src/api-client/socket.ts +150 -983
  9. package/src/brokers/signed-in/adapter.ts +19 -5
  10. package/src/brokers/signed-in/client.ts +13 -1
  11. package/src/brokers/signed-in/sign-in-dialog.tsx +33 -9
  12. package/src/components/chart/native/kitty/manager.ts +2 -0
  13. package/src/components/chart/native/surface/manager.ts +211 -11
  14. package/src/components/command-bar/panel/index.tsx +2 -13
  15. package/src/components/command-bar/panel/layout.ts +1 -7
  16. package/src/components/command-bar/panel/runtime.ts +0 -1
  17. package/src/components/command-bar/panel/types.ts +0 -2
  18. package/src/components/data-table/column-menu.tsx +89 -0
  19. package/src/components/data-table/sort-menu.tsx +9 -2
  20. package/src/components/data-table/view.tsx +33 -6
  21. package/src/components/form-modal/content.tsx +10 -0
  22. package/src/components/index.ts +1 -1
  23. package/src/components/layout/pane/footer/index.tsx +25 -11
  24. package/src/components/layout/pane/footer/model.ts +62 -20
  25. package/src/components/layout/pane/sidebar.tsx +125 -15
  26. package/src/components/layout/shell/active-drag.ts +18 -13
  27. package/src/components/layout/shell/drag/magnets.ts +34 -18
  28. package/src/components/ticker/list-table-view.tsx +5 -0
  29. package/src/components/ui/data-table/column-order.ts +180 -0
  30. package/src/components/ui/data-table/index.tsx +12 -1
  31. package/src/components/ui/data-table/opentui/index.tsx +267 -23
  32. package/src/components/ui/data-table/opentui/model.ts +43 -4
  33. package/src/components/ui/data-table/types.ts +49 -0
  34. package/src/components/ui/data-table/use-column-order.ts +135 -0
  35. package/src/components/ui/index.ts +1 -1
  36. package/src/components/ui/table-layout.ts +120 -0
  37. package/src/docs/snapshot.json +3 -2
  38. package/src/i18n/es.ts +2 -0
  39. package/src/i18n/ja.ts +2 -0
  40. package/src/i18n/ko.ts +2 -0
  41. package/src/i18n/zh-cn.ts +2 -0
  42. package/src/i18n/zh-tw.ts +2 -0
  43. package/src/market-data/coordinator/index.ts +4 -3
  44. package/src/market-data/coordinator/quotes.ts +12 -4
  45. package/src/market-data/quotes/freshness.ts +12 -0
  46. package/src/market-data/quotes/live-valuation.ts +1 -1
  47. package/src/market-data/quotes/regular-session-valuation.ts +1 -1
  48. package/src/plugins/builtin/broker-manager/detail.tsx +5 -3
  49. package/src/plugins/builtin/broker-manager/index.tsx +6 -6
  50. package/src/plugins/builtin/broker-manager/model.ts +15 -6
  51. package/src/plugins/builtin/broker-manager/pane-actions.tsx +11 -4
  52. package/src/plugins/builtin/broker-manager/sign-in-end.ts +50 -19
  53. package/src/plugins/builtin/broker-manager/table.ts +10 -4
  54. package/src/plugins/builtin/chat/sidebar.tsx +33 -16
  55. package/src/plugins/builtin/cloud/askg/tool-timeline.tsx +2 -0
  56. package/src/plugins/builtin/equity-screener/live.ts +74 -18
  57. package/src/plugins/builtin/equity-screener/model.ts +19 -4
  58. package/src/plugins/builtin/equity-screener/pane.tsx +19 -14
  59. package/src/plugins/builtin/equity-screener/refresh-anchor.ts +45 -0
  60. package/src/plugins/builtin/equity-screener/results.ts +22 -2
  61. package/src/plugins/builtin/equity-screener/screen-check.ts +9 -3
  62. package/src/plugins/builtin/futures/index.tsx +15 -1
  63. package/src/plugins/builtin/futures/table.tsx +1 -1
  64. package/src/plugins/builtin/fx-matrix/index.tsx +2 -0
  65. package/src/plugins/builtin/holders/pane.tsx +30 -20
  66. package/src/plugins/builtin/iv-history/events.ts +5 -0
  67. package/src/plugins/builtin/iv-history/headless.ts +7 -2
  68. package/src/plugins/builtin/kelly-sizer/sections.tsx +2 -0
  69. package/src/plugins/builtin/macro-day/headless.ts +12 -3
  70. package/src/plugins/builtin/options/view.tsx +2 -0
  71. package/src/plugins/builtin/options-scenario/pane.tsx +2 -1
  72. package/src/plugins/builtin/perps/cascade-tabs.tsx +2 -1
  73. package/src/plugins/builtin/portfolio-list/pane/index.tsx +13 -0
  74. package/src/plugins/builtin/portfolio-list/table.tsx +5 -0
  75. package/src/plugins/builtin/rate-path/pane.tsx +2 -0
  76. package/src/plugins/builtin/revenue-breakdown/pane.tsx +2 -0
  77. package/src/plugins/builtin/reverse-dcf/pane.tsx +2 -1
  78. package/src/plugins/builtin/seasonality/pane.tsx +2 -1
  79. package/src/plugins/builtin/thirteenf/pane.tsx +2 -0
  80. package/src/plugins/builtin/ticker-detail/financials/model.ts +28 -6
  81. package/src/plugins/builtin/ticker-detail/financials/ratio-table.tsx +26 -9
  82. package/src/plugins/builtin/ticker-detail/financials/tab.tsx +58 -35
  83. package/src/plugins/builtin/vol-surface/heat-grid.tsx +2 -1
  84. package/src/plugins/builtin/vol-surface/pane.tsx +2 -1
  85. package/src/plugins/builtin/world-indices/index.tsx +5 -1
  86. package/src/plugins/builtin/yield-curve/index.tsx +2 -1
  87. package/src/renderers/dom/data-table/column-drag.ts +147 -0
  88. package/src/renderers/dom/data-table/index.tsx +22 -0
  89. package/src/renderers/dom/data-table/row.tsx +27 -5
  90. package/src/renderers/dom/styles.css +22 -0
  91. package/src/renderers/opentui/chart-surface.tsx +1 -0
  92. package/src/renderers/opentui/frame-hits.ts +33 -0
  93. package/src/renderers/opentui/host.tsx +2 -0
  94. package/src/renderers/opentui/native-surface.ts +14 -21
  95. package/src/renderers/opentui/test-utils.tsx +3 -0
  96. package/src/state/app/context/index.tsx +22 -0
  97. package/src/test-support/app-store.ts +24 -1
  98. package/src/time-series/live-quotes.ts +3 -9
  99. package/src/ui/host.tsx +18 -0
  100. package/src/ui/pointer-drag.ts +11 -2
  101. package/src/utils/fundamentals.ts +14 -3
  102. package/src/utils/share-multiples.cases.json +780 -2
  103. package/src/utils/share-multiples.ts +154 -24
@@ -15,7 +15,7 @@ import {
15
15
  import { handleRefreshKey } from "../../../components/data-table/table-pane";
16
16
  import { useRemoteUiNode } from "../../../remote/semantic-tree";
17
17
  import { usePaneVisible } from "../../../state/app/activity";
18
- import { usePaneInstance, usePaneSettingValue } from "../../../state/app/context";
18
+ import { useOptionalPaneSettingUpdater, usePaneInstance, usePaneSettingValue } from "../../../state/app/context";
19
19
  import { TICKER_RESEARCH_PANE_ID } from "../../../types/config";
20
20
  import type { PaneProps } from "../../../types/plugin";
21
21
  import { isPlainKey } from "../../../utils/keyboard";
@@ -60,6 +60,7 @@ import {
60
60
  } from "./model";
61
61
  import {
62
62
  createFuturesColumns,
63
+ DEFAULT_FUTURES_COLUMN_IDS,
63
64
  FUTURES_COLUMN_DEFS,
64
65
  FUTURES_REPORT_COLUMNS,
65
66
  renderFuturesCell,
@@ -88,6 +89,7 @@ export function FuturesPane({ focused, width, height }: PaneProps) {
88
89
  const { pinTicker } = usePluginTickerActions();
89
90
  const dataProvider = useAssetData();
90
91
  const paneInstance = usePaneInstance();
92
+ const updateColumnIds = useOptionalPaneSettingUpdater(paneInstance?.instanceId ?? null, "columnIds");
91
93
  const liveStreaming = useLiveStreamingSetting();
92
94
  const [selectedId, setSelectedId] = useState<string | null>(null);
93
95
  const [sortPreference, setSortPreference] = useState<FuturesSortPreference>(DEFAULT_FUTURES_SORT);
@@ -154,6 +156,17 @@ export function FuturesPane({ focused, width, height }: PaneProps) {
154
156
  })), [columns, returns]);
155
157
  const titledColumns = useMemo(() => returnBases.size === 0 ? columns
156
158
  : columns.map((column) => returnBases.has(column.id) ? { ...column, title: returnBases.get(column.id) } : column), [columns, returnBases]);
159
+ // A header dragged to a new place rewrites the Columns setting; back in the default order, the setting goes, so
160
+ // columns later added to the defaults still show. The session mark and the symbol name the row and stay first.
161
+ const anchoredColumns = columns.findIndex((column) => column.id !== "status" && column.id !== "code");
162
+ const columnReorder = useMemo(() => ({
163
+ anchored: anchoredColumns > 0 ? anchoredColumns : undefined,
164
+ control: {
165
+ order: visibleColumnIds,
166
+ defaultOrder: DEFAULT_FUTURES_COLUMN_IDS,
167
+ onChange: (ids: string[] | undefined) => updateColumnIds(() => ids),
168
+ },
169
+ }), [anchoredColumns, updateColumnIds, visibleColumnIds]);
157
170
  useRemoteUiNode(returnBases.size > 0 ? {
158
171
  role: "report-notice",
159
172
  label: "Return base dates",
@@ -369,6 +382,7 @@ export function FuturesPane({ focused, width, height }: PaneProps) {
369
382
  rootWidth={width}
370
383
  rootHeight={height}
371
384
  columns={titledColumns}
385
+ columnReorder={columnReorder}
372
386
  items={dataProvider ? rows : []}
373
387
  sortable
374
388
  sortColumnId={sortPreference.columnId}
@@ -37,7 +37,7 @@ export const FUTURES_COLUMN_DEFS: readonly FuturesColumnDef[] = [
37
37
  { id: "time", label: "Time", description: "UTC time of the last quote." },
38
38
  ];
39
39
 
40
- const DEFAULT_FUTURES_COLUMN_IDS = FUTURES_COLUMN_DEFS.map((column) => column.id);
40
+ export const DEFAULT_FUTURES_COLUMN_IDS = FUTURES_COLUMN_DEFS.map((column) => column.id);
41
41
 
42
42
  /**
43
43
  * Extra columns only earn their width once the board is wide enough to keep a
@@ -405,6 +405,8 @@ function FxMatrixPane({ focused, width, height }: PaneProps) {
405
405
  resetScrollKey={amount ? storedFxBoardAmount(amount) : ""}
406
406
  // A pane too narrow for every currency scrolls to the rest, as other wide tables do; the row's code stays.
407
407
  columns={allColumns}
408
+ // Each column is a row's currency in the same order: the matrix reads across and down alike.
409
+ columnReorder={false}
408
410
  freezeFirstColumn
409
411
  getExportMetadata={() => createFxExportMetadata(currencies, rates,
410
412
  (currency) => rateEntries.get(currency))}
@@ -19,7 +19,7 @@ import { useAsyncResource } from "../../../react/async-resource";
19
19
  import { useShortcut } from "../../../react/input";
20
20
  import { colors, priceColor } from "../../../theme/colors";
21
21
  import type { HolderData } from "../../../types/financials";
22
- import { clipToDisplayWidth, formatCompact } from "../../../utils/format";
22
+ import { clipToDisplayWidth, displayWidth, formatCompact } from "../../../utils/format";
23
23
  import { isPlainKey } from "../../../utils/keyboard";
24
24
  import { nextHeaderSort } from "../../../utils/sort-values";
25
25
  import { useAssetData, usePluginAppActions, usePluginPaneState } from "../../runtime";
@@ -66,6 +66,34 @@ function cikMatches(rows: readonly HolderRow[]): Map<string, Holder13FMatch> {
66
66
  /** The width of a three-letter badge ("13F", "ADR"): the label and its padding. */
67
67
  const BADGE_WIDTH = 5;
68
68
 
69
+ /**
70
+ * A holder's name and its markers. ADR: a position held as receipts on a home line's list. 13F: a fund
71
+ * whose filing opens on Enter or o. The name gives way first, so the markers survive a narrow column;
72
+ * the cell says how wide it draws whole (`contentWidth`), so the table fits the column to it.
73
+ */
74
+ export function holderNameCell(
75
+ name: string,
76
+ { receipts, fund }: { receipts: string; fund: boolean },
77
+ color: string,
78
+ width: number,
79
+ ): DataTableCell {
80
+ if (!receipts && !fund) return { text: name, color, attributes: TextAttributes.BOLD };
81
+ const badges = (receipts ? 1 : 0) + (fund ? 1 : 0);
82
+ return {
83
+ text: [name, receipts, fund ? "13F" : ""].filter(Boolean).join(" "),
84
+ contentWidth: displayWidth(name) + badges * (BADGE_WIDTH + 1),
85
+ content: (
86
+ <Box flexDirection="row" gap={1} width={width} overflow="hidden">
87
+ <Text fg={color} attributes={TextAttributes.BOLD}>
88
+ {clipToDisplayWidth(name, Math.max(1, width - badges * (BADGE_WIDTH + 1)))}
89
+ </Text>
90
+ {receipts ? <Badge label={receipts} /> : null}
91
+ {fund ? <Badge label="13F" tone="accent" /> : null}
92
+ </Box>
93
+ ),
94
+ };
95
+ }
96
+
69
97
  export function HoldersView({ focused, width, height }: { focused: boolean; width: number; height: number }) {
70
98
  const { nativePaneChrome } = useUiCapabilities();
71
99
  const { symbol, ticker, financials } = usePaneTicker();
@@ -286,25 +314,7 @@ export function HoldersView({ focused, width, height }: { focused: boolean; widt
286
314
  switch (column.id) {
287
315
  case "holder": {
288
316
  const color = rowState.selected ? colors.selectedText : colors.textBright;
289
- // ADR: a position held as receipts on a home line's list. 13F: a fund
290
- // whose filing opens on Enter or o.
291
- const receipts = holderShareBasisMarker(row);
292
- const fund = fundMatches.has(row.id);
293
- if (!receipts && !fund) return { text: row.name, color, attributes: TextAttributes.BOLD };
294
- const badges = (receipts ? 1 : 0) + (fund ? 1 : 0);
295
- // The name gives way first, so the markers survive a narrow column.
296
- return {
297
- text: [row.name, receipts, fund ? "13F" : ""].filter(Boolean).join(" "),
298
- content: (
299
- <Box flexDirection="row" gap={1} width={column.width} overflow="hidden">
300
- <Text fg={color} attributes={TextAttributes.BOLD}>
301
- {clipToDisplayWidth(row.name, Math.max(1, column.width - badges * (BADGE_WIDTH + 1)))}
302
- </Text>
303
- {receipts ? <Badge label={receipts} /> : null}
304
- {fund ? <Badge label="13F" tone="accent" /> : null}
305
- </Box>
306
- ),
307
- };
317
+ return holderNameCell(row.name, { receipts: holderShareBasisMarker(row), fund: fundMatches.has(row.id) }, color, column.width);
308
318
  }
309
319
  case "value":
310
320
  return { text: formatMoneyCompact(row.value, currency, { code: currencyCode }), color: colors.text };
@@ -20,6 +20,10 @@ interface ReleaseOffsetRow {
20
20
  /** 25-delta put IV minus call IV, and the risk reversal, call minus put. */
21
21
  skew25d: number | null;
22
22
  rr25d: number | null;
23
+ /** What a policy decision did (held, raised 75bp) and the rate after it and before, where Gloom Cloud has them. */
24
+ decision: string | null;
25
+ actual: string | null;
26
+ prior: string | null;
23
27
  }
24
28
 
25
29
  export interface ReleaseOffsets {
@@ -132,6 +136,7 @@ export function releaseOffsetRows(
132
136
  iv30: iv30.get(date) ?? null, iv90: iv90.get(date) ?? null, iv365: iv365.get(date) ?? null,
133
137
  hv: hv.get(date) ?? null, spread: spread.get(date) ?? null,
134
138
  skew25d: skewValue, rr25d: skewValue == null ? null : -skewValue,
139
+ decision: release.figures?.decision ?? null, actual: release.figures?.actual ?? null, prior: release.figures?.prior ?? null,
135
140
  });
136
141
  }
137
142
  return result;
@@ -102,15 +102,20 @@ export const ivHistoryHeadless: HeadlessPaneDefinition<"bundle"> = {
102
102
  releases.upcomingNote,
103
103
  staleMacroReleasesNotice(releases.list),
104
104
  ].filter((note): note is string => !!note);
105
- const eventColumns = [{ key: "releaseDate", header: "Release date" }, { key: "session", header: "Session" },
105
+ // A policy decision's row says what it did (ECB raised 75bp to 0.75%), as MDAY's does; the export keeps the rate before too.
106
+ const decisionColumns = event === "fomc" || event === "ecb"
107
+ ? [{ key: "decision", header: "Decision" }, { key: "actual", header: "Actual" }, { key: "prior", header: "Prior" }] : [];
108
+ const eventColumns = [{ key: "releaseDate", header: "Release date" }, ...decisionColumns, { key: "session", header: "Session" },
106
109
  ...historyColumns.slice(1), ...skewColumns];
110
+ const decided = offsets.rows.some((row) => row.decision != null);
111
+ const textColumns = eventColumns.filter((column) => decided ? column.key !== "prior" : !decisionColumns.includes(column));
107
112
  return {
108
113
  sections: [{
109
114
  title: `${label} releases, ${offsetText(offset)}`,
110
115
  // The export names the release and the offset on every row, so files of several offsets or releases join.
111
116
  columns: [{ key: "release", header: "Release" }, eventColumns[0]!, { key: "offset", header: "Offset (sessions)" }, ...eventColumns.slice(1)],
112
117
  rows: offsets.rows.map(({ date, ...row }) => ({ ...row, session: date, release: label })),
113
- textColumns: offsets.rows.some((row) => row.skew25d != null) ? eventColumns : eventColumns.slice(0, -skewColumns.length),
118
+ textColumns: offsets.rows.some((row) => row.skew25d != null) ? textColumns : textColumns.slice(0, -skewColumns.length),
114
119
  }],
115
120
  complete: payload.status === "ready" && errors.length === 0,
116
121
  unavailableSymbols: offsets.rows.some((row) => row.iv30 != null) ? [] : [instrument.symbol], errors,
@@ -204,6 +204,8 @@ export function KellySensitivitySection({
204
204
  return (
205
205
  <DataTableView<SensitivityRow>
206
206
  columns={columns}
207
+ // Prices or returns in order: a sensitivity grid's axis.
208
+ columnReorder={false}
207
209
  items={rows}
208
210
  getItemKey={(row) => row.id}
209
211
  selection={{ kind: "none" }}
@@ -66,15 +66,24 @@ export const macroDayHeadless: HeadlessPaneDefinition<"bundle"> = {
66
66
  // The days the filter keeps get a row of their own: how the name moved on hot CPI days.
67
67
  const selected = surprise === "all" ? [] : [row(`${MACRO_SURPRISE_LABELS[surprise]} ${release === "all" ? "release"
68
68
  : MACRO_EVENT_LABELS[release as MacroEventKind]}`, macroDayStats(events, model.normal.meanAbs))];
69
- // A day without figures says why: before the kept calendar (one note for them all), or the calendar's own gap.
69
+ // A day without figures says why: before the kept calendar (one note for them all), or the calendar's own gap. An ECB
70
+ // decision before it has its rates (Gloom Cloud reads them off the deposit rate series) and lacks only the forecast.
70
71
  const figuresFrom = releases.figuresFrom;
71
- const beforeCalendar = (event: MacroDayEvent) => !!figuresFrom && event.kind !== "ipca" && !event.figures && event.date < figuresFrom;
72
+ const predates = (event: MacroDayEvent) => !!figuresFrom && event.kind !== "ipca" && event.date < figuresFrom;
73
+ const beforeCalendar = (event: MacroDayEvent) => predates(event) && !event.figures;
74
+ const noForecast = (event: MacroDayEvent) => predates(event) && !!event.figures && event.figures.forecast == null;
75
+ /** "CPI and Jobs days": the kinds of the listed days `pick` takes, in the order the summary lists them. */
76
+ const daysOf = (pick: (event: MacroDayEvent) => boolean) => {
77
+ const labels = model.kinds.filter((kind) => events.some((event) => event.kind === kind && pick(event))).map((kind) => MACRO_EVENT_LABELS[kind]);
78
+ return `${labels.length > 1 ? `${labels.slice(0, -1).join(", ")} and ${labels.at(-1)}` : labels[0]} days`;
79
+ };
72
80
  // A release Gloom Cloud alone lists (IPCA, the ECB) is summed up on its own: "Any release" is then the US ones'.
73
81
  const usOnly = model.kinds.some((kind) => !US_MACRO_EVENT_KINDS.includes(kind as (typeof US_MACRO_EVENT_KINDS)[number]));
74
82
  const missing = (event: MacroDayEvent) => event.figures ? null : event.figuresMissing
75
83
  ?? (beforeCalendar(event) ? `before ${figuresFrom}, when Gloom Cloud's economic calendar starts` : null);
76
84
  const figureNotes = [
77
- ...(events.some(beforeCalendar) ? [`Release days before ${figuresFrom} have no actual, forecast or prior: Gloom Cloud's economic calendar starts then.`] : []),
85
+ ...(events.some(beforeCalendar) ? [`${daysOf(beforeCalendar)} before ${figuresFrom} have no actual, forecast or prior: Gloom Cloud's economic calendar starts then.`] : []),
86
+ ...(events.some(noForecast) ? [`Forecasts start ${figuresFrom}, with Gloom Cloud's economic calendar: ${daysOf(noForecast)} before it have an actual and prior, no forecast or surprise.`] : []),
78
87
  ...macroFigureGapNotices(events),
79
88
  ];
80
89
  return {
@@ -1040,6 +1040,8 @@ export function OptionsView({ width, height, focused, nestedInTabs = false, ivRa
1040
1040
  headerScrollId="options-table-header-scroll"
1041
1041
  bodyScrollId="options-table-body-scroll"
1042
1042
  columns={optionColumns}
1043
+ // Calls and puts mirror each other around the strike; Settings orders their fields.
1044
+ columnReorder={false}
1043
1045
  items={rows}
1044
1046
  sortColumnId={null}
1045
1047
  sortDirection="asc"
@@ -373,7 +373,8 @@ export function OptionsScenarioPane({ width, height, focused }: PaneProps) {
373
373
  { id: "expiration", label: "Expiry", width: 12, align: "left" }, { id: "price", label: "Entry / share", width: 14, align: "right" },
374
374
  { id: "volatility", label: "IV %", width: 9, align: "right" }, { id: "multiplier", label: "Units", width: 7, align: "right" }];
375
375
  const activeContent = scenario && tab === "payoff" ? <ScenarioPayoffChart scenario={scenario} width={width} height={bodyHeight} focused={tabsFocused} session={valuedSession} />
376
- : scenario && tab === "grid" ? <DataTableView focused={focused && !volActive} rootWidth={width}
376
+ // Valuation dates in time order across the spot rows.
377
+ : scenario && tab === "grid" ? <DataTableView focused={focused && !volActive} rootWidth={width} columnReorder={false}
377
378
  rootHeight={bodyHeight} items={scenario.grid.toSorted((a, b) => { const value = (row: typeof a) => gridSort.columnId === "spot" ? row.spot : gridSort.columnId === "move" ? row.move ?? 0 : row.values[Number(gridSort.columnId)] ?? 0; return (value(a) - value(b)) * (gridSort.direction === "asc" ? 1 : -1); })}
378
379
  sortColumnId={gridSort.columnId} sortDirection={gridSort.direction} onHeaderClick={(id) => {
379
380
  // The landmark column has no label and no order of its own.
@@ -149,7 +149,8 @@ export function Depth({ asset, onAssetChange, accessKey, width, height, focused,
149
149
  </>;
150
150
  const lock = data && !pro ? <Lock text="Upgrade for hourly depth history" onPress={upgrade} role="perps-depth-upgrade" /> : null;
151
151
  return <PaneStatusBody loading={!data && resource.loading} error={!data ? resource.error : null} subject="order book depth">
152
- <DataTableView<PerpDepthRow> columns={columns} items={rows} focused={focused && !querySearch.active} rootWidth={width} rootHeight={height} rootBefore={before}
152
+ {/* Bid and ask depth in pairs at widening distances from mid: the columns keep their order. */}
153
+ <DataTableView<PerpDepthRow> columns={columns} columnReorder={false} items={rows} focused={focused && !querySearch.active} rootWidth={width} rootHeight={height} rootBefore={before}
153
154
  getItemKey={(row) => row.marketId} sortColumnId={null} sortDirection="desc" resetScrollKey={base}
154
155
  selection={{ kind: "id", selectedId: selected?.marketId ?? null, getId: (row) => row.marketId, onChange: setSelected }} onActivate={(row) => onOpenMarket(row.marketId)}
155
156
  renderCell={(row, column) => depthCell(row, column.id as DepthColumnId, colors)} selectedTextOverridesCellColor
@@ -24,6 +24,7 @@ import {
24
24
  useAppSelector,
25
25
  useAppStateRef,
26
26
  usePaneCollection,
27
+ useOptionalPaneSettingUpdater,
27
28
  usePaneInstance,
28
29
  usePaneSettingValue,
29
30
  usePaneStateValue,
@@ -34,6 +35,7 @@ import { summarizeFxRates, fxStatusLabel } from "../../../../utils/fx-status";
34
35
  import { convertCurrency } from "../../../../utils/format";
35
36
  import { nextHeaderSort } from "../../../../utils/sort-values";
36
37
  import { getSharedMarketDataCoordinator } from "../../../../market-data/coordinator";
38
+ import { DEFAULT_PORTFOLIO_COLUMN_IDS } from "../../../../types/config";
37
39
  import type { TickerRecord } from "../../../../types/ticker";
38
40
  import type { TickerFinancials } from "../../../../types/financials";
39
41
  import type { PaneProps } from "../../../../types/plugin";
@@ -169,6 +171,7 @@ export function PortfolioListPane({ focused, width, height }: PaneProps) {
169
171
  const [collectionSorts, setCollectionSorts] = usePaneStateValue<Record<string, CollectionSortPreference>>("collectionSorts", NO_COLLECTION_SORTS);
170
172
  const [cashDrawerExpanded, setCashDrawerExpanded] = usePaneStateValue<boolean>("cashDrawerExpanded", false);
171
173
  const [, setViewMode] = usePaneSettingValue<PortfolioViewMode>("viewMode", "table");
174
+ const updateColumnIds = useOptionalPaneSettingUpdater(paneInstance?.instanceId ?? null, "columnIds");
172
175
 
173
176
  const [streamWindow, setStreamWindow] = useState({ start: 0, end: 24 });
174
177
  const [quickAddFocused, setQuickAddFocused] = useState(false);
@@ -260,6 +263,15 @@ export function PortfolioListPane({ focused, width, height }: PaneProps) {
260
263
  () => resolveVisibleColumns(paneSettings.columnIds, isPortfolioTab, { targetWeights: hasTargetWeights(currentPortfolio), otherCurrencies }),
261
264
  [currentPortfolio, isPortfolioTab, otherCurrencies, paneSettings.columnIds],
262
265
  );
266
+ // A header dragged to a new place rewrites the Columns setting, so Settings lists them as the table shows them;
267
+ // back in the default order, the setting goes, so columns later added to the defaults still show.
268
+ const columnReorder = useMemo(() => ({
269
+ control: {
270
+ order: paneSettings.columnIds,
271
+ defaultOrder: DEFAULT_PORTFOLIO_COLUMN_IDS,
272
+ onChange: (ids: string[] | undefined) => updateColumnIds(() => ids),
273
+ },
274
+ }), [paneSettings.columnIds, updateColumnIds]);
263
275
  const supplementalData = usePortfolioSupplementalData(tickers, columns, appActive, financialsMap);
264
276
  // One lookup for the whole list, only while a perpetual column is on screen.
265
277
  const showsPerpetuals = viewMode === "table" && columns.some((column) => PERPETUAL_COLUMN_IDS.has(column.id));
@@ -922,6 +934,7 @@ export function PortfolioListPane({ focused, width, height }: PaneProps) {
922
934
  answeredSnapshots={answeredSnapshots}
923
935
  exportName={activeCollectionEntry?.name}
924
936
  allocationRows={allocationRows}
937
+ columnReorder={columnReorder}
925
938
  />
926
939
  ) : (
927
940
  <PortfolioGrid
@@ -10,6 +10,7 @@ import { PRICE_SPARKLINE_COLUMN_ID } from "../../../components/price-sparkline/v
10
10
  import type { QuoteFlashDirection } from "../../../components/quote-flash";
11
11
  import type { TickerTableCell, TickerTableSummaryRow } from "../../../components/ticker/list-table-view";
12
12
  import { createRowValueCache } from "../../../components/ui/row-value-cache";
13
+ import type { DataTableColumnReorder } from "../../../components/ui";
13
14
  import type { ColumnConfig } from "../../../types/config";
14
15
  import type { PricePoint, TickerFinancials } from "../../../types/financials";
15
16
  import type { TickerRecord } from "../../../types/ticker";
@@ -204,6 +205,7 @@ export function PortfolioTickerTable({
204
205
  answeredSnapshots,
205
206
  exportName,
206
207
  allocationRows,
208
+ columnReorder,
207
209
  }: {
208
210
  columns: ColumnConfig[];
209
211
  focused?: boolean;
@@ -240,6 +242,8 @@ export function PortfolioTickerTable({
240
242
  exportName?: string;
241
243
  /** The book's CASH and TOTAL rows under its holdings (`allocationSummaryRows`). */
242
244
  allocationRows?: readonly TickerTableSummaryRow[];
245
+ /** Header drags rewrite the pane's Columns setting (`DataTableProps.columnReorder`). */
246
+ columnReorder?: DataTableColumnReorder;
243
247
  }) {
244
248
  const cellCacheRef = useRef(createRowValueCache<string, ReturnType<typeof getColumnValue> & TickerTableCell>(5000));
245
249
  const openPerpetualRef = useRef(onOpenPerpetual);
@@ -389,6 +393,7 @@ export function PortfolioTickerTable({
389
393
  summaryRows={summaryRows}
390
394
  rootHeight={rootHeight}
391
395
  exportName={exportName}
396
+ columnReorder={columnReorder}
392
397
  />
393
398
  );
394
399
  }
@@ -194,6 +194,8 @@ export function RatePathPane({ width, height, focused }: PaneProps) {
194
194
  rootBefore={header(meetingColumns, meetings.length, pathChart)} />
195
195
  : tab === "probabilities" ? <DataTableView
196
196
  columns={probabilityColumns}
197
+ // Target ranges in rate order.
198
+ columnReorder={false}
197
199
  items={data.meetings} selection={selection} focused={focused} sortColumnId={null} sortDirection="asc"
198
200
  getItemKey={meetingKey} rootWidth={width} rootHeight={bodyHeight} emptyStateTitle="Meeting probabilities unavailable"
199
201
  rootBefore={header(probabilityColumns, data.meetings.length)}
@@ -214,6 +214,8 @@ function RevenueBreakdownView({ width, height, focused }: { width: number; heigh
214
214
  {payload ? (
215
215
  <DataTableView<Item>
216
216
  columns={columns}
217
+ // Reporting quarters in time order, then the latest and TTM.
218
+ columnReorder={false}
217
219
  items={items}
218
220
  focused={focused}
219
221
  rootWidth={width}
@@ -145,7 +145,8 @@ export function ReverseDcfPane({ width, height, focused }: PaneProps) {
145
145
  <Box paddingX={1}><Notice variant="callout" tone="muted">{missingInputsText(model.missing)}</Notice></Box>
146
146
  </> : model && !model.error ? <>
147
147
  <StatGrid items={stats} width={width} maxLines={statMaxLines} />
148
- <DataTableView<Row> focused={focused} columns={COLUMNS} items={model.sensitivity} rootWidth={width} rootHeight={contentHeight}
148
+ {/* Terminal growth rates in order: a sensitivity grid's axis. */}
149
+ <DataTableView<Row> focused={focused} columns={COLUMNS} columnReorder={false} items={model.sensitivity} rootWidth={width} rootHeight={contentHeight}
149
150
  getItemKey={(row) => String(row.discountRate)} emptyStateTitle="No implied growth." sortColumnId={null} sortDirection="desc"
150
151
  selection={{ kind: "id", selectedId, getId: (row) => String(row.discountRate),
151
152
  onChange: (id) => { if (id) setDiscount(String(Math.round(Number(id) * 100))); } }}
@@ -220,7 +220,8 @@ export function SeasonalityPane({ width, height, focused }: PaneProps) {
220
220
  formatCursor: (ratio) => new Date(Date.UTC(OVERLAY_YEAR, 0, 1) + ratio * 365 * 86_400_000).toISOString().slice(5, 10) }}
221
221
  colors={{ background: palette.bgColor, grid: palette.gridColor, crosshair: palette.crosshairColor, text: colors.text,
222
222
  textDim: palette.axisColor, negative: colors.negative }} />
223
- : <DataTableView<Row> focused={focused} columns={COLUMNS} items={rows} rootWidth={width} rootHeight={contentHeight}
223
+ // January to December: the grid is a calendar.
224
+ : <DataTableView<Row> focused={focused} columns={COLUMNS} columnReorder={false} items={rows} rootWidth={width} rootHeight={contentHeight}
224
225
  getItemKey={(row) => row.id} emptyStateTitle="No monthly returns." sortColumnId={null} sortDirection="desc"
225
226
  selection={{ kind: "id", selectedId: selectedRow, getId: (row) => row.id, onChange: (id) => setSelectedRow(id) }}
226
227
  getExportMetadata={() => [["symbol", model.symbol], ["as of", model.asOf?.toISOString()], ["units", "percent, local-price close to close"]]}
@@ -313,6 +313,8 @@ function ThirteenFBrowserPane({ focused, width, height, onDetailChange }: PanePr
313
313
  onBodyScrollActivity={loadMoreFromScroll}
314
314
  resetScrollKey={`${browserMode}:${query}`}
315
315
  columns={columns}
316
+ // Performance adds the quarters' returns in time order after the fund's columns.
317
+ columnReorder={browserMode === "performance" ? false : undefined}
316
318
  items={sortedRows}
317
319
  sortColumnId={browserSort.columnId}
318
320
  sortDirection={browserSort.direction}
@@ -5,6 +5,7 @@ import { areNearbyFinancialPeriodEnds, fillDate, fillDateText, statementPeriodMo
5
5
  import { formatPerShareNumber } from "../../../../utils/reported-money";
6
6
  import { hasNonIncomeStatementGap } from "../../../../utils/statement-gaps";
7
7
  import {
8
+ displayWidth,
8
9
  formatGrowthShort,
9
10
  formatNumber,
10
11
  formatWithDivisor,
@@ -32,7 +33,7 @@ export function hasStatementFinancials(financials: TickerFinancials | null | und
32
33
  type FinancialMetricFormat = "compact" | "eps" | "percent";
33
34
  export type FinancialGrowthDirection = "higher" | "lower" | "neutral";
34
35
 
35
- export type MetricDef = {
36
+ type MetricDef = {
36
37
  label: string;
37
38
  key?: keyof FinancialStatement;
38
39
  id?: string;
@@ -92,7 +93,7 @@ export type FinancialTableRow =
92
93
  toggleable: boolean;
93
94
  };
94
95
 
95
- export function statementMetricValue(
96
+ function statementMetricValue(
96
97
  def: Pick<MetricDef, "key" | "compute">,
97
98
  statement: FinancialStatement,
98
99
  ): number | undefined {
@@ -100,6 +101,12 @@ export function statementMetricValue(
100
101
  return typeof value === "number" && Number.isFinite(value) ? value : undefined;
101
102
  }
102
103
 
104
+ /** The figure a row shows for a period: a group's summary line, or the row's own. */
105
+ export function financialCellValue(row: FinancialTableRow, statement: FinancialStatement): number | undefined {
106
+ if (row.kind === "group") return row.summaryKey ? statement[row.summaryKey] as number | undefined : undefined;
107
+ return statementMetricValue(row, statement);
108
+ }
109
+
103
110
  export const FINANCIAL_COL_W = 18;
104
111
  export const FINANCIAL_LABEL_W = 28;
105
112
  const FINANCIAL_LABEL_MIN_W = 12;
@@ -114,8 +121,22 @@ const FINANCIAL_LABEL_MIN_W = 12;
114
121
  export function financialLabelWidth(width: number): number {
115
122
  return Math.max(FINANCIAL_LABEL_MIN_W, Math.min(FINANCIAL_LABEL_W, width - FINANCIAL_COL_W - 6));
116
123
  }
124
+ /** The growth after a period's value: a blank and up to six characters (`+466%`, `<-99T%`). */
117
125
  const FINANCIAL_GROWTH_W = 7;
118
- const FINANCIAL_VALUE_W = FINANCIAL_COL_W - FINANCIAL_GROWTH_W;
126
+
127
+ /**
128
+ * A terminal period column as wide as the widest value it shows and the growth
129
+ * after it, or its header where that is wider. A fixed 18 left a short value
130
+ * further from its own column's edge than from its growth, so each pair read
131
+ * tight and the next period far off, and fewer periods fit.
132
+ */
133
+ export function financialPeriodWidth(values: Iterable<string>, headers: Iterable<string>): number {
134
+ let value = 0;
135
+ for (const text of values) value = Math.max(value, displayWidth(text));
136
+ let header = 0;
137
+ for (const text of headers) header = Math.max(header, displayWidth(text));
138
+ return Math.max(value + FINANCIAL_GROWTH_W, header);
139
+ }
119
140
 
120
141
  export function computeGrowth(current: number | undefined, previous: number | undefined): number | undefined {
121
142
  if (current == null || previous == null || !Number.isFinite(current) || !Number.isFinite(previous) || previous === 0) return undefined;
@@ -182,10 +203,11 @@ export function semanticGrowthValue(
182
203
  return growth;
183
204
  }
184
205
 
185
- export function formatFinancialCell(value: string, growth: number | undefined) {
206
+ /** A period's value and its growth laid out in a column `width` cells wide, the growth against its right edge. */
207
+ export function formatFinancialCell(value: string, growth: number | undefined, width = FINANCIAL_COL_W) {
186
208
  const growthText = growth != null && Number.isFinite(growth) ? formatFinancialGrowth(growth) : "";
187
209
  return {
188
- valueText: padTo(value, FINANCIAL_VALUE_W, "right"),
210
+ valueText: padTo(value, Math.max(0, width - FINANCIAL_GROWTH_W), "right"),
189
211
  growthText: padTo(growthText ? ` ${growthText}` : "", FINANCIAL_GROWTH_W, "right"),
190
212
  };
191
213
  }
@@ -461,7 +483,7 @@ export function shareFinancialUnit<T extends { unitLabel: string; label: string;
461
483
  export function buildFinancialRows(
462
484
  defs: FinancialRowDef[],
463
485
  statements: FinancialStatement[],
464
- collapsedGroups: Set<string>,
486
+ collapsedGroups: ReadonlySet<string>,
465
487
  depth = 0,
466
488
  ): FinancialTableRow[] {
467
489
  const rows: FinancialTableRow[] = [];
@@ -9,7 +9,7 @@ import {
9
9
  import { useAssetData } from "../../../runtime";
10
10
  import { colors, priceColor } from "../../../../theme/colors";
11
11
  import type { PricePoint } from "../../../../types/financials";
12
- import { padTo } from "../../../../utils/format";
12
+ import { displayWidth, padTo } from "../../../../utils/format";
13
13
  import { useBoundTicker, useTickerRequest } from "../../shared/ticker-request";
14
14
  import type { FinancialTableStatement } from "./aggregation";
15
15
  import { FINANCIAL_COL_W, financialLabelWidth } from "./model";
@@ -29,6 +29,28 @@ export type RatioTableColumn = DataTableColumn & (
29
29
 
30
30
  const ratioRowKey = (row: RatioTableRow) => row.id;
31
31
 
32
+ /**
33
+ * A ratio's name in the metric column, after its disclosure, a cell apart: as wide as it says
34
+ * (`contentWidth`), so the table fits the column to it whole. The desktop draws the disclosure as a
35
+ * path, not a glyph.
36
+ */
37
+ export function ratioNameCell(
38
+ row: Extract<RatioTableRow, { kind: "ratio" }>,
39
+ color: string,
40
+ ): Pick<DataTableCell, "text" | "contentWidth" | "content"> {
41
+ const text = `${row.expanded ? "▾" : "▸"} ${row.label}`;
42
+ return {
43
+ text,
44
+ contentWidth: displayWidth(text),
45
+ content: (
46
+ <Box flexDirection="row" alignItems="center" gap={1}>
47
+ <DisclosureMarker expanded={row.expanded} color={color} />
48
+ <Text fg={color}>{row.label}</Text>
49
+ </Box>
50
+ ),
51
+ };
52
+ }
53
+
32
54
  export interface PeriodEndHistoryState {
33
55
  data: PricePoint[] | undefined;
34
56
  loading: boolean;
@@ -102,15 +124,8 @@ export function RatioTable({
102
124
  return { text: ` ${row.unitLabel}`, color: colors.textDim };
103
125
  }
104
126
  return {
105
- text: `${row.expanded ? "▾" : "▸"} ${row.label}`,
127
+ ...ratioNameCell(row, colors.text),
106
128
  color: colors.text,
107
- // The desktop draws the disclosure as a path, not a glyph.
108
- content: (
109
- <Box flexDirection="row" alignItems="center" gap={1}>
110
- <DisclosureMarker expanded={row.expanded} color={colors.text} />
111
- <Text fg={colors.text}>{row.label}</Text>
112
- </Box>
113
- ),
114
129
  onMouseDown: (event) => {
115
130
  event.preventDefault?.();
116
131
  event.stopPropagation?.();
@@ -146,6 +161,8 @@ export function RatioTable({
146
161
  headerScrollId={headerScrollId}
147
162
  bodyScrollId={bodyScrollId}
148
163
  columns={columns}
164
+ // The statements' fiscal periods: an axis, not columns to arrange.
165
+ columnReorder={false}
149
166
  items={rows}
150
167
  selection={{
151
168
  kind: "id",