aleman 1.7.1 → 1.9.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,13 @@
1
+ 2025.09.14, v1.9.0
2
+
3
+ feature:
4
+ - cb8b8bc aleman: menu: add support of $, ^
5
+
6
+ 2025.09.14, v1.8.0
7
+
8
+ feature:
9
+ - c338550 aleman: menu: vim: built-in
10
+
1
11
  2025.09.13, v1.7.1
2
12
 
3
13
  feature:
package/README.md CHANGED
@@ -20,13 +20,53 @@
20
20
  bun i aleman
21
21
  ```
22
22
 
23
- ## Usage Example
23
+ ## Rules and Addons
24
24
 
25
- Addon:
25
+ Aleman supports two main concepts:
26
+
27
+ - ✅ addons - events;
28
+ - ✅ rules - 🐊**Putout** rules that changes HTML;
29
+
30
+ All interaction with DOM made using rules, and we interact not with DOM directly, but with JSX AST.
31
+ It makes testing simple, states predictable and independent.
32
+
33
+ ### Addons
34
+
35
+ Addon responsible for UI and interfaction with outer world: clicks, fetches and everything like this.
36
+ Aleman supports next types of addons:
37
+
38
+ - ✅ [Global](#globals);
39
+ - ✅ [Events](#events);
40
+ - ✅ [Keys](#keys);
41
+ - ✅ [Vim](#vim);
42
+
43
+ When you need to filter out events according to `state` use `filter`:
26
44
 
27
45
  ```js
28
- export const events = ['click'];
29
46
  export const filter = ({state}) => state.command === 'show';
47
+ ```
48
+
49
+ #### Global
50
+
51
+ Any browser event you need to listen globally:
52
+
53
+ ```js
54
+ export const events = ['click'];
55
+ export const listener = () => ({
56
+ command: 'hide',
57
+ index: -1,
58
+ showSubmenu: false,
59
+ insideSubmenu: false,
60
+ });
61
+ ```
62
+
63
+ #### Events
64
+
65
+ Any browser event you need to listen according to element with `data-name="hello":
66
+
67
+ ```js
68
+ export const name = 'hello';
69
+ export const events = ['click'];
30
70
  export const listener = () => ({
31
71
  command: 'hide',
32
72
  index: -1,
@@ -35,6 +75,48 @@ export const listener = () => ({
35
75
  });
36
76
  ```
37
77
 
78
+ #### Keys
79
+
80
+ ```js
81
+ export const keys = ['Escape'];
82
+
83
+ export const listener = ({state, options}) => {
84
+ options.beforeHide?.(state);
85
+ return {
86
+ command: 'hide',
87
+ showSubmenu: false,
88
+ index: -1,
89
+ };
90
+ };
91
+ ```
92
+
93
+ ### Vim
94
+
95
+ ```js
96
+ import * as up from './up.js';
97
+
98
+ export const commands = ['gg'];
99
+
100
+ export function listener({state, options}) {
101
+ const {
102
+ insideSubmenu,
103
+ index,
104
+ submenuIndex,
105
+ } = state;
106
+
107
+ const newState = {
108
+ ...state,
109
+ index: insideSubmenu ? index : 1,
110
+ submenuIndex: insideSubmenu ? 1 : submenuIndex,
111
+ };
112
+
113
+ return up.listener({
114
+ state: newState,
115
+ options,
116
+ });
117
+ }
118
+ ```
119
+
38
120
  ## Licence
39
121
 
40
122
  MIT
@@ -1,3 +1,5 @@
1
+ import {createVimParser} from './vim.js';
2
+
1
3
  const queryElement = ({name}) => {
2
4
  return document.querySelector(`[data-name="${name}"]`);
3
5
  };
@@ -61,7 +63,7 @@ export const addGlobalListeners = ({globalAddons, options, readState, writeState
61
63
  }
62
64
  };
63
65
 
64
- const createListener = ({options, addon, readState, writeState}) => (event) => {
66
+ const createListener = ({options, addon, readState, writeState, parseVim = createVimParser()}) => (event) => {
65
67
  const {
66
68
  keys,
67
69
  listener,
@@ -70,11 +72,17 @@ const createListener = ({options, addon, readState, writeState}) => (event) => {
70
72
  filter,
71
73
  after,
72
74
  afterIf,
75
+ commands,
73
76
  } = addon;
74
77
 
75
78
  if (keys && !keys.includes(event.key))
76
79
  return;
77
80
 
81
+ const [command, count] = parseVim(event);
82
+
83
+ if (commands && !commands.includes(command))
84
+ return;
85
+
78
86
  const state = readState();
79
87
 
80
88
  const is = filter?.({
@@ -93,6 +101,7 @@ const createListener = ({options, addon, readState, writeState}) => (event) => {
93
101
  event.stopPropagation();
94
102
 
95
103
  const newState = listener({
104
+ count,
96
105
  event,
97
106
  state,
98
107
  options,
package/aleman/vim.js ADDED
@@ -0,0 +1,45 @@
1
+ const isNumber = (a) => !Number.isNaN(a) && typeof a === 'number';
2
+
3
+ export const createVimParser = (buffer = []) => ({key}) => {
4
+ if (key === '^')
5
+ return ['^'];
6
+
7
+ if (key === '$')
8
+ return ['$'];
9
+
10
+ if (!buffer.length && key === 'g') {
11
+ buffer.push('g');
12
+ return [''];
13
+ }
14
+
15
+ if (!buffer.length && /\d/.test(key)) {
16
+ buffer.push(Number(key));
17
+ return [''];
18
+ }
19
+
20
+ if (!buffer.length && key === 'j')
21
+ buffer.push(1);
22
+
23
+ if (!buffer.length && key === 'k')
24
+ buffer.push(1);
25
+
26
+ const [count] = buffer;
27
+
28
+ if (isNumber(count) && key === 'j') {
29
+ buffer = [];
30
+ return ['j', count];
31
+ }
32
+
33
+ if (isNumber(count) && key === 'k') {
34
+ buffer = [];
35
+ return ['k', count];
36
+ }
37
+
38
+ if (count === 'g' && key === 'g') {
39
+ buffer = [];
40
+ return ['gg'];
41
+ }
42
+
43
+ buffer = [];
44
+ return [''];
45
+ };
package/menu/README.md CHANGED
@@ -11,6 +11,19 @@
11
11
  - ✅[`submenu`](https://putout.cloudcmd.io/#/gist/b0a3b64d14f3497869a345e7e438d66e/feb671c4a59a555ff408af92fab602bae3a94e2f);
12
12
  - ✅[`hide-submenu`](https://putout.cloudcmd.io/#/gist/fdf6cf60a7fdfa2bae64279eda2ab023/ce0d5e24dc5e0b3436b7e87585c62e8a5132a9ab);
13
13
 
14
+ ## Hot Keys
15
+
16
+ | Key | Operation |
17
+ |:-------------|:------------------------|
18
+ | `F9` | open |
19
+ | `Esc` | close |
20
+ | `Up`, `j` | move cursor up |
21
+ | `Down`, `k` | move cursor down |
22
+ | `Left`, `h` | close submenu |
23
+ | `Right`, `l` | open submenu |
24
+ | `G` or `$` | navigate to bottom file |
25
+ | `gg` or `^` | navigate to top file |
26
+
14
27
  ## License
15
28
 
16
29
  MIT
@@ -1,6 +1,12 @@
1
- import * as up from '../up.js';
1
+ import * as up from './up.js';
2
2
 
3
- export function gg({state, options}) {
3
+ export const {filter} = up;
4
+ export const commands = [
5
+ 'gg',
6
+ '^',
7
+ ];
8
+
9
+ export function listener({state, options}) {
4
10
  const {
5
11
  insideSubmenu,
6
12
  index,
@@ -6,7 +6,9 @@ import * as enter from './enter.js';
6
6
  import * as left from './left.js';
7
7
  import * as right from './right.js';
8
8
  import * as shiftG from './shift-g.js';
9
- import {createVim} from './vim/index.js';
9
+ import * as gg from './gg.js';
10
+ import * as j from './j.js';
11
+ import * as k from './k.js';
10
12
 
11
13
  export const addons = [
12
14
  click,
@@ -17,5 +19,7 @@ export const addons = [
17
19
  left,
18
20
  right,
19
21
  shiftG,
20
- createVim(),
22
+ gg,
23
+ j,
24
+ k,
21
25
  ];
@@ -1,7 +1,10 @@
1
- import * as down from '../down.js';
2
- import {getSubmenu} from '../submenu/index.js';
1
+ import * as down from './down.js';
2
+ import {getSubmenu} from './submenu/index.js';
3
3
 
4
- export function j({count, state, options}) {
4
+ export const {filter} = down;
5
+ export const commands = ['j'];
6
+
7
+ export function listener({count, state, options}) {
5
8
  const {
6
9
  index,
7
10
  insideSubmenu,
@@ -1,6 +1,9 @@
1
- import * as down from '../down.js';
1
+ import * as down from './down.js';
2
2
 
3
- export function k({count, state, options}) {
3
+ export const {filter} = down;
4
+ export const commands = ['k'];
5
+
6
+ export function listener({count, state, options}) {
4
7
  const {
5
8
  insideSubmenu,
6
9
  index,
@@ -1,6 +1,6 @@
1
1
  import {getSubmenu} from './submenu/index.js';
2
2
 
3
- export const keys = ['G'];
3
+ export const keys = ['G', '$'];
4
4
 
5
5
  export const preventDefault = true;
6
6
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aleman",
3
- "version": "1.7.1",
3
+ "version": "1.9.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",
@@ -1,69 +0,0 @@
1
- import {k} from './k.js';
2
- import {gg} from './gg.js';
3
- import {j} from './j.js';
4
-
5
- const isNumber = (a) => !Number.isNaN(a) && typeof a === 'number';
6
-
7
- export const createVim = () => {
8
- const buffer = [];
9
-
10
- return {
11
- events,
12
- filter,
13
- listener: createListener(buffer),
14
- };
15
- };
16
-
17
- const events = ['keydown'];
18
-
19
- const filter = ({state}) => state.command === 'show';
20
-
21
- const createListener = (buffer) => ({event, state, options}) => {
22
- const {key} = event;
23
-
24
- if (!buffer.length && key === 'g') {
25
- buffer.push('g');
26
- return null;
27
- }
28
-
29
- if (!buffer.length && /\d/.test(key)) {
30
- buffer.push(Number(key));
31
- return null;
32
- }
33
-
34
- if (!buffer.length && key === 'j')
35
- buffer.push(1);
36
-
37
- if (!buffer.length && key === 'k')
38
- buffer.push(1);
39
-
40
- const [count] = buffer;
41
-
42
- if (isNumber(count) && key === 'j') {
43
- buffer = [];
44
- return j({
45
- count,
46
- state,
47
- options,
48
- });
49
- }
50
-
51
- if (isNumber(count) && key === 'k') {
52
- buffer = [];
53
- return k({
54
- count,
55
- state,
56
- options,
57
- });
58
- }
59
-
60
- if (count === 'g' && key === 'g') {
61
- buffer = [];
62
- return gg({
63
- state,
64
- options,
65
- });
66
- }
67
-
68
- buffer = [];
69
- };