@nutui/nutui-react 2.0.0-alpha.5 → 2.0.0-alpha.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ # v2.0.0-alpha.6
2
+ `2023-05-12`
3
+
4
+ * 🛠 refactor: cascader (#993) @xiaoyatong
5
+ * 🛠 refactor: picker (#975) @xiaoyatong
6
+ * 🛠 refactor: table (#982) @xiaoyatong
7
+ * 🛠 refactor: TextArea (#979) @Eiinu
8
+ * :bug: fix: image src 初始状态未空,导致出发加载失败事件 (#988) @oasis-cloud
9
+ * 📖 docs(progress): demo 代码更新 (#986) @Eiinu
10
+ * 📖 docs(progress): update demo (#987) @Eiinu
11
+ * 📖 docs: tabs 文档中的 titleNode 修改为 title (#995) @oasis-cloud
12
+ * 🔨 chore: taro es 构建移入 vite 配置文件 (#990) @oasis-cloud
13
+
14
+
1
15
  # v2.0.0-alpha.5
2
16
  `2023-05-10`
3
17
 
@@ -47,14 +47,11 @@ import React__default, { isValidElement, useState, useEffect } from "react";
47
47
  import classNames from "classnames";
48
48
  import Popup from "./Popup.js";
49
49
  import { T as Tabs } from "./tabs2.js";
50
- import { T as TabPane } from "./tabpane2.js";
51
50
  import { Loading, Checklist } from "@nutui/icons-react";
52
- import { c as cn } from "./bem.js";
53
- import "./typings.js";
51
+ import { C as ComponentDefaults } from "./typings.js";
54
52
  import "./TabPane.js";
55
53
  import "./raf.js";
56
54
  import "./use-props-value.js";
57
- import "@bem-react/classname";
58
55
  var defaultProps$1 = {
59
56
  data: {
60
57
  text: "",
@@ -66,25 +63,25 @@ var defaultProps$1 = {
66
63
  },
67
64
  activeColor: "",
68
65
  checked: false,
69
- checkedIcon: "checklist",
66
+ activeIcon: "checklist",
70
67
  chooseItem: function chooseItem() {
71
68
  }
72
69
  };
73
70
  var InternalCascaderItem = function InternalCascaderItem2(props, ref) {
74
- var _defaultProps$1$props = _objectSpread(_objectSpread({}, defaultProps$1), props), data = _defaultProps$1$props.data, checked = _defaultProps$1$props.checked, checkedIcon = _defaultProps$1$props.checkedIcon, chooseItem2 = _defaultProps$1$props.chooseItem, activeColor = _defaultProps$1$props.activeColor;
75
- var b = cn("cascader-item");
71
+ var _defaultProps$1$props = _objectSpread(_objectSpread({}, defaultProps$1), props), data = _defaultProps$1$props.data, checked = _defaultProps$1$props.checked, activeIcon = _defaultProps$1$props.activeIcon, chooseItem2 = _defaultProps$1$props.chooseItem, activeColor = _defaultProps$1$props.activeColor;
72
+ var classPrefix = "nut-cascader-item";
76
73
  var classes = classNames({
77
74
  active: checked,
78
75
  disabled: data.disabled
79
- }, b(""));
80
- var classesTitle = classNames(_defineProperty({}, "".concat(b(""), "__title"), true));
76
+ }, classPrefix);
77
+ var classesTitle = classNames(_defineProperty({}, "".concat(classPrefix, "__title"), true));
81
78
  var renderIcon = function renderIcon2() {
82
79
  if (checked) {
83
- if (isValidElement(checkedIcon)) {
84
- return checkedIcon;
80
+ if (isValidElement(activeIcon)) {
81
+ return activeIcon;
85
82
  }
86
83
  return React__default.createElement(Checklist, {
87
- className: "".concat(checked ? b("icon-check") : "")
84
+ className: "".concat(checked ? "".concat(classPrefix, "__icon-check") : "")
88
85
  });
89
86
  }
90
87
  return null;
@@ -244,26 +241,25 @@ var Tree = /* @__PURE__ */ function() {
244
241
  return Tree2;
245
242
  }();
246
243
  var Tree$1 = Tree;
247
- var defaultProps = _objectSpread({
248
- className: "",
249
- style: {},
244
+ var defaultProps = _objectSpread(_objectSpread({}, ComponentDefaults), {}, {
250
245
  activeColor: "",
251
- checkedIcon: "checklist",
252
- tabsColor: "",
253
- poppable: true,
246
+ activeIcon: "checklist",
247
+ popup: true,
254
248
  visible: false,
255
249
  options: [],
256
250
  value: [],
257
251
  title: "",
258
- textKey: "text",
259
- valueKey: "value",
260
- childrenKey: "children",
261
- convertConfig: {},
252
+ optionKey: {
253
+ textKey: "text",
254
+ valueKey: "value",
255
+ childrenKey: "children"
256
+ },
257
+ format: {},
262
258
  closeable: false,
263
259
  closeIconPosition: "top-right",
264
260
  closeIcon: "close",
265
261
  lazy: false,
266
- lazyLoad: function lazyLoad() {
262
+ onLoad: function onLoad() {
267
263
  },
268
264
  onClose: function onClose() {
269
265
  },
@@ -273,11 +269,11 @@ var defaultProps = _objectSpread({
273
269
  }
274
270
  }, Popup.defaultProps);
275
271
  var InternalCascader = function InternalCascader2(props, ref) {
276
- var _defaultProps$props = _objectSpread(_objectSpread({}, defaultProps), props), className = _defaultProps$props.className, style = _defaultProps$props.style, tabsColor = _defaultProps$props.tabsColor, poppable = _defaultProps$props.poppable, visible = _defaultProps$props.visible, options = _defaultProps$props.options, value = _defaultProps$props.value, title = _defaultProps$props.title, textKey = _defaultProps$props.textKey, valueKey = _defaultProps$props.valueKey, childrenKey = _defaultProps$props.childrenKey, convertConfig = _defaultProps$props.convertConfig, closeable = _defaultProps$props.closeable, closeIconPosition = _defaultProps$props.closeIconPosition, closeIcon = _defaultProps$props.closeIcon, lazy = _defaultProps$props.lazy, lazyLoad2 = _defaultProps$props.lazyLoad, onClose2 = _defaultProps$props.onClose, onChange2 = _defaultProps$props.onChange, onPathChange2 = _defaultProps$props.onPathChange;
272
+ var _defaultProps$props = _objectSpread(_objectSpread({}, defaultProps), props), className = _defaultProps$props.className, style = _defaultProps$props.style, popup = _defaultProps$props.popup, visible = _defaultProps$props.visible, options = _defaultProps$props.options, value = _defaultProps$props.value, title = _defaultProps$props.title, optionKey = _defaultProps$props.optionKey, format = _defaultProps$props.format, closeable = _defaultProps$props.closeable, closeIconPosition = _defaultProps$props.closeIconPosition, closeIcon = _defaultProps$props.closeIcon, lazy = _defaultProps$props.lazy, onLoad2 = _defaultProps$props.onLoad, onClose2 = _defaultProps$props.onClose, onChange2 = _defaultProps$props.onChange, onPathChange2 = _defaultProps$props.onPathChange;
277
273
  var _useState = useState("c1"), _useState2 = _slicedToArray(_useState, 2), tabvalue = _useState2[0], setTabvalue = _useState2[1];
278
274
  var _useState3 = useState([]), _useState4 = _slicedToArray(_useState3, 2), optionsData = _useState4[0], setOptionsData = _useState4[1];
279
275
  var isLazy = function isLazy2() {
280
- return state.configs.lazy && Boolean(state.configs.lazyLoad);
276
+ return state.configs.lazy && Boolean(state.configs.onLoad);
281
277
  };
282
278
  var _useState5 = useState({
283
279
  optionsData: [],
@@ -293,28 +289,22 @@ var InternalCascader = function InternalCascader2(props, ref) {
293
289
  currentProcessNode: [],
294
290
  configs: {
295
291
  lazy,
296
- lazyLoad: lazyLoad2,
297
- valueKey,
298
- textKey,
299
- childrenKey,
300
- convertConfig
292
+ onLoad: onLoad2,
293
+ optionKey,
294
+ format
301
295
  },
302
296
  lazyLoadMap: /* @__PURE__ */ new Map()
303
297
  }), _useState6 = _slicedToArray(_useState5, 1), state = _useState6[0];
304
- var b = cn("cascader");
305
- var classes = classNames(b(""));
306
- var classesPane = classNames(_defineProperty({}, "".concat(b(""), "-pane"), true));
298
+ var classPrefix = classNames("nut-cascader");
299
+ var classesPane = classNames(_defineProperty({}, "".concat(classPrefix, "-pane"), true));
307
300
  useEffect(function() {
308
301
  initData();
309
- }, []);
302
+ }, [options]);
310
303
  useEffect(function() {
311
304
  if (value !== state.innerValue) {
312
305
  state.innerValue = value;
313
306
  }
314
307
  }, [value]);
315
- useEffect(function() {
316
- initData();
317
- }, [options]);
318
308
  var initData = /* @__PURE__ */ function() {
319
309
  var _ref = _asyncToGenerator(/* @__PURE__ */ _regeneratorRuntime.mark(function _callee() {
320
310
  return _regeneratorRuntime.wrap(function _callee$(_context) {
@@ -322,15 +312,15 @@ var InternalCascader = function InternalCascader2(props, ref) {
322
312
  switch (_context.prev = _context.next) {
323
313
  case 0:
324
314
  state.lazyLoadMap.clear();
325
- if (convertConfig && Object.keys(convertConfig).length > 0) {
326
- state.optionsData = convertListToOptions(options, convertConfig);
315
+ if (format && Object.keys(format).length > 0) {
316
+ state.optionsData = convertListToOptions(options, format);
327
317
  } else {
328
318
  state.optionsData = options;
329
319
  }
330
320
  state.tree = new Tree$1(state.optionsData, {
331
- value: state.configs.valueKey,
332
- text: state.configs.textKey,
333
- children: state.configs.childrenKey
321
+ value: state.configs.optionKey.valueKey,
322
+ text: state.configs.optionKey.textKey,
323
+ children: state.configs.optionKey.childrenKey
334
324
  });
335
325
  if (!(isLazy() && !state.tree.nodes.length)) {
336
326
  _context.next = 6;
@@ -467,7 +457,7 @@ var InternalCascader = function InternalCascader2(props, ref) {
467
457
  }
468
458
  return _context4.abrupt("return");
469
459
  case 2:
470
- if (state.configs.lazyLoad) {
460
+ if (state.configs.onLoad) {
471
461
  _context4.next = 5;
472
462
  break;
473
463
  }
@@ -485,8 +475,8 @@ var InternalCascader = function InternalCascader2(props, ref) {
485
475
  lazyLoadPromise = state.lazyLoadMap.get(node);
486
476
  if (!lazyLoadPromise) {
487
477
  lazyLoadPromise = new Promise(function(resolve) {
488
- var _state$configs$lazyLo, _state$configs;
489
- (_state$configs$lazyLo = (_state$configs = state.configs).lazyLoad) === null || _state$configs$lazyLo === void 0 ? void 0 : _state$configs$lazyLo.call(_state$configs, node, resolve);
478
+ var _state$configs$onLoad, _state$configs;
479
+ (_state$configs$onLoad = (_state$configs = state.configs).onLoad) === null || _state$configs$onLoad === void 0 ? void 0 : _state$configs$onLoad.call(_state$configs, node, resolve);
490
480
  });
491
481
  state.lazyLoadMap.set(node, lazyLoadPromise);
492
482
  }
@@ -564,8 +554,8 @@ var InternalCascader = function InternalCascader2(props, ref) {
564
554
  selectedNode: null,
565
555
  paneKey: "c".concat(state.tabsCursor + 1)
566
556
  });
567
- setTabvalue("c".concat(state.tabsCursor + 1));
568
557
  setOptionsData(state.panes);
558
+ setTabvalue("c".concat(state.tabsCursor + 1));
569
559
  if (!type) {
570
560
  _pathNodes = state.panes.map(function(item) {
571
561
  return item.selectedNode;
@@ -604,10 +594,10 @@ var InternalCascader = function InternalCascader2(props, ref) {
604
594
  }();
605
595
  var renderItem = function renderItem2() {
606
596
  return React__default.createElement("div", {
607
- className: "".concat(classes, " ").concat(className),
597
+ className: "".concat(classPrefix, " ").concat(className),
608
598
  style
609
- }, poppable && React__default.createElement("div", {
610
- className: b("title")
599
+ }, popup && React__default.createElement("div", {
600
+ className: "nut-cascader__title"
611
601
  }, title), React__default.createElement(Tabs, {
612
602
  value: tabvalue,
613
603
  title: function title2() {
@@ -618,20 +608,17 @@ var InternalCascader = function InternalCascader2(props, ref) {
618
608
  setTabvalue(pane.paneKey);
619
609
  state.tabsCursor = index;
620
610
  },
621
- className: "nut-tabs__titles-item ".concat(tabvalue === pane.paneKey ? "active" : ""),
611
+ className: "nut-tabs__titles-item ".concat(tabvalue === pane.paneKey ? "nut-tabs__titles-item--active" : ""),
622
612
  key: pane.paneKey
623
613
  }, React__default.createElement("span", {
624
614
  className: "nut-tabs__titles-item__text"
625
615
  }, !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", {
626
- className: "nut-tabs__titles-item__line",
627
- style: {
628
- background: tabsColor
629
- }
616
+ className: "nut-tabs__titles-item__line"
630
617
  }));
631
618
  });
632
619
  }
633
620
  }, !state.initLoading && state.panes.length ? optionsData.map(function(pane) {
634
- return React__default.createElement(TabPane, {
621
+ return React__default.createElement(Tabs.TabPane, {
635
622
  key: pane.paneKey,
636
623
  value: pane.paneKey
637
624
  }, React__default.createElement("div", {
@@ -648,18 +635,19 @@ var InternalCascader = function InternalCascader2(props, ref) {
648
635
  }
649
636
  }));
650
637
  })));
651
- }) : React__default.createElement(TabPane, null, React__default.createElement("div", {
638
+ }) : React__default.createElement(Tabs.TabPane, null, React__default.createElement("div", {
652
639
  className: classesPane
653
640
  }))));
654
641
  };
655
- return React__default.createElement(React__default.Fragment, null, poppable ? React__default.createElement(Popup, {
656
- className: "cascadar-popup",
642
+ return React__default.createElement(React__default.Fragment, null, popup ? React__default.createElement(Popup, {
643
+ // className="nut-cascadar-popup"
657
644
  visible,
658
645
  position: "bottom",
659
646
  round: true,
660
647
  closeIcon,
661
648
  closeable,
662
649
  closeIconPosition,
650
+ // todo 只关闭,不处理逻辑。和popup的逻辑不一致。关闭时需要增加是否要处理回调
663
651
  onClickOverlay: closePopup,
664
652
  onClickCloseIcon: closePopup
665
653
  }, renderItem()) : renderItem());
@@ -45,7 +45,7 @@ var DatePicker = function DatePicker2(props) {
45
45
  var _useState = useState(false), _useState2 = _slicedToArray(_useState, 2), show = _useState2[0], setShow = _useState2[1];
46
46
  var _useState3 = useState(modelValue), _useState4 = _slicedToArray(_useState3, 2), currentDate = _useState4[0], setCurrentDate = _useState4[1];
47
47
  var _useState5 = useState([]), _useState6 = _slicedToArray(_useState5, 2), defaultValue = _useState6[0], setDefaultValue = _useState6[1];
48
- var _useState7 = useState([]), _useState8 = _slicedToArray(_useState7, 2), listData = _useState8[0], setListData = _useState8[1];
48
+ var _useState7 = useState([]), _useState8 = _slicedToArray(_useState7, 2), options = _useState8[0], setListData = _useState8[1];
49
49
  var pickerRef = useRef(null);
50
50
  var isDate = function isDate2(val) {
51
51
  return Object.prototype.toString.call(val) === "[object Date]" && !Number.isNaN(val.getTime());
@@ -150,7 +150,7 @@ var DatePicker = function DatePicker2(props) {
150
150
  }
151
151
  return result;
152
152
  };
153
- var updateChooseValueCustmer = function updateChooseValueCustmer2(index, selectedValue, cacheValueData) {
153
+ var updateChooseValueCustmer = function updateChooseValueCustmer2(cacheValueData, selectedValue, index) {
154
154
  if (["date", "datetime", "datehour", "month-day", "year-month"].includes(type.toLocaleLowerCase())) {
155
155
  var _date;
156
156
  var formatDate = [];
@@ -177,7 +177,7 @@ var DatePicker = function DatePicker2(props) {
177
177
  var isEqual = (currentDate === null || currentDate === void 0 ? void 0 : currentDate.getTime()) === ((_date = date) === null || _date === void 0 ? void 0 : _date.getTime());
178
178
  date && isDate(date) && !isEqual && setCurrentDate(formatValue(date));
179
179
  }
180
- props.onChange && props.onChange(index, selectedValue, cacheValueData);
180
+ props.onChange && props.onChange(cacheValueData, selectedValue, index);
181
181
  };
182
182
  var padZero = function padZero2(num) {
183
183
  var targetLength = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 2;
@@ -268,17 +268,17 @@ var DatePicker = function DatePicker2(props) {
268
268
  return React__default.createElement("div", _objectSpread({
269
269
  className: "nut-datepicker ".concat(className || ""),
270
270
  style
271
- }, rest), listData.length > 0 && React__default.createElement(Picker, {
271
+ }, rest), options.length > 0 && React__default.createElement(Picker, {
272
272
  title,
273
273
  visible: show,
274
- listData,
274
+ options,
275
275
  onClose: onCloseDatePicker,
276
- defaultValueData: defaultValue,
277
- onConfirm: function onConfirm(values, options) {
278
- return onConfirmDatePicker && onConfirmDatePicker(values, options);
276
+ defaultValue,
277
+ onConfirm: function onConfirm(options2, values) {
278
+ return onConfirmDatePicker && onConfirmDatePicker(options2, values);
279
279
  },
280
- onChange: function onChange2(index, value, list) {
281
- return updateChooseValueCustmer(index, value, list);
280
+ onChange: function onChange2(list, value, index) {
281
+ return updateChooseValueCustmer(list, value, index);
282
282
  },
283
283
  threeDimensional,
284
284
  ref: pickerRef
package/dist/esm/Image.js CHANGED
@@ -41,18 +41,16 @@ var Image = function Image2(props) {
41
41
  var _defaultProps$props = _objectSpread(_objectSpread({}, defaultProps), props), className = _defaultProps$props.className, style = _defaultProps$props.style, src = _defaultProps$props.src, fit = _defaultProps$props.fit, position = _defaultProps$props.position, alt = _defaultProps$props.alt, width = _defaultProps$props.width, height = _defaultProps$props.height, radius = _defaultProps$props.radius, error = _defaultProps$props.error, loading = _defaultProps$props.loading, lazy = _defaultProps$props.lazy, onClick = _defaultProps$props.onClick, onLoad = _defaultProps$props.onLoad, onError = _defaultProps$props.onError;
42
42
  var _useState = useState(true), _useState2 = _slicedToArray(_useState, 2), innerLoading = _useState2[0], setInnerLoading = _useState2[1];
43
43
  var _useState3 = useState(false), _useState4 = _slicedToArray(_useState3, 2), isError = _useState4[0], setIsError = _useState4[1];
44
- var _useState5 = useState(""), _useState6 = _slicedToArray(_useState5, 2), _src = _useState6[0], setSrc = _useState6[1];
45
44
  var imgRef = useRef(null);
46
45
  useEffect(function() {
47
46
  if (imgRef.current && imgRef.current.complete && imgRef.current.naturalHeight !== 0) {
48
47
  setInnerLoading(false);
49
48
  } else if (src) {
50
- setSrc(src);
51
- setIsError(false);
52
49
  setInnerLoading(true);
53
50
  }
54
51
  }, [src]);
55
52
  var handleLoad = function handleLoad2() {
53
+ setIsError(false);
56
54
  setInnerLoading(false);
57
55
  onLoad && onLoad();
58
56
  };
@@ -149,7 +147,7 @@ var Image = function Image2(props) {
149
147
  ref: imgRef,
150
148
  className: "nut-img lazyload",
151
149
  style: imgStyle,
152
- "data-src": _src,
150
+ "data-src": src,
153
151
  alt,
154
152
  loading: "lazy",
155
153
  onLoad: handleLoad,
@@ -158,7 +156,7 @@ var Image = function Image2(props) {
158
156
  ref: imgRef,
159
157
  className: "nut-img",
160
158
  style: imgStyle,
161
- src: _src,
159
+ src,
162
160
  alt,
163
161
  onLoad: handleLoad,
164
162
  onError: handleError