@gloom-sh/terminal 0.19.5 → 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 (208) hide show
  1. package/package.json +1 -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/market.ts +149 -10
  8. package/src/cli/commands/search.ts +21 -3
  9. package/src/cli/commands/ticker.ts +74 -33
  10. package/src/cli/glossary.ts +3 -3
  11. package/src/cli/known-gaps.ts +8 -0
  12. package/src/cli/listing-arg.ts +12 -0
  13. package/src/cli/pane-functions/capabilities.ts +2 -0
  14. package/src/cli/pane-functions/catalog.ts +22 -4
  15. package/src/cli/pane-functions/function-help.ts +8 -5
  16. package/src/cli/pane-functions/headless.ts +4 -3
  17. package/src/cli/pane-functions/resolver.ts +75 -2
  18. package/src/cli/quote-answer.ts +9 -0
  19. package/src/cli/symbol-list.ts +54 -2
  20. package/src/cli/symbol-rows.ts +14 -2
  21. package/src/cli/ticker-resolution.ts +89 -20
  22. package/src/components/chart/composite/axis-overlays.tsx +60 -27
  23. package/src/components/chart/composite/composite-chart.tsx +118 -63
  24. package/src/components/chart/composite/cursor-source.ts +111 -0
  25. package/src/components/chart/composite/format.ts +168 -6
  26. package/src/components/chart/composite/legend.tsx +8 -4
  27. package/src/components/chart/composite/panel-labels.ts +20 -1
  28. package/src/components/chart/composite/panel-surface.tsx +201 -92
  29. package/src/components/chart/composite/price-axis-labels.tsx +92 -46
  30. package/src/components/chart/composite/price-series.ts +31 -8
  31. package/src/components/chart/composite/scene.ts +154 -59
  32. package/src/components/chart/composite/series-axis-tags.tsx +4 -2
  33. package/src/components/chart/composite/time-axis.ts +13 -5
  34. package/src/components/chart/composite/time-scale.ts +211 -56
  35. package/src/components/chart/composite/types.ts +11 -1
  36. package/src/components/chart/composite/use-composite-chart-keyboard.ts +32 -12
  37. package/src/components/chart/curve/curve-surface.tsx +5 -2
  38. package/src/components/chart/curve/model.ts +4 -1
  39. package/src/components/chart/native/use-bitmap-metrics.ts +81 -0
  40. package/src/components/chart/static/series.ts +3 -0
  41. package/src/components/command-bar/commands/collection-list.ts +81 -0
  42. package/src/components/command-bar/commands/direct/index.ts +6 -0
  43. package/src/components/command-bar/commands/registry.ts +8 -0
  44. package/src/components/command-bar/layout-items/current-layout.ts +22 -1
  45. package/src/components/command-bar/layout-items/focused-pane.ts +22 -1
  46. package/src/components/command-bar/pane-templates/items.ts +19 -3
  47. package/src/components/command-bar/pane-templates/workflow.ts +5 -0
  48. package/src/components/command-bar/routes/root/results.ts +23 -3
  49. package/src/components/command-bar/routes/root/selection.ts +4 -2
  50. package/src/components/command-bar/routes/root/shortcut-feedback.ts +1 -1
  51. package/src/components/command-bar/routes/root/shortcut-items.ts +3 -4
  52. package/src/components/command-bar/routes/root/shortcuts.ts +58 -14
  53. package/src/components/command-bar/routes/root/ticker-first.ts +32 -0
  54. package/src/components/command-bar/surface/environment.ts +2 -0
  55. package/src/components/command-bar/view-model.ts +7 -0
  56. package/src/components/command-bar/workflow/ops.ts +2 -1
  57. package/src/components/command-bar/workflow/tickers.ts +20 -0
  58. package/src/components/layout/shell/menu.ts +15 -1
  59. package/src/components/layout/shell/pane/actions.ts +4 -0
  60. package/src/components/layout/shell/ticker-link-menu.ts +12 -3
  61. package/src/components/layout/status-bar.tsx +20 -0
  62. package/src/components/onboarding/onboarding-keyboard.ts +5 -1
  63. package/src/components/onboarding/onboarding-wizard.tsx +15 -4
  64. package/src/components/onboarding/portfolio-step/positions-panel.tsx +8 -5
  65. package/src/components/onboarding/use-onboarding-progress.ts +20 -1
  66. package/src/components/price-sparkline/view.tsx +14 -6
  67. package/src/components/ticker/badge/index.tsx +8 -4
  68. package/src/components/ticker/badge/list.tsx +23 -7
  69. package/src/components/ui/column-grid.tsx +8 -2
  70. package/src/components/ui/data-table/opentui/model.ts +4 -1
  71. package/src/components/ui/tabs.tsx +5 -2
  72. package/src/core/state/app/layout.ts +18 -3
  73. package/src/core/state/app/state.ts +2 -0
  74. package/src/core/state/app/types.ts +5 -0
  75. package/src/data/config/layout.ts +3 -0
  76. package/src/data/config/store/normalize.ts +39 -4
  77. package/src/i18n/es.ts +10 -0
  78. package/src/i18n/ja.ts +10 -0
  79. package/src/i18n/ko.ts +10 -0
  80. package/src/i18n/zh-cn.ts +10 -0
  81. package/src/i18n/zh-tw.ts +10 -0
  82. package/src/layout/pane-manager/floating-placement.ts +7 -4
  83. package/src/layout/pane-manager/floating.ts +5 -2
  84. package/src/market-data/bond-funds.ts +19 -0
  85. package/src/market-data/futures-contract.ts +14 -3
  86. package/src/market-data/market/freshness.ts +18 -0
  87. package/src/market-data/market/status.ts +15 -2
  88. package/src/plugins/builtin/bond-calculator/headless.ts +2 -1
  89. package/src/plugins/builtin/bond-calculator/index.tsx +1 -1
  90. package/src/plugins/builtin/bond-calculator/model.ts +14 -5
  91. package/src/plugins/builtin/bond-calculator/pane.tsx +1 -1
  92. package/src/plugins/builtin/buildout/cells.tsx +25 -45
  93. package/src/plugins/builtin/buildout/detail/company.tsx +3 -3
  94. package/src/plugins/builtin/buildout/detail/index.tsx +1 -1
  95. package/src/plugins/builtin/buildout/detail/intel.tsx +4 -7
  96. package/src/plugins/builtin/buildout/detail/site.tsx +4 -4
  97. package/src/plugins/builtin/buildout/detail/ui.tsx +39 -38
  98. package/src/plugins/builtin/buildout/format.ts +23 -1
  99. package/src/plugins/builtin/buildout/model/types.ts +1 -0
  100. package/src/plugins/builtin/buildout/pane/index.tsx +2 -8
  101. package/src/plugins/builtin/buildout/table-model.ts +12 -4
  102. package/src/plugins/builtin/cds/headless.ts +1 -0
  103. package/src/plugins/builtin/cds/index.tsx +1 -1
  104. package/src/plugins/builtin/cloud/plugin.tsx +2 -0
  105. package/src/plugins/builtin/cloud/upgrade-status-widget.tsx +28 -3
  106. package/src/plugins/builtin/correlation/headless.ts +3 -2
  107. package/src/plugins/builtin/crypto-board/pane.tsx +5 -4
  108. package/src/plugins/builtin/debt-maturities/headless.ts +11 -2
  109. package/src/plugins/builtin/debt-maturities/model.ts +66 -0
  110. package/src/plugins/builtin/debt-maturities/pane.tsx +23 -4
  111. package/src/plugins/builtin/earnings-ripple/pane.tsx +1 -1
  112. package/src/plugins/builtin/econ/calendar-model.ts +28 -6
  113. package/src/plugins/builtin/equity-screener/client.ts +1 -1
  114. package/src/plugins/builtin/equity-screener/criterion-editor.tsx +4 -16
  115. package/src/plugins/builtin/equity-screener/headless.ts +4 -2
  116. package/src/plugins/builtin/equity-screener/ideas.ts +67 -3
  117. package/src/plugins/builtin/equity-screener/model.ts +180 -12
  118. package/src/plugins/builtin/equity-screener/pane.tsx +52 -12
  119. package/src/plugins/builtin/equity-screener/screen-check.ts +7 -4
  120. package/src/plugins/builtin/equity-screener/watchlist.ts +33 -0
  121. package/src/plugins/builtin/futures-curve/client.ts +19 -0
  122. package/src/plugins/builtin/futures-curve/headless.ts +52 -13
  123. package/src/plugins/builtin/futures-curve/index.tsx +1 -1
  124. package/src/plugins/builtin/futures-curve/model.ts +77 -6
  125. package/src/plugins/builtin/futures-curve/pane.tsx +19 -3
  126. package/src/plugins/builtin/macro-day/client.ts +41 -0
  127. package/src/plugins/builtin/macro-day/headless.ts +19 -9
  128. package/src/plugins/builtin/macro-day/model.ts +3 -1
  129. package/src/plugins/builtin/market-movers/index.tsx +4 -3
  130. package/src/plugins/builtin/mna/distress/headless.ts +1 -0
  131. package/src/plugins/builtin/perps/pane.tsx +3 -1
  132. package/src/plugins/builtin/portfolio-list/cli/bulk-symbols.ts +17 -0
  133. package/src/plugins/builtin/portfolio-list/cli/portfolio-command.ts +2 -1
  134. package/src/plugins/builtin/portfolio-list/cli/watchlist-command.ts +2 -1
  135. package/src/plugins/builtin/rate-path/headless.ts +24 -10
  136. package/src/plugins/builtin/research/event-model.ts +10 -3
  137. package/src/plugins/builtin/research/events-headless.ts +20 -2
  138. package/src/plugins/builtin/sec/fund-facts.ts +17 -1
  139. package/src/plugins/builtin/sec/index.tsx +1 -1
  140. package/src/plugins/builtin/shared/members-menu.tsx +103 -38
  141. package/src/plugins/builtin/short-interest/publications-model.ts +22 -1
  142. package/src/plugins/builtin/short-interest/publications-pane.tsx +13 -4
  143. package/src/plugins/builtin/short-interest/watch-model.ts +1 -1
  144. package/src/plugins/builtin/time-sales/pane.tsx +3 -2
  145. package/src/plugins/builtin/trace-bonds/client.ts +7 -4
  146. package/src/plugins/builtin/trace-bonds/index.tsx +1 -1
  147. package/src/plugins/builtin/volatility/client.ts +6 -1
  148. package/src/plugins/builtin/volatility/headless.ts +0 -1
  149. package/src/plugins/builtin/yield-curve/curves.ts +15 -0
  150. package/src/plugins/builtin/yield-curve/headless.ts +6 -1
  151. package/src/plugins/builtin/yield-curve/index.tsx +5 -8
  152. package/src/plugins/host-modules.ts +22 -3
  153. package/src/plugins/host-smoke.ts +6 -3
  154. package/src/portfolio/collection-name.ts +19 -0
  155. package/src/renderers/browser/http-proxy-transport.ts +78 -8
  156. package/src/renderers/cloudflare/http-proxy.ts +13 -2
  157. package/src/renderers/cloudflare/proxy-session.ts +47 -24
  158. package/src/renderers/cloudflare/worker.ts +15 -2
  159. package/src/renderers/desktop/geometry.ts +279 -0
  160. package/src/renderers/desktop/screen-setup.ts +246 -0
  161. package/src/renderers/desktop/sequential-window-host.ts +179 -0
  162. package/src/renderers/desktop/test-utils.ts +71 -0
  163. package/src/renderers/desktop/window-controller.ts +433 -0
  164. package/src/renderers/desktop/window-host.ts +70 -0
  165. package/src/renderers/desktop/window-layouts.ts +630 -0
  166. package/src/renderers/dom/data-frames.ts +15 -4
  167. package/src/renderers/electrobun/bun/application-menu/click.ts +1 -0
  168. package/src/renderers/electrobun/bun/application-menu/index.ts +4 -1
  169. package/src/renderers/electrobun/bun/desktop/backend-requests.ts +19 -8
  170. package/src/renderers/electrobun/bun/desktop/backend.ts +320 -19
  171. package/src/renderers/electrobun/bun/desktop/detached-windows.ts +83 -61
  172. package/src/renderers/electrobun/bun/desktop/host-requests.ts +4 -14
  173. package/src/renderers/electrobun/bun/desktop/initialization.ts +30 -11
  174. package/src/renderers/electrobun/bun/desktop/screen-setup-file.ts +55 -0
  175. package/src/renderers/electrobun/bun/desktop/state-broadcaster.ts +44 -8
  176. package/src/renderers/electrobun/bun/desktop/workspace/index.ts +298 -97
  177. package/src/renderers/electrobun/bun/desktop/workspace/requests.ts +44 -6
  178. package/src/renderers/electrobun/bun/index.ts +4 -97
  179. package/src/renderers/electrobun/bun/window/electrobun-window-host.ts +306 -0
  180. package/src/renderers/electrobun/bun/window/focus.ts +0 -25
  181. package/src/renderers/electrobun/bun/window/remembered-frame.ts +4 -82
  182. package/src/renderers/electrobun/shared/protocol.ts +44 -2
  183. package/src/renderers/electrobun/view/backend-rpc.ts +15 -0
  184. package/src/renderers/electrobun/view/desktop/window/bridge.ts +63 -3
  185. package/src/renderers/electrobun/view/main.tsx +13 -7
  186. package/src/series/fred-argument.ts +17 -0
  187. package/src/sources/provider-router/financial-routes.ts +7 -1
  188. package/src/state/app/context/index.tsx +16 -2
  189. package/src/state/desktop-windows.ts +63 -0
  190. package/src/sync/other-window-tabs.ts +62 -0
  191. package/src/tickers/company-name-listing.ts +23 -3
  192. package/src/tickers/listing-fate.ts +147 -1
  193. package/src/tickers/terminal-codes.ts +5 -0
  194. package/src/time-series/types.ts +6 -0
  195. package/src/types/config.ts +10 -1
  196. package/src/types/desktop-window.ts +71 -2
  197. package/src/types/financials.ts +4 -0
  198. package/src/types/headless.ts +19 -0
  199. package/src/types/plugin.ts +6 -0
  200. package/src/ui/index.tsx +14 -13
  201. package/src/ui/same-props.ts +58 -0
  202. package/src/utils/cli-output.ts +33 -4
  203. package/src/utils/format.ts +7 -2
  204. package/src/utils/futures-generic.ts +12 -0
  205. package/src/utils/http-proxy-upstream.ts +6 -2
  206. package/src/utils/plugin-proxy-hosts.json +0 -4
  207. package/src/utils/plugin-proxy-hosts.ts +22 -0
  208. package/src/utils/sec-filings.ts +7 -1
@@ -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/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 [
@@ -204,9 +204,14 @@ export function formatNumber(value: number | undefined, decimals = 2): string {
204
204
  export function formatSignificant(value: number | undefined, digits = 4): string {
205
205
  if (value == null || !Number.isFinite(value)) return formatNumber(undefined);
206
206
  if (value === 0) return getNumberFormatter(0).format(0);
207
+ return getNumberFormatter(significantDecimals(value, digits)).format(Number(value.toPrecision(digits)));
208
+ }
209
+
210
+ /** The decimals `formatSignificant` writes a value to: 0.8904 has 4, 1.123 has 3, 0 none. */
211
+ export function significantDecimals(value: number, digits = 4): number {
212
+ if (value === 0 || !Number.isFinite(value)) return 0;
207
213
  const rounded = Number(value.toPrecision(digits));
208
- const decimals = Math.min(12, Math.max(0, digits - 1 - Math.floor(Math.log10(Math.abs(rounded)))));
209
- return getNumberFormatter(decimals).format(rounded);
214
+ return Math.min(12, Math.max(0, digits - 1 - Math.floor(Math.log10(Math.abs(rounded)))));
210
215
  }
211
216
 
212
217
  /** A percentile rank with its window: "73 pctl 1Y", "-- pctl 1Y" when unranked, "73 pctl" without a window. */
@@ -68,6 +68,18 @@ const STANDARD_ROLL_DAYS: Readonly<Record<string, number>> = {
68
68
  VX: 0,
69
69
  };
70
70
 
71
+ /**
72
+ * Continuous symbols written as other roots' are (`CL=F`) for a root that has
73
+ * none, Cboe's VIX futures: `VX=F` is the front generic VX1, which follows
74
+ * the same front contract.
75
+ */
76
+ const GENERIC_FOR_ALIAS: Readonly<Record<string, string>> = { "VX=F": "VX1" };
77
+
78
+ /** The front generic a continuous symbol the root does not list stands for (VX=F: VX1), or null. */
79
+ export function continuousAliasGeneric(symbol: string): string | null {
80
+ return GENERIC_FOR_ALIAS[symbol.trim().toUpperCase()] ?? null;
81
+ }
82
+
71
83
  /** A root's standard roll: what a bare generic (NG1) and the continuous alias (NG=F) follow. */
72
84
  export function standardFuturesGenericRoll(root: string): FuturesGenericRoll {
73
85
  return { rule: "first-notice", days: STANDARD_ROLL_DAYS[root] ?? 1, standard: true };
@@ -53,6 +53,10 @@ export async function fetchCheckingRedirects(
53
53
  init: ProxiedRequestInit,
54
54
  options: { fetch: typeof fetch; check: ProxyTargetCheck; signal: AbortSignal },
55
55
  ): Promise<ProxyUpstreamResult> {
56
+ // Taken off `options` before calling: `options.fetch(...)` would call the
57
+ // runtime's fetch with `options` as `this`, which Cloudflare Workers reject
58
+ // with "Illegal invocation", failing every proxied request.
59
+ const { fetch: fetchUpstream, check, signal } = options;
56
60
  const headers = upstreamHeaders(init.headers);
57
61
  const mode = init.redirect ?? "follow";
58
62
  let url = first;
@@ -60,7 +64,7 @@ export async function fetchCheckingRedirects(
60
64
  let body = init.body;
61
65
 
62
66
  for (let followed = 0; ; followed += 1) {
63
- const response = await options.fetch(url, { method, headers, body, redirect: "manual", signal: options.signal });
67
+ const response = await fetchUpstream(url, { method, headers, body, redirect: "manual", signal });
64
68
  const location = REDIRECT_STATUSES.has(response.status) ? response.headers.get("location") : null;
65
69
  // "manual" hands the redirect back to the plugin. If it follows it, that
66
70
  // comes back through here as a new request and is checked like one.
@@ -77,7 +81,7 @@ export async function fetchCheckingRedirects(
77
81
  // Intentional ignore: a Location that does not parse is reported as an invalid redirect, never followed.
78
82
  return { error: "The upstream sent an invalid redirect.", status: 502 };
79
83
  }
80
- const target = await options.check(next);
84
+ const target = await check(next);
81
85
  if ("error" in target) return { error: `The upstream redirect was refused. ${target.error}`, status: 502 };
82
86
 
83
87
  if (target.url.origin !== url.origin) {
@@ -3,17 +3,13 @@
3
3
  "api.crypto.com",
4
4
  "api.elections.kalshi.com",
5
5
  "api.fda.gov",
6
- "api.fiscaldata.treasury.gov",
7
6
  "api.gemini.com",
8
7
  "api.limitless.exchange",
9
8
  "api.votehub.com",
10
9
  "clinicaltrials.gov",
11
- "clob.polymarket.com",
12
- "data-api.polymarket.com",
13
10
  "data.pascal.trade",
14
11
  "efts.sec.gov",
15
12
  "forms13f.com",
16
- "gamma-api.polymarket.com",
17
13
  "gateway.polymarket.us",
18
14
  "markets.newyorkfed.org",
19
15
  "nasdaqtrader.com",
@@ -18,6 +18,28 @@ import allowed from "./plugin-proxy-hosts.json";
18
18
  */
19
19
  export const PROXY_ALLOWED_HOSTS: readonly string[] = allowed.hosts;
20
20
 
21
+ /**
22
+ * Declared hosts the browser calls directly instead of through the proxy,
23
+ * because they answer the terminal's origin with CORS headers and need no
24
+ * header a browser cannot set. The worker lists them in `connect-src`, and
25
+ * the generator leaves them off the proxy list, so a request to one never
26
+ * costs a worker round trip or a slot in anyone's rate limit.
27
+ *
28
+ * Add a host here only after checking that it sends
29
+ * `access-control-allow-origin` for https://term.gloom.sh on the requests the
30
+ * plugin makes, and on their preflight when the plugin sends a header outside
31
+ * the CORS-safelisted ones (`Authorization`, say). The browser transport
32
+ * leaves `User-Agent` off these requests, so it never causes a preflight.
33
+ */
34
+ export const WEB_DIRECT_HOSTS: readonly string[] = [
35
+ "api.fiscaldata.treasury.gov",
36
+ "api.thebuildout.ai",
37
+ // Polymarket's read APIs. An events page can pass the proxy's 5 MB cap.
38
+ "clob.polymarket.com",
39
+ "data-api.polymarket.com",
40
+ "gamma-api.polymarket.com",
41
+ ];
42
+
21
43
  /** The worker route the browser posts proxied requests to. */
22
44
  export const HTTP_PROXY_PATH = "/http-proxy";
23
45
 
@@ -179,6 +179,8 @@ export interface HiddenFilings {
179
179
  pricingSupplements: number;
180
180
  /** The 13D/13G the company filed as a holder of other companies. */
181
181
  ownershipReportsAboutOthers: number;
182
+ /** A fund's trust filed these for its other funds (the sibling series' NPORT-P on the same day). */
183
+ otherFunds?: number;
182
184
  }
183
185
 
184
186
  /**
@@ -194,9 +196,12 @@ function keptFilings(
194
196
  const kept: SecFilingItem[] = [];
195
197
  const hidden: HiddenFilings = { pricingSupplements: 0, ownershipReportsAboutOthers: 0 };
196
198
  const isSupplement = pricingSupplementTest(filings);
199
+ // A fund's trust lists every fund it runs; where the service marks the fund's own series, the others' are left out.
200
+ const ownSeries = filings.some((filing) => filing.fundSeries === true);
197
201
  for (const filing of filings) {
198
202
  if (kept.length >= limit) break;
199
- if (isSupplement(filing)) hidden.pricingSupplements += 1;
203
+ if (ownSeries && filing.fundSeries === false) hidden.otherFunds = (hidden.otherFunds ?? 0) + 1;
204
+ else if (isSupplement(filing)) hidden.pricingSupplements += 1;
200
205
  else if (schedulesAboutOthers && isScheduleAboutAnotherCompany(filing)) hidden.ownershipReportsAboutOthers += 1;
201
206
  else kept.push(filing);
202
207
  }
@@ -213,6 +218,7 @@ export function hiddenFilingsNote(hidden: HiddenFilings): string | null {
213
218
  const parts = [
214
219
  count(hidden.pricingSupplements, "pricing supplement", "pricing supplements"),
215
220
  count(hidden.ownershipReportsAboutOthers, "ownership report about another company", "ownership reports about other companies"),
221
+ count(hidden.otherFunds ?? 0, "filing for the trust's other funds", "filings for the trust's other funds"),
216
222
  ].filter((part): part is string => part != null);
217
223
  return parts.length > 0 ? `${parts.join(" and ")} hidden, --all to show` : null;
218
224
  }