@tidal-ts/terminal 0.25.0 → 0.27.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
@@ -58,6 +58,8 @@ export declare function useCompareAll(): () => void;
58
58
  export declare function useSetCompareFn(): (id: string, fn: PairOp | null) => void;
59
59
  /** Wire a compare's other side by hand, or `null` for automatic. */
60
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;
61
63
  export declare function useSetStudyParam(): (id: string, name: string, value: number) => void;
62
64
  /** Switch which output of a multi-output source a study reads (the output
63
65
  * picker). Pair it with `outputAllowed` to render refused choices disabled. */
package/dist/context.js CHANGED
@@ -114,6 +114,11 @@ export function useSetCompareWith() {
114
114
  const ref = TerminalContext.useActorRef();
115
115
  return useCallback((id, other) => ref.send({ type: 'series.setCompareWith', id, with: other }), [ref]);
116
116
  }
117
+ /** Lock a compare's other side to a symbol, or `null` for the comparison. */
118
+ export function useSetCompareOn() {
119
+ const ref = TerminalContext.useActorRef();
120
+ return useCallback((id, symbol) => ref.send({ type: 'series.setCompareOn', id, symbol }), [ref]);
121
+ }
117
122
  export function useSetStudyParam() {
118
123
  const ref = TerminalContext.useActorRef();
119
124
  return useCallback((id, name, value) => ref.send({ type: 'series.setStudyParam', id, name, value }), [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, 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';
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
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,7 +5,7 @@
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, 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';
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
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;
@@ -236,7 +236,7 @@ export type TerminalEvent = {
236
236
  | {
237
237
  type: 'series.patch';
238
238
  id: string;
239
- patch: Partial<Omit<SeriesConfig, 'axis' | 'axisGroup' | 'parentIds' | 'compareFn' | 'compareWith'>>;
239
+ patch: Partial<Omit<SeriesConfig, 'axis' | 'axisGroup' | 'parentIds' | 'compareFn' | 'compareWith' | 'compareOn'>>;
240
240
  } | {
241
241
  type: 'series.toggleVisible';
242
242
  id: string;
@@ -259,6 +259,15 @@ export type TerminalEvent = {
259
259
  id: string;
260
260
  with: CompareWith | null;
261
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;
269
+ symbol: string | null;
270
+ }
262
271
  /** The PAIR's own eye — hides both legs at once. Each leg keeps its own
263
272
  * `visible`, so unhiding the pair restores what each leg was rather than
264
273
  * switching everything on (Peter, 2026-08-18). */
@@ -700,7 +709,7 @@ export declare const terminalMachine: import("xstate").StateMachine<TerminalCont
700
709
  } | {
701
710
  type: "series.patch";
702
711
  id: string;
703
- patch: Partial<Omit<SeriesConfig, "axis" | "axisGroup" | "parentIds" | "compareFn" | "compareWith">>;
712
+ patch: Partial<Omit<SeriesConfig, "axis" | "axisGroup" | "parentIds" | "compareFn" | "compareWith" | "compareOn">>;
704
713
  } | {
705
714
  type: "series.toggleVisible";
706
715
  id: string;
@@ -712,6 +721,10 @@ export declare const terminalMachine: import("xstate").StateMachine<TerminalCont
712
721
  type: "series.setCompareWith";
713
722
  id: string;
714
723
  with: CompareWith | null;
724
+ } | {
725
+ type: "series.setCompareOn";
726
+ id: string;
727
+ symbol: string | null;
715
728
  } | {
716
729
  type: "group.toggleVisible";
717
730
  groupId: string;
@@ -830,6 +843,9 @@ export declare const terminalMachine: import("xstate").StateMachine<TerminalCont
830
843
  } | {
831
844
  type: "setCompareWith";
832
845
  params: import("xstate").NonReducibleUnknown;
846
+ } | {
847
+ type: "setCompareOn";
848
+ params: import("xstate").NonReducibleUnknown;
833
849
  } | {
834
850
  type: "patchSeries";
835
851
  params: import("xstate").NonReducibleUnknown;
@@ -917,6 +933,9 @@ export declare const terminalMachine: import("xstate").StateMachine<TerminalCont
917
933
  } | {
918
934
  type: "canSetCompareWith";
919
935
  params: unknown;
936
+ } | {
937
+ type: "canSetCompareOn";
938
+ params: unknown;
920
939
  } | {
921
940
  type: "canSetStudyParam";
922
941
  params: unknown;
@@ -1,5 +1,5 @@
1
1
  import { assign, enqueueActions, setup } from 'xstate';
2
- import { COMPARE_PREFIX, hasPairOp, usesCompare, deriveId, opParams, opInputs, opNeedsColumns, opIsBand, opIsMulti, outputMark, opOutputs, TARGET_ROLES, opSharesSourceAxis, studyTag, inputNames, isPickedInput, isPairOp, isValidSpec, partStudyLabel, readPairParts, specUnit, studyInputOf, studyPick, substituteInput, withStudyOutput, studyColumn, withStudyColumn, isStudyOp, BAR_PRICE_COLUMNS, fanPick, primaryOutput, withFanOutput, } from '@tidal-ts/core';
2
+ import { COMPARE_PREFIX, isPinnableSymbol, stripOtherSymbol, hasPairOp, usesCompare, deriveId, opParams, opInputs, opNeedsColumns, opIsBand, opIsMulti, outputMark, opOutputs, TARGET_ROLES, opSharesSourceAxis, studyTag, inputNames, isPickedInput, isPairOp, isValidSpec, partStudyLabel, readPairParts, specUnit, studyInputOf, studyPick, substituteInput, withStudyOutput, studyColumn, withStudyColumn, isStudyOp, BAR_PRICE_COLUMNS, fanPick, primaryOutput, withFanOutput, } from '@tidal-ts/core';
3
3
  /**
4
4
  * The bar columns each data SOURCE carries — the one fact that decides whether a
5
5
  * multi-column study is offerable on a series. Only the price series has bars;
@@ -732,10 +732,10 @@ export const columnUnits = (catalog, configs = []) => {
732
732
  for (const part of BAR_PRICE_PARTS)
733
733
  if (!units.has(part))
734
734
  units.set(part, units.get('close') ?? '');
735
- return (column) => units.get(column) ??
736
- (column.startsWith(COMPARE_PREFIX)
737
- ? (units.get(column.slice(COMPARE_PREFIX.length)) ?? '')
738
- : '');
735
+ return (column) =>
736
+ // Another symbol's reading — the comparison's or a locked symbol's — is in
737
+ // the unit of the same column on the primary.
738
+ units.get(column) ?? units.get(stripOtherSymbol(column)) ?? '';
739
739
  };
740
740
  /** The bar columns that read in the same unit as the bar's `close`. */
741
741
  const BAR_PRICE_PARTS = ['open', 'high', 'low'];
@@ -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, ...asked } = patch;
1075
+ const { compareFn: _ignored, compareWith: _alsoIgnored, compareOn: _locked, ...asked } = patch;
1076
1076
  return keepCompareFnCoherent(drawablePatch(c, asked));
1077
1077
  }
1078
1078
  function drawablePatch(c, patch) {
@@ -1095,9 +1095,9 @@ 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) || compareFnAllowed(c))
1098
+ if ((!c.compareFn && !c.compareWith && !c.compareOn) || compareFnAllowed(c))
1099
1099
  return c;
1100
- const { compareFn: _drop, compareWith: _dropWith, ...rest } = c;
1100
+ const { compareFn: _drop, compareWith: _dropWith, compareOn: _dropOn, ...rest } = c;
1101
1101
  return rest;
1102
1102
  }
1103
1103
  /**
@@ -1959,6 +1959,15 @@ export function canonRows(rows) {
1959
1959
  ],
1960
1960
  ]
1961
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
+ : []),
1962
1971
  ]),
1963
1972
  ];
1964
1973
  }));
@@ -2164,6 +2173,18 @@ export const terminalMachine = setup({
2164
2173
  const other = all.find((c) => c.id === event.with.id);
2165
2174
  return !!other && compareWithAllowed(target, other, output);
2166
2175
  },
2176
+ canSetCompareOn: ({ context, event }) => {
2177
+ if (event.type !== 'series.setCompareOn')
2178
+ return false;
2179
+ const target = flatConfigs(context.rows).find((c) => c.id === event.id);
2180
+ if (!target)
2181
+ return false;
2182
+ if (event.symbol === null)
2183
+ return true;
2184
+ return (typeof event.symbol === 'string' &&
2185
+ isPinnableSymbol(event.symbol) &&
2186
+ compareFnAllowed(target));
2187
+ },
2167
2188
  canSetStudyParam: ({ context, event }) => event.type === 'series.setStudyParam' &&
2168
2189
  respecAllowed(context, event.id, event.name, event.value),
2169
2190
  // The chain toggle — delegated to the shared pure helper so the panel's
@@ -2721,6 +2742,24 @@ export const terminalMachine = setup({
2721
2742
  : r);
2722
2743
  },
2723
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);
2761
+ },
2762
+ }),
2724
2763
  patchSeries: assign({
2725
2764
  rows: keepingCompareWithValid(({ context, event }) => {
2726
2765
  if (event.type !== 'series.patch')
@@ -3199,6 +3238,7 @@ export const terminalMachine = setup({
3199
3238
  'series.patch': { actions: 'patchSeries' },
3200
3239
  'series.setCompareFn': { guard: 'canSetCompareFn', actions: 'setCompareFn' },
3201
3240
  'series.setCompareWith': { guard: 'canSetCompareWith', actions: 'setCompareWith' },
3241
+ 'series.setCompareOn': { guard: 'canSetCompareOn', actions: 'setCompareOn' },
3202
3242
  'series.toggleVisible': { actions: 'toggleVisible' },
3203
3243
  'group.toggleVisible': { actions: 'toggleGroupVisible' },
3204
3244
  'group.remove': { actions: 'removeGroup' },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tidal-ts/terminal",
3
- "version": "0.25.0",
3
+ "version": "0.27.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.25.0",
40
- "@tidal-ts/core": "0.25.0"
39
+ "@tidal-ts/chart": "0.27.0",
40
+ "@tidal-ts/core": "0.27.0"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@pond-ts/charts": "^0.78.0",