@apdesign/web-react 1.1.3 → 1.3.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.
@@ -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, "collapse" | "inDropdown" | "theme" | "mode" | "levelIndent" | "icons" | "autoScrollIntoView" | "selectedKeys" | "openKeys" | "scrollConfig" | "triggerProps" | "tooltipProps"> & {
9
+ declare const MenuContext: import("react").Context<Pick<MenuProps, "collapse" | "mode" | "icons" | "triggerProps" | "inDropdown" | "theme" | "levelIndent" | "autoScrollIntoView" | "selectedKeys" | "openKeys" | "scrollConfig" | "tooltipProps"> & {
10
10
  id?: string;
11
11
  prefixCls?: string;
12
12
  onClickMenuItem?: (key: string, event: any) => void;
@@ -1,4 +1,5 @@
1
- import { ReactNode, CSSProperties } from 'react';
1
+ import { CSSProperties, ReactNode } from 'react';
2
+ import { DraggableCoreProps } from 'react-draggable';
2
3
  import { ButtonProps } from '../Button';
3
4
  import { ConfirmProps } from './confirm';
4
5
  /**
@@ -171,6 +172,17 @@ export interface ModalProps {
171
172
  */
172
173
  modalRender?: (modalNode: ReactNode) => ReactNode;
173
174
  prefixCls?: string;
175
+ /**
176
+ * @zh 是否可以拖动弹窗
177
+ * @en Whether the Modal can be dragged
178
+ * @defaultValue true
179
+ */
180
+ draggable?: boolean;
181
+ /**
182
+ * @zh 拖动弹窗额外参数
183
+ * @en The extra parameters of the Modal
184
+ */
185
+ draggableProps?: Partial<DraggableCoreProps>;
174
186
  }
175
187
  export declare type ModalReturnProps = {
176
188
  update: Function;
package/es/Modal/modal.js CHANGED
@@ -37,6 +37,7 @@ var __read = (this && this.__read) || function (o, n) {
37
37
  return ar;
38
38
  };
39
39
  import React, { useState, forwardRef, useContext, useRef, useEffect, useCallback, } from 'react';
40
+ import Draggable from 'react-draggable';
40
41
  import FocusLock from 'react-focus-lock';
41
42
  import IconClose from '../../icon/react-icon/IconClose';
42
43
  import cs from '../_util/classNames';
@@ -77,13 +78,14 @@ var defaultProps = {
77
78
  escToExit: true,
78
79
  getPopupContainer: function () { return document.body; },
79
80
  alignCenter: true,
81
+ draggable: true,
80
82
  };
81
83
  function Modal(baseProps, ref) {
82
84
  var _a, _b;
83
85
  var _c;
84
86
  var context = useContext(ConfigContext);
85
87
  var props = useMergeProps(baseProps, defaultProps, (_c = context.componentConfig) === null || _c === void 0 ? void 0 : _c.Modal);
86
- var className = props.className, style = props.style, visible = props.visible, simple = props.simple, title = props.title, children = props.children, cancelText = props.cancelText, okText = props.okText, okButtonProps = props.okButtonProps, cancelButtonProps = props.cancelButtonProps, _d = props.getPopupContainer, getPopupContainer = _d === void 0 ? function () { return document.body; } : _d, footer = props.footer, afterClose = props.afterClose, confirmLoading = props.confirmLoading, mountOnEnter = props.mountOnEnter, unmountOnExit = props.unmountOnExit, afterOpen = props.afterOpen, hideCancel = props.hideCancel, autoFocus = props.autoFocus, focusLock = props.focusLock, maskClosable = props.maskClosable, mask = props.mask, alignCenter = props.alignCenter, getChildrenPopupContainer = props.getChildrenPopupContainer, wrapClassName = props.wrapClassName, escToExit = props.escToExit, modalRender = props.modalRender, maskStyle = props.maskStyle, wrapStyle = props.wrapStyle, closeIcon = props.closeIcon, rest = __rest(props, ["className", "style", "visible", "simple", "title", "children", "cancelText", "okText", "okButtonProps", "cancelButtonProps", "getPopupContainer", "footer", "afterClose", "confirmLoading", "mountOnEnter", "unmountOnExit", "afterOpen", "hideCancel", "autoFocus", "focusLock", "maskClosable", "mask", "alignCenter", "getChildrenPopupContainer", "wrapClassName", "escToExit", "modalRender", "maskStyle", "wrapStyle", "closeIcon"]);
88
+ var className = props.className, style = props.style, visible = props.visible, simple = props.simple, title = props.title, children = props.children, cancelText = props.cancelText, okText = props.okText, okButtonProps = props.okButtonProps, cancelButtonProps = props.cancelButtonProps, _d = props.getPopupContainer, getPopupContainer = _d === void 0 ? function () { return document.body; } : _d, footer = props.footer, afterClose = props.afterClose, confirmLoading = props.confirmLoading, mountOnEnter = props.mountOnEnter, unmountOnExit = props.unmountOnExit, afterOpen = props.afterOpen, hideCancel = props.hideCancel, autoFocus = props.autoFocus, focusLock = props.focusLock, maskClosable = props.maskClosable, mask = props.mask, alignCenter = props.alignCenter, getChildrenPopupContainer = props.getChildrenPopupContainer, wrapClassName = props.wrapClassName, escToExit = props.escToExit, modalRender = props.modalRender, maskStyle = props.maskStyle, wrapStyle = props.wrapStyle, closeIcon = props.closeIcon, draggable = props.draggable, draggableProps = props.draggableProps, rest = __rest(props, ["className", "style", "visible", "simple", "title", "children", "cancelText", "okText", "okButtonProps", "cancelButtonProps", "getPopupContainer", "footer", "afterClose", "confirmLoading", "mountOnEnter", "unmountOnExit", "afterOpen", "hideCancel", "autoFocus", "focusLock", "maskClosable", "mask", "alignCenter", "getChildrenPopupContainer", "wrapClassName", "escToExit", "modalRender", "maskStyle", "wrapStyle", "closeIcon", "draggable", "draggableProps"]);
87
89
  var modalWrapperRef = useRef(null);
88
90
  var contentWrapper = useRef(null);
89
91
  var modalRef = useRef(null);
@@ -200,7 +202,7 @@ function Modal(baseProps, ref) {
200
202
  ? getChildrenPopupContainer(node)
201
203
  : contentWrapper.current;
202
204
  } }),
203
- title && (React.createElement("div", { className: prefixCls + "-header" },
205
+ title && (React.createElement("div", { className: prefixCls + "-header", style: { cursor: draggable ? 'move' : null } },
204
206
  React.createElement("div", { className: prefixCls + "-title", id: "arco-dialog-" + dialogIndex.current }, title))),
205
207
  React.createElement("div", { ref: contentWrapper, className: prefixCls + "-content" }, children),
206
208
  renderFooter(),
@@ -211,10 +213,21 @@ function Modal(baseProps, ref) {
211
213
  var modalDom = (React.createElement("div", __assign({ role: "dialog", "aria-modal": "true" }, ariaProps, { className: cs(prefixCls, (_a = {},
212
214
  _a[prefixCls + "-simple"] = simple,
213
215
  _a[prefixCls + "-rtl"] = rtl,
214
- _a), className), style: style, ref: modalRef }), innerFocusLock ? (React.createElement(FocusLock, { crossFrame: false, disabled: !visible, autoFocus: innerAutoFocus, lockProps: {
216
+ _a), className), style: __assign({ display: draggable ? 'block' : null }, style), ref: modalRef }), innerFocusLock ? (React.createElement(FocusLock, { crossFrame: false, disabled: !visible, autoFocus: innerAutoFocus, lockProps: {
215
217
  tabIndex: -1,
216
218
  onKeyDown: onEscExit,
217
219
  } }, element)) : (React.createElement(React.Fragment, null, element))));
220
+ var modalWithMouseEventsDom = React.cloneElement(modalDom, {
221
+ onMouseDown: function () {
222
+ maskClickRef.current = false;
223
+ },
224
+ onMouseUp: function () {
225
+ maskClickRef.current = false;
226
+ },
227
+ });
228
+ // 包装在Draggable中的modal
229
+ var wrappedModalDom = draggable && title ? (React.createElement(Draggable, __assign({ bounds: "parent", handle: "." + prefixCls + "-header" }, draggableProps),
230
+ React.createElement("div", { style: { top: 0, verticalAlign: 'middle', display: 'inline-block' } }, modalWithMouseEventsDom))) : (modalWithMouseEventsDom);
218
231
  var setTransformOrigin = function (e) {
219
232
  if (haveOriginTransformOrigin.current)
220
233
  return;
@@ -252,6 +265,8 @@ function Modal(baseProps, ref) {
252
265
  'onConfirm',
253
266
  'closable',
254
267
  'prefixCls',
268
+ 'draggable',
269
+ 'draggableProps',
255
270
  ]), { tabIndex: !innerFocusLock || !innerAutoFocus ? -1 : null, ref: function (node) {
256
271
  modalWrapperRef.current = node;
257
272
  initPopupZIndex();
@@ -292,14 +307,7 @@ function Modal(baseProps, ref) {
292
307
  if (unmountOnExit) {
293
308
  modalRef.current = null;
294
309
  }
295
- } }, React.cloneElement((isFunction(modalRender) ? modalRender(modalDom) : modalDom), {
296
- onMouseDown: function () {
297
- maskClickRef.current = false;
298
- },
299
- onMouseUp: function () {
300
- maskClickRef.current = false;
301
- },
302
- })))))) : null;
310
+ } }, isFunction(modalRender) ? modalRender(wrappedModalDom) : wrappedModalDom))))) : null;
303
311
  }
304
312
  var ExportedModalComponent = forwardRef(Modal);
305
313
  ExportedModalComponent.displayName = 'Modal';
@@ -55,6 +55,12 @@ export interface SelectProps extends SelectViewCommonProps {
55
55
  * @en Whether to embed label in value, turn the format of value from string to `{ value: string, label: ReactNode }`
56
56
  */
57
57
  labelInValue?: boolean;
58
+ /**
59
+ * @zh 是否开启快速单选模式。开启后,由于需要最后点击确定或者取消来选择,单个选项变化的事件 onSelect 和 onDeselect 将无效
60
+ * @en Whether to enable quick single selection mode. When enabled, the onSelect and onDeselect events will be invalid because the selection needs to be confirmed or canceled at the end.
61
+ * @defaultValue true
62
+ */
63
+ isQuickSingleSelectMode?: boolean;
58
64
  /**
59
65
  * @zh 是否根据输入的值筛选数据。如果传入函数的话,接收 `inputValue` 和 `option` 两个参数,当option符合筛选条件时,返回 `true`,反之返回 `false`。
60
66
  * @en If it's true, filter options by input value. If it's a function, filter options base on the function.
@@ -245,6 +251,8 @@ export interface OptionProps extends Omit<HTMLAttributes<HTMLLIElement>, 'classN
245
251
  extra?: any;
246
252
  isSelectOption?: boolean;
247
253
  _isMultipleMode?: boolean;
254
+ _isMultipleQuickSelectMode?: boolean;
255
+ _onSingleQuickSelect?: (value: OptionProps['value']) => void;
248
256
  _isUserCreatedOption?: boolean;
249
257
  _isUserCreatingOption?: boolean;
250
258
  _valueActive?: OptionProps['value'];
@@ -20,13 +20,30 @@ var __rest = (this && this.__rest) || function (s, e) {
20
20
  }
21
21
  return t;
22
22
  };
23
- import React from 'react';
23
+ var __read = (this && this.__read) || function (o, n) {
24
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
25
+ if (!m) return o;
26
+ var i = m.call(o), r, ar = [], e;
27
+ try {
28
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
29
+ }
30
+ catch (error) { e = { error: error }; }
31
+ finally {
32
+ try {
33
+ if (r && !r.done && (m = i["return"])) m.call(i);
34
+ }
35
+ finally { if (e) throw e.error; }
36
+ }
37
+ return ar;
38
+ };
39
+ import React, { useState } from 'react';
24
40
  import cs from '../_util/classNames';
25
41
  import Checkbox from '../Checkbox';
26
42
  import omit from '../_util/omit';
27
43
  function Option(props, ref) {
28
44
  var _a, _b;
29
- 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, _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", "_isUserCreatedOption", "_isUserCreatingOption", "_valueActive", "_valueSelect", "_onMouseEnter", "_onMouseLeave", "_onClick"]);
45
+ 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 _c = __read(useState(false), 2), isHovering = _c[0], setIsHovering = _c[1];
30
47
  var value = 'value' in props ? propValue : "" + propChildren;
31
48
  var childNode = 'children' in props ? propChildren : "" + propValue;
32
49
  var isChecked = _isMultipleMode
@@ -61,9 +78,34 @@ function Option(props, ref) {
61
78
  return (React.createElement("li", __assign({}, wrapperProps, { className: cs(prefixCls + "-option-wrapper", (_b = {},
62
79
  _b[prefixCls + "-option-wrapper-selected"] = isChecked,
63
80
  _b[prefixCls + "-option-wrapper-disabled"] = disabled,
64
- _b), wrapperClassName) }),
81
+ _b), wrapperClassName) }, (_isMultipleQuickSelectMode && {
82
+ // TODO: 这个等主题处理好了要改成 css ,包括以下内联样式
83
+ onMouseEnter: function () { return setIsHovering(true); },
84
+ onMouseLeave: function () { return setIsHovering(false); },
85
+ style: {
86
+ position: 'relative',
87
+ },
88
+ })),
65
89
  React.createElement(Checkbox, { "aria-hidden": "true", className: prefixCls + "-checkbox", checked: isChecked, disabled: disabled, onChange: optionLabelProps.onClick }),
66
- React.createElement("span", __assign({}, optionLabelProps), childNode)));
90
+ React.createElement("div", { style: {
91
+ display: 'flex',
92
+ flex: 1,
93
+ alignItems: 'center',
94
+ overflow: 'hidden',
95
+ } },
96
+ React.createElement("span", __assign({}, optionLabelProps), childNode),
97
+ _isMultipleQuickSelectMode && !disabled && (React.createElement("span", { style: {
98
+ display: isHovering ? 'inline' : 'none',
99
+ flex: 0,
100
+ backgroundColor: 'rgb(var(--primary-6))',
101
+ cursor: 'pointer',
102
+ color: 'white',
103
+ padding: '7px',
104
+ paddingLeft: '20px',
105
+ marginLeft: '-20px',
106
+ clipPath: 'polygon(12px 50%, 0% 0%, 100% 0%, 100% 100%, 0% 100%)',
107
+ whiteSpace: 'nowrap',
108
+ }, onClick: function () { return _onSingleQuickSelect === null || _onSingleQuickSelect === void 0 ? void 0 : _onSingleQuickSelect(value); } }, "\u4EC5\u7B5B\u9009\u6B64\u9879")))));
67
109
  }
68
110
  return (React.createElement("li", __assign({}, wrapperProps, optionLabelProps), childNode));
69
111
  }
@@ -62,6 +62,7 @@ import { ConfigContext } from '../ConfigProvider';
62
62
  import useMergeValue from '../_util/hooks/useMergeValue';
63
63
  import omit from '../_util/omit';
64
64
  import useMergeProps from '../_util/hooks/useMergeProps';
65
+ import { Button } from '../index';
65
66
  import useId from '../_util/hooks/useId';
66
67
  // 用户创建中的option的origin标识
67
68
  var USER_CREATING_OPTION_ORIGIN = 'userCreatingOption';
@@ -70,13 +71,14 @@ var defaultProps = {
70
71
  bordered: true,
71
72
  filterOption: true,
72
73
  unmountOnExit: true,
74
+ isQuickSingleSelectMode: true,
73
75
  defaultActiveFirstOption: true,
74
76
  };
75
77
  var triggerPopupAlign = { bottom: 4 };
76
78
  function Select(baseProps, ref) {
77
79
  var _a = useContext(ConfigContext), getPrefixCls = _a.getPrefixCls, renderEmpty = _a.renderEmpty, componentConfig = _a.componentConfig, rtl = _a.rtl;
78
80
  var props = useMergeProps(baseProps, defaultProps, componentConfig === null || componentConfig === void 0 ? void 0 : componentConfig.Select);
79
- 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,
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,
80
82
  // events
81
83
  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;
82
84
  // TODO 兼容逻辑,3.0 移除 tags 模式
@@ -88,35 +90,42 @@ function Select(baseProps, ref) {
88
90
  }
89
91
  var prefixCls = getPrefixCls('select');
90
92
  var isMultipleMode = mode === 'multiple';
93
+ var isMultipleQuickSelectMode = isMultipleMode && isQuickSingleSelectMode;
91
94
  // TODO: 统一 useMergeValue 函数的表现
92
95
  var _b = __read(useState(getValidValue(props.defaultValue, isMultipleMode, labelInValue)), 2), stateValue = _b[0], setValue = _b[1];
93
- var value = 'value' in props ? getValidValue(props.value, isMultipleMode, labelInValue) : stateValue;
94
- var _c = __read(useMergeValue('', {
96
+ var _c = __read(useState(getValidValue(props.defaultValue, isMultipleMode, labelInValue)), 2), stateProxyValue = _c[0], setProxyValue = _c[1];
97
+ var value = 'value' in props
98
+ ? getValidValue(props.value, isMultipleMode, labelInValue)
99
+ : isMultipleQuickSelectMode
100
+ ? stateProxyValue
101
+ : stateValue;
102
+ var valueForInputShow = 'value' in props ? getValidValue(props.value, isMultipleMode, labelInValue) : stateValue;
103
+ var _d = __read(useMergeValue('', {
95
104
  value: 'inputValue' in props ? props.inputValue || '' : undefined,
96
- }), 3), inputValue = _c[0], setInputValue = _c[1], stateInputValue = _c[2];
97
- var _d = __read(useMergeValue(false, {
105
+ }), 3), inputValue = _d[0], setInputValue = _d[1], stateInputValue = _d[2];
106
+ var _e = __read(useMergeValue(false, {
98
107
  defaultValue: props.defaultPopupVisible,
99
108
  value: 'popupVisible' in props
100
109
  ? props.popupVisible
101
110
  : triggerProps && 'popupVisible' in triggerProps
102
111
  ? triggerProps.popupVisible
103
112
  : undefined,
104
- }), 2), popupVisible = _d[0], setPopupVisible = _d[1];
113
+ }), 2), popupVisible = _e[0], setPopupVisible = _e[1];
105
114
  // allowCreate 时,用户正在创建的选项值
106
- var _e = __read(useState(null), 2), userCreatingOption = _e[0], setUserCreatingOption = _e[1];
115
+ var _f = __read(useState(null), 2), userCreatingOption = _f[0], setUserCreatingOption = _f[1];
107
116
  // allowCreate 时,由用户输入而扩展到选项中的值
108
- var _f = __read(useState([]), 2), userCreatedOptions = _f[0], setUserCreatedOptions = _f[1];
117
+ var _g = __read(useState([]), 2), userCreatedOptions = _g[0], setUserCreatedOptions = _g[1];
109
118
  // 具有选中态或者 hover 态的 option 的 value
110
- var _g = __read(useState(isArray(value) ? value[0] : value), 2), valueActive = _g[0], setValueActive = _g[1];
119
+ var _h = __read(useState(isArray(value) ? value[0] : value), 2), valueActive = _h[0], setValueActive = _h[1];
111
120
  // 缓存较为耗时的 flatChildren 的结果
112
- var _h = useMemo(function () {
121
+ var _j = useMemo(function () {
113
122
  return flatChildren({ children: children, options: options, filterOption: filterOption }, {
114
123
  prefixCls: prefixCls,
115
124
  inputValue: inputValue,
116
125
  userCreatedOptions: userCreatedOptions,
117
126
  userCreatingOption: userCreatingOption,
118
127
  });
119
- }, [children, options, filterOption, inputValue, userCreatingOption, userCreatedOptions]), childrenList = _h.childrenList, optionInfoMap = _h.optionInfoMap, optionValueList = _h.optionValueList, optionIndexListForArrowKey = _h.optionIndexListForArrowKey, hasOptGroup = _h.hasOptGroup, hasComplexLabelInOptions = _h.hasComplexLabelInOptions;
128
+ }, [children, options, filterOption, inputValue, userCreatingOption, userCreatedOptions]), childrenList = _j.childrenList, optionInfoMap = _j.optionInfoMap, optionValueList = _j.optionValueList, optionIndexListForArrowKey = _j.optionIndexListForArrowKey, hasOptGroup = _j.hasOptGroup, hasComplexLabelInOptions = _j.hasComplexLabelInOptions;
120
129
  // ref
121
130
  var refWrapper = useRef(null);
122
131
  var refTrigger = useRef(null);
@@ -194,10 +203,12 @@ function Select(baseProps, ref) {
194
203
  if (isMultipleMode) {
195
204
  if (!Array.isArray(value)) {
196
205
  setValue(value === undefined ? [] : [value]);
206
+ setProxyValue(value === undefined ? [] : [value]);
197
207
  }
198
208
  }
199
209
  else if (Array.isArray(value)) {
200
210
  setValue(value.length === 0 ? undefined : value[0]);
211
+ setProxyValue(value.length === 0 ? undefined : value[0]);
201
212
  }
202
213
  }, [isMultipleMode, value]);
203
214
  // 选项下拉框显示/隐藏时的一些自动行为
@@ -371,21 +382,50 @@ function Select(baseProps, ref) {
371
382
  onChange(paramsForCallback.value, paramsForCallback.option);
372
383
  }
373
384
  };
374
- // 多选时,选择/取消选择一个选项
375
- var checkOption = function (optionValue, operation) {
385
+ var tryUpdateProxySelectValue = function (value) {
386
+ setProxyValue(value);
387
+ };
388
+ // 多选时,选择/取消选择一个选项。 fromTag 为 true 时,表示从input tag标签触发取消选择
389
+ var checkOption = function (optionValue, operation, fromTag) {
390
+ if (fromTag === void 0) { fromTag = false; }
376
391
  // 取消选中时不需要检查option是否存在,因为可能已被外部剔除了此选项
377
392
  if (operation === 'remove' || (operation === 'add' && optionInfoMap.get(optionValue))) {
378
393
  var newValue = operation === 'add'
379
394
  ? value.concat(optionValue)
380
395
  : value.filter(function (v) { return v !== optionValue; });
381
396
  var callbackToTrigger = operation === 'add' ? onSelect : onDeselect;
382
- tryUpdateSelectValue(newValue);
383
397
  if (typeof callbackToTrigger === 'function') {
384
398
  var paramsForCallback = getValueAndOptionForCallback(optionValue, false);
385
399
  callbackToTrigger(paramsForCallback.value, paramsForCallback.option);
386
400
  }
401
+ // 如果是快速单选模式,更新代理值
402
+ if (isMultipleQuickSelectMode) {
403
+ tryUpdateProxySelectValue(newValue);
404
+ if (fromTag) {
405
+ tryUpdateSelectValue(newValue);
406
+ }
407
+ }
408
+ else {
409
+ tryUpdateSelectValue(newValue);
410
+ }
387
411
  }
388
412
  };
413
+ // 多选时,确定
414
+ var confirmCheck = function () {
415
+ tryUpdateSelectValue(stateProxyValue);
416
+ tryUpdatePopupVisible(false);
417
+ };
418
+ // 多选时,取消
419
+ var cancelCheck = function () {
420
+ tryUpdateProxySelectValue(stateValue);
421
+ tryUpdatePopupVisible(false);
422
+ };
423
+ // 多选时候快速只选一个
424
+ var handleSingleQuickSelect = function (optionValue) {
425
+ tryUpdatePopupVisible(false);
426
+ tryUpdateProxySelectValue([optionValue]);
427
+ tryUpdateSelectValue([optionValue]);
428
+ };
389
429
  var handleOptionClick = function (optionValue, disabled) {
390
430
  if (disabled) {
391
431
  return;
@@ -457,41 +497,53 @@ function Select(baseProps, ref) {
457
497
  var needForbidVirtual = needMeasureLongestItem && hasComplexLabelInOptions;
458
498
  var mergedNotFoundContent = 'notFoundContent' in props ? notFoundContent : renderEmpty('Select');
459
499
  // 选项列表元素
460
- var eleOptionList = childrenList.length ? (React.createElement(VirtualList, __assign({ id: instancePopupID, role: "listbox", style: dropdownMenuStyle, className: cs(prefixCls + "-popup-inner", dropdownMenuClassName), ref: refWrapper, data: childrenList, height: null, isStaticItemHeight: !hasOptGroup, measureLongestItem: needMeasureLongestItem, itemKey: function (child) { return child.props._key; }, onMouseDown: preventDefaultEvent, onMouseMove: function () {
461
- refKeyboardArrowDirection.current = null;
462
- }, onScroll: function (e) { return onPopupScroll && onPopupScroll(e.target); } }, virtualListProps, { threshold: needForbidVirtual ? null : virtualListProps === null || virtualListProps === void 0 ? void 0 : virtualListProps.threshold }), function (child) {
463
- var _a;
464
- if (isSelectOptGroup(child)) {
465
- return React.createElement(child.type, __assign({}, child.props, { prefixCls: prefixCls }));
466
- }
467
- if (isSelectOption(child)) {
468
- var optionValue = (_a = child.props) === null || _a === void 0 ? void 0 : _a.value;
469
- var userCreatingOptionValue = isObject(userCreatingOption)
470
- ? userCreatingOption.value
471
- : userCreatingOption;
472
- var userCreatedOptionValues = userCreatedOptions.map(function (op) {
473
- return isObject(op) ? op.value : op;
474
- });
475
- var optionProps = {
476
- prefixCls: prefixCls,
477
- rtl: rtl,
478
- _valueActive: valueActive,
479
- _valueSelect: value,
480
- _isMultipleMode: isMultipleMode,
481
- _isUserCreatingOption: allowCreate && userCreatingOptionValue === optionValue,
482
- _isUserCreatedOption: allowCreate && userCreatedOptionValues.indexOf(optionValue) > -1,
483
- _onClick: handleOptionClick,
484
- _onMouseEnter: function (value) {
485
- refKeyboardArrowDirection.current === null && setValueActive(value);
486
- },
487
- _onMouseLeave: function () {
488
- refKeyboardArrowDirection.current === null && setValueActive(undefined);
489
- },
490
- };
491
- return child && React.createElement(child.type, __assign({}, child.props, optionProps));
492
- }
493
- return child;
494
- })) : null;
500
+ var eleOptionList = childrenList.length ? (React.createElement(React.Fragment, null,
501
+ React.createElement(VirtualList, __assign({ id: instancePopupID, role: "listbox", style: dropdownMenuStyle, className: cs(prefixCls + "-popup-inner", dropdownMenuClassName), ref: refWrapper, data: childrenList, height: null, isStaticItemHeight: !hasOptGroup, measureLongestItem: needMeasureLongestItem, itemKey: function (child) { return child.props._key; }, onMouseDown: preventDefaultEvent, onMouseMove: function () {
502
+ refKeyboardArrowDirection.current = null;
503
+ }, onScroll: function (e) { return onPopupScroll && onPopupScroll(e.target); } }, virtualListProps, { threshold: needForbidVirtual ? null : virtualListProps === null || virtualListProps === void 0 ? void 0 : virtualListProps.threshold }), function (child) {
504
+ var _a;
505
+ if (isSelectOptGroup(child)) {
506
+ return React.createElement(child.type, __assign({}, child.props, { prefixCls: prefixCls }));
507
+ }
508
+ if (isSelectOption(child)) {
509
+ var optionValue = (_a = child.props) === null || _a === void 0 ? void 0 : _a.value;
510
+ var userCreatingOptionValue = isObject(userCreatingOption)
511
+ ? userCreatingOption.value
512
+ : userCreatingOption;
513
+ var userCreatedOptionValues = userCreatedOptions.map(function (op) {
514
+ return isObject(op) ? op.value : op;
515
+ });
516
+ var optionProps = {
517
+ prefixCls: prefixCls,
518
+ rtl: rtl,
519
+ _valueActive: valueActive,
520
+ _valueSelect: value,
521
+ _isMultipleMode: isMultipleMode,
522
+ _isMultipleQuickSelectMode: isMultipleQuickSelectMode,
523
+ _onSingleQuickSelect: handleSingleQuickSelect,
524
+ _isUserCreatingOption: allowCreate && userCreatingOptionValue === optionValue,
525
+ _isUserCreatedOption: allowCreate && userCreatedOptionValues.indexOf(optionValue) > -1,
526
+ _onClick: handleOptionClick,
527
+ _onMouseEnter: function (value) {
528
+ refKeyboardArrowDirection.current === null && setValueActive(value);
529
+ },
530
+ _onMouseLeave: function () {
531
+ refKeyboardArrowDirection.current === null && setValueActive(undefined);
532
+ },
533
+ };
534
+ return child && React.createElement(child.type, __assign({}, child.props, optionProps));
535
+ }
536
+ return child;
537
+ }),
538
+ isMultipleQuickSelectMode && (React.createElement("div", { style: {
539
+ display: 'flex',
540
+ justifyContent: 'flex-end',
541
+ gap: 12,
542
+ padding: '8px 16px 4px',
543
+ borderTop: '1px solid var(--color-fill-3)',
544
+ } },
545
+ React.createElement(Button, { size: "mini", onClick: cancelCheck }, "\u53D6\u6D88"),
546
+ React.createElement(Button, { type: "primary", size: "mini", onClick: confirmCheck }, "\u786E\u5B9A"))))) : null;
495
547
  // Avoid drop-down box jitter when user is creating a selection
496
548
  var isUserCreating = allowCreate && inputValue;
497
549
  // Dropdown-placeholder when there is no options
@@ -579,7 +631,7 @@ function Select(baseProps, ref) {
579
631
  // Option Items
580
632
  onRemoveCheckedItem: function (_, index, event) {
581
633
  event.stopPropagation();
582
- checkOption(value[index], 'remove');
634
+ checkOption(value[index], 'remove', true);
583
635
  },
584
636
  onClear: function (event) {
585
637
  event.stopPropagation();
@@ -617,7 +669,12 @@ function Select(baseProps, ref) {
617
669
  });
618
670
  }, [hotkeyHandler, optionInfoMap, valueActive, getOptionInfoByValue, scrollIntoView]);
619
671
  var renderView = function (eleView) {
620
- return (React.createElement(Trigger, __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 () {
672
+ return (React.createElement(Trigger, __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) {
673
+ if (visible === false && isMultipleQuickSelectMode) {
674
+ setProxyValue(stateValue);
675
+ }
676
+ tryUpdatePopupVisible(visible);
677
+ }, __onExit: function () {
621
678
  refPopupExiting.current = true;
622
679
  }, __onExited: function () {
623
680
  refPopupExiting.current = false;
@@ -629,7 +686,7 @@ function Select(baseProps, ref) {
629
686
  : triggerElement;
630
687
  return (React.createElement(ResizeObserver, { onResize: function () { return refTrigger.current.updatePopupPosition(); } }, usedTriggerElement !== undefined && usedTriggerElement !== null ? (renderView(usedTriggerElement)) : (React.createElement(SelectView, __assign({}, props, selectViewEventHandlers, { ref: refSelectView,
631
688
  // state
632
- value: value, inputValue: inputValue, popupVisible: popupVisible,
689
+ value: valueForInputShow, inputValue: inputValue, popupVisible: popupVisible,
633
690
  // other
634
691
  rtl: rtl, prefixCls: prefixCls, allowCreate: !!allowCreate, ariaControls: instancePopupID, isEmptyValue: isNoOptionSelected, isMultiple: isMultipleMode, onSort: tryUpdateSelectValue, renderText: function (value) {
635
692
  var option = getOptionInfoByValue(value);
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.1.3";
142
+ export declare const version = "1.3.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.1.3';
72
+ export var version = '1.3.0';
@@ -1,4 +1,5 @@
1
- import { ReactNode, CSSProperties } from 'react';
1
+ import { CSSProperties, ReactNode } from 'react';
2
+ import { DraggableCoreProps } from 'react-draggable';
2
3
  import { ButtonProps } from '../Button';
3
4
  import { ConfirmProps } from './confirm';
4
5
  /**
@@ -171,6 +172,17 @@ export interface ModalProps {
171
172
  */
172
173
  modalRender?: (modalNode: ReactNode) => ReactNode;
173
174
  prefixCls?: string;
175
+ /**
176
+ * @zh 是否可以拖动弹窗
177
+ * @en Whether the Modal can be dragged
178
+ * @defaultValue true
179
+ */
180
+ draggable?: boolean;
181
+ /**
182
+ * @zh 拖动弹窗额外参数
183
+ * @en The extra parameters of the Modal
184
+ */
185
+ draggableProps?: Partial<DraggableCoreProps>;
174
186
  }
175
187
  export declare type ModalReturnProps = {
176
188
  update: Function;
@@ -61,6 +61,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
61
61
  };
62
62
  Object.defineProperty(exports, "__esModule", { value: true });
63
63
  var react_1 = __importStar(require("react"));
64
+ var react_draggable_1 = __importDefault(require("react-draggable"));
64
65
  var react_focus_lock_1 = __importDefault(require("react-focus-lock"));
65
66
  var IconClose_1 = __importDefault(require("../../icon/react-icon-cjs/IconClose"));
66
67
  var classNames_1 = __importDefault(require("../_util/classNames"));
@@ -101,13 +102,14 @@ var defaultProps = {
101
102
  escToExit: true,
102
103
  getPopupContainer: function () { return document.body; },
103
104
  alignCenter: true,
105
+ draggable: true,
104
106
  };
105
107
  function Modal(baseProps, ref) {
106
108
  var _a, _b;
107
109
  var _c;
108
110
  var context = (0, react_1.useContext)(ConfigProvider_1.ConfigContext);
109
111
  var props = (0, useMergeProps_1.default)(baseProps, defaultProps, (_c = context.componentConfig) === null || _c === void 0 ? void 0 : _c.Modal);
110
- var className = props.className, style = props.style, visible = props.visible, simple = props.simple, title = props.title, children = props.children, cancelText = props.cancelText, okText = props.okText, okButtonProps = props.okButtonProps, cancelButtonProps = props.cancelButtonProps, _d = props.getPopupContainer, getPopupContainer = _d === void 0 ? function () { return document.body; } : _d, footer = props.footer, afterClose = props.afterClose, confirmLoading = props.confirmLoading, mountOnEnter = props.mountOnEnter, unmountOnExit = props.unmountOnExit, afterOpen = props.afterOpen, hideCancel = props.hideCancel, autoFocus = props.autoFocus, focusLock = props.focusLock, maskClosable = props.maskClosable, mask = props.mask, alignCenter = props.alignCenter, getChildrenPopupContainer = props.getChildrenPopupContainer, wrapClassName = props.wrapClassName, escToExit = props.escToExit, modalRender = props.modalRender, maskStyle = props.maskStyle, wrapStyle = props.wrapStyle, closeIcon = props.closeIcon, rest = __rest(props, ["className", "style", "visible", "simple", "title", "children", "cancelText", "okText", "okButtonProps", "cancelButtonProps", "getPopupContainer", "footer", "afterClose", "confirmLoading", "mountOnEnter", "unmountOnExit", "afterOpen", "hideCancel", "autoFocus", "focusLock", "maskClosable", "mask", "alignCenter", "getChildrenPopupContainer", "wrapClassName", "escToExit", "modalRender", "maskStyle", "wrapStyle", "closeIcon"]);
112
+ var className = props.className, style = props.style, visible = props.visible, simple = props.simple, title = props.title, children = props.children, cancelText = props.cancelText, okText = props.okText, okButtonProps = props.okButtonProps, cancelButtonProps = props.cancelButtonProps, _d = props.getPopupContainer, getPopupContainer = _d === void 0 ? function () { return document.body; } : _d, footer = props.footer, afterClose = props.afterClose, confirmLoading = props.confirmLoading, mountOnEnter = props.mountOnEnter, unmountOnExit = props.unmountOnExit, afterOpen = props.afterOpen, hideCancel = props.hideCancel, autoFocus = props.autoFocus, focusLock = props.focusLock, maskClosable = props.maskClosable, mask = props.mask, alignCenter = props.alignCenter, getChildrenPopupContainer = props.getChildrenPopupContainer, wrapClassName = props.wrapClassName, escToExit = props.escToExit, modalRender = props.modalRender, maskStyle = props.maskStyle, wrapStyle = props.wrapStyle, closeIcon = props.closeIcon, draggable = props.draggable, draggableProps = props.draggableProps, rest = __rest(props, ["className", "style", "visible", "simple", "title", "children", "cancelText", "okText", "okButtonProps", "cancelButtonProps", "getPopupContainer", "footer", "afterClose", "confirmLoading", "mountOnEnter", "unmountOnExit", "afterOpen", "hideCancel", "autoFocus", "focusLock", "maskClosable", "mask", "alignCenter", "getChildrenPopupContainer", "wrapClassName", "escToExit", "modalRender", "maskStyle", "wrapStyle", "closeIcon", "draggable", "draggableProps"]);
111
113
  var modalWrapperRef = (0, react_1.useRef)(null);
112
114
  var contentWrapper = (0, react_1.useRef)(null);
113
115
  var modalRef = (0, react_1.useRef)(null);
@@ -224,7 +226,7 @@ function Modal(baseProps, ref) {
224
226
  ? getChildrenPopupContainer(node)
225
227
  : contentWrapper.current;
226
228
  } }),
227
- title && (react_1.default.createElement("div", { className: prefixCls + "-header" },
229
+ title && (react_1.default.createElement("div", { className: prefixCls + "-header", style: { cursor: draggable ? 'move' : null } },
228
230
  react_1.default.createElement("div", { className: prefixCls + "-title", id: "arco-dialog-" + dialogIndex.current }, title))),
229
231
  react_1.default.createElement("div", { ref: contentWrapper, className: prefixCls + "-content" }, children),
230
232
  renderFooter(),
@@ -235,10 +237,21 @@ function Modal(baseProps, ref) {
235
237
  var modalDom = (react_1.default.createElement("div", __assign({ role: "dialog", "aria-modal": "true" }, ariaProps, { className: (0, classNames_1.default)(prefixCls, (_a = {},
236
238
  _a[prefixCls + "-simple"] = simple,
237
239
  _a[prefixCls + "-rtl"] = rtl,
238
- _a), className), style: style, ref: modalRef }), innerFocusLock ? (react_1.default.createElement(react_focus_lock_1.default, { crossFrame: false, disabled: !visible, autoFocus: innerAutoFocus, lockProps: {
240
+ _a), className), style: __assign({ display: draggable ? 'block' : null }, style), ref: modalRef }), innerFocusLock ? (react_1.default.createElement(react_focus_lock_1.default, { crossFrame: false, disabled: !visible, autoFocus: innerAutoFocus, lockProps: {
239
241
  tabIndex: -1,
240
242
  onKeyDown: onEscExit,
241
243
  } }, element)) : (react_1.default.createElement(react_1.default.Fragment, null, element))));
244
+ var modalWithMouseEventsDom = react_1.default.cloneElement(modalDom, {
245
+ onMouseDown: function () {
246
+ maskClickRef.current = false;
247
+ },
248
+ onMouseUp: function () {
249
+ maskClickRef.current = false;
250
+ },
251
+ });
252
+ // 包装在Draggable中的modal
253
+ var wrappedModalDom = draggable && title ? (react_1.default.createElement(react_draggable_1.default, __assign({ bounds: "parent", handle: "." + prefixCls + "-header" }, draggableProps),
254
+ react_1.default.createElement("div", { style: { top: 0, verticalAlign: 'middle', display: 'inline-block' } }, modalWithMouseEventsDom))) : (modalWithMouseEventsDom);
242
255
  var setTransformOrigin = function (e) {
243
256
  if (haveOriginTransformOrigin.current)
244
257
  return;
@@ -276,6 +289,8 @@ function Modal(baseProps, ref) {
276
289
  'onConfirm',
277
290
  'closable',
278
291
  'prefixCls',
292
+ 'draggable',
293
+ 'draggableProps',
279
294
  ]), { tabIndex: !innerFocusLock || !innerAutoFocus ? -1 : null, ref: function (node) {
280
295
  modalWrapperRef.current = node;
281
296
  initPopupZIndex();
@@ -316,14 +331,7 @@ function Modal(baseProps, ref) {
316
331
  if (unmountOnExit) {
317
332
  modalRef.current = null;
318
333
  }
319
- } }, react_1.default.cloneElement(((0, is_1.isFunction)(modalRender) ? modalRender(modalDom) : modalDom), {
320
- onMouseDown: function () {
321
- maskClickRef.current = false;
322
- },
323
- onMouseUp: function () {
324
- maskClickRef.current = false;
325
- },
326
- })))))) : null;
334
+ } }, (0, is_1.isFunction)(modalRender) ? modalRender(wrappedModalDom) : wrappedModalDom))))) : null;
327
335
  }
328
336
  var ExportedModalComponent = (0, react_1.forwardRef)(Modal);
329
337
  ExportedModalComponent.displayName = 'Modal';