@opentiny/vue-hooks 2.19.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/LICENSE +22 -0
- package/index.d.ts +14 -0
- package/index.js +2269 -0
- package/package.json +21 -0
- package/src/use-floating.d.ts +90 -0
- package/src/use-lazy-show.d.ts +13 -0
package/package.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@opentiny/vue-hooks",
|
|
3
|
+
"version": "2.19.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"module": "./lib/index.js",
|
|
6
|
+
"main": "./lib/index.js",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"@floating-ui/dom": "^1.6.9",
|
|
12
|
+
"@opentiny/vue-common": "~2.19.0"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [],
|
|
15
|
+
"author": "",
|
|
16
|
+
"license": "ISC",
|
|
17
|
+
"types": "index.d.ts",
|
|
18
|
+
"scripts": {
|
|
19
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { Placement, Strategy, OffsetOptions, RootBoundary, Boundary, ReferenceElement } from '@floating-ui/dom';
|
|
2
|
+
interface IFloatOption {
|
|
3
|
+
reference: null | ReferenceElement;
|
|
4
|
+
popper: null | HTMLElement;
|
|
5
|
+
/** ✅ 是否弹出 */
|
|
6
|
+
show: boolean;
|
|
7
|
+
/** ✅ 是否自动更新位置 */
|
|
8
|
+
autoUpdate: boolean;
|
|
9
|
+
/** ✅ 弹出层定位策略, 【不建议修改】: 'absolute' | 'fixed' https://floating-ui.com/docs/computePosition#strategy */
|
|
10
|
+
strategy: Strategy;
|
|
11
|
+
/** ✅ 默认出现的12个位置 */
|
|
12
|
+
placement: Placement;
|
|
13
|
+
/** ✅ 弹出层偏移量 支持 number | {mainAxis,crossAxis,alignmentAxis}
|
|
14
|
+
* 1、只传入 number, 代表主轴上的偏移。
|
|
15
|
+
* 2、crossAxis,alignmentAxis 都是副轴上的偏移, 区别是:
|
|
16
|
+
* crossAxis 固定向副轴的正方向偏移;
|
|
17
|
+
* alignmentAxis 在副轴上,根据placement的后段决定偏移。
|
|
18
|
+
* 比如 top的副轴为水平方向。 指定alignmentAxis=20的话, top-start时,向右20, top-end时 向左20。
|
|
19
|
+
*/
|
|
20
|
+
offset: OffsetOptions;
|
|
21
|
+
/** ✅ 是否显示箭头 */
|
|
22
|
+
arrowVisible: boolean;
|
|
23
|
+
/** ✅ 溢出的根边界, 取值为: viewport: 可视视口 document: 整个文档区域 或 自定义Rect:{ x,y,width,height} 【不建议切换,不太确定它影响哪些场景】
|
|
24
|
+
* 在floating 内部, 计算所有 [...clippingAncestors, rootBoundary] 的rect 大小
|
|
25
|
+
* 'viewport' 时,访问的是 window.visualViewport, 其 width是不带滚动条的宽度。
|
|
26
|
+
*/
|
|
27
|
+
rootBoundary: RootBoundary;
|
|
28
|
+
/** ✅ 裁剪元素或区域元素。 默认为最近的rel元素。 此处可自定义为某个元素或Rect */
|
|
29
|
+
boundary: Boundary;
|
|
30
|
+
/** ✅ 边界预留padding. 设置后,flip 快到边界时,提前就翻转 */
|
|
31
|
+
boundaryPadding: number;
|
|
32
|
+
/** ✅ 引用元素不可见时,是否自动隐藏。 【需要启用autoUpdate】 */
|
|
33
|
+
syncHide: boolean;
|
|
34
|
+
/** ✅ 元素弹出后,任何重新定位都自动关闭popper, 适用于右键菜单打开后,滚动就或日期组件在滚动时自动关闭。 【需要启用autoUpdate】 */
|
|
35
|
+
autoHide: boolean;
|
|
36
|
+
/** ✅ 是否加速。 加速时,绑定popper的translate属性,否则绑定left/top。 【该属性不建议切换】 */
|
|
37
|
+
gpuAcceleration: boolean;
|
|
38
|
+
/** ✅ 是否动画。 动画的机制简化, 不考虑前个动画未结束时,就开始下个动画的情况。 */
|
|
39
|
+
animate: boolean;
|
|
40
|
+
/** ✅ 动画类名 */
|
|
41
|
+
animateName: string;
|
|
42
|
+
/** ✅ 是否添加到body。【该属性不建议切换】
|
|
43
|
+
* true时, 显示popper时,才body.append; 隐藏时popper.remove。 boundary为 body.
|
|
44
|
+
* false时, 显示popper, 修改style.display='block', 隐藏修改 display:none boundary为 最近的relative元素 */
|
|
45
|
+
appendToBody: boolean;
|
|
46
|
+
/** ✅ 自定义类名,以支持不同的主题色, is-dark is-light 等 , 支持空格分隔的多个类名 */
|
|
47
|
+
customClass: string;
|
|
48
|
+
/** 是否启用flip flip, shift 属性会影响弹层的位置。 在鼠标右击菜单等场景,想固定弹出位置时,可以关闭该属性 */
|
|
49
|
+
flipAble: boolean;
|
|
50
|
+
/** 是否启用shift */
|
|
51
|
+
shiftAble: boolean;
|
|
52
|
+
/** 缓存上次的值。 由于watch state时,取不到oldState的值,所以每次应用后,记录一下 */
|
|
53
|
+
_last: Partial<IFloatOption> & {
|
|
54
|
+
arrowInserted?: boolean;
|
|
55
|
+
arrowEl: HTMLElement;
|
|
56
|
+
timestamp: number;
|
|
57
|
+
};
|
|
58
|
+
/** 缓存用户注册事件
|
|
59
|
+
* show 事件:如果useFloating时,show=true, 那么监听不到第一次show事件。 因为第一次show事件在usFloating内部就已经触发了
|
|
60
|
+
* hide 事件:在动画结束后触发。【是否增加hiding 事件?】
|
|
61
|
+
* update 事件: 每次定位完后触发。 该事件触发频繁,已观察到有以下情况:
|
|
62
|
+
* 在 autoUpdate 时,会频繁触发。 比如切换显示,elementResize /IntersectionObserver 事件发生,内部会进入2次
|
|
63
|
+
* 在reference 不可见时,每一秒会触发一次 update
|
|
64
|
+
* */
|
|
65
|
+
_events: {
|
|
66
|
+
show: Function[];
|
|
67
|
+
hide: Function[];
|
|
68
|
+
update: Function[];
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/** 响应式的弹出层管理函数,适用于场景: tooltip, poppover, select, 右键菜单, floatbar, notify, 或 canvas上跟随鼠标等 */
|
|
72
|
+
export declare const useFloating: (option?: Partial<IFloatOption>) => {
|
|
73
|
+
state: IFloatOption;
|
|
74
|
+
on: (eventName: any, cb: any) => any;
|
|
75
|
+
off: (eventName: any, cb: any) => any;
|
|
76
|
+
virtualEl: (x: number, y: number, w?: number, h?: number) => {
|
|
77
|
+
getBoundingClientRect(): {
|
|
78
|
+
width: number;
|
|
79
|
+
height: number;
|
|
80
|
+
x: number;
|
|
81
|
+
y: number;
|
|
82
|
+
top: number;
|
|
83
|
+
left: number;
|
|
84
|
+
right: number;
|
|
85
|
+
bottom: number;
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
forceUpdate: () => void;
|
|
89
|
+
};
|
|
90
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** 慢加载的 v-show 的办法, 灵感来自于: https://github.com/antfu/v-lazy-show
|
|
2
|
+
* 适用场景: 存在初始加载时,不需要显示的区域,但又需要用v-show切换显示。 比如 tabs\collapse\dropdown\cascader\carousel等
|
|
3
|
+
* @example
|
|
4
|
+
* const isShow = ref(false)
|
|
5
|
+
* const { lazyShow: lazyShowPopper } = useLazyShow(isShow)
|
|
6
|
+
*
|
|
7
|
+
* <div v-if="lazyShowPopper" v-show="isShow">
|
|
8
|
+
* isShow 第一次为true时,才会加载该DOM
|
|
9
|
+
* </div>
|
|
10
|
+
*/
|
|
11
|
+
export declare const useLazyShow: (show: any) => {
|
|
12
|
+
lazyShow: any;
|
|
13
|
+
};
|