@forgecharts/sdk 1.1.23 → 1.1.27

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.
@@ -0,0 +1,76 @@
1
+ import { useState, useEffect, useMemo } from 'react';
2
+ import { LicenseManager, getCapabilities } from '../../';
3
+ import type { ChartCapabilities } from '../../';
4
+ import type { ChartRuntimeConfig } from '@forgecharts/types';
5
+
6
+ /**
7
+ * Merges license-derived capabilities with optional host config overrides.
8
+ *
9
+ * A config flag explicitly set to `false` suppresses the feature even when
10
+ * the license permits it. Omitting a field defers to the license.
11
+ * Derived render flags are recalculated from the updated feature flags so
12
+ * component-level gates remain consistent.
13
+ */
14
+ function applyRuntimeConfig(
15
+ caps: ChartCapabilities,
16
+ config: ChartRuntimeConfig | undefined,
17
+ ): ChartCapabilities {
18
+ if (!config) return caps;
19
+
20
+ const orderEntry = config.enableOrderEntry === false ? false : caps.orderEntry;
21
+ const draggableOrders = config.enableDraggableOrders === false ? false : caps.draggableOrders;
22
+ const bracketOrders = config.enableBracketOrders === false ? false : caps.bracketOrders;
23
+ const managedTrading = config.enableManagedTrading === false ? false : caps.managedTrading;
24
+ const indicators = config.enableIndicators === false ? false : caps.indicators;
25
+
26
+ return {
27
+ ...caps,
28
+ orderEntry,
29
+ draggableOrders,
30
+ bracketOrders,
31
+ managedTrading,
32
+ indicators,
33
+ // Recalculate derived render flags from the updated feature flags.
34
+ renderOrderEntry: orderEntry,
35
+ renderBuySellButtons: orderEntry,
36
+ renderOrderTicket: orderEntry,
37
+ renderBracketControls: orderEntry && bracketOrders,
38
+ renderOrderModificationControls: orderEntry && draggableOrders,
39
+ renderManagedTradingControls: managedTrading,
40
+ renderIndicators: indicators,
41
+ };
42
+ }
43
+
44
+ /**
45
+ * useChartCapabilities
46
+ *
47
+ * Returns the current chart capability set derived from two independent layers
48
+ * (both must allow a feature for it to be considered active):
49
+ * 1. **License entitlement** — from the loaded `LicensePayload` via `LicenseManager`.
50
+ * 2. **Host runtime config** — optional `ChartRuntimeConfig` passed by the consumer.
51
+ *
52
+ * The hook re-evaluates whenever the license changes and whenever the
53
+ * `config` reference changes (use a stable/memoised object to avoid unnecessary
54
+ * re-renders).
55
+ *
56
+ * Usage:
57
+ * const caps = useChartCapabilities();
58
+ * const caps = useChartCapabilities({ enableOrderEntry: false }); // suppress order entry
59
+ * if (caps.renderOrderEntry) { ... }
60
+ */
61
+ export function useChartCapabilities(config?: ChartRuntimeConfig): ChartCapabilities {
62
+ const [licCaps, setLicCaps] = useState<ChartCapabilities>(() => getCapabilities());
63
+
64
+ useEffect(() => {
65
+ // Subscribe to license changes via LicenseManager only.
66
+ // Cross-tab StorageEvent sync is intentionally omitted — that coupling
67
+ // belongs at the app shell layer (ManagedAppShell reloads on auth change).
68
+ const unsub = LicenseManager.getInstance().subscribe(() => {
69
+ setLicCaps(getCapabilities());
70
+ });
71
+ return unsub;
72
+ }, []);
73
+
74
+ return useMemo(() => applyRuntimeConfig(licCaps, config), [licCaps, config]);
75
+ }
76
+
@@ -0,0 +1,51 @@
1
+ /**
2
+ * @forgecharts/sdk/react — Public React embed API
3
+ *
4
+ * Supported external integration surfaces:
5
+ *
6
+ * ChartCanvas — embed a single chart pane with full tool/indicator support
7
+ * ChartWorkspace — embed the full multi-tab workspace UI (toolbars included)
8
+ *
9
+ * For Unmanaged host integration, use ChartCanvas or ChartWorkspace.
10
+ * For trading intents, wire TradingBridgeCallbacks.
11
+ *
12
+ * The following are intentionally NOT part of the public API:
13
+ * - ManagedAppShell (ForgeCharts Managed product shell — apps/frontend only)
14
+ * - Internal sub-components (LayoutMenu, IndicatorPane, toolbars, …)
15
+ * - MultiPaneChart (internal rendering layer beneath ChartCanvas)
16
+ *
17
+ * Import from @forgecharts/chart-components/internal for app-layer-only symbols.
18
+ *
19
+ * @semver BREAKING changes are communicated via package.json major version bumps.
20
+ */
21
+
22
+ // ─── Canvas layer (primary single-pane embed API) ────────────────────────────
23
+ export { ChartCanvas } from './canvas/ChartCanvas';
24
+ export type { ChartCanvasHandle, ChartCanvasProps } from './canvas/ChartCanvas';
25
+
26
+ // ─── Workspace layer (full workspace embed API) ───────────────────────────────
27
+ export { ChartWorkspace } from './workspace/ChartWorkspace';
28
+ export type { ChartWorkspaceProps, TabItem, TradingSession } from './workspace/ChartWorkspace';
29
+
30
+ // ─── Capability hook (useful for custom shells and conditional UI) ────────────
31
+ export { useChartCapabilities } from './hooks/useChartCapabilities';
32
+
33
+ // ─── Trading bridge (Unmanaged host order intents) ────────────────────────────
34
+ export type { TradingBridgeCallbacks } from './trading/TradingBridge';
35
+ export { createTradingBridgeLogger } from './trading/TradingBridge';
36
+
37
+ // ─── Types re-exported for consumer convenience ───────────────────────────────
38
+ // Symbol resolver interface — implement this in your host to power symbol search.
39
+ export type { ISymbolResolver, ChartRuntimeConfig } from '@forgecharts/types';
40
+
41
+ // Trading intent contract — fired by the chart, confirmed by host via TradingOverlayStore.
42
+ export type {
43
+ PlaceOrderIntent,
44
+ ModifyOrderIntent,
45
+ CancelOrderIntent,
46
+ BracketAdjustIntent,
47
+ TradingIntent,
48
+ TradingIntentSide,
49
+ TradingIntentOrderType,
50
+ } from '@forgecharts/types';
51
+
@@ -0,0 +1,62 @@
1
+ /**
2
+ * @forgecharts/sdk/react/internal
3
+ *
4
+ * Internal export surface — for use by the ForgeCharts Managed app layer ONLY.
5
+ * Do NOT import from this path in unmanaged host applications or external integrations.
6
+ * The semver stability guarantee of `@forgecharts/sdk/react` does NOT apply
7
+ * to symbols exported from this path.
8
+ *
9
+ * Direct internal consumers: apps/frontend
10
+ *
11
+ * Why this exists: ManagedAppShell is the ForgeCharts Managed product shell. It carries
12
+ * all Managed-mode state (layouts, preferences, workspace tabs, script drawer, watchlist,
13
+ * trade drawer). External hosts MUST NOT rely on it — they should compose ChartWorkspace
14
+ * or ChartCanvas directly with their own state management.
15
+ */
16
+
17
+ // Re-export the full public API so an import from this path is a strict superset.
18
+ export * from './index';
19
+
20
+ // ─── Managed app shell ────────────────────────────────────────────────────────
21
+ // Internal only: ForgeCharts Managed product shell (apps/frontend).
22
+ // Hosts building Unmanaged integrations must NOT use this.
23
+ export { ManagedAppShell } from './shell/ManagedAppShell';
24
+ export type {
25
+ ManagedAppShellProps,
26
+ ManagedAppShellHandle,
27
+ LayoutsAPI,
28
+ PreferencesAPI,
29
+ } from './shell/ManagedAppShell';
30
+
31
+ // ─── Internal workspace sub-components ───────────────────────────────────────
32
+ // Implementation details of ManagedAppShell / ChartWorkspace.
33
+ // Not part of the public embed contract.
34
+ export { LayoutMenu } from './workspace/LayoutMenu';
35
+ export type { LayoutRecord } from './workspace/LayoutMenu';
36
+
37
+ export { TabBar } from './workspace/TabBar';
38
+ export type { TabItem as TabBarItem } from './workspace/TabBar';
39
+
40
+ export { FloatingPanel } from './workspace/FloatingPanel';
41
+ export { SymbolSearchDialog } from './workspace/SymbolSearchDialog';
42
+ export { IndicatorsDialog } from './workspace/IndicatorsDialog';
43
+
44
+ export { TopToolbar, DEFAULT_FAVORITES } from './workspace/toolbars/TopToolbar';
45
+ export { RightToolbar } from './workspace/toolbars/RightToolbar';
46
+ export { BottomToolbar } from './workspace/toolbars/BottomToolbar';
47
+
48
+ // ─── Internal canvas sub-components ──────────────────────────────────────────
49
+ // Used inside ChartCanvas / ChartWorkspace — not for external composition.
50
+ export { IndicatorPane } from './canvas/IndicatorPane';
51
+ export { IndicatorLabel } from './canvas/IndicatorLabel';
52
+ export { ChartContextMenu } from './canvas/ChartContextMenu';
53
+ export { ChartSettingsDialog } from './canvas/ChartSettingsDialog';
54
+ export { PointerOverlay } from './canvas/PointerOverlay';
55
+
56
+ export { LeftToolbar } from './canvas/toolbars/LeftToolbar';
57
+ export type { VisibilityAction } from './canvas/toolbars/LeftToolbar';
58
+
59
+ // MultiPaneChart is the native multi-pane rendering component underlying ChartCanvas.
60
+ // It is available here for advanced internal scenarios only.
61
+ export { MultiPaneChart } from './canvas/ChartCanvas';
62
+ export type { MultiPaneChartHandle, MultiPaneChartProps } from './canvas/ChartCanvas';