gloomberb 0.19.4 → 0.19.6

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 (321) hide show
  1. package/package.json +3 -1
  2. package/patches/@opentui%2Fcore@0.3.2.patch +86 -25
  3. package/src/api-client/equity-screener.ts +23 -0
  4. package/src/app/pane-runtime/index.tsx +2 -0
  5. package/src/app/pane-runtime/plugin-bindings.ts +10 -1
  6. package/src/app.tsx +63 -16
  7. package/src/cli/commands/command-utils.ts +4 -0
  8. package/src/cli/commands/market.ts +264 -33
  9. package/src/cli/commands/search.ts +22 -4
  10. package/src/cli/commands/ticker.ts +84 -39
  11. package/src/cli/currency-name-hint.ts +60 -0
  12. package/src/cli/glossary.ts +3 -3
  13. package/src/cli/history-rows.ts +18 -1
  14. package/src/cli/known-gaps.ts +25 -2
  15. package/src/cli/listing-arg.ts +12 -0
  16. package/src/cli/not-a-ticker.ts +5 -3
  17. package/src/cli/pane-functions/capabilities.ts +2 -0
  18. package/src/cli/pane-functions/catalog.ts +31 -5
  19. package/src/cli/pane-functions/function-help.ts +8 -5
  20. package/src/cli/pane-functions/headless.ts +11 -6
  21. package/src/cli/pane-functions/market-session.ts +6 -7
  22. package/src/cli/pane-functions/resolver.ts +75 -2
  23. package/src/cli/quote-answer.ts +9 -0
  24. package/src/cli/series-search.ts +4 -5
  25. package/src/cli/symbol-list.ts +54 -2
  26. package/src/cli/symbol-rows.ts +14 -2
  27. package/src/cli/ticker-resolution.ts +89 -20
  28. package/src/components/chart/composite/axis-overlays.tsx +60 -27
  29. package/src/components/chart/composite/composite-chart.tsx +118 -63
  30. package/src/components/chart/composite/cursor-source.ts +111 -0
  31. package/src/components/chart/composite/format.ts +168 -6
  32. package/src/components/chart/composite/legend.tsx +8 -4
  33. package/src/components/chart/composite/panel-bitmap.ts +28 -2
  34. package/src/components/chart/composite/panel-labels.ts +20 -1
  35. package/src/components/chart/composite/panel-surface.tsx +201 -92
  36. package/src/components/chart/composite/price-axis-labels.tsx +92 -46
  37. package/src/components/chart/composite/price-series.ts +31 -8
  38. package/src/components/chart/composite/scene.ts +154 -59
  39. package/src/components/chart/composite/series-axis-tags.tsx +4 -2
  40. package/src/components/chart/composite/time-axis.ts +30 -7
  41. package/src/components/chart/composite/time-scale.ts +211 -56
  42. package/src/components/chart/composite/types.ts +11 -1
  43. package/src/components/chart/composite/use-composite-chart-keyboard.ts +32 -12
  44. package/src/components/chart/curve/curve-surface.tsx +5 -2
  45. package/src/components/chart/curve/model.ts +4 -1
  46. package/src/components/chart/native/use-bitmap-metrics.ts +81 -0
  47. package/src/components/chart/static/series.ts +3 -0
  48. package/src/components/command-bar/commands/collection-list.ts +81 -0
  49. package/src/components/command-bar/commands/direct/index.ts +6 -0
  50. package/src/components/command-bar/commands/registry.ts +8 -0
  51. package/src/components/command-bar/layout-items/current-layout.ts +22 -1
  52. package/src/components/command-bar/layout-items/focused-pane.ts +22 -1
  53. package/src/components/command-bar/pane-templates/items.ts +19 -3
  54. package/src/components/command-bar/pane-templates/workflow.ts +5 -0
  55. package/src/components/command-bar/routes/root/results.ts +23 -3
  56. package/src/components/command-bar/routes/root/selection.ts +4 -2
  57. package/src/components/command-bar/routes/root/shortcut-feedback.ts +1 -1
  58. package/src/components/command-bar/routes/root/shortcut-items.ts +3 -4
  59. package/src/components/command-bar/routes/root/shortcuts.ts +58 -14
  60. package/src/components/command-bar/routes/root/ticker-first.ts +32 -0
  61. package/src/components/command-bar/surface/environment.ts +2 -0
  62. package/src/components/command-bar/view-model.ts +7 -0
  63. package/src/components/command-bar/workflow/ops.ts +2 -1
  64. package/src/components/command-bar/workflow/tickers.ts +20 -0
  65. package/src/components/layout/shell/active-drag.ts +38 -7
  66. package/src/components/layout/shell/drag/magnets.ts +106 -0
  67. package/src/components/layout/shell/menu.ts +15 -1
  68. package/src/components/layout/shell/pane/actions.ts +4 -0
  69. package/src/components/layout/shell/ticker-link-menu.ts +12 -3
  70. package/src/components/layout/status-bar.tsx +20 -0
  71. package/src/components/layout/window-controls.tsx +96 -35
  72. package/src/components/layout/window-fullscreen.ts +20 -0
  73. package/src/components/onboarding/onboarding-keyboard.ts +5 -1
  74. package/src/components/onboarding/onboarding-wizard.tsx +15 -4
  75. package/src/components/onboarding/portfolio-step/positions-panel.tsx +8 -5
  76. package/src/components/onboarding/use-onboarding-progress.ts +20 -1
  77. package/src/components/price-sparkline/view.tsx +14 -6
  78. package/src/components/quote-flash.ts +36 -32
  79. package/src/components/ticker/badge/index.tsx +8 -4
  80. package/src/components/ticker/badge/list.tsx +23 -7
  81. package/src/components/ui/column-grid.tsx +8 -2
  82. package/src/components/ui/data-table/opentui/model.ts +4 -1
  83. package/src/components/ui/tabs.tsx +5 -2
  84. package/src/core/state/app/layout.ts +18 -3
  85. package/src/core/state/app/state.ts +2 -0
  86. package/src/core/state/app/types.ts +5 -0
  87. package/src/data/config/layout.ts +3 -0
  88. package/src/data/config/store/normalize.ts +39 -4
  89. package/src/i18n/es.ts +10 -0
  90. package/src/i18n/ja.ts +10 -0
  91. package/src/i18n/ko.ts +10 -0
  92. package/src/i18n/zh-cn.ts +10 -0
  93. package/src/i18n/zh-tw.ts +10 -0
  94. package/src/layout/pane-manager/floating-placement.ts +7 -4
  95. package/src/layout/pane-manager/floating.ts +5 -2
  96. package/src/market-data/bond-funds.ts +19 -0
  97. package/src/market-data/coordinator/events.ts +17 -1
  98. package/src/market-data/frame-scheduler.ts +47 -10
  99. package/src/market-data/frame-wake.ts +74 -0
  100. package/src/market-data/futures-board.ts +7 -6
  101. package/src/market-data/futures-contract.ts +14 -3
  102. package/src/market-data/hooks.tsx +12 -3
  103. package/src/market-data/market/freshness.ts +18 -0
  104. package/src/market-data/market/status.ts +15 -2
  105. package/src/market-data/performance.ts +78 -9
  106. package/src/market-data/request-types.ts +6 -3
  107. package/src/plugins/builtin/alerts/cli.ts +2 -1
  108. package/src/plugins/builtin/analytics/risk-evidence.ts +1 -0
  109. package/src/plugins/builtin/attention/evidence.ts +1 -1
  110. package/src/plugins/builtin/awards/client.ts +1 -1
  111. package/src/plugins/builtin/awards/evidence.ts +1 -1
  112. package/src/plugins/builtin/awards/pane.tsx +2 -1
  113. package/src/plugins/builtin/bond-calculator/headless.ts +2 -1
  114. package/src/plugins/builtin/bond-calculator/index.tsx +1 -1
  115. package/src/plugins/builtin/bond-calculator/math.ts +1 -1
  116. package/src/plugins/builtin/bond-calculator/model.ts +14 -5
  117. package/src/plugins/builtin/bond-calculator/pane.tsx +1 -1
  118. package/src/plugins/builtin/broker-manager/footer.ts +3 -2
  119. package/src/plugins/builtin/broker-manager/index.tsx +2 -1
  120. package/src/plugins/builtin/broker-manager/keyboard.ts +2 -1
  121. package/src/plugins/builtin/buildout/cells.tsx +25 -45
  122. package/src/plugins/builtin/buildout/detail/company.tsx +3 -3
  123. package/src/plugins/builtin/buildout/detail/index.tsx +1 -1
  124. package/src/plugins/builtin/buildout/detail/intel.tsx +4 -7
  125. package/src/plugins/builtin/buildout/detail/site.tsx +4 -4
  126. package/src/plugins/builtin/buildout/detail/ui.tsx +39 -38
  127. package/src/plugins/builtin/buildout/format.ts +23 -1
  128. package/src/plugins/builtin/buildout/model/types.ts +1 -0
  129. package/src/plugins/builtin/buildout/pane/index.tsx +2 -8
  130. package/src/plugins/builtin/buildout/table-model.ts +12 -4
  131. package/src/plugins/builtin/catalysts/evidence.ts +1 -1
  132. package/src/plugins/builtin/catalysts/pane.tsx +2 -1
  133. package/src/plugins/builtin/cds/headless.ts +1 -0
  134. package/src/plugins/builtin/cds/index.tsx +1 -1
  135. package/src/plugins/builtin/chart-composer/headless.ts +40 -1
  136. package/src/plugins/builtin/cloud/plugin.tsx +2 -0
  137. package/src/plugins/builtin/cloud/upgrade-status-widget.tsx +28 -3
  138. package/src/plugins/builtin/cloud-tweets/table.tsx +3 -2
  139. package/src/plugins/builtin/comment-letters/client.ts +2 -1
  140. package/src/plugins/builtin/company-kpis/client.ts +1 -1
  141. package/src/plugins/builtin/company-kpis/pane.tsx +2 -1
  142. package/src/plugins/builtin/company-kpis/screenshot-evidence.ts +3 -2
  143. package/src/plugins/builtin/correlation/headless.ts +3 -2
  144. package/src/plugins/builtin/cot/headless.ts +9 -3
  145. package/src/plugins/builtin/cot/model.ts +44 -3
  146. package/src/plugins/builtin/credit-documents/client.ts +1 -1
  147. package/src/plugins/builtin/credit-documents/evidence.ts +1 -1
  148. package/src/plugins/builtin/credit-documents/pane.tsx +2 -1
  149. package/src/plugins/builtin/crypto-board/pane.tsx +5 -4
  150. package/src/plugins/builtin/debt-maturities/headless.ts +11 -2
  151. package/src/plugins/builtin/debt-maturities/model.ts +66 -0
  152. package/src/plugins/builtin/debt-maturities/pane.tsx +23 -4
  153. package/src/plugins/builtin/earnings-calls/pane.tsx +1 -1
  154. package/src/plugins/builtin/earnings-ripple/index.tsx +6 -1
  155. package/src/plugins/builtin/earnings-ripple/pane.tsx +1 -1
  156. package/src/plugins/builtin/econ/calendar-model.ts +30 -6
  157. package/src/plugins/builtin/econ/fred-catalog.ts +5 -5
  158. package/src/plugins/builtin/econ/print-watch.ts +3 -1
  159. package/src/plugins/builtin/equity-screener/client.ts +1 -1
  160. package/src/plugins/builtin/equity-screener/criterion-editor.tsx +4 -16
  161. package/src/plugins/builtin/equity-screener/headless.ts +4 -2
  162. package/src/plugins/builtin/equity-screener/ideas.ts +67 -3
  163. package/src/plugins/builtin/equity-screener/model.ts +180 -12
  164. package/src/plugins/builtin/equity-screener/pane.tsx +52 -12
  165. package/src/plugins/builtin/equity-screener/screen-check.ts +7 -4
  166. package/src/plugins/builtin/equity-screener/watchlist.ts +33 -0
  167. package/src/plugins/builtin/futures/series.ts +16 -1
  168. package/src/plugins/builtin/futures-curve/client.ts +19 -0
  169. package/src/plugins/builtin/futures-curve/headless.ts +52 -13
  170. package/src/plugins/builtin/futures-curve/index.tsx +1 -1
  171. package/src/plugins/builtin/futures-curve/model.ts +77 -6
  172. package/src/plugins/builtin/futures-curve/pane.tsx +19 -3
  173. package/src/plugins/builtin/fx-matrix/headless.ts +4 -2
  174. package/src/plugins/builtin/fx-matrix/index.tsx +37 -3
  175. package/src/plugins/builtin/fx-matrix/pairs.ts +15 -0
  176. package/src/plugins/builtin/gpu/headless.ts +2 -1
  177. package/src/plugins/builtin/help/function-card.tsx +2 -1
  178. package/src/plugins/builtin/help/index.tsx +2 -1
  179. package/src/plugins/builtin/insider/display.ts +45 -6
  180. package/src/plugins/builtin/ipo-calendar/model.ts +2 -0
  181. package/src/plugins/builtin/iv-history/client.ts +2 -1
  182. package/src/plugins/builtin/iv-history/headless.ts +2 -1
  183. package/src/plugins/builtin/jobs/pages.ts +4 -4
  184. package/src/plugins/builtin/kelly-sizer/headless.ts +2 -1
  185. package/src/plugins/builtin/macro-day/client.ts +41 -0
  186. package/src/plugins/builtin/macro-day/headless.ts +19 -9
  187. package/src/plugins/builtin/macro-day/model.ts +3 -1
  188. package/src/plugins/builtin/market-heatmap/index.tsx +2 -1
  189. package/src/plugins/builtin/market-movers/index.tsx +4 -3
  190. package/src/plugins/builtin/members/client.ts +1 -1
  191. package/src/plugins/builtin/mna/distress/client.ts +1 -0
  192. package/src/plugins/builtin/mna/distress/headless.ts +1 -0
  193. package/src/plugins/builtin/mna/pane.tsx +4 -1
  194. package/src/plugins/builtin/options/market-reference.ts +1 -1
  195. package/src/plugins/builtin/options/open-interest-as-of.ts +3 -1
  196. package/src/plugins/builtin/options/view.tsx +2 -1
  197. package/src/plugins/builtin/options-calculator/evidence.ts +1 -1
  198. package/src/plugins/builtin/options-scenario/csp-screen-pane.tsx +1 -1
  199. package/src/plugins/builtin/options-scenario/csp-screen.ts +8 -4
  200. package/src/plugins/builtin/options-scenario/csp.ts +28 -9
  201. package/src/plugins/builtin/options-scenario/evidence.ts +5 -4
  202. package/src/plugins/builtin/options-scenario/pane.tsx +2 -1
  203. package/src/plugins/builtin/perps/client.ts +1 -1
  204. package/src/plugins/builtin/perps/pane.tsx +3 -1
  205. package/src/plugins/builtin/portfolio-list/cli/bulk-symbols.ts +17 -0
  206. package/src/plugins/builtin/portfolio-list/cli/portfolio-command.ts +2 -1
  207. package/src/plugins/builtin/portfolio-list/cli/watchlist-command.ts +4 -2
  208. package/src/plugins/builtin/portfolio-list/pane/index.tsx +7 -3
  209. package/src/plugins/builtin/portfolio-list/use-throttled-memo.ts +10 -19
  210. package/src/plugins/builtin/rate-path/headless.ts +24 -10
  211. package/src/plugins/builtin/research/analyst-model.ts +1 -0
  212. package/src/plugins/builtin/research/equity-diagnostic-pane.tsx +2 -1
  213. package/src/plugins/builtin/research/event-model.ts +10 -3
  214. package/src/plugins/builtin/research/events-headless.ts +20 -2
  215. package/src/plugins/builtin/research/index.tsx +1 -0
  216. package/src/plugins/builtin/research/relative-valuation-currency.ts +1 -1
  217. package/src/plugins/builtin/research/relative-valuation-peers.ts +2 -1
  218. package/src/plugins/builtin/research-search/command-bar-search.ts +3 -1
  219. package/src/plugins/builtin/research-search/snippet.ts +1 -0
  220. package/src/plugins/builtin/revenue-breakdown/client.ts +3 -2
  221. package/src/plugins/builtin/seasonality/headless.ts +2 -1
  222. package/src/plugins/builtin/sec/command-bar-search.ts +3 -2
  223. package/src/plugins/builtin/sec/fund-facts.ts +17 -1
  224. package/src/plugins/builtin/sec/index.tsx +8 -5
  225. package/src/plugins/builtin/sec/row-summaries.ts +28 -12
  226. package/src/plugins/builtin/shared/members-menu.tsx +103 -38
  227. package/src/plugins/builtin/short-interest/publications-model.ts +22 -1
  228. package/src/plugins/builtin/short-interest/publications-pane.tsx +13 -4
  229. package/src/plugins/builtin/short-interest/watch-client.ts +2 -1
  230. package/src/plugins/builtin/short-interest/watch-model.ts +1 -1
  231. package/src/plugins/builtin/social-mentions/client.ts +2 -1
  232. package/src/plugins/builtin/supply-chain/client.ts +1 -1
  233. package/src/plugins/builtin/supply-chain/evidence.ts +1 -1
  234. package/src/plugins/builtin/supply-chain/graph-pane.tsx +2 -1
  235. package/src/plugins/builtin/supply-chain/pane.tsx +2 -1
  236. package/src/plugins/builtin/ticker-detail/adr-pair/headless.ts +1 -1
  237. package/src/plugins/builtin/ticker-detail/adr-pair/model.ts +24 -4
  238. package/src/plugins/builtin/ticker-detail/adr-pair/tab.tsx +1 -1
  239. package/src/plugins/builtin/time-sales/client.ts +1 -0
  240. package/src/plugins/builtin/time-sales/pane.tsx +3 -2
  241. package/src/plugins/builtin/trace-bonds/client.ts +7 -4
  242. package/src/plugins/builtin/trace-bonds/index.tsx +1 -1
  243. package/src/plugins/builtin/vol-surface/client.ts +2 -1
  244. package/src/plugins/builtin/volatility/client.ts +6 -1
  245. package/src/plugins/builtin/volatility/headless.ts +0 -1
  246. package/src/plugins/builtin/yield-curve/curves.ts +15 -0
  247. package/src/plugins/builtin/yield-curve/headless.ts +9 -2
  248. package/src/plugins/builtin/yield-curve/index.tsx +5 -8
  249. package/src/plugins/host-modules.ts +22 -3
  250. package/src/plugins/host-smoke.ts +6 -3
  251. package/src/portfolio/collection-name.ts +19 -0
  252. package/src/portfolio/column-values.ts +76 -10
  253. package/src/renderers/browser/http-proxy-transport.ts +78 -8
  254. package/src/renderers/cloudflare/http-proxy.ts +13 -2
  255. package/src/renderers/cloudflare/proxy-session.ts +47 -24
  256. package/src/renderers/cloudflare/worker.ts +15 -2
  257. package/src/renderers/desktop/geometry.ts +279 -0
  258. package/src/renderers/desktop/screen-setup.ts +246 -0
  259. package/src/renderers/desktop/sequential-window-host.ts +179 -0
  260. package/src/renderers/desktop/test-utils.ts +71 -0
  261. package/src/renderers/desktop/window-controller.ts +433 -0
  262. package/src/renderers/desktop/window-host.ts +70 -0
  263. package/src/renderers/desktop/window-layouts.ts +630 -0
  264. package/src/renderers/dom/data-frames.ts +15 -4
  265. package/src/renderers/dom/host/box.tsx +204 -176
  266. package/src/renderers/dom/host/style.ts +49 -20
  267. package/src/renderers/dom/host/text.tsx +3 -2
  268. package/src/renderers/electrobun/bun/application-menu/click.ts +1 -0
  269. package/src/renderers/electrobun/bun/application-menu/index.ts +4 -1
  270. package/src/renderers/electrobun/bun/desktop/backend-requests.ts +19 -8
  271. package/src/renderers/electrobun/bun/desktop/backend.ts +322 -19
  272. package/src/renderers/electrobun/bun/desktop/detached-windows.ts +83 -61
  273. package/src/renderers/electrobun/bun/desktop/host-requests.ts +29 -15
  274. package/src/renderers/electrobun/bun/desktop/initialization.ts +30 -11
  275. package/src/renderers/electrobun/bun/desktop/relaunch.ts +9 -1
  276. package/src/renderers/electrobun/bun/desktop/screen-setup-file.ts +55 -0
  277. package/src/renderers/electrobun/bun/desktop/state-broadcaster.ts +44 -8
  278. package/src/renderers/electrobun/bun/desktop/windows-script.ts +9 -6
  279. package/src/renderers/electrobun/bun/desktop/workspace/index.ts +298 -97
  280. package/src/renderers/electrobun/bun/desktop/workspace/requests.ts +44 -6
  281. package/src/renderers/electrobun/bun/index.ts +4 -97
  282. package/src/renderers/electrobun/bun/window/electrobun-window-host.ts +306 -0
  283. package/src/renderers/electrobun/bun/window/focus.ts +0 -25
  284. package/src/renderers/electrobun/bun/window/remembered-frame.ts +4 -82
  285. package/src/renderers/electrobun/bun/window/windows-native.ts +26 -1
  286. package/src/renderers/electrobun/shared/protocol.ts +50 -2
  287. package/src/renderers/electrobun/view/backend-rpc.ts +15 -0
  288. package/src/renderers/electrobun/view/desktop/window/bridge.ts +63 -3
  289. package/src/renderers/electrobun/view/main.tsx +13 -7
  290. package/src/renderers/electrobun/view/ui-host.tsx +7 -0
  291. package/src/renderers/electrobun/view/window-fullscreen.ts +10 -3
  292. package/src/series/fred-argument.ts +17 -0
  293. package/src/sources/provider-router/financial-routes.ts +7 -1
  294. package/src/sources/provider-router/index.ts +7 -1
  295. package/src/state/app/context/index.tsx +16 -2
  296. package/src/state/desktop-windows.ts +63 -0
  297. package/src/sync/other-window-tabs.ts +62 -0
  298. package/src/tickers/company-name-listing.ts +23 -3
  299. package/src/tickers/listing-fate.ts +147 -1
  300. package/src/tickers/terminal-codes.ts +5 -0
  301. package/src/time-series/price-units.ts +11 -0
  302. package/src/time-series/types.ts +6 -0
  303. package/src/types/config.ts +10 -1
  304. package/src/types/desktop-window.ts +71 -2
  305. package/src/types/financials.ts +4 -0
  306. package/src/types/headless.ts +19 -0
  307. package/src/types/plugin.ts +6 -0
  308. package/src/ui/host.tsx +2 -0
  309. package/src/ui/index.tsx +14 -13
  310. package/src/ui/same-props.ts +58 -0
  311. package/src/utils/cli-output.ts +33 -4
  312. package/src/utils/currency-names.ts +20 -0
  313. package/src/utils/currency-pair.ts +6 -0
  314. package/src/utils/exchange-rate-snapshot.ts +20 -2
  315. package/src/utils/format.ts +7 -2
  316. package/src/utils/futures-generic.ts +12 -0
  317. package/src/utils/fx-market-hours.ts +43 -0
  318. package/src/utils/http-proxy-upstream.ts +6 -2
  319. package/src/utils/plugin-proxy-hosts.json +0 -4
  320. package/src/utils/plugin-proxy-hosts.ts +22 -0
  321. package/src/utils/sec-filings.ts +7 -1
@@ -1,6 +1,8 @@
1
1
  import { logFailure } from "../utils/log-failure";
2
2
  import type { DataProvider } from "../types/data-provider";
3
- import type { Quote } from "../types/financials";
3
+ import type { CompanyProfile, ListingDelisting, PricePoint, Quote } from "../types/financials";
4
+ import { savedCopyAt } from "../data/saved-copies";
5
+ import { sameCompany } from "./company-name";
4
6
  import type { TickerChanges } from "../types/ticker-changes";
5
7
  import {
6
8
  describeFormerIssuer,
@@ -77,6 +79,150 @@ export function noLongerTradingNote(label: string, quote: Quote, now = Date.now(
77
79
  : `${label}: no longer trading since ${date} (last price ${price})`;
78
80
  }
79
81
 
82
+ // A listing with no quote whose newest bar is this old has not traded since; a newer one is a quiet month.
83
+ const NO_QUOTE_ENDED_AFTER_MS = 30 * 24 * 60 * 60_000;
84
+
85
+ /**
86
+ * When a listing the service has no quote for last traded, and whether the
87
+ * service says it no longer trades. `recorded`: its history carries the
88
+ * service's delisting record, whose last day wins over the bars. Otherwise
89
+ * only its newest bar, over 30 days old, says it: a retired line and a thin
90
+ * one that has not traded in a month look alike, so that says no more than
91
+ * "no trades since".
92
+ */
93
+ export interface NoQuoteLastTrade {
94
+ date: string;
95
+ recorded: boolean;
96
+ }
97
+
98
+ /**
99
+ * When a listing the service has no quote for last traded (`NoQuoteLastTrade`).
100
+ * Null for one that traded within the month, has no bars, or whose bars are a
101
+ * copy saved earlier because the refresh failed: the age of a saved copy's
102
+ * bars says when it was saved, not that the listing stopped.
103
+ */
104
+ export function noQuoteLastTraded(
105
+ history: { points: readonly Pick<PricePoint, "date">[]; delisting?: ListingDelisting; savedCopyBehind?: true },
106
+ now = Date.now(),
107
+ ): NoQuoteLastTrade | null {
108
+ if (history.delisting) return { date: history.delisting.lastTradeDate, recorded: true };
109
+ if (history.savedCopyBehind || savedCopyAt(history) != null) return null;
110
+ const newest = Math.max(...history.points.map((point) => new Date(point.date).getTime()).filter(Number.isFinite));
111
+ return Number.isFinite(newest) && now - newest > NO_QUOTE_ENDED_AFTER_MS
112
+ ? { date: new Date(newest).toISOString().slice(0, 10), recorded: false }
113
+ : null;
114
+ }
115
+
116
+ /** "FLAT last traded 2020-06-03; no longer listed": what `quote`, `ticker`, `history` and `search` say of such a listing. */
117
+ export function noLongerListedNote(symbol: string, lastTraded: string): string {
118
+ return `${symbol} last traded ${lastTraded}; no longer listed`;
119
+ }
120
+
121
+ /**
122
+ * What a command says of a listing with no quote that has not traded in over
123
+ * a month: "no longer listed" only on the service's record of it, else "XYZ:
124
+ * no trades since 2026-08-14".
125
+ */
126
+ export function noQuoteLastTradeNote(symbol: string, lastTrade: NoQuoteLastTrade): string {
127
+ return lastTrade.recorded ? noLongerListedNote(symbol, lastTrade.date) : `${symbol}: no trades since ${lastTrade.date}`;
128
+ }
129
+
130
+ /** What says whether a profile served under a stopped listing's symbol is its own (`otherListingProfile`). */
131
+ export interface ListingProfileEvidence {
132
+ /** The listing asked for is a US line: a bare symbol, read on its US line, or one on a US venue. */
133
+ usLine: boolean;
134
+ /** The names on record for the symbol's own issuer: its saved listing's, its ticker change's, a former issuer's. */
135
+ issuerNames?: readonly (string | null | undefined)[];
136
+ }
137
+
138
+ const US_COUNTRY = /^(?:us|usa|united states(?: of america)?)$/i;
139
+
140
+ /**
141
+ * The name of the other listing a profile served under a stopped listing's
142
+ * symbol is of (STPP: a UCITS fund domiciled abroad took the symbol after the
143
+ * iPath steepener ended), only on evidence: it names a company none of the
144
+ * names on record for the symbol's issuer are, or, with none of those
145
+ * matching it, its issuer is domiciled outside the US while the listing asked
146
+ * for is a US line. Otherwise the profile is the listing's own (a stopped
147
+ * company keeps its profile), and the answer is null. A profile that names no
148
+ * one, shown to be abroad, is named by its country.
149
+ */
150
+ export function otherListingProfile(
151
+ profile: Pick<CompanyProfile, "name" | "country"> | null | undefined,
152
+ evidence: ListingProfileEvidence,
153
+ ): string | null {
154
+ const named = profile?.name?.trim() || null;
155
+ const country = profile?.country?.trim() || null;
156
+ const issuers = (evidence.issuerNames ?? []).flatMap((name) => name?.trim() ? [name.trim()] : []);
157
+ const ownName = !!named && issuers.some((issuer) => sameCompany(issuer, named));
158
+ const otherIssuer = !!named && issuers.length > 0 && !ownName;
159
+ const abroad = evidence.usLine && !!country && !US_COUNTRY.test(country) && !ownName;
160
+ if (!otherIssuer && !abroad) return null;
161
+ return named ?? `a company domiciled in ${country}`;
162
+ }
163
+
164
+ /** "The profile served under STPP is another listing's (...), not shown.": the line for `otherListingProfile`'s answer. */
165
+ export function otherListingProfileNote(symbol: string, other: string): string {
166
+ return `The profile served under ${symbol} is another listing's (${other}), not shown.`;
167
+ }
168
+
169
+ /**
170
+ * The US venue to read a bare symbol's own US line on, where a source can
171
+ * otherwise answer it with a listing abroad: the one its listing metadata
172
+ * names, else NYSE. The US exchanges share one symbol, and the service reads
173
+ * any of them as the symbol's one US line (STPP's ended on BATS in 2020).
174
+ */
175
+ export async function usVenueOf(
176
+ symbol: string,
177
+ dataProvider: Pick<DataProvider, "getQuoteMetadata">,
178
+ ): Promise<string> {
179
+ const venue = (await dataProvider.getQuoteMetadata?.(symbol, "")
180
+ .catch(logFailure("tickers-listing-fate", "Read a stopped listing's venue failed", null)))?.listingExchangeName;
181
+ return venue && isUsListingExchange(venue) ? venue : "NYSE";
182
+ }
183
+
184
+ /** When a listing with no quote last traded (`NoQuoteLastTrade`), and its last close then. */
185
+ export interface NoQuoteEnding extends NoQuoteLastTrade {
186
+ lastClose: number | null;
187
+ }
188
+
189
+ /**
190
+ * `noQuoteLastTraded` for a listing a command has no quote for, from its
191
+ * latest month of daily bars (a listing that stopped answers its last ones),
192
+ * with its last close: a bare symbol's on the US venue its metadata names,
193
+ * whose bars a source can otherwise answer with a listing abroad's. Fails
194
+ * soft: a source that does not answer says nothing.
195
+ */
196
+ export async function loadNoQuoteEnding(
197
+ listing: { symbol: string; exchange?: string | null },
198
+ dataProvider: Pick<DataProvider, "getPriceHistory" | "getPriceHistoryWithMetadata" | "getQuoteMetadata">,
199
+ now = Date.now(),
200
+ ): Promise<NoQuoteEnding | null> {
201
+ try {
202
+ const exchange = listing.exchange || await usVenueOf(listing.symbol, dataProvider);
203
+ // Asked afresh: a copy saved for the bare symbol (a listing abroad's bars) can otherwise answer for the venue.
204
+ const history = dataProvider.getPriceHistoryWithMetadata
205
+ ? await dataProvider.getPriceHistoryWithMetadata(listing.symbol, exchange, "1M", { cacheMode: "refresh" })
206
+ : { points: await dataProvider.getPriceHistory(listing.symbol, exchange, "1M", { cacheMode: "refresh" }) };
207
+ const lastTrade = noQuoteLastTraded(history, now);
208
+ const close = history.points.at(-1)?.close;
209
+ return lastTrade ? { ...lastTrade, lastClose: typeof close === "number" && Number.isFinite(close) ? close : null } : null;
210
+ } catch (error) {
211
+ logFailure("tickers-listing-fate", "Could not read a listing's last bars")(error);
212
+ return null;
213
+ }
214
+ }
215
+
216
+ /** `loadNoQuoteEnding` without the close: what `quote`, `ticker` and `history` say of a listing with no quote. */
217
+ export async function loadNoQuoteLastTraded(
218
+ listing: { symbol: string; exchange?: string | null },
219
+ dataProvider: Pick<DataProvider, "getPriceHistory" | "getPriceHistoryWithMetadata" | "getQuoteMetadata">,
220
+ now = Date.now(),
221
+ ): Promise<NoQuoteLastTrade | null> {
222
+ const ending = await loadNoQuoteEnding(listing, dataProvider, now);
223
+ return ending ? { date: ending.date, recorded: ending.recorded } : null;
224
+ }
225
+
80
226
  /**
81
227
  * What became of a symbol, from what `quote` reads it by: the listing's own
82
228
  * quote, which says when it stopped trading, and the symbol's ticker changes
@@ -383,6 +383,11 @@ const LEGAL_FORMS: ReadonlySet<string> = new Set([
383
383
  "GMBH", "KGAA", "BHD", "TBK", "PCL",
384
384
  ]);
385
385
 
386
+ /** Whether a word is a company's legal form (`INC`, `AG`, `PLC`), the last word of a name. */
387
+ export function isLegalForm(word: string): boolean {
388
+ return LEGAL_FORMS.has(word.toUpperCase());
389
+ }
390
+
386
391
  /** Two words, the second a company's legal form (`SAP SE`, `VOLVO AB`): a name to look up before reading it as a code. */
387
392
  export function endsInLegalForm(raw: string): boolean {
388
393
  const words = normalizeTyped(raw).split(" ");
@@ -125,6 +125,17 @@ export function perTonneUnit(unit: string): string {
125
125
  return isPerBarrelUnit(unit) ? unit.replace(/(\/\s*)\S.*$/, "$1tonne") : unit;
126
126
  }
127
127
 
128
+ /**
129
+ * A rate of one currency in another as reports and exports name it: `JPY /
130
+ * USD`, the chart's unit for USDJPY=X, is `JPY per USD`, as `history` says,
131
+ * and a currency future's `USD / CHF` is `USD per CHF`. Any other unit
132
+ * (`USD / barrel`, `USD`) is returned as it is.
133
+ */
134
+ export function currencyRateUnitText(unit: string): string {
135
+ const match = /^([A-Z]{3})\s*\/\s*([A-Z]{3})$/.exec(unit.trim());
136
+ return match ? `${match[1]} per ${match[2]}` : unit;
137
+ }
138
+
128
139
  /**
129
140
  * What a currency pair's price counts: the quote currency one unit of the
130
141
  * base buys, so EURUSD=X is USD / EUR and USDJPY=X JPY / USD. Null for a
@@ -210,6 +210,12 @@ export interface ResolvedSeries {
210
210
  * over an FX rate) prints at: the most its legs print, from two to four.
211
211
  */
212
212
  valueDecimals?: number;
213
+ /**
214
+ * The grid a price quoted in fractions of a point moves on (a Treasury
215
+ * future's half or quarter 32nd): its axis ticks fall on multiples of it,
216
+ * never on decimal steps that read 104-25.60. Unset for decimal prices.
217
+ */
218
+ tickGrid?: number;
213
219
  /** Volume basis established by the source instrument; omitted when unspecified. */
214
220
  volumeUnit?: "shares" | "contracts";
215
221
  nativeFrequency: SeriesPeriod;
@@ -869,6 +869,11 @@ export function normalizePaneLayout(
869
869
  resolveOrphanSymbol?: (instanceId: string) => string | null;
870
870
  /** Pins an orphaned follower on its last symbol; by default only its binding changes. */
871
871
  pinOrphan?: (instance: PaneInstanceConfig, symbol: string | null) => PaneInstanceConfig;
872
+ /**
873
+ * Panes outside this layout that a pane here may follow: on another
874
+ * desktop window's tab. A link to one is not orphaned.
875
+ */
876
+ externalSourceIds?: ReadonlySet<string>;
872
877
  },
873
878
  ): LayoutConfig {
874
879
  const fallbackSourceId = options?.defaultFollowSourceInstanceId ?? null;
@@ -898,7 +903,11 @@ export function normalizePaneLayout(
898
903
  const orphanPins = new Map<string, PaneInstanceConfig>();
899
904
 
900
905
  for (const instance of nextLayout.instances) {
901
- if (instance.binding?.kind === "follow" && !validInstanceIds.has(instance.binding.sourceInstanceId)) {
906
+ if (
907
+ instance.binding?.kind === "follow"
908
+ && !validInstanceIds.has(instance.binding.sourceInstanceId)
909
+ && !options?.externalSourceIds?.has(instance.binding.sourceInstanceId)
910
+ ) {
902
911
  // Structural helpers remove the source before the app can resolve its last ticker. Preserve
903
912
  // the dangling binding until the runtime normalizes again with a resolver.
904
913
  if (!options?.resolveOrphanSymbol) continue;
@@ -1,5 +1,5 @@
1
1
  import type { PaneRuntimeState } from "../core/state/app/state";
2
- import type { AppConfig } from "./config";
2
+ import type { AppConfig, SavedLayout } from "./config";
3
3
 
4
4
  export interface DesktopSharedStateSnapshot {
5
5
  config: AppConfig;
@@ -12,6 +12,66 @@ export interface DesktopSharedStateSnapshot {
12
12
  brokerSyncErrors?: Record<string, string>;
13
13
  mainStateRevision?: number;
14
14
  layoutChanged?: boolean;
15
+ /**
16
+ * The tickers of panes in other windows that panes in this one follow, by
17
+ * pane id: a link keeps working when the pane it follows moved away.
18
+ */
19
+ linkedTickers?: Record<string, string>;
20
+ /**
21
+ * The number of a state the desktop process sent. A window's next sync
22
+ * names the one it last took, so only what it changed since counts.
23
+ */
24
+ stateSeq?: number;
25
+ }
26
+
27
+ /** A full desktop window, as the others list it to move a tab or a pane there. */
28
+ export interface DesktopWindowInfo {
29
+ id: string;
30
+ /** Its place in the order windows opened in: 1 for the main window. */
31
+ number: number;
32
+ /** The tab it shows. */
33
+ activeLayoutName: string;
34
+ tabCount: number;
35
+ }
36
+
37
+ /**
38
+ * A tab another full window holds, at its place among all the tabs. The main
39
+ * window's cloud sync pushes and pulls every window's tabs, not only its own.
40
+ */
41
+ export interface OtherWindowTab {
42
+ at: number;
43
+ tab: SavedLayout;
44
+ }
45
+
46
+ /** Where a tab or pane goes: one of the open windows, or a new one. */
47
+ export type DesktopWindowTarget = { windowId: string } | { newWindow: true };
48
+
49
+ /**
50
+ * The desktop app's full windows, for the window that holds this. Each has
51
+ * its own tabs; a tab or a pane can move to another, and focus can follow.
52
+ */
53
+ export interface DesktopWindowsBridge {
54
+ /** This window's id. */
55
+ readonly windowId: string;
56
+ /** Every full window, this one included, in the order they opened. */
57
+ list(): DesktopWindowInfo[];
58
+ subscribe(listener: () => void): () => void;
59
+ /** A new window on an empty tab of its own. */
60
+ openWindow(): Promise<void>;
61
+ /** Moves a tab of this window. Resolves false when it cannot go (this window's last tab, for the main window). */
62
+ moveLayout(layoutId: string, target: DesktopWindowTarget): Promise<boolean>;
63
+ movePane(paneId: string, target: DesktopWindowTarget): Promise<boolean>;
64
+ focusWindow(windowId: string): Promise<void>;
65
+ /** Brings forward the window showing a pane in another window, on the pane's tab, with the pane focused. */
66
+ focusPane(paneId: string): Promise<boolean>;
67
+ /** Asked by another window to focus one of this window's panes. */
68
+ subscribeFocusRequests(listener: (paneId: string) => void): () => void;
69
+ /**
70
+ * The tabs the other windows hold, for cloud sync; the same array until
71
+ * they change, which `subscribe` reports. Only the main window is sent
72
+ * them, and only while there is more than one window.
73
+ */
74
+ otherWindowTabs(): readonly OtherWindowTab[];
15
75
  }
16
76
 
17
77
  export interface DesktopDockPreviewState {
@@ -26,7 +86,16 @@ export interface DesktopThemePreviewState {
26
86
  export interface DesktopWindowBridge {
27
87
  kind: "main" | "detached";
28
88
  paneId?: string;
29
- syncMainState?(snapshot: DesktopSharedStateSnapshot): Promise<void>;
89
+ /**
90
+ * False in a full window other than the main one: it has its own tabs, but
91
+ * the app-wide work (cloud sync, the session, the Dock badge, deep links,
92
+ * remote control) stays with the main window.
93
+ */
94
+ primary?: boolean;
95
+ /** The full windows, where the shell has more than one. */
96
+ windows?: DesktopWindowsBridge;
97
+ /** `baseSeq` is the `stateSeq` of the last state this window took, or null when it built on its own last sync. */
98
+ syncMainState?(snapshot: DesktopSharedStateSnapshot, baseSeq?: number | null): Promise<void>;
30
99
  syncThemePreview?(preview: DesktopThemePreviewState): Promise<void>;
31
100
  replaceDetachedPaneState?(paneId: string, paneState: PaneRuntimeState): Promise<void>;
32
101
  popOutPane?(paneId: string): Promise<void>;
@@ -643,6 +643,10 @@ export interface DeclaredCash {
643
643
  }
644
644
 
645
645
  export interface CompanyProfile {
646
+ /** Who the profile is of, as the source names it beside its facts: another listing's name where one took the symbol. */
647
+ name?: string;
648
+ /** Where its issuer is domiciled, as the source gives it (NL, US). */
649
+ country?: string;
646
650
  description?: string;
647
651
  /**
648
652
  * Who published the description and where, when it is quoted from a
@@ -511,6 +511,12 @@ export interface HeadlessRowsResult extends HeadlessPaneResultBase {
511
511
  textRows?: HeadlessPaneRow[];
512
512
  /** What the report says when `rows` is empty, in place of "No data.": why there are none. */
513
513
  empty?: string;
514
+ /**
515
+ * Sections the text report prints under the rows, drawn as a bundle's are:
516
+ * the figures a pane shows beside its table (a curve's spreads). JSON keeps
517
+ * them in `metadata`, and the exports leave them out.
518
+ */
519
+ textSections?: HeadlessBundleSection[];
514
520
  /**
515
521
  * The row fields naming each row's own unit, symbol and observation date
516
522
  * (an ISO date or instant), for rows of several series dated apart: each
@@ -696,6 +702,13 @@ export interface HeadlessPaneDefinition<Shape extends HeadlessPaneShape = Headle
696
702
  * means and the commands that run them, and `catalog ivol` lists them first.
697
703
  */
698
704
  suggestFor?: string[];
705
+ /**
706
+ * Words that name one case of the function, each with the argument it
707
+ * takes for it: CTM opens the VIX futures curve for `VX` and `vix
708
+ * futures`. `fn VX` runs `CTM VIX` and says so, and `catalog vx` lists
709
+ * the function first.
710
+ */
711
+ opens?: ReadonlyArray<{ words: readonly string[]; argument: string }>;
699
712
  intents?: string[];
700
713
  dataRequirements?: string[];
701
714
  limitations?: string[];
@@ -723,6 +736,12 @@ export interface HeadlessPaneDefinition<Shape extends HeadlessPaneShape = Headle
723
736
  * points at GIP's 1-minute bars). `key` is the listing as read, RMS:ASX.
724
737
  */
725
738
  usListingsOnlyHint?(key: string): string;
739
+ /**
740
+ * The ticker argument also takes a FRED series as the catalog writes it
741
+ * (`FRED:T10Y2Y`), which reaches `load` as typed instead of being read as a
742
+ * listing: MDAY reads a spread's moves on release days.
743
+ */
744
+ fredSeriesArgument?: boolean;
726
745
  /**
727
746
  * A typed symbol the function reads as another before it is resolved, with
728
747
  * the note that says so: OPX and OVDV read a bare BTC or ETH as the coin
@@ -482,6 +482,12 @@ interface PaneTemplateShortcut {
482
482
  */
483
483
  keepArgToken?: (token: string) => boolean;
484
484
  argOptional?: boolean;
485
+ /**
486
+ * The argument is a company the function reports on (CDS, TRACE): with
487
+ * none typed, the command bar opens it on the ticker in focus, and with no
488
+ * ticker in focus market-wide. `<ticker> <code>` opens it too.
489
+ */
490
+ focusedIssuer?: boolean;
485
491
  /**
486
492
  * With no argument typed and none to infer from the active ticker, open
487
493
  * the pane without one instead of asking for it (ERN alone is the market
package/src/ui/host.tsx CHANGED
@@ -727,6 +727,8 @@ export interface RendererHost {
727
727
  */
728
728
  startWindowDrag?(press?: { detail?: number }): Promise<void> | void;
729
729
  controlWindow?(action: "minimize" | "toggle-maximize" | "close"): Promise<void> | void;
730
+ /** From a press on the page's top edge, where its own window frame has none to pull. */
731
+ startWindowResize?(edge: "top" | "top-left" | "top-right"): Promise<void> | void;
730
732
  /**
731
733
  * Opens a link in the person's browser. Resolves false when no browser could
732
734
  * be shown from here (a terminal over SSH, or no opener installed), so the
package/src/ui/index.tsx CHANGED
@@ -1,8 +1,9 @@
1
- import { createElement, forwardRef, useCallback, useRef, type ComponentProps } from "react";
1
+ import { createElement, forwardRef, memo, useCallback, useRef, type ComponentProps } from "react";
2
2
  import { useForwardedScrollBoxRef, useRegisterPaneScrollBox } from "../state/pane-scroll-registry";
3
3
  import { useUiHost, type UiHost } from "./host";
4
4
  import { scrollBoxScrollsVertically } from "./scroll-box-axis";
5
5
  import { useRemoteUiNode } from "../remote/semantic-tree";
6
+ import { markPure, samePureProps } from "./same-props";
6
7
  import { assignRef } from "../react/assign-ref";
7
8
  import {
8
9
  remoteChartEvent,
@@ -60,7 +61,7 @@ export type {
60
61
  TextareaRenderable,
61
62
  } from "./host";
62
63
 
63
- export const Box = forwardRef<any, ComponentProps<UiHost["Box"]>>((props, ref) => {
64
+ export const Box = markPure(memo(forwardRef<any, ComponentProps<UiHost["Box"]>>((props, ref) => {
64
65
  const { Box: HostBox } = useUiHost();
65
66
  const rawProps = props as Record<string, unknown>;
66
67
  const onMouseDown = rawProps.onMouseDown as ((event?: unknown) => unknown) | undefined;
@@ -84,10 +85,10 @@ export const Box = forwardRef<any, ComponentProps<UiHost["Box"]>>((props, ref) =
84
85
  : null,
85
86
  );
86
87
  return createElement(HostBox as any, { ...props, ref, "data-gloom-remote-node-id": remoteNodeId ?? undefined });
87
- });
88
+ }), samePureProps));
88
89
  Box.displayName = "Box";
89
90
 
90
- export const Text = forwardRef<any, ComponentProps<UiHost["Text"]>>((props, ref) => {
91
+ export const Text = markPure(memo(forwardRef<any, ComponentProps<UiHost["Text"]>>((props, ref) => {
91
92
  const { Text: HostText } = useUiHost();
92
93
  const rawProps = props as Record<string, unknown>;
93
94
  const onMouseDown = rawProps.onMouseDown as ((event?: unknown) => unknown) | undefined;
@@ -105,25 +106,25 @@ export const Text = forwardRef<any, ComponentProps<UiHost["Text"]>>((props, ref)
105
106
  : null,
106
107
  );
107
108
  return createElement(HostText as any, { ...props, ref, "data-gloom-remote-node-id": remoteNodeId ?? undefined });
108
- });
109
+ }), samePureProps));
109
110
  Text.displayName = "Text";
110
111
 
111
- export const Span = forwardRef<any, ComponentProps<UiHost["Span"]>>((props, ref) => {
112
+ export const Span = markPure(memo(forwardRef<any, ComponentProps<UiHost["Span"]>>((props, ref) => {
112
113
  const { Span: HostSpan } = useUiHost();
113
114
  return createElement(HostSpan as any, { ...props, ref });
114
- });
115
+ }), samePureProps));
115
116
  Span.displayName = "Span";
116
117
 
117
- export const Strong = forwardRef<any, ComponentProps<UiHost["Strong"]>>((props, ref) => {
118
+ export const Strong = markPure(memo(forwardRef<any, ComponentProps<UiHost["Strong"]>>((props, ref) => {
118
119
  const { Strong: HostStrong } = useUiHost();
119
120
  return createElement(HostStrong as any, { ...props, ref });
120
- });
121
+ }), samePureProps));
121
122
  Strong.displayName = "Strong";
122
123
 
123
- export const Underline = forwardRef<any, ComponentProps<UiHost["Underline"]>>((props, ref) => {
124
+ export const Underline = markPure(memo(forwardRef<any, ComponentProps<UiHost["Underline"]>>((props, ref) => {
124
125
  const { Underline: HostUnderline } = useUiHost();
125
126
  return createElement(HostUnderline as any, { ...props, ref });
126
- });
127
+ }), samePureProps));
127
128
  Underline.displayName = "Underline";
128
129
 
129
130
  export const ScrollBox = forwardRef<any, ComponentProps<UiHost["ScrollBox"]>>((props, ref) => {
@@ -242,7 +243,7 @@ export const Textarea = forwardRef<any, ComponentProps<UiHost["Textarea"]>>(({
242
243
  });
243
244
  Textarea.displayName = "Textarea";
244
245
 
245
- export const ChartSurface = forwardRef<any, ComponentProps<UiHost["ChartSurface"]>>((props, ref) => {
246
+ export const ChartSurface = markPure(memo(forwardRef<any, ComponentProps<UiHost["ChartSurface"]>>((props, ref) => {
246
247
  const { ChartSurface: HostChartSurface } = useUiHost();
247
248
  const rawProps = props as Record<string, unknown>;
248
249
  const localRef = useRef<any>(null);
@@ -285,7 +286,7 @@ export const ChartSurface = forwardRef<any, ComponentProps<UiHost["ChartSurface"
285
286
  },
286
287
  });
287
288
  return createElement(HostChartSurface as any, { ...props, ref: setSurfaceRef, "data-gloom-remote-node-id": remoteNodeId ?? undefined });
288
- });
289
+ }), samePureProps));
289
290
  ChartSurface.displayName = "ChartSurface";
290
291
 
291
292
  export const ImageSurface = forwardRef<any, ComponentProps<UiHost["ImageSurface"]>>((props, ref) => {
@@ -0,0 +1,58 @@
1
+ import { isValidElement } from "react";
2
+
3
+ /**
4
+ * Memoized components that render from their props and context alone, such
5
+ * as the kit's Box and Text: two elements of one with equal props render the
6
+ * same thing.
7
+ */
8
+ const pureTypes = new WeakSet<object>();
9
+
10
+ /** Marks a memoized component as rendering from its props and context alone. */
11
+ export function markPure<T extends object>(type: T): T {
12
+ pureTypes.add(type);
13
+ return type;
14
+ }
15
+
16
+ /** How many elements and arrays deep a comparison looks before calling props different. */
17
+ const MAX_DEPTH = 6;
18
+
19
+ function sameValue(left: unknown, right: unknown, depth: number): boolean {
20
+ if (Object.is(left, right)) return true;
21
+ if (depth >= MAX_DEPTH || typeof left !== "object" || typeof right !== "object" || !left || !right) return false;
22
+ if (Array.isArray(left)) {
23
+ if (!Array.isArray(right) || left.length !== right.length) return false;
24
+ for (let index = 0; index < left.length; index += 1) {
25
+ if (!sameValue(left[index], right[index], depth + 1)) return false;
26
+ }
27
+ return true;
28
+ }
29
+ if (!isValidElement(left) || !isValidElement(right)) return false;
30
+ // Any other component may read more than its props while it renders, so
31
+ // only a pure component's element counts as the same for equal props.
32
+ return left.type === right.type
33
+ && left.key === right.key
34
+ && typeof left.type === "object"
35
+ && pureTypes.has(left.type)
36
+ && sameProps(left.props as Record<string, unknown>, right.props as Record<string, unknown>, depth + 1);
37
+ }
38
+
39
+ /**
40
+ * The memo test for a pure component: props are the same when each is equal,
41
+ * where elements of pure components (a Box of Texts) compare by their props
42
+ * instead of by identity, as a parent builds them afresh on each render.
43
+ * Functions and other objects still compare by identity.
44
+ */
45
+ export function samePureProps<P extends object>(left: Readonly<P>, right: Readonly<P>): boolean {
46
+ return sameProps(left as Record<string, unknown>, right as Record<string, unknown>, 0);
47
+ }
48
+
49
+ function sameProps(left: Record<string, unknown>, right: Record<string, unknown>, depth: number): boolean {
50
+ if (left === right) return true;
51
+ let count = 0;
52
+ for (const key in left) {
53
+ count += 1;
54
+ if (!Object.prototype.hasOwnProperty.call(right, key) || !sameValue(left[key], right[key], depth)) return false;
55
+ }
56
+ for (const _key in right) count -= 1;
57
+ return count === 0;
58
+ }
@@ -389,21 +389,50 @@ export interface CliStatsOptions {
389
389
  width?: number | null;
390
390
  }
391
391
 
392
+ /** The fewest cells a stat's value is given beside its label; a longer label goes on a line of its own. */
393
+ const MIN_STAT_VALUE_WIDTH = 20;
394
+
395
+ /**
396
+ * The label column of a stats block: its longest label, unless that leaves
397
+ * the values fewer than MIN_STAT_VALUE_WIDTH cells of `width`. Then it is the
398
+ * longest label that leaves them that many, and longer ones go above their values.
399
+ */
400
+ function statLabelWidth(entries: readonly CliStatEntry[], width: number | null, indent: number): number {
401
+ const widths = entries.map(([label]) => visibleLength(label));
402
+ const longest = Math.max(0, ...widths);
403
+ if (width == null) return longest;
404
+ const fits = width - indent - COLUMN_GAP - MIN_STAT_VALUE_WIDTH;
405
+ return longest <= fits ? longest : Math.max(0, ...widths.filter((labelWidth) => labelWidth <= fits));
406
+ }
407
+
392
408
  /** Cells left for values after a block's labels, for callers that build nested values. */
393
409
  export function statValueWidth(entries: readonly CliStatEntry[], options: CliStatsOptions = {}): number | null {
394
410
  const width = options.width === undefined ? cliTerminalWidth() : options.width;
395
411
  if (width == null) return null;
396
- const labelWidth = Math.max(0, ...entries.map(([label]) => visibleLength(label)));
397
- return Math.max(20, width - (options.indent ?? 0) - labelWidth - COLUMN_GAP);
412
+ const indent = options.indent ?? 0;
413
+ return Math.max(MIN_STAT_VALUE_WIDTH, width - indent - statLabelWidth(entries, width, indent) - COLUMN_GAP);
398
414
  }
399
415
 
400
- /** A block of label/value lines aligned on the longest label. Values wrap under themselves. */
416
+ /**
417
+ * A block of label/value lines aligned on the longest label. Values wrap under
418
+ * themselves; in a narrow width a label too long to leave its value room is
419
+ * on its own line, its value indented under it.
420
+ */
401
421
  export function renderStats(entries: readonly CliStatEntry[], options: CliStatsOptions = {}): string {
402
422
  const indent = " ".repeat(options.indent ?? 0);
403
- const labelWidth = Math.max(0, ...entries.map(([label]) => visibleLength(label)));
423
+ const width = options.width === undefined ? cliTerminalWidth() : options.width;
424
+ const labelWidth = statLabelWidth(entries, width, indent.length);
404
425
  const valueIndent = `${indent}${" ".repeat(labelWidth + COLUMN_GAP)}`;
405
426
  const valueWidth = statValueWidth(entries, options);
406
427
  return entries.map(([label, value]) => {
428
+ if (width != null && visibleLength(label) > labelWidth) {
429
+ // Above its value, which is indented under it across the width.
430
+ const under = `${indent}${" ".repeat(COLUMN_GAP)}`;
431
+ return [
432
+ ...wrapText(label, Math.max(1, width - indent.length)).map((line) => `${indent}${cliStyles.muted(line)}`),
433
+ ...wrapText(value, Math.max(1, width - under.length)).map((line) => `${under}${line}`.trimEnd()),
434
+ ].join("\n");
435
+ }
407
436
  const valueLines = valueWidth == null ? value.split("\n") : wrapText(value, valueWidth);
408
437
  const [first = "", ...rest] = valueLines;
409
438
  return [
@@ -126,3 +126,23 @@ export function currenciesNamed(text: string): readonly NamedCurrency[] {
126
126
  if (!key) return [];
127
127
  return names.get(key) ?? (key.endsWith("s") ? names.get(key.slice(0, -1)) : undefined) ?? [];
128
128
  }
129
+
130
+ /** Codes that are also English words, read as a currency only when typed in capitals: "try" is a verb before it is the lira. */
131
+ export const WORD_CURRENCY_CODES: ReadonlySet<string> = new Set(["TRY", "PEN", "COP", "MAD", "RUB", "CAD"]);
132
+
133
+ let namedCodes: ReadonlySet<string> | undefined;
134
+
135
+ /**
136
+ * The currency a three-letter code names, as a query types it: `jpy` and
137
+ * `JPY` are JPY, `TRY` the lira but `try` nothing (`WORD_CURRENCY_CODES`).
138
+ * Only the currencies named here count, so `all` is no Albanian lek. Null for
139
+ * any other text.
140
+ */
141
+ export function currencyCodeTyped(text: string): string | null {
142
+ const typed = text.trim();
143
+ if (!/^[A-Za-z]{3}$/.test(typed)) return null;
144
+ namedCodes ??= new Set(CURRENCY_NAMES.map(([code]) => code));
145
+ const code = typed.toUpperCase();
146
+ if (!namedCodes.has(code)) return null;
147
+ return typed === code || !WORD_CURRENCY_CODES.has(code) ? code : null;
148
+ }
@@ -98,6 +98,12 @@ function pairBaseRank(code: string): number {
98
98
  return code === "JPY" ? PAIR_BASE_ORDER.length + 1 : PAIR_BASE_ORDER.length;
99
99
  }
100
100
 
101
+ /** A currency's pair against the dollar, as markets quote it and as a listing: EURUSD=X for the euro, USDCHF=X for the franc. */
102
+ export function dollarPairListing(code: string): string {
103
+ const currency = code.trim().toUpperCase();
104
+ return pairBaseRank(currency) < pairBaseRank("USD") ? `${currency}USD=X` : `USD${currency}=X`;
105
+ }
106
+
101
107
  /**
102
108
  * A rate of `quote` per unit of `currency`, written the way markets quote
103
109
  * the pair, as `fx` reads a pair: 0.0067 USD per JPY is USD/JPY 149.25, and