aleman 1.4.1 → 1.4.3

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.07, v1.4.3
2
+
3
+ feature:
4
+ - c023f11 aleman: menu: hasTagName
5
+
6
+ 2025.09.07, v1.4.2
7
+
8
+ feature:
9
+ - 1a1899e aleman: menu: item-click: no data-menu find on element
10
+
1
11
  2025.09.06, v1.4.1
2
12
 
3
13
  feature:
@@ -7,9 +7,8 @@ export const createItemClick = (name) => ({
7
7
  });
8
8
 
9
9
  const listener = ({event, options}) => {
10
- const menuItemElement = document.elementFromPoint(event.clientX, event.clientY);
11
- const {menuPath} = menuItemElement.dataset;
12
10
  const {menu} = options;
11
+ const menuPath = getMenuPath(event);
13
12
  const fn = jessy(menuPath, menu);
14
13
 
15
14
  setTimeout(fn);
@@ -21,3 +20,14 @@ const listener = ({event, options}) => {
21
20
  showSubmenu: false,
22
21
  };
23
22
  };
23
+
24
+ function getMenuPath(event) {
25
+ let menuItemElement = document.elementFromPoint(event.clientX, event.clientY);
26
+ const {menuPath} = menuItemElement.dataset;
27
+
28
+ if (!menuPath)
29
+ menuItemElement = menuItemElement.querySelector('[data-menu-path]');
30
+
31
+ return menuItemElement.dataset.menuPath;
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't add .,
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,7 +1,7 @@
1
1
  import {template} from 'putout';
2
- import {checkDataName} from '../check-data-name.js';
3
2
  import {
4
3
  appendAttributeValue,
4
+ hasDataName,
5
5
  setAttributeValue,
6
6
  } from '../jsx-operator.js';
7
7
 
@@ -68,7 +68,7 @@ export const traverse = ({options, push}) => ({
68
68
  icon = false,
69
69
  } = options;
70
70
 
71
- if (!checkDataName(path, name))
71
+ if (!hasDataName(path, name))
72
72
  return;
73
73
 
74
74
  if (path.node.children.length)
@@ -0,0 +1,16 @@
1
+ <ul data-name="hello" className="menu menu-hidden">
2
+ <li data-menu-path="Upload" data-name="menu-item" className="menu-item icon icon-view">
3
+ <label data-menu-path="Upload">Upload</label>
4
+ </li>
5
+ <li data-menu-path="New" data-name="menu-item" className="menu-item icon icon-edit menu-item-selected menu-submenu-show">
6
+ <label data-menu-path="New">New</label>
7
+ <ul data-name="menu" className="menu menu-hidden">
8
+ <li data-menu-path="New.File" data-name="menu-item" className="menu-item icon icon-view">
9
+ <label data-menu-path="New.File">File</label>
10
+ </li>
11
+ <li data-menu-path="New.Directory" data-name="menu-item" className="menu-item icon icon-edit">
12
+ <label data-menu-path="New.Directory">Directory</label>
13
+ </li>
14
+ </ul>
15
+ </li>
16
+ </ul>;
@@ -1,16 +1,17 @@
1
- import {checkDataName} from '../check-data-name.js';
1
+ import {operator} from 'putout';
2
2
  import {
3
- checkTagName,
4
- containsClass,
5
- removeClass,
3
+ containsClassName,
4
+ removeClassName,
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`;
11
12
 
12
13
  export const fix = (path) => {
13
- removeClass(path, CLASS);
14
+ removeClassName(path, CLASS);
14
15
  };
15
16
 
16
17
  export const traverse = ({push, options}) => ({
@@ -21,13 +22,14 @@ export const traverse = ({push, options}) => ({
21
22
  if (showSubmenu)
22
23
  return;
23
24
 
24
- if (!checkTagName(path, 'li'))
25
+ if (!hasTagName(path, 'li'))
25
26
  return;
26
27
 
27
- if (!checkDataName(parentPath, name))
28
+ if (!hasDataName(parentPath, name))
28
29
  return false;
29
30
 
30
- if (containsClass(path, CLASS))
31
+ if (containsClassName(path, CLASS))
31
32
  push(path);
32
33
  },
33
34
  });
35
+
@@ -52,9 +52,6 @@ export function appendAttributeValue(path, name, value) {
52
52
  const node = path.node || path;
53
53
  const attributeNode = getAttributeNode(node, name);
54
54
 
55
- if (!attributeNode)
56
- return;
57
-
58
55
  if (attributeNode.value.value.includes(value))
59
56
  return;
60
57
 
@@ -62,9 +59,6 @@ export function appendAttributeValue(path, name, value) {
62
59
  }
63
60
 
64
61
  export function setAttributeValue(node, name, value) {
65
- if (!node)
66
- return;
67
-
68
62
  node = node.node || node;
69
63
 
70
64
  const attributeNode = getAttributeNode(node, name);
@@ -73,33 +67,34 @@ export function setAttributeValue(node, name, value) {
73
67
  setLiteralValue(attributeNode.value, value);
74
68
  }
75
69
 
76
- export function addClass(path, name) {
70
+ export function addClassName(path, name) {
77
71
  appendAttributeValue(path, 'className', name);
78
72
  }
79
73
 
80
- export function removeClass(path, name) {
74
+ export function removeClassName(path, name) {
81
75
  removeAttributeValue(path, 'className', name);
82
76
  }
83
77
 
84
- export function containsClass(path, className) {
78
+ export function containsClassName(path, className) {
85
79
  const classNameValue = getAttributeValue(path, 'className');
86
80
  return classNameValue.includes(className);
87
81
  }
88
82
 
89
- export const checkTagName = (path, name) => path.node.openingElement.name.name === name;
90
-
91
83
  export function removeAttributeValue(path, name, attributeValue) {
92
84
  if (!path)
93
85
  return;
94
86
 
95
- const node = path.node || path;
87
+ const {node} = path;
96
88
  const classAttribute = getAttributeNode(node, name);
97
89
 
98
- if (!classAttribute)
99
- return;
100
-
101
90
  const {value} = classAttribute.value;
102
91
 
103
92
  if (value.includes(attributeValue))
104
93
  setLiteralValue(classAttribute.value, value.replace(RegExp(`\\s?${attributeValue}`), ''));
105
94
  }
95
+
96
+ export function hasDataName(path, value = 'menu') {
97
+ const attribute = getAttributeValue(path, 'data-name');
98
+
99
+ return attribute === value;
100
+ }
@@ -1,8 +1,8 @@
1
- import {checkDataName} from '../check-data-name.js';
2
1
  import {
3
- addClass,
4
- containsClass,
5
- removeClass,
2
+ addClassName,
3
+ containsClassName,
4
+ hasDataName,
5
+ removeClassName,
6
6
  } from '../jsx-operator.js';
7
7
 
8
8
  export const report = ({command}) => {
@@ -13,21 +13,21 @@ export const report = ({command}) => {
13
13
 
14
14
  export const fix = ({path, command}) => {
15
15
  if (command === 'show') {
16
- removeClass(path, 'menu-hidden');
16
+ removeClassName(path, 'menu-hidden');
17
17
  return;
18
18
  }
19
19
 
20
- addClass(path, 'menu-hidden');
20
+ addClassName(path, 'menu-hidden');
21
21
  };
22
22
 
23
23
  export const traverse = ({push, options}) => ({
24
24
  JSXElement(path) {
25
25
  const {name, command} = options;
26
26
 
27
- if (!checkDataName(path, name))
27
+ if (!hasDataName(path, name))
28
28
  return false;
29
29
 
30
- const shown = !containsClass(path, 'menu-hidden');
30
+ const shown = !containsClassName(path, 'menu-hidden');
31
31
 
32
32
  if (command === 'show' && !shown || command === 'hide' && shown)
33
33
  push({
@@ -1,8 +1,8 @@
1
1
  import {operator, types} from 'putout';
2
- import {checkDataName} from '../check-data-name.js';
3
2
  import {
4
3
  appendAttributeValue,
5
4
  getAttributePath,
5
+ hasDataName,
6
6
  removeAttributeValue,
7
7
  } from '../jsx-operator.js';
8
8
 
@@ -43,7 +43,7 @@ export const traverse = ({options, push}) => ({
43
43
  if (!isJSXElement(parentParentPath))
44
44
  return;
45
45
 
46
- if (!checkDataName(parentParentPath, name))
46
+ if (!hasDataName(parentParentPath, name))
47
47
  return;
48
48
 
49
49
  const children = parentParentPath.get('children').filter(isJSXElement);
@@ -1,8 +1,8 @@
1
1
  import {types} from 'putout';
2
- import {checkDataName} from '../check-data-name.js';
3
2
  import {
4
3
  getAttributePath,
5
4
  getAttributeValue,
5
+ hasDataName,
6
6
  setAttributeValue,
7
7
  } from '../jsx-operator.js';
8
8
 
@@ -33,7 +33,7 @@ export const traverse = ({options, push}) => ({
33
33
  const {name = 'menu', position = {}} = options;
34
34
  const {x = 0, y = 20} = position;
35
35
 
36
- if (!checkDataName(path, name))
36
+ if (!hasDataName(path, name))
37
37
  return;
38
38
 
39
39
  const styleAttributeValue = getAttributeValue(path, 'style');
@@ -1,8 +1,8 @@
1
1
  import {operator, types} from 'putout';
2
- import {checkDataName} from '../check-data-name.js';
3
2
  import {
4
3
  getAttributePath,
5
4
  getAttributeValue,
5
+ hasDataName,
6
6
  removeAttributeValue,
7
7
  } from '../jsx-operator.js';
8
8
 
@@ -48,7 +48,7 @@ export const traverse = ({options, push}) => ({
48
48
 
49
49
  const openingElementPath = path.parentPath.parentPath.get('openingElement');
50
50
 
51
- if (!checkDataName(openingElementPath))
51
+ if (!hasDataName(openingElementPath))
52
52
  return;
53
53
 
54
54
  const children = path.parentPath
@@ -1,5 +1,5 @@
1
1
  import {operator, types} from 'putout';
2
- import {checkDataName} from '../check-data-name.js';
2
+ import {hasDataName} from '../jsx-operator.js';
3
3
 
4
4
  const {isJSXElement} = types;
5
5
  const {setLiteralValue} = operator;
@@ -28,7 +28,7 @@ export const traverse = ({push, options}) => ({
28
28
 
29
29
  const openingElementPath = path.parentPath.parentPath.get('openingElement');
30
30
 
31
- if (!checkDataName(openingElementPath, name))
31
+ if (!hasDataName(openingElementPath, name))
32
32
  return;
33
33
 
34
34
  const children = path.parentPath
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aleman",
3
- "version": "1.4.1",
3
+ "version": "1.4.3",
4
4
  "type": "module",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊Putout-based framework for web",
@@ -1,7 +0,0 @@
1
- import {getAttributeValue} from './jsx-operator.js';
2
-
3
- export function checkDataName(path, value = 'menu') {
4
- const attribute = getAttributeValue(path, 'data-name');
5
-
6
- return attribute === value;
7
- }