@actionexec/dashboards 0.6.0 → 0.8.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.
@@ -1,665 +0,0 @@
1
- import { jsx as i, jsxs as w } from "react/jsx-runtime";
2
- import H from "react-datepicker";
3
- import { useState as x, useRef as P, useMemo as O, useLayoutEffect as J, useEffect as V } from "react";
4
- import { createPortal as q } from "react-dom";
5
- const K = "https://action-data-api-7mbrztperq-rj.a.run.app", B = "/external/dashboards";
6
- let C = K;
7
- function ge(e) {
8
- C = e.replace(/\/$/, "");
9
- }
10
- class Q extends Error {
11
- constructor(t, a, r) {
12
- super(t), this.status = a, this.payload = r, this.name = "ApiError";
13
- }
14
- }
15
- async function R(e, t, a) {
16
- const r = new URL(`${C}${B}${e}`);
17
- if (a)
18
- for (const [o, l] of Object.entries(a)) r.searchParams.set(o, l);
19
- const s = await fetch(r.toString(), {
20
- headers: { Authorization: `Bearer ${t}` }
21
- });
22
- if (!s.ok) {
23
- let o;
24
- try {
25
- o = await s.json();
26
- } catch {
27
- }
28
- throw new Q(
29
- `Requisicao falhou (${s.status}) em ${e}`,
30
- s.status,
31
- o
32
- );
33
- }
34
- return await s.json();
35
- }
36
- const pe = (e) => R("/layout", e), me = (e, t) => R("/render", e, t), m = {
37
- series0: 0,
38
- series1: 1,
39
- series2: 2,
40
- series3: 3,
41
- series4: 4,
42
- bgDark: 5,
43
- bgPaper: 6,
44
- bgElevated: 7,
45
- textPrimary: 8,
46
- textMuted: 9,
47
- accent: 10,
48
- success: 11,
49
- error: 12
50
- }, X = 5, N = 13, Z = {
51
- series0: "Série 1",
52
- series1: "Série 2",
53
- series2: "Série 3",
54
- series3: "Série 4",
55
- series4: "Série 5",
56
- bgDark: "Fundo Escuro",
57
- bgPaper: "Fundo Cartão",
58
- bgElevated: "Fundo Elevado",
59
- textPrimary: "Texto Primário",
60
- textMuted: "Texto Secundário",
61
- accent: "Destaque",
62
- success: "Sucesso",
63
- error: "Erro"
64
- }, v = {
65
- action: {
66
- label: "Action",
67
- colors: [
68
- "#ff6b00",
69
- "#a3e635",
70
- "#e3f544",
71
- "#65ffd1",
72
- "#ff0404",
73
- "#1a1a1a",
74
- "#262626",
75
- "#333333",
76
- "#f5f5f5",
77
- "#999999",
78
- "#ff6b00",
79
- "#a3e635",
80
- "#ef4444"
81
- ]
82
- },
83
- westCoast: {
84
- label: "West Coast",
85
- colors: [
86
- "#a3b86c",
87
- "#c89b3c",
88
- "#8b6f47",
89
- "#6b8e23",
90
- "#d2691e",
91
- "#1f1a14",
92
- "#2a241b",
93
- "#3a3225",
94
- "#e8dcc4",
95
- "#a89878",
96
- "#c89b3c",
97
- "#a3b86c",
98
- "#c44536"
99
- ]
100
- },
101
- mono: {
102
- label: "Monocromático",
103
- colors: [
104
- "#f8fafc",
105
- "#cbd5e1",
106
- "#94a3b8",
107
- "#64748b",
108
- "#475569",
109
- "#0a0a0a",
110
- "#171717",
111
- "#262626",
112
- "#fafafa",
113
- "#a3a3a3",
114
- "#e5e5e5",
115
- "#cbd5e1",
116
- "#ef4444"
117
- ]
118
- },
119
- ocean: {
120
- label: "Ocean",
121
- colors: [
122
- "#0ea5e9",
123
- "#06b6d4",
124
- "#0891b2",
125
- "#3b82f6",
126
- "#22d3ee",
127
- "#0a1929",
128
- "#0f2740",
129
- "#173554",
130
- "#e0f2fe",
131
- "#7dd3fc",
132
- "#22d3ee",
133
- "#10b981",
134
- "#f43f5e"
135
- ]
136
- },
137
- princess: {
138
- label: "Cute Pink",
139
- colors: [
140
- "#ff79bc",
141
- "#a855f7",
142
- "#f472b6",
143
- "#d946ef",
144
- "#fb7185",
145
- "#fff0f6",
146
- "#ffe4ec",
147
- "#ffffff",
148
- "#ff4099",
149
- "#ffadd5",
150
- "#ec4899",
151
- "#10b981",
152
- "#e11d48"
153
- ]
154
- }
155
- }, $ = v.action.colors;
156
- function D(e) {
157
- const t = $;
158
- if (!e || e.length === 0) return [...t];
159
- if (e.length >= N) return e.slice(0, N);
160
- const a = [...e];
161
- for (let r = e.length; r < N; r++) a.push(t[r]);
162
- return a;
163
- }
164
- function ee(e) {
165
- return D(e).slice(0, X);
166
- }
167
- function he(e) {
168
- const t = D(e);
169
- return {
170
- "--bg-dark": t[m.bgDark],
171
- "--bg-paper": t[m.bgPaper],
172
- "--bg-elevated": t[m.bgElevated],
173
- "--text-primary": t[m.textPrimary],
174
- "--text-secondary": t[m.textMuted],
175
- "--text-muted": t[m.textMuted],
176
- "--action-orange": t[m.accent],
177
- "--action-green": t[m.success],
178
- "--color-success": t[m.success],
179
- "--color-error": t[m.error],
180
- "--color-info": t[m.series2],
181
- "--color-warning": t[m.series3]
182
- };
183
- }
184
- const te = $, ae = 30, re = 10, be = {
185
- gridColumns: ae,
186
- gridRows: re,
187
- widgets: []
188
- }, _e = {
189
- kpi_card: "KPI Card",
190
- gauge: "Gauge",
191
- chart: "Gráfico",
192
- table: "Tabela",
193
- filter: "Filtro",
194
- variable: "Variável",
195
- color_palette: "Paleta de Cores"
196
- }, we = ["kpi_card", "gauge", "chart", "table"], Te = ["filter", "variable", "color_palette"], Se = /* @__PURE__ */ new Set(["filter", "variable", "color_palette"]), Ee = {
197
- sum: "Soma",
198
- avg: "Média",
199
- count: "Contagem",
200
- min: "Mínimo",
201
- max: "Máximo",
202
- count_distinct: "Contagem Distinta"
203
- }, se = {
204
- currency: "Moeda (R$)",
205
- number: "Número",
206
- integer: "Inteiro",
207
- percentage: "Porcentagem",
208
- date: "Data",
209
- text: "Texto"
210
- }, ye = Object.entries(se).filter(([e]) => e !== "date" && e !== "text"), De = {
211
- yoy: "vs Ano Anterior",
212
- mom: "vs Mês Anterior",
213
- target: "vs Meta",
214
- none: "Nenhuma"
215
- }, Ne = {
216
- bar: "Barras",
217
- line: "Linhas",
218
- area: "Área",
219
- pie: "Pizza"
220
- }, ve = {
221
- date_range: "Periodo",
222
- select: "Seleção Única",
223
- multi_select: "Seleção Múltipla"
224
- }, k = "", Le = {
225
- kpi_card: { x: 0, y: 0, w: 6, h: 3 },
226
- gauge: { x: 0, y: 0, w: 6, h: 5 },
227
- chart: { x: 0, y: 0, w: 6, h: 6 },
228
- table: { x: 0, y: 0, w: 12, h: 7 },
229
- filter: { x: 0, y: 0, w: 4, h: 2 },
230
- variable: { x: 0, y: 0, w: 4, h: 2 },
231
- color_palette: { x: 0, y: 0, w: 4, h: 2 }
232
- }, xe = {
233
- kpi_card: { label: "Novo KPI", aggregation: "sum", format: "number" },
234
- gauge: { label: "Novo Gauge", aggregation: "sum" },
235
- chart: { label: "Novo Grafico", chartType: "bar", xAxis: { column: "", granularity: "day" }, series: [] },
236
- table: { label: "Nova Tabela", columns: [] },
237
- filter: { label: "Novo Filtro", filterType: "select" },
238
- variable: { label: "Nova Variavel", variableValue: 0, variableFormat: "number", locked: !1 },
239
- color_palette: { label: "Paleta de Cores", paletteColors: te, locked: !1 }
240
- }, Me = [
241
- "Jan",
242
- "Fev",
243
- "Mar",
244
- "Abr",
245
- "Mai",
246
- "Jun",
247
- "Jul",
248
- "Ago",
249
- "Set",
250
- "Out",
251
- "Nov",
252
- "Dez"
253
- ], Ae = [
254
- "Janeiro",
255
- "Fevereiro",
256
- "Marco",
257
- "Abril",
258
- "Maio",
259
- "Junho",
260
- "Julho",
261
- "Agosto",
262
- "Setembro",
263
- "Outubro",
264
- "Novembro",
265
- "Dezembro"
266
- ];
267
- function Pe(e) {
268
- return { start: `${e}-01-01`, end: `${e}-12-31` };
269
- }
270
- function Oe(e) {
271
- if (!e) return null;
272
- const t = e.match(/^(\d{4})/);
273
- return t ? { year: parseInt(t[1]) } : null;
274
- }
275
- function ke(e, t) {
276
- const a = new Date(e, t, 0).getDate(), r = (s) => String(s).padStart(2, "0");
277
- return {
278
- start: `${e}-${r(t)}-01`,
279
- end: `${e}-${r(t)}-${r(a)}`
280
- };
281
- }
282
- function F(e) {
283
- const t = new Date(Date.UTC(e.getFullYear(), e.getMonth(), e.getDate()));
284
- t.setUTCDate(t.getUTCDate() + 4 - (t.getUTCDay() || 7));
285
- const a = new Date(Date.UTC(t.getUTCFullYear(), 0, 1));
286
- return Math.ceil(((t.getTime() - a.getTime()) / 864e5 + 1) / 7);
287
- }
288
- function Ce(e, t) {
289
- const a = new Date(e, 0, 4), r = (a.getDay() + 6) % 7, s = new Date(a.getTime() - r * 864e5), o = new Date(s.getTime() + (t - 1) * 7 * 864e5), l = new Date(o.getTime() + 6 * 864e5), d = (h) => String(h).padStart(2, "0"), f = (h) => `${h.getFullYear()}-${d(h.getMonth() + 1)}-${d(h.getDate())}`;
290
- return { start: f(o), end: f(l) };
291
- }
292
- function Re(e, t) {
293
- const a = /* @__PURE__ */ new Set(), r = new Date(e, t, 0).getDate();
294
- for (let s = 1; s <= r; s++)
295
- a.add(F(new Date(e, t - 1, s)));
296
- return Array.from(a).sort((s, o) => s - o);
297
- }
298
- function $e(e, t) {
299
- const a = new Date(e, t, 0).getDate(), r = (d) => String(d).padStart(2, "0"), s = [];
300
- let o = 1, l = 1;
301
- for (; o <= a; ) {
302
- const d = o, f = Math.min(o + 6, a), h = `${e}-${r(t)}-${r(d)}`, c = `${e}-${r(t)}-${r(f)}`, u = `${l}° Semana (${r(d)}/${r(t)} - ${r(f)}/${r(t)})`;
303
- s.push({ index: l, startDay: d, endDay: f, start: h, end: c, label: u }), o = f + 1, l++;
304
- }
305
- return s;
306
- }
307
- function Fe(e, t, a) {
308
- if (!e) return 1;
309
- const r = (l) => String(l).padStart(2, "0"), s = e.match(new RegExp(`^${t}-${r(a)}-(\\d{2})`));
310
- if (!s) return 1;
311
- const o = parseInt(s[1]);
312
- return Math.ceil(o / 7);
313
- }
314
- function Ie(e) {
315
- if (!e) return null;
316
- const t = e.match(/^(\d{4})-(\d{2})/);
317
- return t ? { year: parseInt(t[1]), month: parseInt(t[2]) } : null;
318
- }
319
- function Ue(e) {
320
- if (!e) return null;
321
- const t = /* @__PURE__ */ new Date(e + "T00:00:00");
322
- return isNaN(t.getTime()) ? null : { year: t.getFullYear(), week: F(t) };
323
- }
324
- function Ye(e) {
325
- const t = /* @__PURE__ */ new Date(), a = e != null && e.min ? parseInt(e.min.slice(0, 4)) : t.getFullYear() - 2, r = e != null && e.max ? parseInt(e.max.slice(0, 4)) : t.getFullYear(), s = [];
326
- for (let o = r; o >= a; o--) s.push(o);
327
- return s;
328
- }
329
- function y(e) {
330
- if (!e) return null;
331
- const [t, a, r] = e.split("-").map(Number);
332
- return !t || !a || !r ? null : new Date(t, a - 1, r);
333
- }
334
- function ne(e) {
335
- if (!e) return "";
336
- const t = e.getFullYear(), a = String(e.getMonth() + 1).padStart(2, "0"), r = String(e.getDate()).padStart(2, "0");
337
- return `${t}-${a}-${r}`;
338
- }
339
- function Ge({
340
- value: e,
341
- onChange: t,
342
- minIso: a,
343
- maxIso: r,
344
- placeholder: s,
345
- selectsStart: o,
346
- selectsEnd: l,
347
- startIso: d,
348
- endIso: f,
349
- className: h,
350
- disabled: c
351
- }) {
352
- return /* @__PURE__ */ i("div", { className: `ddp-field ${h ?? ""}`, children: /* @__PURE__ */ i(
353
- H,
354
- {
355
- selected: y(e),
356
- onChange: (u) => t(ne(u)),
357
- selectsStart: o,
358
- selectsEnd: l,
359
- startDate: y(d) ?? void 0,
360
- endDate: y(f) ?? void 0,
361
- minDate: y(a) ?? void 0,
362
- maxDate: y(r) ?? void 0,
363
- dateFormat: "dd/MM/yyyy",
364
- placeholderText: s ?? "Selecione...",
365
- disabled: c,
366
- portalId: "ddp-portal",
367
- popperPlacement: "bottom-start",
368
- popperModifiers: [
369
- {
370
- name: "flip",
371
- options: { fallbackPlacements: ["bottom-end", "top-start", "top-end"] },
372
- fn: (u) => u
373
- }
374
- ]
375
- }
376
- ) });
377
- }
378
- function We({ options: e, value: t, multi: a, onChange: r }) {
379
- const [s, o] = x(!1), [l, d] = x(""), [f, h] = x(null), c = P(null), u = P(null), g = O(
380
- () => t ? t.split(k).filter(Boolean) : [],
381
- [t]
382
- ), b = O(() => {
383
- const n = l.trim().toLowerCase();
384
- return n ? e.filter((p) => p.toLowerCase().includes(n)) : e;
385
- }, [e, l]), T = () => {
386
- const n = c.current;
387
- if (!n) return;
388
- const p = n.getBoundingClientRect(), _ = 4, S = window.innerHeight - p.bottom - _, E = p.top - _, A = S < 200 && E > S, z = Math.max(150, Math.min(360, A ? E : S));
389
- h({
390
- left: p.left,
391
- width: p.width,
392
- maxHeight: z,
393
- ...A ? { bottom: window.innerHeight - p.top + _ } : { top: p.bottom + _ }
394
- });
395
- };
396
- J(() => {
397
- if (!s) return;
398
- T();
399
- const n = () => T();
400
- return window.addEventListener("scroll", n, !0), window.addEventListener("resize", n), () => {
401
- window.removeEventListener("scroll", n, !0), window.removeEventListener("resize", n);
402
- };
403
- }, [s]), V(() => {
404
- if (!s) return;
405
- const n = (p) => {
406
- var S, E;
407
- const _ = p.target;
408
- (S = c.current) != null && S.contains(_) || (E = u.current) != null && E.contains(_) || o(!1);
409
- };
410
- return document.addEventListener("mousedown", n), () => document.removeEventListener("mousedown", n);
411
- }, [s]);
412
- const I = () => {
413
- o(!1), d("");
414
- }, L = (n) => {
415
- var p;
416
- r(n), d(""), o(!1), (p = c.current) == null || p.blur();
417
- }, M = (n) => {
418
- const p = g.includes(n) ? g.filter((_) => _ !== n) : [...g, n];
419
- r(p.join(k));
420
- }, U = () => {
421
- o(!0), a || d("");
422
- }, Y = (n) => {
423
- var p;
424
- n.key === "Escape" ? (I(), (p = c.current) == null || p.blur()) : n.key === "Enter" && b.length > 0 && (n.preventDefault(), a ? (M(b[0]), d("")) : L(b[0]));
425
- }, G = a || s ? l : t || "", W = a && g.length > 0 ? `${g.length} selecionado(s)` : s ? "Buscar..." : "Todos", j = s && f ? q(
426
- /* @__PURE__ */ i(
427
- "div",
428
- {
429
- ref: u,
430
- className: "widget-filter__search-panel",
431
- style: {
432
- position: "fixed",
433
- left: f.left,
434
- width: f.width,
435
- top: f.top,
436
- bottom: f.bottom,
437
- maxHeight: f.maxHeight
438
- },
439
- children: /* @__PURE__ */ w("div", { className: "widget-filter__search-list", children: [
440
- a && g.length > 0 && /* @__PURE__ */ i(
441
- "button",
442
- {
443
- type: "button",
444
- className: "widget-filter__search-clear",
445
- onClick: () => r(""),
446
- children: "Limpar seleção"
447
- }
448
- ),
449
- !a && /* @__PURE__ */ w(
450
- "button",
451
- {
452
- type: "button",
453
- className: `widget-filter__search-option${t ? "" : " is-selected"}`,
454
- onClick: () => L(""),
455
- children: [
456
- /* @__PURE__ */ i("span", { className: "widget-filter__search-check", "aria-hidden": !0, children: t ? "" : "✓" }),
457
- "Todos"
458
- ]
459
- }
460
- ),
461
- b.length === 0 ? /* @__PURE__ */ i("span", { className: "widget-filter__search-empty", children: "Nenhuma opção" }) : b.map(
462
- (n) => a ? /* @__PURE__ */ w(
463
- "label",
464
- {
465
- className: `widget-filter__search-option${g.includes(n) ? " is-selected" : ""}`,
466
- children: [
467
- /* @__PURE__ */ i(
468
- "input",
469
- {
470
- type: "checkbox",
471
- checked: g.includes(n),
472
- onChange: () => M(n)
473
- }
474
- ),
475
- n
476
- ]
477
- },
478
- n
479
- ) : /* @__PURE__ */ w(
480
- "button",
481
- {
482
- type: "button",
483
- className: `widget-filter__search-option${t === n ? " is-selected" : ""}`,
484
- onClick: () => L(n),
485
- children: [
486
- /* @__PURE__ */ i("span", { className: "widget-filter__search-check", "aria-hidden": !0, children: t === n ? "✓" : "" }),
487
- n
488
- ]
489
- },
490
- n
491
- )
492
- )
493
- ] })
494
- }
495
- ),
496
- document.body
497
- ) : null;
498
- return /* @__PURE__ */ w("div", { className: "widget-filter__search", children: [
499
- /* @__PURE__ */ i(
500
- "input",
501
- {
502
- ref: c,
503
- type: "text",
504
- className: "widget-filter__search-field",
505
- value: G,
506
- placeholder: W,
507
- onFocus: U,
508
- onClick: () => o(!0),
509
- onChange: (n) => {
510
- d(n.target.value), o(!0);
511
- },
512
- onKeyDown: Y
513
- }
514
- ),
515
- j
516
- ] });
517
- }
518
- const oe = [
519
- m.bgDark,
520
- m.bgPaper,
521
- m.bgElevated,
522
- m.accent,
523
- m.success
524
- ];
525
- function ce(e) {
526
- if (!e) return !0;
527
- const t = D(e);
528
- return Object.values(v).some(
529
- (a) => JSON.stringify(a.colors) === JSON.stringify(t)
530
- );
531
- }
532
- const le = [
533
- { label: "Series", slots: ["series0", "series1", "series2", "series3", "series4"] },
534
- { label: "Tema", slots: ["bgDark", "bgPaper", "bgElevated", "textPrimary", "textMuted"] },
535
- { label: "Estados", slots: ["accent", "success", "error"] }
536
- ];
537
- function je({
538
- selected: e,
539
- onSelect: t,
540
- customMode: a,
541
- onCustomModeChange: r,
542
- disabled: s
543
- }) {
544
- var h;
545
- const o = a ?? !ce(e), l = D(e), d = o || (h = Object.entries(v).find(
546
- ([, c]) => JSON.stringify(c.colors) === JSON.stringify(l)
547
- )) == null ? void 0 : h[0], f = (c, u) => {
548
- const g = [...l];
549
- for (; g.length < N; ) g.push("#000000");
550
- g[c] = u, t(g);
551
- };
552
- return /* @__PURE__ */ w("div", { className: `palette-selector ${s ? "palette-selector--disabled" : ""}`, children: [
553
- r && /* @__PURE__ */ w("label", { className: "config-panel__checkbox", children: [
554
- /* @__PURE__ */ i(
555
- "input",
556
- {
557
- type: "checkbox",
558
- checked: o,
559
- onChange: (c) => r(c.target.checked),
560
- disabled: s
561
- }
562
- ),
563
- "Customizar"
564
- ] }),
565
- o ? /* @__PURE__ */ i("div", { className: "palette-selector__custom", children: le.map((c) => /* @__PURE__ */ w("div", { className: "palette-selector__row", children: [
566
- /* @__PURE__ */ i("span", { className: "palette-selector__row-label", children: c.label }),
567
- /* @__PURE__ */ i("div", { className: "palette-selector__row-slots", children: c.slots.map((u) => {
568
- const g = m[u];
569
- return /* @__PURE__ */ i(
570
- "input",
571
- {
572
- type: "color",
573
- className: "palette-selector__color-input",
574
- value: l[g] || "#000000",
575
- onChange: (b) => f(g, b.target.value),
576
- disabled: s,
577
- title: Z[u]
578
- },
579
- u
580
- );
581
- }) })
582
- ] }, c.label)) }) : /* @__PURE__ */ i("div", { className: "palette-selector__options", children: Object.entries(v).map(([c, u]) => {
583
- const g = D(u.colors);
584
- return /* @__PURE__ */ w(
585
- "button",
586
- {
587
- className: `palette-selector__option ${d === c ? "palette-selector__option--active" : ""}`,
588
- onClick: () => t(u.colors),
589
- disabled: s,
590
- children: [
591
- /* @__PURE__ */ i("div", { className: "palette-selector__bar", children: ee(u.colors).map((b, T) => /* @__PURE__ */ i(
592
- "span",
593
- {
594
- className: "palette-selector__swatch",
595
- style: { backgroundColor: b }
596
- },
597
- T
598
- )) }),
599
- /* @__PURE__ */ i("div", { className: "palette-selector__bar palette-selector__bar--theme", children: oe.map((b, T) => /* @__PURE__ */ i(
600
- "span",
601
- {
602
- className: "palette-selector__swatch",
603
- style: { backgroundColor: g[b] }
604
- },
605
- T
606
- )) }),
607
- /* @__PURE__ */ i("span", { className: "palette-selector__label", children: u.label })
608
- ]
609
- },
610
- c
611
- );
612
- }) })
613
- ] });
614
- }
615
- export {
616
- Ee as A,
617
- Re as B,
618
- Ne as C,
619
- we as D,
620
- be as E,
621
- ve as F,
622
- Ye as G,
623
- y as H,
624
- Ie as I,
625
- Fe as J,
626
- Ue as K,
627
- Oe as L,
628
- Ae as M,
629
- ye as N,
630
- ge as O,
631
- v as P,
632
- pe as Q,
633
- me as R,
634
- X as S,
635
- N as T,
636
- Q as U,
637
- _e as W,
638
- De as a,
639
- Se as b,
640
- Te as c,
641
- je as d,
642
- xe as e,
643
- Le as f,
644
- ae as g,
645
- re as h,
646
- te as i,
647
- $ as j,
648
- Ge as k,
649
- se as l,
650
- Me as m,
651
- k as n,
652
- m as o,
653
- Z as p,
654
- We as q,
655
- ne as r,
656
- D as s,
657
- Pe as t,
658
- F as u,
659
- ke as v,
660
- $e as w,
661
- he as x,
662
- ee as y,
663
- Ce as z
664
- };
665
- //# sourceMappingURL=ColorPaletteSelector-Bsda66uL.js.map