@apdesign/web-react 1.3.3 → 1.4.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.
- package/dist/arco-icon.min.js +1 -1
- package/dist/arco.development.js +9 -9
- package/dist/arco.min.js +2 -2
- package/es/Button/index.d.ts +3 -3
- package/es/DatePicker/picker-range.d.ts +1 -1
- package/es/DatePicker/util.d.ts +1 -1
- package/es/Menu/context.d.ts +1 -1
- package/es/Select/option.js +6 -3
- package/es/Select/select.js +21 -5
- package/es/Tree/index.js +15 -0
- package/es/TreeSelect/hook/useStateValue.d.ts +1 -1
- package/es/TreeSelect/hook/useStateValue.js +44 -3
- package/es/TreeSelect/interface.d.ts +6 -0
- package/es/TreeSelect/tree-list.d.ts +1 -0
- package/es/TreeSelect/tree-list.js +38 -3
- package/es/TreeSelect/tree-select.js +57 -11
- package/es/_util/constant.d.ts +1 -1
- package/es/index.d.ts +1 -1
- package/es/index.js +1 -1
- package/es/locale/en-US.d.ts +5 -0
- package/es/locale/en-US.js +5 -0
- package/es/locale/interface.d.ts +1 -0
- package/es/locale/zh-CN.d.ts +5 -0
- package/es/locale/zh-CN.js +5 -0
- package/lib/Select/option.js +5 -2
- package/lib/Select/select.js +20 -4
- package/lib/Tree/index.js +15 -0
- package/lib/TreeSelect/hook/useStateValue.d.ts +1 -1
- package/lib/TreeSelect/hook/useStateValue.js +44 -3
- package/lib/TreeSelect/interface.d.ts +6 -0
- package/lib/TreeSelect/tree-list.d.ts +1 -0
- package/lib/TreeSelect/tree-list.js +37 -2
- package/lib/TreeSelect/tree-select.js +57 -11
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/locale/en-US.d.ts +5 -0
- package/lib/locale/en-US.js +5 -0
- package/lib/locale/interface.d.ts +1 -0
- package/lib/locale/zh-CN.d.ts +5 -0
- package/lib/locale/zh-CN.js +5 -0
- package/package.json +1 -1
package/es/Button/index.d.ts
CHANGED
|
@@ -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" | "
|
|
6
|
-
} & import("./interface").BaseButtonProps & Omit<React.ButtonHTMLAttributes<any>, "className" | "
|
|
5
|
+
htmlType?: "button" | "reset" | "submit";
|
|
6
|
+
} & import("./interface").BaseButtonProps & Omit<React.ButtonHTMLAttributes<any>, "className" | "onClick" | "type"> & {
|
|
7
7
|
href: string;
|
|
8
8
|
target?: string;
|
|
9
9
|
anchorProps?: React.HTMLProps<HTMLAnchorElement>;
|
|
10
|
-
} & Omit<React.AnchorHTMLAttributes<any>, "className" | "
|
|
10
|
+
} & Omit<React.AnchorHTMLAttributes<any>, "className" | "onClick" | "type">> & React.RefAttributes<unknown>> & {
|
|
11
11
|
__BYTE_BUTTON: boolean;
|
|
12
12
|
Group: typeof Group;
|
|
13
13
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { RangePickerHandle } from './interface';
|
|
3
|
-
declare const PickerComponent: React.ForwardRefExoticComponent<import("./interface").BaseRangePickerProps & import("../_util/type").Omit<import("./interface").PickerProps, "onChange" | "onSelect" | "
|
|
3
|
+
declare const PickerComponent: React.ForwardRefExoticComponent<import("./interface").BaseRangePickerProps & import("../_util/type").Omit<import("./interface").PickerProps, "onChange" | "onSelect" | "onOk" | "defaultPickerValue" | "pickerValue" | "onPickerValueChange" | "inputProps"> & React.RefAttributes<RangePickerHandle>>;
|
|
4
4
|
export default PickerComponent;
|
package/es/DatePicker/util.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Dayjs } from 'dayjs';
|
|
2
2
|
export declare function isTimeArrayChange(prevTime: Dayjs[], nextTime: Dayjs[]): boolean;
|
|
3
|
-
export declare function getAvailableDayjsLength(value: any):
|
|
3
|
+
export declare function getAvailableDayjsLength(value: any): 0 | 1 | 2;
|
|
4
4
|
export declare function isDisabledDate(cellDate: any, disabledDate: any, mode: any): boolean;
|
|
5
5
|
declare type WeekStartType = 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
|
6
6
|
export declare function getDefaultWeekStart(dayjsLocale: string): WeekStartType;
|
package/es/Menu/context.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export declare type HotkeyInfo = {
|
|
|
6
6
|
type: 'sibling' | 'generation' | 'enter';
|
|
7
7
|
};
|
|
8
8
|
export declare type ResetHotkeyInfo = (activeKey?: string) => void;
|
|
9
|
-
declare const MenuContext: import("react").Context<Pick<MenuProps, "
|
|
9
|
+
declare const MenuContext: import("react").Context<Pick<MenuProps, "collapse" | "inDropdown" | "theme" | "mode" | "levelIndent" | "icons" | "autoScrollIntoView" | "selectedKeys" | "openKeys" | "scrollConfig" | "triggerProps" | "tooltipProps"> & {
|
|
10
10
|
id?: string;
|
|
11
11
|
prefixCls?: string;
|
|
12
12
|
onClickMenuItem?: (key: string, event: any) => void;
|
package/es/Select/option.js
CHANGED
|
@@ -36,14 +36,17 @@ var __read = (this && this.__read) || function (o, n) {
|
|
|
36
36
|
}
|
|
37
37
|
return ar;
|
|
38
38
|
};
|
|
39
|
-
import React, { useState } from 'react';
|
|
39
|
+
import React, { useContext, useState } from 'react';
|
|
40
40
|
import cs from '../_util/classNames';
|
|
41
41
|
import Checkbox from '../Checkbox';
|
|
42
42
|
import omit from '../_util/omit';
|
|
43
|
+
import { ConfigContext } from '../ConfigProvider';
|
|
43
44
|
function Option(props, ref) {
|
|
44
45
|
var _a, _b;
|
|
46
|
+
var _c;
|
|
45
47
|
var style = props.style, className = props.className, wrapperClassName = props.wrapperClassName, disabled = props.disabled, prefixCls = props.prefixCls, rtl = props.rtl, propValue = props.value, propChildren = props.children, _isMultipleMode = props._isMultipleMode, _isMultipleQuickSelectMode = props._isMultipleQuickSelectMode, _onSingleQuickSelect = props._onSingleQuickSelect, _isUserCreatedOption = props._isUserCreatedOption, _isUserCreatingOption = props._isUserCreatingOption, _valueActive = props._valueActive, _valueSelect = props._valueSelect, _onMouseEnter = props._onMouseEnter, _onMouseLeave = props._onMouseLeave, _onClick = props._onClick, rest = __rest(props, ["style", "className", "wrapperClassName", "disabled", "prefixCls", "rtl", "value", "children", "_isMultipleMode", "_isMultipleQuickSelectMode", "_onSingleQuickSelect", "_isUserCreatedOption", "_isUserCreatingOption", "_valueActive", "_valueSelect", "_onMouseEnter", "_onMouseLeave", "_onClick"]);
|
|
46
|
-
var
|
|
48
|
+
var locale = useContext(ConfigContext).locale;
|
|
49
|
+
var _d = __read(useState(false), 2), isHovering = _d[0], setIsHovering = _d[1];
|
|
47
50
|
var value = 'value' in props ? propValue : "" + propChildren;
|
|
48
51
|
var childNode = 'children' in props ? propChildren : "" + propValue;
|
|
49
52
|
var isChecked = _isMultipleMode
|
|
@@ -106,7 +109,7 @@ function Option(props, ref) {
|
|
|
106
109
|
marginLeft: '-20px',
|
|
107
110
|
clipPath: 'polygon(12px 50%, 0% 0%, 100% 0%, 100% 100%, 0% 100%)',
|
|
108
111
|
whiteSpace: 'nowrap',
|
|
109
|
-
}, onClick: function () { return _onSingleQuickSelect === null || _onSingleQuickSelect === void 0 ? void 0 : _onSingleQuickSelect(value); } },
|
|
112
|
+
}, onClick: function () { return _onSingleQuickSelect === null || _onSingleQuickSelect === void 0 ? void 0 : _onSingleQuickSelect(value); } }, (_c = locale.Select) === null || _c === void 0 ? void 0 : _c.filterThisItemOnly)))));
|
|
110
113
|
}
|
|
111
114
|
return (React.createElement("li", __assign({}, wrapperProps, optionLabelProps), childNode));
|
|
112
115
|
}
|
package/es/Select/select.js
CHANGED
|
@@ -52,7 +52,7 @@ import Trigger from '../Trigger';
|
|
|
52
52
|
import OptGroup from './opt-group';
|
|
53
53
|
import Option from './option';
|
|
54
54
|
import ResizeObserver from '../_util/resizeObserver';
|
|
55
|
-
import { isArray, isFunction, isObject } from '../_util/is';
|
|
55
|
+
import { isArray, isFunction, isNullOrUndefined, isObject } from '../_util/is';
|
|
56
56
|
import getHotkeyHandler from '../_util/getHotkeyHandler';
|
|
57
57
|
import warning from '../_util/warning';
|
|
58
58
|
import SelectView from '../_class/select-view';
|
|
@@ -76,7 +76,7 @@ var defaultProps = {
|
|
|
76
76
|
};
|
|
77
77
|
var triggerPopupAlign = { bottom: 4 };
|
|
78
78
|
function Select(baseProps, ref) {
|
|
79
|
-
var _a = useContext(ConfigContext), getPrefixCls = _a.getPrefixCls, renderEmpty = _a.renderEmpty, componentConfig = _a.componentConfig, rtl = _a.rtl;
|
|
79
|
+
var _a = useContext(ConfigContext), getPrefixCls = _a.getPrefixCls, renderEmpty = _a.renderEmpty, componentConfig = _a.componentConfig, rtl = _a.rtl, locale = _a.locale;
|
|
80
80
|
var props = useMergeProps(baseProps, defaultProps, componentConfig === null || componentConfig === void 0 ? void 0 : componentConfig.Select);
|
|
81
81
|
var children = props.children, renderFormat = props.renderFormat, defaultActiveFirstOption = props.defaultActiveFirstOption, disabled = props.disabled, unmountOnExit = props.unmountOnExit, notFoundContent = props.notFoundContent, showSearch = props.showSearch, tokenSeparators = props.tokenSeparators, options = props.options, filterOption = props.filterOption, labelInValue = props.labelInValue, getPopupContainer = props.getPopupContainer, isQuickSingleSelectMode = props.isQuickSingleSelectMode, trigger = props.trigger, triggerElement = props.triggerElement, triggerProps = props.triggerProps, dropdownRender = props.dropdownRender, dropdownMenuStyle = props.dropdownMenuStyle, dropdownMenuClassName = props.dropdownMenuClassName, virtualListProps = props.virtualListProps,
|
|
82
82
|
// events
|
|
@@ -146,6 +146,8 @@ function Select(baseProps, ref) {
|
|
|
146
146
|
var refPopupExiting = useRef(false);
|
|
147
147
|
// Unique ID of this select instance
|
|
148
148
|
var instancePopupID = useId(prefixCls + "-popup-");
|
|
149
|
+
// 添加一个 ref 来跟踪 props.value 的前一个值
|
|
150
|
+
var prevValueRef = useRef(props.value);
|
|
149
151
|
var isNoOptionSelected = isEmptyValue(value, isMultipleMode);
|
|
150
152
|
var valueActiveDefault = useMemo(function () {
|
|
151
153
|
var _a, _b;
|
|
@@ -213,6 +215,20 @@ function Select(baseProps, ref) {
|
|
|
213
215
|
setProxyValue(value.length === 0 ? undefined : value[0]);
|
|
214
216
|
}
|
|
215
217
|
}, [isMultipleMode, value]);
|
|
218
|
+
useEffect(function () {
|
|
219
|
+
if (isMultipleQuickSelectMode) {
|
|
220
|
+
// 判断 props.value 之前有值现在被手动设置为 undefined 或者 []
|
|
221
|
+
var hadValueBefore = !isNullOrUndefined(prevValueRef.current) &&
|
|
222
|
+
!(Array.isArray(prevValueRef.current) && prevValueRef.current.length === 0);
|
|
223
|
+
var isEmptyNow = isNullOrUndefined(props.value) || (Array.isArray(props.value) && props.value.length === 0);
|
|
224
|
+
if (hadValueBefore && isEmptyNow) {
|
|
225
|
+
setValue(getValidValue(props.value, isMultipleMode, labelInValue));
|
|
226
|
+
setProxyValue(getValidValue(props.value, isMultipleMode, labelInValue));
|
|
227
|
+
}
|
|
228
|
+
// 更新 ref 以保存当前值用于下次比较
|
|
229
|
+
prevValueRef.current = props.value;
|
|
230
|
+
}
|
|
231
|
+
}, [props.value, isMultipleQuickSelectMode]);
|
|
216
232
|
// 选项下拉框显示/隐藏时的一些自动行为
|
|
217
233
|
useEffect(function () {
|
|
218
234
|
if (popupVisible) {
|
|
@@ -501,7 +517,7 @@ function Select(baseProps, ref) {
|
|
|
501
517
|
]));
|
|
502
518
|
var renderPopup = function () {
|
|
503
519
|
var _a;
|
|
504
|
-
var _b, _c;
|
|
520
|
+
var _b, _c, _d, _e;
|
|
505
521
|
// 没有设置弹出框的 width 时,需要在虚拟列表渲染的瞬间获得子元素的最大宽度
|
|
506
522
|
var needMeasureLongestItem = (triggerProps === null || triggerProps === void 0 ? void 0 : triggerProps.autoAlignPopupWidth) === false &&
|
|
507
523
|
(!((_b = triggerProps === null || triggerProps === void 0 ? void 0 : triggerProps.style) === null || _b === void 0 ? void 0 : _b.width) || ((_c = triggerProps === null || triggerProps === void 0 ? void 0 : triggerProps.style) === null || _c === void 0 ? void 0 : _c.width) === 'auto');
|
|
@@ -554,8 +570,8 @@ function Select(baseProps, ref) {
|
|
|
554
570
|
padding: '8px 16px 4px',
|
|
555
571
|
borderTop: '1px solid var(--color-fill-3)',
|
|
556
572
|
} },
|
|
557
|
-
React.createElement(Button, { size: "mini", onClick: cancelCheck },
|
|
558
|
-
React.createElement(Button, { type: "primary", size: "mini", onClick: confirmCheck },
|
|
573
|
+
React.createElement(Button, { size: "mini", onClick: cancelCheck }, (_d = locale.Select) === null || _d === void 0 ? void 0 : _d.cancelText),
|
|
574
|
+
React.createElement(Button, { type: "primary", size: "mini", onClick: confirmCheck }, (_e = locale.Select) === null || _e === void 0 ? void 0 : _e.okText))))) : null;
|
|
559
575
|
// Avoid drop-down box jitter when user is creating a selection
|
|
560
576
|
var isUserCreating = allowCreate && inputValue;
|
|
561
577
|
// Dropdown-placeholder when there is no options
|
package/es/Tree/index.js
CHANGED
|
@@ -106,6 +106,21 @@ import { ConfigContext } from '../ConfigProvider';
|
|
|
106
106
|
import { getAllCheckedKeysByCheck, getCheckedKeysByInitKeys, getTreeDataFromTreeChildren, } from './util';
|
|
107
107
|
import { TreeContext } from './context';
|
|
108
108
|
import { pickDataAttributes } from '../_util/pick';
|
|
109
|
+
var style = document.createElement('style');
|
|
110
|
+
document.head.appendChild(style);
|
|
111
|
+
// 动态写入 hover 样式
|
|
112
|
+
var rules = [
|
|
113
|
+
".arco-tree-node:hover .arco-tree-select-extra-QuickSingleSelect-button { display: block !important; }",
|
|
114
|
+
];
|
|
115
|
+
rules.forEach(function (rule) {
|
|
116
|
+
try {
|
|
117
|
+
var styleSheet = style.sheet;
|
|
118
|
+
style.sheet.insertRule(rule, styleSheet.cssRules.length);
|
|
119
|
+
}
|
|
120
|
+
catch (e) {
|
|
121
|
+
console.error('插入 CSS 规则失败:', rule, e);
|
|
122
|
+
}
|
|
123
|
+
});
|
|
109
124
|
var DefaultFieldNames = {
|
|
110
125
|
key: 'key',
|
|
111
126
|
title: 'title',
|
|
@@ -25,6 +25,15 @@ var __read = (this && this.__read) || function (o, n) {
|
|
|
25
25
|
}
|
|
26
26
|
return ar;
|
|
27
27
|
};
|
|
28
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
29
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
30
|
+
if (ar || !(i in from)) {
|
|
31
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
32
|
+
ar[i] = from[i];
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
36
|
+
};
|
|
28
37
|
import { useState, useRef, useCallback } from 'react';
|
|
29
38
|
import isEqualWith from 'lodash/isEqualWith';
|
|
30
39
|
import { normalizeValueToArray } from '../utils';
|
|
@@ -81,6 +90,8 @@ var getInitCheckKeys = function (keys, key2nodeProps, indeterminateKeys, props)
|
|
|
81
90
|
return keys;
|
|
82
91
|
};
|
|
83
92
|
var useStateValue = function (props, key2nodeProps, indeterminateKeys) {
|
|
93
|
+
var multiple = props.multiple || props.treeCheckable;
|
|
94
|
+
var isMultipleQuickSelectMode = multiple && props.isQuickSingleSelectMode;
|
|
84
95
|
var valueCopy = useRef([]);
|
|
85
96
|
var calcValue = function () {
|
|
86
97
|
var propsValue = props.value || props.defaultValue || [];
|
|
@@ -93,10 +104,18 @@ var useStateValue = function (props, key2nodeProps, indeterminateKeys) {
|
|
|
93
104
|
return parseValue(propsValue, key2nodeProps);
|
|
94
105
|
};
|
|
95
106
|
var _a = __read(useState(calcValue), 2), value = _a[0], _setValue = _a[1];
|
|
107
|
+
// proxyValue 在isMultipleQuickSelectMode时候挡在真实value前面进行展示,真实的value只在确定时候更新。 proxyValue 必须和原有的value行为一致
|
|
108
|
+
var _b = __read(useState(value), 2), proxyValue = _b[0], _setProxyValue = _b[1];
|
|
109
|
+
var proxyValueCopy = useRef(value);
|
|
110
|
+
var stateValue = isMultipleQuickSelectMode ? proxyValue : value;
|
|
96
111
|
var setValue = function (value) {
|
|
97
112
|
valueCopy.current = value;
|
|
98
113
|
_setValue(value);
|
|
99
114
|
};
|
|
115
|
+
var setProxyValue = function (value) {
|
|
116
|
+
proxyValueCopy.current = value;
|
|
117
|
+
_setProxyValue(value);
|
|
118
|
+
};
|
|
100
119
|
useUpdate(function () {
|
|
101
120
|
var nextValue = calcValue();
|
|
102
121
|
if ('value' in props) {
|
|
@@ -104,10 +123,12 @@ var useStateValue = function (props, key2nodeProps, indeterminateKeys) {
|
|
|
104
123
|
// 以外部传入为准,只比较value
|
|
105
124
|
if (!isEqualWith(normalizeValueToArray(value), normalizeValueToArray(nextValue))) {
|
|
106
125
|
setValue(nextValue);
|
|
126
|
+
setProxyValue(nextValue);
|
|
107
127
|
}
|
|
108
128
|
}
|
|
109
129
|
else if (!isEqualWith(value, nextValue)) {
|
|
110
130
|
setValue(nextValue);
|
|
131
|
+
setProxyValue(nextValue);
|
|
111
132
|
}
|
|
112
133
|
}
|
|
113
134
|
}, [
|
|
@@ -117,10 +138,14 @@ var useStateValue = function (props, key2nodeProps, indeterminateKeys) {
|
|
|
117
138
|
props.value,
|
|
118
139
|
key2nodeProps,
|
|
119
140
|
]);
|
|
141
|
+
var extra = useRef(null);
|
|
120
142
|
var setStateValue = useCallback(function (newValue, extra) {
|
|
121
143
|
var onChange = props.onChange, labelInValue = props.labelInValue;
|
|
122
144
|
var multiple = props.multiple || props.treeCheckable;
|
|
123
|
-
if (
|
|
145
|
+
if (isMultipleQuickSelectMode) {
|
|
146
|
+
setProxyValue(newValue);
|
|
147
|
+
}
|
|
148
|
+
if (!('value' in props) && !isMultipleQuickSelectMode) {
|
|
124
149
|
setValue(newValue);
|
|
125
150
|
}
|
|
126
151
|
var tmp;
|
|
@@ -132,8 +157,24 @@ var useStateValue = function (props, key2nodeProps, indeterminateKeys) {
|
|
|
132
157
|
else {
|
|
133
158
|
tmp = labelInValue ? newValue[0] : newValue[0] && newValue[0].value;
|
|
134
159
|
}
|
|
135
|
-
|
|
160
|
+
if (isMultipleQuickSelectMode) {
|
|
161
|
+
extra.current = extra;
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
onChange && onChange(tmp, extra);
|
|
165
|
+
}
|
|
136
166
|
}, [props.onChange, props.labelInValue, props.multiple, props.treeCheckable, props.value]);
|
|
137
|
-
|
|
167
|
+
var confirmSetValue = function () {
|
|
168
|
+
var onChange = props.onChange, labelInValue = props.labelInValue;
|
|
169
|
+
setValue(__spreadArray([], __read(proxyValueCopy.current), false));
|
|
170
|
+
var tmp = proxyValueCopy.current.map(function (x) {
|
|
171
|
+
return labelInValue ? { label: x.label, value: x.value } : x.value;
|
|
172
|
+
});
|
|
173
|
+
onChange && onChange(tmp, extra.current);
|
|
174
|
+
};
|
|
175
|
+
var cancelSetValue = function () {
|
|
176
|
+
setProxyValue(value);
|
|
177
|
+
};
|
|
178
|
+
return [stateValue, setStateValue, value, confirmSetValue, cancelSetValue];
|
|
138
179
|
};
|
|
139
180
|
export default useStateValue;
|
|
@@ -19,6 +19,12 @@ export interface TreeSelectProps extends SelectViewCommonProps {
|
|
|
19
19
|
* @en Whether to select multiple
|
|
20
20
|
*/
|
|
21
21
|
multiple?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* @zh 是否开启快速单选模式。开启后,由于需要最后点击确定或者取消来选择,单个选项变化的事件将无效
|
|
24
|
+
* @en Whether to enable quick single selection mode.
|
|
25
|
+
* @defaultValue true
|
|
26
|
+
*/
|
|
27
|
+
isQuickSingleSelectMode?: boolean;
|
|
22
28
|
/**
|
|
23
29
|
* @zh 选择框的默认值
|
|
24
30
|
* @en The key of node selected by default
|
|
@@ -7,6 +7,7 @@ interface TreeListProps extends TreeSelectProps {
|
|
|
7
7
|
filterNode: TreeProps['filterNode'];
|
|
8
8
|
inputValue?: string;
|
|
9
9
|
prefixCls?: string;
|
|
10
|
+
confirmCheck: () => void;
|
|
10
11
|
}
|
|
11
12
|
declare const _default: React.ForwardRefExoticComponent<TreeListProps & React.RefAttributes<unknown>>;
|
|
12
13
|
export default _default;
|
|
@@ -34,13 +34,17 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
34
34
|
}
|
|
35
35
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
36
36
|
};
|
|
37
|
-
import React, { useRef, useCallback, useMemo, useImperativeHandle, forwardRef } from 'react';
|
|
37
|
+
import React, { useRef, useCallback, useMemo, useImperativeHandle, forwardRef, useContext, } from 'react';
|
|
38
38
|
import Tree from '../Tree';
|
|
39
39
|
import { isFunction, isString } from '../_util/is';
|
|
40
|
+
import { ConfigContext } from '../ConfigProvider';
|
|
40
41
|
function TreeList(props, ref) {
|
|
41
|
-
var value = props.value, multiple = props.multiple, loadMore = props.loadMore, treeCheckedStrategy = props.treeCheckedStrategy, treeCheckStrictly = props.treeCheckStrictly, treeData = props.treeData, treeProps = props.treeProps, prefixCls = props.prefixCls, treeCheckable = props.treeCheckable;
|
|
42
|
+
var value = props.value, multiple = props.multiple, isQuickSingleSelectMode = props.isQuickSingleSelectMode, loadMore = props.loadMore, treeCheckedStrategy = props.treeCheckedStrategy, treeCheckStrictly = props.treeCheckStrictly, treeData = props.treeData, treeProps = props.treeProps, prefixCls = props.prefixCls, treeCheckable = props.treeCheckable, confirmCheck = props.confirmCheck;
|
|
43
|
+
var locale = useContext(ConfigContext).locale;
|
|
42
44
|
var propsRenderTitle = treeProps && treeProps.renderTitle;
|
|
45
|
+
var propsRenderExtra = treeProps && treeProps.renderExtra;
|
|
43
46
|
var treeRef = useRef();
|
|
47
|
+
var isMultipleQuickSelectMode = multiple && isQuickSingleSelectMode;
|
|
44
48
|
var handleCheck = useCallback(function (keys, _a) {
|
|
45
49
|
var checkedNodes = _a.checkedNodes, checked = _a.checked, node = _a.node;
|
|
46
50
|
var newValue = keys.map(function (key) {
|
|
@@ -120,6 +124,37 @@ function TreeList(props, ref) {
|
|
|
120
124
|
}
|
|
121
125
|
return title;
|
|
122
126
|
}, [prefixCls, props.inputValue, propsRenderTitle]);
|
|
127
|
+
var renderExtra = useCallback(function (nodeProps) {
|
|
128
|
+
var _a;
|
|
129
|
+
if (isMultipleQuickSelectMode) {
|
|
130
|
+
if (propsRenderExtra) {
|
|
131
|
+
console.warn('renderExtra is not recommended for use in quick single select mode');
|
|
132
|
+
}
|
|
133
|
+
return (React.createElement(React.Fragment, null,
|
|
134
|
+
React.createElement("span", { className: prefixCls + "-extra-QuickSingleSelect-button", style: {
|
|
135
|
+
position: 'absolute',
|
|
136
|
+
right: 0,
|
|
137
|
+
display: 'none',
|
|
138
|
+
backgroundColor: 'rgb(var(--primary-6))',
|
|
139
|
+
cursor: 'pointer',
|
|
140
|
+
color: 'white',
|
|
141
|
+
padding: '6px',
|
|
142
|
+
fontSize: 12,
|
|
143
|
+
paddingLeft: '20px',
|
|
144
|
+
clipPath: 'polygon(12px 50%, 0% 0%, 100% 0%, 100% 100%, 0% 100%)',
|
|
145
|
+
whiteSpace: 'nowrap',
|
|
146
|
+
}, onClick: function () {
|
|
147
|
+
handleCheck([nodeProps._key], {
|
|
148
|
+
checkedNodes: [],
|
|
149
|
+
checked: true,
|
|
150
|
+
node: { props: nodeProps },
|
|
151
|
+
});
|
|
152
|
+
confirmCheck();
|
|
153
|
+
} }, (_a = locale.Select) === null || _a === void 0 ? void 0 : _a.filterThisItemOnly), propsRenderExtra === null || propsRenderExtra === void 0 ? void 0 :
|
|
154
|
+
propsRenderExtra(nodeProps)));
|
|
155
|
+
}
|
|
156
|
+
return propsRenderExtra === null || propsRenderExtra === void 0 ? void 0 : propsRenderExtra(nodeProps);
|
|
157
|
+
}, [propsRenderExtra, isMultipleQuickSelectMode]);
|
|
123
158
|
var extraProps = useMemo(function () {
|
|
124
159
|
return props.treeCheckable
|
|
125
160
|
? {
|
|
@@ -139,6 +174,6 @@ function TreeList(props, ref) {
|
|
|
139
174
|
}, []);
|
|
140
175
|
return (React.createElement(Tree, __assign({ ref: treeRef, size: props.size, blockNode: true, filterNode: props.filterNode }, treeProps, { checkable: treeCheckable, multiple: multiple, loadMore: props.loadMore ? handleLoadMore : undefined, checkedStrategy: treeCheckedStrategy, checkStrictly: treeCheckStrictly, onMouseDown: function (e) {
|
|
141
176
|
e.preventDefault();
|
|
142
|
-
} }, extraProps, { treeData: treeData, fieldNames: props.fieldNames, renderTitle: renderTitle, onSelect: onSelect, selectedKeys: selectedKeys })));
|
|
177
|
+
} }, extraProps, { treeData: treeData, fieldNames: props.fieldNames, renderTitle: renderTitle, renderExtra: renderExtra, onSelect: onSelect, selectedKeys: selectedKeys })));
|
|
143
178
|
}
|
|
144
179
|
export default forwardRef(TreeList);
|
|
@@ -89,6 +89,7 @@ import cs from '../_util/classNames';
|
|
|
89
89
|
import useMergeProps from '../_util/hooks/useMergeProps';
|
|
90
90
|
import useIsFirstRender from '../_util/hooks/useIsFirstRender';
|
|
91
91
|
import useId from '../_util/hooks/useId';
|
|
92
|
+
import Button from '../Button';
|
|
92
93
|
function isEmptyValue(value) {
|
|
93
94
|
return (!value ||
|
|
94
95
|
(isArray(value) && value.length === 0) ||
|
|
@@ -98,10 +99,11 @@ var defaultProps = {
|
|
|
98
99
|
bordered: true,
|
|
99
100
|
treeCheckedStrategy: Tree.SHOW_CHILD,
|
|
100
101
|
fieldNames: DefaultFieldNames,
|
|
102
|
+
isQuickSingleSelectMode: true,
|
|
101
103
|
};
|
|
102
104
|
var triggerPopupAlign = { bottom: 4 };
|
|
103
105
|
var TreeSelect = function (baseProps, ref) {
|
|
104
|
-
var _a = useContext(ConfigContext), getPrefixCls = _a.getPrefixCls, renderEmpty = _a.renderEmpty, componentConfig = _a.componentConfig, rtl = _a.rtl;
|
|
106
|
+
var _a = useContext(ConfigContext), getPrefixCls = _a.getPrefixCls, renderEmpty = _a.renderEmpty, componentConfig = _a.componentConfig, rtl = _a.rtl, locale = _a.locale;
|
|
105
107
|
var props = useMergeProps(baseProps, defaultProps, componentConfig === null || componentConfig === void 0 ? void 0 : componentConfig.TreeSelect);
|
|
106
108
|
var refIsFirstRender = useIsFirstRender();
|
|
107
109
|
var triggerRef = useRef();
|
|
@@ -123,8 +125,9 @@ var TreeSelect = function (baseProps, ref) {
|
|
|
123
125
|
// 触发 onInputValueChange 回调的原因
|
|
124
126
|
var refOnInputChangeCallbackReason = useRef(null);
|
|
125
127
|
var onInputValueChange = props.onInputValueChange;
|
|
126
|
-
var _f = __read(useStateValue(props, key2nodeProps, indeterminateKeys), 2), value = _f[0], setValue = _f[1];
|
|
127
128
|
var multiple = props.multiple || props.treeCheckable;
|
|
129
|
+
var isMultipleQuickSelectMode = multiple && props.isQuickSingleSelectMode;
|
|
130
|
+
var _f = __read(useStateValue(props, key2nodeProps, indeterminateKeys), 5), value = _f[0], setValue = _f[1], realValue = _f[2], confirmSetValue = _f[3], cancelSetValue = _f[4];
|
|
128
131
|
var prefixCls = getPrefixCls('tree-select');
|
|
129
132
|
var isFilterNode = inputValue && !isFunction(props.onSearch);
|
|
130
133
|
// Unique ID of this select instance
|
|
@@ -134,6 +137,9 @@ var TreeSelect = function (baseProps, ref) {
|
|
|
134
137
|
if (visible !== popupVisible) {
|
|
135
138
|
setPopupVisible(visible);
|
|
136
139
|
(_a = props.onVisibleChange) === null || _a === void 0 ? void 0 : _a.call(props, visible);
|
|
140
|
+
if (isMultipleQuickSelectMode && !visible) {
|
|
141
|
+
cancelSetValue();
|
|
142
|
+
}
|
|
137
143
|
}
|
|
138
144
|
};
|
|
139
145
|
// 尝试更新 inputValue,并触发 onInputValueChange
|
|
@@ -206,6 +212,13 @@ var TreeSelect = function (baseProps, ref) {
|
|
|
206
212
|
tryUpdatePopupVisible(false);
|
|
207
213
|
}
|
|
208
214
|
}, [setValue, resetInputValue, popupVisible]);
|
|
215
|
+
var cancelCheck = function () {
|
|
216
|
+
tryUpdatePopupVisible(false);
|
|
217
|
+
};
|
|
218
|
+
var confirmCheck = function () {
|
|
219
|
+
confirmSetValue();
|
|
220
|
+
tryUpdatePopupVisible(false);
|
|
221
|
+
};
|
|
209
222
|
var handleRemoveCheckedItem = function (item, index, e) {
|
|
210
223
|
e.stopPropagation();
|
|
211
224
|
if (item.disabled) {
|
|
@@ -213,21 +226,31 @@ var TreeSelect = function (baseProps, ref) {
|
|
|
213
226
|
}
|
|
214
227
|
var itemValue = isObject(item.value) ? item.value.value : item.value;
|
|
215
228
|
if (!props.treeCheckable || props.treeCheckStrictly || !key2nodeProps[itemValue]) {
|
|
216
|
-
var newValue =
|
|
229
|
+
var newValue = realValue.filter(function (_, i) { return i !== index; });
|
|
217
230
|
triggerChange(newValue, {
|
|
218
231
|
trigger: key2nodeProps[itemValue] || item,
|
|
219
232
|
checked: false,
|
|
220
233
|
selected: false,
|
|
221
234
|
});
|
|
235
|
+
if (isMultipleQuickSelectMode) {
|
|
236
|
+
setTimeout(function () {
|
|
237
|
+
confirmCheck();
|
|
238
|
+
}, 0);
|
|
239
|
+
}
|
|
222
240
|
return;
|
|
223
241
|
}
|
|
224
|
-
var result = getAllCheckedKeysByCheck(itemValue, false, normalizeValueToArray(
|
|
242
|
+
var result = getAllCheckedKeysByCheck(itemValue, false, normalizeValueToArray(realValue), key2nodeProps, indeterminateKeys.current);
|
|
225
243
|
indeterminateKeys.current = result.indeterminateKeys;
|
|
226
|
-
triggerChange(parseValue(result.checkedKeys, key2nodeProps,
|
|
244
|
+
triggerChange(parseValue(result.checkedKeys, key2nodeProps, realValue), {
|
|
227
245
|
trigger: key2nodeProps[itemValue],
|
|
228
246
|
checked: false,
|
|
229
247
|
selected: false,
|
|
230
248
|
});
|
|
249
|
+
if (isMultipleQuickSelectMode) {
|
|
250
|
+
setTimeout(function () {
|
|
251
|
+
confirmCheck();
|
|
252
|
+
}, 0);
|
|
253
|
+
}
|
|
231
254
|
};
|
|
232
255
|
useEffect(function () {
|
|
233
256
|
inputValue !== undefined && handleSearch(inputValue);
|
|
@@ -290,12 +313,35 @@ var TreeSelect = function (baseProps, ref) {
|
|
|
290
313
|
var renderView = function (eleView) {
|
|
291
314
|
return (React.createElement(Trigger, __assign({ autoAlignPopupWidth: false, autoAlignPopupMinWidth: true, ref: triggerRef, classNames: "slideDynamicOrigin", trigger: "click", position: "bl", getPopupContainer: props.getPopupContainer, popupAlign: triggerPopupAlign, unmountOnExit: props.unmountOnExit }, props.triggerProps, { className: cs(prefixCls + "-trigger", props.triggerProps && props.triggerProps.className), popup: function () {
|
|
292
315
|
var _a;
|
|
293
|
-
var _b, _c, _d;
|
|
316
|
+
var _b, _c, _d, _e, _f;
|
|
294
317
|
var dropdownRender = props.dropdownRender;
|
|
295
|
-
var
|
|
296
|
-
|
|
318
|
+
var treeListDom = (React.createElement(TreeList, __assign({ prefixCls: prefixCls, ref: treeRef }, props, { inputValue: inputValue, filterNode: filterNode, value: value, onChange: triggerChange, multiple: multiple, treeData: treeData, confirmCheck: confirmCheck })));
|
|
319
|
+
var dom = (isFilterNode && isEmptyValue(searchKeys)) || isEmptyValue(treeData) ? (props.notFoundContent || renderEmpty('TreeSelect')) : isMultipleQuickSelectMode ? (React.createElement("div", { style: {
|
|
320
|
+
maxHeight: 188,
|
|
321
|
+
display: 'flex',
|
|
322
|
+
flexDirection: 'column',
|
|
323
|
+
} },
|
|
324
|
+
React.createElement("div", { style: { flex: 1, overflowY: 'auto' } }, treeListDom),
|
|
325
|
+
React.createElement("div", { style: {
|
|
326
|
+
flex: 'none',
|
|
327
|
+
display: 'flex',
|
|
328
|
+
justifyContent: 'flex-end',
|
|
329
|
+
gap: 12,
|
|
330
|
+
padding: '8px 16px 4px',
|
|
331
|
+
borderTop: '1px solid var(--color-fill-3)',
|
|
332
|
+
} },
|
|
333
|
+
React.createElement(Button, { size: "mini", onClick: cancelCheck }, (_b = locale.Select) === null || _b === void 0 ? void 0 : _b.cancelText),
|
|
334
|
+
React.createElement(Button, { type: "primary", size: "mini", onClick: function () {
|
|
335
|
+
confirmCheck();
|
|
336
|
+
} }, (_c = locale.Select) === null || _c === void 0 ? void 0 : _c.okText)))) : (treeListDom);
|
|
337
|
+
var wrapStyle = isMultipleQuickSelectMode
|
|
338
|
+
? {
|
|
339
|
+
overflow: 'hidden',
|
|
340
|
+
}
|
|
341
|
+
: {};
|
|
342
|
+
return (React.createElement("div", { id: instancePopupID, className: cs(prefixCls + "-popup", (_a = {}, _a[prefixCls + "-rtl-popup"] = rtl, _a)), style: __assign(__assign({ maxHeight: ((_d = props.treeProps) === null || _d === void 0 ? void 0 : _d.height) || ((_f = (_e = props.treeProps) === null || _e === void 0 ? void 0 : _e.virtualListProps) === null || _f === void 0 ? void 0 : _f.height)
|
|
297
343
|
? 'unset'
|
|
298
|
-
: '' }, props.dropdownMenuStyle) }, isFunction(dropdownRender) ? dropdownRender(dom) : dom));
|
|
344
|
+
: '' }, wrapStyle), props.dropdownMenuStyle) }, isFunction(dropdownRender) ? dropdownRender(dom) : dom));
|
|
299
345
|
}, disabled: props.disabled, onVisibleChange: function (visible) {
|
|
300
346
|
tryUpdatePopupVisible(visible);
|
|
301
347
|
// props.onVisibleChange && props.onVisibleChange(visible);
|
|
@@ -316,9 +362,9 @@ var TreeSelect = function (baseProps, ref) {
|
|
|
316
362
|
return props.triggerElement({ value: valueForCallback });
|
|
317
363
|
})()
|
|
318
364
|
: props.triggerElement;
|
|
319
|
-
return !isNullOrUndefined(customTriggerElement) ? (renderView(customTriggerElement)) : (React.createElement(SelectView, __assign({ ref: refSelectView, rtl: rtl, ariaControls: instancePopupID }, props, { popupVisible: popupVisible, value: !multiple && isArray(
|
|
365
|
+
return !isNullOrUndefined(customTriggerElement) ? (renderView(customTriggerElement)) : (React.createElement(SelectView, __assign({ ref: refSelectView, rtl: rtl, ariaControls: instancePopupID }, props, { popupVisible: popupVisible, value: !multiple && isArray(realValue) ? realValue[0] : realValue, inputValue: inputValue,
|
|
320
366
|
// other
|
|
321
|
-
isEmptyValue: isEmptyValue(
|
|
367
|
+
isEmptyValue: isEmptyValue(realValue), prefixCls: prefixCls, isMultiple: multiple, renderText: renderText, onSort: tryUpdateSelectValue, onRemoveCheckedItem: handleRemoveCheckedItem, onClear: function (e) {
|
|
322
368
|
var _a;
|
|
323
369
|
e.stopPropagation();
|
|
324
370
|
triggerChange([], {});
|
package/es/_util/constant.d.ts
CHANGED
|
@@ -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, "onClick" | "
|
|
3
|
+
export declare function pickTriggerPropsFromRest(rest: any): Pick<any, "onClick" | "tabIndex" | "onFocus" | "onBlur" | "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.
|
|
142
|
+
export declare const version = "1.4.0";
|
package/es/index.js
CHANGED
package/es/locale/en-US.d.ts
CHANGED
package/es/locale/en-US.js
CHANGED
package/es/locale/interface.d.ts
CHANGED
package/es/locale/zh-CN.d.ts
CHANGED
package/es/locale/zh-CN.js
CHANGED
package/lib/Select/option.js
CHANGED
|
@@ -64,10 +64,13 @@ var react_1 = __importStar(require("react"));
|
|
|
64
64
|
var classNames_1 = __importDefault(require("../_util/classNames"));
|
|
65
65
|
var Checkbox_1 = __importDefault(require("../Checkbox"));
|
|
66
66
|
var omit_1 = __importDefault(require("../_util/omit"));
|
|
67
|
+
var ConfigProvider_1 = require("../ConfigProvider");
|
|
67
68
|
function Option(props, ref) {
|
|
68
69
|
var _a, _b;
|
|
70
|
+
var _c;
|
|
69
71
|
var style = props.style, className = props.className, wrapperClassName = props.wrapperClassName, disabled = props.disabled, prefixCls = props.prefixCls, rtl = props.rtl, propValue = props.value, propChildren = props.children, _isMultipleMode = props._isMultipleMode, _isMultipleQuickSelectMode = props._isMultipleQuickSelectMode, _onSingleQuickSelect = props._onSingleQuickSelect, _isUserCreatedOption = props._isUserCreatedOption, _isUserCreatingOption = props._isUserCreatingOption, _valueActive = props._valueActive, _valueSelect = props._valueSelect, _onMouseEnter = props._onMouseEnter, _onMouseLeave = props._onMouseLeave, _onClick = props._onClick, rest = __rest(props, ["style", "className", "wrapperClassName", "disabled", "prefixCls", "rtl", "value", "children", "_isMultipleMode", "_isMultipleQuickSelectMode", "_onSingleQuickSelect", "_isUserCreatedOption", "_isUserCreatingOption", "_valueActive", "_valueSelect", "_onMouseEnter", "_onMouseLeave", "_onClick"]);
|
|
70
|
-
var
|
|
72
|
+
var locale = (0, react_1.useContext)(ConfigProvider_1.ConfigContext).locale;
|
|
73
|
+
var _d = __read((0, react_1.useState)(false), 2), isHovering = _d[0], setIsHovering = _d[1];
|
|
71
74
|
var value = 'value' in props ? propValue : "" + propChildren;
|
|
72
75
|
var childNode = 'children' in props ? propChildren : "" + propValue;
|
|
73
76
|
var isChecked = _isMultipleMode
|
|
@@ -130,7 +133,7 @@ function Option(props, ref) {
|
|
|
130
133
|
marginLeft: '-20px',
|
|
131
134
|
clipPath: 'polygon(12px 50%, 0% 0%, 100% 0%, 100% 100%, 0% 100%)',
|
|
132
135
|
whiteSpace: 'nowrap',
|
|
133
|
-
}, onClick: function () { return _onSingleQuickSelect === null || _onSingleQuickSelect === void 0 ? void 0 : _onSingleQuickSelect(value); } },
|
|
136
|
+
}, onClick: function () { return _onSingleQuickSelect === null || _onSingleQuickSelect === void 0 ? void 0 : _onSingleQuickSelect(value); } }, (_c = locale.Select) === null || _c === void 0 ? void 0 : _c.filterThisItemOnly)))));
|
|
134
137
|
}
|
|
135
138
|
return (react_1.default.createElement("li", __assign({}, wrapperProps, optionLabelProps), childNode));
|
|
136
139
|
}
|