/**
 * 遍历节点
 * @param node
 * @param arrow
 * @param callback
 * @param length_
 * @returns
 */
export function FlowIterator(node, arrow, callback, length_) {
  if (!node) return;
  var length = (length_ || 0) + 1;
  var breakIterator = callback(node, length);
  if (breakIterator) return;
  if (arrow === 'up') {
    var _node$model, _node$model$getIncomi;
    (_node$model = node.model) === null || _node$model === void 0 ? void 0 : (_node$model$getIncomi = _node$model.getIncomingEdges(node.id)) === null || _node$model$getIncomi === void 0 ? void 0 : _node$model$getIncomi.forEach(function (edge) {
      var _node$model2, _node$model2$graph;
      var source = edge.source;
      var parentNode = (_node$model2 = node.model) === null || _node$model2 === void 0 ? void 0 : (_node$model2$graph = _node$model2.graph) === null || _node$model2$graph === void 0 ? void 0 : _node$model2$graph.getCellById(source.cell);
      if (!source.cell || !parentNode) return;
      FlowIterator(parentNode, arrow, callback, length);
    });
  } else {
    var _node$model3, _node$model3$getOutgo;
    (_node$model3 = node.model) === null || _node$model3 === void 0 ? void 0 : (_node$model3$getOutgo = _node$model3.getOutgoingEdges(node.id)) === null || _node$model3$getOutgo === void 0 ? void 0 : _node$model3$getOutgo.forEach(function (edge) {
      var _node$model4, _node$model4$graph;
      var target = edge.target;
      var nextNode = (_node$model4 = node.model) === null || _node$model4 === void 0 ? void 0 : (_node$model4$graph = _node$model4.graph) === null || _node$model4$graph === void 0 ? void 0 : _node$model4$graph.getCellById(target.cell);
      if (!target.cell || !nextNode) return;
      FlowIterator(nextNode, arrow, callback, length);
    });
  }
}