@nutui/nutui-react-taro 1.4.4 → 1.4.5

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 (219) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/esm/Address.js +5 -5
  3. package/dist/esm/Audio.js +5 -5
  4. package/dist/esm/AvatarContext-7153ad2b.js +3 -1
  5. package/dist/esm/AvatarGroup.js +4 -4
  6. package/dist/esm/Calendar.js +5 -5
  7. package/dist/esm/CalendarItem.js +4 -4
  8. package/dist/esm/Card.js +4 -3
  9. package/dist/esm/Cell.js +2 -2
  10. package/dist/esm/ConfigProvider.js +3 -3
  11. package/dist/esm/CountDown.js +4 -4
  12. package/dist/esm/DatePicker.js +5 -5
  13. package/dist/esm/Dialog.js +4 -4
  14. package/dist/esm/Ellipsis.js +4 -4
  15. package/dist/esm/Empty.js +4 -4
  16. package/dist/esm/FixedNav.js +4 -4
  17. package/dist/esm/Form.js +4 -4
  18. package/dist/esm/FormItem.js +3 -3
  19. package/dist/esm/Grid.js +4 -4
  20. package/dist/esm/GridItem.js +4 -4
  21. package/dist/esm/Image.js +4 -4
  22. package/dist/esm/Infiniteloading.js +4 -4
  23. package/dist/esm/Input.js +4 -4
  24. package/dist/esm/MenuItem.js +4 -4
  25. package/dist/esm/NoticeBar.js +2 -2
  26. package/dist/esm/NumberKeyboard.js +4 -4
  27. package/dist/esm/Pagination.js +4 -4
  28. package/dist/esm/Picker.js +4 -4
  29. package/dist/esm/PullToRefresh.js +4 -4
  30. package/dist/esm/Range.js +4 -4
  31. package/dist/esm/SearchBar.js +4 -4
  32. package/dist/esm/ShortPassword.js +4 -4
  33. package/dist/esm/SideNavBar.js +4 -4
  34. package/dist/esm/Signature.js +4 -4
  35. package/dist/esm/Sticky.js +4 -4
  36. package/dist/esm/Table.js +4 -4
  37. package/dist/esm/Tag.js +3 -2
  38. package/dist/esm/TextArea.js +4 -4
  39. package/dist/esm/TimeDetail.js +4 -4
  40. package/dist/esm/TimePannel.js +4 -4
  41. package/dist/esm/TimeSelect.js +6 -6
  42. package/dist/esm/Uploader.js +4 -4
  43. package/dist/esm/UserContext-68f62e66.js +3 -1
  44. package/dist/esm/UserContext-b4181162.js +3 -1
  45. package/dist/esm/UserContext-be8097d2.js +3 -1
  46. package/dist/esm/VirtualList.js +6 -4
  47. package/dist/esm/WaterMark.js +4 -4
  48. package/dist/esm/actionsheet.taro-a58d3d12.js +45 -83
  49. package/dist/esm/address.taro-79cc7c96.js +461 -0
  50. package/dist/esm/animate.taro-b0e83dd5.js +32 -46
  51. package/dist/esm/animatingnumbers.taro-6f40a2e9.js +93 -134
  52. package/dist/esm/audio.taro-4fadc583.js +161 -0
  53. package/dist/esm/avatar.taro-85ced995.js +93 -119
  54. package/dist/esm/avatargroup-1d900174.js +34 -0
  55. package/dist/esm/backtop.taro-99107c30.js +39 -62
  56. package/dist/esm/badge.taro-fe9171ec.js +40 -58
  57. package/dist/esm/barrage.taro-0e157b5e.js +61 -91
  58. package/dist/esm/bem-893ad28d.js +3 -6
  59. package/dist/esm/button.taro-4ce133b9.js +87 -98
  60. package/dist/esm/calendar.taro-4ed72058.js +38 -0
  61. package/dist/esm/calendaritem.taro-1ebe428d.js +571 -0
  62. package/dist/esm/card.taro-39055e82.js +32 -0
  63. package/dist/esm/cascader.taro-d8cb1c3e.js +397 -636
  64. package/dist/esm/cell.taro-9a04a92e.js +64 -0
  65. package/dist/esm/cellgroup.taro-e094471c.js +18 -27
  66. package/dist/esm/checkbox.taro-0bda9796.js +160 -232
  67. package/dist/esm/circleprogress.taro-47db537c.js +99 -120
  68. package/dist/esm/col.taro-b61c7cba.js +33 -50
  69. package/dist/esm/collapse.taro-af58206c.js +73 -86
  70. package/dist/esm/collapseitem-ce1849d2.js +75 -139
  71. package/dist/esm/configprovider-5eea4f5d.js +19 -0
  72. package/dist/esm/configprovider.taro-26882dd2.js +42 -0
  73. package/dist/esm/countdown.taro-9e40de9c.js +225 -0
  74. package/dist/esm/datepicker.taro-7220e495.js +270 -0
  75. package/dist/esm/dialog.taro-1c03960e.js +123 -0
  76. package/dist/esm/divider.taro-5236fe6a.js +27 -27
  77. package/dist/esm/drag.taro-82b6b27a.js +99 -138
  78. package/dist/esm/elevator.taro-d7d65470.js +185 -259
  79. package/dist/esm/ellipsis.taro-49b6db0c.js +232 -0
  80. package/dist/esm/empty.taro-7bd813f9.js +62 -0
  81. package/dist/esm/fixednav.taro-5ad15202.js +53 -0
  82. package/dist/esm/form.taro-71d32671.js +179 -0
  83. package/dist/esm/formitem.taro-3089489b.js +89 -0
  84. package/dist/esm/grid.taro-e6decfce.js +58 -0
  85. package/dist/esm/grid.taro.context-39636af9.js +4 -2
  86. package/dist/esm/griditem.taro-4cade72e.js +90 -0
  87. package/dist/esm/icon-8dc4de10.js +43 -51
  88. package/dist/esm/icon.taro-1d0d4fb7.js +43 -51
  89. package/dist/esm/image.taro-e6dc5867.js +64 -0
  90. package/dist/esm/imagepreview.taro-3400ea03.js +158 -205
  91. package/dist/esm/index.taro-a36f96fb.js +149 -210
  92. package/dist/esm/indicator.taro-183ea169.js +29 -43
  93. package/dist/esm/infiniteloading.taro-6c2a2e95.js +142 -0
  94. package/dist/esm/input.taro-fd566407.js +243 -0
  95. package/dist/esm/inputnumber.taro-dc39b853.js +129 -177
  96. package/dist/esm/layout.taro-358f014f.js +6 -9
  97. package/dist/esm/menu.taro-4abed328.js +89 -132
  98. package/dist/esm/menuitem.taro-6e8b27c3.js +130 -0
  99. package/dist/esm/navbar.taro-c931c078.js +69 -105
  100. package/dist/esm/noticebar.taro-69ea7673.js +450 -0
  101. package/dist/esm/notify.taro-308e5892.js +66 -97
  102. package/dist/esm/numberkeyboard.taro-194519e4.js +158 -0
  103. package/dist/esm/nutui-react.es.js +44 -44
  104. package/dist/esm/offsetContext-bfb02c25.js +3 -1
  105. package/dist/esm/overlay.taro-98367bc1.js +59 -74
  106. package/dist/esm/pagination.taro-bb490de9.js +124 -0
  107. package/dist/esm/picker.taro-2a8ded7c.js +420 -0
  108. package/dist/esm/popover.taro-46d813e8.js +132 -222
  109. package/dist/esm/popup.taro-cb777e09.js +125 -178
  110. package/dist/esm/price.taro-8801462e.js +75 -86
  111. package/dist/esm/progress.taro-623bc807.js +84 -118
  112. package/dist/esm/pulltorefresh.taro-cab7b51c.js +221 -0
  113. package/dist/esm/range.taro-5d6ff217.js +332 -0
  114. package/dist/esm/rate.taro-10197384.js +64 -111
  115. package/dist/esm/row.taro-37a895de.js +38 -42
  116. package/dist/esm/searchbar.taro-839dd622.js +148 -0
  117. package/dist/esm/shortpassword.taro-182d46f7.js +111 -0
  118. package/dist/esm/sidenavbar.taro-006cf38b.js +35 -0
  119. package/dist/esm/sidenavbaritem.taro-fee11d26.js +9 -22
  120. package/dist/esm/signature.taro-33632585.js +143 -0
  121. package/dist/esm/skeleton.taro-853ce460.js +51 -88
  122. package/dist/esm/step.taro-1c94e067.js +49 -78
  123. package/dist/esm/steps.taro-acf205a0.js +21 -30
  124. package/dist/esm/sticky.taro-d0553f48.js +13 -0
  125. package/dist/esm/subsidenavbar.taro-f46b4c73.js +58 -75
  126. package/dist/esm/swipe.taro-83bc248f.js +164 -254
  127. package/dist/esm/swiper.taro-852f6615.js +424 -505
  128. package/dist/esm/swiperitem-86a3578a.js +20 -28
  129. package/dist/esm/switch.taro-bae2dca0.js +43 -64
  130. package/dist/esm/tabbar.taro-86cece39.js +47 -57
  131. package/dist/esm/tabbaritem.taro-8dfb8055.js +51 -79
  132. package/dist/esm/table.taro-cb4dd2c3.js +92 -0
  133. package/dist/esm/tabpane.taro-91cd6cf4.js +17 -22
  134. package/dist/esm/tabs.taro-e71875fa.js +121 -165
  135. package/dist/esm/tag.taro-00fe554d.js +89 -0
  136. package/dist/esm/textarea.taro-42600f8c.js +74 -0
  137. package/dist/esm/timedetail.taro-c5f564fd.js +44 -0
  138. package/dist/esm/timepannel.taro-29f9dd86.js +22 -0
  139. package/dist/esm/timeselect.taro-3ecce65d.js +133 -0
  140. package/dist/esm/toast.taro-0804b6b4.js +99 -137
  141. package/dist/esm/trendarrow.taro-5a7153e4.js +63 -90
  142. package/dist/esm/types/src/packages/cell/cell.taro.d.ts +0 -1
  143. package/dist/esm/types/src/packages/noticebar/noticebar.d.ts +5 -4
  144. package/dist/esm/types/src/packages/noticebar/noticebar.taro.d.ts +5 -4
  145. package/dist/esm/types/src/packages/uploader/uploader.d.ts +1 -1
  146. package/dist/esm/types/src/packages/virtuallist/virtuallist.taro.d.ts +13 -2
  147. package/dist/esm/typings-1c5f2628.js +7 -6
  148. package/dist/esm/uploader.taro-f80d76d9.js +392 -0
  149. package/dist/esm/useClientRect-bf69d7b3.js +5 -25
  150. package/dist/esm/useTouch-a2ea68c6.js +63 -93
  151. package/dist/esm/video-8a3518c5.js +59 -83
  152. package/dist/esm/virtuallist.taro-e3345ced.js +215 -0
  153. package/dist/esm/watermark.taro-cd9db98a.js +114 -0
  154. package/dist/esm/zh-CN-dfc384d0.js +128 -133
  155. package/dist/locales/base.js +1 -1
  156. package/dist/locales/en-US.js +1 -1
  157. package/dist/locales/id-ID.js +1 -1
  158. package/dist/locales/zh-CN.js +1 -1
  159. package/dist/locales/zh-TW.js +1 -1
  160. package/dist/locales/zh-UG.js +1 -1
  161. package/dist/nutui.react.es.js +634 -5664
  162. package/dist/nutui.react.umd.js +634 -5664
  163. package/dist/packages/noticebar/noticebar.scss +17 -0
  164. package/dist/packages/radio/radio.scss +3 -1
  165. package/dist/packages/row/row.scss +2 -0
  166. package/dist/packages/searchbar/searchbar.scss +1 -1
  167. package/dist/packages/tag/tag.scss +13 -5
  168. package/dist/packages/virtuallist/virtuallist.scss +24 -0
  169. package/dist/style.css +1 -1
  170. package/dist/style.es.js +1 -1
  171. package/dist/styles/temp.scss +2340 -0
  172. package/dist/styles/theme-dark.scss +7 -0
  173. package/dist/styles/theme-default.scss +11 -0
  174. package/dist/styles/variables.scss +1945 -710
  175. package/dist/types/index.d.ts +16 -23
  176. package/package.json +9 -4
  177. package/dist/esm/address.taro-1e2aea24.js +0 -615
  178. package/dist/esm/audio.taro-fddcdfc0.js +0 -228
  179. package/dist/esm/avatargroup-f7f600ff.js +0 -42
  180. package/dist/esm/calendar.taro-72974415.js +0 -83
  181. package/dist/esm/calendaritem.taro-84e889eb.js +0 -580
  182. package/dist/esm/card.taro-a530dfb3.js +0 -61
  183. package/dist/esm/cell.taro-cf50c4f2.js +0 -109
  184. package/dist/esm/configprovider-c7d60e20.js +0 -18
  185. package/dist/esm/configprovider.taro-8bdb3a28.js +0 -50
  186. package/dist/esm/countdown.taro-d7dc8681.js +0 -246
  187. package/dist/esm/datepicker.taro-7199f521.js +0 -304
  188. package/dist/esm/dialog.taro-f54cfbf0.js +0 -187
  189. package/dist/esm/ellipsis.taro-c0de6ff4.js +0 -309
  190. package/dist/esm/empty.taro-dbc66496.js +0 -81
  191. package/dist/esm/fixednav.taro-9e759320.js +0 -97
  192. package/dist/esm/form.taro-880014b1.js +0 -181
  193. package/dist/esm/formitem.taro-3695f4a7.js +0 -136
  194. package/dist/esm/grid.taro-c2cc12d6.js +0 -81
  195. package/dist/esm/griditem.taro-892153cd.js +0 -122
  196. package/dist/esm/image.taro-c30973d5.js +0 -105
  197. package/dist/esm/infiniteloading.taro-b5ddf3cc.js +0 -188
  198. package/dist/esm/input.taro-104130c1.js +0 -361
  199. package/dist/esm/menuitem.taro-216e9f7d.js +0 -193
  200. package/dist/esm/noticebar.taro-94002898.js +0 -368
  201. package/dist/esm/numberkeyboard.taro-5e8f0ddf.js +0 -245
  202. package/dist/esm/pagination.taro-9925ffab.js +0 -169
  203. package/dist/esm/picker.taro-3b5cc054.js +0 -540
  204. package/dist/esm/pulltorefresh.taro-f26a20dd.js +0 -302
  205. package/dist/esm/range.taro-c41e9b90.js +0 -469
  206. package/dist/esm/searchbar.taro-01ed4ea4.js +0 -236
  207. package/dist/esm/shortpassword.taro-3a3bf412.js +0 -190
  208. package/dist/esm/sidenavbar.taro-06026f31.js +0 -66
  209. package/dist/esm/signature.taro-17648cac.js +0 -192
  210. package/dist/esm/sticky.taro-36013e97.js +0 -16
  211. package/dist/esm/table.taro-adda6622.js +0 -139
  212. package/dist/esm/tag.taro-bd900990.js +0 -104
  213. package/dist/esm/textarea.taro-83d5fe73.js +0 -102
  214. package/dist/esm/timedetail.taro-105f5380.js +0 -68
  215. package/dist/esm/timepannel.taro-c66c63dd.js +0 -30
  216. package/dist/esm/timeselect.taro-fc7ec6ee.js +0 -172
  217. package/dist/esm/uploader.taro-a1edf38f.js +0 -529
  218. package/dist/esm/virtuallist.taro-4add61c3.js +0 -315
  219. package/dist/esm/watermark.taro-323d1cf3.js +0 -132
@@ -1,15 +1,3 @@
1
- import _typeof from "@babel/runtime/helpers/typeof";
2
- import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
3
- import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
4
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
5
- import _createClass from "@babel/runtime/helpers/createClass";
6
- import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
7
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
8
- import _regeneratorRuntime from "@babel/runtime/regenerator";
9
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
10
- 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); }
11
- 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; }
12
- 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; }
13
1
  import React__default, { useEffect, useState } from 'react';
14
2
  import classNames from 'classnames';
15
3
  import { P as Popup } from './popup.taro-cb777e09.js';
@@ -17,667 +5,440 @@ import { T as Tabs } from './tabs.taro-e71875fa.js';
17
5
  import { T as TabPane } from './tabpane.taro-91cd6cf4.js';
18
6
  import { I as Icon } from './icon.taro-1d0d4fb7.js';
19
7
  import { c as cn } from './bem-893ad28d.js';
20
- var defaultProps$1 = {
21
- data: {
22
- text: '',
23
- value: '',
24
- paneKey: '',
25
- disabled: false,
26
- loading: false,
27
- children: []
28
- },
29
- activeColor: '#fa2c19',
30
- checked: false,
31
- chooseItem: function chooseItem() {}
32
- };
33
- var InternalCascaderItem = function InternalCascaderItem(props) {
34
- var _defaultProps$1$props = _objectSpread(_objectSpread({}, defaultProps$1), props),
35
- data = _defaultProps$1$props.data,
36
- checked = _defaultProps$1$props.checked,
37
- chooseItem = _defaultProps$1$props.chooseItem,
38
- activeColor = _defaultProps$1$props.activeColor;
39
- var b = cn('cascader-item');
40
- var classes = classNames({
41
- active: checked,
42
- disabled: data.disabled
43
- }, b(''));
44
- var classesTitle = classNames(_defineProperty({}, "".concat(b(''), "__title"), true));
45
- useEffect(function () {
46
- initData();
47
- }, [data]);
48
- var initData = function initData() {
49
- // console.log('------data', data)
50
- };
51
- return React__default.createElement("div", {
52
- style: {
53
- color: checked ? activeColor : ''
8
+
9
+ const defaultProps$1 = {
10
+ data: {
11
+ text: '',
12
+ value: '',
13
+ paneKey: '',
14
+ disabled: false,
15
+ loading: false,
16
+ children: [],
54
17
  },
55
- className: classes,
56
- onClick: function onClick() {
57
- chooseItem(data);
58
- }
59
- }, React__default.createElement("div", {
60
- className: classesTitle
61
- }, data.text), data.loading ? React__default.createElement(Icon, {
62
- color: "#969799",
63
- className: "nut-cascader-item__icon-loading",
64
- name: "loading"
65
- }) : React__default.createElement(Icon, {
66
- className: "".concat(checked ? b('icon-check') : ''),
67
- name: "checklist"
68
- }));
18
+ activeColor: '#fa2c19',
19
+ checked: false,
20
+ chooseItem: () => { },
21
+ };
22
+ const InternalCascaderItem = (props) => {
23
+ const { data, checked, chooseItem, activeColor } = {
24
+ ...defaultProps$1,
25
+ ...props,
26
+ };
27
+ const b = cn('cascader-item');
28
+ const classes = classNames({
29
+ active: checked,
30
+ disabled: data.disabled,
31
+ }, b(''));
32
+ const classesTitle = classNames({
33
+ [`${b('')}__title`]: true,
34
+ });
35
+ useEffect(() => {
36
+ initData();
37
+ }, [data]);
38
+ const initData = () => {
39
+ // console.log('------data', data)
40
+ };
41
+ return (React__default.createElement("div", { style: { color: checked ? activeColor : '' }, className: classes, onClick: () => {
42
+ chooseItem(data);
43
+ } },
44
+ React__default.createElement("div", { className: classesTitle }, data.text),
45
+ data.loading ? (React__default.createElement(Icon, { color: "#969799", className: "nut-cascader-item__icon-loading", name: "loading" })) : (React__default.createElement(Icon, { className: `${checked ? b('icon-check') : ''}`, name: "checklist" }))));
69
46
  };
70
- var CascaderItem = React__default.forwardRef(InternalCascaderItem);
47
+ const CascaderItem = React__default.forwardRef(InternalCascaderItem);
71
48
  CascaderItem.defaultProps = defaultProps$1;
72
49
  CascaderItem.displayName = 'NutCascaderItem';
73
- var formatTree = function formatTree(tree, parent, config) {
74
- return tree.map(function (node) {
75
- var _config$value = config.value,
76
- valueKey = _config$value === void 0 ? 'value' : _config$value,
77
- _config$text = config.text,
78
- textKey = _config$text === void 0 ? 'text' : _config$text,
79
- _config$children = config.children,
80
- childrenKey = _config$children === void 0 ? 'children' : _config$children;
81
- var value = node[valueKey],
82
- text = node[textKey],
83
- children = node[childrenKey],
84
- others = _objectWithoutProperties(node, [valueKey, textKey, childrenKey].map(_toPropertyKey));
85
- var newNode = _objectSpread(_objectSpread({
86
- loading: false
87
- }, others), {}, {
88
- level: parent ? (parent && parent.level || 0) + 1 : 0,
89
- value: value,
90
- text: text,
91
- children: children,
92
- _parent: parent
93
- });
50
+
51
+ const formatTree = (tree, parent, config) => tree.map((node) => {
52
+ const { value: valueKey = 'value', text: textKey = 'text', children: childrenKey = 'children', } = config;
53
+ const { [valueKey]: value, [textKey]: text, [childrenKey]: children, ...others } = node;
54
+ const newNode = {
55
+ loading: false,
56
+ ...others,
57
+ level: parent ? ((parent && parent.level) || 0) + 1 : 0,
58
+ value,
59
+ text,
60
+ children,
61
+ _parent: parent,
62
+ };
94
63
  if (newNode.children && newNode.children.length) {
95
- newNode.children = formatTree(newNode.children, newNode, config);
64
+ newNode.children = formatTree(newNode.children, newNode, config);
96
65
  }
97
66
  return newNode;
98
- });
99
- };
100
- var eachTree = function eachTree(tree, cb) {
101
- var i = 0;
102
- var node;
103
- while (node = tree[i++]) {
104
- if (cb(node) === true) {
105
- break;
106
- }
107
- if (node.children && node.children.length) {
108
- eachTree(node.children, cb);
67
+ });
68
+ const eachTree = (tree, cb) => {
69
+ let i = 0;
70
+ let node;
71
+ while ((node = tree[i++])) {
72
+ if (cb(node) === true) {
73
+ break;
74
+ }
75
+ if (node.children && node.children.length) {
76
+ eachTree(node.children, cb);
77
+ }
109
78
  }
110
- }
111
79
  };
112
- var defaultConvertConfig = {
113
- topId: null,
114
- idKey: 'id',
115
- pidKey: 'pid',
116
- sortKey: ''
80
+ const defaultConvertConfig = {
81
+ topId: null,
82
+ idKey: 'id',
83
+ pidKey: 'pid',
84
+ sortKey: '',
117
85
  };
118
- var convertListToOptions = function convertListToOptions(list, options) {
119
- var mergedOptions = _objectSpread(_objectSpread({}, defaultConvertConfig), options || {});
120
- var topId = mergedOptions.topId,
121
- idKey = mergedOptions.idKey,
122
- pidKey = mergedOptions.pidKey,
123
- sortKey = mergedOptions.sortKey;
124
- var result = [];
125
- var map = {};
126
- list.forEach(function (node) {
127
- node = _objectSpread({}, node);
128
- var _node = node,
129
- id = _node[idKey],
130
- pid = _node[pidKey];
131
- var children = map[pid] = map[pid] || [];
132
- // const children = map[pid] || []
133
- if (!result.length && pid === topId) {
134
- result = children;
135
- }
136
- children.push(node);
137
- node.children = map[id] || (map[id] = []);
138
- });
139
- if (sortKey) {
140
- Object.keys(map).forEach(function (i) {
141
- if (map[i].length > 1) {
142
- map[i].sort(function (a, b) {
143
- return a[sortKey] - b[sortKey];
144
- });
145
- }
86
+ const convertListToOptions = (list, options) => {
87
+ const mergedOptions = {
88
+ ...defaultConvertConfig,
89
+ ...(options || {}),
90
+ };
91
+ const { topId, idKey, pidKey, sortKey } = mergedOptions;
92
+ let result = [];
93
+ let map = {};
94
+ list.forEach((node) => {
95
+ node = { ...node };
96
+ const { [idKey]: id, [pidKey]: pid } = node;
97
+ const children = (map[pid] = map[pid] || []);
98
+ // const children = map[pid] || []
99
+ if (!result.length && pid === topId) {
100
+ result = children;
101
+ }
102
+ children.push(node);
103
+ node.children = map[id] || (map[id] = []);
146
104
  });
147
- }
148
- map = null;
149
- return result;
105
+ if (sortKey) {
106
+ Object.keys(map).forEach((i) => {
107
+ if (map[i].length > 1) {
108
+ map[i].sort((a, b) => a[sortKey] - b[sortKey]);
109
+ }
110
+ });
111
+ }
112
+ map = null;
113
+ return result;
150
114
  };
151
- var Tree = /*#__PURE__*/function () {
152
- function Tree(nodes, config) {
153
- var _this = this;
154
- _classCallCheck(this, Tree);
155
- _defineProperty(this, "nodes", void 0);
156
- _defineProperty(this, "config", void 0);
157
- _defineProperty(this, "isLeaf", function (node, lazy) {
158
- var leaf = node.leaf,
159
- children = node.children;
160
- var hasChildren = Array.isArray(children) && Boolean(children.length);
161
- return leaf || !hasChildren && !lazy;
162
- });
163
- _defineProperty(this, "hasChildren", function (node, lazy) {
164
- var isLeaf = _this.isLeaf(node, lazy);
165
- if (isLeaf) {
166
- return false;
167
- }
168
- var children = node.children;
169
- return Array.isArray(children) && Boolean(children.length);
170
- });
171
- this.config = _objectSpread({
172
- value: 'value',
173
- text: 'text',
174
- children: 'children'
175
- }, config || {});
176
- this.nodes = formatTree(nodes, null, this.config);
177
- }
178
- _createClass(Tree, [{
179
- key: "updateChildren",
180
- value: function updateChildren(nodes, parent) {
181
- if (!parent) {
115
+
116
+ class Tree {
117
+ nodes;
118
+ config;
119
+ constructor(nodes, config) {
120
+ this.config = {
121
+ value: 'value',
122
+ text: 'text',
123
+ children: 'children',
124
+ ...(config || {}),
125
+ };
182
126
  this.nodes = formatTree(nodes, null, this.config);
183
- } else {
184
- parent.children = formatTree(nodes, parent, this.config);
185
- }
186
127
  }
187
- // for test
188
- }, {
189
- key: "getNodeByValue",
190
- value: function getNodeByValue(value) {
191
- var foundNode;
192
- eachTree(this.nodes, function (node) {
193
- if (node.value === value) {
194
- foundNode = node;
195
- return true;
128
+ updateChildren(nodes, parent) {
129
+ if (!parent) {
130
+ this.nodes = formatTree(nodes, null, this.config);
196
131
  }
197
- return null;
198
- });
199
- return foundNode;
200
- }
201
- }, {
202
- key: "getPathNodesByValue",
203
- value: function getPathNodesByValue(value) {
204
- if (!value.length) {
205
- return [];
206
- }
207
- var pathNodes = [];
208
- var currentNodes = this.nodes;
209
- while (currentNodes && currentNodes.length) {
210
- var foundNode = currentNodes.find(function (node) {
211
- return node.value === value[node.level];
212
- });
213
- if (!foundNode) {
214
- break;
132
+ else {
133
+ parent.children = formatTree(nodes, parent, this.config);
215
134
  }
216
- pathNodes.push(foundNode);
217
- currentNodes = foundNode.children;
218
- }
219
- return pathNodes;
220
135
  }
221
- }]);
222
- return Tree;
223
- }();
224
- var defaultProps = _objectSpread({
225
- className: '',
226
- style: {},
227
- activeColor: '#fa2c19',
228
- tabsColor: '',
229
- poppable: true,
230
- visible: false,
231
- options: [],
232
- value: [],
233
- title: '',
234
- textKey: 'text',
235
- valueKey: 'value',
236
- childrenKey: 'children',
237
- convertConfig: {},
238
- closeable: false,
239
- closeIconPosition: 'top-right',
240
- closeIcon: 'close',
241
- lazy: false,
242
- lazyLoad: function lazyLoad() {},
243
- onClose: function onClose() {},
244
- onChange: function onChange() {},
245
- onPathChange: function onPathChange() {}
246
- }, Popup.defaultProps);
247
- var InternalCascader = function InternalCascader(props) {
248
- var _defaultProps$props = _objectSpread(_objectSpread({}, defaultProps), props),
249
- className = _defaultProps$props.className,
250
- style = _defaultProps$props.style,
251
- tabsColor = _defaultProps$props.tabsColor,
252
- poppable = _defaultProps$props.poppable,
253
- visible = _defaultProps$props.visible,
254
- options = _defaultProps$props.options,
255
- value = _defaultProps$props.value,
256
- title = _defaultProps$props.title,
257
- textKey = _defaultProps$props.textKey,
258
- valueKey = _defaultProps$props.valueKey,
259
- childrenKey = _defaultProps$props.childrenKey,
260
- convertConfig = _defaultProps$props.convertConfig,
261
- closeable = _defaultProps$props.closeable,
262
- closeIconPosition = _defaultProps$props.closeIconPosition,
263
- closeIcon = _defaultProps$props.closeIcon,
264
- lazy = _defaultProps$props.lazy,
265
- lazyLoad = _defaultProps$props.lazyLoad,
266
- onClose = _defaultProps$props.onClose,
267
- onChange = _defaultProps$props.onChange,
268
- onPathChange = _defaultProps$props.onPathChange;
269
- var _useState = useState('c1'),
270
- _useState2 = _slicedToArray(_useState, 2),
271
- tabvalue = _useState2[0],
272
- setTabvalue = _useState2[1];
273
- var _useState3 = useState([]),
274
- _useState4 = _slicedToArray(_useState3, 2),
275
- optiosData = _useState4[0],
276
- setOptiosData = _useState4[1];
277
- var isLazy = function isLazy() {
278
- return state.configs.lazy && Boolean(state.configs.lazyLoad);
279
- };
280
- var _useState5 = useState({
281
- optionsData: [],
282
- panes: [{
283
- nodes: [],
284
- selectedNode: [],
285
- paneKey: ''
286
- }],
287
- innerValue: value,
288
- tree: new Tree([], {}),
289
- tabsCursor: 0,
290
- initLoading: false,
291
- currentProcessNode: [],
292
- configs: {
293
- lazy: lazy,
294
- lazyLoad: lazyLoad,
295
- valueKey: valueKey,
296
- textKey: textKey,
297
- childrenKey: childrenKey,
298
- convertConfig: convertConfig
299
- },
300
- lazyLoadMap: new Map()
301
- }),
302
- _useState6 = _slicedToArray(_useState5, 1),
303
- state = _useState6[0];
304
- var b = cn('cascader');
305
- var classes = classNames(b(''));
306
- var classesPane = classNames(_defineProperty({}, "".concat(b(''), "-pane"), true));
307
- useEffect(function () {
308
- initData();
309
- }, []);
310
- useEffect(function () {
311
- if (value !== state.innerValue) {
312
- state.innerValue = value;
136
+ // for test
137
+ getNodeByValue(value) {
138
+ let foundNode;
139
+ eachTree(this.nodes, (node) => {
140
+ if (node.value === value) {
141
+ foundNode = node;
142
+ return true;
143
+ }
144
+ return null;
145
+ });
146
+ return foundNode;
313
147
  }
314
- }, [value]);
315
- useEffect(function () {
316
- initData();
317
- }, [options]);
318
- var initData = /*#__PURE__*/function () {
319
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
320
- return _regeneratorRuntime.wrap(function _callee$(_context) {
321
- while (1) {
322
- switch (_context.prev = _context.next) {
323
- case 0:
324
- // 初始化开始处理数据
325
- state.lazyLoadMap.clear();
326
- if (convertConfig && Object.keys(convertConfig).length > 0) {
327
- state.optionsData = convertListToOptions(options, convertConfig);
328
- } else {
329
- state.optionsData = options;
330
- }
331
- state.tree = new Tree(state.optionsData, {
332
- value: state.configs.valueKey,
333
- text: state.configs.textKey,
334
- children: state.configs.childrenKey
335
- });
336
- if (!(isLazy() && !state.tree.nodes.length)) {
337
- _context.next = 6;
148
+ getPathNodesByValue(value) {
149
+ if (!value.length) {
150
+ return [];
151
+ }
152
+ const pathNodes = [];
153
+ let currentNodes = this.nodes;
154
+ while (currentNodes && currentNodes.length) {
155
+ const foundNode = currentNodes.find((node) => node.value === value[node.level]);
156
+ if (!foundNode) {
338
157
  break;
339
- }
340
- _context.next = 6;
341
- return invokeLazyLoad({
158
+ }
159
+ pathNodes.push(foundNode);
160
+ currentNodes = foundNode.children;
161
+ }
162
+ return pathNodes;
163
+ }
164
+ isLeaf = (node, lazy) => {
165
+ const { leaf, children } = node;
166
+ const hasChildren = Array.isArray(children) && Boolean(children.length);
167
+ return leaf || (!hasChildren && !lazy);
168
+ };
169
+ hasChildren = (node, lazy) => {
170
+ const isLeaf = this.isLeaf(node, lazy);
171
+ if (isLeaf) {
172
+ return false;
173
+ }
174
+ const { children } = node;
175
+ return Array.isArray(children) && Boolean(children.length);
176
+ };
177
+ }
178
+
179
+ const defaultProps = {
180
+ className: '',
181
+ style: {},
182
+ activeColor: '#fa2c19',
183
+ tabsColor: '',
184
+ poppable: true,
185
+ visible: false,
186
+ options: [],
187
+ value: [],
188
+ title: '',
189
+ textKey: 'text',
190
+ valueKey: 'value',
191
+ childrenKey: 'children',
192
+ convertConfig: {},
193
+ closeable: false,
194
+ closeIconPosition: 'top-right',
195
+ closeIcon: 'close',
196
+ lazy: false,
197
+ lazyLoad: () => { },
198
+ onClose: () => { },
199
+ onChange: () => { },
200
+ onPathChange: () => { },
201
+ ...Popup.defaultProps,
202
+ };
203
+ const InternalCascader = (props) => {
204
+ const { className, style, tabsColor, poppable, visible, options, value, title, textKey, valueKey, childrenKey, convertConfig, closeable, closeIconPosition, closeIcon, lazy, lazyLoad, onClose, onChange, onPathChange, } = { ...defaultProps, ...props };
205
+ const [tabvalue, setTabvalue] = useState('c1');
206
+ const [optiosData, setOptiosData] = useState([]);
207
+ const isLazy = () => state.configs.lazy && Boolean(state.configs.lazyLoad);
208
+ const [state] = useState({
209
+ optionsData: [],
210
+ panes: [
211
+ {
212
+ nodes: [],
213
+ selectedNode: [],
214
+ paneKey: '',
215
+ },
216
+ ],
217
+ innerValue: value,
218
+ tree: new Tree([], {}),
219
+ tabsCursor: 0,
220
+ initLoading: false,
221
+ currentProcessNode: [],
222
+ configs: {
223
+ lazy,
224
+ lazyLoad,
225
+ valueKey,
226
+ textKey,
227
+ childrenKey,
228
+ convertConfig,
229
+ },
230
+ lazyLoadMap: new Map(),
231
+ });
232
+ const b = cn('cascader');
233
+ const classes = classNames(b(''));
234
+ const classesPane = classNames({
235
+ [`${b('')}-pane`]: true,
236
+ });
237
+ useEffect(() => {
238
+ initData();
239
+ }, []);
240
+ useEffect(() => {
241
+ if (value !== state.innerValue) {
242
+ state.innerValue = value;
243
+ }
244
+ }, [value]);
245
+ useEffect(() => {
246
+ initData();
247
+ }, [options]);
248
+ const initData = async () => {
249
+ // 初始化开始处理数据
250
+ state.lazyLoadMap.clear();
251
+ if (convertConfig && Object.keys(convertConfig).length > 0) {
252
+ state.optionsData = convertListToOptions(options, convertConfig);
253
+ }
254
+ else {
255
+ state.optionsData = options;
256
+ }
257
+ state.tree = new Tree(state.optionsData, {
258
+ value: state.configs.valueKey,
259
+ text: state.configs.textKey,
260
+ children: state.configs.childrenKey,
261
+ });
262
+ if (isLazy() && !state.tree.nodes.length) {
263
+ await invokeLazyLoad({
342
264
  root: true,
343
265
  loading: true,
344
266
  text: '',
345
- value: ''
346
- });
347
- case 6:
348
- state.panes = [{
267
+ value: '',
268
+ });
269
+ }
270
+ state.panes = [
271
+ {
349
272
  nodes: state.tree.nodes,
350
273
  selectedNode: null,
351
- paneKey: 'c1'
352
- }];
353
- syncValue();
354
- setOptiosData(state.panes);
355
- case 9:
356
- case "end":
357
- return _context.stop();
358
- }
359
- }
360
- }, _callee);
361
- }));
362
- return function initData() {
363
- return _ref.apply(this, arguments);
274
+ paneKey: 'c1',
275
+ },
276
+ ];
277
+ syncValue();
278
+ setOptiosData(state.panes);
364
279
  };
365
- }();
366
- // 处理有默认值时的数据
367
- var syncValue = /*#__PURE__*/function () {
368
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
369
- var currentValue, needToSync, parent, last, pathNodes;
370
- return _regeneratorRuntime.wrap(function _callee3$(_context3) {
371
- while (1) {
372
- switch (_context3.prev = _context3.next) {
373
- case 0:
374
- currentValue = state.innerValue;
375
- if (!(currentValue === undefined || !state.tree.nodes.length)) {
376
- _context3.next = 3;
377
- break;
378
- }
379
- return _context3.abrupt("return");
380
- case 3:
381
- if (!(currentValue.length === 0)) {
382
- _context3.next = 6;
383
- break;
384
- }
385
- state.tabsCursor = 0;
386
- // state.panes = [{ nodes: state.tree.nodes, selectedNode: null }];
387
- return _context3.abrupt("return");
388
- case 6:
389
- needToSync = currentValue;
390
- if (!(isLazy() && Array.isArray(currentValue) && currentValue.length)) {
391
- _context3.next = 19;
392
- break;
393
- }
394
- needToSync = [];
395
- parent = state.tree.nodes.find(function (node) {
396
- return node.value === currentValue[0];
397
- });
398
- if (!parent) {
399
- _context3.next = 19;
400
- break;
401
- }
402
- needToSync = [parent.value];
403
- state.initLoading = true;
404
- _context3.next = 15;
405
- return currentValue.slice(1).reduce( /*#__PURE__*/function () {
406
- var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(p, value) {
407
- var _parent$children;
408
- var parent, node;
409
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
410
- while (1) {
411
- switch (_context2.prev = _context2.next) {
412
- case 0:
413
- _context2.next = 2;
414
- return p;
415
- case 2:
416
- parent = _context2.sent;
417
- _context2.next = 5;
418
- return invokeLazyLoad(parent);
419
- case 5:
420
- node = parent === null || parent === void 0 ? void 0 : (_parent$children = parent.children) === null || _parent$children === void 0 ? void 0 : _parent$children.find(function (item) {
421
- return item.value === value;
422
- });
423
- if (node) {
424
- needToSync.push(value);
425
- }
426
- return _context2.abrupt("return", Promise.resolve(node));
427
- case 8:
428
- case "end":
429
- return _context2.stop();
430
- }
280
+ // 处理有默认值时的数据
281
+ const syncValue = async () => {
282
+ const currentValue = state.innerValue;
283
+ if (currentValue === undefined || !state.tree.nodes.length) {
284
+ return;
285
+ }
286
+ if (currentValue.length === 0) {
287
+ state.tabsCursor = 0;
288
+ // state.panes = [{ nodes: state.tree.nodes, selectedNode: null }];
289
+ return;
290
+ }
291
+ let needToSync = currentValue;
292
+ if (isLazy() && Array.isArray(currentValue) && currentValue.length) {
293
+ needToSync = [];
294
+ const parent = state.tree.nodes.find((node) => node.value === currentValue[0]);
295
+ if (parent) {
296
+ needToSync = [parent.value];
297
+ state.initLoading = true;
298
+ const last = await currentValue
299
+ .slice(1)
300
+ .reduce(async (p, value) => {
301
+ const parent = await p;
302
+ await invokeLazyLoad(parent);
303
+ const node = parent?.children?.find((item) => item.value === value);
304
+ if (node) {
305
+ needToSync.push(value);
431
306
  }
432
- }, _callee2);
433
- }));
434
- return function (_x, _x2) {
435
- return _ref3.apply(this, arguments);
436
- };
437
- }(), Promise.resolve(parent));
438
- case 15:
439
- last = _context3.sent;
440
- _context3.next = 18;
441
- return invokeLazyLoad(last);
442
- case 18:
443
- state.initLoading = false;
444
- case 19:
445
- if (needToSync.length && currentValue === value) {
446
- pathNodes = state.tree.getPathNodesByValue(needToSync);
447
- pathNodes.forEach(function (node, index) {
448
- state.tabsCursor = index;
449
- // 当有默认值时,不触发 chooseItem 里的 emit 事件
450
- _chooseItem(node, true);
451
- });
452
- }
453
- case 20:
454
- case "end":
455
- return _context3.stop();
456
- }
307
+ return Promise.resolve(node);
308
+ }, Promise.resolve(parent));
309
+ await invokeLazyLoad(last);
310
+ state.initLoading = false;
311
+ }
312
+ }
313
+ if (needToSync.length && currentValue === value) {
314
+ const pathNodes = state.tree.getPathNodesByValue(needToSync);
315
+ pathNodes.forEach((node, index) => {
316
+ state.tabsCursor = index;
317
+ // 当有默认值时,不触发 chooseItem 里的 emit 事件
318
+ chooseItem(node, true);
319
+ });
457
320
  }
458
- }, _callee3);
459
- }));
460
- return function syncValue() {
461
- return _ref2.apply(this, arguments);
462
321
  };
463
- }();
464
- var invokeLazyLoad = /*#__PURE__*/function () {
465
- var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(node) {
466
- var parent, lazyLoadPromise, nodes;
467
- return _regeneratorRuntime.wrap(function _callee4$(_context4) {
468
- while (1) {
469
- switch (_context4.prev = _context4.next) {
470
- case 0:
471
- if (node) {
472
- _context4.next = 2;
473
- break;
474
- }
475
- return _context4.abrupt("return");
476
- case 2:
477
- if (state.configs.lazyLoad) {
478
- _context4.next = 5;
479
- break;
480
- }
481
- node.leaf = true;
482
- return _context4.abrupt("return");
483
- case 5:
484
- if (!(state.tree.isLeaf(node, isLazy()) || state.tree.hasChildren(node, isLazy()))) {
485
- _context4.next = 7;
486
- break;
487
- }
488
- return _context4.abrupt("return");
489
- case 7:
490
- node.loading = true;
491
- parent = node.root ? null : node;
492
- lazyLoadPromise = state.lazyLoadMap.get(node);
493
- if (!lazyLoadPromise) {
494
- lazyLoadPromise = new Promise(function (resolve) {
495
- var _state$configs$lazyLo, _state$configs;
496
- // 外部必须resolve
497
- (_state$configs$lazyLo = (_state$configs = state.configs).lazyLoad) === null || _state$configs$lazyLo === void 0 ? void 0 : _state$configs$lazyLo.call(_state$configs, node, resolve);
498
- });
499
- state.lazyLoadMap.set(node, lazyLoadPromise);
500
- }
501
- _context4.next = 13;
502
- return lazyLoadPromise;
503
- case 13:
504
- nodes = _context4.sent;
505
- if (Array.isArray(nodes) && nodes.length > 0) {
506
- state.tree.updateChildren(nodes, parent);
507
- } else {
508
- // 如果加载完成后没有提供子节点,作为叶子节点处理
509
- node.leaf = true;
510
- }
511
- node.loading = false;
512
- state.lazyLoadMap["delete"](node);
513
- case 17:
514
- case "end":
515
- return _context4.stop();
516
- }
322
+ const invokeLazyLoad = async (node) => {
323
+ if (!node) {
324
+ return;
325
+ }
326
+ if (!state.configs.lazyLoad) {
327
+ node.leaf = true;
328
+ return;
329
+ }
330
+ if (state.tree.isLeaf(node, isLazy()) ||
331
+ state.tree.hasChildren(node, isLazy())) {
332
+ return;
333
+ }
334
+ node.loading = true;
335
+ const parent = node.root ? null : node;
336
+ let lazyLoadPromise = state.lazyLoadMap.get(node);
337
+ if (!lazyLoadPromise) {
338
+ lazyLoadPromise = new Promise((resolve) => {
339
+ // 外部必须resolve
340
+ state.configs.lazyLoad?.(node, resolve);
341
+ });
342
+ state.lazyLoadMap.set(node, lazyLoadPromise);
517
343
  }
518
- }, _callee4);
519
- }));
520
- return function invokeLazyLoad(_x3) {
521
- return _ref4.apply(this, arguments);
344
+ const nodes = await lazyLoadPromise;
345
+ if (Array.isArray(nodes) && nodes.length > 0) {
346
+ state.tree.updateChildren(nodes, parent);
347
+ }
348
+ else {
349
+ // 如果加载完成后没有提供子节点,作为叶子节点处理
350
+ node.leaf = true;
351
+ }
352
+ node.loading = false;
353
+ state.lazyLoadMap.delete(node);
522
354
  };
523
- }();
524
- var close = function close() {
525
- onClose && onClose();
526
- };
527
- var closePopup = function closePopup() {
528
- close();
529
- };
530
- /* type: 是否是静默模式,是的话不触发事件
531
- tabsCursor: tab的索引 */
532
- var _chooseItem = /*#__PURE__*/function () {
533
- var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(node, type) {
534
- var pathNodes, optionParams, level, _pathNodes, _optionParams;
535
- return _regeneratorRuntime.wrap(function _callee5$(_context5) {
536
- while (1) {
537
- switch (_context5.prev = _context5.next) {
538
- case 0:
539
- if (!(!type && node.disabled || !state.panes[state.tabsCursor])) {
540
- _context5.next = 2;
541
- break;
542
- }
543
- return _context5.abrupt("return");
544
- case 2:
545
- if (!state.tree.isLeaf(node, isLazy())) {
546
- _context5.next = 10;
547
- break;
548
- }
549
- node.leaf = true;
550
- state.panes[state.tabsCursor].selectedNode = node;
551
- state.panes = state.panes.slice(0, node.level + 1);
552
- if (!type) {
553
- pathNodes = state.panes.map(function (item) {
554
- return item.selectedNode;
555
- });
556
- optionParams = pathNodes.map(function (item) {
557
- return item.value;
558
- });
355
+ const close = () => {
356
+ onClose && onClose();
357
+ };
358
+ const closePopup = () => {
359
+ close();
360
+ };
361
+ /* type: 是否是静默模式,是的话不触发事件
362
+ tabsCursor: tab的索引 */
363
+ const chooseItem = async (node, type) => {
364
+ // console.log('chooseItem', node)
365
+ if ((!type && node.disabled) || !state.panes[state.tabsCursor]) {
366
+ return;
367
+ }
368
+ // 如果没有子节点
369
+ if (state.tree.isLeaf(node, isLazy())) {
370
+ node.leaf = true;
371
+ state.panes[state.tabsCursor].selectedNode = node;
372
+ state.panes = state.panes.slice(0, node.level + 1);
373
+ if (!type) {
374
+ const pathNodes = state.panes.map((item) => item.selectedNode);
375
+ const optionParams = pathNodes.map((item) => item.value);
559
376
  onChange(optionParams, pathNodes);
560
377
  onPathChange(optionParams, pathNodes);
561
- }
562
- setOptiosData(state.panes);
563
- close();
564
- return _context5.abrupt("return");
565
- case 10:
566
- if (!state.tree.hasChildren(node, isLazy())) {
567
- _context5.next = 20;
568
- break;
569
- }
570
- level = node.level + 1;
571
- state.panes[state.tabsCursor].selectedNode = node;
572
- state.panes = state.panes.slice(0, level);
573
- state.tabsCursor = level;
574
- state.panes.push({
378
+ }
379
+ setOptiosData(state.panes);
380
+ close();
381
+ return;
382
+ }
383
+ // 如果有子节点,滑到下一个
384
+ // if (node.children && node.children.length > 0) {
385
+ if (state.tree.hasChildren(node, isLazy())) {
386
+ const level = node.level + 1;
387
+ state.panes[state.tabsCursor].selectedNode = node;
388
+ state.panes = state.panes.slice(0, level);
389
+ state.tabsCursor = level;
390
+ state.panes.push({
575
391
  nodes: node.children || [],
576
392
  selectedNode: null,
577
- paneKey: "c".concat(state.tabsCursor + 1)
578
- });
579
- setTabvalue("c".concat(state.tabsCursor + 1));
580
- setOptiosData(state.panes);
581
- if (!type) {
582
- _pathNodes = state.panes.map(function (item) {
583
- return item.selectedNode;
584
- });
585
- _optionParams = _pathNodes.map(function (item) {
586
- return item === null || item === void 0 ? void 0 : item.value;
587
- });
588
- onPathChange(_optionParams, _pathNodes);
589
- }
590
- return _context5.abrupt("return");
591
- case 20:
592
- state.currentProcessNode = node;
593
- if (!node.loading) {
594
- _context5.next = 23;
595
- break;
596
- }
597
- return _context5.abrupt("return");
598
- case 23:
599
- _context5.next = 25;
600
- return invokeLazyLoad(node);
601
- case 25:
602
- if (state.currentProcessNode === node) {
603
- state.panes[state.tabsCursor].selectedNode = node;
604
- _chooseItem(node, type);
605
- }
606
- setOptiosData(state.panes);
607
- case 27:
608
- case "end":
609
- return _context5.stop();
610
- }
393
+ paneKey: `c${state.tabsCursor + 1}`,
394
+ });
395
+ setTabvalue(`c${state.tabsCursor + 1}`);
396
+ setOptiosData(state.panes);
397
+ if (!type) {
398
+ const pathNodes = state.panes.map((item) => item.selectedNode);
399
+ const optionParams = pathNodes.map((item) => item?.value);
400
+ onPathChange(optionParams, pathNodes);
401
+ }
402
+ return;
403
+ }
404
+ state.currentProcessNode = node;
405
+ if (node.loading) {
406
+ return;
407
+ }
408
+ await invokeLazyLoad(node);
409
+ if (state.currentProcessNode === node) {
410
+ state.panes[state.tabsCursor].selectedNode = node;
411
+ chooseItem(node, type);
611
412
  }
612
- }, _callee5);
613
- }));
614
- return function chooseItem(_x4, _x5) {
615
- return _ref5.apply(this, arguments);
413
+ setOptiosData(state.panes);
616
414
  };
617
- }();
618
- var renderItem = function renderItem() {
619
- return React__default.createElement("div", {
620
- className: "".concat(classes, " ").concat(className),
621
- style: style
622
- }, poppable && React__default.createElement("div", {
623
- className: b('title')
624
- }, title), React__default.createElement(Tabs, {
625
- value: tabvalue,
626
- titleNode: function titleNode() {
627
- return optiosData.map(function (pane, index) {
628
- var _pane$selectedNode, _pane$selectedNode2;
629
- return React__default.createElement("div", {
630
- onClick: function onClick() {
631
- setTabvalue(pane.paneKey);
632
- state.tabsCursor = index;
633
- },
634
- className: "nut-tabs__titles-item ".concat(tabvalue === pane.paneKey ? 'active' : ''),
635
- key: pane.paneKey
636
- }, React__default.createElement("span", {
637
- className: "nut-tabs__titles-item__text"
638
- }, !state.initLoading && state.panes.length && (pane === null || pane === void 0 ? void 0 : (_pane$selectedNode = pane.selectedNode) === null || _pane$selectedNode === void 0 ? void 0 : _pane$selectedNode.text), !state.initLoading && state.panes.length && !(pane !== null && pane !== void 0 && (_pane$selectedNode2 = pane.selectedNode) !== null && _pane$selectedNode2 !== void 0 && _pane$selectedNode2.text) && '请选择', !(!state.initLoading && state.panes.length) && 'Loading...'), React__default.createElement("span", {
639
- className: "nut-tabs__titles-item__line",
640
- style: {
641
- background: tabsColor
642
- }
643
- }));
644
- });
645
- }
646
- }, !state.initLoading && state.panes.length ? optiosData.map(function (pane) {
647
- return React__default.createElement(TabPane, {
648
- key: pane.paneKey,
649
- paneKey: pane.paneKey
650
- }, React__default.createElement("div", {
651
- className: classesPane
652
- }, pane.nodes && pane.nodes.map(function (node, index) {
653
- var _pane$selectedNode3;
654
- return React__default.createElement(CascaderItem, _objectSpread(_objectSpread({
655
- key: index
656
- }, props), {}, {
657
- data: node,
658
- checked: ((_pane$selectedNode3 = pane.selectedNode) === null || _pane$selectedNode3 === void 0 ? void 0 : _pane$selectedNode3.value) === node.value,
659
- chooseItem: function chooseItem(node) {
660
- return _chooseItem(node, false);
661
- }
662
- }));
663
- })));
664
- }) : React__default.createElement(TabPane, null, React__default.createElement("div", {
665
- className: classesPane
666
- }))));
667
- };
668
- return React__default.createElement(React__default.Fragment, null, poppable ? React__default.createElement(Popup, {
669
- popClass: "cascadar-popup",
670
- visible: visible,
671
- position: "bottom",
672
- round: true,
673
- closeable: closeable,
674
- closeIconPosition: closeIconPosition,
675
- closeIcon: closeIcon,
676
- onClickOverlay: closePopup,
677
- onClickCloseIcon: closePopup
678
- }, renderItem()) : renderItem());
415
+ const renderItem = () => {
416
+ return (React__default.createElement("div", { className: `${classes} ${className}`, style: style },
417
+ poppable && React__default.createElement("div", { className: b('title') }, title),
418
+ React__default.createElement(Tabs, { value: tabvalue, titleNode: () => {
419
+ return optiosData.map((pane, index) => (React__default.createElement("div", { onClick: () => {
420
+ setTabvalue(pane.paneKey);
421
+ state.tabsCursor = index;
422
+ }, className: `nut-tabs__titles-item ${tabvalue === pane.paneKey ? 'active' : ''}`, key: pane.paneKey },
423
+ React__default.createElement("span", { className: "nut-tabs__titles-item__text" },
424
+ !state.initLoading &&
425
+ state.panes.length &&
426
+ pane?.selectedNode?.text,
427
+ !state.initLoading &&
428
+ state.panes.length &&
429
+ !pane?.selectedNode?.text &&
430
+ '请选择',
431
+ !(!state.initLoading && state.panes.length) && 'Loading...'),
432
+ React__default.createElement("span", { className: "nut-tabs__titles-item__line", style: { background: tabsColor } }))));
433
+ } }, !state.initLoading && state.panes.length ? (optiosData.map((pane) => (React__default.createElement(TabPane, { key: pane.paneKey, paneKey: pane.paneKey },
434
+ React__default.createElement("div", { className: classesPane }, pane.nodes &&
435
+ pane.nodes.map((node, index) => (React__default.createElement(CascaderItem, { key: index, ...props, data: node, checked: pane.selectedNode?.value === node.value, chooseItem: (node) => chooseItem(node, false) })))))))) : (React__default.createElement(TabPane, null,
436
+ React__default.createElement("div", { className: classesPane }))))));
437
+ };
438
+ return (React__default.createElement(React__default.Fragment, null, poppable ? (React__default.createElement(Popup, { popClass: "cascadar-popup", visible: visible, position: "bottom", round: true, closeable: closeable, closeIconPosition: closeIconPosition, closeIcon: closeIcon, onClickOverlay: closePopup, onClickCloseIcon: closePopup }, renderItem())) : (renderItem())));
679
439
  };
680
- var Cascader = React__default.forwardRef(InternalCascader);
440
+ const Cascader = React__default.forwardRef(InternalCascader);
681
441
  Cascader.defaultProps = defaultProps;
682
442
  Cascader.displayName = 'NutCascader';
443
+
683
444
  export { Cascader as C };