@nutui/nutui-react 2.0.0-alpha.16 → 2.0.0-alpha.17

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 (106) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/esm/ActionSheet/style/style.css +1 -1
  3. package/dist/esm/Button.js +4 -2
  4. package/dist/esm/Divider/style/style.css +1 -1
  5. package/dist/esm/Form/style/index.js +3 -1
  6. package/dist/esm/Form/style/style.css +1 -1
  7. package/dist/esm/Form.js +64 -48
  8. package/dist/esm/FormItem/style/index.js +1 -1
  9. package/dist/esm/FormItem/style/style.css +1 -1
  10. package/dist/esm/FormItem.js +1 -1
  11. package/dist/esm/InputNumber.js +7 -7
  12. package/dist/esm/Pagination/style/style.css +1 -1
  13. package/dist/esm/Picker.js +31 -11
  14. package/dist/esm/Popover.js +7 -7
  15. package/dist/esm/Popup.js +1 -0
  16. package/dist/esm/SearchBar.js +2 -2
  17. package/dist/esm/Swipe.js +4 -6
  18. package/dist/esm/formitem2.js +87 -69
  19. package/dist/esm/types/src/packages/button/button.d.ts +1 -0
  20. package/dist/esm/types/src/packages/elevator/elevator.d.ts +0 -1
  21. package/dist/esm/types/src/packages/elevator/elevator.taro.d.ts +0 -1
  22. package/dist/esm/types/src/packages/form/__tests__/form.spec.d.ts +1 -0
  23. package/dist/esm/types/src/packages/form/context.d.ts +4 -0
  24. package/dist/esm/types/src/packages/form/form.d.ts +11 -4
  25. package/dist/esm/types/src/packages/form/form.taro.d.ts +14 -4
  26. package/dist/esm/types/src/packages/form/index.d.ts +1 -0
  27. package/dist/esm/types/src/packages/form/index.taro.d.ts +1 -0
  28. package/dist/esm/types/src/packages/form/types.d.ts +4 -52
  29. package/dist/esm/types/src/packages/formitem/formitem.d.ts +16 -15
  30. package/dist/esm/types/src/packages/formitem/formitem.taro.d.ts +16 -12
  31. package/dist/esm/types/src/packages/formitem/index.d.ts +1 -0
  32. package/dist/esm/types/src/packages/formitem/index.taro.d.ts +1 -0
  33. package/dist/esm/types/src/packages/formitem/types.d.ts +1 -31
  34. package/dist/esm/types/src/packages/inputnumber/inputnumber.d.ts +1 -1
  35. package/dist/esm/types/src/packages/inputnumber/inputnumber.taro.d.ts +1 -1
  36. package/dist/esm/types/src/packages/picker/picker.d.ts +7 -2
  37. package/dist/esm/types/src/packages/picker/picker.taro.d.ts +7 -2
  38. package/dist/esm/types/src/packages/sticky/sticky.d.ts +0 -1
  39. package/dist/esm/types/src/packages/swipe/swipe.d.ts +2 -6
  40. package/dist/esm/types/src/packages/swipe/swipe.taro.d.ts +2 -6
  41. package/dist/esm/types/src/utils/is-forward-ref-component.d.ts +1 -0
  42. package/dist/locales/base.js +1 -1
  43. package/dist/locales/en-US.js +1 -1
  44. package/dist/locales/id-ID.js +1 -1
  45. package/dist/locales/tr-TR.js +1 -1
  46. package/dist/locales/zh-CN.js +1 -1
  47. package/dist/locales/zh-TW.js +1 -1
  48. package/dist/locales/zh-UG.js +1 -1
  49. package/dist/nutui.react.es.js +244 -173
  50. package/dist/nutui.react.umd.js +244 -173
  51. package/dist/packages/actionsheet/actionsheet.scss +6 -6
  52. package/dist/packages/divider/divider.scss +8 -7
  53. package/dist/packages/formitem/formitem.scss +1 -13
  54. package/dist/packages/layout/layout.scss +0 -2
  55. package/dist/packages/pagination/pagination.scss +8 -30
  56. package/dist/style.css +1 -1
  57. package/dist/style.mjs +1 -1
  58. package/dist/types/packages/animate/animate.d.ts +3 -3
  59. package/dist/types/packages/audio/audio.d.ts +2 -2
  60. package/dist/types/packages/avatar/avatar.d.ts +5 -5
  61. package/dist/types/packages/avatargroup/avatargroup.d.ts +5 -5
  62. package/dist/types/packages/badge/badge.d.ts +1 -1
  63. package/dist/types/packages/button/button.d.ts +5 -4
  64. package/dist/types/packages/cascader/cascader.d.ts +4 -4
  65. package/dist/types/packages/checkboxgroup/checkboxgroup.d.ts +2 -2
  66. package/dist/types/packages/circleprogress/circleprogress.d.ts +2 -2
  67. package/dist/types/packages/divider/divider.d.ts +2 -2
  68. package/dist/types/packages/drag/drag.d.ts +1 -1
  69. package/dist/types/packages/elevator/elevator.d.ts +0 -1
  70. package/dist/types/packages/empty/empty.d.ts +3 -3
  71. package/dist/types/packages/fixednav/fixednav.d.ts +3 -3
  72. package/dist/types/packages/form/context.d.ts +4 -0
  73. package/dist/types/packages/form/form.d.ts +43 -4
  74. package/dist/types/packages/form/index.d.ts +1 -0
  75. package/dist/types/packages/form/types.d.ts +4 -52
  76. package/dist/types/packages/formitem/formitem.d.ts +45 -16
  77. package/dist/types/packages/formitem/index.d.ts +1 -0
  78. package/dist/types/packages/formitem/types.d.ts +1 -31
  79. package/dist/types/packages/grid/grid.d.ts +1 -1
  80. package/dist/types/packages/infiniteloading/infiniteloading.d.ts +1 -1
  81. package/dist/types/packages/inputnumber/inputnumber.d.ts +1 -1
  82. package/dist/types/packages/noticebar/noticebar.d.ts +3 -3
  83. package/dist/types/packages/overlay/overlay.d.ts +1 -1
  84. package/dist/types/packages/pagination/pagination.d.ts +1 -1
  85. package/dist/types/packages/picker/picker.d.ts +7 -2
  86. package/dist/types/packages/popover/popover.d.ts +5 -5
  87. package/dist/types/packages/popup/popup.d.ts +2 -2
  88. package/dist/types/packages/radio/radio.d.ts +2 -2
  89. package/dist/types/packages/searchbar/searchbar.d.ts +7 -7
  90. package/dist/types/packages/step/step.d.ts +3 -3
  91. package/dist/types/packages/steps/steps.d.ts +1 -1
  92. package/dist/types/packages/sticky/sticky.d.ts +1 -2
  93. package/dist/types/packages/swipe/swipe.d.ts +2 -6
  94. package/dist/types/packages/swiper/swiper.d.ts +1 -1
  95. package/dist/types/packages/tabs/tabs.d.ts +1 -1
  96. package/dist/types/packages/tag/tag.d.ts +1 -1
  97. package/dist/types/packages/timeselect/timeselect.d.ts +2 -2
  98. package/dist/types/packages/toast/toast.d.ts +50 -10
  99. package/dist/types/packages/uploader/uploader.d.ts +17 -17
  100. package/dist/types/utils/is-forward-ref-component.d.ts +1 -0
  101. package/package.json +1 -1
  102. package/dist/esm/types/src/packages/formitem/formitemcontext.d.ts +0 -6
  103. package/dist/types/packages/formitem/formitemcontext.d.ts +0 -6
  104. /package/dist/esm/types/src/packages/form/{useForm.d.ts → useform.d.ts} +0 -0
  105. /package/dist/esm/types/src/packages/form/{useForm.taro.d.ts → useform.taro.d.ts} +0 -0
  106. /package/dist/types/packages/form/{useForm.d.ts → useform.d.ts} +0 -0
@@ -6,7 +6,7 @@ var __publicField = (obj, key, value) => {
6
6
  };
7
7
  var _a;
8
8
  /*!
9
- * @nutui/nutui-react v2.0.0-alpha.16 Fri Jun 09 2023 18:29:35 GMT+0800 (China Standard Time)
9
+ * @nutui/nutui-react v2.0.0-alpha.17 Wed Jun 14 2023 16:27:27 GMT+0800 (China Standard Time)
10
10
  * (c) 2023 @jdf2e.
11
11
  * Released under the MIT License.
12
12
  */
@@ -2402,6 +2402,7 @@ const defaultProps$1r = {
2402
2402
  disabled: false,
2403
2403
  block: false,
2404
2404
  icon: null,
2405
+ nativeType: "button",
2405
2406
  onClick: (e) => {
2406
2407
  }
2407
2408
  };
@@ -2421,6 +2422,7 @@ const Button = React__default.forwardRef(
2421
2422
  onClick,
2422
2423
  className,
2423
2424
  style,
2425
+ nativeType,
2424
2426
  ...rest
2425
2427
  } = {
2426
2428
  ...defaultProps$1r,
@@ -2454,6 +2456,7 @@ const Button = React__default.forwardRef(
2454
2456
  {
2455
2457
  ...rest,
2456
2458
  ref,
2459
+ type: nativeType,
2457
2460
  className: classNames(
2458
2461
  prefixCls,
2459
2462
  className,
@@ -11162,6 +11165,7 @@ const Popup = (props) => {
11162
11165
  }
11163
11166
  };
11164
11167
  const onHandleClickOverlay = (e) => {
11168
+ e.stopPropagation();
11165
11169
  if (closeOnOverlayClick) {
11166
11170
  const closed = onClickOverlay && onClickOverlay(e);
11167
11171
  closed && close();
@@ -13816,7 +13820,7 @@ const Cascader = React__default.forwardRef(InternalCascader);
13816
13820
  Cascader.defaultProps = defaultProps$Z;
13817
13821
  Cascader.displayName = "NutCascader";
13818
13822
  const CheckboxGroupContext = createContext(null);
13819
- const Context = CheckboxGroupContext;
13823
+ const Context$1 = CheckboxGroupContext;
13820
13824
  const defaultProps$Y = {
13821
13825
  max: void 0,
13822
13826
  labelPosition: "right",
@@ -13887,7 +13891,7 @@ const CheckboxGroup = React__default.forwardRef(
13887
13891
  });
13888
13892
  }, [options2, max]);
13889
13893
  return /* @__PURE__ */ React__default.createElement(
13890
- Context.Provider,
13894
+ Context$1.Provider,
13891
13895
  {
13892
13896
  value: {
13893
13897
  labelPosition: labelPosition || "right",
@@ -13950,7 +13954,7 @@ const Checkbox = (props) => {
13950
13954
  ...others
13951
13955
  } = props;
13952
13956
  let { labelPosition, ...rest } = others;
13953
- const ctx2 = useContext(Context);
13957
+ const ctx2 = useContext(Context$1);
13954
13958
  let [innerChecked, setChecked] = usePropsValue({
13955
13959
  value: props.checked,
13956
13960
  defaultValue: props.defaultChecked,
@@ -14331,7 +14335,6 @@ function useRefs() {
14331
14335
  }
14332
14336
  const defaultProps$W = {
14333
14337
  ...ComponentDefaults,
14334
- visible: false,
14335
14338
  title: "",
14336
14339
  options: [],
14337
14340
  value: [],
@@ -14368,12 +14371,26 @@ const InternalPicker = (props, ref) => {
14368
14371
  (_a2 = props.onConfirm) == null ? void 0 : _a2.call(props, setSelectedOptions(), val);
14369
14372
  }
14370
14373
  });
14374
+ const [innerVisible, setInnerVisible] = usePropsValue({
14375
+ value: props.visible,
14376
+ defaultValue: false,
14377
+ finalValue: false
14378
+ });
14371
14379
  const [innerValue, setInnerValue] = useState(selectedValue);
14372
14380
  const [columnIndex, setColumnIndex] = useState(0);
14373
14381
  const pickerRef = useRef(null);
14374
14382
  const [refs, setRefs] = useRefs();
14375
14383
  const [columnsList, setColumnsList] = useState([]);
14376
14384
  const isConfirmEvent = useRef(false);
14385
+ const actions = {
14386
+ open: () => {
14387
+ setInnerVisible(true);
14388
+ },
14389
+ close: () => {
14390
+ setInnerVisible(false);
14391
+ }
14392
+ };
14393
+ useImperativeHandle(ref, () => actions);
14377
14394
  const formatCascade = (columns, values) => {
14378
14395
  const formatted = [];
14379
14396
  let columnOptions = {
@@ -14435,12 +14452,12 @@ const InternalPicker = (props, ref) => {
14435
14452
  };
14436
14453
  useEffect(() => {
14437
14454
  setInnerValue(innerValue !== selectedValue ? selectedValue : innerValue);
14438
- }, [visible]);
14455
+ }, [innerVisible]);
14439
14456
  useEffect(() => {
14440
- if (visible) {
14457
+ if (innerVisible) {
14441
14458
  init();
14442
14459
  }
14443
- }, [options2, visible]);
14460
+ }, [options2, innerVisible]);
14444
14461
  useEffect(() => {
14445
14462
  onChange && onChange(setSelectedOptions(), innerValue, columnIndex);
14446
14463
  }, [innerValue, columnsList]);
@@ -14513,6 +14530,7 @@ const InternalPicker = (props, ref) => {
14513
14530
  }, 0);
14514
14531
  };
14515
14532
  const closePicker = () => {
14533
+ setInnerVisible(false);
14516
14534
  onClose && onClose(setSelectedOptions(), innerValue);
14517
14535
  afterClose && afterClose(setSelectedOptions(), innerValue, pickerRef);
14518
14536
  };
@@ -14521,21 +14539,34 @@ const InternalPicker = (props, ref) => {
14521
14539
  "span",
14522
14540
  {
14523
14541
  className: `${classPrefix2}__cancel-btn`,
14524
- onClick: () => closePicker()
14542
+ onClick: (e) => {
14543
+ e.stopPropagation();
14544
+ closePicker();
14545
+ }
14525
14546
  },
14526
14547
  locale.cancel
14527
- ), /* @__PURE__ */ React__default.createElement("div", { className: `${classPrefix2}__title` }, title || ""), /* @__PURE__ */ React__default.createElement("span", { className: `${classPrefix2}__confirm-btn`, onClick: confirm2 }, locale.confirm));
14548
+ ), /* @__PURE__ */ React__default.createElement("div", { className: `${classPrefix2}__title` }, title || ""), /* @__PURE__ */ React__default.createElement(
14549
+ "span",
14550
+ {
14551
+ className: `${classPrefix2}__confirm-btn`,
14552
+ onClick: (e) => {
14553
+ e.stopPropagation();
14554
+ confirm2();
14555
+ }
14556
+ },
14557
+ locale.confirm
14558
+ ));
14528
14559
  };
14529
- return /* @__PURE__ */ React__default.createElement(
14560
+ return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, typeof children === "function" && children(selectedValue), /* @__PURE__ */ React__default.createElement(
14530
14561
  Popup,
14531
14562
  {
14532
- visible,
14563
+ visible: innerVisible,
14533
14564
  position: "bottom",
14534
14565
  afterClose: () => {
14535
14566
  closePicker();
14536
14567
  }
14537
14568
  },
14538
- /* @__PURE__ */ React__default.createElement("div", { className: classes, style, ...rest }, renderTitleBar(), children, /* @__PURE__ */ React__default.createElement("div", { className: `${classPrefix2}__panel`, ref: pickerRef }, columnsList == null ? void 0 : columnsList.map((item, index) => {
14569
+ /* @__PURE__ */ React__default.createElement("div", { className: classes, style, ...rest }, renderTitleBar(), typeof children !== "function" && children, /* @__PURE__ */ React__default.createElement("div", { className: `${classPrefix2}__panel`, ref: pickerRef }, columnsList == null ? void 0 : columnsList.map((item, index) => {
14539
14570
  return /* @__PURE__ */ React__default.createElement(
14540
14571
  PickerPanel$1,
14541
14572
  {
@@ -14550,7 +14581,7 @@ const InternalPicker = (props, ref) => {
14550
14581
  }
14551
14582
  );
14552
14583
  })))
14553
- );
14584
+ ));
14554
14585
  };
14555
14586
  const Picker = React__default.forwardRef(InternalPicker);
14556
14587
  const Picker$1 = Picker;
@@ -14854,7 +14885,7 @@ const DatePicker = (props) => {
14854
14885
  };
14855
14886
  DatePicker.defaultProps = defaultProps$V;
14856
14887
  DatePicker.displayName = "NutDatePicker";
14857
- const FormItemContext = createContext({});
14888
+ const Context = createContext({});
14858
14889
  function _extends() {
14859
14890
  _extends = Object.assign ? Object.assign.bind() : function(target) {
14860
14891
  for (var i = 1; i < arguments.length; i++) {
@@ -15910,13 +15941,15 @@ Schema.messages = messages;
15910
15941
  Schema.validators = validators;
15911
15942
  class FormStore {
15912
15943
  constructor() {
15913
- __publicField(this, "store", {});
15944
+ // 初始化数据
15945
+ __publicField(this, "initialValues", {});
15914
15946
  // 存放表单中所有的数据 eg. {password: "ddd",username: "123"}
15915
- __publicField(this, "fieldEntities", []);
15947
+ __publicField(this, "store", {});
15916
15948
  // 所有的组件实例
15917
- // 成功和失败的回调
15949
+ __publicField(this, "fieldEntities", []);
15950
+ // 校验成功或失败的回调,onFinish、onFinishFailed
15918
15951
  __publicField(this, "callbacks", {});
15919
- __publicField(this, "errList", []);
15952
+ __publicField(this, "errors", []);
15920
15953
  /**
15921
15954
  * 注册组件实例
15922
15955
  * @param field
@@ -15925,11 +15958,29 @@ class FormStore {
15925
15958
  this.fieldEntities.push(field);
15926
15959
  return () => {
15927
15960
  this.fieldEntities = this.fieldEntities.filter((item) => item != field);
15928
- delete this.store[field.props.name];
15961
+ if (this.store) {
15962
+ delete this.store[field.props.name];
15963
+ }
15929
15964
  };
15930
15965
  });
15966
+ /**
15967
+ * 获取 formItem 的值
15968
+ * @param name
15969
+ */
15931
15970
  __publicField(this, "getFieldValue", (name) => {
15932
- return this.store[name];
15971
+ var _a2;
15972
+ return (_a2 = this.store) == null ? void 0 : _a2[name];
15973
+ });
15974
+ /**
15975
+ * 设置 form 的初始值,之后在 reset 的时候使用
15976
+ * @param values
15977
+ * @param init
15978
+ */
15979
+ __publicField(this, "setInitialValues", (values, init) => {
15980
+ if (init) {
15981
+ this.initialValues = values;
15982
+ this.store = values;
15983
+ }
15933
15984
  });
15934
15985
  /**
15935
15986
  * 存储组件数据
@@ -15944,34 +15995,28 @@ class FormStore {
15944
15995
  const { name } = enetity.props;
15945
15996
  Object.keys(newStore).forEach((key) => {
15946
15997
  if (key === name) {
15947
- enetity.onStoreChange();
15998
+ enetity.onStoreChange("update");
15948
15999
  }
15949
16000
  });
15950
16001
  });
15951
16002
  });
15952
- /**
15953
- * 表单校验
15954
- * rules: { required: true, message: '' }
15955
- * descriptor: {
15956
- * username: {
15957
- * type: 'string',
15958
- * required: true,
15959
- * validator: (rule, value) => {
15960
- * return /^[a-zA-Z0-9]+$/.test(value)
15961
- * },
15962
- * },
15963
- * }
15964
- */
16003
+ __publicField(this, "setCallback", (callback) => {
16004
+ this.callbacks = {
16005
+ ...this.callbacks,
16006
+ ...callback
16007
+ };
16008
+ });
15965
16009
  __publicField(this, "validate", () => {
15966
16010
  const err = [];
15967
- this.errList.length = 0;
16011
+ this.errors.length = 0;
15968
16012
  this.fieldEntities.forEach((entity) => {
16013
+ var _a2;
15969
16014
  const { name, rules: rules2 = [] } = entity.props;
15970
16015
  const descriptor = {};
15971
16016
  if (rules2.length) {
15972
16017
  if (rules2.length > 1) {
15973
16018
  descriptor[name] = [];
15974
- rules2.map((v) => {
16019
+ rules2.forEach((v) => {
15975
16020
  descriptor[name].push(v);
15976
16021
  });
15977
16022
  } else {
@@ -15979,39 +16024,36 @@ class FormStore {
15979
16024
  }
15980
16025
  }
15981
16026
  const validator = new Schema(descriptor);
15982
- validator.validate({ [name]: this.store[name] }, (errors) => {
16027
+ validator.messages();
16028
+ validator.validate({ [name]: (_a2 = this.store) == null ? void 0 : _a2[name] }, (errors) => {
15983
16029
  if (errors) {
15984
16030
  err.push(...errors);
15985
- this.errList.push(...errors);
16031
+ this.errors.push(...errors);
15986
16032
  }
15987
- entity.onStoreChange();
16033
+ entity.onStoreChange("validate");
15988
16034
  });
15989
16035
  });
15990
16036
  return err;
15991
16037
  });
15992
- __publicField(this, "setCallback", (callback) => {
15993
- this.callbacks = {
15994
- ...this.callbacks,
15995
- ...callback
15996
- };
15997
- });
15998
16038
  __publicField(this, "submit", () => {
15999
16039
  var _a2, _b, _c, _d;
16000
- const err = this.validate();
16001
- if (err.length === 0) {
16040
+ const errors = this.validate();
16041
+ if (errors.length === 0) {
16002
16042
  (_b = (_a2 = this.callbacks).onFinish) == null ? void 0 : _b.call(_a2, this.store);
16003
- } else if (err.length > 0) {
16004
- (_d = (_c = this.callbacks).onFinishFailed) == null ? void 0 : _d.call(_c, err);
16043
+ } else if (errors.length > 0) {
16044
+ (_d = (_c = this.callbacks).onFinishFailed) == null ? void 0 : _d.call(_c, this.store, errors);
16005
16045
  }
16006
16046
  });
16007
16047
  __publicField(this, "resetFields", () => {
16008
- this.errList.length = 0;
16009
- this.fieldEntities.forEach((enetity) => {
16010
- enetity.onStoreChange();
16048
+ this.errors.length = 0;
16049
+ this.store = this.initialValues;
16050
+ this.fieldEntities.forEach((entity) => {
16051
+ entity.onStoreChange("reset");
16011
16052
  });
16012
16053
  });
16013
16054
  __publicField(this, "getForm", () => {
16014
16055
  return {
16056
+ setInitialValues: this.setInitialValues,
16015
16057
  setCallback: this.setCallback,
16016
16058
  registerField: this.registerField,
16017
16059
  getFieldValue: this.getFieldValue,
@@ -16019,12 +16061,12 @@ class FormStore {
16019
16061
  resetFields: this.resetFields,
16020
16062
  submit: this.submit,
16021
16063
  store: this.store,
16022
- errList: this.errList,
16064
+ errors: this.errors,
16023
16065
  fieldEntities: this.fieldEntities
16024
16066
  };
16025
16067
  });
16026
16068
  this.callbacks = {
16027
- onFinish: (value) => {
16069
+ onFinish: () => {
16028
16070
  },
16029
16071
  onFinishFailed: () => {
16030
16072
  }
@@ -16043,98 +16085,113 @@ const useForm = (form) => {
16043
16085
  }
16044
16086
  return [formRef.current];
16045
16087
  };
16088
+ function isForwardRefComponent(component) {
16089
+ return component.type && component.type.$$typeof && // eslint-disable-next-line react/display-name
16090
+ React__default.forwardRef(
16091
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
16092
+ // @ts-ignore
16093
+ () => {
16094
+ }
16095
+ ).$$typeof === component.type.$$typeof;
16096
+ }
16046
16097
  const defaultProps$U = {
16047
16098
  ...ComponentDefaults,
16099
+ required: false,
16048
16100
  name: "",
16049
16101
  label: "",
16050
- className: "",
16051
16102
  rules: [{ required: false, message: "" }],
16052
- disabled: false,
16053
- labelWidth: 90,
16054
- errorMessageAlign: "left",
16055
- showErrorLine: true,
16056
- showErrorMessage: true,
16057
- initialValue: ""
16103
+ errorMessageAlign: "left"
16058
16104
  };
16059
16105
  class FormItem extends React__default.Component {
16060
- constructor() {
16061
- super(...arguments);
16106
+ constructor(props) {
16107
+ super(props);
16062
16108
  __publicField(this, "cancelRegister");
16063
- __publicField(this, "isInitialValue", false);
16109
+ __publicField(this, "componentRef");
16064
16110
  // children添加value属性和onChange事件
16065
16111
  __publicField(this, "getControlled", (children) => {
16066
- var _a2, _b;
16067
- const { getFieldValue, setFieldsValue } = this.context;
16112
+ var _a2;
16113
+ const { setFieldsValue, getFieldValue } = this.context;
16068
16114
  const { name } = this.props;
16069
- const type4 = children.type.NAME;
16070
- const defaultvalue = this.props.initialValue || ((_a2 = children.props) == null ? void 0 : _a2.defaultValue) || ((_b = children.props) == null ? void 0 : _b.value);
16071
- if (defaultvalue && !this.isInitialValue) {
16072
- setFieldsValue({ [name]: defaultvalue });
16073
- this.isInitialValue = true;
16074
- }
16075
- return {
16076
- value: getFieldValue(name),
16077
- defaultValue: getFieldValue(name),
16078
- onChange: (event) => {
16079
- const originOnChange = children.props.onChange;
16115
+ if ((_a2 = children == null ? void 0 : children.props) == null ? void 0 : _a2.defaultValue) {
16116
+ console.warn("通过 initialValue 设置初始值");
16117
+ }
16118
+ const controlled = {
16119
+ ...children.props,
16120
+ [this.props.valuePropName || "value"]: getFieldValue(name) || this.props.initialValue,
16121
+ [this.props.trigger || "onChange"]: (...args) => {
16122
+ const originOnChange = children.props[this.props.trigger || "onChange"];
16080
16123
  if (originOnChange) {
16081
- originOnChange(event);
16124
+ originOnChange(...args);
16082
16125
  }
16083
- let newValue = event;
16084
- switch (type4) {
16085
- case "checkbox":
16086
- newValue = event.target.value;
16087
- break;
16126
+ let [next] = args;
16127
+ if (this.props.getValueFromEvent) {
16128
+ next = this.props.getValueFromEvent(...args);
16088
16129
  }
16089
- setFieldsValue({ [name]: newValue });
16130
+ setFieldsValue({ [name]: next });
16090
16131
  }
16091
16132
  };
16133
+ if (isForwardRefComponent(children)) {
16134
+ controlled.ref = (componentInstance) => {
16135
+ const originRef = children.ref;
16136
+ if (originRef) {
16137
+ if (typeof originRef === "function") {
16138
+ originRef(componentInstance);
16139
+ }
16140
+ if ("current" in originRef) {
16141
+ originRef.current = componentInstance;
16142
+ }
16143
+ }
16144
+ this.componentRef = componentInstance;
16145
+ };
16146
+ }
16147
+ return controlled;
16148
+ });
16149
+ __publicField(this, "refresh", () => {
16150
+ this.setState(({ resetCount }) => ({
16151
+ resetCount: resetCount + 1
16152
+ }));
16092
16153
  });
16093
- __publicField(this, "onStoreChange", () => {
16094
- this.forceUpdate();
16154
+ __publicField(this, "onStoreChange", (type4) => {
16155
+ if (type4 === "reset") {
16156
+ this.refresh();
16157
+ } else {
16158
+ this.forceUpdate();
16159
+ }
16095
16160
  });
16096
16161
  __publicField(this, "renderLayout", (childNode) => {
16097
16162
  var _a2, _b;
16098
- const {
16099
- label,
16100
- name,
16101
- rules: rules2 = [{ required: false, message: "" }],
16102
- className,
16103
- labelWidth,
16104
- errorMessageAlign,
16105
- showErrorLine,
16106
- showErrorMessage
16107
- } = {
16163
+ const { label, name, required: required4, className, style, errorMessageAlign } = {
16108
16164
  ...defaultProps$U,
16109
16165
  ...this.props
16110
16166
  };
16111
- const item = ((_a2 = this.context.errList) == null ? void 0 : _a2.length) > 0 && ((_b = this.context.errList) == null ? void 0 : _b.filter((item2) => {
16167
+ const item = ((_a2 = this.context.errors) == null ? void 0 : _a2.length) > 0 && ((_b = this.context.errors) == null ? void 0 : _b.filter((item2) => {
16112
16168
  return item2.field === name;
16113
16169
  }));
16114
- const { starPositon } = this.context;
16115
- const renderStar = rules2.length > 0 && rules2[0].required && /* @__PURE__ */ React__default.createElement("i", { className: "required" });
16116
- const renderLabel = starPositon === "Right" ? /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, label, renderStar) : /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, renderStar, label);
16117
- return /* @__PURE__ */ React__default.createElement(Cell, { className: `nut-form-item ${className}` }, label ? /* @__PURE__ */ React__default.createElement(
16118
- "div",
16119
- {
16120
- className: "nut-cell__title nut-form-item__label",
16121
- style: {
16122
- width: this.pxCheck(labelWidth)
16123
- }
16124
- },
16125
- renderLabel
16126
- ) : null, /* @__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(
16127
- "div",
16170
+ const { starPosition } = this.context;
16171
+ const renderStar = required4 && /* @__PURE__ */ React__default.createElement("i", { className: "required" });
16172
+ const renderLabel = /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, starPosition === "left" ? renderStar : null, label, starPosition === "right" ? renderStar : null);
16173
+ return /* @__PURE__ */ React__default.createElement(
16174
+ Cell,
16128
16175
  {
16129
- className: "nut-form-item__body__tips",
16130
- style: { textAlign: errorMessageAlign }
16176
+ className: `nut-form-item ${className}`,
16177
+ style,
16178
+ onClick: (e) => this.props.onClick && this.props.onClick(e, this.componentRef)
16131
16179
  },
16132
- item[0].message
16133
- )));
16134
- });
16135
- __publicField(this, "pxCheck", (value) => {
16136
- return Number.isNaN(Number(value)) ? String(value) : `${value}px`;
16180
+ label ? /* @__PURE__ */ React__default.createElement("div", { className: "nut-cell__title nut-form-item__label" }, renderLabel) : null,
16181
+ /* @__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(
16182
+ "div",
16183
+ {
16184
+ className: "nut-form-item__body__tips",
16185
+ style: { textAlign: errorMessageAlign }
16186
+ },
16187
+ item[0].message
16188
+ ))
16189
+ );
16137
16190
  });
16191
+ this.componentRef = React__default.createRef();
16192
+ this.state = {
16193
+ resetCount: 1
16194
+ };
16138
16195
  }
16139
16196
  componentDidMount() {
16140
16197
  this.cancelRegister = this.context.registerField(this);
@@ -16145,81 +16202,86 @@ class FormItem extends React__default.Component {
16145
16202
  }
16146
16203
  }
16147
16204
  render() {
16148
- const { children, initialValue } = this.props;
16149
- const c = Array.isArray(children) ? children[0] : children;
16150
- let restCNode = c;
16151
- if (initialValue) {
16152
- restCNode = React__default.cloneElement(c, {
16153
- defaultValue: initialValue
16154
- });
16155
- }
16205
+ const { children } = this.props;
16206
+ const child = Array.isArray(children) ? children[0] : children;
16156
16207
  const returnChildNode = React__default.cloneElement(
16157
- restCNode,
16158
- this.getControlled(restCNode)
16208
+ child,
16209
+ this.getControlled(child)
16159
16210
  );
16160
- return this.renderLayout(returnChildNode);
16211
+ return /* @__PURE__ */ React__default.createElement(React__default.Fragment, { key: this.state.resetCount }, this.renderLayout(returnChildNode));
16161
16212
  }
16162
16213
  }
16163
16214
  __publicField(FormItem, "defaultProps", defaultProps$U);
16164
- __publicField(FormItem, "contextType", FormItemContext);
16215
+ __publicField(FormItem, "contextType", Context);
16165
16216
  const defaultProps$T = {
16166
16217
  ...ComponentDefaults,
16167
- className: "",
16168
- style: void 0,
16169
- form: {},
16170
- labelPosition: "Right",
16171
- formGroupTitle: "",
16172
- onFinish: (obj) => {
16173
- },
16174
- onFinishFailed: (value) => {
16218
+ labelPosition: "right",
16219
+ starPosition: "left",
16220
+ onFinish: (values) => {
16175
16221
  },
16176
- starPositon: "Left"
16222
+ onFinishFailed: (values, errorFields) => {
16223
+ }
16177
16224
  };
16178
16225
  const PositionInfo = {
16179
- Top: "form-layout-top",
16180
- Left: "form-layout-left",
16181
- Right: "form-layout-right"
16226
+ top: "form-layout-top",
16227
+ left: "form-layout-left",
16228
+ right: "form-layout-right"
16182
16229
  };
16183
16230
  const Form = (props) => {
16231
+ const classPrefix2 = "nut-form";
16184
16232
  const {
16233
+ className,
16234
+ style,
16235
+ footer,
16185
16236
  children,
16237
+ initialValues,
16186
16238
  onFinish,
16187
16239
  onFinishFailed,
16188
16240
  labelPosition,
16189
- starPositon,
16190
- form,
16191
- ...rest
16241
+ starPosition,
16242
+ form
16192
16243
  } = {
16193
16244
  ...defaultProps$T,
16194
16245
  ...props
16195
16246
  };
16196
- let formInstance = {};
16197
- if (Object.keys(form).length !== 0) {
16247
+ let formInstance;
16248
+ if (form !== void 0) {
16198
16249
  formInstance = form;
16199
16250
  } else {
16200
16251
  [formInstance] = useForm();
16201
16252
  }
16202
- formInstance.starPositon = starPositon;
16203
- const { setCallback, submit, resetFields } = formInstance;
16253
+ formInstance.starPosition = starPosition;
16254
+ const { setCallback, submit, resetFields, setInitialValues } = formInstance;
16204
16255
  setCallback({
16205
16256
  onFinish,
16206
16257
  onFinishFailed
16207
16258
  });
16259
+ const mountRef = React__default.useRef(false);
16260
+ setInitialValues(initialValues, !mountRef.current);
16261
+ if (!mountRef.current) {
16262
+ mountRef.current = true;
16263
+ }
16208
16264
  return /* @__PURE__ */ React__default.createElement(
16209
16265
  "form",
16210
16266
  {
16211
- className: `nut-form ${PositionInfo[labelPosition]} ${props.className}`,
16212
- style: props.style,
16267
+ className: classNames(
16268
+ classPrefix2,
16269
+ className,
16270
+ PositionInfo[labelPosition]
16271
+ ),
16272
+ style,
16213
16273
  onSubmit: (e) => {
16214
16274
  e.preventDefault();
16275
+ e.stopPropagation();
16215
16276
  submit();
16216
16277
  },
16217
16278
  onReset: (e) => {
16218
16279
  e.preventDefault();
16280
+ e.stopPropagation();
16219
16281
  resetFields();
16220
16282
  }
16221
16283
  },
16222
- /* @__PURE__ */ React__default.createElement(CellGroup, null, /* @__PURE__ */ React__default.createElement(FormItemContext.Provider, { value: formInstance }, children))
16284
+ /* @__PURE__ */ React__default.createElement(CellGroup, null, /* @__PURE__ */ React__default.createElement(Context.Provider, { value: formInstance }, children), footer ? /* @__PURE__ */ React__default.createElement(Cell, null, footer) : null)
16223
16285
  );
16224
16286
  };
16225
16287
  Form.defaultProps = defaultProps$T;
@@ -16435,7 +16497,7 @@ const defaultProps$R = {
16435
16497
  disabled: false,
16436
16498
  min: 1,
16437
16499
  max: 9999,
16438
- readonly: false,
16500
+ readOnly: false,
16439
16501
  allowEmpty: false,
16440
16502
  defaultValue: 0,
16441
16503
  step: 1,
@@ -16449,7 +16511,7 @@ const InputNumber = (props) => {
16449
16511
  disabled,
16450
16512
  min,
16451
16513
  max,
16452
- readonly,
16514
+ readOnly,
16453
16515
  value,
16454
16516
  defaultValue,
16455
16517
  allowEmpty,
@@ -16608,14 +16670,14 @@ const InputNumber = (props) => {
16608
16670
  const focusValue = (e) => {
16609
16671
  if (disabled)
16610
16672
  return;
16611
- if (readonly)
16673
+ if (readOnly)
16612
16674
  return;
16613
16675
  onFocus && onFocus(e);
16614
16676
  };
16615
16677
  const burValue = (e) => {
16616
16678
  if (disabled)
16617
16679
  return;
16618
- if (readonly)
16680
+ if (readOnly)
16619
16681
  return;
16620
16682
  const input = e.target;
16621
16683
  let value2 = input.valueAsNumber;
@@ -16643,7 +16705,7 @@ const InputNumber = (props) => {
16643
16705
  min,
16644
16706
  max,
16645
16707
  disabled,
16646
- readOnly: readonly,
16708
+ readOnly,
16647
16709
  value: _checked,
16648
16710
  onInput: changeFormatValue,
16649
16711
  onBlur: burFormatValue,
@@ -16656,7 +16718,7 @@ const InputNumber = (props) => {
16656
16718
  min,
16657
16719
  max,
16658
16720
  disabled,
16659
- readOnly: readonly,
16721
+ readOnly,
16660
16722
  value: _checked,
16661
16723
  onInput: changeValue,
16662
16724
  onBlur: burValue,
@@ -17848,7 +17910,7 @@ const SearchBar = (props) => {
17848
17910
  return /* @__PURE__ */ React__default.createElement(
17849
17911
  "input",
17850
17912
  {
17851
- className: `${classPrefix2}__input ${shape === "round" ? `${classPrefix2}__round` : ""} ${clearable ? `${classPrefix2}__input-clear` : ""}`,
17913
+ className: `${classPrefix2}__input ${clearable ? `${classPrefix2}__input-clear` : ""}`,
17852
17914
  ref: searchRef,
17853
17915
  style: { ...props.style },
17854
17916
  value: value || "",
@@ -17921,7 +17983,16 @@ const SearchBar = (props) => {
17921
17983
  style: { ...props.style }
17922
17984
  },
17923
17985
  renderLeft(),
17924
- /* @__PURE__ */ React__default.createElement("div", { className: `${classPrefix2}__content` }, renderLeftIn(), renderField(), renderRightIn(), clearable && value && handleClear()),
17986
+ /* @__PURE__ */ React__default.createElement(
17987
+ "div",
17988
+ {
17989
+ className: `${classPrefix2}__content ${shape === "round" ? `${classPrefix2}__round` : ""}`
17990
+ },
17991
+ renderLeftIn(),
17992
+ renderField(),
17993
+ renderRightIn(),
17994
+ clearable && value && handleClear()
17995
+ ),
17925
17996
  renderRight()
17926
17997
  );
17927
17998
  };
@@ -20329,7 +20400,7 @@ const Popover = (props) => {
20329
20400
  return styles;
20330
20401
  };
20331
20402
  const getRootPosition = () => {
20332
- let styles = {};
20403
+ const styles = {};
20333
20404
  if (!rootPosition)
20334
20405
  return {};
20335
20406
  const contentWidth = elWidth;
@@ -20339,34 +20410,34 @@ const Popover = (props) => {
20339
20410
  const skew = location.split("-")[1];
20340
20411
  let cross = 0;
20341
20412
  let parallel = 0;
20342
- if (Array.isArray(offset) && offset.length == 2) {
20413
+ if (Array.isArray(offset) && offset.length === 2) {
20343
20414
  cross += +offset[1];
20344
20415
  parallel += +offset[0];
20345
20416
  }
20346
20417
  if (width) {
20347
20418
  if (["bottom", "top"].includes(direction)) {
20348
- const h = direction == "bottom" ? height + cross : -(contentHeight + cross);
20419
+ const h = direction === "bottom" ? height + cross : -(contentHeight + cross);
20349
20420
  styles.top = `${top + h}px`;
20350
20421
  if (!skew) {
20351
20422
  styles.left = `${-(contentWidth - width) / 2 + left + parallel}px`;
20352
20423
  }
20353
- if (skew == "start") {
20424
+ if (skew === "start") {
20354
20425
  styles.left = `${left + parallel}px`;
20355
20426
  }
20356
- if (skew == "end") {
20427
+ if (skew === "end") {
20357
20428
  styles.left = `${right + parallel}px`;
20358
20429
  }
20359
20430
  }
20360
20431
  if (["left", "right"].includes(direction)) {
20361
- const contentW = direction == "left" ? -(contentWidth + cross) : width + cross;
20432
+ const contentW = direction === "left" ? -(contentWidth + cross) : width + cross;
20362
20433
  styles.left = `${left + contentW}px`;
20363
20434
  if (!skew) {
20364
20435
  styles.top = `${top - contentHeight / 2 + height / 2 - 4 + parallel}px`;
20365
20436
  }
20366
- if (skew == "start") {
20437
+ if (skew === "start") {
20367
20438
  styles.top = `${top + parallel}px`;
20368
20439
  }
20369
- if (skew == "end") {
20440
+ if (skew === "end") {
20370
20441
  styles.top = `${top + height + parallel}px`;
20371
20442
  }
20372
20443
  }
@@ -20818,7 +20889,7 @@ const defaultProps$s = {
20818
20889
  name: ""
20819
20890
  };
20820
20891
  const Swipe = forwardRef((props, instanceRef) => {
20821
- const swipeBem = cn("swipe");
20892
+ const classPrefix2 = "nut-swipe";
20822
20893
  const touch = useTouch();
20823
20894
  const { children, className, style } = { ...defaultProps$s, ...props };
20824
20895
  const root2 = useRef();
@@ -20939,7 +21010,7 @@ const Swipe = forwardRef((props, instanceRef) => {
20939
21010
  "div",
20940
21011
  {
20941
21012
  ref: measuredRef,
20942
- className: `${swipeBem(side)}`,
21013
+ className: `${classPrefix2}__${side}`,
20943
21014
  onClick: (e) => handleOperate(e, side)
20944
21015
  },
20945
21016
  props[`${side}Action`]
@@ -20979,13 +21050,13 @@ const Swipe = forwardRef((props, instanceRef) => {
20979
21050
  "div",
20980
21051
  {
20981
21052
  ref: root2,
20982
- className: classNames(swipeBem(), className),
21053
+ className: classNames(classPrefix2, className),
20983
21054
  onTouchStart: (e) => onTouchStart(e),
20984
21055
  onTouchMove: (e) => onTouchMove(e),
20985
21056
  onTouchEnd: (e) => onTouchEnd(e),
20986
21057
  style
20987
21058
  },
20988
- /* @__PURE__ */ React__default.createElement("div", { className: `${swipeBem("wrapper")}`, style: wrapperStyle }, renderActionContent("left", leftRef), children, renderActionContent("right", rightRef))
21059
+ /* @__PURE__ */ React__default.createElement("div", { className: `${classPrefix2}__wrapper`, style: wrapperStyle }, renderActionContent("left", leftRef), children, renderActionContent("right", rightRef))
20989
21060
  );
20990
21061
  });
20991
21062
  Swipe.defaultProps = defaultProps$s;