@lemon-fe/kits 1.0.0-141 → 1.0.0-142
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.
|
@@ -82,6 +82,7 @@ import TextEditor from "./cell-editors/Text";
|
|
|
82
82
|
import EditorWrapper from "./cell-editors/Wrapper";
|
|
83
83
|
import Selected from "./components/Selected";
|
|
84
84
|
import GridStoreContext from "./context/GridStore";
|
|
85
|
+
import { useGridStore } from "./hooks";
|
|
85
86
|
import { ClipboardModule } from "./modules/clipboard/main";
|
|
86
87
|
import { ColumnsToolPanelModule } from "./modules/column-tool-panel/main";
|
|
87
88
|
import { MasterDetailModule } from "./modules/master-detail/main";
|
|
@@ -114,6 +115,15 @@ function unsort() {
|
|
|
114
115
|
return 0;
|
|
115
116
|
}
|
|
116
117
|
|
|
118
|
+
function EmptyOverlay(props) {
|
|
119
|
+
var err = useGridStore(function (state) {
|
|
120
|
+
return state.fetchError;
|
|
121
|
+
});
|
|
122
|
+
return /*#__PURE__*/React.createElement(Empty, {
|
|
123
|
+
description: err ? err.message : props.desc
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
117
127
|
var DataGrid = /*#__PURE__*/function (_Component) {
|
|
118
128
|
_inherits(DataGrid, _Component);
|
|
119
129
|
|
|
@@ -227,9 +237,8 @@ var DataGrid = /*#__PURE__*/function (_Component) {
|
|
|
227
237
|
});
|
|
228
238
|
|
|
229
239
|
_defineProperty(_assertThisInitialized(_this), "NoRowsOverlay", function () {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
description: error ? error.message : _this.props.emptyText
|
|
240
|
+
return /*#__PURE__*/React.createElement(EmptyOverlay, {
|
|
241
|
+
desc: _this.props.emptyText
|
|
233
242
|
});
|
|
234
243
|
});
|
|
235
244
|
|
|
@@ -389,7 +398,7 @@ var DataGrid = /*#__PURE__*/function (_Component) {
|
|
|
389
398
|
return;
|
|
390
399
|
}
|
|
391
400
|
|
|
392
|
-
var node = api.
|
|
401
|
+
var node = api.getModel().getRow(rowIndex);
|
|
393
402
|
|
|
394
403
|
if (node === undefined || !node.id) {
|
|
395
404
|
_this.prevFocusedCell = null;
|
|
@@ -1022,9 +1031,12 @@ var DataGrid = /*#__PURE__*/function (_Component) {
|
|
|
1022
1031
|
onLoad(res.extra);
|
|
1023
1032
|
}
|
|
1024
1033
|
}).catch(function (err) {
|
|
1034
|
+
_this5.store.setState({
|
|
1035
|
+
fetchError: err
|
|
1036
|
+
});
|
|
1037
|
+
|
|
1025
1038
|
_this5.setState({
|
|
1026
|
-
loading: false
|
|
1027
|
-
error: err
|
|
1039
|
+
loading: false
|
|
1028
1040
|
});
|
|
1029
1041
|
});
|
|
1030
1042
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import type { AgGridReactProps } from '@ag-grid-community/react';
|
|
2
1
|
import type { ColDef, ColGroupDef, EditableCallbackParams, ICellEditorParams, ICellRendererParams, IHeaderParams, AgGridEvent } from '@ag-grid-community/core';
|
|
2
|
+
import type { AgGridReactProps } from '@ag-grid-community/react';
|
|
3
3
|
import type { RuleItem } from 'async-validator/dist-types/interface';
|
|
4
4
|
import type { ReactElement, ReactNode } from 'react';
|
|
5
|
-
import type { TextEditorParams } from './cell-editors/Text';
|
|
6
|
-
import type { NumberEditorParams } from './cell-editors/Number';
|
|
7
5
|
import type { DateEditorParams } from './cell-editors/Date';
|
|
8
|
-
import type {
|
|
6
|
+
import type { NumberEditorParams } from './cell-editors/Number';
|
|
9
7
|
import type { RowEditorParams } from './cell-editors/Row';
|
|
8
|
+
import type { SelectEditorParams } from './cell-editors/Select';
|
|
9
|
+
import type { TextEditorParams } from './cell-editors/Text';
|
|
10
10
|
import type DataGrid from './index';
|
|
11
11
|
export type { TextEditorParams } from './cell-editors/Text';
|
|
12
12
|
export type { NumberEditorParams } from './cell-editors/Number';
|
|
@@ -92,6 +92,7 @@ export declare type GridStore = {
|
|
|
92
92
|
errors: Map<string, Map<string, string[]>>;
|
|
93
93
|
context?: any;
|
|
94
94
|
grid: DataGrid<any>;
|
|
95
|
+
fetchError?: Error;
|
|
95
96
|
};
|
|
96
97
|
export interface RowAction<T> {
|
|
97
98
|
/**
|
|
@@ -24,12 +24,12 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
|
|
|
24
24
|
|
|
25
25
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
26
26
|
|
|
27
|
-
import React, { cloneElement, createContext, useContext, useEffect, useMemo, useState, memo, isValidElement, forwardRef, useImperativeHandle, useRef } from 'react';
|
|
28
27
|
import { get, isEqual } from 'lodash';
|
|
28
|
+
import React, { cloneElement, createContext, useContext, useEffect, useMemo, useState, memo, isValidElement, forwardRef, useImperativeHandle, useRef } from 'react';
|
|
29
29
|
import BaseTable from "../BaseTable";
|
|
30
|
+
import EditableCell from "./EditableCell";
|
|
30
31
|
import { FormStore } from "./util";
|
|
31
32
|
import { PREFIX_CLS } from "../../constants";
|
|
32
|
-
import EditableCell from "./EditableCell";
|
|
33
33
|
var Context = /*#__PURE__*/createContext(null);
|
|
34
34
|
|
|
35
35
|
var getColKey = function getColKey(name) {
|
|
@@ -185,7 +185,7 @@ function EditableTable(props, ref) {
|
|
|
185
185
|
onFocus: opts.onFocus
|
|
186
186
|
}, /*#__PURE__*/cloneElement(renderFormItem, {
|
|
187
187
|
bordered: false,
|
|
188
|
-
|
|
188
|
+
value: value,
|
|
189
189
|
onChange: function onChange(e) {
|
|
190
190
|
var result = e;
|
|
191
191
|
|
|
@@ -32,11 +32,12 @@ import { PlayCircleOutlined, PauseCircleOutlined, ReloadOutlined } from '@ant-de
|
|
|
32
32
|
import { useThrottle } from '@lemon-fe/hooks';
|
|
33
33
|
import { ConfigProvider, Modal, Row, Spin } from 'antd';
|
|
34
34
|
import { get } from 'lodash';
|
|
35
|
-
import React, { useMemo, useState, useRef, useEffect, useContext } from 'react';
|
|
35
|
+
import React, { useMemo, useState, useRef, useEffect, useContext, useCallback } from 'react';
|
|
36
36
|
import { render } from 'react-dom';
|
|
37
37
|
import { unmountComponentAtNode } from 'react-dom';
|
|
38
38
|
import Actions from "../../components/Actions";
|
|
39
39
|
import DataGrid from "../../components/DataGrid";
|
|
40
|
+
import { useDataGrid } from "../../components/DataGrid/hooks";
|
|
40
41
|
import Icons from "../../components/Icons";
|
|
41
42
|
import Layout from "../../components/Layout";
|
|
42
43
|
import Section from "../../components/Section";
|
|
@@ -71,7 +72,7 @@ function BatchOperate(props) {
|
|
|
71
72
|
results = _useState6[0],
|
|
72
73
|
setResults = _useState6[1];
|
|
73
74
|
|
|
74
|
-
var _useState7 = useState(
|
|
75
|
+
var _useState7 = useState(null),
|
|
75
76
|
_useState8 = _slicedToArray(_useState7, 2),
|
|
76
77
|
active = _useState8[0],
|
|
77
78
|
setActive = _useState8[1];
|
|
@@ -83,6 +84,7 @@ function BatchOperate(props) {
|
|
|
83
84
|
|
|
84
85
|
var mounted = useRef(false);
|
|
85
86
|
var pausedRef = useRef(paused);
|
|
87
|
+
var grid = useDataGrid();
|
|
86
88
|
pausedRef.current = paused;
|
|
87
89
|
useEffect(function () {
|
|
88
90
|
mounted.current = visible;
|
|
@@ -92,15 +94,8 @@ function BatchOperate(props) {
|
|
|
92
94
|
}, [visible]);
|
|
93
95
|
|
|
94
96
|
var getRowKey = function getRowKey(record) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
if (rowKey !== undefined) {
|
|
100
|
-
return get(record, rowKey);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
return get(record, 'key');
|
|
97
|
+
var result = typeof rowKey === 'function' ? rowKey(record) : get(record, rowKey);
|
|
98
|
+
return String(result !== null && result !== void 0 ? result : '').toString();
|
|
104
99
|
};
|
|
105
100
|
|
|
106
101
|
var changeResult = function changeResult(key, val) {
|
|
@@ -149,73 +144,85 @@ function BatchOperate(props) {
|
|
|
149
144
|
};
|
|
150
145
|
}(), 500);
|
|
151
146
|
|
|
152
|
-
var
|
|
153
|
-
var
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
_context2.next = 23;
|
|
164
|
-
break;
|
|
165
|
-
}
|
|
147
|
+
var run = useCallback( /*#__PURE__*/function () {
|
|
148
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(node) {
|
|
149
|
+
var item, id, res, index, nextNode;
|
|
150
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
151
|
+
while (1) {
|
|
152
|
+
switch (_context2.prev = _context2.next) {
|
|
153
|
+
case 0:
|
|
154
|
+
item = node.data, id = node.id;
|
|
155
|
+
grid.use(function (curr) {
|
|
156
|
+
return curr.api.ensureNodeVisible(node);
|
|
157
|
+
});
|
|
166
158
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
_context2.next = 9;
|
|
172
|
-
return handler(item, params);
|
|
173
|
-
|
|
174
|
-
case 9:
|
|
175
|
-
res = _context2.sent;
|
|
176
|
-
changeResult(key, res);
|
|
177
|
-
_context2.next = 16;
|
|
178
|
-
break;
|
|
179
|
-
|
|
180
|
-
case 13:
|
|
181
|
-
_context2.prev = 13;
|
|
182
|
-
_context2.t0 = _context2["catch"](6);
|
|
183
|
-
changeResult(key, _context2.t0);
|
|
184
|
-
|
|
185
|
-
case 16:
|
|
186
|
-
if (!pausedRef.current) {
|
|
187
|
-
_context2.next = 18;
|
|
188
|
-
break;
|
|
189
|
-
}
|
|
159
|
+
if (!(!item || !id)) {
|
|
160
|
+
_context2.next = 4;
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
190
163
|
|
|
191
|
-
|
|
164
|
+
return _context2.abrupt("return");
|
|
192
165
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
_context2.
|
|
166
|
+
case 4:
|
|
167
|
+
setActive(id);
|
|
168
|
+
_context2.prev = 5;
|
|
169
|
+
_context2.next = 8;
|
|
170
|
+
return handler(item, params);
|
|
171
|
+
|
|
172
|
+
case 8:
|
|
173
|
+
res = _context2.sent;
|
|
174
|
+
changeResult(id, res);
|
|
175
|
+
_context2.next = 15;
|
|
196
176
|
break;
|
|
197
|
-
}
|
|
198
177
|
|
|
199
|
-
|
|
178
|
+
case 12:
|
|
179
|
+
_context2.prev = 12;
|
|
180
|
+
_context2.t0 = _context2["catch"](5);
|
|
181
|
+
changeResult(id, _context2.t0);
|
|
200
182
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
_context2.next = 2;
|
|
204
|
-
break;
|
|
183
|
+
case 15:
|
|
184
|
+
index = node.rowIndex;
|
|
205
185
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
186
|
+
if (!(pausedRef.current || !mounted.current || index === null)) {
|
|
187
|
+
_context2.next = 18;
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return _context2.abrupt("return");
|
|
211
192
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
193
|
+
case 18:
|
|
194
|
+
nextNode = grid.use(function (curr) {
|
|
195
|
+
return curr.api.getModel().getRow(index + 1);
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
if (nextNode) {
|
|
199
|
+
run(nextNode);
|
|
200
|
+
} else {
|
|
201
|
+
setActive(null);
|
|
202
|
+
setPaused(true);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
case 20:
|
|
206
|
+
case "end":
|
|
207
|
+
return _context2.stop();
|
|
208
|
+
}
|
|
215
209
|
}
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
|
|
210
|
+
}, _callee2, null, [[5, 12]]);
|
|
211
|
+
}));
|
|
212
|
+
|
|
213
|
+
return function (_x3) {
|
|
214
|
+
return _ref2.apply(this, arguments);
|
|
215
|
+
};
|
|
216
|
+
}(), [params]);
|
|
217
|
+
var start = useThrottle(function () {
|
|
218
|
+
setPaused(false);
|
|
219
|
+
|
|
220
|
+
if (data.length > 0) {
|
|
221
|
+
run(grid.use(function (curr) {
|
|
222
|
+
return curr.api.getRowNode(getRowKey(data[0]));
|
|
223
|
+
}));
|
|
224
|
+
}
|
|
225
|
+
}, 500);
|
|
219
226
|
|
|
220
227
|
var handleClose = /*#__PURE__*/function () {
|
|
221
228
|
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
@@ -288,16 +295,17 @@ function BatchOperate(props) {
|
|
|
288
295
|
dataIndex: typeof rowKey === 'string' ? rowKey : undefined,
|
|
289
296
|
render: function render(_1, _2, _3, _ref6) {
|
|
290
297
|
var node = _ref6.node;
|
|
291
|
-
return node.id
|
|
298
|
+
return node.id;
|
|
292
299
|
}
|
|
293
300
|
}];
|
|
294
301
|
cols.unshift({
|
|
295
302
|
title: '',
|
|
296
303
|
colId: '__delete__',
|
|
297
304
|
width: 32,
|
|
298
|
-
render: function render(_1, _2,
|
|
305
|
+
render: function render(_1, _2, _3, _ref7) {
|
|
299
306
|
var context = _ref7.context,
|
|
300
|
-
node = _ref7.node
|
|
307
|
+
node = _ref7.node,
|
|
308
|
+
api = _ref7.api;
|
|
301
309
|
var key = node.id;
|
|
302
310
|
return /*#__PURE__*/React.createElement(Icons.Delete, {
|
|
303
311
|
onClick: function onClick() {
|
|
@@ -305,12 +313,8 @@ function BatchOperate(props) {
|
|
|
305
313
|
return;
|
|
306
314
|
}
|
|
307
315
|
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
return prev - 1;
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
return prev;
|
|
316
|
+
api.applyTransaction({
|
|
317
|
+
remove: [node.data]
|
|
314
318
|
});
|
|
315
319
|
setResults(function (prev) {
|
|
316
320
|
if (prev.has(key)) {
|
|
@@ -321,12 +325,6 @@ function BatchOperate(props) {
|
|
|
321
325
|
|
|
322
326
|
return prev;
|
|
323
327
|
});
|
|
324
|
-
setData(function (prev) {
|
|
325
|
-
var next = _toConsumableArray(prev);
|
|
326
|
-
|
|
327
|
-
next.splice(index, 1);
|
|
328
|
-
return next;
|
|
329
|
-
});
|
|
330
328
|
}
|
|
331
329
|
});
|
|
332
330
|
}
|
|
@@ -336,13 +334,13 @@ function BatchOperate(props) {
|
|
|
336
334
|
dataIndex: 'status',
|
|
337
335
|
flex: 1,
|
|
338
336
|
resizable: false,
|
|
339
|
-
render: function render(
|
|
337
|
+
render: function render(_1, record, _2, _ref8) {
|
|
340
338
|
var context = _ref8.context,
|
|
341
339
|
node = _ref8.node;
|
|
342
340
|
var key = node.id;
|
|
343
341
|
var result = context.results.get(key);
|
|
344
342
|
|
|
345
|
-
if (context.active ===
|
|
343
|
+
if (context.active === key && !context.paused || result === loading) {
|
|
346
344
|
return /*#__PURE__*/React.createElement("span", null, /*#__PURE__*/React.createElement(Spin, {
|
|
347
345
|
size: "small",
|
|
348
346
|
style: {
|
|
@@ -412,7 +410,7 @@ function BatchOperate(props) {
|
|
|
412
410
|
afterClose: function afterClose() {
|
|
413
411
|
setResults(new Map());
|
|
414
412
|
setPaused(true);
|
|
415
|
-
setActive(
|
|
413
|
+
setActive(null);
|
|
416
414
|
setData([]);
|
|
417
415
|
|
|
418
416
|
_afterClose();
|
|
@@ -426,7 +424,7 @@ function BatchOperate(props) {
|
|
|
426
424
|
actions: [paused ? {
|
|
427
425
|
disabled: data.length <= 0 || results.size >= data.length,
|
|
428
426
|
icon: /*#__PURE__*/React.createElement(PlayCircleOutlined, null),
|
|
429
|
-
text: active
|
|
427
|
+
text: active ? '继续执行' : '开始执行',
|
|
430
428
|
onClick: start
|
|
431
429
|
} : {
|
|
432
430
|
disabled: data.length <= 0,
|
|
@@ -441,11 +439,13 @@ function BatchOperate(props) {
|
|
|
441
439
|
flex: 1
|
|
442
440
|
}, /*#__PURE__*/React.createElement(DataGrid, {
|
|
443
441
|
pagination: false,
|
|
442
|
+
ref: grid.ref,
|
|
444
443
|
context: {
|
|
445
444
|
results: results,
|
|
446
445
|
paused: paused,
|
|
447
446
|
active: active
|
|
448
447
|
},
|
|
448
|
+
onDataSourceChange: setData,
|
|
449
449
|
dataSource: data,
|
|
450
450
|
columns: mCols,
|
|
451
451
|
rowKey: rowKey
|