@gloom-sh/terminal 0.19.5 → 0.20.0
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/LICENSE +0 -4
- package/package.json +6 -5
- package/patches/@opentui%2Fcore@0.3.2.patch +86 -25
- package/patches/electrobun-devkit@2.0.5.patch +148 -0
- package/src/api-client/bond-trades.ts +59 -0
- package/src/api-client/data.ts +21 -0
- package/src/api-client/equity-screener.ts +23 -0
- package/src/api-client/index.ts +2 -0
- package/src/api-client/types/account.ts +86 -0
- package/src/api-client/types/assist.ts +32 -0
- package/src/api-client/types/auth.ts +63 -0
- package/src/api-client/types/billing.ts +54 -0
- package/src/api-client/types/chat.ts +180 -0
- package/src/api-client/types/congress.ts +107 -0
- package/src/api-client/types/credit.ts +110 -0
- package/src/api-client/types/econ.ts +158 -0
- package/src/api-client/types/equity-diagnostic.ts +73 -0
- package/src/api-client/types/filings-and-calls.ts +350 -0
- package/src/api-client/types/index.ts +25 -0
- package/src/api-client/types/jobs.ts +147 -0
- package/src/api-client/types/market.ts +122 -0
- package/src/api-client/types/news.ts +91 -0
- package/src/api-client/types/notes-and-theses.ts +172 -0
- package/src/api-client/types/quotes.ts +28 -0
- package/src/api-client/types/scanners.ts +125 -0
- package/src/api-client/types/screener.ts +65 -0
- package/src/api-client/types/search.ts +107 -0
- package/src/api-client/types/sync.ts +14 -0
- package/src/api-client/types/team-collections.ts +43 -0
- package/src/api-client/types/team-views.ts +32 -0
- package/src/api-client/types/teams.ts +135 -0
- package/src/api-client/types/ticker-data.ts +57 -0
- package/src/api-client/types/tweets.ts +59 -0
- package/src/api-client/types/world-venues.ts +23 -0
- package/src/app/pane-runtime/index.tsx +2 -0
- package/src/app/pane-runtime/plugin-bindings.ts +10 -1
- package/src/app/runtime/desktop-deeplink.ts +41 -6
- package/src/app/star-prompt/status-line.tsx +1 -1
- package/src/app.tsx +64 -23
- package/src/architecture/ui-tokens-allowlist.json +0 -8
- package/src/cli/commands/market.ts +149 -10
- package/src/cli/commands/search.ts +21 -3
- package/src/cli/commands/ticker.ts +90 -36
- package/src/cli/desktop-pane-shot-browser.ts +69 -3
- package/src/cli/glossary.ts +3 -3
- package/src/cli/known-gaps.ts +8 -0
- package/src/cli/listing-arg.ts +12 -0
- package/src/cli/pane-functions/capabilities.ts +2 -0
- package/src/cli/pane-functions/catalog.ts +25 -5
- package/src/cli/pane-functions/function-help.ts +8 -5
- package/src/cli/pane-functions/headless.ts +4 -3
- package/src/cli/pane-functions/resolver.ts +75 -2
- package/src/cli/quote-answer.ts +9 -0
- package/src/cli/symbol-list.ts +54 -2
- package/src/cli/symbol-rows.ts +14 -2
- package/src/cli/ticker-resolution.ts +89 -20
- package/src/components/chart/composite/axis-overlays.tsx +60 -27
- package/src/components/chart/composite/composite-chart.tsx +118 -63
- package/src/components/chart/composite/cursor-source.ts +111 -0
- package/src/components/chart/composite/format.ts +168 -6
- package/src/components/chart/composite/legend.tsx +8 -4
- package/src/components/chart/composite/panel-labels.ts +20 -1
- package/src/components/chart/composite/panel-surface.tsx +201 -92
- package/src/components/chart/composite/price-axis-labels.tsx +92 -46
- package/src/components/chart/composite/price-series.ts +31 -8
- package/src/components/chart/composite/scene.ts +154 -59
- package/src/components/chart/composite/series-axis-tags.tsx +4 -2
- package/src/components/chart/composite/time-axis.ts +13 -5
- package/src/components/chart/composite/time-scale.ts +211 -56
- package/src/components/chart/composite/types.ts +11 -1
- package/src/components/chart/composite/use-composite-chart-keyboard.ts +43 -14
- package/src/components/chart/curve/curve-surface.tsx +5 -2
- package/src/components/chart/curve/model.ts +4 -1
- package/src/components/chart/native/use-bitmap-metrics.ts +81 -0
- package/src/components/chart/static/series.ts +3 -0
- package/src/components/command-bar/commands/collection-list.ts +81 -0
- package/src/components/command-bar/commands/direct/index.ts +6 -0
- package/src/components/command-bar/commands/registry.ts +8 -0
- package/src/components/command-bar/layout-items/current-layout.ts +22 -1
- package/src/components/command-bar/layout-items/focused-pane.ts +22 -1
- package/src/components/command-bar/pane-templates/items.ts +19 -3
- package/src/components/command-bar/pane-templates/workflow.ts +5 -0
- package/src/components/command-bar/routes/root/results.ts +23 -3
- package/src/components/command-bar/routes/root/selection.ts +4 -2
- package/src/components/command-bar/routes/root/shortcut-feedback.ts +1 -1
- package/src/components/command-bar/routes/root/shortcut-items.ts +3 -4
- package/src/components/command-bar/routes/root/shortcuts.ts +58 -14
- package/src/components/command-bar/routes/root/ticker-first.ts +32 -0
- package/src/components/command-bar/surface/environment.ts +2 -0
- package/src/components/command-bar/view-model.ts +7 -0
- package/src/components/command-bar/workflow/ops.ts +2 -1
- package/src/components/command-bar/workflow/tickers.ts +20 -0
- package/src/components/data-table/export.ts +4 -1
- package/src/components/layout/detached-pane-shell.tsx +10 -37
- package/src/components/layout/double-escape-close.ts +90 -0
- package/src/components/layout/header.tsx +3 -2
- package/src/components/layout/market-summary.ts +6 -3
- package/src/components/layout/pane/footer/index.tsx +2 -6
- package/src/components/layout/pane/footer/model.ts +6 -12
- package/src/components/layout/shell/active-drag.ts +53 -11
- package/src/components/layout/shell/drag/magnets.ts +128 -19
- package/src/components/layout/shell/menu.ts +15 -1
- package/src/components/layout/shell/pane/actions.ts +10 -2
- package/src/components/layout/shell/pane/management-shortcuts.ts +13 -51
- package/src/components/layout/shell/ticker-link-menu.ts +12 -3
- package/src/components/layout/status-bar.tsx +24 -78
- package/src/components/layout/status-widget-space.ts +5 -5
- package/src/components/onboarding/onboarding-keyboard.ts +5 -1
- package/src/components/onboarding/onboarding-wizard.tsx +15 -4
- package/src/components/onboarding/portfolio-step/positions-panel.tsx +9 -6
- package/src/components/onboarding/use-onboarding-progress.ts +20 -1
- package/src/components/price-sparkline/view.tsx +14 -6
- package/src/components/ticker/badge/index.tsx +8 -4
- package/src/components/ticker/badge/list.tsx +23 -7
- package/src/components/ui/column-grid.tsx +8 -2
- package/src/components/ui/data-table/index.tsx +5 -1
- package/src/components/ui/data-table/opentui/model.ts +4 -1
- package/src/components/ui/data-table/render-cell.ts +19 -0
- package/src/components/ui/delayed-mark.tsx +59 -7
- package/src/components/ui/icon.tsx +1 -8
- package/src/components/ui/menu.tsx +6 -1
- package/src/components/ui/tabs.tsx +5 -2
- package/src/core/state/app/layout.ts +18 -3
- package/src/core/state/app/state.ts +2 -0
- package/src/core/state/app/types.ts +5 -0
- package/src/data/config/layout.ts +3 -0
- package/src/data/config/store/normalize.ts +39 -4
- package/src/i18n/es.ts +13 -3
- package/src/i18n/ja.ts +13 -3
- package/src/i18n/ko.ts +13 -3
- package/src/i18n/zh-cn.ts +13 -3
- package/src/i18n/zh-tw.ts +13 -3
- package/src/layout/pane-manager/floating-placement.ts +7 -4
- package/src/layout/pane-manager/floating.ts +5 -2
- package/src/market-data/bond-funds.ts +19 -0
- package/src/market-data/futures-contract.ts +14 -3
- package/src/market-data/market/freshness.ts +18 -0
- package/src/market-data/market/status.ts +15 -2
- package/src/plugins/builtin/bond-calculator/headless.ts +2 -1
- package/src/plugins/builtin/bond-calculator/index.tsx +1 -1
- package/src/plugins/builtin/bond-calculator/model.ts +14 -5
- package/src/plugins/builtin/bond-calculator/pane.tsx +1 -1
- package/src/plugins/builtin/buildout/cells.tsx +25 -45
- package/src/plugins/builtin/buildout/detail/company.tsx +3 -3
- package/src/plugins/builtin/buildout/detail/index.tsx +1 -1
- package/src/plugins/builtin/buildout/detail/intel.tsx +4 -7
- package/src/plugins/builtin/buildout/detail/site.tsx +4 -4
- package/src/plugins/builtin/buildout/detail/ui.tsx +39 -38
- package/src/plugins/builtin/buildout/format.ts +23 -1
- package/src/plugins/builtin/buildout/model/types.ts +1 -0
- package/src/plugins/builtin/buildout/pane/index.tsx +2 -8
- package/src/plugins/builtin/buildout/table-model.ts +12 -4
- package/src/plugins/builtin/cds/headless.ts +1 -0
- package/src/plugins/builtin/cds/index.tsx +1 -1
- package/src/plugins/builtin/chat/content/composer.tsx +21 -27
- package/src/plugins/builtin/chat/content/index.tsx +31 -3
- package/src/plugins/builtin/chat/content/shortcuts.ts +4 -2
- package/src/plugins/builtin/chat/content/snapshot.ts +0 -3
- package/src/plugins/builtin/cloud/auth-actions.tsx +51 -23
- package/src/plugins/builtin/cloud/plugin.tsx +2 -0
- package/src/plugins/builtin/cloud/trial-offer-status-widget.tsx +3 -3
- package/src/plugins/builtin/cloud/upgrade-status-widget.tsx +44 -12
- package/src/plugins/builtin/congress-trades/model.ts +2 -1
- package/src/plugins/builtin/congress-trades/pane.tsx +3 -0
- package/src/plugins/builtin/correlation/headless.ts +3 -2
- package/src/plugins/builtin/crypto-board/pane.tsx +5 -4
- package/src/plugins/builtin/custom-view/index.tsx +1 -1
- package/src/plugins/builtin/custom-view/loader.ts +85 -8
- package/src/plugins/builtin/custom-view/view-spec.ts +28 -0
- package/src/plugins/builtin/debt-maturities/headless.ts +11 -2
- package/src/plugins/builtin/debt-maturities/model.ts +66 -0
- package/src/plugins/builtin/debt-maturities/pane.tsx +23 -4
- package/src/plugins/builtin/earnings-ripple/pane.tsx +1 -1
- package/src/plugins/builtin/econ/calendar-model.ts +28 -6
- package/src/plugins/builtin/equity-screener/client.ts +1 -1
- package/src/plugins/builtin/equity-screener/criterion-editor.tsx +16 -19
- package/src/plugins/builtin/equity-screener/headless.ts +37 -3
- package/src/plugins/builtin/equity-screener/ideas.ts +67 -3
- package/src/plugins/builtin/equity-screener/model.ts +238 -27
- package/src/plugins/builtin/equity-screener/pane.tsx +88 -18
- package/src/plugins/builtin/equity-screener/screen-check.ts +7 -4
- package/src/plugins/builtin/equity-screener/watchlist.ts +33 -0
- package/src/plugins/builtin/executives/format.ts +5 -4
- package/src/plugins/builtin/executives/pane.tsx +1 -1
- package/src/plugins/builtin/futures-curve/client.ts +19 -0
- package/src/plugins/builtin/futures-curve/headless.ts +52 -13
- package/src/plugins/builtin/futures-curve/index.tsx +1 -1
- package/src/plugins/builtin/futures-curve/model.ts +77 -6
- package/src/plugins/builtin/futures-curve/pane.tsx +19 -3
- package/src/plugins/builtin/help/index.tsx +55 -1
- package/src/plugins/builtin/insider/model.ts +30 -2
- package/src/plugins/builtin/jobs/model.ts +2 -2
- package/src/plugins/builtin/macro-day/client.ts +41 -0
- package/src/plugins/builtin/macro-day/headless.ts +19 -9
- package/src/plugins/builtin/macro-day/model.ts +3 -1
- package/src/plugins/builtin/market-movers/index.tsx +4 -3
- package/src/plugins/builtin/mna/distress/headless.ts +1 -0
- package/src/plugins/builtin/mna/model.ts +2 -2
- package/src/plugins/builtin/notes/files.ts +2 -0
- package/src/plugins/builtin/notes/owner.tsx +20 -1
- package/src/plugins/builtin/notes/quick-notes-pane.tsx +22 -4
- package/src/plugins/builtin/notes/store.ts +6 -1
- package/src/plugins/builtin/perps/pane.tsx +3 -1
- package/src/plugins/builtin/portfolio-list/cli/bulk-symbols.ts +17 -0
- package/src/plugins/builtin/portfolio-list/cli/portfolio-command.ts +2 -1
- package/src/plugins/builtin/portfolio-list/cli/watchlist-command.ts +2 -1
- package/src/plugins/builtin/portfolio-list/header.tsx +1 -1
- package/src/plugins/builtin/rate-path/headless.ts +24 -10
- package/src/plugins/builtin/research/corporate-actions-pane.tsx +29 -25
- package/src/plugins/builtin/research/event-model.ts +10 -3
- package/src/plugins/builtin/research/events-headless.ts +20 -2
- package/src/plugins/builtin/sec/fund-facts.ts +17 -1
- package/src/plugins/builtin/sec/index.tsx +1 -1
- package/src/plugins/builtin/series-inventory.ts +1 -0
- package/src/plugins/builtin/shared/earnings-report.ts +7 -2
- package/src/plugins/builtin/shared/members-menu.tsx +103 -38
- package/src/plugins/builtin/shared/use-quote-board.ts +85 -46
- package/src/plugins/builtin/short-interest/headless.ts +1 -1
- package/src/plugins/builtin/short-interest/model.ts +15 -6
- package/src/plugins/builtin/short-interest/publications-model.ts +22 -1
- package/src/plugins/builtin/short-interest/publications-pane.tsx +13 -4
- package/src/plugins/builtin/short-interest/types.ts +2 -0
- package/src/plugins/builtin/short-interest/watch-model.ts +1 -1
- package/src/plugins/builtin/thirteenf/overlap-pane.tsx +3 -0
- package/src/plugins/builtin/thirteenf/pane.tsx +3 -0
- package/src/plugins/builtin/ticker-detail/overview/model.ts +5 -3
- package/src/plugins/builtin/ticker-detail/overview-tab.tsx +4 -4
- package/src/plugins/builtin/time-sales/pane.tsx +3 -2
- package/src/plugins/builtin/trace-bonds/client.ts +7 -4
- package/src/plugins/builtin/trace-bonds/detail.tsx +198 -0
- package/src/plugins/builtin/trace-bonds/headless.ts +62 -4
- package/src/plugins/builtin/trace-bonds/history.ts +155 -0
- package/src/plugins/builtin/trace-bonds/index.tsx +1 -1
- package/src/plugins/builtin/trace-bonds/pane.tsx +64 -5
- package/src/plugins/builtin/volatility/client.ts +6 -1
- package/src/plugins/builtin/volatility/headless.ts +0 -1
- package/src/plugins/builtin/yield-curve/curves.ts +15 -0
- package/src/plugins/builtin/yield-curve/headless.ts +6 -1
- package/src/plugins/builtin/yield-curve/index.tsx +5 -8
- package/src/plugins/host-modules.ts +22 -3
- package/src/plugins/host-smoke.ts +6 -3
- package/src/plugins/installer.ts +16 -3
- package/src/plugins/plugin-names.ts +11 -2
- package/src/portfolio/collection-name.ts +19 -0
- package/src/remote/controller.ts +9 -2
- package/src/remote/schema.ts +2 -1
- package/src/renderers/browser/http-proxy-transport.ts +78 -8
- package/src/renderers/cloudflare/http-proxy.ts +73 -3
- package/src/renderers/cloudflare/proxy-session.ts +47 -24
- package/src/renderers/cloudflare/worker.ts +44 -4
- package/src/renderers/desktop/geometry.ts +279 -0
- package/src/renderers/desktop/screen-setup.ts +246 -0
- package/src/renderers/desktop/sequential-window-host.ts +179 -0
- package/src/renderers/desktop/test-utils.ts +71 -0
- package/src/renderers/desktop/window-controller.ts +433 -0
- package/src/renderers/desktop/window-host.ts +70 -0
- package/src/renderers/desktop/window-layouts.ts +630 -0
- package/src/renderers/dom/data-frames.ts +15 -4
- package/src/renderers/dom/desktop/icons.tsx +0 -2
- package/src/renderers/dom/styles.css +0 -3
- package/src/renderers/electrobun/bun/application-menu/click.ts +1 -0
- package/src/renderers/electrobun/bun/application-menu/index.ts +4 -1
- package/src/renderers/electrobun/bun/desktop/backend-requests.ts +19 -8
- package/src/renderers/electrobun/bun/desktop/backend.ts +320 -19
- package/src/renderers/electrobun/bun/desktop/detached-windows.ts +83 -61
- package/src/renderers/electrobun/bun/desktop/host-requests.ts +4 -14
- package/src/renderers/electrobun/bun/desktop/initialization.ts +30 -11
- package/src/renderers/electrobun/bun/desktop/install-records.ts +59 -0
- package/src/renderers/electrobun/bun/desktop/installer-folder.ts +208 -592
- package/src/renderers/electrobun/bun/desktop/macos-objc.ts +14 -0
- package/src/renderers/electrobun/bun/desktop/screen-setup-file.ts +55 -0
- package/src/renderers/electrobun/bun/desktop/state-broadcaster.ts +44 -8
- package/src/renderers/electrobun/bun/desktop/update.ts +1 -1
- package/src/renderers/electrobun/bun/desktop/workspace/index.ts +298 -97
- package/src/renderers/electrobun/bun/desktop/workspace/requests.ts +44 -6
- package/src/renderers/electrobun/bun/index.ts +22 -109
- package/src/renderers/electrobun/bun/window/create.ts +23 -3
- package/src/renderers/electrobun/bun/window/electrobun-window-host.ts +306 -0
- package/src/renderers/electrobun/bun/window/events.ts +4 -4
- package/src/renderers/electrobun/bun/window/focus.ts +0 -25
- package/src/renderers/electrobun/bun/window/frame.ts +2 -1
- package/src/renderers/electrobun/bun/window/native-min-size.ts +322 -0
- package/src/renderers/electrobun/bun/window/remembered-frame.ts +4 -82
- package/src/renderers/electrobun/shared/protocol.ts +44 -2
- package/src/renderers/electrobun/view/backend-rpc.ts +16 -1
- package/src/renderers/electrobun/view/desktop/window/bridge.ts +63 -3
- package/src/renderers/electrobun/view/main.tsx +13 -7
- package/src/series/fred-argument.ts +17 -0
- package/src/sources/gloomberb-cloud/index.ts +5 -7
- package/src/sources/provider-router/batches.ts +18 -3
- package/src/sources/provider-router/financial-routes.ts +7 -1
- package/src/sources/provider-router/financials.ts +18 -4
- package/src/state/app/context/index.tsx +16 -2
- package/src/state/desktop-windows.ts +63 -0
- package/src/sync/other-window-tabs.ts +62 -0
- package/src/tickers/company-name-listing.ts +23 -3
- package/src/tickers/listing-fate.ts +147 -1
- package/src/tickers/terminal-codes.ts +5 -0
- package/src/time-series/types.ts +6 -0
- package/src/types/config.ts +10 -1
- package/src/types/data-provider.ts +14 -0
- package/src/types/desktop-window.ts +71 -2
- package/src/types/financials.ts +19 -3
- package/src/types/headless.ts +21 -0
- package/src/types/plugin.ts +6 -0
- package/src/ui/index.tsx +14 -13
- package/src/ui/same-props.ts +58 -0
- package/src/utils/cli-output.ts +33 -4
- package/src/utils/double-escape-close.ts +38 -16
- package/src/utils/format.ts +30 -5
- package/src/utils/futures-generic.ts +12 -0
- package/src/utils/http-proxy-upstream.ts +6 -2
- package/src/utils/plugin-proxy-hosts.json +0 -4
- package/src/utils/plugin-proxy-hosts.ts +22 -0
- package/src/utils/price-earnings.ts +18 -0
- package/src/utils/sec-filings.ts +7 -1
- package/patches/electrobun@1.18.1.patch +0 -633
- package/src/api-client/types.ts +0 -2441
|
@@ -0,0 +1,630 @@
|
|
|
1
|
+
import {
|
|
2
|
+
clonePaneStateMap,
|
|
3
|
+
syncConfigActiveLayoutState,
|
|
4
|
+
type PaneRuntimeState,
|
|
5
|
+
} from "../../core/state/app/state";
|
|
6
|
+
import { createSavedLayoutId } from "../../layout/pane-layout-move";
|
|
7
|
+
import { dockPane, floatAtRect, insertAtRootEdge, removePane } from "../../layout/pane-manager";
|
|
8
|
+
import {
|
|
9
|
+
cloneLayout,
|
|
10
|
+
createBlankLayout,
|
|
11
|
+
findPaneInstance,
|
|
12
|
+
type AppConfig,
|
|
13
|
+
type LayoutConfig,
|
|
14
|
+
type SavedLayout,
|
|
15
|
+
} from "../../types/config";
|
|
16
|
+
import type { DesktopSharedStateSnapshot, OtherWindowTab } from "../../types/desktop-window";
|
|
17
|
+
import { MAIN_WINDOW_ID, type ExtraWindowRecord } from "./screen-setup";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Every full desktop window shows its own layout tabs from one shared config.
|
|
21
|
+
* The config keeps every tab, in one order; each tab belongs to exactly one
|
|
22
|
+
* window, the main window by default. A window is sent its projection: the
|
|
23
|
+
* config with only its own tabs, its active tab as `layout`, and its own pane
|
|
24
|
+
* state and focus. What a window sends back is merged against what it last
|
|
25
|
+
* held, so it only ever changes what it changed: a window still drawing a
|
|
26
|
+
* state from a moment ago never undoes another window's edit.
|
|
27
|
+
*
|
|
28
|
+
* Nothing here knows about a shell; the backend keeps one of these and sends
|
|
29
|
+
* each window its projection.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
export interface WindowView {
|
|
33
|
+
activeLayoutId: string;
|
|
34
|
+
paneState: Record<string, PaneRuntimeState>;
|
|
35
|
+
focusedPaneId: string | null;
|
|
36
|
+
statusBarVisible: boolean;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface WindowLayouts {
|
|
40
|
+
/** Every tab, in the config's order. `layout` and `activeLayoutIndex` are the main window's. */
|
|
41
|
+
config: AppConfig;
|
|
42
|
+
brokerSyncErrors: Record<string, string>;
|
|
43
|
+
/** Every full window, the main one first, then in the order they opened. */
|
|
44
|
+
windowIds: string[];
|
|
45
|
+
views: Record<string, WindowView>;
|
|
46
|
+
/** The window showing a tab, by tab id. A tab with no entry is the main window's. */
|
|
47
|
+
owners: Record<string, string>;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const LAYOUT_KEYS = new Set<string>(["layout", "layouts", "activeLayoutIndex"]);
|
|
51
|
+
|
|
52
|
+
function deepEqual(a: unknown, b: unknown): boolean {
|
|
53
|
+
if (Object.is(a, b)) return true;
|
|
54
|
+
if (!a || !b || typeof a !== "object" || typeof b !== "object") return false;
|
|
55
|
+
if (Array.isArray(a) !== Array.isArray(b)) return false;
|
|
56
|
+
if (Array.isArray(a)) {
|
|
57
|
+
const other = b as unknown[];
|
|
58
|
+
if (a.length !== other.length) return false;
|
|
59
|
+
for (let index = 0; index < a.length; index += 1) {
|
|
60
|
+
if (!deepEqual(a[index], other[index])) return false;
|
|
61
|
+
}
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
const left = a as Record<string, unknown>;
|
|
65
|
+
const right = b as Record<string, unknown>;
|
|
66
|
+
const leftKeys = Object.keys(left).filter((key) => left[key] !== undefined);
|
|
67
|
+
const rightKeys = Object.keys(right).filter((key) => right[key] !== undefined);
|
|
68
|
+
if (leftKeys.length !== rightKeys.length) return false;
|
|
69
|
+
return leftKeys.every((key) => deepEqual(left[key], right[key]));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Gives every tab an id, and a new one to a tab that repeats an earlier tab's
|
|
74
|
+
* id: tabs belong to windows by id. Returns the same config when all are set.
|
|
75
|
+
*/
|
|
76
|
+
function ensureLayoutIds(config: AppConfig): AppConfig {
|
|
77
|
+
const seen = new Set<string>();
|
|
78
|
+
let changed = false;
|
|
79
|
+
const layouts = config.layouts.map((entry) => {
|
|
80
|
+
if (entry.id && !seen.has(entry.id)) {
|
|
81
|
+
seen.add(entry.id);
|
|
82
|
+
return entry;
|
|
83
|
+
}
|
|
84
|
+
changed = true;
|
|
85
|
+
const id = createSavedLayoutId();
|
|
86
|
+
seen.add(id);
|
|
87
|
+
return { ...entry, id };
|
|
88
|
+
});
|
|
89
|
+
return changed ? { ...config, layouts } : config;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function layoutId(entry: SavedLayout): string {
|
|
93
|
+
return entry.id!;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function ownerOf(state: Pick<WindowLayouts, "owners" | "views">, id: string): string {
|
|
97
|
+
const owner = state.owners[id];
|
|
98
|
+
return owner && state.views[owner] ? owner : MAIN_WINDOW_ID;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function windowTabs(state: WindowLayouts, windowId: string): SavedLayout[] {
|
|
102
|
+
return state.config.layouts.filter((entry) => ownerOf(state, layoutId(entry)) === windowId);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** The window showing a tab, or null when no tab has the id. */
|
|
106
|
+
export function windowOfLayout(state: WindowLayouts, id: string): string | null {
|
|
107
|
+
return state.config.layouts.some((entry) => entry.id === id) ? ownerOf(state, id) : null;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** The tab holding a pane, and the window showing it. */
|
|
111
|
+
export function locatePane(state: WindowLayouts, paneId: string): { layoutId: string; windowId: string } | null {
|
|
112
|
+
const entry = state.config.layouts.find((candidate) => !!findPaneInstance(candidate.layout, paneId));
|
|
113
|
+
return entry ? { layoutId: layoutId(entry), windowId: ownerOf(state, layoutId(entry)) } : null;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function viewFromTab(tab: SavedLayout, statusBarVisible: boolean): WindowView {
|
|
117
|
+
return {
|
|
118
|
+
activeLayoutId: layoutId(tab),
|
|
119
|
+
paneState: clonePaneStateMap(tab.paneState ?? {}),
|
|
120
|
+
focusedPaneId: tab.focusedPaneId ?? null,
|
|
121
|
+
statusBarVisible,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Settles a state after a change: every window shows tabs it owns, a window
|
|
127
|
+
* left without tabs is gone, the main window keeps at least one, and the
|
|
128
|
+
* config's active layout is the main window's.
|
|
129
|
+
*/
|
|
130
|
+
function settle(state: WindowLayouts): WindowLayouts {
|
|
131
|
+
const ids = new Set(state.config.layouts.map(layoutId));
|
|
132
|
+
const owners: Record<string, string> = {};
|
|
133
|
+
for (const [id, windowId] of Object.entries(state.owners)) {
|
|
134
|
+
if (ids.has(id) && windowId !== MAIN_WINDOW_ID && state.views[windowId]) owners[id] = windowId;
|
|
135
|
+
}
|
|
136
|
+
let next: WindowLayouts = { ...state, owners };
|
|
137
|
+
// The main window always keeps a tab: the config's active layout is one of its.
|
|
138
|
+
if (!next.config.layouts.some((entry) => !owners[layoutId(entry)])) {
|
|
139
|
+
const first = next.config.layouts[0];
|
|
140
|
+
if (first) delete owners[layoutId(first)];
|
|
141
|
+
}
|
|
142
|
+
const views: Record<string, WindowView> = {};
|
|
143
|
+
const windowIds: string[] = [];
|
|
144
|
+
for (const windowId of next.windowIds) {
|
|
145
|
+
const view = next.views[windowId];
|
|
146
|
+
if (!view) continue;
|
|
147
|
+
const tabs = windowTabs(next, windowId);
|
|
148
|
+
if (tabs.length === 0) continue;
|
|
149
|
+
windowIds.push(windowId);
|
|
150
|
+
views[windowId] = tabs.some((tab) => tab.id === view.activeLayoutId)
|
|
151
|
+
? view
|
|
152
|
+
: viewFromTab(tabs[0]!, view.statusBarVisible);
|
|
153
|
+
}
|
|
154
|
+
next = { ...next, views, windowIds };
|
|
155
|
+
const main = views[MAIN_WINDOW_ID]!;
|
|
156
|
+
const mainIndex = next.config.layouts.findIndex((entry) => entry.id === main.activeLayoutId);
|
|
157
|
+
const active = next.config.layouts[mainIndex]!;
|
|
158
|
+
// The saved copy of the main window's active tab is kept current, so it is the live layout.
|
|
159
|
+
return { ...next, config: { ...next.config, activeLayoutIndex: mainIndex, layout: cloneLayout(active.layout) } };
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* The windows as the backend starts them: the config, the main window's live
|
|
164
|
+
* state, and the extra windows this machine kept. A kept window whose tabs
|
|
165
|
+
* are all gone is not opened again.
|
|
166
|
+
*/
|
|
167
|
+
export function createWindowLayouts(
|
|
168
|
+
source: AppConfig,
|
|
169
|
+
main: Omit<WindowView, "activeLayoutId"> & { brokerSyncErrors?: Record<string, string> },
|
|
170
|
+
records: readonly ExtraWindowRecord[] = [],
|
|
171
|
+
): WindowLayouts {
|
|
172
|
+
const config = ensureLayoutIds(syncConfigActiveLayoutState(source, main.paneState, main.focusedPaneId));
|
|
173
|
+
const mainActiveId = layoutId(config.layouts[config.activeLayoutIndex]!);
|
|
174
|
+
const owners: Record<string, string> = {};
|
|
175
|
+
const views: Record<string, WindowView> = {
|
|
176
|
+
[MAIN_WINDOW_ID]: {
|
|
177
|
+
activeLayoutId: mainActiveId,
|
|
178
|
+
paneState: main.paneState,
|
|
179
|
+
focusedPaneId: main.focusedPaneId,
|
|
180
|
+
statusBarVisible: main.statusBarVisible,
|
|
181
|
+
},
|
|
182
|
+
};
|
|
183
|
+
const windowIds = [MAIN_WINDOW_ID];
|
|
184
|
+
const byId = new Map(config.layouts.map((entry) => [layoutId(entry), entry] as const));
|
|
185
|
+
for (const record of records) {
|
|
186
|
+
if (views[record.id]) continue;
|
|
187
|
+
const tabs = record.layoutIds.filter((id) => byId.has(id) && !owners[id] && id !== mainActiveId);
|
|
188
|
+
if (tabs.length === 0) continue;
|
|
189
|
+
for (const id of tabs) owners[id] = record.id;
|
|
190
|
+
const active = byId.get(record.activeLayoutId && tabs.includes(record.activeLayoutId) ? record.activeLayoutId : tabs[0]!)!;
|
|
191
|
+
views[record.id] = viewFromTab(active, main.statusBarVisible);
|
|
192
|
+
windowIds.push(record.id);
|
|
193
|
+
}
|
|
194
|
+
return settle({
|
|
195
|
+
config,
|
|
196
|
+
brokerSyncErrors: { ...main.brokerSyncErrors },
|
|
197
|
+
windowIds,
|
|
198
|
+
views,
|
|
199
|
+
owners,
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** What the backend keeps on this machine about the extra windows. */
|
|
204
|
+
export function extraWindowRecords(state: WindowLayouts): ExtraWindowRecord[] {
|
|
205
|
+
return state.windowIds
|
|
206
|
+
.filter((windowId) => windowId !== MAIN_WINDOW_ID)
|
|
207
|
+
.map((windowId) => ({
|
|
208
|
+
id: windowId,
|
|
209
|
+
layoutIds: windowTabs(state, windowId).map(layoutId),
|
|
210
|
+
activeLayoutId: state.views[windowId]!.activeLayoutId,
|
|
211
|
+
}));
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** The ticker a pane shows where it is: live on its window's shown tab, else as its tab saved it. */
|
|
215
|
+
function paneTicker(state: WindowLayouts, paneId: string, seen: Set<string>): string | null {
|
|
216
|
+
if (seen.has(paneId)) return null;
|
|
217
|
+
seen.add(paneId);
|
|
218
|
+
const located = locatePane(state, paneId);
|
|
219
|
+
if (!located) return null;
|
|
220
|
+
const view = state.views[located.windowId];
|
|
221
|
+
const tab = state.config.layouts.find((entry) => layoutId(entry) === located.layoutId)!;
|
|
222
|
+
const shown = view?.activeLayoutId === located.layoutId;
|
|
223
|
+
const layout = shown && located.windowId === MAIN_WINDOW_ID ? state.config.layout : tab.layout;
|
|
224
|
+
const instance = findPaneInstance(layout, paneId);
|
|
225
|
+
if (!instance) return null;
|
|
226
|
+
const cursor = (shown ? view!.paneState : tab.paneState ?? {})[paneId]?.cursorSymbol;
|
|
227
|
+
if (typeof cursor === "string" && cursor.trim()) return cursor;
|
|
228
|
+
if (instance.binding?.kind === "fixed") return instance.binding.symbol;
|
|
229
|
+
if (instance.binding?.kind === "follow") return paneTicker(state, instance.binding.sourceInstanceId, seen);
|
|
230
|
+
return null;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* The tickers of panes in other windows that panes on any of a window's tabs
|
|
235
|
+
* follow, so a link survives a pane moving to another window and the window
|
|
236
|
+
* switching tabs. A source with no ticker yet is listed too, as "": its
|
|
237
|
+
* follower stays linked. A source on another tab of the same window is not
|
|
238
|
+
* one: links stay within a tab there.
|
|
239
|
+
*/
|
|
240
|
+
function linkedTickersFor(state: WindowLayouts, windowId: string, shownLayout: LayoutConfig): Record<string, string> {
|
|
241
|
+
const shownId = state.views[windowId]?.activeLayoutId;
|
|
242
|
+
const tickers: Record<string, string> = {};
|
|
243
|
+
for (const tab of windowTabs(state, windowId)) {
|
|
244
|
+
const layout = layoutId(tab) === shownId ? shownLayout : tab.layout;
|
|
245
|
+
const local = new Set(layout.instances.map((instance) => instance.instanceId));
|
|
246
|
+
for (const instance of layout.instances) {
|
|
247
|
+
if (instance.binding?.kind !== "follow") continue;
|
|
248
|
+
const sourceId = instance.binding.sourceInstanceId;
|
|
249
|
+
if (local.has(sourceId) || sourceId in tickers) continue;
|
|
250
|
+
const located = locatePane(state, sourceId);
|
|
251
|
+
if (!located || located.windowId === windowId) continue;
|
|
252
|
+
tickers[sourceId] = paneTicker(state, sourceId, new Set()) ?? "";
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
return tickers;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* The tabs the other windows hold, at their places among all the tabs, for
|
|
260
|
+
* the main window's cloud sync: it pushes and pulls every window's tabs.
|
|
261
|
+
*/
|
|
262
|
+
export function otherWindowTabs(state: WindowLayouts): OtherWindowTab[] {
|
|
263
|
+
if (state.windowIds.length <= 1) return [];
|
|
264
|
+
return state.config.layouts.flatMap((tab, at) => (ownerOf(state, layoutId(tab)) === MAIN_WINDOW_ID ? [] : [{ at, tab }]));
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/** The state a window is sent: its own tabs, its active tab as the layout, its own pane state and focus. */
|
|
268
|
+
export function projectWindow(state: WindowLayouts, windowId: string): DesktopSharedStateSnapshot | null {
|
|
269
|
+
const view = state.views[windowId];
|
|
270
|
+
if (!view) return null;
|
|
271
|
+
const tabs = windowTabs(state, windowId);
|
|
272
|
+
const activeIndex = Math.max(0, tabs.findIndex((entry) => entry.id === view.activeLayoutId));
|
|
273
|
+
const active = tabs[activeIndex]!;
|
|
274
|
+
const layout = windowId === MAIN_WINDOW_ID ? state.config.layout : active.layout;
|
|
275
|
+
const linkedTickers = state.windowIds.length > 1 ? linkedTickersFor(state, windowId, layout) : {};
|
|
276
|
+
return {
|
|
277
|
+
config: {
|
|
278
|
+
...state.config,
|
|
279
|
+
layouts: tabs,
|
|
280
|
+
activeLayoutIndex: activeIndex,
|
|
281
|
+
layout,
|
|
282
|
+
},
|
|
283
|
+
paneState: view.paneState,
|
|
284
|
+
focusedPaneId: view.focusedPaneId,
|
|
285
|
+
statusBarVisible: view.statusBarVisible,
|
|
286
|
+
brokerSyncErrors: state.brokerSyncErrors,
|
|
287
|
+
...(Object.keys(linkedTickers).length > 0 ? { linkedTickers } : {}),
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/** A snapshot with its live layout, pane state and focus written into its active tab, as the config saves them. */
|
|
292
|
+
function normalize(snapshot: DesktopSharedStateSnapshot): DesktopSharedStateSnapshot {
|
|
293
|
+
return {
|
|
294
|
+
...snapshot,
|
|
295
|
+
config: syncConfigActiveLayoutState(snapshot.config, snapshot.paneState, snapshot.focusedPaneId),
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
function activeTabId(snapshot: DesktopSharedStateSnapshot): string | undefined {
|
|
300
|
+
return snapshot.config.layouts[snapshot.config.activeLayoutIndex]?.id;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* A window's own tabs in the order it sent them, in the places its tabs hold;
|
|
305
|
+
* a tab given to it since it sent keeps its place after them.
|
|
306
|
+
*/
|
|
307
|
+
function inSentOrder(layouts: SavedLayout[], sentIds: readonly string[], owns: (id: string) => boolean): SavedLayout[] {
|
|
308
|
+
const slots = layouts.flatMap((entry, at) => (owns(layoutId(entry)) ? [at] : []));
|
|
309
|
+
const ownIds = new Set(slots.map((at) => layoutId(layouts[at]!)));
|
|
310
|
+
const sent = new Set(sentIds);
|
|
311
|
+
const order = [
|
|
312
|
+
...sentIds.filter((id) => ownIds.has(id)),
|
|
313
|
+
...slots.map((at) => layoutId(layouts[at]!)).filter((id) => !sent.has(id)),
|
|
314
|
+
];
|
|
315
|
+
const byId = new Map(layouts.map((entry) => [layoutId(entry), entry] as const));
|
|
316
|
+
const reordered = [...layouts];
|
|
317
|
+
slots.forEach((slot, at) => {
|
|
318
|
+
reordered[slot] = byId.get(order[at]!)!;
|
|
319
|
+
});
|
|
320
|
+
return reordered;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Applies what `windowId` sent on top of the shared state, counting only what
|
|
325
|
+
* changed since `base`, the state the window drew from. Settings and lists
|
|
326
|
+
* take the window's value when it changed them. Tabs are matched by id: the
|
|
327
|
+
* window's new tabs join it, its deleted tabs go, its edited tabs replace
|
|
328
|
+
* theirs, and a new order of its own tabs is kept. A tab the window sends
|
|
329
|
+
* that another window owns, which only a pulled or imported config does,
|
|
330
|
+
* takes the content and stays where it is.
|
|
331
|
+
*
|
|
332
|
+
* With no base, everything the window sends counts as its change.
|
|
333
|
+
*/
|
|
334
|
+
export function mergeWindowSnapshot(
|
|
335
|
+
state: WindowLayouts,
|
|
336
|
+
windowId: string,
|
|
337
|
+
base: DesktopSharedStateSnapshot | null,
|
|
338
|
+
sent: DesktopSharedStateSnapshot,
|
|
339
|
+
): WindowLayouts {
|
|
340
|
+
const view = state.views[windowId];
|
|
341
|
+
if (!view) return state;
|
|
342
|
+
const before = normalize(base ?? projectWindow(state, windowId)!);
|
|
343
|
+
const after = normalize(sent);
|
|
344
|
+
|
|
345
|
+
const config: AppConfig = { ...state.config };
|
|
346
|
+
const configRecord = config as unknown as Record<string, unknown>;
|
|
347
|
+
const afterRecord = after.config as unknown as Record<string, unknown>;
|
|
348
|
+
const beforeRecord = before.config as unknown as Record<string, unknown>;
|
|
349
|
+
for (const key of new Set([...Object.keys(afterRecord), ...Object.keys(beforeRecord)])) {
|
|
350
|
+
if (LAYOUT_KEYS.has(key) || deepEqual(afterRecord[key], beforeRecord[key])) continue;
|
|
351
|
+
if (afterRecord[key] === undefined) delete configRecord[key];
|
|
352
|
+
else configRecord[key] = afterRecord[key];
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
const owners = { ...state.owners };
|
|
356
|
+
const owns = (id: string) => ownerOf({ owners, views: state.views }, id) === windowId;
|
|
357
|
+
const seen = new Set<string>();
|
|
358
|
+
// A tab the window made has no id until it takes a state back; a sync sent
|
|
359
|
+
// before then carries it without one again. It is the window's tab of that
|
|
360
|
+
// name that it did not send by id, not one more tab.
|
|
361
|
+
const sentIds = new Set(after.config.layouts.flatMap((entry) => (entry.id ? [entry.id] : [])));
|
|
362
|
+
const unclaimed = state.config.layouts.filter((entry) => owns(layoutId(entry)) && !sentIds.has(layoutId(entry)));
|
|
363
|
+
const sentTabs = after.config.layouts.map((entry) => {
|
|
364
|
+
let id = entry.id && !seen.has(entry.id) ? entry.id : undefined;
|
|
365
|
+
if (!id && !entry.id) {
|
|
366
|
+
const claimed = unclaimed.findIndex((candidate) => candidate.name === entry.name && !seen.has(layoutId(candidate)));
|
|
367
|
+
if (claimed >= 0) id = layoutId(unclaimed.splice(claimed, 1)[0]!);
|
|
368
|
+
}
|
|
369
|
+
id ??= createSavedLayoutId();
|
|
370
|
+
seen.add(id);
|
|
371
|
+
return entry.id === id ? entry : { ...entry, id };
|
|
372
|
+
});
|
|
373
|
+
const sentActiveId = sentTabs[after.config.activeLayoutIndex]?.id;
|
|
374
|
+
const baseTabs = new Map(before.config.layouts.filter((entry) => entry.id).map((entry) => [entry.id!, entry] as const));
|
|
375
|
+
|
|
376
|
+
let layouts = state.config.layouts.filter((entry) => {
|
|
377
|
+
const id = layoutId(entry);
|
|
378
|
+
if (baseTabs.has(id) && !seen.has(id) && owns(id)) {
|
|
379
|
+
delete owners[id];
|
|
380
|
+
return false;
|
|
381
|
+
}
|
|
382
|
+
return true;
|
|
383
|
+
});
|
|
384
|
+
for (const tab of sentTabs) {
|
|
385
|
+
const id = layoutId(tab);
|
|
386
|
+
const index = layouts.findIndex((entry) => entry.id === id);
|
|
387
|
+
const previous = baseTabs.get(id);
|
|
388
|
+
if (index >= 0) {
|
|
389
|
+
if (!previous || !deepEqual(previous, tab)) layouts = layouts.map((entry, at) => (at === index ? tab : entry));
|
|
390
|
+
continue;
|
|
391
|
+
}
|
|
392
|
+
// Sent before, and gone from the shared state since: another window deleted it.
|
|
393
|
+
if (previous) continue;
|
|
394
|
+
let insertAt = layouts.length;
|
|
395
|
+
for (let at = layouts.length - 1; at >= 0; at -= 1) {
|
|
396
|
+
if (owns(layoutId(layouts[at]!))) {
|
|
397
|
+
insertAt = at + 1;
|
|
398
|
+
break;
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
layouts = [...layouts.slice(0, insertAt), tab, ...layouts.slice(insertAt)];
|
|
402
|
+
if (windowId !== MAIN_WINDOW_ID) owners[id] = windowId;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
layouts = inSentOrder(layouts, sentTabs.map(layoutId), owns);
|
|
406
|
+
|
|
407
|
+
const activeChanged = sentActiveId !== undefined && sentActiveId !== activeTabId(before) && owns(sentActiveId);
|
|
408
|
+
const activeLayoutId = activeChanged ? sentActiveId : view.activeLayoutId;
|
|
409
|
+
// Pane state and focus belong to a tab: a window that sent them for a tab it
|
|
410
|
+
// no longer shows (one just moved away) has them kept in that tab only.
|
|
411
|
+
const sameTab = sentActiveId === activeLayoutId;
|
|
412
|
+
const nextView: WindowView = {
|
|
413
|
+
activeLayoutId,
|
|
414
|
+
paneState: sameTab && (activeChanged || !deepEqual(after.paneState, before.paneState)) ? after.paneState : view.paneState,
|
|
415
|
+
focusedPaneId: sameTab && (activeChanged || after.focusedPaneId !== before.focusedPaneId) ? after.focusedPaneId : view.focusedPaneId,
|
|
416
|
+
statusBarVisible: after.statusBarVisible !== before.statusBarVisible ? after.statusBarVisible : view.statusBarVisible,
|
|
417
|
+
};
|
|
418
|
+
const brokerSyncErrors = deepEqual(after.brokerSyncErrors ?? {}, before.brokerSyncErrors ?? {})
|
|
419
|
+
? state.brokerSyncErrors
|
|
420
|
+
: { ...after.brokerSyncErrors };
|
|
421
|
+
|
|
422
|
+
return settle({
|
|
423
|
+
...state,
|
|
424
|
+
config: { ...config, layouts },
|
|
425
|
+
brokerSyncErrors,
|
|
426
|
+
owners,
|
|
427
|
+
views: { ...state.views, [windowId]: nextView },
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* Takes a whole config the backend changed (a broker profile, a popped-out
|
|
433
|
+
* window's frame), keeping which window shows which tab. Its active layout
|
|
434
|
+
* and pane state are the main window's.
|
|
435
|
+
*/
|
|
436
|
+
export function replaceSharedConfig(
|
|
437
|
+
state: WindowLayouts,
|
|
438
|
+
source: AppConfig,
|
|
439
|
+
main: Pick<WindowView, "paneState" | "focusedPaneId"> & Partial<Pick<WindowView, "statusBarVisible">>,
|
|
440
|
+
): WindowLayouts {
|
|
441
|
+
const config = ensureLayoutIds(syncConfigActiveLayoutState(source, main.paneState, main.focusedPaneId));
|
|
442
|
+
const previous = state.views[MAIN_WINDOW_ID]!;
|
|
443
|
+
const activeId = layoutId(config.layouts[config.activeLayoutIndex]!);
|
|
444
|
+
return settle({
|
|
445
|
+
...state,
|
|
446
|
+
config,
|
|
447
|
+
// A tab the backend made active in the main window is the main window's.
|
|
448
|
+
owners: Object.fromEntries(Object.entries(state.owners).filter(([id]) => id !== activeId)),
|
|
449
|
+
views: {
|
|
450
|
+
...state.views,
|
|
451
|
+
[MAIN_WINDOW_ID]: {
|
|
452
|
+
activeLayoutId: activeId,
|
|
453
|
+
paneState: main.paneState,
|
|
454
|
+
focusedPaneId: main.focusedPaneId,
|
|
455
|
+
statusBarVisible: main.statusBarVisible ?? previous.statusBarVisible,
|
|
456
|
+
},
|
|
457
|
+
},
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
/** Why a tab cannot go to a window, or null when it can. */
|
|
462
|
+
export function layoutMoveBlock(state: WindowLayouts, id: string, targetWindowId: string): "missing" | "same-window" | "last-main-tab" | null {
|
|
463
|
+
const source = windowOfLayout(state, id);
|
|
464
|
+
if (!source || (!state.views[targetWindowId] && targetWindowId !== MAIN_WINDOW_ID)) return "missing";
|
|
465
|
+
if (source === targetWindowId) return "same-window";
|
|
466
|
+
if (source === MAIN_WINDOW_ID && windowTabs(state, MAIN_WINDOW_ID).length <= 1) return "last-main-tab";
|
|
467
|
+
return null;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
/** Popped-out panes have a window of their own only in the main window: elsewhere they dock. */
|
|
471
|
+
function dockDetachedPanes(layout: LayoutConfig): LayoutConfig {
|
|
472
|
+
return layout.detached.reduce((next, entry) => dockPane(next, entry.instanceId), layout);
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* Moves a tab to another window, where it becomes the active tab. A window
|
|
477
|
+
* left without tabs closes; the main window keeps its last tab.
|
|
478
|
+
*/
|
|
479
|
+
export function moveLayoutToWindow(state: WindowLayouts, id: string, targetWindowId: string): WindowLayouts {
|
|
480
|
+
if (layoutMoveBlock(state, id, targetWindowId)) return state;
|
|
481
|
+
const target = state.views[targetWindowId]!;
|
|
482
|
+
let tab = state.config.layouts.find((entry) => entry.id === id)!;
|
|
483
|
+
if (targetWindowId !== MAIN_WINDOW_ID && tab.layout.detached.length > 0) {
|
|
484
|
+
tab = { ...tab, layout: dockDetachedPanes(tab.layout) };
|
|
485
|
+
}
|
|
486
|
+
const owners = { ...state.owners };
|
|
487
|
+
if (targetWindowId === MAIN_WINDOW_ID) delete owners[id];
|
|
488
|
+
else owners[id] = targetWindowId;
|
|
489
|
+
return settle({
|
|
490
|
+
...state,
|
|
491
|
+
config: { ...state.config, layouts: state.config.layouts.map((entry) => (entry.id === id ? tab : entry)) },
|
|
492
|
+
owners,
|
|
493
|
+
views: { ...state.views, [targetWindowId]: viewFromTab(tab, target.statusBarVisible) },
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
function uniqueTabName(layouts: readonly SavedLayout[], base: string): string {
|
|
498
|
+
const names = new Set(layouts.map((entry) => entry.name.toLowerCase()));
|
|
499
|
+
if (!names.has(base.toLowerCase())) return base;
|
|
500
|
+
let suffix = 2;
|
|
501
|
+
while (names.has(`${base} ${suffix}`.toLowerCase())) suffix += 1;
|
|
502
|
+
return `${base} ${suffix}`;
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
/**
|
|
506
|
+
* Opens a window. With a tab id it takes that tab; without one it starts on
|
|
507
|
+
* a new empty tab of its own. Returns the state unchanged when the tab cannot
|
|
508
|
+
* move (the main window's last tab).
|
|
509
|
+
*/
|
|
510
|
+
export function addWindow(state: WindowLayouts, windowId: string, options: { layoutId?: string } = {}): WindowLayouts {
|
|
511
|
+
if (state.views[windowId] || windowId === MAIN_WINDOW_ID) return state;
|
|
512
|
+
const statusBarVisible = state.views[MAIN_WINDOW_ID]!.statusBarVisible;
|
|
513
|
+
if (options.layoutId) {
|
|
514
|
+
if (layoutMoveBlock(state, options.layoutId, MAIN_WINDOW_ID) === "missing") return state;
|
|
515
|
+
const source = windowOfLayout(state, options.layoutId);
|
|
516
|
+
if (source === MAIN_WINDOW_ID && windowTabs(state, MAIN_WINDOW_ID).length <= 1) return state;
|
|
517
|
+
const placeholder: WindowView = { activeLayoutId: options.layoutId, paneState: {}, focusedPaneId: null, statusBarVisible };
|
|
518
|
+
return moveLayoutToWindow({
|
|
519
|
+
...state,
|
|
520
|
+
windowIds: [...state.windowIds, windowId],
|
|
521
|
+
views: { ...state.views, [windowId]: placeholder },
|
|
522
|
+
}, options.layoutId, windowId);
|
|
523
|
+
}
|
|
524
|
+
const tab: SavedLayout = {
|
|
525
|
+
id: createSavedLayoutId(),
|
|
526
|
+
name: uniqueTabName(state.config.layouts, "Layout"),
|
|
527
|
+
layout: createBlankLayout(),
|
|
528
|
+
paneState: {},
|
|
529
|
+
focusedPaneId: null,
|
|
530
|
+
};
|
|
531
|
+
return settle({
|
|
532
|
+
...state,
|
|
533
|
+
config: { ...state.config, layouts: [...state.config.layouts, tab] },
|
|
534
|
+
windowIds: [...state.windowIds, windowId],
|
|
535
|
+
views: { ...state.views, [windowId]: viewFromTab(tab, statusBarVisible) },
|
|
536
|
+
owners: { ...state.owners, [layoutId(tab)]: windowId },
|
|
537
|
+
});
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
/** Closes an extra window. Its tabs go back to the main window, where they were in the tab order; nothing is lost. */
|
|
541
|
+
export function closeWindow(state: WindowLayouts, windowId: string): WindowLayouts {
|
|
542
|
+
if (windowId === MAIN_WINDOW_ID || !state.views[windowId]) return state;
|
|
543
|
+
const { [windowId]: _closed, ...views } = state.views;
|
|
544
|
+
return settle({
|
|
545
|
+
...state,
|
|
546
|
+
windowIds: state.windowIds.filter((id) => id !== windowId),
|
|
547
|
+
views,
|
|
548
|
+
owners: Object.fromEntries(Object.entries(state.owners).filter(([, owner]) => owner !== windowId)),
|
|
549
|
+
});
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
/** Why a pane cannot go to a window, or null when it can. */
|
|
553
|
+
export function paneMoveBlock(state: WindowLayouts, paneId: string, targetWindowId: string): "missing" | "same-window" | null {
|
|
554
|
+
const located = locatePane(state, paneId);
|
|
555
|
+
if (!located || !state.views[targetWindowId]) return "missing";
|
|
556
|
+
if (located.windowId === targetWindowId) return "same-window";
|
|
557
|
+
return null;
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
/**
|
|
561
|
+
* Moves a pane into the active tab of another window, focused there. It keeps
|
|
562
|
+
* its id, settings, state and links: a pane that follows another keeps
|
|
563
|
+
* following it from the other window. A docked pane docks on the right; a
|
|
564
|
+
* floating one floats where it was.
|
|
565
|
+
*/
|
|
566
|
+
export function movePaneToWindow(state: WindowLayouts, paneId: string, targetWindowId: string): WindowLayouts {
|
|
567
|
+
if (paneMoveBlock(state, paneId, targetWindowId)) return state;
|
|
568
|
+
const located = locatePane(state, paneId)!;
|
|
569
|
+
const sourceView = state.views[located.windowId]!;
|
|
570
|
+
const targetView = state.views[targetWindowId]!;
|
|
571
|
+
const sourceTab = state.config.layouts.find((entry) => entry.id === located.layoutId)!;
|
|
572
|
+
const targetTab = state.config.layouts.find((entry) => entry.id === targetView.activeLayoutId)!;
|
|
573
|
+
const instance = findPaneInstance(sourceTab.layout, paneId)!;
|
|
574
|
+
const sourceIsLive = sourceView.activeLayoutId === located.layoutId;
|
|
575
|
+
const livePaneState = sourceIsLive ? sourceView.paneState[paneId] : undefined;
|
|
576
|
+
const paneState = livePaneState ?? sourceTab.paneState?.[paneId];
|
|
577
|
+
const floating = sourceTab.layout.floating.find((entry) => entry.instanceId === paneId);
|
|
578
|
+
|
|
579
|
+
const sourceLayout = removePane(sourceTab.layout, paneId);
|
|
580
|
+
const { [paneId]: _moved, ...sourcePaneState } = sourceTab.paneState ?? {};
|
|
581
|
+
const withInstance: LayoutConfig = {
|
|
582
|
+
...targetTab.layout,
|
|
583
|
+
instances: [...targetTab.layout.instances.filter((entry) => entry.instanceId !== paneId), { ...instance, movedFrom: undefined }],
|
|
584
|
+
};
|
|
585
|
+
const targetLayout = floating
|
|
586
|
+
? floatAtRect(withInstance, paneId, { x: floating.x, y: floating.y, width: floating.width, height: floating.height })
|
|
587
|
+
: insertAtRootEdge(withInstance, paneId, "right");
|
|
588
|
+
const targetPaneState = { ...targetTab.paneState, ...(paneState ? { [paneId]: paneState } : {}) };
|
|
589
|
+
|
|
590
|
+
const layouts = state.config.layouts.map((entry) => {
|
|
591
|
+
if (entry.id === sourceTab.id) {
|
|
592
|
+
return {
|
|
593
|
+
...entry,
|
|
594
|
+
layout: sourceLayout,
|
|
595
|
+
paneState: sourcePaneState,
|
|
596
|
+
focusedPaneId: entry.focusedPaneId === paneId ? null : entry.focusedPaneId,
|
|
597
|
+
};
|
|
598
|
+
}
|
|
599
|
+
if (entry.id === targetTab.id) return { ...entry, layout: targetLayout, paneState: targetPaneState, focusedPaneId: paneId };
|
|
600
|
+
return entry;
|
|
601
|
+
});
|
|
602
|
+
const { [paneId]: _live, ...sourceLivePaneState } = sourceView.paneState;
|
|
603
|
+
const views: Record<string, WindowView> = {
|
|
604
|
+
...state.views,
|
|
605
|
+
[located.windowId]: sourceIsLive
|
|
606
|
+
? {
|
|
607
|
+
...sourceView,
|
|
608
|
+
paneState: sourceLivePaneState,
|
|
609
|
+
focusedPaneId: sourceView.focusedPaneId === paneId ? null : sourceView.focusedPaneId,
|
|
610
|
+
}
|
|
611
|
+
: sourceView,
|
|
612
|
+
[targetWindowId]: {
|
|
613
|
+
...targetView,
|
|
614
|
+
paneState: { ...targetView.paneState, ...(paneState ? { [paneId]: paneState } : {}) },
|
|
615
|
+
focusedPaneId: paneId,
|
|
616
|
+
},
|
|
617
|
+
};
|
|
618
|
+
return settle({ ...state, config: { ...state.config, layouts }, views });
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
/** Switches a window to one of its tabs, as clicking the tab there would. */
|
|
622
|
+
export function activateLayout(state: WindowLayouts, windowId: string, id: string): WindowLayouts {
|
|
623
|
+
const view = state.views[windowId];
|
|
624
|
+
if (!view || view.activeLayoutId === id || windowOfLayout(state, id) !== windowId) return state;
|
|
625
|
+
const tab = state.config.layouts.find((entry) => entry.id === id)!;
|
|
626
|
+
return settle({
|
|
627
|
+
...state,
|
|
628
|
+
views: { ...state.views, [windowId]: viewFromTab(tab, view.statusBarVisible) },
|
|
629
|
+
});
|
|
630
|
+
}
|
|
@@ -1,24 +1,35 @@
|
|
|
1
1
|
import { createAnimationFrameDriver, installMarketDataFrameDriver, withLoadPacing } from "../../market-data/frame-scheduler";
|
|
2
2
|
import { setAppVisible } from "../../state/app/activity";
|
|
3
3
|
|
|
4
|
+
/** The window's own report of being minimized or shown, for a shell whose page is not always told. */
|
|
5
|
+
type NativeVisibilitySource = (listener: (visible: boolean) => void) => () => void;
|
|
6
|
+
|
|
4
7
|
/**
|
|
5
8
|
* DOM renderers (desktop windows and the web app) apply streamed data on
|
|
6
9
|
* animation frames, spaced out while the renders they set off are expensive,
|
|
7
10
|
* and pause market data while their document is hidden: a
|
|
8
11
|
* minimized window, a background tab, another desktop Space. Each desktop
|
|
9
|
-
* window has its own document, so a hidden
|
|
10
|
-
*
|
|
12
|
+
* window has its own document, so a hidden window pauses only its own
|
|
13
|
+
* streams; the data stays in the desktop process for the others. Some
|
|
14
|
+
* webviews keep a minimized window's page "visible", so the desktop shell
|
|
15
|
+
* also says when its window is minimized (`nativeVisibility`).
|
|
11
16
|
*/
|
|
12
|
-
export function installDomMarketDataFrames(): () => void {
|
|
17
|
+
export function installDomMarketDataFrames(nativeVisibility?: NativeVisibilitySource): () => void {
|
|
13
18
|
installMarketDataFrameDriver(withLoadPacing(createAnimationFrameDriver()));
|
|
14
19
|
const doc = (globalThis as { document?: Document }).document;
|
|
15
20
|
if (!doc || typeof doc.addEventListener !== "function") return () => {};
|
|
16
|
-
|
|
21
|
+
let nativeVisible = true;
|
|
22
|
+
const syncVisibility = () => setAppVisible(nativeVisible && doc.visibilityState !== "hidden");
|
|
17
23
|
doc.addEventListener("visibilitychange", syncVisibility);
|
|
18
24
|
globalThis.addEventListener?.("pageshow", syncVisibility);
|
|
25
|
+
const stopNative = nativeVisibility?.((visible) => {
|
|
26
|
+
nativeVisible = visible;
|
|
27
|
+
syncVisibility();
|
|
28
|
+
});
|
|
19
29
|
syncVisibility();
|
|
20
30
|
return () => {
|
|
21
31
|
doc.removeEventListener("visibilitychange", syncVisibility);
|
|
22
32
|
globalThis.removeEventListener?.("pageshow", syncVisibility);
|
|
33
|
+
stopNative?.();
|
|
23
34
|
};
|
|
24
35
|
}
|
|
@@ -225,7 +225,6 @@ export function WebIconButton({
|
|
|
225
225
|
disabled = false,
|
|
226
226
|
size = 12,
|
|
227
227
|
stopPropagation = true,
|
|
228
|
-
text,
|
|
229
228
|
}: IconButtonProps) {
|
|
230
229
|
return (
|
|
231
230
|
<button
|
|
@@ -262,7 +261,6 @@ export function WebIconButton({
|
|
|
262
261
|
}}
|
|
263
262
|
>
|
|
264
263
|
<WebIcon name={icon} size={size} />
|
|
265
|
-
{text ? <span className="gloom-icon-button-text">{text}</span> : null}
|
|
266
264
|
</button>
|
|
267
265
|
);
|
|
268
266
|
}
|