aleman 1.1.32 → 1.1.34

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/aleman/index.js CHANGED
@@ -6,6 +6,8 @@ import {
6
6
  } from './add-listeners.js';
7
7
  import {createRender} from './render.js';
8
8
 
9
+ const id = (a) => a;
10
+
9
11
  export const hydrate = (element, {addons, options, state, rules, stateName = 'aleman-state'}) => {
10
12
  const render = createRender(element.innerHTML, {
11
13
  options,
@@ -43,24 +45,19 @@ export const hydrate = (element, {addons, options, state, rules, stateName = 'al
43
45
  });
44
46
 
45
47
  return {
46
- run: (partialState) => {
47
- const state = {
48
- ...readState(),
49
- ...partialState,
50
- };
51
-
52
- const [is, result] = render(state);
53
-
54
- if (!is)
55
- return;
56
-
57
- element.innerHTML = result;
58
- addListeners({
59
- readState,
60
- writeState,
61
- namedAddons,
48
+ run: (event, fn = id, condition) => {
49
+ const state = readState();
50
+ const newState = fn({
51
+ state,
52
+ event,
62
53
  options,
63
54
  });
55
+
56
+ writeState({
57
+ ...state,
58
+ ...newState,
59
+ });
64
60
  },
65
61
  };
66
62
  };
63
+
@@ -1,5 +1,9 @@
1
1
  export const events = ['click'];
2
2
 
3
+ export const filter = ({state}) => {
4
+ return state.command === 'show';
5
+ };
6
+
3
7
  export const listener = ({options, state}) => {
4
8
  options.beforeClick?.(state);
5
9
  options.beforeHide?.(state);
package/menu/addons/f9.js CHANGED
@@ -6,21 +6,11 @@ export const filter = ({state, options}) => {
6
6
  if (!beforeShow)
7
7
  return true;
8
8
 
9
- return options.beforeShow?.({
10
- ...state,
11
- position: {
12
- x: state.position.left,
13
- y: state.position.top,
14
- },
15
- });
9
+ return options.beforeShow?.(state);
16
10
  };
17
11
 
18
12
  export const listener = ({options, state}) => {
19
13
  return {
20
14
  command: 'show',
21
- position: {
22
- left: 0,
23
- top: 0,
24
- },
25
15
  };
26
16
  };
@@ -4,6 +4,8 @@ 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
+ import * as click from './addons/click.js';
7
9
 
8
10
  const {assign} = Object;
9
11
 
@@ -13,8 +15,6 @@ export const hydrateMenu = (element, options, menu) => {
13
15
  });
14
16
 
15
17
  const state = initState(options);
16
- const {beforeShow} = options;
17
- beforeShow?.(state);
18
18
  const {run} = hydrate(element, {
19
19
  options,
20
20
  state,
@@ -27,16 +27,14 @@ export const hydrateMenu = (element, options, menu) => {
27
27
  stateName: `aleman-state-${options.name}`,
28
28
  });
29
29
 
30
- const show = run.bind(null, {
31
- command: 'show',
32
- });
33
-
34
- const hide = run.bind(null, {
35
- command: 'hide',
36
- });
37
-
38
30
  return {
39
- show,
40
- hide,
31
+ show: (clientX, clientY) => {
32
+ const event = {
33
+ clientX,
34
+ clientY,
35
+ };
36
+ run(event, contextMenu.listener, options.beforeShow);
37
+ },
38
+ hide: () => run({}, click.listener, options.beforeHide),
41
39
  };
42
40
  };
@@ -0,0 +1,8 @@
1
+ <ul data-name="menu" class="menu menu-hidden">
2
+ <li data-name='menu-item' className='menu-item icon icon-hello'>
3
+ <label>hello</label>
4
+ </li>
5
+ <li data-name='menu-item' className='menu-item icon icon-world'>
6
+ <label>world</label>
7
+ </li>
8
+ </ul>;
@@ -0,0 +1 @@
1
+ <ul data-name="menu" class="menu menu-hidden"></ul>;
@@ -1,6 +1,6 @@
1
1
  import {types, template} from 'putout';
2
2
 
3
- const {entries} = Object;
3
+ const {entries, keys} = Object;
4
4
  const noop = () => {};
5
5
  const {jsxText} = types;
6
6
 
@@ -20,13 +20,17 @@ const DefaultMenu = {
20
20
  world: noop,
21
21
  };
22
22
 
23
- export const fix = ({path, menu}) => {
23
+ export const fix = ({path, menu, icon}) => {
24
24
  const items = [];
25
25
 
26
- for (const [key] of entries(menu)) {
26
+ for (const key of keys(menu)) {
27
27
  const menuItem = createMenuItem();
28
28
 
29
29
  menuItem.children[1].children[0].value = key;
30
+
31
+ if (icon)
32
+ setIcon(key, menuItem);
33
+
30
34
  items.push(INDENT, menuItem);
31
35
  }
32
36
 
@@ -39,6 +43,7 @@ export const traverse = ({options, push}) => ({
39
43
  const {
40
44
  name = 'menu',
41
45
  menu = DefaultMenu,
46
+ icon = false,
42
47
  } = options;
43
48
 
44
49
  if (!checkDataName(path, name))
@@ -50,6 +55,7 @@ export const traverse = ({options, push}) => ({
50
55
  push({
51
56
  path,
52
57
  menu,
58
+ icon,
53
59
  });
54
60
  },
55
61
  });
@@ -64,3 +70,21 @@ function checkDataName(path, dataName) {
64
70
 
65
71
  return false;
66
72
  }
73
+
74
+ function setIcon(name, menuItem) {
75
+ const {attributes} = menuItem.openingElement;
76
+
77
+ for (const attr of attributes) {
78
+ if (attr.name.name === 'className') {
79
+ attr.value.value += ` icon ${getIconName(name)}`;
80
+ return;
81
+ }
82
+ }
83
+ }
84
+
85
+ function getIconName(name) {
86
+ return 'icon-' + name
87
+ .replace(/[()]/g, '')
88
+ .replace(/\s/g, '-')
89
+ .toLowerCase();
90
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aleman",
3
- "version": "1.1.32",
3
+ "version": "1.1.34",
4
4
  "type": "module",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊Putout-based framework for web",