@tidal-ts/terminal 0.22.0 → 0.23.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 +14 -5
- package/dist/context.js +36 -9
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/terminalMachine.d.ts +39 -6
- package/dist/terminalMachine.js +35 -9
- package/package.json +3 -3
package/dist/context.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { type ReactNode } from 'react';
|
|
|
2
2
|
import type { InspectionEvent, Observer } from 'xstate';
|
|
3
3
|
import type { DeriveOp, PairOp } from '@tidal-ts/core';
|
|
4
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';
|
|
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
|
-
/**
|
|
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
|
|
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
|
|
@@ -85,6 +92,8 @@ export declare function useExpandSeries(): (id: string | null) => void;
|
|
|
85
92
|
export declare function useSetControlsOpen(): (open: boolean) => void;
|
|
86
93
|
export declare function useSelectPreset(): (slot: number) => void;
|
|
87
94
|
export declare function useSavePreset(): (slot: number) => void;
|
|
95
|
+
/** Show a preset set: `compare` while a comparison is named, else `plain`. */
|
|
96
|
+
export declare function useSetPresetSet(): (set: PresetSet) => void;
|
|
88
97
|
export declare function useSetRowHeights(): (heights: Record<string, number>) => void;
|
|
89
98
|
/** Toggle a series' axis membership — the panel's chain icon (unlink to its own
|
|
90
99
|
* 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
|
-
|
|
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
|
-
/**
|
|
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
|
|
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
|
|
@@ -180,6 +202,11 @@ export function useSavePreset() {
|
|
|
180
202
|
const ref = TerminalContext.useActorRef();
|
|
181
203
|
return useCallback((slot) => ref.send({ type: 'preset.save', slot }), [ref]);
|
|
182
204
|
}
|
|
205
|
+
/** Show a preset set: `compare` while a comparison is named, else `plain`. */
|
|
206
|
+
export function useSetPresetSet() {
|
|
207
|
+
const ref = TerminalContext.useActorRef();
|
|
208
|
+
return useCallback((set) => ref.send({ type: 'preset.useSet', set }), [ref]);
|
|
209
|
+
}
|
|
183
210
|
export function useSetRowHeights() {
|
|
184
211
|
const ref = TerminalContext.useActorRef();
|
|
185
212
|
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, 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, 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, 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, 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).
|
|
@@ -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():
|
|
76
|
-
saveActive(
|
|
88
|
+
loadActive(): PresetSlot | null;
|
|
89
|
+
saveActive(active: PresetSlot | null): void;
|
|
77
90
|
}
|
|
78
|
-
|
|
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
|
-
|
|
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
|
}
|
|
@@ -260,6 +278,12 @@ export type TerminalEvent = {
|
|
|
260
278
|
} | {
|
|
261
279
|
type: 'preset.save';
|
|
262
280
|
slot: number;
|
|
281
|
+
}
|
|
282
|
+
/** Show the other preset set: the host sends `compare` when a comparison is
|
|
283
|
+
* named and `plain` when it is cleared. The rows are left alone. */
|
|
284
|
+
| {
|
|
285
|
+
type: 'preset.useSet';
|
|
286
|
+
set: PresetSet;
|
|
263
287
|
} | {
|
|
264
288
|
type: 'layout.setRowHeights';
|
|
265
289
|
heights: Record<string, number>;
|
|
@@ -343,6 +367,9 @@ export interface TerminalInput {
|
|
|
343
367
|
initialRows: RowState[];
|
|
344
368
|
catalog: readonly MetricEntry[];
|
|
345
369
|
storage: PresetStorage;
|
|
370
|
+
/** The preset set showing at start (the host's comparison, on a reload).
|
|
371
|
+
* Default `plain`. */
|
|
372
|
+
initialPresetSet?: PresetSet;
|
|
346
373
|
/** The colour keys the host hands a new series, in order — see
|
|
347
374
|
* `TerminalProviderProps.palette`. Default: none (a leg keeps its pair's). */
|
|
348
375
|
palette?: readonly string[];
|
|
@@ -686,6 +713,9 @@ export declare const terminalMachine: import("xstate").StateMachine<TerminalCont
|
|
|
686
713
|
} | {
|
|
687
714
|
type: "preset.save";
|
|
688
715
|
slot: number;
|
|
716
|
+
} | {
|
|
717
|
+
type: "preset.useSet";
|
|
718
|
+
set: PresetSet;
|
|
689
719
|
} | {
|
|
690
720
|
type: "layout.setRowHeights";
|
|
691
721
|
heights: Record<string, number>;
|
|
@@ -800,6 +830,9 @@ export declare const terminalMachine: import("xstate").StateMachine<TerminalCont
|
|
|
800
830
|
} | {
|
|
801
831
|
type: "savePreset";
|
|
802
832
|
params: import("xstate").NonReducibleUnknown;
|
|
833
|
+
} | {
|
|
834
|
+
type: "usePresetSet";
|
|
835
|
+
params: import("xstate").NonReducibleUnknown;
|
|
803
836
|
} | {
|
|
804
837
|
type: "setRowHeights";
|
|
805
838
|
params: import("xstate").NonReducibleUnknown;
|
package/dist/terminalMachine.js
CHANGED
|
@@ -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
|
|
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
|
/**
|
|
@@ -2717,7 +2730,7 @@ export const terminalMachine = setup({
|
|
|
2717
2730
|
rows: ({ context, event }) => {
|
|
2718
2731
|
if (event.type !== 'preset.select')
|
|
2719
2732
|
return context.rows;
|
|
2720
|
-
const p = context.presets[event.slot];
|
|
2733
|
+
const p = context.presets[context.presetSet][event.slot];
|
|
2721
2734
|
// A preset saved before the invariant existed can carry a stack with no
|
|
2722
2735
|
// remainder row, which would reproduce the stuck-seam bug on apply.
|
|
2723
2736
|
return p ? withRemainder(cloneRows(p.rows)) : context.rows;
|
|
@@ -2732,11 +2745,11 @@ export const terminalMachine = setup({
|
|
|
2732
2745
|
// duplicate row ids collide in `setRowHeights`, in `configAxisId`, and in
|
|
2733
2746
|
// every find-by-rowId.
|
|
2734
2747
|
cfgSeq: ({ context, event }) => {
|
|
2735
|
-
const p = event.type === 'preset.select' ? context.presets[event.slot] : null;
|
|
2748
|
+
const p = event.type === 'preset.select' ? context.presets[context.presetSet][event.slot] : null;
|
|
2736
2749
|
return p ? Math.max(context.cfgSeq, cfgSeqAfter(p.rows)) : context.cfgSeq;
|
|
2737
2750
|
},
|
|
2738
2751
|
rowSeq: ({ context, event }) => {
|
|
2739
|
-
const p = event.type === 'preset.select' ? context.presets[event.slot] : null;
|
|
2752
|
+
const p = event.type === 'preset.select' ? context.presets[context.presetSet][event.slot] : null;
|
|
2740
2753
|
return p ? Math.max(context.rowSeq, rowSeqAfter(p.rows)) : context.rowSeq;
|
|
2741
2754
|
},
|
|
2742
2755
|
// Presets are COMPOSITION; per-axis ranges are ARRANGEMENT and aren't
|
|
@@ -2744,18 +2757,26 @@ export const terminalMachine = setup({
|
|
|
2744
2757
|
// leak: a manual range pinned under different rows reads as a broken
|
|
2745
2758
|
// chart with no visible cause. Membership (`axisGroup`) DOES restore — it
|
|
2746
2759
|
// lives on the configs.
|
|
2747
|
-
axisRanges: ({ context, event }) => event.type === 'preset.select' && context.presets[event.slot]
|
|
2760
|
+
axisRanges: ({ context, event }) => event.type === 'preset.select' && context.presets[context.presetSet][event.slot]
|
|
2761
|
+
? {}
|
|
2762
|
+
: context.axisRanges,
|
|
2748
2763
|
}),
|
|
2749
2764
|
savePreset: assign({
|
|
2750
2765
|
presets: ({ context, event }) => {
|
|
2751
2766
|
if (event.type !== 'preset.save')
|
|
2752
2767
|
return context.presets;
|
|
2753
|
-
const
|
|
2768
|
+
const set = context.presetSet;
|
|
2769
|
+
const next = context.presets[set].slice();
|
|
2754
2770
|
next[event.slot] = { rows: cloneRows(context.rows) };
|
|
2755
|
-
context.storage.savePresets(next);
|
|
2756
|
-
return next;
|
|
2771
|
+
context.storage.savePresets(set, next);
|
|
2772
|
+
return { ...context.presets, [set]: next };
|
|
2757
2773
|
},
|
|
2758
2774
|
}),
|
|
2775
|
+
usePresetSet: assign({
|
|
2776
|
+
presetSet: ({ context, event }) => event.type === 'preset.useSet' && PRESET_SETS.includes(event.set)
|
|
2777
|
+
? event.set
|
|
2778
|
+
: context.presetSet,
|
|
2779
|
+
}),
|
|
2759
2780
|
setRowHeights: assign({
|
|
2760
2781
|
rows: ({ context, event }) => event.type === 'layout.setRowHeights'
|
|
2761
2782
|
? // `withRemainder` because a commit is a full height map: a drag that
|
|
@@ -3032,7 +3053,11 @@ export const terminalMachine = setup({
|
|
|
3032
3053
|
selected: null,
|
|
3033
3054
|
expanded: null,
|
|
3034
3055
|
controlsOpen: false,
|
|
3035
|
-
presets:
|
|
3056
|
+
presets: {
|
|
3057
|
+
plain: toSlots(input.storage.loadPresets('plain')),
|
|
3058
|
+
compare: toSlots(input.storage.loadPresets('compare')),
|
|
3059
|
+
},
|
|
3060
|
+
presetSet: input.initialPresetSet ?? 'plain',
|
|
3036
3061
|
catalog: input.catalog,
|
|
3037
3062
|
storage: input.storage,
|
|
3038
3063
|
}),
|
|
@@ -3079,6 +3104,7 @@ export const terminalMachine = setup({
|
|
|
3079
3104
|
'controls.close': { actions: 'closeControls' },
|
|
3080
3105
|
'preset.select': { actions: 'applyPreset' },
|
|
3081
3106
|
'preset.save': { actions: 'savePreset' },
|
|
3107
|
+
'preset.useSet': { actions: 'usePresetSet' },
|
|
3082
3108
|
'layout.setRowHeights': { actions: 'setRowHeights' },
|
|
3083
3109
|
'row.add': { guard: 'canAddRow', actions: 'addRow' },
|
|
3084
3110
|
'row.remove': { actions: 'removeRow' },
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tidal-ts/terminal",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.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.23.0",
|
|
40
|
+
"@tidal-ts/core": "0.23.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@pond-ts/charts": "^0.78.0",
|