@gloom-sh/terminal 0.20.10 → 0.20.12
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 +2 -1
- package/patches/@opentui%2Fcore@0.3.2.patch +16 -0
- package/src/api-client/awards.ts +16 -0
- package/src/api-client/central-bank-rates.ts +5 -0
- package/src/api-client/data.ts +55 -2
- package/src/api-client/index.ts +18 -1
- package/src/api-client/request.ts +86 -3
- package/src/api-client/socket-connection.ts +366 -0
- package/src/api-client/socket-features.ts +75 -0
- package/src/api-client/socket-frames.ts +161 -0
- package/src/api-client/socket-listeners.ts +207 -0
- package/src/api-client/socket-quotes.ts +332 -0
- package/src/api-client/socket.ts +168 -983
- package/src/api-client/supply-chain-graph.ts +4 -2
- package/src/api-client/supply-chain.ts +8 -0
- package/src/api-client/types/econ.ts +10 -7
- package/src/api-client/types/filings-and-calls.ts +8 -0
- package/src/app/global-shortcuts.ts +2 -1
- package/src/app/keybindings/actions.ts +19 -0
- package/src/app/pane-runtime/index.tsx +18 -3
- package/src/app/pane-runtime/layout-placement.ts +63 -0
- package/src/app/pane-runtime/ticker-open-runtime.ts +10 -2
- package/src/brokers/signed-in/adapter.ts +19 -5
- package/src/brokers/signed-in/client.ts +13 -1
- package/src/brokers/signed-in/sign-in-dialog.tsx +33 -9
- package/src/capabilities/chart-series.ts +4 -1
- package/src/cli/board-coins.ts +10 -1
- package/src/cli/commands/crypto-hints.ts +3 -2
- package/src/cli/commands/fred-series.ts +0 -54
- package/src/cli/commands/market.ts +209 -31
- package/src/cli/commands/overview.ts +47 -14
- package/src/cli/commands/search.ts +37 -8
- package/src/cli/commands/ticker.ts +15 -4
- package/src/cli/desktop-pane-shot.ts +27 -2
- package/src/cli/fx-quote-rate.ts +1 -1
- package/src/cli/glossary.ts +14 -5
- package/src/cli/history-catalog-series.ts +85 -0
- package/src/cli/index.ts +1 -1
- package/src/cli/list-progress.ts +45 -0
- package/src/cli/listing-arg.ts +71 -7
- package/src/cli/name-entries.ts +8 -4
- package/src/cli/not-a-ticker.ts +2 -2
- package/src/cli/pane-functions/freshness.ts +50 -3
- package/src/cli/pane-functions/index.ts +7 -4
- package/src/cli/pane-functions/market-session.ts +66 -14
- package/src/cli/pane-functions/options.ts +5 -0
- package/src/cli/pane-functions/resolver.ts +9 -2
- package/src/cli/pane-functions/screenshot-assessment.ts +28 -3
- package/src/cli/pane-functions/screenshot-types.ts +6 -0
- package/src/cli/quote-answer.ts +49 -10
- package/src/cli/quote-list-reads.ts +87 -0
- package/src/cli/report-tables.ts +70 -13
- package/src/cli/result.ts +24 -2
- package/src/cli/symbol-list.ts +31 -4
- package/src/cli/terminal-code-hints.ts +83 -0
- package/src/cli/ticker-resolution.ts +2 -1
- package/src/cli/treasury-yields.ts +5 -0
- package/src/components/chart/native/kitty/manager.ts +2 -0
- package/src/components/chart/native/surface/manager.ts +211 -11
- package/src/components/command-bar/action-runtime.ts +2 -0
- package/src/components/command-bar/panel/index.tsx +2 -13
- package/src/components/command-bar/panel/layout.ts +1 -7
- package/src/components/command-bar/panel/runtime.ts +0 -1
- package/src/components/command-bar/panel/types.ts +0 -2
- package/src/components/command-bar/routing/launch-request.ts +2 -1
- package/src/components/command-bar/routing/navigation-state.ts +4 -2
- package/src/components/command-bar/workflow/types.ts +6 -0
- package/src/components/data-table/column-menu.tsx +89 -0
- package/src/components/data-table/sort-menu.tsx +9 -2
- package/src/components/data-table/view.tsx +33 -6
- package/src/components/form-modal/content.tsx +10 -0
- package/src/components/index.ts +1 -1
- package/src/components/layout/detached-pane-shell.tsx +3 -0
- package/src/components/layout/double-escape-close.ts +34 -3
- package/src/components/layout/floating-pane.tsx +10 -4
- package/src/components/layout/pane/cycle-order.ts +66 -2
- package/src/components/layout/pane/footer/index.tsx +25 -11
- package/src/components/layout/pane/footer/model.ts +62 -20
- package/src/components/layout/pane/header.tsx +140 -31
- package/src/components/layout/pane/sidebar.tsx +138 -20
- package/src/components/layout/pane/status-footer.ts +3 -1
- package/src/components/layout/shell/active-drag.ts +18 -13
- package/src/components/layout/shell/drag/magnets.ts +34 -18
- package/src/components/layout/shell/drag/runtime.ts +5 -0
- package/src/components/layout/shell/index.tsx +25 -0
- package/src/components/layout/shell/menu.ts +9 -0
- package/src/components/layout/shell/pane/actions.ts +36 -0
- package/src/components/layout/shell/pane/management-shortcuts.ts +27 -3
- package/src/components/layout/shell/pane-occlusion.ts +40 -0
- package/src/components/layout/shell/shortcuts.ts +17 -1
- package/src/components/layout/shell/terminal-pointer-runtime.ts +39 -6
- package/src/components/layout/shell/window-mode/index.ts +5 -16
- package/src/components/layout/shell/window-mode/overlays.tsx +3 -1
- package/src/components/market-board/index.tsx +14 -5
- package/src/components/metric-treemap/index.tsx +3 -1
- package/src/components/ticker/list-table-view.tsx +5 -0
- package/src/components/ui/button.tsx +48 -4
- package/src/components/ui/data-table/column-order.ts +180 -0
- package/src/components/ui/data-table/index.tsx +12 -1
- package/src/components/ui/data-table/opentui/index.tsx +291 -32
- package/src/components/ui/data-table/opentui/model.ts +43 -4
- package/src/components/ui/data-table/types.ts +56 -0
- package/src/components/ui/data-table/use-column-order.ts +135 -0
- package/src/components/ui/index.ts +1 -1
- package/src/components/ui/inline-quick-add.tsx +19 -3
- package/src/components/ui/list-view.tsx +11 -5
- package/src/components/ui/query-bar.tsx +16 -1
- package/src/components/ui/selection-fill.ts +39 -0
- package/src/components/ui/table-layout.ts +120 -0
- package/src/core/state/app/layout-reducer.ts +2 -1
- package/src/core/state/app/pane-choices.ts +68 -0
- package/src/core/state/app/state.ts +14 -6
- package/src/core/state/app/types.ts +8 -0
- package/src/docs/snapshot.json +3 -2
- package/src/i18n/es.ts +2 -0
- package/src/i18n/ja.ts +2 -0
- package/src/i18n/ko.ts +2 -0
- package/src/i18n/zh-cn.ts +2 -0
- package/src/i18n/zh-tw.ts +2 -0
- package/src/layout/pane-manager/dock-tree.ts +19 -0
- package/src/layout/pane-manager/index.ts +3 -0
- package/src/market-data/coordinator/index.ts +4 -3
- package/src/market-data/coordinator/quotes.ts +12 -4
- package/src/market-data/market/freshness.ts +33 -0
- package/src/market-data/market/status.ts +5 -1
- package/src/market-data/quotes/contributions.ts +10 -0
- package/src/market-data/quotes/freshness.ts +31 -0
- package/src/market-data/quotes/live-valuation.ts +32 -5
- package/src/market-data/quotes/regular-session-valuation.ts +1 -1
- package/src/market-data/quotes/resolution.ts +4 -0
- package/src/market-data/quotes/time.ts +0 -14
- package/src/plugins/builtin/account-management/index.tsx +1 -0
- package/src/plugins/builtin/awards/detail.tsx +12 -4
- package/src/plugins/builtin/awards/headless.ts +29 -8
- package/src/plugins/builtin/awards/model.ts +36 -2
- package/src/plugins/builtin/awards/pane.tsx +7 -4
- package/src/plugins/builtin/broker-manager/detail.tsx +5 -3
- package/src/plugins/builtin/broker-manager/index.tsx +7 -6
- package/src/plugins/builtin/broker-manager/model.ts +15 -6
- package/src/plugins/builtin/broker-manager/pane-actions.tsx +11 -4
- package/src/plugins/builtin/broker-manager/sign-in-end.ts +50 -19
- package/src/plugins/builtin/broker-manager/table.ts +10 -4
- package/src/plugins/builtin/broker-trading/index.tsx +1 -1
- package/src/plugins/builtin/central-bank-rates/headless.ts +6 -6
- package/src/plugins/builtin/central-bank-rates/index.tsx +1 -1
- package/src/plugins/builtin/central-bank-rates/model.ts +21 -3
- package/src/plugins/builtin/central-bank-rates/pane.tsx +15 -5
- package/src/plugins/builtin/chart-composer/headless.ts +5 -1
- package/src/plugins/builtin/chart-composer/pane.tsx +1 -0
- package/src/plugins/builtin/chat/content/handle-prompt.tsx +4 -0
- package/src/plugins/builtin/chat/controller/realtime.ts +17 -1
- package/src/plugins/builtin/chat/message/terminal.tsx +4 -1
- package/src/plugins/builtin/chat/sidebar.tsx +35 -19
- package/src/plugins/builtin/cloud/askg/pane.tsx +4 -0
- package/src/plugins/builtin/cloud/askg/tool-timeline.tsx +2 -0
- package/src/plugins/builtin/cloud/plugin.tsx +1 -0
- package/src/plugins/builtin/cloud/team/module.tsx +1 -0
- package/src/plugins/builtin/cloud/thesis/detail.tsx +9 -4
- package/src/plugins/builtin/commodity-balances/pane.tsx +13 -5
- package/src/plugins/builtin/company-kpis/model.ts +3 -3
- package/src/plugins/builtin/connections/index.ts +1 -0
- package/src/plugins/builtin/credit-boards/cdx-pane.tsx +9 -5
- package/src/plugins/builtin/credit-boards/client.ts +5 -0
- package/src/plugins/builtin/credit-boards/headless.ts +1 -6
- package/src/plugins/builtin/credit-boards/model.ts +0 -6
- package/src/plugins/builtin/credit-boards/series.ts +19 -8
- package/src/plugins/builtin/credit-boards/sovr-pane.tsx +9 -5
- package/src/plugins/builtin/crypto-etf-flows/headless.ts +23 -13
- package/src/plugins/builtin/crypto-etf-flows/pane.tsx +8 -3
- package/src/plugins/builtin/debt-maturities/headless.ts +16 -7
- package/src/plugins/builtin/debt-maturities/model.ts +9 -15
- package/src/plugins/builtin/debt-maturities/pane.tsx +9 -10
- package/src/plugins/builtin/earnings/board-model.ts +33 -4
- package/src/plugins/builtin/earnings/board.tsx +15 -3
- package/src/plugins/builtin/earnings/calendar.tsx +10 -6
- package/src/plugins/builtin/earnings/client.ts +0 -9
- package/src/plugins/builtin/earnings/headless.ts +10 -7
- package/src/plugins/builtin/earnings/history.tsx +21 -14
- package/src/plugins/builtin/earnings-calls/data.ts +24 -4
- package/src/plugins/builtin/earnings-calls/format.ts +23 -5
- package/src/plugins/builtin/earnings-calls/headless.ts +23 -3
- package/src/plugins/builtin/earnings-calls/index.tsx +1 -0
- package/src/plugins/builtin/earnings-calls/model.ts +11 -1
- package/src/plugins/builtin/earnings-calls/pane.tsx +2 -5
- package/src/plugins/builtin/econ/calendar-model.ts +27 -0
- package/src/plugins/builtin/econ/fred-catalog.ts +3 -0
- package/src/plugins/builtin/econ/index.tsx +9 -2
- package/src/plugins/builtin/econ-statistics/headless.ts +3 -1
- package/src/plugins/builtin/econ-statistics/index.tsx +1 -1
- package/src/plugins/builtin/equity-screener/live.ts +74 -18
- package/src/plugins/builtin/equity-screener/model.ts +19 -4
- package/src/plugins/builtin/equity-screener/pane.tsx +19 -14
- package/src/plugins/builtin/equity-screener/refresh-anchor.ts +45 -0
- package/src/plugins/builtin/equity-screener/results.ts +22 -2
- package/src/plugins/builtin/equity-screener/screen-check.ts +9 -3
- package/src/plugins/builtin/fear-greed/headless.ts +16 -13
- package/src/plugins/builtin/fear-greed/pane.tsx +12 -4
- package/src/plugins/builtin/filing-events/index.tsx +1 -0
- package/src/plugins/builtin/futures/index.tsx +15 -1
- package/src/plugins/builtin/futures/table.tsx +1 -1
- package/src/plugins/builtin/fx-matrix/index.tsx +32 -19
- package/src/plugins/builtin/holders/pane.tsx +30 -20
- package/src/plugins/builtin/insider/table.tsx +10 -7
- package/src/plugins/builtin/insider/tickers.tsx +1 -1
- package/src/plugins/builtin/iv-history/events.ts +5 -0
- package/src/plugins/builtin/iv-history/headless.ts +15 -9
- package/src/plugins/builtin/jobs/index.tsx +1 -0
- package/src/plugins/builtin/kelly-sizer/sections.tsx +2 -0
- package/src/plugins/builtin/macro-day/headless.ts +15 -6
- package/src/plugins/builtin/macro-day/model.ts +1 -1
- package/src/plugins/builtin/macro-day/releases.ts +25 -16
- package/src/plugins/builtin/market-movers/index.tsx +20 -8
- package/src/plugins/builtin/market-movers/model.ts +5 -0
- package/src/plugins/builtin/market-movers/session-body.tsx +2 -1
- package/src/plugins/builtin/money-markets/headless.ts +12 -2
- package/src/plugins/builtin/money-markets/pane.tsx +10 -1
- package/src/plugins/builtin/options/view.tsx +3 -0
- package/src/plugins/builtin/options-positioning/pane.tsx +1 -1
- package/src/plugins/builtin/options-scenario/pane.tsx +2 -1
- package/src/plugins/builtin/perps/cascade-tabs.tsx +2 -1
- package/src/plugins/builtin/portfolio-list/cli/bulk-symbols.ts +4 -31
- package/src/plugins/builtin/portfolio-list/pane/index.tsx +19 -1
- package/src/plugins/builtin/portfolio-list/quick-add/index.tsx +22 -8
- package/src/plugins/builtin/portfolio-list/summary/index.tsx +6 -8
- package/src/plugins/builtin/portfolio-list/table.tsx +15 -1
- package/src/plugins/builtin/rate-path/pane.tsx +2 -0
- package/src/plugins/builtin/realized-vol/headless.ts +28 -2
- package/src/plugins/builtin/revenue-breakdown/pane.tsx +2 -0
- package/src/plugins/builtin/reverse-dcf/pane.tsx +2 -1
- package/src/plugins/builtin/risk-factors/index.tsx +1 -0
- package/src/plugins/builtin/seasonality/pane.tsx +2 -1
- package/src/plugins/builtin/shared/source-footer.ts +70 -0
- package/src/plugins/builtin/short-interest/publications-pane.tsx +5 -1
- package/src/plugins/builtin/short-volume/pane.tsx +5 -1
- package/src/plugins/builtin/social-mentions/outliers.tsx +10 -1
- package/src/plugins/builtin/social-mentions/pane.tsx +7 -0
- package/src/plugins/builtin/supply-chain/client.ts +3 -1
- package/src/plugins/builtin/supply-chain/flow.tsx +25 -8
- package/src/plugins/builtin/supply-chain/graph-client.ts +1 -1
- package/src/plugins/builtin/supply-chain/graph-evidence.ts +1 -1
- package/src/plugins/builtin/supply-chain/graph-model.ts +12 -1
- package/src/plugins/builtin/supply-chain/graph-pane.tsx +9 -8
- package/src/plugins/builtin/supply-chain/graph.tsx +12 -6
- package/src/plugins/builtin/supply-chain/headless.ts +13 -7
- package/src/plugins/builtin/supply-chain/model.ts +68 -11
- package/src/plugins/builtin/supply-chain/pane.tsx +9 -6
- package/src/plugins/builtin/supply-chain/row-evidence.tsx +5 -5
- package/src/plugins/builtin/thirteenf/pane.tsx +2 -0
- package/src/plugins/builtin/ticker-detail/financials/model.ts +28 -6
- package/src/plugins/builtin/ticker-detail/financials/ratio-table.tsx +26 -9
- package/src/plugins/builtin/ticker-detail/financials/tab.tsx +58 -35
- package/src/plugins/builtin/ticker-detail/overview/components.tsx +14 -1
- package/src/plugins/builtin/ticker-detail/overview-tab.tsx +2 -0
- package/src/plugins/builtin/ticker-detail/pane.tsx +48 -24
- package/src/plugins/builtin/ticker-detail/quote-footer.ts +5 -0
- package/src/plugins/builtin/ticker-detail/quote-monitor/card.tsx +6 -3
- package/src/plugins/builtin/treasury-auctions/after.ts +50 -23
- package/src/plugins/builtin/treasury-auctions/cache.ts +23 -5
- package/src/plugins/builtin/treasury-auctions/headless.ts +226 -37
- package/src/plugins/builtin/treasury-auctions/hk-headless.ts +11 -5
- package/src/plugins/builtin/treasury-auctions/hk-view.tsx +27 -25
- package/src/plugins/builtin/treasury-auctions/hk.ts +60 -8
- package/src/plugins/builtin/treasury-auctions/index.tsx +3 -0
- package/src/plugins/builtin/treasury-auctions/keys.ts +27 -0
- package/src/plugins/builtin/treasury-auctions/like.ts +137 -0
- package/src/plugins/builtin/treasury-auctions/model.ts +100 -22
- package/src/plugins/builtin/treasury-auctions/pane.tsx +39 -11
- package/src/plugins/builtin/vol-surface/heat-grid.tsx +6 -3
- package/src/plugins/builtin/vol-surface/pane.tsx +7 -3
- package/src/plugins/builtin/world-indices/index.tsx +5 -1
- package/src/plugins/builtin/yield-curve/index.tsx +2 -1
- package/src/plugins/runtime/index.tsx +1 -0
- package/src/plugins/runtime/state.ts +20 -0
- package/src/portfolio/column-values.ts +8 -2
- package/src/public/__snapshots__/public-api.test.ts.snap +5 -0
- package/src/public/react.ts +7 -0
- package/src/react/auto-refresh.ts +29 -0
- package/src/renderers/browser/deeplink-bridge.ts +24 -3
- package/src/renderers/dom/data-table/column-drag.ts +147 -0
- package/src/renderers/dom/data-table/index.tsx +22 -0
- package/src/renderers/dom/data-table/row.tsx +27 -5
- package/src/renderers/dom/desktop/query-bar.tsx +229 -60
- package/src/renderers/dom/host/overflow-fade-px.ts +2 -0
- package/src/renderers/dom/host/overflow-fade.ts +1 -2
- package/src/renderers/dom/styles.css +47 -5
- package/src/renderers/electrobun/view/cli-pane-shot-entry.tsx +2 -1
- package/src/renderers/opentui/chart-surface.tsx +1 -0
- package/src/renderers/opentui/frame-hits.ts +33 -0
- package/src/renderers/opentui/host.tsx +2 -0
- package/src/renderers/opentui/native-surface.ts +14 -21
- package/src/renderers/opentui/test-utils.tsx +3 -0
- package/src/series/types.ts +2 -0
- package/src/sources/gloomberb-cloud/fred-attribution.ts +86 -0
- package/src/sources/gloomberb-cloud/index.ts +25 -1
- package/src/sources/gloomberb-cloud/normalizers.ts +22 -3
- package/src/sources/provider-errors.ts +64 -1
- package/src/sources/provider-router/batches.ts +19 -0
- package/src/sources/provider-router/index.ts +7 -1
- package/src/state/app/context/index.tsx +46 -1
- package/src/state/pane-unsent-work.ts +47 -0
- package/src/test-support/app-store.ts +24 -1
- package/src/test-support/shell-pane-keys.tsx +5 -0
- package/src/test-support/telemetry-guard.ts +83 -0
- package/src/test-support/test-env.ts +12 -0
- package/src/theme/colors.ts +17 -1
- package/src/theme/ui-tokens.ts +50 -1
- package/src/tickers/listing-venues.ts +11 -1
- package/src/tickers/search/japanese-names.json +1 -0
- package/src/tickers/search/japanese-names.ts +152 -0
- package/src/tickers/terminal-codes.ts +55 -6
- package/src/time-series/base-series.ts +3 -0
- package/src/time-series/live-quotes.ts +3 -9
- package/src/types/data-provider.ts +6 -0
- package/src/types/financials.ts +11 -0
- package/src/types/plugin-contributions.ts +7 -0
- package/src/types/plugin-panes.ts +7 -0
- package/src/ui/host.tsx +24 -0
- package/src/ui/pointer-drag.ts +11 -2
- package/src/utils/double-escape-close.ts +42 -0
- package/src/utils/fundamentals.ts +14 -3
- package/src/utils/fx-status.ts +30 -7
- package/src/utils/network-failure.ts +23 -0
- package/src/utils/share-multiples.cases.json +780 -2
- package/src/utils/share-multiples.ts +154 -24
|
@@ -122,7 +122,9 @@ export class KittyImageManager {
|
|
|
122
122
|
this.lastPlacementKeys = placements.map(serializePlacement);
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
+
/** Deletes the image on screen, once: a chart hidden or covered every frame writes nothing more. */
|
|
125
126
|
clear() {
|
|
127
|
+
if (this.activeSlot === null) return;
|
|
126
128
|
writeRendererRaw(
|
|
127
129
|
this.renderer,
|
|
128
130
|
`${encodeKittyDeleteImage(this.imageIds[0])}${encodeKittyDeleteImage(this.imageIds[1])}`,
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
type NativeChartBitmap,
|
|
9
9
|
} from "../chart-rasterizer";
|
|
10
10
|
import { KittyImageManager } from "../kitty/manager";
|
|
11
|
+
import { getRenderableCellRect, resolveNativeSurfaceVisibleRect, type NativeSurfaceRenderableNode } from "./visibility";
|
|
11
12
|
|
|
12
13
|
export interface NativePaneLayer {
|
|
13
14
|
paneId: string;
|
|
@@ -29,6 +30,28 @@ export interface NativeLocalOccluder {
|
|
|
29
30
|
rect: CellRect;
|
|
30
31
|
}
|
|
31
32
|
|
|
33
|
+
export interface CellInsets {
|
|
34
|
+
top: number;
|
|
35
|
+
right: number;
|
|
36
|
+
bottom: number;
|
|
37
|
+
left: number;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The box an image draws over. After every frame the terminal shows, the
|
|
42
|
+
* image is measured again from it and kept off every cell something else drew
|
|
43
|
+
* on top of it, so it follows the layout, scrolling and clipping of that frame,
|
|
44
|
+
* goes when the box leaves the screen, and never shows over a window, menu,
|
|
45
|
+
* bar or toast that covers it.
|
|
46
|
+
*/
|
|
47
|
+
export interface NativeSurfaceAnchor {
|
|
48
|
+
renderable: NativeSurfaceRenderableNode;
|
|
49
|
+
/** Cells kept clear inside the box, as a border or padding does. */
|
|
50
|
+
insets?: CellInsets;
|
|
51
|
+
/** Part of the inset box, from its top-left cell: a crosshair strip over its chart. */
|
|
52
|
+
region?: CellRect;
|
|
53
|
+
}
|
|
54
|
+
|
|
32
55
|
export interface NativeSurfaceSnapshot {
|
|
33
56
|
id: string;
|
|
34
57
|
paneId: string;
|
|
@@ -38,6 +61,7 @@ export interface NativeSurfaceSnapshot {
|
|
|
38
61
|
bitmapKey: string;
|
|
39
62
|
/** Kitty stacking order; defaults to the plot layer. */
|
|
40
63
|
imageZIndex?: number;
|
|
64
|
+
anchor?: NativeSurfaceAnchor;
|
|
41
65
|
}
|
|
42
66
|
|
|
43
67
|
interface SurfaceEntry {
|
|
@@ -89,15 +113,150 @@ function sameWindowState(a: NativeWindowState, b: NativeWindowState): boolean {
|
|
|
89
113
|
return true;
|
|
90
114
|
}
|
|
91
115
|
|
|
116
|
+
function sameInsets(a: CellInsets | undefined, b: CellInsets | undefined): boolean {
|
|
117
|
+
if (a === b) return true;
|
|
118
|
+
if (!a || !b) return false;
|
|
119
|
+
return a.top === b.top && a.right === b.right && a.bottom === b.bottom && a.left === b.left;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function sameAnchor(a: NativeSurfaceAnchor | undefined, b: NativeSurfaceAnchor | undefined): boolean {
|
|
123
|
+
if (a === b) return true;
|
|
124
|
+
if (!a || !b) return false;
|
|
125
|
+
return a.renderable === b.renderable
|
|
126
|
+
&& sameInsets(a.insets, b.insets)
|
|
127
|
+
&& sameCellRect(a.region ?? null, b.region ?? null);
|
|
128
|
+
}
|
|
129
|
+
|
|
92
130
|
function sameSnapshot(a: NativeSurfaceSnapshot, b: NativeSurfaceSnapshot): boolean {
|
|
93
131
|
return a.id === b.id
|
|
94
132
|
&& a.paneId === b.paneId
|
|
95
133
|
&& a.bitmapKey === b.bitmapKey
|
|
96
134
|
&& a.imageZIndex === b.imageZIndex
|
|
135
|
+
&& sameAnchor(a.anchor, b.anchor)
|
|
97
136
|
&& sameCellRect(a.rect, b.rect)
|
|
98
137
|
&& sameCellRect(a.visibleRect, b.visibleRect);
|
|
99
138
|
}
|
|
100
139
|
|
|
140
|
+
export function insetCellRect(rect: CellRect, insets: CellInsets | undefined): CellRect | null {
|
|
141
|
+
if (!insets) return rect;
|
|
142
|
+
const width = rect.width - insets.left - insets.right;
|
|
143
|
+
const height = rect.height - insets.top - insets.bottom;
|
|
144
|
+
if (width <= 0 || height <= 0) return null;
|
|
145
|
+
return { x: rect.x + insets.left, y: rect.y + insets.top, width, height };
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Where an anchored image is in the frame just drawn: its box (or the part of
|
|
150
|
+
* it the region names) and the cells of it its ancestors leave on screen, none
|
|
151
|
+
* once the box is hidden, destroyed or out of the tree.
|
|
152
|
+
*/
|
|
153
|
+
function measureNativeSurfaceAnchor(
|
|
154
|
+
anchor: NativeSurfaceAnchor,
|
|
155
|
+
terminalWidth: number,
|
|
156
|
+
terminalHeight: number,
|
|
157
|
+
attached: (renderable: unknown) => boolean,
|
|
158
|
+
): { rect: CellRect; visibleRect: CellRect | null } | null {
|
|
159
|
+
const box = insetCellRect(getRenderableCellRect(anchor.renderable), anchor.insets);
|
|
160
|
+
if (!box) return null;
|
|
161
|
+
const rect = anchor.region
|
|
162
|
+
? { x: box.x + anchor.region.x, y: box.y + anchor.region.y, width: anchor.region.width, height: anchor.region.height }
|
|
163
|
+
: box;
|
|
164
|
+
if (!attached(anchor.renderable)) return { rect, visibleRect: null };
|
|
165
|
+
const outer = resolveNativeSurfaceVisibleRect(anchor.renderable, terminalWidth, terminalHeight);
|
|
166
|
+
return { rect, visibleRect: outer ? intersectCellRects(rect, outer) : null };
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** The renderable a pane window carries its pane id on. */
|
|
170
|
+
const PANE_ID_PROPERTY = "data-gloom-pane-id";
|
|
171
|
+
const MAX_ANCESTOR_DEPTH = 256;
|
|
172
|
+
/** More pieces than this means something scattered covers the image: it is hidden instead. */
|
|
173
|
+
const MAX_UNCOVERED_FRAGMENTS = 128;
|
|
174
|
+
|
|
175
|
+
type ParentedNode = { parent?: unknown } | null | undefined;
|
|
176
|
+
|
|
177
|
+
function parentOf(node: unknown): unknown {
|
|
178
|
+
return node && typeof node === "object" ? (node as ParentedNode)?.parent ?? null : null;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Whether a renderable the frame drew on top of an anchored image covers it.
|
|
183
|
+
* The image's own pane draws over its charts on purpose (legends, toolbars,
|
|
184
|
+
* axis labels): only its explicit local occluders cut those. Anything else
|
|
185
|
+
* covers the image where it or a box it sits in fills its cells, up to the
|
|
186
|
+
* first box the image also sits in: a window, a menu, a bar, a toast. A
|
|
187
|
+
* see-through layer (a click catcher) does not, and text without a background
|
|
188
|
+
* draws over the image anyway.
|
|
189
|
+
*/
|
|
190
|
+
function createCoverTest(
|
|
191
|
+
anchor: NativeSurfaceRenderableNode,
|
|
192
|
+
paints: (renderable: unknown) => boolean,
|
|
193
|
+
): (hit: unknown) => boolean {
|
|
194
|
+
// The image's ancestors up to its pane window hold its own pane's drawing;
|
|
195
|
+
// the ones above it hold everything else.
|
|
196
|
+
const chain: unknown[] = [];
|
|
197
|
+
let home = -1;
|
|
198
|
+
let node = parentOf(anchor);
|
|
199
|
+
for (let depth = 0; node && depth < MAX_ANCESTOR_DEPTH; depth += 1) {
|
|
200
|
+
chain.push(node);
|
|
201
|
+
if (home < 0 && typeof (node as Record<string, unknown>)[PANE_ID_PROPERTY] === "string") home = chain.length - 1;
|
|
202
|
+
node = parentOf(node);
|
|
203
|
+
}
|
|
204
|
+
// Outside any pane, what the image's own component draws beside it is its own.
|
|
205
|
+
if (home < 0) home = chain.length > 0 ? 0 : -1;
|
|
206
|
+
const own = new Set<unknown>([anchor, ...chain.slice(0, home + 1)]);
|
|
207
|
+
const shared = new Set<unknown>(chain.slice(home + 1));
|
|
208
|
+
const known = new Map<unknown, boolean>();
|
|
209
|
+
return (hit) => {
|
|
210
|
+
if (hit == null || hit === anchor) return false;
|
|
211
|
+
const cached = known.get(hit);
|
|
212
|
+
if (cached !== undefined) return cached;
|
|
213
|
+
let covers = false;
|
|
214
|
+
let current: unknown = hit;
|
|
215
|
+
for (let depth = 0; current && depth < MAX_ANCESTOR_DEPTH; depth += 1) {
|
|
216
|
+
if (own.has(current)) {
|
|
217
|
+
covers = false;
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
if (shared.has(current)) break;
|
|
221
|
+
if (paints(current)) covers = true;
|
|
222
|
+
current = parentOf(current);
|
|
223
|
+
}
|
|
224
|
+
known.set(hit, covers);
|
|
225
|
+
return covers;
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* The cells of `rect` nothing covers, as rectangles: runs of uncovered cells
|
|
231
|
+
* row by row, a run that lines up with the one above it extending it down.
|
|
232
|
+
*/
|
|
233
|
+
function uncoveredCellRects(rect: CellRect, covered: (x: number, y: number) => boolean): CellRect[] {
|
|
234
|
+
const done: CellRect[] = [];
|
|
235
|
+
let open: CellRect[] = [];
|
|
236
|
+
const right = rect.x + rect.width;
|
|
237
|
+
for (let y = rect.y; y < rect.y + rect.height; y += 1) {
|
|
238
|
+
const next: CellRect[] = [];
|
|
239
|
+
let start = -1;
|
|
240
|
+
for (let x = rect.x; x <= right; x += 1) {
|
|
241
|
+
const free = x < right && !covered(x, y);
|
|
242
|
+
if (free && start < 0) start = x;
|
|
243
|
+
if (!free && start >= 0) {
|
|
244
|
+
const above = open.find((candidate) => candidate.x === start && candidate.x + candidate.width === x);
|
|
245
|
+
if (above) {
|
|
246
|
+
above.height += 1;
|
|
247
|
+
next.push(above);
|
|
248
|
+
} else {
|
|
249
|
+
next.push({ x: start, y, width: x - start, height: 1 });
|
|
250
|
+
}
|
|
251
|
+
start = -1;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
for (const candidate of open) if (!next.includes(candidate)) done.push(candidate);
|
|
255
|
+
open = next;
|
|
256
|
+
}
|
|
257
|
+
return [...done, ...open];
|
|
258
|
+
}
|
|
259
|
+
|
|
101
260
|
export function computeSurfaceVisibleFragments(
|
|
102
261
|
rect: CellRect,
|
|
103
262
|
visibleRect: CellRect | null,
|
|
@@ -126,7 +285,16 @@ export class NativeSurfaceManager {
|
|
|
126
285
|
private readonly surfaces = new Map<string, SurfaceEntry>();
|
|
127
286
|
private readonly localOccluders = new Map<string, NativeLocalOccluder>();
|
|
128
287
|
|
|
129
|
-
|
|
288
|
+
private readonly onFrame = () => {
|
|
289
|
+
if (this.surfaces.size === 0) return;
|
|
290
|
+
this.frameSync();
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
constructor(private readonly renderer: CliRenderer) {
|
|
294
|
+
// Only a terminal host reports what its frames drew; then every frame it
|
|
295
|
+
// shows re-measures the anchored images and re-cuts them all.
|
|
296
|
+
if (renderer.frameHits && typeof renderer.on === "function") renderer.on("frame", this.onFrame);
|
|
297
|
+
}
|
|
130
298
|
|
|
131
299
|
setWindowState(windowState: NativeWindowState) {
|
|
132
300
|
if (sameWindowState(this.windowState, windowState)) {
|
|
@@ -139,7 +307,10 @@ export class NativeSurfaceManager {
|
|
|
139
307
|
this.syncAll();
|
|
140
308
|
}
|
|
141
309
|
|
|
142
|
-
upsertSurface(
|
|
310
|
+
upsertSurface(incoming: NativeSurfaceSnapshot) {
|
|
311
|
+
// An anchored image goes where its box is in the frame on screen, which
|
|
312
|
+
// the rect React measured before that frame's layout can trail.
|
|
313
|
+
const snapshot = this.onScreen(incoming);
|
|
143
314
|
const existing = this.surfaces.get(snapshot.id);
|
|
144
315
|
if (existing) {
|
|
145
316
|
if (sameSnapshot(existing.snapshot, snapshot)) {
|
|
@@ -208,21 +379,56 @@ export class NativeSurfaceManager {
|
|
|
208
379
|
return [...this.surfaces.values()]
|
|
209
380
|
.map(({ snapshot }) => ({ snapshot, zIndex: this.paneZIndex(snapshot.paneId) }))
|
|
210
381
|
.sort((a, b) => a.zIndex - b.zIndex || (a.snapshot.imageZIndex ?? 0) - (b.snapshot.imageZIndex ?? 0))
|
|
211
|
-
.map(({ snapshot
|
|
382
|
+
.map(({ snapshot }) => ({
|
|
212
383
|
rect: snapshot.rect,
|
|
213
|
-
fragments:
|
|
384
|
+
fragments: this.visibleFragments(snapshot, occluders),
|
|
214
385
|
bitmap: snapshot.bitmap,
|
|
215
386
|
}))
|
|
216
387
|
.filter((image) => image.fragments.length > 0);
|
|
217
388
|
}
|
|
218
389
|
|
|
219
390
|
destroy() {
|
|
391
|
+
if (this.renderer.frameHits && typeof this.renderer.off === "function") this.renderer.off("frame", this.onFrame);
|
|
220
392
|
for (const id of [...this.surfaces.keys()]) {
|
|
221
393
|
this.removeSurface(id);
|
|
222
394
|
}
|
|
223
395
|
this.localOccluders.clear();
|
|
224
396
|
}
|
|
225
397
|
|
|
398
|
+
/** After a frame: each anchored image where its box is now, each image off what now covers it. */
|
|
399
|
+
private frameSync() {
|
|
400
|
+
for (const entry of this.surfaces.values()) {
|
|
401
|
+
entry.snapshot = this.onScreen(entry.snapshot);
|
|
402
|
+
this.syncSurface(entry);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
/** An anchored snapshot measured from its box as the frame on screen laid it out. */
|
|
407
|
+
private onScreen(snapshot: NativeSurfaceSnapshot): NativeSurfaceSnapshot {
|
|
408
|
+
const attached = this.renderer.frameHits?.attached;
|
|
409
|
+
if (!snapshot.anchor || !attached) return snapshot;
|
|
410
|
+
const measured = measureNativeSurfaceAnchor(snapshot.anchor, this.renderer.terminalWidth, this.renderer.terminalHeight, attached);
|
|
411
|
+
if (!measured) return snapshot.visibleRect === null ? snapshot : { ...snapshot, visibleRect: null };
|
|
412
|
+
if (sameCellRect(measured.rect, snapshot.rect) && sameCellRect(measured.visibleRect, snapshot.visibleRect)) return snapshot;
|
|
413
|
+
return { ...snapshot, rect: measured.rect, visibleRect: measured.visibleRect };
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
/** The cells of an image left to show: its visible rect, less the layout's occluders and whatever the frame drew over it. */
|
|
417
|
+
private visibleFragments(snapshot: NativeSurfaceSnapshot, occluders: NativeOccluder[]): CellRect[] {
|
|
418
|
+
const fragments = computeSurfaceVisibleFragments(
|
|
419
|
+
snapshot.rect,
|
|
420
|
+
snapshot.visibleRect,
|
|
421
|
+
this.paneZIndex(snapshot.paneId),
|
|
422
|
+
snapshot.paneId,
|
|
423
|
+
occluders,
|
|
424
|
+
);
|
|
425
|
+
const hits = this.renderer.frameHits;
|
|
426
|
+
if (!hits || !snapshot.anchor || fragments.length === 0) return fragments;
|
|
427
|
+
const covers = createCoverTest(snapshot.anchor.renderable, hits.paints);
|
|
428
|
+
const uncovered = fragments.flatMap((fragment) => uncoveredCellRects(fragment, (x, y) => covers(hits.at(x, y))));
|
|
429
|
+
return uncovered.length > MAX_UNCOVERED_FRAGMENTS ? [] : uncovered.sort(compareRects);
|
|
430
|
+
}
|
|
431
|
+
|
|
226
432
|
private paneZIndex(paneId: string): number {
|
|
227
433
|
return this.windowState.paneLayers.find((layer) => layer.paneId === paneId)?.zIndex ?? 0;
|
|
228
434
|
}
|
|
@@ -249,13 +455,7 @@ export class NativeSurfaceManager {
|
|
|
249
455
|
return;
|
|
250
456
|
}
|
|
251
457
|
|
|
252
|
-
const fragments =
|
|
253
|
-
entry.snapshot.rect,
|
|
254
|
-
entry.snapshot.visibleRect,
|
|
255
|
-
this.paneZIndex(entry.snapshot.paneId),
|
|
256
|
-
entry.snapshot.paneId,
|
|
257
|
-
this.resolvedOccluders(),
|
|
258
|
-
);
|
|
458
|
+
const fragments = this.visibleFragments(entry.snapshot, this.resolvedOccluders());
|
|
259
459
|
|
|
260
460
|
const placements = computeNativePlacements(
|
|
261
461
|
entry.snapshot.rect,
|
|
@@ -104,6 +104,7 @@ export function useCommandBarActionRuntime({
|
|
|
104
104
|
screen: "ticker-search" | "layout",
|
|
105
105
|
initialQuery = "",
|
|
106
106
|
payload?: Record<string, unknown>,
|
|
107
|
+
options?: { launched?: boolean },
|
|
107
108
|
) => {
|
|
108
109
|
if (screen === "ticker-search" && initialQuery.trim()) {
|
|
109
110
|
skipTickerSearchDebounceRef.current = true;
|
|
@@ -115,6 +116,7 @@ export function useCommandBarActionRuntime({
|
|
|
115
116
|
selectedIdx: 0,
|
|
116
117
|
hoveredIdx: null,
|
|
117
118
|
payload,
|
|
119
|
+
...(options?.launched ? { launched: true } : {}),
|
|
118
120
|
});
|
|
119
121
|
}, [pushRoute, skipTickerSearchDebounceRef]);
|
|
120
122
|
|
|
@@ -65,7 +65,6 @@ export function CommandBarPanel({
|
|
|
65
65
|
onThemeCommit,
|
|
66
66
|
onThemePreview,
|
|
67
67
|
panelBounds,
|
|
68
|
-
clearBounds = null,
|
|
69
68
|
queryDisplayWidth,
|
|
70
69
|
rootGhostSuffix,
|
|
71
70
|
rootShortcutFeedback,
|
|
@@ -136,6 +135,8 @@ export function CommandBarPanel({
|
|
|
136
135
|
return (
|
|
137
136
|
// The click-away overlay starts where the sheet does: the header above it
|
|
138
137
|
// holds the bar's input, and a click there must reach it, not close the bar.
|
|
138
|
+
// It draws nothing: the panes beside and below the sheet stay as they are,
|
|
139
|
+
// a chart image among them too, and only the sheet covers them.
|
|
139
140
|
<Box
|
|
140
141
|
position="absolute"
|
|
141
142
|
top={panelBounds.y}
|
|
@@ -149,18 +150,6 @@ export function CommandBarPanel({
|
|
|
149
150
|
onOverlayClose();
|
|
150
151
|
}}
|
|
151
152
|
>
|
|
152
|
-
{/* The terminal sheet's rows are its own, edge to edge: no piece of a pane shows at its sides. */}
|
|
153
|
-
{clearBounds && (
|
|
154
|
-
<Box
|
|
155
|
-
position="absolute"
|
|
156
|
-
top={clearBounds.y}
|
|
157
|
-
left={clearBounds.x}
|
|
158
|
-
width={clearBounds.width}
|
|
159
|
-
height={clearBounds.height}
|
|
160
|
-
backgroundColor={palette.panelBg}
|
|
161
|
-
zIndex={100}
|
|
162
|
-
/>
|
|
163
|
-
)}
|
|
164
153
|
<Box
|
|
165
154
|
position="absolute"
|
|
166
155
|
top={0}
|
|
@@ -27,13 +27,8 @@ export interface CommandBarPanelLayout {
|
|
|
27
27
|
listBodyHeight: number;
|
|
28
28
|
nativeOccluderRect: LayoutBounds;
|
|
29
29
|
nativePanelPaddingColumns: number;
|
|
30
|
+
/** The sheet, the one thing the open bar covers: the panes beside and below it stay as they are. */
|
|
30
31
|
panelBounds: LayoutBounds;
|
|
31
|
-
/**
|
|
32
|
-
* The rows the terminal sheet clears behind it, relative to its top, edge
|
|
33
|
-
* to edge: a pane cut by the sheet's sides shows only pieces of its words
|
|
34
|
-
* and borders. Null on the desktop, whose sheet is a floating surface.
|
|
35
|
-
*/
|
|
36
|
-
clearBounds: LayoutBounds | null;
|
|
37
32
|
queryDisplayWidth: number;
|
|
38
33
|
labelWidth: number;
|
|
39
34
|
trailingWidth: number;
|
|
@@ -154,7 +149,6 @@ export function resolveCommandBarPanelLayout({
|
|
|
154
149
|
width: barWidth,
|
|
155
150
|
height: barHeight,
|
|
156
151
|
},
|
|
157
|
-
clearBounds: nativePaneChrome ? null : { x: 0, y: 0, width: termWidth, height: barHeight },
|
|
158
152
|
queryDisplayWidth,
|
|
159
153
|
labelWidth,
|
|
160
154
|
trailingWidth,
|
|
@@ -214,7 +214,6 @@ export function useCommandBarPanelRuntime({
|
|
|
214
214
|
onThemeCommit: handleThemeCommit,
|
|
215
215
|
onThemePreview: applyThemePreview,
|
|
216
216
|
panelBounds: panelLayout.panelBounds,
|
|
217
|
-
clearBounds: panelLayout.clearBounds,
|
|
218
217
|
queryDisplayWidth: panelLayout.queryDisplayWidth,
|
|
219
218
|
rootGhostSuffix,
|
|
220
219
|
rootShortcutFeedback,
|
|
@@ -30,8 +30,6 @@ export interface CommandBarPanelProps {
|
|
|
30
30
|
onThemeCommit: (themeId: string) => void;
|
|
31
31
|
onThemePreview: (themeId: string | null) => void;
|
|
32
32
|
panelBounds: LayoutBounds;
|
|
33
|
-
/** What the terminal sheet clears behind it (see CommandBarPanelLayout); null on the desktop. */
|
|
34
|
-
clearBounds?: LayoutBounds | null;
|
|
35
33
|
queryDisplayWidth: number;
|
|
36
34
|
rootGhostSuffix: string | null;
|
|
37
35
|
rootShortcutFeedback: string | null;
|
|
@@ -9,6 +9,7 @@ interface UseCommandBarLaunchRequestOptions {
|
|
|
9
9
|
screen: "ticker-search" | "layout",
|
|
10
10
|
initialQuery?: string,
|
|
11
11
|
payload?: TickerSearchPayload,
|
|
12
|
+
options?: { launched?: boolean },
|
|
12
13
|
) => void;
|
|
13
14
|
}
|
|
14
15
|
|
|
@@ -30,7 +31,7 @@ export function useCommandBarLaunchRequest({
|
|
|
30
31
|
processedLaunchSequenceRef.current = launch.sequence;
|
|
31
32
|
|
|
32
33
|
if (launch.kind === "ticker-search") {
|
|
33
|
-
openModeRoute("ticker-search", launch.query ?? "", launch.payload);
|
|
34
|
+
openModeRoute("ticker-search", launch.query ?? "", launch.payload, { launched: true });
|
|
34
35
|
}
|
|
35
36
|
// Submitting text needs the selection runtime, which the surface wires up
|
|
36
37
|
// after this hook; it watches for run-query itself.
|
|
@@ -161,13 +161,15 @@ export function useCommandBarNavigationState({
|
|
|
161
161
|
setRouteStack((current) => current.slice(0, -1));
|
|
162
162
|
}, [closeAll, currentRoute, routeStack.length, setRootQuery]);
|
|
163
163
|
|
|
164
|
+
// Esc: one screen back, or out of the bar from the root or from a screen
|
|
165
|
+
// the bar opened on (`launched`).
|
|
164
166
|
const dismissCommandBar = useCallback(() => {
|
|
165
|
-
if (currentRoute) {
|
|
167
|
+
if (currentRoute && !(routeStack.length === 1 && currentRoute.launched)) {
|
|
166
168
|
popRoute();
|
|
167
169
|
return;
|
|
168
170
|
}
|
|
169
171
|
closeAll();
|
|
170
|
-
}, [closeAll, currentRoute, popRoute]);
|
|
172
|
+
}, [closeAll, currentRoute, popRoute, routeStack.length]);
|
|
171
173
|
|
|
172
174
|
return {
|
|
173
175
|
closeAll,
|
|
@@ -35,6 +35,12 @@ export type CommandBarFieldValue = string | boolean | string[];
|
|
|
35
35
|
|
|
36
36
|
interface CommandBarRouteBase {
|
|
37
37
|
restoreMain?: CommandBarMainSnapshot;
|
|
38
|
+
/**
|
|
39
|
+
* The bar opened on this screen from outside it (the ticker search key, a
|
|
40
|
+
* click in the header): Esc closes the bar, back where the user was,
|
|
41
|
+
* instead of showing the root screen they never saw.
|
|
42
|
+
*/
|
|
43
|
+
launched?: boolean;
|
|
38
44
|
}
|
|
39
45
|
|
|
40
46
|
interface CommandBarModeRoute extends CommandBarRouteBase {
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { useMemo, useRef } from "react";
|
|
2
|
+
import { t, tf } from "../../i18n";
|
|
3
|
+
import type { ContextMenuItem } from "../../types/context-menu";
|
|
4
|
+
import { useOptionalDialog, type PromptContext } from "../../ui/dialog";
|
|
5
|
+
import { logFailure } from "../../utils/log-failure";
|
|
6
|
+
import { ChoiceDialog } from "../ui/choice-dialog";
|
|
7
|
+
import type { DataTableColumn } from "../ui";
|
|
8
|
+
|
|
9
|
+
const NO_ITEMS: readonly ContextMenuItem[] = [];
|
|
10
|
+
|
|
11
|
+
function columnName(column: DataTableColumn): string {
|
|
12
|
+
return column.label.trim() || column.title || column.id;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The pane menu's column entries while the table is focused: "Move Column…"
|
|
17
|
+
* does a header drag from the keyboard (a column, then the one it should
|
|
18
|
+
* follow), and "Reset Columns" puts the pane's own order back once the reader
|
|
19
|
+
* has changed it.
|
|
20
|
+
*/
|
|
21
|
+
export function useDataTableColumnMenuItems({
|
|
22
|
+
enabled,
|
|
23
|
+
columns,
|
|
24
|
+
anchoredColumns,
|
|
25
|
+
onColumnMove,
|
|
26
|
+
customized,
|
|
27
|
+
reset,
|
|
28
|
+
}: {
|
|
29
|
+
enabled: boolean;
|
|
30
|
+
columns: readonly DataTableColumn[];
|
|
31
|
+
anchoredColumns: number;
|
|
32
|
+
onColumnMove?: (columnId: string, toIndex: number) => void;
|
|
33
|
+
customized: boolean;
|
|
34
|
+
reset: () => void;
|
|
35
|
+
}): readonly ContextMenuItem[] {
|
|
36
|
+
const dialog = useOptionalDialog();
|
|
37
|
+
const latest = useRef({ columns, anchoredColumns, onColumnMove });
|
|
38
|
+
latest.current = { columns, anchoredColumns, onColumnMove };
|
|
39
|
+
const movable = !!onColumnMove && columns.length - anchoredColumns >= 2;
|
|
40
|
+
|
|
41
|
+
return useMemo(() => {
|
|
42
|
+
if (!enabled || !movable) return NO_ITEMS;
|
|
43
|
+
const move = async () => {
|
|
44
|
+
if (!dialog) return;
|
|
45
|
+
const current = latest.current;
|
|
46
|
+
const columnId = await dialog.prompt<string>({
|
|
47
|
+
closeOnClickOutside: true,
|
|
48
|
+
content: (ctx: PromptContext<string>) => (
|
|
49
|
+
<ChoiceDialog
|
|
50
|
+
{...ctx}
|
|
51
|
+
title={t("Move Column")}
|
|
52
|
+
choices={current.columns.slice(current.anchoredColumns).map((column) => ({ id: column.id, label: columnName(column) }))}
|
|
53
|
+
/>
|
|
54
|
+
),
|
|
55
|
+
});
|
|
56
|
+
const from = current.columns.findIndex((column) => column.id === columnId);
|
|
57
|
+
if (!columnId || from < 0) return;
|
|
58
|
+
// After the column it should follow: the one it follows now is chosen to begin with.
|
|
59
|
+
const others = current.columns.filter((column) => column.id !== columnId);
|
|
60
|
+
const start = Math.max(0, current.anchoredColumns - 1);
|
|
61
|
+
const target = await dialog.prompt<string>({
|
|
62
|
+
closeOnClickOutside: true,
|
|
63
|
+
content: (ctx: PromptContext<string>) => (
|
|
64
|
+
<ChoiceDialog
|
|
65
|
+
{...ctx}
|
|
66
|
+
title={tf("Move {column}", { column: columnName(current.columns[from]!) })}
|
|
67
|
+
selectedChoiceId={String(from)}
|
|
68
|
+
choices={[
|
|
69
|
+
...current.anchoredColumns === 0 ? [{ id: "0", label: t("First") }] : [],
|
|
70
|
+
...others.slice(start).map((column, index) => ({
|
|
71
|
+
id: String(start + index + 1),
|
|
72
|
+
label: tf("After {column}", { column: columnName(column) }),
|
|
73
|
+
})),
|
|
74
|
+
]}
|
|
75
|
+
/>
|
|
76
|
+
),
|
|
77
|
+
});
|
|
78
|
+
if (target) latest.current.onColumnMove?.(columnId, Number(target));
|
|
79
|
+
};
|
|
80
|
+
return [
|
|
81
|
+
...dialog ? [{
|
|
82
|
+
id: "move-column",
|
|
83
|
+
label: "Move Column…",
|
|
84
|
+
onSelect: () => move().catch(logFailure("data-table", "Move Column failed")),
|
|
85
|
+
}] : [],
|
|
86
|
+
...customized ? [{ id: "reset-columns", label: "Reset Columns", onSelect: reset }] : [],
|
|
87
|
+
];
|
|
88
|
+
}, [customized, dialog, enabled, movable, reset]);
|
|
89
|
+
}
|
|
@@ -4,6 +4,9 @@ import { useOptionalDialog, type PromptContext } from "../../ui/dialog";
|
|
|
4
4
|
import { usePaneMenuItems } from "../layout/pane/footer";
|
|
5
5
|
import { ChoiceDialog } from "../ui/choice-dialog";
|
|
6
6
|
import type { DataTableColumn } from "../ui";
|
|
7
|
+
import type { ContextMenuItem } from "../../types/context-menu";
|
|
8
|
+
|
|
9
|
+
const NO_ITEMS: readonly ContextMenuItem[] = [];
|
|
7
10
|
|
|
8
11
|
/**
|
|
9
12
|
* A sortable table's header clicks, for the keyboard: "Sort by…" in the pane
|
|
@@ -17,6 +20,7 @@ export function useDataTableSortMenu({
|
|
|
17
20
|
sortDirection,
|
|
18
21
|
onHeaderClick,
|
|
19
22
|
onSortChange,
|
|
23
|
+
columnItems = NO_ITEMS,
|
|
20
24
|
}: {
|
|
21
25
|
enabled: boolean;
|
|
22
26
|
columns: DataTableColumn[];
|
|
@@ -25,6 +29,8 @@ export function useDataTableSortMenu({
|
|
|
25
29
|
onHeaderClick: (columnId: string) => void;
|
|
26
30
|
/** Sets a direction outright, for a header click that cycles through "unsorted". */
|
|
27
31
|
onSortChange?: (columnId: string, direction: "asc" | "desc") => void;
|
|
32
|
+
/** The table's column entries (Move Column…, Reset Columns), listed with its sort. */
|
|
33
|
+
columnItems?: readonly ContextMenuItem[];
|
|
28
34
|
}) {
|
|
29
35
|
const dialog = useOptionalDialog();
|
|
30
36
|
const registrationId = `data-table-sort:${useId()}`;
|
|
@@ -39,7 +45,7 @@ export function useDataTableSortMenu({
|
|
|
39
45
|
const sortableColumns = columns.filter((column) => column.label.trim().length > 0);
|
|
40
46
|
|
|
41
47
|
usePaneMenuItems(registrationId, () => {
|
|
42
|
-
if (!enabled || !dialog || sortableColumns.length === 0) return null;
|
|
48
|
+
if (!enabled || !dialog || sortableColumns.length === 0) return columnItems.length > 0 ? [...columnItems] : null;
|
|
43
49
|
const chooseColumn = async () => {
|
|
44
50
|
const current = latest.current;
|
|
45
51
|
const arrow = current.sortDirection === "asc" ? "▲" : "▼";
|
|
@@ -70,6 +76,7 @@ export function useDataTableSortMenu({
|
|
|
70
76
|
...(sortColumnId
|
|
71
77
|
? [{ id: "sort-reverse", label: "Reverse Sort", onSelect: reverse }]
|
|
72
78
|
: []),
|
|
79
|
+
...columnItems,
|
|
73
80
|
];
|
|
74
|
-
}, [dialog, enabled, sortColumnId, sortableColumns.length]);
|
|
81
|
+
}, [columnItems, dialog, enabled, sortColumnId, sortableColumns.length]);
|
|
75
82
|
}
|
|
@@ -13,7 +13,9 @@ import { useBeforeShortcut, useShortcut } from "../../react/input";
|
|
|
13
13
|
import { isPlainKey, isPlainKeyboardEvent } from "../../utils/keyboard";
|
|
14
14
|
import { DataTable, PaneStatusBody, type DataTableColumn, type DataTableProps, type PaneStatusBodyProps } from "../ui";
|
|
15
15
|
import { useDataTableSortMenu } from "./sort-menu";
|
|
16
|
-
import {
|
|
16
|
+
import { useDataTableColumnMenuItems } from "./column-menu";
|
|
17
|
+
import { drawnTableColumns, tableFreezesFirstColumn, tableRevealLeft, tableScrollStep } from "../ui/table-layout";
|
|
18
|
+
import { useDataTableColumnOrder } from "../ui/data-table/use-column-order";
|
|
17
19
|
import {
|
|
18
20
|
TableViewFrame,
|
|
19
21
|
useResetTableScroll,
|
|
@@ -211,13 +213,31 @@ export function DataTableView<
|
|
|
211
213
|
...tableProps
|
|
212
214
|
}: DataTableViewProps<T, C>) {
|
|
213
215
|
const onHeaderClick = tableProps.onHeaderClick;
|
|
216
|
+
// Ordered here, so a sideways step and a revealed column count the columns as they are drawn.
|
|
217
|
+
const columnOrder = useDataTableColumnOrder(
|
|
218
|
+
tableProps.columns,
|
|
219
|
+
tableProps.onColumnMove ? false : tableProps.columnReorder,
|
|
220
|
+
{ menu: false },
|
|
221
|
+
);
|
|
222
|
+
const columns = columnOrder.columns;
|
|
223
|
+
const onColumnMove = tableProps.onColumnMove ?? columnOrder.onColumnMove;
|
|
224
|
+
const anchoredColumns = tableProps.onColumnMove ? tableProps.anchoredColumns ?? 1 : columnOrder.anchoredColumns;
|
|
225
|
+
const columnItems = useDataTableColumnMenuItems({
|
|
226
|
+
enabled: focused && keyboardNavigation,
|
|
227
|
+
columns,
|
|
228
|
+
anchoredColumns,
|
|
229
|
+
onColumnMove,
|
|
230
|
+
customized: columnOrder.customized,
|
|
231
|
+
reset: columnOrder.reset,
|
|
232
|
+
});
|
|
214
233
|
useDataTableSortMenu({
|
|
215
234
|
enabled: focused && keyboardNavigation && !!onHeaderClick && (sortable ?? true),
|
|
216
|
-
columns: isColumnSortable ?
|
|
235
|
+
columns: isColumnSortable ? columns.filter(isColumnSortable) : columns,
|
|
217
236
|
sortColumnId: tableProps.sortColumnId ?? null,
|
|
218
237
|
sortDirection: tableProps.sortDirection ?? "asc",
|
|
219
238
|
onHeaderClick: onHeaderClick ?? ignoreHeaderClick,
|
|
220
239
|
onSortChange,
|
|
240
|
+
columnItems,
|
|
221
241
|
});
|
|
222
242
|
const {
|
|
223
243
|
effectiveHeaderScrollRef,
|
|
@@ -697,13 +717,15 @@ export function DataTableView<
|
|
|
697
717
|
// At either edge the key is still the table's, so it never falls through
|
|
698
718
|
// to switch a tab.
|
|
699
719
|
stopTableKey(event);
|
|
720
|
+
// The columns in their order, at the widths the terminal's fit drew them.
|
|
721
|
+
const drawn = drawnTableColumns.get(body) ?? columns;
|
|
700
722
|
const nextLeft = tableScrollStep({
|
|
701
|
-
columns:
|
|
723
|
+
columns: drawn,
|
|
702
724
|
columnGap: tableProps.columnGap,
|
|
703
725
|
horizontalPadding: tableProps.horizontalPadding,
|
|
704
726
|
frozenFirstColumn: tableFreezesFirstColumn({
|
|
705
727
|
freezeFirstColumn: tableProps.freezeFirstColumn,
|
|
706
|
-
columns:
|
|
728
|
+
columns: drawn,
|
|
707
729
|
columnGap: tableProps.columnGap,
|
|
708
730
|
horizontalPadding: tableProps.horizontalPadding,
|
|
709
731
|
viewportWidth,
|
|
@@ -725,7 +747,7 @@ export function DataTableView<
|
|
|
725
747
|
// The column asked for, in the middle of the scrolled columns once the body has its width. Keyed on the
|
|
726
748
|
// column and the pane's width only: a refresh that resizes a column to its new figures, or a scroll the
|
|
727
749
|
// reader made with Shift+arrows, stays where it is. An empty table waits for its rows.
|
|
728
|
-
const revealColumnIndex = revealColumnId == null ? -1 :
|
|
750
|
+
const revealColumnIndex = revealColumnId == null ? -1 : columns.findIndex((column) => column.id === revealColumnId);
|
|
729
751
|
const revealKey = revealColumnIndex < 0 ? null : `${revealColumnIndex}:${rootWidth ?? ""}`;
|
|
730
752
|
const revealedKeyRef = useRef<string | null>(null);
|
|
731
753
|
const hasRows = tableProps.items.length > 0;
|
|
@@ -742,7 +764,8 @@ export function DataTableView<
|
|
|
742
764
|
if (scrollWidth > 0) revealedKeyRef.current = revealKey;
|
|
743
765
|
return scrollWidth > 0;
|
|
744
766
|
}
|
|
745
|
-
|
|
767
|
+
// The columns in their order, at the widths the terminal's fit drew them.
|
|
768
|
+
const shared = { columns: drawnTableColumns.get(body) ?? columns, columnGap: tableProps.columnGap, horizontalPadding: tableProps.horizontalPadding };
|
|
746
769
|
const nextLeft = tableRevealLeft({ ...shared, columnIndex: revealColumnIndex, viewportWidth, maxLeft,
|
|
747
770
|
frozenFirstColumn: tableFreezesFirstColumn({ ...shared, freezeFirstColumn: tableProps.freezeFirstColumn, viewportWidth, overflows: true }) });
|
|
748
771
|
if (nextLeft !== body.scrollLeft) {
|
|
@@ -811,6 +834,10 @@ export function DataTableView<
|
|
|
811
834
|
>
|
|
812
835
|
{bodyStatusShown(status) ? <PaneStatusBody {...status} /> : <DataTable<T, C>
|
|
813
836
|
{...tableProps}
|
|
837
|
+
columns={columns}
|
|
838
|
+
columnReorder={false}
|
|
839
|
+
onColumnMove={onColumnMove}
|
|
840
|
+
anchoredColumns={anchoredColumns}
|
|
814
841
|
headerScrollRef={effectiveHeaderScrollRef}
|
|
815
842
|
scrollRef={effectiveScrollRef}
|
|
816
843
|
syncHeaderScroll={effectiveSyncHeaderScroll}
|