@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
@@ -9,7 +9,7 @@ var __publicField = (obj, key, value) => {
9
9
  return value;
10
10
  };
11
11
  /*!
12
- * @nutui/nutui-react v2.0.0-alpha.16 Fri Jun 09 2023 18:29:35 GMT+0800 (China Standard Time)
12
+ * @nutui/nutui-react v2.0.0-alpha.18 Fri Jun 16 2023 18:36:57 GMT+0800 (China Standard Time)
13
13
  * (c) 2023 @jdf2e.
14
14
  * Released under the MIT License.
15
15
  */
@@ -2420,6 +2420,7 @@ Check the top-level render call using <` + t + ">.");
2420
2420
  disabled: false,
2421
2421
  block: false,
2422
2422
  icon: null,
2423
+ nativeType: "button",
2423
2424
  onClick: (e) => {
2424
2425
  }
2425
2426
  };
@@ -2439,6 +2440,7 @@ Check the top-level render call using <` + t + ">.");
2439
2440
  onClick,
2440
2441
  className,
2441
2442
  style,
2443
+ nativeType,
2442
2444
  ...rest
2443
2445
  } = {
2444
2446
  ...defaultProps$1r,
@@ -2472,6 +2474,7 @@ Check the top-level render call using <` + t + ">.");
2472
2474
  {
2473
2475
  ...rest,
2474
2476
  ref,
2477
+ type: nativeType,
2475
2478
  className: classNames(
2476
2479
  prefixCls,
2477
2480
  className,
@@ -11180,6 +11183,7 @@ Please add \`${key}Action\` when creating your handler.`);
11180
11183
  }
11181
11184
  };
11182
11185
  const onHandleClickOverlay = (e) => {
11186
+ e.stopPropagation();
11183
11187
  if (closeOnOverlayClick) {
11184
11188
  const closed = onClickOverlay && onClickOverlay(e);
11185
11189
  closed && close();
@@ -11455,8 +11459,11 @@ Please add \`${key}Action\` when creating your handler.`);
11455
11459
  icon: null,
11456
11460
  active: false,
11457
11461
  index: 0,
11458
- handleClick: (idx) => {
11459
- }
11462
+ value: "",
11463
+ dot: false,
11464
+ max: 99,
11465
+ top: "0",
11466
+ right: "5"
11460
11467
  };
11461
11468
  const TabbarItem = (props) => {
11462
11469
  const {
@@ -11468,8 +11475,12 @@ Please add \`${key}Action\` when creating your handler.`);
11468
11475
  activeColor,
11469
11476
  inactiveColor,
11470
11477
  index,
11471
- handleClick: handleClick2,
11472
- ...rest
11478
+ value,
11479
+ dot,
11480
+ max,
11481
+ top,
11482
+ right,
11483
+ handleClick: handleClick2
11473
11484
  } = {
11474
11485
  ...defaultProps$17,
11475
11486
  ...props
@@ -11482,6 +11493,14 @@ Please add \`${key}Action\` when creating your handler.`);
11482
11493
  const titleClass = classNames(boxPrefix, `${boxPrefix}-nav`, {
11483
11494
  [`${boxPrefix}-large`]: !icon
11484
11495
  });
11496
+ const badgeProps = {
11497
+ value,
11498
+ dot,
11499
+ max,
11500
+ top,
11501
+ right,
11502
+ color: activeColor
11503
+ };
11485
11504
  return /* @__PURE__ */ React.createElement(
11486
11505
  "div",
11487
11506
  {
@@ -11492,7 +11511,7 @@ Please add \`${key}Action\` when creating your handler.`);
11492
11511
  },
11493
11512
  onClick: () => handleClick2(index)
11494
11513
  },
11495
- icon ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(Badge, { ...rest }, /* @__PURE__ */ React.createElement("div", { className: boxPrefix }, icon)), /* @__PURE__ */ React.createElement("div", { className: titleClass }, title)) : /* @__PURE__ */ React.createElement(Badge, { ...rest }, /* @__PURE__ */ React.createElement("div", { className: titleClass }, title))
11514
+ icon ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(Badge, { ...badgeProps }, /* @__PURE__ */ React.createElement("div", { className: boxPrefix }, icon)), /* @__PURE__ */ React.createElement("div", { className: titleClass }, title)) : /* @__PURE__ */ React.createElement(Badge, { ...badgeProps }, /* @__PURE__ */ React.createElement("div", { className: titleClass }, title))
11496
11515
  );
11497
11516
  };
11498
11517
  const defaultProps$16 = {
@@ -13834,7 +13853,7 @@ Please add \`${key}Action\` when creating your handler.`);
13834
13853
  Cascader.defaultProps = defaultProps$Z;
13835
13854
  Cascader.displayName = "NutCascader";
13836
13855
  const CheckboxGroupContext = React.createContext(null);
13837
- const Context = CheckboxGroupContext;
13856
+ const Context$1 = CheckboxGroupContext;
13838
13857
  const defaultProps$Y = {
13839
13858
  max: void 0,
13840
13859
  labelPosition: "right",
@@ -13905,7 +13924,7 @@ Please add \`${key}Action\` when creating your handler.`);
13905
13924
  });
13906
13925
  }, [options2, max]);
13907
13926
  return /* @__PURE__ */ React.createElement(
13908
- Context.Provider,
13927
+ Context$1.Provider,
13909
13928
  {
13910
13929
  value: {
13911
13930
  labelPosition: labelPosition || "right",
@@ -13968,7 +13987,7 @@ Please add \`${key}Action\` when creating your handler.`);
13968
13987
  ...others
13969
13988
  } = props;
13970
13989
  let { labelPosition, ...rest } = others;
13971
- const ctx2 = React.useContext(Context);
13990
+ const ctx2 = React.useContext(Context$1);
13972
13991
  let [innerChecked, setChecked] = usePropsValue({
13973
13992
  value: props.checked,
13974
13993
  defaultValue: props.defaultChecked,
@@ -14349,7 +14368,6 @@ Please add \`${key}Action\` when creating your handler.`);
14349
14368
  }
14350
14369
  const defaultProps$W = {
14351
14370
  ...ComponentDefaults,
14352
- visible: false,
14353
14371
  title: "",
14354
14372
  options: [],
14355
14373
  value: [],
@@ -14386,12 +14404,26 @@ Please add \`${key}Action\` when creating your handler.`);
14386
14404
  (_a2 = props.onConfirm) == null ? void 0 : _a2.call(props, setSelectedOptions(), val);
14387
14405
  }
14388
14406
  });
14407
+ const [innerVisible, setInnerVisible] = usePropsValue({
14408
+ value: props.visible,
14409
+ defaultValue: false,
14410
+ finalValue: false
14411
+ });
14389
14412
  const [innerValue, setInnerValue] = React.useState(selectedValue);
14390
14413
  const [columnIndex, setColumnIndex] = React.useState(0);
14391
14414
  const pickerRef = React.useRef(null);
14392
14415
  const [refs, setRefs] = useRefs();
14393
14416
  const [columnsList, setColumnsList] = React.useState([]);
14394
14417
  const isConfirmEvent = React.useRef(false);
14418
+ const actions = {
14419
+ open: () => {
14420
+ setInnerVisible(true);
14421
+ },
14422
+ close: () => {
14423
+ setInnerVisible(false);
14424
+ }
14425
+ };
14426
+ React.useImperativeHandle(ref, () => actions);
14395
14427
  const formatCascade = (columns, values) => {
14396
14428
  const formatted = [];
14397
14429
  let columnOptions = {
@@ -14453,12 +14485,12 @@ Please add \`${key}Action\` when creating your handler.`);
14453
14485
  };
14454
14486
  React.useEffect(() => {
14455
14487
  setInnerValue(innerValue !== selectedValue ? selectedValue : innerValue);
14456
- }, [visible]);
14488
+ }, [innerVisible]);
14457
14489
  React.useEffect(() => {
14458
- if (visible) {
14490
+ if (innerVisible) {
14459
14491
  init();
14460
14492
  }
14461
- }, [options2, visible]);
14493
+ }, [options2, innerVisible]);
14462
14494
  React.useEffect(() => {
14463
14495
  onChange && onChange(setSelectedOptions(), innerValue, columnIndex);
14464
14496
  }, [innerValue, columnsList]);
@@ -14531,6 +14563,7 @@ Please add \`${key}Action\` when creating your handler.`);
14531
14563
  }, 0);
14532
14564
  };
14533
14565
  const closePicker = () => {
14566
+ setInnerVisible(false);
14534
14567
  onClose && onClose(setSelectedOptions(), innerValue);
14535
14568
  afterClose && afterClose(setSelectedOptions(), innerValue, pickerRef);
14536
14569
  };
@@ -14539,21 +14572,34 @@ Please add \`${key}Action\` when creating your handler.`);
14539
14572
  "span",
14540
14573
  {
14541
14574
  className: `${classPrefix2}__cancel-btn`,
14542
- onClick: () => closePicker()
14575
+ onClick: (e) => {
14576
+ e.stopPropagation();
14577
+ closePicker();
14578
+ }
14543
14579
  },
14544
14580
  locale.cancel
14545
- ), /* @__PURE__ */ React.createElement("div", { className: `${classPrefix2}__title` }, title || ""), /* @__PURE__ */ React.createElement("span", { className: `${classPrefix2}__confirm-btn`, onClick: confirm2 }, locale.confirm));
14581
+ ), /* @__PURE__ */ React.createElement("div", { className: `${classPrefix2}__title` }, title || ""), /* @__PURE__ */ React.createElement(
14582
+ "span",
14583
+ {
14584
+ className: `${classPrefix2}__confirm-btn`,
14585
+ onClick: (e) => {
14586
+ e.stopPropagation();
14587
+ confirm2();
14588
+ }
14589
+ },
14590
+ locale.confirm
14591
+ ));
14546
14592
  };
14547
- return /* @__PURE__ */ React.createElement(
14593
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, typeof children === "function" && children(selectedValue), /* @__PURE__ */ React.createElement(
14548
14594
  Popup,
14549
14595
  {
14550
- visible,
14596
+ visible: innerVisible,
14551
14597
  position: "bottom",
14552
14598
  afterClose: () => {
14553
14599
  closePicker();
14554
14600
  }
14555
14601
  },
14556
- /* @__PURE__ */ React.createElement("div", { className: classes, style, ...rest }, renderTitleBar(), children, /* @__PURE__ */ React.createElement("div", { className: `${classPrefix2}__panel`, ref: pickerRef }, columnsList == null ? void 0 : columnsList.map((item, index) => {
14602
+ /* @__PURE__ */ React.createElement("div", { className: classes, style, ...rest }, renderTitleBar(), typeof children !== "function" && children, /* @__PURE__ */ React.createElement("div", { className: `${classPrefix2}__panel`, ref: pickerRef }, columnsList == null ? void 0 : columnsList.map((item, index) => {
14557
14603
  return /* @__PURE__ */ React.createElement(
14558
14604
  PickerPanel$1,
14559
14605
  {
@@ -14568,7 +14614,7 @@ Please add \`${key}Action\` when creating your handler.`);
14568
14614
  }
14569
14615
  );
14570
14616
  })))
14571
- );
14617
+ ));
14572
14618
  };
14573
14619
  const Picker = React.forwardRef(InternalPicker);
14574
14620
  const Picker$1 = Picker;
@@ -14872,7 +14918,7 @@ Please add \`${key}Action\` when creating your handler.`);
14872
14918
  };
14873
14919
  DatePicker.defaultProps = defaultProps$V;
14874
14920
  DatePicker.displayName = "NutDatePicker";
14875
- const FormItemContext = React.createContext({});
14921
+ const Context = React.createContext({});
14876
14922
  function _extends() {
14877
14923
  _extends = Object.assign ? Object.assign.bind() : function(target) {
14878
14924
  for (var i = 1; i < arguments.length; i++) {
@@ -15926,15 +15972,18 @@ Please add \`${key}Action\` when creating your handler.`);
15926
15972
  Schema.warning = warning;
15927
15973
  Schema.messages = messages;
15928
15974
  Schema.validators = validators;
15975
+ console.log("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
15929
15976
  class FormStore {
15930
15977
  constructor() {
15931
- __publicField(this, "store", {});
15978
+ // 初始化数据
15979
+ __publicField(this, "initialValues", {});
15932
15980
  // 存放表单中所有的数据 eg. {password: "ddd",username: "123"}
15933
- __publicField(this, "fieldEntities", []);
15981
+ __publicField(this, "store", {});
15934
15982
  // 所有的组件实例
15935
- // 成功和失败的回调
15983
+ __publicField(this, "fieldEntities", []);
15984
+ // 校验成功或失败的回调,onFinish、onFinishFailed
15936
15985
  __publicField(this, "callbacks", {});
15937
- __publicField(this, "errList", []);
15986
+ __publicField(this, "errors", []);
15938
15987
  /**
15939
15988
  * 注册组件实例
15940
15989
  * @param field
@@ -15943,11 +15992,29 @@ Please add \`${key}Action\` when creating your handler.`);
15943
15992
  this.fieldEntities.push(field);
15944
15993
  return () => {
15945
15994
  this.fieldEntities = this.fieldEntities.filter((item) => item != field);
15946
- delete this.store[field.props.name];
15995
+ if (this.store) {
15996
+ delete this.store[field.props.name];
15997
+ }
15947
15998
  };
15948
15999
  });
16000
+ /**
16001
+ * 获取 formItem 的值
16002
+ * @param name
16003
+ */
15949
16004
  __publicField(this, "getFieldValue", (name) => {
15950
- return this.store[name];
16005
+ var _a2;
16006
+ return (_a2 = this.store) == null ? void 0 : _a2[name];
16007
+ });
16008
+ /**
16009
+ * 设置 form 的初始值,之后在 reset 的时候使用
16010
+ * @param values
16011
+ * @param init
16012
+ */
16013
+ __publicField(this, "setInitialValues", (values, init) => {
16014
+ if (init) {
16015
+ this.initialValues = values;
16016
+ this.store = values;
16017
+ }
15951
16018
  });
15952
16019
  /**
15953
16020
  * 存储组件数据
@@ -15962,34 +16029,28 @@ Please add \`${key}Action\` when creating your handler.`);
15962
16029
  const { name } = enetity.props;
15963
16030
  Object.keys(newStore).forEach((key) => {
15964
16031
  if (key === name) {
15965
- enetity.onStoreChange();
16032
+ enetity.onStoreChange("update");
15966
16033
  }
15967
16034
  });
15968
16035
  });
15969
16036
  });
15970
- /**
15971
- * 表单校验
15972
- * rules: { required: true, message: '' }
15973
- * descriptor: {
15974
- * username: {
15975
- * type: 'string',
15976
- * required: true,
15977
- * validator: (rule, value) => {
15978
- * return /^[a-zA-Z0-9]+$/.test(value)
15979
- * },
15980
- * },
15981
- * }
15982
- */
16037
+ __publicField(this, "setCallback", (callback) => {
16038
+ this.callbacks = {
16039
+ ...this.callbacks,
16040
+ ...callback
16041
+ };
16042
+ });
15983
16043
  __publicField(this, "validate", () => {
15984
16044
  const err = [];
15985
- this.errList.length = 0;
16045
+ this.errors.length = 0;
15986
16046
  this.fieldEntities.forEach((entity) => {
16047
+ var _a2;
15987
16048
  const { name, rules: rules2 = [] } = entity.props;
15988
16049
  const descriptor = {};
15989
16050
  if (rules2.length) {
15990
16051
  if (rules2.length > 1) {
15991
16052
  descriptor[name] = [];
15992
- rules2.map((v) => {
16053
+ rules2.forEach((v) => {
15993
16054
  descriptor[name].push(v);
15994
16055
  });
15995
16056
  } else {
@@ -15997,39 +16058,36 @@ Please add \`${key}Action\` when creating your handler.`);
15997
16058
  }
15998
16059
  }
15999
16060
  const validator = new Schema(descriptor);
16000
- validator.validate({ [name]: this.store[name] }, (errors) => {
16061
+ validator.messages();
16062
+ validator.validate({ [name]: (_a2 = this.store) == null ? void 0 : _a2[name] }, (errors) => {
16001
16063
  if (errors) {
16002
16064
  err.push(...errors);
16003
- this.errList.push(...errors);
16065
+ this.errors.push(...errors);
16004
16066
  }
16005
- entity.onStoreChange();
16067
+ entity.onStoreChange("validate");
16006
16068
  });
16007
16069
  });
16008
16070
  return err;
16009
16071
  });
16010
- __publicField(this, "setCallback", (callback) => {
16011
- this.callbacks = {
16012
- ...this.callbacks,
16013
- ...callback
16014
- };
16015
- });
16016
16072
  __publicField(this, "submit", () => {
16017
16073
  var _a2, _b, _c, _d;
16018
- const err = this.validate();
16019
- if (err.length === 0) {
16074
+ const errors = this.validate();
16075
+ if (errors.length === 0) {
16020
16076
  (_b = (_a2 = this.callbacks).onFinish) == null ? void 0 : _b.call(_a2, this.store);
16021
- } else if (err.length > 0) {
16022
- (_d = (_c = this.callbacks).onFinishFailed) == null ? void 0 : _d.call(_c, err);
16077
+ } else if (errors.length > 0) {
16078
+ (_d = (_c = this.callbacks).onFinishFailed) == null ? void 0 : _d.call(_c, this.store, errors);
16023
16079
  }
16024
16080
  });
16025
16081
  __publicField(this, "resetFields", () => {
16026
- this.errList.length = 0;
16027
- this.fieldEntities.forEach((enetity) => {
16028
- enetity.onStoreChange();
16082
+ this.errors.length = 0;
16083
+ this.store = this.initialValues;
16084
+ this.fieldEntities.forEach((entity) => {
16085
+ entity.onStoreChange("reset");
16029
16086
  });
16030
16087
  });
16031
16088
  __publicField(this, "getForm", () => {
16032
16089
  return {
16090
+ setInitialValues: this.setInitialValues,
16033
16091
  setCallback: this.setCallback,
16034
16092
  registerField: this.registerField,
16035
16093
  getFieldValue: this.getFieldValue,
@@ -16037,12 +16095,12 @@ Please add \`${key}Action\` when creating your handler.`);
16037
16095
  resetFields: this.resetFields,
16038
16096
  submit: this.submit,
16039
16097
  store: this.store,
16040
- errList: this.errList,
16098
+ errors: this.errors,
16041
16099
  fieldEntities: this.fieldEntities
16042
16100
  };
16043
16101
  });
16044
16102
  this.callbacks = {
16045
- onFinish: (value) => {
16103
+ onFinish: () => {
16046
16104
  },
16047
16105
  onFinishFailed: () => {
16048
16106
  }
@@ -16061,98 +16119,113 @@ Please add \`${key}Action\` when creating your handler.`);
16061
16119
  }
16062
16120
  return [formRef.current];
16063
16121
  };
16122
+ function isForwardRefComponent(component) {
16123
+ return component.type && component.type.$$typeof && // eslint-disable-next-line react/display-name
16124
+ React.forwardRef(
16125
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
16126
+ // @ts-ignore
16127
+ () => {
16128
+ }
16129
+ ).$$typeof === component.type.$$typeof;
16130
+ }
16064
16131
  const defaultProps$U = {
16065
16132
  ...ComponentDefaults,
16133
+ required: false,
16066
16134
  name: "",
16067
16135
  label: "",
16068
- className: "",
16069
16136
  rules: [{ required: false, message: "" }],
16070
- disabled: false,
16071
- labelWidth: 90,
16072
- errorMessageAlign: "left",
16073
- showErrorLine: true,
16074
- showErrorMessage: true,
16075
- initialValue: ""
16137
+ errorMessageAlign: "left"
16076
16138
  };
16077
16139
  class FormItem extends React.Component {
16078
- constructor() {
16079
- super(...arguments);
16140
+ constructor(props) {
16141
+ super(props);
16080
16142
  __publicField(this, "cancelRegister");
16081
- __publicField(this, "isInitialValue", false);
16143
+ __publicField(this, "componentRef");
16082
16144
  // children添加value属性和onChange事件
16083
16145
  __publicField(this, "getControlled", (children) => {
16084
- var _a2, _b;
16085
- const { getFieldValue, setFieldsValue } = this.context;
16146
+ var _a2;
16147
+ const { setFieldsValue, getFieldValue } = this.context;
16086
16148
  const { name } = this.props;
16087
- const type2 = children.type.NAME;
16088
- const defaultvalue = this.props.initialValue || ((_a2 = children.props) == null ? void 0 : _a2.defaultValue) || ((_b = children.props) == null ? void 0 : _b.value);
16089
- if (defaultvalue && !this.isInitialValue) {
16090
- setFieldsValue({ [name]: defaultvalue });
16091
- this.isInitialValue = true;
16092
- }
16093
- return {
16094
- value: getFieldValue(name),
16095
- defaultValue: getFieldValue(name),
16096
- onChange: (event) => {
16097
- const originOnChange = children.props.onChange;
16149
+ if ((_a2 = children == null ? void 0 : children.props) == null ? void 0 : _a2.defaultValue) {
16150
+ console.warn("通过 initialValue 设置初始值");
16151
+ }
16152
+ const controlled = {
16153
+ ...children.props,
16154
+ [this.props.valuePropName || "value"]: getFieldValue(name) || this.props.initialValue,
16155
+ [this.props.trigger || "onChange"]: (...args) => {
16156
+ const originOnChange = children.props[this.props.trigger || "onChange"];
16098
16157
  if (originOnChange) {
16099
- originOnChange(event);
16158
+ originOnChange(...args);
16100
16159
  }
16101
- let newValue = event;
16102
- switch (type2) {
16103
- case "checkbox":
16104
- newValue = event.target.value;
16105
- break;
16160
+ let [next] = args;
16161
+ if (this.props.getValueFromEvent) {
16162
+ next = this.props.getValueFromEvent(...args);
16106
16163
  }
16107
- setFieldsValue({ [name]: newValue });
16164
+ setFieldsValue({ [name]: next });
16108
16165
  }
16109
16166
  };
16167
+ if (isForwardRefComponent(children)) {
16168
+ controlled.ref = (componentInstance) => {
16169
+ const originRef = children.ref;
16170
+ if (originRef) {
16171
+ if (typeof originRef === "function") {
16172
+ originRef(componentInstance);
16173
+ }
16174
+ if ("current" in originRef) {
16175
+ originRef.current = componentInstance;
16176
+ }
16177
+ }
16178
+ this.componentRef = componentInstance;
16179
+ };
16180
+ }
16181
+ return controlled;
16182
+ });
16183
+ __publicField(this, "refresh", () => {
16184
+ this.setState(({ resetCount }) => ({
16185
+ resetCount: resetCount + 1
16186
+ }));
16110
16187
  });
16111
- __publicField(this, "onStoreChange", () => {
16112
- this.forceUpdate();
16188
+ __publicField(this, "onStoreChange", (type2) => {
16189
+ if (type2 === "reset") {
16190
+ this.refresh();
16191
+ } else {
16192
+ this.forceUpdate();
16193
+ }
16113
16194
  });
16114
16195
  __publicField(this, "renderLayout", (childNode) => {
16115
16196
  var _a2, _b;
16116
- const {
16117
- label,
16118
- name,
16119
- rules: rules2 = [{ required: false, message: "" }],
16120
- className,
16121
- labelWidth,
16122
- errorMessageAlign,
16123
- showErrorLine,
16124
- showErrorMessage
16125
- } = {
16197
+ const { label, name, required: required2, className, style, errorMessageAlign } = {
16126
16198
  ...defaultProps$U,
16127
16199
  ...this.props
16128
16200
  };
16129
- const item = ((_a2 = this.context.errList) == null ? void 0 : _a2.length) > 0 && ((_b = this.context.errList) == null ? void 0 : _b.filter((item2) => {
16201
+ const item = ((_a2 = this.context.errors) == null ? void 0 : _a2.length) > 0 && ((_b = this.context.errors) == null ? void 0 : _b.filter((item2) => {
16130
16202
  return item2.field === name;
16131
16203
  }));
16132
- const { starPositon } = this.context;
16133
- const renderStar = rules2.length > 0 && rules2[0].required && /* @__PURE__ */ React.createElement("i", { className: "required" });
16134
- const renderLabel = starPositon === "Right" ? /* @__PURE__ */ React.createElement(React.Fragment, null, label, renderStar) : /* @__PURE__ */ React.createElement(React.Fragment, null, renderStar, label);
16135
- return /* @__PURE__ */ React.createElement(Cell, { className: `nut-form-item ${className}` }, label ? /* @__PURE__ */ React.createElement(
16136
- "div",
16137
- {
16138
- className: "nut-cell__title nut-form-item__label",
16139
- style: {
16140
- width: this.pxCheck(labelWidth)
16141
- }
16142
- },
16143
- renderLabel
16144
- ) : null, /* @__PURE__ */ React.createElement("div", { className: "nut-cell__value nut-form-item__body" }, /* @__PURE__ */ React.createElement("div", { className: "nut-form-item__body__slots" }, childNode), item.length > 0 && /* @__PURE__ */ React.createElement(
16145
- "div",
16204
+ const { starPosition } = this.context;
16205
+ const renderStar = required2 && /* @__PURE__ */ React.createElement("i", { className: "required" });
16206
+ const renderLabel = /* @__PURE__ */ React.createElement(React.Fragment, null, starPosition === "left" ? renderStar : null, label, starPosition === "right" ? renderStar : null);
16207
+ return /* @__PURE__ */ React.createElement(
16208
+ Cell,
16146
16209
  {
16147
- className: "nut-form-item__body__tips",
16148
- style: { textAlign: errorMessageAlign }
16210
+ className: `nut-form-item ${className}`,
16211
+ style,
16212
+ onClick: (e) => this.props.onClick && this.props.onClick(e, this.componentRef)
16149
16213
  },
16150
- item[0].message
16151
- )));
16152
- });
16153
- __publicField(this, "pxCheck", (value) => {
16154
- return Number.isNaN(Number(value)) ? String(value) : `${value}px`;
16214
+ label ? /* @__PURE__ */ React.createElement("div", { className: "nut-cell__title nut-form-item__label" }, renderLabel) : null,
16215
+ /* @__PURE__ */ React.createElement("div", { className: "nut-cell__value nut-form-item__body" }, /* @__PURE__ */ React.createElement("div", { className: "nut-form-item__body__slots" }, childNode), item.length > 0 && /* @__PURE__ */ React.createElement(
16216
+ "div",
16217
+ {
16218
+ className: "nut-form-item__body__tips",
16219
+ style: { textAlign: errorMessageAlign }
16220
+ },
16221
+ item[0].message
16222
+ ))
16223
+ );
16155
16224
  });
16225
+ this.componentRef = React.createRef();
16226
+ this.state = {
16227
+ resetCount: 1
16228
+ };
16156
16229
  }
16157
16230
  componentDidMount() {
16158
16231
  this.cancelRegister = this.context.registerField(this);
@@ -16163,81 +16236,86 @@ Please add \`${key}Action\` when creating your handler.`);
16163
16236
  }
16164
16237
  }
16165
16238
  render() {
16166
- const { children, initialValue } = this.props;
16167
- const c = Array.isArray(children) ? children[0] : children;
16168
- let restCNode = c;
16169
- if (initialValue) {
16170
- restCNode = React.cloneElement(c, {
16171
- defaultValue: initialValue
16172
- });
16173
- }
16239
+ const { children } = this.props;
16240
+ const child = Array.isArray(children) ? children[0] : children;
16174
16241
  const returnChildNode = React.cloneElement(
16175
- restCNode,
16176
- this.getControlled(restCNode)
16242
+ child,
16243
+ this.getControlled(child)
16177
16244
  );
16178
- return this.renderLayout(returnChildNode);
16245
+ return /* @__PURE__ */ React.createElement(React.Fragment, { key: this.state.resetCount }, this.renderLayout(returnChildNode));
16179
16246
  }
16180
16247
  }
16181
16248
  __publicField(FormItem, "defaultProps", defaultProps$U);
16182
- __publicField(FormItem, "contextType", FormItemContext);
16249
+ __publicField(FormItem, "contextType", Context);
16183
16250
  const defaultProps$T = {
16184
16251
  ...ComponentDefaults,
16185
- className: "",
16186
- style: void 0,
16187
- form: {},
16188
- labelPosition: "Right",
16189
- formGroupTitle: "",
16190
- onFinish: (obj) => {
16191
- },
16192
- onFinishFailed: (value) => {
16252
+ labelPosition: "right",
16253
+ starPosition: "left",
16254
+ onFinish: (values) => {
16193
16255
  },
16194
- starPositon: "Left"
16256
+ onFinishFailed: (values, errorFields) => {
16257
+ }
16195
16258
  };
16196
16259
  const PositionInfo = {
16197
- Top: "form-layout-top",
16198
- Left: "form-layout-left",
16199
- Right: "form-layout-right"
16260
+ top: "form-layout-top",
16261
+ left: "form-layout-left",
16262
+ right: "form-layout-right"
16200
16263
  };
16201
16264
  const Form = (props) => {
16265
+ const classPrefix2 = "nut-form";
16202
16266
  const {
16267
+ className,
16268
+ style,
16269
+ footer,
16203
16270
  children,
16271
+ initialValues,
16204
16272
  onFinish,
16205
16273
  onFinishFailed,
16206
16274
  labelPosition,
16207
- starPositon,
16208
- form,
16209
- ...rest
16275
+ starPosition,
16276
+ form
16210
16277
  } = {
16211
16278
  ...defaultProps$T,
16212
16279
  ...props
16213
16280
  };
16214
- let formInstance = {};
16215
- if (Object.keys(form).length !== 0) {
16281
+ let formInstance;
16282
+ if (form !== void 0) {
16216
16283
  formInstance = form;
16217
16284
  } else {
16218
16285
  [formInstance] = useForm();
16219
16286
  }
16220
- formInstance.starPositon = starPositon;
16221
- const { setCallback, submit, resetFields } = formInstance;
16287
+ formInstance.starPosition = starPosition;
16288
+ const { setCallback, submit, resetFields, setInitialValues } = formInstance;
16222
16289
  setCallback({
16223
16290
  onFinish,
16224
16291
  onFinishFailed
16225
16292
  });
16293
+ const mountRef = React.useRef(false);
16294
+ setInitialValues(initialValues, !mountRef.current);
16295
+ if (!mountRef.current) {
16296
+ mountRef.current = true;
16297
+ }
16226
16298
  return /* @__PURE__ */ React.createElement(
16227
16299
  "form",
16228
16300
  {
16229
- className: `nut-form ${PositionInfo[labelPosition]} ${props.className}`,
16230
- style: props.style,
16301
+ className: classNames(
16302
+ classPrefix2,
16303
+ className,
16304
+ PositionInfo[labelPosition]
16305
+ ),
16306
+ style,
16231
16307
  onSubmit: (e) => {
16232
16308
  e.preventDefault();
16309
+ e.stopPropagation();
16233
16310
  submit();
16234
16311
  },
16235
16312
  onReset: (e) => {
16236
16313
  e.preventDefault();
16314
+ e.stopPropagation();
16237
16315
  resetFields();
16238
16316
  }
16239
16317
  },
16240
- /* @__PURE__ */ React.createElement(CellGroup, null, /* @__PURE__ */ React.createElement(FormItemContext.Provider, { value: formInstance }, children))
16318
+ /* @__PURE__ */ React.createElement(CellGroup, null, /* @__PURE__ */ React.createElement(Context.Provider, { value: formInstance }, children), footer ? /* @__PURE__ */ React.createElement(Cell, null, footer) : null)
16241
16319
  );
16242
16320
  };
16243
16321
  Form.defaultProps = defaultProps$T;
@@ -16453,7 +16531,7 @@ Please add \`${key}Action\` when creating your handler.`);
16453
16531
  disabled: false,
16454
16532
  min: 1,
16455
16533
  max: 9999,
16456
- readonly: false,
16534
+ readOnly: false,
16457
16535
  allowEmpty: false,
16458
16536
  defaultValue: 0,
16459
16537
  step: 1,
@@ -16467,7 +16545,7 @@ Please add \`${key}Action\` when creating your handler.`);
16467
16545
  disabled,
16468
16546
  min,
16469
16547
  max,
16470
- readonly,
16548
+ readOnly,
16471
16549
  value,
16472
16550
  defaultValue,
16473
16551
  allowEmpty,
@@ -16626,14 +16704,14 @@ Please add \`${key}Action\` when creating your handler.`);
16626
16704
  const focusValue = (e) => {
16627
16705
  if (disabled)
16628
16706
  return;
16629
- if (readonly)
16707
+ if (readOnly)
16630
16708
  return;
16631
16709
  onFocus && onFocus(e);
16632
16710
  };
16633
16711
  const burValue = (e) => {
16634
16712
  if (disabled)
16635
16713
  return;
16636
- if (readonly)
16714
+ if (readOnly)
16637
16715
  return;
16638
16716
  const input = e.target;
16639
16717
  let value2 = input.valueAsNumber;
@@ -16661,7 +16739,7 @@ Please add \`${key}Action\` when creating your handler.`);
16661
16739
  min,
16662
16740
  max,
16663
16741
  disabled,
16664
- readOnly: readonly,
16742
+ readOnly,
16665
16743
  value: _checked,
16666
16744
  onInput: changeFormatValue,
16667
16745
  onBlur: burFormatValue,
@@ -16674,7 +16752,7 @@ Please add \`${key}Action\` when creating your handler.`);
16674
16752
  min,
16675
16753
  max,
16676
16754
  disabled,
16677
- readOnly: readonly,
16755
+ readOnly,
16678
16756
  value: _checked,
16679
16757
  onInput: changeValue,
16680
16758
  onBlur: burValue,
@@ -17866,7 +17944,7 @@ Please add \`${key}Action\` when creating your handler.`);
17866
17944
  return /* @__PURE__ */ React.createElement(
17867
17945
  "input",
17868
17946
  {
17869
- className: `${classPrefix2}__input ${shape === "round" ? `${classPrefix2}__round` : ""} ${clearable ? `${classPrefix2}__input-clear` : ""}`,
17947
+ className: `${classPrefix2}__input ${clearable ? `${classPrefix2}__input-clear` : ""}`,
17870
17948
  ref: searchRef,
17871
17949
  style: { ...props.style },
17872
17950
  value: value || "",
@@ -17939,7 +18017,16 @@ Please add \`${key}Action\` when creating your handler.`);
17939
18017
  style: { ...props.style }
17940
18018
  },
17941
18019
  renderLeft(),
17942
- /* @__PURE__ */ React.createElement("div", { className: `${classPrefix2}__content` }, renderLeftIn(), renderField(), renderRightIn(), clearable && value && handleClear()),
18020
+ /* @__PURE__ */ React.createElement(
18021
+ "div",
18022
+ {
18023
+ className: `${classPrefix2}__content ${shape === "round" ? `${classPrefix2}__round` : ""}`
18024
+ },
18025
+ renderLeftIn(),
18026
+ renderField(),
18027
+ renderRightIn(),
18028
+ clearable && value && handleClear()
18029
+ ),
17943
18030
  renderRight()
17944
18031
  );
17945
18032
  };
@@ -20347,7 +20434,7 @@ Please add \`${key}Action\` when creating your handler.`);
20347
20434
  return styles;
20348
20435
  };
20349
20436
  const getRootPosition = () => {
20350
- let styles = {};
20437
+ const styles = {};
20351
20438
  if (!rootPosition)
20352
20439
  return {};
20353
20440
  const contentWidth = elWidth;
@@ -20357,34 +20444,34 @@ Please add \`${key}Action\` when creating your handler.`);
20357
20444
  const skew = location.split("-")[1];
20358
20445
  let cross = 0;
20359
20446
  let parallel = 0;
20360
- if (Array.isArray(offset) && offset.length == 2) {
20447
+ if (Array.isArray(offset) && offset.length === 2) {
20361
20448
  cross += +offset[1];
20362
20449
  parallel += +offset[0];
20363
20450
  }
20364
20451
  if (width) {
20365
20452
  if (["bottom", "top"].includes(direction)) {
20366
- const h = direction == "bottom" ? height + cross : -(contentHeight + cross);
20453
+ const h = direction === "bottom" ? height + cross : -(contentHeight + cross);
20367
20454
  styles.top = `${top + h}px`;
20368
20455
  if (!skew) {
20369
20456
  styles.left = `${-(contentWidth - width) / 2 + left + parallel}px`;
20370
20457
  }
20371
- if (skew == "start") {
20458
+ if (skew === "start") {
20372
20459
  styles.left = `${left + parallel}px`;
20373
20460
  }
20374
- if (skew == "end") {
20461
+ if (skew === "end") {
20375
20462
  styles.left = `${right + parallel}px`;
20376
20463
  }
20377
20464
  }
20378
20465
  if (["left", "right"].includes(direction)) {
20379
- const contentW = direction == "left" ? -(contentWidth + cross) : width + cross;
20466
+ const contentW = direction === "left" ? -(contentWidth + cross) : width + cross;
20380
20467
  styles.left = `${left + contentW}px`;
20381
20468
  if (!skew) {
20382
20469
  styles.top = `${top - contentHeight / 2 + height / 2 - 4 + parallel}px`;
20383
20470
  }
20384
- if (skew == "start") {
20471
+ if (skew === "start") {
20385
20472
  styles.top = `${top + parallel}px`;
20386
20473
  }
20387
- if (skew == "end") {
20474
+ if (skew === "end") {
20388
20475
  styles.top = `${top + height + parallel}px`;
20389
20476
  }
20390
20477
  }
@@ -20836,7 +20923,7 @@ Please add \`${key}Action\` when creating your handler.`);
20836
20923
  name: ""
20837
20924
  };
20838
20925
  const Swipe = React.forwardRef((props, instanceRef) => {
20839
- const swipeBem = cn("swipe");
20926
+ const classPrefix2 = "nut-swipe";
20840
20927
  const touch = useTouch();
20841
20928
  const { children, className, style } = { ...defaultProps$s, ...props };
20842
20929
  const root2 = React.useRef();
@@ -20957,7 +21044,7 @@ Please add \`${key}Action\` when creating your handler.`);
20957
21044
  "div",
20958
21045
  {
20959
21046
  ref: measuredRef,
20960
- className: `${swipeBem(side)}`,
21047
+ className: `${classPrefix2}__${side}`,
20961
21048
  onClick: (e) => handleOperate(e, side)
20962
21049
  },
20963
21050
  props[`${side}Action`]
@@ -20997,13 +21084,13 @@ Please add \`${key}Action\` when creating your handler.`);
20997
21084
  "div",
20998
21085
  {
20999
21086
  ref: root2,
21000
- className: classNames(swipeBem(), className),
21087
+ className: classNames(classPrefix2, className),
21001
21088
  onTouchStart: (e) => onTouchStart(e),
21002
21089
  onTouchMove: (e) => onTouchMove(e),
21003
21090
  onTouchEnd: (e) => onTouchEnd(e),
21004
21091
  style
21005
21092
  },
21006
- /* @__PURE__ */ React.createElement("div", { className: `${swipeBem("wrapper")}`, style: wrapperStyle }, renderActionContent("left", leftRef), children, renderActionContent("right", rightRef))
21093
+ /* @__PURE__ */ React.createElement("div", { className: `${classPrefix2}__wrapper`, style: wrapperStyle }, renderActionContent("left", leftRef), children, renderActionContent("right", rightRef))
21007
21094
  );
21008
21095
  });
21009
21096
  Swipe.defaultProps = defaultProps$s;