@apdesign/web-react 1.2.0 → 1.3.1

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.
@@ -86,6 +86,7 @@ var ConfigProvider_1 = require("../ConfigProvider");
86
86
  var useMergeValue_1 = __importDefault(require("../_util/hooks/useMergeValue"));
87
87
  var omit_1 = __importDefault(require("../_util/omit"));
88
88
  var useMergeProps_1 = __importDefault(require("../_util/hooks/useMergeProps"));
89
+ var index_1 = require("../index");
89
90
  var useId_1 = __importDefault(require("../_util/hooks/useId"));
90
91
  // 用户创建中的option的origin标识
91
92
  var USER_CREATING_OPTION_ORIGIN = 'userCreatingOption';
@@ -94,13 +95,14 @@ var defaultProps = {
94
95
  bordered: true,
95
96
  filterOption: true,
96
97
  unmountOnExit: true,
98
+ isQuickSingleSelectMode: true,
97
99
  defaultActiveFirstOption: true,
98
100
  };
99
101
  var triggerPopupAlign = { bottom: 4 };
100
102
  function Select(baseProps, ref) {
101
103
  var _a = (0, react_1.useContext)(ConfigProvider_1.ConfigContext), getPrefixCls = _a.getPrefixCls, renderEmpty = _a.renderEmpty, componentConfig = _a.componentConfig, rtl = _a.rtl;
102
104
  var props = (0, useMergeProps_1.default)(baseProps, defaultProps, componentConfig === null || componentConfig === void 0 ? void 0 : componentConfig.Select);
103
- 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, trigger = props.trigger, triggerElement = props.triggerElement, triggerProps = props.triggerProps, dropdownRender = props.dropdownRender, dropdownMenuStyle = props.dropdownMenuStyle, dropdownMenuClassName = props.dropdownMenuClassName, virtualListProps = props.virtualListProps,
105
+ 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,
104
106
  // events
105
107
  onChange = props.onChange, onSelect = props.onSelect, onDeselect = props.onDeselect, onClear = props.onClear, onSearch = props.onSearch, onFocus = props.onFocus, onBlur = props.onBlur, onPopupScroll = props.onPopupScroll, onVisibleChange = props.onVisibleChange, onInputValueChange = props.onInputValueChange, onPaste = props.onPaste, onKeyDown = props.onKeyDown;
106
108
  // TODO 兼容逻辑,3.0 移除 tags 模式
@@ -112,35 +114,44 @@ function Select(baseProps, ref) {
112
114
  }
113
115
  var prefixCls = getPrefixCls('select');
114
116
  var isMultipleMode = mode === 'multiple';
117
+ var isMultipleQuickSelectMode = isMultipleMode && isQuickSingleSelectMode;
115
118
  // TODO: 统一 useMergeValue 函数的表现
116
119
  var _b = __read((0, react_1.useState)((0, utils_1.getValidValue)(props.defaultValue, isMultipleMode, labelInValue)), 2), stateValue = _b[0], setValue = _b[1];
117
- var value = 'value' in props ? (0, utils_1.getValidValue)(props.value, isMultipleMode, labelInValue) : stateValue;
118
- var _c = __read((0, useMergeValue_1.default)('', {
120
+ var _c = __read((0, react_1.useState)('value' in props
121
+ ? (0, utils_1.getValidValue)(props.value, isMultipleMode, labelInValue)
122
+ : (0, utils_1.getValidValue)(props.defaultValue, isMultipleMode, labelInValue)), 2), stateProxyValue = _c[0], setProxyValue = _c[1];
123
+ var value = 'value' in props && !isMultipleQuickSelectMode
124
+ ? (0, utils_1.getValidValue)(props.value, isMultipleMode, labelInValue)
125
+ : isMultipleQuickSelectMode
126
+ ? stateProxyValue
127
+ : stateValue;
128
+ var valueForInputShow = 'value' in props ? (0, utils_1.getValidValue)(props.value, isMultipleMode, labelInValue) : stateValue;
129
+ var _d = __read((0, useMergeValue_1.default)('', {
119
130
  value: 'inputValue' in props ? props.inputValue || '' : undefined,
120
- }), 3), inputValue = _c[0], setInputValue = _c[1], stateInputValue = _c[2];
121
- var _d = __read((0, useMergeValue_1.default)(false, {
131
+ }), 3), inputValue = _d[0], setInputValue = _d[1], stateInputValue = _d[2];
132
+ var _e = __read((0, useMergeValue_1.default)(false, {
122
133
  defaultValue: props.defaultPopupVisible,
123
134
  value: 'popupVisible' in props
124
135
  ? props.popupVisible
125
136
  : triggerProps && 'popupVisible' in triggerProps
126
137
  ? triggerProps.popupVisible
127
138
  : undefined,
128
- }), 2), popupVisible = _d[0], setPopupVisible = _d[1];
139
+ }), 2), popupVisible = _e[0], setPopupVisible = _e[1];
129
140
  // allowCreate 时,用户正在创建的选项值
130
- var _e = __read((0, react_1.useState)(null), 2), userCreatingOption = _e[0], setUserCreatingOption = _e[1];
141
+ var _f = __read((0, react_1.useState)(null), 2), userCreatingOption = _f[0], setUserCreatingOption = _f[1];
131
142
  // allowCreate 时,由用户输入而扩展到选项中的值
132
- var _f = __read((0, react_1.useState)([]), 2), userCreatedOptions = _f[0], setUserCreatedOptions = _f[1];
143
+ var _g = __read((0, react_1.useState)([]), 2), userCreatedOptions = _g[0], setUserCreatedOptions = _g[1];
133
144
  // 具有选中态或者 hover 态的 option 的 value
134
- var _g = __read((0, react_1.useState)((0, is_1.isArray)(value) ? value[0] : value), 2), valueActive = _g[0], setValueActive = _g[1];
145
+ var _h = __read((0, react_1.useState)((0, is_1.isArray)(value) ? value[0] : value), 2), valueActive = _h[0], setValueActive = _h[1];
135
146
  // 缓存较为耗时的 flatChildren 的结果
136
- var _h = (0, react_1.useMemo)(function () {
147
+ var _j = (0, react_1.useMemo)(function () {
137
148
  return (0, utils_1.flatChildren)({ children: children, options: options, filterOption: filterOption }, {
138
149
  prefixCls: prefixCls,
139
150
  inputValue: inputValue,
140
151
  userCreatedOptions: userCreatedOptions,
141
152
  userCreatingOption: userCreatingOption,
142
153
  });
143
- }, [children, options, filterOption, inputValue, userCreatingOption, userCreatedOptions]), childrenList = _h.childrenList, optionInfoMap = _h.optionInfoMap, optionValueList = _h.optionValueList, optionIndexListForArrowKey = _h.optionIndexListForArrowKey, hasOptGroup = _h.hasOptGroup, hasComplexLabelInOptions = _h.hasComplexLabelInOptions;
154
+ }, [children, options, filterOption, inputValue, userCreatingOption, userCreatedOptions]), childrenList = _j.childrenList, optionInfoMap = _j.optionInfoMap, optionValueList = _j.optionValueList, optionIndexListForArrowKey = _j.optionIndexListForArrowKey, hasOptGroup = _j.hasOptGroup, hasComplexLabelInOptions = _j.hasComplexLabelInOptions;
144
155
  // ref
145
156
  var refWrapper = (0, react_1.useRef)(null);
146
157
  var refTrigger = (0, react_1.useRef)(null);
@@ -218,10 +229,12 @@ function Select(baseProps, ref) {
218
229
  if (isMultipleMode) {
219
230
  if (!Array.isArray(value)) {
220
231
  setValue(value === undefined ? [] : [value]);
232
+ setProxyValue(value === undefined ? [] : [value]);
221
233
  }
222
234
  }
223
235
  else if (Array.isArray(value)) {
224
236
  setValue(value.length === 0 ? undefined : value[0]);
237
+ setProxyValue(value.length === 0 ? undefined : value[0]);
225
238
  }
226
239
  }, [isMultipleMode, value]);
227
240
  // 选项下拉框显示/隐藏时的一些自动行为
@@ -395,21 +408,60 @@ function Select(baseProps, ref) {
395
408
  onChange(paramsForCallback.value, paramsForCallback.option);
396
409
  }
397
410
  };
398
- // 多选时,选择/取消选择一个选项
399
- var checkOption = function (optionValue, operation) {
411
+ var tryUpdateProxySelectValue = function (value) {
412
+ setProxyValue(value);
413
+ };
414
+ // 多选时,选择/取消选择一个选项。 fromTag 为 true 时,表示从input tag标签触发取消选择
415
+ var checkOption = function (optionValue, operation, fromTag) {
416
+ if (fromTag === void 0) { fromTag = false; }
400
417
  // 取消选中时不需要检查option是否存在,因为可能已被外部剔除了此选项
401
418
  if (operation === 'remove' || (operation === 'add' && optionInfoMap.get(optionValue))) {
402
419
  var newValue = operation === 'add'
403
420
  ? value.concat(optionValue)
404
421
  : value.filter(function (v) { return v !== optionValue; });
405
422
  var callbackToTrigger = operation === 'add' ? onSelect : onDeselect;
406
- tryUpdateSelectValue(newValue);
407
423
  if (typeof callbackToTrigger === 'function') {
408
424
  var paramsForCallback = getValueAndOptionForCallback(optionValue, false);
409
425
  callbackToTrigger(paramsForCallback.value, paramsForCallback.option);
410
426
  }
427
+ // 如果是快速单选模式,更新代理值
428
+ if (isMultipleQuickSelectMode) {
429
+ tryUpdateProxySelectValue(newValue);
430
+ if (fromTag) {
431
+ if (popupVisible) {
432
+ tryUpdatePopupVisible(false);
433
+ var _newValue = operation === 'add'
434
+ ? stateValue.concat(optionValue)
435
+ : stateValue.filter(function (v) { return v !== optionValue; });
436
+ tryUpdateSelectValue(_newValue);
437
+ setProxyValue(_newValue);
438
+ }
439
+ else {
440
+ tryUpdateSelectValue(newValue);
441
+ }
442
+ }
443
+ }
444
+ else {
445
+ tryUpdateSelectValue(newValue);
446
+ }
411
447
  }
412
448
  };
449
+ // 多选时,确定
450
+ var confirmCheck = function () {
451
+ tryUpdateSelectValue(stateProxyValue);
452
+ tryUpdatePopupVisible(false);
453
+ };
454
+ // 多选时,取消
455
+ var cancelCheck = function () {
456
+ tryUpdateProxySelectValue(stateValue);
457
+ tryUpdatePopupVisible(false);
458
+ };
459
+ // 多选时候快速只选一个
460
+ var handleSingleQuickSelect = function (optionValue) {
461
+ tryUpdatePopupVisible(false);
462
+ tryUpdateProxySelectValue([optionValue]);
463
+ tryUpdateSelectValue([optionValue]);
464
+ };
413
465
  var handleOptionClick = function (optionValue, disabled) {
414
466
  if (disabled) {
415
467
  return;
@@ -481,41 +533,53 @@ function Select(baseProps, ref) {
481
533
  var needForbidVirtual = needMeasureLongestItem && hasComplexLabelInOptions;
482
534
  var mergedNotFoundContent = 'notFoundContent' in props ? notFoundContent : renderEmpty('Select');
483
535
  // 选项列表元素
484
- var eleOptionList = childrenList.length ? (react_1.default.createElement(VirtualList_1.default, __assign({ id: instancePopupID, role: "listbox", style: dropdownMenuStyle, className: (0, classNames_1.default)(prefixCls + "-popup-inner", dropdownMenuClassName), ref: refWrapper, data: childrenList, height: null, isStaticItemHeight: !hasOptGroup, measureLongestItem: needMeasureLongestItem, itemKey: function (child) { return child.props._key; }, onMouseDown: utils_1.preventDefaultEvent, onMouseMove: function () {
485
- refKeyboardArrowDirection.current = null;
486
- }, onScroll: function (e) { return onPopupScroll && onPopupScroll(e.target); } }, virtualListProps, { threshold: needForbidVirtual ? null : virtualListProps === null || virtualListProps === void 0 ? void 0 : virtualListProps.threshold }), function (child) {
487
- var _a;
488
- if ((0, utils_1.isSelectOptGroup)(child)) {
489
- return react_1.default.createElement(child.type, __assign({}, child.props, { prefixCls: prefixCls }));
490
- }
491
- if ((0, utils_1.isSelectOption)(child)) {
492
- var optionValue = (_a = child.props) === null || _a === void 0 ? void 0 : _a.value;
493
- var userCreatingOptionValue = (0, is_1.isObject)(userCreatingOption)
494
- ? userCreatingOption.value
495
- : userCreatingOption;
496
- var userCreatedOptionValues = userCreatedOptions.map(function (op) {
497
- return (0, is_1.isObject)(op) ? op.value : op;
498
- });
499
- var optionProps = {
500
- prefixCls: prefixCls,
501
- rtl: rtl,
502
- _valueActive: valueActive,
503
- _valueSelect: value,
504
- _isMultipleMode: isMultipleMode,
505
- _isUserCreatingOption: allowCreate && userCreatingOptionValue === optionValue,
506
- _isUserCreatedOption: allowCreate && userCreatedOptionValues.indexOf(optionValue) > -1,
507
- _onClick: handleOptionClick,
508
- _onMouseEnter: function (value) {
509
- refKeyboardArrowDirection.current === null && setValueActive(value);
510
- },
511
- _onMouseLeave: function () {
512
- refKeyboardArrowDirection.current === null && setValueActive(undefined);
513
- },
514
- };
515
- return child && react_1.default.createElement(child.type, __assign({}, child.props, optionProps));
516
- }
517
- return child;
518
- })) : null;
536
+ var eleOptionList = childrenList.length ? (react_1.default.createElement(react_1.default.Fragment, null,
537
+ react_1.default.createElement(VirtualList_1.default, __assign({ id: instancePopupID, role: "listbox", style: dropdownMenuStyle, className: (0, classNames_1.default)(prefixCls + "-popup-inner", dropdownMenuClassName), ref: refWrapper, data: childrenList, height: null, isStaticItemHeight: !hasOptGroup, measureLongestItem: needMeasureLongestItem, itemKey: function (child) { return child.props._key; }, onMouseDown: utils_1.preventDefaultEvent, onMouseMove: function () {
538
+ refKeyboardArrowDirection.current = null;
539
+ }, onScroll: function (e) { return onPopupScroll && onPopupScroll(e.target); } }, virtualListProps, { threshold: needForbidVirtual ? null : virtualListProps === null || virtualListProps === void 0 ? void 0 : virtualListProps.threshold }), function (child) {
540
+ var _a;
541
+ if ((0, utils_1.isSelectOptGroup)(child)) {
542
+ return react_1.default.createElement(child.type, __assign({}, child.props, { prefixCls: prefixCls }));
543
+ }
544
+ if ((0, utils_1.isSelectOption)(child)) {
545
+ var optionValue = (_a = child.props) === null || _a === void 0 ? void 0 : _a.value;
546
+ var userCreatingOptionValue = (0, is_1.isObject)(userCreatingOption)
547
+ ? userCreatingOption.value
548
+ : userCreatingOption;
549
+ var userCreatedOptionValues = userCreatedOptions.map(function (op) {
550
+ return (0, is_1.isObject)(op) ? op.value : op;
551
+ });
552
+ var optionProps = {
553
+ prefixCls: prefixCls,
554
+ rtl: rtl,
555
+ _valueActive: valueActive,
556
+ _valueSelect: value,
557
+ _isMultipleMode: isMultipleMode,
558
+ _isMultipleQuickSelectMode: isMultipleQuickSelectMode,
559
+ _onSingleQuickSelect: handleSingleQuickSelect,
560
+ _isUserCreatingOption: allowCreate && userCreatingOptionValue === optionValue,
561
+ _isUserCreatedOption: allowCreate && userCreatedOptionValues.indexOf(optionValue) > -1,
562
+ _onClick: handleOptionClick,
563
+ _onMouseEnter: function (value) {
564
+ refKeyboardArrowDirection.current === null && setValueActive(value);
565
+ },
566
+ _onMouseLeave: function () {
567
+ refKeyboardArrowDirection.current === null && setValueActive(undefined);
568
+ },
569
+ };
570
+ return child && react_1.default.createElement(child.type, __assign({}, child.props, optionProps));
571
+ }
572
+ return child;
573
+ }),
574
+ isMultipleQuickSelectMode && (react_1.default.createElement("div", { style: {
575
+ display: 'flex',
576
+ justifyContent: 'flex-end',
577
+ gap: 12,
578
+ padding: '8px 16px 4px',
579
+ borderTop: '1px solid var(--color-fill-3)',
580
+ } },
581
+ react_1.default.createElement(index_1.Button, { size: "mini", onClick: cancelCheck }, "\u53D6\u6D88"),
582
+ react_1.default.createElement(index_1.Button, { type: "primary", size: "mini", onClick: confirmCheck }, "\u786E\u5B9A"))))) : null;
519
583
  // Avoid drop-down box jitter when user is creating a selection
520
584
  var isUserCreating = allowCreate && inputValue;
521
585
  // Dropdown-placeholder when there is no options
@@ -603,7 +667,7 @@ function Select(baseProps, ref) {
603
667
  // Option Items
604
668
  onRemoveCheckedItem: function (_, index, event) {
605
669
  event.stopPropagation();
606
- checkOption(value[index], 'remove');
670
+ checkOption(value[index], 'remove', true);
607
671
  },
608
672
  onClear: function (event) {
609
673
  event.stopPropagation();
@@ -641,7 +705,12 @@ function Select(baseProps, ref) {
641
705
  });
642
706
  }, [hotkeyHandler, optionInfoMap, valueActive, getOptionInfoByValue, scrollIntoView]);
643
707
  var renderView = function (eleView) {
644
- return (react_1.default.createElement(Trigger_1.default, __assign({ ref: function (ref) { return (refTrigger.current = ref); }, popup: renderPopup, trigger: trigger, disabled: disabled, getPopupContainer: getPopupContainer, classNames: "slideDynamicOrigin", autoAlignPopupWidth: true, popupAlign: triggerPopupAlign, popupVisible: popupVisible, unmountOnExit: unmountOnExit, onVisibleChange: tryUpdatePopupVisible, __onExit: function () {
708
+ return (react_1.default.createElement(Trigger_1.default, __assign({ ref: function (ref) { return (refTrigger.current = ref); }, popup: renderPopup, trigger: trigger, disabled: disabled, getPopupContainer: getPopupContainer, classNames: "slideDynamicOrigin", autoAlignPopupWidth: true, popupAlign: triggerPopupAlign, popupVisible: popupVisible, unmountOnExit: unmountOnExit, onVisibleChange: function (visible) {
709
+ if (visible === false && isMultipleQuickSelectMode) {
710
+ setProxyValue(stateValue);
711
+ }
712
+ tryUpdatePopupVisible(visible);
713
+ }, __onExit: function () {
645
714
  refPopupExiting.current = true;
646
715
  }, __onExited: function () {
647
716
  refPopupExiting.current = false;
@@ -653,7 +722,7 @@ function Select(baseProps, ref) {
653
722
  : triggerElement;
654
723
  return (react_1.default.createElement(resizeObserver_1.default, { onResize: function () { return refTrigger.current.updatePopupPosition(); } }, usedTriggerElement !== undefined && usedTriggerElement !== null ? (renderView(usedTriggerElement)) : (react_1.default.createElement(select_view_1.default, __assign({}, props, selectViewEventHandlers, { ref: refSelectView,
655
724
  // state
656
- value: value, inputValue: inputValue, popupVisible: popupVisible,
725
+ value: valueForInputShow, inputValue: inputValue, popupVisible: popupVisible,
657
726
  // other
658
727
  rtl: rtl, prefixCls: prefixCls, allowCreate: !!allowCreate, ariaControls: instancePopupID, isEmptyValue: isNoOptionSelected, isMultiple: isMultipleMode, onSort: tryUpdateSelectValue, renderText: function (value) {
659
728
  var option = getOptionInfoByValue(value);
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.2.0";
142
+ export declare const version = "1.3.1";
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.2.0';
150
+ exports.version = '1.3.1';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apdesign/web-react",
3
- "version": "1.2.0",
3
+ "version": "1.3.1",
4
4
  "description": "AP Design React UI Library.",
5
5
  "module": "./es/index.js",
6
6
  "main": "./lib/index.js",