@rotorjs/react 0.8.0 → 0.10.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.
@@ -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
- engine: DashboardEventTarget;
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({ engine, initialVars: rawInitialVars, initialFacts: rawInitialFacts, layouts, defaultLayout, tiles, layout, content, onAction, allowedNavigateOrigins: rawAllowedNavigateOrigins, children, }: DashboardProps): import("react/jsx-runtime").JSX.Element;
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
- engine: DashboardEventTarget;
6
+ target: DashboardEventTarget;
7
7
  vars: {
8
8
  [name: string]: DashboardVar;
9
9
  };
@@ -4,4 +4,4 @@ export type DashboardLayoutProps = {
4
4
  layout?: DashboardLayoutNode;
5
5
  children: ReactNode;
6
6
  };
7
- export declare function DashboardLayout({ layout, children }: DashboardLayoutProps): import("react/jsx-runtime").JSX.Element | null;
7
+ export declare function DashboardLayout({ layout, children }: DashboardLayoutProps): import("react").JSX.Element | null;
@@ -3,4 +3,4 @@ export declare function DashboardLayoutError({ id, error, children, }: PropsWith
3
3
  type?: 'error';
4
4
  id?: string;
5
5
  error: unknown;
6
- }>): import("react/jsx-runtime").JSX.Element;
6
+ }>): import("react").JSX.Element;
@@ -7,4 +7,4 @@ export type DashboardTileContainerProps = {
7
7
  style?: CSSProperties;
8
8
  }) => ReactNode;
9
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;
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.Element | null | undefined;
@@ -2,4 +2,4 @@ export declare function DashboardTileError({ id, error, }: {
2
2
  type?: 'error';
3
3
  id?: string;
4
4
  error: unknown;
5
- }): import("react/jsx-runtime").JSX.Element;
5
+ }): import("react").JSX.Element;
@@ -2,4 +2,4 @@ import { DashboardTileNode } from '@rotorjs/dashboard';
2
2
  export type DashboardTilesProps = {
3
3
  content: DashboardTileNode[];
4
4
  };
5
- export declare function DashboardTiles({ content }: DashboardTilesProps): import("react/jsx-runtime").JSX.Element;
5
+ export declare function DashboardTiles({ content }: DashboardTilesProps): import("react").JSX.Element;
package/dist/main.d.ts CHANGED
@@ -9,3 +9,4 @@ export * from './DashboardTileError';
9
9
  export * from './DashboardTiles';
10
10
  export * from './getNodeKey';
11
11
  export * from './useDashboardState';
12
+ export * from './useNumberFormatter';
package/dist/main.js CHANGED
@@ -1,148 +1,128 @@
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";
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 p = n(void 0);
6
+ var h = a(void 0);
9
7
  //#endregion
10
8
  //#region lib/DashboardError.tsx
11
- function m({ error: e }) {
9
+ function g({ error: e }) {
12
10
  throw e;
13
11
  }
14
12
  //#endregion
15
13
  //#region lib/DashboardLayoutContext.ts
16
- var h = n(void 0);
14
+ var _ = a(void 0);
17
15
  //#endregion
18
16
  //#region lib/getNodeKey.ts
19
- function g(e, t = 0) {
17
+ function v(e, t = 0) {
20
18
  return `${encodeURIComponent(e.type)}:${e.id ? `id:${encodeURIComponent(e.id)}` : `idx:${t}`}`;
21
19
  }
22
20
  //#endregion
23
21
  //#region lib/DashboardLayoutError.tsx
24
- var _ = { type: "error" };
25
- function v({ id: e, error: t, children: n }) {
26
- let { layouts: a } = i(p), o = a.error ?? m, s = {
22
+ var y = { type: "error" };
23
+ function b({ id: e, error: t, children: n }) {
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__ */ u(h.Provider, {
32
- value: _,
33
- children: /* @__PURE__ */ r(o, {
34
- ...s,
35
- key: g(s)
29
+ return /* @__PURE__ */ p(_.Provider, {
30
+ value: y,
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
- function y({ layout: e, children: t }) {
42
- let { layouts: n, defaultLayout: a } = i(p), s = o(() => ({
43
- error: m,
39
+ function x({ layout: e, children: t }) {
40
+ let { layouts: n, defaultLayout: r } = c(h), i = u(() => ({
41
+ error: g,
44
42
  ...n
45
- }), [n]), c = e ?? a, l = c?.type, d = o(() => ({ type: l }), [l]);
46
- if (!c?.type) return null;
47
- let f = s[c.type];
48
- return f ? /* @__PURE__ */ u(h.Provider, {
49
- value: d,
50
- children: /* @__PURE__ */ r(f, {
51
- ...c,
52
- key: g(c)
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__ */ u(v, {
55
- error: `Invalid layout type "${c.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
- function b({ id: e, error: t }) {
62
- let { tiles: n } = i(p), a = n.error ?? m, o = {
59
+ function S({ id: e, error: t }) {
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(a, {
68
- ...o,
69
- key: g(o)
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
- function x({ content: e }) {
75
- let { tiles: t } = i(p), n = o(() => ({
76
- error: m,
72
+ function C({ content: e }) {
73
+ let { tiles: t } = c(h), n = u(() => ({
74
+ error: g,
77
75
  ...t
78
76
  }), [t]);
79
- return /* @__PURE__ */ u(l, { children: e.map((e, t) => {
77
+ return /* @__PURE__ */ p(f, { children: e.map((e, t) => {
80
78
  if (!e?.type) return null;
81
- let i = n[e.type];
82
- return i ? /* @__PURE__ */ r(i, {
79
+ let r = n[e.type];
80
+ return r ? /* @__PURE__ */ o(r, {
83
81
  ...e,
84
- key: g(e, t)
85
- }) : /* @__PURE__ */ u(b, { error: `Invalid tile type "${e.type}"` }, g({ type: "error" }, t));
82
+ key: v(e, t)
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
- 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({
96
- type: "var",
97
- name: t,
98
- value: r,
99
- exposed: i
88
+ var w = { [window.location.origin]: !0 };
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
- a.emitter = C, n.dispatchEvent(a);
102
- }), Object.entries(T).forEach(([t, { value: r }]) => {
103
- let i = new e({
104
- type: "fact",
105
- name: t,
106
- value: r
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
- 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) => {
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.emitter !== C) switch (t.type) {
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 (!E["*"] && (!Object.hasOwn(E, e) || !E[e])) {
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,59 +130,64 @@ function C({ engine: n, initialVars: r, initialFacts: i, layouts: l, defaultLayo
150
130
  break;
151
131
  }
152
132
  }
153
- }, { signal: t }), () => {
133
+ }, { signal: n }), () => {
154
134
  e.abort();
155
135
  };
156
136
  }, [
157
- C,
158
- n,
159
- _,
160
- E
137
+ t,
138
+ g,
139
+ y
161
140
  ]);
162
- let M = o(() => ({
163
- engine: n,
164
- vars: O,
165
- facts: A,
166
- layouts: l,
167
- defaultLayout: f,
168
- tiles: m
141
+ let O = u(() => ({
142
+ target: t,
143
+ vars: S,
144
+ facts: E,
145
+ layouts: a,
146
+ defaultLayout: o,
147
+ tiles: s
169
148
  }), [
170
- n,
171
- O,
172
- A,
173
- l,
174
- f,
175
- m
149
+ t,
150
+ S,
151
+ E,
152
+ a,
153
+ o,
154
+ s
176
155
  ]);
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]
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
- function w({ layout: e, children: t }) {
188
- let { tileContainer: n } = i(h);
189
- return n ? /* @__PURE__ */ u(n, {
166
+ function E({ layout: e, children: t }) {
167
+ let { tileContainer: n } = c(_);
168
+ return n ? /* @__PURE__ */ p(n, {
190
169
  layout: e,
191
170
  children: t
192
171
  }) : t({});
193
172
  }
194
173
  //#endregion
195
174
  //#region lib/useDashboardState.ts
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);
175
+ function D(e, n = []) {
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, o]), l;
184
+ }, [r, a]), s;
185
+ }
186
+ //#endregion
187
+ //#region lib/useNumberFormatter.ts
188
+ function O(e) {
189
+ let { facts: t } = c(h), i = t[r], 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]);
206
191
  }
207
192
  //#endregion
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 };
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 };
@@ -0,0 +1,5 @@
1
+ import { NumberFormat } from '@rotorjs/dashboard';
2
+ export type NumberFormatterOptions = {
3
+ locale?: Intl.UnicodeBCP47LocaleIdentifier;
4
+ };
5
+ export declare function useNumberFormatter(init?: NumberFormatterOptions): (value: number, format?: NumberFormat) => string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rotorjs/react",
3
- "version": "0.8.0",
3
+ "version": "0.10.0",
4
4
  "description": "Rotor",
5
5
  "author": {
6
6
  "name": "Aaron Burmeister"
@@ -44,32 +44,32 @@
44
44
  },
45
45
  "devDependencies": {
46
46
  "@eslint/js": "^10.0.1",
47
- "@rotorjs/dashboard": "^0.2.0",
48
- "@types/react": "^19.1.12",
47
+ "@rotorjs/dashboard": "^0.5.2",
48
+ "@types/react": "^19.2.17",
49
49
  "@types/react-dom": "^19.1.9",
50
50
  "@vitejs/plugin-react": "^6.0.2",
51
- "eslint": "^10.4.0",
51
+ "eslint": "^10.4.1",
52
52
  "eslint-config-prettier": "^10.1.8",
53
- "eslint-import-resolver-typescript": "^4.4.4",
53
+ "eslint-import-resolver-typescript": "^4.4.5",
54
54
  "eslint-plugin-import-x": "^4.16.2",
55
- "eslint-plugin-prettier": "^5.5.4",
55
+ "eslint-plugin-prettier": "^5.5.6",
56
56
  "eslint-plugin-react-hooks": "^7.1.1",
57
57
  "eslint-plugin-react-refresh": "^0.5.2",
58
58
  "globals": "^17.6.0",
59
- "prettier": "^3.8.3",
60
- "react": "^19.2.6",
61
- "react-dom": "^19.2.6",
59
+ "prettier": "^3.8.4",
60
+ "react": "^19.2.7",
61
+ "react-dom": "^19.2.7",
62
62
  "typescript": "^6.0.3",
63
- "typescript-eslint": "^8.59.4",
64
- "unplugin-dts": "^1.0.1",
65
- "vite": "^8.0.13"
63
+ "typescript-eslint": "^8.61.0",
64
+ "unplugin-dts": "^1.0.2",
65
+ "vite": "^8.0.16"
66
66
  },
67
67
  "peerDependencies": {
68
- "@rotorjs/dashboard": "^0.2.0",
68
+ "@rotorjs/dashboard": "^0.5.0",
69
69
  "react": "^19.0.0"
70
70
  },
71
71
  "dependencies": {
72
- "@rotorjs/state": "^0.6.0",
72
+ "@rotorjs/state": "^0.7.0",
73
73
  "fast-deep-equal": "^3.1.3",
74
74
  "uuid": "^14.0.0"
75
75
  }