@tidal-ts/terminal 0.4.0 → 0.5.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 +3 -0
- package/dist/context.js +6 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/terminalMachine.js +69 -25
- package/package.json +3 -3
package/dist/context.d.ts
CHANGED
|
@@ -48,6 +48,9 @@ export declare function useAddPair(): (a: PairLegInput, b: PairLegInput, op: Pai
|
|
|
48
48
|
* terminal machine cannot see whether one is. */
|
|
49
49
|
export declare function useCompareAll(): () => void;
|
|
50
50
|
export declare function useSetStudyParam(): (id: string, name: string, value: number) => void;
|
|
51
|
+
/** Switch which output of a multi-output source a study reads (the output
|
|
52
|
+
* picker). Pair it with `outputAllowed` to render refused choices disabled. */
|
|
53
|
+
export declare function useSetStudyOutput(): (id: string, output: string) => void;
|
|
51
54
|
/** Step a series' draw order within its row (`front`/`up`/`down`/`back`; the
|
|
52
55
|
* list is front→back, so `up` moves toward the top of the canvas stack). */
|
|
53
56
|
export declare function useOrderSeries(): (id: string, to: 'front' | 'up' | 'down' | 'back') => void;
|
package/dist/context.js
CHANGED
|
@@ -86,6 +86,12 @@ export function useSetStudyParam() {
|
|
|
86
86
|
const ref = TerminalContext.useActorRef();
|
|
87
87
|
return useCallback((id, name, value) => ref.send({ type: 'series.setStudyParam', id, name, value }), [ref]);
|
|
88
88
|
}
|
|
89
|
+
/** Switch which output of a multi-output source a study reads (the output
|
|
90
|
+
* picker). Pair it with `outputAllowed` to render refused choices disabled. */
|
|
91
|
+
export function useSetStudyOutput() {
|
|
92
|
+
const ref = TerminalContext.useActorRef();
|
|
93
|
+
return useCallback((id, output) => ref.send({ type: 'series.setStudyOutput', id, output }), [ref]);
|
|
94
|
+
}
|
|
89
95
|
/** Step a series' draw order within its row (`front`/`up`/`down`/`back`; the
|
|
90
96
|
* list is front→back, so `up` moves toward the top of the canvas stack). */
|
|
91
97
|
export function useOrderSeries() {
|
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, useSetStudyParam, 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';
|
|
8
|
+
export { TerminalProvider, useRows, useSelectedSeries, useExpandedSeries, useControlsOpen, usePresetSaved, useActiveSlot, useAddSeries, useAddPair, useCompareAll, useAddStudy, useSetStudyParam, useSetStudyOutput, 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
9
|
export { PRESET_SLOTS, MAX_ROWS, activeSlot, canonRows, columnLabel, columnUnits, entryColumn, groupMembers, mintId, axisMoveAllowed, linkToggleAllowed, respecAllowed, outputAllowed, 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, useSetStudyParam, 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';
|
|
8
|
+
export { TerminalProvider, useRows, useSelectedSeries, useExpandedSeries, useControlsOpen, usePresetSaved, useActiveSlot, useAddSeries, useAddPair, useCompareAll, useAddStudy, useSetStudyParam, useSetStudyOutput, 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
9
|
export { PRESET_SLOTS, MAX_ROWS, activeSlot, canonRows, columnLabel, columnUnits, entryColumn, groupMembers, mintId, axisMoveAllowed, linkToggleAllowed, respecAllowed, outputAllowed, 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;
|
package/dist/terminalMachine.js
CHANGED
|
@@ -37,6 +37,12 @@ import { axisForAdd, canAddUnit } from './axisPolicy.js';
|
|
|
37
37
|
export const PRESET_SLOTS = 5;
|
|
38
38
|
/** Max viewport rows (the control-panel spec: 1–3, capped at 3 for now). */
|
|
39
39
|
export const MAX_ROWS = 3;
|
|
40
|
+
/**
|
|
41
|
+
* Whether a new study of `op` opens on a row of its own (TDL-OSCROW): it reads
|
|
42
|
+
* in its own units (pond's `unit` rule — only `inherit` shares its source's
|
|
43
|
+
* scale) and there is room for another row.
|
|
44
|
+
*/
|
|
45
|
+
const ownsRow = (context, op) => !opSharesSourceAxis(op) && context.rows.length < MAX_ROWS;
|
|
40
46
|
/** Committed height (px) a freshly added row gets — a **fixed** strip, not a flex
|
|
41
47
|
* remainder row (`height: 0`). Exactly one remainder row is kept (the seed's
|
|
42
48
|
* top/vol panel, which absorbs slack); a second would make dragging any seam
|
|
@@ -64,6 +70,21 @@ function withRemainder(rows) {
|
|
|
64
70
|
return rows;
|
|
65
71
|
return rows.map((r, i) => (i === 0 ? { ...r, height: 0 } : r));
|
|
66
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* Drop every row an edit EMPTIED (the control-panel spec: no empty rows), and
|
|
75
|
+
* keep exactly one remainder row. `after` is `before` with configs taken out
|
|
76
|
+
* or moved, row for row. A row that was already empty (a fresh `row.add`)
|
|
77
|
+
* stays: the user made it to fill. At least one row always survives.
|
|
78
|
+
*
|
|
79
|
+
* Shared by every edit that takes configs off rows — remove, group remove and a
|
|
80
|
+
* cross-row move — because an oscillator on its own row (TDL-OSCROW) means
|
|
81
|
+
* one edit can empty a row other than the one it started on.
|
|
82
|
+
*/
|
|
83
|
+
function pruneEmptied(before, after) {
|
|
84
|
+
const had = new Set(before.filter((r) => r.configs.length > 0).map((r) => r.id));
|
|
85
|
+
const kept = after.filter((r) => r.configs.length > 0 || !had.has(r.id));
|
|
86
|
+
return withRemainder(kept.length > 0 ? kept : after.slice(0, 1));
|
|
87
|
+
}
|
|
67
88
|
/**
|
|
68
89
|
* Config identity. A seated config's `id` is minted here and never derived from
|
|
69
90
|
* what it computes: `s-3` keys selection, expansion, the chart theme, axis
|
|
@@ -137,8 +158,10 @@ function derivedClosure(configs, rootId) {
|
|
|
137
158
|
}
|
|
138
159
|
/**
|
|
139
160
|
* `rootId` plus the **studies layered on it** within this row — the travel set for
|
|
140
|
-
* a cross-row move.
|
|
141
|
-
* target takes its studies along rather than leaving
|
|
161
|
+
* a cross-row move. A study that shares its target's scale sits on its target's
|
|
162
|
+
* row, so moving the target takes its studies along rather than leaving
|
|
163
|
+
* `Price · SMA(20)` behind. A study on a row of its own (an RSI, TDL-OSCROW)
|
|
164
|
+
* stays where it is: its row is its place, not its target's.
|
|
142
165
|
*
|
|
143
166
|
* Only **studies** travel, never a derived **catalog** metric (`isCatalogId`): a
|
|
144
167
|
* study exists solely as a layer on the series it was added to, whereas the
|
|
@@ -1601,15 +1624,42 @@ export const terminalMachine = setup({
|
|
|
1601
1624
|
// the id minted here and the one `expanded`/`cfgSeq` compute below all
|
|
1602
1625
|
// agree without threading a value between them.
|
|
1603
1626
|
const cfg = studyConfig(target, event.op, event.period, mintId(context.cfgSeq), unitOfColumn(context));
|
|
1604
|
-
//
|
|
1605
|
-
//
|
|
1606
|
-
//
|
|
1607
|
-
//
|
|
1627
|
+
// A study in its OWN units (an RSI, a MACD, an ATR) opens on a row of
|
|
1628
|
+
// its own, directly under its target's row (TDL-OSCROW). On the target's
|
|
1629
|
+
// row it drew over the price on a second scale, which is what the
|
|
1630
|
+
// drawing plan measured for 63 of the addable studies. With the row cap
|
|
1631
|
+
// reached it overlays as before, on its own axis, and can be moved later.
|
|
1632
|
+
if (ownsRow(context, event.op)) {
|
|
1633
|
+
// Under the target's row — and under any own-row study of the same
|
|
1634
|
+
// target already there, so oscillators stack in the order added.
|
|
1635
|
+
const built = studiesOn(flatConfigs(context.rows), target.id, isCatalogColumn(context));
|
|
1636
|
+
const at = context.rows.reduce((last, r, i) => (r.configs.some((c) => built.has(c.id)) ? i : last), -1);
|
|
1637
|
+
const row = {
|
|
1638
|
+
id: mintRowId(context.rowSeq),
|
|
1639
|
+
height: NEW_ROW_HEIGHT,
|
|
1640
|
+
configs: [cfg],
|
|
1641
|
+
};
|
|
1642
|
+
return withRemainder([
|
|
1643
|
+
...context.rows.slice(0, at + 1),
|
|
1644
|
+
row,
|
|
1645
|
+
...context.rows.slice(at + 1),
|
|
1646
|
+
]);
|
|
1647
|
+
}
|
|
1648
|
+
// Otherwise overlay on the target's row, inserted directly IN FRONT of
|
|
1649
|
+
// its target — the list is front→back, so that's the target's own
|
|
1650
|
+
// index. A study must read over its source (see `studyConfig`);
|
|
1651
|
+
// appending would bury it at the very back.
|
|
1608
1652
|
return context.rows.map((r) => {
|
|
1609
1653
|
const at = r.configs.findIndex((c) => c.id === target.id);
|
|
1610
1654
|
return at < 0 ? r : { ...r, configs: reindex([...r.configs, cfg], r.configs.length, at) };
|
|
1611
1655
|
});
|
|
1612
1656
|
},
|
|
1657
|
+
rowSeq: ({ context, event }) => {
|
|
1658
|
+
if (event.type !== 'series.addStudy')
|
|
1659
|
+
return context.rowSeq;
|
|
1660
|
+
const known = flatConfigs(context.rows).some((c) => c.id === event.targetId);
|
|
1661
|
+
return known && ownsRow(context, event.op) ? context.rowSeq + 1 : context.rowSeq;
|
|
1662
|
+
},
|
|
1613
1663
|
// Expand the new study so its controls (period, colour) open for tuning.
|
|
1614
1664
|
expanded: ({ context, event }) => {
|
|
1615
1665
|
if (event.type !== 'series.addStudy')
|
|
@@ -1782,9 +1832,7 @@ export const terminalMachine = setup({
|
|
|
1782
1832
|
...r,
|
|
1783
1833
|
configs: r.configs.filter((c) => !doomed.has(c.id)),
|
|
1784
1834
|
}));
|
|
1785
|
-
return
|
|
1786
|
-
? mapped.filter((r) => r.configs.length > 0)
|
|
1787
|
-
: mapped;
|
|
1835
|
+
return pruneEmptied(context.rows, mapped);
|
|
1788
1836
|
},
|
|
1789
1837
|
// The same invariant `removeSeries` states: neither pointer may point at a
|
|
1790
1838
|
// removed series. Sibling assigners read the PRE-update context, so both
|
|
@@ -1869,13 +1917,9 @@ export const terminalMachine = setup({
|
|
|
1869
1917
|
.filter((c) => !doomed.has(c.id))
|
|
1870
1918
|
.map((c) => (c.group && orphaned.has(c.group.id) ? { ...c, group: undefined } : c)),
|
|
1871
1919
|
}));
|
|
1872
|
-
//
|
|
1873
|
-
//
|
|
1874
|
-
|
|
1875
|
-
const hostNow = host && mapped.find((r) => r.id === host.id);
|
|
1876
|
-
return hostNow && hostNow.configs.length === 0 && mapped.length > 1
|
|
1877
|
-
? mapped.filter((r) => r.id !== host.id)
|
|
1878
|
-
: mapped;
|
|
1920
|
+
// Not only the host row: an oscillator on its own row is in the
|
|
1921
|
+
// cascade, and its row must not stay behind as an empty pane.
|
|
1922
|
+
return pruneEmptied(context.rows, mapped);
|
|
1879
1923
|
},
|
|
1880
1924
|
// Neither pointer may point at a removed series (or a cascaded dependent).
|
|
1881
1925
|
selected: ({ context, event }) => event.type === 'series.remove' &&
|
|
@@ -1941,10 +1985,8 @@ export const terminalMachine = setup({
|
|
|
1941
1985
|
return { ...r, configs: [...placed, ...r.configs] };
|
|
1942
1986
|
return r;
|
|
1943
1987
|
});
|
|
1944
|
-
// An emptied source row goes away
|
|
1945
|
-
|
|
1946
|
-
const emptied = mapped.find((r) => r.id === from.id && r.configs.length === 0);
|
|
1947
|
-
return emptied && mapped.length > 1 ? mapped.filter((r) => r.id !== from.id) : mapped;
|
|
1988
|
+
// An emptied source row goes away; the remainder row is kept.
|
|
1989
|
+
return pruneEmptied(context.rows, mapped);
|
|
1948
1990
|
},
|
|
1949
1991
|
}),
|
|
1950
1992
|
patchSeries: assign({
|
|
@@ -1981,10 +2023,9 @@ export const terminalMachine = setup({
|
|
|
1981
2023
|
// trade from the pair eye, which keeps each leg's own state behind a
|
|
1982
2024
|
// separate `group.hidden` flag. A pair's legs are peers; a study is
|
|
1983
2025
|
// subordinate, so following its parent is the better default.
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
: new Set();
|
|
2026
|
+
// Across EVERY row: an oscillator on its own row is still built on
|
|
2027
|
+
// this series (TDL-OSCROW).
|
|
2028
|
+
const cascade = studiesOn(flatConfigs(context.rows), event.id, isCatalogColumn(context));
|
|
1988
2029
|
return context.rows.map((r) => ({
|
|
1989
2030
|
...r,
|
|
1990
2031
|
configs: r.configs.map((c) => (cascade.has(c.id) ? { ...c, visible: next } : c)),
|
|
@@ -2321,7 +2362,10 @@ export const terminalMachine = setup({
|
|
|
2321
2362
|
palette: input.palette ?? [],
|
|
2322
2363
|
spreadColor: input.spreadColor,
|
|
2323
2364
|
axisRanges: {},
|
|
2324
|
-
|
|
2365
|
+
// Past every seeded `row-N`, not just the row count: a host re-seeds from a
|
|
2366
|
+
// stored preset whose rows were minted in an earlier session, and a count
|
|
2367
|
+
// would mint one of their ids again.
|
|
2368
|
+
rowSeq: Math.max(input.initialRows.length, rowSeqAfter(input.initialRows)),
|
|
2325
2369
|
cfgSeq: cfgSeqAfter(input.initialRows),
|
|
2326
2370
|
selected: null,
|
|
2327
2371
|
expanded: null,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tidal-ts/terminal",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.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.5.0",
|
|
40
|
+
"@tidal-ts/core": "0.5.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@pond-ts/charts": "^0.70.0",
|