gloomberb 0.19.3 → 0.19.4

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 (104) hide show
  1. package/package.json +2 -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/desktop-pane-shot-api-policy.ts +10 -2
  12. package/src/cli/desktop-pane-shot.ts +2 -1
  13. package/src/components/command-bar/action-runtime.ts +2 -0
  14. package/src/components/command-bar/commands/direct/runtime.ts +3 -3
  15. package/src/components/command-bar/helpers.ts +2 -0
  16. package/src/components/command-bar/list/model.ts +9 -0
  17. package/src/components/command-bar/pane-actions.ts +46 -35
  18. package/src/components/command-bar/pane-templates/workflow.ts +6 -0
  19. package/src/components/command-bar/panel/index.tsx +30 -3
  20. package/src/components/command-bar/panel/types.ts +7 -0
  21. package/src/components/command-bar/routes/root/results.ts +4 -4
  22. package/src/components/command-bar/routes/root/selection.ts +3 -2
  23. package/src/components/command-bar/routes/ticker-search/actions.ts +21 -16
  24. package/src/components/command-bar/routing/launch-request.ts +3 -2
  25. package/src/components/command-bar/routing/list-state.ts +4 -1
  26. package/src/components/command-bar/surface/index.tsx +15 -1
  27. package/src/components/layout/floating-pane.tsx +10 -0
  28. package/src/components/layout/pane/frame.tsx +6 -0
  29. package/src/components/layout/pane/header.tsx +244 -42
  30. package/src/components/layout/pane/index.tsx +20 -2
  31. package/src/components/layout/shell/active-drag.ts +128 -27
  32. package/src/components/layout/shell/drag/index.ts +99 -96
  33. package/src/components/layout/shell/drag/live.ts +3 -17
  34. package/src/components/layout/shell/drag/magnets.ts +198 -0
  35. package/src/components/layout/shell/drag/overlays.tsx +77 -75
  36. package/src/components/layout/shell/drag/runtime.ts +12 -7
  37. package/src/components/layout/shell/index.tsx +66 -32
  38. package/src/components/layout/shell/native/pointer-runtime.ts +7 -2
  39. package/src/components/layout/shell/native/surfaces.ts +1 -9
  40. package/src/components/layout/shell/native/window-state.ts +21 -25
  41. package/src/components/layout/shell/pane/layers.tsx +153 -24
  42. package/src/components/layout/shell/shortcuts.ts +4 -1
  43. package/src/components/layout/shell/terminal-pointer-runtime.ts +24 -1
  44. package/src/components/layout/shell/window-mode/overlays.tsx +14 -6
  45. package/src/components/layout/status-bar.tsx +75 -6
  46. package/src/core/app-runtime.ts +4 -1
  47. package/src/core/connection-health.ts +76 -1
  48. package/src/core/state/app/command-bar-launch.ts +12 -0
  49. package/src/core/state/app/layout.ts +4 -3
  50. package/src/core/state/app/types.ts +4 -1
  51. package/src/data/config/layout.ts +2 -2
  52. package/src/data/config/store/fold-panes.ts +6 -1
  53. package/src/i18n/es.ts +8 -1
  54. package/src/i18n/ja.ts +8 -1
  55. package/src/i18n/ko.ts +8 -1
  56. package/src/i18n/zh-cn.ts +8 -1
  57. package/src/i18n/zh-tw.ts +8 -1
  58. package/src/layout/pane-follow.ts +3 -2
  59. package/src/layout/pane-layout-move.ts +2 -1
  60. package/src/layout/pane-manager/dock-stack.ts +38 -0
  61. package/src/layout/pane-manager/dock-tree.ts +76 -15
  62. package/src/layout/pane-manager/docking.ts +48 -6
  63. package/src/layout/pane-manager/floating-actions.ts +12 -3
  64. package/src/layout/pane-manager/floating-placement.ts +189 -0
  65. package/src/layout/pane-manager/floating.ts +23 -4
  66. package/src/layout/pane-manager/gridlock.ts +16 -4
  67. package/src/layout/pane-manager/hidden-panes.ts +30 -1
  68. package/src/layout/pane-manager/index.ts +2 -0
  69. package/src/layout/pane-manager/layout-state.ts +17 -0
  70. package/src/layout/pane-manager/types.ts +4 -1
  71. package/src/layout/ticker-retarget.ts +88 -0
  72. package/src/layout-marketplace/cloud.ts +9 -1
  73. package/src/market-data/connection-follow.ts +68 -0
  74. package/src/market-data/coordinator/entries.ts +15 -3
  75. package/src/market-data/coordinator/financials.ts +20 -7
  76. package/src/market-data/coordinator/index.ts +217 -4
  77. package/src/market-data/coordinator/quotes.ts +10 -0
  78. package/src/market-data/hooks.tsx +31 -0
  79. package/src/news/aggregator.ts +12 -1
  80. package/src/plugins/builtin/buildout/company/pane.tsx +2 -1
  81. package/src/plugins/builtin/buildout/model/index.ts +6 -0
  82. package/src/plugins/builtin/buildout/pane/index.tsx +2 -1
  83. package/src/plugins/builtin/chart-composer/index.tsx +13 -0
  84. package/src/plugins/builtin/chat/controller/index.ts +10 -3
  85. package/src/plugins/builtin/chat/controller/session-runtime.ts +9 -2
  86. package/src/plugins/builtin/chat/status-widget.tsx +3 -1
  87. package/src/plugins/builtin/help/index.tsx +1 -1
  88. package/src/plugins/builtin/sectors/client.ts +18 -8
  89. package/src/plugins/builtin/sectors/index.tsx +19 -5
  90. package/src/plugins/builtin/ticker-detail/overview/pane.tsx +4 -1
  91. package/src/plugins/builtin/ticker-detail/overview-tab.tsx +25 -2
  92. package/src/react/async-resource.ts +12 -0
  93. package/src/remote/controller.ts +3 -1
  94. package/src/renderers/browser/app-services.ts +8 -1
  95. package/src/renderers/browser/cloud-transport.ts +6 -1
  96. package/src/renderers/cloudflare/worker.ts +24 -2
  97. package/src/renderers/dom/styles.css +32 -0
  98. package/src/shares/portable-layout.ts +99 -2
  99. package/src/sources/provider-router/index.ts +2 -2
  100. package/src/sources/provider-router/sources.ts +26 -1
  101. package/src/sync/core-contributors.ts +18 -4
  102. package/src/time-series/resolve.ts +12 -0
  103. package/src/types/config.ts +17 -1
  104. package/src/types/plugin.ts +6 -0
@@ -2,8 +2,8 @@ import { Box, useUiCapabilities } from "../../../ui";
2
2
  import type { ReactNode } from "react";
3
3
  import { paneBg } from "../../../theme/colors";
4
4
  import { useThemeColors } from "../../../theme/theme-context";
5
- import { PaneBodyFrame, getPaneWindowAttributes } from "./frame";
6
- import { PaneHeader, type PaneHeaderQuickSetting } from "./header";
5
+ import { PaneBodyFrame, getPaneWindowAttributes, type DockEdge } from "./frame";
6
+ import { PaneHeader, type PaneHeaderQuickSetting, type PaneHeaderStack } from "./header";
7
7
  import { PaneHeaderTabsProvider, usePaneHeaderTabsHost } from "./header-tabs";
8
8
  import { hasPaneFooterContent, PaneFooterBar, type CombinedPaneFooter } from "./footer";
9
9
  import { paneHeaderRows, resolvePaneBodyFrame, shouldReservePaneFooter } from "./sizing";
@@ -11,6 +11,12 @@ import { paneHeaderRows, resolvePaneBodyFrame, shouldReservePaneFooter } from ".
11
11
  interface PaneWrapperProps {
12
12
  paneId?: string;
13
13
  title?: string;
14
+ /**
15
+ * Desktop and web: the ticker the title shows, drawn as a control that opens ticker search for
16
+ * the pane (`onTitleTickerPress`).
17
+ */
18
+ titleTicker?: string | null;
19
+ onTitleTickerPress?: () => void;
14
20
  focused: boolean;
15
21
  windowModeSelected?: boolean;
16
22
  width?: number;
@@ -27,6 +33,10 @@ interface PaneWrapperProps {
27
33
  quickSettings?: PaneHeaderQuickSetting[];
28
34
  /** A dock divider line is drawn over the top row (the pane is below another). */
29
35
  topRule?: boolean;
36
+ /** Desktop: the sides that face another docked pane across the gap between them. */
37
+ dockEdges?: readonly DockEdge[];
38
+ /** Panes stacked as tabs in this spot. */
39
+ stack?: PaneHeaderStack | null;
30
40
  onMouseDown?: (event: any) => void;
31
41
  onMouseDownCapture?: (event: any) => void;
32
42
  onHeaderMouseMove?: (event: any) => void;
@@ -47,6 +57,8 @@ interface PaneWrapperProps {
47
57
  export function PaneWrapper({
48
58
  paneId,
49
59
  title,
60
+ titleTicker = null,
61
+ onTitleTickerPress,
50
62
  focused,
51
63
  windowModeSelected = false,
52
64
  width = 0,
@@ -57,6 +69,8 @@ export function PaneWrapper({
57
69
  showActions = false,
58
70
  quickSettings,
59
71
  topRule = false,
72
+ dockEdges,
73
+ stack,
60
74
  onMouseDown,
61
75
  onMouseDownCapture,
62
76
  onHeaderMouseMove,
@@ -105,6 +119,7 @@ export function PaneWrapper({
105
119
  focused,
106
120
  windowModeSelected,
107
121
  showBorderColor: true,
122
+ dockEdges,
108
123
  })}
109
124
  onMouseDown={onMouseDown}
110
125
  onMouseDownCapture={onMouseDownCapture}
@@ -112,6 +127,8 @@ export function PaneWrapper({
112
127
  {title && (
113
128
  <PaneHeader
114
129
  title={title}
130
+ titleTicker={titleTicker}
131
+ onTitleTickerPress={onTitleTickerPress}
115
132
  width={width}
116
133
  focused={focused}
117
134
  windowModeSelected={windowModeSelected}
@@ -119,6 +136,7 @@ export function PaneWrapper({
119
136
  showActions={showActions}
120
137
  quickSettings={quickSettings}
121
138
  tabs={headerTabs}
139
+ stack={stack}
122
140
  bodyBackground={bg}
123
141
  topRule={topRule}
124
142
  onHeaderMouseMove={onHeaderMouseMove}
@@ -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,38 @@ 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 { NO_LATCH, snapMovedRect, snapResizedRect, type MagnetDistances, type MagnetLatch } from "./drag/magnets";
35
+ import { paneHeaderRows } from "../pane/sizing";
36
+
37
+ /** A join the pointer has lined up: armed once it has held for JOIN_DWELL_MS. */
38
+ interface PendingJoin {
39
+ key: string;
40
+ armed: boolean;
41
+ timer: ReturnType<typeof setTimeout> | null;
42
+ }
43
+
44
+ function dropPendingJoin(memo: { join: PendingJoin | null }) {
45
+ if (memo.join?.timer) clearTimeout(memo.join.timer);
46
+ memo.join = null;
47
+ }
48
+
49
+ /** A resize without edges is the bottom-right corner's (the terminal's only one). */
50
+ const CORNER_EDGES = { x: 1, y: 1 } as const;
32
51
 
33
52
  interface UseShellActiveDragOptions {
34
53
  appHeaderHeight: number;
@@ -38,6 +57,8 @@ interface UseShellActiveDragOptions {
38
57
  dockLeafLayouts: DockLeafLayout[];
39
58
  dragRuntime: ShellDragRuntimeState;
40
59
  focusPane: (paneId: string) => void;
60
+ /** How close a moving or resizing pane's edge comes to another before it sticks, in cells. */
61
+ magnetDistances: MagnetDistances;
41
62
  nativePaneChrome: boolean;
42
63
  paneMap: Map<string, ResolvedPane>;
43
64
  persistLayout: (nextLayout: LayoutConfig, options?: { pushHistory?: boolean }) => void;
@@ -57,6 +78,7 @@ export function useShellActiveDrag({
57
78
  dockLeafLayouts,
58
79
  dragRuntime,
59
80
  focusPane,
81
+ magnetDistances,
60
82
  nativePaneChrome,
61
83
  paneMap,
62
84
  persistLayout,
@@ -72,19 +94,24 @@ export function useShellActiveDrag({
72
94
  dragRef,
73
95
  endDrag,
74
96
  live,
75
- setHoverTarget,
76
97
  updateDividerPreview,
77
98
  updateDockPreview,
78
99
  updateDragFloatingRect,
79
100
  } = 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.
101
+ // What one drag keeps between moves: a docked pane's floating size, the
102
+ // last drop it simulated, so a move over the same target computes nothing,
103
+ // the edges its magnets hold, with the other panes' rects they hold to, and
104
+ // the join it is holding still for.
82
105
  const memoRef = useRef<{
83
106
  drag: unknown;
84
107
  baseRect: FloatingRect | null;
85
108
  dropKey: string | null;
86
109
  drop: DragPreview | null;
87
- }>({ drag: null, baseRect: null, dropKey: null, drop: null });
110
+ latch: MagnetLatch;
111
+ magnetTargets: LayoutBounds[] | null;
112
+ join: PendingJoin | null;
113
+ }>({ drag: null, baseRect: null, dropKey: null, drop: null, latch: NO_LATCH, magnetTargets: null, join: null });
114
+ useEffect(() => () => dropPendingJoin(memoRef.current), []);
88
115
 
89
116
  return useCallback((event: ShellMouseEvent) => {
90
117
  const shellY = event.y - appHeaderHeight;
@@ -106,7 +133,49 @@ export function useShellActiveDrag({
106
133
  memo.baseRect = null;
107
134
  memo.dropKey = null;
108
135
  memo.drop = null;
136
+ memo.latch = NO_LATCH;
137
+ memo.magnetTargets = null;
138
+ dropPendingJoin(memo);
109
139
  }
140
+ // Every other pane on screen, docked or floating, whose edges a floating
141
+ // pane's edges stick to. Alt (Option) lets it go anywhere.
142
+ const magnetTargets = (paneId: string) => {
143
+ memo.magnetTargets ??= [
144
+ ...dockLeafLayouts.filter((leaf) => leaf.instanceId !== paneId).map((leaf) => leaf.rect),
145
+ ...baseLayout.floating
146
+ .filter((entry) => entry.instanceId !== paneId && paneMap.has(entry.instanceId))
147
+ .map(({ x, y, width: w, height: h }) => ({ x, y, width: w, height: h })),
148
+ ];
149
+ return memo.magnetTargets;
150
+ };
151
+ const magnetsOff = event.modifiers?.alt === true;
152
+ const magnetArea = { x: 0, y: 0, width, height: contentHeight };
153
+ const snapMove = (paneId: string, rect: FloatingRect): FloatingRect => {
154
+ if (magnetsOff) {
155
+ memo.latch = NO_LATCH;
156
+ return rect;
157
+ }
158
+ const snapped = snapMovedRect(rect, magnetTargets(paneId), magnetArea, magnetDistances, memo.latch);
159
+ memo.latch = snapped.latch;
160
+ return snapped.rect;
161
+ };
162
+ const snapResize = (paneId: string, rect: FloatingRect, edges: { x: -1 | 0 | 1; y: -1 | 0 | 1 }): FloatingRect => {
163
+ if (magnetsOff) {
164
+ memo.latch = NO_LATCH;
165
+ return rect;
166
+ }
167
+ const snapped = snapResizedRect(
168
+ rect,
169
+ edges,
170
+ { width: MIN_FLOAT_WIDTH, height: MIN_FLOAT_HEIGHT },
171
+ magnetTargets(paneId),
172
+ magnetArea,
173
+ magnetDistances,
174
+ memo.latch,
175
+ );
176
+ memo.latch = snapped.latch;
177
+ return snapped.rect;
178
+ };
110
179
  const dividerRatioAt = (x: number, y: number) => {
111
180
  if (drag.type !== "divider") return 0;
112
181
  const total = drag.axis === "horizontal" ? drag.bounds.width : drag.bounds.height;
@@ -122,6 +191,7 @@ export function useShellActiveDrag({
122
191
 
123
192
  if (event.type === "drag-cancel") {
124
193
  // The window lost focus or the system took the pointer: put everything back.
194
+ dropPendingJoin(memo);
125
195
  cancelActiveDrag();
126
196
  event.stopPropagation();
127
197
  event.preventDefault();
@@ -150,7 +220,6 @@ export function useShellActiveDrag({
150
220
  } else if (drag.type === "pane-drag") {
151
221
  if (!isMeaningfulPaneDrag(drag.startX, drag.startY, preciseX, preciseShellY, dragThreshold)) {
152
222
  updateDockPreview(null);
153
- setHoverTarget(null);
154
223
  if (drag.mode === "floating") {
155
224
  updateDragFloatingRect({ paneId: drag.paneId, rect: drag.origRect });
156
225
  }
@@ -159,33 +228,65 @@ export function useShellActiveDrag({
159
228
  return;
160
229
  }
161
230
 
162
- const nextRect = resolvePaneDragFloatingRect(drag, dragBaseRect()!, drawX, drawShellY, width, contentHeight);
231
+ const nextRect = snapMove(drag.paneId, resolvePaneDragFloatingRect(drag, dragBaseRect()!, drawX, drawShellY, width, contentHeight));
163
232
  updateDragFloatingRect({ paneId: drag.paneId, rect: nextRect });
164
233
 
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}`;
234
+ // Over a title bar it would be a tab there; pushed against a docked
235
+ // pane's edge it would join the dock on that side.
236
+ const target = resolvePaneDropTarget({
237
+ x: hitX,
238
+ y: hitShellY,
239
+ rect: nextRect,
240
+ free: freePaneDragRect(drag, dragBaseRect()!, drawX, drawShellY, width, contentHeight),
241
+ leaves: dockLeafLayouts,
242
+ paneId: drag.paneId,
243
+ area: bounds,
244
+ flush: { x: magnetDistances.catchX, y: magnetDistances.catchY },
245
+ headerRows: paneHeaderRows(nativePaneChrome),
246
+ join: !magnetsOff,
247
+ });
248
+ const showSnapGuide = () => {
249
+ const snapGuide = resolveSnapGuide(hitX, hitShellY, snapGuides);
250
+ updateDockPreview(snapGuide ? { kind: "snap", position: snapGuide.position, rect: snapGuide.previewRect } : null);
251
+ };
252
+ if (target) {
253
+ const dropKey = target.kind === "tab" ? `tab:${target.targetId}` : target.kind === "leaf" ? `${target.targetId}:${target.position}` : target.edge;
254
+ const showDrop = () => {
171
255
  if (memo.dropKey !== dropKey) {
172
- const target: DropTarget = { kind: "leaf", targetId: hoveredOverlay.targetId, position: hoveredCell.position };
173
256
  const simulation = simulateDrop(baseLayout, drag.paneId, target, bounds, dockGeometryOptions);
174
257
  memo.dropKey = dropKey;
175
258
  memo.drop = simulation.previewRect ? { kind: "dock", target, rect: simulation.previewRect } : null;
176
259
  }
177
260
  updateDockPreview(memo.drop);
261
+ };
262
+ if (target.kind === "leaf") {
263
+ // A join arms once the edge has held, and shows its preview then:
264
+ // a release before that leaves the pane floating where it is.
265
+ if (memo.join?.key !== dropKey) {
266
+ dropPendingJoin(memo);
267
+ const join: PendingJoin = { key: dropKey, armed: false, timer: null };
268
+ join.timer = setTimeout(() => {
269
+ if (memo.join !== join || dragRef.current !== drag) return;
270
+ join.armed = true;
271
+ join.timer = null;
272
+ showDrop();
273
+ }, JOIN_DWELL_MS);
274
+ memo.join = join;
275
+ }
276
+ if (memo.join?.armed) showDrop();
277
+ else showSnapGuide();
178
278
  } else {
179
- updateDockPreview(null);
279
+ dropPendingJoin(memo);
280
+ showDrop();
180
281
  }
181
282
  } else {
182
- const snapGuide = resolveSnapGuide(hitX, hitShellY, snapGuides);
183
- updateDockPreview(snapGuide ? { kind: "snap", position: snapGuide.position, rect: snapGuide.previewRect } : null);
283
+ dropPendingJoin(memo);
284
+ showSnapGuide();
184
285
  }
185
286
  } else if (drag.type === "float-resize") {
186
287
  updateDragFloatingRect({
187
288
  paneId: drag.paneId,
188
- rect: resolveFloatResizeRect(drag, preciseX, preciseShellY, width, contentHeight),
289
+ rect: snapResize(drag.paneId, resolveFloatResizeRect(drag, preciseX, preciseShellY, width, contentHeight), drag.edges ?? CORNER_EDGES),
189
290
  });
190
291
  }
191
292
  event.stopPropagation();
@@ -194,6 +295,7 @@ export function useShellActiveDrag({
194
295
  }
195
296
 
196
297
  if (event.type === "up" || event.type === "drag-end") {
298
+ dropPendingJoin(memo);
197
299
  if (drag.type === "divider") {
198
300
  if (live.get().divider) {
199
301
  const nextLayout = resizeSplitAtPath(baseLayout, drag.path, dividerRatioAt(preciseX, preciseShellY));
@@ -208,10 +310,11 @@ export function useShellActiveDrag({
208
310
  const movedEnough = isMeaningfulPaneDrag(drag.startX, drag.startY, preciseX, preciseShellY, dragThreshold);
209
311
  if (!movedEnough) {
210
312
  updateDockPreview(null);
211
- setHoverTarget(null);
212
313
  updateDragFloatingRect(null);
314
+ // A click on a stack's tab shows that pane.
315
+ if (drag.mode === "docked") focusPane(drag.paneId);
213
316
  } else {
214
- const releaseRect = resolvePaneDragFloatingRect(drag, dragBaseRect()!, preciseX, preciseShellY, width, contentHeight);
317
+ const releaseRect = snapMove(drag.paneId, resolvePaneDragFloatingRect(drag, dragBaseRect()!, preciseX, preciseShellY, width, contentHeight));
215
318
  const nextLayout = finalizePaneDragRelease(baseLayout, drag.paneId, releaseRect, live.get().dockPreview);
216
319
  if (windowMode) {
217
320
  updateWindowModePreviewLayout(nextLayout, drag.paneId);
@@ -220,11 +323,10 @@ export function useShellActiveDrag({
220
323
  }
221
324
  focusPane(drag.paneId);
222
325
  updateDockPreview(null);
223
- setHoverTarget(null);
224
326
  updateDragFloatingRect(null);
225
327
  }
226
328
  } else if (drag.type === "float-resize") {
227
- const releaseRect = resolveFloatResizeRect(drag, preciseX, preciseShellY, width, contentHeight);
329
+ const releaseRect = snapResize(drag.paneId, resolveFloatResizeRect(drag, preciseX, preciseShellY, width, contentHeight), drag.edges ?? CORNER_EDGES);
228
330
  const nextLayout = floatAtRect(baseLayout, drag.paneId, releaseRect);
229
331
  if (windowMode) {
230
332
  updateWindowModePreviewLayout(nextLayout, drag.paneId);
@@ -232,7 +334,6 @@ export function useShellActiveDrag({
232
334
  persistLayout(nextLayout);
233
335
  }
234
336
  updateDragFloatingRect(null);
235
- setHoverTarget(null);
236
337
  }
237
338
  endDrag();
238
339
  event.stopPropagation();
@@ -249,11 +350,11 @@ export function useShellActiveDrag({
249
350
  endDrag,
250
351
  focusPane,
251
352
  live,
353
+ magnetDistances,
252
354
  nativePaneChrome,
253
355
  paneMap,
254
356
  persistLayout,
255
357
  precisePointer,
256
- setHoverTarget,
257
358
  snapGuides,
258
359
  updateDividerPreview,
259
360
  updateDockPreview,
@@ -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);