@flowgram.ai/document 0.5.1 → 0.5.3

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.mts CHANGED
@@ -841,6 +841,8 @@ interface FlowRendererState {
841
841
  nodeDragIds?: string[];
842
842
  nodeDragIdsWithChildren?: string[];
843
843
  dragLabelSide?: LABEL_SIDE_TYPE;
844
+ dragging?: boolean;
845
+ isBranch?: boolean;
844
846
  }
845
847
  /**
846
848
  * 渲染相关的全局状态管理
@@ -851,6 +853,10 @@ declare class FlowRendererStateEntity extends ConfigEntity<FlowRendererState, Fl
851
853
  constructor(conf: FlowRendererStateEntityConfig);
852
854
  getNodeHovered(): FlowNodeEntity | undefined;
853
855
  setNodeHovered(node: FlowNodeEntity | undefined): void;
856
+ get dragging(): boolean | undefined;
857
+ setDragging(dragging: boolean): void;
858
+ get isBranch(): boolean | undefined;
859
+ setIsBranch(isBranch: boolean): void;
854
860
  getDragLabelSide(): LABEL_SIDE_TYPE | undefined;
855
861
  setDragLabelSide(dragLabelSide?: LABEL_SIDE_TYPE): void;
856
862
  getNodeDroppingId(): string | undefined;
@@ -1314,7 +1320,6 @@ declare enum OperationType {
1314
1320
  moveChildNodes = "moveChildNodes",
1315
1321
  addNodes = "addNodes",
1316
1322
  deleteNodes = "deleteNodes",
1317
- changeNode = "changeNode",
1318
1323
  addChildNode = "addChildNode",
1319
1324
  deleteChildNode = "deleteChildNode",
1320
1325
  addNode = "addNode",
@@ -1384,16 +1389,6 @@ interface DeleteNodesOperation {
1384
1389
  type: OperationType.deleteNodes;
1385
1390
  value: AddOrDeleteNodesOperationValue;
1386
1391
  }
1387
- interface ChangeNodeOperationValue {
1388
- id: string;
1389
- path: string;
1390
- oldValue: any;
1391
- value: any;
1392
- }
1393
- interface ChangeNodeOperation {
1394
- type: OperationType.changeNode;
1395
- value: ChangeNodeOperationValue;
1396
- }
1397
1392
  interface MoveChildNodesOperationValue {
1398
1393
  nodeIds: string[];
1399
1394
  fromParentId: string;
@@ -1445,7 +1440,7 @@ interface AddOrDeleteNodeValue {
1445
1440
  index?: number;
1446
1441
  hidden?: boolean;
1447
1442
  }
1448
- type FlowOperation = AddFromNodeOperation | DeleteFromNodeOperation | AddBlockOperation | DeleteBlockOperation | CreateGroupOperation | UngroupOperation | MoveNodesOperation | AddNodesOperation | DeleteNodesOperation | ChangeNodeOperation | MoveBlockOperation | AddChildNodeOperation | DeleteChildNodeOperation | MoveChildNodesOperation | AddNodeOperation | DeleteNodeOperation;
1443
+ type FlowOperation = AddFromNodeOperation | DeleteFromNodeOperation | AddBlockOperation | DeleteBlockOperation | CreateGroupOperation | UngroupOperation | MoveNodesOperation | AddNodesOperation | DeleteNodesOperation | MoveBlockOperation | AddChildNodeOperation | DeleteChildNodeOperation | MoveChildNodesOperation | AddNodeOperation | DeleteNodeOperation;
1449
1444
  type FlowNodeEntityOrId = string | FlowNodeEntity;
1450
1445
  type AddNodeConfig = {
1451
1446
  parent?: FlowNodeEntityOrId;
@@ -1574,10 +1569,12 @@ declare class FlowDragService {
1574
1569
  protected onDropEmitter: Emitter<{
1575
1570
  dropNode: FlowNodeEntity;
1576
1571
  dragNodes: FlowNodeEntity[];
1572
+ dragJSON?: FlowNodeJSON;
1577
1573
  }>;
1578
1574
  readonly onDrop: _flowgram_ai_utils.Event<{
1579
1575
  dropNode: FlowNodeEntity;
1580
1576
  dragNodes: FlowNodeEntity[];
1577
+ dragJSON?: FlowNodeJSON;
1581
1578
  }>;
1582
1579
  get renderState(): FlowRendererStateEntity;
1583
1580
  get dragStartNode(): FlowNodeEntity;
@@ -1591,6 +1588,11 @@ declare class FlowDragService {
1591
1588
  * 放置到目标分支
1592
1589
  */
1593
1590
  dropBranch(): void;
1591
+ /**
1592
+ * 移动并且创建节点
1593
+ * Move and create node
1594
+ */
1595
+ dropCreateNode(json: FlowNodeJSON, onCreateNode?: (json: FlowNodeJSON, dropEntity: FlowNodeEntity) => Promise<FlowNodeEntity>): Promise<void>;
1594
1596
  /**
1595
1597
  * 移动到目标节点
1596
1598
  */
@@ -1717,4 +1719,4 @@ declare class FlowGroupService {
1717
1719
  */
1718
1720
  declare const getDefaultSpacing: (node: FlowNodeEntity, key: string, defaultSpacing?: number) => any;
1719
1721
 
1720
- 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 };
1722
+ 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 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 };
package/dist/index.d.ts CHANGED
@@ -841,6 +841,8 @@ interface FlowRendererState {
841
841
  nodeDragIds?: string[];
842
842
  nodeDragIdsWithChildren?: string[];
843
843
  dragLabelSide?: LABEL_SIDE_TYPE;
844
+ dragging?: boolean;
845
+ isBranch?: boolean;
844
846
  }
845
847
  /**
846
848
  * 渲染相关的全局状态管理
@@ -851,6 +853,10 @@ declare class FlowRendererStateEntity extends ConfigEntity<FlowRendererState, Fl
851
853
  constructor(conf: FlowRendererStateEntityConfig);
852
854
  getNodeHovered(): FlowNodeEntity | undefined;
853
855
  setNodeHovered(node: FlowNodeEntity | undefined): void;
856
+ get dragging(): boolean | undefined;
857
+ setDragging(dragging: boolean): void;
858
+ get isBranch(): boolean | undefined;
859
+ setIsBranch(isBranch: boolean): void;
854
860
  getDragLabelSide(): LABEL_SIDE_TYPE | undefined;
855
861
  setDragLabelSide(dragLabelSide?: LABEL_SIDE_TYPE): void;
856
862
  getNodeDroppingId(): string | undefined;
@@ -1314,7 +1320,6 @@ declare enum OperationType {
1314
1320
  moveChildNodes = "moveChildNodes",
1315
1321
  addNodes = "addNodes",
1316
1322
  deleteNodes = "deleteNodes",
1317
- changeNode = "changeNode",
1318
1323
  addChildNode = "addChildNode",
1319
1324
  deleteChildNode = "deleteChildNode",
1320
1325
  addNode = "addNode",
@@ -1384,16 +1389,6 @@ interface DeleteNodesOperation {
1384
1389
  type: OperationType.deleteNodes;
1385
1390
  value: AddOrDeleteNodesOperationValue;
1386
1391
  }
1387
- interface ChangeNodeOperationValue {
1388
- id: string;
1389
- path: string;
1390
- oldValue: any;
1391
- value: any;
1392
- }
1393
- interface ChangeNodeOperation {
1394
- type: OperationType.changeNode;
1395
- value: ChangeNodeOperationValue;
1396
- }
1397
1392
  interface MoveChildNodesOperationValue {
1398
1393
  nodeIds: string[];
1399
1394
  fromParentId: string;
@@ -1445,7 +1440,7 @@ interface AddOrDeleteNodeValue {
1445
1440
  index?: number;
1446
1441
  hidden?: boolean;
1447
1442
  }
1448
- type FlowOperation = AddFromNodeOperation | DeleteFromNodeOperation | AddBlockOperation | DeleteBlockOperation | CreateGroupOperation | UngroupOperation | MoveNodesOperation | AddNodesOperation | DeleteNodesOperation | ChangeNodeOperation | MoveBlockOperation | AddChildNodeOperation | DeleteChildNodeOperation | MoveChildNodesOperation | AddNodeOperation | DeleteNodeOperation;
1443
+ type FlowOperation = AddFromNodeOperation | DeleteFromNodeOperation | AddBlockOperation | DeleteBlockOperation | CreateGroupOperation | UngroupOperation | MoveNodesOperation | AddNodesOperation | DeleteNodesOperation | MoveBlockOperation | AddChildNodeOperation | DeleteChildNodeOperation | MoveChildNodesOperation | AddNodeOperation | DeleteNodeOperation;
1449
1444
  type FlowNodeEntityOrId = string | FlowNodeEntity;
1450
1445
  type AddNodeConfig = {
1451
1446
  parent?: FlowNodeEntityOrId;
@@ -1574,10 +1569,12 @@ declare class FlowDragService {
1574
1569
  protected onDropEmitter: Emitter<{
1575
1570
  dropNode: FlowNodeEntity;
1576
1571
  dragNodes: FlowNodeEntity[];
1572
+ dragJSON?: FlowNodeJSON;
1577
1573
  }>;
1578
1574
  readonly onDrop: _flowgram_ai_utils.Event<{
1579
1575
  dropNode: FlowNodeEntity;
1580
1576
  dragNodes: FlowNodeEntity[];
1577
+ dragJSON?: FlowNodeJSON;
1581
1578
  }>;
1582
1579
  get renderState(): FlowRendererStateEntity;
1583
1580
  get dragStartNode(): FlowNodeEntity;
@@ -1591,6 +1588,11 @@ declare class FlowDragService {
1591
1588
  * 放置到目标分支
1592
1589
  */
1593
1590
  dropBranch(): void;
1591
+ /**
1592
+ * 移动并且创建节点
1593
+ * Move and create node
1594
+ */
1595
+ dropCreateNode(json: FlowNodeJSON, onCreateNode?: (json: FlowNodeJSON, dropEntity: FlowNodeEntity) => Promise<FlowNodeEntity>): Promise<void>;
1594
1596
  /**
1595
1597
  * 移动到目标节点
1596
1598
  */
@@ -1717,4 +1719,4 @@ declare class FlowGroupService {
1717
1719
  */
1718
1720
  declare const getDefaultSpacing: (node: FlowNodeEntity, key: string, defaultSpacing?: number) => any;
1719
1721
 
1720
- 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 };
1722
+ 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 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 };
package/dist/index.js CHANGED
@@ -303,7 +303,6 @@ var OperationType = /* @__PURE__ */ ((OperationType2) => {
303
303
  OperationType2["moveChildNodes"] = "moveChildNodes";
304
304
  OperationType2["addNodes"] = "addNodes";
305
305
  OperationType2["deleteNodes"] = "deleteNodes";
306
- OperationType2["changeNode"] = "changeNode";
307
306
  OperationType2["addChildNode"] = "addChildNode";
308
307
  OperationType2["deleteChildNode"] = "deleteChildNode";
309
308
  OperationType2["addNode"] = "addNode";
@@ -1254,6 +1253,22 @@ var FlowRendererStateEntity = class extends import_core6.ConfigEntity {
1254
1253
  nodeHoveredId: node?.id
1255
1254
  });
1256
1255
  }
1256
+ get dragging() {
1257
+ return this.config.dragging;
1258
+ }
1259
+ setDragging(dragging) {
1260
+ this.updateConfig({
1261
+ dragging
1262
+ });
1263
+ }
1264
+ get isBranch() {
1265
+ return this.config.isBranch;
1266
+ }
1267
+ setIsBranch(isBranch) {
1268
+ this.updateConfig({
1269
+ isBranch
1270
+ });
1271
+ }
1257
1272
  getDragLabelSide() {
1258
1273
  return this.config.dragLabelSide;
1259
1274
  }
@@ -2510,15 +2525,14 @@ var FlowDragService = class {
2510
2525
  }
2511
2526
  // 是否在拖拽分支
2512
2527
  get isDragBranch() {
2513
- return this.dragStartNode?.isInlineBlock;
2528
+ return this.renderState.isBranch || this.dragStartNode?.isInlineBlock;
2514
2529
  }
2515
2530
  // 拖拽的所有节点及其自节点
2516
2531
  get nodeDragIdsWithChildren() {
2517
2532
  return this.renderState.config.nodeDragIdsWithChildren || [];
2518
2533
  }
2519
2534
  get dragging() {
2520
- const renderData = this.dragStartNode?.getData(FlowNodeRenderData);
2521
- return !!renderData?.dragging;
2535
+ return !!this.renderState.dragging;
2522
2536
  }
2523
2537
  get labelSide() {
2524
2538
  return this.renderState.config.dragLabelSide;
@@ -2529,6 +2543,24 @@ var FlowDragService = class {
2529
2543
  dropBranch() {
2530
2544
  this.dropNode();
2531
2545
  }
2546
+ /**
2547
+ * 移动并且创建节点
2548
+ * Move and create node
2549
+ */
2550
+ async dropCreateNode(json, onCreateNode) {
2551
+ const dropEntity = this.document.getNode(this.dropNodeId);
2552
+ if (!dropEntity) {
2553
+ return;
2554
+ }
2555
+ if (json) {
2556
+ const dragNodes = await onCreateNode?.(json, dropEntity);
2557
+ this.onDropEmitter.fire({
2558
+ dropNode: dropEntity,
2559
+ dragNodes: dragNodes ? [dragNodes] : [],
2560
+ dragJSON: json
2561
+ });
2562
+ }
2563
+ }
2532
2564
  /**
2533
2565
  * 移动到目标节点
2534
2566
  */
@@ -2584,6 +2616,9 @@ var FlowDragService = class {
2584
2616
  * @param side 分支的前面还是后面
2585
2617
  */
2586
2618
  isDroppableBranch(node, side = "normal_branch" /* NORMAL_BRANCH */) {
2619
+ if (this.renderState.isBranch) {
2620
+ return true;
2621
+ }
2587
2622
  if (this.isDragBranch) {
2588
2623
  if (
2589
2624
  // 拖拽到分支