@forgecharts/sdk 1.3.10 → 1.3.11

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.
@@ -29889,89 +29889,6 @@ var watchlistApi = {
29889
29889
  return apiFetch("PUT", "/watchlist/items/reorder", { ids });
29890
29890
  }
29891
29891
  };
29892
- var LOCAL_KEY = "forgecharts:watchlist";
29893
- function _localRead() {
29894
- try {
29895
- const raw = typeof localStorage !== "undefined" ? localStorage.getItem(LOCAL_KEY) : null;
29896
- if (raw) {
29897
- const parsed = JSON.parse(raw);
29898
- if (Array.isArray(parsed.groups) && Array.isArray(parsed.items)) return parsed;
29899
- }
29900
- } catch {
29901
- }
29902
- return { groups: [], items: [] };
29903
- }
29904
- function _localWrite(data) {
29905
- try {
29906
- if (typeof localStorage !== "undefined") localStorage.setItem(LOCAL_KEY, JSON.stringify(data));
29907
- } catch {
29908
- }
29909
- }
29910
- function _localId() {
29911
- return `wl-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
29912
- }
29913
- var localWatchlistApi = {
29914
- async getAll() {
29915
- return _localRead();
29916
- },
29917
- async addItem(symbol, group_id) {
29918
- const data = _localRead();
29919
- const existing = data.items.find((i) => i.symbol === symbol && i.group_id === (group_id ?? null));
29920
- if (existing) return existing;
29921
- const item = {
29922
- id: _localId(),
29923
- group_id: group_id ?? null,
29924
- symbol,
29925
- position: data.items.length,
29926
- created_at: (/* @__PURE__ */ new Date()).toISOString()
29927
- };
29928
- data.items.push(item);
29929
- _localWrite(data);
29930
- return item;
29931
- },
29932
- async removeItem(id) {
29933
- const data = _localRead();
29934
- data.items = data.items.filter((i) => i.id !== id);
29935
- _localWrite(data);
29936
- },
29937
- async moveItemToGroup(id, group_id) {
29938
- const data = _localRead();
29939
- const item = data.items.find((i) => i.id === id);
29940
- if (!item) throw new Error("Watchlist item not found");
29941
- item.group_id = group_id;
29942
- _localWrite(data);
29943
- return item;
29944
- },
29945
- async addGroup(name) {
29946
- const data = _localRead();
29947
- const group = {
29948
- id: _localId(),
29949
- name,
29950
- position: data.groups.length,
29951
- created_at: (/* @__PURE__ */ new Date()).toISOString()
29952
- };
29953
- data.groups.push(group);
29954
- _localWrite(data);
29955
- return group;
29956
- },
29957
- async removeGroup(id) {
29958
- const data = _localRead();
29959
- data.groups = data.groups.filter((g) => g.id !== id);
29960
- for (const item of data.items) {
29961
- if (item.group_id === id) item.group_id = null;
29962
- }
29963
- _localWrite(data);
29964
- },
29965
- async reorderItems(ids) {
29966
- const data = _localRead();
29967
- const order = new Map(ids.map((id, idx) => [id, idx]));
29968
- data.items.sort((a, b) => (order.get(a.id) ?? a.position) - (order.get(b.id) ?? b.position));
29969
- data.items.forEach((item, idx) => {
29970
- item.position = idx;
29971
- });
29972
- _localWrite(data);
29973
- }
29974
- };
29975
29892
  function fmtPrice2(v) {
29976
29893
  const abs = Math.abs(v);
29977
29894
  const dec = abs >= 1e3 ? 2 : abs >= 1 ? 2 : abs >= 1e-4 ? 4 : 6;
@@ -30074,8 +29991,16 @@ function SymbolRow({
30074
29991
  }
30075
29992
  );
30076
29993
  }
30077
- function WatchlistDrawer({ onClose, onSelectSymbol, symbolResolver, mode = "managed" }) {
30078
- const api = mode === "local" ? localWatchlistApi : watchlistApi;
29994
+ function WatchlistDrawer({ onClose, onSelectSymbol, symbolResolver, apiUrl, getAuthToken, liveQuotes = true }) {
29995
+ const api = watchlistApi;
29996
+ useEffect(() => {
29997
+ if (apiUrl !== void 0 || getAuthToken) {
29998
+ watchlistApi.configure({
29999
+ ...apiUrl !== void 0 ? { apiBase: `${apiUrl}/api` } : {},
30000
+ ...getAuthToken ? { getAuthToken } : {}
30001
+ });
30002
+ }
30003
+ }, [apiUrl, getAuthToken]);
30079
30004
  const [groups, setGroups] = useState([]);
30080
30005
  const [items, setItems] = useState([]);
30081
30006
  const [loading, setLoading] = useState(true);
@@ -30161,13 +30086,13 @@ function WatchlistDrawer({ onClose, onSelectSymbol, symbolResolver, mode = "mana
30161
30086
  reload();
30162
30087
  }, [reload]);
30163
30088
  useEffect(() => {
30164
- if (items.length === 0 || mode === "local") return;
30089
+ if (items.length === 0 || liveQuotes === false) return;
30165
30090
  const syms = [...new Set(items.map((i) => i.symbol))].join(",");
30166
30091
  fetch(`/api/reference/symbols/logos?symbols=${encodeURIComponent(syms)}`).then((r) => r.ok ? r.json() : {}).then((map) => setLogoMap(new Map(Object.entries(map)))).catch(() => {
30167
30092
  });
30168
- }, [items, mode]);
30093
+ }, [items, liveQuotes]);
30169
30094
  const symbols = items.map((i) => i.symbol);
30170
- const { prices: livePrices, dirs: liveDirs, volumes: liveVolumes } = useWatchlistQuotes(symbols, mode !== "local");
30095
+ const { prices: livePrices, dirs: liveDirs, volumes: liveVolumes } = useWatchlistQuotes(symbols, liveQuotes);
30171
30096
  const sessionOpenRef = useRef(/* @__PURE__ */ new Map());
30172
30097
  const quotes = useRef(/* @__PURE__ */ new Map()).current;
30173
30098
  quotes.clear();
@@ -30636,6 +30561,7 @@ function ChartWorkspace({
30636
30561
  scriptDrawerOpen,
30637
30562
  onToggleScriptDrawer,
30638
30563
  builtinScriptDrawer,
30564
+ hostApiUrl,
30639
30565
  scriptApiUrl,
30640
30566
  // Trading panel
30641
30567
  tradingPanel,
@@ -30844,17 +30770,19 @@ function ChartWorkspace({
30844
30770
  {
30845
30771
  onClose: closeScriptDrawer,
30846
30772
  onAddIndicator,
30847
- ...scriptApiUrl !== void 0 ? { apiUrl: scriptApiUrl } : {},
30773
+ ...(hostApiUrl ?? scriptApiUrl) !== void 0 ? { apiUrl: hostApiUrl ?? scriptApiUrl } : {},
30848
30774
  ...getAuthToken !== void 0 ? { getAuthToken } : {}
30849
30775
  }
30850
30776
  ),
30851
30777
  builtinWatchlistDrawer !== false && effWatchlistOpen && capabilities.watchlists && /* @__PURE__ */ jsx(
30852
30778
  WatchlistDrawer,
30853
30779
  {
30854
- mode: "local",
30855
30780
  onClose: closeWatchlist,
30856
30781
  onSelectSymbol: onSymbolChange,
30857
- symbolResolver
30782
+ symbolResolver,
30783
+ liveQuotes: false,
30784
+ ...hostApiUrl !== void 0 ? { apiUrl: hostApiUrl } : {},
30785
+ ...getAuthToken !== void 0 ? { getAuthToken } : {}
30858
30786
  }
30859
30787
  ),
30860
30788
  leftDrawers,