@lemon-fe/kits 1.0.2 → 1.0.3-0
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.js +9 -19
- package/es/components/DataGrid/index.less +1 -46
- package/es/components/DataGrid/renderer/Actions.d.ts +1 -0
- package/es/components/DataGrid/renderer/Actions.js +45 -84
- package/es/components/DataGrid/renderer/ActionsRenderer.d.ts +6 -0
- package/es/components/DataGrid/renderer/ActionsRenderer.js +46 -0
- package/es/components/DataGrid/typings.d.ts +5 -0
- package/package.json +1 -1
|
@@ -93,7 +93,7 @@ import { MasterDetailModule } from "./modules/master-detail/main";
|
|
|
93
93
|
import { MenuModule } from "./modules/menu/main";
|
|
94
94
|
import { RowGroupingModule } from "./modules/row-grouping/main";
|
|
95
95
|
import { SideBarModule } from "./modules/side-bar/main";
|
|
96
|
-
import
|
|
96
|
+
import ActionsRenderer from "./renderer/ActionsRenderer";
|
|
97
97
|
import CellIndexRender from "./renderer/CellIndexRenderer";
|
|
98
98
|
import CellRenderer from "./renderer/CellRenderer";
|
|
99
99
|
import DetailCellRenderer from "./renderer/DetailCellRenderer";
|
|
@@ -1302,36 +1302,26 @@ var DataGrid = /*#__PURE__*/function (_Component) {
|
|
|
1302
1302
|
}
|
|
1303
1303
|
|
|
1304
1304
|
if (rowActions !== undefined) {
|
|
1305
|
+
var _this$props$rowAction;
|
|
1306
|
+
|
|
1305
1307
|
leafColIds.push('$$actions');
|
|
1306
1308
|
result.push({
|
|
1307
1309
|
colId: '$$actions',
|
|
1308
1310
|
pinned: 'right',
|
|
1309
|
-
|
|
1310
|
-
width: 1,
|
|
1311
|
-
maxWidth: 1,
|
|
1312
|
-
headerName: '',
|
|
1311
|
+
headerName: '操作',
|
|
1313
1312
|
resizable: false,
|
|
1314
1313
|
sortable: false,
|
|
1315
1314
|
suppressAutoSize: true,
|
|
1316
1315
|
suppressMovable: true,
|
|
1316
|
+
suppressColumnsToolPanel: true,
|
|
1317
1317
|
lockPinned: true,
|
|
1318
1318
|
lockVisible: true,
|
|
1319
|
+
initialWidth: (_this$props$rowAction = this.props.rowActionsColumnWidth) !== null && _this$props$rowAction !== void 0 ? _this$props$rowAction : 160,
|
|
1319
1320
|
cellClass: prefix('operator-cell'),
|
|
1320
|
-
headerClass: prefix('operator-cell'),
|
|
1321
1321
|
cellRendererParams: {
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
if (actions !== undefined) {
|
|
1326
|
-
return /*#__PURE__*/React.createElement(Actions, {
|
|
1327
|
-
data: data,
|
|
1328
|
-
actions: actions
|
|
1329
|
-
});
|
|
1330
|
-
}
|
|
1331
|
-
|
|
1332
|
-
return null;
|
|
1333
|
-
}
|
|
1334
|
-
}
|
|
1322
|
+
actions: this.props.rowActions
|
|
1323
|
+
},
|
|
1324
|
+
cellRenderer: ActionsRenderer
|
|
1335
1325
|
});
|
|
1336
1326
|
}
|
|
1337
1327
|
|
|
@@ -350,43 +350,12 @@
|
|
|
350
350
|
}
|
|
351
351
|
|
|
352
352
|
&-operator {
|
|
353
|
-
position: absolute;
|
|
354
|
-
top: 4px;
|
|
355
|
-
right: 4px;
|
|
356
|
-
bottom: 4px;
|
|
357
|
-
z-index: 10;
|
|
358
|
-
display: none;
|
|
359
|
-
align-items: center;
|
|
360
|
-
justify-content: flex-end;
|
|
361
|
-
padding-left: 8px;
|
|
362
|
-
white-space: nowrap;
|
|
363
|
-
background-color: var(--ag-background-color);
|
|
364
|
-
|
|
365
|
-
.ag-row-hover & {
|
|
366
|
-
display: flex;
|
|
367
|
-
background-color: var(--ag-row-hover-color);
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
.ag-row-selected & {
|
|
371
|
-
background-color: var(--ag-selected-row-background-color);
|
|
372
|
-
}
|
|
373
|
-
|
|
374
353
|
&-cell {
|
|
375
354
|
display: flex;
|
|
376
355
|
align-items: center;
|
|
377
356
|
padding-right: 0;
|
|
378
357
|
padding-left: 0;
|
|
379
|
-
|
|
380
|
-
background-color: inherit;
|
|
381
|
-
border: none !important;
|
|
382
|
-
|
|
383
|
-
&::after {
|
|
384
|
-
display: none !important;
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
&-column {
|
|
389
|
-
border-right: none !important;
|
|
358
|
+
outline: none;
|
|
390
359
|
|
|
391
360
|
&::after {
|
|
392
361
|
display: none !important;
|
|
@@ -394,21 +363,12 @@
|
|
|
394
363
|
}
|
|
395
364
|
|
|
396
365
|
&-item {
|
|
397
|
-
margin-right: 8px;
|
|
398
366
|
padding: 0 8px;
|
|
399
367
|
color: @primary-color;
|
|
400
368
|
line-height: 28px;
|
|
401
369
|
background-color: transparent;
|
|
402
370
|
border: none;
|
|
403
|
-
border-radius: 4px;
|
|
404
|
-
outline: none;
|
|
405
371
|
cursor: pointer;
|
|
406
|
-
transition: background-color 0.2s;
|
|
407
|
-
user-select: none;
|
|
408
|
-
|
|
409
|
-
&:hover {
|
|
410
|
-
background-color: .primary(0.12) [];
|
|
411
|
-
}
|
|
412
372
|
|
|
413
373
|
&:active {
|
|
414
374
|
color: .primary(0.8) [];
|
|
@@ -417,10 +377,6 @@
|
|
|
417
377
|
&-disabled {
|
|
418
378
|
color: rgba(51, 51, 51, 0.5) !important;
|
|
419
379
|
cursor: not-allowed;
|
|
420
|
-
|
|
421
|
-
&:hover {
|
|
422
|
-
background-color: rgba(51, 51, 51, 0.06);
|
|
423
|
-
}
|
|
424
380
|
}
|
|
425
381
|
}
|
|
426
382
|
|
|
@@ -429,7 +385,6 @@
|
|
|
429
385
|
|
|
430
386
|
&-item {
|
|
431
387
|
text-align: left;
|
|
432
|
-
background-color: #fff;
|
|
433
388
|
border: none;
|
|
434
389
|
outline: none;
|
|
435
390
|
.popoverItem();
|
|
@@ -1,78 +1,34 @@
|
|
|
1
1
|
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; }
|
|
2
2
|
|
|
3
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
4
|
-
|
|
5
|
-
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."); }
|
|
6
|
-
|
|
7
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
8
|
-
|
|
9
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
10
|
-
|
|
11
|
-
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
12
|
-
|
|
13
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
14
|
-
|
|
15
|
-
import React, { useEffect, useRef, useState } from 'react';
|
|
16
3
|
import classNames from 'classnames';
|
|
17
|
-
import
|
|
4
|
+
import React from 'react';
|
|
18
5
|
import { prefixClassName } from "../../utils";
|
|
19
|
-
import
|
|
6
|
+
import Dropdown from "../../Dropdown";
|
|
7
|
+
import Icons from "../../Icons";
|
|
20
8
|
var prefix = prefixClassName('grid-operator');
|
|
21
9
|
|
|
22
10
|
var getKey = function getKey(item, idx) {
|
|
23
|
-
var key = item.key || (typeof item.
|
|
11
|
+
var key = item.key || (typeof item.label === 'string' ? item.label : idx);
|
|
24
12
|
return key;
|
|
25
13
|
};
|
|
26
14
|
|
|
27
15
|
function ActionItem(props) {
|
|
28
|
-
var item = props.item
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
var _useState = useState(false),
|
|
32
|
-
_useState2 = _slicedToArray(_useState, 2),
|
|
33
|
-
visible = _useState2[0],
|
|
34
|
-
setVisible = _useState2[1];
|
|
35
|
-
|
|
36
|
-
var dropDown = item.dropDown ? item.dropDown.filter(function (sub) {
|
|
37
|
-
return sub !== null;
|
|
38
|
-
}) : [];
|
|
16
|
+
var item = props.item;
|
|
17
|
+
var children = item.children || [];
|
|
39
18
|
var node = /*#__PURE__*/React.createElement("div", {
|
|
40
19
|
className: classNames(prefix('item'), _defineProperty({}, prefix("item-disabled"), item.disabled)),
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
20
|
+
onClick: item.onClick
|
|
21
|
+
}, item.label, children.length > 0 && /*#__PURE__*/React.createElement(Icons.Down, null));
|
|
22
|
+
|
|
23
|
+
if (children.length > 0) {
|
|
24
|
+
return /*#__PURE__*/React.createElement(Dropdown, {
|
|
25
|
+
trigger: 'click',
|
|
26
|
+
menu: {
|
|
27
|
+
items: children
|
|
28
|
+
},
|
|
29
|
+
overlayStyle: {
|
|
30
|
+
minWidth: 100
|
|
48
31
|
}
|
|
49
|
-
|
|
50
|
-
if (item.onClick) {
|
|
51
|
-
item.onClick(data);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}, item.text, dropDown.length > 0 && /*#__PURE__*/React.createElement(Icons.Down, null));
|
|
55
|
-
|
|
56
|
-
if (dropDown.length > 0) {
|
|
57
|
-
return /*#__PURE__*/React.createElement(Popover, {
|
|
58
|
-
placement: "bottomRight",
|
|
59
|
-
trigger: "click",
|
|
60
|
-
visible: visible,
|
|
61
|
-
onVisibleChange: setVisible,
|
|
62
|
-
overlayClassName: prefix('popover'),
|
|
63
|
-
content: dropDown.map(function (menu, idx) {
|
|
64
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
65
|
-
className: classNames(prefix("popover-item"), _defineProperty({}, prefix("popover-item-disabled"), item.disabled)),
|
|
66
|
-
key: getKey(menu, idx),
|
|
67
|
-
onClick: function onClick() {
|
|
68
|
-
if (!menu.disabled && menu.onClick) {
|
|
69
|
-
menu.onClick(data);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
setVisible(false);
|
|
73
|
-
}
|
|
74
|
-
}, menu.text);
|
|
75
|
-
})
|
|
76
32
|
}, node);
|
|
77
33
|
}
|
|
78
34
|
|
|
@@ -82,38 +38,43 @@ function ActionItem(props) {
|
|
|
82
38
|
export default function Actions(props) {
|
|
83
39
|
var data = props.data,
|
|
84
40
|
actionsProp = props.actions,
|
|
85
|
-
context = props.context
|
|
86
|
-
|
|
41
|
+
context = props.context,
|
|
42
|
+
_props$maxShowCount = props.maxShowCount,
|
|
43
|
+
maxShowCount = _props$maxShowCount === void 0 ? Infinity : _props$maxShowCount;
|
|
87
44
|
var actions = typeof actionsProp === 'function' ? actionsProp(data, context) : actionsProp;
|
|
88
|
-
useEffect(function () {
|
|
89
|
-
var node = ref.current;
|
|
90
45
|
|
|
46
|
+
var traverse = function traverse(node, idx) {
|
|
91
47
|
if (node === null) {
|
|
92
|
-
return;
|
|
48
|
+
return null;
|
|
93
49
|
}
|
|
94
50
|
|
|
95
|
-
var handler =
|
|
96
|
-
|
|
51
|
+
var handler = node.onClick;
|
|
52
|
+
return {
|
|
53
|
+
label: node.text,
|
|
54
|
+
key: node.key || idx.toString(),
|
|
55
|
+
onClick: handler ? function () {
|
|
56
|
+
return handler.call(node, data);
|
|
57
|
+
} : undefined,
|
|
58
|
+
disabled: node.disabled,
|
|
59
|
+
children: node.dropDown ? node.dropDown.map(function (subNode, subIdx) {
|
|
60
|
+
return traverse(subNode, subIdx);
|
|
61
|
+
}).filter(Boolean) : undefined
|
|
97
62
|
};
|
|
63
|
+
};
|
|
98
64
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}, actions.map(function (item, idx) {
|
|
108
|
-
if (item === null) {
|
|
109
|
-
return null;
|
|
110
|
-
}
|
|
65
|
+
var list = actions.map(traverse).filter(Boolean);
|
|
66
|
+
|
|
67
|
+
if (list.length > maxShowCount) {
|
|
68
|
+
list = list.slice(0, maxShowCount - 1).concat([{
|
|
69
|
+
label: '更多',
|
|
70
|
+
children: list.slice(maxShowCount - 1)
|
|
71
|
+
}]);
|
|
72
|
+
}
|
|
111
73
|
|
|
112
|
-
|
|
74
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, list.map(function (item, idx) {
|
|
113
75
|
return /*#__PURE__*/React.createElement(ActionItem, {
|
|
114
|
-
key:
|
|
115
|
-
item: item
|
|
116
|
-
data: data
|
|
76
|
+
key: getKey(item, idx),
|
|
77
|
+
item: item
|
|
117
78
|
});
|
|
118
79
|
}));
|
|
119
80
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { ICellRendererParams } from '@ag-grid-community/core';
|
|
3
|
+
import type { RowActionsType } from '../typings';
|
|
4
|
+
export default function ActionsRenderer<TData>(props: ICellRendererParams<TData> & {
|
|
5
|
+
actions: RowActionsType<TData>;
|
|
6
|
+
}): JSX.Element | null;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
+
|
|
3
|
+
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."); }
|
|
4
|
+
|
|
5
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
6
|
+
|
|
7
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
8
|
+
|
|
9
|
+
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
10
|
+
|
|
11
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
12
|
+
|
|
13
|
+
import React, { useEffect, useState } from 'react';
|
|
14
|
+
import DataGrid from "../index";
|
|
15
|
+
import Actions from "./Actions";
|
|
16
|
+
export default function ActionsRenderer(props) {
|
|
17
|
+
var actions = props.actions,
|
|
18
|
+
node = props.node;
|
|
19
|
+
|
|
20
|
+
var _useState = useState(node.data),
|
|
21
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
22
|
+
data = _useState2[0],
|
|
23
|
+
setData = _useState2[1];
|
|
24
|
+
|
|
25
|
+
useEffect(function () {
|
|
26
|
+
var handler = function handler(evt) {
|
|
27
|
+
setData(evt.newData);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
node.addEventListener('dataChanged', handler);
|
|
31
|
+
return function () {
|
|
32
|
+
node.removeEventListener('dataChanged', handler);
|
|
33
|
+
};
|
|
34
|
+
}, []);
|
|
35
|
+
|
|
36
|
+
if (DataGrid.isSummaryRow({
|
|
37
|
+
node: node
|
|
38
|
+
}) || !data) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return /*#__PURE__*/React.createElement(Actions, {
|
|
43
|
+
data: data,
|
|
44
|
+
actions: actions
|
|
45
|
+
});
|
|
46
|
+
}
|
|
@@ -185,6 +185,11 @@ export interface DataGridProps<TData> extends Omit<AgGridReactProps<TData>, 'row
|
|
|
185
185
|
* @description 行操作按钮组
|
|
186
186
|
*/
|
|
187
187
|
rowActions?: RowActionsType<TData>;
|
|
188
|
+
/**
|
|
189
|
+
*
|
|
190
|
+
* @description 行操作按钮组列宽
|
|
191
|
+
*/
|
|
192
|
+
rowActionsColumnWidth?: number;
|
|
188
193
|
/**
|
|
189
194
|
* @description 加载动画
|
|
190
195
|
*/
|