aleman 1.3.2 → 1.4.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 CHANGED
@@ -1,3 +1,9 @@
1
+ 2025.09.04, v1.4.0
2
+
3
+ feature:
4
+ - 2749907 aleman: menu: select: jsx-operator
5
+ - 43294ec aleman: menu: jsx-operator
6
+
1
7
  2025.09.04, v1.3.2
2
8
 
3
9
  feature:
@@ -41,11 +41,17 @@ export function getAttributePath(path, name) {
41
41
  return result;
42
42
  }
43
43
 
44
- export function appendAttributeValue(node, name, value) {
44
+ export function appendAttributeValue(path, name, value) {
45
+ const node = path.node || path;
45
46
  const attributeNode = getAttributeNode(node, name);
46
47
 
47
- if (attributeNode)
48
- setLiteralValue(attributeNode.value, `${attributeNode.value.value} ${value}`);
48
+ if (!attributeNode)
49
+ return;
50
+
51
+ if (attributeNode.value.value.includes(value))
52
+ return;
53
+
54
+ setLiteralValue(attributeNode.value, `${attributeNode.value.value} ${value}`);
49
55
  }
50
56
 
51
57
  export function setAttributeValue(node, name, value) {
@@ -54,3 +60,19 @@ export function setAttributeValue(node, name, value) {
54
60
  if (attributeNode)
55
61
  setLiteralValue(attributeNode.value, value);
56
62
  }
63
+
64
+ export function removeAttributeValue(path, name, attributeValue) {
65
+ if (!path)
66
+ return;
67
+
68
+ const node = path.node || path;
69
+ const classAttribute = getAttributeNode(node, name);
70
+
71
+ if (!classAttribute)
72
+ return;
73
+
74
+ const {value} = classAttribute.value;
75
+
76
+ if (value.includes(attributeValue))
77
+ setLiteralValue(classAttribute.value, value.replace(RegExp(`\\s?${attributeValue}`), ''));
78
+ }
@@ -1,5 +1,10 @@
1
1
  import {operator, types} from 'putout';
2
2
  import {checkDataName} from '../check-data-name.js';
3
+ import {
4
+ appendAttributeValue,
5
+ getAttributePath,
6
+ removeAttributeValue,
7
+ } from '../jsx-operator.js';
3
8
 
4
9
  const {isJSXElement} = types;
5
10
  const {setLiteralValue} = operator;
@@ -53,75 +58,30 @@ export const traverse = ({options, push}) => ({
53
58
  if (!current)
54
59
  return;
55
60
 
56
- for (const attr of current.get('openingElement.attributes')) {
57
- const {name} = attr.node;
58
-
59
- if (name.name !== 'className')
60
- continue;
61
-
62
- push({
63
- path: attr,
64
- current,
65
- prev,
66
- next,
67
- showSubmenu,
68
- });
69
- break;
70
- }
61
+ const currentOpeningElement = current.get('openingElement');
62
+ const attributePath = getAttributePath(currentOpeningElement, 'className');
63
+
64
+ push({
65
+ path: attributePath,
66
+ current,
67
+ prev,
68
+ next,
69
+ showSubmenu,
70
+ });
71
71
  },
72
72
  });
73
73
 
74
74
  function unselect(path) {
75
- if (!path)
76
- return;
77
-
78
- for (const attr of path.get('openingElement.attributes')) {
79
- const {name, value} = attr.node;
80
-
81
- if (name.name !== 'className')
82
- continue;
83
-
84
- if (value.value.includes('menu-item-selected'))
85
- setLiteralValue(value, value.value.replace(' menu-item-selected', ''));
86
- }
75
+ removeAttributeValue(path, 'className', 'menu-item-selected');
87
76
  }
88
77
 
89
78
  function addShowSubmenu(path, {showSubmenu}) {
90
- for (const attr of path.get('openingElement.attributes')) {
91
- const {name, value} = attr.node;
92
-
93
- if (name.name !== 'className')
94
- continue;
95
-
96
- const currentValue = value.value;
97
-
98
- if (showSubmenu && !currentValue.includes('menu-submenu-show')) {
99
- setLiteralValue(value, `${currentValue} menu-submenu-show`);
100
- break;
101
- }
102
-
103
- if (!showSubmenu && currentValue.includes('menu-submenu-show')) {
104
- setLiteralValue(value, currentValue.replace('menu-submenu-show', ''));
105
- break;
106
- }
107
- }
79
+ if (showSubmenu)
80
+ return appendAttributeValue(path, 'className', 'menu-submenu-show');
81
+
82
+ removeAttributeValue(path, 'className', 'menu-submenu-show');
108
83
  }
109
84
 
110
85
  function removeShowSubmenu(path) {
111
- if (!path)
112
- return;
113
-
114
- for (const attr of path.get('openingElement.attributes')) {
115
- const {name, value} = attr.node;
116
-
117
- if (name.name !== 'className')
118
- continue;
119
-
120
- const currentValue = value.value;
121
-
122
- if (currentValue.includes('menu-submenu-show')) {
123
- setLiteralValue(value, currentValue.replace(' menu-submenu-show', ''));
124
- break;
125
- }
126
- }
86
+ removeAttributeValue(path, 'className', 'menu-submenu-show');
127
87
  }
@@ -0,0 +1,3 @@
1
+ <li data-menu-path="Upload" data-name="menu-item" className="menu-item icon icon-view">
2
+ <label data-menu-path="Upload">Upload</label>
3
+ </li>
@@ -0,0 +1,17 @@
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="world" 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>;
@@ -1,5 +1,10 @@
1
1
  import {operator, types} from 'putout';
2
2
  import {checkDataName} from '../check-data-name.js';
3
+ import {
4
+ getAttributePath,
5
+ getAttributeValue,
6
+ removeAttributeValue,
7
+ } from '../jsx-operator.js';
3
8
 
4
9
  const {isJSXElement} = types;
5
10
  const {setLiteralValue} = operator;
@@ -29,6 +34,9 @@ export const traverse = ({options, push}) => ({
29
34
  if (path.node.name.name !== 'li')
30
35
  return;
31
36
 
37
+ if (!isJSXElement(path.parentPath.parentPath))
38
+ return;
39
+
32
40
  const {insideSubmenu = true, submenuIndex = 1} = options;
33
41
  const parentMenu = path.parentPath.parentPath.parentPath;
34
42
 
@@ -38,9 +46,6 @@ export const traverse = ({options, push}) => ({
38
46
  if (!isParentSelected(parentMenu))
39
47
  return;
40
48
 
41
- if (!isJSXElement(path.parentPath.parentPath))
42
- return;
43
-
44
49
  const openingElementPath = path.parentPath.parentPath.get('openingElement');
45
50
 
46
51
  if (!checkDataName(openingElementPath))
@@ -58,7 +63,8 @@ export const traverse = ({options, push}) => ({
58
63
  if (!current)
59
64
  return;
60
65
 
61
- const [currentClassPath] = getClassPath(current);
66
+ const currentOpeningElementPath = current.get('openingElement');
67
+ const currentClassPath = getAttributePath(currentOpeningElementPath, 'className');
62
68
 
63
69
  push({
64
70
  path: currentClassPath,
@@ -70,46 +76,15 @@ export const traverse = ({options, push}) => ({
70
76
  });
71
77
 
72
78
  function isParentSelected(path) {
73
- const attributes = path.get('openingElement.attributes');
79
+ const openingElement = path.get('openingElement');
80
+ const classAttributeValue = getAttributeValue(openingElement, 'className');
74
81
 
75
- for (const attr of attributes) {
76
- const {name, value} = attr.node;
77
-
78
- if (name.name === 'className')
79
- return value.value.includes('menu-item-selected');
80
- }
81
-
82
- return false;
82
+ return classAttributeValue.includes('menu-item-selected');
83
83
  }
84
84
 
85
85
  function unselect(path) {
86
86
  if (!path)
87
87
  return;
88
88
 
89
- for (const attr of path.get('openingElement.attributes')) {
90
- const {name, value} = attr.node;
91
-
92
- if (name.name !== 'className')
93
- continue;
94
-
95
- if (value.value.includes('menu-item-selected'))
96
- setLiteralValue(value, value.value.replace(' menu-item-selected', ''));
97
- }
98
- }
99
-
100
- function getClassPath(path) {
101
- if (!path)
102
- return [null, ''];
103
-
104
- for (const attr of path.get('openingElement.attributes')) {
105
- const {name, value} = attr.node;
106
-
107
- if (name.name !== 'className')
108
- continue;
109
-
110
- return [
111
- attr,
112
- value.value,
113
- ];
114
- }
89
+ removeAttributeValue(path, 'className', 'menu-item-selected');
115
90
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aleman",
3
- "version": "1.3.2",
3
+ "version": "1.4.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",