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

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 (116) hide show
  1. package/CHANGELOG.md +24 -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 +65 -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/style/style.css +1 -1
  12. package/dist/esm/InputNumber.js +7 -7
  13. package/dist/esm/Pagination/style/style.css +1 -1
  14. package/dist/esm/Picker.js +31 -11
  15. package/dist/esm/Popover.js +7 -7
  16. package/dist/esm/Popup.js +1 -0
  17. package/dist/esm/SearchBar.js +2 -2
  18. package/dist/esm/Swipe.js +4 -6
  19. package/dist/esm/Tabbar/style/style.css +1 -1
  20. package/dist/esm/TabbarItem/style/index.js +1 -1
  21. package/dist/esm/TabbarItem/style/style.css +1 -1
  22. package/dist/esm/formitem2.js +87 -69
  23. package/dist/esm/tabbaritem2.js +17 -8
  24. package/dist/esm/types/src/packages/button/button.d.ts +1 -0
  25. package/dist/esm/types/src/packages/elevator/elevator.d.ts +0 -1
  26. package/dist/esm/types/src/packages/elevator/elevator.taro.d.ts +0 -1
  27. package/dist/esm/types/src/packages/form/__tests__/form.spec.d.ts +1 -0
  28. package/dist/esm/types/src/packages/form/context.d.ts +4 -0
  29. package/dist/esm/types/src/packages/form/form.d.ts +11 -4
  30. package/dist/esm/types/src/packages/form/form.taro.d.ts +14 -4
  31. package/dist/esm/types/src/packages/form/index.d.ts +1 -0
  32. package/dist/esm/types/src/packages/form/index.taro.d.ts +1 -0
  33. package/dist/esm/types/src/packages/form/types.d.ts +4 -52
  34. package/dist/esm/types/src/packages/formitem/formitem.d.ts +16 -15
  35. package/dist/esm/types/src/packages/formitem/formitem.taro.d.ts +16 -12
  36. package/dist/esm/types/src/packages/formitem/index.d.ts +1 -0
  37. package/dist/esm/types/src/packages/formitem/index.taro.d.ts +1 -0
  38. package/dist/esm/types/src/packages/formitem/types.d.ts +1 -31
  39. package/dist/esm/types/src/packages/inputnumber/inputnumber.d.ts +1 -1
  40. package/dist/esm/types/src/packages/inputnumber/inputnumber.taro.d.ts +1 -1
  41. package/dist/esm/types/src/packages/picker/picker.d.ts +7 -2
  42. package/dist/esm/types/src/packages/picker/picker.taro.d.ts +7 -2
  43. package/dist/esm/types/src/packages/sticky/sticky.d.ts +0 -1
  44. package/dist/esm/types/src/packages/swipe/swipe.d.ts +2 -6
  45. package/dist/esm/types/src/packages/swipe/swipe.taro.d.ts +2 -6
  46. package/dist/esm/types/src/packages/tabbaritem/tabbaritem.d.ts +7 -2
  47. package/dist/esm/types/src/packages/tabbaritem/tabbaritem.taro.d.ts +7 -2
  48. package/dist/esm/types/src/utils/is-forward-ref-component.d.ts +1 -0
  49. package/dist/locales/base.js +1 -1
  50. package/dist/locales/en-US.js +1 -1
  51. package/dist/locales/id-ID.js +1 -1
  52. package/dist/locales/tr-TR.js +1 -1
  53. package/dist/locales/zh-CN.js +1 -1
  54. package/dist/locales/zh-TW.js +1 -1
  55. package/dist/locales/zh-UG.js +1 -1
  56. package/dist/nutui.react.es.js +265 -178
  57. package/dist/nutui.react.umd.js +265 -178
  58. package/dist/packages/actionsheet/actionsheet.scss +6 -6
  59. package/dist/packages/divider/divider.scss +8 -7
  60. package/dist/packages/formitem/formitem.scss +1 -13
  61. package/dist/packages/inputnumber/inputnumber.scss +4 -2
  62. package/dist/packages/layout/layout.scss +0 -2
  63. package/dist/packages/pagination/pagination.scss +8 -30
  64. package/dist/packages/tabbaritem/tabbaritem.scss +1 -0
  65. package/dist/style.css +1 -1
  66. package/dist/style.mjs +1 -1
  67. package/dist/types/packages/animate/animate.d.ts +3 -3
  68. package/dist/types/packages/audio/audio.d.ts +2 -2
  69. package/dist/types/packages/avatar/avatar.d.ts +5 -5
  70. package/dist/types/packages/avatargroup/avatargroup.d.ts +5 -5
  71. package/dist/types/packages/badge/badge.d.ts +1 -1
  72. package/dist/types/packages/button/button.d.ts +5 -4
  73. package/dist/types/packages/cascader/cascader.d.ts +4 -4
  74. package/dist/types/packages/checkboxgroup/checkboxgroup.d.ts +2 -2
  75. package/dist/types/packages/circleprogress/circleprogress.d.ts +2 -2
  76. package/dist/types/packages/divider/divider.d.ts +2 -2
  77. package/dist/types/packages/drag/drag.d.ts +1 -1
  78. package/dist/types/packages/elevator/elevator.d.ts +0 -1
  79. package/dist/types/packages/empty/empty.d.ts +3 -3
  80. package/dist/types/packages/fixednav/fixednav.d.ts +3 -3
  81. package/dist/types/packages/form/context.d.ts +4 -0
  82. package/dist/types/packages/form/form.d.ts +43 -4
  83. package/dist/types/packages/form/index.d.ts +1 -0
  84. package/dist/types/packages/form/types.d.ts +4 -52
  85. package/dist/types/packages/formitem/formitem.d.ts +45 -16
  86. package/dist/types/packages/formitem/index.d.ts +1 -0
  87. package/dist/types/packages/formitem/types.d.ts +1 -31
  88. package/dist/types/packages/grid/grid.d.ts +1 -1
  89. package/dist/types/packages/infiniteloading/infiniteloading.d.ts +1 -1
  90. package/dist/types/packages/inputnumber/inputnumber.d.ts +1 -1
  91. package/dist/types/packages/noticebar/noticebar.d.ts +3 -3
  92. package/dist/types/packages/overlay/overlay.d.ts +1 -1
  93. package/dist/types/packages/pagination/pagination.d.ts +1 -1
  94. package/dist/types/packages/picker/picker.d.ts +7 -2
  95. package/dist/types/packages/popover/popover.d.ts +5 -5
  96. package/dist/types/packages/popup/popup.d.ts +2 -2
  97. package/dist/types/packages/radio/radio.d.ts +2 -2
  98. package/dist/types/packages/searchbar/searchbar.d.ts +7 -7
  99. package/dist/types/packages/step/step.d.ts +3 -3
  100. package/dist/types/packages/steps/steps.d.ts +1 -1
  101. package/dist/types/packages/sticky/sticky.d.ts +1 -2
  102. package/dist/types/packages/swipe/swipe.d.ts +2 -6
  103. package/dist/types/packages/swiper/swiper.d.ts +1 -1
  104. package/dist/types/packages/tabbaritem/tabbaritem.d.ts +27 -2
  105. package/dist/types/packages/tabs/tabs.d.ts +1 -1
  106. package/dist/types/packages/tag/tag.d.ts +1 -1
  107. package/dist/types/packages/timeselect/timeselect.d.ts +2 -2
  108. package/dist/types/packages/toast/toast.d.ts +50 -10
  109. package/dist/types/packages/uploader/uploader.d.ts +17 -17
  110. package/dist/types/utils/is-forward-ref-component.d.ts +1 -0
  111. package/package.json +1 -1
  112. package/dist/esm/types/src/packages/formitem/formitemcontext.d.ts +0 -6
  113. package/dist/types/packages/formitem/formitemcontext.d.ts +0 -6
  114. /package/dist/esm/types/src/packages/form/{useForm.d.ts → useform.d.ts} +0 -0
  115. /package/dist/esm/types/src/packages/form/{useForm.taro.d.ts → useform.taro.d.ts} +0 -0
  116. /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.18 Fri Jun 16 2023 18:36:57 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();
@@ -11437,8 +11441,11 @@ const defaultProps$17 = {
11437
11441
  icon: null,
11438
11442
  active: false,
11439
11443
  index: 0,
11440
- handleClick: (idx) => {
11441
- }
11444
+ value: "",
11445
+ dot: false,
11446
+ max: 99,
11447
+ top: "0",
11448
+ right: "5"
11442
11449
  };
11443
11450
  const TabbarItem = (props) => {
11444
11451
  const {
@@ -11450,8 +11457,12 @@ const TabbarItem = (props) => {
11450
11457
  activeColor,
11451
11458
  inactiveColor,
11452
11459
  index,
11453
- handleClick: handleClick2,
11454
- ...rest
11460
+ value,
11461
+ dot,
11462
+ max,
11463
+ top,
11464
+ right,
11465
+ handleClick: handleClick2
11455
11466
  } = {
11456
11467
  ...defaultProps$17,
11457
11468
  ...props
@@ -11464,6 +11475,14 @@ const TabbarItem = (props) => {
11464
11475
  const titleClass = classNames(boxPrefix, `${boxPrefix}-nav`, {
11465
11476
  [`${boxPrefix}-large`]: !icon
11466
11477
  });
11478
+ const badgeProps = {
11479
+ value,
11480
+ dot,
11481
+ max,
11482
+ top,
11483
+ right,
11484
+ color: activeColor
11485
+ };
11467
11486
  return /* @__PURE__ */ React__default.createElement(
11468
11487
  "div",
11469
11488
  {
@@ -11474,7 +11493,7 @@ const TabbarItem = (props) => {
11474
11493
  },
11475
11494
  onClick: () => handleClick2(index)
11476
11495
  },
11477
- icon ? /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, /* @__PURE__ */ React__default.createElement(Badge, { ...rest }, /* @__PURE__ */ React__default.createElement("div", { className: boxPrefix }, icon)), /* @__PURE__ */ React__default.createElement("div", { className: titleClass }, title)) : /* @__PURE__ */ React__default.createElement(Badge, { ...rest }, /* @__PURE__ */ React__default.createElement("div", { className: titleClass }, title))
11496
+ icon ? /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, /* @__PURE__ */ React__default.createElement(Badge, { ...badgeProps }, /* @__PURE__ */ React__default.createElement("div", { className: boxPrefix }, icon)), /* @__PURE__ */ React__default.createElement("div", { className: titleClass }, title)) : /* @__PURE__ */ React__default.createElement(Badge, { ...badgeProps }, /* @__PURE__ */ React__default.createElement("div", { className: titleClass }, title))
11478
11497
  );
11479
11498
  };
11480
11499
  const defaultProps$16 = {
@@ -13816,7 +13835,7 @@ const Cascader = React__default.forwardRef(InternalCascader);
13816
13835
  Cascader.defaultProps = defaultProps$Z;
13817
13836
  Cascader.displayName = "NutCascader";
13818
13837
  const CheckboxGroupContext = createContext(null);
13819
- const Context = CheckboxGroupContext;
13838
+ const Context$1 = CheckboxGroupContext;
13820
13839
  const defaultProps$Y = {
13821
13840
  max: void 0,
13822
13841
  labelPosition: "right",
@@ -13887,7 +13906,7 @@ const CheckboxGroup = React__default.forwardRef(
13887
13906
  });
13888
13907
  }, [options2, max]);
13889
13908
  return /* @__PURE__ */ React__default.createElement(
13890
- Context.Provider,
13909
+ Context$1.Provider,
13891
13910
  {
13892
13911
  value: {
13893
13912
  labelPosition: labelPosition || "right",
@@ -13950,7 +13969,7 @@ const Checkbox = (props) => {
13950
13969
  ...others
13951
13970
  } = props;
13952
13971
  let { labelPosition, ...rest } = others;
13953
- const ctx2 = useContext(Context);
13972
+ const ctx2 = useContext(Context$1);
13954
13973
  let [innerChecked, setChecked] = usePropsValue({
13955
13974
  value: props.checked,
13956
13975
  defaultValue: props.defaultChecked,
@@ -14331,7 +14350,6 @@ function useRefs() {
14331
14350
  }
14332
14351
  const defaultProps$W = {
14333
14352
  ...ComponentDefaults,
14334
- visible: false,
14335
14353
  title: "",
14336
14354
  options: [],
14337
14355
  value: [],
@@ -14368,12 +14386,26 @@ const InternalPicker = (props, ref) => {
14368
14386
  (_a2 = props.onConfirm) == null ? void 0 : _a2.call(props, setSelectedOptions(), val);
14369
14387
  }
14370
14388
  });
14389
+ const [innerVisible, setInnerVisible] = usePropsValue({
14390
+ value: props.visible,
14391
+ defaultValue: false,
14392
+ finalValue: false
14393
+ });
14371
14394
  const [innerValue, setInnerValue] = useState(selectedValue);
14372
14395
  const [columnIndex, setColumnIndex] = useState(0);
14373
14396
  const pickerRef = useRef(null);
14374
14397
  const [refs, setRefs] = useRefs();
14375
14398
  const [columnsList, setColumnsList] = useState([]);
14376
14399
  const isConfirmEvent = useRef(false);
14400
+ const actions = {
14401
+ open: () => {
14402
+ setInnerVisible(true);
14403
+ },
14404
+ close: () => {
14405
+ setInnerVisible(false);
14406
+ }
14407
+ };
14408
+ useImperativeHandle(ref, () => actions);
14377
14409
  const formatCascade = (columns, values) => {
14378
14410
  const formatted = [];
14379
14411
  let columnOptions = {
@@ -14435,12 +14467,12 @@ const InternalPicker = (props, ref) => {
14435
14467
  };
14436
14468
  useEffect(() => {
14437
14469
  setInnerValue(innerValue !== selectedValue ? selectedValue : innerValue);
14438
- }, [visible]);
14470
+ }, [innerVisible]);
14439
14471
  useEffect(() => {
14440
- if (visible) {
14472
+ if (innerVisible) {
14441
14473
  init();
14442
14474
  }
14443
- }, [options2, visible]);
14475
+ }, [options2, innerVisible]);
14444
14476
  useEffect(() => {
14445
14477
  onChange && onChange(setSelectedOptions(), innerValue, columnIndex);
14446
14478
  }, [innerValue, columnsList]);
@@ -14513,6 +14545,7 @@ const InternalPicker = (props, ref) => {
14513
14545
  }, 0);
14514
14546
  };
14515
14547
  const closePicker = () => {
14548
+ setInnerVisible(false);
14516
14549
  onClose && onClose(setSelectedOptions(), innerValue);
14517
14550
  afterClose && afterClose(setSelectedOptions(), innerValue, pickerRef);
14518
14551
  };
@@ -14521,21 +14554,34 @@ const InternalPicker = (props, ref) => {
14521
14554
  "span",
14522
14555
  {
14523
14556
  className: `${classPrefix2}__cancel-btn`,
14524
- onClick: () => closePicker()
14557
+ onClick: (e) => {
14558
+ e.stopPropagation();
14559
+ closePicker();
14560
+ }
14525
14561
  },
14526
14562
  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));
14563
+ ), /* @__PURE__ */ React__default.createElement("div", { className: `${classPrefix2}__title` }, title || ""), /* @__PURE__ */ React__default.createElement(
14564
+ "span",
14565
+ {
14566
+ className: `${classPrefix2}__confirm-btn`,
14567
+ onClick: (e) => {
14568
+ e.stopPropagation();
14569
+ confirm2();
14570
+ }
14571
+ },
14572
+ locale.confirm
14573
+ ));
14528
14574
  };
14529
- return /* @__PURE__ */ React__default.createElement(
14575
+ return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, typeof children === "function" && children(selectedValue), /* @__PURE__ */ React__default.createElement(
14530
14576
  Popup,
14531
14577
  {
14532
- visible,
14578
+ visible: innerVisible,
14533
14579
  position: "bottom",
14534
14580
  afterClose: () => {
14535
14581
  closePicker();
14536
14582
  }
14537
14583
  },
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) => {
14584
+ /* @__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
14585
  return /* @__PURE__ */ React__default.createElement(
14540
14586
  PickerPanel$1,
14541
14587
  {
@@ -14550,7 +14596,7 @@ const InternalPicker = (props, ref) => {
14550
14596
  }
14551
14597
  );
14552
14598
  })))
14553
- );
14599
+ ));
14554
14600
  };
14555
14601
  const Picker = React__default.forwardRef(InternalPicker);
14556
14602
  const Picker$1 = Picker;
@@ -14854,7 +14900,7 @@ const DatePicker = (props) => {
14854
14900
  };
14855
14901
  DatePicker.defaultProps = defaultProps$V;
14856
14902
  DatePicker.displayName = "NutDatePicker";
14857
- const FormItemContext = createContext({});
14903
+ const Context = createContext({});
14858
14904
  function _extends() {
14859
14905
  _extends = Object.assign ? Object.assign.bind() : function(target) {
14860
14906
  for (var i = 1; i < arguments.length; i++) {
@@ -15908,15 +15954,18 @@ Schema.register = function register(type4, validator) {
15908
15954
  Schema.warning = warning;
15909
15955
  Schema.messages = messages;
15910
15956
  Schema.validators = validators;
15957
+ console.log("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
15911
15958
  class FormStore {
15912
15959
  constructor() {
15913
- __publicField(this, "store", {});
15960
+ // 初始化数据
15961
+ __publicField(this, "initialValues", {});
15914
15962
  // 存放表单中所有的数据 eg. {password: "ddd",username: "123"}
15915
- __publicField(this, "fieldEntities", []);
15963
+ __publicField(this, "store", {});
15916
15964
  // 所有的组件实例
15917
- // 成功和失败的回调
15965
+ __publicField(this, "fieldEntities", []);
15966
+ // 校验成功或失败的回调,onFinish、onFinishFailed
15918
15967
  __publicField(this, "callbacks", {});
15919
- __publicField(this, "errList", []);
15968
+ __publicField(this, "errors", []);
15920
15969
  /**
15921
15970
  * 注册组件实例
15922
15971
  * @param field
@@ -15925,11 +15974,29 @@ class FormStore {
15925
15974
  this.fieldEntities.push(field);
15926
15975
  return () => {
15927
15976
  this.fieldEntities = this.fieldEntities.filter((item) => item != field);
15928
- delete this.store[field.props.name];
15977
+ if (this.store) {
15978
+ delete this.store[field.props.name];
15979
+ }
15929
15980
  };
15930
15981
  });
15982
+ /**
15983
+ * 获取 formItem 的值
15984
+ * @param name
15985
+ */
15931
15986
  __publicField(this, "getFieldValue", (name) => {
15932
- return this.store[name];
15987
+ var _a2;
15988
+ return (_a2 = this.store) == null ? void 0 : _a2[name];
15989
+ });
15990
+ /**
15991
+ * 设置 form 的初始值,之后在 reset 的时候使用
15992
+ * @param values
15993
+ * @param init
15994
+ */
15995
+ __publicField(this, "setInitialValues", (values, init) => {
15996
+ if (init) {
15997
+ this.initialValues = values;
15998
+ this.store = values;
15999
+ }
15933
16000
  });
15934
16001
  /**
15935
16002
  * 存储组件数据
@@ -15944,34 +16011,28 @@ class FormStore {
15944
16011
  const { name } = enetity.props;
15945
16012
  Object.keys(newStore).forEach((key) => {
15946
16013
  if (key === name) {
15947
- enetity.onStoreChange();
16014
+ enetity.onStoreChange("update");
15948
16015
  }
15949
16016
  });
15950
16017
  });
15951
16018
  });
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
- */
16019
+ __publicField(this, "setCallback", (callback) => {
16020
+ this.callbacks = {
16021
+ ...this.callbacks,
16022
+ ...callback
16023
+ };
16024
+ });
15965
16025
  __publicField(this, "validate", () => {
15966
16026
  const err = [];
15967
- this.errList.length = 0;
16027
+ this.errors.length = 0;
15968
16028
  this.fieldEntities.forEach((entity) => {
16029
+ var _a2;
15969
16030
  const { name, rules: rules2 = [] } = entity.props;
15970
16031
  const descriptor = {};
15971
16032
  if (rules2.length) {
15972
16033
  if (rules2.length > 1) {
15973
16034
  descriptor[name] = [];
15974
- rules2.map((v) => {
16035
+ rules2.forEach((v) => {
15975
16036
  descriptor[name].push(v);
15976
16037
  });
15977
16038
  } else {
@@ -15979,39 +16040,36 @@ class FormStore {
15979
16040
  }
15980
16041
  }
15981
16042
  const validator = new Schema(descriptor);
15982
- validator.validate({ [name]: this.store[name] }, (errors) => {
16043
+ validator.messages();
16044
+ validator.validate({ [name]: (_a2 = this.store) == null ? void 0 : _a2[name] }, (errors) => {
15983
16045
  if (errors) {
15984
16046
  err.push(...errors);
15985
- this.errList.push(...errors);
16047
+ this.errors.push(...errors);
15986
16048
  }
15987
- entity.onStoreChange();
16049
+ entity.onStoreChange("validate");
15988
16050
  });
15989
16051
  });
15990
16052
  return err;
15991
16053
  });
15992
- __publicField(this, "setCallback", (callback) => {
15993
- this.callbacks = {
15994
- ...this.callbacks,
15995
- ...callback
15996
- };
15997
- });
15998
16054
  __publicField(this, "submit", () => {
15999
16055
  var _a2, _b, _c, _d;
16000
- const err = this.validate();
16001
- if (err.length === 0) {
16056
+ const errors = this.validate();
16057
+ if (errors.length === 0) {
16002
16058
  (_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);
16059
+ } else if (errors.length > 0) {
16060
+ (_d = (_c = this.callbacks).onFinishFailed) == null ? void 0 : _d.call(_c, this.store, errors);
16005
16061
  }
16006
16062
  });
16007
16063
  __publicField(this, "resetFields", () => {
16008
- this.errList.length = 0;
16009
- this.fieldEntities.forEach((enetity) => {
16010
- enetity.onStoreChange();
16064
+ this.errors.length = 0;
16065
+ this.store = this.initialValues;
16066
+ this.fieldEntities.forEach((entity) => {
16067
+ entity.onStoreChange("reset");
16011
16068
  });
16012
16069
  });
16013
16070
  __publicField(this, "getForm", () => {
16014
16071
  return {
16072
+ setInitialValues: this.setInitialValues,
16015
16073
  setCallback: this.setCallback,
16016
16074
  registerField: this.registerField,
16017
16075
  getFieldValue: this.getFieldValue,
@@ -16019,12 +16077,12 @@ class FormStore {
16019
16077
  resetFields: this.resetFields,
16020
16078
  submit: this.submit,
16021
16079
  store: this.store,
16022
- errList: this.errList,
16080
+ errors: this.errors,
16023
16081
  fieldEntities: this.fieldEntities
16024
16082
  };
16025
16083
  });
16026
16084
  this.callbacks = {
16027
- onFinish: (value) => {
16085
+ onFinish: () => {
16028
16086
  },
16029
16087
  onFinishFailed: () => {
16030
16088
  }
@@ -16043,98 +16101,113 @@ const useForm = (form) => {
16043
16101
  }
16044
16102
  return [formRef.current];
16045
16103
  };
16104
+ function isForwardRefComponent(component) {
16105
+ return component.type && component.type.$$typeof && // eslint-disable-next-line react/display-name
16106
+ React__default.forwardRef(
16107
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
16108
+ // @ts-ignore
16109
+ () => {
16110
+ }
16111
+ ).$$typeof === component.type.$$typeof;
16112
+ }
16046
16113
  const defaultProps$U = {
16047
16114
  ...ComponentDefaults,
16115
+ required: false,
16048
16116
  name: "",
16049
16117
  label: "",
16050
- className: "",
16051
16118
  rules: [{ required: false, message: "" }],
16052
- disabled: false,
16053
- labelWidth: 90,
16054
- errorMessageAlign: "left",
16055
- showErrorLine: true,
16056
- showErrorMessage: true,
16057
- initialValue: ""
16119
+ errorMessageAlign: "left"
16058
16120
  };
16059
16121
  class FormItem extends React__default.Component {
16060
- constructor() {
16061
- super(...arguments);
16122
+ constructor(props) {
16123
+ super(props);
16062
16124
  __publicField(this, "cancelRegister");
16063
- __publicField(this, "isInitialValue", false);
16125
+ __publicField(this, "componentRef");
16064
16126
  // children添加value属性和onChange事件
16065
16127
  __publicField(this, "getControlled", (children) => {
16066
- var _a2, _b;
16067
- const { getFieldValue, setFieldsValue } = this.context;
16128
+ var _a2;
16129
+ const { setFieldsValue, getFieldValue } = this.context;
16068
16130
  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;
16131
+ if ((_a2 = children == null ? void 0 : children.props) == null ? void 0 : _a2.defaultValue) {
16132
+ console.warn("通过 initialValue 设置初始值");
16133
+ }
16134
+ const controlled = {
16135
+ ...children.props,
16136
+ [this.props.valuePropName || "value"]: getFieldValue(name) || this.props.initialValue,
16137
+ [this.props.trigger || "onChange"]: (...args) => {
16138
+ const originOnChange = children.props[this.props.trigger || "onChange"];
16080
16139
  if (originOnChange) {
16081
- originOnChange(event);
16140
+ originOnChange(...args);
16082
16141
  }
16083
- let newValue = event;
16084
- switch (type4) {
16085
- case "checkbox":
16086
- newValue = event.target.value;
16087
- break;
16142
+ let [next] = args;
16143
+ if (this.props.getValueFromEvent) {
16144
+ next = this.props.getValueFromEvent(...args);
16088
16145
  }
16089
- setFieldsValue({ [name]: newValue });
16146
+ setFieldsValue({ [name]: next });
16090
16147
  }
16091
16148
  };
16149
+ if (isForwardRefComponent(children)) {
16150
+ controlled.ref = (componentInstance) => {
16151
+ const originRef = children.ref;
16152
+ if (originRef) {
16153
+ if (typeof originRef === "function") {
16154
+ originRef(componentInstance);
16155
+ }
16156
+ if ("current" in originRef) {
16157
+ originRef.current = componentInstance;
16158
+ }
16159
+ }
16160
+ this.componentRef = componentInstance;
16161
+ };
16162
+ }
16163
+ return controlled;
16164
+ });
16165
+ __publicField(this, "refresh", () => {
16166
+ this.setState(({ resetCount }) => ({
16167
+ resetCount: resetCount + 1
16168
+ }));
16092
16169
  });
16093
- __publicField(this, "onStoreChange", () => {
16094
- this.forceUpdate();
16170
+ __publicField(this, "onStoreChange", (type4) => {
16171
+ if (type4 === "reset") {
16172
+ this.refresh();
16173
+ } else {
16174
+ this.forceUpdate();
16175
+ }
16095
16176
  });
16096
16177
  __publicField(this, "renderLayout", (childNode) => {
16097
16178
  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
- } = {
16179
+ const { label, name, required: required4, className, style, errorMessageAlign } = {
16108
16180
  ...defaultProps$U,
16109
16181
  ...this.props
16110
16182
  };
16111
- const item = ((_a2 = this.context.errList) == null ? void 0 : _a2.length) > 0 && ((_b = this.context.errList) == null ? void 0 : _b.filter((item2) => {
16183
+ const item = ((_a2 = this.context.errors) == null ? void 0 : _a2.length) > 0 && ((_b = this.context.errors) == null ? void 0 : _b.filter((item2) => {
16112
16184
  return item2.field === name;
16113
16185
  }));
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",
16186
+ const { starPosition } = this.context;
16187
+ const renderStar = required4 && /* @__PURE__ */ React__default.createElement("i", { className: "required" });
16188
+ const renderLabel = /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, starPosition === "left" ? renderStar : null, label, starPosition === "right" ? renderStar : null);
16189
+ return /* @__PURE__ */ React__default.createElement(
16190
+ Cell,
16128
16191
  {
16129
- className: "nut-form-item__body__tips",
16130
- style: { textAlign: errorMessageAlign }
16192
+ className: `nut-form-item ${className}`,
16193
+ style,
16194
+ onClick: (e) => this.props.onClick && this.props.onClick(e, this.componentRef)
16131
16195
  },
16132
- item[0].message
16133
- )));
16134
- });
16135
- __publicField(this, "pxCheck", (value) => {
16136
- return Number.isNaN(Number(value)) ? String(value) : `${value}px`;
16196
+ label ? /* @__PURE__ */ React__default.createElement("div", { className: "nut-cell__title nut-form-item__label" }, renderLabel) : null,
16197
+ /* @__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(
16198
+ "div",
16199
+ {
16200
+ className: "nut-form-item__body__tips",
16201
+ style: { textAlign: errorMessageAlign }
16202
+ },
16203
+ item[0].message
16204
+ ))
16205
+ );
16137
16206
  });
16207
+ this.componentRef = React__default.createRef();
16208
+ this.state = {
16209
+ resetCount: 1
16210
+ };
16138
16211
  }
16139
16212
  componentDidMount() {
16140
16213
  this.cancelRegister = this.context.registerField(this);
@@ -16145,81 +16218,86 @@ class FormItem extends React__default.Component {
16145
16218
  }
16146
16219
  }
16147
16220
  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
- }
16221
+ const { children } = this.props;
16222
+ const child = Array.isArray(children) ? children[0] : children;
16156
16223
  const returnChildNode = React__default.cloneElement(
16157
- restCNode,
16158
- this.getControlled(restCNode)
16224
+ child,
16225
+ this.getControlled(child)
16159
16226
  );
16160
- return this.renderLayout(returnChildNode);
16227
+ return /* @__PURE__ */ React__default.createElement(React__default.Fragment, { key: this.state.resetCount }, this.renderLayout(returnChildNode));
16161
16228
  }
16162
16229
  }
16163
16230
  __publicField(FormItem, "defaultProps", defaultProps$U);
16164
- __publicField(FormItem, "contextType", FormItemContext);
16231
+ __publicField(FormItem, "contextType", Context);
16165
16232
  const defaultProps$T = {
16166
16233
  ...ComponentDefaults,
16167
- className: "",
16168
- style: void 0,
16169
- form: {},
16170
- labelPosition: "Right",
16171
- formGroupTitle: "",
16172
- onFinish: (obj) => {
16173
- },
16174
- onFinishFailed: (value) => {
16234
+ labelPosition: "right",
16235
+ starPosition: "left",
16236
+ onFinish: (values) => {
16175
16237
  },
16176
- starPositon: "Left"
16238
+ onFinishFailed: (values, errorFields) => {
16239
+ }
16177
16240
  };
16178
16241
  const PositionInfo = {
16179
- Top: "form-layout-top",
16180
- Left: "form-layout-left",
16181
- Right: "form-layout-right"
16242
+ top: "form-layout-top",
16243
+ left: "form-layout-left",
16244
+ right: "form-layout-right"
16182
16245
  };
16183
16246
  const Form = (props) => {
16247
+ const classPrefix2 = "nut-form";
16184
16248
  const {
16249
+ className,
16250
+ style,
16251
+ footer,
16185
16252
  children,
16253
+ initialValues,
16186
16254
  onFinish,
16187
16255
  onFinishFailed,
16188
16256
  labelPosition,
16189
- starPositon,
16190
- form,
16191
- ...rest
16257
+ starPosition,
16258
+ form
16192
16259
  } = {
16193
16260
  ...defaultProps$T,
16194
16261
  ...props
16195
16262
  };
16196
- let formInstance = {};
16197
- if (Object.keys(form).length !== 0) {
16263
+ let formInstance;
16264
+ if (form !== void 0) {
16198
16265
  formInstance = form;
16199
16266
  } else {
16200
16267
  [formInstance] = useForm();
16201
16268
  }
16202
- formInstance.starPositon = starPositon;
16203
- const { setCallback, submit, resetFields } = formInstance;
16269
+ formInstance.starPosition = starPosition;
16270
+ const { setCallback, submit, resetFields, setInitialValues } = formInstance;
16204
16271
  setCallback({
16205
16272
  onFinish,
16206
16273
  onFinishFailed
16207
16274
  });
16275
+ const mountRef = React__default.useRef(false);
16276
+ setInitialValues(initialValues, !mountRef.current);
16277
+ if (!mountRef.current) {
16278
+ mountRef.current = true;
16279
+ }
16208
16280
  return /* @__PURE__ */ React__default.createElement(
16209
16281
  "form",
16210
16282
  {
16211
- className: `nut-form ${PositionInfo[labelPosition]} ${props.className}`,
16212
- style: props.style,
16283
+ className: classNames(
16284
+ classPrefix2,
16285
+ className,
16286
+ PositionInfo[labelPosition]
16287
+ ),
16288
+ style,
16213
16289
  onSubmit: (e) => {
16214
16290
  e.preventDefault();
16291
+ e.stopPropagation();
16215
16292
  submit();
16216
16293
  },
16217
16294
  onReset: (e) => {
16218
16295
  e.preventDefault();
16296
+ e.stopPropagation();
16219
16297
  resetFields();
16220
16298
  }
16221
16299
  },
16222
- /* @__PURE__ */ React__default.createElement(CellGroup, null, /* @__PURE__ */ React__default.createElement(FormItemContext.Provider, { value: formInstance }, children))
16300
+ /* @__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
16301
  );
16224
16302
  };
16225
16303
  Form.defaultProps = defaultProps$T;
@@ -16435,7 +16513,7 @@ const defaultProps$R = {
16435
16513
  disabled: false,
16436
16514
  min: 1,
16437
16515
  max: 9999,
16438
- readonly: false,
16516
+ readOnly: false,
16439
16517
  allowEmpty: false,
16440
16518
  defaultValue: 0,
16441
16519
  step: 1,
@@ -16449,7 +16527,7 @@ const InputNumber = (props) => {
16449
16527
  disabled,
16450
16528
  min,
16451
16529
  max,
16452
- readonly,
16530
+ readOnly,
16453
16531
  value,
16454
16532
  defaultValue,
16455
16533
  allowEmpty,
@@ -16608,14 +16686,14 @@ const InputNumber = (props) => {
16608
16686
  const focusValue = (e) => {
16609
16687
  if (disabled)
16610
16688
  return;
16611
- if (readonly)
16689
+ if (readOnly)
16612
16690
  return;
16613
16691
  onFocus && onFocus(e);
16614
16692
  };
16615
16693
  const burValue = (e) => {
16616
16694
  if (disabled)
16617
16695
  return;
16618
- if (readonly)
16696
+ if (readOnly)
16619
16697
  return;
16620
16698
  const input = e.target;
16621
16699
  let value2 = input.valueAsNumber;
@@ -16643,7 +16721,7 @@ const InputNumber = (props) => {
16643
16721
  min,
16644
16722
  max,
16645
16723
  disabled,
16646
- readOnly: readonly,
16724
+ readOnly,
16647
16725
  value: _checked,
16648
16726
  onInput: changeFormatValue,
16649
16727
  onBlur: burFormatValue,
@@ -16656,7 +16734,7 @@ const InputNumber = (props) => {
16656
16734
  min,
16657
16735
  max,
16658
16736
  disabled,
16659
- readOnly: readonly,
16737
+ readOnly,
16660
16738
  value: _checked,
16661
16739
  onInput: changeValue,
16662
16740
  onBlur: burValue,
@@ -17848,7 +17926,7 @@ const SearchBar = (props) => {
17848
17926
  return /* @__PURE__ */ React__default.createElement(
17849
17927
  "input",
17850
17928
  {
17851
- className: `${classPrefix2}__input ${shape === "round" ? `${classPrefix2}__round` : ""} ${clearable ? `${classPrefix2}__input-clear` : ""}`,
17929
+ className: `${classPrefix2}__input ${clearable ? `${classPrefix2}__input-clear` : ""}`,
17852
17930
  ref: searchRef,
17853
17931
  style: { ...props.style },
17854
17932
  value: value || "",
@@ -17921,7 +17999,16 @@ const SearchBar = (props) => {
17921
17999
  style: { ...props.style }
17922
18000
  },
17923
18001
  renderLeft(),
17924
- /* @__PURE__ */ React__default.createElement("div", { className: `${classPrefix2}__content` }, renderLeftIn(), renderField(), renderRightIn(), clearable && value && handleClear()),
18002
+ /* @__PURE__ */ React__default.createElement(
18003
+ "div",
18004
+ {
18005
+ className: `${classPrefix2}__content ${shape === "round" ? `${classPrefix2}__round` : ""}`
18006
+ },
18007
+ renderLeftIn(),
18008
+ renderField(),
18009
+ renderRightIn(),
18010
+ clearable && value && handleClear()
18011
+ ),
17925
18012
  renderRight()
17926
18013
  );
17927
18014
  };
@@ -20329,7 +20416,7 @@ const Popover = (props) => {
20329
20416
  return styles;
20330
20417
  };
20331
20418
  const getRootPosition = () => {
20332
- let styles = {};
20419
+ const styles = {};
20333
20420
  if (!rootPosition)
20334
20421
  return {};
20335
20422
  const contentWidth = elWidth;
@@ -20339,34 +20426,34 @@ const Popover = (props) => {
20339
20426
  const skew = location.split("-")[1];
20340
20427
  let cross = 0;
20341
20428
  let parallel = 0;
20342
- if (Array.isArray(offset) && offset.length == 2) {
20429
+ if (Array.isArray(offset) && offset.length === 2) {
20343
20430
  cross += +offset[1];
20344
20431
  parallel += +offset[0];
20345
20432
  }
20346
20433
  if (width) {
20347
20434
  if (["bottom", "top"].includes(direction)) {
20348
- const h = direction == "bottom" ? height + cross : -(contentHeight + cross);
20435
+ const h = direction === "bottom" ? height + cross : -(contentHeight + cross);
20349
20436
  styles.top = `${top + h}px`;
20350
20437
  if (!skew) {
20351
20438
  styles.left = `${-(contentWidth - width) / 2 + left + parallel}px`;
20352
20439
  }
20353
- if (skew == "start") {
20440
+ if (skew === "start") {
20354
20441
  styles.left = `${left + parallel}px`;
20355
20442
  }
20356
- if (skew == "end") {
20443
+ if (skew === "end") {
20357
20444
  styles.left = `${right + parallel}px`;
20358
20445
  }
20359
20446
  }
20360
20447
  if (["left", "right"].includes(direction)) {
20361
- const contentW = direction == "left" ? -(contentWidth + cross) : width + cross;
20448
+ const contentW = direction === "left" ? -(contentWidth + cross) : width + cross;
20362
20449
  styles.left = `${left + contentW}px`;
20363
20450
  if (!skew) {
20364
20451
  styles.top = `${top - contentHeight / 2 + height / 2 - 4 + parallel}px`;
20365
20452
  }
20366
- if (skew == "start") {
20453
+ if (skew === "start") {
20367
20454
  styles.top = `${top + parallel}px`;
20368
20455
  }
20369
- if (skew == "end") {
20456
+ if (skew === "end") {
20370
20457
  styles.top = `${top + height + parallel}px`;
20371
20458
  }
20372
20459
  }
@@ -20818,7 +20905,7 @@ const defaultProps$s = {
20818
20905
  name: ""
20819
20906
  };
20820
20907
  const Swipe = forwardRef((props, instanceRef) => {
20821
- const swipeBem = cn("swipe");
20908
+ const classPrefix2 = "nut-swipe";
20822
20909
  const touch = useTouch();
20823
20910
  const { children, className, style } = { ...defaultProps$s, ...props };
20824
20911
  const root2 = useRef();
@@ -20939,7 +21026,7 @@ const Swipe = forwardRef((props, instanceRef) => {
20939
21026
  "div",
20940
21027
  {
20941
21028
  ref: measuredRef,
20942
- className: `${swipeBem(side)}`,
21029
+ className: `${classPrefix2}__${side}`,
20943
21030
  onClick: (e) => handleOperate(e, side)
20944
21031
  },
20945
21032
  props[`${side}Action`]
@@ -20979,13 +21066,13 @@ const Swipe = forwardRef((props, instanceRef) => {
20979
21066
  "div",
20980
21067
  {
20981
21068
  ref: root2,
20982
- className: classNames(swipeBem(), className),
21069
+ className: classNames(classPrefix2, className),
20983
21070
  onTouchStart: (e) => onTouchStart(e),
20984
21071
  onTouchMove: (e) => onTouchMove(e),
20985
21072
  onTouchEnd: (e) => onTouchEnd(e),
20986
21073
  style
20987
21074
  },
20988
- /* @__PURE__ */ React__default.createElement("div", { className: `${swipeBem("wrapper")}`, style: wrapperStyle }, renderActionContent("left", leftRef), children, renderActionContent("right", rightRef))
21075
+ /* @__PURE__ */ React__default.createElement("div", { className: `${classPrefix2}__wrapper`, style: wrapperStyle }, renderActionContent("left", leftRef), children, renderActionContent("right", rightRef))
20989
21076
  );
20990
21077
  });
20991
21078
  Swipe.defaultProps = defaultProps$s;