@rotorjs/dashboard 0.3.1 → 0.5.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.
|
@@ -10,12 +10,17 @@ import { DashboardVar } from './DashboardVar';
|
|
|
10
10
|
export type DashboardStateReducerMap<Engine extends DashboardEngine = DashboardEngine> = {
|
|
11
11
|
[type: string]: DashboardStateReducerConfig<Engine>;
|
|
12
12
|
};
|
|
13
|
-
export
|
|
13
|
+
export type DashboardEngineInit = {
|
|
14
|
+
vars?: {
|
|
15
|
+
[name: string]: DashboardVar;
|
|
16
|
+
};
|
|
17
|
+
facts?: {
|
|
18
|
+
[name: string]: DashboardFact;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
export declare class DashboardEngine extends StateEngine<DashboardStateDescriptor, DashboardState, DashboardAction, DashboardEventTarget> {
|
|
14
22
|
#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;
|
|
23
|
+
constructor(target: DashboardEventTarget, reducerInit: DashboardStateReducerMap, init?: DashboardEngineInit);
|
|
19
24
|
hasVar(name: string): boolean;
|
|
20
25
|
getVar(name: string): DashboardVar | undefined;
|
|
21
26
|
hasFact(name: string): boolean;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { TypedEventTarget } from '@rotorjs/state';
|
|
2
|
+
import { DashboardEventTarget } from './DashboardEventTarget';
|
|
3
|
+
import { DashboardFact } from './DashboardFact';
|
|
4
|
+
import { DashboardVar } from './DashboardVar';
|
|
5
|
+
export type DashboardEnvironmentInit = {
|
|
6
|
+
vars?: {
|
|
7
|
+
[name: string]: DashboardVar;
|
|
8
|
+
};
|
|
9
|
+
facts?: {
|
|
10
|
+
[name: string]: DashboardFact;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
export declare class DashboardEnvironment extends TypedEventTarget<{
|
|
14
|
+
var: VarEvent;
|
|
15
|
+
fact: FactEvent;
|
|
16
|
+
}> {
|
|
17
|
+
#private;
|
|
18
|
+
constructor(target: DashboardEventTarget, init?: DashboardEnvironmentInit);
|
|
19
|
+
get target(): DashboardEventTarget;
|
|
20
|
+
get id(): string;
|
|
21
|
+
get signal(): AbortSignal;
|
|
22
|
+
hasVar(name: string): boolean;
|
|
23
|
+
getVar(name: string): DashboardVar | undefined;
|
|
24
|
+
getVars(): [name: string, value: DashboardVar][];
|
|
25
|
+
hasFact(name: string): boolean;
|
|
26
|
+
getFact(name: string): DashboardFact | undefined;
|
|
27
|
+
getFacts(): [name: string, value: DashboardFact][];
|
|
28
|
+
stop(): void;
|
|
29
|
+
}
|
|
30
|
+
export declare class VarEvent extends Event {
|
|
31
|
+
#private;
|
|
32
|
+
constructor(name: string, value: unknown, exposed: boolean);
|
|
33
|
+
get name(): string;
|
|
34
|
+
get value(): unknown;
|
|
35
|
+
get exposed(): boolean;
|
|
36
|
+
}
|
|
37
|
+
export declare class FactEvent extends Event {
|
|
38
|
+
#private;
|
|
39
|
+
constructor(name: string, value: unknown);
|
|
40
|
+
get name(): string;
|
|
41
|
+
get value(): unknown;
|
|
42
|
+
}
|
|
@@ -5,4 +5,5 @@ import { DashboardStateDescriptor } from './DashboardStateDescriptor';
|
|
|
5
5
|
export declare class DashboardEventTarget extends StateEventTarget<DashboardStateDescriptor, DashboardState, DashboardAction> {
|
|
6
6
|
dispatchVar(name: string, value: unknown, exposed?: boolean): void;
|
|
7
7
|
dispatchFact(name: string, value: unknown): void;
|
|
8
|
+
sync(): void;
|
|
8
9
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { StateConsumer } from '@rotorjs/state';
|
|
1
|
+
import { StateConsumer, StateCallback, StateEventTarget } from '@rotorjs/state';
|
|
2
2
|
import { DashboardAction } from './DashboardAction';
|
|
3
3
|
import { DashboardState } from './DashboardState';
|
|
4
4
|
import { DashboardStateDescriptor } from './DashboardStateDescriptor';
|
|
5
5
|
export declare class DashboardStateConsumer extends StateConsumer<DashboardStateDescriptor, DashboardState, DashboardAction> {
|
|
6
|
+
constructor(target: StateEventTarget<DashboardStateDescriptor, DashboardState, DashboardAction>, descriptor: DashboardStateDescriptor, callback: StateCallback<DashboardState>);
|
|
6
7
|
protected compareStates(nextState: DashboardState, prevState: DashboardState): boolean;
|
|
7
8
|
}
|
package/dist/main.js
CHANGED
|
@@ -1,63 +1,149 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import { v7 as
|
|
1
|
+
import { ActionEvent as e, StateConsumer as t, StateEngine as n, StateEventTarget as r, StateReducer as i, TypedEventTarget as a } from "@rotorjs/state";
|
|
2
|
+
import o from "fast-deep-equal";
|
|
3
|
+
import { v7 as s } from "uuid";
|
|
4
|
+
//#region lib/DashboardEnvironment.ts
|
|
5
|
+
var c = class extends a {
|
|
6
|
+
#e;
|
|
7
|
+
#t = s();
|
|
8
|
+
#n;
|
|
9
|
+
#r;
|
|
10
|
+
#i = new AbortController();
|
|
11
|
+
constructor(t, n) {
|
|
12
|
+
super(), this.#e = t, this.#n = Object.fromEntries(Object.entries(n?.vars ?? {}).map(([e, t]) => [e, Object.freeze(t)])), this.#r = Object.fromEntries(Object.entries(n?.facts ?? {}).map(([e, t]) => [e, Object.freeze(t)]));
|
|
13
|
+
let r = this.signal;
|
|
14
|
+
this.target.addEventListener("action", (t) => {
|
|
15
|
+
if (t.emitter === this.#t) return;
|
|
16
|
+
let n = t.action;
|
|
17
|
+
switch (n.type) {
|
|
18
|
+
case "var": {
|
|
19
|
+
let e = this.#n[n.name], t = Object.freeze({
|
|
20
|
+
value: n.value,
|
|
21
|
+
exposed: n.exposed ?? !1
|
|
22
|
+
});
|
|
23
|
+
o(e, t) || (this.#n[n.name] = t, this.dispatchEvent(new l(n.name, t.value, t.exposed)));
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
case "fact": {
|
|
27
|
+
let e = this.#r[n.name], t = Object.freeze({ value: n.value });
|
|
28
|
+
o(e, t) || (this.#r[n.name] = t, this.dispatchEvent(new u(n.name, t.value)));
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
case "sync": Object.entries(this.#n).forEach(([t, { value: n, exposed: r }]) => {
|
|
32
|
+
let i = new e({
|
|
33
|
+
type: "var",
|
|
34
|
+
name: t,
|
|
35
|
+
value: n,
|
|
36
|
+
exposed: r
|
|
37
|
+
});
|
|
38
|
+
i.emitter = this.#t, this.target.dispatchEvent(i);
|
|
39
|
+
}), Object.entries(this.#r).forEach(([t, { value: n }]) => {
|
|
40
|
+
let r = new e({
|
|
41
|
+
type: "fact",
|
|
42
|
+
name: t,
|
|
43
|
+
value: n
|
|
44
|
+
});
|
|
45
|
+
r.emitter = this.#t, this.target.dispatchEvent(r);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}, { signal: r }), this.target.sync();
|
|
49
|
+
}
|
|
50
|
+
get target() {
|
|
51
|
+
return this.#e;
|
|
52
|
+
}
|
|
53
|
+
get id() {
|
|
54
|
+
return this.#t;
|
|
55
|
+
}
|
|
56
|
+
get signal() {
|
|
57
|
+
return this.#i.signal;
|
|
58
|
+
}
|
|
59
|
+
hasVar(e) {
|
|
60
|
+
return Object.hasOwn(this.#n, e);
|
|
61
|
+
}
|
|
62
|
+
getVar(e) {
|
|
63
|
+
return this.#n[e];
|
|
64
|
+
}
|
|
65
|
+
getVars() {
|
|
66
|
+
return Object.entries(this.#n);
|
|
67
|
+
}
|
|
68
|
+
hasFact(e) {
|
|
69
|
+
return Object.hasOwn(this.#r, e);
|
|
70
|
+
}
|
|
71
|
+
getFact(e) {
|
|
72
|
+
return this.#r[e];
|
|
73
|
+
}
|
|
74
|
+
getFacts() {
|
|
75
|
+
return Object.entries(this.#r);
|
|
76
|
+
}
|
|
77
|
+
stop() {
|
|
78
|
+
this.#i.abort();
|
|
79
|
+
}
|
|
80
|
+
}, l = class extends Event {
|
|
81
|
+
#e;
|
|
82
|
+
#t;
|
|
83
|
+
#n;
|
|
84
|
+
constructor(e, t, n) {
|
|
85
|
+
super("var"), this.#e = e, this.#t = t, this.#n = n;
|
|
86
|
+
}
|
|
87
|
+
get name() {
|
|
88
|
+
return this.#e;
|
|
89
|
+
}
|
|
90
|
+
get value() {
|
|
91
|
+
return this.#t;
|
|
92
|
+
}
|
|
93
|
+
get exposed() {
|
|
94
|
+
return this.#n;
|
|
95
|
+
}
|
|
96
|
+
}, u = class extends Event {
|
|
97
|
+
#e;
|
|
98
|
+
#t;
|
|
99
|
+
constructor(e, t) {
|
|
100
|
+
super("fact"), this.#e = e, this.#t = t;
|
|
101
|
+
}
|
|
102
|
+
get name() {
|
|
103
|
+
return this.#e;
|
|
104
|
+
}
|
|
105
|
+
get value() {
|
|
106
|
+
return this.#t;
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
//#endregion
|
|
4
110
|
//#region lib/interests.ts
|
|
5
|
-
function
|
|
111
|
+
function d(e) {
|
|
6
112
|
return `dashboard://var/${encodeURIComponent(e)}`;
|
|
7
113
|
}
|
|
8
|
-
function
|
|
114
|
+
function f(e) {
|
|
9
115
|
return `dashboard://fact/${encodeURIComponent(e)}`;
|
|
10
116
|
}
|
|
11
117
|
//#endregion
|
|
12
118
|
//#region lib/DashboardEngine.ts
|
|
13
|
-
var
|
|
119
|
+
var p = class extends n {
|
|
14
120
|
#e;
|
|
15
|
-
#t
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
|
121
|
+
#t;
|
|
122
|
+
constructor(e, t, n) {
|
|
123
|
+
super(e), this.#e = t, this.#t = new c(this.target, {
|
|
124
|
+
vars: n?.vars,
|
|
125
|
+
facts: n?.facts
|
|
41
126
|
});
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
name
|
|
47
|
-
|
|
127
|
+
let r = this.signal;
|
|
128
|
+
this.#t.addEventListener("var", (e) => {
|
|
129
|
+
this.target.dispatchInterest(d(e.name));
|
|
130
|
+
}, { signal: r }), this.#t.addEventListener("fact", (e) => {
|
|
131
|
+
this.target.dispatchInterest(f(e.name));
|
|
132
|
+
}, { signal: r }), r.addEventListener("abort", () => {
|
|
133
|
+
this.#t.stop();
|
|
48
134
|
});
|
|
49
135
|
}
|
|
50
136
|
hasVar(e) {
|
|
51
|
-
return
|
|
137
|
+
return this.#t.hasVar(e);
|
|
52
138
|
}
|
|
53
139
|
getVar(e) {
|
|
54
|
-
return this.#t
|
|
140
|
+
return this.#t.getVar(e);
|
|
55
141
|
}
|
|
56
142
|
hasFact(e) {
|
|
57
|
-
return
|
|
143
|
+
return this.#t.hasFact(e);
|
|
58
144
|
}
|
|
59
145
|
getFact(e) {
|
|
60
|
-
return this.#
|
|
146
|
+
return this.#t.getFact(e);
|
|
61
147
|
}
|
|
62
148
|
getReducerConfig(e) {
|
|
63
149
|
if (!Object.hasOwn(this.#e, e.type)) throw Error(`Unknown reducer type "${e.type}"`);
|
|
@@ -69,7 +155,7 @@ var c = class extends t {
|
|
|
69
155
|
createReducer(e) {
|
|
70
156
|
return this.getReducerConfig(e).createReducer(this, e);
|
|
71
157
|
}
|
|
72
|
-
},
|
|
158
|
+
}, m = class extends r {
|
|
73
159
|
dispatchVar(e, t, n) {
|
|
74
160
|
this.dispatchAction({
|
|
75
161
|
type: "var",
|
|
@@ -85,22 +171,34 @@ var c = class extends t {
|
|
|
85
171
|
value: t
|
|
86
172
|
});
|
|
87
173
|
}
|
|
88
|
-
|
|
174
|
+
sync() {
|
|
175
|
+
this.dispatchAction({ type: "sync" });
|
|
176
|
+
}
|
|
177
|
+
}, h = class extends t {
|
|
178
|
+
constructor(e, t, n) {
|
|
179
|
+
super(e, t, n), this.target.addEventListener("action", (e) => {
|
|
180
|
+
switch (e.action.type) {
|
|
181
|
+
case "sync":
|
|
182
|
+
this.target.subscribeState(this.id, this.descriptor);
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
}, { signal: this.signal });
|
|
186
|
+
}
|
|
89
187
|
compareStates(e, t) {
|
|
90
|
-
return
|
|
188
|
+
return o(e, t);
|
|
91
189
|
}
|
|
92
|
-
},
|
|
190
|
+
}, g = class extends i {
|
|
93
191
|
recover(e, t) {
|
|
94
192
|
return [{
|
|
95
193
|
type: "error",
|
|
96
|
-
id:
|
|
194
|
+
id: s(),
|
|
97
195
|
error: t
|
|
98
196
|
}];
|
|
99
197
|
}
|
|
100
198
|
compareStates(e, t) {
|
|
101
|
-
return
|
|
199
|
+
return o(e, t);
|
|
102
200
|
}
|
|
103
|
-
},
|
|
201
|
+
}, _ = "locale", v = class {
|
|
104
202
|
#e;
|
|
105
203
|
constructor(e) {
|
|
106
204
|
this.#e = e ?? {};
|
|
@@ -108,19 +206,19 @@ var c = class extends t {
|
|
|
108
206
|
getLocale(e) {
|
|
109
207
|
if (e?.locale) return e.locale;
|
|
110
208
|
if (this.#e?.locale) return this.#e.locale;
|
|
111
|
-
let t = this.#e?.reducer?.engine.getFact(
|
|
112
|
-
return this.#e?.reducer?.addInterest(
|
|
209
|
+
let t = this.#e?.reducer?.engine.getFact(_)?.value;
|
|
210
|
+
return this.#e?.reducer?.addInterest(f(_)), typeof t == "string" ? t : void 0;
|
|
113
211
|
}
|
|
114
212
|
getFormat(e) {
|
|
115
213
|
return new Intl.NumberFormat(this.getLocale(e));
|
|
116
214
|
}
|
|
117
215
|
format(e, t) {
|
|
118
216
|
switch (t?.type) {
|
|
119
|
-
default: return
|
|
217
|
+
default: return y(this.getFormat(t).format(e), t);
|
|
120
218
|
}
|
|
121
219
|
}
|
|
122
220
|
};
|
|
123
|
-
function
|
|
221
|
+
function y(e, t) {
|
|
124
222
|
let n;
|
|
125
223
|
if (n = typeof t?.unit == "string" ? t.unit : t?.unit?.value, !n) return e;
|
|
126
224
|
let r;
|
|
@@ -138,4 +236,4 @@ function m(e, t) {
|
|
|
138
236
|
}
|
|
139
237
|
}
|
|
140
238
|
//#endregion
|
|
141
|
-
export {
|
|
239
|
+
export { p as DashboardEngine, m as DashboardEventTarget, h as DashboardStateConsumer, g as DashboardStateReducer, v as NumberFormatter, f as dashboardFactInterest, _ as dashboardLocaleFact, d as dashboardVarInterest };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rotorjs/dashboard",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Rotor",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Aaron Burmeister"
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"vite": "^8.0.16"
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
|
-
"@rotorjs/state": "^0.
|
|
66
|
+
"@rotorjs/state": "^0.7.0",
|
|
67
67
|
"fast-deep-equal": "^3.1.3",
|
|
68
68
|
"uuid": "^14.0.0"
|
|
69
69
|
}
|