rsuite 5.31.1 → 5.33.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/CHANGELOG.md +17 -0
- package/cjs/Calendar/CalendarContainer.d.ts +2 -0
- package/cjs/Calendar/CalendarContainer.js +4 -1
- package/cjs/Calendar/MonthDropdown.js +1 -1
- package/cjs/Cascader/Cascader.d.ts +2 -2
- package/cjs/Cascader/Cascader.js +83 -71
- package/cjs/Cascader/DropdownMenu.d.ts +6 -2
- package/cjs/Cascader/DropdownMenu.js +8 -4
- package/cjs/Cascader/utils.d.ts +43 -17
- package/cjs/Cascader/utils.js +60 -145
- package/cjs/CheckTreePicker/CheckTreePicker.js +16 -3
- package/cjs/DatePicker/DatePicker.d.ts +3 -1
- package/cjs/DatePicker/DatePicker.js +4 -1
- package/cjs/DateRangePicker/Calendar.d.ts +1 -0
- package/cjs/DateRangePicker/Calendar.js +4 -1
- package/cjs/DateRangePicker/DateRangePicker.d.ts +3 -1
- package/cjs/DateRangePicker/DateRangePicker.js +4 -1
- package/cjs/MultiCascader/DropdownMenu.d.ts +2 -2
- package/cjs/MultiCascader/MultiCascader.d.ts +1 -1
- package/cjs/MultiCascader/MultiCascader.js +12 -7
- package/cjs/MultiCascader/utils.d.ts +2 -2
- package/cjs/MultiCascader/utils.js +3 -3
- package/cjs/Picker/utils.d.ts +4 -3
- package/cjs/Picker/utils.js +8 -4
- package/cjs/Tree/Tree.d.ts +2 -0
- package/cjs/TreePicker/TreePicker.js +16 -3
- package/cjs/utils/getDataGroupBy.js +1 -1
- package/cjs/utils/treeUtils.d.ts +23 -1
- package/cjs/utils/treeUtils.js +109 -6
- package/cjs/utils/useMap.d.ts +6 -0
- package/cjs/utils/useMap.js +35 -0
- package/dist/rsuite.js +189 -17
- package/dist/rsuite.js.map +1 -1
- package/dist/rsuite.min.js +1 -1
- package/dist/rsuite.min.js.map +1 -1
- package/esm/Calendar/CalendarContainer.d.ts +2 -0
- package/esm/Calendar/CalendarContainer.js +4 -1
- package/esm/Calendar/MonthDropdown.js +1 -1
- package/esm/Cascader/Cascader.d.ts +2 -2
- package/esm/Cascader/Cascader.js +84 -74
- package/esm/Cascader/DropdownMenu.d.ts +6 -2
- package/esm/Cascader/DropdownMenu.js +8 -4
- package/esm/Cascader/utils.d.ts +43 -17
- package/esm/Cascader/utils.js +64 -142
- package/esm/CheckTreePicker/CheckTreePicker.js +17 -4
- package/esm/DatePicker/DatePicker.d.ts +3 -1
- package/esm/DatePicker/DatePicker.js +4 -1
- package/esm/DateRangePicker/Calendar.d.ts +1 -0
- package/esm/DateRangePicker/Calendar.js +4 -1
- package/esm/DateRangePicker/DateRangePicker.d.ts +3 -1
- package/esm/DateRangePicker/DateRangePicker.js +4 -1
- package/esm/MultiCascader/DropdownMenu.d.ts +2 -2
- package/esm/MultiCascader/MultiCascader.d.ts +1 -1
- package/esm/MultiCascader/MultiCascader.js +12 -7
- package/esm/MultiCascader/utils.d.ts +2 -2
- package/esm/MultiCascader/utils.js +4 -4
- package/esm/Picker/utils.d.ts +4 -3
- package/esm/Picker/utils.js +8 -4
- package/esm/Tree/Tree.d.ts +2 -0
- package/esm/TreePicker/TreePicker.js +18 -5
- package/esm/utils/getDataGroupBy.js +2 -2
- package/esm/utils/treeUtils.d.ts +23 -1
- package/esm/utils/treeUtils.js +103 -6
- package/esm/utils/useMap.d.ts +6 -0
- package/esm/utils/useMap.js +29 -0
- package/package.json +2 -1
package/esm/Cascader/utils.js
CHANGED
|
@@ -1,161 +1,83 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
} else if (children) {
|
|
25
|
-
var node = findNode(children);
|
|
26
|
-
|
|
27
|
-
if (node) {
|
|
28
|
-
columns.push(children.map(function (item) {
|
|
29
|
-
return attachParent(item, items[i]);
|
|
30
|
-
}));
|
|
31
|
-
paths.push(node.active);
|
|
32
|
-
return {
|
|
33
|
-
v: {
|
|
34
|
-
items: items,
|
|
35
|
-
active: items[i]
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
}
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { getPathTowardsItem } from '../utils/treeUtils';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Calculate columns to be displayed:
|
|
6
|
+
*
|
|
7
|
+
* - Every ancestor level of activeItem should be displayed
|
|
8
|
+
* - The level that activeItem is at should be displayed
|
|
9
|
+
* - If activeItem is a parent node, its child level should be displayed
|
|
10
|
+
*
|
|
11
|
+
* @param items
|
|
12
|
+
* @param value
|
|
13
|
+
* @param options
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
export function getColumnsAndPaths(items, pathTarget, options) {
|
|
17
|
+
var getParent = options.getParent,
|
|
18
|
+
getChildren = options.getChildren;
|
|
19
|
+
|
|
20
|
+
if (!pathTarget) {
|
|
21
|
+
return {
|
|
22
|
+
columns: [items],
|
|
23
|
+
path: []
|
|
40
24
|
};
|
|
25
|
+
}
|
|
41
26
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (typeof _ret === "object") return _ret.v;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return null;
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
var selectedNode = findNode(data);
|
|
52
|
-
columns.push(data);
|
|
27
|
+
var columns = [];
|
|
28
|
+
var path = [pathTarget];
|
|
29
|
+
var children = getChildren(pathTarget);
|
|
53
30
|
|
|
54
|
-
if (
|
|
55
|
-
|
|
31
|
+
if (children && children.length > 0) {
|
|
32
|
+
columns.unshift(children);
|
|
56
33
|
}
|
|
57
34
|
|
|
58
|
-
|
|
59
|
-
var
|
|
60
|
-
return item[valueKey] === value;
|
|
61
|
-
});
|
|
35
|
+
for (var parent = getParent(pathTarget); !!parent; parent = getParent(parent)) {
|
|
36
|
+
var _getChildren;
|
|
62
37
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
38
|
+
columns.unshift((_getChildren = getChildren(parent)) !== null && _getChildren !== void 0 ? _getChildren : []);
|
|
39
|
+
path.unshift(parent);
|
|
66
40
|
}
|
|
67
41
|
|
|
68
|
-
columns.
|
|
69
|
-
paths.reverse();
|
|
42
|
+
columns.unshift(items);
|
|
70
43
|
return {
|
|
71
44
|
columns: columns,
|
|
72
|
-
|
|
45
|
+
path: path
|
|
73
46
|
};
|
|
74
47
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Caculate following 3 things
|
|
51
|
+
*
|
|
52
|
+
* - The columns of items to be displayed
|
|
53
|
+
* - The path towards the current focused item
|
|
54
|
+
* - The path towards the current selected item (referred to by Cascader's value)
|
|
55
|
+
*
|
|
56
|
+
* @param params
|
|
57
|
+
* @returns
|
|
58
|
+
*/
|
|
59
|
+
export function usePaths(_ref) {
|
|
60
|
+
var data = _ref.data,
|
|
61
|
+
activeItem = _ref.activeItem,
|
|
62
|
+
selectedItem = _ref.selectedItem,
|
|
63
|
+
getParent = _ref.getParent,
|
|
64
|
+
getChildren = _ref.getChildren;
|
|
65
|
+
var pathTowardsSelectedItem = useMemo(function () {
|
|
66
|
+
return getPathTowardsItem(selectedItem, getParent);
|
|
67
|
+
}, [getParent, selectedItem]);
|
|
80
68
|
|
|
81
69
|
var _useMemo = useMemo(function () {
|
|
82
|
-
return getColumnsAndPaths(data,
|
|
83
|
-
|
|
84
|
-
|
|
70
|
+
return getColumnsAndPaths(data, activeItem, {
|
|
71
|
+
getParent: getParent,
|
|
72
|
+
getChildren: getChildren
|
|
85
73
|
});
|
|
86
|
-
}, [data,
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
var _useState = useState(columns),
|
|
92
|
-
columnData = _useState[0],
|
|
93
|
-
setColumnData = _useState[1]; // The path after cascading data selection.
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
var _useState2 = useState(paths),
|
|
97
|
-
selectedPaths = _useState2[0],
|
|
98
|
-
setSelectedPaths = _useState2[1]; // The path corresponding to the selected value.
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
var _useState3 = useState(paths),
|
|
102
|
-
valueToPaths = _useState3[0],
|
|
103
|
-
setValueToPaths = _useState3[1];
|
|
104
|
-
/**
|
|
105
|
-
* Add a list of options to the cascading panel. Used for lazy loading options.
|
|
106
|
-
* @param column
|
|
107
|
-
* @param index The index of the current column.
|
|
108
|
-
*/
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
function addColumn(column, index) {
|
|
112
|
-
setColumnData([].concat(slice(columnData, 0, index), [column]));
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Remove subsequent columns of the specified column
|
|
116
|
-
* @param index
|
|
117
|
-
*/
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
function removeColumnByIndex(index) {
|
|
121
|
-
setColumnData([].concat(slice(columnData, 0, index)));
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Enforce update of columns and paths.
|
|
125
|
-
* @param nextValue Selected value
|
|
126
|
-
* @param isAttachChildren Whether to attach the children of the selected node.
|
|
127
|
-
*/
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
function enforceUpdate(nextValue, isAttachChildren) {
|
|
131
|
-
var _getColumnsAndPaths = getColumnsAndPaths(data, nextValue, {
|
|
132
|
-
valueKey: valueKey,
|
|
133
|
-
childrenKey: childrenKey,
|
|
134
|
-
isAttachChildren: isAttachChildren
|
|
135
|
-
}),
|
|
136
|
-
columns = _getColumnsAndPaths.columns,
|
|
137
|
-
paths = _getColumnsAndPaths.paths;
|
|
138
|
-
|
|
139
|
-
setColumnData(columns);
|
|
140
|
-
setSelectedPaths(paths);
|
|
141
|
-
}
|
|
74
|
+
}, [data, activeItem, getParent, getChildren]),
|
|
75
|
+
columnsToDisplay = _useMemo.columns,
|
|
76
|
+
pathTowardsActiveItem = _useMemo.path;
|
|
142
77
|
|
|
143
|
-
useUpdateEffect(function () {
|
|
144
|
-
// Update paths when value is updated, then update valueToPaths.
|
|
145
|
-
setValueToPaths(paths);
|
|
146
|
-
}, [paths]);
|
|
147
|
-
useUpdateEffect(function () {
|
|
148
|
-
enforceUpdate(value);
|
|
149
|
-
}, [data]);
|
|
150
78
|
return {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
selectedPaths: selectedPaths,
|
|
155
|
-
setValueToPaths: setValueToPaths,
|
|
156
|
-
setColumnData: setColumnData,
|
|
157
|
-
setSelectedPaths: setSelectedPaths,
|
|
158
|
-
addColumn: addColumn,
|
|
159
|
-
removeColumnByIndex: removeColumnByIndex
|
|
79
|
+
columnsToDisplay: columnsToDisplay,
|
|
80
|
+
pathTowardsSelectedItem: pathTowardsSelectedItem,
|
|
81
|
+
pathTowardsActiveItem: pathTowardsActiveItem
|
|
160
82
|
};
|
|
161
83
|
}
|
|
@@ -12,7 +12,7 @@ import classNames from 'classnames';
|
|
|
12
12
|
import { List, AutoSizer } from '../Windowing';
|
|
13
13
|
import CheckTreeNode from './CheckTreeNode';
|
|
14
14
|
import TreeContext from '../Tree/TreeContext';
|
|
15
|
-
import { getTreeNodeIndent } from '../utils/treeUtils';
|
|
15
|
+
import { getKeyParentMap, getPathTowardsItem, getTreeNodeIndent } from '../utils/treeUtils';
|
|
16
16
|
import { createChainedFunction, useCustom, useClassNames, useControlled, KEY_VALUES, mergeRefs } from '../utils';
|
|
17
17
|
import { PickerToggle, onMenuKeyDown as _onMenuKeyDown, PickerOverlay, SearchBar, SelectedElement, PickerToggleTrigger, createConcatChildrenFunction, usePickerClassName, usePublicMethods, pickTriggerPropKeys, omitTriggerPropKeys, listPickerPropTypes, useToggleKeyDownEvent } from '../Picker';
|
|
18
18
|
import { isEveryChildChecked, isSomeNodeHasChildren, isAllSiblingNodeUncheckable, isEveryFirstLevelNodeUncheckable, getFormattedTree, getDisabledState, getCheckTreePickerDefaultValue, getSelectedItems, isNodeUncheckable } from './utils';
|
|
@@ -91,13 +91,14 @@ var CheckTreePicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
91
91
|
onExited = props.onExited,
|
|
92
92
|
onSearch = props.onSearch,
|
|
93
93
|
onSelect = props.onSelect,
|
|
94
|
+
onSelectItem = props.onSelectItem,
|
|
94
95
|
onOpen = props.onOpen,
|
|
95
96
|
onScroll = props.onScroll,
|
|
96
97
|
onExpand = props.onExpand,
|
|
97
98
|
renderValue = props.renderValue,
|
|
98
99
|
renderTreeIcon = props.renderTreeIcon,
|
|
99
100
|
renderTreeNode = props.renderTreeNode,
|
|
100
|
-
rest = _objectWithoutPropertiesLoose(props, ["as", "data", "style", "appearance", "cleanable", "countable", "searchBy", "toggleAs", "searchKeyword", "showIndentLine", "locale", "cascade", "disabled", "valueKey", "labelKey", "placement", "childrenKey", "placeholder", "value", "defaultValue", "defaultExpandAll", "disabledItemValues", "expandItemValues", "defaultExpandItemValues", "height", "menuMaxHeight", "menuStyle", "searchable", "virtualized", "className", "classPrefix", "menuClassName", "menuAutoWidth", "uncheckableItemValues", "id", "listProps", "renderMenu", "getChildren", "renderExtraFooter", "onEntered", "onChange", "onClean", "onClose", "onExited", "onSearch", "onSelect", "onOpen", "onScroll", "onExpand", "renderValue", "renderTreeIcon", "renderTreeNode"]);
|
|
101
|
+
rest = _objectWithoutPropertiesLoose(props, ["as", "data", "style", "appearance", "cleanable", "countable", "searchBy", "toggleAs", "searchKeyword", "showIndentLine", "locale", "cascade", "disabled", "valueKey", "labelKey", "placement", "childrenKey", "placeholder", "value", "defaultValue", "defaultExpandAll", "disabledItemValues", "expandItemValues", "defaultExpandItemValues", "height", "menuMaxHeight", "menuStyle", "searchable", "virtualized", "className", "classPrefix", "menuClassName", "menuAutoWidth", "uncheckableItemValues", "id", "listProps", "renderMenu", "getChildren", "renderExtraFooter", "onEntered", "onChange", "onClean", "onClose", "onExited", "onSearch", "onSelect", "onSelectItem", "onOpen", "onScroll", "onExpand", "renderValue", "renderTreeIcon", "renderTreeNode"]);
|
|
101
102
|
|
|
102
103
|
var _useContext = useContext(TreeContext),
|
|
103
104
|
inline = _useContext.inline;
|
|
@@ -343,7 +344,16 @@ var CheckTreePicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
343
344
|
return values.filter(function (v) {
|
|
344
345
|
return !uncheckableItemValues.includes(v);
|
|
345
346
|
});
|
|
346
|
-
}, [flattenNodes, uncheckableItemValues, serializeListOnlyParent, toggleDownChecked, toggleUpChecked]);
|
|
347
|
+
}, [flattenNodes, uncheckableItemValues, serializeListOnlyParent, toggleDownChecked, toggleUpChecked]); // TODO-Doma
|
|
348
|
+
// Replace `getKeyParentMap` with `getParentMap`
|
|
349
|
+
|
|
350
|
+
var itemParentMap = useMemo(function () {
|
|
351
|
+
return getKeyParentMap(data, function (node) {
|
|
352
|
+
return node[valueKey];
|
|
353
|
+
}, function (node) {
|
|
354
|
+
return node[childrenKey];
|
|
355
|
+
});
|
|
356
|
+
}, [childrenKey, data, valueKey]);
|
|
347
357
|
var handleSelect = useCallback(function (node, event) {
|
|
348
358
|
var currentNode = node.refKey ? flattenNodes[node.refKey] : null;
|
|
349
359
|
|
|
@@ -368,7 +378,10 @@ var CheckTreePicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
368
378
|
setFocusItemValue(node[valueKey]);
|
|
369
379
|
onChange === null || onChange === void 0 ? void 0 : onChange(selectedValues, event);
|
|
370
380
|
onSelect === null || onSelect === void 0 ? void 0 : onSelect(node, selectedValues, event);
|
|
371
|
-
|
|
381
|
+
onSelectItem === null || onSelectItem === void 0 ? void 0 : onSelectItem(node, getPathTowardsItem(node, function (item) {
|
|
382
|
+
return itemParentMap.get(item[valueKey]);
|
|
383
|
+
}));
|
|
384
|
+
}, [flattenNodes, toggleChecked, isControlled, valueKey, onChange, onSelect, onSelectItem, unSerializeList, cascade, uncheckableItemValues, setValue, itemParentMap]);
|
|
372
385
|
var handleOpen = useCallback(function () {
|
|
373
386
|
var _triggerRef$current, _triggerRef$current$o;
|
|
374
387
|
|
|
@@ -21,8 +21,10 @@ export interface DatePickerProps extends PickerBaseProps<DatePickerLocale>, Form
|
|
|
21
21
|
inline?: boolean;
|
|
22
22
|
/** ISO 8601 standard, each calendar week begins on Monday and Sunday on the seventh day */
|
|
23
23
|
isoWeek?: boolean;
|
|
24
|
-
/** Set the
|
|
24
|
+
/** Set the upper limit of the available year relative to the current selection date */
|
|
25
25
|
limitEndYear?: number;
|
|
26
|
+
/** Set the lower limit of the available year relative to the current selection date */
|
|
27
|
+
limitStartYear?: number;
|
|
26
28
|
/** Whether to show week numbers */
|
|
27
29
|
showWeekNumbers?: boolean;
|
|
28
30
|
/** Meridian format */
|
|
@@ -35,6 +35,7 @@ var DatePicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
35
35
|
isoWeek = props.isoWeek,
|
|
36
36
|
_props$limitEndYear = props.limitEndYear,
|
|
37
37
|
limitEndYear = _props$limitEndYear === void 0 ? 1000 : _props$limitEndYear,
|
|
38
|
+
limitStartYear = props.limitStartYear,
|
|
38
39
|
overrideLocale = props.locale,
|
|
39
40
|
menuClassName = props.menuClassName,
|
|
40
41
|
_props$appearance = props.appearance,
|
|
@@ -73,7 +74,7 @@ var DatePicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
73
74
|
onSelect = props.onSelect,
|
|
74
75
|
onToggleMonthDropdown = props.onToggleMonthDropdown,
|
|
75
76
|
onToggleTimeDropdown = props.onToggleTimeDropdown,
|
|
76
|
-
rest = _objectWithoutPropertiesLoose(props, ["as", "className", "classPrefix", "calendarDefaultDate", "cleanable", "editable", "defaultValue", "disabled", "format", "isoWeek", "limitEndYear", "locale", "menuClassName", "appearance", "placement", "oneTap", "placeholder", "ranges", "value", "showMeridian", "showWeekNumbers", "style", "toggleAs", "caretAs", "disabledDate", "disabledHours", "disabledMinutes", "disabledSeconds", "shouldDisableDate", "shouldDisableHour", "shouldDisableMinute", "shouldDisableSecond", "renderValue", "onChange", "onChangeCalendarDate", "onClean", "onClose", "onEntered", "onExited", "onNextMonth", "onOk", "onOpen", "onPrevMonth", "onSelect", "onToggleMonthDropdown", "onToggleTimeDropdown"]);
|
|
77
|
+
rest = _objectWithoutPropertiesLoose(props, ["as", "className", "classPrefix", "calendarDefaultDate", "cleanable", "editable", "defaultValue", "disabled", "format", "isoWeek", "limitEndYear", "limitStartYear", "locale", "menuClassName", "appearance", "placement", "oneTap", "placeholder", "ranges", "value", "showMeridian", "showWeekNumbers", "style", "toggleAs", "caretAs", "disabledDate", "disabledHours", "disabledMinutes", "disabledSeconds", "shouldDisableDate", "shouldDisableHour", "shouldDisableMinute", "shouldDisableSecond", "renderValue", "onChange", "onChangeCalendarDate", "onClean", "onClose", "onEntered", "onExited", "onNextMonth", "onOk", "onOpen", "onPrevMonth", "onSelect", "onToggleMonthDropdown", "onToggleTimeDropdown"]);
|
|
77
78
|
|
|
78
79
|
var _useCustom = useCustom('DatePicker', overrideLocale),
|
|
79
80
|
locale = _useCustom.locale,
|
|
@@ -352,6 +353,7 @@ var DatePicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
352
353
|
disabledMinutes: shouldDisableMinute !== null && shouldDisableMinute !== void 0 ? shouldDisableMinute : DEPRECATED_disabledMinutes,
|
|
353
354
|
disabledSeconds: shouldDisableSecond !== null && shouldDisableSecond !== void 0 ? shouldDisableSecond : DEPRECATED_disabledSeconds,
|
|
354
355
|
limitEndYear: limitEndYear,
|
|
356
|
+
limitStartYear: limitStartYear,
|
|
355
357
|
format: formatStr,
|
|
356
358
|
isoWeek: isoWeek,
|
|
357
359
|
calendarDate: calendarDate,
|
|
@@ -495,6 +497,7 @@ DatePicker.propTypes = _extends({}, pickerPropTypes, {
|
|
|
495
497
|
hideSeconds: PropTypes.func,
|
|
496
498
|
isoWeek: PropTypes.bool,
|
|
497
499
|
limitEndYear: PropTypes.number,
|
|
500
|
+
limitStartYear: PropTypes.number,
|
|
498
501
|
onChange: PropTypes.func,
|
|
499
502
|
onChangeCalendarDate: PropTypes.func,
|
|
500
503
|
onNextMonth: PropTypes.func,
|
|
@@ -13,6 +13,7 @@ export interface CalendarProps extends WithAsProps, Omit<CalendarCoreProps, Omit
|
|
|
13
13
|
index: number;
|
|
14
14
|
isoWeek?: boolean;
|
|
15
15
|
limitEndYear?: number;
|
|
16
|
+
limitStartYear?: number;
|
|
16
17
|
locale?: DatePickerLocale;
|
|
17
18
|
onChangeCalendarMonth?: (index: number, date: Date) => void;
|
|
18
19
|
onChangeCalendarTime?: (index: number, date: Date) => void;
|
|
@@ -16,13 +16,14 @@ var Calendar = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
16
16
|
_props$index = props.index,
|
|
17
17
|
index = _props$index === void 0 ? 0 : _props$index,
|
|
18
18
|
limitEndYear = props.limitEndYear,
|
|
19
|
+
limitStartYear = props.limitStartYear,
|
|
19
20
|
onChangeCalendarMonth = props.onChangeCalendarMonth,
|
|
20
21
|
onChangeCalendarTime = props.onChangeCalendarTime,
|
|
21
22
|
onToggleMeridian = props.onToggleMeridian,
|
|
22
23
|
onSelect = props.onSelect,
|
|
23
24
|
_props$value = props.value,
|
|
24
25
|
value = _props$value === void 0 ? [] : _props$value,
|
|
25
|
-
rest = _objectWithoutPropertiesLoose(props, ["as", "calendarDate", "format", "disabledDate", "index", "limitEndYear", "onChangeCalendarMonth", "onChangeCalendarTime", "onToggleMeridian", "onSelect", "value"]);
|
|
26
|
+
rest = _objectWithoutPropertiesLoose(props, ["as", "calendarDate", "format", "disabledDate", "index", "limitEndYear", "limitStartYear", "onChangeCalendarMonth", "onChangeCalendarTime", "onToggleMeridian", "onSelect", "value"]);
|
|
26
27
|
|
|
27
28
|
var onMoveForward = useCallback(function (nextPageDate) {
|
|
28
29
|
onChangeCalendarMonth === null || onChangeCalendarMonth === void 0 ? void 0 : onChangeCalendarMonth(index, nextPageDate);
|
|
@@ -60,6 +61,7 @@ var Calendar = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
60
61
|
disabledDate: disabledMonth,
|
|
61
62
|
index: index,
|
|
62
63
|
limitEndYear: limitEndYear,
|
|
64
|
+
limitStartYear: limitStartYear,
|
|
63
65
|
onChangeMonth: handleChangeMonth,
|
|
64
66
|
onChangeTime: handleChangeTime,
|
|
65
67
|
onMoveBackward: handleMoveBackward,
|
|
@@ -79,6 +81,7 @@ Calendar.propTypes = {
|
|
|
79
81
|
format: PropTypes.string,
|
|
80
82
|
isoWeek: PropTypes.bool,
|
|
81
83
|
limitEndYear: PropTypes.number,
|
|
84
|
+
limitStartYear: PropTypes.number,
|
|
82
85
|
classPrefix: PropTypes.string,
|
|
83
86
|
disabledDate: PropTypes.func,
|
|
84
87
|
onSelect: PropTypes.func,
|
|
@@ -15,8 +15,10 @@ export interface DateRangePickerProps extends PickerBaseProps, FormControlBasePr
|
|
|
15
15
|
oneTap?: boolean;
|
|
16
16
|
/** ISO 8601 standard, each calendar week begins on Monday and Sunday on the seventh day */
|
|
17
17
|
isoWeek?: boolean;
|
|
18
|
-
/** Set the
|
|
18
|
+
/** Set the upper limit of the available year relative to the current selection date */
|
|
19
19
|
limitEndYear?: number;
|
|
20
|
+
/** Set the lower limit of the available year relative to the current selection date */
|
|
21
|
+
limitStartYear?: number;
|
|
20
22
|
/** Whether to show week numbers */
|
|
21
23
|
showWeekNumbers?: boolean;
|
|
22
24
|
/** Show only one calendar select */
|
|
@@ -47,6 +47,7 @@ var DateRangePicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
47
47
|
isoWeek = _props$isoWeek === void 0 ? false : _props$isoWeek,
|
|
48
48
|
_props$limitEndYear = props.limitEndYear,
|
|
49
49
|
limitEndYear = _props$limitEndYear === void 0 ? 1000 : _props$limitEndYear,
|
|
50
|
+
limitStartYear = props.limitStartYear,
|
|
50
51
|
overrideLocale = props.locale,
|
|
51
52
|
menuClassName = props.menuClassName,
|
|
52
53
|
menuStyle = props.menuStyle,
|
|
@@ -75,7 +76,7 @@ var DateRangePicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
75
76
|
onOpen = props.onOpen,
|
|
76
77
|
onSelect = props.onSelect,
|
|
77
78
|
renderTitle = props.renderTitle,
|
|
78
|
-
rest = _objectWithoutPropertiesLoose(props, ["as", "classPrefix", "className", "appearance", "editable", "cleanable", "character", "defaultCalendarValue", "defaultValue", "disabled", "disabledDate", "shouldDisableDate", "format", "hoverRange", "isoWeek", "limitEndYear", "locale", "menuClassName", "menuStyle", "oneTap", "placeholder", "placement", "ranges", "renderValue", "showOneCalendar", "showWeekNumbers", "showMeridian", "style", "toggleAs", "caretAs", "value", "onChange", "onClean", "onClose", "onEnter", "onEntered", "onExited", "onOk", "onOpen", "onSelect", "renderTitle"]);
|
|
79
|
+
rest = _objectWithoutPropertiesLoose(props, ["as", "classPrefix", "className", "appearance", "editable", "cleanable", "character", "defaultCalendarValue", "defaultValue", "disabled", "disabledDate", "shouldDisableDate", "format", "hoverRange", "isoWeek", "limitEndYear", "limitStartYear", "locale", "menuClassName", "menuStyle", "oneTap", "placeholder", "placement", "ranges", "renderValue", "showOneCalendar", "showWeekNumbers", "showMeridian", "style", "toggleAs", "caretAs", "value", "onChange", "onClean", "onClose", "onEnter", "onEntered", "onExited", "onOk", "onOpen", "onSelect", "renderTitle"]);
|
|
79
80
|
|
|
80
81
|
var _useClassNames = useClassNames(classPrefix),
|
|
81
82
|
merge = _useClassNames.merge,
|
|
@@ -621,6 +622,7 @@ var DateRangePicker = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
621
622
|
hoverRangeValue: hoverDateRange !== null && hoverDateRange !== void 0 ? hoverDateRange : undefined,
|
|
622
623
|
isoWeek: isoWeek,
|
|
623
624
|
limitEndYear: limitEndYear,
|
|
625
|
+
limitStartYear: limitStartYear,
|
|
624
626
|
locale: locale,
|
|
625
627
|
showWeekNumbers: showWeekNumbers,
|
|
626
628
|
value: selectedDates,
|
|
@@ -747,6 +749,7 @@ DateRangePicker.propTypes = _extends({}, pickerPropTypes, {
|
|
|
747
749
|
isoWeek: PropTypes.bool,
|
|
748
750
|
oneTap: PropTypes.bool,
|
|
749
751
|
limitEndYear: PropTypes.number,
|
|
752
|
+
limitStartYear: PropTypes.number,
|
|
750
753
|
onChange: PropTypes.func,
|
|
751
754
|
onOk: PropTypes.func,
|
|
752
755
|
disabledDate: deprecatePropTypeNew(PropTypes.func, 'Use "shouldDisableDate" property instead.'),
|
|
@@ -10,11 +10,11 @@ export interface DropdownMenuProps extends WithAsProps {
|
|
|
10
10
|
menuWidth?: number;
|
|
11
11
|
menuHeight?: number | string;
|
|
12
12
|
cascade?: boolean;
|
|
13
|
-
cascadeData: ItemDataType[][];
|
|
13
|
+
cascadeData: (readonly ItemDataType[])[];
|
|
14
14
|
cascadePaths?: ItemDataType[];
|
|
15
15
|
uncheckableItemValues: ValueType;
|
|
16
16
|
renderMenuItem?: (itemLabel: React.MouseEventHandler, item: ItemDataType) => React.ReactNode;
|
|
17
|
-
renderMenu?: (children: ItemDataType[], menu: React.ReactNode, parentNode?: ItemDataType, layer?: number) => React.ReactNode;
|
|
17
|
+
renderMenu?: (children: readonly ItemDataType[], menu: React.ReactNode, parentNode?: ItemDataType, layer?: number) => React.ReactNode;
|
|
18
18
|
onCheck?: (node: ItemDataType, event: React.SyntheticEvent, checked: boolean) => void;
|
|
19
19
|
onSelect?: (node: ItemDataType, cascadePaths: ItemDataType[], event: React.SyntheticEvent) => void;
|
|
20
20
|
}
|
|
@@ -18,7 +18,7 @@ export interface MultiCascaderProps<T = ValueType> extends FormControlPickerProp
|
|
|
18
18
|
/** The menu is displayed directly when the component is initialized */
|
|
19
19
|
inline?: boolean;
|
|
20
20
|
/** Custom render menu */
|
|
21
|
-
renderMenu?: (items: ItemDataType[], menu: React.ReactNode, parentNode?: any, layer?: number) => React.ReactNode;
|
|
21
|
+
renderMenu?: (items: readonly ItemDataType[], menu: React.ReactNode, parentNode?: any, layer?: number) => React.ReactNode;
|
|
22
22
|
/** Custom render menu items */
|
|
23
23
|
renderMenuItem?: (itemLabel: React.ReactNode, item: any) => React.ReactNode;
|
|
24
24
|
/** Custom render selected items */
|
|
@@ -143,17 +143,22 @@ var MultiCascader = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
143
143
|
return overlayRef.current;
|
|
144
144
|
},
|
|
145
145
|
callback: useCallback(function (value) {
|
|
146
|
-
var _getColumnsAndPaths = getColumnsAndPaths(data,
|
|
147
|
-
valueKey
|
|
148
|
-
|
|
149
|
-
|
|
146
|
+
var _getColumnsAndPaths = getColumnsAndPaths(data, flattenData.find(function (item) {
|
|
147
|
+
return item[valueKey] === value;
|
|
148
|
+
}), {
|
|
149
|
+
getParent: function getParent() {
|
|
150
|
+
return undefined;
|
|
151
|
+
},
|
|
152
|
+
getChildren: function getChildren(item) {
|
|
153
|
+
return item[childrenKey];
|
|
154
|
+
}
|
|
150
155
|
}),
|
|
151
156
|
columns = _getColumnsAndPaths.columns,
|
|
152
|
-
|
|
157
|
+
path = _getColumnsAndPaths.path;
|
|
153
158
|
|
|
154
159
|
setColumnData(columns);
|
|
155
|
-
setSelectedPaths(
|
|
156
|
-
}, [childrenKey, data, setColumnData, valueKey])
|
|
160
|
+
setSelectedPaths(path);
|
|
161
|
+
}, [childrenKey, data, flattenData, setColumnData, valueKey])
|
|
157
162
|
}),
|
|
158
163
|
focusItemValue = _useFocusItemValue.focusItemValue,
|
|
159
164
|
setLayer = _useFocusItemValue.setLayer,
|
|
@@ -49,10 +49,10 @@ export declare function useFlattenData<T>(data: T[], itemKeys: ItemKeys): {
|
|
|
49
49
|
* @param flattenData
|
|
50
50
|
*/
|
|
51
51
|
export declare function useColumnData<T extends MayHasParent<Record<string, unknown>>>(flattenData: T[]): {
|
|
52
|
-
columnData: T[][];
|
|
52
|
+
columnData: (readonly T[])[];
|
|
53
53
|
addColumn: (column: T[], index: number) => void;
|
|
54
54
|
removeColumnByIndex: (index: number) => void;
|
|
55
|
-
setColumnData: import("react").Dispatch<import("react").SetStateAction<T[][]>>;
|
|
55
|
+
setColumnData: import("react").Dispatch<import("react").SetStateAction<(readonly T[])[]>>;
|
|
56
56
|
enforceUpdateColumnData: (nextData: T[]) => void;
|
|
57
57
|
};
|
|
58
58
|
/**
|
|
@@ -2,7 +2,7 @@ import { useState, useEffect, useCallback } from 'react';
|
|
|
2
2
|
import uniq from 'lodash/uniq';
|
|
3
3
|
import remove from 'lodash/remove';
|
|
4
4
|
import slice from 'lodash/slice';
|
|
5
|
-
import {
|
|
5
|
+
import { UNSAFE_flattenTree } from '../utils/treeUtils';
|
|
6
6
|
import { attachParent } from '../utils/attachParent';
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -162,7 +162,7 @@ export var removeAllChildrenValue = function removeAllChildrenValue(value, item,
|
|
|
162
162
|
export function useFlattenData(data, itemKeys) {
|
|
163
163
|
var childrenKey = itemKeys.childrenKey;
|
|
164
164
|
|
|
165
|
-
var _useState = useState(
|
|
165
|
+
var _useState = useState(UNSAFE_flattenTree(data, itemKeys.childrenKey)),
|
|
166
166
|
flattenData = _useState[0],
|
|
167
167
|
setFlattenData = _useState[1];
|
|
168
168
|
|
|
@@ -174,7 +174,7 @@ export function useFlattenData(data, itemKeys) {
|
|
|
174
174
|
setFlattenData([].concat(flattenData, nodes));
|
|
175
175
|
}, [childrenKey, flattenData]);
|
|
176
176
|
useEffect(function () {
|
|
177
|
-
setFlattenData(
|
|
177
|
+
setFlattenData(UNSAFE_flattenTree(data, itemKeys.childrenKey));
|
|
178
178
|
}, [data, itemKeys.childrenKey]);
|
|
179
179
|
return {
|
|
180
180
|
addFlattenData: addFlattenData,
|
|
@@ -214,7 +214,7 @@ export function useColumnData(flattenData) {
|
|
|
214
214
|
}
|
|
215
215
|
|
|
216
216
|
function enforceUpdateColumnData(nextData) {
|
|
217
|
-
var nextFlattenData =
|
|
217
|
+
var nextFlattenData = UNSAFE_flattenTree(nextData);
|
|
218
218
|
setColumnData([nextFlattenData.filter(function (item) {
|
|
219
219
|
return !item.parent;
|
|
220
220
|
})]);
|
package/esm/Picker/utils.d.ts
CHANGED
|
@@ -42,21 +42,22 @@ export interface EventsProps {
|
|
|
42
42
|
* @param events Event callback functions
|
|
43
43
|
*/
|
|
44
44
|
export declare function onMenuKeyDown(event: React.KeyboardEvent, events: EventsProps): void;
|
|
45
|
-
export interface FocusItemValueProps {
|
|
45
|
+
export interface FocusItemValueProps<T = unknown> {
|
|
46
46
|
target: HTMLElement | null | (() => HTMLElement | null);
|
|
47
|
-
data?:
|
|
47
|
+
data?: T[];
|
|
48
48
|
valueKey?: string;
|
|
49
49
|
focusableQueryKey?: string;
|
|
50
50
|
defaultLayer?: number;
|
|
51
51
|
rtl?: boolean;
|
|
52
52
|
callback?: (value: any, event: React.KeyboardEvent) => void;
|
|
53
|
+
getParent?: (node: T) => T | undefined;
|
|
53
54
|
}
|
|
54
55
|
/**
|
|
55
56
|
* A hook that manages the focus state of the option.
|
|
56
57
|
* @param defaultFocusItemValue
|
|
57
58
|
* @param props
|
|
58
59
|
*/
|
|
59
|
-
export declare const useFocusItemValue: <T>(defaultFocusItemValue: T | null | undefined, props: FocusItemValueProps) => {
|
|
60
|
+
export declare const useFocusItemValue: <T, D>(defaultFocusItemValue: T | null | undefined, props: FocusItemValueProps<D>) => {
|
|
60
61
|
focusItemValue: T | null | undefined;
|
|
61
62
|
setFocusItemValue: React.Dispatch<React.SetStateAction<T | null | undefined>>;
|
|
62
63
|
layer: number;
|
package/esm/Picker/utils.js
CHANGED
|
@@ -191,7 +191,11 @@ export var useFocusItemValue = function useFocusItemValue(defaultFocusItemValue,
|
|
|
191
191
|
data = props.data,
|
|
192
192
|
target = props.target,
|
|
193
193
|
rtl = props.rtl,
|
|
194
|
-
callback = props.callback
|
|
194
|
+
callback = props.callback,
|
|
195
|
+
_props$getParent = props.getParent,
|
|
196
|
+
getParent = _props$getParent === void 0 ? function (item) {
|
|
197
|
+
return item === null || item === void 0 ? void 0 : item.parent;
|
|
198
|
+
} : _props$getParent;
|
|
195
199
|
|
|
196
200
|
var _useState = useState(defaultFocusItemValue),
|
|
197
201
|
focusItemValue = _useState[0],
|
|
@@ -353,21 +357,21 @@ export var useFocusItemValue = function useFocusItemValue(defaultFocusItemValue,
|
|
|
353
357
|
var nextKeys = getSubMenuKeys(nextLayer);
|
|
354
358
|
|
|
355
359
|
if (nextKeys) {
|
|
356
|
-
var
|
|
360
|
+
var _getParent;
|
|
357
361
|
|
|
358
362
|
setKeys(nextKeys);
|
|
359
363
|
setLayer(nextLayer);
|
|
360
364
|
var focusItem = findNodeOfTree(data, function (item) {
|
|
361
365
|
return item[valueKey] === focusItemValue;
|
|
362
366
|
});
|
|
363
|
-
var parentItemValue =
|
|
367
|
+
var parentItemValue = (_getParent = getParent(focusItem)) === null || _getParent === void 0 ? void 0 : _getParent[valueKey];
|
|
364
368
|
|
|
365
369
|
if (parentItemValue) {
|
|
366
370
|
setFocusItemValue(parentItemValue);
|
|
367
371
|
callback === null || callback === void 0 ? void 0 : callback(parentItemValue, event);
|
|
368
372
|
}
|
|
369
373
|
}
|
|
370
|
-
}, [callback, data, focusItemValue, getSubMenuKeys, layer, valueKey]);
|
|
374
|
+
}, [callback, data, focusItemValue, getParent, getSubMenuKeys, layer, valueKey]);
|
|
371
375
|
var handleKeyDown = useCallback(function (event) {
|
|
372
376
|
var _onMenuKeyDown;
|
|
373
377
|
|
package/esm/Tree/Tree.d.ts
CHANGED
|
@@ -60,6 +60,8 @@ export interface TreeBaseProps<ValueType = string | number, ItemDataType = Recor
|
|
|
60
60
|
onExpand?: (expandItemValues: ItemDataType[], activeNode: ItemDataType, concat: (data: ItemDataType[], children: ItemDataType[]) => ItemDataType[]) => void;
|
|
61
61
|
/** Callback function after selecting tree node */
|
|
62
62
|
onSelect?: (activeNode: ItemDataType, value: ValueType, event: React.SyntheticEvent) => void;
|
|
63
|
+
/** Callback when a tree item is clicked */
|
|
64
|
+
onSelectItem?: (item: ItemDataType, path: ItemDataType[]) => void;
|
|
63
65
|
/** Custom Render tree Node */
|
|
64
66
|
renderTreeNode?: (nodeData: ItemDataType) => React.ReactNode;
|
|
65
67
|
/** Custom Render icon */
|