@apdesign/web-react 1.5.1 → 1.6.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.
@@ -2,12 +2,12 @@ import React from 'react';
2
2
  import Group from './group';
3
3
  import { ButtonProps } from './interface';
4
4
  declare const ButtonComponent: React.ForwardRefExoticComponent<Partial<{
5
- htmlType?: "button" | "reset" | "submit";
6
- } & import("./interface").BaseButtonProps & Omit<React.ButtonHTMLAttributes<any>, "className" | "onClick" | "type"> & {
5
+ htmlType?: "button" | "submit" | "reset";
6
+ } & import("./interface").BaseButtonProps & Omit<React.ButtonHTMLAttributes<any>, "className" | "type" | "onClick"> & {
7
7
  href: string;
8
8
  target?: string;
9
9
  anchorProps?: React.HTMLProps<HTMLAnchorElement>;
10
- } & Omit<React.AnchorHTMLAttributes<any>, "className" | "onClick" | "type">> & React.RefAttributes<unknown>> & {
10
+ } & Omit<React.AnchorHTMLAttributes<any>, "className" | "type" | "onClick">> & React.RefAttributes<unknown>> & {
11
11
  __BYTE_BUTTON: boolean;
12
12
  Group: typeof Group;
13
13
  };
@@ -14,6 +14,12 @@ export declare type LabelValue = {
14
14
  * @title TreeSelect
15
15
  */
16
16
  export interface TreeSelectProps extends SelectViewCommonProps {
17
+ /**
18
+ * @zh 是否允许拼音搜索(仅在 showSearch 开启时生效)
19
+ * @en Whether to enable pinyin search (only works when showSearch is enabled)
20
+ * @defaultValue false
21
+ */
22
+ allowPYSearch?: boolean;
17
23
  /**
18
24
  * @zh 是否多选
19
25
  * @en Whether to select multiple
@@ -72,6 +72,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
72
72
  };
73
73
  import React, { forwardRef, useContext, useEffect, useRef, useState, useImperativeHandle, useMemo, useCallback, } from 'react';
74
74
  import debounce from 'lodash/debounce';
75
+ import PinyinMatch from 'pinyin-match';
75
76
  import useStateValue, { getInitCheckKeys, parseValue } from './hook/useStateValue';
76
77
  import { normalizeValueToArray } from './utils';
77
78
  import { isArray, isFunction, isNullOrUndefined, isObject } from '../_util/is';
@@ -91,6 +92,27 @@ import useIsFirstRender from '../_util/hooks/useIsFirstRender';
91
92
  import useId from '../_util/hooks/useId';
92
93
  import Button from '../Button';
93
94
  import Checkbox from '../Checkbox';
95
+ /** 与 value/_key 子串匹配,或在开启拼音时按 title(或 value)做拼音匹配 */
96
+ function matchNodeByTextAndPinyin(nodeProps, inputText, allowPYSearch) {
97
+ var text = nodeProps.value || nodeProps._key;
98
+ if (text && text.indexOf(inputText) > -1) {
99
+ return true;
100
+ }
101
+ if (!allowPYSearch) {
102
+ return false;
103
+ }
104
+ var displayText = typeof nodeProps.title === 'string' || typeof nodeProps.title === 'number'
105
+ ? String(nodeProps.title)
106
+ : typeof text === 'string' || typeof text === 'number'
107
+ ? String(text)
108
+ : '';
109
+ try {
110
+ return !!PinyinMatch.match(displayText, String(inputText || ''));
111
+ }
112
+ catch (_a) {
113
+ return false;
114
+ }
115
+ }
94
116
  function isEmptyValue(value) {
95
117
  return (!value ||
96
118
  (isArray(value) && value.length === 0) ||
@@ -131,6 +153,7 @@ var TreeSelect = function (baseProps, ref) {
131
153
  var _f = __read(useStateValue(props, key2nodeProps, indeterminateKeys), 5), value = _f[0], setValue = _f[1], realValue = _f[2], confirmSetValue = _f[3], cancelSetValue = _f[4];
132
154
  var prefixCls = getPrefixCls('tree-select');
133
155
  var isFilterNode = inputValue && !isFunction(props.onSearch);
156
+ var allowPYSearchEnabled = !!props.allowPYSearch && !!props.showSearch;
134
157
  // Unique ID of this select instance
135
158
  var instancePopupID = useId(prefixCls + "-popup-");
136
159
  var tryUpdatePopupVisible = function (visible) {
@@ -172,16 +195,17 @@ var TreeSelect = function (baseProps, ref) {
172
195
  var nodeProps = key2nodeProps[key];
173
196
  var isHit = false;
174
197
  if (isFunction(props.filterTreeNode)) {
198
+ // Keep historical behavior: user errors should throw.
175
199
  // @ts-ignore
176
200
  if (props.filterTreeNode(inputText, React.createElement(Tree.Node, __assign({}, nodeProps)))) {
177
201
  isHit = true;
178
202
  }
203
+ else if (allowPYSearchEnabled) {
204
+ isHit = matchNodeByTextAndPinyin(nodeProps, inputText, true);
205
+ }
179
206
  }
180
207
  else {
181
- var text = nodeProps.value || nodeProps._key;
182
- if (text && text.indexOf(inputText) > -1) {
183
- isHit = true;
184
- }
208
+ isHit = matchNodeByTextAndPinyin(nodeProps, inputText, allowPYSearchEnabled);
185
209
  }
186
210
  if (isHit) {
187
211
  hitKeys.add(nodeProps.key);
@@ -193,7 +217,7 @@ var TreeSelect = function (baseProps, ref) {
193
217
  });
194
218
  }); }, 100);
195
219
  return search(inputText);
196
- }, [props.onSearch, treeData, key2nodeProps, props.filterTreeNode]);
220
+ }, [props.onSearch, treeData, key2nodeProps, props.filterTreeNode, allowPYSearchEnabled]);
197
221
  var resetInputValue = useCallback(function () {
198
222
  // 多选选中值时候不清除搜索文本
199
223
  var retainInputValueWhileSelect = true;
@@ -1,3 +1,3 @@
1
1
  export declare const NOOP: () => void;
2
2
  export declare function newArray(length: number): any;
3
- export declare function pickTriggerPropsFromRest(rest: any): Pick<any, "onFocus" | "onBlur" | "onClick" | "tabIndex" | "onContextMenu" | "onMouseEnter" | "onMouseLeave" | "onMouseMove">;
3
+ export declare function pickTriggerPropsFromRest(rest: any): Pick<any, "onClick" | "onFocus" | "onBlur" | "tabIndex" | "onContextMenu" | "onMouseEnter" | "onMouseLeave" | "onMouseMove">;
package/es/index.d.ts CHANGED
@@ -139,4 +139,4 @@ export type { WatermarkProps } from './Watermark/interface';
139
139
  export { default as Watermark } from './Watermark';
140
140
  export type { ImageProps, ImagePreviewProps, ImagePreviewActionProps, ImagePreviewGroupProps } from './Image/interface';
141
141
  export { default as Image } from './Image';
142
- export declare const version = "1.5.1";
142
+ export declare const version = "1.6.0";
package/es/index.js CHANGED
@@ -69,4 +69,4 @@ export { default as Upload } from './Upload';
69
69
  export { default as Mentions } from './Mentions';
70
70
  export { default as Watermark } from './Watermark';
71
71
  export { default as Image } from './Image';
72
- export var version = '1.5.1';
72
+ export var version = '1.6.0';
@@ -14,6 +14,12 @@ export declare type LabelValue = {
14
14
  * @title TreeSelect
15
15
  */
16
16
  export interface TreeSelectProps extends SelectViewCommonProps {
17
+ /**
18
+ * @zh 是否允许拼音搜索(仅在 showSearch 开启时生效)
19
+ * @en Whether to enable pinyin search (only works when showSearch is enabled)
20
+ * @defaultValue false
21
+ */
22
+ allowPYSearch?: boolean;
17
23
  /**
18
24
  * @zh 是否多选
19
25
  * @en Whether to select multiple
@@ -96,6 +96,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
96
96
  Object.defineProperty(exports, "__esModule", { value: true });
97
97
  var react_1 = __importStar(require("react"));
98
98
  var debounce_1 = __importDefault(require("lodash/debounce"));
99
+ var pinyin_match_1 = __importDefault(require("pinyin-match"));
99
100
  var useStateValue_1 = __importStar(require("./hook/useStateValue"));
100
101
  var utils_1 = require("./utils");
101
102
  var is_1 = require("../_util/is");
@@ -115,6 +116,27 @@ var useIsFirstRender_1 = __importDefault(require("../_util/hooks/useIsFirstRende
115
116
  var useId_1 = __importDefault(require("../_util/hooks/useId"));
116
117
  var Button_1 = __importDefault(require("../Button"));
117
118
  var Checkbox_1 = __importDefault(require("../Checkbox"));
119
+ /** 与 value/_key 子串匹配,或在开启拼音时按 title(或 value)做拼音匹配 */
120
+ function matchNodeByTextAndPinyin(nodeProps, inputText, allowPYSearch) {
121
+ var text = nodeProps.value || nodeProps._key;
122
+ if (text && text.indexOf(inputText) > -1) {
123
+ return true;
124
+ }
125
+ if (!allowPYSearch) {
126
+ return false;
127
+ }
128
+ var displayText = typeof nodeProps.title === 'string' || typeof nodeProps.title === 'number'
129
+ ? String(nodeProps.title)
130
+ : typeof text === 'string' || typeof text === 'number'
131
+ ? String(text)
132
+ : '';
133
+ try {
134
+ return !!pinyin_match_1.default.match(displayText, String(inputText || ''));
135
+ }
136
+ catch (_a) {
137
+ return false;
138
+ }
139
+ }
118
140
  function isEmptyValue(value) {
119
141
  return (!value ||
120
142
  ((0, is_1.isArray)(value) && value.length === 0) ||
@@ -155,6 +177,7 @@ var TreeSelect = function (baseProps, ref) {
155
177
  var _f = __read((0, useStateValue_1.default)(props, key2nodeProps, indeterminateKeys), 5), value = _f[0], setValue = _f[1], realValue = _f[2], confirmSetValue = _f[3], cancelSetValue = _f[4];
156
178
  var prefixCls = getPrefixCls('tree-select');
157
179
  var isFilterNode = inputValue && !(0, is_1.isFunction)(props.onSearch);
180
+ var allowPYSearchEnabled = !!props.allowPYSearch && !!props.showSearch;
158
181
  // Unique ID of this select instance
159
182
  var instancePopupID = (0, useId_1.default)(prefixCls + "-popup-");
160
183
  var tryUpdatePopupVisible = function (visible) {
@@ -196,16 +219,17 @@ var TreeSelect = function (baseProps, ref) {
196
219
  var nodeProps = key2nodeProps[key];
197
220
  var isHit = false;
198
221
  if ((0, is_1.isFunction)(props.filterTreeNode)) {
222
+ // Keep historical behavior: user errors should throw.
199
223
  // @ts-ignore
200
224
  if (props.filterTreeNode(inputText, react_1.default.createElement(Tree_1.default.Node, __assign({}, nodeProps)))) {
201
225
  isHit = true;
202
226
  }
227
+ else if (allowPYSearchEnabled) {
228
+ isHit = matchNodeByTextAndPinyin(nodeProps, inputText, true);
229
+ }
203
230
  }
204
231
  else {
205
- var text = nodeProps.value || nodeProps._key;
206
- if (text && text.indexOf(inputText) > -1) {
207
- isHit = true;
208
- }
232
+ isHit = matchNodeByTextAndPinyin(nodeProps, inputText, allowPYSearchEnabled);
209
233
  }
210
234
  if (isHit) {
211
235
  hitKeys.add(nodeProps.key);
@@ -217,7 +241,7 @@ var TreeSelect = function (baseProps, ref) {
217
241
  });
218
242
  }); }, 100);
219
243
  return search(inputText);
220
- }, [props.onSearch, treeData, key2nodeProps, props.filterTreeNode]);
244
+ }, [props.onSearch, treeData, key2nodeProps, props.filterTreeNode, allowPYSearchEnabled]);
221
245
  var resetInputValue = (0, react_1.useCallback)(function () {
222
246
  // 多选选中值时候不清除搜索文本
223
247
  var retainInputValueWhileSelect = true;
package/lib/index.d.ts CHANGED
@@ -139,4 +139,4 @@ export type { WatermarkProps } from './Watermark/interface';
139
139
  export { default as Watermark } from './Watermark';
140
140
  export type { ImageProps, ImagePreviewProps, ImagePreviewActionProps, ImagePreviewGroupProps } from './Image/interface';
141
141
  export { default as Image } from './Image';
142
- export declare const version = "1.5.1";
142
+ export declare const version = "1.6.0";
package/lib/index.js CHANGED
@@ -147,4 +147,4 @@ var Watermark_1 = require("./Watermark");
147
147
  Object.defineProperty(exports, "Watermark", { enumerable: true, get: function () { return __importDefault(Watermark_1).default; } });
148
148
  var Image_1 = require("./Image");
149
149
  Object.defineProperty(exports, "Image", { enumerable: true, get: function () { return __importDefault(Image_1).default; } });
150
- exports.version = '1.5.1';
150
+ exports.version = '1.6.0';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apdesign/web-react",
3
- "version": "1.5.1",
3
+ "version": "1.6.0",
4
4
  "description": "AP Design React UI Library.",
5
5
  "module": "./es/index.js",
6
6
  "main": "./lib/index.js",
@@ -126,6 +126,7 @@
126
126
  "dayjs": "^1.10.5",
127
127
  "lodash": "^4.17.21",
128
128
  "number-precision": "^1.3.1",
129
+ "pinyin-match": "^1.2.10",
129
130
  "react-draggable": "^4.4.6",
130
131
  "react-focus-lock": "^2.12.1",
131
132
  "react-is": "^18.2.0",