@rc-component/select 1.0.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/LICENSE.md +9 -0
- package/README.md +191 -0
- package/assets/index.css +306 -0
- package/assets/index.less +397 -0
- package/es/BaseSelect/Polite.d.ts +7 -0
- package/es/BaseSelect/Polite.js +26 -0
- package/es/BaseSelect/index.d.ts +118 -0
- package/es/BaseSelect/index.js +569 -0
- package/es/OptGroup.d.ts +12 -0
- package/es/OptGroup.js +6 -0
- package/es/Option.d.ts +14 -0
- package/es/Option.js +6 -0
- package/es/OptionList.d.ts +10 -0
- package/es/OptionList.js +379 -0
- package/es/Select.d.ts +114 -0
- package/es/Select.js +480 -0
- package/es/SelectContext.d.ts +23 -0
- package/es/SelectContext.js +6 -0
- package/es/SelectTrigger.d.ts +30 -0
- package/es/SelectTrigger.js +138 -0
- package/es/Selector/Input.d.ts +27 -0
- package/es/Selector/Input.js +114 -0
- package/es/Selector/MultipleSelector.d.ts +16 -0
- package/es/Selector/MultipleSelector.js +185 -0
- package/es/Selector/SingleSelector.d.ts +8 -0
- package/es/Selector/SingleSelector.js +104 -0
- package/es/Selector/index.d.ts +85 -0
- package/es/Selector/index.js +184 -0
- package/es/TransBtn.d.ts +12 -0
- package/es/TransBtn.js +30 -0
- package/es/hooks/useAllowClear.d.ts +8 -0
- package/es/hooks/useAllowClear.js +26 -0
- package/es/hooks/useBaseProps.d.ts +13 -0
- package/es/hooks/useBaseProps.js +10 -0
- package/es/hooks/useCache.d.ts +7 -0
- package/es/hooks/useCache.js +40 -0
- package/es/hooks/useDelayReset.d.ts +5 -0
- package/es/hooks/useDelayReset.js +24 -0
- package/es/hooks/useFilterOptions.d.ts +3 -0
- package/es/hooks/useFilterOptions.js +57 -0
- package/es/hooks/useId.d.ts +5 -0
- package/es/hooks/useId.js +29 -0
- package/es/hooks/useLayoutEffect.d.ts +5 -0
- package/es/hooks/useLayoutEffect.js +17 -0
- package/es/hooks/useLock.d.ts +7 -0
- package/es/hooks/useLock.js +27 -0
- package/es/hooks/useOptions.d.ts +12 -0
- package/es/hooks/useOptions.js +45 -0
- package/es/hooks/useRefFunc.d.ts +5 -0
- package/es/hooks/useRefFunc.js +14 -0
- package/es/hooks/useSelectTriggerControl.d.ts +1 -0
- package/es/hooks/useSelectTriggerControl.js +27 -0
- package/es/index.d.ts +10 -0
- package/es/index.js +7 -0
- package/es/interface.d.ts +23 -0
- package/es/interface.js +1 -0
- package/es/utils/__mocks__/platformUtil.d.ts +1 -0
- package/es/utils/__mocks__/platformUtil.js +3 -0
- package/es/utils/commonUtil.d.ts +9 -0
- package/es/utils/commonUtil.js +32 -0
- package/es/utils/keyUtil.d.ts +2 -0
- package/es/utils/keyUtil.js +16 -0
- package/es/utils/legacyUtil.d.ts +3 -0
- package/es/utils/legacyUtil.js +44 -0
- package/es/utils/platformUtil.d.ts +1 -0
- package/es/utils/platformUtil.js +4 -0
- package/es/utils/valueUtil.d.ts +24 -0
- package/es/utils/valueUtil.js +128 -0
- package/es/utils/warningPropsUtil.d.ts +4 -0
- package/es/utils/warningPropsUtil.js +119 -0
- package/lib/BaseSelect/Polite.d.ts +7 -0
- package/lib/BaseSelect/Polite.js +34 -0
- package/lib/BaseSelect/index.d.ts +118 -0
- package/lib/BaseSelect/index.js +579 -0
- package/lib/OptGroup.d.ts +12 -0
- package/lib/OptGroup.js +12 -0
- package/lib/Option.d.ts +14 -0
- package/lib/Option.js +12 -0
- package/lib/OptionList.d.ts +10 -0
- package/lib/OptionList.js +387 -0
- package/lib/Select.d.ts +114 -0
- package/lib/Select.js +487 -0
- package/lib/SelectContext.d.ts +23 -0
- package/lib/SelectContext.js +13 -0
- package/lib/SelectTrigger.d.ts +30 -0
- package/lib/SelectTrigger.js +147 -0
- package/lib/Selector/Input.d.ts +27 -0
- package/lib/Selector/Input.js +123 -0
- package/lib/Selector/MultipleSelector.d.ts +16 -0
- package/lib/Selector/MultipleSelector.js +194 -0
- package/lib/Selector/SingleSelector.d.ts +8 -0
- package/lib/Selector/SingleSelector.js +113 -0
- package/lib/Selector/index.d.ts +85 -0
- package/lib/Selector/index.js +191 -0
- package/lib/TransBtn.d.ts +12 -0
- package/lib/TransBtn.js +39 -0
- package/lib/hooks/useAllowClear.d.ts +8 -0
- package/lib/hooks/useAllowClear.js +34 -0
- package/lib/hooks/useBaseProps.d.ts +13 -0
- package/lib/hooks/useBaseProps.js +19 -0
- package/lib/hooks/useCache.d.ts +7 -0
- package/lib/hooks/useCache.js +49 -0
- package/lib/hooks/useDelayReset.d.ts +5 -0
- package/lib/hooks/useDelayReset.js +31 -0
- package/lib/hooks/useFilterOptions.d.ts +3 -0
- package/lib/hooks/useFilterOptions.js +66 -0
- package/lib/hooks/useId.d.ts +5 -0
- package/lib/hooks/useId.js +40 -0
- package/lib/hooks/useLayoutEffect.d.ts +5 -0
- package/lib/hooks/useLayoutEffect.js +25 -0
- package/lib/hooks/useLock.d.ts +7 -0
- package/lib/hooks/useLock.js +34 -0
- package/lib/hooks/useOptions.d.ts +12 -0
- package/lib/hooks/useOptions.js +52 -0
- package/lib/hooks/useRefFunc.d.ts +5 -0
- package/lib/hooks/useRefFunc.js +21 -0
- package/lib/hooks/useSelectTriggerControl.d.ts +1 -0
- package/lib/hooks/useSelectTriggerControl.js +35 -0
- package/lib/index.d.ts +10 -0
- package/lib/index.js +37 -0
- package/lib/interface.d.ts +23 -0
- package/lib/interface.js +5 -0
- package/lib/utils/__mocks__/platformUtil.d.ts +1 -0
- package/lib/utils/__mocks__/platformUtil.js +9 -0
- package/lib/utils/commonUtil.d.ts +9 -0
- package/lib/utils/commonUtil.js +42 -0
- package/lib/utils/keyUtil.d.ts +2 -0
- package/lib/utils/keyUtil.js +22 -0
- package/lib/utils/legacyUtil.d.ts +3 -0
- package/lib/utils/legacyUtil.js +53 -0
- package/lib/utils/platformUtil.d.ts +1 -0
- package/lib/utils/platformUtil.js +10 -0
- package/lib/utils/valueUtil.d.ts +24 -0
- package/lib/utils/valueUtil.js +140 -0
- package/lib/utils/warningPropsUtil.d.ts +4 -0
- package/lib/utils/warningPropsUtil.js +129 -0
- package/package.json +86 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cursor rule:
|
|
3
|
+
* 1. Only `showSearch` enabled
|
|
4
|
+
* 2. Only `open` is `true`
|
|
5
|
+
* 3. When typing, set `open` to `true` which hit rule of 2
|
|
6
|
+
*
|
|
7
|
+
* Accessibility:
|
|
8
|
+
* - https://www.w3.org/TR/wai-aria-practices/examples/combobox/aria1.1pattern/listbox-combo.html
|
|
9
|
+
*/
|
|
10
|
+
import type { ScrollTo } from 'rc-virtual-list/lib/List';
|
|
11
|
+
import * as React from 'react';
|
|
12
|
+
import type { CustomTagProps, DisplayValueType, Mode, RenderNode } from '../BaseSelect';
|
|
13
|
+
export interface InnerSelectorProps {
|
|
14
|
+
prefixCls: string;
|
|
15
|
+
id: string;
|
|
16
|
+
mode: Mode;
|
|
17
|
+
title?: string;
|
|
18
|
+
inputRef: React.Ref<HTMLInputElement | HTMLTextAreaElement>;
|
|
19
|
+
placeholder?: React.ReactNode;
|
|
20
|
+
disabled?: boolean;
|
|
21
|
+
autoFocus?: boolean;
|
|
22
|
+
autoComplete?: string;
|
|
23
|
+
values: DisplayValueType[];
|
|
24
|
+
showSearch?: boolean;
|
|
25
|
+
searchValue: string;
|
|
26
|
+
autoClearSearchValue?: boolean;
|
|
27
|
+
activeDescendantId?: string;
|
|
28
|
+
open: boolean;
|
|
29
|
+
tabIndex?: number;
|
|
30
|
+
maxLength?: number;
|
|
31
|
+
onInputKeyDown: React.KeyboardEventHandler<HTMLInputElement | HTMLTextAreaElement>;
|
|
32
|
+
onInputMouseDown: React.MouseEventHandler<HTMLInputElement | HTMLTextAreaElement>;
|
|
33
|
+
onInputChange: React.ChangeEventHandler<HTMLInputElement | HTMLTextAreaElement>;
|
|
34
|
+
onInputPaste: React.ClipboardEventHandler<HTMLInputElement | HTMLTextAreaElement>;
|
|
35
|
+
onInputCompositionStart: React.CompositionEventHandler<HTMLInputElement | HTMLTextAreaElement>;
|
|
36
|
+
onInputCompositionEnd: React.CompositionEventHandler<HTMLInputElement | HTMLTextAreaElement>;
|
|
37
|
+
onInputBlur: React.FocusEventHandler<HTMLInputElement | HTMLTextAreaElement>;
|
|
38
|
+
}
|
|
39
|
+
export interface RefSelectorProps {
|
|
40
|
+
focus: (options?: FocusOptions) => void;
|
|
41
|
+
blur: () => void;
|
|
42
|
+
scrollTo?: ScrollTo;
|
|
43
|
+
}
|
|
44
|
+
export interface SelectorProps {
|
|
45
|
+
id: string;
|
|
46
|
+
prefixCls: string;
|
|
47
|
+
showSearch?: boolean;
|
|
48
|
+
open: boolean;
|
|
49
|
+
/** Display in the Selector value, it's not same as `value` prop */
|
|
50
|
+
values: DisplayValueType[];
|
|
51
|
+
mode: Mode;
|
|
52
|
+
searchValue: string;
|
|
53
|
+
activeValue: string;
|
|
54
|
+
autoClearSearchValue: boolean;
|
|
55
|
+
inputElement: JSX.Element;
|
|
56
|
+
maxLength?: number;
|
|
57
|
+
autoFocus?: boolean;
|
|
58
|
+
activeDescendantId?: string;
|
|
59
|
+
tabIndex?: number;
|
|
60
|
+
disabled?: boolean;
|
|
61
|
+
placeholder?: React.ReactNode;
|
|
62
|
+
removeIcon?: RenderNode;
|
|
63
|
+
prefix?: React.ReactNode;
|
|
64
|
+
maxTagCount?: number | 'responsive';
|
|
65
|
+
maxTagTextLength?: number;
|
|
66
|
+
maxTagPlaceholder?: React.ReactNode | ((omittedValues: DisplayValueType[]) => React.ReactNode);
|
|
67
|
+
tagRender?: (props: CustomTagProps) => React.ReactElement;
|
|
68
|
+
/** Check if `tokenSeparators` contains `\n` or `\r\n` */
|
|
69
|
+
tokenWithEnter?: boolean;
|
|
70
|
+
choiceTransitionName?: string;
|
|
71
|
+
onToggleOpen: (open?: boolean) => void;
|
|
72
|
+
/** `onSearch` returns go next step boolean to check if need do toggle open */
|
|
73
|
+
onSearch: (searchText: string, fromTyping: boolean, isCompositing: boolean) => boolean;
|
|
74
|
+
onSearchSubmit?: (searchText: string) => void;
|
|
75
|
+
onRemove: (value: DisplayValueType) => void;
|
|
76
|
+
onInputKeyDown?: React.KeyboardEventHandler<HTMLInputElement | HTMLTextAreaElement>;
|
|
77
|
+
onInputBlur?: () => void;
|
|
78
|
+
/**
|
|
79
|
+
* @private get real dom for trigger align.
|
|
80
|
+
* This may be removed after React provides replacement of `findDOMNode`
|
|
81
|
+
*/
|
|
82
|
+
domRef: React.Ref<HTMLDivElement>;
|
|
83
|
+
}
|
|
84
|
+
declare const ForwardSelector: React.ForwardRefExoticComponent<SelectorProps & React.RefAttributes<RefSelectorProps>>;
|
|
85
|
+
export default ForwardSelector;
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _KeyCode = _interopRequireDefault(require("@rc-component/util/lib/KeyCode"));
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
+
var React = _react;
|
|
10
|
+
var _useLock = _interopRequireDefault(require("../hooks/useLock"));
|
|
11
|
+
var _keyUtil = require("../utils/keyUtil");
|
|
12
|
+
var _MultipleSelector = _interopRequireDefault(require("./MultipleSelector"));
|
|
13
|
+
var _SingleSelector = _interopRequireDefault(require("./SingleSelector"));
|
|
14
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
15
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
+
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } /**
|
|
18
|
+
* Cursor rule:
|
|
19
|
+
* 1. Only `showSearch` enabled
|
|
20
|
+
* 2. Only `open` is `true`
|
|
21
|
+
* 3. When typing, set `open` to `true` which hit rule of 2
|
|
22
|
+
*
|
|
23
|
+
* Accessibility:
|
|
24
|
+
* - https://www.w3.org/TR/wai-aria-practices/examples/combobox/aria1.1pattern/listbox-combo.html
|
|
25
|
+
*/
|
|
26
|
+
const Selector = (props, ref) => {
|
|
27
|
+
const inputRef = (0, _react.useRef)(null);
|
|
28
|
+
const compositionStatusRef = (0, _react.useRef)(false);
|
|
29
|
+
const {
|
|
30
|
+
prefixCls,
|
|
31
|
+
open,
|
|
32
|
+
mode,
|
|
33
|
+
showSearch,
|
|
34
|
+
tokenWithEnter,
|
|
35
|
+
disabled,
|
|
36
|
+
prefix,
|
|
37
|
+
autoClearSearchValue,
|
|
38
|
+
onSearch,
|
|
39
|
+
onSearchSubmit,
|
|
40
|
+
onToggleOpen,
|
|
41
|
+
onInputKeyDown,
|
|
42
|
+
onInputBlur,
|
|
43
|
+
domRef
|
|
44
|
+
} = props;
|
|
45
|
+
|
|
46
|
+
// ======================= Ref =======================
|
|
47
|
+
React.useImperativeHandle(ref, () => ({
|
|
48
|
+
focus: options => {
|
|
49
|
+
inputRef.current.focus(options);
|
|
50
|
+
},
|
|
51
|
+
blur: () => {
|
|
52
|
+
inputRef.current.blur();
|
|
53
|
+
}
|
|
54
|
+
}));
|
|
55
|
+
|
|
56
|
+
// ====================== Input ======================
|
|
57
|
+
const [getInputMouseDown, setInputMouseDown] = (0, _useLock.default)(0);
|
|
58
|
+
const onInternalInputKeyDown = event => {
|
|
59
|
+
const {
|
|
60
|
+
which
|
|
61
|
+
} = event;
|
|
62
|
+
|
|
63
|
+
// Compatible with multiple lines in TextArea
|
|
64
|
+
const isTextAreaElement = inputRef.current instanceof HTMLTextAreaElement;
|
|
65
|
+
if (!isTextAreaElement && open && (which === _KeyCode.default.UP || which === _KeyCode.default.DOWN)) {
|
|
66
|
+
event.preventDefault();
|
|
67
|
+
}
|
|
68
|
+
if (onInputKeyDown) {
|
|
69
|
+
onInputKeyDown(event);
|
|
70
|
+
}
|
|
71
|
+
if (which === _KeyCode.default.ENTER && mode === 'tags' && !compositionStatusRef.current && !open) {
|
|
72
|
+
// When menu isn't open, OptionList won't trigger a value change
|
|
73
|
+
// So when enter is pressed, the tag's input value should be emitted here to let selector know
|
|
74
|
+
onSearchSubmit?.(event.target.value);
|
|
75
|
+
}
|
|
76
|
+
// Move within the text box
|
|
77
|
+
if (isTextAreaElement && !open && ~[_KeyCode.default.UP, _KeyCode.default.DOWN, _KeyCode.default.LEFT, _KeyCode.default.RIGHT].indexOf(which)) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if ((0, _keyUtil.isValidateOpenKey)(which)) {
|
|
81
|
+
onToggleOpen(true);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* We can not use `findDOMNode` sine it will get warning,
|
|
87
|
+
* have to use timer to check if is input element.
|
|
88
|
+
*/
|
|
89
|
+
const onInternalInputMouseDown = () => {
|
|
90
|
+
setInputMouseDown(true);
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
// When paste come, ignore next onChange
|
|
94
|
+
const pastedTextRef = (0, _react.useRef)(null);
|
|
95
|
+
const triggerOnSearch = value => {
|
|
96
|
+
if (onSearch(value, true, compositionStatusRef.current) !== false) {
|
|
97
|
+
onToggleOpen(true);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
const onInputCompositionStart = () => {
|
|
101
|
+
compositionStatusRef.current = true;
|
|
102
|
+
};
|
|
103
|
+
const onInputCompositionEnd = e => {
|
|
104
|
+
compositionStatusRef.current = false;
|
|
105
|
+
|
|
106
|
+
// Trigger search again to support `tokenSeparators` with typewriting
|
|
107
|
+
if (mode !== 'combobox') {
|
|
108
|
+
triggerOnSearch(e.target.value);
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
const onInputChange = event => {
|
|
112
|
+
let {
|
|
113
|
+
target: {
|
|
114
|
+
value
|
|
115
|
+
}
|
|
116
|
+
} = event;
|
|
117
|
+
|
|
118
|
+
// Pasted text should replace back to origin content
|
|
119
|
+
if (tokenWithEnter && pastedTextRef.current && /[\r\n]/.test(pastedTextRef.current)) {
|
|
120
|
+
// CRLF will be treated as a single space for input element
|
|
121
|
+
const replacedText = pastedTextRef.current.replace(/[\r\n]+$/, '').replace(/\r\n/g, ' ').replace(/[\r\n]/g, ' ');
|
|
122
|
+
value = value.replace(replacedText, pastedTextRef.current);
|
|
123
|
+
}
|
|
124
|
+
pastedTextRef.current = null;
|
|
125
|
+
triggerOnSearch(value);
|
|
126
|
+
};
|
|
127
|
+
const onInputPaste = e => {
|
|
128
|
+
const {
|
|
129
|
+
clipboardData
|
|
130
|
+
} = e;
|
|
131
|
+
const value = clipboardData?.getData('text');
|
|
132
|
+
pastedTextRef.current = value || '';
|
|
133
|
+
};
|
|
134
|
+
const onClick = ({
|
|
135
|
+
target
|
|
136
|
+
}) => {
|
|
137
|
+
if (target !== inputRef.current) {
|
|
138
|
+
// Should focus input if click the selector
|
|
139
|
+
const isIE = document.body.style.msTouchAction !== undefined;
|
|
140
|
+
if (isIE) {
|
|
141
|
+
setTimeout(() => {
|
|
142
|
+
inputRef.current.focus();
|
|
143
|
+
});
|
|
144
|
+
} else {
|
|
145
|
+
inputRef.current.focus();
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
const onMouseDown = event => {
|
|
150
|
+
const inputMouseDown = getInputMouseDown();
|
|
151
|
+
|
|
152
|
+
// when mode is combobox and it is disabled, don't prevent default behavior
|
|
153
|
+
// https://github.com/ant-design/ant-design/issues/37320
|
|
154
|
+
// https://github.com/ant-design/ant-design/issues/48281
|
|
155
|
+
if (event.target !== inputRef.current && !inputMouseDown && !(mode === 'combobox' && disabled)) {
|
|
156
|
+
event.preventDefault();
|
|
157
|
+
}
|
|
158
|
+
if (mode !== 'combobox' && (!showSearch || !inputMouseDown) || !open) {
|
|
159
|
+
if (open && autoClearSearchValue !== false) {
|
|
160
|
+
onSearch('', true, false);
|
|
161
|
+
}
|
|
162
|
+
onToggleOpen();
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
// ================= Inner Selector ==================
|
|
167
|
+
const sharedProps = {
|
|
168
|
+
inputRef,
|
|
169
|
+
onInputKeyDown: onInternalInputKeyDown,
|
|
170
|
+
onInputMouseDown: onInternalInputMouseDown,
|
|
171
|
+
onInputChange,
|
|
172
|
+
onInputPaste,
|
|
173
|
+
onInputCompositionStart,
|
|
174
|
+
onInputCompositionEnd,
|
|
175
|
+
onInputBlur
|
|
176
|
+
};
|
|
177
|
+
const selectNode = mode === 'multiple' || mode === 'tags' ? /*#__PURE__*/React.createElement(_MultipleSelector.default, _extends({}, props, sharedProps)) : /*#__PURE__*/React.createElement(_SingleSelector.default, _extends({}, props, sharedProps));
|
|
178
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
179
|
+
ref: domRef,
|
|
180
|
+
className: `${prefixCls}-selector`,
|
|
181
|
+
onClick: onClick,
|
|
182
|
+
onMouseDown: onMouseDown
|
|
183
|
+
}, prefix && /*#__PURE__*/React.createElement("div", {
|
|
184
|
+
className: `${prefixCls}-prefix`
|
|
185
|
+
}, prefix), selectNode);
|
|
186
|
+
};
|
|
187
|
+
const ForwardSelector = /*#__PURE__*/React.forwardRef(Selector);
|
|
188
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
189
|
+
ForwardSelector.displayName = 'Selector';
|
|
190
|
+
}
|
|
191
|
+
var _default = exports.default = ForwardSelector;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import type { RenderNode } from './BaseSelect';
|
|
3
|
+
export interface TransBtnProps {
|
|
4
|
+
className: string;
|
|
5
|
+
customizeIcon: RenderNode;
|
|
6
|
+
customizeIconProps?: any;
|
|
7
|
+
onMouseDown?: React.MouseEventHandler<HTMLSpanElement>;
|
|
8
|
+
onClick?: React.MouseEventHandler<HTMLSpanElement>;
|
|
9
|
+
children?: React.ReactNode;
|
|
10
|
+
}
|
|
11
|
+
declare const TransBtn: React.FC<TransBtnProps>;
|
|
12
|
+
export default TransBtn;
|
package/lib/TransBtn.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var React = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
11
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
12
|
+
const TransBtn = props => {
|
|
13
|
+
const {
|
|
14
|
+
className,
|
|
15
|
+
customizeIcon,
|
|
16
|
+
customizeIconProps,
|
|
17
|
+
children,
|
|
18
|
+
onMouseDown,
|
|
19
|
+
onClick
|
|
20
|
+
} = props;
|
|
21
|
+
const icon = typeof customizeIcon === 'function' ? customizeIcon(customizeIconProps) : customizeIcon;
|
|
22
|
+
return /*#__PURE__*/React.createElement("span", {
|
|
23
|
+
className: className,
|
|
24
|
+
onMouseDown: event => {
|
|
25
|
+
event.preventDefault();
|
|
26
|
+
onMouseDown?.(event);
|
|
27
|
+
},
|
|
28
|
+
style: {
|
|
29
|
+
userSelect: 'none',
|
|
30
|
+
WebkitUserSelect: 'none'
|
|
31
|
+
},
|
|
32
|
+
unselectable: "on",
|
|
33
|
+
onClick: onClick,
|
|
34
|
+
"aria-hidden": true
|
|
35
|
+
}, icon !== undefined ? icon : /*#__PURE__*/React.createElement("span", {
|
|
36
|
+
className: (0, _classnames.default)(className.split(/\s+/).map(cls => `${cls}-icon`))
|
|
37
|
+
}, children));
|
|
38
|
+
};
|
|
39
|
+
var _default = exports.default = TransBtn;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { DisplayValueType, Mode, RenderNode } from '../interface';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
export declare const useAllowClear: (prefixCls: string, onClearMouseDown: React.MouseEventHandler<HTMLSpanElement>, displayValues: DisplayValueType[], allowClear?: boolean | {
|
|
4
|
+
clearIcon?: RenderNode;
|
|
5
|
+
}, clearIcon?: RenderNode, disabled?: boolean, mergedSearchValue?: string, mode?: Mode) => {
|
|
6
|
+
allowClear: boolean;
|
|
7
|
+
clearIcon: React.JSX.Element;
|
|
8
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useAllowClear = void 0;
|
|
7
|
+
var _TransBtn = _interopRequireDefault(require("../TransBtn"));
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
+
const useAllowClear = (prefixCls, onClearMouseDown, displayValues, allowClear, clearIcon, disabled = false, mergedSearchValue, mode) => {
|
|
11
|
+
const mergedClearIcon = _react.default.useMemo(() => {
|
|
12
|
+
if (typeof allowClear === 'object') {
|
|
13
|
+
return allowClear.clearIcon;
|
|
14
|
+
}
|
|
15
|
+
if (clearIcon) {
|
|
16
|
+
return clearIcon;
|
|
17
|
+
}
|
|
18
|
+
}, [allowClear, clearIcon]);
|
|
19
|
+
const mergedAllowClear = _react.default.useMemo(() => {
|
|
20
|
+
if (!disabled && !!allowClear && (displayValues.length || mergedSearchValue) && !(mode === 'combobox' && mergedSearchValue === '')) {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
return false;
|
|
24
|
+
}, [allowClear, disabled, displayValues.length, mergedSearchValue, mode]);
|
|
25
|
+
return {
|
|
26
|
+
allowClear: mergedAllowClear,
|
|
27
|
+
clearIcon: /*#__PURE__*/_react.default.createElement(_TransBtn.default, {
|
|
28
|
+
className: `${prefixCls}-clear`,
|
|
29
|
+
onMouseDown: onClearMouseDown,
|
|
30
|
+
customizeIcon: mergedClearIcon
|
|
31
|
+
}, "\xD7")
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
exports.useAllowClear = useAllowClear;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BaseSelect provide some parsed data into context.
|
|
3
|
+
* You can use this hooks to get them.
|
|
4
|
+
*/
|
|
5
|
+
import * as React from 'react';
|
|
6
|
+
import type { BaseSelectProps } from '../BaseSelect';
|
|
7
|
+
export interface BaseSelectContextProps extends BaseSelectProps {
|
|
8
|
+
triggerOpen: boolean;
|
|
9
|
+
multiple: boolean;
|
|
10
|
+
toggleOpen: (open?: boolean) => void;
|
|
11
|
+
}
|
|
12
|
+
export declare const BaseSelectContext: React.Context<BaseSelectContextProps>;
|
|
13
|
+
export default function useBaseProps(): BaseSelectContextProps;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.BaseSelectContext = void 0;
|
|
7
|
+
exports.default = useBaseProps;
|
|
8
|
+
var React = _interopRequireWildcard(require("react"));
|
|
9
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
10
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
11
|
+
/**
|
|
12
|
+
* BaseSelect provide some parsed data into context.
|
|
13
|
+
* You can use this hooks to get them.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
const BaseSelectContext = exports.BaseSelectContext = /*#__PURE__*/React.createContext(null);
|
|
17
|
+
function useBaseProps() {
|
|
18
|
+
return React.useContext(BaseSelectContext);
|
|
19
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { RawValueType } from '../BaseSelect';
|
|
2
|
+
import type { DefaultOptionType, LabelInValueType } from '../Select';
|
|
3
|
+
/**
|
|
4
|
+
* Cache `value` related LabeledValue & options.
|
|
5
|
+
*/
|
|
6
|
+
declare const _default: (labeledValues: LabelInValueType[], valueOptions: Map<RawValueType, DefaultOptionType>) => [LabelInValueType[], (val: RawValueType) => DefaultOptionType];
|
|
7
|
+
export default _default;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var React = _interopRequireWildcard(require("react"));
|
|
8
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
9
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
10
|
+
/**
|
|
11
|
+
* Cache `value` related LabeledValue & options.
|
|
12
|
+
*/
|
|
13
|
+
var _default = (labeledValues, valueOptions) => {
|
|
14
|
+
const cacheRef = React.useRef({
|
|
15
|
+
values: new Map(),
|
|
16
|
+
options: new Map()
|
|
17
|
+
});
|
|
18
|
+
const filledLabeledValues = React.useMemo(() => {
|
|
19
|
+
const {
|
|
20
|
+
values: prevValueCache,
|
|
21
|
+
options: prevOptionCache
|
|
22
|
+
} = cacheRef.current;
|
|
23
|
+
|
|
24
|
+
// Fill label by cache
|
|
25
|
+
const patchedValues = labeledValues.map(item => {
|
|
26
|
+
if (item.label === undefined) {
|
|
27
|
+
return {
|
|
28
|
+
...item,
|
|
29
|
+
label: prevValueCache.get(item.value)?.label
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
return item;
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// Refresh cache
|
|
36
|
+
const valueCache = new Map();
|
|
37
|
+
const optionCache = new Map();
|
|
38
|
+
patchedValues.forEach(item => {
|
|
39
|
+
valueCache.set(item.value, item);
|
|
40
|
+
optionCache.set(item.value, valueOptions.get(item.value) || prevOptionCache.get(item.value));
|
|
41
|
+
});
|
|
42
|
+
cacheRef.current.values = valueCache;
|
|
43
|
+
cacheRef.current.options = optionCache;
|
|
44
|
+
return patchedValues;
|
|
45
|
+
}, [labeledValues, valueOptions]);
|
|
46
|
+
const getOption = React.useCallback(val => valueOptions.get(val) || cacheRef.current.options.get(val), [valueOptions]);
|
|
47
|
+
return [filledLabeledValues, getOption];
|
|
48
|
+
};
|
|
49
|
+
exports.default = _default;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Similar with `useLock`, but this hook will always execute last value.
|
|
3
|
+
* When set to `true`, it will keep `true` for a short time even if `false` is set.
|
|
4
|
+
*/
|
|
5
|
+
export default function useDelayReset(timeout?: number): [boolean, (val: boolean, callback?: () => void) => void, () => void];
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = useDelayReset;
|
|
7
|
+
var React = _interopRequireWildcard(require("react"));
|
|
8
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
9
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
10
|
+
/**
|
|
11
|
+
* Similar with `useLock`, but this hook will always execute last value.
|
|
12
|
+
* When set to `true`, it will keep `true` for a short time even if `false` is set.
|
|
13
|
+
*/
|
|
14
|
+
function useDelayReset(timeout = 10) {
|
|
15
|
+
const [bool, setBool] = React.useState(false);
|
|
16
|
+
const delayRef = React.useRef(null);
|
|
17
|
+
const cancelLatest = () => {
|
|
18
|
+
window.clearTimeout(delayRef.current);
|
|
19
|
+
};
|
|
20
|
+
React.useEffect(() => cancelLatest, []);
|
|
21
|
+
const delaySetBool = (value, callback) => {
|
|
22
|
+
cancelLatest();
|
|
23
|
+
delayRef.current = window.setTimeout(() => {
|
|
24
|
+
setBool(value);
|
|
25
|
+
if (callback) {
|
|
26
|
+
callback();
|
|
27
|
+
}
|
|
28
|
+
}, timeout);
|
|
29
|
+
};
|
|
30
|
+
return [bool, delaySetBool, cancelLatest];
|
|
31
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { FieldNames, DefaultOptionType, SelectProps } from '../Select';
|
|
2
|
+
declare const _default: (options: DefaultOptionType[], fieldNames: FieldNames, searchValue?: string, filterOption?: SelectProps['filterOption'], optionFilterProp?: string) => DefaultOptionType[];
|
|
3
|
+
export default _default;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var React = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _commonUtil = require("../utils/commonUtil");
|
|
9
|
+
var _valueUtil = require("../utils/valueUtil");
|
|
10
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
11
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
12
|
+
function includes(test, search) {
|
|
13
|
+
return (0, _commonUtil.toArray)(test).join('').toUpperCase().includes(search);
|
|
14
|
+
}
|
|
15
|
+
var _default = (options, fieldNames, searchValue, filterOption, optionFilterProp) => React.useMemo(() => {
|
|
16
|
+
if (!searchValue || filterOption === false) {
|
|
17
|
+
return options;
|
|
18
|
+
}
|
|
19
|
+
const {
|
|
20
|
+
options: fieldOptions,
|
|
21
|
+
label: fieldLabel,
|
|
22
|
+
value: fieldValue
|
|
23
|
+
} = fieldNames;
|
|
24
|
+
const filteredOptions = [];
|
|
25
|
+
const customizeFilter = typeof filterOption === 'function';
|
|
26
|
+
const upperSearch = searchValue.toUpperCase();
|
|
27
|
+
const filterFunc = customizeFilter ? filterOption : (_, option) => {
|
|
28
|
+
// Use provided `optionFilterProp`
|
|
29
|
+
if (optionFilterProp) {
|
|
30
|
+
return includes(option[optionFilterProp], upperSearch);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Auto select `label` or `value` by option type
|
|
34
|
+
if (option[fieldOptions]) {
|
|
35
|
+
// hack `fieldLabel` since `OptionGroup` children is not `label`
|
|
36
|
+
return includes(option[fieldLabel !== 'children' ? fieldLabel : 'label'], upperSearch);
|
|
37
|
+
}
|
|
38
|
+
return includes(option[fieldValue], upperSearch);
|
|
39
|
+
};
|
|
40
|
+
const wrapOption = customizeFilter ? opt => (0, _valueUtil.injectPropsWithOption)(opt) : opt => opt;
|
|
41
|
+
options.forEach(item => {
|
|
42
|
+
// Group should check child options
|
|
43
|
+
if (item[fieldOptions]) {
|
|
44
|
+
// Check group first
|
|
45
|
+
const matchGroup = filterFunc(searchValue, wrapOption(item));
|
|
46
|
+
if (matchGroup) {
|
|
47
|
+
filteredOptions.push(item);
|
|
48
|
+
} else {
|
|
49
|
+
// Check option
|
|
50
|
+
const subOptions = item[fieldOptions].filter(subItem => filterFunc(searchValue, wrapOption(subItem)));
|
|
51
|
+
if (subOptions.length) {
|
|
52
|
+
filteredOptions.push({
|
|
53
|
+
...item,
|
|
54
|
+
[fieldOptions]: subOptions
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (filterFunc(searchValue, wrapOption(item))) {
|
|
61
|
+
filteredOptions.push(item);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
return filteredOptions;
|
|
65
|
+
}, [options, filterOption, optionFilterProp, searchValue, fieldNames]);
|
|
66
|
+
exports.default = _default;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = useId;
|
|
7
|
+
exports.getUUID = getUUID;
|
|
8
|
+
exports.isBrowserClient = void 0;
|
|
9
|
+
var React = _interopRequireWildcard(require("react"));
|
|
10
|
+
var _canUseDom = _interopRequireDefault(require("@rc-component/util/lib/Dom/canUseDom"));
|
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
13
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
14
|
+
let uuid = 0;
|
|
15
|
+
|
|
16
|
+
/** Is client side and not jsdom */
|
|
17
|
+
const isBrowserClient = exports.isBrowserClient = process.env.NODE_ENV !== 'test' && (0, _canUseDom.default)();
|
|
18
|
+
|
|
19
|
+
/** Get unique id for accessibility usage */
|
|
20
|
+
function getUUID() {
|
|
21
|
+
let retId;
|
|
22
|
+
|
|
23
|
+
// Test never reach
|
|
24
|
+
/* istanbul ignore if */
|
|
25
|
+
if (isBrowserClient) {
|
|
26
|
+
retId = uuid;
|
|
27
|
+
uuid += 1;
|
|
28
|
+
} else {
|
|
29
|
+
retId = 'TEST_OR_SSR';
|
|
30
|
+
}
|
|
31
|
+
return retId;
|
|
32
|
+
}
|
|
33
|
+
function useId(id) {
|
|
34
|
+
// Inner id for accessibility usage. Only work in client side
|
|
35
|
+
const [innerId, setInnerId] = React.useState();
|
|
36
|
+
React.useEffect(() => {
|
|
37
|
+
setInnerId(`rc_select_${getUUID()}`);
|
|
38
|
+
}, []);
|
|
39
|
+
return id || innerId;
|
|
40
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = useLayoutEffect;
|
|
7
|
+
var React = _interopRequireWildcard(require("react"));
|
|
8
|
+
var _commonUtil = require("../utils/commonUtil");
|
|
9
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
10
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
11
|
+
/* eslint-disable react-hooks/rules-of-hooks */
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Wrap `React.useLayoutEffect` which will not throw warning message in test env
|
|
15
|
+
*/
|
|
16
|
+
function useLayoutEffect(effect, deps) {
|
|
17
|
+
// Never happen in test env
|
|
18
|
+
if (_commonUtil.isBrowserClient) {
|
|
19
|
+
/* istanbul ignore next */
|
|
20
|
+
React.useLayoutEffect(effect, deps);
|
|
21
|
+
} else {
|
|
22
|
+
React.useEffect(effect, deps);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/* eslint-enable */
|