@rotorjs/react 0.5.0 → 0.7.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,4 +1,4 @@
1
- import { DashboardEventTarget, DashboardFact, DashboardLayoutNode, DashboardTileNode, DashboardVar } from '@rotorjs/dashboards';
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/dashboards';
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>>;
@@ -1,2 +1,2 @@
1
- import { ErrorDashboardNode } from '@rotorjs/dashboards';
1
+ import { ErrorDashboardNode } from '@rotorjs/dashboard';
2
2
  export declare function DashboardError({ error }: ErrorDashboardNode): void;
@@ -1,4 +1,4 @@
1
- import { DashboardLayoutNode } from '@rotorjs/dashboards';
1
+ import { DashboardLayoutNode } from '@rotorjs/dashboard';
2
2
  import { ReactNode } from 'react';
3
3
  export type DashboardLayoutProps = {
4
4
  layout?: DashboardLayoutNode;
@@ -1,6 +1,10 @@
1
- import { DashboardLayoutConfig } from '@rotorjs/dashboards';
2
- import { PropsWithChildren } from 'react';
3
- export type DashboardTileContainerProps = PropsWithChildren<{
1
+ import { DashboardLayoutConfig } from '@rotorjs/dashboard';
2
+ import { CSSProperties, ReactNode } from 'react';
3
+ export type DashboardTileContainerProps = {
4
4
  layout?: DashboardLayoutConfig;
5
- }>;
6
- export declare function DashboardTileContainer({ layout, children, }: DashboardTileContainerProps): string | number | bigint | boolean | Iterable<import('react').ReactNode> | Promise<string | number | bigint | boolean | import('react').ReactPortal | import('react').ReactElement<unknown, string | import('react').JSXElementConstructor<any>> | Iterable<import('react').ReactNode> | null | undefined> | import("react/jsx-runtime").JSX.Element | null | undefined;
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;
@@ -1,4 +1,4 @@
1
- import { DashboardTileNode } from '@rotorjs/dashboards';
1
+ import { DashboardTileNode } from '@rotorjs/dashboard';
2
2
  export type DashboardTilesProps = {
3
3
  content: DashboardTileNode[];
4
4
  };
@@ -0,0 +1,2 @@
1
+ import { DashboardNode } from '@rotorjs/dashboard';
2
+ export declare function getNodeKey(node: DashboardNode, index?: number): string;
package/dist/main.d.ts CHANGED
@@ -7,5 +7,5 @@ export * from './DashboardLayoutError';
7
7
  export * from './DashboardTileContainer';
8
8
  export * from './DashboardTileError';
9
9
  export * from './DashboardTiles';
10
- export * from './getKey';
10
+ export * from './getNodeKey';
11
11
  export * from './useDashboardState';
package/dist/main.js CHANGED
@@ -1,116 +1,124 @@
1
- import { ActionEvent as e } from "@rotorjs/core";
2
- import { createContext as t, createElement as n, useContext as r, useEffect as i, useMemo as a, useState as o } from "react";
3
- import { v7 as s } from "uuid";
4
- import { Fragment as c, jsx as l, jsxs as u } from "react/jsx-runtime";
5
- import d from "fast-deep-equal";
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 f = t(void 0);
8
+ var p = n(void 0);
8
9
  //#endregion
9
10
  //#region lib/DashboardError.tsx
10
- function p({ error: e }) {
11
+ function m({ error: e }) {
11
12
  throw e;
12
13
  }
13
14
  //#endregion
14
15
  //#region lib/DashboardLayoutContext.ts
15
- var m = t(void 0);
16
+ var h = n(void 0);
16
17
  //#endregion
17
- //#region lib/getKey.ts
18
- function h(e, t = 0) {
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 g = { type: "error" };
24
- function _({ id: e, error: t, children: i }) {
25
- let { layouts: a } = r(f), o = a.error ?? p, s = {
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__ */ l(m.Provider, {
31
- value: g,
32
- children: /* @__PURE__ */ n(o, {
31
+ return /* @__PURE__ */ u(h.Provider, {
32
+ value: _,
33
+ children: /* @__PURE__ */ r(o, {
33
34
  ...s,
34
- key: h(s)
35
- }, i)
35
+ key: g(s)
36
+ }, n)
36
37
  });
37
38
  }
38
39
  //#endregion
39
40
  //#region lib/DashboardLayout.tsx
40
- function v({ layout: e, children: t }) {
41
- let { layouts: i, defaultLayout: o } = r(f), s = a(() => ({
42
- error: p,
43
- ...i
44
- }), [i]), c = e ?? o, u = c?.type, d = a(() => ({ type: u }), [u]);
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 g = s[c.type];
47
- return g ? /* @__PURE__ */ l(m.Provider, {
47
+ let f = s[c.type];
48
+ return f ? /* @__PURE__ */ u(h.Provider, {
48
49
  value: d,
49
- children: /* @__PURE__ */ n(g, {
50
+ children: /* @__PURE__ */ r(f, {
50
51
  ...c,
51
- key: h(c)
52
+ key: g(c)
52
53
  }, t)
53
- }) : /* @__PURE__ */ l(_, {
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 y({ id: e, error: t }) {
61
- let { tiles: i } = r(f), a = i.error ?? p, o = {
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__ */ n(a, {
67
+ return /* @__PURE__ */ r(a, {
67
68
  ...o,
68
- key: h(o)
69
+ key: g(o)
69
70
  });
70
71
  }
71
72
  //#endregion
72
73
  //#region lib/DashboardTiles.tsx
73
- function b({ content: e }) {
74
- let { tiles: t } = r(f), i = a(() => ({
75
- error: p,
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(c, { children: e.map((e, t) => {
79
+ return /* @__PURE__ */ u(l, { children: e.map((e, t) => {
79
80
  if (!e?.type) return null;
80
- let r = i[e.type];
81
- return r ? /* @__PURE__ */ n(r, {
81
+ let i = n[e.type];
82
+ return i ? /* @__PURE__ */ r(i, {
82
83
  ...e,
83
- key: h(e, t)
84
- }) : /* @__PURE__ */ l(y, { error: `Invalid tile type "${e.type}"` }, h({ type: "error" }, t));
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
- function x({ engine: t, initialVars: n, initialFacts: r, layouts: c, defaultLayout: d, tiles: p, layout: m, content: h, children: g }) {
90
- let [_] = o(n ?? {}), [y, x] = o(_), [S] = o(r ?? {}), [C, w] = o(S);
91
- i(() => {
92
- let n = s(), r = new AbortController(), i = r.signal;
93
- return Object.entries(_).forEach(([r, { value: i, exposed: a }]) => {
94
- let o = new e({
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: r,
97
- value: i,
98
- exposed: a
97
+ name: t,
98
+ value: r,
99
+ exposed: i
99
100
  });
100
- o.emitter = n, t.dispatchEvent(o);
101
- }), Object.entries(S).forEach(([r, { value: i }]) => {
102
- let a = new e({
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: r,
105
- value: i
105
+ name: t,
106
+ value: r
106
107
  });
107
- a.emitter = n, t.dispatchEvent(a);
108
- }), t.addEventListener("action", (e) => {
109
- if (e.emitter === n) return;
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
- x((e) => {
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,67 +128,81 @@ function x({ engine: t, initialVars: n, initialFacts: r, layouts: c, defaultLayo
120
128
  }
121
129
  };
122
130
  });
123
- return;
124
- case "fact": w((e) => {
125
- let n = e[t.name];
126
- return Object.hasOwn(e, t.name) && n.value === t.value ? e : {
127
- ...e,
128
- [t.name]: { value: t.value }
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: i }), () => {
133
- r.abort();
153
+ }, { signal: t }), () => {
154
+ e.abort();
134
155
  };
135
156
  }, [
136
- t,
157
+ C,
158
+ n,
137
159
  _,
138
- S
160
+ E
139
161
  ]);
140
- let T = a(() => ({
141
- engine: t,
142
- vars: y,
143
- facts: C,
144
- layouts: c,
145
- defaultLayout: d,
146
- tiles: p
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
- t,
149
- y,
150
- C,
151
- c,
152
- d,
153
- p
170
+ n,
171
+ O,
172
+ A,
173
+ l,
174
+ f,
175
+ m
154
176
  ]);
155
- return /* @__PURE__ */ l(f.Provider, {
156
- value: T,
157
- children: /* @__PURE__ */ u(v, {
158
- layout: m,
159
- children: [/* @__PURE__ */ l(b, { content: h }), g]
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
164
186
  //#region lib/DashboardTileContainer.tsx
165
- function S({ layout: e, children: t }) {
166
- let { tileContainer: n } = r(m);
167
- return n ? /* @__PURE__ */ l(n, {
187
+ function w({ layout: e, children: t }) {
188
+ let { tileContainer: n } = i(h);
189
+ return n ? /* @__PURE__ */ u(n, {
168
190
  layout: e,
169
191
  children: t
170
- }) : t;
192
+ }) : t({});
171
193
  }
172
194
  //#endregion
173
195
  //#region lib/useDashboardState.ts
174
- function C(e, t = []) {
175
- let { engine: n } = r(f), [a, c] = o(e), [l, u] = o(t);
176
- return d(e, a) || c(a), i(() => {
177
- let e = s(), t = new AbortController(), r = t.signal;
178
- return n.addEventListener("state", (t) => {
179
- t.id === e && u(t.state);
180
- }, { signal: r }), n.registerReducer(e, a), () => {
181
- t.abort(), n.removeReducer(e);
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();
182
204
  };
183
- }, [a, n]), l;
205
+ }, [r, o]), l;
184
206
  }
185
207
  //#endregion
186
- export { x as Dashboard, f as DashboardContext, p as DashboardError, v as DashboardLayout, m as DashboardLayoutContext, _ as DashboardLayoutError, S as DashboardTileContainer, y as DashboardTileError, b as DashboardTiles, h as getKey, C as useDashboardState };
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 { DashboardReducerInit, DashboardState } from '@rotorjs/dashboards';
2
- export declare function useDashboardState(init: DashboardReducerInit, initialState?: DashboardState): DashboardState;
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.5.0",
3
+ "version": "0.7.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/dashboards": "^0.13.3",
47
+ "@rotorjs/dashboard": "^0.1.0",
48
48
  "@types/react": "^19.1.12",
49
49
  "@types/react-dom": "^19.1.9",
50
- "@vitejs/plugin-react": "^6.0.1",
51
- "eslint": "^10.3.0",
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.3",
64
- "unplugin-dts": "^1.0.0",
63
+ "typescript-eslint": "^8.59.4",
64
+ "unplugin-dts": "^1.0.1",
65
65
  "vite": "^8.0.13"
66
66
  },
67
67
  "peerDependencies": {
68
- "@rotorjs/dashboards": "^0.13.0",
68
+ "@rotorjs/dashboard": "^0.1.0",
69
69
  "react": "^19.0.0"
70
70
  },
71
71
  "dependencies": {
72
- "@rotorjs/core": "^0.5.3",
72
+ "@rotorjs/state": "^0.3.0",
73
73
  "fast-deep-equal": "^3.1.3",
74
74
  "uuid": "^14.0.0"
75
75
  }
package/dist/getKey.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import { DashboardNode } from '@rotorjs/dashboards';
2
- export declare function getKey(node: DashboardNode, index?: number): string;