@funnest/charts-ui 0.11.27 → 0.11.29

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.ts CHANGED
@@ -10,4 +10,5 @@ export { LAYOUT_GROUPS, LAYOUTS, MAX_PANES, paneCount } from './layouts.js';
10
10
  export type { LayoutId, SplitNode, SplitSizes } from './layouts.js';
11
11
  export type { ContextMenuItem, ContextMenuItems, MenuIconName, DrawingAction, DrawingActions, IntervalGroup, PriceAxisActions, SettingsToggle, SettingsToggles, SettingsChoice, SettingsLink, SettingsSection, SettingsSections, LayoutSync, LegendValues, SearchCategory, SearchExchange, ToolsMenuItem, ToolsMenuItems } from './context.js';
12
12
  export type { ColorScheme, TradingChart, TradingChartOptions, TradingChartSlots } from './trading-chart.js';
13
+ export type { WidgetPreferences } from './shell.js';
13
14
  export { resolutionLabel, STRINGS, stringsOf, type Strings } from './i18n.js';
package/dist/index.js CHANGED
@@ -4301,6 +4301,13 @@ var CSS = (
4301
4301
  /* \u2500\u2500 \uB3C4\uAD6C menu: chart type, split, compare, replay, axis, screenshot, settings \u2500\u2500 */
4302
4302
  .fnc-tools-menu { width: 300px; padding: 8px; gap: 2px; max-height: 72vh; overflow-y: auto; }
4303
4303
  .fnc-tools-section { padding: 8px 6px 6px; font-size: 12px; font-weight: 700; color: var(--fnc-text-2); }
4304
+ .fnc-tools-fold { display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px 6px; border-radius: 6px; text-align: left; cursor: pointer; }
4305
+ .fnc-tools-fold:hover { background: var(--fnc-surface); color: var(--fnc-text); }
4306
+ .fnc-tools-fold > span:first-child { flex: 1; }
4307
+ .fnc-tools-fold-now { display: inline-flex; align-items: center; gap: 5px; font-weight: 500; color: var(--fnc-text-2); }
4308
+ .fnc-tools-fold-now svg { width: 15px; height: 15px; }
4309
+ .fnc-tools-fold > svg { width: 14px; height: 14px; transition: transform 0.15s; transform: rotate(-90deg); }
4310
+ .fnc-tools-fold[aria-expanded="true"] > svg { transform: none; }
4304
4311
  .fnc-tools-seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; margin: 0 2px 4px; }
4305
4312
  .fnc-tools-seg[data-count="5"], .fnc-tools-seg[data-count="8"], .fnc-tools-seg[data-count="13"] { display: grid; grid-auto-flow: row; grid-template-columns: repeat(3, 1fr); gap: 2px; }
4306
4313
  .fnc-tools-seg[data-count="8"], .fnc-tools-seg[data-count="13"] { grid-template-columns: repeat(4, 1fr); }
@@ -4888,6 +4895,12 @@ function createShell(container, options) {
4888
4895
  const broadcast = (patch) => {
4889
4896
  for (const p3 of panes()) p3.store.set(patch);
4890
4897
  };
4898
+ const prefListeners = /* @__PURE__ */ new Set();
4899
+ const prefs = () => ({ favoriteIntervals: [...favoriteIntervals], customIntervals: [...customIntervals], favoriteTools: [...favoriteTools], keepDrawing, drawingDefaults: { ...drawingDefaults }, cursorMode });
4900
+ const changed = () => {
4901
+ const now = prefs();
4902
+ for (const l3 of prefListeners) l3(now);
4903
+ };
4891
4904
  const isNativeFullscreen = () => document.fullscreenElement === root;
4892
4905
  const isFullscreen = () => isNativeFullscreen() || root.classList.contains("fnc-pseudo-fullscreen");
4893
4906
  const onFullscreenChange = () => broadcast({ fullscreen: isFullscreen() });
@@ -4912,23 +4925,27 @@ function createShell(container, options) {
4912
4925
  storage.set("cursor-mode", mode);
4913
4926
  for (const p3 of panes()) p3.chart.setCursorMode(mode);
4914
4927
  broadcast({ cursorMode });
4928
+ changed();
4915
4929
  },
4916
4930
  drawingDefaults: () => drawingDefaults,
4917
4931
  saveDrawingDefaults: (defaults) => {
4918
4932
  drawingDefaults = defaults;
4919
4933
  storage.set("drawing-defaults", defaults);
4920
4934
  for (const p3 of panes()) p3.chart.setDrawingDefaults(defaults);
4935
+ changed();
4921
4936
  },
4922
4937
  toggleFavoriteTool: (tool) => {
4923
4938
  favoriteTools = favoriteTools.includes(tool) ? favoriteTools.filter((x2) => x2 !== tool) : [...favoriteTools, tool];
4924
4939
  storage.set("favorite-tools", favoriteTools);
4925
4940
  broadcast({ favoriteTools });
4941
+ changed();
4926
4942
  },
4927
4943
  setKeepDrawing: (on) => {
4928
4944
  keepDrawing = on;
4929
4945
  storage.set("keep-drawing", on);
4930
4946
  for (const p3 of panes()) p3.chart.setKeepDrawingTool(on);
4931
4947
  broadcast({ keepDrawing });
4948
+ changed();
4932
4949
  },
4933
4950
  setDrawingsHidden: (hidden) => {
4934
4951
  for (const p3 of panes()) p3.chart.setDrawingsHidden(hidden);
@@ -4961,6 +4978,7 @@ function createShell(container, options) {
4961
4978
  customIntervals = [...customIntervals, res];
4962
4979
  storage.set("custom-intervals", customIntervals);
4963
4980
  broadcast({ customIntervals });
4981
+ changed();
4964
4982
  },
4965
4983
  removeCustomInterval: (res) => {
4966
4984
  customIntervals = customIntervals.filter((r3) => r3 !== res);
@@ -4970,12 +4988,42 @@ function createShell(container, options) {
4970
4988
  storage.set("favorite-intervals", favoriteIntervals);
4971
4989
  }
4972
4990
  broadcast({ customIntervals, favoriteIntervals });
4991
+ changed();
4973
4992
  },
4974
4993
  toggleFavoriteInterval: (res) => {
4975
4994
  favoriteIntervals = favoriteIntervals.includes(res) ? favoriteIntervals.filter((r3) => r3 !== res) : [...favoriteIntervals, res];
4976
4995
  storage.set("favorite-intervals", favoriteIntervals);
4977
4996
  broadcast({ favoriteIntervals });
4978
4997
  options.onFavoriteIntervalsChange?.(favoriteIntervals);
4998
+ changed();
4999
+ },
5000
+ preferences: prefs,
5001
+ setPreferences: (patch) => {
5002
+ const list = (v3, ok) => Array.isArray(v3) && v3.every(ok) ? v3 : void 0;
5003
+ const str = (x2) => typeof x2 === "string" && x2.length > 0 && x2.length < 40;
5004
+ const fav = list(patch.favoriteIntervals, str);
5005
+ const custom = list(patch.customIntervals, str);
5006
+ const tools = list(patch.favoriteTools, str);
5007
+ if (fav) storage.set("favorite-intervals", favoriteIntervals = fav);
5008
+ if (custom) storage.set("custom-intervals", customIntervals = custom);
5009
+ if (tools) storage.set("favorite-tools", favoriteTools = tools);
5010
+ if (typeof patch.keepDrawing === "boolean") {
5011
+ storage.set("keep-drawing", keepDrawing = patch.keepDrawing);
5012
+ for (const p3 of panes()) p3.chart.setKeepDrawingTool(keepDrawing);
5013
+ }
5014
+ if (patch.drawingDefaults && typeof patch.drawingDefaults === "object") {
5015
+ storage.set("drawing-defaults", drawingDefaults = patch.drawingDefaults);
5016
+ for (const p3 of panes()) p3.chart.setDrawingDefaults(drawingDefaults);
5017
+ }
5018
+ if (patch.cursorMode === "cross" || patch.cursorMode === "dot" || patch.cursorMode === "arrow") {
5019
+ storage.set("cursor-mode", cursorMode = patch.cursorMode);
5020
+ for (const p3 of panes()) p3.chart.setCursorMode(cursorMode);
5021
+ }
5022
+ broadcast({ favoriteIntervals, customIntervals, favoriteTools, keepDrawing, cursorMode });
5023
+ },
5024
+ onPreferences: (listener) => {
5025
+ prefListeners.add(listener);
5026
+ return () => prefListeners.delete(listener);
4979
5027
  },
4980
5028
  destroy: () => {
4981
5029
  unbindTips();
@@ -6190,50 +6238,61 @@ var SYNC_KEYS = [
6190
6238
  { key: "interval", label: "syncInterval" },
6191
6239
  { key: "indicators", label: "syncIndicators" }
6192
6240
  ];
6193
- function LayoutSection({ ctx, multi, close }) {
6241
+ function Fold({ label, open, onToggle, children }) {
6242
+ return /* @__PURE__ */ a3("button", { type: "button", class: "fnc-tools-section fnc-tools-fold", "aria-expanded": open, onClick: onToggle, children: [
6243
+ /* @__PURE__ */ a3("span", { children: label }),
6244
+ /* @__PURE__ */ a3("span", { class: "fnc-tools-fold-now", children }),
6245
+ /* @__PURE__ */ a3(ChevronDownIcon, {})
6246
+ ] });
6247
+ }
6248
+ function LayoutSection({ ctx, multi, close, open, onToggle }) {
6194
6249
  const s3 = useStore(ctx.store);
6195
6250
  const m3 = useStore(multi.store);
6196
6251
  const t3 = stringsOf(s3);
6197
6252
  return /* @__PURE__ */ a3($, { children: [
6198
- /* @__PURE__ */ a3("div", { class: "fnc-tools-section", children: t3.layout }),
6199
- /* @__PURE__ */ a3("div", { class: "fnc-tools-layouts", children: LAYOUT_GROUPS.map((group) => /* @__PURE__ */ a3("div", { class: "fnc-layout-row", children: [
6200
- /* @__PURE__ */ a3("span", { class: "fnc-layout-count", children: group[0].split("-")[0] }),
6201
- group.map((id) => /* @__PURE__ */ a3(
6253
+ /* @__PURE__ */ a3(Fold, { label: t3.layout, open, onToggle, children: /* @__PURE__ */ a3(LayoutGlyph, { id: m3.layout }) }),
6254
+ open && /* @__PURE__ */ a3($, { children: [
6255
+ /* @__PURE__ */ a3("div", { class: "fnc-tools-layouts", children: LAYOUT_GROUPS.map((group) => /* @__PURE__ */ a3("div", { class: "fnc-layout-row", children: [
6256
+ /* @__PURE__ */ a3("span", { class: "fnc-layout-count", children: group[0].split("-")[0] }),
6257
+ group.map((id) => /* @__PURE__ */ a3(
6258
+ "button",
6259
+ {
6260
+ class: "fnc-layout-opt",
6261
+ role: "menuitemradio",
6262
+ "aria-checked": id === m3.layout,
6263
+ "aria-label": `${t3.layout} ${id}`,
6264
+ "data-layout": id,
6265
+ onClick: () => {
6266
+ multi.setLayout(id);
6267
+ close();
6268
+ },
6269
+ children: /* @__PURE__ */ a3(LayoutGlyph, { id })
6270
+ }
6271
+ ))
6272
+ ] })) }),
6273
+ paneCount(LAYOUTS[m3.layout]) > 1 && /* @__PURE__ */ a3("div", { class: "fnc-tools-section", children: t3.sync }),
6274
+ paneCount(LAYOUTS[m3.layout]) > 1 && SYNC_KEYS.map(({ key, label }) => /* @__PURE__ */ a3(
6202
6275
  "button",
6203
6276
  {
6204
- class: "fnc-layout-opt",
6205
- role: "menuitemradio",
6206
- "aria-checked": id === m3.layout,
6207
- "aria-label": `${t3.layout} ${id}`,
6208
- "data-layout": id,
6209
- onClick: () => {
6210
- multi.setLayout(id);
6211
- close();
6212
- },
6213
- children: /* @__PURE__ */ a3(LayoutGlyph, { id })
6277
+ class: "fnc-menu-item fnc-sync-item",
6278
+ role: "menuitemcheckbox",
6279
+ "aria-checked": m3.sync[key],
6280
+ onClick: () => multi.setSync({ [key]: !m3.sync[key] }),
6281
+ children: [
6282
+ /* @__PURE__ */ a3("span", { children: t3[label] }),
6283
+ /* @__PURE__ */ a3("span", { class: "fnc-switch", "data-on": m3.sync[key] ? "true" : "false", "aria-hidden": "true" })
6284
+ ]
6214
6285
  }
6215
6286
  ))
6216
- ] })) }),
6217
- paneCount(LAYOUTS[m3.layout]) > 1 && /* @__PURE__ */ a3("div", { class: "fnc-tools-section", children: t3.sync }),
6218
- paneCount(LAYOUTS[m3.layout]) > 1 && SYNC_KEYS.map(({ key, label }) => /* @__PURE__ */ a3(
6219
- "button",
6220
- {
6221
- class: "fnc-menu-item fnc-sync-item",
6222
- role: "menuitemcheckbox",
6223
- "aria-checked": m3.sync[key],
6224
- onClick: () => multi.setSync({ [key]: !m3.sync[key] }),
6225
- children: [
6226
- /* @__PURE__ */ a3("span", { children: t3[label] }),
6227
- /* @__PURE__ */ a3("span", { class: "fnc-switch", "data-on": m3.sync[key] ? "true" : "false", "aria-hidden": "true" })
6228
- ]
6229
- }
6230
- ))
6287
+ ] })
6231
6288
  ] });
6232
6289
  }
6233
6290
  function ToolsMenu({ ctx }) {
6234
6291
  const s3 = useStore(ctx.store);
6235
6292
  const t3 = stringsOf(s3);
6236
6293
  const [open, setOpen] = d2(false);
6294
+ const [typesOpen, setTypesOpen] = d2(false);
6295
+ const [layoutOpen, setLayoutOpen] = d2(false);
6237
6296
  const [scale, setScale] = d2(ctx.chart.settings.priceScale);
6238
6297
  const ref = T2(null);
6239
6298
  const menuRef = useKeepInView(open);
@@ -6287,8 +6346,14 @@ function ToolsMenu({ ctx }) {
6287
6346
  }
6288
6347
  ),
6289
6348
  open && /* @__PURE__ */ a3("div", { class: "fnc-menu fnc-tools-menu", role: "menu", "aria-label": t3.tools, ref: menuRef, children: [
6290
- /* @__PURE__ */ a3("div", { class: "fnc-tools-section", children: t3.chartType }),
6291
- /* @__PURE__ */ a3("div", { class: "fnc-seg fnc-tools-seg", role: "radiogroup", "aria-label": t3.chartType, "data-count": TYPES.length, children: TYPES.map(({ type, label, icon: Icon2 }) => /* @__PURE__ */ a3(
6349
+ /* @__PURE__ */ a3(Fold, { label: t3.chartType, open: typesOpen, onToggle: () => setTypesOpen(!typesOpen), children: (() => {
6350
+ const now = TYPES.find((x2) => x2.type === s3.chartType) ?? TYPES[0];
6351
+ return /* @__PURE__ */ a3($, { children: [
6352
+ /* @__PURE__ */ a3(now.icon, {}),
6353
+ t3[now.label]
6354
+ ] });
6355
+ })() }),
6356
+ typesOpen && /* @__PURE__ */ a3("div", { class: "fnc-seg fnc-tools-seg", role: "radiogroup", "aria-label": t3.chartType, "data-count": TYPES.length, children: TYPES.map(({ type, label, icon: Icon2 }) => /* @__PURE__ */ a3(
6292
6357
  "button",
6293
6358
  {
6294
6359
  type: "button",
@@ -6305,7 +6370,7 @@ function ToolsMenu({ ctx }) {
6305
6370
  ]
6306
6371
  }
6307
6372
  )) }),
6308
- ctx.multi && /* @__PURE__ */ a3(LayoutSection, { ctx, multi: ctx.multi, close }),
6373
+ ctx.multi && /* @__PURE__ */ a3(LayoutSection, { ctx, multi: ctx.multi, close, open: layoutOpen, onToggle: () => setLayoutOpen(!layoutOpen) }),
6309
6374
  /* @__PURE__ */ a3("div", { class: "fnc-tools-sep" }),
6310
6375
  canSearch && item("fnc-btn-compare", t3.compareSymbol, /* @__PURE__ */ a3(CompareIcon, {}), () => ctx.setSearchOpen(true, "compare"), {
6311
6376
  disabled: s3.compares.length >= 5
@@ -7773,6 +7838,7 @@ function createMultiChart(container, options) {
7773
7838
  }
7774
7839
  renderGrid();
7775
7840
  }
7841
+ const offPrefs = shell.onPreferences((prefs) => emit("preferencesChange", prefs));
7776
7842
  makePane(0, paneSpecs[0]);
7777
7843
  ensurePanes(Math.max(visibleCount(), Math.min(paneSpecs.length, MAX_PANES)));
7778
7844
  shell.setPanes(() => panes);
@@ -7867,6 +7933,8 @@ function createMultiChart(container, options) {
7867
7933
  if (raw.sync?.time && panes.every((p3) => p3.chart.settings.timeLink === "off")) controls.applySettings({ timeLink: "follow" });
7868
7934
  store.set({ sync: { ...store.get().sync, time: false } });
7869
7935
  },
7936
+ preferences: () => shell.preferences(),
7937
+ setPreferences: (patch) => shell.setPreferences(patch),
7870
7938
  on: (event, listener) => {
7871
7939
  let set = listeners.get(event);
7872
7940
  if (!set) listeners.set(event, set = /* @__PURE__ */ new Set());
@@ -7874,6 +7942,7 @@ function createMultiChart(container, options) {
7874
7942
  return () => set.delete(listener);
7875
7943
  },
7876
7944
  destroy: () => {
7945
+ offPrefs();
7877
7946
  unbindKeys();
7878
7947
  resize.disconnect();
7879
7948
  Q(null, shell.toolbarHost);
@@ -2,7 +2,7 @@
2
2
  import { type Chart, type ChartState, type Locale, type Resolution, type ThemeTokens } from '@funnest/charts';
3
3
  import type { LayoutSync } from './context.js';
4
4
  import { type LayoutId, type SplitSizes } from './layouts.js';
5
- import { type ColorScheme, type TradingChartSlots } from './shell.js';
5
+ import { type ColorScheme, type TradingChartSlots, type WidgetPreferences } from './shell.js';
6
6
  import { type TradingChartOptions } from './trading-chart.js';
7
7
  export interface PaneSpec {
8
8
  symbol: string;
@@ -44,6 +44,8 @@ export interface MultiChartEvents {
44
44
  };
45
45
  /** Something worth persisting changed in any pane or in the layout — a hook for autosave. */
46
46
  stateChange: void;
47
+ /** The person changed a preference here (pinned intervals, favorite tools…): all of them, to keep on their account. */
48
+ preferencesChange: WidgetPreferences;
47
49
  }
48
50
  export interface MultiChart {
49
51
  readonly slots: TradingChartSlots;
@@ -69,6 +71,10 @@ export interface MultiChart {
69
71
  setColorScheme(scheme: ColorScheme): void;
70
72
  save(): MultiChartState;
71
73
  load(state: MultiChartState | unknown): Promise<void>;
74
+ /** The person's widget preferences (pinned and added intervals, favorite tools, keep-drawing, tool styles, cursor). */
75
+ preferences(): WidgetPreferences;
76
+ /** Puts preferences kept elsewhere (another device's): stored here, every pane follows; no preferencesChange. */
77
+ setPreferences(patch: Partial<WidgetPreferences>): void;
72
78
  on<K extends keyof MultiChartEvents>(event: K, listener: (payload: MultiChartEvents[K]) => void): () => void;
73
79
  destroy(): void;
74
80
  }
package/dist/shell.d.ts CHANGED
@@ -3,6 +3,20 @@ import type { UiState } from './context.js';
3
3
  import { type WidgetStorage } from './storage.js';
4
4
  import type { Store } from './store.js';
5
5
  export type ColorScheme = 'light' | 'dark' | 'system';
6
+ /**
7
+ * A person's widget preferences (what follows them, not the device): pinned and added intervals,
8
+ * favorite drawing tools, keep-drawing, each tool's last style, the cursor. `preferences()` reads
9
+ * them, `setPreferences()` puts them (another device's), and `preferencesChange` tells when they
10
+ * change here — so an app can keep them on its users' accounts.
11
+ */
12
+ export interface WidgetPreferences {
13
+ favoriteIntervals: Resolution[];
14
+ customIntervals: Resolution[];
15
+ favoriteTools: DrawingType[];
16
+ keepDrawing: boolean;
17
+ drawingDefaults: DrawingDefaults;
18
+ cursorMode: CursorMode;
19
+ }
6
20
  /**
7
21
  * Empty elements inside the widget layout where the host app mounts its own UI (any framework):
8
22
  * market stats, account info, status bars… They inherit the widget's `--fnc-*` theme variables
@@ -81,6 +95,11 @@ export interface Shell {
81
95
  toggleFavoriteInterval(resolution: Resolution): void;
82
96
  addCustomInterval(resolution: Resolution): void;
83
97
  removeCustomInterval(resolution: Resolution): void;
98
+ preferences(): WidgetPreferences;
99
+ /** Puts preferences (from another device): stored, and every pane follows. Doesn't fire onPreferences. */
100
+ setPreferences(patch: Partial<WidgetPreferences>): void;
101
+ /** Hears every change made here (by the person), with them all. */
102
+ onPreferences(listener: (prefs: WidgetPreferences) => void): () => void;
84
103
  destroy(): void;
85
104
  }
86
105
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@funnest/charts-ui",
3
- "version": "0.11.27",
3
+ "version": "0.11.29",
4
4
  "description": "Pro trading UI (toolbar, drawing tools, sheets) for Funnest Charts. Framework-agnostic.",
5
5
  "keywords": [
6
6
  "chart",
@@ -42,7 +42,7 @@
42
42
  "NOTICE"
43
43
  ],
44
44
  "dependencies": {
45
- "@funnest/charts": "0.11.27"
45
+ "@funnest/charts": "0.11.29"
46
46
  },
47
47
  "devDependencies": {
48
48
  "preact": "^11.2.0"