@lemon-fe/kits 1.0.0-33 → 1.0.0-35
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/cell-editors/Custom.d.ts +2 -0
- package/es/components/DataGrid/cell-editors/Custom.js +28 -7
- package/es/components/DataGrid/cell-editors/Date.js +19 -2
- package/es/components/DataGrid/cell-editors/Number.js +13 -9
- package/es/components/DataGrid/cell-editors/Select.js +9 -11
- package/es/components/DataGrid/cell-editors/Text.js +10 -7
- package/es/components/DataGrid/cell-editors/Wrapper.d.ts +2 -1
- package/es/components/DataGrid/cell-editors/Wrapper.js +4 -2
- package/es/components/DataGrid/index.js +15 -1
- package/es/components/DataGrid/typings.d.ts +0 -1
- package/package.json +1 -1
- package/es/components/DataGrid/cell-editors/Combination.d.ts +0 -8
- package/es/components/DataGrid/cell-editors/Combination.js +0 -25
|
@@ -3,6 +3,8 @@ import React from 'react';
|
|
|
3
3
|
import type { ICellEditorReactComp } from '@ag-grid-community/react';
|
|
4
4
|
import type { ICellEditorParams } from '@ag-grid-community/core';
|
|
5
5
|
export interface CustomEditorParams<T = any, K = any> {
|
|
6
|
+
suppressEnterEvent?: boolean;
|
|
7
|
+
isCancelAfterEnd?: (prevValue: T, nextValue: T) => boolean;
|
|
6
8
|
render: (val: K, data: T, params: ICellEditorParams<T, K> & {
|
|
7
9
|
ref: MutableRefObject<{
|
|
8
10
|
select?: () => void;
|
|
@@ -23,11 +23,11 @@ import EditorWrapper from "./Wrapper";
|
|
|
23
23
|
import { useGridStore } from "../hooks";
|
|
24
24
|
export default /*#__PURE__*/forwardRef(function CustomEditor(props, ref) {
|
|
25
25
|
var api = props.api,
|
|
26
|
-
|
|
26
|
+
suppressEnterEvent = props.suppressEnterEvent,
|
|
27
27
|
stopEditing = props.stopEditing,
|
|
28
28
|
data = props.data,
|
|
29
29
|
render = props.render,
|
|
30
|
-
|
|
30
|
+
isCancelAfterEnd = props.isCancelAfterEnd,
|
|
31
31
|
field = props.colDef.field;
|
|
32
32
|
|
|
33
33
|
var _useState = useState(data),
|
|
@@ -40,23 +40,38 @@ export default /*#__PURE__*/forwardRef(function CustomEditor(props, ref) {
|
|
|
40
40
|
});
|
|
41
41
|
var elm = useRef(null);
|
|
42
42
|
useEffect(function () {
|
|
43
|
-
if (
|
|
43
|
+
if (elm.current !== null) {
|
|
44
44
|
if (elm.current.select !== undefined) {
|
|
45
45
|
elm.current.select();
|
|
46
46
|
} else if (elm.current.focus !== undefined) {
|
|
47
47
|
elm.current.focus();
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
|
-
}, [
|
|
50
|
+
}, []);
|
|
51
51
|
useImperativeHandle(ref, function () {
|
|
52
52
|
return {
|
|
53
53
|
getValue: function getValue() {
|
|
54
54
|
var newData = _objectSpread(_objectSpread({}, data), value);
|
|
55
55
|
|
|
56
|
+
var prevValue = props.value;
|
|
57
|
+
var nextValue = prevValue;
|
|
58
|
+
|
|
59
|
+
if (field === undefined) {
|
|
60
|
+
return prevValue;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
nextValue = get(value, field);
|
|
64
|
+
|
|
65
|
+
if (nextValue == prevValue || isCancelAfterEnd !== undefined && isCancelAfterEnd(data, newData)) {
|
|
66
|
+
return prevValue;
|
|
67
|
+
}
|
|
68
|
+
|
|
56
69
|
requestAnimationFrame(function () {
|
|
57
|
-
|
|
70
|
+
api.applyTransaction({
|
|
71
|
+
update: [newData]
|
|
72
|
+
});
|
|
58
73
|
});
|
|
59
|
-
return
|
|
74
|
+
return prevValue;
|
|
60
75
|
}
|
|
61
76
|
};
|
|
62
77
|
});
|
|
@@ -78,7 +93,13 @@ export default /*#__PURE__*/forwardRef(function CustomEditor(props, ref) {
|
|
|
78
93
|
}
|
|
79
94
|
};
|
|
80
95
|
|
|
81
|
-
return /*#__PURE__*/React.createElement(EditorWrapper,
|
|
96
|
+
return /*#__PURE__*/React.createElement(EditorWrapper, {
|
|
97
|
+
onKeyDown: function onKeyDown(e) {
|
|
98
|
+
if (!suppressEnterEvent && e.key === 'Enter') {
|
|
99
|
+
api.tabToNextCell();
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}, render(field ? get(value, field) : props.value, data, _objectSpread(_objectSpread({}, props), {}, {
|
|
82
103
|
context: context,
|
|
83
104
|
ref: elm,
|
|
84
105
|
onChange: handleChange
|
|
@@ -20,7 +20,8 @@ export default /*#__PURE__*/forwardRef(function DateEditor(props, ref) {
|
|
|
20
20
|
var cellStartedEdit = props.cellStartedEdit,
|
|
21
21
|
_props$format = props.format,
|
|
22
22
|
format = _props$format === void 0 ? 'YYYY-MM-DD' : _props$format,
|
|
23
|
-
disabled = props.disabled
|
|
23
|
+
disabled = props.disabled,
|
|
24
|
+
api = props.api;
|
|
24
25
|
|
|
25
26
|
var _useState = useState(props.value ? moment(props.value, format) : null),
|
|
26
27
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -28,6 +29,7 @@ export default /*#__PURE__*/forwardRef(function DateEditor(props, ref) {
|
|
|
28
29
|
setValue = _useState2[1];
|
|
29
30
|
|
|
30
31
|
var elm = useRef(null);
|
|
32
|
+
var isEdited = useRef(false);
|
|
31
33
|
useEffect(function () {
|
|
32
34
|
if (cellStartedEdit) {
|
|
33
35
|
var _elm$current;
|
|
@@ -45,7 +47,13 @@ export default /*#__PURE__*/forwardRef(function DateEditor(props, ref) {
|
|
|
45
47
|
getValue: getValue
|
|
46
48
|
};
|
|
47
49
|
});
|
|
48
|
-
return /*#__PURE__*/React.createElement(EditorWrapper,
|
|
50
|
+
return /*#__PURE__*/React.createElement(EditorWrapper, {
|
|
51
|
+
onKeyDown: function onKeyDown(e) {
|
|
52
|
+
if (isEdited.current && e.key === 'Enter') {
|
|
53
|
+
api.tabToNextCell();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}, /*#__PURE__*/React.createElement(DatePicker, {
|
|
49
57
|
style: {
|
|
50
58
|
display: 'flex',
|
|
51
59
|
paddingTop: 0,
|
|
@@ -55,12 +63,21 @@ export default /*#__PURE__*/forwardRef(function DateEditor(props, ref) {
|
|
|
55
63
|
className: editorPrefixClass('date'),
|
|
56
64
|
value: value,
|
|
57
65
|
placeholder: format,
|
|
66
|
+
onOpenChange: function onOpenChange(val) {
|
|
67
|
+
if (!val) {
|
|
68
|
+
isEdited.current = true;
|
|
69
|
+
}
|
|
70
|
+
},
|
|
58
71
|
onChange: function onChange(val) {
|
|
59
72
|
if (val) {
|
|
60
73
|
setValue(val);
|
|
61
74
|
} else {
|
|
62
75
|
setValue(null);
|
|
63
76
|
}
|
|
77
|
+
|
|
78
|
+
requestAnimationFrame(function () {
|
|
79
|
+
api.tabToNextCell();
|
|
80
|
+
});
|
|
64
81
|
},
|
|
65
82
|
ref: elm,
|
|
66
83
|
bordered: false
|
|
@@ -17,14 +17,14 @@ import { editorPrefixClass } from "./utils";
|
|
|
17
17
|
export default /*#__PURE__*/forwardRef(function NumberEditor(props, ref) {
|
|
18
18
|
var _props$value;
|
|
19
19
|
|
|
20
|
-
var
|
|
21
|
-
_props$min = props.min,
|
|
20
|
+
var _props$min = props.min,
|
|
22
21
|
min = _props$min === void 0 ? -99999999 : _props$min,
|
|
23
22
|
_props$max = props.max,
|
|
24
23
|
max = _props$max === void 0 ? 99999999 : _props$max,
|
|
25
24
|
emptyValue = props.emptyValue,
|
|
26
25
|
undoWhenError = props.undoWhenError,
|
|
27
|
-
disabled = props.disabled
|
|
26
|
+
disabled = props.disabled,
|
|
27
|
+
api = props.api;
|
|
28
28
|
|
|
29
29
|
var _useState = useState((_props$value = props.value) !== null && _props$value !== void 0 ? _props$value : null),
|
|
30
30
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -33,12 +33,10 @@ export default /*#__PURE__*/forwardRef(function NumberEditor(props, ref) {
|
|
|
33
33
|
|
|
34
34
|
var elm = useRef(null);
|
|
35
35
|
useEffect(function () {
|
|
36
|
-
|
|
37
|
-
var _elm$current;
|
|
36
|
+
var _elm$current;
|
|
38
37
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}, [cellStartedEdit]);
|
|
38
|
+
(_elm$current = elm.current) === null || _elm$current === void 0 ? void 0 : _elm$current.select();
|
|
39
|
+
}, []);
|
|
42
40
|
|
|
43
41
|
var getValue = function getValue() {
|
|
44
42
|
var val;
|
|
@@ -74,7 +72,13 @@ export default /*#__PURE__*/forwardRef(function NumberEditor(props, ref) {
|
|
|
74
72
|
getValue: getValue
|
|
75
73
|
};
|
|
76
74
|
});
|
|
77
|
-
return /*#__PURE__*/React.createElement(EditorWrapper,
|
|
75
|
+
return /*#__PURE__*/React.createElement(EditorWrapper, {
|
|
76
|
+
onKeyDown: function onKeyDown(e) {
|
|
77
|
+
if (e.key === 'Enter') {
|
|
78
|
+
api.tabToNextCell();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}, /*#__PURE__*/React.createElement("input", {
|
|
78
82
|
type: "number",
|
|
79
83
|
disabled: disabled,
|
|
80
84
|
className: editorPrefixClass('text'),
|
|
@@ -18,10 +18,8 @@ import { Select } from 'antd';
|
|
|
18
18
|
import EditorWrapper from "./Wrapper";
|
|
19
19
|
import { editorPrefixClass } from "./utils";
|
|
20
20
|
export default /*#__PURE__*/forwardRef(function SelectEditor(props, ref) {
|
|
21
|
-
var
|
|
22
|
-
|
|
23
|
-
column = props.column,
|
|
24
|
-
node = props.node;
|
|
21
|
+
var cellEditorParams = props.colDef.cellEditorParams,
|
|
22
|
+
api = props.api;
|
|
25
23
|
|
|
26
24
|
var _useState = useState(props.value),
|
|
27
25
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -30,12 +28,10 @@ export default /*#__PURE__*/forwardRef(function SelectEditor(props, ref) {
|
|
|
30
28
|
|
|
31
29
|
var elm = useRef(null);
|
|
32
30
|
useEffect(function () {
|
|
33
|
-
|
|
34
|
-
var _elm$current;
|
|
31
|
+
var _elm$current;
|
|
35
32
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}, [cellStartedEdit]);
|
|
33
|
+
(_elm$current = elm.current) === null || _elm$current === void 0 ? void 0 : _elm$current.focus();
|
|
34
|
+
}, []);
|
|
39
35
|
useImperativeHandle(ref, function () {
|
|
40
36
|
return {
|
|
41
37
|
getValue: function getValue() {
|
|
@@ -49,9 +45,11 @@ export default /*#__PURE__*/forwardRef(function SelectEditor(props, ref) {
|
|
|
49
45
|
className: editorPrefixClass('select')
|
|
50
46
|
}, cellEditorParams, {
|
|
51
47
|
value: value,
|
|
52
|
-
|
|
48
|
+
onSelect: function onSelect(val) {
|
|
53
49
|
setValue(val);
|
|
54
|
-
|
|
50
|
+
requestAnimationFrame(function () {
|
|
51
|
+
api.tabToNextCell();
|
|
52
|
+
});
|
|
55
53
|
}
|
|
56
54
|
})));
|
|
57
55
|
});
|
|
@@ -15,8 +15,8 @@ import { forwardRef, useImperativeHandle, useState } from 'react';
|
|
|
15
15
|
import EditorWrapper from "./Wrapper";
|
|
16
16
|
import { editorPrefixClass } from "./utils";
|
|
17
17
|
export default /*#__PURE__*/forwardRef(function TextEditor(props, ref) {
|
|
18
|
-
var
|
|
19
|
-
|
|
18
|
+
var disabled = props.disabled,
|
|
19
|
+
api = props.api;
|
|
20
20
|
|
|
21
21
|
var _useState = useState(props.value),
|
|
22
22
|
_useState2 = _slicedToArray(_useState, 2),
|
|
@@ -25,12 +25,10 @@ export default /*#__PURE__*/forwardRef(function TextEditor(props, ref) {
|
|
|
25
25
|
|
|
26
26
|
var elm = useRef(null);
|
|
27
27
|
useEffect(function () {
|
|
28
|
-
|
|
29
|
-
var _elm$current;
|
|
28
|
+
var _elm$current;
|
|
30
29
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}, [cellStartedEdit]);
|
|
30
|
+
(_elm$current = elm.current) === null || _elm$current === void 0 ? void 0 : _elm$current.select();
|
|
31
|
+
}, []);
|
|
34
32
|
useImperativeHandle(ref, function () {
|
|
35
33
|
return {
|
|
36
34
|
getValue: function getValue() {
|
|
@@ -39,6 +37,11 @@ export default /*#__PURE__*/forwardRef(function TextEditor(props, ref) {
|
|
|
39
37
|
};
|
|
40
38
|
});
|
|
41
39
|
return /*#__PURE__*/React.createElement(EditorWrapper, null, /*#__PURE__*/React.createElement("input", {
|
|
40
|
+
onKeyDown: function onKeyDown(e) {
|
|
41
|
+
if (e.key === 'Enter') {
|
|
42
|
+
api.tabToNextCell();
|
|
43
|
+
}
|
|
44
|
+
},
|
|
42
45
|
disabled: disabled,
|
|
43
46
|
className: editorPrefixClass('text'),
|
|
44
47
|
ref: elm,
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
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); }
|
|
2
|
+
|
|
1
3
|
import React from 'react';
|
|
2
4
|
import { editorPrefixClass } from "./utils";
|
|
3
5
|
export default function EditorWrapper(props) {
|
|
4
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
6
|
+
return /*#__PURE__*/React.createElement("div", _extends({
|
|
5
7
|
className: editorPrefixClass()
|
|
6
|
-
}, props
|
|
8
|
+
}, props));
|
|
7
9
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
var _excluded = ["validator"],
|
|
2
|
-
_excluded2 = ["title", "key", "dataIndex", "align", "type", "fixed", "render", "ellipsis", "cellRenderer", "cellRendererParams", "className", "sorter", "editable"],
|
|
2
|
+
_excluded2 = ["title", "key", "dataIndex", "align", "type", "fixed", "render", "ellipsis", "cellRenderer", "cellRendererParams", "className", "sorter", "editable", "suppressKeyboardEvent"],
|
|
3
3
|
_excluded3 = ["title", "children"],
|
|
4
4
|
_excluded4 = ["rowSelection", "rowKey", "fetch", "dataSource", "summary", "rowActions", "context", "onGridReady", "pagination", "columnTypes", "defaultColDef", "components", "columns", "loading", "autoLoad", "sideBar"];
|
|
5
5
|
|
|
@@ -494,6 +494,7 @@ var DataGrid = /*#__PURE__*/function (_Component) {
|
|
|
494
494
|
className = item.className,
|
|
495
495
|
sorter = item.sorter,
|
|
496
496
|
editable = item.editable,
|
|
497
|
+
suppressKeyboardEvent = item.suppressKeyboardEvent,
|
|
497
498
|
_rest = _objectWithoutProperties(item, _excluded2);
|
|
498
499
|
|
|
499
500
|
var _opts = {
|
|
@@ -562,6 +563,19 @@ var DataGrid = /*#__PURE__*/function (_Component) {
|
|
|
562
563
|
_opts.cellClassRules = _defineProperty({}, prefix('editor-cell'), function () {
|
|
563
564
|
return true;
|
|
564
565
|
});
|
|
566
|
+
/** 由于ag-grid注册事件使用的是js原生事件,不在React事件流内,会产生很多问题,所以默认关闭所有Enter导致关闭编辑,由组件内部自行实现回车 */
|
|
567
|
+
|
|
568
|
+
_opts.suppressKeyboardEvent = function (keyParmas) {
|
|
569
|
+
if (suppressKeyboardEvent !== undefined && suppressKeyboardEvent(keyParmas)) {
|
|
570
|
+
return true;
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
if (keyParmas.editing && keyParmas.event.key === 'Enter') {
|
|
574
|
+
return true;
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
return false;
|
|
578
|
+
};
|
|
565
579
|
|
|
566
580
|
if (_opts.cellRenderer === undefined) {
|
|
567
581
|
_opts.cellRenderer = CellRenderer;
|
|
@@ -11,7 +11,6 @@ export type { TextEditorParams } from './cell-editors/Text';
|
|
|
11
11
|
export type { NumberEditorParams } from './cell-editors/Number';
|
|
12
12
|
export type { DateEditorParams } from './cell-editors/Date';
|
|
13
13
|
export type { SelectEditorParams } from './cell-editors/Select';
|
|
14
|
-
export type { CombinationEditorParams } from './cell-editors/Combination';
|
|
15
14
|
export type { CustomEditorParams } from './cell-editors/Custom';
|
|
16
15
|
export declare type GetRowId<T> = string | ((data: T) => string);
|
|
17
16
|
export declare type PathType = string | (string | number)[];
|
package/package.json
CHANGED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { ICellEditorReactComp } from '@ag-grid-community/react';
|
|
2
|
-
import type { ICellEditorParams } from '@ag-grid-community/core';
|
|
3
|
-
import { type ForwardedRef, type ReactElement } from 'react';
|
|
4
|
-
export interface CombinationEditorParams<T = any> {
|
|
5
|
-
render: (props: ICellEditorParams<T>, ref: ForwardedRef<ICellEditorReactComp>) => ReactElement | null;
|
|
6
|
-
}
|
|
7
|
-
declare const _default: import("react").ForwardRefExoticComponent<ICellEditorParams<any, any> & CombinationEditorParams<any> & import("react").RefAttributes<ICellEditorReactComp>>;
|
|
8
|
-
export default _default;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
var _excluded = ["render"];
|
|
2
|
-
|
|
3
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
4
|
-
|
|
5
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
6
|
-
|
|
7
|
-
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; }
|
|
8
|
-
|
|
9
|
-
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
10
|
-
|
|
11
|
-
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
12
|
-
|
|
13
|
-
import { forwardRef } from 'react';
|
|
14
|
-
import { useGridStore } from "../hooks";
|
|
15
|
-
export default /*#__PURE__*/forwardRef(function CombinationEditor(props, ref) {
|
|
16
|
-
var render = props.render,
|
|
17
|
-
restProps = _objectWithoutProperties(props, _excluded);
|
|
18
|
-
|
|
19
|
-
var context = useGridStore(function (state) {
|
|
20
|
-
return state.context;
|
|
21
|
-
});
|
|
22
|
-
return render(_objectSpread(_objectSpread({}, restProps), {}, {
|
|
23
|
-
context: context
|
|
24
|
-
}), ref);
|
|
25
|
-
});
|