@gearbox-protocol/ui-kit 4.0.0-next.62 → 4.0.0-next.64

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.
Files changed (27) hide show
  1. package/dist/cjs/components/graph/graph.cjs +1 -1
  2. package/dist/cjs/components/graph/series-config.cjs +1 -1
  3. package/dist/cjs/components/index.cjs +1 -1
  4. package/dist/cjs/components/table/grid-table.cjs +1 -1
  5. package/dist/cjs/components/trading-view/constants.cjs +1 -0
  6. package/dist/cjs/components/trading-view/index.cjs +1 -1
  7. package/dist/cjs/components/trading-view/price-scale-titles.cjs +1 -0
  8. package/dist/cjs/components/trading-view/trading-view.cjs +1 -1
  9. package/dist/cjs/index.cjs +1 -1
  10. package/dist/esm/components/graph/graph.js +257 -266
  11. package/dist/esm/components/graph/series-config.js +10 -1
  12. package/dist/esm/components/index.js +70 -68
  13. package/dist/esm/components/table/grid-table.js +94 -90
  14. package/dist/esm/components/trading-view/constants.js +7 -0
  15. package/dist/esm/components/trading-view/index.js +4 -2
  16. package/dist/esm/components/trading-view/price-scale-titles.js +52 -0
  17. package/dist/esm/components/trading-view/trading-view.js +119 -115
  18. package/dist/esm/index.js +124 -122
  19. package/dist/globals.css +1 -1
  20. package/dist/types/components/graph/graph.d.ts +1 -5
  21. package/dist/types/components/graph/series-config.d.ts +13 -0
  22. package/dist/types/components/table/grid-table.d.ts +0 -52
  23. package/dist/types/components/trading-view/constants.d.ts +4 -0
  24. package/dist/types/components/trading-view/index.d.ts +1 -0
  25. package/dist/types/components/trading-view/price-scale-titles.d.ts +16 -0
  26. package/dist/types/components/trading-view/trading-view.d.ts +1 -1
  27. package/package.json +1 -1
@@ -0,0 +1,52 @@
1
+ import { jsxs as a, jsx as l } from "react/jsx-runtime";
2
+ import { cn as m } from "../../utils/cn.js";
3
+ import "@gearbox-protocol/sdk/onchain";
4
+ import "../../utils/z-index.js";
5
+ import { resolvePriceScaleSides as n } from "../graph/series-config.js";
6
+ import { TradingViewTest as s } from "./constants.js";
7
+ function u({
8
+ series: e
9
+ }) {
10
+ const i = n(e);
11
+ return (
12
+ // Half the card's gap below: the titles belong to the frame they sit on,
13
+ // not to the toolbar above them.
14
+ /* @__PURE__ */ a(
15
+ "div",
16
+ {
17
+ className: "-mb-1.5 flex w-full flex-row items-end justify-between gap-4",
18
+ "data-testid": s.priceScaleTitles,
19
+ children: [
20
+ /* @__PURE__ */ l(r, { side: "left", resolved: i }),
21
+ /* @__PURE__ */ l(r, { side: "right", resolved: i })
22
+ ]
23
+ }
24
+ )
25
+ );
26
+ }
27
+ function r({
28
+ side: e,
29
+ resolved: i
30
+ }) {
31
+ return /* @__PURE__ */ l(
32
+ "div",
33
+ {
34
+ className: m(
35
+ "flex min-w-0 flex-1 flex-col gap-0.5",
36
+ e === "left" ? "items-start text-left" : "items-end text-right"
37
+ ),
38
+ "data-testid": s.priceScaleTitle(e),
39
+ children: i.filter((t) => t.side === e).map(({ series: t }) => /* @__PURE__ */ l(
40
+ "span",
41
+ {
42
+ className: "max-w-full truncate text-xs font-medium leading-4 text-muted-foreground",
43
+ children: t.label
44
+ },
45
+ t.id ?? t.label
46
+ ))
47
+ }
48
+ );
49
+ }
50
+ export {
51
+ u as PriceScaleTitles
52
+ };
@@ -1,26 +1,27 @@
1
- import { jsxs as h, jsx as n } from "react/jsx-runtime";
2
- import { useMemo as I, useCallback as we, useRef as N } from "react";
1
+ import { jsxs as x, jsx as n } from "react/jsx-runtime";
2
+ import { useMemo as I, useCallback as pe, useRef as N } from "react";
3
3
  import { toast as ve } from "sonner";
4
- import { SectionHeading as pe } from "../base/section-heading/section-heading.js";
5
- import { useIsMobile as xe } from "../../hooks/use-media-query.js";
6
- import { cn as Se } from "../../utils/cn.js";
4
+ import { SectionHeading as Se } from "../base/section-heading/section-heading.js";
5
+ import { useIsMobile as he } from "../../hooks/use-media-query.js";
6
+ import { cn as xe } from "../../utils/cn.js";
7
7
  import "@gearbox-protocol/sdk/onchain";
8
8
  import "../../utils/z-index.js";
9
- import { GraphLegend as he } from "../graph/graph.js";
10
- import { GraphViewWithData as ge } from "../graph/graph-view.js";
11
- import { DEFAULT_SERIES_COLORS as k } from "../graph/graph-vocabulary.js";
12
- import { getSeriesColorPalette as ye } from "../graph/series-palette.js";
13
- import { Select as Ae, SelectTrigger as Ie, SelectValue as Ne, SelectContent as Ce, SelectItem as Me } from "../select/select.js";
14
- import { GraphDropdown as Re } from "./graph-dropdown.js";
15
- const Ee = {
9
+ import { GraphLegend as ge } from "../graph/graph.js";
10
+ import { GraphViewWithData as ye } from "../graph/graph-view.js";
11
+ import { DEFAULT_SERIES_COLORS as j } from "../graph/graph-vocabulary.js";
12
+ import { getSeriesColorPalette as Ae } from "../graph/series-palette.js";
13
+ import { Select as Ie, SelectTrigger as Ne, SelectValue as Ce, SelectContent as Me, SelectItem as Re } from "../select/select.js";
14
+ import { GraphDropdown as Te } from "./graph-dropdown.js";
15
+ import { PriceScaleTitles as Ee } from "./price-scale-titles.js";
16
+ const Oe = {
16
17
  expand: "M8 3H5a2 2 0 0 0-2 2v3m18 0V5a2 2 0 0 0-2-2h-3m0 18h3a2 2 0 0 0 2-2v-3M3 16v3a2 2 0 0 0 2 2h3",
17
18
  exit: "M8 3v3a2 2 0 0 1-2 2H3m18 0h-3a2 2 0 0 1-2-2V3m0 18v-3a2 2 0 0 1 2-2h3M3 16h3a2 2 0 0 1 2 2v3"
18
- }, X = ({
19
+ }, q = ({
19
20
  direction: r,
20
21
  size: t = 16
21
22
  }) => {
22
23
  const l = r === "expand" ? "Expand fullscreen" : "Exit fullscreen";
23
- return /* @__PURE__ */ h(
24
+ return /* @__PURE__ */ x(
24
25
  "svg",
25
26
  {
26
27
  width: t,
@@ -34,98 +35,99 @@ const Ee = {
34
35
  "aria-label": l,
35
36
  children: [
36
37
  /* @__PURE__ */ n("title", { children: l }),
37
- /* @__PURE__ */ n("path", { d: Ee[r] })
38
+ /* @__PURE__ */ n("path", { d: Oe[r] })
38
39
  ]
39
40
  }
40
41
  );
41
- }, Te = {
42
+ }, ke = {
42
43
  timeScale: { borderVisible: !1 },
43
44
  rightPriceScale: { borderVisible: !1 },
44
45
  leftPriceScale: { borderVisible: !1 }
45
- }, Q = "ui-kit:tradingview-series-colors:";
46
- function L(r) {
46
+ }, Z = "ui-kit:tradingview-series-colors:";
47
+ function V(r) {
47
48
  if (typeof window > "u" || !window.localStorage)
48
49
  return /* @__PURE__ */ new Map();
49
50
  try {
50
- const t = window.localStorage.getItem(Q + r);
51
+ const t = window.localStorage.getItem(Z + r);
51
52
  if (!t) return /* @__PURE__ */ new Map();
52
53
  const l = JSON.parse(t);
53
54
  return l == null || typeof l != "object" ? /* @__PURE__ */ new Map() : new Map(
54
55
  Object.entries(l).filter(
55
- ([, o]) => typeof o == "number" && o >= 0 && o < k.length
56
+ ([, o]) => typeof o == "number" && o >= 0 && o < j.length
56
57
  )
57
58
  );
58
59
  } catch {
59
60
  return /* @__PURE__ */ new Map();
60
61
  }
61
62
  }
62
- function Oe(r, t) {
63
+ function Le(r, t) {
63
64
  if (!(typeof window > "u" || !window.localStorage))
64
65
  try {
65
66
  window.localStorage.setItem(
66
- Q + r,
67
+ Z + r,
67
68
  JSON.stringify(Object.fromEntries(t))
68
69
  );
69
70
  } catch {
70
71
  }
71
72
  }
72
- function q(r, t) {
73
+ function Q(r, t) {
73
74
  if (t.size === 0) return;
74
- const l = L(r);
75
- for (const [o, p] of t)
76
- l.set(o, p);
77
- Oe(r, l);
75
+ const l = V(r);
76
+ for (const [o, v] of t)
77
+ l.set(o, v);
78
+ Le(r, l);
78
79
  }
79
- function Pe({
80
+ function Ke({
80
81
  data: r,
81
82
  yMeasureUnit: t,
82
83
  height: l = 306,
83
84
  defaultGraph: o,
84
- onGraphSelected: p,
85
+ onGraphSelected: v,
85
86
  graphs: f,
86
- isMultipleSelect: Y,
87
- range: Z,
87
+ isMultipleSelect: P,
88
+ range: Y,
88
89
  rangeList: g,
89
- setRange: P,
90
+ setRange: D,
90
91
  onGraphExpanded: C,
91
- isGraphExpanded: D,
92
- onUnselectSeries: j,
93
- legendMarkers: V,
94
- graphsWithNoData: U,
92
+ isGraphExpanded: U,
93
+ onUnselectSeries: _,
94
+ legendMarkers: z,
95
+ graphsWithNoData: K,
95
96
  loadingGraphs: M,
96
- isLoading: _,
97
- noDataMessage: z = "No data available for this graph",
98
- currentValueDecimals: K,
99
- containerClassName: G,
100
- useSharedPriceScale: ee,
101
- showCurrentValue: te,
102
- yScaleMin: re,
103
- yScaleMinMultiple: oe,
97
+ isLoading: F,
98
+ noDataMessage: H = "No data available for this graph",
99
+ currentValueDecimals: G,
100
+ containerClassName: ee,
101
+ useSharedPriceScale: te,
102
+ dualYAxis: B,
103
+ showCurrentValue: re,
104
+ yScaleMin: oe,
105
+ yScaleMinMultiple: ne,
104
106
  seriesColorPersistenceKey: d,
105
- title: ne,
107
+ title: le,
106
108
  trailing: R,
107
- ...le
109
+ ...ie
108
110
  }) {
109
- const x = I(() => Array.isArray(r) ? r : r ? [r] : [], [r]), ie = I(() => Array.isArray(r) && r.length > 1, [r]), F = xe(), se = we(
111
+ const S = I(() => Array.isArray(r) ? r : r ? [r] : [], [r]), se = I(() => Array.isArray(r) && r.length > 1, [r]), T = he(), ce = pe(
110
112
  (u, y) => {
111
- ve.error(z);
113
+ ve.error(H);
112
114
  },
113
- [z]
114
- ), ce = I(() => {
115
+ [H]
116
+ ), ue = I(() => {
115
117
  if (t)
116
118
  return Array.isArray(t) ? t[0] : t;
117
- }, [t]), ue = !!(p && f && o), s = N(/* @__PURE__ */ new Map()), b = N(0), H = N(!1);
118
- if (f && f.length > 0 && !H.current) {
119
- H.current = !0;
120
- const u = d ? L(d) : /* @__PURE__ */ new Map(), y = String(f[0].value);
119
+ }, [t]), de = !!(v && f && o), s = N(/* @__PURE__ */ new Map()), b = N(0), J = N(!1);
120
+ if (f && f.length > 0 && !J.current) {
121
+ J.current = !0;
122
+ const u = d ? V(d) : /* @__PURE__ */ new Map(), y = String(f[0].value);
121
123
  s.current.set(y, 0), b.current = 1;
122
124
  for (let e = 1; e < f.length; e++) {
123
125
  const m = String(f[e].value);
124
126
  if (s.current.has(m)) continue;
125
- const S = u.get(m) ?? e;
126
- s.current.set(m, S), b.current = Math.max(b.current, S + 1);
127
+ const h = u.get(m) ?? e;
128
+ s.current.set(m, h), b.current = Math.max(b.current, h + 1);
127
129
  }
128
- d && q(
130
+ d && Q(
129
131
  d,
130
132
  s.current
131
133
  );
@@ -133,39 +135,39 @@ function Pe({
133
135
  const w = I(() => {
134
136
  const u = Array.isArray(t) ? t : void 0;
135
137
  if (d) {
136
- const e = L(d);
137
- for (const [m, v] of e)
138
- s.current.has(m) || (s.current.set(m, v), b.current = Math.max(
138
+ const e = V(d);
139
+ for (const [m, p] of e)
140
+ s.current.has(m) || (s.current.set(m, p), b.current = Math.max(
139
141
  b.current,
140
- v + 1
142
+ p + 1
141
143
  ));
142
144
  }
143
- const y = x.map((e, m) => {
144
- const v = e?.title || `Series ${m + 1}`, S = o != null ? Array.isArray(o) ? o[0]?.value ?? o[0] : typeof o == "object" && "value" in o ? o.value : o : null, T = x.length === 1 ? S != null ? String(S) : "single" : e?.id || v;
145
- if (!s.current.has(T)) {
145
+ const y = S.map((e, m) => {
146
+ const p = e?.title || `Series ${m + 1}`, h = o != null ? Array.isArray(o) ? o[0]?.value ?? o[0] : typeof o == "object" && "value" in o ? o.value : o : null, k = S.length === 1 ? h != null ? String(h) : "single" : e?.id || p;
147
+ if (!s.current.has(k)) {
146
148
  const i = new Set(
147
149
  Array.from(s.current.values())
148
150
  );
149
151
  let c = b.current;
150
- for (let a = 0; a < k.length; a++) {
151
- const A = (b.current + a) % k.length;
152
+ for (let a = 0; a < j.length; a++) {
153
+ const A = (b.current + a) % j.length;
152
154
  if (!i.has(A)) {
153
155
  c = A;
154
156
  break;
155
157
  }
156
158
  }
157
- s.current.set(T, c), b.current = c + 1;
159
+ s.current.set(k, c), b.current = c + 1;
158
160
  }
159
- const fe = s.current.get(T) ?? 0, O = ye(fe), be = [...e?.data || []].sort((i, c) => {
161
+ const be = s.current.get(k) ?? 0, L = Ae(be), we = [...e?.data || []].sort((i, c) => {
160
162
  const a = typeof i.time == "number" ? i.time : Number(i.time), A = typeof c.time == "number" ? c.time : Number(c.time);
161
163
  return a - A;
162
164
  }).reduce((i, c) => {
163
165
  const a = c.time;
164
166
  return i.length === 0 || i[i.length - 1].time !== a ? i.push({ time: a, value: c.value }) : i[i.length - 1] = { time: a, value: c.value }, i;
165
- }, []), $ = e?.lineColor ?? e?.color ?? void 0;
167
+ }, []), X = e?.lineColor ?? e?.color ?? void 0;
166
168
  return {
167
- data: be,
168
- label: v,
169
+ data: we,
170
+ label: p,
169
171
  ...e?.id != null && { id: e.id },
170
172
  yMeasureUnit: u?.[m] ?? (Array.isArray(t) ? void 0 : t),
171
173
  ...e?.priceScaleId != null && {
@@ -177,8 +179,8 @@ function Pe({
177
179
  ...e?.lineStyle != null && {
178
180
  lineStyle: e.lineStyle
179
181
  },
180
- ...$ != null ? {
181
- lineColor: $,
182
+ ...X != null ? {
183
+ lineColor: X,
182
184
  ...e?.topColor != null && {
183
185
  topColor: e.topColor
184
186
  },
@@ -186,65 +188,66 @@ function Pe({
186
188
  bottomColor: e.bottomColor
187
189
  }
188
190
  } : {
189
- color: O.line,
190
- topColor: O.top,
191
- bottomColor: O.bottom
191
+ color: L.line,
192
+ topColor: L.top,
193
+ bottomColor: L.bottom
192
194
  }
193
195
  };
194
196
  });
195
- return d && s.current.size > 0 && q(
197
+ return d && s.current.size > 0 && Q(
196
198
  d,
197
199
  s.current
198
200
  ), y;
199
- }, [x, o, t, d]), B = _ !== void 0 ? _ : M !== void 0 ? M.size > 0 : ie && x.length > 0 ? x.some((u) => !u) : !r, J = N(w);
200
- w.length > 0 && (J.current = w);
201
- const W = w.length > 0 ? w : B ? J.current : w, E = ne, de = !F && C ? !0 : g.length > 0 || ue || E != null || R != null, me = p && f && o ? /* @__PURE__ */ n(
202
- Re,
201
+ }, [S, o, t, d]), W = F !== void 0 ? F : M !== void 0 ? M.size > 0 : se && S.length > 0 ? S.some((u) => !u) : !r, $ = N(w);
202
+ w.length > 0 && ($.current = w);
203
+ const E = w.length > 0 ? w : W ? $.current : w, O = le, me = !T && C ? !0 : g.length > 0 || de || O != null || R != null, ae = v && f && o ? /* @__PURE__ */ n(
204
+ Te,
203
205
  {
204
- onSelected: p,
206
+ onSelected: v,
205
207
  items: f,
206
208
  defaultItem: o,
207
- multiple: Y,
208
- graphsWithNoData: U,
209
+ multiple: P,
210
+ graphsWithNoData: K,
209
211
  loadingGraphs: M,
210
- onNoDataSelected: se
212
+ onNoDataSelected: ce
211
213
  }
212
- ) : E != null ? /* @__PURE__ */ n(pe, { className: "min-w-0 truncate", children: E }) : null, ae = de && /* @__PURE__ */ h("div", { className: "flex w-full flex-row flex-wrap items-center justify-between gap-3", children: [
213
- /* @__PURE__ */ n("div", { className: "min-w-0 flex-1", children: me }),
214
- /* @__PURE__ */ h("div", { className: "flex shrink-0 flex-row flex-nowrap items-center gap-3", children: [
214
+ ) : O != null ? /* @__PURE__ */ n(Se, { className: "min-w-0 truncate", children: O }) : null, fe = me && /* @__PURE__ */ x("div", { className: "flex w-full flex-row flex-wrap items-center justify-between gap-3", children: [
215
+ /* @__PURE__ */ n("div", { className: "min-w-0 flex-1", children: ae }),
216
+ /* @__PURE__ */ x("div", { className: "flex shrink-0 flex-row flex-nowrap items-center gap-3", children: [
215
217
  R,
216
218
  R != null && g.length > 0 ? /* @__PURE__ */ n("div", { className: "h-4 w-px shrink-0 bg-border" }) : null,
217
- g.length > 0 ? /* @__PURE__ */ h(Ae, { value: Z, onValueChange: P, children: [
219
+ g.length > 0 ? /* @__PURE__ */ x(Ie, { value: Y, onValueChange: D, children: [
218
220
  /* @__PURE__ */ n(
219
- Ie,
221
+ Ne,
220
222
  {
221
223
  size: "sm",
222
224
  className: "h-8 w-auto min-w-[4.5rem] gap-1.5 border-border bg-muted shadow-none",
223
- children: /* @__PURE__ */ n(Ne, {})
225
+ children: /* @__PURE__ */ n(Ce, {})
224
226
  }
225
227
  ),
226
- /* @__PURE__ */ n(Ce, { align: "end", children: g.map((u) => /* @__PURE__ */ n(Me, { value: u.value, children: u.label }, u.value)) })
228
+ /* @__PURE__ */ n(Me, { align: "end", children: g.map((u) => /* @__PURE__ */ n(Re, { value: u.value, children: u.label }, u.value)) })
227
229
  ] }) : null,
228
- !F && C && /* @__PURE__ */ n(
230
+ !T && C && /* @__PURE__ */ n(
229
231
  "button",
230
232
  {
231
233
  type: "button",
232
234
  className: "flex min-h-[26px] min-w-[44px] cursor-pointer items-center justify-center rounded-md border border-muted bg-muted px-2.5 py-1.5 text-center text-xs font-medium leading-[14px] text-muted-foreground transition-colors hover:border-secondary focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring",
233
235
  onClick: C,
234
- children: D ? /* @__PURE__ */ n(X, { direction: "exit", size: 16 }) : /* @__PURE__ */ n(X, { direction: "expand", size: 16 })
236
+ children: U ? /* @__PURE__ */ n(q, { direction: "exit", size: 16 }) : /* @__PURE__ */ n(q, { direction: "expand", size: 16 })
235
237
  }
236
238
  )
237
239
  ] })
238
240
  ] });
239
- return /* @__PURE__ */ h(
241
+ return /* @__PURE__ */ x(
240
242
  "div",
241
243
  {
242
- className: Se(
244
+ className: xe(
243
245
  "flex w-full flex-col gap-3 rounded-lg border border-border bg-card p-4 shadow-none",
244
- G
246
+ ee
245
247
  ),
246
248
  children: [
247
- ae,
249
+ fe,
250
+ B && !T ? /* @__PURE__ */ n(Ee, { series: E }) : null,
248
251
  /* @__PURE__ */ n(
249
252
  "div",
250
253
  {
@@ -254,36 +257,37 @@ function Pe({
254
257
  },
255
258
  className: "w-full",
256
259
  children: /* @__PURE__ */ n(
257
- ge,
260
+ ye,
258
261
  {
259
- ...le,
262
+ ...ie,
260
263
  series: w,
261
- loading: B,
264
+ loading: W,
262
265
  size: l ? "full" : "default",
263
266
  padding: "none",
264
267
  variant: "ghost",
265
268
  className: "rounded-md border border-border bg-card",
266
269
  containerClassName: "h-full overflow-hidden rounded-none border-0 bg-transparent shadow-none",
267
270
  showLegend: !1,
268
- onUnselectSeries: j,
269
- yMeasureUnit: ce,
270
- currentValueDecimals: K,
271
- useSharedPriceScale: ee,
272
- showCurrentValue: te,
273
- yScaleMin: re,
274
- yScaleMinMultiple: oe,
271
+ onUnselectSeries: _,
272
+ yMeasureUnit: ue,
273
+ currentValueDecimals: G,
274
+ useSharedPriceScale: te,
275
+ dualYAxis: B,
276
+ showCurrentValue: re,
277
+ yScaleMin: oe,
278
+ yScaleMinMultiple: ne,
275
279
  hideDefaultTooltip: !0,
276
- optionsOverrides: Te
280
+ optionsOverrides: ke
277
281
  }
278
282
  )
279
283
  }
280
284
  ),
281
- W.length > 0 || (V?.length ?? 0) > 0 ? /* @__PURE__ */ n(
282
- he,
285
+ E.length > 0 || (z?.length ?? 0) > 0 ? /* @__PURE__ */ n(
286
+ ge,
283
287
  {
284
- series: W,
285
- markers: V,
286
- onUnselect: j,
288
+ series: E,
289
+ markers: z,
290
+ onUnselect: _,
287
291
  inline: !0
288
292
  }
289
293
  ) : null
@@ -292,5 +296,5 @@ function Pe({
292
296
  );
293
297
  }
294
298
  export {
295
- Pe as TradingView
299
+ Ke as TradingView
296
300
  };