@flowgram.ai/document 0.1.0

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