@hi-ui/check-select 4.0.0-beta.46 → 4.0.0-beta.49
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 +26 -39
- package/lib/cjs/utils/index.js +52 -0
- package/lib/esm/CheckSelect.js +25 -38
- package/lib/esm/utils/index.js +45 -0
- package/lib/types/CheckSelect.d.ts +1 -1
- package/lib/types/utils/index.d.ts +10 -0
- package/package.json +4 -4
package/lib/cjs/CheckSelect.js
CHANGED
@@ -47,8 +47,6 @@ var highlighter = require('@hi-ui/highlighter');
|
|
47
47
|
|
48
48
|
var useToggle = require('@hi-ui/use-toggle');
|
49
49
|
|
50
|
-
var times = require('@hi-ui/times');
|
51
|
-
|
52
50
|
var funcUtils = require('@hi-ui/func-utils');
|
53
51
|
|
54
52
|
var localeContext = require('@hi-ui/locale-context');
|
@@ -59,6 +57,8 @@ require('@hi-ui/use-children');
|
|
59
57
|
|
60
58
|
var useFlattenData = require('./hooks/use-flatten-data.js');
|
61
59
|
|
60
|
+
var index = require('./utils/index.js');
|
61
|
+
|
62
62
|
function _interopDefaultLegacy(e) {
|
63
63
|
return e && _typeof(e) === 'object' && 'default' in e ? e : {
|
64
64
|
'default': e
|
@@ -219,48 +219,37 @@ var CheckSelect = /*#__PURE__*/React.forwardRef(function (_a, ref) {
|
|
219
219
|
var activeExpandable = showOnlyShowChecked && !!filterItems && menuVisible;
|
220
220
|
|
221
221
|
var _useMemo = React.useMemo(function () {
|
222
|
-
|
223
|
-
return !('groupTitle' in item);
|
224
|
-
}).map(function (_ref) {
|
225
|
-
var id = _ref.id;
|
226
|
-
return id;
|
227
|
-
});
|
228
|
-
var dropdownIdsSet = new Set(dropdownIds);
|
229
|
-
var hasValue = false;
|
230
|
-
value.forEach(function (id) {
|
231
|
-
if (dropdownIdsSet.has(id)) {
|
232
|
-
hasValue = true;
|
233
|
-
dropdownIdsSet["delete"](id);
|
234
|
-
}
|
235
|
-
});
|
236
|
-
return [hasValue && dropdownIdsSet.size === 0, hasValue && dropdownIdsSet.size > 0];
|
222
|
+
return index.getAllCheckedStatus(dropdownItems, value, index.isOption);
|
237
223
|
}, [dropdownItems, value]),
|
238
|
-
|
239
|
-
|
224
|
+
showAllChecked = _useMemo[0],
|
225
|
+
showIndeterminate = _useMemo[1];
|
240
226
|
|
241
227
|
var valueLatestRef = useLatest.useLatestRef(value);
|
242
|
-
var toggleCheckAll = React.useCallback(function (
|
243
|
-
var value = valueLatestRef.current;
|
228
|
+
var toggleCheckAll = React.useCallback(function () {
|
229
|
+
var value = valueLatestRef.current;
|
244
230
|
|
245
|
-
var
|
246
|
-
|
247
|
-
|
248
|
-
var
|
249
|
-
|
231
|
+
var _getAllCheckedStatus = index.getAllCheckedStatus(dropdownItems, value, index.isCheckableOption),
|
232
|
+
currentAllChecked = _getAllCheckedStatus[0];
|
233
|
+
|
234
|
+
var shouldChecked = !currentAllChecked; // 当前页的数据选项
|
235
|
+
|
236
|
+
var items = dropdownItems.filter(index.isCheckableOption);
|
237
|
+
var targetIds = items.map(function (_ref) {
|
238
|
+
var id = _ref.id;
|
250
239
|
return id;
|
251
240
|
});
|
252
241
|
var allData = arrayUtils.uniqBy(items.concat(mergedData), 'id');
|
253
242
|
|
254
|
-
if (
|
243
|
+
if (shouldChecked) {
|
255
244
|
var nextCheckedIds = Array.from(new Set(value.concat(targetIds)));
|
256
245
|
var changedIds = nextCheckedIds.filter(function (id) {
|
257
246
|
return !value.includes(id);
|
258
247
|
});
|
259
|
-
var changedItems = allData.filter(function (
|
260
|
-
var id =
|
248
|
+
var changedItems = allData.filter(function (_ref2) {
|
249
|
+
var id = _ref2.id;
|
261
250
|
return changedIds.includes(id);
|
262
251
|
});
|
263
|
-
tryChangeValue(nextCheckedIds, changedItems,
|
252
|
+
tryChangeValue(nextCheckedIds, changedItems, shouldChecked);
|
264
253
|
} else {
|
265
254
|
var _nextCheckedIds = value.filter(function (id) {
|
266
255
|
return !targetIds.includes(id);
|
@@ -270,13 +259,13 @@ var CheckSelect = /*#__PURE__*/React.forwardRef(function (_a, ref) {
|
|
270
259
|
return !_nextCheckedIds.includes(id);
|
271
260
|
});
|
272
261
|
|
273
|
-
var _changedItems = allData.filter(function (
|
274
|
-
var id =
|
262
|
+
var _changedItems = allData.filter(function (_ref3) {
|
263
|
+
var id = _ref3.id;
|
275
264
|
return _changedIds.includes(id);
|
276
265
|
}); // items
|
277
266
|
|
278
267
|
|
279
|
-
tryChangeValue(_nextCheckedIds, _changedItems,
|
268
|
+
tryChangeValue(_nextCheckedIds, _changedItems, shouldChecked);
|
280
269
|
}
|
281
270
|
}, [dropdownItems, mergedData, valueLatestRef, tryChangeValue]);
|
282
271
|
|
@@ -285,11 +274,9 @@ var CheckSelect = /*#__PURE__*/React.forwardRef(function (_a, ref) {
|
|
285
274
|
|
286
275
|
if (showCheckAll) {
|
287
276
|
return /*#__PURE__*/React__default["default"].createElement(React__default["default"].Fragment, null, /*#__PURE__*/React__default["default"].createElement(Checkbox__default["default"], {
|
288
|
-
indeterminate:
|
289
|
-
checked:
|
290
|
-
onChange:
|
291
|
-
toggleCheckAll(evt.target.checked);
|
292
|
-
}
|
277
|
+
indeterminate: showIndeterminate,
|
278
|
+
checked: showAllChecked,
|
279
|
+
onChange: toggleCheckAll
|
293
280
|
}, i18n.get('checkSelect.checkAll')), extra);
|
294
281
|
}
|
295
282
|
|
@@ -489,7 +476,7 @@ if (env.__DEV__) {
|
|
489
476
|
|
490
477
|
|
491
478
|
var renderIndent = function renderIndent(prefixCls, depth) {
|
492
|
-
return
|
479
|
+
return arrayUtils.times(depth, function (index) {
|
493
480
|
return /*#__PURE__*/React__default["default"].createElement("span", {
|
494
481
|
key: index,
|
495
482
|
style: {
|
@@ -0,0 +1,52 @@
|
|
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
|
+
* 判断选项是否进行可选操作
|
17
|
+
*/
|
18
|
+
|
19
|
+
var isCheckableOption = function isCheckableOption(item) {
|
20
|
+
if ('groupTitle' in item) return false;
|
21
|
+
if (item.disabled) return false;
|
22
|
+
return true;
|
23
|
+
};
|
24
|
+
/**
|
25
|
+
* 判断选项为
|
26
|
+
*/
|
27
|
+
|
28
|
+
|
29
|
+
var isOption = function isOption(item) {
|
30
|
+
if ('groupTitle' in item) return false;
|
31
|
+
return true;
|
32
|
+
};
|
33
|
+
|
34
|
+
var getAllCheckedStatus = function getAllCheckedStatus(dropdownItems, values, filterFunc) {
|
35
|
+
var dropdownIds = dropdownItems.filter(filterFunc).map(function (_ref) {
|
36
|
+
var id = _ref.id;
|
37
|
+
return id;
|
38
|
+
});
|
39
|
+
var dropdownIdsSet = new Set(dropdownIds);
|
40
|
+
var hasValue = false;
|
41
|
+
values.forEach(function (id) {
|
42
|
+
if (dropdownIdsSet.has(id)) {
|
43
|
+
hasValue = true;
|
44
|
+
dropdownIdsSet["delete"](id);
|
45
|
+
}
|
46
|
+
});
|
47
|
+
return [hasValue && dropdownIdsSet.size === 0, hasValue && dropdownIdsSet.size > 0];
|
48
|
+
};
|
49
|
+
|
50
|
+
exports.getAllCheckedStatus = getAllCheckedStatus;
|
51
|
+
exports.isCheckableOption = isCheckableOption;
|
52
|
+
exports.isOption = isOption;
|
package/lib/esm/CheckSelect.js
CHANGED
@@ -20,15 +20,15 @@ import { TagInputMock } from '@hi-ui/tag-input';
|
|
20
20
|
import { isUndef, isFunction, isArrayNonEmpty } from '@hi-ui/type-assertion';
|
21
21
|
import VirtualList, { useCheckInVirtual } from '@hi-ui/virtual-list';
|
22
22
|
import { Picker } from '@hi-ui/picker';
|
23
|
-
import { uniqBy } from '@hi-ui/array-utils';
|
23
|
+
import { uniqBy, times } from '@hi-ui/array-utils';
|
24
24
|
import { Highlighter } from '@hi-ui/highlighter';
|
25
25
|
import { useUncontrolledToggle } from '@hi-ui/use-toggle';
|
26
|
-
import { times } from '@hi-ui/times';
|
27
26
|
import { callAllFuncs } from '@hi-ui/func-utils';
|
28
27
|
import { useLocaleContext } from '@hi-ui/locale-context';
|
29
28
|
import { useAsyncSearch, useTreeCustomSearch, useFilterSearch, useSearchMode } from '@hi-ui/use-search-mode';
|
30
29
|
import '@hi-ui/use-children';
|
31
30
|
import { flattenData } from './hooks/use-flatten-data.js';
|
31
|
+
import { getAllCheckedStatus, isCheckableOption, isOption } from './utils/index.js';
|
32
32
|
var _role = 'check-select';
|
33
33
|
|
34
34
|
var _prefix = getPrefixCls(_role);
|
@@ -177,48 +177,37 @@ var CheckSelect = /*#__PURE__*/forwardRef(function (_a, ref) {
|
|
177
177
|
var activeExpandable = showOnlyShowChecked && !!filterItems && menuVisible;
|
178
178
|
|
179
179
|
var _useMemo = useMemo(function () {
|
180
|
-
|
181
|
-
return !('groupTitle' in item);
|
182
|
-
}).map(function (_ref) {
|
183
|
-
var id = _ref.id;
|
184
|
-
return id;
|
185
|
-
});
|
186
|
-
var dropdownIdsSet = new Set(dropdownIds);
|
187
|
-
var hasValue = false;
|
188
|
-
value.forEach(function (id) {
|
189
|
-
if (dropdownIdsSet.has(id)) {
|
190
|
-
hasValue = true;
|
191
|
-
dropdownIdsSet["delete"](id);
|
192
|
-
}
|
193
|
-
});
|
194
|
-
return [hasValue && dropdownIdsSet.size === 0, hasValue && dropdownIdsSet.size > 0];
|
180
|
+
return getAllCheckedStatus(dropdownItems, value, isOption);
|
195
181
|
}, [dropdownItems, value]),
|
196
|
-
|
197
|
-
|
182
|
+
showAllChecked = _useMemo[0],
|
183
|
+
showIndeterminate = _useMemo[1];
|
198
184
|
|
199
185
|
var valueLatestRef = useLatestRef(value);
|
200
|
-
var toggleCheckAll = useCallback(function (
|
201
|
-
var value = valueLatestRef.current;
|
186
|
+
var toggleCheckAll = useCallback(function () {
|
187
|
+
var value = valueLatestRef.current;
|
202
188
|
|
203
|
-
var
|
204
|
-
|
205
|
-
|
206
|
-
var
|
207
|
-
|
189
|
+
var _getAllCheckedStatus = getAllCheckedStatus(dropdownItems, value, isCheckableOption),
|
190
|
+
currentAllChecked = _getAllCheckedStatus[0];
|
191
|
+
|
192
|
+
var shouldChecked = !currentAllChecked; // 当前页的数据选项
|
193
|
+
|
194
|
+
var items = dropdownItems.filter(isCheckableOption);
|
195
|
+
var targetIds = items.map(function (_ref) {
|
196
|
+
var id = _ref.id;
|
208
197
|
return id;
|
209
198
|
});
|
210
199
|
var allData = uniqBy(items.concat(mergedData), 'id');
|
211
200
|
|
212
|
-
if (
|
201
|
+
if (shouldChecked) {
|
213
202
|
var nextCheckedIds = Array.from(new Set(value.concat(targetIds)));
|
214
203
|
var changedIds = nextCheckedIds.filter(function (id) {
|
215
204
|
return !value.includes(id);
|
216
205
|
});
|
217
|
-
var changedItems = allData.filter(function (
|
218
|
-
var id =
|
206
|
+
var changedItems = allData.filter(function (_ref2) {
|
207
|
+
var id = _ref2.id;
|
219
208
|
return changedIds.includes(id);
|
220
209
|
});
|
221
|
-
tryChangeValue(nextCheckedIds, changedItems,
|
210
|
+
tryChangeValue(nextCheckedIds, changedItems, shouldChecked);
|
222
211
|
} else {
|
223
212
|
var _nextCheckedIds = value.filter(function (id) {
|
224
213
|
return !targetIds.includes(id);
|
@@ -228,13 +217,13 @@ var CheckSelect = /*#__PURE__*/forwardRef(function (_a, ref) {
|
|
228
217
|
return !_nextCheckedIds.includes(id);
|
229
218
|
});
|
230
219
|
|
231
|
-
var _changedItems = allData.filter(function (
|
232
|
-
var id =
|
220
|
+
var _changedItems = allData.filter(function (_ref3) {
|
221
|
+
var id = _ref3.id;
|
233
222
|
return _changedIds.includes(id);
|
234
223
|
}); // items
|
235
224
|
|
236
225
|
|
237
|
-
tryChangeValue(_nextCheckedIds, _changedItems,
|
226
|
+
tryChangeValue(_nextCheckedIds, _changedItems, shouldChecked);
|
238
227
|
}
|
239
228
|
}, [dropdownItems, mergedData, valueLatestRef, tryChangeValue]);
|
240
229
|
|
@@ -243,11 +232,9 @@ var CheckSelect = /*#__PURE__*/forwardRef(function (_a, ref) {
|
|
243
232
|
|
244
233
|
if (showCheckAll) {
|
245
234
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Checkbox, {
|
246
|
-
indeterminate:
|
247
|
-
checked:
|
248
|
-
onChange:
|
249
|
-
toggleCheckAll(evt.target.checked);
|
250
|
-
}
|
235
|
+
indeterminate: showIndeterminate,
|
236
|
+
checked: showAllChecked,
|
237
|
+
onChange: toggleCheckAll
|
251
238
|
}, i18n.get('checkSelect.checkAll')), extra);
|
252
239
|
}
|
253
240
|
|
@@ -0,0 +1,45 @@
|
|
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
|
+
|
11
|
+
/**
|
12
|
+
* 判断选项是否进行可选操作
|
13
|
+
*/
|
14
|
+
var isCheckableOption = function isCheckableOption(item) {
|
15
|
+
if ('groupTitle' in item) return false;
|
16
|
+
if (item.disabled) return false;
|
17
|
+
return true;
|
18
|
+
};
|
19
|
+
/**
|
20
|
+
* 判断选项为
|
21
|
+
*/
|
22
|
+
|
23
|
+
|
24
|
+
var isOption = function isOption(item) {
|
25
|
+
if ('groupTitle' in item) return false;
|
26
|
+
return true;
|
27
|
+
};
|
28
|
+
|
29
|
+
var getAllCheckedStatus = function getAllCheckedStatus(dropdownItems, values, filterFunc) {
|
30
|
+
var dropdownIds = dropdownItems.filter(filterFunc).map(function (_ref) {
|
31
|
+
var id = _ref.id;
|
32
|
+
return id;
|
33
|
+
});
|
34
|
+
var dropdownIdsSet = new Set(dropdownIds);
|
35
|
+
var hasValue = false;
|
36
|
+
values.forEach(function (id) {
|
37
|
+
if (dropdownIdsSet.has(id)) {
|
38
|
+
hasValue = true;
|
39
|
+
dropdownIdsSet["delete"](id);
|
40
|
+
}
|
41
|
+
});
|
42
|
+
return [hasValue && dropdownIdsSet.size === 0, hasValue && dropdownIdsSet.size > 0];
|
43
|
+
};
|
44
|
+
|
45
|
+
export { getAllCheckedStatus, isCheckableOption, isOption };
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import React from 'react';
|
2
|
+
/**
|
3
|
+
* 判断选项是否进行可选操作
|
4
|
+
*/
|
5
|
+
export declare const isCheckableOption: (item: any) => boolean;
|
6
|
+
/**
|
7
|
+
* 判断选项为
|
8
|
+
*/
|
9
|
+
export declare const isOption: (item: any) => boolean;
|
10
|
+
export declare const getAllCheckedStatus: (dropdownItems: any[], values: React.ReactText[], filterFunc: (item: any) => boolean) => boolean[];
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@hi-ui/check-select",
|
3
|
-
"version": "4.0.0-beta.
|
3
|
+
"version": "4.0.0-beta.49",
|
4
4
|
"description": "A sub-package for @hi-ui/hiui.",
|
5
5
|
"keywords": [],
|
6
6
|
"author": "HIUI <mi-hiui@xiaomi.com>",
|
@@ -54,7 +54,7 @@
|
|
54
54
|
"@hi-ui/icons": "^4.0.0-beta.14",
|
55
55
|
"@hi-ui/input": "^4.0.0-beta.21",
|
56
56
|
"@hi-ui/locale-context": "^4.0.0-beta.19",
|
57
|
-
"@hi-ui/picker": "^4.0.0-beta.
|
57
|
+
"@hi-ui/picker": "^4.0.0-beta.36",
|
58
58
|
"@hi-ui/popper": "^4.0.0-beta.19",
|
59
59
|
"@hi-ui/tag-input": "^4.0.0-beta.23",
|
60
60
|
"@hi-ui/times": "^4.0.0-beta.6",
|
@@ -64,7 +64,7 @@
|
|
64
64
|
"@hi-ui/use-children": "^4.0.0-beta.5",
|
65
65
|
"@hi-ui/use-data-source": "^4.0.0-beta.6",
|
66
66
|
"@hi-ui/use-latest": "^4.0.0-beta.5",
|
67
|
-
"@hi-ui/use-search-mode": "^4.0.0-beta.
|
67
|
+
"@hi-ui/use-search-mode": "^4.0.0-beta.27",
|
68
68
|
"@hi-ui/use-toggle": "^4.0.0-beta.5",
|
69
69
|
"@hi-ui/use-uncontrolled-state": "^4.0.0-beta.5",
|
70
70
|
"@hi-ui/virtual-list": "^4.0.0-beta.1"
|
@@ -78,5 +78,5 @@
|
|
78
78
|
"react": "^17.0.1",
|
79
79
|
"react-dom": "^17.0.1"
|
80
80
|
},
|
81
|
-
"gitHead": "
|
81
|
+
"gitHead": "346438168b2b334e22d4de3f302f6d9bbddccfe8"
|
82
82
|
}
|