aleman 1.1.44 → 1.2.1
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 +13 -0
- package/aleman/add-listeners.js +12 -0
- package/aleman/index.js +21 -3
- package/menu/addons/context-menu.js +22 -5
- package/menu/addons/set-position.js +51 -0
- package/menu/hydrate-menu.js +10 -8
- package/package.json +2 -2
package/ChangeLog
CHANGED
package/aleman/add-listeners.js
CHANGED
|
@@ -68,6 +68,8 @@ const createListener = ({options, addon, readState, writeState}) => (event) => {
|
|
|
68
68
|
preventDefault,
|
|
69
69
|
stopPropagation,
|
|
70
70
|
filter,
|
|
71
|
+
after,
|
|
72
|
+
conditionAfter,
|
|
71
73
|
} = addon;
|
|
72
74
|
|
|
73
75
|
if (key && event.key !== key)
|
|
@@ -94,7 +96,17 @@ const createListener = ({options, addon, readState, writeState}) => (event) => {
|
|
|
94
96
|
event,
|
|
95
97
|
state,
|
|
96
98
|
options,
|
|
99
|
+
writeState,
|
|
97
100
|
});
|
|
98
101
|
|
|
99
102
|
writeState(newState);
|
|
103
|
+
|
|
104
|
+
if (after && conditionAfter?.({state: newState, options}))
|
|
105
|
+
requestAnimationFrame(() => {
|
|
106
|
+
writeState(after({
|
|
107
|
+
event,
|
|
108
|
+
state: newState,
|
|
109
|
+
options,
|
|
110
|
+
}));
|
|
111
|
+
});
|
|
100
112
|
};
|
package/aleman/index.js
CHANGED
|
@@ -8,7 +8,15 @@ import {createRender} from './render.js';
|
|
|
8
8
|
|
|
9
9
|
const id = (a) => a;
|
|
10
10
|
|
|
11
|
-
export const hydrate = (element,
|
|
11
|
+
export const hydrate = (element, config) => {
|
|
12
|
+
const {
|
|
13
|
+
addons,
|
|
14
|
+
options,
|
|
15
|
+
state,
|
|
16
|
+
rules,
|
|
17
|
+
stateName = 'aleman-state',
|
|
18
|
+
} = config;
|
|
19
|
+
|
|
12
20
|
const render = createRender(element.innerHTML, {
|
|
13
21
|
options,
|
|
14
22
|
rules,
|
|
@@ -45,18 +53,28 @@ export const hydrate = (element, {addons, options, state, rules, stateName = 'al
|
|
|
45
53
|
});
|
|
46
54
|
|
|
47
55
|
return {
|
|
48
|
-
run: (event,
|
|
56
|
+
run: (event, addon) => {
|
|
49
57
|
const state = readState();
|
|
50
|
-
const newState =
|
|
58
|
+
const newState = addon.listener({
|
|
51
59
|
state,
|
|
52
60
|
event,
|
|
53
61
|
options,
|
|
62
|
+
writeState,
|
|
54
63
|
});
|
|
55
64
|
|
|
56
65
|
writeState({
|
|
57
66
|
...state,
|
|
58
67
|
...newState,
|
|
59
68
|
});
|
|
69
|
+
|
|
70
|
+
if (addon.conditionAfter?.({state: newState, options}))
|
|
71
|
+
requestAnimationFrame(() => {
|
|
72
|
+
writeState(addon.after({
|
|
73
|
+
event,
|
|
74
|
+
options,
|
|
75
|
+
state: newState,
|
|
76
|
+
}));
|
|
77
|
+
});
|
|
60
78
|
},
|
|
61
79
|
};
|
|
62
80
|
};
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
import {setPosition} from './set-position.js';
|
|
2
|
+
|
|
1
3
|
export const createContextMenu = (name) => {
|
|
2
4
|
return {
|
|
3
5
|
name,
|
|
4
6
|
events,
|
|
5
7
|
preventDefault,
|
|
8
|
+
after,
|
|
6
9
|
listener,
|
|
10
|
+
conditionAfter,
|
|
7
11
|
};
|
|
8
12
|
};
|
|
9
13
|
|
|
@@ -13,14 +17,18 @@ const events = [
|
|
|
13
17
|
|
|
14
18
|
const preventDefault = true;
|
|
15
19
|
|
|
16
|
-
const listener = ({event, state, options}) => {
|
|
20
|
+
const listener = ({event, state, options, writeState}) => {
|
|
17
21
|
const {beforeShow} = options;
|
|
22
|
+
const {x, y} = {
|
|
23
|
+
x: event.clientX,
|
|
24
|
+
y: event.clientY,
|
|
25
|
+
};
|
|
18
26
|
|
|
19
27
|
const is = !beforeShow || beforeShow?.({
|
|
20
28
|
...state,
|
|
21
29
|
position: {
|
|
22
|
-
x
|
|
23
|
-
y
|
|
30
|
+
x,
|
|
31
|
+
y,
|
|
24
32
|
},
|
|
25
33
|
});
|
|
26
34
|
|
|
@@ -29,8 +37,17 @@ const listener = ({event, state, options}) => {
|
|
|
29
37
|
return {
|
|
30
38
|
command,
|
|
31
39
|
position: {
|
|
32
|
-
x
|
|
33
|
-
y:
|
|
40
|
+
x,
|
|
41
|
+
y: y - 14,
|
|
34
42
|
},
|
|
35
43
|
};
|
|
36
44
|
};
|
|
45
|
+
|
|
46
|
+
const after = ({event, options}) => {
|
|
47
|
+
const {name} = options;
|
|
48
|
+
return setPosition(name, event);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const conditionAfter = ({state}) => {
|
|
52
|
+
return state.command === 'show';
|
|
53
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export const setPosition = (name, event) => {
|
|
2
|
+
const element = document.querySelector(`[data-name="${name}"]`);
|
|
3
|
+
const {x, y} = calculate(element, event);
|
|
4
|
+
|
|
5
|
+
element.style.left = `${x}px`;
|
|
6
|
+
element.style.top = `${y}px`;
|
|
7
|
+
|
|
8
|
+
return {
|
|
9
|
+
position: {
|
|
10
|
+
x,
|
|
11
|
+
y,
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
|
|
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
|
+
function getMenuHeight(element) {
|
|
43
|
+
const {height} = getComputedStyle(element);
|
|
44
|
+
return parseInt(height, 10);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function getMenuWidth(element) {
|
|
48
|
+
const {width} = getComputedStyle(element);
|
|
49
|
+
return parseInt(width, 10);
|
|
50
|
+
}
|
|
51
|
+
|
package/menu/hydrate-menu.js
CHANGED
|
@@ -4,30 +4,32 @@ import {initState} from './state.js';
|
|
|
4
4
|
import {addons} from './addons/index.js';
|
|
5
5
|
import {createMouseEnter} from './addons/mouse-enter.js';
|
|
6
6
|
import {createItemClick} from './addons/item-click.js';
|
|
7
|
-
import * as contextMenu from './addons/context-menu.js';
|
|
8
7
|
import * as click from './addons/click.js';
|
|
9
8
|
import {createContextMenu} from './addons/context-menu.js';
|
|
9
|
+
import {setPosition} from './addons/set-position.js';
|
|
10
10
|
|
|
11
11
|
const {assign} = Object;
|
|
12
12
|
|
|
13
|
-
export const hydrateMenu = (
|
|
13
|
+
export const hydrateMenu = (elementName, {hydrateElement, options, menu}) => {
|
|
14
14
|
assign(options, {
|
|
15
15
|
menu,
|
|
16
16
|
});
|
|
17
17
|
|
|
18
|
+
const {name} = options;
|
|
18
19
|
const state = initState(options);
|
|
19
|
-
const contextMenu = createContextMenu(
|
|
20
|
+
const contextMenu = createContextMenu(elementName);
|
|
20
21
|
const {run} = hydrate(hydrateElement, {
|
|
21
22
|
options,
|
|
22
23
|
state,
|
|
23
24
|
addons: [
|
|
24
25
|
contextMenu,
|
|
25
|
-
createMouseEnter(
|
|
26
|
-
createItemClick(
|
|
26
|
+
createMouseEnter(name),
|
|
27
|
+
createItemClick(name),
|
|
27
28
|
...addons,
|
|
28
29
|
],
|
|
29
30
|
rules,
|
|
30
|
-
|
|
31
|
+
afterHydrate: setPosition,
|
|
32
|
+
stateName: `aleman-state-${name}`,
|
|
31
33
|
});
|
|
32
34
|
|
|
33
35
|
return {
|
|
@@ -37,8 +39,8 @@ export const hydrateMenu = (name, {hydrateElement, options, menu}) => {
|
|
|
37
39
|
clientY,
|
|
38
40
|
};
|
|
39
41
|
|
|
40
|
-
run(event, contextMenu
|
|
42
|
+
run(event, contextMenu, options.beforeShow);
|
|
41
43
|
},
|
|
42
|
-
hide: () => run({}, click
|
|
44
|
+
hide: () => run({}, click, options.beforeHide),
|
|
43
45
|
};
|
|
44
46
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aleman",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "🐊Putout-based framework for web",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"main": "aleman/index.js",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
|
-
"url": "git+https://github.com/
|
|
11
|
+
"url": "git+https://github.com/putoutjs/aleman.git"
|
|
12
12
|
},
|
|
13
13
|
"exports": {
|
|
14
14
|
"./menu": "./menu/menu.js"
|