@chaoswise/ui 2.2.8 → 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 (54) 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/CWMessage/index.js +3 -1
  25. package/lib/CWMessage/index.less +3 -0
  26. package/lib/CWRangePicker/index.js +6 -1
  27. package/lib/CWSelect/index.js +9 -1
  28. package/lib/CWSelect/index.less +10 -0
  29. package/lib/Cascader/index.js +0 -8
  30. package/lib/Cascader/index.less +5 -0
  31. package/lib/Cascaders/Cascader/index.js +208 -0
  32. package/lib/Cascaders/index.js +17 -0
  33. package/lib/Cascaders/index.less +1 -0
  34. package/lib/Cascaders/rc-cascader/Cascader.js +326 -0
  35. package/lib/Cascaders/rc-cascader/OptionList/Checkbox.js +22 -0
  36. package/lib/Cascaders/rc-cascader/OptionList/Column.js +203 -0
  37. package/lib/Cascaders/rc-cascader/OptionList/index.js +213 -0
  38. package/lib/Cascaders/rc-cascader/OptionList/useActive.js +33 -0
  39. package/lib/Cascaders/rc-cascader/OptionList/useKeyboard.js +171 -0
  40. package/lib/Cascaders/rc-cascader/context.js +3 -0
  41. package/lib/Cascaders/rc-cascader/hooks/useDisplayValues.js +56 -0
  42. package/lib/Cascaders/rc-cascader/hooks/useEntities.js +34 -0
  43. package/lib/Cascaders/rc-cascader/hooks/useMissingValues.js +19 -0
  44. package/lib/Cascaders/rc-cascader/hooks/useRefFunc.js +13 -0
  45. package/lib/Cascaders/rc-cascader/hooks/useSearchConfig.js +25 -0
  46. package/lib/Cascaders/rc-cascader/hooks/useSearchOptions.js +72 -0
  47. package/lib/Cascaders/rc-cascader/index.js +2 -0
  48. package/lib/Cascaders/rc-cascader/utils/commonUtil.js +54 -0
  49. package/lib/Cascaders/rc-cascader/utils/treeUtil.js +37 -0
  50. package/lib/Cascaders/rc-cascader/utils/warningPropsUtil.js +30 -0
  51. package/lib/CitySelect/index.js +2 -2
  52. package/lib/QuickTransfer/NotDragList.js +1 -4
  53. package/lib/QuickTransfer/TopicList.js +2 -4
  54. package/package.json +3 -3
@@ -204,7 +204,11 @@ AbreastLayout.propTypes = {
204
204
  /**
205
205
  * 内容区样式
206
206
  */
207
- contentStyle: PropTypes.object
207
+ contentStyle: PropTypes.object,
208
+ /**
209
+ * 折叠展开的callback,onCollapse = (collapsed)=>{}
210
+ */
211
+ onCollapse: PropTypes.func
208
212
  };
209
213
  AbreastLayout.NavTreeContainer = NavTreeContainer;
210
214
  export default AbreastLayout;
@@ -6,7 +6,7 @@ import "@chaoswise/ui/lib/SiderMenu/index.less";
6
6
  import _SiderMenu from "@chaoswise/ui/lib/SiderMenu";
7
7
  import "antd/es/layout/style";
8
8
  import _Layout from "antd/es/layout";
9
- var _excluded = ["canDrag", "enable", "maxDragWidth", "resizeBarColor", "onResizeStart", "onResizeStop", "siderDragWidth"],
9
+ var _excluded = ["canDrag", "enable", "maxDragWidth", "resizeBarColor", "onResizeStart", "onResizeStop", "onResize", "siderDragWidth"],
10
10
  _excluded2 = ["menuData", "resizableProps"];
11
11
  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); }
12
12
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
@@ -38,7 +38,7 @@ function Sider(_ref) {
38
38
  _menuOptions$resizabl = menuOptions.resizableProps,
39
39
  _menuOptions$resizabl2 = _menuOptions$resizabl === void 0 ? {} : _menuOptions$resizabl,
40
40
  _menuOptions$resizabl3 = _menuOptions$resizabl2.canDrag,
41
- canDrag = _menuOptions$resizabl3 === void 0 ? false : _menuOptions$resizabl3,
41
+ canDrag = _menuOptions$resizabl3 === void 0 ? true : _menuOptions$resizabl3,
42
42
  enable = _menuOptions$resizabl2.enable,
43
43
  _menuOptions$resizabl4 = _menuOptions$resizabl2.maxDragWidth,
44
44
  maxDragWidth = _menuOptions$resizabl4 === void 0 ? 264 : _menuOptions$resizabl4,
@@ -48,6 +48,8 @@ function Sider(_ref) {
48
48
  _onResizeStart = _menuOptions$resizabl6 === void 0 ? function () {} : _menuOptions$resizabl6,
49
49
  _menuOptions$resizabl7 = _menuOptions$resizabl2.onResizeStop,
50
50
  _onResizeStop = _menuOptions$resizabl7 === void 0 ? function () {} : _menuOptions$resizabl7,
51
+ _menuOptions$resizabl8 = _menuOptions$resizabl2.onResize,
52
+ _onResize = _menuOptions$resizabl8 === void 0 ? function () {} : _menuOptions$resizabl8,
51
53
  siderDragWidth = _menuOptions$resizabl2.siderDragWidth,
52
54
  _resizableProps = _objectWithoutProperties(_menuOptions$resizabl2, _excluded),
53
55
  _resMenuProps = _objectWithoutProperties(menuOptions, _excluded2);
@@ -56,7 +58,7 @@ function Sider(_ref) {
56
58
  maxWidth: collapsed ? siderCollapsedWidth : maxDragWidth,
57
59
  onResizeStart: function onResizeStart() {
58
60
  setEnableResizable(true);
59
- _onResizeStart();
61
+ _onResizeStart.apply(void 0, arguments);
60
62
  },
61
63
  onResizeStop: function onResizeStop(e, direction, ref, d) {
62
64
  setEnableResizable(false);
@@ -66,6 +68,9 @@ function Sider(_ref) {
66
68
  _setSiderDragWidth(newWidth);
67
69
  }
68
70
  },
71
+ onResize: function onResize(e, direction, ref, d) {
72
+ _onResize(d.width);
73
+ },
69
74
  enable: _objectSpread({
70
75
  top: false,
71
76
  bottom: false,
@@ -98,7 +98,8 @@ var BasicLayout = function BasicLayout(_ref) {
98
98
  getPrefixCls = _useConfigContext.getPrefixCls;
99
99
  var prefixCls = getPrefixCls('basic-layout');
100
100
  var _useLocale = useLocale(langConfig),
101
- langObj = _useLocale.langObj;
101
+ langObj = _useLocale.langObj,
102
+ locale = _useLocale.locale;
102
103
  var menuData = menuOptions.menuData,
103
104
  _menuOptions$resizabl = menuOptions.resizableProps,
104
105
  _menuOptions$resizabl2 = _menuOptions$resizabl === void 0 ? {} : _menuOptions$resizabl,
@@ -123,7 +124,9 @@ var BasicLayout = function BasicLayout(_ref) {
123
124
  _useState8 = _slicedToArray(_useState7, 2),
124
125
  enableResizable = _useState8[0],
125
126
  setEnableResizable = _useState8[1];
126
- var _useState9 = useState(siderWidth),
127
+ // TODO 优化代码!!!!
128
+ var defaultSiderWidth = locale === 'zh' ? siderWidth : siderWidth + 40;
129
+ var _useState9 = useState(defaultSiderWidth),
127
130
  _useState10 = _slicedToArray(_useState9, 2),
128
131
  _siderDragWidth = _useState10[0],
129
132
  _setSiderDragWidth = _useState10[1];
@@ -140,6 +143,11 @@ var BasicLayout = function BasicLayout(_ref) {
140
143
  _setSiderDragWidth(siderDragWidth);
141
144
  }
142
145
  }, [siderDragWidth]);
146
+ useEffect(function () {
147
+ if (!siderDragWidth) {
148
+ _setSiderDragWidth(defaultSiderWidth);
149
+ }
150
+ }, [locale, defaultSiderWidth]);
143
151
  var onFooterLoaded = function onFooterLoaded(args) {
144
152
  // 移动footer到指定位置展示 统一布局
145
153
  setTimeout(function () {
@@ -0,0 +1,207 @@
1
+ var _excluded = ["prefixCls", "size", "className", "multiple", "bordered", "transitionName", "choiceTransitionName", "popupClassName", "dropdownClassName", "expandIcon", "placement", "showSearch", "allowClear", "notFoundContent", "direction", "getPopupContainer", "status", "showArrow"];
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
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
4
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
5
+ 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; }
6
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
7
+ 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); }
8
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
9
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
10
+ 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); }
11
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
12
+ 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."); }
13
+ 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); }
14
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
15
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
16
+ 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; }
17
+ import LeftOutlined from "@ant-design/icons/LeftOutlined";
18
+ import LoadingOutlined from "@ant-design/icons/LoadingOutlined";
19
+ import RightOutlined from "@ant-design/icons/RightOutlined";
20
+ import classNames from "classnames";
21
+ import RcCascader from "../rc-cascader";
22
+ import omit from "rc-util/lib/omit";
23
+ import * as React from "react";
24
+ import { useContext } from 'react';
25
+ import { ConfigContext } from '../../Antd4/config-provider';
26
+ import SizeContext from '../../Antd4/config-provider/SizeContext';
27
+ import { FormItemInputContext } from '../../Antd4/form4-24-7/context';
28
+ import getIcons from '../../Antd4/select/utils/iconUtil';
29
+ import { getTransitionName, getTransitionDirection } from '../../Antd4/_util/motion';
30
+ import { getMergedStatus, getStatusClassNames } from "../../Antd4/_util/statusUtils";
31
+ var SHOW_CHILD = RcCascader.SHOW_CHILD,
32
+ SHOW_PARENT = RcCascader.SHOW_PARENT;
33
+ function highlightKeyword(str, lowerKeyword, prefixCls) {
34
+ var cells = str.toLowerCase().split(lowerKeyword).reduce(function (list, cur, index) {
35
+ return index === 0 ? [cur] : [].concat(_toConsumableArray(list), [lowerKeyword, cur]);
36
+ }, []);
37
+ var fillCells = [];
38
+ var start = 0;
39
+ cells.forEach(function (cell, index) {
40
+ var end = start + cell.length;
41
+ var originWorld = str.slice(start, end);
42
+ start = end;
43
+ if (index % 2 === 1) {
44
+ originWorld =
45
+ /*#__PURE__*/
46
+ // eslint-disable-next-line react/no-array-index-key
47
+ React.createElement("span", {
48
+ className: "".concat(prefixCls, "-menu-item-keyword"),
49
+ key: "seperator-".concat(index)
50
+ }, originWorld);
51
+ }
52
+ fillCells.push(originWorld);
53
+ });
54
+ return fillCells;
55
+ }
56
+ var defaultSearchRender = function defaultSearchRender(inputValue, path, prefixCls, fieldNames) {
57
+ var optionList = [];
58
+ // We do lower here to save perf
59
+ var lower = inputValue.toLowerCase();
60
+ path.forEach(function (node, index) {
61
+ if (index !== 0) {
62
+ optionList.push(" / ");
63
+ }
64
+ var label = node[fieldNames.label];
65
+ var type = _typeof(label);
66
+ if (type === "string" || type === "number") {
67
+ label = highlightKeyword(String(label), lower, prefixCls);
68
+ }
69
+ optionList.push(label);
70
+ });
71
+ return optionList;
72
+ };
73
+ var Cascader = /*#__PURE__*/React.forwardRef(function (props, ref) {
74
+ var _classNames2;
75
+ var customizePrefixCls = props.prefixCls,
76
+ customizeSize = props.size,
77
+ className = props.className,
78
+ multiple = props.multiple,
79
+ _props$bordered = props.bordered,
80
+ bordered = _props$bordered === void 0 ? true : _props$bordered,
81
+ transitionName = props.transitionName,
82
+ _props$choiceTransiti = props.choiceTransitionName,
83
+ choiceTransitionName = _props$choiceTransiti === void 0 ? '' : _props$choiceTransiti,
84
+ popupClassName = props.popupClassName,
85
+ dropdownClassName = props.dropdownClassName,
86
+ expandIcon = props.expandIcon,
87
+ placement = props.placement,
88
+ showSearch = props.showSearch,
89
+ _props$allowClear = props.allowClear,
90
+ allowClear = _props$allowClear === void 0 ? true : _props$allowClear,
91
+ notFoundContent = props.notFoundContent,
92
+ direction = props.direction,
93
+ getPopupContainer = props.getPopupContainer,
94
+ customStatus = props.status,
95
+ showArrow = props.showArrow,
96
+ rest = _objectWithoutProperties(props, _excluded);
97
+ var restProps = omit(rest, ['suffixIcon']);
98
+ var _useContext = useContext(ConfigContext),
99
+ getContextPopupContainer = _useContext.getPopupContainer,
100
+ getPrefixCls = _useContext.getPrefixCls,
101
+ renderEmpty = _useContext.renderEmpty,
102
+ rootDirection = _useContext.direction;
103
+ var mergedDirection = direction || rootDirection;
104
+ var isRtl = mergedDirection === 'rtl';
105
+
106
+ // =================== Form =====================
107
+ var _useContext2 = useContext(FormItemInputContext),
108
+ contextStatus = _useContext2.status,
109
+ hasFeedback = _useContext2.hasFeedback,
110
+ isFormItemInput = _useContext2.isFormItemInput,
111
+ feedbackIcon = _useContext2.feedbackIcon;
112
+ var mergedStatus = getMergedStatus(contextStatus, customStatus);
113
+ // =================== No Found ====================
114
+ var mergedNotFoundContent = notFoundContent || renderEmpty('Cascader');
115
+
116
+ // ==================== Prefix =====================
117
+ var rootPrefixCls = getPrefixCls();
118
+ var prefixCls = getPrefixCls('select', customizePrefixCls);
119
+ var cascaderPrefixCls = getPrefixCls('cascader', customizePrefixCls);
120
+ // =================== Dropdown ====================
121
+ var mergedDropdownClassName = classNames(dropdownClassName || popupClassName, "".concat(cascaderPrefixCls, "-dropdown"), "cw-cascader-custom-dropdown", _defineProperty({}, "".concat(cascaderPrefixCls, "-dropdown-rtl"), mergedDirection === 'rtl'));
122
+ // ==================== Search =====================
123
+ var mergedShowSearch = React.useMemo(function () {
124
+ if (!showSearch) {
125
+ return showSearch;
126
+ }
127
+ var searchConfig = {
128
+ render: defaultSearchRender
129
+ };
130
+ if (_typeof(showSearch) === 'object') {
131
+ searchConfig = _objectSpread(_objectSpread({}, searchConfig), showSearch);
132
+ }
133
+ return searchConfig;
134
+ }, [showSearch]);
135
+ // ===================== Size ======================
136
+ var size = React.useContext(SizeContext);
137
+ var mergedSize = customizeSize || size;
138
+ // ===================== Icon ======================
139
+ var mergedExpandIcon = expandIcon;
140
+ if (!expandIcon) {
141
+ mergedExpandIcon = isRtl ? /*#__PURE__*/React.createElement(LeftOutlined, null) : /*#__PURE__*/React.createElement(RightOutlined, null);
142
+ }
143
+ var loadingIcon = /*#__PURE__*/React.createElement("span", {
144
+ className: "".concat(prefixCls, "-menu-item-loading-icon")
145
+ }, /*#__PURE__*/React.createElement(LoadingOutlined, {
146
+ spin: true
147
+ }));
148
+
149
+ // =================== Multiple ====================
150
+ var checkable = React.useMemo(function () {
151
+ return multiple ? /*#__PURE__*/React.createElement("span", {
152
+ className: "".concat(cascaderPrefixCls, "-checkbox-inner")
153
+ }) : false;
154
+ }, [multiple]);
155
+ // ===================== Icons =====================
156
+ var mergedShowArrow = showArrow !== undefined ? showArrow : props.loading || !multiple;
157
+ var _getIcons = getIcons(_objectSpread(_objectSpread({}, props), {}, {
158
+ hasFeedback: hasFeedback,
159
+ feedbackIcon: feedbackIcon,
160
+ showArrow: mergedShowArrow,
161
+ multiple: multiple,
162
+ prefixCls: prefixCls
163
+ })),
164
+ suffixIcon = _getIcons.suffixIcon,
165
+ removeIcon = _getIcons.removeIcon,
166
+ clearIcon = _getIcons.clearIcon;
167
+ // ===================== Placement =====================
168
+ var getPlacement = function getPlacement() {
169
+ if (placement !== undefined) {
170
+ return placement;
171
+ }
172
+ return isRtl ? "bottomRight" : "bottomLeft";
173
+ };
174
+ // ==================== Render =====================
175
+ return /*#__PURE__*/React.createElement(RcCascader, _extends({
176
+ prefixCls: prefixCls,
177
+ 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)
178
+ }, restProps, {
179
+ direction: mergedDirection,
180
+ placement: getPlacement(),
181
+ notFoundContent: mergedNotFoundContent,
182
+ allowClear: allowClear,
183
+ showSearch: mergedShowSearch,
184
+ expandIcon: mergedExpandIcon,
185
+ inputIcon: suffixIcon,
186
+ removeIcon: removeIcon,
187
+ clearIcon: clearIcon,
188
+ loadingIcon: loadingIcon,
189
+ checkable: checkable,
190
+ dropdownClassName: mergedDropdownClassName,
191
+ dropdownPrefixCls: customizePrefixCls || cascaderPrefixCls,
192
+ choiceTransitionName: getTransitionName(rootPrefixCls, '', choiceTransitionName),
193
+ transitionName: getTransitionName(rootPrefixCls, getTransitionDirection(placement), transitionName),
194
+ getPopupContainer: getPopupContainer || getContextPopupContainer,
195
+ ref: ref,
196
+ showArrow: hasFeedback || showArrow
197
+ }));
198
+ });
199
+ if (process.env.NODE_ENV !== "production") {
200
+ Cascader.displayName = "Cascader";
201
+ }
202
+ // We don't care debug panel
203
+ /* istanbul ignore next */
204
+ Cascader.SHOW_PARENT = SHOW_PARENT;
205
+ Cascader.SHOW_CHILD = SHOW_CHILD;
206
+ Cascader._InternalPanelDoNotUseOrYouWillBeFired = Cascader;
207
+ export default Cascader;
@@ -0,0 +1,5 @@
1
+ import Cascader from "./Cascader";
2
+ import "antd/es/cascader/style/index.less";
3
+ import "../Antd4/cascader/style/index.less";
4
+ import "./index.less";
5
+ export default Cascader;
@@ -0,0 +1,9 @@
1
+ @import '../Cascader/index.less';
2
+
3
+ .cw-cascader-custom-dropdown.@{ant-prefix}-select-dropdown {
4
+ overflow: visible !important;
5
+ padding: 0 !important;
6
+ // .@{ant-prefix}-cascader-menu {
7
+ // max-height: 200px !important;
8
+ // }
9
+ }
@@ -0,0 +1,329 @@
1
+ var _excluded = ["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", "dropdownColumnRender"];
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
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
4
+ 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."); }
5
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
6
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
7
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
8
+ 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."); }
9
+ 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); }
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
+ 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; } }
12
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
13
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
14
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
15
+ import { BaseSelect } from "rc-cascader/node_modules/rc-select";
16
+ import useId from "rc-cascader/node_modules/rc-select/lib/hooks/useId";
17
+ import { conductCheck } from "rc-cascader/node_modules/rc-tree/lib/utils/conductUtil";
18
+ import useMergedState from "rc-util/lib/hooks/useMergedState";
19
+ import * as React from "react";
20
+ import CascaderContext from "./context";
21
+ import useDisplayValues from "./hooks/useDisplayValues";
22
+ import useEntities from "./hooks/useEntities";
23
+ import useMissingValues from "./hooks/useMissingValues";
24
+ import useRefFunc from "./hooks/useRefFunc";
25
+ import useSearchConfig from "./hooks/useSearchConfig";
26
+ import useSearchOptions from "./hooks/useSearchOptions";
27
+ import OptionList from "./OptionList";
28
+ import { fillFieldNames, SHOW_CHILD, SHOW_PARENT, toPathKey, toPathKeys } from "./utils/commonUtil";
29
+ import { formatStrategyValues, toPathOptions } from "./utils/treeUtil";
30
+ import warningProps, { warningNullOptions } from "./utils/warningPropsUtil";
31
+ function isMultipleValue(value) {
32
+ return Array.isArray(value) && Array.isArray(value[0]);
33
+ }
34
+ function toRawValues(value) {
35
+ if (!value) {
36
+ return [];
37
+ }
38
+ if (isMultipleValue(value)) {
39
+ return value;
40
+ }
41
+ return (value.length === 0 ? [] : [value]).map(function (val) {
42
+ return Array.isArray(val) ? val : [val];
43
+ });
44
+ }
45
+ var Cascader = /*#__PURE__*/React.forwardRef(function (props, ref) {
46
+ var id = props.id,
47
+ _props$prefixCls = props.prefixCls,
48
+ prefixCls = _props$prefixCls === void 0 ? "rc-cascader" : _props$prefixCls,
49
+ fieldNames = props.fieldNames,
50
+ defaultValue = props.defaultValue,
51
+ value = props.value,
52
+ changeOnSelect = props.changeOnSelect,
53
+ onChange = props.onChange,
54
+ displayRender = props.displayRender,
55
+ checkable = props.checkable,
56
+ searchValue = props.searchValue,
57
+ onSearch = props.onSearch,
58
+ showSearch = props.showSearch,
59
+ expandTrigger = props.expandTrigger,
60
+ options = props.options,
61
+ dropdownPrefixCls = props.dropdownPrefixCls,
62
+ loadData = props.loadData,
63
+ popupVisible = props.popupVisible,
64
+ open = props.open,
65
+ popupClassName = props.popupClassName,
66
+ dropdownClassName = props.dropdownClassName,
67
+ dropdownMenuColumnStyle = props.dropdownMenuColumnStyle,
68
+ popupPlacement = props.popupPlacement,
69
+ placement = props.placement,
70
+ onDropdownVisibleChange = props.onDropdownVisibleChange,
71
+ onPopupVisibleChange = props.onPopupVisibleChange,
72
+ _props$expandIcon = props.expandIcon,
73
+ expandIcon = _props$expandIcon === void 0 ? ">" : _props$expandIcon,
74
+ loadingIcon = props.loadingIcon,
75
+ children = props.children,
76
+ _props$dropdownMatchS = props.dropdownMatchSelectWidth,
77
+ dropdownMatchSelectWidth = _props$dropdownMatchS === void 0 ? false : _props$dropdownMatchS,
78
+ _props$showCheckedStr = props.showCheckedStrategy,
79
+ showCheckedStrategy = _props$showCheckedStr === void 0 ? SHOW_PARENT : _props$showCheckedStr,
80
+ onScroll = props.onScroll,
81
+ onSrollBottom = props.onSrollBottom,
82
+ showColumnSearch = props.showColumnSearch,
83
+ onInputChange = props.onInputChange,
84
+ dropdownColumnRender = props.dropdownColumnRender,
85
+ restProps = _objectWithoutProperties(props, _excluded);
86
+ var mergedId = useId(id);
87
+ var multiple = !!checkable;
88
+ // =========================== Values ===========================
89
+ var _useMergedState = useMergedState(defaultValue, {
90
+ value: value,
91
+ postState: toRawValues
92
+ }),
93
+ _useMergedState2 = _slicedToArray(_useMergedState, 2),
94
+ rawValues = _useMergedState2[0],
95
+ setRawValues = _useMergedState2[1];
96
+ // ========================= FieldNames =========================
97
+ var mergedFieldNames = React.useMemo(function () {
98
+ return fillFieldNames(fieldNames);
99
+ }, /* eslint-disable react-hooks/exhaustive-deps */
100
+ [JSON.stringify(fieldNames)]);
101
+ // =========================== Option ===========================
102
+ var mergedOptions = React.useMemo(function () {
103
+ return options || [];
104
+ }, [options]);
105
+ // Only used in multiple mode, this fn will not call in single mode
106
+ var getPathKeyEntities = useEntities(mergedOptions, mergedFieldNames);
107
+ /** Convert path key back to value format */
108
+ var getValueByKeyPath = React.useCallback(function (pathKeys) {
109
+ var keyPathEntities = getPathKeyEntities();
110
+ return pathKeys.map(function (pathKey) {
111
+ var nodes = keyPathEntities[pathKey].nodes;
112
+ return nodes.map(function (node) {
113
+ return node[mergedFieldNames.value];
114
+ });
115
+ });
116
+ }, [getPathKeyEntities, mergedFieldNames]);
117
+ // =========================== Search ===========================
118
+ var _useMergedState3 = useMergedState("", {
119
+ value: searchValue,
120
+ postState: function postState(search) {
121
+ return search || "";
122
+ }
123
+ }),
124
+ _useMergedState4 = _slicedToArray(_useMergedState3, 2),
125
+ mergedSearchValue = _useMergedState4[0],
126
+ setSearchValue = _useMergedState4[1];
127
+ var onInternalSearch = function onInternalSearch(searchText, info) {
128
+ setSearchValue(searchText);
129
+ if (info.source !== "blur" && onSearch) {
130
+ onSearch(searchText);
131
+ }
132
+ };
133
+ var _useSearchConfig = useSearchConfig(showSearch),
134
+ _useSearchConfig2 = _slicedToArray(_useSearchConfig, 2),
135
+ mergedShowSearch = _useSearchConfig2[0],
136
+ searchConfig = _useSearchConfig2[1];
137
+ var searchOptions = useSearchOptions(mergedSearchValue, mergedOptions, mergedFieldNames, dropdownPrefixCls || prefixCls, searchConfig, changeOnSelect);
138
+ // =========================== Values ===========================
139
+ var getMissingValues = useMissingValues(mergedOptions, mergedFieldNames);
140
+ // Fill `rawValues` with checked conduction values
141
+ var _React$useMemo = React.useMemo(function () {
142
+ var _getMissingValues = getMissingValues(rawValues),
143
+ _getMissingValues2 = _slicedToArray(_getMissingValues, 2),
144
+ existValues = _getMissingValues2[0],
145
+ missingValues = _getMissingValues2[1];
146
+ if (!multiple || !rawValues.length) {
147
+ return [existValues, [], missingValues];
148
+ }
149
+ var keyPathValues = toPathKeys(existValues);
150
+ var keyPathEntities = getPathKeyEntities();
151
+ var _conductCheck = conductCheck(keyPathValues, true, keyPathEntities),
152
+ checkedKeys = _conductCheck.checkedKeys,
153
+ halfCheckedKeys = _conductCheck.halfCheckedKeys;
154
+ // Convert key back to value cells
155
+ return [getValueByKeyPath(checkedKeys), getValueByKeyPath(halfCheckedKeys), missingValues];
156
+ }, [multiple, rawValues, getPathKeyEntities, getValueByKeyPath, getMissingValues]),
157
+ _React$useMemo2 = _slicedToArray(_React$useMemo, 3),
158
+ checkedValues = _React$useMemo2[0],
159
+ halfCheckedValues = _React$useMemo2[1],
160
+ missingCheckedValues = _React$useMemo2[2];
161
+ var deDuplicatedValues = React.useMemo(function () {
162
+ var checkedKeys = toPathKeys(checkedValues);
163
+ var deduplicateKeys = formatStrategyValues(checkedKeys, getPathKeyEntities, showCheckedStrategy);
164
+ return [].concat(_toConsumableArray(missingCheckedValues), _toConsumableArray(getValueByKeyPath(deduplicateKeys)));
165
+ }, [checkedValues, getPathKeyEntities, getValueByKeyPath, missingCheckedValues, showCheckedStrategy]);
166
+ var displayValues = useDisplayValues(deDuplicatedValues, mergedOptions, mergedFieldNames, multiple, displayRender);
167
+ // =========================== Change ===========================
168
+ var triggerChange = useRefFunc(function (nextValues) {
169
+ setRawValues(nextValues);
170
+ // Save perf if no need trigger event
171
+ if (onChange) {
172
+ var nextRawValues = toRawValues(nextValues);
173
+ var valueOptions = nextRawValues.map(function (valueCells) {
174
+ return toPathOptions(valueCells, mergedOptions, mergedFieldNames).map(function (valueOpt) {
175
+ return valueOpt.option;
176
+ });
177
+ });
178
+ var triggerValues = multiple ? nextRawValues : nextRawValues[0];
179
+ var triggerOptions = multiple ? valueOptions : valueOptions[0];
180
+ onChange(triggerValues, triggerOptions);
181
+ }
182
+ });
183
+ // =========================== Select ===========================
184
+ var onInternalSelect = useRefFunc(function (valuePath) {
185
+ setSearchValue("");
186
+ if (!multiple) {
187
+ triggerChange(valuePath);
188
+ } else {
189
+ // Prepare conduct required info
190
+ var pathKey = toPathKey(valuePath);
191
+ var checkedPathKeys = toPathKeys(checkedValues);
192
+ var halfCheckedPathKeys = toPathKeys(halfCheckedValues);
193
+ var existInChecked = checkedPathKeys.includes(pathKey);
194
+ var existInMissing = missingCheckedValues.some(function (valueCells) {
195
+ return toPathKey(valueCells) === pathKey;
196
+ });
197
+ // Do update
198
+ var nextCheckedValues = checkedValues;
199
+ var nextMissingValues = missingCheckedValues;
200
+ if (existInMissing && !existInChecked) {
201
+ // Missing value only do filter
202
+ nextMissingValues = missingCheckedValues.filter(function (valueCells) {
203
+ return toPathKey(valueCells) !== pathKey;
204
+ });
205
+ } else {
206
+ // Update checked key first
207
+ var nextRawCheckedKeys = existInChecked ? checkedPathKeys.filter(function (key) {
208
+ return key !== pathKey;
209
+ }) : [].concat(_toConsumableArray(checkedPathKeys), [pathKey]);
210
+ var pathKeyEntities = getPathKeyEntities();
211
+ // Conduction by selected or not
212
+ var checkedKeys;
213
+ if (existInChecked) {
214
+ var _conductCheck2 = conductCheck(nextRawCheckedKeys, {
215
+ checked: false,
216
+ halfCheckedKeys: halfCheckedPathKeys
217
+ }, pathKeyEntities);
218
+ checkedKeys = _conductCheck2.checkedKeys;
219
+ } else {
220
+ var _conductCheck3 = conductCheck(nextRawCheckedKeys, true, pathKeyEntities);
221
+ checkedKeys = _conductCheck3.checkedKeys;
222
+ }
223
+ // Roll up to parent level keys
224
+ var deDuplicatedKeys = formatStrategyValues(checkedKeys, getPathKeyEntities, showCheckedStrategy);
225
+ nextCheckedValues = getValueByKeyPath(deDuplicatedKeys);
226
+ }
227
+ triggerChange([].concat(_toConsumableArray(nextMissingValues), _toConsumableArray(nextCheckedValues)));
228
+ }
229
+ });
230
+ // Display Value change logic
231
+ var onDisplayValuesChange = function onDisplayValuesChange(_, info) {
232
+ if (info.type === "clear") {
233
+ triggerChange([]);
234
+ return;
235
+ }
236
+ // Cascader do not support `add` type. Only support `remove`
237
+ var valueCells = info.values[0].valueCells;
238
+ onInternalSelect(valueCells);
239
+ };
240
+ // ============================ Open ============================
241
+ var mergedOpen = open !== undefined ? open : popupVisible;
242
+ var mergedDropdownClassName = dropdownClassName || popupClassName;
243
+ var mergedPlacement = placement || popupPlacement;
244
+ var onInternalDropdownVisibleChange = function onInternalDropdownVisibleChange(nextVisible) {
245
+ onDropdownVisibleChange === null || onDropdownVisibleChange === void 0 ? void 0 : onDropdownVisibleChange(nextVisible);
246
+ onPopupVisibleChange === null || onPopupVisibleChange === void 0 ? void 0 : onPopupVisibleChange(nextVisible);
247
+ };
248
+ // ========================== Warning ===========================
249
+ if (process.env.NODE_ENV !== "production") {
250
+ warningProps(props);
251
+ warningNullOptions(mergedOptions, mergedFieldNames);
252
+ }
253
+ // ========================== Context ===========================
254
+ var cascaderContext = React.useMemo(function () {
255
+ return {
256
+ options: mergedOptions,
257
+ fieldNames: mergedFieldNames,
258
+ values: checkedValues,
259
+ halfValues: halfCheckedValues,
260
+ changeOnSelect: changeOnSelect,
261
+ onSelect: onInternalSelect,
262
+ checkable: checkable,
263
+ searchOptions: searchOptions,
264
+ dropdownPrefixCls: dropdownPrefixCls,
265
+ loadData: loadData,
266
+ expandTrigger: expandTrigger,
267
+ expandIcon: expandIcon,
268
+ loadingIcon: loadingIcon,
269
+ dropdownMenuColumnStyle: dropdownMenuColumnStyle,
270
+ onScroll: onScroll,
271
+ onSrollBottom: onSrollBottom,
272
+ showColumnSearch: showColumnSearch,
273
+ onInputChange: onInputChange,
274
+ dropdownColumnRender: dropdownColumnRender
275
+ };
276
+ }, [mergedOptions, mergedFieldNames, checkedValues, halfCheckedValues, changeOnSelect, onInternalSelect, checkable, searchOptions, dropdownPrefixCls, loadData, expandTrigger, expandIcon, loadingIcon, dropdownMenuColumnStyle, onScroll, onSrollBottom, showColumnSearch, onInputChange, dropdownColumnRender]);
277
+ // ==============================================================
278
+ // == Render ==
279
+ // ==============================================================
280
+ var emptyOptions = !(mergedSearchValue ? searchOptions : mergedOptions).length;
281
+ var dropdownStyle =
282
+ // Search to match width
283
+ mergedSearchValue && searchConfig.matchInputWidth ||
284
+ // Empty keep the width
285
+ emptyOptions ? {} : {
286
+ minWidth: "auto"
287
+ };
288
+ return /*#__PURE__*/React.createElement(CascaderContext.Provider, {
289
+ value: cascaderContext
290
+ }, /*#__PURE__*/React.createElement(BaseSelect, _extends({}, restProps, {
291
+ // MISC
292
+ ref: ref,
293
+ id: mergedId,
294
+ prefixCls: prefixCls,
295
+ dropdownMatchSelectWidth: dropdownMatchSelectWidth,
296
+ dropdownStyle: dropdownStyle
297
+ // Value
298
+ ,
299
+ displayValues: displayValues,
300
+ onDisplayValuesChange: onDisplayValuesChange,
301
+ mode: multiple ? "multiple" : undefined
302
+ // Search
303
+ ,
304
+ searchValue: mergedSearchValue,
305
+ onSearch: onInternalSearch,
306
+ showSearch: showColumnSearch ? false : mergedShowSearch // 列搜索开启时,关闭showSearch
307
+ // Options
308
+ ,
309
+ OptionList: OptionList,
310
+ emptyOptions: emptyOptions
311
+ // Open
312
+ ,
313
+ open: mergedOpen,
314
+ dropdownClassName: mergedDropdownClassName,
315
+ placement: mergedPlacement,
316
+ onDropdownVisibleChange: onInternalDropdownVisibleChange
317
+ // Children
318
+ ,
319
+ getRawInputElement: function getRawInputElement() {
320
+ return children;
321
+ }
322
+ })));
323
+ });
324
+ if (process.env.NODE_ENV !== "production") {
325
+ Cascader.displayName = "Cascader";
326
+ }
327
+ Cascader.SHOW_PARENT = SHOW_PARENT;
328
+ Cascader.SHOW_CHILD = SHOW_CHILD;
329
+ export default Cascader;