@lemon-fe/kits 1.0.0-5 → 1.0.0-50

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.
Files changed (110) hide show
  1. package/es/components/Actions/index.d.ts +2 -2
  2. package/es/components/Actions/index.js +13 -8
  3. package/es/components/BaseTable/Actions.js +2 -2
  4. package/es/components/BaseTable/VirtualBody.js +2 -2
  5. package/es/components/BaseTable/index.js +2 -2
  6. package/es/components/BaseTable/utils.d.ts +1 -1
  7. package/es/components/DataGrid/cell-editors/Date.d.ts +1 -0
  8. package/es/components/DataGrid/cell-editors/Date.js +24 -21
  9. package/es/components/DataGrid/cell-editors/Number.d.ts +19 -0
  10. package/es/components/DataGrid/cell-editors/Number.js +43 -30
  11. package/es/components/DataGrid/cell-editors/Row.d.ts +22 -0
  12. package/es/components/DataGrid/cell-editors/Row.js +124 -0
  13. package/es/components/DataGrid/cell-editors/Select.d.ts +21 -3
  14. package/es/components/DataGrid/cell-editors/Select.js +61 -29
  15. package/es/components/DataGrid/cell-editors/Text.d.ts +4 -1
  16. package/es/components/DataGrid/cell-editors/Text.js +11 -18
  17. package/es/components/DataGrid/cell-editors/Wrapper.d.ts +2 -1
  18. package/es/components/DataGrid/cell-editors/Wrapper.js +4 -2
  19. package/es/components/DataGrid/context/GridStore.d.ts +4 -0
  20. package/es/components/DataGrid/context/GridStore.js +4 -0
  21. package/es/components/DataGrid/hooks.js +2 -2
  22. package/es/components/DataGrid/index.d.ts +21 -19
  23. package/es/components/DataGrid/index.js +385 -272
  24. package/es/components/DataGrid/index.less +73 -31
  25. package/es/components/DataGrid/modules/client-side-row-model/clientSideRowModel/clientSideNodeManager.d.ts +33 -55
  26. package/es/components/DataGrid/modules/client-side-row-model/clientSideRowModel/clientSideNodeManager.js +1 -1
  27. package/es/components/DataGrid/modules/client-side-row-model/clientSideRowModel/clientSideRowModel.d.ts +93 -114
  28. package/es/components/DataGrid/modules/client-side-row-model/clientSideRowModel/clientSideRowModel.js +19 -19
  29. package/es/components/DataGrid/modules/client-side-row-model/clientSideRowModel/filterService.d.ts +5 -5
  30. package/es/components/DataGrid/modules/client-side-row-model/clientSideRowModel/filterService.js +4 -4
  31. package/es/components/DataGrid/modules/client-side-row-model/clientSideRowModel/filterStage.d.ts +3 -3
  32. package/es/components/DataGrid/modules/client-side-row-model/clientSideRowModel/filterStage.js +3 -3
  33. package/es/components/DataGrid/modules/client-side-row-model/clientSideRowModel/flattenStage.d.ts +8 -8
  34. package/es/components/DataGrid/modules/client-side-row-model/clientSideRowModel/flattenStage.js +6 -6
  35. package/es/components/DataGrid/modules/client-side-row-model/clientSideRowModel/immutableService.d.ts +11 -11
  36. package/es/components/DataGrid/modules/client-side-row-model/clientSideRowModel/immutableService.js +8 -8
  37. package/es/components/DataGrid/modules/client-side-row-model/clientSideRowModel/sortService.d.ts +12 -19
  38. package/es/components/DataGrid/modules/client-side-row-model/clientSideRowModel/sortService.js +5 -5
  39. package/es/components/DataGrid/modules/client-side-row-model/clientSideRowModel/sortStage.d.ts +5 -5
  40. package/es/components/DataGrid/modules/client-side-row-model/clientSideRowModel/sortStage.js +7 -7
  41. package/es/components/DataGrid/modules/client-side-row-model/clientSideRowModelModule.d.ts +2 -15
  42. package/es/components/DataGrid/modules/client-side-row-model/clientSideRowModelModule.js +1 -1
  43. package/es/components/DataGrid/modules/client-side-row-model/index.d.ts +1 -1
  44. package/es/components/DataGrid/{Actions.d.ts → renderer/Actions.d.ts} +1 -1
  45. package/es/components/DataGrid/{Actions.js → renderer/Actions.js} +4 -4
  46. package/es/components/DataGrid/renderer/CellIndexRenderer.d.ts +2 -0
  47. package/es/components/DataGrid/renderer/CellIndexRenderer.js +46 -0
  48. package/es/components/DataGrid/{CellRenderer.d.ts → renderer/CellRenderer.d.ts} +2 -2
  49. package/es/components/DataGrid/{CellRenderer.js → renderer/CellRenderer.js} +3 -3
  50. package/es/components/DataGrid/{HeaderRenderer.d.ts → renderer/HeaderRenderer.d.ts} +3 -3
  51. package/es/components/DataGrid/{HeaderRenderer.js → renderer/HeaderRenderer.js} +1 -2
  52. package/es/components/DataGrid/typings.d.ts +48 -35
  53. package/es/components/DataGrid/utils.d.ts +6 -4
  54. package/es/components/DataGrid/utils.js +34 -8
  55. package/es/components/Dropdown/index.js +2 -2
  56. package/es/components/EditableTable/EditableCell.d.ts +1 -1
  57. package/es/components/EditableTable/EditableTableFormItem.d.ts +1 -1
  58. package/es/components/EditableTable/Table.d.ts +1 -1
  59. package/es/components/EditableTable/Table.js +5 -5
  60. package/es/components/EditableTable/typings.d.ts +1 -1
  61. package/es/components/Filter/index.js +9 -8
  62. package/es/components/FormLayout/index.d.ts +1 -0
  63. package/es/components/FormLayout/index.js +19 -7
  64. package/es/components/FormLayout/index.less +10 -3
  65. package/es/components/Icons/BigTip/index.d.ts +1 -1
  66. package/es/components/Icons/Calendar.d.ts +1 -1
  67. package/es/components/Icons/Close.d.ts +1 -1
  68. package/es/components/Icons/CollapseUp.d.ts +1 -1
  69. package/es/components/Icons/DarkSearch.d.ts +1 -1
  70. package/es/components/Icons/Down.d.ts +1 -1
  71. package/es/components/Icons/LookUp.d.ts +1 -1
  72. package/es/components/Icons/More.d.ts +1 -1
  73. package/es/components/Icons/Search.d.ts +1 -1
  74. package/es/components/Icons/Tip.d.ts +1 -1
  75. package/es/components/Layout/index.less +0 -3
  76. package/es/components/Popup/index.d.ts +24 -11
  77. package/es/components/Popup/index.js +62 -50
  78. package/es/components/Section/index.d.ts +1 -1
  79. package/es/components/Section/index.js +1 -1
  80. package/es/components/SelectView/index.d.ts +8 -3
  81. package/es/components/SelectView/index.js +36 -16
  82. package/es/components/SelectView/index.less +3 -7
  83. package/es/components/SiderTree/index.d.ts +3 -11
  84. package/es/components/SiderTree/index.js +2 -4
  85. package/es/components/SiderTree/index.less +97 -114
  86. package/es/components/SiderTree/typings.d.ts +2 -2
  87. package/es/components/TabBar/index.d.ts +1 -2
  88. package/es/components/TabBar/index.less +6 -3
  89. package/es/components/Table/typings.d.ts +1 -2
  90. package/es/components/Table/utils.d.ts +1 -1
  91. package/es/hooks/useBatchOperator/index.d.ts +3 -3
  92. package/es/hooks/useBatchOperator/index.js +103 -104
  93. package/es/index.d.ts +5 -0
  94. package/es/index.js +2 -0
  95. package/es/init.js +16 -2
  96. package/es/layouts/BasicLayout/components/MainFramework/components/Menu/index.js +23 -22
  97. package/es/layouts/BasicLayout/typings.d.ts +3 -3
  98. package/es/layouts/Breadcrumb/index.js +1 -1
  99. package/es/layouts/MicroLayout/typings.d.ts +1 -1
  100. package/es/layouts/typings.d.ts +0 -2
  101. package/es/layouts/utils.js +2 -2
  102. package/es/styles/empty.png +0 -0
  103. package/es/styles/overrides.less +10 -0
  104. package/es/styles/utils.less +2 -2
  105. package/package.json +3 -5
  106. package/es/components/DataGrid/GridContext.d.ts +0 -4
  107. package/es/components/DataGrid/GridContext.js +0 -4
  108. package/es/components/DataGrid/cell-editors/Custom.d.ts +0 -9
  109. package/es/components/DataGrid/cell-editors/Custom.js +0 -105
  110. package/es/components/DataGrid/empty.png +0 -0
@@ -1,6 +1,6 @@
1
- import { ReactElement } from 'react';
1
+ import { type ReactElement } from 'react';
2
2
  import type { CSSProperties } from 'react';
3
- import { ButtonProps } from 'antd';
3
+ import { type ButtonProps } from 'antd';
4
4
  interface ActionBtn extends ButtonProps {
5
5
  text: string | ReactElement;
6
6
  onClick?: () => void;
@@ -89,21 +89,26 @@ function Actions(props) {
89
89
  }));
90
90
 
91
91
  if (handleClick !== undefined) {
92
- return /*#__PURE__*/React.createElement(Dropdown.Button, {
92
+ return /*#__PURE__*/React.createElement(Dropdown.Button, _extends({
93
93
  key: text,
94
94
  disabled: disabled,
95
95
  overlay: overlay,
96
96
  onClick: handleClick,
97
+ trigger: ['click'],
98
+ overlayStyle: {
99
+ minWidth: 80
100
+ },
97
101
  buttonsRender: function buttonsRender(_ref) {
98
- var _ref2 = _slicedToArray(_ref, 2),
99
- leftBtn = _ref2[0],
100
- _ = _ref2[1];
102
+ var _ref2 = _slicedToArray(_ref, 1),
103
+ leftBtn = _ref2[0];
101
104
 
102
105
  return [leftBtn, /*#__PURE__*/React.createElement(Button, {
103
- icon: /*#__PURE__*/React.createElement(Icons.More, null)
106
+ icon: /*#__PURE__*/React.createElement(Icons.More, null),
107
+ type: rest.type,
108
+ key: "more"
104
109
  })];
105
110
  }
106
- }, text);
111
+ }, rest), text);
107
112
  }
108
113
 
109
114
  return /*#__PURE__*/React.createElement(Dropdown, {
@@ -131,8 +136,8 @@ function Actions(props) {
131
136
  }), collapsedBtns.length > 0 ? /*#__PURE__*/React.createElement(Popover, {
132
137
  placement: "bottomRight",
133
138
  overlayClassName: "".concat(prefixCls, "-actions-popover"),
134
- onVisibleChange: setVisible,
135
- visible: visible,
139
+ onOpenChange: setVisible,
140
+ open: visible,
136
141
  trigger: "click",
137
142
  content: collapsedBtns.map(function (item, index) {
138
143
  if (item === null) {
@@ -77,8 +77,8 @@ export default function Actions(props) {
77
77
  }
78
78
 
79
79
  var key = getKey(item, idx);
80
- var dropDown = item.dropDown ? item.dropDown.filter(function (item) {
81
- return item !== null;
80
+ var dropDown = item.dropDown ? item.dropDown.filter(function (sub) {
81
+ return sub !== null;
82
82
  }) : [];
83
83
  return /*#__PURE__*/React.createElement("div", {
84
84
  className: classNames("".concat(prefixCls, "-item"), _defineProperty({}, "".concat(prefixCls, "-item-disabled"), item.disabled)),
@@ -114,8 +114,8 @@ export default function VirtualList(props) {
114
114
 
115
115
  var list = [];
116
116
  var max = rows.length - 1;
117
- var start = range.start,
118
- end = range.end;
117
+ var start = range.start;
118
+ var end = range.end;
119
119
 
120
120
  if (end > max) {
121
121
  end = max;
@@ -168,8 +168,8 @@ function BaseTable(props, _ref) {
168
168
  return null;
169
169
  }
170
170
 
171
- var style = getComputedStyle(parent);
172
- var contentHeight = parent.offsetHeight - (parseFloat(style.getPropertyValue('padding-top')) || 0) - (parseFloat(style.getPropertyValue('padding-bottom')) || 0);
171
+ var mStyle = getComputedStyle(parent);
172
+ var contentHeight = parent.offsetHeight - (parseFloat(mStyle.getPropertyValue('padding-top')) || 0) - (parseFloat(mStyle.getPropertyValue('padding-bottom')) || 0);
173
173
  var nodes = [];
174
174
 
175
175
  if (tableBody.previousElementSibling !== null) {
@@ -1,4 +1,4 @@
1
- import { ColumnType, ColumnGroupType } from './typings';
1
+ import type { ColumnType, ColumnGroupType } from './typings';
2
2
  export declare function isColumnType<T>(col: ColumnGroupType<T> | ColumnType<T>): col is ColumnType<T>;
3
3
  export declare function getColumnKey(col: ColumnType<any>): string | number;
4
4
  export declare function randomStr(): string;
@@ -3,6 +3,7 @@ import type { ICellEditorReactComp } from '@ag-grid-community/react';
3
3
  import type { ICellEditorParams } from '@ag-grid-community/core';
4
4
  export interface DateEditorParams {
5
5
  format: string;
6
+ disabled?: boolean;
6
7
  }
7
8
  declare const _default: React.ForwardRefExoticComponent<ICellEditorParams<any, any> & DateEditorParams & React.RefAttributes<ICellEditorReactComp>>;
8
9
  export default _default;
@@ -17,9 +17,10 @@ import { DatePicker } from 'antd';
17
17
  import EditorWrapper from "./Wrapper";
18
18
  import { editorPrefixClass } from "./utils";
19
19
  export default /*#__PURE__*/forwardRef(function DateEditor(props, ref) {
20
- var cellStartedEdit = props.cellStartedEdit,
21
- _props$format = props.format,
22
- format = _props$format === void 0 ? 'YYYY-MM-DD' : _props$format;
20
+ var _props$format = props.format,
21
+ format = _props$format === void 0 ? 'YYYY-MM-DD' : _props$format,
22
+ disabled = props.disabled,
23
+ api = props.api;
23
24
 
24
25
  var _useState = useState(props.value ? moment(props.value, format) : null),
25
26
  _useState2 = _slicedToArray(_useState, 2),
@@ -27,13 +28,12 @@ export default /*#__PURE__*/forwardRef(function DateEditor(props, ref) {
27
28
  setValue = _useState2[1];
28
29
 
29
30
  var elm = useRef(null);
31
+ var isEdited = useRef(false);
30
32
  useEffect(function () {
31
- if (cellStartedEdit) {
32
- var _elm$current;
33
+ var _elm$current;
33
34
 
34
- (_elm$current = elm.current) === null || _elm$current === void 0 ? void 0 : _elm$current.focus();
35
- }
36
- }, [cellStartedEdit]);
35
+ (_elm$current = elm.current) === null || _elm$current === void 0 ? void 0 : _elm$current.focus();
36
+ }, []);
37
37
 
38
38
  var getValue = function getValue() {
39
39
  return value ? value.format(format) : '';
@@ -41,36 +41,39 @@ export default /*#__PURE__*/forwardRef(function DateEditor(props, ref) {
41
41
 
42
42
  useImperativeHandle(ref, function () {
43
43
  return {
44
- getValue: getValue,
45
- focusIn: function focusIn() {
46
- var _elm$current2;
47
-
48
- (_elm$current2 = elm.current) === null || _elm$current2 === void 0 ? void 0 : _elm$current2.focus();
49
- return true;
50
- },
51
- focusOut: function focusOut() {
52
- var _elm$current3;
53
-
54
- (_elm$current3 = elm.current) === null || _elm$current3 === void 0 ? void 0 : _elm$current3.blur();
55
- return true;
56
- }
44
+ getValue: getValue
57
45
  };
58
46
  });
59
47
  return /*#__PURE__*/React.createElement(EditorWrapper, null, /*#__PURE__*/React.createElement(DatePicker, {
48
+ onKeyDown: function onKeyDown(e) {
49
+ if (isEdited.current && e.key === 'Enter') {
50
+ api.tabToNextCell();
51
+ }
52
+ },
60
53
  style: {
61
54
  display: 'flex',
62
55
  paddingTop: 0,
63
56
  paddingBottom: 0
64
57
  },
58
+ disabled: disabled,
65
59
  className: editorPrefixClass('date'),
66
60
  value: value,
67
61
  placeholder: format,
62
+ onOpenChange: function onOpenChange(val) {
63
+ if (!val) {
64
+ isEdited.current = true;
65
+ }
66
+ },
68
67
  onChange: function onChange(val) {
69
68
  if (val) {
70
69
  setValue(val);
71
70
  } else {
72
71
  setValue(null);
73
72
  }
73
+
74
+ requestAnimationFrame(function () {
75
+ api.tabToNextCell();
76
+ });
74
77
  },
75
78
  ref: elm,
76
79
  bordered: false
@@ -2,8 +2,27 @@ import React from 'react';
2
2
  import type { ICellEditorReactComp } from '@ag-grid-community/react';
3
3
  import type { ICellEditorParams } from '@ag-grid-community/core';
4
4
  export interface NumberEditorParams {
5
+ disabled?: boolean;
6
+ /**
7
+ * @description 最小值
8
+ */
5
9
  min?: number;
10
+ /**
11
+ * @description 最大值
12
+ */
6
13
  max?: number;
14
+ /**
15
+ * @description 空值
16
+ */
17
+ emptyValue?: number;
18
+ /**
19
+ * @description 当值不合理时,不修改单元格
20
+ */
21
+ undoWhenError?: boolean;
22
+ /**
23
+ * @description 精度
24
+ */
25
+ precision?: number;
7
26
  }
8
27
  declare const _default: React.ForwardRefExoticComponent<ICellEditorParams<any, any> & NumberEditorParams & React.RefAttributes<ICellEditorReactComp>>;
9
28
  export default _default;
@@ -17,9 +17,15 @@ import { editorPrefixClass } from "./utils";
17
17
  export default /*#__PURE__*/forwardRef(function NumberEditor(props, ref) {
18
18
  var _props$value;
19
19
 
20
- var cellStartedEdit = props.cellStartedEdit,
21
- min = props.min,
22
- max = props.max;
20
+ var _props$min = props.min,
21
+ min = _props$min === void 0 ? -99999999 : _props$min,
22
+ _props$max = props.max,
23
+ max = _props$max === void 0 ? 99999999 : _props$max,
24
+ emptyValue = props.emptyValue,
25
+ undoWhenError = props.undoWhenError,
26
+ disabled = props.disabled,
27
+ api = props.api,
28
+ precision = props.precision;
23
29
 
24
30
  var _useState = useState((_props$value = props.value) !== null && _props$value !== void 0 ? _props$value : null),
25
31
  _useState2 = _slicedToArray(_useState, 2),
@@ -27,60 +33,67 @@ export default /*#__PURE__*/forwardRef(function NumberEditor(props, ref) {
27
33
  setValue = _useState2[1];
28
34
 
29
35
  var elm = useRef(null);
36
+ var dirty = useRef(false);
30
37
  useEffect(function () {
31
- if (cellStartedEdit) {
32
- var _elm$current;
38
+ var _elm$current;
33
39
 
34
- (_elm$current = elm.current) === null || _elm$current === void 0 ? void 0 : _elm$current.select();
35
- }
36
- }, [cellStartedEdit]);
40
+ (_elm$current = elm.current) === null || _elm$current === void 0 ? void 0 : _elm$current.select();
41
+ }, []);
37
42
 
38
43
  var getValue = function getValue() {
39
- if (value === '' || value === null) {
40
- return null;
41
- }
42
-
43
44
  var val;
45
+ var error = false;
44
46
 
45
- if (typeof value === 'string') {
46
- val = parseFloat(value);
47
+ if (value === '' || value === null) {
48
+ val = emptyValue !== null && emptyValue !== void 0 ? emptyValue : null;
47
49
  } else {
48
- val = value;
50
+ val = +value;
51
+
52
+ if (precision !== undefined) {
53
+ val = Math.round(val * Math.pow(10, precision)) / Math.pow(10, precision);
54
+ }
49
55
  }
50
56
 
51
- if (min !== undefined && val < min) {
57
+ if (val === null) {
58
+ error = true;
59
+ } else if (val < min) {
60
+ error = true;
52
61
  val = min;
53
- } else if (max !== undefined && val > max) {
62
+ } else if (val > max) {
63
+ error = true;
54
64
  val = max;
55
65
  }
56
66
 
67
+ if (error && undoWhenError) {
68
+ return props.value;
69
+ }
70
+
57
71
  return val;
58
72
  };
59
73
 
60
74
  useImperativeHandle(ref, function () {
61
75
  return {
62
76
  getValue: getValue,
63
- focusIn: function focusIn() {
64
- var _elm$current2;
65
-
66
- (_elm$current2 = elm.current) === null || _elm$current2 === void 0 ? void 0 : _elm$current2.select();
67
- return true;
68
- },
69
- focusOut: function focusOut() {
70
- var _elm$current3;
71
-
72
- (_elm$current3 = elm.current) === null || _elm$current3 === void 0 ? void 0 : _elm$current3.blur();
73
- return true;
77
+ isCancelAfterEnd: function isCancelAfterEnd() {
78
+ return !dirty.current;
74
79
  }
75
80
  };
76
81
  });
77
- return /*#__PURE__*/React.createElement(EditorWrapper, null, /*#__PURE__*/React.createElement("input", {
82
+ return /*#__PURE__*/React.createElement(EditorWrapper, {
83
+ onKeyDown: function onKeyDown(e) {
84
+ if (e.key === 'Enter') {
85
+ api.tabToNextCell();
86
+ }
87
+ }
88
+ }, /*#__PURE__*/React.createElement("input", {
78
89
  type: "number",
90
+ disabled: disabled,
79
91
  className: editorPrefixClass('text'),
80
92
  ref: elm,
81
93
  value: value !== null && value !== void 0 ? value : '',
82
94
  onChange: function onChange(event) {
83
- return setValue(event.target.value);
95
+ dirty.current = true;
96
+ setValue(event.target.value);
84
97
  }
85
98
  }));
86
99
  });
@@ -0,0 +1,22 @@
1
+ import type { MutableRefObject, ReactElement } from 'react';
2
+ import React from 'react';
3
+ import type { ICellEditorReactComp } from '@ag-grid-community/react';
4
+ import type { ICellEditorParams } from '@ag-grid-community/core';
5
+ export declare class RowEditorData<T> {
6
+ private data;
7
+ constructor(data: T);
8
+ getValue(): T;
9
+ }
10
+ export interface RowEditorParams<T = any, K = any> {
11
+ suppressEnterEvent?: boolean;
12
+ isCancelAfterEnd?: (prevValue: T, nextValue: T) => boolean;
13
+ render: (val: K, data: T, params: ICellEditorParams<T, K> & {
14
+ ref: MutableRefObject<{
15
+ select?: () => void;
16
+ focus?: () => void;
17
+ } | null>;
18
+ onChange: (val: Partial<T>, action?: 'stop' | 'next') => void;
19
+ }) => ReactElement | null;
20
+ }
21
+ declare const _default: React.ForwardRefExoticComponent<ICellEditorParams<any, any> & RowEditorParams<any, any> & React.RefAttributes<ICellEditorReactComp>>;
22
+ export default _default;
@@ -0,0 +1,124 @@
1
+ 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; }
2
+
3
+ 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; }
4
+
5
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
6
+
7
+ 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."); }
8
+
9
+ 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); }
10
+
11
+ 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; }
12
+
13
+ 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; }
14
+
15
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
16
+
17
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
18
+
19
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
20
+
21
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
22
+
23
+ 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; }
24
+
25
+ import React, { useEffect, useRef } from 'react';
26
+ import { get } from 'lodash';
27
+ import { forwardRef, useImperativeHandle, useState } from 'react';
28
+ import EditorWrapper from "./Wrapper";
29
+ import { useGridStore } from "../hooks";
30
+ export var RowEditorData = /*#__PURE__*/function () {
31
+ function RowEditorData(data) {
32
+ _classCallCheck(this, RowEditorData);
33
+
34
+ _defineProperty(this, "data", void 0);
35
+
36
+ this.data = data;
37
+ }
38
+
39
+ _createClass(RowEditorData, [{
40
+ key: "getValue",
41
+ value: function getValue() {
42
+ return this.data;
43
+ }
44
+ }]);
45
+
46
+ return RowEditorData;
47
+ }();
48
+ export default /*#__PURE__*/forwardRef(function RowEditor(props, ref) {
49
+ var api = props.api,
50
+ suppressEnterEvent = props.suppressEnterEvent,
51
+ stopEditing = props.stopEditing,
52
+ data = props.data,
53
+ render = props.render,
54
+ isCancelAfterEnd = props.isCancelAfterEnd,
55
+ field = props.colDef.field;
56
+
57
+ var _useState = useState(data),
58
+ _useState2 = _slicedToArray(_useState, 2),
59
+ value = _useState2[0],
60
+ setValue = _useState2[1];
61
+
62
+ var context = useGridStore(function (state) {
63
+ return state.context;
64
+ });
65
+ var elm = useRef(null);
66
+ useEffect(function () {
67
+ if (elm.current !== null) {
68
+ if (elm.current.select !== undefined) {
69
+ elm.current.select();
70
+ } else if (elm.current.focus !== undefined) {
71
+ elm.current.focus();
72
+ }
73
+ }
74
+ }, []);
75
+ useImperativeHandle(ref, function () {
76
+ return {
77
+ getValue: function getValue() {
78
+ var prevValue = props.value;
79
+ var nextValue = prevValue;
80
+
81
+ if (field === undefined || value === data || isCancelAfterEnd !== undefined && isCancelAfterEnd(data, _objectSpread(_objectSpread({}, data), value))) {
82
+ return prevValue;
83
+ }
84
+
85
+ nextValue = get(value, field);
86
+
87
+ if (nextValue == prevValue) {
88
+ return prevValue;
89
+ }
90
+
91
+ return new RowEditorData(value);
92
+ }
93
+ };
94
+ });
95
+
96
+ var handleChange = function handleChange(val, action) {
97
+ setValue(val);
98
+
99
+ if (action !== undefined) {
100
+ requestAnimationFrame(function () {
101
+ switch (action) {
102
+ case 'stop':
103
+ stopEditing();
104
+ break;
105
+
106
+ case 'next':
107
+ api.tabToNextCell();
108
+ }
109
+ });
110
+ }
111
+ };
112
+
113
+ return /*#__PURE__*/React.createElement(EditorWrapper, {
114
+ onKeyDown: function onKeyDown(e) {
115
+ if (!suppressEnterEvent && e.key === 'Enter') {
116
+ api.tabToNextCell();
117
+ }
118
+ }
119
+ }, render(field ? get(value, field) : props.value, data, _objectSpread(_objectSpread({}, props), {}, {
120
+ context: context,
121
+ ref: elm,
122
+ onChange: handleChange
123
+ })));
124
+ });
@@ -1,7 +1,25 @@
1
1
  import React from 'react';
2
2
  import type { ICellEditorReactComp } from '@ag-grid-community/react';
3
3
  import type { ICellEditorParams } from '@ag-grid-community/core';
4
- import type { SelectProps } from 'antd/lib/select';
5
- export declare type SelectEditorParams = Pick<SelectProps, 'options' | 'fieldNames' | 'virtual' | 'showSearch' | 'listHeight' | 'listItemHeight' | 'allowClear' | 'mode' | 'labelInValue'>;
6
- declare const _default: React.ForwardRefExoticComponent<ICellEditorParams<any, any> & SelectEditorParams & React.RefAttributes<ICellEditorReactComp>>;
4
+ import type { BaseOptionType, SelectProps } from 'antd/lib/select';
5
+ export declare type SelectEditorParams = Pick<SelectProps<any, BaseOptionType>, 'disabled' | 'options' | 'virtual' | 'showSearch' | 'listHeight' | 'allowClear' | 'mode'> & {
6
+ fieldNames?: {
7
+ label: string;
8
+ value: string;
9
+ };
10
+ /**
11
+ * 是否是用options的数组成员作为value的值,此时传入的value也应该是数组成员的类型
12
+ */
13
+ valueByOption?: boolean;
14
+ };
15
+ declare const _default: React.ForwardRefExoticComponent<ICellEditorParams<any, any> & Pick<SelectProps<any, BaseOptionType>, "disabled" | "options" | "virtual" | "showSearch" | "listHeight" | "allowClear" | "mode"> & {
16
+ fieldNames?: {
17
+ label: string;
18
+ value: string;
19
+ } | undefined;
20
+ /**
21
+ * 是否是用options的数组成员作为value的值,此时传入的value也应该是数组成员的类型
22
+ */
23
+ valueByOption?: boolean | undefined;
24
+ } & React.RefAttributes<ICellEditorReactComp>>;
7
25
  export default _default;
@@ -1,4 +1,4 @@
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); }
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
2
 
3
3
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
4
4
 
@@ -12,15 +12,23 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
12
12
 
13
13
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
14
14
 
15
+ import { useMemo } from 'react';
15
16
  import React, { useEffect, useRef } from 'react';
16
17
  import { forwardRef, useImperativeHandle, useState } from 'react';
17
18
  import { Select } from 'antd';
18
19
  import EditorWrapper from "./Wrapper";
19
20
  import { editorPrefixClass } from "./utils";
20
21
  export default /*#__PURE__*/forwardRef(function SelectEditor(props, ref) {
21
- var stopEditing = props.stopEditing,
22
- cellStartedEdit = props.cellStartedEdit,
23
- cellEditorParams = props.colDef.cellEditorParams;
22
+ var api = props.api,
23
+ disabled = props.disabled,
24
+ options = props.options,
25
+ virtual = props.virtual,
26
+ allowClear = props.allowClear,
27
+ mode = props.mode,
28
+ fieldNames = props.fieldNames,
29
+ valueByOption = props.valueByOption,
30
+ showSearch = props.showSearch,
31
+ listHeight = props.listHeight;
24
32
 
25
33
  var _useState = useState(props.value),
26
34
  _useState2 = _slicedToArray(_useState, 2),
@@ -29,42 +37,66 @@ export default /*#__PURE__*/forwardRef(function SelectEditor(props, ref) {
29
37
 
30
38
  var elm = useRef(null);
31
39
  useEffect(function () {
32
- if (cellStartedEdit) {
33
- var _elm$current;
40
+ var _elm$current;
34
41
 
35
- (_elm$current = elm.current) === null || _elm$current === void 0 ? void 0 : _elm$current.focus();
36
- }
37
- }, [cellStartedEdit]);
42
+ (_elm$current = elm.current) === null || _elm$current === void 0 ? void 0 : _elm$current.focus();
43
+ }, []);
38
44
  useImperativeHandle(ref, function () {
39
45
  return {
40
46
  getValue: function getValue() {
41
47
  return value;
42
- },
43
- focusIn: function focusIn() {
44
- var _elm$current2;
45
-
46
- (_elm$current2 = elm.current) === null || _elm$current2 === void 0 ? void 0 : _elm$current2.focus();
47
- return true;
48
- },
49
- focusOut: function focusOut() {
50
- var _elm$current3;
51
-
52
- (_elm$current3 = elm.current) === null || _elm$current3 === void 0 ? void 0 : _elm$current3.blur();
53
- return true;
54
48
  }
55
49
  };
56
50
  });
57
- return /*#__PURE__*/React.createElement(EditorWrapper, null, /*#__PURE__*/React.createElement(Select, _extends({
51
+ var val = useMemo(function () {
52
+ var result = value;
53
+
54
+ if (valueByOption && result !== null && fieldNames !== undefined) {
55
+ var formatValue = function formatValue(item) {
56
+ if (item instanceof Object) {
57
+ return item[fieldNames.value];
58
+ }
59
+
60
+ return item;
61
+ };
62
+
63
+ if (Array.isArray(result)) {
64
+ result = result.map(function (item) {
65
+ return formatValue(item);
66
+ });
67
+ } else if (_typeof(result) === 'object') {
68
+ result = formatValue(result);
69
+ }
70
+ }
71
+
72
+ return result;
73
+ }, [value]);
74
+ return /*#__PURE__*/React.createElement(EditorWrapper, null, /*#__PURE__*/React.createElement(Select, {
58
75
  ref: elm,
59
76
  bordered: false,
60
- className: editorPrefixClass('select')
61
- }, cellEditorParams, {
62
- value: value,
63
- onChange: function onChange(val) {
64
- setValue(val);
77
+ fieldNames: fieldNames,
78
+ disabled: disabled,
79
+ virtual: virtual,
80
+ allowClear: allowClear,
81
+ showSearch: showSearch,
82
+ mode: mode,
83
+ className: editorPrefixClass('select'),
84
+ value: val,
85
+ options: options,
86
+ listHeight: listHeight,
87
+ style: {
88
+ width: '100%'
89
+ },
90
+ onChange: function onChange(changedValue, opt) {
91
+ if (valueByOption) {
92
+ setValue(opt);
93
+ } else {
94
+ setValue(changedValue);
95
+ }
96
+
65
97
  requestAnimationFrame(function () {
66
- stopEditing();
98
+ api.tabToNextCell();
67
99
  });
68
100
  }
69
- })));
101
+ }));
70
102
  });
@@ -1,5 +1,8 @@
1
1
  import React from 'react';
2
2
  import type { ICellEditorReactComp } from '@ag-grid-community/react';
3
3
  import type { ICellEditorParams } from '@ag-grid-community/core';
4
- declare const _default: React.ForwardRefExoticComponent<ICellEditorParams<any, any> & React.RefAttributes<ICellEditorReactComp>>;
4
+ export interface TextEditorParams {
5
+ disabled: boolean;
6
+ }
7
+ declare const _default: React.ForwardRefExoticComponent<ICellEditorParams<any, any> & TextEditorParams & React.RefAttributes<ICellEditorReactComp>>;
5
8
  export default _default;