rsuite 5.16.1 → 5.16.4
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/CHANGELOG.md +27 -0
- package/Picker/styles/index.less +3 -1
- package/Slider/styles/index.less +2 -1
- package/TreePicker/styles/index.less +0 -3
- package/cjs/Cascader/utils.js +3 -5
- package/cjs/CheckPicker/CheckPicker.d.ts +1 -1
- package/cjs/CheckPicker/test/CheckPicker.test.js +8 -0
- package/cjs/CheckTreePicker/CheckTreePicker.d.ts +2 -2
- package/cjs/CheckTreePicker/CheckTreePicker.js +5 -0
- package/cjs/CheckTreePicker/test/CheckTreePicker.test.d.ts +1 -0
- package/cjs/CheckTreePicker/test/CheckTreePicker.test.js +15 -0
- package/cjs/CheckTreePicker/utils.js +3 -1
- package/cjs/CustomProvider/CustomProvider.js +6 -3
- package/cjs/DatePicker/DatePicker.d.ts +1 -1
- package/cjs/DatePicker/DatePicker.js +1 -1
- package/cjs/DatePicker/Toolbar.js +1 -1
- package/cjs/DateRangePicker/Calendar.d.ts +0 -1
- package/cjs/DateRangePicker/Calendar.js +1 -39
- package/cjs/DateRangePicker/DateRangePicker.d.ts +1 -1
- package/cjs/DateRangePicker/DateRangePicker.js +23 -23
- package/cjs/DateRangePicker/utils.d.ts +2 -1
- package/cjs/DateRangePicker/utils.js +12 -3
- package/cjs/InputPicker/InputPicker.d.ts +2 -2
- package/cjs/InputPicker/test/InputPicker.test.d.ts +1 -0
- package/cjs/InputPicker/test/InputPicker.test.js +15 -0
- package/cjs/MultiCascader/utils.js +3 -2
- package/cjs/Overlay/OverlayTrigger.js +43 -34
- package/cjs/Panel/Panel.js +8 -7
- package/cjs/Picker/DropdownMenu.d.ts +1 -1
- package/cjs/Picker/PickerToggle.d.ts +1 -1
- package/cjs/Picker/PickerToggle.js +52 -27
- package/cjs/SelectPicker/SelectPicker.d.ts +9 -3
- package/cjs/SelectPicker/test/SelectPicker.test.js +33 -0
- package/cjs/Tree/Tree.d.ts +2 -2
- package/cjs/Tree/test/Tree.test.d.ts +1 -0
- package/cjs/Tree/test/Tree.test.js +18 -0
- package/cjs/TreePicker/TreePicker.d.ts +2 -2
- package/cjs/TreePicker/test/TreePicker.test.d.ts +1 -0
- package/cjs/TreePicker/test/TreePicker.test.js +15 -0
- package/cjs/utils/attachParent.d.ts +1 -0
- package/cjs/utils/attachParent.js +15 -0
- package/cjs/utils/treeUtils.js +3 -2
- package/cjs/utils/usePortal.d.ts +4 -2
- package/cjs/utils/usePortal.js +40 -14
- package/dist/rsuite-rtl.css +9 -10
- package/dist/rsuite-rtl.min.css +1 -1
- package/dist/rsuite-rtl.min.css.map +1 -1
- package/dist/rsuite.css +9 -10
- package/dist/rsuite.js +29 -18
- package/dist/rsuite.js.map +1 -1
- package/dist/rsuite.min.css +1 -1
- package/dist/rsuite.min.css.map +1 -1
- package/dist/rsuite.min.js +1 -1
- package/dist/rsuite.min.js.map +1 -1
- package/esm/Cascader/utils.js +2 -4
- package/esm/CheckPicker/CheckPicker.d.ts +1 -1
- package/esm/CheckPicker/test/CheckPicker.test.js +8 -0
- package/esm/CheckTreePicker/CheckTreePicker.d.ts +2 -2
- package/esm/CheckTreePicker/CheckTreePicker.js +5 -0
- package/esm/CheckTreePicker/test/CheckTreePicker.test.d.ts +1 -0
- package/esm/CheckTreePicker/test/CheckTreePicker.test.js +10 -0
- package/esm/CheckTreePicker/utils.js +2 -1
- package/esm/CustomProvider/CustomProvider.js +6 -3
- package/esm/DatePicker/DatePicker.d.ts +1 -1
- package/esm/DatePicker/DatePicker.js +1 -1
- package/esm/DatePicker/Toolbar.js +1 -1
- package/esm/DateRangePicker/Calendar.d.ts +0 -1
- package/esm/DateRangePicker/Calendar.js +2 -41
- package/esm/DateRangePicker/DateRangePicker.d.ts +1 -1
- package/esm/DateRangePicker/DateRangePicker.js +23 -23
- package/esm/DateRangePicker/utils.d.ts +2 -1
- package/esm/DateRangePicker/utils.js +12 -3
- package/esm/InputPicker/InputPicker.d.ts +2 -2
- package/esm/InputPicker/test/InputPicker.test.d.ts +1 -0
- package/esm/InputPicker/test/InputPicker.test.js +10 -0
- package/esm/MultiCascader/utils.js +2 -2
- package/esm/Overlay/OverlayTrigger.js +44 -35
- package/esm/Panel/Panel.js +8 -7
- package/esm/Picker/DropdownMenu.d.ts +1 -1
- package/esm/Picker/PickerToggle.d.ts +1 -1
- package/esm/Picker/PickerToggle.js +52 -27
- package/esm/SelectPicker/SelectPicker.d.ts +9 -3
- package/esm/SelectPicker/test/SelectPicker.test.js +32 -0
- package/esm/Tree/Tree.d.ts +2 -2
- package/esm/Tree/test/Tree.test.d.ts +1 -0
- package/esm/Tree/test/Tree.test.js +11 -0
- package/esm/TreePicker/TreePicker.d.ts +2 -2
- package/esm/TreePicker/test/TreePicker.test.d.ts +1 -0
- package/esm/TreePicker/test/TreePicker.test.js +10 -0
- package/esm/utils/attachParent.d.ts +1 -0
- package/esm/utils/attachParent.js +10 -0
- package/esm/utils/treeUtils.js +2 -2
- package/esm/utils/usePortal.d.ts +4 -2
- package/esm/utils/usePortal.js +36 -14
- package/package.json +1 -1
|
@@ -15,7 +15,7 @@ export interface PickerToggleProps extends ToggleButtonProps {
|
|
|
15
15
|
readOnly?: boolean;
|
|
16
16
|
plaintext?: boolean;
|
|
17
17
|
tabIndex?: number;
|
|
18
|
-
|
|
18
|
+
editable?: boolean;
|
|
19
19
|
inputPlaceholder?: string;
|
|
20
20
|
inputMask?: (string | RegExp)[];
|
|
21
21
|
onInputChange?: (value: string, event: React.ChangeEvent) => void;
|
|
@@ -29,12 +29,12 @@ var PickerToggle = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
29
29
|
readOnly = props.readOnly,
|
|
30
30
|
plaintext = props.plaintext,
|
|
31
31
|
hasValue = props.hasValue,
|
|
32
|
+
editable = props.editable,
|
|
32
33
|
cleanableProp = props.cleanable,
|
|
33
34
|
_props$tabIndex = props.tabIndex,
|
|
34
|
-
|
|
35
|
+
tabIndexProp = _props$tabIndex === void 0 ? editable ? -1 : 0 : _props$tabIndex,
|
|
35
36
|
id = props.id,
|
|
36
37
|
value = props.value,
|
|
37
|
-
input = props.input,
|
|
38
38
|
inputPlaceholder = props.inputPlaceholder,
|
|
39
39
|
inputValueProp = props.inputValue,
|
|
40
40
|
_props$inputMask = props.inputMask,
|
|
@@ -52,9 +52,10 @@ var PickerToggle = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
52
52
|
_props$caretAs = props.caretAs,
|
|
53
53
|
caretAs = _props$caretAs === void 0 ? caretComponent : _props$caretAs,
|
|
54
54
|
label = props.label,
|
|
55
|
-
rest = _objectWithoutPropertiesLoose(props, ["active", "as", "classPrefix", "children", "caret", "className", "disabled", "readOnly", "plaintext", "hasValue", "cleanable", "tabIndex", "id", "value", "
|
|
55
|
+
rest = _objectWithoutPropertiesLoose(props, ["active", "as", "classPrefix", "children", "caret", "className", "disabled", "readOnly", "plaintext", "hasValue", "editable", "cleanable", "tabIndex", "id", "value", "inputPlaceholder", "inputValue", "inputMask", "onInputChange", "onInputPressEnter", "onInputBlur", "onInputFocus", "onClean", "onFocus", "onBlur", "placement", "caretComponent", "caretAs", "label"]);
|
|
56
56
|
|
|
57
57
|
var inputRef = useRef(null);
|
|
58
|
+
var comboboxRef = useRef(null);
|
|
58
59
|
|
|
59
60
|
var _useState = useState(false),
|
|
60
61
|
activeState = _useState[0],
|
|
@@ -74,30 +75,46 @@ var PickerToggle = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
74
75
|
setInputValue = _useState2[1];
|
|
75
76
|
|
|
76
77
|
useEffect(function () {
|
|
77
|
-
|
|
78
|
-
|
|
78
|
+
if (comboboxRef.current) {
|
|
79
|
+
var _value = getInputValue();
|
|
80
|
+
|
|
81
|
+
setInputValue(_value);
|
|
82
|
+
}
|
|
79
83
|
}, [getInputValue]);
|
|
80
84
|
var classes = merge(className, withClassPrefix({
|
|
81
85
|
active: activeProp || activeState
|
|
82
86
|
}));
|
|
83
87
|
var handleFocus = useCallback(function (event) {
|
|
84
88
|
setActive(true);
|
|
85
|
-
onFocus === null || onFocus === void 0 ? void 0 : onFocus(event);
|
|
86
89
|
|
|
87
|
-
if (
|
|
88
|
-
|
|
90
|
+
if (editable) {
|
|
91
|
+
// Avoid firing the onFocus event twice when DatePicker and DateRangePicker allow keyboard input.
|
|
92
|
+
if (event.target === inputRef.current) {
|
|
93
|
+
onFocus === null || onFocus === void 0 ? void 0 : onFocus(event);
|
|
94
|
+
} // Force the input to be focused and editable.
|
|
89
95
|
|
|
90
|
-
|
|
96
|
+
|
|
97
|
+
if (document.activeElement === comboboxRef.current) {
|
|
98
|
+
var _inputRef$current;
|
|
99
|
+
|
|
100
|
+
(_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 ? void 0 : _inputRef$current.focus();
|
|
101
|
+
}
|
|
102
|
+
} else {
|
|
103
|
+
onFocus === null || onFocus === void 0 ? void 0 : onFocus(event);
|
|
91
104
|
}
|
|
92
|
-
}, [
|
|
105
|
+
}, [editable, onFocus]);
|
|
93
106
|
var handleBlur = useCallback(function (event) {
|
|
94
|
-
if (inputRef.current &&
|
|
107
|
+
if (inputRef.current && !editable) {
|
|
108
|
+
setActive(false);
|
|
109
|
+
} // When activeElement is an input, it remains active.
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
if (editable && inputRef.current && document.activeElement !== inputRef.current) {
|
|
95
113
|
setActive(false);
|
|
96
|
-
inputRef.current.blur();
|
|
97
114
|
}
|
|
98
115
|
|
|
99
116
|
onBlur === null || onBlur === void 0 ? void 0 : onBlur(event);
|
|
100
|
-
}, [onBlur]);
|
|
117
|
+
}, [editable, onBlur]);
|
|
101
118
|
|
|
102
119
|
var handleInputBlur = function handleInputBlur(event) {
|
|
103
120
|
setInputValue(getInputValue());
|
|
@@ -105,10 +122,13 @@ var PickerToggle = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
105
122
|
};
|
|
106
123
|
|
|
107
124
|
var handleClean = useCallback(function (event) {
|
|
125
|
+
var _inputRef$current2, _comboboxRef$current;
|
|
126
|
+
|
|
108
127
|
event.stopPropagation();
|
|
109
|
-
onClean === null || onClean === void 0 ? void 0 : onClean(event);
|
|
110
|
-
|
|
111
|
-
|
|
128
|
+
onClean === null || onClean === void 0 ? void 0 : onClean(event); // When the value is cleared, the current component is still in focus.
|
|
129
|
+
|
|
130
|
+
editable ? (_inputRef$current2 = inputRef.current) === null || _inputRef$current2 === void 0 ? void 0 : _inputRef$current2.focus() : (_comboboxRef$current = comboboxRef.current) === null || _comboboxRef$current === void 0 ? void 0 : _comboboxRef$current.focus();
|
|
131
|
+
}, [editable, onClean]);
|
|
112
132
|
var handleInputChange = useCallback(function (event) {
|
|
113
133
|
var _event$target;
|
|
114
134
|
|
|
@@ -117,10 +137,18 @@ var PickerToggle = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
117
137
|
onInputChange === null || onInputChange === void 0 ? void 0 : onInputChange(value, event);
|
|
118
138
|
}, [onInputChange]);
|
|
119
139
|
var handleInputKeyDown = useCallback(function (event) {
|
|
120
|
-
if (
|
|
140
|
+
if (editable && event.key === KEY_VALUES.ENTER) {
|
|
121
141
|
onInputPressEnter === null || onInputPressEnter === void 0 ? void 0 : onInputPressEnter(event);
|
|
122
142
|
}
|
|
123
|
-
}, [onInputPressEnter,
|
|
143
|
+
}, [onInputPressEnter, editable]);
|
|
144
|
+
var renderInput = useCallback(function (ref, props) {
|
|
145
|
+
return /*#__PURE__*/React.createElement("input", _extends({
|
|
146
|
+
ref: mergeRefs(inputRef, ref),
|
|
147
|
+
style: {
|
|
148
|
+
pointerEvents: editable ? undefined : 'none'
|
|
149
|
+
}
|
|
150
|
+
}, props));
|
|
151
|
+
}, [editable]);
|
|
124
152
|
var ToggleCaret = useToggleCaret(placement);
|
|
125
153
|
var Caret = caretAs !== null && caretAs !== void 0 ? caretAs : ToggleCaret;
|
|
126
154
|
|
|
@@ -133,7 +161,8 @@ var PickerToggle = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
133
161
|
|
|
134
162
|
var showCleanButton = cleanableProp && hasValue && !readOnly; // When the component is read-only or disabled, the input is not interactive.
|
|
135
163
|
|
|
136
|
-
var inputFocused = readOnly || disabled ? false :
|
|
164
|
+
var inputFocused = readOnly || disabled ? false : editable && activeState;
|
|
165
|
+
var tabIndex = disabled ? undefined : tabIndexProp;
|
|
137
166
|
return /*#__PURE__*/React.createElement(Component, _extends({
|
|
138
167
|
role: "combobox",
|
|
139
168
|
"aria-haspopup": "listbox",
|
|
@@ -141,9 +170,9 @@ var PickerToggle = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
141
170
|
"aria-disabled": disabled,
|
|
142
171
|
"aria-owns": id ? id + "-listbox" : undefined
|
|
143
172
|
}, rest, {
|
|
144
|
-
ref: ref,
|
|
173
|
+
ref: mergeRefs(comboboxRef, ref),
|
|
145
174
|
disabled: disabled,
|
|
146
|
-
tabIndex:
|
|
175
|
+
tabIndex: tabIndex,
|
|
147
176
|
className: classes,
|
|
148
177
|
onFocus: !disabled ? handleFocus : null // The debounce is set to 200 to solve the flicker caused by the switch between input and div.
|
|
149
178
|
,
|
|
@@ -160,16 +189,12 @@ var PickerToggle = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
160
189
|
readOnly: !inputFocused,
|
|
161
190
|
disabled: disabled,
|
|
162
191
|
"aria-controls": id ? id + "-listbox" : undefined,
|
|
163
|
-
tabIndex: -1,
|
|
192
|
+
tabIndex: editable ? 0 : -1,
|
|
164
193
|
className: prefix('textbox', {
|
|
165
194
|
'read-only': !inputFocused
|
|
166
195
|
}),
|
|
167
196
|
placeholder: inputPlaceholder,
|
|
168
|
-
render:
|
|
169
|
-
return /*#__PURE__*/React.createElement("input", _extends({
|
|
170
|
-
ref: mergeRefs(inputRef, ref)
|
|
171
|
-
}, props));
|
|
172
|
-
}
|
|
197
|
+
render: renderInput
|
|
173
198
|
}), children ? /*#__PURE__*/React.createElement("span", {
|
|
174
199
|
className: prefix(hasValue ? 'value' : 'placeholder'),
|
|
175
200
|
"aria-placeholder": typeof children === 'string' ? children : undefined
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import React, { Ref } from 'react';
|
|
2
2
|
import { PickerLocale } from '../locales';
|
|
3
3
|
import { PickerInstance, PickerToggleProps } from '../Picker';
|
|
4
|
+
import { ListProps } from '../Picker/VirtualizedList';
|
|
4
5
|
import { FormControlPickerProps, ItemDataType } from '../@types/common';
|
|
5
|
-
import { ListProps } from 'react-virtualized/dist/commonjs/List';
|
|
6
6
|
export interface SelectProps<T> {
|
|
7
7
|
/** Set group condition key in data */
|
|
8
8
|
groupBy?: string;
|
|
@@ -14,7 +14,7 @@ export interface SelectProps<T> {
|
|
|
14
14
|
* List-related properties in `react-virtualized`
|
|
15
15
|
* https://github.com/bvaughn/react-virtualized/blob/master/docs/List.md#prop-types
|
|
16
16
|
*/
|
|
17
|
-
listProps?: ListProps
|
|
17
|
+
listProps?: Partial<ListProps>;
|
|
18
18
|
/** Custom search rules. */
|
|
19
19
|
searchBy?: (keyword: string, label: React.ReactNode, item: ItemDataType) => boolean;
|
|
20
20
|
/** Sort options */
|
|
@@ -40,7 +40,13 @@ export interface MultipleSelectProps<T> extends Omit<SelectProps<T>, 'renderValu
|
|
|
40
40
|
/** Custom render selected items */
|
|
41
41
|
renderValue?: (value: T[], item: ItemDataType<T>[], selectedElement: React.ReactNode) => React.ReactNode;
|
|
42
42
|
}
|
|
43
|
-
export interface SelectPickerProps<T> extends FormControlPickerProps<T, PickerLocale, ItemDataType<T>>, SelectProps<T>, Pick<PickerToggleProps, 'label'> {
|
|
43
|
+
export interface SelectPickerProps<T> extends Omit<FormControlPickerProps<T, PickerLocale, ItemDataType<T>>, 'value' | 'defaultValue' | 'onChange'>, SelectProps<T>, Pick<PickerToggleProps, 'caretAs' | 'label'> {
|
|
44
|
+
/** Initial value */
|
|
45
|
+
defaultValue?: T;
|
|
46
|
+
/** Current value of the component. Creates a controlled component */
|
|
47
|
+
value?: T | null;
|
|
48
|
+
/** Called after the value has been changed */
|
|
49
|
+
onChange?: (value: T | null, event: React.SyntheticEvent) => void;
|
|
44
50
|
}
|
|
45
51
|
export interface SelectPickerComponent {
|
|
46
52
|
<T>(props: SelectPickerProps<T> & {
|
|
@@ -62,4 +62,36 @@ React.createElement(SelectPicker, {
|
|
|
62
62
|
React.createElement(SelectPicker, {
|
|
63
63
|
label: "User",
|
|
64
64
|
data: []
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
/*#__PURE__*/
|
|
68
|
+
React.createElement(SelectPicker, {
|
|
69
|
+
data: [{
|
|
70
|
+
label: 'Ascending',
|
|
71
|
+
value: 'asc'
|
|
72
|
+
}, {
|
|
73
|
+
label: 'Descending',
|
|
74
|
+
value: 'desc'
|
|
75
|
+
}],
|
|
76
|
+
value: "asc",
|
|
77
|
+
onChange: function onChange(value) {
|
|
78
|
+
expectType(value);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
/*#__PURE__*/
|
|
83
|
+
React.createElement(SelectPicker, {
|
|
84
|
+
caretAs: function caretAs() {
|
|
85
|
+
return /*#__PURE__*/React.createElement("div", null);
|
|
86
|
+
},
|
|
87
|
+
data: []
|
|
88
|
+
}); // Override the default value of listProps.
|
|
89
|
+
|
|
90
|
+
/*#__PURE__*/
|
|
91
|
+
React.createElement(SelectPicker, {
|
|
92
|
+
data: [],
|
|
93
|
+
virtualized: true,
|
|
94
|
+
listProps: {
|
|
95
|
+
rowHeight: 70
|
|
96
|
+
}
|
|
65
97
|
});
|
package/esm/Tree/Tree.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { StandardProps, ItemDataType, RsRefForwardingComponent } from '../@types/common';
|
|
3
|
-
import { ListProps } from '
|
|
3
|
+
import { ListProps } from '../Picker/VirtualizedList';
|
|
4
4
|
/**
|
|
5
5
|
* Tree Node Drag Type
|
|
6
6
|
*/
|
|
@@ -50,7 +50,7 @@ export interface TreeBaseProps<ValueType = string | number, ItemDataType = Recor
|
|
|
50
50
|
* List-related properties in `react-virtualized`
|
|
51
51
|
* https://github.com/bvaughn/react-virtualized/blob/master/docs/List.md#prop-types
|
|
52
52
|
*/
|
|
53
|
-
listProps?: ListProps
|
|
53
|
+
listProps?: Partial<ListProps>;
|
|
54
54
|
/** Expand all nodes By default */
|
|
55
55
|
defaultExpandAll?: boolean;
|
|
56
56
|
/** searchKeyword (Controlled) */
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { PickerLocale } from '../locales';
|
|
3
|
-
import { PickerComponent } from '../Picker';
|
|
3
|
+
import { PickerComponent, PickerToggleProps } from '../Picker';
|
|
4
4
|
import { TreeDragProps, TreeBaseProps } from '../Tree/Tree';
|
|
5
5
|
import { FormControlPickerProps, ItemDataType } from '../@types/common';
|
|
6
6
|
export declare const maxTreeHeight = 320;
|
|
7
|
-
export interface TreePickerProps<T = number | string> extends TreeBaseProps<T, ItemDataType>, TreeDragProps, FormControlPickerProps<T, PickerLocale, ItemDataType> {
|
|
7
|
+
export interface TreePickerProps<T = number | string> extends TreeBaseProps<T, ItemDataType>, TreeDragProps, FormControlPickerProps<T, PickerLocale, ItemDataType>, Pick<PickerToggleProps, 'caretAs'> {
|
|
8
8
|
/** The height of Dropdown */
|
|
9
9
|
height?: number;
|
|
10
10
|
/** Tree node cascade */
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function attachParent<T>(data: T, parent: T): T;
|
package/esm/utils/treeUtils.js
CHANGED
|
@@ -13,6 +13,7 @@ import { TREE_NODE_DROP_POSITION, shallowEqual } from '../utils';
|
|
|
13
13
|
import { shouldDisplay } from '../Picker';
|
|
14
14
|
import reactToString from './reactToString';
|
|
15
15
|
import { TREE_NODE_PADDING, TREE_NODE_ROOT_PADDING } from './constants';
|
|
16
|
+
import { attachParent } from './attachParent';
|
|
16
17
|
// gap of tree node
|
|
17
18
|
var TREE_NODE_GAP = 4;
|
|
18
19
|
/**
|
|
@@ -59,8 +60,7 @@ export function flattenTree(tree, childrenKey, executor) {
|
|
|
59
60
|
|
|
60
61
|
data.forEach(function (item, index) {
|
|
61
62
|
var node = typeof executor === 'function' ? executor(item, index) : item;
|
|
62
|
-
node
|
|
63
|
-
flattenData.push(_extends({}, node));
|
|
63
|
+
flattenData.push(attachParent(node, parent));
|
|
64
64
|
|
|
65
65
|
if (item[childrenKey]) {
|
|
66
66
|
traverse(item[childrenKey], item);
|
package/esm/utils/usePortal.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
interface PortalProps {
|
|
3
|
-
id?: string;
|
|
4
3
|
container?: HTMLElement | (() => HTMLElement | null) | null;
|
|
4
|
+
waitMount?: boolean;
|
|
5
5
|
}
|
|
6
6
|
declare function usePortal(props?: PortalProps): {
|
|
7
7
|
target: HTMLElement | null;
|
|
8
|
-
Portal:
|
|
8
|
+
Portal: ((props: any) => JSX.Element) | (({ children }: {
|
|
9
|
+
children: React.ReactNode;
|
|
10
|
+
}) => React.ReactPortal | null);
|
|
9
11
|
};
|
|
10
12
|
export default usePortal;
|
package/esm/utils/usePortal.js
CHANGED
|
@@ -1,6 +1,25 @@
|
|
|
1
|
-
import
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import React, { useRef, useEffect, useState, useCallback } from 'react';
|
|
2
3
|
import { createPortal } from 'react-dom';
|
|
3
4
|
import canUseDOM from 'dom-lib/canUseDOM';
|
|
5
|
+
var MountedPortal = /*#__PURE__*/React.memo(function (_ref) {
|
|
6
|
+
var children = _ref.children,
|
|
7
|
+
container = _ref.container;
|
|
8
|
+
|
|
9
|
+
var _useState = useState(false),
|
|
10
|
+
mounted = _useState[0],
|
|
11
|
+
setMounted = _useState[1];
|
|
12
|
+
|
|
13
|
+
useEffect(function () {
|
|
14
|
+
return setMounted(true);
|
|
15
|
+
}, []);
|
|
16
|
+
|
|
17
|
+
if (container && mounted) {
|
|
18
|
+
return /*#__PURE__*/createPortal(children, container);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return null;
|
|
22
|
+
});
|
|
4
23
|
|
|
5
24
|
function usePortal(props) {
|
|
6
25
|
if (props === void 0) {
|
|
@@ -8,25 +27,28 @@ function usePortal(props) {
|
|
|
8
27
|
}
|
|
9
28
|
|
|
10
29
|
var _props = props,
|
|
11
|
-
|
|
12
|
-
|
|
30
|
+
container = _props.container,
|
|
31
|
+
_props$waitMount = _props.waitMount,
|
|
32
|
+
waitMount = _props$waitMount === void 0 ? false : _props$waitMount;
|
|
13
33
|
var rootElemRef = useRef(canUseDOM ? document.body : null);
|
|
14
34
|
useEffect(function () {
|
|
15
|
-
var containerElement = typeof container === 'function' ? container() : container; //
|
|
16
|
-
|
|
17
|
-
var existingParent = id && document.querySelector("#" + id); // Parent is either a new root or the existing dom element
|
|
35
|
+
var containerElement = typeof container === 'function' ? container() : container; // Parent is either a new root or the existing dom element
|
|
18
36
|
|
|
19
|
-
var parentElement = containerElement ||
|
|
37
|
+
var parentElement = containerElement || document.body;
|
|
20
38
|
rootElemRef.current = parentElement;
|
|
21
|
-
}, [rootElemRef, container
|
|
22
|
-
var Portal = useCallback(function (
|
|
23
|
-
var children =
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
39
|
+
}, [rootElemRef, container]);
|
|
40
|
+
var Portal = useCallback(function (_ref2) {
|
|
41
|
+
var children = _ref2.children;
|
|
42
|
+
return rootElemRef.current != null ? /*#__PURE__*/createPortal(children, rootElemRef.current) : null;
|
|
43
|
+
}, []);
|
|
44
|
+
var WaitMountPortal = useCallback(function (props) {
|
|
45
|
+
return /*#__PURE__*/React.createElement(MountedPortal, _extends({
|
|
46
|
+
container: rootElemRef.current
|
|
47
|
+
}, props));
|
|
48
|
+
}, []);
|
|
27
49
|
return {
|
|
28
50
|
target: rootElemRef.current,
|
|
29
|
-
Portal: Portal
|
|
51
|
+
Portal: waitMount ? WaitMountPortal : Portal
|
|
30
52
|
};
|
|
31
53
|
}
|
|
32
54
|
|