@mezzanine-ui/react 0.12.6 → 0.12.8
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.
|
@@ -12,7 +12,7 @@ import Icon from '../../Icon/Icon.js';
|
|
|
12
12
|
import cx from 'clsx';
|
|
13
13
|
|
|
14
14
|
const TableRowSelection = forwardRef(function TableRowSelection(props, ref) {
|
|
15
|
-
var _a;
|
|
15
|
+
var _a, _b;
|
|
16
16
|
const { rowKey, setChecked, showDropdownIcon, ...rest } = props;
|
|
17
17
|
const { rowSelection, expanding, } = useContext(TableContext) || {};
|
|
18
18
|
const { dataSource = [], } = useContext(TableDataContext) || {};
|
|
@@ -72,14 +72,14 @@ const TableRowSelection = forwardRef(function TableRowSelection(props, ref) {
|
|
|
72
72
|
const actionMenu = (jsx(Menu, { size: "medium", children: ((_a = rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.actions) !== null && _a !== void 0 ? _a : []).map(((action) => (jsx(MenuItem, { className: action.className, onClick: (evt) => onMenuItemClicked(evt, action), children: action.text }, action.key)))) }));
|
|
73
73
|
return (jsxs("div", { ref: ref, ...rest, className: tableClasses.selections, style: hiddenIconWithExpandableStyle.host, children: [jsx(Checkbox, { checked: checked, disabled: false, indeterminate: indeterminate, inputProps: {
|
|
74
74
|
name,
|
|
75
|
-
}, onChange: onSelected, size: "medium" }), jsx("div", { className: tableClasses.icon, style: hiddenIconWithExpandableStyle.icon, children: showDropdownIcon ? (jsx(Dropdown, { menu: actionMenu, onClose: () => toggleOpen(false), popperProps: {
|
|
75
|
+
}, onChange: onSelected, size: "medium" }), ((_b = rowSelection === null || rowSelection === void 0 ? void 0 : rowSelection.actions) === null || _b === void 0 ? void 0 : _b.length) ? (jsx("div", { className: tableClasses.icon, style: hiddenIconWithExpandableStyle.icon, children: showDropdownIcon ? (jsx(Dropdown, { menu: actionMenu, onClose: () => toggleOpen(false), popperProps: {
|
|
76
76
|
open,
|
|
77
77
|
options: {
|
|
78
78
|
placement: 'bottom-start',
|
|
79
79
|
},
|
|
80
80
|
}, children: (dropdownRef) => (jsx(Icon, { ref: dropdownRef, className: cx(tableClasses.icon, {
|
|
81
81
|
[tableClasses.iconClickable]: isMenuAllowOpen,
|
|
82
|
-
}), color: isMenuAllowOpen ? 'primary' : 'disabled', icon: MoreVerticalIcon, onClick: onIconClicked })) })) : null })] }));
|
|
82
|
+
}), color: isMenuAllowOpen ? 'primary' : 'disabled', icon: MoreVerticalIcon, onClick: onIconClicked })) })) : null })) : null] }));
|
|
83
83
|
});
|
|
84
84
|
var TableRowSelection$1 = TableRowSelection;
|
|
85
85
|
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { useState, useCallback } from 'react';
|
|
1
|
+
import { useState, useEffect, useCallback } from 'react';
|
|
2
2
|
import isEqual from 'lodash/isEqual';
|
|
3
3
|
import get from 'lodash/get';
|
|
4
4
|
import { useControlValueState } from '../../Form/useControlValueState.js';
|
|
5
5
|
import { useLastCallback } from '../../hooks/useLastCallback.js';
|
|
6
|
+
import { usePreviousValue } from '../../hooks/usePreviousValue.js';
|
|
6
7
|
|
|
7
8
|
const sortSource = (prev, cur) => {
|
|
8
9
|
const prevKey = (prev.key || prev.id);
|
|
@@ -13,9 +14,17 @@ const sortSource = (prev, cur) => {
|
|
|
13
14
|
return 1;
|
|
14
15
|
return 0;
|
|
15
16
|
};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
/**
|
|
18
|
+
* @NOTE deepCompare = true 時,會深度比較 dataSource 順序是否有不同
|
|
19
|
+
* @NOTE deepCompare = false(預設),則是為了內部排序可以讓 useControlValueState 認為是一樣的 dataSource
|
|
20
|
+
* useControlValueState 會強制把 return value 和傳入的 value 做同步,當有不一樣時就會自動 sync
|
|
21
|
+
* 所以無論如何用 setDataSource 都不會有改變
|
|
22
|
+
*/
|
|
23
|
+
const equalityFn = (a, b, deepCompare = false) => {
|
|
24
|
+
const aTemp = a.slice(0);
|
|
25
|
+
const bTemp = b.slice(0);
|
|
26
|
+
const sortedA = deepCompare ? aTemp : aTemp.sort(sortSource);
|
|
27
|
+
const sortedB = deepCompare ? bTemp : bTemp.sort(sortSource);
|
|
19
28
|
const mappedAKeys = sortedA.map((s) => (s.key || s.id));
|
|
20
29
|
const mappedBKeys = sortedB.map((s) => (s.key || s.id));
|
|
21
30
|
const isShallowEqual = mappedAKeys.length === mappedBKeys.length &&
|
|
@@ -34,8 +43,19 @@ function useTableSorting(props) {
|
|
|
34
43
|
const [dataSource, setDataSource] = useControlValueState({
|
|
35
44
|
defaultValue: [],
|
|
36
45
|
equalityFn,
|
|
37
|
-
|
|
46
|
+
/** @NOTE 只有當 dataSource 傳入時,並且使用了 table 提供的 sorting,才需要完全同步 dataSource */
|
|
47
|
+
value: dataSourceProp.length && sortedOn ? dataSourceProp : undefined,
|
|
38
48
|
});
|
|
49
|
+
const prevDataSourceProps = usePreviousValue(dataSourceProp);
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
/**
|
|
52
|
+
* @NOTE 條件1: 如果一開始就有傳入值,則直接同步 dataSource
|
|
53
|
+
* @NOTE 條件2: 深度比較舊 dataSourceProp 跟新的是否有不同,如果有則同步
|
|
54
|
+
*/
|
|
55
|
+
if (!dataSource.length || !equalityFn(prevDataSourceProps, dataSourceProp, true)) {
|
|
56
|
+
setDataSource(dataSourceProp);
|
|
57
|
+
}
|
|
58
|
+
}, [prevDataSourceProps, dataSourceProp]);
|
|
39
59
|
const getNextSortedType = useCallback((currentType) => {
|
|
40
60
|
// none -> desc -> asc -> none
|
|
41
61
|
if (currentType === 'none')
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mezzanine-ui/react",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.8",
|
|
4
4
|
"description": "React components for mezzanine-ui",
|
|
5
5
|
"author": "Mezzanine",
|
|
6
6
|
"repository": {
|
|
@@ -31,9 +31,9 @@
|
|
|
31
31
|
"react-dom": "^18.2.0"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@mezzanine-ui/core": "^0.12.
|
|
35
|
-
"@mezzanine-ui/icons": "^0.12.
|
|
36
|
-
"@mezzanine-ui/system": "^0.12.
|
|
34
|
+
"@mezzanine-ui/core": "^0.12.8",
|
|
35
|
+
"@mezzanine-ui/icons": "^0.12.8",
|
|
36
|
+
"@mezzanine-ui/system": "^0.12.8",
|
|
37
37
|
"@popperjs/core": "^2.11.6",
|
|
38
38
|
"@types/react-transition-group": "^4.4.5",
|
|
39
39
|
"clsx": "^1.2.1",
|