@v-c/util 0.0.12 → 0.0.13
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/Children/isFragment.cjs +7 -1
- package/dist/Children/isFragment.js +4 -4
- package/dist/Children/toArray.cjs +20 -1
- package/dist/Children/toArray.js +17 -8
- package/dist/Dom/addEventListener.cjs +13 -1
- package/dist/Dom/addEventListener.js +7 -5
- package/dist/Dom/canUseDom.cjs +6 -1
- package/dist/Dom/canUseDom.js +3 -3
- package/dist/Dom/class.cjs +29 -1
- package/dist/Dom/class.js +23 -13
- package/dist/Dom/contains.cjs +16 -1
- package/dist/Dom/contains.js +12 -12
- package/dist/Dom/css.cjs +96 -1
- package/dist/Dom/css.js +69 -48
- package/dist/Dom/dynamicCSS.cjs +110 -1
- package/dist/Dom/dynamicCSS.js +92 -59
- package/dist/Dom/findDOMNode.cjs +16 -1
- package/dist/Dom/findDOMNode.js +12 -8
- package/dist/Dom/focus.cjs +60 -1
- package/dist/Dom/focus.js +48 -28
- package/dist/Dom/isVisible.cjs +22 -1
- package/dist/Dom/isVisible.js +16 -16
- package/dist/Dom/scrollLocker.cjs +89 -1
- package/dist/Dom/scrollLocker.js +70 -45
- package/dist/Dom/shadow.cjs +13 -1
- package/dist/Dom/shadow.js +8 -8
- package/dist/Dom/styleChecker.cjs +25 -1
- package/dist/Dom/styleChecker.js +19 -14
- package/dist/Dom/support.cjs +28 -1
- package/dist/Dom/support.js +16 -12
- package/dist/KeyCode.cjs +523 -1
- package/dist/KeyCode.js +62 -55
- package/dist/Portal.cjs +48 -1
- package/dist/Portal.js +34 -19
- package/dist/PortalWrapper.cjs +169 -1
- package/dist/PortalWrapper.js +133 -79
- package/dist/classnames.cjs +45 -1
- package/dist/classnames.js +38 -25
- package/dist/composeProps.cjs +19 -1
- package/dist/composeProps.js +15 -9
- package/dist/createRef.cjs +24 -1
- package/dist/createRef.js +16 -13
- package/dist/debug/diff.cjs +50 -1
- package/dist/debug/diff.js +39 -30
- package/dist/deprecated.cjs +10 -1
- package/dist/deprecated.js +7 -5
- package/dist/getScrollBarSize.cjs +51 -1
- package/dist/getScrollBarSize.js +39 -25
- package/dist/guid.cjs +7 -1
- package/dist/guid.js +4 -4
- package/dist/hooks/useEvent.cjs +6 -1
- package/dist/hooks/useEvent.js +3 -3
- package/dist/hooks/useId.cjs +18 -1
- package/dist/hooks/useId.js +14 -8
- package/dist/hooks/useLayoutEffect.cjs +58 -1
- package/dist/hooks/useLayoutEffect.js +50 -20
- package/dist/hooks/useMemo.cjs +16 -1
- package/dist/hooks/useMemo.js +13 -7
- package/dist/hooks/useMergedState.cjs +30 -1
- package/dist/hooks/useMergedState.js +25 -16
- package/dist/hooks/useMobile.cjs +16 -1
- package/dist/hooks/useMobile.js +13 -11
- package/dist/hooks/useState.cjs +12 -1
- package/dist/hooks/useState.js +8 -7
- package/dist/index.cjs +11 -1
- package/dist/index.js +9 -9
- package/dist/isEqual.cjs +36 -1
- package/dist/isEqual.js +30 -26
- package/dist/isMobile.cjs +13 -1
- package/dist/isMobile.js +7 -7
- package/dist/isValid.cjs +6 -1
- package/dist/isValid.js +3 -3
- package/dist/omit.cjs +12 -1
- package/dist/omit.js +9 -6
- package/dist/pickAttrs.cjs +41 -3
- package/dist/pickAttrs.js +37 -22
- package/dist/props-util/index.cjs +69 -1
- package/dist/props-util/index.js +62 -32
- package/dist/raf.cjs +48 -1
- package/dist/raf.js +37 -26
- package/dist/setStyle.cjs +17 -1
- package/dist/setStyle.js +13 -9
- package/dist/switchScrollingEffect.cjs +38 -1
- package/dist/switchScrollingEffect.js +27 -20
- package/dist/test/domHook.cjs +52 -1
- package/dist/test/domHook.js +43 -28
- package/dist/type.cjs +51 -1
- package/dist/type.js +39 -37
- package/dist/utils/checkSlotProp.cjs +13 -1
- package/dist/utils/checkSlotProp.js +10 -3
- package/dist/utils/get.cjs +12 -1
- package/dist/utils/get.js +8 -8
- package/dist/utils/omit.cjs +10 -1
- package/dist/utils/omit.js +7 -6
- package/dist/utils/set.cjs +64 -1
- package/dist/utils/set.js +54 -32
- package/dist/utils/transition.cjs +96 -1
- package/dist/utils/transition.d.ts +2 -2
- package/dist/utils/transition.js +70 -65
- package/dist/utils/watchState.cjs +20 -1
- package/dist/utils/watchState.js +15 -10
- package/dist/vnode.cjs +56 -1
- package/dist/vnode.js +46 -30
- package/dist/vueuse/unref-element.cjs +8 -1
- package/dist/vueuse/unref-element.js +5 -5
- package/dist/warning.cjs +53 -1
- package/dist/warning.js +40 -35
- package/package.json +1 -1
package/dist/KeyCode.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const KeyCode = {
|
|
2
2
|
/**
|
|
3
3
|
* MAC_ENTER
|
|
4
4
|
*/
|
|
@@ -448,69 +448,76 @@ const E = {
|
|
|
448
448
|
/**
|
|
449
449
|
* whether text and modified key is entered at the same time.
|
|
450
450
|
*/
|
|
451
|
-
isTextModifyingKeyEvent: function(
|
|
452
|
-
const { keyCode
|
|
453
|
-
if (
|
|
454
|
-
return
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
case
|
|
458
|
-
case
|
|
459
|
-
case
|
|
460
|
-
case
|
|
461
|
-
case
|
|
462
|
-
case
|
|
463
|
-
case
|
|
464
|
-
case
|
|
465
|
-
case
|
|
466
|
-
case
|
|
467
|
-
case
|
|
468
|
-
case
|
|
469
|
-
case
|
|
470
|
-
case
|
|
471
|
-
case
|
|
472
|
-
case
|
|
473
|
-
case
|
|
474
|
-
case
|
|
475
|
-
case
|
|
476
|
-
case
|
|
477
|
-
case
|
|
478
|
-
case
|
|
479
|
-
|
|
451
|
+
isTextModifyingKeyEvent: function isTextModifyingKeyEvent(e) {
|
|
452
|
+
const { keyCode } = e;
|
|
453
|
+
if (e.altKey && !e.ctrlKey || e.metaKey || keyCode >= KeyCode.F1 && keyCode <= KeyCode.F12) {
|
|
454
|
+
return false;
|
|
455
|
+
}
|
|
456
|
+
switch (keyCode) {
|
|
457
|
+
case KeyCode.ALT:
|
|
458
|
+
case KeyCode.CAPS_LOCK:
|
|
459
|
+
case KeyCode.CONTEXT_MENU:
|
|
460
|
+
case KeyCode.CTRL:
|
|
461
|
+
case KeyCode.DOWN:
|
|
462
|
+
case KeyCode.END:
|
|
463
|
+
case KeyCode.ESC:
|
|
464
|
+
case KeyCode.HOME:
|
|
465
|
+
case KeyCode.INSERT:
|
|
466
|
+
case KeyCode.LEFT:
|
|
467
|
+
case KeyCode.MAC_FF_META:
|
|
468
|
+
case KeyCode.META:
|
|
469
|
+
case KeyCode.NUMLOCK:
|
|
470
|
+
case KeyCode.NUM_CENTER:
|
|
471
|
+
case KeyCode.PAGE_DOWN:
|
|
472
|
+
case KeyCode.PAGE_UP:
|
|
473
|
+
case KeyCode.PAUSE:
|
|
474
|
+
case KeyCode.PRINT_SCREEN:
|
|
475
|
+
case KeyCode.RIGHT:
|
|
476
|
+
case KeyCode.SHIFT:
|
|
477
|
+
case KeyCode.UP:
|
|
478
|
+
case KeyCode.WIN_KEY:
|
|
479
|
+
case KeyCode.WIN_KEY_RIGHT:
|
|
480
|
+
return false;
|
|
480
481
|
default:
|
|
481
|
-
return
|
|
482
|
+
return true;
|
|
482
483
|
}
|
|
483
484
|
},
|
|
484
485
|
/**
|
|
485
486
|
* whether character is entered.
|
|
486
487
|
*/
|
|
487
|
-
isCharacterKey: function(
|
|
488
|
-
if (
|
|
489
|
-
return
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
case
|
|
498
|
-
case
|
|
499
|
-
case
|
|
500
|
-
case
|
|
501
|
-
case
|
|
502
|
-
case
|
|
503
|
-
case
|
|
504
|
-
case
|
|
505
|
-
case
|
|
506
|
-
case
|
|
507
|
-
case
|
|
508
|
-
|
|
488
|
+
isCharacterKey: function isCharacterKey(keyCode) {
|
|
489
|
+
if (keyCode >= KeyCode.ZERO && keyCode <= KeyCode.NINE)
|
|
490
|
+
return true;
|
|
491
|
+
if (keyCode >= KeyCode.NUM_ZERO && keyCode <= KeyCode.NUM_MULTIPLY)
|
|
492
|
+
return true;
|
|
493
|
+
if (keyCode >= KeyCode.A && keyCode <= KeyCode.Z)
|
|
494
|
+
return true;
|
|
495
|
+
if (window.navigator.userAgent.includes("WebKit") && keyCode === 0)
|
|
496
|
+
return true;
|
|
497
|
+
switch (keyCode) {
|
|
498
|
+
case KeyCode.SPACE:
|
|
499
|
+
case KeyCode.QUESTION_MARK:
|
|
500
|
+
case KeyCode.NUM_PLUS:
|
|
501
|
+
case KeyCode.NUM_MINUS:
|
|
502
|
+
case KeyCode.NUM_PERIOD:
|
|
503
|
+
case KeyCode.NUM_DIVISION:
|
|
504
|
+
case KeyCode.SEMICOLON:
|
|
505
|
+
case KeyCode.DASH:
|
|
506
|
+
case KeyCode.EQUALS:
|
|
507
|
+
case KeyCode.COMMA:
|
|
508
|
+
case KeyCode.PERIOD:
|
|
509
|
+
case KeyCode.SLASH:
|
|
510
|
+
case KeyCode.APOSTROPHE:
|
|
511
|
+
case KeyCode.SINGLE_QUOTE:
|
|
512
|
+
case KeyCode.OPEN_SQUARE_BRACKET:
|
|
513
|
+
case KeyCode.BACKSLASH:
|
|
514
|
+
case KeyCode.CLOSE_SQUARE_BRACKET:
|
|
515
|
+
return true;
|
|
509
516
|
default:
|
|
510
|
-
return
|
|
517
|
+
return false;
|
|
511
518
|
}
|
|
512
519
|
}
|
|
513
520
|
};
|
|
514
521
|
export {
|
|
515
|
-
|
|
522
|
+
KeyCode as default
|
|
516
523
|
};
|
package/dist/Portal.cjs
CHANGED
|
@@ -1 +1,48 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const vue = require("vue");
|
|
4
|
+
const canUseDom = require("./Dom/canUseDom.cjs");
|
|
5
|
+
const Portal = /* @__PURE__ */ vue.defineComponent((props, ctx) => {
|
|
6
|
+
const parentRef = vue.shallowRef();
|
|
7
|
+
const containerRef = vue.shallowRef();
|
|
8
|
+
const initRef = vue.shallowRef(false);
|
|
9
|
+
if (!initRef.value && canUseDom.default()) {
|
|
10
|
+
containerRef.value = props.getContainer();
|
|
11
|
+
parentRef.value = containerRef.value?.parentNode;
|
|
12
|
+
initRef.value = true;
|
|
13
|
+
}
|
|
14
|
+
vue.onMounted(() => {
|
|
15
|
+
if (containerRef.value?.parentNode === null && parentRef.value !== null) parentRef.value.appendChild(containerRef.value);
|
|
16
|
+
});
|
|
17
|
+
vue.onBeforeUnmount(() => {
|
|
18
|
+
props.didUpdate?.(props);
|
|
19
|
+
});
|
|
20
|
+
vue.onUnmounted(() => {
|
|
21
|
+
containerRef.value?.parentNode?.removeChild?.(containerRef.value);
|
|
22
|
+
});
|
|
23
|
+
return () => {
|
|
24
|
+
if (containerRef.value) {
|
|
25
|
+
return vue.createVNode(vue.Teleport, {
|
|
26
|
+
"to": containerRef.value
|
|
27
|
+
}, {
|
|
28
|
+
default: () => [ctx.slots.default?.()]
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
};
|
|
33
|
+
}, {
|
|
34
|
+
props: {
|
|
35
|
+
didUpdate: {
|
|
36
|
+
type: Function,
|
|
37
|
+
required: false,
|
|
38
|
+
default: void 0
|
|
39
|
+
},
|
|
40
|
+
getContainer: {
|
|
41
|
+
type: Function,
|
|
42
|
+
required: true,
|
|
43
|
+
default: void 0
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
inheritAttrs: false
|
|
47
|
+
});
|
|
48
|
+
exports.default = Portal;
|
package/dist/Portal.js
CHANGED
|
@@ -1,33 +1,48 @@
|
|
|
1
|
-
import { defineComponent
|
|
2
|
-
import
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
import { defineComponent, shallowRef, onMounted, onBeforeUnmount, onUnmounted, createVNode, Teleport } from "vue";
|
|
2
|
+
import canUseDom from "./Dom/canUseDom.js";
|
|
3
|
+
const Portal = /* @__PURE__ */ defineComponent((props, ctx) => {
|
|
4
|
+
const parentRef = shallowRef();
|
|
5
|
+
const containerRef = shallowRef();
|
|
6
|
+
const initRef = shallowRef(false);
|
|
7
|
+
if (!initRef.value && canUseDom()) {
|
|
8
|
+
containerRef.value = props.getContainer();
|
|
9
|
+
parentRef.value = containerRef.value?.parentNode;
|
|
10
|
+
initRef.value = true;
|
|
11
|
+
}
|
|
12
|
+
onMounted(() => {
|
|
13
|
+
if (containerRef.value?.parentNode === null && parentRef.value !== null) parentRef.value.appendChild(containerRef.value);
|
|
14
|
+
});
|
|
15
|
+
onBeforeUnmount(() => {
|
|
16
|
+
props.didUpdate?.(props);
|
|
17
|
+
});
|
|
18
|
+
onUnmounted(() => {
|
|
19
|
+
containerRef.value?.parentNode?.removeChild?.(containerRef.value);
|
|
20
|
+
});
|
|
21
|
+
return () => {
|
|
22
|
+
if (containerRef.value) {
|
|
23
|
+
return createVNode(Teleport, {
|
|
24
|
+
"to": containerRef.value
|
|
25
|
+
}, {
|
|
26
|
+
default: () => [ctx.slots.default?.()]
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
};
|
|
16
31
|
}, {
|
|
17
32
|
props: {
|
|
18
33
|
didUpdate: {
|
|
19
34
|
type: Function,
|
|
20
|
-
required:
|
|
35
|
+
required: false,
|
|
21
36
|
default: void 0
|
|
22
37
|
},
|
|
23
38
|
getContainer: {
|
|
24
39
|
type: Function,
|
|
25
|
-
required:
|
|
40
|
+
required: true,
|
|
26
41
|
default: void 0
|
|
27
42
|
}
|
|
28
43
|
},
|
|
29
|
-
inheritAttrs:
|
|
44
|
+
inheritAttrs: false
|
|
30
45
|
});
|
|
31
46
|
export {
|
|
32
|
-
|
|
47
|
+
Portal as default
|
|
33
48
|
};
|
package/dist/PortalWrapper.cjs
CHANGED
|
@@ -1 +1,169 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const vue = require("vue");
|
|
4
|
+
const canUseDom = require("./Dom/canUseDom.cjs");
|
|
5
|
+
const scrollLocker = require("./Dom/scrollLocker.cjs");
|
|
6
|
+
const Portal = require("./Portal.cjs");
|
|
7
|
+
const raf = require("./raf.cjs");
|
|
8
|
+
const setStyle = require("./setStyle.cjs");
|
|
9
|
+
let openCount = 0;
|
|
10
|
+
const supportDom = canUseDom.default();
|
|
11
|
+
function getOpenCount() {
|
|
12
|
+
return process.env.NODE_ENV === "test" ? openCount : 0;
|
|
13
|
+
}
|
|
14
|
+
let cacheOverflow = {};
|
|
15
|
+
function getParent(getContainer) {
|
|
16
|
+
if (!supportDom) return null;
|
|
17
|
+
if (getContainer) {
|
|
18
|
+
if (typeof getContainer === "string") return document.querySelectorAll(getContainer)[0];
|
|
19
|
+
if (typeof getContainer === "function") return getContainer();
|
|
20
|
+
if (typeof getContainer === "object" && getContainer instanceof window.HTMLElement) {
|
|
21
|
+
return getContainer;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return document.body;
|
|
25
|
+
}
|
|
26
|
+
const PortalWrapper = /* @__PURE__ */ vue.defineComponent((props, ctx) => {
|
|
27
|
+
const container = vue.shallowRef();
|
|
28
|
+
const componentRef = vue.shallowRef();
|
|
29
|
+
const rafId = vue.shallowRef();
|
|
30
|
+
const scrollLocker$1 = vue.shallowRef();
|
|
31
|
+
const removeCurrentContainer = () => {
|
|
32
|
+
container.value?.parentNode?.removeChild(container.value);
|
|
33
|
+
};
|
|
34
|
+
const updateOpenCount = (prevProps) => {
|
|
35
|
+
const {
|
|
36
|
+
visible: prevVisible,
|
|
37
|
+
getContainer: prevGetContainer
|
|
38
|
+
} = prevProps || {};
|
|
39
|
+
const {
|
|
40
|
+
visible,
|
|
41
|
+
getContainer: getContainer2
|
|
42
|
+
} = props;
|
|
43
|
+
if (visible !== prevVisible && supportDom && getParent(getContainer2) === document.body) {
|
|
44
|
+
if (visible && !prevVisible) openCount += 1;
|
|
45
|
+
else if (prevProps) openCount -= 1;
|
|
46
|
+
}
|
|
47
|
+
const getContainerIsFunc = typeof getContainer2 === "function" && typeof prevGetContainer === "function";
|
|
48
|
+
if (getContainerIsFunc ? getContainer2.toString() !== prevGetContainer.toString() : getContainer2 !== prevGetContainer) {
|
|
49
|
+
removeCurrentContainer();
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
const attachToParent = (force = false) => {
|
|
53
|
+
if (force || container.value && !container.value.parentNode) {
|
|
54
|
+
const parent = getParent(props.getContainer);
|
|
55
|
+
if (parent) {
|
|
56
|
+
parent.appendChild(container.value);
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
return true;
|
|
62
|
+
};
|
|
63
|
+
const setWrapperClassName = () => {
|
|
64
|
+
const {
|
|
65
|
+
wrapperClassName
|
|
66
|
+
} = props;
|
|
67
|
+
if (container.value && wrapperClassName && wrapperClassName !== container.value.className) {
|
|
68
|
+
container.value.className = wrapperClassName;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
const getContainer = () => {
|
|
72
|
+
if (!supportDom) return null;
|
|
73
|
+
if (!container.value) {
|
|
74
|
+
container.value = document.createElement("div");
|
|
75
|
+
attachToParent(true);
|
|
76
|
+
}
|
|
77
|
+
setWrapperClassName();
|
|
78
|
+
return container.value;
|
|
79
|
+
};
|
|
80
|
+
vue.onMounted(() => {
|
|
81
|
+
scrollLocker$1.value = new scrollLocker.default({
|
|
82
|
+
container: getParent(props.getContainer)
|
|
83
|
+
});
|
|
84
|
+
updateOpenCount();
|
|
85
|
+
if (!attachToParent()) {
|
|
86
|
+
rafId.value = raf.default(() => {
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
vue.onUpdated(() => {
|
|
91
|
+
updateOpenCount(props);
|
|
92
|
+
updateOpenCount(props);
|
|
93
|
+
setWrapperClassName();
|
|
94
|
+
attachToParent();
|
|
95
|
+
});
|
|
96
|
+
vue.onBeforeUnmount(() => {
|
|
97
|
+
const {
|
|
98
|
+
visible,
|
|
99
|
+
getContainer: getContainer2
|
|
100
|
+
} = props;
|
|
101
|
+
if (supportDom && getParent(getContainer2) === document.body) {
|
|
102
|
+
openCount = visible && openCount ? openCount - 1 : openCount;
|
|
103
|
+
}
|
|
104
|
+
removeCurrentContainer();
|
|
105
|
+
raf.default.cancel(rafId.value);
|
|
106
|
+
});
|
|
107
|
+
const switchScrollingEffect = () => {
|
|
108
|
+
if (openCount === 1 && !Object.keys(cacheOverflow).length) {
|
|
109
|
+
switchScrollingEffect();
|
|
110
|
+
cacheOverflow = setStyle.default({
|
|
111
|
+
overflow: "hidden",
|
|
112
|
+
overflowX: "hidden",
|
|
113
|
+
overflowY: "hidden"
|
|
114
|
+
});
|
|
115
|
+
} else if (!openCount) {
|
|
116
|
+
setStyle.default(cacheOverflow);
|
|
117
|
+
cacheOverflow = {};
|
|
118
|
+
switchScrollingEffect();
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
return () => {
|
|
122
|
+
const {
|
|
123
|
+
forceRender,
|
|
124
|
+
visible
|
|
125
|
+
} = props;
|
|
126
|
+
let portal = null;
|
|
127
|
+
const childProps = {
|
|
128
|
+
getOpenCount,
|
|
129
|
+
getContainer,
|
|
130
|
+
switchScrollingEffect,
|
|
131
|
+
scrollLocker: scrollLocker$1.value
|
|
132
|
+
};
|
|
133
|
+
if (forceRender || visible || componentRef.value) {
|
|
134
|
+
portal = vue.createVNode(Portal.default, {
|
|
135
|
+
"getContainer": getContainer,
|
|
136
|
+
"ref": componentRef
|
|
137
|
+
}, {
|
|
138
|
+
default: () => [ctx?.slots?.default(childProps)]
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
return portal;
|
|
142
|
+
};
|
|
143
|
+
}, {
|
|
144
|
+
props: {
|
|
145
|
+
visible: {
|
|
146
|
+
type: Boolean,
|
|
147
|
+
required: false,
|
|
148
|
+
default: void 0
|
|
149
|
+
},
|
|
150
|
+
getContainer: {
|
|
151
|
+
type: [String, Function],
|
|
152
|
+
required: false,
|
|
153
|
+
skipCheck: true,
|
|
154
|
+
default: void 0
|
|
155
|
+
},
|
|
156
|
+
wrapperClassName: {
|
|
157
|
+
type: String,
|
|
158
|
+
required: false,
|
|
159
|
+
default: void 0
|
|
160
|
+
},
|
|
161
|
+
forceRender: {
|
|
162
|
+
type: Boolean,
|
|
163
|
+
required: false,
|
|
164
|
+
default: void 0
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
exports.default = PortalWrapper;
|
|
169
|
+
exports.getOpenCount = getOpenCount;
|
package/dist/PortalWrapper.js
CHANGED
|
@@ -1,115 +1,169 @@
|
|
|
1
|
-
import { defineComponent
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
let
|
|
8
|
-
const
|
|
9
|
-
function
|
|
10
|
-
return process.env.NODE_ENV === "test" ?
|
|
1
|
+
import { defineComponent, shallowRef, onMounted, onUpdated, onBeforeUnmount, createVNode } from "vue";
|
|
2
|
+
import canUseDom from "./Dom/canUseDom.js";
|
|
3
|
+
import ScrollLocker from "./Dom/scrollLocker.js";
|
|
4
|
+
import Portal from "./Portal.js";
|
|
5
|
+
import wrapperRaf from "./raf.js";
|
|
6
|
+
import setStyle from "./setStyle.js";
|
|
7
|
+
let openCount = 0;
|
|
8
|
+
const supportDom = canUseDom();
|
|
9
|
+
function getOpenCount() {
|
|
10
|
+
return process.env.NODE_ENV === "test" ? openCount : 0;
|
|
11
11
|
}
|
|
12
|
-
let
|
|
13
|
-
function
|
|
14
|
-
if (!
|
|
15
|
-
if (
|
|
16
|
-
if (typeof
|
|
17
|
-
if (typeof
|
|
18
|
-
if (typeof
|
|
19
|
-
return
|
|
12
|
+
let cacheOverflow = {};
|
|
13
|
+
function getParent(getContainer) {
|
|
14
|
+
if (!supportDom) return null;
|
|
15
|
+
if (getContainer) {
|
|
16
|
+
if (typeof getContainer === "string") return document.querySelectorAll(getContainer)[0];
|
|
17
|
+
if (typeof getContainer === "function") return getContainer();
|
|
18
|
+
if (typeof getContainer === "object" && getContainer instanceof window.HTMLElement) {
|
|
19
|
+
return getContainer;
|
|
20
|
+
}
|
|
20
21
|
}
|
|
21
22
|
return document.body;
|
|
22
23
|
}
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
const PortalWrapper = /* @__PURE__ */ defineComponent((props, ctx) => {
|
|
25
|
+
const container = shallowRef();
|
|
26
|
+
const componentRef = shallowRef();
|
|
27
|
+
const rafId = shallowRef();
|
|
28
|
+
const scrollLocker = shallowRef();
|
|
29
|
+
const removeCurrentContainer = () => {
|
|
30
|
+
container.value?.parentNode?.removeChild(container.value);
|
|
31
|
+
};
|
|
32
|
+
const updateOpenCount = (prevProps) => {
|
|
33
|
+
const {
|
|
34
|
+
visible: prevVisible,
|
|
35
|
+
getContainer: prevGetContainer
|
|
36
|
+
} = prevProps || {};
|
|
27
37
|
const {
|
|
28
|
-
visible
|
|
29
|
-
getContainer:
|
|
30
|
-
} =
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
a !== o && s && c(i) === document.body && (a && !o ? r += 1 : t && (r -= 1)), (typeof i == "function" && typeof l == "function" ? i.toString() !== l.toString() : i !== l) && g();
|
|
35
|
-
}, p = (t = !1) => {
|
|
36
|
-
if (t || n.value && !n.value.parentNode) {
|
|
37
|
-
const o = c(e.getContainer);
|
|
38
|
-
return o ? (o.appendChild(n.value), !0) : !1;
|
|
38
|
+
visible,
|
|
39
|
+
getContainer: getContainer2
|
|
40
|
+
} = props;
|
|
41
|
+
if (visible !== prevVisible && supportDom && getParent(getContainer2) === document.body) {
|
|
42
|
+
if (visible && !prevVisible) openCount += 1;
|
|
43
|
+
else if (prevProps) openCount -= 1;
|
|
39
44
|
}
|
|
40
|
-
|
|
41
|
-
|
|
45
|
+
const getContainerIsFunc = typeof getContainer2 === "function" && typeof prevGetContainer === "function";
|
|
46
|
+
if (getContainerIsFunc ? getContainer2.toString() !== prevGetContainer.toString() : getContainer2 !== prevGetContainer) {
|
|
47
|
+
removeCurrentContainer();
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const attachToParent = (force = false) => {
|
|
51
|
+
if (force || container.value && !container.value.parentNode) {
|
|
52
|
+
const parent = getParent(props.getContainer);
|
|
53
|
+
if (parent) {
|
|
54
|
+
parent.appendChild(container.value);
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
return true;
|
|
60
|
+
};
|
|
61
|
+
const setWrapperClassName = () => {
|
|
42
62
|
const {
|
|
43
|
-
wrapperClassName
|
|
44
|
-
} =
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
63
|
+
wrapperClassName
|
|
64
|
+
} = props;
|
|
65
|
+
if (container.value && wrapperClassName && wrapperClassName !== container.value.className) {
|
|
66
|
+
container.value.className = wrapperClassName;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
const getContainer = () => {
|
|
70
|
+
if (!supportDom) return null;
|
|
71
|
+
if (!container.value) {
|
|
72
|
+
container.value = document.createElement("div");
|
|
73
|
+
attachToParent(true);
|
|
74
|
+
}
|
|
75
|
+
setWrapperClassName();
|
|
76
|
+
return container.value;
|
|
77
|
+
};
|
|
78
|
+
onMounted(() => {
|
|
79
|
+
scrollLocker.value = new ScrollLocker({
|
|
80
|
+
container: getParent(props.getContainer)
|
|
81
|
+
});
|
|
82
|
+
updateOpenCount();
|
|
83
|
+
if (!attachToParent()) {
|
|
84
|
+
rafId.value = wrapperRaf(() => {
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
onUpdated(() => {
|
|
89
|
+
updateOpenCount(props);
|
|
90
|
+
updateOpenCount(props);
|
|
91
|
+
setWrapperClassName();
|
|
92
|
+
attachToParent();
|
|
93
|
+
});
|
|
94
|
+
onBeforeUnmount(() => {
|
|
55
95
|
const {
|
|
56
|
-
visible
|
|
57
|
-
getContainer:
|
|
58
|
-
} =
|
|
59
|
-
|
|
96
|
+
visible,
|
|
97
|
+
getContainer: getContainer2
|
|
98
|
+
} = props;
|
|
99
|
+
if (supportDom && getParent(getContainer2) === document.body) {
|
|
100
|
+
openCount = visible && openCount ? openCount - 1 : openCount;
|
|
101
|
+
}
|
|
102
|
+
removeCurrentContainer();
|
|
103
|
+
wrapperRaf.cancel(rafId.value);
|
|
60
104
|
});
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
105
|
+
const switchScrollingEffect = () => {
|
|
106
|
+
if (openCount === 1 && !Object.keys(cacheOverflow).length) {
|
|
107
|
+
switchScrollingEffect();
|
|
108
|
+
cacheOverflow = setStyle({
|
|
109
|
+
overflow: "hidden",
|
|
110
|
+
overflowX: "hidden",
|
|
111
|
+
overflowY: "hidden"
|
|
112
|
+
});
|
|
113
|
+
} else if (!openCount) {
|
|
114
|
+
setStyle(cacheOverflow);
|
|
115
|
+
cacheOverflow = {};
|
|
116
|
+
switchScrollingEffect();
|
|
117
|
+
}
|
|
67
118
|
};
|
|
68
119
|
return () => {
|
|
69
120
|
const {
|
|
70
|
-
forceRender
|
|
71
|
-
visible
|
|
72
|
-
} =
|
|
73
|
-
let
|
|
74
|
-
const
|
|
75
|
-
getOpenCount
|
|
76
|
-
getContainer
|
|
77
|
-
switchScrollingEffect
|
|
78
|
-
scrollLocker:
|
|
121
|
+
forceRender,
|
|
122
|
+
visible
|
|
123
|
+
} = props;
|
|
124
|
+
let portal = null;
|
|
125
|
+
const childProps = {
|
|
126
|
+
getOpenCount,
|
|
127
|
+
getContainer,
|
|
128
|
+
switchScrollingEffect,
|
|
129
|
+
scrollLocker: scrollLocker.value
|
|
79
130
|
};
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
131
|
+
if (forceRender || visible || componentRef.value) {
|
|
132
|
+
portal = createVNode(Portal, {
|
|
133
|
+
"getContainer": getContainer,
|
|
134
|
+
"ref": componentRef
|
|
135
|
+
}, {
|
|
136
|
+
default: () => [ctx?.slots?.default(childProps)]
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
return portal;
|
|
86
140
|
};
|
|
87
141
|
}, {
|
|
88
142
|
props: {
|
|
89
143
|
visible: {
|
|
90
144
|
type: Boolean,
|
|
91
|
-
required:
|
|
145
|
+
required: false,
|
|
92
146
|
default: void 0
|
|
93
147
|
},
|
|
94
148
|
getContainer: {
|
|
95
149
|
type: [String, Function],
|
|
96
|
-
required:
|
|
97
|
-
skipCheck:
|
|
150
|
+
required: false,
|
|
151
|
+
skipCheck: true,
|
|
98
152
|
default: void 0
|
|
99
153
|
},
|
|
100
154
|
wrapperClassName: {
|
|
101
155
|
type: String,
|
|
102
|
-
required:
|
|
156
|
+
required: false,
|
|
103
157
|
default: void 0
|
|
104
158
|
},
|
|
105
159
|
forceRender: {
|
|
106
160
|
type: Boolean,
|
|
107
|
-
required:
|
|
161
|
+
required: false,
|
|
108
162
|
default: void 0
|
|
109
163
|
}
|
|
110
164
|
}
|
|
111
165
|
});
|
|
112
166
|
export {
|
|
113
|
-
|
|
114
|
-
|
|
167
|
+
PortalWrapper as default,
|
|
168
|
+
getOpenCount
|
|
115
169
|
};
|