@tidal-ts/terminal 0.29.0 → 0.30.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/context.d.ts +13 -8
- package/dist/context.js +12 -10
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/terminalMachine.d.ts +36 -42
- package/dist/terminalMachine.js +91 -170
- package/package.json +3 -3
package/dist/context.d.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { type ReactNode } from 'react';
|
|
2
2
|
import type { InspectionEvent, Observer } from 'xstate';
|
|
3
3
|
import type { DeriveOp, PairOp } from '@tidal-ts/core';
|
|
4
|
-
import type { AxisRange,
|
|
5
|
-
import { type MetricEntry, type PairLegInput, type PresetSet, type PresetStorage, type RowState, type TerminalPreset } from './terminalMachine.js';
|
|
4
|
+
import type { AxisRange, PairLensOp, SeriesConfig } from '@tidal-ts/chart';
|
|
5
|
+
import { type MetricEntry, type PairLegInput, type PresetSet, type PresetStorage, type RowState, type SourceLocks, type TerminalPreset } from './terminalMachine.js';
|
|
6
6
|
export interface TerminalProviderProps {
|
|
7
7
|
initialRows: RowState[];
|
|
8
|
+
/** The source locks to start with — the stored active preset's, on a
|
|
9
|
+
* reload. Read once, at mount. */
|
|
10
|
+
initialSourceLocks?: SourceLocks;
|
|
8
11
|
catalog: readonly MetricEntry[];
|
|
9
12
|
storage: PresetStorage;
|
|
10
13
|
/** The colour KEYS the host offers a new series, in the order to hand them
|
|
@@ -26,7 +29,7 @@ export interface TerminalProviderProps {
|
|
|
26
29
|
inspect?: Observer<InspectionEvent> | ((event: InspectionEvent) => void);
|
|
27
30
|
children: ReactNode;
|
|
28
31
|
}
|
|
29
|
-
export declare function TerminalProvider({ initialRows, catalog, storage, palette, spreadColor, initialPresetSet, inspect, children, }: TerminalProviderProps): import("react").JSX.Element;
|
|
32
|
+
export declare function TerminalProvider({ initialRows, initialSourceLocks, catalog, storage, palette, spreadColor, initialPresetSet, inspect, children, }: TerminalProviderProps): import("react").JSX.Element;
|
|
30
33
|
export declare function useRows(): RowState[];
|
|
31
34
|
export declare function useSelectedSeries(): string | null;
|
|
32
35
|
/** The control-panel expansion (the row whose controls are open) — overrides the
|
|
@@ -38,7 +41,8 @@ export declare function usePresetSet(): PresetSet;
|
|
|
38
41
|
/** Which slots of the showing set hold a saved preset (length === PRESET_SLOTS). */
|
|
39
42
|
export declare function usePresetSaved(): boolean[];
|
|
40
43
|
/** The active slot of the showing set — the saved slot whose rows deep-equal
|
|
41
|
-
* the live rows — or null (a custom state). Derived, not
|
|
44
|
+
* the live rows and source locks — or null (a custom state). Derived, not
|
|
45
|
+
* stored. */
|
|
42
46
|
export declare function useActiveSlot(): number | null;
|
|
43
47
|
/** Per-axis range state, keyed by axis id (`configAxisId`). No entry = an
|
|
44
48
|
* untouched auto axis; `mode:'auto'` with values = the preserved manual
|
|
@@ -56,10 +60,11 @@ export declare function useAddPair(): (a: PairLegInput, b: PairLegInput, op: Pai
|
|
|
56
60
|
export declare function useCompareAll(): () => void;
|
|
57
61
|
/** Set or clear (`null`) the function a compare applies to a metric. */
|
|
58
62
|
export declare function useSetCompareFn(): (id: string, fn: PairOp | null) => void;
|
|
59
|
-
/**
|
|
60
|
-
export declare function
|
|
61
|
-
/** Lock a
|
|
62
|
-
|
|
63
|
+
/** Each data source's locked comparison symbol, by source key. */
|
|
64
|
+
export declare function useSourceLocks(): SourceLocks;
|
|
65
|
+
/** Lock a data source's comparison side to a symbol, or `null` to read the
|
|
66
|
+
* bar's comparison again. */
|
|
67
|
+
export declare function useSetSourceLock(): (source: string, symbol: string | null) => void;
|
|
63
68
|
export declare function useSetStudyParam(): (id: string, name: string, value: number) => void;
|
|
64
69
|
/** Switch which output of a multi-output source a study reads (the output
|
|
65
70
|
* picker). Pair it with `outputAllowed` to render refused choices disabled. */
|
package/dist/context.js
CHANGED
|
@@ -8,10 +8,11 @@ import { activeSlot, terminalMachine, } from './terminalMachine.js';
|
|
|
8
8
|
* barrel re-exports these + the event union; the actor + machine stay private.
|
|
9
9
|
*/
|
|
10
10
|
const TerminalContext = createActorContext(terminalMachine);
|
|
11
|
-
export function TerminalProvider({ initialRows, catalog, storage, palette, spreadColor, initialPresetSet, inspect, children, }) {
|
|
11
|
+
export function TerminalProvider({ initialRows, initialSourceLocks, catalog, storage, palette, spreadColor, initialPresetSet, inspect, children, }) {
|
|
12
12
|
return (_jsxs(TerminalContext.Provider, { options: {
|
|
13
13
|
input: {
|
|
14
14
|
initialRows,
|
|
15
|
+
...(initialSourceLocks ? { initialSourceLocks } : {}),
|
|
15
16
|
catalog,
|
|
16
17
|
storage,
|
|
17
18
|
...(palette ? { palette } : {}),
|
|
@@ -71,9 +72,10 @@ export function usePresetSaved() {
|
|
|
71
72
|
return TerminalContext.useSelector((s) => s.context.presets[s.context.presetSet].map((p) => p != null));
|
|
72
73
|
}
|
|
73
74
|
/** The active slot of the showing set — the saved slot whose rows deep-equal
|
|
74
|
-
* the live rows — or null (a custom state). Derived, not
|
|
75
|
+
* the live rows and source locks — or null (a custom state). Derived, not
|
|
76
|
+
* stored. */
|
|
75
77
|
export function useActiveSlot() {
|
|
76
|
-
return TerminalContext.useSelector((s) => activeSlot(s.context.presets[s.context.presetSet], s.context.rows));
|
|
78
|
+
return TerminalContext.useSelector((s) => activeSlot(s.context.presets[s.context.presetSet], s.context.rows, s.context.sourceLocks));
|
|
77
79
|
}
|
|
78
80
|
/** Per-axis range state, keyed by axis id (`configAxisId`). No entry = an
|
|
79
81
|
* untouched auto axis; `mode:'auto'` with values = the preserved manual
|
|
@@ -109,15 +111,15 @@ export function useSetCompareFn() {
|
|
|
109
111
|
const ref = TerminalContext.useActorRef();
|
|
110
112
|
return useCallback((id, fn) => ref.send({ type: 'series.setCompareFn', id, fn }), [ref]);
|
|
111
113
|
}
|
|
112
|
-
/**
|
|
113
|
-
export function
|
|
114
|
-
|
|
115
|
-
return useCallback((id, other) => ref.send({ type: 'series.setCompareWith', id, with: other }), [ref]);
|
|
114
|
+
/** Each data source's locked comparison symbol, by source key. */
|
|
115
|
+
export function useSourceLocks() {
|
|
116
|
+
return TerminalContext.useSelector((s) => s.context.sourceLocks);
|
|
116
117
|
}
|
|
117
|
-
/** Lock a
|
|
118
|
-
|
|
118
|
+
/** Lock a data source's comparison side to a symbol, or `null` to read the
|
|
119
|
+
* bar's comparison again. */
|
|
120
|
+
export function useSetSourceLock() {
|
|
119
121
|
const ref = TerminalContext.useActorRef();
|
|
120
|
-
return useCallback((
|
|
122
|
+
return useCallback((source, symbol) => ref.send({ type: 'source.setLock', source, symbol }), [ref]);
|
|
121
123
|
}
|
|
122
124
|
export function useSetStudyParam() {
|
|
123
125
|
const ref = TerminalContext.useActorRef();
|
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,6 @@
|
|
|
5
5
|
* union — the pre-paid bus contract. The actor context + machine internals stay
|
|
6
6
|
* private to the module.
|
|
7
7
|
*/
|
|
8
|
-
export { TerminalProvider, useRows, useSelectedSeries, useExpandedSeries, useControlsOpen, usePresetSaved, useActiveSlot, useAddSeries, useAddPair, useCompareAll, useAddStudy, useSetCompareFn,
|
|
9
|
-
export { PRESET_SLOTS, PRESET_SETS, type PresetSet, type PresetSlot, MAX_ROWS, activeSlot, canonRows, columnLabel, columnUnits, compareFnAllowed,
|
|
8
|
+
export { TerminalProvider, useRows, useSelectedSeries, useExpandedSeries, useControlsOpen, usePresetSaved, useActiveSlot, useAddSeries, useAddPair, useCompareAll, useAddStudy, useSetCompareFn, useSourceLocks, useSetSourceLock, useSetStudyParam, useSetStudyOutput, useSetStudyInput, useSetDataColumns, useSetStudyOutputs, useOrderSeries, useReindexSeries, useMoveSeriesToRow, useMoveToAxis, useRemoveSeries, usePatchSeries, useToggleVisible, useToggleGroupVisible, useRemoveGroup, useSelectSeries, useExpandSeries, useSetControlsOpen, useSelectPreset, useSavePreset, useSetPresetSet, usePresetSet, useSetRowHeights, useAddRow, useRemoveRow, useAxisRanges, useToggleAxisLink, useSwapAxisSide, useSetAxisRange, useSetAxisAuto, useSetAxisLocks, useSetAxisAutoOpts, useSetAxisFormat, useTerminalHotkeys, type TerminalProviderProps, } from './context.js';
|
|
9
|
+
export { PRESET_SLOTS, PRESET_SETS, type PresetSet, type PresetSlot, MAX_ROWS, activeSlot, canonRows, columnLabel, columnUnits, compareFnAllowed, validLocks, entryColumn, groupMembers, mintId, axisMoveAllowed, linkToggleAllowed, respecAllowed, outputAllowed, inputAllowed, dataColumnsAllowed, outputsAllowed, studyOutputChoices, studyOutputsOf, studyOutputsRead, defaultStudyOutputs, studyChainTail, studyOfferable, SOURCE_COLUMNS, swapAllowed, type EditScope, type RowState, type TerminalPreset, type SourceLocks, type MetricEntry, type PairLegInput, type PresetStorage, type TerminalEvent, type TerminalInput, } from './terminalMachine.js';
|
|
10
10
|
export { axisBindings, allowedAxes, canAddUnit, axisForAdd, type AxisMember, } from './axisPolicy.js';
|
package/dist/index.js
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
* union — the pre-paid bus contract. The actor context + machine internals stay
|
|
6
6
|
* private to the module.
|
|
7
7
|
*/
|
|
8
|
-
export { TerminalProvider, useRows, useSelectedSeries, useExpandedSeries, useControlsOpen, usePresetSaved, useActiveSlot, useAddSeries, useAddPair, useCompareAll, useAddStudy, useSetCompareFn,
|
|
9
|
-
export { PRESET_SLOTS, PRESET_SETS, MAX_ROWS, activeSlot, canonRows, columnLabel, columnUnits, compareFnAllowed,
|
|
8
|
+
export { TerminalProvider, useRows, useSelectedSeries, useExpandedSeries, useControlsOpen, usePresetSaved, useActiveSlot, useAddSeries, useAddPair, useCompareAll, useAddStudy, useSetCompareFn, useSourceLocks, useSetSourceLock, useSetStudyParam, useSetStudyOutput, useSetStudyInput, useSetDataColumns, useSetStudyOutputs, useOrderSeries, useReindexSeries, useMoveSeriesToRow, useMoveToAxis, useRemoveSeries, usePatchSeries, useToggleVisible, useToggleGroupVisible, useRemoveGroup, useSelectSeries, useExpandSeries, useSetControlsOpen, useSelectPreset, useSavePreset, useSetPresetSet, usePresetSet, useSetRowHeights, useAddRow, useRemoveRow, useAxisRanges, useToggleAxisLink, useSwapAxisSide, useSetAxisRange, useSetAxisAuto, useSetAxisLocks, useSetAxisAutoOpts, useSetAxisFormat, useTerminalHotkeys, } from './context.js';
|
|
9
|
+
export { PRESET_SLOTS, PRESET_SETS, MAX_ROWS, activeSlot, canonRows, columnLabel, columnUnits, compareFnAllowed, validLocks, entryColumn, groupMembers, mintId, axisMoveAllowed, linkToggleAllowed, respecAllowed, outputAllowed, inputAllowed, dataColumnsAllowed, outputsAllowed, studyOutputChoices, studyOutputsOf, studyOutputsRead, defaultStudyOutputs, studyChainTail, studyOfferable, SOURCE_COLUMNS, swapAllowed, } from './terminalMachine.js';
|
|
10
10
|
// The axis policy a host's MENUS gate on — the same predicates the machine's
|
|
11
11
|
// guards enforce, exported so the two cannot disagree (0.1.0 left them internal;
|
|
12
12
|
// a host had to keep its own copy).
|
|
@@ -12,7 +12,7 @@ export declare const SOURCE_COLUMNS: Readonly<Record<string, readonly string[]>>
|
|
|
12
12
|
* The menu filters on it; `canAddStudy` refuses on it. */
|
|
13
13
|
export declare function studyOfferable(source: string | undefined, op: DeriveOp): boolean;
|
|
14
14
|
import { type PairLensOp } from '@tidal-ts/chart';
|
|
15
|
-
import { type AxisRange, type SeriesAxis, type SeriesConfig
|
|
15
|
+
import { type AxisRange, type SeriesAxis, type SeriesConfig } from '@tidal-ts/chart';
|
|
16
16
|
/**
|
|
17
17
|
* The terminal machine (XState migration, slice 2 — see Tidal's state-architecture note).
|
|
18
18
|
* The **headless product**: it owns the control-panel *configuration* — rows of
|
|
@@ -41,7 +41,13 @@ export interface RowState {
|
|
|
41
41
|
* adapter. */
|
|
42
42
|
export interface TerminalPreset {
|
|
43
43
|
rows: RowState[];
|
|
44
|
+
/** The symbol each data source's comparison side is LOCKED to (see
|
|
45
|
+
* {@link TerminalContext.sourceLocks}). Absent ⇒ none locked. */
|
|
46
|
+
sourceLocks?: SourceLocks;
|
|
44
47
|
}
|
|
48
|
+
/** A source key (`price`, `vol`) to the symbol its comparison side is locked
|
|
49
|
+
* to. */
|
|
50
|
+
export type SourceLocks = Readonly<Record<string, string>>;
|
|
45
51
|
/** The minimal catalog-entry shape the machine needs (host-supplied as `input`;
|
|
46
52
|
* `seriesCatalog`'s entries satisfy it structurally). Keeps the module free of
|
|
47
53
|
* an app-config import for extraction. */
|
|
@@ -94,6 +100,17 @@ export declare const PRESET_SLOTS = 6;
|
|
|
94
100
|
export declare const MAX_ROWS = 3;
|
|
95
101
|
export declare const mintId: (seq: number) => string;
|
|
96
102
|
interface TerminalContext {
|
|
103
|
+
/**
|
|
104
|
+
* The symbol each data source's COMPARISON side is locked to, by source key
|
|
105
|
+
* (`{ price: 'SPY' }`): every line of that source then reads the locked
|
|
106
|
+
* symbol as its other side instead of the bar's comparison, comparison named
|
|
107
|
+
* or not. A property of the source, not of a line (Peter, 2026-12-02): the
|
|
108
|
+
* host stamps it onto each line it draws as {@link SeriesConfig.compareOn}.
|
|
109
|
+
* Saved in a preset with the rows, and part of what makes a preset match
|
|
110
|
+
* (`activeSlot`) even while no line of that source is on the chart: the lock
|
|
111
|
+
* is a setting of the source, and comes back with its lines.
|
|
112
|
+
*/
|
|
113
|
+
sourceLocks: SourceLocks;
|
|
97
114
|
/** The host's colour keys for new series, in hand-out order. */
|
|
98
115
|
palette: readonly string[];
|
|
99
116
|
/** What a new spread draws in, when the host reserves a colour for one. */
|
|
@@ -236,7 +253,7 @@ export type TerminalEvent = {
|
|
|
236
253
|
| {
|
|
237
254
|
type: 'series.patch';
|
|
238
255
|
id: string;
|
|
239
|
-
patch: Partial<Omit<SeriesConfig, 'axis' | 'axisGroup' | 'parentIds' | 'compareFn' | '
|
|
256
|
+
patch: Partial<Omit<SeriesConfig, 'axis' | 'axisGroup' | 'parentIds' | 'compareFn' | 'compareOn'>>;
|
|
240
257
|
} | {
|
|
241
258
|
type: 'series.toggleVisible';
|
|
242
259
|
id: string;
|
|
@@ -251,21 +268,12 @@ export type TerminalEvent = {
|
|
|
251
268
|
id: string;
|
|
252
269
|
fn: PairOp | null;
|
|
253
270
|
}
|
|
254
|
-
/**
|
|
255
|
-
*
|
|
256
|
-
* {@link
|
|
271
|
+
/** Lock a data source's comparison side to a symbol, or `null` to read the
|
|
272
|
+
* bar's comparison again ({@link TerminalContext.sourceLocks}). Refused for
|
|
273
|
+
* a name {@link isPinnableSymbol} refuses. */
|
|
257
274
|
| {
|
|
258
|
-
type: '
|
|
259
|
-
|
|
260
|
-
with: CompareWith | null;
|
|
261
|
-
}
|
|
262
|
-
/** Lock a compare's other side to a symbol ({@link SeriesConfig.compareOn}),
|
|
263
|
-
* or `null` to read the bar's comparison again. Refused for anything
|
|
264
|
-
* {@link compareFnAllowed} refuses, and for a name {@link isPinnableSymbol}
|
|
265
|
-
* refuses. */
|
|
266
|
-
| {
|
|
267
|
-
type: 'series.setCompareOn';
|
|
268
|
-
id: string;
|
|
275
|
+
type: 'source.setLock';
|
|
276
|
+
source: string;
|
|
269
277
|
symbol: string | null;
|
|
270
278
|
}
|
|
271
279
|
/** The PAIR's own eye — hides both legs at once. Each leg keeps its own
|
|
@@ -382,6 +390,9 @@ export type TerminalEvent = {
|
|
|
382
390
|
};
|
|
383
391
|
export interface TerminalInput {
|
|
384
392
|
initialRows: RowState[];
|
|
393
|
+
/** The source locks to start with (the stored active preset's, on a
|
|
394
|
+
* reload). Default: none. */
|
|
395
|
+
initialSourceLocks?: SourceLocks;
|
|
385
396
|
catalog: readonly MetricEntry[];
|
|
386
397
|
storage: PresetStorage;
|
|
387
398
|
/** The preset set showing at start (the host's comparison, on a reload).
|
|
@@ -625,18 +636,9 @@ export declare function linkToggleAllowed(configs: readonly SeriesConfig[], id:
|
|
|
625
636
|
* gutters.
|
|
626
637
|
*/
|
|
627
638
|
export declare function swapAllowed(configs: readonly SeriesConfig[], id: string): boolean;
|
|
628
|
-
/**
|
|
629
|
-
* Whether `other` can be wired by hand as `target`'s compare other side
|
|
630
|
-
* ({@link SeriesConfig.compareWith}): the target must be able to carry a
|
|
631
|
-
* compare at all ({@link compareFnAllowed}), and the other side must be a
|
|
632
|
-
* different config with ONE line to read — its only line, or the one
|
|
633
|
-
* `output` names when it draws several ({@link compareWithInput}).
|
|
634
|
-
*/
|
|
635
|
-
export declare function compareWithAllowed(target: SeriesConfig, other: SeriesConfig, output?: string): boolean;
|
|
636
639
|
/**
|
|
637
640
|
* Whether a seated config can carry a compare function
|
|
638
|
-
* ({@link SeriesConfig.compareFn})
|
|
639
|
-
* ({@link SeriesConfig.compareWith}).
|
|
641
|
+
* ({@link SeriesConfig.compareFn}).
|
|
640
642
|
*
|
|
641
643
|
* Only the ROOT of a chain — a metric, raw or a derived catalog metric, never
|
|
642
644
|
* a study: the function sits straight after the metric and every study on it
|
|
@@ -651,7 +653,9 @@ export declare function compareFnAllowed(c: SeriesConfig): boolean;
|
|
|
651
653
|
export declare function canonRows(rows: readonly RowState[]): string;
|
|
652
654
|
/** The active slot: first saved preset whose rows deep-equal the live rows, else
|
|
653
655
|
* null (custom). The single derivation behind the filled circle + the seed. */
|
|
654
|
-
export declare function activeSlot(presets: readonly (TerminalPreset | null)[], rows: readonly RowState[]): number | null;
|
|
656
|
+
export declare function activeSlot(presets: readonly (TerminalPreset | null)[], rows: readonly RowState[], sourceLocks?: SourceLocks): number | null;
|
|
657
|
+
/** A stored preset's locks, keeping only entries the lock guard would take. */
|
|
658
|
+
export declare function validLocks(raw: unknown): SourceLocks;
|
|
655
659
|
export declare const terminalMachine: import("xstate").StateMachine<TerminalContext, {
|
|
656
660
|
type: "series.add";
|
|
657
661
|
catalogId: string;
|
|
@@ -709,7 +713,7 @@ export declare const terminalMachine: import("xstate").StateMachine<TerminalCont
|
|
|
709
713
|
} | {
|
|
710
714
|
type: "series.patch";
|
|
711
715
|
id: string;
|
|
712
|
-
patch: Partial<Omit<SeriesConfig, "axis" | "axisGroup" | "parentIds" | "compareFn" | "
|
|
716
|
+
patch: Partial<Omit<SeriesConfig, "axis" | "axisGroup" | "parentIds" | "compareFn" | "compareOn">>;
|
|
713
717
|
} | {
|
|
714
718
|
type: "series.toggleVisible";
|
|
715
719
|
id: string;
|
|
@@ -718,12 +722,8 @@ export declare const terminalMachine: import("xstate").StateMachine<TerminalCont
|
|
|
718
722
|
id: string;
|
|
719
723
|
fn: PairOp | null;
|
|
720
724
|
} | {
|
|
721
|
-
type: "
|
|
722
|
-
|
|
723
|
-
with: CompareWith | null;
|
|
724
|
-
} | {
|
|
725
|
-
type: "series.setCompareOn";
|
|
726
|
-
id: string;
|
|
725
|
+
type: "source.setLock";
|
|
726
|
+
source: string;
|
|
727
727
|
symbol: string | null;
|
|
728
728
|
} | {
|
|
729
729
|
type: "group.toggleVisible";
|
|
@@ -841,10 +841,7 @@ export declare const terminalMachine: import("xstate").StateMachine<TerminalCont
|
|
|
841
841
|
type: "setCompareFn";
|
|
842
842
|
params: import("xstate").NonReducibleUnknown;
|
|
843
843
|
} | {
|
|
844
|
-
type: "
|
|
845
|
-
params: import("xstate").NonReducibleUnknown;
|
|
846
|
-
} | {
|
|
847
|
-
type: "setCompareOn";
|
|
844
|
+
type: "setSourceLock";
|
|
848
845
|
params: import("xstate").NonReducibleUnknown;
|
|
849
846
|
} | {
|
|
850
847
|
type: "patchSeries";
|
|
@@ -931,10 +928,7 @@ export declare const terminalMachine: import("xstate").StateMachine<TerminalCont
|
|
|
931
928
|
type: "canSetCompareFn";
|
|
932
929
|
params: unknown;
|
|
933
930
|
} | {
|
|
934
|
-
type: "
|
|
935
|
-
params: unknown;
|
|
936
|
-
} | {
|
|
937
|
-
type: "canSetCompareOn";
|
|
931
|
+
type: "canSetSourceLock";
|
|
938
932
|
params: unknown;
|
|
939
933
|
} | {
|
|
940
934
|
type: "canSetStudyParam";
|
package/dist/terminalMachine.js
CHANGED
|
@@ -32,7 +32,7 @@ function hidesPointer(context, toggledId, pointer) {
|
|
|
32
32
|
return cascade.has(pointer);
|
|
33
33
|
}
|
|
34
34
|
import { axisRangeIsEmpty, logAllowed, isStudySeries, readsFrom, sourcesOf, fanIsBand, offersOutputBars, publishedColumns, } from '@tidal-ts/chart';
|
|
35
|
-
import { configAxisId, seriesAxisId, sharedAxisId,
|
|
35
|
+
import { configAxisId, seriesAxisId, sharedAxisId, } from '@tidal-ts/chart';
|
|
36
36
|
import { axisForAdd, canAddUnit } from './axisPolicy.js';
|
|
37
37
|
export const PRESET_SETS = ['plain', 'compare'];
|
|
38
38
|
/** Slots in each preset set. */
|
|
@@ -1072,7 +1072,7 @@ export function dataColumnsAllowed(scope, id, columns) {
|
|
|
1072
1072
|
function coherentPatch(c, patch) {
|
|
1073
1073
|
// `compareFn` is set only through `series.setCompareFn` and its guard; a
|
|
1074
1074
|
// patch that names it (an untyped caller) is not let around that guard.
|
|
1075
|
-
const { compareFn: _ignored,
|
|
1075
|
+
const { compareFn: _ignored, compareOn: _locked, ...asked } = patch;
|
|
1076
1076
|
return keepCompareFnCoherent(drawablePatch(c, asked));
|
|
1077
1077
|
}
|
|
1078
1078
|
function drawablePatch(c, patch) {
|
|
@@ -1095,41 +1095,11 @@ function drawablePatch(c, patch) {
|
|
|
1095
1095
|
* review). Everything else passes through unchanged.
|
|
1096
1096
|
*/
|
|
1097
1097
|
function keepCompareFnCoherent(c) {
|
|
1098
|
-
if ((!c.compareFn && !c.
|
|
1098
|
+
if ((!c.compareFn && !c.compareOn) || compareFnAllowed(c))
|
|
1099
1099
|
return c;
|
|
1100
|
-
const { compareFn: _drop,
|
|
1100
|
+
const { compareFn: _drop, compareOn: _dropOn, ...rest } = c;
|
|
1101
1101
|
return rest;
|
|
1102
1102
|
}
|
|
1103
|
-
/**
|
|
1104
|
-
* Rows with every hand-wired compare that no longer holds made automatic
|
|
1105
|
-
* again: the config it names is gone, or has stopped being one line to read
|
|
1106
|
-
* ({@link compareWithAllowed}) — pulled into a pair as a leg, given several
|
|
1107
|
-
* columns, a band or a fan. Run after every edit that can change either side,
|
|
1108
|
-
* so a saved config never carries a wiring the guard would refuse (PR #48
|
|
1109
|
-
* review). Returns `rows` itself when nothing changes.
|
|
1110
|
-
*/
|
|
1111
|
-
function keepCompareWithValid(rows) {
|
|
1112
|
-
const byId = new Map(flatConfigs(rows).map((c) => [c.id, c]));
|
|
1113
|
-
const holds = (c) => {
|
|
1114
|
-
if (!c.compareWith)
|
|
1115
|
-
return true;
|
|
1116
|
-
const other = byId.get(c.compareWith.id);
|
|
1117
|
-
return !!other && compareWithAllowed(c, other, c.compareWith.output);
|
|
1118
|
-
};
|
|
1119
|
-
if (flatConfigs(rows).every(holds))
|
|
1120
|
-
return rows;
|
|
1121
|
-
return rows.map((r) => ({
|
|
1122
|
-
...r,
|
|
1123
|
-
configs: r.configs.map((c) => {
|
|
1124
|
-
if (holds(c))
|
|
1125
|
-
return c;
|
|
1126
|
-
const { compareWith: _drop, ...rest } = c;
|
|
1127
|
-
return rest;
|
|
1128
|
-
}),
|
|
1129
|
-
}));
|
|
1130
|
-
}
|
|
1131
|
-
/** A rows assigner whose result passes through {@link keepCompareWithValid}. */
|
|
1132
|
-
const keepingCompareWithValid = (fn) => (args) => keepCompareWithValid(fn(args));
|
|
1133
1103
|
/** Bar price columns in the bar's own order. */
|
|
1134
1104
|
const barOrder = (columns) => [...columns].sort((a, b) => BAR_PRICE_COLUMNS.indexOf(a) - BAR_PRICE_COLUMNS.indexOf(b));
|
|
1135
1105
|
/**
|
|
@@ -1831,28 +1801,9 @@ function comparableMetric(c) {
|
|
|
1831
1801
|
return false; // a fan is several lines too
|
|
1832
1802
|
return !c.column.startsWith(COMPARE_PREFIX);
|
|
1833
1803
|
}
|
|
1834
|
-
/**
|
|
1835
|
-
* Whether `other` can be wired by hand as `target`'s compare other side
|
|
1836
|
-
* ({@link SeriesConfig.compareWith}): the target must be able to carry a
|
|
1837
|
-
* compare at all ({@link compareFnAllowed}), and the other side must be a
|
|
1838
|
-
* different config with ONE line to read — its only line, or the one
|
|
1839
|
-
* `output` names when it draws several ({@link compareWithInput}).
|
|
1840
|
-
*/
|
|
1841
|
-
export function compareWithAllowed(target, other, output) {
|
|
1842
|
-
if (!compareFnAllowed(target) || other.id === target.id)
|
|
1843
|
-
return false;
|
|
1844
|
-
// Read from its own spec: the same refusals as a function's metric, except
|
|
1845
|
-
// that a study is a fine other side (price against its own SMA).
|
|
1846
|
-
if (other.group || other.column.startsWith(COMPARE_PREFIX))
|
|
1847
|
-
return false;
|
|
1848
|
-
if (other.derive && (hasPairOp(other.derive) || usesCompare(other.derive)))
|
|
1849
|
-
return false;
|
|
1850
|
-
return compareWithInput(other, output) !== null;
|
|
1851
|
-
}
|
|
1852
1804
|
/**
|
|
1853
1805
|
* Whether a seated config can carry a compare function
|
|
1854
|
-
* ({@link SeriesConfig.compareFn})
|
|
1855
|
-
* ({@link SeriesConfig.compareWith}).
|
|
1806
|
+
* ({@link SeriesConfig.compareFn}).
|
|
1856
1807
|
*
|
|
1857
1808
|
* Only the ROOT of a chain — a metric, raw or a derived catalog metric, never
|
|
1858
1809
|
* a study: the function sits straight after the metric and every study on it
|
|
@@ -1883,9 +1834,6 @@ export function compareFnAllowed(c) {
|
|
|
1883
1834
|
return true;
|
|
1884
1835
|
}
|
|
1885
1836
|
export function canonRows(rows) {
|
|
1886
|
-
// A hand-wired compare names its other side by config id, which is minted;
|
|
1887
|
-
// it hashes by what that config draws (its column) and the side instead.
|
|
1888
|
-
const columnOf = new Map(rows.flatMap((r) => r.configs.map((c) => [c.id, c.column])));
|
|
1889
1837
|
return JSON.stringify(rows.map((r) => {
|
|
1890
1838
|
// Axis membership is preset identity — but `axisGroup` is a MINTED config
|
|
1891
1839
|
// id, and hashing it would make a hand-rebuilt copy of a saved preset read
|
|
@@ -1946,23 +1894,10 @@ export function canonRows(rows) {
|
|
|
1946
1894
|
// How the metric reads under a comparison, appended only when any of
|
|
1947
1895
|
// it is set, so a config without it hashes exactly as it did before
|
|
1948
1896
|
// these fields existed and a saved preset still matches: one joined
|
|
1949
|
-
// line or two (`compareFn`)
|
|
1950
|
-
//
|
|
1951
|
-
//
|
|
1952
|
-
|
|
1953
|
-
// after the last one present.
|
|
1954
|
-
...trimNulls([
|
|
1955
|
-
c.compareFn || null,
|
|
1956
|
-
c.compareWith
|
|
1957
|
-
? [
|
|
1958
|
-
columnOf.get(c.compareWith.id) ?? null,
|
|
1959
|
-
c.compareWith.side,
|
|
1960
|
-
...(c.compareWith.output ? [c.compareWith.output] : []),
|
|
1961
|
-
]
|
|
1962
|
-
: null,
|
|
1963
|
-
c.compareOn || null,
|
|
1964
|
-
styleEntries(c.compareStyle),
|
|
1965
|
-
]),
|
|
1897
|
+
// line or two (`compareFn`) and how its compared line draws
|
|
1898
|
+
// (`compareStyle`). Each takes its slot, an absent one a `null`, and
|
|
1899
|
+
// the tail is cut after the last one present.
|
|
1900
|
+
...trimNulls([c.compareFn || null, styleEntries(c.compareStyle)]),
|
|
1966
1901
|
]),
|
|
1967
1902
|
];
|
|
1968
1903
|
}));
|
|
@@ -1985,12 +1920,38 @@ const trimNulls = (xs) => {
|
|
|
1985
1920
|
};
|
|
1986
1921
|
/** The active slot: first saved preset whose rows deep-equal the live rows, else
|
|
1987
1922
|
* null (custom). The single derivation behind the filled circle + the seed. */
|
|
1988
|
-
export function activeSlot(presets, rows) {
|
|
1989
|
-
const live = canonRows(rows);
|
|
1990
|
-
const i = presets.findIndex((p) => p != null && canonRows(p.rows) === live);
|
|
1923
|
+
export function activeSlot(presets, rows, sourceLocks = {}) {
|
|
1924
|
+
const live = canonRows(rows) + canonLocks(sourceLocks);
|
|
1925
|
+
const i = presets.findIndex((p) => p != null && canonRows(p.rows) + canonLocks(validLocks(p.sourceLocks)) === live);
|
|
1991
1926
|
return i === -1 ? null : i;
|
|
1992
1927
|
}
|
|
1993
|
-
|
|
1928
|
+
/** Source locks as a key, in source order; empty for none, so a preset with no
|
|
1929
|
+
* locks matches exactly as it did before locks existed. */
|
|
1930
|
+
const canonLocks = (locks) => {
|
|
1931
|
+
const keys = Object.keys(locks).sort();
|
|
1932
|
+
return keys.length ? JSON.stringify(keys.map((k) => [k, locks[k]])) : '';
|
|
1933
|
+
};
|
|
1934
|
+
/** A stored preset's locks, keeping only entries the lock guard would take. */
|
|
1935
|
+
export function validLocks(raw) {
|
|
1936
|
+
if (raw == null || typeof raw !== 'object' || Array.isArray(raw))
|
|
1937
|
+
return {};
|
|
1938
|
+
return Object.fromEntries(Object.entries(raw).filter((e) => e[0] !== '' && typeof e[1] === 'string' && isPinnableSymbol(e[1])));
|
|
1939
|
+
}
|
|
1940
|
+
const cloneRows = (rows) => rows.map((r) => ({
|
|
1941
|
+
...r,
|
|
1942
|
+
configs: r.configs.map((c) => ({ ...withoutLineLock(c), value: null })),
|
|
1943
|
+
}));
|
|
1944
|
+
/**
|
|
1945
|
+
* A config without the per-line compare fields an older build saved: a lock
|
|
1946
|
+
* on the line (`compareOn`, now the source's and stamped by the host) and a
|
|
1947
|
+
* hand wiring (`compareWith`, removed). Applied to every row the machine takes
|
|
1948
|
+
* in — seeded or from a preset — so a stale one cannot draw a lock the
|
|
1949
|
+
* source does not have.
|
|
1950
|
+
*/
|
|
1951
|
+
function withoutLineLock(c) {
|
|
1952
|
+
const { compareOn: _lock, compareWith: _wire, ...rest } = c;
|
|
1953
|
+
return rest;
|
|
1954
|
+
}
|
|
1994
1955
|
// --- the machine -------------------------------------------------------------
|
|
1995
1956
|
export const terminalMachine = setup({
|
|
1996
1957
|
types: {
|
|
@@ -2166,35 +2127,13 @@ export const terminalMachine = setup({
|
|
|
2166
2127
|
// can no longer carry one must still be removable.
|
|
2167
2128
|
return event.fn === null || (isPairOp(event.fn) && compareFnAllowed(target));
|
|
2168
2129
|
},
|
|
2169
|
-
|
|
2170
|
-
if (event.type !== '
|
|
2171
|
-
return false;
|
|
2172
|
-
const all = flatConfigs(context.rows);
|
|
2173
|
-
const target = all.find((c) => c.id === event.id);
|
|
2174
|
-
if (!target)
|
|
2175
|
-
return false;
|
|
2176
|
-
if (event.with === null)
|
|
2177
|
-
return true;
|
|
2178
|
-
if (event.with.side !== 'primary' && event.with.side !== 'comparison')
|
|
2130
|
+
canSetSourceLock: ({ event }) => {
|
|
2131
|
+
if (event.type !== 'source.setLock')
|
|
2179
2132
|
return false;
|
|
2180
|
-
|
|
2181
|
-
// A name, or none: an empty name would be stored as none.
|
|
2182
|
-
if (output !== undefined && (typeof output !== 'string' || output === ''))
|
|
2133
|
+
if (typeof event.source !== 'string' || event.source === '')
|
|
2183
2134
|
return false;
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
},
|
|
2187
|
-
canSetCompareOn: ({ context, event }) => {
|
|
2188
|
-
if (event.type !== 'series.setCompareOn')
|
|
2189
|
-
return false;
|
|
2190
|
-
const target = flatConfigs(context.rows).find((c) => c.id === event.id);
|
|
2191
|
-
if (!target)
|
|
2192
|
-
return false;
|
|
2193
|
-
if (event.symbol === null)
|
|
2194
|
-
return true;
|
|
2195
|
-
return (typeof event.symbol === 'string' &&
|
|
2196
|
-
isPinnableSymbol(event.symbol) &&
|
|
2197
|
-
compareFnAllowed(target));
|
|
2135
|
+
return (event.symbol === null ||
|
|
2136
|
+
(typeof event.symbol === 'string' && isPinnableSymbol(event.symbol)));
|
|
2198
2137
|
},
|
|
2199
2138
|
canSetStudyParam: ({ context, event }) => event.type === 'series.setStudyParam' &&
|
|
2200
2139
|
respecAllowed(context, event.id, event.name, event.value),
|
|
@@ -2305,7 +2244,7 @@ export const terminalMachine = setup({
|
|
|
2305
2244
|
},
|
|
2306
2245
|
}),
|
|
2307
2246
|
addPair: assign({
|
|
2308
|
-
rows:
|
|
2247
|
+
rows: ({ context, event }) => {
|
|
2309
2248
|
if (event.type !== 'series.addPair')
|
|
2310
2249
|
return context.rows;
|
|
2311
2250
|
const a = resolveLeg(context, event.a.metricId);
|
|
@@ -2360,7 +2299,7 @@ export const terminalMachine = setup({
|
|
|
2360
2299
|
});
|
|
2361
2300
|
}
|
|
2362
2301
|
return context.rows.map((r) => r.id === row.id ? { ...r, configs: [cfg, ...r.configs] } : r);
|
|
2363
|
-
}
|
|
2302
|
+
},
|
|
2364
2303
|
// Expand the new node so its controls open for tuning — the spread, or
|
|
2365
2304
|
// (unjoined) whichever leg took the group's first minted id. Nothing to
|
|
2366
2305
|
// expand when BOTH legs were adopted: no config was created.
|
|
@@ -2389,17 +2328,17 @@ export const terminalMachine = setup({
|
|
|
2389
2328
|
// expansion, ink, axis membership and range pins all survive (they used to
|
|
2390
2329
|
// be destroyed, and the dependents deleted outright).
|
|
2391
2330
|
setStudyOutput: assign({
|
|
2392
|
-
rows:
|
|
2331
|
+
rows: ({ context, event }) => {
|
|
2393
2332
|
if (event.type !== 'series.setStudyOutput')
|
|
2394
2333
|
return context.rows;
|
|
2395
2334
|
const target = flatConfigs(context.rows).find((c) => c.id === event.id);
|
|
2396
2335
|
if (!target?.derive)
|
|
2397
2336
|
return context.rows;
|
|
2398
2337
|
return applyRespec(context, event.id, respecOutput(target, event.output));
|
|
2399
|
-
}
|
|
2338
|
+
},
|
|
2400
2339
|
}),
|
|
2401
2340
|
setStudyInput: assign({
|
|
2402
|
-
rows:
|
|
2341
|
+
rows: ({ context, event }) => {
|
|
2403
2342
|
if (event.type !== 'series.setStudyInput')
|
|
2404
2343
|
return context.rows;
|
|
2405
2344
|
const configs = flatConfigs(context.rows);
|
|
@@ -2431,10 +2370,10 @@ export const terminalMachine = setup({
|
|
|
2431
2370
|
return { ...c, parentIds };
|
|
2432
2371
|
}),
|
|
2433
2372
|
}));
|
|
2434
|
-
}
|
|
2373
|
+
},
|
|
2435
2374
|
}),
|
|
2436
2375
|
setDataColumns: assign({
|
|
2437
|
-
rows:
|
|
2376
|
+
rows: ({ context, event }) => {
|
|
2438
2377
|
if (event.type !== 'series.setDataColumns')
|
|
2439
2378
|
return context.rows;
|
|
2440
2379
|
const configs = flatConfigs(context.rows);
|
|
@@ -2470,10 +2409,10 @@ export const terminalMachine = setup({
|
|
|
2470
2409
|
return { ...c, parentIds };
|
|
2471
2410
|
}),
|
|
2472
2411
|
}));
|
|
2473
|
-
}
|
|
2412
|
+
},
|
|
2474
2413
|
}),
|
|
2475
2414
|
setStudyOutputs: assign({
|
|
2476
|
-
rows:
|
|
2415
|
+
rows: ({ context, event }) => {
|
|
2477
2416
|
if (event.type !== 'series.setStudyOutputs')
|
|
2478
2417
|
return context.rows;
|
|
2479
2418
|
const study = flatConfigs(context.rows).find((c) => c.id === event.id);
|
|
@@ -2491,17 +2430,17 @@ export const terminalMachine = setup({
|
|
|
2491
2430
|
...r,
|
|
2492
2431
|
configs: r.configs.map((c) => c.id === event.id ? { ...c, fan: next.fan, style: next.style } : c),
|
|
2493
2432
|
}));
|
|
2494
|
-
}
|
|
2433
|
+
},
|
|
2495
2434
|
}),
|
|
2496
2435
|
setStudyParam: assign({
|
|
2497
|
-
rows:
|
|
2436
|
+
rows: ({ context, event }) => {
|
|
2498
2437
|
if (event.type !== 'series.setStudyParam')
|
|
2499
2438
|
return context.rows;
|
|
2500
2439
|
const target = flatConfigs(context.rows).find((c) => c.id === event.id);
|
|
2501
2440
|
if (!target?.derive)
|
|
2502
2441
|
return context.rows;
|
|
2503
2442
|
return applyRespec(context, event.id, respecParam(target, event.name, event.value));
|
|
2504
|
-
}
|
|
2443
|
+
},
|
|
2505
2444
|
}),
|
|
2506
2445
|
addSeries: assign({
|
|
2507
2446
|
rows: ({ context, event }) => {
|
|
@@ -2548,7 +2487,7 @@ export const terminalMachine = setup({
|
|
|
2548
2487
|
},
|
|
2549
2488
|
}),
|
|
2550
2489
|
removeGroup: assign({
|
|
2551
|
-
rows:
|
|
2490
|
+
rows: ({ context, event }) => {
|
|
2552
2491
|
if (event.type !== 'group.remove')
|
|
2553
2492
|
return context.rows;
|
|
2554
2493
|
const doomed = groupDoomed(context.rows, event.groupId);
|
|
@@ -2557,7 +2496,7 @@ export const terminalMachine = setup({
|
|
|
2557
2496
|
configs: r.configs.filter((c) => !doomed.has(c.id)),
|
|
2558
2497
|
}));
|
|
2559
2498
|
return pruneEmptied(context.rows, mapped);
|
|
2560
|
-
}
|
|
2499
|
+
},
|
|
2561
2500
|
// The same invariant `removeSeries` states: neither pointer may point at a
|
|
2562
2501
|
// removed series. Sibling assigners read the PRE-update context, so both
|
|
2563
2502
|
// recompute the doomed set rather than reading the new rows (PR #149
|
|
@@ -2623,7 +2562,7 @@ export const terminalMachine = setup({
|
|
|
2623
2562
|
},
|
|
2624
2563
|
}),
|
|
2625
2564
|
removeSeries: assign({
|
|
2626
|
-
rows:
|
|
2565
|
+
rows: ({ context, event }) => {
|
|
2627
2566
|
if (event.type !== 'series.remove')
|
|
2628
2567
|
return context.rows;
|
|
2629
2568
|
// Cascade to dependent studies so a nested study can't strand invisible +
|
|
@@ -2644,7 +2583,7 @@ export const terminalMachine = setup({
|
|
|
2644
2583
|
// Not only the host row: an oscillator on its own row is in the
|
|
2645
2584
|
// cascade, and its row must not stay behind as an empty pane.
|
|
2646
2585
|
return pruneEmptied(context.rows, mapped);
|
|
2647
|
-
}
|
|
2586
|
+
},
|
|
2648
2587
|
// Neither pointer may point at a removed series (or a cascaded dependent).
|
|
2649
2588
|
selected: ({ context, event }) => event.type === 'series.remove' &&
|
|
2650
2589
|
context.selected != null &&
|
|
@@ -2661,7 +2600,7 @@ export const terminalMachine = setup({
|
|
|
2661
2600
|
// (a drag's absolute drop). Both splice-move within the series' own row; the
|
|
2662
2601
|
// list is front→back, so index 0 is topmost on the canvas.
|
|
2663
2602
|
orderSeries: assign({
|
|
2664
|
-
rows:
|
|
2603
|
+
rows: ({ context, event }) => {
|
|
2665
2604
|
if (event.type !== 'series.order' && event.type !== 'series.reindex')
|
|
2666
2605
|
return context.rows;
|
|
2667
2606
|
return context.rows.map((r) => {
|
|
@@ -2680,14 +2619,14 @@ export const terminalMachine = setup({
|
|
|
2680
2619
|
: Math.max(0, Math.min(event.index, blocks.length - 1));
|
|
2681
2620
|
return to === i ? r : { ...r, configs: reindex(blocks, i, to).flat() };
|
|
2682
2621
|
});
|
|
2683
|
-
}
|
|
2622
|
+
},
|
|
2684
2623
|
}),
|
|
2685
2624
|
// Cross-row move: the series leaves its row (pruned if that empties it, as
|
|
2686
2625
|
// with remove) and lands at the FRONT of the target row, on an axis its unit
|
|
2687
2626
|
// can take there (the guard already proved one exists). Studies layered on it
|
|
2688
2627
|
// travel with it, so a study can't strand on a row without its source.
|
|
2689
2628
|
moveSeriesToRow: assign({
|
|
2690
|
-
rows:
|
|
2629
|
+
rows: ({ context, event }) => {
|
|
2691
2630
|
if (event.type !== 'series.moveToRow')
|
|
2692
2631
|
return context.rows;
|
|
2693
2632
|
const from = context.rows.find((r) => r.configs.some((c) => c.id === event.id));
|
|
@@ -2711,7 +2650,7 @@ export const terminalMachine = setup({
|
|
|
2711
2650
|
});
|
|
2712
2651
|
// An emptied source row goes away; the remainder row is kept.
|
|
2713
2652
|
return pruneEmptied(context.rows, mapped);
|
|
2714
|
-
}
|
|
2653
|
+
},
|
|
2715
2654
|
}),
|
|
2716
2655
|
setCompareFn: assign({
|
|
2717
2656
|
rows: ({ context, event }) => {
|
|
@@ -2732,47 +2671,17 @@ export const terminalMachine = setup({
|
|
|
2732
2671
|
: r);
|
|
2733
2672
|
},
|
|
2734
2673
|
}),
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
if (event.type !== '
|
|
2738
|
-
return context.
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
configs: r.configs.map((c) => {
|
|
2743
|
-
if (c.id !== event.id)
|
|
2744
|
-
return c;
|
|
2745
|
-
// Automatic again by REMOVING the key, as for the function.
|
|
2746
|
-
const { compareWith: _drop, ...rest } = c;
|
|
2747
|
-
if (!event.with)
|
|
2748
|
-
return rest;
|
|
2749
|
-
const { id, side, output } = event.with;
|
|
2750
|
-
return { ...rest, compareWith: { id, side, ...(output ? { output } : {}) } };
|
|
2751
|
-
}),
|
|
2752
|
-
}
|
|
2753
|
-
: r);
|
|
2754
|
-
},
|
|
2755
|
-
}),
|
|
2756
|
-
setCompareOn: assign({
|
|
2757
|
-
rows: ({ context, event }) => {
|
|
2758
|
-
if (event.type !== 'series.setCompareOn')
|
|
2759
|
-
return context.rows;
|
|
2760
|
-
return context.rows.map((r) => r.configs.some((c) => c.id === event.id)
|
|
2761
|
-
? {
|
|
2762
|
-
...r,
|
|
2763
|
-
configs: r.configs.map((c) => {
|
|
2764
|
-
if (c.id !== event.id)
|
|
2765
|
-
return c;
|
|
2766
|
-
// Unlocked by REMOVING the key, as for the function.
|
|
2767
|
-
const { compareOn: _drop, ...rest } = c;
|
|
2768
|
-
return event.symbol ? { ...rest, compareOn: event.symbol } : rest;
|
|
2769
|
-
}),
|
|
2770
|
-
}
|
|
2771
|
-
: r);
|
|
2674
|
+
setSourceLock: assign({
|
|
2675
|
+
sourceLocks: ({ context, event }) => {
|
|
2676
|
+
if (event.type !== 'source.setLock')
|
|
2677
|
+
return context.sourceLocks;
|
|
2678
|
+
// Unlocked by REMOVING the key, so an unlocked source saves no entry.
|
|
2679
|
+
const { [event.source]: _drop, ...rest } = context.sourceLocks;
|
|
2680
|
+
return event.symbol ? { ...rest, [event.source]: event.symbol } : rest;
|
|
2772
2681
|
},
|
|
2773
2682
|
}),
|
|
2774
2683
|
patchSeries: assign({
|
|
2775
|
-
rows:
|
|
2684
|
+
rows: ({ context, event }) => {
|
|
2776
2685
|
if (event.type !== 'series.patch')
|
|
2777
2686
|
return context.rows;
|
|
2778
2687
|
// A study's colour is its parent's until the user says otherwise
|
|
@@ -2817,7 +2726,7 @@ export const terminalMachine = setup({
|
|
|
2817
2726
|
? { ...c, color: color }
|
|
2818
2727
|
: c),
|
|
2819
2728
|
}));
|
|
2820
|
-
}
|
|
2729
|
+
},
|
|
2821
2730
|
}),
|
|
2822
2731
|
toggleVisible: assign({
|
|
2823
2732
|
rows: ({ context, event }) => {
|
|
@@ -2888,6 +2797,13 @@ export const terminalMachine = setup({
|
|
|
2888
2797
|
// remainder row, which would reproduce the stuck-seam bug on apply.
|
|
2889
2798
|
return p ? withRemainder(cloneRows(p.rows)) : context.rows;
|
|
2890
2799
|
},
|
|
2800
|
+
// The preset's locks, or none: a preset restores the whole look.
|
|
2801
|
+
sourceLocks: ({ context, event }) => {
|
|
2802
|
+
if (event.type !== 'preset.select')
|
|
2803
|
+
return context.sourceLocks;
|
|
2804
|
+
const p = context.presets[context.presetSet][event.slot];
|
|
2805
|
+
return p ? validLocks(p.sourceLocks) : context.sourceLocks;
|
|
2806
|
+
},
|
|
2891
2807
|
// The applied rows are a fresh config — neither pointer necessarily survives.
|
|
2892
2808
|
selected: null,
|
|
2893
2809
|
expanded: null,
|
|
@@ -2920,7 +2836,12 @@ export const terminalMachine = setup({
|
|
|
2920
2836
|
return context.presets;
|
|
2921
2837
|
const set = context.presetSet;
|
|
2922
2838
|
const next = context.presets[set].slice();
|
|
2923
|
-
next[event.slot] = {
|
|
2839
|
+
next[event.slot] = {
|
|
2840
|
+
rows: cloneRows(context.rows),
|
|
2841
|
+
...(Object.keys(context.sourceLocks).length
|
|
2842
|
+
? { sourceLocks: { ...context.sourceLocks } }
|
|
2843
|
+
: {}),
|
|
2844
|
+
};
|
|
2924
2845
|
context.storage.savePresets(set, next);
|
|
2925
2846
|
return { ...context.presets, [set]: next };
|
|
2926
2847
|
},
|
|
@@ -3158,7 +3079,7 @@ export const terminalMachine = setup({
|
|
|
3158
3079
|
removeRow: assign({
|
|
3159
3080
|
// Removing a row is removing each of its series (`rowDoomed`), so a
|
|
3160
3081
|
// study of one of its STUDIES goes too, on whatever row it sits.
|
|
3161
|
-
rows:
|
|
3082
|
+
rows: ({ context, event }) => {
|
|
3162
3083
|
if (event.type !== 'row.remove' || context.rows.length <= 1)
|
|
3163
3084
|
return context.rows;
|
|
3164
3085
|
const doomed = rowDoomed(context.rows, event.id);
|
|
@@ -3168,7 +3089,7 @@ export const terminalMachine = setup({
|
|
|
3168
3089
|
// Removing the remainder row would leave the stack with none, so the
|
|
3169
3090
|
// first survivor takes over as the one that absorbs slack.
|
|
3170
3091
|
return pruneEmptied(context.rows, after);
|
|
3171
|
-
}
|
|
3092
|
+
},
|
|
3172
3093
|
// Removing a row drops its series for good, so a pointer into it can't return
|
|
3173
3094
|
// (unlike a ticker switch) — clear both (mirrors removeSeries).
|
|
3174
3095
|
selected: ({ context, event }) => {
|
|
@@ -3194,7 +3115,8 @@ export const terminalMachine = setup({
|
|
|
3194
3115
|
// reload re-seeds from the stored ACTIVE preset), so a blob written before
|
|
3195
3116
|
// `withRemainder` existed — or any future host that forgets — would boot
|
|
3196
3117
|
// straight into the stuck-seam state rather than being healed on first edit.
|
|
3197
|
-
rows: withRemainder(input.initialRows),
|
|
3118
|
+
rows: withRemainder(input.initialRows.map((r) => ({ ...r, configs: r.configs.map(withoutLineLock) }))),
|
|
3119
|
+
sourceLocks: validLocks(input.initialSourceLocks),
|
|
3198
3120
|
palette: input.palette ?? [],
|
|
3199
3121
|
spreadColor: input.spreadColor,
|
|
3200
3122
|
axisRanges: {},
|
|
@@ -3248,8 +3170,7 @@ export const terminalMachine = setup({
|
|
|
3248
3170
|
'series.remove': { actions: 'removeSeries' },
|
|
3249
3171
|
'series.patch': { actions: 'patchSeries' },
|
|
3250
3172
|
'series.setCompareFn': { guard: 'canSetCompareFn', actions: 'setCompareFn' },
|
|
3251
|
-
'
|
|
3252
|
-
'series.setCompareOn': { guard: 'canSetCompareOn', actions: 'setCompareOn' },
|
|
3173
|
+
'source.setLock': { guard: 'canSetSourceLock', actions: 'setSourceLock' },
|
|
3253
3174
|
'series.toggleVisible': { actions: 'toggleVisible' },
|
|
3254
3175
|
'group.toggleVisible': { actions: 'toggleGroupVisible' },
|
|
3255
3176
|
'group.remove': { actions: 'removeGroup' },
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tidal-ts/terminal",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.30.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "The terminal machine — an XState v5 statechart that owns a chart's configuration (rows, series, studies, pairs, axes, presets) and never its data.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
"xstate": "^5.28.0"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@tidal-ts/chart": "0.
|
|
40
|
-
"@tidal-ts/core": "0.
|
|
39
|
+
"@tidal-ts/chart": "0.30.0",
|
|
40
|
+
"@tidal-ts/core": "0.30.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@pond-ts/charts": "^0.78.0",
|