@arco-design/mobile-react 2.31.1 → 2.31.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.
- package/CHANGELOG.md +22 -0
- package/README.en-US.md +3 -3
- package/README.md +3 -3
- package/cjs/date-picker/index.js +7 -7
- package/cjs/date-picker/type.d.ts +7 -1
- package/cjs/form/form-item.d.ts +0 -3
- package/cjs/form/form-item.js +19 -30
- package/cjs/form/index.js +6 -2
- package/cjs/form/linked-container.d.ts +8 -0
- package/cjs/form/linked-container.js +72 -0
- package/cjs/form/style/index.less +3 -3
- package/cjs/form/type.d.ts +7 -11
- package/cjs/form/useForm.js +36 -48
- package/cjs/picker/index.js +1 -1
- package/dist/index.js +1824 -1827
- package/dist/index.min.js +4 -4
- package/esm/date-picker/index.js +8 -8
- package/esm/date-picker/type.d.ts +7 -1
- package/esm/form/form-item.d.ts +0 -3
- package/esm/form/form-item.js +14 -25
- package/esm/form/index.js +7 -3
- package/esm/form/linked-container.d.ts +8 -0
- package/esm/form/linked-container.js +54 -0
- package/esm/form/style/index.less +3 -3
- package/esm/form/type.d.ts +7 -11
- package/esm/form/useForm.js +31 -42
- package/esm/picker/index.js +1 -1
- package/package.json +4 -3
- package/umd/date-picker/index.js +7 -7
- package/umd/date-picker/type.d.ts +7 -1
- package/umd/form/form-item.d.ts +0 -3
- package/umd/form/form-item.js +19 -34
- package/umd/form/index.js +6 -2
- package/umd/form/linked-container.d.ts +8 -0
- package/umd/form/linked-container.js +78 -0
- package/umd/form/style/index.less +3 -3
- package/umd/form/type.d.ts +7 -11
- package/umd/form/useForm.js +38 -50
- package/umd/picker/index.js +1 -1
package/CHANGELOG.md
CHANGED
@@ -3,6 +3,28 @@
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
5
5
|
|
6
|
+
## [2.31.3](https://github.com/arco-design/arco-design-mobile/compare/@arco-design/mobile-react@2.31.2...@arco-design/mobile-react@2.31.3) (2024-05-11)
|
7
|
+
|
8
|
+
|
9
|
+
### Bug Fixes
|
10
|
+
|
11
|
+
* `Form` optimize "initialValues" and picker form item logic & add `DatePicker` default linked container ([#261](https://github.com/arco-design/arco-design-mobile/issues/261)) ([790ba3a](https://github.com/arco-design/arco-design-mobile/commit/790ba3a9dc4b289a20ddd18b5c11e2855bc6a8bd))
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
## [2.31.2](https://github.com/arco-design/arco-design-mobile/compare/@arco-design/mobile-react@2.31.1...@arco-design/mobile-react@2.31.2) (2024-04-19)
|
18
|
+
|
19
|
+
|
20
|
+
### Bug Fixes
|
21
|
+
|
22
|
+
* add "@babel/runtime" to dependencies ([#257](https://github.com/arco-design/arco-design-mobile/issues/257)) ([c3f0f6c](https://github.com/arco-design/arco-design-mobile/commit/c3f0f6cf281b146c75f14622f1e454f165af4c01))
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
|
6
28
|
## [2.31.1](https://github.com/arco-design/arco-design-mobile/compare/@arco-design/mobile-react@2.31.0...@arco-design/mobile-react@2.31.1) (2024-04-18)
|
7
29
|
|
8
30
|
|
package/README.en-US.md
CHANGED
@@ -59,8 +59,8 @@ React & ReactDOM: **<a href="https://reactjs.org/docs/cdn-links.html" target="_b
|
|
59
59
|
React Transition Group: **<a href="https://reactcommunity.org/react-transition-group/" target="_blank">Click here</a>**
|
60
60
|
|
61
61
|
```
|
62
|
-
<link ref="stylesheet" href="https://unpkg.com/@arco-design/mobile-react@2.31.
|
63
|
-
<script src="https://unpkg.com/@arco-design/mobile-react@2.31.
|
62
|
+
<link ref="stylesheet" href="https://unpkg.com/@arco-design/mobile-react@2.31.2/dist/style.min.css">
|
63
|
+
<script src="https://unpkg.com/@arco-design/mobile-react@2.31.2/dist/index.min.js"></script>
|
64
64
|
```
|
65
65
|
|
66
66
|
## Full import
|
@@ -247,7 +247,7 @@ lessOptions: {
|
|
247
247
|
|
248
248
|
## Using components on PC
|
249
249
|
|
250
|
-
Only touch-related events are monitored and processed in the component. If you need to use the component on the PC side, you can import `touch2mouse.js` provided by this component library to be compatible with mouse event processing:
|
250
|
+
Only touch-related events are monitored and processed in the component. If you need to use the component on the PC side, you can import `touch2mouse.js` provided by this component library to be compatible with mouse event processing (Note: After importing this file, the following mouse events will be blocked: mousedown, mouseenter, mouseleave, mousemove, mouseout, mouseover and mouseup, and the page content cannot be selected):
|
251
251
|
|
252
252
|
```js
|
253
253
|
import '@arco-design/mobile-react/tools/touch2mouse';
|
package/README.md
CHANGED
@@ -59,8 +59,8 @@ React & ReactDOM: **<a href="https://reactjs.org/docs/cdn-links.html" target="
|
|
59
59
|
React Transition Group: **<a href="https://reactcommunity.org/react-transition-group/" target="_blank">戳这里获取</a>**
|
60
60
|
|
61
61
|
```
|
62
|
-
<link ref="stylesheet" href="https://unpkg.com/@arco-design/mobile-react@2.31.
|
63
|
-
<script src="https://unpkg.com/@arco-design/mobile-react@2.31.
|
62
|
+
<link ref="stylesheet" href="https://unpkg.com/@arco-design/mobile-react@2.31.2/dist/style.min.css">
|
63
|
+
<script src="https://unpkg.com/@arco-design/mobile-react@2.31.2/dist/index.min.js"></script>
|
64
64
|
```
|
65
65
|
|
66
66
|
## 引入全部
|
@@ -245,7 +245,7 @@ lessOptions: {
|
|
245
245
|
|
246
246
|
## 在 PC 端使用组件
|
247
247
|
|
248
|
-
组件中仅监听及处理 touch 相关事件,如需在 PC 端使用组件,可引入本组件库提供的 touch2mouse.js 以兼容 mouse
|
248
|
+
组件中仅监听及处理 touch 相关事件,如需在 PC 端使用组件,可引入本组件库提供的 touch2mouse.js 以兼容 mouse 事件处理(注意:引入该文件后将阻止如下鼠标事件:mousedown、mouseenter、mouseleave、mousemove、mouseout、mouseover和mouseup,页面内容无法被选中):
|
249
249
|
|
250
250
|
```js
|
251
251
|
import '@arco-design/mobile-react/tools/touch2mouse';
|
package/cjs/date-picker/index.js
CHANGED
@@ -30,18 +30,14 @@ Object.keys(_type).forEach(function (key) {
|
|
30
30
|
if (key in exports && exports[key] === _type[key]) return;
|
31
31
|
exports[key] = _type[key];
|
32
32
|
});
|
33
|
-
var _excluded = ["currentTs", "className", "visible", "onOk", "onChange", "onValueChange", "mode", "typeArr", "minTs", "maxTs", "formatter", "valueFilter", "columnsProcessor", "touchToStop", "useUTC"];
|
33
|
+
var _excluded = ["currentTs", "className", "visible", "onOk", "onChange", "onValueChange", "mode", "typeArr", "minTs", "maxTs", "formatter", "valueFilter", "columnsProcessor", "touchToStop", "useUTC", "renderLinkedContainer"];
|
34
34
|
|
35
35
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
36
36
|
|
37
37
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
38
38
|
|
39
39
|
var allTypes = ['year', 'month', 'date', 'hour', 'minute', 'second'];
|
40
|
-
|
41
|
-
var defaultFormatter = function defaultFormatter(value) {
|
42
|
-
return value < 10 ? "0" + value : String(value);
|
43
|
-
};
|
44
|
-
|
40
|
+
var defaultFormatter = _mobileUtils.formatDateNumber;
|
45
41
|
var YEAR = 12 * 30 * 24 * 60 * 60 * 1000;
|
46
42
|
exports.YEAR = YEAR;
|
47
43
|
var initMinDate = Date.now() - 10 * YEAR;
|
@@ -75,6 +71,7 @@ var DatePicker = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
75
71
|
touchToStop = props.touchToStop,
|
76
72
|
_props$useUTC = props.useUTC,
|
77
73
|
useUTC = _props$useUTC === void 0 ? false : _props$useUTC,
|
74
|
+
renderLinkedContainer = props.renderLinkedContainer,
|
78
75
|
otherProps = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
|
79
76
|
var currentTs = Math.min(maxTs, Math.max(minTs, userSetCurrentTs));
|
80
77
|
|
@@ -346,7 +343,10 @@ var DatePicker = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
346
343
|
value: value,
|
347
344
|
onPickerChange: _handlePickerChange,
|
348
345
|
onOk: _handlePickerConfirm,
|
349
|
-
touchToStop: touchToStop
|
346
|
+
touchToStop: touchToStop,
|
347
|
+
renderLinkedContainer: renderLinkedContainer ? function () {
|
348
|
+
return renderLinkedContainer(currentTs, keyOptions);
|
349
|
+
} : undefined
|
350
350
|
}));
|
351
351
|
});
|
352
352
|
});
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import { ReactNode } from 'react';
|
1
2
|
import { PickerProps } from '../picker';
|
2
3
|
import { PickerData } from '../picker-view';
|
3
4
|
export declare type ItemType = 'year' | 'month' | 'date' | 'hour' | 'minute' | 'second';
|
@@ -34,7 +35,7 @@ export interface IDateObj {
|
|
34
35
|
second: number;
|
35
36
|
}
|
36
37
|
export declare type mode = 'date' | 'time' | 'datetime';
|
37
|
-
export interface DatePickerProps extends Omit<PickerProps, 'data' | 'cascade' | 'cols' | 'value' | 'onChange' | 'onPickerChange' | 'onOk'> {
|
38
|
+
export interface DatePickerProps extends Omit<PickerProps, 'data' | 'cascade' | 'cols' | 'value' | 'onChange' | 'onPickerChange' | 'onOk' | 'renderLinkedContainer'> {
|
38
39
|
/**
|
39
40
|
* 点击选中时执行的回调
|
40
41
|
* @en Callback when clicking OK
|
@@ -105,4 +106,9 @@ export interface DatePickerProps extends Omit<PickerProps, 'data' | 'cascade' |
|
|
105
106
|
* @en Selector list item intervention to insert custom options.
|
106
107
|
*/
|
107
108
|
columnsProcessor?: (columns: PickerData[][], currentDateObj: IDateObj) => PickerData[][];
|
109
|
+
/**
|
110
|
+
* 将选择器的展现隐藏状态及选中值的展示与某个容器关联,传入后将同时渲染该容器和选择器组件,此时选择器组件的 visible 和 onHide 属性可不传,点击该容器会唤起选择器
|
111
|
+
* @en Associate the hidden state of the picker and the display of the selected value with a container. After passing it in, the container and the picker component will be rendered at the same time. At this time, the visible and onHide attributes of the picker component are optional values. Clicking the container will evoke the picker
|
112
|
+
*/
|
113
|
+
renderLinkedContainer?: (currentTs: number, itemTypes: ItemType[]) => ReactNode;
|
108
114
|
}
|
package/cjs/form/form-item.d.ts
CHANGED
@@ -1,7 +1,4 @@
|
|
1
1
|
import React from 'react';
|
2
2
|
import { FormItemProps, FormItemRef } from './type';
|
3
|
-
export declare function DefaultPickerLinkedContainer({ value }: {
|
4
|
-
value: (string | number)[];
|
5
|
-
}): JSX.Element;
|
6
3
|
declare const _default: React.ForwardRefExoticComponent<FormItemProps & React.RefAttributes<FormItemRef>>;
|
7
4
|
export default _default;
|
package/cjs/form/form-item.js
CHANGED
@@ -3,7 +3,6 @@
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
4
|
|
5
5
|
exports.__esModule = true;
|
6
|
-
exports.DefaultPickerLinkedContainer = DefaultPickerLinkedContainer;
|
7
6
|
exports.default = void 0;
|
8
7
|
|
9
8
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
@@ -16,6 +15,8 @@ var _react = _interopRequireWildcard(require("react"));
|
|
16
15
|
|
17
16
|
var _mobileUtils = require("@arco-design/mobile-utils");
|
18
17
|
|
18
|
+
var _es6Promise = require("es6-promise");
|
19
|
+
|
19
20
|
var _formItemContext = require("./form-item-context");
|
20
21
|
|
21
22
|
var _contextProvider = require("../context-provider");
|
@@ -24,27 +25,14 @@ var _type = require("./type");
|
|
24
25
|
|
25
26
|
var _utils = require("./utils");
|
26
27
|
|
28
|
+
var _linkedContainer = require("./linked-container");
|
29
|
+
|
27
30
|
var _excluded = ["label", "field", "disabled", "layout", "style", "extra", "requiredIcon", "rules", "className"];
|
28
31
|
|
29
32
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
30
33
|
|
31
34
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
32
35
|
|
33
|
-
function DefaultPickerLinkedContainer(_ref) {
|
34
|
-
var value = _ref.value;
|
35
|
-
|
36
|
-
var _useContext = (0, _react.useContext)(_contextProvider.GlobalContext),
|
37
|
-
prefixCls = _useContext.prefixCls,
|
38
|
-
locale = _useContext.locale;
|
39
|
-
|
40
|
-
var className = prefixCls + "-form-picker-link-container";
|
41
|
-
return /*#__PURE__*/_react.default.createElement("div", {
|
42
|
-
className: className
|
43
|
-
}, value && value.length ? value.join('-') : /*#__PURE__*/_react.default.createElement("span", {
|
44
|
-
className: className + "-placeholder"
|
45
|
-
}, locale == null ? void 0 : locale.Form.pickerDefaultHint));
|
46
|
-
}
|
47
|
-
|
48
36
|
var FormItemInner = /*#__PURE__*/function (_PureComponent) {
|
49
37
|
(0, _inheritsLoose2.default)(FormItemInner, _PureComponent);
|
50
38
|
|
@@ -58,14 +46,14 @@ var FormItemInner = /*#__PURE__*/function (_PureComponent) {
|
|
58
46
|
_this._errors = [];
|
59
47
|
_this._touched = false;
|
60
48
|
|
61
|
-
_this.onValueChange = function (
|
49
|
+
_this.onValueChange = function (curValue, preValue) {
|
62
50
|
_this._touched = true;
|
63
51
|
var shouldUpdate = _this.props.shouldUpdate;
|
64
52
|
|
65
53
|
if (typeof shouldUpdate === 'function') {
|
66
54
|
shouldUpdate({
|
67
|
-
|
68
|
-
|
55
|
+
preValue: preValue,
|
56
|
+
curValue: curValue
|
69
57
|
}) && _this.forceUpdate();
|
70
58
|
return;
|
71
59
|
}
|
@@ -98,7 +86,7 @@ var FormItemInner = /*#__PURE__*/function (_PureComponent) {
|
|
98
86
|
var fieldValidator = new _mobileUtils.Validator((_Validator = {}, _Validator[field] = rules, _Validator), {
|
99
87
|
validateMessages: validateMessages
|
100
88
|
});
|
101
|
-
return new Promise(function (resolve) {
|
89
|
+
return new _es6Promise.Promise(function (resolve) {
|
102
90
|
var _fieldValidator$valid;
|
103
91
|
|
104
92
|
fieldValidator.validate((_fieldValidator$valid = {}, _fieldValidator$valid[field] = value, _fieldValidator$valid), function (errorsMap) {
|
@@ -124,7 +112,7 @@ var FormItemInner = /*#__PURE__*/function (_PureComponent) {
|
|
124
112
|
});
|
125
113
|
}
|
126
114
|
|
127
|
-
return Promise.resolve({
|
115
|
+
return _es6Promise.Promise.resolve({
|
128
116
|
errors: [],
|
129
117
|
warnings: [],
|
130
118
|
value: value,
|
@@ -275,9 +263,10 @@ var FormItemInner = /*#__PURE__*/function (_PureComponent) {
|
|
275
263
|
currentTs: getFieldValue(field),
|
276
264
|
onChange: this.innerTriggerFunctionWithValueFirst,
|
277
265
|
disabled: this.props.disabled,
|
278
|
-
renderLinkedContainer: ((_children$props7 = children.props) == null ? void 0 : _children$props7.renderLinkedContainer) || function (
|
279
|
-
return /*#__PURE__*/_react.default.createElement(
|
280
|
-
|
266
|
+
renderLinkedContainer: ((_children$props7 = children.props) == null ? void 0 : _children$props7.renderLinkedContainer) || function (ts, types) {
|
267
|
+
return /*#__PURE__*/_react.default.createElement(_linkedContainer.DefaultDatePickerLinkedContainer, {
|
268
|
+
ts: ts,
|
269
|
+
types: types
|
281
270
|
});
|
282
271
|
}
|
283
272
|
};
|
@@ -289,7 +278,7 @@ var FormItemInner = /*#__PURE__*/function (_PureComponent) {
|
|
289
278
|
onChange: this.innerTriggerFunctionWithValueFirst,
|
290
279
|
disabled: this.props.disabled,
|
291
280
|
renderLinkedContainer: ((_children$props8 = children.props) == null ? void 0 : _children$props8.renderLinkedContainer) || function (val) {
|
292
|
-
return /*#__PURE__*/_react.default.createElement(DefaultPickerLinkedContainer, {
|
281
|
+
return /*#__PURE__*/_react.default.createElement(_linkedContainer.DefaultPickerLinkedContainer, {
|
293
282
|
value: val
|
294
283
|
});
|
295
284
|
}
|
@@ -357,12 +346,12 @@ var _default = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
357
346
|
className = _props$className === void 0 ? '' : _props$className,
|
358
347
|
rest = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
|
359
348
|
|
360
|
-
var
|
361
|
-
prefixCls =
|
349
|
+
var _useContext = (0, _react.useContext)(_contextProvider.GlobalContext),
|
350
|
+
prefixCls = _useContext.prefixCls;
|
362
351
|
|
363
|
-
var
|
364
|
-
layout =
|
365
|
-
propsDisabled =
|
352
|
+
var _useContext2 = (0, _react.useContext)(_formItemContext.FormItemContext),
|
353
|
+
layout = _useContext2.layout,
|
354
|
+
propsDisabled = _useContext2.disabled;
|
366
355
|
|
367
356
|
var _useState = (0, _react.useState)(null),
|
368
357
|
errors = _useState[0],
|
package/cjs/form/index.js
CHANGED
@@ -51,6 +51,7 @@ var Form = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
51
51
|
onSubmitFailed = props.onSubmitFailed,
|
52
52
|
disabled = props.disabled;
|
53
53
|
var domRef = (0, _react.useRef)(null);
|
54
|
+
var initRef = (0, _react.useRef)(false);
|
54
55
|
|
55
56
|
var _useForm = (0, _useForm2.default)(formInstance),
|
56
57
|
form = _useForm[0];
|
@@ -64,9 +65,12 @@ var Form = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
64
65
|
onSubmit: onSubmit,
|
65
66
|
onSubmitFailed: onSubmitFailed
|
66
67
|
});
|
67
|
-
|
68
|
+
|
69
|
+
if (!initRef.current) {
|
68
70
|
setInitialValues(initialValues || {});
|
69
|
-
|
71
|
+
initRef.current = true;
|
72
|
+
}
|
73
|
+
|
70
74
|
(0, _react.useImperativeHandle)(ref, function () {
|
71
75
|
return {
|
72
76
|
dom: domRef.current,
|
@@ -0,0 +1,8 @@
|
|
1
|
+
/// <reference types="react" />
|
2
|
+
export declare function DefaultPickerLinkedContainer({ value }: {
|
3
|
+
value: (string | number)[];
|
4
|
+
}): JSX.Element;
|
5
|
+
export declare function DefaultDatePickerLinkedContainer({ ts, types }: {
|
6
|
+
ts: number;
|
7
|
+
types: string[];
|
8
|
+
}): JSX.Element;
|
@@ -0,0 +1,72 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
+
|
5
|
+
exports.__esModule = true;
|
6
|
+
exports.DefaultDatePickerLinkedContainer = DefaultDatePickerLinkedContainer;
|
7
|
+
exports.DefaultPickerLinkedContainer = DefaultPickerLinkedContainer;
|
8
|
+
|
9
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
10
|
+
|
11
|
+
var _react = _interopRequireWildcard(require("react"));
|
12
|
+
|
13
|
+
var _mobileUtils = require("@arco-design/mobile-utils");
|
14
|
+
|
15
|
+
var _helper = require("../date-picker/helper");
|
16
|
+
|
17
|
+
var _contextProvider = require("../context-provider");
|
18
|
+
|
19
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
20
|
+
|
21
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
22
|
+
|
23
|
+
function DefaultPickerLinkedContainer(_ref) {
|
24
|
+
var value = _ref.value;
|
25
|
+
|
26
|
+
var _useContext = (0, _react.useContext)(_contextProvider.GlobalContext),
|
27
|
+
prefixCls = _useContext.prefixCls,
|
28
|
+
locale = _useContext.locale;
|
29
|
+
|
30
|
+
var className = prefixCls + "-form-picker-link-container";
|
31
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
32
|
+
className: className
|
33
|
+
}, value && value.length ? value.join('-') : /*#__PURE__*/_react.default.createElement("span", {
|
34
|
+
className: className + "-placeholder"
|
35
|
+
}, locale == null ? void 0 : locale.Form.pickerDefaultHint));
|
36
|
+
}
|
37
|
+
|
38
|
+
function DefaultDatePickerLinkedContainer(_ref2) {
|
39
|
+
var ts = _ref2.ts,
|
40
|
+
types = _ref2.types;
|
41
|
+
|
42
|
+
var _useContext2 = (0, _react.useContext)(_contextProvider.GlobalContext),
|
43
|
+
prefixCls = _useContext2.prefixCls,
|
44
|
+
locale = _useContext2.locale;
|
45
|
+
|
46
|
+
var className = prefixCls + "-form-picker-link-container";
|
47
|
+
var dateTimeStr = (0, _react.useMemo)(function () {
|
48
|
+
return formatDateTimeStr(ts, types);
|
49
|
+
}, [ts, types]);
|
50
|
+
|
51
|
+
function formatDateTimeStr(timestamp, itemTypes) {
|
52
|
+
var dateObj = (0, _helper.convertTsToDateObj)(timestamp);
|
53
|
+
var validDateObj = Object.keys(dateObj).reduce(function (acc, key) {
|
54
|
+
var _ref3;
|
55
|
+
|
56
|
+
return (0, _extends2.default)({}, acc, itemTypes.includes(key) ? (_ref3 = {}, _ref3[key] = (0, _mobileUtils.formatDateNumber)(dateObj[key]), _ref3) : {});
|
57
|
+
}, {});
|
58
|
+
var dateStr = [validDateObj.year, validDateObj.month, validDateObj.date].filter(function (v) {
|
59
|
+
return v;
|
60
|
+
}).join('-');
|
61
|
+
var timeStr = [validDateObj.hour, validDateObj.minute, validDateObj.second].filter(function (v) {
|
62
|
+
return v;
|
63
|
+
}).join(':');
|
64
|
+
return dateStr + " " + timeStr;
|
65
|
+
}
|
66
|
+
|
67
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
68
|
+
className: className
|
69
|
+
}, ts ? dateTimeStr : /*#__PURE__*/_react.default.createElement("span", {
|
70
|
+
className: className + "-placeholder"
|
71
|
+
}, locale == null ? void 0 : locale.Form.pickerDefaultHint));
|
72
|
+
}
|
@@ -39,14 +39,14 @@
|
|
39
39
|
}
|
40
40
|
&-item-control {
|
41
41
|
padding: 16px 0;
|
42
|
-
|
42
|
+
.@{prefix}-input-wrap, .@{prefix}-input {
|
43
43
|
padding: 0;
|
44
44
|
}
|
45
45
|
&-wrapper {
|
46
46
|
width: 100%;
|
47
47
|
flex: 1;
|
48
48
|
position: relative;
|
49
|
-
|
49
|
+
.@{prefix}-input-wrap {
|
50
50
|
.use-var(height, input-text-line-height);
|
51
51
|
}
|
52
52
|
}
|
@@ -75,7 +75,7 @@
|
|
75
75
|
|
76
76
|
&-item.@{prefix}-form-item-vertical {
|
77
77
|
display: block;
|
78
|
-
|
78
|
+
.@{prefix}-input-wrap {
|
79
79
|
.set-prop-with-rtl(padding-left, 0);
|
80
80
|
}
|
81
81
|
.@{prefix}-form-label-item {
|
package/cjs/form/type.d.ts
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
import { IRules } from '@arco-design/mobile-utils';
|
2
2
|
import { ReactNode } from 'react';
|
3
|
+
import { Promise } from 'es6-promise';
|
3
4
|
export declare type FieldValue = any;
|
4
5
|
export declare type FieldItem = Record<string, any>;
|
5
6
|
export declare type ILayout = 'horizontal' | 'vertical' | 'inline';
|
@@ -169,19 +170,14 @@ export interface IFormInstance {
|
|
169
170
|
* 校验所有表单项
|
170
171
|
* @en Validate all fields
|
171
172
|
*/
|
172
|
-
validateFields: () => Promise<
|
173
|
+
validateFields: () => Promise<IFieldError[]>;
|
173
174
|
/**
|
174
175
|
* 提交表单
|
175
176
|
* @en Submit all fields
|
176
177
|
*/
|
177
178
|
submit: () => void;
|
178
179
|
}
|
179
|
-
export declare type InternalFormInstance =
|
180
|
-
/**
|
181
|
-
* 校验所有表单项
|
182
|
-
* @en Validate all fields
|
183
|
-
*/
|
184
|
-
validateFields: () => Promise<FieldItem>;
|
180
|
+
export declare type InternalFormInstance = IFormInstance & {
|
185
181
|
/**
|
186
182
|
* 获取内部方法
|
187
183
|
* @en Get internal methods
|
@@ -223,8 +219,8 @@ export interface IFormItemContext {
|
|
223
219
|
validateMessages?: Record<string, unknown>;
|
224
220
|
}
|
225
221
|
export declare type IShouldUpdateFunc = (data: {
|
226
|
-
|
227
|
-
|
222
|
+
preValue: any;
|
223
|
+
curValue: any;
|
228
224
|
}) => boolean;
|
229
225
|
export interface FormItemProps {
|
230
226
|
/**
|
@@ -272,7 +268,7 @@ export interface FormItemProps {
|
|
272
268
|
* 表单项是否刷新
|
273
269
|
* @en Form item is updated
|
274
270
|
*/
|
275
|
-
shouldUpdate?:
|
271
|
+
shouldUpdate?: IShouldUpdateFunc;
|
276
272
|
/**
|
277
273
|
* 表单项规则
|
278
274
|
* @en Form item rules
|
@@ -327,7 +323,7 @@ export interface IFormItemInnerProps {
|
|
327
323
|
* 表单项是否刷新
|
328
324
|
* @en Form item is updated
|
329
325
|
*/
|
330
|
-
shouldUpdate?:
|
326
|
+
shouldUpdate?: IShouldUpdateFunc;
|
331
327
|
/**
|
332
328
|
* 表单项下方节点
|
333
329
|
* @en Form item extra node
|
package/cjs/form/useForm.js
CHANGED
@@ -6,14 +6,12 @@ exports.__esModule = true;
|
|
6
6
|
exports.default = useForm;
|
7
7
|
exports.defaultFormDataMethods = void 0;
|
8
8
|
|
9
|
-
var
|
10
|
-
|
11
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
12
|
-
|
13
|
-
var _extends5 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
9
|
+
var _extends6 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
14
10
|
|
15
11
|
var _react = require("react");
|
16
12
|
|
13
|
+
var _es6Promise = require("es6-promise");
|
14
|
+
|
17
15
|
/* eslint-disable no-console */
|
18
16
|
var defaultFunc = function defaultFunc() {};
|
19
17
|
|
@@ -59,40 +57,41 @@ var FormData = function FormData() {
|
|
59
57
|
this._callbacks = {};
|
60
58
|
|
61
59
|
this.setFieldsValue = function (values) {
|
62
|
-
|
60
|
+
var oldValues = Object.keys(values).reduce(function (acc, key) {
|
61
|
+
var _extends2;
|
63
62
|
|
64
|
-
|
63
|
+
return (0, _extends6.default)({}, acc, (_extends2 = {}, _extends2[key] = _this.getFieldValue(key), _extends2));
|
64
|
+
}, {});
|
65
|
+
_this._formData = (0, _extends6.default)({}, _this._formData, values);
|
66
|
+
var onValuesChange = _this._callbacks.onValuesChange;
|
67
|
+
onValuesChange && onValuesChange(values, _this._formData);
|
65
68
|
|
66
|
-
|
67
|
-
if (key in _this._fieldsList) {
|
68
|
-
var _this$_fieldsList$key;
|
69
|
+
_this.notifyField(values, oldValues);
|
69
70
|
|
70
|
-
(_this$_fieldsList$key = _this._fieldsList[key]) == null ? void 0 : _this$_fieldsList$key.onValueChange();
|
71
|
-
}
|
72
|
-
});
|
73
71
|
return true;
|
74
72
|
};
|
75
73
|
|
76
74
|
this.setFieldValue = function (name, value) {
|
77
|
-
var
|
75
|
+
var _oldValues, _extends3, _onValuesChange, _this$notifyField;
|
78
76
|
|
79
|
-
|
77
|
+
var oldValues = (_oldValues = {}, _oldValues[name] = _this.getFieldValue(name), _oldValues);
|
78
|
+
_this._formData = (0, _extends6.default)({}, _this._formData, (_extends3 = {}, _extends3[name] = value, _extends3));
|
80
79
|
var onValuesChange = _this._callbacks.onValuesChange;
|
81
80
|
onValuesChange && onValuesChange((_onValuesChange = {}, _onValuesChange[name] = value, _onValuesChange), _this._formData);
|
82
81
|
|
83
|
-
_this.notifyField((_this$notifyField = {}, _this$notifyField[name] = value, _this$notifyField));
|
82
|
+
_this.notifyField((_this$notifyField = {}, _this$notifyField[name] = value, _this$notifyField), oldValues);
|
84
83
|
|
85
84
|
return true;
|
86
85
|
};
|
87
86
|
|
88
|
-
this.notifyField = function (values) {
|
87
|
+
this.notifyField = function (values, oldValues) {
|
89
88
|
Object.keys(values).map(function (fieldName) {
|
90
89
|
var _this$_fieldsList;
|
91
90
|
|
92
91
|
var fieldObj = ((_this$_fieldsList = _this._fieldsList) == null ? void 0 : _this$_fieldsList[fieldName]) || null;
|
93
92
|
|
94
93
|
if (fieldObj) {
|
95
|
-
fieldObj.onValueChange(values[fieldName]);
|
94
|
+
fieldObj.onValueChange(values[fieldName], oldValues[fieldName]);
|
96
95
|
}
|
97
96
|
});
|
98
97
|
};
|
@@ -157,11 +156,11 @@ var FormData = function FormData() {
|
|
157
156
|
var initialValue = self.props.initialValue;
|
158
157
|
|
159
158
|
if (initialValue !== undefined && name) {
|
160
|
-
var
|
159
|
+
var _extends4, _extends5;
|
161
160
|
|
162
|
-
_this._initialValues = (0,
|
161
|
+
_this._initialValues = (0, _extends6.default)({}, _this._initialValues, (_extends4 = {}, _extends4[name] = initialValue, _extends4));
|
163
162
|
|
164
|
-
_this.setFieldsValue((0,
|
163
|
+
_this.setFieldsValue((0, _extends6.default)({}, _this._formData, (_extends5 = {}, _extends5[name] = initialValue, _extends5)));
|
165
164
|
}
|
166
165
|
|
167
166
|
return function () {
|
@@ -173,7 +172,7 @@ var FormData = function FormData() {
|
|
173
172
|
};
|
174
173
|
|
175
174
|
this.setInitialValues = function (initVal) {
|
176
|
-
_this._initialValues = (0,
|
175
|
+
_this._initialValues = (0, _extends6.default)({}, initVal || {});
|
177
176
|
|
178
177
|
_this.setFieldsValue(initVal);
|
179
178
|
};
|
@@ -190,8 +189,8 @@ var FormData = function FormData() {
|
|
190
189
|
return errors;
|
191
190
|
}));
|
192
191
|
});
|
193
|
-
var summaryPromise = new Promise(function (resolve, reject) {
|
194
|
-
Promise.all(promiseList).then(function (res) {
|
192
|
+
var summaryPromise = new _es6Promise.Promise(function (resolve, reject) {
|
193
|
+
_es6Promise.Promise.all(promiseList).then(function (res) {
|
195
194
|
var errorResults = res.filter(function (item) {
|
196
195
|
var _item$errors;
|
197
196
|
|
@@ -208,31 +207,20 @@ var FormData = function FormData() {
|
|
208
207
|
return summaryPromise;
|
209
208
|
};
|
210
209
|
|
211
|
-
this.submit =
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
var onSubmitFailed = _this._callbacks.onSubmitFailed;
|
221
|
-
|
222
|
-
if (!onSubmitFailed) {
|
223
|
-
return;
|
224
|
-
}
|
225
|
-
|
226
|
-
onSubmitFailed(_this._formData, e);
|
227
|
-
});
|
228
|
-
|
229
|
-
case 1:
|
230
|
-
case "end":
|
231
|
-
return _context.stop();
|
232
|
-
}
|
210
|
+
this.submit = function () {
|
211
|
+
_this.validateFields().then(function (result) {
|
212
|
+
var onSubmit = _this._callbacks.onSubmit;
|
213
|
+
onSubmit == null ? void 0 : onSubmit(_this._formData, result);
|
214
|
+
}).catch(function (e) {
|
215
|
+
var onSubmitFailed = _this._callbacks.onSubmitFailed;
|
216
|
+
|
217
|
+
if (!onSubmitFailed) {
|
218
|
+
return;
|
233
219
|
}
|
234
|
-
|
235
|
-
|
220
|
+
|
221
|
+
onSubmitFailed(_this._formData, e);
|
222
|
+
});
|
223
|
+
};
|
236
224
|
|
237
225
|
this.setCallbacks = function (callbacks) {
|
238
226
|
_this._callbacks = callbacks;
|
package/cjs/picker/index.js
CHANGED
@@ -131,7 +131,7 @@ var Picker = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
131
131
|
(0, _mobileUtils.nextTick)(function () {
|
132
132
|
setLinkArgs(getCurrentValueData());
|
133
133
|
});
|
134
|
-
}, []);
|
134
|
+
}, [value]);
|
135
135
|
|
136
136
|
function hidePicker(scene) {
|
137
137
|
setLinkVisible(false);
|