@nutui/nutui-react 2.0.16 → 2.0.17-beta.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 (44) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/esm/Audio.js +1 -2
  3. package/dist/esm/Avatar.js +1 -1
  4. package/dist/esm/Form/style/style.css +1 -1
  5. package/dist/esm/Form.js +51 -3
  6. package/dist/esm/FormItem/style/style.css +1 -1
  7. package/dist/esm/InputNumber.js +2 -2
  8. package/dist/esm/Picker.js +4 -6
  9. package/dist/esm/Table.js +4 -4
  10. package/dist/esm/VirtualList.js +3 -4
  11. package/dist/esm/cascader2.js +3 -3
  12. package/dist/esm/formitem2.js +29 -9
  13. package/dist/esm/types/src/packages/cascader/cascader.d.ts +2 -1
  14. package/dist/esm/types/src/packages/cascader/cascader.taro.d.ts +2 -1
  15. package/dist/esm/types/src/packages/form/types.d.ts +1 -0
  16. package/dist/esm/types/src/packages/formitem/formitem.d.ts +1 -0
  17. package/dist/esm/types/src/packages/formitem/formitem.taro.d.ts +1 -0
  18. package/dist/esm/types/src/packages/table/types.d.ts +1 -1
  19. package/dist/esm/types/src/packages/toast/toast.taro.d.ts +3 -6
  20. package/dist/esm/types/src/packages/virtuallist/utils.d.ts +1 -1
  21. package/dist/esm/types/src/utils/get-rect-by-taro.d.ts +12 -0
  22. package/dist/esm/types/src/utils/use-client-rect.d.ts +3 -9
  23. package/dist/esm/types/src/utils/use-uuid.d.ts +1 -0
  24. package/dist/locales/src/locales/base.js +5 -0
  25. package/dist/locales/{en-US.js → src/locales/en-US.js} +1 -1
  26. package/dist/locales/{id-ID.js → src/locales/id-ID.js} +1 -1
  27. package/dist/locales/{tr-TR.js → src/locales/tr-TR.js} +1 -1
  28. package/dist/locales/{zh-CN.js → src/locales/zh-CN.js} +1 -1
  29. package/dist/locales/{zh-TW.js → src/locales/zh-TW.js} +1 -1
  30. package/dist/locales/{zh-UG.js → src/locales/zh-UG.js} +1 -1
  31. package/dist/nutui.react.es.js +120 -37
  32. package/dist/nutui.react.umd.js +120 -37
  33. package/dist/packages/form/form.scss +9 -1
  34. package/dist/packages/formitem/formitem.scss +0 -11
  35. package/dist/style.css +1 -1
  36. package/dist/style.mjs +1 -1
  37. package/dist/types/packages/cascader/cascader.d.ts +2 -1
  38. package/dist/types/packages/form/types.d.ts +1 -0
  39. package/dist/types/packages/formitem/formitem.d.ts +5 -0
  40. package/dist/types/packages/table/types.d.ts +1 -1
  41. package/dist/types/packages/virtuallist/utils.d.ts +1 -1
  42. package/dist/types/utils/use-client-rect.d.ts +3 -9
  43. package/package.json +1 -1
  44. package/dist/locales/base.js +0 -5
@@ -6,7 +6,7 @@ var __publicField = (obj, key, value) => {
6
6
  };
7
7
  var _a;
8
8
  /*!
9
- * @nutui/nutui-react v2.0.16 Wed Sep 06 2023 15:53:25 GMT+0800 (China Standard Time)
9
+ * @nutui/nutui-react v2.0.17 Wed Sep 13 2023 16:45:40 GMT+0800 (中国标准时间)
10
10
  * (c) 2023 @jdf2e.
11
11
  * Released under the MIT License.
12
12
  */
@@ -12742,6 +12742,7 @@ const InternalCascader = (props, ref) => {
12742
12742
  activeColor,
12743
12743
  activeIcon,
12744
12744
  popup,
12745
+ popupProps = {},
12745
12746
  visible,
12746
12747
  options: options2,
12747
12748
  value,
@@ -13037,6 +13038,7 @@ const InternalCascader = (props, ref) => {
13037
13038
  return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, popup ? /* @__PURE__ */ React__default.createElement(
13038
13039
  Popup,
13039
13040
  {
13041
+ ...popupProps,
13040
13042
  visible,
13041
13043
  position: "bottom",
13042
13044
  round: true,
@@ -14588,7 +14590,7 @@ const InternalPickerPanel = (props, ref) => {
14588
14590
  }
14589
14591
  return false;
14590
14592
  };
14591
- const setTransform = (translateY = 0, type4, time = DEFAULT_DURATION, deg) => {
14593
+ const setTransform = (type4, deg, time = DEFAULT_DURATION, translateY = 0) => {
14592
14594
  let nTime = time;
14593
14595
  if (type4 !== "end") {
14594
14596
  nTime = 0;
@@ -14608,7 +14610,7 @@ const InternalPickerPanel = (props, ref) => {
14608
14610
  }
14609
14611
  const endMove = Math.round(updateMove / lineSpacing) * lineSpacing;
14610
14612
  const deg = `${(Math.abs(Math.round(endMove / lineSpacing)) + 1) * rotation}deg`;
14611
- setTransform(endMove, type4, time, deg);
14613
+ setTransform(type4, deg, time, endMove);
14612
14614
  setCurrIndex(Math.abs(Math.round(endMove / lineSpacing)) + 1);
14613
14615
  } else {
14614
14616
  let deg = 0;
@@ -14617,7 +14619,7 @@ const InternalPickerPanel = (props, ref) => {
14617
14619
  const minDeg = 0;
14618
14620
  deg = Math.min(Math.max(currentDeg, minDeg), maxDeg);
14619
14621
  if (minDeg < deg && deg < maxDeg) {
14620
- setTransform(updateMove, "", void 0, `${deg}deg`);
14622
+ setTransform("", `${deg}deg`, void 0, updateMove);
14621
14623
  setCurrIndex(Math.abs(Math.round(updateMove / lineSpacing)) + 1);
14622
14624
  }
14623
14625
  }
@@ -14851,9 +14853,7 @@ const InternalPicker = (props, ref) => {
14851
14853
  while (columnOptions && columnOptions.children) {
14852
14854
  const options22 = columnOptions.children;
14853
14855
  const value = values[columnIndex2];
14854
- let index = options22.findIndex(
14855
- (columnItem) => columnItem.value === value
14856
- );
14856
+ let index = options22.findIndex((columnItem) => columnItem.value === value);
14857
14857
  if (index === -1)
14858
14858
  index = 0;
14859
14859
  columnOptions = columnOptions.children[index];
@@ -16405,7 +16405,7 @@ class FormStore {
16405
16405
  __publicField(this, "fieldEntities", []);
16406
16406
  // 校验成功或失败的回调,onFinish、onFinishFailed
16407
16407
  __publicField(this, "callbacks", {});
16408
- __publicField(this, "errors", []);
16408
+ __publicField(this, "errors", {});
16409
16409
  /**
16410
16410
  * 注册组件实例
16411
16411
  * @param field
@@ -16427,6 +16427,19 @@ class FormStore {
16427
16427
  var _a2;
16428
16428
  return (_a2 = this.store) == null ? void 0 : _a2[name];
16429
16429
  });
16430
+ /**
16431
+ * 获取全部字段
16432
+ */
16433
+ __publicField(this, "getFieldsValue", (name) => {
16434
+ if (typeof name === "boolean") {
16435
+ return JSON.parse(JSON.stringify(this.store));
16436
+ }
16437
+ const fieldsValue = {};
16438
+ name.forEach((field) => {
16439
+ fieldsValue[field] = this.getFieldValue(field);
16440
+ });
16441
+ return fieldsValue;
16442
+ });
16430
16443
  /**
16431
16444
  * 设置 form 的初始值,之后在 reset 的时候使用
16432
16445
  * @param values
@@ -16484,13 +16497,45 @@ class FormStore {
16484
16497
  validator.validate({ [name]: (_a2 = this.store) == null ? void 0 : _a2[name] }, (errors) => {
16485
16498
  if (errors) {
16486
16499
  err.push(...errors);
16487
- this.errors.push(...errors);
16500
+ this.errors[name] = errors;
16488
16501
  }
16489
16502
  entity.onStoreChange("validate");
16490
16503
  });
16491
16504
  });
16492
16505
  return err;
16493
16506
  });
16507
+ __publicField(this, "validateFields", (nameList) => {
16508
+ if (!nameList || nameList.length === 0) {
16509
+ this.validate();
16510
+ return;
16511
+ }
16512
+ this.fieldEntities.filter(({ props: { name } }) => {
16513
+ return nameList.includes(name);
16514
+ }).forEach((entity) => {
16515
+ var _a2;
16516
+ const { name, rules: rules2 = [] } = entity.props;
16517
+ const descriptor = {};
16518
+ if (rules2.length) {
16519
+ if (rules2.length > 1) {
16520
+ descriptor[name] = [];
16521
+ rules2.forEach((v) => {
16522
+ descriptor[name].push(v);
16523
+ });
16524
+ } else {
16525
+ descriptor[name] = rules2[0];
16526
+ }
16527
+ }
16528
+ const validator = new Schema(descriptor);
16529
+ validator.messages();
16530
+ validator.validate({ [name]: (_a2 = this.store) == null ? void 0 : _a2[name] }, (errors) => {
16531
+ this.errors[name] = [];
16532
+ if (errors) {
16533
+ this.errors[name] = errors;
16534
+ }
16535
+ entity.onStoreChange("validate");
16536
+ });
16537
+ });
16538
+ });
16494
16539
  __publicField(this, "submit", () => {
16495
16540
  var _a2, _b, _c, _d;
16496
16541
  const errors = this.validate();
@@ -16507,12 +16552,17 @@ class FormStore {
16507
16552
  entity.onStoreChange("reset");
16508
16553
  });
16509
16554
  });
16555
+ __publicField(this, "dispatch", ({ name }) => {
16556
+ this.validateFields([name]);
16557
+ });
16510
16558
  __publicField(this, "getForm", () => {
16511
16559
  return {
16560
+ dispatch: this.dispatch,
16512
16561
  setInitialValues: this.setInitialValues,
16513
16562
  setCallback: this.setCallback,
16514
16563
  registerField: this.registerField,
16515
16564
  getFieldValue: this.getFieldValue,
16565
+ getFieldsValue: this.getFieldsValue,
16516
16566
  setFieldsValue: this.setFieldsValue,
16517
16567
  resetFields: this.resetFields,
16518
16568
  submit: this.submit,
@@ -16634,7 +16684,8 @@ const defaultProps$V = {
16634
16684
  name: "",
16635
16685
  label: "",
16636
16686
  rules: [{ required: false, message: "" }],
16637
- errorMessageAlign: "left"
16687
+ errorMessageAlign: "left",
16688
+ validateTrigger: "onChange"
16638
16689
  };
16639
16690
  class FormItem extends React__default.Component {
16640
16691
  constructor(props) {
@@ -16644,7 +16695,7 @@ class FormItem extends React__default.Component {
16644
16695
  // children添加value属性和onChange事件
16645
16696
  __publicField(this, "getControlled", (children) => {
16646
16697
  var _a2;
16647
- const { setFieldsValue, getFieldValue } = this.context;
16698
+ const { setFieldsValue, getFieldValue, dispatch } = this.context;
16648
16699
  const { name = "" } = this.props;
16649
16700
  if ((_a2 = children == null ? void 0 : children.props) == null ? void 0 : _a2.defaultValue) {
16650
16701
  console.warn("通过 initialValue 设置初始值");
@@ -16665,6 +16716,24 @@ class FormItem extends React__default.Component {
16665
16716
  setFieldsValue({ [name]: next });
16666
16717
  }
16667
16718
  };
16719
+ const { validateTrigger } = this.props;
16720
+ let validateTriggers = [this.props.trigger || "onChange"];
16721
+ if (validateTrigger) {
16722
+ validateTriggers = typeof validateTrigger === "string" ? [...validateTriggers, validateTrigger] : [...validateTriggers, ...validateTrigger];
16723
+ validateTriggers.forEach((trigger) => {
16724
+ const originTrigger = controlled[trigger];
16725
+ controlled[trigger] = (...args) => {
16726
+ if (originTrigger) {
16727
+ originTrigger(...args);
16728
+ }
16729
+ if (this.props.rules && this.props.rules.length) {
16730
+ dispatch({
16731
+ name: this.props.name
16732
+ });
16733
+ }
16734
+ };
16735
+ });
16736
+ }
16668
16737
  if (isForwardRefComponent(children)) {
16669
16738
  controlled.ref = (componentInstance) => {
16670
16739
  const originRef = children.ref;
@@ -16694,16 +16763,22 @@ class FormItem extends React__default.Component {
16694
16763
  }
16695
16764
  });
16696
16765
  __publicField(this, "renderLayout", (childNode) => {
16697
- var _a2, _b;
16698
- const { label, name, required: required4, className, style, errorMessageAlign } = {
16766
+ const {
16767
+ label,
16768
+ name,
16769
+ required: required4,
16770
+ rules: rules2,
16771
+ className,
16772
+ style,
16773
+ errorMessageAlign
16774
+ } = {
16699
16775
  ...defaultProps$V,
16700
16776
  ...this.props
16701
16777
  };
16702
- const item = ((_a2 = this.context.errors) == null ? void 0 : _a2.length) > 0 && ((_b = this.context.errors) == null ? void 0 : _b.filter((item2) => {
16703
- return item2.field === name;
16704
- }));
16778
+ const requiredInRules = rules2 == null ? void 0 : rules2.some((rule) => rule.required);
16779
+ const item = name ? this.context.errors[name] : [];
16705
16780
  const { starPosition } = this.context;
16706
- const renderStar = required4 && /* @__PURE__ */ React__default.createElement("i", { className: "required" });
16781
+ const renderStar = (required4 || requiredInRules) && /* @__PURE__ */ React__default.createElement("i", { className: "required" });
16707
16782
  const renderLabel = /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, starPosition === "left" ? renderStar : null, label, starPosition === "right" ? renderStar : null);
16708
16783
  return /* @__PURE__ */ React__default.createElement(
16709
16784
  Cell,
@@ -16713,7 +16788,7 @@ class FormItem extends React__default.Component {
16713
16788
  onClick: (e) => this.props.onClick && this.props.onClick(e, this.componentRef)
16714
16789
  },
16715
16790
  label ? /* @__PURE__ */ React__default.createElement("div", { className: "nut-cell__title nut-form-item__label" }, renderLabel) : null,
16716
- /* @__PURE__ */ React__default.createElement("div", { className: "nut-cell__value nut-form-item__body" }, /* @__PURE__ */ React__default.createElement("div", { className: "nut-form-item__body__slots" }, childNode), item.length > 0 && /* @__PURE__ */ React__default.createElement(
16791
+ /* @__PURE__ */ React__default.createElement("div", { className: "nut-cell__value nut-form-item__body" }, /* @__PURE__ */ React__default.createElement("div", { className: "nut-form-item__body__slots" }, childNode), item && item.length > 0 && /* @__PURE__ */ React__default.createElement(
16717
16792
  "div",
16718
16793
  {
16719
16794
  className: "nut-form-item__body__tips",
@@ -17101,7 +17176,7 @@ const InputNumber = (props) => {
17101
17176
  };
17102
17177
  const changeFormatValue = (e) => {
17103
17178
  const input = e.target.value;
17104
- const numReg = new RegExp("^[0-9]*$");
17179
+ const numReg = /^[0-9]*$/;
17105
17180
  const numValue = input.replace(/[^0-9|.]/gi, "");
17106
17181
  if (formatter) {
17107
17182
  if (!numReg.test(input[0]) && numValue) {
@@ -17120,7 +17195,7 @@ const InputNumber = (props) => {
17120
17195
  };
17121
17196
  const burFormatValue = (e) => {
17122
17197
  const input = e.target.value;
17123
- const numReg = new RegExp("^[0-9]*$");
17198
+ const numReg = /^[0-9]*$/;
17124
17199
  const numValue = input.replace(/[^0-9|.]/gi, "");
17125
17200
  if (formatter) {
17126
17201
  if (formatter(numValue) === input) {
@@ -18704,7 +18779,9 @@ const InternalSignature = (props, ref) => {
18704
18779
  }));
18705
18780
  return /* @__PURE__ */ React__default.createElement("div", { className: `${classPrefix2} ${className}`, style, ...rest }, /* @__PURE__ */ React__default.createElement("div", { className: `${classPrefix2}__inner`, ref: wrapRef }, /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, isCanvasSupported ? /* @__PURE__ */ React__default.createElement("canvas", { ref: canvasRef, height: canvasHeight, width: canvasWidth }) : unsupported ? /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, unsupported) : /* @__PURE__ */ React__default.createElement("p", { className: `${classPrefix2}__unsupport` }, locale.signature.unsupported))));
18706
18781
  };
18707
- const Signature = React__default.forwardRef(InternalSignature);
18782
+ const Signature = React__default.forwardRef(
18783
+ InternalSignature
18784
+ );
18708
18785
  Signature.defaultProps = defaultProps$J;
18709
18786
  Signature.displayName = "NutSignature";
18710
18787
  const defaultProps$I = {
@@ -20481,10 +20558,13 @@ const NoticeBar = (props) => {
20481
20558
  if (childCount <= 1)
20482
20559
  return;
20483
20560
  stopAutoPlay();
20484
- swiperRef.current.autoplayTimer = setTimeout(() => {
20485
- next();
20486
- autoplay();
20487
- }, Number(duration) + 100 * speed);
20561
+ swiperRef.current.autoplayTimer = setTimeout(
20562
+ () => {
20563
+ next();
20564
+ autoplay();
20565
+ },
20566
+ Number(duration) + 100 * speed
20567
+ );
20488
20568
  };
20489
20569
  const move = ({ pace = 0, offset: offset2 = 0 }) => {
20490
20570
  if (childCount <= 1)
@@ -21387,7 +21467,7 @@ const Avatar = (props) => {
21387
21467
  ...icon.props,
21388
21468
  className: `${icon.props.className || ""} icon`
21389
21469
  }) : null, children && /* @__PURE__ */ React__default.createElement("span", { className: "text" }, children), !src && !icon && !children && /* @__PURE__ */ React__default.createElement(k$2, { className: "icon" })),
21390
- showMax && /* @__PURE__ */ React__default.createElement("div", { className: "text" }, ((_l = parent == null ? void 0 : parent.propAvatarGroup) == null ? void 0 : _l.maxContent) ? (_m = parent == null ? void 0 : parent.propAvatarGroup) == null ? void 0 : _m.maxContent : `+ ${avatarIndex - ((_n = parent == null ? void 0 : parent.propAvatarGroup) == null ? void 0 : _n.max)}`)
21470
+ showMax && /* @__PURE__ */ React__default.createElement("div", { className: "text" }, ((_l = parent == null ? void 0 : parent.propAvatarGroup) == null ? void 0 : _l.maxContent) ? (_m = parent == null ? void 0 : parent.propAvatarGroup) == null ? void 0 : _m.maxContent : `+ ${avatarIndex - Number(((_n = parent == null ? void 0 : parent.propAvatarGroup) == null ? void 0 : _n.max) || 0)}`)
21391
21471
  ));
21392
21472
  };
21393
21473
  Avatar.defaultProps = defaultProps$u;
@@ -22052,10 +22132,9 @@ const Audio = (props) => {
22052
22132
  handPlaying: false
22053
22133
  });
22054
22134
  const classPrefix2 = "nut-audio";
22055
- const warn = console.warn;
22056
22135
  const handleEnded = (e) => {
22057
22136
  if (props.loop) {
22058
- warn(locale.audio.tips || "onPlayEnd事件在loop=false时才会触发");
22137
+ console.warn(locale.audio.tips || "onPlayEnd事件在loop=false时才会触发");
22059
22138
  } else {
22060
22139
  props.onEnd && props.onEnd(e);
22061
22140
  }
@@ -22768,7 +22847,9 @@ const InternalCountDown = (props, ref) => {
22768
22847
  )
22769
22848
  );
22770
22849
  };
22771
- const CountDown = React__default.forwardRef(InternalCountDown);
22850
+ const CountDown = React__default.forwardRef(
22851
+ InternalCountDown
22852
+ );
22772
22853
  CountDown.defaultProps = defaultProps$k;
22773
22854
  CountDown.displayName = "NutCountDown";
22774
22855
  const useIsomorphicLayoutEffect = canUseDom ? useLayoutEffect : useEffect;
@@ -24105,8 +24186,8 @@ const Table = (props) => {
24105
24186
  return [columns2.key, columns2.render];
24106
24187
  });
24107
24188
  };
24108
- const renderBodyTds = (item) => {
24109
- return sortDataItem().map(([value, render2], index) => {
24189
+ const renderBodyTds = (item, rowIndex) => {
24190
+ return sortDataItem().map(([value, render2]) => {
24110
24191
  return /* @__PURE__ */ React__default.createElement(
24111
24192
  "span",
24112
24193
  {
@@ -24116,13 +24197,13 @@ const Table = (props) => {
24116
24197
  ),
24117
24198
  key: value
24118
24199
  },
24119
- typeof item[value] === "function" || typeof render2 === "function" ? /* @__PURE__ */ React__default.createElement("div", null, render2 ? render2(item) : item[value](item)) : item[value]
24200
+ typeof item[value] === "function" || typeof render2 === "function" ? /* @__PURE__ */ React__default.createElement("div", null, render2 ? render2(item, rowIndex) : item[value](item)) : item[value]
24120
24201
  );
24121
24202
  });
24122
24203
  };
24123
24204
  const renderBoyTrs = () => {
24124
24205
  return curData.map((item, index) => {
24125
- return /* @__PURE__ */ React__default.createElement("div", { className: bodyClassPrefix, key: index }, renderBodyTds(item));
24206
+ return /* @__PURE__ */ React__default.createElement("div", { className: bodyClassPrefix, key: index }, renderBodyTds(item, index));
24126
24207
  });
24127
24208
  };
24128
24209
  return /* @__PURE__ */ React__default.createElement("div", { className: cls, style, ...rest }, /* @__PURE__ */ React__default.createElement(
@@ -24432,7 +24513,7 @@ const getListTotalSize = (positions, horizontal) => {
24432
24513
  }
24433
24514
  return size;
24434
24515
  };
24435
- const binarySearch = (positionsList, value = 0, horizontal) => {
24516
+ const binarySearch = (positionsList, horizontal, value = 0) => {
24436
24517
  let start2 = 0;
24437
24518
  let end = positionsList.length - 1;
24438
24519
  let tempIndex = null;
@@ -24608,7 +24689,7 @@ const VirtualList = (props) => {
24608
24689
  const scroll = useCallback(() => {
24609
24690
  requestAnimationFrame((e) => {
24610
24691
  const scrollSize = getElement()[scrollKey];
24611
- const startIndex = binarySearch(positions, scrollSize, horizontal);
24692
+ const startIndex = binarySearch(positions, horizontal, scrollSize);
24612
24693
  const overStart = startIndex - overscan > -1 ? startIndex - overscan : 0;
24613
24694
  if (!itemEqual) {
24614
24695
  updateTotalSize();
@@ -24788,7 +24869,9 @@ const InternalBarrage = (props, ref) => {
24788
24869
  };
24789
24870
  return /* @__PURE__ */ React__default.createElement("div", { className: classes, ref: barrageBody, ...restProps }, /* @__PURE__ */ React__default.createElement("div", { ref: barrageContainer, className: "bContainer" }));
24790
24871
  };
24791
- const Barrage = React__default.forwardRef(InternalBarrage);
24872
+ const Barrage = React__default.forwardRef(
24873
+ InternalBarrage
24874
+ );
24792
24875
  Barrage.defaultProps = defaultProps$5;
24793
24876
  Barrage.displayName = "NutBarrage";
24794
24877
  const defaultProps$4 = {
@@ -25068,7 +25151,7 @@ const TrendArrow = (props) => {
25068
25151
  return console.warn(`传入的值:${num}不是一个数字`);
25069
25152
  }
25070
25153
  num = parseFloat(num);
25071
- const numPow = Math.pow(10, digit);
25154
+ const numPow = 10 ** digit;
25072
25155
  return (Math.round((num + Number.EPSILON) * numPow) / numPow).toFixed(digit);
25073
25156
  };
25074
25157
  const calcStyle = (() => {