@nutui/nutui-react-taro 2.7.6 → 2.7.8

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 (54) hide show
  1. package/CHANGELOG.md +29 -7
  2. package/dist/esm/Address/style/style.css +1 -1
  3. package/dist/esm/Address.js +1 -1
  4. package/dist/esm/Animate/style/style.css +1 -1
  5. package/dist/esm/Animate.js +1 -1
  6. package/dist/esm/Calendar/style/style.css +1 -1
  7. package/dist/esm/Calendar.js +1 -1
  8. package/dist/esm/CalendarCard.js +1 -1
  9. package/dist/esm/CalendarItem.js +1 -1
  10. package/dist/esm/Cascader/style/style.css +1 -1
  11. package/dist/esm/Cascader.js +1 -1
  12. package/dist/esm/DatePicker.js +1 -1
  13. package/dist/esm/Empty.js +1 -1
  14. package/dist/esm/Form.js +2 -1
  15. package/dist/esm/FormItem.js +1 -1
  16. package/dist/esm/TabPane.js +1 -1
  17. package/dist/esm/Tabs/style/style.css +1 -1
  18. package/dist/esm/Tabs.js +1 -1
  19. package/dist/esm/{address.taro-BCoDZM6h.js → address.taro-Ck0ZmxRg.js} +1 -1
  20. package/dist/esm/{animate.taro-CQVEyDKL.js → animate.taro-BHDZMzJF.js} +9 -12
  21. package/dist/esm/{calendar.taro-CM4yWFlF.js → calendar.taro-CUDVpJBa.js} +3 -3
  22. package/dist/esm/{calendarcard.taro-CvWyBqnr.js → calendarcard.taro-BiOnui_b.js} +4 -4
  23. package/dist/esm/{calendaritem.taro-BGbbuJOS.js → calendaritem.taro-DveeC4_t.js} +237 -219
  24. package/dist/esm/{cascader.taro-BwRnRQXE.js → cascader.taro-DUJvcGw0.js} +1 -1
  25. package/dist/esm/date-BmUWlDuN.js +147 -0
  26. package/dist/esm/{datepicker.taro-DicskhhH.js → datepicker.taro-Dwh8sKhJ.js} +8 -0
  27. package/dist/esm/{empty.taro-DhCHSdca.js → empty.taro-ChtnK90s.js} +1 -1
  28. package/dist/esm/{formitem.taro-CU6rrcJD.js → formitem.taro-Bee3MWwq.js} +121 -31
  29. package/dist/esm/nutui-react.es.js +11 -11
  30. package/dist/esm/{tabpane.taro-BAe86j3t.js → tabpane.taro-BAihO3w8.js} +2 -1
  31. package/dist/esm/{tabs.taro-CnXiMR_B.js → tabs.taro-sp_DNWis.js} +26 -44
  32. package/dist/locales/base.js +1 -1
  33. package/dist/locales/en-US.js +1 -1
  34. package/dist/locales/id-ID.js +1 -1
  35. package/dist/locales/tr-TR.js +1 -1
  36. package/dist/locales/zh-CN.js +1 -1
  37. package/dist/locales/zh-TW.js +1 -1
  38. package/dist/locales/zh-UG.js +1 -1
  39. package/dist/nutui.react.es.js +529 -555
  40. package/dist/nutui.react.umd.js +529 -555
  41. package/dist/packages/animate/animate.scss +63 -105
  42. package/dist/packages/calendar/calendar.scss +9 -9
  43. package/dist/packages/tabs/tabs.scss +72 -115
  44. package/dist/style.css +1 -1
  45. package/dist/types/packages/animate/animate.taro.d.ts +2 -1
  46. package/dist/types/packages/form/__tests__/merge.spec.d.ts +1 -0
  47. package/dist/types/packages/form/index.d.ts +2 -1
  48. package/dist/types/packages/form/index.taro.d.ts +2 -1
  49. package/dist/types/packages/form/useform.d.ts +2 -1
  50. package/dist/types/packages/form/useform.taro.d.ts +2 -1
  51. package/dist/types/utils/date.d.ts +54 -52
  52. package/dist/types/utils/merge.d.ts +14 -1
  53. package/package.json +1 -1
  54. package/dist/esm/date-CYwRNlGq.js +0 -219
@@ -4,7 +4,7 @@ import classNames from "classnames";
4
4
  import { Loading, Checklist } from "@nutui/icons-react-taro";
5
5
  import { ScrollView } from "@tarojs/components";
6
6
  import { P as Popup } from "./popup.taro-JynjcLCn.js";
7
- import { T as Tabs } from "./tabs.taro-CnXiMR_B.js";
7
+ import { T as Tabs } from "./tabs.taro-sp_DNWis.js";
8
8
  import { C as ComponentDefaults } from "./typings-DV9RBfhj.js";
9
9
  import { u as usePropsValue } from "./use-props-value-SH9krhkx.js";
10
10
  import { u as useConfig } from "./configprovider.taro-C3WyeHSO.js";
@@ -0,0 +1,147 @@
1
+ const isLeapYear = (y) => {
2
+ return y % 4 === 0 && y % 100 !== 0 || y % 400 === 0;
3
+ };
4
+ const getWhatDay = (year, month, day) => {
5
+ const date = new Date(year, month - 1, day);
6
+ const dayNames = [
7
+ "星期日",
8
+ "星期一",
9
+ "星期二",
10
+ "星期三",
11
+ "星期四",
12
+ "星期五",
13
+ "星期六"
14
+ ];
15
+ return dayNames[date.getDay()];
16
+ };
17
+ const getMonthPreDay = (year, month) => {
18
+ const day = new Date(year, month - 1, 1).getDay();
19
+ return day === 0 ? 7 : day;
20
+ };
21
+ const getMonthDays = (year, month) => {
22
+ if (/^0/.test(month)) {
23
+ month = month.split("")[1];
24
+ }
25
+ return [
26
+ 0,
27
+ 31,
28
+ isLeapYear(Number(year)) ? 29 : 28,
29
+ 31,
30
+ 30,
31
+ 31,
32
+ 30,
33
+ 31,
34
+ 31,
35
+ 30,
36
+ 31,
37
+ 30,
38
+ 31
39
+ ][month];
40
+ };
41
+ const getNumTwoBit = (n) => {
42
+ return n > 9 ? `${n}` : `0${n}`;
43
+ };
44
+ const date2Str = (date, split = "-") => {
45
+ const y = date.getFullYear();
46
+ const m = getNumTwoBit(date.getMonth() + 1);
47
+ const d = getNumTwoBit(date.getDate());
48
+ return [y, m, d].join(split);
49
+ };
50
+ const getDateString = (offset = 0) => {
51
+ const date = /* @__PURE__ */ new Date();
52
+ date.setDate(date.getDate() + offset);
53
+ return date2Str(date, "-");
54
+ };
55
+ const compareDate = (date1, date2) => {
56
+ const startTime = new Date(date1.replace("-", "/").replace("-", "/"));
57
+ const endTime = new Date(date2.replace("-", "/").replace("-", "/"));
58
+ return startTime < endTime;
59
+ };
60
+ const isEqual = (date1, date2) => {
61
+ const startTime = new Date((date1 || "").replace(/-/g, "/")).getTime();
62
+ const endTime = new Date(date2.replace(/-/g, "/")).getTime();
63
+ return startTime === endTime;
64
+ };
65
+ const getWeekDate = (year, month, date, firstDayOfWeek = 0) => {
66
+ const dateNow = new Date(Number(year), parseInt(month) - 1, Number(date));
67
+ const nowTime = dateNow.getTime();
68
+ let day = dateNow.getDay();
69
+ if (firstDayOfWeek === 0) {
70
+ const oneDayTime2 = 24 * 60 * 60 * 1e3;
71
+ const SundayTime2 = nowTime - day * oneDayTime2;
72
+ const SaturdayTime = nowTime + (6 - day) * oneDayTime2;
73
+ const sunday2 = date2Str(new Date(SundayTime2));
74
+ const saturday = date2Str(new Date(SaturdayTime));
75
+ return [sunday2, saturday];
76
+ }
77
+ day = day === 0 ? 7 : day;
78
+ const oneDayTime = 24 * 60 * 60 * 1e3;
79
+ const MondayTime = nowTime - (day - 1) * oneDayTime;
80
+ const SundayTime = nowTime + (7 - day) * oneDayTime;
81
+ const monday = date2Str(new Date(MondayTime));
82
+ const sunday = date2Str(new Date(SundayTime));
83
+ return [monday, sunday];
84
+ };
85
+ const formatResultDate = (date) => {
86
+ const [year, month, day] = [...date.split("-")];
87
+ const formatterDay = getNumTwoBit(Number(day));
88
+ const formatterDate = `${year}-${month}-${day}`;
89
+ const dayOfWeek = getWhatDay(Number(year), Number(month), Number(day));
90
+ return [year, month, formatterDay, formatterDate, dayOfWeek];
91
+ };
92
+ const getCurrMonthData = (type, year, month) => {
93
+ {
94
+ month === 12 && (year += 1);
95
+ month = month === 12 ? 1 : ++month;
96
+ }
97
+ return [year, getNumTwoBit(month), getMonthDays(String(year), String(month))];
98
+ };
99
+ const getDaysStatus = (type, year, month) => {
100
+ let days = getMonthDays(`${year}`, `${month}`);
101
+ return Array.from(Array(days), (v, k) => {
102
+ return {
103
+ day: k + 1,
104
+ type,
105
+ year,
106
+ month
107
+ };
108
+ });
109
+ };
110
+ const getPreMonthDates = (type, year, month, firstDayOfWeek) => {
111
+ let preMonth = +month - 1;
112
+ let preYear = year;
113
+ if (preMonth <= 0) {
114
+ preMonth = 12;
115
+ preYear += 1;
116
+ }
117
+ let days = getMonthPreDay(+year, +month);
118
+ days -= firstDayOfWeek;
119
+ if (days >= 7) {
120
+ days -= 7;
121
+ }
122
+ const preDates = getMonthDays(`${preYear}`, `${preMonth}`);
123
+ const months = Array.from(Array(preDates), (v, k) => {
124
+ return {
125
+ day: k + 1,
126
+ type,
127
+ preYear,
128
+ preMonth
129
+ };
130
+ });
131
+ return months.slice(preDates - days);
132
+ };
133
+ export {
134
+ getNumTwoBit as a,
135
+ getPreMonthDates as b,
136
+ compareDate as c,
137
+ date2Str as d,
138
+ getDaysStatus as e,
139
+ getMonthDays as f,
140
+ getDateString as g,
141
+ getCurrMonthData as h,
142
+ isEqual as i,
143
+ getWeekDate as j,
144
+ getWhatDay as k,
145
+ formatResultDate as l,
146
+ getMonthPreDay as m
147
+ };
@@ -155,6 +155,14 @@ const DatePicker = (props) => {
155
155
  const year = Number(formatDate[0]);
156
156
  const month = Number(formatDate[1]) - 1;
157
157
  const day = Math.min(Number(formatDate[2]), getMonthEndDay(Number(formatDate[0]), Number(formatDate[1])));
158
+ if (selectedOptions.length >= 2 && ["date", "datehour", "datetime", "month-day"].includes(rangeType)) {
159
+ const dayOption = formatOption("day", day);
160
+ if (rangeType === "month-day") {
161
+ selectedOptions[1] = dayOption;
162
+ } else {
163
+ selectedOptions[2] = dayOption;
164
+ }
165
+ }
158
166
  let date = null;
159
167
  if (rangeType === "date" || rangeType === "month-day" || rangeType === "year-month") {
160
168
  date = new Date(year, month, day);
@@ -25,7 +25,7 @@ const Empty = (props) => {
25
25
  const imageNode = typeof imageUrl === "string" ? React__default.createElement("img", { className: "img", src: imageUrl, alt: "empty" }) : imageUrl;
26
26
  useEffect(() => {
27
27
  setImgStyle(() => {
28
- if (!imageSize) {
28
+ if (typeof imageSize !== "number" && typeof imageSize !== "string") {
29
29
  return {};
30
30
  }
31
31
  if (typeof imageSize === "number") {
@@ -1,29 +1,66 @@
1
- import React__default, { createContext, useRef } from "react";
1
+ import React__default, { createContext, useRef, useState, useEffect } from "react";
2
2
  import { Text, View } from "@tarojs/components";
3
3
  import { C as Cell } from "./cell.taro-DWLhb5m6.js";
4
4
  import { C as ComponentDefaults } from "./typings-DV9RBfhj.js";
5
5
  import { a as __awaiter } from "./tslib.es6-iWu3F_1J.js";
6
6
  import Schema from "async-validator";
7
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
- }
8
+ function merge(...items) {
9
+ return _merge(items[0] === true, false, items);
10
+ }
11
+ function recursive(...items) {
12
+ return _merge(items[0] === true, true, items);
13
+ }
14
+ function clone(input) {
15
+ if (Array.isArray(input)) {
16
+ const output = [];
17
+ for (let index = 0; index < input.length; ++index)
18
+ output.push(clone(input[index]));
19
+ return output;
20
+ }
21
+ if (isPlainObject(input)) {
22
+ const output = {};
23
+ for (const index in input)
24
+ output[index] = clone(input[index]);
25
+ return output;
26
+ }
27
+ return input;
28
+ }
29
+ function isPlainObject(input) {
30
+ if (input === null || typeof input !== "object")
31
+ return false;
32
+ if (Object.getPrototypeOf(input) === null)
33
+ return true;
34
+ let ref = input;
35
+ while (Object.getPrototypeOf(ref) !== null)
36
+ ref = Object.getPrototypeOf(ref);
37
+ return Object.getPrototypeOf(input) === ref;
38
+ }
39
+ function _recursiveMerge(base, extend) {
40
+ if (!isPlainObject(base) || !isPlainObject(extend))
41
+ return extend;
42
+ for (const key in extend) {
43
+ if (key === "__proto__" || key === "constructor" || key === "prototype")
44
+ continue;
45
+ base[key] = isPlainObject(base[key]) && isPlainObject(extend[key]) ? _recursiveMerge(base[key], extend[key]) : extend[key];
46
+ }
47
+ return base;
48
+ }
49
+ function _merge(isClone, isRecursive, items) {
50
+ let result;
51
+ if (isClone || !isPlainObject(result = items.shift()))
52
+ result = {};
53
+ for (let index = 0; index < items.length; ++index) {
54
+ const item = items[index];
55
+ if (!isPlainObject(item))
56
+ continue;
57
+ for (const key in item) {
58
+ if (key === "__proto__" || key === "constructor" || key === "prototype")
59
+ continue;
60
+ const value = isClone ? clone(item[key]) : item[key];
61
+ result[key] = isRecursive ? _recursiveMerge(result[key], value) : value;
24
62
  }
25
63
  }
26
- objects.filter((obj) => !!obj).forEach((obj) => mergeHelper(obj));
27
64
  return result;
28
65
  }
29
66
  const SECRET = "NUT_FORM_INTERNAL";
@@ -39,9 +76,6 @@ class FormStore {
39
76
  this.fieldEntities.push(field);
40
77
  return () => {
41
78
  this.fieldEntities = this.fieldEntities.filter((item) => item !== field);
42
- if (this.store) {
43
- delete this.store[field.props.name];
44
- }
45
79
  };
46
80
  };
47
81
  this.getFieldValue = (name) => {
@@ -63,10 +97,11 @@ class FormStore {
63
97
  if (init) {
64
98
  const nextStore = merge(initialValues, this.store);
65
99
  this.updateStore(nextStore);
100
+ this.notifyWatch();
66
101
  }
67
102
  };
68
103
  this.setFieldsValue = (newStore) => {
69
- const nextStore = merge(this.store, newStore);
104
+ const nextStore = recursive(true, this.store, newStore);
70
105
  this.updateStore(nextStore);
71
106
  this.fieldEntities.forEach((entity) => {
72
107
  const { name } = entity.props;
@@ -85,12 +120,14 @@ class FormStore {
85
120
  item.entity.onStoreChange("update");
86
121
  }
87
122
  });
123
+ this.notifyWatch();
88
124
  };
89
125
  this.setFieldValue = (name, value) => {
90
126
  const store = {
91
127
  [name]: value
92
128
  };
93
129
  this.setFieldsValue(store);
130
+ this.notifyWatch([name]);
94
131
  };
95
132
  this.setCallback = (callback) => {
96
133
  this.callbacks = Object.assign(Object.assign({}, this.callbacks), callback);
@@ -130,7 +167,6 @@ class FormStore {
130
167
  });
131
168
  this.validateFields = (nameList) => __awaiter(this, void 0, void 0, function* () {
132
169
  let filterEntities = [];
133
- this.errors.length = 0;
134
170
  if (!nameList || nameList.length === 0) {
135
171
  filterEntities = this.fieldEntities;
136
172
  } else {
@@ -151,13 +187,29 @@ class FormStore {
151
187
  (_d = (_c = this.callbacks).onFinishFailed) === null || _d === void 0 ? void 0 : _d.call(_c, this.store, errors);
152
188
  }
153
189
  });
154
- this.resetFields = () => {
155
- this.errors.length = 0;
156
- const nextStore = merge({}, this.initialValues);
157
- this.updateStore(nextStore);
158
- this.fieldEntities.forEach((entity) => {
159
- entity.onStoreChange("reset");
160
- });
190
+ this.resetFields = (namePaths) => {
191
+ if (namePaths && namePaths.length) {
192
+ namePaths.forEach((path) => {
193
+ this.errors[path] = null;
194
+ this.fieldEntities.forEach((entity) => {
195
+ const name = entity.props.name;
196
+ if (name === path) {
197
+ if (path in this.initialValues) {
198
+ this.updateStore({ [path]: this.initialValues[path] });
199
+ } else {
200
+ delete this.store[path];
201
+ }
202
+ entity.onStoreChange("reset");
203
+ }
204
+ });
205
+ });
206
+ } else {
207
+ const nextStore = merge({}, this.initialValues);
208
+ this.updateStore(nextStore);
209
+ this.fieldEntities.forEach((entity) => {
210
+ entity.onStoreChange("reset");
211
+ });
212
+ }
161
213
  };
162
214
  this.registerUpdate = (field, shouldUpdate) => {
163
215
  this.updateList.push({
@@ -180,7 +232,8 @@ class FormStore {
180
232
  dispatch: this.dispatch,
181
233
  store: this.store,
182
234
  fieldEntities: this.fieldEntities,
183
- registerUpdate: this.registerUpdate
235
+ registerUpdate: this.registerUpdate,
236
+ registerWatch: this.registerWatch
184
237
  };
185
238
  }
186
239
  };
@@ -197,6 +250,26 @@ class FormStore {
197
250
  getInternal: this.getInternal
198
251
  };
199
252
  };
253
+ this.watchList = [];
254
+ this.registerWatch = (callback) => {
255
+ this.watchList.push(callback);
256
+ return () => {
257
+ this.watchList = this.watchList.filter((fn) => fn !== callback);
258
+ };
259
+ };
260
+ this.notifyWatch = (namePath = []) => {
261
+ if (this.watchList.length) {
262
+ let allValues;
263
+ if (!namePath || namePath.length === 0) {
264
+ allValues = this.getFieldsValue(true);
265
+ } else {
266
+ allValues = this.getFieldsValue(namePath);
267
+ }
268
+ this.watchList.forEach((callback) => {
269
+ callback(allValues, namePath);
270
+ });
271
+ }
272
+ };
200
273
  this.callbacks = {
201
274
  onFinish: () => {
202
275
  },
@@ -220,6 +293,22 @@ const useForm = (form) => {
220
293
  }
221
294
  return [formRef.current];
222
295
  };
296
+ const useWatch = (path, form) => {
297
+ const formInstance = form.getInternal(SECRET);
298
+ const [value, setValue] = useState();
299
+ useEffect(() => {
300
+ const unsubscribe = formInstance.registerWatch((data, namePath) => {
301
+ const value2 = data[path];
302
+ setValue(value2);
303
+ });
304
+ const initialValue = form.getFieldsValue(true);
305
+ if (value !== initialValue[path]) {
306
+ setValue(initialValue[path]);
307
+ }
308
+ return () => unsubscribe();
309
+ }, [form]);
310
+ return value;
311
+ };
223
312
  function isForwardRefComponent(component) {
224
313
  return component.type && component.type.$$typeof && // eslint-disable-next-line react/display-name
225
314
  React__default.forwardRef(
@@ -389,5 +478,6 @@ export {
389
478
  Context as C,
390
479
  FormItem as F,
391
480
  SECRET as S,
481
+ useWatch as a,
392
482
  useForm as u
393
483
  };
@@ -22,17 +22,17 @@ import { S as S5 } from "./sidenavbaritem.taro-BKpzXpzG.js";
22
22
  import { S as S6 } from "./subsidenavbar.taro-CSU3DhNq.js";
23
23
  import { T } from "./tabbar.taro-BiQDgZQF.js";
24
24
  import { T as T2 } from "./tabbaritem.taro-BiIVucQz.js";
25
- import { T as T3 } from "./tabpane.taro-BAe86j3t.js";
26
- import { T as T4 } from "./tabs.taro-CnXiMR_B.js";
27
- import { A } from "./address.taro-BCoDZM6h.js";
28
- import { C as C5 } from "./calendar.taro-CM4yWFlF.js";
29
- import { C as C6 } from "./calendaritem.taro-BGbbuJOS.js";
30
- import { C as C7 } from "./calendarcard.taro-CvWyBqnr.js";
31
- import { C as C8 } from "./cascader.taro-BwRnRQXE.js";
25
+ import { T as T3 } from "./tabpane.taro-BAihO3w8.js";
26
+ import { T as T4 } from "./tabs.taro-sp_DNWis.js";
27
+ import { A } from "./address.taro-Ck0ZmxRg.js";
28
+ import { C as C5 } from "./calendar.taro-CUDVpJBa.js";
29
+ import { C as C6 } from "./calendaritem.taro-DveeC4_t.js";
30
+ import { C as C7 } from "./calendarcard.taro-BiOnui_b.js";
31
+ import { C as C8 } from "./cascader.taro-DUJvcGw0.js";
32
32
  import { C as C9, a as a2 } from "./checkbox.taro-CgqJyhrh.js";
33
- import { D as D2 } from "./datepicker.taro-DicskhhH.js";
33
+ import { D as D2 } from "./datepicker.taro-Dwh8sKhJ.js";
34
34
  import { default as default2 } from "./Form.js";
35
- import { F as F2 } from "./formitem.taro-CU6rrcJD.js";
35
+ import { F as F2 } from "./formitem.taro-Bee3MWwq.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-2APk--BX.js";
@@ -52,7 +52,7 @@ 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-r5Lmncrq.js";
55
- import { E as E2 } from "./empty.taro-DhCHSdca.js";
55
+ import { E as E2 } from "./empty.taro-ChtnK90s.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-B0qm66Cu.js";
@@ -63,7 +63,7 @@ import { P as P4 } from "./pulltorefresh.taro-BiSDwLpA.js";
63
63
  import { S as S11 } from "./skeleton.taro-D9Vkgsyx.js";
64
64
  import { S as S12 } from "./swipe.taro-CUZSZcIh.js";
65
65
  import { T as T6 } from "./toast.taro-Tx0IHbsl.js";
66
- import { A as A3 } from "./animate.taro-CQVEyDKL.js";
66
+ import { A as A3 } from "./animate.taro-BHDZMzJF.js";
67
67
  import { default as default3 } from "./AnimatingNumbers.js";
68
68
  import { A as A4 } from "./audio.taro-DtIUjg89.js";
69
69
  import { A as A5 } from "./avatar.taro-9dU2KeWv.js";
@@ -1,5 +1,6 @@
1
1
  import React__default from "react";
2
2
  import classNames from "classnames";
3
+ import { View } from "@tarojs/components";
3
4
  const defaultProps = {
4
5
  title: "",
5
6
  value: "",
@@ -11,7 +12,7 @@ const TabPane = (props) => {
11
12
  const classes = classNames(classPrefix, {
12
13
  active: !disabled && props.active
13
14
  }, autoHeightClassName, className);
14
- return children ? React__default.createElement("div", { className: classes }, !disabled && children) : null;
15
+ return children && React__default.createElement(View, { className: classes }, !disabled && children);
15
16
  };
16
17
  export {
17
18
  TabPane as T
@@ -5,7 +5,7 @@ import classNames from "classnames";
5
5
  import { JoySmile } from "@nutui/icons-react-taro";
6
6
  import Taro, { nextTick, createSelectorQuery } from "@tarojs/taro";
7
7
  import { C as ComponentDefaults } from "./typings-DV9RBfhj.js";
8
- import { T as TabPane } from "./tabpane.taro-BAe86j3t.js";
8
+ import { T as TabPane } from "./tabpane.taro-BAihO3w8.js";
9
9
  import { u as usePropsValue } from "./use-props-value-SH9krhkx.js";
10
10
  import { u as useForceUpdate } from "./use-force-update-CudFjCsy.js";
11
11
  import { r as requestAniFrame } from "./raf-Di10dXPS.js";
@@ -20,16 +20,14 @@ const Tabs = (props) => {
20
20
  const [value, setValue] = usePropsValue({
21
21
  value: outerValue,
22
22
  defaultValue: outerDefaultValue,
23
- finalValue: 0,
24
23
  onChange
25
24
  });
26
25
  const titleItemsRef = useRef([]);
27
- const navRef = useRef(null);
28
26
  const getTitles = () => {
29
27
  const titles2 = [];
30
28
  React__default.Children.forEach(children, (child, idx) => {
31
29
  if (React__default.isValidElement(child)) {
32
- const props2 = child === null || child === void 0 ? void 0 : child.props;
30
+ const { props: props2 } = child;
33
31
  if ((props2 === null || props2 === void 0 ? void 0 : props2.title) || (props2 === null || props2 === void 0 ? void 0 : props2.value)) {
34
32
  titles2.push({
35
33
  title: props2.title,
@@ -60,13 +58,8 @@ const Tabs = (props) => {
60
58
  const classes = classNames(classPrefix, `${classPrefix}-${direction}`, className);
61
59
  const classesTitle = classNames(`${classPrefix}-titles`, {
62
60
  [`${classPrefix}-titles-${activeType}`]: activeType,
63
- [`${classPrefix}-titles-scrollable`]: true,
64
61
  [`${classPrefix}-titles-${align}`]: align
65
62
  });
66
- const tabsActiveStyle = {
67
- color: activeType === "smile" ? activeColor : "",
68
- background: activeType === "line" ? activeColor : ""
69
- };
70
63
  const getRect = (selector) => {
71
64
  return new Promise((resolve) => {
72
65
  createSelectorQuery().select(selector).boundingClientRect().exec((rect = []) => {
@@ -82,22 +75,18 @@ const Tabs = (props) => {
82
75
  });
83
76
  };
84
77
  const scrollWithAnimation = useRef(false);
85
- const navRectRef = useRef();
86
- const titleRectRef = useRef([]);
87
78
  const [scrollLeft, setScrollLeft] = useState(0);
88
79
  const [scrollTop, setScrollTop] = useState(0);
89
80
  const scrollDirection = (to, direction2) => {
90
81
  let count = 0;
91
82
  const frames = 1;
92
83
  function animate() {
93
- if (direction2 === "horizontal") {
84
+ if (direction2 === "horizontal")
94
85
  setScrollLeft(to);
95
- } else {
86
+ else
96
87
  setScrollTop(to);
97
- }
98
- if (++count < frames) {
88
+ if (++count < frames)
99
89
  requestAniFrame(animate);
100
- }
101
90
  }
102
91
  animate();
103
92
  };
@@ -107,18 +96,19 @@ const Tabs = (props) => {
107
96
  getRect(`#nut-tabs-titles-${name || uuid} .nut-tabs-list`),
108
97
  getAllRect(`#nut-tabs-titles-${name || uuid} .nut-tabs-titles-item`)
109
98
  ]).then(([navRect, titleRects]) => {
110
- navRectRef.current = navRect;
111
- titleRectRef.current = titleRects;
112
- const titleRect = titleRectRef.current[index];
99
+ const titleRect = titleRects[index];
113
100
  if (!titleRect)
114
101
  return;
115
102
  let to = 0;
116
103
  if (direction === "vertical") {
117
104
  const top = titleRects.slice(0, index).reduce((prev, curr) => prev + curr.height, 0);
118
- to = top - (navRectRef.current.height - titleRect.height) / 2;
105
+ to = top - (navRect.height - titleRect.height) / 2;
119
106
  } else {
120
107
  const left = titleRects.slice(0, index).reduce((prev, curr) => prev + curr.width, 0);
121
- to = rtl ? -left : left;
108
+ to = left - (navRect.width - titleRect.width) / 2;
109
+ if (to < 0)
110
+ return;
111
+ to = rtl ? -to : to;
122
112
  }
123
113
  nextTick(() => {
124
114
  scrollWithAnimation.current = true;
@@ -131,7 +121,7 @@ const Tabs = (props) => {
131
121
  let index = titles.current.findIndex((t) => String(t.value) === String(value));
132
122
  index = index < 0 ? 0 : index;
133
123
  return {
134
- transform: direction === "horizontal" ? `translate3d(${rtl ? "" : "-"}${index * 100}%, 0, 0)` : `translate3d( 0,-${index * 100}%, 0)`,
124
+ transform: direction === "horizontal" ? `translate3d(${rtl ? "" : "-"}${index * 100}%, 0, 0)` : `translate3d( 0, -${index * 100}%, 0)`,
135
125
  transitionDuration: `${duration}ms`
136
126
  };
137
127
  };
@@ -140,38 +130,35 @@ const Tabs = (props) => {
140
130
  index = index < 0 ? 0 : index;
141
131
  scrollIntoView(index);
142
132
  }, [value]);
143
- const tabChange = (item, index) => {
133
+ const tabChange = (item) => {
144
134
  onClick && onClick(item.value);
145
- if (item.disabled) {
146
- return;
135
+ if (!item.disabled) {
136
+ setValue(item.value);
147
137
  }
148
- setValue(item.value);
149
138
  };
150
139
  return React__default.createElement(
151
140
  View,
152
141
  Object.assign({ className: classes }, rest),
153
142
  React__default.createElement(
154
143
  ScrollView,
155
- { enableFlex: true, scrollX: direction === "horizontal", scrollY: direction === "vertical", scrollLeft, scrollTop, enhanced: true, showScrollbar: false, scrollWithAnimation: rtl && Taro.getEnv() !== "WEB" ? false : scrollWithAnimation.current, id: `nut-tabs-titles-${name || uuid}`, className: classesTitle, style: Object.assign({}, tabStyle) },
156
- React__default.createElement(View, { className: "nut-tabs-list", ref: navRef }, !!title && typeof title === "function" ? title() : titles.current.map((item, index) => {
144
+ { enableFlex: true, scrollX: direction === "horizontal", scrollY: direction === "vertical", scrollLeft, scrollTop, enhanced: true, showScrollbar: false, scrollWithAnimation: rtl && Taro.getEnv() !== "WEB" ? false : scrollWithAnimation.current, id: `nut-tabs-titles-${name || uuid}`, className: classesTitle, style: tabStyle },
145
+ React__default.createElement(View, { className: "nut-tabs-list" }, !!title && typeof title === "function" ? title() : titles.current.map((item, index) => {
157
146
  return React__default.createElement(
158
147
  View,
159
- { ref: (ref) => titleItemsRef.current.push(ref), id: `scrollIntoView${index}`, onClick: (e) => {
160
- tabChange(item);
161
- }, className: classNames(`${classPrefix}-titles-item`, {
148
+ { key: item.value, ref: (ref) => titleItemsRef.current.push(ref), id: `scrollIntoView${index}`, onClick: () => tabChange(item), className: classNames(`${classPrefix}-titles-item`, {
162
149
  [`nut-tabs-titles-item-active`]: !item.disabled && String(item.value) === String(value),
163
150
  [`nut-tabs-titles-item-disabled`]: item.disabled,
164
151
  [`nut-tabs-titles-item-${align}`]: align
165
- }), key: item.value },
166
- activeType === "line" && React__default.createElement(View, { className: classNames(`${classPrefix}-titles-item-line`, {
167
- [`${classPrefix}-titles-item-line-${direction}`]: true
168
- }), style: tabsActiveStyle }),
152
+ }) },
153
+ activeType === "line" && React__default.createElement(View, { className: classNames(`${classPrefix}-titles-item-line`, `${classPrefix}-titles-item-line-${direction}`), style: { background: activeColor } }),
169
154
  activeType === "smile" && React__default.createElement(
170
155
  View,
171
- { className: `${classPrefix}-titles-item-smile`, style: tabsActiveStyle },
156
+ { className: `${classPrefix}-titles-item-smile` },
172
157
  React__default.createElement(JoySmile, { color: activeColor })
173
158
  ),
174
- React__default.createElement(View, { className: classNames(`${classPrefix}-ellipsis`, `${classPrefix}-titles-item-text`) }, item.title)
159
+ React__default.createElement(View, { className: classNames({
160
+ [`${classPrefix}-ellipsis`]: direction === "vertical"
161
+ }, `${classPrefix}-titles-item-text`), style: { color: activeColor } }, item.title)
175
162
  );
176
163
  }))
177
164
  ),
@@ -179,14 +166,9 @@ const Tabs = (props) => {
179
166
  View,
180
167
  { className: `${classPrefix}-content-wrap` },
181
168
  React__default.createElement(View, { className: `${classPrefix}-content`, style: getContentStyle() }, React__default.Children.map(children, (child, idx) => {
182
- if (!React__default.isValidElement(child)) {
169
+ if (!React__default.isValidElement(child))
183
170
  return null;
184
- }
185
- let childProps = Object.assign(Object.assign({}, child.props), { active: value === child.props.value });
186
- if (String(value) !== String(child.props.value || idx) && autoHeight) {
187
- childProps = Object.assign(Object.assign({}, childProps), { autoHeightClassName: "inactive" });
188
- }
189
- return React__default.cloneElement(child, childProps);
171
+ return React__default.cloneElement(child, Object.assign(Object.assign({}, child.props), { active: value === child.props.value, autoHeightClassName: autoHeight && String(value) !== String(child.props.value || idx) ? "inactive" : void 0 }));
190
172
  }))
191
173
  )
192
174
  );
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @nutui/nutui-react-taro v2.7.6 Fri Jan 10 2025 10:44:00 GMT+0800 (China Standard Time)
2
+ * @nutui/nutui-react-taro v2.7.8 Fri Feb 14 2025 16:18:31 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.6 Fri Jan 10 2025 10:44:00 GMT+0800 (China Standard Time)
2
+ * @nutui/nutui-react-taro v2.7.8 Fri Feb 14 2025 16:18:31 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.6 Fri Jan 10 2025 10:44:00 GMT+0800 (China Standard Time)
2
+ * @nutui/nutui-react-taro v2.7.8 Fri Feb 14 2025 16:18:31 GMT+0800 (China Standard Time)
3
3
  * (c) 2023 @jdf2e.
4
4
  * Released under the MIT License.
5
5
  */