@lemon-fe/kits 1.0.0-121 → 1.0.0-122
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/components/DataGrid/index.d.ts +2 -3
- package/es/components/DataGrid/index.js +25 -33
- package/es/components/DataGrid/index.less +1 -1
- package/es/components/Filter/index.js +11 -11
- package/es/components/Layout/index.d.ts +12 -2
- package/es/components/Layout/index.js +81 -23
- package/es/components/Layout/index.less +1 -0
- package/es/components/Portal/index.d.ts +7 -6
- package/es/components/Portal/index.js +54 -12
- package/es/hooks/useBatchOperator/index.d.ts +26 -4
- package/es/hooks/useBatchOperator/index.js +92 -29
- package/es/index.d.ts +1 -0
- package/es/index.js +1 -0
- package/package.json +1 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import React, { Component } from 'react';
|
|
2
1
|
import type { ColDef } from '@ag-grid-community/core';
|
|
3
2
|
import { GridApi, ColumnApi } from '@ag-grid-community/core';
|
|
4
|
-
import
|
|
3
|
+
import React, { Component } from 'react';
|
|
5
4
|
import EditorWrapper from './cell-editors/Wrapper';
|
|
5
|
+
import type { ColType, DataGridProps, DataGridState } from './typings';
|
|
6
6
|
export default class DataGrid<TData extends Record<string, any>> extends Component<DataGridProps<TData>, DataGridState<TData>> {
|
|
7
7
|
api: GridApi<TData>;
|
|
8
8
|
columnApi: ColumnApi;
|
|
@@ -41,7 +41,6 @@ export default class DataGrid<TData extends Record<string, any>> extends Compone
|
|
|
41
41
|
columnTypes: Record<string, ColDef<any>>;
|
|
42
42
|
defaultColDef: ColDef<any>;
|
|
43
43
|
components: Record<string, any>;
|
|
44
|
-
loading: boolean;
|
|
45
44
|
};
|
|
46
45
|
static EmptyCol: ColType<any>;
|
|
47
46
|
static Editors: {
|
|
@@ -63,36 +63,36 @@ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.g
|
|
|
63
63
|
|
|
64
64
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
65
65
|
|
|
66
|
-
import
|
|
67
|
-
import { AgGridReact } from '@ag-grid-community/react';
|
|
68
|
-
import shallowEqual from 'shallowequal';
|
|
66
|
+
import { ClientSideRowModelModule } from '@ag-grid-community/client-side-row-model';
|
|
69
67
|
import { ModuleRegistry, GridApi, ColumnApi } from '@ag-grid-community/core';
|
|
70
68
|
import { InfiniteRowModelModule } from '@ag-grid-community/infinite-row-model';
|
|
71
|
-
import {
|
|
72
|
-
import { get, set } from 'lodash';
|
|
73
|
-
import Scheme from 'async-validator';
|
|
74
|
-
import GridStoreContext from "./context/GridStore";
|
|
75
|
-
import { RowGroupingModule } from "./modules/row-grouping/main";
|
|
76
|
-
import { ClipboardModule } from "./modules/clipboard/main";
|
|
77
|
-
import { MenuModule } from "./modules/menu/main";
|
|
78
|
-
import { ColumnsToolPanelModule } from "./modules/column-tool-panel/main";
|
|
79
|
-
import { SideBarModule } from "./modules/side-bar/main";
|
|
80
|
-
import { MasterDetailModule } from "./modules/master-detail/main";
|
|
69
|
+
import { AgGridReact } from '@ag-grid-community/react';
|
|
81
70
|
import { Spin, Pagination, Empty } from 'antd';
|
|
82
|
-
import
|
|
83
|
-
import
|
|
84
|
-
import
|
|
85
|
-
import
|
|
71
|
+
import Scheme from 'async-validator';
|
|
72
|
+
import { get, set } from 'lodash';
|
|
73
|
+
import memoizeOne from 'memoize-one';
|
|
74
|
+
import React, { Component } from 'react';
|
|
75
|
+
import shallowEqual from 'shallowequal';
|
|
86
76
|
import DateEditor from "./cell-editors/Date";
|
|
87
|
-
import TextEditor from "./cell-editors/Text";
|
|
88
77
|
import NumberEditor from "./cell-editors/Number";
|
|
89
|
-
import SelectEditor from "./cell-editors/Select";
|
|
90
78
|
import RowEditor, { RowEditorData } from "./cell-editors/Row";
|
|
79
|
+
import SelectEditor from "./cell-editors/Select";
|
|
80
|
+
import TextEditor from "./cell-editors/Text";
|
|
91
81
|
import EditorWrapper from "./cell-editors/Wrapper";
|
|
92
|
-
import memoizeOne from 'memoize-one';
|
|
93
82
|
import Selected from "./components/Selected";
|
|
83
|
+
import GridStoreContext from "./context/GridStore";
|
|
84
|
+
import { ClipboardModule } from "./modules/clipboard/main";
|
|
85
|
+
import { ColumnsToolPanelModule } from "./modules/column-tool-panel/main";
|
|
86
|
+
import { MasterDetailModule } from "./modules/master-detail/main";
|
|
87
|
+
import { MenuModule } from "./modules/menu/main";
|
|
88
|
+
import { RowGroupingModule } from "./modules/row-grouping/main";
|
|
89
|
+
import { SideBarModule } from "./modules/side-bar/main";
|
|
90
|
+
import Actions from "./renderer/Actions";
|
|
94
91
|
import CellIndexRender from "./renderer/CellIndexRenderer";
|
|
92
|
+
import CellRenderer from "./renderer/CellRenderer";
|
|
95
93
|
import DetailCellRenderer from "./renderer/DetailCellRenderer";
|
|
94
|
+
import HeaderRenderer from "./renderer/HeaderRenderer";
|
|
95
|
+
import { prefix, getColField, isColumn, withSyncRender, Store, Selection, columnTypes } from "./utils";
|
|
96
96
|
ModuleRegistry.registerModules([ClientSideRowModelModule, RowGroupingModule, InfiniteRowModelModule, ClipboardModule, MenuModule, SideBarModule, ColumnsToolPanelModule, MasterDetailModule], false);
|
|
97
97
|
var defaultColDef = {
|
|
98
98
|
resizable: true,
|
|
@@ -396,7 +396,7 @@ var DataGrid = /*#__PURE__*/function (_Component) {
|
|
|
396
396
|
|
|
397
397
|
_this.state = _objectSpread({
|
|
398
398
|
colDefs: _this.getColumDefs(),
|
|
399
|
-
loading:
|
|
399
|
+
loading: false
|
|
400
400
|
}, _this.getPagination());
|
|
401
401
|
_this.store = new Store({
|
|
402
402
|
errors: new Map(),
|
|
@@ -456,8 +456,7 @@ var DataGrid = /*#__PURE__*/function (_Component) {
|
|
|
456
456
|
columns = _this$props5.columns,
|
|
457
457
|
rowSelection = _this$props5.rowSelection,
|
|
458
458
|
dataSource = _this$props5.dataSource,
|
|
459
|
-
context = _this$props5.context
|
|
460
|
-
loading = _this$props5.loading;
|
|
459
|
+
context = _this$props5.context;
|
|
461
460
|
|
|
462
461
|
if (columns !== prevProps.columns) {
|
|
463
462
|
this.syncColRender();
|
|
@@ -479,12 +478,6 @@ var DataGrid = /*#__PURE__*/function (_Component) {
|
|
|
479
478
|
context: context
|
|
480
479
|
});
|
|
481
480
|
}
|
|
482
|
-
|
|
483
|
-
if (loading !== prevProps.loading) {
|
|
484
|
-
this.setState({
|
|
485
|
-
loading: loading || false
|
|
486
|
-
});
|
|
487
|
-
}
|
|
488
481
|
}
|
|
489
482
|
}, {
|
|
490
483
|
key: "componentWillUnmount",
|
|
@@ -1369,9 +1362,9 @@ var DataGrid = /*#__PURE__*/function (_Component) {
|
|
|
1369
1362
|
columnTypes: this.getMemoizedColumnTypes(columnTypesProp)
|
|
1370
1363
|
})), footer.length > 0 && /*#__PURE__*/React.createElement("div", {
|
|
1371
1364
|
className: prefix('bottom')
|
|
1372
|
-
}, footer),
|
|
1365
|
+
}, footer), (loadingProp !== null && loadingProp !== void 0 ? loadingProp : loading) ? /*#__PURE__*/React.createElement(Spin, {
|
|
1373
1366
|
className: prefix('spin')
|
|
1374
|
-
})));
|
|
1367
|
+
}) : null));
|
|
1375
1368
|
}
|
|
1376
1369
|
}]);
|
|
1377
1370
|
|
|
@@ -1402,8 +1395,7 @@ _defineProperty(DataGrid, "defaultProps", {
|
|
|
1402
1395
|
},
|
|
1403
1396
|
columnTypes: {},
|
|
1404
1397
|
defaultColDef: {},
|
|
1405
|
-
components: {}
|
|
1406
|
-
loading: false
|
|
1398
|
+
components: {}
|
|
1407
1399
|
});
|
|
1408
1400
|
|
|
1409
1401
|
_defineProperty(DataGrid, "EmptyCol", {
|
|
@@ -268,7 +268,7 @@
|
|
|
268
268
|
--ag-header-column-resize-handle-display: block;
|
|
269
269
|
--ag-header-column-resize-handle-width: 1px;
|
|
270
270
|
--ag-header-column-resize-handle-height: 12px;
|
|
271
|
-
--ag-header-column-resize-handle-color: #
|
|
271
|
+
--ag-header-column-resize-handle-color: #d9d9d9;
|
|
272
272
|
--ag-cell-horizontal-padding: 8px;
|
|
273
273
|
--ag-icon-font-family: 'agGridAlpine';
|
|
274
274
|
--ag-selected-row-background-color: ~'var(--@{ant-prefix}-primary-1)';
|
|
@@ -34,16 +34,16 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
|
|
|
34
34
|
|
|
35
35
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
36
36
|
|
|
37
|
-
import React, { useEffect, useMemo, useState } from 'react';
|
|
38
|
-
import ResizeObserver from 'rc-resize-observer';
|
|
39
|
-
import { Button, Checkbox, Form, Input, Popover, Space, Modal, message, Select, Empty, InputNumber } from 'antd';
|
|
40
37
|
import { useDebounce, useRequest } from '@lemon-fe/hooks';
|
|
38
|
+
import { Button, Checkbox, Form, Input, Popover, Space, Modal, message, Select, Empty, InputNumber } from 'antd';
|
|
41
39
|
import classNames from 'classnames';
|
|
42
|
-
import
|
|
40
|
+
import ResizeObserver from 'rc-resize-observer';
|
|
41
|
+
import React, { useEffect, useMemo, useState } from 'react';
|
|
42
|
+
import Dropdown from "../Dropdown";
|
|
43
43
|
import DurationPicker from "../DurationPicker";
|
|
44
44
|
import FormLayout from "../FormLayout";
|
|
45
|
+
import Icons from "../Icons";
|
|
45
46
|
import TabBar from "../TabBar";
|
|
46
|
-
import Dropdown from "../Dropdown";
|
|
47
47
|
import { prefixClassName } from "../utils";
|
|
48
48
|
var components = [{
|
|
49
49
|
type: 'input',
|
|
@@ -136,9 +136,7 @@ function Filter(props) {
|
|
|
136
136
|
return new Set(defaultActiveKeys);
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
-
return
|
|
140
|
-
return item.key;
|
|
141
|
-
}));
|
|
139
|
+
return null;
|
|
142
140
|
}, []);
|
|
143
141
|
var compMap = useMemo(function () {
|
|
144
142
|
return new Map(components.map(function (item) {
|
|
@@ -365,7 +363,9 @@ function Filter(props) {
|
|
|
365
363
|
|
|
366
364
|
var handleActiveKey = function handleActiveKey(key, flag) {
|
|
367
365
|
setActiveKeys(function (prev) {
|
|
368
|
-
var next = new Set(prev)
|
|
366
|
+
var next = new Set(prev === null ? data.map(function (item) {
|
|
367
|
+
return item.key;
|
|
368
|
+
}) : prev);
|
|
369
369
|
|
|
370
370
|
if (flag) {
|
|
371
371
|
next.add(key);
|
|
@@ -395,7 +395,7 @@ function Filter(props) {
|
|
|
395
395
|
};
|
|
396
396
|
|
|
397
397
|
var result = data.filter(function (item) {
|
|
398
|
-
if (activeKeys.has(item.key) && !item.hidden) {
|
|
398
|
+
if (activeKeys === null || activeKeys.has(item.key) && !item.hidden) {
|
|
399
399
|
return true;
|
|
400
400
|
}
|
|
401
401
|
|
|
@@ -614,7 +614,7 @@ function Filter(props) {
|
|
|
614
614
|
key: item.key,
|
|
615
615
|
className: prefix('item')
|
|
616
616
|
}, /*#__PURE__*/React.createElement(Checkbox, {
|
|
617
|
-
checked: activeKeys.has(item.key),
|
|
617
|
+
checked: activeKeys === null || activeKeys.has(item.key),
|
|
618
618
|
onChange: function onChange(e) {
|
|
619
619
|
handleActiveKey(item.key, e.target.checked);
|
|
620
620
|
}
|
|
@@ -1,8 +1,15 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ReactNode, type CSSProperties } from 'react';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
interface Tab {
|
|
4
|
+
label?: ReactNode;
|
|
5
|
+
/**
|
|
6
|
+
* 与antd tabs保持一致
|
|
7
|
+
* @deprecated
|
|
8
|
+
*/
|
|
4
9
|
title?: ReactNode;
|
|
5
10
|
key: string;
|
|
11
|
+
forceRender?: boolean;
|
|
12
|
+
children?: ReactNode;
|
|
6
13
|
}
|
|
7
14
|
interface Props {
|
|
8
15
|
children?: ReactNode;
|
|
@@ -39,7 +46,10 @@ declare namespace Layout {
|
|
|
39
46
|
left?: ReactNode;
|
|
40
47
|
tab?: string | undefined;
|
|
41
48
|
forceRender?: boolean | undefined;
|
|
42
|
-
} & Pick<Props, "onCollapse">) => JSX.Element;
|
|
49
|
+
} & Pick<Props, "footer" | "header" | "onCollapse">) => JSX.Element;
|
|
50
|
+
var useFocus: () => boolean;
|
|
51
|
+
var SLOT_HEADER: string;
|
|
52
|
+
var SLOT_FOOTER: string;
|
|
43
53
|
}
|
|
44
54
|
export default Layout;
|
|
45
55
|
declare function LayoutTabs(props: {
|
|
@@ -20,12 +20,16 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
|
|
|
20
20
|
|
|
21
21
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
22
22
|
|
|
23
|
-
import { mapChildren, prefixClassName } from "../utils";
|
|
24
23
|
import { Spin, Tabs } from 'antd';
|
|
25
|
-
import { Resizable } from 'react-resizable';
|
|
26
|
-
import React, { useState } from 'react';
|
|
27
24
|
import classNames from 'classnames';
|
|
28
25
|
import { get } from 'lodash';
|
|
26
|
+
import { useCallback, createContext, useContext } from 'react';
|
|
27
|
+
import React, { useState } from 'react';
|
|
28
|
+
import { Resizable } from 'react-resizable';
|
|
29
|
+
import Portal from "../Portal";
|
|
30
|
+
import { mapChildren, prefixClassName } from "../utils";
|
|
31
|
+
var SLOT_HEADER = 'header';
|
|
32
|
+
var SLOT_FOOTER = 'footer';
|
|
29
33
|
var prefix = prefixClassName('layout');
|
|
30
34
|
|
|
31
35
|
function Sider(props) {
|
|
@@ -126,17 +130,30 @@ function Sider(props) {
|
|
|
126
130
|
})))))))));
|
|
127
131
|
}
|
|
128
132
|
|
|
133
|
+
var ActiveContext = /*#__PURE__*/createContext(true);
|
|
134
|
+
|
|
135
|
+
function useFocus() {
|
|
136
|
+
return useContext(ActiveContext);
|
|
137
|
+
}
|
|
138
|
+
|
|
129
139
|
function Content(props) {
|
|
130
140
|
var left = props.left,
|
|
131
141
|
children = props.children,
|
|
132
|
-
onCollapse = props.onCollapse
|
|
142
|
+
onCollapse = props.onCollapse,
|
|
143
|
+
header = props.header,
|
|
144
|
+
footer = props.footer;
|
|
145
|
+
var focused = useFocus();
|
|
133
146
|
return /*#__PURE__*/React.createElement("div", {
|
|
134
147
|
className: prefix('content')
|
|
135
148
|
}, left ? /*#__PURE__*/React.createElement(Sider, {
|
|
136
149
|
onCollapse: onCollapse
|
|
137
150
|
}, left) : null, /*#__PURE__*/React.createElement("div", {
|
|
138
151
|
className: prefix('main')
|
|
139
|
-
}, children)
|
|
152
|
+
}, children), focused && header ? /*#__PURE__*/React.createElement(Portal, {
|
|
153
|
+
slot: SLOT_HEADER
|
|
154
|
+
}, header) : null, focused && footer ? /*#__PURE__*/React.createElement(Portal, {
|
|
155
|
+
slot: SLOT_FOOTER
|
|
156
|
+
}, footer) : null);
|
|
140
157
|
}
|
|
141
158
|
|
|
142
159
|
export default function Layout(props) {
|
|
@@ -153,12 +170,23 @@ export default function Layout(props) {
|
|
|
153
170
|
tabs = props.tabs,
|
|
154
171
|
activeKey = props.activeKey,
|
|
155
172
|
onTabClick = props.onTabClick;
|
|
156
|
-
|
|
173
|
+
var renderHeader = useCallback(function (node) {
|
|
174
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
175
|
+
className: prefix('header')
|
|
176
|
+
}, node);
|
|
177
|
+
}, []);
|
|
178
|
+
var renderFooter = useCallback(function (node) {
|
|
179
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
180
|
+
className: prefix('footer')
|
|
181
|
+
}, node);
|
|
182
|
+
}, []);
|
|
183
|
+
return /*#__PURE__*/React.createElement(Portal.Host, null, /*#__PURE__*/React.createElement("div", {
|
|
157
184
|
className: classNames(prefix(), className),
|
|
158
185
|
style: style
|
|
159
|
-
}, header ? /*#__PURE__*/React.createElement(
|
|
160
|
-
|
|
161
|
-
|
|
186
|
+
}, header ? renderHeader(header) : null, /*#__PURE__*/React.createElement(Portal.Slot, {
|
|
187
|
+
slot: SLOT_HEADER,
|
|
188
|
+
render: renderHeader
|
|
189
|
+
}), /*#__PURE__*/React.createElement("div", {
|
|
162
190
|
className: prefix('body')
|
|
163
191
|
}, tabs ? /*#__PURE__*/React.createElement(Tabs, {
|
|
164
192
|
className: prefix('tabs'),
|
|
@@ -176,41 +204,68 @@ export default function Layout(props) {
|
|
|
176
204
|
}) : null, body || /*#__PURE__*/React.createElement(Content, {
|
|
177
205
|
onCollapse: onCollapse,
|
|
178
206
|
left: left
|
|
179
|
-
}, children)),
|
|
180
|
-
|
|
181
|
-
|
|
207
|
+
}, children)), /*#__PURE__*/React.createElement(Portal.Slot, {
|
|
208
|
+
slot: SLOT_FOOTER,
|
|
209
|
+
render: renderFooter
|
|
210
|
+
}), footer ? renderFooter(footer) : null, loading && /*#__PURE__*/React.createElement("div", {
|
|
182
211
|
className: prefix('spin')
|
|
183
|
-
}, /*#__PURE__*/React.createElement(Spin, null)));
|
|
212
|
+
}, /*#__PURE__*/React.createElement(Spin, null))));
|
|
184
213
|
}
|
|
185
214
|
|
|
186
215
|
function LayoutTabs(props) {
|
|
216
|
+
var _tabs$;
|
|
217
|
+
|
|
187
218
|
var _props$tabs = props.tabs,
|
|
188
219
|
tabs = _props$tabs === void 0 ? [] : _props$tabs,
|
|
189
220
|
children = props.children,
|
|
190
221
|
className = props.className,
|
|
191
222
|
activeKey = props.activeKey,
|
|
192
|
-
|
|
223
|
+
_onTabClick = props.onTabClick,
|
|
193
224
|
hideTabBar = props.hideTabBar,
|
|
194
225
|
restProps = _objectWithoutProperties(props, _excluded);
|
|
195
226
|
|
|
227
|
+
var _useState7 = useState((_tabs$ = tabs[0]) === null || _tabs$ === void 0 ? void 0 : _tabs$.key),
|
|
228
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
229
|
+
active = _useState8[0],
|
|
230
|
+
setActive = _useState8[1];
|
|
231
|
+
|
|
232
|
+
var currentTab = activeKey !== null && activeKey !== void 0 ? activeKey : active;
|
|
196
233
|
return /*#__PURE__*/React.createElement(Layout, _extends({
|
|
197
234
|
className: classNames(className, prefix('tabs-wrapper'), _defineProperty({}, prefix('tabs-hide-tab-bar'), hideTabBar)),
|
|
198
235
|
body: /*#__PURE__*/React.createElement(Tabs, {
|
|
199
|
-
activeKey:
|
|
200
|
-
onTabClick: onTabClick,
|
|
236
|
+
activeKey: currentTab,
|
|
237
|
+
onTabClick: function onTabClick(key, e) {
|
|
238
|
+
if (_onTabClick !== undefined) {
|
|
239
|
+
_onTabClick(key, e);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
setActive(key);
|
|
243
|
+
},
|
|
201
244
|
className: prefix('tabs'),
|
|
202
245
|
renderTabBar: hideTabBar ? function () {
|
|
203
246
|
return null;
|
|
204
247
|
} : undefined,
|
|
205
|
-
items: mapChildren(children, function (node, index) {
|
|
206
|
-
var _get, _get2;
|
|
248
|
+
items: children ? mapChildren(children, function (node, index) {
|
|
249
|
+
var _get, _get2, _get3, _get4;
|
|
207
250
|
|
|
208
251
|
var tab = tabs[index];
|
|
252
|
+
var key = (_get = get(node, 'key')) !== null && _get !== void 0 ? _get : tab === null || tab === void 0 ? void 0 : tab.key;
|
|
253
|
+
return {
|
|
254
|
+
label: (_get2 = get(node, ['props', 'tab'])) !== null && _get2 !== void 0 ? _get2 : tab === null || tab === void 0 ? void 0 : tab.title,
|
|
255
|
+
key: (_get3 = get(node, 'key')) !== null && _get3 !== void 0 ? _get3 : tab === null || tab === void 0 ? void 0 : tab.key,
|
|
256
|
+
forceRender: (_get4 = get(node, ['props', 'forceRender'])) !== null && _get4 !== void 0 ? _get4 : tab === null || tab === void 0 ? void 0 : tab.forceRender,
|
|
257
|
+
children: /*#__PURE__*/React.createElement(ActiveContext.Provider, {
|
|
258
|
+
value: currentTab === key
|
|
259
|
+
}, node)
|
|
260
|
+
};
|
|
261
|
+
}) : tabs.map(function (tab) {
|
|
209
262
|
return {
|
|
210
|
-
label:
|
|
211
|
-
key:
|
|
212
|
-
forceRender:
|
|
213
|
-
children:
|
|
263
|
+
label: tab.label || tab.title,
|
|
264
|
+
key: tab.key,
|
|
265
|
+
forceRender: tab.forceRender,
|
|
266
|
+
children: /*#__PURE__*/React.createElement(ActiveContext.Provider, {
|
|
267
|
+
value: currentTab === tab.key
|
|
268
|
+
}, tab.children)
|
|
214
269
|
};
|
|
215
270
|
})
|
|
216
271
|
})
|
|
@@ -218,4 +273,7 @@ function LayoutTabs(props) {
|
|
|
218
273
|
}
|
|
219
274
|
|
|
220
275
|
Layout.Tabs = LayoutTabs;
|
|
221
|
-
Layout.Content = Content;
|
|
276
|
+
Layout.Content = Content;
|
|
277
|
+
Layout.useFocus = useFocus;
|
|
278
|
+
Layout.SLOT_HEADER = SLOT_HEADER;
|
|
279
|
+
Layout.SLOT_FOOTER = SLOT_FOOTER;
|
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ReactNode } from 'react';
|
|
3
|
+
declare type ContentType = ReactNode;
|
|
3
4
|
declare function PortalHost(props: {
|
|
4
5
|
children: ContentType;
|
|
5
6
|
}): JSX.Element;
|
|
6
|
-
declare function PortalSlot(props: {
|
|
7
|
-
slot: string;
|
|
8
|
-
}): ContentType;
|
|
9
7
|
declare function Portal(props: {
|
|
10
8
|
children: ContentType;
|
|
11
9
|
slot: string;
|
|
12
10
|
}): null;
|
|
13
11
|
declare namespace Portal {
|
|
14
12
|
var Host: typeof PortalHost;
|
|
15
|
-
var Slot:
|
|
13
|
+
var Slot: React.NamedExoticComponent<{
|
|
14
|
+
slot: string;
|
|
15
|
+
render?: ((children: React.ReactNode) => React.ReactElement<any, string | React.JSXElementConstructor<any>> | null) | undefined;
|
|
16
|
+
}>;
|
|
16
17
|
}
|
|
17
18
|
export default Portal;
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
2
|
+
|
|
3
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
+
|
|
5
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
6
|
+
|
|
7
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
8
|
+
|
|
1
9
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
10
|
|
|
3
11
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
@@ -10,9 +18,10 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
|
|
|
10
18
|
|
|
11
19
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
12
20
|
|
|
13
|
-
import React, { createContext, memo, useContext, useEffect, useMemo, useState } from 'react';
|
|
21
|
+
import React, { createContext, memo, useContext, useEffect, useId, useMemo, useState, Fragment } from 'react';
|
|
14
22
|
var Slot = /*#__PURE__*/memo(function Content(props) {
|
|
15
|
-
|
|
23
|
+
var children = props.children;
|
|
24
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, children);
|
|
16
25
|
});
|
|
17
26
|
var Context = /*#__PURE__*/createContext({
|
|
18
27
|
set: function set() {},
|
|
@@ -72,17 +81,28 @@ function PortalHost(props) {
|
|
|
72
81
|
}, []);
|
|
73
82
|
var portal = useMemo(function () {
|
|
74
83
|
return {
|
|
75
|
-
set: function set(
|
|
84
|
+
set: function set(slot, id, node) {
|
|
76
85
|
setNodes(function (prev) {
|
|
77
86
|
var next = new Map(prev);
|
|
78
|
-
next.
|
|
87
|
+
var elms = new Map(next.get(slot));
|
|
88
|
+
elms.set(id, node);
|
|
89
|
+
next.set(slot, elms);
|
|
79
90
|
return next;
|
|
80
91
|
});
|
|
81
92
|
},
|
|
82
|
-
delete: function _delete(
|
|
93
|
+
delete: function _delete(slot, id) {
|
|
83
94
|
setNodes(function (prev) {
|
|
84
95
|
var next = new Map(prev);
|
|
85
|
-
next.
|
|
96
|
+
var elms = new Map(next.get(slot));
|
|
97
|
+
|
|
98
|
+
if (elms) {
|
|
99
|
+
elms.delete(id);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (elms.size <= 0) {
|
|
103
|
+
next.delete(slot);
|
|
104
|
+
}
|
|
105
|
+
|
|
86
106
|
return next;
|
|
87
107
|
});
|
|
88
108
|
},
|
|
@@ -97,8 +117,9 @@ function PortalHost(props) {
|
|
|
97
117
|
}, /*#__PURE__*/React.createElement(Slot, null, children));
|
|
98
118
|
}
|
|
99
119
|
|
|
100
|
-
|
|
101
|
-
var slot = props.slot
|
|
120
|
+
var PortalSlot = /*#__PURE__*/memo(function PortalSlotContent(props) {
|
|
121
|
+
var slot = props.slot,
|
|
122
|
+
render = props.render;
|
|
102
123
|
|
|
103
124
|
var _useContext = useContext(Context),
|
|
104
125
|
observable = _useContext.observable;
|
|
@@ -118,20 +139,41 @@ function PortalSlot(props) {
|
|
|
118
139
|
|
|
119
140
|
return unsubscribe;
|
|
120
141
|
}, [slot]);
|
|
121
|
-
|
|
122
|
-
|
|
142
|
+
var result = useMemo(function () {
|
|
143
|
+
if (node === null) {
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return _toConsumableArray(node).map(function (_ref) {
|
|
148
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
149
|
+
id = _ref2[0],
|
|
150
|
+
elm = _ref2[1];
|
|
151
|
+
|
|
152
|
+
return /*#__PURE__*/React.createElement(Fragment, {
|
|
153
|
+
key: id
|
|
154
|
+
}, elm);
|
|
155
|
+
});
|
|
156
|
+
}, [node]);
|
|
157
|
+
|
|
158
|
+
if (render) {
|
|
159
|
+
return result ? render(result) : null;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, result);
|
|
163
|
+
});
|
|
123
164
|
|
|
124
165
|
function Portal(props) {
|
|
125
166
|
var slot = props.slot,
|
|
126
167
|
children = props.children;
|
|
127
168
|
var portal = useContext(Context);
|
|
169
|
+
var id = useId();
|
|
128
170
|
useEffect(function () {
|
|
129
171
|
return function () {
|
|
130
|
-
portal.delete(slot);
|
|
172
|
+
portal.delete(slot, id);
|
|
131
173
|
};
|
|
132
174
|
}, [slot]);
|
|
133
175
|
useEffect(function () {
|
|
134
|
-
portal.set(slot, children);
|
|
176
|
+
portal.set(slot, id, children);
|
|
135
177
|
}, [slot, children]);
|
|
136
178
|
return null;
|
|
137
179
|
}
|
|
@@ -1,12 +1,34 @@
|
|
|
1
|
+
import { type ReactElement } from 'react';
|
|
1
2
|
import type { Key } from 'react';
|
|
2
3
|
import type { ColType, DataGridProps } from "../../components/DataGrid/typings";
|
|
3
|
-
declare type Result = void | string | Error | symbol;
|
|
4
|
-
export default function useBatchOperate<RecordType extends Record<string, any> = Record<string, any
|
|
4
|
+
declare type Result<ResultType = unknown> = void | string | Error | symbol | ResultType;
|
|
5
|
+
export default function useBatchOperate<RecordType extends Record<string, any> = Record<string, any>, ResultType = unknown>(options: {
|
|
5
6
|
modalTitle: string;
|
|
6
|
-
handler: (record: RecordType) => Promise<string | void>;
|
|
7
|
+
handler: (record: RecordType) => Promise<string | void | ResultType>;
|
|
7
8
|
columns?: ColType<RecordType>[];
|
|
8
9
|
rowKey: DataGridProps<RecordType>['rowKey'];
|
|
9
|
-
onClose?: (results: Map<Key, Result
|
|
10
|
+
onClose?: (results: Map<Key, Result<ResultType>>) => void;
|
|
11
|
+
/** 弹窗关闭前的检验,返回true校验通过关闭弹窗,false校验不通过 */
|
|
12
|
+
onBeforeClose?: (results: Map<Key, Result>) => Promise<boolean>;
|
|
13
|
+
/**
|
|
14
|
+
* 自定义渲染结果,不要依赖上下文
|
|
15
|
+
* @param params
|
|
16
|
+
* @returns
|
|
17
|
+
*/
|
|
18
|
+
renderResult?: (params: {
|
|
19
|
+
data: RecordType;
|
|
20
|
+
result: ResultType;
|
|
21
|
+
/**
|
|
22
|
+
* 显示用的节点
|
|
23
|
+
*/
|
|
24
|
+
elements: {
|
|
25
|
+
reloadButton: ReactElement;
|
|
26
|
+
failIcon: ReactElement;
|
|
27
|
+
successIcon: ReactElement;
|
|
28
|
+
};
|
|
29
|
+
reload: () => any;
|
|
30
|
+
}) => ReactElement | string | number | null;
|
|
31
|
+
isError?: () => boolean;
|
|
10
32
|
}): {
|
|
11
33
|
node: JSX.Element;
|
|
12
34
|
run: (rows: RecordType[]) => void;
|
|
@@ -26,15 +26,15 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
|
|
|
26
26
|
|
|
27
27
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
28
28
|
|
|
29
|
-
import
|
|
29
|
+
import { PlayCircleOutlined, PauseCircleOutlined, ReloadOutlined } from '@ant-design/icons';
|
|
30
|
+
import { useThrottle } from '@lemon-fe/hooks';
|
|
30
31
|
import { Modal, Row, Spin } from 'antd';
|
|
31
|
-
import { PlayCircleOutlined, DeleteTwoTone, PauseCircleOutlined, ReloadOutlined } from '@ant-design/icons';
|
|
32
32
|
import { get } from 'lodash';
|
|
33
|
-
import {
|
|
33
|
+
import React, { useMemo, useState, useRef, useEffect } from 'react';
|
|
34
|
+
import Actions from "../../components/Actions";
|
|
34
35
|
import DataGrid from "../../components/DataGrid";
|
|
35
36
|
import Icons from "../../components/Icons";
|
|
36
37
|
import Layout from "../../components/Layout";
|
|
37
|
-
import Actions from "../../components/Actions";
|
|
38
38
|
import Section from "../../components/Section";
|
|
39
39
|
var loading = Symbol('loading');
|
|
40
40
|
export default function useBatchOperate(options) {
|
|
@@ -43,7 +43,9 @@ export default function useBatchOperate(options) {
|
|
|
43
43
|
handler = options.handler,
|
|
44
44
|
columns = options.columns,
|
|
45
45
|
onClose = options.onClose,
|
|
46
|
-
|
|
46
|
+
onBeforeClose = options.onBeforeClose,
|
|
47
|
+
rowKey = options.rowKey,
|
|
48
|
+
renderResult = options.renderResult;
|
|
47
49
|
|
|
48
50
|
var _useState = useState(false),
|
|
49
51
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -102,7 +104,7 @@ export default function useBatchOperate(options) {
|
|
|
102
104
|
}
|
|
103
105
|
};
|
|
104
106
|
|
|
105
|
-
var
|
|
107
|
+
var _reload = useThrottle( /*#__PURE__*/function () {
|
|
106
108
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(item, key) {
|
|
107
109
|
var res;
|
|
108
110
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
@@ -137,6 +139,7 @@ export default function useBatchOperate(options) {
|
|
|
137
139
|
return _ref.apply(this, arguments);
|
|
138
140
|
};
|
|
139
141
|
}(), 500);
|
|
142
|
+
|
|
140
143
|
var start = useThrottle( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
141
144
|
var i, item, key, res;
|
|
142
145
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
@@ -210,33 +213,70 @@ export default function useBatchOperate(options) {
|
|
|
210
213
|
setData(rows);
|
|
211
214
|
};
|
|
212
215
|
|
|
213
|
-
var handleClose = function
|
|
214
|
-
|
|
216
|
+
var handleClose = /*#__PURE__*/function () {
|
|
217
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
218
|
+
var beforeCloseResult;
|
|
219
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
220
|
+
while (1) {
|
|
221
|
+
switch (_context3.prev = _context3.next) {
|
|
222
|
+
case 0:
|
|
223
|
+
if (!onBeforeClose) {
|
|
224
|
+
_context3.next = 6;
|
|
225
|
+
break;
|
|
226
|
+
}
|
|
215
227
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
228
|
+
_context3.next = 3;
|
|
229
|
+
return onBeforeClose(results);
|
|
230
|
+
|
|
231
|
+
case 3:
|
|
232
|
+
beforeCloseResult = _context3.sent;
|
|
233
|
+
|
|
234
|
+
if (beforeCloseResult) {
|
|
235
|
+
_context3.next = 6;
|
|
236
|
+
break;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
return _context3.abrupt("return");
|
|
240
|
+
|
|
241
|
+
case 6:
|
|
242
|
+
setVisible(false);
|
|
243
|
+
|
|
244
|
+
if (onClose) {
|
|
245
|
+
onClose(results);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
case 8:
|
|
249
|
+
case "end":
|
|
250
|
+
return _context3.stop();
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}, _callee3);
|
|
254
|
+
}));
|
|
255
|
+
|
|
256
|
+
return function handleClose() {
|
|
257
|
+
return _ref3.apply(this, arguments);
|
|
258
|
+
};
|
|
259
|
+
}();
|
|
220
260
|
|
|
221
261
|
var mCols = useMemo(function () {
|
|
222
262
|
var cols = columns ? _toConsumableArray(columns) : [{
|
|
223
263
|
title: '编号',
|
|
224
264
|
colId: 'id',
|
|
225
265
|
dataIndex: typeof rowKey === 'string' ? rowKey : undefined,
|
|
226
|
-
render: function render(_1, _2, _3,
|
|
227
|
-
var node =
|
|
266
|
+
render: function render(_1, _2, _3, _ref4) {
|
|
267
|
+
var node = _ref4.node;
|
|
228
268
|
return node.id || '';
|
|
229
269
|
}
|
|
230
270
|
}];
|
|
231
271
|
cols.unshift({
|
|
232
272
|
title: '',
|
|
233
|
-
colId: '
|
|
273
|
+
colId: '__delete__',
|
|
234
274
|
width: 32,
|
|
235
|
-
render: function render(_1, _2, index,
|
|
236
|
-
var context =
|
|
237
|
-
node =
|
|
275
|
+
render: function render(_1, _2, index, _ref5) {
|
|
276
|
+
var context = _ref5.context,
|
|
277
|
+
node = _ref5.node;
|
|
238
278
|
var key = node.id;
|
|
239
|
-
return /*#__PURE__*/React.createElement(
|
|
279
|
+
return /*#__PURE__*/React.createElement(Icons.Delete, {
|
|
240
280
|
onClick: function onClick() {
|
|
241
281
|
if (!context.paused) {
|
|
242
282
|
return;
|
|
@@ -273,9 +313,9 @@ export default function useBatchOperate(options) {
|
|
|
273
313
|
dataIndex: 'status',
|
|
274
314
|
flex: 1,
|
|
275
315
|
resizable: false,
|
|
276
|
-
render: function render(_, record, index,
|
|
277
|
-
var context =
|
|
278
|
-
node =
|
|
316
|
+
render: function render(_, record, index, _ref6) {
|
|
317
|
+
var context = _ref6.context,
|
|
318
|
+
node = _ref6.node;
|
|
279
319
|
var key = node.id;
|
|
280
320
|
var result = context.results.get(key);
|
|
281
321
|
|
|
@@ -299,18 +339,41 @@ export default function useBatchOperate(options) {
|
|
|
299
339
|
type: "error"
|
|
300
340
|
}), /*#__PURE__*/React.createElement("span", null, " ", result.message, " "), /*#__PURE__*/React.createElement(ReloadOutlined, {
|
|
301
341
|
onClick: function onClick() {
|
|
302
|
-
return
|
|
342
|
+
return _reload(record, key);
|
|
303
343
|
}
|
|
304
344
|
}));
|
|
305
345
|
}
|
|
306
346
|
|
|
347
|
+
if (renderResult !== undefined) {
|
|
348
|
+
return renderResult({
|
|
349
|
+
data: record,
|
|
350
|
+
result: result,
|
|
351
|
+
elements: {
|
|
352
|
+
failIcon: /*#__PURE__*/React.createElement(Icons.Tip, {
|
|
353
|
+
type: "error"
|
|
354
|
+
}),
|
|
355
|
+
successIcon: /*#__PURE__*/React.createElement(Icons.Tip, {
|
|
356
|
+
type: "success"
|
|
357
|
+
}),
|
|
358
|
+
reloadButton: /*#__PURE__*/React.createElement(ReloadOutlined, {
|
|
359
|
+
onClick: function onClick() {
|
|
360
|
+
return _reload(record, key);
|
|
361
|
+
}
|
|
362
|
+
})
|
|
363
|
+
},
|
|
364
|
+
reload: function reload() {
|
|
365
|
+
_reload(record, key);
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
|
|
307
370
|
return /*#__PURE__*/React.createElement("span", null, /*#__PURE__*/React.createElement(Icons.Tip, {
|
|
308
371
|
type: "success"
|
|
309
|
-
}), /*#__PURE__*/React.createElement("span", null, " ", (result
|
|
372
|
+
}), /*#__PURE__*/React.createElement("span", null, " ", (typeof result === 'string' ? result : '操作成功').toString()));
|
|
310
373
|
}
|
|
311
374
|
});
|
|
312
375
|
return cols;
|
|
313
|
-
}, [columns, paused, active
|
|
376
|
+
}, [columns, paused, active]);
|
|
314
377
|
var node = /*#__PURE__*/React.createElement(Modal, {
|
|
315
378
|
title: modalTitle,
|
|
316
379
|
open: visible,
|
|
@@ -320,9 +383,8 @@ export default function useBatchOperate(options) {
|
|
|
320
383
|
footer: null,
|
|
321
384
|
maskClosable: false,
|
|
322
385
|
bodyStyle: {
|
|
323
|
-
height:
|
|
324
|
-
padding: 0
|
|
325
|
-
backgroundColor: '#f9f9f9'
|
|
386
|
+
height: 550,
|
|
387
|
+
padding: 0
|
|
326
388
|
},
|
|
327
389
|
afterClose: function afterClose() {
|
|
328
390
|
setResults(new Map());
|
|
@@ -333,7 +395,8 @@ export default function useBatchOperate(options) {
|
|
|
333
395
|
keyboard: false
|
|
334
396
|
}, /*#__PURE__*/React.createElement(Layout, {
|
|
335
397
|
header: /*#__PURE__*/React.createElement(Row, {
|
|
336
|
-
justify: "space-between"
|
|
398
|
+
justify: "space-between",
|
|
399
|
+
align: "middle"
|
|
337
400
|
}, /*#__PURE__*/React.createElement("span", null, "\u660E\u7EC6".concat(results.size > 0 ? "(".concat(results.size, "/").concat(data.length, ")") : '')), /*#__PURE__*/React.createElement(Actions, {
|
|
338
401
|
actions: [paused ? {
|
|
339
402
|
disabled: data.length <= 0 || results.size >= data.length,
|
package/es/index.d.ts
CHANGED
|
@@ -37,6 +37,7 @@ export type { ColDef, ColGroupDef, ColumnState, GridOptions, GridReadyEvent, ICe
|
|
|
37
37
|
export { GridApi, ColumnApi } from '@ag-grid-community/core';
|
|
38
38
|
export * from '@ag-grid-community/react';
|
|
39
39
|
export { default as TipMark } from './components/TipMark';
|
|
40
|
+
export { default as Portal } from './components/Portal';
|
|
40
41
|
export { default as BasicLayout } from './layouts/BasicLayout';
|
|
41
42
|
export { default as BlankLayout } from './layouts/BlankLayout';
|
|
42
43
|
export { default as MicroLayout } from './layouts/MicroLayout';
|
package/es/index.js
CHANGED
|
@@ -30,6 +30,7 @@ export * from "./components/DataGrid/hooks";
|
|
|
30
30
|
export { GridApi, ColumnApi } from '@ag-grid-community/core';
|
|
31
31
|
export * from '@ag-grid-community/react';
|
|
32
32
|
export { default as TipMark } from "./components/TipMark";
|
|
33
|
+
export { default as Portal } from "./components/Portal";
|
|
33
34
|
export { default as BasicLayout } from "./layouts/BasicLayout";
|
|
34
35
|
export { default as BlankLayout } from "./layouts/BlankLayout";
|
|
35
36
|
export { default as MicroLayout } from "./layouts/MicroLayout";
|