@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
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { memo, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
2
|
-
import { Box, ScrollBox, Span, Text, TextAttributes, useNativeRenderer } from "../../../../ui";
|
|
3
|
-
import {
|
|
1
|
+
import { memo, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
2
|
+
import { Box, ScrollBox, Span, Text, TextAttributes, useNativeRenderer, type BoxRenderable } from "../../../../ui";
|
|
3
|
+
import { capturePointerDrag, releasePointerDrag } from "../../../../ui/pointer-drag";
|
|
4
|
+
import { hoverBg, inactiveSelectedText } from "../../../../theme/colors";
|
|
4
5
|
import { selectedRowCellColor } from "../../../../theme/tone-contrast";
|
|
5
6
|
import { useThemeColors } from "../../../../theme/theme-context";
|
|
6
7
|
import { usePaneInstance } from "../../../../state/app/context";
|
|
7
|
-
import {
|
|
8
|
+
import { useSelectionFill } from "../../selection-fill";
|
|
9
|
+
import { useShortcut, useViewport } from "../../../../react/input";
|
|
8
10
|
import { measurePerf } from "../../../../utils/perf-marks";
|
|
9
11
|
import { displayWidth } from "../../../../utils/format";
|
|
10
12
|
import { useDoubleClickActivation } from "../../../use-double-click-activation";
|
|
@@ -13,6 +15,9 @@ import { EmptyState } from "../../status";
|
|
|
13
15
|
import { observeScrollBoxContentSize, observeScrollBoxViewportSize } from "../../../../renderers/opentui/scrollbox-layout";
|
|
14
16
|
import {
|
|
15
17
|
expandTableColumns,
|
|
18
|
+
drawnTableColumns,
|
|
19
|
+
fitTableColumns,
|
|
20
|
+
tableColumnWidth,
|
|
16
21
|
fitTableHeaderText,
|
|
17
22
|
getTableWidth,
|
|
18
23
|
hasMeaningfulTableHorizontalOverflow,
|
|
@@ -31,12 +36,15 @@ import type {
|
|
|
31
36
|
import { resolveDataTableScrollTop } from "../visible-range";
|
|
32
37
|
import { useFocusOwningPane, useVisibleRangeEmitter } from "../hooks";
|
|
33
38
|
import { useStableColumns } from "../stable-columns";
|
|
39
|
+
import { COLUMN_DRAG_THRESHOLD_CELLS, columnDropBoundary, columnDropIndex } from "../column-order";
|
|
34
40
|
import {
|
|
41
|
+
columnsShownWhole,
|
|
35
42
|
cutColumnText,
|
|
36
43
|
fitColumnCellText,
|
|
37
44
|
resolveDataTableColumnClips,
|
|
38
45
|
resolveDataTableVisibleWindow,
|
|
39
46
|
resolveMoreColumnsHint,
|
|
47
|
+
MORE_COLUMNS_HINT_WIDTH,
|
|
40
48
|
reuseDataTableColumnClips,
|
|
41
49
|
type DataTableColumnClip,
|
|
42
50
|
} from "./model";
|
|
@@ -46,6 +54,26 @@ interface DataTableRowPointerTarget<T> {
|
|
|
46
54
|
index: number;
|
|
47
55
|
}
|
|
48
56
|
|
|
57
|
+
/** A press on a header that may become a drag of its column. */
|
|
58
|
+
interface HeaderPress {
|
|
59
|
+
columnId: string;
|
|
60
|
+
from: number;
|
|
61
|
+
startX: number;
|
|
62
|
+
dragging: boolean;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
interface HeaderDragEvent {
|
|
66
|
+
x?: number;
|
|
67
|
+
preventDefault?: () => void;
|
|
68
|
+
stopPropagation?: () => void;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** A column being dragged, and the gap it would drop into (null where it would stay). */
|
|
72
|
+
interface ColumnDrag {
|
|
73
|
+
from: number;
|
|
74
|
+
boundary: number | null;
|
|
75
|
+
}
|
|
76
|
+
|
|
49
77
|
type ManagedScrollBar = {
|
|
50
78
|
visible: boolean;
|
|
51
79
|
resetVisibilityControl?: () => void;
|
|
@@ -61,6 +89,12 @@ function setScrollBarVisible(scrollBar: unknown, visible: boolean): void {
|
|
|
61
89
|
bar.visible = visible;
|
|
62
90
|
}
|
|
63
91
|
|
|
92
|
+
/** The widths of what a row drew in each column, null for a cell of its own (`content`) that gives none (`contentWidth`). */
|
|
93
|
+
interface RowCellWidths {
|
|
94
|
+
columnsKey: string;
|
|
95
|
+
widths: (number | null)[];
|
|
96
|
+
}
|
|
97
|
+
|
|
64
98
|
function OpenTuiDataTableRowInner<
|
|
65
99
|
T,
|
|
66
100
|
C extends DataTableColumn,
|
|
@@ -69,6 +103,7 @@ function OpenTuiDataTableRowInner<
|
|
|
69
103
|
columnGap,
|
|
70
104
|
columnStarts,
|
|
71
105
|
contentWidth,
|
|
106
|
+
cellColumns,
|
|
72
107
|
displayColumns,
|
|
73
108
|
focusPane,
|
|
74
109
|
frozenColumnOffset,
|
|
@@ -86,9 +121,16 @@ function OpenTuiDataTableRowInner<
|
|
|
86
121
|
rowContextMenuSurface,
|
|
87
122
|
sectionWidth,
|
|
88
123
|
selected,
|
|
124
|
+
selectionBg,
|
|
125
|
+
selectionLit: paneSelectionLit,
|
|
89
126
|
selectedTextOverridesCellColor,
|
|
90
127
|
columnClips,
|
|
128
|
+
cellWidths,
|
|
129
|
+
columnsKey,
|
|
91
130
|
}: {
|
|
131
|
+
/** Where the row leaves the width of each column's text as it draws it, for the table to fit its columns to. */
|
|
132
|
+
cellWidths: Map<string, RowCellWidths>;
|
|
133
|
+
columnsKey: string;
|
|
92
134
|
/** Only compared by the row memo; see `getRowVersion`. */
|
|
93
135
|
rowVersion?: unknown;
|
|
94
136
|
/** Columns of the row in view, which a section header's action keeps to. */
|
|
@@ -97,6 +139,12 @@ function OpenTuiDataTableRowInner<
|
|
|
97
139
|
columnGap: number;
|
|
98
140
|
columnStarts: number[];
|
|
99
141
|
contentWidth: number;
|
|
142
|
+
/**
|
|
143
|
+
* The columns as each cell's text is made for and measured at: as an unfitted table draws them, so
|
|
144
|
+
* text that fits itself to its column (a price's digits) neither shrinks with the blank the fit took
|
|
145
|
+
* from it nor grows with the room the fit gave it.
|
|
146
|
+
*/
|
|
147
|
+
cellColumns: C[];
|
|
100
148
|
displayColumns: C[];
|
|
101
149
|
focusPane: () => void;
|
|
102
150
|
frozenColumnOffset?: number;
|
|
@@ -117,15 +165,23 @@ function OpenTuiDataTableRowInner<
|
|
|
117
165
|
renderSectionHeader?: DataTableProps<T, C>["renderSectionHeader"];
|
|
118
166
|
rowContextMenuSurface: boolean;
|
|
119
167
|
selected: boolean;
|
|
168
|
+
/** The selected row's fill (`useSelectionFill`): quieter, in the row's own text colours, when the pane is not focused. */
|
|
169
|
+
selectionBg: string;
|
|
170
|
+
selectionLit: boolean;
|
|
120
171
|
selectedTextOverridesCellColor: boolean;
|
|
121
172
|
/** How the viewport cuts each column, null when every column shows whole (resolveDataTableColumnClips). */
|
|
122
173
|
columnClips: readonly (DataTableColumnClip | null)[] | null;
|
|
123
174
|
}) {
|
|
124
175
|
const sectionHeader = renderSectionHeader?.(item, index) ?? null;
|
|
176
|
+
const selectionLit = selected && paneSelectionLit;
|
|
177
|
+
// On the quieter fill a row keeps its own colours, each lifted only where it would not read there.
|
|
178
|
+
const ink = (color: string) => (selected && !selectionLit ? inactiveSelectedText(color, colors) : color);
|
|
125
179
|
|
|
126
180
|
if (sectionHeader) {
|
|
127
181
|
// A header the cursor can land on (a collapsible group) shows it like a row.
|
|
128
|
-
const headerColor =
|
|
182
|
+
const headerColor = selectionLit
|
|
183
|
+
? sectionHeader.color ?? colors.selectedText
|
|
184
|
+
: ink(sectionHeader.color ?? colors.textBright);
|
|
129
185
|
const action = sectionHeader.action;
|
|
130
186
|
return (
|
|
131
187
|
<Box
|
|
@@ -135,7 +191,7 @@ function OpenTuiDataTableRowInner<
|
|
|
135
191
|
// Beside a pinned first column the heading stays in view too, not cut to its last letters.
|
|
136
192
|
paddingLeft={horizontalPadding + (frozenColumnOffset ?? 0)}
|
|
137
193
|
paddingRight={horizontalPadding}
|
|
138
|
-
backgroundColor={selected ?
|
|
194
|
+
backgroundColor={selected ? selectionBg : sectionHeader.backgroundColor ?? colors.bg}
|
|
139
195
|
onMouseDown={(event: any) => {
|
|
140
196
|
focusPane();
|
|
141
197
|
onTableMouseDown?.(event);
|
|
@@ -166,7 +222,7 @@ function OpenTuiDataTableRowInner<
|
|
|
166
222
|
action.onPress();
|
|
167
223
|
}}
|
|
168
224
|
>
|
|
169
|
-
<Text fg={
|
|
225
|
+
<Text fg={selectionLit ? colors.selectedText : ink(colors.text)}>{action.label}</Text>
|
|
170
226
|
</Box>
|
|
171
227
|
</Box>
|
|
172
228
|
) : (
|
|
@@ -181,9 +237,11 @@ function OpenTuiDataTableRowInner<
|
|
|
181
237
|
);
|
|
182
238
|
}
|
|
183
239
|
|
|
184
|
-
const rowState = { selected };
|
|
240
|
+
const rowState = { selected, inactive: selected && !selectionLit };
|
|
241
|
+
const widths: (number | null)[] = [];
|
|
242
|
+
cellWidths.set(itemKey, { columnsKey, widths });
|
|
185
243
|
const rowBackgroundColor = getRowBackgroundColor?.(item, index, rowState);
|
|
186
|
-
const rowBg = selected ?
|
|
244
|
+
const rowBg = selected ? selectionBg : rowBackgroundColor ?? colors.bg;
|
|
187
245
|
const rowHoverBg = selected ? undefined : hoverBg(colors);
|
|
188
246
|
|
|
189
247
|
return (
|
|
@@ -210,7 +268,11 @@ function OpenTuiDataTableRowInner<
|
|
|
210
268
|
{displayColumns.map((column, columnIndex) => {
|
|
211
269
|
const frozen = columnIndex === 0 && frozenColumnOffset !== undefined;
|
|
212
270
|
const clip = columnClips?.[columnIndex] ?? null;
|
|
213
|
-
const
|
|
271
|
+
const cellColumn = cellColumns[columnIndex] ?? column;
|
|
272
|
+
const made = renderCell(item, cellColumn, index, rowState);
|
|
273
|
+
// A drawn cell lays itself out in the column as drawn; its width is the one made for its column unfitted.
|
|
274
|
+
const cell = made.content !== undefined && cellColumn !== column ? renderCell(item, column, index, rowState) : made;
|
|
275
|
+
widths[columnIndex] = made.content === undefined ? displayWidth(made.text) : made.contentWidth ?? null;
|
|
214
276
|
const columnStart = columnStarts[columnIndex] ?? 0;
|
|
215
277
|
const leadGap = tableColumnLeadGap(displayColumns, columnIndex, columnGap);
|
|
216
278
|
const inset = clip ? clip.inset : !frozen && frozenColumnOffset !== undefined
|
|
@@ -255,13 +317,14 @@ function OpenTuiDataTableRowInner<
|
|
|
255
317
|
)) : (
|
|
256
318
|
<Text
|
|
257
319
|
attributes={cell.attributes ?? TextAttributes.NONE}
|
|
258
|
-
fg={
|
|
320
|
+
fg={selectionLit
|
|
259
321
|
? selectedRowCellColor(cell.color, !!selectedTextOverridesCellColor, cell.keepColorWhenSelected, colors) ?? colors.selectedText
|
|
260
|
-
|
|
322
|
+
// A cell on a fill of its own keeps the colour it chose for it.
|
|
323
|
+
: cell.backgroundColor && cell.backgroundColor !== selectionBg ? cell.color ?? colors.text : ink(cell.color ?? colors.text)}
|
|
261
324
|
>
|
|
262
325
|
{fitted.note ? <>
|
|
263
326
|
{`${frozen ? " ".repeat(horizontalPadding) : ""}${" ".repeat(inset)}${fitted.text}`}
|
|
264
|
-
<Span fg={colors.textDim} attributes={TextAttributes.NONE}>{fitted.note}</Span>
|
|
327
|
+
<Span fg={ink(colors.textDim)} attributes={TextAttributes.NONE}>{fitted.note}</Span>
|
|
265
328
|
{`${fitted.padding ?? ""}${frozen ? " ".repeat(columnGap) : ""}`}
|
|
266
329
|
</> : `${frozen ? " ".repeat(horizontalPadding) : ""}${" ".repeat(inset)}${fitted.text}${frozen ? " ".repeat(columnGap) : ""}`}
|
|
267
330
|
</Text>
|
|
@@ -281,6 +344,8 @@ export function OpenTuiDataTable<T, C extends DataTableColumn = DataTableColumn>
|
|
|
281
344
|
sortColumnId,
|
|
282
345
|
sortDirection,
|
|
283
346
|
onHeaderClick,
|
|
347
|
+
onColumnMove,
|
|
348
|
+
anchoredColumns = 1,
|
|
284
349
|
headerScrollRef,
|
|
285
350
|
scrollRef,
|
|
286
351
|
syncHeaderScroll,
|
|
@@ -323,6 +388,7 @@ export function OpenTuiDataTable<T, C extends DataTableColumn = DataTableColumn>
|
|
|
323
388
|
const colors = useThemeColors();
|
|
324
389
|
const focusPane = useFocusOwningPane();
|
|
325
390
|
const paneInstanceId = usePaneInstance()?.instanceId ?? null;
|
|
391
|
+
const selectionFill = useSelectionFill();
|
|
326
392
|
const appViewport = useViewport();
|
|
327
393
|
const nativeRenderer = useNativeRenderer();
|
|
328
394
|
const [scrollVersion, setScrollVersion] = useState(0);
|
|
@@ -368,48 +434,210 @@ export function OpenTuiDataTable<T, C extends DataTableColumn = DataTableColumn>
|
|
|
368
434
|
],
|
|
369
435
|
);
|
|
370
436
|
const { endIndex, startIndex, viewportHeight, visibleItems } = tableWindow;
|
|
371
|
-
const
|
|
437
|
+
const setTableWidth = useMemo(
|
|
372
438
|
() => getTableWidth(columns, columnGap, horizontalPadding),
|
|
373
439
|
[columnGap, columns, horizontalPadding],
|
|
374
440
|
);
|
|
375
441
|
const {
|
|
376
|
-
contentWidth: measuredContentWidth,
|
|
377
442
|
viewportWidth: measuredViewportWidth,
|
|
378
443
|
measureContentWidth,
|
|
379
|
-
} = useMeasuredTableContentWidth(
|
|
444
|
+
} = useMeasuredTableContentWidth(setTableWidth, headerScrollRef, scrollRef);
|
|
445
|
+
// The widest text each column holds in the rows drawn so far, kept while the columns, the rows and the
|
|
446
|
+
// pane's width stay the same, so a column never narrows as the rows under it scroll by; new rows or a new
|
|
447
|
+
// width start it over from the rows in view. Each row reports its cells' widths as it draws them (a drawn
|
|
448
|
+
// cell, `content`, gives its `contentWidth` or keeps its column's width), so no cell is made twice.
|
|
449
|
+
const columnsKey = columns.map((column) => `${column.id}:${column.width}:${column.label}`).join("\u0000");
|
|
450
|
+
const rowCellWidths = useRef(new Map<string, RowCellWidths>()).current;
|
|
451
|
+
const [measuredWidths, setMeasuredWidths] = useState<{ key: string; widths: (number | null)[] } | null>(null);
|
|
452
|
+
const measuredFrom = useRef<{ items: readonly T[]; viewportWidth: number } | null>(null);
|
|
453
|
+
const contentWidths = measuredWidths?.key === columnsKey ? measuredWidths.widths : null;
|
|
454
|
+
useLayoutEffect(() => {
|
|
455
|
+
const from = measuredFrom.current;
|
|
456
|
+
const fresh = !from || from.items !== items || from.viewportWidth !== measuredViewportWidth;
|
|
457
|
+
measuredFrom.current = { items, viewportWidth: measuredViewportWidth };
|
|
458
|
+
const previous = measuredWidths?.key === columnsKey ? measuredWidths.widths : null;
|
|
459
|
+
const kept = fresh ? null : previous;
|
|
460
|
+
const widths: (number | null)[] = columns.map((_, index) => kept?.[index] ?? 0);
|
|
461
|
+
if (kept) kept.forEach((width, index) => { if (width === null) widths[index] = null; });
|
|
462
|
+
visibleItems.forEach((item, offset) => {
|
|
463
|
+
const row = rowCellWidths.get(getItemKey(item, startIndex + offset));
|
|
464
|
+
if (!row || row.columnsKey !== columnsKey) return;
|
|
465
|
+
row.widths.forEach((width, index) => {
|
|
466
|
+
const known = widths[index];
|
|
467
|
+
widths[index] = known === null || width === null ? null : Math.max(known ?? 0, width);
|
|
468
|
+
});
|
|
469
|
+
});
|
|
470
|
+
if (rowCellWidths.size > visibleItems.length * 4 + 64) rowCellWidths.clear();
|
|
471
|
+
if (previous && widths.every((width, index) => width === previous[index])) return;
|
|
472
|
+
setMeasuredWidths({ key: columnsKey, widths });
|
|
473
|
+
});
|
|
474
|
+
// A header as drawn, with its sort mark.
|
|
475
|
+
const sortedLabel = useCallback(
|
|
476
|
+
(column: { id: string; label: string }) => (sortColumnId === column.id ? `${column.label}${column.label ? " " : ""}▲` : column.label),
|
|
477
|
+
[sortColumnId],
|
|
478
|
+
);
|
|
479
|
+
// The header row has a blank cell past its scroll box, over the body's vertical scrollbar, which the
|
|
480
|
+
// "more ⇧→" hint takes first (resolveMoreColumnsHint).
|
|
481
|
+
const besideHeader = Math.max(0, Math.min(1, (scrollRef.current?.width ?? 0) - measuredViewportWidth));
|
|
482
|
+
// Fitted to the viewport and what the columns hold: blank past their text gives way before a column is
|
|
483
|
+
// cut or pushed out of view (fitTableColumns).
|
|
484
|
+
const fittedColumns = useMemo(
|
|
485
|
+
() => contentWidths
|
|
486
|
+
? fitTableColumns(columns, contentWidths, measuredViewportWidth, columnGap, horizontalPadding, showHorizontalScrollbar ? {
|
|
487
|
+
...MORE_COLUMNS_HINT_WIDTH,
|
|
488
|
+
shownWhole: (fitted) => columnsShownWhole({
|
|
489
|
+
columns: fitted.map((column) => ({ width: column.width, align: column.align, label: sortedLabel(column) })),
|
|
490
|
+
columnGap,
|
|
491
|
+
besideHeader,
|
|
492
|
+
horizontalPadding,
|
|
493
|
+
viewportWidth: measuredViewportWidth,
|
|
494
|
+
}),
|
|
495
|
+
} : undefined)
|
|
496
|
+
: columns,
|
|
497
|
+
[besideHeader, columnGap, columns, contentWidths, horizontalPadding, measuredViewportWidth, showHorizontalScrollbar, sortedLabel],
|
|
498
|
+
);
|
|
499
|
+
const tableWidth = useMemo(
|
|
500
|
+
() => getTableWidth(fittedColumns, columnGap, horizontalPadding),
|
|
501
|
+
[columnGap, fittedColumns, horizontalPadding],
|
|
502
|
+
);
|
|
503
|
+
const measuredContentWidth = Math.max(tableWidth, measuredViewportWidth);
|
|
380
504
|
const horizontalScrollbarVisible = showHorizontalScrollbar
|
|
381
505
|
&& hasMeaningfulTableHorizontalOverflow(tableWidth, measuredViewportWidth, columnGap);
|
|
382
506
|
const freezeFirstColumn = tableFreezesFirstColumn({
|
|
383
|
-
freezeFirstColumn: freezeFirstColumnProp, columns, columnGap, horizontalPadding, viewportWidth: measuredViewportWidth,
|
|
507
|
+
freezeFirstColumn: freezeFirstColumnProp, columns: fittedColumns, columnGap, horizontalPadding, viewportWidth: measuredViewportWidth,
|
|
384
508
|
overflows: horizontalScrollbarVisible,
|
|
385
509
|
});
|
|
386
510
|
const contentWidth = fillAvailableWidth ? measuredContentWidth : tableWidth;
|
|
387
511
|
const sectionWidth = measuredViewportWidth > 0 ? Math.min(contentWidth, measuredViewportWidth) : contentWidth;
|
|
388
512
|
const displayColumns = useMemo(
|
|
389
|
-
() => expandTableColumns(
|
|
390
|
-
[columnGap,
|
|
513
|
+
() => expandTableColumns(fittedColumns, contentWidth, columnGap, horizontalPadding),
|
|
514
|
+
[columnGap, fittedColumns, contentWidth, horizontalPadding],
|
|
391
515
|
);
|
|
516
|
+
// What each cell's text is made for, and measured at: the columns as an unfitted table draws them, never the
|
|
517
|
+
// fit's. Text that fits itself to its column (a price's digits) does not shrink with the blank the fit took
|
|
518
|
+
// from it, nor, made for the room the fit gave it, measure wider and so take more on the next fit.
|
|
519
|
+
const cellColumns = useMemo(() => {
|
|
520
|
+
if (fittedColumns === columns) return displayColumns;
|
|
521
|
+
const unfitted = expandTableColumns(
|
|
522
|
+
columns,
|
|
523
|
+
fillAvailableWidth ? Math.max(setTableWidth, measuredViewportWidth) : setTableWidth,
|
|
524
|
+
columnGap,
|
|
525
|
+
horizontalPadding,
|
|
526
|
+
);
|
|
527
|
+
return displayColumns.map((column, index) => {
|
|
528
|
+
const width = unfitted[index]?.width ?? column.width;
|
|
529
|
+
return width === column.width ? column : { ...column, width };
|
|
530
|
+
});
|
|
531
|
+
}, [columnGap, columns, displayColumns, fillAvailableWidth, fittedColumns, horizontalPadding, measuredViewportWidth, setTableWidth]);
|
|
392
532
|
const columnStarts = useMemo(
|
|
393
533
|
() => tableColumnStarts(displayColumns, columnGap),
|
|
394
534
|
[columnGap, displayColumns],
|
|
395
535
|
);
|
|
536
|
+
// Sideways steps and the column a table opens on go by the widths drawn where the fit moved them.
|
|
537
|
+
useEffect(() => {
|
|
538
|
+
const body = scrollRef.current;
|
|
539
|
+
if (!body) return;
|
|
540
|
+
const moved = fittedColumns !== columns && fittedColumns.some((column, index) => column.width !== tableColumnWidth(columns[index]!));
|
|
541
|
+
if (moved) drawnTableColumns.set(body, fittedColumns);
|
|
542
|
+
else drawnTableColumns.delete(body);
|
|
543
|
+
}, [columns, fittedColumns, scrollRef]);
|
|
544
|
+
// A press on a movable header sorts on release, or drags its column once it moves two cells: the header row
|
|
545
|
+
// takes the drag (capturePointerDrag), marks the gap the column would drop into, and moves it on release.
|
|
546
|
+
const headerRowRef = useRef<BoxRenderable | null>(null);
|
|
547
|
+
const headerPressRef = useRef<HeaderPress | null>(null);
|
|
548
|
+
const [columnDrag, setColumnDrag] = useState<ColumnDrag | null>(null);
|
|
549
|
+
const columnSpans = useMemo(
|
|
550
|
+
() => displayColumns.map((column, index) => ({ start: columnStarts[index] ?? 0, end: (columnStarts[index] ?? 0) + column.width })),
|
|
551
|
+
[columnStarts, displayColumns],
|
|
552
|
+
);
|
|
553
|
+
// Scrolled sideways, a frozen first column covers the columns under it: it ends here, in the row's
|
|
554
|
+
// coordinates past its padding, and nothing drops among the columns it covers.
|
|
555
|
+
const frozenEnd = freezeFirstColumn ? frozenColumnOffset + (displayColumns[0]?.width ?? 0) + columnGap : undefined;
|
|
556
|
+
const dropBoundaryAt = useCallback((event?: { x?: number }) => {
|
|
557
|
+
const row = headerRowRef.current;
|
|
558
|
+
if (typeof event?.x !== "number" || !row) return null;
|
|
559
|
+
// row.x is where the scrolled row starts on screen, so this is the pointer's place among the columns.
|
|
560
|
+
return columnDropBoundary(columnSpans, event.x - (row.x ?? 0) - horizontalPadding, anchoredColumns, frozenEnd);
|
|
561
|
+
}, [anchoredColumns, columnSpans, frozenEnd, horizontalPadding]);
|
|
562
|
+
const dragHeader = useCallback((event?: HeaderDragEvent) => {
|
|
563
|
+
const press = headerPressRef.current;
|
|
564
|
+
if (!press || typeof event?.x !== "number") return;
|
|
565
|
+
if (!press.dragging && Math.abs(event.x - press.startX) < COLUMN_DRAG_THRESHOLD_CELLS) return;
|
|
566
|
+
press.dragging = true;
|
|
567
|
+
event.preventDefault?.();
|
|
568
|
+
event.stopPropagation?.();
|
|
569
|
+
const boundary = dropBoundaryAt(event);
|
|
570
|
+
const next = { from: press.from, boundary: boundary !== null && columnDropIndex(press.from, boundary) !== null ? boundary : null };
|
|
571
|
+
setColumnDrag((current) => current?.from === next.from && current.boundary === next.boundary ? current : next);
|
|
572
|
+
}, [dropBoundaryAt]);
|
|
573
|
+
// A press that never sees its release (let go outside the window) ends at the next move with no button
|
|
574
|
+
// held, the next press or the terminal losing focus: no move, no sort, and the header is put down.
|
|
575
|
+
const cancelHeaderPress = useCallback(() => {
|
|
576
|
+
if (!headerPressRef.current) return;
|
|
577
|
+
headerPressRef.current = null;
|
|
578
|
+
setColumnDrag(null);
|
|
579
|
+
releasePointerDrag(nativeRenderer);
|
|
580
|
+
}, [nativeRenderer]);
|
|
581
|
+
const dragging = columnDrag !== null;
|
|
582
|
+
useEffect(() => {
|
|
583
|
+
if (!dragging || typeof nativeRenderer?.on !== "function") return;
|
|
584
|
+
nativeRenderer.on("blur", cancelHeaderPress);
|
|
585
|
+
return () => nativeRenderer.off("blur", cancelHeaderPress);
|
|
586
|
+
}, [cancelHeaderPress, dragging, nativeRenderer]);
|
|
587
|
+
// Esc while a column drags puts it back; the release then does nothing.
|
|
588
|
+
useShortcut((event) => {
|
|
589
|
+
if (event.name !== "escape" || !headerPressRef.current?.dragging) return;
|
|
590
|
+
event.preventDefault?.();
|
|
591
|
+
event.stopPropagation?.();
|
|
592
|
+
headerPressRef.current = null;
|
|
593
|
+
setColumnDrag(null);
|
|
594
|
+
}, { enabled: dragging, phase: "capture" });
|
|
595
|
+
const releaseHeader = useCallback((event?: HeaderDragEvent) => {
|
|
596
|
+
const press = headerPressRef.current;
|
|
597
|
+
headerPressRef.current = null;
|
|
598
|
+
setColumnDrag(null);
|
|
599
|
+
if (!press) return;
|
|
600
|
+
event?.preventDefault?.();
|
|
601
|
+
event?.stopPropagation?.();
|
|
602
|
+
if (!press.dragging) {
|
|
603
|
+
onHeaderClick?.(press.columnId);
|
|
604
|
+
return;
|
|
605
|
+
}
|
|
606
|
+
const boundary = dropBoundaryAt(event);
|
|
607
|
+
const to = boundary === null ? null : columnDropIndex(press.from, boundary);
|
|
608
|
+
if (to !== null) onColumnMove?.(press.columnId, to);
|
|
609
|
+
}, [dropBoundaryAt, onColumnMove, onHeaderClick]);
|
|
396
610
|
// A frozen board's rows run on past the last column, blank, so scrolled to its far end it starts a column
|
|
397
611
|
// whole beside the frozen one, as each step does (tableScrollStep).
|
|
398
612
|
const scrollContentWidth = contentWidth + (freezeFirstColumn && horizontalScrollbarVisible
|
|
399
613
|
? tableFarEdgePad({ columns: displayColumns, columnGap, horizontalPadding, contentWidth, viewportWidth: measuredViewportWidth })
|
|
400
614
|
: 0);
|
|
615
|
+
const lastColumn = displayColumns.length - 1;
|
|
616
|
+
// The gap's own blank cell, before the column it would land in front of or after the last one; never under a
|
|
617
|
+
// frozen first column, but in its trailing blank cell when the column it lands before is partly behind it, and
|
|
618
|
+
// at the viewport's last cell when the gap after the last column is past it.
|
|
619
|
+
const dropMarkerLeft = columnDrag?.boundary == null ? null : Math.min(
|
|
620
|
+
scrollContentWidth - 1,
|
|
621
|
+
measuredViewportWidth > 0 ? frozenColumnOffset + measuredViewportWidth - 1 : Number.POSITIVE_INFINITY,
|
|
622
|
+
horizontalPadding + Math.max(
|
|
623
|
+
frozenEnd === undefined ? Number.NEGATIVE_INFINITY : frozenEnd - 1,
|
|
624
|
+
columnDrag.boundary <= lastColumn
|
|
625
|
+
? (columnStarts[columnDrag.boundary] ?? 0) - 1
|
|
626
|
+
: (columnStarts[lastColumn] ?? 0) + (displayColumns[lastColumn]?.width ?? 0),
|
|
627
|
+
),
|
|
628
|
+
);
|
|
401
629
|
// Columns out of view past the right edge: the header row ends in "more ⇧→" there, a press on it scrolls to
|
|
402
630
|
// them, and the rows leave its cells blank, so a narrow pane says it has more than it shows. The header's
|
|
403
|
-
// scroll box is as wide as the body's viewport (measuredViewportWidth)
|
|
404
|
-
//
|
|
405
|
-
//
|
|
406
|
-
const
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
631
|
+
// scroll box is as wide as the body's viewport (measuredViewportWidth); the hint is laid over the row, not
|
|
632
|
+
// inside the scroll box, and takes the cell past it first (besideHeader).
|
|
633
|
+
// An empty table has nothing past the edge to scroll to.
|
|
634
|
+
const hintColumns = useMemo(() => displayColumns.map((column) => ({
|
|
635
|
+
width: column.width,
|
|
636
|
+
align: column.align,
|
|
637
|
+
label: sortedLabel(column),
|
|
638
|
+
})), [displayColumns, sortedLabel]);
|
|
639
|
+
const moreColumns = horizontalScrollbarVisible && items.length > 0 ? resolveMoreColumnsHint({
|
|
640
|
+
columns: hintColumns,
|
|
413
641
|
columnGap,
|
|
414
642
|
columnStarts,
|
|
415
643
|
frozenFirstColumn: freezeFirstColumn,
|
|
@@ -433,8 +661,9 @@ export function OpenTuiDataTable<T, C extends DataTableColumn = DataTableColumn>
|
|
|
433
661
|
// A table that cannot scroll sideways fits its own columns; one it cut could never be scrolled to.
|
|
434
662
|
viewportWidth: showHorizontalScrollbar ? measuredViewportWidth : 0,
|
|
435
663
|
widths: displayColumns.map((column) => column.width),
|
|
664
|
+
labels: hintColumns,
|
|
436
665
|
})),
|
|
437
|
-
[columnGap, columnStarts, displayColumns, freezeFirstColumn, horizontalPadding, measuredViewportWidth, moreColumnsReserve, scrollLeft, showHorizontalScrollbar],
|
|
666
|
+
[columnGap, columnStarts, displayColumns, freezeFirstColumn, hintColumns, horizontalPadding, measuredViewportWidth, moreColumnsReserve, scrollLeft, showHorizontalScrollbar],
|
|
438
667
|
);
|
|
439
668
|
const reportVisibleRange = useVisibleRangeEmitter({
|
|
440
669
|
itemCount: items.length,
|
|
@@ -649,14 +878,25 @@ export function OpenTuiDataTable<T, C extends DataTableColumn = DataTableColumn>
|
|
|
649
878
|
onSizeChange={measureContentWidth}
|
|
650
879
|
>
|
|
651
880
|
<Box
|
|
881
|
+
ref={headerRowRef}
|
|
652
882
|
flexDirection="row"
|
|
653
883
|
height={1}
|
|
654
884
|
{...tableContentWidthProps(scrollContentWidth)}
|
|
655
885
|
paddingX={horizontalPadding}
|
|
656
886
|
backgroundColor={colors.panel}
|
|
887
|
+
onMouseDrag={onColumnMove ? dragHeader : undefined}
|
|
888
|
+
onMouseDragEnd={onColumnMove ? releaseHeader : undefined}
|
|
889
|
+
// While the row holds a press, every other mouse event comes here: one with no button held, or a
|
|
890
|
+
// new press (sent to the row itself, not bubbled up from a header), means the release went missing.
|
|
891
|
+
onMouseMove={onColumnMove ? cancelHeaderPress : undefined}
|
|
892
|
+
onMouseDown={onColumnMove ? (event: any) => {
|
|
893
|
+
if (event?.target === headerRowRef.current) cancelHeaderPress();
|
|
894
|
+
} : undefined}
|
|
657
895
|
>
|
|
658
896
|
{displayColumns.map((column, columnIndex) => {
|
|
659
897
|
const frozen = freezeFirstColumn && columnIndex === 0;
|
|
898
|
+
const movable = !!onColumnMove && columnIndex >= anchoredColumns;
|
|
899
|
+
const dragged = columnDrag?.from === columnIndex;
|
|
660
900
|
const columnStart = columnStarts[columnIndex] ?? 0;
|
|
661
901
|
const clip = columnClips?.[columnIndex] ?? null;
|
|
662
902
|
const inset = clip ? clip.inset : freezeFirstColumn && !frozen
|
|
@@ -688,10 +928,17 @@ export function OpenTuiDataTable<T, C extends DataTableColumn = DataTableColumn>
|
|
|
688
928
|
position="relative"
|
|
689
929
|
left={frozen ? frozenColumnOffset : undefined}
|
|
690
930
|
zIndex={frozen ? 1 : undefined}
|
|
691
|
-
backgroundColor={column.headerBackgroundColor ?? colors.panel}
|
|
931
|
+
backgroundColor={dragged ? hoverBg(colors) : column.headerBackgroundColor ?? colors.panel}
|
|
692
932
|
onMouseDown={(event: any) => {
|
|
693
933
|
focusPane();
|
|
694
934
|
onTableMouseDown?.(event);
|
|
935
|
+
if (movable && (event.button ?? 0) === 0) {
|
|
936
|
+
// Sorted on release, unless the press drags the column first.
|
|
937
|
+
event.preventDefault();
|
|
938
|
+
headerPressRef.current = { columnId: column.id, from: columnIndex, startX: event.x, dragging: false };
|
|
939
|
+
capturePointerDrag(nativeRenderer, headerRowRef.current);
|
|
940
|
+
return;
|
|
941
|
+
}
|
|
695
942
|
if (!onHeaderClick) return;
|
|
696
943
|
event.preventDefault();
|
|
697
944
|
onHeaderClick(column.id);
|
|
@@ -699,13 +946,20 @@ export function OpenTuiDataTable<T, C extends DataTableColumn = DataTableColumn>
|
|
|
699
946
|
>
|
|
700
947
|
<Text
|
|
701
948
|
attributes={TextAttributes.BOLD}
|
|
702
|
-
fg={isSorted ? colors.text : column.headerColor ?? colors.textDim}
|
|
949
|
+
fg={dragged ? colors.textBright : isSorted ? colors.text : column.headerColor ?? colors.textDim}
|
|
950
|
+
// A press here may drag the column, which a text selection would take over.
|
|
951
|
+
selectable={onColumnMove ? false : undefined}
|
|
703
952
|
>
|
|
704
953
|
{frozen ? `${" ".repeat(horizontalPadding)}${labelText}${" ".repeat(columnGap)}` : labelText}
|
|
705
954
|
</Text>
|
|
706
955
|
</Box>
|
|
707
956
|
);
|
|
708
957
|
})}
|
|
958
|
+
{dropMarkerLeft !== null ? (
|
|
959
|
+
<Box position="absolute" left={dropMarkerLeft} top={0} width={1} height={1} zIndex={3}>
|
|
960
|
+
<Text fg={colors.borderFocused}>│</Text>
|
|
961
|
+
</Box>
|
|
962
|
+
) : null}
|
|
709
963
|
</Box>
|
|
710
964
|
</ScrollBox>
|
|
711
965
|
{moreColumns ? (
|
|
@@ -768,6 +1022,7 @@ export function OpenTuiDataTable<T, C extends DataTableColumn = DataTableColumn>
|
|
|
768
1022
|
columnGap={columnGap}
|
|
769
1023
|
columnStarts={columnStarts}
|
|
770
1024
|
contentWidth={scrollContentWidth}
|
|
1025
|
+
cellColumns={cellColumns}
|
|
771
1026
|
displayColumns={displayColumns}
|
|
772
1027
|
focusPane={focusPane}
|
|
773
1028
|
frozenColumnOffset={freezeFirstColumn ? frozenColumnOffset : undefined}
|
|
@@ -786,8 +1041,12 @@ export function OpenTuiDataTable<T, C extends DataTableColumn = DataTableColumn>
|
|
|
786
1041
|
rowVersion={getRowVersion?.(item, index)}
|
|
787
1042
|
sectionWidth={sectionWidth}
|
|
788
1043
|
selected={isSelected(item, index)}
|
|
1044
|
+
selectionBg={selectionFill.bg}
|
|
1045
|
+
selectionLit={selectionFill.lit}
|
|
789
1046
|
selectedTextOverridesCellColor={selectedTextOverridesCellColor}
|
|
790
1047
|
columnClips={columnClips}
|
|
1048
|
+
cellWidths={rowCellWidths}
|
|
1049
|
+
columnsKey={columnsKey}
|
|
791
1050
|
/>
|
|
792
1051
|
);
|
|
793
1052
|
}),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { displayWidth } from "../../../../utils/format";
|
|
2
|
-
import { fitTableCellText, tableColumnLeadGap } from "../../table-layout";
|
|
2
|
+
import { fitTableCellText, tableColumnLeadGap, tableColumnStarts } from "../../table-layout";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Where the viewport cuts a column: `inset` cells hidden on its left (past the
|
|
@@ -101,6 +101,11 @@ export function reuseDataTableColumnClips(
|
|
|
101
101
|
* the only sign.
|
|
102
102
|
*/
|
|
103
103
|
const MORE_COLUMNS_LABELS = ["more ⇧→", "⇧→", "→"] as const;
|
|
104
|
+
/** The cells the "more ⇧→" hint takes at the right edge with the blank before it, whole and at its shortest with a key. */
|
|
105
|
+
export const MORE_COLUMNS_HINT_WIDTH = {
|
|
106
|
+
whole: displayWidth(MORE_COLUMNS_LABELS[0]) + 1,
|
|
107
|
+
least: displayWidth(MORE_COLUMNS_LABELS[1]) + 1,
|
|
108
|
+
} as const;
|
|
104
109
|
|
|
105
110
|
export interface MoreColumnsHint {
|
|
106
111
|
/** The cells the hint draws: its label, after a blank unless it takes the last column's own. */
|
|
@@ -164,8 +169,7 @@ export function resolveMoreColumnsHint({
|
|
|
164
169
|
scrollLeft: number;
|
|
165
170
|
viewportWidth: number;
|
|
166
171
|
}): MoreColumnsHint | null {
|
|
167
|
-
|
|
168
|
-
if (columns.length === 0 || viewportWidth < longest * 2) return null;
|
|
172
|
+
if (columns.length === 0 || viewportWidth < MORE_COLUMNS_HINT_WIDTH.whole * 2) return null;
|
|
169
173
|
const right = scrollLeft + viewportWidth;
|
|
170
174
|
const starts = columns.map((_, index) => horizontalPadding + (columnStarts[index] ?? 0));
|
|
171
175
|
if (!hasColumnsPastRightEdge(columns, starts, right)) return null;
|
|
@@ -195,6 +199,31 @@ export function resolveMoreColumnsHint({
|
|
|
195
199
|
return null;
|
|
196
200
|
}
|
|
197
201
|
|
|
202
|
+
/**
|
|
203
|
+
* How many leading columns a table scrolled to its start shows whole, the
|
|
204
|
+
* rows' cells under the "more ⇧→" hint aside (`resolveMoreColumnsHint`).
|
|
205
|
+
*/
|
|
206
|
+
export function columnsShownWhole({
|
|
207
|
+
columns,
|
|
208
|
+
columnGap,
|
|
209
|
+
besideHeader = 0,
|
|
210
|
+
horizontalPadding,
|
|
211
|
+
viewportWidth,
|
|
212
|
+
}: {
|
|
213
|
+
columns: readonly HintColumn[];
|
|
214
|
+
columnGap: number;
|
|
215
|
+
besideHeader?: number;
|
|
216
|
+
horizontalPadding: number;
|
|
217
|
+
viewportWidth: number;
|
|
218
|
+
}): number {
|
|
219
|
+
const columnStarts = tableColumnStarts(columns, columnGap);
|
|
220
|
+
const hint = resolveMoreColumnsHint({ columns, columnGap, columnStarts, besideHeader, horizontalPadding, scrollLeft: 0, viewportWidth });
|
|
221
|
+
const right = viewportWidth - (hint?.reserve ?? 0);
|
|
222
|
+
let count = 0;
|
|
223
|
+
while (count < columns.length && horizontalPadding + columnStarts[count]! + columns[count]!.width <= right) count += 1;
|
|
224
|
+
return count;
|
|
225
|
+
}
|
|
226
|
+
|
|
198
227
|
/**
|
|
199
228
|
* Each column's clip at the current scroll, null for a column shown whole.
|
|
200
229
|
* A frozen first column stays, and what slides under it counts as cut on the
|
|
@@ -211,6 +240,7 @@ export function resolveDataTableColumnClips({
|
|
|
211
240
|
scrollLeft,
|
|
212
241
|
viewportWidth,
|
|
213
242
|
widths,
|
|
243
|
+
labels,
|
|
214
244
|
}: {
|
|
215
245
|
columnGap: number;
|
|
216
246
|
/** Where each column's content starts, from the first column (tableColumnStarts). */
|
|
@@ -223,6 +253,12 @@ export function resolveDataTableColumnClips({
|
|
|
223
253
|
viewportWidth: number;
|
|
224
254
|
/** Each column's drawn width. */
|
|
225
255
|
widths: readonly number[];
|
|
256
|
+
/**
|
|
257
|
+
* Each column's header as drawn, with its alignment. Text the right edge leaves fewer cells than its
|
|
258
|
+
* label shows none of them: a sliver would read as a stray ellipsis, and "more ⇧→" counts the column
|
|
259
|
+
* as past the edge (hasColumnsPastRightEdge).
|
|
260
|
+
*/
|
|
261
|
+
labels?: readonly HintColumn[];
|
|
226
262
|
}): (DataTableColumnClip | null)[] | null {
|
|
227
263
|
if (viewportWidth <= 0 || widths.length === 0) return null;
|
|
228
264
|
const right = scrollLeft + viewportWidth - Math.max(0, rightReserve);
|
|
@@ -235,7 +271,10 @@ export function resolveDataTableColumnClips({
|
|
|
235
271
|
if (start >= left && end <= right) return null;
|
|
236
272
|
cut = true;
|
|
237
273
|
const inset = Math.min(width, Math.max(0, left - start));
|
|
238
|
-
|
|
274
|
+
const shown = Math.max(0, Math.min(end, right) - start - inset);
|
|
275
|
+
const header = labels?.[index];
|
|
276
|
+
const sliver = !!header && (header.align ?? "left") !== "right" && inset + shown < width && shown < displayWidth(header.label);
|
|
277
|
+
return { inset, width: sliver ? 0 : shown };
|
|
239
278
|
});
|
|
240
279
|
return cut ? clips : null;
|
|
241
280
|
}
|