aleman 1.4.4 → 1.4.6

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,14 @@
1
+ 2025.09.09, v1.4.6
2
+
3
+ feature:
4
+ - 14b0011 aleman: menu: jsx-operator: getAttributeNode
5
+
6
+ 2025.09.09, v1.4.5
7
+
8
+ feature:
9
+ - 3adffdf aleman: menu: use getAttributePath from operator
10
+ - 92d48da jsx-operator: simplify
11
+
1
12
  2025.09.08, v1.4.4
2
13
 
3
14
  feature:
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.6.0',
3
+ 'putout': 'https://esm.sh/@putout/bundle@4.6.3',
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',
@@ -16,7 +16,7 @@ export const fix = (path) => {
16
16
 
17
17
  export const traverse = ({push, options}) => ({
18
18
  JSXElement(path) {
19
- const {name, showSubmenu} = options;
19
+ const {name = 'menu', showSubmenu} = options;
20
20
  const {parentPath} = path;
21
21
 
22
22
  if (showSubmenu)
@@ -1,8 +1,9 @@
1
- import {operator, types} from 'putout';
1
+ import {operator} from 'putout';
2
2
 
3
- const {isJSXElement} = types;
4
-
5
- const {setLiteralValue} = operator;
3
+ const {
4
+ setLiteralValue,
5
+ getAttributeNode,
6
+ } = operator;
6
7
 
7
8
  export function getAttributeValue(path, attributeName) {
8
9
  const attribute = getAttributeNode(path, attributeName);
@@ -13,39 +14,6 @@ export function getAttributeValue(path, attributeName) {
13
14
  return attribute.value.value;
14
15
  }
15
16
 
16
- export function getAttributeNode(path, name) {
17
- let result = null;
18
-
19
- const node = path.node || path;
20
- const {attributes} = node.openingElement;
21
-
22
- for (const attr of attributes) {
23
- if (attr.name.name === name) {
24
- result = attr;
25
- break;
26
- }
27
- }
28
-
29
- return result;
30
- }
31
-
32
- export function getAttributePath(path, name) {
33
- if (isJSXElement(path))
34
- path = path.get('openingElement');
35
-
36
- let result = null;
37
- const attributes = path.get('attributes');
38
-
39
- for (const attr of attributes) {
40
- if (attr.node.name.name === name) {
41
- result = attr;
42
- break;
43
- }
44
- }
45
-
46
- return result;
47
- }
48
-
49
17
  export function addAttributeValue(path, name, value) {
50
18
  const node = path.node || path;
51
19
  const attributeNode = getAttributeNode(node, name);
@@ -69,12 +37,16 @@ export function addClassName(path, name) {
69
37
  addAttributeValue(path, 'className', name);
70
38
  }
71
39
 
40
+ export function getClassName(path) {
41
+ return getAttributeValue(path, 'className');
42
+ }
43
+
72
44
  export function removeClassName(path, name) {
73
45
  removeAttributeValue(path, 'className', name);
74
46
  }
75
47
 
76
48
  export function containsClassName(path, className) {
77
- const classNameValue = getAttributeValue(path, 'className');
49
+ const classNameValue = getClassName(path);
78
50
  return classNameValue.includes(className);
79
51
  }
80
52
 
@@ -91,7 +63,8 @@ export function removeAttributeValue(path, name, attributeValue) {
91
63
  setLiteralValue(classAttribute.value, value.replace(RegExp(`\\s?${attributeValue}`), ''));
92
64
  }
93
65
 
94
- export function hasDataName(path, value = 'menu') {
66
+ export function hasDataName(path, value = '') {
95
67
  const attribute = getAttributeValue(path, 'data-name');
96
68
  return attribute === value;
97
69
  }
70
+
@@ -1,26 +1,22 @@
1
1
  import {operator, types} from 'putout';
2
2
  import {
3
- addAttributeValue,
4
- getAttributePath,
3
+ addClassName,
5
4
  hasDataName,
6
- removeAttributeValue,
5
+ removeClassName,
7
6
  } from '../jsx-operator.js';
8
7
 
8
+ const {hasTagName} = operator;
9
9
  const {isJSXElement} = types;
10
- const {setLiteralValue} = operator;
10
+ const SELECTED = 'menu-item-selected';
11
+ const SHOW = 'menu-submenu-show';
11
12
 
12
13
  export const report = () => `Select item`;
13
14
 
14
- export const fix = ({path, current, prev, next, showSubmenu}) => {
15
- const {value} = path.node;
16
-
17
- if (!value.value.includes('menu-item-selected'))
18
- setLiteralValue(value, `${value.value} menu-item-selected`);
19
-
20
- addShowSubmenu(current, {
15
+ export const fix = ({path, prev, next, showSubmenu}) => {
16
+ addClassName(path, SELECTED);
17
+ addShowSubmenu(path, {
21
18
  showSubmenu,
22
19
  });
23
-
24
20
  unselect(prev);
25
21
  unselect(next);
26
22
  removeShowSubmenu(next);
@@ -28,25 +24,25 @@ export const fix = ({path, current, prev, next, showSubmenu}) => {
28
24
  };
29
25
 
30
26
  export const traverse = ({options, push}) => ({
31
- JSXOpeningElement(path) {
27
+ JSXElement(path) {
32
28
  const {
33
29
  name = 'menu',
34
30
  index = 1,
35
31
  showSubmenu,
36
32
  } = options;
37
33
 
38
- if (path.node.name.name !== 'li')
34
+ if (!hasTagName(path, 'li'))
39
35
  return;
40
36
 
41
- const parentParentPath = path.parentPath.parentPath;
37
+ const {parentPath} = path;
42
38
 
43
- if (!isJSXElement(parentParentPath))
39
+ if (!isJSXElement(parentPath))
44
40
  return;
45
41
 
46
- if (!hasDataName(parentParentPath, name))
42
+ if (!hasDataName(parentPath, name))
47
43
  return;
48
44
 
49
- const children = parentParentPath.get('children').filter(isJSXElement);
45
+ const children = parentPath.get('children').filter(isJSXElement);
50
46
 
51
47
  const prev = children[index - 1];
52
48
  const current = children[index];
@@ -55,11 +51,8 @@ export const traverse = ({options, push}) => ({
55
51
  if (!current)
56
52
  return;
57
53
 
58
- const attributePath = getAttributePath(current, 'className');
59
-
60
54
  push({
61
- path: attributePath,
62
- current,
55
+ path: current,
63
56
  prev,
64
57
  next,
65
58
  showSubmenu,
@@ -68,14 +61,14 @@ export const traverse = ({options, push}) => ({
68
61
  });
69
62
 
70
63
  function unselect(path) {
71
- removeAttributeValue(path, 'className', 'menu-item-selected');
64
+ removeClassName(path, SELECTED);
72
65
  }
73
66
 
74
67
  function addShowSubmenu(path, {showSubmenu}) {
75
68
  if (showSubmenu)
76
- return addAttributeValue(path, 'className', 'menu-submenu-show');
69
+ return addClassName(path, SHOW);
77
70
  }
78
71
 
79
72
  function removeShowSubmenu(path) {
80
- removeAttributeValue(path, 'className', 'menu-submenu-show');
73
+ removeClassName(path, SHOW);
81
74
  }
@@ -1,11 +1,12 @@
1
- import {types} from 'putout';
1
+ import {types, operator} from 'putout';
2
2
  import {
3
- getAttributePath,
4
3
  getAttributeValue,
5
4
  hasDataName,
6
5
  setAttributeValue,
7
6
  } from '../jsx-operator.js';
8
7
 
8
+ const {getAttributePath} = operator;
9
+
9
10
  const {
10
11
  stringLiteral,
11
12
  jsxIdentifier,
@@ -1,6 +1,5 @@
1
1
  import {operator, types} from 'putout';
2
2
  import {
3
- addAttributeValue,
4
3
  addClassName,
5
4
  getAttributeValue,
6
5
  hasDataName,
@@ -43,7 +42,7 @@ export const traverse = ({options, push}) => ({
43
42
  if (!isParentSelected(path.parentPath.parentPath))
44
43
  return;
45
44
 
46
- if (!hasDataName(path.parentPath))
45
+ if (!hasDataName(path.parentPath, 'menu'))
47
46
  return;
48
47
 
49
48
  const children = path.parentPath
@@ -1,26 +1,23 @@
1
1
  import {operator, types} from 'putout';
2
2
  import {
3
- getAttributeValue,
3
+ containsClassName,
4
4
  hasDataName,
5
5
  removeClassName,
6
6
  } from '../jsx-operator.js';
7
7
 
8
- const {
9
- hasTagName,
10
- setLiteralValue,
11
- } = operator;
12
-
8
+ const {hasTagName} = operator;
13
9
  const {isJSXElement} = types;
10
+ const SELECTED = 'menu-item-selected';
14
11
 
15
12
  export const report = () => `Unselect all`;
16
13
 
17
14
  export const fix = ({path}) => {
18
- removeClassName(path, 'menu-item-selected');
15
+ removeClassName(path, SELECTED);
19
16
  };
20
17
 
21
18
  export const traverse = ({push, options}) => ({
22
19
  JSXElement(path) {
23
- const {index, name} = options;
20
+ const {index, name = 'menu'} = options;
24
21
 
25
22
  if (index !== -1)
26
23
  return;
@@ -39,13 +36,10 @@ export const traverse = ({push, options}) => ({
39
36
  .filter(isJSXElement);
40
37
 
41
38
  for (const child of children) {
42
- const classNameValue = getAttributeValue(child, 'className');
43
-
44
- if (classNameValue.includes('menu-item-selected'))
39
+ if (containsClassName(child, SELECTED))
45
40
  push({
46
41
  path: child,
47
42
  });
48
43
  }
49
44
  },
50
45
  });
51
-
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aleman",
3
- "version": "1.4.4",
3
+ "version": "1.4.6",
4
4
  "type": "module",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊Putout-based framework for web",