@flowgram.ai/document 0.1.13 → 0.1.15

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
@@ -409,6 +409,7 @@ interface FlowNodeRenderSchema {
409
409
  activated: boolean;
410
410
  hovered: boolean;
411
411
  dragging: boolean;
412
+ stackIndex: number;
412
413
  extInfo?: Record<string, any>;
413
414
  }
414
415
  /**
@@ -447,6 +448,8 @@ declare class FlowNodeRenderData extends EntityData<FlowNodeRenderSchema> {
447
448
  set dragging(dragging: boolean);
448
449
  set activated(activated: boolean);
449
450
  get activated(): boolean;
451
+ get stackIndex(): number;
452
+ set stackIndex(index: number);
450
453
  get lineActivated(): boolean;
451
454
  get node(): HTMLDivElement;
452
455
  dispose(): void;
@@ -1316,6 +1319,16 @@ interface OnNodeAddEvent {
1316
1319
  node: FlowNodeEntity;
1317
1320
  data: AddNodeData;
1318
1321
  }
1322
+ /**
1323
+ * 节点移动事件
1324
+ */
1325
+ interface OnNodeMoveEvent {
1326
+ node: FlowNodeEntity;
1327
+ fromParent: FlowNodeEntity;
1328
+ fromIndex: number;
1329
+ toParent: FlowNodeEntity;
1330
+ toIndex: number;
1331
+ }
1319
1332
  interface FlowOperationBaseService extends Disposable {
1320
1333
  /**
1321
1334
  * 执行操作
@@ -1374,6 +1387,10 @@ interface FlowOperationBaseService extends Disposable {
1374
1387
  * 添加节点的回调
1375
1388
  */
1376
1389
  onNodeAdd: Event<OnNodeAddEvent>;
1390
+ /**
1391
+ * 节点移动的回调
1392
+ */
1393
+ onNodeMove: Event<OnNodeMoveEvent>;
1377
1394
  }
1378
1395
  declare const FlowOperationBaseService: unique symbol;
1379
1396
 
@@ -1436,6 +1453,8 @@ declare class FlowOperationBaseServiceImpl implements FlowOperationBaseService {
1436
1453
  protected onNodeAddEmitter: Emitter<OnNodeAddEvent>;
1437
1454
  readonly onNodeAdd: _flowgram_ai_utils.Event<OnNodeAddEvent>;
1438
1455
  protected toDispose: DisposableCollection;
1456
+ private onNodeMoveEmitter;
1457
+ readonly onNodeMove: _flowgram_ai_utils.Event<OnNodeMoveEvent>;
1439
1458
  protected init(): void;
1440
1459
  addNode(nodeJSON: FlowNodeJSON, config?: AddNodeConfig): FlowNodeEntity;
1441
1460
  addFromNode(fromNode: FlowNodeEntityOrId, nodeJSON: FlowNodeJSON): FlowNodeEntity;
@@ -1531,4 +1550,4 @@ declare class FlowGroupController {
1531
1550
  */
1532
1551
  declare const getDefaultSpacing: (node: FlowNodeEntity, key: string, defaultSpacing?: number) => any;
1533
1552
 
1534
- 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 };
1553
+ 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 };
package/dist/index.d.ts CHANGED
@@ -409,6 +409,7 @@ interface FlowNodeRenderSchema {
409
409
  activated: boolean;
410
410
  hovered: boolean;
411
411
  dragging: boolean;
412
+ stackIndex: number;
412
413
  extInfo?: Record<string, any>;
413
414
  }
414
415
  /**
@@ -447,6 +448,8 @@ declare class FlowNodeRenderData extends EntityData<FlowNodeRenderSchema> {
447
448
  set dragging(dragging: boolean);
448
449
  set activated(activated: boolean);
449
450
  get activated(): boolean;
451
+ get stackIndex(): number;
452
+ set stackIndex(index: number);
450
453
  get lineActivated(): boolean;
451
454
  get node(): HTMLDivElement;
452
455
  dispose(): void;
@@ -1316,6 +1319,16 @@ interface OnNodeAddEvent {
1316
1319
  node: FlowNodeEntity;
1317
1320
  data: AddNodeData;
1318
1321
  }
1322
+ /**
1323
+ * 节点移动事件
1324
+ */
1325
+ interface OnNodeMoveEvent {
1326
+ node: FlowNodeEntity;
1327
+ fromParent: FlowNodeEntity;
1328
+ fromIndex: number;
1329
+ toParent: FlowNodeEntity;
1330
+ toIndex: number;
1331
+ }
1319
1332
  interface FlowOperationBaseService extends Disposable {
1320
1333
  /**
1321
1334
  * 执行操作
@@ -1374,6 +1387,10 @@ interface FlowOperationBaseService extends Disposable {
1374
1387
  * 添加节点的回调
1375
1388
  */
1376
1389
  onNodeAdd: Event<OnNodeAddEvent>;
1390
+ /**
1391
+ * 节点移动的回调
1392
+ */
1393
+ onNodeMove: Event<OnNodeMoveEvent>;
1377
1394
  }
1378
1395
  declare const FlowOperationBaseService: unique symbol;
1379
1396
 
@@ -1436,6 +1453,8 @@ declare class FlowOperationBaseServiceImpl implements FlowOperationBaseService {
1436
1453
  protected onNodeAddEmitter: Emitter<OnNodeAddEvent>;
1437
1454
  readonly onNodeAdd: _flowgram_ai_utils.Event<OnNodeAddEvent>;
1438
1455
  protected toDispose: DisposableCollection;
1456
+ private onNodeMoveEmitter;
1457
+ readonly onNodeMove: _flowgram_ai_utils.Event<OnNodeMoveEvent>;
1439
1458
  protected init(): void;
1440
1459
  addNode(nodeJSON: FlowNodeJSON, config?: AddNodeConfig): FlowNodeEntity;
1441
1460
  addFromNode(fromNode: FlowNodeEntityOrId, nodeJSON: FlowNodeJSON): FlowNodeEntity;
@@ -1531,4 +1550,4 @@ declare class FlowGroupController {
1531
1550
  */
1532
1551
  declare const getDefaultSpacing: (node: FlowNodeEntity, key: string, defaultSpacing?: number) => any;
1533
1552
 
1534
- 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 };
1553
+ 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 };
package/dist/index.js CHANGED
@@ -304,7 +304,8 @@ var _FlowNodeRenderData = class _FlowNodeRenderData extends import_core.EntityDa
304
304
  expanded: defaultExpanded || false,
305
305
  activated: false,
306
306
  hovered: false,
307
- dragging: false
307
+ dragging: false,
308
+ stackIndex: 0
308
309
  };
309
310
  }
310
311
  updateExtInfo(info) {
@@ -410,6 +411,12 @@ var _FlowNodeRenderData = class _FlowNodeRenderData extends import_core.EntityDa
410
411
  }
411
412
  return this.data.activated;
412
413
  }
414
+ get stackIndex() {
415
+ return this.data.stackIndex;
416
+ }
417
+ set stackIndex(index) {
418
+ this.data.stackIndex = index;
419
+ }
413
420
  get lineActivated() {
414
421
  const { activated } = this;
415
422
  if (!activated) return false;
@@ -2218,9 +2225,11 @@ var FlowOperationBaseServiceImpl = class {
2218
2225
  this.onNodeAddEmitter = new import_utils8.Emitter();
2219
2226
  this.onNodeAdd = this.onNodeAddEmitter.event;
2220
2227
  this.toDispose = new import_utils8.DisposableCollection();
2228
+ this.onNodeMoveEmitter = new import_utils8.Emitter();
2229
+ this.onNodeMove = this.onNodeMoveEmitter.event;
2221
2230
  }
2222
2231
  init() {
2223
- this.toDispose.push(this.onNodeAddEmitter);
2232
+ this.toDispose.pushAll([this.onNodeAddEmitter, this.onNodeMoveEmitter]);
2224
2233
  }
2225
2234
  addNode(nodeJSON, config = {}) {
2226
2235
  const { parent, index, hidden } = config;
@@ -2284,7 +2293,7 @@ var FlowOperationBaseServiceImpl = class {
2284
2293
  console.warn("no new parent found", newParent);
2285
2294
  return;
2286
2295
  }
2287
- let toIndex = typeof index === "undefined" ? parent.children.length : index;
2296
+ let toIndex = typeof index === "undefined" ? newParentEntity.collapsedChildren.length : index;
2288
2297
  return this.doMoveNode(entity, newParentEntity, toIndex);
2289
2298
  }
2290
2299
  /**
@@ -2437,11 +2446,22 @@ var FlowOperationBaseServiceImpl = class {
2437
2446
  return parent.children.findIndex((child) => child === entity);
2438
2447
  }
2439
2448
  doMoveNode(node, newParent, index) {
2440
- return this.document.moveChildNodes({
2449
+ if (!node.parent) {
2450
+ throw new Error("root node cannot move");
2451
+ }
2452
+ const event = {
2453
+ node,
2454
+ fromParent: node.parent,
2455
+ toParent: newParent,
2456
+ fromIndex: this.getNodeIndex(node),
2457
+ toIndex: index
2458
+ };
2459
+ this.document.moveChildNodes({
2441
2460
  nodeIds: [this.toId(node)],
2442
2461
  toParentId: this.toId(newParent),
2443
2462
  toIndex: index
2444
2463
  });
2464
+ this.onNodeMoveEmitter.fire(event);
2445
2465
  }
2446
2466
  };
2447
2467
  __decorateClass([