@funnest/charts-ui 0.11.1 → 0.11.2

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,5 @@
1
+ import type { MenuIconName } from '../context.js';
2
+ /** The glyph for a menu row's `icon`, sized for the row (16px). */
3
+ export declare function MenuIcon({ name }: {
4
+ name: MenuIconName;
5
+ }): import("preact").JSX.Element;
package/dist/context.d.ts CHANGED
@@ -59,13 +59,19 @@ export interface UiState {
59
59
  legendItems: readonly LegendItem[];
60
60
  replay: ReplayStatus;
61
61
  }
62
+ /**
63
+ * A menu row's glyph (before the label): 'alert' a bell, 'line' a horizontal line, 'date' a
64
+ * calendar, 'eye' display, 'clock' time, and the chart's own rows' (undo, redo, smooth, lock,
65
+ * ratio, reset, settings).
66
+ */
67
+ export type MenuIconName = 'alert' | 'line' | 'date' | 'eye' | 'clock' | 'undo' | 'redo' | 'smooth' | 'lock' | 'ratio' | 'reset' | 'settings';
62
68
  /** A row in the chart's right-click menu, or a divider. */
63
69
  export type ContextMenuItem = {
64
70
  label: string;
65
71
  shortcut?: string;
66
72
  disabled?: boolean;
67
- /** 'alert': a bell before the label. */
68
- icon?: 'alert';
73
+ /** A glyph before the label (see MenuIconName). Rows without one keep the space, so labels line up. */
74
+ icon?: MenuIconName;
69
75
  /** A setting that's on or off: a check mark, and it reads as a checkbox. */
70
76
  checked?: boolean;
71
77
  onSelect(): void;
package/dist/index.d.ts CHANGED
@@ -8,6 +8,6 @@ export { createMultiChart } from './multi-chart.js';
8
8
  export type { MultiChart, MultiChartEvents, MultiChartOptions, MultiChartState, PaneSpec } from './multi-chart.js';
9
9
  export { LAYOUT_GROUPS, LAYOUTS, MAX_PANES, paneCount } from './layouts.js';
10
10
  export type { LayoutId, SplitNode, SplitSizes } from './layouts.js';
11
- export type { ContextMenuItem, ContextMenuItems, DrawingAction, DrawingActions, IntervalGroup, PriceAxisActions, SettingsToggle, SettingsToggles, LayoutSync, LegendValues, SearchCategory, SearchExchange, ToolsMenuItem, ToolsMenuItems } from './context.js';
11
+ export type { ContextMenuItem, ContextMenuItems, MenuIconName, DrawingAction, DrawingActions, IntervalGroup, PriceAxisActions, SettingsToggle, SettingsToggles, LayoutSync, LegendValues, SearchCategory, SearchExchange, ToolsMenuItem, ToolsMenuItems } from './context.js';
12
12
  export type { ColorScheme, TradingChart, TradingChartOptions, TradingChartSlots } from './trading-chart.js';
13
13
  export { resolutionLabel, STRINGS, stringsOf, type Strings } from './i18n.js';
package/dist/index.js CHANGED
@@ -4188,6 +4188,53 @@ import { formatCompact, formatPrice as formatPrice4 } from "@funnest/charts";
4188
4188
 
4189
4189
  // src/components/context-menu.tsx
4190
4190
  import { formatPrice as formatPrice2 } from "@funnest/charts";
4191
+
4192
+ // src/components/menu-icon.tsx
4193
+ function Glyph({ children }) {
4194
+ return /* @__PURE__ */ a3("svg", { width: "16", height: "16", viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", "stroke-width": "1.6", "stroke-linecap": "round", "stroke-linejoin": "round", "aria-hidden": "true", children });
4195
+ }
4196
+ var GLYPHS = {
4197
+ undo: /* @__PURE__ */ a3($, { children: [
4198
+ /* @__PURE__ */ a3("path", { d: "M7 5.5 3.5 9 7 12.5" }),
4199
+ /* @__PURE__ */ a3("path", { d: "M3.5 9h8a4.5 4.5 0 0 1 0 9H9" })
4200
+ ] }),
4201
+ redo: /* @__PURE__ */ a3($, { children: [
4202
+ /* @__PURE__ */ a3("path", { d: "M13 5.5 16.5 9 13 12.5" }),
4203
+ /* @__PURE__ */ a3("path", { d: "M16.5 9h-8a4.5 4.5 0 0 0 0 9H11" })
4204
+ ] }),
4205
+ // Motion lines behind a dot: something gliding.
4206
+ smooth: /* @__PURE__ */ a3($, { children: [
4207
+ /* @__PURE__ */ a3("path", { d: "M3 7h6M2 10h5M3 13h6" }),
4208
+ /* @__PURE__ */ a3("circle", { cx: "13.5", cy: "10", r: "3.5" })
4209
+ ] }),
4210
+ lock: /* @__PURE__ */ a3($, { children: [
4211
+ /* @__PURE__ */ a3("rect", { x: "4.5", y: "9", width: "11", height: "8", rx: "1.8" }),
4212
+ /* @__PURE__ */ a3("path", { d: "M7 9V6.5a3 3 0 0 1 6 0V9" })
4213
+ ] }),
4214
+ // A diagonal across a box: price to bar kept in step.
4215
+ ratio: /* @__PURE__ */ a3($, { children: [
4216
+ /* @__PURE__ */ a3("rect", { x: "3.5", y: "3.5", width: "13", height: "13", rx: "2" }),
4217
+ /* @__PURE__ */ a3("path", { d: "M6.5 13.5l7-7M10.5 6.5h3v3" })
4218
+ ] }),
4219
+ settings: /* @__PURE__ */ a3($, { children: [
4220
+ /* @__PURE__ */ a3("circle", { cx: "10", cy: "10", r: "2.6" }),
4221
+ /* @__PURE__ */ a3("path", { d: "M10 2.8v2.1M10 15.1v2.1M2.8 10h2.1M15.1 10h2.1M4.9 4.9l1.5 1.5M13.6 13.6l1.5 1.5M4.9 15.1l1.5-1.5M13.6 6.4l1.5-1.5" })
4222
+ ] }),
4223
+ eye: /* @__PURE__ */ a3($, { children: [
4224
+ /* @__PURE__ */ a3("path", { d: "M2 10s3-5.5 8-5.5S18 10 18 10s-3 5.5-8 5.5S2 10 2 10z" }),
4225
+ /* @__PURE__ */ a3("circle", { cx: "10", cy: "10", r: "2.3" })
4226
+ ] }),
4227
+ clock: /* @__PURE__ */ a3($, { children: [
4228
+ /* @__PURE__ */ a3("circle", { cx: "10", cy: "10", r: "7" }),
4229
+ /* @__PURE__ */ a3("path", { d: "M10 6v4l2.5 1.5" })
4230
+ ] })
4231
+ };
4232
+ function MenuIcon({ name }) {
4233
+ const shared = name === "alert" ? /* @__PURE__ */ a3(BellIcon, {}) : name === "line" ? /* @__PURE__ */ a3(HorizontalLineIcon, {}) : name === "date" ? /* @__PURE__ */ a3(CalendarIcon, {}) : name === "reset" ? /* @__PURE__ */ a3(ResetIcon, {}) : null;
4234
+ return /* @__PURE__ */ a3("span", { class: "fnc-menu-icon", children: shared ?? /* @__PURE__ */ a3(Glyph, { children: GLYPHS[name] }) });
4235
+ }
4236
+
4237
+ // src/components/context-menu.tsx
4191
4238
  var MARGIN2 = 8;
4192
4239
  function ContextMenu({ ctx }) {
4193
4240
  const s3 = useStore(ctx.store);
@@ -4229,8 +4276,8 @@ function ContextMenu({ ctx }) {
4229
4276
  const precision = s3.symbol?.pricePrecision ?? 2;
4230
4277
  const extra = ctx.contextMenuItems?.({ ...target, chart: ctx.chart }) ?? [];
4231
4278
  const items = [
4232
- { label: t3.undo, shortcut: `${mod}Z`, disabled: !s3.canUndo, onSelect: () => ctx.chart.undo() },
4233
- { label: t3.redo, shortcut: `${mod}${mac ? "\u21E7" : "Shift+"}Z`, disabled: !s3.canRedo, onSelect: () => ctx.chart.redo() },
4279
+ { label: t3.undo, icon: "undo", shortcut: `${mod}Z`, disabled: !s3.canUndo, onSelect: () => ctx.chart.undo() },
4280
+ { label: t3.redo, icon: "redo", shortcut: `${mod}${mac ? "\u21E7" : "Shift+"}Z`, disabled: !s3.canRedo, onSelect: () => ctx.chart.redo() },
4234
4281
  "separator",
4235
4282
  ...extra.length ? [...extra, "separator"] : []
4236
4283
  ];
@@ -4238,19 +4285,20 @@ function ContextMenu({ ctx }) {
4238
4285
  const time = target.time ?? ctx.chart.bars[ctx.chart.bars.length - 1]?.time ?? Date.now();
4239
4286
  items.push({
4240
4287
  label: t3.horizontalAt.replace("{price}", formatPrice2(price, precision)),
4288
+ icon: "line",
4241
4289
  onSelect: () => ctx.chart.addDrawing({ type: "horizontal", points: [{ time, price }] })
4242
4290
  });
4243
4291
  }
4244
4292
  const { zoomAnimation, scrollInertia, lockView, lockRatio } = ctx.chart.settings;
4245
4293
  const smooth = zoomAnimation && scrollInertia;
4246
4294
  items.push(
4247
- { label: t3.goToDateMore, onSelect: () => ctx.store.set({ dialog: { kind: "goToDate" } }) },
4248
- { label: t3.smoothScroll, checked: smooth, onSelect: () => ctx.chart.setSettings({ smoothScroll: !smooth }) },
4249
- { label: t3.lockView, checked: lockView, onSelect: () => ctx.chart.setSettings({ lockView: !lockView }) },
4250
- { label: t3.lockRatio, checked: lockRatio, onSelect: () => ctx.chart.setSettings({ lockRatio: !lockRatio }) },
4295
+ { label: t3.goToDateMore, icon: "date", onSelect: () => ctx.store.set({ dialog: { kind: "goToDate" } }) },
4296
+ { label: t3.smoothScroll, icon: "smooth", checked: smooth, onSelect: () => ctx.chart.setSettings({ smoothScroll: !smooth }) },
4297
+ { label: t3.lockView, icon: "lock", checked: lockView, onSelect: () => ctx.chart.setSettings({ lockView: !lockView }) },
4298
+ { label: t3.lockRatio, icon: "ratio", checked: lockRatio, onSelect: () => ctx.chart.setSettings({ lockRatio: !lockRatio }) },
4251
4299
  "separator",
4252
- { label: t3.resetChart, disabled: lockView, onSelect: () => ctx.chart.resetView() },
4253
- { label: t3.chartSettingsMore, onSelect: () => ctx.store.set({ dialog: { kind: "chartSettings" } }) }
4300
+ { label: t3.resetChart, icon: "reset", disabled: lockView, onSelect: () => ctx.chart.resetView() },
4301
+ { label: t3.chartSettingsMore, icon: "settings", onSelect: () => ctx.store.set({ dialog: { kind: "chartSettings" } }) }
4254
4302
  );
4255
4303
  return /* @__PURE__ */ a3("div", { class: "fnc-menu fnc-ctx-menu", role: "menu", ref, onContextMenu: (e3) => e3.preventDefault(), children: items.map(
4256
4304
  (item) => item === "separator" ? /* @__PURE__ */ a3("div", { class: "fnc-ctx-sep", role: "separator" }) : /* @__PURE__ */ a3(
@@ -4265,10 +4313,10 @@ function ContextMenu({ ctx }) {
4265
4313
  item.onSelect();
4266
4314
  },
4267
4315
  children: [
4268
- item.icon === "alert" && /* @__PURE__ */ a3(BellIcon, {}),
4269
- /* @__PURE__ */ a3("span", { children: item.label }),
4316
+ item.icon ? /* @__PURE__ */ a3(MenuIcon, { name: item.icon }) : /* @__PURE__ */ a3("span", { class: "fnc-menu-icon" }),
4317
+ /* @__PURE__ */ a3("span", { class: "fnc-menu-label", children: item.label }),
4270
4318
  item.shortcut && /* @__PURE__ */ a3("kbd", { children: item.shortcut }),
4271
- item.checked && /* @__PURE__ */ a3(CheckIcon, {})
4319
+ item.checked && /* @__PURE__ */ a3("span", { class: "fnc-menu-check-mark", children: /* @__PURE__ */ a3(CheckIcon, {}) })
4272
4320
  ]
4273
4321
  }
4274
4322
  )
@@ -4345,7 +4393,7 @@ function PriceAxisPlus({ ctx }) {
4345
4393
  item.onSelect();
4346
4394
  },
4347
4395
  children: [
4348
- item.icon === "alert" ? /* @__PURE__ */ a3(BellIcon, {}) : item.icon === "line" ? /* @__PURE__ */ a3(HorizontalLineIcon, {}) : null,
4396
+ item.icon && /* @__PURE__ */ a3(MenuIcon, { name: item.icon }),
4349
4397
  /* @__PURE__ */ a3("span", { children: item.label })
4350
4398
  ]
4351
4399
  }
@@ -4502,18 +4550,26 @@ function Legend({ ctx }) {
4502
4550
  const ref = T2(null);
4503
4551
  const tracking = T2(false);
4504
4552
  tracking.current = ctx.legendValues === "crosshair" && !!hover;
4553
+ const hovering = T2(false);
4554
+ hovering.current = !!hover;
4555
+ const measure = T2(() => {
4556
+ });
4505
4557
  A2(() => {
4506
4558
  const el = ref.current;
4507
4559
  if (!el) return;
4508
4560
  const update = () => {
4509
- if (tracking.current) return;
4561
+ if (tracking.current || hovering.current) return;
4510
4562
  const floating = ctx.legendValues === "crosshair" ? el.querySelector(".fnc-legend-values") : null;
4511
4563
  ctx.chart.setTopInset(el.offsetTop + el.offsetHeight - (floating ? floating.offsetHeight + 2 : 0) + 4);
4512
4564
  };
4565
+ measure.current = update;
4513
4566
  const ro = new ResizeObserver(update);
4514
4567
  ro.observe(el);
4515
4568
  return () => ro.disconnect();
4516
4569
  }, [ctx.chart]);
4570
+ A2(() => {
4571
+ if (!hover) measure.current();
4572
+ }, [!!hover]);
4517
4573
  if (!s3.symbol) return /* @__PURE__ */ a3("div", { class: "fnc-legend", ref });
4518
4574
  const bars = ctx.chart.bars;
4519
4575
  const bar = hover?.bar ?? bars[bars.length - 1];
@@ -5556,6 +5612,8 @@ var CSS = (
5556
5612
 
5557
5613
  /* A setting in a menu (\uBD80\uB4DC\uB7EC\uC6B4 \uC2A4\uD06C\uB864\xB7\uD655\uB300): the check at the end. */
5558
5614
  .fnc-menu-check svg { margin-left: auto; color: var(--fnc-accent); }
5615
+ /* The row's own glyph stays neutral; only the check mark is in the accent. */
5616
+ .fnc-menu-check .fnc-menu-icon svg { margin-left: 0; color: var(--fnc-text-2); }
5559
5617
 
5560
5618
  /* \uB0A0\uC9DC\uB85C \uC774\uB3D9: a date typed or picked on a month calendar. */
5561
5619
  .fnc-goto-dialog { width: min(320px, calc(100% - 32px)); }
@@ -5588,8 +5646,10 @@ var CSS = (
5588
5646
  .fnc-selbar-action.is-text { width: auto; padding: 0 8px; font-size: 12px; font-weight: 600; }
5589
5647
  .fnc-selbar-action.is-on { color: var(--fnc-accent); }
5590
5648
  .fnc-selbar-action.is-on svg path:first-child { fill: currentColor; }
5591
- .fnc-axis-plus-menu .fnc-menu-item, .fnc-ctx-menu .fnc-menu-item:has(svg) { color: var(--fnc-text); font-weight: 600; }
5592
- .fnc-axis-plus-menu .fnc-menu-item svg, .fnc-ctx-menu .fnc-menu-item svg { flex: none; color: var(--fnc-text-2); }
5649
+ .fnc-axis-plus-menu .fnc-menu-item { color: var(--fnc-text); font-weight: 600; }
5650
+ /* A menu row's glyph: one 18px column, so every label starts at the same x. */
5651
+ .fnc-menu-icon { display: inline-flex; align-items: center; justify-content: center; flex: none; width: 18px; height: 18px; color: var(--fnc-text-2); }
5652
+ .fnc-menu-icon svg { width: 16px; height: 16px; }
5593
5653
 
5594
5654
  /* \uAE30\uAC04 \xB7 \uB0A0\uC9DC\uB85C \uC774\uB3D9: a row under the chart. */
5595
5655
  .fnc-rangebar-host { flex: none; border-top: 1px solid var(--fnc-border); }
@@ -5973,7 +6033,9 @@ var CSS = (
5973
6033
 
5974
6034
  /* \u2500\u2500 Right-click menu \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
5975
6035
  .fnc-ctx-menu { top: 0; left: 0; z-index: 40; min-width: 220px; pointer-events: auto; }
5976
- .fnc-ctx-menu .fnc-menu-item { justify-content: space-between; gap: 24px; color: var(--fnc-text); }
6036
+ .fnc-ctx-menu .fnc-menu-item { gap: 10px; color: var(--fnc-text); }
6037
+ .fnc-ctx-menu .fnc-menu-label { flex: 1; min-width: 0; margin-right: 14px; }
6038
+ .fnc-menu-check-mark { display: inline-flex; flex: none; color: var(--fnc-accent); }
5977
6039
  .fnc-ctx-menu .fnc-menu-item:disabled { color: var(--fnc-text-2); }
5978
6040
  .fnc-ctx-menu kbd { font: inherit; font-size: 12px; color: var(--fnc-text-2); }
5979
6041
  .fnc-ctx-sep { height: 1px; margin: 4px 6px; background: var(--fnc-border); }
@@ -6106,7 +6168,9 @@ var CSS = (
6106
6168
  .fnc-dialog.fnc-settings-dialog { width: min(940px, calc(100% - 32px)); height: min(660px, 100%); max-height: none; }
6107
6169
  .fnc-settings-body { display: flex; flex: 1; min-height: 0; }
6108
6170
  .fnc-settings-side { display: flex; flex-direction: column; flex: 1 1 0; min-width: 0; border-right: 1px solid var(--fnc-border); }
6109
- .fnc-settings-side .fnc-settings-tabs { flex: none; padding: 12px 20px 0; }
6171
+ .fnc-settings-side .fnc-settings-tabs { flex: none; gap: 2px; padding: 12px 20px 0; }
6172
+ /* The tabs share the row, each label centred in its share. */
6173
+ .fnc-settings-tabs .fnc-tab { display: inline-flex; align-items: center; justify-content: center; flex: 1 1 0; min-width: 0; padding: 0 4px; }
6110
6174
  .fnc-root .fnc-dialog form.fnc-settings-form { flex: 1; min-height: 0; overflow-y: auto; }
6111
6175
  .fnc-settings-preview { display: flex; flex-direction: column; gap: 8px; flex: 1.2 1 0; min-width: 0; padding: 20px; }
6112
6176
  .fnc-settings-preview-chart { position: relative; flex: 1; min-height: 160px; border: 1px solid var(--fnc-border); border-radius: 12px; overflow: hidden; }
@@ -6115,8 +6179,8 @@ var CSS = (
6115
6179
  .fnc-backdrop:has(> .fnc-settings-dialog) { padding: 0; align-items: stretch; }
6116
6180
  .fnc-dialog.fnc-settings-dialog { width: 100%; height: 100%; border-radius: 0; }
6117
6181
  .fnc-settings-dialog .fnc-dialog-head { height: 44px; }
6118
- .fnc-settings-side .fnc-settings-tabs { gap: 2px; padding: 6px 12px 0; }
6119
- .fnc-settings-tabs .fnc-tab { flex: 1 1 auto; padding: 0 6px; font-size: 12.5px; }
6182
+ .fnc-settings-side .fnc-settings-tabs { padding: 6px 12px 0; }
6183
+ .fnc-settings-tabs .fnc-tab { padding: 0 6px; font-size: 12.5px; }
6120
6184
  .fnc-settings-preview { padding: 8px 12px; }
6121
6185
  .fnc-settings-preview .fnc-section, .fnc-settings-preview .fnc-toggle-hint { display: none; }
6122
6186
  .fnc-settings-preview-chart .fnc-ranges { display: none; }
@@ -6182,9 +6246,8 @@ var CSS = (
6182
6246
  .fnc-settings-preview-chart { flex: none; height: clamp(170px, 34dvh, 280px); min-height: 0; }
6183
6247
  .fnc-settings-preview-chart .fnc-ranges { display: none; }
6184
6248
  .fnc-settings-side { flex: 1; min-height: 0; border-right: 0; }
6185
- .fnc-settings-side .fnc-settings-tabs { gap: 2px; padding: 8px 12px 0; }
6186
- /* The four tabs share the width instead of running off the edge. */
6187
- .fnc-settings-tabs .fnc-tab { flex: 1 1 auto; padding: 0 6px; font-size: 12.5px; }
6249
+ .fnc-settings-side .fnc-settings-tabs { padding: 8px 12px 0; }
6250
+ .fnc-settings-tabs .fnc-tab { padding: 0 6px; font-size: 12.5px; }
6188
6251
  .fnc-form-actions.fnc-settings-actions { padding: 8px 16px; }
6189
6252
  }
6190
6253
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@funnest/charts-ui",
3
- "version": "0.11.1",
3
+ "version": "0.11.2",
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.1"
45
+ "@funnest/charts": "0.11.2"
46
46
  },
47
47
  "devDependencies": {
48
48
  "preact": "^11.2.0"