@gitlab/ui 128.2.1 → 128.2.3
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.
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import Vue from 'vue';
|
|
2
2
|
import isFunction from 'lodash/isFunction';
|
|
3
|
-
import isString from 'lodash/isString';
|
|
4
3
|
import { DISCLOSURE_DROPDOWN_ITEM_NAME, DISCLOSURE_DROPDOWN_GROUP_NAME } from './constants';
|
|
5
4
|
|
|
6
5
|
const itemValidator = item => {
|
|
@@ -16,28 +15,58 @@ group.items.every(isItem);
|
|
|
16
15
|
const itemsValidator = items => items.every(isItem) || items.every(isGroup);
|
|
17
16
|
const isListItem = tag => ['gl-disclosure-dropdown-group', 'gl-disclosure-dropdown-item', 'li'].includes(tag);
|
|
18
17
|
const isValidSlotTagVue2 = vNode => {
|
|
19
|
-
var _vNode$componentOptio;
|
|
20
|
-
|
|
18
|
+
var _vNode$componentOptio, _vNode$componentOptio2, _vNode$componentOptio3, _vNode$componentOptio4;
|
|
19
|
+
if (!vNode) return false;
|
|
20
|
+
const tag = ((_vNode$componentOptio = vNode.componentOptions) === null || _vNode$componentOptio === void 0 ? void 0 : _vNode$componentOptio.tag) || vNode.tag;
|
|
21
|
+
if (isListItem(tag)) return true;
|
|
22
|
+
const componentName = (_vNode$componentOptio2 = vNode.componentOptions) === null || _vNode$componentOptio2 === void 0 ? void 0 : (_vNode$componentOptio3 = _vNode$componentOptio2.Ctor) === null || _vNode$componentOptio3 === void 0 ? void 0 : (_vNode$componentOptio4 = _vNode$componentOptio3.options) === null || _vNode$componentOptio4 === void 0 ? void 0 : _vNode$componentOptio4.name;
|
|
23
|
+
return [DISCLOSURE_DROPDOWN_ITEM_NAME, DISCLOSURE_DROPDOWN_GROUP_NAME].includes(componentName);
|
|
21
24
|
};
|
|
22
25
|
const isValidSlotTagVue3 = vNode => {
|
|
23
26
|
var _vNode$type;
|
|
27
|
+
if (!vNode) return false;
|
|
24
28
|
return [DISCLOSURE_DROPDOWN_ITEM_NAME, DISCLOSURE_DROPDOWN_GROUP_NAME].includes((_vNode$type = vNode.type) === null || _vNode$type === void 0 ? void 0 : _vNode$type.name) || vNode.type === 'li';
|
|
25
29
|
};
|
|
30
|
+
const isSkippableVue2 = vNode => {
|
|
31
|
+
if (!vNode) return true;
|
|
32
|
+
if (vNode.isComment) return true;
|
|
33
|
+
if (!vNode.tag && typeof vNode.text === 'string' && !vNode.text.trim()) return true;
|
|
34
|
+
return false;
|
|
35
|
+
};
|
|
26
36
|
const hasOnlyListItemsVue2 = defaultSlot => {
|
|
27
37
|
const nodes = defaultSlot();
|
|
28
38
|
if (!Array.isArray(nodes)) {
|
|
29
39
|
return false;
|
|
30
40
|
}
|
|
31
|
-
const
|
|
32
|
-
|
|
41
|
+
const candidateNodes = nodes.filter(vNode => !isSkippableVue2(vNode));
|
|
42
|
+
if (candidateNodes.length === 0) return true;
|
|
43
|
+
return candidateNodes.every(vNode => isValidSlotTagVue2(vNode));
|
|
44
|
+
};
|
|
45
|
+
const isSkippableVue3 = vNode => {
|
|
46
|
+
var _vNode$children;
|
|
47
|
+
if (!vNode) return true;
|
|
48
|
+
if (vNode.type === Vue.Comment) return true;
|
|
49
|
+
if (vNode.type === Vue.Text && !((_vNode$children = vNode.children) !== null && _vNode$children !== void 0 && _vNode$children.trim())) return true;
|
|
50
|
+
if (vNode.type === Vue.Fragment && (!vNode.children || vNode.children.length === 0)) return true;
|
|
51
|
+
return false;
|
|
52
|
+
};
|
|
53
|
+
const validateNodesRecursiveVue3 = nodes => {
|
|
54
|
+
if (!Array.isArray(nodes) || nodes.length === 0) return true;
|
|
55
|
+
const candidateNodes = nodes.filter(vNode => !isSkippableVue3(vNode));
|
|
56
|
+
if (candidateNodes.length === 0) return true;
|
|
57
|
+
return candidateNodes.every(vNode => {
|
|
58
|
+
if (isValidSlotTagVue3(vNode)) return true;
|
|
59
|
+
if (vNode.type === Vue.Fragment && Array.isArray(vNode.children)) {
|
|
60
|
+
return validateNodesRecursiveVue3(vNode.children);
|
|
61
|
+
}
|
|
62
|
+
return false;
|
|
63
|
+
});
|
|
33
64
|
};
|
|
34
65
|
const hasOnlyListItemsVue3 = defaultSlot => {
|
|
35
66
|
const nodes = defaultSlot();
|
|
36
67
|
const fragment = nodes.find(node => Array.isArray(node.children) && node.children.length);
|
|
37
68
|
const targetNodes = fragment ? fragment.children : nodes;
|
|
38
|
-
return targetNodes
|
|
39
|
-
// Remove empty text vNodes
|
|
40
|
-
.filter(vNode => !isString(vNode.text) || vNode.text.trim().length > 0).every(vNode => isValidSlotTagVue3(vNode));
|
|
69
|
+
return validateNodesRecursiveVue3(targetNodes);
|
|
41
70
|
};
|
|
42
71
|
const hasOnlyListItems = defaultSlot => {
|
|
43
72
|
if (!isFunction(defaultSlot)) {
|