@rotorjs/dashboard 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
+ export type VarDashboardAction = {
2
+ type: 'var';
3
+ name: string;
4
+ value: unknown;
5
+ exposed?: boolean;
6
+ };
7
+ export type FactDashboardAction = {
8
+ type: 'fact';
9
+ name: string;
10
+ value: unknown;
11
+ };
12
+ export type NavigateDashboardAction = {
13
+ type: 'navigate';
14
+ href: string;
15
+ replace?: boolean;
16
+ };
17
+ export type DashboardAction = {
18
+ type: string;
19
+ [key: string]: unknown;
20
+ };
@@ -0,0 +1,26 @@
1
+ import { StateEngine } from '@rotorjs/state';
2
+ import { DashboardAction } from './DashboardAction';
3
+ import { DashboardEventTarget } from './DashboardEventTarget';
4
+ import { DashboardFact } from './DashboardFact';
5
+ import { DashboardState } from './DashboardState';
6
+ import { DashboardStateDescriptor } from './DashboardStateDescriptor';
7
+ import { DashboardStateReducer } from './DashboardStateReducer';
8
+ import { DashboardStateReducerConfig } from './DashboardStateReducerConfig';
9
+ import { DashboardVar } from './DashboardVar';
10
+ export type DashboardStateReducerMap<Engine extends DashboardEngine = DashboardEngine> = {
11
+ [type: string]: DashboardStateReducerConfig<Engine>;
12
+ };
13
+ export declare class DashboardEngine extends StateEngine<DashboardStateDescriptor, DashboardState, DashboardAction> implements DashboardEventTarget {
14
+ #private;
15
+ constructor(reducerInit: DashboardStateReducerMap);
16
+ protected onAction(action: DashboardAction): void;
17
+ dispatchVar(name: string, value: unknown, exposed?: boolean): void;
18
+ dispatchFact(name: string, value: unknown): void;
19
+ hasVar(name: string): boolean;
20
+ getVar(name: string): DashboardVar | undefined;
21
+ hasFact(name: string): boolean;
22
+ getFact(name: string): DashboardFact | undefined;
23
+ protected getReducerConfig(descriptor: DashboardStateDescriptor): DashboardStateReducerConfig;
24
+ getReducerID(descriptor: DashboardStateDescriptor): string;
25
+ protected createReducer(descriptor: DashboardStateDescriptor): DashboardStateReducer<DashboardEngine>;
26
+ }
@@ -0,0 +1,8 @@
1
+ import { StateEventTarget } from '@rotorjs/state';
2
+ import { DashboardAction } from './DashboardAction';
3
+ import { DashboardState } from './DashboardState';
4
+ import { DashboardStateDescriptor } from './DashboardStateDescriptor';
5
+ export declare class DashboardEventTarget extends StateEventTarget<DashboardStateDescriptor, DashboardState, DashboardAction> {
6
+ dispatchVar(name: string, value: unknown, exposed?: boolean): void;
7
+ dispatchFact(name: string, value: unknown): void;
8
+ }
@@ -0,0 +1,3 @@
1
+ export type DashboardFact = {
2
+ value: unknown;
3
+ };
@@ -0,0 +1,2 @@
1
+ import { DashboardNode } from './nodes';
2
+ export type DashboardState = DashboardNode[];
@@ -0,0 +1,7 @@
1
+ import { StateConsumer } from '@rotorjs/state';
2
+ import { DashboardAction } from './DashboardAction';
3
+ import { DashboardState } from './DashboardState';
4
+ import { DashboardStateDescriptor } from './DashboardStateDescriptor';
5
+ export declare class DashboardStateConsumer extends StateConsumer<DashboardStateDescriptor, DashboardState, DashboardAction> {
6
+ protected compareStates(nextState: DashboardState, prevState: DashboardState): boolean;
7
+ }
@@ -0,0 +1,4 @@
1
+ export type DashboardStateDescriptor = {
2
+ type: string;
3
+ params?: unknown;
4
+ };
@@ -0,0 +1,9 @@
1
+ import { StateReducer } from '@rotorjs/state';
2
+ import { DashboardAction } from './DashboardAction';
3
+ import { DashboardEngine } from './DashboardEngine';
4
+ import { DashboardState } from './DashboardState';
5
+ import { DashboardStateDescriptor } from './DashboardStateDescriptor';
6
+ export declare abstract class DashboardStateReducer<Engine extends DashboardEngine = DashboardEngine> extends StateReducer<DashboardStateDescriptor, DashboardState, DashboardAction, Engine> {
7
+ recover(_prevState: DashboardState, error: unknown): DashboardState;
8
+ protected compareStates(nextState: DashboardState, prevState: DashboardState): boolean;
9
+ }
@@ -0,0 +1,11 @@
1
+ import { DashboardEngine } from './DashboardEngine';
2
+ import { DashboardStateDescriptor } from './DashboardStateDescriptor';
3
+ import { DashboardStateReducer } from './DashboardStateReducer';
4
+ export type GetDashboardStateReducerIDFunction = (params: unknown | undefined) => string;
5
+ export type CreateDashboardStateReducerFunction<Engine extends DashboardEngine = DashboardEngine> = {
6
+ bivarianceHack(engine: Engine, descriptor: DashboardStateDescriptor): DashboardStateReducer<Engine>;
7
+ }['bivarianceHack'];
8
+ export type DashboardStateReducerConfig<Engine extends DashboardEngine = DashboardEngine> = {
9
+ getReducerID: GetDashboardStateReducerIDFunction;
10
+ createReducer: CreateDashboardStateReducerFunction<Engine>;
11
+ };
@@ -0,0 +1,4 @@
1
+ export type DashboardVar = {
2
+ value: unknown;
3
+ exposed: boolean;
4
+ };
@@ -0,0 +1,2 @@
1
+ export declare function dashboardVarInterest(name: string): string;
2
+ export declare function dashboardFactInterest(name: string): string;
package/dist/main.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ export * from './DashboardAction';
2
+ export * from './DashboardEngine';
3
+ export * from './DashboardEventTarget';
4
+ export * from './DashboardFact';
5
+ export * from './DashboardState';
6
+ export * from './DashboardStateConsumer';
7
+ export * from './DashboardStateDescriptor';
8
+ export * from './DashboardStateReducer';
9
+ export * from './DashboardStateReducerConfig';
10
+ export * from './DashboardVar';
11
+ export * from './interests';
12
+ export * from './nodes';
package/dist/main.js ADDED
@@ -0,0 +1,105 @@
1
+ import { StateConsumer as e, StateEngine as t, StateEventTarget as n, StateReducer as r } from "@rotorjs/state";
2
+ import i from "fast-deep-equal";
3
+ import { v7 as a } from "uuid";
4
+ //#region lib/interests.ts
5
+ function o(e) {
6
+ return `dashboard://var/${encodeURIComponent(e)}`;
7
+ }
8
+ function s(e) {
9
+ return `dashboard://fact/${encodeURIComponent(e)}`;
10
+ }
11
+ //#endregion
12
+ //#region lib/DashboardEngine.ts
13
+ var c = class extends t {
14
+ #e;
15
+ #t = {};
16
+ #n = {};
17
+ constructor(e) {
18
+ super(), this.#e = e;
19
+ }
20
+ onAction(e) {
21
+ super.onAction(e);
22
+ let t = e;
23
+ switch (t.type) {
24
+ case "var":
25
+ this.#t[t.name] = {
26
+ value: t.value,
27
+ exposed: t.exposed ?? !1
28
+ }, this.dispatchInterest(o(t.name));
29
+ return;
30
+ case "fact":
31
+ this.#n[t.name] = { value: t.value }, this.dispatchInterest(s(t.name));
32
+ return;
33
+ }
34
+ }
35
+ dispatchVar(e, t, n) {
36
+ this.dispatchAction({
37
+ type: "var",
38
+ name: e,
39
+ value: t,
40
+ exposed: n
41
+ });
42
+ }
43
+ dispatchFact(e, t) {
44
+ this.dispatchAction({
45
+ type: "fact",
46
+ name: e,
47
+ value: t
48
+ });
49
+ }
50
+ hasVar(e) {
51
+ return Object.hasOwn(this.#t, e);
52
+ }
53
+ getVar(e) {
54
+ return this.#t[e];
55
+ }
56
+ hasFact(e) {
57
+ return Object.hasOwn(this.#n, e);
58
+ }
59
+ getFact(e) {
60
+ return this.#n[e];
61
+ }
62
+ getReducerConfig(e) {
63
+ if (!Object.hasOwn(this.#e, e.type)) throw Error(`Unknown reducer type "${e.type}"`);
64
+ return this.#e[e.type];
65
+ }
66
+ getReducerID(e) {
67
+ return `${encodeURIComponent(e.type)}:${encodeURIComponent(this.getReducerConfig(e).getReducerID(e.params))}`;
68
+ }
69
+ createReducer(e) {
70
+ return this.getReducerConfig(e).createReducer(this, e);
71
+ }
72
+ }, l = class extends n {
73
+ dispatchVar(e, t, n) {
74
+ this.dispatchAction({
75
+ type: "var",
76
+ name: e,
77
+ value: t,
78
+ exposed: n
79
+ });
80
+ }
81
+ dispatchFact(e, t) {
82
+ this.dispatchAction({
83
+ type: "fact",
84
+ name: e,
85
+ value: t
86
+ });
87
+ }
88
+ }, u = class extends e {
89
+ compareStates(e, t) {
90
+ return i(e, t);
91
+ }
92
+ }, d = class extends r {
93
+ recover(e, t) {
94
+ return [{
95
+ type: "error",
96
+ id: a(),
97
+ error: t
98
+ }];
99
+ }
100
+ compareStates(e, t) {
101
+ return i(e, t);
102
+ }
103
+ };
104
+ //#endregion
105
+ export { c as DashboardEngine, l as DashboardEventTarget, u as DashboardStateConsumer, d as DashboardStateReducer, s as dashboardFactInterest, o as dashboardVarInterest };
@@ -0,0 +1,19 @@
1
+ export type DashboardNode = {
2
+ type: string;
3
+ id?: string;
4
+ [key: string]: unknown;
5
+ };
6
+ export type ErrorDashboardNode = {
7
+ type: 'error';
8
+ id?: string;
9
+ error: unknown;
10
+ };
11
+ export type DashboardLayoutNode = DashboardNode;
12
+ export type ErrorDashboardLayoutNode = ErrorDashboardNode;
13
+ export type DashboardLayoutConfig = unknown;
14
+ export type DashboardTileNode = DashboardNode & {
15
+ layout?: DashboardLayoutConfig;
16
+ };
17
+ export type ErrorDashboardTileNode = ErrorDashboardNode & {
18
+ layout?: DashboardLayoutConfig;
19
+ };
package/package.json ADDED
@@ -0,0 +1,70 @@
1
+ {
2
+ "name": "@rotorjs/dashboard",
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/dashboard.git"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/rotorjs/dashboard/issues"
14
+ },
15
+ "homepage": "https://github.com/rotorjs/",
16
+ "type": "module",
17
+ "keywords": [
18
+ "state",
19
+ "dashboards"
20
+ ],
21
+ "files": [
22
+ "dist"
23
+ ],
24
+ "main": "./dist/main.js",
25
+ "types": "./dist/main.d.ts",
26
+ "exports": {
27
+ ".": {
28
+ "import": {
29
+ "types": "./dist/main.d.ts",
30
+ "default": "./dist/main.js"
31
+ }
32
+ }
33
+ },
34
+ "scripts": {
35
+ "dev": "vite",
36
+ "build": "tsc -b ./tsconfig-build.json && vite build",
37
+ "lint": "eslint . --max-warnings 0",
38
+ "lint:fix": "npm run lint -- --fix",
39
+ "prettify": "prettier . --write",
40
+ "preview": "vite preview",
41
+ "postversion": "git commit -am$npm_package_version",
42
+ "prepublishOnly": "npm run build"
43
+ },
44
+ "devDependencies": {
45
+ "@eslint/js": "^10.0.1",
46
+ "@types/react": "^19.1.12",
47
+ "@types/react-dom": "^19.1.9",
48
+ "@vitejs/plugin-react": "^6.0.2",
49
+ "eslint": "^10.4.0",
50
+ "eslint-config-prettier": "^10.1.8",
51
+ "eslint-import-resolver-typescript": "^4.4.4",
52
+ "eslint-plugin-import-x": "^4.16.2",
53
+ "eslint-plugin-prettier": "^5.5.4",
54
+ "eslint-plugin-react-hooks": "^7.1.1",
55
+ "eslint-plugin-react-refresh": "^0.5.2",
56
+ "globals": "^17.6.0",
57
+ "prettier": "^3.8.3",
58
+ "react": "^19.2.6",
59
+ "react-dom": "^19.2.6",
60
+ "typescript": "^6.0.3",
61
+ "typescript-eslint": "^8.59.4",
62
+ "unplugin-dts": "^1.0.1",
63
+ "vite": "^8.0.13"
64
+ },
65
+ "dependencies": {
66
+ "@rotorjs/state": "^0.2.0",
67
+ "fast-deep-equal": "^3.1.3",
68
+ "uuid": "^14.0.0"
69
+ }
70
+ }