aleman 1.1.19 → 1.1.21
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/menu/addons/index.js +0 -4
- package/menu/addons/item-click.js +6 -3
- package/menu/addons/mouse-enter.js +6 -4
- package/menu/hydrate-menu.js +7 -1
- package/menu/menu.js +1 -1
- package/menu/rules/select/index.js +5 -16
- package/menu/rules/set-position/index.js +2 -2
- package/menu/rules/unselect-all/index.js +1 -1
- package/package.json +1 -1
package/menu/addons/index.js
CHANGED
|
@@ -5,8 +5,6 @@ import * as down from './down.js';
|
|
|
5
5
|
import * as up from './up.js';
|
|
6
6
|
import * as f9 from './f9.js';
|
|
7
7
|
import * as enter from './enter.js';
|
|
8
|
-
import * as mouseEnter from './mouse-enter.js';
|
|
9
|
-
import * as itemClick from './item-click.js';
|
|
10
8
|
|
|
11
9
|
export const addons = [
|
|
12
10
|
contextMenu,
|
|
@@ -16,6 +14,4 @@ export const addons = [
|
|
|
16
14
|
up,
|
|
17
15
|
f9,
|
|
18
16
|
enter,
|
|
19
|
-
mouseEnter,
|
|
20
|
-
itemClick,
|
|
21
17
|
];
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
export const
|
|
2
|
-
|
|
1
|
+
export const createItemClick = (name) => ({
|
|
2
|
+
name,
|
|
3
|
+
events: ['click'],
|
|
4
|
+
listener,
|
|
5
|
+
});
|
|
3
6
|
|
|
4
|
-
|
|
7
|
+
const listener = ({event, options}) => {
|
|
5
8
|
const menuItemElement = document.elementFromPoint(event.clientX, event.clientY);
|
|
6
9
|
const name = menuItemElement.textContent.trim();
|
|
7
10
|
const {menu} = options;
|
package/menu/hydrate-menu.js
CHANGED
|
@@ -2,6 +2,8 @@ import {rules} from './rules/index.js';
|
|
|
2
2
|
import {hydrate} from '../aleman/index.js';
|
|
3
3
|
import {initState} from './state.js';
|
|
4
4
|
import {addons} from './addons/index.js';
|
|
5
|
+
import {createMouseEnter} from './addons/mouse-enter.js';
|
|
6
|
+
import {createItemClick} from './addons/item-click.js';
|
|
5
7
|
|
|
6
8
|
const {assign} = Object;
|
|
7
9
|
|
|
@@ -14,7 +16,11 @@ export const hydrateMenu = (element, options, menu) => {
|
|
|
14
16
|
const {run} = hydrate(element, {
|
|
15
17
|
options,
|
|
16
18
|
state,
|
|
17
|
-
addons
|
|
19
|
+
addons: [
|
|
20
|
+
createMouseEnter(options.name),
|
|
21
|
+
createItemClick(options.name),
|
|
22
|
+
...addons,
|
|
23
|
+
],
|
|
18
24
|
rules,
|
|
19
25
|
stateName: `aleman-state-${options.name}`,
|
|
20
26
|
});
|
package/menu/menu.js
CHANGED
|
@@ -46,7 +46,7 @@ function createHydrate(name) {
|
|
|
46
46
|
const section = document.createElement('section');
|
|
47
47
|
|
|
48
48
|
section.dataset.name = `aleman-hydrate-${name}`;
|
|
49
|
-
section.innerHTML = `<ul data-name="
|
|
49
|
+
section.innerHTML = `<ul data-name="${name}" class="menu menu-hidden"></ul>`;
|
|
50
50
|
document.body.append(section);
|
|
51
51
|
|
|
52
52
|
return section;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {operator, types} from 'putout';
|
|
2
|
+
import {checkDataName} from '../check-data-name.js';
|
|
2
3
|
|
|
3
4
|
const {isJSXElement} = types;
|
|
4
5
|
const {setLiteralValue} = operator;
|
|
@@ -15,15 +16,15 @@ export const fix = ({path, prev, next}) => {
|
|
|
15
16
|
|
|
16
17
|
export const traverse = ({options, push}) => ({
|
|
17
18
|
JSXOpeningElement(path) {
|
|
19
|
+
const {name = 'menu', index = 1} = options;
|
|
20
|
+
|
|
18
21
|
if (path.node.name.name !== 'li')
|
|
19
22
|
return;
|
|
20
23
|
|
|
21
|
-
const {index = 1} = options;
|
|
22
|
-
|
|
23
24
|
if (!isJSXElement(path.parentPath.parentPath))
|
|
24
25
|
return;
|
|
25
26
|
|
|
26
|
-
if (!checkDataName(path.parentPath.parentPath))
|
|
27
|
+
if (!checkDataName(path.parentPath.parentPath, name))
|
|
27
28
|
return;
|
|
28
29
|
|
|
29
30
|
const children = path.parentPath
|
|
@@ -56,19 +57,6 @@ export const traverse = ({options, push}) => ({
|
|
|
56
57
|
},
|
|
57
58
|
});
|
|
58
59
|
|
|
59
|
-
function checkDataName(path) {
|
|
60
|
-
const attributes = path.get('openingElement.attributes');
|
|
61
|
-
|
|
62
|
-
for (const attr of attributes) {
|
|
63
|
-
const {name, value} = attr.node;
|
|
64
|
-
|
|
65
|
-
if (name.name === 'data-name')
|
|
66
|
-
return value.value === 'menu';
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return false;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
60
|
function unselect(path) {
|
|
73
61
|
if (!path)
|
|
74
62
|
return;
|
|
@@ -83,3 +71,4 @@ function unselect(path) {
|
|
|
83
71
|
setLiteralValue(value, value.value.replace(' menu-item-selected', ''));
|
|
84
72
|
}
|
|
85
73
|
}
|
|
74
|
+
|
|
@@ -29,10 +29,10 @@ export const fix = ({path, attr, left, top}) => {
|
|
|
29
29
|
|
|
30
30
|
export const traverse = ({options, push}) => ({
|
|
31
31
|
JSXOpeningElement(path) {
|
|
32
|
-
const {position = {}} = options;
|
|
32
|
+
const {name = 'menu', position = {}} = options;
|
|
33
33
|
const {left = 0, top = 20} = position;
|
|
34
34
|
|
|
35
|
-
if (!checkDataName(path.parentPath,
|
|
35
|
+
if (!checkDataName(path.parentPath, name))
|
|
36
36
|
return;
|
|
37
37
|
|
|
38
38
|
for (const attr of path.node.attributes) {
|
|
@@ -26,7 +26,7 @@ export const traverse = ({push, options}) => ({
|
|
|
26
26
|
if (!isJSXElement(path.parentPath.parentPath))
|
|
27
27
|
return;
|
|
28
28
|
|
|
29
|
-
if (!checkDataName(path.parentPath.parentPath))
|
|
29
|
+
if (!checkDataName(path.parentPath.parentPath, name))
|
|
30
30
|
return;
|
|
31
31
|
|
|
32
32
|
const children = path.parentPath
|