@alifd/chat 0.0.1
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/README.md +1 -0
- package/es/button/index.d.ts +1 -0
- package/es/button/index.js +1 -0
- package/es/button/main.scss +0 -0
- package/es/button/style.d.ts +1 -0
- package/es/button/style.js +1 -0
- package/es/button/types.d.ts +123 -0
- package/es/button/types.js +1 -0
- package/es/button/view/button.d.ts +23 -0
- package/es/button/view/button.js +26 -0
- package/es/float-button/hooks/useAutoAlign.d.ts +11 -0
- package/es/float-button/hooks/useAutoAlign.js +45 -0
- package/es/float-button/hooks/useAutoHide.d.ts +15 -0
- package/es/float-button/hooks/useAutoHide.js +157 -0
- package/es/float-button/hooks/useDragable.d.ts +9 -0
- package/es/float-button/hooks/useDragable.js +128 -0
- package/es/float-button/hooks/useNestleEdge.d.ts +13 -0
- package/es/float-button/hooks/useNestleEdge.js +77 -0
- package/es/float-button/index.d.ts +6 -0
- package/es/float-button/index.js +5 -0
- package/es/float-button/main.scss +16 -0
- package/es/float-button/style.d.ts +2 -0
- package/es/float-button/style.js +2 -0
- package/es/float-button/types.d.ts +225 -0
- package/es/float-button/types.js +1 -0
- package/es/float-button/util.d.ts +8 -0
- package/es/float-button/util.js +67 -0
- package/es/float-button/view/backtop.d.ts +4 -0
- package/es/float-button/view/backtop.js +73 -0
- package/es/float-button/view/balloon.d.ts +8 -0
- package/es/float-button/view/balloon.js +12 -0
- package/es/float-button/view/drawer.d.ts +2 -0
- package/es/float-button/view/drawer.js +4 -0
- package/es/float-button/view/float-button.d.ts +4 -0
- package/es/float-button/view/float-button.js +117 -0
- package/es/float-button/view/inner-drawer.d.ts +2 -0
- package/es/float-button/view/inner-drawer.js +4 -0
- package/es/index.d.ts +2 -0
- package/es/index.js +2 -0
- package/es/utils/common.d.ts +2 -0
- package/es/utils/common.js +8 -0
- package/es/utils/func.d.ts +3 -0
- package/es/utils/func.js +30 -0
- package/es/utils/hooks/useControlable.d.ts +6 -0
- package/es/utils/hooks/useControlable.js +27 -0
- package/es/utils/hooks/useDebounce.d.ts +2 -0
- package/es/utils/hooks/useDebounce.js +9 -0
- package/es/utils/hooks/useThrottle.d.ts +2 -0
- package/es/utils/hooks/useThrottle.js +9 -0
- package/es/utils/index.d.ts +6 -0
- package/es/utils/index.js +6 -0
- package/es/utils/types.d.ts +2 -0
- package/es/utils/types.js +1 -0
- package/lib/button/index.d.ts +1 -0
- package/lib/button/index.js +8 -0
- package/lib/button/main.scss +0 -0
- package/lib/button/style.d.ts +1 -0
- package/lib/button/style.js +3 -0
- package/lib/button/types.d.ts +123 -0
- package/lib/button/types.js +2 -0
- package/lib/button/view/button.d.ts +23 -0
- package/lib/button/view/button.js +29 -0
- package/lib/float-button/hooks/useAutoAlign.d.ts +11 -0
- package/lib/float-button/hooks/useAutoAlign.js +49 -0
- package/lib/float-button/hooks/useAutoHide.d.ts +15 -0
- package/lib/float-button/hooks/useAutoHide.js +161 -0
- package/lib/float-button/hooks/useDragable.d.ts +9 -0
- package/lib/float-button/hooks/useDragable.js +132 -0
- package/lib/float-button/hooks/useNestleEdge.d.ts +13 -0
- package/lib/float-button/hooks/useNestleEdge.js +81 -0
- package/lib/float-button/index.d.ts +6 -0
- package/lib/float-button/index.js +8 -0
- package/lib/float-button/main.scss +16 -0
- package/lib/float-button/style.d.ts +2 -0
- package/lib/float-button/style.js +4 -0
- package/lib/float-button/types.d.ts +225 -0
- package/lib/float-button/types.js +2 -0
- package/lib/float-button/util.d.ts +8 -0
- package/lib/float-button/util.js +74 -0
- package/lib/float-button/view/backtop.d.ts +4 -0
- package/lib/float-button/view/backtop.js +76 -0
- package/lib/float-button/view/balloon.d.ts +8 -0
- package/lib/float-button/view/balloon.js +16 -0
- package/lib/float-button/view/drawer.d.ts +2 -0
- package/lib/float-button/view/drawer.js +9 -0
- package/lib/float-button/view/float-button.d.ts +4 -0
- package/lib/float-button/view/float-button.js +119 -0
- package/lib/float-button/view/inner-drawer.d.ts +2 -0
- package/lib/float-button/view/inner-drawer.js +9 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +9 -0
- package/lib/utils/common.d.ts +2 -0
- package/lib/utils/common.js +12 -0
- package/lib/utils/func.d.ts +3 -0
- package/lib/utils/func.js +35 -0
- package/lib/utils/hooks/useControlable.d.ts +6 -0
- package/lib/utils/hooks/useControlable.js +31 -0
- package/lib/utils/hooks/useDebounce.d.ts +2 -0
- package/lib/utils/hooks/useDebounce.js +13 -0
- package/lib/utils/hooks/useThrottle.d.ts +2 -0
- package/lib/utils/hooks/useThrottle.js +13 -0
- package/lib/utils/index.d.ts +6 -0
- package/lib/utils/index.js +13 -0
- package/lib/utils/types.d.ts +2 -0
- package/lib/utils/types.js +2 -0
- package/package.json +103 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useNestleEdge = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const utils_1 = require("../../utils");
|
|
6
|
+
const util_1 = require("../util");
|
|
7
|
+
/**
|
|
8
|
+
* 吸边逻辑
|
|
9
|
+
*/
|
|
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
|
+
const update = (animation = true) => {
|
|
19
|
+
if (!enable || !dom) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const rect = dom.getBoundingClientRect();
|
|
23
|
+
const { left, top, width, height } = rect;
|
|
24
|
+
const { width: screenWidth, height: screenHeight } = (0, util_1.getScreenSize)();
|
|
25
|
+
const [edge] = (0, util_1.getNearlyEdge)(dom, interactiveEdges, rect);
|
|
26
|
+
const position = { left, top };
|
|
27
|
+
switch (edge) {
|
|
28
|
+
case 'top': {
|
|
29
|
+
position.top = 0;
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
case 'right': {
|
|
33
|
+
position.left = screenWidth - width;
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
case 'bottom': {
|
|
37
|
+
position.top = screenHeight - height;
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
case 'left': {
|
|
41
|
+
position.left = 0;
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
// no default
|
|
45
|
+
}
|
|
46
|
+
if (position.left !== left || position.left !== top) {
|
|
47
|
+
const { left, top } = (0, util_1.adjustBySafeAreaMargin)(position, dom.getBoundingClientRect(), safeAreaMargin) ||
|
|
48
|
+
position;
|
|
49
|
+
const shouldContinue = onUpdate === null || onUpdate === void 0 ? void 0 : onUpdate({ left, top });
|
|
50
|
+
if (shouldContinue === false) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
dom.style.left = '0px';
|
|
54
|
+
dom.style.top = '0px';
|
|
55
|
+
if (animation) {
|
|
56
|
+
dom.style.transition = 'transform 0.25s';
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
dom.style.transition = '';
|
|
60
|
+
}
|
|
61
|
+
dom.style.transform = `translate(${left}px, ${top}px)`;
|
|
62
|
+
triggerUpdateEnd({ left, top });
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
const debounceUpdate = (0, utils_1.useDebounce)(() => update(), 100);
|
|
66
|
+
(0, react_1.useEffect)(() => {
|
|
67
|
+
if (dom) {
|
|
68
|
+
update(false);
|
|
69
|
+
}
|
|
70
|
+
}, [dom]);
|
|
71
|
+
(0, react_1.useEffect)(() => {
|
|
72
|
+
window.addEventListener('resize', debounceUpdate);
|
|
73
|
+
return () => {
|
|
74
|
+
window.removeEventListener('resize', debounceUpdate);
|
|
75
|
+
};
|
|
76
|
+
}, []);
|
|
77
|
+
return {
|
|
78
|
+
update,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
exports.useNestleEdge = useNestleEdge;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
declare const FloatButtonWithSub: import("@alifd/next/types/config-provider/types").ConfiguredComponentClass<Pick<import("./types").FloatButtonProps & import("react").RefAttributes<import("./types").FloatButtonRef>, keyof import("./types").FloatButtonProps | "key"> & import("@alifd/next/types/config-provider/types").ComponentCommonProps, import("./types").FloatButtonRef, {}> & {
|
|
3
|
+
Backtop: import("@alifd/next/types/config-provider/types").ConfiguredComponentClass<Pick<import("./types").BacktopProps & import("react").RefAttributes<import("./types").BacktopRef>, "key" | keyof import("./types").BacktopProps> & import("@alifd/next/types/config-provider/types").ComponentCommonProps, import("./types").BacktopRef, {}>;
|
|
4
|
+
};
|
|
5
|
+
export type { BacktopRef, BacktopProps, FloatButtonRef, FloatButtonProps } from './types';
|
|
6
|
+
export default FloatButtonWithSub;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const float_button_1 = tslib_1.__importDefault(require("./view/float-button"));
|
|
5
|
+
const backtop_1 = tslib_1.__importDefault(require("./view/backtop"));
|
|
6
|
+
const index_1 = require("../utils/index");
|
|
7
|
+
const FloatButtonWithSub = (0, index_1.assignSubComponent)(float_button_1.default, { Backtop: backtop_1.default });
|
|
8
|
+
exports.default = FloatButtonWithSub;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
@import '~@alifd/next/variables.scss';
|
|
2
|
+
|
|
3
|
+
.#{$css-prefix}float-button {
|
|
4
|
+
position: fixed;
|
|
5
|
+
z-index: 1001;
|
|
6
|
+
|
|
7
|
+
&-backtop {
|
|
8
|
+
transition: opacity 0.2s, transform 0.2s;
|
|
9
|
+
cursor: pointer;
|
|
10
|
+
|
|
11
|
+
&--hidden {
|
|
12
|
+
opacity: 0;
|
|
13
|
+
transform: scale(0);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
import { type CommonProps } from '@alifd/next';
|
|
3
|
+
import { type BalloonProps } from '@alifd/next/lib/balloon';
|
|
4
|
+
export type { BalloonProps };
|
|
5
|
+
/**
|
|
6
|
+
* @api
|
|
7
|
+
*/
|
|
8
|
+
export type ScreenRatioPosition = [widthRatio: number, heightRatio: number];
|
|
9
|
+
/**
|
|
10
|
+
* @api
|
|
11
|
+
*/
|
|
12
|
+
export type Edge = 'top' | 'right' | 'bottom' | 'left';
|
|
13
|
+
/**
|
|
14
|
+
* @api
|
|
15
|
+
*/
|
|
16
|
+
export type Position = {
|
|
17
|
+
left: number;
|
|
18
|
+
top: number;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* @api
|
|
22
|
+
*/
|
|
23
|
+
export type Size = {
|
|
24
|
+
width: number;
|
|
25
|
+
height: number;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* @api
|
|
29
|
+
*/
|
|
30
|
+
export type Margin = [top: number, right: number, bottom: number, left: number];
|
|
31
|
+
/**
|
|
32
|
+
* 回到顶部组件 ref 对象
|
|
33
|
+
* @api
|
|
34
|
+
* @order 4
|
|
35
|
+
*/
|
|
36
|
+
export interface BacktopRef {
|
|
37
|
+
/**
|
|
38
|
+
* 滚动到顶部
|
|
39
|
+
*/
|
|
40
|
+
backToTop(): void;
|
|
41
|
+
/**
|
|
42
|
+
* 设置是否隐藏
|
|
43
|
+
* @param isHide - 是否隐藏
|
|
44
|
+
* @param force - 强制设置,忽略此时的滚动位置
|
|
45
|
+
*/
|
|
46
|
+
setHide(isHide: boolean, force?: boolean): void;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* 回到顶部组件
|
|
50
|
+
* @api FloatButton.Backtop
|
|
51
|
+
* @order 3
|
|
52
|
+
*/
|
|
53
|
+
export interface BacktopProps extends CommonProps {
|
|
54
|
+
/**
|
|
55
|
+
* 滚动到顶部自动隐藏
|
|
56
|
+
* @defaultValue true
|
|
57
|
+
*/
|
|
58
|
+
autoHide?: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* 内容
|
|
61
|
+
*/
|
|
62
|
+
children: React.ReactNode;
|
|
63
|
+
/**
|
|
64
|
+
* 可触发隐藏的偏移距离 px
|
|
65
|
+
* @defaultValue 10
|
|
66
|
+
*/
|
|
67
|
+
offset?: number;
|
|
68
|
+
/**
|
|
69
|
+
* 滚动节点
|
|
70
|
+
* @defaultValue window
|
|
71
|
+
*/
|
|
72
|
+
scroller?: string | HTMLElement;
|
|
73
|
+
/**
|
|
74
|
+
* 采用平滑滚动
|
|
75
|
+
* @defaultValue true
|
|
76
|
+
*/
|
|
77
|
+
smooth?: boolean;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* 悬浮球组件 ref 对象
|
|
81
|
+
* @api
|
|
82
|
+
* @order 2
|
|
83
|
+
*/
|
|
84
|
+
export interface FloatButtonRef {
|
|
85
|
+
/**
|
|
86
|
+
* 设置是否展示弹窗
|
|
87
|
+
*/
|
|
88
|
+
setVisible(visible: boolean): void;
|
|
89
|
+
/**
|
|
90
|
+
* 根据当前位置更新弹窗的 align 位置
|
|
91
|
+
*/
|
|
92
|
+
updateAlign(): void;
|
|
93
|
+
/**
|
|
94
|
+
* 设置是否隐藏悬浮球
|
|
95
|
+
*/
|
|
96
|
+
setHide(isHide: boolean): void;
|
|
97
|
+
/**
|
|
98
|
+
* 是悬浮球吸附到最近的屏幕边缘
|
|
99
|
+
* @param animation - 是否开启动画,默认为 true
|
|
100
|
+
*/
|
|
101
|
+
updateNestleEdge(animation?: boolean): void;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* @api FloatButton
|
|
105
|
+
* @order 1
|
|
106
|
+
*/
|
|
107
|
+
export interface FloatButtonProps extends CommonProps {
|
|
108
|
+
className?: string;
|
|
109
|
+
style?: React.CSSProperties;
|
|
110
|
+
/**
|
|
111
|
+
* 面板展示类型
|
|
112
|
+
* @defaultValue 'balloon'
|
|
113
|
+
* @example
|
|
114
|
+
* - `balloon`: 悬浮面板
|
|
115
|
+
* - `drawer`: 悬浮侧边抽屉
|
|
116
|
+
* - `inner-drawer`: 文档内部抽屉
|
|
117
|
+
*/
|
|
118
|
+
type?: 'balloon' | 'drawer' | 'inner-drawer';
|
|
119
|
+
/**
|
|
120
|
+
* 弹层位置,适用 `type`: 'balloon'
|
|
121
|
+
*/
|
|
122
|
+
align?: BalloonProps['align'];
|
|
123
|
+
/**
|
|
124
|
+
* 自动设置弹层位置,适用 `type`: 'balloon'
|
|
125
|
+
*/
|
|
126
|
+
autoAlign?: boolean;
|
|
127
|
+
/**
|
|
128
|
+
* 抽屉位置,适用 `type`: 'drawer' | 'inner-drawer'
|
|
129
|
+
*/
|
|
130
|
+
placement?: 'top' | 'right' | 'bottom' | 'left';
|
|
131
|
+
/**
|
|
132
|
+
* 是否显示弹层(受控模式)
|
|
133
|
+
*/
|
|
134
|
+
visible?: boolean;
|
|
135
|
+
/**
|
|
136
|
+
* 是否默认展示弹层(非受控模式)
|
|
137
|
+
*/
|
|
138
|
+
defaultVisible?: boolean;
|
|
139
|
+
/**
|
|
140
|
+
* 弹层展示状态变化事件
|
|
141
|
+
*/
|
|
142
|
+
onVisibleChange?: BalloonProps['onVisibleChange'];
|
|
143
|
+
/**
|
|
144
|
+
* 前置添加内容
|
|
145
|
+
*/
|
|
146
|
+
addonBefore?: React.ReactNode;
|
|
147
|
+
/**
|
|
148
|
+
* 后置添加内容
|
|
149
|
+
*/
|
|
150
|
+
addonAfter?: React.ReactNode;
|
|
151
|
+
/**
|
|
152
|
+
* 是否可拖拽
|
|
153
|
+
*/
|
|
154
|
+
dragable?: boolean;
|
|
155
|
+
/**
|
|
156
|
+
* 拖拽安全区边距
|
|
157
|
+
* @defaultValue [10, 10, 10, 10]
|
|
158
|
+
*/
|
|
159
|
+
safeAreaMargin?: Margin;
|
|
160
|
+
/**
|
|
161
|
+
* 默认位置
|
|
162
|
+
*/
|
|
163
|
+
defaultPosition?: {
|
|
164
|
+
top?: number | string;
|
|
165
|
+
right?: number | string;
|
|
166
|
+
bottom?: number | string;
|
|
167
|
+
left?: number | string;
|
|
168
|
+
} | ScreenRatioPosition;
|
|
169
|
+
/**
|
|
170
|
+
* 是否自动吸附屏幕边缘
|
|
171
|
+
* @defaultValue true
|
|
172
|
+
*/
|
|
173
|
+
autoNestleEdge?: boolean;
|
|
174
|
+
/**
|
|
175
|
+
* 在屏幕边缘时是否自动隐藏
|
|
176
|
+
*/
|
|
177
|
+
autoHide?: boolean;
|
|
178
|
+
/**
|
|
179
|
+
* 隐藏时留在屏幕内的尺寸
|
|
180
|
+
*/
|
|
181
|
+
leftSizeOfHidden?: number;
|
|
182
|
+
/**
|
|
183
|
+
* 可交互的边缘,适用于 autoNestleEdge、autoHide
|
|
184
|
+
* @defaultValue ['left', 'right']
|
|
185
|
+
*/
|
|
186
|
+
interactiveEdges?: Edge[];
|
|
187
|
+
/**
|
|
188
|
+
* 触发节点
|
|
189
|
+
*/
|
|
190
|
+
trigger: NonNullable<BalloonProps['trigger']>;
|
|
191
|
+
/**
|
|
192
|
+
* 隐藏时的触发节点,默认为 trigger
|
|
193
|
+
*/
|
|
194
|
+
hiddenTrigger?: BalloonProps['trigger'];
|
|
195
|
+
/**
|
|
196
|
+
* 触发方式
|
|
197
|
+
* @defaultValue 'click'
|
|
198
|
+
*/
|
|
199
|
+
triggerType?: BalloonProps['triggerType'];
|
|
200
|
+
/**
|
|
201
|
+
* 展示关闭按钮
|
|
202
|
+
* @defaultValue false
|
|
203
|
+
*/
|
|
204
|
+
showClose?: boolean;
|
|
205
|
+
/**
|
|
206
|
+
* 弹层组件其它参数
|
|
207
|
+
*/
|
|
208
|
+
balloonProps?: BalloonProps;
|
|
209
|
+
/**
|
|
210
|
+
* 弹层内容
|
|
211
|
+
*/
|
|
212
|
+
children?: React.ReactNode;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* @api
|
|
216
|
+
* @order 5
|
|
217
|
+
*/
|
|
218
|
+
export interface DragableOption {
|
|
219
|
+
enable?: boolean;
|
|
220
|
+
defaultPosition?: FloatButtonProps['defaultPosition'];
|
|
221
|
+
safeAreaMargin?: Margin;
|
|
222
|
+
onDragBefore?: (dom: HTMLElement) => void;
|
|
223
|
+
onDraging?: (dom: HTMLElement, event: MouseEvent) => void | false;
|
|
224
|
+
onDragend?: (dom: HTMLElement) => void;
|
|
225
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Edge, Margin, Position } from './types';
|
|
2
|
+
export declare function getScreenSize(): {
|
|
3
|
+
width: number;
|
|
4
|
+
height: number;
|
|
5
|
+
};
|
|
6
|
+
export declare function getNearlyEdge(el: HTMLElement, interactiveEdges?: Edge[], rect?: DOMRect): [] | [nearestEdge: Edge, subNearestEdge?: Edge];
|
|
7
|
+
export declare function isInScreen(dom: HTMLElement): boolean;
|
|
8
|
+
export declare function adjustBySafeAreaMargin(position: Position | undefined, rect: DOMRect | null, safeAreaMargin?: Margin): Position | undefined;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.adjustBySafeAreaMargin = exports.isInScreen = exports.getNearlyEdge = exports.getScreenSize = void 0;
|
|
4
|
+
function getScreenSize() {
|
|
5
|
+
return {
|
|
6
|
+
width: document.documentElement.clientWidth,
|
|
7
|
+
height: document.documentElement.clientHeight,
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
exports.getScreenSize = getScreenSize;
|
|
11
|
+
function getNearlyEdge(el, interactiveEdges, rect = el.getBoundingClientRect()) {
|
|
12
|
+
if (!(interactiveEdges === null || interactiveEdges === void 0 ? void 0 : interactiveEdges.length)) {
|
|
13
|
+
return [];
|
|
14
|
+
}
|
|
15
|
+
const edgeSet = new Set(interactiveEdges);
|
|
16
|
+
if (edgeSet.size === 1) {
|
|
17
|
+
return [interactiveEdges[0]];
|
|
18
|
+
}
|
|
19
|
+
const { left, top, width, height } = rect;
|
|
20
|
+
const { width: screenWidth, height: screenHeight } = getScreenSize();
|
|
21
|
+
const edgeItems = [
|
|
22
|
+
{
|
|
23
|
+
edge: 'left',
|
|
24
|
+
size: left + width / 2,
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
edge: 'top',
|
|
28
|
+
size: top + height / 2,
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
edge: 'right',
|
|
32
|
+
size: screenWidth - left - width / 2,
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
edge: 'bottom',
|
|
36
|
+
size: screenHeight - top - height / 2,
|
|
37
|
+
},
|
|
38
|
+
];
|
|
39
|
+
const [closest, subClosest] = edgeItems
|
|
40
|
+
.filter(t => edgeSet.has(t.edge))
|
|
41
|
+
.sort((a, b) => (a.size > b.size ? 1 : -1));
|
|
42
|
+
return [closest.edge, subClosest === null || subClosest === void 0 ? void 0 : subClosest.edge];
|
|
43
|
+
}
|
|
44
|
+
exports.getNearlyEdge = getNearlyEdge;
|
|
45
|
+
function isInScreen(dom) {
|
|
46
|
+
const rect = dom.getBoundingClientRect();
|
|
47
|
+
const { width, height } = getScreenSize();
|
|
48
|
+
const { left, top } = rect;
|
|
49
|
+
const right = width - rect.left - rect.width;
|
|
50
|
+
const bottom = height - rect.top - rect.height;
|
|
51
|
+
return [left, top, right, bottom].every(n => n >= 0);
|
|
52
|
+
}
|
|
53
|
+
exports.isInScreen = isInScreen;
|
|
54
|
+
function adjustBySafeAreaMargin(position, rect, safeAreaMargin) {
|
|
55
|
+
if (!position || !rect || !safeAreaMargin) {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
const [top, right, bottom, left] = safeAreaMargin;
|
|
59
|
+
const { width, height } = getScreenSize();
|
|
60
|
+
const makeInRange = (num, min, max) => {
|
|
61
|
+
if (num < min) {
|
|
62
|
+
return min;
|
|
63
|
+
}
|
|
64
|
+
if (num > max) {
|
|
65
|
+
return max;
|
|
66
|
+
}
|
|
67
|
+
return num;
|
|
68
|
+
};
|
|
69
|
+
return {
|
|
70
|
+
left: makeInRange(position.left, Math.max(0, left), Math.min(width, width - rect.width - right)),
|
|
71
|
+
top: makeInRange(position.top, Math.max(0, top), Math.min(height, height - rect.height - bottom)),
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
exports.adjustBySafeAreaMargin = adjustBySafeAreaMargin;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { BacktopProps, BacktopRef } from '../types';
|
|
3
|
+
declare const _default: import("@alifd/next/types/config-provider/types").ConfiguredComponentClass<Pick<BacktopProps & React.RefAttributes<BacktopRef>, "key" | keyof BacktopProps> & import("@alifd/next/types/config-provider/types").ComponentCommonProps, BacktopRef, {}>;
|
|
4
|
+
export default _default;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const react_1 = tslib_1.__importStar(require("react"));
|
|
5
|
+
const next_1 = require("@alifd/next");
|
|
6
|
+
const classnames_1 = tslib_1.__importDefault(require("classnames"));
|
|
7
|
+
const utils_1 = require("../../utils");
|
|
8
|
+
function getScroller(scroller) {
|
|
9
|
+
if (!scroller) {
|
|
10
|
+
return window;
|
|
11
|
+
}
|
|
12
|
+
if (typeof scroller === 'string') {
|
|
13
|
+
return document.getElementById(scroller);
|
|
14
|
+
}
|
|
15
|
+
return scroller;
|
|
16
|
+
}
|
|
17
|
+
const Backtop = (0, react_1.forwardRef)(({ prefix = 'next-', autoHide = true, scroller, offset = 10, smooth = true, children }, ref) => {
|
|
18
|
+
const [visible, setVisible] = (0, react_1.useState)(true);
|
|
19
|
+
const cls = `${prefix}float-button-backtop`;
|
|
20
|
+
const visibleRef = (0, react_1.useRef)(visible);
|
|
21
|
+
visibleRef.current = visible;
|
|
22
|
+
const handleBackToTop = () => {
|
|
23
|
+
var _a;
|
|
24
|
+
if (!visible) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
(_a = getScroller(scroller)) === null || _a === void 0 ? void 0 : _a.scrollTo({ top: 0, behavior: smooth ? 'smooth' : 'auto' });
|
|
28
|
+
};
|
|
29
|
+
const isAtTop = (el = window) => {
|
|
30
|
+
if (el === window) {
|
|
31
|
+
return el.scrollY <= offset;
|
|
32
|
+
}
|
|
33
|
+
if (el instanceof HTMLElement) {
|
|
34
|
+
return el.scrollTop <= offset;
|
|
35
|
+
}
|
|
36
|
+
return false;
|
|
37
|
+
};
|
|
38
|
+
(0, react_1.useImperativeHandle)(ref, () => ({
|
|
39
|
+
backToTop: handleBackToTop,
|
|
40
|
+
setHide(isHide, force) {
|
|
41
|
+
let vis = !isHide;
|
|
42
|
+
if (!force && vis && isAtTop(getScroller(scroller))) {
|
|
43
|
+
vis = false;
|
|
44
|
+
}
|
|
45
|
+
if (vis !== visible) {
|
|
46
|
+
setVisible(vis);
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
}));
|
|
50
|
+
(0, react_1.useEffect)(() => {
|
|
51
|
+
if (!autoHide) {
|
|
52
|
+
if (!visible) {
|
|
53
|
+
setVisible(true);
|
|
54
|
+
}
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const target = getScroller(scroller);
|
|
58
|
+
if (!target) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const onScroll = (0, utils_1.debounce)(() => {
|
|
62
|
+
if (isAtTop(target)) {
|
|
63
|
+
visibleRef.current && setVisible(false);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
!visibleRef.current && setVisible(true);
|
|
67
|
+
}
|
|
68
|
+
}, 100);
|
|
69
|
+
window.addEventListener('scroll', onScroll);
|
|
70
|
+
return () => {
|
|
71
|
+
target.removeEventListener('scroll', onScroll);
|
|
72
|
+
};
|
|
73
|
+
}, [scroller, autoHide, offset]);
|
|
74
|
+
return (react_1.default.createElement("button", { className: (0, classnames_1.default)(cls, { [`${cls}--hidden`]: !visible }), onClick: handleBackToTop }, children));
|
|
75
|
+
});
|
|
76
|
+
exports.default = next_1.ConfigProvider.config(Backtop);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React, { type ComponentProps } from 'react';
|
|
2
|
+
import { Balloon as NextBalloon } from '@alifd/next';
|
|
3
|
+
export declare function Balloon(props: ComponentProps<typeof NextBalloon> & {
|
|
4
|
+
cls: string;
|
|
5
|
+
triggerEl: HTMLElement | null;
|
|
6
|
+
el: HTMLElement | null;
|
|
7
|
+
autoAlign?: boolean;
|
|
8
|
+
}): React.JSX.Element;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Balloon = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const react_1 = tslib_1.__importDefault(require("react"));
|
|
6
|
+
const next_1 = require("@alifd/next");
|
|
7
|
+
const useAutoAlign_1 = require("../hooks/useAutoAlign");
|
|
8
|
+
function Balloon(props) {
|
|
9
|
+
const { triggerEl, el, autoAlign, align, cls } = props, rests = tslib_1.__rest(props, ["triggerEl", "el", "autoAlign", "align", "cls"]);
|
|
10
|
+
const { align: currentAlign } = (0, useAutoAlign_1.useAutoAlign)(el === null || el === void 0 ? void 0 : el.querySelector(`.${cls}-popup`), triggerEl, {
|
|
11
|
+
enable: autoAlign,
|
|
12
|
+
defaultAlign: align,
|
|
13
|
+
});
|
|
14
|
+
return react_1.default.createElement(next_1.Balloon, Object.assign({}, rests, { align: currentAlign }));
|
|
15
|
+
}
|
|
16
|
+
exports.Balloon = Balloon;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Drawer = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const react_1 = tslib_1.__importDefault(require("react"));
|
|
6
|
+
function Drawer() {
|
|
7
|
+
return (react_1.default.createElement("div", null, "drawer"));
|
|
8
|
+
}
|
|
9
|
+
exports.Drawer = Drawer;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { FloatButtonProps, FloatButtonRef } from '../types';
|
|
3
|
+
declare const _default: import("@alifd/next/types/config-provider/types").ConfiguredComponentClass<Pick<FloatButtonProps & React.RefAttributes<FloatButtonRef>, keyof FloatButtonProps | "key"> & import("@alifd/next/types/config-provider/types").ComponentCommonProps, FloatButtonRef, {}>;
|
|
4
|
+
export default _default;
|