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