aleman 1.1.36 → 1.1.38

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 ADDED
@@ -0,0 +1,9 @@
1
+ 2025.08.30, v1.1.38
2
+
3
+ fix:
4
+ - c235f46 aleman: menu: submenu
5
+
6
+ 2025.08.29, v1.1.37
7
+
8
+ fix:
9
+ - abf2a68 aleman: menu: click
package/aleman/index.js CHANGED
@@ -45,7 +45,7 @@ export const hydrate = (element, {addons, options, state, rules, stateName = 'al
45
45
  });
46
46
 
47
47
  return {
48
- run: (event, fn = id, condition) => {
48
+ run: (event, fn = id) => {
49
49
  const state = readState();
50
50
  const newState = fn({
51
51
  state,
@@ -60,4 +60,3 @@ export const hydrate = (element, {addons, options, state, rules, stateName = 'al
60
60
  },
61
61
  };
62
62
  };
63
-
@@ -1,12 +1,10 @@
1
1
  export const events = ['click'];
2
2
 
3
- export const filter = ({state}) => {
4
- return state.command === 'show';
5
- };
3
+ export const filter = ({state}) => state.command === 'show';
6
4
 
7
5
  export const listener = ({options, state}) => {
8
6
  options.beforeClick?.(state);
9
- options.beforeHide?.(state);
7
+ options.beforeClose?.(state);
10
8
 
11
9
  return {
12
10
  command: 'hide',
@@ -16,6 +16,7 @@ export const listener = ({event, state, options}) => {
16
16
  });
17
17
 
18
18
  const command = is ? 'show' : 'hide';
19
+
19
20
  return {
20
21
  command,
21
22
  position: {
@@ -2,9 +2,7 @@ const {values} = Object;
2
2
 
3
3
  export const key = 'Enter';
4
4
 
5
- export const filter = ({state}) => {
6
- return state.command === 'show';
7
- };
5
+ export const filter = ({state}) => state.command === 'show';
8
6
 
9
7
  export const listener = ({options, state}) => {
10
8
  const {index} = state;
package/menu/addons/f9.js CHANGED
@@ -9,8 +9,6 @@ export const filter = ({state, options}) => {
9
9
  return options.beforeShow?.(state);
10
10
  };
11
11
 
12
- export const listener = ({options, state}) => {
13
- return {
14
- command: 'show',
15
- };
16
- };
12
+ export const listener = () => ({
13
+ command: 'show',
14
+ });
@@ -33,6 +33,7 @@ export const hydrateMenu = (element, options, menu) => {
33
33
  clientX,
34
34
  clientY,
35
35
  };
36
+
36
37
  run(event, contextMenu.listener, options.beforeShow);
37
38
  },
38
39
  hide: () => run({}, click.listener, options.beforeHide),
@@ -1,7 +1,7 @@
1
1
  {
2
- "imports": {
3
- "putout": "https://esm.sh/@putout/bundle",
4
- "@putout/processor-html": "https://esm.sh/@putout/processor-html",
5
- "fullstore": "https://esm.sh/fullstore"
6
- }
2
+ "imports": {
3
+ "putout": "https://esm.sh/@putout/bundle",
4
+ "@putout/processor-html": "https://esm.sh/@putout/processor-html",
5
+ "fullstore": "https://esm.sh/fullstore"
6
+ }
7
7
  }
package/menu/menu.js CHANGED
@@ -73,6 +73,7 @@ async function createMap() {
73
73
  return;
74
74
 
75
75
  const script = document.createElement('script');
76
+
76
77
  const {default: importmap} = await import('./importmap.json', {
77
78
  with: {
78
79
  type: 'json',
@@ -1 +1 @@
1
- <ul data-name="menu" class="menu menu-hidden"><li data-name='menu-item' className='menu-item icon icon-hello'><label>hello</label></li><li data-name='menu-item' className='menu-item icon icon-world'><label>world</label></li></ul>;
1
+ <ul data-name="menu" class="menu menu-hidden"><li data-name='menu-item' className="menu-item icon icon-hello"><label>hello</label></li><li data-name='menu-item' className="menu-item icon icon-world"><label>world</label></li></ul>;
@@ -0,0 +1 @@
1
+ <ul data-name="menu" class="menu menu-hidden"><li data-name='menu-item' className="menu-item icon icon-hello"><label>hello</label><ul data-name='menu' className='menu menu-hidden'><li data-name='menu-item' className="menu-item icon icon-world"><label>world</label></li></ul></li></ul>;
@@ -0,0 +1 @@
1
+ <ul data-name="menu" class="menu menu-hidden"></ul>;
@@ -1,8 +1,13 @@
1
- import {types, template} from 'putout';
1
+ import {template, operator} from 'putout';
2
+ import {checkDataName} from '../check-data-name.js';
3
+
4
+ const {setLiteralValue} = operator;
5
+
6
+ const isObject = (a) => a && typeof a === 'object';
7
+
8
+ const {entries} = Object;
2
9
 
3
- const {entries, keys} = Object;
4
10
  const noop = () => {};
5
- const {jsxText} = types;
6
11
 
7
12
  export const report = () => `Build menu`;
8
13
 
@@ -10,8 +15,9 @@ const createMenuItem = template(`
10
15
  <li data-name="menu-item" className="menu-item"><label>NAME</label></li>
11
16
  `);
12
17
 
13
- const NEWLINE = jsxText('\n');
14
- const INDENT = jsxText(' ');
18
+ const createMenu = template(`
19
+ <ul data-name="menu" className="menu menu-hidden"></ul>
20
+ `);
15
21
 
16
22
  const DefaultMenu = {
17
23
  hello: noop,
@@ -19,9 +25,9 @@ const DefaultMenu = {
19
25
  };
20
26
 
21
27
  export const fix = ({path, menu, icon}) => {
22
- const items = [];
28
+ const {children} = path.parentPath.node;
23
29
 
24
- for (const key of keys(menu)) {
30
+ for (const [key, value] of entries(menu)) {
25
31
  const menuItem = createMenuItem();
26
32
 
27
33
  menuItem.children[0].children[0].value = key;
@@ -29,10 +35,24 @@ export const fix = ({path, menu, icon}) => {
29
35
  if (icon)
30
36
  setIcon(key, menuItem);
31
37
 
32
- items.push(menuItem);
38
+ children.push(menuItem);
39
+
40
+ if (isObject(value)) {
41
+ setSubmenu(menuItem);
42
+ menuItem.children.push(createMenu());
43
+
44
+ const openingElement = path.parentPath
45
+ .get('children')
46
+ .at(-1)
47
+ .get('children.1.openingElement');
48
+
49
+ fix({
50
+ path: openingElement,
51
+ icon,
52
+ menu: value,
53
+ });
54
+ }
33
55
  }
34
-
35
- path.parentPath.node.children = items;
36
56
  };
37
57
 
38
58
  export const traverse = ({options, push}) => ({
@@ -57,15 +77,15 @@ export const traverse = ({options, push}) => ({
57
77
  },
58
78
  });
59
79
 
60
- function checkDataName(path, dataName) {
61
- const {attributes} = path.node;
80
+ function setSubmenu(menuItem) {
81
+ const {attributes} = menuItem.openingElement;
62
82
 
63
- for (const {name, value} of attributes) {
64
- if (name.name === 'data-name')
65
- return value.value === dataName;
83
+ for (const attr of attributes) {
84
+ if (attr.name.name === 'className') {
85
+ setLiteralValue(attr.value, `${attr.value.value} menu-submenu`);
86
+ break;
87
+ }
66
88
  }
67
-
68
- return false;
69
89
  }
70
90
 
71
91
  function setIcon(name, menuItem) {
@@ -73,8 +93,8 @@ function setIcon(name, menuItem) {
73
93
 
74
94
  for (const attr of attributes) {
75
95
  if (attr.name.name === 'className') {
76
- attr.value.value += ` icon ${getIconName(name)}`;
77
- return;
96
+ setLiteralValue(attr.value, `${attr.value.value} icon ${getIconName(name)}`);
97
+ break;
78
98
  }
79
99
  }
80
100
  }
@@ -85,3 +105,4 @@ function getIconName(name) {
85
105
  .replace(/\s/g, '-')
86
106
  .toLowerCase();
87
107
  }
108
+
@@ -1,9 +1,7 @@
1
1
  export function checkDataName(path, dataName = 'menu') {
2
- const attributes = path.get('openingElement.attributes');
2
+ const {attributes} = path.node;
3
3
 
4
- for (const attr of attributes) {
5
- const {name, value} = attr.node;
6
-
4
+ for (const {name, value} of attributes) {
7
5
  if (name.name === 'data-name')
8
6
  return value.value === dataName;
9
7
  }
@@ -26,7 +26,9 @@ export const traverse = ({push, options}) => ({
26
26
  const {name, command} = options;
27
27
  const attributes = path.get('attributes');
28
28
 
29
- if (!checkDataName(path.parentPath, name))
29
+ const opengineElementPath = path.parentPath.get('openingElement');
30
+
31
+ if (!checkDataName(opengineElementPath, name))
30
32
  return false;
31
33
 
32
34
  for (const attr of attributes) {
@@ -24,7 +24,9 @@ export const traverse = ({options, push}) => ({
24
24
  if (!isJSXElement(path.parentPath.parentPath))
25
25
  return;
26
26
 
27
- if (!checkDataName(path.parentPath.parentPath, name))
27
+ const openingElementPath = path.parentPath.parentPath.get('openingElement');
28
+
29
+ if (!checkDataName(openingElementPath, name))
28
30
  return;
29
31
 
30
32
  const children = path.parentPath
@@ -32,7 +32,9 @@ export const traverse = ({options, push}) => ({
32
32
  const {name = 'menu', position = {}} = options;
33
33
  const {x = 0, y = 20} = position;
34
34
 
35
- if (!checkDataName(path.parentPath, name))
35
+ const openingElementPath = path.parentPath.get('openingElement');
36
+
37
+ if (!checkDataName(openingElementPath, name))
36
38
  return;
37
39
 
38
40
  for (const attr of path.node.attributes) {
@@ -26,7 +26,9 @@ export const traverse = ({push, options}) => ({
26
26
  if (!isJSXElement(path.parentPath.parentPath))
27
27
  return;
28
28
 
29
- if (!checkDataName(path.parentPath.parentPath, name))
29
+ const openingElementPath = path.parentPath.parentPath.get('openingElement');
30
+
31
+ if (!checkDataName(openingElementPath, name))
30
32
  return;
31
33
 
32
34
  const children = path.parentPath
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aleman",
3
- "version": "1.1.36",
3
+ "version": "1.1.38",
4
4
  "type": "module",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊Putout-based framework for web",