@zykj2024/much-library 1.0.11 → 1.0.12-beta.10

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 (49) hide show
  1. package/dist/McContainer/demo/actionBar.d.ts +1 -1
  2. package/dist/McContainer/demo/actionBar.js +58 -10
  3. package/dist/McContainer/demo/batch.d.ts +1 -1
  4. package/dist/McContainer/demo/batch.js +70 -30
  5. package/dist/McContainer/demo/standard.js +1 -2
  6. package/dist/McContainer/index.css +9 -8
  7. package/dist/McContainer/index.d.ts +29 -4
  8. package/dist/McContainer/index.js +97 -29
  9. package/dist/McDateRange/index.d.ts +1 -1
  10. package/dist/McDateRange/index.js +1 -1
  11. package/dist/McEllipsisMiddle/demo/base.d.ts +6 -0
  12. package/dist/McEllipsisMiddle/demo/base.js +25 -0
  13. package/dist/McEllipsisMiddle/index.css +4 -0
  14. package/dist/McEllipsisMiddle/index.d.ts +11 -0
  15. package/dist/McEllipsisMiddle/index.js +32 -0
  16. package/dist/McGroupPanel/comps/SelectedItem/index.js +2 -3
  17. package/dist/McGroupPanel/index.css +12 -10
  18. package/dist/McGroupPanel/index.js +34 -34
  19. package/dist/McInput/index.css +27 -0
  20. package/dist/McInputNumber/demo/index.js +6 -0
  21. package/dist/McInputNumber/index.css +27 -0
  22. package/dist/McSelect/components/PanelSearchInput/index.css +6 -0
  23. package/dist/McSelect/components/PanelSearchInput/index.d.ts +12 -0
  24. package/dist/McSelect/components/PanelSearchInput/index.js +45 -0
  25. package/dist/McSelect/demo/fetchOptions.js +1 -0
  26. package/dist/McSelect/demo/panelInSearch.d.ts +2 -0
  27. package/dist/McSelect/demo/panelInSearch.js +47 -0
  28. package/dist/McSelect/index.d.ts +7 -0
  29. package/dist/McSelect/index.js +94 -10
  30. package/dist/McThemeConfig/demo/card.d.ts +2 -0
  31. package/dist/McThemeConfig/demo/card.js +60 -0
  32. package/dist/McThemeConfig/globalStyle.js +9 -1
  33. package/dist/McThemeConfig/layoutStyle.d.ts +1 -1
  34. package/dist/McThemeConfig/layoutStyle.js +1 -1
  35. package/dist/McThemeConfig/provider.d.ts +1 -0
  36. package/dist/McThemeConfig/provider.js +1 -0
  37. package/dist/McThemeConfig/themeToken.json +7 -4
  38. package/dist/Styles/demo/basic.d.ts +2 -0
  39. package/dist/Styles/demo/basic.js +44 -0
  40. package/dist/Styles/demo/delete-icon.d.ts +2 -0
  41. package/dist/Styles/demo/delete-icon.js +72 -0
  42. package/dist/Styles/demo/form-bottom-0.d.ts +2 -0
  43. package/dist/Styles/demo/form-bottom-0.js +33 -0
  44. package/dist/Styles/index.css +41 -0
  45. package/dist/Styles/mixins.css +2 -0
  46. package/dist/Styles/utilities.css +41 -0
  47. package/dist/index.d.ts +12 -6
  48. package/dist/index.js +12 -6
  49. package/package.json +6 -1
@@ -0,0 +1,4 @@
1
+ .mc-ellipsis-middle,
2
+ .mc-ellipsis-middle * {
3
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
4
+ }
@@ -0,0 +1,11 @@
1
+ /// <reference types="react" />
2
+ import { TextProps } from 'antd/es/typography/Text';
3
+ import './index.less';
4
+ export interface McEllipsisMiddleProps extends TextProps {
5
+ text: string;
6
+ /** 省略号结尾显示的字个数 */
7
+ suffixCount: number;
8
+ style?: React.CSSProperties;
9
+ className?: string;
10
+ }
11
+ export declare const McEllipsisMiddle: ({ text, suffixCount, style, className, ...rest }: McEllipsisMiddleProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,32 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
+ var _excluded = ["text", "suffixCount", "style", "className"];
4
+ import { Typography } from 'antd';
5
+ import "./index.css";
6
+
7
+ /** 中间省略 */
8
+ import { jsx as _jsx } from "react/jsx-runtime";
9
+ var Text = Typography.Text;
10
+ export var McEllipsisMiddle = function McEllipsisMiddle(_ref) {
11
+ var text = _ref.text,
12
+ suffixCount = _ref.suffixCount,
13
+ style = _ref.style,
14
+ className = _ref.className,
15
+ rest = _objectWithoutProperties(_ref, _excluded);
16
+ var labelStr = String(text || '').trim();
17
+ var isBeyond = labelStr.length > suffixCount;
18
+ var start = isBeyond ? labelStr.slice(0, labelStr.length - suffixCount) : labelStr;
19
+ var suffix = isBeyond ? labelStr.slice(-suffixCount).trim() : '';
20
+ return /*#__PURE__*/_jsx(Text, _objectSpread(_objectSpread({
21
+ className: ['mc-ellipsis-middle', className].filter(Boolean).join(''),
22
+ style: _objectSpread({
23
+ width: '100%'
24
+ }, style),
25
+ ellipsis: {
26
+ tooltip: labelStr,
27
+ suffix: suffix
28
+ }
29
+ }, rest), {}, {
30
+ children: start
31
+ }));
32
+ };
@@ -1,6 +1,7 @@
1
1
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
2
  import { useSortable } from '@dnd-kit/sortable';
3
3
  import { Button, Typography } from 'antd';
4
+ import { MenuOutlined } from 'much-icons';
4
5
  import { McIconFont } from "../../..";
5
6
  import { memo, useMemo } from 'react';
6
7
  import "../../index.css";
@@ -53,9 +54,7 @@ var SelectedItem = function SelectedItem(_ref) {
53
54
  children: [sortable && /*#__PURE__*/_jsx(Button, _objectSpread(_objectSpread({}, listeners), {}, {
54
55
  className: "mc-group-panel__selected-item__drag",
55
56
  type: "text",
56
- icon: /*#__PURE__*/_jsx(McIconFont, {
57
- type: "icon-MenuOutlined"
58
- })
57
+ icon: /*#__PURE__*/_jsx(MenuOutlined, {})
59
58
  })), /*#__PURE__*/_jsx(Typography.Paragraph, {
60
59
  style: {
61
60
  margin: '0 auto 0 4px'
@@ -29,6 +29,7 @@
29
29
  }
30
30
  .mc-group-panel__card-body {
31
31
  height: calc(100% - 40px);
32
+ overflow: auto;
32
33
  padding: 8px;
33
34
  }
34
35
  .mc-group-panel__options {
@@ -49,6 +50,7 @@
49
50
  -webkit-box-flex: 1;
50
51
  -ms-flex: 1 1 44%;
51
52
  flex: 1 1 44%;
53
+ overflow: auto;
52
54
  }
53
55
  .mc-group-panel__options-items {
54
56
  -webkit-box-flex: 1;
@@ -65,23 +67,23 @@
65
67
  padding: 0 8px;
66
68
  }
67
69
  .mc-group-panel__checkbox-wrapper {
68
- width: calc(100% - 24px);
70
+ width: 100%;
69
71
  height: 40px;
70
72
  line-height: 40px;
71
73
  padding: 0 12px;
74
+ display: -webkit-box;
75
+ display: -ms-flexbox;
76
+ display: flex;
77
+ -webkit-box-align: center;
78
+ -ms-flex-align: center;
79
+ align-items: center;
72
80
  }
73
- .mc-group-panel__checkbox-wrapper .ant-checkbox-wrapper {
74
- max-width: 100%;
75
- }
76
- .mc-group-panel__checkbox-wrapper .ant-checkbox-wrapper .ant-checkbox + span {
77
- overflow: hidden;
78
- }
79
- .mc-group-panel__checkbox-wrapper:not(:first-child):hover {
81
+ .mc-group-panel__checkbox-wrapper:not(.mc-group-panel__check-all):hover {
80
82
  background: #f6f6f6;
81
83
  cursor: pointer;
82
84
  }
83
85
  .mc-group-panel__checkbox {
84
- width: calc(100% - 24px);
86
+ width: 100%;
85
87
  height: 40px;
86
88
  -webkit-box-align: center;
87
89
  -ms-flex-align: center;
@@ -101,7 +103,7 @@
101
103
  width: 240px;
102
104
  }
103
105
  .mc-group-panel__selected-item {
104
- width: calc(100% - 16px);
106
+ width: 100%;
105
107
  height: 40px;
106
108
  display: -webkit-box;
107
109
  display: -ms-flexbox;
@@ -4,8 +4,8 @@ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
4
4
  import { DndContext } from '@dnd-kit/core';
5
5
  import { SortableContext, arrayMove, verticalListSortingStrategy } from '@dnd-kit/sortable';
6
6
  import { Button, Checkbox, Empty, Input, Typography } from 'antd';
7
+ import debounce from 'lodash/debounce';
7
8
  import { SearchOutlined } from 'much-icons';
8
- import { Utils } from "./..";
9
9
  import { useEffect, useMemo, useState } from 'react';
10
10
  import SelectedItem from "./comps/SelectedItem";
11
11
  import "./index.css";
@@ -122,26 +122,26 @@ var McGroupPanel = function McGroupPanel(props) {
122
122
  setGroupMap(_groupMap);
123
123
  setActiveGroup(_options === null || _options === void 0 || (_options$2 = _options[0]) === null || _options$2 === void 0 ? void 0 : _options$2.value);
124
124
  };
125
- return Utils.debounce(fn, 350);
125
+ return debounce(fn, 350);
126
126
  }, [options]);
127
- var echo = function echo(value) {
128
- var _inexistentItemMap = {};
129
- value === null || value === void 0 || value.forEach(function (item) {
130
- var v = labelInValue ? item.value : item,
131
- l = labelInValue ? item.label || item.value : item;
132
- if (!itemMap[v]) _inexistentItemMap[v] = {
133
- value: v,
134
- label: l
135
- };
136
- });
137
- setSelected(value ? labelInValue ? value.map(function (item) {
138
- return item.value;
139
- }) : value : []);
140
- setInexistentItemMap(_inexistentItemMap);
141
- };
142
127
 
143
128
  /* 回显 */
144
129
  useEffect(function () {
130
+ var echo = function echo(value) {
131
+ var _inexistentItemMap = {};
132
+ value === null || value === void 0 || value.forEach(function (item) {
133
+ var v = labelInValue ? item.value : item,
134
+ l = labelInValue ? item.label || item.value : item;
135
+ if (!itemMap[v]) _inexistentItemMap[v] = {
136
+ value: v,
137
+ label: l
138
+ };
139
+ });
140
+ setSelected(value ? labelInValue ? value.map(function (item) {
141
+ return item.value;
142
+ }) : value : []);
143
+ setInexistentItemMap(_inexistentItemMap);
144
+ };
145
145
  echo(value);
146
146
  }, [value]);
147
147
 
@@ -189,9 +189,7 @@ var McGroupPanel = function McGroupPanel(props) {
189
189
  onChange: function onChange(e) {
190
190
  var v = e.target.value.trim();
191
191
  setSearchValue(v);
192
- if (v !== searchValue) {
193
- debounceSearch(v);
194
- }
192
+ v !== searchValue && debounceSearch(v);
195
193
  }
196
194
  })
197
195
  }), _options.length > 0 ? /*#__PURE__*/_jsxs("div", {
@@ -199,7 +197,7 @@ var McGroupPanel = function McGroupPanel(props) {
199
197
  children: [/*#__PURE__*/_jsxs("div", {
200
198
  className: "mc-group-panel__options-groups",
201
199
  children: [/*#__PURE__*/_jsx("div", {
202
- className: "mc-group-panel__checkbox-wrapper",
200
+ className: "mc-group-panel__checkbox-wrapper mc-group-panel__check-all",
203
201
  children: /*#__PURE__*/_jsx(Checkbox, {
204
202
  checked: allValues.length > 0 && allValues.every(function (v) {
205
203
  return selected.includes(v);
@@ -221,7 +219,7 @@ var McGroupPanel = function McGroupPanel(props) {
221
219
  className: "mc-group-panel__options-list",
222
220
  children: _options.map(function (item) {
223
221
  var _groupMap$item$value, _groupMap$item$value2;
224
- return /*#__PURE__*/_jsx("div", {
222
+ return /*#__PURE__*/_jsxs("div", {
225
223
  className: "mc-group-panel__checkbox-wrapper",
226
224
  style: {
227
225
  background: activeGroup === item.value ? '#EAEEFE' : ''
@@ -229,7 +227,7 @@ var McGroupPanel = function McGroupPanel(props) {
229
227
  onClick: function onClick() {
230
228
  return setActiveGroup(item.value);
231
229
  },
232
- children: /*#__PURE__*/_jsx(Checkbox, {
230
+ children: [/*#__PURE__*/_jsx(Checkbox, {
233
231
  checked: ((_groupMap$item$value = groupMap[item.value]) === null || _groupMap$item$value === void 0 ? void 0 : _groupMap$item$value.length) > 0 && groupMap[item.value].every(function (_ref2) {
234
232
  var value = _ref2.value;
235
233
  return selected.includes(value);
@@ -255,16 +253,18 @@ var McGroupPanel = function McGroupPanel(props) {
255
253
  }));
256
254
  },
257
255
  disabled: disabled,
258
- children: /*#__PURE__*/_jsx(Typography.Paragraph, {
259
- style: {
260
- margin: 0
261
- },
262
- ellipsis: {
263
- tooltip: item.label
264
- },
265
- children: item.label
266
- })
267
- })
256
+ onClick: function onClick(e) {
257
+ return e.stopPropagation();
258
+ }
259
+ }), /*#__PURE__*/_jsx(Typography.Paragraph, {
260
+ style: {
261
+ margin: '0 0 0 8px'
262
+ },
263
+ ellipsis: {
264
+ tooltip: item.label
265
+ },
266
+ children: item.label
267
+ })]
268
268
  }, item.value);
269
269
  })
270
270
  })]
@@ -272,7 +272,7 @@ var McGroupPanel = function McGroupPanel(props) {
272
272
  className: "mc-group-panel__options-items",
273
273
  children: ((_groupMap$activeGroup = groupMap[activeGroup]) === null || _groupMap$activeGroup === void 0 ? void 0 : _groupMap$activeGroup.length) > 0 ? /*#__PURE__*/_jsxs(_Fragment, {
274
274
  children: [/*#__PURE__*/_jsx("div", {
275
- className: "mc-group-panel__checkbox-wrapper",
275
+ className: "mc-group-panel__checkbox-wrapper mc-group-panel__check-all",
276
276
  children: /*#__PURE__*/_jsx(Checkbox, {
277
277
  checked: ((_groupMap$activeGroup2 = groupMap[activeGroup]) === null || _groupMap$activeGroup2 === void 0 ? void 0 : _groupMap$activeGroup2.length) > 0 && groupMap[activeGroup].every(function (_ref7) {
278
278
  var value = _ref7.value;
@@ -1,3 +1,5 @@
1
+ /** 给input和input number用的, 增加竖线 **/
2
+ /** 最后一个formitem没有底部空白 */
1
3
  .mc-input .ant-input-suffix .ant-input-show-count-suffix,
2
4
  .mc-search .ant-input-suffix .ant-input-show-count-suffix {
3
5
  color: #b3b3b3;
@@ -42,3 +44,28 @@
42
44
  color: #b3b3b3;
43
45
  font-size: 12px;
44
46
  }
47
+ .mc-input .ant-input-wrapper .ant-input-group-addon:nth-child(1)::after,
48
+ .mc-input .ant-input-wrapper .ant-input-group-addon:nth-last-child(1)::before {
49
+ content: '';
50
+ position: absolute;
51
+ top: 50%;
52
+ /* 居中对齐 */
53
+ -webkit-transform: translateY(-50%);
54
+ -ms-transform: translateY(-50%);
55
+ transform: translateY(-50%);
56
+ /* 垂直居中 */
57
+ height: 50%;
58
+ /* 竖线高度为输入框高度的 50% */
59
+ width: 1px;
60
+ /* 竖线宽度 */
61
+ background-color: #d8d8d8;
62
+ /* 竖线颜色 */
63
+ }
64
+ .mc-input .ant-input-wrapper .ant-input-group-addon:nth-child(1)::after {
65
+ right: 0;
66
+ /* 定位到右侧 */
67
+ }
68
+ .mc-input .ant-input-wrapper .ant-input-group-addon:nth-last-child(1)::before {
69
+ left: 0;
70
+ /* 定位到右侧 */
71
+ }
@@ -14,6 +14,12 @@ export default (function () {
14
14
  style: {
15
15
  width: 200
16
16
  }
17
+ }), /*#__PURE__*/_jsx(McInputNumber, {
18
+ addonBefore: "\u65E7\u7D20\u6750",
19
+ addonAfter: "%",
20
+ style: {
21
+ width: 200
22
+ }
17
23
  }), /*#__PURE__*/_jsxs(Space, {
18
24
  children: [/*#__PURE__*/_jsx("span", {
19
25
  children: "\u7981\u7528"
@@ -1,3 +1,5 @@
1
+ /** 给input和input number用的, 增加竖线 **/
2
+ /** 最后一个formitem没有底部空白 */
1
3
  .mc-input-number__label {
2
4
  color: #262626;
3
5
  font-size: 14px;
@@ -7,3 +9,28 @@
7
9
  content: ':';
8
10
  margin-left: 2px;
9
11
  }
12
+ .mc-input-number .ant-input-number-wrapper .ant-input-number-group-addon:nth-child(1)::after,
13
+ .mc-input-number .ant-input-number-wrapper .ant-input-number-group-addon:nth-last-child(1)::before {
14
+ content: '';
15
+ position: absolute;
16
+ top: 50%;
17
+ /* 居中对齐 */
18
+ -webkit-transform: translateY(-50%);
19
+ -ms-transform: translateY(-50%);
20
+ transform: translateY(-50%);
21
+ /* 垂直居中 */
22
+ height: 50%;
23
+ /* 竖线高度为输入框高度的 50% */
24
+ width: 1px;
25
+ /* 竖线宽度 */
26
+ background-color: #d8d8d8;
27
+ /* 竖线颜色 */
28
+ }
29
+ .mc-input-number .ant-input-number-wrapper .ant-input-number-group-addon:nth-child(1)::after {
30
+ right: 0;
31
+ /* 定位到右侧 */
32
+ }
33
+ .mc-input-number .ant-input-number-wrapper .ant-input-number-group-addon:nth-last-child(1)::before {
34
+ left: 0;
35
+ /* 定位到右侧 */
36
+ }
@@ -0,0 +1,6 @@
1
+ .mc-search-input__container {
2
+ margin: 8px;
3
+ }
4
+ .mc-search-input {
5
+ width: '100%';
6
+ }
@@ -0,0 +1,12 @@
1
+ /// <reference types="react" />
2
+ import './index.less';
3
+ interface PanelSearchInputProps {
4
+ placeholder: string | undefined;
5
+ searchValue: string | undefined;
6
+ onSearch: (e: string | undefined) => void;
7
+ }
8
+ export interface PanelSearchInputRef {
9
+ focus: () => void;
10
+ }
11
+ declare const _default: import("react").MemoExoticComponent<import("react").ForwardRefExoticComponent<PanelSearchInputProps & import("react").RefAttributes<PanelSearchInputRef>>>;
12
+ export default _default;
@@ -0,0 +1,45 @@
1
+ import { SearchOutlined } from 'much-icons';
2
+ import { forwardRef, memo, useEffect, useImperativeHandle, useRef } from 'react';
3
+ import McInput from "../../../McInput";
4
+ import "./index.css";
5
+ import { jsx as _jsx } from "react/jsx-runtime";
6
+ var PanelSearchInput = /*#__PURE__*/forwardRef(function (_ref, ref) {
7
+ var placeholder = _ref.placeholder,
8
+ onSearch = _ref.onSearch,
9
+ searchValue = _ref.searchValue;
10
+ var inputRef = useRef(null);
11
+ var focus = function focus() {
12
+ if (inputRef.current) {
13
+ setTimeout(function () {
14
+ var _inputRef$current;
15
+ (_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 || _inputRef$current.focus({
16
+ cursor: 'all'
17
+ });
18
+ }, 200);
19
+ }
20
+ };
21
+ useEffect(focus, []);
22
+ useImperativeHandle(ref, function () {
23
+ return {
24
+ focus: focus
25
+ };
26
+ });
27
+ return /*#__PURE__*/_jsx("div", {
28
+ className: "mc-search-input__container",
29
+ children: /*#__PURE__*/_jsx(McInput, {
30
+ ref: inputRef,
31
+ className: "mc-search-input",
32
+ placeholder: placeholder || '请输入搜索内容',
33
+ value: searchValue,
34
+ onKeyDown: function onKeyDown(e) {
35
+ // 避免触发原select的keydown,比如删除选项等不符预期的操作
36
+ if (['Backspace', 'Delete', 'Enter'].includes(e.key)) {
37
+ e.stopPropagation();
38
+ }
39
+ },
40
+ onChange: onSearch,
41
+ suffix: /*#__PURE__*/_jsx(SearchOutlined, {})
42
+ })
43
+ });
44
+ });
45
+ export default /*#__PURE__*/memo(PanelSearchInput);
@@ -130,6 +130,7 @@ export default (function () {
130
130
  return _ref3.apply(this, arguments);
131
131
  };
132
132
  }()),
133
+ searchInPanel: true,
133
134
  multiple: true,
134
135
  onChange: setMultipleValue
135
136
  }), /*#__PURE__*/_jsx(McSelect, {
@@ -0,0 +1,2 @@
1
+ declare const _default: () => import("react/jsx-runtime").JSX.Element;
2
+ export default _default;
@@ -0,0 +1,47 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
2
+ /**
3
+ * title: 搜索框下移+已选中的优先展示
4
+ * description: 默认都为false,仅支持多选
5
+ */
6
+ import { Space } from 'antd';
7
+ import { McSelect } from "../..";
8
+ import { useState } from 'react';
9
+ import { jsx as _jsx } from "react/jsx-runtime";
10
+ var options = [{
11
+ value: 'jack',
12
+ label: 'Jack'
13
+ }, {
14
+ value: 'lucy',
15
+ label: 'Lucy'
16
+ }, {
17
+ value: 'Yiminghe',
18
+ label: 'yiminghe'
19
+ }, {
20
+ value: 'disabled',
21
+ label: 'Disabled',
22
+ disabled: true
23
+ }];
24
+ export default (function () {
25
+ var _useState = useState(options),
26
+ _useState2 = _slicedToArray(_useState, 2),
27
+ finalOptions = _useState2[0],
28
+ setFinalOptions = _useState2[1];
29
+ return /*#__PURE__*/_jsx(Space, {
30
+ wrap: true,
31
+ children: /*#__PURE__*/_jsx(McSelect, {
32
+ style: {
33
+ width: 240
34
+ },
35
+ searchInPanel: true,
36
+ pinSelectedOptions: true,
37
+ searchInPanelPlaceholder: "\u81EA\u5B9A\u4E49\u641C\u7D22\u6846\u63D0\u793A\u6587\u5B57",
38
+ options: finalOptions,
39
+ onSearch: function onSearch(v) {
40
+ return setFinalOptions(options.filter(function (item) {
41
+ return item.value.includes(v);
42
+ }));
43
+ },
44
+ multiple: true
45
+ })
46
+ });
47
+ });
@@ -25,6 +25,7 @@ export type FetchOptions = (params: {
25
25
  export type McSelectProps = Omit<SelectProps, 'mode' | 'fieldNames'> & {
26
26
  style?: CSSProperties;
27
27
  className?: string;
28
+ /** 外部控制展示的options */
28
29
  toFilterOptions?: (options: Option[]) => Option[];
29
30
  name?: string;
30
31
  label?: ReactNode;
@@ -35,6 +36,12 @@ export type McSelectProps = Omit<SelectProps, 'mode' | 'fieldNames'> & {
35
36
  pageSize?: number;
36
37
  extra?: any;
37
38
  options?: Option[];
39
+ /** 仅多选生效。默认为false,在下拉框中展示搜索框,会影响回车生成新标签等功能 */
40
+ searchInPanel?: boolean;
41
+ /** 搜索框提示文字 */
42
+ searchInPanelPlaceholder?: string;
43
+ /** 仅多选+("非远程"或"远程+labelvalue"")生效。默认为false,将选中项置顶。 */
44
+ pinSelectedOptions?: boolean;
38
45
  };
39
46
  declare const McSelect: FC<McSelectProps>;
40
47
  export default McSelect;
@@ -3,13 +3,45 @@ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
3
3
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
4
4
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
5
5
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
6
- var _excluded = ["style", "className", "label", "multiple", "changeOnHidden", "inexistent", "fetchOptions", "pageSize", "extra", "value", "onChange", "labelInValue", "options", "disabled", "maxTagCount", "onSearch", "onPopupScroll", "onBlur", "onDropdownVisibleChange", "toFilterOptions"];
6
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
7
+ import _typeof from "@babel/runtime/helpers/esm/typeof";
8
+ var _excluded = ["style", "className", "label", "multiple", "changeOnHidden", "inexistent", "fetchOptions", "pageSize", "extra", "value", "onChange", "labelInValue", "options", "disabled", "maxTagCount", "onSearch", "onPopupScroll", "onBlur", "onDropdownVisibleChange", "toFilterOptions", "searchInPanel", "pinSelectedOptions", "searchInPanelPlaceholder"];
7
9
  import { Empty, Popover, Select, Spin } from 'antd';
8
10
  import { debounce } from "../Utils";
9
11
  import { forwardRef, useCallback, useEffect, useMemo, useRef, useState } from 'react';
12
+ import PanelSearchInput from "./components/PanelSearchInput";
10
13
  import "./index.css";
11
14
  import { jsx as _jsx } from "react/jsx-runtime";
15
+ import { Fragment as _Fragment } from "react/jsx-runtime";
12
16
  import { jsxs as _jsxs } from "react/jsx-runtime";
17
+ // 将已选的option置顶
18
+ var createPinedSelectedOptions = function createPinedSelectedOptions(options, selectedValues) {
19
+ if (!options || options.length === 0) return [];
20
+ if (!selectedValues || selectedValues.length === 0) return options;
21
+ var isLabelInValue = _typeof(selectedValues[0]) === 'object';
22
+ if (isLabelInValue) {
23
+ var unselectedOptions = options.filter(function (o) {
24
+ return !selectedValues.some(function (v) {
25
+ return v.value === o.value;
26
+ });
27
+ });
28
+ return [].concat(_toConsumableArray(selectedValues), _toConsumableArray(unselectedOptions));
29
+ } else {
30
+ var _options$filter;
31
+ // options中找不到的就不展示
32
+ var selectedOptions = selectedValues.map(function (v) {
33
+ return options.find(function (o) {
34
+ return o.value === v;
35
+ });
36
+ }).filter(function (o) {
37
+ return Boolean(o);
38
+ });
39
+ var _unselectedOptions = (_options$filter = options.filter(function (x) {
40
+ return !selectedValues.includes(x.value);
41
+ })) !== null && _options$filter !== void 0 ? _options$filter : [];
42
+ return [].concat(_toConsumableArray(selectedOptions), _toConsumableArray(_unselectedOptions));
43
+ }
44
+ };
13
45
  var McSelect = /*#__PURE__*/forwardRef(function (props, ref) {
14
46
  var style = props.style,
15
47
  className = props.className,
@@ -33,6 +65,11 @@ var McSelect = /*#__PURE__*/forwardRef(function (props, ref) {
33
65
  onBlur = props.onBlur,
34
66
  onDropdownVisibleChange = props.onDropdownVisibleChange,
35
67
  toFilterOptions = props.toFilterOptions,
68
+ _props$searchInPanel = props.searchInPanel,
69
+ searchInPanel = _props$searchInPanel === void 0 ? false : _props$searchInPanel,
70
+ _props$pinSelectedOpt = props.pinSelectedOptions,
71
+ pinSelectedOptions = _props$pinSelectedOpt === void 0 ? false : _props$pinSelectedOpt,
72
+ searchInPanelPlaceholder = props.searchInPanelPlaceholder,
36
73
  rest = _objectWithoutProperties(props, _excluded);
37
74
  var _ref = typeof inexistent === 'boolean' ? {} : inexistent,
38
75
  _ref$inexistentText = _ref.inexistentText,
@@ -88,7 +125,19 @@ var McSelect = /*#__PURE__*/forwardRef(function (props, ref) {
88
125
  var _oldValue = useRef();
89
126
  var _changeOption = useRef();
90
127
  var _inexistent = useRef(false);
91
- var filteredOptions = toFilterOptions ? toFilterOptions(selectOptions) : selectOptions; // 只要有render就需要重新生成options
128
+ var panelSearchInputRef = useRef(null);
129
+ var useDefaultSearch = !(multiple && searchInPanel);
130
+ var optionWithPriority = useMemo(function () {
131
+ if (pinSelectedOptions && multiple) {
132
+ if (fetchOptions && !labelInValue) {
133
+ console.warn('远程搜索下,pinSelectedOptions只支持labelInValue模式,建议修改');
134
+ } else {
135
+ return createPinedSelectedOptions(selectOptions, selectValue);
136
+ }
137
+ }
138
+ return selectOptions;
139
+ }, [selectOptions, selectValue]);
140
+ var filteredOptions = toFilterOptions ? toFilterOptions(optionWithPriority) : optionWithPriority; // 只要有render就需要重新生成options
92
141
 
93
142
  // 监听值和备选项的变化(赋值备选项,执行不存在值的判断逻辑)
94
143
  useEffect(function () {
@@ -216,7 +265,7 @@ var McSelect = /*#__PURE__*/forwardRef(function (props, ref) {
216
265
 
217
266
  // 文本框值变化时回调
218
267
  var search = function search(v) {
219
- var _v = v.trim();
268
+ var _v = (v === null || v === void 0 ? void 0 : v.trim()) || '';
220
269
  setSearchValue(_v);
221
270
  if (fetchOptions) {
222
271
  debounceSearcher(_v, 1);
@@ -256,13 +305,16 @@ var McSelect = /*#__PURE__*/forwardRef(function (props, ref) {
256
305
  }
257
306
  onPopupScroll === null || onPopupScroll === void 0 || onPopupScroll(e);
258
307
  };
308
+ var clearSearchData = function clearSearchData() {
309
+ setSearchValue('');
310
+ loadOptions('', 1);
311
+ };
259
312
 
260
313
  // 失去焦点时的回调(若为异步分页查询,需重置查询)
261
314
  var blur = function blur(e) {
262
315
  // 若当前文本框有值,则清空文本框并重置查询
263
- if (searchValue) {
264
- setSearchValue('');
265
- loadOptions('', 1);
316
+ if (useDefaultSearch && searchValue) {
317
+ clearSearchData();
266
318
  }
267
319
  onBlur === null || onBlur === void 0 || onBlur(e);
268
320
  };
@@ -279,8 +331,38 @@ var McSelect = /*#__PURE__*/forwardRef(function (props, ref) {
279
331
  }
280
332
  }
281
333
  }
334
+ // 新版搜索交互逻辑
335
+ if (!useDefaultSearch) {
336
+ if (open) {
337
+ var _panelSearchInputRef$;
338
+ (_panelSearchInputRef$ = panelSearchInputRef.current) === null || _panelSearchInputRef$ === void 0 || _panelSearchInputRef$.focus();
339
+ } else if (searchValue) {
340
+ // 避免界面抖动
341
+ setTimeout(clearSearchData, 200);
342
+ }
343
+ }
282
344
  onDropdownVisibleChange === null || onDropdownVisibleChange === void 0 || onDropdownVisibleChange(open);
283
345
  };
346
+ var renderDropdownPanel = function renderDropdownPanel(menu) {
347
+ if (!multiple || !searchInPanel) {
348
+ return menu;
349
+ }
350
+ return /*#__PURE__*/_jsxs(_Fragment, {
351
+ children: [/*#__PURE__*/_jsx(PanelSearchInput, {
352
+ ref: panelSearchInputRef,
353
+ placeholder: searchInPanelPlaceholder,
354
+ searchValue: searchValue,
355
+ onSearch: search
356
+ }), menu, filteredOptions.length > 0 && fetching && /*#__PURE__*/_jsx("div", {
357
+ style: {
358
+ color: '#999',
359
+ fontSize: 12,
360
+ textAlign: 'center'
361
+ },
362
+ children: "\u52A0\u8F7D\u4E2D..."
363
+ })]
364
+ });
365
+ };
284
366
  return /*#__PURE__*/_jsxs("div", {
285
367
  style: _objectSpread({
286
368
  position: label ? 'relative' : 'static',
@@ -302,7 +384,8 @@ var McSelect = /*#__PURE__*/forwardRef(function (props, ref) {
302
384
  options: filteredOptions,
303
385
  disabled: disabled,
304
386
  placeholder: "\u8BF7\u9009\u62E9",
305
- showSearch: true,
387
+ showSearch: useDefaultSearch // 否则会和panel中的search冲突
388
+ ,
306
389
  optionFilterProp: "label",
307
390
  allowClear: true,
308
391
  maxTagCount: _maxTagCount,
@@ -332,8 +415,8 @@ var McSelect = /*#__PURE__*/forwardRef(function (props, ref) {
332
415
  });
333
416
  },
334
417
  filterOption: fetchOptions ? false : true,
335
- searchValue: searchValue,
336
- onSearch: search,
418
+ searchValue: useDefaultSearch ? searchValue : undefined,
419
+ onSearch: useDefaultSearch ? search : undefined,
337
420
  loading: fetching,
338
421
  notFoundContent: fetching ? /*#__PURE__*/_jsx(Spin, {
339
422
  size: "small"
@@ -342,7 +425,8 @@ var McSelect = /*#__PURE__*/forwardRef(function (props, ref) {
342
425
  }),
343
426
  onPopupScroll: popupScroll,
344
427
  onBlur: blur,
345
- onDropdownVisibleChange: dropdownVisibleChange
428
+ onDropdownVisibleChange: dropdownVisibleChange,
429
+ dropdownRender: renderDropdownPanel
346
430
  }, rest), {}, {
347
431
  mode: multiple ? 'multiple' : undefined,
348
432
  fieldNames: undefined
@@ -0,0 +1,2 @@
1
+ declare const _default: () => import("react/jsx-runtime").JSX.Element;
2
+ export default _default;