diff --git a/README.md b/README.md index dd4c3706..c5d637fe 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ our name.
[![License](https://img.shields.io/github/license/bytedance/flowgram.ai)](https://github.com/bytedance/flowgram.ai/blob/main/LICENSE) -[![@flowgram.ai/editor](https://img.shields.io/npm/dw/%40flowgram.ai%2Fcore +[![@flowgram.ai/editor](https://img.shields.io/npm/dm/%40flowgram.ai%2Fcore )](https://www.npmjs.com/package/@flowgram.ai/editor)
@@ -119,9 +119,6 @@ After that, you can start to develop projects inside this repository. Enjoy it! -## Stats -![Repo Stats](https://repobeats.axiom.co/api/embed/2b88f04ae1568daf1e49f77de99bb9d2fbe0d296.svg) - ## 🌟 Contributors [![FlowGram.AI Contributors](https://contrib.rocks/image?repo=bytedance/flowgram.ai)](https://github.com/bytedance/flowgram.ai/graphs/contributors) diff --git a/packages/plugins/free-group-plugin/src/create-free-group-plugin.tsx b/packages/plugins/free-group-plugin/src/create-free-group-plugin.tsx index ef8d4249..2094fe7f 100644 --- a/packages/plugins/free-group-plugin/src/create-free-group-plugin.tsx +++ b/packages/plugins/free-group-plugin/src/create-free-group-plugin.tsx @@ -11,8 +11,9 @@ import { GroupNodeRegistry } from './group-node'; export const createFreeGroupPlugin = definePluginCreator( { - onBind({ bind, rebind }) { + onBind({ bind, rebind }, opts) { bind(WorkflowGroupService).toSelf().inSingletonScope(); + bind(WorkflowGroupPluginOptions).toConstantValue(opts); rebind(FlowGroupService).toService(WorkflowGroupService); }, onInit( diff --git a/packages/plugins/free-group-plugin/src/type.ts b/packages/plugins/free-group-plugin/src/type.ts index 0d9818c3..fadb3e8d 100644 --- a/packages/plugins/free-group-plugin/src/type.ts +++ b/packages/plugins/free-group-plugin/src/type.ts @@ -1,7 +1,12 @@ import { FC } from 'react'; +import { WorkflowNodeEntity, WorkflowNodeJSON } from '@flowgram.ai/free-layout-core'; + export interface WorkflowGroupPluginOptions { groupNodeRender: FC; disableGroupShortcuts?: boolean; disableGroupNodeRegister?: boolean; + initGroupJSON?: (json: WorkflowNodeJSON, nodes: WorkflowNodeEntity[]) => WorkflowNodeJSON; } + +export const WorkflowGroupPluginOptions = Symbol('WorkflowGroupPluginOptions'); diff --git a/packages/plugins/free-group-plugin/src/workflow-group-service.ts b/packages/plugins/free-group-plugin/src/workflow-group-service.ts index 6ba0428f..47bfd601 100644 --- a/packages/plugins/free-group-plugin/src/workflow-group-service.ts +++ b/packages/plugins/free-group-plugin/src/workflow-group-service.ts @@ -16,6 +16,7 @@ import { FlowGroupService, FlowNodeBaseType } from '@flowgram.ai/document'; import { TransformData } from '@flowgram.ai/core'; import { WorkflowGroupUtils } from './utils'; +import { WorkflowGroupPluginOptions } from './type'; @injectable() /** 分组服务 */ @@ -28,6 +29,8 @@ export class WorkflowGroupService extends FlowGroupService { @inject(NodeIntoContainerService) private nodeIntoContainerService: NodeIntoContainerService; + @inject(WorkflowGroupPluginOptions) private opts: WorkflowGroupPluginOptions; + private toDispose = new DisposableCollection(); public ready(): void { @@ -44,10 +47,9 @@ export class WorkflowGroupService extends FlowGroupService { return; } const parent = nodes[0].parent ?? this.document.root; - const groupId = `group_${nanoid(5)}`; - const groupJSON: WorkflowNodeJSON = { + let groupJSON: WorkflowNodeJSON = { type: FlowNodeBaseType.GROUP, - id: groupId, + id: `group_${nanoid(5)}`, meta: { position: { x: 0, @@ -56,6 +58,9 @@ export class WorkflowGroupService extends FlowGroupService { }, data: {}, }; + if (this.opts.initGroupJSON) { + groupJSON = this.opts.initGroupJSON(groupJSON, nodes); + } this.historyService.startTransaction(); this.document.createWorkflowNodeByType( FlowNodeBaseType.GROUP, @@ -68,7 +73,7 @@ export class WorkflowGroupService extends FlowGroupService { ); nodes.forEach((node) => { this.freeOperationService.moveNode(node, { - parent: groupId, + parent: groupJSON.id, }); }); this.historyService.endTransaction();