@flowgram.ai/document 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.
@@ -0,0 +1,1683 @@
1
+ import * as _flowgram_ai_utils from '@flowgram.ai/utils';
2
+ import { Disposable, Emitter, IPoint, Rectangle, Event, PaddingSchema, SizeSchema as SizeSchema$1, ScrollSchema, PositionSchema as PositionSchema$1, DisposableCollection } from '@flowgram.ai/utils';
3
+ import { EntityManager, EntityDataRegistry, EntityData, SizeSchema, TransformData, PositionSchema, EntityOpts, Entity, ConfigEntity, OriginSchema } from '@flowgram.ai/core';
4
+ import { ContainerModule } from 'inversify';
5
+
6
+ /**
7
+ * 存储节点的 tree 结构信息
8
+ * 策略是 "重修改轻查询",即修改时候做的事情更多,查询都通过指针来操作
9
+ */
10
+ declare class FlowVirtualTree<T extends {
11
+ id: string;
12
+ flowNodeType?: FlowNodeType;
13
+ }> implements Disposable {
14
+ readonly root: T;
15
+ protected onTreeChangeEmitter: Emitter<void>;
16
+ /**
17
+ * tree 结构变化时候触发
18
+ */
19
+ onTreeChange: _flowgram_ai_utils.Event<void>;
20
+ protected map: Map<T, FlowVirtualTree.NodeInfo<T>>;
21
+ constructor(root: T);
22
+ dispose(): void;
23
+ getInfo(node: T): FlowVirtualTree.NodeInfo<T>;
24
+ clear(): void;
25
+ cloneMap(): Map<T, FlowVirtualTree.NodeInfo<T>>;
26
+ clone(): FlowVirtualTree<T>;
27
+ remove(node: T, withChildren?: boolean): void;
28
+ addChild(parent: T, child: T, index?: number): T;
29
+ moveChilds(parent: T, childs: T[], index?: number): T[];
30
+ getById(id: string): T | undefined;
31
+ /**
32
+ * 插入节点到后边
33
+ * @param before
34
+ * @param after
35
+ */
36
+ insertAfter(before: T, after: T): void;
37
+ removeParent(node: T): void;
38
+ private _removeChildren;
39
+ getParent(node: T): T | undefined;
40
+ getPre(node: T): T | undefined;
41
+ getNext(node: T): T | undefined;
42
+ getChildren(node: T): T[];
43
+ traverse(fn: (node: T, depth: number, index: number) => boolean | void, node?: T, depth?: number, index?: number): boolean | void;
44
+ /**
45
+ * 通知文档树结构更新
46
+ */
47
+ fireTreeChange(): void;
48
+ get size(): number;
49
+ toString(showType?: boolean): string;
50
+ }
51
+ declare namespace FlowVirtualTree {
52
+ interface NodeInfo<T> {
53
+ parent?: T;
54
+ next?: T;
55
+ pre?: T;
56
+ children: T[];
57
+ }
58
+ }
59
+
60
+ /**
61
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
62
+ * SPDX-License-Identifier: MIT
63
+ */
64
+
65
+ /**
66
+ * Render Tree 会只读模式,不具备操作 tree 结构元素
67
+ */
68
+ declare class FlowRenderTree<T extends FlowNodeEntity> extends FlowVirtualTree<T> {
69
+ readonly root: T;
70
+ protected originTree: FlowVirtualTree<T>;
71
+ protected document: FlowDocument;
72
+ /**
73
+ * 折叠的节点
74
+ * @protected
75
+ */
76
+ protected nodesCollapsed: Set<T>;
77
+ constructor(root: T, originTree: FlowVirtualTree<T>, document: FlowDocument);
78
+ isCollapsed(node: T): boolean;
79
+ get collapsedNodeList(): T[];
80
+ /**
81
+ * 折叠元素
82
+ * @param node
83
+ * @param collapsed
84
+ */
85
+ setCollapsed(node: T, collapsed: boolean): void;
86
+ /**
87
+ *
88
+ */
89
+ openNodeInsideCollapsed(node: T): void;
90
+ /**
91
+ * 更新结束节点等位置信息,分支里如果全是结束节点则要做相应的偏移
92
+ */
93
+ updateRenderStruct(): void;
94
+ /**
95
+ * 隐藏收起节点
96
+ */
97
+ protected hideCollapsed(): void;
98
+ isNodeEnd(node: T): boolean;
99
+ /**
100
+ * 优化精简分支线
101
+ * - 结束节点拉直分支线
102
+ */
103
+ protected refineBranch(block: T): void;
104
+ protected dragNextNodesToBlock(toBlock: T, next: T): void;
105
+ getInfo(node: T): FlowVirtualTree.NodeInfo<T>;
106
+ getOriginInfo(node: T): FlowVirtualTree.NodeInfo<T>;
107
+ getCollapsedChildren(node: T): T[];
108
+ remove(): void;
109
+ addChild(): T;
110
+ insertAfter(): void;
111
+ removeParent(): void;
112
+ }
113
+
114
+ /**
115
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
116
+ * SPDX-License-Identifier: MIT
117
+ */
118
+
119
+ declare const FlowDocumentOptions: unique symbol;
120
+ /**
121
+ * 流程画布配置
122
+ */
123
+ interface FlowDocumentOptions {
124
+ /**
125
+ * 布局,默认 垂直布局
126
+ */
127
+ defaultLayout?: string;
128
+ /**
129
+ * 所有节点的默认展开状态
130
+ */
131
+ allNodesDefaultExpanded?: boolean;
132
+ toNodeJSON?(node: FlowNodeEntity): FlowNodeJSON;
133
+ fromNodeJSON?(node: FlowNodeEntity, json: FlowNodeJSON, isFirstCreate: boolean): void;
134
+ constants?: Record<string, any>;
135
+ formatNodeLines?: (node: FlowNodeEntity, lines: FlowTransitionLine[]) => FlowTransitionLine[];
136
+ formatNodeLabels?: (node: FlowNodeEntity, lines: FlowTransitionLabel[]) => FlowTransitionLabel[];
137
+ /**
138
+ * 获取默认的节点配置
139
+ */
140
+ getNodeDefaultRegistry?: (type: FlowNodeType) => FlowNodeRegistry;
141
+ }
142
+ declare const FlowDocumentOptionsDefault: FlowDocumentOptions;
143
+ /**
144
+ * 支持外部 constants 自定义的 key 枚举
145
+ */
146
+ declare const ConstantKeys: {
147
+ /**
148
+ * loop 底部留白
149
+ */
150
+ INLINE_SPACING_BOTTOM: string;
151
+ /**
152
+ * inlineBlocks 的 inlineTop
153
+ * loop 循环线条上边距
154
+ */
155
+ INLINE_BLOCKS_INLINE_SPACING_TOP: string;
156
+ /**
157
+ * inlineBlocks 的 inlineBottom
158
+ * loop 循环线条的下边距
159
+ *
160
+ */
161
+ INLINE_BLOCKS_INLINE_SPACING_BOTTOM: string;
162
+ /***
163
+ * 线条、label 默认颜色
164
+ */
165
+ BASE_COLOR: string;
166
+ /***
167
+ * 线条、label 激活后的颜色
168
+ */
169
+ BASE_ACTIVATED_COLOR: string;
170
+ /**
171
+ * Branch bottom margin
172
+ * 分支下边距
173
+ */
174
+ INLINE_BLOCKS_PADDING_TOP: string;
175
+ NODE_SPACING: string;
176
+ BRANCH_SPACING: string;
177
+ ROUNDED_LINE_X_RADIUS: string;
178
+ ROUNDED_LINE_Y_RADIUS: string;
179
+ INLINE_BLOCKS_PADDING_BOTTOM: string;
180
+ COLLAPSED_SPACING: string;
181
+ HOVER_AREA_WIDTH: string;
182
+ };
183
+
184
+ /**
185
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
186
+ * SPDX-License-Identifier: MIT
187
+ */
188
+
189
+ declare const FlowDocumentContribution: unique symbol;
190
+ interface FlowDocumentContribution<T extends FlowDocument = FlowDocument> {
191
+ /**
192
+ * 注册
193
+ * @param document
194
+ */
195
+ registerDocument?(document: T): void;
196
+ /**
197
+ * 加载数据
198
+ * @param document
199
+ */
200
+ loadDocument?(document: T): Promise<void>;
201
+ }
202
+
203
+ /**
204
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
205
+ * SPDX-License-Identifier: MIT
206
+ */
207
+ declare const FlowDocumentConfigDefaultData: unique symbol;
208
+ /**
209
+ * 用于文档扩展配置
210
+ */
211
+ declare class FlowDocumentConfig {
212
+ private _data;
213
+ private onDataChangeEmitter;
214
+ readonly onChange: _flowgram_ai_utils.Event<string>;
215
+ constructor(_data?: Record<string, any>);
216
+ get(key: string): any;
217
+ set(key: string, value: any): void;
218
+ registerConfigs(config: Record<string, any>): void;
219
+ }
220
+
221
+ type FlowDocumentProvider = () => FlowDocument;
222
+ declare const FlowDocumentProvider: unique symbol;
223
+ /**
224
+ * 流程整个文档数据
225
+ */
226
+ declare class FlowDocument<T = FlowDocumentJSON> implements Disposable {
227
+ protected entityManager: EntityManager;
228
+ readonly config: FlowDocumentConfig;
229
+ /**
230
+ * 流程画布配置项
231
+ */
232
+ options: FlowDocumentOptions;
233
+ protected contributions: FlowDocumentContribution[];
234
+ protected registers: Map<FlowNodeType, FlowNodeRegistry<FlowNodeMeta>>;
235
+ private nodeRegistryCache;
236
+ protected nodeDataRegistries: EntityDataRegistry[];
237
+ protected layouts: FlowLayout[];
238
+ protected currentLayoutKey: string;
239
+ protected onNodeUpdateEmitter: Emitter<{
240
+ node: FlowNodeEntity;
241
+ /**
242
+ * use 'json' instead
243
+ * @deprecated
244
+ */
245
+ data: FlowNodeJSON;
246
+ json: FlowNodeJSON;
247
+ }>;
248
+ protected onNodeCreateEmitter: Emitter<{
249
+ node: FlowNodeEntity;
250
+ /**
251
+ * use 'json' instead
252
+ * @deprecated
253
+ */
254
+ data: FlowNodeJSON;
255
+ json: FlowNodeJSON;
256
+ }>;
257
+ protected onNodeDisposeEmitter: Emitter<{
258
+ node: FlowNodeEntity;
259
+ }>;
260
+ protected onLayoutChangeEmitter: Emitter<FlowLayout>;
261
+ readonly onNodeUpdate: _flowgram_ai_utils.Event<{
262
+ node: FlowNodeEntity;
263
+ /**
264
+ * use 'json' instead
265
+ * @deprecated
266
+ */
267
+ data: FlowNodeJSON;
268
+ json: FlowNodeJSON;
269
+ }>;
270
+ readonly onNodeCreate: _flowgram_ai_utils.Event<{
271
+ node: FlowNodeEntity;
272
+ /**
273
+ * use 'json' instead
274
+ * @deprecated
275
+ */
276
+ data: FlowNodeJSON;
277
+ json: FlowNodeJSON;
278
+ }>;
279
+ readonly onNodeDispose: _flowgram_ai_utils.Event<{
280
+ node: FlowNodeEntity;
281
+ }>;
282
+ readonly onLayoutChange: _flowgram_ai_utils.Event<FlowLayout>;
283
+ private _disposed;
284
+ root: FlowNodeEntity;
285
+ /**
286
+ * 原始的 tree 结构
287
+ */
288
+ originTree: FlowVirtualTree<FlowNodeEntity>;
289
+ transformer: FlowDocumentTransformerEntity;
290
+ /**
291
+ * 渲染相关的全局轧辊台
292
+ */
293
+ renderState: FlowRendererStateEntity;
294
+ /**
295
+ * 渲染后的 tree 结构
296
+ */
297
+ renderTree: FlowRenderTree<FlowNodeEntity>;
298
+ /**
299
+ *
300
+ */
301
+ get disposed(): boolean;
302
+ init(): void;
303
+ /**
304
+ * 从数据初始化 O(n)
305
+ * @param json
306
+ */
307
+ /**
308
+ * 加载数据,可以被重载
309
+ * @param json 文档数据更新
310
+ * @param fireRender 是否要触发渲染,默认 true
311
+ */
312
+ fromJSON(json: FlowDocumentJSON | any, fireRender?: boolean): void;
313
+ get layout(): FlowLayout;
314
+ load(): Promise<void>;
315
+ get loading(): boolean;
316
+ /**
317
+ * 触发 render
318
+ */
319
+ fireRender(): void;
320
+ /**
321
+ * 从指定节点的下一个节点新增
322
+ * @param fromNode
323
+ * @param json
324
+ */
325
+ addFromNode(fromNode: FlowNodeEntity | string, json: FlowNodeJSON): FlowNodeEntity;
326
+ removeNode(node: FlowNodeEntity | string): void;
327
+ /**
328
+ * 添加节点,如果节点已经存在则不会重复创建
329
+ * @param data
330
+ * @param addedNodes
331
+ */
332
+ addNode(data: AddNodeData, addedNodes?: FlowNodeEntity[]): FlowNodeEntity;
333
+ addBlocksAsChildren(parent: FlowNodeEntity, blocks: FlowNodeJSON[], addedNodes?: FlowNodeEntity[]): void;
334
+ /**
335
+ * block 格式:
336
+ * node: (最原始的 id)
337
+ * blockIcon
338
+ * inlineBlocks
339
+ * block
340
+ * blockOrderIcon
341
+ * block
342
+ * blockOrderIcon
343
+ * @param node
344
+ * @param blocks
345
+ * @param addedNodes
346
+ */
347
+ addInlineBlocks(node: FlowNodeEntity, blocks: FlowNodeJSON[], addedNodes?: FlowNodeEntity[]): FlowNodeEntity[];
348
+ /**
349
+ * 添加单个 block
350
+ * @param target
351
+ * @param blockData
352
+ * @param addedNodes
353
+ * @param parent 默认去找 $inlineBlocks$
354
+ */
355
+ addBlock(target: FlowNodeEntity | string, blockData: FlowNodeJSON, addedNodes?: FlowNodeEntity[], parent?: FlowNodeEntity, index?: number): FlowNodeEntity;
356
+ /**
357
+ * 根据 id 获取节点
358
+ * @param id
359
+ */
360
+ getNode(id: string): FlowNodeEntity | undefined;
361
+ /**
362
+ * 注册节点
363
+ * @param registries
364
+ */
365
+ registerFlowNodes<T extends FlowNodeRegistry<any>>(...registries: T[]): void;
366
+ /**
367
+ * Check node extend
368
+ * @param currentType
369
+ * @param parentType
370
+ */
371
+ isExtend(currentType: FlowNodeType, parentType: FlowNodeType): boolean;
372
+ /**
373
+ * 导出数据,可以重载
374
+ */
375
+ toJSON(): T | any;
376
+ /**
377
+ * @deprecated
378
+ * use `getNodeRegistry` instead
379
+ */
380
+ getNodeRegister<T extends FlowNodeRegistry = FlowNodeRegistry>(type: FlowNodeType, originParent?: FlowNodeEntity): T;
381
+ getNodeRegistry<T extends FlowNodeRegistry = FlowNodeRegistry>(type: FlowNodeType, originParent?: FlowNodeEntity): T;
382
+ /**
383
+ * 节点注入数据
384
+ * @param nodeDatas
385
+ */
386
+ registerNodeDatas(...nodeDatas: EntityDataRegistry[]): void;
387
+ /**
388
+ * traverse all nodes, O(n)
389
+ * R
390
+ * |
391
+ * +---1
392
+ * | |
393
+ * | +---1.1
394
+ * | |
395
+ * | +---1.2
396
+ * | |
397
+ * | +---1.3
398
+ * | | |
399
+ * | | +---1.3.1
400
+ * | | |
401
+ * | | +---1.3.2
402
+ * | |
403
+ * | +---1.4
404
+ * |
405
+ * +---2
406
+ * |
407
+ * +---2.1
408
+ *
409
+ * sort: [1, 1.1, 1.2, 1.3, 1.3.1, 1.3.2, 1.4, 2, 2.1]
410
+ * @param fn
411
+ * @param node
412
+ * @param depth
413
+ * @return isBreak
414
+ */
415
+ traverse(fn: (node: FlowNodeEntity, depth: number, index: number) => boolean | void, node?: FlowNodeEntity, depth?: number): boolean | void;
416
+ get size(): number;
417
+ hasNode(nodeId: string): boolean;
418
+ getAllNodes(): FlowNodeEntity[];
419
+ toString(showType?: boolean): string;
420
+ /**
421
+ * 返回需要渲染的数据
422
+ */
423
+ getRenderDatas<T extends EntityData>(dataRegistry: EntityDataRegistry<T>, containHiddenNodes?: boolean): T[];
424
+ toNodeJSON(node: FlowNodeEntity): FlowNodeJSON;
425
+ /**
426
+ * 移动节点
427
+ * @param param0
428
+ * @returns
429
+ */
430
+ moveNodes({ dropNodeId, sortNodeIds, inside, }: {
431
+ dropNodeId: string;
432
+ sortNodeIds: string[];
433
+ inside?: boolean;
434
+ }): void;
435
+ /**
436
+ * 移动子节点
437
+ * @param param0
438
+ * @returns
439
+ */
440
+ moveChildNodes({ toParentId, toIndex, nodeIds, }: {
441
+ toParentId: string;
442
+ nodeIds: string[];
443
+ toIndex: number;
444
+ }): void;
445
+ /**
446
+ * 注册布局
447
+ * @param layout
448
+ */
449
+ registerLayout(layout: FlowLayout): void;
450
+ /**
451
+ * 更新布局
452
+ * @param layoutKey
453
+ */
454
+ setLayout(layoutKey: string): void;
455
+ /**
456
+ * 切换垂直或水平布局
457
+ */
458
+ toggleFixedLayout(): void;
459
+ dispose(): void;
460
+ }
461
+
462
+ interface FlowNodeRenderSchema {
463
+ addable: boolean;
464
+ expandable: boolean;
465
+ collapsed?: boolean;
466
+ expanded: boolean;
467
+ activated: boolean;
468
+ hovered: boolean;
469
+ dragging: boolean;
470
+ stackIndex: number;
471
+ extInfo?: Record<string, any>;
472
+ }
473
+ /**
474
+ * 节点渲染状态相关数据
475
+ */
476
+ declare class FlowNodeRenderData extends EntityData<FlowNodeRenderSchema> {
477
+ static type: string;
478
+ entity: FlowNodeEntity;
479
+ private _node?;
480
+ protected onExtInfoChangeEmitter: Emitter<{
481
+ newInfo: any;
482
+ oldInfo: any;
483
+ }>;
484
+ readonly onExtInfoChange: _flowgram_ai_utils.Event<{
485
+ newInfo: any;
486
+ oldInfo: any;
487
+ }>;
488
+ get key(): string;
489
+ getDefaultData(): FlowNodeRenderSchema;
490
+ updateExtInfo(info: Record<string, any>): void;
491
+ getExtInfo(): Record<string, any> | undefined;
492
+ constructor(entity: FlowNodeEntity);
493
+ get addable(): boolean;
494
+ get expandable(): boolean;
495
+ get draggable(): boolean;
496
+ get expanded(): boolean;
497
+ set expanded(expanded: boolean);
498
+ toggleExpand(): void;
499
+ mouseLeaveTimeout?: ReturnType<typeof setTimeout>;
500
+ toggleMouseEnter(silent?: boolean): void;
501
+ toggleMouseLeave(silent?: boolean): void;
502
+ get hidden(): boolean;
503
+ set hovered(hovered: boolean);
504
+ get hovered(): boolean;
505
+ get dragging(): boolean;
506
+ set dragging(dragging: boolean);
507
+ set activated(activated: boolean);
508
+ get activated(): boolean;
509
+ get stackIndex(): number;
510
+ set stackIndex(index: number);
511
+ get lineActivated(): boolean;
512
+ get node(): HTMLDivElement;
513
+ dispose(): void;
514
+ }
515
+
516
+ interface FlowNodeTransformSchema {
517
+ size: SizeSchema;
518
+ }
519
+ declare class FlowNodeTransformData extends EntityData<FlowNodeTransformSchema> {
520
+ static type: string;
521
+ entity: FlowNodeEntity;
522
+ transform: TransformData;
523
+ renderState: FlowNodeRenderData;
524
+ localDirty: boolean;
525
+ get origin(): _flowgram_ai_utils.OriginSchema;
526
+ get key(): string;
527
+ getDefaultData(): FlowNodeTransformSchema;
528
+ constructor(entity: FlowNodeEntity);
529
+ /**
530
+ * 获取节点是否展开
531
+ */
532
+ get collapsed(): boolean;
533
+ set collapsed(collapsed: boolean);
534
+ /**
535
+ * 获取节点的大小
536
+ */
537
+ get size(): SizeSchema;
538
+ get position(): PositionSchema;
539
+ set size(size: SizeSchema);
540
+ get inputPoint(): IPoint;
541
+ get defaultInputPoint(): IPoint;
542
+ get defaultOutputPoint(): IPoint;
543
+ get outputPoint(): IPoint;
544
+ /**
545
+ * 原点的最左偏移
546
+ */
547
+ get originDeltaX(): number;
548
+ /**
549
+ * 原点 y 轴偏移
550
+ */
551
+ get originDeltaY(): number;
552
+ /**
553
+ * 绝对坐标 bbox, 不包含自身的 spacing(marginBottom), 但是包含 inlineSpacing 和 子节点的 spacing
554
+ */
555
+ get bounds(): Rectangle;
556
+ get boundsWithPadding(): Rectangle;
557
+ get isContainer(): boolean;
558
+ /**
559
+ * 相对坐标 bbox, 这里的 localBounds 会加入 padding 一起算
560
+ */
561
+ get localBounds(): Rectangle;
562
+ get padding(): _flowgram_ai_utils.PaddingSchema;
563
+ setParentTransform(transform?: FlowNodeTransformData): void;
564
+ get spacing(): number;
565
+ get inlineSpacingPre(): number;
566
+ get inlineSpacingAfter(): number;
567
+ get minInlineBlockSpacing(): number;
568
+ get children(): FlowNodeTransformData[];
569
+ /**
570
+ * 上一个节点的 transform 数据
571
+ */
572
+ get pre(): FlowNodeTransformData | undefined;
573
+ get originParent(): FlowNodeTransformData | undefined;
574
+ get isFirst(): boolean;
575
+ get isLast(): boolean;
576
+ get lastChild(): FlowNodeTransformData | undefined;
577
+ get firstChild(): FlowNodeTransformData | undefined;
578
+ /**
579
+ * 下一个节点的 transform 数据
580
+ */
581
+ get next(): FlowNodeTransformData | undefined;
582
+ /**
583
+ * parent 节点的 transform 数据
584
+ */
585
+ get parent(): FlowNodeTransformData | undefined;
586
+ }
587
+
588
+ interface FlowNodeTransitionSchema {
589
+ }
590
+ declare const drawLineToNext: (transition: FlowNodeTransitionData) => {
591
+ type: FlowTransitionLineEnum;
592
+ from: _flowgram_ai_utils.IPoint;
593
+ to: _flowgram_ai_utils.IPoint;
594
+ }[];
595
+ declare const drawLineToBottom: (transition: FlowNodeTransitionData) => {
596
+ type: FlowTransitionLineEnum;
597
+ from: _flowgram_ai_utils.IPoint;
598
+ to: _flowgram_ai_utils.IPoint;
599
+ }[];
600
+ declare class FlowNodeTransitionData extends EntityData<FlowNodeTransitionSchema> {
601
+ static type: string;
602
+ entity: FlowNodeEntity;
603
+ transform: FlowNodeTransformData;
604
+ renderData: FlowNodeRenderData;
605
+ getDefaultData(): FlowNodeTransitionSchema;
606
+ formatLines(lines: FlowTransitionLine[]): FlowTransitionLine[];
607
+ formatLabels(labels: FlowTransitionLabel[]): FlowTransitionLabel[];
608
+ get lines(): FlowTransitionLine[];
609
+ get labels(): FlowTransitionLabel[];
610
+ constructor(entity: FlowNodeEntity);
611
+ get collapsed(): boolean;
612
+ get isNodeEnd(): boolean;
613
+ }
614
+
615
+ /**
616
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
617
+ * SPDX-License-Identifier: MIT
618
+ */
619
+
620
+ interface FlowNodeEntityConfig extends EntityOpts {
621
+ document: FlowDocument;
622
+ flowNodeType: FlowNodeType;
623
+ originParent?: FlowNodeEntity;
624
+ meta?: FlowNodeMeta;
625
+ }
626
+ interface FlowNodeInitData {
627
+ originParent?: FlowNodeEntity;
628
+ parent?: FlowNodeEntity;
629
+ hidden?: boolean;
630
+ meta?: FlowNodeMeta;
631
+ index?: number;
632
+ }
633
+ declare class FlowNodeEntity extends Entity<FlowNodeEntityConfig> {
634
+ private _memoLocalCache;
635
+ private _memoGlobalCache;
636
+ static type: string;
637
+ private _registerCache?;
638
+ private _metaCache?;
639
+ metaFromJSON?: FlowNodeMeta;
640
+ /**
641
+ * 真实的父节点,条件块在内部会创建一些空的块节点,这些块需要关联它真实的父亲节点
642
+ */
643
+ originParent?: FlowNodeEntity;
644
+ flowNodeType: FlowNodeType;
645
+ /**
646
+ * 是否隐藏
647
+ */
648
+ private _hidden;
649
+ index: number;
650
+ /**
651
+ * 文档引用
652
+ */
653
+ document: FlowDocument;
654
+ constructor(conf: FlowNodeEntityConfig);
655
+ initData(initConf: FlowNodeInitData): void;
656
+ get isStart(): boolean;
657
+ get isFirst(): boolean;
658
+ get isLast(): boolean;
659
+ /**
660
+ * 子节点采用水平布局
661
+ */
662
+ get isInlineBlocks(): boolean;
663
+ /**
664
+ * 水平节点
665
+ */
666
+ get isInlineBlock(): boolean;
667
+ /**
668
+ * 节点结束标记
669
+ * - 当前节点是结束节点
670
+ * - 当前节点最后一个节点包含结束标记
671
+ * - 当前节点为 inlineBlock,每一个 block 包含结束标记
672
+ *
673
+ * 由子元素确定,因此使用 memoLocal
674
+ */
675
+ get isNodeEnd(): boolean;
676
+ /**
677
+ * 添加 子节点
678
+ *
679
+ * @param child 插入节点
680
+ */
681
+ addChild(child: FlowNodeEntity, index?: number): void;
682
+ get hasChild(): boolean;
683
+ get pre(): FlowNodeEntity | undefined;
684
+ get next(): FlowNodeEntity | undefined;
685
+ get parent(): FlowNodeEntity | undefined;
686
+ getNodeRegistry<M extends FlowNodeRegistry = FlowNodeRegistry & {
687
+ meta: FlowNodeMeta;
688
+ }>(): M;
689
+ /**
690
+ * @deprecated
691
+ * use getNodeRegistry instead
692
+ */
693
+ getNodeRegister<M extends FlowNodeRegistry = FlowNodeRegistry>(): M;
694
+ getNodeMeta<M extends FlowNodeMeta = FlowNodeMeta>(): M & Required<FlowNodeMeta>;
695
+ /**
696
+ * 获取所有子节点,包含 child 及其所有兄弟节点
697
+ */
698
+ get allChildren(): FlowNodeEntity[];
699
+ /**
700
+ * 获取所有收起的子节点,包含 child 及其所有兄弟节点
701
+ */
702
+ get allCollapsedChildren(): FlowNodeEntity[];
703
+ /**
704
+ *
705
+ * Get child blocks
706
+ *
707
+ * use `blocks` instead
708
+ * @deprecated
709
+ */
710
+ get collapsedChildren(): FlowNodeEntity[];
711
+ /**
712
+ * Get child blocks
713
+ */
714
+ get blocks(): FlowNodeEntity[];
715
+ /**
716
+ * Get last block
717
+ */
718
+ get lastBlock(): FlowNodeEntity | undefined;
719
+ /**
720
+ * use `lastBlock` instead
721
+ */
722
+ get lastCollapsedChild(): FlowNodeEntity | undefined;
723
+ /**
724
+ * 获取子节点,如果子节点收起来,则会返回 空数组
725
+ */
726
+ get children(): FlowNodeEntity[];
727
+ get lastChild(): FlowNodeEntity | undefined;
728
+ get firstChild(): FlowNodeEntity | undefined;
729
+ memoLocal<T>(key: string, fn: () => T): T;
730
+ memoGlobal<T>(key: string, fn: () => T): T;
731
+ clearMemoGlobal(): void;
732
+ clearMemoLocal(): void;
733
+ get childrenLength(): number;
734
+ get collapsed(): boolean;
735
+ set collapsed(collapsed: boolean);
736
+ get hidden(): boolean;
737
+ openInsideCollapsed(): void;
738
+ /**
739
+ * 可以重载
740
+ */
741
+ getJSONData(): any;
742
+ /**
743
+ * 生成 JSON
744
+ * @param newId
745
+ */
746
+ toJSON(): FlowNodeJSON;
747
+ get isVertical(): boolean;
748
+ /**
749
+ * 修改节点扩展信息
750
+ * @param info
751
+ */
752
+ updateExtInfo<T extends Record<string, any> = Record<string, any>>(extInfo: T): void;
753
+ /**
754
+ * 获取节点扩展信息
755
+ */
756
+ getExtInfo<T extends Record<string, any> = Record<string, any>>(): T;
757
+ get onExtInfoChange(): Event<{
758
+ newInfo: any;
759
+ oldInfo: any;
760
+ }>;
761
+ /**
762
+ * 获取渲染数据
763
+ */
764
+ get renderData(): FlowNodeRenderData;
765
+ /**
766
+ * 获取位置大小数据
767
+ */
768
+ get transform(): FlowNodeTransformData;
769
+ /**
770
+ * 获取节点的位置及大小矩形
771
+ */
772
+ get bounds(): Rectangle;
773
+ }
774
+ declare namespace FlowNodeEntity {
775
+ function is(obj: Entity): obj is FlowNodeEntity;
776
+ }
777
+
778
+ interface FlowDocumentTransformerEntityConfig extends EntityOpts {
779
+ document: FlowDocument;
780
+ }
781
+ /**
782
+ * 用于通知所有 layer 更新
783
+ */
784
+ declare class FlowDocumentTransformerEntity extends ConfigEntity<{
785
+ loading: boolean;
786
+ treeVersion: number;
787
+ }, FlowDocumentTransformerEntityConfig> {
788
+ static type: string;
789
+ protected onRefreshEmitter: Emitter<void>;
790
+ protected lastTransformVersion: number;
791
+ protected lastTreeVersion: number;
792
+ document: FlowDocument;
793
+ readonly onRefresh: _flowgram_ai_utils.Event<void>;
794
+ constructor(conf: FlowDocumentTransformerEntityConfig);
795
+ getDefaultConfig(): {
796
+ loading: boolean;
797
+ treeVersion: number;
798
+ };
799
+ get loading(): boolean;
800
+ set loading(loading: boolean);
801
+ /**
802
+ * 更新矩阵结构 (这个只有在树结构变化时候才会触发,如:添加节点、删除节点、改变位置节点)
803
+ */
804
+ updateTransformsTree(): void;
805
+ clear(): void;
806
+ isTreeDirty(): boolean;
807
+ /**
808
+ * 刷新节点的相对偏移
809
+ */
810
+ refresh(): void;
811
+ }
812
+
813
+ /**
814
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
815
+ * SPDX-License-Identifier: MIT
816
+ */
817
+
818
+ interface FlowRendererStateEntityConfig extends EntityOpts {
819
+ }
820
+ interface FlowRendererState {
821
+ nodeHoveredId?: string;
822
+ nodeDroppingId?: string;
823
+ nodeDragStartId?: string;
824
+ nodeDragIds?: string[];
825
+ nodeDragIdsWithChildren?: string[];
826
+ dragLabelSide?: LABEL_SIDE_TYPE;
827
+ }
828
+ /**
829
+ * 渲染相关的全局状态管理
830
+ */
831
+ declare class FlowRendererStateEntity extends ConfigEntity<FlowRendererState, FlowRendererStateEntityConfig> {
832
+ static type: string;
833
+ getDefaultConfig(): {};
834
+ constructor(conf: FlowRendererStateEntityConfig);
835
+ getNodeHovered(): FlowNodeEntity | undefined;
836
+ setNodeHovered(node: FlowNodeEntity | undefined): void;
837
+ getDragLabelSide(): LABEL_SIDE_TYPE | undefined;
838
+ setDragLabelSide(dragLabelSide?: LABEL_SIDE_TYPE): void;
839
+ getNodeDroppingId(): string | undefined;
840
+ setNodeDroppingId(nodeDroppingId?: string): void;
841
+ getDragStartEntity(): FlowNodeEntity | undefined;
842
+ setDragStartEntity(node?: FlowNodeEntity): void;
843
+ getDragEntities(): FlowNodeEntity[];
844
+ setDragEntities(nodes: FlowNodeEntity[]): void;
845
+ onNodeHoveredChange(fn: (hoveredNode: FlowNodeEntity | undefined) => void, debounceTime?: number): Disposable;
846
+ }
847
+
848
+ /**
849
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
850
+ * SPDX-License-Identifier: MIT
851
+ */
852
+
853
+ declare enum FlowTransitionLineEnum {
854
+ STRAIGHT_LINE = 0,
855
+ DIVERGE_LINE = 1,
856
+ MERGE_LINE = 2,
857
+ ROUNDED_LINE = 3,
858
+ CUSTOM_LINE = 4,
859
+ DRAGGING_LINE = 5
860
+ }
861
+ interface Vertex extends IPoint {
862
+ radiusX?: number;
863
+ radiusY?: number;
864
+ moveX?: number;
865
+ moveY?: number;
866
+ }
867
+ interface FlowTransitionLine {
868
+ type: FlowTransitionLineEnum;
869
+ from: IPoint;
870
+ to: IPoint;
871
+ vertices?: Vertex[];
872
+ arrow?: boolean;
873
+ renderKey?: string;
874
+ isHorizontal?: boolean;
875
+ isDraggingLine?: boolean;
876
+ activated?: boolean;
877
+ side?: LABEL_SIDE_TYPE;
878
+ style?: React.CSSProperties;
879
+ lineId?: string;
880
+ }
881
+ declare enum FlowTransitionLabelEnum {
882
+ ADDER_LABEL = 0,
883
+ TEXT_LABEL = 1,
884
+ COLLAPSE_LABEL = 2,
885
+ COLLAPSE_ADDER_LABEL = 3,
886
+ CUSTOM_LABEL = 4,
887
+ BRANCH_DRAGGING_LABEL = 5
888
+ }
889
+ interface FlowTransitionLabel {
890
+ type: FlowTransitionLabelEnum;
891
+ renderKey?: string;
892
+ offset: IPoint;
893
+ width?: number;
894
+ rotate?: string;
895
+ props?: Record<string, any>;
896
+ labelId?: string;
897
+ }
898
+ interface AdderProps {
899
+ node: FlowNodeEntity;
900
+ from: FlowNodeEntity;
901
+ to: FlowNodeEntity;
902
+ renderTo: FlowNodeEntity;
903
+ [key: string]: any;
904
+ }
905
+ interface CollapseProps {
906
+ node: FlowNodeEntity;
907
+ collapseNode: FlowNodeEntity;
908
+ activateNode?: FlowNodeEntity;
909
+ forceVisible?: boolean;
910
+ [key: string]: any;
911
+ }
912
+ interface CustomLabelProps {
913
+ node: FlowNodeEntity;
914
+ [key: string]: any;
915
+ }
916
+ interface CollapseAdderProps extends AdderProps, CollapseProps {
917
+ [key: string]: any;
918
+ }
919
+ interface DragNodeProps {
920
+ node: FlowNodeEntity;
921
+ }
922
+
923
+ /**
924
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
925
+ * SPDX-License-Identifier: MIT
926
+ */
927
+
928
+ declare enum FlowLayoutDefault {
929
+ VERTICAL_FIXED_LAYOUT = "vertical-fixed-layout",
930
+ HORIZONTAL_FIXED_LAYOUT = "horizontal-fixed-layout"
931
+ }
932
+ declare namespace FlowLayoutDefault {
933
+ function isVertical(layout: FlowLayout): boolean;
934
+ }
935
+ declare const FlowLayoutContribution: unique symbol;
936
+ interface FlowLayoutContribution {
937
+ onAfterUpdateLocalTransform?: (transform: FlowNodeTransformData, layout: FlowLayout) => void;
938
+ }
939
+ declare const FlowLayout: unique symbol;
940
+ /**
941
+ * 流程布局算法
942
+ */
943
+ interface FlowLayout {
944
+ /**
945
+ * 布局名字
946
+ */
947
+ name: string;
948
+ /**
949
+ * 布局切换时候触发
950
+ */
951
+ reload?(): void;
952
+ /**
953
+ * 更新布局
954
+ */
955
+ update(): void;
956
+ /**
957
+ * 获取节点的 padding 数据
958
+ * @param node
959
+ */
960
+ getPadding(node: FlowNodeEntity): PaddingSchema;
961
+ /**
962
+ * 获取默认滚动 目前用在 scroll-limit-layer
963
+ * @param contentSize
964
+ */
965
+ getInitScroll(contentSize: SizeSchema$1): ScrollSchema;
966
+ /**
967
+ * 获取默认输入点
968
+ */
969
+ getDefaultInputPoint(node: FlowNodeEntity): IPoint;
970
+ /**
971
+ * 获取默认输出点
972
+ */
973
+ getDefaultOutputPoint(node: FlowNodeEntity): IPoint;
974
+ /**
975
+ * 获取默认远点
976
+ */
977
+ getDefaultNodeOrigin(): IPoint;
978
+ }
979
+
980
+ /**
981
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
982
+ * SPDX-License-Identifier: MIT
983
+ */
984
+
985
+ /**
986
+ * 节点渲染相关配置信息,可扩展
987
+ */
988
+ interface FlowNodeMeta {
989
+ isStart?: boolean;
990
+ addable?: boolean;
991
+ expandable?: boolean;
992
+ draggable?: boolean | ((node: FlowNodeEntity) => boolean);
993
+ selectable?: boolean | ((node: FlowNodeEntity, mousePos?: PositionSchema$1) => boolean);
994
+ deleteDisable?: boolean;
995
+ copyDisable?: boolean;
996
+ addDisable?: boolean;
997
+ hidden?: boolean;
998
+ size?: SizeSchema;
999
+ autoResizeDisable?: boolean;
1000
+ /**
1001
+ * @deprecated 使用 NodeRegister.getOrigin 代替
1002
+ */
1003
+ origin?: OriginSchema;
1004
+ defaultExpanded?: boolean;
1005
+ defaultCollapsed?: boolean;
1006
+ spacing?: number | ((transform: FlowNodeTransformData) => number);
1007
+ padding?: PaddingSchema | ((transform: FlowNodeTransformData) => PaddingSchema);
1008
+ inlineSpacingPre?: number | ((transform: FlowNodeTransformData) => number);
1009
+ inlineSpacingAfter?: number | ((transform: FlowNodeTransformData) => number);
1010
+ renderKey?: string;
1011
+ isInlineBlocks?: boolean | ((node: FlowNodeEntity) => boolean);
1012
+ minInlineBlockSpacing?: number | ((node: FlowNodeTransformData) => number);
1013
+ isNodeEnd?: boolean;
1014
+ [key: string]: any;
1015
+ }
1016
+ /**
1017
+ * spacing default key 值
1018
+ */
1019
+ declare const DefaultSpacingKey: {
1020
+ /**
1021
+ * 普通节点间距。垂直 / 水平
1022
+ */
1023
+ NODE_SPACING: string;
1024
+ /**
1025
+ * 分支节点间距
1026
+ */
1027
+ BRANCH_SPACING: string;
1028
+ /**
1029
+ * 圆弧线条 x radius
1030
+ */
1031
+ ROUNDED_LINE_X_RADIUS: string;
1032
+ /**
1033
+ * 圆弧线条 y radius
1034
+ */
1035
+ ROUNDED_LINE_Y_RADIUS: string;
1036
+ /**
1037
+ * dynamicSplit block list 下部留白间距,因为有两个拐弯,所以翻一倍
1038
+ */
1039
+ INLINE_BLOCKS_PADDING_BOTTOM: string;
1040
+ /**
1041
+ * 复合节点距离上个节点的距离
1042
+ * 条件分支菱形下边和分支的距离
1043
+ */
1044
+ COLLAPSED_SPACING: string;
1045
+ /**
1046
+ * width of hover area
1047
+ */
1048
+ HOVER_AREA_WIDTH: string;
1049
+ };
1050
+ /**
1051
+ * 默认一些间隔参数
1052
+ */
1053
+ declare const DEFAULT_SPACING: {
1054
+ [x: string]: number;
1055
+ NULL: number;
1056
+ /**
1057
+ * @deprecated use 'BRANCH_SPACING' instead
1058
+ */
1059
+ MARGIN_RIGHT: number;
1060
+ INLINE_BLOCK_PADDING_BOTTOM: number;
1061
+ INLINE_BLOCKS_PADDING_TOP: number;
1062
+ MIN_INLINE_BLOCK_SPACING: number;
1063
+ MIN_INLINE_BLOCK_SPACING_HORIZONTAL: number;
1064
+ };
1065
+ /**
1066
+ * 拖拽种类枚举
1067
+ * 1. 节点拖拽
1068
+ * 2. 分支拖拽
1069
+ */
1070
+ declare enum DRAGGING_TYPE {
1071
+ NODE = "node",
1072
+ BRANCH = "branch"
1073
+ }
1074
+ /**
1075
+ * 拖拽分支 Adder、Line 类型
1076
+ */
1077
+ declare enum LABEL_SIDE_TYPE {
1078
+ PRE_BRANCH = "pre_branch",
1079
+ NORMAL_BRANCH = "normal_branch"
1080
+ }
1081
+ /**
1082
+ * 默认节点大小
1083
+ */
1084
+ declare const DEFAULT_SIZE: {
1085
+ width: number;
1086
+ height: number;
1087
+ };
1088
+ /**
1089
+ * 默认 meta 配置
1090
+ */
1091
+ declare const DEFAULT_FLOW_NODE_META: (nodeType: FlowNodeType, document: FlowDocument) => FlowNodeMeta;
1092
+ /**
1093
+ * 节点注册
1094
+ */
1095
+ interface FlowNodeRegistry<M extends FlowNodeMeta = FlowNodeMeta> {
1096
+ /**
1097
+ * 从另外一个注册扩展
1098
+ */
1099
+ extend?: string;
1100
+ /**
1101
+ * 节点类型
1102
+ */
1103
+ type: FlowNodeType;
1104
+ /**
1105
+ * 节点注册的数据,可以理解为 ECS 里的 Component, 这里可以配置自定义数据
1106
+ */
1107
+ dataRegistries?: EntityDataRegistry[];
1108
+ /**
1109
+ * 节点画布相关初始化配置信息,会覆盖 DEFAULT_FLOW_NODE_META
1110
+ */
1111
+ meta?: Partial<M>;
1112
+ /**
1113
+ * 自定义创建节点,可以自定义节点的树形结构
1114
+ * 返回新加入的节点,这样才能统计缓存
1115
+ *
1116
+ * @action 使用该方法,在创建时候将会忽略 json blocks 数据,而是交给适用节点自己处理 json 逻辑
1117
+ */
1118
+ onCreate?: (node: FlowNodeEntity, json: FlowNodeJSON) => FlowNodeEntity[] | void;
1119
+ /**
1120
+ * 添加子 block,一般用于分支的动态添加
1121
+ */
1122
+ onBlockChildCreate?: (node: FlowNodeEntity, json: FlowNodeJSON, addedNodes?: FlowNodeEntity[]) => FlowNodeEntity;
1123
+ /**
1124
+ * 创建线条
1125
+ */
1126
+ getLines?: (transition: FlowNodeTransitionData, layout: FlowLayout) => FlowTransitionLine[];
1127
+ /**
1128
+ * 创建 label
1129
+ */
1130
+ getLabels?: (transition: FlowNodeTransitionData, layout: FlowLayout) => FlowTransitionLabel[];
1131
+ /**
1132
+ * 调整子节点的线条,优先级高于子节点本身的 getLines
1133
+ */
1134
+ getChildLines?: (transition: FlowNodeTransitionData, layout: FlowLayout) => FlowTransitionLine[];
1135
+ /**
1136
+ * 调整子节点的 Labels,优先级高于子节点本身的 getLabels
1137
+ */
1138
+ getChildLabels?: (transition: FlowNodeTransitionData, layout: FlowLayout) => FlowTransitionLabel[];
1139
+ /**
1140
+ * 自定义输入节点
1141
+ */
1142
+ getInputPoint?: (transform: FlowNodeTransformData, layout: FlowLayout) => IPoint;
1143
+ /**
1144
+ * 自定义输出节点
1145
+ */
1146
+ getOutputPoint?: (transform: FlowNodeTransformData, layoutKey: FlowLayout) => IPoint;
1147
+ /**
1148
+ * 获取当前节点 Position 偏移量,偏移量计算只能使用已经计算完的数据,如上一个节点或者子节点,不然会造成 o(n^2) 复杂度
1149
+ *
1150
+ * 1. 切记不要用当前节点的 localBounds(相对位置 bbox),因为 delta 计算发生在 localBounds 计算之前
1151
+ * 2. 切记不要用 bounds(绝对位置 bbox, 会触发所有父节点绝对位置计算), bounds 只能在最终 render 时候使用
1152
+ * 3. 可以用 pre 节点 和 子节点的 localBounds 或者 size 数据,因为子节点是先算的
1153
+ * 4. 可以用当前节点的 size (所有子节点的最大 bbox), 这是已经确定下来的
1154
+ */
1155
+ getDelta?: (transform: FlowNodeTransformData, layout: FlowLayout) => IPoint | undefined;
1156
+ /**
1157
+ * 动态获取原点,会覆盖 meta.origin
1158
+ */
1159
+ getOrigin?(transform: FlowNodeTransformData, layout: FlowLayout): IPoint;
1160
+ /**
1161
+ * 原点 X 偏移
1162
+ * @param transform
1163
+ */
1164
+ getOriginDeltaX?: (transform: FlowNodeTransformData, layout: FlowLayout) => number;
1165
+ /**
1166
+ * 原点 Y 偏移
1167
+ * @param transform
1168
+ */
1169
+ getOriginDeltaY?: (transform: FlowNodeTransformData, layout: FlowLayout) => number;
1170
+ /**
1171
+ * 通过 parent 计算当前节点的偏移,规则同 getDelta
1172
+ */
1173
+ getChildDelta?: (childBlock: FlowNodeTransformData, layout: FlowLayout) => IPoint | undefined;
1174
+ /**
1175
+ * 在当前节点布局完成后调用,可以对布局做更精细的调整
1176
+ */
1177
+ onAfterUpdateLocalTransform?: (transform: FlowNodeTransformData, layout: FlowLayout) => void;
1178
+ /**
1179
+ * 子节点的 registry 覆盖,这里通过 originParent 来查找
1180
+ */
1181
+ extendChildRegistries?: FlowNodeRegistry[];
1182
+ /**
1183
+ * @deprecated
1184
+ * 自定义子节点添加逻辑
1185
+ * @param node 节点
1186
+ * @param json 添加的节点 JSON
1187
+ * @param options 其它配置
1188
+ * @returns
1189
+ */
1190
+ addChild?: (node: FlowNodeEntity, json: FlowNodeJSON, options?: {
1191
+ hidden?: boolean;
1192
+ index?: number;
1193
+ }) => FlowNodeEntity;
1194
+ /**
1195
+ * 内部用于继承逻辑判断,不要使用
1196
+ */
1197
+ __extends__?: FlowNodeType[];
1198
+ /**
1199
+ * 扩展注册器
1200
+ */
1201
+ [key: string]: any;
1202
+ }
1203
+ declare namespace FlowNodeRegistry {
1204
+ function mergeChildRegistries(r1?: FlowNodeRegistry[], r2?: FlowNodeRegistry[]): FlowNodeRegistry[];
1205
+ function merge(registry1: FlowNodeRegistry, registry2: FlowNodeRegistry, finalType: FlowNodeType): FlowNodeRegistry;
1206
+ function extend(registry: FlowNodeRegistry, extendRegistries: FlowNodeRegistry[]): FlowNodeRegistry;
1207
+ }
1208
+
1209
+ /**
1210
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
1211
+ * SPDX-License-Identifier: MIT
1212
+ */
1213
+
1214
+ type FlowNodeType = string | number;
1215
+ /**
1216
+ * Flow node json data
1217
+ */
1218
+ interface FlowNodeJSON {
1219
+ id: string;
1220
+ type?: FlowNodeBaseType | FlowNodeSplitType | FlowNodeType;
1221
+ data?: Record<string, any>;
1222
+ meta?: FlowNodeMeta;
1223
+ blocks?: FlowNodeJSON[];
1224
+ }
1225
+ type FlowDocumentJSON = {
1226
+ nodes: FlowNodeJSON[];
1227
+ };
1228
+ declare enum FlowNodeBaseType {
1229
+ START = "start",
1230
+ DEFAULT = "default",
1231
+ ROOT = "root",
1232
+ EMPTY = "empty",
1233
+ INLINE_BLOCKS = "inlineBlocks",
1234
+ BLOCK_ICON = "blockIcon",
1235
+ BLOCK = "block",
1236
+ BLOCK_ORDER_ICON = "blockOrderIcon",
1237
+ GROUP = "group",
1238
+ END = "end",
1239
+ BREAK = "break",
1240
+ CONDITION = "condition",
1241
+ SUB_CANVAS = "subCanvas",
1242
+ MULTI_INPUTS = "multiInputs",
1243
+ MULTI_OUTPUTS = "multiOutputs",
1244
+ INPUT = "input",
1245
+ OUTPUT = "output"
1246
+ }
1247
+ declare enum FlowNodeSplitType {
1248
+ SIMPLE_SPLIT = "simpleSplit",
1249
+ DYNAMIC_SPLIT = "dynamicSplit",
1250
+ STATIC_SPLIT = "staticSplit"
1251
+ }
1252
+ declare enum FlowDocumentConfigEnum {
1253
+ END_NODES_REFINE_BRANCH = "END_NODES_REFINE_BRANCH"
1254
+ }
1255
+ declare const FLOW_DEFAULT_HIDDEN_TYPES: FlowNodeType[];
1256
+ type AddNodeData = FlowNodeJSON & {
1257
+ originParent?: FlowNodeEntity;
1258
+ parent?: FlowNodeEntity;
1259
+ hidden?: boolean;
1260
+ index?: number;
1261
+ };
1262
+
1263
+ /**
1264
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
1265
+ * SPDX-License-Identifier: MIT
1266
+ */
1267
+
1268
+ declare enum OperationType {
1269
+ addFromNode = "addFromNode",
1270
+ deleteFromNode = "deleteFromNode",
1271
+ addBlock = "addBlock",
1272
+ deleteBlock = "deleteBlock",
1273
+ createGroup = "createGroup",
1274
+ ungroup = "ungroup",
1275
+ moveNodes = "moveNodes",
1276
+ moveBlock = "moveBlock",
1277
+ moveChildNodes = "moveChildNodes",
1278
+ addNodes = "addNodes",
1279
+ deleteNodes = "deleteNodes",
1280
+ changeNode = "changeNode",
1281
+ addChildNode = "addChildNode",
1282
+ deleteChildNode = "deleteChildNode",
1283
+ addNode = "addNode",
1284
+ deleteNode = "deleteNode"
1285
+ }
1286
+ interface AddOrDeleteFromNodeOperationValue {
1287
+ fromId: string;
1288
+ data: FlowNodeJSON;
1289
+ }
1290
+ interface AddOrDeleteNodeOperationValue {
1291
+ fromId: string;
1292
+ data: FlowNodeJSON;
1293
+ }
1294
+ interface AddFromNodeOperation {
1295
+ type: OperationType.addFromNode;
1296
+ value: AddOrDeleteFromNodeOperationValue;
1297
+ }
1298
+ interface DeleteFromNodeOperation {
1299
+ type: OperationType.deleteFromNode;
1300
+ value: AddOrDeleteFromNodeOperationValue;
1301
+ }
1302
+ interface AddOrDeleteBlockValue {
1303
+ targetId: string;
1304
+ index?: number;
1305
+ blockData: FlowNodeJSON;
1306
+ parentId?: string;
1307
+ }
1308
+ interface createOrUngroupValue {
1309
+ targetId: string;
1310
+ groupId: string;
1311
+ nodeIds: string[];
1312
+ }
1313
+ interface AddBlockOperation {
1314
+ type: OperationType.addBlock;
1315
+ value: AddOrDeleteBlockValue;
1316
+ }
1317
+ interface DeleteBlockOperation {
1318
+ type: OperationType.deleteBlock;
1319
+ value: AddOrDeleteBlockValue;
1320
+ }
1321
+ interface CreateGroupOperation {
1322
+ type: OperationType.createGroup;
1323
+ value: createOrUngroupValue;
1324
+ }
1325
+ interface UngroupOperation {
1326
+ type: OperationType.ungroup;
1327
+ value: createOrUngroupValue;
1328
+ }
1329
+ interface MoveNodesOperationValue {
1330
+ fromId: string;
1331
+ toId: string;
1332
+ nodeIds: string[];
1333
+ }
1334
+ interface MoveNodesOperation {
1335
+ type: OperationType.moveNodes;
1336
+ value: MoveNodesOperationValue;
1337
+ }
1338
+ interface AddOrDeleteNodesOperationValue {
1339
+ fromId: string;
1340
+ nodes: FlowNodeJSON[];
1341
+ }
1342
+ interface AddNodesOperation {
1343
+ type: OperationType.addNodes;
1344
+ value: AddOrDeleteNodesOperationValue;
1345
+ }
1346
+ interface DeleteNodesOperation {
1347
+ type: OperationType.deleteNodes;
1348
+ value: AddOrDeleteNodesOperationValue;
1349
+ }
1350
+ interface ChangeNodeOperationValue {
1351
+ id: string;
1352
+ path: string;
1353
+ oldValue: any;
1354
+ value: any;
1355
+ }
1356
+ interface ChangeNodeOperation {
1357
+ type: OperationType.changeNode;
1358
+ value: ChangeNodeOperationValue;
1359
+ }
1360
+ interface MoveChildNodesOperationValue {
1361
+ nodeIds: string[];
1362
+ fromParentId: string;
1363
+ fromIndex: number;
1364
+ toParentId: string;
1365
+ toIndex: number;
1366
+ }
1367
+ type MoveBlockOperationValue = {
1368
+ nodeId: string;
1369
+ fromParentId: string;
1370
+ fromIndex: number;
1371
+ toParentId: string;
1372
+ toIndex: number;
1373
+ };
1374
+ interface MoveBlockOperation {
1375
+ type: OperationType.moveBlock;
1376
+ value: MoveBlockOperationValue;
1377
+ }
1378
+ interface MoveChildNodesOperation {
1379
+ type: OperationType.moveChildNodes;
1380
+ value: MoveChildNodesOperationValue;
1381
+ }
1382
+ interface AddChildNodeOperation {
1383
+ type: OperationType.addChildNode;
1384
+ value: AddOrDeleteChildNodeValue;
1385
+ }
1386
+ interface DeleteChildNodeOperation {
1387
+ type: OperationType.deleteChildNode;
1388
+ value: AddOrDeleteChildNodeValue;
1389
+ }
1390
+ interface AddOrDeleteChildNodeValue {
1391
+ data: FlowNodeJSON;
1392
+ parentId?: string;
1393
+ index?: number;
1394
+ originParentId?: string;
1395
+ hidden?: boolean;
1396
+ }
1397
+ interface AddNodeOperation {
1398
+ type: OperationType.addNode;
1399
+ value: AddOrDeleteNodeValue;
1400
+ }
1401
+ interface DeleteNodeOperation {
1402
+ type: OperationType.deleteNode;
1403
+ value: AddOrDeleteNodeValue;
1404
+ }
1405
+ interface AddOrDeleteNodeValue {
1406
+ data: FlowNodeJSON;
1407
+ parentId?: string;
1408
+ index?: number;
1409
+ hidden?: boolean;
1410
+ }
1411
+ type FlowOperation = AddFromNodeOperation | DeleteFromNodeOperation | AddBlockOperation | DeleteBlockOperation | CreateGroupOperation | UngroupOperation | MoveNodesOperation | AddNodesOperation | DeleteNodesOperation | ChangeNodeOperation | MoveBlockOperation | AddChildNodeOperation | DeleteChildNodeOperation | MoveChildNodesOperation | AddNodeOperation | DeleteNodeOperation;
1412
+ type FlowNodeEntityOrId = string | FlowNodeEntity;
1413
+ type AddNodeConfig = {
1414
+ parent?: FlowNodeEntityOrId;
1415
+ hidden?: boolean;
1416
+ index?: number;
1417
+ };
1418
+ /**
1419
+ * 添加block时的配置
1420
+ */
1421
+ interface AddBlockConfig {
1422
+ parent?: FlowNodeEntity;
1423
+ index?: number;
1424
+ }
1425
+ /**
1426
+ * 移动节点时的配置
1427
+ */
1428
+ interface MoveNodeConfig {
1429
+ parent?: FlowNodeEntityOrId;
1430
+ index?: number;
1431
+ }
1432
+ /**
1433
+ * 节点添加事件
1434
+ */
1435
+ interface OnNodeAddEvent {
1436
+ node: FlowNodeEntity;
1437
+ data: AddNodeData;
1438
+ }
1439
+ /**
1440
+ * 节点移动事件
1441
+ */
1442
+ interface OnNodeMoveEvent {
1443
+ node: FlowNodeEntity;
1444
+ fromParent: FlowNodeEntity;
1445
+ fromIndex: number;
1446
+ toParent: FlowNodeEntity;
1447
+ toIndex: number;
1448
+ }
1449
+ interface FlowOperationBaseService extends Disposable {
1450
+ /**
1451
+ * 执行操作
1452
+ * @param operation 可序列化的操作
1453
+ * @returns 操作返回
1454
+ */
1455
+ apply(operation: FlowOperation): any;
1456
+ /**
1457
+ * 添加节点,如果节点已经存在则不会重复创建
1458
+ * @param nodeJSON 节点数据
1459
+ * @param config 配置
1460
+ * @returns 成功添加的节点
1461
+ */
1462
+ addNode(nodeJSON: FlowNodeJSON, config?: AddNodeConfig): FlowNodeEntity;
1463
+ /**
1464
+ * 基于某一个起始节点往后面添加
1465
+ * @param fromNode 起始节点
1466
+ * @param nodeJSON 添加的节点JSON
1467
+ */
1468
+ addFromNode(fromNode: FlowNodeEntityOrId, nodeJSON: FlowNodeJSON): FlowNodeEntity;
1469
+ /**
1470
+ * 删除节点
1471
+ * @param node 节点
1472
+ * @returns
1473
+ */
1474
+ deleteNode(node: FlowNodeEntityOrId): void;
1475
+ /**
1476
+ * 批量删除节点
1477
+ * @param nodes
1478
+ */
1479
+ deleteNodes(nodes: FlowNodeEntityOrId[]): void;
1480
+ /**
1481
+ * 添加块(分支)
1482
+ * @param target 目标
1483
+ * @param blockJSON 块数据
1484
+ * @param config 配置
1485
+ * @returns
1486
+ */
1487
+ addBlock(target: FlowNodeEntityOrId, blockJSON: FlowNodeJSON, config?: AddBlockConfig): FlowNodeEntity;
1488
+ /**
1489
+ * 移动节点
1490
+ * @param node 被移动的节点
1491
+ * @param config 移动节点配置
1492
+ */
1493
+ moveNode(node: FlowNodeEntityOrId, config?: MoveNodeConfig): void;
1494
+ /**
1495
+ * 拖拽节点
1496
+ * @param param0
1497
+ * @returns
1498
+ */
1499
+ dragNodes({ dropNode, nodes }: {
1500
+ dropNode: FlowNodeEntity;
1501
+ nodes: FlowNodeEntity[];
1502
+ }): void;
1503
+ /**
1504
+ * 添加节点的回调
1505
+ */
1506
+ onNodeAdd: Event<OnNodeAddEvent>;
1507
+ /**
1508
+ * 节点移动的回调
1509
+ */
1510
+ onNodeMove: Event<OnNodeMoveEvent>;
1511
+ }
1512
+ declare const FlowOperationBaseService: unique symbol;
1513
+
1514
+ /**
1515
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
1516
+ * SPDX-License-Identifier: MIT
1517
+ */
1518
+ interface FlowGroupJSON {
1519
+ nodeIDs: string[];
1520
+ }
1521
+
1522
+ /**
1523
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
1524
+ * SPDX-License-Identifier: MIT
1525
+ */
1526
+
1527
+ declare const FlowDocumentContainerModule: ContainerModule;
1528
+
1529
+ /**
1530
+ * 拖拽相关操作
1531
+ * 外部实现抽象类
1532
+ */
1533
+ declare class FlowDragService {
1534
+ protected document: FlowDocument;
1535
+ protected operationService: FlowOperationBaseService;
1536
+ protected entityManager: EntityManager;
1537
+ protected onDropEmitter: Emitter<{
1538
+ dropNode: FlowNodeEntity;
1539
+ dragNodes: FlowNodeEntity[];
1540
+ }>;
1541
+ readonly onDrop: _flowgram_ai_utils.Event<{
1542
+ dropNode: FlowNodeEntity;
1543
+ dragNodes: FlowNodeEntity[];
1544
+ }>;
1545
+ get renderState(): FlowRendererStateEntity;
1546
+ get dragStartNode(): FlowNodeEntity;
1547
+ get dragNodes(): FlowNodeEntity[];
1548
+ get dropNodeId(): string | undefined;
1549
+ get isDragBranch(): boolean;
1550
+ get nodeDragIdsWithChildren(): string[];
1551
+ get dragging(): boolean;
1552
+ get labelSide(): LABEL_SIDE_TYPE | undefined;
1553
+ /**
1554
+ * 放置到目标分支
1555
+ */
1556
+ dropBranch(): void;
1557
+ /**
1558
+ * 移动到目标节点
1559
+ */
1560
+ dropNode(): void;
1561
+ /**
1562
+ * 拖拽是否可以释放在该节点后面
1563
+ */
1564
+ isDroppableNode(node: FlowNodeEntity): boolean;
1565
+ /**
1566
+ * 拖拽分支是否可以释放在该分支
1567
+ * @param node 拖拽的分支节点
1568
+ * @param side 分支的前面还是后面
1569
+ */
1570
+ isDroppableBranch(node: FlowNodeEntity, side?: LABEL_SIDE_TYPE): boolean;
1571
+ }
1572
+
1573
+ /**
1574
+ * 操作服务
1575
+ */
1576
+ declare class FlowOperationBaseServiceImpl implements FlowOperationBaseService {
1577
+ protected entityManager: EntityManager;
1578
+ protected document: FlowDocument;
1579
+ protected onNodeAddEmitter: Emitter<OnNodeAddEvent>;
1580
+ readonly onNodeAdd: _flowgram_ai_utils.Event<OnNodeAddEvent>;
1581
+ protected toDispose: DisposableCollection;
1582
+ private onNodeMoveEmitter;
1583
+ readonly onNodeMove: _flowgram_ai_utils.Event<OnNodeMoveEvent>;
1584
+ protected init(): void;
1585
+ addNode(nodeJSON: FlowNodeJSON, config?: AddNodeConfig): FlowNodeEntity;
1586
+ addFromNode(fromNode: FlowNodeEntityOrId, nodeJSON: FlowNodeJSON): FlowNodeEntity;
1587
+ deleteNode(node: FlowNodeEntityOrId): void;
1588
+ deleteNodes(nodes: FlowNodeEntityOrId[]): void;
1589
+ addBlock(target: FlowNodeEntityOrId, blockJSON: FlowNodeJSON, config?: AddBlockConfig): FlowNodeEntity;
1590
+ moveNode(node: FlowNodeEntityOrId, config?: MoveNodeConfig): void;
1591
+ /**
1592
+ * 拖拽节点
1593
+ * @param param0
1594
+ * @returns
1595
+ */
1596
+ dragNodes({ dropNode, nodes }: {
1597
+ dropNode: FlowNodeEntity;
1598
+ nodes: FlowNodeEntity[];
1599
+ }): any;
1600
+ /**
1601
+ * 执行操作
1602
+ * @param operation 可序列化的操作
1603
+ * @returns 操作返回
1604
+ */
1605
+ apply(operation: FlowOperation): any;
1606
+ /**
1607
+ * 事务执行
1608
+ * @param transaction
1609
+ */
1610
+ transact(transaction: () => void): void;
1611
+ dispose(): void;
1612
+ protected toId(node: FlowNodeEntityOrId): string;
1613
+ protected toNodeEntity(node: FlowNodeEntityOrId): FlowNodeEntity | undefined;
1614
+ protected getNodeIndex(node: FlowNodeEntityOrId): number;
1615
+ protected doMoveNode(node: FlowNodeEntity, newParent: FlowNodeEntity, index: number): void;
1616
+ }
1617
+
1618
+ /**
1619
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
1620
+ * SPDX-License-Identifier: MIT
1621
+ */
1622
+
1623
+ /** 分组控制器 */
1624
+ declare class FlowGroupController {
1625
+ readonly groupNode: FlowNodeEntity;
1626
+ private constructor();
1627
+ get nodes(): FlowNodeEntity[];
1628
+ get collapsed(): boolean;
1629
+ collapse(): void;
1630
+ expand(): void;
1631
+ /** 获取分组外围的最大边框 */
1632
+ get bounds(): Rectangle;
1633
+ /** 是否是开始节点 */
1634
+ isStartNode(node?: FlowNodeEntity): boolean;
1635
+ /** 是否是结束节点 */
1636
+ isEndNode(node?: FlowNodeEntity): boolean;
1637
+ set note(note: string);
1638
+ get note(): string;
1639
+ set noteHeight(height: number);
1640
+ get noteHeight(): number;
1641
+ get positionConfig(): Record<string, number>;
1642
+ private set collapsed(value);
1643
+ set hovered(hovered: boolean);
1644
+ get hovered(): boolean;
1645
+ static create(groupNode?: FlowNodeEntity): FlowGroupController | undefined;
1646
+ }
1647
+
1648
+ /**
1649
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
1650
+ * SPDX-License-Identifier: MIT
1651
+ */
1652
+
1653
+ declare class FlowGroupService {
1654
+ readonly entityManager: EntityManager;
1655
+ readonly operationService: FlowOperationBaseService;
1656
+ /** 创建分组节点 */
1657
+ createGroup(nodes: FlowNodeEntity[]): FlowNodeEntity | undefined;
1658
+ /** 删除分组 */
1659
+ deleteGroup(groupNode: FlowNodeEntity): void;
1660
+ /** 取消分组 */
1661
+ ungroup(groupNode: FlowNodeEntity): void;
1662
+ /** 返回所有分组节点 */
1663
+ getAllGroups(): FlowGroupController[];
1664
+ /** 获取分组控制器*/
1665
+ groupController(group: FlowNodeEntity): FlowGroupController | undefined;
1666
+ static validate(nodes: FlowNodeEntity[]): boolean;
1667
+ }
1668
+
1669
+ /**
1670
+ * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
1671
+ * SPDX-License-Identifier: MIT
1672
+ */
1673
+
1674
+ /**
1675
+ *
1676
+ * @param node 节点 entity
1677
+ * @param key 从 DocumentOptions 里获取 constants 的 key
1678
+ * @param defaultSpacing 默认从 DEFAULT_SPACING 获取 spacing,也可以外部传入默认值
1679
+ * @returns
1680
+ */
1681
+ declare const getDefaultSpacing: (node: FlowNodeEntity, key: string, defaultSpacing?: number) => any;
1682
+
1683
+ export { type AddBlockConfig, type AddBlockOperation, type AddChildNodeOperation, type AddFromNodeOperation, type AddNodeConfig, type AddNodeData, type AddNodeOperation, type AddNodesOperation, type AddOrDeleteBlockValue, type AddOrDeleteChildNodeValue, type AddOrDeleteFromNodeOperationValue, type AddOrDeleteNodeOperationValue, type AddOrDeleteNodeValue, type AddOrDeleteNodesOperationValue, type AdderProps, type ChangeNodeOperation, type ChangeNodeOperationValue, type CollapseAdderProps, type CollapseProps, ConstantKeys, type CreateGroupOperation, type CustomLabelProps, DEFAULT_FLOW_NODE_META, DEFAULT_SIZE, DEFAULT_SPACING, DRAGGING_TYPE, DefaultSpacingKey, type DeleteBlockOperation, type DeleteChildNodeOperation, type DeleteFromNodeOperation, type DeleteNodeOperation, type DeleteNodesOperation, type DragNodeProps, FLOW_DEFAULT_HIDDEN_TYPES, FlowDocument, FlowDocumentConfig, FlowDocumentConfigDefaultData, FlowDocumentConfigEnum, FlowDocumentContainerModule, FlowDocumentContribution, type FlowDocumentJSON, FlowDocumentOptions, FlowDocumentOptionsDefault, FlowDocumentProvider, FlowDocumentTransformerEntity, FlowDragService, FlowGroupController, type FlowGroupJSON, FlowGroupService, FlowLayout, FlowLayoutContribution, FlowLayoutDefault, FlowNodeBaseType, FlowNodeEntity, type FlowNodeEntityConfig, type FlowNodeEntityOrId, type FlowNodeInitData, type FlowNodeJSON, type FlowNodeMeta, FlowNodeRegistry, FlowNodeRenderData, type FlowNodeRenderSchema, FlowNodeSplitType, FlowNodeTransformData, type FlowNodeTransformSchema, FlowNodeTransitionData, type FlowNodeTransitionSchema, type FlowNodeType, type FlowOperation, FlowOperationBaseService, FlowOperationBaseServiceImpl, FlowRendererStateEntity, type FlowTransitionLabel, FlowTransitionLabelEnum, type FlowTransitionLine, FlowTransitionLineEnum, FlowVirtualTree, LABEL_SIDE_TYPE, type MoveBlockOperation, type MoveBlockOperationValue, type MoveChildNodesOperation, type MoveChildNodesOperationValue, type MoveNodeConfig, type MoveNodesOperation, type MoveNodesOperationValue, type OnNodeAddEvent, type OnNodeMoveEvent, OperationType, type UngroupOperation, type Vertex, type createOrUngroupValue, drawLineToBottom, drawLineToNext, getDefaultSpacing };