@hi-ui/check-select 4.0.0-alpha.14 → 4.0.0-alpha.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/lib/cjs/CheckSelect.js +204 -132
- package/lib/cjs/CheckSelect.js.map +1 -1
- package/lib/cjs/index.js +0 -1
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/styles/index.scss.js +1 -1
- package/lib/cjs/use-check-select.js +59 -33
- package/lib/cjs/use-check-select.js.map +1 -1
- package/lib/esm/CheckSelect.js +202 -129
- package/lib/esm/CheckSelect.js.map +1 -1
- package/lib/esm/index.js +1 -1
- package/lib/esm/styles/index.scss.js +1 -1
- package/lib/esm/use-check-select.js +58 -32
- package/lib/esm/use-check-select.js.map +1 -1
- package/lib/types/CheckSelect.d.ts +44 -13
- package/lib/types/context.d.ts +6 -20
- package/lib/types/hooks/use-search.d.ts +2 -2
- package/lib/types/types.d.ts +28 -4
- package/lib/types/use-check-select.d.ts +15 -22
- package/package.json +14 -6
- package/lib/cjs/hooks/use-search.js +0 -154
- package/lib/cjs/hooks/use-search.js.map +0 -1
- package/lib/cjs/utils/type-assertion/lib/esm/index.js +0 -42
- package/lib/cjs/utils/type-assertion/lib/esm/index.js.map +0 -1
- package/lib/esm/hooks/use-search.js +0 -144
- package/lib/esm/hooks/use-search.js.map +0 -1
- package/lib/esm/utils/type-assertion/lib/esm/index.js +0 -33
- package/lib/esm/utils/type-assertion/lib/esm/index.js.map +0 -1
@@ -1,154 +0,0 @@
|
|
1
|
-
/** @LICENSE
|
2
|
-
* @hi-ui/check-select
|
3
|
-
* https://github.com/XiaoMi/hiui/tree/master/packages/ui/check-select#readme
|
4
|
-
*
|
5
|
-
* Copyright (c) HIUI <mi-hiui@xiaomi.com>.
|
6
|
-
*
|
7
|
-
* This source code is licensed under the MIT license found in the
|
8
|
-
* LICENSE file in the root directory of this source tree.
|
9
|
-
*/
|
10
|
-
'use strict';
|
11
|
-
|
12
|
-
Object.defineProperty(exports, '__esModule', {
|
13
|
-
value: true
|
14
|
-
});
|
15
|
-
|
16
|
-
var React = require('react');
|
17
|
-
|
18
|
-
var useLatest = require('@hi-ui/use-latest');
|
19
|
-
|
20
|
-
var env = require('@hi-ui/env');
|
21
|
-
|
22
|
-
var index = require('../utils/type-assertion/lib/esm/index.js');
|
23
|
-
/**
|
24
|
-
* 支持搜索功能的 hook
|
25
|
-
*/
|
26
|
-
|
27
|
-
|
28
|
-
var useSearch = function useSearch(flattedData, filter) {
|
29
|
-
var _useState = React.useState(''),
|
30
|
-
searchValue = _useState[0],
|
31
|
-
setSearchValue = _useState[1];
|
32
|
-
|
33
|
-
var _useState2 = React.useState([]),
|
34
|
-
matchedNodes = _useState2[0],
|
35
|
-
setMatchedNodes = _useState2[1];
|
36
|
-
|
37
|
-
var flattedDataRef = useLatest.useLatestRef(flattedData);
|
38
|
-
var handleChange = React.useCallback(function (evt) {
|
39
|
-
var nextSearchValue = evt.target.value;
|
40
|
-
setSearchValue(nextSearchValue); // 匹配到搜索的节点,将这些节点进行展开显示,其它均隐藏
|
41
|
-
|
42
|
-
var matchedNodes = getMatchedNodes(flattedDataRef.current, nextSearchValue, filter);
|
43
|
-
setMatchedNodes(matchedNodes);
|
44
|
-
}, [flattedDataRef, filter]);
|
45
|
-
var inputProps = React.useMemo(function () {
|
46
|
-
return {
|
47
|
-
value: searchValue,
|
48
|
-
onChange: handleChange
|
49
|
-
};
|
50
|
-
}, [searchValue, handleChange]);
|
51
|
-
var resetSearch = React.useCallback(function () {
|
52
|
-
setSearchValue('');
|
53
|
-
}, []);
|
54
|
-
var isSearch = !!searchValue;
|
55
|
-
var isEmpty = isSearch && matchedNodes.length === 0;
|
56
|
-
return [isSearch, matchedNodes, inputProps, isEmpty, resetSearch];
|
57
|
-
};
|
58
|
-
/**
|
59
|
-
* 从 value 中 找到指定的 options(逐层查找)
|
60
|
-
*/
|
61
|
-
|
62
|
-
|
63
|
-
var getMatchedNodes = function getMatchedNodes(flattedData, searchValue, filter) {
|
64
|
-
if (!searchValue) return [];
|
65
|
-
var matchedResult = [];
|
66
|
-
var shouldFilter = index.isFunction(filter); // 1. 先对于 groupTitle 匹配
|
67
|
-
// 2. 若未匹配到。再对其 children 进行 title 匹配
|
68
|
-
|
69
|
-
var _loop = function _loop(i) {
|
70
|
-
var optionOrGroup = flattedData[i];
|
71
|
-
|
72
|
-
if ('groupTitle' in optionOrGroup) {
|
73
|
-
// search for OptionGroup
|
74
|
-
// @ts-ignore
|
75
|
-
var shouldReserved = shouldFilter && filter(searchValue, optionOrGroup) === true;
|
76
|
-
|
77
|
-
if (shouldReserved) {
|
78
|
-
matchedResult.push(optionOrGroup);
|
79
|
-
return "continue";
|
80
|
-
}
|
81
|
-
|
82
|
-
if (typeof optionOrGroup.groupTitle === 'string') {
|
83
|
-
// 匹配策略:`String.include`
|
84
|
-
if (optionOrGroup.groupTitle.includes(searchValue)) {
|
85
|
-
matchedResult.push(optionOrGroup);
|
86
|
-
return "continue";
|
87
|
-
}
|
88
|
-
} else {
|
89
|
-
if (env.__DEV__) {
|
90
|
-
console.info('WARNING: The `optionGroup.groupTitle` should be `string` when searchable is enabled.');
|
91
|
-
}
|
92
|
-
}
|
93
|
-
|
94
|
-
if (index.isArrayNonEmpty(optionOrGroup.children)) {
|
95
|
-
var matchedChildren = optionOrGroup.children.filter(function (node) {
|
96
|
-
var _a, _b;
|
97
|
-
|
98
|
-
if (shouldFilter) {
|
99
|
-
// @ts-ignore
|
100
|
-
return filter(searchValue, optionOrGroup);
|
101
|
-
}
|
102
|
-
|
103
|
-
if (typeof node.title !== 'string') {
|
104
|
-
if (env.__DEV__) {
|
105
|
-
console.info('WARNING: The `option.title` should be `string` when searchable is enabled.');
|
106
|
-
}
|
107
|
-
|
108
|
-
return false;
|
109
|
-
}
|
110
|
-
|
111
|
-
return (_b = (_a = node.title).includes) === null || _b === void 0 ? void 0 : _b.call(_a, searchValue);
|
112
|
-
});
|
113
|
-
|
114
|
-
if (index.isArrayNonEmpty(matchedChildren)) {
|
115
|
-
var matchedOptionOrGroup = Object.assign(Object.assign({}, optionOrGroup), {
|
116
|
-
children: matchedChildren
|
117
|
-
});
|
118
|
-
matchedResult.push(matchedOptionOrGroup);
|
119
|
-
}
|
120
|
-
}
|
121
|
-
} else {
|
122
|
-
// search for Option
|
123
|
-
// @ts-ignore
|
124
|
-
var _shouldReserved = shouldFilter && filter(searchValue, optionOrGroup) === true;
|
125
|
-
|
126
|
-
if (_shouldReserved) {
|
127
|
-
matchedResult.push(optionOrGroup);
|
128
|
-
return "continue";
|
129
|
-
}
|
130
|
-
|
131
|
-
if (typeof optionOrGroup.title === 'string') {
|
132
|
-
// 匹配策略:`String.include`
|
133
|
-
if (optionOrGroup.title.includes(searchValue)) {
|
134
|
-
matchedResult.push(optionOrGroup);
|
135
|
-
}
|
136
|
-
} else {
|
137
|
-
if (env.__DEV__) {
|
138
|
-
console.info('WARNING: The `option.title` should be `string` when searchable is enabled.');
|
139
|
-
}
|
140
|
-
}
|
141
|
-
}
|
142
|
-
};
|
143
|
-
|
144
|
-
for (var i = 0; i < flattedData.length; i++) {
|
145
|
-
var _ret = _loop(i);
|
146
|
-
|
147
|
-
if (_ret === "continue") continue;
|
148
|
-
}
|
149
|
-
|
150
|
-
return matchedResult;
|
151
|
-
};
|
152
|
-
|
153
|
-
exports.useSearch = useSearch;
|
154
|
-
//# sourceMappingURL=use-search.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"use-search.js","sources":["../../../src/hooks/use-search.ts"],"sourcesContent":[null],"names":["useSearch","flattedData","filter","useState","searchValue","setSearchValue","matchedNodes","setMatchedNodes","flattedDataRef","useLatestRef","handleChange","useCallback","evt","nextSearchValue","target","value","getMatchedNodes","current","inputProps","useMemo","onChange","resetSearch","isSearch","isEmpty","length","matchedResult","shouldFilter","isFunction","i","optionOrGroup","shouldReserved","push","groupTitle","includes","__DEV__","console","info","isArrayNonEmpty","children","matchedChildren","node","title","matchedOptionOrG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Aa,CAACY,KAArB,KAA+B,UAAU;;YAEvCZ,aAAa,CAACY,KAAdZ,CAAoBI,QAApBJ,CAA6BzB,WAA7ByB,GAA2C;AAC7CJ,UAAAA,aAAa,CAACM,IAAdN,CAAmBI,aAAnBJ;;AAHJ,aAKO;YACDS,aAAS;AACXC,UAAAA,OAAO,CAACC,IAARD,CAAa,4EAAbA;;;;;;OArEH,IAAIP,CAAC,GAAG,GAAGA,CAAC,GAAG3B,WAAW,CAACuB,QAAQI,CAAC,IAAI;qBAApCA;;6BA2DH;;;SAgBCH;AAvFT,CAAA;;"}
|
@@ -1,42 +0,0 @@
|
|
1
|
-
/** @LICENSE
|
2
|
-
* @hi-ui/check-select
|
3
|
-
* https://github.com/XiaoMi/hiui/tree/master/packages/ui/check-select#readme
|
4
|
-
*
|
5
|
-
* Copyright (c) HIUI <mi-hiui@xiaomi.com>.
|
6
|
-
*
|
7
|
-
* This source code is licensed under the MIT license found in the
|
8
|
-
* LICENSE file in the root directory of this source tree.
|
9
|
-
*/
|
10
|
-
'use strict';
|
11
|
-
|
12
|
-
Object.defineProperty(exports, '__esModule', {
|
13
|
-
value: true
|
14
|
-
});
|
15
|
-
|
16
|
-
require('@babel/runtime/helpers/esm/typeof');
|
17
|
-
/**
|
18
|
-
* Assert is an array
|
19
|
-
*/
|
20
|
-
|
21
|
-
|
22
|
-
var isArray = Array.isArray;
|
23
|
-
/**
|
24
|
-
* Assert is an array and `array.length > 0`
|
25
|
-
*/
|
26
|
-
|
27
|
-
var isArrayNonEmpty = function isArrayNonEmpty(arg) {
|
28
|
-
return isArray(arg) && arg.length > 0;
|
29
|
-
};
|
30
|
-
/**
|
31
|
-
* Assert is function
|
32
|
-
*/
|
33
|
-
|
34
|
-
|
35
|
-
var isFunction = function isFunction(arg) {
|
36
|
-
return typeof arg === 'function';
|
37
|
-
};
|
38
|
-
|
39
|
-
exports.isArray = isArray;
|
40
|
-
exports.isArrayNonEmpty = isArrayNonEmpty;
|
41
|
-
exports.isFunction = isFunction;
|
42
|
-
//# sourceMappingURL=index.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../../../../../utils/type-assertion/lib/esm/index.js"],"sourcesContent":["import _typeof from \"@babel/runtime/helpers/esm/typeof\";\n\n/** @LICENSE\n * @hi-ui/type-assertion\n * https://github.com/XiaoMi/hiui/tree/master/packages/utils/type-assertion#readme\n *\n * Copyright (c) HIUI <mi-hiui@xiaomi.com>.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n/**\n * Assert is undefined\n */\nvar isUndefined = function isUndefined(arg) {\n return arg === undefined;\n};\n/**\n * Assert is Nullish\n */\n\n\nvar isNullish = function isNullish(arg) {\n return arg === null || arg === undefined;\n};\n/**\n * Assert is an objectLike\n * TODO: Assert the return type\n */\n\n\nvar isObjectLike = function isObjectLike(arg) {\n return !!arg && _typeof(arg) === 'object';\n};\n/**\n * Assert is an object\n */\n\n\nvar isObject = function isObject(arg) {\n return isObjectLike(arg) && arg.constructor === Object;\n};\n/**\n * Assert is a dom element\n */\n\n\nvar isElement = function isElement(arg) {\n return isObjectLike(arg) && arg.constructor !== Object && arg.nodeType === 1;\n};\n/**\n * Assert is an Promise\n */\n\n\nvar isPromise = function isPromise(arg) {\n return (isObjectLike(arg) || typeof arg === 'function') && typeof arg.then === 'function';\n};\n/**\n * Assert is an array\n */\n\n\nvar isArray = Array.isArray;\n/**\n * Assert is an array and `array.length > 0`\n */\n\nvar isArrayNonEmpty = function isArrayNonEmpty(arg) {\n return isArray(arg) && arg.length > 0;\n};\n/**\n * Assert is numeric\n */\n\n\nvar isNumeric = function isNumeric(arg) {\n return !Number.isNaN(Number(arg));\n};\n/**\n * Assert is function\n */\n\n\nvar isFunction = function isFunction(arg) {\n return typeof arg === 'function';\n};\n\nvar toString = Object.prototype.toString;\n/**\n * Assert is string\n */\n\nvar isString = function isString(arg) {\n return toString.call(arg) === '[object String]';\n};\n\nexport { isArray, isArrayNonEmpty, isElement, isFunction, isNullish, isNumeric, isObject, isPromise, isString, isUndefined };\n//# sourceMappingURL=index.js.map\n"],"names":["isArray","Array","isArrayNonEmpty","arg","isFunction"],"mappings":";;;;;;;;;;;;;;;;AAuCA;;;;;IAGaA,OAAO,GAAoCC,KAAK,CAACD;AAE9D;;;;IAGaE,eAAe,GAAG,SAAlBA,eAAkB,CAAAC,GAAA,EAAA;SAAiCH,OAAO,CAAPA,GAAO,CAAPA,IAAgBG,GAAG,CAAHA,MAAAA,GAAa;;AAO7F;;;;;IAGaC,UAAU,GAAG,SAAbA,UAAa,CAAAD,GAAA,EAAA;SACxB,OAAAA,GAAA,KAAe;;;;;"}
|
@@ -1,144 +0,0 @@
|
|
1
|
-
/** @LICENSE
|
2
|
-
* @hi-ui/check-select
|
3
|
-
* https://github.com/XiaoMi/hiui/tree/master/packages/ui/check-select#readme
|
4
|
-
*
|
5
|
-
* Copyright (c) HIUI <mi-hiui@xiaomi.com>.
|
6
|
-
*
|
7
|
-
* This source code is licensed under the MIT license found in the
|
8
|
-
* LICENSE file in the root directory of this source tree.
|
9
|
-
*/
|
10
|
-
import { useState, useCallback, useMemo } from 'react';
|
11
|
-
import { useLatestRef } from '@hi-ui/use-latest';
|
12
|
-
import { __DEV__ } from '@hi-ui/env';
|
13
|
-
import { isArrayNonEmpty, isFunction } from '../utils/type-assertion/lib/esm/index.js';
|
14
|
-
/**
|
15
|
-
* 支持搜索功能的 hook
|
16
|
-
*/
|
17
|
-
|
18
|
-
var useSearch = function useSearch(flattedData, filter) {
|
19
|
-
var _useState = useState(''),
|
20
|
-
searchValue = _useState[0],
|
21
|
-
setSearchValue = _useState[1];
|
22
|
-
|
23
|
-
var _useState2 = useState([]),
|
24
|
-
matchedNodes = _useState2[0],
|
25
|
-
setMatchedNodes = _useState2[1];
|
26
|
-
|
27
|
-
var flattedDataRef = useLatestRef(flattedData);
|
28
|
-
var handleChange = useCallback(function (evt) {
|
29
|
-
var nextSearchValue = evt.target.value;
|
30
|
-
setSearchValue(nextSearchValue); // 匹配到搜索的节点,将这些节点进行展开显示,其它均隐藏
|
31
|
-
|
32
|
-
var matchedNodes = getMatchedNodes(flattedDataRef.current, nextSearchValue, filter);
|
33
|
-
setMatchedNodes(matchedNodes);
|
34
|
-
}, [flattedDataRef, filter]);
|
35
|
-
var inputProps = useMemo(function () {
|
36
|
-
return {
|
37
|
-
value: searchValue,
|
38
|
-
onChange: handleChange
|
39
|
-
};
|
40
|
-
}, [searchValue, handleChange]);
|
41
|
-
var resetSearch = useCallback(function () {
|
42
|
-
setSearchValue('');
|
43
|
-
}, []);
|
44
|
-
var isSearch = !!searchValue;
|
45
|
-
var isEmpty = isSearch && matchedNodes.length === 0;
|
46
|
-
return [isSearch, matchedNodes, inputProps, isEmpty, resetSearch];
|
47
|
-
};
|
48
|
-
/**
|
49
|
-
* 从 value 中 找到指定的 options(逐层查找)
|
50
|
-
*/
|
51
|
-
|
52
|
-
|
53
|
-
var getMatchedNodes = function getMatchedNodes(flattedData, searchValue, filter) {
|
54
|
-
if (!searchValue) return [];
|
55
|
-
var matchedResult = [];
|
56
|
-
var shouldFilter = isFunction(filter); // 1. 先对于 groupTitle 匹配
|
57
|
-
// 2. 若未匹配到。再对其 children 进行 title 匹配
|
58
|
-
|
59
|
-
var _loop = function _loop(i) {
|
60
|
-
var optionOrGroup = flattedData[i];
|
61
|
-
|
62
|
-
if ('groupTitle' in optionOrGroup) {
|
63
|
-
// search for OptionGroup
|
64
|
-
// @ts-ignore
|
65
|
-
var shouldReserved = shouldFilter && filter(searchValue, optionOrGroup) === true;
|
66
|
-
|
67
|
-
if (shouldReserved) {
|
68
|
-
matchedResult.push(optionOrGroup);
|
69
|
-
return "continue";
|
70
|
-
}
|
71
|
-
|
72
|
-
if (typeof optionOrGroup.groupTitle === 'string') {
|
73
|
-
// 匹配策略:`String.include`
|
74
|
-
if (optionOrGroup.groupTitle.includes(searchValue)) {
|
75
|
-
matchedResult.push(optionOrGroup);
|
76
|
-
return "continue";
|
77
|
-
}
|
78
|
-
} else {
|
79
|
-
if (__DEV__) {
|
80
|
-
console.info('WARNING: The `optionGroup.groupTitle` should be `string` when searchable is enabled.');
|
81
|
-
}
|
82
|
-
}
|
83
|
-
|
84
|
-
if (isArrayNonEmpty(optionOrGroup.children)) {
|
85
|
-
var matchedChildren = optionOrGroup.children.filter(function (node) {
|
86
|
-
var _a, _b;
|
87
|
-
|
88
|
-
if (shouldFilter) {
|
89
|
-
// @ts-ignore
|
90
|
-
return filter(searchValue, optionOrGroup);
|
91
|
-
}
|
92
|
-
|
93
|
-
if (typeof node.title !== 'string') {
|
94
|
-
if (__DEV__) {
|
95
|
-
console.info('WARNING: The `option.title` should be `string` when searchable is enabled.');
|
96
|
-
}
|
97
|
-
|
98
|
-
return false;
|
99
|
-
}
|
100
|
-
|
101
|
-
return (_b = (_a = node.title).includes) === null || _b === void 0 ? void 0 : _b.call(_a, searchValue);
|
102
|
-
});
|
103
|
-
|
104
|
-
if (isArrayNonEmpty(matchedChildren)) {
|
105
|
-
var matchedOptionOrGroup = Object.assign(Object.assign({}, optionOrGroup), {
|
106
|
-
children: matchedChildren
|
107
|
-
});
|
108
|
-
matchedResult.push(matchedOptionOrGroup);
|
109
|
-
}
|
110
|
-
}
|
111
|
-
} else {
|
112
|
-
// search for Option
|
113
|
-
// @ts-ignore
|
114
|
-
var _shouldReserved = shouldFilter && filter(searchValue, optionOrGroup) === true;
|
115
|
-
|
116
|
-
if (_shouldReserved) {
|
117
|
-
matchedResult.push(optionOrGroup);
|
118
|
-
return "continue";
|
119
|
-
}
|
120
|
-
|
121
|
-
if (typeof optionOrGroup.title === 'string') {
|
122
|
-
// 匹配策略:`String.include`
|
123
|
-
if (optionOrGroup.title.includes(searchValue)) {
|
124
|
-
matchedResult.push(optionOrGroup);
|
125
|
-
}
|
126
|
-
} else {
|
127
|
-
if (__DEV__) {
|
128
|
-
console.info('WARNING: The `option.title` should be `string` when searchable is enabled.');
|
129
|
-
}
|
130
|
-
}
|
131
|
-
}
|
132
|
-
};
|
133
|
-
|
134
|
-
for (var i = 0; i < flattedData.length; i++) {
|
135
|
-
var _ret = _loop(i);
|
136
|
-
|
137
|
-
if (_ret === "continue") continue;
|
138
|
-
}
|
139
|
-
|
140
|
-
return matchedResult;
|
141
|
-
};
|
142
|
-
|
143
|
-
export { useSearch };
|
144
|
-
//# sourceMappingURL=use-search.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"use-search.js","sources":["../../../src/hooks/use-search.ts"],"sourcesContent":[null],"names":["useSearch","flattedData","filter","useState","searchValue","setSearchValue","matchedNodes","setMatchedNodes","flattedDataRef","useLatestRef","handleChange","useCallback","evt","nextSearchValue","target","value","getMatchedNodes","current","inputProps","useMemo","onChange","resetSearch","isSearch","isEmpty","length","matchedResult","shouldFilter","isFunction","i","optionOrGroup","shouldReserved","push","groupTitle","includes","__DEV__","console","info","isArrayNonEmpty","children","matchedChildren","node","title","matchedOptionOrGroup"],"mappings":";;;;;;;;;;;;;AAMA;;;;IAGaA,SAAS,GAAG,SAAZA,SAAY,CACvBC,WADuB,EAEvBC,MAFuB;kBAIeC,QAAQ,CAAC,EAAD;MAAvCC,WAAP;MAAoBC,cAApB;;mBACwCF,QAAQ,CAAuC,EAAvC;MAAzCG,YAAP;MAAqBC,eAArB;;MAEMC,cAAc,GAAGC,YAAY,CAACR,WAAD;MAE7BS,YAAY,GAAGC,WAAW,CAC9B,UAACC,GAAD;QACQC,eAAe,GAAGD,GAAG,CAACE,MAAJF,CAAWG;AAEnCV,IAAAA,cAAc,CAACQ,eAAD,CAAdR;;QAGMC,YAAY,GAAGU,eAAe,CAACR,cAAc,CAACS,OAAhB,EAAyBJ,eAAzB,EAA0CX,MAA1C;AACpCK,IAAAA,eAAe,CAACD,YAAD,CAAfC;AAR4B,GAAA,EAU9B,CAACC,cAAD,EAAiBN,MAAjB,CAV8B;MAa1BgB,UAAU,GAAGC,OAAO,CACxB;WAAO;AACLJ,MAAAA,KAAK,EAAEX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GX,OAAOW,IAAI,CAACC,KAAZ,KAAsB,UAAU;gBAC9BP,SAAS;AACXC,cAAAA,OAAO,CAACC,IAARD,CACE,4EADFA;;;mBAIK;;;iBAGF,MAAA,MAAAK,IAAI,CAACC,KAAL,EAAWR,QAAX,UAAA,iBAAA,SAAA,eAAsB7B;AAfP,SAAAyB;;YAkBpBQ,eAAe,CAACE,eAAD,GAAmB;cAC9BG,oBAAoB,mCAAQb;AAAeS,YAAAA,QAAQ,EAAEC;;AAC3Dd,UAAAA,aAAa,CAACM,IAAdN,CAAmBiB,oBAAnBjB;;;AA9CN,WAiDO;;;UAGCK,eAAc,GAAGJ,YAAY,IAAIxB,MAAM,CAACE,WAAD,EAAcyB,aAAd,CAAN3B,KAAuC;;UAE1E4B,iBAAgB;AAClBL,QAAAA,aAAa,CAACM,IAAdN,CAAmBI,aAAnBJ;;;;UAIE,OAAOI,aAAa,CAACY,KAArB,KAA+B,UAAU;;YAEvCZ,aAAa,CAACY,KAAdZ,CAAoBI,QAApBJ,CAA6BzB,WAA7ByB,GAA2C;AAC7CJ,UAAAA,aAAa,CAACM,IAAdN,CAAmBI,aAAnBJ;;AAHJ,aAKO;YACDS,SAAS;AACXC,UAAAA,OAAO,CAACC,IAARD,CAAa,4EAAbA;;;;;;OArEH,IAAIP,CAAC,GAAG,GAAGA,CAAC,GAAG3B,WAAW,CAACuB,QAAQI,CAAC,IAAI;qBAApCA;;6BA2DH;;;SAgBCH;AAvFT,CAAA;;"}
|
@@ -1,33 +0,0 @@
|
|
1
|
-
/** @LICENSE
|
2
|
-
* @hi-ui/check-select
|
3
|
-
* https://github.com/XiaoMi/hiui/tree/master/packages/ui/check-select#readme
|
4
|
-
*
|
5
|
-
* Copyright (c) HIUI <mi-hiui@xiaomi.com>.
|
6
|
-
*
|
7
|
-
* This source code is licensed under the MIT license found in the
|
8
|
-
* LICENSE file in the root directory of this source tree.
|
9
|
-
*/
|
10
|
-
import '@babel/runtime/helpers/esm/typeof';
|
11
|
-
/**
|
12
|
-
* Assert is an array
|
13
|
-
*/
|
14
|
-
|
15
|
-
var isArray = Array.isArray;
|
16
|
-
/**
|
17
|
-
* Assert is an array and `array.length > 0`
|
18
|
-
*/
|
19
|
-
|
20
|
-
var isArrayNonEmpty = function isArrayNonEmpty(arg) {
|
21
|
-
return isArray(arg) && arg.length > 0;
|
22
|
-
};
|
23
|
-
/**
|
24
|
-
* Assert is function
|
25
|
-
*/
|
26
|
-
|
27
|
-
|
28
|
-
var isFunction = function isFunction(arg) {
|
29
|
-
return typeof arg === 'function';
|
30
|
-
};
|
31
|
-
|
32
|
-
export { isArray, isArrayNonEmpty, isFunction };
|
33
|
-
//# sourceMappingURL=index.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../../../../../utils/type-assertion/lib/esm/index.js"],"sourcesContent":["import _typeof from \"@babel/runtime/helpers/esm/typeof\";\n\n/** @LICENSE\n * @hi-ui/type-assertion\n * https://github.com/XiaoMi/hiui/tree/master/packages/utils/type-assertion#readme\n *\n * Copyright (c) HIUI <mi-hiui@xiaomi.com>.\n *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n */\n\n/**\n * Assert is undefined\n */\nvar isUndefined = function isUndefined(arg) {\n return arg === undefined;\n};\n/**\n * Assert is Nullish\n */\n\n\nvar isNullish = function isNullish(arg) {\n return arg === null || arg === undefined;\n};\n/**\n * Assert is an objectLike\n * TODO: Assert the return type\n */\n\n\nvar isObjectLike = function isObjectLike(arg) {\n return !!arg && _typeof(arg) === 'object';\n};\n/**\n * Assert is an object\n */\n\n\nvar isObject = function isObject(arg) {\n return isObjectLike(arg) && arg.constructor === Object;\n};\n/**\n * Assert is a dom element\n */\n\n\nvar isElement = function isElement(arg) {\n return isObjectLike(arg) && arg.constructor !== Object && arg.nodeType === 1;\n};\n/**\n * Assert is an Promise\n */\n\n\nvar isPromise = function isPromise(arg) {\n return (isObjectLike(arg) || typeof arg === 'function') && typeof arg.then === 'function';\n};\n/**\n * Assert is an array\n */\n\n\nvar isArray = Array.isArray;\n/**\n * Assert is an array and `array.length > 0`\n */\n\nvar isArrayNonEmpty = function isArrayNonEmpty(arg) {\n return isArray(arg) && arg.length > 0;\n};\n/**\n * Assert is numeric\n */\n\n\nvar isNumeric = function isNumeric(arg) {\n return !Number.isNaN(Number(arg));\n};\n/**\n * Assert is function\n */\n\n\nvar isFunction = function isFunction(arg) {\n return typeof arg === 'function';\n};\n\nvar toString = Object.prototype.toString;\n/**\n * Assert is string\n */\n\nvar isString = function isString(arg) {\n return toString.call(arg) === '[object String]';\n};\n\nexport { isArray, isArrayNonEmpty, isElement, isFunction, isNullish, isNumeric, isObject, isPromise, isString, isUndefined };\n//# sourceMappingURL=index.js.map\n"],"names":["isArray","Array","isArrayNonEmpty","arg","isFunction"],"mappings":";;;;;;;;;;AAuCA;;;;IAGaA,OAAO,GAAoCC,KAAK,CAACD;AAE9D;;;;IAGaE,eAAe,GAAG,SAAlBA,eAAkB,CAAAC,GAAA,EAAA;SAAiCH,OAAO,CAAPA,GAAO,CAAPA,IAAgBG,GAAG,CAAHA,MAAAA,GAAa;;AAO7F;;;;;IAGaC,UAAU,GAAG,SAAbA,UAAa,CAAAD,GAAA,EAAA;SACxB,OAAAA,GAAA,KAAe;;;"}
|