antd-mobile 5.4.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/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.js +14 -5
- 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 +16 -5
- 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/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/utils/use-props-value.d.ts +2 -1
- package/2x/cjs/utils/use-props-value.js +4 -2
- 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.js +14 -5
- 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 +15 -5
- 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/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/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/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.js +14 -5
- 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 +16 -5
- 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/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/utils/use-props-value.d.ts +2 -1
- package/cjs/utils/use-props-value.js +4 -2
- 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.js +14 -5
- 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 +15 -5
- 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/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/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
|
@@ -5,9 +5,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.Popover = void 0;
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _tslib = require("tslib");
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
11
11
|
|
|
12
12
|
var _classnames = _interopRequireDefault(require("classnames"));
|
|
13
13
|
|
|
@@ -15,10 +15,26 @@ var _usePropsValue = require("../../utils/use-props-value");
|
|
|
15
15
|
|
|
16
16
|
var _withDefaultProps = require("../../utils/with-default-props");
|
|
17
17
|
|
|
18
|
+
var _nativeProps = require("../../utils/native-props");
|
|
19
|
+
|
|
18
20
|
var _withStopPropagation = require("../../utils/with-stop-propagation");
|
|
19
21
|
|
|
20
22
|
var _arrow = require("./arrow");
|
|
21
23
|
|
|
24
|
+
var _renderToContainer = require("../../utils/render-to-container");
|
|
25
|
+
|
|
26
|
+
var _dom = require("@floating-ui/dom");
|
|
27
|
+
|
|
28
|
+
var _wrapper = require("./wrapper");
|
|
29
|
+
|
|
30
|
+
var _shouldRender = require("../../utils/should-render");
|
|
31
|
+
|
|
32
|
+
var _ahooks = require("ahooks");
|
|
33
|
+
|
|
34
|
+
var _normalizePlacement = require("./normalize-placement");
|
|
35
|
+
|
|
36
|
+
var _convertPx = require("../../utils/convert-px");
|
|
37
|
+
|
|
22
38
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
39
|
|
|
24
40
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
@@ -33,12 +49,11 @@ const defaultProps = {
|
|
|
33
49
|
getContainer: () => document.body
|
|
34
50
|
};
|
|
35
51
|
const Popover = (0, _react.forwardRef)((p, ref) => {
|
|
36
|
-
var _a;
|
|
37
|
-
|
|
38
52
|
const props = (0, _withDefaultProps.mergeProps)(defaultProps, p);
|
|
39
53
|
const {
|
|
40
54
|
mode = 'light'
|
|
41
55
|
} = props;
|
|
56
|
+
const placement = (0, _normalizePlacement.normalizePlacement)(props.placement);
|
|
42
57
|
const [visible, setVisible] = (0, _usePropsValue.usePropsValue)({
|
|
43
58
|
value: props.visible,
|
|
44
59
|
defaultValue: props.defaultVisible,
|
|
@@ -51,24 +66,113 @@ const Popover = (0, _react.forwardRef)((p, ref) => {
|
|
|
51
66
|
visible
|
|
52
67
|
};
|
|
53
68
|
}, [visible]);
|
|
54
|
-
const
|
|
69
|
+
const targetRef = (0, _react.useRef)(null);
|
|
70
|
+
const floatingRef = (0, _react.useRef)(null);
|
|
71
|
+
const arrowRef = (0, _react.useRef)(null);
|
|
72
|
+
const floating = (0, _withStopPropagation.withStopPropagation)(props.stopPropagation, (0, _nativeProps.withNativeProps)(props, _react.default.createElement("div", {
|
|
73
|
+
className: (0, _classnames.default)(classPrefix, `${classPrefix}-${mode}`, !visible && `${classPrefix}-hidden`),
|
|
74
|
+
ref: floatingRef
|
|
75
|
+
}, _react.default.createElement("div", {
|
|
76
|
+
className: `${classPrefix}-arrow`,
|
|
77
|
+
ref: arrowRef
|
|
78
|
+
}, _react.default.createElement(_arrow.Arrow, {
|
|
79
|
+
className: `${classPrefix}-arrow-icon`
|
|
80
|
+
})), _react.default.createElement("div", {
|
|
81
|
+
className: `${classPrefix}-inner`
|
|
82
|
+
}, _react.default.createElement("div", {
|
|
55
83
|
className: `${classPrefix}-inner-content`
|
|
56
|
-
}, props.content));
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
84
|
+
}, props.content)))));
|
|
85
|
+
const [targetElement, setTargetElement] = (0, _react.useState)(null);
|
|
86
|
+
|
|
87
|
+
function update() {
|
|
88
|
+
var _a, _b, _c;
|
|
89
|
+
|
|
90
|
+
return (0, _tslib.__awaiter)(this, void 0, void 0, function* () {
|
|
91
|
+
const target = (_b = (_a = targetRef.current) === null || _a === void 0 ? void 0 : _a.element) !== null && _b !== void 0 ? _b : null;
|
|
92
|
+
const floating = floatingRef.current;
|
|
93
|
+
const arrowElement = arrowRef.current;
|
|
94
|
+
setTargetElement(target);
|
|
95
|
+
if (!target || !floating || !arrowElement) return;
|
|
96
|
+
const {
|
|
97
|
+
x,
|
|
98
|
+
y,
|
|
99
|
+
placement: realPlacement,
|
|
100
|
+
middlewareData
|
|
101
|
+
} = yield (0, _dom.computePosition)(target, floating, {
|
|
102
|
+
placement,
|
|
103
|
+
middleware: [(0, _dom.offset)((0, _convertPx.convertPx)(12)), (0, _dom.shift)({
|
|
104
|
+
padding: (0, _convertPx.convertPx)(4),
|
|
105
|
+
crossAxis: false,
|
|
106
|
+
limiter: (0, _dom.limitShift)()
|
|
107
|
+
}), (0, _dom.flip)(), (0, _dom.hide)(), (0, _dom.arrow)({
|
|
108
|
+
element: arrowElement,
|
|
109
|
+
padding: (0, _convertPx.convertPx)(12)
|
|
110
|
+
})]
|
|
111
|
+
});
|
|
112
|
+
Object.assign(floating.style, {
|
|
113
|
+
left: `${x}px`,
|
|
114
|
+
top: `${y}px`
|
|
115
|
+
});
|
|
116
|
+
const side = realPlacement.split('-')[0];
|
|
117
|
+
const arrowSide = {
|
|
118
|
+
top: 'bottom',
|
|
119
|
+
right: 'left',
|
|
120
|
+
bottom: 'top',
|
|
121
|
+
left: 'right'
|
|
122
|
+
}[side];
|
|
123
|
+
const {
|
|
124
|
+
x: arrowX,
|
|
125
|
+
y: arrowY
|
|
126
|
+
} = (_c = middlewareData.arrow) !== null && _c !== void 0 ? _c : {};
|
|
127
|
+
Object.assign(arrowElement.style, {
|
|
128
|
+
left: arrowX != null ? `${arrowX}px` : '',
|
|
129
|
+
top: arrowY != null ? `${arrowY}px` : '',
|
|
130
|
+
right: '',
|
|
131
|
+
bottom: '',
|
|
132
|
+
[arrowSide]: `-${(0, _convertPx.convertPx)(8)}px`
|
|
133
|
+
});
|
|
134
|
+
const arrowRotate = {
|
|
135
|
+
top: '0deg',
|
|
136
|
+
bottom: '180deg',
|
|
137
|
+
left: '270deg',
|
|
138
|
+
right: '90deg'
|
|
139
|
+
}[side];
|
|
140
|
+
arrowElement.style.setProperty('--arrow-icon-rotate', arrowRotate);
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
(0, _ahooks.useIsomorphicLayoutEffect)(() => {
|
|
145
|
+
update();
|
|
146
|
+
});
|
|
147
|
+
(0, _react.useEffect)(() => {
|
|
148
|
+
if (!targetElement) return;
|
|
149
|
+
if (!props.trigger) return;
|
|
150
|
+
|
|
151
|
+
function handleClick() {
|
|
152
|
+
setVisible(v => !v);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
targetElement.addEventListener('click', handleClick);
|
|
156
|
+
return () => {
|
|
157
|
+
targetElement.removeEventListener('click', handleClick);
|
|
158
|
+
};
|
|
159
|
+
}, [targetElement, props.trigger]);
|
|
160
|
+
(0, _react.useEffect)(() => {
|
|
161
|
+
const floatingElement = floatingRef.current;
|
|
162
|
+
if (!targetElement || !floatingElement) return;
|
|
163
|
+
return (0, _dom.autoUpdate)(targetElement, floatingElement, update);
|
|
164
|
+
}, [targetElement]);
|
|
165
|
+
(0, _ahooks.useClickAway)(() => {
|
|
166
|
+
if (!props.trigger) return;
|
|
167
|
+
setVisible(false);
|
|
168
|
+
}, () => {
|
|
169
|
+
var _a;
|
|
170
|
+
|
|
171
|
+
return (_a = targetRef.current) === null || _a === void 0 ? void 0 : _a.element;
|
|
172
|
+
});
|
|
173
|
+
const shouldRender = (0, _shouldRender.useShouldRender)(visible, false, props.destroyOnHide);
|
|
174
|
+
return _react.default.createElement(_react.default.Fragment, null, _react.default.createElement(_wrapper.Wrapper, {
|
|
175
|
+
ref: targetRef
|
|
176
|
+
}, props.children), shouldRender && (0, _renderToContainer.renderToContainer)(props.getContainer, floating));
|
|
73
177
|
});
|
|
74
178
|
exports.Popover = Popover;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Wrapper = void 0;
|
|
7
|
+
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
|
|
10
|
+
var _reactDom = require("react-dom");
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
|
|
14
|
+
class Wrapper extends _react.default.Component {
|
|
15
|
+
constructor() {
|
|
16
|
+
super(...arguments);
|
|
17
|
+
this.element = null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
componentDidMount() {
|
|
21
|
+
this.componentDidUpdate();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
componentDidUpdate() {
|
|
25
|
+
// eslint-disable-next-line
|
|
26
|
+
const node = (0, _reactDom.findDOMNode)(this);
|
|
27
|
+
|
|
28
|
+
if (node instanceof Element) {
|
|
29
|
+
this.element = node;
|
|
30
|
+
} else {
|
|
31
|
+
this.element = null;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
render() {
|
|
36
|
+
return _react.default.Children.only(this.props.children);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
exports.Wrapper = Wrapper;
|
|
@@ -126,15 +126,30 @@ const PullToRefresh = p => {
|
|
|
126
126
|
|
|
127
127
|
const [, y] = state.movement;
|
|
128
128
|
|
|
129
|
-
if (state.first) {
|
|
130
|
-
const
|
|
131
|
-
if (!
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
129
|
+
if (state.first && y > 0) {
|
|
130
|
+
const target = state.event.target;
|
|
131
|
+
if (!target || !(target instanceof Element)) return;
|
|
132
|
+
let scrollParent = (0, _getScrollParent.getScrollParent)(target);
|
|
133
|
+
|
|
134
|
+
while (true) {
|
|
135
|
+
if (!scrollParent) return;
|
|
136
|
+
const scrollTop = getScrollTop(scrollParent);
|
|
137
|
+
|
|
138
|
+
if (scrollTop > 0) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (scrollParent instanceof Window) {
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
scrollParent = (0, _getScrollParent.getScrollParent)(scrollParent.parentNode);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
pullingRef.current = true;
|
|
150
|
+
|
|
151
|
+
function getScrollTop(element) {
|
|
152
|
+
return 'scrollTop' in element ? element.scrollTop : element.scrollY;
|
|
138
153
|
}
|
|
139
154
|
}
|
|
140
155
|
|
|
@@ -87,22 +87,34 @@ const Radio = p => {
|
|
|
87
87
|
}, checked && _react.default.createElement(_checkIcon.CheckIcon, null));
|
|
88
88
|
};
|
|
89
89
|
|
|
90
|
+
const inputRef = (0, _react.useRef)(null);
|
|
91
|
+
const labelRef = (0, _react.useRef)(null);
|
|
92
|
+
(0, _react.useEffect)(() => {
|
|
93
|
+
var _a;
|
|
94
|
+
|
|
95
|
+
(_a = labelRef.current) === null || _a === void 0 ? void 0 : _a.addEventListener('click', e => {
|
|
96
|
+
if (e.target !== inputRef.current) {
|
|
97
|
+
e.stopPropagation();
|
|
98
|
+
e.stopImmediatePropagation();
|
|
99
|
+
}
|
|
100
|
+
}, {
|
|
101
|
+
capture: false
|
|
102
|
+
});
|
|
103
|
+
}, []);
|
|
90
104
|
return (0, _nativeProps.withNativeProps)(props, _react.default.createElement("label", {
|
|
105
|
+
ref: labelRef,
|
|
91
106
|
className: (0, _classnames.default)(classPrefix, {
|
|
92
107
|
[`${classPrefix}-checked`]: checked,
|
|
93
108
|
[`${classPrefix}-disabled`]: disabled,
|
|
94
109
|
[`${classPrefix}-block`]: props.block
|
|
95
110
|
})
|
|
96
111
|
}, _react.default.createElement("input", {
|
|
112
|
+
ref: inputRef,
|
|
97
113
|
type: 'radio',
|
|
98
114
|
checked: checked,
|
|
99
115
|
onChange: e => {
|
|
100
116
|
setChecked(e.target.checked);
|
|
101
117
|
},
|
|
102
|
-
onClick: e => {
|
|
103
|
-
e.stopPropagation();
|
|
104
|
-
e.nativeEvent.stopImmediatePropagation();
|
|
105
|
-
},
|
|
106
118
|
disabled: disabled,
|
|
107
119
|
id: props.id
|
|
108
120
|
}), renderIcon(), props.children && _react.default.createElement("div", {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { SetStateAction } from 'react';
|
|
1
2
|
declare type Options<T> = {
|
|
2
3
|
value?: T;
|
|
3
4
|
defaultValue: T;
|
|
4
5
|
onChange?: (v: T) => void;
|
|
5
6
|
};
|
|
6
|
-
export declare function usePropsValue<T>(options: Options<T>): readonly [T, (this: unknown, v: T) => void];
|
|
7
|
+
export declare function usePropsValue<T>(options: Options<T>): readonly [T, (this: unknown, v: SetStateAction<T>) => void];
|
|
7
8
|
export {};
|
|
@@ -23,12 +23,14 @@ function usePropsValue(options) {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
const setState = (0, _ahooks.useMemoizedFn)(v => {
|
|
26
|
+
const nextValue = typeof v === 'function' ? v(stateRef.current) : v;
|
|
27
|
+
|
|
26
28
|
if (value === undefined) {
|
|
27
|
-
stateRef.current =
|
|
29
|
+
stateRef.current = nextValue;
|
|
28
30
|
update();
|
|
29
31
|
}
|
|
30
32
|
|
|
31
|
-
onChange === null || onChange === void 0 ? void 0 : onChange(
|
|
33
|
+
onChange === null || onChange === void 0 ? void 0 : onChange(nextValue);
|
|
32
34
|
});
|
|
33
35
|
return [stateRef.current, setState];
|
|
34
36
|
}
|
|
@@ -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", {
|
|
@@ -30,15 +30,15 @@ export const FloatingBubble = p => {
|
|
|
30
30
|
let nextX = state.offset[0];
|
|
31
31
|
let nextY = state.offset[1];
|
|
32
32
|
|
|
33
|
-
if (state.last) {
|
|
33
|
+
if (state.last && props.magnetic) {
|
|
34
34
|
const boundary = boundaryRef.current;
|
|
35
35
|
const button = buttonRef.current;
|
|
36
36
|
if (!boundary || !button) return;
|
|
37
|
+
const boundaryRect = boundary.getBoundingClientRect();
|
|
38
|
+
const buttonRect = button.getBoundingClientRect();
|
|
37
39
|
|
|
38
40
|
if (props.magnetic === 'x') {
|
|
39
41
|
const compensation = x.goal - x.get();
|
|
40
|
-
const boundaryRect = boundary.getBoundingClientRect();
|
|
41
|
-
const buttonRect = button.getBoundingClientRect();
|
|
42
42
|
const leftDistance = buttonRect.left + compensation - boundaryRect.left;
|
|
43
43
|
const rightDistance = boundaryRect.right - (buttonRect.right + compensation);
|
|
44
44
|
|
|
@@ -47,13 +47,22 @@ export const FloatingBubble = p => {
|
|
|
47
47
|
} else {
|
|
48
48
|
nextX -= leftDistance;
|
|
49
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
|
+
}
|
|
50
60
|
}
|
|
51
61
|
}
|
|
52
62
|
|
|
53
63
|
api.start({
|
|
54
64
|
x: nextX,
|
|
55
|
-
y: nextY
|
|
56
|
-
|
|
65
|
+
y: nextY
|
|
57
66
|
}); // active status
|
|
58
67
|
|
|
59
68
|
api.start({
|
|
@@ -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
|
+
};
|
|
@@ -40,10 +40,14 @@
|
|
|
40
40
|
.adm-form-item-child-position-right > * {
|
|
41
41
|
flex: none;
|
|
42
42
|
}
|
|
43
|
-
.adm-form-item-
|
|
43
|
+
.adm-form-item-feedback-error {
|
|
44
44
|
color: var(--adm-color-danger);
|
|
45
45
|
margin-top: 4px;
|
|
46
46
|
}
|
|
47
|
+
.adm-form-item-feedback-warning {
|
|
48
|
+
color: var(--adm-color-warning);
|
|
49
|
+
margin-top: 4px;
|
|
50
|
+
}
|
|
47
51
|
.adm-form-item.adm-form-item-hidden {
|
|
48
52
|
display: none;
|
|
49
53
|
}
|
|
@@ -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,
|