aleman 1.3.1 → 1.3.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.
package/ChangeLog
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import {template
|
|
1
|
+
import {template} from 'putout';
|
|
2
2
|
import {checkDataName} from '../check-data-name.js';
|
|
3
|
+
import {
|
|
4
|
+
appendAttributeValue,
|
|
5
|
+
setAttributeValue,
|
|
6
|
+
} from '../jsx-operator.js';
|
|
3
7
|
|
|
4
|
-
const {setLiteralValue} = operator;
|
|
5
8
|
const {entries} = Object;
|
|
6
9
|
|
|
7
10
|
const noop = () => {};
|
|
@@ -80,37 +83,16 @@ export const traverse = ({options, push}) => ({
|
|
|
80
83
|
});
|
|
81
84
|
|
|
82
85
|
function setSubmenu(menuItem) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
for (const attr of attributes) {
|
|
86
|
-
if (attr.name.name === 'className') {
|
|
87
|
-
setLiteralValue(attr.value, `${attr.value.value} menu-submenu`);
|
|
88
|
-
break;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
86
|
+
appendAttributeValue(menuItem, 'className', 'menu-submenu');
|
|
91
87
|
}
|
|
92
88
|
|
|
93
89
|
function setDataMenuPath(key, name, menuItem) {
|
|
94
|
-
const {attributes} = menuItem.openingElement;
|
|
95
90
|
const dataMenuPath = name ? `${name}.${key}` : key;
|
|
96
|
-
|
|
97
|
-
for (const attr of attributes) {
|
|
98
|
-
if (attr.name.name === 'data-menu-path') {
|
|
99
|
-
setLiteralValue(attr.value, dataMenuPath);
|
|
100
|
-
break;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
91
|
+
setAttributeValue(menuItem, 'data-menu-path', dataMenuPath);
|
|
103
92
|
}
|
|
104
93
|
|
|
105
94
|
function setIcon(name, menuItem) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
for (const attr of attributes) {
|
|
109
|
-
if (attr.name.name === 'className') {
|
|
110
|
-
setLiteralValue(attr.value, `${attr.value.value} icon ${getIconName(name)}`);
|
|
111
|
-
break;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
95
|
+
appendAttributeValue(menuItem, 'className', `icon ${getIconName(name)}`);
|
|
114
96
|
}
|
|
115
97
|
|
|
116
98
|
function getIconName(name) {
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import {getAttributeValue} from './jsx-operator.js';
|
|
2
|
+
|
|
3
|
+
export function checkDataName(path, value = 'menu') {
|
|
4
|
+
const attribute = getAttributeValue(path, 'data-name');
|
|
3
5
|
|
|
4
|
-
|
|
5
|
-
if (name.name === 'data-name')
|
|
6
|
-
return value.value === dataName;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
return false;
|
|
6
|
+
return attribute === value;
|
|
10
7
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import {operator} from 'putout';
|
|
2
|
+
import {checkDataName} from '../check-data-name.js';
|
|
3
|
+
import {getAttributePath} from '../jsx-operator.js';
|
|
2
4
|
|
|
3
5
|
const {setLiteralValue} = operator;
|
|
4
6
|
|
|
@@ -23,31 +25,17 @@ export const traverse = ({push, options}) => ({
|
|
|
23
25
|
if (showSubmenu)
|
|
24
26
|
return;
|
|
25
27
|
|
|
26
|
-
const attributes = path.get('attributes');
|
|
27
28
|
const openingElementPath = path.parentPath.parentPath.get('openingElement');
|
|
28
29
|
|
|
29
30
|
if (!checkDataName(openingElementPath, name))
|
|
30
31
|
return false;
|
|
31
32
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
push(attr);
|
|
40
|
-
}
|
|
33
|
+
const attributePath = getAttributePath(path, 'className');
|
|
34
|
+
|
|
35
|
+
if (!attributePath)
|
|
36
|
+
return;
|
|
37
|
+
|
|
38
|
+
if (attributePath.node.value.value.includes('menu-submenu-show'))
|
|
39
|
+
push(attributePath);
|
|
41
40
|
},
|
|
42
41
|
});
|
|
43
|
-
|
|
44
|
-
function checkDataName(path, dataName = 'menu') {
|
|
45
|
-
const {attributes} = path.node;
|
|
46
|
-
|
|
47
|
-
for (const {name, value} of attributes) {
|
|
48
|
-
if (name.name === 'data-name')
|
|
49
|
-
return value.value === dataName;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return false;
|
|
53
|
-
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import {operator} from 'putout';
|
|
2
|
+
|
|
3
|
+
const {setLiteralValue} = operator;
|
|
4
|
+
|
|
5
|
+
export function getAttributeValue(path, attributeName) {
|
|
6
|
+
const {attributes} = path.node;
|
|
7
|
+
|
|
8
|
+
for (const {name, value} of attributes) {
|
|
9
|
+
if (name.name === attributeName)
|
|
10
|
+
return value.value;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return '';
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function getAttributeNode(node, name) {
|
|
17
|
+
let result = null;
|
|
18
|
+
const {attributes} = node.openingElement;
|
|
19
|
+
|
|
20
|
+
for (const attr of attributes) {
|
|
21
|
+
if (attr.name.name === name) {
|
|
22
|
+
result = attr;
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function getAttributePath(path, name) {
|
|
31
|
+
let result = null;
|
|
32
|
+
const attributes = path.get('attributes');
|
|
33
|
+
|
|
34
|
+
for (const attr of attributes) {
|
|
35
|
+
if (attr.node.name.name === name) {
|
|
36
|
+
result = attr;
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function appendAttributeValue(node, name, value) {
|
|
45
|
+
const attributeNode = getAttributeNode(node, name);
|
|
46
|
+
|
|
47
|
+
if (attributeNode)
|
|
48
|
+
setLiteralValue(attributeNode.value, `${attributeNode.value.value} ${value}`);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function setAttributeValue(node, name, value) {
|
|
52
|
+
const attributeNode = getAttributeNode(node, name);
|
|
53
|
+
|
|
54
|
+
if (attributeNode)
|
|
55
|
+
setLiteralValue(attributeNode.value, value);
|
|
56
|
+
}
|