aleman 1.3.0 → 1.3.2

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.04, v1.3.2
2
+
3
+ feature:
4
+ - a94f8d9 aleman: menu: jsx-operator: add
5
+ - 6a18625 aleman: menu: operator: add
6
+
7
+ 2025.09.04, v1.3.1
8
+
9
+ feature:
10
+ - 314e4f9 aleman: menu: hide-submenu
11
+
1
12
  2025.09.04, v1.3.0
2
13
 
3
14
  feature:
package/aleman/state.js CHANGED
@@ -39,6 +39,7 @@ export const createState = (state, {options, listener, stateName = 'aleman-state
39
39
 
40
40
  history[str] = true;
41
41
  stateElement.textContent = str;
42
+ window.alemanSync = fn;
42
43
 
43
44
  document.addEventListener('keydown', ({key}) => {
44
45
  if (key === '`')
package/menu/README.md CHANGED
@@ -8,6 +8,7 @@
8
8
  - ✅[`build-menu`](https://putout.cloudcmd.io/#/gist/329dccd5fdc7f8b220be79af405dc9bb/b56df53f52bbe2a300ede38a96d1d2242e60679f);
9
9
  - ✅[`set-position`](https://putout.cloudcmd.io/#/gist/215bb4654a27f15235f3e380a3035138/7f4af88aaa4863be4f1b8a90b9f0f4b1cf4744a0);
10
10
  - ✅[`submenu`](https://putout.cloudcmd.io/#/gist/b0a3b64d14f3497869a345e7e438d66e/feb671c4a59a555ff408af92fab602bae3a94e2f);
11
+ - ✅[`hide-submenu`](https://putout.cloudcmd.io/#/gist/fdf6cf60a7fdfa2bae64279eda2ab023/ce0d5e24dc5e0b3436b7e87585c62e8a5132a9ab);
11
12
 
12
13
  ## License
13
14
 
@@ -9,5 +9,6 @@ export const listener = ({options, state}) => {
9
9
  command: 'hide',
10
10
  index: -1,
11
11
  showSubmenu: false,
12
+ insideSubmenu: false,
12
13
  };
13
14
  };
@@ -3,5 +3,8 @@ export const createMouseEnter = (name) => ({
3
3
  events: ['mouseenter'],
4
4
  listener: () => ({
5
5
  index: -1,
6
+ showSubmenu: false,
7
+ insideSubmenu: false,
8
+ submenuIndex: 0,
6
9
  }),
7
10
  });
@@ -1,7 +1,10 @@
1
- import {template, operator} from 'putout';
1
+ import {template} from 'putout';
2
2
  import {checkDataName} from '../check-data-name.js';
3
+ import {
4
+ appendAttributeValue,
5
+ setAttributeValue,
6
+ } from '../jsx-operator.js';
3
7
 
4
- const {setLiteralValue} = operator;
5
8
  const {entries} = Object;
6
9
 
7
10
  const noop = () => {};
@@ -80,37 +83,16 @@ export const traverse = ({options, push}) => ({
80
83
  });
81
84
 
82
85
  function setSubmenu(menuItem) {
83
- const {attributes} = menuItem.openingElement;
84
-
85
- for (const attr of attributes) {
86
- if (attr.name.name === 'className') {
87
- setLiteralValue(attr.value, `${attr.value.value} menu-submenu`);
88
- break;
89
- }
90
- }
86
+ appendAttributeValue(menuItem, 'className', 'menu-submenu');
91
87
  }
92
88
 
93
89
  function setDataMenuPath(key, name, menuItem) {
94
- const {attributes} = menuItem.openingElement;
95
90
  const dataMenuPath = name ? `${name}.${key}` : key;
96
-
97
- for (const attr of attributes) {
98
- if (attr.name.name === 'data-menu-path') {
99
- setLiteralValue(attr.value, dataMenuPath);
100
- break;
101
- }
102
- }
91
+ setAttributeValue(menuItem, 'data-menu-path', dataMenuPath);
103
92
  }
104
93
 
105
94
  function setIcon(name, menuItem) {
106
- const {attributes} = menuItem.openingElement;
107
-
108
- for (const attr of attributes) {
109
- if (attr.name.name === 'className') {
110
- setLiteralValue(attr.value, `${attr.value.value} icon ${getIconName(name)}`);
111
- break;
112
- }
113
- }
95
+ appendAttributeValue(menuItem, 'className', `icon ${getIconName(name)}`);
114
96
  }
115
97
 
116
98
  function getIconName(name) {
@@ -1,10 +1,7 @@
1
- export function checkDataName(path, dataName = 'menu') {
2
- const {attributes} = path.node;
1
+ import {getAttributeValue} from './jsx-operator.js';
2
+
3
+ export function checkDataName(path, value = 'menu') {
4
+ const attribute = getAttributeValue(path, 'data-name');
3
5
 
4
- for (const {name, value} of attributes) {
5
- if (name.name === 'data-name')
6
- return value.value === dataName;
7
- }
8
-
9
- return false;
6
+ return attribute === value;
10
7
  }
@@ -0,0 +1,17 @@
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'>
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>;
@@ -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
+
@@ -0,0 +1,41 @@
1
+ import {operator} from 'putout';
2
+ import {checkDataName} from '../check-data-name.js';
3
+ import {getAttributePath} from '../jsx-operator.js';
4
+
5
+ const {setLiteralValue} = operator;
6
+
7
+ export const report = () => `Hide submenu`;
8
+
9
+ export const fix = (path) => {
10
+ const {value} = path.node;
11
+ const newValue = value.value;
12
+
13
+ setLiteralValue(value, newValue
14
+ .replace('menu-submenu-show', '')
15
+ .trim());
16
+ };
17
+
18
+ export const traverse = ({push, options}) => ({
19
+ JSXOpeningElement(path) {
20
+ const {name, showSubmenu} = options;
21
+
22
+ if (path.node.name.name !== 'li')
23
+ return;
24
+
25
+ if (showSubmenu)
26
+ return;
27
+
28
+ const openingElementPath = path.parentPath.parentPath.get('openingElement');
29
+
30
+ if (!checkDataName(openingElementPath, name))
31
+ return false;
32
+
33
+ const attributePath = getAttributePath(path, 'className');
34
+
35
+ if (!attributePath)
36
+ return;
37
+
38
+ if (attributePath.node.value.value.includes('menu-submenu-show'))
39
+ push(attributePath);
40
+ },
41
+ });
@@ -1,3 +1,4 @@
1
+ import * as hideSubmenu from './hide-submenu/index.js';
1
2
  import * as submenu from './submenu/index.js';
2
3
  import * as setPosition from './set-position/index.js';
3
4
  import * as buildMenu from './build-menu/index.js';
@@ -12,4 +13,5 @@ export const rules = {
12
13
  'select': select,
13
14
  'unselect-all': unselectAll,
14
15
  'submenu': submenu,
16
+ 'hide-submenu': hideSubmenu,
15
17
  };
@@ -0,0 +1,56 @@
1
+ import {operator} from 'putout';
2
+
3
+ const {setLiteralValue} = operator;
4
+
5
+ export function getAttributeValue(path, attributeName) {
6
+ const {attributes} = path.node;
7
+
8
+ for (const {name, value} of attributes) {
9
+ if (name.name === attributeName)
10
+ return value.value;
11
+ }
12
+
13
+ return '';
14
+ }
15
+
16
+ export function getAttributeNode(node, name) {
17
+ let result = null;
18
+ const {attributes} = node.openingElement;
19
+
20
+ for (const attr of attributes) {
21
+ if (attr.name.name === name) {
22
+ result = attr;
23
+ break;
24
+ }
25
+ }
26
+
27
+ return result;
28
+ }
29
+
30
+ export function getAttributePath(path, name) {
31
+ let result = null;
32
+ const attributes = path.get('attributes');
33
+
34
+ for (const attr of attributes) {
35
+ if (attr.node.name.name === name) {
36
+ result = attr;
37
+ break;
38
+ }
39
+ }
40
+
41
+ return result;
42
+ }
43
+
44
+ export function appendAttributeValue(node, name, value) {
45
+ const attributeNode = getAttributeNode(node, name);
46
+
47
+ if (attributeNode)
48
+ setLiteralValue(attributeNode.value, `${attributeNode.value.value} ${value}`);
49
+ }
50
+
51
+ export function setAttributeValue(node, name, value) {
52
+ const attributeNode = getAttributeNode(node, name);
53
+
54
+ if (attributeNode)
55
+ setLiteralValue(attributeNode.value, value);
56
+ }
@@ -0,0 +1,17 @@
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-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>;
@@ -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 menu-item-selected">
13
+ <label data-menu-path="New.Directory">Directory</label>
14
+ </li>
15
+ </ul>
16
+ </li>
17
+ </ul>;
18
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aleman",
3
- "version": "1.3.0",
3
+ "version": "1.3.2",
4
4
  "type": "module",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊Putout-based framework for web",