@funnest/charts-ui 0.11.14 → 0.11.16

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,13 @@
1
+ /** @jsxImportSource preact */
2
+ import type { IndicatorConfig } from '@funnest/charts';
3
+ import type { WidgetContext } from '../context.js';
4
+ export interface IndicatorTemplate {
5
+ name: string;
6
+ indicators: IndicatorConfig[];
7
+ /** What it holds, as the legend names them (for the list). */
8
+ titles: string[];
9
+ }
10
+ export declare function readIndicatorTemplates(): IndicatorTemplate[];
11
+ export declare function IndicatorTemplates({ ctx }: {
12
+ ctx: WidgetContext;
13
+ }): import("preact").JSX.Element;
package/dist/context.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { Chart, ChartContextMenu, ChartLayout, ChartType, CompareInfo, CursorMode, Datafeed, Drawing, DrawingType, IndicatorConfig, LegendItem, Locale, ReplayStatus, Resolution, SymbolInfo } from '@funnest/charts';
1
+ import type { Chart, ChartContextMenu, ChartLayout, ChartSettings, ChartType, CompareInfo, CursorMode, Datafeed, Drawing, DrawingType, IndicatorConfig, LegendItem, Locale, ReplayStatus, Resolution, SymbolInfo } from '@funnest/charts';
2
2
  import type { LayoutId } from './layouts.js';
3
3
  import type { WidgetStorage } from './storage.js';
4
4
  import type { Strings } from './i18n.js';
@@ -126,7 +126,7 @@ export type ToolsMenuItems = (chart: Chart) => ToolsMenuItem[];
126
126
  */
127
127
  export type LegendValues = 'always' | 'crosshair';
128
128
  export interface IntervalGroup {
129
- id: 'minutes' | 'hours' | 'days';
129
+ id: 'ticks' | 'minutes' | 'hours' | 'days';
130
130
  intervals: Resolution[];
131
131
  }
132
132
  /** A tab in the symbol search dialog. */
@@ -223,4 +223,6 @@ export interface MultiControls {
223
223
  setSync(patch: Partial<LayoutSync>): void;
224
224
  activate(index: number): void;
225
225
  toggleMaximize(index?: number): void;
226
+ /** Applies a settings patch to every pane (widget-wide looks such as the watermarks). */
227
+ applySettings(patch: Partial<ChartSettings>): void;
226
228
  }
package/dist/i18n.d.ts CHANGED
@@ -164,6 +164,10 @@ export declare const STRINGS: {
164
164
  saveTemplate: string;
165
165
  templateName: string;
166
166
  noTemplates: string;
167
+ indicatorTemplates: string;
168
+ saveIndicatorTemplate: string;
169
+ noIndicatorTemplates: string;
170
+ noIndicatorsToSave: string;
167
171
  deleteTemplate: string;
168
172
  lineWidth: string;
169
173
  lineStyle: string;
@@ -263,6 +267,7 @@ export declare const STRINGS: {
263
267
  point: string;
264
268
  price: string;
265
269
  time: string;
270
+ intervalTicks: string;
266
271
  intervalMinutes: string;
267
272
  intervalHours: string;
268
273
  intervalDays: string;
@@ -493,6 +498,10 @@ export declare const STRINGS: {
493
498
  saveTemplate: string;
494
499
  templateName: string;
495
500
  noTemplates: string;
501
+ indicatorTemplates: string;
502
+ saveIndicatorTemplate: string;
503
+ noIndicatorTemplates: string;
504
+ noIndicatorsToSave: string;
496
505
  deleteTemplate: string;
497
506
  lineWidth: string;
498
507
  lineStyle: string;
@@ -592,6 +601,7 @@ export declare const STRINGS: {
592
601
  point: string;
593
602
  price: string;
594
603
  time: string;
604
+ intervalTicks: string;
595
605
  intervalMinutes: string;
596
606
  intervalHours: string;
597
607
  intervalDays: string;
package/dist/index.js CHANGED
@@ -599,6 +599,10 @@ var STRINGS = {
599
599
  saveTemplate: "\uC9C0\uAE08 \uBAA8\uC591\uC744 \uD15C\uD50C\uB9BF\uC73C\uB85C \uC800\uC7A5",
600
600
  templateName: "\uD15C\uD50C\uB9BF \uC774\uB984",
601
601
  noTemplates: "\uC774 \uB3C4\uAD6C\uB85C \uC800\uC7A5\uD55C \uD15C\uD50C\uB9BF\uC774 \uC5C6\uC5B4\uC694",
602
+ indicatorTemplates: "\uC9C0\uD45C \uD15C\uD50C\uB9BF",
603
+ saveIndicatorTemplate: "\uC9C0\uAE08 \uC9C0\uD45C\uB97C \uD15C\uD50C\uB9BF\uC73C\uB85C \uC800\uC7A5",
604
+ noIndicatorTemplates: "\uC800\uC7A5\uD55C \uC9C0\uD45C \uD15C\uD50C\uB9BF\uC774 \uC5C6\uC5B4\uC694. \uC9C0\uD45C\uB97C \uB123\uC740 \uB4A4 \uC544\uB798\uC5D0\uC11C \uC800\uC7A5\uD558\uBA74 \uB2E4\uB978 \uCC28\uD2B8\uC5D0\uB3C4 \uD55C \uBC88\uC5D0 \uB123\uC744 \uC218 \uC788\uC5B4\uC694.",
605
+ noIndicatorsToSave: "\uC800\uC7A5\uD560 \uC9C0\uD45C\uAC00 \uC5C6\uC5B4\uC694",
602
606
  deleteTemplate: "\uD15C\uD50C\uB9BF \uC9C0\uC6B0\uAE30",
603
607
  lineWidth: "\uC120 \uAD75\uAE30",
604
608
  lineStyle: "\uC120 \uBAA8\uC591",
@@ -699,6 +703,7 @@ var STRINGS = {
699
703
  price: "\uAC00\uACA9",
700
704
  time: "\uC2DC\uAC04",
701
705
  // intervals
706
+ intervalTicks: "\uD2F1",
702
707
  intervalMinutes: "\uBD84",
703
708
  intervalHours: "\uC2DC\uAC04",
704
709
  intervalDays: "\uC77C",
@@ -930,6 +935,10 @@ var STRINGS = {
930
935
  saveTemplate: "Save this look as a template",
931
936
  templateName: "Template name",
932
937
  noTemplates: "No templates for this tool yet",
938
+ indicatorTemplates: "Indicator templates",
939
+ saveIndicatorTemplate: "Save these indicators as a template",
940
+ noIndicatorTemplates: "No indicator templates yet. Add indicators, save them below, and put them on any chart in one go.",
941
+ noIndicatorsToSave: "No indicators to save",
933
942
  deleteTemplate: "Delete template",
934
943
  lineWidth: "Line width",
935
944
  lineStyle: "Line style",
@@ -1029,6 +1038,7 @@ var STRINGS = {
1029
1038
  point: "Point",
1030
1039
  price: "Price",
1031
1040
  time: "Time",
1041
+ intervalTicks: "Ticks",
1032
1042
  intervalMinutes: "Minutes",
1033
1043
  intervalHours: "Hours",
1034
1044
  intervalDays: "Days",
@@ -3109,10 +3119,11 @@ function SettingsDialog({ ctx }) {
3109
3119
  ...appToggles.length > 0 ? [["symbol", t3.settingsSymbol]] : []
3110
3120
  ];
3111
3121
  const shown = tabs.some(([k2]) => k2 === tab) ? tab : "look";
3122
+ const setRow = (key, on) => ctx.multi && WATERMARK_ROWS.some((r3) => r3.key === key) ? ctx.multi.applySettings({ [key]: on }) : set({ [key]: on });
3112
3123
  const toggles = (rows) => rows.map(({ key, label, hint }) => /* @__PURE__ */ a3("label", { class: "fnc-row fnc-toggle-row", children: [
3113
3124
  /* @__PURE__ */ a3("span", { class: "fnc-toggle-label", children: t3[label] }),
3114
3125
  hint && /* @__PURE__ */ a3(Info, { text: t3[hint] }),
3115
- /* @__PURE__ */ a3("input", { type: "checkbox", role: "switch", class: "fnc-switch", checked: settings[key], onChange: (e3) => set({ [key]: e3.currentTarget.checked }) })
3126
+ /* @__PURE__ */ a3("input", { type: "checkbox", role: "switch", class: "fnc-switch", checked: settings[key], onChange: (e3) => setRow(key, e3.currentTarget.checked) })
3116
3127
  ] }));
3117
3128
  const anchor = T2(null);
3118
3129
  const layer = usePageLayer(anchor, settings);
@@ -3507,8 +3518,9 @@ function Dialogs({ ctx }) {
3507
3518
  }
3508
3519
 
3509
3520
  // src/components/interval-picker.tsx
3510
- import { derivedBase as derivedBase2, resolutionToMs as resolutionToMs3 } from "@funnest/charts";
3521
+ import { derivedBase as derivedBase2, resolutionToMs as resolutionToMs3, tickCount } from "@funnest/charts";
3511
3522
  var GROUP_LABEL = {
3523
+ ticks: "intervalTicks",
3512
3524
  minutes: "intervalMinutes",
3513
3525
  hours: "intervalHours",
3514
3526
  days: "intervalDays"
@@ -3538,7 +3550,8 @@ function IntervalPicker({ ctx }) {
3538
3550
  };
3539
3551
  }, [open]);
3540
3552
  const supported = s3.symbol?.supportedResolutions;
3541
- const isSupported = (r3) => !supported || supported.includes(r3) || !!derivedBase2(r3, supported);
3553
+ const isSupported = (r3) => tickCount(r3) !== null ? !!supported?.includes(r3) : !supported || supported.includes(r3) || !!derivedBase2(r3, supported);
3554
+ const groups = ctx.intervalGroups.filter((g3) => g3.id !== "ticks" || g3.intervals.some(isSupported));
3542
3555
  const listed = new Set(ctx.intervalGroups.flatMap((g3) => g3.intervals));
3543
3556
  const custom = s3.customIntervals.filter((r3) => !listed.has(r3)).sort((a4, b) => resolutionToMs3(a4) - resolutionToMs3(b));
3544
3557
  const order = [...ctx.intervalGroups.flatMap((g3) => g3.intervals), ...custom];
@@ -3586,7 +3599,7 @@ function IntervalPicker({ ctx }) {
3586
3599
  }
3587
3600
  ),
3588
3601
  open && /* @__PURE__ */ a3("div", { class: "fnc-menu fnc-interval-menu", role: "menu", ref: menuRef, children: [
3589
- ctx.intervalGroups.map((group) => /* @__PURE__ */ a3("div", { class: "fnc-menu-group", role: "group", "aria-label": t3[GROUP_LABEL[group.id]], children: [
3602
+ groups.map((group) => /* @__PURE__ */ a3("div", { class: "fnc-menu-group", role: "group", "aria-label": t3[GROUP_LABEL[group.id]], children: [
3590
3603
  /* @__PURE__ */ a3("div", { class: "fnc-menu-title", children: t3[GROUP_LABEL[group.id]] }),
3591
3604
  group.intervals.map((r3) => {
3592
3605
  const favorite = s3.favoriteIntervals.includes(r3);
@@ -4293,6 +4306,108 @@ function ToolsMenu({ ctx }) {
4293
4306
  ] });
4294
4307
  }
4295
4308
 
4309
+ // src/components/indicator-templates.tsx
4310
+ var KEY = "fnc-indicator-templates";
4311
+ var MAX = 30;
4312
+ function readIndicatorTemplates() {
4313
+ try {
4314
+ const raw = localStorage.getItem(KEY);
4315
+ const list = raw ? JSON.parse(raw) : [];
4316
+ return Array.isArray(list) ? list.filter((x2) => !!x2 && typeof x2.name === "string" && Array.isArray(x2.indicators)) : [];
4317
+ } catch {
4318
+ return [];
4319
+ }
4320
+ }
4321
+ function writeIndicatorTemplates(list) {
4322
+ try {
4323
+ localStorage.setItem(KEY, JSON.stringify(list));
4324
+ } catch {
4325
+ }
4326
+ }
4327
+ function IndicatorTemplates({ ctx }) {
4328
+ const s3 = useStore(ctx.store);
4329
+ const t3 = stringsOf(s3);
4330
+ const [open, setOpen] = d2(false);
4331
+ const [list, setList] = d2(() => readIndicatorTemplates());
4332
+ const [naming, setNaming] = d2(null);
4333
+ const ref = T2(null);
4334
+ const menuRef = useKeepInView(open);
4335
+ A2(() => {
4336
+ if (!open) return;
4337
+ setList(readIndicatorTemplates());
4338
+ const onDown = (e3) => !ref.current?.contains(e3.target) && setOpen(false);
4339
+ const onKey = (e3) => e3.key === "Escape" && setOpen(false);
4340
+ document.addEventListener("pointerdown", onDown);
4341
+ document.addEventListener("keydown", onKey);
4342
+ return () => {
4343
+ document.removeEventListener("pointerdown", onDown);
4344
+ document.removeEventListener("keydown", onKey);
4345
+ };
4346
+ }, [open]);
4347
+ const keep = (next) => {
4348
+ setList(next);
4349
+ writeIndicatorTemplates(next);
4350
+ };
4351
+ const current = ctx.chart.getIndicators();
4352
+ const save = () => {
4353
+ const name = (naming ?? "").trim().slice(0, 30);
4354
+ if (!name || current.length === 0) return setNaming(null);
4355
+ const titles = ctx.chart.indicatorLegend().map((i3) => i3.title);
4356
+ keep([{ name, indicators: JSON.parse(JSON.stringify(current)), titles }, ...list.filter((x2) => x2.name !== name)].slice(0, MAX));
4357
+ setNaming(null);
4358
+ };
4359
+ const apply = (tpl) => {
4360
+ ctx.chart.setIndicators(JSON.parse(JSON.stringify(tpl.indicators)));
4361
+ setOpen(false);
4362
+ };
4363
+ return /* @__PURE__ */ a3("div", { class: "fnc-menu-wrap fnc-indtpl-wrap", ref, children: [
4364
+ /* @__PURE__ */ a3(
4365
+ "button",
4366
+ {
4367
+ class: "fnc-btn fnc-btn-indtpl",
4368
+ "data-tip": t3.indicatorTemplates,
4369
+ "aria-label": t3.indicatorTemplates,
4370
+ "aria-haspopup": "menu",
4371
+ "aria-expanded": open,
4372
+ onClick: () => {
4373
+ setNaming(null);
4374
+ setOpen(!open);
4375
+ },
4376
+ children: /* @__PURE__ */ a3(TemplateIcon, {})
4377
+ }
4378
+ ),
4379
+ open && /* @__PURE__ */ a3("div", { class: "fnc-menu fnc-template-menu fnc-indtpl-menu", role: "menu", "aria-label": t3.indicatorTemplates, ref: menuRef, children: [
4380
+ /* @__PURE__ */ a3("div", { class: "fnc-menu-title", children: t3.indicatorTemplates }),
4381
+ list.length === 0 && /* @__PURE__ */ a3("div", { class: "fnc-menu-note", children: t3.noIndicatorTemplates }),
4382
+ list.map((tpl) => /* @__PURE__ */ a3("div", { class: "fnc-template-row", children: [
4383
+ /* @__PURE__ */ a3("button", { class: "fnc-menu-item fnc-indtpl-item", role: "menuitem", onClick: () => apply(tpl), children: [
4384
+ /* @__PURE__ */ a3("span", { class: "fnc-indtpl-name", children: tpl.name }),
4385
+ /* @__PURE__ */ a3("small", { class: "fnc-indtpl-sub", children: tpl.titles.length ? tpl.titles.join(" \xB7 ") : `${tpl.indicators.length}` })
4386
+ ] }),
4387
+ /* @__PURE__ */ a3("button", { class: "fnc-ind-btn", "data-tip": t3.deleteTemplate, "aria-label": `${tpl.name} ${t3.deleteTemplate}`, onClick: () => keep(list.filter((x2) => x2 !== tpl)), children: /* @__PURE__ */ a3(SmallCloseIcon, {}) })
4388
+ ] })),
4389
+ /* @__PURE__ */ a3("div", { class: "fnc-menu-sep" }),
4390
+ naming === null ? /* @__PURE__ */ a3("button", { class: "fnc-menu-item", role: "menuitem", disabled: current.length === 0, onClick: () => setNaming(""), children: current.length === 0 ? t3.noIndicatorsToSave : t3.saveIndicatorTemplate }) : /* @__PURE__ */ a3(
4391
+ "input",
4392
+ {
4393
+ class: "fnc-selbar-text fnc-template-name",
4394
+ value: naming,
4395
+ placeholder: t3.templateName,
4396
+ "aria-label": t3.templateName,
4397
+ maxLength: 30,
4398
+ autoFocus: true,
4399
+ onInput: (e3) => setNaming(e3.target.value),
4400
+ onKeyDown: (e3) => {
4401
+ e3.stopPropagation();
4402
+ if (e3.key === "Enter") save();
4403
+ if (e3.key === "Escape") setNaming(null);
4404
+ }
4405
+ }
4406
+ )
4407
+ ] })
4408
+ ] });
4409
+ }
4410
+
4296
4411
  // src/components/toolbar.tsx
4297
4412
  function Toolbar({ ctx }) {
4298
4413
  const s3 = useStore(ctx.store);
@@ -4333,6 +4448,7 @@ function Toolbar({ ctx }) {
4333
4448
  ]
4334
4449
  }
4335
4450
  ),
4451
+ /* @__PURE__ */ a3(IndicatorTemplates, { ctx }),
4336
4452
  /* @__PURE__ */ a3(ToolsMenu, { ctx })
4337
4453
  ] }),
4338
4454
  /* @__PURE__ */ a3("div", { class: "fnc-sep" }),
@@ -6222,6 +6338,11 @@ var CSS = (
6222
6338
  .fnc-tools-seg button { display: inline-flex; align-items: center; justify-content: center; gap: 4px; min-width: 0; padding: 0 6px; }
6223
6339
  .fnc-tools-seg svg { width: 16px; height: 16px; flex: none; }
6224
6340
  .fnc-template-menu { min-width: 220px; }
6341
+ .fnc-indtpl-menu { width: 280px; max-height: 60vh; overflow-y: auto; }
6342
+ .fnc-indtpl-menu .fnc-menu-note { line-height: 1.5; }
6343
+ .fnc-indtpl-item { flex-direction: column; align-items: flex-start !important; gap: 1px !important; padding-top: 6px; padding-bottom: 6px; }
6344
+ .fnc-indtpl-name { font-weight: 600; }
6345
+ .fnc-template-row .fnc-menu-item .fnc-indtpl-sub { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; color: var(--fnc-text-2); }
6225
6346
  .fnc-levels-menu { min-width: 340px; }
6226
6347
  .fnc-level-text { flex: 1; min-width: 0; width: 110px; height: 28px; padding: 0 8px; font-size: 13px; }
6227
6348
  .fnc-options-menu { min-width: 280px; max-height: min(70vh, 560px); overflow-y: auto; }
@@ -7090,6 +7211,7 @@ function createPane(shell, config) {
7090
7211
 
7091
7212
  // src/trading-chart.tsx
7092
7213
  var DEFAULT_INTERVAL_GROUPS = [
7214
+ { id: "ticks", intervals: ["10T", "100T", "1000T"] },
7093
7215
  { id: "minutes", intervals: ["1", "5", "15", "30"] },
7094
7216
  { id: "hours", intervals: ["60", "240"] },
7095
7217
  { id: "days", intervals: ["1D", "1W", "1M", "3M", "6M", "12M"] }
@@ -7304,7 +7426,10 @@ function createMultiChart(container, options) {
7304
7426
  setLayout: (layout) => setLayout(layout),
7305
7427
  setSync: (patch) => setSync(patch),
7306
7428
  activate: (index) => activate(index),
7307
- toggleMaximize: (index) => toggleMaximize(index)
7429
+ toggleMaximize: (index) => toggleMaximize(index),
7430
+ applySettings: (patch) => {
7431
+ for (const p3 of panes) p3.chart.setSettings(patch);
7432
+ }
7308
7433
  };
7309
7434
  function makePane(index, spec) {
7310
7435
  const pane = createPane(shell, {
@@ -7378,11 +7503,20 @@ function createMultiChart(container, options) {
7378
7503
  function ensurePanes(count) {
7379
7504
  for (let i3 = panes.length; i3 < count; i3++) {
7380
7505
  const src = panes[store.get().active] ?? panes[0];
7381
- const spec = paneSpecs[i3] ?? {
7506
+ const given = paneSpecs[i3];
7507
+ const spec = given ?? {
7382
7508
  symbol: src?.chart.symbolInfo?.symbol ?? paneSpecs[0].symbol,
7383
7509
  resolution: src?.chart.currentResolution ?? src?.store.get().resolution ?? resolution
7384
7510
  };
7385
- makePane(i3, spec);
7511
+ const pane = makePane(i3, spec);
7512
+ if (!src) continue;
7513
+ if (!given && src.chart.symbolInfo) {
7514
+ const state = src.chart.save();
7515
+ void pane.chart.load({ ...state, drawings: {} });
7516
+ } else {
7517
+ const { symbolWatermark, replayWatermark } = src.chart.settings;
7518
+ pane.chart.setSettings({ symbolWatermark, replayWatermark });
7519
+ }
7386
7520
  }
7387
7521
  }
7388
7522
  function buildNode(node, path, layout) {
@@ -4,7 +4,7 @@ import type { ContextMenuItems, DrawingActions, IntervalGroup, LegendValues, Pri
4
4
  import type { Strings } from './i18n.js';
5
5
  import { type ColorScheme, type TradingChartSlots } from './shell.js';
6
6
  export type { ColorScheme, TradingChartSlots } from './shell.js';
7
- /** Interval menu: 분 | 시간 | 일. '12M' is shown as 1년. */
7
+ /** Interval menu: 틱 | 분 | 시간 | 일. '12M' is shown as 1년. 틱 shows only on a feed that lists tick intervals. */
8
8
  export declare const DEFAULT_INTERVAL_GROUPS: readonly IntervalGroup[];
9
9
  /** Toolbar chips until the user stars their own. */
10
10
  export declare const DEFAULT_FAVORITE_INTERVALS: readonly Resolution[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@funnest/charts-ui",
3
- "version": "0.11.14",
3
+ "version": "0.11.16",
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.14"
45
+ "@funnest/charts": "0.11.16"
46
46
  },
47
47
  "devDependencies": {
48
48
  "preact": "^11.2.0"