aleman 1.9.0 → 1.10.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 +10 -0
- package/menu/addons/click.js +20 -1
- package/menu/addons/item-click.js +13 -10
- package/menu/addons/menu/get-menu-path.js +13 -0
- package/menu/addons/shift-g.js +4 -1
- package/menu/menu.js +30 -4
- package/package.json +3 -2
package/ChangeLog
CHANGED
package/menu/addons/click.js
CHANGED
|
@@ -1,6 +1,24 @@
|
|
|
1
|
+
import jessy from 'jessy';
|
|
2
|
+
import {getMenuPath} from './menu/get-menu-path.js';
|
|
3
|
+
|
|
4
|
+
const isFn = (a) => typeof a === 'function';
|
|
5
|
+
|
|
1
6
|
export const events = ['click'];
|
|
2
7
|
|
|
3
|
-
export const filter = ({state}) =>
|
|
8
|
+
export const filter = ({event, state, options}) => {
|
|
9
|
+
const {menu} = options;
|
|
10
|
+
const menuPath = getMenuPath(event);
|
|
11
|
+
|
|
12
|
+
if (!menuPath)
|
|
13
|
+
return true;
|
|
14
|
+
|
|
15
|
+
const fn = jessy(menuPath, menu);
|
|
16
|
+
|
|
17
|
+
if (!isFn(fn))
|
|
18
|
+
return false;
|
|
19
|
+
|
|
20
|
+
return state.command === 'show';
|
|
21
|
+
};
|
|
4
22
|
|
|
5
23
|
export const listener = ({options, state}) => {
|
|
6
24
|
options.beforeHide?.(state);
|
|
@@ -12,3 +30,4 @@ export const listener = ({options, state}) => {
|
|
|
12
30
|
insideSubmenu: false,
|
|
13
31
|
};
|
|
14
32
|
};
|
|
33
|
+
|
|
@@ -1,12 +1,24 @@
|
|
|
1
1
|
import jessy from 'jessy';
|
|
2
|
+
import {getMenuPath as _getMenuPath} from './menu/get-menu-path.js';
|
|
3
|
+
|
|
4
|
+
const isFn = (a) => typeof a === 'function';
|
|
2
5
|
|
|
3
6
|
export const createItemClick = (name) => ({
|
|
4
7
|
name,
|
|
5
8
|
events: ['click'],
|
|
6
9
|
listener,
|
|
10
|
+
filter,
|
|
7
11
|
});
|
|
8
12
|
|
|
9
|
-
const
|
|
13
|
+
const filter = ({event, options, getMenuPath = _getMenuPath}) => {
|
|
14
|
+
const {menu} = options;
|
|
15
|
+
const menuPath = getMenuPath(event);
|
|
16
|
+
const fn = jessy(menuPath, menu);
|
|
17
|
+
|
|
18
|
+
return isFn(fn);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const listener = ({event, options, getMenuPath = _getMenuPath}) => {
|
|
10
22
|
const {menu} = options;
|
|
11
23
|
const menuPath = getMenuPath(event);
|
|
12
24
|
const fn = jessy(menuPath, menu);
|
|
@@ -21,12 +33,3 @@ const listener = ({event, options}) => {
|
|
|
21
33
|
};
|
|
22
34
|
};
|
|
23
35
|
|
|
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
|
-
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export function getMenuPath(event) {
|
|
2
|
+
let menuItemElement = document.elementFromPoint(event.clientX, event.clientY);
|
|
3
|
+
const {menuPath} = menuItemElement.dataset;
|
|
4
|
+
|
|
5
|
+
if (!menuPath)
|
|
6
|
+
menuItemElement = menuItemElement.querySelector('[data-menu-path]');
|
|
7
|
+
|
|
8
|
+
if (!menuPath)
|
|
9
|
+
return '';
|
|
10
|
+
|
|
11
|
+
return menuItemElement.dataset.menuPath;
|
|
12
|
+
}
|
|
13
|
+
|
package/menu/addons/shift-g.js
CHANGED
package/menu/menu.js
CHANGED
|
@@ -7,7 +7,7 @@ export const createMenu = async (elementName, options, menu) => {
|
|
|
7
7
|
const hydrateElement = createHydrate(name);
|
|
8
8
|
|
|
9
9
|
await createMap();
|
|
10
|
-
await
|
|
10
|
+
await loadStyle();
|
|
11
11
|
|
|
12
12
|
createStateElement(name);
|
|
13
13
|
const {hydrateMenu} = await import('./hydrate-menu.js');
|
|
@@ -19,21 +19,39 @@ export const createMenu = async (elementName, options, menu) => {
|
|
|
19
19
|
});
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
-
async function
|
|
22
|
+
async function loadStyle() {
|
|
23
23
|
const name = 'aleman-menu-style';
|
|
24
24
|
|
|
25
25
|
if (findByName(name))
|
|
26
26
|
return;
|
|
27
27
|
|
|
28
|
-
const
|
|
28
|
+
const [error] = await tryToCatch(importCSS);
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
if (!error)
|
|
31
|
+
return;
|
|
32
|
+
|
|
33
|
+
createLink();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function createLink() {
|
|
37
|
+
const link = document.createElement('link');
|
|
38
|
+
|
|
39
|
+
link.rel = 'stylesheet';
|
|
40
|
+
link.href = new URL('menu.css', import.meta.url).pathname;
|
|
41
|
+
document.head.appendChild(link);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async function importCSS() {
|
|
31
45
|
const content = await import('./menu.css', {
|
|
32
46
|
with: {
|
|
33
47
|
type: 'css',
|
|
34
48
|
},
|
|
35
49
|
});
|
|
36
50
|
|
|
51
|
+
const style = document.createElement('style');
|
|
52
|
+
|
|
53
|
+
style.dataset.name = name;
|
|
54
|
+
|
|
37
55
|
for (const rule of content.default.cssRules) {
|
|
38
56
|
style.innerHTML += rule.cssText;
|
|
39
57
|
}
|
|
@@ -89,3 +107,11 @@ async function createMap() {
|
|
|
89
107
|
function findByName(name) {
|
|
90
108
|
return document.querySelector(`[data-name=${name}]`);
|
|
91
109
|
}
|
|
110
|
+
|
|
111
|
+
async function tryToCatch(fn, args) {
|
|
112
|
+
try {
|
|
113
|
+
return [null, await fn(...args)];
|
|
114
|
+
} catch(error) {
|
|
115
|
+
return [error];
|
|
116
|
+
}
|
|
117
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aleman",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.10.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "🐊Putout-based framework for web",
|
|
@@ -29,7 +29,8 @@
|
|
|
29
29
|
"html-escaper": "^3.0.3",
|
|
30
30
|
"jessy": "^4.1.0",
|
|
31
31
|
"once": "^1.4.0",
|
|
32
|
-
"putout": "^40.5.1"
|
|
32
|
+
"putout": "^40.5.1",
|
|
33
|
+
"try-to-catch": "^3.0.1"
|
|
33
34
|
},
|
|
34
35
|
"keywords": [
|
|
35
36
|
"putout",
|