mirror of
https://gitee.com/ByteDance/flowgram.ai.git
synced 2025-07-07 17:43:29 +08:00
feat(free-group-plugin): add initGroupJSON config (#394)
* docs: update readme * feat(free-group-plugin): add initGroupJSON config
This commit is contained in:
parent
e385211484
commit
2ed104ee95
@ -10,7 +10,7 @@ our name.
|
||||
<div align="center">
|
||||
|
||||
[](https://github.com/bytedance/flowgram.ai/blob/main/LICENSE)
|
||||
[](https://www.npmjs.com/package/@flowgram.ai/editor)
|
||||
|
||||
</div>
|
||||
@ -119,9 +119,6 @@ After that, you can start to develop projects inside this repository.
|
||||
|
||||
Enjoy it!
|
||||
|
||||
## Stats
|
||||

|
||||
|
||||
## 🌟 Contributors
|
||||
|
||||
[](https://github.com/bytedance/flowgram.ai/graphs/contributors)
|
||||
|
||||
@ -11,8 +11,9 @@ import { GroupNodeRegistry } from './group-node';
|
||||
|
||||
export const createFreeGroupPlugin = definePluginCreator<WorkflowGroupPluginOptions, PluginContext>(
|
||||
{
|
||||
onBind({ bind, rebind }) {
|
||||
onBind({ bind, rebind }, opts) {
|
||||
bind(WorkflowGroupService).toSelf().inSingletonScope();
|
||||
bind(WorkflowGroupPluginOptions).toConstantValue(opts);
|
||||
rebind(FlowGroupService).toService(WorkflowGroupService);
|
||||
},
|
||||
onInit(
|
||||
|
||||
@ -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');
|
||||
|
||||
@ -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();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user