@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.
Files changed (195) hide show
  1. package/package.json +1 -1
  2. package/src/account/heard-from-question.tsx +6 -4
  3. package/src/account/heard-from.ts +3 -4
  4. package/src/api-client/exchange-announcements.ts +2 -2
  5. package/src/api-client/heard-from.ts +5 -7
  6. package/src/api-client/ownership-disclosures.ts +38 -5
  7. package/src/api-client/types/ticker-data.ts +3 -1
  8. package/src/architecture/dom-cell-metrics-allowlist.json +2 -2
  9. package/src/cli/commands/market.ts +5 -3
  10. package/src/cli/commands/overview.ts +7 -9
  11. package/src/cli/listing-arg.ts +45 -18
  12. package/src/cli/pane-functions/catalog-snapshot.json +2 -2
  13. package/src/cli/pane-functions/data.ts +3 -1
  14. package/src/cli/pane-functions/freshness.ts +6 -1
  15. package/src/cli/pane-functions/function-help.ts +0 -2
  16. package/src/cli/pane-functions/market-session.ts +12 -2
  17. package/src/cli/pane-functions/screenshot-payload.ts +3 -1
  18. package/src/cli/symbol-list.ts +52 -14
  19. package/src/cli/ticker-resolution.ts +133 -38
  20. package/src/components/chart/composite/composite-chart.tsx +12 -0
  21. package/src/components/chart/composite/types.ts +18 -0
  22. package/src/components/chart/composite/use-composite-chart-keyboard.ts +38 -15
  23. package/src/components/chart-table/header.tsx +11 -5
  24. package/src/components/chart-table/selection.ts +20 -1
  25. package/src/components/data-table/view.tsx +2 -0
  26. package/src/components/feed-data-table/stack-view.tsx +85 -5
  27. package/src/components/layout/pane/header.tsx +12 -30
  28. package/src/components/ticker/badge/index.tsx +9 -4
  29. package/src/components/ticker/badge/list.tsx +3 -1
  30. package/src/components/ui/data-table/index.tsx +7 -1
  31. package/src/components/ui/data-table/muted-row.tsx +47 -0
  32. package/src/components/ui/data-table/opentui/index.tsx +42 -11
  33. package/src/components/ui/data-table/spill.ts +36 -0
  34. package/src/components/ui/data-table/types.ts +17 -1
  35. package/src/components/ui/data-table/use-column-order.ts +11 -0
  36. package/src/components/ui/icon.tsx +50 -3
  37. package/src/components/ui/list-view.tsx +2 -2
  38. package/src/components/ui/table-layout.ts +32 -0
  39. package/src/components/ui/terminal-hover-label.tsx +49 -0
  40. package/src/components/use-pinned-moment.ts +222 -13
  41. package/src/core/state/app/state.ts +11 -2
  42. package/src/core/state/app/types.ts +2 -1
  43. package/src/data/sqlite/access.ts +14 -1
  44. package/src/data/sqlite/checkpointer.ts +2 -2
  45. package/src/data/sqlite/database.ts +4 -0
  46. package/src/docs/snapshot.json +180 -26
  47. package/src/i18n/es.ts +1 -0
  48. package/src/i18n/ja.ts +1 -0
  49. package/src/i18n/ko.ts +1 -0
  50. package/src/i18n/zh-cn.ts +1 -0
  51. package/src/i18n/zh-tw.ts +1 -0
  52. package/src/market-data/market/freshness.ts +2 -2
  53. package/src/market-data/market/globex-day.ts +14 -0
  54. package/src/market-data/published-us-sessions.ts +3 -2
  55. package/src/market-data/quotes/live-valuation.ts +4 -2
  56. package/src/market-data/quotes/metadata.ts +48 -5
  57. package/src/market-data/quotes/regular-session-valuation.ts +12 -1
  58. package/src/plugins/builtin/alerts/history-pane.tsx +19 -3
  59. package/src/plugins/builtin/broker-trading/orders.tsx +4 -2
  60. package/src/plugins/builtin/chat/attachments/desktop.tsx +46 -12
  61. package/src/plugins/builtin/chat/channels.ts +5 -2
  62. package/src/plugins/builtin/chat/content/composer-runtime.ts +64 -65
  63. package/src/plugins/builtin/chat/content/footer.tsx +17 -7
  64. package/src/plugins/builtin/chat/content/index.tsx +108 -36
  65. package/src/plugins/builtin/chat/content/new-dm-dialog.tsx +21 -8
  66. package/src/plugins/builtin/chat/content/selection-runtime.ts +16 -0
  67. package/src/plugins/builtin/chat/content/shortcuts.ts +3 -0
  68. package/src/plugins/builtin/chat/content/snapshot.ts +37 -13
  69. package/src/plugins/builtin/chat/content/transcript.tsx +12 -0
  70. package/src/plugins/builtin/chat/content/types.ts +2 -0
  71. package/src/plugins/builtin/chat/controller/channels.ts +15 -15
  72. package/src/plugins/builtin/chat/controller/index.ts +140 -34
  73. package/src/plugins/builtin/chat/controller/lifecycle.ts +8 -12
  74. package/src/plugins/builtin/chat/controller/persistence.ts +32 -4
  75. package/src/plugins/builtin/chat/controller/send.ts +41 -17
  76. package/src/plugins/builtin/chat/controller/session-runtime.ts +28 -27
  77. package/src/plugins/builtin/chat/controller/state.ts +17 -8
  78. package/src/plugins/builtin/chat/controller/storage.ts +41 -4
  79. package/src/plugins/builtin/chat/controller/view.ts +6 -3
  80. package/src/plugins/builtin/chat/index.tsx +1 -1
  81. package/src/plugins/builtin/chat/layout.ts +8 -1
  82. package/src/plugins/builtin/chat/message/desktop.tsx +15 -11
  83. package/src/plugins/builtin/chat/message/header.tsx +112 -30
  84. package/src/plugins/builtin/chat/message/reactions.tsx +10 -11
  85. package/src/plugins/builtin/chat/message/render-state.ts +4 -2
  86. package/src/plugins/builtin/chat/message/terminal.tsx +13 -15
  87. package/src/plugins/builtin/chat/message/types.ts +5 -0
  88. package/src/plugins/builtin/cloud-tweets/table.tsx +25 -2
  89. package/src/plugins/builtin/company-kpis/model.ts +11 -3
  90. package/src/plugins/builtin/correlation/compute.ts +6 -1
  91. package/src/plugins/builtin/custom-view/loader.ts +95 -34
  92. package/src/plugins/builtin/custom-view/pane.tsx +31 -41
  93. package/src/plugins/builtin/custom-view/table.ts +201 -0
  94. package/src/plugins/builtin/dividend-yield/client.ts +14 -17
  95. package/src/plugins/builtin/dividend-yield/headless.ts +0 -1
  96. package/src/plugins/builtin/dividend-yield/model.ts +45 -6
  97. package/src/plugins/builtin/dividend-yield/pane.tsx +70 -7
  98. package/src/plugins/builtin/dividend-yield/types.ts +2 -3
  99. package/src/plugins/builtin/dividend-yield/view.ts +22 -2
  100. package/src/plugins/builtin/econ/calendar-model.ts +135 -0
  101. package/src/plugins/builtin/econ/columns.ts +132 -0
  102. package/src/plugins/builtin/econ/index.tsx +25 -65
  103. package/src/plugins/builtin/holders/disclosures-view.tsx +9 -6
  104. package/src/plugins/builtin/holders/disclosures.ts +20 -6
  105. package/src/plugins/builtin/holders/headless.ts +2 -2
  106. package/src/plugins/builtin/ipo-calendar/model.ts +30 -1
  107. package/src/plugins/builtin/ipo-calendar/pane.tsx +7 -3
  108. package/src/plugins/builtin/kelly-sizer/headless.ts +9 -4
  109. package/src/plugins/builtin/kelly-sizer/pane.tsx +19 -9
  110. package/src/plugins/builtin/kelly-sizer/units.ts +26 -0
  111. package/src/plugins/builtin/market-halts/pane.tsx +14 -2
  112. package/src/plugins/builtin/news/wire/news/row.ts +5 -12
  113. package/src/plugins/builtin/news/wire/news/table.tsx +32 -41
  114. package/src/plugins/builtin/pe-band/headless.ts +1 -1
  115. package/src/plugins/builtin/pe-band/model.ts +41 -18
  116. package/src/plugins/builtin/pe-band/pane.tsx +6 -5
  117. package/src/plugins/builtin/perps/equity-row.tsx +4 -6
  118. package/src/plugins/builtin/perps/markets-section.tsx +19 -15
  119. package/src/plugins/builtin/perps/model.ts +10 -2
  120. package/src/plugins/builtin/portfolio-list/cli/import-positions.ts +6 -18
  121. package/src/plugins/builtin/portfolio-list/cli/portfolio-command.ts +1 -1
  122. package/src/plugins/builtin/portfolio-list/pane/purchase-date-fx.ts +1 -1
  123. package/src/plugins/builtin/portfolio-list/positions-import/index.tsx +1 -1
  124. package/src/plugins/builtin/portfolio-list/positions-import/lookup.ts +28 -57
  125. package/src/plugins/builtin/research/event-data.ts +3 -1
  126. package/src/plugins/builtin/research/event-model.ts +17 -15
  127. package/src/plugins/builtin/research/relative-valuation-columns.ts +19 -6
  128. package/src/plugins/builtin/research/relative-valuation-headless.ts +1 -1
  129. package/src/plugins/builtin/scanner/flow-pane.tsx +10 -0
  130. package/src/plugins/builtin/sec/exchange-filings.ts +32 -7
  131. package/src/plugins/builtin/sec/headless.ts +8 -8
  132. package/src/plugins/builtin/sec/index.tsx +69 -29
  133. package/src/plugins/builtin/shared/report-freshness.ts +4 -1
  134. package/src/plugins/builtin/ticker-detail/financials/aggregation.ts +1 -2
  135. package/src/plugins/builtin/ticker-detail/financials/exchange-table.tsx +61 -0
  136. package/src/plugins/builtin/ticker-detail/financials/model.ts +38 -4
  137. package/src/plugins/builtin/ticker-detail/financials/ratio-table.tsx +9 -2
  138. package/src/plugins/builtin/ticker-detail/financials/tab.tsx +68 -39
  139. package/src/plugins/builtin/ticker-detail/headless.ts +4 -1
  140. package/src/plugins/builtin/ticker-detail/overview/model.ts +61 -15
  141. package/src/plugins/builtin/ticker-detail/overview-tab.tsx +5 -0
  142. package/src/plugins/builtin/time-sales/model.ts +16 -9
  143. package/src/plugins/builtin/time-sales/pane.tsx +27 -24
  144. package/src/plugins/builtin/treasury-daily/client.ts +43 -9
  145. package/src/plugins/builtin/treasury-daily/pane.tsx +48 -27
  146. package/src/plugins/builtin/treasury-daily/resource.ts +33 -0
  147. package/src/portfolio/positions-import/parse.ts +14 -6
  148. package/src/portfolio/positions-import/plan.ts +3 -2
  149. package/src/react/async-resource.ts +3 -1
  150. package/src/renderers/dom/data-table/index.tsx +40 -0
  151. package/src/renderers/dom/data-table/row.tsx +39 -3
  152. package/src/renderers/dom/desktop/icons.tsx +147 -3
  153. package/src/renderers/dom/desktop/popover.tsx +2 -2
  154. package/src/renderers/dom/host/media-surface.tsx +204 -45
  155. package/src/renderers/dom/host/tabs.tsx +1 -0
  156. package/src/renderers/dom/styles.css +14 -2
  157. package/src/renderers/electrobun/bun/desktop/backend.ts +2 -0
  158. package/src/renderers/electrobun/bun/desktop/rpc-timing.ts +9 -3
  159. package/src/renderers/electrobun/shared/protocol.ts +2 -0
  160. package/src/renderers/electrobun/view/backend-rpc.ts +5 -2
  161. package/src/renderers/electrobun/view/rpc-timeout.ts +44 -3
  162. package/src/sources/gloomberb-cloud/index.ts +8 -7
  163. package/src/sources/gloomberb-cloud/normalizers.ts +7 -2
  164. package/src/sources/listing-symbols.ts +7 -1
  165. package/src/sources/provider-router/cache.ts +5 -4
  166. package/src/sources/provider-router/financials.ts +40 -18
  167. package/src/state/app/tab-cursor.ts +47 -6
  168. package/src/telemetry/stall-clocks.ts +3 -0
  169. package/src/telemetry/stall-reports.ts +12 -3
  170. package/src/telemetry/windows-process-activity.ts +41 -0
  171. package/src/telemetry/windows-time.ts +32 -0
  172. package/src/test-support/scoped-earnings.ts +24 -0
  173. package/src/tickers/terminal-codes.ts +1 -6
  174. package/src/time-series/daily-valuation.ts +13 -6
  175. package/src/time-series/filed-trailing-eps.ts +16 -3
  176. package/src/time-series/fundamentals/current-valuation.ts +8 -0
  177. package/src/time-series/fundamentals/historical-valuation.ts +20 -0
  178. package/src/time-series/fundamentals/series.ts +13 -1
  179. package/src/time-series/valuation-currency.ts +2 -0
  180. package/src/types/financials.ts +46 -10
  181. package/src/ui/dialog-context.ts +8 -0
  182. package/src/utils/datetime-format.ts +23 -1
  183. package/src/utils/declared-dividends.ts +12 -2
  184. package/src/utils/exchange-announcements.ts +4 -1
  185. package/src/utils/exchange-notation.generated.ts +3 -1
  186. package/src/utils/exchanges.ts +2 -1
  187. package/src/utils/fundamentals.ts +1 -0
  188. package/src/utils/main-thread-stall.ts +9 -1
  189. package/src/utils/rpc-timeout-error.ts +36 -11
  190. package/src/utils/sec.ts +3 -1
  191. package/src/utils/share-multiples.ts +1 -1
  192. package/src/utils/stall-process-activity.ts +70 -0
  193. package/src/utils/statement-scope.ts +103 -0
  194. package/src/utils/trailing-eps.ts +1 -1
  195. package/src/utils/zoned-date-time.ts +1 -0
@@ -1,9 +1,10 @@
1
1
  import type { DataTableColumn } from "../../../components";
2
+ import { getTableWidth, hasMeaningfulTableHorizontalOverflow } from "../../../components/ui/table-layout";
2
3
  import { compareSortValues, type SortDirection } from "../../../utils/sort-values";
3
4
  import { displayWidth, formatDistributionAmount } from "../../../utils/format";
4
- import { dividendAmountDigits, formatDividendRowAmount, type DividendRow } from "./view";
5
+ import { dividendAmountDigits, dividendRowStatus, formatDividendRowAmount, type DividendRow } from "./view";
5
6
 
6
- export type DividendColumnId = "exDate" | "amount" | "declared" | "currency" | "source";
7
+ export type DividendColumnId = "exDate" | "amount" | "declared" | "currency" | "status" | "source";
7
8
  export type DividendColumn = DataTableColumn & { id: DividendColumnId };
8
9
 
9
10
  export interface DividendSortPreference {
@@ -21,19 +22,56 @@ export const DEFAULT_SORT_PREFERENCE: DividendSortPreference = {
21
22
  * amount follows it only for a company declaring in another currency than the
22
23
  * listing pays (BP's dollars beside its pence). The currency column shows only
23
24
  * when the payments mix currencies; otherwise the amount's own symbol says it.
24
- * The source column shows only when a fund's sponsor gave a row its history lacks.
25
+ * The source column appears when a record cites an original publisher, at the
26
+ * widest of its widths the pane has the room for (`paneWidth`, in cells).
25
27
  */
26
- export function buildDividendColumns(rows: readonly Pick<DividendRow, "amount" | "currency" | "declared" | "source" | "cashEstimate" | "combined" | "special">[] = [], converted = false, subUnit?: string): DividendColumn[] {
28
+ export function buildDividendColumns(rows: readonly Pick<DividendRow, "amount" | "currency" | "declared" | "source" | "cashEstimate" | "combined" | "special" | "pending" | "sourceScheduleUrl">[] = [], converted = false, subUnit?: string, paneWidth?: number): DividendColumn[] {
27
29
  const mixed = new Set(rows.map((row) => row.currency)).size > 1;
28
30
  const digits = dividendAmountDigits(rows, converted, subUnit);
29
31
  const declared = rows.flatMap((row) => row.declared ? [row.declared] : []);
30
32
  const declaredDigits = dividendAmountDigits(declared);
31
- return [
33
+ const columns: DividendColumn[] = [
32
34
  { id: "exDate", label: "EX-DATE", width: 11, align: "left" },
33
35
  { id: "amount", label: "AMOUNT", width: Math.max(12, ...rows.map((row) => displayWidth(formatDividendRowAmount(row, converted, subUnit, digits)))), align: "right" },
34
36
  ...(declared.length ? [{ id: "declared" as const, label: "DECLARED", width: Math.max(10, ...declared.map((entry) => displayWidth(formatDistributionAmount(entry.amount, entry.currency, declaredDigits.get(entry.currency))))), align: "right" as const }] : []),
35
37
  ...(mixed ? [{ id: "currency" as const, label: "CCY", width: 6, align: "left" as const }] : []),
36
- ...(rows.some((row) => row.source) ? [{ id: "source" as const, label: "SOURCE", width: 12, align: "left" as const }] : []),
38
+ ...(rows.some((row) => row.pending) ? [{ id: "status" as const, label: "STATUS", width: 10, align: "left" as const }] : []),
39
+ ];
40
+ const widths = sourceColumnWidths(rows);
41
+ if (!widths.length) return columns;
42
+ const source = (width: number): DividendColumn[] => [...columns, { id: "source", label: "SOURCE", width, align: "left" }];
43
+ // By the table's own count of an overflow, in the pane less the cell of its scrollbar.
44
+ const fits = (width: number) => paneWidth === undefined || !hasMeaningfulTableHorizontalOverflow(getTableWidth(source(width)), paneWidth - 1);
45
+ return source(widths.find(fits) ?? widths.at(-1)!);
46
+ }
47
+
48
+ /** The second link of a sourced row: the timetable its publisher issued apart from the cash notice. */
49
+ export const SCHEDULE_LINK_LABEL = "Schedule";
50
+ /** A publisher's room in the source column, as wide as the longest fund sponsor's name. */
51
+ const PUBLISHER_WIDTH = 12;
52
+
53
+ /** The cells a sourced row's links take: its publisher's, and with `schedule` the schedule's a cell after it. */
54
+ export function sourceLinksWidth(row: Pick<DividendRow, "source" | "sourceScheduleUrl">, schedule = !!row.sourceScheduleUrl): number {
55
+ return displayWidth(row.source ?? "") + (schedule && row.sourceScheduleUrl ? 1 + displayWidth(SCHEDULE_LINK_LABEL) : 0);
56
+ }
57
+
58
+ /**
59
+ * The widths the source column can take, widest first, none without a sourced
60
+ * row. A table whose rows link a schedule beside the notice has three: a
61
+ * publisher's room and the schedule; then both links as the rows hold them;
62
+ * then the publishers alone, where the schedule is left to the selected row's
63
+ * menu. A cell draws the schedule only in a column with the room for both
64
+ * links whole (`sourceLinksWidth`), so the pane's edge never cuts one.
65
+ */
66
+ function sourceColumnWidths(rows: readonly Pick<DividendRow, "source" | "sourceScheduleUrl">[]): number[] {
67
+ const sourced = rows.filter((row) => row.source);
68
+ if (!sourced.length) return [];
69
+ if (!sourced.some((row) => row.sourceScheduleUrl)) return [PUBLISHER_WIDTH];
70
+ const links = Math.max(...sourced.map((row) => sourceLinksWidth(row)));
71
+ return [
72
+ Math.max(links, PUBLISHER_WIDTH + 1 + displayWidth(SCHEDULE_LINK_LABEL)),
73
+ links,
74
+ Math.max(...sourced.map((row) => sourceLinksWidth(row, false))),
37
75
  ];
38
76
  }
39
77
 
@@ -43,6 +81,7 @@ function getSortValue(columnId: DividendColumnId, row: DividendRow): string | nu
43
81
  case "amount": return row.amount;
44
82
  case "declared": return row.declared?.amount ?? null;
45
83
  case "currency": return row.currency;
84
+ case "status": return dividendRowStatus(row);
46
85
  case "source": return row.source ?? null;
47
86
  }
48
87
  }
@@ -7,12 +7,14 @@ import {
7
7
  ChartTableHeader,
8
8
  chartTableLayout,
9
9
  DataTableView,
10
+ ExternalLinkText,
10
11
  scalarPoint,
11
12
  spanAxisFormatter,
12
13
  statGridColumns,
13
14
  staticSeries,
14
15
  useChartTableSelection,
15
16
  usePaneFooter,
17
+ usePaneMenuItems,
16
18
  usePaneNoticeFooter,
17
19
  usePaneTicker,
18
20
  type DataTableCell,
@@ -21,12 +23,13 @@ import {
21
23
  } from "../../../components";
22
24
  import { useAsyncResource } from "../../../react/async-resource";
23
25
  import { colors, priceColor } from "../../../theme/colors";
24
- import { TextAttributes, useUiCapabilities } from "../../../ui";
26
+ import { Box, TextAttributes, useRendererHost, useUiCapabilities } from "../../../ui";
25
27
  import { MISSING_VALUE, displayWidth, formatCurrency, formatDistributionAmount, formatPercentRaw } from "../../../utils/format";
26
28
  import { NOT_MEANINGFUL_TEXT } from "../../../utils/growth";
27
29
  import { resolveCurrencyUnit } from "../../../utils/currency-units";
28
30
  import { parsePublicTickerKey } from "../../../utils/exchanges";
29
31
  import { forwardDividendNote, lapseValue, lastPaidNote, UNEVEN_REGULAR_PAYMENTS } from "../../../utils/forward-dividend";
32
+ import { logFailure } from "../../../utils/log-failure";
30
33
  import { nextHeaderSort } from "../../../utils/sort-values";
31
34
  import { handleRefreshKey, loadingErrorFooterInfo } from "../../../components/data-table/table-pane";
32
35
  import { SignInWall } from "../cloud/auth-actions";
@@ -34,11 +37,13 @@ import { isCloudSessionRequired, useResearchCloudSession } from "../shared/resea
34
37
  import { fetchDividendData, repriceDividendMetrics, statedForwardRate, type DividendData } from "./client";
35
38
  import { dividendReferencePrice } from "../../../utils/trailing-dividend";
36
39
  import { useTickerQuoteStream } from "../../../state/hooks/live-ticker-financials";
37
- import { buildTrailingCashChartPoints, convertedFromText, dividendAmountDigits, formatConvertedAmount, formatDividendRowAmount, formatDividendYield, forwardEstimateText, growthPaymentsDetail, PAYOUT_BASIS, PAYOUT_NOT_MEANINGFUL, staleHistoryText, toDividendRows, trailingPaymentsText, trailingSpecialText, type DividendAmountDigits, type DividendRow } from "./view";
40
+ import { buildTrailingCashChartPoints, convertedFromText, dividendAmountDigits, dividendRowStatus, formatConvertedAmount, formatDividendRowAmount, formatDividendYield, forwardEstimateText, growthPaymentsDetail, PAYOUT_BASIS, PAYOUT_NOT_MEANINGFUL, staleHistoryText, toDividendRows, trailingPaymentsText, trailingSpecialText, type DividendAmountDigits, type DividendRow } from "./view";
38
41
  import {
39
42
  DEFAULT_SORT_PREFERENCE,
43
+ SCHEDULE_LINK_LABEL,
40
44
  buildDividendColumns,
41
45
  sortRows,
46
+ sourceLinksWidth,
42
47
  type DividendColumn,
43
48
  type DividendColumnId,
44
49
  type DividendSortPreference,
@@ -182,11 +187,37 @@ function renderCell(
182
187
  return { text: row.declared ? formatDistributionAmount(row.declared.amount, row.declared.currency, digits.declared.get(row.declared.currency)) : "", color: colors.textDim };
183
188
  case "currency":
184
189
  return { text: row.currency, color: colors.textDim };
190
+ case "status":
191
+ return { text: dividendRowStatus(row), color: colors.textDim };
185
192
  case "source":
186
- return { text: row.source ?? "", color: colors.textDim };
193
+ return sourceCell(row, column.width);
187
194
  }
188
195
  }
189
196
 
197
+ /**
198
+ * A sourced row's links: its publisher opens the notice, and the schedule
199
+ * follows it only in a column with the room for both whole. In less (the
200
+ * column the pane fits to its width, or the cells of it the pane's edge
201
+ * leaves), the publisher's link stands alone, cut where its room ends, and
202
+ * the schedule opens from the selected row's menu.
203
+ */
204
+ function sourceCell(row: DividendRow, width: number): DataTableCell {
205
+ const text = row.source ?? "";
206
+ if (!row.sourceUrl) return { text, color: colors.textDim };
207
+ const schedule = sourceLinksWidth(row) <= width ? row.sourceScheduleUrl : undefined;
208
+ return {
209
+ text,
210
+ color: colors.textDim,
211
+ contentWidth: sourceLinksWidth(row, !!schedule),
212
+ content: (
213
+ <Box flexDirection="row" gap={1}>
214
+ <ExternalLinkText url={row.sourceUrl} label={text} width={schedule ? displayWidth(text) : width} />
215
+ {schedule ? <ExternalLinkText url={schedule} label={SCHEDULE_LINK_LABEL} width={displayWidth(SCHEDULE_LINK_LABEL)} /> : null}
216
+ </Box>
217
+ ),
218
+ };
219
+ }
220
+
190
221
  type DividendPaneProps = { focused: boolean; width: number; height: number; loadData?: typeof fetchDividendData };
191
222
 
192
223
  /** One ticker's dividends, or several ranked by yield when the pane was opened with a list (`shot DVD KO JNJ`). */
@@ -197,6 +228,10 @@ export function DividendYieldPane(props: DividendPaneProps) {
197
228
 
198
229
  function DividendTickerPane({ focused, width, height, loadData = fetchDividendData }: DividendPaneProps) {
199
230
  const { symbol, ticker, financials } = usePaneTicker();
231
+ const rendererHost = useRendererHost();
232
+ const openNotice = useCallback((url: string) => {
233
+ void rendererHost.openExternal(url).catch(logFailure("dividend-yield.pane", "Open dividend notice failed"));
234
+ }, [rendererHost]);
200
235
  const { nativePaneChrome } = useUiCapabilities();
201
236
  // Yields are repriced from the quote on every render, so streaming it is all
202
237
  // it takes for them to move with the stock. A yield to two decimals needs
@@ -280,11 +315,31 @@ function DividendTickerPane({ focused, width, height, loadData = fetchDividendDa
280
315
  enabled: !authWall,
281
316
  });
282
317
  const metrics = data?.metrics ? repriceDividendMetrics(data.metrics, currentPrice) : undefined;
283
- const rows = useMemo(() => toDividendRows(payments), [payments]);
318
+ const nextPayDate = metrics?.nextPayDate?.toISOString().slice(0, 10);
319
+ const rows = useMemo(() => {
320
+ // The pay date a history record carries dates its status here; a report states it as the row's `paymentDate`.
321
+ const listed = toDividendRows(payments).map((row, index): DividendRow => {
322
+ const paidOn = payments[index]?.paymentDate;
323
+ return paidOn ? { ...row, payDate: paidOn.toISOString().slice(0, 10) } : row;
324
+ });
325
+ const listedDates = new Set(listed.map((row) => row.exDate));
326
+ const notices = new Map<string, Partial<DividendRow>>();
327
+ const ahead: DividendRow[] = [];
328
+ for (const dividend of data?.declared ?? []) {
329
+ if (!dividend.source || !currency) continue;
330
+ const notice = { pending: true as const, ...(dividend.payDate ? { payDate: dividend.payDate } : {}), ...(dividend.special ? { special: true as const } : {}),
331
+ source: dividend.source.publisher, sourceUrl: dividend.source.url, sourceScheduleUrl: dividend.source.scheduleUrl };
332
+ // A declaration the history already holds (ex-dated, its cash not fixed yet) is that row: the row keeps the
333
+ // cash the listing and the issuer state and takes the notice. One still ahead of the history is a row of its own.
334
+ if (listedDates.has(dividend.exDate)) notices.set(dividend.exDate, notice);
335
+ else ahead.push({ key: `declared:${dividend.exDate}`, exDate: dividend.exDate, amount: dividend.amount, currency, cashEstimate: dividend.cashEstimate, ...notice });
336
+ }
337
+ return [...ahead, ...listed.map((row): DividendRow => ({ ...row, ...notices.get(row.exDate) }))];
338
+ }, [currency, data?.declared, payments]);
284
339
  const sortedRows = useMemo(() => sortRows(rows, sortPreference), [rows, sortPreference]);
285
340
  const convertedFrom = historyData?.convertedFrom;
286
341
  const convertedSubUnit = historyData?.convertedSubUnit;
287
- const columns = useMemo(() => buildDividendColumns(rows, !!convertedFrom, convertedSubUnit), [rows, convertedFrom, convertedSubUnit]);
342
+ const columns = useMemo(() => buildDividendColumns(rows, !!convertedFrom, convertedSubUnit, width), [rows, convertedFrom, convertedSubUnit, width]);
288
343
  const chartPoints = useMemo(
289
344
  () => data?.historyAvailable === false ? [] : buildTrailingCashChartPoints(payments),
290
345
  [data?.historyAvailable, payments],
@@ -307,6 +362,11 @@ function DividendTickerPane({ focused, width, height, loadData = fetchDividendDa
307
362
  return chartSpan && time >= chartSpan.first && time <= chartSpan.last ? new Date(time) : null;
308
363
  }, [chartSpan?.first, chartSpan?.last]);
309
364
  const selectedId = sortedRows.some((row) => row.key === selectedKey) ? selectedKey : sortedRows[0]?.key ?? null;
365
+ const selectedSchedule = sortedRows.find((row) => row.key === selectedId)?.sourceScheduleUrl;
366
+ usePaneMenuItems("dividend-notice-schedule", () => selectedSchedule ? [{
367
+ id: "dividend-notice-schedule", label: "Open dividend schedule",
368
+ onSelect: () => openNotice(selectedSchedule),
369
+ }] : [], [openNotice, selectedSchedule]);
310
370
  const link = useChartTableSelection({
311
371
  rows: sortedRows, getId: rowKey, getDate: rowDate, selectedId, onSelect: setSelectedKey, focused,
312
372
  });
@@ -319,13 +379,13 @@ function DividendTickerPane({ focused, width, height, loadData = fetchDividendDa
319
379
  }), [rows, convertedFrom, convertedSubUnit]);
320
380
  const renderRowCell = useCallback((row: DividendRow, column: DividendColumn) => renderCell(row, column, digits, !!convertedFrom, convertedSubUnit),
321
381
  [convertedFrom, convertedSubUnit, digits]);
322
- const fullFigures = metrics ? buildMetricItems(metrics, currency, sortedRows.length > 0, false, data?.declared, bond, convertedFrom, convertedSubUnit) : [];
382
+ const fullFigures = metrics ? buildMetricItems(metrics, currency, payments.length > 0, false, data?.declared, bond, convertedFrom, convertedSubUnit) : [];
323
383
  const keptFigures = chartTableLayout({
324
384
  width, height, figures: fullFigures, tableRows: sortedRows.length, tableChromeRows, chart: chartPoints.length >= 2 ? {} : null,
325
385
  }).figures;
326
386
  // The desktop grid never clips a label; the terminal shortens them rather than clip.
327
387
  const figures = metrics && !nativePaneChrome && labelsClip(keptFigures, width)
328
- ? buildMetricItems(metrics, currency, sortedRows.length > 0, true, data?.declared, bond, convertedFrom, convertedSubUnit) : fullFigures;
388
+ ? buildMetricItems(metrics, currency, payments.length > 0, true, data?.declared, bond, convertedFrom, convertedSubUnit) : fullFigures;
329
389
 
330
390
  const handleHeaderClick = useCallback((columnId: string) => {
331
391
  setSortPreference((current) => nextHeaderSort(current, columnId as DividendColumnId, {
@@ -351,6 +411,9 @@ function DividendTickerPane({ focused, width, height, loadData = fetchDividendDa
351
411
  <DataTableView<DividendRow, DividendColumn>
352
412
  focused={focused}
353
413
  selection={{ kind: "id", selectedId, getId: rowKey, onChange: (id) => setSelectedKey(id) }}
414
+ onActivate={(row) => { if (row.sourceUrl) openNotice(row.sourceUrl); }}
415
+ rowNote={(row) => row.pending && row.payDate && row.payDate !== nextPayDate
416
+ ? { text: `Payable ${formatDay(row.payDate)}`, tone: "muted" } : null}
354
417
  onRootKeyDown={handleKeyDown}
355
418
  resetScrollKey={symbol}
356
419
  rootWidth={width}
@@ -1,6 +1,6 @@
1
1
  import type { DividendLapse } from "../../../utils/forward-dividend";
2
2
  import type { DistributionCadence, TrailingPayments } from "../../../utils/trailing-dividend";
3
- import type { DividendCashEstimate } from "../../../types/financials";
3
+ import type { DividendCashEstimate, DividendNoticeSource } from "../../../types/financials";
4
4
 
5
5
  export interface DividendPayment {
6
6
  exDate: Date;
@@ -13,8 +13,7 @@ export interface DividendPayment {
13
13
  /** The amount as the company declared it, in another currency than `currency` (BP's dollars beside the pence its London line paid). */
14
14
  declared?: { amount: number; currency: string };
15
15
  cashEstimate?: DividendCashEstimate;
16
- /** Who published it when not the listing's history: the fund's sponsor (DividendAction.source). */
17
- source?: { publisher: string; url: string };
16
+ source?: DividendNoticeSource;
18
17
  /** The amount is a regular payment and an extra one on the same ex-date, which the history keeps as one row (combinedPaymentTimes). */
19
18
  combined?: true;
20
19
  /** The issuer's own dividend announcement form says it is a special (CashDistribution.special). */
@@ -176,14 +176,33 @@ export interface DividendRow {
176
176
  currency: string;
177
177
  /** The amount as the company declared it, in another currency (DividendPayment.declared). */
178
178
  declared?: { amount: number; currency: string };
179
- /** Who published it when not the listing's history: the fund's sponsor (DividendPayment.source). */
179
+ /** The original publisher when the record cites a notice or sponsor page. */
180
180
  source?: string;
181
+ sourceUrl?: string;
182
+ sourceScheduleUrl?: string;
183
+ /** A sourced declaration still owes this distribution (DividendData.declared). */
184
+ pending?: true;
185
+ /** The pay date on record, YYYY-MM-DD: a declaration's, or the one a history record carries. */
186
+ payDate?: string;
181
187
  /** A regular payment and an extra one on the same ex-date (DividendPayment.combined). */
182
188
  combined?: true;
183
189
  /** A special, as the issuer's own form types it (DividendPayment.special). */
184
190
  special?: true;
185
191
  }
186
192
 
193
+ /**
194
+ * Where a distribution stands, by the dates on record and never by its place
195
+ * in the history: declared while a declaration still owes it, while its pay
196
+ * date is today or ahead, or before it goes ex; paid once a pay date on record
197
+ * has passed; and ex-dated where the ex-date has passed and no pay date says
198
+ * whether the cash went out.
199
+ */
200
+ export function dividendRowStatus(row: Pick<DividendRow, "exDate" | "pending" | "payDate">, today = new Date().toISOString().slice(0, 10)): "Declared" | "Paid" | "Ex-dated" {
201
+ if (row.pending) return "Declared";
202
+ if (row.payDate) return row.payDate < today ? "Paid" : "Declared";
203
+ return row.exDate > today ? "Declared" : "Ex-dated";
204
+ }
205
+
187
206
  export function toDividendRows(payments: DividendPayment[]): DividendRow[] {
188
207
  return payments.map((payment, index) => ({
189
208
  key: `${payment.exDate.toISOString()}:${index}`,
@@ -192,7 +211,8 @@ export function toDividendRows(payments: DividendPayment[]): DividendRow[] {
192
211
  ...(payment.cashEstimate ? { cashEstimate: payment.cashEstimate } : {}),
193
212
  currency: payment.currency,
194
213
  ...(payment.declared ? { declared: payment.declared } : {}),
195
- ...(payment.source ? { source: payment.source.publisher } : {}),
214
+ ...(payment.source ? { source: payment.source.publisher, sourceUrl: payment.source.url,
215
+ ...(payment.source.scheduleUrl ? { sourceScheduleUrl: payment.source.scheduleUrl } : {}) } : {}),
196
216
  ...(payment.combined ? { combined: true as const } : {}),
197
217
  ...(payment.special ? { special: true as const } : {}),
198
218
  }));
@@ -1,5 +1,6 @@
1
1
  import { createPluginCache } from "../../../data/plugin-cache";
2
2
  import type { DataTableCell, DataTableColumn } from "../../../components";
3
+ import { narrowColumnsForName } from "../../../components/ui/table-layout";
3
4
  import { colors } from "../../../theme/colors";
4
5
  import { displayWidth, MISSING_VALUE } from "../../../utils/format";
5
6
  import { fetchEconCalendar } from "./calendar-source";
@@ -281,6 +282,33 @@ export function eventCountry(event: Pick<EconEvent, "country" | "event">): strin
281
282
  return euroAreaMember(event) ?? event.country;
282
283
  }
283
284
 
285
+ /**
286
+ * The adjective that names a country, which a release's name may start with:
287
+ * the euro area's members, whose national releases both feeds write so, and
288
+ * the other countries the calendar lists.
289
+ */
290
+ const COUNTRY_ADJECTIVES: Readonly<Record<string, string>> = {
291
+ ...EURO_AREA_MEMBERS,
292
+ Australian: "AU", Brazilian: "BR", British: "GB", Canadian: "CA", Chinese: "CN", Danish: "DK", Indian: "IN",
293
+ Indonesian: "ID", Japanese: "JP", Mexican: "MX", Norwegian: "NO", Polish: "PL", Russian: "RU", Swedish: "SE",
294
+ Swiss: "CH", Turkish: "TR",
295
+ };
296
+
297
+ /**
298
+ * A row's name as the list shows it. Beside the country column
299
+ * (`countryShown`) a name that starts with the adjective of the row's country
300
+ * leaves it out, the column saying it once: "French Inflation Rate YoY Prel"
301
+ * on an FR row reads "Inflation Rate YoY Prel". Without the column (a filter
302
+ * on one country) the name keeps it. The detail, the search and the exports
303
+ * read the whole name (econEventName).
304
+ */
305
+ export function listedEventName(event: Pick<EconEvent, "country" | "event" | "actual" | "forecast" | "prior">, countryShown: boolean): string {
306
+ const name = econEventName(event);
307
+ if (!countryShown) return name;
308
+ const adjective = /^([A-Z][a-z]+) (?=\S)/.exec(name);
309
+ return adjective && COUNTRY_ADJECTIVES[adjective[1]!] === eventCountry(event) ? name.slice(adjective[0].length) : name;
310
+ }
311
+
284
312
  /** What the feeds call the Fed's rate decision. */
285
313
  const FED_RATE_DECISION_NAMES = new Set(["federal funds rate", "fed interest rate decision"]);
286
314
  /** A figure that is a range (3.75-4.00%) rather than one level. */
@@ -608,6 +636,20 @@ const AWAITING_FIGURE_CELL = "awaiting";
608
636
  /** The ACTUAL cell of a release whose source has no figure; the footer says it whole. */
609
637
  const NO_FIGURE_CELL = "no figure";
610
638
 
639
+ /**
640
+ * The cells of the widest word a row of `events` says under ACTUAL in place of
641
+ * its figure (`awaiting`, `no figure`), at `now`; 0 where none does. The
642
+ * column keeps them whatever the names need: a word is not a long figure.
643
+ */
644
+ export function actualNoteWidth(events: readonly EconEvent[], now: number, calendar: readonly EconEvent[] = []): number {
645
+ let widest = 0;
646
+ for (const event of events) {
647
+ const gap = figureGap(event, now, calendar);
648
+ if (gap) widest = Math.max(widest, displayWidth(gap === "none" ? NO_FIGURE_CELL : AWAITING_FIGURE_CELL));
649
+ }
650
+ return widest;
651
+ }
652
+
611
653
  /**
612
654
  * A release's ACTUAL, FORECAST or PRIOR cell. An amount reads with its
613
655
  * currency beside it (-556.5B JPY), where the server says it. A dash is
@@ -844,6 +886,99 @@ export function valueColumnWidth(events: readonly EconEvent[], key: "actual" | "
844
886
  return width;
845
887
  }
846
888
 
889
+ /** The cells a release's name needs to say which one it is (`GDP Growth Rate QoQ`, `Inflation Rate YoY`). */
890
+ const READABLE_NAME_CELLS = 20;
891
+
892
+ /**
893
+ * The figure columns a narrow calendar leaves out, least needed first, each
894
+ * with the cells the event names keep before it goes. PRIOR is context, so it
895
+ * leaves once the names would get under READABLE_NAME_CELLS: in the 9 the
896
+ * three columns left them in a pane 53 cells wide, two rows of one hour both
897
+ * read `GDP Growt…`. The forecast is what a print is read against, so the
898
+ * names give up more before it goes. The actual always stays, and an event's
899
+ * detail has all three.
900
+ */
901
+ const ECON_FIGURE_DROP_ORDER: readonly { id: string; namesUnder: number }[] = [
902
+ { id: "prior", namesUnder: READABLE_NAME_CELLS },
903
+ { id: "forecast", namesUnder: 14 },
904
+ ];
905
+
906
+ /**
907
+ * The cells a plain figure takes (`105.28B`, `-24 Bcf`, `36.00%`): a column
908
+ * keeps these, and its header, whatever the names need. A column whose
909
+ * figures are all shorter (`0.4%`) is already as narrow as its widest.
910
+ */
911
+ const PLAIN_FIGURE_WIDTH = 7;
912
+
913
+ /** The fewest cells `column` gives up to: a plain figure's, and under ACTUAL the word a row says in place of one (`actualNote`). */
914
+ const plainFigureCells = (column: { id: string }, actualNote: number) =>
915
+ (column.id === "actual" ? Math.max(PLAIN_FIGURE_WIDTH, actualNote) : PLAIN_FIGURE_WIDTH);
916
+
917
+ /**
918
+ * The cells the longest event name listed takes, as the list shows it beside
919
+ * its country (`countryShown`, listedEventName): a calendar of short names
920
+ * (`Retail Sales`) asks for no more.
921
+ */
922
+ export function longestEventName(events: readonly Pick<EconEvent, "country" | "event" | "actual" | "forecast" | "prior">[], countryShown = false): number {
923
+ let longest = 0;
924
+ for (const event of events) longest = Math.max(longest, displayWidth(listedEventName(event, countryShown)));
925
+ return longest;
926
+ }
927
+
928
+ /**
929
+ * The figure columns a calendar keeps at its width, as every narrow table
930
+ * decides: the name that says what a row is stays readable, and the least
931
+ * needed columns leave first (ECON_FIGURE_DROP_ORDER). Once one has left, the
932
+ * columns kept give the names what a long figure took before another goes
933
+ * (narrowColumnsForName). `roomFor` is the cells the event column gets
934
+ * beside the columns given; `longestName` what the names listed take at most
935
+ * (longestEventName), `floor` the fewest cells the column is ever drawn at,
936
+ * and `actualNote` the word a row says under ACTUAL in place of a figure
937
+ * (actualNoteWidth), which ACTUAL keeps whole. The widths are the ones the
938
+ * choice is made at; `figuresBesideNames` then gives the names the rest of
939
+ * what a long figure took.
940
+ */
941
+ export function keptFigureColumns<C extends { id: string; width: number; label?: string }>(
942
+ figures: readonly C[],
943
+ roomFor: (kept: readonly C[]) => number,
944
+ longestName: number,
945
+ floor: number,
946
+ actualNote = 0,
947
+ ): C[] {
948
+ const names = (cells: number) => Math.max(floor, Math.min(cells, longestName));
949
+ const fit = (kept: readonly C[]) => (kept.length < figures.length
950
+ ? narrowColumnsForName(kept, roomFor, names(READABLE_NAME_CELLS), (column) => plainFigureCells(column, actualNote))
951
+ : [...kept]);
952
+ let kept = [...figures];
953
+ for (const { id, namesUnder } of ECON_FIGURE_DROP_ORDER) {
954
+ const fitted = fit(kept);
955
+ if (roomFor(fitted) >= names(namesUnder)) return fitted;
956
+ kept = kept.filter((column) => column.id !== id);
957
+ }
958
+ return fit(kept);
959
+ }
960
+
961
+ /**
962
+ * The figure columns kept (keptFigureColumns) as wide as the names leave
963
+ * them: at any width, a column keeps more than a plain figure's cells (or its
964
+ * header's) only while the longest name listed is whole beside it. A column
965
+ * is as wide as the widest figure listed, so one long figure weeks out held
966
+ * every row's name to `French Inflation Rate …` beside a column of `2.9%`;
967
+ * now that figure is cut, and whole in its detail. `roomFor` is the cells the
968
+ * event column gets beside the columns given, under the headers drawn, and
969
+ * `actualNote` the word a row says under ACTUAL in place of a figure
970
+ * (actualNoteWidth), which ACTUAL keeps whole.
971
+ */
972
+ export function figuresBesideNames<C extends { id: string; width: number; label?: string }>(
973
+ figures: readonly C[],
974
+ roomFor: (kept: readonly C[]) => number,
975
+ longestName: number,
976
+ floor: number,
977
+ actualNote = 0,
978
+ ): C[] {
979
+ return narrowColumnsForName(figures, roomFor, Math.max(floor, longestName), (column) => plainFigureCells(column, actualNote));
980
+ }
981
+
847
982
  export function actualColor(actual: string | null, forecast: string | null): string {
848
983
  const a = parseEconFigure(actual)?.value ?? null;
849
984
  const f = parseEconFigure(forecast)?.value ?? null;
@@ -0,0 +1,132 @@
1
+ import { COUNTRY_FLAG_CELLS } from "../../../components/ui/country-flag";
2
+ import { markHiddenTableColumns, tableColumnWidth } from "../../../components/ui/table-layout";
3
+ import { timeZoneCity, zonedClock } from "../../../utils/utc-time";
4
+ import {
5
+ CALENDAR_TIME_ZONE_LABEL,
6
+ figuresBesideNames,
7
+ keptFigureColumns,
8
+ longestEventName,
9
+ valueColumnWidth,
10
+ type CountryFilter,
11
+ type EconCalendarColumn,
12
+ type ImpactFilter,
13
+ } from "./calendar-model";
14
+ import { hasNoReleaseTime, isAllDayEvent, type EconEvent } from "./types";
15
+
16
+ const SPELLED_IMPACT = "IMPACT";
17
+ const SPELLED_COUNTRY = "COUNTRY";
18
+ /** Event names this wide still read; past it the headers spell themselves out. */
19
+ const SPELLED_HEADER_MIN_EVENT_WIDTH = 24;
20
+
21
+ /** Whether the list has a country column: not where a filter names one country (the euro area's are several). */
22
+ export function countryColumnShown(countryFilter: CountryFilter): boolean {
23
+ return !/^[A-Z]{2}$/.test(countryFilter) || countryFilter === "EU";
24
+ }
25
+
26
+ /**
27
+ * The calendar's columns at `width` cells for the events listed (`events`):
28
+ * `columns` the table draws, `exportColumns` all of them, as Export CSV
29
+ * writes them, in the reader's column order where `exportInReaderOrder`. `flagged` leads each country's code with its flag (the
30
+ * desktop and the web), and `readerZone` is the reader's own time zone.
31
+ * `actualNote` is the widest word a row says under ACTUAL in place of its
32
+ * figure (actualNoteWidth), which the column keeps whole.
33
+ * Every width comes from the whole list, never the rows in view, so no
34
+ * column moves as the reader scrolls.
35
+ */
36
+ export function econCalendarColumns({ width, events, countryFilter, impactFilter, flagged, readerZone, actualNote = 0 }: {
37
+ width: number;
38
+ events: readonly EconEvent[];
39
+ countryFilter: CountryFilter;
40
+ impactFilter: ImpactFilter;
41
+ flagged: boolean;
42
+ readerZone: string | null;
43
+ actualNote?: number;
44
+ }): { columns: EconCalendarColumn[]; exportColumns: EconCalendarColumn[]; exportInReaderOrder: boolean } {
45
+ // Named by its zone, as the reader's column is by its city: "TIME (UTC)" took 13
46
+ // cells over "07:00" while EVENT read "GDP Growth Ra…" (review, 12 Nov 2026).
47
+ const timeLabelText = CALENDAR_TIME_ZONE_LABEL;
48
+ const timeWidth = tableColumnWidth({ width: events.some(isAllDayEvent) ? "All day".length : 5, label: timeLabelText });
49
+ const compact = width < 58;
50
+ // One country, or one impact level, is the filter's: no column repeats it on each row.
51
+ const showCountry = countryColumnShown(countryFilter);
52
+ const showImpact = impactFilter === "all";
53
+ const actualLabel = compact ? "ACT" : "ACTUAL";
54
+ const forecastLabel = compact ? "EST" : "FORECAST";
55
+ // ACTUAL as wide as its widest figure and `note`, the word a row may say in its place.
56
+ const actualWidth = (note: number) => tableColumnWidth({ width: Math.max(valueColumnWidth(events, "actual", compact ? 3 : 9), note), label: actualLabel });
57
+ const forecastWidth = tableColumnWidth({ width: valueColumnWidth(events, "forecast", compact ? 3 : 10), label: forecastLabel });
58
+ const priorWidth = tableColumnWidth({ width: valueColumnWidth(events, "prior", compact ? 5 : 9), label: "PRIOR" });
59
+ const minEventWidth = tableColumnWidth({ width: compact ? 5 : 12, label: "EVENT" });
60
+ // The reader's clock, with the weekday on rows where it is another day than the UTC one they are listed under.
61
+ const readerLabel = readerZone ? timeZoneCity(readerZone).toUpperCase() : null;
62
+ const readerWidth = !readerZone || !readerLabel ? 0 : tableColumnWidth({ label: readerLabel,
63
+ width: events.some((ev) => !hasNoReleaseTime(ev) && zonedClock(ev.date.getTime(), readerZone).label.length > 5) ? 9 : 5 });
64
+ const figureColumnsFor = (note: number): EconCalendarColumn[] => [
65
+ { id: "actual", label: actualLabel, title: "Actual", width: actualWidth(note), align: "right" },
66
+ { id: "forecast", label: forecastLabel, title: "Forecast", width: forecastWidth, align: "right" },
67
+ { id: "prior", label: "PRIOR", width: priorWidth, align: "right" },
68
+ ];
69
+ // Padding, one gap per column boundary, and the vertical scrollbar lane;
70
+ // one column short of that clipped the PRIOR values at the right edge.
71
+ // `times` is the time columns (UTC, and the reader's clock); impact, country and event are the other three.
72
+ const roomBeside = (figures: readonly EconCalendarColumn[], times: number, timesWidth: number) => (impactWidth: number, countryWidth: number) => (
73
+ width - 3 - (times + 3 + figures.length) + (showCountry ? 0 : 1) + (showImpact ? 0 : 1)
74
+ - (timesWidth + (showImpact ? impactWidth : 0) + (showCountry ? countryWidth : 0) + figures.reduce((sum, column) => sum + column.width, 0))
75
+ );
76
+ const codeWidth = 2 + (flagged ? COUNTRY_FLAG_CELLS : 0);
77
+ const underShortHeaders = (room: (impactWidth: number, countryWidth: number) => number) => room(4, Math.max(3, codeWidth));
78
+ const spelledImpactWidth = tableColumnWidth({ width: 1, label: SPELLED_IMPACT });
79
+ const spelledCountryWidth = Math.max(codeWidth, tableColumnWidth({ width: 1, label: SPELLED_COUNTRY }));
80
+
81
+ // The columns before the figures, and the figures kept, beside figure columns as wide as `figureColumns` and names
82
+ // of up to `longestName` cells, with `note` the word ACTUAL keeps whole.
83
+ const layout = (figureColumns: readonly EconCalendarColumn[], longestName: number, note: number) => {
84
+ // The reader's column only where the event names keep room to read beside it, under the short headers.
85
+ const withReader = readerWidth > 0 && underShortHeaders(roomBeside(figureColumns, 2, timeWidth + readerWidth)) >= minEventWidth;
86
+ const times = withReader ? 2 : 1;
87
+ const timesWidth = withReader ? timeWidth + readerWidth : timeWidth;
88
+ // The names come first, as in every narrow table: where three figure columns leave "GDP Growt…", PRIOR goes, and
89
+ // in a narrower pane still the forecast; the table says which it left out. The event's detail has all three.
90
+ const kept = keptFigureColumns(figureColumns, (columns) => underShortHeaders(roomBeside(columns, times, timesWidth)), longestName, minEventWidth,
91
+ note);
92
+ // IMPACT and COUNTRY in words while event names keep room to read; the
93
+ // short labels otherwise, with the word on hover where there is one.
94
+ const spelled = roomBeside(kept, times, timesWidth)(spelledImpactWidth, spelledCountryWidth) >= SPELLED_HEADER_MIN_EVENT_WIDTH;
95
+ const impactColumn = spelled
96
+ ? { label: SPELLED_IMPACT, width: spelledImpactWidth }
97
+ : { label: "IMP", width: 4, title: "Impact" };
98
+ const countryColumn = spelled
99
+ ? { label: SPELLED_COUNTRY, width: spelledCountryWidth }
100
+ : { label: "CTY", width: Math.max(3, codeWidth), title: "Country" };
101
+ const eventRoom = (columns: readonly EconCalendarColumn[]) =>
102
+ roomBeside(columns, times, timesWidth)(tableColumnWidth(impactColumn), tableColumnWidth(countryColumn));
103
+ const leading = (eventWidth: number): EconCalendarColumn[] => [
104
+ { id: "time", label: timeLabelText, width: timeWidth, align: "left" },
105
+ ...withReader ? [{ id: "readerTime" as const, label: readerLabel!, width: readerWidth, align: "left" as const, title: readerZone! }] : [],
106
+ ...showImpact ? [{ id: "impact" as const, ...impactColumn, align: "left" as const }] : [],
107
+ ...showCountry ? [{ id: "country" as const, ...countryColumn, align: "left" as const }] : [],
108
+ // The names take any room the pane has past these widths too: the desktop and the web otherwise spread it over
109
+ // every column, figures among them, while the names stay cut.
110
+ { id: "event", label: "EVENT", width: eventWidth, align: "left", flexGrow: 1 },
111
+ ];
112
+ return { kept, eventRoom, leading };
113
+ };
114
+
115
+ const figureColumns = figureColumnsFor(actualNote);
116
+ const longestName = longestEventName(events, showCountry);
117
+ const shown = layout(figureColumns, longestName, actualNote);
118
+ // Then the names have what a long figure weeks out took, up to the longest of them: the figure is cut, not every name.
119
+ const figures = figuresBesideNames(shown.kept, shown.eventRoom, longestName, minEventWidth, actualNote);
120
+ const leading = shown.leading(Math.max(minEventWidth, shown.eventRoom(figures)));
121
+ // Export CSV writes the columns it always did, decided at the figures' own widths and the names as the source
122
+ // writes them: a row awaiting its figure, which widens ACT in the table, never takes the reader's clock from the file.
123
+ const filedFigures = figureColumnsFor(0);
124
+ const filed = layout(filedFigures, longestEventName(events), 0);
125
+ return {
126
+ columns: markHiddenTableColumns([...leading, ...figureColumns], [...leading, ...figures]),
127
+ exportColumns: [...filed.leading(Math.max(minEventWidth, filed.eventRoom(filed.kept))), ...filedFigures],
128
+ // Where those columns keep every figure, the file follows the order the reader left the table's columns in,
129
+ // as the table's own export does; where they leave one out, it writes the pane's own order.
130
+ exportInReaderOrder: filed.kept.length === filedFigures.length,
131
+ };
132
+ }