@gloom-sh/terminal 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.
- package/package.json +4 -2
- package/src/api-client/errors.ts +8 -0
- package/src/api-client/index.ts +18 -0
- package/src/api-client/request.ts +295 -42
- package/src/api-client/socket.ts +95 -0
- package/src/app/keybindings/actions.ts +1 -1
- package/src/app/pane-runtime/index.tsx +1 -1
- package/src/app/pane-runtime/ticker-inspector-runtime.ts +1 -1
- package/src/app/pane-runtime/ticker-open-runtime.ts +1 -1
- package/src/app/pane-runtime/ticker-open-target.ts +12 -2
- package/src/cli/commands/command-utils.ts +4 -0
- package/src/cli/commands/market.ts +119 -27
- package/src/cli/commands/search.ts +1 -1
- package/src/cli/commands/ticker.ts +10 -6
- package/src/cli/currency-name-hint.ts +60 -0
- package/src/cli/desktop-pane-shot-api-policy.ts +10 -2
- package/src/cli/desktop-pane-shot.ts +2 -1
- package/src/cli/history-rows.ts +18 -1
- package/src/cli/known-gaps.ts +17 -2
- package/src/cli/not-a-ticker.ts +5 -3
- package/src/cli/pane-functions/catalog.ts +9 -1
- package/src/cli/pane-functions/headless.ts +7 -3
- package/src/cli/pane-functions/market-session.ts +6 -7
- package/src/cli/series-search.ts +4 -5
- package/src/components/chart/composite/panel-bitmap.ts +28 -2
- package/src/components/chart/composite/time-axis.ts +17 -2
- package/src/components/command-bar/action-runtime.ts +2 -0
- package/src/components/command-bar/commands/direct/runtime.ts +3 -3
- package/src/components/command-bar/helpers.ts +2 -0
- package/src/components/command-bar/list/model.ts +9 -0
- package/src/components/command-bar/pane-actions.ts +46 -35
- package/src/components/command-bar/pane-templates/workflow.ts +6 -0
- package/src/components/command-bar/panel/index.tsx +30 -3
- package/src/components/command-bar/panel/types.ts +7 -0
- package/src/components/command-bar/routes/root/results.ts +4 -4
- package/src/components/command-bar/routes/root/selection.ts +3 -2
- package/src/components/command-bar/routes/ticker-search/actions.ts +21 -16
- package/src/components/command-bar/routing/launch-request.ts +3 -2
- package/src/components/command-bar/routing/list-state.ts +4 -1
- package/src/components/command-bar/surface/index.tsx +15 -1
- package/src/components/layout/floating-pane.tsx +10 -0
- package/src/components/layout/pane/frame.tsx +6 -0
- package/src/components/layout/pane/header.tsx +244 -42
- package/src/components/layout/pane/index.tsx +20 -2
- package/src/components/layout/shell/active-drag.ts +160 -28
- package/src/components/layout/shell/drag/index.ts +99 -96
- package/src/components/layout/shell/drag/live.ts +3 -17
- package/src/components/layout/shell/drag/magnets.ts +304 -0
- package/src/components/layout/shell/drag/overlays.tsx +77 -75
- package/src/components/layout/shell/drag/runtime.ts +12 -7
- package/src/components/layout/shell/index.tsx +66 -32
- package/src/components/layout/shell/native/pointer-runtime.ts +7 -2
- package/src/components/layout/shell/native/surfaces.ts +1 -9
- package/src/components/layout/shell/native/window-state.ts +21 -25
- package/src/components/layout/shell/pane/layers.tsx +153 -24
- package/src/components/layout/shell/shortcuts.ts +4 -1
- package/src/components/layout/shell/terminal-pointer-runtime.ts +24 -1
- package/src/components/layout/shell/window-mode/overlays.tsx +14 -6
- package/src/components/layout/status-bar.tsx +75 -6
- package/src/components/layout/window-controls.tsx +96 -35
- package/src/components/layout/window-fullscreen.ts +20 -0
- package/src/components/quote-flash.ts +36 -32
- package/src/core/app-runtime.ts +4 -1
- package/src/core/connection-health.ts +76 -1
- package/src/core/state/app/command-bar-launch.ts +12 -0
- package/src/core/state/app/layout.ts +4 -3
- package/src/core/state/app/types.ts +4 -1
- package/src/data/config/layout.ts +2 -2
- package/src/data/config/store/fold-panes.ts +6 -1
- package/src/i18n/es.ts +8 -1
- package/src/i18n/ja.ts +8 -1
- package/src/i18n/ko.ts +8 -1
- package/src/i18n/zh-cn.ts +8 -1
- package/src/i18n/zh-tw.ts +8 -1
- package/src/layout/pane-follow.ts +3 -2
- package/src/layout/pane-layout-move.ts +2 -1
- package/src/layout/pane-manager/dock-stack.ts +38 -0
- package/src/layout/pane-manager/dock-tree.ts +76 -15
- package/src/layout/pane-manager/docking.ts +48 -6
- package/src/layout/pane-manager/floating-actions.ts +12 -3
- package/src/layout/pane-manager/floating-placement.ts +189 -0
- package/src/layout/pane-manager/floating.ts +23 -4
- package/src/layout/pane-manager/gridlock.ts +16 -4
- package/src/layout/pane-manager/hidden-panes.ts +30 -1
- package/src/layout/pane-manager/index.ts +2 -0
- package/src/layout/pane-manager/layout-state.ts +17 -0
- package/src/layout/pane-manager/types.ts +4 -1
- package/src/layout/ticker-retarget.ts +88 -0
- package/src/layout-marketplace/cloud.ts +9 -1
- package/src/market-data/connection-follow.ts +68 -0
- package/src/market-data/coordinator/entries.ts +15 -3
- package/src/market-data/coordinator/events.ts +17 -1
- package/src/market-data/coordinator/financials.ts +20 -7
- package/src/market-data/coordinator/index.ts +217 -4
- package/src/market-data/coordinator/quotes.ts +10 -0
- package/src/market-data/frame-scheduler.ts +47 -10
- package/src/market-data/frame-wake.ts +74 -0
- package/src/market-data/futures-board.ts +7 -6
- package/src/market-data/hooks.tsx +43 -3
- package/src/market-data/performance.ts +78 -9
- package/src/market-data/request-types.ts +6 -3
- package/src/news/aggregator.ts +12 -1
- package/src/plugins/builtin/alerts/cli.ts +2 -1
- package/src/plugins/builtin/analytics/risk-evidence.ts +1 -0
- package/src/plugins/builtin/attention/evidence.ts +1 -1
- package/src/plugins/builtin/awards/client.ts +1 -1
- package/src/plugins/builtin/awards/evidence.ts +1 -1
- package/src/plugins/builtin/awards/pane.tsx +2 -1
- package/src/plugins/builtin/bond-calculator/math.ts +1 -1
- package/src/plugins/builtin/broker-manager/footer.ts +3 -2
- package/src/plugins/builtin/broker-manager/index.tsx +2 -1
- package/src/plugins/builtin/broker-manager/keyboard.ts +2 -1
- package/src/plugins/builtin/buildout/company/pane.tsx +2 -1
- package/src/plugins/builtin/buildout/model/index.ts +6 -0
- package/src/plugins/builtin/buildout/pane/index.tsx +2 -1
- package/src/plugins/builtin/catalysts/evidence.ts +1 -1
- package/src/plugins/builtin/catalysts/pane.tsx +2 -1
- package/src/plugins/builtin/chart-composer/headless.ts +40 -1
- package/src/plugins/builtin/chart-composer/index.tsx +13 -0
- package/src/plugins/builtin/chat/controller/index.ts +10 -3
- package/src/plugins/builtin/chat/controller/session-runtime.ts +9 -2
- package/src/plugins/builtin/chat/status-widget.tsx +3 -1
- package/src/plugins/builtin/cloud-tweets/table.tsx +3 -2
- package/src/plugins/builtin/comment-letters/client.ts +2 -1
- package/src/plugins/builtin/company-kpis/client.ts +1 -1
- package/src/plugins/builtin/company-kpis/pane.tsx +2 -1
- package/src/plugins/builtin/company-kpis/screenshot-evidence.ts +3 -2
- package/src/plugins/builtin/cot/headless.ts +9 -3
- package/src/plugins/builtin/cot/model.ts +44 -3
- package/src/plugins/builtin/credit-documents/client.ts +1 -1
- package/src/plugins/builtin/credit-documents/evidence.ts +1 -1
- package/src/plugins/builtin/credit-documents/pane.tsx +2 -1
- package/src/plugins/builtin/earnings-calls/pane.tsx +1 -1
- package/src/plugins/builtin/earnings-ripple/index.tsx +6 -1
- package/src/plugins/builtin/econ/calendar-model.ts +2 -0
- package/src/plugins/builtin/econ/fred-catalog.ts +5 -5
- package/src/plugins/builtin/econ/print-watch.ts +3 -1
- package/src/plugins/builtin/futures/series.ts +16 -1
- package/src/plugins/builtin/fx-matrix/headless.ts +4 -2
- package/src/plugins/builtin/fx-matrix/index.tsx +37 -3
- package/src/plugins/builtin/fx-matrix/pairs.ts +15 -0
- package/src/plugins/builtin/gpu/headless.ts +2 -1
- package/src/plugins/builtin/help/function-card.tsx +2 -1
- package/src/plugins/builtin/help/index.tsx +3 -2
- package/src/plugins/builtin/insider/display.ts +45 -6
- package/src/plugins/builtin/ipo-calendar/model.ts +2 -0
- package/src/plugins/builtin/iv-history/client.ts +2 -1
- package/src/plugins/builtin/iv-history/headless.ts +2 -1
- package/src/plugins/builtin/jobs/pages.ts +4 -4
- package/src/plugins/builtin/kelly-sizer/headless.ts +2 -1
- package/src/plugins/builtin/market-heatmap/index.tsx +2 -1
- package/src/plugins/builtin/members/client.ts +1 -1
- package/src/plugins/builtin/mna/distress/client.ts +1 -0
- package/src/plugins/builtin/mna/pane.tsx +4 -1
- package/src/plugins/builtin/options/market-reference.ts +1 -1
- package/src/plugins/builtin/options/open-interest-as-of.ts +3 -1
- package/src/plugins/builtin/options/view.tsx +2 -1
- package/src/plugins/builtin/options-calculator/evidence.ts +1 -1
- package/src/plugins/builtin/options-scenario/csp-screen-pane.tsx +1 -1
- package/src/plugins/builtin/options-scenario/csp-screen.ts +8 -4
- package/src/plugins/builtin/options-scenario/csp.ts +28 -9
- package/src/plugins/builtin/options-scenario/evidence.ts +5 -4
- package/src/plugins/builtin/options-scenario/pane.tsx +2 -1
- package/src/plugins/builtin/perps/client.ts +1 -1
- package/src/plugins/builtin/portfolio-list/cli/watchlist-command.ts +2 -1
- package/src/plugins/builtin/portfolio-list/pane/index.tsx +7 -3
- package/src/plugins/builtin/portfolio-list/use-throttled-memo.ts +10 -19
- package/src/plugins/builtin/research/analyst-model.ts +1 -0
- package/src/plugins/builtin/research/equity-diagnostic-pane.tsx +2 -1
- package/src/plugins/builtin/research/index.tsx +1 -0
- package/src/plugins/builtin/research/relative-valuation-currency.ts +1 -1
- package/src/plugins/builtin/research/relative-valuation-peers.ts +2 -1
- package/src/plugins/builtin/research-search/command-bar-search.ts +3 -1
- package/src/plugins/builtin/research-search/snippet.ts +1 -0
- package/src/plugins/builtin/revenue-breakdown/client.ts +3 -2
- package/src/plugins/builtin/seasonality/headless.ts +2 -1
- package/src/plugins/builtin/sec/command-bar-search.ts +3 -2
- package/src/plugins/builtin/sec/index.tsx +7 -4
- package/src/plugins/builtin/sec/row-summaries.ts +28 -12
- package/src/plugins/builtin/sectors/client.ts +18 -8
- package/src/plugins/builtin/sectors/index.tsx +19 -5
- package/src/plugins/builtin/short-interest/watch-client.ts +2 -1
- package/src/plugins/builtin/social-mentions/client.ts +2 -1
- package/src/plugins/builtin/supply-chain/client.ts +1 -1
- package/src/plugins/builtin/supply-chain/evidence.ts +1 -1
- package/src/plugins/builtin/supply-chain/graph-pane.tsx +2 -1
- package/src/plugins/builtin/supply-chain/pane.tsx +2 -1
- package/src/plugins/builtin/ticker-detail/adr-pair/headless.ts +1 -1
- package/src/plugins/builtin/ticker-detail/adr-pair/model.ts +24 -4
- package/src/plugins/builtin/ticker-detail/adr-pair/tab.tsx +1 -1
- package/src/plugins/builtin/ticker-detail/overview/pane.tsx +4 -1
- package/src/plugins/builtin/ticker-detail/overview-tab.tsx +25 -2
- package/src/plugins/builtin/time-sales/client.ts +1 -0
- package/src/plugins/builtin/vol-surface/client.ts +2 -1
- package/src/plugins/builtin/yield-curve/headless.ts +3 -1
- package/src/portfolio/column-values.ts +76 -10
- package/src/react/async-resource.ts +12 -0
- package/src/remote/controller.ts +3 -1
- package/src/renderers/browser/app-services.ts +8 -1
- package/src/renderers/browser/cloud-transport.ts +6 -1
- package/src/renderers/cloudflare/worker.ts +24 -2
- package/src/renderers/dom/host/box.tsx +204 -176
- package/src/renderers/dom/host/style.ts +49 -20
- package/src/renderers/dom/host/text.tsx +3 -2
- package/src/renderers/dom/styles.css +32 -0
- package/src/renderers/electrobun/bun/desktop/backend.ts +2 -0
- package/src/renderers/electrobun/bun/desktop/host-requests.ts +25 -1
- package/src/renderers/electrobun/bun/desktop/relaunch.ts +9 -1
- package/src/renderers/electrobun/bun/desktop/windows-script.ts +9 -6
- package/src/renderers/electrobun/bun/window/windows-native.ts +26 -1
- package/src/renderers/electrobun/shared/protocol.ts +6 -0
- package/src/renderers/electrobun/view/ui-host.tsx +7 -0
- package/src/renderers/electrobun/view/window-fullscreen.ts +10 -3
- package/src/shares/portable-layout.ts +99 -2
- package/src/sources/provider-router/index.ts +9 -3
- package/src/sources/provider-router/sources.ts +26 -1
- package/src/sync/core-contributors.ts +18 -4
- package/src/time-series/price-units.ts +11 -0
- package/src/time-series/resolve.ts +12 -0
- package/src/types/config.ts +17 -1
- package/src/types/plugin.ts +6 -0
- package/src/ui/host.tsx +2 -0
- package/src/utils/currency-names.ts +20 -0
- package/src/utils/currency-pair.ts +6 -0
- package/src/utils/exchange-rate-snapshot.ts +20 -2
- package/src/utils/fx-market-hours.ts +43 -0
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import type { LayoutConfig } from "../../types/config";
|
|
2
|
+
import { getDockLeafLayouts, type LayoutBounds } from "./dock-tree";
|
|
3
|
+
import { clampFloatingRect, MIN_FLOAT_HEIGHT, MIN_FLOAT_WIDTH, type FloatingRect } from "./floating";
|
|
4
|
+
|
|
5
|
+
/** What a new floating pane keeps clear of beyond the other floating panes. */
|
|
6
|
+
export interface FloatingPlacementOptions {
|
|
7
|
+
/** The pane being worked in: a new window never covers all of it. */
|
|
8
|
+
focusedPaneId?: string | null;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** How far each window of a cascade sits from the one before it, in cells: past its header and its left edge. */
|
|
12
|
+
const CASCADE_STEP = { x: 2, y: 1 };
|
|
13
|
+
/** A free spot has to hold at least this share of the window's size on each axis to be worth shrinking into. */
|
|
14
|
+
const MIN_FREE_SHARE = 0.5;
|
|
15
|
+
/** Past this many windows to keep clear of, the free spots are slivers: cascade instead of searching them. */
|
|
16
|
+
const MAX_FREE_SEARCH_OBSTACLES = 12;
|
|
17
|
+
|
|
18
|
+
function overlaps(a: LayoutBounds, b: LayoutBounds): boolean {
|
|
19
|
+
return a.x < b.x + b.width && b.x < a.x + a.width && a.y < b.y + b.height && b.y < a.y + a.height;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function contains(outer: LayoutBounds, inner: LayoutBounds): boolean {
|
|
23
|
+
return outer.x <= inner.x
|
|
24
|
+
&& outer.y <= inner.y
|
|
25
|
+
&& outer.x + outer.width >= inner.x + inner.width
|
|
26
|
+
&& outer.y + outer.height >= inner.y + inner.height;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Every rectangle of `area` that touches none of `obstacles` and runs between
|
|
31
|
+
* the lines their edges and the area's draw. Every largest empty rectangle
|
|
32
|
+
* lies on those lines, so the largest are among them; fine for the few
|
|
33
|
+
* windows a layout floats.
|
|
34
|
+
*/
|
|
35
|
+
function forEachFreeRect(area: LayoutBounds, obstacles: readonly LayoutBounds[], visit: (rect: LayoutBounds) => void): void {
|
|
36
|
+
const clip = (value: number, start: number, length: number) => Math.max(start, Math.min(start + length, value));
|
|
37
|
+
const xs = [...new Set([area.x, area.x + area.width, ...obstacles.flatMap((rect) => [rect.x, rect.x + rect.width].map((x) => clip(x, area.x, area.width)))])].sort((a, b) => a - b);
|
|
38
|
+
const ys = [...new Set([area.y, area.y + area.height, ...obstacles.flatMap((rect) => [rect.y, rect.y + rect.height].map((y) => clip(y, area.y, area.height)))])].sort((a, b) => a - b);
|
|
39
|
+
for (let left = 0; left < xs.length; left += 1) {
|
|
40
|
+
for (let right = left + 1; right < xs.length; right += 1) {
|
|
41
|
+
for (let top = 0; top < ys.length; top += 1) {
|
|
42
|
+
for (let bottom = top + 1; bottom < ys.length; bottom += 1) {
|
|
43
|
+
const rect = { x: xs[left]!, y: ys[top]!, width: xs[right]! - xs[left]!, height: ys[bottom]! - ys[top]! };
|
|
44
|
+
// Taller ones from this corner only overlap more.
|
|
45
|
+
if (obstacles.some((obstacle) => overlaps(rect, obstacle))) break;
|
|
46
|
+
visit(rect);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Where a pane sits on screen: its floating rect, or its docked one laid out over `area`. */
|
|
54
|
+
function screenRect(layout: LayoutConfig, instanceId: string, area: LayoutBounds): LayoutBounds | null {
|
|
55
|
+
const floating = layout.floating.find((entry) => entry.instanceId === instanceId);
|
|
56
|
+
if (floating) return floating;
|
|
57
|
+
return getDockLeafLayouts(layout, area).find((leaf) => leaf.instanceId === instanceId)?.rect ?? null;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* The rect a new floating window of `size` opens at in a `termWidth` by
|
|
62
|
+
* `termHeight` area: in the largest spot clear of the other floating windows
|
|
63
|
+
* and of the focused pane, shrunk to it when it is a little small, and centred
|
|
64
|
+
* in it; otherwise one step down and right of the frontmost window, a cascade.
|
|
65
|
+
* It never lands exactly on another window, and never covers all of the
|
|
66
|
+
* focused pane when there is any other way.
|
|
67
|
+
*/
|
|
68
|
+
export function placeFloatingRect(
|
|
69
|
+
layout: LayoutConfig,
|
|
70
|
+
instanceId: string,
|
|
71
|
+
size: { width: number; height: number },
|
|
72
|
+
termWidth: number,
|
|
73
|
+
termHeight: number,
|
|
74
|
+
options: FloatingPlacementOptions = {},
|
|
75
|
+
): FloatingRect {
|
|
76
|
+
const area = { x: 0, y: 0, width: Math.max(1, termWidth), height: Math.max(1, termHeight) };
|
|
77
|
+
const others = layout.floating.filter((entry) => entry.instanceId !== instanceId);
|
|
78
|
+
const focusedId = options.focusedPaneId && options.focusedPaneId !== instanceId ? options.focusedPaneId : null;
|
|
79
|
+
const focused = focusedId ? screenRect(layout, focusedId, area) : null;
|
|
80
|
+
const obstacles: LayoutBounds[] = [...others];
|
|
81
|
+
if (focused && !others.some((entry) => entry.instanceId === focusedId)) obstacles.push(focused);
|
|
82
|
+
const width = Math.min(size.width, area.width);
|
|
83
|
+
const height = Math.min(size.height, area.height);
|
|
84
|
+
|
|
85
|
+
if (obstacles.length <= MAX_FREE_SEARCH_OBSTACLES) {
|
|
86
|
+
const spot = bestFreeSpot(area, obstacles, width, height);
|
|
87
|
+
if (spot) return clampFloatingRect(spot, termWidth, termHeight);
|
|
88
|
+
}
|
|
89
|
+
return cascadeRect(area, others, focused, width, height, termWidth, termHeight);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** The free rect that holds the most of a `width` by `height` window, with the window centred in it; null when none holds enough. */
|
|
93
|
+
function bestFreeSpot(area: LayoutBounds, obstacles: readonly LayoutBounds[], width: number, height: number): FloatingRect | null {
|
|
94
|
+
const minWidth = Math.max(Math.min(MIN_FLOAT_WIDTH, width), Math.ceil(width * MIN_FREE_SHARE));
|
|
95
|
+
const minHeight = Math.max(Math.min(MIN_FLOAT_HEIGHT, height), Math.ceil(height * MIN_FREE_SHARE));
|
|
96
|
+
const found: { best: { rect: LayoutBounds; fit: number } | null } = { best: null };
|
|
97
|
+
forEachFreeRect(area, obstacles, (rect) => {
|
|
98
|
+
const fitWidth = Math.min(width, rect.width);
|
|
99
|
+
const fitHeight = Math.min(height, rect.height);
|
|
100
|
+
if (fitWidth < minWidth || fitHeight < minHeight) return;
|
|
101
|
+
const fit = fitWidth * fitHeight;
|
|
102
|
+
const best = found.best;
|
|
103
|
+
const room = rect.width * rect.height;
|
|
104
|
+
const bestRoom = best ? best.rect.width * best.rect.height : 0;
|
|
105
|
+
// Ties go to the roomier spot, then to the right and to the top, where a new window reads as new.
|
|
106
|
+
if (!best || fit > best.fit
|
|
107
|
+
|| (fit === best.fit && (room > bestRoom
|
|
108
|
+
|| (room === bestRoom && (rect.x > best.rect.x || (rect.x === best.rect.x && rect.y < best.rect.y)))))) {
|
|
109
|
+
found.best = { rect, fit };
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
const best = found.best;
|
|
113
|
+
if (!best) return null;
|
|
114
|
+
const fitWidth = Math.min(width, best.rect.width);
|
|
115
|
+
const fitHeight = Math.min(height, best.rect.height);
|
|
116
|
+
return {
|
|
117
|
+
x: Math.floor(best.rect.x + (best.rect.width - fitWidth) / 2),
|
|
118
|
+
y: Math.floor(best.rect.y + (best.rect.height - fitHeight) / 2),
|
|
119
|
+
width: Math.floor(fitWidth),
|
|
120
|
+
height: Math.floor(fitHeight),
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* One step down and right of the frontmost window (or centred, with no
|
|
126
|
+
* window to follow), wrapping to the top left when it runs off the area, and
|
|
127
|
+
* stepping on while it would sit exactly on another window or cover all of
|
|
128
|
+
* the focused pane.
|
|
129
|
+
*/
|
|
130
|
+
function cascadeRect(
|
|
131
|
+
area: LayoutBounds,
|
|
132
|
+
others: readonly { x: number; y: number; width: number; height: number; zIndex?: number }[],
|
|
133
|
+
focused: LayoutBounds | null,
|
|
134
|
+
width: number,
|
|
135
|
+
height: number,
|
|
136
|
+
termWidth: number,
|
|
137
|
+
termHeight: number,
|
|
138
|
+
): FloatingRect {
|
|
139
|
+
const front = others.reduce<(typeof others)[number] | null>(
|
|
140
|
+
(top, entry) => (!top || (entry.zIndex ?? 0) >= (top.zIndex ?? 0) ? entry : top),
|
|
141
|
+
null,
|
|
142
|
+
);
|
|
143
|
+
const maxX = Math.max(0, area.width - width);
|
|
144
|
+
const maxY = Math.max(0, area.height - height);
|
|
145
|
+
let x = front ? front.x + CASCADE_STEP.x : Math.floor(maxX / 2);
|
|
146
|
+
let y = front ? front.y + CASCADE_STEP.y : Math.floor(maxY / 2);
|
|
147
|
+
const taken = (left: number, top: number) => others.some((entry) => Math.round(entry.x) === left && Math.round(entry.y) === top);
|
|
148
|
+
const coversFocus = (left: number, top: number) => !!focused && contains({ x: left, y: top, width, height }, focused);
|
|
149
|
+
const attempts = Math.max(1, Math.ceil(Math.max(maxX / CASCADE_STEP.x, maxY / CASCADE_STEP.y)) + others.length + 1);
|
|
150
|
+
let fallback: { x: number; y: number } | null = null;
|
|
151
|
+
for (let attempt = 0; attempt < attempts; attempt += 1) {
|
|
152
|
+
if (x > maxX || y > maxY) {
|
|
153
|
+
// Off the edge: start a new run from the top left, a step in.
|
|
154
|
+
x = Math.min(maxX, CASCADE_STEP.x * (attempt % 4));
|
|
155
|
+
y = 0;
|
|
156
|
+
}
|
|
157
|
+
x = Math.round(x);
|
|
158
|
+
y = Math.round(y);
|
|
159
|
+
if (!taken(x, y)) {
|
|
160
|
+
if (!coversFocus(x, y)) return clampFloatingRect({ x, y, width, height }, termWidth, termHeight);
|
|
161
|
+
fallback ??= { x, y };
|
|
162
|
+
}
|
|
163
|
+
x += CASCADE_STEP.x;
|
|
164
|
+
y += CASCADE_STEP.y;
|
|
165
|
+
}
|
|
166
|
+
const at = fallback ?? { x: Math.min(maxX, x), y: Math.min(maxY, y) };
|
|
167
|
+
return clampFloatingRect({ ...at, width, height }, termWidth, termHeight);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* A remembered or chosen rect moved off any window it would sit exactly on:
|
|
172
|
+
* stepped down and right until it lands on no other window's corner.
|
|
173
|
+
*/
|
|
174
|
+
export function avoidStackedRect(layout: LayoutConfig, instanceId: string, rect: FloatingRect, termWidth: number, termHeight: number): FloatingRect {
|
|
175
|
+
const others = layout.floating.filter((entry) => entry.instanceId !== instanceId);
|
|
176
|
+
let next = rect;
|
|
177
|
+
for (let attempt = 0; attempt < others.length + 1; attempt += 1) {
|
|
178
|
+
const stacked = others.some((entry) => Math.round(entry.x) === Math.round(next.x) && Math.round(entry.y) === Math.round(next.y));
|
|
179
|
+
if (!stacked) return next;
|
|
180
|
+
const moved = clampFloatingRect({ ...next, x: next.x + CASCADE_STEP.x, y: next.y + CASCADE_STEP.y }, termWidth, termHeight);
|
|
181
|
+
if (moved.x === next.x && moved.y === next.y) {
|
|
182
|
+
// Against the far corner: start again from the top left.
|
|
183
|
+
next = clampFloatingRect({ ...next, x: 0, y: 0 }, termWidth, termHeight);
|
|
184
|
+
} else {
|
|
185
|
+
next = moved;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return next;
|
|
189
|
+
}
|
|
@@ -53,9 +53,19 @@ export function clampFloatingRectWithinBounds(rect: FloatingRect, bounds: Layout
|
|
|
53
53
|
};
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
/** A new floating pane's size: its own default, or 60% of the area each way. */
|
|
57
|
+
export function defaultFloatingSize(termWidth: number, termHeight: number, def?: PaneDef): { width: number; height: number } {
|
|
58
|
+
const { width, height } = clampFloatingRect({
|
|
59
|
+
x: 0,
|
|
60
|
+
y: 0,
|
|
61
|
+
width: def?.defaultFloatingSize?.width ?? Math.floor(termWidth * 0.6),
|
|
62
|
+
height: def?.defaultFloatingSize?.height ?? Math.floor(termHeight * 0.6),
|
|
63
|
+
}, termWidth, termHeight);
|
|
64
|
+
return { width, height };
|
|
65
|
+
}
|
|
66
|
+
|
|
56
67
|
export function defaultFloatingRect(termWidth: number, termHeight: number, def?: PaneDef): FloatingRect {
|
|
57
|
-
const width =
|
|
58
|
-
const height = def?.defaultFloatingSize?.height ?? Math.floor(termHeight * 0.6);
|
|
68
|
+
const { width, height } = defaultFloatingSize(termWidth, termHeight, def);
|
|
59
69
|
return clampFloatingRect({
|
|
60
70
|
x: Math.floor((termWidth - width) / 2),
|
|
61
71
|
y: Math.floor((termHeight - height) / 2),
|
|
@@ -71,8 +81,17 @@ export function maxFloatingZ(layout: LayoutConfig): number {
|
|
|
71
81
|
/** Where floating panes stack from, above the docked panes and the dividers between them. */
|
|
72
82
|
const FLOATING_PANE_BASE_Z = 50;
|
|
73
83
|
|
|
74
|
-
/**
|
|
75
|
-
|
|
84
|
+
/**
|
|
85
|
+
* The shell's fixed overlays of a pane move, over every pane. A move draws a
|
|
86
|
+
* pair at `under` and `over`: on the desktop the landing preview under the
|
|
87
|
+
* pane on the move (lifted to `over` while it is over a target, or its outline
|
|
88
|
+
* when it was docked); in the terminal, which cannot see through a pane, the
|
|
89
|
+
* docked pane's outline under the landing outline.
|
|
90
|
+
*/
|
|
91
|
+
export const SHELL_DRAG_Z = { under: 95, over: 96 } as const;
|
|
92
|
+
|
|
93
|
+
/** The lowest of the shell's fixed overlays over every pane. */
|
|
94
|
+
const SHELL_PREVIEW_Z = SHELL_DRAG_Z.under;
|
|
76
95
|
|
|
77
96
|
/**
|
|
78
97
|
* How far above its own z a floating pane draws: its resize edges one level
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { FloatingPaneEntry, LayoutConfig } from "../../types/config";
|
|
1
|
+
import type { DockLayoutNode, FloatingPaneEntry, LayoutConfig } from "../../types/config";
|
|
2
|
+
import { buildDockStack } from "./dock-stack";
|
|
2
3
|
import type { AppNotificationRequest } from "../../types/plugin";
|
|
3
4
|
import {
|
|
4
5
|
boundsForRects,
|
|
@@ -91,6 +92,15 @@ export function shouldShowTidyWindows(layout: LayoutConfig): boolean {
|
|
|
91
92
|
|| analyzeFloatingPaneVisibility(layout).some((pane) => pane.buried);
|
|
92
93
|
}
|
|
93
94
|
|
|
95
|
+
function withStacks(node: DockLayoutNode | null, stacks: ReadonlyMap<string, readonly string[]>): DockLayoutNode | null {
|
|
96
|
+
if (!node || stacks.size === 0) return node;
|
|
97
|
+
if (node.kind === "pane") {
|
|
98
|
+
const tabs = stacks.get(node.instanceId);
|
|
99
|
+
return tabs ? buildDockStack(tabs, node.instanceId) : node;
|
|
100
|
+
}
|
|
101
|
+
return { ...node, first: withStacks(node.first, stacks)!, second: withStacks(node.second, stacks)! };
|
|
102
|
+
}
|
|
103
|
+
|
|
94
104
|
export function gridlockAllPanes(
|
|
95
105
|
layout: LayoutConfig,
|
|
96
106
|
bounds: LayoutBounds = { x: 0, y: 0, width: 120, height: 40 },
|
|
@@ -99,8 +109,10 @@ export function gridlockAllPanes(
|
|
|
99
109
|
const visibleLayout = paneTypes
|
|
100
110
|
? removeUnavailablePaneTypes(layout, paneTypes)
|
|
101
111
|
: layout;
|
|
102
|
-
const
|
|
103
|
-
|
|
112
|
+
const leaves = getDockLeafLayouts(visibleLayout, bounds);
|
|
113
|
+
const dockedRects: GridlockRect[] = leaves.map((leaf) => ({ instanceId: leaf.instanceId, ...leaf.rect }));
|
|
114
|
+
// A stack is tiled as the tab it shows and keeps its other tabs.
|
|
115
|
+
const stacks = new Map(leaves.flatMap((leaf) => (leaf.stack ? [[leaf.instanceId, leaf.stack] as const] : [])));
|
|
104
116
|
const floatingRects: GridlockRect[] = visibleLayout.floating.map((entry) => ({
|
|
105
117
|
instanceId: entry.instanceId,
|
|
106
118
|
x: entry.x,
|
|
@@ -113,7 +125,7 @@ export function gridlockAllPanes(
|
|
|
113
125
|
|
|
114
126
|
return finalizeLayout({
|
|
115
127
|
...visibleLayout,
|
|
116
|
-
dockRoot: inferDockTreeFromRects(allRects, boundsForRects(allRects)),
|
|
128
|
+
dockRoot: withStacks(inferDockTreeFromRects(allRects, boundsForRects(allRects)), stacks),
|
|
117
129
|
floating: [],
|
|
118
130
|
});
|
|
119
131
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { DockLayoutNode, DockSplitNode, LayoutConfig, PaneInstanceConfig } from "../../types/config";
|
|
2
|
-
import {
|
|
2
|
+
import { buildDockStack, isDockStack } from "./dock-stack";
|
|
3
|
+
import { collectDockLeafRefs, dockStackShown, getDockedInstanceIds, getNodeAtPath, replaceNodeAtPath } from "./dock-tree";
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* A hidden part of the saved dock tree: the largest subtree with no pane on
|
|
@@ -14,6 +15,8 @@ interface HiddenDockBranch {
|
|
|
14
15
|
/** The shown panes on the other side of that split. */
|
|
15
16
|
besideIds: ReadonlySet<string>;
|
|
16
17
|
depth: number;
|
|
18
|
+
/** Tabs of a stack: they go back into the stack of `besideIds`, its other tabs. */
|
|
19
|
+
tabs?: boolean;
|
|
17
20
|
}
|
|
18
21
|
|
|
19
22
|
function isAllHidden(node: DockLayoutNode, hidden: ReadonlySet<string>): boolean {
|
|
@@ -27,6 +30,24 @@ function collectHiddenBranches(
|
|
|
27
30
|
out: HiddenDockBranch[],
|
|
28
31
|
): void {
|
|
29
32
|
if (node.kind !== "split") return;
|
|
33
|
+
if (isDockStack(node)) {
|
|
34
|
+
// A stack is one spot: its hidden tabs go back into it, not beside it.
|
|
35
|
+
const members = getDockedInstanceIds(node);
|
|
36
|
+
const shown = members.filter((instanceId) => !hidden.has(instanceId));
|
|
37
|
+
const tabs = members.filter((instanceId) => hidden.has(instanceId));
|
|
38
|
+
if (tabs.length > 0 && shown.length > 0) {
|
|
39
|
+
out.push({
|
|
40
|
+
node: buildDockStack(tabs)!,
|
|
41
|
+
axis: node.axis,
|
|
42
|
+
ratio: node.ratio,
|
|
43
|
+
side: 1,
|
|
44
|
+
besideIds: new Set(shown),
|
|
45
|
+
depth,
|
|
46
|
+
tabs: true,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
30
51
|
const children = [node.first, node.second] as const;
|
|
31
52
|
children.forEach((child, index) => {
|
|
32
53
|
const side = index as 0 | 1;
|
|
@@ -70,6 +91,14 @@ function reattachBranch(
|
|
|
70
91
|
): DockLayoutNode {
|
|
71
92
|
if (!root) return branch.node;
|
|
72
93
|
const beside = collectDockLeafRefs(root).filter((leaf) => branch.besideIds.has(leaf.instanceId));
|
|
94
|
+
if (branch.tabs && beside[0]) {
|
|
95
|
+
const spotPath = beside[0].stackPath ?? beside[0].path;
|
|
96
|
+
const spot = getNodeAtPath(root, spotPath);
|
|
97
|
+
if (spot) {
|
|
98
|
+
const stack = buildDockStack([...getDockedInstanceIds(spot), ...getDockedInstanceIds(branch.node)], dockStackShown(spot));
|
|
99
|
+
return replaceNodeAtPath(root, spotPath, stack!);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
73
102
|
let path = beside.length > 0 ? commonPathPrefix(beside.map((leaf) => leaf.path)) : [];
|
|
74
103
|
while (path.length > 0) {
|
|
75
104
|
const parent = getNodeAtPath(root, path.slice(0, -1));
|
|
@@ -3,6 +3,7 @@ export {
|
|
|
3
3
|
FLOATING_PANE_MAX_Z,
|
|
4
4
|
MIN_FLOAT_HEIGHT,
|
|
5
5
|
MIN_FLOAT_WIDTH,
|
|
6
|
+
SHELL_DRAG_Z,
|
|
6
7
|
type FloatingRect,
|
|
7
8
|
} from "./floating";
|
|
8
9
|
|
|
@@ -13,6 +14,7 @@ export {
|
|
|
13
14
|
getDockLeafLayouts,
|
|
14
15
|
getDockResizeTargets,
|
|
15
16
|
getDockSplitGeometry,
|
|
17
|
+
showDockTab,
|
|
16
18
|
type DockDividerLayout,
|
|
17
19
|
type DockGeometryOptions,
|
|
18
20
|
type DockLeafLayout,
|
|
@@ -51,11 +51,28 @@ function normalizeDetachedEntries(layout: LayoutConfig) {
|
|
|
51
51
|
.map((entry) => ({ ...entry }));
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
+
/** A tab's way back into its stack: beside the tab it shows, or the first other one. */
|
|
55
|
+
export function stackTabMemory(
|
|
56
|
+
dockRoot: DockLayoutNode | null,
|
|
57
|
+
stackPath: Array<0 | 1>,
|
|
58
|
+
instanceId: string,
|
|
59
|
+
): Pick<DockedPlacementMemory, "anchorInstanceId" | "position"> {
|
|
60
|
+
const stack = getNodeAtPath(dockRoot, stackPath);
|
|
61
|
+
const members = stack ? getDockedInstanceIds(stack) : [];
|
|
62
|
+
const shown = stack ? getRepresentativeLeafId(stack, true) : undefined;
|
|
63
|
+
const anchorInstanceId = shown && shown !== instanceId ? shown : members.find((id) => id !== instanceId);
|
|
64
|
+
return { anchorInstanceId, position: "tab" };
|
|
65
|
+
}
|
|
66
|
+
|
|
54
67
|
function captureDockedMemory(dockRoot: DockLayoutNode | null): Map<string, DockedPlacementMemory> {
|
|
55
68
|
const memory = new Map<string, DockedPlacementMemory>();
|
|
56
69
|
const leaves = collectDockLeafRefs(dockRoot);
|
|
57
70
|
|
|
58
71
|
for (const leaf of leaves) {
|
|
72
|
+
if (leaf.stackPath) {
|
|
73
|
+
memory.set(leaf.instanceId, { path: [...leaf.path], ...stackTabMemory(dockRoot, leaf.stackPath, leaf.instanceId) });
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
59
76
|
if (leaf.path.length === 0) {
|
|
60
77
|
memory.set(leaf.instanceId, { path: [] });
|
|
61
78
|
continue;
|
|
@@ -14,7 +14,10 @@ export type LeafDropPosition =
|
|
|
14
14
|
|
|
15
15
|
export type DropTarget =
|
|
16
16
|
| { kind: "frame"; edge: "left" | "right" | "top" | "bottom" }
|
|
17
|
-
|
|
17
|
+
/** Beside the spot `targetId` is in; "center" stacks onto it like `tab`. */
|
|
18
|
+
| { kind: "leaf"; targetId: string; position: LeafDropPosition }
|
|
19
|
+
/** A tab of the spot `targetId` is in, shown. */
|
|
20
|
+
| { kind: "tab"; targetId: string };
|
|
18
21
|
|
|
19
22
|
export type FloatingResizeCorner = "top-left" | "top-right" | "bottom-left" | "bottom-right";
|
|
20
23
|
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import {
|
|
2
|
+
findPaneInstance,
|
|
3
|
+
TICKER_RESEARCH_PANE_ID,
|
|
4
|
+
type LayoutConfig,
|
|
5
|
+
type PaneBinding,
|
|
6
|
+
type PaneInstanceConfig,
|
|
7
|
+
} from "../types/config";
|
|
8
|
+
import type { BrokerContractRef, TickerListingRef } from "../types/instrument";
|
|
9
|
+
import type { PaneDef } from "../types/plugin";
|
|
10
|
+
import { tickerInstrumentLabel } from "../tickers/instrument-label";
|
|
11
|
+
import { pinnedTitle } from "./pane-follow";
|
|
12
|
+
import { isPaneInLayout } from "./pane-manager";
|
|
13
|
+
import { isTickerLinkPeer } from "./ticker-navigation";
|
|
14
|
+
|
|
15
|
+
/*
|
|
16
|
+
* Ticker search (the backtick, or a click on the ticker in a pane's header) changes what the
|
|
17
|
+
* focused pane shows rather than opening another pane, whenever that pane shows one ticker:
|
|
18
|
+
* Ticker Research, or a pane flagged `tickerFollower` (OMON, G of one security, FA).
|
|
19
|
+
*
|
|
20
|
+
* - A pane on a fixed ticker changes to the new one, and every pane linked to it moves along.
|
|
21
|
+
* - A linked pane changes its source instead, up the chain of single-ticker panes it follows, so
|
|
22
|
+
* the linked group moves together: OPX on the Options desk changes OMON, and OPX, OVDV and HIVG
|
|
23
|
+
* follow it.
|
|
24
|
+
* - A group whose top pane follows a watchlist, portfolio or scanner is pinned on the new ticker
|
|
25
|
+
* and leaves the list. A search never edits the user's list or moves its cursor, and the list
|
|
26
|
+
* may not hold the ticker at all; the pane menu's "Link to" puts the group back on the list.
|
|
27
|
+
*
|
|
28
|
+
* A pane that shows no ticker (a list, a market board, a comparison chart, INS without one) has
|
|
29
|
+
* no target here, and its search opens a ticker pane as it always has. Shift+Enter opens a new
|
|
30
|
+
* pane from any pane.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
/** The pane whose ticker search changes when `paneId` has the focus, or null to open a pane instead. */
|
|
34
|
+
export function resolveTickerRetargetPane(
|
|
35
|
+
layout: LayoutConfig,
|
|
36
|
+
paneId: string | null | undefined,
|
|
37
|
+
panes: ReadonlyMap<string, PaneDef>,
|
|
38
|
+
): PaneInstanceConfig | null {
|
|
39
|
+
const focused = paneId ? findPaneInstance(layout, paneId) : undefined;
|
|
40
|
+
if (!focused || !isPaneInLayout(layout, focused.instanceId) || !isTickerLinkPeer(focused, panes)) return null;
|
|
41
|
+
let root = focused;
|
|
42
|
+
const seen = new Set([root.instanceId]);
|
|
43
|
+
while (root.binding?.kind === "follow") {
|
|
44
|
+
const source = findPaneInstance(layout, root.binding.sourceInstanceId);
|
|
45
|
+
if (!source || seen.has(source.instanceId) || !isTickerLinkPeer(source, panes)) break;
|
|
46
|
+
seen.add(source.instanceId);
|
|
47
|
+
root = source;
|
|
48
|
+
}
|
|
49
|
+
// Unbound, a pane other than Ticker Research shows no ticker (INS alone is the market's buying).
|
|
50
|
+
const unbound = !root.binding || root.binding.kind === "none";
|
|
51
|
+
if (unbound && root.paneId !== TICKER_RESEARCH_PANE_ID) return null;
|
|
52
|
+
return root;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export interface TickerRetargetSelection {
|
|
56
|
+
instrument?: BrokerContractRef | null;
|
|
57
|
+
listing?: TickerListingRef;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* The layout with `target` (from `resolveTickerRetargetPane`) pinned on `symbol`. Its title
|
|
62
|
+
* names the new ticker where it named the old one, and a pane that keeps its ticker elsewhere
|
|
63
|
+
* (a chart's series) moves it through `PaneDef.retargetTicker`.
|
|
64
|
+
*/
|
|
65
|
+
export function retargetTickerPane(
|
|
66
|
+
layout: LayoutConfig,
|
|
67
|
+
target: PaneInstanceConfig,
|
|
68
|
+
symbol: string,
|
|
69
|
+
options: TickerRetargetSelection & { previous: string | null; paneDef?: PaneDef },
|
|
70
|
+
): LayoutConfig {
|
|
71
|
+
const { instrument, listing, previous, paneDef } = options;
|
|
72
|
+
const binding: PaneBinding = {
|
|
73
|
+
kind: "fixed",
|
|
74
|
+
symbol,
|
|
75
|
+
// Only a broker contract is kept, as `pinFollowingPane` keeps it: a public pick's `null` would
|
|
76
|
+
// stop `T AAPL` finding this pane again, since reuse tells null and unspecified contracts apart.
|
|
77
|
+
...(instrument ? { instrument } : {}),
|
|
78
|
+
...(listing ? { listing } : {}),
|
|
79
|
+
};
|
|
80
|
+
const research = target.paneId === TICKER_RESEARCH_PANE_ID;
|
|
81
|
+
const title = research ? tickerInstrumentLabel(symbol, instrument) : pinnedTitle(target, symbol);
|
|
82
|
+
const pinned: PaneInstanceConfig = { ...target, binding, ...(title ? { title } : {}) };
|
|
83
|
+
const next = paneDef?.retargetTicker?.(pinned, symbol, previous) ?? pinned;
|
|
84
|
+
return {
|
|
85
|
+
...layout,
|
|
86
|
+
instances: layout.instances.map((instance) => (instance.instanceId === target.instanceId ? next : instance)),
|
|
87
|
+
};
|
|
88
|
+
}
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
type LayoutMarketplaceAuthor,
|
|
5
5
|
type LayoutMarketplacePayload,
|
|
6
6
|
parseMarketplaceLayoutPayload,
|
|
7
|
+
SHARED_STACK_STATE_KEY,
|
|
7
8
|
} from "../shares/portable-layout";
|
|
8
9
|
import { isRecord } from "../utils/guards";
|
|
9
10
|
import { fnv1aHex } from "../utils/hash";
|
|
@@ -129,6 +130,13 @@ function canonicalJson(value: unknown): string {
|
|
|
129
130
|
* settings do not, and a build that words it differently ("CTM BZ", now
|
|
130
131
|
* "Curve · BZ") retitles the window on open, which is not an edit.
|
|
131
132
|
*/
|
|
133
|
+
/** A pane's shared state without the stack it heads: like the rest of the arrangement, no edit of its content. */
|
|
134
|
+
function arrangementFree(state: Record<string, unknown> | undefined): Record<string, unknown> | undefined {
|
|
135
|
+
if (!state || !(SHARED_STACK_STATE_KEY in state)) return state;
|
|
136
|
+
const { [SHARED_STACK_STATE_KEY]: _stack, ...rest } = state;
|
|
137
|
+
return Object.keys(rest).length > 0 ? rest : undefined;
|
|
138
|
+
}
|
|
139
|
+
|
|
132
140
|
export function layoutContentFingerprint(
|
|
133
141
|
payload: Pick<LayoutMarketplacePayload, "layout" | "paneState">,
|
|
134
142
|
derivesTitle: (paneId: string) => boolean = () => false,
|
|
@@ -149,7 +157,7 @@ export function layoutContentFingerprint(
|
|
|
149
157
|
: (instance.binding ?? null),
|
|
150
158
|
params: instance.params ?? null,
|
|
151
159
|
settings: instance.settings ?? null,
|
|
152
|
-
state: payload.paneState[instance.instanceId] ?? null,
|
|
160
|
+
state: arrangementFree(payload.paneState[instance.instanceId]) ?? null,
|
|
153
161
|
})).sort();
|
|
154
162
|
return `${items.length.toString(16)}-${fnv1aHex(items.join("\n"))}`;
|
|
155
163
|
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import {
|
|
2
|
+
GLOOM_CLOUD_HTTP_CONNECTION_ID,
|
|
3
|
+
GLOOM_CLOUD_SOCKET_CONNECTION_ID,
|
|
4
|
+
type ConnectionHealthRegistry,
|
|
5
|
+
} from "../core/connection-health";
|
|
6
|
+
import type { MarketDataCoordinator } from "./coordinator";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A stream that closes and comes straight back (a server restart) is not
|
|
10
|
+
* called stale for it. One that failed (no answer, a network error) is at once:
|
|
11
|
+
* the socket has already waited out its silence by then.
|
|
12
|
+
*/
|
|
13
|
+
export const QUOTE_STREAM_DOWN_GRACE_MS = 3_000;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Keeps the market data in step with the data service's connection: what
|
|
17
|
+
* failed while the service was unreachable is asked again once it answers,
|
|
18
|
+
* and streamed prices read as stale while the quote stream is down.
|
|
19
|
+
*/
|
|
20
|
+
export function followDataServiceHealth(
|
|
21
|
+
health: ConnectionHealthRegistry,
|
|
22
|
+
coordinator: Pick<MarketDataCoordinator, "reloadAfterOutage" | "setQuoteStreamDown">,
|
|
23
|
+
): () => void {
|
|
24
|
+
const stopRecovery = health.subscribeRecovery((sourceId) => {
|
|
25
|
+
if (sourceId === GLOOM_CLOUD_HTTP_CONNECTION_ID) coordinator.reloadAfterOutage();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
/** The stream has been open since it was last torn down on purpose: only then can it go down. */
|
|
29
|
+
let streamed = false;
|
|
30
|
+
let downSince: number | null = null;
|
|
31
|
+
let grace: ReturnType<typeof setTimeout> | null = null;
|
|
32
|
+
const clearGrace = () => {
|
|
33
|
+
if (grace) clearTimeout(grace);
|
|
34
|
+
grace = null;
|
|
35
|
+
};
|
|
36
|
+
const followStream = () => {
|
|
37
|
+
const state = health.socketState(GLOOM_CLOUD_SOCKET_CONNECTION_ID);
|
|
38
|
+
if (state === "open" || state === "idle" || state === null) {
|
|
39
|
+
// Open again, or closed on purpose (signed out, nothing left to stream): nothing is down.
|
|
40
|
+
streamed = state === "open";
|
|
41
|
+
clearGrace();
|
|
42
|
+
downSince = null;
|
|
43
|
+
coordinator.setQuoteStreamDown(null);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
if (!streamed) return;
|
|
47
|
+
if (downSince == null) downSince = Date.now();
|
|
48
|
+
if (state === "error") {
|
|
49
|
+
clearGrace();
|
|
50
|
+
coordinator.setQuoteStreamDown(downSince);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (grace) return;
|
|
54
|
+
const since = downSince;
|
|
55
|
+
grace = setTimeout(() => {
|
|
56
|
+
grace = null;
|
|
57
|
+
if (downSince === since) coordinator.setQuoteStreamDown(since);
|
|
58
|
+
}, QUOTE_STREAM_DOWN_GRACE_MS);
|
|
59
|
+
};
|
|
60
|
+
const stopHealth = health.subscribe(followStream);
|
|
61
|
+
followStream();
|
|
62
|
+
|
|
63
|
+
return () => {
|
|
64
|
+
stopRecovery();
|
|
65
|
+
stopHealth();
|
|
66
|
+
clearGrace();
|
|
67
|
+
};
|
|
68
|
+
}
|
|
@@ -34,12 +34,24 @@ export function hasFreshEntryData<T>(entry: QueryEntry<T>, ttlMs: number, now =
|
|
|
34
34
|
/**
|
|
35
35
|
* The last request for this entry failed or came back empty a moment ago.
|
|
36
36
|
* A symbol with no financials (an index, a crypto pair) fails every time;
|
|
37
|
-
* without this, each pane, cursor move or warm-up asks again.
|
|
37
|
+
* without this, each pane, cursor move or warm-up asks again. One that
|
|
38
|
+
* finished by `since` does not count.
|
|
38
39
|
*/
|
|
39
|
-
export function hasRecentFailedAttempt<T>(entry: QueryEntry<T>, retryAfterMs: number, now = Date.now()): boolean {
|
|
40
|
+
export function hasRecentFailedAttempt<T>(entry: QueryEntry<T>, retryAfterMs: number, now = Date.now(), since = 0): boolean {
|
|
40
41
|
const attempt = entry.attempts.at(-1);
|
|
41
42
|
return !!attempt && attempt.status !== "success" && attempt.status !== "partial"
|
|
42
|
-
&& now - attempt.finishedAt < retryAfterMs;
|
|
43
|
+
&& attempt.finishedAt > since && now - attempt.finishedAt < retryAfterMs;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* A load of this entry failed (its last request errored), rather than
|
|
48
|
+
* answering, empty or not: what an outage leaves behind, and what is asked
|
|
49
|
+
* again once the service answers.
|
|
50
|
+
*/
|
|
51
|
+
export function hasFailedLoad<T>(entry: QueryEntry<T>): boolean {
|
|
52
|
+
const status = entry.attempts.at(-1)?.status;
|
|
53
|
+
if (status === "fatal_error" || status === "retryable_error") return true;
|
|
54
|
+
return entry.phase === "error" && status !== "empty" && status !== "unsupported";
|
|
43
55
|
}
|
|
44
56
|
|
|
45
57
|
export function hasFreshReadyEntry<T>(entry: QueryEntry<T>, ttlMs: number, now = Date.now()): boolean {
|
|
@@ -1,6 +1,22 @@
|
|
|
1
1
|
import { measurePerf } from "../../utils/perf-marks";
|
|
2
2
|
import { marketDataFrames, type DataFrameScheduler } from "../frame-scheduler";
|
|
3
3
|
|
|
4
|
+
const uniqueKeyLists = new WeakMap<readonly string[], readonly string[]>();
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* `keys` without repeats. React reads a hook's version on every store change
|
|
8
|
+
* and every render, always with the same memoized list, so its de-duplicated
|
|
9
|
+
* copy is kept with it rather than built each time.
|
|
10
|
+
*/
|
|
11
|
+
function uniqueKeys(keys: readonly string[]): readonly string[] {
|
|
12
|
+
let unique = uniqueKeyLists.get(keys);
|
|
13
|
+
if (!unique) {
|
|
14
|
+
unique = [...new Set(keys)];
|
|
15
|
+
uniqueKeyLists.set(keys, unique);
|
|
16
|
+
}
|
|
17
|
+
return unique;
|
|
18
|
+
}
|
|
19
|
+
|
|
4
20
|
/** Hears when a key gains its first listener and loses its last. */
|
|
5
21
|
export interface KeyWatchHooks {
|
|
6
22
|
watched?(key: string): void;
|
|
@@ -73,7 +89,7 @@ export class MarketDataCoordinatorEvents {
|
|
|
73
89
|
|
|
74
90
|
getKeysVersion(keys: readonly string[]): number {
|
|
75
91
|
let version = 0;
|
|
76
|
-
for (const key of
|
|
92
|
+
for (const key of uniqueKeys(keys)) {
|
|
77
93
|
version += this.getKeyVersion(key);
|
|
78
94
|
}
|
|
79
95
|
return version;
|