@rotorjs/react 0.9.0 → 0.10.1
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/Dashboard.d.ts +2 -2
- package/dist/DashboardContext.d.ts +1 -1
- package/dist/main.js +92 -113
- package/package.json +4 -4
package/dist/Dashboard.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { DashboardAction, DashboardEventTarget, DashboardFact, DashboardLayoutNo
|
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
3
|
import { DashboardLayoutMap, DashboardTileMap } from './DashboardContext';
|
|
4
4
|
export type DashboardProps = {
|
|
5
|
-
|
|
5
|
+
target: DashboardEventTarget;
|
|
6
6
|
initialVars?: {
|
|
7
7
|
[name: string]: DashboardVar;
|
|
8
8
|
};
|
|
@@ -20,4 +20,4 @@ export type DashboardProps = {
|
|
|
20
20
|
};
|
|
21
21
|
children?: ReactNode;
|
|
22
22
|
};
|
|
23
|
-
export declare function Dashboard({
|
|
23
|
+
export declare function Dashboard({ target, initialVars, initialFacts, layouts, defaultLayout, tiles, layout, content, onAction, allowedNavigateOrigins: rawAllowedNavigateOrigins, children, }: DashboardProps): import("react").JSX.Element;
|
|
@@ -3,7 +3,7 @@ import { ComponentType, PropsWithChildren } from 'react';
|
|
|
3
3
|
export type DashboardLayoutMap = Record<string, ComponentType<PropsWithChildren<DashboardLayoutNode>>>;
|
|
4
4
|
export type DashboardTileMap = Record<string, ComponentType<DashboardTileNode>>;
|
|
5
5
|
export type DashboardContextValue = {
|
|
6
|
-
|
|
6
|
+
target: DashboardEventTarget;
|
|
7
7
|
vars: {
|
|
8
8
|
[name: string]: DashboardVar;
|
|
9
9
|
};
|
package/dist/main.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import { createContext as
|
|
4
|
-
import {
|
|
5
|
-
import { Fragment as u, jsx as d, jsxs as f } from "react/jsx-runtime";
|
|
6
|
-
import { DashboardStateConsumer as p, NumberFormatter as m } from "@rotorjs/dashboard";
|
|
1
|
+
import { DashboardEnvironment as e, DashboardStateConsumer as t, NumberFormatter as n, dashboardLocaleFact as r } from "@rotorjs/dashboard";
|
|
2
|
+
import i from "fast-deep-equal";
|
|
3
|
+
import { createContext as a, createElement as o, useCallback as s, useContext as c, useEffect as l, useMemo as u, useState as d } from "react";
|
|
4
|
+
import { Fragment as f, jsx as p, jsxs as m } from "react/jsx-runtime";
|
|
7
5
|
//#region lib/DashboardContext.ts
|
|
8
|
-
var h =
|
|
6
|
+
var h = a(void 0);
|
|
9
7
|
//#endregion
|
|
10
8
|
//#region lib/DashboardError.tsx
|
|
11
9
|
function g({ error: e }) {
|
|
@@ -13,7 +11,7 @@ function g({ error: e }) {
|
|
|
13
11
|
}
|
|
14
12
|
//#endregion
|
|
15
13
|
//#region lib/DashboardLayoutContext.ts
|
|
16
|
-
var _ =
|
|
14
|
+
var _ = a(void 0);
|
|
17
15
|
//#endregion
|
|
18
16
|
//#region lib/getNodeKey.ts
|
|
19
17
|
function v(e, t = 0) {
|
|
@@ -23,126 +21,108 @@ function v(e, t = 0) {
|
|
|
23
21
|
//#region lib/DashboardLayoutError.tsx
|
|
24
22
|
var y = { type: "error" };
|
|
25
23
|
function b({ id: e, error: t, children: n }) {
|
|
26
|
-
let { layouts:
|
|
24
|
+
let { layouts: r } = c(h), i = r.error ?? g, a = {
|
|
27
25
|
type: "error",
|
|
28
26
|
id: e,
|
|
29
27
|
error: t
|
|
30
28
|
};
|
|
31
|
-
return /* @__PURE__ */
|
|
29
|
+
return /* @__PURE__ */ p(_.Provider, {
|
|
32
30
|
value: y,
|
|
33
|
-
children: /* @__PURE__ */
|
|
34
|
-
...
|
|
35
|
-
key: v(
|
|
31
|
+
children: /* @__PURE__ */ o(i, {
|
|
32
|
+
...a,
|
|
33
|
+
key: v(a)
|
|
36
34
|
}, n)
|
|
37
35
|
});
|
|
38
36
|
}
|
|
39
37
|
//#endregion
|
|
40
38
|
//#region lib/DashboardLayout.tsx
|
|
41
39
|
function x({ layout: e, children: t }) {
|
|
42
|
-
let { layouts: n, defaultLayout:
|
|
40
|
+
let { layouts: n, defaultLayout: r } = c(h), i = u(() => ({
|
|
43
41
|
error: g,
|
|
44
42
|
...n
|
|
45
|
-
}), [n]),
|
|
46
|
-
if (!
|
|
47
|
-
let
|
|
48
|
-
return
|
|
49
|
-
value:
|
|
50
|
-
children: /* @__PURE__ */
|
|
51
|
-
...
|
|
52
|
-
key: v(
|
|
43
|
+
}), [n]), a = e ?? r, s = a?.type, l = u(() => ({ type: s }), [s]);
|
|
44
|
+
if (!a?.type) return null;
|
|
45
|
+
let d = i[a.type];
|
|
46
|
+
return d ? /* @__PURE__ */ p(_.Provider, {
|
|
47
|
+
value: l,
|
|
48
|
+
children: /* @__PURE__ */ o(d, {
|
|
49
|
+
...a,
|
|
50
|
+
key: v(a)
|
|
53
51
|
}, t)
|
|
54
|
-
}) : /* @__PURE__ */
|
|
55
|
-
error: `Invalid layout type "${
|
|
52
|
+
}) : /* @__PURE__ */ p(b, {
|
|
53
|
+
error: `Invalid layout type "${a.type}"`,
|
|
56
54
|
children: t
|
|
57
55
|
});
|
|
58
56
|
}
|
|
59
57
|
//#endregion
|
|
60
58
|
//#region lib/DashboardTileError.tsx
|
|
61
59
|
function S({ id: e, error: t }) {
|
|
62
|
-
let { tiles: n } =
|
|
60
|
+
let { tiles: n } = c(h), r = n.error ?? g, i = {
|
|
63
61
|
type: "error",
|
|
64
62
|
id: e,
|
|
65
63
|
error: t
|
|
66
64
|
};
|
|
67
|
-
return /* @__PURE__ */ r
|
|
68
|
-
...
|
|
69
|
-
key: v(
|
|
65
|
+
return /* @__PURE__ */ o(r, {
|
|
66
|
+
...i,
|
|
67
|
+
key: v(i)
|
|
70
68
|
});
|
|
71
69
|
}
|
|
72
70
|
//#endregion
|
|
73
71
|
//#region lib/DashboardTiles.tsx
|
|
74
72
|
function C({ content: e }) {
|
|
75
|
-
let { tiles: t } =
|
|
73
|
+
let { tiles: t } = c(h), n = u(() => ({
|
|
76
74
|
error: g,
|
|
77
75
|
...t
|
|
78
76
|
}), [t]);
|
|
79
|
-
return /* @__PURE__ */
|
|
77
|
+
return /* @__PURE__ */ p(f, { children: e.map((e, t) => {
|
|
80
78
|
if (!e?.type) return null;
|
|
81
|
-
let
|
|
82
|
-
return
|
|
79
|
+
let r = n[e.type];
|
|
80
|
+
return r ? /* @__PURE__ */ o(r, {
|
|
83
81
|
...e,
|
|
84
82
|
key: v(e, t)
|
|
85
|
-
}) : /* @__PURE__ */
|
|
83
|
+
}) : /* @__PURE__ */ p(S, { error: `Invalid tile type "${e.type}"` }, v({ type: "error" }, t));
|
|
86
84
|
}) });
|
|
87
85
|
}
|
|
88
86
|
//#endregion
|
|
89
87
|
//#region lib/Dashboard.tsx
|
|
90
88
|
var w = { [window.location.origin]: !0 };
|
|
91
|
-
function T({
|
|
92
|
-
let [b] =
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
89
|
+
function T({ target: t, initialVars: n, initialFacts: r, layouts: a, defaultLayout: o, tiles: s, layout: c, content: f, onAction: g, allowedNavigateOrigins: _ = w, children: v }) {
|
|
90
|
+
let [y, b] = d(_), [S, T] = d(n ?? {}), [E, D] = d(r ?? {});
|
|
91
|
+
i(y, _) || b(_), l(() => {
|
|
92
|
+
let n = new e(t, {
|
|
93
|
+
vars: S,
|
|
94
|
+
facts: E
|
|
95
|
+
});
|
|
96
|
+
return n.addEventListener("var", (e) => {
|
|
97
|
+
T((t) => {
|
|
98
|
+
let n = t[e.name], r = {
|
|
99
|
+
value: e.value,
|
|
100
|
+
exposed: e.exposed
|
|
101
|
+
};
|
|
102
|
+
return Object.hasOwn(t, e.name) && i(n, r) ? t : {
|
|
103
|
+
...t,
|
|
104
|
+
[e.name]: r
|
|
105
|
+
};
|
|
100
106
|
});
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
+
}), n.addEventListener("fact", (e) => {
|
|
108
|
+
D((t) => {
|
|
109
|
+
let n = t[e.name], r = { value: e.value };
|
|
110
|
+
return Object.hasOwn(t, e.name) && i(n, r) ? t : {
|
|
111
|
+
...t,
|
|
112
|
+
[e.name]: r
|
|
113
|
+
};
|
|
107
114
|
});
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
n
|
|
113
|
-
|
|
114
|
-
T
|
|
115
|
-
]), o(() => {
|
|
116
|
-
let e = new AbortController(), t = e.signal;
|
|
117
|
-
return n.addEventListener("action", (e) => {
|
|
115
|
+
}), () => {
|
|
116
|
+
n.stop();
|
|
117
|
+
};
|
|
118
|
+
}, [t]), l(() => {
|
|
119
|
+
let e = new AbortController(), n = e.signal;
|
|
120
|
+
return t.addEventListener("action", (e) => {
|
|
118
121
|
let t = e.action;
|
|
119
|
-
if (e.
|
|
120
|
-
case "var":
|
|
121
|
-
k((e) => {
|
|
122
|
-
let n = e[t.name];
|
|
123
|
-
return Object.hasOwn(e, t.name) && n.value === t.value && n.exposed === (t.exposed ?? !1) ? e : {
|
|
124
|
-
...e,
|
|
125
|
-
[t.name]: {
|
|
126
|
-
value: t.value,
|
|
127
|
-
exposed: t.exposed ?? !1
|
|
128
|
-
}
|
|
129
|
-
};
|
|
130
|
-
});
|
|
131
|
-
break;
|
|
132
|
-
case "fact":
|
|
133
|
-
j((e) => {
|
|
134
|
-
let n = e[t.name];
|
|
135
|
-
return Object.hasOwn(e, t.name) && n.value === t.value ? e : {
|
|
136
|
-
...e,
|
|
137
|
-
[t.name]: { value: t.value }
|
|
138
|
-
};
|
|
139
|
-
});
|
|
140
|
-
break;
|
|
141
|
-
}
|
|
142
|
-
if (!_?.(e.action)) switch (t.type) {
|
|
122
|
+
if (!g?.(e.action)) switch (t.type) {
|
|
143
123
|
case "navigate": {
|
|
144
124
|
let e = new URL(t.href, window.location.href).origin;
|
|
145
|
-
if (!
|
|
125
|
+
if (!y["*"] && (!Object.hasOwn(y, e) || !y[e])) {
|
|
146
126
|
console.warn(`Dashboard navigation blocked: origin "${e}" is not allowed`);
|
|
147
127
|
break;
|
|
148
128
|
}
|
|
@@ -150,43 +130,42 @@ function T({ engine: n, initialVars: r, initialFacts: i, layouts: a, defaultLayo
|
|
|
150
130
|
break;
|
|
151
131
|
}
|
|
152
132
|
}
|
|
153
|
-
}, { signal:
|
|
133
|
+
}, { signal: n }), () => {
|
|
154
134
|
e.abort();
|
|
155
135
|
};
|
|
156
136
|
}, [
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
E
|
|
137
|
+
t,
|
|
138
|
+
g,
|
|
139
|
+
y
|
|
161
140
|
]);
|
|
162
|
-
let
|
|
163
|
-
|
|
164
|
-
vars:
|
|
165
|
-
facts:
|
|
141
|
+
let O = u(() => ({
|
|
142
|
+
target: t,
|
|
143
|
+
vars: S,
|
|
144
|
+
facts: E,
|
|
166
145
|
layouts: a,
|
|
167
|
-
defaultLayout:
|
|
168
|
-
tiles:
|
|
146
|
+
defaultLayout: o,
|
|
147
|
+
tiles: s
|
|
169
148
|
}), [
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
149
|
+
t,
|
|
150
|
+
S,
|
|
151
|
+
E,
|
|
173
152
|
a,
|
|
174
|
-
|
|
175
|
-
|
|
153
|
+
o,
|
|
154
|
+
s
|
|
176
155
|
]);
|
|
177
|
-
return /* @__PURE__ */
|
|
178
|
-
value:
|
|
179
|
-
children: /* @__PURE__ */
|
|
180
|
-
layout:
|
|
181
|
-
children: [/* @__PURE__ */
|
|
156
|
+
return /* @__PURE__ */ p(h.Provider, {
|
|
157
|
+
value: O,
|
|
158
|
+
children: /* @__PURE__ */ m(x, {
|
|
159
|
+
layout: c,
|
|
160
|
+
children: [/* @__PURE__ */ p(C, { content: f }), v]
|
|
182
161
|
})
|
|
183
162
|
});
|
|
184
163
|
}
|
|
185
164
|
//#endregion
|
|
186
165
|
//#region lib/DashboardTileContainer.tsx
|
|
187
166
|
function E({ layout: e, children: t }) {
|
|
188
|
-
let { tileContainer: n } =
|
|
189
|
-
return n ? /* @__PURE__ */
|
|
167
|
+
let { tileContainer: n } = c(_);
|
|
168
|
+
return n ? /* @__PURE__ */ p(n, {
|
|
190
169
|
layout: e,
|
|
191
170
|
children: t
|
|
192
171
|
}) : t({});
|
|
@@ -194,21 +173,21 @@ function E({ layout: e, children: t }) {
|
|
|
194
173
|
//#endregion
|
|
195
174
|
//#region lib/useDashboardState.ts
|
|
196
175
|
function D(e, n = []) {
|
|
197
|
-
let {
|
|
198
|
-
return
|
|
199
|
-
let e = new
|
|
200
|
-
u((
|
|
176
|
+
let { target: r } = c(h), [a, o] = d(e), [s, u] = d(n);
|
|
177
|
+
return i(a, e) || o(e), l(() => {
|
|
178
|
+
let e = new t(r, a, (e) => {
|
|
179
|
+
u((t) => i(e, t) ? t : e);
|
|
201
180
|
});
|
|
202
181
|
return () => {
|
|
203
182
|
e.stop();
|
|
204
183
|
};
|
|
205
|
-
}, [r,
|
|
184
|
+
}, [r, a]), s;
|
|
206
185
|
}
|
|
207
186
|
//#endregion
|
|
208
187
|
//#region lib/useNumberFormatter.ts
|
|
209
188
|
function O(e) {
|
|
210
|
-
let {
|
|
211
|
-
return
|
|
189
|
+
let { facts: t } = c(h), i = t[r]?.value, a = e?.locale || (typeof i == "string" && i ? i : void 0), o = u(() => new n({ locale: a }), [a]);
|
|
190
|
+
return s((e, t) => o.format(e, t), [o]);
|
|
212
191
|
}
|
|
213
192
|
//#endregion
|
|
214
193
|
export { T as Dashboard, h as DashboardContext, g as DashboardError, x as DashboardLayout, _ as DashboardLayoutContext, b as DashboardLayoutError, E as DashboardTileContainer, S as DashboardTileError, C as DashboardTiles, v as getNodeKey, D as useDashboardState, O as useNumberFormatter };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rotorjs/react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.1",
|
|
4
4
|
"description": "Rotor",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Aaron Burmeister"
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@eslint/js": "^10.0.1",
|
|
47
|
-
"@rotorjs/dashboard": "^0.
|
|
47
|
+
"@rotorjs/dashboard": "^0.5.2",
|
|
48
48
|
"@types/react": "^19.2.17",
|
|
49
49
|
"@types/react-dom": "^19.1.9",
|
|
50
50
|
"@vitejs/plugin-react": "^6.0.2",
|
|
@@ -65,11 +65,11 @@
|
|
|
65
65
|
"vite": "^8.0.16"
|
|
66
66
|
},
|
|
67
67
|
"peerDependencies": {
|
|
68
|
-
"@rotorjs/dashboard": "^0.
|
|
68
|
+
"@rotorjs/dashboard": "^0.5.0",
|
|
69
69
|
"react": "^19.0.0"
|
|
70
70
|
},
|
|
71
71
|
"dependencies": {
|
|
72
|
-
"@rotorjs/state": "^0.
|
|
72
|
+
"@rotorjs/state": "^0.7.0",
|
|
73
73
|
"fast-deep-equal": "^3.1.3",
|
|
74
74
|
"uuid": "^14.0.0"
|
|
75
75
|
}
|