/**
 * ldesign v0.2.14
 * (c) 2022/11/2 15:57 built by swimly
 * @license MIT
 */

import { _ as _defineProperty } from './dep-e15c7c8a.js';
import { _ as _arrayMap, a as _MapCache, t as toString_1 } from './dep-3ecca51f.js';
import { T as TreeNode, i as isPlainObject_1, _ as _overRest, a as _setToString, b as _baseFlatten, c as _baseUnary, d as identity_1 } from './dep-7e15502c.js';
import { i as isArrayLike_1, _ as _baseSlice } from './dep-35398e5e.js';
import { i as isObjectLike_1 } from './dep-de6170dd.js';
import './dep-c862ae53.js';

var HASH_UNDEFINED = "__lodash_hash_undefined__";
function setCacheAdd$1(value) {
  this.__data__.set(value, HASH_UNDEFINED);
  return this;
}
var _setCacheAdd = setCacheAdd$1;
function setCacheHas$1(value) {
  return this.__data__.has(value);
}
var _setCacheHas = setCacheHas$1;
var MapCache = _MapCache,
  setCacheAdd = _setCacheAdd,
  setCacheHas = _setCacheHas;
function SetCache$1(values) {
  var index = -1,
    length = values == null ? 0 : values.length;
  this.__data__ = new MapCache();
  while (++index < length) {
    this.add(values[index]);
  }
}
SetCache$1.prototype.add = SetCache$1.prototype.push = setCacheAdd;
SetCache$1.prototype.has = setCacheHas;
var _SetCache = SetCache$1;
function baseFindIndex$1(array, predicate, fromIndex, fromRight) {
  var length = array.length,
    index = fromIndex + (fromRight ? 1 : -1);
  while (fromRight ? index-- : ++index < length) {
    if (predicate(array[index], index, array)) {
      return index;
    }
  }
  return -1;
}
var _baseFindIndex = baseFindIndex$1;
function baseIsNaN$1(value) {
  return value !== value;
}
var _baseIsNaN = baseIsNaN$1;
function strictIndexOf$1(array, value, fromIndex) {
  var index = fromIndex - 1,
    length = array.length;
  while (++index < length) {
    if (array[index] === value) {
      return index;
    }
  }
  return -1;
}
var _strictIndexOf = strictIndexOf$1;
var baseFindIndex = _baseFindIndex,
  baseIsNaN = _baseIsNaN,
  strictIndexOf = _strictIndexOf;
function baseIndexOf$1(array, value, fromIndex) {
  return value === value ? strictIndexOf(array, value, fromIndex) : baseFindIndex(array, baseIsNaN, fromIndex);
}
var _baseIndexOf = baseIndexOf$1;
var baseIndexOf = _baseIndexOf;
function arrayIncludes$1(array, value) {
  var length = array == null ? 0 : array.length;
  return !!length && baseIndexOf(array, value, 0) > -1;
}
var _arrayIncludes = arrayIncludes$1;
function arrayIncludesWith$1(array, value, comparator) {
  var index = -1,
    length = array == null ? 0 : array.length;
  while (++index < length) {
    if (comparator(value, array[index])) {
      return true;
    }
  }
  return false;
}
var _arrayIncludesWith = arrayIncludesWith$1;
function cacheHas$1(cache, key) {
  return cache.has(key);
}
var _cacheHas = cacheHas$1;
var SetCache = _SetCache,
  arrayIncludes = _arrayIncludes,
  arrayIncludesWith = _arrayIncludesWith,
  arrayMap = _arrayMap,
  baseUnary = _baseUnary,
  cacheHas = _cacheHas;
var LARGE_ARRAY_SIZE = 200;
function baseDifference$1(array, values, iteratee, comparator) {
  var index = -1,
    includes = arrayIncludes,
    isCommon = true,
    length = array.length,
    result = [],
    valuesLength = values.length;
  if (!length) {
    return result;
  }
  if (iteratee) {
    values = arrayMap(values, baseUnary(iteratee));
  }
  if (comparator) {
    includes = arrayIncludesWith;
    isCommon = false;
  } else if (values.length >= LARGE_ARRAY_SIZE) {
    includes = cacheHas;
    isCommon = false;
    values = new SetCache(values);
  }
  outer: while (++index < length) {
    var value = array[index],
      computed = iteratee == null ? value : iteratee(value);
    value = comparator || value !== 0 ? value : 0;
    if (isCommon && computed === computed) {
      var valuesIndex = valuesLength;
      while (valuesIndex--) {
        if (values[valuesIndex] === computed) {
          continue outer;
        }
      }
      result.push(value);
    } else if (!includes(values, computed, comparator)) {
      result.push(value);
    }
  }
  return result;
}
var _baseDifference = baseDifference$1;
var identity = identity_1,
  overRest = _overRest,
  setToString = _setToString;
function baseRest$1(func, start) {
  return setToString(overRest(func, start, identity), func + "");
}
var _baseRest = baseRest$1;
var isArrayLike = isArrayLike_1,
  isObjectLike = isObjectLike_1;
function isArrayLikeObject$1(value) {
  return isObjectLike(value) && isArrayLike(value);
}
var isArrayLikeObject_1 = isArrayLikeObject$1;
var baseDifference = _baseDifference,
  baseFlatten = _baseFlatten,
  baseRest = _baseRest,
  isArrayLikeObject = isArrayLikeObject_1;
var difference = baseRest(function (array, values) {
  return isArrayLikeObject(array) ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true)) : [];
});
var difference_1 = difference;
var baseSlice = _baseSlice;
function castSlice$1(array, start, end) {
  var length = array.length;
  end = end === void 0 ? length : end;
  return !start && end >= length ? array : baseSlice(array, start, end);
}
var _castSlice = castSlice$1;
var rsAstralRange$2 = "\\ud800-\\udfff",
  rsComboMarksRange$3 = "\\u0300-\\u036f",
  reComboHalfMarksRange$3 = "\\ufe20-\\ufe2f",
  rsComboSymbolsRange$3 = "\\u20d0-\\u20ff",
  rsComboRange$3 = rsComboMarksRange$3 + reComboHalfMarksRange$3 + rsComboSymbolsRange$3,
  rsVarRange$2 = "\\ufe0e\\ufe0f";
var rsZWJ$2 = "\\u200d";
var reHasUnicode = RegExp("[" + rsZWJ$2 + rsAstralRange$2 + rsComboRange$3 + rsVarRange$2 + "]");
function hasUnicode$2(string) {
  return reHasUnicode.test(string);
}
var _hasUnicode = hasUnicode$2;
function asciiToArray$1(string) {
  return string.split("");
}
var _asciiToArray = asciiToArray$1;
var rsAstralRange$1 = "\\ud800-\\udfff",
  rsComboMarksRange$2 = "\\u0300-\\u036f",
  reComboHalfMarksRange$2 = "\\ufe20-\\ufe2f",
  rsComboSymbolsRange$2 = "\\u20d0-\\u20ff",
  rsComboRange$2 = rsComboMarksRange$2 + reComboHalfMarksRange$2 + rsComboSymbolsRange$2,
  rsVarRange$1 = "\\ufe0e\\ufe0f";
var rsAstral = "[" + rsAstralRange$1 + "]",
  rsCombo$2 = "[" + rsComboRange$2 + "]",
  rsFitz$1 = "\\ud83c[\\udffb-\\udfff]",
  rsModifier$1 = "(?:" + rsCombo$2 + "|" + rsFitz$1 + ")",
  rsNonAstral$1 = "[^" + rsAstralRange$1 + "]",
  rsRegional$1 = "(?:\\ud83c[\\udde6-\\uddff]){2}",
  rsSurrPair$1 = "[\\ud800-\\udbff][\\udc00-\\udfff]",
  rsZWJ$1 = "\\u200d";
var reOptMod$1 = rsModifier$1 + "?",
  rsOptVar$1 = "[" + rsVarRange$1 + "]?",
  rsOptJoin$1 = "(?:" + rsZWJ$1 + "(?:" + [rsNonAstral$1, rsRegional$1, rsSurrPair$1].join("|") + ")" + rsOptVar$1 + reOptMod$1 + ")*",
  rsSeq$1 = rsOptVar$1 + reOptMod$1 + rsOptJoin$1,
  rsSymbol = "(?:" + [rsNonAstral$1 + rsCombo$2 + "?", rsCombo$2, rsRegional$1, rsSurrPair$1, rsAstral].join("|") + ")";
var reUnicode = RegExp(rsFitz$1 + "(?=" + rsFitz$1 + ")|" + rsSymbol + rsSeq$1, "g");
function unicodeToArray$1(string) {
  return string.match(reUnicode) || [];
}
var _unicodeToArray = unicodeToArray$1;
var asciiToArray = _asciiToArray,
  hasUnicode$1 = _hasUnicode,
  unicodeToArray = _unicodeToArray;
function stringToArray$1(string) {
  return hasUnicode$1(string) ? unicodeToArray(string) : asciiToArray(string);
}
var _stringToArray = stringToArray$1;
var castSlice = _castSlice,
  hasUnicode = _hasUnicode,
  stringToArray = _stringToArray,
  toString$3 = toString_1;
function createCaseFirst$1(methodName) {
  return function (string) {
    string = toString$3(string);
    var strSymbols = hasUnicode(string) ? stringToArray(string) : void 0;
    var chr = strSymbols ? strSymbols[0] : string.charAt(0);
    var trailing = strSymbols ? castSlice(strSymbols, 1).join("") : string.slice(1);
    return chr[methodName]() + trailing;
  };
}
var _createCaseFirst = createCaseFirst$1;
var createCaseFirst = _createCaseFirst;
var upperFirst$1 = createCaseFirst("toUpperCase");
var upperFirst_1 = upperFirst$1;
var toString$2 = toString_1,
  upperFirst = upperFirst_1;
function capitalize$1(string) {
  return upperFirst(toString$2(string).toLowerCase());
}
var capitalize_1 = capitalize$1;
function arrayReduce$1(array, iteratee, accumulator, initAccum) {
  var index = -1,
    length = array == null ? 0 : array.length;
  if (initAccum && length) {
    accumulator = array[++index];
  }
  while (++index < length) {
    accumulator = iteratee(accumulator, array[index], index, array);
  }
  return accumulator;
}
var _arrayReduce = arrayReduce$1;
function basePropertyOf$1(object) {
  return function (key) {
    return object == null ? void 0 : object[key];
  };
}
var _basePropertyOf = basePropertyOf$1;
var basePropertyOf = _basePropertyOf;
var deburredLetters = {
  "\xC0": "A",
  "\xC1": "A",
  "\xC2": "A",
  "\xC3": "A",
  "\xC4": "A",
  "\xC5": "A",
  "\xE0": "a",
  "\xE1": "a",
  "\xE2": "a",
  "\xE3": "a",
  "\xE4": "a",
  "\xE5": "a",
  "\xC7": "C",
  "\xE7": "c",
  "\xD0": "D",
  "\xF0": "d",
  "\xC8": "E",
  "\xC9": "E",
  "\xCA": "E",
  "\xCB": "E",
  "\xE8": "e",
  "\xE9": "e",
  "\xEA": "e",
  "\xEB": "e",
  "\xCC": "I",
  "\xCD": "I",
  "\xCE": "I",
  "\xCF": "I",
  "\xEC": "i",
  "\xED": "i",
  "\xEE": "i",
  "\xEF": "i",
  "\xD1": "N",
  "\xF1": "n",
  "\xD2": "O",
  "\xD3": "O",
  "\xD4": "O",
  "\xD5": "O",
  "\xD6": "O",
  "\xD8": "O",
  "\xF2": "o",
  "\xF3": "o",
  "\xF4": "o",
  "\xF5": "o",
  "\xF6": "o",
  "\xF8": "o",
  "\xD9": "U",
  "\xDA": "U",
  "\xDB": "U",
  "\xDC": "U",
  "\xF9": "u",
  "\xFA": "u",
  "\xFB": "u",
  "\xFC": "u",
  "\xDD": "Y",
  "\xFD": "y",
  "\xFF": "y",
  "\xC6": "Ae",
  "\xE6": "ae",
  "\xDE": "Th",
  "\xFE": "th",
  "\xDF": "ss",
  "\u0100": "A",
  "\u0102": "A",
  "\u0104": "A",
  "\u0101": "a",
  "\u0103": "a",
  "\u0105": "a",
  "\u0106": "C",
  "\u0108": "C",
  "\u010A": "C",
  "\u010C": "C",
  "\u0107": "c",
  "\u0109": "c",
  "\u010B": "c",
  "\u010D": "c",
  "\u010E": "D",
  "\u0110": "D",
  "\u010F": "d",
  "\u0111": "d",
  "\u0112": "E",
  "\u0114": "E",
  "\u0116": "E",
  "\u0118": "E",
  "\u011A": "E",
  "\u0113": "e",
  "\u0115": "e",
  "\u0117": "e",
  "\u0119": "e",
  "\u011B": "e",
  "\u011C": "G",
  "\u011E": "G",
  "\u0120": "G",
  "\u0122": "G",
  "\u011D": "g",
  "\u011F": "g",
  "\u0121": "g",
  "\u0123": "g",
  "\u0124": "H",
  "\u0126": "H",
  "\u0125": "h",
  "\u0127": "h",
  "\u0128": "I",
  "\u012A": "I",
  "\u012C": "I",
  "\u012E": "I",
  "\u0130": "I",
  "\u0129": "i",
  "\u012B": "i",
  "\u012D": "i",
  "\u012F": "i",
  "\u0131": "i",
  "\u0134": "J",
  "\u0135": "j",
  "\u0136": "K",
  "\u0137": "k",
  "\u0138": "k",
  "\u0139": "L",
  "\u013B": "L",
  "\u013D": "L",
  "\u013F": "L",
  "\u0141": "L",
  "\u013A": "l",
  "\u013C": "l",
  "\u013E": "l",
  "\u0140": "l",
  "\u0142": "l",
  "\u0143": "N",
  "\u0145": "N",
  "\u0147": "N",
  "\u014A": "N",
  "\u0144": "n",
  "\u0146": "n",
  "\u0148": "n",
  "\u014B": "n",
  "\u014C": "O",
  "\u014E": "O",
  "\u0150": "O",
  "\u014D": "o",
  "\u014F": "o",
  "\u0151": "o",
  "\u0154": "R",
  "\u0156": "R",
  "\u0158": "R",
  "\u0155": "r",
  "\u0157": "r",
  "\u0159": "r",
  "\u015A": "S",
  "\u015C": "S",
  "\u015E": "S",
  "\u0160": "S",
  "\u015B": "s",
  "\u015D": "s",
  "\u015F": "s",
  "\u0161": "s",
  "\u0162": "T",
  "\u0164": "T",
  "\u0166": "T",
  "\u0163": "t",
  "\u0165": "t",
  "\u0167": "t",
  "\u0168": "U",
  "\u016A": "U",
  "\u016C": "U",
  "\u016E": "U",
  "\u0170": "U",
  "\u0172": "U",
  "\u0169": "u",
  "\u016B": "u",
  "\u016D": "u",
  "\u016F": "u",
  "\u0171": "u",
  "\u0173": "u",
  "\u0174": "W",
  "\u0175": "w",
  "\u0176": "Y",
  "\u0177": "y",
  "\u0178": "Y",
  "\u0179": "Z",
  "\u017B": "Z",
  "\u017D": "Z",
  "\u017A": "z",
  "\u017C": "z",
  "\u017E": "z",
  "\u0132": "IJ",
  "\u0133": "ij",
  "\u0152": "Oe",
  "\u0153": "oe",
  "\u0149": "'n",
  "\u017F": "s"
};
var deburrLetter$1 = basePropertyOf(deburredLetters);
var _deburrLetter = deburrLetter$1;
var deburrLetter = _deburrLetter,
  toString$1 = toString_1;
var reLatin = /[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g;
var rsComboMarksRange$1 = "\\u0300-\\u036f",
  reComboHalfMarksRange$1 = "\\ufe20-\\ufe2f",
  rsComboSymbolsRange$1 = "\\u20d0-\\u20ff",
  rsComboRange$1 = rsComboMarksRange$1 + reComboHalfMarksRange$1 + rsComboSymbolsRange$1;
var rsCombo$1 = "[" + rsComboRange$1 + "]";
var reComboMark = RegExp(rsCombo$1, "g");
function deburr$1(string) {
  string = toString$1(string);
  return string && string.replace(reLatin, deburrLetter).replace(reComboMark, "");
}
var deburr_1 = deburr$1;
var reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
function asciiWords$1(string) {
  return string.match(reAsciiWord) || [];
}
var _asciiWords = asciiWords$1;
var reHasUnicodeWord = /[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/;
function hasUnicodeWord$1(string) {
  return reHasUnicodeWord.test(string);
}
var _hasUnicodeWord = hasUnicodeWord$1;
var rsAstralRange = "\\ud800-\\udfff",
  rsComboMarksRange = "\\u0300-\\u036f",
  reComboHalfMarksRange = "\\ufe20-\\ufe2f",
  rsComboSymbolsRange = "\\u20d0-\\u20ff",
  rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange,
  rsDingbatRange = "\\u2700-\\u27bf",
  rsLowerRange = "a-z\\xdf-\\xf6\\xf8-\\xff",
  rsMathOpRange = "\\xac\\xb1\\xd7\\xf7",
  rsNonCharRange = "\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf",
  rsPunctuationRange = "\\u2000-\\u206f",
  rsSpaceRange = " \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000",
  rsUpperRange = "A-Z\\xc0-\\xd6\\xd8-\\xde",
  rsVarRange = "\\ufe0e\\ufe0f",
  rsBreakRange = rsMathOpRange + rsNonCharRange + rsPunctuationRange + rsSpaceRange;
var rsApos$1 = "['\u2019]",
  rsBreak = "[" + rsBreakRange + "]",
  rsCombo = "[" + rsComboRange + "]",
  rsDigits = "\\d+",
  rsDingbat = "[" + rsDingbatRange + "]",
  rsLower = "[" + rsLowerRange + "]",
  rsMisc = "[^" + rsAstralRange + rsBreakRange + rsDigits + rsDingbatRange + rsLowerRange + rsUpperRange + "]",
  rsFitz = "\\ud83c[\\udffb-\\udfff]",
  rsModifier = "(?:" + rsCombo + "|" + rsFitz + ")",
  rsNonAstral = "[^" + rsAstralRange + "]",
  rsRegional = "(?:\\ud83c[\\udde6-\\uddff]){2}",
  rsSurrPair = "[\\ud800-\\udbff][\\udc00-\\udfff]",
  rsUpper = "[" + rsUpperRange + "]",
  rsZWJ = "\\u200d";
var rsMiscLower = "(?:" + rsLower + "|" + rsMisc + ")",
  rsMiscUpper = "(?:" + rsUpper + "|" + rsMisc + ")",
  rsOptContrLower = "(?:" + rsApos$1 + "(?:d|ll|m|re|s|t|ve))?",
  rsOptContrUpper = "(?:" + rsApos$1 + "(?:D|LL|M|RE|S|T|VE))?",
  reOptMod = rsModifier + "?",
  rsOptVar = "[" + rsVarRange + "]?",
  rsOptJoin = "(?:" + rsZWJ + "(?:" + [rsNonAstral, rsRegional, rsSurrPair].join("|") + ")" + rsOptVar + reOptMod + ")*",
  rsOrdLower = "\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])",
  rsOrdUpper = "\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])",
  rsSeq = rsOptVar + reOptMod + rsOptJoin,
  rsEmoji = "(?:" + [rsDingbat, rsRegional, rsSurrPair].join("|") + ")" + rsSeq;
var reUnicodeWord = RegExp([rsUpper + "?" + rsLower + "+" + rsOptContrLower + "(?=" + [rsBreak, rsUpper, "$"].join("|") + ")", rsMiscUpper + "+" + rsOptContrUpper + "(?=" + [rsBreak, rsUpper + rsMiscLower, "$"].join("|") + ")", rsUpper + "?" + rsMiscLower + "+" + rsOptContrLower, rsUpper + "+" + rsOptContrUpper, rsOrdUpper, rsOrdLower, rsDigits, rsEmoji].join("|"), "g");
function unicodeWords$1(string) {
  return string.match(reUnicodeWord) || [];
}
var _unicodeWords = unicodeWords$1;
var asciiWords = _asciiWords,
  hasUnicodeWord = _hasUnicodeWord,
  toString = toString_1,
  unicodeWords = _unicodeWords;
function words$1(string, pattern, guard) {
  string = toString(string);
  pattern = guard ? void 0 : pattern;
  if (pattern === void 0) {
    return hasUnicodeWord(string) ? unicodeWords(string) : asciiWords(string);
  }
  return string.match(pattern) || [];
}
var words_1 = words$1;
var arrayReduce = _arrayReduce,
  deburr = deburr_1,
  words = words_1;
var rsApos = "['\u2019]";
var reApos = RegExp(rsApos, "g");
function createCompounder$1(callback) {
  return function (string) {
    return arrayReduce(words(deburr(string).replace(reApos, "")), callback, "");
  };
}
var _createCompounder = createCompounder$1;
var capitalize = capitalize_1,
  createCompounder = _createCompounder;
var camelCase = createCompounder(function (result, word, index) {
  word = word.toLowerCase();
  return result + (index ? capitalize(word) : word);
});
var camelCase_1 = camelCase;
function ownKeys(object, enumerableOnly) {
  var keys = Object.keys(object);
  if (Object.getOwnPropertySymbols) {
    var symbols = Object.getOwnPropertySymbols(object);
    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 = null != arguments[i] ? arguments[i] : {};
    i % 2 ? ownKeys(Object(source), true).forEach(function (key) {
      _defineProperty(target, key, source[key]);
    }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
      Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
    });
  }
  return target;
}
class TreeStore {
  constructor(options) {
    _defineProperty(this, "children", void 0);
    _defineProperty(this, "nodes", void 0);
    _defineProperty(this, "nodeMap", void 0);
    _defineProperty(this, "config", void 0);
    _defineProperty(this, "activedMap", void 0);
    _defineProperty(this, "updatedMap", void 0);
    _defineProperty(this, "checkedMap", void 0);
    _defineProperty(this, "expandedMap", void 0);
    _defineProperty(this, "filterMap", void 0);
    _defineProperty(this, "updateTimer", void 0);
    _defineProperty(this, "shouldReflow", void 0);
    _defineProperty(this, "prevFilter", void 0);
    _defineProperty(this, "nullNodeModel", void 0);
    var config = _objectSpread({
      prefix: "t",
      keys: {},
      expandAll: false,
      expandLevel: 0,
      expandMutex: false,
      expandParent: false,
      activable: false,
      activeMultiple: false,
      checkable: false,
      checkStrictly: false,
      disabled: false,
      draggable: false,
      load: null,
      lazy: false,
      valueMode: "onlyLeaf",
      filter: null,
      onLoad: null,
      onReflow: null,
      onUpdate: null,
      allowFoldNodeOnFilter: false
    }, options);
    this.config = config;
    this.nodes = [];
    this.children = [];
    this.nodeMap = /* @__PURE__ */new Map();
    this.activedMap = /* @__PURE__ */new Map();
    this.expandedMap = /* @__PURE__ */new Map();
    this.checkedMap = /* @__PURE__ */new Map();
    this.updatedMap = /* @__PURE__ */new Map();
    this.filterMap = /* @__PURE__ */new Map();
    this.prevFilter = null;
    this.updateTimer = null;
    this.shouldReflow = false;
    this.initNullNodeModel();
  }
  initNullNodeModel() {
    var nullNode = new TreeNode(this, {
      value: "",
      label: "",
      children: []
    });
    this.nullNodeModel = nullNode.getModel();
    nullNode.remove();
  }
  setConfig(options) {
    var hasChanged = false;
    Object.keys(options).forEach(key => {
      var val = options[key];
      if (val !== this.config[key]) {
        hasChanged = true;
        this.config[key] = val;
      }
    });
    if (hasChanged) {
      this.refreshState();
    }
  }
  getChildren() {
    return this.children;
  }
  getNode(item) {
    var node = null;
    if (typeof item === "string" || typeof item === "number") node = this.nodeMap.get(item);else if (item instanceof TreeNode) node = this.nodeMap.get(item.value);
    return node;
  }
  getIndex(node) {
    return this.nodes.indexOf(node);
  }
  getParent(value) {
    var parent = null;
    var node = this.getNode(value);
    if (node) parent = node.getParent();
    return parent;
  }
  getParents(value) {
    var node = this.getNode(value);
    var parents = [];
    if (node) parents = node.getParents();
    return parents;
  }
  getNodeIndex(value) {
    var node = this.getNode(value);
    var index = -1;
    if (node) index = node.getIndex();
    return index;
  }
  getNodes(item, options) {
    var nodes = [];
    var val = "";
    if (typeof item === "string" || typeof item === "number") val = item;else if (item instanceof TreeNode) val = item.value;
    if (!val) {
      nodes = this.nodes.slice(0);
    } else {
      var node = this.getNode(val);
      if (node) nodes = node.walk();
    }
    if (options) {
      var conf = _objectSpread({
        filter: null,
        level: Infinity
      }, options);
      if (typeof conf.level === "number" && conf.level !== Infinity) nodes = nodes.filter(node2 => node2.level <= conf.level);
      if (typeof conf.filter === "function") {
        nodes = nodes.filter(node2 => {
          var nodeModel = node2.getModel();
          return conf.filter(nodeModel);
        });
      }
      if (isPlainObject_1(conf.props)) {
        nodes = nodes.filter(node2 => {
          var result = Object.keys(conf.props).every(key => {
            var propEqual = node2[key] === conf.props[key];
            return propEqual;
          });
          return result;
        });
      }
    }
    return nodes;
  }
  append(list) {
    list.forEach(item => {
      var node = new TreeNode(this, item);
      this.children.push(node);
    });
    this.reflow();
  }
  reload(list) {
    this.expandedMap.clear();
    this.checkedMap.clear();
    this.activedMap.clear();
    this.filterMap.clear();
    this.removeAll();
    this.append(list);
  }
  parseNodeData(para, item) {
    var value = "";
    var node = null;
    var data = null;
    if (typeof para === "string" || typeof para === "number") {
      value = para;
      data = item;
      node = this.getNode(value);
    } else if (para instanceof TreeNode) {
      node = para;
      data = item;
    } else {
      data = para;
    }
    var spec = {
      node,
      data
    };
    return spec;
  }
  appendNodes(para, item) {
    var spec = this.parseNodeData(para, item);
    if (spec.data) {
      if (!spec.node) {
        if (spec.data instanceof TreeNode) spec.data.appendTo(this);else if (Array.isArray(spec.data)) this.append(spec.data);else this.append([spec.data]);
      } else {
        if (spec.data instanceof TreeNode) spec.data.appendTo(this, spec.node);else if (Array.isArray(spec.data)) spec.node.append(spec.data);else spec.node.append([spec.data]);
        spec.node.updateRelated();
      }
    }
  }
  insertBefore(value, item) {
    var node = this.getNode(value);
    if (node) node.insertBefore(item);
  }
  insertAfter(value, item) {
    var node = this.getNode(value);
    if (node) node.insertAfter(item);
  }
  refreshNodes() {
    var {
      children,
      nodes
    } = this;
    nodes.length = 0;
    children.forEach(node => {
      var list = node.walk();
      Array.prototype.push.apply(nodes, list);
    });
  }
  refreshState() {
    var {
      nodes
    } = this;
    nodes.forEach(node => {
      node.update();
      node.updateChecked();
    });
  }
  reflow(node) {
    this.shouldReflow = true;
    this.updated(node);
  }
  updated(node) {
    if (node !== null && node !== void 0 && node.value) this.updatedMap.set(node.value, true);
    if (this.updateTimer) return;
    this.updateTimer = +setTimeout(() => {
      var _this$config;
      clearTimeout(this.updateTimer);
      this.updateTimer = null;
      if (this.shouldReflow) {
        this.refreshNodes();
        this.emit("reflow");
      }
      if (!((_this$config = this.config) !== null && _this$config !== void 0 && _this$config.allowFoldNodeOnFilter)) this.lockFilterPathNodes();
      var updatedList = Array.from(this.updatedMap.keys());
      if (updatedList.length > 0) {
        var updatedNodes = updatedList.map(value => this.getNode(value));
        this.emit("update", {
          nodes: updatedNodes,
          map: this.updatedMap
        });
      } else if (this.shouldReflow) {
        this.emit("update", {
          nodes: [],
          map: this.updatedMap
        });
      }
      this.shouldReflow = false;
      this.updatedMap.clear();
    });
  }
  getActived(map) {
    var activedMap = map || this.activedMap;
    return Array.from(activedMap.keys());
  }
  getActivedNodes(item) {
    var nodes = this.getNodes(item);
    nodes = nodes.filter(node => node.isActived());
    return nodes;
  }
  replaceActived(list) {
    this.resetActived();
    this.setActived(list);
  }
  setActived(actived) {
    var {
      activeMultiple
    } = this.config;
    var list = actived.slice(0);
    if (!activeMultiple) list.length = 1;
    list.forEach(val => {
      this.activedMap.set(val, true);
      var node = this.getNode(val);
      if (node) node.update();
    });
  }
  resetActived() {
    var actived = this.getActived();
    this.activedMap.clear();
    var relatedNodes = this.getRelatedNodes(actived);
    relatedNodes.forEach(node => {
      node.update();
    });
  }
  getExpanded(map) {
    var expandedMap = map || this.expandedMap;
    return Array.from(expandedMap.keys());
  }
  replaceExpanded(list) {
    var expanded = this.getExpanded();
    var added = difference_1(list, expanded);
    var removed = difference_1(expanded, list);
    this.setExpandedDirectly(removed, false);
    this.updateExpanded(removed);
    this.setExpanded(added);
  }
  setExpanded(list) {
    this.setExpandedDirectly(list);
    this.updateExpanded(list);
  }
  setExpandedDirectly(list) {
    var expanded = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : true;
    list.forEach(val => {
      if (expanded) {
        this.expandedMap.set(val, true);
        var node = this.getNode(val);
        if (node) node.afterExpanded();
      } else {
        this.expandedMap.delete(val);
      }
    });
  }
  resetExpanded() {
    var expanded = this.getExpanded();
    this.expandedMap.clear();
    this.updateExpanded(expanded);
  }
  updateExpanded(list) {
    var relatedNodes = this.getRelatedNodes(list, {
      withParents: false
    });
    relatedNodes.forEach(node => {
      node.update();
    });
  }
  getChecked(map) {
    var {
      nodes,
      config
    } = this;
    var {
      valueMode,
      checkStrictly
    } = config;
    var list = [];
    var checkedMap = map || this.checkedMap;
    nodes.forEach(node => {
      if (node.isChecked(checkedMap)) {
        if (valueMode === "parentFirst" && !checkStrictly) {
          if (!node.parent || !node.parent.isChecked(checkedMap)) list.push(node.value);
        } else if (valueMode === "onlyLeaf" && !checkStrictly) {
          if (node.isLeaf()) list.push(node.value);
        } else {
          list.push(node.value);
        }
      }
    });
    return list;
  }
  getCheckedNodes(item) {
    var nodes = this.getNodes(item);
    nodes = nodes.filter(node => node.isChecked());
    return nodes;
  }
  replaceChecked(list) {
    this.resetChecked();
    this.setChecked(list, true);
  }
  setChecked(list, isFromValueChange) {
    var {
      valueMode,
      checkStrictly,
      checkable
    } = this.config;
    if (!checkable) return;
    list.forEach(val => {
      var node = this.getNode(val);
      if (node) {
        if (valueMode === "parentFirst" && !checkStrictly) {
          var childrenNodes = node.walk();
          childrenNodes.forEach(childNode => {
            this.checkedMap.set(childNode.value, true);
          });
        } else {
          this.checkedMap.set(val, true);
          node.updateChecked(isFromValueChange);
        }
      }
    });
    if (!checkStrictly) {
      var checked = this.getChecked();
      var relatedNodes = this.getRelatedNodes(checked);
      relatedNodes.forEach(node => {
        node.updateChecked();
      });
    }
  }
  resetChecked() {
    var checked = this.getChecked();
    var relatedNodes = this.getRelatedNodes(checked);
    this.checkedMap.clear();
    relatedNodes.forEach(node => {
      node.updateChecked();
    });
  }
  updateAll() {
    var nodes = this.getNodes();
    nodes.forEach(node => {
      node.update();
    });
  }
  remove(value) {
    var node = this.getNode(value);
    if (node) node.remove();
  }
  removeAll() {
    var nodes = this.getNodes();
    nodes.forEach(node => {
      node.remove();
    });
  }
  getRelatedNodes(list, options) {
    var conf = _objectSpread({
      withParents: true
    }, options);
    var map = /* @__PURE__ */new Map();
    list.forEach(value => {
      if (map.get(value)) return;
      var node = this.getNode(value);
      if (node) {
        var parents = node.getParents();
        var children = node.walk();
        var related = [];
        if (conf.withParents) related = parents.concat(children);else related = children;
        related.forEach(relatedNode => {
          map.set(relatedNode.value, relatedNode);
        });
      }
    });
    var relatedNodes = Array.from(map.values());
    return relatedNodes;
  }
  emit(name, state) {
    var config = this.config || {};
    var methodName = camelCase_1("on-".concat(name));
    var method = config[methodName];
    if (typeof method === "function") method(state);
  }
  lockFilterPathNodes() {
    var {
      config
    } = this;
    var allNodes = this.getNodes();
    if (this.prevFilter) {
      allNodes.forEach(node => {
        node.lock(false);
      });
    }
    var currentFilter = config.filter;
    if (!currentFilter || typeof currentFilter !== "function") return;
    if (currentFilter(this.nullNodeModel)) return;
    this.prevFilter = config.filter;
    var map = /* @__PURE__ */new Map();
    allNodes.reverse().forEach(item => {
      var node = item;
      var parent = node.getParent();
      if (node.vmIsRest) {
        if (parent) {
          parent.expanded = true;
        }
        node.visible = true;
      }
      if (node.vmIsRest || map.get(node.value)) {
        if (parent && !parent.vmIsRest) map.set(parent.value, true);
      }
    });
    var filterPathValues = Array.from(map.keys());
    filterPathValues.forEach(value => {
      var node = this.getNode(value);
      if (node) node.lock(true);
    });
  }
}

export { TreeStore as T };
//# sourceMappingURL=dep-de0d5edf.js.map
