1 | import Vue from 'vue';
|
2 |
|
3 |
|
4 | const { Fragment, Comment } = Vue;
|
5 |
|
6 | function callIfNeeded(fnOrResult, args) {
|
7 | return fnOrResult instanceof Function ? fnOrResult(args) : fnOrResult;
|
8 | }
|
9 |
|
10 | function isEmpty(vnode) {
|
11 | if (!vnode || (Comment && vnode.type === Comment)) {
|
12 | return true;
|
13 | }
|
14 |
|
15 | if (Array.isArray(vnode)) {
|
16 |
|
17 | return vnode.every(isEmpty);
|
18 | }
|
19 |
|
20 | if (Fragment && vnode.type === Fragment) {
|
21 |
|
22 |
|
23 | return vnode.children.every(isEmpty);
|
24 | }
|
25 |
|
26 | return false;
|
27 | }
|
28 |
|
29 | export function isSlotEmpty(vueInstance, slot, slotArgs) {
|
30 | const isVue3 = Boolean(Fragment);
|
31 |
|
32 | const slotContent = isVue3
|
33 | ?
|
34 |
|
35 | callIfNeeded(vueInstance.$slots[slot] || vueInstance.$scopedSlots[slot], slotArgs)
|
36 | : vueInstance.$scopedSlots[slot]?.(slotArgs);
|
37 |
|
38 |
|
39 | return isEmpty(slotContent);
|
40 | }
|