@tidal-ts/terminal 0.22.0 → 0.24.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 CHANGED
@@ -1,8 +1,8 @@
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, PairLensOp, SeriesConfig } from '@tidal-ts/chart';
5
- import { type MetricEntry, type PairLegInput, type PresetStorage, type RowState, type TerminalPreset } from './terminalMachine.js';
4
+ import type { AxisRange, CompareWith, PairLensOp, SeriesConfig } from '@tidal-ts/chart';
5
+ import { type MetricEntry, type PairLegInput, type PresetSet, type PresetStorage, type RowState, type TerminalPreset } from './terminalMachine.js';
6
6
  export interface TerminalProviderProps {
7
7
  initialRows: RowState[];
8
8
  catalog: readonly MetricEntry[];
@@ -15,23 +15,30 @@ export interface TerminalProviderProps {
15
15
  /** What a new SPREAD draws in, when the host reserves a colour for one —
16
16
  * see {@link TerminalInput.spreadColor}. Absent ⇒ the first free palette key. */
17
17
  spreadColor?: string;
18
+ /** The preset set showing at mount — `compare` when the host reloads with a
19
+ * comparison named. Default `plain`. Read once, at mount: changing it later
20
+ * does nothing, so a host that switches sets as its comparison comes and
21
+ * goes sends {@link useSetPresetSet} instead. */
22
+ initialPresetSet?: PresetSet;
18
23
  /** An XState inspector (`@statelyai/inspect`'s `inspect`, or any observer of
19
24
  * inspection events). The host decides whether and when to attach one; the
20
25
  * machine has no opinion and no build-time flag. */
21
26
  inspect?: Observer<InspectionEvent> | ((event: InspectionEvent) => void);
22
27
  children: ReactNode;
23
28
  }
24
- export declare function TerminalProvider({ initialRows, catalog, storage, palette, spreadColor, inspect, children, }: TerminalProviderProps): import("react").JSX.Element;
29
+ export declare function TerminalProvider({ initialRows, catalog, storage, palette, spreadColor, initialPresetSet, inspect, children, }: TerminalProviderProps): import("react").JSX.Element;
25
30
  export declare function useRows(): RowState[];
26
31
  export declare function useSelectedSeries(): string | null;
27
32
  /** The control-panel expansion (the row whose controls are open) — overrides the
28
33
  * app selection for emphasis while set. Null when nothing is expanded. */
29
34
  export declare function useExpandedSeries(): string | null;
30
35
  export declare function useControlsOpen(): boolean;
31
- /** Which preset slots hold a saved preset (length === PRESET_SLOTS). */
36
+ /** The preset set showing (`plain` or `compare`). */
37
+ export declare function usePresetSet(): PresetSet;
38
+ /** Which slots of the showing set hold a saved preset (length === PRESET_SLOTS). */
32
39
  export declare function usePresetSaved(): boolean[];
33
- /** The active slot — the saved slot whose rows deep-equal the live rows — or
34
- * null (a custom state). Derived, not stored. */
40
+ /** 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 stored. */
35
42
  export declare function useActiveSlot(): number | null;
36
43
  /** Per-axis range state, keyed by axis id (`configAxisId`). No entry = an
37
44
  * untouched auto axis; `mode:'auto'` with values = the preserved manual
@@ -49,6 +56,8 @@ export declare function useAddPair(): (a: PairLegInput, b: PairLegInput, op: Pai
49
56
  export declare function useCompareAll(): () => void;
50
57
  /** Set or clear (`null`) the function a compare applies to a metric. */
51
58
  export declare function useSetCompareFn(): (id: string, fn: PairOp | null) => void;
59
+ /** Wire a compare's other side by hand, or `null` for automatic. */
60
+ export declare function useSetCompareWith(): (id: string, other: CompareWith | null) => void;
52
61
  export declare function useSetStudyParam(): (id: string, name: string, value: number) => void;
53
62
  /** Switch which output of a multi-output source a study reads (the output
54
63
  * picker). Pair it with `outputAllowed` to render refused choices disabled. */
@@ -85,6 +94,8 @@ export declare function useExpandSeries(): (id: string | null) => void;
85
94
  export declare function useSetControlsOpen(): (open: boolean) => void;
86
95
  export declare function useSelectPreset(): (slot: number) => void;
87
96
  export declare function useSavePreset(): (slot: number) => void;
97
+ /** Show a preset set: `compare` while a comparison is named, else `plain`. */
98
+ export declare function useSetPresetSet(): (set: PresetSet) => void;
88
99
  export declare function useSetRowHeights(): (heights: Record<string, number>) => void;
89
100
  /** Toggle a series' axis membership — the panel's chain icon (unlink to its own
90
101
  * axis / unit-gated re-link into the side's shared axis; `linkToggleAllowed`
package/dist/context.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useCallback, useEffect } from 'react';
2
+ import { useCallback, useEffect, useRef } from 'react';
3
3
  import { createActorContext } from '@xstate/react';
4
4
  import { activeSlot, terminalMachine, } from './terminalMachine.js';
5
5
  /**
@@ -8,7 +8,7 @@ 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, inspect, children, }) {
11
+ export function TerminalProvider({ initialRows, catalog, storage, palette, spreadColor, initialPresetSet, inspect, children, }) {
12
12
  return (_jsxs(TerminalContext.Provider, { options: {
13
13
  input: {
14
14
  initialRows,
@@ -16,6 +16,7 @@ export function TerminalProvider({ initialRows, catalog, storage, palette, sprea
16
16
  storage,
17
17
  ...(palette ? { palette } : {}),
18
18
  ...(spreadColor ? { spreadColor } : {}),
19
+ ...(initialPresetSet ? { initialPresetSet } : {}),
19
20
  },
20
21
  ...(inspect ? { inspect } : {}),
21
22
  }, children: [_jsx(PersistActive, { storage: storage }), children] }));
@@ -23,10 +24,27 @@ export function TerminalProvider({ initialRows, catalog, storage, palette, sprea
23
24
  /** Persists the derived active-slot pointer so a fresh mount (a reload) can
24
25
  * re-seed from the last applied preset (see `seedTerminalRows`). The machine
25
26
  * owns preset *contents*; this is the only writer of the pointer. Renders
26
- * nothing. */
27
+ * nothing.
28
+ *
29
+ * It writes on a change, never at mount: the state a mount starts in came
30
+ * from what storage already holds, so there is nothing new to save — and a
31
+ * host whose set arrives a moment after mount (a comparison that resolves
32
+ * late) would otherwise overwrite the stored pointer with null first. */
27
33
  function PersistActive({ storage }) {
28
34
  const active = useActiveSlot();
29
- useEffect(() => storage.saveActive(active), [active, storage]);
35
+ const set = usePresetSet();
36
+ const last = useRef(null);
37
+ useEffect(() => {
38
+ const key = active == null ? 'none' : `${set}:${active}`;
39
+ if (last.current === null) {
40
+ last.current = key;
41
+ return;
42
+ }
43
+ if (last.current === key)
44
+ return;
45
+ last.current = key;
46
+ storage.saveActive(active == null ? null : { set, slot: active });
47
+ }, [active, set, storage]);
30
48
  return null;
31
49
  }
32
50
  // --- Read surface ----------------------------------------------------------
@@ -44,14 +62,18 @@ export function useExpandedSeries() {
44
62
  export function useControlsOpen() {
45
63
  return TerminalContext.useSelector((s) => s.context.controlsOpen);
46
64
  }
47
- /** Which preset slots hold a saved preset (length === PRESET_SLOTS). */
65
+ /** The preset set showing (`plain` or `compare`). */
66
+ export function usePresetSet() {
67
+ return TerminalContext.useSelector((s) => s.context.presetSet);
68
+ }
69
+ /** Which slots of the showing set hold a saved preset (length === PRESET_SLOTS). */
48
70
  export function usePresetSaved() {
49
- return TerminalContext.useSelector((s) => s.context.presets.map((p) => p != null));
71
+ return TerminalContext.useSelector((s) => s.context.presets[s.context.presetSet].map((p) => p != null));
50
72
  }
51
- /** The active slot — the saved slot whose rows deep-equal the live rows — or
52
- * null (a custom state). Derived, not stored. */
73
+ /** 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 stored. */
53
75
  export function useActiveSlot() {
54
- return TerminalContext.useSelector((s) => activeSlot(s.context.presets, s.context.rows));
76
+ return TerminalContext.useSelector((s) => activeSlot(s.context.presets[s.context.presetSet], s.context.rows));
55
77
  }
56
78
  /** Per-axis range state, keyed by axis id (`configAxisId`). No entry = an
57
79
  * untouched auto axis; `mode:'auto'` with values = the preserved manual
@@ -87,6 +109,11 @@ export function useSetCompareFn() {
87
109
  const ref = TerminalContext.useActorRef();
88
110
  return useCallback((id, fn) => ref.send({ type: 'series.setCompareFn', id, fn }), [ref]);
89
111
  }
112
+ /** Wire a compare's other side by hand, or `null` for automatic. */
113
+ export function useSetCompareWith() {
114
+ const ref = TerminalContext.useActorRef();
115
+ return useCallback((id, other) => ref.send({ type: 'series.setCompareWith', id, with: other }), [ref]);
116
+ }
90
117
  export function useSetStudyParam() {
91
118
  const ref = TerminalContext.useActorRef();
92
119
  return useCallback((id, name, value) => ref.send({ type: 'series.setStudyParam', id, name, value }), [ref]);
@@ -180,6 +207,11 @@ export function useSavePreset() {
180
207
  const ref = TerminalContext.useActorRef();
181
208
  return useCallback((slot) => ref.send({ type: 'preset.save', slot }), [ref]);
182
209
  }
210
+ /** Show a preset set: `compare` while a comparison is named, else `plain`. */
211
+ export function useSetPresetSet() {
212
+ const ref = TerminalContext.useActorRef();
213
+ return useCallback((set) => ref.send({ type: 'preset.useSet', set }), [ref]);
214
+ }
183
215
  export function useSetRowHeights() {
184
216
  const ref = TerminalContext.useActorRef();
185
217
  return useCallback((heights) => ref.send({ type: 'layout.setRowHeights', heights }), [ref]);
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, useSetStudyParam, useSetStudyOutput, useSetStudyInput, useSetDataColumns, useSetStudyOutputs, useOrderSeries, useReindexSeries, useMoveSeriesToRow, useMoveToAxis, useRemoveSeries, usePatchSeries, useToggleVisible, useToggleGroupVisible, useRemoveGroup, useSelectSeries, useExpandSeries, useSetControlsOpen, useSelectPreset, useSavePreset, useSetRowHeights, useAddRow, useRemoveRow, useAxisRanges, useToggleAxisLink, useSwapAxisSide, useSetAxisRange, useSetAxisAuto, useSetAxisLocks, useSetAxisAutoOpts, useSetAxisFormat, useTerminalHotkeys, type TerminalProviderProps, } from './context.js';
9
- export { PRESET_SLOTS, MAX_ROWS, activeSlot, canonRows, columnLabel, columnUnits, compareFnAllowed, 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 MetricEntry, type PairLegInput, type PresetStorage, type TerminalEvent, type TerminalInput, } from './terminalMachine.js';
8
+ export { TerminalProvider, useRows, useSelectedSeries, useExpandedSeries, useControlsOpen, usePresetSaved, useActiveSlot, useAddSeries, useAddPair, useCompareAll, useAddStudy, useSetCompareFn, useSetCompareWith, 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, compareWithAllowed, 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 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, useSetStudyParam, useSetStudyOutput, useSetStudyInput, useSetDataColumns, useSetStudyOutputs, useOrderSeries, useReindexSeries, useMoveSeriesToRow, useMoveToAxis, useRemoveSeries, usePatchSeries, useToggleVisible, useToggleGroupVisible, useRemoveGroup, useSelectSeries, useExpandSeries, useSetControlsOpen, useSelectPreset, useSavePreset, useSetRowHeights, useAddRow, useRemoveRow, useAxisRanges, useToggleAxisLink, useSwapAxisSide, useSetAxisRange, useSetAxisAuto, useSetAxisLocks, useSetAxisAutoOpts, useSetAxisFormat, useTerminalHotkeys, } from './context.js';
9
- export { PRESET_SLOTS, MAX_ROWS, activeSlot, canonRows, columnLabel, columnUnits, compareFnAllowed, entryColumn, groupMembers, mintId, axisMoveAllowed, linkToggleAllowed, respecAllowed, outputAllowed, inputAllowed, dataColumnsAllowed, outputsAllowed, studyOutputChoices, studyOutputsOf, studyOutputsRead, defaultStudyOutputs, studyChainTail, studyOfferable, SOURCE_COLUMNS, swapAllowed, } from './terminalMachine.js';
8
+ export { TerminalProvider, useRows, useSelectedSeries, useExpandedSeries, useControlsOpen, usePresetSaved, useActiveSlot, useAddSeries, useAddPair, useCompareAll, useAddStudy, useSetCompareFn, useSetCompareWith, 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, compareWithAllowed, 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 } from '@tidal-ts/chart';
15
+ import { type AxisRange, type SeriesAxis, type SeriesConfig, type CompareWith } 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
@@ -66,16 +66,30 @@ export interface MetricEntry {
66
66
  * this spec by `applyDerived`, not read from the feed. Absent ⇒ raw. */
67
67
  derive?: DeriveSpec;
68
68
  }
69
+ /**
70
+ * The two **preset sets**: `plain` (P1…) for a chart of one symbol, `compare`
71
+ * (C1…) for a chart with a comparison named. Both store the same shape; the
72
+ * host says which one is showing (`preset.useSet`), since only it knows whether
73
+ * a comparison is named.
74
+ */
75
+ export type PresetSet = 'plain' | 'compare';
76
+ export declare const PRESET_SETS: readonly PresetSet[];
77
+ /** A slot in one set: what the active-preset pointer persists. */
78
+ export interface PresetSlot {
79
+ set: PresetSet;
80
+ slot: number;
81
+ }
69
82
  /** Injectable persistence for the preset slots (default: the app's localStorage
70
83
  * keys). A host brings its own storage, or none. */
71
84
  export interface PresetStorage {
72
- loadPresets(): (TerminalPreset | null)[];
73
- savePresets(presets: (TerminalPreset | null)[]): void;
85
+ loadPresets(set: PresetSet): (TerminalPreset | null)[];
86
+ savePresets(set: PresetSet, presets: (TerminalPreset | null)[]): void;
74
87
  /** The persisted active-slot pointer — only used to seed `initialRows`. */
75
- loadActive(): number | null;
76
- saveActive(index: number | null): void;
88
+ loadActive(): PresetSlot | null;
89
+ saveActive(active: PresetSlot | null): void;
77
90
  }
78
- export declare const PRESET_SLOTS = 5;
91
+ /** Slots in each preset set. */
92
+ export declare const PRESET_SLOTS = 6;
79
93
  /** Max viewport rows (the control-panel spec: 1–3, capped at 3 for now). */
80
94
  export declare const MAX_ROWS = 3;
81
95
  export declare const mintId: (seq: number) => string;
@@ -109,7 +123,11 @@ interface TerminalContext {
109
123
  * on collapse or closing the panel, so emphasis falls back to `selected`. */
110
124
  expanded: string | null;
111
125
  controlsOpen: boolean;
112
- presets: (TerminalPreset | null)[];
126
+ /** Each set's slots, {@link PRESET_SLOTS} long. */
127
+ presets: Record<PresetSet, (TerminalPreset | null)[]>;
128
+ /** The set the host is showing — `compare` while a comparison is named. The
129
+ * slot events and the active slot read this one. */
130
+ presetSet: PresetSet;
113
131
  catalog: readonly MetricEntry[];
114
132
  storage: PresetStorage;
115
133
  }
@@ -218,7 +236,7 @@ export type TerminalEvent = {
218
236
  | {
219
237
  type: 'series.patch';
220
238
  id: string;
221
- patch: Partial<Omit<SeriesConfig, 'axis' | 'axisGroup' | 'parentIds' | 'compareFn'>>;
239
+ patch: Partial<Omit<SeriesConfig, 'axis' | 'axisGroup' | 'parentIds' | 'compareFn' | 'compareWith'>>;
222
240
  } | {
223
241
  type: 'series.toggleVisible';
224
242
  id: string;
@@ -233,6 +251,14 @@ export type TerminalEvent = {
233
251
  id: string;
234
252
  fn: PairOp | null;
235
253
  }
254
+ /** Wire a compare's other side by hand ({@link SeriesConfig.compareWith}),
255
+ * or `null` to make it automatic again. Refused for anything
256
+ * {@link compareWithAllowed} refuses. */
257
+ | {
258
+ type: 'series.setCompareWith';
259
+ id: string;
260
+ with: CompareWith | null;
261
+ }
236
262
  /** The PAIR's own eye — hides both legs at once. Each leg keeps its own
237
263
  * `visible`, so unhiding the pair restores what each leg was rather than
238
264
  * switching everything on (Peter, 2026-08-18). */
@@ -260,6 +286,12 @@ export type TerminalEvent = {
260
286
  } | {
261
287
  type: 'preset.save';
262
288
  slot: number;
289
+ }
290
+ /** Show the other preset set: the host sends `compare` when a comparison is
291
+ * named and `plain` when it is cleared. The rows are left alone. */
292
+ | {
293
+ type: 'preset.useSet';
294
+ set: PresetSet;
263
295
  } | {
264
296
  type: 'layout.setRowHeights';
265
297
  heights: Record<string, number>;
@@ -343,6 +375,9 @@ export interface TerminalInput {
343
375
  initialRows: RowState[];
344
376
  catalog: readonly MetricEntry[];
345
377
  storage: PresetStorage;
378
+ /** The preset set showing at start (the host's comparison, on a reload).
379
+ * Default `plain`. */
380
+ initialPresetSet?: PresetSet;
346
381
  /** The colour keys the host hands a new series, in order — see
347
382
  * `TerminalProviderProps.palette`. Default: none (a leg keeps its pair's). */
348
383
  palette?: readonly string[];
@@ -581,9 +616,17 @@ export declare function linkToggleAllowed(configs: readonly SeriesConfig[], id:
581
616
  * gutters.
582
617
  */
583
618
  export declare function swapAllowed(configs: readonly SeriesConfig[], id: string): boolean;
619
+ /**
620
+ * Whether `other` can be wired by hand as `target`'s compare other side
621
+ * ({@link SeriesConfig.compareWith}): the target must be able to carry a
622
+ * compare at all ({@link compareFnAllowed}), and the other side must be a
623
+ * different config with one line to read.
624
+ */
625
+ export declare function compareWithAllowed(target: SeriesConfig, other: SeriesConfig): boolean;
584
626
  /**
585
627
  * Whether a seated config can carry a compare function
586
- * ({@link SeriesConfig.compareFn}).
628
+ * ({@link SeriesConfig.compareFn}) or a hand-wired other side
629
+ * ({@link SeriesConfig.compareWith}).
587
630
  *
588
631
  * Only the ROOT of a chain — a metric, raw or a derived catalog metric, never
589
632
  * a study: the function sits straight after the metric and every study on it
@@ -656,7 +699,7 @@ export declare const terminalMachine: import("xstate").StateMachine<TerminalCont
656
699
  } | {
657
700
  type: "series.patch";
658
701
  id: string;
659
- patch: Partial<Omit<SeriesConfig, "axis" | "axisGroup" | "parentIds" | "compareFn">>;
702
+ patch: Partial<Omit<SeriesConfig, "axis" | "axisGroup" | "parentIds" | "compareFn" | "compareWith">>;
660
703
  } | {
661
704
  type: "series.toggleVisible";
662
705
  id: string;
@@ -664,6 +707,10 @@ export declare const terminalMachine: import("xstate").StateMachine<TerminalCont
664
707
  type: "series.setCompareFn";
665
708
  id: string;
666
709
  fn: PairOp | null;
710
+ } | {
711
+ type: "series.setCompareWith";
712
+ id: string;
713
+ with: CompareWith | null;
667
714
  } | {
668
715
  type: "group.toggleVisible";
669
716
  groupId: string;
@@ -686,6 +733,9 @@ export declare const terminalMachine: import("xstate").StateMachine<TerminalCont
686
733
  } | {
687
734
  type: "preset.save";
688
735
  slot: number;
736
+ } | {
737
+ type: "preset.useSet";
738
+ set: PresetSet;
689
739
  } | {
690
740
  type: "layout.setRowHeights";
691
741
  heights: Record<string, number>;
@@ -776,6 +826,9 @@ export declare const terminalMachine: import("xstate").StateMachine<TerminalCont
776
826
  } | {
777
827
  type: "setCompareFn";
778
828
  params: import("xstate").NonReducibleUnknown;
829
+ } | {
830
+ type: "setCompareWith";
831
+ params: import("xstate").NonReducibleUnknown;
779
832
  } | {
780
833
  type: "patchSeries";
781
834
  params: import("xstate").NonReducibleUnknown;
@@ -800,6 +853,9 @@ export declare const terminalMachine: import("xstate").StateMachine<TerminalCont
800
853
  } | {
801
854
  type: "savePreset";
802
855
  params: import("xstate").NonReducibleUnknown;
856
+ } | {
857
+ type: "usePresetSet";
858
+ params: import("xstate").NonReducibleUnknown;
803
859
  } | {
804
860
  type: "setRowHeights";
805
861
  params: import("xstate").NonReducibleUnknown;
@@ -857,6 +913,9 @@ export declare const terminalMachine: import("xstate").StateMachine<TerminalCont
857
913
  } | {
858
914
  type: "canSetCompareFn";
859
915
  params: unknown;
916
+ } | {
917
+ type: "canSetCompareWith";
918
+ params: unknown;
860
919
  } | {
861
920
  type: "canSetStudyParam";
862
921
  params: unknown;
@@ -34,7 +34,20 @@ function hidesPointer(context, toggledId, pointer) {
34
34
  import { axisRangeIsEmpty, logAllowed, isStudySeries, readsFrom, sourcesOf, fanIsBand, offersOutputBars, publishedColumns, } from '@tidal-ts/chart';
35
35
  import { configAxisId, seriesAxisId, sharedAxisId, } from '@tidal-ts/chart';
36
36
  import { axisForAdd, canAddUnit } from './axisPolicy.js';
37
- export const PRESET_SLOTS = 5;
37
+ export const PRESET_SETS = ['plain', 'compare'];
38
+ /** Slots in each preset set. */
39
+ export const PRESET_SLOTS = 6;
40
+ /** Whatever storage handed back, as exactly {@link PRESET_SLOTS} slots: a
41
+ * shorter list (an older build kept fewer) is padded with empty slots, a
42
+ * longer one is cut, and anything that isn't a list — or an entry that isn't
43
+ * a preset — reads as empty. */
44
+ function toSlots(raw) {
45
+ const list = Array.isArray(raw) ? raw : [];
46
+ return Array.from({ length: PRESET_SLOTS }, (_, i) => {
47
+ const p = list[i];
48
+ return p != null && typeof p === 'object' && Array.isArray(p.rows) ? p : null;
49
+ });
50
+ }
38
51
  /** Max viewport rows (the control-panel spec: 1–3, capped at 3 for now). */
39
52
  export const MAX_ROWS = 3;
40
53
  /**
@@ -1059,7 +1072,7 @@ export function dataColumnsAllowed(scope, id, columns) {
1059
1072
  function coherentPatch(c, patch) {
1060
1073
  // `compareFn` is set only through `series.setCompareFn` and its guard; a
1061
1074
  // patch that names it (an untyped caller) is not let around that guard.
1062
- const { compareFn: _ignored, ...asked } = patch;
1075
+ const { compareFn: _ignored, compareWith: _alsoIgnored, ...asked } = patch;
1063
1076
  return keepCompareFnCoherent(drawablePatch(c, asked));
1064
1077
  }
1065
1078
  function drawablePatch(c, patch) {
@@ -1082,11 +1095,41 @@ function drawablePatch(c, patch) {
1082
1095
  * review). Everything else passes through unchanged.
1083
1096
  */
1084
1097
  function keepCompareFnCoherent(c) {
1085
- if (!c.compareFn || compareFnAllowed(c))
1098
+ if ((!c.compareFn && !c.compareWith) || compareFnAllowed(c))
1086
1099
  return c;
1087
- const { compareFn: _drop, ...rest } = c;
1100
+ const { compareFn: _drop, compareWith: _dropWith, ...rest } = c;
1088
1101
  return rest;
1089
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);
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));
1090
1133
  /** Bar price columns in the bar's own order. */
1091
1134
  const barOrder = (columns) => [...columns].sort((a, b) => BAR_PRICE_COLUMNS.indexOf(a) - BAR_PRICE_COLUMNS.indexOf(b));
1092
1135
  /**
@@ -1788,9 +1831,36 @@ function comparableMetric(c) {
1788
1831
  return false; // a fan is several lines too
1789
1832
  return !c.column.startsWith(COMPARE_PREFIX);
1790
1833
  }
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.
1839
+ */
1840
+ export function compareWithAllowed(target, other) {
1841
+ if (!compareFnAllowed(target) || other.id === target.id)
1842
+ return false;
1843
+ // The other side is ONE line, read from its own spec: the same refusals as
1844
+ // a function's metric, except that a study is a fine other side (price
1845
+ // against its own SMA).
1846
+ if (other.group || other.column.startsWith(COMPARE_PREFIX))
1847
+ return false;
1848
+ if (other.style === 'band' || other.style === 'lines')
1849
+ return false;
1850
+ if (other.fan && other.fan.length > 0)
1851
+ return false;
1852
+ if (other.derive) {
1853
+ if (hasPairOp(other.derive) || usesCompare(other.derive))
1854
+ return false;
1855
+ if (opIsMulti(other.derive.op) || opIsBand(other.derive.op))
1856
+ return false;
1857
+ }
1858
+ return true;
1859
+ }
1791
1860
  /**
1792
1861
  * Whether a seated config can carry a compare function
1793
- * ({@link SeriesConfig.compareFn}).
1862
+ * ({@link SeriesConfig.compareFn}) or a hand-wired other side
1863
+ * ({@link SeriesConfig.compareWith}).
1794
1864
  *
1795
1865
  * Only the ROOT of a chain — a metric, raw or a derived catalog metric, never
1796
1866
  * a study: the function sits straight after the metric and every study on it
@@ -1821,6 +1891,9 @@ export function compareFnAllowed(c) {
1821
1891
  return true;
1822
1892
  }
1823
1893
  export function canonRows(rows) {
1894
+ // A hand-wired compare names its other side by config id, which is minted;
1895
+ // it hashes by what that config draws (its column) and the side instead.
1896
+ const columnOf = new Map(rows.flatMap((r) => r.configs.map((c) => [c.id, c.column])));
1824
1897
  return JSON.stringify(rows.map((r) => {
1825
1898
  // Axis membership is preset identity — but `axisGroup` is a MINTED config
1826
1899
  // id, and hashing it would make a hand-rebuilt copy of a saved preset read
@@ -1882,6 +1955,14 @@ export function canonRows(rows) {
1882
1955
  // Appended only when set, so a config without one hashes exactly as
1883
1956
  // it did before the field existed and a saved preset still matches.
1884
1957
  ...(c.compareFn ? [c.compareFn] : []),
1958
+ // …and what it reads as its other side, when that is wired by hand.
1959
+ // Appended the same way, after a placeholder for an absent function.
1960
+ ...(c.compareWith
1961
+ ? [
1962
+ ...(c.compareFn ? [] : [null]),
1963
+ [columnOf.get(c.compareWith.id) ?? null, c.compareWith.side],
1964
+ ]
1965
+ : []),
1885
1966
  ]),
1886
1967
  ];
1887
1968
  }));
@@ -2069,6 +2150,20 @@ export const terminalMachine = setup({
2069
2150
  // can no longer carry one must still be removable.
2070
2151
  return event.fn === null || (isPairOp(event.fn) && compareFnAllowed(target));
2071
2152
  },
2153
+ canSetCompareWith: ({ context, event }) => {
2154
+ if (event.type !== 'series.setCompareWith')
2155
+ return false;
2156
+ const all = flatConfigs(context.rows);
2157
+ const target = all.find((c) => c.id === event.id);
2158
+ if (!target)
2159
+ return false;
2160
+ if (event.with === null)
2161
+ return true;
2162
+ if (event.with.side !== 'primary' && event.with.side !== 'comparison')
2163
+ return false;
2164
+ const other = all.find((c) => c.id === event.with.id);
2165
+ return !!other && compareWithAllowed(target, other);
2166
+ },
2072
2167
  canSetStudyParam: ({ context, event }) => event.type === 'series.setStudyParam' &&
2073
2168
  respecAllowed(context, event.id, event.name, event.value),
2074
2169
  // The chain toggle — delegated to the shared pure helper so the panel's
@@ -2178,7 +2273,7 @@ export const terminalMachine = setup({
2178
2273
  },
2179
2274
  }),
2180
2275
  addPair: assign({
2181
- rows: ({ context, event }) => {
2276
+ rows: keepingCompareWithValid(({ context, event }) => {
2182
2277
  if (event.type !== 'series.addPair')
2183
2278
  return context.rows;
2184
2279
  const a = resolveLeg(context, event.a.metricId);
@@ -2233,7 +2328,7 @@ export const terminalMachine = setup({
2233
2328
  });
2234
2329
  }
2235
2330
  return context.rows.map((r) => r.id === row.id ? { ...r, configs: [cfg, ...r.configs] } : r);
2236
- },
2331
+ }),
2237
2332
  // Expand the new node so its controls open for tuning — the spread, or
2238
2333
  // (unjoined) whichever leg took the group's first minted id. Nothing to
2239
2334
  // expand when BOTH legs were adopted: no config was created.
@@ -2262,17 +2357,17 @@ export const terminalMachine = setup({
2262
2357
  // expansion, ink, axis membership and range pins all survive (they used to
2263
2358
  // be destroyed, and the dependents deleted outright).
2264
2359
  setStudyOutput: assign({
2265
- rows: ({ context, event }) => {
2360
+ rows: keepingCompareWithValid(({ context, event }) => {
2266
2361
  if (event.type !== 'series.setStudyOutput')
2267
2362
  return context.rows;
2268
2363
  const target = flatConfigs(context.rows).find((c) => c.id === event.id);
2269
2364
  if (!target?.derive)
2270
2365
  return context.rows;
2271
2366
  return applyRespec(context, event.id, respecOutput(target, event.output));
2272
- },
2367
+ }),
2273
2368
  }),
2274
2369
  setStudyInput: assign({
2275
- rows: ({ context, event }) => {
2370
+ rows: keepingCompareWithValid(({ context, event }) => {
2276
2371
  if (event.type !== 'series.setStudyInput')
2277
2372
  return context.rows;
2278
2373
  const configs = flatConfigs(context.rows);
@@ -2304,10 +2399,10 @@ export const terminalMachine = setup({
2304
2399
  return { ...c, parentIds };
2305
2400
  }),
2306
2401
  }));
2307
- },
2402
+ }),
2308
2403
  }),
2309
2404
  setDataColumns: assign({
2310
- rows: ({ context, event }) => {
2405
+ rows: keepingCompareWithValid(({ context, event }) => {
2311
2406
  if (event.type !== 'series.setDataColumns')
2312
2407
  return context.rows;
2313
2408
  const configs = flatConfigs(context.rows);
@@ -2343,10 +2438,10 @@ export const terminalMachine = setup({
2343
2438
  return { ...c, parentIds };
2344
2439
  }),
2345
2440
  }));
2346
- },
2441
+ }),
2347
2442
  }),
2348
2443
  setStudyOutputs: assign({
2349
- rows: ({ context, event }) => {
2444
+ rows: keepingCompareWithValid(({ context, event }) => {
2350
2445
  if (event.type !== 'series.setStudyOutputs')
2351
2446
  return context.rows;
2352
2447
  const study = flatConfigs(context.rows).find((c) => c.id === event.id);
@@ -2364,17 +2459,17 @@ export const terminalMachine = setup({
2364
2459
  ...r,
2365
2460
  configs: r.configs.map((c) => c.id === event.id ? { ...c, fan: next.fan, style: next.style } : c),
2366
2461
  }));
2367
- },
2462
+ }),
2368
2463
  }),
2369
2464
  setStudyParam: assign({
2370
- rows: ({ context, event }) => {
2465
+ rows: keepingCompareWithValid(({ context, event }) => {
2371
2466
  if (event.type !== 'series.setStudyParam')
2372
2467
  return context.rows;
2373
2468
  const target = flatConfigs(context.rows).find((c) => c.id === event.id);
2374
2469
  if (!target?.derive)
2375
2470
  return context.rows;
2376
2471
  return applyRespec(context, event.id, respecParam(target, event.name, event.value));
2377
- },
2472
+ }),
2378
2473
  }),
2379
2474
  addSeries: assign({
2380
2475
  rows: ({ context, event }) => {
@@ -2421,7 +2516,7 @@ export const terminalMachine = setup({
2421
2516
  },
2422
2517
  }),
2423
2518
  removeGroup: assign({
2424
- rows: ({ context, event }) => {
2519
+ rows: keepingCompareWithValid(({ context, event }) => {
2425
2520
  if (event.type !== 'group.remove')
2426
2521
  return context.rows;
2427
2522
  const doomed = groupDoomed(context.rows, event.groupId);
@@ -2430,7 +2525,7 @@ export const terminalMachine = setup({
2430
2525
  configs: r.configs.filter((c) => !doomed.has(c.id)),
2431
2526
  }));
2432
2527
  return pruneEmptied(context.rows, mapped);
2433
- },
2528
+ }),
2434
2529
  // The same invariant `removeSeries` states: neither pointer may point at a
2435
2530
  // removed series. Sibling assigners read the PRE-update context, so both
2436
2531
  // recompute the doomed set rather than reading the new rows (PR #149
@@ -2496,7 +2591,7 @@ export const terminalMachine = setup({
2496
2591
  },
2497
2592
  }),
2498
2593
  removeSeries: assign({
2499
- rows: ({ context, event }) => {
2594
+ rows: keepingCompareWithValid(({ context, event }) => {
2500
2595
  if (event.type !== 'series.remove')
2501
2596
  return context.rows;
2502
2597
  // Cascade to dependent studies so a nested study can't strand invisible +
@@ -2517,7 +2612,7 @@ export const terminalMachine = setup({
2517
2612
  // Not only the host row: an oscillator on its own row is in the
2518
2613
  // cascade, and its row must not stay behind as an empty pane.
2519
2614
  return pruneEmptied(context.rows, mapped);
2520
- },
2615
+ }),
2521
2616
  // Neither pointer may point at a removed series (or a cascaded dependent).
2522
2617
  selected: ({ context, event }) => event.type === 'series.remove' &&
2523
2618
  context.selected != null &&
@@ -2534,7 +2629,7 @@ export const terminalMachine = setup({
2534
2629
  // (a drag's absolute drop). Both splice-move within the series' own row; the
2535
2630
  // list is front→back, so index 0 is topmost on the canvas.
2536
2631
  orderSeries: assign({
2537
- rows: ({ context, event }) => {
2632
+ rows: keepingCompareWithValid(({ context, event }) => {
2538
2633
  if (event.type !== 'series.order' && event.type !== 'series.reindex')
2539
2634
  return context.rows;
2540
2635
  return context.rows.map((r) => {
@@ -2553,14 +2648,14 @@ export const terminalMachine = setup({
2553
2648
  : Math.max(0, Math.min(event.index, blocks.length - 1));
2554
2649
  return to === i ? r : { ...r, configs: reindex(blocks, i, to).flat() };
2555
2650
  });
2556
- },
2651
+ }),
2557
2652
  }),
2558
2653
  // Cross-row move: the series leaves its row (pruned if that empties it, as
2559
2654
  // with remove) and lands at the FRONT of the target row, on an axis its unit
2560
2655
  // can take there (the guard already proved one exists). Studies layered on it
2561
2656
  // travel with it, so a study can't strand on a row without its source.
2562
2657
  moveSeriesToRow: assign({
2563
- rows: ({ context, event }) => {
2658
+ rows: keepingCompareWithValid(({ context, event }) => {
2564
2659
  if (event.type !== 'series.moveToRow')
2565
2660
  return context.rows;
2566
2661
  const from = context.rows.find((r) => r.configs.some((c) => c.id === event.id));
@@ -2584,7 +2679,7 @@ export const terminalMachine = setup({
2584
2679
  });
2585
2680
  // An emptied source row goes away; the remainder row is kept.
2586
2681
  return pruneEmptied(context.rows, mapped);
2587
- },
2682
+ }),
2588
2683
  }),
2589
2684
  setCompareFn: assign({
2590
2685
  rows: ({ context, event }) => {
@@ -2605,8 +2700,28 @@ export const terminalMachine = setup({
2605
2700
  : r);
2606
2701
  },
2607
2702
  }),
2608
- patchSeries: assign({
2703
+ setCompareWith: assign({
2609
2704
  rows: ({ context, event }) => {
2705
+ if (event.type !== 'series.setCompareWith')
2706
+ return context.rows;
2707
+ return context.rows.map((r) => r.configs.some((c) => c.id === event.id)
2708
+ ? {
2709
+ ...r,
2710
+ configs: r.configs.map((c) => {
2711
+ if (c.id !== event.id)
2712
+ return c;
2713
+ // Automatic again by REMOVING the key, as for the function.
2714
+ const { compareWith: _drop, ...rest } = c;
2715
+ return event.with
2716
+ ? { ...rest, compareWith: { id: event.with.id, side: event.with.side } }
2717
+ : rest;
2718
+ }),
2719
+ }
2720
+ : r);
2721
+ },
2722
+ }),
2723
+ patchSeries: assign({
2724
+ rows: keepingCompareWithValid(({ context, event }) => {
2610
2725
  if (event.type !== 'series.patch')
2611
2726
  return context.rows;
2612
2727
  // A study's colour is its parent's until the user says otherwise
@@ -2651,7 +2766,7 @@ export const terminalMachine = setup({
2651
2766
  ? { ...c, color: color }
2652
2767
  : c),
2653
2768
  }));
2654
- },
2769
+ }),
2655
2770
  }),
2656
2771
  toggleVisible: assign({
2657
2772
  rows: ({ context, event }) => {
@@ -2717,7 +2832,7 @@ export const terminalMachine = setup({
2717
2832
  rows: ({ context, event }) => {
2718
2833
  if (event.type !== 'preset.select')
2719
2834
  return context.rows;
2720
- const p = context.presets[event.slot];
2835
+ const p = context.presets[context.presetSet][event.slot];
2721
2836
  // A preset saved before the invariant existed can carry a stack with no
2722
2837
  // remainder row, which would reproduce the stuck-seam bug on apply.
2723
2838
  return p ? withRemainder(cloneRows(p.rows)) : context.rows;
@@ -2732,11 +2847,11 @@ export const terminalMachine = setup({
2732
2847
  // duplicate row ids collide in `setRowHeights`, in `configAxisId`, and in
2733
2848
  // every find-by-rowId.
2734
2849
  cfgSeq: ({ context, event }) => {
2735
- const p = event.type === 'preset.select' ? context.presets[event.slot] : null;
2850
+ const p = event.type === 'preset.select' ? context.presets[context.presetSet][event.slot] : null;
2736
2851
  return p ? Math.max(context.cfgSeq, cfgSeqAfter(p.rows)) : context.cfgSeq;
2737
2852
  },
2738
2853
  rowSeq: ({ context, event }) => {
2739
- const p = event.type === 'preset.select' ? context.presets[event.slot] : null;
2854
+ const p = event.type === 'preset.select' ? context.presets[context.presetSet][event.slot] : null;
2740
2855
  return p ? Math.max(context.rowSeq, rowSeqAfter(p.rows)) : context.rowSeq;
2741
2856
  },
2742
2857
  // Presets are COMPOSITION; per-axis ranges are ARRANGEMENT and aren't
@@ -2744,18 +2859,26 @@ export const terminalMachine = setup({
2744
2859
  // leak: a manual range pinned under different rows reads as a broken
2745
2860
  // chart with no visible cause. Membership (`axisGroup`) DOES restore — it
2746
2861
  // lives on the configs.
2747
- axisRanges: ({ context, event }) => event.type === 'preset.select' && context.presets[event.slot] ? {} : context.axisRanges,
2862
+ axisRanges: ({ context, event }) => event.type === 'preset.select' && context.presets[context.presetSet][event.slot]
2863
+ ? {}
2864
+ : context.axisRanges,
2748
2865
  }),
2749
2866
  savePreset: assign({
2750
2867
  presets: ({ context, event }) => {
2751
2868
  if (event.type !== 'preset.save')
2752
2869
  return context.presets;
2753
- const next = context.presets.slice();
2870
+ const set = context.presetSet;
2871
+ const next = context.presets[set].slice();
2754
2872
  next[event.slot] = { rows: cloneRows(context.rows) };
2755
- context.storage.savePresets(next);
2756
- return next;
2873
+ context.storage.savePresets(set, next);
2874
+ return { ...context.presets, [set]: next };
2757
2875
  },
2758
2876
  }),
2877
+ usePresetSet: assign({
2878
+ presetSet: ({ context, event }) => event.type === 'preset.useSet' && PRESET_SETS.includes(event.set)
2879
+ ? event.set
2880
+ : context.presetSet,
2881
+ }),
2759
2882
  setRowHeights: assign({
2760
2883
  rows: ({ context, event }) => event.type === 'layout.setRowHeights'
2761
2884
  ? // `withRemainder` because a commit is a full height map: a drag that
@@ -2984,7 +3107,7 @@ export const terminalMachine = setup({
2984
3107
  removeRow: assign({
2985
3108
  // Removing a row is removing each of its series (`rowDoomed`), so a
2986
3109
  // study of one of its STUDIES goes too, on whatever row it sits.
2987
- rows: ({ context, event }) => {
3110
+ rows: keepingCompareWithValid(({ context, event }) => {
2988
3111
  if (event.type !== 'row.remove' || context.rows.length <= 1)
2989
3112
  return context.rows;
2990
3113
  const doomed = rowDoomed(context.rows, event.id);
@@ -2994,7 +3117,7 @@ export const terminalMachine = setup({
2994
3117
  // Removing the remainder row would leave the stack with none, so the
2995
3118
  // first survivor takes over as the one that absorbs slack.
2996
3119
  return pruneEmptied(context.rows, after);
2997
- },
3120
+ }),
2998
3121
  // Removing a row drops its series for good, so a pointer into it can't return
2999
3122
  // (unlike a ticker switch) — clear both (mirrors removeSeries).
3000
3123
  selected: ({ context, event }) => {
@@ -3032,7 +3155,11 @@ export const terminalMachine = setup({
3032
3155
  selected: null,
3033
3156
  expanded: null,
3034
3157
  controlsOpen: false,
3035
- presets: input.storage.loadPresets(),
3158
+ presets: {
3159
+ plain: toSlots(input.storage.loadPresets('plain')),
3160
+ compare: toSlots(input.storage.loadPresets('compare')),
3161
+ },
3162
+ presetSet: input.initialPresetSet ?? 'plain',
3036
3163
  catalog: input.catalog,
3037
3164
  storage: input.storage,
3038
3165
  }),
@@ -3070,6 +3197,7 @@ export const terminalMachine = setup({
3070
3197
  'series.remove': { actions: 'removeSeries' },
3071
3198
  'series.patch': { actions: 'patchSeries' },
3072
3199
  'series.setCompareFn': { guard: 'canSetCompareFn', actions: 'setCompareFn' },
3200
+ 'series.setCompareWith': { guard: 'canSetCompareWith', actions: 'setCompareWith' },
3073
3201
  'series.toggleVisible': { actions: 'toggleVisible' },
3074
3202
  'group.toggleVisible': { actions: 'toggleGroupVisible' },
3075
3203
  'group.remove': { actions: 'removeGroup' },
@@ -3079,6 +3207,7 @@ export const terminalMachine = setup({
3079
3207
  'controls.close': { actions: 'closeControls' },
3080
3208
  'preset.select': { actions: 'applyPreset' },
3081
3209
  'preset.save': { actions: 'savePreset' },
3210
+ 'preset.useSet': { actions: 'usePresetSet' },
3082
3211
  'layout.setRowHeights': { actions: 'setRowHeights' },
3083
3212
  'row.add': { guard: 'canAddRow', actions: 'addRow' },
3084
3213
  'row.remove': { actions: 'removeRow' },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tidal-ts/terminal",
3
- "version": "0.22.0",
3
+ "version": "0.24.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.22.0",
40
- "@tidal-ts/core": "0.22.0"
39
+ "@tidal-ts/chart": "0.24.0",
40
+ "@tidal-ts/core": "0.24.0"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@pond-ts/charts": "^0.78.0",