@tidal-ts/terminal 0.28.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 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, CompareWith, PairLensOp, SeriesConfig } from '@tidal-ts/chart';
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 stored. */
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
- /** Wire a compare's other side by hand, or `null` for automatic. */
60
- export declare function useSetCompareWith(): (id: string, other: CompareWith | null) => void;
61
- /** Lock a compare's other side to a symbol, or `null` for the comparison. */
62
- export declare function useSetCompareOn(): (id: string, symbol: string | null) => void;
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 stored. */
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
- /** 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]);
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 compare's other side to a symbol, or `null` for the comparison. */
118
- export function useSetCompareOn() {
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((id, symbol) => ref.send({ type: 'series.setCompareOn', id, symbol }), [ref]);
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, useSetCompareWith, useSetCompareOn, 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';
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, useSetCompareWith, useSetCompareOn, 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';
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, type CompareWith } from '@tidal-ts/chart';
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' | 'compareWith' | 'compareOn'>>;
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
- /** 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. */
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: 'series.setCompareWith';
259
- id: string;
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}) or a hand-wired other side
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" | "compareWith" | "compareOn">>;
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: "series.setCompareWith";
722
- id: string;
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: "setCompareWith";
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: "canSetCompareWith";
935
- params: unknown;
936
- } | {
937
- type: "canSetCompareOn";
931
+ type: "canSetSourceLock";
938
932
  params: unknown;
939
933
  } | {
940
934
  type: "canSetStudyParam";
@@ -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, compareWithInput, } from '@tidal-ts/chart';
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, compareWith: _alsoIgnored, compareOn: _locked, ...asked } = patch;
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.compareWith && !c.compareOn) || compareFnAllowed(c))
1098
+ if ((!c.compareFn && !c.compareOn) || compareFnAllowed(c))
1099
1099
  return c;
1100
- const { compareFn: _drop, compareWith: _dropWith, compareOn: _dropOn, ...rest } = c;
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}) or a hand-wired other side
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
@@ -1943,43 +1891,67 @@ export function canonRows(rows) {
1943
1891
  .map((k) => [k, c.outputStyles[k]])
1944
1892
  : null,
1945
1893
  c.fan ?? null,
1946
- // How the metric reads under a comparison: one joined line or two.
1947
- // Appended only when set, so a config without one hashes exactly as
1948
- // it did before the field existed and a saved preset still matches.
1949
- ...(c.compareFn ? [c.compareFn] : []),
1950
- // …and what it reads as its other side, when that is wired by hand.
1951
- // Appended the same way, after a placeholder for an absent function.
1952
- ...(c.compareWith
1953
- ? [
1954
- ...(c.compareFn ? [] : [null]),
1955
- [
1956
- columnOf.get(c.compareWith.id) ?? null,
1957
- c.compareWith.side,
1958
- ...(c.compareWith.output ? [c.compareWith.output] : []),
1959
- ],
1960
- ]
1961
- : []),
1962
- // …and the symbol it is locked to: the one symbol a preset carries.
1963
- // After placeholders for whatever is absent before it.
1964
- ...(c.compareOn
1965
- ? [
1966
- ...(c.compareFn || c.compareWith ? [] : [null]),
1967
- ...(c.compareWith ? [] : [null]),
1968
- c.compareOn,
1969
- ]
1970
- : []),
1894
+ // How the metric reads under a comparison, appended only when any of
1895
+ // it is set, so a config without it hashes exactly as it did before
1896
+ // these fields existed and a saved preset still matches: one joined
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)]),
1971
1901
  ]),
1972
1902
  ];
1973
1903
  }));
1974
1904
  }
1905
+ /** A style's set fields as key-sorted pairs, or `null` when none is set: a
1906
+ * field cleared to `undefined` hashes as absent, as it reads after a JSON
1907
+ * round-trip (PR #53 review). */
1908
+ const styleEntries = (st) => {
1909
+ const set = Object.entries(st ?? {})
1910
+ .filter(([, v]) => v !== undefined)
1911
+ .sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0));
1912
+ return set.length > 0 ? set : null;
1913
+ };
1914
+ /** `xs` without its trailing `null`s. */
1915
+ const trimNulls = (xs) => {
1916
+ let n = xs.length;
1917
+ while (n > 0 && xs[n - 1] === null)
1918
+ n--;
1919
+ return xs.slice(0, n);
1920
+ };
1975
1921
  /** The active slot: first saved preset whose rows deep-equal the live rows, else
1976
1922
  * null (custom). The single derivation behind the filled circle + the seed. */
1977
- export function activeSlot(presets, rows) {
1978
- const live = canonRows(rows);
1979
- 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);
1980
1926
  return i === -1 ? null : i;
1981
1927
  }
1982
- const cloneRows = (rows) => rows.map((r) => ({ ...r, configs: r.configs.map((c) => ({ ...c, value: null })) }));
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
+ }
1983
1955
  // --- the machine -------------------------------------------------------------
1984
1956
  export const terminalMachine = setup({
1985
1957
  types: {
@@ -2155,35 +2127,13 @@ export const terminalMachine = setup({
2155
2127
  // can no longer carry one must still be removable.
2156
2128
  return event.fn === null || (isPairOp(event.fn) && compareFnAllowed(target));
2157
2129
  },
2158
- canSetCompareWith: ({ context, event }) => {
2159
- if (event.type !== 'series.setCompareWith')
2160
- return false;
2161
- const all = flatConfigs(context.rows);
2162
- const target = all.find((c) => c.id === event.id);
2163
- if (!target)
2164
- return false;
2165
- if (event.with === null)
2166
- return true;
2167
- if (event.with.side !== 'primary' && event.with.side !== 'comparison')
2168
- return false;
2169
- const output = event.with.output;
2170
- // A name, or none: an empty name would be stored as none.
2171
- if (output !== undefined && (typeof output !== 'string' || output === ''))
2172
- return false;
2173
- const other = all.find((c) => c.id === event.with.id);
2174
- return !!other && compareWithAllowed(target, other, output);
2175
- },
2176
- canSetCompareOn: ({ context, event }) => {
2177
- if (event.type !== 'series.setCompareOn')
2130
+ canSetSourceLock: ({ event }) => {
2131
+ if (event.type !== 'source.setLock')
2178
2132
  return false;
2179
- const target = flatConfigs(context.rows).find((c) => c.id === event.id);
2180
- if (!target)
2133
+ if (typeof event.source !== 'string' || event.source === '')
2181
2134
  return false;
2182
- if (event.symbol === null)
2183
- return true;
2184
- return (typeof event.symbol === 'string' &&
2185
- isPinnableSymbol(event.symbol) &&
2186
- compareFnAllowed(target));
2135
+ return (event.symbol === null ||
2136
+ (typeof event.symbol === 'string' && isPinnableSymbol(event.symbol)));
2187
2137
  },
2188
2138
  canSetStudyParam: ({ context, event }) => event.type === 'series.setStudyParam' &&
2189
2139
  respecAllowed(context, event.id, event.name, event.value),
@@ -2294,7 +2244,7 @@ export const terminalMachine = setup({
2294
2244
  },
2295
2245
  }),
2296
2246
  addPair: assign({
2297
- rows: keepingCompareWithValid(({ context, event }) => {
2247
+ rows: ({ context, event }) => {
2298
2248
  if (event.type !== 'series.addPair')
2299
2249
  return context.rows;
2300
2250
  const a = resolveLeg(context, event.a.metricId);
@@ -2349,7 +2299,7 @@ export const terminalMachine = setup({
2349
2299
  });
2350
2300
  }
2351
2301
  return context.rows.map((r) => r.id === row.id ? { ...r, configs: [cfg, ...r.configs] } : r);
2352
- }),
2302
+ },
2353
2303
  // Expand the new node so its controls open for tuning — the spread, or
2354
2304
  // (unjoined) whichever leg took the group's first minted id. Nothing to
2355
2305
  // expand when BOTH legs were adopted: no config was created.
@@ -2378,17 +2328,17 @@ export const terminalMachine = setup({
2378
2328
  // expansion, ink, axis membership and range pins all survive (they used to
2379
2329
  // be destroyed, and the dependents deleted outright).
2380
2330
  setStudyOutput: assign({
2381
- rows: keepingCompareWithValid(({ context, event }) => {
2331
+ rows: ({ context, event }) => {
2382
2332
  if (event.type !== 'series.setStudyOutput')
2383
2333
  return context.rows;
2384
2334
  const target = flatConfigs(context.rows).find((c) => c.id === event.id);
2385
2335
  if (!target?.derive)
2386
2336
  return context.rows;
2387
2337
  return applyRespec(context, event.id, respecOutput(target, event.output));
2388
- }),
2338
+ },
2389
2339
  }),
2390
2340
  setStudyInput: assign({
2391
- rows: keepingCompareWithValid(({ context, event }) => {
2341
+ rows: ({ context, event }) => {
2392
2342
  if (event.type !== 'series.setStudyInput')
2393
2343
  return context.rows;
2394
2344
  const configs = flatConfigs(context.rows);
@@ -2420,10 +2370,10 @@ export const terminalMachine = setup({
2420
2370
  return { ...c, parentIds };
2421
2371
  }),
2422
2372
  }));
2423
- }),
2373
+ },
2424
2374
  }),
2425
2375
  setDataColumns: assign({
2426
- rows: keepingCompareWithValid(({ context, event }) => {
2376
+ rows: ({ context, event }) => {
2427
2377
  if (event.type !== 'series.setDataColumns')
2428
2378
  return context.rows;
2429
2379
  const configs = flatConfigs(context.rows);
@@ -2459,10 +2409,10 @@ export const terminalMachine = setup({
2459
2409
  return { ...c, parentIds };
2460
2410
  }),
2461
2411
  }));
2462
- }),
2412
+ },
2463
2413
  }),
2464
2414
  setStudyOutputs: assign({
2465
- rows: keepingCompareWithValid(({ context, event }) => {
2415
+ rows: ({ context, event }) => {
2466
2416
  if (event.type !== 'series.setStudyOutputs')
2467
2417
  return context.rows;
2468
2418
  const study = flatConfigs(context.rows).find((c) => c.id === event.id);
@@ -2480,17 +2430,17 @@ export const terminalMachine = setup({
2480
2430
  ...r,
2481
2431
  configs: r.configs.map((c) => c.id === event.id ? { ...c, fan: next.fan, style: next.style } : c),
2482
2432
  }));
2483
- }),
2433
+ },
2484
2434
  }),
2485
2435
  setStudyParam: assign({
2486
- rows: keepingCompareWithValid(({ context, event }) => {
2436
+ rows: ({ context, event }) => {
2487
2437
  if (event.type !== 'series.setStudyParam')
2488
2438
  return context.rows;
2489
2439
  const target = flatConfigs(context.rows).find((c) => c.id === event.id);
2490
2440
  if (!target?.derive)
2491
2441
  return context.rows;
2492
2442
  return applyRespec(context, event.id, respecParam(target, event.name, event.value));
2493
- }),
2443
+ },
2494
2444
  }),
2495
2445
  addSeries: assign({
2496
2446
  rows: ({ context, event }) => {
@@ -2537,7 +2487,7 @@ export const terminalMachine = setup({
2537
2487
  },
2538
2488
  }),
2539
2489
  removeGroup: assign({
2540
- rows: keepingCompareWithValid(({ context, event }) => {
2490
+ rows: ({ context, event }) => {
2541
2491
  if (event.type !== 'group.remove')
2542
2492
  return context.rows;
2543
2493
  const doomed = groupDoomed(context.rows, event.groupId);
@@ -2546,7 +2496,7 @@ export const terminalMachine = setup({
2546
2496
  configs: r.configs.filter((c) => !doomed.has(c.id)),
2547
2497
  }));
2548
2498
  return pruneEmptied(context.rows, mapped);
2549
- }),
2499
+ },
2550
2500
  // The same invariant `removeSeries` states: neither pointer may point at a
2551
2501
  // removed series. Sibling assigners read the PRE-update context, so both
2552
2502
  // recompute the doomed set rather than reading the new rows (PR #149
@@ -2612,7 +2562,7 @@ export const terminalMachine = setup({
2612
2562
  },
2613
2563
  }),
2614
2564
  removeSeries: assign({
2615
- rows: keepingCompareWithValid(({ context, event }) => {
2565
+ rows: ({ context, event }) => {
2616
2566
  if (event.type !== 'series.remove')
2617
2567
  return context.rows;
2618
2568
  // Cascade to dependent studies so a nested study can't strand invisible +
@@ -2633,7 +2583,7 @@ export const terminalMachine = setup({
2633
2583
  // Not only the host row: an oscillator on its own row is in the
2634
2584
  // cascade, and its row must not stay behind as an empty pane.
2635
2585
  return pruneEmptied(context.rows, mapped);
2636
- }),
2586
+ },
2637
2587
  // Neither pointer may point at a removed series (or a cascaded dependent).
2638
2588
  selected: ({ context, event }) => event.type === 'series.remove' &&
2639
2589
  context.selected != null &&
@@ -2650,7 +2600,7 @@ export const terminalMachine = setup({
2650
2600
  // (a drag's absolute drop). Both splice-move within the series' own row; the
2651
2601
  // list is front→back, so index 0 is topmost on the canvas.
2652
2602
  orderSeries: assign({
2653
- rows: keepingCompareWithValid(({ context, event }) => {
2603
+ rows: ({ context, event }) => {
2654
2604
  if (event.type !== 'series.order' && event.type !== 'series.reindex')
2655
2605
  return context.rows;
2656
2606
  return context.rows.map((r) => {
@@ -2669,14 +2619,14 @@ export const terminalMachine = setup({
2669
2619
  : Math.max(0, Math.min(event.index, blocks.length - 1));
2670
2620
  return to === i ? r : { ...r, configs: reindex(blocks, i, to).flat() };
2671
2621
  });
2672
- }),
2622
+ },
2673
2623
  }),
2674
2624
  // Cross-row move: the series leaves its row (pruned if that empties it, as
2675
2625
  // with remove) and lands at the FRONT of the target row, on an axis its unit
2676
2626
  // can take there (the guard already proved one exists). Studies layered on it
2677
2627
  // travel with it, so a study can't strand on a row without its source.
2678
2628
  moveSeriesToRow: assign({
2679
- rows: keepingCompareWithValid(({ context, event }) => {
2629
+ rows: ({ context, event }) => {
2680
2630
  if (event.type !== 'series.moveToRow')
2681
2631
  return context.rows;
2682
2632
  const from = context.rows.find((r) => r.configs.some((c) => c.id === event.id));
@@ -2700,7 +2650,7 @@ export const terminalMachine = setup({
2700
2650
  });
2701
2651
  // An emptied source row goes away; the remainder row is kept.
2702
2652
  return pruneEmptied(context.rows, mapped);
2703
- }),
2653
+ },
2704
2654
  }),
2705
2655
  setCompareFn: assign({
2706
2656
  rows: ({ context, event }) => {
@@ -2721,47 +2671,17 @@ export const terminalMachine = setup({
2721
2671
  : r);
2722
2672
  },
2723
2673
  }),
2724
- setCompareWith: assign({
2725
- rows: ({ context, event }) => {
2726
- if (event.type !== 'series.setCompareWith')
2727
- return context.rows;
2728
- return context.rows.map((r) => r.configs.some((c) => c.id === event.id)
2729
- ? {
2730
- ...r,
2731
- configs: r.configs.map((c) => {
2732
- if (c.id !== event.id)
2733
- return c;
2734
- // Automatic again by REMOVING the key, as for the function.
2735
- const { compareWith: _drop, ...rest } = c;
2736
- if (!event.with)
2737
- return rest;
2738
- const { id, side, output } = event.with;
2739
- return { ...rest, compareWith: { id, side, ...(output ? { output } : {}) } };
2740
- }),
2741
- }
2742
- : r);
2743
- },
2744
- }),
2745
- setCompareOn: assign({
2746
- rows: ({ context, event }) => {
2747
- if (event.type !== 'series.setCompareOn')
2748
- return context.rows;
2749
- return context.rows.map((r) => r.configs.some((c) => c.id === event.id)
2750
- ? {
2751
- ...r,
2752
- configs: r.configs.map((c) => {
2753
- if (c.id !== event.id)
2754
- return c;
2755
- // Unlocked by REMOVING the key, as for the function.
2756
- const { compareOn: _drop, ...rest } = c;
2757
- return event.symbol ? { ...rest, compareOn: event.symbol } : rest;
2758
- }),
2759
- }
2760
- : 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;
2761
2681
  },
2762
2682
  }),
2763
2683
  patchSeries: assign({
2764
- rows: keepingCompareWithValid(({ context, event }) => {
2684
+ rows: ({ context, event }) => {
2765
2685
  if (event.type !== 'series.patch')
2766
2686
  return context.rows;
2767
2687
  // A study's colour is its parent's until the user says otherwise
@@ -2806,7 +2726,7 @@ export const terminalMachine = setup({
2806
2726
  ? { ...c, color: color }
2807
2727
  : c),
2808
2728
  }));
2809
- }),
2729
+ },
2810
2730
  }),
2811
2731
  toggleVisible: assign({
2812
2732
  rows: ({ context, event }) => {
@@ -2877,6 +2797,13 @@ export const terminalMachine = setup({
2877
2797
  // remainder row, which would reproduce the stuck-seam bug on apply.
2878
2798
  return p ? withRemainder(cloneRows(p.rows)) : context.rows;
2879
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
+ },
2880
2807
  // The applied rows are a fresh config — neither pointer necessarily survives.
2881
2808
  selected: null,
2882
2809
  expanded: null,
@@ -2909,7 +2836,12 @@ export const terminalMachine = setup({
2909
2836
  return context.presets;
2910
2837
  const set = context.presetSet;
2911
2838
  const next = context.presets[set].slice();
2912
- next[event.slot] = { rows: cloneRows(context.rows) };
2839
+ next[event.slot] = {
2840
+ rows: cloneRows(context.rows),
2841
+ ...(Object.keys(context.sourceLocks).length
2842
+ ? { sourceLocks: { ...context.sourceLocks } }
2843
+ : {}),
2844
+ };
2913
2845
  context.storage.savePresets(set, next);
2914
2846
  return { ...context.presets, [set]: next };
2915
2847
  },
@@ -3147,7 +3079,7 @@ export const terminalMachine = setup({
3147
3079
  removeRow: assign({
3148
3080
  // Removing a row is removing each of its series (`rowDoomed`), so a
3149
3081
  // study of one of its STUDIES goes too, on whatever row it sits.
3150
- rows: keepingCompareWithValid(({ context, event }) => {
3082
+ rows: ({ context, event }) => {
3151
3083
  if (event.type !== 'row.remove' || context.rows.length <= 1)
3152
3084
  return context.rows;
3153
3085
  const doomed = rowDoomed(context.rows, event.id);
@@ -3157,7 +3089,7 @@ export const terminalMachine = setup({
3157
3089
  // Removing the remainder row would leave the stack with none, so the
3158
3090
  // first survivor takes over as the one that absorbs slack.
3159
3091
  return pruneEmptied(context.rows, after);
3160
- }),
3092
+ },
3161
3093
  // Removing a row drops its series for good, so a pointer into it can't return
3162
3094
  // (unlike a ticker switch) — clear both (mirrors removeSeries).
3163
3095
  selected: ({ context, event }) => {
@@ -3183,7 +3115,8 @@ export const terminalMachine = setup({
3183
3115
  // reload re-seeds from the stored ACTIVE preset), so a blob written before
3184
3116
  // `withRemainder` existed — or any future host that forgets — would boot
3185
3117
  // straight into the stuck-seam state rather than being healed on first edit.
3186
- rows: withRemainder(input.initialRows),
3118
+ rows: withRemainder(input.initialRows.map((r) => ({ ...r, configs: r.configs.map(withoutLineLock) }))),
3119
+ sourceLocks: validLocks(input.initialSourceLocks),
3187
3120
  palette: input.palette ?? [],
3188
3121
  spreadColor: input.spreadColor,
3189
3122
  axisRanges: {},
@@ -3237,8 +3170,7 @@ export const terminalMachine = setup({
3237
3170
  'series.remove': { actions: 'removeSeries' },
3238
3171
  'series.patch': { actions: 'patchSeries' },
3239
3172
  'series.setCompareFn': { guard: 'canSetCompareFn', actions: 'setCompareFn' },
3240
- 'series.setCompareWith': { guard: 'canSetCompareWith', actions: 'setCompareWith' },
3241
- 'series.setCompareOn': { guard: 'canSetCompareOn', actions: 'setCompareOn' },
3173
+ 'source.setLock': { guard: 'canSetSourceLock', actions: 'setSourceLock' },
3242
3174
  'series.toggleVisible': { actions: 'toggleVisible' },
3243
3175
  'group.toggleVisible': { actions: 'toggleGroupVisible' },
3244
3176
  'group.remove': { actions: 'removeGroup' },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tidal-ts/terminal",
3
- "version": "0.28.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.28.0",
40
- "@tidal-ts/core": "0.28.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",