@alifd/chat 0.1.7 → 0.1.9
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/es/float-button/hooks/useAutoHide.js +1 -1
- package/es/float-button/hooks/useNestleEdge.d.ts +3 -3
- package/es/float-button/hooks/useNestleEdge.js +28 -20
- package/es/float-button/types.d.ts +13 -0
- package/es/float-button/util.d.ts +4 -1
- package/es/float-button/view/float-button.js +8 -4
- package/es/float-button/view/inner-drawer.js +17 -15
- package/es/index.js +1 -1
- package/es/utils/hooks/useControlable.js +2 -2
- package/lib/float-button/hooks/useAutoHide.js +1 -1
- package/lib/float-button/hooks/useNestleEdge.d.ts +3 -3
- package/lib/float-button/hooks/useNestleEdge.js +26 -18
- package/lib/float-button/types.d.ts +13 -0
- package/lib/float-button/util.d.ts +4 -1
- package/lib/float-button/view/float-button.js +8 -4
- package/lib/float-button/view/inner-drawer.js +17 -15
- package/lib/index.js +1 -1
- package/lib/utils/hooks/useControlable.js +2 -2
- package/package.json +1 -1
|
@@ -83,7 +83,7 @@ export function useAutoHide(dom, { enable, leftSize, interactiveEdges, }) {
|
|
|
83
83
|
setHide(hide);
|
|
84
84
|
};
|
|
85
85
|
const debounceTriggerHide = useDebounce(triggerHide, 100);
|
|
86
|
-
const throttleSetHideByMouse = useThrottle(setHideByMouse,
|
|
86
|
+
const throttleSetHideByMouse = useThrottle(setHideByMouse, 50);
|
|
87
87
|
const throttleSetHideByApi = useThrottle(setHideByApi, 250);
|
|
88
88
|
useEffect(() => {
|
|
89
89
|
if (!dom) {
|
|
@@ -6,8 +6,8 @@ export declare function useNestleEdge(dom: HTMLElement | null, { enable, safeAre
|
|
|
6
6
|
enable?: boolean;
|
|
7
7
|
safeAreaMargin?: Margin;
|
|
8
8
|
interactiveEdges?: Edge[];
|
|
9
|
-
onUpdate?: (position: Position) => void | false;
|
|
10
|
-
onUpdateEnd?: (position: Position) => void;
|
|
9
|
+
onUpdate?: (position: Position, edge: Edge) => void | false;
|
|
10
|
+
onUpdateEnd?: (position: Position, edge: Edge) => void;
|
|
11
11
|
}): {
|
|
12
|
-
update: (animation?: boolean) => void;
|
|
12
|
+
update: (animation?: boolean | undefined) => void;
|
|
13
13
|
};
|
|
@@ -1,17 +1,10 @@
|
|
|
1
|
-
import { useEffect, useLayoutEffect
|
|
2
|
-
import { useDebounce } from '../../utils';
|
|
1
|
+
import { useEffect, useLayoutEffect } from 'react';
|
|
2
|
+
import { throttle, useDebounce, useThrottle } from '../../utils';
|
|
3
3
|
import { getScreenSize, getNearlyEdge, adjustBySafeAreaMargin } from '../util';
|
|
4
4
|
/**
|
|
5
5
|
* 吸边逻辑
|
|
6
6
|
*/
|
|
7
7
|
export function useNestleEdge(dom, { enable, safeAreaMargin, interactiveEdges, onUpdate, onUpdateEnd, }) {
|
|
8
|
-
const eventTimerRef = useRef();
|
|
9
|
-
const triggerUpdateEnd = (position) => {
|
|
10
|
-
clearTimeout(eventTimerRef.current);
|
|
11
|
-
eventTimerRef.current = setTimeout(() => {
|
|
12
|
-
onUpdateEnd === null || onUpdateEnd === void 0 ? void 0 : onUpdateEnd(position);
|
|
13
|
-
}, 300);
|
|
14
|
-
};
|
|
15
8
|
const update = (animation = true) => {
|
|
16
9
|
if (!enable || !dom) {
|
|
17
10
|
return;
|
|
@@ -20,7 +13,7 @@ export function useNestleEdge(dom, { enable, safeAreaMargin, interactiveEdges, o
|
|
|
20
13
|
const { left, top, width, height } = rect;
|
|
21
14
|
const { width: screenWidth, height: screenHeight } = getScreenSize();
|
|
22
15
|
const [edge] = getNearlyEdge(dom, interactiveEdges, rect);
|
|
23
|
-
|
|
16
|
+
let position = { left, top };
|
|
24
17
|
switch (edge) {
|
|
25
18
|
case 'top': {
|
|
26
19
|
position.top = 0;
|
|
@@ -38,30 +31,45 @@ export function useNestleEdge(dom, { enable, safeAreaMargin, interactiveEdges, o
|
|
|
38
31
|
position.left = 0;
|
|
39
32
|
break;
|
|
40
33
|
}
|
|
41
|
-
|
|
34
|
+
default: {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
42
37
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const shouldContinue = onUpdate === null || onUpdate === void 0 ? void 0 : onUpdate({ left, top });
|
|
47
|
-
if (shouldContinue === false) {
|
|
38
|
+
position = adjustBySafeAreaMargin(position, { width, height }, safeAreaMargin) || position;
|
|
39
|
+
if (position.left !== left || position.top !== top) {
|
|
40
|
+
if ((onUpdate === null || onUpdate === void 0 ? void 0 : onUpdate(position, edge)) === false) {
|
|
48
41
|
return;
|
|
49
42
|
}
|
|
50
43
|
dom.style.left = '0px';
|
|
51
44
|
dom.style.top = '0px';
|
|
52
45
|
if (animation) {
|
|
53
46
|
dom.style.transition = 'transform 0.25s';
|
|
47
|
+
let isRemoved = false;
|
|
48
|
+
const onEnd = throttle(() => {
|
|
49
|
+
onUpdateEnd === null || onUpdateEnd === void 0 ? void 0 : onUpdateEnd(position, edge);
|
|
50
|
+
dom.removeEventListener('transitionend', onEnd);
|
|
51
|
+
isRemoved = true;
|
|
52
|
+
}, 10);
|
|
53
|
+
dom.addEventListener('transitionend', onEnd);
|
|
54
|
+
// 超时 500ms 移除监听
|
|
55
|
+
setTimeout(() => {
|
|
56
|
+
if (!isRemoved) {
|
|
57
|
+
dom.removeEventListener('transitionend', onEnd);
|
|
58
|
+
}
|
|
59
|
+
}, 500);
|
|
60
|
+
dom.style.transform = `translate(${position.left}px, ${position.top}px)`;
|
|
54
61
|
}
|
|
55
62
|
else {
|
|
56
63
|
dom.style.transition = '';
|
|
64
|
+
dom.style.transform = `translate(${position.left}px, ${position.top}px)`;
|
|
65
|
+
onUpdateEnd === null || onUpdateEnd === void 0 ? void 0 : onUpdateEnd(position, edge);
|
|
57
66
|
}
|
|
58
|
-
dom.style.transform = `translate(${left}px, ${top}px)`;
|
|
59
|
-
triggerUpdateEnd({ left, top });
|
|
60
67
|
}
|
|
61
68
|
};
|
|
62
69
|
const debounceUpdate = useDebounce(() => update(), 100);
|
|
70
|
+
const throttleUpdate = useThrottle(update, 16);
|
|
63
71
|
useLayoutEffect(() => {
|
|
64
|
-
|
|
72
|
+
throttleUpdate(false);
|
|
65
73
|
});
|
|
66
74
|
useEffect(() => {
|
|
67
75
|
window.addEventListener('resize', debounceUpdate);
|
|
@@ -70,6 +78,6 @@ export function useNestleEdge(dom, { enable, safeAreaMargin, interactiveEdges, o
|
|
|
70
78
|
};
|
|
71
79
|
}, []);
|
|
72
80
|
return {
|
|
73
|
-
update,
|
|
81
|
+
update: throttleUpdate,
|
|
74
82
|
};
|
|
75
83
|
}
|
|
@@ -164,6 +164,19 @@ export interface FloatButtonProps extends CommonProps {
|
|
|
164
164
|
* @defaultValue true
|
|
165
165
|
*/
|
|
166
166
|
autoNestleEdge?: boolean;
|
|
167
|
+
/**
|
|
168
|
+
* 当触发边缘吸附前的回调
|
|
169
|
+
* @param position - 吸附位置
|
|
170
|
+
* @param edge - 吸附的边
|
|
171
|
+
* @returns false 则不允许吸附
|
|
172
|
+
*/
|
|
173
|
+
beforeNestleEdge?: (position: Position, edge: Edge) => false | void;
|
|
174
|
+
/**
|
|
175
|
+
* 吸附到边缘后的回调
|
|
176
|
+
* @param position - 吸附位置
|
|
177
|
+
* @param edge - 吸附的边
|
|
178
|
+
*/
|
|
179
|
+
afterNestleEdge?: (position: Position, edge: Edge) => void;
|
|
167
180
|
/**
|
|
168
181
|
* 在屏幕边缘时是否自动隐藏
|
|
169
182
|
*/
|
|
@@ -5,4 +5,7 @@ export declare function getScreenSize(): {
|
|
|
5
5
|
};
|
|
6
6
|
export declare function getNearlyEdge(el: HTMLElement, interactiveEdges?: Edge[], rect?: DOMRect): [] | [nearestEdge: Edge, subNearestEdge?: Edge];
|
|
7
7
|
export declare function isInScreen(dom: HTMLElement): boolean;
|
|
8
|
-
export declare function adjustBySafeAreaMargin(position: Position | undefined, rect:
|
|
8
|
+
export declare function adjustBySafeAreaMargin(position: Position | undefined, rect: {
|
|
9
|
+
width: number;
|
|
10
|
+
height: number;
|
|
11
|
+
} | null, safeAreaMargin?: Margin): Position | undefined;
|
|
@@ -27,7 +27,7 @@ import { useDragable } from '../hooks/useDragable';
|
|
|
27
27
|
* | SPACE | Trigger the onClick event |
|
|
28
28
|
*/
|
|
29
29
|
const FloatButton = forwardRef((props, ref) => {
|
|
30
|
-
const { className, style, addonAfter, addonBefore, dragable, safeAreaMargin = [10, 10, 10, 10], autoNestleEdge = true, interactiveEdges = ['left', 'right'], autoHide, autoAlign, leftSizeOfHidden, defaultPosition, trigger, triggerType = 'click', showClose = false, align, balloonProps, children, _renderView } = props, others = __rest(props, ["className", "style", "addonAfter", "addonBefore", "dragable", "safeAreaMargin", "autoNestleEdge", "interactiveEdges", "autoHide", "autoAlign", "leftSizeOfHidden", "defaultPosition", "trigger", "triggerType", "showClose", "align", "balloonProps", "children", "_renderView"]);
|
|
30
|
+
const { className, style, addonAfter, addonBefore, dragable, safeAreaMargin = [10, 10, 10, 10], autoNestleEdge = true, interactiveEdges = ['left', 'right'], autoHide, autoAlign, leftSizeOfHidden, defaultPosition, trigger, triggerType = 'click', showClose = false, align, balloonProps, children, _renderView, beforeNestleEdge, afterNestleEdge } = props, others = __rest(props, ["className", "style", "addonAfter", "addonBefore", "dragable", "safeAreaMargin", "autoNestleEdge", "interactiveEdges", "autoHide", "autoAlign", "leftSizeOfHidden", "defaultPosition", "trigger", "triggerType", "showClose", "align", "balloonProps", "children", "_renderView", "beforeNestleEdge", "afterNestleEdge"]);
|
|
31
31
|
const elRef = useRef(null);
|
|
32
32
|
const triggerRef = useRef(null);
|
|
33
33
|
const [el, setEl] = useState(null);
|
|
@@ -63,14 +63,18 @@ const FloatButton = forwardRef((props, ref) => {
|
|
|
63
63
|
enable: !!autoNestleEdge,
|
|
64
64
|
safeAreaMargin,
|
|
65
65
|
interactiveEdges,
|
|
66
|
-
onUpdate(position) {
|
|
66
|
+
onUpdate(position, edge) {
|
|
67
67
|
if (isHideRef.current) {
|
|
68
68
|
saveRestorePosition(position);
|
|
69
69
|
return false;
|
|
70
70
|
}
|
|
71
|
+
if ((beforeNestleEdge === null || beforeNestleEdge === void 0 ? void 0 : beforeNestleEdge(position, edge)) === false) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
71
74
|
},
|
|
72
|
-
onUpdateEnd() {
|
|
75
|
+
onUpdateEnd(position, edge) {
|
|
73
76
|
updateAlign();
|
|
77
|
+
afterNestleEdge === null || afterNestleEdge === void 0 ? void 0 : afterNestleEdge(position, edge);
|
|
74
78
|
},
|
|
75
79
|
});
|
|
76
80
|
useImperativeHandle(ref, () => ({
|
|
@@ -100,7 +104,7 @@ const FloatButton = forwardRef((props, ref) => {
|
|
|
100
104
|
},
|
|
101
105
|
onDragend() {
|
|
102
106
|
if (!isHideRef.current) {
|
|
103
|
-
|
|
107
|
+
updateNestleEdge();
|
|
104
108
|
}
|
|
105
109
|
},
|
|
106
110
|
});
|
|
@@ -101,6 +101,21 @@ export function InnerDrawer({ className, prefix, target, children, trigger, trig
|
|
|
101
101
|
const handlers = useTriggerType({ visible, onVisibleChange: handleVisibleChange, triggerType });
|
|
102
102
|
const domRef = useRef(null);
|
|
103
103
|
const triggerRef = useRef(null);
|
|
104
|
+
useEffect(() => {
|
|
105
|
+
if (!mountTarget) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
const onEnd = (e) => {
|
|
109
|
+
if (e.target === mountTarget && e.propertyName === 'width') {
|
|
110
|
+
const { visible, afterClose, afterOpen } = propsRef.current;
|
|
111
|
+
visible ? afterOpen === null || afterOpen === void 0 ? void 0 : afterOpen() : afterClose === null || afterClose === void 0 ? void 0 : afterClose();
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
mountTarget.addEventListener('transitionend', onEnd);
|
|
115
|
+
return () => {
|
|
116
|
+
mountTarget.removeEventListener('transitionend', onEnd);
|
|
117
|
+
};
|
|
118
|
+
}, [mountTarget]);
|
|
104
119
|
useEffect(() => {
|
|
105
120
|
if (!mountTarget) {
|
|
106
121
|
return;
|
|
@@ -108,6 +123,7 @@ export function InnerDrawer({ className, prefix, target, children, trigger, trig
|
|
|
108
123
|
if (visible) {
|
|
109
124
|
beforeOpen === null || beforeOpen === void 0 ? void 0 : beforeOpen();
|
|
110
125
|
const id = requestAnimationFrame(() => {
|
|
126
|
+
mountTarget.style.transition = 'width 0.3s,opacity 0.3s';
|
|
111
127
|
mountTarget.style.width = `${typeof width === 'number' ? `${width}px` : width}`;
|
|
112
128
|
mountTarget.style.opacity = '1';
|
|
113
129
|
});
|
|
@@ -117,25 +133,11 @@ export function InnerDrawer({ className, prefix, target, children, trigger, trig
|
|
|
117
133
|
}
|
|
118
134
|
else {
|
|
119
135
|
beforeClose === null || beforeClose === void 0 ? void 0 : beforeClose();
|
|
136
|
+
mountTarget.style.transition = 'width 0.3s,opacity 0.3s';
|
|
120
137
|
mountTarget.style.width = `0px`;
|
|
121
138
|
mountTarget.style.opacity = '0';
|
|
122
139
|
}
|
|
123
140
|
}, [visible, mountTarget]);
|
|
124
|
-
useEffect(() => {
|
|
125
|
-
if (!mountTarget) {
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
const onEnd = (e) => {
|
|
129
|
-
if (e.target === mountTarget && e.propertyName === 'width') {
|
|
130
|
-
const { visible, afterClose, afterOpen } = propsRef.current;
|
|
131
|
-
visible ? afterOpen === null || afterOpen === void 0 ? void 0 : afterOpen() : afterClose === null || afterClose === void 0 ? void 0 : afterClose();
|
|
132
|
-
}
|
|
133
|
-
};
|
|
134
|
-
mountTarget.addEventListener('transitionend', onEnd);
|
|
135
|
-
return () => {
|
|
136
|
-
mountTarget.removeEventListener('transitionend', onEnd);
|
|
137
|
-
};
|
|
138
|
-
}, [mountTarget]);
|
|
139
141
|
useEffect(() => {
|
|
140
142
|
if (!mountTarget || !className) {
|
|
141
143
|
return;
|
package/es/index.js
CHANGED
|
@@ -20,9 +20,9 @@ export function useControlable(props, { valueName = 'value', defaultValueName =
|
|
|
20
20
|
}
|
|
21
21
|
};
|
|
22
22
|
useEffect(() => {
|
|
23
|
-
if (value !== propValue) {
|
|
23
|
+
if (isControl && value !== propValue) {
|
|
24
24
|
setValue(() => propValue);
|
|
25
25
|
}
|
|
26
|
-
}, [propValue]);
|
|
26
|
+
}, [propValue, isControl]);
|
|
27
27
|
return [value, handleChange];
|
|
28
28
|
}
|
|
@@ -86,7 +86,7 @@ function useAutoHide(dom, { enable, leftSize, interactiveEdges, }) {
|
|
|
86
86
|
setHide(hide);
|
|
87
87
|
};
|
|
88
88
|
const debounceTriggerHide = (0, utils_1.useDebounce)(triggerHide, 100);
|
|
89
|
-
const throttleSetHideByMouse = (0, utils_1.useThrottle)(setHideByMouse,
|
|
89
|
+
const throttleSetHideByMouse = (0, utils_1.useThrottle)(setHideByMouse, 50);
|
|
90
90
|
const throttleSetHideByApi = (0, utils_1.useThrottle)(setHideByApi, 250);
|
|
91
91
|
(0, react_1.useEffect)(() => {
|
|
92
92
|
if (!dom) {
|
|
@@ -6,8 +6,8 @@ export declare function useNestleEdge(dom: HTMLElement | null, { enable, safeAre
|
|
|
6
6
|
enable?: boolean;
|
|
7
7
|
safeAreaMargin?: Margin;
|
|
8
8
|
interactiveEdges?: Edge[];
|
|
9
|
-
onUpdate?: (position: Position) => void | false;
|
|
10
|
-
onUpdateEnd?: (position: Position) => void;
|
|
9
|
+
onUpdate?: (position: Position, edge: Edge) => void | false;
|
|
10
|
+
onUpdateEnd?: (position: Position, edge: Edge) => void;
|
|
11
11
|
}): {
|
|
12
|
-
update: (animation?: boolean) => void;
|
|
12
|
+
update: (animation?: boolean | undefined) => void;
|
|
13
13
|
};
|
|
@@ -8,13 +8,6 @@ const util_1 = require("../util");
|
|
|
8
8
|
* 吸边逻辑
|
|
9
9
|
*/
|
|
10
10
|
function useNestleEdge(dom, { enable, safeAreaMargin, interactiveEdges, onUpdate, onUpdateEnd, }) {
|
|
11
|
-
const eventTimerRef = (0, react_1.useRef)();
|
|
12
|
-
const triggerUpdateEnd = (position) => {
|
|
13
|
-
clearTimeout(eventTimerRef.current);
|
|
14
|
-
eventTimerRef.current = setTimeout(() => {
|
|
15
|
-
onUpdateEnd === null || onUpdateEnd === void 0 ? void 0 : onUpdateEnd(position);
|
|
16
|
-
}, 300);
|
|
17
|
-
};
|
|
18
11
|
const update = (animation = true) => {
|
|
19
12
|
if (!enable || !dom) {
|
|
20
13
|
return;
|
|
@@ -23,7 +16,7 @@ function useNestleEdge(dom, { enable, safeAreaMargin, interactiveEdges, onUpdate
|
|
|
23
16
|
const { left, top, width, height } = rect;
|
|
24
17
|
const { width: screenWidth, height: screenHeight } = (0, util_1.getScreenSize)();
|
|
25
18
|
const [edge] = (0, util_1.getNearlyEdge)(dom, interactiveEdges, rect);
|
|
26
|
-
|
|
19
|
+
let position = { left, top };
|
|
27
20
|
switch (edge) {
|
|
28
21
|
case 'top': {
|
|
29
22
|
position.top = 0;
|
|
@@ -41,30 +34,45 @@ function useNestleEdge(dom, { enable, safeAreaMargin, interactiveEdges, onUpdate
|
|
|
41
34
|
position.left = 0;
|
|
42
35
|
break;
|
|
43
36
|
}
|
|
44
|
-
|
|
37
|
+
default: {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
45
40
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const shouldContinue = onUpdate === null || onUpdate === void 0 ? void 0 : onUpdate({ left, top });
|
|
50
|
-
if (shouldContinue === false) {
|
|
41
|
+
position = (0, util_1.adjustBySafeAreaMargin)(position, { width, height }, safeAreaMargin) || position;
|
|
42
|
+
if (position.left !== left || position.top !== top) {
|
|
43
|
+
if ((onUpdate === null || onUpdate === void 0 ? void 0 : onUpdate(position, edge)) === false) {
|
|
51
44
|
return;
|
|
52
45
|
}
|
|
53
46
|
dom.style.left = '0px';
|
|
54
47
|
dom.style.top = '0px';
|
|
55
48
|
if (animation) {
|
|
56
49
|
dom.style.transition = 'transform 0.25s';
|
|
50
|
+
let isRemoved = false;
|
|
51
|
+
const onEnd = (0, utils_1.throttle)(() => {
|
|
52
|
+
onUpdateEnd === null || onUpdateEnd === void 0 ? void 0 : onUpdateEnd(position, edge);
|
|
53
|
+
dom.removeEventListener('transitionend', onEnd);
|
|
54
|
+
isRemoved = true;
|
|
55
|
+
}, 10);
|
|
56
|
+
dom.addEventListener('transitionend', onEnd);
|
|
57
|
+
// 超时 500ms 移除监听
|
|
58
|
+
setTimeout(() => {
|
|
59
|
+
if (!isRemoved) {
|
|
60
|
+
dom.removeEventListener('transitionend', onEnd);
|
|
61
|
+
}
|
|
62
|
+
}, 500);
|
|
63
|
+
dom.style.transform = `translate(${position.left}px, ${position.top}px)`;
|
|
57
64
|
}
|
|
58
65
|
else {
|
|
59
66
|
dom.style.transition = '';
|
|
67
|
+
dom.style.transform = `translate(${position.left}px, ${position.top}px)`;
|
|
68
|
+
onUpdateEnd === null || onUpdateEnd === void 0 ? void 0 : onUpdateEnd(position, edge);
|
|
60
69
|
}
|
|
61
|
-
dom.style.transform = `translate(${left}px, ${top}px)`;
|
|
62
|
-
triggerUpdateEnd({ left, top });
|
|
63
70
|
}
|
|
64
71
|
};
|
|
65
72
|
const debounceUpdate = (0, utils_1.useDebounce)(() => update(), 100);
|
|
73
|
+
const throttleUpdate = (0, utils_1.useThrottle)(update, 16);
|
|
66
74
|
(0, react_1.useLayoutEffect)(() => {
|
|
67
|
-
|
|
75
|
+
throttleUpdate(false);
|
|
68
76
|
});
|
|
69
77
|
(0, react_1.useEffect)(() => {
|
|
70
78
|
window.addEventListener('resize', debounceUpdate);
|
|
@@ -73,7 +81,7 @@ function useNestleEdge(dom, { enable, safeAreaMargin, interactiveEdges, onUpdate
|
|
|
73
81
|
};
|
|
74
82
|
}, []);
|
|
75
83
|
return {
|
|
76
|
-
update,
|
|
84
|
+
update: throttleUpdate,
|
|
77
85
|
};
|
|
78
86
|
}
|
|
79
87
|
exports.useNestleEdge = useNestleEdge;
|
|
@@ -164,6 +164,19 @@ export interface FloatButtonProps extends CommonProps {
|
|
|
164
164
|
* @defaultValue true
|
|
165
165
|
*/
|
|
166
166
|
autoNestleEdge?: boolean;
|
|
167
|
+
/**
|
|
168
|
+
* 当触发边缘吸附前的回调
|
|
169
|
+
* @param position - 吸附位置
|
|
170
|
+
* @param edge - 吸附的边
|
|
171
|
+
* @returns false 则不允许吸附
|
|
172
|
+
*/
|
|
173
|
+
beforeNestleEdge?: (position: Position, edge: Edge) => false | void;
|
|
174
|
+
/**
|
|
175
|
+
* 吸附到边缘后的回调
|
|
176
|
+
* @param position - 吸附位置
|
|
177
|
+
* @param edge - 吸附的边
|
|
178
|
+
*/
|
|
179
|
+
afterNestleEdge?: (position: Position, edge: Edge) => void;
|
|
167
180
|
/**
|
|
168
181
|
* 在屏幕边缘时是否自动隐藏
|
|
169
182
|
*/
|
|
@@ -5,4 +5,7 @@ export declare function getScreenSize(): {
|
|
|
5
5
|
};
|
|
6
6
|
export declare function getNearlyEdge(el: HTMLElement, interactiveEdges?: Edge[], rect?: DOMRect): [] | [nearestEdge: Edge, subNearestEdge?: Edge];
|
|
7
7
|
export declare function isInScreen(dom: HTMLElement): boolean;
|
|
8
|
-
export declare function adjustBySafeAreaMargin(position: Position | undefined, rect:
|
|
8
|
+
export declare function adjustBySafeAreaMargin(position: Position | undefined, rect: {
|
|
9
|
+
width: number;
|
|
10
|
+
height: number;
|
|
11
|
+
} | null, safeAreaMargin?: Margin): Position | undefined;
|
|
@@ -29,7 +29,7 @@ const useDragable_1 = require("../hooks/useDragable");
|
|
|
29
29
|
* | SPACE | Trigger the onClick event |
|
|
30
30
|
*/
|
|
31
31
|
const FloatButton = (0, react_1.forwardRef)((props, ref) => {
|
|
32
|
-
const { className, style, addonAfter, addonBefore, dragable, safeAreaMargin = [10, 10, 10, 10], autoNestleEdge = true, interactiveEdges = ['left', 'right'], autoHide, autoAlign, leftSizeOfHidden, defaultPosition, trigger, triggerType = 'click', showClose = false, align, balloonProps, children, _renderView } = props, others = tslib_1.__rest(props, ["className", "style", "addonAfter", "addonBefore", "dragable", "safeAreaMargin", "autoNestleEdge", "interactiveEdges", "autoHide", "autoAlign", "leftSizeOfHidden", "defaultPosition", "trigger", "triggerType", "showClose", "align", "balloonProps", "children", "_renderView"]);
|
|
32
|
+
const { className, style, addonAfter, addonBefore, dragable, safeAreaMargin = [10, 10, 10, 10], autoNestleEdge = true, interactiveEdges = ['left', 'right'], autoHide, autoAlign, leftSizeOfHidden, defaultPosition, trigger, triggerType = 'click', showClose = false, align, balloonProps, children, _renderView, beforeNestleEdge, afterNestleEdge } = props, others = tslib_1.__rest(props, ["className", "style", "addonAfter", "addonBefore", "dragable", "safeAreaMargin", "autoNestleEdge", "interactiveEdges", "autoHide", "autoAlign", "leftSizeOfHidden", "defaultPosition", "trigger", "triggerType", "showClose", "align", "balloonProps", "children", "_renderView", "beforeNestleEdge", "afterNestleEdge"]);
|
|
33
33
|
const elRef = (0, react_1.useRef)(null);
|
|
34
34
|
const triggerRef = (0, react_1.useRef)(null);
|
|
35
35
|
const [el, setEl] = (0, react_1.useState)(null);
|
|
@@ -65,14 +65,18 @@ const FloatButton = (0, react_1.forwardRef)((props, ref) => {
|
|
|
65
65
|
enable: !!autoNestleEdge,
|
|
66
66
|
safeAreaMargin,
|
|
67
67
|
interactiveEdges,
|
|
68
|
-
onUpdate(position) {
|
|
68
|
+
onUpdate(position, edge) {
|
|
69
69
|
if (isHideRef.current) {
|
|
70
70
|
saveRestorePosition(position);
|
|
71
71
|
return false;
|
|
72
72
|
}
|
|
73
|
+
if ((beforeNestleEdge === null || beforeNestleEdge === void 0 ? void 0 : beforeNestleEdge(position, edge)) === false) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
73
76
|
},
|
|
74
|
-
onUpdateEnd() {
|
|
77
|
+
onUpdateEnd(position, edge) {
|
|
75
78
|
updateAlign();
|
|
79
|
+
afterNestleEdge === null || afterNestleEdge === void 0 ? void 0 : afterNestleEdge(position, edge);
|
|
76
80
|
},
|
|
77
81
|
});
|
|
78
82
|
(0, react_1.useImperativeHandle)(ref, () => ({
|
|
@@ -102,7 +106,7 @@ const FloatButton = (0, react_1.forwardRef)((props, ref) => {
|
|
|
102
106
|
},
|
|
103
107
|
onDragend() {
|
|
104
108
|
if (!isHideRef.current) {
|
|
105
|
-
|
|
109
|
+
updateNestleEdge();
|
|
106
110
|
}
|
|
107
111
|
},
|
|
108
112
|
});
|
|
@@ -104,6 +104,21 @@ function InnerDrawer({ className, prefix, target, children, trigger, triggerType
|
|
|
104
104
|
const handlers = (0, useTriggerType_1.useTriggerType)({ visible, onVisibleChange: handleVisibleChange, triggerType });
|
|
105
105
|
const domRef = (0, react_1.useRef)(null);
|
|
106
106
|
const triggerRef = (0, react_1.useRef)(null);
|
|
107
|
+
(0, react_1.useEffect)(() => {
|
|
108
|
+
if (!mountTarget) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const onEnd = (e) => {
|
|
112
|
+
if (e.target === mountTarget && e.propertyName === 'width') {
|
|
113
|
+
const { visible, afterClose, afterOpen } = propsRef.current;
|
|
114
|
+
visible ? afterOpen === null || afterOpen === void 0 ? void 0 : afterOpen() : afterClose === null || afterClose === void 0 ? void 0 : afterClose();
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
mountTarget.addEventListener('transitionend', onEnd);
|
|
118
|
+
return () => {
|
|
119
|
+
mountTarget.removeEventListener('transitionend', onEnd);
|
|
120
|
+
};
|
|
121
|
+
}, [mountTarget]);
|
|
107
122
|
(0, react_1.useEffect)(() => {
|
|
108
123
|
if (!mountTarget) {
|
|
109
124
|
return;
|
|
@@ -111,6 +126,7 @@ function InnerDrawer({ className, prefix, target, children, trigger, triggerType
|
|
|
111
126
|
if (visible) {
|
|
112
127
|
beforeOpen === null || beforeOpen === void 0 ? void 0 : beforeOpen();
|
|
113
128
|
const id = requestAnimationFrame(() => {
|
|
129
|
+
mountTarget.style.transition = 'width 0.3s,opacity 0.3s';
|
|
114
130
|
mountTarget.style.width = `${typeof width === 'number' ? `${width}px` : width}`;
|
|
115
131
|
mountTarget.style.opacity = '1';
|
|
116
132
|
});
|
|
@@ -120,25 +136,11 @@ function InnerDrawer({ className, prefix, target, children, trigger, triggerType
|
|
|
120
136
|
}
|
|
121
137
|
else {
|
|
122
138
|
beforeClose === null || beforeClose === void 0 ? void 0 : beforeClose();
|
|
139
|
+
mountTarget.style.transition = 'width 0.3s,opacity 0.3s';
|
|
123
140
|
mountTarget.style.width = `0px`;
|
|
124
141
|
mountTarget.style.opacity = '0';
|
|
125
142
|
}
|
|
126
143
|
}, [visible, mountTarget]);
|
|
127
|
-
(0, react_1.useEffect)(() => {
|
|
128
|
-
if (!mountTarget) {
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
const onEnd = (e) => {
|
|
132
|
-
if (e.target === mountTarget && e.propertyName === 'width') {
|
|
133
|
-
const { visible, afterClose, afterOpen } = propsRef.current;
|
|
134
|
-
visible ? afterOpen === null || afterOpen === void 0 ? void 0 : afterOpen() : afterClose === null || afterClose === void 0 ? void 0 : afterClose();
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
mountTarget.addEventListener('transitionend', onEnd);
|
|
138
|
-
return () => {
|
|
139
|
-
mountTarget.removeEventListener('transitionend', onEnd);
|
|
140
|
-
};
|
|
141
|
-
}, [mountTarget]);
|
|
142
144
|
(0, react_1.useEffect)(() => {
|
|
143
145
|
if (!mountTarget || !className) {
|
|
144
146
|
return;
|
package/lib/index.js
CHANGED
|
@@ -18,4 +18,4 @@ var tag_1 = require("./tag");
|
|
|
18
18
|
Object.defineProperty(exports, "Tag", { enumerable: true, get: function () { return __importDefault(tag_1).default; } });
|
|
19
19
|
var tab_1 = require("./tab");
|
|
20
20
|
Object.defineProperty(exports, "Tab", { enumerable: true, get: function () { return __importDefault(tab_1).default; } });
|
|
21
|
-
exports.version = '0.1.
|
|
21
|
+
exports.version = '0.1.9';
|
|
@@ -23,10 +23,10 @@ function useControlable(props, { valueName = 'value', defaultValueName = getDefa
|
|
|
23
23
|
}
|
|
24
24
|
};
|
|
25
25
|
(0, react_1.useEffect)(() => {
|
|
26
|
-
if (value !== propValue) {
|
|
26
|
+
if (isControl && value !== propValue) {
|
|
27
27
|
setValue(() => propValue);
|
|
28
28
|
}
|
|
29
|
-
}, [propValue]);
|
|
29
|
+
}, [propValue, isControl]);
|
|
30
30
|
return [value, handleChange];
|
|
31
31
|
}
|
|
32
32
|
exports.useControlable = useControlable;
|