aleman 1.4.1 → 1.4.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 +5 -0
- package/menu/addons/item-click.js +12 -2
- package/menu/rules/build-menu/index.js +2 -2
- package/menu/rules/hide-submenu/fixture/no-menu.js +16 -0
- package/menu/rules/hide-submenu/index.js +8 -8
- package/menu/rules/jsx-operator.js +11 -14
- package/menu/rules/menu/index.js +8 -8
- package/menu/rules/select/index.js +2 -2
- package/menu/rules/set-position/index.js +2 -2
- package/menu/rules/submenu/index.js +2 -2
- package/menu/rules/unselect-all/index.js +2 -2
- package/package.json +1 -1
- package/menu/rules/check-data-name.js +0 -7
package/ChangeLog
CHANGED
|
@@ -7,9 +7,8 @@ export const createItemClick = (name) => ({
|
|
|
7
7
|
});
|
|
8
8
|
|
|
9
9
|
const listener = ({event, options}) => {
|
|
10
|
-
const menuItemElement = document.elementFromPoint(event.clientX, event.clientY);
|
|
11
|
-
const {menuPath} = menuItemElement.dataset;
|
|
12
10
|
const {menu} = options;
|
|
11
|
+
const menuPath = getMenuPath(event);
|
|
13
12
|
const fn = jessy(menuPath, menu);
|
|
14
13
|
|
|
15
14
|
setTimeout(fn);
|
|
@@ -21,3 +20,14 @@ const listener = ({event, options}) => {
|
|
|
21
20
|
showSubmenu: false,
|
|
22
21
|
};
|
|
23
22
|
};
|
|
23
|
+
|
|
24
|
+
function getMenuPath(event) {
|
|
25
|
+
let menuItemElement = document.elementFromPoint(event.clientX, event.clientY);
|
|
26
|
+
const {menuPath} = menuItemElement.dataset;
|
|
27
|
+
|
|
28
|
+
if (!menuPath)
|
|
29
|
+
menuItemElement = menuItemElement.querySelector('[data-menu-path]');
|
|
30
|
+
|
|
31
|
+
return menuItemElement.dataset.menuPath;
|
|
32
|
+
}
|
|
33
|
+
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {template} from 'putout';
|
|
2
|
-
import {checkDataName} from '../check-data-name.js';
|
|
3
2
|
import {
|
|
4
3
|
appendAttributeValue,
|
|
4
|
+
hasDataName,
|
|
5
5
|
setAttributeValue,
|
|
6
6
|
} from '../jsx-operator.js';
|
|
7
7
|
|
|
@@ -68,7 +68,7 @@ export const traverse = ({options, push}) => ({
|
|
|
68
68
|
icon = false,
|
|
69
69
|
} = options;
|
|
70
70
|
|
|
71
|
-
if (!
|
|
71
|
+
if (!hasDataName(path, name))
|
|
72
72
|
return;
|
|
73
73
|
|
|
74
74
|
if (path.node.children.length)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<ul data-name="hello" className="menu menu-hidden">
|
|
2
|
+
<li data-menu-path="Upload" data-name="menu-item" className="menu-item icon icon-view">
|
|
3
|
+
<label data-menu-path="Upload">Upload</label>
|
|
4
|
+
</li>
|
|
5
|
+
<li data-menu-path="New" data-name="menu-item" className="menu-item icon icon-edit menu-item-selected menu-submenu-show">
|
|
6
|
+
<label data-menu-path="New">New</label>
|
|
7
|
+
<ul data-name="menu" className="menu menu-hidden">
|
|
8
|
+
<li data-menu-path="New.File" data-name="menu-item" className="menu-item icon icon-view">
|
|
9
|
+
<label data-menu-path="New.File">File</label>
|
|
10
|
+
</li>
|
|
11
|
+
<li data-menu-path="New.Directory" data-name="menu-item" className="menu-item icon icon-edit">
|
|
12
|
+
<label data-menu-path="New.Directory">Directory</label>
|
|
13
|
+
</li>
|
|
14
|
+
</ul>
|
|
15
|
+
</li>
|
|
16
|
+
</ul>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {checkDataName} from '../check-data-name.js';
|
|
2
1
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
hasTagName,
|
|
3
|
+
containsClassName,
|
|
4
|
+
removeClassName,
|
|
5
|
+
hasDataName,
|
|
6
6
|
} from '../jsx-operator.js';
|
|
7
7
|
|
|
8
8
|
const CLASS = 'menu-submenu-show';
|
|
@@ -10,7 +10,7 @@ const CLASS = 'menu-submenu-show';
|
|
|
10
10
|
export const report = () => `Hide submenu`;
|
|
11
11
|
|
|
12
12
|
export const fix = (path) => {
|
|
13
|
-
|
|
13
|
+
removeClassName(path, CLASS);
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
export const traverse = ({push, options}) => ({
|
|
@@ -21,13 +21,13 @@ export const traverse = ({push, options}) => ({
|
|
|
21
21
|
if (showSubmenu)
|
|
22
22
|
return;
|
|
23
23
|
|
|
24
|
-
if (!
|
|
24
|
+
if (!hasTagName(path, 'li'))
|
|
25
25
|
return;
|
|
26
26
|
|
|
27
|
-
if (!
|
|
27
|
+
if (!hasDataName(parentPath, name))
|
|
28
28
|
return false;
|
|
29
29
|
|
|
30
|
-
if (
|
|
30
|
+
if (containsClassName(path, CLASS))
|
|
31
31
|
push(path);
|
|
32
32
|
},
|
|
33
33
|
});
|
|
@@ -52,9 +52,6 @@ export function appendAttributeValue(path, name, value) {
|
|
|
52
52
|
const node = path.node || path;
|
|
53
53
|
const attributeNode = getAttributeNode(node, name);
|
|
54
54
|
|
|
55
|
-
if (!attributeNode)
|
|
56
|
-
return;
|
|
57
|
-
|
|
58
55
|
if (attributeNode.value.value.includes(value))
|
|
59
56
|
return;
|
|
60
57
|
|
|
@@ -62,9 +59,6 @@ export function appendAttributeValue(path, name, value) {
|
|
|
62
59
|
}
|
|
63
60
|
|
|
64
61
|
export function setAttributeValue(node, name, value) {
|
|
65
|
-
if (!node)
|
|
66
|
-
return;
|
|
67
|
-
|
|
68
62
|
node = node.node || node;
|
|
69
63
|
|
|
70
64
|
const attributeNode = getAttributeNode(node, name);
|
|
@@ -73,33 +67,36 @@ export function setAttributeValue(node, name, value) {
|
|
|
73
67
|
setLiteralValue(attributeNode.value, value);
|
|
74
68
|
}
|
|
75
69
|
|
|
76
|
-
export function
|
|
70
|
+
export function addClassName(path, name) {
|
|
77
71
|
appendAttributeValue(path, 'className', name);
|
|
78
72
|
}
|
|
79
73
|
|
|
80
|
-
export function
|
|
74
|
+
export function removeClassName(path, name) {
|
|
81
75
|
removeAttributeValue(path, 'className', name);
|
|
82
76
|
}
|
|
83
77
|
|
|
84
|
-
export function
|
|
78
|
+
export function containsClassName(path, className) {
|
|
85
79
|
const classNameValue = getAttributeValue(path, 'className');
|
|
86
80
|
return classNameValue.includes(className);
|
|
87
81
|
}
|
|
88
82
|
|
|
89
|
-
export const
|
|
83
|
+
export const hasTagName = (path, name) => path.node.openingElement.name.name === name;
|
|
90
84
|
|
|
91
85
|
export function removeAttributeValue(path, name, attributeValue) {
|
|
92
86
|
if (!path)
|
|
93
87
|
return;
|
|
94
88
|
|
|
95
|
-
const node = path
|
|
89
|
+
const {node} = path;
|
|
96
90
|
const classAttribute = getAttributeNode(node, name);
|
|
97
91
|
|
|
98
|
-
if (!classAttribute)
|
|
99
|
-
return;
|
|
100
|
-
|
|
101
92
|
const {value} = classAttribute.value;
|
|
102
93
|
|
|
103
94
|
if (value.includes(attributeValue))
|
|
104
95
|
setLiteralValue(classAttribute.value, value.replace(RegExp(`\\s?${attributeValue}`), ''));
|
|
105
96
|
}
|
|
97
|
+
|
|
98
|
+
export function hasDataName(path, value = 'menu') {
|
|
99
|
+
const attribute = getAttributeValue(path, 'data-name');
|
|
100
|
+
|
|
101
|
+
return attribute === value;
|
|
102
|
+
}
|
package/menu/rules/menu/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {checkDataName} from '../check-data-name.js';
|
|
2
1
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
addClassName,
|
|
3
|
+
containsClassName,
|
|
4
|
+
hasDataName,
|
|
5
|
+
removeClassName,
|
|
6
6
|
} from '../jsx-operator.js';
|
|
7
7
|
|
|
8
8
|
export const report = ({command}) => {
|
|
@@ -13,21 +13,21 @@ export const report = ({command}) => {
|
|
|
13
13
|
|
|
14
14
|
export const fix = ({path, command}) => {
|
|
15
15
|
if (command === 'show') {
|
|
16
|
-
|
|
16
|
+
removeClassName(path, 'menu-hidden');
|
|
17
17
|
return;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
addClassName(path, 'menu-hidden');
|
|
21
21
|
};
|
|
22
22
|
|
|
23
23
|
export const traverse = ({push, options}) => ({
|
|
24
24
|
JSXElement(path) {
|
|
25
25
|
const {name, command} = options;
|
|
26
26
|
|
|
27
|
-
if (!
|
|
27
|
+
if (!hasDataName(path, name))
|
|
28
28
|
return false;
|
|
29
29
|
|
|
30
|
-
const shown = !
|
|
30
|
+
const shown = !containsClassName(path, 'menu-hidden');
|
|
31
31
|
|
|
32
32
|
if (command === 'show' && !shown || command === 'hide' && shown)
|
|
33
33
|
push({
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {operator, types} from 'putout';
|
|
2
|
-
import {checkDataName} from '../check-data-name.js';
|
|
3
2
|
import {
|
|
4
3
|
appendAttributeValue,
|
|
5
4
|
getAttributePath,
|
|
5
|
+
hasDataName,
|
|
6
6
|
removeAttributeValue,
|
|
7
7
|
} from '../jsx-operator.js';
|
|
8
8
|
|
|
@@ -43,7 +43,7 @@ export const traverse = ({options, push}) => ({
|
|
|
43
43
|
if (!isJSXElement(parentParentPath))
|
|
44
44
|
return;
|
|
45
45
|
|
|
46
|
-
if (!
|
|
46
|
+
if (!hasDataName(parentParentPath, name))
|
|
47
47
|
return;
|
|
48
48
|
|
|
49
49
|
const children = parentParentPath.get('children').filter(isJSXElement);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {types} from 'putout';
|
|
2
|
-
import {checkDataName} from '../check-data-name.js';
|
|
3
2
|
import {
|
|
4
3
|
getAttributePath,
|
|
5
4
|
getAttributeValue,
|
|
5
|
+
hasDataName,
|
|
6
6
|
setAttributeValue,
|
|
7
7
|
} from '../jsx-operator.js';
|
|
8
8
|
|
|
@@ -33,7 +33,7 @@ export const traverse = ({options, push}) => ({
|
|
|
33
33
|
const {name = 'menu', position = {}} = options;
|
|
34
34
|
const {x = 0, y = 20} = position;
|
|
35
35
|
|
|
36
|
-
if (!
|
|
36
|
+
if (!hasDataName(path, name))
|
|
37
37
|
return;
|
|
38
38
|
|
|
39
39
|
const styleAttributeValue = getAttributeValue(path, 'style');
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {operator, types} from 'putout';
|
|
2
|
-
import {checkDataName} from '../check-data-name.js';
|
|
3
2
|
import {
|
|
4
3
|
getAttributePath,
|
|
5
4
|
getAttributeValue,
|
|
5
|
+
hasDataName,
|
|
6
6
|
removeAttributeValue,
|
|
7
7
|
} from '../jsx-operator.js';
|
|
8
8
|
|
|
@@ -48,7 +48,7 @@ export const traverse = ({options, push}) => ({
|
|
|
48
48
|
|
|
49
49
|
const openingElementPath = path.parentPath.parentPath.get('openingElement');
|
|
50
50
|
|
|
51
|
-
if (!
|
|
51
|
+
if (!hasDataName(openingElementPath))
|
|
52
52
|
return;
|
|
53
53
|
|
|
54
54
|
const children = path.parentPath
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {operator, types} from 'putout';
|
|
2
|
-
import {
|
|
2
|
+
import {hasDataName} from '../jsx-operator.js';
|
|
3
3
|
|
|
4
4
|
const {isJSXElement} = types;
|
|
5
5
|
const {setLiteralValue} = operator;
|
|
@@ -28,7 +28,7 @@ export const traverse = ({push, options}) => ({
|
|
|
28
28
|
|
|
29
29
|
const openingElementPath = path.parentPath.parentPath.get('openingElement');
|
|
30
30
|
|
|
31
|
-
if (!
|
|
31
|
+
if (!hasDataName(openingElementPath, name))
|
|
32
32
|
return;
|
|
33
33
|
|
|
34
34
|
const children = path.parentPath
|
package/package.json
CHANGED