@funnest/charts-ui 0.11.28 → 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
@@ -4895,6 +4895,12 @@ function createShell(container, options) {
4895
4895
  const broadcast = (patch) => {
4896
4896
  for (const p3 of panes()) p3.store.set(patch);
4897
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
+ };
4898
4904
  const isNativeFullscreen = () => document.fullscreenElement === root;
4899
4905
  const isFullscreen = () => isNativeFullscreen() || root.classList.contains("fnc-pseudo-fullscreen");
4900
4906
  const onFullscreenChange = () => broadcast({ fullscreen: isFullscreen() });
@@ -4919,23 +4925,27 @@ function createShell(container, options) {
4919
4925
  storage.set("cursor-mode", mode);
4920
4926
  for (const p3 of panes()) p3.chart.setCursorMode(mode);
4921
4927
  broadcast({ cursorMode });
4928
+ changed();
4922
4929
  },
4923
4930
  drawingDefaults: () => drawingDefaults,
4924
4931
  saveDrawingDefaults: (defaults) => {
4925
4932
  drawingDefaults = defaults;
4926
4933
  storage.set("drawing-defaults", defaults);
4927
4934
  for (const p3 of panes()) p3.chart.setDrawingDefaults(defaults);
4935
+ changed();
4928
4936
  },
4929
4937
  toggleFavoriteTool: (tool) => {
4930
4938
  favoriteTools = favoriteTools.includes(tool) ? favoriteTools.filter((x2) => x2 !== tool) : [...favoriteTools, tool];
4931
4939
  storage.set("favorite-tools", favoriteTools);
4932
4940
  broadcast({ favoriteTools });
4941
+ changed();
4933
4942
  },
4934
4943
  setKeepDrawing: (on) => {
4935
4944
  keepDrawing = on;
4936
4945
  storage.set("keep-drawing", on);
4937
4946
  for (const p3 of panes()) p3.chart.setKeepDrawingTool(on);
4938
4947
  broadcast({ keepDrawing });
4948
+ changed();
4939
4949
  },
4940
4950
  setDrawingsHidden: (hidden) => {
4941
4951
  for (const p3 of panes()) p3.chart.setDrawingsHidden(hidden);
@@ -4968,6 +4978,7 @@ function createShell(container, options) {
4968
4978
  customIntervals = [...customIntervals, res];
4969
4979
  storage.set("custom-intervals", customIntervals);
4970
4980
  broadcast({ customIntervals });
4981
+ changed();
4971
4982
  },
4972
4983
  removeCustomInterval: (res) => {
4973
4984
  customIntervals = customIntervals.filter((r3) => r3 !== res);
@@ -4977,12 +4988,42 @@ function createShell(container, options) {
4977
4988
  storage.set("favorite-intervals", favoriteIntervals);
4978
4989
  }
4979
4990
  broadcast({ customIntervals, favoriteIntervals });
4991
+ changed();
4980
4992
  },
4981
4993
  toggleFavoriteInterval: (res) => {
4982
4994
  favoriteIntervals = favoriteIntervals.includes(res) ? favoriteIntervals.filter((r3) => r3 !== res) : [...favoriteIntervals, res];
4983
4995
  storage.set("favorite-intervals", favoriteIntervals);
4984
4996
  broadcast({ favoriteIntervals });
4985
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);
4986
5027
  },
4987
5028
  destroy: () => {
4988
5029
  unbindTips();
@@ -7797,6 +7838,7 @@ function createMultiChart(container, options) {
7797
7838
  }
7798
7839
  renderGrid();
7799
7840
  }
7841
+ const offPrefs = shell.onPreferences((prefs) => emit("preferencesChange", prefs));
7800
7842
  makePane(0, paneSpecs[0]);
7801
7843
  ensurePanes(Math.max(visibleCount(), Math.min(paneSpecs.length, MAX_PANES)));
7802
7844
  shell.setPanes(() => panes);
@@ -7891,6 +7933,8 @@ function createMultiChart(container, options) {
7891
7933
  if (raw.sync?.time && panes.every((p3) => p3.chart.settings.timeLink === "off")) controls.applySettings({ timeLink: "follow" });
7892
7934
  store.set({ sync: { ...store.get().sync, time: false } });
7893
7935
  },
7936
+ preferences: () => shell.preferences(),
7937
+ setPreferences: (patch) => shell.setPreferences(patch),
7894
7938
  on: (event, listener) => {
7895
7939
  let set = listeners.get(event);
7896
7940
  if (!set) listeners.set(event, set = /* @__PURE__ */ new Set());
@@ -7898,6 +7942,7 @@ function createMultiChart(container, options) {
7898
7942
  return () => set.delete(listener);
7899
7943
  },
7900
7944
  destroy: () => {
7945
+ offPrefs();
7901
7946
  unbindKeys();
7902
7947
  resize.disconnect();
7903
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.28",
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.28"
45
+ "@funnest/charts": "0.11.29"
46
46
  },
47
47
  "devDependencies": {
48
48
  "preact": "^11.2.0"