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">
|
<div align="center">
|
||||||
|
|
||||||
[](https://github.com/bytedance/flowgram.ai/blob/main/LICENSE)
|
[](https://github.com/bytedance/flowgram.ai/blob/main/LICENSE)
|
||||||
[](https://www.npmjs.com/package/@flowgram.ai/editor)
|
)](https://www.npmjs.com/package/@flowgram.ai/editor)
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
@ -119,9 +119,6 @@ After that, you can start to develop projects inside this repository.
|
|||||||
|
|
||||||
Enjoy it!
|
Enjoy it!
|
||||||
|
|
||||||
## Stats
|
|
||||||

|
|
||||||
|
|
||||||
## 🌟 Contributors
|
## 🌟 Contributors
|
||||||
|
|
||||||
[](https://github.com/bytedance/flowgram.ai/graphs/contributors)
|
[](https://github.com/bytedance/flowgram.ai/graphs/contributors)
|
||||||
|
|||||||
@ -11,8 +11,9 @@ import { GroupNodeRegistry } from './group-node';
|
|||||||
|
|
||||||
export const createFreeGroupPlugin = definePluginCreator<WorkflowGroupPluginOptions, PluginContext>(
|
export const createFreeGroupPlugin = definePluginCreator<WorkflowGroupPluginOptions, PluginContext>(
|
||||||
{
|
{
|
||||||
onBind({ bind, rebind }) {
|
onBind({ bind, rebind }, opts) {
|
||||||
bind(WorkflowGroupService).toSelf().inSingletonScope();
|
bind(WorkflowGroupService).toSelf().inSingletonScope();
|
||||||
|
bind(WorkflowGroupPluginOptions).toConstantValue(opts);
|
||||||
rebind(FlowGroupService).toService(WorkflowGroupService);
|
rebind(FlowGroupService).toService(WorkflowGroupService);
|
||||||
},
|
},
|
||||||
onInit(
|
onInit(
|
||||||
|
|||||||
@ -1,7 +1,12 @@
|
|||||||
import { FC } from 'react';
|
import { FC } from 'react';
|
||||||
|
|
||||||
|
import { WorkflowNodeEntity, WorkflowNodeJSON } from '@flowgram.ai/free-layout-core';
|
||||||
|
|
||||||
export interface WorkflowGroupPluginOptions {
|
export interface WorkflowGroupPluginOptions {
|
||||||
groupNodeRender: FC;
|
groupNodeRender: FC;
|
||||||
disableGroupShortcuts?: boolean;
|
disableGroupShortcuts?: boolean;
|
||||||
disableGroupNodeRegister?: 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 { TransformData } from '@flowgram.ai/core';
|
||||||
|
|
||||||
import { WorkflowGroupUtils } from './utils';
|
import { WorkflowGroupUtils } from './utils';
|
||||||
|
import { WorkflowGroupPluginOptions } from './type';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
/** 分组服务 */
|
/** 分组服务 */
|
||||||
@ -28,6 +29,8 @@ export class WorkflowGroupService extends FlowGroupService {
|
|||||||
|
|
||||||
@inject(NodeIntoContainerService) private nodeIntoContainerService: NodeIntoContainerService;
|
@inject(NodeIntoContainerService) private nodeIntoContainerService: NodeIntoContainerService;
|
||||||
|
|
||||||
|
@inject(WorkflowGroupPluginOptions) private opts: WorkflowGroupPluginOptions;
|
||||||
|
|
||||||
private toDispose = new DisposableCollection();
|
private toDispose = new DisposableCollection();
|
||||||
|
|
||||||
public ready(): void {
|
public ready(): void {
|
||||||
@ -44,10 +47,9 @@ export class WorkflowGroupService extends FlowGroupService {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const parent = nodes[0].parent ?? this.document.root;
|
const parent = nodes[0].parent ?? this.document.root;
|
||||||
const groupId = `group_${nanoid(5)}`;
|
let groupJSON: WorkflowNodeJSON = {
|
||||||
const groupJSON: WorkflowNodeJSON = {
|
|
||||||
type: FlowNodeBaseType.GROUP,
|
type: FlowNodeBaseType.GROUP,
|
||||||
id: groupId,
|
id: `group_${nanoid(5)}`,
|
||||||
meta: {
|
meta: {
|
||||||
position: {
|
position: {
|
||||||
x: 0,
|
x: 0,
|
||||||
@ -56,6 +58,9 @@ export class WorkflowGroupService extends FlowGroupService {
|
|||||||
},
|
},
|
||||||
data: {},
|
data: {},
|
||||||
};
|
};
|
||||||
|
if (this.opts.initGroupJSON) {
|
||||||
|
groupJSON = this.opts.initGroupJSON(groupJSON, nodes);
|
||||||
|
}
|
||||||
this.historyService.startTransaction();
|
this.historyService.startTransaction();
|
||||||
this.document.createWorkflowNodeByType(
|
this.document.createWorkflowNodeByType(
|
||||||
FlowNodeBaseType.GROUP,
|
FlowNodeBaseType.GROUP,
|
||||||
@ -68,7 +73,7 @@ export class WorkflowGroupService extends FlowGroupService {
|
|||||||
);
|
);
|
||||||
nodes.forEach((node) => {
|
nodes.forEach((node) => {
|
||||||
this.freeOperationService.moveNode(node, {
|
this.freeOperationService.moveNode(node, {
|
||||||
parent: groupId,
|
parent: groupJSON.id,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
this.historyService.endTransaction();
|
this.historyService.endTransaction();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user