@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.
@@ -30114,89 +30114,6 @@ var watchlistApi = {
30114
30114
  return apiFetch("PUT", "/watchlist/items/reorder", { ids });
30115
30115
  }
30116
30116
  };
30117
- var LOCAL_KEY = "forgecharts:watchlist";
30118
- function _localRead() {
30119
- try {
30120
- const raw = typeof localStorage !== "undefined" ? localStorage.getItem(LOCAL_KEY) : null;
30121
- if (raw) {
30122
- const parsed = JSON.parse(raw);
30123
- if (Array.isArray(parsed.groups) && Array.isArray(parsed.items)) return parsed;
30124
- }
30125
- } catch {
30126
- }
30127
- return { groups: [], items: [] };
30128
- }
30129
- function _localWrite(data) {
30130
- try {
30131
- if (typeof localStorage !== "undefined") localStorage.setItem(LOCAL_KEY, JSON.stringify(data));
30132
- } catch {
30133
- }
30134
- }
30135
- function _localId() {
30136
- return `wl-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
30137
- }
30138
- var localWatchlistApi = {
30139
- async getAll() {
30140
- return _localRead();
30141
- },
30142
- async addItem(symbol, group_id) {
30143
- const data = _localRead();
30144
- const existing = data.items.find((i) => i.symbol === symbol && i.group_id === (group_id ?? null));
30145
- if (existing) return existing;
30146
- const item = {
30147
- id: _localId(),
30148
- group_id: group_id ?? null,
30149
- symbol,
30150
- position: data.items.length,
30151
- created_at: (/* @__PURE__ */ new Date()).toISOString()
30152
- };
30153
- data.items.push(item);
30154
- _localWrite(data);
30155
- return item;
30156
- },
30157
- async removeItem(id) {
30158
- const data = _localRead();
30159
- data.items = data.items.filter((i) => i.id !== id);
30160
- _localWrite(data);
30161
- },
30162
- async moveItemToGroup(id, group_id) {
30163
- const data = _localRead();
30164
- const item = data.items.find((i) => i.id === id);
30165
- if (!item) throw new Error("Watchlist item not found");
30166
- item.group_id = group_id;
30167
- _localWrite(data);
30168
- return item;
30169
- },
30170
- async addGroup(name) {
30171
- const data = _localRead();
30172
- const group = {
30173
- id: _localId(),
30174
- name,
30175
- position: data.groups.length,
30176
- created_at: (/* @__PURE__ */ new Date()).toISOString()
30177
- };
30178
- data.groups.push(group);
30179
- _localWrite(data);
30180
- return group;
30181
- },
30182
- async removeGroup(id) {
30183
- const data = _localRead();
30184
- data.groups = data.groups.filter((g) => g.id !== id);
30185
- for (const item of data.items) {
30186
- if (item.group_id === id) item.group_id = null;
30187
- }
30188
- _localWrite(data);
30189
- },
30190
- async reorderItems(ids) {
30191
- const data = _localRead();
30192
- const order = new Map(ids.map((id, idx) => [id, idx]));
30193
- data.items.sort((a, b) => (order.get(a.id) ?? a.position) - (order.get(b.id) ?? b.position));
30194
- data.items.forEach((item, idx) => {
30195
- item.position = idx;
30196
- });
30197
- _localWrite(data);
30198
- }
30199
- };
30200
30117
  function fmtPrice2(v) {
30201
30118
  const abs = Math.abs(v);
30202
30119
  const dec = abs >= 1e3 ? 2 : abs >= 1 ? 2 : abs >= 1e-4 ? 4 : 6;
@@ -30299,8 +30216,16 @@ function SymbolRow({
30299
30216
  }
30300
30217
  );
30301
30218
  }
30302
- function WatchlistDrawer({ onClose, onSelectSymbol, symbolResolver, mode = "managed" }) {
30303
- const api = mode === "local" ? localWatchlistApi : watchlistApi;
30219
+ function WatchlistDrawer({ onClose, onSelectSymbol, symbolResolver, apiUrl, getAuthToken, liveQuotes = true }) {
30220
+ const api = watchlistApi;
30221
+ useEffect(() => {
30222
+ if (apiUrl !== void 0 || getAuthToken) {
30223
+ watchlistApi.configure({
30224
+ ...apiUrl !== void 0 ? { apiBase: `${apiUrl}/api` } : {},
30225
+ ...getAuthToken ? { getAuthToken } : {}
30226
+ });
30227
+ }
30228
+ }, [apiUrl, getAuthToken]);
30304
30229
  const [groups, setGroups] = useState([]);
30305
30230
  const [items, setItems] = useState([]);
30306
30231
  const [loading, setLoading] = useState(true);
@@ -30386,13 +30311,13 @@ function WatchlistDrawer({ onClose, onSelectSymbol, symbolResolver, mode = "mana
30386
30311
  reload();
30387
30312
  }, [reload]);
30388
30313
  useEffect(() => {
30389
- if (items.length === 0 || mode === "local") return;
30314
+ if (items.length === 0 || liveQuotes === false) return;
30390
30315
  const syms = [...new Set(items.map((i) => i.symbol))].join(",");
30391
30316
  fetch(`/api/reference/symbols/logos?symbols=${encodeURIComponent(syms)}`).then((r) => r.ok ? r.json() : {}).then((map) => setLogoMap(new Map(Object.entries(map)))).catch(() => {
30392
30317
  });
30393
- }, [items, mode]);
30318
+ }, [items, liveQuotes]);
30394
30319
  const symbols = items.map((i) => i.symbol);
30395
- const { prices: livePrices, dirs: liveDirs, volumes: liveVolumes } = useWatchlistQuotes(symbols, mode !== "local");
30320
+ const { prices: livePrices, dirs: liveDirs, volumes: liveVolumes } = useWatchlistQuotes(symbols, liveQuotes);
30396
30321
  const sessionOpenRef = useRef(/* @__PURE__ */ new Map());
30397
30322
  const quotes = useRef(/* @__PURE__ */ new Map()).current;
30398
30323
  quotes.clear();
@@ -30861,6 +30786,7 @@ function ChartWorkspace({
30861
30786
  scriptDrawerOpen,
30862
30787
  onToggleScriptDrawer,
30863
30788
  builtinScriptDrawer,
30789
+ hostApiUrl,
30864
30790
  scriptApiUrl,
30865
30791
  // Trading panel
30866
30792
  tradingPanel,
@@ -31069,17 +30995,19 @@ function ChartWorkspace({
31069
30995
  {
31070
30996
  onClose: closeScriptDrawer,
31071
30997
  onAddIndicator,
31072
- ...scriptApiUrl !== void 0 ? { apiUrl: scriptApiUrl } : {},
30998
+ ...(hostApiUrl ?? scriptApiUrl) !== void 0 ? { apiUrl: hostApiUrl ?? scriptApiUrl } : {},
31073
30999
  ...getAuthToken !== void 0 ? { getAuthToken } : {}
31074
31000
  }
31075
31001
  ),
31076
31002
  builtinWatchlistDrawer !== false && effWatchlistOpen && capabilities.watchlists && /* @__PURE__ */ jsx(
31077
31003
  WatchlistDrawer,
31078
31004
  {
31079
- mode: "local",
31080
31005
  onClose: closeWatchlist,
31081
31006
  onSelectSymbol: onSymbolChange,
31082
- symbolResolver
31007
+ symbolResolver,
31008
+ liveQuotes: false,
31009
+ ...hostApiUrl !== void 0 ? { apiUrl: hostApiUrl } : {},
31010
+ ...getAuthToken !== void 0 ? { getAuthToken } : {}
31083
31011
  }
31084
31012
  ),
31085
31013
  leftDrawers,