antd-mobile 5.3.0 → 5.5.0
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/2x/cjs/components/avatar/avatar.js +1 -0
- package/2x/cjs/components/calendar/calendar.js +23 -20
- package/2x/cjs/components/cascader-view/cascader-view.d.ts +1 -0
- package/2x/cjs/components/cascader-view/use-cascader-value-extend.js +23 -0
- package/2x/cjs/components/check-list/check-list-item.js +1 -1
- package/2x/cjs/components/checkbox/checkbox.js +16 -4
- package/2x/cjs/components/floating-bubble/floating-bubble.d.ts +2 -0
- package/2x/cjs/components/floating-bubble/floating-bubble.js +56 -16
- package/2x/cjs/components/form/form-array.d.ts +19 -0
- package/2x/cjs/components/form/form-array.js +52 -0
- package/2x/cjs/components/form/form-item.css +6 -1
- package/2x/cjs/components/form/form-item.js +24 -8
- package/2x/cjs/components/form/form.css +5 -0
- package/2x/cjs/components/form/form.js +17 -6
- package/2x/cjs/components/form/index.css +11 -1
- package/2x/cjs/components/form/index.d.ts +2 -0
- package/2x/cjs/components/form/index.js +3 -0
- package/2x/cjs/components/image-uploader/image-uploader.d.ts +1 -1
- package/2x/cjs/components/image-uploader/image-uploader.js +17 -1
- package/2x/cjs/components/infinite-scroll/infinite-scroll.js +23 -19
- package/2x/cjs/components/modal/modal.js +0 -1
- package/2x/cjs/components/notice-bar/notice-bar.js +1 -1
- package/2x/cjs/components/popover/index.d.ts +7 -2
- package/2x/cjs/components/popover/normalize-placement.d.ts +2 -0
- package/2x/cjs/components/popover/normalize-placement.js +22 -0
- package/2x/cjs/components/popover/popover.css +0 -104
- package/2x/cjs/components/popover/popover.d.ts +11 -5
- package/2x/cjs/components/popover/popover.js +126 -22
- package/2x/cjs/components/popover/wrapper.d.ts +7 -0
- package/2x/cjs/components/popover/wrapper.js +41 -0
- package/2x/cjs/components/pull-to-refresh/pull-to-refresh.js +24 -9
- package/2x/cjs/components/radio/radio.js +16 -4
- package/2x/cjs/components/search-bar/search-bar.js +0 -1
- package/2x/cjs/components/swiper/swiper.js +1 -1
- package/2x/cjs/components/text-area/text-area.css +4 -1
- package/2x/cjs/components/text-area/text-area.d.ts +2 -2
- package/2x/cjs/utils/use-props-value.d.ts +2 -1
- package/2x/cjs/utils/use-props-value.js +4 -2
- package/2x/es/components/avatar/avatar.js +1 -0
- package/2x/es/components/calendar/calendar.js +23 -19
- package/2x/es/components/cascader-view/cascader-view.d.ts +1 -0
- package/2x/es/components/cascader-view/use-cascader-value-extend.js +23 -0
- package/2x/es/components/check-list/check-list-item.js +1 -1
- package/2x/es/components/checkbox/checkbox.js +17 -5
- package/2x/es/components/floating-bubble/floating-bubble.d.ts +2 -0
- package/2x/es/components/floating-bubble/floating-bubble.js +57 -17
- package/2x/es/components/form/form-array.d.ts +19 -0
- package/2x/es/components/form/form-array.js +38 -0
- package/2x/es/components/form/form-item.css +6 -1
- package/2x/es/components/form/form-item.js +22 -8
- package/2x/es/components/form/form.css +5 -0
- package/2x/es/components/form/form.js +16 -6
- package/2x/es/components/form/index.css +11 -1
- package/2x/es/components/form/index.d.ts +2 -0
- package/2x/es/components/form/index.js +2 -0
- package/2x/es/components/image-uploader/image-uploader.d.ts +1 -1
- package/2x/es/components/image-uploader/image-uploader.js +17 -1
- package/2x/es/components/infinite-scroll/infinite-scroll.js +22 -19
- package/2x/es/components/modal/modal.js +0 -1
- package/2x/es/components/notice-bar/notice-bar.js +1 -1
- package/2x/es/components/popover/index.d.ts +7 -2
- package/2x/es/components/popover/normalize-placement.d.ts +2 -0
- package/2x/es/components/popover/normalize-placement.js +15 -0
- package/2x/es/components/popover/popover.css +0 -104
- package/2x/es/components/popover/popover.d.ts +11 -5
- package/2x/es/components/popover/popover.js +118 -22
- package/2x/es/components/popover/wrapper.d.ts +7 -0
- package/2x/es/components/popover/wrapper.js +28 -0
- package/2x/es/components/pull-to-refresh/pull-to-refresh.js +24 -9
- package/2x/es/components/radio/radio.js +17 -5
- package/2x/es/components/search-bar/search-bar.js +0 -1
- package/2x/es/components/swiper/swiper.js +1 -1
- package/2x/es/components/text-area/text-area.css +4 -1
- package/2x/es/components/text-area/text-area.d.ts +2 -2
- package/2x/es/utils/use-props-value.d.ts +2 -1
- package/2x/es/utils/use-props-value.js +4 -2
- package/2x/package.json +2 -2
- package/cjs/components/avatar/avatar.js +1 -0
- package/cjs/components/calendar/calendar.js +23 -20
- package/cjs/components/cascader-view/cascader-view.d.ts +1 -0
- package/cjs/components/cascader-view/use-cascader-value-extend.js +23 -0
- package/cjs/components/check-list/check-list-item.js +1 -1
- package/cjs/components/checkbox/checkbox.js +16 -4
- package/cjs/components/floating-bubble/floating-bubble.d.ts +2 -0
- package/cjs/components/floating-bubble/floating-bubble.js +56 -16
- package/cjs/components/form/form-array.d.ts +19 -0
- package/cjs/components/form/form-array.js +52 -0
- package/cjs/components/form/form-item.css +5 -1
- package/cjs/components/form/form-item.js +24 -8
- package/cjs/components/form/form.css +4 -0
- package/cjs/components/form/form.js +17 -6
- package/cjs/components/form/index.css +9 -1
- package/cjs/components/form/index.d.ts +2 -0
- package/cjs/components/form/index.js +3 -0
- package/cjs/components/image-uploader/image-uploader.d.ts +1 -1
- package/cjs/components/image-uploader/image-uploader.js +17 -1
- package/cjs/components/infinite-scroll/infinite-scroll.js +23 -19
- package/cjs/components/modal/modal.js +0 -1
- package/cjs/components/notice-bar/notice-bar.js +1 -1
- package/cjs/components/popover/index.d.ts +7 -2
- package/cjs/components/popover/normalize-placement.d.ts +2 -0
- package/cjs/components/popover/normalize-placement.js +22 -0
- package/cjs/components/popover/popover.css +0 -84
- package/cjs/components/popover/popover.d.ts +11 -5
- package/cjs/components/popover/popover.js +126 -22
- package/cjs/components/popover/wrapper.d.ts +7 -0
- package/cjs/components/popover/wrapper.js +41 -0
- package/cjs/components/pull-to-refresh/pull-to-refresh.js +24 -9
- package/cjs/components/radio/radio.js +16 -4
- package/cjs/components/search-bar/search-bar.js +0 -1
- package/cjs/components/swiper/swiper.js +1 -1
- package/cjs/components/text-area/text-area.css +4 -1
- package/cjs/components/text-area/text-area.d.ts +2 -2
- package/cjs/utils/use-props-value.d.ts +2 -1
- package/cjs/utils/use-props-value.js +4 -2
- package/es/components/avatar/avatar.js +1 -0
- package/es/components/calendar/calendar.js +23 -19
- package/es/components/cascader-view/cascader-view.d.ts +1 -0
- package/es/components/cascader-view/use-cascader-value-extend.js +23 -0
- package/es/components/check-list/check-list-item.js +1 -1
- package/es/components/checkbox/checkbox.js +17 -5
- package/es/components/floating-bubble/floating-bubble.d.ts +2 -0
- package/es/components/floating-bubble/floating-bubble.js +57 -17
- package/es/components/form/form-array.d.ts +19 -0
- package/es/components/form/form-array.js +38 -0
- package/es/components/form/form-item.css +5 -1
- package/es/components/form/form-item.js +22 -8
- package/es/components/form/form.css +4 -0
- package/es/components/form/form.js +16 -6
- package/es/components/form/index.css +9 -1
- package/es/components/form/index.d.ts +2 -0
- package/es/components/form/index.js +2 -0
- package/es/components/image-uploader/image-uploader.d.ts +1 -1
- package/es/components/image-uploader/image-uploader.js +17 -1
- package/es/components/infinite-scroll/infinite-scroll.js +22 -19
- package/es/components/modal/modal.js +0 -1
- package/es/components/notice-bar/notice-bar.js +1 -1
- package/es/components/popover/index.d.ts +7 -2
- package/es/components/popover/normalize-placement.d.ts +2 -0
- package/es/components/popover/normalize-placement.js +15 -0
- package/es/components/popover/popover.css +0 -84
- package/es/components/popover/popover.d.ts +11 -5
- package/es/components/popover/popover.js +118 -22
- package/es/components/popover/wrapper.d.ts +7 -0
- package/es/components/popover/wrapper.js +28 -0
- package/es/components/pull-to-refresh/pull-to-refresh.js +24 -9
- package/es/components/radio/radio.js +17 -5
- package/es/components/search-bar/search-bar.js +0 -1
- package/es/components/swiper/swiper.js +1 -1
- package/es/components/text-area/text-area.css +4 -1
- package/es/components/text-area/text-area.d.ts +2 -2
- package/es/utils/use-props-value.d.ts +2 -1
- package/es/utils/use-props-value.js +4 -2
- package/package.json +2 -2
- package/umd/antd-mobile.js +1 -1
- package/umd/antd-mobile.js.LICENSE.txt +0 -24
|
@@ -26,7 +26,29 @@ export const Calendar = forwardRef((p, ref) => {
|
|
|
26
26
|
if (item) markItems.unshift(item);
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
const
|
|
29
|
+
const dateRange = useMemo(() => {
|
|
30
|
+
var _a, _b, _c, _d;
|
|
31
|
+
|
|
32
|
+
if (props.selectionMode === 'single') {
|
|
33
|
+
const value = (_b = (_a = props.value) !== null && _a !== void 0 ? _a : props.defaultValue) !== null && _b !== void 0 ? _b : null;
|
|
34
|
+
return [value, value];
|
|
35
|
+
} else if (props.selectionMode === 'range') {
|
|
36
|
+
return (_d = (_c = props.value) !== null && _c !== void 0 ? _c : props.defaultValue) !== null && _d !== void 0 ? _d : [null, null];
|
|
37
|
+
} else {
|
|
38
|
+
return [null, null];
|
|
39
|
+
}
|
|
40
|
+
}, [props.selectionMode, props.value, props.defaultValue]);
|
|
41
|
+
const [begin, setBegin] = useState(null);
|
|
42
|
+
const [end, setEnd] = useState(null);
|
|
43
|
+
useIsomorphicLayoutEffect(() => {
|
|
44
|
+
setBegin(dateRange[0] ? dayjs(dateRange[0]) : null);
|
|
45
|
+
setEnd(dateRange[1] ? dayjs(dateRange[1]) : null);
|
|
46
|
+
}, [dateRange[0], dateRange[1]]);
|
|
47
|
+
const [current, setCurrent] = useState(() => {
|
|
48
|
+
var _a;
|
|
49
|
+
|
|
50
|
+
return dayjs((_a = dateRange[0]) !== null && _a !== void 0 ? _a : today).date(1);
|
|
51
|
+
});
|
|
30
52
|
useUpdateEffect(() => {
|
|
31
53
|
var _a;
|
|
32
54
|
|
|
@@ -76,24 +98,6 @@ export const Calendar = forwardRef((p, ref) => {
|
|
|
76
98
|
setCurrent(current.add(1, 'year'));
|
|
77
99
|
}
|
|
78
100
|
}, React.createElement(ArrowLeftDouble, null)));
|
|
79
|
-
const dateRange = useMemo(() => {
|
|
80
|
-
var _a, _b, _c, _d;
|
|
81
|
-
|
|
82
|
-
if (props.selectionMode === 'single') {
|
|
83
|
-
const value = (_b = (_a = props.value) !== null && _a !== void 0 ? _a : props.defaultValue) !== null && _b !== void 0 ? _b : null;
|
|
84
|
-
return [value, value];
|
|
85
|
-
} else if (props.selectionMode === 'range') {
|
|
86
|
-
return (_d = (_c = props.value) !== null && _c !== void 0 ? _c : props.defaultValue) !== null && _d !== void 0 ? _d : [null, null];
|
|
87
|
-
} else {
|
|
88
|
-
return [null, null];
|
|
89
|
-
}
|
|
90
|
-
}, [props.selectionMode, props.value, props.defaultValue]);
|
|
91
|
-
const [begin, setBegin] = useState(null);
|
|
92
|
-
const [end, setEnd] = useState(null);
|
|
93
|
-
useIsomorphicLayoutEffect(() => {
|
|
94
|
-
setBegin(dateRange[0] ? dayjs(dateRange[0]) : null);
|
|
95
|
-
setEnd(dateRange[1] ? dayjs(dateRange[1]) : null);
|
|
96
|
-
}, [dateRange[0], dateRange[1]]);
|
|
97
101
|
|
|
98
102
|
function renderCells() {
|
|
99
103
|
var _a;
|
|
@@ -21,11 +21,34 @@ export function useCascaderValueExtend(options) {
|
|
|
21
21
|
return ret;
|
|
22
22
|
}, val => JSON.stringify(val));
|
|
23
23
|
}, [options]);
|
|
24
|
+
const generateIsLeaf = useMemo(() => {
|
|
25
|
+
return memoize(val => {
|
|
26
|
+
var _a;
|
|
27
|
+
|
|
28
|
+
let isLeaf = false;
|
|
29
|
+
|
|
30
|
+
for (const v of val) {
|
|
31
|
+
const target = options.find(option => option.value === v);
|
|
32
|
+
|
|
33
|
+
if (!target) {
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
isLeaf = ((_a = target.children) === null || _a === void 0 ? void 0 : _a.length) === val.length;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return isLeaf;
|
|
41
|
+
}, val => JSON.stringify(val));
|
|
42
|
+
}, [options]);
|
|
24
43
|
|
|
25
44
|
function generateValueExtend(val) {
|
|
26
45
|
return {
|
|
27
46
|
get items() {
|
|
28
47
|
return generateItems(val);
|
|
48
|
+
},
|
|
49
|
+
|
|
50
|
+
get isLeaf() {
|
|
51
|
+
return generateIsLeaf(val);
|
|
29
52
|
}
|
|
30
53
|
|
|
31
54
|
};
|
|
@@ -20,7 +20,7 @@ export const CheckListItem = props => {
|
|
|
20
20
|
}, active ? context.activeIcon : null);
|
|
21
21
|
return withNativeProps(props, React.createElement(List.Item, {
|
|
22
22
|
title: props.title,
|
|
23
|
-
className: classNames(classPrefix, readOnly && `${classPrefix}-readonly`),
|
|
23
|
+
className: classNames(classPrefix, readOnly && `${classPrefix}-readonly`, active && `${classPrefix}-active`),
|
|
24
24
|
description: props.description,
|
|
25
25
|
prefix: props.prefix,
|
|
26
26
|
onClick: e => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useContext } from 'react';
|
|
1
|
+
import React, { useContext, useEffect, useRef } from 'react';
|
|
2
2
|
import { withNativeProps } from '../../utils/native-props';
|
|
3
3
|
import classNames from 'classnames';
|
|
4
4
|
import { CheckboxGroupContext } from './group-context';
|
|
@@ -66,7 +66,22 @@ export const Checkbox = p => {
|
|
|
66
66
|
}, props.indeterminate ? React.createElement(IndeterminateIcon, null) : checked && React.createElement(CheckIcon, null));
|
|
67
67
|
};
|
|
68
68
|
|
|
69
|
+
const inputRef = useRef(null);
|
|
70
|
+
const labelRef = useRef(null);
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
var _a;
|
|
73
|
+
|
|
74
|
+
(_a = labelRef.current) === null || _a === void 0 ? void 0 : _a.addEventListener('click', e => {
|
|
75
|
+
if (e.target !== inputRef.current) {
|
|
76
|
+
e.stopPropagation();
|
|
77
|
+
e.stopImmediatePropagation();
|
|
78
|
+
}
|
|
79
|
+
}, {
|
|
80
|
+
capture: false
|
|
81
|
+
});
|
|
82
|
+
}, []);
|
|
69
83
|
return withNativeProps(props, React.createElement("label", {
|
|
84
|
+
ref: labelRef,
|
|
70
85
|
className: classNames(classPrefix, {
|
|
71
86
|
[`${classPrefix}-checked`]: checked && !props.indeterminate,
|
|
72
87
|
[`${classPrefix}-indeterminate`]: props.indeterminate,
|
|
@@ -74,15 +89,12 @@ export const Checkbox = p => {
|
|
|
74
89
|
[`${classPrefix}-block`]: props.block
|
|
75
90
|
})
|
|
76
91
|
}, React.createElement("input", {
|
|
92
|
+
ref: inputRef,
|
|
77
93
|
type: 'checkbox',
|
|
78
94
|
checked: checked,
|
|
79
95
|
onChange: e => {
|
|
80
96
|
setChecked(e.target.checked);
|
|
81
97
|
},
|
|
82
|
-
onClick: e => {
|
|
83
|
-
e.stopPropagation();
|
|
84
|
-
e.nativeEvent.stopImmediatePropagation();
|
|
85
|
-
},
|
|
86
98
|
disabled: disabled,
|
|
87
99
|
id: props.id
|
|
88
100
|
}), renderIcon(), props.children && React.createElement("div", {
|
|
@@ -2,5 +2,7 @@ import React, { FC } from 'react';
|
|
|
2
2
|
import { NativeProps } from '../../utils/native-props';
|
|
3
3
|
export declare type FloatingBubbleProps = {
|
|
4
4
|
onClick?: (event: React.MouseEvent<HTMLDivElement, MouseEvent>) => void;
|
|
5
|
+
axis?: 'x' | 'y' | 'xy' | 'lock';
|
|
6
|
+
magnetic?: 'x' | 'y';
|
|
5
7
|
} & NativeProps<'--initial-position-left' | '--initial-position-right' | '--initial-position-top' | '--initial-position-bottom' | '--z-index' | '--edge-distance' | '--size' | '--border-radius'>;
|
|
6
8
|
export declare const FloatingBubble: FC<FloatingBubbleProps>;
|
|
@@ -1,47 +1,83 @@
|
|
|
1
1
|
import React, { useRef } from 'react';
|
|
2
|
-
import { useSpring, animated } from '@react-spring/web';
|
|
2
|
+
import { useSpring, animated, to } from '@react-spring/web';
|
|
3
3
|
import { useDrag } from '@use-gesture/react';
|
|
4
4
|
import { mergeProps } from '../../utils/with-default-props';
|
|
5
5
|
import { withNativeProps } from '../../utils/native-props';
|
|
6
6
|
const classPrefix = `adm-floating-bubble`;
|
|
7
|
-
const defaultProps = {
|
|
7
|
+
const defaultProps = {
|
|
8
|
+
axis: 'y'
|
|
9
|
+
};
|
|
8
10
|
export const FloatingBubble = p => {
|
|
9
11
|
const props = mergeProps(defaultProps, p);
|
|
10
12
|
const boundaryRef = useRef(null);
|
|
13
|
+
const buttonRef = useRef(null);
|
|
11
14
|
/**
|
|
12
15
|
* memoize the `to` function
|
|
13
16
|
* inside a component that renders frequently
|
|
14
17
|
* to prevent an unintended restart
|
|
15
18
|
*/
|
|
16
19
|
|
|
17
|
-
const [
|
|
20
|
+
const [{
|
|
21
|
+
x,
|
|
22
|
+
y,
|
|
23
|
+
opacity
|
|
24
|
+
}, api] = useSpring(() => ({
|
|
25
|
+
x: 0,
|
|
18
26
|
y: 0,
|
|
19
|
-
scale: 1,
|
|
20
27
|
opacity: 1
|
|
21
28
|
}));
|
|
22
29
|
const bind = useDrag(state => {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
animation.start({
|
|
26
|
-
y: state.offset[1]
|
|
27
|
-
});
|
|
28
|
-
} // active status
|
|
30
|
+
let nextX = state.offset[0];
|
|
31
|
+
let nextY = state.offset[1];
|
|
29
32
|
|
|
33
|
+
if (state.last && props.magnetic) {
|
|
34
|
+
const boundary = boundaryRef.current;
|
|
35
|
+
const button = buttonRef.current;
|
|
36
|
+
if (!boundary || !button) return;
|
|
37
|
+
const boundaryRect = boundary.getBoundingClientRect();
|
|
38
|
+
const buttonRect = button.getBoundingClientRect();
|
|
30
39
|
|
|
31
|
-
|
|
32
|
-
|
|
40
|
+
if (props.magnetic === 'x') {
|
|
41
|
+
const compensation = x.goal - x.get();
|
|
42
|
+
const leftDistance = buttonRect.left + compensation - boundaryRect.left;
|
|
43
|
+
const rightDistance = boundaryRect.right - (buttonRect.right + compensation);
|
|
44
|
+
|
|
45
|
+
if (rightDistance <= leftDistance) {
|
|
46
|
+
nextX += rightDistance;
|
|
47
|
+
} else {
|
|
48
|
+
nextX -= leftDistance;
|
|
49
|
+
}
|
|
50
|
+
} else if (props.magnetic === 'y') {
|
|
51
|
+
const compensation = y.goal - y.get();
|
|
52
|
+
const topDistance = buttonRect.top + compensation - boundaryRect.top;
|
|
53
|
+
const bottomDistance = boundaryRect.bottom - (buttonRect.bottom + compensation);
|
|
54
|
+
|
|
55
|
+
if (bottomDistance <= topDistance) {
|
|
56
|
+
nextY += bottomDistance;
|
|
57
|
+
} else {
|
|
58
|
+
nextY -= topDistance;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
api.start({
|
|
64
|
+
x: nextX,
|
|
65
|
+
y: nextY
|
|
66
|
+
}); // active status
|
|
67
|
+
|
|
68
|
+
api.start({
|
|
33
69
|
opacity: state.active ? 0.8 : 1
|
|
34
70
|
});
|
|
35
71
|
}, {
|
|
36
|
-
|
|
37
|
-
axis: 'y',
|
|
72
|
+
axis: props.axis === 'xy' ? undefined : props.axis,
|
|
38
73
|
pointer: {
|
|
39
74
|
touch: true
|
|
40
75
|
},
|
|
41
76
|
// the component won't trigger drag logic if the user just clicked on the component.
|
|
42
77
|
filterTaps: true,
|
|
43
78
|
// set constraints to the user gesture
|
|
44
|
-
bounds: boundaryRef
|
|
79
|
+
bounds: boundaryRef,
|
|
80
|
+
from: () => [x.get(), y.get()]
|
|
45
81
|
});
|
|
46
82
|
return withNativeProps(props, React.createElement("div", {
|
|
47
83
|
className: classPrefix
|
|
@@ -51,8 +87,12 @@ export const FloatingBubble = p => {
|
|
|
51
87
|
className: `${classPrefix}-boundary`,
|
|
52
88
|
ref: boundaryRef
|
|
53
89
|
})), React.createElement(animated.div, Object.assign({}, bind(), {
|
|
54
|
-
style:
|
|
90
|
+
style: {
|
|
91
|
+
opacity,
|
|
92
|
+
transform: to([x, y], (x, y) => `translate(${x}px, ${y}px)`)
|
|
93
|
+
},
|
|
55
94
|
onClick: props.onClick,
|
|
56
|
-
className: `${classPrefix}-button
|
|
95
|
+
className: `${classPrefix}-button`,
|
|
96
|
+
ref: buttonRef
|
|
57
97
|
}), props.children)));
|
|
58
98
|
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React, { ReactElement, ReactNode } from 'react';
|
|
2
|
+
import type { StoreValue } from 'rc-field-form/es/interface';
|
|
3
|
+
export interface FormArrayField {
|
|
4
|
+
index: number;
|
|
5
|
+
key: number;
|
|
6
|
+
}
|
|
7
|
+
export interface FormArrayOperation {
|
|
8
|
+
add: (defaultValue?: StoreValue, insertIndex?: number) => void;
|
|
9
|
+
remove: (index: number | number[]) => void;
|
|
10
|
+
move: (from: number, to: number) => void;
|
|
11
|
+
}
|
|
12
|
+
export interface FormArrayProps {
|
|
13
|
+
name: string | number | (string | number)[];
|
|
14
|
+
initialValue?: any[];
|
|
15
|
+
renderHeader?: (field: FormArrayField, operation: FormArrayOperation) => ReactNode;
|
|
16
|
+
renderAdd?: () => ReactNode;
|
|
17
|
+
children: (fields: FormArrayField[], operation: FormArrayOperation) => ReactElement[];
|
|
18
|
+
}
|
|
19
|
+
export declare const FormArray: React.FC<FormArrayProps>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { List as RCList } from 'rc-field-form';
|
|
3
|
+
import List from '../list';
|
|
4
|
+
export const FormArray = props => {
|
|
5
|
+
return React.createElement(RCList, {
|
|
6
|
+
name: props.name,
|
|
7
|
+
initialValue: props.initialValue
|
|
8
|
+
}, (rcFields, operation) => {
|
|
9
|
+
const fields = rcFields.map(field => ({
|
|
10
|
+
index: field.name,
|
|
11
|
+
key: field.key
|
|
12
|
+
}));
|
|
13
|
+
const children = props.children(fields, operation).map((child, index) => {
|
|
14
|
+
var _a;
|
|
15
|
+
|
|
16
|
+
return React.createElement(List, {
|
|
17
|
+
key: fields[index].key,
|
|
18
|
+
mode: 'card',
|
|
19
|
+
header: (_a = props.renderHeader) === null || _a === void 0 ? void 0 : _a.call(props, fields[index], operation)
|
|
20
|
+
}, child);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
if (props.renderAdd) {
|
|
24
|
+
children.push(React.createElement(List, {
|
|
25
|
+
key: 'add',
|
|
26
|
+
mode: 'card'
|
|
27
|
+
}, React.createElement(List.Item, {
|
|
28
|
+
className: 'adm-form-list-operation',
|
|
29
|
+
onClick: () => {
|
|
30
|
+
operation.add();
|
|
31
|
+
},
|
|
32
|
+
arrow: false
|
|
33
|
+
}, props.renderAdd())));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return React.createElement(React.Fragment, null, children);
|
|
37
|
+
});
|
|
38
|
+
};
|
|
@@ -50,11 +50,16 @@
|
|
|
50
50
|
flex: none;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
.adm-form-item-
|
|
53
|
+
.adm-form-item-feedback-error {
|
|
54
54
|
color: var(--adm-color-danger);
|
|
55
55
|
margin-top: 8px;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
.adm-form-item-feedback-warning {
|
|
59
|
+
color: var(--adm-color-warning);
|
|
60
|
+
margin-top: 8px;
|
|
61
|
+
}
|
|
62
|
+
|
|
58
63
|
.adm-form-item.adm-form-item-hidden {
|
|
59
64
|
display: none;
|
|
60
65
|
}
|
|
@@ -28,9 +28,7 @@ const FormItemLayout = props => {
|
|
|
28
28
|
children,
|
|
29
29
|
htmlFor,
|
|
30
30
|
hidden,
|
|
31
|
-
errors,
|
|
32
31
|
arrow,
|
|
33
|
-
description,
|
|
34
32
|
childElementPosition = 'normal'
|
|
35
33
|
} = props;
|
|
36
34
|
const context = useContext(FormContext);
|
|
@@ -39,7 +37,6 @@ const FormItemLayout = props => {
|
|
|
39
37
|
} = useConfig();
|
|
40
38
|
const hasFeedback = props.hasFeedback !== undefined ? props.hasFeedback : context.hasFeedback;
|
|
41
39
|
const layout = props.layout || context.layout;
|
|
42
|
-
const feedback = hasFeedback && errors && errors.length > 0 ? errors[0] : null;
|
|
43
40
|
|
|
44
41
|
const requiredMark = (() => {
|
|
45
42
|
const {
|
|
@@ -77,15 +74,19 @@ const FormItemLayout = props => {
|
|
|
77
74
|
mode: 'dark',
|
|
78
75
|
trigger: 'click'
|
|
79
76
|
}, React.createElement(QuestionCircleOutline, null)))) : null;
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
77
|
+
const description = React.createElement(React.Fragment, null, props.description, hasFeedback && React.createElement(React.Fragment, null, props.errors.map((error, index) => React.createElement("div", {
|
|
78
|
+
key: `error-${index}`,
|
|
79
|
+
className: `${classPrefix}-feedback-error`
|
|
80
|
+
}, error)), props.warnings.map((warning, index) => React.createElement("div", {
|
|
81
|
+
key: `warning-${index}`,
|
|
82
|
+
className: `${classPrefix}-feedback-warning`
|
|
83
|
+
}, warning))));
|
|
83
84
|
return React.createElement(List.Item, {
|
|
84
85
|
style: style,
|
|
85
86
|
title: layout === 'vertical' && labelElement,
|
|
86
87
|
prefix: layout === 'horizontal' && labelElement,
|
|
87
88
|
extra: extra,
|
|
88
|
-
description:
|
|
89
|
+
description: description,
|
|
89
90
|
className: classNames(classPrefix, className, `${classPrefix}-${layout}`, {
|
|
90
91
|
[`${classPrefix}-hidden`]: hidden
|
|
91
92
|
}),
|
|
@@ -153,7 +154,7 @@ export const FormItem = props => {
|
|
|
153
154
|
}, [setSubMetas]);
|
|
154
155
|
|
|
155
156
|
function renderLayout(baseChildren, fieldId, meta, isRequired) {
|
|
156
|
-
var _a;
|
|
157
|
+
var _a, _b;
|
|
157
158
|
|
|
158
159
|
if (noStyle && !hidden) {
|
|
159
160
|
return baseChildren;
|
|
@@ -171,6 +172,18 @@ export const FormItem = props => {
|
|
|
171
172
|
|
|
172
173
|
return subErrors;
|
|
173
174
|
}, curErrors);
|
|
175
|
+
const curWarnings = (_b = meta === null || meta === void 0 ? void 0 : meta.warnings) !== null && _b !== void 0 ? _b : [];
|
|
176
|
+
const warnings = Object.keys(subMetas).reduce((subWarnings, key) => {
|
|
177
|
+
var _a, _b;
|
|
178
|
+
|
|
179
|
+
const warnings = (_b = (_a = subMetas[key]) === null || _a === void 0 ? void 0 : _a.warnings) !== null && _b !== void 0 ? _b : [];
|
|
180
|
+
|
|
181
|
+
if (warnings.length) {
|
|
182
|
+
subWarnings = [...subWarnings, ...warnings];
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return subWarnings;
|
|
186
|
+
}, curWarnings);
|
|
174
187
|
return React.createElement(FormItemLayout, {
|
|
175
188
|
className: className,
|
|
176
189
|
style: style,
|
|
@@ -183,6 +196,7 @@ export const FormItem = props => {
|
|
|
183
196
|
hasFeedback: hasFeedback,
|
|
184
197
|
htmlFor: fieldId,
|
|
185
198
|
errors: errors,
|
|
199
|
+
warnings: warnings,
|
|
186
200
|
onClick: onClick,
|
|
187
201
|
hidden: hidden,
|
|
188
202
|
layout: layout,
|
|
@@ -8,6 +8,7 @@ import { mergeProps } from '../../utils/with-default-props';
|
|
|
8
8
|
import { Header } from './header';
|
|
9
9
|
import { useConfig } from '../config-provider';
|
|
10
10
|
import merge from 'lodash/merge';
|
|
11
|
+
import { FormArray } from './form-array';
|
|
11
12
|
const classPrefix = 'adm-form';
|
|
12
13
|
const defaultProps = defaultFormContext;
|
|
13
14
|
export const Form = forwardRef((p, ref) => {
|
|
@@ -45,13 +46,22 @@ export const Form = forwardRef((p, ref) => {
|
|
|
45
46
|
items = [];
|
|
46
47
|
}
|
|
47
48
|
|
|
48
|
-
React.Children.forEach(props.children,
|
|
49
|
-
if (React.isValidElement(child)
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
49
|
+
React.Children.forEach(props.children, child => {
|
|
50
|
+
if (React.isValidElement(child)) {
|
|
51
|
+
if (child.type === Header) {
|
|
52
|
+
collect();
|
|
53
|
+
currentHeader = child.props.children;
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (child.type === FormArray) {
|
|
58
|
+
collect();
|
|
59
|
+
lists.push(child);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
54
62
|
}
|
|
63
|
+
|
|
64
|
+
items.push(child);
|
|
55
65
|
});
|
|
56
66
|
collect();
|
|
57
67
|
return React.createElement(RcForm, Object.assign({
|
|
@@ -19,6 +19,11 @@
|
|
|
19
19
|
padding: 40px 24px;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
.adm-form-list-operation {
|
|
23
|
+
text-align: center;
|
|
24
|
+
color: #1677ff;
|
|
25
|
+
}
|
|
26
|
+
|
|
22
27
|
.adm-form-item + .adm-form-item {
|
|
23
28
|
border-top: none;
|
|
24
29
|
}
|
|
@@ -71,11 +76,16 @@
|
|
|
71
76
|
flex: none;
|
|
72
77
|
}
|
|
73
78
|
|
|
74
|
-
.adm-form-item-
|
|
79
|
+
.adm-form-item-feedback-error {
|
|
75
80
|
color: var(--adm-color-danger);
|
|
76
81
|
margin-top: 8px;
|
|
77
82
|
}
|
|
78
83
|
|
|
84
|
+
.adm-form-item-feedback-warning {
|
|
85
|
+
color: var(--adm-color-warning);
|
|
86
|
+
margin-top: 8px;
|
|
87
|
+
}
|
|
88
|
+
|
|
79
89
|
.adm-form-item.adm-form-item-hidden {
|
|
80
90
|
display: none;
|
|
81
91
|
}
|
|
@@ -6,6 +6,7 @@ export type { FormProps, FormInstance } from './form';
|
|
|
6
6
|
export type { FormItemProps } from './form-item';
|
|
7
7
|
export type { FormSubscribeProps } from './form-subscribe';
|
|
8
8
|
export type { ValidateMessages, FieldData, NamePath, } from 'rc-field-form/es/interface';
|
|
9
|
+
export type { FormArrayField, FormArrayOperation, FormArrayProps, } from './form-array';
|
|
9
10
|
declare const _default: import("react").ForwardRefExoticComponent<Pick<import("rc-field-form").FormProps<any>, "children" | "form" | "name" | "initialValues" | "preserve" | "validateMessages" | "validateTrigger" | "onFieldsChange" | "onFinish" | "onFinishFailed" | "onValuesChange"> & import("../../utils/native-props").NativeProps<"--border-inner" | "--border-top" | "--border-bottom"> & Partial<import("./context").FormContextType> & {
|
|
10
11
|
footer?: import("react").ReactNode;
|
|
11
12
|
layout?: FormLayout | undefined;
|
|
@@ -14,6 +15,7 @@ declare const _default: import("react").ForwardRefExoticComponent<Pick<import("r
|
|
|
14
15
|
Item: import("react").FC<import("./form-item").FormItemProps>;
|
|
15
16
|
Subscribe: import("react").VFC<import("./form-subscribe").FormSubscribeProps>;
|
|
16
17
|
Header: import("react").FC<{}>;
|
|
18
|
+
Array: import("react").FC<import("./form-array").FormArrayProps>;
|
|
17
19
|
useForm: typeof useForm;
|
|
18
20
|
};
|
|
19
21
|
export default _default;
|
|
@@ -5,9 +5,11 @@ import { FormItem } from './form-item';
|
|
|
5
5
|
import { Header } from './header';
|
|
6
6
|
import { useForm } from 'rc-field-form';
|
|
7
7
|
import { FormSubscribe } from './form-subscribe';
|
|
8
|
+
import { FormArray } from './form-array';
|
|
8
9
|
export default attachPropertiesToComponent(Form, {
|
|
9
10
|
Item: FormItem,
|
|
10
11
|
Subscribe: FormSubscribe,
|
|
11
12
|
Header,
|
|
13
|
+
Array: FormArray,
|
|
12
14
|
useForm
|
|
13
15
|
});
|
|
@@ -20,7 +20,7 @@ export declare type ImageUploaderProps = {
|
|
|
20
20
|
deletable?: boolean;
|
|
21
21
|
capture?: InputHTMLAttributes<unknown>['capture'];
|
|
22
22
|
onPreview?: (index: number, item: ImageUploadItem) => void;
|
|
23
|
-
beforeUpload?: (file: File[]) => Promise<File
|
|
23
|
+
beforeUpload?: (file: File, files: File[]) => Promise<File | null> | File | null;
|
|
24
24
|
upload: (file: File) => Promise<ImageUploadItem>;
|
|
25
25
|
onDelete?: (item: ImageUploadItem) => boolean | Promise<boolean> | void;
|
|
26
26
|
preview?: boolean;
|
|
@@ -39,6 +39,17 @@ export const ImageUploader = p => {
|
|
|
39
39
|
onPreview
|
|
40
40
|
} = props;
|
|
41
41
|
|
|
42
|
+
function processFile(file, fileList) {
|
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
const {
|
|
45
|
+
beforeUpload
|
|
46
|
+
} = props;
|
|
47
|
+
let transformedFile = file;
|
|
48
|
+
transformedFile = yield beforeUpload === null || beforeUpload === void 0 ? void 0 : beforeUpload(file, fileList);
|
|
49
|
+
return transformedFile;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
42
53
|
function onChange(e) {
|
|
43
54
|
var _a;
|
|
44
55
|
|
|
@@ -51,7 +62,12 @@ export const ImageUploader = p => {
|
|
|
51
62
|
let files = [].slice.call(rawFiles);
|
|
52
63
|
|
|
53
64
|
if (props.beforeUpload) {
|
|
54
|
-
|
|
65
|
+
const postFiles = files.map(file => {
|
|
66
|
+
return processFile(file, files);
|
|
67
|
+
});
|
|
68
|
+
yield Promise.all(postFiles).then(filesList => {
|
|
69
|
+
files = filesList.filter(Boolean);
|
|
70
|
+
});
|
|
55
71
|
}
|
|
56
72
|
|
|
57
73
|
if (files.length === 0) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
1
2
|
import { mergeProps } from '../../utils/with-default-props';
|
|
2
|
-
import React, { useEffect, useRef } from 'react';
|
|
3
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
3
4
|
import { useLockFn, useMemoizedFn } from 'ahooks';
|
|
4
5
|
import { withNativeProps } from '../../utils/native-props';
|
|
5
6
|
import { getScrollParent } from '../../utils/get-scroll-parent';
|
|
@@ -23,25 +24,27 @@ export const InfiniteScroll = p => {
|
|
|
23
24
|
}, p);
|
|
24
25
|
const doLoadMore = useLockFn(() => props.loadMore());
|
|
25
26
|
const elementRef = useRef(null);
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
27
|
+
const [flag, setFlag] = useState({});
|
|
28
|
+
const nextFlagRef = useRef(flag);
|
|
29
|
+
const check = useMemoizedFn(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
30
|
+
if (nextFlagRef.current !== flag) return;
|
|
31
|
+
if (!props.hasMore) return;
|
|
32
|
+
const element = elementRef.current;
|
|
33
|
+
if (!element) return;
|
|
34
|
+
if (!element.offsetParent) return;
|
|
35
|
+
const parent = getScrollParent(element);
|
|
36
|
+
if (!parent) return;
|
|
37
|
+
const rect = element.getBoundingClientRect();
|
|
38
|
+
const elementTop = rect.top;
|
|
39
|
+
const current = isWindow(parent) ? window.innerHeight : parent.getBoundingClientRect().bottom;
|
|
39
40
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
if (current >= elementTop - props.threshold) {
|
|
42
|
+
const nextFlag = {};
|
|
43
|
+
nextFlagRef.current = nextFlag;
|
|
44
|
+
yield doLoadMore();
|
|
45
|
+
setFlag(nextFlag);
|
|
46
|
+
}
|
|
47
|
+
})); // 确保在内容不足时会自动触发加载事件
|
|
45
48
|
|
|
46
49
|
useEffect(() => {
|
|
47
50
|
check();
|
|
@@ -13,7 +13,6 @@ import AutoCenter from '../auto-center';
|
|
|
13
13
|
import { useSpring, animated } from '@react-spring/web';
|
|
14
14
|
import { withNativeProps } from '../../utils/native-props';
|
|
15
15
|
import { CloseOutline } from 'antd-mobile-icons';
|
|
16
|
-
const classPrefix = `adm-modal`;
|
|
17
16
|
const defaultProps = {
|
|
18
17
|
visible: false,
|
|
19
18
|
actions: [],
|