text: "use strict";
  
  Object.defineProperty(exports, "__esModule", {
    value: true
  });
  exports.getKey = getKey;
  exports.warningWithoutKey = warningWithoutKey;
  exports.convertTreeToData = convertTreeToData;
  exports.flattenTreeData = flattenTreeData;
  exports.traverseDataNodes = traverseDataNodes;
  exports.convertDataToEntities = convertDataToEntities;
  exports.getTreeNodeProps = getTreeNodeProps;
  exports.convertNodePropsToEventData = convertNodePropsToEventData;
  
  var _toArray = _interopRequireDefault(require("rc-util/lib/Children/toArray"));
  
  var _warning = _interopRequireDefault(require("rc-util/lib/warning"));
  
  var _util = require("../util");
  
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
  
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
  
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
  
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); }
  
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
  
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
  
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
  
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
  
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
  
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
  
  function getKey(key, pos) {
    if (key !== null && key !== undefined) {
      return key;
    }
  
    return pos;
  }
  /**
   * Warning if TreeNode do not provides key
   */
  
  
  function warningWithoutKey() {
    var treeData = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
    var keys = new Map();
  
    function dig(list) {
      var path = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
      (list || []).forEach(function (treeNode) {
        var key = treeNode.key,
            children = treeNode.children;
        (0, _warning.default)(key !== null && key !== undefined, "Tree node must have a certain key: [".concat(path).concat(key, "]"));
        var recordKey = String(key);
        (0, _warning.default)(!keys.has(recordKey) || key === null || key === undefined, "Same 'key' exist in the Tree: ".concat(recordKey));
        keys.set(recordKey, true);
        dig(children, "".concat(path).concat(recordKey, " > "));
      });
    }
  
    dig(treeData);
  }
  /**
   * Convert `children` of Tree into `treeData` structure.
   */
  
  
  function convertTreeToData(rootNodes) {
    function dig(node) {
      var treeNodes = (0, _toArray.default)(node);
      return treeNodes.map(function (treeNode) {
        // Filter invalidate node
        if (!(0, _util.isTreeNode)(treeNode)) {
          (0, _warning.default)(!treeNode, 'Tree/TreeNode can only accept TreeNode as children.');
          return null;
        }
  
        var key = treeNode.key;
  
        var _treeNode$props = treeNode.props,
            children = _treeNode$props.children,
            rest = _objectWithoutProperties(_treeNode$props, ["children"]);
  
        var dataNode = _objectSpread({
          key: key
        }, rest);
  
        var parsedChildren = dig(children);
  
        if (parsedChildren.length) {
          dataNode.children = parsedChildren;
        }
  
        return dataNode;
      }).filter(function (dataNode) {
        return dataNode;
      });
    }
  
    return dig(rootNodes);
  }
  /**
   * Flat nest tree data into flatten list. This is used for virtual list render.
   * @param treeNodeList Origin data node list
   * @param expandedKeys
   * need expanded keys, provides `true` means all expanded (used in `rc-tree-select`).
   */
  
  
  function flattenTreeData() {
    var treeNodeList = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
    var expandedKeys = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
    var expandedKeySet = new Set(expandedKeys === true ? [] : expandedKeys);
    var flattenList = [];
  
    function dig(list) {
      var parent = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
      return list.map(function (treeNode, index) {
        var pos = (0, _util.getPosition)(parent ? parent.pos : '0', index);
        var mergedKey = getKey(treeNode.key, pos); // Add FlattenDataNode into list
  
        var flattenNode = _objectSpread(_objectSpread({}, treeNode), {}, {
          parent: parent,
          pos: pos,
          children: null,
          data: treeNode,
          isStart: [].concat(_toConsumableArray(parent ? parent.isStart : []), [index === 0]),
          isEnd: [].concat(_toConsumableArray(parent ? parent.isEnd : []), [index === list.length - 1])
        });
  
        flattenList.push(flattenNode); // Loop treeNode children
  
        if (expandedKeys === true || expandedKeySet.has(mergedKey)) {
          flattenNode.children = dig(treeNode.children || [], flattenNode);
        } else {
          flattenNode.children = [];
        }
  
        return flattenNode;
      });
    }
  
    dig(treeNodeList);
    return flattenList;
  }
  /**
   * Traverse all the data by `treeData`.
   * Please not use it out of the `rc-tree` since we may refactor this code.
   */
  
  
  function traverseDataNodes(dataNodes, callback) {
    function processNode(node, index, parent) {
      var children = node ? node.children : dataNodes;
      var pos = node ? (0, _util.getPosition)(parent.pos, index) : '0'; // Process node if is not root
  
      if (node) {
        var data = {
          node: node,
          index: index,
          pos: pos,
          key: node.key !== null ? node.key : pos,
          parentPos: parent.node ? parent.pos : null,
          level: parent.level + 1
        };
        callback(data);
      } // Process children node
  
  
      if (children) {
        children.forEach(function (subNode, subIndex) {
          processNode(subNode, subIndex, {
            node: node,
            pos: pos,
            level: parent ? parent.level + 1 : -1
          });
        });
      }
    }
  
    processNode(null);
  }
  /**
   * Convert `treeData` into entity records.
   */
  
  
  function convertDataToEntities(dataNodes) {
    var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
        initWrapper = _ref.initWrapper,
        processEntity = _ref.processEntity,
        onProcessFinished = _ref.onProcessFinished;
  
    var posEntities = {};
    var keyEntities = {};
    var wrapper = {
      posEntities: posEntities,
      keyEntities: keyEntities
    };
  
    if (initWrapper) {
      wrapper = initWrapper(wrapper) || wrapper;
    }
  
    traverseDataNodes(dataNodes, function (item) {
      var node = item.node,
          index = item.index,
          pos = item.pos,
          key = item.key,
          parentPos = item.parentPos,
          level = item.level;
      var entity = {
        node: node,
        index: index,
        key: key,
        pos: pos,
        level: level
      };
      var mergedKey = getKey(key, pos);
      posEntities[pos] = entity;
      keyEntities[mergedKey] = entity; // Fill children
  
      entity.parent = posEntities[parentPos];
  
      if (entity.parent) {
        entity.parent.children = entity.parent.children || [];
        entity.parent.children.push(entity);
      }
  
      if (processEntity) {
        processEntity(entity, wrapper);
      }
    });
  
    if (onProcessFinished) {
      onProcessFinished(wrapper);
    }
  
    return wrapper;
  }
  /**
   * Get TreeNode props with Tree props.
   */
  
  
  function getTreeNodeProps(key, _ref2) {
    var expandedKeys = _ref2.expandedKeys,
        selectedKeys = _ref2.selectedKeys,
        loadedKeys = _ref2.loadedKeys,
        loadingKeys = _ref2.loadingKeys,
        checkedKeys = _ref2.checkedKeys,
        halfCheckedKeys = _ref2.halfCheckedKeys,
        dragOverNodeKey = _ref2.dragOverNodeKey,
        dropPosition = _ref2.dropPosition,
        keyEntities = _ref2.keyEntities;
    var entity = keyEntities[key];
    var treeNodeProps = {
      eventKey: key,
      expanded: expandedKeys.indexOf(key) !== -1,
      selected: selectedKeys.indexOf(key) !== -1,
      loaded: loadedKeys.indexOf(key) !== -1,
      loading: loadingKeys.indexOf(key) !== -1,
      checked: checkedKeys.indexOf(key) !== -1,
      halfChecked: halfCheckedKeys.indexOf(key) !== -1,
      pos: String(entity ? entity.pos : ''),
      // [Legacy] Drag props
      dragOver: dragOverNodeKey === key && dropPosition === 0,
      dragOverGapTop: dragOverNodeKey === key && dropPosition === -1,
      dragOverGapBottom: dragOverNodeKey === key && dropPosition === 1
    };
    return treeNodeProps;
  }
  
  function convertNodePropsToEventData(props) {
    var data = props.data,
        expanded = props.expanded,
        selected = props.selected,
        checked = props.checked,
        loaded = props.loaded,
        loading = props.loading,
        halfChecked = props.halfChecked,
        dragOver = props.dragOver,
        dragOverGapTop = props.dragOverGapTop,
        dragOverGapBottom = props.dragOverGapBottom,
        pos = props.pos,
        active = props.active;
  
    var eventData = _objectSpread(_objectSpread({}, data), {}, {
      expanded: expanded,
      selected: selected,
      checked: checked,
      loaded: loaded,
      loading: loading,
      halfChecked: halfChecked,
      dragOver: dragOver,
      dragOverGapTop: dragOverGapTop,
      dragOverGapBottom: dragOverGapBottom,
      pos: pos,
      active: active
    });
  
    if (!('props' in eventData)) {
      Object.defineProperty(eventData, 'props', {
        get: function get() {
          (0, _warning.default)(false, 'Second param return from event is node data instead of TreeNode instance. Please read value directly instead of reading from `props`.');
          return props;
        }
      });
    }
  
    return eventData;
  }