@chaoswise/ui 2.2.9 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/lib/AbreastLayout/index.js +5 -1
  2. package/lib/BasicLayout/Sider.js +8 -3
  3. package/lib/BasicLayout/index.js +10 -2
  4. package/lib/CWCascader/Cascader/index.js +207 -0
  5. package/lib/CWCascader/index.js +5 -0
  6. package/lib/CWCascader/index.less +9 -0
  7. package/lib/CWCascader/rc-cascader/Cascader.js +329 -0
  8. package/lib/CWCascader/rc-cascader/OptionList/Checkbox.js +22 -0
  9. package/lib/CWCascader/rc-cascader/OptionList/Column.js +209 -0
  10. package/lib/CWCascader/rc-cascader/OptionList/index.js +215 -0
  11. package/lib/CWCascader/rc-cascader/OptionList/useActive.js +33 -0
  12. package/lib/CWCascader/rc-cascader/OptionList/useKeyboard.js +177 -0
  13. package/lib/CWCascader/rc-cascader/context.js +3 -0
  14. package/lib/CWCascader/rc-cascader/hooks/useDisplayValues.js +56 -0
  15. package/lib/CWCascader/rc-cascader/hooks/useEntities.js +48 -0
  16. package/lib/CWCascader/rc-cascader/hooks/useMissingValues.js +19 -0
  17. package/lib/CWCascader/rc-cascader/hooks/useRefFunc.js +13 -0
  18. package/lib/CWCascader/rc-cascader/hooks/useSearchConfig.js +30 -0
  19. package/lib/CWCascader/rc-cascader/hooks/useSearchOptions.js +74 -0
  20. package/lib/CWCascader/rc-cascader/index.js +2 -0
  21. package/lib/CWCascader/rc-cascader/utils/commonUtil.js +54 -0
  22. package/lib/CWCascader/rc-cascader/utils/treeUtil.js +37 -0
  23. package/lib/CWCascader/rc-cascader/utils/warningPropsUtil.js +30 -0
  24. package/lib/CWRangePicker/index.js +6 -1
  25. package/lib/CWSelect/index.js +9 -1
  26. package/lib/CWSelect/index.less +10 -0
  27. package/lib/Cascader/index.js +0 -8
  28. package/lib/Cascader/index.less +5 -0
  29. package/lib/Cascaders/Cascader/index.js +208 -0
  30. package/lib/Cascaders/index.js +17 -0
  31. package/lib/Cascaders/index.less +1 -0
  32. package/lib/Cascaders/rc-cascader/Cascader.js +326 -0
  33. package/lib/Cascaders/rc-cascader/OptionList/Checkbox.js +22 -0
  34. package/lib/Cascaders/rc-cascader/OptionList/Column.js +203 -0
  35. package/lib/Cascaders/rc-cascader/OptionList/index.js +213 -0
  36. package/lib/Cascaders/rc-cascader/OptionList/useActive.js +33 -0
  37. package/lib/Cascaders/rc-cascader/OptionList/useKeyboard.js +171 -0
  38. package/lib/Cascaders/rc-cascader/context.js +3 -0
  39. package/lib/Cascaders/rc-cascader/hooks/useDisplayValues.js +56 -0
  40. package/lib/Cascaders/rc-cascader/hooks/useEntities.js +34 -0
  41. package/lib/Cascaders/rc-cascader/hooks/useMissingValues.js +19 -0
  42. package/lib/Cascaders/rc-cascader/hooks/useRefFunc.js +13 -0
  43. package/lib/Cascaders/rc-cascader/hooks/useSearchConfig.js +25 -0
  44. package/lib/Cascaders/rc-cascader/hooks/useSearchOptions.js +72 -0
  45. package/lib/Cascaders/rc-cascader/index.js +2 -0
  46. package/lib/Cascaders/rc-cascader/utils/commonUtil.js +54 -0
  47. package/lib/Cascaders/rc-cascader/utils/treeUtil.js +37 -0
  48. package/lib/Cascaders/rc-cascader/utils/warningPropsUtil.js +30 -0
  49. package/lib/CitySelect/index.js +2 -2
  50. package/package.json +3 -3
@@ -0,0 +1,208 @@
1
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
3
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
4
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
5
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
6
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
7
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
8
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
9
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
10
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
11
+ var __rest = this && this.__rest || function (s, e) {
12
+ var t = {};
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
14
+ if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
15
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
16
+ }
17
+ return t;
18
+ };
19
+ // @ts-nocheck
20
+ import * as React from 'react';
21
+ import classNames from 'classnames';
22
+ import RcCascader from '../rc-cascader';
23
+ import omit from 'rc-util/lib/omit';
24
+ import RightOutlined from '@ant-design/icons/RightOutlined';
25
+ import LoadingOutlined from '@ant-design/icons/LoadingOutlined';
26
+ import LeftOutlined from '@ant-design/icons/LeftOutlined';
27
+ import { useContext } from 'react';
28
+ import devWarning from '../../Antd4/_util/devWarning';
29
+ import { ConfigContext } from '../../Antd4/config-provider';
30
+ import SizeContext from '../../Antd4/config-provider/SizeContext';
31
+ import getIcons from '../../Antd4/select/utils/iconUtil';
32
+ import { getTransitionName, getTransitionDirection } from '../../Antd4/_util/motion';
33
+ import { FormItemInputContext } from '../../Antd4/form4-24-7/context';
34
+ import { getMergedStatus, getStatusClassNames } from '../../Antd4/_util/statusUtils';
35
+ var SHOW_CHILD = RcCascader.SHOW_CHILD,
36
+ SHOW_PARENT = RcCascader.SHOW_PARENT;
37
+ function highlightKeyword(str, lowerKeyword, prefixCls) {
38
+ var cells = str.toLowerCase().split(lowerKeyword).reduce(function (list, cur, index) {
39
+ return index === 0 ? [cur] : [].concat(_toConsumableArray(list), [lowerKeyword, cur]);
40
+ }, []);
41
+ var fillCells = [];
42
+ var start = 0;
43
+ cells.forEach(function (cell, index) {
44
+ var end = start + cell.length;
45
+ var originWorld = str.slice(start, end);
46
+ start = end;
47
+ if (index % 2 === 1) {
48
+ originWorld =
49
+ /*#__PURE__*/
50
+ // eslint-disable-next-line react/no-array-index-key
51
+ React.createElement("span", {
52
+ className: "".concat(prefixCls, "-menu-item-keyword"),
53
+ key: "seperator-".concat(index)
54
+ }, originWorld);
55
+ }
56
+ fillCells.push(originWorld);
57
+ });
58
+ return fillCells;
59
+ }
60
+ var defaultSearchRender = function defaultSearchRender(inputValue, path, prefixCls, fieldNames) {
61
+ var optionList = [];
62
+ // We do lower here to save perf
63
+ var lower = inputValue.toLowerCase();
64
+ path.forEach(function (node, index) {
65
+ if (index !== 0) {
66
+ optionList.push(' / ');
67
+ }
68
+ var label = node[fieldNames.label];
69
+ var type = _typeof(label);
70
+ if (type === 'string' || type === 'number') {
71
+ label = highlightKeyword(String(label), lower, prefixCls);
72
+ }
73
+ optionList.push(label);
74
+ });
75
+ return optionList;
76
+ };
77
+ var Cascader = /*#__PURE__*/React.forwardRef(function (props, ref) {
78
+ var _classNames2;
79
+ var customizePrefixCls = props.prefixCls,
80
+ customizeSize = props.size,
81
+ className = props.className,
82
+ multiple = props.multiple,
83
+ _props$bordered = props.bordered,
84
+ bordered = _props$bordered === void 0 ? true : _props$bordered,
85
+ transitionName = props.transitionName,
86
+ _props$choiceTransiti = props.choiceTransitionName,
87
+ choiceTransitionName = _props$choiceTransiti === void 0 ? '' : _props$choiceTransiti,
88
+ popupClassName = props.popupClassName,
89
+ dropdownClassName = props.dropdownClassName,
90
+ expandIcon = props.expandIcon,
91
+ placement = props.placement,
92
+ showSearch = props.showSearch,
93
+ _props$allowClear = props.allowClear,
94
+ allowClear = _props$allowClear === void 0 ? true : _props$allowClear,
95
+ notFoundContent = props.notFoundContent,
96
+ direction = props.direction,
97
+ getPopupContainer = props.getPopupContainer,
98
+ customStatus = props.status,
99
+ showArrow = props.showArrow,
100
+ rest = __rest(props, ["prefixCls", "size", "className", "multiple", "bordered", "transitionName", "choiceTransitionName", "popupClassName", "dropdownClassName", "expandIcon", "placement", "showSearch", "allowClear", "notFoundContent", "direction", "getPopupContainer", "status", "showArrow"]);
101
+ var restProps = omit(rest, ['suffixIcon']);
102
+ var _useContext = useContext(ConfigContext),
103
+ getContextPopupContainer = _useContext.getPopupContainer,
104
+ getPrefixCls = _useContext.getPrefixCls,
105
+ renderEmpty = _useContext.renderEmpty,
106
+ rootDirection = _useContext.direction;
107
+ var mergedDirection = direction || rootDirection;
108
+ var isRtl = mergedDirection === 'rtl';
109
+ // =================== Form =====================
110
+ var _useContext2 = useContext(FormItemInputContext),
111
+ contextStatus = _useContext2.status,
112
+ hasFeedback = _useContext2.hasFeedback,
113
+ isFormItemInput = _useContext2.isFormItemInput,
114
+ feedbackIcon = _useContext2.feedbackIcon;
115
+ var mergedStatus = getMergedStatus(contextStatus, customStatus);
116
+ // =================== Warning =====================
117
+ if (process.env.NODE_ENV !== 'production') {
118
+ devWarning(popupClassName === undefined, 'Cascader', '`popupClassName` is deprecated. Please use `dropdownClassName` instead.');
119
+ devWarning(!multiple || !props.displayRender, 'Cascader', '`displayRender` not work on `multiple`. Please use `tagRender` instead.');
120
+ }
121
+ // =================== No Found ====================
122
+ var mergedNotFoundContent = notFoundContent || renderEmpty('Cascader');
123
+ // ==================== Prefix =====================
124
+ var rootPrefixCls = getPrefixCls();
125
+ var prefixCls = getPrefixCls('select', customizePrefixCls);
126
+ var cascaderPrefixCls = getPrefixCls('cascader', customizePrefixCls);
127
+ // =================== Dropdown ====================
128
+ var mergedDropdownClassName = classNames(dropdownClassName || popupClassName, "".concat(cascaderPrefixCls, "-dropdown"), _defineProperty({}, "".concat(cascaderPrefixCls, "-dropdown-rtl"), mergedDirection === 'rtl'));
129
+ // ==================== Search =====================
130
+ var mergedShowSearch = React.useMemo(function () {
131
+ if (!showSearch) {
132
+ return showSearch;
133
+ }
134
+ var searchConfig = {
135
+ render: defaultSearchRender
136
+ };
137
+ if (_typeof(showSearch) === 'object') {
138
+ searchConfig = Object.assign(Object.assign({}, searchConfig), showSearch);
139
+ }
140
+ return searchConfig;
141
+ }, [showSearch]);
142
+ // ===================== Size ======================
143
+ var size = React.useContext(SizeContext);
144
+ var mergedSize = customizeSize || size;
145
+ // ===================== Icon ======================
146
+ var mergedExpandIcon = expandIcon;
147
+ if (!expandIcon) {
148
+ mergedExpandIcon = isRtl ? /*#__PURE__*/React.createElement(LeftOutlined, null) : /*#__PURE__*/React.createElement(RightOutlined, null);
149
+ }
150
+ var loadingIcon = /*#__PURE__*/React.createElement("span", {
151
+ className: "".concat(prefixCls, "-menu-item-loading-icon")
152
+ }, /*#__PURE__*/React.createElement(LoadingOutlined, {
153
+ spin: true
154
+ }));
155
+ // =================== Multiple ====================
156
+ var checkable = React.useMemo(function () {
157
+ return multiple ? /*#__PURE__*/React.createElement("span", {
158
+ className: "".concat(cascaderPrefixCls, "-checkbox-inner")
159
+ }) : false;
160
+ }, [multiple]);
161
+ // ===================== Icons =====================
162
+ var mergedShowArrow = showArrow !== undefined ? showArrow : props.loading || !multiple;
163
+ var _getIcons = getIcons(Object.assign(Object.assign({}, props), {
164
+ hasFeedback: hasFeedback,
165
+ feedbackIcon: feedbackIcon,
166
+ showArrow: mergedShowArrow,
167
+ multiple: multiple,
168
+ prefixCls: prefixCls
169
+ })),
170
+ suffixIcon = _getIcons.suffixIcon,
171
+ removeIcon = _getIcons.removeIcon,
172
+ clearIcon = _getIcons.clearIcon;
173
+ // ===================== Placement =====================
174
+ var getPlacement = function getPlacement() {
175
+ if (placement !== undefined) {
176
+ return placement;
177
+ }
178
+ return direction === 'rtl' ? 'bottomRight' : 'bottomLeft';
179
+ };
180
+ // ==================== Render =====================
181
+ return /*#__PURE__*/React.createElement(RcCascader, Object.assign({
182
+ prefixCls: prefixCls,
183
+ className: classNames(!customizePrefixCls && cascaderPrefixCls, (_classNames2 = {}, _defineProperty(_classNames2, "".concat(prefixCls, "-lg"), mergedSize === 'large'), _defineProperty(_classNames2, "".concat(prefixCls, "-sm"), mergedSize === 'small'), _defineProperty(_classNames2, "".concat(prefixCls, "-rtl"), isRtl), _defineProperty(_classNames2, "".concat(prefixCls, "-borderless"), !bordered), _defineProperty(_classNames2, "".concat(prefixCls, "-in-form-item"), isFormItemInput), _classNames2), getStatusClassNames(prefixCls, mergedStatus, hasFeedback), className)
184
+ }, restProps, {
185
+ direction: mergedDirection,
186
+ placement: getPlacement(),
187
+ notFoundContent: mergedNotFoundContent,
188
+ allowClear: allowClear,
189
+ showSearch: mergedShowSearch,
190
+ expandIcon: mergedExpandIcon,
191
+ inputIcon: suffixIcon,
192
+ removeIcon: removeIcon,
193
+ clearIcon: clearIcon,
194
+ loadingIcon: loadingIcon,
195
+ checkable: checkable,
196
+ dropdownClassName: mergedDropdownClassName,
197
+ dropdownPrefixCls: customizePrefixCls || cascaderPrefixCls,
198
+ choiceTransitionName: getTransitionName(rootPrefixCls, '', choiceTransitionName),
199
+ transitionName: getTransitionName(rootPrefixCls, getTransitionDirection(placement), transitionName),
200
+ getPopupContainer: getPopupContainer || getContextPopupContainer,
201
+ ref: ref,
202
+ showArrow: hasFeedback || showArrow
203
+ }));
204
+ });
205
+ Cascader.displayName = 'Cascader';
206
+ Cascader.SHOW_PARENT = SHOW_PARENT;
207
+ Cascader.SHOW_CHILD = SHOW_CHILD;
208
+ export default Cascader;
@@ -0,0 +1,17 @@
1
+ function _objectDestructuringEmpty(obj) { if (obj == null) throw new TypeError("Cannot destructure " + obj); }
2
+ 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); }
3
+ import React, { forwardRef } from "react";
4
+ import Cascader from "./Cascader";
5
+ import "antd/es/cascader/style/index.less";
6
+ import "../Antd4/cascader/style/index.less";
7
+ import classnames from "classnames";
8
+ import { cloneComProps } from "../utils";
9
+ import "./index.less";
10
+ var Cascaders = /*#__PURE__*/forwardRef(function (props, ref) {
11
+ var rest = _extends({}, (_objectDestructuringEmpty(props), props));
12
+ return /*#__PURE__*/React.createElement(Cascader, _extends({
13
+ ref: ref
14
+ }, rest));
15
+ });
16
+ cloneComProps(Cascader, Cascaders);
17
+ export default Cascaders;
@@ -0,0 +1 @@
1
+ @import '../Cascader/index.less';
@@ -0,0 +1,326 @@
1
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
2
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
4
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
5
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
6
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
7
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
8
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
9
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
10
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
11
+ var __rest = this && this.__rest || function (s, e) {
12
+ var t = {};
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
14
+ if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
15
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
16
+ }
17
+ return t;
18
+ };
19
+ import { BaseSelect } from 'rc-cascader/node_modules/rc-select';
20
+ import useId from 'rc-cascader/node_modules/rc-select/lib/hooks/useId';
21
+ import { conductCheck } from 'rc-cascader/node_modules/rc-tree/lib/utils/conductUtil';
22
+ import useMergedState from 'rc-util/lib/hooks/useMergedState';
23
+ import * as React from 'react';
24
+ import CascaderContext from './context';
25
+ import useDisplayValues from './hooks/useDisplayValues';
26
+ import useEntities from './hooks/useEntities';
27
+ import useMissingValues from './hooks/useMissingValues';
28
+ import useRefFunc from './hooks/useRefFunc';
29
+ import useSearchConfig from './hooks/useSearchConfig';
30
+ import useSearchOptions from './hooks/useSearchOptions';
31
+ import OptionList from './OptionList';
32
+ import { fillFieldNames, SHOW_CHILD, SHOW_PARENT, toPathKey, toPathKeys } from './utils/commonUtil';
33
+ import { formatStrategyValues, toPathOptions } from './utils/treeUtil';
34
+ import warningProps, { warningNullOptions } from './utils/warningPropsUtil';
35
+ function isMultipleValue(value) {
36
+ return Array.isArray(value) && Array.isArray(value[0]);
37
+ }
38
+ function toRawValues(value) {
39
+ if (!value) {
40
+ return [];
41
+ }
42
+ if (isMultipleValue(value)) {
43
+ return value;
44
+ }
45
+ return (value.length === 0 ? [] : [value]).map(function (val) {
46
+ return Array.isArray(val) ? val : [val];
47
+ });
48
+ }
49
+ var Cascader = /*#__PURE__*/React.forwardRef(function (props, ref) {
50
+ var id = props.id,
51
+ _props$prefixCls = props.prefixCls,
52
+ prefixCls = _props$prefixCls === void 0 ? 'rc-cascader' : _props$prefixCls,
53
+ fieldNames = props.fieldNames,
54
+ defaultValue = props.defaultValue,
55
+ value = props.value,
56
+ changeOnSelect = props.changeOnSelect,
57
+ onChange = props.onChange,
58
+ displayRender = props.displayRender,
59
+ checkable = props.checkable,
60
+ searchValue = props.searchValue,
61
+ onSearch = props.onSearch,
62
+ showSearch = props.showSearch,
63
+ expandTrigger = props.expandTrigger,
64
+ options = props.options,
65
+ dropdownPrefixCls = props.dropdownPrefixCls,
66
+ loadData = props.loadData,
67
+ popupVisible = props.popupVisible,
68
+ open = props.open,
69
+ popupClassName = props.popupClassName,
70
+ dropdownClassName = props.dropdownClassName,
71
+ dropdownMenuColumnStyle = props.dropdownMenuColumnStyle,
72
+ popupPlacement = props.popupPlacement,
73
+ placement = props.placement,
74
+ onDropdownVisibleChange = props.onDropdownVisibleChange,
75
+ onPopupVisibleChange = props.onPopupVisibleChange,
76
+ _props$expandIcon = props.expandIcon,
77
+ expandIcon = _props$expandIcon === void 0 ? '>' : _props$expandIcon,
78
+ loadingIcon = props.loadingIcon,
79
+ children = props.children,
80
+ _props$dropdownMatchS = props.dropdownMatchSelectWidth,
81
+ dropdownMatchSelectWidth = _props$dropdownMatchS === void 0 ? false : _props$dropdownMatchS,
82
+ _props$showCheckedStr = props.showCheckedStrategy,
83
+ showCheckedStrategy = _props$showCheckedStr === void 0 ? SHOW_PARENT : _props$showCheckedStr,
84
+ onScroll = props.onScroll,
85
+ onSrollBottom = props.onSrollBottom,
86
+ showColumnSearch = props.showColumnSearch,
87
+ onInputChange = props.onInputChange,
88
+ restProps = __rest(props, ["id", "prefixCls", "fieldNames", "defaultValue", "value", "changeOnSelect", "onChange", "displayRender", "checkable", "searchValue", "onSearch", "showSearch", "expandTrigger", "options", "dropdownPrefixCls", "loadData", "popupVisible", "open", "popupClassName", "dropdownClassName", "dropdownMenuColumnStyle", "popupPlacement", "placement", "onDropdownVisibleChange", "onPopupVisibleChange", "expandIcon", "loadingIcon", "children", "dropdownMatchSelectWidth", "showCheckedStrategy", "onScroll", "onSrollBottom", "showColumnSearch", "onInputChange"]);
89
+ var mergedId = useId(id);
90
+ var multiple = !!checkable;
91
+ // =========================== Values ===========================
92
+ var _useMergedState = useMergedState(defaultValue, {
93
+ value: value,
94
+ postState: toRawValues
95
+ }),
96
+ _useMergedState2 = _slicedToArray(_useMergedState, 2),
97
+ rawValues = _useMergedState2[0],
98
+ setRawValues = _useMergedState2[1];
99
+ // ========================= FieldNames =========================
100
+ var mergedFieldNames = React.useMemo(function () {
101
+ return fillFieldNames(fieldNames);
102
+ }, /* eslint-disable react-hooks/exhaustive-deps */
103
+ [JSON.stringify(fieldNames)]);
104
+ // =========================== Option ===========================
105
+ var mergedOptions = React.useMemo(function () {
106
+ return options || [];
107
+ }, [options]);
108
+ // Only used in multiple mode, this fn will not call in single mode
109
+ var getPathKeyEntities = useEntities(mergedOptions, mergedFieldNames);
110
+ /** Convert path key back to value format */
111
+ var getValueByKeyPath = React.useCallback(function (pathKeys) {
112
+ var keyPathEntities = getPathKeyEntities();
113
+ return pathKeys.map(function (pathKey) {
114
+ var nodes = keyPathEntities[pathKey].nodes;
115
+ return nodes.map(function (node) {
116
+ return node[mergedFieldNames.value];
117
+ });
118
+ });
119
+ }, [getPathKeyEntities, mergedFieldNames]);
120
+ // =========================== Search ===========================
121
+ var _useMergedState3 = useMergedState('', {
122
+ value: searchValue,
123
+ postState: function postState(search) {
124
+ return search || '';
125
+ }
126
+ }),
127
+ _useMergedState4 = _slicedToArray(_useMergedState3, 2),
128
+ mergedSearchValue = _useMergedState4[0],
129
+ setSearchValue = _useMergedState4[1];
130
+ var onInternalSearch = function onInternalSearch(searchText, info) {
131
+ setSearchValue(searchText);
132
+ if (info.source !== 'blur' && onSearch) {
133
+ onSearch(searchText);
134
+ }
135
+ };
136
+ var _useSearchConfig = useSearchConfig(showSearch),
137
+ _useSearchConfig2 = _slicedToArray(_useSearchConfig, 2),
138
+ mergedShowSearch = _useSearchConfig2[0],
139
+ searchConfig = _useSearchConfig2[1];
140
+ var searchOptions = useSearchOptions(mergedSearchValue, mergedOptions, mergedFieldNames, dropdownPrefixCls || prefixCls, searchConfig, changeOnSelect);
141
+ // =========================== Values ===========================
142
+ var getMissingValues = useMissingValues(mergedOptions, mergedFieldNames);
143
+ // Fill `rawValues` with checked conduction values
144
+ var _React$useMemo = React.useMemo(function () {
145
+ var _getMissingValues = getMissingValues(rawValues),
146
+ _getMissingValues2 = _slicedToArray(_getMissingValues, 2),
147
+ existValues = _getMissingValues2[0],
148
+ missingValues = _getMissingValues2[1];
149
+ if (!multiple || !rawValues.length) {
150
+ return [existValues, [], missingValues];
151
+ }
152
+ var keyPathValues = toPathKeys(existValues);
153
+ var keyPathEntities = getPathKeyEntities();
154
+ var _conductCheck = conductCheck(keyPathValues, true, keyPathEntities),
155
+ checkedKeys = _conductCheck.checkedKeys,
156
+ halfCheckedKeys = _conductCheck.halfCheckedKeys;
157
+ // Convert key back to value cells
158
+ return [getValueByKeyPath(checkedKeys), getValueByKeyPath(halfCheckedKeys), missingValues];
159
+ }, [multiple, rawValues, getPathKeyEntities, getValueByKeyPath, getMissingValues]),
160
+ _React$useMemo2 = _slicedToArray(_React$useMemo, 3),
161
+ checkedValues = _React$useMemo2[0],
162
+ halfCheckedValues = _React$useMemo2[1],
163
+ missingCheckedValues = _React$useMemo2[2];
164
+ var deDuplicatedValues = React.useMemo(function () {
165
+ var checkedKeys = toPathKeys(checkedValues);
166
+ var deduplicateKeys = formatStrategyValues(checkedKeys, getPathKeyEntities, showCheckedStrategy);
167
+ return [].concat(_toConsumableArray(missingCheckedValues), _toConsumableArray(getValueByKeyPath(deduplicateKeys)));
168
+ }, [checkedValues, getPathKeyEntities, getValueByKeyPath, missingCheckedValues, showCheckedStrategy]);
169
+ var displayValues = useDisplayValues(deDuplicatedValues, mergedOptions, mergedFieldNames, multiple, displayRender);
170
+ // =========================== Change ===========================
171
+ var triggerChange = useRefFunc(function (nextValues) {
172
+ setRawValues(nextValues);
173
+ // Save perf if no need trigger event
174
+ if (onChange) {
175
+ var nextRawValues = toRawValues(nextValues);
176
+ var valueOptions = nextRawValues.map(function (valueCells) {
177
+ return toPathOptions(valueCells, mergedOptions, mergedFieldNames).map(function (valueOpt) {
178
+ return valueOpt.option;
179
+ });
180
+ });
181
+ var triggerValues = multiple ? nextRawValues : nextRawValues[0];
182
+ var triggerOptions = multiple ? valueOptions : valueOptions[0];
183
+ onChange(triggerValues, triggerOptions);
184
+ }
185
+ });
186
+ // =========================== Select ===========================
187
+ var onInternalSelect = useRefFunc(function (valuePath) {
188
+ setSearchValue('');
189
+ if (!multiple) {
190
+ triggerChange(valuePath);
191
+ } else {
192
+ // Prepare conduct required info
193
+ var pathKey = toPathKey(valuePath);
194
+ var checkedPathKeys = toPathKeys(checkedValues);
195
+ var halfCheckedPathKeys = toPathKeys(halfCheckedValues);
196
+ var existInChecked = checkedPathKeys.includes(pathKey);
197
+ var existInMissing = missingCheckedValues.some(function (valueCells) {
198
+ return toPathKey(valueCells) === pathKey;
199
+ });
200
+ // Do update
201
+ var nextCheckedValues = checkedValues;
202
+ var nextMissingValues = missingCheckedValues;
203
+ if (existInMissing && !existInChecked) {
204
+ // Missing value only do filter
205
+ nextMissingValues = missingCheckedValues.filter(function (valueCells) {
206
+ return toPathKey(valueCells) !== pathKey;
207
+ });
208
+ } else {
209
+ // Update checked key first
210
+ var nextRawCheckedKeys = existInChecked ? checkedPathKeys.filter(function (key) {
211
+ return key !== pathKey;
212
+ }) : [].concat(_toConsumableArray(checkedPathKeys), [pathKey]);
213
+ var pathKeyEntities = getPathKeyEntities();
214
+ // Conduction by selected or not
215
+ var checkedKeys;
216
+ if (existInChecked) {
217
+ var _conductCheck2 = conductCheck(nextRawCheckedKeys, {
218
+ checked: false,
219
+ halfCheckedKeys: halfCheckedPathKeys
220
+ }, pathKeyEntities);
221
+ checkedKeys = _conductCheck2.checkedKeys;
222
+ } else {
223
+ var _conductCheck3 = conductCheck(nextRawCheckedKeys, true, pathKeyEntities);
224
+ checkedKeys = _conductCheck3.checkedKeys;
225
+ }
226
+ // Roll up to parent level keys
227
+ var deDuplicatedKeys = formatStrategyValues(checkedKeys, getPathKeyEntities, showCheckedStrategy);
228
+ nextCheckedValues = getValueByKeyPath(deDuplicatedKeys);
229
+ }
230
+ triggerChange([].concat(_toConsumableArray(nextMissingValues), _toConsumableArray(nextCheckedValues)));
231
+ }
232
+ });
233
+ // Display Value change logic
234
+ var onDisplayValuesChange = function onDisplayValuesChange(_, info) {
235
+ if (info.type === 'clear') {
236
+ triggerChange([]);
237
+ return;
238
+ }
239
+ // Cascader do not support `add` type. Only support `remove`
240
+ var valueCells = info.values[0].valueCells;
241
+ onInternalSelect(valueCells);
242
+ };
243
+ // ============================ Open ============================
244
+ var mergedOpen = open !== undefined ? open : popupVisible;
245
+ var mergedDropdownClassName = dropdownClassName || popupClassName;
246
+ var mergedPlacement = placement || popupPlacement;
247
+ var onInternalDropdownVisibleChange = function onInternalDropdownVisibleChange(nextVisible) {
248
+ onDropdownVisibleChange === null || onDropdownVisibleChange === void 0 ? void 0 : onDropdownVisibleChange(nextVisible);
249
+ onPopupVisibleChange === null || onPopupVisibleChange === void 0 ? void 0 : onPopupVisibleChange(nextVisible);
250
+ };
251
+ // ========================== Warning ===========================
252
+ if (process.env.NODE_ENV !== 'production') {
253
+ warningProps(props);
254
+ warningNullOptions(mergedOptions, mergedFieldNames);
255
+ }
256
+ // ========================== Context ===========================
257
+ var cascaderContext = React.useMemo(function () {
258
+ return {
259
+ options: mergedOptions,
260
+ fieldNames: mergedFieldNames,
261
+ values: checkedValues,
262
+ halfValues: halfCheckedValues,
263
+ changeOnSelect: changeOnSelect,
264
+ onSelect: onInternalSelect,
265
+ checkable: checkable,
266
+ searchOptions: searchOptions,
267
+ dropdownPrefixCls: dropdownPrefixCls,
268
+ loadData: loadData,
269
+ expandTrigger: expandTrigger,
270
+ expandIcon: expandIcon,
271
+ loadingIcon: loadingIcon,
272
+ dropdownMenuColumnStyle: dropdownMenuColumnStyle,
273
+ onScroll: onScroll,
274
+ onSrollBottom: onSrollBottom,
275
+ showColumnSearch: showColumnSearch,
276
+ onInputChange: onInputChange
277
+ };
278
+ }, [mergedOptions, mergedFieldNames, checkedValues, halfCheckedValues, changeOnSelect, onInternalSelect, checkable, searchOptions, dropdownPrefixCls, loadData, expandTrigger, expandIcon, loadingIcon, dropdownMenuColumnStyle, onScroll, onSrollBottom, showColumnSearch, onInputChange]);
279
+ // ==============================================================
280
+ // == Render ==
281
+ // ==============================================================
282
+ var emptyOptions = !(mergedSearchValue ? searchOptions : mergedOptions).length;
283
+ var dropdownStyle =
284
+ // Search to match width
285
+ mergedSearchValue && searchConfig.matchInputWidth ||
286
+ // Empty keep the width
287
+ emptyOptions ? {} : {
288
+ minWidth: 'auto'
289
+ };
290
+ return /*#__PURE__*/React.createElement(CascaderContext.Provider, {
291
+ value: cascaderContext
292
+ }, /*#__PURE__*/React.createElement(BaseSelect, Object.assign({}, restProps, {
293
+ // MISC
294
+ ref: ref,
295
+ id: mergedId,
296
+ prefixCls: prefixCls,
297
+ dropdownMatchSelectWidth: dropdownMatchSelectWidth,
298
+ dropdownStyle: dropdownStyle,
299
+ // Value
300
+ displayValues: displayValues,
301
+ onDisplayValuesChange: onDisplayValuesChange,
302
+ mode: multiple ? 'multiple' : undefined,
303
+ // Search
304
+ searchValue: mergedSearchValue,
305
+ onSearch: onInternalSearch,
306
+ showSearch: showColumnSearch ? false : mergedShowSearch,
307
+ // Options
308
+ OptionList: OptionList,
309
+ emptyOptions: emptyOptions,
310
+ // Open
311
+ open: mergedOpen,
312
+ dropdownClassName: mergedDropdownClassName,
313
+ placement: mergedPlacement,
314
+ onDropdownVisibleChange: onInternalDropdownVisibleChange,
315
+ // Children
316
+ getRawInputElement: function getRawInputElement() {
317
+ return children;
318
+ }
319
+ })));
320
+ });
321
+ if (process.env.NODE_ENV !== 'production') {
322
+ Cascader.displayName = 'Cascader';
323
+ }
324
+ Cascader.SHOW_PARENT = SHOW_PARENT;
325
+ Cascader.SHOW_CHILD = SHOW_CHILD;
326
+ export default Cascader;
@@ -0,0 +1,22 @@
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
3
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
4
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
5
+ import * as React from 'react';
6
+ import classNames from 'classnames';
7
+ import CascaderContext from '../context';
8
+ export default function Checkbox(_ref) {
9
+ var _classNames;
10
+ var prefixCls = _ref.prefixCls,
11
+ checked = _ref.checked,
12
+ halfChecked = _ref.halfChecked,
13
+ disabled = _ref.disabled,
14
+ onClick = _ref.onClick;
15
+ var _React$useContext = React.useContext(CascaderContext),
16
+ checkable = _React$useContext.checkable;
17
+ var customCheckbox = typeof checkable !== 'boolean' ? checkable : null;
18
+ return /*#__PURE__*/React.createElement("span", {
19
+ className: classNames("".concat(prefixCls), (_classNames = {}, _defineProperty(_classNames, "".concat(prefixCls, "-checked"), checked), _defineProperty(_classNames, "".concat(prefixCls, "-indeterminate"), !checked && halfChecked), _defineProperty(_classNames, "".concat(prefixCls, "-disabled"), disabled), _classNames)),
20
+ onClick: onClick
21
+ }, customCheckbox);
22
+ }