@tidal-ts/terminal 0.24.0 → 0.26.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). */
@@ -620,9 +629,10 @@ export declare function swapAllowed(configs: readonly SeriesConfig[], id: string
620
629
  * Whether `other` can be wired by hand as `target`'s compare other side
621
630
  * ({@link SeriesConfig.compareWith}): the target must be able to carry a
622
631
  * compare at all ({@link compareFnAllowed}), and the other side must be a
623
- * different config with one line to read.
632
+ * different config with ONE line to read — its only line, or the one
633
+ * `output` names when it draws several ({@link compareWithInput}).
624
634
  */
625
- export declare function compareWithAllowed(target: SeriesConfig, other: SeriesConfig): boolean;
635
+ export declare function compareWithAllowed(target: SeriesConfig, other: SeriesConfig, output?: string): boolean;
626
636
  /**
627
637
  * Whether a seated config can carry a compare function
628
638
  * ({@link SeriesConfig.compareFn}) or a hand-wired other side
@@ -699,7 +709,7 @@ export declare const terminalMachine: import("xstate").StateMachine<TerminalCont
699
709
  } | {
700
710
  type: "series.patch";
701
711
  id: string;
702
- patch: Partial<Omit<SeriesConfig, "axis" | "axisGroup" | "parentIds" | "compareFn" | "compareWith">>;
712
+ patch: Partial<Omit<SeriesConfig, "axis" | "axisGroup" | "parentIds" | "compareFn" | "compareWith" | "compareOn">>;
703
713
  } | {
704
714
  type: "series.toggleVisible";
705
715
  id: string;
@@ -711,6 +721,10 @@ export declare const terminalMachine: import("xstate").StateMachine<TerminalCont
711
721
  type: "series.setCompareWith";
712
722
  id: string;
713
723
  with: CompareWith | null;
724
+ } | {
725
+ type: "series.setCompareOn";
726
+ id: string;
727
+ symbol: string | null;
714
728
  } | {
715
729
  type: "group.toggleVisible";
716
730
  groupId: string;
@@ -829,6 +843,9 @@ export declare const terminalMachine: import("xstate").StateMachine<TerminalCont
829
843
  } | {
830
844
  type: "setCompareWith";
831
845
  params: import("xstate").NonReducibleUnknown;
846
+ } | {
847
+ type: "setCompareOn";
848
+ params: import("xstate").NonReducibleUnknown;
832
849
  } | {
833
850
  type: "patchSeries";
834
851
  params: import("xstate").NonReducibleUnknown;
@@ -916,6 +933,9 @@ export declare const terminalMachine: import("xstate").StateMachine<TerminalCont
916
933
  } | {
917
934
  type: "canSetCompareWith";
918
935
  params: unknown;
936
+ } | {
937
+ type: "canSetCompareOn";
938
+ params: unknown;
919
939
  } | {
920
940
  type: "canSetStudyParam";
921
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;
@@ -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, } from '@tidal-ts/chart';
35
+ import { configAxisId, seriesAxisId, sharedAxisId, compareWithInput, } 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. */
@@ -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
  /**
@@ -1114,7 +1114,7 @@ function keepCompareWithValid(rows) {
1114
1114
  if (!c.compareWith)
1115
1115
  return true;
1116
1116
  const other = byId.get(c.compareWith.id);
1117
- return !!other && compareWithAllowed(c, other);
1117
+ return !!other && compareWithAllowed(c, other, c.compareWith.output);
1118
1118
  };
1119
1119
  if (flatConfigs(rows).every(holds))
1120
1120
  return rows;
@@ -1835,27 +1835,19 @@ function comparableMetric(c) {
1835
1835
  * Whether `other` can be wired by hand as `target`'s compare other side
1836
1836
  * ({@link SeriesConfig.compareWith}): the target must be able to carry a
1837
1837
  * compare at all ({@link compareFnAllowed}), and the other side must be a
1838
- * different config with one line to read.
1838
+ * different config with ONE line to read — its only line, or the one
1839
+ * `output` names when it draws several ({@link compareWithInput}).
1839
1840
  */
1840
- export function compareWithAllowed(target, other) {
1841
+ export function compareWithAllowed(target, other, output) {
1841
1842
  if (!compareFnAllowed(target) || other.id === target.id)
1842
1843
  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).
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
1846
  if (other.group || other.column.startsWith(COMPARE_PREFIX))
1847
1847
  return false;
1848
- if (other.style === 'band' || other.style === 'lines')
1848
+ if (other.derive && (hasPairOp(other.derive) || usesCompare(other.derive)))
1849
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;
1850
+ return compareWithInput(other, output) !== null;
1859
1851
  }
1860
1852
  /**
1861
1853
  * Whether a seated config can carry a compare function
@@ -1960,7 +1952,20 @@ export function canonRows(rows) {
1960
1952
  ...(c.compareWith
1961
1953
  ? [
1962
1954
  ...(c.compareFn ? [] : [null]),
1963
- [columnOf.get(c.compareWith.id) ?? null, c.compareWith.side],
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,
1964
1969
  ]
1965
1970
  : []),
1966
1971
  ]),
@@ -2161,8 +2166,24 @@ export const terminalMachine = setup({
2161
2166
  return true;
2162
2167
  if (event.with.side !== 'primary' && event.with.side !== 'comparison')
2163
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;
2164
2173
  const other = all.find((c) => c.id === event.with.id);
2165
- return !!other && compareWithAllowed(target, other);
2174
+ return !!other && compareWithAllowed(target, other, output);
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));
2166
2187
  },
2167
2188
  canSetStudyParam: ({ context, event }) => event.type === 'series.setStudyParam' &&
2168
2189
  respecAllowed(context, event.id, event.name, event.value),
@@ -2712,9 +2733,28 @@ export const terminalMachine = setup({
2712
2733
  return c;
2713
2734
  // Automatic again by REMOVING the key, as for the function.
2714
2735
  const { compareWith: _drop, ...rest } = c;
2715
- return event.with
2716
- ? { ...rest, compareWith: { id: event.with.id, side: event.with.side } }
2717
- : rest;
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;
2718
2758
  }),
2719
2759
  }
2720
2760
  : r);
@@ -3198,6 +3238,7 @@ export const terminalMachine = setup({
3198
3238
  'series.patch': { actions: 'patchSeries' },
3199
3239
  'series.setCompareFn': { guard: 'canSetCompareFn', actions: 'setCompareFn' },
3200
3240
  'series.setCompareWith': { guard: 'canSetCompareWith', actions: 'setCompareWith' },
3241
+ 'series.setCompareOn': { guard: 'canSetCompareOn', actions: 'setCompareOn' },
3201
3242
  'series.toggleVisible': { actions: 'toggleVisible' },
3202
3243
  'group.toggleVisible': { actions: 'toggleGroupVisible' },
3203
3244
  'group.remove': { actions: 'removeGroup' },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tidal-ts/terminal",
3
- "version": "0.24.0",
3
+ "version": "0.26.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.24.0",
40
- "@tidal-ts/core": "0.24.0"
39
+ "@tidal-ts/chart": "0.26.0",
40
+ "@tidal-ts/core": "0.26.0"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@pond-ts/charts": "^0.78.0",