@opentiny/vue-hooks 3.21.0 → 3.22.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/README.md +3 -0
- package/README.zh-CN.md +3 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +24 -0
- package/{src → dist/src}/use-floating.d.ts +7 -2
- package/dist/src/use-floating.js +141 -0
- package/{src → dist/src}/use-lazy-show.d.ts +6 -3
- package/dist/src/use-lazy-show.js +10 -0
- package/dist/src/useEventListener.d.ts +15 -0
- package/dist/src/useEventListener.js +31 -0
- package/dist/src/useInstanceSlots.d.ts +6 -0
- package/dist/src/useInstanceSlots.js +14 -0
- package/dist/src/useRect.d.ts +1 -0
- package/dist/src/useRect.js +18 -0
- package/dist/src/useRelation.d.ts +31 -0
- package/dist/src/useRelation.js +54 -0
- package/dist/src/useTouch.d.ts +15 -0
- package/dist/src/useTouch.js +32 -0
- package/dist/src/useUserAgent.d.ts +3 -0
- package/dist/src/useUserAgent.js +10 -0
- package/dist/src/useWindowSize.d.ts +4 -0
- package/dist/src/useWindowSize.js +14 -0
- package/{index.d.ts → dist/src/vue-emitter.d.ts} +5 -3
- package/dist/src/vue-popper.js +85 -0
- package/dist/src/vue-popup.d.ts +18 -0
- package/dist/src/vue-popup.js +69 -0
- package/index.ts +23 -0
- package/package.json +15 -9
- package/src/use-floating.ts +409 -0
- package/src/use-lazy-show.ts +20 -0
- package/src/useEventListener.ts +65 -0
- package/src/useInstanceSlots.ts +29 -0
- package/src/useRect.ts +25 -0
- package/src/useRelation.ts +130 -0
- package/src/useTouch.ts +74 -0
- package/src/useUserAgent.ts +18 -0
- package/src/useWindowSize.ts +25 -0
- package/src/vue-emitter.ts +49 -0
- package/src/vue-popper.ts +277 -0
- package/src/vue-popup.ts +196 -0
- package/tsconfig.json +25 -0
- package/tsconfig.node.json +10 -0
- package/vite.config.ts +23 -0
- package/index.js +0 -2258
package/README.md
ADDED
package/README.zh-CN.md
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2022 - present TinyVue Authors.
|
|
3
|
+
* Copyright (c) 2022 - present Huawei Cloud Computing Technologies Co., Ltd.
|
|
4
|
+
*
|
|
5
|
+
* Use of this source code is governed by an MIT-style license.
|
|
6
|
+
*
|
|
7
|
+
* THE OPEN SOURCE SOFTWARE IN THIS PRODUCT IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
|
|
8
|
+
* BUT WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS FOR
|
|
9
|
+
* A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
|
|
10
|
+
*
|
|
11
|
+
*/
|
|
12
|
+
export { useFloating } from './src/use-floating';
|
|
13
|
+
export { useLazyShow } from './src/use-lazy-show';
|
|
14
|
+
export { useEventListener } from './src/useEventListener';
|
|
15
|
+
export { useInstanceSlots } from './src/useInstanceSlots';
|
|
16
|
+
export { useRect } from './src/useRect';
|
|
17
|
+
export { useRelation } from './src/useRelation';
|
|
18
|
+
export { useTouch } from './src/useTouch';
|
|
19
|
+
export { useUserAgent } from './src/useUserAgent';
|
|
20
|
+
export { useWindowSize } from './src/useWindowSize';
|
|
21
|
+
export { userPopper } from './src/vue-popper';
|
|
22
|
+
export { usePopup } from './src/vue-popup';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { useFloating as r } from "./src/use-floating.js";
|
|
2
|
+
import { useLazyShow as p } from "./src/use-lazy-show.js";
|
|
3
|
+
import { useEventListener as u } from "./src/useEventListener.js";
|
|
4
|
+
import { useInstanceSlots as m } from "./src/useInstanceSlots.js";
|
|
5
|
+
import { useRect as n } from "./src/useRect.js";
|
|
6
|
+
import { useRelation as a } from "./src/useRelation.js";
|
|
7
|
+
import { useTouch as l } from "./src/useTouch.js";
|
|
8
|
+
import { useUserAgent as g } from "./src/useUserAgent.js";
|
|
9
|
+
import { useWindowSize as w } from "./src/useWindowSize.js";
|
|
10
|
+
import { userPopper as L } from "./src/vue-popper.js";
|
|
11
|
+
import { usePopup as R } from "./src/vue-popup.js";
|
|
12
|
+
export {
|
|
13
|
+
u as useEventListener,
|
|
14
|
+
r as useFloating,
|
|
15
|
+
m as useInstanceSlots,
|
|
16
|
+
p as useLazyShow,
|
|
17
|
+
R as usePopup,
|
|
18
|
+
n as useRect,
|
|
19
|
+
a as useRelation,
|
|
20
|
+
l as useTouch,
|
|
21
|
+
g as useUserAgent,
|
|
22
|
+
w as useWindowSize,
|
|
23
|
+
L as userPopper
|
|
24
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Placement, Strategy, OffsetOptions, RootBoundary, Boundary, ReferenceElement } from '@floating-ui/dom';
|
|
2
2
|
interface IFloatOption {
|
|
3
3
|
reference: null | ReferenceElement;
|
|
4
4
|
popper: null | HTMLElement;
|
|
@@ -69,7 +69,12 @@ interface IFloatOption {
|
|
|
69
69
|
};
|
|
70
70
|
}
|
|
71
71
|
/** 响应式的弹出层管理函数,适用于场景: tooltip, poppover, select, 右键菜单, floatbar, notify, 或 canvas上跟随鼠标等 */
|
|
72
|
-
export declare const useFloating: (
|
|
72
|
+
export declare const useFloating: ({ reactive, watch, markRaw, onBeforeUnmount }: {
|
|
73
|
+
reactive: any;
|
|
74
|
+
watch: any;
|
|
75
|
+
markRaw: any;
|
|
76
|
+
onBeforeUnmount: any;
|
|
77
|
+
}) => (option?: Partial<IFloatOption>) => {
|
|
73
78
|
state: IFloatOption;
|
|
74
79
|
on: (eventName: any, cb: any) => any;
|
|
75
80
|
off: (eventName: any, cb: any) => any;
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { autoUpdate as v, offset as C, flip as T, shift as B, limitShift as E, arrow as N, hide as O, computePosition as $ } from "@floating-ui/dom";
|
|
2
|
+
const h = {
|
|
3
|
+
reference: null,
|
|
4
|
+
popper: null,
|
|
5
|
+
show: !1,
|
|
6
|
+
autoUpdate: !0,
|
|
7
|
+
strategy: "absolute",
|
|
8
|
+
placement: "bottom",
|
|
9
|
+
offset: 6,
|
|
10
|
+
arrowVisible: !0,
|
|
11
|
+
rootBoundary: "viewport",
|
|
12
|
+
boundary: "clippingAncestors",
|
|
13
|
+
boundaryPadding: 5,
|
|
14
|
+
syncHide: !0,
|
|
15
|
+
autoHide: !1,
|
|
16
|
+
gpuAcceleration: !1,
|
|
17
|
+
animate: !0,
|
|
18
|
+
animateName: "fade-in-linear",
|
|
19
|
+
appendToBody: !1,
|
|
20
|
+
customClass: "",
|
|
21
|
+
flipAble: !0,
|
|
22
|
+
shiftAble: !0
|
|
23
|
+
}, j = { top: "bottom", right: "left", bottom: "top", left: "right" }, d = (e) => e === "auto" ? 0 : Number(e.slice(0, -1).replace(",", ".")) * 1e3, w = (e) => {
|
|
24
|
+
const p = window.getComputedStyle(e);
|
|
25
|
+
let r = d(p.transitionDelay) + d(p.transitionDuration);
|
|
26
|
+
return r || (r = d(p.animationDelay) + d(p.animationDuration), r) ? r : 0;
|
|
27
|
+
}, _ = (e, p, r) => {
|
|
28
|
+
p.split(" ").forEach((n) => n && e.classList.toggle(n, r));
|
|
29
|
+
}, b = (e) => {
|
|
30
|
+
const p = [C(e.offset)];
|
|
31
|
+
e.flipAble && p.push(
|
|
32
|
+
T({
|
|
33
|
+
rootBoundary: e.rootBoundary,
|
|
34
|
+
boundary: e.boundary,
|
|
35
|
+
padding: e.boundaryPadding
|
|
36
|
+
})
|
|
37
|
+
), e.shiftAble && p.push(B({ limiter: E() })), e.arrowVisible && p.push(
|
|
38
|
+
N({
|
|
39
|
+
element: e.popper.querySelector(".tiny-popper__arrow"),
|
|
40
|
+
padding: 8
|
|
41
|
+
})
|
|
42
|
+
), p.push(O()), $(e.reference, e.popper, {
|
|
43
|
+
placement: e.placement,
|
|
44
|
+
strategy: e.strategy,
|
|
45
|
+
middleware: p
|
|
46
|
+
}).then(({ x: r, y: n, placement: c, strategy: o, middlewareData: i }) => {
|
|
47
|
+
var u;
|
|
48
|
+
if (e.autoHide && e._last.show && (/* @__PURE__ */ new Date()).getTime() > e._last.timestamp + 300) {
|
|
49
|
+
e.show = !1;
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const s = {};
|
|
53
|
+
if (Object.assign(s, {
|
|
54
|
+
position: o
|
|
55
|
+
}), e.gpuAcceleration ? Object.assign(s, {
|
|
56
|
+
transform: `translate(${r}px,${n}px)`,
|
|
57
|
+
left: "0",
|
|
58
|
+
top: "0"
|
|
59
|
+
}) : Object.assign(s, {
|
|
60
|
+
left: `${r}px`,
|
|
61
|
+
top: `${n}px`
|
|
62
|
+
}), e.syncHide && i.hide && Object.assign(s, {
|
|
63
|
+
visibility: i.hide.referenceHidden ? "hidden" : "visible"
|
|
64
|
+
}), Object.assign(e.popper.style, s), e._last.customClass && e._last.customClass !== e.customClass && _(e.popper, e._last.customClass, !1), e.customClass && ((u = e._last) == null ? void 0 : u.customClass) !== e.customClass && (_(e.popper, e.customClass, !0), e._last.customClass = e.customClass), e.arrowVisible) {
|
|
65
|
+
const { x: t, y: l } = i.arrow, a = e._last.arrowEl, m = j[c.split("-")[0]], g = {
|
|
66
|
+
left: t !== null ? `${t}px` : "",
|
|
67
|
+
top: l !== null ? `${l}px` : "",
|
|
68
|
+
right: "",
|
|
69
|
+
bottom: "",
|
|
70
|
+
[m]: "-4px",
|
|
71
|
+
display: "block"
|
|
72
|
+
};
|
|
73
|
+
Object.assign(a.style, g);
|
|
74
|
+
} else
|
|
75
|
+
e._last.arrowInserted && (e._last.arrowEl.style.display = "none");
|
|
76
|
+
f(e, "update", { x: r, y: n, placement: c, strategy: o, middlewareData: i });
|
|
77
|
+
});
|
|
78
|
+
}, P = (e) => v(e.reference, e.popper, () => {
|
|
79
|
+
b(e);
|
|
80
|
+
}), S = (e) => {
|
|
81
|
+
if (!(e._last.show && e._last.popper === e.popper) && (e._last.popper && e._last.popper !== e.popper && (e._last.appendToBody ? e._last.popper.remove() : e._last.popper.style.display = "none", e._last.arrowInserted = !1, e._last.arrowEl = null), e.popper)) {
|
|
82
|
+
if (e.appendToBody ? document.body.append(e.popper) : e.popper.style.display = "block", !e._last.arrowInserted) {
|
|
83
|
+
const p = document.createElement("div");
|
|
84
|
+
p.className = "tiny-popper__arrow", e.popper.append(p), e._last.arrowInserted = !0, e._last.arrowEl = p;
|
|
85
|
+
}
|
|
86
|
+
if (e.animate) {
|
|
87
|
+
const p = `${e.animateName}-enter-from`, r = `${e.animateName}-enter-active`;
|
|
88
|
+
e.popper.classList.add(p, r), setTimeout(() => {
|
|
89
|
+
e.popper.classList.remove(p);
|
|
90
|
+
}, 0);
|
|
91
|
+
const n = w(e.popper);
|
|
92
|
+
setTimeout(() => {
|
|
93
|
+
e.popper.classList.remove(r);
|
|
94
|
+
}, n);
|
|
95
|
+
}
|
|
96
|
+
f(e, "show");
|
|
97
|
+
}
|
|
98
|
+
}, y = (e) => {
|
|
99
|
+
if (e._last.show && e.popper)
|
|
100
|
+
if (e.animate && e.animateName) {
|
|
101
|
+
const p = `${e.animateName}-leave-to`, r = `${e.animateName}-leave-active`;
|
|
102
|
+
e.popper.classList.add(p, r);
|
|
103
|
+
const n = w(e.popper);
|
|
104
|
+
setTimeout(() => {
|
|
105
|
+
e.popper.classList.remove(p, r), e.appendToBody ? e.popper.remove() : e.popper.style.display = "none", f(e, "hide");
|
|
106
|
+
}, n);
|
|
107
|
+
} else
|
|
108
|
+
e.appendToBody ? e.popper.remove() : e.popper.style.display = "none", f(e, "hide");
|
|
109
|
+
}, f = (e, p, r) => {
|
|
110
|
+
e._events[p].forEach((n) => n(r));
|
|
111
|
+
}, A = (e, p, r = 0, n = 0) => ({
|
|
112
|
+
getBoundingClientRect() {
|
|
113
|
+
return {
|
|
114
|
+
width: 0,
|
|
115
|
+
height: 0,
|
|
116
|
+
x: e,
|
|
117
|
+
y: p,
|
|
118
|
+
top: p,
|
|
119
|
+
left: e,
|
|
120
|
+
right: e + r,
|
|
121
|
+
bottom: p + n
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
}), x = ({ reactive: e, watch: p, markRaw: r, onBeforeUnmount: n }) => (c = {}) => {
|
|
125
|
+
const o = e(c);
|
|
126
|
+
let i = null;
|
|
127
|
+
Object.keys(h).forEach((l) => {
|
|
128
|
+
Object.prototype.hasOwnProperty.call(o, l) || (o[l] = h[l]);
|
|
129
|
+
}), o._last = r({}), o._events = r({ show: [], hide: [], update: [] });
|
|
130
|
+
const s = () => {
|
|
131
|
+
o.popper && o.reference && o.show ? (S(o), o.autoUpdate ? (i && i(), i = P(o)) : b(o)) : (i && i(), y(o)), o._last.popper = o.popper, o._last.reference = o.reference, o._last.show = o.show && o.popper && o.reference, o._last.appendToBody = o.appendToBody, o._last.timestamp = (/* @__PURE__ */ new Date()).getTime();
|
|
132
|
+
};
|
|
133
|
+
p(o, s, { immediate: !0 });
|
|
134
|
+
const u = (l, a) => o._events[l].push(a), t = (l, a) => o._events[l] = o._events[l].filter((m) => m !== a);
|
|
135
|
+
return n(() => {
|
|
136
|
+
i && i(), y(o);
|
|
137
|
+
}), { state: o, on: u, off: t, virtualEl: A, forceUpdate: s };
|
|
138
|
+
};
|
|
139
|
+
export {
|
|
140
|
+
x as useFloating
|
|
141
|
+
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { hooks } from '@opentiny/vue-common';
|
|
2
1
|
/** 慢加载的 v-show 的办法, 灵感来自于: https://github.com/antfu/v-lazy-show
|
|
3
2
|
* 适用场景: 存在初始加载时,不需要显示的区域,但又需要用v-show切换显示。 比如 tabs\collapse\dropdown\cascader\carousel等
|
|
4
3
|
* @example
|
|
@@ -9,6 +8,10 @@ import { hooks } from '@opentiny/vue-common';
|
|
|
9
8
|
* isShow 第一次为true时,才会加载该DOM
|
|
10
9
|
* </div>
|
|
11
10
|
*/
|
|
12
|
-
export declare const useLazyShow: (
|
|
13
|
-
|
|
11
|
+
export declare const useLazyShow: ({ ref, watch, isRef }: {
|
|
12
|
+
ref: any;
|
|
13
|
+
watch: any;
|
|
14
|
+
isRef: any;
|
|
15
|
+
}) => (show: any) => {
|
|
16
|
+
lazyShow: any;
|
|
14
17
|
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare const onMountedOrActivated: ({ onMounted, onActivated, nextTick }: {
|
|
2
|
+
onMounted: any;
|
|
3
|
+
onActivated: any;
|
|
4
|
+
nextTick: any;
|
|
5
|
+
}) => (hook: any) => void;
|
|
6
|
+
export declare const useEventListener: ({ unref, isRef, watch, nextTick, onMounted, onUnmounted, onActivated, onDeactivated }: {
|
|
7
|
+
unref: any;
|
|
8
|
+
isRef: any;
|
|
9
|
+
watch: any;
|
|
10
|
+
nextTick: any;
|
|
11
|
+
onMounted: any;
|
|
12
|
+
onUnmounted: any;
|
|
13
|
+
onActivated: any;
|
|
14
|
+
onDeactivated: any;
|
|
15
|
+
}) => (type: any, listener: any, options?: {}) => (() => void) | undefined;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { isServer as E, on as L, off as M } from "@opentiny/utils";
|
|
2
|
+
const O = ({ onMounted: r, onActivated: f, nextTick: i }) => (o) => {
|
|
3
|
+
let s;
|
|
4
|
+
r(() => {
|
|
5
|
+
o(), i(() => s = !0);
|
|
6
|
+
}), f(() => s && o());
|
|
7
|
+
}, W = ({ unref: r, isRef: f, watch: i, nextTick: o, onMounted: s, onUnmounted: g, onActivated: h, onDeactivated: x }) => (d, m, A = {}) => {
|
|
8
|
+
if (E) return;
|
|
9
|
+
const { target: t = window, passive: v = !1, capture: p = !1 } = A;
|
|
10
|
+
let l = !1, a;
|
|
11
|
+
const w = (n) => {
|
|
12
|
+
if (l) return;
|
|
13
|
+
const e = r(n);
|
|
14
|
+
e && !a && (L(e, d, m, { capture: p, passive: v }), a = !0);
|
|
15
|
+
}, c = (n) => {
|
|
16
|
+
if (l) return;
|
|
17
|
+
const e = r(n);
|
|
18
|
+
e && a && (M(e, d, m, { capture: p, passive: v }), a = !1);
|
|
19
|
+
};
|
|
20
|
+
g(() => c(t)), x(() => c(t)), O({ onMounted: s, onActivated: h, nextTick: o })(() => w(t));
|
|
21
|
+
let u;
|
|
22
|
+
return f(t) && (u = i(t, (n, e) => {
|
|
23
|
+
c(e), w(n);
|
|
24
|
+
})), () => {
|
|
25
|
+
u && u(), c(t), l = !0;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
export {
|
|
29
|
+
O as onMountedOrActivated,
|
|
30
|
+
W as useEventListener
|
|
31
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const n = ({ getCurrentInstance: o, isVue2: t, nextTick: s, onUnmounted: l }) => () => {
|
|
2
|
+
const e = o().proxy;
|
|
3
|
+
t || Object.defineProperty(e, "$scopedSlots", { configurable: !0, value: null }), Object.defineProperty(e, "instanceSlots", {
|
|
4
|
+
configurable: !0,
|
|
5
|
+
get: () => e.$scopedSlots || e.$slots
|
|
6
|
+
}), l(() => {
|
|
7
|
+
s(() => {
|
|
8
|
+
t || delete e.$scopedSlots, delete e.instanceSlots;
|
|
9
|
+
});
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
export {
|
|
13
|
+
n as useInstanceSlots
|
|
14
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useRect: (unref: any) => (elOrRef: any) => any;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const r = (t) => t === window, i = (t, e) => ({
|
|
2
|
+
top: 0,
|
|
3
|
+
left: 0,
|
|
4
|
+
width: t,
|
|
5
|
+
right: t,
|
|
6
|
+
height: e,
|
|
7
|
+
bottom: e
|
|
8
|
+
}), s = (t) => (e) => {
|
|
9
|
+
const n = t(e);
|
|
10
|
+
if (r(n)) {
|
|
11
|
+
const o = n.innerWidth, c = n.innerHeight;
|
|
12
|
+
return i(o, c);
|
|
13
|
+
}
|
|
14
|
+
return n && n.getBoundingClientRect ? n.getBoundingClientRect() : i(0, 0);
|
|
15
|
+
};
|
|
16
|
+
export {
|
|
17
|
+
s as useRect
|
|
18
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 处理组件嵌套的组合式 API
|
|
3
|
+
* relationKey 关系树上的父子组件使用同一个关系名称
|
|
4
|
+
* relationContainer 子组件顺序由关系容器确定,由根组件提供,可以不使用,子组件顺序就是组件创建顺序
|
|
5
|
+
* onChange 子组件顺序改变后的回调处理,由根组件提供,可以不使用
|
|
6
|
+
* childrenKey 在组件关系树上的所有实例中定义的子组件引用名称,默认是 instanceChildren
|
|
7
|
+
* delivery 根组件向下分发的内容
|
|
8
|
+
*/
|
|
9
|
+
export declare const useRelation: ({ computed, getCurrentInstance, inject, markRaw, nextTick, onMounted, onActivated, onUnmounted, provide, reactive, toRef }: {
|
|
10
|
+
computed: any;
|
|
11
|
+
getCurrentInstance: any;
|
|
12
|
+
inject: any;
|
|
13
|
+
markRaw: any;
|
|
14
|
+
nextTick: any;
|
|
15
|
+
onMounted: any;
|
|
16
|
+
onActivated: any;
|
|
17
|
+
onUnmounted: any;
|
|
18
|
+
provide: any;
|
|
19
|
+
reactive: any;
|
|
20
|
+
toRef: any;
|
|
21
|
+
}) => ({ relationKey, relationContainer, onChange, childrenKey, delivery }?: {
|
|
22
|
+
relationKey: any;
|
|
23
|
+
relationContainer: any;
|
|
24
|
+
onChange: any;
|
|
25
|
+
childrenKey: any;
|
|
26
|
+
delivery: any;
|
|
27
|
+
}) => {
|
|
28
|
+
children: any;
|
|
29
|
+
index: any;
|
|
30
|
+
delivery: any;
|
|
31
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { noop as y } from "@opentiny/utils";
|
|
2
|
+
import { onMountedOrActivated as C } from "./useEventListener.js";
|
|
3
|
+
const V = ({
|
|
4
|
+
computed: l,
|
|
5
|
+
getCurrentInstance: i,
|
|
6
|
+
inject: c,
|
|
7
|
+
markRaw: a,
|
|
8
|
+
nextTick: f,
|
|
9
|
+
onMounted: v,
|
|
10
|
+
onActivated: E,
|
|
11
|
+
onUnmounted: h,
|
|
12
|
+
provide: M,
|
|
13
|
+
reactive: m,
|
|
14
|
+
toRef: k
|
|
15
|
+
}) => ({ relationKey: p, relationContainer: x, onChange: P, childrenKey: r, delivery: b } = {}) => {
|
|
16
|
+
if (!p)
|
|
17
|
+
throw new Error("[TINY Error]<relationKey> must exist.");
|
|
18
|
+
const u = i(), e = m({ children: [], indexInParent: -1 }), j = c(p, null);
|
|
19
|
+
let o = [];
|
|
20
|
+
if (j) {
|
|
21
|
+
const { link: t, unlink: n, callbacks: s, childrenKey: d, delivery: O } = j;
|
|
22
|
+
o = s, r = r || d || "instanceChildren", b = O, e.indexInParent = t(u), h(() => n(u));
|
|
23
|
+
} else {
|
|
24
|
+
r = r || "instanceChildren";
|
|
25
|
+
const t = C({ onMounted: v, onActivated: E, nextTick: f }), n = P ? () => f(P) : y;
|
|
26
|
+
let s;
|
|
27
|
+
f(() => {
|
|
28
|
+
const d = typeof x == "function" ? x() : x;
|
|
29
|
+
d && (s = new MutationObserver((O, $) => {
|
|
30
|
+
const I = [];
|
|
31
|
+
g(d.childNodes, I), o.forEach((A) => A(I, O, $)), n();
|
|
32
|
+
}), s.observe(d, { attributes: !0, childList: !0, subtree: !0 }));
|
|
33
|
+
}), t(() => n()), h(() => {
|
|
34
|
+
s && (s.disconnect(), s = null), o = null;
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
const w = (t) => {
|
|
38
|
+
const n = t.proxy;
|
|
39
|
+
return e.children.push(a(n)), l(() => e.children.indexOf(n));
|
|
40
|
+
}, N = (t) => {
|
|
41
|
+
const n = e.children.indexOf(t.proxy);
|
|
42
|
+
n > -1 && e.children.splice(n, 1);
|
|
43
|
+
};
|
|
44
|
+
return o.push((t) => D(e.children, t)), M(p, { link: w, unlink: N, callbacks: o, childrenKey: r, delivery: b }), Object.defineProperty(u.proxy, r, { configurable: !0, get: () => e.children }), h(() => delete u.proxy[r]), { children: k(e, "children"), index: k(e, "indexInParent"), delivery: b };
|
|
45
|
+
}, g = (l, i) => {
|
|
46
|
+
l.length && l.forEach((c) => {
|
|
47
|
+
i.push(c), c.childNodes && g(c.childNodes, i);
|
|
48
|
+
});
|
|
49
|
+
}, D = (l, i) => {
|
|
50
|
+
l.sort((c, a) => i.indexOf(c.$el) - i.indexOf(a.$el));
|
|
51
|
+
};
|
|
52
|
+
export {
|
|
53
|
+
V as useRelation
|
|
54
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare const useTouch: (ref: any) => () => {
|
|
2
|
+
move: (event: any) => void;
|
|
3
|
+
start: (event: any) => void;
|
|
4
|
+
reset: () => void;
|
|
5
|
+
isVertical: () => boolean;
|
|
6
|
+
isHorizontal: () => boolean;
|
|
7
|
+
startX: any;
|
|
8
|
+
startY: any;
|
|
9
|
+
deltaX: any;
|
|
10
|
+
deltaY: any;
|
|
11
|
+
offsetX: any;
|
|
12
|
+
offsetY: any;
|
|
13
|
+
direction: any;
|
|
14
|
+
isTap: any;
|
|
15
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const X = (t, e) => t > e ? "horizontal" : e > t ? "vertical" : "", h = (t) => t.touches[0], _ = (t) => () => {
|
|
2
|
+
const e = t(0), v = t(0), c = t(0), n = t(0), a = t(0), l = t(0), u = t(""), s = t(!0), E = () => u.value === "vertical", F = () => u.value === "horizontal", r = () => {
|
|
3
|
+
c.value = 0, n.value = 0, a.value = 0, l.value = 0, u.value = "", s.value = !0;
|
|
4
|
+
};
|
|
5
|
+
return {
|
|
6
|
+
move: (i) => {
|
|
7
|
+
const o = h(i);
|
|
8
|
+
c.value = (o.clientX < 0 ? 0 : o.clientX) - e.value, n.value = o.clientY - v.value, a.value = Math.abs(c.value), l.value = Math.abs(n.value);
|
|
9
|
+
const T = 10;
|
|
10
|
+
(!u.value || a.value < T && l.value < T) && (u.value = X(a.value, l.value)), s.value && (a.value > 5 || l.value > 5) && (s.value = !1);
|
|
11
|
+
},
|
|
12
|
+
start: (i) => {
|
|
13
|
+
r();
|
|
14
|
+
const o = h(i);
|
|
15
|
+
e.value = o.clientX, v.value = o.clientY;
|
|
16
|
+
},
|
|
17
|
+
reset: r,
|
|
18
|
+
isVertical: E,
|
|
19
|
+
isHorizontal: F,
|
|
20
|
+
startX: e,
|
|
21
|
+
startY: v,
|
|
22
|
+
deltaX: c,
|
|
23
|
+
deltaY: n,
|
|
24
|
+
offsetX: a,
|
|
25
|
+
offsetY: l,
|
|
26
|
+
direction: u,
|
|
27
|
+
isTap: s
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
export {
|
|
31
|
+
_ as useTouch
|
|
32
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { isServer as n } from "@opentiny/utils";
|
|
2
|
+
function t() {
|
|
3
|
+
return n ? !1 : window.navigator && window.navigator.userAgent && (/iP(?:ad|hone|od)/.test(window.navigator.userAgent) || // The new iPad Pro Gen3 does not identify itself as iPad, but as Macintosh.
|
|
4
|
+
// https://github.com/vueuse/vueuse/issues/3577
|
|
5
|
+
window.navigator.maxTouchPoints > 2 && /iPad|Macintosh/.test(window.navigator.userAgent));
|
|
6
|
+
}
|
|
7
|
+
const i = () => ({ isIOS: t() });
|
|
8
|
+
export {
|
|
9
|
+
i as useUserAgent
|
|
10
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { isServer as r, on as o } from "@opentiny/utils";
|
|
2
|
+
let e, n;
|
|
3
|
+
const s = (t) => () => {
|
|
4
|
+
if (!e && (e = t(0), n = t(0), !r)) {
|
|
5
|
+
const i = () => {
|
|
6
|
+
e.value = window.innerWidth, n.value = window.innerHeight;
|
|
7
|
+
};
|
|
8
|
+
i(), o(window, "resize", i, { passive: !0 }), o(window, "orientationchange", i, { passive: !0 });
|
|
9
|
+
}
|
|
10
|
+
return { width: e, height: n };
|
|
11
|
+
};
|
|
12
|
+
export {
|
|
13
|
+
s as useWindowSize
|
|
14
|
+
};
|
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
* A PARTICULAR PURPOSE. SEE THE APPLICABLE LICENSES FOR MORE DETAILS.
|
|
10
10
|
*
|
|
11
11
|
*/
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
declare const _default: (vm: any) => {
|
|
13
|
+
dispatch(componentName: any, eventName: any, params: any): void;
|
|
14
|
+
broadcast(componentName: any, eventName: any, params: any): void;
|
|
15
|
+
};
|
|
16
|
+
export default _default;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { off as b, PopupManager as I, isDisplayNone as $, isServer as N, PopperJS as T, on as v } from "@opentiny/utils";
|
|
2
|
+
const x = (t) => t.stopPropagation(), E = ({ state: t, props: l, vm: n, slots: d }) => {
|
|
3
|
+
let a = t.referenceElm || l.reference || n.$refs.reference && n.$refs.reference.$el || n.$refs.reference;
|
|
4
|
+
return !a && d.reference && d.reference()[0] && (t.referenceElm = d.reference()[0].elm || d.reference()[0].el, a = t.referenceElm), a;
|
|
5
|
+
}, R = (t) => {
|
|
6
|
+
if (!t || !t.nodeType) return;
|
|
7
|
+
let l = (a) => parseInt(window.getComputedStyle(a).zIndex, 10) || 0, n = l(t), d;
|
|
8
|
+
do {
|
|
9
|
+
if (t = t.parentNode, t && t instanceof ShadowRoot && t.host && (t = t.host), t)
|
|
10
|
+
d = l(t);
|
|
11
|
+
else
|
|
12
|
+
break;
|
|
13
|
+
n = d > n ? d : n;
|
|
14
|
+
} while (t !== document.body);
|
|
15
|
+
return n + 1 + "";
|
|
16
|
+
}, k = (t) => {
|
|
17
|
+
const {
|
|
18
|
+
parent: l,
|
|
19
|
+
emit: n,
|
|
20
|
+
nextTick: d,
|
|
21
|
+
onBeforeUnmount: a,
|
|
22
|
+
onDeactivated: J,
|
|
23
|
+
props: p,
|
|
24
|
+
watch: y,
|
|
25
|
+
reactive: g,
|
|
26
|
+
vm: f,
|
|
27
|
+
slots: w,
|
|
28
|
+
toRefs: h,
|
|
29
|
+
popperVmRef: A
|
|
30
|
+
} = t, e = g({
|
|
31
|
+
popperJS: null,
|
|
32
|
+
appended: !1,
|
|
33
|
+
// arrow 是否添加
|
|
34
|
+
popperElm: null,
|
|
35
|
+
showPopper: p.manual ? !!p.modelValue : !1,
|
|
36
|
+
referenceElm: null,
|
|
37
|
+
currentPlacement: ""
|
|
38
|
+
}), B = (o) => {
|
|
39
|
+
if (e.appended)
|
|
40
|
+
return;
|
|
41
|
+
e.appended = !0;
|
|
42
|
+
const r = document.createElement("div");
|
|
43
|
+
r.setAttribute("x-arrow", ""), r.className = "popper__arrow", o.appendChild(r);
|
|
44
|
+
}, S = (o) => {
|
|
45
|
+
const { followReferenceHide: r = !0 } = (p == null ? void 0 : p.popperOptions) || {}, { _popper: c, _reference: s } = o;
|
|
46
|
+
r && $(s) && (c.style.display = "none");
|
|
47
|
+
}, P = (o) => p.zIndex === "relative" ? R(o) : I.nextZIndex(), _ = (o) => {
|
|
48
|
+
if (N || (e.currentPlacement = e.currentPlacement || p.placement, !/^(top|bottom|left|right)(-start|-end)?$/g.test(e.currentPlacement)))
|
|
49
|
+
return;
|
|
50
|
+
const r = p.popperOptions || { gpuAcceleration: !1 };
|
|
51
|
+
e.popperElm = e.popperElm || p.popper || f.$refs.popper || A.popper || o;
|
|
52
|
+
const c = e.popperElm;
|
|
53
|
+
let s = E({ state: e, props: p, vm: f, slots: w });
|
|
54
|
+
!c || !s || s.nodeType !== Node.ELEMENT_NODE || (p.visibleArrow && B(c), p.appendToBody || p.popperAppendToBody ? document.body.appendChild(e.popperElm) : (l && l.$el && l.$el.appendChild(e.popperElm), r.forceAbsolute = !0), r.placement = e.currentPlacement, r.offset = p.offset || 0, r.arrowOffset = p.arrowOffset || 0, r.adjustArrow = p.adjustArrow || !1, r.appendToBody = p.appendToBody || p.popperAppendToBody, e.popperJS = new T(s, c, r), n("created", e), typeof r.onUpdate == "function" && e.popperJS.onUpdate(r.onUpdate), e.popperJS._popper.style.zIndex = P(e.popperJS._reference), S(e.popperJS), v(e.popperElm, "click", x));
|
|
55
|
+
}, i = (o) => {
|
|
56
|
+
o && o !== !0 && (e.popperElm = o);
|
|
57
|
+
const r = e.popperJS;
|
|
58
|
+
r ? (r._reference = E({ state: e, props: p, vm: f, slots: w }), r.update(), r._popper && o !== !0 && (r._popper.style.zIndex = P(r._reference), S(e.popperJS))) : _(o && o !== !0 ? o : void 0);
|
|
59
|
+
}, u = (o) => {
|
|
60
|
+
!e.popperJS || e.showPopper && !o || (e.popperJS.destroy(), e.popperJS = null);
|
|
61
|
+
}, m = (o) => {
|
|
62
|
+
o && e.popperElm && e.popperElm.parentNode === document.body && (b(e.popperElm, "click", x), e.popperElm.remove());
|
|
63
|
+
};
|
|
64
|
+
return y(
|
|
65
|
+
() => e.showPopper,
|
|
66
|
+
(o) => {
|
|
67
|
+
p.disabled || (o && d(i), p.trigger === "manual" && n("update:modelValue", o));
|
|
68
|
+
}
|
|
69
|
+
), y(
|
|
70
|
+
() => p.placement,
|
|
71
|
+
(o) => {
|
|
72
|
+
var r;
|
|
73
|
+
e.currentPlacement = o, (r = e.popperJS) == null || r.setOptions({ placement: o }), !p.disabled && (o && d(i), p.trigger === "manual" && n("update:modelValue", o));
|
|
74
|
+
}
|
|
75
|
+
), a(() => {
|
|
76
|
+
d(() => {
|
|
77
|
+
u(!0), (p.appendToBody || p.popperAppendToBody) && m("remove");
|
|
78
|
+
});
|
|
79
|
+
}), J(() => {
|
|
80
|
+
u(!0), (p.appendToBody || p.popperAppendToBody) && m("remove");
|
|
81
|
+
}), { updatePopper: i, destroyPopper: m, doDestroy: u, ...h(e) };
|
|
82
|
+
};
|
|
83
|
+
export {
|
|
84
|
+
k as userPopper
|
|
85
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ISharedRenderlessFunctionParams } from 'types/shared.type';
|
|
2
|
+
export interface IPopupState {
|
|
3
|
+
opened: boolean;
|
|
4
|
+
rendered: boolean;
|
|
5
|
+
}
|
|
6
|
+
type IPopupInputParams = ISharedRenderlessFunctionParams<never> & {
|
|
7
|
+
api: {
|
|
8
|
+
open: Function;
|
|
9
|
+
close: Function;
|
|
10
|
+
};
|
|
11
|
+
state: IPopupState;
|
|
12
|
+
props: any;
|
|
13
|
+
};
|
|
14
|
+
/** vue-popup 只是dialog-box 自己使用的包, 封装了一些state和几个方法,处理mount,unmount 和watch。 它内部封装了 PopupManager 的调用!
|
|
15
|
+
* 计划:drawer/image 等组件均使用该函数
|
|
16
|
+
*/
|
|
17
|
+
export declare const usePopup: (options: IPopupInputParams) => any;
|
|
18
|
+
export {};
|