aleman 1.12.3 → 1.13.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/aleman/add-listeners.js +15 -15
- package/aleman/emit.js +52 -0
- package/aleman/render.js +6 -2
- package/menu/addons/context-menu.js +1 -1
- package/menu/addons/index.js +1 -1
- package/menu/addons/k/fixture/k-fix.html +1 -0
- package/menu/addons/k/fixture/k.html +8 -0
- package/menu/addons/k/fixture/m.js +8 -0
- package/menu/addons/{k.js → k/k.js} +5 -5
- package/menu/addons/set-position/calculate.js +28 -0
- package/menu/addons/{set-position.js → set-position/set-position.js} +12 -27
- package/menu/addons/up.js +3 -0
- package/menu/hydrate-menu.js +1 -1
- package/menu/importmap.js +1 -1
- package/menu/rules/build-menu/index.js +2 -3
- package/menu/rules/select/index.js +10 -3
- package/menu/state.js +12 -19
- package/package.json +4 -1
package/ChangeLog
CHANGED
package/aleman/add-listeners.js
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import {createVimParser} from './vim.js';
|
|
2
|
+
import {
|
|
3
|
+
emitBefore,
|
|
4
|
+
emitIf,
|
|
5
|
+
emitRun,
|
|
6
|
+
} from './emit.js';
|
|
2
7
|
|
|
3
8
|
const queryElement = ({name}) => {
|
|
4
9
|
return document.querySelector(`[data-name="${name}"]`);
|
|
@@ -65,34 +70,30 @@ export const addGlobalListeners = ({globalAddons, options, readState, writeState
|
|
|
65
70
|
|
|
66
71
|
const createListener = ({options, addon, readState, writeState, parseVim = createVimParser()}) => (event) => {
|
|
67
72
|
const {
|
|
68
|
-
keys,
|
|
69
|
-
listener,
|
|
70
73
|
preventDefault,
|
|
71
74
|
stopPropagation,
|
|
72
|
-
filter,
|
|
73
75
|
after,
|
|
74
76
|
afterIf,
|
|
75
|
-
commands,
|
|
76
77
|
} = addon;
|
|
77
78
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
79
|
+
const [isEmitBefore, count] = emitBefore(addon, {
|
|
80
|
+
event,
|
|
81
|
+
parseVim,
|
|
82
|
+
});
|
|
82
83
|
|
|
83
|
-
if (
|
|
84
|
-
return;
|
|
84
|
+
if (!isEmitBefore)
|
|
85
|
+
return false;
|
|
85
86
|
|
|
86
87
|
const state = readState();
|
|
87
88
|
|
|
88
|
-
const is =
|
|
89
|
+
const is = emitIf(addon, {
|
|
89
90
|
event,
|
|
90
91
|
state,
|
|
91
92
|
options,
|
|
92
93
|
});
|
|
93
94
|
|
|
94
|
-
if (
|
|
95
|
-
return
|
|
95
|
+
if (!is)
|
|
96
|
+
return;
|
|
96
97
|
|
|
97
98
|
if (preventDefault)
|
|
98
99
|
event.preventDefault();
|
|
@@ -100,12 +101,11 @@ const createListener = ({options, addon, readState, writeState, parseVim = creat
|
|
|
100
101
|
if (stopPropagation)
|
|
101
102
|
event.stopPropagation();
|
|
102
103
|
|
|
103
|
-
const newState =
|
|
104
|
+
const newState = emitRun(addon, {
|
|
104
105
|
count,
|
|
105
106
|
event,
|
|
106
107
|
state,
|
|
107
108
|
options,
|
|
108
|
-
writeState,
|
|
109
109
|
});
|
|
110
110
|
|
|
111
111
|
writeState(newState);
|
package/aleman/emit.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export const emit = (addon, {state, options, event, parseVim}) => {
|
|
2
|
+
const [isEmitBefore, count] = emitBefore(addon, {
|
|
3
|
+
event,
|
|
4
|
+
parseVim,
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
if (!isEmitBefore)
|
|
8
|
+
return false;
|
|
9
|
+
|
|
10
|
+
if (!emitIf(addon, {state, event}))
|
|
11
|
+
return state;
|
|
12
|
+
|
|
13
|
+
return emitRun(addon, {
|
|
14
|
+
event,
|
|
15
|
+
state,
|
|
16
|
+
options,
|
|
17
|
+
count,
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
export const emitIf = (addon, {state, event, options}) => {
|
|
21
|
+
if (!addon.filter)
|
|
22
|
+
return true;
|
|
23
|
+
|
|
24
|
+
return addon.filter({
|
|
25
|
+
state,
|
|
26
|
+
event,
|
|
27
|
+
options,
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const emitRun = (addon, {count, state, event, options}) => {
|
|
32
|
+
return addon.listener({
|
|
33
|
+
count,
|
|
34
|
+
event,
|
|
35
|
+
state,
|
|
36
|
+
options,
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export const emitBefore = (addon, {event, parseVim}) => {
|
|
41
|
+
const {keys, commands} = addon;
|
|
42
|
+
|
|
43
|
+
if (keys && !keys.includes(event.key))
|
|
44
|
+
return [false];
|
|
45
|
+
|
|
46
|
+
const [command, count] = parseVim(event);
|
|
47
|
+
|
|
48
|
+
if (commands && !commands.includes(command))
|
|
49
|
+
return [false];
|
|
50
|
+
|
|
51
|
+
return [true, count];
|
|
52
|
+
};
|
package/aleman/render.js
CHANGED
|
@@ -33,7 +33,7 @@ export const createRender = (html, {options, rules}) => {
|
|
|
33
33
|
});
|
|
34
34
|
|
|
35
35
|
if (!places.length)
|
|
36
|
-
return [SKIP];
|
|
36
|
+
return [SKIP, '', places];
|
|
37
37
|
|
|
38
38
|
transform(ast, '', {
|
|
39
39
|
rules: currentRules,
|
|
@@ -53,6 +53,10 @@ export const createRender = (html, {options, rules}) => {
|
|
|
53
53
|
const suffix = '<\\template>\n';
|
|
54
54
|
const result = merge('', [code]).slice(prefix.length, -suffix.length);
|
|
55
55
|
|
|
56
|
-
return [
|
|
56
|
+
return [
|
|
57
|
+
TRANSFORM,
|
|
58
|
+
result,
|
|
59
|
+
places,
|
|
60
|
+
];
|
|
57
61
|
};
|
|
58
62
|
};
|
package/menu/addons/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<ul data-name="menu" class="menu menu-hidden" style="left: 0px; top: 20px;"> <li data-name="menu-item" data-menu-index="0" class="menu-item icon icon-view menu-item-selected"> <label data-menu-path="View">View</label></li> <li data-name="menu-item" data-menu-index="1" class="menu-item icon icon-edit"> <label data-menu-path="Edit">Edit</label></li></ul>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<ul data-name="menu" className="menu menu-hidden" style="left: 0px; top: 20px;">
|
|
2
|
+
<li data-name="menu-item" data-menu-index="0" className="menu-item icon icon-view">
|
|
3
|
+
<label data-menu-path="View">View</label>
|
|
4
|
+
</li>
|
|
5
|
+
<li data-name="menu-item" data-menu-index="1" className="menu-item icon icon-edit menu-item-selected">
|
|
6
|
+
<label data-menu-path="Edit">Edit</label>
|
|
7
|
+
</li>
|
|
8
|
+
</ul>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
<ul data-name="menu" class="menu menu-hidden" style="left: 0px; top: 20px;">
|
|
2
|
+
<li data-name="menu-item" data-menu-index="0" className="menu-item icon icon-view">
|
|
3
|
+
<label data-menu-path="View">View</label>
|
|
4
|
+
</li>
|
|
5
|
+
<li data-name="menu-item" data-menu-index="1" className="menu-item icon icon-edit menu-item-selected">
|
|
6
|
+
<label data-menu-path="Edit">Edit</label>
|
|
7
|
+
</li>
|
|
8
|
+
</ul>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as up from '../up.js';
|
|
2
2
|
|
|
3
|
-
export const {filter} =
|
|
3
|
+
export const {filter} = up;
|
|
4
4
|
export const commands = ['k'];
|
|
5
5
|
|
|
6
6
|
export function listener({count, state, options}) {
|
|
@@ -10,8 +10,8 @@ export function listener({count, state, options}) {
|
|
|
10
10
|
submenuIndex,
|
|
11
11
|
} = state;
|
|
12
12
|
|
|
13
|
-
let newIndex = insideSubmenu ? index : index - count
|
|
14
|
-
let newSubmenuIndex = insideSubmenu ? submenuIndex - count
|
|
13
|
+
let newIndex = insideSubmenu ? index : index - count + 1;
|
|
14
|
+
let newSubmenuIndex = insideSubmenu ? submenuIndex - count + 1 : submenuIndex;
|
|
15
15
|
|
|
16
16
|
if (newIndex < -1)
|
|
17
17
|
newIndex = -1;
|
|
@@ -25,7 +25,7 @@ export function listener({count, state, options}) {
|
|
|
25
25
|
submenuIndex: newSubmenuIndex,
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
-
return
|
|
28
|
+
return up.listener({
|
|
29
29
|
state: newState,
|
|
30
30
|
options,
|
|
31
31
|
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export function calculate(event, sizes) {
|
|
2
|
+
let {clientX, clientY} = event;
|
|
3
|
+
const {
|
|
4
|
+
heightMenu,
|
|
5
|
+
widthMenu,
|
|
6
|
+
innerHeight,
|
|
7
|
+
innerWidth,
|
|
8
|
+
} = sizes;
|
|
9
|
+
|
|
10
|
+
if (innerWidth < widthMenu + clientX + clientX / 2) {
|
|
11
|
+
clientX -= widthMenu;
|
|
12
|
+
|
|
13
|
+
if (clientX < 0)
|
|
14
|
+
clientX = 0;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (innerHeight < heightMenu + clientY) {
|
|
18
|
+
clientY -= heightMenu;
|
|
19
|
+
|
|
20
|
+
if (clientY < 0)
|
|
21
|
+
clientY = 0;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
x: clientX,
|
|
26
|
+
y: clientY - 14,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
@@ -1,6 +1,17 @@
|
|
|
1
|
+
import {calculate} from './calculate.js';
|
|
2
|
+
|
|
1
3
|
export const setPosition = (name, event) => {
|
|
2
4
|
const element = document.querySelector(`[data-name="${name}"]`);
|
|
3
|
-
const
|
|
5
|
+
const heightMenu = getMenuHeight(element);
|
|
6
|
+
const widthMenu = getMenuWidth(element);
|
|
7
|
+
const {innerHeight, innerWidth} = window;
|
|
8
|
+
|
|
9
|
+
const {x, y} = calculate(event, {
|
|
10
|
+
heightMenu,
|
|
11
|
+
widthMenu,
|
|
12
|
+
innerWidth,
|
|
13
|
+
innerHeight,
|
|
14
|
+
});
|
|
4
15
|
|
|
5
16
|
element.style.left = `${x}px`;
|
|
6
17
|
element.style.top = `${y}px`;
|
|
@@ -13,32 +24,6 @@ export const setPosition = (name, event) => {
|
|
|
13
24
|
};
|
|
14
25
|
};
|
|
15
26
|
|
|
16
|
-
function calculate(element, {clientX, clientY}) {
|
|
17
|
-
const heightMenu = getMenuHeight(element);
|
|
18
|
-
const widthMenu = getMenuWidth(element);
|
|
19
|
-
const heightInner = window.innerHeight;
|
|
20
|
-
const widthInner = window.innerWidth;
|
|
21
|
-
|
|
22
|
-
if (widthInner < widthMenu + clientX) {
|
|
23
|
-
clientX -= widthMenu;
|
|
24
|
-
|
|
25
|
-
if (clientX < 0)
|
|
26
|
-
clientX = 0;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (heightInner < heightMenu + clientY) {
|
|
30
|
-
clientY -= heightMenu;
|
|
31
|
-
|
|
32
|
-
if (clientY < 0)
|
|
33
|
-
clientY = 0;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return {
|
|
37
|
-
x: clientX,
|
|
38
|
-
y: clientY - 14,
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
|
|
42
27
|
function getMenuHeight(element) {
|
|
43
28
|
const {height} = getComputedStyle(element);
|
|
44
29
|
return parseInt(height, 10);
|
package/menu/addons/up.js
CHANGED
|
@@ -3,6 +3,9 @@ import {getSubmenu} from './submenu/index.js';
|
|
|
3
3
|
export const keys = ['ArrowUp'];
|
|
4
4
|
|
|
5
5
|
export const preventDefault = true;
|
|
6
|
+
export const filter = ({state, options}) => {
|
|
7
|
+
return state.command === 'show';
|
|
8
|
+
};
|
|
6
9
|
|
|
7
10
|
export const listener = ({state, options}) => {
|
|
8
11
|
const {menu} = options;
|
package/menu/hydrate-menu.js
CHANGED
|
@@ -6,7 +6,7 @@ import {createMouseEnter} from './addons/mouse-enter.js';
|
|
|
6
6
|
import {createItemClick} from './addons/item-click.js';
|
|
7
7
|
import * as click from './addons/click.js';
|
|
8
8
|
import {createContextMenu} from './addons/context-menu.js';
|
|
9
|
-
import {setPosition} from './addons/set-position.js';
|
|
9
|
+
import {setPosition} from './addons/set-position/set-position.js';
|
|
10
10
|
|
|
11
11
|
const {assign} = Object;
|
|
12
12
|
|
package/menu/importmap.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export const importmap = {
|
|
2
2
|
imports: {
|
|
3
|
-
'putout': 'https://esm.sh/@putout/bundle@4.7.
|
|
3
|
+
'putout': 'https://esm.sh/@putout/bundle@4.7.4',
|
|
4
4
|
'@putout/processor-html': 'https://esm.sh/@putout/processor-html',
|
|
5
5
|
'fullstore': 'https://esm.sh/fullstore',
|
|
6
6
|
'jessy': 'https://esm.sh/jessy',
|
|
@@ -8,7 +8,6 @@ const {
|
|
|
8
8
|
|
|
9
9
|
const {entries} = Object;
|
|
10
10
|
|
|
11
|
-
const noop = () => {};
|
|
12
11
|
const isObject = (a) => a && typeof a === 'object';
|
|
13
12
|
|
|
14
13
|
export const report = () => `Build menu`;
|
|
@@ -22,8 +21,8 @@ const createMenu = template(`
|
|
|
22
21
|
`);
|
|
23
22
|
|
|
24
23
|
const DefaultMenu = {
|
|
25
|
-
hello:
|
|
26
|
-
world:
|
|
24
|
+
hello: null,
|
|
25
|
+
world: null,
|
|
27
26
|
};
|
|
28
27
|
|
|
29
28
|
export const fix = ({path, menu, icon, name = ''}) => {
|
|
@@ -6,6 +6,8 @@ const {
|
|
|
6
6
|
addClassName,
|
|
7
7
|
hasDataName,
|
|
8
8
|
removeClassName,
|
|
9
|
+
hasAttributeValue,
|
|
10
|
+
containsClassName,
|
|
9
11
|
} = operator;
|
|
10
12
|
|
|
11
13
|
const SELECTED = 'menu-item-selected';
|
|
@@ -31,6 +33,7 @@ export const traverse = ({options, push}) => ({
|
|
|
31
33
|
name = 'menu',
|
|
32
34
|
index = 1,
|
|
33
35
|
showSubmenu,
|
|
36
|
+
insideSubmenu,
|
|
34
37
|
} = options;
|
|
35
38
|
|
|
36
39
|
if (!hasTagName(path, 'li'))
|
|
@@ -44,15 +47,18 @@ export const traverse = ({options, push}) => ({
|
|
|
44
47
|
if (!hasDataName(parentPath, name))
|
|
45
48
|
return;
|
|
46
49
|
|
|
50
|
+
if (!insideSubmenu && !hasAttributeValue(path, 'data-menu-index', `${index}`))
|
|
51
|
+
return;
|
|
52
|
+
|
|
53
|
+
if (!insideSubmenu && containsClassName(path, 'menu-item-selected'))
|
|
54
|
+
return;
|
|
55
|
+
|
|
47
56
|
const children = parentPath.get('children').filter(isJSXElement);
|
|
48
57
|
|
|
49
58
|
const prev = children[index - 1];
|
|
50
59
|
const current = children[index];
|
|
51
60
|
const next = children[index + 1];
|
|
52
61
|
|
|
53
|
-
if (!current)
|
|
54
|
-
return;
|
|
55
|
-
|
|
56
62
|
push({
|
|
57
63
|
path: current,
|
|
58
64
|
prev,
|
|
@@ -74,3 +80,4 @@ function addShowSubmenu(path, {showSubmenu}) {
|
|
|
74
80
|
function removeShowSubmenu(path) {
|
|
75
81
|
removeClassName(path, SHOW);
|
|
76
82
|
}
|
|
83
|
+
|
package/menu/state.js
CHANGED
|
@@ -1,19 +1,12 @@
|
|
|
1
|
-
const {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
count,
|
|
14
|
-
position: {
|
|
15
|
-
x: 0,
|
|
16
|
-
y: 20,
|
|
17
|
-
},
|
|
18
|
-
};
|
|
19
|
-
};
|
|
1
|
+
export const initState = ({name = 'menu'}) => ({
|
|
2
|
+
name,
|
|
3
|
+
command: 'hide',
|
|
4
|
+
insideSubmenu: false,
|
|
5
|
+
submenuIndex: 0,
|
|
6
|
+
showSubmenu: false,
|
|
7
|
+
index: -1,
|
|
8
|
+
position: {
|
|
9
|
+
x: 0,
|
|
10
|
+
y: 20,
|
|
11
|
+
},
|
|
12
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aleman",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.13.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",
|
|
@@ -23,6 +23,9 @@
|
|
|
23
23
|
"coverage": "madrun coverage",
|
|
24
24
|
"report": "madrun report"
|
|
25
25
|
},
|
|
26
|
+
"imports": {
|
|
27
|
+
"#test": "./test/create-test.js"
|
|
28
|
+
},
|
|
26
29
|
"dependencies": {
|
|
27
30
|
"@putout/processor-html": "^14.0.2",
|
|
28
31
|
"fullstore": "^3.0.0",
|