@lemon-fe/components 1.4.22 → 1.4.23-alpha.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.
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { DataGridSearch, DataGridSearchRef } from '../typings';
|
|
3
|
-
declare const _default:
|
|
3
|
+
declare const _default: <TData>(props: DataGridSearch<TData> & {
|
|
4
|
+
ref: React.RefObject<DataGridSearchRef>;
|
|
5
|
+
}) => React.ReactElement;
|
|
4
6
|
export default _default;
|
|
@@ -15,10 +15,12 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
15
15
|
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; }
|
|
16
16
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
17
17
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
18
|
-
import { Button, Input, Space } from 'antd';
|
|
18
|
+
import { Button, Input, Select, Space } from 'antd';
|
|
19
19
|
import React, { forwardRef, memo, useState, useImperativeHandle, useMemo, useRef } from 'react';
|
|
20
|
+
import InputCompact from "../../input-compact";
|
|
20
21
|
import { useLocaleReceiver } from "../../locale-receiver";
|
|
21
22
|
import { useGridStore } from "../hooks";
|
|
23
|
+
import { prefix } from "../utils";
|
|
22
24
|
import { useDebounce } from '@lemon-fe/hooks';
|
|
23
25
|
export default /*#__PURE__*/memo( /*#__PURE__*/forwardRef(function Search(props, ref) {
|
|
24
26
|
var placeholder = props.placeholder,
|
|
@@ -27,7 +29,8 @@ export default /*#__PURE__*/memo( /*#__PURE__*/forwardRef(function Search(props,
|
|
|
27
29
|
_props$clearSelection = props.clearSelection,
|
|
28
30
|
clearSelection = _props$clearSelection === void 0 ? true : _props$clearSelection,
|
|
29
31
|
defaultValue = props.defaultValue,
|
|
30
|
-
onValueChange = props.onValueChange
|
|
32
|
+
onValueChange = props.onValueChange,
|
|
33
|
+
dropdownConfig = props.dropdownConfig;
|
|
31
34
|
// 单行搜索大致耗时
|
|
32
35
|
var duration = useRef(0);
|
|
33
36
|
var defaultState = useMemo(function () {
|
|
@@ -64,15 +67,33 @@ export default /*#__PURE__*/memo( /*#__PURE__*/forwardRef(function Search(props,
|
|
|
64
67
|
}
|
|
65
68
|
return cols;
|
|
66
69
|
};
|
|
70
|
+
var getLabel = function getLabel(node) {
|
|
71
|
+
var defaultVal = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
72
|
+
if (dropdownConfig && node.data) {
|
|
73
|
+
var label = dropdownConfig.label;
|
|
74
|
+
if (typeof label === 'function') {
|
|
75
|
+
return label(node.data);
|
|
76
|
+
} else {
|
|
77
|
+
return grid.api.getValue(label, node);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return defaultVal;
|
|
81
|
+
};
|
|
67
82
|
var checkNodes = function checkNodes(keywords, node, cols) {
|
|
83
|
+
var result = {
|
|
84
|
+
label: '',
|
|
85
|
+
matched: false
|
|
86
|
+
};
|
|
68
87
|
for (var i = 0; i < cols.length; i++) {
|
|
69
88
|
var col = cols[i];
|
|
70
89
|
var value = grid.api.getValue(col, node);
|
|
71
90
|
if (value !== undefined && value !== null && typeof value === 'string' && value.toUpperCase().includes(keywords.toUpperCase())) {
|
|
72
|
-
|
|
91
|
+
result.label = getLabel(node, value);
|
|
92
|
+
result.matched = true;
|
|
93
|
+
return result;
|
|
73
94
|
}
|
|
74
95
|
}
|
|
75
|
-
return
|
|
96
|
+
return result;
|
|
76
97
|
};
|
|
77
98
|
var handleSearch = useDebounce(function (str, prevState) {
|
|
78
99
|
var keywords = str.trim();
|
|
@@ -107,9 +128,11 @@ export default /*#__PURE__*/memo( /*#__PURE__*/forwardRef(function Search(props,
|
|
|
107
128
|
if (id === undefined) {
|
|
108
129
|
return;
|
|
109
130
|
}
|
|
110
|
-
|
|
131
|
+
var checkResult = checkNodes(keywords, node, cols);
|
|
132
|
+
if (checkResult.matched) {
|
|
111
133
|
nodes.push({
|
|
112
|
-
id: id
|
|
134
|
+
id: id,
|
|
135
|
+
label: checkResult.label
|
|
113
136
|
});
|
|
114
137
|
if (prevNodes.has(id)) {
|
|
115
138
|
prevNodes.set(id, nodes.length - 1);
|
|
@@ -186,6 +209,23 @@ export default /*#__PURE__*/memo( /*#__PURE__*/forwardRef(function Search(props,
|
|
|
186
209
|
});
|
|
187
210
|
});
|
|
188
211
|
};
|
|
212
|
+
var jumpToItem = function jumpToItem(id) {
|
|
213
|
+
if (state.nodes.length <= 0) {
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
var idx = state.nodes.findIndex(function (item) {
|
|
217
|
+
return item.id === id;
|
|
218
|
+
});
|
|
219
|
+
if (idx < 0) {
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
focusCell(id);
|
|
223
|
+
setState(function (prev) {
|
|
224
|
+
return _objectSpread(_objectSpread({}, prev), {}, {
|
|
225
|
+
index: idx
|
|
226
|
+
});
|
|
227
|
+
});
|
|
228
|
+
};
|
|
189
229
|
useImperativeHandle(ref, function () {
|
|
190
230
|
return {
|
|
191
231
|
reset: function reset() {
|
|
@@ -233,8 +273,10 @@ export default /*#__PURE__*/memo( /*#__PURE__*/forwardRef(function Search(props,
|
|
|
233
273
|
break;
|
|
234
274
|
}
|
|
235
275
|
}
|
|
276
|
+
var label = getLabel(node);
|
|
236
277
|
_newNodes.splice(idx, 0, {
|
|
237
|
-
id: id
|
|
278
|
+
id: id,
|
|
279
|
+
label: label
|
|
238
280
|
});
|
|
239
281
|
setState(function (prev) {
|
|
240
282
|
return _objectSpread(_objectSpread({}, prev), {}, {
|
|
@@ -253,7 +295,12 @@ export default /*#__PURE__*/memo( /*#__PURE__*/forwardRef(function Search(props,
|
|
|
253
295
|
}
|
|
254
296
|
};
|
|
255
297
|
});
|
|
256
|
-
return /*#__PURE__*/React.createElement(Space, null, /*#__PURE__*/React.createElement(
|
|
298
|
+
return /*#__PURE__*/React.createElement(Space, null, /*#__PURE__*/React.createElement(InputCompact, {
|
|
299
|
+
className: "".concat(prefix('bottom-search')),
|
|
300
|
+
style: {
|
|
301
|
+
width: 264
|
|
302
|
+
}
|
|
303
|
+
}, /*#__PURE__*/React.createElement(Input, {
|
|
257
304
|
placeholder: placeholder || dataGridLocale.searchPlaceholderText,
|
|
258
305
|
value: state.keywords,
|
|
259
306
|
defaultValue: defaultValue,
|
|
@@ -272,8 +319,24 @@ export default /*#__PURE__*/memo( /*#__PURE__*/forwardRef(function Search(props,
|
|
|
272
319
|
if (e.key === 'Enter') {
|
|
273
320
|
handleNext(searching.current ? handleSearch.flush() : state);
|
|
274
321
|
}
|
|
322
|
+
},
|
|
323
|
+
bordered: false
|
|
324
|
+
}), /*#__PURE__*/React.createElement(Select, {
|
|
325
|
+
options: state.nodes,
|
|
326
|
+
bordered: false,
|
|
327
|
+
notFoundContent: null,
|
|
328
|
+
className: "".concat(prefix('bottom-search-select')),
|
|
329
|
+
fieldNames: {
|
|
330
|
+
label: 'label',
|
|
331
|
+
value: 'id'
|
|
332
|
+
},
|
|
333
|
+
placement: "topRight",
|
|
334
|
+
dropdownMatchSelectWidth: 264,
|
|
335
|
+
listHeight: 280,
|
|
336
|
+
onChange: function onChange(val) {
|
|
337
|
+
jumpToItem(val);
|
|
275
338
|
}
|
|
276
|
-
}), /*#__PURE__*/React.createElement(Button, {
|
|
339
|
+
})), /*#__PURE__*/React.createElement(Button, {
|
|
277
340
|
size: "small",
|
|
278
341
|
onClick: handlePrev
|
|
279
342
|
}, dataGridLocale.searchPrevText), /*#__PURE__*/React.createElement(Button, {
|
package/es/data-grid/index.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ declare const Editors: {
|
|
|
17
17
|
Text: React.ForwardRefExoticComponent<import("ag-grid-community").ICellEditorParams<any, any, any> & import("..").TextEditorParams<any> & React.RefAttributes<import("ag-grid-react").ICellEditorReactComp>>;
|
|
18
18
|
Date: React.ForwardRefExoticComponent<import("ag-grid-community").ICellEditorParams<any, any, any> & import("..").DateEditorParams<any> & React.RefAttributes<import("ag-grid-react").ICellEditorReactComp>>;
|
|
19
19
|
Number: React.ForwardRefExoticComponent<import("ag-grid-community").ICellEditorParams<any, any, any> & import("..").NumberEditorParams<any> & React.RefAttributes<import("ag-grid-react").ICellEditorReactComp>>;
|
|
20
|
-
Select: React.ForwardRefExoticComponent<import("ag-grid-community").ICellEditorParams<any, any, any> & Pick<import("antd").SelectProps<any, import("antd/lib/select").BaseOptionType>, "disabled" | "mode" | "
|
|
20
|
+
Select: React.ForwardRefExoticComponent<import("ag-grid-community").ICellEditorParams<any, any, any> & Pick<import("antd").SelectProps<any, import("antd/lib/select").BaseOptionType>, "disabled" | "mode" | "allowClear" | "showSearch" | "optionFilterProp" | "options" | "virtual" | "listHeight"> & {
|
|
21
21
|
fieldNames?: {
|
|
22
22
|
label: string;
|
|
23
23
|
value: string;
|
package/es/data-grid/index.less
CHANGED
|
@@ -538,6 +538,17 @@
|
|
|
538
538
|
justify-content: center;
|
|
539
539
|
background-color: rgba(255, 255, 255, 0.6);
|
|
540
540
|
}
|
|
541
|
+
|
|
542
|
+
&-bottom-search {
|
|
543
|
+
&-select {
|
|
544
|
+
width: 32px;
|
|
545
|
+
overflow: hidden;
|
|
546
|
+
|
|
547
|
+
.@{ant-prefix}-select-selector {
|
|
548
|
+
opacity: 0;
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
}
|
|
541
552
|
}
|
|
542
553
|
|
|
543
554
|
.ag-theme-@{prefixCls} {
|
|
@@ -133,7 +133,7 @@ export declare type DetailCell<TData, Params = Record<string, never>> = {
|
|
|
133
133
|
/** 这是一个render函数不是组件 */
|
|
134
134
|
render: (params: ICellRendererParams<TData> & Params) => ReactNode;
|
|
135
135
|
};
|
|
136
|
-
export interface DataGridSearch {
|
|
136
|
+
export interface DataGridSearch<TData> {
|
|
137
137
|
/**
|
|
138
138
|
* @description
|
|
139
139
|
* 不传入就根据所有字符类型的列数据搜索
|
|
@@ -156,6 +156,16 @@ export interface DataGridSearch {
|
|
|
156
156
|
*/
|
|
157
157
|
defaultValue?: string;
|
|
158
158
|
onValueChange?: (value: string) => void;
|
|
159
|
+
/**
|
|
160
|
+
* @description
|
|
161
|
+
* 是否显示搜索结果 上下键快速定位
|
|
162
|
+
*/
|
|
163
|
+
dropdownConfig?: {
|
|
164
|
+
/**
|
|
165
|
+
* label字段
|
|
166
|
+
*/
|
|
167
|
+
label: string | ((item: TData) => ReactNode | string);
|
|
168
|
+
};
|
|
159
169
|
}
|
|
160
170
|
export interface DataGridSearchRef {
|
|
161
171
|
reset: () => void;
|
|
@@ -235,7 +245,7 @@ export interface DataGridProps<TData> extends Omit<AgGridReactProps<TData>, 'row
|
|
|
235
245
|
/**
|
|
236
246
|
* @description 显示底部搜索栏,只支持非远程模式
|
|
237
247
|
*/
|
|
238
|
-
showSearch?: boolean | DataGridSearch
|
|
248
|
+
showSearch?: boolean | DataGridSearch<TData>;
|
|
239
249
|
/**
|
|
240
250
|
* @description 单元格是否表现成弹性盒子,从而便于垂直,此时也会导致文本ellipsis失效
|
|
241
251
|
*/
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lemon-fe/components",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.23-alpha.0",
|
|
4
4
|
"description": "> TODO: description",
|
|
5
5
|
"homepage": "",
|
|
6
6
|
"license": "MIT",
|
|
@@ -58,5 +58,5 @@
|
|
|
58
58
|
"publishConfig": {
|
|
59
59
|
"registry": "https://registry.npmjs.org"
|
|
60
60
|
},
|
|
61
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "35dfdc73a1e887377b7f67734a0231d1271420a0"
|
|
62
62
|
}
|