@flowgram.ai/group-plugin 0.1.0-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/index.js +497 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/index.d.mts +116 -0
- package/dist/index.d.ts +116 -0
- package/dist/index.js +525 -0
- package/dist/index.js.map +1 -0
- package/package.json +55 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { FlowNodeEntity, FlowGroupController, FlowDocument, FlowGroupService, FlowDocumentTransformerEntity, FlowNodeRenderData, FlowNodeTransformData, FlowNodeRegistry } from '@flowgram.ai/document';
|
|
2
|
+
export { FlowGroupController } from '@flowgram.ai/document';
|
|
3
|
+
import { FlowRendererRegistry } from '@flowgram.ai/renderer';
|
|
4
|
+
import * as _flowgram_ai_core from '@flowgram.ai/core';
|
|
5
|
+
import { LayerOptions, PluginContext, Layer } from '@flowgram.ai/core';
|
|
6
|
+
import { FC, CSSProperties } from 'react';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
10
|
+
* SPDX-License-Identifier: MIT
|
|
11
|
+
*/
|
|
12
|
+
declare enum GroupRenderer {
|
|
13
|
+
GroupRender = "group_render",
|
|
14
|
+
GroupBox = "group_box"
|
|
15
|
+
}
|
|
16
|
+
declare const PositionConfig: {
|
|
17
|
+
paddingWithNote: number;
|
|
18
|
+
padding: number;
|
|
19
|
+
paddingWithAddLabel: number;
|
|
20
|
+
headerHeight: number;
|
|
21
|
+
};
|
|
22
|
+
declare enum GroupPluginRegister {
|
|
23
|
+
GroupNode = "registerGroupNode",
|
|
24
|
+
Render = "registerRender",
|
|
25
|
+
Layer = "registerLayer",
|
|
26
|
+
CleanGroups = "registerCleanGroups"
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
31
|
+
* SPDX-License-Identifier: MIT
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
type IGroupBox = FC<{
|
|
35
|
+
groupNode: FlowNodeEntity;
|
|
36
|
+
backgroundStyle?: (groupController: FlowGroupController) => CSSProperties;
|
|
37
|
+
}>;
|
|
38
|
+
type IGroupRender = FC<{
|
|
39
|
+
groupNode: FlowNodeEntity;
|
|
40
|
+
GroupNode: IGroupNode;
|
|
41
|
+
GroupBoxHeader: IGroupBoxHeader;
|
|
42
|
+
}>;
|
|
43
|
+
type IGroupNode = FC<{
|
|
44
|
+
groupNode: FlowNodeEntity;
|
|
45
|
+
groupController: FlowGroupController;
|
|
46
|
+
}>;
|
|
47
|
+
type IGroupBoxHeader = FC<{
|
|
48
|
+
groupNode: FlowNodeEntity;
|
|
49
|
+
groupController: FlowGroupController;
|
|
50
|
+
}>;
|
|
51
|
+
interface GroupsLayerOptions extends LayerOptions {
|
|
52
|
+
groupBoxStyle?: (groupController: FlowGroupController) => CSSProperties;
|
|
53
|
+
}
|
|
54
|
+
type IGroupPluginRegister = (ctx: PluginContext, opts: CreateGroupPluginOptions) => void;
|
|
55
|
+
type CreateGroupPluginOptions = GroupsLayerOptions & {
|
|
56
|
+
components?: {
|
|
57
|
+
GroupNode: IGroupNode;
|
|
58
|
+
GroupBoxHeader: IGroupBoxHeader;
|
|
59
|
+
};
|
|
60
|
+
registers?: {
|
|
61
|
+
[key in GroupPluginRegister]?: IGroupPluginRegister | boolean;
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
67
|
+
* SPDX-License-Identifier: MIT
|
|
68
|
+
*/
|
|
69
|
+
|
|
70
|
+
declare class GroupsLayer extends Layer<GroupsLayerOptions> {
|
|
71
|
+
readonly node: HTMLElement;
|
|
72
|
+
protected document: FlowDocument;
|
|
73
|
+
protected readonly rendererRegistry: FlowRendererRegistry;
|
|
74
|
+
protected readonly groupService: FlowGroupService;
|
|
75
|
+
readonly documentTransformer: FlowDocumentTransformerEntity;
|
|
76
|
+
renderStates: FlowNodeRenderData[];
|
|
77
|
+
transforms: FlowNodeTransformData[];
|
|
78
|
+
private readonly className;
|
|
79
|
+
constructor();
|
|
80
|
+
/** 缩放 */
|
|
81
|
+
onZoom(scale: number): void;
|
|
82
|
+
render(): JSX.Element;
|
|
83
|
+
/** 渲染分组 */
|
|
84
|
+
protected renderGroups(): JSX.Element;
|
|
85
|
+
/** 所有分组 */
|
|
86
|
+
protected get groups(): FlowGroupController[];
|
|
87
|
+
protected get renderer(): IGroupBox;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* 分组插件
|
|
92
|
+
*/
|
|
93
|
+
declare const createGroupPlugin: _flowgram_ai_core.PluginCreator<CreateGroupPluginOptions>;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
97
|
+
* SPDX-License-Identifier: MIT
|
|
98
|
+
*/
|
|
99
|
+
|
|
100
|
+
declare const GroupRegister: FlowNodeRegistry;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
104
|
+
* SPDX-License-Identifier: MIT
|
|
105
|
+
*/
|
|
106
|
+
|
|
107
|
+
declare const GroupRender: IGroupRender;
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
|
|
111
|
+
* SPDX-License-Identifier: MIT
|
|
112
|
+
*/
|
|
113
|
+
|
|
114
|
+
declare const GroupBox: IGroupBox;
|
|
115
|
+
|
|
116
|
+
export { type CreateGroupPluginOptions, GroupBox, GroupPluginRegister, GroupRegister, GroupRender, GroupRenderer, GroupsLayer, type GroupsLayerOptions, type IGroupBox, type IGroupBoxHeader, type IGroupNode, type IGroupPluginRegister, type IGroupRender, PositionConfig, createGroupPlugin };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,525 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
30
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
31
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
32
|
+
if (decorator = decorators[i])
|
|
33
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
34
|
+
if (kind && result) __defProp(target, key, result);
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
// src/index.ts
|
|
39
|
+
var src_exports = {};
|
|
40
|
+
__export(src_exports, {
|
|
41
|
+
FlowGroupController: () => import_document9.FlowGroupController,
|
|
42
|
+
GroupBox: () => GroupBox,
|
|
43
|
+
GroupPluginRegister: () => GroupPluginRegister,
|
|
44
|
+
GroupRegister: () => GroupRegister,
|
|
45
|
+
GroupRender: () => GroupRender,
|
|
46
|
+
GroupRenderer: () => GroupRenderer,
|
|
47
|
+
GroupsLayer: () => GroupsLayer,
|
|
48
|
+
PositionConfig: () => PositionConfig,
|
|
49
|
+
createGroupPlugin: () => createGroupPlugin
|
|
50
|
+
});
|
|
51
|
+
module.exports = __toCommonJS(src_exports);
|
|
52
|
+
var import_document9 = require("@flowgram.ai/document");
|
|
53
|
+
|
|
54
|
+
// src/groups-layer.tsx
|
|
55
|
+
var import_react5 = __toESM(require("react"));
|
|
56
|
+
var import_inversify = require("inversify");
|
|
57
|
+
var import_renderer = require("@flowgram.ai/renderer");
|
|
58
|
+
var import_document4 = require("@flowgram.ai/document");
|
|
59
|
+
var import_core2 = require("@flowgram.ai/core");
|
|
60
|
+
var import_utils2 = require("@flowgram.ai/utils");
|
|
61
|
+
|
|
62
|
+
// src/constant.ts
|
|
63
|
+
var GroupRenderer = /* @__PURE__ */ ((GroupRenderer2) => {
|
|
64
|
+
GroupRenderer2["GroupRender"] = "group_render";
|
|
65
|
+
GroupRenderer2["GroupBox"] = "group_box";
|
|
66
|
+
return GroupRenderer2;
|
|
67
|
+
})(GroupRenderer || {});
|
|
68
|
+
var PositionConfig = {
|
|
69
|
+
paddingWithNote: 50,
|
|
70
|
+
// note 留白大小
|
|
71
|
+
padding: 10,
|
|
72
|
+
// 无 label 的 padding
|
|
73
|
+
paddingWithAddLabel: 20,
|
|
74
|
+
// 有 label 的padding,如要放添加按钮
|
|
75
|
+
headerHeight: 20
|
|
76
|
+
// 基础头部高度
|
|
77
|
+
};
|
|
78
|
+
var GroupPluginRegister = /* @__PURE__ */ ((GroupPluginRegister2) => {
|
|
79
|
+
GroupPluginRegister2["GroupNode"] = "registerGroupNode";
|
|
80
|
+
GroupPluginRegister2["Render"] = "registerRender";
|
|
81
|
+
GroupPluginRegister2["Layer"] = "registerLayer";
|
|
82
|
+
GroupPluginRegister2["CleanGroups"] = "registerCleanGroups";
|
|
83
|
+
return GroupPluginRegister2;
|
|
84
|
+
})(GroupPluginRegister || {});
|
|
85
|
+
|
|
86
|
+
// src/components/group-render.tsx
|
|
87
|
+
var import_react = __toESM(require("react"));
|
|
88
|
+
var import_document = require("@flowgram.ai/document");
|
|
89
|
+
var import_document2 = require("@flowgram.ai/document");
|
|
90
|
+
var import_core = require("@flowgram.ai/core");
|
|
91
|
+
var import_utils = require("@flowgram.ai/utils");
|
|
92
|
+
function useCurrentDomNode() {
|
|
93
|
+
const entity = (0, import_core.useEntityFromContext)();
|
|
94
|
+
const renderData = entity.getData(import_document.FlowNodeRenderData);
|
|
95
|
+
return renderData.node;
|
|
96
|
+
}
|
|
97
|
+
var GroupRender = (props) => {
|
|
98
|
+
const { groupNode, GroupNode, GroupBoxHeader } = props;
|
|
99
|
+
const container = useCurrentDomNode();
|
|
100
|
+
const document = (0, import_core.useService)(import_document2.FlowDocument);
|
|
101
|
+
const groupController = import_document.FlowGroupController.create(groupNode);
|
|
102
|
+
const [key, setKey] = (0, import_react.useState)(0);
|
|
103
|
+
const [rendering, setRendering] = (0, import_react.useState)(true);
|
|
104
|
+
const [collapsedCache, setCollapsedCache] = (0, import_react.useState)(groupController?.collapsed ?? false);
|
|
105
|
+
const rerender = (0, import_react.useCallback)(async () => {
|
|
106
|
+
setRendering(true);
|
|
107
|
+
setKey(key + 1);
|
|
108
|
+
await (0, import_utils.delay)(50);
|
|
109
|
+
setKey(key + 1);
|
|
110
|
+
setRendering(false);
|
|
111
|
+
}, [key]);
|
|
112
|
+
(0, import_react.useEffect)(() => {
|
|
113
|
+
const disposer = document.renderTree.onTreeChange(() => {
|
|
114
|
+
if (groupController?.collapsed !== collapsedCache) {
|
|
115
|
+
setCollapsedCache(groupController?.collapsed ?? false);
|
|
116
|
+
rerender();
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
return () => {
|
|
120
|
+
disposer.dispose();
|
|
121
|
+
};
|
|
122
|
+
}, [key]);
|
|
123
|
+
(0, import_react.useEffect)(() => {
|
|
124
|
+
if (!groupController || groupController.collapsed) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
rerender();
|
|
128
|
+
}, []);
|
|
129
|
+
if (!groupController) {
|
|
130
|
+
return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null);
|
|
131
|
+
}
|
|
132
|
+
const groupNodeRender = /* @__PURE__ */ import_react.default.createElement(GroupNode, { key, groupNode, groupController });
|
|
133
|
+
const groupBoxHeader = /* @__PURE__ */ import_react.default.createElement(GroupBoxHeader, { key, groupController, groupNode });
|
|
134
|
+
if (groupController.collapsed) {
|
|
135
|
+
const positionStyle = {
|
|
136
|
+
display: "block",
|
|
137
|
+
zIndex: "0",
|
|
138
|
+
width: "auto",
|
|
139
|
+
height: "auto"
|
|
140
|
+
};
|
|
141
|
+
Object.assign(container.style, positionStyle);
|
|
142
|
+
return groupNodeRender;
|
|
143
|
+
} else if (!rendering) {
|
|
144
|
+
const bounds = groupController.bounds;
|
|
145
|
+
const positionStyle = {
|
|
146
|
+
width: `${bounds.width}px`
|
|
147
|
+
};
|
|
148
|
+
Object.assign(container.style, positionStyle);
|
|
149
|
+
return groupBoxHeader;
|
|
150
|
+
} else {
|
|
151
|
+
return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null);
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
// src/components/group-box.tsx
|
|
156
|
+
var import_react3 = require("react");
|
|
157
|
+
var import_react4 = __toESM(require("react"));
|
|
158
|
+
var import_document3 = require("@flowgram.ai/document");
|
|
159
|
+
|
|
160
|
+
// src/components/hooks.ts
|
|
161
|
+
var import_react2 = require("react");
|
|
162
|
+
var useHover = () => {
|
|
163
|
+
const ref = (0, import_react2.useRef)(null);
|
|
164
|
+
const [hover, setHover] = (0, import_react2.useState)(false);
|
|
165
|
+
const checkMouseOver = (event) => {
|
|
166
|
+
if (!ref.current) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
const { left, top, right, bottom } = ref.current.getBoundingClientRect();
|
|
170
|
+
const isOver = event.clientX >= left && event.clientX <= right && event.clientY >= top && event.clientY <= bottom;
|
|
171
|
+
setHover(isOver);
|
|
172
|
+
};
|
|
173
|
+
(0, import_react2.useEffect)(() => {
|
|
174
|
+
window.addEventListener("mousemove", checkMouseOver);
|
|
175
|
+
return () => {
|
|
176
|
+
window.removeEventListener("mousemove", checkMouseOver);
|
|
177
|
+
};
|
|
178
|
+
}, []);
|
|
179
|
+
return {
|
|
180
|
+
hover,
|
|
181
|
+
ref
|
|
182
|
+
};
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
// src/components/group-box.tsx
|
|
186
|
+
var GroupBox = (props) => {
|
|
187
|
+
const { groupNode } = props;
|
|
188
|
+
const groupController = import_document3.FlowGroupController.create(groupNode);
|
|
189
|
+
const bounds = groupController.bounds;
|
|
190
|
+
const { hover, ref } = useHover();
|
|
191
|
+
const positionStyle = {
|
|
192
|
+
position: "absolute",
|
|
193
|
+
left: bounds.left,
|
|
194
|
+
top: bounds.top,
|
|
195
|
+
width: bounds.width,
|
|
196
|
+
height: bounds.height
|
|
197
|
+
};
|
|
198
|
+
const defaultBackgroundStyle = {
|
|
199
|
+
borderRadius: 10,
|
|
200
|
+
zIndex: -1,
|
|
201
|
+
outline: `${hover ? 3 : 1}px solid rgb(97, 69, 211)`,
|
|
202
|
+
backgroundColor: "rgb(236 233 247)"
|
|
203
|
+
};
|
|
204
|
+
const backgroundStyle = props.backgroundStyle ? props.backgroundStyle(groupController) : defaultBackgroundStyle;
|
|
205
|
+
(0, import_react3.useEffect)(() => {
|
|
206
|
+
groupController.hovered = hover;
|
|
207
|
+
}, [hover]);
|
|
208
|
+
if (!groupController || groupController.collapsed) {
|
|
209
|
+
return /* @__PURE__ */ import_react4.default.createElement(import_react4.default.Fragment, null);
|
|
210
|
+
}
|
|
211
|
+
return /* @__PURE__ */ import_react4.default.createElement("div", { className: "gedit-group-box", "data-group-id": groupNode.id }, /* @__PURE__ */ import_react4.default.createElement(
|
|
212
|
+
"div",
|
|
213
|
+
{
|
|
214
|
+
className: "gedit-group-background",
|
|
215
|
+
ref,
|
|
216
|
+
style: {
|
|
217
|
+
...positionStyle,
|
|
218
|
+
...backgroundStyle
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
));
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
// src/groups-layer.tsx
|
|
225
|
+
var GroupsLayer = class extends import_core2.Layer {
|
|
226
|
+
constructor() {
|
|
227
|
+
super();
|
|
228
|
+
this.className = "gedit-groups-layer";
|
|
229
|
+
this.node = import_utils2.domUtils.createDivWithClass(this.className);
|
|
230
|
+
this.node.style.zIndex = "0";
|
|
231
|
+
}
|
|
232
|
+
/** 缩放 */
|
|
233
|
+
onZoom(scale) {
|
|
234
|
+
this.node.style.transform = `scale(${scale})`;
|
|
235
|
+
}
|
|
236
|
+
render() {
|
|
237
|
+
if (this.documentTransformer.loading) return /* @__PURE__ */ import_react5.default.createElement(import_react5.default.Fragment, null);
|
|
238
|
+
this.documentTransformer.refresh();
|
|
239
|
+
return /* @__PURE__ */ import_react5.default.createElement(import_react5.default.Fragment, null, this.renderGroups());
|
|
240
|
+
}
|
|
241
|
+
/** 渲染分组 */
|
|
242
|
+
renderGroups() {
|
|
243
|
+
const Box = this.renderer || GroupBox;
|
|
244
|
+
return /* @__PURE__ */ import_react5.default.createElement(import_react5.default.Fragment, null, this.groups.map((group) => /* @__PURE__ */ import_react5.default.createElement(
|
|
245
|
+
Box,
|
|
246
|
+
{
|
|
247
|
+
key: group.groupNode.id,
|
|
248
|
+
groupNode: group.groupNode,
|
|
249
|
+
backgroundStyle: this.options.groupBoxStyle
|
|
250
|
+
}
|
|
251
|
+
)));
|
|
252
|
+
}
|
|
253
|
+
/** 所有分组 */
|
|
254
|
+
get groups() {
|
|
255
|
+
return this.groupService.getAllGroups();
|
|
256
|
+
}
|
|
257
|
+
get renderer() {
|
|
258
|
+
return this.rendererRegistry.tryToGetRendererComponent("group_box" /* GroupBox */)?.renderer;
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
__decorateClass([
|
|
262
|
+
(0, import_inversify.inject)(import_document4.FlowDocument)
|
|
263
|
+
], GroupsLayer.prototype, "document", 2);
|
|
264
|
+
__decorateClass([
|
|
265
|
+
(0, import_inversify.inject)(import_renderer.FlowRendererRegistry)
|
|
266
|
+
], GroupsLayer.prototype, "rendererRegistry", 2);
|
|
267
|
+
__decorateClass([
|
|
268
|
+
(0, import_inversify.inject)(import_document4.FlowGroupService)
|
|
269
|
+
], GroupsLayer.prototype, "groupService", 2);
|
|
270
|
+
__decorateClass([
|
|
271
|
+
(0, import_core2.observeEntity)(import_document4.FlowDocumentTransformerEntity)
|
|
272
|
+
], GroupsLayer.prototype, "documentTransformer", 2);
|
|
273
|
+
__decorateClass([
|
|
274
|
+
(0, import_core2.observeEntityDatas)(import_document4.FlowNodeEntity, import_document4.FlowNodeRenderData)
|
|
275
|
+
], GroupsLayer.prototype, "renderStates", 2);
|
|
276
|
+
__decorateClass([
|
|
277
|
+
(0, import_core2.observeEntityDatas)(import_document4.FlowNodeEntity, import_document4.FlowNodeTransformData)
|
|
278
|
+
], GroupsLayer.prototype, "transforms", 2);
|
|
279
|
+
GroupsLayer = __decorateClass([
|
|
280
|
+
(0, import_inversify.injectable)()
|
|
281
|
+
], GroupsLayer);
|
|
282
|
+
|
|
283
|
+
// src/create-group-plugin.tsx
|
|
284
|
+
var import_core3 = require("@flowgram.ai/core");
|
|
285
|
+
|
|
286
|
+
// src/registers/register-render.tsx
|
|
287
|
+
var import_react6 = __toESM(require("react"));
|
|
288
|
+
var import_renderer2 = require("@flowgram.ai/renderer");
|
|
289
|
+
var registerRender = (ctx, opts) => {
|
|
290
|
+
const rendererRegistry = ctx.get(import_renderer2.FlowRendererRegistry);
|
|
291
|
+
const renderer = (props) => /* @__PURE__ */ import_react6.default.createElement(
|
|
292
|
+
GroupRender,
|
|
293
|
+
{
|
|
294
|
+
groupNode: props.node,
|
|
295
|
+
GroupNode: opts.components.GroupNode,
|
|
296
|
+
GroupBoxHeader: opts.components.GroupBoxHeader
|
|
297
|
+
}
|
|
298
|
+
);
|
|
299
|
+
rendererRegistry.registerReactComponent("group_render" /* GroupRender */, renderer);
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
// src/registers/register-layer.ts
|
|
303
|
+
var registerLayer = (ctx, opts) => {
|
|
304
|
+
ctx.playground.registerLayer(GroupsLayer, opts);
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
// src/registers/register-group-node.ts
|
|
308
|
+
var import_document6 = require("@flowgram.ai/document");
|
|
309
|
+
|
|
310
|
+
// src/group-node-register.tsx
|
|
311
|
+
var import_utils3 = require("@flowgram.ai/utils");
|
|
312
|
+
var import_document5 = require("@flowgram.ai/document");
|
|
313
|
+
var GroupRegister = {
|
|
314
|
+
type: import_document5.FlowNodeBaseType.GROUP,
|
|
315
|
+
meta: {
|
|
316
|
+
exportJSON: true,
|
|
317
|
+
renderKey: "group_render" /* GroupRender */,
|
|
318
|
+
positionConfig: PositionConfig,
|
|
319
|
+
padding: (transform) => {
|
|
320
|
+
const groupController = import_document5.FlowGroupController.create(transform.entity);
|
|
321
|
+
if (!groupController || groupController.collapsed || groupController.nodes.length === 0) {
|
|
322
|
+
return {
|
|
323
|
+
top: 0,
|
|
324
|
+
bottom: 0,
|
|
325
|
+
left: 0,
|
|
326
|
+
right: 0
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
if (transform.entity.isVertical) {
|
|
330
|
+
return {
|
|
331
|
+
top: PositionConfig.paddingWithNote,
|
|
332
|
+
bottom: PositionConfig.paddingWithAddLabel,
|
|
333
|
+
left: PositionConfig.padding,
|
|
334
|
+
right: PositionConfig.padding
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
return {
|
|
338
|
+
top: PositionConfig.paddingWithNote,
|
|
339
|
+
bottom: PositionConfig.padding,
|
|
340
|
+
left: PositionConfig.padding,
|
|
341
|
+
right: PositionConfig.paddingWithAddLabel
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
},
|
|
345
|
+
getLines(transition) {
|
|
346
|
+
const { transform } = transition;
|
|
347
|
+
const lines = [];
|
|
348
|
+
if (transform.firstChild) {
|
|
349
|
+
lines.push({
|
|
350
|
+
type: import_document5.FlowTransitionLineEnum.STRAIGHT_LINE,
|
|
351
|
+
from: transform.inputPoint,
|
|
352
|
+
to: transform.firstChild.inputPoint
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
if (transform.next) {
|
|
356
|
+
lines.push({
|
|
357
|
+
type: import_document5.FlowTransitionLineEnum.STRAIGHT_LINE,
|
|
358
|
+
from: transform.outputPoint,
|
|
359
|
+
to: transform.next.inputPoint
|
|
360
|
+
});
|
|
361
|
+
} else {
|
|
362
|
+
lines.push({
|
|
363
|
+
type: import_document5.FlowTransitionLineEnum.STRAIGHT_LINE,
|
|
364
|
+
from: transform.outputPoint,
|
|
365
|
+
to: transform.parent.outputPoint
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
return lines;
|
|
369
|
+
},
|
|
370
|
+
getDelta(transform) {
|
|
371
|
+
const groupController = import_document5.FlowGroupController.create(transform.entity);
|
|
372
|
+
if (!groupController || groupController.collapsed) {
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
if (transform.entity.isVertical) {
|
|
376
|
+
return {
|
|
377
|
+
x: 0,
|
|
378
|
+
y: PositionConfig.paddingWithNote
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
return {
|
|
382
|
+
x: PositionConfig.padding,
|
|
383
|
+
y: 0
|
|
384
|
+
};
|
|
385
|
+
},
|
|
386
|
+
getInputPoint(transform) {
|
|
387
|
+
const child = transform.firstChild;
|
|
388
|
+
if (!child) return transform.defaultInputPoint;
|
|
389
|
+
if (transform.entity.isVertical) {
|
|
390
|
+
return {
|
|
391
|
+
x: child.inputPoint.x,
|
|
392
|
+
y: transform.bounds.topCenter.y
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
return {
|
|
396
|
+
x: transform.bounds.leftCenter.x,
|
|
397
|
+
y: child.inputPoint.y
|
|
398
|
+
};
|
|
399
|
+
},
|
|
400
|
+
getOutputPoint(transform) {
|
|
401
|
+
const child = transform.lastChild;
|
|
402
|
+
if (!child) return transform.defaultOutputPoint;
|
|
403
|
+
if (transform.entity.isVertical) {
|
|
404
|
+
return {
|
|
405
|
+
x: child.outputPoint.x,
|
|
406
|
+
y: child.outputPoint.y + PositionConfig.paddingWithAddLabel / 2
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
return {
|
|
410
|
+
x: child.outputPoint.x + PositionConfig.paddingWithAddLabel / 2,
|
|
411
|
+
y: child.outputPoint.y
|
|
412
|
+
};
|
|
413
|
+
},
|
|
414
|
+
getLabels(transition) {
|
|
415
|
+
const { transform } = transition;
|
|
416
|
+
if (transform.next) {
|
|
417
|
+
if (transform.entity.isVertical) {
|
|
418
|
+
return [
|
|
419
|
+
{
|
|
420
|
+
offset: import_utils3.Point.getMiddlePoint(
|
|
421
|
+
import_utils3.Point.move(transform.outputPoint, {
|
|
422
|
+
x: 0,
|
|
423
|
+
y: PositionConfig.paddingWithAddLabel / 2
|
|
424
|
+
}),
|
|
425
|
+
transform.next.inputPoint
|
|
426
|
+
),
|
|
427
|
+
type: import_document5.FlowTransitionLabelEnum.ADDER_LABEL
|
|
428
|
+
}
|
|
429
|
+
];
|
|
430
|
+
}
|
|
431
|
+
return [
|
|
432
|
+
{
|
|
433
|
+
offset: import_utils3.Point.getMiddlePoint(
|
|
434
|
+
import_utils3.Point.move(transform.outputPoint, { x: PositionConfig.paddingWithAddLabel / 2, y: 0 }),
|
|
435
|
+
transform.next.inputPoint
|
|
436
|
+
),
|
|
437
|
+
type: import_document5.FlowTransitionLabelEnum.ADDER_LABEL
|
|
438
|
+
}
|
|
439
|
+
];
|
|
440
|
+
}
|
|
441
|
+
return [
|
|
442
|
+
{
|
|
443
|
+
offset: transform.parent.outputPoint,
|
|
444
|
+
type: import_document5.FlowTransitionLabelEnum.ADDER_LABEL
|
|
445
|
+
}
|
|
446
|
+
];
|
|
447
|
+
},
|
|
448
|
+
getOriginDeltaY(transform) {
|
|
449
|
+
const { children } = transform;
|
|
450
|
+
if (children.length === 0) {
|
|
451
|
+
return -transform.size.height * transform.origin.y;
|
|
452
|
+
}
|
|
453
|
+
return -transform.size.height * transform.origin.y - PositionConfig.paddingWithNote;
|
|
454
|
+
}
|
|
455
|
+
};
|
|
456
|
+
|
|
457
|
+
// src/registers/register-group-node.ts
|
|
458
|
+
var registerGroupNode = (ctx) => {
|
|
459
|
+
const document = ctx.get(import_document6.FlowDocument);
|
|
460
|
+
document.registerFlowNodes(GroupRegister);
|
|
461
|
+
};
|
|
462
|
+
|
|
463
|
+
// src/registers/register-clean-groups.ts
|
|
464
|
+
var import_document7 = require("@flowgram.ai/document");
|
|
465
|
+
var import_document8 = require("@flowgram.ai/document");
|
|
466
|
+
var registerCleanGroups = (ctx, opts) => {
|
|
467
|
+
const groupService = ctx.get(import_document8.FlowGroupService);
|
|
468
|
+
const document = ctx.get(import_document7.FlowDocument);
|
|
469
|
+
const clearInvalidGroups = () => {
|
|
470
|
+
groupService.getAllGroups().forEach((group) => {
|
|
471
|
+
if (group?.nodes.length !== 0) {
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
474
|
+
if (!group.groupNode.pre) {
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
groupService.deleteGroup(group.groupNode);
|
|
478
|
+
});
|
|
479
|
+
};
|
|
480
|
+
document.originTree.onTreeChange(() => {
|
|
481
|
+
setTimeout(() => {
|
|
482
|
+
clearInvalidGroups();
|
|
483
|
+
}, 0);
|
|
484
|
+
});
|
|
485
|
+
};
|
|
486
|
+
|
|
487
|
+
// src/registers/index.ts
|
|
488
|
+
var groupRegisters = {
|
|
489
|
+
["registerGroupNode" /* GroupNode */]: registerGroupNode,
|
|
490
|
+
["registerRender" /* Render */]: registerRender,
|
|
491
|
+
["registerLayer" /* Layer */]: registerLayer,
|
|
492
|
+
["registerCleanGroups" /* CleanGroups */]: registerCleanGroups
|
|
493
|
+
};
|
|
494
|
+
|
|
495
|
+
// src/create-group-plugin.tsx
|
|
496
|
+
var createGroupPlugin = (0, import_core3.definePluginCreator)({
|
|
497
|
+
onInit: (ctx, opts) => {
|
|
498
|
+
const { registers: registerConfs = {} } = opts;
|
|
499
|
+
Object.entries(groupRegisters).forEach(([key, register]) => {
|
|
500
|
+
const registerName = key;
|
|
501
|
+
const registerConf = registerConfs[registerName];
|
|
502
|
+
if (registerConf === false) {
|
|
503
|
+
return;
|
|
504
|
+
}
|
|
505
|
+
if (typeof registerConf === "function") {
|
|
506
|
+
registerConf(ctx, opts);
|
|
507
|
+
return;
|
|
508
|
+
}
|
|
509
|
+
register(ctx, opts);
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
});
|
|
513
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
514
|
+
0 && (module.exports = {
|
|
515
|
+
FlowGroupController,
|
|
516
|
+
GroupBox,
|
|
517
|
+
GroupPluginRegister,
|
|
518
|
+
GroupRegister,
|
|
519
|
+
GroupRender,
|
|
520
|
+
GroupRenderer,
|
|
521
|
+
GroupsLayer,
|
|
522
|
+
PositionConfig,
|
|
523
|
+
createGroupPlugin
|
|
524
|
+
});
|
|
525
|
+
//# sourceMappingURL=index.js.map
|