chore: import upstream snapshot with attribution
CI / build (push) Has been cancelled

This commit is contained in:
wehub-resource-sync
2026-07-13 13:09:51 +08:00
commit 0232b4e2bb
3528 changed files with 291404 additions and 0 deletions
@@ -0,0 +1,11 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
const { defineFlatConfig } = require('@flowgram.ai/eslint-config');
module.exports = defineFlatConfig({
preset: 'web',
packageRoot: __dirname,
});
@@ -0,0 +1,47 @@
{
"name": "@flowgram.ai/redux-devtool-plugin",
"version": "0.1.8",
"homepage": "https://flowgram.ai/",
"repository": "https://github.com/bytedance/flowgram.ai",
"license": "MIT",
"exports": {
"types": "./dist/index.d.ts",
"import": "./dist/esm/index.js",
"require": "./dist/index.js"
},
"main": "./dist/index.js",
"module": "./dist/esm/index.js",
"types": "./dist/index.d.ts",
"files": [
"dist"
],
"scripts": {
"build": "npm run build:fast -- --dts-resolve",
"build:fast": "tsup src/index.ts --format cjs,esm --sourcemap --legacy-output",
"build:watch": "npm run build:fast -- --dts-resolve",
"clean": "rimraf dist",
"test": "exit 0",
"test:cov": "exit 0",
"ts-check": "tsc --noEmit",
"watch": "npm run build:fast -- --dts-resolve --watch --ignore-watch dist"
},
"dependencies": {
"@flowgram.ai/core": "workspace:*",
"@flowgram.ai/variable-core": "workspace:*",
"inversify": "^6.0.1",
"reflect-metadata": "~0.2.2"
},
"devDependencies": {
"@flowgram.ai/eslint-config": "workspace:*",
"@flowgram.ai/ts-config": "workspace:*",
"@vitest/coverage-v8": "^3.2.4",
"eslint": "^9.0.0",
"tsup": "^8.0.1",
"typescript": "^5.8.3",
"vitest": "^3.2.4"
},
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org/"
}
}
@@ -0,0 +1,46 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
import { injectable, postConstruct } from 'inversify';
/**
* 参考:https://github.com/zalmoxisus/redux-devtools-extension/blob/master/docs/API/Methods.md
*/
@injectable()
export abstract class BaseConnector {
devTools;
abstract getName(): string;
abstract getState(): any;
abstract onInit(): any;
constructor() {
this.devTools = (window as any).__REDUX_DEVTOOLS_EXTENSION__?.connect({
name: this.getName(),
});
}
@postConstruct()
init() {
if (this.devTools) {
this.devTools.init(this.getState());
this.devTools.subscribe((_msg: any) => {
// COMMIT 清空数据
if (_msg?.payload?.type === 'COMMIT') {
this.devTools.init(this.getState());
}
});
this.onInit();
}
}
protected send(action: any, state?: any) {
if (this.devTools) {
this.devTools.send(action, state || this.getState());
}
}
}
@@ -0,0 +1,28 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
import { inject, injectable } from 'inversify';
import { EntityManager } from '@flowgram.ai/core';
import { BaseConnector } from './base';
@injectable()
export class ECSConnector extends BaseConnector {
@inject(EntityManager) protected entityManager: EntityManager;
getName(): string {
return '@flowgram.ai/EntityManager';
}
getState() {
return this.entityManager.storeState({ configOnly: false });
}
onInit() {
this.entityManager.onEntityLifeCycleChange(action => {
this.send(`${action.type}/${action.entity.type}/${action.entity.id}`);
});
}
}
@@ -0,0 +1,7 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
export { ECSConnector } from './ecs-connector';
export { VariableConnector } from './variable-connector';
@@ -0,0 +1,52 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
import { inject, injectable } from 'inversify';
import { Scope, VariableEngine } from '@flowgram.ai/variable-core';
import { BaseConnector } from './base';
@injectable()
export class VariableConnector extends BaseConnector {
@inject(VariableEngine) protected variableEngine: VariableEngine;
/**
* 缓存变量状态
*/
scopes: Record<string, any> = {};
getName(): string {
return '@flowgram.ai/VariableEngine';
}
getState() {
return { scopes: this.scopes, variables: this.variableEngine.globalVariableTable.variables };
}
getScopeState(scope: Scope) {
return {
ast: scope?.ast.toJSON(),
output: scope.output.variables,
available: scope.available.variables,
};
}
onInit() {
this.variableEngine.onScopeChange((action) => {
const { scope, type } = action;
if (type === 'delete') {
delete this.scopes[String(scope.id)];
} else {
this.scopes = {
...this.scopes,
[scope.id]: this.getScopeState(scope),
};
}
this.send(`${type}/${String(scope.id)}`);
});
}
}
@@ -0,0 +1,42 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
import { definePluginCreator } from '@flowgram.ai/core';
import { ECSConnector, VariableConnector } from './connectors';
export interface ReduxDevToolPluginOptions {
enable?: boolean;
// 需要监听的内容
ecs?: boolean;
variable?: boolean;
}
export const createReduxDevToolPlugin = definePluginCreator<ReduxDevToolPluginOptions>({
onBind({ bind }, opts) {
const { enable } = opts;
if (!enable) {
return;
}
bind(ECSConnector).toSelf().inSingletonScope();
bind(VariableConnector).toSelf().inSingletonScope();
},
onInit(ctx, opts) {
const { enable, ecs = true, variable = false } = opts;
if (!enable) {
return;
}
if (ecs) {
ctx.get(ECSConnector);
}
if (variable) {
ctx.get(VariableConnector);
}
},
});
@@ -0,0 +1,7 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
export * from './create-redux-devtool-plugin';
export * from './connectors/ecs-connector';
@@ -0,0 +1,7 @@
{
"extends": "@flowgram.ai/ts-config/tsconfig.flow.path.json",
"compilerOptions": {
},
"include": ["./src"],
"exclude": ["node_modules"]
}
@@ -0,0 +1,31 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
const path = require('path');
import { defineConfig } from 'vitest/config';
export default defineConfig({
build: {
commonjsOptions: {
transformMixedEsModules: true,
},
},
test: {
globals: true,
mockReset: false,
environment: 'jsdom',
setupFiles: [path.resolve(__dirname, './vitest.setup.ts')],
include: ['**/?(*.){test,spec}.?(c|m)[jt]s?(x)'],
exclude: [
'**/__mocks__**',
'**/node_modules/**',
'**/dist/**',
'**/lib/**', // lib 编译结果忽略掉
'**/cypress/**',
'**/.{idea,git,cache,output,temp}/**',
'**/{karma,rollup,webpack,vite,vitest,jest,ava,babel,nyc,cypress,tsup,build}.config.*',
],
},
});
@@ -0,0 +1,6 @@
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
import 'reflect-metadata';