gloomberb 0.20.4 → 0.20.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 (316) hide show
  1. package/README.md +3 -1
  2. package/README.zh-CN.md +1 -1
  3. package/bin/gloom +9 -0
  4. package/bin/without-bun.cjs +98 -0
  5. package/package.json +4 -1
  6. package/src/api-client/data.ts +148 -37
  7. package/src/api-client/hk-tenders.ts +59 -0
  8. package/src/api-client/index.ts +1 -0
  9. package/src/api-client/types/econ.ts +30 -0
  10. package/src/api-client/yield-curves.ts +1 -1
  11. package/src/app/global-shortcuts.ts +4 -1
  12. package/src/app/keybindings/actions.ts +6 -0
  13. package/src/app/keybindings/config.ts +2 -1
  14. package/src/app/keybindings/index.ts +1 -0
  15. package/src/app/keybindings/labels.ts +6 -1
  16. package/src/app/keybindings/resolve.ts +23 -4
  17. package/src/app/keybindings/terminal-keys.ts +35 -0
  18. package/src/app/pane-runtime/index.tsx +2 -2
  19. package/src/app/pane-runtime/ticker-open-runtime.ts +68 -40
  20. package/src/app.tsx +18 -13
  21. package/src/architecture/floating-promise-allowlist.json +313 -0
  22. package/src/architecture/ui-literals-allowlist.json +1 -1
  23. package/src/capabilities/chart-series.ts +27 -1
  24. package/src/cli/commands/keybindings.ts +5 -5
  25. package/src/cli/commands/market.ts +238 -57
  26. package/src/cli/commands/news-search.ts +81 -14
  27. package/src/cli/commands/overview.ts +27 -6
  28. package/src/cli/commands/remote.ts +16 -17
  29. package/src/cli/commands/system.ts +1 -1
  30. package/src/cli/commands/ticker.ts +3 -1
  31. package/src/cli/early-command.ts +2 -0
  32. package/src/cli/errors.ts +10 -1
  33. package/src/cli/fx-forward.ts +89 -7
  34. package/src/cli/fx-pair.ts +1 -1
  35. package/src/cli/fx-quote-rate.ts +23 -0
  36. package/src/cli/glossary.ts +19 -5
  37. package/src/cli/help.ts +1 -0
  38. package/src/cli/history-rows.ts +5 -3
  39. package/src/cli/index-roots.ts +5 -4
  40. package/src/cli/index.ts +40 -3
  41. package/src/cli/known-gaps.ts +38 -9
  42. package/src/cli/listing-arg.ts +17 -5
  43. package/src/cli/name-entries.ts +5 -1
  44. package/src/cli/not-a-ticker.ts +4 -0
  45. package/src/cli/options.ts +52 -3
  46. package/src/cli/output-file.ts +5 -3
  47. package/src/cli/pane-functions/catalog.ts +15 -0
  48. package/src/cli/pane-functions/function-help.ts +4 -4
  49. package/src/cli/pane-functions/headless.ts +9 -4
  50. package/src/cli/pane-functions/index.ts +6 -4
  51. package/src/cli/pane-functions/resolver.ts +2 -2
  52. package/src/cli/result.ts +21 -2
  53. package/src/cli/spreadsheet-hint.ts +7 -3
  54. package/src/cli/treasury-yields.ts +5 -3
  55. package/src/components/chart/composite/legend.tsx +40 -2
  56. package/src/components/command-bar/pane-settings.ts +2 -2
  57. package/src/components/command-bar/routes/root/results.ts +6 -2
  58. package/src/components/command-bar/workflow/tickers.ts +2 -2
  59. package/src/components/data-table/view.tsx +9 -2
  60. package/src/components/input-search-bar.tsx +9 -2
  61. package/src/components/layout/pane/header.tsx +2 -0
  62. package/src/components/layout/shell/pane/capture.ts +4 -1
  63. package/src/components/layout/status-bar.tsx +6 -1
  64. package/src/components/onboarding/first-run-workspace.ts +44 -2
  65. package/src/components/onboarding/onboarding-frame.tsx +11 -2
  66. package/src/components/onboarding/onboarding-keyboard.ts +16 -0
  67. package/src/components/onboarding/onboarding-wizard.tsx +8 -8
  68. package/src/components/onboarding/portfolio-step/positions-panel.tsx +62 -1
  69. package/src/components/onboarding/use-onboarding-progress.ts +12 -4
  70. package/src/components/pane-settings-dialog/desktop.tsx +2 -2
  71. package/src/components/pane-settings-dialog/tui.tsx +2 -2
  72. package/src/components/pane-settings-dialog/value.ts +6 -0
  73. package/src/components/pane-settings-dialog.tsx +3 -3
  74. package/src/components/reader/detail-reader.tsx +4 -0
  75. package/src/components/ui/data-table/opentui/index.tsx +11 -4
  76. package/src/components/ui/data-table/opentui/model.ts +8 -6
  77. package/src/components/ui/data-table/types.ts +6 -1
  78. package/src/components/ui/index.ts +1 -1
  79. package/src/components/ui/page-stack-view.tsx +3 -0
  80. package/src/components/ui/pane-link-chip.tsx +269 -54
  81. package/src/components/ui/query-bar.tsx +2 -1
  82. package/src/components/ui/table-layout.ts +38 -1
  83. package/src/components/ui/tabs.tsx +97 -19
  84. package/src/core/state/app/layout-reducer.ts +7 -0
  85. package/src/core/state/app/layout.ts +44 -7
  86. package/src/core/state/app/state.ts +1 -1
  87. package/src/core/state/app/types.ts +22 -2
  88. package/src/docs/snapshot.json +30 -13
  89. package/src/market-data/depositary-pair.ts +5 -3
  90. package/src/market-data/market/change-basis.ts +9 -5
  91. package/src/market-data/market/dated-previous-close.ts +147 -17
  92. package/src/market-data/market/status.ts +17 -1
  93. package/src/market-data/quotes/contributions.ts +2 -0
  94. package/src/market-data/quotes/listing-enterprise-value.ts +50 -0
  95. package/src/plugins/builtin/alerts/metric-data.ts +15 -2
  96. package/src/plugins/builtin/analytics/risk-client.ts +10 -4
  97. package/src/plugins/builtin/analytics/risk-episodes.ts +5 -4
  98. package/src/plugins/builtin/analytics/risk-headless.ts +4 -2
  99. package/src/plugins/builtin/analytics/risk-sectors.ts +91 -0
  100. package/src/plugins/builtin/awards/index.tsx +1 -1
  101. package/src/plugins/builtin/backtest/headless.ts +1 -1
  102. package/src/plugins/builtin/buildout/index.tsx +1 -0
  103. package/src/plugins/builtin/catalysts/index.tsx +2 -2
  104. package/src/plugins/builtin/cds/headless.ts +4 -0
  105. package/src/plugins/builtin/cds/model.ts +0 -6
  106. package/src/plugins/builtin/chart-composer/formula.ts +16 -3
  107. package/src/plugins/builtin/chart-composer/headless-schema.ts +2 -0
  108. package/src/plugins/builtin/chart-composer/headless.ts +4 -2
  109. package/src/plugins/builtin/chart-composer/index.tsx +1 -0
  110. package/src/plugins/builtin/chart-composer/presets.ts +1 -0
  111. package/src/plugins/builtin/chat/content/composer.tsx +5 -4
  112. package/src/plugins/builtin/chat/content/index.tsx +12 -2
  113. package/src/plugins/builtin/chat/content/layout-metrics.ts +3 -3
  114. package/src/plugins/builtin/chat/content/open-targets.ts +3 -3
  115. package/src/plugins/builtin/chat/layout.ts +5 -2
  116. package/src/plugins/builtin/chat/message/pane-chip.tsx +61 -40
  117. package/src/plugins/builtin/chat/message/terminal.tsx +13 -15
  118. package/src/plugins/builtin/chat/pane-links/previews.ts +51 -5
  119. package/src/plugins/builtin/chat/pane-links/share-card.ts +36 -0
  120. package/src/plugins/builtin/cloud/askg/pane.tsx +55 -13
  121. package/src/plugins/builtin/cloud/askg/tool-display.ts +1 -0
  122. package/src/plugins/builtin/cloud/terminal-relay/redact.ts +5 -3
  123. package/src/plugins/builtin/commodity-balances/index.tsx +1 -0
  124. package/src/plugins/builtin/company-attention/index.tsx +1 -1
  125. package/src/plugins/builtin/company-kpis/headless.ts +3 -1
  126. package/src/plugins/builtin/company-kpis/index.tsx +2 -2
  127. package/src/plugins/builtin/cot/index.tsx +1 -1
  128. package/src/plugins/builtin/cpi/index.tsx +1 -1
  129. package/src/plugins/builtin/credit-boards/cdx-pane.tsx +20 -7
  130. package/src/plugins/builtin/credit-boards/client.ts +8 -0
  131. package/src/plugins/builtin/credit-boards/headless.ts +4 -1
  132. package/src/plugins/builtin/credit-boards/model.ts +58 -4
  133. package/src/plugins/builtin/credit-boards/series.ts +63 -6
  134. package/src/plugins/builtin/credit-boards/sovr-pane.tsx +3 -2
  135. package/src/plugins/builtin/credit-conditions/headless.ts +24 -6
  136. package/src/plugins/builtin/credit-conditions/index.tsx +1 -1
  137. package/src/plugins/builtin/credit-conditions/model.ts +12 -6
  138. package/src/plugins/builtin/credit-conditions/series.ts +2 -1
  139. package/src/plugins/builtin/crypto-board/index.tsx +1 -0
  140. package/src/plugins/builtin/dividend-yield/index.tsx +1 -0
  141. package/src/plugins/builtin/doe/index.tsx +1 -1
  142. package/src/plugins/builtin/earnings-calls/headless.ts +5 -1
  143. package/src/plugins/builtin/earnings-calls/index.tsx +1 -0
  144. package/src/plugins/builtin/econ/calendar-model.ts +115 -8
  145. package/src/plugins/builtin/econ/calendar-source.ts +7 -1
  146. package/src/plugins/builtin/econ/fred-catalog.ts +3 -1
  147. package/src/plugins/builtin/econ/index.tsx +42 -8
  148. package/src/plugins/builtin/econ/types.ts +3 -0
  149. package/src/plugins/builtin/econ-statistics/index.tsx +1 -0
  150. package/src/plugins/builtin/econ-statistics/pane.tsx +6 -0
  151. package/src/plugins/builtin/estimate-revisions/index.tsx +1 -0
  152. package/src/plugins/builtin/executives/index.tsx +1 -0
  153. package/src/plugins/builtin/filing-events/index.tsx +1 -0
  154. package/src/plugins/builtin/fixed-income/index.tsx +3 -0
  155. package/src/plugins/builtin/futures-curve/headless.ts +3 -3
  156. package/src/plugins/builtin/futures-curve/index.tsx +1 -1
  157. package/src/plugins/builtin/futures-curve/model.ts +18 -0
  158. package/src/plugins/builtin/fx-matrix/index.tsx +44 -14
  159. package/src/plugins/builtin/gpu/index.tsx +1 -1
  160. package/src/plugins/builtin/help/functions-table.tsx +1 -1
  161. package/src/plugins/builtin/help/index.tsx +11 -1
  162. package/src/plugins/builtin/help/keybindings-editor.tsx +7 -3
  163. package/src/plugins/builtin/holders/index.tsx +1 -0
  164. package/src/plugins/builtin/holders/report-header.ts +2 -2
  165. package/src/plugins/builtin/insider/index.tsx +1 -0
  166. package/src/plugins/builtin/iv-history/index.tsx +1 -1
  167. package/src/plugins/builtin/jobs/index.tsx +1 -0
  168. package/src/plugins/builtin/macro-day/headless.ts +27 -8
  169. package/src/plugins/builtin/macro-day/index.tsx +1 -1
  170. package/src/plugins/builtin/macro-day/model.ts +19 -3
  171. package/src/plugins/builtin/macro-day/pane.tsx +14 -9
  172. package/src/plugins/builtin/macro-day/releases.ts +25 -7
  173. package/src/plugins/builtin/market-valuation/index.tsx +1 -0
  174. package/src/plugins/builtin/market-valuation/pane.tsx +8 -0
  175. package/src/plugins/builtin/members/index.tsx +1 -1
  176. package/src/plugins/builtin/mna/index.tsx +1 -0
  177. package/src/plugins/builtin/news/index.tsx +1 -0
  178. package/src/plugins/builtin/news/wire/index.tsx +5 -1
  179. package/src/plugins/builtin/news/wire/news/detail-view.tsx +4 -0
  180. package/src/plugins/builtin/news/wire/news/list-search.ts +5 -2
  181. package/src/plugins/builtin/options/index.tsx +1 -0
  182. package/src/plugins/builtin/options-positioning/index.tsx +1 -0
  183. package/src/plugins/builtin/pe-band/index.tsx +1 -1
  184. package/src/plugins/builtin/portfolio-list/cli/portfolio-command.ts +25 -0
  185. package/src/plugins/builtin/portfolio-list/cli/render.ts +20 -3
  186. package/src/plugins/builtin/portfolio-list/cli/watchlist-command.ts +5 -1
  187. package/src/plugins/builtin/portfolio-list/headless.ts +15 -6
  188. package/src/plugins/builtin/power/index.tsx +1 -1
  189. package/src/plugins/builtin/realized-vol/index.tsx +1 -1
  190. package/src/plugins/builtin/research/headless-schema.ts +4 -3
  191. package/src/plugins/builtin/research/headless.ts +10 -4
  192. package/src/plugins/builtin/research/index.tsx +4 -0
  193. package/src/plugins/builtin/research/relative-valuation-columns.ts +145 -47
  194. package/src/plugins/builtin/research/relative-valuation-currency.ts +31 -0
  195. package/src/plugins/builtin/research/relative-valuation-headless.ts +25 -8
  196. package/src/plugins/builtin/research/relative-valuation-model.ts +40 -9
  197. package/src/plugins/builtin/research/relative-valuation-pane.tsx +3 -2
  198. package/src/plugins/builtin/research/relative-valuation-peers.ts +2 -2
  199. package/src/plugins/builtin/research-search/index.tsx +1 -0
  200. package/src/plugins/builtin/research-search/pane.tsx +8 -0
  201. package/src/plugins/builtin/revenue-breakdown/index.tsx +1 -0
  202. package/src/plugins/builtin/reverse-dcf/index.tsx +1 -1
  203. package/src/plugins/builtin/risk-factors/index.tsx +1 -0
  204. package/src/plugins/builtin/scanner/headless.ts +52 -13
  205. package/src/plugins/builtin/seasonality/index.tsx +1 -1
  206. package/src/plugins/builtin/sec/index.tsx +1 -0
  207. package/src/plugins/builtin/series-inventory.ts +1 -1
  208. package/src/plugins/builtin/shared/scanner-capture.ts +11 -3
  209. package/src/plugins/builtin/shared/series-list-detail.tsx +5 -0
  210. package/src/plugins/builtin/short-interest/index.tsx +1 -0
  211. package/src/plugins/builtin/social-mentions/index.tsx +1 -1
  212. package/src/plugins/builtin/supply-chain/index.tsx +1 -0
  213. package/src/plugins/builtin/thirteenf/api.ts +47 -4
  214. package/src/plugins/builtin/thirteenf/data.ts +43 -10
  215. package/src/plugins/builtin/thirteenf/headless.ts +55 -11
  216. package/src/plugins/builtin/thirteenf/model.ts +25 -9
  217. package/src/plugins/builtin/thirteenf/report-notes.ts +27 -6
  218. package/src/plugins/builtin/thirteenf/types.ts +2 -0
  219. package/src/plugins/builtin/ticker-detail/adr-pair/model.ts +1 -1
  220. package/src/plugins/builtin/ticker-detail/data-panes/historical-prices.tsx +8 -7
  221. package/src/plugins/builtin/ticker-detail/data-panes/history-bars.ts +8 -5
  222. package/src/plugins/builtin/ticker-detail/financials/model.ts +18 -2
  223. package/src/plugins/builtin/ticker-detail/financials/ratio-table.tsx +3 -3
  224. package/src/plugins/builtin/ticker-detail/financials/tab.tsx +6 -6
  225. package/src/plugins/builtin/ticker-detail/headless.ts +24 -17
  226. package/src/plugins/builtin/ticker-detail/index.tsx +4 -0
  227. package/src/plugins/builtin/ticker-detail/overview/model.ts +6 -4
  228. package/src/plugins/builtin/ticker-detail/overview-tab.tsx +6 -4
  229. package/src/plugins/builtin/time-sales/client.ts +9 -11
  230. package/src/plugins/builtin/time-sales/index.tsx +1 -1
  231. package/src/plugins/builtin/treasury-auctions/after.ts +267 -0
  232. package/src/plugins/builtin/treasury-auctions/cache.ts +54 -5
  233. package/src/plugins/builtin/treasury-auctions/client.ts +33 -2
  234. package/src/plugins/builtin/treasury-auctions/headless.ts +150 -22
  235. package/src/plugins/builtin/treasury-auctions/hk-headless.ts +126 -0
  236. package/src/plugins/builtin/treasury-auctions/hk-view.tsx +347 -0
  237. package/src/plugins/builtin/treasury-auctions/hk.ts +363 -0
  238. package/src/plugins/builtin/treasury-auctions/index.tsx +27 -4
  239. package/src/plugins/builtin/treasury-auctions/model.ts +264 -28
  240. package/src/plugins/builtin/treasury-auctions/pane.tsx +176 -41
  241. package/src/plugins/builtin/treasury-auctions/treasury-direct.ts +5 -2
  242. package/src/plugins/builtin/treasury-auctions/types.ts +7 -1
  243. package/src/plugins/builtin/vol-surface/index.tsx +1 -1
  244. package/src/plugins/builtin/world-venue-map/index.ts +1 -0
  245. package/src/plugins/builtin/yield-curve/curves.ts +10 -4
  246. package/src/plugins/builtin/yield-curve/headless.ts +6 -2
  247. package/src/plugins/builtin/yield-curve/index.tsx +3 -3
  248. package/src/plugins/builtin/yield-curve/series.ts +10 -0
  249. package/src/plugins/builtin/yield-curve/world.ts +3 -1
  250. package/src/portfolio/collection-name.ts +22 -0
  251. package/src/portfolio/column-values.ts +2 -1
  252. package/src/public/__snapshots__/public-api.test.ts.snap +4 -0
  253. package/src/public/remote.ts +7 -1
  254. package/src/remote/client.ts +191 -11
  255. package/src/remote/controller-utils.ts +13 -1
  256. package/src/remote/controller.ts +88 -26
  257. package/src/remote/endpoint.ts +24 -0
  258. package/src/remote/form.ts +59 -4
  259. package/src/remote/resources.ts +44 -18
  260. package/src/remote/schema.ts +21 -9
  261. package/src/remote/secrets.ts +12 -0
  262. package/src/remote/semantic-tree.tsx +14 -2
  263. package/src/remote/server.ts +2 -1
  264. package/src/remote/surface.tsx +192 -0
  265. package/src/remote/types.ts +5 -0
  266. package/src/renderers/dom/data-table/frozen-column.ts +3 -1
  267. package/src/renderers/dom/data-table/index.tsx +27 -9
  268. package/src/renderers/dom/data-table/row.tsx +2 -0
  269. package/src/renderers/electrobun/bun/desktop/backend.ts +27 -24
  270. package/src/renderers/electrobun/bun/desktop/detached-windows.ts +3 -3
  271. package/src/renderers/electrobun/bun/desktop/snapshot-commit.ts +77 -0
  272. package/src/renderers/electrobun/shared/protocol.ts +4 -0
  273. package/src/renderers/electrobun/view/backend-rpc.ts +3 -0
  274. package/src/renderers/electrobun/view/desktop/window/bridge.ts +3 -0
  275. package/src/renderers/opentui/host.tsx +6 -0
  276. package/src/series/standalone.ts +2 -2
  277. package/src/shares/api.ts +21 -4
  278. package/src/shares/item.ts +73 -0
  279. package/src/shares/pane-item.ts +205 -0
  280. package/src/shares/pane.ts +4 -0
  281. package/src/shares/payload.ts +9 -5
  282. package/src/sources/gloomberb-cloud/news.ts +2 -0
  283. package/src/sources/gloomberb-cloud/normalizers.ts +9 -5
  284. package/src/sources/provider-router/cache.ts +3 -1
  285. package/src/sync/controller.ts +17 -2
  286. package/src/sync/other-window-tabs.ts +32 -1
  287. package/src/sync/react.ts +4 -4
  288. package/src/tickers/renamed-listings.ts +105 -0
  289. package/src/tickers/search/index.ts +103 -16
  290. package/src/time-series/bar-spacing.ts +33 -0
  291. package/src/time-series/base-series.ts +21 -3
  292. package/src/time-series/chart-bounds.ts +31 -0
  293. package/src/time-series/field-catalog.ts +17 -0
  294. package/src/time-series/fundamentals.ts +143 -11
  295. package/src/time-series/ice-credit.ts +32 -6
  296. package/src/time-series/resolve.ts +11 -7
  297. package/src/time-series/session-bar.ts +78 -9
  298. package/src/time-series/studies/formula.ts +53 -10
  299. package/src/time-series/studies/pair.ts +18 -7
  300. package/src/time-series/studies/units.ts +49 -2
  301. package/src/time-series/types.ts +12 -0
  302. package/src/types/desktop-window.ts +2 -0
  303. package/src/types/financials.ts +7 -0
  304. package/src/types/headless.ts +8 -0
  305. package/src/types/plugin-pane-settings.ts +2 -0
  306. package/src/types/plugin-panes.ts +22 -0
  307. package/src/utils/central-banks.ts +86 -1
  308. package/src/utils/cli-output.ts +6 -3
  309. package/src/utils/datetime-format.ts +12 -3
  310. package/src/utils/depositary-receipt.ts +28 -3
  311. package/src/utils/ebitda.ts +128 -0
  312. package/src/utils/format.ts +1 -1
  313. package/src/utils/fundamentals.ts +14 -0
  314. package/src/utils/max-drawdown.ts +97 -16
  315. package/src/utils/shell-word.ts +13 -0
  316. package/src/utils/untrusted-text.ts +29 -0
@@ -1,7 +1,6 @@
1
1
  import Electrobun, { ApplicationMenu, BrowserView, Screen, Utils, type BrowserWindow } from "electrobun/bun";
2
2
  import { homedir } from "os";
3
3
  import { createAppServices, type AppServices } from "../../../../core/app-services";
4
- import { syncConfigActiveLayoutState, type PaneRuntimeState } from "../../../../core/state/app/state";
5
4
  import {
6
5
  APP_SESSION_ID,
7
6
  APP_SESSION_SCHEMA_VERSION,
@@ -77,6 +76,13 @@ import { scheduleDesktopRelaunch } from "./relaunch";
77
76
  import { createDesktopRpcRegistry } from "./rpc-registry";
78
77
  import { measureRpcTraffic } from "./rpc-timing";
79
78
  import { DesktopStateBroadcaster } from "./state-broadcaster";
79
+ import {
80
+ commitDesktopSnapshot,
81
+ commitDesktopSnapshotInBackground,
82
+ syncActiveLayout,
83
+ type DesktopSnapshotCommitHost,
84
+ type DesktopSnapshotCommitOptions,
85
+ } from "./snapshot-commit";
80
86
  import { createDesktopWorkspace, type DesktopWorkspace } from "./workspace";
81
87
  import { handleDesktopWorkspaceRequest } from "./workspace/requests";
82
88
 
@@ -105,14 +111,6 @@ function isGloomberbDeepLink(rawUrl: string): boolean {
105
111
  }
106
112
  }
107
113
 
108
- function syncActiveLayout(
109
- config: AppConfig,
110
- paneState: Record<string, PaneRuntimeState> = config.layouts[config.activeLayoutIndex]?.paneState ?? {},
111
- focusedPaneId: string | null = config.layouts[config.activeLayoutIndex]?.focusedPaneId ?? null,
112
- ): AppConfig {
113
- return syncConfigActiveLayoutState(config, paneState, focusedPaneId);
114
- }
115
-
116
114
  /**
117
115
  * Everything the desktop Bun process holds for its windows: the config and
118
116
  * services they share, the workspace that owns popped-out panes, the native
@@ -391,7 +389,7 @@ export class DesktopBackend {
391
389
  if (this.quitting) return;
392
390
  const workspace = this.workspace;
393
391
  if (!workspace || !workspace.windowIds().includes(windowId)) return;
394
- void this.commitDesktopSnapshot(workspace.closeWindow(windowId));
392
+ this.commitDesktopSnapshotInBackground(workspace.closeWindow(windowId));
395
393
  }
396
394
 
397
395
  /** What a closed full window held: its streams, its channel. */
@@ -512,22 +510,27 @@ export class DesktopBackend {
512
510
  this.services = null;
513
511
  }
514
512
 
515
- async commitDesktopSnapshot(
513
+ private readonly snapshotCommits: DesktopSnapshotCommitHost = {
514
+ setConfig: (config) => this.setConfig(config),
515
+ replaceConfig: (config, options) => { this.requireWorkspace().replaceConfig(config, options); },
516
+ currentSnapshot: () => this.requireWorkspace().getSnapshot(),
517
+ saveConfig: (config) => saveConfig(config),
518
+ reconcileWindows: () => this.reconcileWindows(),
519
+ broadcastState: (snapshot) => this.stateBroadcaster.sendDesktopState(snapshot),
520
+ sendWindowList: () => this.sendWindowList(),
521
+ reportSaveFailure: () => { this.readyMainWindowRpc()?.send["desktop.saveFailed"]({}); },
522
+ };
523
+
524
+ commitDesktopSnapshot(
516
525
  snapshot: DesktopSharedStateSnapshot,
517
- options: { persistConfig?: boolean; reconcileWindows?: boolean } = {},
526
+ options: DesktopSnapshotCommitOptions = {},
518
527
  ): Promise<DesktopSharedStateSnapshot> {
519
- const nextConfig = syncActiveLayout(snapshot.config, snapshot.paneState, snapshot.focusedPaneId);
520
- this.setConfig(nextConfig);
521
- this.requireWorkspace().replaceConfig(nextConfig, { layoutChanged: snapshot.layoutChanged });
522
- if (options.persistConfig !== false) {
523
- await saveConfig(nextConfig);
524
- }
525
- if (options.reconcileWindows !== false) {
526
- this.reconcileWindows();
527
- }
528
- this.stateBroadcaster.sendDesktopState(this.requireWorkspace().getSnapshot());
529
- this.sendWindowList();
530
- return this.requireWorkspace().getSnapshot();
528
+ return commitDesktopSnapshot(this.snapshotCommits, snapshot, options);
529
+ }
530
+
531
+ /** For a change no request waits on: a failure is logged and the main window says so. */
532
+ commitDesktopSnapshotInBackground(snapshot: DesktopSharedStateSnapshot, options: DesktopSnapshotCommitOptions = {}): void {
533
+ commitDesktopSnapshotInBackground(this.snapshotCommits, snapshot, options);
531
534
  }
532
535
 
533
536
  /** Stops what a closed window was streaming or subscribed to. */
@@ -80,7 +80,7 @@ export class DesktopDetachedWindowManager {
80
80
  const workspace = this.backend.workspace;
81
81
  const config = this.backend.config;
82
82
  if (!workspace || !config || !isPaneDetached(config.layout, instanceId)) return;
83
- void this.backend.commitDesktopSnapshot(workspace.closeDetachedPane(instanceId));
83
+ this.backend.commitDesktopSnapshotInBackground(workspace.closeDetachedPane(instanceId));
84
84
  }
85
85
 
86
86
  /**
@@ -264,7 +264,7 @@ export class DesktopDetachedWindowManager {
264
264
  const nextConfig = this.backend.config;
265
265
  const nextWorkspace = this.backend.workspace;
266
266
  if (!nextConfig || !nextWorkspace || !isPaneDetached(nextConfig.layout, instanceId)) return;
267
- void this.backend.commitDesktopSnapshot(
267
+ this.backend.commitDesktopSnapshotInBackground(
268
268
  this.backend.requireWorkspace().updateDetachedFrame(instanceId, frame),
269
269
  { reconcileWindows: false },
270
270
  );
@@ -302,7 +302,7 @@ export class DesktopDetachedWindowManager {
302
302
  || this.backend.stateBroadcaster.currentDockPreview.edge !== edge
303
303
  ) return;
304
304
  this.backend.stateBroadcaster.clearDockPreview(instanceId);
305
- void this.backend.commitDesktopSnapshot(this.backend.requireWorkspace().dockDetachedPane(instanceId, edge));
305
+ this.backend.commitDesktopSnapshotInBackground(this.backend.requireWorkspace().dockDetachedPane(instanceId, edge));
306
306
  }, 120));
307
307
  }
308
308
 
@@ -0,0 +1,77 @@
1
+ import { syncConfigActiveLayoutState, type PaneRuntimeState } from "../../../../core/state/app/state";
2
+ import type { AppConfig } from "../../../../types/config";
3
+ import type { DesktopSharedStateSnapshot } from "../../../../types/desktop-window";
4
+ import { logFailure } from "../../../../utils/log-failure";
5
+
6
+ export function syncActiveLayout(
7
+ config: AppConfig,
8
+ paneState: Record<string, PaneRuntimeState> = config.layouts[config.activeLayoutIndex]?.paneState ?? {},
9
+ focusedPaneId: string | null = config.layouts[config.activeLayoutIndex]?.focusedPaneId ?? null,
10
+ ): AppConfig {
11
+ return syncConfigActiveLayoutState(config, paneState, focusedPaneId);
12
+ }
13
+
14
+ /** What a desktop state change touches in the backend. */
15
+ export interface DesktopSnapshotCommitHost {
16
+ setConfig(config: AppConfig): void;
17
+ replaceConfig(config: AppConfig, options: { layoutChanged?: boolean }): void;
18
+ currentSnapshot(): DesktopSharedStateSnapshot;
19
+ saveConfig(config: AppConfig): Promise<void>;
20
+ reconcileWindows(): void;
21
+ broadcastState(snapshot: DesktopSharedStateSnapshot): void;
22
+ sendWindowList(): void;
23
+ /** Tells the person a change nobody waited on was not saved. */
24
+ reportSaveFailure(): void;
25
+ }
26
+
27
+ export interface DesktopSnapshotCommitOptions {
28
+ persistConfig?: boolean;
29
+ reconcileWindows?: boolean;
30
+ }
31
+
32
+ /**
33
+ * Makes a state change the backend's, saves its config and shows it in every
34
+ * window. The windows follow even when the save fails: the backend holds the
35
+ * change already, and a window left on the old state would send it back. The
36
+ * failed save rejects after that.
37
+ */
38
+ export async function commitDesktopSnapshot(
39
+ host: DesktopSnapshotCommitHost,
40
+ snapshot: DesktopSharedStateSnapshot,
41
+ options: DesktopSnapshotCommitOptions = {},
42
+ ): Promise<DesktopSharedStateSnapshot> {
43
+ const nextConfig = syncActiveLayout(snapshot.config, snapshot.paneState, snapshot.focusedPaneId);
44
+ host.setConfig(nextConfig);
45
+ host.replaceConfig(nextConfig, { layoutChanged: snapshot.layoutChanged });
46
+ let saveFailure: { error: unknown } | null = null;
47
+ if (options.persistConfig !== false) {
48
+ try {
49
+ await host.saveConfig(nextConfig);
50
+ } catch (error) {
51
+ saveFailure = { error };
52
+ }
53
+ }
54
+ if (options.reconcileWindows !== false) {
55
+ host.reconcileWindows();
56
+ }
57
+ host.broadcastState(host.currentSnapshot());
58
+ host.sendWindowList();
59
+ if (saveFailure) throw saveFailure.error;
60
+ return host.currentSnapshot();
61
+ }
62
+
63
+ /**
64
+ * A change no request waits on: a window or popped-out pane closed, a pane
65
+ * docked or moved by dragging. A failure is logged, and the main window says
66
+ * the change was not saved.
67
+ */
68
+ export function commitDesktopSnapshotInBackground(
69
+ host: DesktopSnapshotCommitHost,
70
+ snapshot: DesktopSharedStateSnapshot,
71
+ options: DesktopSnapshotCommitOptions = {},
72
+ ): void {
73
+ commitDesktopSnapshot(host, snapshot, options).catch((error: unknown) => {
74
+ logFailure("desktop-backend", "Saving a window change failed")(error);
75
+ host.reportSaveFailure();
76
+ });
77
+ }
@@ -377,6 +377,9 @@ interface DesktopWindowVisibilityMessage {
377
377
  visible: boolean;
378
378
  }
379
379
 
380
+ /** A window change no request waited on (a window closed, a pane docked) could not be saved; to the main window. */
381
+ type DesktopSaveFailedMessage = Record<string, never>;
382
+
380
383
  /** Plugin folders the Bun process updated in the background, for the main window to bring into its session. */
381
384
  interface PluginsUpdatedMessage {
382
385
  directories: string[];
@@ -423,6 +426,7 @@ export interface ElectrobunDesktopRpcSchema {
423
426
  "desktop.otherWindowTabs": DesktopOtherWindowTabsMessage;
424
427
  "desktop.focusPane": DesktopFocusPaneMessage;
425
428
  "desktop.windowVisibility": DesktopWindowVisibilityMessage;
429
+ "desktop.saveFailed": DesktopSaveFailedMessage;
426
430
  "plugins.updated": PluginsUpdatedMessage;
427
431
  "plugins.seedProgress": PluginSeedProgressMessage;
428
432
  "update.progress": UpdateProgressMessage;
@@ -101,6 +101,9 @@ const rpc = Electroview.defineRPC<ElectrobunDesktopRpcSchema>({
101
101
  "desktop.windowVisibility": (message) => {
102
102
  emit("desktop.windowVisibility", { visible: message?.visible !== false });
103
103
  },
104
+ "desktop.saveFailed": () => {
105
+ emit("desktop.saveFailed", {});
106
+ },
104
107
  "update.progress": (message) => {
105
108
  emit("update.progress", { progress: decodeRpcValue(message.progress) });
106
109
  },
@@ -124,5 +124,8 @@ export function createDesktopWindowBridge(kind: "main" | "detached", paneId?: st
124
124
  listener(message.preview);
125
125
  });
126
126
  },
127
+ subscribeSaveFailures: kind === "main"
128
+ ? (listener: () => void) => onBackendMessage("desktop.saveFailed", () => listener())
129
+ : undefined,
127
130
  };
128
131
  }
@@ -11,6 +11,7 @@ import { buildTerminalMediaArgs, createTerminalMediaReaper, terminalMediaStateFi
11
11
  import { saveTextFileToDownloads } from "../../utils/save-text-file";
12
12
  import { installInteractionPerformanceRecorder } from "./interaction-performance";
13
13
  import { provideKittyServices } from "./kitty-services";
14
+ import { setTerminalReportsControlKeys } from "../../app/keybindings/terminal-keys";
14
15
  import { captureRendererFrame } from "./frame-capture";
15
16
  import {
16
17
  createTimerFrameDriver,
@@ -120,6 +121,11 @@ export async function createOpenTuiHost(): Promise<OpenTuiHost> {
120
121
  // at 11 is not a leak here, and it prints over the panes.
121
122
  renderer.setMaxListeners(0);
122
123
  installResolutionEventBridge(renderer);
124
+ // Whether Control reaches a digit, once the terminal has answered: the
125
+ // layout tabs name Alt+1 where it does not. Unknown until then.
126
+ renderer.on("capabilities", (capabilities: { kitty_keyboard?: boolean } | null) => {
127
+ setTerminalReportsControlKeys(capabilities?.kitty_keyboard === true);
128
+ });
123
129
  // Streamed quotes apply and notify on one clock of up to 10 Hz: every
124
130
  // visible row stays live while a burst of ticks costs one terminal redraw,
125
131
  // and a layout whose redraws are expensive gets fewer of them.
@@ -1,5 +1,5 @@
1
1
  import { logFailure } from "../utils/log-failure";
2
- import { chartSeriesResolveRequestSchema } from "../capabilities/chart-series";
2
+ import { chartSeriesResolveRequestSchema, uncoveredCapabilityMessage } from "../capabilities/chart-series";
3
3
  import type { CapabilityInvoker } from "../capabilities/types";
4
4
  import type { GloomPlugin } from "../types/plugin";
5
5
  import { resolveRegisteredSeries } from "./capability";
@@ -43,7 +43,7 @@ export function standaloneSeriesInvoker(
43
43
  registry ??= build();
44
44
  const request = chartSeriesResolveRequestSchema.parse(payload);
45
45
  const resolved = await resolveRegisteredSeries(await registry, capabilityId, request.seriesId, request.viewport, options?.signal);
46
- if (!resolved) throw new Error(`Chart series capability "${capabilityId}" is unavailable. Enable its plugin or provider.`);
46
+ if (!resolved) throw new Error(uncoveredCapabilityMessage(capabilityId, request.seriesId));
47
47
  return resolved as T;
48
48
  },
49
49
  };
package/src/shares/api.ts CHANGED
@@ -58,17 +58,28 @@ async function readJson(response: Response): Promise<unknown> {
58
58
  try { return await response.json(); } catch { throw new Error("The share service returned an invalid response."); }
59
59
  }
60
60
 
61
+ /**
62
+ * A service from before shares kept an item refuses one it does not know with
63
+ * a 400: the share is made again without it, as that service would keep it.
64
+ */
65
+ function withoutItem(payload: SharePayload): SharePayload | null {
66
+ return payload.kind === "pane" && payload.item ? { kind: "pane", data: payload.data } : null;
67
+ }
68
+
61
69
  export async function createShare(payload: SharePayload, fetchImpl?: ShareFetch): Promise<CreatedShare> {
62
70
  const validated = parseSharePayload(payload);
63
71
  if (!validated) throw new Error("Invalid share payload.");
64
72
  let body: unknown;
65
73
  if (fetchImpl) {
66
- const response = await fetchImpl(`${SHARE_API_ORIGIN}/shares`, {
74
+ const post = (share: SharePayload) => fetchImpl(`${SHARE_API_ORIGIN}/shares`, {
67
75
  method: "POST",
68
76
  credentials: "include",
69
77
  headers: { "Content-Type": "application/json" },
70
- body: JSON.stringify(validated),
78
+ body: JSON.stringify(share),
71
79
  });
80
+ let response = await post(validated);
81
+ const plain = response.status === 400 ? withoutItem(validated) : null;
82
+ if (plain) response = await post(plain);
72
83
  if (!response.ok) {
73
84
  if (response.status === 401) throw new Error("Sign in to Gloom Cloud to share.");
74
85
  if (response.status === 403) throw new Error("Verify your Gloom Cloud email to share.");
@@ -80,7 +91,13 @@ export async function createShare(payload: SharePayload, fetchImpl?: ShareFetch)
80
91
  // client when an interactive app creates a share, not on every public view.
81
92
  const { apiClient } = await import("../api-client").catch((error: unknown) => { throw shareFailed(error); });
82
93
  try {
83
- body = await apiClient.createTerminalShare(validated);
94
+ try {
95
+ body = await apiClient.createTerminalShare(validated);
96
+ } catch (error) {
97
+ const plain = error instanceof ApiRequestError && error.status === 400 ? withoutItem(validated) : null;
98
+ if (!plain) throw error;
99
+ body = await apiClient.createTerminalShare(plain);
100
+ }
84
101
  } catch (error) {
85
102
  if (error instanceof ApiRequestError && error.status === 401) throw new Error("Sign in to Gloom Cloud to share.");
86
103
  if (error instanceof ApiRequestError && error.status === 403) throw new Error("Verify your Gloom Cloud email to share.");
@@ -112,7 +129,7 @@ export async function getShare(
112
129
  const body = await readJson(response);
113
130
  if (!body || typeof body !== "object") return null;
114
131
  const object = body as Record<string, unknown>;
115
- const payload = parseSharePayload({ kind: object.kind, data: object.data });
132
+ const payload = parseSharePayload({ kind: object.kind, data: object.data, item: object.item });
116
133
  if (!payload || !validDate(object.createdAt) || !validDate(object.expiresAt)) return null;
117
134
  return {
118
135
  ...payload,
@@ -0,0 +1,73 @@
1
+ import { markdownPlainText } from "../utils/markdown";
2
+ import { isRecord } from "../utils/guards";
3
+ import { plainUntrustedLine } from "../utils/untrusted-text";
4
+
5
+ /**
6
+ * What a shared pane was on when it was shared: the story it had open, the
7
+ * result it had picked, the ticker it shows. It goes with the share, beside
8
+ * the pane's settings, so a chat card, a link preview in another app and the
9
+ * chat's bots can say what the link is about without opening it. A pane on
10
+ * nothing in particular shares none.
11
+ */
12
+ export interface ShareItem {
13
+ /** The pane it opens, by name: a reader without that pane (a link preview, a bot) still says which. */
14
+ pane: string;
15
+ title: string;
16
+ /** A sentence or two of what it says: a story's summary, a result's snippet. */
17
+ excerpt?: string;
18
+ }
19
+
20
+ const SHARE_ITEM_LIMITS = { pane: 80, title: 200, excerpt: 300 } as const;
21
+ /** About two lines of a chat card and what link previews show of a description. */
22
+ const EXCERPT_LENGTH = 240;
23
+
24
+ /** One line of plain text, as the share service keeps it and every reader draws it (untrusted-text.ts). */
25
+ const oneLine = plainUntrustedLine;
26
+
27
+ /** `text` cut to `max` characters at a word, with an ellipsis when it was cut. */
28
+ function clip(text: string, max: number): string {
29
+ if (text.length <= max) return text;
30
+ const cut = text.slice(0, max - 1);
31
+ const space = cut.lastIndexOf(" ");
32
+ return `${(space > max * 0.6 ? cut.slice(0, space) : cut).replace(/[\s,;:.-]+$/, "")}…`;
33
+ }
34
+
35
+ /** The opening of a text as one line: its first paragraph, cut to about two lines. */
36
+ export function shareItemExcerpt(text: string | null | undefined, { markdown = false, max = EXCERPT_LENGTH } = {}): string | undefined {
37
+ if (!text) return undefined;
38
+ const plain = markdown ? markdownPlainText(text, { links: true }) : text;
39
+ const paragraph = plain.split(/\n\s*\n/).map(oneLine).find(Boolean);
40
+ return paragraph ? clip(paragraph, Math.min(max, SHARE_ITEM_LIMITS.excerpt)) : undefined;
41
+ }
42
+
43
+ /** The item as it is kept: one line each, within the limits, or null without a title. */
44
+ export function shareItem(pane: string, part: { title?: string | null; excerpt?: string | null } | null | undefined): ShareItem | null {
45
+ const title = part?.title ? clip(oneLine(part.title), SHARE_ITEM_LIMITS.title) : "";
46
+ const name = clip(oneLine(pane), SHARE_ITEM_LIMITS.pane);
47
+ if (!title || !name) return null;
48
+ const excerpt = part?.excerpt ? clip(oneLine(part.excerpt), SHARE_ITEM_LIMITS.excerpt) : "";
49
+ return { pane: name, title, ...(excerpt && excerpt !== title ? { excerpt } : {}) };
50
+ }
51
+
52
+ /** `value` as one line of plain text within `max`, or null when it is not text, says nothing, or is over. */
53
+ function boundedText(value: unknown, max: number): string | null {
54
+ if (typeof value !== "string") return null;
55
+ const text = oneLine(value);
56
+ return text && text.length <= max ? text : null;
57
+ }
58
+
59
+ /**
60
+ * An item read back from a share, or null for anything else. Another person's
61
+ * app wrote it, so its text is made plain again here, whatever the service
62
+ * kept: no escape sequence, control, bidi or zero-width character reaches a
63
+ * card.
64
+ */
65
+ export function parseShareItem(value: unknown): ShareItem | null {
66
+ if (!isRecord(value) || !Object.keys(value).every((key) => key === "pane" || key === "title" || key === "excerpt")) return null;
67
+ const pane = boundedText(value.pane, SHARE_ITEM_LIMITS.pane);
68
+ const title = boundedText(value.title, SHARE_ITEM_LIMITS.title);
69
+ if (!pane || !title) return null;
70
+ if (value.excerpt === undefined) return { pane, title };
71
+ const excerpt = boundedText(value.excerpt, SHARE_ITEM_LIMITS.excerpt);
72
+ return excerpt ? { pane, title, excerpt } : null;
73
+ }
@@ -0,0 +1,205 @@
1
+ import { useEffect, useRef } from "react";
2
+ import { usePaneFooterScopeActive } from "../components/layout/pane/footer/registration";
3
+ import type { ResolvedPane } from "../layout/pane-manager";
4
+ import { listExternalPlugins } from "../plugins/external-runtime";
5
+ import type { PluginRegistry } from "../plugins/registry";
6
+ import { resolveTickerForPane, useOptionalPaneInstanceId, type AppState } from "../state/app/context";
7
+ import type { PaneTemplateDef } from "../types/plugin";
8
+ import { logFailure } from "../utils/log-failure";
9
+ import { shareItem, type ShareItem } from "./item";
10
+
11
+ /** What a pane, or a part of the kit it is drawn with, says it is on. */
12
+ export interface PaneShareItemPart {
13
+ title?: string | null;
14
+ excerpt?: string | null;
15
+ }
16
+
17
+ type PaneShareItemInput = PaneShareItemPart | null | (() => PaneShareItemPart | null);
18
+
19
+ interface Entry {
20
+ read(): PaneShareItemPart | null;
21
+ /** Said by the kit (a stack's open detail, a reader's text), which a pane's own word outranks. */
22
+ kit: boolean;
23
+ order: number;
24
+ }
25
+
26
+ const entries = new Map<string, Set<Entry>>();
27
+ let nextOrder = 0;
28
+
29
+ /**
30
+ * Says what the pane is on now, for Share to keep with its link: the story
31
+ * it has open, the result it has picked. Pass null when it is on nothing in
32
+ * particular, and a function for an item that takes work to put together:
33
+ * it is read only when a link is made. A tab that is not shown says nothing. `kit` marks the shared components'
34
+ * own guesses (a stack's detail title, a reader's opening), which a pane's
35
+ * own item outranks; they combine, so a stack's title takes its reader's
36
+ * opening as its excerpt. Any pane may say; a link reads it only from a pane
37
+ * that opts in with `shareItem.open` (paneShareItemFor).
38
+ */
39
+ export function usePaneShareItem(item: PaneShareItemInput, options: { paneId?: string; kit?: boolean } = {}): void {
40
+ const contextPaneId = useOptionalPaneInstanceId();
41
+ const paneId = options.paneId ?? contextPaneId;
42
+ const shown = usePaneFooterScopeActive();
43
+ const latest = useRef(item);
44
+ latest.current = item;
45
+ const kit = options.kit === true;
46
+ useEffect(() => {
47
+ if (!paneId || !shown) return;
48
+ const entry: Entry = {
49
+ read: () => {
50
+ const current = latest.current;
51
+ return typeof current === "function" ? current() : current;
52
+ },
53
+ kit,
54
+ order: ++nextOrder,
55
+ };
56
+ let set = entries.get(paneId);
57
+ if (!set) entries.set(paneId, set = new Set());
58
+ set.add(entry);
59
+ return () => {
60
+ set.delete(entry);
61
+ if (set.size === 0 && entries.get(paneId) === set) entries.delete(paneId);
62
+ };
63
+ }, [kit, paneId, shown]);
64
+ }
65
+
66
+ function readEntry(entry: Entry): PaneShareItemPart | null {
67
+ try {
68
+ return entry.read();
69
+ } catch (error) {
70
+ logFailure("shares.pane-item", "Reading what a pane is on failed")(error);
71
+ return null;
72
+ }
73
+ }
74
+
75
+ /**
76
+ * What the pane says it is on: the pane's own item first, then the kit's,
77
+ * the one shown last first within each. A title without an excerpt takes the
78
+ * kit's excerpt (a stack's title, its reader's opening).
79
+ */
80
+ function declaredPaneShareItem(paneId: string): PaneShareItemPart | null {
81
+ const said = [...entries.get(paneId) ?? []]
82
+ .sort((a, b) => Number(a.kit) - Number(b.kit) || b.order - a.order)
83
+ .map((entry) => ({ entry, part: readEntry(entry) }))
84
+ .filter((said): said is { entry: Entry; part: PaneShareItemPart } => !!said.part);
85
+ const titled = said.find(({ part }) => part.title?.trim());
86
+ if (!titled) return null;
87
+ const excerpt = titled.part.excerpt?.trim()
88
+ || said.find(({ entry, part }) => entry.kit && entry !== titled.entry && part.excerpt?.trim())?.part.excerpt;
89
+ return { title: titled.part.title, excerpt: excerpt || null };
90
+ }
91
+
92
+ export interface PaneShareItemSource {
93
+ /** The pane's instance id, when what it says it is on may name the item (`shareItem.open`); null when not. */
94
+ paneId: string | null;
95
+ /** The pane's name. */
96
+ paneName: string;
97
+ /** The one ticker the pane shows, with what is known of it; not a list's cursor. */
98
+ ticker?: { symbol: string; name?: string; exchange?: string; sector?: string; industry?: string } | null;
99
+ /** The argument the pane's function was opened with (`NI CRYPTO`), as its option names it. */
100
+ argument?: { label: string; description?: string } | null;
101
+ }
102
+
103
+ /**
104
+ * The item a share keeps: what the pane says it is on, else the ticker it
105
+ * shows, else the argument its function was opened with; null when it is on
106
+ * none of these.
107
+ */
108
+ export function resolvePaneShareItem(source: PaneShareItemSource): ShareItem | null {
109
+ const declared = source.paneId ? shareItem(source.paneName, declaredPaneShareItem(source.paneId)) : null;
110
+ if (declared) return declared;
111
+ const ticker = source.ticker;
112
+ if (ticker?.symbol) {
113
+ const symbol = ticker.symbol.split(":")[0] || ticker.symbol;
114
+ const name = ticker.name?.trim();
115
+ return shareItem(source.paneName, {
116
+ title: name && name !== symbol ? `${name} (${symbol})` : ticker.symbol,
117
+ excerpt: [ticker.exchange, ticker.sector, ticker.industry].filter(Boolean).join(" · "),
118
+ });
119
+ }
120
+ if (source.argument) return shareItem(source.paneName, { title: source.argument.label, excerpt: source.argument.description });
121
+ return null;
122
+ }
123
+
124
+ /**
125
+ * The argument a pane's function was opened with, read from its title as the
126
+ * function wrote it (`NI CRYPTO`), named as the function's options name it.
127
+ * Only an option the function lists: words typed after it (a search, a note)
128
+ * are the person's own, and a ticker is not one (the pane's ticker says more).
129
+ */
130
+ function functionArgument(
131
+ templates: ReadonlyMap<string, PaneTemplateDef>,
132
+ paneType: string,
133
+ title: string | undefined,
134
+ ): PaneShareItemSource["argument"] {
135
+ const [code = "", ...words] = (title ?? "").trim().split(/\s+/);
136
+ const argument = words.join(" ");
137
+ if (!argument) return null;
138
+ const opens = (prefix: string) => prefix.toUpperCase() === code.toUpperCase();
139
+ const template = [...templates.values()].find((candidate) => candidate.paneId === paneType
140
+ && !!candidate.shortcut
141
+ && (opens(candidate.shortcut.prefix) || (candidate.shortcut.aliases ?? []).some(opens)));
142
+ const options = template?.shortcut?.argKind === "ticker" ? undefined : template?.shortcut?.argOptions;
143
+ if (!template || !options) return null;
144
+ try {
145
+ const label = options().find((option) => option.value.toUpperCase() === argument.toUpperCase())?.label;
146
+ return label ? { label, description: template.description } : null;
147
+ } catch (error) {
148
+ logFailure("shares.pane-item", "Reading a function's argument options failed")(error);
149
+ return null;
150
+ }
151
+ }
152
+
153
+ /** Fields the pane keeps on the device when shared, so nothing it shows may stand in for them. */
154
+ function keepsFieldsPrivate(pane: Pick<ResolvedPane, "def">): boolean {
155
+ const kept = pane.def.portableShare?.private;
156
+ return !!kept && Object.values(kept).some((fields) => fields === true || (Array.isArray(fields) && fields.length > 0));
157
+ }
158
+
159
+ /** Whether a plugin loaded from outside the app (a registry or local plugin) owns the pane. */
160
+ function fromExternalPlugin(registry: Pick<PluginRegistry, "getPanePluginId">, paneType: string): boolean {
161
+ const owner = registry.getPanePluginId(paneType);
162
+ return !!owner && listExternalPlugins().some((entry) => entry.plugin.id === owner);
163
+ }
164
+
165
+ /** Whether the pane shows one ticker now: a chart of one security, not a comparison or a list. */
166
+ function showsOneTicker(pane: Pick<ResolvedPane, "instance" | "def">): boolean {
167
+ const { def, instance } = pane;
168
+ if (def.tickerSource) return false;
169
+ return typeof def.tickerFollower === "function" ? def.tickerFollower(instance) : def.tickerFollower === true;
170
+ }
171
+
172
+ /**
173
+ * The item a public link to the pane keeps, or null. Only from what the pane
174
+ * opts into (`PaneDef.shareItem`): an alert, a form's title or a search typed
175
+ * in a pane that says nothing never reaches a link, nor anything from a
176
+ * plugin loaded from outside the app. A pane that shows the person's own data,
177
+ * or keeps fields of its own off a share, keeps none either: what it is on
178
+ * would say what its settings leave out.
179
+ */
180
+ export function paneShareItemFor({ pane, state, registry, personal }: {
181
+ pane: Pick<ResolvedPane, "instance" | "def">;
182
+ state: Pick<AppState, "tickers"> & Parameters<typeof resolveTickerForPane>[0];
183
+ registry: Pick<PluginRegistry, "paneTemplates" | "getPanePluginId">;
184
+ /** Whether the pane shows the person's own data now (personal-pane.ts). */
185
+ personal: boolean;
186
+ }): ShareItem | null {
187
+ const { instance, def } = pane;
188
+ const allowed = def.shareItem;
189
+ if (!allowed || personal || keepsFieldsPrivate(pane) || fromExternalPlugin(registry, instance.paneId)) return null;
190
+ // The one ticker it shows; a list's cursor is where the list is, not something picked to share.
191
+ const symbol = allowed.ticker && showsOneTicker(pane) ? resolveTickerForPane(state, instance.instanceId) : null;
192
+ const metadata = symbol ? state.tickers.get(symbol)?.metadata : undefined;
193
+ return resolvePaneShareItem({
194
+ paneId: allowed.open ? instance.instanceId : null,
195
+ paneName: def.name,
196
+ ticker: symbol ? {
197
+ symbol,
198
+ name: metadata?.name,
199
+ exchange: metadata?.exchange,
200
+ sector: metadata?.sector,
201
+ industry: metadata?.industry,
202
+ } : null,
203
+ argument: allowed.argument ? functionArgument(registry.paneTemplates, instance.paneId, instance.title) : null,
204
+ });
205
+ }
@@ -6,6 +6,7 @@ import type { PluginRegistry } from "../plugins/registry";
6
6
  import type { PaneInstanceConfig } from "../types/config";
7
7
  import type { PaneDef, PaneTemplateDef } from "../types/plugin";
8
8
  import type { TickerRecord } from "../types/ticker";
9
+ import type { ShareItem } from "./item";
9
10
  import { parseSharePayload, type PaneShareData, type SharePayload } from "./payload";
10
11
 
11
12
  export function buildPaneSharePayload(
@@ -15,6 +16,8 @@ export function buildPaneSharePayload(
15
16
  resolvedTicker?: string | null,
16
17
  tickers?: ReadonlyMap<string, TickerRecord>,
17
18
  pinnedTime?: number | null,
19
+ /** What the pane is on (pane-item.ts), kept beside its settings. */
20
+ item?: ShareItem | null,
18
21
  ): Extract<SharePayload, { kind: "pane" }> | null {
19
22
  const def = pluginRegistry.panes.get(pane.paneId);
20
23
  if (!def) return null;
@@ -37,6 +40,7 @@ export function buildPaneSharePayload(
37
40
  ...(description ? { description } : {}),
38
41
  layout,
39
42
  },
43
+ ...(item ? { item } : {}),
40
44
  });
41
45
  return payload?.kind === "pane" ? payload : null;
42
46
  } catch (error) {