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
@@ -1,13 +1,14 @@
1
- import { useCallback, useRef } from "react";
1
+ import { useCallback, useEffect, useRef } from "react";
2
2
  import {
3
3
  floatAtRect,
4
4
  getDockSplitGeometry,
5
+ MIN_FLOAT_HEIGHT,
6
+ MIN_FLOAT_WIDTH,
5
7
  getRememberedFloatingRect,
6
8
  resizeSplitAtPath,
7
9
  simulateDrop,
8
10
  type DockGeometryOptions,
9
11
  type DockLeafLayout,
10
- type DropTarget,
11
12
  type FloatingRect,
12
13
  type LayoutBounds,
13
14
  type ResolvedPane,
@@ -15,20 +16,46 @@ import {
15
16
  import type { LayoutConfig } from "../../../types/config";
16
17
  import {
17
18
  finalizePaneDragRelease,
19
+ freePaneDragRect,
18
20
  isMeaningfulPaneDrag,
21
+ JOIN_DWELL_MS,
19
22
  makeSnapGuides,
20
23
  PANE_DRAG_THRESHOLD,
21
- pointInRect,
22
24
  PRECISE_PANE_DRAG_THRESHOLD,
23
25
  resolveDividerPreviewRect,
24
26
  resolveFloatResizeRect,
25
- resolveHoverOverlay,
26
27
  resolvePaneDragFloatingRect,
28
+ resolvePaneDropTarget,
27
29
  resolveSnapGuide,
28
30
  type DragPreview,
29
31
  } from "./drag";
30
32
  import type { ShellDragRuntimeState, ShellMouseEvent } from "./drag/runtime";
31
33
  import type { WindowEditState } from "../window-edit/mode";
34
+ import {
35
+ createMagnetPace,
36
+ NO_LATCH,
37
+ snapMovedRect,
38
+ snapResizedRect,
39
+ type MagnetDistances,
40
+ type MagnetLatch,
41
+ type MagnetPace,
42
+ } from "./drag/magnets";
43
+ import { paneHeaderRows } from "../pane/sizing";
44
+
45
+ /** A join the pointer has lined up: armed once it has held for JOIN_DWELL_MS. */
46
+ interface PendingJoin {
47
+ key: string;
48
+ armed: boolean;
49
+ timer: ReturnType<typeof setTimeout> | null;
50
+ }
51
+
52
+ function dropPendingJoin(memo: { join: PendingJoin | null }) {
53
+ if (memo.join?.timer) clearTimeout(memo.join.timer);
54
+ memo.join = null;
55
+ }
56
+
57
+ /** A resize without edges is the bottom-right corner's (the terminal's only one). */
58
+ const CORNER_EDGES = { x: 1, y: 1 } as const;
32
59
 
33
60
  interface UseShellActiveDragOptions {
34
61
  appHeaderHeight: number;
@@ -38,6 +65,8 @@ interface UseShellActiveDragOptions {
38
65
  dockLeafLayouts: DockLeafLayout[];
39
66
  dragRuntime: ShellDragRuntimeState;
40
67
  focusPane: (paneId: string) => void;
68
+ /** How close a moving or resizing pane's edge comes to another before it sticks, in cells. */
69
+ magnetDistances: MagnetDistances;
41
70
  nativePaneChrome: boolean;
42
71
  paneMap: Map<string, ResolvedPane>;
43
72
  persistLayout: (nextLayout: LayoutConfig, options?: { pushHistory?: boolean }) => void;
@@ -57,6 +86,7 @@ export function useShellActiveDrag({
57
86
  dockLeafLayouts,
58
87
  dragRuntime,
59
88
  focusPane,
89
+ magnetDistances,
60
90
  nativePaneChrome,
61
91
  paneMap,
62
92
  persistLayout,
@@ -72,21 +102,34 @@ export function useShellActiveDrag({
72
102
  dragRef,
73
103
  endDrag,
74
104
  live,
75
- setHoverTarget,
76
105
  updateDividerPreview,
77
106
  updateDockPreview,
78
107
  updateDragFloatingRect,
79
108
  } = dragRuntime;
80
- // What one drag keeps between moves: a docked pane's floating size, and the
81
- // last drop it simulated, so a move over the same target computes nothing.
109
+ // What one drag keeps between moves: a docked pane's floating size, the
110
+ // last drop it simulated, so a move over the same target computes nothing,
111
+ // the edges its magnets hold, with the other panes' rects they hold to, the
112
+ // join it is holding still for, and on the desktop where the pointer has
113
+ // been lately (the magnets wait for it to slow down) with the check that
114
+ // catches once it rests.
82
115
  const memoRef = useRef<{
83
116
  drag: unknown;
84
117
  baseRect: FloatingRect | null;
85
118
  dropKey: string | null;
86
119
  drop: DragPreview | null;
87
- }>({ drag: null, baseRect: null, dropKey: null, drop: null });
120
+ latch: MagnetLatch;
121
+ magnetTargets: LayoutBounds[] | null;
122
+ join: PendingJoin | null;
123
+ pace: MagnetPace;
124
+ }>({ drag: null, baseRect: null, dropKey: null, drop: null, latch: NO_LATCH, magnetTargets: null, join: null, pace: createMagnetPace() });
125
+ useEffect(() => () => {
126
+ dropPendingJoin(memoRef.current);
127
+ memoRef.current.pace.reset();
128
+ }, []);
129
+ // The handler as it is now, for the rest check to run again.
130
+ const handleRef = useRef<(event: ShellMouseEvent) => void>(() => {});
88
131
 
89
- return useCallback((event: ShellMouseEvent) => {
132
+ const handle = useCallback((event: ShellMouseEvent) => {
90
133
  const shellY = event.y - appHeaderHeight;
91
134
  const preciseX = event.preciseX ?? event.x;
92
135
  const preciseShellY = (event.preciseY ?? event.y) - appHeaderHeight;
@@ -106,7 +149,62 @@ export function useShellActiveDrag({
106
149
  memo.baseRect = null;
107
150
  memo.dropKey = null;
108
151
  memo.drop = null;
152
+ memo.latch = NO_LATCH;
153
+ memo.magnetTargets = null;
154
+ memo.pace.reset();
155
+ dropPendingJoin(memo);
109
156
  }
157
+ // Any later event supersedes the rest check of an earlier move.
158
+ memo.pace.cancel();
159
+ // Every other pane on screen, docked or floating, whose edges a floating
160
+ // pane's edges stick to. Alt (Option) lets it go anywhere.
161
+ const magnetTargets = (paneId: string) => {
162
+ memo.magnetTargets ??= [
163
+ ...dockLeafLayouts.filter((leaf) => leaf.instanceId !== paneId).map((leaf) => leaf.rect),
164
+ ...baseLayout.floating
165
+ .filter((entry) => entry.instanceId !== paneId && paneMap.has(entry.instanceId))
166
+ .map(({ x, y, width: w, height: h }) => ({ x, y, width: w, height: h })),
167
+ ];
168
+ return memo.magnetTargets;
169
+ };
170
+ const magnetsOff = event.modifiers?.alt === true;
171
+ const magnetArea = { x: 0, y: 0, width, height: contentHeight };
172
+ // Desktop: while the pointer travels, a moving pane follows it exactly;
173
+ // its magnets catch once it slows down near a line, or rests there (the
174
+ // rest check runs the last move again once the pointer has stopped). What
175
+ // they hold to still follows every move, so it rests where it would have.
176
+ const travelling = () => {
177
+ if (!nativePaneChrome || drag.type !== "pane-drag") return false;
178
+ // A release lands where the pane is drawn: no catch after it.
179
+ const rest = event.type === "drag" ? () => { if (dragRef.current === drag) handleRef.current(event); } : undefined;
180
+ return memo.pace.travelling({ t: performance.now(), x: preciseX, y: preciseShellY }, magnetDistances, rest);
181
+ };
182
+ const snapMove = (paneId: string, rect: FloatingRect): FloatingRect => {
183
+ if (magnetsOff) {
184
+ memo.latch = NO_LATCH;
185
+ return rect;
186
+ }
187
+ const snapped = snapMovedRect(rect, magnetTargets(paneId), magnetArea, magnetDistances, memo.latch);
188
+ memo.latch = snapped.latch;
189
+ return travelling() ? rect : snapped.rect;
190
+ };
191
+ const snapResize = (paneId: string, rect: FloatingRect, edges: { x: -1 | 0 | 1; y: -1 | 0 | 1 }): FloatingRect => {
192
+ if (magnetsOff) {
193
+ memo.latch = NO_LATCH;
194
+ return rect;
195
+ }
196
+ const snapped = snapResizedRect(
197
+ rect,
198
+ edges,
199
+ { width: MIN_FLOAT_WIDTH, height: MIN_FLOAT_HEIGHT },
200
+ magnetTargets(paneId),
201
+ magnetArea,
202
+ magnetDistances,
203
+ memo.latch,
204
+ );
205
+ memo.latch = snapped.latch;
206
+ return snapped.rect;
207
+ };
110
208
  const dividerRatioAt = (x: number, y: number) => {
111
209
  if (drag.type !== "divider") return 0;
112
210
  const total = drag.axis === "horizontal" ? drag.bounds.width : drag.bounds.height;
@@ -122,6 +220,7 @@ export function useShellActiveDrag({
122
220
 
123
221
  if (event.type === "drag-cancel") {
124
222
  // The window lost focus or the system took the pointer: put everything back.
223
+ dropPendingJoin(memo);
125
224
  cancelActiveDrag();
126
225
  event.stopPropagation();
127
226
  event.preventDefault();
@@ -150,7 +249,6 @@ export function useShellActiveDrag({
150
249
  } else if (drag.type === "pane-drag") {
151
250
  if (!isMeaningfulPaneDrag(drag.startX, drag.startY, preciseX, preciseShellY, dragThreshold)) {
152
251
  updateDockPreview(null);
153
- setHoverTarget(null);
154
252
  if (drag.mode === "floating") {
155
253
  updateDragFloatingRect({ paneId: drag.paneId, rect: drag.origRect });
156
254
  }
@@ -159,33 +257,65 @@ export function useShellActiveDrag({
159
257
  return;
160
258
  }
161
259
 
162
- const nextRect = resolvePaneDragFloatingRect(drag, dragBaseRect()!, drawX, drawShellY, width, contentHeight);
260
+ const nextRect = snapMove(drag.paneId, resolvePaneDragFloatingRect(drag, dragBaseRect()!, drawX, drawShellY, width, contentHeight));
163
261
  updateDragFloatingRect({ paneId: drag.paneId, rect: nextRect });
164
262
 
165
- const hoveredOverlay = resolveHoverOverlay(hitX, hitShellY, dockLeafLayouts, drag.paneId);
166
- setHoverTarget(hoveredOverlay?.targetId ?? null);
167
- if (hoveredOverlay) {
168
- const hoveredCell = hoveredOverlay.cells.find((cell) => pointInRect(cell.rect, hitX, hitShellY));
169
- if (hoveredCell) {
170
- const dropKey = `${hoveredOverlay.targetId}:${hoveredCell.position}`;
263
+ // Over a title bar it would be a tab there; pushed against a docked
264
+ // pane's edge it would join the dock on that side.
265
+ const target = resolvePaneDropTarget({
266
+ x: hitX,
267
+ y: hitShellY,
268
+ rect: nextRect,
269
+ free: freePaneDragRect(drag, dragBaseRect()!, drawX, drawShellY, width, contentHeight),
270
+ leaves: dockLeafLayouts,
271
+ paneId: drag.paneId,
272
+ area: bounds,
273
+ flush: { x: magnetDistances.catchX, y: magnetDistances.catchY },
274
+ headerRows: paneHeaderRows(nativePaneChrome),
275
+ join: !magnetsOff,
276
+ });
277
+ const showSnapGuide = () => {
278
+ const snapGuide = resolveSnapGuide(hitX, hitShellY, snapGuides);
279
+ updateDockPreview(snapGuide ? { kind: "snap", position: snapGuide.position, rect: snapGuide.previewRect } : null);
280
+ };
281
+ if (target) {
282
+ const dropKey = target.kind === "tab" ? `tab:${target.targetId}` : target.kind === "leaf" ? `${target.targetId}:${target.position}` : target.edge;
283
+ const showDrop = () => {
171
284
  if (memo.dropKey !== dropKey) {
172
- const target: DropTarget = { kind: "leaf", targetId: hoveredOverlay.targetId, position: hoveredCell.position };
173
285
  const simulation = simulateDrop(baseLayout, drag.paneId, target, bounds, dockGeometryOptions);
174
286
  memo.dropKey = dropKey;
175
287
  memo.drop = simulation.previewRect ? { kind: "dock", target, rect: simulation.previewRect } : null;
176
288
  }
177
289
  updateDockPreview(memo.drop);
290
+ };
291
+ if (target.kind === "leaf") {
292
+ // A join arms once the edge has held, and shows its preview then:
293
+ // a release before that leaves the pane floating where it is.
294
+ if (memo.join?.key !== dropKey) {
295
+ dropPendingJoin(memo);
296
+ const join: PendingJoin = { key: dropKey, armed: false, timer: null };
297
+ join.timer = setTimeout(() => {
298
+ if (memo.join !== join || dragRef.current !== drag) return;
299
+ join.armed = true;
300
+ join.timer = null;
301
+ showDrop();
302
+ }, JOIN_DWELL_MS);
303
+ memo.join = join;
304
+ }
305
+ if (memo.join?.armed) showDrop();
306
+ else showSnapGuide();
178
307
  } else {
179
- updateDockPreview(null);
308
+ dropPendingJoin(memo);
309
+ showDrop();
180
310
  }
181
311
  } else {
182
- const snapGuide = resolveSnapGuide(hitX, hitShellY, snapGuides);
183
- updateDockPreview(snapGuide ? { kind: "snap", position: snapGuide.position, rect: snapGuide.previewRect } : null);
312
+ dropPendingJoin(memo);
313
+ showSnapGuide();
184
314
  }
185
315
  } else if (drag.type === "float-resize") {
186
316
  updateDragFloatingRect({
187
317
  paneId: drag.paneId,
188
- rect: resolveFloatResizeRect(drag, preciseX, preciseShellY, width, contentHeight),
318
+ rect: snapResize(drag.paneId, resolveFloatResizeRect(drag, preciseX, preciseShellY, width, contentHeight), drag.edges ?? CORNER_EDGES),
189
319
  });
190
320
  }
191
321
  event.stopPropagation();
@@ -194,6 +324,7 @@ export function useShellActiveDrag({
194
324
  }
195
325
 
196
326
  if (event.type === "up" || event.type === "drag-end") {
327
+ dropPendingJoin(memo);
197
328
  if (drag.type === "divider") {
198
329
  if (live.get().divider) {
199
330
  const nextLayout = resizeSplitAtPath(baseLayout, drag.path, dividerRatioAt(preciseX, preciseShellY));
@@ -208,10 +339,11 @@ export function useShellActiveDrag({
208
339
  const movedEnough = isMeaningfulPaneDrag(drag.startX, drag.startY, preciseX, preciseShellY, dragThreshold);
209
340
  if (!movedEnough) {
210
341
  updateDockPreview(null);
211
- setHoverTarget(null);
212
342
  updateDragFloatingRect(null);
343
+ // A click on a stack's tab shows that pane.
344
+ if (drag.mode === "docked") focusPane(drag.paneId);
213
345
  } else {
214
- const releaseRect = resolvePaneDragFloatingRect(drag, dragBaseRect()!, preciseX, preciseShellY, width, contentHeight);
346
+ const releaseRect = snapMove(drag.paneId, resolvePaneDragFloatingRect(drag, dragBaseRect()!, preciseX, preciseShellY, width, contentHeight));
215
347
  const nextLayout = finalizePaneDragRelease(baseLayout, drag.paneId, releaseRect, live.get().dockPreview);
216
348
  if (windowMode) {
217
349
  updateWindowModePreviewLayout(nextLayout, drag.paneId);
@@ -220,11 +352,10 @@ export function useShellActiveDrag({
220
352
  }
221
353
  focusPane(drag.paneId);
222
354
  updateDockPreview(null);
223
- setHoverTarget(null);
224
355
  updateDragFloatingRect(null);
225
356
  }
226
357
  } else if (drag.type === "float-resize") {
227
- const releaseRect = resolveFloatResizeRect(drag, preciseX, preciseShellY, width, contentHeight);
358
+ const releaseRect = snapResize(drag.paneId, resolveFloatResizeRect(drag, preciseX, preciseShellY, width, contentHeight), drag.edges ?? CORNER_EDGES);
228
359
  const nextLayout = floatAtRect(baseLayout, drag.paneId, releaseRect);
229
360
  if (windowMode) {
230
361
  updateWindowModePreviewLayout(nextLayout, drag.paneId);
@@ -232,7 +363,6 @@ export function useShellActiveDrag({
232
363
  persistLayout(nextLayout);
233
364
  }
234
365
  updateDragFloatingRect(null);
235
- setHoverTarget(null);
236
366
  }
237
367
  endDrag();
238
368
  event.stopPropagation();
@@ -249,11 +379,11 @@ export function useShellActiveDrag({
249
379
  endDrag,
250
380
  focusPane,
251
381
  live,
382
+ magnetDistances,
252
383
  nativePaneChrome,
253
384
  paneMap,
254
385
  persistLayout,
255
386
  precisePointer,
256
- setHoverTarget,
257
387
  snapGuides,
258
388
  updateDividerPreview,
259
389
  updateDockPreview,
@@ -263,4 +393,6 @@ export function useShellActiveDrag({
263
393
  windowMode,
264
394
  width,
265
395
  ]);
396
+ handleRef.current = handle;
397
+ return handle;
266
398
  }
@@ -12,12 +12,6 @@ import type { DesktopDockPreviewState } from "../../../../types/desktop-window";
12
12
  import type { LayoutConfig } from "../../../../types/config";
13
13
  import { PANE_HEADER_ACTION, PANE_HEADER_CLOSE, PANE_HEADER_HELP, PANE_HEADER_RESTORE } from "../../pane/header";
14
14
 
15
- export interface HoverOverlay {
16
- targetId: string;
17
- rect: LayoutBounds;
18
- cells: Array<{ position: "top" | "left" | "center" | "right" | "bottom"; rect: LayoutBounds }>;
19
- }
20
-
21
15
  export type SnapGuidePosition =
22
16
  | "left"
23
17
  | "right"
@@ -121,22 +115,31 @@ export function constrainFloatingRectToBounds(
121
115
  };
122
116
  }
123
117
 
124
- function positionFloatingRectUnderPointer(
125
- rect: FloatingRect,
118
+ /**
119
+ * Where the pointer alone puts a pane on the move, before the screen's edges
120
+ * hold it in: a docked pane at its floating size, held where it was pressed
121
+ * (as far into it as it reaches); a floating one moved by the pointer.
122
+ */
123
+ export function freePaneDragRect(
126
124
  drag: PaneDragRectState,
125
+ baseRect: FloatingRect,
127
126
  pointerX: number,
128
127
  pointerY: number,
129
128
  totalWidth: number,
130
129
  totalHeight: number,
131
130
  ): FloatingRect {
132
- const fittedRect = constrainFloatingRectToBounds(rect, totalWidth, totalHeight);
133
- const pointerOffsetX = Math.max(0, Math.min(fittedRect.width - 1, drag.startX - drag.origRect.x));
134
- const pointerOffsetY = Math.max(0, Math.min(fittedRect.height - 1, drag.startY - drag.origRect.y));
135
- return constrainFloatingRectToBounds({
136
- ...fittedRect,
137
- x: pointerX - pointerOffsetX,
138
- y: pointerY - pointerOffsetY,
139
- }, totalWidth, totalHeight);
131
+ if (drag.mode === "docked") {
132
+ const fittedRect = constrainFloatingRectToBounds(baseRect, totalWidth, totalHeight);
133
+ const pointerOffsetX = Math.max(0, Math.min(fittedRect.width - 1, drag.startX - drag.origRect.x));
134
+ const pointerOffsetY = Math.max(0, Math.min(fittedRect.height - 1, drag.startY - drag.origRect.y));
135
+ return { ...fittedRect, x: pointerX - pointerOffsetX, y: pointerY - pointerOffsetY };
136
+ }
137
+ return {
138
+ x: drag.origRect.x + (pointerX - drag.startX),
139
+ y: drag.origRect.y + (pointerY - drag.startY),
140
+ width: drag.origRect.width,
141
+ height: drag.origRect.height,
142
+ };
140
143
  }
141
144
 
142
145
  export function resolvePaneDragFloatingRect(
@@ -147,16 +150,7 @@ export function resolvePaneDragFloatingRect(
147
150
  totalWidth: number,
148
151
  totalHeight: number,
149
152
  ): FloatingRect {
150
- if (drag.mode === "docked") {
151
- return positionFloatingRectUnderPointer(baseRect, drag, pointerX, pointerY, totalWidth, totalHeight);
152
- }
153
-
154
- return constrainFloatingRectToBounds({
155
- x: drag.origRect.x + (pointerX - drag.startX),
156
- y: drag.origRect.y + (pointerY - drag.startY),
157
- width: drag.origRect.width,
158
- height: drag.origRect.height,
159
- }, totalWidth, totalHeight);
153
+ return constrainFloatingRectToBounds(freePaneDragRect(drag, baseRect, pointerX, pointerY, totalWidth, totalHeight), totalWidth, totalHeight);
160
154
  }
161
155
 
162
156
  /**
@@ -188,82 +182,91 @@ export function resolveFloatResizeRect(
188
182
  return constrainFloatingRectToBounds({ x, y, width, height, zIndex: origRect.zIndex }, totalWidth, totalHeight);
189
183
  }
190
184
 
191
- function centerRectWithin(parent: LayoutBounds, width: number, height: number): LayoutBounds {
192
- const nextWidth = Math.max(1, Math.min(parent.width, width));
193
- const nextHeight = Math.max(1, Math.min(parent.height, height));
194
- return {
195
- x: parent.x + Math.floor((parent.width - nextWidth) / 2),
196
- y: parent.y + Math.floor((parent.height - nextHeight) / 2),
197
- width: nextWidth,
198
- height: nextHeight,
199
- };
185
+ /** A distance on each axis, in cells. */
186
+ export interface AxisDistance {
187
+ x: number;
188
+ y: number;
200
189
  }
201
190
 
202
- function compactOverlayRect(rect: LayoutBounds): LayoutBounds {
203
- if (rect.width < 12 || rect.height < 7) return rect;
204
- return centerRectWithin(
205
- rect,
206
- Math.max(9, Math.min(19, Math.floor(rect.width * 0.45))),
207
- Math.max(5, Math.min(9, Math.floor(rect.height * 0.45))),
208
- );
209
- }
191
+ const JOIN_SIDES = [
192
+ ["left", "x"],
193
+ ["right", "x"],
194
+ ["top", "y"],
195
+ ["bottom", "y"],
196
+ ] as const;
210
197
 
211
- function makeOverlayCellRects(rect: LayoutBounds): HoverOverlay["cells"] {
212
- const col1 = Math.max(1, Math.floor(rect.width / 3));
213
- const col2 = Math.max(1, Math.floor((rect.width - col1) / 2));
214
- const col3 = Math.max(1, rect.width - col1 - col2);
215
- const row1 = Math.max(1, Math.floor(rect.height / 3));
216
- const row2 = Math.max(1, Math.floor((rect.height - row1) / 2));
217
- const row3 = Math.max(1, rect.height - row1 - row2);
218
- const cols = [col1, col2, col3];
219
- const rows = [row1, row2, row3];
220
- const cells: HoverOverlay["cells"] = [];
221
- let y = rect.y;
222
- for (let rowIndex = 0; rowIndex < 3; rowIndex += 1) {
223
- let x = rect.x;
224
- for (let colIndex = 0; colIndex < 3; colIndex += 1) {
225
- const position = (
226
- rowIndex === 0 && colIndex === 1 ? "top"
227
- : rowIndex === 1 && colIndex === 0 ? "left"
228
- : rowIndex === 1 && colIndex === 1 ? "center"
229
- : rowIndex === 1 && colIndex === 2 ? "right"
230
- : rowIndex === 2 && colIndex === 1 ? "bottom"
231
- : null
232
- );
233
- if (position) {
234
- cells.push({
235
- position,
236
- rect: { x, y, width: cols[colIndex]!, height: rows[rowIndex]! },
237
- });
238
- }
239
- x += cols[colIndex]!;
240
- }
241
- y += rows[rowIndex]!;
242
- }
243
- return cells;
244
- }
198
+ type JoinSide = (typeof JOIN_SIDES)[number][0];
245
199
 
246
- /** The drop grid drawn over a docked pane while another pane is dragged onto it. */
247
- export function hoverOverlayForLeaf(leaf: DockLeafLayout): HoverOverlay {
248
- const overlayRect = compactOverlayRect(leaf.rect);
249
- return {
250
- targetId: leaf.instanceId,
251
- rect: overlayRect,
252
- cells: makeOverlayCellRects(overlayRect),
253
- };
200
+ /**
201
+ * Where a pane on the move would land on release, if anywhere but where it is
202
+ * drawn. Over another spot's title bar it becomes a tab there. Its edge
203
+ * pushed flush against the same edge of the spot under the pointer, where
204
+ * that spot meets another (never the dock's own edge, so a window parked at
205
+ * the screen's edge or corner stays floating), it joins the dock on that
206
+ * side: where it is drawn and where the pointer puts it, that edge is within
207
+ * `flush` of the spot's. The caller arms a join only once it has held (see
208
+ * JOIN_DWELL_MS). `join` false (Alt) leaves the edges out.
209
+ */
210
+ export function resolvePaneDropTarget({
211
+ x,
212
+ y,
213
+ rect,
214
+ free,
215
+ leaves,
216
+ paneId,
217
+ area,
218
+ flush,
219
+ headerRows,
220
+ join,
221
+ }: {
222
+ /** The pointer, in shell cells. */
223
+ x: number;
224
+ y: number;
225
+ /** Where the moving pane is drawn, its edges caught by the magnets. */
226
+ rect: LayoutBounds;
227
+ /** Where the pointer alone puts it, past the screen's edges if it goes there. */
228
+ free: LayoutBounds;
229
+ leaves: readonly DockLeafLayout[];
230
+ paneId: string;
231
+ /** The dock area. */
232
+ area: LayoutBounds;
233
+ /** How close its edge comes to a spot's edge to count as flush (the magnets' catch). */
234
+ flush: AxisDistance;
235
+ /** A docked pane's title bar, in rows. */
236
+ headerRows: number;
237
+ join: boolean;
238
+ }): DropTarget | null {
239
+ if (!pointInRect(area, x, y)) return null;
240
+ const leaf = leaves.find((entry) => pointInRect(entry.rect, x, y));
241
+ if (!leaf) return null;
242
+ // Its own spot: alone there, nothing to land on; a tab of a stack can
243
+ // leave it for a side of the stack, but is a tab of it already.
244
+ const own = leaf.instanceId === paneId || (leaf.stack?.includes(paneId) ?? false);
245
+ const targetId = leaf.instanceId !== paneId ? leaf.instanceId : leaf.stack?.find((id) => id !== paneId);
246
+ if (!targetId) return null;
247
+ if (y < leaf.rect.y + headerRows) return own ? null : { kind: "tab", targetId };
248
+ if (!join) return null;
249
+ const edgeOf = (box: LayoutBounds, side: JoinSide) => (
250
+ side === "left" ? box.x : side === "right" ? box.x + box.width : side === "top" ? box.y : box.y + box.height
251
+ );
252
+ let best: { side: JoinSide; closeness: number } | null = null;
253
+ for (const [side, axis] of JOIN_SIDES) {
254
+ const line = edgeOf(leaf.rect, side);
255
+ // The dock's own edge is the screen's: parking there is not joining.
256
+ if (Math.abs(line - edgeOf(area, side)) <= flush[axis]) continue;
257
+ if (Math.abs(edgeOf(free, side) - line) > flush[axis]) continue;
258
+ const closeness = Math.abs(edgeOf(rect, side) - line) / Math.max(flush[axis], 1e-6);
259
+ if (closeness <= 1 && (!best || closeness < best.closeness)) best = { side, closeness };
260
+ }
261
+ return best ? { kind: "leaf", targetId, position: best.side } : null;
254
262
  }
255
263
 
256
- export function resolveHoverOverlay(
257
- x: number,
258
- y: number,
259
- leaves: DockLeafLayout[],
260
- draggedPaneId: string,
261
- ): HoverOverlay | null {
262
- const targetLeaf = leaves.find((leaf) => leaf.instanceId !== draggedPaneId && pointInRect(leaf.rect, x, y));
263
- if (!targetLeaf) return null;
264
- const overlay = hoverOverlayForLeaf(targetLeaf);
265
- return pointInRect(overlay.rect, x, y) ? overlay : null;
266
- }
264
+ /**
265
+ * How long an edge holds flush before the join arms and its preview shows, so
266
+ * a window moved past a docked pane's edge, or briefly lined up with it, does
267
+ * not dock on release.
268
+ */
269
+ export const JOIN_DWELL_MS = 350;
267
270
 
268
271
  export function resolveDividerPreviewRect(
269
272
  axis: "horizontal" | "vertical",
@@ -1,8 +1,8 @@
1
- import { startTransition, useCallback, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore, type RefObject } from "react";
2
- import type { DockLeafLayout, FloatingRect, LayoutBounds } from "../../../../layout/pane-manager";
1
+ import { startTransition, useCallback, useLayoutEffect, useRef, useState, useSyncExternalStore, type RefObject } from "react";
2
+ import type { FloatingRect, LayoutBounds } from "../../../../layout/pane-manager";
3
3
  import type { BoxRenderable, LiveBoxFrame } from "../../../../ui";
4
4
  import type { DividerPreviewState } from "../native/window-state";
5
- import { hoverOverlayForLeaf, sameRect, type DragPreview, type HoverOverlay } from "./index";
5
+ import { sameRect, type DragPreview } from "./index";
6
6
 
7
7
  /** Desktop divider drag: where the panes and dividers under the split are this frame. */
8
8
  export interface LiveDockGeometry {
@@ -27,8 +27,6 @@ export interface LiveDragGeometry {
27
27
  divider: DividerPreviewState | null;
28
28
  /** Desktop divider drag: the panes and dividers it resizes, where the pointer has them. */
29
29
  dock: LiveDockGeometry | null;
30
- /** The tiled pane whose drop grid is under the pointer during a pane move. */
31
- hoverTargetId: string | null;
32
30
  /** Where the release would dock or snap. */
33
31
  dockPreview: DragPreview | null;
34
32
  }
@@ -60,7 +58,6 @@ export const IDLE_DRAG: LiveDragGeometry = {
60
58
  floating: null,
61
59
  divider: null,
62
60
  dock: null,
63
- hoverTargetId: null,
64
61
  dockPreview: null,
65
62
  };
66
63
 
@@ -190,14 +187,3 @@ export function useLiveCatchUp(
190
187
  }, [select, store]);
191
188
  return select ? rect : null;
192
189
  }
193
-
194
- /** The drop grid under the pointer during a pane move. Re-renders only when the pointer enters another pane's grid. */
195
- export function useLiveHoverOverlay(store: LiveDragStore, leaves: DockLeafLayout[]): HoverOverlay | null {
196
- const targetId = useLiveDrag(store, selectHoverTarget);
197
- return useMemo(() => {
198
- const leaf = targetId ? leaves.find((entry) => entry.instanceId === targetId) : undefined;
199
- return leaf ? hoverOverlayForLeaf(leaf) : null;
200
- }, [leaves, targetId]);
201
- }
202
-
203
- const selectHoverTarget = (geometry: LiveDragGeometry) => (geometry.paneDrag ? geometry.hoverTargetId : null);