react-klinecharts-ui 0.4.0 → 0.6.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/index.d.cts CHANGED
@@ -1,14 +1,79 @@
1
1
  import * as react from 'react';
2
2
  import { Dispatch, RefObject, ReactNode, ReactElement } from 'react';
3
- import { Period, SymbolInfo, KLineData, Chart, DeepPartial, Styles, OverlayTemplate, YAxisOverride, DataLoader, IndicatorTemplate } from 'react-klinecharts';
4
- import { OrderLineExtendData } from './extensions.cjs';
5
- export { DepthOverlayExtendData, DepthOverlayRow, OrderLineFontStyle, OrderLineLabelStyle, OrderLineLineStyle, OrderLineMarkStyle, OrderLinePadding, depthOverlay, indicators, orderLine, overlays, registerExtensions } from './extensions.cjs';
3
+ import { Period, SymbolInfo, KLineData, Chart, DeepPartial, Styles, OverlayTemplate, YAxisOverride, HotkeyTemplate, Hotkey, XAxisOverride, DataLoader, IndicatorTemplate } from 'react-klinecharts';
4
+ export { Hotkey, HotkeyActionParams, HotkeyTemplate, XAxisOverride, YAxisOverride } from 'react-klinecharts';
5
+ import { AlertLineExtendData, OrderLineExtendData } from './extensions.cjs';
6
+ export { DepthOverlayExtendData, DepthOverlayRow, OrderLineFontStyle, OrderLineLabelStyle, OrderLineLineStyle, OrderLineMarkStyle, OrderLinePadding, alertLine, depthOverlay, indicators, orderLine, overlays, registerExtensions } from './extensions.cjs';
6
7
 
7
8
  interface TerminalPeriod extends Period {
8
9
  label: string;
9
10
  }
10
11
  declare const DEFAULT_PERIODS: TerminalPeriod[];
11
12
 
13
+ /**
14
+ * Shared domain types for stateful feature hooks (`useAlerts`, `useMeasure`,
15
+ * `useReplay`).
16
+ *
17
+ * These live in a neutral module so they can be referenced both by the
18
+ * provider store (`KlinechartsUIState` / actions in `./types`) and by the
19
+ * hooks, without creating a circular import between the two. The hooks
20
+ * re-export them so the public API surface (consumed via the package root)
21
+ * stays unchanged.
22
+ */
23
+
24
+ type AlertCondition = "crossing_up" | "crossing_down" | "crossing";
25
+ interface Alert {
26
+ id: string;
27
+ price: number;
28
+ condition: AlertCondition;
29
+ message?: string;
30
+ triggered: boolean;
31
+ /**
32
+ * Visual style for the alert line overlay (color, label text, line/mark
33
+ * styling, bell marker). Persisted in the store so it survives undo/redo
34
+ * and layout presets.
35
+ */
36
+ extendData?: AlertLineExtendData;
37
+ }
38
+ interface MeasurePoint {
39
+ price: number;
40
+ timestamp: number;
41
+ barIndex: number;
42
+ }
43
+ interface MeasureResult {
44
+ from: MeasurePoint;
45
+ to: MeasurePoint;
46
+ /** Absolute price difference */
47
+ priceDiff: number;
48
+ /** Percentage change from → to */
49
+ pricePercent: number;
50
+ /** Number of bars between the two points */
51
+ bars: number;
52
+ /** Time difference in milliseconds */
53
+ timeDiff: number;
54
+ }
55
+ interface MeasureState {
56
+ /** Whether measure mode is active (waiting for clicks) */
57
+ isActive: boolean;
58
+ /** First point (set after first click) */
59
+ fromPoint: MeasurePoint | null;
60
+ /** Current measurement result (null until both points are set) */
61
+ result: MeasureResult | null;
62
+ }
63
+ type ReplaySpeed = 1 | 2 | 5 | 10;
64
+ interface ReplayState {
65
+ /** Whether a replay session is active */
66
+ isReplaying: boolean;
67
+ /** Whether the replay is currently paused */
68
+ isPaused: boolean;
69
+ /** Current playback speed multiplier */
70
+ speed: ReplaySpeed;
71
+ /** Current bar index in the replay */
72
+ barIndex: number;
73
+ /** Total number of bars in the saved data */
74
+ totalBars: number;
75
+ }
76
+
12
77
  /**
13
78
  * Explicit partial symbol type — avoids `PickPartial<SymbolInfo, ...>` which
14
79
  * degenerates when SymbolInfo has an index signature `[key: string]: unknown`.
@@ -74,6 +139,37 @@ interface KlinechartsUIState {
74
139
  * undo/redo and layout presets.
75
140
  */
76
141
  indicatorAxes: Record<string, string>;
142
+ /**
143
+ * Visibility overrides for indicators, keyed by indicator id
144
+ * (`main_<name>` / `sub_<name>`), value is whether the indicator is shown.
145
+ * Mirrors the `visible` flag held inside klinecharts so `useIndicators` can
146
+ * expose a reactive getter (the chart instance has no React-friendly read
147
+ * path). Only populated for indicators whose visibility has been toggled
148
+ * away from the default; an absent key means visible (`true`). Updated by
149
+ * `setIndicatorVisible` and the collapse/expand helpers, and rebuilt when a
150
+ * layout preset is restored so the mirror never drifts from the chart.
151
+ */
152
+ indicatorVisibility: Record<string, boolean>;
153
+ /**
154
+ * Price alerts (`useAlerts`). Lives in the shared store rather than per-hook
155
+ * local state so every consumer (toolbar, list panel, status bar, sound
156
+ * trigger) observes one synchronized list. The crossing poller and the
157
+ * `onAlertTriggered` listener are owned by the provider, not the hook.
158
+ */
159
+ alerts: Alert[];
160
+ /**
161
+ * Measure-tool state (`useMeasure`). Shared so the toolbar toggle and the
162
+ * result readout panel stay in sync regardless of where each is mounted.
163
+ */
164
+ measure: MeasureState;
165
+ /**
166
+ * Historical-replay control state (`useReplay`). Shared so play/pause/step
167
+ * controls in different components drive one session. The playback interval
168
+ * and data buffers are owned by the provider (see the `replay*Ref` fields on
169
+ * the dispatch value), guaranteeing a single timer no matter how many hook
170
+ * instances are mounted.
171
+ */
172
+ replay: ReplayState;
77
173
  styles: DeepPartial<Styles> | undefined;
78
174
  screenshotUrl: string | null;
79
175
  }
@@ -104,6 +200,18 @@ type KlinechartsUIAction = {
104
200
  } | {
105
201
  type: "SET_INDICATOR_AXES";
106
202
  axes: Record<string, string>;
203
+ } | {
204
+ type: "SET_INDICATOR_VISIBILITY";
205
+ visibility: Record<string, boolean>;
206
+ } | {
207
+ type: "SET_ALERTS";
208
+ alerts: Alert[];
209
+ } | {
210
+ type: "SET_MEASURE";
211
+ measure: Partial<MeasureState>;
212
+ } | {
213
+ type: "SET_REPLAY";
214
+ replay: Partial<ReplayState>;
107
215
  } | {
108
216
  type: "SET_STYLES";
109
217
  styles: DeepPartial<Styles> | undefined;
@@ -127,6 +235,20 @@ interface KlinechartsUIDispatchValue {
127
235
  fullscreenContainerRef: RefObject<HTMLElement | null>;
128
236
  /** Ref populated by useUndoRedo; other hooks call it to record actions. */
129
237
  undoRedoListenerRef: RefObject<UndoRedoListener | null>;
238
+ /**
239
+ * Listener set by `useAlerts.onAlertTriggered`; invoked by the provider-owned
240
+ * crossing poller when an alert fires. Last writer wins (one active listener).
241
+ */
242
+ alertTriggeredListenerRef: RefObject<((alert: Alert) => void) | null>;
243
+ /**
244
+ * Provider-owned replay resources, shared across every `useReplay` instance
245
+ * so there is exactly one playback timer and one data buffer. The hook reads
246
+ * and writes these instead of its own refs; the provider clears the interval
247
+ * on unmount.
248
+ */
249
+ replayIntervalRef: RefObject<ReturnType<typeof setInterval> | null>;
250
+ replaySavedDataRef: RefObject<KLineData[]>;
251
+ replayIndexRef: RefObject<number>;
130
252
  }
131
253
  /** Combined context value returned by `useKlinechartsUI()`. */
132
254
  interface KlinechartsUIContextValue extends KlinechartsUIDispatchValue {
@@ -187,6 +309,13 @@ declare function useSymbolSearch(debounceMs?: number): UseSymbolSearchReturn;
187
309
  interface IndicatorInfo {
188
310
  name: string;
189
311
  isActive: boolean;
312
+ /**
313
+ * Whether the indicator is currently visible on the chart. Defaults to
314
+ * `true`; only `false` after the indicator has been hidden via
315
+ * `setIndicatorVisible` or `collapseSubIndicator`. Meaningful only when
316
+ * `isActive` is `true` (inactive indicators are always reported `true`).
317
+ */
318
+ visible: boolean;
190
319
  }
191
320
  /** Options accepted when adding an indicator. */
192
321
  interface AddIndicatorOptions {
@@ -214,6 +343,13 @@ interface UseIndicatorsReturn {
214
343
  moveToMain: (name: string) => void;
215
344
  moveToSub: (name: string) => void;
216
345
  setIndicatorVisible: (name: string, isMain: boolean, visible: boolean) => void;
346
+ /**
347
+ * Read whether an indicator is currently visible. Returns `true` for the
348
+ * default (un-toggled) state and for inactive indicators. This is the
349
+ * reactive read counterpart to `setIndicatorVisible` — UI no longer needs to
350
+ * track visibility locally or reach into the chart instance.
351
+ */
352
+ isIndicatorVisible: (name: string, isMain: boolean) => boolean;
217
353
  updateIndicatorParams: (name: string, paneId: string, params: number[]) => void;
218
354
  getIndicatorParams: (name: string) => {
219
355
  label: string;
@@ -236,6 +372,13 @@ interface UseIndicatorsReturn {
236
372
  indicatorAxes: Record<string, string>;
237
373
  /** Get the custom `yAxisId` an indicator is bound to, or `undefined` for the default axis. */
238
374
  getIndicatorAxis: (name: string, isMain: boolean) => string | undefined;
375
+ /**
376
+ * Visibility overrides keyed by indicator id (`main_<name>` / `sub_<name>`).
377
+ * Only contains indicators hidden away from the default; an absent key means
378
+ * visible. Mirror of the provider state, exposed for layout-preset
379
+ * persistence and direct rendering.
380
+ */
381
+ indicatorVisibility: Record<string, boolean>;
239
382
  /**
240
383
  * Rebind an existing indicator to a different Y-axis. Because klinecharts v10
241
384
  * `overrideIndicator` cannot change axis binding, this removes and recreates
@@ -373,6 +516,58 @@ interface UseScreenshotReturn {
373
516
  }
374
517
  declare function useScreenshot(): UseScreenshotReturn;
375
518
 
519
+ interface UseHotkeysReturn {
520
+ /**
521
+ * Register a custom hotkey globally. Idempotent per `template.name` — calling
522
+ * again with the same name replaces the previous handler. The `action`
523
+ * callback receives the chart instance, the keyboard event and the matched
524
+ * hotkey template (see klinecharts `HotkeyActionParams`).
525
+ */
526
+ registerHotkey: (template: HotkeyTemplate) => void;
527
+ /** Look up a registered hotkey template by name (built-in or custom). */
528
+ getHotkey: (name: string) => HotkeyTemplate | null;
529
+ /** Names of every registered hotkey (built-in + custom). */
530
+ supportedHotkeys: string[];
531
+ /**
532
+ * Enable or disable hotkey handling for the current chart. Pass `exclude`
533
+ * to keep hotkeys on but silence specific ones by name.
534
+ */
535
+ setHotkeysEnabled: (enabled: boolean, exclude?: string[]) => void;
536
+ /** The current hotkey config (`{ enabled, exclude }`) for the chart, or null. */
537
+ getHotkeysConfig: () => Hotkey | null;
538
+ }
539
+ /**
540
+ * Headless hook for klinecharts v10 keyboard shortcuts (added in
541
+ * klinecharts 10.0.0-beta3).
542
+ *
543
+ * Custom hotkeys are registered **globally** via klinecharts `registerHotkey`,
544
+ * so a shortcut defined here is shared by every chart in the page; the
545
+ * per-chart enable/exclude switches operate on the provider's chart instance.
546
+ */
547
+ declare function useHotkeys(): UseHotkeysReturn;
548
+
549
+ interface UseChartAxesReturn {
550
+ /**
551
+ * Override the main pane's X (time) axis — e.g. `scrollZoomEnabled`,
552
+ * `name`, or a custom `createTicks` generator. Added in klinecharts
553
+ * 10.0.0-beta2.
554
+ */
555
+ overrideXAxis: (override: XAxisOverride) => void;
556
+ /**
557
+ * Override a Y (value) axis — e.g. `reverse` to flip the price scale,
558
+ * `inside` to draw labels inside the pane, `position`, or a custom
559
+ * `createRange` / `createTicks`. Target a specific axis with `id` / `paneId`.
560
+ * Added in klinecharts 10.0.0-beta2.
561
+ */
562
+ overrideYAxis: (override: YAxisOverride) => void;
563
+ }
564
+ /**
565
+ * Headless hook for overriding the chart's built-in X / Y axes (klinecharts
566
+ * v10 `overrideXAxis` / `overrideYAxis`). For binding indicators to additional
567
+ * secondary Y-axes, use {@link useIndicators} instead.
568
+ */
569
+ declare function useChartAxes(): UseChartAxesReturn;
570
+
376
571
  interface UseFullscreenReturn {
377
572
  isFullscreen: boolean;
378
573
  toggle: () => void;
@@ -561,21 +756,22 @@ interface UseCrosshairReturn {
561
756
  }
562
757
  declare function useCrosshair(): UseCrosshairReturn;
563
758
 
564
- type AlertCondition = "crossing_up" | "crossing_down" | "crossing";
565
- interface Alert {
566
- id: string;
567
- price: number;
568
- condition: AlertCondition;
569
- message?: string;
570
- triggered: boolean;
571
- }
572
759
  interface UseAlertsReturn {
573
760
  alerts: Alert[];
574
- addAlert: (price: number, condition: AlertCondition, message?: string) => string;
761
+ addAlert: (price: number, condition: AlertCondition, message?: string, extendData?: AlertLineExtendData) => string;
575
762
  removeAlert: (id: string) => void;
576
763
  clearAlerts: () => void;
577
764
  onAlertTriggered: (callback: (alert: Alert) => void) => void;
578
765
  }
766
+ /**
767
+ * Headless hook for price-crossing alerts.
768
+ *
769
+ * The alert list lives in the shared provider store, and the 1s crossing
770
+ * poller + the `onAlertTriggered` listener are owned by the provider. This
771
+ * means several `useAlerts()` instances (toolbar, list panel, sound trigger)
772
+ * observe and mutate one synchronized list and share a single poller — they no
773
+ * longer drift apart or each spawn their own interval.
774
+ */
579
775
  declare function useAlerts(): UseAlertsReturn;
580
776
 
581
777
  type ExportFormat = "csv" | "json";
@@ -602,7 +798,6 @@ interface UseWatchlistReturn {
602
798
  }
603
799
  declare function useWatchlist(): UseWatchlistReturn;
604
800
 
605
- type ReplaySpeed = 1 | 2 | 5 | 10;
606
801
  interface UseReplayReturn {
607
802
  /** Whether a replay session is active */
608
803
  isReplaying: boolean;
@@ -633,8 +828,13 @@ interface UseReplayReturn {
633
828
  * Headless hook for historical data replay (bar-by-bar playback).
634
829
  *
635
830
  * Loads the current chart data, clears the chart, then progressively adds
636
- * bars back one at a time at the configured speed. Useful for backtesting
637
- * and reviewing price action.
831
+ * bars back one at a time at the configured speed.
832
+ *
833
+ * Replay control state lives in the shared provider store and the playback
834
+ * interval + data buffers are owned by the provider (accessed through stable
835
+ * refs). This guarantees a single playback session even when `useReplay()` is
836
+ * mounted in several components (e.g. toolbar + bottom controls + status bar):
837
+ * starting in one and stepping in another drives the same timer and buffer.
638
838
  */
639
839
  declare function useReplay(): UseReplayReturn;
640
840
 
@@ -666,23 +866,6 @@ interface UseCompareReturn {
666
866
  */
667
867
  declare function useCompare(): UseCompareReturn;
668
868
 
669
- interface MeasurePoint {
670
- price: number;
671
- timestamp: number;
672
- barIndex: number;
673
- }
674
- interface MeasureResult {
675
- from: MeasurePoint;
676
- to: MeasurePoint;
677
- /** Absolute price difference */
678
- priceDiff: number;
679
- /** Percentage change from → to */
680
- pricePercent: number;
681
- /** Number of bars between the two points */
682
- bars: number;
683
- /** Time difference in milliseconds */
684
- timeDiff: number;
685
- }
686
869
  interface UseMeasureReturn {
687
870
  /** Whether measure mode is active (waiting for clicks) */
688
871
  isActive: boolean;
@@ -701,7 +884,10 @@ interface UseMeasureReturn {
701
884
  * Headless hook for measuring distance/time/percentage between two points.
702
885
  *
703
886
  * Activates measure mode, captures two clicks on the chart via overlay
704
- * interaction, then computes price diff, %, bar count, and time diff.
887
+ * interaction, then computes price diff, %, bar count, and time diff. The
888
+ * measure state (active/from/result) lives in the shared provider store, so a
889
+ * toolbar toggle and a separate result-readout panel stay in sync no matter
890
+ * where each is mounted.
705
891
  */
706
892
  declare function useMeasure(): UseMeasureReturn;
707
893
 
@@ -900,4 +1086,4 @@ declare const superTrend: IndicatorTemplate;
900
1086
 
901
1087
  declare const vwap: IndicatorTemplate;
902
1088
 
903
- export { type AddIndicatorOptions, type Alert, type AlertCondition, type Annotation, CANDLE_TYPES, COMPARE_RULES, type CandleTypeItem, type CandleTypeOption, type ChartLayoutState, type CompareRule, type CompareSymbol, type CrosshairBarData, DEFAULT_PERIODS, DRAWING_CATEGORIES, type Datafeed, type DrawingCategoryItem, type DrawingTool, type DrawingToolCategory, type DrawingToolItem, type ExportFormat, INDICATOR_PARAMS, type IndicatorDefinition, type IndicatorInfo, type IndicatorParamConfig, type KlinechartsUIAction, type KlinechartsUIContextValue, KlinechartsUIDispatchContext, type KlinechartsUIDispatchValue, type KlinechartsUIOptions, KlinechartsUIProvider, type KlinechartsUISettingsState, type KlinechartsUIState, KlinechartsUIStateContext, type LayoutEntry, MAIN_INDICATORS, type MagnetMode, type MeasurePoint, type MeasureResult, OrderLineExtendData, type OrderLineOptions, PRICE_AXIS_TYPES, type PartialSymbolInfo, type PriceAxisType, type ReplaySpeed, SUB_INDICATORS, type ScriptPlacement, TA, TIMEZONES, TOOLTIP_SHOW_RULES, type TerminalPeriod, type TimezoneItem, type TimezoneOption, type TooltipShowRule, type UndoRedoAction, type UndoRedoActionType, type UseAlertsReturn, type UseAnnotationsReturn, type UseCompareReturn, type UseCrosshairReturn, type UseDataExportReturn, type UseDrawingToolsReturn, type UseFullscreenReturn, type UseIndicatorsReturn, type UseKlinechartsUILoadingReturn, type UseKlinechartsUISettingsReturn, type UseKlinechartsUIThemeReturn, type UseLayoutManagerReturn, type UseMeasureReturn, type UseOrderLinesReturn, type UsePeriodsReturn, type UseReplayReturn, type UseScreenshotReturn, type UseScriptEditorReturn, type UseSymbolSearchReturn, type UseTimezoneReturn, type UseUndoRedoReturn, type UseWatchlistReturn, type WatchlistItem, YAXIS_POSITIONS, type YAxisPosition, abcd, anyWaves, arrow, bollTv, brush, cci, circle, createDataLoader, eightWaves, elliottWave, fibRetracement, fibonacciCircle, fibonacciExtension, fibonacciSegment, fibonacciSpeedResistanceFan, fibonacciSpiral, fiveWaves, gannBox, gannFan, hma, ichimoku, longPosition, maRibbon, macdTv, measure, parallelChannel, parallelogram, pivotPoints, ray, rect, rsiTv, shortPosition, stochastic, superTrend, threeWaves, triangle, useAlerts, useAnnotations, useCompare, useCrosshair, useDataExport, useDrawingTools, useFullscreen, useIndicators, useKlinechartsUI, useKlinechartsUILoading, useKlinechartsUISettings, useKlinechartsUITheme, useLayoutManager, useMeasure, useOrderLines, usePeriods, useReplay, useScreenshot, useScriptEditor, useSymbolSearch, useTimezone, useUndoRedo, useWatchlist, vwap, xabcd };
1089
+ export { type AddIndicatorOptions, type Alert, type AlertCondition, AlertLineExtendData, type Annotation, CANDLE_TYPES, COMPARE_RULES, type CandleTypeItem, type CandleTypeOption, type ChartLayoutState, type CompareRule, type CompareSymbol, type CrosshairBarData, DEFAULT_PERIODS, DRAWING_CATEGORIES, type Datafeed, type DrawingCategoryItem, type DrawingTool, type DrawingToolCategory, type DrawingToolItem, type ExportFormat, INDICATOR_PARAMS, type IndicatorDefinition, type IndicatorInfo, type IndicatorParamConfig, type KlinechartsUIAction, type KlinechartsUIContextValue, KlinechartsUIDispatchContext, type KlinechartsUIDispatchValue, type KlinechartsUIOptions, KlinechartsUIProvider, type KlinechartsUISettingsState, type KlinechartsUIState, KlinechartsUIStateContext, type LayoutEntry, MAIN_INDICATORS, type MagnetMode, type MeasurePoint, type MeasureResult, OrderLineExtendData, type OrderLineOptions, PRICE_AXIS_TYPES, type PartialSymbolInfo, type PriceAxisType, type ReplaySpeed, SUB_INDICATORS, type ScriptPlacement, TA, TIMEZONES, TOOLTIP_SHOW_RULES, type TerminalPeriod, type TimezoneItem, type TimezoneOption, type TooltipShowRule, type UndoRedoAction, type UndoRedoActionType, type UseAlertsReturn, type UseAnnotationsReturn, type UseChartAxesReturn, type UseCompareReturn, type UseCrosshairReturn, type UseDataExportReturn, type UseDrawingToolsReturn, type UseFullscreenReturn, type UseHotkeysReturn, type UseIndicatorsReturn, type UseKlinechartsUILoadingReturn, type UseKlinechartsUISettingsReturn, type UseKlinechartsUIThemeReturn, type UseLayoutManagerReturn, type UseMeasureReturn, type UseOrderLinesReturn, type UsePeriodsReturn, type UseReplayReturn, type UseScreenshotReturn, type UseScriptEditorReturn, type UseSymbolSearchReturn, type UseTimezoneReturn, type UseUndoRedoReturn, type UseWatchlistReturn, type WatchlistItem, YAXIS_POSITIONS, type YAxisPosition, abcd, anyWaves, arrow, bollTv, brush, cci, circle, createDataLoader, eightWaves, elliottWave, fibRetracement, fibonacciCircle, fibonacciExtension, fibonacciSegment, fibonacciSpeedResistanceFan, fibonacciSpiral, fiveWaves, gannBox, gannFan, hma, ichimoku, longPosition, maRibbon, macdTv, measure, parallelChannel, parallelogram, pivotPoints, ray, rect, rsiTv, shortPosition, stochastic, superTrend, threeWaves, triangle, useAlerts, useAnnotations, useChartAxes, useCompare, useCrosshair, useDataExport, useDrawingTools, useFullscreen, useHotkeys, useIndicators, useKlinechartsUI, useKlinechartsUILoading, useKlinechartsUISettings, useKlinechartsUITheme, useLayoutManager, useMeasure, useOrderLines, usePeriods, useReplay, useScreenshot, useScriptEditor, useSymbolSearch, useTimezone, useUndoRedo, useWatchlist, vwap, xabcd };