@funnest/charts-ui 0.8.3 → 0.8.4

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,9 @@
1
+ import type { WidgetContext } from '../context.js';
2
+ /**
3
+ * 날짜로 이동 (from the right-click menu): a date — typed, or picked on a month calendar (‹ › a
4
+ * month, « » a year) — and 이동. Older history is loaded first when the date is before what's
5
+ * on the chart; the view keeps its zoom, centered on that day.
6
+ */
7
+ export declare function GoToDateDialog({ ctx }: {
8
+ ctx: WidgetContext;
9
+ }): import("preact").JSX.Element;
package/dist/context.d.ts CHANGED
@@ -34,6 +34,8 @@ export interface UiState {
34
34
  id: string;
35
35
  } | {
36
36
  kind: 'chartSettings';
37
+ } | {
38
+ kind: 'goToDate';
37
39
  } | null;
38
40
  /** Intervals pinned as toolbar chips (★ in the interval menu). */
39
41
  favoriteIntervals: Resolution[];
@@ -60,8 +62,11 @@ export interface UiState {
60
62
  export type ContextMenuItem = {
61
63
  label: string;
62
64
  shortcut?: string;
63
- disabled?: boolean; /** 'alert': a bell before the label. */
65
+ disabled?: boolean;
66
+ /** 'alert': a bell before the label. */
64
67
  icon?: 'alert';
68
+ /** A setting that's on or off: a check mark, and it reads as a checkbox. */
69
+ checked?: boolean;
65
70
  onSelect(): void;
66
71
  } | 'separator';
67
72
  /** Extra right-click items for a click on `chart` (e.g. "create an alert at this price"). */
package/dist/i18n.d.ts CHANGED
@@ -180,6 +180,13 @@ export declare const STRINGS: {
180
180
  range5Y: string;
181
181
  rangeAll: string;
182
182
  goToDate: string;
183
+ goToDateMore: string;
184
+ smoothScroll: string;
185
+ today: string;
186
+ prevMonth: string;
187
+ nextMonth: string;
188
+ prevYear: string;
189
+ nextYear: string;
183
190
  goTo: string;
184
191
  customInterval: string;
185
192
  addInterval: string;
@@ -371,6 +378,13 @@ export declare const STRINGS: {
371
378
  range5Y: string;
372
379
  rangeAll: string;
373
380
  goToDate: string;
381
+ goToDateMore: string;
382
+ smoothScroll: string;
383
+ today: string;
384
+ prevMonth: string;
385
+ nextMonth: string;
386
+ prevYear: string;
387
+ nextYear: string;
374
388
  goTo: string;
375
389
  customInterval: string;
376
390
  addInterval: string;
package/dist/icons.d.ts CHANGED
@@ -4,6 +4,7 @@ export declare const CameraIcon: () => import("preact").JSX.Element;
4
4
  export declare const ExpandIcon: () => import("preact").JSX.Element;
5
5
  export declare const CollapseIcon: () => import("preact").JSX.Element;
6
6
  export declare const MinusIcon: () => import("preact").JSX.Element;
7
+ export declare const CheckIcon: () => import("preact").JSX.Element;
7
8
  export declare const BellIcon: () => import("preact").JSX.Element;
8
9
  export declare const PlusIcon: () => import("preact").JSX.Element;
9
10
  export declare const ChevronLeftIcon: () => import("preact").JSX.Element;
package/dist/index.js CHANGED
@@ -608,6 +608,13 @@ var STRINGS = {
608
608
  range5Y: "5\uB144",
609
609
  rangeAll: "\uC804\uCCB4",
610
610
  goToDate: "\uB0A0\uC9DC\uB85C \uC774\uB3D9",
611
+ goToDateMore: "\uB0A0\uC9DC\uB85C \uC774\uB3D9\u2026",
612
+ smoothScroll: "\uBD80\uB4DC\uB7EC\uC6B4 \uC2A4\uD06C\uB864\xB7\uD655\uB300",
613
+ today: "\uC624\uB298",
614
+ prevMonth: "\uC774\uC804 \uB2EC",
615
+ nextMonth: "\uB2E4\uC74C \uB2EC",
616
+ prevYear: "1\uB144 \uC804",
617
+ nextYear: "1\uB144 \uD6C4",
611
618
  goTo: "\uC774\uB3D9",
612
619
  customInterval: "\uC9C1\uC811 \uCD94\uAC00",
613
620
  addInterval: "\uCD94\uAC00",
@@ -799,6 +806,13 @@ var STRINGS = {
799
806
  range5Y: "5Y",
800
807
  rangeAll: "All",
801
808
  goToDate: "Go to date",
809
+ goToDateMore: "Go to date\u2026",
810
+ smoothScroll: "Smooth scroll & zoom",
811
+ today: "Today",
812
+ prevMonth: "Previous month",
813
+ nextMonth: "Next month",
814
+ prevYear: "A year back",
815
+ nextYear: "A year ahead",
802
816
  goTo: "Go",
803
817
  customInterval: "Add custom",
804
818
  addInterval: "Add",
@@ -860,6 +874,7 @@ var CameraIcon = () => /* @__PURE__ */ a3(Icon, { children: [
860
874
  var ExpandIcon = () => /* @__PURE__ */ a3(Icon, { children: /* @__PURE__ */ a3("path", { d: "M4 8V4h4M16 8V4h-4M4 12v4h4M16 12v4h-4" }) });
861
875
  var CollapseIcon = () => /* @__PURE__ */ a3(Icon, { children: /* @__PURE__ */ a3("path", { d: "M8 4v4H4M12 4v4h4M8 16v-4H4M12 16v-4h4" }) });
862
876
  var MinusIcon = () => /* @__PURE__ */ a3(Icon, { size: 18, children: /* @__PURE__ */ a3("path", { d: "M5 10h10" }) });
877
+ var CheckIcon = () => /* @__PURE__ */ a3(Icon, { size: 16, children: /* @__PURE__ */ a3("path", { d: "M4.5 10.5l3.5 3.5 7.5-8" }) });
863
878
  var BellIcon = () => /* @__PURE__ */ a3(Icon, { size: 18, children: [
864
879
  /* @__PURE__ */ a3("path", { d: "M5.5 13.5V9a4.5 4.5 0 0 1 9 0v4.5l1.2 1.5H4.3z" }),
865
880
  /* @__PURE__ */ a3("path", { d: "M8.5 17a1.6 1.6 0 0 0 3 0" })
@@ -1659,6 +1674,139 @@ import {
1659
1674
  SERIES_COLORS
1660
1675
  } from "@funnest/charts";
1661
1676
 
1677
+ // src/components/go-to-date.tsx
1678
+ var DAY2 = 864e5;
1679
+ var ymd = (t3) => new Date(t3).toISOString().slice(0, 10);
1680
+ function parseYmd(text) {
1681
+ const m3 = /^(\d{4})-(\d{2})-(\d{2})$/.exec(text);
1682
+ if (!m3) return Number.NaN;
1683
+ const t3 = Date.UTC(Number(m3[1]), Number(m3[2]) - 1, Number(m3[3]));
1684
+ return ymd(t3) === text ? t3 : Number.NaN;
1685
+ }
1686
+ function formatTyped(text) {
1687
+ const d3 = text.replace(/\D/g, "").slice(0, 8);
1688
+ return [d3.slice(0, 4), d3.slice(4, 6), d3.slice(6, 8)].filter(Boolean).join("-");
1689
+ }
1690
+ function GoToDateDialog({ ctx }) {
1691
+ const s3 = useStore(ctx.store);
1692
+ const t3 = stringsOf(s3);
1693
+ const today = Date.now();
1694
+ const start = ctx.chart.getVisibleTimeRange()?.from ?? today;
1695
+ const [text, setText] = d2(ymd(start));
1696
+ const [month, setMonth] = d2(() => {
1697
+ const d3 = new Date(start);
1698
+ return { y: d3.getUTCFullYear(), m: d3.getUTCMonth() };
1699
+ });
1700
+ const [busy, setBusy] = d2(false);
1701
+ const input = T2(null);
1702
+ const close = () => ctx.store.set({ dialog: null });
1703
+ A2(() => input.current?.select(), []);
1704
+ const picked = parseYmd(text);
1705
+ const valid = Number.isFinite(picked) && picked <= today;
1706
+ const locale = s3.locale === "en" ? "en-US" : "ko-KR";
1707
+ const title = new Intl.DateTimeFormat(locale, { year: "numeric", month: "long", timeZone: "UTC" }).format(Date.UTC(month.y, month.m, 1));
1708
+ const weekdays = w2(() => {
1709
+ const f4 = new Intl.DateTimeFormat(locale, { weekday: "narrow", timeZone: "UTC" });
1710
+ return Array.from({ length: 7 }, (_3, i3) => f4.format(Date.UTC(2023, 0, 1 + i3)));
1711
+ }, [locale]);
1712
+ const first = Date.UTC(month.y, month.m, 1);
1713
+ const lead = new Date(first).getUTCDay();
1714
+ const days = new Date(Date.UTC(month.y, month.m + 1, 0)).getUTCDate();
1715
+ const cells = [...Array.from({ length: lead }, () => null), ...Array.from({ length: days }, (_3, i3) => first + i3 * DAY2)];
1716
+ const shift = (months) => setMonth(({ y: y3, m: m3 }) => {
1717
+ const d3 = new Date(Date.UTC(y3, m3 + months, 1));
1718
+ return { y: d3.getUTCFullYear(), m: d3.getUTCMonth() };
1719
+ });
1720
+ const pick = (time) => {
1721
+ setText(ymd(time));
1722
+ const d3 = new Date(time);
1723
+ setMonth({ y: d3.getUTCFullYear(), m: d3.getUTCMonth() });
1724
+ };
1725
+ const go = async () => {
1726
+ if (!valid || busy) return;
1727
+ setBusy(true);
1728
+ try {
1729
+ await ctx.chart.goToTime(picked);
1730
+ close();
1731
+ } finally {
1732
+ setBusy(false);
1733
+ }
1734
+ };
1735
+ return /* @__PURE__ */ a3("div", { class: "fnc-backdrop", onPointerDown: (e3) => e3.target === e3.currentTarget && close(), children: /* @__PURE__ */ a3("div", { class: "fnc-dialog fnc-goto-dialog", role: "dialog", "aria-modal": "true", "aria-label": t3.goToDate, onKeyDown: (e3) => e3.key === "Escape" && close(), children: [
1736
+ /* @__PURE__ */ a3("div", { class: "fnc-dialog-head", children: [
1737
+ /* @__PURE__ */ a3("b", { children: t3.goToDate }),
1738
+ /* @__PURE__ */ a3("button", { class: "fnc-btn", "aria-label": t3.close, onClick: close, children: /* @__PURE__ */ a3(CloseIcon, {}) })
1739
+ ] }),
1740
+ /* @__PURE__ */ a3(
1741
+ "form",
1742
+ {
1743
+ class: "fnc-goto-body",
1744
+ onSubmit: (e3) => {
1745
+ e3.preventDefault();
1746
+ void go();
1747
+ },
1748
+ children: [
1749
+ /* @__PURE__ */ a3(
1750
+ "input",
1751
+ {
1752
+ ref: input,
1753
+ class: "fnc-input fnc-goto-input",
1754
+ value: text,
1755
+ inputMode: "numeric",
1756
+ placeholder: "YYYY-MM-DD",
1757
+ "aria-label": t3.goToDate,
1758
+ "aria-invalid": text.length === 10 && !valid,
1759
+ onInput: (e3) => {
1760
+ const next = formatTyped(e3.target.value);
1761
+ setText(next);
1762
+ const time = parseYmd(next);
1763
+ if (Number.isFinite(time)) {
1764
+ const d3 = new Date(time);
1765
+ setMonth({ y: d3.getUTCFullYear(), m: d3.getUTCMonth() });
1766
+ }
1767
+ },
1768
+ onKeyDown: (e3) => e3.stopPropagation()
1769
+ }
1770
+ ),
1771
+ /* @__PURE__ */ a3("div", { class: "fnc-cal", role: "group", "aria-label": title, children: [
1772
+ /* @__PURE__ */ a3("div", { class: "fnc-cal-head", children: [
1773
+ /* @__PURE__ */ a3("button", { type: "button", class: "fnc-btn", "aria-label": t3.prevYear, "data-tip": t3.prevYear, onClick: () => shift(-12), children: "\xAB" }),
1774
+ /* @__PURE__ */ a3("button", { type: "button", class: "fnc-btn", "aria-label": t3.prevMonth, "data-tip": t3.prevMonth, onClick: () => shift(-1), children: /* @__PURE__ */ a3(ChevronLeftIcon, {}) }),
1775
+ /* @__PURE__ */ a3("b", { children: title }),
1776
+ /* @__PURE__ */ a3("button", { type: "button", class: "fnc-btn", "aria-label": t3.nextMonth, "data-tip": t3.nextMonth, disabled: first + days * DAY2 > today, onClick: () => shift(1), children: /* @__PURE__ */ a3(ChevronRightIcon, {}) }),
1777
+ /* @__PURE__ */ a3("button", { type: "button", class: "fnc-btn", "aria-label": t3.nextYear, "data-tip": t3.nextYear, disabled: Date.UTC(month.y + 1, month.m, 1) > today, onClick: () => shift(12), children: "\xBB" })
1778
+ ] }),
1779
+ /* @__PURE__ */ a3("div", { class: "fnc-cal-grid", children: [
1780
+ weekdays.map((w3) => /* @__PURE__ */ a3("span", { class: "fnc-cal-wd", children: w3 })),
1781
+ cells.map(
1782
+ (time) => time === null ? /* @__PURE__ */ a3("span", {}) : /* @__PURE__ */ a3(
1783
+ "button",
1784
+ {
1785
+ type: "button",
1786
+ class: `fnc-cal-day${ymd(time) === text ? " is-on" : ""}${ymd(time) === ymd(today) ? " is-today" : ""}`,
1787
+ disabled: time > today,
1788
+ "aria-pressed": ymd(time) === text,
1789
+ onClick: () => pick(time),
1790
+ onDblClick: () => {
1791
+ pick(time);
1792
+ void ctx.chart.goToTime(time).then(close);
1793
+ },
1794
+ children: new Date(time).getUTCDate()
1795
+ }
1796
+ )
1797
+ )
1798
+ ] })
1799
+ ] }),
1800
+ /* @__PURE__ */ a3("div", { class: "fnc-goto-actions", children: [
1801
+ /* @__PURE__ */ a3("button", { type: "button", class: "fnc-btn fnc-goto-today", onClick: () => pick(Date.UTC(new Date(today).getUTCFullYear(), new Date(today).getUTCMonth(), new Date(today).getUTCDate())), children: t3.today }),
1802
+ /* @__PURE__ */ a3("button", { type: "submit", class: "fnc-btn fnc-goto-go", disabled: !valid || busy, children: t3.goTo })
1803
+ ] })
1804
+ ]
1805
+ }
1806
+ )
1807
+ ] }) });
1808
+ }
1809
+
1662
1810
  // src/components/settings-dialog.tsx
1663
1811
  import { CHART_THEMES, DEFAULT_CHART_SETTINGS, matchChartTheme } from "@funnest/charts";
1664
1812
  function toHex(color) {
@@ -1676,7 +1824,8 @@ var SECTIONS = [
1676
1824
  { key: "lastPriceLine", label: "settingLastPrice" },
1677
1825
  { key: "countdown", label: "settingCountdown" },
1678
1826
  { key: "volume", label: "settingVolume" },
1679
- { key: "navigationButtons", label: "settingNavButtons" }
1827
+ { key: "navigationButtons", label: "settingNavButtons" },
1828
+ { key: "smoothScroll", label: "smoothScroll" }
1680
1829
  ]
1681
1830
  },
1682
1831
  {
@@ -2048,6 +2197,7 @@ function Dialogs({ ctx }) {
2048
2197
  if (dialog?.kind === "indicators") return /* @__PURE__ */ a3(IndicatorPicker, { ctx });
2049
2198
  if (dialog?.kind === "indicatorSettings") return /* @__PURE__ */ a3(IndicatorSettings, { ctx, id: dialog.id });
2050
2199
  if (dialog?.kind === "chartSettings") return /* @__PURE__ */ a3(SettingsDialog, { ctx });
2200
+ if (dialog?.kind === "goToDate") return /* @__PURE__ */ a3(GoToDateDialog, { ctx });
2051
2201
  return null;
2052
2202
  }
2053
2203
 
@@ -2997,7 +3147,11 @@ function ContextMenu({ ctx }) {
2997
3147
  onSelect: () => ctx.chart.addDrawing({ type: "horizontal", points: [{ time, price }] })
2998
3148
  });
2999
3149
  }
3150
+ const smooth = ctx.chart.settings.smoothScroll;
3000
3151
  items.push(
3152
+ { label: t3.goToDateMore, onSelect: () => ctx.store.set({ dialog: { kind: "goToDate" } }) },
3153
+ { label: t3.smoothScroll, checked: smooth, onSelect: () => ctx.chart.setSettings({ smoothScroll: !smooth }) },
3154
+ "separator",
3001
3155
  { label: t3.resetChart, onSelect: () => ctx.chart.resetView() },
3002
3156
  { label: t3.chartSettingsMore, onSelect: () => ctx.store.set({ dialog: { kind: "chartSettings" } }) }
3003
3157
  );
@@ -3005,8 +3159,9 @@ function ContextMenu({ ctx }) {
3005
3159
  (item) => item === "separator" ? /* @__PURE__ */ a3("div", { class: "fnc-ctx-sep", role: "separator" }) : /* @__PURE__ */ a3(
3006
3160
  "button",
3007
3161
  {
3008
- class: "fnc-menu-item",
3009
- role: "menuitem",
3162
+ class: `fnc-menu-item${item.checked !== void 0 ? " fnc-menu-check" : ""}`,
3163
+ role: item.checked !== void 0 ? "menuitemcheckbox" : "menuitem",
3164
+ "aria-checked": item.checked,
3010
3165
  disabled: item.disabled,
3011
3166
  onClick: () => {
3012
3167
  setTarget(null);
@@ -3015,7 +3170,8 @@ function ContextMenu({ ctx }) {
3015
3170
  children: [
3016
3171
  item.icon === "alert" && /* @__PURE__ */ a3(BellIcon, {}),
3017
3172
  /* @__PURE__ */ a3("span", { children: item.label }),
3018
- item.shortcut && /* @__PURE__ */ a3("kbd", { children: item.shortcut })
3173
+ item.shortcut && /* @__PURE__ */ a3("kbd", { children: item.shortcut }),
3174
+ item.checked && /* @__PURE__ */ a3(CheckIcon, {})
3019
3175
  ]
3020
3176
  }
3021
3177
  )
@@ -4235,6 +4391,28 @@ var CSS = (
4235
4391
  @media (hover: none) {
4236
4392
  .fnc-nav { display: none; }
4237
4393
  }
4394
+ /* A setting in a menu (\uBD80\uB4DC\uB7EC\uC6B4 \uC2A4\uD06C\uB864\xB7\uD655\uB300): the check at the end. */
4395
+ .fnc-menu-check svg { margin-left: auto; color: var(--fnc-accent); }
4396
+
4397
+ /* \uB0A0\uC9DC\uB85C \uC774\uB3D9: a date typed or picked on a month calendar. */
4398
+ .fnc-goto-dialog { width: min(320px, calc(100% - 32px)); }
4399
+ .fnc-goto-body { display: flex; flex-direction: column; gap: 10px; padding: 4px 16px 16px; }
4400
+ .fnc-goto-input { height: 38px; font-size: 15px; font-variant-numeric: tabular-nums; letter-spacing: 0.02em; }
4401
+ .fnc-goto-input[aria-invalid="true"] { box-shadow: 0 0 0 1px var(--fnc-down, #f04452); }
4402
+ .fnc-cal-head { display: flex; align-items: center; gap: 2px; }
4403
+ .fnc-cal-head b { flex: 1; text-align: center; font-size: 14px; }
4404
+ .fnc-cal-head .fnc-btn { width: 30px; height: 30px; font-size: 16px; }
4405
+ .fnc-cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; margin-top: 4px; }
4406
+ .fnc-cal-wd { padding: 4px 0; text-align: center; font-size: 11px; color: var(--fnc-text-2); }
4407
+ .fnc-cal-day { height: 34px; border-radius: var(--fnc-radius); font-size: 13px; font-variant-numeric: tabular-nums; color: var(--fnc-text); }
4408
+ .fnc-cal-day:hover:not(:disabled) { background: var(--fnc-surface); }
4409
+ .fnc-cal-day.is-today { box-shadow: inset 0 0 0 1px var(--fnc-border); }
4410
+ .fnc-cal-day.is-on { background: var(--fnc-accent); color: #fff; font-weight: 700; }
4411
+ .fnc-cal-day:disabled { opacity: 0.3; cursor: default; }
4412
+ .fnc-goto-actions { display: flex; gap: 8px; }
4413
+ .fnc-goto-dialog .fnc-goto-today { flex: none; width: auto; white-space: nowrap; height: 36px; padding: 0 16px; border-radius: var(--fnc-radius); background: var(--fnc-surface); font-weight: 600; }
4414
+ .fnc-goto-dialog .fnc-goto-go { flex: 1; height: 36px; }
4415
+
4238
4416
  /* The + on the price axis at the crosshair price, and its menu (mouse only). */
4239
4417
  .fnc-axis-plus { position: absolute; z-index: 25; }
4240
4418
  .fnc-axis-plus-btn { display: flex; align-items: center; justify-content: center; width: 22px; height: 22px; border-radius: 6px; background: var(--fnc-bg); color: var(--fnc-text-2); box-shadow: 0 0 0 1px var(--fnc-border); }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@funnest/charts-ui",
3
- "version": "0.8.3",
3
+ "version": "0.8.4",
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.8.3"
45
+ "@funnest/charts": "0.8.4"
46
46
  },
47
47
  "devDependencies": {
48
48
  "preact": "^11.2.0"