@tenorlab/react-dashboard 1.6.6 → 1.6.7
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/core.es.js +77 -77
- package/package.json +2 -2
package/dist/core.es.js
CHANGED
|
@@ -85,53 +85,53 @@ const W = [
|
|
|
85
85
|
* @returns the update item
|
|
86
86
|
*/
|
|
87
87
|
incrementOrDecrementValue: (e, t) => {
|
|
88
|
-
const i = e.value.match(/([\d.]+)/),
|
|
88
|
+
const i = e.value.match(/([\d.]+)/), s = i ? parseFloat(i[1]) : 0, r = e.value.match(/([^\d.]+)/), n = r ? r[1] : e.defaultUnit, a = S(n, e.step) * t, l = `${Math.max(s + a, e.minValue).toFixed(1)}${n}`;
|
|
89
89
|
return {
|
|
90
90
|
...e,
|
|
91
91
|
value: l
|
|
92
92
|
};
|
|
93
93
|
}
|
|
94
|
-
}, y = (e, t) => `dashboards_${t}_${e}`, v = async (e, t, i,
|
|
94
|
+
}, y = (e, t) => `dashboards_${t}_${e}`, v = async (e, t, i, s) => {
|
|
95
95
|
const r = localStorage.getItem(y(e, t));
|
|
96
96
|
if (r)
|
|
97
97
|
try {
|
|
98
98
|
const n = JSON.parse(r);
|
|
99
|
-
return n.length < 1 ? [
|
|
100
|
-
|
|
101
|
-
const l = (
|
|
102
|
-
(o) =>
|
|
99
|
+
return n.length < 1 ? [s] : (n.forEach((a) => {
|
|
100
|
+
a.dashboardId || (a.dashboardId = "default"), a.dashboardName || (a.dashboardName = `Dashboard ${a.dashboardId}`), a.responsiveGrid = a.responsiveGrid ?? !1, (a.widgets || []).length < 1 && (a.widgets = []);
|
|
101
|
+
const l = (a.cssSettings || []).filter(
|
|
102
|
+
(o) => s.cssSettings.some((d) => d.key === o.key)
|
|
103
103
|
);
|
|
104
104
|
if (l.length < 1)
|
|
105
|
-
|
|
105
|
+
a.cssSettings = [...s.cssSettings];
|
|
106
106
|
else {
|
|
107
107
|
l.forEach((d) => {
|
|
108
108
|
d.value = (d.value || "").replace(/NaN/g, "");
|
|
109
|
-
const c =
|
|
109
|
+
const c = s.cssSettings.find((g) => g.key === d.key);
|
|
110
110
|
c && (Object.keys(c).forEach((g) => {
|
|
111
111
|
g in d || (d[g] = c[g]);
|
|
112
112
|
}), d.step = c.step, d.minValue = c.minValue, d.defaultValue = c.defaultValue, d.defaultUnit = c.defaultUnit, /\d+/g.test(d.value) === !1 && (d.value = c ? c.value : "1.0rem"));
|
|
113
113
|
});
|
|
114
|
-
const o =
|
|
115
|
-
|
|
114
|
+
const o = s.cssSettings.filter((d) => !l.some((c) => c.key === d.key));
|
|
115
|
+
a.cssSettings = [...l, ...o];
|
|
116
116
|
}
|
|
117
|
-
|
|
117
|
+
a.widgets = a.widgets.filter(
|
|
118
118
|
(o) => o.includes("WidgetContainer") || i.has(o)
|
|
119
|
-
),
|
|
119
|
+
), a.childWidgetsConfig = a.childWidgetsConfig.filter(
|
|
120
120
|
(o) => i.has(o.widgetKey)
|
|
121
|
-
),
|
|
121
|
+
), a.zoomScale ? a.zoomScale < 0.7 && (a.zoomScale = 0.7) : a.zoomScale = 1;
|
|
122
122
|
}), n);
|
|
123
123
|
} catch (n) {
|
|
124
124
|
console.warn("Error parsing saved dashboard config:", n);
|
|
125
125
|
}
|
|
126
|
-
return [
|
|
127
|
-
}, $ = async (e, t, i,
|
|
126
|
+
return [s];
|
|
127
|
+
}, $ = async (e, t, i, s) => {
|
|
128
128
|
i.forEach((n) => {
|
|
129
129
|
if (n.userID = e, n.clientAppKey = t, n.responsiveGrid = n.responsiveGrid ?? !1, typeof n != "object")
|
|
130
130
|
throw new Error("Invalid dashboard configuration");
|
|
131
131
|
n.widgets = n.widgets.filter(
|
|
132
|
-
(
|
|
132
|
+
(a) => a.includes("WidgetContainer") || s.has(a)
|
|
133
133
|
), n.childWidgetsConfig = n.childWidgetsConfig.filter(
|
|
134
|
-
(
|
|
134
|
+
(a) => s.has(a.widgetKey)
|
|
135
135
|
), n.zoomScale ? n.zoomScale < 0.7 && (n.zoomScale = 0.7) : n.zoomScale = 1;
|
|
136
136
|
});
|
|
137
137
|
const r = JSON.stringify(i);
|
|
@@ -156,60 +156,60 @@ const W = [
|
|
|
156
156
|
let t = Number(e || 0);
|
|
157
157
|
return t < p && (t = p), t > h && (t = h), t;
|
|
158
158
|
}, L = (e, t) => {
|
|
159
|
-
let i = Number(Number((V * t).toFixed(2)).toFixed(2)),
|
|
160
|
-
return K(
|
|
159
|
+
let i = Number(Number((V * t).toFixed(2)).toFixed(2)), s = Number((Number(e) + i).toFixed(2));
|
|
160
|
+
return K(s);
|
|
161
161
|
}, j = (e) => {
|
|
162
162
|
let t = {
|
|
163
163
|
...e
|
|
164
164
|
};
|
|
165
165
|
return t.widgets = t.widgets.filter((i) => {
|
|
166
166
|
if (`${i}`.includes("WidgetContainer")) {
|
|
167
|
-
const
|
|
167
|
+
const s = t.childWidgetsConfig.filter(
|
|
168
168
|
(r) => r.parentWidgetKey === i
|
|
169
169
|
);
|
|
170
|
-
if (!
|
|
170
|
+
if (!s || s.length === 0)
|
|
171
171
|
return t.widgets = t.widgets.filter((r) => r !== i), !1;
|
|
172
172
|
}
|
|
173
173
|
return !0;
|
|
174
174
|
}), t;
|
|
175
175
|
}, x = (e) => {
|
|
176
|
-
const t = e.widgets.filter((
|
|
177
|
-
return t.forEach((
|
|
178
|
-
const n = `${
|
|
179
|
-
i[
|
|
180
|
-
}), e.widgets = e.widgets.map((
|
|
181
|
-
const r =
|
|
176
|
+
const t = e.widgets.filter((s) => s.includes("WidgetContainer")), i = {};
|
|
177
|
+
return t.forEach((s, r) => {
|
|
178
|
+
const n = `${s.split("_container")[0]}_container${r + 1}`;
|
|
179
|
+
i[s] = n;
|
|
180
|
+
}), e.widgets = e.widgets.map((s) => i[s] || s), e.childWidgetsConfig = e.childWidgetsConfig.map((s) => {
|
|
181
|
+
const r = s.parentWidgetKey, n = i[r];
|
|
182
182
|
return {
|
|
183
|
-
...
|
|
183
|
+
...s,
|
|
184
184
|
// If a new key exists, use it. If not, keep the original key.
|
|
185
185
|
parentWidgetKey: n || r
|
|
186
186
|
};
|
|
187
187
|
}), e;
|
|
188
188
|
}, m = (e, t) => {
|
|
189
|
-
const i = `${e}`.includes("Container"),
|
|
189
|
+
const i = `${e}`.includes("Container"), s = i ? ["Container"] : ["Widget"], r = t?.name || e, n = t?.description || (i ? "Container" : "Unknown");
|
|
190
190
|
return {
|
|
191
191
|
name: r,
|
|
192
192
|
description: n,
|
|
193
|
-
categories:
|
|
193
|
+
categories: s,
|
|
194
194
|
noDuplicatedWidgets: !0,
|
|
195
195
|
icon: void 0,
|
|
196
196
|
externalDependencies: []
|
|
197
197
|
};
|
|
198
198
|
}, M = (e, t, i) => t[e] || m(e, i), I = (e, t) => t.get(e)?.meta || m(e), k = (e, t, i) => {
|
|
199
|
-
const
|
|
199
|
+
const s = i || m(e);
|
|
200
200
|
return [
|
|
201
201
|
e,
|
|
202
202
|
{
|
|
203
203
|
key: e,
|
|
204
|
-
title:
|
|
204
|
+
title: s.name,
|
|
205
205
|
isContainer: `${e}`.includes("Container"),
|
|
206
206
|
isRemote: !1,
|
|
207
|
-
meta:
|
|
207
|
+
meta: s,
|
|
208
208
|
component: t
|
|
209
209
|
}
|
|
210
210
|
];
|
|
211
|
-
}, C = (e, t, i,
|
|
212
|
-
const r =
|
|
211
|
+
}, C = (e, t, i, s) => {
|
|
212
|
+
const r = s || m(e);
|
|
213
213
|
return [
|
|
214
214
|
e,
|
|
215
215
|
{
|
|
@@ -224,7 +224,7 @@ const W = [
|
|
|
224
224
|
}, F = (e) => {
|
|
225
225
|
const t = e.match(/\/widget-([a-zA-Z0-9-]+)\/index\.ts$/);
|
|
226
226
|
if (t && t[1]) {
|
|
227
|
-
const i = t[1],
|
|
227
|
+
const i = t[1], s = i.split("-"), r = `Widget${s.map((a) => a.charAt(0).toUpperCase() + a.slice(1)).join("")}`, n = s.map((a) => a.charAt(0).toUpperCase() + a.slice(1)).join(" ");
|
|
228
228
|
return {
|
|
229
229
|
key: r,
|
|
230
230
|
name: n,
|
|
@@ -232,33 +232,33 @@ const W = [
|
|
|
232
232
|
};
|
|
233
233
|
}
|
|
234
234
|
return null;
|
|
235
|
-
}, N = (e, t, i,
|
|
235
|
+
}, N = (e, t, i, s) => {
|
|
236
236
|
const r = `${t}/widget-${i}/meta.ts`, n = e[r];
|
|
237
237
|
if (!n)
|
|
238
238
|
return;
|
|
239
|
-
const
|
|
240
|
-
return n[
|
|
239
|
+
const a = `${s}Meta`;
|
|
240
|
+
return n[a] || void 0;
|
|
241
241
|
}, A = async (e) => new Promise(async (t, i) => {
|
|
242
|
-
const
|
|
242
|
+
const s = [];
|
|
243
243
|
try {
|
|
244
244
|
const r = await (await fetch(`${e}?${Math.random()}`)).json();
|
|
245
245
|
for (const n in r) {
|
|
246
|
-
const
|
|
246
|
+
const a = r[n], l = () => import(
|
|
247
247
|
/* @vite-ignore */
|
|
248
|
-
|
|
248
|
+
a.url
|
|
249
249
|
), o = {
|
|
250
|
-
name:
|
|
251
|
-
description:
|
|
252
|
-
categories:
|
|
253
|
-
noDuplicatedWidgets:
|
|
250
|
+
name: a.meta?.name || "Unknown",
|
|
251
|
+
description: a.meta?.description || "Remote Plugin",
|
|
252
|
+
categories: a.meta?.categories || ["Widget"],
|
|
253
|
+
noDuplicatedWidgets: a.meta?.noDuplicatedWidgets ?? !0,
|
|
254
254
|
icon: void 0,
|
|
255
255
|
// Or a logic to map a string name to a Lucide component
|
|
256
|
-
externalDependencies:
|
|
256
|
+
externalDependencies: a.meta?.externalDependencies || []
|
|
257
257
|
};
|
|
258
|
-
|
|
258
|
+
s.push(C(n, l, !0, o));
|
|
259
259
|
}
|
|
260
260
|
t({
|
|
261
|
-
entries:
|
|
261
|
+
entries: s,
|
|
262
262
|
message: "",
|
|
263
263
|
details: ""
|
|
264
264
|
});
|
|
@@ -269,22 +269,22 @@ const W = [
|
|
|
269
269
|
details: typeof r == "object" ? JSON.stringify(r) : r
|
|
270
270
|
});
|
|
271
271
|
}
|
|
272
|
-
}), R = (e, t, i,
|
|
272
|
+
}), R = (e, t, i, s = !0) => {
|
|
273
273
|
const r = [];
|
|
274
274
|
for (const n in t) {
|
|
275
|
-
const
|
|
276
|
-
if (l &&
|
|
275
|
+
const a = t[n], l = F(n);
|
|
276
|
+
if (l && a) {
|
|
277
277
|
const { key: o, name: d, folder: c } = l;
|
|
278
278
|
let g = N(i, e, c, o);
|
|
279
279
|
if (g || (g = m(o, {
|
|
280
280
|
name: d,
|
|
281
|
-
description: `Local ${
|
|
282
|
-
})),
|
|
281
|
+
description: `Local ${s ? "dynamic" : "static"} widget`
|
|
282
|
+
})), s)
|
|
283
283
|
r.push(
|
|
284
|
-
C(o,
|
|
284
|
+
C(o, a, !1, g)
|
|
285
285
|
);
|
|
286
286
|
else {
|
|
287
|
-
const f =
|
|
287
|
+
const f = a.default || a;
|
|
288
288
|
r.push(k(o, f, g));
|
|
289
289
|
}
|
|
290
290
|
}
|
|
@@ -322,10 +322,10 @@ const W = [
|
|
|
322
322
|
* @returns A {@link TCoreResponse} containing the success status and updated config.
|
|
323
323
|
*/
|
|
324
324
|
addWidget: (e) => {
|
|
325
|
-
const { dashboardConfig: t, widgetKey: i, parentWidgetKey:
|
|
326
|
-
if (
|
|
325
|
+
const { dashboardConfig: t, widgetKey: i, parentWidgetKey: s, noDuplicatedWidgets: r } = e;
|
|
326
|
+
if (s) {
|
|
327
327
|
if (r && t.childWidgetsConfig.find(
|
|
328
|
-
(
|
|
328
|
+
(a) => a.parentWidgetKey === s && a.widgetKey === i
|
|
329
329
|
))
|
|
330
330
|
return {
|
|
331
331
|
success: !1,
|
|
@@ -334,7 +334,7 @@ const W = [
|
|
|
334
334
|
};
|
|
335
335
|
const n = [
|
|
336
336
|
...t.childWidgetsConfig,
|
|
337
|
-
{ parentWidgetKey:
|
|
337
|
+
{ parentWidgetKey: s, widgetKey: i }
|
|
338
338
|
// new entry
|
|
339
339
|
];
|
|
340
340
|
return {
|
|
@@ -370,31 +370,31 @@ const W = [
|
|
|
370
370
|
* @returns {TCoreResponse<TRemoveWidgetResponse>} The response indicating success or failure and the updated dashboard configuration
|
|
371
371
|
*/
|
|
372
372
|
removeWidget: (e, t, i) => {
|
|
373
|
-
const
|
|
373
|
+
const s = `${t || ""}`.trim().toLowerCase(), r = `${i || ""}`.trim().toLowerCase();
|
|
374
374
|
if (r.length > 0) {
|
|
375
375
|
const n = e.childWidgetsConfig.filter(
|
|
376
376
|
(d) => `${d.parentWidgetKey}`.trim().toLowerCase() !== r
|
|
377
|
-
),
|
|
378
|
-
(d) => `${d.parentWidgetKey}`.trim().toLowerCase() === r && `${d.widgetKey}`.trim().toLowerCase() !==
|
|
379
|
-
), l = [...n, ...
|
|
377
|
+
), a = e.childWidgetsConfig.filter(
|
|
378
|
+
(d) => `${d.parentWidgetKey}`.trim().toLowerCase() === r && `${d.widgetKey}`.trim().toLowerCase() !== s
|
|
379
|
+
), l = [...n, ...a];
|
|
380
380
|
let o = {
|
|
381
381
|
...e,
|
|
382
382
|
childWidgetsConfig: l
|
|
383
383
|
};
|
|
384
|
-
return
|
|
384
|
+
return s.includes("container") && (o = x(o)), {
|
|
385
385
|
success: !0,
|
|
386
386
|
updatedDashboardConfig: o
|
|
387
387
|
};
|
|
388
388
|
} else {
|
|
389
|
-
const n = (e.widgets || []).filter((l) => `${l}`.trim().toLowerCase() !==
|
|
390
|
-
(l) => `${l.parentWidgetKey}`.trim().toLowerCase() !==
|
|
389
|
+
const n = (e.widgets || []).filter((l) => `${l}`.trim().toLowerCase() !== s), a = e.childWidgetsConfig.filter(
|
|
390
|
+
(l) => `${l.parentWidgetKey}`.trim().toLowerCase() !== s
|
|
391
391
|
);
|
|
392
392
|
return {
|
|
393
393
|
success: !0,
|
|
394
394
|
updatedDashboardConfig: {
|
|
395
395
|
...e,
|
|
396
396
|
widgets: n,
|
|
397
|
-
childWidgetsConfig:
|
|
397
|
+
childWidgetsConfig: a
|
|
398
398
|
}
|
|
399
399
|
};
|
|
400
400
|
}
|
|
@@ -407,10 +407,10 @@ const W = [
|
|
|
407
407
|
* @param parentWidgetKey - The container key if the widget is nested.
|
|
408
408
|
* @returns A {@link TCoreResponse} with the new array order.
|
|
409
409
|
*/
|
|
410
|
-
moveWidget: (e, t, i,
|
|
411
|
-
const r = `${i || ""}`.trim().toLowerCase(), n = `${
|
|
410
|
+
moveWidget: (e, t, i, s) => {
|
|
411
|
+
const r = `${i || ""}`.trim().toLowerCase(), n = `${s || ""}`.trim().toLowerCase();
|
|
412
412
|
if (n.length > 0) {
|
|
413
|
-
const
|
|
413
|
+
const a = e.childWidgetsConfig.filter(
|
|
414
414
|
(u) => `${u.parentWidgetKey}`.trim().toLowerCase() !== n
|
|
415
415
|
);
|
|
416
416
|
let l = e.childWidgetsConfig.filter(
|
|
@@ -431,19 +431,19 @@ const W = [
|
|
|
431
431
|
success: !0,
|
|
432
432
|
updatedDashboardConfig: {
|
|
433
433
|
...e,
|
|
434
|
-
childWidgetsConfig: [...
|
|
434
|
+
childWidgetsConfig: [...a, ...g]
|
|
435
435
|
}
|
|
436
436
|
};
|
|
437
437
|
} else {
|
|
438
|
-
const
|
|
438
|
+
const a = e.widgets || [], l = a.map((g) => `${g}`.trim().toLowerCase()).indexOf(r);
|
|
439
439
|
let o = l + t;
|
|
440
|
-
if (o = Math.max(0, o), o = Math.min(
|
|
440
|
+
if (o = Math.max(0, o), o = Math.min(a.length - 1, o), o === l)
|
|
441
441
|
return {
|
|
442
442
|
success: !1,
|
|
443
443
|
message: `DashboardStore: moveWidget: Widget already at min/max position (${i})`,
|
|
444
444
|
updatedDashboardConfig: e
|
|
445
445
|
};
|
|
446
|
-
const d = [...
|
|
446
|
+
const d = [...a], [c] = d.splice(l, 1);
|
|
447
447
|
return d.splice(o, 0, c), {
|
|
448
448
|
success: !0,
|
|
449
449
|
updatedDashboardConfig: {
|
|
@@ -457,8 +457,8 @@ const W = [
|
|
|
457
457
|
if (typeof window > "u") return "#FFFFFF";
|
|
458
458
|
const i = document.createElement("div");
|
|
459
459
|
Array.isArray(e) ? e.forEach((r) => i.classList.add(r)) : e.split(" ").forEach((r) => i.classList.add(r)), i.style.display = "none", document.body.appendChild(i);
|
|
460
|
-
const
|
|
461
|
-
return document.body.removeChild(i),
|
|
460
|
+
const s = window.getComputedStyle(i)[t];
|
|
461
|
+
return document.body.removeChild(i), s;
|
|
462
462
|
}, G = {
|
|
463
463
|
/**
|
|
464
464
|
* @name getCssVariableValue
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tenorlab/react-dashboard",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.7",
|
|
4
4
|
"description": "Foundation components for creating user-configurable dashboards in React",
|
|
5
5
|
"author": "Damiano Fusco",
|
|
6
6
|
"license": "MIT",
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"zustand": "5.0.9"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@tenorlab/dashboard-core": "^1.6.
|
|
58
|
+
"@tenorlab/dashboard-core": "^1.6.5",
|
|
59
59
|
"@types/node": "^24.10.1",
|
|
60
60
|
"@types/react": "19.2.3",
|
|
61
61
|
"@types/react-dom": "19.2.3",
|