@arco-design/mobile-react 2.36.0 → 2.36.2
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 +24 -0
- package/README.en-US.md +2 -2
- package/README.md +2 -2
- package/cjs/carousel/index.js +8 -7
- package/cjs/ellipsis/components/js-ellipsis.js +3 -1
- package/cjs/form/form-item.d.ts +33 -2
- package/cjs/form/form-item.js +142 -121
- package/cjs/form/index.js +3 -1
- package/cjs/form/linked-container.d.ts +1 -1
- package/cjs/form/linked-container.js +4 -0
- package/cjs/form/style/css/index.css +4 -1
- package/cjs/form/style/index.less +6 -1
- package/cjs/form/type.d.ts +24 -1
- package/cjs/form/type.js +10 -2
- package/cjs/form/useForm.d.ts +2 -17
- package/cjs/form/useForm.js +98 -17
- package/cjs/form/utils.d.ts +2 -0
- package/cjs/form/utils.js +42 -2
- package/cjs/input/index.js +1 -1
- package/cjs/popover/hooks/usePosition.js +26 -8
- package/cjs/radio/group.js +1 -1
- package/cjs/radio/type.d.ts +2 -2
- package/dist/index.js +3021 -370
- package/dist/index.min.js +4 -4
- package/dist/style.css +4 -1
- package/dist/style.min.css +1 -1
- package/esm/carousel/index.js +8 -7
- package/esm/ellipsis/components/js-ellipsis.js +3 -1
- package/esm/form/form-item.d.ts +33 -2
- package/esm/form/form-item.js +143 -122
- package/esm/form/index.js +3 -1
- package/esm/form/linked-container.d.ts +1 -1
- package/esm/form/linked-container.js +4 -0
- package/esm/form/style/css/index.css +4 -1
- package/esm/form/style/index.less +6 -1
- package/esm/form/type.d.ts +24 -1
- package/esm/form/type.js +8 -1
- package/esm/form/useForm.d.ts +2 -17
- package/esm/form/useForm.js +97 -17
- package/esm/form/utils.d.ts +2 -0
- package/esm/form/utils.js +31 -1
- package/esm/input/index.js +1 -1
- package/esm/popover/hooks/usePosition.js +26 -8
- package/esm/radio/group.js +1 -1
- package/esm/radio/type.d.ts +2 -2
- package/esnext/carousel/index.js +7 -5
- package/esnext/ellipsis/components/js-ellipsis.js +2 -0
- package/esnext/form/form-item.d.ts +33 -2
- package/esnext/form/form-item.js +85 -71
- package/esnext/form/index.js +2 -1
- package/esnext/form/linked-container.d.ts +1 -1
- package/esnext/form/linked-container.js +3 -0
- package/esnext/form/style/css/index.css +4 -1
- package/esnext/form/style/index.less +6 -1
- package/esnext/form/type.d.ts +24 -1
- package/esnext/form/type.js +7 -0
- package/esnext/form/useForm.d.ts +2 -17
- package/esnext/form/useForm.js +72 -13
- package/esnext/form/utils.d.ts +2 -0
- package/esnext/form/utils.js +26 -0
- package/esnext/input/index.js +1 -1
- package/esnext/popover/hooks/usePosition.js +32 -12
- package/esnext/radio/group.js +3 -1
- package/esnext/radio/type.d.ts +2 -2
- package/package.json +3 -3
- package/umd/carousel/index.js +8 -7
- package/umd/ellipsis/components/js-ellipsis.js +3 -1
- package/umd/form/form-item.d.ts +33 -2
- package/umd/form/form-item.js +142 -121
- package/umd/form/index.js +3 -1
- package/umd/form/linked-container.d.ts +1 -1
- package/umd/form/linked-container.js +4 -0
- package/umd/form/style/css/index.css +4 -1
- package/umd/form/style/index.less +6 -1
- package/umd/form/type.d.ts +24 -1
- package/umd/form/type.js +9 -1
- package/umd/form/useForm.d.ts +2 -17
- package/umd/form/useForm.js +98 -21
- package/umd/form/utils.d.ts +2 -0
- package/umd/form/utils.js +40 -5
- package/umd/input/index.js +1 -1
- package/umd/popover/hooks/usePosition.js +26 -8
- package/umd/radio/group.js +1 -1
- package/umd/radio/type.d.ts +2 -2
package/umd/form/useForm.js
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
(function (global, factory) {
|
2
2
|
if (typeof define === "function" && define.amd) {
|
3
|
-
define(["exports", "@babel/runtime/helpers/extends", "react", "es6-promise"], factory);
|
3
|
+
define(["exports", "@babel/runtime/helpers/extends", "react", "es6-promise", "./type", "./utils"], factory);
|
4
4
|
} else if (typeof exports !== "undefined") {
|
5
|
-
factory(exports, require("@babel/runtime/helpers/extends"), require("react"), require("es6-promise"));
|
5
|
+
factory(exports, require("@babel/runtime/helpers/extends"), require("react"), require("es6-promise"), require("./type"), require("./utils"));
|
6
6
|
} else {
|
7
7
|
var mod = {
|
8
8
|
exports: {}
|
9
9
|
};
|
10
|
-
factory(mod.exports, global._extends, global.react, global.es6Promise);
|
10
|
+
factory(mod.exports, global._extends, global.react, global.es6Promise, global.type, global.utils);
|
11
11
|
global.useForm = mod.exports;
|
12
12
|
}
|
13
|
-
})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _extends6, _react, _es6Promise) {
|
13
|
+
})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _extends6, _react, _es6Promise, _type, _utils) {
|
14
14
|
"use strict";
|
15
15
|
|
16
16
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
@@ -49,7 +49,11 @@
|
|
49
49
|
return {
|
50
50
|
registerField: defaultFunc,
|
51
51
|
setInitialValues: defaultFunc,
|
52
|
-
setCallbacks: defaultFunc
|
52
|
+
setCallbacks: defaultFunc,
|
53
|
+
getInitialValue: defaultFunc,
|
54
|
+
setInitialValue: defaultFunc,
|
55
|
+
innerSetFieldsValue: defaultFunc,
|
56
|
+
innerSetFieldValue: defaultFunc
|
53
57
|
};
|
54
58
|
}
|
55
59
|
}; // 在field的静态的状态下设置
|
@@ -64,42 +68,82 @@
|
|
64
68
|
this._initialValues = {};
|
65
69
|
this._callbacks = {};
|
66
70
|
|
67
|
-
this.
|
71
|
+
this.commonSetFieldsValue = function (values, changeType) {
|
68
72
|
var oldValues = Object.keys(values).reduce(function (acc, key) {
|
69
73
|
var _extends2;
|
70
74
|
|
71
75
|
return (0, _extends6.default)({}, acc, (_extends2 = {}, _extends2[key] = _this.getFieldValue(key), _extends2));
|
72
76
|
}, {});
|
73
77
|
_this._formData = (0, _extends6.default)({}, _this._formData, values);
|
78
|
+
|
79
|
+
_this.notifyField(values, oldValues, changeType);
|
80
|
+
};
|
81
|
+
|
82
|
+
this.setFieldsValue = function (values) {
|
83
|
+
_this.commonSetFieldsValue(values);
|
84
|
+
|
74
85
|
var onValuesChange = _this._callbacks.onValuesChange;
|
75
|
-
onValuesChange
|
86
|
+
onValuesChange == null ? void 0 : onValuesChange(values, _this._formData);
|
87
|
+
return true;
|
88
|
+
};
|
76
89
|
|
77
|
-
|
90
|
+
this.innerSetFieldsValue = function (values, changeType) {
|
91
|
+
_this.commonSetFieldsValue(values, changeType);
|
78
92
|
|
93
|
+
var _this$_callbacks = _this._callbacks,
|
94
|
+
onValuesChange = _this$_callbacks.onValuesChange,
|
95
|
+
onChange = _this$_callbacks.onChange;
|
96
|
+
onValuesChange == null ? void 0 : onValuesChange(values, _this._formData);
|
97
|
+
onChange == null ? void 0 : onChange(values, _this._formData);
|
79
98
|
return true;
|
80
99
|
};
|
81
100
|
|
82
|
-
this.
|
83
|
-
var _oldValues, _extends3,
|
101
|
+
this.commonSetFieldValue = function (name, value, changeType) {
|
102
|
+
var _oldValues, _extends3, _this$notifyField;
|
84
103
|
|
85
104
|
var oldValues = (_oldValues = {}, _oldValues[name] = _this.getFieldValue(name), _oldValues);
|
86
105
|
_this._formData = (0, _extends6.default)({}, _this._formData, (_extends3 = {}, _extends3[name] = value, _extends3));
|
106
|
+
|
107
|
+
_this.notifyField((_this$notifyField = {}, _this$notifyField[name] = value, _this$notifyField), oldValues, changeType);
|
108
|
+
};
|
109
|
+
|
110
|
+
this.setFieldValue = function (name, value) {
|
111
|
+
var _onValuesChange;
|
112
|
+
|
113
|
+
_this.commonSetFieldValue(name, value);
|
114
|
+
|
87
115
|
var onValuesChange = _this._callbacks.onValuesChange;
|
88
|
-
onValuesChange && onValuesChange((_onValuesChange = {}, _onValuesChange[name] = value, _onValuesChange), _this.
|
116
|
+
onValuesChange && onValuesChange((_onValuesChange = {}, _onValuesChange[name] = value, _onValuesChange), _this.getFieldsValue());
|
117
|
+
return true;
|
118
|
+
};
|
119
|
+
|
120
|
+
this.innerSetFieldValue = function (name, value, changeType) {
|
121
|
+
var _onValuesChange2, _onChange;
|
89
122
|
|
90
|
-
_this.
|
123
|
+
_this.commonSetFieldValue(name, value, changeType);
|
91
124
|
|
125
|
+
var _this$_callbacks2 = _this._callbacks,
|
126
|
+
onValuesChange = _this$_callbacks2.onValuesChange,
|
127
|
+
onChange = _this$_callbacks2.onChange;
|
128
|
+
onValuesChange && onValuesChange((_onValuesChange2 = {}, _onValuesChange2[name] = value, _onValuesChange2), _this._formData);
|
129
|
+
onChange && onChange((_onChange = {}, _onChange[name] = value, _onChange), _this._formData);
|
92
130
|
return true;
|
93
131
|
};
|
94
132
|
|
95
|
-
this.notifyField = function (values, oldValues) {
|
133
|
+
this.notifyField = function (values, oldValues, changeType) {
|
134
|
+
if (changeType === void 0) {
|
135
|
+
changeType = _type.ValueChangeType.Update;
|
136
|
+
}
|
137
|
+
|
96
138
|
Object.keys(values).map(function (fieldName) {
|
97
139
|
var _this$_fieldsList;
|
98
140
|
|
99
141
|
var fieldObj = ((_this$_fieldsList = _this._fieldsList) == null ? void 0 : _this$_fieldsList[fieldName]) || null;
|
100
142
|
|
101
143
|
if (fieldObj) {
|
102
|
-
fieldObj.onValueChange(values[fieldName], oldValues[fieldName]
|
144
|
+
fieldObj.onValueChange(values[fieldName], oldValues[fieldName], {
|
145
|
+
changeType: changeType
|
146
|
+
});
|
103
147
|
}
|
104
148
|
});
|
105
149
|
};
|
@@ -111,13 +155,13 @@
|
|
111
155
|
});
|
112
156
|
}
|
113
157
|
|
114
|
-
return _this._formData;
|
158
|
+
return (0, _utils.deepClone)(_this._formData);
|
115
159
|
};
|
116
160
|
|
117
161
|
this.getFieldValue = function (name) {
|
118
162
|
var _this$_formData;
|
119
163
|
|
120
|
-
return (_this$_formData = _this._formData) == null ? void 0 : _this$_formData[name];
|
164
|
+
return (0, _utils.deepClone)((_this$_formData = _this._formData) == null ? void 0 : _this$_formData[name]);
|
121
165
|
};
|
122
166
|
|
123
167
|
this.getFieldError = function (name) {
|
@@ -180,13 +224,42 @@
|
|
180
224
|
};
|
181
225
|
|
182
226
|
this.setInitialValues = function (initVal) {
|
183
|
-
_this._initialValues = (0,
|
227
|
+
_this._initialValues = (0, _utils.deepClone)(initVal || {});
|
184
228
|
|
185
229
|
_this.setFieldsValue(initVal);
|
186
230
|
};
|
187
231
|
|
232
|
+
this.setInitialValue = function (fieldName, value) {
|
233
|
+
if (!fieldName) {
|
234
|
+
return;
|
235
|
+
}
|
236
|
+
|
237
|
+
_this._initialValues[fieldName] = value;
|
238
|
+
|
239
|
+
_this.setFieldValue(fieldName, value);
|
240
|
+
};
|
241
|
+
|
242
|
+
this.getInitialValue = function (fieldName) {
|
243
|
+
return _this._initialValues[fieldName];
|
244
|
+
};
|
245
|
+
|
188
246
|
this.resetFields = function () {
|
189
|
-
|
247
|
+
var oldValues = (0, _extends6.default)({}, _this._formData);
|
248
|
+
var initialValues = {};
|
249
|
+
Object.keys(_this._formData).forEach(function (fieldName) {
|
250
|
+
var _this$_fieldsList5;
|
251
|
+
|
252
|
+
var fieldObj = ((_this$_fieldsList5 = _this._fieldsList) == null ? void 0 : _this$_fieldsList5[fieldName]) || null;
|
253
|
+
|
254
|
+
if (fieldObj) {
|
255
|
+
initialValues[fieldName] = fieldObj.getInitialValue();
|
256
|
+
}
|
257
|
+
});
|
258
|
+
var onValuesChange = _this._callbacks.onValuesChange;
|
259
|
+
onValuesChange && onValuesChange(initialValues, _this._formData);
|
260
|
+
_this._formData = initialValues;
|
261
|
+
|
262
|
+
_this.notifyField(initialValues, oldValues, _type.ValueChangeType.Reset);
|
190
263
|
};
|
191
264
|
|
192
265
|
this.validateFields = function () {
|
@@ -218,7 +291,7 @@
|
|
218
291
|
this.submit = function () {
|
219
292
|
_this.validateFields().then(function (result) {
|
220
293
|
var onSubmit = _this._callbacks.onSubmit;
|
221
|
-
onSubmit == null ? void 0 : onSubmit(_this.
|
294
|
+
onSubmit == null ? void 0 : onSubmit(_this.getFieldsValue(), result);
|
222
295
|
}).catch(function (e) {
|
223
296
|
var onSubmitFailed = _this._callbacks.onSubmitFailed;
|
224
297
|
|
@@ -226,7 +299,7 @@
|
|
226
299
|
return;
|
227
300
|
}
|
228
301
|
|
229
|
-
onSubmitFailed(_this.
|
302
|
+
onSubmitFailed(_this.getFieldsValue(), e);
|
230
303
|
});
|
231
304
|
};
|
232
305
|
|
@@ -255,7 +328,11 @@
|
|
255
328
|
return {
|
256
329
|
registerField: _this.registerField,
|
257
330
|
setInitialValues: _this.setInitialValues,
|
258
|
-
setCallbacks: _this.setCallbacks
|
331
|
+
setCallbacks: _this.setCallbacks,
|
332
|
+
getInitialValue: _this.getInitialValue,
|
333
|
+
setInitialValue: _this.setInitialValue,
|
334
|
+
innerSetFieldsValue: _this.innerSetFieldsValue,
|
335
|
+
innerSetFieldValue: _this.innerSetFieldValue
|
259
336
|
};
|
260
337
|
};
|
261
338
|
};
|
package/umd/form/utils.d.ts
CHANGED
@@ -5,3 +5,5 @@ export declare const getErrorAndWarnings: (result: ValidatorError[]) => {
|
|
5
5
|
errors: string[];
|
6
6
|
errorTypes: string[];
|
7
7
|
};
|
8
|
+
export declare const getDefaultValueForInterComponent: (componentType: string) => 0 | never[] | null | undefined;
|
9
|
+
export declare function deepClone(value: any): any;
|
package/umd/form/utils.js
CHANGED
@@ -1,20 +1,24 @@
|
|
1
1
|
(function (global, factory) {
|
2
2
|
if (typeof define === "function" && define.amd) {
|
3
|
-
define(["exports"], factory);
|
3
|
+
define(["exports", "@arco-design/mobile-utils", "lodash/cloneDeepWith", "./type"], factory);
|
4
4
|
} else if (typeof exports !== "undefined") {
|
5
|
-
factory(exports);
|
5
|
+
factory(exports, require("@arco-design/mobile-utils"), require("lodash/cloneDeepWith"), require("./type"));
|
6
6
|
} else {
|
7
7
|
var mod = {
|
8
8
|
exports: {}
|
9
9
|
};
|
10
|
-
factory(mod.exports);
|
10
|
+
factory(mod.exports, global.mobileUtils, global.cloneDeepWith, global.type);
|
11
11
|
global.utils = mod.exports;
|
12
12
|
}
|
13
|
-
})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports) {
|
13
|
+
})(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _mobileUtils, _cloneDeepWith, _type) {
|
14
14
|
"use strict";
|
15
15
|
|
16
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
17
|
+
|
16
18
|
_exports.__esModule = true;
|
17
|
-
_exports.
|
19
|
+
_exports.deepClone = deepClone;
|
20
|
+
_exports.isFieldRequired = _exports.getErrorAndWarnings = _exports.getDefaultValueForInterComponent = void 0;
|
21
|
+
_cloneDeepWith = _interopRequireDefault(_cloneDeepWith);
|
18
22
|
|
19
23
|
var isFieldRequired = function isFieldRequired(rules) {
|
20
24
|
if (rules === void 0) {
|
@@ -58,4 +62,35 @@
|
|
58
62
|
};
|
59
63
|
|
60
64
|
_exports.getErrorAndWarnings = getErrorAndWarnings;
|
65
|
+
|
66
|
+
var getDefaultValueForInterComponent = function getDefaultValueForInterComponent(componentType) {
|
67
|
+
switch (componentType) {
|
68
|
+
case _type.FormInternalComponentType.Input:
|
69
|
+
case _type.FormInternalComponentType.Textarea:
|
70
|
+
return undefined;
|
71
|
+
|
72
|
+
case _type.FormInternalComponentType.CheckboxGroup:
|
73
|
+
return [];
|
74
|
+
|
75
|
+
case _type.FormInternalComponentType.RadioGroup:
|
76
|
+
return null;
|
77
|
+
|
78
|
+
case _type.FormInternalComponentType.Slider:
|
79
|
+
case _type.FormInternalComponentType.Rate:
|
80
|
+
return 0;
|
81
|
+
|
82
|
+
default:
|
83
|
+
return undefined;
|
84
|
+
}
|
85
|
+
};
|
86
|
+
|
87
|
+
_exports.getDefaultValueForInterComponent = getDefaultValueForInterComponent;
|
88
|
+
|
89
|
+
function deepClone(value) {
|
90
|
+
return (0, _cloneDeepWith.default)(value, function (val) {
|
91
|
+
if (!(0, _mobileUtils.isObject)(val) && !(0, _mobileUtils.isArray)(val)) {
|
92
|
+
return val;
|
93
|
+
}
|
94
|
+
});
|
95
|
+
}
|
61
96
|
});
|
package/umd/input/index.js
CHANGED
@@ -65,7 +65,7 @@
|
|
65
65
|
function renderInput(_ref) {
|
66
66
|
var prefixCls = _ref.prefixCls;
|
67
67
|
var prefix = prefixCls + "-input";
|
68
|
-
return renderWrapper(prefix, type, /*#__PURE__*/_react.default.createElement("input", (0, _extends2.default)({}, nativeProps, {
|
68
|
+
return renderWrapper(prefix, type + " single-line", /*#__PURE__*/_react.default.createElement("input", (0, _extends2.default)({}, nativeProps, {
|
69
69
|
id: id,
|
70
70
|
name: name,
|
71
71
|
maxLength: maxLength,
|
@@ -239,20 +239,38 @@
|
|
239
239
|
|
240
240
|
|
241
241
|
if (verticalAuto) {
|
242
|
-
var
|
243
|
-
var popoverBottom = childRect.top + (newConfig.top && newConfig.height ? newConfig.top + newConfig.height : 0); // 顶部安全距离不够,调整到底部
|
244
|
-
// @en The top safety distance is not enough, adjust to the bottom
|
245
|
-
|
246
|
-
if (directionState.indexOf('top') !== -1 && popoverTop < topOffset) {
|
242
|
+
var setToBottom = function setToBottom() {
|
247
243
|
newConfig.top = verticalOffset + childRect.height;
|
248
244
|
newConfig.bottom = null;
|
249
245
|
onAdjustDirection('bottom');
|
250
|
-
}
|
251
|
-
|
252
|
-
|
246
|
+
};
|
247
|
+
|
248
|
+
var setToTop = function setToTop() {
|
253
249
|
newConfig.top = null;
|
254
250
|
newConfig.bottom = verticalOffset + childRect.height;
|
255
251
|
onAdjustDirection('top');
|
252
|
+
}; // 判断上下空间是否都不足以展示气泡内容
|
253
|
+
// @en Determine whether there is insufficient space both above and below to display content
|
254
|
+
|
255
|
+
|
256
|
+
var isPopoverTooTall = window.innerHeight - topOffset - bottomOffset < 2 * (newConfig.height || 0) + 2 * verticalOffset + childRect.height;
|
257
|
+
|
258
|
+
if (isPopoverTooTall) {
|
259
|
+
var spaceAbove = childRect.top;
|
260
|
+
var spaceBelow = window.innerHeight - childRect.bottom;
|
261
|
+
spaceAbove > spaceBelow ? setToTop() : setToBottom();
|
262
|
+
} else {
|
263
|
+
var popoverTop = childRect.bottom - (newConfig.bottom && newConfig.height ? newConfig.bottom + newConfig.height : 0);
|
264
|
+
var popoverBottom = childRect.top + (newConfig.top && newConfig.height ? newConfig.top + newConfig.height : 0); // 顶部安全距离不够,调整到底部
|
265
|
+
// @en The top safety distance is not enough, adjust to the bottom
|
266
|
+
|
267
|
+
if (directionState.indexOf('top') !== -1 && popoverTop < topOffset) {
|
268
|
+
setToBottom();
|
269
|
+
} else if ( // 底部安全距离不够,调整到顶部
|
270
|
+
// @en The bottom safety distance is not enough, adjust to the top
|
271
|
+
directionState.indexOf('bottom') !== -1 && popoverBottom + bottomOffset > window.innerHeight) {
|
272
|
+
setToTop();
|
273
|
+
}
|
256
274
|
}
|
257
275
|
} // 挂载在全局的气泡需要计算相对屏幕的位置
|
258
276
|
// @en Bubble mounted in the global needs to calculate the position relative to the screen
|
package/umd/radio/group.js
CHANGED
@@ -97,7 +97,7 @@
|
|
97
97
|
layout: layout,
|
98
98
|
disabled: disabled,
|
99
99
|
icons: icons,
|
100
|
-
value: groupValue === void 0 ? [] : [groupValue],
|
100
|
+
value: groupValue === void 0 || groupValue === null ? [] : [groupValue],
|
101
101
|
onChange: handleChange
|
102
102
|
}
|
103
103
|
}, children, !children && options && options.map(function (option) {
|
package/umd/radio/type.d.ts
CHANGED
@@ -8,10 +8,10 @@ export interface RadioGroupProps<T extends ValueType = ValueType, P extends Radi
|
|
8
8
|
*/
|
9
9
|
options?: P[];
|
10
10
|
/**
|
11
|
-
*
|
11
|
+
* 受控模式,选中的选项,传null表示取消选中
|
12
12
|
* @en Checked option, controlled mode
|
13
13
|
*/
|
14
|
-
value?: T;
|
14
|
+
value?: T | null;
|
15
15
|
/**
|
16
16
|
* 默认选中项
|
17
17
|
* @en Default checked value
|