@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.
Files changed (212) hide show
  1. package/package.json +1 -1
  2. package/patches/@opentui%2Fcore@0.3.2.patch +16 -0
  3. package/src/api-client/auth.ts +6 -0
  4. package/src/api-client/data.ts +1 -0
  5. package/src/api-client/earnings.ts +15 -0
  6. package/src/api-client/index.ts +14 -3
  7. package/src/api-client/socket-connection.ts +355 -0
  8. package/src/api-client/socket-features.ts +75 -0
  9. package/src/api-client/socket-frames.ts +161 -0
  10. package/src/api-client/socket-listeners.ts +207 -0
  11. package/src/api-client/socket-quotes.ts +332 -0
  12. package/src/api-client/socket.ts +150 -983
  13. package/src/api-client/types/account.ts +10 -0
  14. package/src/api-client/types/billing.ts +10 -0
  15. package/src/api-client/types/econ.ts +19 -7
  16. package/src/api-client/types/market.ts +7 -0
  17. package/src/api-client/types/screener.ts +2 -0
  18. package/src/brokers/signed-in/adapter.ts +19 -5
  19. package/src/brokers/signed-in/client.ts +13 -1
  20. package/src/brokers/signed-in/sign-in-dialog.tsx +33 -9
  21. package/src/cli/commands/market.ts +18 -8
  22. package/src/cli/commands/overview.ts +26 -7
  23. package/src/cli/commands/ticker.ts +40 -15
  24. package/src/cli/desktop-pane-shot.ts +39 -0
  25. package/src/cli/errors.ts +20 -3
  26. package/src/cli/fx-pair.ts +11 -2
  27. package/src/cli/history-rows.ts +34 -3
  28. package/src/cli/index.ts +1 -1
  29. package/src/cli/listing-arg.ts +51 -13
  30. package/src/cli/pane-functions/headless.ts +4 -2
  31. package/src/cli/pane-functions/index.ts +1 -0
  32. package/src/cli/pane-functions/resolver.ts +2 -1
  33. package/src/cli/pane-functions/screenshot-assessment.ts +73 -5
  34. package/src/cli/pane-functions/screenshot-types.ts +4 -0
  35. package/src/components/chart/composite/chart-layout.ts +7 -4
  36. package/src/components/chart/composite/composite-chart.tsx +6 -16
  37. package/src/components/chart/composite/toolbar.tsx +258 -82
  38. package/src/components/chart/composite/use-composite-chart-keyboard.ts +5 -6
  39. package/src/components/chart/native/kitty/manager.ts +2 -0
  40. package/src/components/chart/native/surface/manager.ts +211 -11
  41. package/src/components/command-bar/list/model.ts +13 -0
  42. package/src/components/command-bar/panel/index.tsx +2 -13
  43. package/src/components/command-bar/panel/layout.ts +1 -7
  44. package/src/components/command-bar/panel/runtime.ts +0 -1
  45. package/src/components/command-bar/panel/types.ts +0 -2
  46. package/src/components/command-bar/routes/ticker-search/actions.ts +2 -0
  47. package/src/components/command-bar/routes/ticker-search/results.ts +15 -8
  48. package/src/components/command-bar/surface/index.tsx +10 -5
  49. package/src/components/command-bar/workflow/alert.ts +21 -7
  50. package/src/components/data-table/column-menu.tsx +89 -0
  51. package/src/components/data-table/sort-menu.tsx +9 -2
  52. package/src/components/data-table/table-pane.ts +3 -1
  53. package/src/components/data-table/view.tsx +33 -6
  54. package/src/components/form-modal/content.tsx +10 -0
  55. package/src/components/index.ts +1 -1
  56. package/src/components/layout/pane/footer/index.tsx +25 -11
  57. package/src/components/layout/pane/footer/model.ts +88 -21
  58. package/src/components/layout/pane/sidebar.tsx +125 -15
  59. package/src/components/layout/shell/active-drag.ts +18 -13
  60. package/src/components/layout/shell/drag/magnets.ts +34 -18
  61. package/src/components/metric-treemap/heat-surface.tsx +2 -1
  62. package/src/components/metric-treemap/index.tsx +3 -2
  63. package/src/components/ticker/list-table-view.tsx +5 -0
  64. package/src/components/ui/confirm-dialog.tsx +253 -7
  65. package/src/components/ui/data-table/column-order.ts +180 -0
  66. package/src/components/ui/data-table/index.tsx +13 -2
  67. package/src/components/ui/data-table/opentui/index.tsx +267 -23
  68. package/src/components/ui/data-table/opentui/model.ts +43 -4
  69. package/src/components/ui/data-table/types.ts +56 -0
  70. package/src/components/ui/data-table/use-column-order.ts +135 -0
  71. package/src/components/ui/index.ts +1 -1
  72. package/src/components/ui/list-view.tsx +4 -3
  73. package/src/components/ui/status.tsx +9 -6
  74. package/src/components/ui/table-layout.ts +120 -0
  75. package/src/docs/snapshot.json +39 -2
  76. package/src/i18n/es.ts +14 -0
  77. package/src/i18n/ja.ts +14 -0
  78. package/src/i18n/ko.ts +14 -0
  79. package/src/i18n/zh-cn.ts +14 -0
  80. package/src/i18n/zh-tw.ts +14 -0
  81. package/src/market-data/coordinator/index.ts +4 -3
  82. package/src/market-data/coordinator/quotes.ts +12 -4
  83. package/src/market-data/fx-closes.ts +14 -2
  84. package/src/market-data/market/change-basis.ts +35 -1
  85. package/src/market-data/market/status.ts +37 -0
  86. package/src/market-data/performance.ts +4 -1
  87. package/src/market-data/quotes/freshness.ts +12 -0
  88. package/src/market-data/quotes/live-valuation.ts +26 -3
  89. package/src/market-data/quotes/regular-session-valuation.ts +1 -1
  90. package/src/market-data/realized-volatility.ts +3 -0
  91. package/src/market-data/us-bond-market.ts +115 -0
  92. package/src/plugins/builtin/account-management/invite-row.tsx +54 -0
  93. package/src/plugins/builtin/account-management/keyboard.ts +3 -0
  94. package/src/plugins/builtin/account-management/model.ts +1 -0
  95. package/src/plugins/builtin/account-management/pane.tsx +51 -5
  96. package/src/plugins/builtin/account-management/trial-cancel.ts +32 -7
  97. package/src/plugins/builtin/broker-manager/detail.tsx +5 -3
  98. package/src/plugins/builtin/broker-manager/index.tsx +6 -6
  99. package/src/plugins/builtin/broker-manager/model.ts +15 -6
  100. package/src/plugins/builtin/broker-manager/pane-actions.tsx +11 -4
  101. package/src/plugins/builtin/broker-manager/sign-in-end.ts +50 -19
  102. package/src/plugins/builtin/broker-manager/table.ts +10 -4
  103. package/src/plugins/builtin/chat/sidebar.tsx +33 -16
  104. package/src/plugins/builtin/cloud/askg/pane-session.ts +94 -0
  105. package/src/plugins/builtin/cloud/askg/pane.tsx +40 -83
  106. package/src/plugins/builtin/cloud/askg/tool-timeline.tsx +2 -0
  107. package/src/plugins/builtin/congress-trades/pane.tsx +8 -2
  108. package/src/plugins/builtin/correlation/compute.ts +4 -3
  109. package/src/plugins/builtin/earnings/board-model.ts +33 -0
  110. package/src/plugins/builtin/earnings/board-table.ts +50 -11
  111. package/src/plugins/builtin/earnings/board.tsx +29 -13
  112. package/src/plugins/builtin/earnings/calendar.tsx +15 -3
  113. package/src/plugins/builtin/earnings/client.ts +4 -1
  114. package/src/plugins/builtin/earnings/headless.ts +27 -14
  115. package/src/plugins/builtin/econ/calendar-source.ts +3 -0
  116. package/src/plugins/builtin/equity-screener/live.ts +74 -18
  117. package/src/plugins/builtin/equity-screener/model.ts +19 -4
  118. package/src/plugins/builtin/equity-screener/pane.tsx +19 -14
  119. package/src/plugins/builtin/equity-screener/refresh-anchor.ts +45 -0
  120. package/src/plugins/builtin/equity-screener/results.ts +22 -2
  121. package/src/plugins/builtin/equity-screener/screen-check.ts +9 -3
  122. package/src/plugins/builtin/futures/index.tsx +15 -1
  123. package/src/plugins/builtin/futures/table.tsx +1 -1
  124. package/src/plugins/builtin/fx-matrix/index.tsx +2 -0
  125. package/src/plugins/builtin/help/index.tsx +1 -1
  126. package/src/plugins/builtin/holders/pane.tsx +30 -20
  127. package/src/plugins/builtin/ipo-calendar/model.ts +3 -3
  128. package/src/plugins/builtin/iv-history/events.ts +5 -0
  129. package/src/plugins/builtin/iv-history/headless.ts +19 -12
  130. package/src/plugins/builtin/kelly-sizer/sections.tsx +2 -0
  131. package/src/plugins/builtin/macro-day/headless.ts +27 -8
  132. package/src/plugins/builtin/macro-day/model.ts +17 -4
  133. package/src/plugins/builtin/macro-day/releases.ts +36 -15
  134. package/src/plugins/builtin/market-halts/model.ts +3 -2
  135. package/src/plugins/builtin/market-movers/headless.ts +2 -1
  136. package/src/plugins/builtin/market-movers/index.tsx +3 -2
  137. package/src/plugins/builtin/market-movers/model.ts +75 -22
  138. package/src/plugins/builtin/market-movers/screener.ts +2 -1
  139. package/src/plugins/builtin/market-movers/table.ts +7 -5
  140. package/src/plugins/builtin/options/view.tsx +2 -0
  141. package/src/plugins/builtin/options-scenario/pane.tsx +2 -1
  142. package/src/plugins/builtin/pe-band/model.ts +4 -0
  143. package/src/plugins/builtin/perps/cascade-tabs.tsx +2 -1
  144. package/src/plugins/builtin/portfolio-list/cell-version.ts +4 -4
  145. package/src/plugins/builtin/portfolio-list/cli/render.ts +9 -4
  146. package/src/plugins/builtin/portfolio-list/pane/index.tsx +15 -1
  147. package/src/plugins/builtin/portfolio-list/summary/index.tsx +24 -7
  148. package/src/plugins/builtin/portfolio-list/summary/totals.ts +40 -11
  149. package/src/plugins/builtin/portfolio-list/table.tsx +18 -1
  150. package/src/plugins/builtin/rate-path/pane.tsx +2 -0
  151. package/src/plugins/builtin/research/analyst-headless.ts +9 -1
  152. package/src/plugins/builtin/research/analyst-pane.tsx +10 -4
  153. package/src/plugins/builtin/research/client.ts +25 -1
  154. package/src/plugins/builtin/research/corporate-actions-pane.tsx +2 -1
  155. package/src/plugins/builtin/research/event-model.ts +3 -13
  156. package/src/plugins/builtin/research/event-sources.ts +3 -1
  157. package/src/plugins/builtin/revenue-breakdown/pane.tsx +2 -0
  158. package/src/plugins/builtin/reverse-dcf/pane.tsx +2 -1
  159. package/src/plugins/builtin/seasonality/pane.tsx +2 -1
  160. package/src/plugins/builtin/short-interest/headless.ts +2 -0
  161. package/src/plugins/builtin/short-interest/publications-headless.ts +2 -0
  162. package/src/plugins/builtin/short-interest/watch-headless.ts +1 -0
  163. package/src/plugins/builtin/thirteenf/pane.tsx +2 -0
  164. package/src/plugins/builtin/ticker-detail/financials/model.ts +28 -6
  165. package/src/plugins/builtin/ticker-detail/financials/ratio-table.tsx +26 -9
  166. package/src/plugins/builtin/ticker-detail/financials/tab.tsx +58 -35
  167. package/src/plugins/builtin/vol-surface/heat-grid.tsx +2 -1
  168. package/src/plugins/builtin/vol-surface/pane.tsx +2 -1
  169. package/src/plugins/builtin/world-indices/index.tsx +5 -1
  170. package/src/plugins/builtin/yield-curve/headless.ts +5 -1
  171. package/src/plugins/builtin/yield-curve/index.tsx +7 -1
  172. package/src/portfolio/column-values.ts +47 -14
  173. package/src/portfolio/return-metrics.ts +4 -2
  174. package/src/renderers/dom/data-table/column-drag.ts +147 -0
  175. package/src/renderers/dom/data-table/index.tsx +22 -0
  176. package/src/renderers/dom/data-table/row.tsx +27 -5
  177. package/src/renderers/dom/host/image-surface.tsx +19 -9
  178. package/src/renderers/dom/host/input.tsx +4 -0
  179. package/src/renderers/dom/styles.css +22 -0
  180. package/src/renderers/electrobun/view/cli-pane-shot-entry.tsx +23 -1
  181. package/src/renderers/opentui/chart-surface.tsx +1 -0
  182. package/src/renderers/opentui/frame-hits.ts +33 -0
  183. package/src/renderers/opentui/host.tsx +2 -0
  184. package/src/renderers/opentui/native-surface.ts +14 -21
  185. package/src/renderers/opentui/test-utils.tsx +3 -0
  186. package/src/sources/gloomberb-cloud/normalizers.ts +2 -0
  187. package/src/sources/provider-errors.ts +12 -0
  188. package/src/sources/provider-router/index.ts +12 -4
  189. package/src/state/app/context/index.tsx +22 -0
  190. package/src/state/pane-session.ts +145 -0
  191. package/src/test-support/app-store.ts +24 -1
  192. package/src/tickers/search/home-listing.ts +44 -1
  193. package/src/tickers/search/index.ts +5 -2
  194. package/src/tickers/search/ranking.ts +7 -7
  195. package/src/tickers/us-listing.ts +11 -5
  196. package/src/time-series/base-series.ts +7 -1
  197. package/src/time-series/fundamentals/current-valuation.ts +8 -0
  198. package/src/time-series/fundamentals/series.ts +6 -0
  199. package/src/time-series/live-quotes.ts +3 -9
  200. package/src/time-series/resolve.ts +1 -0
  201. package/src/types/financials.ts +20 -0
  202. package/src/types/headless.ts +9 -0
  203. package/src/ui/host.tsx +20 -0
  204. package/src/ui/pointer-drag.ts +11 -2
  205. package/src/utils/exchanges.ts +13 -8
  206. package/src/utils/fundamentals.ts +14 -3
  207. package/src/utils/price-earnings.ts +17 -10
  208. package/src/utils/price-history-integrity.ts +15 -0
  209. package/src/utils/reason-codes.ts +79 -0
  210. package/src/utils/share-multiples.cases.json +1667 -0
  211. package/src/utils/share-multiples.ts +384 -0
  212. package/src/utils/untrusted-text.ts +11 -0
@@ -15,17 +15,19 @@ import {
15
15
  } from "../../../../components";
16
16
  import { colors, priceColor } from "../../../../theme/colors";
17
17
  import { fiscalYearEndMonth } from "../../../../utils/fiscal-period";
18
- import { padTo } from "../../../../utils/format";
18
+ import { displayWidth, padTo } from "../../../../utils/format";
19
19
  import { filledPeriodPublications, filledPeriodsNote, stalePeriodNote } from "../../../../utils/financial-statements";
20
20
  import {
21
21
  FINANCIAL_COL_W,
22
22
  financialLabelWidth,
23
+ financialPeriodWidth,
23
24
  FINANCIAL_SUB_TABS,
24
25
  buildFinancialRows,
25
26
  canCompareFinancialRow,
26
27
  collectDefaultCollapsedGroupIds,
27
28
  collectGroupIds,
28
29
  computeGrowth,
30
+ financialCellValue,
29
31
  financialColumnLabel,
30
32
  formatFinancialCell,
31
33
  financialStatementCurrency,
@@ -41,7 +43,6 @@ import {
41
43
  selectFinancialStatements,
42
44
  shareFinancialUnit,
43
45
  splitPeriodsNotInYet,
44
- statementMetricValue,
45
46
  type FinancialPeriod,
46
47
  type FinancialTableRow,
47
48
  } from "./model";
@@ -72,6 +73,32 @@ type FinancialTableColumn = DataTableColumn & (
72
73
  | { id: string; kind: "statement"; statement: FinancialTableStatement }
73
74
  );
74
75
 
76
+ const NO_COLLAPSED_GROUPS: ReadonlySet<string> = new Set();
77
+
78
+ /**
79
+ * A group's name in the metric column. It draws its indent (an empty one still takes a cell), its disclosure
80
+ * and its name a cell apart, and says that width (`contentWidth`) so the table fits the column to it whole.
81
+ * The desktop draws the disclosure as a path, not a glyph.
82
+ */
83
+ export function financialGroupNameCell(
84
+ row: Extract<FinancialTableRow, { kind: "group" }>,
85
+ color: string,
86
+ attributes: number,
87
+ ): Pick<DataTableCell, "text" | "contentWidth" | "content"> {
88
+ const indent = " ".repeat(row.depth * 2);
89
+ const marker = row.toggleable ? (row.expanded ? "\u25be" : "\u25b8") : " ";
90
+ return {
91
+ text: `${indent}${marker} ${row.unitLabel}`,
92
+ contentWidth: Math.max(1, displayWidth(indent)) + 1 + displayWidth(marker) + 1 + displayWidth(row.unitLabel),
93
+ content: (
94
+ <Box flexDirection="row" alignItems="center" gap={1}>
95
+ <Text fg={color}>{indent}</Text>
96
+ {row.toggleable ? <DisclosureMarker expanded={!!row.expanded} color={color} /> : <Text> </Text>}
97
+ <Text fg={color} attributes={attributes}>{row.unitLabel}</Text>
98
+ </Box>
99
+ ),
100
+ };
101
+ }
75
102
  const financialRowKey = (row: FinancialTableRow) => row.id;
76
103
  const financialRowBackground = (row: FinancialTableRow) => (
77
104
  row.kind === "group" && row.depth === 0 ? colors.panel : undefined
@@ -318,6 +345,24 @@ export function ResolvedFinancialsTab({
318
345
  const moneyUnit = [comparisonCurrency, unit].filter(Boolean).join(" ");
319
346
  const unitMarked = !!unit && rows.some((row) => row.unitLabel !== row.label);
320
347
  const metricHeader = moneyUnit ? `${moneyUnit}${unitMarked ? " unless marked" : ""}` : "Metric";
348
+ // The annual balance sheet leads with a newer quarter-end position.
349
+ const periodHeaders = useMemo(() => displayStatements.map((statement) => financialColumnHeader(
350
+ statement,
351
+ isAnnual && (statement.date === "TTM" || annualDates.has(statement.date)) ? "annual" : "quarterly",
352
+ yearEndMonth,
353
+ comparisonCurrency,
354
+ )), [annualDates, comparisonCurrency, displayStatements, isAnnual, yearEndMonth]);
355
+ // In the terminal a period is as wide as its widest value and growth, so each pair sits as far from the next
356
+ // as from its own growth and more periods fit. The ratio tabs keep the statement columns' width. Every line of
357
+ // the statement counts, a collapsed group's too, so opening or closing one leaves the periods where they are.
358
+ const periodWidth = useMemo(() => {
359
+ if (nativePaneChrome || ratioTab) return FINANCIAL_COL_W;
360
+ const everyRow = shareFinancialUnit(buildFinancialRows(subTab.rows, displayStatements, NO_COLLAPSED_GROUPS)).rows;
361
+ const values = [...everyRow, ...rows].flatMap((row) => displayStatements.map((statement) => (
362
+ formatFinancialValue(financialCellValue(row, statement), row, statement)
363
+ )));
364
+ return financialPeriodWidth(values, periodHeaders);
365
+ }, [displayStatements, nativePaneChrome, periodHeaders, ratioTab, rows, subTab.rows]);
321
366
  const columns = useMemo<FinancialTableColumn[]>(() => [
322
367
  {
323
368
  id: "metric",
@@ -330,18 +375,12 @@ export function ResolvedFinancialsTab({
330
375
  id: `statement:${statement.date}:${index}`,
331
376
  kind: "statement",
332
377
  statement,
333
- // The annual balance sheet leads with a newer quarter-end position.
334
- label: padTo(financialColumnHeader(
335
- statement,
336
- isAnnual && (statement.date === "TTM" || annualDates.has(statement.date)) ? "annual" : "quarterly",
337
- yearEndMonth,
338
- comparisonCurrency,
339
- ), FINANCIAL_COL_W, "center"),
340
- width: FINANCIAL_COL_W,
378
+ label: padTo(periodHeaders[index]!, periodWidth, "center"),
379
+ width: periodWidth,
341
380
  align: "right",
342
381
  headerColor: statement.date === "TTM" ? colors.textBright : colors.textDim,
343
382
  })),
344
- ], [annualDates, comparisonCurrency, displayStatements, isAnnual, metricHeader, width, yearEndMonth]);
383
+ ], [displayStatements, metricHeader, periodHeaders, periodWidth, width]);
345
384
  const periodEnd = latestFinancialPeriodEnd(displayStatements);
346
385
  const renderCell = useCallback((
347
386
  row: FinancialTableRow,
@@ -349,22 +388,12 @@ export function ResolvedFinancialsTab({
349
388
  ): DataTableCell => {
350
389
  if (column.kind === "metric") {
351
390
  if (row.kind === "group") {
352
- const indent = " ".repeat(row.depth * 2);
353
- const marker = row.toggleable ? (row.expanded ? "\u25be" : "\u25b8") : " ";
354
391
  const labelColor = row.depth === 0 ? colors.textBright : colors.textDim;
355
392
  const labelAttributes = row.depth === 0 ? TextAttributes.BOLD : TextAttributes.NONE;
356
393
  return {
357
- text: `${indent}${marker} ${row.unitLabel}`,
394
+ ...financialGroupNameCell(row, labelColor, labelAttributes),
358
395
  color: labelColor,
359
396
  attributes: labelAttributes,
360
- // The desktop draws the disclosure as a path, not a glyph.
361
- content: (
362
- <Box flexDirection="row" alignItems="center" gap={1}>
363
- <Text fg={labelColor}>{indent}</Text>
364
- {row.toggleable ? <DisclosureMarker expanded={!!row.expanded} color={labelColor} /> : <Text> </Text>}
365
- <Text fg={labelColor} attributes={labelAttributes}>{row.unitLabel}</Text>
366
- </Box>
367
- ),
368
397
  onMouseDown: row.toggleable
369
398
  ? (event) => {
370
399
  event.preventDefault?.();
@@ -381,31 +410,24 @@ export function ResolvedFinancialsTab({
381
410
  };
382
411
  }
383
412
 
384
- const key = row.kind === "group" ? row.summaryKey : undefined;
385
- if (row.kind === "group" && !key) return {
413
+ if (row.kind === "group" && !row.summaryKey) return {
386
414
  text: "",
387
415
  };
388
416
 
389
417
  const previous = previousStatementMap.get(column.statement.date);
390
- const value = row.kind === "group"
391
- ? column.statement[key!] as number | undefined
392
- : statementMetricValue(row, column.statement);
393
- const previousValue = previous
394
- ? row.kind === "group"
395
- ? previous[key!] as number | undefined
396
- : statementMetricValue(row, previous)
397
- : undefined;
418
+ const value = financialCellValue(row, column.statement);
419
+ const previousValue = previous ? financialCellValue(row, previous) : undefined;
398
420
  const growth = (row.kind === "metric" && !row.showGrowth)
399
421
  || !canCompareFinancialRow(row, column.statement, previous, comparisonCurrency)
400
422
  ? undefined : computeGrowth(value, previousValue);
401
423
  const formattedValue = formatFinancialValue(value, row, column.statement);
402
- const cell = formatFinancialCell(formattedValue, growth);
424
+ const cell = formatFinancialCell(formattedValue, growth, column.width);
403
425
  const growthColorValue = semanticGrowthValue(growth, row.growthDirection);
404
426
 
405
427
  return {
406
428
  text: `${cell.valueText}${cell.growthText}`,
407
429
  content: (
408
- <Box flexDirection="row" width={FINANCIAL_COL_W}>
430
+ <Box flexDirection="row" width={column.width}>
409
431
  <Text
410
432
  attributes={row.kind === "group" ? TextAttributes.BOLD : TextAttributes.NONE}
411
433
  fg={colors.text}
@@ -547,7 +569,6 @@ export function ResolvedFinancialsTab({
547
569
  // Desktop: the query bar and table run edge to edge like every other
548
570
  // pane; the table keeps its own inline padding.
549
571
  paddingX={nativePaneChrome ? 0 : 1}
550
- paddingBottom={nativePaneChrome ? 0 : 1}
551
572
  overflow="hidden"
552
573
  >
553
574
  {isValuation && oldestPeriodEnd ? <PeriodEndHistoryLoader oldestPeriodEnd={oldestPeriodEnd} onChange={setHistory} /> : null}
@@ -578,6 +599,8 @@ export function ResolvedFinancialsTab({
578
599
  headerScrollId={headerScrollId}
579
600
  bodyScrollId={bodyScrollId}
580
601
  columns={columns}
602
+ // Fiscal periods, oldest to newest: an axis, not columns to arrange.
603
+ columnReorder={false}
581
604
  items={rows}
582
605
  selection={{
583
606
  kind: "id",
@@ -84,7 +84,8 @@ export function SurfaceHeatGrid({ grid, range, ticks, selected, onSelect, width,
84
84
  const first = ticks[0], last = ticks.at(-1);
85
85
  return <Box flexDirection="column" width={width} height={height} data-gloom-role="surface-grid" data-gloom-surface-renderer="grid">
86
86
  {notice ? <Box paddingX={1}><Notice tone="muted">{notice}</Notice></Box> : null}
87
- <DataTableView<HeatRow> rootWidth={width} rootHeight={Math.max(2, height - 1 - noticeRows)} columns={columns} items={rows}
87
+ {/* Moneyness or delta in order across the tenors: the surface's axis. */}
88
+ <DataTableView<HeatRow> rootWidth={width} rootHeight={Math.max(2, height - 1 - noticeRows)} columns={columns} columnReorder={false} items={rows}
88
89
  getItemKey={(row) => String(row.index)}
89
90
  selection={{ kind: "id", selectedId: selected ? String(selected.tenorIndex) : null, getId: (row) => String(row.index),
90
91
  onChange: (_id, row) => onSelect({ tenorIndex: row.index, moneynessIndex: selected?.moneynessIndex ?? 0 }) }}
@@ -500,7 +500,8 @@ export function VolSurfacePane({ focused, width, height }: PaneProps) {
500
500
  return sort.direction === "asc" ? delta : -delta;
501
501
  });
502
502
  const table = <DataTableView<SurfaceGridRow> focused={focused} rootWidth={width} rootHeight={tableHeight}
503
- columns={columns} items={sortedRows} getItemKey={(row) => row.label} scrollRef={scrollRef} onBodyScrollActivity={onScroll}
503
+ // Moneyness or delta in order across the tenors: the surface's axis.
504
+ columns={columns} columnReorder={false} items={sortedRows} getItemKey={(row) => row.label} scrollRef={scrollRef} onBodyScrollActivity={onScroll}
504
505
  sortColumnId={sort.columnId} sortDirection={sort.direction} onHeaderClick={(id) => setSort((current) => nextHeaderSort(current, id))}
505
506
  selection={{ kind: "id", selectedId: tableSelectedRow?.label ?? null, getId: (row) => row.label, onChange: (_id, row) => onSelectRow(row) }}
506
507
  onActivate={onSelectRow} onRootKeyDown={handleKey} getExportMetadata={exportMetadata} freezeFirstColumn
@@ -1,5 +1,5 @@
1
1
  import { useCallback, useEffect, useMemo, useState } from "react";
2
- import { DataTableView, type DataTableVisibleRange } from "../../../components";
2
+ import { DataTableView, type DataTableColumnReorder, type DataTableVisibleRange } from "../../../components";
3
3
  import type { PaneProps } from "../../../types/plugin";
4
4
  import type { PluginModule } from "../plugin-module";
5
5
  import { TICKER_RESEARCH_PANE_ID } from "../../../types/config";
@@ -39,6 +39,8 @@ function renderRegionHeader(row: WorldIndexTableRow) {
39
39
  return row.type === "header" ? { text: REGION_LABELS[row.region] } : null;
40
40
  }
41
41
 
42
+ const WORLD_INDEX_COLUMN_REORDER: DataTableColumnReorder = { anchored: 2 };
43
+
42
44
  function WorldIndicesPane({ focused, width, height }: PaneProps) {
43
45
  const { pinTicker } = usePluginTickerActions();
44
46
  const dataProvider = useAssetData();
@@ -124,6 +126,8 @@ function WorldIndicesPane({ focused, width, height }: PaneProps) {
124
126
  rootWidth={width}
125
127
  rootHeight={height}
126
128
  columns={columns}
129
+ // The session mark and the index name the row, whether or not the mark has a heading at this width.
130
+ columnReorder={WORLD_INDEX_COLUMN_REORDER}
127
131
  items={dataProvider ? flatRows : []}
128
132
  sortable
129
133
  sortColumnId={sortPreference.columnId}
@@ -17,6 +17,7 @@ import { fetchSwapCurve, loadSavedCurve, loadSavedWorldRows } from "./client";
17
17
  import { savedCopyMark } from "../../../data/saved-copies";
18
18
  import { formatSwapBp, selectedSwapTenor } from "./swaps-model";
19
19
  import { logFailure } from "../../../utils/log-failure";
20
+ import { usBondMarketClosedNote } from "../../../market-data/us-bond-market";
20
21
 
21
22
  const percent = (value: unknown) => value == null ? "-" : `${Number(value).toFixed(2)}%`;
22
23
  /** A move already in basis points: `+3bp`, `-1bp`, `0bp`. */
@@ -237,6 +238,9 @@ export function createYieldCurveHeadless(
237
238
  : data.seriesSource ? data.seriesSource
238
239
  : data.seriesSource === null ? "FRED" : CURVE_PUBLISHERS[curve];
239
240
  const cutoff = curveCutoff(curve);
241
+ // A US curve asked for a day the bond market was shut says so, and which day it shows (Veterans Day shows the day before).
242
+ const closed = requestedDate && session && CURVE_MARKETS[curve] === "US" ? usBondMarketClosedNote(requestedDate, session) : null;
243
+ const notes = [...(ranked ? [RANK_NOTE] : []), ...(closed ? [closed] : [])];
240
244
  return {
241
245
  // A stored curve cites its publisher. FRED's fallback cites info.source, not that publisher.
242
246
  // A Treasury curve names when in the day it was taken, beside its date.
@@ -244,7 +248,7 @@ export function createYieldCurveHeadless(
244
248
  ...(cutoff ? { schedule: cutoff } : {}),
245
249
  ...(requestedDate ? { basis: "historical curve" } : { basis: "daily curve", cadence: "daily" }) },
246
250
  ...(comparePoints ? { columns: compareColumns(compareAsOf) } : ranked ? { columns: RANKED_COLUMNS } : {}),
247
- ...(ranked ? { notes: [RANK_NOTE] } : {}),
251
+ ...(notes.length ? { notes } : {}),
248
252
  // The spreads the pane shows over its table, each with its day move and where it sits in the last year.
249
253
  ...(spreads.length ? { textSections: [{ title: "Spreads", entries: spreads.map((figure) => {
250
254
  const text = curveSpreadText(figure);
@@ -40,6 +40,7 @@ import { SwapsTab } from "./swaps";
40
40
  import {
41
41
  cachedCurve, cachedWorldRows, curveViewCache, loadSavedCurve, loadSavedWorldRows, swapCurveCache, worldCurvesCache,
42
42
  } from "./client";
43
+ import { usBondMarketClosedNote } from "../../../market-data/us-bond-market";
43
44
 
44
45
  type GcTab = "curve" | "world" | "swaps";
45
46
  const TABS = [{ label: "Curve", value: "curve" }, { label: "World", value: "world" }, { label: "Swaps", value: "swaps" }];
@@ -260,9 +261,13 @@ function CurveTab({ curve, onCurveChange, focused, width, height }: {
260
261
  // Both look-backs share one request per tenor, so they usually fail together.
261
262
  const lookbackFailures = [...new Set((fredLookbacks ?? []).flatMap((lookback) => lookback.points ? [] : [lookback.error]))]
262
263
  .map((message) => `${andList((fredLookbacks ?? []).filter((lookback) => lookback.error === message).map((lookback) => lookback.id))} look-back unavailable: ${message}`);
264
+ // A Treasury curve asked for a day the bond market was shut (Veterans Day) says so, and which day it shows.
265
+ const closedDay = requestedDate && asOf && (curve === "us" || curve === "us-real" || curve === "us-breakeven")
266
+ ? usBondMarketClosedNote(requestedDate, asOf) : null;
263
267
  usePaneNoticeFooter({
264
268
  registrationId: "yield-curve:notices",
265
269
  notices: [
270
+ closedDay ? `${closedDay}.` : null,
266
271
  !asOf && points.some((point) => point.yield != null) ? "The tenors carry mixed or unknown observation dates, so the curve is not one session." : null,
267
272
  missingTenors.length ? `Unavailable tenors: ${missingTenors.join(", ")}.` : null,
268
273
  points.some((point) => point.stale) ? "Some tenors are cached values because their refresh failed." : null,
@@ -466,7 +471,8 @@ function WorldTab({ onOpen, focused, width, height }: {
466
471
  <PaneStatusBody loading={loading && !data} error={!data ? error : null} loadingLabel="Loading world curves..." subject="world curves">
467
472
  <DataTableView<WorldRow>
468
473
  focused={focused} rootWidth={width} rootHeight={height}
469
- columns={WORLD_COLUMNS} items={rows} getItemKey={worldKey} renderCell={renderCell}
474
+ // Maturities in order, each beside its own change.
475
+ columns={WORLD_COLUMNS} columnReorder={false} items={rows} getItemKey={worldKey} renderCell={renderCell}
470
476
  selection={{ kind: "id", selectedId, getId: worldKey, onChange: (id) => setSelected(id) }}
471
477
  onActivate={(row) => onOpen(row.id)} sortColumnId={null} sortDirection="asc"
472
478
  emptyStateTitle="No curves yet."
@@ -25,6 +25,8 @@ import {
25
25
  type MarketFormatOptions,
26
26
  } from "../market-data/market/format";
27
27
  import {
28
+ EXTENDED_SESSION_MARKS,
29
+ extendedPrintSession,
28
30
  getActiveQuoteDisplay,
29
31
  getCompletedRegularSessionDisplay,
30
32
  getExtendedSessionDisplay,
@@ -33,6 +35,7 @@ import {
33
35
  marketStateDot,
34
36
  quoteDotMarketState,
35
37
  type ActiveQuoteDisplay,
38
+ type SessionPriceDisplay,
36
39
  } from "../market-data/market/status";
37
40
  import { formatOptionTicker } from "../utils/options";
38
41
  import { distributionHistory, forwardYieldMayHaveLapsed, lapsedDividend } from "../utils/forward-dividend";
@@ -119,7 +122,12 @@ export interface ColumnContext {
119
122
  fxDayMoves?: ReadonlyMap<string, number>;
120
123
  /** Clock for quote age (per second while shown) and day-based columns. */
121
124
  now: number;
122
- /** What market values, P&L, weights and the day's move are priced at; the latest print when absent. */
125
+ /**
126
+ * What market values, P&L, weights and the day's move are priced at, and
127
+ * LAST, CHG and CHG% show with it (rowHeadlineDisplay). Absent, as in a
128
+ * list that values nothing (a watchlist), the values are at the latest print
129
+ * and LAST is the regular session's, as `quote` heads it.
130
+ */
123
131
  valuationBasis?: PortfolioValuationBasis;
124
132
  /**
125
133
  * What a portfolio's weights divide by (allocationWeightBase): its priced
@@ -344,15 +352,15 @@ function tradedQuoteDisplay(
344
352
  }
345
353
 
346
354
  /**
347
- * LAST, CHG and CHG% once the regular session is over, and in the pre-market
348
- * while the quote carries the last session's close and move: that close and its
349
- * move, frozen, because the EXT% column carries the extended print measured
350
- * from that close. Until the close, and wherever no close is reported (a
351
- * pre-market quote without it, venues without extended hours), the traded price
352
- * as above.
353
- * Valuation columns (DAY P&L, MKT VAL, weight, P&L) keep the latest print,
354
- * unless the pane values at the regular close, which is this headline.
355
- * A watchlist's Avg Day averages this CHG%.
355
+ * The regular session's price and move, as `quote` heads Last: once the
356
+ * session is over, and in the pre-market while the quote carries the last
357
+ * session's close and move, that close and its move, frozen, because the EXT%
358
+ * column carries the extended print measured from that close. Until the close,
359
+ * and wherever no close is reported (a pre-market quote without it, venues
360
+ * without extended hours), the traded price as above. A watchlist's LAST and
361
+ * CHG% (its Avg Day averages this CHG%), and a book's valued at the regular
362
+ * close, which is this price; a book valued at the latest print shows that
363
+ * print instead (rowHeadlineDisplay).
356
364
  */
357
365
  export function headlineQuoteDisplay(
358
366
  traded: ActiveQuoteDisplay | null,
@@ -361,6 +369,26 @@ export function headlineQuoteDisplay(
361
369
  return traded ? getCompletedRegularSessionDisplay(quote) ?? traded : null;
362
370
  }
363
371
 
372
+ /**
373
+ * LAST, CHG and CHG% of a row: the price its figures use, so LAST times the
374
+ * shares is MKT VAL and CHG times them is DAY. In a book valued at the latest
375
+ * print, that print and its move from the close DAY measures from, naming its
376
+ * session when it is a pre-market, after-hours or overnight trade (`AH
377
+ * 158.78`); an option shows its trade, valued at its mark. A book at the
378
+ * regular close, and a list that values nothing (no `valuationBasis`, a
379
+ * watchlist), show the regular session as `quote` heads it
380
+ * (headlineQuoteDisplay), with the extended print in EXT%.
381
+ */
382
+ function rowHeadlineDisplay(
383
+ traded: ActiveQuoteDisplay | null,
384
+ quote: TickerFinancials["quote"],
385
+ ctx: Pick<ColumnContext, "valuationBasis">,
386
+ ): SessionPriceDisplay | null {
387
+ if (ctx.valuationBasis !== "latest-print" || !traded) return headlineQuoteDisplay(traded, quote);
388
+ const session = extendedPrintSession(quote, traded.price);
389
+ return session ? { ...traded, session } : traded;
390
+ }
391
+
364
392
  /** CHG% as shown: the headline's, else the quote's own when no position price is usable. */
365
393
  function headlineChangePercent(
366
394
  headline: ActiveQuoteDisplay | null,
@@ -546,7 +574,7 @@ export function getColumnValue(
546
574
  const liveQuote = getPortfolioQuoteDisplay(positionMetrics, quote);
547
575
  const activeQuote = getPortfolioValuationDisplay(positionMetrics, quote, ctx.valuationBasis, futures?.settlement);
548
576
  const displayQuote = tradedQuoteDisplay(positionMetrics, liveQuote, quote);
549
- const headlineQuote = settledHeadline(positionMetrics, ctx, futures) ?? headlineQuoteDisplay(displayQuote, quote);
577
+ const headlineQuote: SessionPriceDisplay | null = settledHeadline(positionMetrics, ctx, futures) ?? rowHeadlineDisplay(displayQuote, quote, ctx);
550
578
  const { positionCurrency, totalShares, totalCost, totalCostUnits, totalPriceUnits, multiplierHint, brokerMarkPrice } = positionMetrics;
551
579
 
552
580
  const toBaseQuote = (value: number) =>
@@ -598,8 +626,13 @@ export function getColumnValue(
598
626
  return { text: compactText(ticker.metadata.industry || financials?.profile?.industry) };
599
627
  case "tags":
600
628
  return { text: ticker.metadata.tags.length > 0 ? ticker.metadata.tags.join(",") : "—" };
601
- case "price":
602
- return resolvePortfolioPriceValue(headlineQuote, brokerMarkPrice, headlineQuote ? currentQuoteOptions : markOptions, col.width, quote?.marketState);
629
+ case "price": {
630
+ const cell = resolvePortfolioPriceValue(headlineQuote, brokerMarkPrice, headlineQuote ? currentQuoteOptions : markOptions, col.width, quote?.marketState);
631
+ // An extended-hours print says which session it is from, before it so the digits stay aligned: AH 158.78.
632
+ // The table widens the column to fit; an export keeps the price.
633
+ const session = headlineQuote?.session;
634
+ return session ? { ...cell, text: `${EXTENDED_SESSION_MARKS[session]} ${cell.text}`, value: headlineQuote.price } : cell;
635
+ }
603
636
  case "change":
604
637
  if (!headlineQuote) return { text: "—" };
605
638
  // A listing that no longer trades has no day's move: its last session's is years old.
@@ -832,7 +865,7 @@ export function getSortValue(
832
865
  const liveQuote = getPortfolioQuoteDisplay(positionMetrics, quote);
833
866
  const activeQuote = getPortfolioValuationDisplay(positionMetrics, quote, ctx.valuationBasis, futures?.settlement);
834
867
  const displayQuote = tradedQuoteDisplay(positionMetrics, liveQuote, quote);
835
- const headlineQuote = settledHeadline(positionMetrics, ctx, futures) ?? headlineQuoteDisplay(displayQuote, quote);
868
+ const headlineQuote = settledHeadline(positionMetrics, ctx, futures) ?? rowHeadlineDisplay(displayQuote, quote, ctx);
836
869
  const { positionCurrency, totalShares, totalCost, totalCostUnits, totalPriceUnits, brokerMarkPrice } = positionMetrics;
837
870
 
838
871
  const toBaseQuote = (value: number) =>
@@ -3,7 +3,7 @@ import type { TickerRecord } from "../types/ticker";
3
3
  import type { BrokerAccount } from "../types/trading";
4
4
  import { isDepositaryReceiptCategory, normalizeAssetCategory } from "../utils/asset-category";
5
5
  import { getPricePointTimestamp } from "../utils/price-history";
6
- import { mergePriceHistoryIntegrity, pricePointIntegrity, type PriceHistoryIntegrity } from "../utils/price-history-integrity";
6
+ import { mergePriceHistoryIntegrity, pricePointCloseCopied, pricePointIntegrity, type PriceHistoryIntegrity } from "../utils/price-history-integrity";
7
7
 
8
8
  export interface DatedReturn {
9
9
  startDateKey: string;
@@ -107,7 +107,9 @@ export function resolveDatedReturns(history: PricePoint[]): ReturnHistoryResult
107
107
  const byTimestamp = new Map<number, PricePoint>();
108
108
  for (const point of history) {
109
109
  const timestamp = getPricePointTimestamp(point);
110
- if (Number.isFinite(timestamp)) byTimestamp.set(timestamp, point);
110
+ // A pair's close its source copied from the open, which nothing rebuilt, is no day's close: the return runs across
111
+ // it from the close before, as across a holiday.
112
+ if (Number.isFinite(timestamp) && !pricePointCloseCopied(point)) byTimestamp.set(timestamp, point);
111
113
  }
112
114
  const reported = [...byTimestamp].map(([timestamp, point]) => ({ timestamp, point }));
113
115
  const issues = reported.map(({ point }) => pricePointIntegrity(point))
@@ -0,0 +1,147 @@
1
+ import { useCallback, useEffect, useRef, useState, type MouseEvent as ReactMouseEvent, type RefObject } from "react";
2
+ import { COLUMN_DRAG_THRESHOLD_PX, columnDropBoundary, columnDropIndex } from "../../../components/ui/data-table/column-order";
3
+ import { hideDragShield, showDragShield } from "../host/drag-shield";
4
+
5
+ /** A header being dragged: the column's index, and where the drop line stands in the table's content (null where it would stay). */
6
+ export interface WebColumnDrag {
7
+ from: number;
8
+ dropLeft: number | null;
9
+ }
10
+
11
+ /** How near the body's side edge the pointer scrolls a wide table toward it while it drags a column, and how far each frame. */
12
+ const AUTO_SCROLL_EDGE_PX = 24;
13
+ const AUTO_SCROLL_STEP_PX = 8;
14
+
15
+ interface Span {
16
+ start: number;
17
+ end: number;
18
+ }
19
+
20
+ /** Where the line between two columns stands: in the middle of the gap, or just past the last column. */
21
+ function dropLineX(spans: readonly Span[], boundary: number): number | null {
22
+ const before = spans[boundary - 1];
23
+ const after = spans[boundary];
24
+ if (before && after) return (before.end + after.start) / 2;
25
+ const gap = spans.length > 1 ? Math.max(0, spans[1]!.start - spans[0]!.end) : 0;
26
+ if (before) return before.end + gap / 2;
27
+ if (after) return after.start - gap / 2;
28
+ return null;
29
+ }
30
+
31
+ /**
32
+ * A press on a movable header: released where it was, it sorts as a click
33
+ * does; moved past a few pixels, it drags the column, an accent line marks
34
+ * the gap it would drop into, and the release moves it there. A table wider
35
+ * than its body scrolls while the pointer holds at its side edge. Escape, or
36
+ * the window losing focus, puts the column back.
37
+ */
38
+ export function useWebColumnDrag({
39
+ contentRef,
40
+ bodyRef,
41
+ anchoredColumns,
42
+ onColumnMove,
43
+ onHeaderClick,
44
+ }: {
45
+ contentRef: RefObject<HTMLDivElement | null>;
46
+ bodyRef: RefObject<HTMLDivElement | null>;
47
+ anchoredColumns: number;
48
+ onColumnMove?: (columnId: string, toIndex: number) => void;
49
+ onHeaderClick?: (columnId: string) => void;
50
+ }) {
51
+ const [drag, setDrag] = useState<WebColumnDrag | null>(null);
52
+ const cleanupRef = useRef<(() => void) | null>(null);
53
+ const latest = useRef({ anchoredColumns, onColumnMove, onHeaderClick });
54
+ latest.current = { anchoredColumns, onColumnMove, onHeaderClick };
55
+ useEffect(() => () => cleanupRef.current?.(), []);
56
+
57
+ const startPress = useCallback((columnId: string, from: number, event: ReactMouseEvent<HTMLElement>) => {
58
+ cleanupRef.current?.();
59
+ const startX = event.clientX;
60
+ let pointerX = startX;
61
+ let dragging = false;
62
+ let frame = 0;
63
+ const measure = () => {
64
+ const cells = contentRef.current?.querySelectorAll<HTMLElement>(
65
+ '[data-gloom-role="data-table-header-row"] > [data-gloom-role="data-table-header-cell"]',
66
+ ) ?? [];
67
+ const spans = [...cells].map((cell) => {
68
+ const bounds = cell.getBoundingClientRect();
69
+ return { start: bounds.left, end: bounds.right };
70
+ });
71
+ // A frozen first column stays put while the others scroll under it: nothing drops among those it covers.
72
+ const frozenEnd = cells[0]?.style.position === "sticky" ? spans[0]?.end : undefined;
73
+ return { spans, frozenEnd, boundary: columnDropBoundary(spans, pointerX, latest.current.anchoredColumns, frozenEnd) };
74
+ };
75
+ const show = () => {
76
+ const { spans, frozenEnd, boundary } = measure();
77
+ const content = contentRef.current?.getBoundingClientRect();
78
+ const gapX = columnDropIndex(from, boundary) === null ? null : dropLineX(spans, boundary);
79
+ const lineX = gapX === null || frozenEnd === undefined ? gapX : Math.max(gapX, frozenEnd);
80
+ const dropLeft = lineX === null || !content ? null : lineX - content.left;
81
+ setDrag((current) => current?.from === from && current.dropLeft === dropLeft ? current : { from, dropLeft });
82
+ };
83
+ const autoScroll = () => {
84
+ frame = requestAnimationFrame(autoScroll);
85
+ const body = bodyRef.current;
86
+ if (!body || body.scrollWidth <= body.clientWidth) return;
87
+ const bounds = body.getBoundingClientRect();
88
+ const step = pointerX < bounds.left + AUTO_SCROLL_EDGE_PX ? -AUTO_SCROLL_STEP_PX
89
+ : pointerX > bounds.right - AUTO_SCROLL_EDGE_PX ? AUTO_SCROLL_STEP_PX : 0;
90
+ if (step === 0) return;
91
+ const before = body.scrollLeft;
92
+ body.scrollLeft = before + step;
93
+ if (body.scrollLeft !== before) show();
94
+ };
95
+ const cleanup = () => {
96
+ document.removeEventListener("mousemove", handleMove, true);
97
+ document.removeEventListener("mouseup", handleUp, true);
98
+ window.removeEventListener("keydown", handleKey, true);
99
+ window.removeEventListener("blur", cleanup);
100
+ cancelAnimationFrame(frame);
101
+ if (dragging) hideDragShield();
102
+ cleanupRef.current = null;
103
+ setDrag(null);
104
+ };
105
+ const handleMove = (moveEvent: MouseEvent) => {
106
+ if (moveEvent.buttons === 0) {
107
+ cleanup();
108
+ return;
109
+ }
110
+ pointerX = moveEvent.clientX;
111
+ if (!dragging) {
112
+ if (Math.abs(pointerX - startX) < COLUMN_DRAG_THRESHOLD_PX) return;
113
+ dragging = true;
114
+ showDragShield();
115
+ frame = requestAnimationFrame(autoScroll);
116
+ }
117
+ moveEvent.preventDefault();
118
+ show();
119
+ };
120
+ const handleUp = (upEvent: MouseEvent) => {
121
+ pointerX = upEvent.clientX;
122
+ const wasDragging = dragging;
123
+ const { boundary } = measure();
124
+ cleanup();
125
+ const { onColumnMove: move, onHeaderClick: sort } = latest.current;
126
+ if (!wasDragging) {
127
+ sort?.(columnId);
128
+ return;
129
+ }
130
+ const to = columnDropIndex(from, boundary);
131
+ if (to !== null) move?.(columnId, to);
132
+ };
133
+ const handleKey = (keyEvent: KeyboardEvent) => {
134
+ if (keyEvent.key !== "Escape" || !dragging) return;
135
+ keyEvent.preventDefault();
136
+ keyEvent.stopPropagation();
137
+ cleanup();
138
+ };
139
+ document.addEventListener("mousemove", handleMove, true);
140
+ document.addEventListener("mouseup", handleUp, true);
141
+ window.addEventListener("keydown", handleKey, true);
142
+ window.addEventListener("blur", cleanup);
143
+ cleanupRef.current = cleanup;
144
+ }, [bodyRef, contentRef]);
145
+
146
+ return { drag, startPress };
147
+ }
@@ -44,6 +44,7 @@ import {
44
44
  useScrollbarState,
45
45
  } from "./dom";
46
46
  import { WebDataTableHeader, WebDataTableRow } from "./row";
47
+ import { useWebColumnDrag } from "./column-drag";
47
48
 
48
49
  interface VirtualRow {
49
50
  index: number;
@@ -84,6 +85,8 @@ export function WebDataTable<T, C extends DataTableColumn = DataTableColumn>({
84
85
  sortColumnId,
85
86
  sortDirection,
86
87
  onHeaderClick,
88
+ onColumnMove,
89
+ anchoredColumns = 1,
87
90
  headerScrollRef,
88
91
  scrollRef,
89
92
  syncHeaderScroll: _syncHeaderScroll,
@@ -124,6 +127,14 @@ export function WebDataTable<T, C extends DataTableColumn = DataTableColumn>({
124
127
  const paneInstanceId = usePaneInstance()?.instanceId ?? null;
125
128
  const focusPane = useFocusOwningPane();
126
129
  const bodyElementRef = useRef<HTMLDivElement | null>(null);
130
+ const contentElementRef = useRef<HTMLDivElement | null>(null);
131
+ const { drag: columnDrag, startPress: pressMovableHeader } = useWebColumnDrag({
132
+ contentRef: contentElementRef,
133
+ bodyRef: bodyElementRef,
134
+ anchoredColumns,
135
+ onColumnMove,
136
+ onHeaderClick,
137
+ });
127
138
  const headerHorizontal = useScrollbarState(false);
128
139
  const headerVertical = useScrollbarState(false);
129
140
  const bodyHorizontal = useScrollbarState(showHorizontalScrollbar);
@@ -427,6 +438,7 @@ export function WebDataTable<T, C extends DataTableColumn = DataTableColumn>({
427
438
  onTouchMove={() => { controlledScrollOffsetRef.current = null; }}
428
439
  >
429
440
  <div
441
+ ref={contentElementRef}
430
442
  data-gloom-role="data-table-scroll-content"
431
443
  style={{
432
444
  position: "relative",
@@ -446,9 +458,19 @@ export function WebDataTable<T, C extends DataTableColumn = DataTableColumn>({
446
458
  onTableMouseDown={onTableMouseDown}
447
459
  gridTemplateColumns={gridTemplateColumns}
448
460
  onHeaderClick={onHeaderClick}
461
+ onMovableHeaderPress={onColumnMove ? pressMovableHeader : undefined}
462
+ anchoredColumns={anchoredColumns}
463
+ draggedColumn={columnDrag?.from ?? null}
449
464
  sortColumnId={sortColumnId}
450
465
  sortDirection={sortDirection}
451
466
  />
467
+ {columnDrag?.dropLeft != null ? (
468
+ <div
469
+ data-gloom-role="data-table-drop-indicator"
470
+ aria-hidden="true"
471
+ style={{ left: columnDrag.dropLeft }}
472
+ />
473
+ ) : null}
452
474
  {items.length === 0 ? (
453
475
  emptyContent ?? (
454
476
  <EmptyBody body={bodyElementRef}>