aleman 1.3.1 → 1.4.0
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 +12 -0
- package/menu/rules/build-menu/index.js +8 -26
- package/menu/rules/check-data-name.js +5 -8
- package/menu/rules/hide-submenu/index.js +9 -21
- package/menu/rules/jsx-operator.js +78 -0
- package/menu/rules/select/index.js +21 -61
- package/menu/rules/submenu/fixture/li.js +3 -0
- package/menu/rules/submenu/fixture/not-menu.js +17 -0
- package/menu/rules/submenu/index.js +14 -39
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
2025.09.04, v1.4.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- 2749907 aleman: menu: select: jsx-operator
|
|
5
|
+
- 43294ec aleman: menu: jsx-operator
|
|
6
|
+
|
|
7
|
+
2025.09.04, v1.3.2
|
|
8
|
+
|
|
9
|
+
feature:
|
|
10
|
+
- a94f8d9 aleman: menu: jsx-operator: add
|
|
11
|
+
- 6a18625 aleman: menu: operator: add
|
|
12
|
+
|
|
1
13
|
2025.09.04, v1.3.1
|
|
2
14
|
|
|
3
15
|
feature:
|
|
@@ -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,78 @@
|
|
|
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(path, name, value) {
|
|
45
|
+
const node = path.node || path;
|
|
46
|
+
const attributeNode = getAttributeNode(node, name);
|
|
47
|
+
|
|
48
|
+
if (!attributeNode)
|
|
49
|
+
return;
|
|
50
|
+
|
|
51
|
+
if (attributeNode.value.value.includes(value))
|
|
52
|
+
return;
|
|
53
|
+
|
|
54
|
+
setLiteralValue(attributeNode.value, `${attributeNode.value.value} ${value}`);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function setAttributeValue(node, name, value) {
|
|
58
|
+
const attributeNode = getAttributeNode(node, name);
|
|
59
|
+
|
|
60
|
+
if (attributeNode)
|
|
61
|
+
setLiteralValue(attributeNode.value, value);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function removeAttributeValue(path, name, attributeValue) {
|
|
65
|
+
if (!path)
|
|
66
|
+
return;
|
|
67
|
+
|
|
68
|
+
const node = path.node || path;
|
|
69
|
+
const classAttribute = getAttributeNode(node, name);
|
|
70
|
+
|
|
71
|
+
if (!classAttribute)
|
|
72
|
+
return;
|
|
73
|
+
|
|
74
|
+
const {value} = classAttribute.value;
|
|
75
|
+
|
|
76
|
+
if (value.includes(attributeValue))
|
|
77
|
+
setLiteralValue(classAttribute.value, value.replace(RegExp(`\\s?${attributeValue}`), ''));
|
|
78
|
+
}
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import {operator, types} from 'putout';
|
|
2
2
|
import {checkDataName} from '../check-data-name.js';
|
|
3
|
+
import {
|
|
4
|
+
appendAttributeValue,
|
|
5
|
+
getAttributePath,
|
|
6
|
+
removeAttributeValue,
|
|
7
|
+
} from '../jsx-operator.js';
|
|
3
8
|
|
|
4
9
|
const {isJSXElement} = types;
|
|
5
10
|
const {setLiteralValue} = operator;
|
|
@@ -53,75 +58,30 @@ export const traverse = ({options, push}) => ({
|
|
|
53
58
|
if (!current)
|
|
54
59
|
return;
|
|
55
60
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
next,
|
|
67
|
-
showSubmenu,
|
|
68
|
-
});
|
|
69
|
-
break;
|
|
70
|
-
}
|
|
61
|
+
const currentOpeningElement = current.get('openingElement');
|
|
62
|
+
const attributePath = getAttributePath(currentOpeningElement, 'className');
|
|
63
|
+
|
|
64
|
+
push({
|
|
65
|
+
path: attributePath,
|
|
66
|
+
current,
|
|
67
|
+
prev,
|
|
68
|
+
next,
|
|
69
|
+
showSubmenu,
|
|
70
|
+
});
|
|
71
71
|
},
|
|
72
72
|
});
|
|
73
73
|
|
|
74
74
|
function unselect(path) {
|
|
75
|
-
|
|
76
|
-
return;
|
|
77
|
-
|
|
78
|
-
for (const attr of path.get('openingElement.attributes')) {
|
|
79
|
-
const {name, value} = attr.node;
|
|
80
|
-
|
|
81
|
-
if (name.name !== 'className')
|
|
82
|
-
continue;
|
|
83
|
-
|
|
84
|
-
if (value.value.includes('menu-item-selected'))
|
|
85
|
-
setLiteralValue(value, value.value.replace(' menu-item-selected', ''));
|
|
86
|
-
}
|
|
75
|
+
removeAttributeValue(path, 'className', 'menu-item-selected');
|
|
87
76
|
}
|
|
88
77
|
|
|
89
78
|
function addShowSubmenu(path, {showSubmenu}) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
continue;
|
|
95
|
-
|
|
96
|
-
const currentValue = value.value;
|
|
97
|
-
|
|
98
|
-
if (showSubmenu && !currentValue.includes('menu-submenu-show')) {
|
|
99
|
-
setLiteralValue(value, `${currentValue} menu-submenu-show`);
|
|
100
|
-
break;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
if (!showSubmenu && currentValue.includes('menu-submenu-show')) {
|
|
104
|
-
setLiteralValue(value, currentValue.replace('menu-submenu-show', ''));
|
|
105
|
-
break;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
79
|
+
if (showSubmenu)
|
|
80
|
+
return appendAttributeValue(path, 'className', 'menu-submenu-show');
|
|
81
|
+
|
|
82
|
+
removeAttributeValue(path, 'className', 'menu-submenu-show');
|
|
108
83
|
}
|
|
109
84
|
|
|
110
85
|
function removeShowSubmenu(path) {
|
|
111
|
-
|
|
112
|
-
return;
|
|
113
|
-
|
|
114
|
-
for (const attr of path.get('openingElement.attributes')) {
|
|
115
|
-
const {name, value} = attr.node;
|
|
116
|
-
|
|
117
|
-
if (name.name !== 'className')
|
|
118
|
-
continue;
|
|
119
|
-
|
|
120
|
-
const currentValue = value.value;
|
|
121
|
-
|
|
122
|
-
if (currentValue.includes('menu-submenu-show')) {
|
|
123
|
-
setLiteralValue(value, currentValue.replace(' menu-submenu-show', ''));
|
|
124
|
-
break;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
86
|
+
removeAttributeValue(path, 'className', 'menu-submenu-show');
|
|
127
87
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// second selected
|
|
2
|
+
<ul data-name="menu" class="menu menu-hidden">
|
|
3
|
+
<li data-menu-path="Upload" data-name="menu-item" className="menu-item icon icon-view">
|
|
4
|
+
<label data-menu-path="Upload">Upload</label>
|
|
5
|
+
</li>
|
|
6
|
+
<li data-menu-path="New" data-name="menu-item" className="menu-item icon icon-edit menu-item-selected">
|
|
7
|
+
<label data-menu-path="New">New</label>
|
|
8
|
+
<ul data-name="world" class="menu menu-hidden">
|
|
9
|
+
<li data-menu-path="New.File" data-name="menu-item" className="menu-item icon icon-view">
|
|
10
|
+
<label data-menu-path="New.File">File</label>
|
|
11
|
+
</li>
|
|
12
|
+
<li data-menu-path="New.Directory" data-name="menu-item" className="menu-item icon icon-edit">
|
|
13
|
+
<label data-menu-path="New.Directory">Directory</label>
|
|
14
|
+
</li>
|
|
15
|
+
</ul>
|
|
16
|
+
</li>
|
|
17
|
+
</ul>;
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import {operator, types} from 'putout';
|
|
2
2
|
import {checkDataName} from '../check-data-name.js';
|
|
3
|
+
import {
|
|
4
|
+
getAttributePath,
|
|
5
|
+
getAttributeValue,
|
|
6
|
+
removeAttributeValue,
|
|
7
|
+
} from '../jsx-operator.js';
|
|
3
8
|
|
|
4
9
|
const {isJSXElement} = types;
|
|
5
10
|
const {setLiteralValue} = operator;
|
|
@@ -29,6 +34,9 @@ export const traverse = ({options, push}) => ({
|
|
|
29
34
|
if (path.node.name.name !== 'li')
|
|
30
35
|
return;
|
|
31
36
|
|
|
37
|
+
if (!isJSXElement(path.parentPath.parentPath))
|
|
38
|
+
return;
|
|
39
|
+
|
|
32
40
|
const {insideSubmenu = true, submenuIndex = 1} = options;
|
|
33
41
|
const parentMenu = path.parentPath.parentPath.parentPath;
|
|
34
42
|
|
|
@@ -38,9 +46,6 @@ export const traverse = ({options, push}) => ({
|
|
|
38
46
|
if (!isParentSelected(parentMenu))
|
|
39
47
|
return;
|
|
40
48
|
|
|
41
|
-
if (!isJSXElement(path.parentPath.parentPath))
|
|
42
|
-
return;
|
|
43
|
-
|
|
44
49
|
const openingElementPath = path.parentPath.parentPath.get('openingElement');
|
|
45
50
|
|
|
46
51
|
if (!checkDataName(openingElementPath))
|
|
@@ -58,7 +63,8 @@ export const traverse = ({options, push}) => ({
|
|
|
58
63
|
if (!current)
|
|
59
64
|
return;
|
|
60
65
|
|
|
61
|
-
const
|
|
66
|
+
const currentOpeningElementPath = current.get('openingElement');
|
|
67
|
+
const currentClassPath = getAttributePath(currentOpeningElementPath, 'className');
|
|
62
68
|
|
|
63
69
|
push({
|
|
64
70
|
path: currentClassPath,
|
|
@@ -70,46 +76,15 @@ export const traverse = ({options, push}) => ({
|
|
|
70
76
|
});
|
|
71
77
|
|
|
72
78
|
function isParentSelected(path) {
|
|
73
|
-
const
|
|
79
|
+
const openingElement = path.get('openingElement');
|
|
80
|
+
const classAttributeValue = getAttributeValue(openingElement, 'className');
|
|
74
81
|
|
|
75
|
-
|
|
76
|
-
const {name, value} = attr.node;
|
|
77
|
-
|
|
78
|
-
if (name.name === 'className')
|
|
79
|
-
return value.value.includes('menu-item-selected');
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return false;
|
|
82
|
+
return classAttributeValue.includes('menu-item-selected');
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
function unselect(path) {
|
|
86
86
|
if (!path)
|
|
87
87
|
return;
|
|
88
88
|
|
|
89
|
-
|
|
90
|
-
const {name, value} = attr.node;
|
|
91
|
-
|
|
92
|
-
if (name.name !== 'className')
|
|
93
|
-
continue;
|
|
94
|
-
|
|
95
|
-
if (value.value.includes('menu-item-selected'))
|
|
96
|
-
setLiteralValue(value, value.value.replace(' menu-item-selected', ''));
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function getClassPath(path) {
|
|
101
|
-
if (!path)
|
|
102
|
-
return [null, ''];
|
|
103
|
-
|
|
104
|
-
for (const attr of path.get('openingElement.attributes')) {
|
|
105
|
-
const {name, value} = attr.node;
|
|
106
|
-
|
|
107
|
-
if (name.name !== 'className')
|
|
108
|
-
continue;
|
|
109
|
-
|
|
110
|
-
return [
|
|
111
|
-
attr,
|
|
112
|
-
value.value,
|
|
113
|
-
];
|
|
114
|
-
}
|
|
89
|
+
removeAttributeValue(path, 'className', 'menu-item-selected');
|
|
115
90
|
}
|