@blueking/flow-canvas 0.0.3 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -112,7 +112,7 @@ type CanvasCommand = {
112
112
  path: string[];
113
113
  value: unknown;
114
114
  };
115
- type CommandSource = 'user:drag' | 'user:keyboard' | 'user:toolbar' | 'user:quick-add' | 'user:panel' | 'plugin' | 'system' | 'system:replace';
115
+ type CommandSource = 'user:drag' | 'user:edge-drop' | 'user:keyboard' | 'user:toolbar' | 'user:quick-add' | 'user:panel' | 'plugin' | 'system' | 'system:replace';
116
116
  interface CommandEnvelope {
117
117
  id: string;
118
118
  label?: string;
@@ -207,6 +207,8 @@ type CanvasUiEvent = {
207
207
  type: 'node.action.quick-insert';
208
208
  sourceNodeId: string;
209
209
  newNodeId: string;
210
+ } | {
211
+ type: 'toolbar.auto-layout';
210
212
  };
211
213
 
212
214
  interface CanvasHistory {
@@ -244,6 +246,8 @@ interface RuntimePluginContext extends EditorPluginContext {
244
246
  api: CanvasApi;
245
247
  overlay: OverlayManager;
246
248
  graph: Graph;
249
+ /** 框选模式是否激活(由 editor.selectionMode 驱动) */
250
+ selectionMode: Readonly<Ref<boolean>>;
247
251
  }
248
252
  interface CanvasSelection {
249
253
  nodeIds: string[];
@@ -288,7 +292,12 @@ interface CanvasPlugin {
288
292
  extendApi?(api: CanvasApi, ctx: RuntimePluginContext): Record<string, Function>;
289
293
  }
290
294
 
291
- type BuiltinToolbarType = 'undo' | 'redo' | 'select' | 'auto-layout' | 'search' | 'minimap' | 'export' | 'zoom-in' | 'zoom-out' | 'zoom-display' | 'fit' | 'reset';
295
+ type CoreToolbarType = 'undo' | 'redo' | 'select' | 'auto-layout' | 'export' | 'zoom-in' | 'zoom-out' | 'zoom-display' | 'fit' | 'reset';
296
+ /**
297
+ * 这类工具项默认由内置插件提供入口与行为,toolbar 壳层只负责渲染与隐藏控制。
298
+ */
299
+ type PluginManagedToolbarType = 'search' | 'minimap';
300
+ type BuiltinToolbarType = CoreToolbarType | PluginManagedToolbarType;
292
301
  interface CanvasToolbarItem {
293
302
  id: string;
294
303
  type: BuiltinToolbarType | 'custom';
@@ -304,12 +313,21 @@ interface CanvasToolbarItem {
304
313
  order?: number;
305
314
  visible?: boolean | ((ctx: CanvasCallbackContext) => boolean);
306
315
  disabled?: boolean | ((ctx: CanvasCallbackContext) => boolean);
316
+ active?: boolean | ((ctx: CanvasCallbackContext) => boolean);
307
317
  onClick?: (ctx: CanvasCallbackContext) => void;
308
318
  }
309
319
  interface ExportOptions {
310
320
  backgroundColor?: string;
311
321
  padding?: number;
312
322
  quality?: number;
323
+ /** 输出图片的缩放倍率,默认跟随 devicePixelRatio */
324
+ scale?: number;
325
+ }
326
+ interface DeleteSelectionOptions {
327
+ selection?: CanvasSelection;
328
+ source?: CommandSource;
329
+ label?: string;
330
+ clearSelectionAfterApply?: boolean;
313
331
  }
314
332
  interface NodeActionsConfig {
315
333
  showDebug?: boolean;
@@ -336,13 +354,14 @@ interface CanvasApi {
336
354
  scrollToOrigin(): void;
337
355
  scrollToNode(nodeId: string): void;
338
356
  getSelection(): CanvasSelection;
357
+ getSelectionBounds(selection?: CanvasSelection): DOMRect | null;
339
358
  selectNodes(ids: string[]): void;
340
359
  selectEdges(ids: string[]): void;
341
360
  clearSelection(): void;
361
+ deleteSelection(options?: DeleteSelectionOptions): CommandExecutionResult | null;
342
362
  registerDndSource(el: HTMLElement, factory: () => FlowNodeModel): () => void;
343
363
  startConnection(nodeId: string, portId?: string): void;
344
364
  exportAsImage(options?: ExportOptions): Promise<Blob>;
345
- exportAsSVG(): Promise<string>;
346
365
  highlightNodes(nodeIds: string[]): void;
347
366
  highlightEdges(edgeIds: string[]): void;
348
367
  clearHighlight(): void;
@@ -381,8 +400,6 @@ type QuickAddInsertDirectionResolver = (node: FlowNodeModel, port: FlowPortModel
381
400
  interface QuickAddConfig {
382
401
  /** 全局开关,默认 true */
383
402
  enabled?: boolean;
384
- /** "+"按钮 hover 时的 tooltip 文案 */
385
- tooltipText?: string;
386
403
  /** quick-add 绑定的端口分组,默认 'right';节点不存在该分组端口时将不显示 quick-add */
387
404
  portGroup?: string;
388
405
  /** 精确指定 quick-add 使用哪个端口;优先级高于 portGroup */
@@ -390,6 +407,20 @@ interface QuickAddConfig {
390
407
  /** 点击 quick-add 插入节点时使用的方向;默认跟随绑定 port 的标准方向,不可推断时回退为 'right' */
391
408
  insertDirection?: InsertDirection | QuickAddInsertDirectionResolver;
392
409
  }
410
+ interface EdgeDropConfig {
411
+ /** 全局开关,默认 false */
412
+ enabled?: boolean;
413
+ /** 节点矩形向内收缩的边距(px),越大越不容易触发,默认 15 */
414
+ bufferMargin?: number;
415
+ /** 判断拖拽中的节点是否可以插入到边上,默认全部允许 */
416
+ isNodeInsertable?: (node: FlowNodeModel, flowModel: FlowModel) => boolean;
417
+ /** 判断边是否可作为插入目标,默认全部允许 */
418
+ isEdgeDropTarget?: (edge: FlowEdgeModel, flowModel: FlowModel) => boolean;
419
+ /** 插入节点的入口端口分组,默认 'left' */
420
+ incomingPortGroup?: string;
421
+ /** 插入节点的出口端口分组,默认 'right' */
422
+ outgoingPortGroup?: string;
423
+ }
393
424
  interface NodePaletteItem {
394
425
  type: string;
395
426
  label: string;
@@ -479,6 +510,13 @@ interface CanvasCallbackContext {
479
510
  mode: CanvasMode;
480
511
  }
481
512
 
513
+ /**
514
+ * @antv/x6-plugin-selection 在运行时向 Graph 原型注入的方法。
515
+ * 仅在 selectionPlugin 已通过 graph.use() 注册后可用。
516
+ * 当前 X6 类型声明已包含这些方法,因此这里保留别名供运行时语义标注使用。
517
+ */
518
+ type GraphWithSelection = Graph;
519
+
482
520
  /**
483
521
  * 纯函数 reducer:将一条原子命令应用到 FlowModel 上,返回新 FlowModel(不可变)。
484
522
  * 所有 FlowModel 不变量在此处保证:
@@ -591,6 +629,11 @@ interface CanvasEditorContext {
591
629
  extendedApi: Record<string, Function>;
592
630
  /** @internal used by CanvasRuntime */
593
631
  _pluginManager: PluginManager;
632
+ /**
633
+ * @internal 发出 UI 事件。Runtime mount 前仅分发到插件;mount 后同时触发 Vue emit('ui-event')。
634
+ * 由 CanvasRuntime 在挂载时注入完整实现。
635
+ */
636
+ _emitUiEvent: (event: CanvasUiEvent) => void;
594
637
  }
595
638
  /**
596
639
  * 画布编辑引擎的核心 composable。
@@ -614,6 +657,7 @@ type __VLS_Props$5 = {
614
657
  graphOptions?: Record<string, unknown>;
615
658
  nodeActions?: NodeActionsConfig;
616
659
  quickAdd?: QuickAddConfig;
660
+ edgeDrop?: EdgeDropConfig;
617
661
  /** 拖拽连线时,根据源节点 ID 返回不应显示端口的节点 ID 集合(如自身、上游、不可作为目标的节点) */
618
662
  getConnectionExcludedNodeIds?: (sourceNodeId: string) => Iterable<string>;
619
663
  };
@@ -711,7 +755,6 @@ declare const _default$1: typeof __VLS_export$1;
711
755
  type __VLS_Props = {
712
756
  node: FlowNodeModel;
713
757
  portPosition: ScreenPosition;
714
- tooltipText?: string;
715
758
  };
716
759
  declare function closePopover(): void;
717
760
  declare var __VLS_7: {};
@@ -743,17 +786,18 @@ type __VLS_WithSlots<T, S> = T & {
743
786
  };
744
787
 
745
788
  interface DefaultToolbarItemsOptions {
746
- /** 要排除的操作项类型(仅对可隐藏的组生效,zoom 和 reset 组固定不可排除) */
747
- exclude?: BuiltinToolbarType[];
748
789
  /** 要恢复显示的默认隐藏项(默认隐藏:undo、redo) */
749
790
  include?: BuiltinToolbarType[];
750
791
  }
751
792
  /**
752
793
  * 工具栏默认项分为四组(从左到右):
753
794
  * 1. history: 撤销、重做 — 默认隐藏,通过 include: ['undo', 'redo'] 恢复显示
754
- * 2. tools: 框选、自动排版、搜索、缩略图、下载 — 可隐藏
795
+ * 2. tools: 框选、自动排版、下载
796
+ * search / minimap 由内置插件默认提供,不在 core 默认项中声明
755
797
  * 3. zoom: 缩小、放大 — 固定
756
798
  * 4. reset: 重置 — 固定
799
+ *
800
+ * exclude 过滤统一由 CanvasToolbar 组件在合并 plugin items 后执行,此函数不处理。
757
801
  */
758
802
  declare function createDefaultToolbarItems(options?: DefaultToolbarItemsOptions): CanvasToolbarItem[];
759
803
 
@@ -812,7 +856,21 @@ interface SnaplinePluginOptions {
812
856
  }
813
857
  declare function snaplinePlugin(options?: SnaplinePluginOptions): CanvasPlugin;
814
858
 
859
+ interface SearchNodeMeta {
860
+ label?: string;
861
+ subtitle?: string;
862
+ keywords?: string[];
863
+ }
864
+ interface SearchPluginOptions {
865
+ placeholder?: string;
866
+ emptyText?: string;
867
+ maxResults?: number;
868
+ getNodeMeta?: (node: FlowNodeModel) => SearchNodeMeta | null | undefined;
869
+ }
870
+ declare function searchPlugin(options?: SearchPluginOptions): CanvasPlugin;
871
+
815
872
  interface MinimapPluginOptions {
873
+ /** 外部容器(传入后使用外部容器渲染,不创建浮动面板) */
816
874
  container?: HTMLElement;
817
875
  width?: number;
818
876
  height?: number;
@@ -828,5 +886,5 @@ declare function minimapPlugin(options?: MinimapPluginOptions): CanvasPlugin;
828
886
  */
829
887
  declare function clipboardPlugin(): CanvasPlugin;
830
888
 
831
- export { CanvasConstraintError, _default$5 as CanvasLayout, _default$3 as CanvasNodePalette, _default$6 as CanvasRuntime, CanvasSchemaError, _default$4 as CanvasToolbar, _default$2 as DefaultNode, _default$1 as NodeActionsToolbar, _default as NodeQuickAddPopover, applyCanvasCommand, clipboardPlugin, connectionValidatorPlugin, createBuiltinEdgeTypes, createCanvasHistory, createDefaultSchema, createDefaultToolbarItems, createEmptyFlowModel, generateId, minimapPlugin, selectionPlugin, snaplinePlugin, useCanvasEditor };
832
- export type { BuiltinEdgeType, BuiltinToolbarType, CanvasApi, CanvasCallbackContext, CanvasCommand, CanvasEdgeDefinition, CanvasEditorContext, CanvasEditorOptions, CanvasHistory, CanvasHistoryOptions, CanvasMode, CanvasNodeDefinition, CanvasPlugin, CanvasPosition, CanvasSchema, CanvasSelection, CanvasToolbarItem, CanvasUiEvent, CommandEnvelope, CommandExecutionError, CommandExecutionResult, CommandPreview, CommandRejection, CommandSource, ConnectionValidateContext, ConnectionValidateResult, ConnectionValidator, ContextMenuItem, DefaultNodeTypeConfig, DefaultSchemaOptions, DefaultSchemaResult, DefaultToolbarItemsOptions, EdgeDecoration, EdgeRenderState, EdgeStyle, EditorPluginContext, ExportOptions, FlowEdgeLabelModel, FlowEdgeModel, FlowModel, FlowModelChangeEvent, FlowNodeModel, FlowPortModel, IdGenerator, InsertDirection, InsertNodeOptions, MinimapPluginOptions, NodeActionsConfig, NodeBehaviorConfig, NodeDecoration, NodePaletteItem, OverlayManager, QuickAddConfig, QuickAddInsertDirectionResolver, QuickAddPortResolver, RuntimePluginContext, ScreenPosition, SelectionPluginOptions, SnaplinePluginOptions };
889
+ export { CanvasConstraintError, _default$5 as CanvasLayout, _default$3 as CanvasNodePalette, _default$6 as CanvasRuntime, CanvasSchemaError, _default$4 as CanvasToolbar, _default$2 as DefaultNode, _default$1 as NodeActionsToolbar, _default as NodeQuickAddPopover, applyCanvasCommand, clipboardPlugin, connectionValidatorPlugin, createBuiltinEdgeTypes, createCanvasHistory, createDefaultSchema, createDefaultToolbarItems, createEmptyFlowModel, generateId, minimapPlugin, searchPlugin, selectionPlugin, snaplinePlugin, useCanvasEditor };
890
+ export type { BuiltinEdgeType, BuiltinToolbarType, CanvasApi, CanvasCallbackContext, CanvasCommand, CanvasEdgeDefinition, CanvasEditorContext, CanvasEditorOptions, CanvasHistory, CanvasHistoryOptions, CanvasMode, CanvasNodeDefinition, CanvasPlugin, CanvasPosition, CanvasSchema, CanvasSelection, CanvasToolbarItem, CanvasUiEvent, CommandEnvelope, CommandExecutionError, CommandExecutionResult, CommandPreview, CommandRejection, CommandSource, ConnectionValidateContext, ConnectionValidateResult, ConnectionValidator, ContextMenuItem, CoreToolbarType, DefaultNodeTypeConfig, DefaultSchemaOptions, DefaultSchemaResult, DefaultToolbarItemsOptions, DeleteSelectionOptions, EdgeDecoration, EdgeDropConfig, EdgeRenderState, EdgeStyle, EditorPluginContext, ExportOptions, FlowEdgeLabelModel, FlowEdgeModel, FlowModel, FlowModelChangeEvent, FlowNodeModel, FlowPortModel, GraphWithSelection, IdGenerator, InsertDirection, InsertNodeOptions, MinimapPluginOptions, NodeActionsConfig, NodeBehaviorConfig, NodeDecoration, NodePaletteItem, OverlayManager, PluginManagedToolbarType, QuickAddConfig, QuickAddInsertDirectionResolver, QuickAddPortResolver, RuntimePluginContext, ScreenPosition, SearchNodeMeta, SearchPluginOptions, SelectionPluginOptions, SnaplinePluginOptions };