@tidal-ts/terminal 0.1.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/LICENSE +21 -0
- package/dist/axisPolicy.d.ts +34 -0
- package/dist/axisPolicy.js +31 -0
- package/dist/context.d.ts +103 -0
- package/dist/context.js +229 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +9 -0
- package/dist/terminalMachine.d.ts +683 -0
- package/dist/terminalMachine.js +2229 -0
- package/package.json +59 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Peter Murphy
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { SeriesAxis } from '@tidal-ts/chart';
|
|
2
|
+
/**
|
|
3
|
+
* Unit-driven axis compatibility for a panel. A panel has two sides (L / R);
|
|
4
|
+
* once a series sits on a side, that side is **bound** to its unit. The rules
|
|
5
|
+
* (pure functions, so they're unit-tested directly):
|
|
6
|
+
*
|
|
7
|
+
* - A series may share a side only with series of the **same unit** (exact match).
|
|
8
|
+
* - A different unit must take the other side.
|
|
9
|
+
* - With both sides bound to different units, a third unit can't be added.
|
|
10
|
+
*
|
|
11
|
+
* `members` is the panel's present series (each contributes its `unit` + `axis`).
|
|
12
|
+
*/
|
|
13
|
+
export interface AxisMember {
|
|
14
|
+
unit: string;
|
|
15
|
+
axis: SeriesAxis;
|
|
16
|
+
}
|
|
17
|
+
/** The unit bound to each side (undefined = free). Reports the FIRST series' unit
|
|
18
|
+
* per side — sides are single-unit by construction (every add/move goes through
|
|
19
|
+
* {@link allowedAxes}), so this is for display/queries, not the safety gate. */
|
|
20
|
+
export declare function axisBindings(members: readonly AxisMember[]): {
|
|
21
|
+
L?: string;
|
|
22
|
+
R?: string;
|
|
23
|
+
};
|
|
24
|
+
/** Sides where a series of `unit` may sit given `members`: a free side, or one
|
|
25
|
+
* where **every** present series already shares `unit`. Checking all members
|
|
26
|
+
* (not just the first-bound unit) keeps the gate correct even if a mixed-unit
|
|
27
|
+
* side ever slips in — such a side is then allowed for no unit. Pass `members`
|
|
28
|
+
* WITHOUT the series itself when asking where an existing series may move. */
|
|
29
|
+
export declare function allowedAxes(members: readonly AxisMember[], unit: string): SeriesAxis[];
|
|
30
|
+
/** Whether a series of `unit` can be added to the panel at all. */
|
|
31
|
+
export declare function canAddUnit(members: readonly AxisMember[], unit: string): boolean;
|
|
32
|
+
/** Which side to place a new series of `unit` on — its `preferred` side if that's
|
|
33
|
+
* allowed, else the other allowed side, else `null` (incompatible). */
|
|
34
|
+
export declare function axisForAdd(members: readonly AxisMember[], unit: string, preferred: SeriesAxis): SeriesAxis | null;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const SIDES = ['L', 'R'];
|
|
2
|
+
/** The unit bound to each side (undefined = free). Reports the FIRST series' unit
|
|
3
|
+
* per side — sides are single-unit by construction (every add/move goes through
|
|
4
|
+
* {@link allowedAxes}), so this is for display/queries, not the safety gate. */
|
|
5
|
+
export function axisBindings(members) {
|
|
6
|
+
const bindings = {};
|
|
7
|
+
for (const m of members)
|
|
8
|
+
if (bindings[m.axis] === undefined)
|
|
9
|
+
bindings[m.axis] = m.unit;
|
|
10
|
+
return bindings;
|
|
11
|
+
}
|
|
12
|
+
/** Sides where a series of `unit` may sit given `members`: a free side, or one
|
|
13
|
+
* where **every** present series already shares `unit`. Checking all members
|
|
14
|
+
* (not just the first-bound unit) keeps the gate correct even if a mixed-unit
|
|
15
|
+
* side ever slips in — such a side is then allowed for no unit. Pass `members`
|
|
16
|
+
* WITHOUT the series itself when asking where an existing series may move. */
|
|
17
|
+
export function allowedAxes(members, unit) {
|
|
18
|
+
return SIDES.filter((side) => members.every((m) => m.axis !== side || m.unit === unit));
|
|
19
|
+
}
|
|
20
|
+
/** Whether a series of `unit` can be added to the panel at all. */
|
|
21
|
+
export function canAddUnit(members, unit) {
|
|
22
|
+
return allowedAxes(members, unit).length > 0;
|
|
23
|
+
}
|
|
24
|
+
/** Which side to place a new series of `unit` on — its `preferred` side if that's
|
|
25
|
+
* allowed, else the other allowed side, else `null` (incompatible). */
|
|
26
|
+
export function axisForAdd(members, unit, preferred) {
|
|
27
|
+
const allowed = allowedAxes(members, unit);
|
|
28
|
+
if (allowed.includes(preferred))
|
|
29
|
+
return preferred;
|
|
30
|
+
return allowed[0] ?? null;
|
|
31
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import type { InspectionEvent, Observer } from 'xstate';
|
|
3
|
+
import type { DeriveOp } from '@tidal-ts/core';
|
|
4
|
+
import type { AxisRange, PairLensOp, SeriesConfig } from '@tidal-ts/chart';
|
|
5
|
+
import { type MetricEntry, type PairLegInput, type PresetStorage, type RowState, type TerminalPreset } from './terminalMachine.js';
|
|
6
|
+
export interface TerminalProviderProps {
|
|
7
|
+
initialRows: RowState[];
|
|
8
|
+
catalog: readonly MetricEntry[];
|
|
9
|
+
storage: PresetStorage;
|
|
10
|
+
/** The colour KEYS the host offers a new series, in the order to hand them
|
|
11
|
+
* out (a split pair's second leg takes the first one its row is not using).
|
|
12
|
+
* A host's own vocabulary — palette names its chart resolves, or CSS colours.
|
|
13
|
+
* Omit to let a new leg keep its pair's colour. */
|
|
14
|
+
palette?: readonly string[];
|
|
15
|
+
/** An XState inspector (`@statelyai/inspect`'s `inspect`, or any observer of
|
|
16
|
+
* inspection events). The host decides whether and when to attach one; the
|
|
17
|
+
* machine has no opinion and no build-time flag. */
|
|
18
|
+
inspect?: Observer<InspectionEvent> | ((event: InspectionEvent) => void);
|
|
19
|
+
children: ReactNode;
|
|
20
|
+
}
|
|
21
|
+
export declare function TerminalProvider({ initialRows, catalog, storage, palette, inspect, children, }: TerminalProviderProps): import("react").JSX.Element;
|
|
22
|
+
export declare function useRows(): RowState[];
|
|
23
|
+
export declare function useSelectedSeries(): string | null;
|
|
24
|
+
/** The control-panel expansion (the row whose controls are open) — overrides the
|
|
25
|
+
* app selection for emphasis while set. Null when nothing is expanded. */
|
|
26
|
+
export declare function useExpandedSeries(): string | null;
|
|
27
|
+
export declare function useControlsOpen(): boolean;
|
|
28
|
+
/** Which preset slots hold a saved preset (length === PRESET_SLOTS). */
|
|
29
|
+
export declare function usePresetSaved(): boolean[];
|
|
30
|
+
/** The active slot — the saved slot whose rows deep-equal the live rows — or
|
|
31
|
+
* null (a custom state). Derived, not stored. */
|
|
32
|
+
export declare function useActiveSlot(): number | null;
|
|
33
|
+
/** Per-axis range state, keyed by axis id (`configAxisId`). No entry = an
|
|
34
|
+
* untouched auto axis; `mode:'auto'` with values = the preserved manual
|
|
35
|
+
* memory (see the machine's context doc). */
|
|
36
|
+
export declare function useAxisRanges(): Record<string, AxisRange>;
|
|
37
|
+
export declare function useAddSeries(): (catalogId: string, rowId?: string) => void;
|
|
38
|
+
/** Add a study (`sma`/`ema` …) of a target series, layered on its row. */
|
|
39
|
+
export declare function useAddStudy(): (targetId: string, op: DeriveOp, period: number) => void;
|
|
40
|
+
/** Add a pair (A vs B spread — diff/ratio/logRatio) of two metrics, on `rowId`
|
|
41
|
+
* when given (the per-row `+Pair`), else in front of leg A. */
|
|
42
|
+
export declare function useAddPair(): (a: PairLegInput, b: PairLegInput, op: PairLensOp, rowId?: string) => void;
|
|
43
|
+
/** The bar's bulk compare: pair every visible plain metric against the
|
|
44
|
+
* comparison, in one gesture. Offer it only when a comparison is named — the
|
|
45
|
+
* terminal machine cannot see whether one is. */
|
|
46
|
+
export declare function useCompareAll(): () => void;
|
|
47
|
+
export declare function useSetStudyParam(): (id: string, name: string, value: number) => void;
|
|
48
|
+
/** Step a series' draw order within its row (`front`/`up`/`down`/`back`; the
|
|
49
|
+
* list is front→back, so `up` moves toward the top of the canvas stack). */
|
|
50
|
+
export declare function useOrderSeries(): (id: string, to: 'front' | 'up' | 'down' | 'back') => void;
|
|
51
|
+
/** Drop a series at an absolute index in its row (the drag gesture's commit). */
|
|
52
|
+
export declare function useReindexSeries(): (id: string, index: number) => void;
|
|
53
|
+
/** Move a series (with any studies layered on it) to another row. */
|
|
54
|
+
export declare function useMoveSeriesToRow(): (id: string, rowId: string) => void;
|
|
55
|
+
/** Move one member onto another axis on its side (the panel's drag). */
|
|
56
|
+
export declare function useMoveToAxis(): (id: string, axisGroup?: string) => void;
|
|
57
|
+
export declare function useRemoveSeries(): (id: string) => void;
|
|
58
|
+
export declare function usePatchSeries(): (id: string, patch: Partial<SeriesConfig>) => void;
|
|
59
|
+
/** The PAIR's eye — hides both legs, each keeping its own state. */
|
|
60
|
+
export declare function useToggleGroupVisible(): (groupId: string) => void;
|
|
61
|
+
/** Remove a whole pair — both legs and anything layered on them. */
|
|
62
|
+
export declare function useRemoveGroup(): (groupId: string) => void;
|
|
63
|
+
export declare function useToggleVisible(): (id: string) => void;
|
|
64
|
+
export declare function useSelectSeries(): (id: string | null) => void;
|
|
65
|
+
/** Expand/collapse a control-panel row (null collapses). Distinct from `select`
|
|
66
|
+
* (the legend/app selection) — expansion is a temporary override. */
|
|
67
|
+
export declare function useExpandSeries(): (id: string | null) => void;
|
|
68
|
+
export declare function useSetControlsOpen(): (open: boolean) => void;
|
|
69
|
+
export declare function useSelectPreset(): (slot: number) => void;
|
|
70
|
+
export declare function useSavePreset(): (slot: number) => void;
|
|
71
|
+
export declare function useSetRowHeights(): (heights: Record<string, number>) => void;
|
|
72
|
+
/** Toggle a series' axis membership — the panel's chain icon (unlink to its own
|
|
73
|
+
* axis / unit-gated re-link into the side's shared axis; `linkToggleAllowed`
|
|
74
|
+
* is the shared gate the panel disables refused toggles with). */
|
|
75
|
+
export declare function useToggleAxisLink(): (id: string) => void;
|
|
76
|
+
/** Pin an axis to `[min, max]` (implies MANUAL). The caller seeds the values —
|
|
77
|
+
* the preserved memory when it exists, else the current auto fit — and names
|
|
78
|
+
* the unit the axis reads in (the pin suspends on a unit re-bind). */
|
|
79
|
+
export declare function useSetAxisRange(): (axisId: string, min: number, max: number, unit: string) => void;
|
|
80
|
+
/** Move a whole axis (every member) to the other side of its row — the
|
|
81
|
+
* panel's ⇄. `swapAllowed` is the shared gate the panel disables with. */
|
|
82
|
+
export declare function useSwapAxisSide(): (memberId: string) => void;
|
|
83
|
+
/** REPLACE an axis's hard bound locks (both fields are the new truth — an
|
|
84
|
+
* omitted one clears that lock). The host derives them; the machine stores. */
|
|
85
|
+
export declare function useSetAxisLocks(): (axisId: string, lockMin: number | undefined, lockMax: number | undefined, unit: string) => void;
|
|
86
|
+
/** The AUTO-mode options for an axis: the fit's basis and centre-zero. */
|
|
87
|
+
export declare function useSetAxisAutoOpts(): (axisId: string, autoBasis: 'metric' | 'viewport', centerZero: boolean, unit: string) => void;
|
|
88
|
+
/** The axis's tick precision (0-4, or undefined for the unit's default) and
|
|
89
|
+
* scale type. */
|
|
90
|
+
export declare function useSetAxisFormat(): (axisId: string, precision: number | undefined, scaleType: 'linear' | 'log', unit: string) => void;
|
|
91
|
+
/** Flip an axis back to AUTO, keeping its manual values as memory. */
|
|
92
|
+
export declare function useSetAxisAuto(): (axisId: string) => void;
|
|
93
|
+
/** Append an empty row (capped at `MAX_ROWS` by the machine's `canAddRow`). */
|
|
94
|
+
export declare function useAddRow(): () => void;
|
|
95
|
+
/** Remove a row by id (the machine keeps at least one). */
|
|
96
|
+
export declare function useRemoveRow(): (id: string) => void;
|
|
97
|
+
/**
|
|
98
|
+
* The 1–5 preset hotkey — opt-in (a library must not grab the host's keyboard
|
|
99
|
+
* uninvited; the host mounts this). Ignored while a form control is focused, and
|
|
100
|
+
* it never `preventDefault`s (digits carry no default outside a field).
|
|
101
|
+
*/
|
|
102
|
+
export declare function useTerminalHotkeys(): void;
|
|
103
|
+
export type { RowState, TerminalPreset, MetricEntry, PresetStorage };
|
package/dist/context.js
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useEffect } from 'react';
|
|
3
|
+
import { createActorContext } from '@xstate/react';
|
|
4
|
+
import { activeSlot, terminalMachine, } from './terminalMachine.js';
|
|
5
|
+
/**
|
|
6
|
+
* Private actor context — never exported. Public API is the named hooks below
|
|
7
|
+
* (the read-surface selectors + narrow command senders). The terminal module's
|
|
8
|
+
* barrel re-exports these + the event union; the actor + machine stay private.
|
|
9
|
+
*/
|
|
10
|
+
const TerminalContext = createActorContext(terminalMachine);
|
|
11
|
+
export function TerminalProvider({ initialRows, catalog, storage, palette, inspect, children, }) {
|
|
12
|
+
return (_jsxs(TerminalContext.Provider, { options: {
|
|
13
|
+
input: { initialRows, catalog, storage, ...(palette ? { palette } : {}) },
|
|
14
|
+
...(inspect ? { inspect } : {}),
|
|
15
|
+
}, children: [_jsx(PersistActive, { storage: storage }), children] }));
|
|
16
|
+
}
|
|
17
|
+
/** Persists the derived active-slot pointer so a fresh mount (a reload) can
|
|
18
|
+
* re-seed from the last applied preset (see `seedTerminalRows`). The machine
|
|
19
|
+
* owns preset *contents*; this is the only writer of the pointer. Renders
|
|
20
|
+
* nothing. */
|
|
21
|
+
function PersistActive({ storage }) {
|
|
22
|
+
const active = useActiveSlot();
|
|
23
|
+
useEffect(() => storage.saveActive(active), [active, storage]);
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
// --- Read surface ----------------------------------------------------------
|
|
27
|
+
export function useRows() {
|
|
28
|
+
return TerminalContext.useSelector((s) => s.context.rows);
|
|
29
|
+
}
|
|
30
|
+
export function useSelectedSeries() {
|
|
31
|
+
return TerminalContext.useSelector((s) => s.context.selected);
|
|
32
|
+
}
|
|
33
|
+
/** The control-panel expansion (the row whose controls are open) — overrides the
|
|
34
|
+
* app selection for emphasis while set. Null when nothing is expanded. */
|
|
35
|
+
export function useExpandedSeries() {
|
|
36
|
+
return TerminalContext.useSelector((s) => s.context.expanded);
|
|
37
|
+
}
|
|
38
|
+
export function useControlsOpen() {
|
|
39
|
+
return TerminalContext.useSelector((s) => s.context.controlsOpen);
|
|
40
|
+
}
|
|
41
|
+
/** Which preset slots hold a saved preset (length === PRESET_SLOTS). */
|
|
42
|
+
export function usePresetSaved() {
|
|
43
|
+
return TerminalContext.useSelector((s) => s.context.presets.map((p) => p != null));
|
|
44
|
+
}
|
|
45
|
+
/** The active slot — the saved slot whose rows deep-equal the live rows — or
|
|
46
|
+
* null (a custom state). Derived, not stored. */
|
|
47
|
+
export function useActiveSlot() {
|
|
48
|
+
return TerminalContext.useSelector((s) => activeSlot(s.context.presets, s.context.rows));
|
|
49
|
+
}
|
|
50
|
+
/** Per-axis range state, keyed by axis id (`configAxisId`). No entry = an
|
|
51
|
+
* untouched auto axis; `mode:'auto'` with values = the preserved manual
|
|
52
|
+
* memory (see the machine's context doc). */
|
|
53
|
+
export function useAxisRanges() {
|
|
54
|
+
return TerminalContext.useSelector((s) => s.context.axisRanges);
|
|
55
|
+
}
|
|
56
|
+
// --- Write surface (narrow commands) ---------------------------------------
|
|
57
|
+
export function useAddSeries() {
|
|
58
|
+
const ref = TerminalContext.useActorRef();
|
|
59
|
+
return useCallback((catalogId, rowId) => ref.send({ type: 'series.add', catalogId, rowId }), [ref]);
|
|
60
|
+
}
|
|
61
|
+
/** Add a study (`sma`/`ema` …) of a target series, layered on its row. */
|
|
62
|
+
export function useAddStudy() {
|
|
63
|
+
const ref = TerminalContext.useActorRef();
|
|
64
|
+
return useCallback((targetId, op, period) => ref.send({ type: 'series.addStudy', targetId, op, period }), [ref]);
|
|
65
|
+
}
|
|
66
|
+
/** Add a pair (A vs B spread — diff/ratio/logRatio) of two metrics, on `rowId`
|
|
67
|
+
* when given (the per-row `+Pair`), else in front of leg A. */
|
|
68
|
+
export function useAddPair() {
|
|
69
|
+
const ref = TerminalContext.useActorRef();
|
|
70
|
+
return useCallback((a, b, op, rowId) => ref.send({ type: 'series.addPair', a, b, op, rowId }), [ref]);
|
|
71
|
+
}
|
|
72
|
+
/** The bar's bulk compare: pair every visible plain metric against the
|
|
73
|
+
* comparison, in one gesture. Offer it only when a comparison is named — the
|
|
74
|
+
* terminal machine cannot see whether one is. */
|
|
75
|
+
export function useCompareAll() {
|
|
76
|
+
const ref = TerminalContext.useActorRef();
|
|
77
|
+
return useCallback(() => ref.send({ type: 'series.compareAll' }), [ref]);
|
|
78
|
+
}
|
|
79
|
+
export function useSetStudyParam() {
|
|
80
|
+
const ref = TerminalContext.useActorRef();
|
|
81
|
+
return useCallback((id, name, value) => ref.send({ type: 'series.setStudyParam', id, name, value }), [ref]);
|
|
82
|
+
}
|
|
83
|
+
/** Step a series' draw order within its row (`front`/`up`/`down`/`back`; the
|
|
84
|
+
* list is front→back, so `up` moves toward the top of the canvas stack). */
|
|
85
|
+
export function useOrderSeries() {
|
|
86
|
+
const ref = TerminalContext.useActorRef();
|
|
87
|
+
return useCallback((id, to) => ref.send({ type: 'series.order', id, to }), [ref]);
|
|
88
|
+
}
|
|
89
|
+
/** Drop a series at an absolute index in its row (the drag gesture's commit). */
|
|
90
|
+
export function useReindexSeries() {
|
|
91
|
+
const ref = TerminalContext.useActorRef();
|
|
92
|
+
return useCallback((id, index) => ref.send({ type: 'series.reindex', id, index }), [ref]);
|
|
93
|
+
}
|
|
94
|
+
/** Move a series (with any studies layered on it) to another row. */
|
|
95
|
+
export function useMoveSeriesToRow() {
|
|
96
|
+
const ref = TerminalContext.useActorRef();
|
|
97
|
+
return useCallback((id, rowId) => ref.send({ type: 'series.moveToRow', id, rowId }), [ref]);
|
|
98
|
+
}
|
|
99
|
+
/** Move one member onto another axis on its side (the panel's drag). */
|
|
100
|
+
export function useMoveToAxis() {
|
|
101
|
+
const ref = TerminalContext.useActorRef();
|
|
102
|
+
return useCallback((id, axisGroup) => ref.send({ type: 'axis.moveTo', id, axisGroup }), [ref]);
|
|
103
|
+
}
|
|
104
|
+
export function useRemoveSeries() {
|
|
105
|
+
const ref = TerminalContext.useActorRef();
|
|
106
|
+
return useCallback((id) => ref.send({ type: 'series.remove', id }), [ref]);
|
|
107
|
+
}
|
|
108
|
+
export function usePatchSeries() {
|
|
109
|
+
const ref = TerminalContext.useActorRef();
|
|
110
|
+
return useCallback((id, patch) => ref.send({ type: 'series.patch', id, patch }), [ref]);
|
|
111
|
+
}
|
|
112
|
+
/** The PAIR's eye — hides both legs, each keeping its own state. */
|
|
113
|
+
export function useToggleGroupVisible() {
|
|
114
|
+
const ref = TerminalContext.useActorRef();
|
|
115
|
+
return useCallback((groupId) => ref.send({ type: 'group.toggleVisible', groupId }), [ref]);
|
|
116
|
+
}
|
|
117
|
+
/** Remove a whole pair — both legs and anything layered on them. */
|
|
118
|
+
export function useRemoveGroup() {
|
|
119
|
+
const ref = TerminalContext.useActorRef();
|
|
120
|
+
return useCallback((groupId) => ref.send({ type: 'group.remove', groupId }), [ref]);
|
|
121
|
+
}
|
|
122
|
+
export function useToggleVisible() {
|
|
123
|
+
const ref = TerminalContext.useActorRef();
|
|
124
|
+
return useCallback((id) => ref.send({ type: 'series.toggleVisible', id }), [ref]);
|
|
125
|
+
}
|
|
126
|
+
export function useSelectSeries() {
|
|
127
|
+
const ref = TerminalContext.useActorRef();
|
|
128
|
+
return useCallback((id) => ref.send({ type: 'select', id }), [ref]);
|
|
129
|
+
}
|
|
130
|
+
/** Expand/collapse a control-panel row (null collapses). Distinct from `select`
|
|
131
|
+
* (the legend/app selection) — expansion is a temporary override. */
|
|
132
|
+
export function useExpandSeries() {
|
|
133
|
+
const ref = TerminalContext.useActorRef();
|
|
134
|
+
return useCallback((id) => ref.send({ type: 'expand', id }), [ref]);
|
|
135
|
+
}
|
|
136
|
+
export function useSetControlsOpen() {
|
|
137
|
+
const ref = TerminalContext.useActorRef();
|
|
138
|
+
return useCallback((open) => ref.send({ type: open ? 'controls.open' : 'controls.close' }), [ref]);
|
|
139
|
+
}
|
|
140
|
+
export function useSelectPreset() {
|
|
141
|
+
const ref = TerminalContext.useActorRef();
|
|
142
|
+
return useCallback((slot) => ref.send({ type: 'preset.select', slot }), [ref]);
|
|
143
|
+
}
|
|
144
|
+
export function useSavePreset() {
|
|
145
|
+
const ref = TerminalContext.useActorRef();
|
|
146
|
+
return useCallback((slot) => ref.send({ type: 'preset.save', slot }), [ref]);
|
|
147
|
+
}
|
|
148
|
+
export function useSetRowHeights() {
|
|
149
|
+
const ref = TerminalContext.useActorRef();
|
|
150
|
+
return useCallback((heights) => ref.send({ type: 'layout.setRowHeights', heights }), [ref]);
|
|
151
|
+
}
|
|
152
|
+
/** Toggle a series' axis membership — the panel's chain icon (unlink to its own
|
|
153
|
+
* axis / unit-gated re-link into the side's shared axis; `linkToggleAllowed`
|
|
154
|
+
* is the shared gate the panel disables refused toggles with). */
|
|
155
|
+
export function useToggleAxisLink() {
|
|
156
|
+
const ref = TerminalContext.useActorRef();
|
|
157
|
+
return useCallback((id) => ref.send({ type: 'axis.toggleLink', id }), [ref]);
|
|
158
|
+
}
|
|
159
|
+
/** Pin an axis to `[min, max]` (implies MANUAL). The caller seeds the values —
|
|
160
|
+
* the preserved memory when it exists, else the current auto fit — and names
|
|
161
|
+
* the unit the axis reads in (the pin suspends on a unit re-bind). */
|
|
162
|
+
export function useSetAxisRange() {
|
|
163
|
+
const ref = TerminalContext.useActorRef();
|
|
164
|
+
return useCallback((axisId, min, max, unit) => ref.send({ type: 'axis.setRange', axisId, min, max, unit }), [ref]);
|
|
165
|
+
}
|
|
166
|
+
/** Move a whole axis (every member) to the other side of its row — the
|
|
167
|
+
* panel's ⇄. `swapAllowed` is the shared gate the panel disables with. */
|
|
168
|
+
export function useSwapAxisSide() {
|
|
169
|
+
const ref = TerminalContext.useActorRef();
|
|
170
|
+
return useCallback((memberId) => ref.send({ type: 'axis.swapSide', memberId }), [ref]);
|
|
171
|
+
}
|
|
172
|
+
/** REPLACE an axis's hard bound locks (both fields are the new truth — an
|
|
173
|
+
* omitted one clears that lock). The host derives them; the machine stores. */
|
|
174
|
+
export function useSetAxisLocks() {
|
|
175
|
+
const ref = TerminalContext.useActorRef();
|
|
176
|
+
return useCallback((axisId, lockMin, lockMax, unit) => ref.send({ type: 'axis.setLocks', axisId, lockMin, lockMax, unit }), [ref]);
|
|
177
|
+
}
|
|
178
|
+
/** The AUTO-mode options for an axis: the fit's basis and centre-zero. */
|
|
179
|
+
export function useSetAxisAutoOpts() {
|
|
180
|
+
const ref = TerminalContext.useActorRef();
|
|
181
|
+
return useCallback((axisId, autoBasis, centerZero, unit) => ref.send({ type: 'axis.setAutoOpts', axisId, autoBasis, centerZero, unit }), [ref]);
|
|
182
|
+
}
|
|
183
|
+
/** The axis's tick precision (0-4, or undefined for the unit's default) and
|
|
184
|
+
* scale type. */
|
|
185
|
+
export function useSetAxisFormat() {
|
|
186
|
+
const ref = TerminalContext.useActorRef();
|
|
187
|
+
return useCallback((axisId, precision, scaleType, unit) => ref.send({ type: 'axis.setFormat', axisId, precision, scaleType, unit }), [ref]);
|
|
188
|
+
}
|
|
189
|
+
/** Flip an axis back to AUTO, keeping its manual values as memory. */
|
|
190
|
+
export function useSetAxisAuto() {
|
|
191
|
+
const ref = TerminalContext.useActorRef();
|
|
192
|
+
return useCallback((axisId) => ref.send({ type: 'axis.setAuto', axisId }), [ref]);
|
|
193
|
+
}
|
|
194
|
+
/** Append an empty row (capped at `MAX_ROWS` by the machine's `canAddRow`). */
|
|
195
|
+
export function useAddRow() {
|
|
196
|
+
const ref = TerminalContext.useActorRef();
|
|
197
|
+
return useCallback(() => ref.send({ type: 'row.add' }), [ref]);
|
|
198
|
+
}
|
|
199
|
+
/** Remove a row by id (the machine keeps at least one). */
|
|
200
|
+
export function useRemoveRow() {
|
|
201
|
+
const ref = TerminalContext.useActorRef();
|
|
202
|
+
return useCallback((id) => ref.send({ type: 'row.remove', id }), [ref]);
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* The 1–5 preset hotkey — opt-in (a library must not grab the host's keyboard
|
|
206
|
+
* uninvited; the host mounts this). Ignored while a form control is focused, and
|
|
207
|
+
* it never `preventDefault`s (digits carry no default outside a field).
|
|
208
|
+
*/
|
|
209
|
+
export function useTerminalHotkeys() {
|
|
210
|
+
const ref = TerminalContext.useActorRef();
|
|
211
|
+
useEffect(() => {
|
|
212
|
+
const onKey = (e) => {
|
|
213
|
+
if (e.metaKey || e.ctrlKey || e.altKey)
|
|
214
|
+
return;
|
|
215
|
+
const t = e.target;
|
|
216
|
+
if (t &&
|
|
217
|
+
(t.tagName === 'INPUT' ||
|
|
218
|
+
t.tagName === 'TEXTAREA' ||
|
|
219
|
+
t.tagName === 'SELECT' ||
|
|
220
|
+
t.isContentEditable))
|
|
221
|
+
return;
|
|
222
|
+
const n = Number(e.key);
|
|
223
|
+
if (Number.isInteger(n) && n >= 1 && n <= 5)
|
|
224
|
+
ref.send({ type: 'preset.select', slot: n - 1 });
|
|
225
|
+
};
|
|
226
|
+
window.addEventListener('keydown', onKey);
|
|
227
|
+
return () => window.removeEventListener('keydown', onKey);
|
|
228
|
+
}, [ref]);
|
|
229
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The terminal module barrel — the extraction candidate's public API. Exports
|
|
3
|
+
* the **provider** + **hooks** (read selectors + narrow command senders), the
|
|
4
|
+
* public **types** (rows / preset / catalog-entry / storage), and the event
|
|
5
|
+
* union — the pre-paid bus contract. The actor context + machine internals stay
|
|
6
|
+
* private to the module.
|
|
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';
|
|
9
|
+
export { PRESET_SLOTS, MAX_ROWS, activeSlot, canonRows, columnLabel, columnUnits, entryColumn, groupMembers, mintId, axisMoveAllowed, linkToggleAllowed, respecAllowed, studyChainTail, studyOfferable, SOURCE_COLUMNS, swapAllowed, type EditScope, type RowState, type TerminalPreset, type MetricEntry, type PairLegInput, type PresetStorage, type TerminalEvent, type TerminalInput, } from './terminalMachine.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The terminal module barrel — the extraction candidate's public API. Exports
|
|
3
|
+
* the **provider** + **hooks** (read selectors + narrow command senders), the
|
|
4
|
+
* public **types** (rows / preset / catalog-entry / storage), and the event
|
|
5
|
+
* union — the pre-paid bus contract. The actor context + machine internals stay
|
|
6
|
+
* private to the module.
|
|
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';
|
|
9
|
+
export { PRESET_SLOTS, MAX_ROWS, activeSlot, canonRows, columnLabel, columnUnits, entryColumn, groupMembers, mintId, axisMoveAllowed, linkToggleAllowed, respecAllowed, studyChainTail, studyOfferable, SOURCE_COLUMNS, swapAllowed, } from './terminalMachine.js';
|