gloomberb 0.19.3 → 0.19.5

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 (226) hide show
  1. package/package.json +4 -2
  2. package/src/api-client/errors.ts +8 -0
  3. package/src/api-client/index.ts +18 -0
  4. package/src/api-client/request.ts +295 -42
  5. package/src/api-client/socket.ts +95 -0
  6. package/src/app/keybindings/actions.ts +1 -1
  7. package/src/app/pane-runtime/index.tsx +1 -1
  8. package/src/app/pane-runtime/ticker-inspector-runtime.ts +1 -1
  9. package/src/app/pane-runtime/ticker-open-runtime.ts +1 -1
  10. package/src/app/pane-runtime/ticker-open-target.ts +12 -2
  11. package/src/cli/commands/command-utils.ts +4 -0
  12. package/src/cli/commands/market.ts +119 -27
  13. package/src/cli/commands/search.ts +1 -1
  14. package/src/cli/commands/ticker.ts +10 -6
  15. package/src/cli/currency-name-hint.ts +60 -0
  16. package/src/cli/desktop-pane-shot-api-policy.ts +10 -2
  17. package/src/cli/desktop-pane-shot.ts +2 -1
  18. package/src/cli/history-rows.ts +18 -1
  19. package/src/cli/known-gaps.ts +17 -2
  20. package/src/cli/not-a-ticker.ts +5 -3
  21. package/src/cli/pane-functions/catalog.ts +9 -1
  22. package/src/cli/pane-functions/headless.ts +7 -3
  23. package/src/cli/pane-functions/market-session.ts +6 -7
  24. package/src/cli/series-search.ts +4 -5
  25. package/src/components/chart/composite/panel-bitmap.ts +28 -2
  26. package/src/components/chart/composite/time-axis.ts +17 -2
  27. package/src/components/command-bar/action-runtime.ts +2 -0
  28. package/src/components/command-bar/commands/direct/runtime.ts +3 -3
  29. package/src/components/command-bar/helpers.ts +2 -0
  30. package/src/components/command-bar/list/model.ts +9 -0
  31. package/src/components/command-bar/pane-actions.ts +46 -35
  32. package/src/components/command-bar/pane-templates/workflow.ts +6 -0
  33. package/src/components/command-bar/panel/index.tsx +30 -3
  34. package/src/components/command-bar/panel/types.ts +7 -0
  35. package/src/components/command-bar/routes/root/results.ts +4 -4
  36. package/src/components/command-bar/routes/root/selection.ts +3 -2
  37. package/src/components/command-bar/routes/ticker-search/actions.ts +21 -16
  38. package/src/components/command-bar/routing/launch-request.ts +3 -2
  39. package/src/components/command-bar/routing/list-state.ts +4 -1
  40. package/src/components/command-bar/surface/index.tsx +15 -1
  41. package/src/components/layout/floating-pane.tsx +10 -0
  42. package/src/components/layout/pane/frame.tsx +6 -0
  43. package/src/components/layout/pane/header.tsx +244 -42
  44. package/src/components/layout/pane/index.tsx +20 -2
  45. package/src/components/layout/shell/active-drag.ts +160 -28
  46. package/src/components/layout/shell/drag/index.ts +99 -96
  47. package/src/components/layout/shell/drag/live.ts +3 -17
  48. package/src/components/layout/shell/drag/magnets.ts +304 -0
  49. package/src/components/layout/shell/drag/overlays.tsx +77 -75
  50. package/src/components/layout/shell/drag/runtime.ts +12 -7
  51. package/src/components/layout/shell/index.tsx +66 -32
  52. package/src/components/layout/shell/native/pointer-runtime.ts +7 -2
  53. package/src/components/layout/shell/native/surfaces.ts +1 -9
  54. package/src/components/layout/shell/native/window-state.ts +21 -25
  55. package/src/components/layout/shell/pane/layers.tsx +153 -24
  56. package/src/components/layout/shell/shortcuts.ts +4 -1
  57. package/src/components/layout/shell/terminal-pointer-runtime.ts +24 -1
  58. package/src/components/layout/shell/window-mode/overlays.tsx +14 -6
  59. package/src/components/layout/status-bar.tsx +75 -6
  60. package/src/components/layout/window-controls.tsx +96 -35
  61. package/src/components/layout/window-fullscreen.ts +20 -0
  62. package/src/components/quote-flash.ts +36 -32
  63. package/src/core/app-runtime.ts +4 -1
  64. package/src/core/connection-health.ts +76 -1
  65. package/src/core/state/app/command-bar-launch.ts +12 -0
  66. package/src/core/state/app/layout.ts +4 -3
  67. package/src/core/state/app/types.ts +4 -1
  68. package/src/data/config/layout.ts +2 -2
  69. package/src/data/config/store/fold-panes.ts +6 -1
  70. package/src/i18n/es.ts +8 -1
  71. package/src/i18n/ja.ts +8 -1
  72. package/src/i18n/ko.ts +8 -1
  73. package/src/i18n/zh-cn.ts +8 -1
  74. package/src/i18n/zh-tw.ts +8 -1
  75. package/src/layout/pane-follow.ts +3 -2
  76. package/src/layout/pane-layout-move.ts +2 -1
  77. package/src/layout/pane-manager/dock-stack.ts +38 -0
  78. package/src/layout/pane-manager/dock-tree.ts +76 -15
  79. package/src/layout/pane-manager/docking.ts +48 -6
  80. package/src/layout/pane-manager/floating-actions.ts +12 -3
  81. package/src/layout/pane-manager/floating-placement.ts +189 -0
  82. package/src/layout/pane-manager/floating.ts +23 -4
  83. package/src/layout/pane-manager/gridlock.ts +16 -4
  84. package/src/layout/pane-manager/hidden-panes.ts +30 -1
  85. package/src/layout/pane-manager/index.ts +2 -0
  86. package/src/layout/pane-manager/layout-state.ts +17 -0
  87. package/src/layout/pane-manager/types.ts +4 -1
  88. package/src/layout/ticker-retarget.ts +88 -0
  89. package/src/layout-marketplace/cloud.ts +9 -1
  90. package/src/market-data/connection-follow.ts +68 -0
  91. package/src/market-data/coordinator/entries.ts +15 -3
  92. package/src/market-data/coordinator/events.ts +17 -1
  93. package/src/market-data/coordinator/financials.ts +20 -7
  94. package/src/market-data/coordinator/index.ts +217 -4
  95. package/src/market-data/coordinator/quotes.ts +10 -0
  96. package/src/market-data/frame-scheduler.ts +47 -10
  97. package/src/market-data/frame-wake.ts +74 -0
  98. package/src/market-data/futures-board.ts +7 -6
  99. package/src/market-data/hooks.tsx +43 -3
  100. package/src/market-data/performance.ts +78 -9
  101. package/src/market-data/request-types.ts +6 -3
  102. package/src/news/aggregator.ts +12 -1
  103. package/src/plugins/builtin/alerts/cli.ts +2 -1
  104. package/src/plugins/builtin/analytics/risk-evidence.ts +1 -0
  105. package/src/plugins/builtin/attention/evidence.ts +1 -1
  106. package/src/plugins/builtin/awards/client.ts +1 -1
  107. package/src/plugins/builtin/awards/evidence.ts +1 -1
  108. package/src/plugins/builtin/awards/pane.tsx +2 -1
  109. package/src/plugins/builtin/bond-calculator/math.ts +1 -1
  110. package/src/plugins/builtin/broker-manager/footer.ts +3 -2
  111. package/src/plugins/builtin/broker-manager/index.tsx +2 -1
  112. package/src/plugins/builtin/broker-manager/keyboard.ts +2 -1
  113. package/src/plugins/builtin/buildout/company/pane.tsx +2 -1
  114. package/src/plugins/builtin/buildout/model/index.ts +6 -0
  115. package/src/plugins/builtin/buildout/pane/index.tsx +2 -1
  116. package/src/plugins/builtin/catalysts/evidence.ts +1 -1
  117. package/src/plugins/builtin/catalysts/pane.tsx +2 -1
  118. package/src/plugins/builtin/chart-composer/headless.ts +40 -1
  119. package/src/plugins/builtin/chart-composer/index.tsx +13 -0
  120. package/src/plugins/builtin/chat/controller/index.ts +10 -3
  121. package/src/plugins/builtin/chat/controller/session-runtime.ts +9 -2
  122. package/src/plugins/builtin/chat/status-widget.tsx +3 -1
  123. package/src/plugins/builtin/cloud-tweets/table.tsx +3 -2
  124. package/src/plugins/builtin/comment-letters/client.ts +2 -1
  125. package/src/plugins/builtin/company-kpis/client.ts +1 -1
  126. package/src/plugins/builtin/company-kpis/pane.tsx +2 -1
  127. package/src/plugins/builtin/company-kpis/screenshot-evidence.ts +3 -2
  128. package/src/plugins/builtin/cot/headless.ts +9 -3
  129. package/src/plugins/builtin/cot/model.ts +44 -3
  130. package/src/plugins/builtin/credit-documents/client.ts +1 -1
  131. package/src/plugins/builtin/credit-documents/evidence.ts +1 -1
  132. package/src/plugins/builtin/credit-documents/pane.tsx +2 -1
  133. package/src/plugins/builtin/earnings-calls/pane.tsx +1 -1
  134. package/src/plugins/builtin/earnings-ripple/index.tsx +6 -1
  135. package/src/plugins/builtin/econ/calendar-model.ts +2 -0
  136. package/src/plugins/builtin/econ/fred-catalog.ts +5 -5
  137. package/src/plugins/builtin/econ/print-watch.ts +3 -1
  138. package/src/plugins/builtin/futures/series.ts +16 -1
  139. package/src/plugins/builtin/fx-matrix/headless.ts +4 -2
  140. package/src/plugins/builtin/fx-matrix/index.tsx +37 -3
  141. package/src/plugins/builtin/fx-matrix/pairs.ts +15 -0
  142. package/src/plugins/builtin/gpu/headless.ts +2 -1
  143. package/src/plugins/builtin/help/function-card.tsx +2 -1
  144. package/src/plugins/builtin/help/index.tsx +3 -2
  145. package/src/plugins/builtin/insider/display.ts +45 -6
  146. package/src/plugins/builtin/ipo-calendar/model.ts +2 -0
  147. package/src/plugins/builtin/iv-history/client.ts +2 -1
  148. package/src/plugins/builtin/iv-history/headless.ts +2 -1
  149. package/src/plugins/builtin/jobs/pages.ts +4 -4
  150. package/src/plugins/builtin/kelly-sizer/headless.ts +2 -1
  151. package/src/plugins/builtin/market-heatmap/index.tsx +2 -1
  152. package/src/plugins/builtin/members/client.ts +1 -1
  153. package/src/plugins/builtin/mna/distress/client.ts +1 -0
  154. package/src/plugins/builtin/mna/pane.tsx +4 -1
  155. package/src/plugins/builtin/options/market-reference.ts +1 -1
  156. package/src/plugins/builtin/options/open-interest-as-of.ts +3 -1
  157. package/src/plugins/builtin/options/view.tsx +2 -1
  158. package/src/plugins/builtin/options-calculator/evidence.ts +1 -1
  159. package/src/plugins/builtin/options-scenario/csp-screen-pane.tsx +1 -1
  160. package/src/plugins/builtin/options-scenario/csp-screen.ts +8 -4
  161. package/src/plugins/builtin/options-scenario/csp.ts +28 -9
  162. package/src/plugins/builtin/options-scenario/evidence.ts +5 -4
  163. package/src/plugins/builtin/options-scenario/pane.tsx +2 -1
  164. package/src/plugins/builtin/perps/client.ts +1 -1
  165. package/src/plugins/builtin/portfolio-list/cli/watchlist-command.ts +2 -1
  166. package/src/plugins/builtin/portfolio-list/pane/index.tsx +7 -3
  167. package/src/plugins/builtin/portfolio-list/use-throttled-memo.ts +10 -19
  168. package/src/plugins/builtin/research/analyst-model.ts +1 -0
  169. package/src/plugins/builtin/research/equity-diagnostic-pane.tsx +2 -1
  170. package/src/plugins/builtin/research/index.tsx +1 -0
  171. package/src/plugins/builtin/research/relative-valuation-currency.ts +1 -1
  172. package/src/plugins/builtin/research/relative-valuation-peers.ts +2 -1
  173. package/src/plugins/builtin/research-search/command-bar-search.ts +3 -1
  174. package/src/plugins/builtin/research-search/snippet.ts +1 -0
  175. package/src/plugins/builtin/revenue-breakdown/client.ts +3 -2
  176. package/src/plugins/builtin/seasonality/headless.ts +2 -1
  177. package/src/plugins/builtin/sec/command-bar-search.ts +3 -2
  178. package/src/plugins/builtin/sec/index.tsx +7 -4
  179. package/src/plugins/builtin/sec/row-summaries.ts +28 -12
  180. package/src/plugins/builtin/sectors/client.ts +18 -8
  181. package/src/plugins/builtin/sectors/index.tsx +19 -5
  182. package/src/plugins/builtin/short-interest/watch-client.ts +2 -1
  183. package/src/plugins/builtin/social-mentions/client.ts +2 -1
  184. package/src/plugins/builtin/supply-chain/client.ts +1 -1
  185. package/src/plugins/builtin/supply-chain/evidence.ts +1 -1
  186. package/src/plugins/builtin/supply-chain/graph-pane.tsx +2 -1
  187. package/src/plugins/builtin/supply-chain/pane.tsx +2 -1
  188. package/src/plugins/builtin/ticker-detail/adr-pair/headless.ts +1 -1
  189. package/src/plugins/builtin/ticker-detail/adr-pair/model.ts +24 -4
  190. package/src/plugins/builtin/ticker-detail/adr-pair/tab.tsx +1 -1
  191. package/src/plugins/builtin/ticker-detail/overview/pane.tsx +4 -1
  192. package/src/plugins/builtin/ticker-detail/overview-tab.tsx +25 -2
  193. package/src/plugins/builtin/time-sales/client.ts +1 -0
  194. package/src/plugins/builtin/vol-surface/client.ts +2 -1
  195. package/src/plugins/builtin/yield-curve/headless.ts +3 -1
  196. package/src/portfolio/column-values.ts +76 -10
  197. package/src/react/async-resource.ts +12 -0
  198. package/src/remote/controller.ts +3 -1
  199. package/src/renderers/browser/app-services.ts +8 -1
  200. package/src/renderers/browser/cloud-transport.ts +6 -1
  201. package/src/renderers/cloudflare/worker.ts +24 -2
  202. package/src/renderers/dom/host/box.tsx +204 -176
  203. package/src/renderers/dom/host/style.ts +49 -20
  204. package/src/renderers/dom/host/text.tsx +3 -2
  205. package/src/renderers/dom/styles.css +32 -0
  206. package/src/renderers/electrobun/bun/desktop/backend.ts +2 -0
  207. package/src/renderers/electrobun/bun/desktop/host-requests.ts +25 -1
  208. package/src/renderers/electrobun/bun/desktop/relaunch.ts +9 -1
  209. package/src/renderers/electrobun/bun/desktop/windows-script.ts +9 -6
  210. package/src/renderers/electrobun/bun/window/windows-native.ts +26 -1
  211. package/src/renderers/electrobun/shared/protocol.ts +6 -0
  212. package/src/renderers/electrobun/view/ui-host.tsx +7 -0
  213. package/src/renderers/electrobun/view/window-fullscreen.ts +10 -3
  214. package/src/shares/portable-layout.ts +99 -2
  215. package/src/sources/provider-router/index.ts +9 -3
  216. package/src/sources/provider-router/sources.ts +26 -1
  217. package/src/sync/core-contributors.ts +18 -4
  218. package/src/time-series/price-units.ts +11 -0
  219. package/src/time-series/resolve.ts +12 -0
  220. package/src/types/config.ts +17 -1
  221. package/src/types/plugin.ts +6 -0
  222. package/src/ui/host.tsx +2 -0
  223. package/src/utils/currency-names.ts +20 -0
  224. package/src/utils/currency-pair.ts +6 -0
  225. package/src/utils/exchange-rate-snapshot.ts +20 -2
  226. package/src/utils/fx-market-hours.ts +43 -0
@@ -0,0 +1,304 @@
1
+ import type { FloatingRect, LayoutBounds } from "../../../../layout/pane-manager";
2
+
3
+ /**
4
+ * Magnets: while a floating pane moves or resizes, an edge that comes within
5
+ * `catch` of another pane's edge (floating or docked), or of the edge of the
6
+ * area, jumps to it, and stays there until it is pulled more than `release`
7
+ * away. Distances are in cells per axis (the desktop's 8px and 12px, one and
8
+ * two cells in the terminal).
9
+ */
10
+ export interface MagnetDistances {
11
+ catchX: number;
12
+ catchY: number;
13
+ releaseX: number;
14
+ releaseY: number;
15
+ }
16
+
17
+ type Side = "start" | "end";
18
+
19
+ /** The line one edge of the rect holds to on an axis: which edge, at what coordinate. */
20
+ interface AxisLatch {
21
+ side: Side;
22
+ line: number;
23
+ }
24
+
25
+ /** What a move or resize is holding to, kept from one pointer move to the next. */
26
+ export interface MagnetLatch {
27
+ x: AxisLatch | null;
28
+ y: AxisLatch | null;
29
+ }
30
+
31
+ export const NO_LATCH: MagnetLatch = { x: null, y: null };
32
+
33
+ /** Desktop magnets, in px: an edge this close jumps to a line, and lets go this far from it. */
34
+ const MAGNET_CATCH_PX = 8;
35
+ const MAGNET_RELEASE_PX = 12;
36
+ /** Terminal magnets, in cells: the next cell catches, two let go. */
37
+ const TERMINAL_MAGNETS: MagnetDistances = { catchX: 1, catchY: 1, releaseX: 2, releaseY: 2 };
38
+
39
+ /**
40
+ * Desktop: a moving pane's magnets act while the pointer slows down or rests
41
+ * near a line; faster than this, in catch distances a second (300 px/s), the
42
+ * pane follows the pointer exactly. Holding an edge on every line a window
43
+ * crossed on its way stopped it for 20 px at each one and then jumped it,
44
+ * which read as a drag that lags and stutters.
45
+ */
46
+ const MAGNET_TRAVEL_SPEED = 300 / MAGNET_CATCH_PX;
47
+ /** How far back the pointer's speed is read, ms: a few frames. */
48
+ const SPEED_WINDOW_MS = 64;
49
+ /** How long the pointer rests before the magnets catch where it stopped, ms. */
50
+ export const MAGNET_REST_MS = 80;
51
+
52
+ /** Where the pointer was during a move, in cells, and when (ms). */
53
+ interface PointerSample {
54
+ t: number;
55
+ x: number;
56
+ y: number;
57
+ }
58
+
59
+ /** Adds where the pointer is now, keeping only what the speed reads. */
60
+ function trackPointer(track: PointerSample[], sample: PointerSample): void {
61
+ track.push(sample);
62
+ const oldest = sample.t - SPEED_WINDOW_MS * 2;
63
+ while (track.length > 2 && track[1]!.t <= oldest) track.shift();
64
+ }
65
+
66
+ /**
67
+ * Desktop: when a moving pane's magnets act, over one drag. `travelling`
68
+ * takes each move and says whether the pointer is on its way somewhere; while
69
+ * it is, the pane follows it exactly, and `rest` (the move run again) is set
70
+ * to run once the pointer has stopped for MAGNET_REST_MS, so the magnets
71
+ * catch where it stopped. Any later move drops that check, travelling or not:
72
+ * run after a slower move, it would put the pane back where the pointer was.
73
+ * The check runs at the start of a frame, after the moves that frame brings,
74
+ * so a page drawing fewer frames than 1 / MAGNET_REST_MS still sees a
75
+ * pointer that moves on every frame as travelling.
76
+ */
77
+ export interface MagnetPace {
78
+ travelling(sample: PointerSample, distances: MagnetDistances, rest?: () => void): boolean;
79
+ /** Drops the rest check: another event of the drag came first. */
80
+ cancel(): void;
81
+ /** Forgets the pointer's path, for a new drag. */
82
+ reset(): void;
83
+ }
84
+
85
+ export function createMagnetPace(): MagnetPace {
86
+ let track: PointerSample[] = [];
87
+ let rest: ReturnType<typeof setTimeout> | null = null;
88
+ let frame: number | null = null;
89
+ const cancel = () => {
90
+ if (rest) clearTimeout(rest);
91
+ if (frame !== null) cancelAnimationFrame(frame);
92
+ rest = null;
93
+ frame = null;
94
+ };
95
+ return {
96
+ travelling(sample, distances, onRest) {
97
+ cancel();
98
+ const last = track[track.length - 1];
99
+ // The same place again (a rest check, a repeated event) is not a move.
100
+ if (!last || last.x !== sample.x || last.y !== sample.y) trackPointer(track, sample);
101
+ if (!pointerTravelling(track, sample.t, distances)) return false;
102
+ if (onRest) {
103
+ rest = setTimeout(() => {
104
+ rest = null;
105
+ if (typeof requestAnimationFrame !== "function") return onRest();
106
+ frame = requestAnimationFrame(() => {
107
+ frame = null;
108
+ onRest();
109
+ });
110
+ }, MAGNET_REST_MS);
111
+ }
112
+ return true;
113
+ },
114
+ cancel,
115
+ reset() {
116
+ cancel();
117
+ track = [];
118
+ },
119
+ };
120
+ }
121
+
122
+ /**
123
+ * Whether the pointer is on its way somewhere rather than placing the pane:
124
+ * how far it went over the last few frames, in catch distances a second,
125
+ * against the travel speed. A move with nothing before it (the first of a
126
+ * drag) is travel, so a pane leaves its spot without catching the lines it
127
+ * sits on.
128
+ */
129
+ function pointerTravelling(track: readonly PointerSample[], now: number, distances: MagnetDistances): boolean {
130
+ const latest = track[track.length - 1];
131
+ if (!latest) return false;
132
+ const since = now - SPEED_WINDOW_MS;
133
+ let from = track[0]!;
134
+ for (const sample of track) {
135
+ if (sample.t > since) break;
136
+ from = sample;
137
+ }
138
+ const span = Math.min(SPEED_WINDOW_MS, now - from.t);
139
+ if (from === latest) return track.length === 1 && span <= 0;
140
+ if (span <= 0) return true;
141
+ const catches = Math.hypot((latest.x - from.x) / distances.catchX, (latest.y - from.y) / distances.catchY);
142
+ return (catches / span) * 1000 > MAGNET_TRAVEL_SPEED;
143
+ }
144
+
145
+ /**
146
+ * The magnets in cells: the desktop's px over its cell size (`cell`), or the
147
+ * terminal's whole cells, also for a cell size not measured yet (zero), which
148
+ * would otherwise catch at any distance.
149
+ */
150
+ export function magnetDistancesFor(cell: { width: number; height: number } | null): MagnetDistances {
151
+ if (!cell || !(cell.width > 0) || !(cell.height > 0) || !Number.isFinite(cell.width) || !Number.isFinite(cell.height)) {
152
+ return TERMINAL_MAGNETS;
153
+ }
154
+ return {
155
+ catchX: MAGNET_CATCH_PX / cell.width,
156
+ catchY: MAGNET_CATCH_PX / cell.height,
157
+ releaseX: MAGNET_RELEASE_PX / cell.width,
158
+ releaseY: MAGNET_RELEASE_PX / cell.height,
159
+ };
160
+ }
161
+
162
+ interface Span { start: number; end: number }
163
+
164
+ /** How close two spans across the axis must be for their edges to matter to each other. */
165
+ function near(a: Span, b: Span, slack: number): boolean {
166
+ return a.start < b.end + slack && b.start < a.end + slack;
167
+ }
168
+
169
+ /**
170
+ * The lines an edge can hold to on one axis: the area's two edges, and the
171
+ * near and far edge of every target that sits beside the rect across the
172
+ * axis (overlapping it there, or within the catch distance), so a pane lines
173
+ * up with its neighbours, not with something across the screen.
174
+ */
175
+ function axisLines(axis: "x" | "y", rect: LayoutBounds, targets: readonly LayoutBounds[], area: LayoutBounds, slack: number): number[] {
176
+ const across: Span = axis === "x"
177
+ ? { start: rect.y, end: rect.y + rect.height }
178
+ : { start: rect.x, end: rect.x + rect.width };
179
+ const lines = axis === "x" ? [area.x, area.x + area.width] : [area.y, area.y + area.height];
180
+ for (const target of targets) {
181
+ const span: Span = axis === "x"
182
+ ? { start: target.y, end: target.y + target.height }
183
+ : { start: target.x, end: target.x + target.width };
184
+ if (!near(across, span, slack)) continue;
185
+ if (axis === "x") lines.push(target.x, target.x + target.width);
186
+ else lines.push(target.y, target.y + target.height);
187
+ }
188
+ return lines;
189
+ }
190
+
191
+ /**
192
+ * Where one axis of the rect snaps: the latch it keeps or takes, or null.
193
+ * `sides` are the edges allowed to move: both for a move, the dragged one for
194
+ * a resize. A latch holds while its edge stays within `release` of a line
195
+ * still there; otherwise the closest edge-to-line pair within `catch` wins.
196
+ */
197
+ function resolveAxis(
198
+ edges: Record<Side, number>,
199
+ sides: readonly Side[],
200
+ lines: readonly number[],
201
+ latch: AxisLatch | null,
202
+ catchDistance: number,
203
+ releaseDistance: number,
204
+ ): AxisLatch | null {
205
+ if (latch && sides.includes(latch.side) && lines.some((line) => Math.abs(line - latch.line) < 1e-6)) {
206
+ if (Math.abs(edges[latch.side] - latch.line) <= releaseDistance) return latch;
207
+ }
208
+ let best: AxisLatch | null = null;
209
+ let bestDistance = catchDistance;
210
+ for (const side of sides) {
211
+ for (const line of lines) {
212
+ const distance = Math.abs(edges[side] - line);
213
+ if (distance <= bestDistance && (best === null || distance < bestDistance)) {
214
+ best = { side, line };
215
+ bestDistance = distance;
216
+ }
217
+ }
218
+ }
219
+ return best;
220
+ }
221
+
222
+ /** A floating rect being moved, with its edges pulled onto the lines nearby. */
223
+ export function snapMovedRect(
224
+ rect: FloatingRect,
225
+ targets: readonly LayoutBounds[],
226
+ area: LayoutBounds,
227
+ distances: MagnetDistances,
228
+ latch: MagnetLatch,
229
+ ): { rect: FloatingRect; latch: MagnetLatch } {
230
+ const xLatch = resolveAxis(
231
+ { start: rect.x, end: rect.x + rect.width },
232
+ ["start", "end"],
233
+ axisLines("x", rect, targets, area, distances.catchY),
234
+ latch.x,
235
+ distances.catchX,
236
+ distances.releaseX,
237
+ );
238
+ const yLatch = resolveAxis(
239
+ { start: rect.y, end: rect.y + rect.height },
240
+ ["start", "end"],
241
+ axisLines("y", rect, targets, area, distances.catchX),
242
+ latch.y,
243
+ distances.catchY,
244
+ distances.releaseY,
245
+ );
246
+ const x = xLatch ? (xLatch.side === "start" ? xLatch.line : xLatch.line - rect.width) : rect.x;
247
+ const y = yLatch ? (yLatch.side === "start" ? yLatch.line : yLatch.line - rect.height) : rect.y;
248
+ return {
249
+ rect: { ...rect, x: clampStart(x, rect.width, area.x, area.width), y: clampStart(y, rect.height, area.y, area.height) },
250
+ latch: { x: xLatch, y: yLatch },
251
+ };
252
+ }
253
+
254
+ function clampStart(start: number, length: number, areaStart: number, areaLength: number): number {
255
+ return Math.max(areaStart, Math.min(start, areaStart + Math.max(0, areaLength - length)));
256
+ }
257
+
258
+ /**
259
+ * A floating rect being resized by the edges in `edges` (-1 the left or top
260
+ * one, 1 the right or bottom one, 0 neither), with each of those pulled onto
261
+ * the lines nearby. The other edges stay put, and neither axis goes under
262
+ * its minimum.
263
+ */
264
+ export function snapResizedRect(
265
+ rect: FloatingRect,
266
+ edges: { x: -1 | 0 | 1; y: -1 | 0 | 1 },
267
+ minimum: { width: number; height: number },
268
+ targets: readonly LayoutBounds[],
269
+ area: LayoutBounds,
270
+ distances: MagnetDistances,
271
+ latch: MagnetLatch,
272
+ ): { rect: FloatingRect; latch: MagnetLatch } {
273
+ const sideOf = (edge: -1 | 0 | 1): Side[] => (edge === -1 ? ["start"] : edge === 1 ? ["end"] : []);
274
+ const xLatch = resolveAxis(
275
+ { start: rect.x, end: rect.x + rect.width },
276
+ sideOf(edges.x),
277
+ axisLines("x", rect, targets, area, distances.catchY),
278
+ latch.x,
279
+ distances.catchX,
280
+ distances.releaseX,
281
+ );
282
+ const yLatch = resolveAxis(
283
+ { start: rect.y, end: rect.y + rect.height },
284
+ sideOf(edges.y),
285
+ axisLines("y", rect, targets, area, distances.catchX),
286
+ latch.y,
287
+ distances.catchY,
288
+ distances.releaseY,
289
+ );
290
+ const xs = resizeTo(rect.x, rect.width, xLatch, minimum.width);
291
+ const ys = resizeTo(rect.y, rect.height, yLatch, minimum.height);
292
+ return {
293
+ rect: { ...rect, x: xs.start, y: ys.start, width: xs.length, height: ys.length },
294
+ latch: { x: xs.latch, y: ys.latch },
295
+ };
296
+ }
297
+
298
+ /** One axis resized so the latched edge sits on its line; no latch when that would go under the minimum. */
299
+ function resizeTo(start: number, length: number, latch: AxisLatch | null, minimum: number): { start: number; length: number; latch: AxisLatch | null } {
300
+ const end = start + length;
301
+ if (latch?.side === "end" && latch.line - start >= minimum) return { start, length: latch.line - start, latch };
302
+ if (latch?.side === "start" && end - latch.line >= minimum) return { start: latch.line, length: end - latch.line, latch };
303
+ return { start, length, latch: null };
304
+ }
@@ -1,12 +1,13 @@
1
1
  import { useRef, type CSSProperties, type RefObject } from "react";
2
2
  import { Box, useUiCapabilities, type BoxRenderable, type LiveBoxFrame } from "../../../../ui";
3
3
  import { colors } from "../../../../theme/colors";
4
- import type { DockLeafLayout, LayoutBounds } from "../../../../layout/pane-manager";
5
- import type { DragPreview, HoverOverlay } from "./index";
6
- import { useLiveBoxFrame, useLiveDrag, useLiveHoverOverlay, type LiveDragGeometry, type LiveDragStore } from "./live";
4
+ import { SHELL_DRAG_Z, type LayoutBounds } from "../../../../layout/pane-manager";
5
+ import type { DragPreview } from "./index";
6
+ import { useLiveBoxFrame, useLiveDrag, type LiveDragGeometry, type LiveDragStore } from "./live";
7
7
  import { placeStyle } from "./slide";
8
8
 
9
- const CELL_POSITIONS = ["top", "left", "center", "right", "bottom"] as const;
9
+ /** Desktop: how opaque a pane on the move is while it is over somewhere to land, so the preview under it shows. */
10
+ export const ARMED_DRAG_OPACITY = 0.7;
10
11
 
11
12
  function selectDockedOutline(geometry: LiveDragGeometry) {
12
13
  const { paneDrag, floating } = geometry;
@@ -18,15 +19,7 @@ const selectPaneDragActive = (geometry: LiveDragGeometry) => geometry.paneDrag !
18
19
  const selectOutlineWidth = (geometry: LiveDragGeometry) => selectDockedOutline(geometry)?.width ?? null;
19
20
  const selectOutlineHeight = (geometry: LiveDragGeometry) => selectDockedOutline(geometry)?.height ?? null;
20
21
 
21
- function isActiveCell(dockPreview: DragPreview | null, overlay: HoverOverlay, position: string): boolean {
22
- return dockPreview?.kind === "dock"
23
- && dockPreview.target.kind === "leaf"
24
- && dockPreview.target.targetId === overlay.targetId
25
- && dockPreview.target.position === position;
26
- }
27
-
28
22
  export function ShellDragOverlays(props: {
29
- dockLeafLayouts: DockLeafLayout[];
30
23
  /** A pane from another window over this one's edge. */
31
24
  externalDockPreview: DragPreview | null;
32
25
  live: LiveDragStore;
@@ -50,44 +43,26 @@ function TerminalDockedDragOutline({ live }: { live: LiveDragStore }) {
50
43
  borderStyle="single"
51
44
  borderColor={colors.borderFocused}
52
45
  backgroundColor={colors.panel}
53
- zIndex={95}
46
+ zIndex={SHELL_DRAG_Z.under}
54
47
  />
55
48
  );
56
49
  }
57
50
 
51
+ /**
52
+ * Terminal: where the release would land is an outline with nothing filled
53
+ * in, so what it is over stays readable.
54
+ */
58
55
  function TerminalDragOverlays({
59
- dockLeafLayouts,
60
56
  externalDockPreview,
61
57
  live,
62
58
  }: {
63
- dockLeafLayouts: DockLeafLayout[];
64
59
  externalDockPreview: DragPreview | null;
65
60
  live: LiveDragStore;
66
61
  }) {
67
- const activeHoverOverlay = useLiveHoverOverlay(live, dockLeafLayouts);
68
62
  const dockPreview = useLiveDrag(live, selectDockPreview);
69
63
  const effectiveDockPreview = dockPreview ?? externalDockPreview;
70
64
  return (
71
65
  <>
72
- {activeHoverOverlay && activeHoverOverlay.cells.map((cell) => {
73
- const active = isActiveCell(dockPreview, activeHoverOverlay, cell.position);
74
- return (
75
- <Box
76
- key={`cell:${activeHoverOverlay.targetId}:${cell.position}`}
77
- position="absolute"
78
- left={cell.rect.x}
79
- top={cell.rect.y}
80
- width={cell.rect.width}
81
- height={cell.rect.height}
82
- border
83
- borderStyle="single"
84
- borderColor={active ? colors.borderFocused : colors.border}
85
- backgroundColor={active ? colors.header : colors.panel}
86
- zIndex={cell.position === "center" ? 98 : 97}
87
- />
88
- );
89
- })}
90
-
91
66
  {!effectiveDockPreview && <TerminalDockedDragOutline live={live} />}
92
67
 
93
68
  {effectiveDockPreview && (
@@ -100,8 +75,7 @@ function TerminalDragOverlays({
100
75
  border
101
76
  borderStyle="single"
102
77
  borderColor={colors.borderFocused}
103
- backgroundColor={colors.panel}
104
- zIndex={96}
78
+ zIndex={SHELL_DRAG_Z.over}
105
79
  />
106
80
  )}
107
81
  </>
@@ -109,30 +83,32 @@ function TerminalDragOverlays({
109
83
  }
110
84
 
111
85
  /**
112
- * Desktop: an outline laid out at the shell's corner and drawn at `rect` by a
86
+ * Desktop: an overlay laid out at the shell's corner and drawn at `rect` by a
113
87
  * transform, hidden by opacity, so a new drop target restyles it in place.
88
+ * `framed` draws the border and fill of a pane (the outline a docked pane
89
+ * drags around); without it, styles.css draws the box by its role.
114
90
  */
115
- function OutlineBox({
91
+ function OverlayBox({
116
92
  rect,
117
93
  zIndex,
118
- borderColor = colors.borderFocused,
119
- backgroundColor = colors.panel,
120
94
  role,
95
+ framed = false,
96
+ opacity = 1,
121
97
  boxRef,
122
98
  follows = false,
123
99
  }: {
124
100
  rect: LayoutBounds | null;
125
101
  zIndex: number;
126
- borderColor?: string;
127
- backgroundColor?: string;
128
102
  role: string;
103
+ framed?: boolean;
104
+ opacity?: number;
129
105
  boxRef?: RefObject<BoxRenderable | null>;
130
106
  /** Its position follows the pointer outside React (`useLiveBoxFrame`). */
131
107
  follows?: boolean;
132
108
  }) {
133
109
  const style: CSSProperties = {
134
110
  ...(rect && !follows ? placeStyle(rect.x, rect.y) : undefined),
135
- opacity: rect ? 1 : 0,
111
+ opacity: rect ? opacity : 0,
136
112
  pointerEvents: "none",
137
113
  };
138
114
  return (
@@ -143,10 +119,12 @@ function OutlineBox({
143
119
  top={0}
144
120
  width={rect?.width ?? 0}
145
121
  height={rect?.height ?? 0}
146
- border
147
- borderStyle="single"
148
- borderColor={borderColor}
149
- backgroundColor={backgroundColor}
122
+ {...(framed ? {
123
+ border: true,
124
+ borderStyle: "single",
125
+ borderColor: colors.borderFocused,
126
+ backgroundColor: colors.panel,
127
+ } : {})}
150
128
  zIndex={zIndex}
151
129
  data-gloom-role={role}
152
130
  style={style}
@@ -155,62 +133,86 @@ function OutlineBox({
155
133
  }
156
134
 
157
135
  /**
158
- * Desktop overlays of a pane move: the outline a docked pane drags around, the
159
- * drop grid of the pane under the pointer and the dock or snap preview. They
160
- * render when the drop target changes, never on a move: the outline follows
161
- * the pointer by restyling itself.
136
+ * Desktop: where a pane would land. The exact rectangle, outlined in the
137
+ * accent over a light tint of it (styles.css), so the panes under it still
138
+ * show; window mode's keyboard move draws the same.
139
+ */
140
+ export function DesktopDropPreview({
141
+ rect,
142
+ zIndex,
143
+ role = "drop-preview",
144
+ attributes,
145
+ }: {
146
+ rect: LayoutBounds | null;
147
+ zIndex: number;
148
+ role?: string;
149
+ attributes?: Record<string, string>;
150
+ }) {
151
+ return (
152
+ <Box
153
+ position="absolute"
154
+ left={0}
155
+ top={0}
156
+ width={rect?.width ?? 0}
157
+ height={rect?.height ?? 0}
158
+ zIndex={zIndex}
159
+ data-gloom-role={role}
160
+ {...attributes}
161
+ style={{
162
+ ...(rect ? placeStyle(rect.x, rect.y) : undefined),
163
+ opacity: rect ? 1 : 0,
164
+ pointerEvents: "none",
165
+ }}
166
+ />
167
+ );
168
+ }
169
+
170
+ /**
171
+ * Desktop overlays of a pane move: the outline a docked pane drags around and
172
+ * the dock or snap preview. They render when the drop target changes, never
173
+ * on a move: the outline follows the pointer by restyling itself.
162
174
  */
163
175
  function DesktopDragOverlays({
164
- dockLeafLayouts,
165
176
  externalDockPreview,
166
177
  live,
167
178
  }: {
168
- dockLeafLayouts: DockLeafLayout[];
169
179
  externalDockPreview: DragPreview | null;
170
180
  live: LiveDragStore;
171
181
  }) {
172
182
  const dragging = useLiveDrag(live, selectPaneDragActive);
173
183
  if (!dragging && !externalDockPreview) return null;
174
- return <DesktopDragOverlayLayers dockLeafLayouts={dockLeafLayouts} externalDockPreview={externalDockPreview} live={live} />;
184
+ return <DesktopDragOverlayLayers externalDockPreview={externalDockPreview} live={live} />;
175
185
  }
176
186
 
177
187
  function DesktopDragOverlayLayers({
178
- dockLeafLayouts,
179
188
  externalDockPreview,
180
189
  live,
181
190
  }: {
182
- dockLeafLayouts: DockLeafLayout[];
183
191
  externalDockPreview: DragPreview | null;
184
192
  live: LiveDragStore;
185
193
  }) {
186
- const activeHoverOverlay = useLiveHoverOverlay(live, dockLeafLayouts);
187
194
  const dockPreview = useLiveDrag(live, selectDockPreview);
188
195
  const effectiveDockPreview = dockPreview ?? externalDockPreview;
189
196
  const outlineWidth = useLiveDrag(live, selectOutlineWidth);
190
197
  const outlineHeight = useLiveDrag(live, selectOutlineHeight);
191
198
  const outlineRef = useRef<BoxRenderable | null>(null);
192
199
  useLiveBoxFrame(live, outlineRef, followDockedOutline);
193
- const outline = outlineWidth !== null && outlineHeight !== null && !effectiveDockPreview
200
+ const outline = outlineWidth !== null && outlineHeight !== null
194
201
  ? { x: 0, y: 0, width: outlineWidth, height: outlineHeight }
195
202
  : null;
196
203
  return (
197
204
  <>
198
- {CELL_POSITIONS.map((position) => {
199
- const cell = activeHoverOverlay?.cells.find((entry) => entry.position === position) ?? null;
200
- const active = !!activeHoverOverlay && isActiveCell(dockPreview, activeHoverOverlay, position);
201
- return (
202
- <OutlineBox
203
- key={position}
204
- role="drop-cell"
205
- rect={cell?.rect ?? null}
206
- borderColor={active ? colors.borderFocused : colors.border}
207
- backgroundColor={active ? colors.header : colors.panel}
208
- zIndex={position === "center" ? 98 : 97}
209
- />
210
- );
211
- })}
212
- <OutlineBox role="drag-outline" rect={outline} zIndex={95} boxRef={outlineRef} follows />
213
- <OutlineBox role="drop-preview" rect={effectiveDockPreview?.rect ?? null} zIndex={96} />
205
+ {/* The preview sits under what is moving, which turns see-through over it. */}
206
+ <DesktopDropPreview rect={effectiveDockPreview?.rect ?? null} zIndex={SHELL_DRAG_Z.under} />
207
+ <OverlayBox
208
+ role="drag-outline"
209
+ rect={outline}
210
+ zIndex={SHELL_DRAG_Z.over}
211
+ framed
212
+ opacity={effectiveDockPreview ? ARMED_DRAG_OPACITY : 1}
213
+ boxRef={outlineRef}
214
+ follows
215
+ />
214
216
  </>
215
217
  );
216
218
  }
@@ -27,6 +27,7 @@ import {
27
27
  import type { ActionMenuState } from "../action-menu-overlay";
28
28
  import type { DividerPreviewState } from "../native/window-state";
29
29
  import { createLiveDragStore, IDLE_DRAG, type LiveDockGeometry, type LiveDragStore } from "./live";
30
+ import type { MagnetDistances } from "./magnets";
30
31
  import { beginLiveResize, createCatchUp } from "../../../../ui/live-resize";
31
32
  import type { WindowEditState } from "../../window-edit/mode";
32
33
  import { useShellActiveDrag } from "../active-drag";
@@ -67,6 +68,8 @@ export interface ShellMouseEvent {
67
68
  /** Desktop: where the browser predicts the pointer a moment later, for drawing only. */
68
69
  predictedX?: number;
69
70
  predictedY?: number;
71
+ /** Alt (Option) held: a moving or resizing pane ignores its magnets. */
72
+ modifiers?: { alt?: boolean };
70
73
  /** Whether a later handler has claimed this pointer interaction. */
71
74
  isDefaultPrevented?: () => boolean;
72
75
  stopPropagation: () => void;
@@ -86,8 +89,6 @@ export interface ShellDragRuntimeState {
86
89
  hasActiveDrag: () => boolean;
87
90
  /** Positions that follow the pointer, outside React state. */
88
91
  live: LiveDragStore;
89
- /** The tiled pane whose drop grid is under the pointer. */
90
- setHoverTarget: (targetId: string | null) => void;
91
92
  startDrag: (drag: DragMode) => void;
92
93
  /** `dock`: on the desktop, the panes and dividers under the split, where the pointer has them. */
93
94
  updateDividerPreview: (next: DividerPreviewState | null, dock?: LiveDockGeometry | null) => void;
@@ -103,6 +104,7 @@ function sameDragPreview(a: DragPreview | null, b: DragPreview | null): boolean
103
104
  const [x, y] = [a.target, b.target];
104
105
  if (x.kind === "frame" && y.kind === "frame") return x.edge === y.edge;
105
106
  if (x.kind === "leaf" && y.kind === "leaf") return x.targetId === y.targetId && x.position === y.position;
107
+ if (x.kind === "tab" && y.kind === "tab") return x.targetId === y.targetId;
106
108
  }
107
109
  return false;
108
110
  }
@@ -149,10 +151,6 @@ export function useShellDragRuntimeState({
149
151
  }
150
152
  }, [catchUp, contentHeight, live, nativePaneChrome, width]);
151
153
 
152
- const setHoverTarget = useCallback((targetId: string | null) => {
153
- live.set({ hoverTargetId: targetId });
154
- }, [live]);
155
-
156
154
  const updateDividerPreview = useCallback((next: DividerPreviewState | null, dock: LiveDockGeometry | null = null) => {
157
155
  const current = live.get().divider;
158
156
  // The desktop divider and the panes on both sides follow by restyling
@@ -202,7 +200,6 @@ export function useShellDragRuntimeState({
202
200
  endDrag,
203
201
  hasActiveDrag,
204
202
  live,
205
- setHoverTarget,
206
203
  startDrag,
207
204
  updateDividerPreview,
208
205
  updateDockPreview,
@@ -222,6 +219,8 @@ interface UseShellPointerRuntimeOptions {
222
219
  focusPane: (paneId: string) => void;
223
220
  focusedPaneId: string | null;
224
221
  handleFloatingClose: (paneId: string) => void;
222
+ /** How close a moving or resizing pane's edge comes to another before it sticks, in cells. */
223
+ magnetDistances: MagnetDistances;
225
224
  restoreFullscreen: () => void;
226
225
  menuState: ActionMenuState | null;
227
226
  nativePaneChrome: boolean;
@@ -231,6 +230,8 @@ interface UseShellPointerRuntimeOptions {
231
230
  event?: { preventDefault?: () => void; stopPropagation?: () => void },
232
231
  ) => void;
233
232
  openPaneDocs: (paneId: string) => void;
233
+ /** A pane's title as its header shows it: the terminal finds a stack's tabs by it. */
234
+ getPaneTitle: (pane: ResolvedPane) => string;
234
235
  paneMap: Map<string, ResolvedPane>;
235
236
  persistLayout: (nextLayout: LayoutConfig, options?: { pushHistory?: boolean }) => void;
236
237
  precisePointer: boolean | undefined;
@@ -259,11 +260,13 @@ export function useShellPointerRuntime({
259
260
  focusPane,
260
261
  focusedPaneId,
261
262
  handleFloatingClose,
263
+ magnetDistances,
262
264
  restoreFullscreen,
263
265
  menuState,
264
266
  nativePaneChrome,
265
267
  openPaneMenu,
266
268
  openPaneDocs,
269
+ getPaneTitle,
267
270
  paneMap,
268
271
  persistLayout,
269
272
  precisePointer,
@@ -287,6 +290,7 @@ export function useShellPointerRuntime({
287
290
  dockLeafLayouts,
288
291
  focusPane,
289
292
  dragRuntime,
293
+ magnetDistances,
290
294
  nativePaneChrome,
291
295
  paneMap,
292
296
  persistLayout,
@@ -313,6 +317,7 @@ export function useShellPointerRuntime({
313
317
  menuState,
314
318
  openPaneMenu,
315
319
  openPaneDocs,
320
+ getPaneTitle,
316
321
  paneMap,
317
322
  selectWindowModePane,
318
323
  setHoveredMenuItemId,