rsuite 5.23.1 → 5.23.3
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/ButtonToolbar/styles/index.less +0 -4
- package/CHANGELOG.md +15 -0
- package/FormHelpText/styles/index.less +2 -2
- package/Modal/styles/index.less +6 -6
- package/Tooltip/styles/index.less +0 -1
- package/cjs/AutoComplete/utils.d.ts +3 -2
- package/cjs/AutoComplete/utils.js +1 -1
- package/cjs/ButtonToolbar/ButtonToolbar.d.ts +2 -1
- package/cjs/ButtonToolbar/ButtonToolbar.js +9 -2
- package/cjs/Cascader/Cascader.js +2 -1
- package/cjs/Cascader/utils.d.ts +17 -12
- package/cjs/Cascader/utils.js +5 -5
- package/cjs/Menu/Menu.js +1 -0
- package/cjs/MultiCascader/utils.d.ts +14 -11
- package/cjs/Nav/NavDropdownMenu.d.ts +2 -0
- package/cjs/Nav/NavDropdownMenu.js +4 -2
- package/cjs/Picker/utils.d.ts +15 -13
- package/cjs/Picker/utils.js +81 -5
- package/cjs/Stack/Stack.d.ts +4 -0
- package/cjs/Stack/Stack.js +10 -8
- package/cjs/utils/treeUtils.d.ts +30 -22
- package/dist/rsuite-rtl.css +7 -9
- package/dist/rsuite-rtl.min.css +1 -1
- package/dist/rsuite-rtl.min.css.map +1 -1
- package/dist/rsuite.css +7 -9
- package/dist/rsuite.js +9 -9
- 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/AutoComplete/utils.d.ts +3 -2
- package/esm/AutoComplete/utils.js +1 -1
- package/esm/ButtonToolbar/ButtonToolbar.d.ts +2 -1
- package/esm/ButtonToolbar/ButtonToolbar.js +9 -2
- package/esm/Cascader/Cascader.js +2 -1
- package/esm/Cascader/utils.d.ts +17 -12
- package/esm/Cascader/utils.js +5 -5
- package/esm/Menu/Menu.js +1 -0
- package/esm/MultiCascader/utils.d.ts +14 -11
- package/esm/Nav/NavDropdownMenu.d.ts +2 -0
- package/esm/Nav/NavDropdownMenu.js +4 -2
- package/esm/Picker/utils.d.ts +15 -13
- package/esm/Picker/utils.js +80 -5
- package/esm/Stack/Stack.d.ts +4 -0
- package/esm/Stack/Stack.js +10 -8
- package/esm/utils/treeUtils.d.ts +30 -22
- package/package.json +1 -1
- package/styles/variables.less +3 -2
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import { ItemDataType } from '../@types/common';
|
|
2
1
|
export declare function transformData(data: any[]): any[];
|
|
3
|
-
export declare const shouldDisplay:
|
|
2
|
+
export declare const shouldDisplay: <TItem extends {
|
|
3
|
+
label: string;
|
|
4
|
+
}>(filterBy: ((value: string, item: TItem) => boolean) | undefined, value: string) => (item: TItem) => boolean;
|
|
@@ -27,7 +27,7 @@ export var shouldDisplay = function shouldDisplay(filterBy, value) {
|
|
|
27
27
|
return false;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
var keyword =
|
|
30
|
+
var keyword = value.toLocaleLowerCase();
|
|
31
31
|
return ("" + item.label).toLocaleLowerCase().indexOf(keyword) >= 0;
|
|
32
32
|
};
|
|
33
33
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { WithAsProps, RsRefForwardingComponent } from '../@types/common';
|
|
2
|
+
import Stack from '../Stack';
|
|
2
3
|
export interface ButtonToolbarProps extends WithAsProps {
|
|
3
4
|
/**
|
|
4
5
|
* The ARIA role describing the button toolbar. Generally the default
|
|
@@ -7,5 +8,5 @@ export interface ButtonToolbarProps extends WithAsProps {
|
|
|
7
8
|
*/
|
|
8
9
|
role?: string;
|
|
9
10
|
}
|
|
10
|
-
declare const ButtonToolbar: RsRefForwardingComponent<
|
|
11
|
+
declare const ButtonToolbar: RsRefForwardingComponent<typeof Stack, ButtonToolbarProps>;
|
|
11
12
|
export default ButtonToolbar;
|
|
@@ -3,22 +3,29 @@ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWith
|
|
|
3
3
|
import React from 'react';
|
|
4
4
|
import PropTypes from 'prop-types';
|
|
5
5
|
import { useClassNames } from '../utils';
|
|
6
|
+
import Stack from '../Stack';
|
|
6
7
|
var ButtonToolbar = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
7
8
|
var className = props.className,
|
|
8
9
|
_props$classPrefix = props.classPrefix,
|
|
9
10
|
classPrefix = _props$classPrefix === void 0 ? 'btn-toolbar' : _props$classPrefix,
|
|
10
11
|
_props$as = props.as,
|
|
11
|
-
Component = _props$as === void 0 ?
|
|
12
|
+
Component = _props$as === void 0 ? Stack : _props$as,
|
|
12
13
|
_props$role = props.role,
|
|
13
14
|
role = _props$role === void 0 ? 'toolbar' : _props$role,
|
|
14
15
|
rest = _objectWithoutPropertiesLoose(props, ["className", "classPrefix", "as", "role"]);
|
|
15
16
|
|
|
17
|
+
var stackProps = Component === Stack ? {
|
|
18
|
+
wrap: true,
|
|
19
|
+
spacing: 10,
|
|
20
|
+
childrenRenderMode: 'clone'
|
|
21
|
+
} : null;
|
|
22
|
+
|
|
16
23
|
var _useClassNames = useClassNames(classPrefix),
|
|
17
24
|
withClassPrefix = _useClassNames.withClassPrefix,
|
|
18
25
|
merge = _useClassNames.merge;
|
|
19
26
|
|
|
20
27
|
var classes = merge(className, withClassPrefix());
|
|
21
|
-
return /*#__PURE__*/React.createElement(Component, _extends({}, rest, {
|
|
28
|
+
return /*#__PURE__*/React.createElement(Component, _extends({}, stackProps, rest, {
|
|
22
29
|
role: role,
|
|
23
30
|
ref: ref,
|
|
24
31
|
className: classes
|
package/esm/Cascader/Cascader.js
CHANGED
|
@@ -432,7 +432,8 @@ var Cascader = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
432
432
|
classPrefix: 'picker-cascader-menu',
|
|
433
433
|
cascadeData: columnData,
|
|
434
434
|
cascadePaths: selectedPaths,
|
|
435
|
-
activeItemValue: value
|
|
435
|
+
activeItemValue: value // FIXME make onSelect generic
|
|
436
|
+
,
|
|
436
437
|
onSelect: handleSelect,
|
|
437
438
|
renderMenu: renderMenu,
|
|
438
439
|
renderMenuItem: renderMenuItem
|
package/esm/Cascader/utils.d.ts
CHANGED
|
@@ -1,18 +1,23 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export declare function getColumnsAndPaths<T extends ItemDataType>(data: T[], value: any, options: any): {
|
|
5
|
-
columns: ItemDataType<string | number>[][];
|
|
2
|
+
export declare function getColumnsAndPaths<T extends Record<string, unknown>>(data: T[], value: any, options: any): {
|
|
3
|
+
columns: T[][];
|
|
6
4
|
paths: T[];
|
|
7
5
|
};
|
|
8
|
-
|
|
6
|
+
declare type UsePathsParams<T> = {
|
|
7
|
+
data: T[];
|
|
8
|
+
valueKey: string;
|
|
9
|
+
childrenKey: string;
|
|
10
|
+
value: unknown;
|
|
11
|
+
};
|
|
12
|
+
export declare function usePaths<T extends Record<string, unknown>>(params: UsePathsParams<T>): {
|
|
9
13
|
enforceUpdate: (nextValue: any, isAttachChildren?: boolean) => void;
|
|
10
|
-
columnData:
|
|
11
|
-
valueToPaths:
|
|
12
|
-
selectedPaths:
|
|
13
|
-
setValueToPaths: import("react").Dispatch<import("react").SetStateAction<
|
|
14
|
-
setColumnData: import("react").Dispatch<import("react").SetStateAction<
|
|
15
|
-
setSelectedPaths: import("react").Dispatch<import("react").SetStateAction<
|
|
16
|
-
addColumn: (column:
|
|
14
|
+
columnData: T[][];
|
|
15
|
+
valueToPaths: T[];
|
|
16
|
+
selectedPaths: T[];
|
|
17
|
+
setValueToPaths: import("react").Dispatch<import("react").SetStateAction<T[]>>;
|
|
18
|
+
setColumnData: import("react").Dispatch<import("react").SetStateAction<T[][]>>;
|
|
19
|
+
setSelectedPaths: import("react").Dispatch<import("react").SetStateAction<T[]>>;
|
|
20
|
+
addColumn: (column: T[], index: number) => void;
|
|
17
21
|
romoveColumnByIndex: (index: number) => void;
|
|
18
22
|
};
|
|
23
|
+
export {};
|
package/esm/Cascader/utils.js
CHANGED
|
@@ -72,11 +72,11 @@ export function getColumnsAndPaths(data, value, options) {
|
|
|
72
72
|
paths: paths
|
|
73
73
|
};
|
|
74
74
|
}
|
|
75
|
-
export function usePaths(
|
|
76
|
-
var data =
|
|
77
|
-
valueKey =
|
|
78
|
-
childrenKey =
|
|
79
|
-
value =
|
|
75
|
+
export function usePaths(params) {
|
|
76
|
+
var data = params.data,
|
|
77
|
+
valueKey = params.valueKey,
|
|
78
|
+
childrenKey = params.childrenKey,
|
|
79
|
+
value = params.value;
|
|
80
80
|
|
|
81
81
|
var _useMemo = useMemo(function () {
|
|
82
82
|
return getColumnsAndPaths(data, value, {
|
package/esm/Menu/Menu.js
CHANGED
|
@@ -9,25 +9,28 @@ interface ItemKeys {
|
|
|
9
9
|
labelKey: string;
|
|
10
10
|
childrenKey: string;
|
|
11
11
|
}
|
|
12
|
+
declare type MayHasParent<T extends Record<string, unknown>> = T & {
|
|
13
|
+
parent?: MayHasParent<T>;
|
|
14
|
+
};
|
|
12
15
|
/**
|
|
13
16
|
* Get all parents of a node
|
|
14
17
|
* @param node
|
|
15
18
|
*/
|
|
16
|
-
export declare const getParents: (node:
|
|
19
|
+
export declare const getParents: <T extends Record<string, unknown>>(node: MayHasParent<T>) => MayHasParent<T>[];
|
|
17
20
|
/**
|
|
18
21
|
* Check if any child nodes are selected.
|
|
19
22
|
* @param node
|
|
20
23
|
* @param value
|
|
21
24
|
* @param itemKeys
|
|
22
25
|
*/
|
|
23
|
-
export declare const isSomeChildChecked: (node:
|
|
26
|
+
export declare const isSomeChildChecked: <T extends Record<string, unknown>>(node: T, value: ValueType, itemKeys: Omit<ItemKeys, 'labelKey'>) => any;
|
|
24
27
|
/**
|
|
25
28
|
* Check if the parent is selected.
|
|
26
29
|
* @param node
|
|
27
30
|
* @param value
|
|
28
31
|
* @param itemKeys
|
|
29
32
|
*/
|
|
30
|
-
export declare const isSomeParentChecked: (node:
|
|
33
|
+
export declare const isSomeParentChecked: <T extends Record<string, unknown>>(node: MayHasParent<T>, value: ValueType, itemKeys: Pick<ItemKeys, 'valueKey'>) => any;
|
|
31
34
|
export declare const getOtherItemValuesByUnselectChild: <T>(itemNode: ItemType, value: any, itemKeys: Omit<ItemKeys, 'labelKey'>) => T[];
|
|
32
35
|
/**
|
|
33
36
|
* Remove the values of all children.
|
|
@@ -37,20 +40,20 @@ export declare const removeAllChildrenValue: <T>(value: T[], item: ItemType, ite
|
|
|
37
40
|
* A hook to flatten tree structure data
|
|
38
41
|
* @param data
|
|
39
42
|
*/
|
|
40
|
-
export declare function useFlattenData(data:
|
|
41
|
-
addFlattenData: (children:
|
|
42
|
-
flattenData:
|
|
43
|
+
export declare function useFlattenData<T>(data: T[], itemKeys: ItemKeys): {
|
|
44
|
+
addFlattenData: (children: T[], parent: T) => void;
|
|
45
|
+
flattenData: T[];
|
|
43
46
|
};
|
|
44
47
|
/**
|
|
45
48
|
* A hook for column data
|
|
46
49
|
* @param flattenData
|
|
47
50
|
*/
|
|
48
|
-
export declare function useColumnData(flattenData:
|
|
49
|
-
columnData:
|
|
50
|
-
addColumn: (column:
|
|
51
|
+
export declare function useColumnData<T extends MayHasParent<Record<string, unknown>>>(flattenData: T[]): {
|
|
52
|
+
columnData: T[][];
|
|
53
|
+
addColumn: (column: T[], index: number) => void;
|
|
51
54
|
romoveColumnByIndex: (index: number) => void;
|
|
52
|
-
setColumnData: import("react").Dispatch<import("react").SetStateAction<
|
|
53
|
-
enforceUpdateColumnData: (nextData:
|
|
55
|
+
setColumnData: import("react").Dispatch<import("react").SetStateAction<T[][]>>;
|
|
56
|
+
enforceUpdateColumnData: (nextData: T[]) => void;
|
|
54
57
|
};
|
|
55
58
|
/**
|
|
56
59
|
* A hook that converts the value into a cascading value
|
|
@@ -17,6 +17,8 @@ export interface NavDropdownMenuProps<T = any> extends StandardProps {
|
|
|
17
17
|
* @default 'end'
|
|
18
18
|
*/
|
|
19
19
|
openDirection?: 'start' | 'end';
|
|
20
|
+
/** No caret variation */
|
|
21
|
+
noCaret?: boolean;
|
|
20
22
|
/**
|
|
21
23
|
* Only used for setting the default expand state when it's a submenu.
|
|
22
24
|
*/
|
|
@@ -34,7 +34,8 @@ var NavDropdownMenu = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
34
34
|
children = props.children,
|
|
35
35
|
_props$openDirection = props.openDirection,
|
|
36
36
|
openDirection = _props$openDirection === void 0 ? 'end' : _props$openDirection,
|
|
37
|
-
|
|
37
|
+
noCaret = props.noCaret,
|
|
38
|
+
rest = _objectWithoutPropertiesLoose(props, ["onToggle", "eventKey", "title", "classPrefix", "children", "openDirection", "noCaret"]);
|
|
38
39
|
|
|
39
40
|
var _useCustom = useCustom('DropdownMenu'),
|
|
40
41
|
rtl = _useCustom.rtl;
|
|
@@ -91,7 +92,7 @@ var NavDropdownMenu = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
91
92
|
"data-event-key-type": typeof eventKey
|
|
92
93
|
}, menuitem, omit(menuButtonProps, ['role'])), icon && /*#__PURE__*/React.cloneElement(icon, {
|
|
93
94
|
className: prefix('menu-icon')
|
|
94
|
-
}), title, /*#__PURE__*/React.createElement(Icon, {
|
|
95
|
+
}), title, !noCaret && /*#__PURE__*/React.createElement(Icon, {
|
|
95
96
|
className: prefix(_templateObject2 || (_templateObject2 = _taggedTemplateLiteralLoose(["toggle-icon"])))
|
|
96
97
|
}));
|
|
97
98
|
});
|
|
@@ -133,6 +134,7 @@ NavDropdownMenu.propTypes = {
|
|
|
133
134
|
classPrefix: PropTypes.string,
|
|
134
135
|
pullLeft: deprecatePropType(PropTypes.bool, 'Use openDirection="start" instead.'),
|
|
135
136
|
openDirection: PropTypes.oneOf(['start', 'end']),
|
|
137
|
+
noCaret: PropTypes.bool,
|
|
136
138
|
title: PropTypes.node,
|
|
137
139
|
open: PropTypes.bool,
|
|
138
140
|
eventKey: PropTypes.any,
|
package/esm/Picker/utils.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { OverlayTriggerHandle } from './PickerToggleTrigger';
|
|
3
|
-
import { TypeAttributes
|
|
3
|
+
import { TypeAttributes } from '../@types/common';
|
|
4
4
|
import type { ListHandle } from '../Windowing';
|
|
5
5
|
export interface NodeKeys {
|
|
6
6
|
valueKey: string;
|
|
@@ -86,24 +86,25 @@ export interface ToggleKeyDownEventProps {
|
|
|
86
86
|
* @param props
|
|
87
87
|
*/
|
|
88
88
|
export declare const useToggleKeyDownEvent: (props: ToggleKeyDownEventProps) => (event: React.KeyboardEvent) => void;
|
|
89
|
-
export interface SearchProps {
|
|
89
|
+
export interface SearchProps<TItem extends Record<string, unknown>, TLabel> {
|
|
90
90
|
labelKey: string;
|
|
91
|
-
data:
|
|
92
|
-
searchBy?: (keyword:
|
|
93
|
-
callback?: (keyword: string, data:
|
|
91
|
+
data: TItem[];
|
|
92
|
+
searchBy?: (keyword: string, label: TLabel, item: TItem) => boolean;
|
|
93
|
+
callback?: (keyword: string, data: TItem[], event: React.SyntheticEvent) => void;
|
|
94
94
|
}
|
|
95
|
+
declare type UseSearchResult<TItem extends Record<string, unknown>> = {
|
|
96
|
+
searchKeyword: string;
|
|
97
|
+
filteredData: TItem[];
|
|
98
|
+
updateFilteredData: (nextData: TItem[]) => void;
|
|
99
|
+
setSearchKeyword: (value: string) => void;
|
|
100
|
+
checkShouldDisplay: (item: TItem, keyword?: string) => boolean;
|
|
101
|
+
handleSearch: (searchKeyword: string, event: React.SyntheticEvent) => void;
|
|
102
|
+
};
|
|
95
103
|
/**
|
|
96
104
|
* A hook that handles search filter options
|
|
97
105
|
* @param props
|
|
98
106
|
*/
|
|
99
|
-
export declare function useSearch(props: SearchProps):
|
|
100
|
-
searchKeyword: string;
|
|
101
|
-
filteredData: import("../CheckTreePicker/utils").TreeNodeType[];
|
|
102
|
-
updateFilteredData: (nextData: ItemDataType[]) => void;
|
|
103
|
-
setSearchKeyword: React.Dispatch<React.SetStateAction<string>>;
|
|
104
|
-
checkShouldDisplay: (item: ItemDataType, keyword?: string) => boolean;
|
|
105
|
-
handleSearch: (searchKeyword: string, event: React.SyntheticEvent) => void;
|
|
106
|
-
};
|
|
107
|
+
export declare function useSearch<TItem extends Record<string, unknown>, TLabel>(props: SearchProps<TItem, TLabel>): UseSearchResult<TItem>;
|
|
107
108
|
export interface PickerDependentParameters {
|
|
108
109
|
triggerRef?: React.RefObject<OverlayTriggerHandle>;
|
|
109
110
|
rootRef?: React.RefObject<HTMLElement>;
|
|
@@ -116,3 +117,4 @@ export interface PickerDependentParameters {
|
|
|
116
117
|
* A hook of the exposed method of Picker
|
|
117
118
|
*/
|
|
118
119
|
export declare function usePublicMethods(ref: any, parmas: PickerDependentParameters): void;
|
|
120
|
+
export {};
|
package/esm/Picker/utils.js
CHANGED
|
@@ -8,6 +8,7 @@ import omit from 'lodash/omit';
|
|
|
8
8
|
import find from 'lodash/find';
|
|
9
9
|
import { findNodeOfTree, filterNodesOfTree } from '../utils/treeUtils';
|
|
10
10
|
import { KEY_VALUES, useClassNames, shallowEqual, reactToString, placementPolyfill } from '../utils';
|
|
11
|
+
import { getHeight } from 'dom-lib';
|
|
11
12
|
var defaultNodeKeys = {
|
|
12
13
|
valueKey: 'value',
|
|
13
14
|
childrenKey: 'children'
|
|
@@ -135,11 +136,51 @@ export function onMenuKeyDown(event, events) {
|
|
|
135
136
|
}
|
|
136
137
|
}
|
|
137
138
|
|
|
139
|
+
/**
|
|
140
|
+
* Checks if the element has a vertical scrollbar.
|
|
141
|
+
*/
|
|
142
|
+
function hasVerticalScroll(element) {
|
|
143
|
+
var scrollHeight = element.scrollHeight,
|
|
144
|
+
clientHeight = element.clientHeight;
|
|
145
|
+
return scrollHeight > clientHeight;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Checks if the element is within the visible area of the container
|
|
149
|
+
*/
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
function isVisible(element, container, direction) {
|
|
153
|
+
if (!hasVerticalScroll(container)) {
|
|
154
|
+
return true;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
var _element$getBoundingC = element.getBoundingClientRect(),
|
|
158
|
+
top = _element$getBoundingC.top,
|
|
159
|
+
bottom = _element$getBoundingC.bottom,
|
|
160
|
+
height = _element$getBoundingC.height;
|
|
161
|
+
|
|
162
|
+
var _container$getBoundin = container.getBoundingClientRect(),
|
|
163
|
+
containerTop = _container$getBoundin.top,
|
|
164
|
+
containerBottom = _container$getBoundin.bottom;
|
|
165
|
+
|
|
166
|
+
if (direction === 'top') {
|
|
167
|
+
return top + height > containerTop;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return bottom - height < containerBottom;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function scrollTo(container, direction, step) {
|
|
174
|
+
var scrollTop = container.scrollTop;
|
|
175
|
+
container.scrollTop = direction === 'top' ? scrollTop - step : scrollTop + step;
|
|
176
|
+
}
|
|
138
177
|
/**
|
|
139
178
|
* A hook that manages the focus state of the option.
|
|
140
179
|
* @param defaultFocusItemValue
|
|
141
180
|
* @param props
|
|
142
181
|
*/
|
|
182
|
+
|
|
183
|
+
|
|
143
184
|
export var useFocusItemValue = function useFocusItemValue(defaultFocusItemValue, props) {
|
|
144
185
|
var _props$valueKey = props.valueKey,
|
|
145
186
|
valueKey = _props$valueKey === void 0 ? 'value' : _props$valueKey,
|
|
@@ -163,11 +204,23 @@ export var useFocusItemValue = function useFocusItemValue(defaultFocusItemValue,
|
|
|
163
204
|
var _useState3 = useState([]),
|
|
164
205
|
keys = _useState3[0],
|
|
165
206
|
setKeys = _useState3[1];
|
|
207
|
+
|
|
208
|
+
var getScrollContainer = useCallback(function () {
|
|
209
|
+
var menu = isFunction(target) ? target() : target; // For Cascader and MutiCascader
|
|
210
|
+
|
|
211
|
+
var subMenu = menu === null || menu === void 0 ? void 0 : menu.querySelector("[data-layer=\"" + layer + "\"]");
|
|
212
|
+
|
|
213
|
+
if (subMenu) {
|
|
214
|
+
return subMenu;
|
|
215
|
+
} // For SelectPicker、CheckPicker、Autocomplete、InputPicker、TagPicker
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
return menu === null || menu === void 0 ? void 0 : menu.querySelector('[role="listbox"]');
|
|
219
|
+
}, [layer, target]);
|
|
166
220
|
/**
|
|
167
221
|
* Get the elements visible in all options.
|
|
168
222
|
*/
|
|
169
223
|
|
|
170
|
-
|
|
171
224
|
var getFocusableMenuItems = useCallback(function () {
|
|
172
225
|
if (!target) {
|
|
173
226
|
return [];
|
|
@@ -224,28 +277,50 @@ export var useFocusItemValue = function useFocusItemValue(defaultFocusItemValue,
|
|
|
224
277
|
|
|
225
278
|
callback(items, -1);
|
|
226
279
|
}, [focusItemValue, getFocusableMenuItems, valueKey]);
|
|
280
|
+
var scrollListItem = useCallback(function (direction, itemValue, willOverflow) {
|
|
281
|
+
var container = getScrollContainer();
|
|
282
|
+
var item = container === null || container === void 0 ? void 0 : container.querySelector("[data-key=\"" + itemValue + "\"]");
|
|
283
|
+
|
|
284
|
+
if (willOverflow && container) {
|
|
285
|
+
var scrollHeight = container.scrollHeight,
|
|
286
|
+
clientHeight = container.clientHeight;
|
|
287
|
+
container.scrollTop = direction === 'top' ? scrollHeight - clientHeight : 0;
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
if (item && container) {
|
|
292
|
+
if (!isVisible(item, container, direction)) {
|
|
293
|
+
var height = getHeight(item);
|
|
294
|
+
scrollTo(container, direction, height);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}, [getScrollContainer]);
|
|
227
298
|
var focusNextMenuItem = useCallback(function (event) {
|
|
228
299
|
findFocusItemIndex(function (items, index) {
|
|
229
|
-
var
|
|
300
|
+
var willOverflow = index + 2 > items.length;
|
|
301
|
+
var nextIndex = willOverflow ? 0 : index + 1;
|
|
230
302
|
var focusItem = items[nextIndex];
|
|
231
303
|
|
|
232
304
|
if (!isUndefined(focusItem)) {
|
|
233
305
|
setFocusItemValue(focusItem[valueKey]);
|
|
234
306
|
callback === null || callback === void 0 ? void 0 : callback(focusItem[valueKey], event);
|
|
307
|
+
scrollListItem('bottom', focusItem[valueKey], willOverflow);
|
|
235
308
|
}
|
|
236
309
|
});
|
|
237
|
-
}, [callback, findFocusItemIndex, valueKey]);
|
|
310
|
+
}, [callback, findFocusItemIndex, scrollListItem, valueKey]);
|
|
238
311
|
var focusPrevMenuItem = useCallback(function (event) {
|
|
239
312
|
findFocusItemIndex(function (items, index) {
|
|
240
|
-
var
|
|
313
|
+
var willOverflow = index === 0;
|
|
314
|
+
var nextIndex = willOverflow ? items.length - 1 : index - 1;
|
|
241
315
|
var focusItem = items[nextIndex];
|
|
242
316
|
|
|
243
317
|
if (!isUndefined(focusItem)) {
|
|
244
318
|
setFocusItemValue(focusItem[valueKey]);
|
|
245
319
|
callback === null || callback === void 0 ? void 0 : callback(focusItem[valueKey], event);
|
|
320
|
+
scrollListItem('top', focusItem[valueKey], willOverflow);
|
|
246
321
|
}
|
|
247
322
|
});
|
|
248
|
-
}, [callback, findFocusItemIndex, valueKey]);
|
|
323
|
+
}, [callback, findFocusItemIndex, scrollListItem, valueKey]);
|
|
249
324
|
var getSubMenuKeys = useCallback(function (nextLayer) {
|
|
250
325
|
var menu = isFunction(target) ? target() : target;
|
|
251
326
|
var subMenu = menu === null || menu === void 0 ? void 0 : menu.querySelector("[data-layer=\"" + nextLayer + "\"]");
|
package/esm/Stack/Stack.d.ts
CHANGED
|
@@ -22,6 +22,10 @@ export interface StackProps extends WithAsProps {
|
|
|
22
22
|
* Define whether the children in the stack are forced onto one line or can wrap onto multiple lines
|
|
23
23
|
*/
|
|
24
24
|
wrap?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* The render mode of the children.
|
|
27
|
+
*/
|
|
28
|
+
childrenRenderMode?: 'clone' | 'wrap';
|
|
25
29
|
}
|
|
26
30
|
export interface StackComponent extends RsRefForwardingComponent<'div', StackProps> {
|
|
27
31
|
Item: typeof StackItem;
|
package/esm/Stack/Stack.js
CHANGED
|
@@ -13,6 +13,8 @@ var Stack = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
13
13
|
alignItems = _props$alignItems === void 0 ? 'center' : _props$alignItems,
|
|
14
14
|
_props$classPrefix = props.classPrefix,
|
|
15
15
|
classPrefix = _props$classPrefix === void 0 ? 'stack' : _props$classPrefix,
|
|
16
|
+
_props$childrenRender = props.childrenRenderMode,
|
|
17
|
+
childrenRenderMode = _props$childrenRender === void 0 ? 'wrap' : _props$childrenRender,
|
|
16
18
|
className = props.className,
|
|
17
19
|
children = props.children,
|
|
18
20
|
direction = props.direction,
|
|
@@ -21,7 +23,7 @@ var Stack = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
21
23
|
divider = props.divider,
|
|
22
24
|
style = props.style,
|
|
23
25
|
wrap = props.wrap,
|
|
24
|
-
rest = _objectWithoutPropertiesLoose(props, ["as", "alignItems", "classPrefix", "className", "children", "direction", "justifyContent", "spacing", "divider", "style", "wrap"]);
|
|
26
|
+
rest = _objectWithoutPropertiesLoose(props, ["as", "alignItems", "classPrefix", "childrenRenderMode", "className", "children", "direction", "justifyContent", "spacing", "divider", "style", "wrap"]);
|
|
25
27
|
|
|
26
28
|
var _useCustom = useCustom('Stack'),
|
|
27
29
|
rtl = _useCustom.rtl;
|
|
@@ -32,16 +34,16 @@ var Stack = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
32
34
|
prefix = _useClassNames.prefix;
|
|
33
35
|
|
|
34
36
|
var classes = merge(className, withClassPrefix());
|
|
35
|
-
var
|
|
36
|
-
var
|
|
37
|
-
var itemStyles = (_itemStyles = {}, _itemStyles[rtl ? 'marginLeft' : 'marginRight'] =
|
|
37
|
+
var isSupportGap = isSupportFlexGap();
|
|
38
|
+
var flexGap = Array.isArray(spacing) ? spacing : [spacing, spacing];
|
|
39
|
+
var itemStyles = (_itemStyles = {}, _itemStyles[rtl ? 'marginLeft' : 'marginRight'] = flexGap[0], _itemStyles.marginBottom = flexGap[1], _itemStyles);
|
|
38
40
|
|
|
39
41
|
var styles = _extends({
|
|
40
42
|
alignItems: alignItems,
|
|
41
43
|
justifyContent: justifyContent,
|
|
42
44
|
flexDirection: direction,
|
|
43
45
|
flexWrap: wrap ? 'wrap' : undefined,
|
|
44
|
-
gap:
|
|
46
|
+
gap: isSupportGap ? spacing : undefined
|
|
45
47
|
}, style);
|
|
46
48
|
/*
|
|
47
49
|
* toArray remove undefined, null and boolean
|
|
@@ -55,13 +57,13 @@ var Stack = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
55
57
|
className: classes,
|
|
56
58
|
style: styles
|
|
57
59
|
}), React.Children.map(filterChildren, function (child, index) {
|
|
58
|
-
var childNode = child.type !== StackItem ? /*#__PURE__*/React.createElement(StackItem, {
|
|
60
|
+
var childNode = childrenRenderMode === 'wrap' && child.type !== StackItem ? /*#__PURE__*/React.createElement(StackItem, {
|
|
59
61
|
key: index,
|
|
60
62
|
className: prefix('item'),
|
|
61
|
-
style: !
|
|
63
|
+
style: !isSupportGap ? itemStyles : undefined
|
|
62
64
|
}, child) : /*#__PURE__*/React.cloneElement(child, {
|
|
63
65
|
className: merge(prefix('item'), child.props.className),
|
|
64
|
-
style: !
|
|
66
|
+
style: !isSupportGap ? _extends({}, itemStyles, child.props.style) : child.props.style
|
|
65
67
|
});
|
|
66
68
|
return [childNode, index < count - 1 ? divider : null];
|
|
67
69
|
}));
|
package/esm/utils/treeUtils.d.ts
CHANGED
|
@@ -2,7 +2,6 @@ import React from 'react';
|
|
|
2
2
|
import { TreeNodeType, TreeNodesType } from '../CheckTreePicker/utils';
|
|
3
3
|
import { TREE_NODE_DROP_POSITION } from '../utils';
|
|
4
4
|
import { CheckTreePickerProps } from '../CheckTreePicker/CheckTreePicker';
|
|
5
|
-
import { ItemDataType } from '../@types/common';
|
|
6
5
|
import { TreePickerProps } from '../TreePicker/TreePicker';
|
|
7
6
|
import { ListHandle } from '../Windowing';
|
|
8
7
|
declare type PartialTreeProps = Partial<TreePickerProps | CheckTreePickerProps>;
|
|
@@ -11,14 +10,14 @@ declare type PartialTreeProps = Partial<TreePickerProps | CheckTreePickerProps>;
|
|
|
11
10
|
* @param {*} expandItemValues
|
|
12
11
|
* @param {*} parentKeys
|
|
13
12
|
*/
|
|
14
|
-
export declare function shouldShowNodeByParentExpanded(expandItemValues?:
|
|
13
|
+
export declare function shouldShowNodeByParentExpanded<T>(expandItemValues?: T[], parentKeys?: T[]): boolean;
|
|
15
14
|
/**
|
|
16
15
|
* flatten tree structure to array
|
|
17
16
|
* @param {*} tree
|
|
18
17
|
* @param {*} childrenKey
|
|
19
18
|
* @param {*} executor
|
|
20
19
|
*/
|
|
21
|
-
export declare function flattenTree(tree:
|
|
20
|
+
export declare function flattenTree<TItem>(tree: TItem[], childrenKey?: string, executor?: (node: any, index: number) => any): TItem[];
|
|
22
21
|
/**
|
|
23
22
|
* get all ancestor nodes of given node
|
|
24
23
|
* @param {*} node
|
|
@@ -30,7 +29,7 @@ export declare function getNodeParents(node: any, parentKey?: string, valueKey?:
|
|
|
30
29
|
* @param node
|
|
31
30
|
* @param valueKey
|
|
32
31
|
*/
|
|
33
|
-
export declare function getNodeParentKeys(nodes: TreeNodesType, node: TreeNodeType, valueKey: string):
|
|
32
|
+
export declare function getNodeParentKeys<T>(nodes: TreeNodesType, node: TreeNodeType, valueKey: string): T[];
|
|
34
33
|
export declare function hasVisibleChildren(node: TreeNodeType, childrenKey: string): any;
|
|
35
34
|
/**
|
|
36
35
|
* shallow equal array
|
|
@@ -38,7 +37,7 @@ export declare function hasVisibleChildren(node: TreeNodeType, childrenKey: stri
|
|
|
38
37
|
* @param b
|
|
39
38
|
*/
|
|
40
39
|
export declare function compareArray(a: any[], b: any[]): boolean;
|
|
41
|
-
export declare function getDefaultExpandItemValues(data:
|
|
40
|
+
export declare function getDefaultExpandItemValues<TItem>(data: TItem[], props: Required<Pick<TreePickerProps, 'defaultExpandAll' | 'valueKey' | 'childrenKey' | 'defaultExpandItemValues'>>): any[];
|
|
42
41
|
/**
|
|
43
42
|
* 获取 expandItemValues 的 value
|
|
44
43
|
* @param props
|
|
@@ -61,7 +60,10 @@ export declare function createUpdateTreeDataFunction(params: any, { valueKey, ch
|
|
|
61
60
|
childrenKey: any;
|
|
62
61
|
}): (tree: any[]) => any[];
|
|
63
62
|
export declare function findNodeOfTree(data: any, check: any): any;
|
|
64
|
-
|
|
63
|
+
declare type HasChildren<T extends Record<string, unknown>> = T & {
|
|
64
|
+
children?: readonly HasChildren<T>[];
|
|
65
|
+
};
|
|
66
|
+
export declare function filterNodesOfTree<TItem extends HasChildren<Record<string, unknown>>>(data: readonly TItem[], check: (item: TItem) => boolean): TItem[];
|
|
65
67
|
/**
|
|
66
68
|
* get all focusable items
|
|
67
69
|
* exclude not visible and disabled node
|
|
@@ -70,7 +72,7 @@ export declare function filterNodesOfTree(data: any, check: any): TreeNodeType[]
|
|
|
70
72
|
* @param isSearching - component is in Searching
|
|
71
73
|
* @returns
|
|
72
74
|
*/
|
|
73
|
-
export declare const getFocusableItems: (filteredData:
|
|
75
|
+
export declare const getFocusableItems: <TItem extends TreeNodeType>(filteredData: TItem[], props: Required<Pick<PartialTreeProps, 'disabledItemValues' | 'valueKey' | 'childrenKey' | 'expandItemValues'>>, isSearching?: boolean) => TItem[];
|
|
74
76
|
/**
|
|
75
77
|
* return all focusable Item and active Element index
|
|
76
78
|
* @param focusItemValue
|
|
@@ -150,7 +152,13 @@ export { getTreeActiveNode };
|
|
|
150
152
|
* toggle tree node
|
|
151
153
|
* @param param0
|
|
152
154
|
*/
|
|
153
|
-
export declare function toggleExpand({ node, isExpand, expandItemValues, valueKey }:
|
|
155
|
+
export declare function toggleExpand<T>({ node, isExpand, expandItemValues, valueKey }: ToggleExpandOptions<T>): T[];
|
|
156
|
+
declare type ToggleExpandOptions<T> = {
|
|
157
|
+
node: Record<string, unknown>;
|
|
158
|
+
isExpand: boolean;
|
|
159
|
+
expandItemValues: T[];
|
|
160
|
+
valueKey: string;
|
|
161
|
+
};
|
|
154
162
|
export declare function getTreeNodeTitle(label: any): string | undefined;
|
|
155
163
|
/**
|
|
156
164
|
* get all children from flattenNodes object by given parent node
|
|
@@ -158,12 +166,12 @@ export declare function getTreeNodeTitle(label: any): string | undefined;
|
|
|
158
166
|
* @param parent
|
|
159
167
|
*/
|
|
160
168
|
export declare function getChildrenByFlattenNodes(nodes: TreeNodesType, parent: TreeNodeType): TreeNodeType[];
|
|
161
|
-
export declare function useTreeDrag(): {
|
|
162
|
-
dragNode:
|
|
169
|
+
export declare function useTreeDrag<T>(): {
|
|
170
|
+
dragNode: T | null;
|
|
163
171
|
dragOverNodeKey: null;
|
|
164
172
|
dragNodeKeys: (string | number)[];
|
|
165
173
|
dropNodePosition: TREE_NODE_DROP_POSITION | null;
|
|
166
|
-
setDragNode: (node:
|
|
174
|
+
setDragNode: (node: T | null) => void;
|
|
167
175
|
setDragOverNodeKey: React.Dispatch<React.SetStateAction<null>>;
|
|
168
176
|
setDragNodeKeys: React.Dispatch<React.SetStateAction<(string | number)[]>>;
|
|
169
177
|
setDropNodePosition: React.Dispatch<React.SetStateAction<TREE_NODE_DROP_POSITION | null>>;
|
|
@@ -193,7 +201,7 @@ export declare function useFlattenTreeData({ data, labelKey, valueKey, childrenK
|
|
|
193
201
|
flattenTreeData: (treeData: TreeNodeType[], parent?: TreeNodeType, layer?: any) => never[] | undefined;
|
|
194
202
|
serializeListOnlyParent: (nodes: TreeNodesType, key: string) => (string | number)[];
|
|
195
203
|
unSerializeList: ({ nodes, key, value, cascade, uncheckableItemValues }: UnSerializeListProps) => void;
|
|
196
|
-
formatVirtualizedTreeData: (nodes: TreeNodesType, data: any[], expandItemValues:
|
|
204
|
+
formatVirtualizedTreeData: (nodes: TreeNodesType, data: any[], expandItemValues: unknown[], options: {
|
|
197
205
|
cascade?: boolean;
|
|
198
206
|
searchKeyword?: string;
|
|
199
207
|
}) => TreeNodeType[];
|
|
@@ -205,28 +213,28 @@ export declare function useTreeNodeRefs(): {
|
|
|
205
213
|
treeNodesRefs: {};
|
|
206
214
|
saveTreeNodeRef: (ref: React.Ref<any>, refKey?: string) => void;
|
|
207
215
|
};
|
|
208
|
-
interface TreeSearchProps {
|
|
216
|
+
interface TreeSearchProps<T> {
|
|
209
217
|
labelKey: string;
|
|
210
218
|
childrenKey: string;
|
|
211
219
|
searchKeyword?: string;
|
|
212
|
-
data:
|
|
220
|
+
data: T[];
|
|
213
221
|
searchBy?: (keyword: any, label: any, item: any) => boolean;
|
|
214
|
-
callback?: (keyword: string, data:
|
|
222
|
+
callback?: (keyword: string, data: T[], event: React.SyntheticEvent) => void;
|
|
215
223
|
}
|
|
216
224
|
/**
|
|
217
225
|
* A hook that handles tree search filter options
|
|
218
226
|
* @param props
|
|
219
227
|
*/
|
|
220
|
-
export declare function useTreeSearch<T
|
|
228
|
+
export declare function useTreeSearch<T>(props: TreeSearchProps<T>): {
|
|
221
229
|
searchKeywordState: string;
|
|
222
|
-
filteredData:
|
|
223
|
-
setFilteredData: (data:
|
|
230
|
+
filteredData: T[];
|
|
231
|
+
setFilteredData: (data: T[], searchKeyword: string) => void;
|
|
224
232
|
setSearchKeyword: React.Dispatch<React.SetStateAction<string>>;
|
|
225
|
-
handleSearch: (searchKeyword: string, event: React.ChangeEvent
|
|
233
|
+
handleSearch: (searchKeyword: string, event: React.ChangeEvent) => void;
|
|
226
234
|
};
|
|
227
|
-
export declare function useGetTreeNodeChildren(treeData:
|
|
228
|
-
data:
|
|
229
|
-
setData: React.Dispatch<React.SetStateAction<
|
|
235
|
+
export declare function useGetTreeNodeChildren<T extends Record<string, unknown>>(treeData: T[], valueKey: string, childrenKey: string): {
|
|
236
|
+
data: T[];
|
|
237
|
+
setData: React.Dispatch<React.SetStateAction<T[]>>;
|
|
230
238
|
loadingNodeValues: never[];
|
|
231
239
|
loadChildren: (node: any, getChildren: any) => void;
|
|
232
240
|
};
|