mirror of
https://gitee.com/ByteDance/flowgram.ai.git
synced 2025-07-07 17:43:29 +08:00
chore: add variable api
This commit is contained in:
parent
613351c770
commit
1b2c0ea06e
@ -1,6 +1,8 @@
|
||||
{
|
||||
"name": "@flowgram.ai/core",
|
||||
"version": "0.1.0",
|
||||
"homepage": "https://coze-dev.github.io/flowgram.ai/",
|
||||
"repository": "https://github.com/coze-dev/flowgram.ai",
|
||||
"license": "MIT",
|
||||
"exports": {
|
||||
"types": "./dist/index.d.ts",
|
||||
|
||||
@ -6,7 +6,8 @@
|
||||
"flow",
|
||||
"engine"
|
||||
],
|
||||
"homepage": "",
|
||||
"homepage": "https://coze-dev.github.io/flowgram.ai/",
|
||||
"repository": "https://github.com/coze-dev/flowgram.ai",
|
||||
"license": "MIT",
|
||||
"exports": {
|
||||
"types": "./dist/index.d.ts",
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
{
|
||||
"name": "@flowgram.ai/fixed-layout-core",
|
||||
"version": "0.1.0",
|
||||
"homepage": "https://coze-dev.github.io/flowgram.ai/",
|
||||
"repository": "https://github.com/coze-dev/flowgram.ai",
|
||||
"license": "MIT",
|
||||
"exports": {
|
||||
"types": "./dist/index.d.ts",
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
{
|
||||
"name": "@flowgram.ai/free-layout-core",
|
||||
"version": "0.1.0",
|
||||
"homepage": "https://coze-dev.github.io/flowgram.ai/",
|
||||
"repository": "https://github.com/coze-dev/flowgram.ai",
|
||||
"license": "MIT",
|
||||
"exports": {
|
||||
".": {
|
||||
|
||||
@ -8,7 +8,6 @@ export default defineConfig({
|
||||
},
|
||||
},
|
||||
test: {
|
||||
testTimeout: 30000,
|
||||
globals: true,
|
||||
mockReset: false,
|
||||
environment: 'jsdom',
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
{
|
||||
"name": "@flowgram.ai/renderer",
|
||||
"version": "0.1.0",
|
||||
"homepage": "https://coze-dev.github.io/flowgram.ai/",
|
||||
"repository": "https://github.com/coze-dev/flowgram.ai",
|
||||
"license": "MIT",
|
||||
"exports": {
|
||||
"types": "./dist/index.d.ts",
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
{
|
||||
"name": "@flowgram.ai/editor",
|
||||
"version": "0.1.0",
|
||||
"homepage": "https://coze-dev.github.io/flowgram.ai/",
|
||||
"repository": "https://github.com/coze-dev/flowgram.ai",
|
||||
"license": "MIT",
|
||||
"exports": {
|
||||
"types": "./dist/index.d.ts",
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
{
|
||||
"name": "@flowgram.ai/fixed-layout-editor",
|
||||
"version": "0.1.0",
|
||||
"homepage": "https://coze-dev.github.io/flowgram.ai/",
|
||||
"repository": "https://github.com/coze-dev/flowgram.ai",
|
||||
"license": "MIT",
|
||||
"exports": {
|
||||
".": {
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
{
|
||||
"name": "@flowgram.ai/free-layout-editor",
|
||||
"version": "0.1.0",
|
||||
"homepage": "https://coze-dev.github.io/flowgram.ai/",
|
||||
"repository": "https://github.com/coze-dev/flowgram.ai",
|
||||
"license": "MIT",
|
||||
"exports": {
|
||||
".": {
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
{
|
||||
"name": "@flowgram.ai/playground-react",
|
||||
"version": "0.1.0",
|
||||
"homepage": "https://coze-dev.github.io/flowgram.ai/",
|
||||
"repository": "https://github.com/coze-dev/flowgram.ai",
|
||||
"license": "MIT",
|
||||
"exports": {
|
||||
".": {
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
{
|
||||
"name": "@flowgram.ai/command",
|
||||
"version": "0.1.0",
|
||||
"homepage": "https://coze-dev.github.io/flowgram.ai/",
|
||||
"repository": "https://github.com/coze-dev/flowgram.ai",
|
||||
"license": "MIT",
|
||||
"exports": {
|
||||
"types": "./dist/index.d.ts",
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
{
|
||||
"name": "@flowgram.ai/history-storage",
|
||||
"version": "0.1.0",
|
||||
"homepage": "https://coze-dev.github.io/flowgram.ai/",
|
||||
"repository": "https://github.com/coze-dev/flowgram.ai",
|
||||
"license": "MIT",
|
||||
"exports": {
|
||||
"types": "./dist/index.d.ts",
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
{
|
||||
"name": "@flowgram.ai/history",
|
||||
"version": "0.1.0",
|
||||
"homepage": "https://coze-dev.github.io/flowgram.ai/",
|
||||
"repository": "https://github.com/coze-dev/flowgram.ai",
|
||||
"license": "MIT",
|
||||
"exports": {
|
||||
"types": "./dist/index.d.ts",
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
{
|
||||
"name": "@flowgram.ai/i18n",
|
||||
"version": "0.1.0",
|
||||
"homepage": "https://coze-dev.github.io/flowgram.ai/",
|
||||
"repository": "https://github.com/coze-dev/flowgram.ai",
|
||||
"license": "MIT",
|
||||
"exports": {
|
||||
"types": "./dist/index.d.ts",
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
{
|
||||
"name": "@flowgram.ai/reactive",
|
||||
"version": "0.1.0",
|
||||
"homepage": "https://coze-dev.github.io/flowgram.ai/",
|
||||
"repository": "https://github.com/coze-dev/flowgram.ai",
|
||||
"license": "MIT",
|
||||
"exports": {
|
||||
"types": "./dist/index.d.ts",
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
{
|
||||
"name": "@flowgram.ai/utils",
|
||||
"version": "0.1.0",
|
||||
"homepage": "https://coze-dev.github.io/flowgram.ai/",
|
||||
"repository": "https://github.com/coze-dev/flowgram.ai",
|
||||
"license": "MIT",
|
||||
"exports": {
|
||||
"types": "./dist/index.d.ts",
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
{
|
||||
"name": "@flowgram.ai/fixed-semi-materials",
|
||||
"version": "0.1.0",
|
||||
"homepage": "https://coze-dev.github.io/flowgram.ai/",
|
||||
"repository": "https://github.com/coze-dev/flowgram.ai",
|
||||
"license": "MIT",
|
||||
"exports": {
|
||||
"types": "./dist/index.d.ts",
|
||||
|
||||
@ -6,7 +6,8 @@
|
||||
"flow",
|
||||
"engine"
|
||||
],
|
||||
"homepage": "",
|
||||
"homepage": "https://coze-dev.github.io/flowgram.ai/",
|
||||
"repository": "https://github.com/coze-dev/flowgram.ai",
|
||||
"license": "MIT",
|
||||
"exports": {
|
||||
"types": "./dist/index.d.ts",
|
||||
|
||||
@ -1,9 +1,10 @@
|
||||
import { mapValues } from 'lodash';
|
||||
import { inject, injectable, multiInject, optional, postConstruct } from 'inversify';
|
||||
import { Emitter } from '@flowgram.ai/utils';
|
||||
import { injectPlaygroundContext, PlaygroundContext } from '@flowgram.ai/core';
|
||||
|
||||
import { AbilityClass, FormItemAbility } from '../models/form-item-ability';
|
||||
import { FormAbilityExtensionRegistry } from '../models';
|
||||
import { FormAbilityExtensionRegistry, FormModel } from '../models';
|
||||
import { FormContribution } from '../form-contribution';
|
||||
import {
|
||||
DecoratorAbility,
|
||||
@ -30,6 +31,13 @@ export class FormManager {
|
||||
|
||||
@multiInject(FormContribution) @optional() protected formContributions: FormContribution[] = [];
|
||||
|
||||
private readonly onFormModelWillInitEmitter = new Emitter<{
|
||||
model: FormModel;
|
||||
data: any;
|
||||
}>();
|
||||
|
||||
readonly onFormModelWillInit = this.onFormModelWillInitEmitter.event;
|
||||
|
||||
get components(): Record<string, any> {
|
||||
return mapValues(
|
||||
this.extensionRegistryMap.get(SetterAbility.type)?.objectMap || {},
|
||||
@ -81,6 +89,17 @@ export class FormManager {
|
||||
this.setterHocs.push(hoc);
|
||||
}
|
||||
|
||||
fireFormModelWillInit(model: FormModel, data: any) {
|
||||
this.onFormModelWillInitEmitter.fire({
|
||||
model,
|
||||
data,
|
||||
});
|
||||
}
|
||||
|
||||
dispose() {
|
||||
this.onFormModelWillInitEmitter.dispose();
|
||||
}
|
||||
|
||||
@postConstruct()
|
||||
protected init(): void {
|
||||
this.formContributions.forEach((contrib) => contrib.onRegister?.(this));
|
||||
|
||||
@ -6,7 +6,8 @@
|
||||
"flow",
|
||||
"engine"
|
||||
],
|
||||
"homepage": "",
|
||||
"homepage": "https://coze-dev.github.io/flowgram.ai/",
|
||||
"repository": "https://github.com/coze-dev/flowgram.ai",
|
||||
"license": "MIT",
|
||||
"exports": {
|
||||
"types": "./dist/index.d.ts",
|
||||
|
||||
@ -6,7 +6,8 @@
|
||||
"flow",
|
||||
"engine"
|
||||
],
|
||||
"homepage": "",
|
||||
"homepage": "https://coze-dev.github.io/flowgram.ai/",
|
||||
"repository": "https://github.com/coze-dev/flowgram.ai",
|
||||
"license": "MIT",
|
||||
"exports": {
|
||||
"types": "./dist/index.d.ts",
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
{
|
||||
"name": "@flowgram.ai/background-plugin",
|
||||
"version": "0.1.0",
|
||||
"homepage": "https://coze-dev.github.io/flowgram.ai/",
|
||||
"repository": "https://github.com/coze-dev/flowgram.ai",
|
||||
"license": "MIT",
|
||||
"exports": {
|
||||
"types": "./dist/index.d.ts",
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
{
|
||||
"name": "@flowgram.ai/fixed-drag-plugin",
|
||||
"version": "0.1.0",
|
||||
"homepage": "https://coze-dev.github.io/flowgram.ai/",
|
||||
"repository": "https://github.com/coze-dev/flowgram.ai",
|
||||
"license": "MIT",
|
||||
"exports": {
|
||||
"types": "./dist/index.d.ts",
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
{
|
||||
"name": "@flowgram.ai/fixed-history-plugin",
|
||||
"version": "0.1.0",
|
||||
"homepage": "https://coze-dev.github.io/flowgram.ai/",
|
||||
"repository": "https://github.com/coze-dev/flowgram.ai",
|
||||
"license": "MIT",
|
||||
"exports": {
|
||||
"types": "./dist/index.d.ts",
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
{
|
||||
"name": "@flowgram.ai/fixed-reactor-plugin",
|
||||
"version": "0.1.0",
|
||||
"homepage": "https://coze-dev.github.io/flowgram.ai/",
|
||||
"repository": "https://github.com/coze-dev/flowgram.ai",
|
||||
"license": "MIT",
|
||||
"exports": {
|
||||
"types": "./dist/index.d.ts",
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
{
|
||||
"name": "@flowgram.ai/free-auto-layout-plugin",
|
||||
"version": "0.1.0",
|
||||
"homepage": "https://coze-dev.github.io/flowgram.ai/",
|
||||
"repository": "https://github.com/coze-dev/flowgram.ai",
|
||||
"license": "MIT",
|
||||
"exports": {
|
||||
"import": "./dist/esm/index.js",
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
{
|
||||
"name": "@flowgram.ai/free-history-plugin",
|
||||
"version": "0.1.0",
|
||||
"homepage": "https://coze-dev.github.io/flowgram.ai/",
|
||||
"repository": "https://github.com/coze-dev/flowgram.ai",
|
||||
"license": "MIT",
|
||||
"exports": {
|
||||
"types": "./dist/index.d.ts",
|
||||
|
||||
@ -1,15 +1,16 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import { cloneDeep } from 'lodash';
|
||||
import { injectable, inject } from 'inversify';
|
||||
import { FlowNodeFormData } from '@flowgram.ai/form-core';
|
||||
import { type PluginContext, PositionData } from '@flowgram.ai/core';
|
||||
import { DisposableCollection } from '@flowgram.ai/utils';
|
||||
import { HistoryService } from '@flowgram.ai/history';
|
||||
import {
|
||||
WorkflowDocument,
|
||||
WorkflowResetLayoutService,
|
||||
WorkflowDragService,
|
||||
} from '@flowgram.ai/free-layout-core';
|
||||
import { DisposableCollection } from '@flowgram.ai/utils';
|
||||
import { HistoryService } from '@flowgram.ai/history';
|
||||
import { FlowNodeFormData } from '@flowgram.ai/form-core';
|
||||
import { FormManager } from '@flowgram.ai/form-core';
|
||||
import { type PluginContext, PositionData } from '@flowgram.ai/core';
|
||||
|
||||
import { type FreeHistoryPluginOptions, FreeOperationType } from './types';
|
||||
import { HistoryEntityManager } from './history-entity-manager';
|
||||
@ -34,6 +35,9 @@ export class FreeHistoryManager {
|
||||
@inject(HistoryEntityManager)
|
||||
private _entityManager: HistoryEntityManager;
|
||||
|
||||
@inject(FormManager)
|
||||
private _formManager: FormManager;
|
||||
|
||||
private _toDispose: DisposableCollection = new DisposableCollection();
|
||||
|
||||
onInit(ctx: PluginContext, opts: FreeHistoryPluginOptions) {
|
||||
@ -49,7 +53,7 @@ export class FreeHistoryManager {
|
||||
historyService.context.source = ctx;
|
||||
|
||||
this._toDispose.pushAll([
|
||||
dragService.onNodesDrag(async event => {
|
||||
dragService.onNodesDrag(async (event) => {
|
||||
if (event.type !== 'onDragEnd') {
|
||||
return;
|
||||
}
|
||||
@ -60,28 +64,31 @@ export class FreeHistoryManager {
|
||||
if (positionData) {
|
||||
this._entityManager.addEntityData(positionData);
|
||||
}
|
||||
}),
|
||||
this._formManager.onFormModelWillInit(({ model, data }) => {
|
||||
const node = model.flowNodeEntity;
|
||||
const formData = node.getData<FlowNodeFormData>(FlowNodeFormData);
|
||||
|
||||
if (formData) {
|
||||
this._entityManager.setValue(formData, cloneDeep(data.data));
|
||||
this._entityManager.setValue(formData, cloneDeep(data));
|
||||
|
||||
this._toDispose.push(
|
||||
formData.onDetailChange(event => {
|
||||
formData.onDetailChange((event) => {
|
||||
this._changeNodeDataHandler.handle({
|
||||
...event,
|
||||
node,
|
||||
});
|
||||
}),
|
||||
})
|
||||
);
|
||||
}
|
||||
}),
|
||||
document.onContentChange(async event => {
|
||||
document.onContentChange(async (event) => {
|
||||
await this._changeContentHandler.handle(event, ctx);
|
||||
}),
|
||||
document.onReload(_event => {
|
||||
document.onReload((_event) => {
|
||||
historyService.clear();
|
||||
}),
|
||||
resetLayoutService.onResetLayout(event => {
|
||||
resetLayoutService.onResetLayout((event) => {
|
||||
historyService.pushOperation(
|
||||
{
|
||||
type: FreeOperationType.resetLayout,
|
||||
@ -91,7 +98,7 @@ export class FreeHistoryManager {
|
||||
oldValue: event.oldPositionMap,
|
||||
},
|
||||
},
|
||||
{ noApply: true },
|
||||
{ noApply: true }
|
||||
);
|
||||
}),
|
||||
]);
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
{
|
||||
"name": "@flowgram.ai/free-hover-plugin",
|
||||
"version": "0.1.0",
|
||||
"homepage": "https://coze-dev.github.io/flowgram.ai/",
|
||||
"repository": "https://github.com/coze-dev/flowgram.ai",
|
||||
"license": "MIT",
|
||||
"exports": {
|
||||
"types": "./dist/index.d.ts",
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
{
|
||||
"name": "@flowgram.ai/free-lines-plugin",
|
||||
"version": "0.1.0",
|
||||
"homepage": "https://coze-dev.github.io/flowgram.ai/",
|
||||
"repository": "https://github.com/coze-dev/flowgram.ai",
|
||||
"license": "MIT",
|
||||
"exports": {
|
||||
"types": "./dist/index.d.ts",
|
||||
@ -59,4 +61,4 @@
|
||||
"access": "public",
|
||||
"registry": "https://registry.npmjs.org/"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,8 @@
|
||||
{
|
||||
"name": "@flowgram.ai/free-node-panel-plugin",
|
||||
"version": "0.1.0",
|
||||
"homepage": "https://coze-dev.github.io/flowgram.ai/",
|
||||
"repository": "https://github.com/coze-dev/flowgram.ai",
|
||||
"license": "MIT",
|
||||
"exports": {
|
||||
"import": "./dist/esm/index.js",
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
{
|
||||
"name": "@flowgram.ai/free-snap-plugin",
|
||||
"version": "0.1.0",
|
||||
"homepage": "https://coze-dev.github.io/flowgram.ai/",
|
||||
"repository": "https://github.com/coze-dev/flowgram.ai",
|
||||
"license": "MIT",
|
||||
"exports": {
|
||||
"import": "./dist/esm/index.js",
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
{
|
||||
"name": "@flowgram.ai/free-stack-plugin",
|
||||
"version": "0.1.0",
|
||||
"homepage": "https://coze-dev.github.io/flowgram.ai/",
|
||||
"repository": "https://github.com/coze-dev/flowgram.ai",
|
||||
"license": "MIT",
|
||||
"exports": {
|
||||
"import": "./dist/esm/index.js",
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
{
|
||||
"name": "@flowgram.ai/group-plugin",
|
||||
"version": "0.1.0",
|
||||
"homepage": "https://coze-dev.github.io/flowgram.ai/",
|
||||
"repository": "https://github.com/coze-dev/flowgram.ai",
|
||||
"license": "MIT",
|
||||
"exports": {
|
||||
"types": "./dist/index.d.ts",
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
{
|
||||
"name": "@flowgram.ai/history-node-plugin",
|
||||
"version": "0.1.0",
|
||||
"homepage": "https://coze-dev.github.io/flowgram.ai/",
|
||||
"repository": "https://github.com/coze-dev/flowgram.ai",
|
||||
"license": "MIT",
|
||||
"exports": {
|
||||
"types": "./dist/index.d.ts",
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
{
|
||||
"name": "@flowgram.ai/i18n-plugin",
|
||||
"version": "0.1.0",
|
||||
"homepage": "https://coze-dev.github.io/flowgram.ai/",
|
||||
"repository": "https://github.com/coze-dev/flowgram.ai",
|
||||
"license": "MIT",
|
||||
"exports": {
|
||||
"types": "./dist/index.d.ts",
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
{
|
||||
"name": "@flowgram.ai/materials-plugin",
|
||||
"version": "0.1.0",
|
||||
"homepage": "https://coze-dev.github.io/flowgram.ai/",
|
||||
"repository": "https://github.com/coze-dev/flowgram.ai",
|
||||
"license": "MIT",
|
||||
"exports": {
|
||||
"types": "./dist/index.d.ts",
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
{
|
||||
"name": "@flowgram.ai/minimap-plugin",
|
||||
"version": "0.1.0",
|
||||
"homepage": "https://coze-dev.github.io/flowgram.ai/",
|
||||
"repository": "https://github.com/coze-dev/flowgram.ai",
|
||||
"license": "MIT",
|
||||
"exports": {
|
||||
"import": "./dist/esm/index.js",
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
{
|
||||
"name": "@flowgram.ai/node-core-plugin",
|
||||
"version": "0.1.0",
|
||||
"homepage": "https://coze-dev.github.io/flowgram.ai/",
|
||||
"repository": "https://github.com/coze-dev/flowgram.ai",
|
||||
"license": "MIT",
|
||||
"exports": {
|
||||
"types": "./dist/index.d.ts",
|
||||
|
||||
@ -46,6 +46,9 @@ export const createNodeCorePlugin = definePluginCreator<NodeCorePluginOptions>({
|
||||
|
||||
registerNodeMaterial({ nodeManager, formManager, material: options.materials! });
|
||||
},
|
||||
onDispose(ctx) {
|
||||
ctx.get<FormManager>(FormManager)?.dispose();
|
||||
},
|
||||
containerModules: createNodeContainerModules(),
|
||||
// onBind: ({ bind }) => {
|
||||
// bindContributions(bind, FormNodeContribution, [NodeContribution]);
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
{
|
||||
"name": "@flowgram.ai/node-variable-plugin",
|
||||
"version": "0.1.0",
|
||||
"homepage": "https://coze-dev.github.io/flowgram.ai/",
|
||||
"repository": "https://github.com/coze-dev/flowgram.ai",
|
||||
"license": "MIT",
|
||||
"exports": {
|
||||
"types": "./dist/index.d.ts",
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
{
|
||||
"name": "@flowgram.ai/redux-devtool-plugin",
|
||||
"version": "0.1.0",
|
||||
"homepage": "https://coze-dev.github.io/flowgram.ai/",
|
||||
"repository": "https://github.com/coze-dev/flowgram.ai",
|
||||
"license": "MIT",
|
||||
"exports": {
|
||||
"types": "./dist/index.d.ts",
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
{
|
||||
"name": "@flowgram.ai/select-box-plugin",
|
||||
"version": "0.1.0",
|
||||
"homepage": "https://coze-dev.github.io/flowgram.ai/",
|
||||
"repository": "https://github.com/coze-dev/flowgram.ai",
|
||||
"license": "MIT",
|
||||
"exports": {
|
||||
"types": "./dist/index.d.ts",
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
{
|
||||
"name": "@flowgram.ai/shortcuts-plugin",
|
||||
"version": "0.1.0",
|
||||
"homepage": "https://coze-dev.github.io/flowgram.ai/",
|
||||
"repository": "https://github.com/coze-dev/flowgram.ai",
|
||||
"license": "MIT",
|
||||
"exports": {
|
||||
"types": "./dist/index.d.ts",
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
{
|
||||
"name": "@flowgram.ai/variable-plugin",
|
||||
"version": "0.1.0",
|
||||
"homepage": "https://coze-dev.github.io/flowgram.ai/",
|
||||
"repository": "https://github.com/coze-dev/flowgram.ai",
|
||||
"license": "MIT",
|
||||
"exports": {
|
||||
"types": "./dist/index.d.ts",
|
||||
|
||||
@ -8,7 +8,8 @@
|
||||
"scope",
|
||||
"engine"
|
||||
],
|
||||
"homepage": "",
|
||||
"homepage": "https://coze-dev.github.io/flowgram.ai/",
|
||||
"repository": "https://github.com/coze-dev/flowgram.ai",
|
||||
"license": "MIT",
|
||||
"exports": {
|
||||
"types": "./dist/index.d.ts",
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
{
|
||||
"name": "@flowgram.ai/variable-layout",
|
||||
"version": "0.1.0",
|
||||
"homepage": "https://coze-dev.github.io/flowgram.ai/",
|
||||
"repository": "https://github.com/coze-dev/flowgram.ai",
|
||||
"license": "MIT",
|
||||
"exports": {
|
||||
"types": "./dist/index.d.ts",
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import { VariableEngine } from '@flowgram.ai/variable-core';
|
||||
import { type ASTNode, ASTNodeJSON } from '@flowgram.ai/variable-core';
|
||||
import { FlowNodeEntity } from '@flowgram.ai/document';
|
||||
import { EntityData } from '@flowgram.ai/core';
|
||||
|
||||
@ -16,7 +17,7 @@ export class FlowNodeVariableData extends EntityData {
|
||||
readonly variableEngine: VariableEngine;
|
||||
|
||||
/**
|
||||
* private 的变量可以被 public 所访问,反之则不行
|
||||
* Private variables can be accessed by public ones, but not the other way around.
|
||||
*/
|
||||
protected _private?: FlowNodeScope;
|
||||
|
||||
@ -30,6 +31,104 @@ export class FlowNodeVariableData extends EntityData {
|
||||
return this._public;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a variable in the public AST (Abstract Syntax Tree) with the given key and JSON value.
|
||||
*
|
||||
* @param key - The key under which the variable will be stored.
|
||||
* @param json - The JSON value to store.
|
||||
* @returns The updated AST node.
|
||||
*/
|
||||
public setVar(key: string, json: ASTNodeJSON): ASTNode;
|
||||
|
||||
/**
|
||||
* Sets a variable in the public AST (Abstract Syntax Tree) with the default key 'outputs'.
|
||||
*
|
||||
* @param json - The JSON value to store.
|
||||
* @returns The updated AST node.
|
||||
*/
|
||||
public setVar(json: ASTNodeJSON): ASTNode;
|
||||
|
||||
public setVar(arg1: string | ASTNodeJSON, arg2?: ASTNodeJSON): ASTNode {
|
||||
if (typeof arg1 === 'string' && arg2 !== undefined) {
|
||||
return this.public.ast.set(arg1, arg2);
|
||||
}
|
||||
|
||||
if (typeof arg1 === 'object' && arg2 === undefined) {
|
||||
return this.public.ast.set('outputs', arg1);
|
||||
}
|
||||
|
||||
throw new Error('Invalid arguments');
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a variable from the public AST (Abstract Syntax Tree) by key.
|
||||
*
|
||||
* @param key - The key of the variable to retrieve. Defaults to 'outputs'.
|
||||
* @returns The value of the variable, or undefined if not found.
|
||||
*/
|
||||
public getVar(key: string = 'outputs') {
|
||||
return this.public.ast.get(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears a variable from the public AST (Abstract Syntax Tree) by key.
|
||||
*
|
||||
* @param key - The key of the variable to clear. Defaults to 'outputs'.
|
||||
* @returns The updated AST node.
|
||||
*/
|
||||
public clearVar(key: string = 'outputs') {
|
||||
return this.public.ast.remove(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a variable in the private AST (Abstract Syntax Tree) with the given key and JSON value.
|
||||
*
|
||||
* @param key - The key under which the variable will be stored.
|
||||
* @param json - The JSON value to store.
|
||||
* @returns The updated AST node.
|
||||
*/
|
||||
public setPrivateVar(key: string, json: ASTNodeJSON): ASTNode;
|
||||
|
||||
/**
|
||||
* Sets a variable in the private AST (Abstract Syntax Tree) with the default key 'outputs'.
|
||||
*
|
||||
* @param json - The JSON value to store.
|
||||
* @returns The updated AST node.
|
||||
*/
|
||||
public setPrivateVar(json: ASTNodeJSON): ASTNode;
|
||||
|
||||
public setPrivateVar(arg1: string | ASTNodeJSON, arg2?: ASTNodeJSON): ASTNode {
|
||||
if (typeof arg1 === 'string' && arg2 !== undefined) {
|
||||
return this.initPrivate().ast.set(arg1, arg2);
|
||||
}
|
||||
|
||||
if (typeof arg1 === 'object' && arg2 === undefined) {
|
||||
return this.initPrivate().ast.set('outputs', arg1);
|
||||
}
|
||||
|
||||
throw new Error('Invalid arguments');
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a variable from the private AST (Abstract Syntax Tree) by key.
|
||||
*
|
||||
* @param key - The key of the variable to retrieve. Defaults to 'outputs'.
|
||||
* @returns The value of the variable, or undefined if not found.
|
||||
*/
|
||||
public getPrivateVar(key: string = 'outputs') {
|
||||
return this.private?.ast.get(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears a variable from the private AST (Abstract Syntax Tree) by key.
|
||||
*
|
||||
* @param key - The key of the variable to clear. Defaults to 'outputs'.
|
||||
* @returns The updated AST node.
|
||||
*/
|
||||
public clearPrivateVar(key: string = 'outputs') {
|
||||
return this.private?.ast.remove(key);
|
||||
}
|
||||
|
||||
get allScopes(): FlowNodeScope[] {
|
||||
const res = [];
|
||||
|
||||
@ -65,15 +164,15 @@ export class FlowNodeVariableData extends EntityData {
|
||||
node: this.entity,
|
||||
type: FlowNodeScopeTypeEnum.private,
|
||||
} as FlowNodeScopeMeta);
|
||||
// 1. 通知 private 的覆盖作用域更新依赖
|
||||
this._private.coverScopes.forEach(_scope => {
|
||||
// 1. Notify the covering scopes of private to update dependencies
|
||||
this._private.coverScopes.forEach((_scope) => {
|
||||
_scope.refreshDeps();
|
||||
});
|
||||
// 2. 通知 private 的依赖作用域更新覆盖
|
||||
this._private.depScopes.forEach(_scope => {
|
||||
// 2. Notify the dependent scopes of private to update their covers
|
||||
this._private.depScopes.forEach((_scope) => {
|
||||
_scope.refreshCovers();
|
||||
});
|
||||
// 3. private 自身需要刷新依赖
|
||||
// 3. The private scope itself needs to refresh its dependencies
|
||||
this._private.available.refresh();
|
||||
|
||||
this.toDispose.push(this._private);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user