tdesign-vue-next
Version:
TDesign Component for vue-next
1,520 lines (1,458 loc) • 44 kB
JavaScript
/**
* tdesign v1.20.2
* (c) 2026 tdesign
* @license MIT
*/
'use strict';
var _classCallCheck = require('@babel/runtime/helpers/classCallCheck');
var _createClass = require('@babel/runtime/helpers/createClass');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var mitt = require('mitt');
var treeNode = require('./dep-6f04645f.js');
var isFunction = require('./dep-ed620b03.js');
var isString = require('./dep-df5442c5.js');
var isNumber = require('./dep-e41b3434.js');
var get = require('./dep-e129d089.js');
var _baseSlice = require('./dep-64b2629b.js');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var _classCallCheck__default = /*#__PURE__*/_interopDefaultLegacy(_classCallCheck);
var _createClass__default = /*#__PURE__*/_interopDefaultLegacy(_createClass);
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
var mitt__default = /*#__PURE__*/_interopDefaultLegacy(mitt);
/**
* The base implementation of `_.findIndex` and `_.findLastIndex` without
* support for iteratee shorthands.
*
* @private
* @param {Array} array The array to inspect.
* @param {Function} predicate The function invoked per iteration.
* @param {number} fromIndex The index to search from.
* @param {boolean} [fromRight] Specify iterating from right to left.
* @returns {number} Returns the index of the matched value, else `-1`.
*/
function baseFindIndex(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;
}
/**
* The base implementation of `_.isNaN` without support for number objects.
*
* @private
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
*/
function baseIsNaN(value) {
return value !== value;
}
/**
* A specialized version of `_.indexOf` which performs strict equality
* comparisons of values, i.e. `===`.
*
* @private
* @param {Array} array The array to inspect.
* @param {*} value The value to search for.
* @param {number} fromIndex The index to search from.
* @returns {number} Returns the index of the matched value, else `-1`.
*/
function strictIndexOf(array, value, fromIndex) {
var index = fromIndex - 1,
length = array.length;
while (++index < length) {
if (array[index] === value) {
return index;
}
}
return -1;
}
/**
* The base implementation of `_.indexOf` without `fromIndex` bounds checks.
*
* @private
* @param {Array} array The array to inspect.
* @param {*} value The value to search for.
* @param {number} fromIndex The index to search from.
* @returns {number} Returns the index of the matched value, else `-1`.
*/
function baseIndexOf(array, value, fromIndex) {
return value === value ? strictIndexOf(array, value, fromIndex) : baseFindIndex(array, baseIsNaN, fromIndex);
}
/**
* A specialized version of `_.includes` for arrays without support for
* specifying an index to search from.
*
* @private
* @param {Array} [array] The array to inspect.
* @param {*} target The value to search for.
* @returns {boolean} Returns `true` if `target` is found, else `false`.
*/
function arrayIncludes(array, value) {
var length = array == null ? 0 : array.length;
return !!length && baseIndexOf(array, value, 0) > -1;
}
/**
* The base implementation of `_.rest` which doesn't validate or coerce arguments.
*
* @private
* @param {Function} func The function to apply a rest parameter to.
* @param {number} [start=func.length-1] The start position of the rest parameter.
* @returns {Function} Returns the new function.
*/
function baseRest(func, start) {
return treeNode.setToString(treeNode.overRest(func, start, treeNode.identity), func + '');
}
/**
* Casts `array` to a slice if it's needed.
*
* @private
* @param {Array} array The array to inspect.
* @param {number} start The start position.
* @param {number} [end=array.length] The end position.
* @returns {Array} Returns the cast slice.
*/
function castSlice(array, start, end) {
var length = array.length;
end = end === undefined ? length : end;
return !start && end >= length ? array : _baseSlice.baseSlice(array, start, end);
}
/** Used to compose unicode character classes. */
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";
/** Used to compose unicode capture groups. */
var rsZWJ$2 = "\\u200d";
/** Used to detect strings with [zero-width joiners or code points from the astral planes](http://eev.ee/blog/2015/09/12/dark-corners-of-unicode/). */
var reHasUnicode = RegExp('[' + rsZWJ$2 + rsAstralRange$2 + rsComboRange$3 + rsVarRange$2 + ']');
/**
* Checks if `string` contains Unicode symbols.
*
* @private
* @param {string} string The string to inspect.
* @returns {boolean} Returns `true` if a symbol is found, else `false`.
*/
function hasUnicode(string) {
return reHasUnicode.test(string);
}
/**
* Converts an ASCII `string` to an array.
*
* @private
* @param {string} string The string to convert.
* @returns {Array} Returns the converted array.
*/
function asciiToArray(string) {
return string.split('');
}
/** Used to compose unicode character classes. */
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";
/** Used to compose unicode capture groups. */
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";
/** Used to compose unicode regexes. */
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('|') + ')';
/** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */
var reUnicode = RegExp(rsFitz$1 + '(?=' + rsFitz$1 + ')|' + rsSymbol + rsSeq$1, 'g');
/**
* Converts a Unicode `string` to an array.
*
* @private
* @param {string} string The string to convert.
* @returns {Array} Returns the converted array.
*/
function unicodeToArray(string) {
return string.match(reUnicode) || [];
}
/**
* Converts `string` to an array.
*
* @private
* @param {string} string The string to convert.
* @returns {Array} Returns the converted array.
*/
function stringToArray(string) {
return hasUnicode(string) ? unicodeToArray(string) : asciiToArray(string);
}
/**
* Creates a function like `_.lowerFirst`.
*
* @private
* @param {string} methodName The name of the `String` case method to use.
* @returns {Function} Returns the new case function.
*/
function createCaseFirst(methodName) {
return function (string) {
string = get.toString(string);
var strSymbols = hasUnicode(string) ? stringToArray(string) : undefined;
var chr = strSymbols ? strSymbols[0] : string.charAt(0);
var trailing = strSymbols ? castSlice(strSymbols, 1).join('') : string.slice(1);
return chr[methodName]() + trailing;
};
}
/**
* Converts the first character of `string` to upper case.
*
* @static
* @memberOf _
* @since 4.0.0
* @category String
* @param {string} [string=''] The string to convert.
* @returns {string} Returns the converted string.
* @example
*
* _.upperFirst('fred');
* // => 'Fred'
*
* _.upperFirst('FRED');
* // => 'FRED'
*/
var upperFirst = createCaseFirst('toUpperCase');
/**
* Converts the first character of `string` to upper case and the remaining
* to lower case.
*
* @static
* @memberOf _
* @since 3.0.0
* @category String
* @param {string} [string=''] The string to capitalize.
* @returns {string} Returns the capitalized string.
* @example
*
* _.capitalize('FRED');
* // => 'Fred'
*/
function capitalize(string) {
return upperFirst(get.toString(string).toLowerCase());
}
/**
* A specialized version of `_.reduce` for arrays without support for
* iteratee shorthands.
*
* @private
* @param {Array} [array] The array to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @param {*} [accumulator] The initial value.
* @param {boolean} [initAccum] Specify using the first element of `array` as
* the initial value.
* @returns {*} Returns the accumulated value.
*/
function arrayReduce(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;
}
/**
* The base implementation of `_.propertyOf` without support for deep paths.
*
* @private
* @param {Object} object The object to query.
* @returns {Function} Returns the new accessor function.
*/
function basePropertyOf(object) {
return function (key) {
return object == null ? undefined : object[key];
};
}
/** Used to map Latin Unicode letters to basic Latin letters. */
var deburredLetters = {
// Latin-1 Supplement block.
'\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',
// Latin Extended-A block.
"\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'
};
/**
* Used by `_.deburr` to convert Latin-1 Supplement and Latin Extended-A
* letters to basic Latin letters.
*
* @private
* @param {string} letter The matched letter to deburr.
* @returns {string} Returns the deburred letter.
*/
var deburrLetter = basePropertyOf(deburredLetters);
/** Used to match Latin Unicode letters (excluding mathematical operators). */
var reLatin = /[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g;
/** Used to compose unicode character classes. */
var rsComboMarksRange$1 = "\\u0300-\\u036f",
reComboHalfMarksRange$1 = "\\ufe20-\\ufe2f",
rsComboSymbolsRange$1 = "\\u20d0-\\u20ff",
rsComboRange$1 = rsComboMarksRange$1 + reComboHalfMarksRange$1 + rsComboSymbolsRange$1;
/** Used to compose unicode capture groups. */
var rsCombo$1 = '[' + rsComboRange$1 + ']';
/**
* Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks) and
* [combining diacritical marks for symbols](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks_for_Symbols).
*/
var reComboMark = RegExp(rsCombo$1, 'g');
/**
* Deburrs `string` by converting
* [Latin-1 Supplement](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
* and [Latin Extended-A](https://en.wikipedia.org/wiki/Latin_Extended-A)
* letters to basic Latin letters and removing
* [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
*
* @static
* @memberOf _
* @since 3.0.0
* @category String
* @param {string} [string=''] The string to deburr.
* @returns {string} Returns the deburred string.
* @example
*
* _.deburr('déjà vu');
* // => 'deja vu'
*/
function deburr(string) {
string = get.toString(string);
return string && string.replace(reLatin, deburrLetter).replace(reComboMark, '');
}
/** Used to match words composed of alphanumeric characters. */
var reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
/**
* Splits an ASCII `string` into an array of its words.
*
* @private
* @param {string} The string to inspect.
* @returns {Array} Returns the words of `string`.
*/
function asciiWords(string) {
return string.match(reAsciiWord) || [];
}
/** Used to detect strings that need a more robust regexp to match words. */
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 ]/;
/**
* Checks if `string` contains a word composed of Unicode symbols.
*
* @private
* @param {string} string The string to inspect.
* @returns {boolean} Returns `true` if a word is found, else `false`.
*/
function hasUnicodeWord(string) {
return reHasUnicodeWord.test(string);
}
/** Used to compose unicode character classes. */
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;
/** Used to compose unicode capture groups. */
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";
/** Used to compose unicode regexes. */
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;
/** Used to match complex or compound words. */
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');
/**
* Splits a Unicode `string` into an array of its words.
*
* @private
* @param {string} The string to inspect.
* @returns {Array} Returns the words of `string`.
*/
function unicodeWords(string) {
return string.match(reUnicodeWord) || [];
}
/**
* Splits `string` into an array of its words.
*
* @static
* @memberOf _
* @since 3.0.0
* @category String
* @param {string} [string=''] The string to inspect.
* @param {RegExp|string} [pattern] The pattern to match words.
* @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
* @returns {Array} Returns the words of `string`.
* @example
*
* _.words('fred, barney, & pebbles');
* // => ['fred', 'barney', 'pebbles']
*
* _.words('fred, barney, & pebbles', /[^, ]+/g);
* // => ['fred', 'barney', '&', 'pebbles']
*/
function words(string, pattern, guard) {
string = get.toString(string);
pattern = guard ? undefined : pattern;
if (pattern === undefined) {
return hasUnicodeWord(string) ? unicodeWords(string) : asciiWords(string);
}
return string.match(pattern) || [];
}
/** Used to compose unicode capture groups. */
var rsApos = "['\u2019]";
/** Used to match apostrophes. */
var reApos = RegExp(rsApos, 'g');
/**
* Creates a function like `_.camelCase`.
*
* @private
* @param {Function} callback The function to combine each word.
* @returns {Function} Returns the new compounder function.
*/
function createCompounder(callback) {
return function (string) {
return arrayReduce(words(deburr(string).replace(reApos, '')), callback, '');
};
}
/**
* Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase).
*
* @static
* @memberOf _
* @since 3.0.0
* @category String
* @param {string} [string=''] The string to convert.
* @returns {string} Returns the camel cased string.
* @example
*
* _.camelCase('Foo Bar');
* // => 'fooBar'
*
* _.camelCase('--foo-bar--');
* // => 'fooBar'
*
* _.camelCase('__FOO_BAR__');
* // => 'fooBar'
*/
var camelCase = createCompounder(function (result, word, index) {
word = word.toLowerCase();
return result + (index ? capitalize(word) : word);
});
var camelCase$1 = camelCase;
/** Used to stand-in for `undefined` hash values. */
var HASH_UNDEFINED = '__lodash_hash_undefined__';
/**
* Adds `value` to the array cache.
*
* @private
* @name add
* @memberOf SetCache
* @alias push
* @param {*} value The value to cache.
* @returns {Object} Returns the cache instance.
*/
function setCacheAdd(value) {
this.__data__.set(value, HASH_UNDEFINED);
return this;
}
/**
* Checks if `value` is in the array cache.
*
* @private
* @name has
* @memberOf SetCache
* @param {*} value The value to search for.
* @returns {number} Returns `true` if `value` is found, else `false`.
*/
function setCacheHas(value) {
return this.__data__.has(value);
}
/**
*
* Creates an array cache object to store unique values.
*
* @private
* @constructor
* @param {Array} [values] The values to cache.
*/
function SetCache(values) {
var index = -1,
length = values == null ? 0 : values.length;
this.__data__ = new get.MapCache();
while (++index < length) {
this.add(values[index]);
}
}
// Add methods to `SetCache`.
SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
SetCache.prototype.has = setCacheHas;
/**
* Checks if a `cache` value for `key` exists.
*
* @private
* @param {Object} cache The cache to query.
* @param {string} key The key of the entry to check.
* @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
*/
function cacheHas(cache, key) {
return cache.has(key);
}
/**
* This method is like `_.isArrayLike` except that it also checks if `value`
* is an object.
*
* @static
* @memberOf _
* @since 4.0.0
* @category Lang
* @param {*} value The value to check.
* @returns {boolean} Returns `true` if `value` is an array-like object,
* else `false`.
* @example
*
* _.isArrayLikeObject([1, 2, 3]);
* // => true
*
* _.isArrayLikeObject(document.body.children);
* // => true
*
* _.isArrayLikeObject('abc');
* // => false
*
* _.isArrayLikeObject(_.noop);
* // => false
*/
function isArrayLikeObject(value) {
return isString.isObjectLike(value) && _baseSlice.isArrayLike(value);
}
/**
* This function is like `arrayIncludes` except that it accepts a comparator.
*
* @private
* @param {Array} [array] The array to inspect.
* @param {*} target The value to search for.
* @param {Function} comparator The comparator invoked per element.
* @returns {boolean} Returns `true` if `target` is found, else `false`.
*/
function arrayIncludesWith(array, value, comparator) {
var index = -1,
length = array == null ? 0 : array.length;
while (++index < length) {
if (comparator(value, array[index])) {
return true;
}
}
return false;
}
/** Used as the size to enable large array optimizations. */
var LARGE_ARRAY_SIZE = 200;
/**
* The base implementation of methods like `_.difference` without support
* for excluding multiple arrays or iteratee shorthands.
*
* @private
* @param {Array} array The array to inspect.
* @param {Array} values The values to exclude.
* @param {Function} [iteratee] The iteratee invoked per element.
* @param {Function} [comparator] The comparator invoked per element.
* @returns {Array} Returns the new array of filtered values.
*/
function baseDifference(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 = get.arrayMap(values, treeNode.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;
}
/**
* Creates an array of `array` values not included in the other given arrays
* using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
* for equality comparisons. The order and references of result values are
* determined by the first array.
*
* **Note:** Unlike `_.pullAll`, this method returns a new array.
*
* @static
* @memberOf _
* @since 0.1.0
* @category Array
* @param {Array} array The array to inspect.
* @param {...Array} [values] The values to exclude.
* @returns {Array} Returns the new array of filtered values.
* @see _.without, _.xor
* @example
*
* _.difference([2, 1], [2, 3]);
* // => [1]
*/
var difference = baseRest(function (array, values) {
return isArrayLikeObject(array) ? baseDifference(array, treeNode.baseFlatten(values, 1, isArrayLikeObject, true)) : [];
});
var difference$1 = difference;
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty__default["default"](e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function nextTick(fn) {
var pm = Promise.resolve();
pm.then(fn);
return pm;
}
var TreeStore = /*#__PURE__*/function () {
function TreeStore(options) {
_classCallCheck__default["default"](this, TreeStore);
_defineProperty__default["default"](this, "children", void 0);
_defineProperty__default["default"](this, "nodes", void 0);
_defineProperty__default["default"](this, "nodeMap", void 0);
_defineProperty__default["default"](this, "privateMap", void 0);
_defineProperty__default["default"](this, "config", void 0);
_defineProperty__default["default"](this, "activedMap", void 0);
_defineProperty__default["default"](this, "updatedMap", void 0);
_defineProperty__default["default"](this, "checkedMap", void 0);
_defineProperty__default["default"](this, "expandedMap", void 0);
_defineProperty__default["default"](this, "filterMap", void 0);
_defineProperty__default["default"](this, "hasFilter", void 0);
_defineProperty__default["default"](this, "emitter", void 0);
_defineProperty__default["default"](this, "updateTick", void 0);
_defineProperty__default["default"](this, "shouldReflow", void 0);
_defineProperty__default["default"](this, "prevFilter", 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,
disableCheck: false,
draggable: false,
load: null,
lazy: false,
valueMode: "onlyLeaf",
filter: null,
allowFoldNodeOnFilter: false,
onLoad: null,
onReflow: null,
onUpdate: null
}, options);
this.config = config;
this.nodes = [];
this.children = [];
this.nodeMap = /* @__PURE__ */new Map();
this.privateMap = /* @__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.updateTick = null;
this.shouldReflow = false;
this.hasFilter = isFunction.isFunction(config.filter);
this.emitter = mitt__default["default"]();
}
return _createClass__default["default"](TreeStore, [{
key: "setConfig",
value: function setConfig(options) {
var config = this.config;
var hasChanged = false;
Object.keys(options).forEach(function (key) {
var val = options[key];
if (val !== config[key]) {
hasChanged = true;
config[key] = val;
}
});
this.hasFilter = isFunction.isFunction(config.filter);
if (hasChanged) {
this.refreshState();
}
}
}, {
key: "getChildren",
value: function getChildren() {
return this.children;
}
}, {
key: "getNode",
value: function getNode(item) {
var node = null;
if (isString.isString(item) || isNumber.isNumber(item)) {
node = this.nodeMap.get(item);
} else if (item instanceof treeNode.TreeNode) {
node = this.nodeMap.get(item.value);
}
if (!node) node = null;
return node;
}
}, {
key: "getIndex",
value: function getIndex(node) {
return this.nodes.indexOf(node);
}
}, {
key: "getParent",
value: function getParent(value) {
var parent = null;
var node = this.getNode(value);
if (node) {
parent = node.getParent();
}
return parent;
}
}, {
key: "getParents",
value: function getParents(value) {
var node = this.getNode(value);
var parents = [];
if (node) {
parents = node.getParents();
}
return parents;
}
}, {
key: "getNodeIndex",
value: function getNodeIndex(value) {
var node = this.getNode(value);
var index = -1;
if (node) {
index = node.getIndex();
}
return index;
}
}, {
key: "getNodes",
value: function getNodes(item, options) {
var nodes = [];
var val = "";
if (isString.isString(item) || isNumber.isNumber(item)) {
val = item;
} else if (item instanceof treeNode.TreeNode) {
val = item.value;
}
if (!val && val !== 0) {
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 (isNumber.isNumber(conf.level) && conf.level !== Infinity) {
nodes = nodes.filter(function (node) {
return node.level <= conf.level;
});
}
if (isFunction.isFunction(conf.filter)) {
nodes = nodes.filter(function (node) {
var nodeModel = node.getModel();
return conf.filter(nodeModel);
});
}
if (treeNode.isPlainObject(conf.props)) {
nodes = nodes.filter(function (node) {
var result = Object.keys(conf.props).every(function (key) {
var propEqual = node[key] === conf.props[key];
return propEqual;
});
return result;
});
}
}
return nodes;
}
}, {
key: "append",
value: function append(list) {
var _this = this;
list.forEach(function (item) {
var node = new treeNode.TreeNode(_this, item);
_this.children.push(node);
});
this.reflow();
}
}, {
key: "reload",
value: function reload(list) {
this.removeAll();
this.append(list);
}
}, {
key: "parseNodeData",
value: function parseNodeData(para, item) {
var value = "";
var node = null;
var data = null;
if (isString.isString(para) || isNumber.isNumber(para)) {
value = para;
node = this.getNode(value);
data = item;
} else if (para instanceof treeNode.TreeNode) {
if (item) {
node = para;
data = item;
} else {
data = para;
}
} else {
data = para;
}
var spec = {
node: node,
data: data
};
return spec;
}
}, {
key: "appendNodes",
value: function appendNodes(para, item) {
var spec = this.parseNodeData(para, item);
if (spec.data) {
if (!spec.node) {
if (spec.data instanceof treeNode.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.TreeNode) {
spec.data.appendTo(this, spec.node);
} else if (isString.isArray(spec.data)) {
spec.node.append(spec.data);
} else {
spec.node.append([spec.data]);
}
spec.node.updateRelated();
}
}
}
}, {
key: "insertBefore",
value: function insertBefore(value, item) {
var node = this.getNode(value);
if (node) {
node.insertBefore(item);
}
}
}, {
key: "insertAfter",
value: function insertAfter(value, item) {
var node = this.getNode(value);
if (node) {
node.insertAfter(item);
}
}
}, {
key: "refreshNodes",
value: function refreshNodes() {
var children = this.children,
nodes = this.nodes;
nodes.length = 0;
children.forEach(function (node) {
var list = node.walk();
Array.prototype.push.apply(nodes, list);
});
}
}, {
key: "reflow",
value: function reflow(node) {
this.shouldReflow = true;
this.updated(node);
}
}, {
key: "updated",
value: function updated(node) {
var _this2 = this;
var updatedMap = this.updatedMap;
if (node) {
updatedMap.set(node[treeNode.privateKey], "changed");
} else {
this.getNodes().forEach(function (itemNode) {
updatedMap.set(itemNode[treeNode.privateKey], "changed");
});
}
if (this.updateTick) return;
this.updateTick = nextTick(function () {
_this2.updateTick = null;
if (_this2.shouldReflow) {
_this2.refreshNodes();
_this2.emit("reflow");
}
_this2.lockFilterPathNodes();
var stateId = "t".concat(new Date().getTime());
var updatedList = Array.from(updatedMap.keys());
var updatedNodes = updatedList.map(function (nodePrivateKey) {
updatedMap.set(nodePrivateKey, stateId);
return _this2.privateMap.get(nodePrivateKey);
});
_this2.emit("update", {
nodes: updatedNodes,
map: updatedMap
});
_this2.shouldReflow = false;
updatedMap.clear();
});
}
}, {
key: "getActived",
value: function getActived(map) {
var activedMap = map || this.activedMap;
return Array.from(activedMap.keys());
}
}, {
key: "getActivedNodes",
value: function getActivedNodes(item) {
var nodes = this.getNodes(item);
nodes = nodes.filter(function (node) {
return node.isActived();
});
return nodes;
}
}, {
key: "replaceActived",
value: function replaceActived(list) {
this.resetActived();
this.setActived(list);
}
}, {
key: "setActived",
value: function setActived(actived) {
var _this3 = this;
var activeMultiple = this.config.activeMultiple;
var list = actived.slice(0);
if (!activeMultiple) {
list.length = 1;
}
list.forEach(function (val) {
_this3.activedMap.set(val, true);
var node = _this3.getNode(val);
if (node) {
node.update();
}
});
}
}, {
key: "resetActived",
value: function resetActived() {
var actived = this.getActived();
this.activedMap.clear();
var relatedNodes = this.getRelatedNodes(actived);
relatedNodes.forEach(function (node) {
node.update();
});
}
}, {
key: "getExpanded",
value: function getExpanded(map) {
var expandedMap = map || this.expandedMap;
return Array.from(expandedMap.keys());
}
}, {
key: "replaceExpanded",
value: function 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);
}
}, {
key: "setExpanded",
value: function setExpanded(list) {
this.setExpandedDirectly(list);
this.updateExpanded(list);
}
}, {
key: "setExpandedDirectly",
value: function setExpandedDirectly(list) {
var _this4 = this;
var expanded = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
list.forEach(function (val) {
var node = _this4.getNode(val);
if (!(node !== null && node !== void 0 && node.isLeaf()) && expanded) {
_this4.expandedMap.set(val, true);
} else {
_this4.expandedMap["delete"](val);
}
node === null || node === void 0 || node.afterExpanded();
});
}
}, {
key: "resetExpanded",
value: function resetExpanded() {
var expanded = this.getExpanded();
this.expandedMap.clear();
this.updateExpanded(expanded);
}
}, {
key: "updateExpanded",
value: function updateExpanded(list) {
var relatedNodes = this.getRelatedNodes(list, {
withParents: false
});
relatedNodes.forEach(function (node) {
node.update();
});
}
}, {
key: "getChecked",
value: function getChecked(map) {
var nodeMap = this.nodeMap,
config = this.config;
var valueMode = config.valueMode,
checkStrictly = config.checkStrictly;
var list = [];
var checkedMap = map || this.checkedMap;
nodeMap.forEach(function (node) {
if (!node.isChecked(checkedMap)) return;
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;
}
}, {
key: "getCheckedNodes",
value: function getCheckedNodes(item) {
var nodes = this.getNodes(item);
nodes = nodes.filter(function (node) {
return node.isChecked();
});
return nodes;
}
}, {
key: "replaceChecked",
value: function replaceChecked(list) {
this.resetChecked();
this.setChecked(list);
}
}, {
key: "setChecked",
value: function setChecked(list) {
var _this5 = this;
var _this$config = this.config,
checkStrictly = _this$config.checkStrictly,
checkable = _this$config.checkable;
if (!checkable) return;
list.forEach(function (val) {
var node = _this5.getNode(val);
if (!node) return;
if (checkStrictly) {
_this5.checkedMap.set(val, true);
node.updateChecked();
} else {
var childrenNodes = node.walk();
childrenNodes.forEach(function (childNode) {
_this5.checkedMap.set(childNode.value, true);
});
}
});
if (!checkStrictly) {
var checkedValues = this.getChecked();
var relatedNodes = this.getRelatedNodes(checkedValues);
relatedNodes.forEach(function (node) {
node.updateChecked();
});
}
}
}, {
key: "resetChecked",
value: function resetChecked() {
var checked = this.getChecked();
var relatedNodes = this.getRelatedNodes(checked);
this.checkedMap.clear();
relatedNodes.forEach(function (node) {
node.updateChecked();
});
}
}, {
key: "refreshState",
value: function refreshState() {
var nodeMap = this.nodeMap;
nodeMap.forEach(function (node) {
node.update();
});
}
}, {
key: "updateAll",
value: function updateAll() {
var nodeMap = this.nodeMap;
nodeMap.forEach(function (node) {
node.update();
node.updateChecked();
});
}
}, {
key: "remove",
value: function remove(value) {
var node = this.getNode(value);
if (node) {
node.remove();
}
}
}, {
key: "removeAll",
value: function removeAll() {
this.expandedMap.clear();
this.checkedMap.clear();
this.activedMap.clear();
this.filterMap.clear();
this.nodeMap.clear();
this.privateMap.clear();
this.updatedMap.clear();
this.nodes = [];
this.children = [];
this.reflow();
}
}, {
key: "getRelatedNodes",
value: function getRelatedNodes(list, options) {
var _this6 = this;
var conf = _objectSpread({
reverse: false,
withParents: true
}, options);
var map = /* @__PURE__ */new Map();
list.forEach(function (value) {
if (map.get(value)) return;
var node = _this6.getNode(value);
if (node) {
var parents = node.getParents().reverse();
var children = node.walk();
var related = [];
if (conf.withParents) {
related = parents.concat(children);
} else {
related = children;
}
related.forEach(function (relatedNode) {
map.set(relatedNode.value, relatedNode);
});
}
});
var relatedNodes = Array.from(map.values());
if (conf.reverse) {
relatedNodes = relatedNodes.reverse();
}
return relatedNodes;
}
}, {
key: "emit",
value: function emit(name, state) {
var config = this.config,
emitter = this.emitter;
var methodName = camelCase$1("on-".concat(name));
var method = config[methodName];
if (isFunction.isFunction(method)) {
method(state);
}
emitter.emit(name, state);
}
}, {
key: "lockFilterPathNodes",
value: function lockFilterPathNodes() {
var config = this.config;
var allNodes = this.getNodes();
if (this.prevFilter) {
allNodes.forEach(function (node) {
if (node.vmIsLocked) {
node.lock(false);
}
});
}
var currentFilter = config.filter;
if (!currentFilter || !isFunction.isFunction(currentFilter)) return;
this.prevFilter = config.filter;
allNodes.reverse().forEach(function (node) {
var parent = node.getParent();
if (!parent) return;
if (node.vmIsRest || node.vmIsLocked) {
if (!parent.vmIsLocked) {
parent.lock(true);
}
}
});
}
}]);
}();
exports.TreeStore = TreeStore;
//# sourceMappingURL=dep-2bee593d.js.map