aleman 1.1.43 → 1.2.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 +1 -0
- package/aleman/index.js +10 -1
- package/menu/addons/context-menu.js +28 -8
- package/menu/addons/index.js +0 -2
- package/menu/addons/set-position.js +51 -0
- package/menu/hydrate-menu.js +11 -6
- package/menu/menu.js +6 -2
- package/package.json +2 -2
package/ChangeLog
CHANGED
package/aleman/add-listeners.js
CHANGED
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,
|
|
@@ -51,6 +59,7 @@ export const hydrate = (element, {addons, options, state, rules, stateName = 'al
|
|
|
51
59
|
state,
|
|
52
60
|
event,
|
|
53
61
|
options,
|
|
62
|
+
writeState,
|
|
54
63
|
});
|
|
55
64
|
|
|
56
65
|
writeState({
|
|
@@ -1,27 +1,47 @@
|
|
|
1
|
-
|
|
1
|
+
import {setPosition} from './set-position.js';
|
|
2
|
+
|
|
3
|
+
export const createContextMenu = (name) => {
|
|
4
|
+
return {
|
|
5
|
+
name,
|
|
6
|
+
events,
|
|
7
|
+
preventDefault,
|
|
8
|
+
listener,
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const events = [
|
|
2
13
|
'contextmenu',
|
|
3
14
|
];
|
|
4
15
|
|
|
5
|
-
|
|
16
|
+
const preventDefault = true;
|
|
6
17
|
|
|
7
|
-
|
|
8
|
-
const {beforeShow} = options;
|
|
18
|
+
const listener = ({event, state, options, writeState}) => {
|
|
19
|
+
const {name, beforeShow} = options;
|
|
20
|
+
const {x, y} = {
|
|
21
|
+
x: event.clientX,
|
|
22
|
+
y: event.clientY,
|
|
23
|
+
};
|
|
9
24
|
|
|
10
25
|
const is = !beforeShow || beforeShow?.({
|
|
11
26
|
...state,
|
|
12
27
|
position: {
|
|
13
|
-
x
|
|
14
|
-
y
|
|
28
|
+
x,
|
|
29
|
+
y,
|
|
15
30
|
},
|
|
16
31
|
});
|
|
17
32
|
|
|
33
|
+
if (is)
|
|
34
|
+
requestAnimationFrame(() => {
|
|
35
|
+
writeState(setPosition(name, event));
|
|
36
|
+
}, 0);
|
|
37
|
+
|
|
18
38
|
const command = is ? 'show' : 'hide';
|
|
19
39
|
|
|
20
40
|
return {
|
|
21
41
|
command,
|
|
22
42
|
position: {
|
|
23
|
-
x
|
|
24
|
-
y:
|
|
43
|
+
x,
|
|
44
|
+
y: y - 14,
|
|
25
45
|
},
|
|
26
46
|
};
|
|
27
47
|
};
|
package/menu/addons/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as contextMenu from './context-menu.js';
|
|
2
1
|
import * as click from './click.js';
|
|
3
2
|
import * as escape from './escape.js';
|
|
4
3
|
import * as down from './down.js';
|
|
@@ -6,7 +5,6 @@ import * as up from './up.js';
|
|
|
6
5
|
import * as enter from './enter.js';
|
|
7
6
|
|
|
8
7
|
export const addons = [
|
|
9
|
-
contextMenu,
|
|
10
8
|
click,
|
|
11
9
|
escape,
|
|
12
10
|
down,
|
|
@@ -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 - 14}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,27 +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';
|
|
8
|
+
import {createContextMenu} from './addons/context-menu.js';
|
|
9
|
+
import {setPosition} from './addons/set-position.js';
|
|
9
10
|
|
|
10
11
|
const {assign} = Object;
|
|
11
12
|
|
|
12
|
-
export const hydrateMenu = (
|
|
13
|
+
export const hydrateMenu = (elementName, {hydrateElement, options, menu}) => {
|
|
13
14
|
assign(options, {
|
|
14
15
|
menu,
|
|
15
16
|
});
|
|
16
17
|
|
|
18
|
+
const {name} = options;
|
|
17
19
|
const state = initState(options);
|
|
18
|
-
const
|
|
20
|
+
const contextMenu = createContextMenu(elementName);
|
|
21
|
+
const {run} = hydrate(hydrateElement, {
|
|
19
22
|
options,
|
|
20
23
|
state,
|
|
21
24
|
addons: [
|
|
22
|
-
|
|
23
|
-
|
|
25
|
+
contextMenu,
|
|
26
|
+
createMouseEnter(name),
|
|
27
|
+
createItemClick(name),
|
|
24
28
|
...addons,
|
|
25
29
|
],
|
|
26
30
|
rules,
|
|
27
|
-
|
|
31
|
+
afterHydrate: setPosition,
|
|
32
|
+
stateName: `aleman-state-${name}`,
|
|
28
33
|
});
|
|
29
34
|
|
|
30
35
|
return {
|
package/menu/menu.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const {stringify} = JSON;
|
|
2
2
|
|
|
3
|
-
export const createMenu = async (
|
|
3
|
+
export const createMenu = async (elementName, options, menu) => {
|
|
4
4
|
options.name = options.name || 'menu';
|
|
5
5
|
const {name} = options;
|
|
6
6
|
|
|
@@ -12,7 +12,11 @@ export const createMenu = async (element, options, menuData) => {
|
|
|
12
12
|
createStateElement(name);
|
|
13
13
|
const {hydrateMenu} = await import('./hydrate-menu.js');
|
|
14
14
|
|
|
15
|
-
return hydrateMenu(
|
|
15
|
+
return hydrateMenu(elementName, {
|
|
16
|
+
hydrateElement,
|
|
17
|
+
options,
|
|
18
|
+
menu,
|
|
19
|
+
});
|
|
16
20
|
};
|
|
17
21
|
|
|
18
22
|
async function createLink() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aleman",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.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",
|
|
@@ -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"
|