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