@nutui/nutui-react 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.
- package/CHANGELOG.md +29 -7
- package/dist/esm/Address/style/style.css +1 -1
- package/dist/esm/Animate/style/style.css +1 -1
- package/dist/esm/Animate.js +6 -9
- package/dist/esm/Calendar/style/style.css +1 -1
- package/dist/esm/Calendar.js +2 -2
- package/dist/esm/CalendarCard.js +4 -4
- package/dist/esm/CalendarItem.js +177 -180
- package/dist/esm/Cascader/style/style.css +1 -1
- package/dist/esm/DatePicker.js +8 -0
- package/dist/esm/Empty.js +1 -1
- package/dist/esm/Form.js +2 -1
- package/dist/esm/TabPane.js +1 -1
- package/dist/esm/Tabs/style/style.css +1 -1
- package/dist/esm/date.js +109 -181
- package/dist/esm/formitem2.js +121 -31
- package/dist/esm/tabs2.js +26 -42
- package/dist/locales/base.js +1 -1
- package/dist/locales/en-US.js +1 -1
- package/dist/locales/id-ID.js +1 -1
- package/dist/locales/tr-TR.js +1 -1
- package/dist/locales/zh-CN.js +1 -1
- package/dist/locales/zh-TW.js +1 -1
- package/dist/locales/zh-UG.js +1 -1
- package/dist/nutui.react.es.js +477 -517
- package/dist/nutui.react.umd.js +477 -517
- package/dist/packages/animate/animate.scss +63 -105
- package/dist/packages/calendar/calendar.scss +9 -9
- package/dist/packages/tabs/tabs.scss +72 -115
- package/dist/style.css +1 -1
- package/dist/types/packages/animate/animate.taro.d.ts +2 -1
- package/dist/types/packages/form/__tests__/merge.spec.d.ts +1 -0
- package/dist/types/packages/form/index.d.ts +2 -1
- package/dist/types/packages/form/index.taro.d.ts +2 -1
- package/dist/types/packages/form/useform.d.ts +2 -1
- package/dist/types/packages/form/useform.taro.d.ts +2 -1
- package/dist/types/utils/date.d.ts +54 -52
- package/dist/types/utils/merge.d.ts +14 -1
- package/package.json +1 -1
package/dist/esm/Empty.js
CHANGED
|
@@ -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 (
|
|
28
|
+
if (typeof imageSize !== "number" && typeof imageSize !== "string") {
|
|
29
29
|
return {};
|
|
30
30
|
}
|
|
31
31
|
if (typeof imageSize === "number") {
|
package/dist/esm/Form.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React__default from "react";
|
|
2
2
|
import classNames from "classnames";
|
|
3
|
-
import { u as useForm, S as SECRET, C as Context, F as FormItem } from "./formitem2.js";
|
|
3
|
+
import { u as useForm, S as SECRET, C as Context, F as FormItem, a as useWatch } from "./formitem2.js";
|
|
4
4
|
import { C as ComponentDefaults } from "./typings.js";
|
|
5
5
|
import Cell__default from "./Cell.js";
|
|
6
6
|
const defaultProps = Object.assign(Object.assign({}, ComponentDefaults), { labelPosition: "right", starPosition: "left", disabled: false, divider: false, validateTrigger: "onChange", onFinish: (values) => {
|
|
@@ -56,6 +56,7 @@ Form.displayName = "NutForm";
|
|
|
56
56
|
const InnerForm = Form;
|
|
57
57
|
InnerForm.Item = FormItem;
|
|
58
58
|
InnerForm.useForm = useForm;
|
|
59
|
+
InnerForm.useWatch = useWatch;
|
|
59
60
|
export {
|
|
60
61
|
InnerForm as default
|
|
61
62
|
};
|
package/dist/esm/TabPane.js
CHANGED
|
@@ -11,7 +11,7 @@ const TabPane = (props) => {
|
|
|
11
11
|
const classes = classNames(classPrefix, {
|
|
12
12
|
active: !disabled && props.active
|
|
13
13
|
}, autoHeightClassName, className);
|
|
14
|
-
return children
|
|
14
|
+
return children && React__default.createElement("div", { className: classes }, !disabled && children);
|
|
15
15
|
};
|
|
16
16
|
export {
|
|
17
17
|
TabPane as default
|
|
@@ -1 +1 @@
|
|
|
1
|
-
.nut-tabpane{width:100%;flex-shrink:0;display:block;background-color:var(--nutui-tabs-tabpane-backgroundColor, #fff);color:var(--nutui-gray-7, #1a1a1a);padding:var(--nutui-tabs-tabpane-padding, 24px 20px);box-sizing:border-box;overflow:auto}.nut-tabpane.inactive{overflow:visible;height:0}.nut-tabs{display:flex}.nut-tabs-titles{display:flex;box-sizing:border-box;height:var(--nutui-tabs-titles-height, 44px);-webkit-user-select:none;user-select:none;overflow:hidden;background:var(--nutui-tabs-titles-background-color, var(--nutui-gray-3, #f6f6f6));scrollbar-width:none}.nut-tabs-titles::-webkit-scrollbar{display:none;width:0;background:transparent}.nut-tabs-titles .nut-tabs-list{width:100%;
|
|
1
|
+
.nut-tabpane{width:100%;flex-shrink:0;display:block;background-color:var(--nutui-tabs-tabpane-backgroundColor, #fff);color:var(--nutui-gray-7, #1a1a1a);padding:var(--nutui-tabs-tabpane-padding, 24px 20px);box-sizing:border-box;overflow:auto}.nut-tabpane.inactive{overflow:visible;height:0}.nut-tabs{display:flex}.nut-tabs-horizontal{flex-direction:column}.nut-tabs-titles{display:flex;box-sizing:border-box;height:var(--nutui-tabs-titles-height, 44px);-webkit-user-select:none;user-select:none;overflow-x:auto;overflow-y:hidden;background:var(--nutui-tabs-titles-background-color, var(--nutui-gray-3, #f6f6f6));scrollbar-width:none}.nut-tabs-titles::-webkit-scrollbar{display:none;width:0;background:transparent}.nut-tabs-titles .nut-tabs-list{width:100%;display:flex;flex-shrink:0}.nut-tabs-titles-left{justify-content:flex-start}.nut-tabs-titles-left .nut-tabs-titles-item{padding:0 22px}.nut-tabs-titles-right{justify-content:flex-end}.nut-tabs-titles-right .nut-tabs-titles-item{padding:0 22px}.nut-tabs-titles-item{position:relative;display:flex;align-items:center;justify-content:center;flex:1 0 auto;padding:0 var(--nutui-tabs-titles-gap, 12px);height:var(--nutui-tabs-titles-height, 44px);line-height:var(--nutui-tabs-titles-height, 44px);min-width:var(--nutui-tabs-titles-item-min-width, 50px);font-size:var(--nutui-tabs-titles-font-size, var(--nutui-font-size-3, 14px));color:var(--nutui-tabs-titles-item-color, var(--nutui-gray-7, #1a1a1a));text-overflow:ellipsis;white-space:nowrap}.nut-tabs-titles-item .nut-icon{color:var(--nutui-tabs-titles-item-color, var(--nutui-gray-7, #1a1a1a))}.nut-tabs-titles-item-left,.nut-tabs-titles-item-right{flex:none}.nut-tabs-titles-item-text{color:var(--nutui-tabs-titles-item-color, var(--nutui-gray-7, #1a1a1a))}.nut-tabs-titles-item-smile,.nut-tabs-titles-item-line{position:absolute;transition:width .3s ease;width:0;height:0;content:" ";left:50%;transform:translate(-50%);bottom:var(--nutui-tabs-line-bottom, 15%);border-radius:var(--nutui-tabs-line-border-radius, 2px);opacity:var(--nutui-tabs-tab-line-opacity, 1);overflow:hidden}.nut-tabs-titles-item-smile{bottom:var(--nutui-tabs-titles-item-smile-bottom, -10%)}.nut-tabs-titles-item-smile .nut-icon{position:absolute;font-size:20px;width:100%;height:100%}.nut-tabs-titles-item-active .nut-icon{color:var(--nutui-tabs-titles-item-active-color, var(--nutui-color-primary, #fa2c19))}.nut-tabs-titles-item-active .nut-tabs-titles-item-text{color:var(--nutui-tabs-titles-item-active-color, var(--nutui-color-primary, #fa2c19));font-weight:var(--nutui-tabs-titles-item-active-font-weight, var(--nutui-font-weight-bold, 500))}.nut-tabs-titles-item-active .nut-tabs-titles-item-line{overflow:unset;content:" ";width:var(--nutui-tabs-tab-line-width, 12px);height:var(--nutui-tabs-tab-line-height, 2px);background:var(--nutui-tabs-tab-line-color, var(--nutui-color-primary, #fa2c19))}.nut-tabs-titles-item-active .nut-tabs-titles-item-smile{overflow:unset;width:40px;height:20px}.nut-tabs-titles-item-active .nut-tabs-titles-item-smile .nut-icon{color:var(--nutui-tabs-titles-item-active-color, var(--nutui-color-primary, #fa2c19))}.nut-tabs-titles-item-disabled,.nut-tabs-titles-item-disabled .nut-icon,.nut-tabs-titles-item-disabled .nut-tabs-titles-item-text{color:var(--nutui-color-text-disabled, #bfbfbf)}.nut-tabs-titles-simple .nut-tabs-titles-item-active .nut-tabs-titles-item-text,.nut-tabs-titles-simple .nut-tabs-titles-item-active .nut-icon{color:var(--nutui-gray-7, #1a1a1a);font-size:var(--nutui-tabs-titles-item-active-font-size, var(--nutui-font-size-4, 16px))}.nut-tabs-titles-card .nut-tabs-titles-item-active{font-weight:var(--nutui-font-weight-bold, 500);background-color:#fff;border-radius:var(--nutui-radius-3) var(--nutui-radius-3) 0 0}.nut-tabs-titles-button .nut-tabs-titles-item{padding:0 10px}.nut-tabs-titles-button .nut-tabs-titles-item .nut-tabs-titles-item-text{flex:1;height:28px;display:flex;align-items:center;justify-content:center;padding:0 8px}.nut-tabs-titles-button .nut-tabs-titles-item-active .nut-tabs-titles-item-text{background:var(--nutui-color-default-light);color:var(--nutui-tabs-titles-item-active-color, var(--nutui-color-primary, #fa2c19));border-radius:var(--nutui-tabs-button-border-radius, 50px);font-weight:var(--nutui-font-weight-bold, 500);background-color:var(--nutui-tabs-button-active-background-color, var(--nutui-color-primary-light, #ffeae8));border:var(--nutui-tabs-button-active-border, 1px solid var(--nutui-color-primary, #fa2c19))}.nut-tabs-titles-divider{border-bottom:1px solid var(--nutui-black-3, rgba(0, 0, 0, .06))}.nut-tabs-titles-divider .nut-tabs-titles-item{position:relative}.nut-tabs-titles-divider .nut-tabs-titles-item:after{content:"";position:absolute;right:0;top:50%;height:50%;width:1px;background:var(--nutui-black-3, rgba(0, 0, 0, .06));transform:translateY(-50%)}.nut-tabs-titles-divider .nut-tabs-titles-item:last-child:after{display:none}.nut-tabs-vertical .nut-tabs-ellipsis{white-space:break-spaces;padding-left:6px;width:90px;line-height:var(--nutui-font-size-3, 14px)}.nut-tabs-vertical .nut-tabs-titles{flex-direction:column;height:100%;width:var(--nutui-tabs-vertical-titles-width, 100px);flex-shrink:0}.nut-tabs-vertical .nut-tabs-titles .nut-tabs-list{flex-direction:column}.nut-tabs-vertical .nut-tabs-titles-item{height:var(--nutui-tabs-vertical-titles-item-height, 40px);flex:none}.nut-tabs-vertical .nut-tabs-titles-item-smile{overflow:hidden;transition:width .3s ease}.nut-tabs-vertical .nut-tabs-titles-item-line{transform:translateY(-50%);transition:height .3s ease}.nut-tabs-vertical .nut-tabs-titles-item-line-vertical{top:50%}.nut-tabs-vertical .nut-tabs-titles-item-active{background-color:var(--nutui-tabs-titles-item-active-background-color, var(--nutui-gray-1, #ffffff))}.nut-tabs-vertical .nut-tabs-titles-item-active .nut-tabs-titles-item-line{left:10px;width:var(--nutui-tabs-vertical-tab-line-width, 3px);height:var(--nutui-tabs-vertical-tab-line-height, 12px);background:var(--nutui-tabs-vertical-tab-line-color, linear-gradient(180deg, var(--nutui-color-primary-stop-1, #f53d4d) 0%, var(--nutui-color-primary-light, #ffeae8) 100%))}.nut-tabs-vertical .nut-tabs-titles-item-active .nut-tabs-titles-item-smile{right:-12px;bottom:-2%;left:auto;transform:rotate(320deg)}.nut-tabs-vertical .nut-tabs-horizontal .nut-tabs-titles{flex-direction:row;height:var(--nutui-tabs-titles-height, 44px);width:100%;padding:0!important}.nut-tabs-vertical .nut-tabs-horizontal .nut-tabs-titles .nut-tabs-list{flex-direction:row;height:auto}.nut-tabs-vertical .nut-tabs-horizontal .nut-tabs-content{flex-direction:row}.nut-tabs-vertical .nut-tabs-horizontal .nut-tabs-titles-item-active{background-color:initial}.nut-tabs-vertical .nut-tabs-horizontal .nut-tabs-titles-item-active .nut-tabs-titles-item-line{left:50%;transform:translate(-50%);width:var(--nutui-tabs-tab-line-width, 12px);height:var(--nutui-tabs-tab-line-height, 2px);background:var(--nutui-tabs-tab-line-color, var(--nutui-color-primary, #fa2c19))}.nut-tabs-vertical .nut-tabs-horizontal .nut-tabs-titles-item-active .nut-tabs-titles-item-smile{left:50%;right:auto;bottom:-3px;transform:translate(-50%) rotate(0)}.nut-tabs-vertical .nut-tabs-content{flex-direction:column;height:100%}.nut-tabs-vertical .nut-tabs-content-wrap{flex:1}.nut-tabs-vertical .nut-tabs-content .nut-tabpane{height:100%}.nut-tabs-content{display:flex;box-sizing:border-box}.nut-tabs-content-wrap{overflow:hidden}[dir=rtl] .nut-tabs-titles-item-smile,[dir=rtl] .nut-tabs-titles-item-line,.nut-rtl .nut-tabs-titles-item-smile,.nut-rtl .nut-tabs-titles-item-line{left:auto;right:50%;transform:translate(50%)}[dir=rtl] .nut-tabs-titles-divider .nut-tabs-titles-item:after,.nut-rtl .nut-tabs-titles-divider .nut-tabs-titles-item:after{right:auto;left:0}[dir=rtl] .nut-tabs-vertical .nut-tabs-titles-line .nut-tabs-titles-item,.nut-rtl .nut-tabs-vertical .nut-tabs-titles-line .nut-tabs-titles-item{padding-left:0;padding-right:14px}[dir=rtl] .nut-tabs-vertical .nut-tabs-titles-item-active .nut-tabs-titles-item-line,.nut-rtl .nut-tabs-vertical .nut-tabs-titles-item-active .nut-tabs-titles-item-line{left:auto;right:10px}[dir=rtl] .nut-tabs-vertical .nut-tabs-titles-item-active .nut-tabs-titles-item-smile,.nut-rtl .nut-tabs-vertical .nut-tabs-titles-item-active .nut-tabs-titles-item-smile{left:-12px;right:auto;transform:rotate(-320deg)}[dir=rtl] .nut-tabs-vertical .nut-tabs-horizontal .nut-tabs-titles-item-active .nut-tabs-titles-item-line,.nut-rtl .nut-tabs-vertical .nut-tabs-horizontal .nut-tabs-titles-item-active .nut-tabs-titles-item-line{left:auto;right:50%;transform:translate(50%)}[dir=rtl] .nut-tabs-vertical .nut-tabs-horizontal .nut-tabs-titles-item-active .nut-tabs-titles-item-smile,.nut-rtl .nut-tabs-vertical .nut-tabs-horizontal .nut-tabs-titles-item-active .nut-tabs-titles-item-smile{right:50%;left:auto;transform:translate(50%) rotate(0)}
|
package/dist/esm/date.js
CHANGED
|
@@ -1,184 +1,103 @@
|
|
|
1
|
-
const
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
];
|
|
25
|
-
return dayNames[index];
|
|
26
|
-
},
|
|
27
|
-
/**
|
|
28
|
-
* 返回上一个月在当前面板中的天数
|
|
29
|
-
* @return {Number}
|
|
30
|
-
*/
|
|
31
|
-
getMonthPreDay(year, month) {
|
|
32
|
-
const date = /* @__PURE__ */ new Date(`${year}/${month}/01`);
|
|
33
|
-
let day = date.getDay();
|
|
34
|
-
if (day === 0) {
|
|
35
|
-
day = 7;
|
|
36
|
-
}
|
|
37
|
-
return day;
|
|
38
|
-
},
|
|
39
|
-
/**
|
|
40
|
-
* 返回月份天数
|
|
41
|
-
* @return {Number}
|
|
42
|
-
*/
|
|
43
|
-
getMonthDays(year, month) {
|
|
44
|
-
if (/^0/.test(month)) {
|
|
45
|
-
month = month.split("")[1];
|
|
46
|
-
}
|
|
47
|
-
return [
|
|
48
|
-
0,
|
|
49
|
-
31,
|
|
50
|
-
this.isLeapYear(Number(year)) ? 29 : 28,
|
|
51
|
-
31,
|
|
52
|
-
30,
|
|
53
|
-
31,
|
|
54
|
-
30,
|
|
55
|
-
31,
|
|
56
|
-
31,
|
|
57
|
-
30,
|
|
58
|
-
31,
|
|
59
|
-
30,
|
|
60
|
-
31
|
|
61
|
-
][month];
|
|
62
|
-
},
|
|
63
|
-
/**
|
|
64
|
-
* 补齐数字位数
|
|
65
|
-
* @return {string}
|
|
66
|
-
*/
|
|
67
|
-
getNumTwoBit(n) {
|
|
68
|
-
n = Number(n);
|
|
69
|
-
return (n > 9 ? "" : "0") + n;
|
|
70
|
-
},
|
|
71
|
-
/**
|
|
72
|
-
* 日期对象转成字符串
|
|
73
|
-
* @return {string}
|
|
74
|
-
*/
|
|
75
|
-
date2Str(date, split) {
|
|
76
|
-
split = split || "-";
|
|
77
|
-
const y = date.getFullYear();
|
|
78
|
-
const m = this.getNumTwoBit(date.getMonth() + 1);
|
|
79
|
-
const d = this.getNumTwoBit(date.getDate());
|
|
80
|
-
return [y, m, d].join(split);
|
|
81
|
-
},
|
|
82
|
-
/**
|
|
83
|
-
* 返回日期格式字符串
|
|
84
|
-
* @param {Number} 0返回今天的日期、1返回明天的日期,2返回后天得日期,依次类推
|
|
85
|
-
* @return {string} '2014-12-31'
|
|
86
|
-
*/
|
|
87
|
-
getDay(i) {
|
|
88
|
-
i = i || 0;
|
|
89
|
-
let date = /* @__PURE__ */ new Date();
|
|
90
|
-
const diff = i * (1e3 * 60 * 60 * 24);
|
|
91
|
-
date = new Date(date.getTime() + diff);
|
|
92
|
-
return this.date2Str(date);
|
|
93
|
-
},
|
|
94
|
-
/**
|
|
95
|
-
* 时间比较
|
|
96
|
-
* @return {Boolean}
|
|
97
|
-
*/
|
|
98
|
-
compareDate(date1, date2) {
|
|
99
|
-
const startTime = new Date(date1.replace("-", "/").replace("-", "/"));
|
|
100
|
-
const endTime = new Date(date2.replace("-", "/").replace("-", "/"));
|
|
101
|
-
if (startTime >= endTime) {
|
|
102
|
-
return false;
|
|
103
|
-
}
|
|
104
|
-
return true;
|
|
105
|
-
},
|
|
106
|
-
/**
|
|
107
|
-
* 时间是否相等
|
|
108
|
-
* @return {Boolean}
|
|
109
|
-
*/
|
|
110
|
-
isEqual(date1, date2) {
|
|
111
|
-
const startTime = new Date((date1 || "").replace(/-/g, "/")).getTime();
|
|
112
|
-
const endTime = new Date(date2.replace(/-/g, "/")).getTime();
|
|
113
|
-
if (startTime === endTime) {
|
|
114
|
-
return true;
|
|
115
|
-
}
|
|
116
|
-
return false;
|
|
117
|
-
},
|
|
118
|
-
getMonthWeek(year, month, date, firstDayOfWeek = 0) {
|
|
119
|
-
const dateNow = new Date(Number(year), parseInt(month) - 1, Number(date));
|
|
120
|
-
let w = dateNow.getDay();
|
|
121
|
-
const d = dateNow.getDate();
|
|
122
|
-
let remainder = 6 - w;
|
|
123
|
-
if (firstDayOfWeek !== 0) {
|
|
124
|
-
w = w === 0 ? 7 : w;
|
|
125
|
-
remainder = 7 - w;
|
|
126
|
-
}
|
|
127
|
-
return Math.ceil((d + remainder) / 7);
|
|
128
|
-
},
|
|
129
|
-
getYearWeek(year, month, date, firstDayOfWeek = 0) {
|
|
130
|
-
const dateNow = new Date(Number(year), parseInt(month) - 1, Number(date));
|
|
131
|
-
const dateFirst = new Date(Number(year), 0, 1);
|
|
132
|
-
const dataNumber = Math.round((dateNow.valueOf() - dateFirst.valueOf()) / 864e5);
|
|
133
|
-
return Math.ceil((dataNumber + (dateFirst.getDay() + 1 - 1)) / 7);
|
|
134
|
-
},
|
|
135
|
-
getWeekDate(year, month, date, firstDayOfWeek = 0) {
|
|
136
|
-
const dateNow = new Date(Number(year), parseInt(month) - 1, Number(date));
|
|
137
|
-
const nowTime = dateNow.getTime();
|
|
138
|
-
let day = dateNow.getDay();
|
|
139
|
-
if (firstDayOfWeek === 0) {
|
|
140
|
-
const oneDayTime2 = 24 * 60 * 60 * 1e3;
|
|
141
|
-
const SundayTime2 = nowTime - day * oneDayTime2;
|
|
142
|
-
const SaturdayTime = nowTime + (6 - day) * oneDayTime2;
|
|
143
|
-
const sunday2 = this.date2Str(new Date(SundayTime2));
|
|
144
|
-
const saturday = this.date2Str(new Date(SaturdayTime));
|
|
145
|
-
return [sunday2, saturday];
|
|
146
|
-
}
|
|
147
|
-
day = day === 0 ? 7 : day;
|
|
148
|
-
const oneDayTime = 24 * 60 * 60 * 1e3;
|
|
149
|
-
const MondayTime = nowTime - (day - 1) * oneDayTime;
|
|
150
|
-
const SundayTime = nowTime + (7 - day) * oneDayTime;
|
|
151
|
-
const monday = this.date2Str(new Date(MondayTime));
|
|
152
|
-
const sunday = this.date2Str(new Date(SundayTime));
|
|
153
|
-
return [monday, sunday];
|
|
154
|
-
},
|
|
155
|
-
formatResultDate(date) {
|
|
156
|
-
const days = [...date.split("-")];
|
|
157
|
-
days[2] = Utils.getNumTwoBit(Number(days[2]));
|
|
158
|
-
days[3] = `${days[0]}-${days[1]}-${days[2]}`;
|
|
159
|
-
days[4] = Utils.getWhatDay(+days[0], +days[1], +days[2]);
|
|
160
|
-
return days;
|
|
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];
|
|
161
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];
|
|
162
91
|
};
|
|
163
92
|
const getCurrMonthData = (type, year, month) => {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
month = month === 1 ? 12 : --month;
|
|
168
|
-
break;
|
|
169
|
-
case "next":
|
|
170
|
-
month === 12 && (year += 1);
|
|
171
|
-
month = month === 12 ? 1 : ++month;
|
|
172
|
-
break;
|
|
93
|
+
{
|
|
94
|
+
month === 12 && (year += 1);
|
|
95
|
+
month = month === 12 ? 1 : ++month;
|
|
173
96
|
}
|
|
174
|
-
return [
|
|
175
|
-
year,
|
|
176
|
-
Utils.getNumTwoBit(month),
|
|
177
|
-
Utils.getMonthDays(String(year), String(month))
|
|
178
|
-
];
|
|
97
|
+
return [year, getNumTwoBit(month), getMonthDays(String(year), String(month))];
|
|
179
98
|
};
|
|
180
99
|
const getDaysStatus = (type, year, month) => {
|
|
181
|
-
let days =
|
|
100
|
+
let days = getMonthDays(`${year}`, `${month}`);
|
|
182
101
|
return Array.from(Array(days), (v, k) => {
|
|
183
102
|
return {
|
|
184
103
|
day: k + 1,
|
|
@@ -195,12 +114,12 @@ const getPreMonthDates = (type, year, month, firstDayOfWeek) => {
|
|
|
195
114
|
preMonth = 12;
|
|
196
115
|
preYear += 1;
|
|
197
116
|
}
|
|
198
|
-
let days =
|
|
117
|
+
let days = getMonthPreDay(+year, +month);
|
|
199
118
|
days -= firstDayOfWeek;
|
|
200
119
|
if (days >= 7) {
|
|
201
120
|
days -= 7;
|
|
202
121
|
}
|
|
203
|
-
const preDates =
|
|
122
|
+
const preDates = getMonthDays(`${preYear}`, `${preMonth}`);
|
|
204
123
|
const months = Array.from(Array(preDates), (v, k) => {
|
|
205
124
|
return {
|
|
206
125
|
day: k + 1,
|
|
@@ -212,8 +131,17 @@ const getPreMonthDates = (type, year, month, firstDayOfWeek) => {
|
|
|
212
131
|
return months.slice(preDates - days);
|
|
213
132
|
};
|
|
214
133
|
export {
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
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
|
|
219
147
|
};
|
package/dist/esm/formitem2.js
CHANGED
|
@@ -1,28 +1,65 @@
|
|
|
1
|
-
import React__default, { createContext, useRef } from "react";
|
|
1
|
+
import React__default, { createContext, useRef, useState, useEffect } from "react";
|
|
2
2
|
import Cell__default from "./Cell.js";
|
|
3
3
|
import { C as ComponentDefaults } from "./typings.js";
|
|
4
4
|
import { a as __awaiter } from "./tslib.es6.js";
|
|
5
5
|
import Schema from "async-validator";
|
|
6
6
|
const Context = createContext({});
|
|
7
|
-
function merge(...
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
7
|
+
function merge(...items) {
|
|
8
|
+
return _merge(items[0] === true, false, items);
|
|
9
|
+
}
|
|
10
|
+
function recursive(...items) {
|
|
11
|
+
return _merge(items[0] === true, true, items);
|
|
12
|
+
}
|
|
13
|
+
function clone(input) {
|
|
14
|
+
if (Array.isArray(input)) {
|
|
15
|
+
const output = [];
|
|
16
|
+
for (let index = 0; index < input.length; ++index)
|
|
17
|
+
output.push(clone(input[index]));
|
|
18
|
+
return output;
|
|
19
|
+
}
|
|
20
|
+
if (isPlainObject(input)) {
|
|
21
|
+
const output = {};
|
|
22
|
+
for (const index in input)
|
|
23
|
+
output[index] = clone(input[index]);
|
|
24
|
+
return output;
|
|
25
|
+
}
|
|
26
|
+
return input;
|
|
27
|
+
}
|
|
28
|
+
function isPlainObject(input) {
|
|
29
|
+
if (input === null || typeof input !== "object")
|
|
30
|
+
return false;
|
|
31
|
+
if (Object.getPrototypeOf(input) === null)
|
|
32
|
+
return true;
|
|
33
|
+
let ref = input;
|
|
34
|
+
while (Object.getPrototypeOf(ref) !== null)
|
|
35
|
+
ref = Object.getPrototypeOf(ref);
|
|
36
|
+
return Object.getPrototypeOf(input) === ref;
|
|
37
|
+
}
|
|
38
|
+
function _recursiveMerge(base, extend) {
|
|
39
|
+
if (!isPlainObject(base) || !isPlainObject(extend))
|
|
40
|
+
return extend;
|
|
41
|
+
for (const key in extend) {
|
|
42
|
+
if (key === "__proto__" || key === "constructor" || key === "prototype")
|
|
43
|
+
continue;
|
|
44
|
+
base[key] = isPlainObject(base[key]) && isPlainObject(extend[key]) ? _recursiveMerge(base[key], extend[key]) : extend[key];
|
|
45
|
+
}
|
|
46
|
+
return base;
|
|
47
|
+
}
|
|
48
|
+
function _merge(isClone, isRecursive, items) {
|
|
49
|
+
let result;
|
|
50
|
+
if (isClone || !isPlainObject(result = items.shift()))
|
|
51
|
+
result = {};
|
|
52
|
+
for (let index = 0; index < items.length; ++index) {
|
|
53
|
+
const item = items[index];
|
|
54
|
+
if (!isPlainObject(item))
|
|
55
|
+
continue;
|
|
56
|
+
for (const key in item) {
|
|
57
|
+
if (key === "__proto__" || key === "constructor" || key === "prototype")
|
|
58
|
+
continue;
|
|
59
|
+
const value = isClone ? clone(item[key]) : item[key];
|
|
60
|
+
result[key] = isRecursive ? _recursiveMerge(result[key], value) : value;
|
|
23
61
|
}
|
|
24
62
|
}
|
|
25
|
-
objects.filter((obj) => !!obj).forEach((obj) => mergeHelper(obj));
|
|
26
63
|
return result;
|
|
27
64
|
}
|
|
28
65
|
const SECRET = "NUT_FORM_INTERNAL";
|
|
@@ -38,9 +75,6 @@ class FormStore {
|
|
|
38
75
|
this.fieldEntities.push(field);
|
|
39
76
|
return () => {
|
|
40
77
|
this.fieldEntities = this.fieldEntities.filter((item) => item !== field);
|
|
41
|
-
if (this.store) {
|
|
42
|
-
delete this.store[field.props.name];
|
|
43
|
-
}
|
|
44
78
|
};
|
|
45
79
|
};
|
|
46
80
|
this.getFieldValue = (name) => {
|
|
@@ -62,10 +96,11 @@ class FormStore {
|
|
|
62
96
|
if (init) {
|
|
63
97
|
const nextStore = merge(initialValues, this.store);
|
|
64
98
|
this.updateStore(nextStore);
|
|
99
|
+
this.notifyWatch();
|
|
65
100
|
}
|
|
66
101
|
};
|
|
67
102
|
this.setFieldsValue = (newStore) => {
|
|
68
|
-
const nextStore =
|
|
103
|
+
const nextStore = recursive(true, this.store, newStore);
|
|
69
104
|
this.updateStore(nextStore);
|
|
70
105
|
this.fieldEntities.forEach((entity) => {
|
|
71
106
|
const { name } = entity.props;
|
|
@@ -84,12 +119,14 @@ class FormStore {
|
|
|
84
119
|
item.entity.onStoreChange("update");
|
|
85
120
|
}
|
|
86
121
|
});
|
|
122
|
+
this.notifyWatch();
|
|
87
123
|
};
|
|
88
124
|
this.setFieldValue = (name, value) => {
|
|
89
125
|
const store = {
|
|
90
126
|
[name]: value
|
|
91
127
|
};
|
|
92
128
|
this.setFieldsValue(store);
|
|
129
|
+
this.notifyWatch([name]);
|
|
93
130
|
};
|
|
94
131
|
this.setCallback = (callback) => {
|
|
95
132
|
this.callbacks = Object.assign(Object.assign({}, this.callbacks), callback);
|
|
@@ -129,7 +166,6 @@ class FormStore {
|
|
|
129
166
|
});
|
|
130
167
|
this.validateFields = (nameList) => __awaiter(this, void 0, void 0, function* () {
|
|
131
168
|
let filterEntities = [];
|
|
132
|
-
this.errors.length = 0;
|
|
133
169
|
if (!nameList || nameList.length === 0) {
|
|
134
170
|
filterEntities = this.fieldEntities;
|
|
135
171
|
} else {
|
|
@@ -150,13 +186,29 @@ class FormStore {
|
|
|
150
186
|
(_d = (_c = this.callbacks).onFinishFailed) === null || _d === void 0 ? void 0 : _d.call(_c, this.store, errors);
|
|
151
187
|
}
|
|
152
188
|
});
|
|
153
|
-
this.resetFields = () => {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
189
|
+
this.resetFields = (namePaths) => {
|
|
190
|
+
if (namePaths && namePaths.length) {
|
|
191
|
+
namePaths.forEach((path) => {
|
|
192
|
+
this.errors[path] = null;
|
|
193
|
+
this.fieldEntities.forEach((entity) => {
|
|
194
|
+
const name = entity.props.name;
|
|
195
|
+
if (name === path) {
|
|
196
|
+
if (path in this.initialValues) {
|
|
197
|
+
this.updateStore({ [path]: this.initialValues[path] });
|
|
198
|
+
} else {
|
|
199
|
+
delete this.store[path];
|
|
200
|
+
}
|
|
201
|
+
entity.onStoreChange("reset");
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
} else {
|
|
206
|
+
const nextStore = merge({}, this.initialValues);
|
|
207
|
+
this.updateStore(nextStore);
|
|
208
|
+
this.fieldEntities.forEach((entity) => {
|
|
209
|
+
entity.onStoreChange("reset");
|
|
210
|
+
});
|
|
211
|
+
}
|
|
160
212
|
};
|
|
161
213
|
this.registerUpdate = (field, shouldUpdate) => {
|
|
162
214
|
this.updateList.push({
|
|
@@ -179,7 +231,8 @@ class FormStore {
|
|
|
179
231
|
dispatch: this.dispatch,
|
|
180
232
|
store: this.store,
|
|
181
233
|
fieldEntities: this.fieldEntities,
|
|
182
|
-
registerUpdate: this.registerUpdate
|
|
234
|
+
registerUpdate: this.registerUpdate,
|
|
235
|
+
registerWatch: this.registerWatch
|
|
183
236
|
};
|
|
184
237
|
}
|
|
185
238
|
};
|
|
@@ -196,6 +249,26 @@ class FormStore {
|
|
|
196
249
|
getInternal: this.getInternal
|
|
197
250
|
};
|
|
198
251
|
};
|
|
252
|
+
this.watchList = [];
|
|
253
|
+
this.registerWatch = (callback) => {
|
|
254
|
+
this.watchList.push(callback);
|
|
255
|
+
return () => {
|
|
256
|
+
this.watchList = this.watchList.filter((fn) => fn !== callback);
|
|
257
|
+
};
|
|
258
|
+
};
|
|
259
|
+
this.notifyWatch = (namePath = []) => {
|
|
260
|
+
if (this.watchList.length) {
|
|
261
|
+
let allValues;
|
|
262
|
+
if (!namePath || namePath.length === 0) {
|
|
263
|
+
allValues = this.getFieldsValue(true);
|
|
264
|
+
} else {
|
|
265
|
+
allValues = this.getFieldsValue(namePath);
|
|
266
|
+
}
|
|
267
|
+
this.watchList.forEach((callback) => {
|
|
268
|
+
callback(allValues, namePath);
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
};
|
|
199
272
|
this.callbacks = {
|
|
200
273
|
onFinish: () => {
|
|
201
274
|
},
|
|
@@ -219,6 +292,22 @@ const useForm = (form) => {
|
|
|
219
292
|
}
|
|
220
293
|
return [formRef.current];
|
|
221
294
|
};
|
|
295
|
+
const useWatch = (path, form) => {
|
|
296
|
+
const formInstance = form.getInternal(SECRET);
|
|
297
|
+
const [value, setValue] = useState();
|
|
298
|
+
useEffect(() => {
|
|
299
|
+
const unsubscribe = formInstance.registerWatch((data, namePath) => {
|
|
300
|
+
const value2 = data[path];
|
|
301
|
+
setValue(value2);
|
|
302
|
+
});
|
|
303
|
+
const initialValue = form.getFieldsValue(true);
|
|
304
|
+
if (value !== initialValue[path]) {
|
|
305
|
+
setValue(initialValue[path]);
|
|
306
|
+
}
|
|
307
|
+
return () => unsubscribe();
|
|
308
|
+
}, [form]);
|
|
309
|
+
return value;
|
|
310
|
+
};
|
|
222
311
|
function isForwardRefComponent(component) {
|
|
223
312
|
return component.type && component.type.$$typeof && // eslint-disable-next-line react/display-name
|
|
224
313
|
React__default.forwardRef(
|
|
@@ -384,5 +473,6 @@ export {
|
|
|
384
473
|
Context as C,
|
|
385
474
|
FormItem as F,
|
|
386
475
|
SECRET as S,
|
|
476
|
+
useWatch as a,
|
|
387
477
|
useForm as u
|
|
388
478
|
};
|