@gloom-sh/terminal 0.20.17 → 0.20.18
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 +3 -1
- package/src/account/auth-dialog.tsx +19 -1
- package/src/account/billing.ts +2 -1
- package/src/account/heard-from-question.tsx +235 -0
- package/src/account/heard-from.ts +97 -0
- package/src/api-client/data.ts +3 -2
- package/src/api-client/heard-from.ts +72 -0
- package/src/api-client/index.ts +63 -6
- package/src/api-client/mna.ts +18 -0
- package/src/api-client/supply-chain.ts +9 -0
- package/src/api-client/types/billing.ts +35 -1
- package/src/app/global-shortcuts.ts +5 -3
- package/src/app/pro-welcome/keys.ts +27 -0
- package/src/app/pro-welcome/model.ts +158 -0
- package/src/app/pro-welcome/row.tsx +176 -0
- package/src/app/pro-welcome/use-pro-welcome.ts +156 -0
- package/src/app/runtime/external-profile-changes.ts +135 -0
- package/src/app.tsx +33 -2
- package/src/architecture/core-builtin-allowlist.json +1 -1
- package/src/architecture/floating-promise-allowlist.json +0 -1
- package/src/architecture/shortcut-labels-allowlist.json +1 -0
- package/src/cli/alert-listing.ts +98 -0
- package/src/cli/commands/market.ts +138 -22
- package/src/cli/commands/overview.ts +7 -1
- package/src/cli/commands/plugins.ts +3 -2
- package/src/cli/commands/search.ts +30 -6
- package/src/cli/context.ts +16 -5
- package/src/cli/csv-export.ts +2 -1
- package/src/cli/desktop-pane-shot.ts +72 -9
- package/src/cli/glossary.ts +64 -10
- package/src/cli/history-demergers.ts +117 -0
- package/src/cli/history-rows.ts +6 -2
- package/src/cli/index.ts +1 -0
- package/src/cli/known-gaps.ts +16 -0
- package/src/cli/known-us-stocks.ts +18 -0
- package/src/cli/listing-arg.ts +105 -15
- package/src/cli/pane-functions/catalog-snapshot-build.ts +83 -0
- package/src/cli/pane-functions/catalog-snapshot.json +866 -0
- package/src/cli/pane-functions/catalog-snapshot.ts +62 -0
- package/src/cli/pane-functions/catalog.ts +50 -16
- package/src/cli/pane-functions/data.ts +16 -4
- package/src/cli/pane-functions/dom.ts +24 -6
- package/src/cli/pane-functions/freshness.ts +17 -1
- package/src/cli/pane-functions/index.ts +100 -42
- package/src/cli/pane-functions/resolver.ts +8 -5
- package/src/cli/pane-functions/screenshot-assessment.ts +30 -7
- package/src/cli/pane-functions/screenshot-payload.ts +21 -0
- package/src/cli/pane-functions/screenshot-render.ts +3 -1
- package/src/cli/quote-answer.ts +32 -16
- package/src/cli/registry.ts +22 -2
- package/src/cli/result.ts +5 -4
- package/src/cli/series-search.ts +45 -6
- package/src/cli/shot-temp-dir.ts +4 -9
- package/src/components/chart/composite/legend.tsx +43 -18
- package/src/components/chart/composite/panel-surface/panel-cursor.tsx +3 -3
- package/src/components/chart/composite/price-axis-labels.tsx +7 -5
- package/src/components/chart-table/header.tsx +9 -0
- package/src/components/chart-table/layout.ts +11 -11
- package/src/components/command-bar/pane-templates/items.ts +17 -1
- package/src/components/command-bar/routes/root/provider-search.ts +10 -1
- package/src/components/command-bar/routes/root/results.ts +34 -2
- package/src/components/command-bar/routes/root/runtime.ts +8 -1
- package/src/components/command-bar/routes/ticker-search/route.ts +5 -0
- package/src/components/command-bar/workflow/alert.ts +19 -8
- package/src/components/data-table/view.tsx +15 -2
- package/src/components/form-modal/content.tsx +9 -4
- package/src/components/index.ts +1 -1
- package/src/components/layout/header.tsx +9 -5
- package/src/components/layout/pane/capture-status.ts +6 -0
- package/src/components/layout/pane/footer/index.tsx +2 -0
- package/src/components/layout/pane/footer/model.ts +113 -15
- package/src/components/layout/pane/header.tsx +16 -2
- package/src/components/market-board/index.tsx +4 -2
- package/src/components/onboarding/onboarding-frame.tsx +6 -2
- package/src/components/onboarding/onboarding-keyboard.ts +7 -1
- package/src/components/onboarding/onboarding-wizard.tsx +3 -1
- package/src/components/onboarding/portfolio-step/positions-panel.tsx +24 -15
- package/src/components/onboarding/setup-cards.ts +36 -0
- package/src/components/onboarding/use-onboarding-progress.ts +22 -1
- package/src/components/onboarding/wizard-account.ts +6 -1
- package/src/components/onboarding/wizard-model.ts +32 -6
- package/src/components/onboarding/wizard-positions.ts +1 -1
- package/src/components/sign-in-gate.tsx +3 -1
- package/src/components/toggle-list.tsx +6 -8
- package/src/components/ui/confirm-dialog.tsx +47 -7
- package/src/components/ui/data-table/types.ts +8 -0
- package/src/components/ui/display.tsx +17 -2
- package/src/components/ui/index.ts +1 -1
- package/src/components/ui/stat-grid.tsx +4 -0
- package/src/components/ui/status.tsx +13 -1
- package/src/components/ui/table-layout.ts +2 -1
- package/src/components/use-pane-notice-footer.tsx +16 -3
- package/src/data/config/store/index.ts +31 -0
- package/src/data/config/store/node.ts +61 -11
- package/src/data/config/store/normalize.ts +4 -6
- package/src/data/config/store/shared-file.ts +309 -0
- package/src/data/profile-merge.ts +299 -0
- package/src/data/sqlite/checkpointer.ts +11 -1
- package/src/data/sqlite/database.ts +1 -1
- package/src/data/ticker-repository.ts +134 -10
- package/src/data/ticker-store.ts +67 -0
- package/src/data/ticker-writes.ts +5 -0
- package/src/i18n/es.ts +27 -0
- package/src/i18n/ja.ts +27 -0
- package/src/i18n/ko.ts +27 -0
- package/src/i18n/zh-cn.ts +27 -0
- package/src/i18n/zh-tw.ts +27 -0
- package/src/layout-marketplace/gallery-desktop.tsx +2 -2
- package/src/market-data/ah-pair.ts +103 -0
- package/src/market-data/depositary-pair.ts +6 -2
- package/src/market-data/hooks.tsx +33 -2
- package/src/market-data/market/change-basis.ts +2 -1
- package/src/market-data/market/header-market.ts +11 -0
- package/src/market-data/split-terms.ts +28 -0
- package/src/plugins/builtin/account-management/footer.ts +1 -1
- package/src/plugins/builtin/account-management/keyboard.ts +4 -0
- package/src/plugins/builtin/account-management/model.ts +1 -0
- package/src/plugins/builtin/account-management/pane.tsx +75 -7
- package/src/plugins/builtin/account-management/payment-recovery-row.tsx +12 -5
- package/src/plugins/builtin/account-management/pro-cancel.tsx +197 -0
- package/src/plugins/builtin/account-management/trial-cancel.ts +1 -1
- package/src/plugins/builtin/alerts/cli-move.ts +2 -2
- package/src/plugins/builtin/alerts/cli.ts +36 -30
- package/src/plugins/builtin/alerts/constants.ts +10 -0
- package/src/plugins/builtin/alerts/earnings-listing.ts +20 -0
- package/src/plugins/builtin/alerts/format.ts +24 -8
- package/src/plugins/builtin/alerts/index.tsx +38 -9
- package/src/plugins/builtin/alerts/move-checks.ts +7 -0
- package/src/plugins/builtin/alerts/pane.tsx +1 -1
- package/src/plugins/builtin/alerts/quotes.ts +26 -2
- package/src/plugins/builtin/alerts/scheduled.ts +6 -1
- package/src/plugins/builtin/alerts/types.ts +7 -0
- package/src/plugins/builtin/analytics/manual-value.ts +61 -0
- package/src/plugins/builtin/analytics/risk-book.ts +7 -7
- package/src/plugins/builtin/analytics/risk-client.ts +26 -13
- package/src/plugins/builtin/analytics/risk-headless.ts +13 -8
- package/src/plugins/builtin/analytics/risk-model.ts +92 -4
- package/src/plugins/builtin/analytics/risk-pane.tsx +85 -38
- package/src/plugins/builtin/awards/pane.tsx +1 -1
- package/src/plugins/builtin/broker-trading/orders.tsx +2 -2
- package/src/plugins/builtin/central-bank-rates/model.ts +8 -2
- package/src/plugins/builtin/central-bank-rates/pane.tsx +5 -3
- package/src/plugins/builtin/chart-composer/cli-options.ts +4 -2
- package/src/plugins/builtin/chart-composer/data-catalog-pane.tsx +2 -6
- package/src/plugins/builtin/chart-composer/pane.tsx +5 -2
- package/src/plugins/builtin/cloud/auth-actions.tsx +11 -6
- package/src/plugins/builtin/cloud/company-picker.tsx +5 -3
- package/src/plugins/builtin/cloud/upgrade-command.ts +1 -1
- package/src/plugins/builtin/company-kpis/headless.ts +9 -4
- package/src/plugins/builtin/company-kpis/latest.ts +45 -0
- package/src/plugins/builtin/company-kpis/model.ts +38 -8
- package/src/plugins/builtin/company-kpis/pane.tsx +22 -8
- package/src/plugins/builtin/composite/alt-data.ts +20 -0
- package/src/plugins/builtin/composite/application.ts +14 -0
- package/src/plugins/builtin/composite/broker.ts +12 -0
- package/src/plugins/builtin/composite/credit.ts +33 -0
- package/src/plugins/builtin/composite/crypto.ts +10 -0
- package/src/plugins/builtin/composite/earnings.ts +12 -0
- package/src/plugins/builtin/composite/filings.ts +13 -0
- package/src/plugins/builtin/composite/futures-commodities.ts +23 -0
- package/src/plugins/builtin/composite/global-markets.ts +12 -0
- package/src/plugins/builtin/composite/options-volatility.ts +23 -0
- package/src/plugins/builtin/composite/ownership.ts +23 -0
- package/src/plugins/builtin/composite/portfolio.ts +10 -0
- package/src/plugins/builtin/composite/quant.ts +15 -0
- package/src/plugins/builtin/composite/rates-macro.ts +30 -0
- package/src/plugins/builtin/composite/screeners.ts +11 -0
- package/src/plugins/builtin/composite/shared.ts +11 -0
- package/src/plugins/builtin/composite/ticker-core.ts +36 -0
- package/src/plugins/builtin/congress-trades/headless.ts +31 -3
- package/src/plugins/builtin/correlation/index.tsx +13 -17
- package/src/plugins/builtin/correlation/matrix/model.ts +18 -0
- package/src/plugins/builtin/dividend-yield/client.ts +57 -16
- package/src/plugins/builtin/dividend-yield/headless.ts +17 -11
- package/src/plugins/builtin/dividend-yield/model.ts +4 -3
- package/src/plugins/builtin/dividend-yield/pane.tsx +22 -18
- package/src/plugins/builtin/dividend-yield/ranking.ts +1 -1
- package/src/plugins/builtin/dividend-yield/types.ts +4 -0
- package/src/plugins/builtin/dividend-yield/view.ts +23 -12
- package/src/plugins/builtin/earnings/fiscal-quarter.ts +39 -0
- package/src/plugins/builtin/earnings/headless.ts +7 -4
- package/src/plugins/builtin/earnings/history-model.ts +6 -4
- package/src/plugins/builtin/earnings/history-table.ts +4 -3
- package/src/plugins/builtin/earnings-calls/pane.tsx +8 -2
- package/src/plugins/builtin/econ/calendar-model.ts +16 -0
- package/src/plugins/builtin/econ/index.tsx +3 -0
- package/src/plugins/builtin/equity-screener/headless.ts +4 -1
- package/src/plugins/builtin/equity-screener/model.ts +7 -6
- package/src/plugins/builtin/estimate-revisions/headless.ts +1 -1
- package/src/plugins/builtin/exposure/model.ts +10 -0
- package/src/plugins/builtin/exposure/pane.tsx +10 -3
- package/src/plugins/builtin/fx-matrix/amount.ts +15 -1
- package/src/plugins/builtin/fx-matrix/headless.ts +12 -6
- package/src/plugins/builtin/fx-matrix/index.tsx +23 -5
- package/src/plugins/builtin/fx-matrix/settings.ts +9 -4
- package/src/plugins/builtin/kelly-sizer/pane.tsx +9 -4
- package/src/plugins/builtin/market-valuation/pane.tsx +22 -10
- package/src/plugins/builtin/mna/detail.tsx +67 -6
- package/src/plugins/builtin/mna/headless.ts +128 -13
- package/src/plugins/builtin/mna/model.ts +219 -16
- package/src/plugins/builtin/mna/pane.tsx +34 -6
- package/src/plugins/builtin/money-markets/model.ts +14 -5
- package/src/plugins/builtin/money-markets/pane.tsx +4 -3
- package/src/plugins/builtin/news/wire/news/footer.ts +3 -8
- package/src/plugins/builtin/options-scenario/csp-screen-pane.tsx +22 -6
- package/src/plugins/builtin/options-scenario/csp-screen.ts +39 -12
- package/src/plugins/builtin/options-scenario/strategy-screen.ts +7 -5
- package/src/plugins/builtin/pe-band/client.ts +13 -1
- package/src/plugins/builtin/pe-band/headless.ts +2 -2
- package/src/plugins/builtin/pe-band/model.ts +63 -10
- package/src/plugins/builtin/pe-band/pane.tsx +5 -5
- package/src/plugins/builtin/portfolio-list/allocation-rows.ts +26 -7
- package/src/plugins/builtin/portfolio-list/cli/portfolio-command.ts +66 -13
- package/src/plugins/builtin/portfolio-list/cli/render.ts +76 -33
- package/src/plugins/builtin/portfolio-list/headless.ts +69 -22
- package/src/plugins/builtin/portfolio-list/pane/data.ts +3 -3
- package/src/plugins/builtin/portfolio-list/pane/index.tsx +29 -14
- package/src/plugins/builtin/portfolio-list/summary/index.tsx +2 -2
- package/src/plugins/builtin/relative-rotation/pane.tsx +2 -3
- package/src/plugins/builtin/research/corporate-actions-pane.tsx +5 -1
- package/src/plugins/builtin/research/event-model.ts +31 -13
- package/src/plugins/builtin/research/headless.ts +8 -1
- package/src/plugins/builtin/research/relative-valuation-pane.tsx +19 -17
- package/src/plugins/builtin/sectors/index.tsx +6 -9
- package/src/plugins/builtin/shared/cloud-upgrade.ts +1 -1
- package/src/plugins/builtin/shared/earnings-report.ts +19 -4
- package/src/plugins/builtin/shared/report-freshness.ts +2 -3
- package/src/plugins/builtin/supply-chain/client.ts +34 -9
- package/src/plugins/builtin/supply-chain/evidence.ts +3 -2
- package/src/plugins/builtin/supply-chain/flow.tsx +4 -3
- package/src/plugins/builtin/supply-chain/graph-model.ts +14 -7
- package/src/plugins/builtin/supply-chain/graph-pane.tsx +3 -1
- package/src/plugins/builtin/supply-chain/graph.tsx +6 -3
- package/src/plugins/builtin/supply-chain/headless.ts +19 -4
- package/src/plugins/builtin/supply-chain/model.ts +50 -6
- package/src/plugins/builtin/supply-chain/pane.tsx +76 -16
- package/src/plugins/builtin/ticker-detail/adr-pair/ah.ts +62 -0
- package/src/plugins/builtin/ticker-detail/adr-pair/headless.ts +119 -20
- package/src/plugins/builtin/ticker-detail/adr-pair/model.ts +51 -1
- package/src/plugins/builtin/ticker-detail/adr-pair/tab.tsx +25 -14
- package/src/plugins/builtin/ticker-detail/overview/model.ts +17 -1
- package/src/plugins/builtin/ticker-detail/overview/pane.tsx +4 -0
- package/src/plugins/builtin/ticker-detail/overview-tab.tsx +9 -2
- package/src/plugins/builtin/ticker-detail/quote-monitor/card.tsx +9 -2
- package/src/plugins/builtin/ticker-detail/quote-monitor/index.tsx +5 -2
- package/src/plugins/builtin/volatility/model.ts +17 -0
- package/src/plugins/builtin/volatility/pane.tsx +13 -4
- package/src/plugins/builtin/world-indices/index.tsx +2 -0
- package/src/plugins/builtin/world-indices/table.tsx +15 -0
- package/src/plugins/builtin/world-venue-map/evidence.ts +3 -2
- package/src/plugins/builtin/world-venue-map/headless.ts +28 -16
- package/src/plugins/builtin/world-venue-map/index.ts +19 -6
- package/src/plugins/builtin/world-venue-map/layered-pane.tsx +9 -5
- package/src/plugins/builtin/world-venue-map/layers.ts +33 -11
- package/src/plugins/builtin/world-venue-map/map.tsx +12 -0
- package/src/plugins/builtin/world-venue-map/pane.tsx +35 -6
- package/src/plugins/builtin/world-venue-map/place.ts +119 -0
- package/src/plugins/catalog-data.ts +20 -0
- package/src/plugins/catalog-lazy.ts +51 -0
- package/src/plugins/catalog-ui.ts +16 -18
- package/src/plugins/host-smoke.ts +5 -2
- package/src/portfolio/allocation.ts +79 -19
- package/src/portfolio/cash-balances.ts +76 -0
- package/src/portfolio/mutations.ts +43 -8
- package/src/public/__snapshots__/public-api.test.ts.snap +1 -0
- package/src/renderers/desktop/window-layouts.ts +14 -0
- package/src/renderers/dom/data-table/row.tsx +2 -0
- package/src/renderers/dom/host/tabs.tsx +57 -8
- package/src/renderers/dom/styles.css +13 -5
- package/src/renderers/electrobun/bun/desktop/backend-requests.ts +4 -0
- package/src/renderers/electrobun/bun/desktop/backend.ts +22 -1
- package/src/renderers/electrobun/bun/window/native-min-size.ts +6 -1
- package/src/renderers/electrobun/shared/protocol.ts +4 -0
- package/src/renderers/electrobun/view/cli-pane-shot-frame.tsx +50 -12
- package/src/renderers/electrobun/view/remote/ticker-repository.ts +10 -0
- package/src/series/standalone-catalog.ts +5 -4
- package/src/series/standalone.ts +13 -7
- package/src/sources/gloomberb-cloud/index.ts +14 -3
- package/src/sources/gloomberb-cloud/perpetuals.ts +60 -3
- package/src/sources/provider-router/financials.ts +20 -13
- package/src/sources/provider-router/index.ts +4 -0
- package/src/sources/provider-router/search.ts +1 -0
- package/src/sync/collections-contributor.ts +3 -1
- package/src/sync/config-merge.ts +10 -1
- package/src/sync/sanitize.ts +26 -2
- package/src/tickers/company-name-listing.ts +16 -2
- package/src/tickers/listing-fate.ts +12 -8
- package/src/tickers/renamed-listings.ts +43 -10
- package/src/tickers/search/home-listing.ts +28 -0
- package/src/tickers/search/index.ts +19 -7
- package/src/tickers/terminal-codes.ts +11 -1
- package/src/time-series/resolve.ts +3 -1
- package/src/time-series/spec.ts +2 -2
- package/src/time-series/types.ts +1 -1
- package/src/types/data-provider.ts +11 -0
- package/src/types/financials.ts +39 -3
- package/src/types/ticker.ts +10 -2
- package/src/utils/cli-output.ts +1 -1
- package/src/utils/declared-dividends.ts +13 -1
- package/src/utils/dividend-cash.ts +5 -1
- package/src/utils/forward-dividend.ts +4 -3
- package/src/utils/remove-folder.ts +37 -0
- package/src/utils/trailing-dividend.ts +1 -1
- package/src/plugins/builtin/composite-plugins.ts +0 -285
|
@@ -36,8 +36,8 @@ export interface ToggleListProps {
|
|
|
36
36
|
remoteMetadata?: Record<string, unknown>;
|
|
37
37
|
/**
|
|
38
38
|
* The terminal row's width in cells. With it, a label and detail that do
|
|
39
|
-
* not both fit are cut with an ellipsis, the
|
|
40
|
-
*
|
|
39
|
+
* not both fit are cut with an ellipsis, the detail first, and a
|
|
40
|
+
* two-cell gap always parts them; without it they are
|
|
41
41
|
* drawn whole.
|
|
42
42
|
*/
|
|
43
43
|
width?: number;
|
|
@@ -46,8 +46,6 @@ export interface ToggleListProps {
|
|
|
46
46
|
/** The checkbox's `> [ ] ` before a label, and the gap kept before the detail. */
|
|
47
47
|
const CHECKBOX_PREFIX = 6;
|
|
48
48
|
const DETAIL_GAP = 2;
|
|
49
|
-
/** The label keeps this much before the detail is cut. */
|
|
50
|
-
const LABEL_MIN = 10;
|
|
51
49
|
|
|
52
50
|
/** Words that fit `width`, then an ellipsis: a list of codes is never cut inside one. */
|
|
53
51
|
function clipWords(text: string, width: number): string {
|
|
@@ -64,15 +62,15 @@ function clipWords(text: string, width: number): string {
|
|
|
64
62
|
|
|
65
63
|
/**
|
|
66
64
|
* A terminal toggle row's label and detail, cut to fit `width` with an
|
|
67
|
-
* ellipsis: the
|
|
68
|
-
* detail, at a word. Whole when they fit.
|
|
65
|
+
* ellipsis: the detail gives way first, at a word. Whole when they fit.
|
|
69
66
|
*/
|
|
70
67
|
export function fitToggleRow(label: string, detail: string | undefined, width: number): { label: string; detail: string | undefined } {
|
|
71
68
|
const room = Math.max(0, width - CHECKBOX_PREFIX);
|
|
72
69
|
if (!detail) return { label: clipToDisplayWidth(label, room), detail };
|
|
73
70
|
const available = Math.max(0, room - DETAIL_GAP);
|
|
74
|
-
const labelWidth = Math.min(displayWidth(label),
|
|
75
|
-
|
|
71
|
+
const labelWidth = Math.min(displayWidth(label), available);
|
|
72
|
+
const fittedDetail = clipWords(detail, Math.max(0, available - labelWidth));
|
|
73
|
+
return { label: clipToDisplayWidth(label, fittedDetail ? labelWidth : room), detail: fittedDetail || undefined };
|
|
76
74
|
}
|
|
77
75
|
|
|
78
76
|
function DesktopToggleRow({
|
|
@@ -4,7 +4,7 @@ import { colors } from "../../theme/colors";
|
|
|
4
4
|
import { t, tf } from "../../i18n";
|
|
5
5
|
import { type DialogApi, type PromptContext, useDialogKeyboard } from "../../ui/dialog";
|
|
6
6
|
import type { InputRenderable } from "../../ui/host";
|
|
7
|
-
import type
|
|
7
|
+
import { useViewport, type KeyEventLike } from "../../react/input";
|
|
8
8
|
import { isPlainKey } from "../../utils/keyboard";
|
|
9
9
|
import { Button, type ButtonVariant } from "./button";
|
|
10
10
|
import { DialogActions } from "./dialog-actions";
|
|
@@ -78,10 +78,20 @@ export interface ConfirmDialogProps extends PromptContext<boolean> {
|
|
|
78
78
|
question?: ConfirmDialogQuestion;
|
|
79
79
|
/** With `question`: what it got, called as the dialog confirms. */
|
|
80
80
|
onAnswer?: (answer: ConfirmDialogAnswer) => void;
|
|
81
|
+
/**
|
|
82
|
+
* For a confirm whose two buttons are both ways on, such as an offer's
|
|
83
|
+
* accept and continue: Esc and the desktop close button leave without
|
|
84
|
+
* either answer (the prompt resolves undefined) instead of pressing the
|
|
85
|
+
* cancel button. See `confirmDialogChoice`.
|
|
86
|
+
*/
|
|
87
|
+
escapeLeaves?: boolean;
|
|
88
|
+
/** Buttons that do not fit the dialog's width (long labels on a phone) wrap to another row. */
|
|
89
|
+
wrapButtons?: boolean;
|
|
81
90
|
}
|
|
82
91
|
|
|
83
92
|
export function ConfirmDialog({
|
|
84
93
|
resolve,
|
|
94
|
+
dismiss,
|
|
85
95
|
title,
|
|
86
96
|
body,
|
|
87
97
|
confirmLabel,
|
|
@@ -97,9 +107,15 @@ export function ConfirmDialog({
|
|
|
97
107
|
defaultAction = "confirm",
|
|
98
108
|
question,
|
|
99
109
|
onAnswer,
|
|
110
|
+
escapeLeaves = false,
|
|
111
|
+
wrapButtons = false,
|
|
100
112
|
}: ConfirmDialogProps) {
|
|
101
113
|
const enterCancels = defaultAction === "cancel";
|
|
102
114
|
const desktop = useUiHost().kind === "desktop-web";
|
|
115
|
+
// The terminal's dialog box is the window less its border and padding: a
|
|
116
|
+
// narrow terminal wraps the words inside it rather than past its edge.
|
|
117
|
+
const viewport = useViewport();
|
|
118
|
+
const terminalWidth = Math.max(16, Math.min(width, viewport.width - 8));
|
|
103
119
|
const openedAt = useRef(Date.now());
|
|
104
120
|
const answer = useQuestionAnswer(question);
|
|
105
121
|
const confirm = useCallback(() => {
|
|
@@ -107,6 +123,7 @@ export function ConfirmDialog({
|
|
|
107
123
|
resolve(true);
|
|
108
124
|
}, [answer, onAnswer, question, resolve]);
|
|
109
125
|
const cancel = useCallback(() => resolve(false), [resolve]);
|
|
126
|
+
const leave = escapeLeaves ? dismiss : cancel;
|
|
110
127
|
|
|
111
128
|
// Every key, even with a field focused under the dialog: a confirm has
|
|
112
129
|
// nothing to type into but its own note, so nothing below should take one.
|
|
@@ -120,7 +137,7 @@ export function ConfirmDialog({
|
|
|
120
137
|
event.stopPropagation();
|
|
121
138
|
if (event.name === "escape") {
|
|
122
139
|
event.preventDefault();
|
|
123
|
-
|
|
140
|
+
leave();
|
|
124
141
|
return;
|
|
125
142
|
}
|
|
126
143
|
if (busy) {
|
|
@@ -162,27 +179,31 @@ export function ConfirmDialog({
|
|
|
162
179
|
onPress={confirm}
|
|
163
180
|
/>
|
|
164
181
|
);
|
|
165
|
-
|
|
182
|
+
// With Esc stepping out, `n` is the cancel button's key.
|
|
183
|
+
const cancelKey = enterCancels ? "Enter" : escapeLeaves ? "N" : "Esc";
|
|
184
|
+
const cancelButton = <Button label={cancelLabel} variant={enterCancels ? "primary" : "secondary"} disabled={busy} desktopShortcut={keys ? cancelKey : undefined} onPress={cancel} />;
|
|
166
185
|
const noteKey = question?.notePlaceholder !== undefined;
|
|
167
186
|
const keyLine = enterCancels
|
|
168
187
|
? noteKey
|
|
169
188
|
? tf("y {action} · Tab note · Enter or Esc {cancel}", { action: t(confirmLabel).toLowerCase(), cancel: t(cancelLabel).toLowerCase() })
|
|
170
189
|
: tf("y {action} · Enter or Esc {cancel}", { action: t(confirmLabel).toLowerCase(), cancel: t(cancelLabel).toLowerCase() })
|
|
171
|
-
:
|
|
190
|
+
: escapeLeaves
|
|
191
|
+
? tf("Enter {action} · n {cancel} · Esc close", { action: t(confirmLabel).toLowerCase(), cancel: t(cancelLabel).toLowerCase() })
|
|
192
|
+
: tf("Enter {action} · Esc cancel", { action: t(confirmLabel).toLowerCase() });
|
|
172
193
|
return (
|
|
173
194
|
<DialogFrame
|
|
174
195
|
title={title}
|
|
175
196
|
footer={footer ?? keyLine}
|
|
176
197
|
desktopFooter={null}
|
|
177
198
|
// The terminal's Cancel is its mouse close already: a second close in the title would only repeat it.
|
|
178
|
-
onClose={desktop ? onClose : undefined}
|
|
199
|
+
onClose={desktop ? (escapeLeaves ? dismiss : onClose) : undefined}
|
|
179
200
|
>
|
|
180
|
-
<Box flexDirection="column" {...(desktop ? { style: { width: fitDialogWidth(width) } } : { width })}>
|
|
201
|
+
<Box flexDirection="column" {...(desktop ? { style: { width: fitDialogWidth(width) } } : { width: terminalWidth })}>
|
|
181
202
|
{renderBody(body)}
|
|
182
203
|
{question && (
|
|
183
204
|
<>
|
|
184
205
|
<Box height={1} />
|
|
185
|
-
<QuestionFields question={question} answer={answer} width={
|
|
206
|
+
<QuestionFields question={question} answer={answer} width={terminalWidth} disabled={busy} />
|
|
186
207
|
</>
|
|
187
208
|
)}
|
|
188
209
|
{status && (
|
|
@@ -194,6 +215,7 @@ export function ConfirmDialog({
|
|
|
194
215
|
<Box height={1} />
|
|
195
216
|
<DialogActions
|
|
196
217
|
alignEnd={formButtons}
|
|
218
|
+
wrap={wrapButtons}
|
|
197
219
|
hints={question && keys ? { keys: [{ key: "↑↓", label: "choose" }, ...noteKey ? [{ key: "Tab", label: "note" }] : []] } : undefined}
|
|
198
220
|
>
|
|
199
221
|
{formButtons ? cancelButton : confirmButton}
|
|
@@ -410,6 +432,24 @@ export async function confirmDialogWithAnswer(
|
|
|
410
432
|
return confirmed === true ? answer : null;
|
|
411
433
|
}
|
|
412
434
|
|
|
435
|
+
/**
|
|
436
|
+
* A confirm whose two buttons are both ways on (an offer's accept and its
|
|
437
|
+
* continue): "confirm" or "cancel" for the button pressed, null when the
|
|
438
|
+
* person stepped out instead (Esc, a click outside, the desktop close button,
|
|
439
|
+
* a failed dialog).
|
|
440
|
+
*/
|
|
441
|
+
export async function confirmDialogChoice(
|
|
442
|
+
dialog: DialogApi,
|
|
443
|
+
{ closeOnClickOutside = true, ...props }: ConfirmDialogOptions,
|
|
444
|
+
): Promise<"confirm" | "cancel" | null> {
|
|
445
|
+
const answer = await dialog.prompt<boolean>({
|
|
446
|
+
closeOnClickOutside,
|
|
447
|
+
content: (context) => <ConfirmDialog {...context} {...props} escapeLeaves />,
|
|
448
|
+
}).catch(logFailure("ui.confirm-dialog", "Open confirm dialog failed"));
|
|
449
|
+
if (answer === true) return "confirm";
|
|
450
|
+
return answer === false ? "cancel" : null;
|
|
451
|
+
}
|
|
452
|
+
|
|
413
453
|
function renderBody(body: ReactNode | string | string[]): ReactNode {
|
|
414
454
|
if (Array.isArray(body)) {
|
|
415
455
|
return body.map((line, index) => (
|
|
@@ -62,6 +62,14 @@ export interface DataTableCell {
|
|
|
62
62
|
* header: MCAP (USD).
|
|
63
63
|
*/
|
|
64
64
|
valueUnit?: string;
|
|
65
|
+
/**
|
|
66
|
+
* This row has no value here yet, with nothing missing: it comes after an
|
|
67
|
+
* event the row is still waiting on (an economic release not yet out). The
|
|
68
|
+
* column-wide form is DataTableColumn.mayBeBlank; this one is for a column
|
|
69
|
+
* whose other rows must have the value. `shot --strict` counts a column
|
|
70
|
+
* blank in every other row as data the pane lost, and leaves this row out.
|
|
71
|
+
*/
|
|
72
|
+
mayBeBlank?: boolean;
|
|
65
73
|
content?: ReactNode;
|
|
66
74
|
/**
|
|
67
75
|
* The cells `content` takes to show whole in the terminal, where a table
|
|
@@ -5,6 +5,7 @@ import { blendForContrast, higherContrast } from "../../theme/color-utils";
|
|
|
5
5
|
import { useThemeColors } from "../../theme/theme-context";
|
|
6
6
|
import { Box, Text, TextAttributes, useUiCapabilities } from "../../ui";
|
|
7
7
|
import { truncateToDisplayWidth } from "../../utils/format";
|
|
8
|
+
import { clipKeepingEnd } from "./table-layout";
|
|
8
9
|
import { CountryFlagLead } from "./country-flag";
|
|
9
10
|
import { usePaneLinkMenuEntry } from "./external-link";
|
|
10
11
|
import { ICON_GLYPHS, Icon, type IconName } from "./icon";
|
|
@@ -96,6 +97,12 @@ export interface ClippedTextProps {
|
|
|
96
97
|
cut?: (text: string, width: number) => string;
|
|
97
98
|
/** The desktop wraps it onto more lines instead (a message, a description); the terminal still cuts it. */
|
|
98
99
|
wrap?: boolean;
|
|
100
|
+
/**
|
|
101
|
+
* The end of `text` a cut keeps whole, as a table cell's `keepEnd` does: what tells it apart from its
|
|
102
|
+
* neighbours ("Customer 1", "Customer A"). The cut shortens what comes before it, in the terminal by its
|
|
103
|
+
* count of cells and on the desktop and the web by CSS.
|
|
104
|
+
*/
|
|
105
|
+
keepEnd?: string | null;
|
|
99
106
|
}
|
|
100
107
|
|
|
101
108
|
/**
|
|
@@ -104,10 +111,18 @@ export interface ClippedTextProps {
|
|
|
104
111
|
* `wrap`. Its box (or its row, with the siblings that keep their room) has to
|
|
105
112
|
* bound it there.
|
|
106
113
|
*/
|
|
107
|
-
export function ClippedText({ text, width, fg, attributes, flex = "0 1 auto", lead = "", cut = truncateToDisplayWidth, wrap = false }: ClippedTextProps) {
|
|
114
|
+
export function ClippedText({ text, width, fg, attributes, flex = "0 1 auto", lead = "", cut = truncateToDisplayWidth, wrap = false, keepEnd = null }: ClippedTextProps) {
|
|
108
115
|
const { nativePaneChrome } = useUiCapabilities();
|
|
109
116
|
const ink = { ...(fg === undefined ? {} : { fg }), ...(attributes === undefined ? {} : { attributes }) };
|
|
110
|
-
|
|
117
|
+
const end = keepEnd && text.endsWith(keepEnd) && text.length > keepEnd.length ? keepEnd : null;
|
|
118
|
+
if (!nativePaneChrome) return <Text {...ink}>{`${lead}${end ? clipKeepingEnd(text, width, end) : cut(text, width)}`}</Text>;
|
|
119
|
+
// The desktop clips what comes before the end, which keeps its own room beside it.
|
|
120
|
+
if (end && !wrap) {
|
|
121
|
+
return <Box flexDirection="row" style={{ minWidth: 0, flex, overflow: "hidden" }}>
|
|
122
|
+
<Text {...ink} style={{ ...NATIVE_CLIP_STYLE, flex: "0 1 auto" }}>{`${lead}${text.slice(0, -end.length)}`}</Text>
|
|
123
|
+
<Text {...ink} style={{ flex: "0 0 auto", whiteSpace: "pre" }}>{end}</Text>
|
|
124
|
+
</Box>;
|
|
125
|
+
}
|
|
111
126
|
return wrap
|
|
112
127
|
? <Text {...ink} wrapText style={{ minWidth: 0, flex }}>{`${lead}${text}`}</Text>
|
|
113
128
|
: <Text {...ink} style={{ ...NATIVE_CLIP_STYLE, flex }}>{`${lead}${text}`}</Text>;
|
|
@@ -62,7 +62,7 @@ export { Tabs } from "./tabs";
|
|
|
62
62
|
export type { TabsProps } from "./tabs";
|
|
63
63
|
export { SegmentedControl } from "./toggle";
|
|
64
64
|
export type { SegmentedControlProps } from "./toggle";
|
|
65
|
-
export { EmptyState, PaneStatusBody, Notice, loadingText, unavailableText } from "./status";
|
|
65
|
+
export { EmptyState, PaneStatusBody, Notice, RowNote, loadingText, unavailableText } from "./status";
|
|
66
66
|
export type { EmptyStateProps, PaneStatusBodyProps, NoticeProps, StatusRetry } from "./status";
|
|
67
67
|
export { Badge, BulletList, Divider, FigureList, KeyValueRow, Prose, READING_WIDTH, Section, SectionHeading } from "./display";
|
|
68
68
|
export { Card } from "./card";
|
|
@@ -25,6 +25,8 @@ export function statToneColor(tone: StatTone | undefined, colors: ThemeColors):
|
|
|
25
25
|
*/
|
|
26
26
|
export interface StatItem {
|
|
27
27
|
id?: string;
|
|
28
|
+
/** Opt in only for figures that must survive ahead of table rows and pass screenshot certification. */
|
|
29
|
+
essential?: boolean;
|
|
28
30
|
label: string;
|
|
29
31
|
value: string;
|
|
30
32
|
detail?: string;
|
|
@@ -380,6 +382,7 @@ export function StatGrid({ items, width, columns: columnsProp, maxLines }: StatG
|
|
|
380
382
|
data-wide={item.wide ? "true" : undefined}
|
|
381
383
|
data-wrapped="true"
|
|
382
384
|
data-gloom-stat-id={item.id}
|
|
385
|
+
data-gloom-essential={item.essential === true ? "true" : undefined}
|
|
383
386
|
>
|
|
384
387
|
<Text fg={colors.textDim} data-gloom-role="stat-grid-label">
|
|
385
388
|
{nativePaneChrome ? label : labelText(label, labelWidth)}
|
|
@@ -434,6 +437,7 @@ export function StatGrid({ items, width, columns: columnsProp, maxLines }: StatG
|
|
|
434
437
|
data-gloom-role="stat-grid-cell"
|
|
435
438
|
data-wide={item.wide ? "true" : undefined}
|
|
436
439
|
data-gloom-stat-id={item.id}
|
|
440
|
+
data-gloom-essential={item.essential === true ? "true" : undefined}
|
|
437
441
|
// The last cell of a short row takes the columns left over, so the
|
|
438
442
|
// band never ends in an empty cell.
|
|
439
443
|
style={nativePaneChrome && !item.wide && index === row.length - 1 && row.length < columns
|
|
@@ -243,13 +243,14 @@ export interface NoticeProps {
|
|
|
243
243
|
export function Notice({ children, tone = "warning", variant = "inline" }: NoticeProps) {
|
|
244
244
|
const colors = useThemeColors();
|
|
245
245
|
const native = useUiCapabilities().nativePaneChrome;
|
|
246
|
+
const { id, flush } = useFlushInPane(native === true && variant === "inline");
|
|
246
247
|
const color = tone === "muted" ? colors.textDim : colors[tone];
|
|
247
248
|
const status = tone === "negative" ? "error" : "notice";
|
|
248
249
|
const body = typeof children === "string" ? readableError(children) : children;
|
|
249
250
|
// Inline feedback keeps its original single-text shape: a flex row here collapses inside content-sized parents.
|
|
250
251
|
if (variant !== "callout") {
|
|
251
252
|
return (
|
|
252
|
-
<Box data-gloom-status={status} data-gloom-ui="notice">
|
|
253
|
+
<Box id={id} data-gloom-status={status} data-gloom-ui="notice" style={flush ? { paddingInline: "var(--gloom-inset)" } : undefined}>
|
|
253
254
|
<Text fg={color} wrapText>{body}</Text>
|
|
254
255
|
</Box>
|
|
255
256
|
);
|
|
@@ -262,6 +263,17 @@ export function Notice({ children, tone = "warning", variant = "inline" }: Notic
|
|
|
262
263
|
);
|
|
263
264
|
}
|
|
264
265
|
|
|
266
|
+
/**
|
|
267
|
+
* What concerns the selected row of a table that has no detail of its own,
|
|
268
|
+
* said under the table (DataTableView `rootAfter`) while the row is
|
|
269
|
+
* selected: the whole reason behind the few words its row shows
|
|
270
|
+
* (docs/pane-conventions.md, Row messages). Nothing while no row has one.
|
|
271
|
+
*/
|
|
272
|
+
export function RowNote({ children, tone = "warning" }: Pick<NoticeProps, "tone"> & { children: ReactNode | null | undefined }) {
|
|
273
|
+
if (children == null || children === "") return null;
|
|
274
|
+
return <Box paddingX={1} flexShrink={0}><Notice tone={tone}>{children}</Notice></Box>;
|
|
275
|
+
}
|
|
276
|
+
|
|
265
277
|
/** The one loading phrasing: "Loading ..." with three dots, never the ellipsis glyph. */
|
|
266
278
|
export function loadingText(thing?: string): string {
|
|
267
279
|
return thing ? tf("Loading {thing}...", { thing }) : t("Loading...");
|
|
@@ -76,7 +76,8 @@ export function fitTableCellText(text: string, width: number, align?: string, ke
|
|
|
76
76
|
return padToWidth(clipKeepingEnd(text, width, keepEnd), width, align);
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
|
|
79
|
+
/** `text` cut to `width` cells keeping `keepEnd` whole after the ellipsis, as a table cell's `keepEnd` cuts it. */
|
|
80
|
+
export function clipKeepingEnd(text: string, width: number, keepEnd: string | undefined): string {
|
|
80
81
|
if (!keepEnd || displayWidth(text) <= width || !text.endsWith(keepEnd)) return clipToDisplayWidth(text, width);
|
|
81
82
|
const lead = text.slice(0, -keepEnd.length);
|
|
82
83
|
const room = width - displayWidth(keepEnd);
|
|
@@ -12,6 +12,7 @@ import { Prose } from "./ui/prose";
|
|
|
12
12
|
import { logFailure } from "../utils/log-failure";
|
|
13
13
|
import { markPaneNoticesSeen, usePaneNoticesSeen } from "./pane-notice-seen";
|
|
14
14
|
import { withoutCryptoVenueCode } from "../utils/crypto-pair";
|
|
15
|
+
import { readableStatus } from "../utils/reason-codes";
|
|
15
16
|
|
|
16
17
|
export interface UsePaneNoticeFooterOptions {
|
|
17
18
|
registrationId: string;
|
|
@@ -19,6 +20,13 @@ export interface UsePaneNoticeFooterOptions {
|
|
|
19
20
|
focused: boolean;
|
|
20
21
|
title?: string;
|
|
21
22
|
enabled?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* The notes a picture of the pane prints as its note line, every notice
|
|
25
|
+
* otherwise: for a pane whose footer already says some of them in other
|
|
26
|
+
* words (what its numbers leave out, as segments a capture keeps), the
|
|
27
|
+
* rest. Empty prints none; the dialog always lists every notice.
|
|
28
|
+
*/
|
|
29
|
+
captureNotes?: readonly string[];
|
|
22
30
|
}
|
|
23
31
|
|
|
24
32
|
function NoticeDialog({ notices, title, dismiss, dialogId }: AlertContext & {
|
|
@@ -78,14 +86,18 @@ export function usePaneNoticeFooter({
|
|
|
78
86
|
focused,
|
|
79
87
|
title: rawTitle = "Data warnings",
|
|
80
88
|
enabled = true,
|
|
89
|
+
captureNotes,
|
|
81
90
|
}: UsePaneNoticeFooterOptions): void {
|
|
82
91
|
const dialog = useDialog();
|
|
83
92
|
const dialogOpen = useDialogState((state) => state.isOpen);
|
|
84
93
|
const scopeActive = usePaneFooterScopeActive();
|
|
85
94
|
const title = t(rawTitle);
|
|
86
|
-
// Said as a reader takes it: a coin's pair without the internal code of the venue it is charted on
|
|
87
|
-
|
|
95
|
+
// Said as a reader takes it: a coin's pair without the internal code of the venue it is charted on, and a
|
|
96
|
+
// source's reason code (UPSTREAM_ERROR) as what happened.
|
|
97
|
+
const noticeKey = JSON.stringify([...new Set(notices.map((notice) => readableStatus(withoutCryptoVenueCode(notice.trim()))).filter(Boolean))]);
|
|
88
98
|
const currentNotices = useMemo<readonly string[]>(() => JSON.parse(noticeKey), [noticeKey]);
|
|
99
|
+
const capturedKey = captureNotes ? JSON.stringify(captureNotes.map((note) => readableStatus(note.trim())).filter(Boolean)) : null;
|
|
100
|
+
const capturedNotes = useMemo<readonly string[] | null>(() => (capturedKey ? JSON.parse(capturedKey) : null), [capturedKey]);
|
|
89
101
|
const active = enabled && scopeActive && currentNotices.length > 0;
|
|
90
102
|
const seen = usePaneNoticesSeen(currentNotices);
|
|
91
103
|
const openingRef = useRef(false);
|
|
@@ -128,11 +140,12 @@ export function usePaneNoticeFooter({
|
|
|
128
140
|
info: [{
|
|
129
141
|
id: "data-warnings",
|
|
130
142
|
icon: "warning",
|
|
143
|
+
notes: capturedNotes ?? currentNotices,
|
|
131
144
|
label: title,
|
|
132
145
|
title: `${title} (!)`,
|
|
133
146
|
shortcut: "!",
|
|
134
147
|
parts: [{ text: "⚠", tone: seen ? "muted" : "warning" }],
|
|
135
148
|
onPress: open,
|
|
136
149
|
}],
|
|
137
|
-
} : null, [active, open, seen, title]);
|
|
150
|
+
} : null, [active, open, seen, title, currentNotices, capturedNotes]);
|
|
138
151
|
}
|
|
@@ -2,6 +2,12 @@ import type { AppConfig } from "../../../types/config";
|
|
|
2
2
|
|
|
3
3
|
export { sanitizeLayout } from "../layout";
|
|
4
4
|
|
|
5
|
+
/** Another program's change to config.json, to fold into this program's copy. */
|
|
6
|
+
export interface ExternalConfigChange {
|
|
7
|
+
/** `config` with the change folded in, or the same object when it already holds it. */
|
|
8
|
+
apply(config: AppConfig): AppConfig;
|
|
9
|
+
}
|
|
10
|
+
|
|
5
11
|
export interface ConfigStoreHost {
|
|
6
12
|
getDataDir(): Promise<string | null>;
|
|
7
13
|
loadConfig(dataDir: string): Promise<AppConfig>;
|
|
@@ -10,6 +16,12 @@ export interface ConfigStoreHost {
|
|
|
10
16
|
resetAllData(dataDir: string): Promise<void>;
|
|
11
17
|
exportConfig(config: AppConfig, destPath: string): Promise<void>;
|
|
12
18
|
importConfig(dataDir: string, srcPath: string): Promise<AppConfig>;
|
|
19
|
+
/**
|
|
20
|
+
* Reports each change another program makes to the config while this one
|
|
21
|
+
* runs (a `gloom` command run beside the app). A host whose config no other
|
|
22
|
+
* program writes leaves it out.
|
|
23
|
+
*/
|
|
24
|
+
watchExternalChanges?(dataDir: string, listener: (change: ExternalConfigChange) => void): () => void;
|
|
13
25
|
}
|
|
14
26
|
|
|
15
27
|
let configuredHost: ConfigStoreHost | null = null;
|
|
@@ -61,3 +73,22 @@ export async function exportConfig(config: AppConfig, destPath: string): Promise
|
|
|
61
73
|
export async function importConfig(dataDir: string, srcPath: string): Promise<AppConfig> {
|
|
62
74
|
return (await getHost()).importConfig(dataDir, srcPath);
|
|
63
75
|
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Calls `listener` with each change another program makes to the config of
|
|
79
|
+
* `dataDir` while this one runs. The listener folds it into the app's state
|
|
80
|
+
* at once: saves already waiting are written with it.
|
|
81
|
+
*/
|
|
82
|
+
export function watchExternalConfigChanges(dataDir: string, listener: (change: ExternalConfigChange) => void): () => void {
|
|
83
|
+
let stop: (() => void) | null = null;
|
|
84
|
+
let stopped = false;
|
|
85
|
+
void getHost().then((host) => {
|
|
86
|
+
if (stopped || !host.watchExternalChanges) return;
|
|
87
|
+
stop = host.watchExternalChanges(dataDir, listener);
|
|
88
|
+
}, () => { /* Intentional ignore: a renderer without a config store has no file to watch. */ });
|
|
89
|
+
return () => {
|
|
90
|
+
stopped = true;
|
|
91
|
+
stop?.();
|
|
92
|
+
stop = null;
|
|
93
|
+
};
|
|
94
|
+
}
|
|
@@ -11,11 +11,22 @@ import { EXTRACTED_PLUGINS } from "../../../plugins/extracted-plugins";
|
|
|
11
11
|
import { makePrivateDir, writePrivateFile } from "../../../utils/private-files";
|
|
12
12
|
import { renameIntoPlace } from "../../../utils/replace-file";
|
|
13
13
|
import { tightenProfilePermissions } from "../../profile-permissions";
|
|
14
|
+
import type { ExternalConfigChange } from "./index";
|
|
14
15
|
import type { ConfigMigrationHost } from "./migrations";
|
|
15
16
|
import {
|
|
16
17
|
normalizeConfigForSave,
|
|
17
18
|
normalizeLoadedConfig,
|
|
18
19
|
} from "./normalize";
|
|
20
|
+
import { applyProfileEdits, sameProfileJson, type ProfileJson } from "../../profile-merge";
|
|
21
|
+
import {
|
|
22
|
+
changesHeld,
|
|
23
|
+
changesSince,
|
|
24
|
+
forgetSharedFile,
|
|
25
|
+
markChangesHeld,
|
|
26
|
+
noteSharedFileRead,
|
|
27
|
+
watchSharedFile,
|
|
28
|
+
writeSharedFile,
|
|
29
|
+
} from "./shared-file";
|
|
19
30
|
|
|
20
31
|
const configLog = debugLog.createLogger("config");
|
|
21
32
|
const IN_MEMORY_DATA_DIR = ":memory:";
|
|
@@ -96,23 +107,25 @@ async function loadConfigState(dataDir: string): Promise<{ config: AppConfig; ne
|
|
|
96
107
|
const raw = await readFile(configPath, "utf-8");
|
|
97
108
|
const saved = JSON.parse(raw) as Record<string, unknown>;
|
|
98
109
|
const state = normalizeLoadedConfig(saved, dataDir, migrationHost);
|
|
110
|
+
noteSharedFileRead(configPath, raw);
|
|
99
111
|
// A config.json that names a different directory than the one it belongs
|
|
100
112
|
// to came along with a moved folder. Record where it lives now, so the next
|
|
101
113
|
// launch reads it directly instead of through the missing-path fallback.
|
|
102
114
|
const recorded = typeof saved.dataDir === "string" ? saved.dataDir : null;
|
|
103
|
-
return {
|
|
115
|
+
return {
|
|
116
|
+
config: markChangesHeld(configPath, state.config),
|
|
117
|
+
needsSave: state.needsSave || (recorded !== null && recorded !== dataDir),
|
|
118
|
+
};
|
|
104
119
|
} catch {
|
|
105
120
|
// Fresh installs have no former built-in plugins to restore. Record the
|
|
106
121
|
// current baseline so onboarding never waits for plugin network installs.
|
|
107
122
|
return {
|
|
108
|
-
config: { ...createDefaultConfig(dataDir), seededPlugins: EXTRACTED_PLUGINS.map((plugin) => plugin.id) },
|
|
123
|
+
config: markChangesHeld(configFileFor(dataDir), { ...createDefaultConfig(dataDir), seededPlugins: EXTRACTED_PLUGINS.map((plugin) => plugin.id) }),
|
|
109
124
|
needsSave: true,
|
|
110
125
|
};
|
|
111
126
|
}
|
|
112
127
|
}
|
|
113
128
|
|
|
114
|
-
/** The save in flight or queued last for each config file; it never rejects. */
|
|
115
|
-
const saveQueues = new Map<string, Promise<void>>();
|
|
116
129
|
let tempFileCounter = 0;
|
|
117
130
|
|
|
118
131
|
async function writeConfigFile(configPath: string, contents: string): Promise<void> {
|
|
@@ -133,7 +146,9 @@ async function writeConfigFile(configPath: string, contents: string): Promise<vo
|
|
|
133
146
|
/**
|
|
134
147
|
* Saves to one file run one after another in call order, so the last call is
|
|
135
148
|
* the one on disk and none is lost. A failed save rejects only its own caller
|
|
136
|
-
* and the next one still runs.
|
|
149
|
+
* and the next one still runs. What another program wrote to the file since
|
|
150
|
+
* this one last read or wrote it (a `gloom` command run beside the app) is
|
|
151
|
+
* kept: see `shared-file.ts`.
|
|
137
152
|
*/
|
|
138
153
|
export async function saveConfig(config: AppConfig): Promise<void> {
|
|
139
154
|
// `:memory:` is the data directory of a config kept in memory (tests, as for
|
|
@@ -143,13 +158,47 @@ export async function saveConfig(config: AppConfig): Promise<void> {
|
|
|
143
158
|
// Written as it was when called, however the caller's object changes while
|
|
144
159
|
// earlier saves are still running.
|
|
145
160
|
const contents = JSON.stringify(normalizeConfigForSave(config), null, 2);
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
161
|
+
return writeSharedFile(configPath, contents, changesHeld(configPath, config), (output) => writeConfigFile(configPath, output));
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Calls `listener` with each change another program makes to the config of
|
|
166
|
+
* `dataDir` while this one runs, as soon as it is found. The listener folds
|
|
167
|
+
* it into the app's state before anything more is written.
|
|
168
|
+
*/
|
|
169
|
+
export function watchExternalChanges(dataDir: string, listener: (change: ExternalConfigChange) => void): () => void {
|
|
170
|
+
if (dataDir === IN_MEMORY_DATA_DIR) return () => {};
|
|
171
|
+
const configPath = configFileFor(dataDir);
|
|
172
|
+
return watchSharedFile(configPath, (change) => {
|
|
173
|
+
// A copy that does not say what it holds was built before this change was found.
|
|
174
|
+
listener({ apply: (config) => foldConfigChanges(configPath, config, change.index + 1, change.index) });
|
|
151
175
|
});
|
|
152
|
-
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** The top-level settings one derives from the others: a change to either takes all three. */
|
|
179
|
+
const LAYOUT_KEYS = ["layout", "layouts", "activeLayoutIndex"];
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* `config` with the changes it lacks, up to the first `upTo`, folded in. What
|
|
183
|
+
* the changes leave alone keeps its object, so a pane that reads it does not
|
|
184
|
+
* redraw for another program's edit elsewhere.
|
|
185
|
+
*/
|
|
186
|
+
function foldConfigChanges(configPath: string, config: AppConfig, upTo: number, unmarked: number): AppConfig {
|
|
187
|
+
const held = changesHeld(configPath, config, unmarked);
|
|
188
|
+
if (held >= upTo) return config;
|
|
189
|
+
const saved = JSON.parse(JSON.stringify(normalizeConfigForSave(config))) as Record<string, ProfileJson>;
|
|
190
|
+
let merged = saved;
|
|
191
|
+
for (const change of changesSince(configPath, held).slice(0, upTo - held)) merged = applyProfileEdits(merged, change.edits);
|
|
192
|
+
if (merged === saved) return markChangesHeld(configPath, { ...config }, upTo);
|
|
193
|
+
const loaded = normalizeLoadedConfig(merged, config.dataDir, migrationHost).config as unknown as Record<string, unknown>;
|
|
194
|
+
const next: Record<string, unknown> = { ...config };
|
|
195
|
+
const touched = new Set(Object.keys({ ...saved, ...merged }).filter((key) => !sameProfileJson(saved[key], merged[key])));
|
|
196
|
+
if (LAYOUT_KEYS.some((key) => touched.has(key))) for (const key of LAYOUT_KEYS) touched.add(key);
|
|
197
|
+
for (const key of touched) {
|
|
198
|
+
if (Object.hasOwn(loaded, key)) next[key] = loaded[key];
|
|
199
|
+
else delete next[key];
|
|
200
|
+
}
|
|
201
|
+
return markChangesHeld(configPath, next as unknown as AppConfig, upTo);
|
|
153
202
|
}
|
|
154
203
|
|
|
155
204
|
export async function initDataDir(dataDir: string): Promise<AppConfig> {
|
|
@@ -168,6 +217,7 @@ export async function resetAllData(dataDir: string): Promise<void> {
|
|
|
168
217
|
// Settings outside the data directory (the XDG config file) go too, or the
|
|
169
218
|
// next launch would skip the setup wizard the reset promises.
|
|
170
219
|
await rm(configFileFor(dataDir), { force: true });
|
|
220
|
+
forgetSharedFile(configFileFor(dataDir));
|
|
171
221
|
}
|
|
172
222
|
|
|
173
223
|
export async function exportConfig(config: AppConfig, destPath: string): Promise<void> {
|
|
@@ -25,6 +25,7 @@ import { encodeBuiltinDisabledPluginIds, expandBuiltinPluginGroups } from "../..
|
|
|
25
25
|
import { sanitizeSavedPaneState } from "./pane-state";
|
|
26
26
|
import { isRecord } from "../../../utils/guards";
|
|
27
27
|
import { normalizeWatchlistGroups } from "../../../portfolio/watchlist-groups";
|
|
28
|
+
import { portfolioCashBalances, withPortfolioCashBalances } from "../../../portfolio/cash-balances";
|
|
28
29
|
import { normalizeStoredBaseCurrency } from "../../../utils/base-currency";
|
|
29
30
|
import { debugLog } from "../../../utils/debug-log";
|
|
30
31
|
import { DEFAULT_THEME, themes } from "../../../theme/themes";
|
|
@@ -401,8 +402,9 @@ function sanitizePortfolios(value: unknown, fallback: Portfolio[]): Portfolio[]
|
|
|
401
402
|
|
|
402
403
|
/** Cash, target weights, the import source and a fixed currency the portfolio commands write; a malformed one is dropped. */
|
|
403
404
|
function sanitizePortfolioAllocation(entry: Portfolio): Portfolio {
|
|
404
|
-
const { cash, targetWeights, importedFrom, fixedCurrency, ...portfolio } = entry;
|
|
405
|
-
|
|
405
|
+
const { cash, otherCash, targetWeights, importedFrom, fixedCurrency, ...portfolio } = entry;
|
|
406
|
+
// Each currency's balance once, the first in `cash` as an older build reads it.
|
|
407
|
+
const next: Portfolio = withPortfolioCashBalances(portfolio, portfolioCashBalances({ cash, otherCash }));
|
|
406
408
|
if (fixedCurrency === true) next.fixedCurrency = true;
|
|
407
409
|
if (isRecord(importedFrom) && importedFrom.kind === "13f"
|
|
408
410
|
&& [importedFrom.cik, importedFrom.name, importedFrom.period, importedFrom.filed].every((value) => typeof value === "string" && value)) {
|
|
@@ -414,10 +416,6 @@ function sanitizePortfolioAllocation(entry: Portfolio): Portfolio {
|
|
|
414
416
|
next.importedFrom.weights = Object.fromEntries(weights) as Record<string, number>;
|
|
415
417
|
}
|
|
416
418
|
}
|
|
417
|
-
if (isRecord(cash) && typeof cash.amount === "number" && Number.isFinite(cash.amount)
|
|
418
|
-
&& typeof cash.currency === "string" && /^[A-Z]{3}$/.test(cash.currency)) {
|
|
419
|
-
next.cash = { amount: cash.amount, currency: cash.currency };
|
|
420
|
-
}
|
|
421
419
|
if (isRecord(targetWeights)) {
|
|
422
420
|
const weights = Object.entries(targetWeights).filter((weight): weight is [string, number] =>
|
|
423
421
|
!!weight[0].trim() && typeof weight[1] === "number" && Number.isFinite(weight[1]) && weight[1] >= 0 && weight[1] <= 100);
|