@rotorjs/react 0.0.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.
@@ -0,0 +1,20 @@
1
+ import { DashboardEventTarget, DashboardFact, DashboardVar } from '@rotorjs/dashboards';
2
+ import { ReactNode } from 'react';
3
+ import { DashboardLayoutMap, DashboardLayoutNode } from './DashboardLayoutNode';
4
+ import { DashboardTileMap, DashboardTileNode } from './DashboardTileNode';
5
+ export type DashboardProps = {
6
+ engine: DashboardEventTarget;
7
+ initialVars?: {
8
+ [name: string]: DashboardVar;
9
+ };
10
+ initialFacts?: {
11
+ [name: string]: DashboardFact;
12
+ };
13
+ layouts: DashboardLayoutMap;
14
+ defaultLayout?: DashboardLayoutNode;
15
+ tiles: DashboardTileMap;
16
+ layout?: DashboardLayoutNode;
17
+ content: DashboardTileNode[];
18
+ children?: ReactNode;
19
+ };
20
+ export declare function Dashboard({ engine, initialVars: rawInitialVars, initialFacts: rawInitialFacts, layouts, defaultLayout, tiles, layout, content, children, }: DashboardProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,16 @@
1
+ import { DashboardEventTarget, DashboardFact, DashboardVar } from '@rotorjs/dashboards';
2
+ import { DashboardLayoutMap, DashboardLayoutNode } from './DashboardLayoutNode';
3
+ import { DashboardTileMap } from './DashboardTileNode';
4
+ export type DashboardContextValue = {
5
+ engine: DashboardEventTarget;
6
+ vars: {
7
+ [name: string]: DashboardVar;
8
+ };
9
+ facts: {
10
+ [name: string]: DashboardFact;
11
+ };
12
+ layouts: DashboardLayoutMap;
13
+ defaultLayout?: DashboardLayoutNode;
14
+ tiles: DashboardTileMap;
15
+ };
16
+ export declare const DashboardContext: import('react').Context<DashboardContextValue>;
@@ -0,0 +1,2 @@
1
+ import { ErrorDashboardNode } from '@rotorjs/dashboards';
2
+ export declare function DashboardError({ error }: ErrorDashboardNode): void;
@@ -0,0 +1,7 @@
1
+ import { ReactNode } from 'react';
2
+ import { DashboardLayoutNode } from './DashboardLayoutNode';
3
+ export type DashboardLayoutProps = {
4
+ layout?: DashboardLayoutNode;
5
+ children: ReactNode;
6
+ };
7
+ export declare function DashboardLayout({ layout, children }: DashboardLayoutProps): import("react/jsx-runtime").JSX.Element | null;
@@ -0,0 +1,4 @@
1
+ import { DashboardNode } from '@rotorjs/dashboards';
2
+ import { ComponentType, PropsWithChildren } from 'react';
3
+ export type DashboardLayoutNode = DashboardNode;
4
+ export type DashboardLayoutMap = Record<string, ComponentType<PropsWithChildren<DashboardLayoutNode>>>;
@@ -0,0 +1,4 @@
1
+ import { DashboardNode } from '@rotorjs/dashboards';
2
+ import { ComponentType } from 'react';
3
+ export type DashboardTileNode = DashboardNode;
4
+ export type DashboardTileMap = Record<string, ComponentType<DashboardTileNode>>;
@@ -0,0 +1,5 @@
1
+ import { DashboardTileNode } from './DashboardTileNode';
2
+ export type DashboardTilesProps = {
3
+ content: DashboardTileNode[];
4
+ };
5
+ export declare function DashboardTiles({ content }: DashboardTilesProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,2 @@
1
+ import { DashboardNode } from '@rotorjs/dashboards';
2
+ export declare function getKey(node: DashboardNode, index?: number): string;
package/dist/main.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ export * from './Dashboard';
2
+ export * from './DashboardContext';
3
+ export * from './DashboardError';
4
+ export * from './DashboardLayout';
5
+ export * from './DashboardLayoutNode';
6
+ export * from './DashboardTileNode';
7
+ export * from './DashboardTiles';
8
+ export * from './getKey';
9
+ export * from './useDashboardState';
package/dist/main.js ADDED
@@ -0,0 +1,204 @@
1
+ import { createContext as e, createElement as t, useContext as n, useEffect as r, useMemo as i, useState as a } from "react";
2
+ import { Fragment as o, jsx as s, jsxs as c } from "react/jsx-runtime";
3
+ //#region node_modules/@rotorjs/core/dist/main.js
4
+ var l = class extends Event {
5
+ emitter;
6
+ constructor(e, t) {
7
+ super(e, t);
8
+ }
9
+ }, u = class extends l {
10
+ #e;
11
+ constructor(e) {
12
+ super("action"), this.#e = e;
13
+ }
14
+ get action() {
15
+ return this.#e;
16
+ }
17
+ }, d = [];
18
+ for (let e = 0; e < 256; ++e) d.push((e + 256).toString(16).slice(1));
19
+ //#endregion
20
+ //#region node_modules/uuid/dist/stringify.js
21
+ var f = [];
22
+ for (let e = 0; e < 256; ++e) f.push((e + 256).toString(16).slice(1));
23
+ function p(e, t = 0) {
24
+ return (f[e[t + 0]] + f[e[t + 1]] + f[e[t + 2]] + f[e[t + 3]] + "-" + f[e[t + 4]] + f[e[t + 5]] + "-" + f[e[t + 6]] + f[e[t + 7]] + "-" + f[e[t + 8]] + f[e[t + 9]] + "-" + f[e[t + 10]] + f[e[t + 11]] + f[e[t + 12]] + f[e[t + 13]] + f[e[t + 14]] + f[e[t + 15]]).toLowerCase();
25
+ }
26
+ //#endregion
27
+ //#region node_modules/uuid/dist/rng.js
28
+ var m = new Uint8Array(16);
29
+ function h() {
30
+ return crypto.getRandomValues(m);
31
+ }
32
+ //#endregion
33
+ //#region node_modules/uuid/dist/v7.js
34
+ var g = {};
35
+ function _(e, t, n) {
36
+ let r;
37
+ if (e) r = y(e.random ?? e.rng?.() ?? h(), e.msecs, e.seq, t, n);
38
+ else {
39
+ let e = Date.now(), i = h();
40
+ v(g, e, i), r = y(i, g.msecs, g.seq, t, n);
41
+ }
42
+ return t ?? p(r);
43
+ }
44
+ function v(e, t, n) {
45
+ return e.msecs ??= -Infinity, e.seq ??= 0, t > e.msecs ? (e.seq = n[6] << 23 | n[7] << 16 | n[8] << 8 | n[9], e.msecs = t) : (e.seq = e.seq + 1 | 0, e.seq === 0 && e.msecs++), e;
46
+ }
47
+ function y(e, t, n, r, i = 0) {
48
+ if (e.length < 16) throw Error("Random bytes length must be >= 16");
49
+ if (!r) r = new Uint8Array(16), i = 0;
50
+ else if (i < 0 || i + 16 > r.length) throw RangeError(`UUID byte range ${i}:${i + 15} is out of buffer bounds`);
51
+ return t ??= Date.now(), n ??= e[6] * 127 << 24 | e[7] << 16 | e[8] << 8 | e[9], r[i++] = t / 1099511627776 & 255, r[i++] = t / 4294967296 & 255, r[i++] = t / 16777216 & 255, r[i++] = t / 65536 & 255, r[i++] = t / 256 & 255, r[i++] = t & 255, r[i++] = 112 | n >>> 28 & 15, r[i++] = n >>> 20 & 255, r[i++] = 128 | n >>> 14 & 63, r[i++] = n >>> 6 & 255, r[i++] = n << 2 & 255 | e[10] & 3, r[i++] = e[11], r[i++] = e[12], r[i++] = e[13], r[i++] = e[14], r[i++] = e[15], r;
52
+ }
53
+ //#endregion
54
+ //#region lib/DashboardContext.ts
55
+ var b = e(void 0);
56
+ //#endregion
57
+ //#region lib/DashboardError.tsx
58
+ function x({ error: e }) {
59
+ throw e;
60
+ }
61
+ //#endregion
62
+ //#region lib/getKey.ts
63
+ function S(e, t = 0) {
64
+ return `${encodeURIComponent(e.type)}:${e.id ? `id:${encodeURIComponent(e.id)}` : `idx:${t}`}`;
65
+ }
66
+ //#endregion
67
+ //#region lib/DashboardLayout.tsx
68
+ function C({ layout: e, children: r }) {
69
+ let { layouts: a, defaultLayout: o } = n(b), s = i(() => ({
70
+ error: x,
71
+ ...a
72
+ }), [a]), c = e ?? o;
73
+ if (!c) return null;
74
+ let l = s[c.type];
75
+ if (!l) {
76
+ let e = s.error, n = {
77
+ type: "error",
78
+ error: `Invalid layout type "${c.type}"`
79
+ };
80
+ return /* @__PURE__ */ t(e, {
81
+ ...n,
82
+ key: S(n)
83
+ });
84
+ }
85
+ return /* @__PURE__ */ t(l, {
86
+ ...c,
87
+ key: S(c)
88
+ }, r);
89
+ }
90
+ //#endregion
91
+ //#region lib/DashboardTiles.tsx
92
+ function w({ content: e }) {
93
+ let { tiles: r } = n(b), a = i(() => ({
94
+ error: x,
95
+ ...r
96
+ }), [r]);
97
+ return /* @__PURE__ */ s(o, { children: e.map((e, n) => {
98
+ if (!e) return null;
99
+ let r = a[e.type];
100
+ if (!r) {
101
+ let r = a.error;
102
+ return /* @__PURE__ */ t(r, {
103
+ type: "error",
104
+ error: `Invalid tile type "${e.type}"`,
105
+ key: S(e, n)
106
+ });
107
+ }
108
+ return /* @__PURE__ */ t(r, {
109
+ ...e,
110
+ key: S(e, n)
111
+ });
112
+ }) });
113
+ }
114
+ //#endregion
115
+ //#region lib/Dashboard.tsx
116
+ function T({ engine: e, initialVars: t, initialFacts: n, layouts: o, defaultLayout: l, tiles: d, layout: f, content: p, children: m }) {
117
+ let [h] = a(t ?? {}), [g, v] = a(h), [y] = a(n ?? {}), [x, S] = a(y);
118
+ r(() => {
119
+ let t = _(), n = new AbortController(), r = n.signal;
120
+ return Object.entries(h).forEach(([n, { value: r, exposed: i }]) => {
121
+ let a = new u({
122
+ type: "var",
123
+ name: n,
124
+ value: r,
125
+ exposed: i
126
+ });
127
+ a.emitter = t, e.dispatchEvent(a);
128
+ }), Object.entries(y).forEach(([n, { value: r }]) => {
129
+ let i = new u({
130
+ type: "fact",
131
+ name: n,
132
+ value: r
133
+ });
134
+ i.emitter = t, e.dispatchEvent(i);
135
+ }), e.addEventListener("action", (e) => {
136
+ if (e.emitter === t) return;
137
+ let n = e.action;
138
+ switch (n.type) {
139
+ case "var":
140
+ v((e) => {
141
+ let t = e[n.name];
142
+ return Object.hasOwn(e, n.name) && t.value === n.value && t.exposed === (n.exposed ?? !1) ? e : {
143
+ ...e,
144
+ [n.name]: {
145
+ value: n.value,
146
+ exposed: n.exposed ?? !1
147
+ }
148
+ };
149
+ });
150
+ return;
151
+ case "fact": S((e) => {
152
+ let t = e[n.name];
153
+ return Object.hasOwn(e, n.name) && t.value === n.value ? e : {
154
+ ...e,
155
+ [n.name]: { value: n.value }
156
+ };
157
+ });
158
+ }
159
+ }, { signal: r }), () => {
160
+ n.abort();
161
+ };
162
+ }, [
163
+ e,
164
+ h,
165
+ y
166
+ ]);
167
+ let T = i(() => ({
168
+ engine: e,
169
+ vars: g,
170
+ facts: x,
171
+ layouts: o,
172
+ defaultLayout: l,
173
+ tiles: d
174
+ }), [
175
+ e,
176
+ g,
177
+ x,
178
+ o,
179
+ l,
180
+ d
181
+ ]);
182
+ return /* @__PURE__ */ s(b.Provider, {
183
+ value: T,
184
+ children: /* @__PURE__ */ c(C, {
185
+ layout: f,
186
+ children: [/* @__PURE__ */ s(w, { content: p }), m]
187
+ })
188
+ });
189
+ }
190
+ //#endregion
191
+ //#region lib/useDashboardState.ts
192
+ function E(e, t = []) {
193
+ let { engine: i } = n(b), [o, s] = a(t);
194
+ return r(() => {
195
+ let t = _(), n = new AbortController(), r = n.signal;
196
+ return i.addEventListener("state", (e) => {
197
+ e.id === t && s(e.state);
198
+ }, { signal: r }), i.registerReducer(t, e), () => {
199
+ n.abort(), i.removeReducer(t);
200
+ };
201
+ }, [e, i]), o;
202
+ }
203
+ //#endregion
204
+ export { T as Dashboard, b as DashboardContext, x as DashboardError, C as DashboardLayout, w as DashboardTiles, S as getKey, E as useDashboardState };
@@ -0,0 +1,2 @@
1
+ import { DashboardReducerInit, DashboardState } from '@rotorjs/dashboards';
2
+ export declare function useDashboardState(init: DashboardReducerInit, initialState?: DashboardState): DashboardState;
package/package.json ADDED
@@ -0,0 +1,76 @@
1
+ {
2
+ "name": "@rotorjs/react",
3
+ "version": "0.0.0",
4
+ "description": "Rotor",
5
+ "author": {
6
+ "name": "Aaron Burmeister"
7
+ },
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/rotorjs/react.git"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/rotorjs/react/issues"
14
+ },
15
+ "homepage": "https://github.com/rotorjs/",
16
+ "type": "module",
17
+ "keywords": [
18
+ "state",
19
+ "dashboards",
20
+ "react"
21
+ ],
22
+ "files": [
23
+ "dist"
24
+ ],
25
+ "main": "./dist/main.js",
26
+ "types": "./dist/main.d.ts",
27
+ "exports": {
28
+ ".": {
29
+ "import": {
30
+ "types": "./dist/main.d.ts",
31
+ "default": "./dist/main.js"
32
+ }
33
+ }
34
+ },
35
+ "scripts": {
36
+ "dev": "vite",
37
+ "build": "tsc -b ./tsconfig-build.json && vite build",
38
+ "lint": "eslint . --max-warnings 0",
39
+ "lint:fix": "npm run lint -- --fix",
40
+ "prettify": "prettier . --write",
41
+ "preview": "vite preview",
42
+ "postversion": "git commit -am$npm_package_version",
43
+ "prepublishOnly": "npm run build"
44
+ },
45
+ "devDependencies": {
46
+ "@eslint/js": "^10.0.1",
47
+ "@jplorg/jpl": "^2.0.0",
48
+ "@rotorjs/core": "^0.5.1",
49
+ "@rotorjs/dashboards": "^0.11.0",
50
+ "@types/react": "^19.1.12",
51
+ "@types/react-dom": "^19.1.9",
52
+ "@vitejs/plugin-react": "^6.0.1",
53
+ "eslint": "^10.3.0",
54
+ "eslint-config-prettier": "^10.1.8",
55
+ "eslint-import-resolver-typescript": "^4.4.4",
56
+ "eslint-plugin-import-x": "^4.16.2",
57
+ "eslint-plugin-prettier": "^5.5.4",
58
+ "eslint-plugin-react-hooks": "^7.1.1",
59
+ "eslint-plugin-react-refresh": "^0.5.2",
60
+ "globals": "^17.6.0",
61
+ "prettier": "^3.8.3",
62
+ "react": "^19.2.6",
63
+ "react-dom": "^19.2.6",
64
+ "typescript": "^6.0.3",
65
+ "typescript-eslint": "^8.59.3",
66
+ "unplugin-dts": "^1.0.0",
67
+ "vite": "^8.0.12"
68
+ },
69
+ "peerDependencies": {
70
+ "@rotorjs/core": "^0.5.0",
71
+ "@rotorjs/dashboards": "^0.11.0"
72
+ },
73
+ "dependencies": {
74
+ "uuid": "^14.0.0"
75
+ }
76
+ }