@actionexec/dashboards 0.4.0 → 0.5.0

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.
package/dist/index.js CHANGED
@@ -1,106 +1,80 @@
1
- import { jsxs as _, jsx as l } from "react/jsx-runtime";
2
- import { useState as N, useRef as M, useEffect as T, useCallback as R, useMemo as G } from "react";
3
- import { J as z, z as I, G as E, m as D, u as x, H as X, k as L, t as H, r as U, d as q, w as J, v as Q, b as Z } from "./index-BHv7_r-h.js";
4
- import { PieChart as B, Pie as ee, Cell as te, Tooltip as W, LineChart as ae, Line as re, AreaChart as le, Area as ne, BarChart as ie, Bar as se, CartesianGrid as ce, XAxis as oe, YAxis as de, Legend as he } from "recharts";
5
- const ue = "https://action-data-api.fly.dev/api", ge = "/external/dashboards";
6
- class pe extends Error {
7
- constructor(r, n, t) {
8
- super(r), this.status = n, this.payload = t, this.name = "ApiError";
9
- }
10
- }
11
- async function Y(a, r, n) {
12
- const t = new URL(`${ue}${ge}${a}`);
13
- if (n)
14
- for (const [i, s] of Object.entries(n)) t.searchParams.set(i, s);
15
- const e = await fetch(t.toString(), {
16
- headers: { Authorization: `Bearer ${r}` }
17
- });
18
- if (!e.ok) {
19
- let i;
20
- try {
21
- i = await e.json();
22
- } catch {
23
- }
24
- throw new pe(
25
- `Requisicao falhou (${e.status}) em ${a}`,
26
- e.status,
27
- i
28
- );
29
- }
30
- return await e.json();
31
- }
32
- const me = (a) => Y("/layout", a), _e = (a, r) => Y("/render", a, r), fe = 300;
33
- function be(a) {
34
- const [r, n] = N(null), [t, e] = N(null), [i, s] = N({}), [c, p] = N({}), [o, d] = N(null), [h, g] = N(!0), [w, u] = N(null), m = M(), $ = M(!1);
1
+ import { jsxs as _, jsx as r } from "react/jsx-runtime";
2
+ import { useState as N, useRef as x, useEffect as T, useCallback as M, useMemo as G } from "react";
3
+ import { L as j, O as z, J as H, z as I, G as W, m as D, u as R, H as X, k as L, t as q, r as Q, d as U, w as J, v as Z, b as B } from "./index-C3jiurhg.js";
4
+ import { Q as Ke } from "./index-C3jiurhg.js";
5
+ import { PieChart as ee, Pie as te, Cell as ae, Tooltip as P, LineChart as re, Line as le, AreaChart as ne, Area as ie, BarChart as se, Bar as ce, CartesianGrid as oe, XAxis as de, YAxis as ge, Legend as he } from "recharts";
6
+ const ue = 300;
7
+ function me(l) {
8
+ const [a, n] = N(null), [t, e] = N(null), [i, s] = N({}), [c, m] = N({}), [o, d] = N(null), [g, u] = N(!0), [w, h] = N(null), p = x(), k = x(!1);
35
9
  T(() => {
36
10
  let v = !1;
37
- return me(a).then((b) => {
38
- v || n(b);
39
- }).catch((b) => {
40
- v || u(b.message);
11
+ return j(l).then((f) => {
12
+ v || n(f);
13
+ }).catch((f) => {
14
+ v || h(f.message);
41
15
  }), () => {
42
16
  v = !0;
43
17
  };
44
- }, [a]), T(() => {
45
- if (r)
46
- return m.current && clearTimeout(m.current), m.current = setTimeout(() => {
47
- const v = ve(i, c);
48
- g(!0), _e(a, v).then((b) => {
49
- e(b), !$.current && b.applied && ($.current = !0, s((k) => ({ ...we(b.applied), ...k }))), u(null);
50
- }).catch((b) => u(b.message)).finally(() => g(!1));
51
- }, fe), () => {
52
- m.current && clearTimeout(m.current);
18
+ }, [l]), T(() => {
19
+ if (a)
20
+ return p.current && clearTimeout(p.current), p.current = setTimeout(() => {
21
+ const v = pe(i, c);
22
+ u(!0), z(l, v).then((f) => {
23
+ e(f), !k.current && f.applied && (k.current = !0, s(($) => ({ ..._e(f.applied), ...$ }))), h(null);
24
+ }).catch((f) => h(f.message)).finally(() => u(!1));
25
+ }, ue), () => {
26
+ p.current && clearTimeout(p.current);
53
27
  };
54
- }, [a, r, i, c]);
55
- const f = R((v, b) => {
56
- s((k) => ({ ...k, [v]: b }));
57
- }, []), C = R((v, b) => {
58
- p((k) => ({ ...k, [v]: b }));
59
- }, []), y = R((v) => {
28
+ }, [l, a, i, c]);
29
+ const b = M((v, f) => {
30
+ s(($) => ({ ...$, [v]: f }));
31
+ }, []), C = M((v, f) => {
32
+ m(($) => ({ ...$, [v]: f }));
33
+ }, []), y = M((v) => {
60
34
  d(v);
61
35
  }, []), S = G(
62
- () => o ?? (r == null ? void 0 : r.palette) ?? [],
63
- [o, r]
36
+ () => o ?? (a == null ? void 0 : a.palette) ?? [],
37
+ [o, a]
64
38
  );
65
39
  return {
66
- layout: r,
40
+ layout: a,
67
41
  renderData: t,
68
- loading: h,
42
+ loading: g,
69
43
  error: w,
70
44
  filters: i,
71
45
  variables: c,
72
46
  palette: S,
73
- setFilter: f,
47
+ setFilter: b,
74
48
  setVariable: C,
75
49
  setPalette: y
76
50
  };
77
51
  }
78
- function ve(a, r) {
52
+ function pe(l, a) {
79
53
  const n = {};
80
- for (const [t, e] of Object.entries(a))
54
+ for (const [t, e] of Object.entries(l))
81
55
  if (e.includes("|")) {
82
56
  const [i, s] = e.split("|");
83
57
  i && (n.f_date_start = i), s && (n.f_date_end = s);
84
58
  } else
85
59
  n[`f_${t}`] = e;
86
- for (const [t, e] of Object.entries(r))
60
+ for (const [t, e] of Object.entries(a))
87
61
  n[`v_${t}`] = String(e);
88
62
  return n;
89
63
  }
90
- function we(a) {
91
- const r = {};
92
- for (const [n, t] of Object.entries(a))
64
+ function _e(l) {
65
+ const a = {};
66
+ for (const [n, t] of Object.entries(l))
93
67
  if (t && typeof t == "object" && "start" in t) {
94
68
  const e = t;
95
- r[n] = `${e.start || ""}|${e.end || ""}`;
96
- } else Array.isArray(t) ? r[n] = t.join(",") : typeof t == "string" && (r[n] = t);
97
- return r;
69
+ a[n] = `${e.start || ""}|${e.end || ""}`;
70
+ } else Array.isArray(t) ? a[n] = t.join(",") : typeof t == "string" && (a[n] = t);
71
+ return a;
98
72
  }
99
- function ye({ data: a, label: r }) {
100
- const n = r || String(a.label || ""), t = String(a.formatted || "-"), e = a.comparison, i = (e == null ? void 0 : e.trend) === "up" ? "widget-kpi__trend--up" : (e == null ? void 0 : e.trend) === "down" ? "widget-kpi__trend--down" : "", s = (e == null ? void 0 : e.trend) === "up" ? "↑" : (e == null ? void 0 : e.trend) === "down" ? "↓" : "";
73
+ function be({ data: l, label: a }) {
74
+ const n = a || String(l.label || ""), t = String(l.formatted || "-"), e = l.comparison, i = (e == null ? void 0 : e.trend) === "up" ? "widget-kpi__trend--up" : (e == null ? void 0 : e.trend) === "down" ? "widget-kpi__trend--down" : "", s = (e == null ? void 0 : e.trend) === "up" ? "↑" : (e == null ? void 0 : e.trend) === "down" ? "↓" : "";
101
75
  return /* @__PURE__ */ _("div", { className: "widget widget-kpi", children: [
102
- /* @__PURE__ */ l("span", { className: "widget-kpi__label", children: n }),
103
- /* @__PURE__ */ l("span", { className: "widget-kpi__value", children: t }),
76
+ /* @__PURE__ */ r("span", { className: "widget-kpi__label", children: n }),
77
+ /* @__PURE__ */ r("span", { className: "widget-kpi__value", children: t }),
104
78
  e && e.variance_pct != null && /* @__PURE__ */ _("div", { className: `widget-kpi__trend ${i}`, children: [
105
79
  /* @__PURE__ */ _("span", { className: "widget-kpi__variance", children: [
106
80
  s,
@@ -109,101 +83,101 @@ function ye({ data: a, label: r }) {
109
83
  e.variance_pct.toFixed(1),
110
84
  "%"
111
85
  ] }),
112
- e.label && /* @__PURE__ */ l("span", { className: "widget-kpi__trend-label", children: e.label })
86
+ e.label && /* @__PURE__ */ r("span", { className: "widget-kpi__trend-label", children: e.label })
113
87
  ] })
114
88
  ] });
115
89
  }
116
- const Ne = "var(--bg-elevated)";
117
- function P(a, r, n, t) {
90
+ const fe = "var(--bg-elevated)";
91
+ function O(l, a, n, t) {
118
92
  if (t <= 0) return "";
119
93
  if (t >= 1)
120
- return `M ${a - n} ${r} A ${n} ${n} 0 0 1 ${a} ${r - n} A ${n} ${n} 0 0 1 ${a + n} ${r}`;
121
- const e = t * Math.PI, i = a - n * Math.cos(e), s = r - n * Math.sin(e);
122
- return `M ${a - n} ${r} A ${n} ${n} 0 0 1 ${i} ${s}`;
94
+ return `M ${l - n} ${a} A ${n} ${n} 0 0 1 ${l} ${a - n} A ${n} ${n} 0 0 1 ${l + n} ${a}`;
95
+ const e = t * Math.PI, i = l - n * Math.cos(e), s = a - n * Math.sin(e);
96
+ return `M ${l - n} ${a} A ${n} ${n} 0 0 1 ${i} ${s}`;
123
97
  }
124
- function A(a) {
125
- const r = Math.abs(a);
126
- return r >= 1e6 ? `${(a / 1e6).toFixed(1)}M` : r >= 1e3 ? `${(a / 1e3).toFixed(1)}K` : a.toLocaleString("pt-BR");
98
+ function A(l) {
99
+ const a = Math.abs(l);
100
+ return a >= 1e6 ? `${(l / 1e6).toFixed(1)}M` : a >= 1e3 ? `${(l / 1e3).toFixed(1)}K` : l.toLocaleString("pt-BR");
127
101
  }
128
- function $e({ data: a, palette: r, label: n }) {
129
- const t = n || String(a.label || ""), e = typeof a.value == "number" ? a.value : null, i = e != null ? A(e) : "-", s = String(a.formatted || "-"), c = typeof a.ratio == "number" ? a.ratio : 0, p = a.target_value, o = a.comparison_label, d = c >= 1, h = Math.min(Math.max(c, 0), 1), g = d ? "var(--action-green)" : c >= 0.7 ? r[0] || "var(--color-info)" : c >= 0.4 ? "var(--color-warning)" : "var(--color-error)", w = p != null ? A(p) : "-", u = 50, m = 50, $ = 44, f = 10;
102
+ function ve({ data: l, palette: a, label: n }) {
103
+ const t = n || String(l.label || ""), e = typeof l.value == "number" ? l.value : null, i = e != null ? A(e) : "-", s = String(l.formatted || "-"), c = typeof l.ratio == "number" ? l.ratio : 0, m = l.target_value, o = l.comparison_label, d = c >= 1, g = Math.min(Math.max(c, 0), 1), u = d ? "var(--action-green)" : c >= 0.7 ? a[0] || "var(--color-info)" : c >= 0.4 ? "var(--color-warning)" : "var(--color-error)", w = m != null ? A(m) : "-", h = 50, p = 50, k = 44, b = 10;
130
104
  return /* @__PURE__ */ _("div", { className: "widget widget-gauge", children: [
131
- /* @__PURE__ */ l("span", { className: "widget-gauge__label", children: t }),
105
+ /* @__PURE__ */ r("span", { className: "widget-gauge__label", children: t }),
132
106
  /* @__PURE__ */ _("div", { className: "widget-gauge__chart", children: [
133
107
  /* @__PURE__ */ _("svg", { viewBox: "0 0 100 56", preserveAspectRatio: "xMidYMax meet", children: [
134
- /* @__PURE__ */ l("path", { d: P(u, m, $, 1), fill: "none", stroke: Ne, strokeWidth: f, strokeLinecap: "butt" }),
135
- h > 0 && /* @__PURE__ */ l("path", { d: P(u, m, $, h), fill: "none", stroke: g, strokeWidth: f, strokeLinecap: "butt" })
108
+ /* @__PURE__ */ r("path", { d: O(h, p, k, 1), fill: "none", stroke: fe, strokeWidth: b, strokeLinecap: "butt" }),
109
+ g > 0 && /* @__PURE__ */ r("path", { d: O(h, p, k, g), fill: "none", stroke: u, strokeWidth: b, strokeLinecap: "butt" })
136
110
  ] }),
137
111
  /* @__PURE__ */ _("div", { className: "widget-gauge__center", children: [
138
- /* @__PURE__ */ l("span", { className: "widget-gauge__percent", children: s }),
112
+ /* @__PURE__ */ r("span", { className: "widget-gauge__percent", children: s }),
139
113
  /* @__PURE__ */ _("span", { className: "widget-gauge__comparison", children: [
140
114
  i,
141
115
  " / ",
142
116
  w
143
117
  ] }),
144
- d && /* @__PURE__ */ l("span", { className: "widget-gauge__badge", children: o || "Meta batida" }),
145
- !d && o && /* @__PURE__ */ l("span", { className: "widget-gauge__comparison", children: o })
118
+ d && /* @__PURE__ */ r("span", { className: "widget-gauge__badge", children: o || "Meta batida" }),
119
+ !d && o && /* @__PURE__ */ r("span", { className: "widget-gauge__comparison", children: o })
146
120
  ] })
147
121
  ] })
148
122
  ] });
149
123
  }
150
- const O = { fontSize: 10, fill: "var(--text-muted)" }, ke = "var(--bg-elevated)", V = {
124
+ const E = { fontSize: 10, fill: "var(--text-muted)" }, we = "var(--bg-elevated)", Y = {
151
125
  backgroundColor: "var(--bg-elevated)",
152
126
  border: "1px solid var(--bg-paper)",
153
127
  borderRadius: "6px",
154
128
  color: "var(--text-primary)"
155
- }, j = {
129
+ }, V = {
156
130
  color: "var(--text-primary)",
157
131
  fontWeight: 600
158
132
  };
159
- function K(a, r) {
133
+ function K(l, a) {
160
134
  var e;
161
- const n = Array.isArray(r) ? r[0] : void 0, t = (e = n == null ? void 0 : n.payload) == null ? void 0 : e.tooltipLabel;
162
- return typeof t == "string" && t ? t : String(a ?? "");
135
+ const n = Array.isArray(a) ? a[0] : void 0, t = (e = n == null ? void 0 : n.payload) == null ? void 0 : e.tooltipLabel;
136
+ return typeof t == "string" && t ? t : String(l ?? "");
163
137
  }
164
- function Ce(a) {
165
- const [r, n] = N({ width: 0, height: 0 });
138
+ function ye(l) {
139
+ const [a, n] = N({ width: 0, height: 0 });
166
140
  return T(() => {
167
- const t = a.current;
141
+ const t = l.current;
168
142
  if (!t) return;
169
143
  const e = new ResizeObserver(([i]) => {
170
144
  const { width: s, height: c } = i.contentRect;
171
145
  n(
172
- (p) => p.width !== Math.floor(s) || p.height !== Math.floor(c) ? { width: Math.floor(s), height: Math.floor(c) } : p
146
+ (m) => m.width !== Math.floor(s) || m.height !== Math.floor(c) ? { width: Math.floor(s), height: Math.floor(c) } : m
173
147
  );
174
148
  });
175
149
  return e.observe(t), () => e.disconnect();
176
- }, [a]), r;
150
+ }, [l]), a;
177
151
  }
178
- function F({ Chart: a, chartData: r, xKey: n, series: t, palette: e, renderSeries: i, width: s, height: c }) {
179
- return /* @__PURE__ */ _(a, { data: r, width: s, height: c, children: [
180
- /* @__PURE__ */ l(ce, { strokeDasharray: "3 3", stroke: ke }),
181
- /* @__PURE__ */ l(oe, { dataKey: n, tick: O }),
182
- /* @__PURE__ */ l(de, { tick: O }),
183
- /* @__PURE__ */ l(
184
- W,
152
+ function F({ Chart: l, chartData: a, xKey: n, series: t, palette: e, renderSeries: i, width: s, height: c }) {
153
+ return /* @__PURE__ */ _(l, { data: a, width: s, height: c, children: [
154
+ /* @__PURE__ */ r(oe, { strokeDasharray: "3 3", stroke: we }),
155
+ /* @__PURE__ */ r(de, { dataKey: n, tick: E }),
156
+ /* @__PURE__ */ r(ge, { tick: E }),
157
+ /* @__PURE__ */ r(
158
+ P,
185
159
  {
186
- contentStyle: V,
187
- labelStyle: j,
160
+ contentStyle: Y,
161
+ labelStyle: V,
188
162
  labelFormatter: K,
189
163
  cursor: { fill: "var(--bg-paper)", opacity: 0.3 }
190
164
  }
191
165
  ),
192
- t.length > 1 && /* @__PURE__ */ l(he, {}),
193
- t.map((p, o) => i(p, e[o % e.length], o))
166
+ t.length > 1 && /* @__PURE__ */ r(he, {}),
167
+ t.map((m, o) => i(m, e[o % e.length], o))
194
168
  ] });
195
169
  }
196
- function Se({ data: a, palette: r, label: n }) {
197
- const t = String(a.chartType || "bar"), e = n || String(a.label || ""), i = String(a.xKey || "label"), s = a.series || [], c = a.data || [], p = M(null), { width: o, height: d } = Ce(p);
170
+ function Ne({ data: l, palette: a, label: n }) {
171
+ const t = String(l.chartType || "bar"), e = n || String(l.label || ""), i = String(l.xKey || "label"), s = l.series || [], c = l.data || [], m = x(null), { width: o, height: d } = ye(m);
198
172
  return c.length ? /* @__PURE__ */ _("div", { className: "widget widget-chart", children: [
199
- e && /* @__PURE__ */ l("h4", { className: "widget-chart__title", children: e }),
200
- /* @__PURE__ */ l("div", { ref: p, className: "widget-chart__container", children: (() => {
173
+ e && /* @__PURE__ */ r("h4", { className: "widget-chart__title", children: e }),
174
+ /* @__PURE__ */ r("div", { ref: m, className: "widget-chart__container", children: (() => {
201
175
  var w;
202
176
  if (o <= 0 || d <= 0) return null;
203
177
  if (t === "pie")
204
- return /* @__PURE__ */ _(B, { width: o, height: d, children: [
205
- /* @__PURE__ */ l(
206
- ee,
178
+ return /* @__PURE__ */ _(ee, { width: o, height: d, children: [
179
+ /* @__PURE__ */ r(
180
+ te,
207
181
  {
208
182
  data: c,
209
183
  dataKey: ((w = s[0]) == null ? void 0 : w.key) || "s0",
@@ -211,64 +185,64 @@ function Se({ data: a, palette: r, label: n }) {
211
185
  cx: "50%",
212
186
  cy: "50%",
213
187
  outerRadius: "75%",
214
- label: ({ name: u, percent: m }) => `${u}: ${(m * 100).toFixed(0)}%`,
188
+ label: ({ name: h, percent: p }) => `${h}: ${(p * 100).toFixed(0)}%`,
215
189
  labelLine: !1,
216
- children: c.map((u, m) => /* @__PURE__ */ l(te, { fill: r[m % r.length] }, m))
190
+ children: c.map((h, p) => /* @__PURE__ */ r(ae, { fill: a[p % a.length] }, p))
217
191
  }
218
192
  ),
219
- /* @__PURE__ */ l(
220
- W,
193
+ /* @__PURE__ */ r(
194
+ P,
221
195
  {
222
- contentStyle: V,
223
- labelStyle: j,
196
+ contentStyle: Y,
197
+ labelStyle: V,
224
198
  labelFormatter: K
225
199
  }
226
200
  )
227
201
  ] });
228
- const g = { chartData: c, xKey: i, series: s, palette: r, width: o, height: d };
229
- return t === "line" ? /* @__PURE__ */ l(F, { ...g, Chart: ae, renderSeries: (u, m) => /* @__PURE__ */ l(
230
- re,
202
+ const u = { chartData: c, xKey: i, series: s, palette: a, width: o, height: d };
203
+ return t === "line" ? /* @__PURE__ */ r(F, { ...u, Chart: re, renderSeries: (h, p) => /* @__PURE__ */ r(
204
+ le,
231
205
  {
232
206
  type: "monotone",
233
- dataKey: u.key,
234
- name: u.label,
235
- stroke: m,
207
+ dataKey: h.key,
208
+ name: h.label,
209
+ stroke: p,
236
210
  strokeWidth: 2,
237
211
  dot: c.length <= 31
238
212
  },
239
- u.key
240
- ) }) : t === "area" ? /* @__PURE__ */ l(F, { ...g, Chart: le, renderSeries: (u, m) => /* @__PURE__ */ l(
241
- ne,
213
+ h.key
214
+ ) }) : t === "area" ? /* @__PURE__ */ r(F, { ...u, Chart: ne, renderSeries: (h, p) => /* @__PURE__ */ r(
215
+ ie,
242
216
  {
243
217
  type: "monotone",
244
- dataKey: u.key,
245
- name: u.label,
246
- fill: m,
247
- stroke: m,
218
+ dataKey: h.key,
219
+ name: h.label,
220
+ fill: p,
221
+ stroke: p,
248
222
  fillOpacity: 0.3
249
223
  },
250
- u.key
251
- ) }) : /* @__PURE__ */ l(F, { ...g, Chart: ie, renderSeries: (u, m) => /* @__PURE__ */ l(
252
- se,
224
+ h.key
225
+ ) }) : /* @__PURE__ */ r(F, { ...u, Chart: se, renderSeries: (h, p) => /* @__PURE__ */ r(
226
+ ce,
253
227
  {
254
- dataKey: u.key,
255
- name: u.label,
256
- fill: m,
228
+ dataKey: h.key,
229
+ name: h.label,
230
+ fill: p,
257
231
  radius: [3, 3, 0, 0]
258
232
  },
259
- u.key
233
+ h.key
260
234
  ) });
261
235
  })() })
262
- ] }) : /* @__PURE__ */ l("div", { className: "widget widget-chart widget-chart--empty", children: "Sem dados" });
236
+ ] }) : /* @__PURE__ */ r("div", { className: "widget widget-chart widget-chart--empty", children: "Sem dados" });
263
237
  }
264
- function Re({ config: a, value: r, options: n = [], dateBounds: t, onChange: e }) {
265
- const i = a.filterType || "select", s = a.label || "Filtro", c = a.dateFilterMode || "range";
238
+ function ke({ config: l, value: a, options: n = [], dateBounds: t, onChange: e }) {
239
+ const i = l.filterType || "select", s = l.label || "Filtro", c = l.dateFilterMode || "range";
266
240
  return /* @__PURE__ */ _("div", { className: "widget-filter", children: [
267
- /* @__PURE__ */ l("label", { className: "widget-filter__label", children: s }),
268
- i === "date_range" ? c === "yearly" ? /* @__PURE__ */ l(Fe, { value: r, dateBounds: t, onChange: e }) : c === "monthly" ? /* @__PURE__ */ l(Me, { value: r, dateBounds: t, onChange: e }) : c === "weekly" ? /* @__PURE__ */ l(Te, { value: r, dateBounds: t, onChange: e }) : /* @__PURE__ */ l(xe, { value: r, dateBounds: t, onChange: e }) : /* @__PURE__ */ l(
269
- Ie,
241
+ /* @__PURE__ */ r("label", { className: "widget-filter__label", children: s }),
242
+ i === "date_range" ? c === "yearly" ? /* @__PURE__ */ r(Ce, { value: a, dateBounds: t, onChange: e }) : c === "monthly" ? /* @__PURE__ */ r(Se, { value: a, dateBounds: t, onChange: e }) : c === "weekly" ? /* @__PURE__ */ r(Me, { value: a, dateBounds: t, onChange: e }) : /* @__PURE__ */ r($e, { value: a, dateBounds: t, onChange: e }) : /* @__PURE__ */ r(
243
+ Re,
270
244
  {
271
- value: r,
245
+ value: a,
272
246
  options: n,
273
247
  multi: i === "multi_select",
274
248
  onChange: e
@@ -276,15 +250,15 @@ function Re({ config: a, value: r, options: n = [], dateBounds: t, onChange: e }
276
250
  )
277
251
  ] });
278
252
  }
279
- function xe({ value: a, dateBounds: r, onChange: n }) {
280
- const [t, e] = a ? a.split("|") : ["", ""];
253
+ function $e({ value: l, dateBounds: a, onChange: n }) {
254
+ const [t, e] = l ? l.split("|") : ["", ""];
281
255
  return /* @__PURE__ */ _("div", { className: "widget-filter__date-range widget-filter__date-range--stacked", children: [
282
- /* @__PURE__ */ l(
256
+ /* @__PURE__ */ r(
283
257
  L,
284
258
  {
285
259
  value: t,
286
- minIso: r == null ? void 0 : r.min,
287
- maxIso: e || (r == null ? void 0 : r.max),
260
+ minIso: a == null ? void 0 : a.min,
261
+ maxIso: e || (a == null ? void 0 : a.max),
288
262
  selectsStart: !0,
289
263
  startIso: t,
290
264
  endIso: e,
@@ -292,12 +266,12 @@ function xe({ value: a, dateBounds: r, onChange: n }) {
292
266
  onChange: (i) => n(`${i}|${e}`)
293
267
  }
294
268
  ),
295
- /* @__PURE__ */ l(
269
+ /* @__PURE__ */ r(
296
270
  L,
297
271
  {
298
272
  value: e,
299
- minIso: t || (r == null ? void 0 : r.min),
300
- maxIso: r == null ? void 0 : r.max,
273
+ minIso: t || (a == null ? void 0 : a.min),
274
+ maxIso: a == null ? void 0 : a.max,
301
275
  selectsEnd: !0,
302
276
  startIso: t,
303
277
  endIso: e,
@@ -307,96 +281,96 @@ function xe({ value: a, dateBounds: r, onChange: n }) {
307
281
  )
308
282
  ] });
309
283
  }
310
- function Fe({ value: a, dateBounds: r, onChange: n }) {
311
- const [t] = a ? a.split("|") : [""], e = z(t), i = /* @__PURE__ */ new Date(), s = (e == null ? void 0 : e.year) ?? i.getFullYear(), c = I(r), p = (o) => {
312
- const d = U(o);
284
+ function Ce({ value: l, dateBounds: a, onChange: n }) {
285
+ const [t] = l ? l.split("|") : [""], e = H(t), i = /* @__PURE__ */ new Date(), s = (e == null ? void 0 : e.year) ?? i.getFullYear(), c = I(a), m = (o) => {
286
+ const d = Q(o);
313
287
  n(`${d.start}|${d.end}`);
314
288
  };
315
- return /* @__PURE__ */ l("div", { className: "widget-filter__date-range widget-filter__date-range--year", children: /* @__PURE__ */ l(
289
+ return /* @__PURE__ */ r("div", { className: "widget-filter__date-range widget-filter__date-range--year", children: /* @__PURE__ */ r(
316
290
  "select",
317
291
  {
318
292
  className: "widget-filter__select",
319
293
  value: s,
320
- onChange: (o) => p(parseInt(o.target.value)),
321
- children: c.map((o) => /* @__PURE__ */ l("option", { value: o, children: o }, o))
294
+ onChange: (o) => m(parseInt(o.target.value)),
295
+ children: c.map((o) => /* @__PURE__ */ r("option", { value: o, children: o }, o))
322
296
  }
323
297
  ) });
324
298
  }
325
- function Me({ value: a, dateBounds: r, onChange: n }) {
326
- const [t] = a ? a.split("|") : [""], e = E(t), i = /* @__PURE__ */ new Date(), s = (e == null ? void 0 : e.year) ?? i.getFullYear(), c = (e == null ? void 0 : e.month) ?? i.getMonth() + 1, p = I(r), o = (d, h) => {
327
- const g = H(d, h);
328
- n(`${g.start}|${g.end}`);
299
+ function Se({ value: l, dateBounds: a, onChange: n }) {
300
+ const [t] = l ? l.split("|") : [""], e = W(t), i = /* @__PURE__ */ new Date(), s = (e == null ? void 0 : e.year) ?? i.getFullYear(), c = (e == null ? void 0 : e.month) ?? i.getMonth() + 1, m = I(a), o = (d, g) => {
301
+ const u = q(d, g);
302
+ n(`${u.start}|${u.end}`);
329
303
  };
330
304
  return /* @__PURE__ */ _("div", { className: "widget-filter__date-range widget-filter__date-range--month", children: [
331
- /* @__PURE__ */ l(
305
+ /* @__PURE__ */ r(
332
306
  "select",
333
307
  {
334
308
  className: "widget-filter__select",
335
309
  value: c,
336
310
  onChange: (d) => o(s, parseInt(d.target.value)),
337
- children: D.map((d, h) => /* @__PURE__ */ l("option", { value: h + 1, children: d }, h + 1))
311
+ children: D.map((d, g) => /* @__PURE__ */ r("option", { value: g + 1, children: d }, g + 1))
338
312
  }
339
313
  ),
340
- /* @__PURE__ */ l(
314
+ /* @__PURE__ */ r(
341
315
  "select",
342
316
  {
343
317
  className: "widget-filter__select",
344
318
  value: s,
345
319
  onChange: (d) => o(parseInt(d.target.value), c),
346
- children: p.map((d) => /* @__PURE__ */ l("option", { value: d, children: d }, d))
320
+ children: m.map((d) => /* @__PURE__ */ r("option", { value: d, children: d }, d))
347
321
  }
348
322
  )
349
323
  ] });
350
324
  }
351
- function Te({ value: a, dateBounds: r, onChange: n }) {
352
- const [t] = a ? a.split("|") : [""], e = E(t), i = /* @__PURE__ */ new Date(), s = (e == null ? void 0 : e.year) ?? i.getFullYear(), c = (e == null ? void 0 : e.month) ?? i.getMonth() + 1, p = I(r), o = x(s, c), d = X(t, s, c) || 1;
325
+ function Me({ value: l, dateBounds: a, onChange: n }) {
326
+ const [t] = l ? l.split("|") : [""], e = W(t), i = /* @__PURE__ */ new Date(), s = (e == null ? void 0 : e.year) ?? i.getFullYear(), c = (e == null ? void 0 : e.month) ?? i.getMonth() + 1, m = I(a), o = R(s, c), d = X(t, s, c) || 1;
353
327
  return /* @__PURE__ */ _("div", { className: "widget-filter__date-range widget-filter__date-range--week", children: [
354
- /* @__PURE__ */ l(
328
+ /* @__PURE__ */ r(
355
329
  "select",
356
330
  {
357
331
  className: "widget-filter__select",
358
332
  value: s,
359
- onChange: (h) => {
360
- const g = parseInt(h.target.value), u = x(g, c)[0];
361
- u && n(`${u.start}|${u.end}`);
333
+ onChange: (g) => {
334
+ const u = parseInt(g.target.value), h = R(u, c)[0];
335
+ h && n(`${h.start}|${h.end}`);
362
336
  },
363
- children: p.map((h) => /* @__PURE__ */ l("option", { value: h, children: h }, h))
337
+ children: m.map((g) => /* @__PURE__ */ r("option", { value: g, children: g }, g))
364
338
  }
365
339
  ),
366
- /* @__PURE__ */ l(
340
+ /* @__PURE__ */ r(
367
341
  "select",
368
342
  {
369
343
  className: "widget-filter__select",
370
344
  value: c,
371
- onChange: (h) => {
372
- const g = parseInt(h.target.value), u = x(s, g)[0];
373
- u && n(`${u.start}|${u.end}`);
345
+ onChange: (g) => {
346
+ const u = parseInt(g.target.value), h = R(s, u)[0];
347
+ h && n(`${h.start}|${h.end}`);
374
348
  },
375
- children: D.map((h, g) => /* @__PURE__ */ l("option", { value: g + 1, children: h }, g + 1))
349
+ children: D.map((g, u) => /* @__PURE__ */ r("option", { value: u + 1, children: g }, u + 1))
376
350
  }
377
351
  ),
378
- /* @__PURE__ */ l(
352
+ /* @__PURE__ */ r(
379
353
  "select",
380
354
  {
381
355
  className: "widget-filter__select",
382
356
  value: d,
383
- onChange: (h) => {
384
- const g = o[parseInt(h.target.value) - 1];
385
- g && n(`${g.start}|${g.end}`);
357
+ onChange: (g) => {
358
+ const u = o[parseInt(g.target.value) - 1];
359
+ u && n(`${u.start}|${u.end}`);
386
360
  },
387
- children: o.map((h) => /* @__PURE__ */ l("option", { value: h.index, children: h.label }, h.index))
361
+ children: o.map((g) => /* @__PURE__ */ r("option", { value: g.index, children: g.label }, g.index))
388
362
  }
389
363
  )
390
364
  ] });
391
365
  }
392
- function Ie({ value: a, options: r, multi: n, onChange: t }) {
366
+ function Re({ value: l, options: a, multi: n, onChange: t }) {
393
367
  if (n) {
394
- const e = a ? a.split(",") : [], i = (s) => {
395
- const c = e.includes(s) ? e.filter((p) => p !== s) : [...e, s];
368
+ const e = l ? l.split(",") : [], i = (s) => {
369
+ const c = e.includes(s) ? e.filter((m) => m !== s) : [...e, s];
396
370
  t(c.join(","));
397
371
  };
398
- return /* @__PURE__ */ l("div", { className: "widget-filter__multi", children: r.map((s) => /* @__PURE__ */ _("label", { className: "widget-filter__multi-option", children: [
399
- /* @__PURE__ */ l(
372
+ return /* @__PURE__ */ r("div", { className: "widget-filter__multi", children: a.map((s) => /* @__PURE__ */ _("label", { className: "widget-filter__multi-option", children: [
373
+ /* @__PURE__ */ r(
400
374
  "input",
401
375
  {
402
376
  type: "checkbox",
@@ -411,74 +385,74 @@ function Ie({ value: a, options: r, multi: n, onChange: t }) {
411
385
  "select",
412
386
  {
413
387
  className: "widget-filter__select",
414
- value: a,
388
+ value: l,
415
389
  onChange: (e) => t(e.target.value),
416
390
  children: [
417
- /* @__PURE__ */ l("option", { value: "", children: "Todos" }),
418
- r.map((e) => /* @__PURE__ */ l("option", { value: e, children: e }, e))
391
+ /* @__PURE__ */ r("option", { value: "", children: "Todos" }),
392
+ a.map((e) => /* @__PURE__ */ r("option", { value: e, children: e }, e))
419
393
  ]
420
394
  }
421
395
  );
422
396
  }
423
- const Le = {
397
+ const Fe = {
424
398
  currency: "R$",
425
399
  percentage: "%"
426
400
  };
427
- function Pe({ config: a, value: r, onChange: n }) {
428
- const t = a.label || "Variavel", e = a.locked || !1, i = a.variableFormat || "number", s = Le[i] || "";
401
+ function xe({ config: l, value: a, onChange: n }) {
402
+ const t = l.label || "Variavel", e = l.locked || !1, i = l.variableFormat || "number", s = Fe[i] || "";
429
403
  return /* @__PURE__ */ _("div", { className: `widget-variable ${e ? "widget-variable--locked" : ""}`, children: [
430
- /* @__PURE__ */ l("label", { className: "widget-variable__label", children: t }),
404
+ /* @__PURE__ */ r("label", { className: "widget-variable__label", children: t }),
431
405
  /* @__PURE__ */ _("div", { className: "widget-variable__input-wrapper", children: [
432
- /* @__PURE__ */ l(
406
+ /* @__PURE__ */ r(
433
407
  "input",
434
408
  {
435
409
  className: "widget-variable__input",
436
410
  type: "number",
437
- value: r,
411
+ value: a,
438
412
  onChange: (c) => n(parseFloat(c.target.value) || 0),
439
413
  disabled: e,
440
414
  step: i === "integer" ? 1 : 0.01
441
415
  }
442
416
  ),
443
- s && /* @__PURE__ */ l("span", { className: "widget-variable__suffix", children: s })
417
+ s && /* @__PURE__ */ r("span", { className: "widget-variable__suffix", children: s })
444
418
  ] }),
445
- e && /* @__PURE__ */ l("span", { className: "widget-variable__lock-icon", title: "Bloqueado", children: "🔒" })
419
+ e && /* @__PURE__ */ r("span", { className: "widget-variable__lock-icon", title: "Bloqueado", children: "🔒" })
446
420
  ] });
447
421
  }
448
- function Ae({ config: a, palette: r, onChange: n }) {
449
- const t = a.label || "Cores", e = a.locked || !1;
422
+ function Te({ config: l, palette: a, onChange: n }) {
423
+ const t = l.label || "Cores", e = l.locked || !1;
450
424
  return /* @__PURE__ */ _("div", { className: `widget-palette ${e ? "widget-palette--locked" : ""}`, children: [
451
- /* @__PURE__ */ l("label", { className: "widget-palette__label", children: t }),
452
- /* @__PURE__ */ l(q, { selected: r, onSelect: n, customMode: !0, disabled: e }),
453
- e && /* @__PURE__ */ l("span", { className: "widget-palette__lock-icon", title: "Bloqueado", children: "🔒" })
425
+ /* @__PURE__ */ r("label", { className: "widget-palette__label", children: t }),
426
+ /* @__PURE__ */ r(U, { selected: a, onSelect: n, customMode: !0, disabled: e }),
427
+ e && /* @__PURE__ */ r("span", { className: "widget-palette__lock-icon", title: "Bloqueado", children: "🔒" })
454
428
  ] });
455
429
  }
456
- function Oe({
457
- type: a,
458
- computed: r,
430
+ function Ie({
431
+ type: l,
432
+ computed: a,
459
433
  palette: n,
460
434
  config: t,
461
435
  filterValue: e,
462
436
  filterOptions: i,
463
437
  dateBounds: s,
464
438
  onFilterChange: c,
465
- variableValue: p,
439
+ variableValue: m,
466
440
  onVariableChange: o,
467
441
  onPaletteChange: d
468
442
  }) {
469
- if (r.error)
470
- return /* @__PURE__ */ l("div", { className: "widget widget--error", children: /* @__PURE__ */ l("span", { className: "widget__error-text", children: String(r.error) }) });
471
- const h = J(n);
472
- switch (a) {
443
+ if (a.error)
444
+ return /* @__PURE__ */ r("div", { className: "widget widget--error", children: /* @__PURE__ */ r("span", { className: "widget__error-text", children: String(a.error) }) });
445
+ const g = J(n);
446
+ switch (l) {
473
447
  case "kpi_card":
474
- return /* @__PURE__ */ l(ye, { data: r, label: t == null ? void 0 : t.label });
448
+ return /* @__PURE__ */ r(be, { data: a, label: t == null ? void 0 : t.label });
475
449
  case "gauge":
476
- return /* @__PURE__ */ l($e, { data: r, palette: h, label: t == null ? void 0 : t.label });
450
+ return /* @__PURE__ */ r(ve, { data: a, palette: g, label: t == null ? void 0 : t.label });
477
451
  case "chart":
478
- return /* @__PURE__ */ l(Se, { data: r, palette: h, label: t == null ? void 0 : t.label });
452
+ return /* @__PURE__ */ r(Ne, { data: a, palette: g, label: t == null ? void 0 : t.label });
479
453
  case "filter":
480
- return t && c ? /* @__PURE__ */ l(
481
- Re,
454
+ return t && c ? /* @__PURE__ */ r(
455
+ ke,
482
456
  {
483
457
  config: t,
484
458
  value: e || "",
@@ -488,19 +462,19 @@ function Oe({
488
462
  }
489
463
  ) : null;
490
464
  case "variable": {
491
- const g = t;
492
- return g && o ? /* @__PURE__ */ l(
493
- Pe,
465
+ const u = t;
466
+ return u && o ? /* @__PURE__ */ r(
467
+ xe,
494
468
  {
495
- config: g,
496
- value: p ?? g.variableValue ?? 0,
469
+ config: u,
470
+ value: m ?? u.variableValue ?? 0,
497
471
  onChange: o
498
472
  }
499
473
  ) : null;
500
474
  }
501
475
  case "color_palette":
502
- return t && d ? /* @__PURE__ */ l(
503
- Ae,
476
+ return t && d ? /* @__PURE__ */ r(
477
+ Te,
504
478
  {
505
479
  config: t,
506
480
  palette: n,
@@ -510,15 +484,15 @@ function Oe({
510
484
  default:
511
485
  return /* @__PURE__ */ _("div", { className: "widget", children: [
512
486
  "Widget: ",
513
- a
487
+ l
514
488
  ] });
515
489
  }
516
490
  }
517
- const Ee = 40, De = 6;
518
- function Ke({
519
- token: a,
520
- rowHeight: r = Ee,
521
- gridGap: n = De,
491
+ const Le = 2.5, Oe = 0.375;
492
+ function Pe({
493
+ token: l,
494
+ rowHeight: a = Le,
495
+ gridGap: n = Oe,
522
496
  className: t
523
497
  }) {
524
498
  const {
@@ -526,63 +500,63 @@ function Ke({
526
500
  renderData: i,
527
501
  loading: s,
528
502
  error: c,
529
- filters: p,
503
+ filters: m,
530
504
  variables: o,
531
505
  palette: d,
532
- setFilter: h,
533
- setVariable: g,
506
+ setFilter: g,
507
+ setVariable: u,
534
508
  setPalette: w
535
- } = be(a);
509
+ } = me(l);
536
510
  if (c && !e)
537
- return /* @__PURE__ */ l("div", { className: `preview-tab ${t ?? ""}`, children: /* @__PURE__ */ l("div", { className: "preview-tab__error", children: c }) });
511
+ return /* @__PURE__ */ r("div", { className: `preview-tab ${t ?? ""}`, children: /* @__PURE__ */ r("div", { className: "preview-tab__error", children: c }) });
538
512
  if (!e)
539
- return /* @__PURE__ */ l("div", { className: `preview-tab ${t ?? ""}`, children: /* @__PURE__ */ l("div", { className: "preview-tab__loading", children: "Carregando dashboard..." }) });
513
+ return /* @__PURE__ */ r("div", { className: `preview-tab ${t ?? ""}`, children: /* @__PURE__ */ r("div", { className: "preview-tab__loading", children: "Carregando dashboard..." }) });
540
514
  if (e.widgets.length === 0)
541
- return /* @__PURE__ */ l("div", { className: `preview-tab ${t ?? ""}`, children: /* @__PURE__ */ l("div", { className: "preview-tab__empty", children: "Este dashboard nao possui widgets." }) });
542
- const u = (i == null ? void 0 : i.widgets) ?? {}, m = (i == null ? void 0 : i.date_bounds) ?? null, $ = {
515
+ return /* @__PURE__ */ r("div", { className: `preview-tab ${t ?? ""}`, children: /* @__PURE__ */ r("div", { className: "preview-tab__empty", children: "Este dashboard nao possui widgets." }) });
516
+ const h = (i == null ? void 0 : i.widgets) ?? {}, p = (i == null ? void 0 : i.date_bounds) ?? null, k = {
543
517
  display: "grid",
544
518
  gridTemplateColumns: `repeat(${e.gridColumns}, 1fr)`,
545
- gridTemplateRows: `repeat(${e.gridRows}, ${r}px)`,
546
- gap: `${n}px`,
547
- ...Q(d)
519
+ gridTemplateRows: `repeat(${e.gridRows}, ${a}rem)`,
520
+ gap: `${n}rem`,
521
+ ...Z(d)
548
522
  };
549
523
  return /* @__PURE__ */ _("div", { className: `preview-tab ${t ?? ""}`, children: [
550
- c && !i && /* @__PURE__ */ l("div", { className: "preview-tab__error", children: c }),
551
- i && /* @__PURE__ */ l("div", { className: "preview-tab__grid", style: $, children: e.widgets.map((f) => {
552
- const C = Z.has(f.type), y = u[f.id], S = {
553
- gridColumn: `${f.grid.x + 1} / span ${f.grid.w}`,
554
- gridRow: `${f.grid.y + 1} / span ${f.grid.h}`
555
- }, v = f.type === "variable" ? o[f.id] ?? (y == null ? void 0 : y.value) ?? f.config.variableValue ?? 0 : void 0;
556
- return /* @__PURE__ */ l(
524
+ c && !i && /* @__PURE__ */ r("div", { className: "preview-tab__error", children: c }),
525
+ i && /* @__PURE__ */ r("div", { className: "preview-tab__grid", style: k, children: e.widgets.map((b) => {
526
+ const C = B.has(b.type), y = h[b.id], S = {
527
+ gridColumn: `${b.grid.x + 1} / span ${b.grid.w}`,
528
+ gridRow: `${b.grid.y + 1} / span ${b.grid.h}`
529
+ }, v = b.type === "variable" ? o[b.id] ?? (y == null ? void 0 : y.value) ?? b.config.variableValue ?? 0 : void 0;
530
+ return /* @__PURE__ */ r(
557
531
  "div",
558
532
  {
559
533
  className: `preview-tab__widget ${C ? "preview-tab__widget--control" : ""}`,
560
534
  style: S,
561
- children: C || y ? /* @__PURE__ */ l(
562
- Oe,
535
+ children: C || y ? /* @__PURE__ */ r(
536
+ Ie,
563
537
  {
564
- type: f.type,
538
+ type: b.type,
565
539
  computed: y || {},
566
540
  palette: d,
567
- config: f.config,
568
- filterValue: p[f.id] || "",
541
+ config: b.config,
542
+ filterValue: m[b.id] || "",
569
543
  filterOptions: (y == null ? void 0 : y.available_values) || [],
570
- dateBounds: m,
571
- onFilterChange: (b) => h(f.id, b),
544
+ dateBounds: p,
545
+ onFilterChange: (f) => g(b.id, f),
572
546
  variableValue: v,
573
- onVariableChange: (b) => g(f.id, b),
547
+ onVariableChange: (f) => u(b.id, f),
574
548
  onPaletteChange: w
575
549
  }
576
- ) : /* @__PURE__ */ l("div", { className: "preview-tab__widget-loading", children: s ? "Carregando..." : "Sem dados" })
550
+ ) : /* @__PURE__ */ r("div", { className: "preview-tab__widget-loading", children: s ? "Carregando..." : "Sem dados" })
577
551
  },
578
- f.id
552
+ b.id
579
553
  );
580
554
  }) }),
581
- s && i && /* @__PURE__ */ l("div", { className: "preview-tab__recalculating", children: "Atualizando..." })
555
+ s && i && /* @__PURE__ */ r("div", { className: "preview-tab__recalculating", children: "Atualizando..." })
582
556
  ] });
583
557
  }
584
558
  export {
585
- pe as ApiError,
586
- Ke as Dashboard
559
+ Ke as ApiError,
560
+ Pe as Dashboard
587
561
  };
588
562
  //# sourceMappingURL=index.js.map