@gitlab/ui 128.2.1 → 128.2.2

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
- return Boolean(vNode) && isListItem(((_vNode$componentOptio = vNode.componentOptions) === null || _vNode$componentOptio === void 0 ? void 0 : _vNode$componentOptio.tag) || vNode.tag);
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 tags = nodes.filter(vNode => vNode.tag);
32
- return tags.length && tags.every(tag => isValidSlotTagVue2(tag));
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)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gitlab/ui",
3
- "version": "128.2.1",
3
+ "version": "128.2.2",
4
4
  "description": "GitLab UI Components",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -165,7 +165,7 @@
165
165
  "start-server-and-test": "^2.1.3",
166
166
  "storybook": "^7.6.20",
167
167
  "storybook-dark-mode": "4.0.2",
168
- "style-dictionary": "^5.1.3",
168
+ "style-dictionary": "^5.1.4",
169
169
  "style-loader": "^4",
170
170
  "tailwindcss": "3.4.19",
171
171
  "vue": "2.7.16",
@@ -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) => item?.text?.length > 0 && !Array.isArray(item?.items);
@@ -20,16 +19,29 @@ const itemsValidator = (items) => items.every(isItem) || items.every(isGroup);
20
19
  const isListItem = (tag) =>
21
20
  ['gl-disclosure-dropdown-group', 'gl-disclosure-dropdown-item', 'li'].includes(tag);
22
21
 
23
- const isValidSlotTagVue2 = (vNode) =>
24
- Boolean(vNode) && isListItem(vNode.componentOptions?.tag || vNode.tag);
22
+ const isValidSlotTagVue2 = (vNode) => {
23
+ if (!vNode) return false;
24
+ const tag = vNode.componentOptions?.tag || vNode.tag;
25
+ if (isListItem(tag)) return true;
26
+ const componentName = vNode.componentOptions?.Ctor?.options?.name;
27
+ return [DISCLOSURE_DROPDOWN_ITEM_NAME, DISCLOSURE_DROPDOWN_GROUP_NAME].includes(componentName);
28
+ };
25
29
 
26
30
  const isValidSlotTagVue3 = (vNode) => {
31
+ if (!vNode) return false;
27
32
  return (
28
33
  [DISCLOSURE_DROPDOWN_ITEM_NAME, DISCLOSURE_DROPDOWN_GROUP_NAME].includes(vNode.type?.name) ||
29
34
  vNode.type === 'li'
30
35
  );
31
36
  };
32
37
 
38
+ const isSkippableVue2 = (vNode) => {
39
+ if (!vNode) return true;
40
+ if (vNode.isComment) return true;
41
+ if (!vNode.tag && typeof vNode.text === 'string' && !vNode.text.trim()) return true;
42
+ return false;
43
+ };
44
+
33
45
  const hasOnlyListItemsVue2 = (defaultSlot) => {
34
46
  const nodes = defaultSlot();
35
47
 
@@ -37,9 +49,35 @@ const hasOnlyListItemsVue2 = (defaultSlot) => {
37
49
  return false;
38
50
  }
39
51
 
40
- const tags = nodes.filter((vNode) => vNode.tag);
52
+ const candidateNodes = nodes.filter((vNode) => !isSkippableVue2(vNode));
53
+
54
+ if (candidateNodes.length === 0) return true;
55
+
56
+ return candidateNodes.every((vNode) => isValidSlotTagVue2(vNode));
57
+ };
58
+
59
+ const isSkippableVue3 = (vNode) => {
60
+ if (!vNode) return true;
61
+ if (vNode.type === Vue.Comment) return true;
62
+ if (vNode.type === Vue.Text && !vNode.children?.trim()) return true;
63
+ if (vNode.type === Vue.Fragment && (!vNode.children || vNode.children.length === 0)) return true;
64
+ return false;
65
+ };
66
+
67
+ const validateNodesRecursiveVue3 = (nodes) => {
68
+ if (!Array.isArray(nodes) || nodes.length === 0) return true;
69
+
70
+ const candidateNodes = nodes.filter((vNode) => !isSkippableVue3(vNode));
71
+
72
+ if (candidateNodes.length === 0) return true;
41
73
 
42
- return tags.length && tags.every((tag) => isValidSlotTagVue2(tag));
74
+ return candidateNodes.every((vNode) => {
75
+ if (isValidSlotTagVue3(vNode)) return true;
76
+ if (vNode.type === Vue.Fragment && Array.isArray(vNode.children)) {
77
+ return validateNodesRecursiveVue3(vNode.children);
78
+ }
79
+ return false;
80
+ });
43
81
  };
44
82
 
45
83
  const hasOnlyListItemsVue3 = (defaultSlot) => {
@@ -47,12 +85,7 @@ const hasOnlyListItemsVue3 = (defaultSlot) => {
47
85
  const fragment = nodes.find((node) => Array.isArray(node.children) && node.children.length);
48
86
  const targetNodes = fragment ? fragment.children : nodes;
49
87
 
50
- return (
51
- targetNodes
52
- // Remove empty text vNodes
53
- .filter((vNode) => !isString(vNode.text) || vNode.text.trim().length > 0)
54
- .every((vNode) => isValidSlotTagVue3(vNode))
55
- );
88
+ return validateNodesRecursiveVue3(targetNodes);
56
89
  };
57
90
 
58
91
  const hasOnlyListItems = (defaultSlot) => {