@gearbox-protocol/permissionless-ui 1.26.2 → 1.26.3

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.
@@ -1,16 +1,16 @@
1
- import { jsxs as y, jsx as r } from "react/jsx-runtime";
2
- import { useMemo as v, useCallback as ee, useRef as L } from "react";
3
- import { toast as te } from "sonner";
4
- import { useIsMobile as oe } from "../../hooks/use-media-query.js";
1
+ import { jsxs as y, jsx as i } from "react/jsx-runtime";
2
+ import { useMemo as S, useCallback as oe, useRef as C } from "react";
3
+ import { toast as ne } from "sonner";
4
+ import { useIsMobile as ie } from "../../hooks/use-media-query.js";
5
5
  import "@gearbox-protocol/sdk";
6
- import { cn as re } from "../../utils/cn.js";
6
+ import { cn as le } from "../../utils/cn.js";
7
7
  import "luxon";
8
8
  import "../../utils/z-index.js";
9
- import { RangeButtons as ne } from "../buttons/range-buttons/range-buttons.js";
10
- import { DEFAULT_SERIES_COLORS as A, getSeriesColorPalette as ie } from "../graph/graph.js";
11
- import { GraphViewWithData as le } from "../graph/graph-view.js";
12
- import { GraphDropdown as se } from "./graph-dropdown.js";
13
- const ce = ({ size: e = 16 }) => /* @__PURE__ */ y(
9
+ import { RangeButtons as se } from "../buttons/range-buttons/range-buttons.js";
10
+ import { DEFAULT_SERIES_COLORS as M, getSeriesColorPalette as ce } from "../graph/graph.js";
11
+ import { GraphViewWithData as ue } from "../graph/graph-view.js";
12
+ import { GraphDropdown as me } from "./graph-dropdown.js";
13
+ const ae = ({ size: e = 16 }) => /* @__PURE__ */ y(
14
14
  "svg",
15
15
  {
16
16
  width: e,
@@ -23,11 +23,11 @@ const ce = ({ size: e = 16 }) => /* @__PURE__ */ y(
23
23
  strokeLinejoin: "round",
24
24
  "aria-label": "Expand fullscreen",
25
25
  children: [
26
- /* @__PURE__ */ r("title", { children: "Expand fullscreen" }),
27
- /* @__PURE__ */ r("path", { d: "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" })
26
+ /* @__PURE__ */ i("title", { children: "Expand fullscreen" }),
27
+ /* @__PURE__ */ i("path", { d: "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" })
28
28
  ]
29
29
  }
30
- ), ue = ({ size: e = 16 }) => /* @__PURE__ */ y(
30
+ ), de = ({ size: e = 16 }) => /* @__PURE__ */ y(
31
31
  "svg",
32
32
  {
33
33
  width: e,
@@ -40,202 +40,206 @@ const ce = ({ size: e = 16 }) => /* @__PURE__ */ y(
40
40
  strokeLinejoin: "round",
41
41
  "aria-label": "Exit fullscreen",
42
42
  children: [
43
- /* @__PURE__ */ r("title", { children: "Exit fullscreen" }),
44
- /* @__PURE__ */ r("path", { d: "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" })
43
+ /* @__PURE__ */ i("title", { children: "Exit fullscreen" }),
44
+ /* @__PURE__ */ i("path", { d: "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" })
45
45
  ]
46
46
  }
47
- ), R = "permissionless-ui:tradingview-series-colors:";
48
- function O(e) {
47
+ ), z = "permissionless-ui:tradingview-series-colors:";
48
+ function E(e) {
49
49
  if (typeof window > "u" || !window.localStorage)
50
50
  return /* @__PURE__ */ new Map();
51
51
  try {
52
- const t = window.localStorage.getItem(R + e);
52
+ const t = window.localStorage.getItem(z + e);
53
53
  if (!t) return /* @__PURE__ */ new Map();
54
- const i = JSON.parse(t);
55
- return i == null || typeof i != "object" ? /* @__PURE__ */ new Map() : new Map(
56
- Object.entries(i).filter(
57
- ([, s]) => typeof s == "number" && s >= 0 && s < A.length
54
+ const s = JSON.parse(t);
55
+ return s == null || typeof s != "object" ? /* @__PURE__ */ new Map() : new Map(
56
+ Object.entries(s).filter(
57
+ ([, c]) => typeof c == "number" && c >= 0 && c < M.length
58
58
  )
59
59
  );
60
60
  } catch {
61
61
  return /* @__PURE__ */ new Map();
62
62
  }
63
63
  }
64
- function ae(e, t) {
64
+ function fe(e, t) {
65
65
  if (!(typeof window > "u" || !window.localStorage))
66
66
  try {
67
67
  window.localStorage.setItem(
68
- R + e,
68
+ z + e,
69
69
  JSON.stringify(Object.fromEntries(t))
70
70
  );
71
71
  } catch {
72
72
  }
73
73
  }
74
- function me(e, t) {
74
+ function _(e, t) {
75
75
  if (t.size === 0) return;
76
- const i = O(e);
77
- for (const [s, w] of t)
78
- i.set(s, w);
79
- ae(e, i);
76
+ const s = E(e);
77
+ for (const [c, h] of t)
78
+ s.set(c, h);
79
+ fe(e, s);
80
80
  }
81
- function Me({
81
+ function Ne({
82
82
  data: e,
83
83
  yMeasureUnit: t,
84
- height: i = 306,
85
- defaultGraph: s,
86
- onGraphSelected: w,
87
- graphs: S,
88
- isMultipleSelect: _,
89
- range: V,
90
- rangeList: I,
91
- setRange: z,
92
- onGraphExpanded: C,
93
- isGraphExpanded: B,
94
- onUnselectSeries: D,
95
- graphsWithNoData: F,
96
- loadingGraphs: T,
97
- noDataMessage: E = "No data available for this graph",
98
- currentValueDecimals: W,
99
- containerClassName: H,
100
- useSharedPriceScale: J,
101
- showCurrentValue: $,
102
- yScaleMin: X,
103
- yScaleMinMultiple: q,
104
- seriesColorPersistenceKey: h,
105
- ...Q
84
+ height: s = 306,
85
+ defaultGraph: c,
86
+ onGraphSelected: h,
87
+ graphs: d,
88
+ isMultipleSelect: V,
89
+ range: B,
90
+ rangeList: k,
91
+ setRange: F,
92
+ onGraphExpanded: A,
93
+ isGraphExpanded: T,
94
+ onUnselectSeries: W,
95
+ graphsWithNoData: D,
96
+ loadingGraphs: H,
97
+ noDataMessage: N = "No data available for this graph",
98
+ currentValueDecimals: J,
99
+ containerClassName: $,
100
+ useSharedPriceScale: X,
101
+ showCurrentValue: q,
102
+ yScaleMin: Q,
103
+ yScaleMinMultiple: Y,
104
+ seriesColorPersistenceKey: u,
105
+ ...Z
106
106
  }) {
107
- const f = v(() => Array.isArray(e) ? e : e ? [e] : [], [e]), M = v(() => Array.isArray(e) && e.length > 1, [e]), N = oe(), Y = ee(
108
- (b, j) => {
109
- te.error(E);
107
+ const b = S(() => Array.isArray(e) ? e : e ? [e] : [], [e]), j = S(() => Array.isArray(e) && e.length > 1, [e]), R = ie(), G = oe(
108
+ (p, v) => {
109
+ ne.error(N);
110
110
  },
111
- [E]
112
- ), Z = v(() => {
111
+ [N]
112
+ ), U = S(() => {
113
113
  if (t)
114
114
  return Array.isArray(t) ? t[0] : t;
115
- }, [t]), P = (!N && C || I.length > 0 || w && S && s) && /* @__PURE__ */ y("div", { className: "z-10 w-full flex flex-row flex-wrap sm:flex-nowrap items-center gap-2", children: [
116
- /* @__PURE__ */ r("div", { children: w && S && s && /* @__PURE__ */ r(
117
- se,
115
+ }, [t]), P = (!R && A || k.length > 0 || h && d && c) && /* @__PURE__ */ y("div", { className: "z-10 w-full flex flex-row flex-wrap sm:flex-nowrap items-center gap-2", children: [
116
+ /* @__PURE__ */ i("div", { children: h && d && c && /* @__PURE__ */ i(
117
+ me,
118
118
  {
119
- onSelected: w,
120
- items: S,
121
- defaultItem: s,
122
- multiple: _,
123
- graphsWithNoData: F,
124
- loadingGraphs: T,
125
- onNoDataSelected: Y
119
+ onSelected: h,
120
+ items: d,
121
+ defaultItem: c,
122
+ multiple: V,
123
+ graphsWithNoData: D,
124
+ loadingGraphs: H,
125
+ onNoDataSelected: G
126
126
  }
127
127
  ) }),
128
128
  /* @__PURE__ */ y("div", { className: "flex flex-row flex-nowrap justify-start sm:justify-end items-center flex-1", children: [
129
- /* @__PURE__ */ r(ne, { range: V, rangeList: I, setRange: z }),
130
- !N && C && /* @__PURE__ */ r(
129
+ /* @__PURE__ */ i(se, { range: B, rangeList: k, setRange: F }),
130
+ !R && A && /* @__PURE__ */ i(
131
131
  "button",
132
132
  {
133
133
  type: "button",
134
134
  className: "px-2.5 py-1.5 flex min-w-[44px] min-h-[26px] justify-center items-center text-xs leading-[14px] font-medium text-center rounded-md border cursor-pointer transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring bg-muted border-muted text-muted-foreground hover:border-secondary ml-1.5",
135
- onClick: C,
136
- children: B ? /* @__PURE__ */ r(ue, { size: 16 }) : /* @__PURE__ */ r(ce, { size: 16 })
135
+ onClick: A,
136
+ children: T ? /* @__PURE__ */ i(de, { size: 16 }) : /* @__PURE__ */ i(ae, { size: 16 })
137
137
  }
138
138
  )
139
139
  ] })
140
- ] }), u = L(/* @__PURE__ */ new Map()), x = L(0), G = v(() => {
141
- const b = Array.isArray(t) ? t : void 0;
142
- if (h && f.length > 0) {
143
- const l = O(h);
144
- let m = -1;
145
- for (const d of f) {
146
- const p = d?.title || "";
147
- if (!p) continue;
148
- const a = l.get(p);
149
- !u.current.has(p) && a !== void 0 && (u.current.set(p, a), a > m && (m = a));
150
- }
151
- m >= 0 && (x.current = Math.max(
152
- x.current,
153
- m + 1
154
- ));
140
+ ] }), n = C(/* @__PURE__ */ new Map()), f = C(0), L = C(!1);
141
+ if (d && d.length > 0 && !L.current) {
142
+ L.current = !0;
143
+ const p = u ? E(u) : /* @__PURE__ */ new Map(), v = String(d[0].value);
144
+ n.current.set(v, 0), f.current = 1;
145
+ for (let r = 1; r < d.length; r++) {
146
+ const m = String(d[r].value);
147
+ if (n.current.has(m)) continue;
148
+ const x = p.get(m) ?? r;
149
+ n.current.set(m, x), f.current = Math.max(f.current, x + 1);
150
+ }
151
+ u && _(
152
+ u,
153
+ n.current
154
+ );
155
+ }
156
+ const K = S(() => {
157
+ const p = Array.isArray(t) ? t : void 0;
158
+ if (u) {
159
+ const r = E(u);
160
+ for (const [m, w] of r)
161
+ n.current.has(m) || (n.current.set(m, w), f.current = Math.max(
162
+ f.current,
163
+ w + 1
164
+ ));
155
165
  }
156
- const j = f.map((l, m) => {
157
- const d = l?.title || `Series ${m + 1}`;
158
- if (!u.current.has(d)) {
166
+ const v = b.map((r, m) => {
167
+ const w = r?.title || `Series ${m + 1}`, x = r?.id || w;
168
+ if (!n.current.has(x)) {
159
169
  const o = new Set(
160
- Array.from(u.current.values())
170
+ Array.from(n.current.values())
161
171
  );
162
- let n = x.current;
163
- for (let c = 0; c < A.length; c++) {
164
- const g = (x.current + c) % A.length;
172
+ let l = f.current;
173
+ for (let a = 0; a < M.length; a++) {
174
+ const g = (f.current + a) % M.length;
165
175
  if (!o.has(g)) {
166
- n = g;
176
+ l = g;
167
177
  break;
168
178
  }
169
179
  }
170
- u.current.set(d, n), x.current = n + 1;
180
+ n.current.set(x, l), f.current = l + 1;
171
181
  }
172
- const p = u.current.get(d) ?? 0, a = ie(p), U = [...l?.data || []].sort((o, n) => {
173
- const c = typeof o.time == "number" ? o.time : Number(o.time), g = typeof n.time == "number" ? n.time : Number(n.time);
174
- return c - g;
175
- }).reduce((o, n) => {
176
- const c = n.time;
177
- return o.length === 0 || o[o.length - 1].time !== c ? o.push({
178
- time: c,
179
- value: n.value
180
- }) : o[o.length - 1] = {
181
- time: c,
182
- value: n.value
183
- }, o;
184
- }, []), k = l?.lineColor ?? l?.color ?? void 0;
182
+ const te = n.current.get(x) ?? 0, I = ce(te), re = [...r?.data || []].sort((o, l) => {
183
+ const a = typeof o.time == "number" ? o.time : Number(o.time), g = typeof l.time == "number" ? l.time : Number(l.time);
184
+ return a - g;
185
+ }).reduce((o, l) => {
186
+ const a = l.time;
187
+ return o.length === 0 || o[o.length - 1].time !== a ? o.push({ time: a, value: l.value }) : o[o.length - 1] = { time: a, value: l.value }, o;
188
+ }, []), O = r?.lineColor ?? r?.color ?? void 0;
185
189
  return {
186
- data: U,
187
- label: d,
188
- yMeasureUnit: b?.[m] ?? (Array.isArray(t) ? void 0 : t),
189
- ...k != null ? {
190
- lineColor: k,
191
- ...l?.topColor != null && {
192
- topColor: l.topColor
190
+ data: re,
191
+ label: w,
192
+ yMeasureUnit: p?.[m] ?? (Array.isArray(t) ? void 0 : t),
193
+ ...O != null ? {
194
+ lineColor: O,
195
+ ...r?.topColor != null && {
196
+ topColor: r.topColor
193
197
  },
194
- ...l?.bottomColor != null && {
195
- bottomColor: l.bottomColor
198
+ ...r?.bottomColor != null && {
199
+ bottomColor: r.bottomColor
196
200
  }
197
201
  } : {
198
- color: a.line,
199
- topColor: a.top,
200
- bottomColor: a.bottom
202
+ color: I.line,
203
+ topColor: I.top,
204
+ bottomColor: I.bottom
201
205
  }
202
206
  };
203
207
  });
204
- return h && u.current.size > 0 && me(
205
- h,
206
- u.current
207
- ), j;
208
- }, [f, t, h]), K = M && f.length > 0 ? f.some((b) => !b) : !e;
209
- return /* @__PURE__ */ r(
208
+ return u && n.current.size > 0 && _(
209
+ u,
210
+ n.current
211
+ ), v;
212
+ }, [b, t, u]), ee = j && b.length > 0 ? b.some((p) => !p) : !e;
213
+ return /* @__PURE__ */ i(
210
214
  "div",
211
215
  {
212
216
  style: {
213
217
  width: "100%",
214
- height: i ? `${i}px` : void 0
218
+ height: s ? `${s}px` : void 0
215
219
  },
216
220
  className: "w-full",
217
- children: /* @__PURE__ */ r(
218
- le,
221
+ children: /* @__PURE__ */ i(
222
+ ue,
219
223
  {
220
- series: G,
221
- loading: K,
224
+ series: K,
225
+ loading: ee,
222
226
  toolbar: P,
223
- size: i ? "full" : "default",
224
- containerClassName: re("h-full", H),
225
- showLegend: M,
226
- onUnselectSeries: D,
227
- yMeasureUnit: Z,
228
- currentValueDecimals: W,
229
- useSharedPriceScale: J,
230
- showCurrentValue: $,
231
- yScaleMin: X,
232
- yScaleMinMultiple: q,
233
- ...Q
227
+ size: s ? "full" : "default",
228
+ containerClassName: le("h-full", $),
229
+ showLegend: j,
230
+ onUnselectSeries: W,
231
+ yMeasureUnit: U,
232
+ currentValueDecimals: J,
233
+ useSharedPriceScale: X,
234
+ showCurrentValue: q,
235
+ yScaleMin: Q,
236
+ yScaleMinMultiple: Y,
237
+ ...Z
234
238
  }
235
239
  )
236
240
  }
237
241
  );
238
242
  }
239
243
  export {
240
- Me as TradingView
244
+ Ne as TradingView
241
245
  };