@lemon-fe/kits 1.0.0-48 → 1.0.0-49

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.
@@ -17,8 +17,7 @@ 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,
20
+ var _props$format = props.format,
22
21
  format = _props$format === void 0 ? 'YYYY-MM-DD' : _props$format,
23
22
  disabled = props.disabled,
24
23
  api = props.api;
@@ -31,12 +30,10 @@ export default /*#__PURE__*/forwardRef(function DateEditor(props, ref) {
31
30
  var elm = useRef(null);
32
31
  var isEdited = useRef(false);
33
32
  useEffect(function () {
34
- if (cellStartedEdit) {
35
- var _elm$current;
33
+ var _elm$current;
36
34
 
37
- (_elm$current = elm.current) === null || _elm$current === void 0 ? void 0 : _elm$current.focus();
38
- }
39
- }, [cellStartedEdit]);
35
+ (_elm$current = elm.current) === null || _elm$current === void 0 ? void 0 : _elm$current.focus();
36
+ }, []);
40
37
 
41
38
  var getValue = function getValue() {
42
39
  return value ? value.format(format) : '';
@@ -47,13 +44,12 @@ export default /*#__PURE__*/forwardRef(function DateEditor(props, ref) {
47
44
  getValue: getValue
48
45
  };
49
46
  });
50
- return /*#__PURE__*/React.createElement(EditorWrapper, {
47
+ return /*#__PURE__*/React.createElement(EditorWrapper, null, /*#__PURE__*/React.createElement(DatePicker, {
51
48
  onKeyDown: function onKeyDown(e) {
52
49
  if (isEdited.current && e.key === 'Enter') {
53
50
  api.tabToNextCell();
54
51
  }
55
- }
56
- }, /*#__PURE__*/React.createElement(DatePicker, {
52
+ },
57
53
  style: {
58
54
  display: 'flex',
59
55
  paddingTop: 0,
@@ -1,11 +1,25 @@
1
- import type { ReactNode } from 'react';
2
1
  import React from 'react';
3
2
  import type { ICellEditorReactComp } from '@ag-grid-community/react';
4
3
  import type { ICellEditorParams } from '@ag-grid-community/core';
5
- import type { SelectProps } from 'antd/lib/select';
6
- export declare type SelectEditorParams = Pick<SelectProps<any, {
7
- label: ReactNode;
8
- value?: string | number | null | boolean;
9
- }>, 'disabled' | 'options' | 'fieldNames' | 'virtual' | 'showSearch' | 'listHeight' | 'listItemHeight' | 'allowClear' | 'mode' | 'labelInValue'>;
10
- 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" | "mode" | "allowClear" | "options" | "virtual" | "showSearch" | "listHeight"> & {
16
+ fieldNames?: {
17
+ label: string;
18
+ value: string;
19
+ } | undefined;
20
+ /**
21
+ * 是否是用options的数组成员作为value的值,此时传入的value也应该是数组成员的类型
22
+ */
23
+ valueByOption?: boolean | undefined;
24
+ } & React.RefAttributes<ICellEditorReactComp>>;
11
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,14 +12,21 @@ 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 cellEditorParams = props.colDef.cellEditorParams,
22
- api = props.api;
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;
23
30
 
24
31
  var _useState = useState(props.value),
25
32
  _useState2 = _slicedToArray(_useState, 2),
@@ -39,17 +46,53 @@ export default /*#__PURE__*/forwardRef(function SelectEditor(props, ref) {
39
46
  }
40
47
  };
41
48
  });
42
- return /*#__PURE__*/React.createElement(EditorWrapper, null, /*#__PURE__*/React.createElement(Select, _extends({
49
+ var val = useMemo(function () {
50
+ var result = value;
51
+
52
+ if (valueByOption && result !== null && fieldNames !== undefined) {
53
+ var formatValue = function formatValue(item) {
54
+ if (item instanceof Object) {
55
+ return item[fieldNames.value];
56
+ }
57
+
58
+ return item;
59
+ };
60
+
61
+ if (Array.isArray(result)) {
62
+ result = result.map(function (item) {
63
+ return formatValue(item);
64
+ });
65
+ } else if (_typeof(result) === 'object') {
66
+ result = formatValue(result);
67
+ }
68
+ }
69
+
70
+ return result;
71
+ }, [value]);
72
+ return /*#__PURE__*/React.createElement(EditorWrapper, null, /*#__PURE__*/React.createElement(Select, {
43
73
  ref: elm,
44
74
  bordered: false,
45
- className: editorPrefixClass('select')
46
- }, cellEditorParams, {
47
- value: value,
48
- onSelect: function onSelect(val) {
49
- setValue(val);
75
+ fieldNames: fieldNames,
76
+ disabled: disabled,
77
+ virtual: virtual,
78
+ allowClear: allowClear,
79
+ mode: mode,
80
+ className: editorPrefixClass('select'),
81
+ value: val,
82
+ options: options,
83
+ style: {
84
+ width: '100%'
85
+ },
86
+ onChange: function onChange(changedValue, opt) {
87
+ if (valueByOption) {
88
+ setValue(opt);
89
+ } else {
90
+ setValue(changedValue);
91
+ }
92
+
50
93
  requestAnimationFrame(function () {
51
94
  api.tabToNextCell();
52
95
  });
53
96
  }
54
- })));
97
+ }));
55
98
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lemon-fe/kits",
3
- "version": "1.0.0-48",
3
+ "version": "1.0.0-49",
4
4
  "scripts": {
5
5
  "start": "dumi dev",
6
6
  "docs:build": "dumi build",