doui-react 2.0.8 → 2.0.9
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/es/table/component/table.js +56 -62
- package/lib/table/component/table.js +55 -61
- package/package.json +1 -1
|
@@ -10,7 +10,7 @@ var _excluded = ["rowKey", "loading", "columns", "dataSource", "editorValueKey"]
|
|
|
10
10
|
import { executeFunction, getClassName, includesNonStrictMode } from "../../api";
|
|
11
11
|
import { Empty } from "../../empty";
|
|
12
12
|
import { Form, useFormContext } from "../../form";
|
|
13
|
-
import { useListOperation } from "../../hooks";
|
|
13
|
+
import { useListOperation, useMemoFn } from "../../hooks";
|
|
14
14
|
import { TableProvider, useSearchColumn } from "./..";
|
|
15
15
|
import { cx } from '@emotion/css';
|
|
16
16
|
import _ from 'lodash';
|
|
@@ -87,11 +87,51 @@ function useInit(_ref2) {
|
|
|
87
87
|
value: dataSource,
|
|
88
88
|
onChange: setDataSource
|
|
89
89
|
});
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
90
|
+
var updateSelectedStatus = useMemoFn(function (keys) {
|
|
91
|
+
var data = _.map(dataSource, function (item) {
|
|
92
|
+
return _objectSpread(_objectSpread({}, item), {}, {
|
|
93
|
+
__selected__: includesNonStrictMode(keys, item[rowKey])
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
setDataSource(data);
|
|
97
|
+
});
|
|
98
|
+
var refresh = useMemoFn( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
99
|
+
var _ref4,
|
|
100
|
+
onlyLoading,
|
|
101
|
+
params,
|
|
102
|
+
_yield$Promise$all,
|
|
103
|
+
_yield$Promise$all2,
|
|
104
|
+
res,
|
|
105
|
+
_args2 = arguments;
|
|
106
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
107
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
108
|
+
case 0:
|
|
109
|
+
_ref4 = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : {}, onlyLoading = _ref4.onlyLoading, params = _objectWithoutProperties(_ref4, _excluded2);
|
|
110
|
+
setLoading(true);
|
|
111
|
+
if (!onlyLoading) {
|
|
112
|
+
_context2.next = 4;
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
return _context2.abrupt("return");
|
|
116
|
+
case 4:
|
|
117
|
+
_context2.prev = 4;
|
|
118
|
+
_context2.next = 7;
|
|
119
|
+
return Promise.all([executeFunction(data, params), getInitialContext(params)]);
|
|
120
|
+
case 7:
|
|
121
|
+
_yield$Promise$all = _context2.sent;
|
|
122
|
+
_yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 1);
|
|
123
|
+
res = _yield$Promise$all2[0];
|
|
124
|
+
setDataSource(res || []);
|
|
125
|
+
case 11:
|
|
126
|
+
_context2.prev = 11;
|
|
127
|
+
setLoading(false);
|
|
128
|
+
return _context2.finish(11);
|
|
129
|
+
case 14:
|
|
130
|
+
case "end":
|
|
131
|
+
return _context2.stop();
|
|
132
|
+
}
|
|
133
|
+
}, _callee2, null, [[4,, 11, 14]]);
|
|
134
|
+
})));
|
|
95
135
|
var context = _objectSpread(_objectSpread({}, contexts), {}, {
|
|
96
136
|
refresh: refresh,
|
|
97
137
|
dataSource: dataSource,
|
|
@@ -107,57 +147,11 @@ function useInit(_ref2) {
|
|
|
107
147
|
columns: columns,
|
|
108
148
|
editorValueKey: editorValueKey
|
|
109
149
|
});
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
});
|
|
116
|
-
setDataSource(data);
|
|
117
|
-
}
|
|
118
|
-
function refresh() {
|
|
119
|
-
return _refresh.apply(this, arguments);
|
|
120
|
-
}
|
|
121
|
-
function _refresh() {
|
|
122
|
-
_refresh = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
123
|
-
var _ref3,
|
|
124
|
-
onlyLoading,
|
|
125
|
-
params,
|
|
126
|
-
_yield$Promise$all,
|
|
127
|
-
_yield$Promise$all2,
|
|
128
|
-
res,
|
|
129
|
-
_args2 = arguments;
|
|
130
|
-
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
131
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
132
|
-
case 0:
|
|
133
|
-
_ref3 = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : {}, onlyLoading = _ref3.onlyLoading, params = _objectWithoutProperties(_ref3, _excluded2);
|
|
134
|
-
setLoading(true);
|
|
135
|
-
if (!onlyLoading) {
|
|
136
|
-
_context2.next = 4;
|
|
137
|
-
break;
|
|
138
|
-
}
|
|
139
|
-
return _context2.abrupt("return");
|
|
140
|
-
case 4:
|
|
141
|
-
_context2.prev = 4;
|
|
142
|
-
_context2.next = 7;
|
|
143
|
-
return Promise.all([executeFunction(data, params), getInitialContext(params)]);
|
|
144
|
-
case 7:
|
|
145
|
-
_yield$Promise$all = _context2.sent;
|
|
146
|
-
_yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 1);
|
|
147
|
-
res = _yield$Promise$all2[0];
|
|
148
|
-
setDataSource(res || []);
|
|
149
|
-
case 11:
|
|
150
|
-
_context2.prev = 11;
|
|
151
|
-
setLoading(false);
|
|
152
|
-
return _context2.finish(11);
|
|
153
|
-
case 14:
|
|
154
|
-
case "end":
|
|
155
|
-
return _context2.stop();
|
|
156
|
-
}
|
|
157
|
-
}, _callee2, null, [[4,, 11, 14]]);
|
|
158
|
-
}));
|
|
159
|
-
return _refresh.apply(this, arguments);
|
|
160
|
-
}
|
|
150
|
+
|
|
151
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
152
|
+
useEffect(function () {
|
|
153
|
+
return void refresh();
|
|
154
|
+
}, [data]);
|
|
161
155
|
var rowSelection = getRowSelection({
|
|
162
156
|
rowKey: rowKey,
|
|
163
157
|
columns: columns,
|
|
@@ -177,11 +171,11 @@ function useInit(_ref2) {
|
|
|
177
171
|
useFormWrapper: useFormWrapper
|
|
178
172
|
};
|
|
179
173
|
}
|
|
180
|
-
export function useTable(
|
|
181
|
-
var onRowClick =
|
|
182
|
-
width =
|
|
183
|
-
emptyText =
|
|
184
|
-
restProps = _objectWithoutProperties(
|
|
174
|
+
export function useTable(_ref5) {
|
|
175
|
+
var onRowClick = _ref5.onRowClick,
|
|
176
|
+
width = _ref5.width,
|
|
177
|
+
emptyText = _ref5.emptyText,
|
|
178
|
+
restProps = _objectWithoutProperties(_ref5, _excluded3);
|
|
185
179
|
var params = useInit(restProps);
|
|
186
180
|
var _useSearchColumn = useSearchColumn(),
|
|
187
181
|
getSearchColumn = _useSearchColumn.getSearchColumn;
|
|
@@ -95,11 +95,51 @@ function useInit(_ref2) {
|
|
|
95
95
|
value: dataSource,
|
|
96
96
|
onChange: setDataSource
|
|
97
97
|
});
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
98
|
+
var updateSelectedStatus = (0, _hooks.useMemoFn)(function (keys) {
|
|
99
|
+
var data = _lodash.default.map(dataSource, function (item) {
|
|
100
|
+
return (0, _objectSpread2.default)((0, _objectSpread2.default)({}, item), {}, {
|
|
101
|
+
__selected__: (0, _api.includesNonStrictMode)(keys, item[rowKey])
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
setDataSource(data);
|
|
105
|
+
});
|
|
106
|
+
var refresh = (0, _hooks.useMemoFn)( /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/(0, _regeneratorRuntime2.default)().mark(function _callee2() {
|
|
107
|
+
var _ref4,
|
|
108
|
+
onlyLoading,
|
|
109
|
+
params,
|
|
110
|
+
_yield$Promise$all,
|
|
111
|
+
_yield$Promise$all2,
|
|
112
|
+
res,
|
|
113
|
+
_args2 = arguments;
|
|
114
|
+
return (0, _regeneratorRuntime2.default)().wrap(function _callee2$(_context2) {
|
|
115
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
116
|
+
case 0:
|
|
117
|
+
_ref4 = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : {}, onlyLoading = _ref4.onlyLoading, params = (0, _objectWithoutProperties2.default)(_ref4, _excluded2);
|
|
118
|
+
setLoading(true);
|
|
119
|
+
if (!onlyLoading) {
|
|
120
|
+
_context2.next = 4;
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
return _context2.abrupt("return");
|
|
124
|
+
case 4:
|
|
125
|
+
_context2.prev = 4;
|
|
126
|
+
_context2.next = 7;
|
|
127
|
+
return Promise.all([(0, _api.executeFunction)(data, params), getInitialContext(params)]);
|
|
128
|
+
case 7:
|
|
129
|
+
_yield$Promise$all = _context2.sent;
|
|
130
|
+
_yield$Promise$all2 = (0, _slicedToArray2.default)(_yield$Promise$all, 1);
|
|
131
|
+
res = _yield$Promise$all2[0];
|
|
132
|
+
setDataSource(res || []);
|
|
133
|
+
case 11:
|
|
134
|
+
_context2.prev = 11;
|
|
135
|
+
setLoading(false);
|
|
136
|
+
return _context2.finish(11);
|
|
137
|
+
case 14:
|
|
138
|
+
case "end":
|
|
139
|
+
return _context2.stop();
|
|
140
|
+
}
|
|
141
|
+
}, _callee2, null, [[4,, 11, 14]]);
|
|
142
|
+
})));
|
|
103
143
|
var context = (0, _objectSpread2.default)((0, _objectSpread2.default)({}, contexts), {}, {
|
|
104
144
|
refresh: refresh,
|
|
105
145
|
dataSource: dataSource,
|
|
@@ -115,57 +155,11 @@ function useInit(_ref2) {
|
|
|
115
155
|
columns: columns,
|
|
116
156
|
editorValueKey: editorValueKey
|
|
117
157
|
});
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
});
|
|
124
|
-
setDataSource(data);
|
|
125
|
-
}
|
|
126
|
-
function refresh() {
|
|
127
|
-
return _refresh.apply(this, arguments);
|
|
128
|
-
}
|
|
129
|
-
function _refresh() {
|
|
130
|
-
_refresh = (0, _asyncToGenerator2.default)( /*#__PURE__*/(0, _regeneratorRuntime2.default)().mark(function _callee2() {
|
|
131
|
-
var _ref3,
|
|
132
|
-
onlyLoading,
|
|
133
|
-
params,
|
|
134
|
-
_yield$Promise$all,
|
|
135
|
-
_yield$Promise$all2,
|
|
136
|
-
res,
|
|
137
|
-
_args2 = arguments;
|
|
138
|
-
return (0, _regeneratorRuntime2.default)().wrap(function _callee2$(_context2) {
|
|
139
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
140
|
-
case 0:
|
|
141
|
-
_ref3 = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : {}, onlyLoading = _ref3.onlyLoading, params = (0, _objectWithoutProperties2.default)(_ref3, _excluded2);
|
|
142
|
-
setLoading(true);
|
|
143
|
-
if (!onlyLoading) {
|
|
144
|
-
_context2.next = 4;
|
|
145
|
-
break;
|
|
146
|
-
}
|
|
147
|
-
return _context2.abrupt("return");
|
|
148
|
-
case 4:
|
|
149
|
-
_context2.prev = 4;
|
|
150
|
-
_context2.next = 7;
|
|
151
|
-
return Promise.all([(0, _api.executeFunction)(data, params), getInitialContext(params)]);
|
|
152
|
-
case 7:
|
|
153
|
-
_yield$Promise$all = _context2.sent;
|
|
154
|
-
_yield$Promise$all2 = (0, _slicedToArray2.default)(_yield$Promise$all, 1);
|
|
155
|
-
res = _yield$Promise$all2[0];
|
|
156
|
-
setDataSource(res || []);
|
|
157
|
-
case 11:
|
|
158
|
-
_context2.prev = 11;
|
|
159
|
-
setLoading(false);
|
|
160
|
-
return _context2.finish(11);
|
|
161
|
-
case 14:
|
|
162
|
-
case "end":
|
|
163
|
-
return _context2.stop();
|
|
164
|
-
}
|
|
165
|
-
}, _callee2, null, [[4,, 11, 14]]);
|
|
166
|
-
}));
|
|
167
|
-
return _refresh.apply(this, arguments);
|
|
168
|
-
}
|
|
158
|
+
|
|
159
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
160
|
+
(0, _react.useEffect)(function () {
|
|
161
|
+
return void refresh();
|
|
162
|
+
}, [data]);
|
|
169
163
|
var rowSelection = (0, _utils.getRowSelection)({
|
|
170
164
|
rowKey: rowKey,
|
|
171
165
|
columns: columns,
|
|
@@ -185,11 +179,11 @@ function useInit(_ref2) {
|
|
|
185
179
|
useFormWrapper: useFormWrapper
|
|
186
180
|
};
|
|
187
181
|
}
|
|
188
|
-
function useTable(
|
|
189
|
-
var onRowClick =
|
|
190
|
-
width =
|
|
191
|
-
emptyText =
|
|
192
|
-
restProps = (0, _objectWithoutProperties2.default)(
|
|
182
|
+
function useTable(_ref5) {
|
|
183
|
+
var onRowClick = _ref5.onRowClick,
|
|
184
|
+
width = _ref5.width,
|
|
185
|
+
emptyText = _ref5.emptyText,
|
|
186
|
+
restProps = (0, _objectWithoutProperties2.default)(_ref5, _excluded3);
|
|
193
187
|
var params = useInit(restProps);
|
|
194
188
|
var _useSearchColumn = (0, _2.useSearchColumn)(),
|
|
195
189
|
getSearchColumn = _useSearchColumn.getSearchColumn;
|