aleman 1.4.2 → 1.4.4

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 CHANGED
@@ -1,3 +1,13 @@
1
+ 2025.09.08, v1.4.4
2
+
3
+ feature:
4
+ - c69b6da aleman: menu: simplify
5
+
6
+ 2025.09.07, v1.4.3
7
+
8
+ feature:
9
+ - c023f11 aleman: menu: hasTagName
10
+
1
11
  2025.09.07, v1.4.2
2
12
 
3
13
  feature:
@@ -30,4 +30,3 @@ function getMenuPath(event) {
30
30
 
31
31
  return menuItemElement.dataset.menuPath;
32
32
  }
33
-
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.5.3',
3
+ 'putout': 'https://esm.sh/@putout/bundle@4.6.0',
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',
@@ -1,6 +1,6 @@
1
1
  import {template} from 'putout';
2
2
  import {
3
- appendAttributeValue,
3
+ addAttributeValue,
4
4
  hasDataName,
5
5
  setAttributeValue,
6
6
  } from '../jsx-operator.js';
@@ -45,9 +45,7 @@ export const fix = ({path, menu, icon, name = ''}) => {
45
45
  setSubmenu(menuItem);
46
46
  menuItem.children.push(createMenu());
47
47
 
48
- const elementPath = path
49
- .get('children')
50
- .at(-1)
48
+ const elementPath = path.get('children').at(-1)
51
49
  .get('children.1');
52
50
 
53
51
  fix({
@@ -83,7 +81,7 @@ export const traverse = ({options, push}) => ({
83
81
  });
84
82
 
85
83
  function setSubmenu(menuItem) {
86
- appendAttributeValue(menuItem, 'className', 'menu-submenu');
84
+ addAttributeValue(menuItem, 'className', 'menu-submenu');
87
85
  }
88
86
 
89
87
  function setDataMenuPath(key, name, menuItem) {
@@ -92,7 +90,7 @@ function setDataMenuPath(key, name, menuItem) {
92
90
  }
93
91
 
94
92
  function setIcon(name, menuItem) {
95
- appendAttributeValue(menuItem, 'className', `icon ${getIconName(name)}`);
93
+ addAttributeValue(menuItem, 'className', `icon ${getIconName(name)}`);
96
94
  }
97
95
 
98
96
  function getIconName(name) {
@@ -0,0 +1,18 @@
1
+ // second selected
2
+ <ul data-name="menu" className="menu menu-hidden">
3
+ <li data-menu-path="Upload" data-name="menu-item" className="menu-item icon icon-view">
4
+ <label data-menu-path="Upload">Upload</label>
5
+ </li>
6
+ <li data-menu-path="New" data-name="menu-item" className="menu-item icon icon-edit menu-item-selected menu-submenu-show">
7
+ <label data-menu-path="New">New</label>
8
+ <ul data-name="menu" className="menu menu-hidden">
9
+ <li data-menu-path="New.File" data-name="menu-item" className="menu-item icon icon-view">
10
+ <label data-menu-path="New.File">File</label>
11
+ </li>
12
+ <li data-menu-path="New.Directory" data-name="menu-item" className="menu-item icon icon-edit">
13
+ <label data-menu-path="New.Directory">Directory</label>
14
+ </li>
15
+ </ul>
16
+ </li>
17
+ </ul>;
18
+
@@ -1,10 +1,11 @@
1
+ import {operator} from 'putout';
1
2
  import {
2
- hasTagName,
3
3
  containsClassName,
4
4
  removeClassName,
5
5
  hasDataName,
6
6
  } from '../jsx-operator.js';
7
7
 
8
+ const {hasTagName} = operator;
8
9
  const CLASS = 'menu-submenu-show';
9
10
 
10
11
  export const report = () => `Hide submenu`;
@@ -1,24 +1,22 @@
1
1
  import {operator, types} from 'putout';
2
2
 
3
3
  const {isJSXElement} = types;
4
+
4
5
  const {setLiteralValue} = operator;
5
6
 
6
7
  export function getAttributeValue(path, attributeName) {
7
- if (isJSXElement(path))
8
- path = path.get('openingElement');
8
+ const attribute = getAttributeNode(path, attributeName);
9
9
 
10
- const {attributes} = path.node;
11
-
12
- for (const {name, value} of attributes) {
13
- if (name.name === attributeName)
14
- return value.value;
15
- }
10
+ if (!attribute)
11
+ return '';
16
12
 
17
- return '';
13
+ return attribute.value.value;
18
14
  }
19
15
 
20
- export function getAttributeNode(node, name) {
16
+ export function getAttributeNode(path, name) {
21
17
  let result = null;
18
+
19
+ const node = path.node || path;
22
20
  const {attributes} = node.openingElement;
23
21
 
24
22
  for (const attr of attributes) {
@@ -48,7 +46,7 @@ export function getAttributePath(path, name) {
48
46
  return result;
49
47
  }
50
48
 
51
- export function appendAttributeValue(path, name, value) {
49
+ export function addAttributeValue(path, name, value) {
52
50
  const node = path.node || path;
53
51
  const attributeNode = getAttributeNode(node, name);
54
52
 
@@ -68,7 +66,7 @@ export function setAttributeValue(node, name, value) {
68
66
  }
69
67
 
70
68
  export function addClassName(path, name) {
71
- appendAttributeValue(path, 'className', name);
69
+ addAttributeValue(path, 'className', name);
72
70
  }
73
71
 
74
72
  export function removeClassName(path, name) {
@@ -80,8 +78,6 @@ export function containsClassName(path, className) {
80
78
  return classNameValue.includes(className);
81
79
  }
82
80
 
83
- export const hasTagName = (path, name) => path.node.openingElement.name.name === name;
84
-
85
81
  export function removeAttributeValue(path, name, attributeValue) {
86
82
  if (!path)
87
83
  return;
@@ -97,6 +93,5 @@ export function removeAttributeValue(path, name, attributeValue) {
97
93
 
98
94
  export function hasDataName(path, value = 'menu') {
99
95
  const attribute = getAttributeValue(path, 'data-name');
100
-
101
96
  return attribute === value;
102
97
  }
@@ -1,6 +1,6 @@
1
1
  import {operator, types} from 'putout';
2
2
  import {
3
- appendAttributeValue,
3
+ addAttributeValue,
4
4
  getAttributePath,
5
5
  hasDataName,
6
6
  removeAttributeValue,
@@ -73,7 +73,7 @@ function unselect(path) {
73
73
 
74
74
  function addShowSubmenu(path, {showSubmenu}) {
75
75
  if (showSubmenu)
76
- return appendAttributeValue(path, 'className', 'menu-submenu-show');
76
+ return addAttributeValue(path, 'className', 'menu-submenu-show');
77
77
  }
78
78
 
79
79
  function removeShowSubmenu(path) {
@@ -45,7 +45,7 @@
45
45
  <li data-menu-path="New.File" data-name="menu-item" className='menu-item icon icon-view'>
46
46
  <label data-menu-path="New.File">File</label>
47
47
  </li>
48
- <li data-menu-path="New.Directory" data-name="menu-item" className='menu-item icon icon-edit'>
48
+ <li data-menu-path="New.Directory" data-name="menu-item" className="menu-item icon icon-edit">
49
49
  <label data-menu-path="New.Directory">Directory</label>
50
50
  </li>
51
51
  </ul>
@@ -0,0 +1,54 @@
1
+ // second selected
2
+ <ul data-name="menu" class="menu menu-hidden">
3
+ <li data-menu-path="Upload" data-name="menu-item" className="menu-item icon icon-view">
4
+ <label data-menu-path="Upload">Upload</label>
5
+ </li>
6
+ <li data-menu-path="New" data-name="menu-item" className="menu-item icon icon-edit menu-item-selected">
7
+ <label data-menu-path="New">New</label>
8
+ <ul data-name="menu" class="menu menu-hidden">
9
+ <li data-menu-path="New.File" data-name="menu-item" className="menu-item icon icon-view">
10
+ <label data-menu-path="New.File">File</label>
11
+ </li>
12
+ <li data-menu-path="New.Directory" data-name="menu-item" className="menu-item icon icon-edit">
13
+ <label data-menu-path="New.Directory">Directory</label>
14
+ </li>
15
+ </ul>
16
+ </li>
17
+ </ul>;
18
+
19
+
20
+ // first selected
21
+ <ul data-name="menu" class="menu menu-hidden">
22
+ <li data-menu-path="Upload" data-name="menu-item" className="menu-item icon icon-view menu-item-selected">
23
+ <label data-menu-path="Upload">Upload</label>
24
+ </li>
25
+ <li data-menu-path="New" data-name="menu-item" className="menu-item icon icon-edit">
26
+ <label data-menu-path="New">New</label>
27
+ <ul data-name="menu" class="menu menu-hidden">
28
+ <li data-menu-path="New.File" data-name="menu-item" className="menu-item icon icon-view">
29
+ <label data-menu-path="New.File">File</label>
30
+ </li>
31
+ <li data-menu-path="New.Directory" data-name="menu-item" className="menu-item icon icon-edit">
32
+ <label data-menu-path="New.Directory">Directory</label>
33
+ </li>
34
+ </ul>
35
+ </li>
36
+ </ul>;
37
+
38
+ // second selected, submenu first selected
39
+ <ul data-name="menu" class="menu menu-hidden">
40
+ <li data-menu-path="Upload" data-name="menu-item" className="menu-item icon icon-view">
41
+ <label data-menu-path="Upload">Upload</label>
42
+ </li>
43
+ <li data-menu-path="New" data-name="menu-item" className="menu-item icon icon-edit menu-item-selected">
44
+ <label data-menu-path="New">New</label>
45
+ <ul data-name="menu" class="menu menu-hidden">
46
+ <li data-menu-path="New.File" data-name="menu-item" className="menu-item icon icon-view menu-item-selected">
47
+ <label data-menu-path="New.File">File</label>
48
+ </li>
49
+ <li data-menu-path="New.Directory" data-name="menu-item" className="menu-item icon icon-edit">
50
+ <label data-menu-path="New.Directory">Directory</label>
51
+ </li>
52
+ </ul>
53
+ </li>
54
+ </ul>;
@@ -1,40 +1,37 @@
1
1
  import {operator, types} from 'putout';
2
2
  import {
3
- getAttributePath,
3
+ addAttributeValue,
4
+ addClassName,
4
5
  getAttributeValue,
5
6
  hasDataName,
6
7
  removeAttributeValue,
8
+ removeClassName,
7
9
  } from '../jsx-operator.js';
8
10
 
11
+ const {hasTagName} = operator;
12
+
9
13
  const {isJSXElement} = types;
10
- const {setLiteralValue} = operator;
11
14
 
12
15
  export const report = ({insideSubmenu}) => `${insideSubmenu ? 'Show' : 'Hide'} submenu`;
13
16
 
14
17
  export const fix = ({path, prev, next, insideSubmenu}) => {
15
- const {value} = path.node;
16
18
  unselect(prev);
17
19
  unselect(next);
18
20
 
19
21
  if (!insideSubmenu) {
20
- const newValue = value.value.replace(/\s?menu-item-selected/, '');
21
- setLiteralValue(value, newValue);
22
-
22
+ removeClassName(path, 'menu-item-selected');
23
23
  return;
24
24
  }
25
25
 
26
- if (!value.value.includes('menu-item-selected')) {
27
- const newValue = `${value.value} menu-item-selected`;
28
- setLiteralValue(value, newValue);
29
- }
26
+ addClassName(path, 'menu-item-selected');
30
27
  };
31
28
 
32
29
  export const traverse = ({options, push}) => ({
33
- JSXOpeningElement(path) {
34
- if (path.node.name.name !== 'li')
30
+ JSXElement(path) {
31
+ if (!hasTagName(path, 'li'))
35
32
  return;
36
33
 
37
- if (!isJSXElement(path.parentPath.parentPath))
34
+ if (!isJSXElement(path.parentPath))
38
35
  return;
39
36
 
40
37
  const {insideSubmenu = true, submenuIndex = 1} = options;
@@ -43,16 +40,13 @@ export const traverse = ({options, push}) => ({
43
40
  if (!isJSXElement(parentMenu))
44
41
  return;
45
42
 
46
- if (!isParentSelected(parentMenu))
43
+ if (!isParentSelected(path.parentPath.parentPath))
47
44
  return;
48
45
 
49
- const openingElementPath = path.parentPath.parentPath.get('openingElement');
50
-
51
- if (!hasDataName(openingElementPath))
46
+ if (!hasDataName(path.parentPath))
52
47
  return;
53
48
 
54
49
  const children = path.parentPath
55
- .parentPath
56
50
  .get('children')
57
51
  .filter(isJSXElement);
58
52
 
@@ -63,11 +57,8 @@ export const traverse = ({options, push}) => ({
63
57
  if (!current)
64
58
  return;
65
59
 
66
- const currentOpeningElementPath = current.get('openingElement');
67
- const currentClassPath = getAttributePath(currentOpeningElementPath, 'className');
68
-
69
60
  push({
70
- path: currentClassPath,
61
+ path: current,
71
62
  insideSubmenu,
72
63
  prev,
73
64
  next,
@@ -76,9 +67,7 @@ export const traverse = ({options, push}) => ({
76
67
  });
77
68
 
78
69
  function isParentSelected(path) {
79
- const openingElement = path.get('openingElement');
80
- const classAttributeValue = getAttributeValue(openingElement, 'className');
81
-
70
+ const classAttributeValue = getAttributeValue(path, 'className');
82
71
  return classAttributeValue.includes('menu-item-selected');
83
72
  }
84
73
 
@@ -1,53 +1,51 @@
1
1
  import {operator, types} from 'putout';
2
- import {hasDataName} from '../jsx-operator.js';
2
+ import {
3
+ getAttributeValue,
4
+ hasDataName,
5
+ removeClassName,
6
+ } from '../jsx-operator.js';
7
+
8
+ const {
9
+ hasTagName,
10
+ setLiteralValue,
11
+ } = operator;
3
12
 
4
13
  const {isJSXElement} = types;
5
- const {setLiteralValue} = operator;
6
14
 
7
15
  export const report = () => `Unselect all`;
8
16
 
9
17
  export const fix = ({path}) => {
10
- const {value} = path.node;
11
- const newValue = value.value.replace(/\s?menu-item-selected/, '');
12
-
13
- setLiteralValue(value, newValue);
18
+ removeClassName(path, 'menu-item-selected');
14
19
  };
15
20
 
16
21
  export const traverse = ({push, options}) => ({
17
- JSXOpeningElement(path) {
22
+ JSXElement(path) {
18
23
  const {index, name} = options;
19
24
 
20
25
  if (index !== -1)
21
26
  return;
22
27
 
23
- if (path.node.name.name !== 'li')
28
+ if (!hasTagName(path, 'li'))
24
29
  return;
25
30
 
26
- if (!isJSXElement(path.parentPath.parentPath))
31
+ if (!isJSXElement(path.parentPath))
27
32
  return;
28
33
 
29
- const openingElementPath = path.parentPath.parentPath.get('openingElement');
30
-
31
- if (!hasDataName(openingElementPath, name))
34
+ if (!hasDataName(path.parentPath, name))
32
35
  return;
33
36
 
34
37
  const children = path.parentPath
35
- .parentPath
36
38
  .get('children')
37
39
  .filter(isJSXElement);
38
40
 
39
41
  for (const child of children) {
40
- for (const attr of child.get('openingElement.attributes')) {
41
- const {name, value} = attr.node;
42
-
43
- if (name.name !== 'className')
44
- continue;
45
-
46
- if (value.value.includes('menu-item-selected'))
47
- push({
48
- path: attr,
49
- });
50
- }
42
+ const classNameValue = getAttributeValue(child, 'className');
43
+
44
+ if (classNameValue.includes('menu-item-selected'))
45
+ push({
46
+ path: child,
47
+ });
51
48
  }
52
49
  },
53
50
  });
51
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aleman",
3
- "version": "1.4.2",
3
+ "version": "1.4.4",
4
4
  "type": "module",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊Putout-based framework for web",