@v-c/trigger 0.0.9 → 0.0.11
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/dist/Popup/Arrow.cjs +91 -1
- package/dist/Popup/Arrow.js +60 -38
- package/dist/Popup/Mask.cjs +66 -1
- package/dist/Popup/Mask.js +35 -32
- package/dist/Popup/PopupContent.cjs +29 -1
- package/dist/Popup/PopupContent.js +15 -8
- package/dist/Popup/index.cjs +365 -1
- package/dist/Popup/index.js +194 -160
- package/dist/UniqueProvider/UniqueContainer.cjs +159 -1
- package/dist/UniqueProvider/UniqueContainer.js +87 -67
- package/dist/UniqueProvider/index.cjs +213 -1
- package/dist/UniqueProvider/index.js +177 -131
- package/dist/UniqueProvider/useTargetState.cjs +42 -1
- package/dist/UniqueProvider/useTargetState.js +39 -10
- package/dist/context.cjs +38 -1
- package/dist/context.js +27 -16
- package/dist/hooks/useAction.cjs +32 -1
- package/dist/hooks/useAction.js +27 -12
- package/dist/hooks/useAlign.cjs +499 -1
- package/dist/hooks/useAlign.d.ts +1 -1
- package/dist/hooks/useAlign.js +445 -204
- package/dist/hooks/useDelay.cjs +27 -1
- package/dist/hooks/useDelay.js +23 -12
- package/dist/hooks/useOffsetStyle.cjs +36 -1
- package/dist/hooks/useOffsetStyle.js +28 -12
- package/dist/hooks/useWatch.cjs +37 -1
- package/dist/hooks/useWatch.js +28 -17
- package/dist/hooks/useWinClick.cjs +67 -1
- package/dist/hooks/useWinClick.js +56 -39
- package/dist/index.cjs +700 -1
- package/dist/index.js +501 -312
- package/dist/util.cjs +101 -1
- package/dist/util.js +86 -54
- package/package.json +3 -3
package/dist/hooks/useDelay.cjs
CHANGED
|
@@ -1 +1,27 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const vue = require("vue");
|
|
4
|
+
function useDelay() {
|
|
5
|
+
const delayRef = vue.ref(null);
|
|
6
|
+
const clearDelay = () => {
|
|
7
|
+
if (delayRef.value) {
|
|
8
|
+
clearTimeout(delayRef.value);
|
|
9
|
+
delayRef.value = null;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
const delayInvoke = (callback, delay) => {
|
|
13
|
+
clearDelay();
|
|
14
|
+
if (delay === 0) {
|
|
15
|
+
callback();
|
|
16
|
+
} else {
|
|
17
|
+
delayRef.value = setTimeout(() => {
|
|
18
|
+
callback();
|
|
19
|
+
}, delay * 1e3);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
vue.onBeforeUnmount(() => {
|
|
23
|
+
clearDelay();
|
|
24
|
+
});
|
|
25
|
+
return delayInvoke;
|
|
26
|
+
}
|
|
27
|
+
exports.default = useDelay;
|
package/dist/hooks/useDelay.js
CHANGED
|
@@ -1,16 +1,27 @@
|
|
|
1
|
-
import { ref
|
|
2
|
-
function
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
1
|
+
import { ref, onBeforeUnmount } from "vue";
|
|
2
|
+
function useDelay() {
|
|
3
|
+
const delayRef = ref(null);
|
|
4
|
+
const clearDelay = () => {
|
|
5
|
+
if (delayRef.value) {
|
|
6
|
+
clearTimeout(delayRef.value);
|
|
7
|
+
delayRef.value = null;
|
|
8
|
+
}
|
|
9
9
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
const delayInvoke = (callback, delay) => {
|
|
11
|
+
clearDelay();
|
|
12
|
+
if (delay === 0) {
|
|
13
|
+
callback();
|
|
14
|
+
} else {
|
|
15
|
+
delayRef.value = setTimeout(() => {
|
|
16
|
+
callback();
|
|
17
|
+
}, delay * 1e3);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
onBeforeUnmount(() => {
|
|
21
|
+
clearDelay();
|
|
22
|
+
});
|
|
23
|
+
return delayInvoke;
|
|
13
24
|
}
|
|
14
25
|
export {
|
|
15
|
-
|
|
26
|
+
useDelay as default
|
|
16
27
|
};
|
|
@@ -1 +1,36 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const vue = require("vue");
|
|
4
|
+
function useOffsetStyle(isMobile, ready, open, align, offsetR, offsetB, offsetX, offsetY) {
|
|
5
|
+
const AUTO = "auto";
|
|
6
|
+
return vue.computed(() => {
|
|
7
|
+
const offsetStyle = isMobile.value ? {} : {
|
|
8
|
+
left: "-1000vw",
|
|
9
|
+
top: "-1000vh",
|
|
10
|
+
right: AUTO,
|
|
11
|
+
bottom: AUTO
|
|
12
|
+
};
|
|
13
|
+
if (!isMobile.value && (ready.value || !open.value)) {
|
|
14
|
+
const { points } = align.value ?? {};
|
|
15
|
+
const dynamicInset = align.value?.dynamicInset || align.value?._experimental?.dynamicInset;
|
|
16
|
+
const alignRight = dynamicInset && points?.[0]?.[1] === "r";
|
|
17
|
+
const alignBottom = dynamicInset && points?.[0]?.[0] === "b";
|
|
18
|
+
if (alignRight) {
|
|
19
|
+
offsetStyle.right = `${offsetR.value}px`;
|
|
20
|
+
offsetStyle.left = AUTO;
|
|
21
|
+
} else {
|
|
22
|
+
offsetStyle.left = `${offsetX.value}px`;
|
|
23
|
+
offsetStyle.right = AUTO;
|
|
24
|
+
}
|
|
25
|
+
if (alignBottom) {
|
|
26
|
+
offsetStyle.bottom = `${offsetB.value}px`;
|
|
27
|
+
offsetStyle.top = AUTO;
|
|
28
|
+
} else {
|
|
29
|
+
offsetStyle.top = `${offsetY.value}px`;
|
|
30
|
+
offsetStyle.bottom = AUTO;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return offsetStyle;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
exports.default = useOffsetStyle;
|
|
@@ -1,20 +1,36 @@
|
|
|
1
|
-
import { computed
|
|
2
|
-
function
|
|
3
|
-
const
|
|
4
|
-
return
|
|
5
|
-
const
|
|
1
|
+
import { computed } from "vue";
|
|
2
|
+
function useOffsetStyle(isMobile, ready, open, align, offsetR, offsetB, offsetX, offsetY) {
|
|
3
|
+
const AUTO = "auto";
|
|
4
|
+
return computed(() => {
|
|
5
|
+
const offsetStyle = isMobile.value ? {} : {
|
|
6
6
|
left: "-1000vw",
|
|
7
7
|
top: "-1000vh",
|
|
8
|
-
right:
|
|
9
|
-
bottom:
|
|
8
|
+
right: AUTO,
|
|
9
|
+
bottom: AUTO
|
|
10
10
|
};
|
|
11
|
-
if (!
|
|
12
|
-
const { points
|
|
13
|
-
|
|
11
|
+
if (!isMobile.value && (ready.value || !open.value)) {
|
|
12
|
+
const { points } = align.value ?? {};
|
|
13
|
+
const dynamicInset = align.value?.dynamicInset || align.value?._experimental?.dynamicInset;
|
|
14
|
+
const alignRight = dynamicInset && points?.[0]?.[1] === "r";
|
|
15
|
+
const alignBottom = dynamicInset && points?.[0]?.[0] === "b";
|
|
16
|
+
if (alignRight) {
|
|
17
|
+
offsetStyle.right = `${offsetR.value}px`;
|
|
18
|
+
offsetStyle.left = AUTO;
|
|
19
|
+
} else {
|
|
20
|
+
offsetStyle.left = `${offsetX.value}px`;
|
|
21
|
+
offsetStyle.right = AUTO;
|
|
22
|
+
}
|
|
23
|
+
if (alignBottom) {
|
|
24
|
+
offsetStyle.bottom = `${offsetB.value}px`;
|
|
25
|
+
offsetStyle.top = AUTO;
|
|
26
|
+
} else {
|
|
27
|
+
offsetStyle.top = `${offsetY.value}px`;
|
|
28
|
+
offsetStyle.bottom = AUTO;
|
|
29
|
+
}
|
|
14
30
|
}
|
|
15
|
-
return
|
|
31
|
+
return offsetStyle;
|
|
16
32
|
});
|
|
17
33
|
}
|
|
18
34
|
export {
|
|
19
|
-
|
|
35
|
+
useOffsetStyle as default
|
|
20
36
|
};
|
package/dist/hooks/useWatch.cjs
CHANGED
|
@@ -1 +1,37 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const vue = require("vue");
|
|
4
|
+
const util = require("../util.cjs");
|
|
5
|
+
function useWatch(open, target, popup, onAlign, onScroll) {
|
|
6
|
+
vue.watch([open, target, popup], async (_n, _o, onCleanup) => {
|
|
7
|
+
await vue.nextTick();
|
|
8
|
+
if (open.value && target.value && popup.value) {
|
|
9
|
+
let notifyScroll = function() {
|
|
10
|
+
onAlign();
|
|
11
|
+
onScroll();
|
|
12
|
+
};
|
|
13
|
+
const targetElement = target.value;
|
|
14
|
+
const popupElement = popup.value;
|
|
15
|
+
const targetScrollList = util.collectScroller(targetElement);
|
|
16
|
+
const popupScrollList = util.collectScroller(popupElement);
|
|
17
|
+
const win = util.getWin(popupElement);
|
|
18
|
+
const mergedList = /* @__PURE__ */ new Set([
|
|
19
|
+
win,
|
|
20
|
+
...targetScrollList,
|
|
21
|
+
...popupScrollList
|
|
22
|
+
]);
|
|
23
|
+
mergedList.forEach((scroller) => {
|
|
24
|
+
scroller.addEventListener("scroll", notifyScroll, { passive: true });
|
|
25
|
+
});
|
|
26
|
+
win.addEventListener("resize", notifyScroll, { passive: true });
|
|
27
|
+
onAlign();
|
|
28
|
+
onCleanup(() => {
|
|
29
|
+
mergedList.forEach((scroller) => {
|
|
30
|
+
scroller.removeEventListener("scroll", notifyScroll);
|
|
31
|
+
win.removeEventListener("resize", notifyScroll);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
exports.default = useWatch;
|
package/dist/hooks/useWatch.js
CHANGED
|
@@ -1,26 +1,37 @@
|
|
|
1
|
-
import { watch
|
|
2
|
-
import { collectScroller
|
|
3
|
-
function
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { watch, nextTick } from "vue";
|
|
2
|
+
import { collectScroller, getWin } from "../util.js";
|
|
3
|
+
function useWatch(open, target, popup, onAlign, onScroll) {
|
|
4
|
+
watch([open, target, popup], async (_n, _o, onCleanup) => {
|
|
5
|
+
await nextTick();
|
|
6
|
+
if (open.value && target.value && popup.value) {
|
|
7
|
+
let notifyScroll = function() {
|
|
8
|
+
onAlign();
|
|
9
|
+
onScroll();
|
|
8
10
|
};
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
const targetElement = target.value;
|
|
12
|
+
const popupElement = popup.value;
|
|
13
|
+
const targetScrollList = collectScroller(targetElement);
|
|
14
|
+
const popupScrollList = collectScroller(popupElement);
|
|
15
|
+
const win = getWin(popupElement);
|
|
16
|
+
const mergedList = /* @__PURE__ */ new Set([
|
|
17
|
+
win,
|
|
18
|
+
...targetScrollList,
|
|
19
|
+
...popupScrollList
|
|
13
20
|
]);
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
})
|
|
17
|
-
|
|
18
|
-
|
|
21
|
+
mergedList.forEach((scroller) => {
|
|
22
|
+
scroller.addEventListener("scroll", notifyScroll, { passive: true });
|
|
23
|
+
});
|
|
24
|
+
win.addEventListener("resize", notifyScroll, { passive: true });
|
|
25
|
+
onAlign();
|
|
26
|
+
onCleanup(() => {
|
|
27
|
+
mergedList.forEach((scroller) => {
|
|
28
|
+
scroller.removeEventListener("scroll", notifyScroll);
|
|
29
|
+
win.removeEventListener("resize", notifyScroll);
|
|
19
30
|
});
|
|
20
31
|
});
|
|
21
32
|
}
|
|
22
33
|
});
|
|
23
34
|
}
|
|
24
35
|
export {
|
|
25
|
-
|
|
36
|
+
useWatch as default
|
|
26
37
|
};
|
|
@@ -1 +1,67 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const util$1 = require("@v-c/util");
|
|
4
|
+
const shadow = require("@v-c/util/dist/Dom/shadow");
|
|
5
|
+
const vue = require("vue");
|
|
6
|
+
const util = require("../util.cjs");
|
|
7
|
+
function useWinClick(open, clickToHide, targetEle, popupEle, mask, maskClosable, inPopupOrChild, triggerOpen) {
|
|
8
|
+
const openRef = vue.shallowRef(open.value);
|
|
9
|
+
vue.watchEffect(() => {
|
|
10
|
+
openRef.value = open.value;
|
|
11
|
+
});
|
|
12
|
+
const popupPointerDownRef = vue.shallowRef(false);
|
|
13
|
+
vue.watch(
|
|
14
|
+
[clickToHide, targetEle, popupEle, mask, maskClosable],
|
|
15
|
+
([clickToHide2, targetEle2, popupEle2, mask2, maskClosable2], _o, onCleanup) => {
|
|
16
|
+
if (clickToHide2 && popupEle2 && (!mask2 || maskClosable2)) {
|
|
17
|
+
const onPointerDown = () => {
|
|
18
|
+
popupPointerDownRef.value = false;
|
|
19
|
+
};
|
|
20
|
+
const onTriggerClose = (e) => {
|
|
21
|
+
if (openRef.value && !inPopupOrChild(e.composedPath?.()?.[0] || e.target) && !popupPointerDownRef.value) {
|
|
22
|
+
triggerOpen(false);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
const win = util.getWin(popupEle2);
|
|
26
|
+
win.addEventListener("pointerdown", onPointerDown, true);
|
|
27
|
+
win.addEventListener("mousedown", onTriggerClose, true);
|
|
28
|
+
win.addEventListener("contextmenu", onTriggerClose, true);
|
|
29
|
+
const targetShadowRoot = shadow.getShadowRoot(targetEle2);
|
|
30
|
+
if (targetShadowRoot) {
|
|
31
|
+
targetShadowRoot.addEventListener("mousedown", onTriggerClose, true);
|
|
32
|
+
targetShadowRoot.addEventListener("contextmenu", onTriggerClose, true);
|
|
33
|
+
}
|
|
34
|
+
if (process.env.NODE_ENV !== "production" && targetEle2) {
|
|
35
|
+
const targetRoot = targetEle2.getRootNode?.();
|
|
36
|
+
const popupRoot = popupEle2.getRootNode?.();
|
|
37
|
+
util$1.warning(
|
|
38
|
+
targetRoot === popupRoot,
|
|
39
|
+
`trigger element and popup element should in same shadow root.`
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
onCleanup(() => {
|
|
43
|
+
win.removeEventListener("pointerdown", onPointerDown, true);
|
|
44
|
+
win.removeEventListener("mousedown", onTriggerClose, true);
|
|
45
|
+
win.removeEventListener("contextmenu", onTriggerClose, true);
|
|
46
|
+
if (targetShadowRoot) {
|
|
47
|
+
targetShadowRoot.removeEventListener(
|
|
48
|
+
"mousedown",
|
|
49
|
+
onTriggerClose,
|
|
50
|
+
true
|
|
51
|
+
);
|
|
52
|
+
targetShadowRoot.removeEventListener(
|
|
53
|
+
"contextmenu",
|
|
54
|
+
onTriggerClose,
|
|
55
|
+
true
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
);
|
|
62
|
+
function onPopupPointerDown() {
|
|
63
|
+
popupPointerDownRef.value = true;
|
|
64
|
+
}
|
|
65
|
+
return onPopupPointerDown;
|
|
66
|
+
}
|
|
67
|
+
exports.default = useWinClick;
|
|
@@ -1,50 +1,67 @@
|
|
|
1
|
-
import { warning
|
|
2
|
-
import { getShadowRoot
|
|
3
|
-
import { shallowRef
|
|
4
|
-
import { getWin
|
|
5
|
-
function
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { warning } from "@v-c/util";
|
|
2
|
+
import { getShadowRoot } from "@v-c/util/dist/Dom/shadow";
|
|
3
|
+
import { shallowRef, watchEffect, watch } from "vue";
|
|
4
|
+
import { getWin } from "../util.js";
|
|
5
|
+
function useWinClick(open, clickToHide, targetEle, popupEle, mask, maskClosable, inPopupOrChild, triggerOpen) {
|
|
6
|
+
const openRef = shallowRef(open.value);
|
|
7
|
+
watchEffect(() => {
|
|
8
|
+
openRef.value = open.value;
|
|
9
9
|
});
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
[
|
|
13
|
-
([
|
|
14
|
-
if (
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
10
|
+
const popupPointerDownRef = shallowRef(false);
|
|
11
|
+
watch(
|
|
12
|
+
[clickToHide, targetEle, popupEle, mask, maskClosable],
|
|
13
|
+
([clickToHide2, targetEle2, popupEle2, mask2, maskClosable2], _o, onCleanup) => {
|
|
14
|
+
if (clickToHide2 && popupEle2 && (!mask2 || maskClosable2)) {
|
|
15
|
+
const onPointerDown = () => {
|
|
16
|
+
popupPointerDownRef.value = false;
|
|
17
|
+
};
|
|
18
|
+
const onTriggerClose = (e) => {
|
|
19
|
+
if (openRef.value && !inPopupOrChild(e.composedPath?.()?.[0] || e.target) && !popupPointerDownRef.value) {
|
|
20
|
+
triggerOpen(false);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
const win = getWin(popupEle2);
|
|
24
|
+
win.addEventListener("pointerdown", onPointerDown, true);
|
|
25
|
+
win.addEventListener("mousedown", onTriggerClose, true);
|
|
26
|
+
win.addEventListener("contextmenu", onTriggerClose, true);
|
|
27
|
+
const targetShadowRoot = getShadowRoot(targetEle2);
|
|
28
|
+
if (targetShadowRoot) {
|
|
29
|
+
targetShadowRoot.addEventListener("mousedown", onTriggerClose, true);
|
|
30
|
+
targetShadowRoot.addEventListener("contextmenu", onTriggerClose, true);
|
|
31
|
+
}
|
|
32
|
+
if (process.env.NODE_ENV !== "production" && targetEle2) {
|
|
33
|
+
const targetRoot = targetEle2.getRootNode?.();
|
|
34
|
+
const popupRoot = popupEle2.getRootNode?.();
|
|
35
|
+
warning(
|
|
36
|
+
targetRoot === popupRoot,
|
|
37
|
+
`trigger element and popup element should in same shadow root.`
|
|
27
38
|
);
|
|
28
39
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
40
|
+
onCleanup(() => {
|
|
41
|
+
win.removeEventListener("pointerdown", onPointerDown, true);
|
|
42
|
+
win.removeEventListener("mousedown", onTriggerClose, true);
|
|
43
|
+
win.removeEventListener("contextmenu", onTriggerClose, true);
|
|
44
|
+
if (targetShadowRoot) {
|
|
45
|
+
targetShadowRoot.removeEventListener(
|
|
46
|
+
"mousedown",
|
|
47
|
+
onTriggerClose,
|
|
48
|
+
true
|
|
49
|
+
);
|
|
50
|
+
targetShadowRoot.removeEventListener(
|
|
51
|
+
"contextmenu",
|
|
52
|
+
onTriggerClose,
|
|
53
|
+
true
|
|
54
|
+
);
|
|
55
|
+
}
|
|
39
56
|
});
|
|
40
57
|
}
|
|
41
58
|
}
|
|
42
59
|
);
|
|
43
|
-
function
|
|
44
|
-
|
|
60
|
+
function onPopupPointerDown() {
|
|
61
|
+
popupPointerDownRef.value = true;
|
|
45
62
|
}
|
|
46
|
-
return
|
|
63
|
+
return onPopupPointerDown;
|
|
47
64
|
}
|
|
48
65
|
export {
|
|
49
|
-
|
|
66
|
+
useWinClick as default
|
|
50
67
|
};
|