@flowgram.ai/redux-devtool-plugin 0.1.1
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.
- package/dist/esm/index.js +145 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/index.d.mts +31 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.js +170 -0
- package/dist/index.js.map +1 -0
- package/package.json +45 -0
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
4
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
5
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
6
|
+
if (decorator = decorators[i])
|
|
7
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
8
|
+
if (kind && result) __defProp(target, key, result);
|
|
9
|
+
return result;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
// src/create-redux-devtool-plugin.ts
|
|
13
|
+
import { definePluginCreator } from "@flowgram.ai/core";
|
|
14
|
+
|
|
15
|
+
// src/connectors/ecs-connector.ts
|
|
16
|
+
import { inject, injectable as injectable2 } from "inversify";
|
|
17
|
+
import { EntityManager } from "@flowgram.ai/core";
|
|
18
|
+
|
|
19
|
+
// src/connectors/base.ts
|
|
20
|
+
import { injectable, postConstruct } from "inversify";
|
|
21
|
+
var BaseConnector = class {
|
|
22
|
+
constructor() {
|
|
23
|
+
this.devTools = window.__REDUX_DEVTOOLS_EXTENSION__?.connect({
|
|
24
|
+
name: this.getName()
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
init() {
|
|
28
|
+
if (this.devTools) {
|
|
29
|
+
this.devTools.init(this.getState());
|
|
30
|
+
this.devTools.subscribe((_msg) => {
|
|
31
|
+
if (_msg?.payload?.type === "COMMIT") {
|
|
32
|
+
this.devTools.init(this.getState());
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
this.onInit();
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
send(action, state) {
|
|
39
|
+
if (this.devTools) {
|
|
40
|
+
this.devTools.send(action, state || this.getState());
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
__decorateClass([
|
|
45
|
+
postConstruct()
|
|
46
|
+
], BaseConnector.prototype, "init", 1);
|
|
47
|
+
BaseConnector = __decorateClass([
|
|
48
|
+
injectable()
|
|
49
|
+
], BaseConnector);
|
|
50
|
+
|
|
51
|
+
// src/connectors/ecs-connector.ts
|
|
52
|
+
var ECSConnector = class extends BaseConnector {
|
|
53
|
+
getName() {
|
|
54
|
+
return "@flowgram.ai/EntityManager";
|
|
55
|
+
}
|
|
56
|
+
getState() {
|
|
57
|
+
return this.entityManager.storeState({ configOnly: false });
|
|
58
|
+
}
|
|
59
|
+
onInit() {
|
|
60
|
+
this.entityManager.onEntityLifeCycleChange((action) => {
|
|
61
|
+
this.send(`${action.type}/${action.entity.type}/${action.entity.id}`);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
__decorateClass([
|
|
66
|
+
inject(EntityManager)
|
|
67
|
+
], ECSConnector.prototype, "entityManager", 2);
|
|
68
|
+
ECSConnector = __decorateClass([
|
|
69
|
+
injectable2()
|
|
70
|
+
], ECSConnector);
|
|
71
|
+
|
|
72
|
+
// src/connectors/variable-connector.ts
|
|
73
|
+
import { inject as inject2, injectable as injectable3 } from "inversify";
|
|
74
|
+
import { VariableEngine } from "@flowgram.ai/variable-core";
|
|
75
|
+
var VariableConnector = class extends BaseConnector {
|
|
76
|
+
constructor() {
|
|
77
|
+
super(...arguments);
|
|
78
|
+
/**
|
|
79
|
+
* 缓存变量状态
|
|
80
|
+
*/
|
|
81
|
+
this.scopes = {};
|
|
82
|
+
}
|
|
83
|
+
getName() {
|
|
84
|
+
return "@flowgram.ai/VariableEngine";
|
|
85
|
+
}
|
|
86
|
+
getState() {
|
|
87
|
+
return { scopes: this.scopes, variables: this.variableEngine.globalVariableTable.variables };
|
|
88
|
+
}
|
|
89
|
+
getScopeState(scope) {
|
|
90
|
+
return {
|
|
91
|
+
ast: scope?.ast.toJSON(),
|
|
92
|
+
output: scope.output.variables,
|
|
93
|
+
available: scope.available.variables
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
onInit() {
|
|
97
|
+
this.variableEngine.onScopeChange((action) => {
|
|
98
|
+
const { scope, type } = action;
|
|
99
|
+
if (type === "delete") {
|
|
100
|
+
delete this.scopes[scope.id];
|
|
101
|
+
} else {
|
|
102
|
+
this.scopes = {
|
|
103
|
+
...this.scopes,
|
|
104
|
+
[scope.id]: this.getScopeState(scope)
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
this.send(`${type}/${scope.id}`);
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
__decorateClass([
|
|
112
|
+
inject2(VariableEngine)
|
|
113
|
+
], VariableConnector.prototype, "variableEngine", 2);
|
|
114
|
+
VariableConnector = __decorateClass([
|
|
115
|
+
injectable3()
|
|
116
|
+
], VariableConnector);
|
|
117
|
+
|
|
118
|
+
// src/create-redux-devtool-plugin.ts
|
|
119
|
+
var createReduxDevToolPlugin = definePluginCreator({
|
|
120
|
+
onBind({ bind }, opts) {
|
|
121
|
+
const { enable } = opts;
|
|
122
|
+
if (!enable) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
bind(ECSConnector).toSelf().inSingletonScope();
|
|
126
|
+
bind(VariableConnector).toSelf().inSingletonScope();
|
|
127
|
+
},
|
|
128
|
+
onInit(ctx, opts) {
|
|
129
|
+
const { enable, ecs = true, variable = false } = opts;
|
|
130
|
+
if (!enable) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
if (ecs) {
|
|
134
|
+
ctx.get(ECSConnector);
|
|
135
|
+
}
|
|
136
|
+
if (variable) {
|
|
137
|
+
ctx.get(VariableConnector);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
export {
|
|
142
|
+
ECSConnector,
|
|
143
|
+
createReduxDevToolPlugin
|
|
144
|
+
};
|
|
145
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/create-redux-devtool-plugin.ts","../../src/connectors/ecs-connector.ts","../../src/connectors/base.ts","../../src/connectors/variable-connector.ts"],"sourcesContent":["import { definePluginCreator } from '@flowgram.ai/core';\n\nimport { ECSConnector, VariableConnector } from './connectors';\n\nexport interface ReduxDevToolPluginOptions {\n enable?: boolean;\n // 需要监听的内容\n ecs?: boolean;\n variable?: boolean;\n}\n\nexport const createReduxDevToolPlugin = definePluginCreator<ReduxDevToolPluginOptions>({\n onBind({ bind }, opts) {\n const { enable } = opts;\n if (!enable) {\n return;\n }\n\n bind(ECSConnector).toSelf().inSingletonScope();\n\n bind(VariableConnector).toSelf().inSingletonScope();\n },\n onInit(ctx, opts) {\n const { enable, ecs = true, variable = false } = opts;\n if (!enable) {\n return;\n }\n\n if (ecs) {\n ctx.get(ECSConnector);\n }\n\n if (variable) {\n ctx.get(VariableConnector);\n }\n },\n});\n","import { inject, injectable } from 'inversify';\nimport { EntityManager } from '@flowgram.ai/core';\n\nimport { BaseConnector } from './base';\n\n@injectable()\nexport class ECSConnector extends BaseConnector {\n @inject(EntityManager) protected entityManager: EntityManager;\n\n getName(): string {\n return '@flowgram.ai/EntityManager';\n }\n\n getState() {\n return this.entityManager.storeState({ configOnly: false });\n }\n\n onInit() {\n this.entityManager.onEntityLifeCycleChange(action => {\n this.send(`${action.type}/${action.entity.type}/${action.entity.id}`);\n });\n }\n}\n","import { injectable, postConstruct } from 'inversify';\n\n/**\n * 参考:https://github.com/zalmoxisus/redux-devtools-extension/blob/master/docs/API/Methods.md\n */\n@injectable()\nexport abstract class BaseConnector {\n devTools;\n\n abstract getName(): string;\n\n abstract getState(): any;\n\n abstract onInit(): any;\n\n constructor() {\n this.devTools = (window as any).__REDUX_DEVTOOLS_EXTENSION__?.connect({\n name: this.getName(),\n });\n }\n\n @postConstruct()\n init() {\n if (this.devTools) {\n this.devTools.init(this.getState());\n this.devTools.subscribe((_msg: any) => {\n // COMMIT 清空数据\n if (_msg?.payload?.type === 'COMMIT') {\n this.devTools.init(this.getState());\n }\n });\n this.onInit();\n }\n }\n\n protected send(action: any, state?: any) {\n if (this.devTools) {\n this.devTools.send(action, state || this.getState());\n }\n }\n}\n","import { inject, injectable } from 'inversify';\nimport { Scope, VariableEngine } from '@flowgram.ai/variable-core';\n\nimport { BaseConnector } from './base';\n\n@injectable()\nexport class VariableConnector extends BaseConnector {\n @inject(VariableEngine) protected variableEngine: VariableEngine;\n\n /**\n * 缓存变量状态\n */\n scopes: Record<string, any> = {};\n\n getName(): string {\n return '@flowgram.ai/VariableEngine';\n }\n\n getState() {\n return { scopes: this.scopes, variables: this.variableEngine.globalVariableTable.variables };\n }\n\n getScopeState(scope: Scope) {\n return {\n ast: scope?.ast.toJSON(),\n output: scope.output.variables,\n available: scope.available.variables,\n };\n }\n\n onInit() {\n this.variableEngine.onScopeChange(action => {\n const { scope, type } = action;\n\n if (type === 'delete') {\n delete this.scopes[scope.id];\n } else {\n this.scopes = {\n ...this.scopes,\n [scope.id]: this.getScopeState(scope),\n };\n }\n\n this.send(`${type}/${scope.id}`);\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;AAAA,SAAS,2BAA2B;;;ACApC,SAAS,QAAQ,cAAAA,mBAAkB;AACnC,SAAS,qBAAqB;;;ACD9B,SAAS,YAAY,qBAAqB;AAMnC,IAAe,gBAAf,MAA6B;AAAA,EASlC,cAAc;AACZ,SAAK,WAAY,OAAe,8BAA8B,QAAQ;AAAA,MACpE,MAAM,KAAK,QAAQ;AAAA,IACrB,CAAC;AAAA,EACH;AAAA,EAGA,OAAO;AACL,QAAI,KAAK,UAAU;AAC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AAO,IAAI,OAAO;AAAA,MACvB,QAAQ,MAAM,OAAO;AAAA,MACrB,WAAW,MAAM,UAAU;AAAA,IAC7B;AAAA,EACF;AAAA,EAEA,SAAS;AACP,SAAK,eAAe,cAAc,YAAU;AAC1C,YAAM,EAAE,OAAO,KAAK,IAAI;AAExB,UAAI,SAAS,UAAU;AACrB,eAAO,KAAK,OAAO,MAAM,EAAE;AAAA,MAC7B,OAAO;AACL,aAAK,SAAS;AAAA,UACZ,GAAG,KAAK;AAAA,UACR,CAAC,MAAM,EAAE,GAAG,KAAK,cAAc,KAAK;AAAA,QACtC;AAAA,MACF;AAEA,WAAK,KAAK,GAAG,IAAI,IAAI,MAAM,EAAE,EAAE;AAAA,IACjC,CAAC;AAAA,EACH;AACF;AAvCoC;AAAA,EAAjCC,QAAO,cAAc;AAAA,GADX,kBACuB;AADvB,oBAAN;AAAA,EADNC,YAAW;AAAA,GACC;;;AHKN,IAAM,2BAA2B,oBAA+C;AAAA,EACrF,OAAO,EAAE,KAAK,GAAG,MAAM;AACrB,UAAM,EAAE,OAAO,IAAI;AACnB,QAAI,CAAC,QAAQ;AACX;AAAA,IACF;AAEA,SAAK,YAAY,EAAE,OAAO,EAAE,iBAAiB;AAE7C,SAAK,iBAAiB,EAAE,OAAO,EAAE,iBAAiB;AAAA,EACpD;AAAA,EACA,OAAO,KAAK,MAAM;AAChB,UAAM,EAAE,QAAQ,MAAM,MAAM,WAAW,MAAM,IAAI;AACjD,QAAI,CAAC,QAAQ;AACX;AAAA,IACF;AAEA,QAAI,KAAK;AACP,UAAI,IAAI,YAAY;AAAA,IACtB;AAEA,QAAI,UAAU;AACZ,UAAI,IAAI,iBAAiB;AAAA,IAC3B;AAAA,EACF;AACF,CAAC;","names":["injectable","injectable","inject","injectable","inject","injectable"]}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as _flowgram_ai_core from '@flowgram.ai/core';
|
|
2
|
+
import { EntityManager } from '@flowgram.ai/core';
|
|
3
|
+
|
|
4
|
+
interface ReduxDevToolPluginOptions {
|
|
5
|
+
enable?: boolean;
|
|
6
|
+
ecs?: boolean;
|
|
7
|
+
variable?: boolean;
|
|
8
|
+
}
|
|
9
|
+
declare const createReduxDevToolPlugin: _flowgram_ai_core.PluginCreator<ReduxDevToolPluginOptions>;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 参考:https://github.com/zalmoxisus/redux-devtools-extension/blob/master/docs/API/Methods.md
|
|
13
|
+
*/
|
|
14
|
+
declare abstract class BaseConnector {
|
|
15
|
+
devTools: any;
|
|
16
|
+
abstract getName(): string;
|
|
17
|
+
abstract getState(): any;
|
|
18
|
+
abstract onInit(): any;
|
|
19
|
+
constructor();
|
|
20
|
+
init(): void;
|
|
21
|
+
protected send(action: any, state?: any): void;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
declare class ECSConnector extends BaseConnector {
|
|
25
|
+
protected entityManager: EntityManager;
|
|
26
|
+
getName(): string;
|
|
27
|
+
getState(): _flowgram_ai_core.EntityJSON[];
|
|
28
|
+
onInit(): void;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export { ECSConnector, type ReduxDevToolPluginOptions, createReduxDevToolPlugin };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as _flowgram_ai_core from '@flowgram.ai/core';
|
|
2
|
+
import { EntityManager } from '@flowgram.ai/core';
|
|
3
|
+
|
|
4
|
+
interface ReduxDevToolPluginOptions {
|
|
5
|
+
enable?: boolean;
|
|
6
|
+
ecs?: boolean;
|
|
7
|
+
variable?: boolean;
|
|
8
|
+
}
|
|
9
|
+
declare const createReduxDevToolPlugin: _flowgram_ai_core.PluginCreator<ReduxDevToolPluginOptions>;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 参考:https://github.com/zalmoxisus/redux-devtools-extension/blob/master/docs/API/Methods.md
|
|
13
|
+
*/
|
|
14
|
+
declare abstract class BaseConnector {
|
|
15
|
+
devTools: any;
|
|
16
|
+
abstract getName(): string;
|
|
17
|
+
abstract getState(): any;
|
|
18
|
+
abstract onInit(): any;
|
|
19
|
+
constructor();
|
|
20
|
+
init(): void;
|
|
21
|
+
protected send(action: any, state?: any): void;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
declare class ECSConnector extends BaseConnector {
|
|
25
|
+
protected entityManager: EntityManager;
|
|
26
|
+
getName(): string;
|
|
27
|
+
getState(): _flowgram_ai_core.EntityJSON[];
|
|
28
|
+
onInit(): void;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export { ECSConnector, type ReduxDevToolPluginOptions, createReduxDevToolPlugin };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
20
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
21
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
22
|
+
if (decorator = decorators[i])
|
|
23
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
24
|
+
if (kind && result) __defProp(target, key, result);
|
|
25
|
+
return result;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
// src/index.ts
|
|
29
|
+
var src_exports = {};
|
|
30
|
+
__export(src_exports, {
|
|
31
|
+
ECSConnector: () => ECSConnector,
|
|
32
|
+
createReduxDevToolPlugin: () => createReduxDevToolPlugin
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(src_exports);
|
|
35
|
+
|
|
36
|
+
// src/create-redux-devtool-plugin.ts
|
|
37
|
+
var import_core2 = require("@flowgram.ai/core");
|
|
38
|
+
|
|
39
|
+
// src/connectors/ecs-connector.ts
|
|
40
|
+
var import_inversify2 = require("inversify");
|
|
41
|
+
var import_core = require("@flowgram.ai/core");
|
|
42
|
+
|
|
43
|
+
// src/connectors/base.ts
|
|
44
|
+
var import_inversify = require("inversify");
|
|
45
|
+
var BaseConnector = class {
|
|
46
|
+
constructor() {
|
|
47
|
+
this.devTools = window.__REDUX_DEVTOOLS_EXTENSION__?.connect({
|
|
48
|
+
name: this.getName()
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
init() {
|
|
52
|
+
if (this.devTools) {
|
|
53
|
+
this.devTools.init(this.getState());
|
|
54
|
+
this.devTools.subscribe((_msg) => {
|
|
55
|
+
if (_msg?.payload?.type === "COMMIT") {
|
|
56
|
+
this.devTools.init(this.getState());
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
this.onInit();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
send(action, state) {
|
|
63
|
+
if (this.devTools) {
|
|
64
|
+
this.devTools.send(action, state || this.getState());
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
__decorateClass([
|
|
69
|
+
(0, import_inversify.postConstruct)()
|
|
70
|
+
], BaseConnector.prototype, "init", 1);
|
|
71
|
+
BaseConnector = __decorateClass([
|
|
72
|
+
(0, import_inversify.injectable)()
|
|
73
|
+
], BaseConnector);
|
|
74
|
+
|
|
75
|
+
// src/connectors/ecs-connector.ts
|
|
76
|
+
var ECSConnector = class extends BaseConnector {
|
|
77
|
+
getName() {
|
|
78
|
+
return "@flowgram.ai/EntityManager";
|
|
79
|
+
}
|
|
80
|
+
getState() {
|
|
81
|
+
return this.entityManager.storeState({ configOnly: false });
|
|
82
|
+
}
|
|
83
|
+
onInit() {
|
|
84
|
+
this.entityManager.onEntityLifeCycleChange((action) => {
|
|
85
|
+
this.send(`${action.type}/${action.entity.type}/${action.entity.id}`);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
__decorateClass([
|
|
90
|
+
(0, import_inversify2.inject)(import_core.EntityManager)
|
|
91
|
+
], ECSConnector.prototype, "entityManager", 2);
|
|
92
|
+
ECSConnector = __decorateClass([
|
|
93
|
+
(0, import_inversify2.injectable)()
|
|
94
|
+
], ECSConnector);
|
|
95
|
+
|
|
96
|
+
// src/connectors/variable-connector.ts
|
|
97
|
+
var import_inversify3 = require("inversify");
|
|
98
|
+
var import_variable_core = require("@flowgram.ai/variable-core");
|
|
99
|
+
var VariableConnector = class extends BaseConnector {
|
|
100
|
+
constructor() {
|
|
101
|
+
super(...arguments);
|
|
102
|
+
/**
|
|
103
|
+
* 缓存变量状态
|
|
104
|
+
*/
|
|
105
|
+
this.scopes = {};
|
|
106
|
+
}
|
|
107
|
+
getName() {
|
|
108
|
+
return "@flowgram.ai/VariableEngine";
|
|
109
|
+
}
|
|
110
|
+
getState() {
|
|
111
|
+
return { scopes: this.scopes, variables: this.variableEngine.globalVariableTable.variables };
|
|
112
|
+
}
|
|
113
|
+
getScopeState(scope) {
|
|
114
|
+
return {
|
|
115
|
+
ast: scope?.ast.toJSON(),
|
|
116
|
+
output: scope.output.variables,
|
|
117
|
+
available: scope.available.variables
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
onInit() {
|
|
121
|
+
this.variableEngine.onScopeChange((action) => {
|
|
122
|
+
const { scope, type } = action;
|
|
123
|
+
if (type === "delete") {
|
|
124
|
+
delete this.scopes[scope.id];
|
|
125
|
+
} else {
|
|
126
|
+
this.scopes = {
|
|
127
|
+
...this.scopes,
|
|
128
|
+
[scope.id]: this.getScopeState(scope)
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
this.send(`${type}/${scope.id}`);
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
__decorateClass([
|
|
136
|
+
(0, import_inversify3.inject)(import_variable_core.VariableEngine)
|
|
137
|
+
], VariableConnector.prototype, "variableEngine", 2);
|
|
138
|
+
VariableConnector = __decorateClass([
|
|
139
|
+
(0, import_inversify3.injectable)()
|
|
140
|
+
], VariableConnector);
|
|
141
|
+
|
|
142
|
+
// src/create-redux-devtool-plugin.ts
|
|
143
|
+
var createReduxDevToolPlugin = (0, import_core2.definePluginCreator)({
|
|
144
|
+
onBind({ bind }, opts) {
|
|
145
|
+
const { enable } = opts;
|
|
146
|
+
if (!enable) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
bind(ECSConnector).toSelf().inSingletonScope();
|
|
150
|
+
bind(VariableConnector).toSelf().inSingletonScope();
|
|
151
|
+
},
|
|
152
|
+
onInit(ctx, opts) {
|
|
153
|
+
const { enable, ecs = true, variable = false } = opts;
|
|
154
|
+
if (!enable) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
if (ecs) {
|
|
158
|
+
ctx.get(ECSConnector);
|
|
159
|
+
}
|
|
160
|
+
if (variable) {
|
|
161
|
+
ctx.get(VariableConnector);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
166
|
+
0 && (module.exports = {
|
|
167
|
+
ECSConnector,
|
|
168
|
+
createReduxDevToolPlugin
|
|
169
|
+
});
|
|
170
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/create-redux-devtool-plugin.ts","../src/connectors/ecs-connector.ts","../src/connectors/base.ts","../src/connectors/variable-connector.ts"],"sourcesContent":["export * from './create-redux-devtool-plugin';\nexport * from './connectors/ecs-connector';\n","import { definePluginCreator } from '@flowgram.ai/core';\n\nimport { ECSConnector, VariableConnector } from './connectors';\n\nexport interface ReduxDevToolPluginOptions {\n enable?: boolean;\n // 需要监听的内容\n ecs?: boolean;\n variable?: boolean;\n}\n\nexport const createReduxDevToolPlugin = definePluginCreator<ReduxDevToolPluginOptions>({\n onBind({ bind }, opts) {\n const { enable } = opts;\n if (!enable) {\n return;\n }\n\n bind(ECSConnector).toSelf().inSingletonScope();\n\n bind(VariableConnector).toSelf().inSingletonScope();\n },\n onInit(ctx, opts) {\n const { enable, ecs = true, variable = false } = opts;\n if (!enable) {\n return;\n }\n\n if (ecs) {\n ctx.get(ECSConnector);\n }\n\n if (variable) {\n ctx.get(VariableConnector);\n }\n },\n});\n","import { inject, injectable } from 'inversify';\nimport { EntityManager } from '@flowgram.ai/core';\n\nimport { BaseConnector } from './base';\n\n@injectable()\nexport class ECSConnector extends BaseConnector {\n @inject(EntityManager) protected entityManager: EntityManager;\n\n getName(): string {\n return '@flowgram.ai/EntityManager';\n }\n\n getState() {\n return this.entityManager.storeState({ configOnly: false });\n }\n\n onInit() {\n this.entityManager.onEntityLifeCycleChange(action => {\n this.send(`${action.type}/${action.entity.type}/${action.entity.id}`);\n });\n }\n}\n","import { injectable, postConstruct } from 'inversify';\n\n/**\n * 参考:https://github.com/zalmoxisus/redux-devtools-extension/blob/master/docs/API/Methods.md\n */\n@injectable()\nexport abstract class BaseConnector {\n devTools;\n\n abstract getName(): string;\n\n abstract getState(): any;\n\n abstract onInit(): any;\n\n constructor() {\n this.devTools = (window as any).__REDUX_DEVTOOLS_EXTENSION__?.connect({\n name: this.getName(),\n });\n }\n\n @postConstruct()\n init() {\n if (this.devTools) {\n this.devTools.init(this.getState());\n this.devTools.subscribe((_msg: any) => {\n // COMMIT 清空数据\n if (_msg?.payload?.type === 'COMMIT') {\n this.devTools.init(this.getState());\n }\n });\n this.onInit();\n }\n }\n\n protected send(action: any, state?: any) {\n if (this.devTools) {\n this.devTools.send(action, state || this.getState());\n }\n }\n}\n","import { inject, injectable } from 'inversify';\nimport { Scope, VariableEngine } from '@flowgram.ai/variable-core';\n\nimport { BaseConnector } from './base';\n\n@injectable()\nexport class VariableConnector extends BaseConnector {\n @inject(VariableEngine) protected variableEngine: VariableEngine;\n\n /**\n * 缓存变量状态\n */\n scopes: Record<string, any> = {};\n\n getName(): string {\n return '@flowgram.ai/VariableEngine';\n }\n\n getState() {\n return { scopes: this.scopes, variables: this.variableEngine.globalVariableTable.variables };\n }\n\n getScopeState(scope: Scope) {\n return {\n ast: scope?.ast.toJSON(),\n output: scope.output.variables,\n available: scope.available.variables,\n };\n }\n\n onInit() {\n this.variableEngine.onScopeChange(action => {\n const { scope, type } = action;\n\n if (type === 'delete') {\n delete this.scopes[scope.id];\n } else {\n this.scopes = {\n ...this.scopes,\n [scope.id]: this.getScopeState(scope),\n };\n }\n\n this.send(`${type}/${scope.id}`);\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,eAAoC;;;ACApC,IAAAC,oBAAmC;AACnC,kBAA8B;;;ACD9B,uBAA0C;AAMnC,IAAe,gBAAf,MAA6B;AAAA,EASlC,cAAc;AACZ,SAAK,WAAY,OAAe,8BAA8B,QAAQ;AAAA,MACpE,MAAM,KAAK,QAAQ;AAAA,IACrB,CAAC;AAAA,EACH;AAAA,EAGA,OAAO;AACL,QAAI,KAAK,UAAU;AACjB,WAAK,SAAS,KAAK,KAAK,SAAS,CAAC;AAClC,WAAK,SAAS,UAAU,CAAC,SAAc;AAErC,YAAI,MAAM,S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S;AACP,SAAK,eAAe,cAAc,YAAU;AAC1C,YAAM,EAAE,OAAO,KAAK,IAAI;AAExB,UAAI,SAAS,UAAU;AACrB,eAAO,KAAK,OAAO,MAAM,EAAE;AAAA,MAC7B,OAAO;AACL,aAAK,SAAS;AAAA,UACZ,GAAG,KAAK;AAAA,UACR,CAAC,MAAM,EAAE,GAAG,KAAK,cAAc,KAAK;AAAA,QACtC;AAAA,MACF;AAEA,WAAK,KAAK,GAAG,IAAI,IAAI,MAAM,EAAE,EAAE;AAAA,IACjC,CAAC;AAAA,EACH;AACF;AAvCoC;AAAA,MAAjC,0BAAO,mCAAc;AAAA,GADX,kBACuB;AADvB,oBAAN;AAAA,MADN,8BAAW;AAAA,GACC;;;AHKN,IAAM,+BAA2B,kCAA+C;AAAA,EACrF,OAAO,EAAE,KAAK,GAAG,MAAM;AACrB,UAAM,EAAE,OAAO,IAAI;AACnB,QAAI,CAAC,QAAQ;AACX;AAAA,IACF;AAEA,SAAK,YAAY,EAAE,OAAO,EAAE,iBAAiB;AAE7C,SAAK,iBAAiB,EAAE,OAAO,EAAE,iBAAiB;AAAA,EACpD;AAAA,EACA,OAAO,KAAK,MAAM;AAChB,UAAM,EAAE,QAAQ,MAAM,MAAM,WAAW,MAAM,IAAI;AACjD,QAAI,CAAC,QAAQ;AACX;AAAA,IACF;AAEA,QAAI,KAAK;AACP,UAAI,IAAI,YAAY;AAAA,IACtB;AAEA,QAAI,UAAU;AACZ,UAAI,IAAI,iBAAiB;AAAA,IAC3B;AAAA,EACF;AACF,CAAC;","names":["import_core","import_inversify","import_inversify"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@flowgram.ai/redux-devtool-plugin",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"exports": {
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"import": "./dist/esm/index.js",
|
|
8
|
+
"require": "./dist/index.js"
|
|
9
|
+
},
|
|
10
|
+
"main": "./dist/index.js",
|
|
11
|
+
"module": "./dist/esm/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"inversify": "^6.0.1",
|
|
18
|
+
"styled-components": "^5",
|
|
19
|
+
"@flowgram.ai/core": "0.1.1",
|
|
20
|
+
"@flowgram.ai/variable-core": "0.1.1"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@vitest/coverage-v8": "^0.32.0",
|
|
24
|
+
"eslint": "^8.54.0",
|
|
25
|
+
"tsup": "^8.0.1",
|
|
26
|
+
"typescript": "^5.0.4",
|
|
27
|
+
"vitest": "^0.34.6",
|
|
28
|
+
"@flowgram.ai/ts-config": "0.1.1",
|
|
29
|
+
"@flowgram.ai/eslint-config": "0.1.1"
|
|
30
|
+
},
|
|
31
|
+
"publishConfig": {
|
|
32
|
+
"access": "public",
|
|
33
|
+
"registry": "https://registry.npmjs.org/"
|
|
34
|
+
},
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "npm run build:fast -- --dts-resolve",
|
|
37
|
+
"build:fast": "tsup src/index.ts --format cjs,esm --sourcemap --legacy-output",
|
|
38
|
+
"build:watch": "npm run build:fast -- --dts-resolve",
|
|
39
|
+
"clean": "rimraf dist",
|
|
40
|
+
"test": "exit 0",
|
|
41
|
+
"test:cov": "exit 0",
|
|
42
|
+
"ts-check": "tsc --noEmit",
|
|
43
|
+
"watch": "npm run build:fast -- --dts-resolve --watch --ignore-watch dist"
|
|
44
|
+
}
|
|
45
|
+
}
|