@nutui/nutui-react-taro 2.7.1 → 2.7.3

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 (47) hide show
  1. package/CHANGELOG.md +36 -10
  2. package/dist/esm/Animate/style/style.css +1 -1
  3. package/dist/esm/Elevator.js +1 -1
  4. package/dist/esm/Empty.js +1 -1
  5. package/dist/esm/Form/style/style.css +1 -1
  6. package/dist/esm/Form.js +6 -5
  7. package/dist/esm/FormItem/style/style.css +1 -1
  8. package/dist/esm/FormItem.js +1 -1
  9. package/dist/esm/Popover/style/style.css +1 -1
  10. package/dist/esm/Table/style/style.css +1 -1
  11. package/dist/esm/Tour/style/style.css +1 -1
  12. package/dist/esm/Uploader/style/style.css +1 -1
  13. package/dist/esm/Uploader.js +1 -1
  14. package/dist/esm/{elevator.taro-Bsc8PcT0.js → elevator.taro-C0Gs93x7.js} +5 -3
  15. package/dist/esm/{empty.taro-Dt07kty5.js → empty.taro-DhCHSdca.js} +9 -1
  16. package/dist/esm/{formitem.taro-CEWRz5EJ.js → formitem.taro-CU6rrcJD.js} +105 -47
  17. package/dist/esm/nutui-react.es.js +4 -4
  18. package/dist/esm/{uploader.taro-CceZ5Y4t.js → uploader.taro-C3hV5Aih.js} +3 -1
  19. package/dist/locales/base.js +1 -1
  20. package/dist/locales/en-US.js +1 -1
  21. package/dist/locales/id-ID.js +1 -1
  22. package/dist/locales/tr-TR.js +1 -1
  23. package/dist/locales/zh-CN.js +1 -1
  24. package/dist/locales/zh-TW.js +1 -1
  25. package/dist/locales/zh-UG.js +1 -1
  26. package/dist/nutui.react.es.js +247 -148
  27. package/dist/nutui.react.umd.js +246 -147
  28. package/dist/packages/animate/animate.scss +0 -3
  29. package/dist/packages/form/form.scss +0 -68
  30. package/dist/packages/formitem/formitem.scss +90 -21
  31. package/dist/packages/popover/popover.scss +16 -11
  32. package/dist/packages/table/table.scss +1 -0
  33. package/dist/packages/uploader/uploader.scss +2 -1
  34. package/dist/style.css +1 -1
  35. package/dist/styles/variables.scss +1 -0
  36. package/dist/types/packages/configprovider/types.d.ts +1 -1
  37. package/dist/types/packages/empty/types.d.ts +10 -1
  38. package/dist/types/packages/empty/utils.d.ts +2 -0
  39. package/dist/types/packages/form/form.d.ts +2 -0
  40. package/dist/types/packages/form/form.taro.d.ts +10 -0
  41. package/dist/types/packages/form/types.d.ts +2 -1
  42. package/dist/types/packages/formitem/formitem.d.ts +1 -0
  43. package/dist/types/packages/formitem/formitem.taro.d.ts +1 -0
  44. package/dist/types/packages/video/video.d.ts +6 -2
  45. package/dist/types/utils/merge.d.ts +1 -0
  46. package/dist/types/utils/to-array.d.ts +1 -0
  47. package/package.json +1 -1
@@ -1,9 +1,31 @@
1
1
  import React__default, { createContext, useRef } from "react";
2
+ import { Text, View } from "@tarojs/components";
2
3
  import { C as Cell } from "./cell.taro-DWLhb5m6.js";
3
4
  import { C as ComponentDefaults } from "./typings-DV9RBfhj.js";
4
5
  import { a as __awaiter } from "./tslib.es6-iWu3F_1J.js";
5
6
  import Schema from "async-validator";
6
7
  const Context = createContext({});
8
+ function merge(...objects) {
9
+ const result = Array.isArray(objects[0]) ? [] : {};
10
+ function mergeHelper(obj, path = []) {
11
+ for (const [key, value] of Object.entries(obj)) {
12
+ const newPath = [...path, key];
13
+ if (Array.isArray(value)) {
14
+ result[key] = [...value];
15
+ } else if (typeof value === "object" && value !== null) {
16
+ if (path.some((p) => p === value))
17
+ continue;
18
+ if (!result[key])
19
+ result[key] = {};
20
+ mergeHelper(value, newPath);
21
+ } else {
22
+ result[key] = value;
23
+ }
24
+ }
25
+ }
26
+ objects.filter((obj) => !!obj).forEach((obj) => mergeHelper(obj));
27
+ return result;
28
+ }
7
29
  const SECRET = "NUT_FORM_INTERNAL";
8
30
  class FormStore {
9
31
  constructor() {
@@ -36,14 +58,16 @@ class FormStore {
36
58
  });
37
59
  return fieldsValue;
38
60
  };
39
- this.setInitialValues = (values, init) => {
61
+ this.setInitialValues = (initialValues, init) => {
62
+ this.initialValues = initialValues || {};
40
63
  if (init) {
41
- this.initialValues = values;
42
- this.store = values;
64
+ const nextStore = merge(initialValues, this.store);
65
+ this.updateStore(nextStore);
43
66
  }
44
67
  };
45
- this.setFieldsValue = (newStore, needValidate = true) => {
46
- this.store = Object.assign(Object.assign({}, this.store), newStore);
68
+ this.setFieldsValue = (newStore) => {
69
+ const nextStore = merge(this.store, newStore);
70
+ this.updateStore(nextStore);
47
71
  this.fieldEntities.forEach((entity) => {
48
72
  const { name } = entity.props;
49
73
  Object.keys(newStore).forEach((key) => {
@@ -61,7 +85,12 @@ class FormStore {
61
85
  item.entity.onStoreChange("update");
62
86
  }
63
87
  });
64
- needValidate && this.validateFields();
88
+ };
89
+ this.setFieldValue = (name, value) => {
90
+ const store = {
91
+ [name]: value
92
+ };
93
+ this.setFieldsValue(store);
65
94
  };
66
95
  this.setCallback = (callback) => {
67
96
  this.callbacks = Object.assign(Object.assign({}, this.callbacks), callback);
@@ -69,6 +98,10 @@ class FormStore {
69
98
  this.validateEntities = (entity, errs) => __awaiter(this, void 0, void 0, function* () {
70
99
  var _a;
71
100
  const { name, rules = [] } = entity.props;
101
+ if (!name) {
102
+ console.warn("Form field missing name property");
103
+ return;
104
+ }
72
105
  const descriptor = {};
73
106
  if (rules.length) {
74
107
  if (rules.length > 1) {
@@ -120,7 +153,8 @@ class FormStore {
120
153
  });
121
154
  this.resetFields = () => {
122
155
  this.errors.length = 0;
123
- this.store = this.initialValues;
156
+ const nextStore = merge({}, this.initialValues);
157
+ this.updateStore(nextStore);
124
158
  this.fieldEntities.forEach((entity) => {
125
159
  entity.onStoreChange("reset");
126
160
  });
@@ -155,6 +189,7 @@ class FormStore {
155
189
  getFieldValue: this.getFieldValue,
156
190
  getFieldsValue: this.getFieldsValue,
157
191
  setFieldsValue: this.setFieldsValue,
192
+ setFieldValue: this.setFieldValue,
158
193
  resetFields: this.resetFields,
159
194
  validateFields: this.validateFields,
160
195
  submit: this.submit,
@@ -169,6 +204,9 @@ class FormStore {
169
204
  }
170
205
  };
171
206
  }
207
+ updateStore(nextStore) {
208
+ this.store = nextStore;
209
+ }
172
210
  }
173
211
  const useForm = (form) => {
174
212
  const formRef = useRef();
@@ -191,20 +229,28 @@ function isForwardRefComponent(component) {
191
229
  }
192
230
  ).$$typeof === component.type.$$typeof;
193
231
  }
194
- const defaultProps = Object.assign(Object.assign({}, ComponentDefaults), { required: false, name: "", label: "", rules: [{ required: false, message: "" }], errorMessageAlign: "left", validateTrigger: "onChange", shouldUpdate: false, noStyle: false });
232
+ function toArray(value) {
233
+ if (value === void 0 || value === null) {
234
+ return [];
235
+ }
236
+ return Array.isArray(value) ? value : [value];
237
+ }
238
+ const defaultProps = Object.assign(Object.assign({}, ComponentDefaults), { required: false, name: "", label: "", rules: [{ required: false, message: "" }], errorMessageAlign: "left", shouldUpdate: false, noStyle: false });
195
239
  class FormItem extends React__default.Component {
196
240
  constructor(props) {
197
241
  super(props);
198
242
  this.getControlled = (children) => {
199
243
  var _a;
200
- const { setFieldsValue, getFieldValue } = this.context;
201
- const { dispatch } = this.context.getInternal(SECRET);
244
+ const { setFieldsValue, getFieldValue } = this.context.formInstance;
245
+ const { dispatch } = this.context.formInstance.getInternal(SECRET);
202
246
  const { name = "" } = this.props;
203
247
  if ((_a = children === null || children === void 0 ? void 0 : children.props) === null || _a === void 0 ? void 0 : _a.defaultValue) {
204
- console.warn("通过 initialValue 设置初始值");
248
+ if (process.env.NODE_ENV !== "production") {
249
+ console.warn("[NutUI] FormItem:", "请通过 initialValue 设置初始值,而不是 defaultValue");
250
+ }
205
251
  }
206
252
  const fieldValue = getFieldValue(name);
207
- const controlled = Object.assign(Object.assign({}, children.props), { [this.props.valuePropName || "value"]: fieldValue !== void 0 ? fieldValue : this.props.initialValue, [this.props.trigger || "onChange"]: (...args) => {
253
+ const controlled = Object.assign(Object.assign({}, children.props), { className: children.props.className, [this.props.valuePropName || "value"]: fieldValue !== void 0 ? fieldValue : this.props.initialValue, [this.props.trigger || "onChange"]: (...args) => {
208
254
  const originOnChange = children.props[this.props.trigger || "onChange"];
209
255
  if (originOnChange) {
210
256
  originOnChange(...args);
@@ -213,26 +259,24 @@ class FormItem extends React__default.Component {
213
259
  if (this.props.getValueFromEvent) {
214
260
  next = this.props.getValueFromEvent(...args);
215
261
  }
216
- setFieldsValue({ [name]: next }, false);
262
+ setFieldsValue({ [name]: next });
217
263
  } });
218
264
  const { validateTrigger } = this.props;
219
- let validateTriggers = [this.props.trigger || "onChange"];
220
- if (validateTrigger) {
221
- validateTriggers = typeof validateTrigger === "string" ? [validateTrigger] : [...validateTrigger];
222
- validateTriggers.forEach((trigger) => {
223
- const originTrigger = controlled[trigger];
224
- controlled[trigger] = (...args) => {
225
- if (originTrigger) {
226
- originTrigger(...args);
227
- }
228
- if (this.props.rules && this.props.rules.length) {
229
- dispatch({
230
- name: this.props.name
231
- });
232
- }
233
- };
234
- });
235
- }
265
+ const mergedValidateTrigger = validateTrigger || this.context.validateTrigger;
266
+ const validateTriggers = toArray(mergedValidateTrigger);
267
+ validateTriggers.forEach((trigger) => {
268
+ const originTrigger = controlled[trigger];
269
+ controlled[trigger] = (...args) => {
270
+ if (originTrigger) {
271
+ originTrigger(...args);
272
+ }
273
+ if (this.props.rules && this.props.rules.length) {
274
+ dispatch({
275
+ name: this.props.name
276
+ });
277
+ }
278
+ };
279
+ });
236
280
  if (isForwardRefComponent(children)) {
237
281
  controlled.ref = (componentInstance) => {
238
282
  const originRef = children.ref;
@@ -256,7 +300,7 @@ class FormItem extends React__default.Component {
256
300
  };
257
301
  this.onStoreChange = (type) => {
258
302
  if (type === "reset") {
259
- this.context.errors[this.props.name] = [];
303
+ this.context.formInstance.errors[this.props.name] = [];
260
304
  this.refresh();
261
305
  } else {
262
306
  this.forceUpdate();
@@ -264,27 +308,31 @@ class FormItem extends React__default.Component {
264
308
  };
265
309
  this.renderLayout = (childNode) => {
266
310
  var _a;
267
- const { label, name, required, rules, className, style, align, errorMessageAlign } = Object.assign(Object.assign({}, defaultProps), this.props);
311
+ const { label, name, required, rules, className, style, errorMessageAlign, align } = Object.assign(Object.assign({}, defaultProps), this.props);
268
312
  const requiredInRules = rules === null || rules === void 0 ? void 0 : rules.some((rule) => rule.required);
269
- const item = name ? this.context.errors[name] : [];
270
- const { starPosition } = this.context;
271
- const renderStar = (required || requiredInRules) && React__default.createElement("i", { className: "required" });
313
+ const item = name ? this.context.formInstance.errors[name] : [];
314
+ const { starPosition } = this.context.formInstance;
315
+ const renderStar = (required || requiredInRules) && React__default.createElement(Text, { className: "nut-form-item-label-required required" }, "*");
272
316
  const renderLabel = React__default.createElement(
273
317
  React__default.Fragment,
274
318
  null,
275
- starPosition === "left" ? renderStar : null,
276
- label,
319
+ React__default.createElement(
320
+ Text,
321
+ { className: "nut-form-item-labeltxt" },
322
+ starPosition === "left" ? renderStar : null,
323
+ label
324
+ ),
277
325
  starPosition === "right" ? renderStar : null
278
326
  );
279
327
  return React__default.createElement(
280
328
  Cell,
281
- { className: `nut-form-item ${className}`, style, align, onClick: (e) => this.props.onClick && this.props.onClick(e, this.componentRef) },
282
- label ? React__default.createElement("div", { className: "nut-cell-title nut-form-item-label" }, renderLabel) : null,
329
+ { className: `${this.getClassNameWithDirection("nut-form-item")} ${className}`, style, align, onClick: (e) => this.props.onClick && this.props.onClick(e, this.componentRef) },
330
+ label ? React__default.createElement(View, { className: `nut-cell-title ${this.getClassNameWithDirection("nut-form-item-label")}` }, renderLabel) : null,
283
331
  React__default.createElement(
284
- "div",
285
- { className: "nut-cell-value nut-form-item-body" },
286
- React__default.createElement("div", { className: "nut-form-item-body-slots" }, childNode),
287
- React__default.createElement("div", { className: "nut-form-item-body-tips", style: {
332
+ View,
333
+ { className: `nut-cell-value ${this.getClassNameWithDirection("nut-form-item-body")}` },
334
+ React__default.createElement(View, { className: "nut-form-item-body-slots" }, childNode),
335
+ React__default.createElement(View, { className: "nut-form-item-body-tips", style: {
288
336
  textAlign: errorMessageAlign,
289
337
  display: (item === null || item === void 0 ? void 0 : item.length) ? "initial" : "none"
290
338
  } }, (_a = item === null || item === void 0 ? void 0 : item[0]) === null || _a === void 0 ? void 0 : _a.message)
@@ -297,11 +345,11 @@ class FormItem extends React__default.Component {
297
345
  };
298
346
  }
299
347
  componentDidMount() {
300
- const { store = {}, setInitialValues } = this.context.getInternal(SECRET);
348
+ const { store = {}, setInitialValues } = this.context.formInstance.getInternal(SECRET);
301
349
  if (this.props.initialValue && this.props.name && !Object.keys(store).includes(this.props.name)) {
302
350
  setInitialValues(Object.assign(Object.assign({}, store), { [this.props.name]: this.props.initialValue }), true);
303
351
  }
304
- const { registerField, registerUpdate } = this.context.getInternal(SECRET);
352
+ const { registerField, registerUpdate } = this.context.formInstance.getInternal(SECRET);
305
353
  this.cancelRegister = registerField(this);
306
354
  this.eventOff = registerUpdate(this, this.props.shouldUpdate);
307
355
  }
@@ -313,6 +361,12 @@ class FormItem extends React__default.Component {
313
361
  this.eventOff();
314
362
  }
315
363
  }
364
+ getClassNameWithDirection(className) {
365
+ if (className && this.context.labelPosition) {
366
+ return `${className} ${className}-${this.context.labelPosition}`;
367
+ }
368
+ return className;
369
+ }
316
370
  render() {
317
371
  const { children } = this.props;
318
372
  const child = Array.isArray(children) ? children[0] : children;
@@ -320,9 +374,13 @@ class FormItem extends React__default.Component {
320
374
  if (!this.props.shouldUpdate) {
321
375
  returnChildNode = React__default.cloneElement(child, this.getControlled(child));
322
376
  } else {
323
- returnChildNode = child(this.context);
377
+ returnChildNode = child(this.context.formInstance);
324
378
  }
325
- return React__default.createElement(React__default.Fragment, { key: this.state.resetCount }, this.props.noStyle ? returnChildNode : this.renderLayout(returnChildNode));
379
+ return React__default.createElement(
380
+ React__default.Fragment,
381
+ { key: this.state.resetCount },
382
+ React__default.createElement(View, { className: this.context.disabled ? "nut-form-item-disabled" : "", catchMove: this.context.disabled }, this.props.noStyle ? returnChildNode : this.renderLayout(returnChildNode))
383
+ );
326
384
  }
327
385
  }
328
386
  FormItem.defaultProps = defaultProps;
@@ -14,7 +14,7 @@ import { S } from "./space.taro-B1KsEPZL.js";
14
14
  import { S as S2 } from "./sticky.taro-DC98CdU7.js";
15
15
  import { S as S3 } from "./safearea.taro-BJpvFsMf.js";
16
16
  import { B as B2 } from "./backtop.taro-D3Lo3jFO.js";
17
- import { E } from "./elevator.taro-Bsc8PcT0.js";
17
+ import { E } from "./elevator.taro-C0Gs93x7.js";
18
18
  import { F } from "./fixednav.taro-BodErnYy.js";
19
19
  import { N } from "./navbar.taro-HRFRDGii.js";
20
20
  import { S as S4 } from "./sidenavbar.taro-C-AoUXLA.js";
@@ -32,7 +32,7 @@ import { C as C8 } from "./cascader.taro-DRE3asjI.js";
32
32
  import { C as C9, a as a2 } from "./checkbox.taro-CgqJyhrh.js";
33
33
  import { D as D2 } from "./datepicker.taro-DU4OSraL.js";
34
34
  import { default as default2 } from "./Form.js";
35
- import { F as F2 } from "./formitem.taro-CEWRz5EJ.js";
35
+ import { F as F2 } from "./formitem.taro-CU6rrcJD.js";
36
36
  import { I as I2 } from "./input.taro-CA9ZpM9a.js";
37
37
  import { I as I3 } from "./inputnumber.taro-CZourWz-.js";
38
38
  import { M } from "./menu.taro-BmjnA_YM.js";
@@ -47,12 +47,12 @@ import { S as S8 } from "./shortpassword.taro-CUnXqjab.js";
47
47
  import { S as S9 } from "./signature.taro-BW4eiGIR.js";
48
48
  import { S as S10 } from "./switch.taro-CdBmDo18.js";
49
49
  import { T as T5 } from "./textarea.taro-PsaohYay.js";
50
- import { U } from "./uploader.taro-CceZ5Y4t.js";
50
+ import { U } from "./uploader.taro-C3hV5Aih.js";
51
51
  import { A as A2 } from "./actionsheet.taro-kMhbV73n.js";
52
52
  import { B as B3 } from "./badge.taro-B42_7q8v.js";
53
53
  import { B as B4 } from "./dialog.taro-yjDaaRHA.js";
54
54
  import { D as D3 } from "./drag.taro-B_sfzmtW.js";
55
- import { E as E2 } from "./empty.taro-Dt07kty5.js";
55
+ import { E as E2 } from "./empty.taro-DhCHSdca.js";
56
56
  import { I as I4 } from "./infiniteloading.taro-DzIrZvc0.js";
57
57
  import { L as L2 } from "./loading.taro-n_qoNgCW.js";
58
58
  import { N as N3 } from "./noticebar.taro-BjKDC7We.js";
@@ -365,6 +365,7 @@ const InternalUploader = (props, ref) => {
365
365
  }
366
366
  };
367
367
  const readFile = (files) => {
368
+ const results = [];
368
369
  files.forEach((file, index) => {
369
370
  var _a2, _b;
370
371
  let fileType = file.type;
@@ -400,8 +401,9 @@ const InternalUploader = (props, ref) => {
400
401
  fileItem.url = fileType === "video" ? file.thumbTempFilePath : filepath;
401
402
  }
402
403
  executeUpload(fileItem, index);
403
- setFileList([...fileList, fileItem]);
404
+ results.push(fileItem);
404
405
  });
406
+ setFileList([...fileList, ...results]);
405
407
  };
406
408
  const filterFiles = (files) => {
407
409
  const maximum = maxCount * 1;
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @nutui/nutui-react-taro v2.7.1 Fri Nov 22 2024 15:43:35 GMT+0800 (Central Standard Time)
2
+ * @nutui/nutui-react-taro v2.7.3 Fri Dec 13 2024 15:48:17 GMT+0800 (China Standard Time)
3
3
  * (c) 2023 @jdf2e.
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @nutui/nutui-react-taro v2.7.1 Fri Nov 22 2024 15:43:35 GMT+0800 (Central Standard Time)
2
+ * @nutui/nutui-react-taro v2.7.3 Fri Dec 13 2024 15:48:17 GMT+0800 (China Standard Time)
3
3
  * (c) 2023 @jdf2e.
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @nutui/nutui-react-taro v2.7.1 Fri Nov 22 2024 15:43:35 GMT+0800 (Central Standard Time)
2
+ * @nutui/nutui-react-taro v2.7.3 Fri Dec 13 2024 15:48:17 GMT+0800 (China Standard Time)
3
3
  * (c) 2023 @jdf2e.
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @nutui/nutui-react-taro v2.7.1 Fri Nov 22 2024 15:43:35 GMT+0800 (Central Standard Time)
2
+ * @nutui/nutui-react-taro v2.7.3 Fri Dec 13 2024 15:48:17 GMT+0800 (China Standard Time)
3
3
  * (c) 2023 @jdf2e.
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @nutui/nutui-react-taro v2.7.1 Fri Nov 22 2024 15:43:35 GMT+0800 (Central Standard Time)
2
+ * @nutui/nutui-react-taro v2.7.3 Fri Dec 13 2024 15:48:17 GMT+0800 (China Standard Time)
3
3
  * (c) 2023 @jdf2e.
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @nutui/nutui-react-taro v2.7.1 Fri Nov 22 2024 15:43:35 GMT+0800 (Central Standard Time)
2
+ * @nutui/nutui-react-taro v2.7.3 Fri Dec 13 2024 15:48:17 GMT+0800 (China Standard Time)
3
3
  * (c) 2023 @jdf2e.
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @nutui/nutui-react-taro v2.7.1 Fri Nov 22 2024 15:43:35 GMT+0800 (Central Standard Time)
2
+ * @nutui/nutui-react-taro v2.7.3 Fri Dec 13 2024 15:48:17 GMT+0800 (China Standard Time)
3
3
  * (c) 2023 @jdf2e.
4
4
  * Released under the MIT License.
5
5
  */