aleman 1.6.2 → 1.7.1

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.13, v1.7.1
2
+
3
+ feature:
4
+ - c5ddd5d vim: restructure
5
+
6
+ 2025.09.13, v1.7.0
7
+
8
+ feature:
9
+ - 176eb02 aleman: menu: Number + j, Number + k
10
+
1
11
  2025.09.12, v1.6.2
2
12
 
3
13
  fix:
@@ -1,9 +1,6 @@
1
1
  import {getSubmenu} from './submenu/index.js';
2
2
 
3
- export const keys = [
4
- 'ArrowDown',
5
- 'j',
6
- ];
3
+ export const keys = ['ArrowDown'];
7
4
  export const preventDefault = true;
8
5
 
9
6
  export const filter = ({state}) => state.command === 'show';
@@ -6,7 +6,7 @@ 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.js';
9
+ import {createVim} from './vim/index.js';
10
10
 
11
11
  export const addons = [
12
12
  click,
package/menu/addons/up.js CHANGED
@@ -1,9 +1,6 @@
1
1
  import {getSubmenu} from './submenu/index.js';
2
2
 
3
- export const keys = [
4
- 'ArrowUp',
5
- 'k',
6
- ];
3
+ export const keys = ['ArrowUp'];
7
4
 
8
5
  export const preventDefault = true;
9
6
 
@@ -0,0 +1,20 @@
1
+ import * as up from '../up.js';
2
+
3
+ export function gg({state, options}) {
4
+ const {
5
+ insideSubmenu,
6
+ index,
7
+ submenuIndex,
8
+ } = state;
9
+
10
+ const newState = {
11
+ ...state,
12
+ index: insideSubmenu ? index : 1,
13
+ submenuIndex: insideSubmenu ? 1 : submenuIndex,
14
+ };
15
+
16
+ return up.listener({
17
+ state: newState,
18
+ options,
19
+ });
20
+ }
@@ -0,0 +1,69 @@
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
+ };
@@ -0,0 +1,36 @@
1
+ import * as down from '../down.js';
2
+ import {getSubmenu} from '../submenu/index.js';
3
+
4
+ export function j({count, state, options}) {
5
+ const {
6
+ index,
7
+ insideSubmenu,
8
+ submenuIndex,
9
+ } = state;
10
+
11
+ const menuCount = Object.keys(options.menu).length;
12
+ const submenuCount = Object.keys(getSubmenu({
13
+ index,
14
+ options,
15
+ })).length;
16
+
17
+ let newIndex = insideSubmenu ? index : index + count - 1;
18
+ let newSubmenuIndex = insideSubmenu ? submenuIndex + count : submenuIndex;
19
+
20
+ if (newIndex > menuCount - 1)
21
+ newIndex = menuCount - 1;
22
+
23
+ if (newSubmenuIndex > submenuCount - 1)
24
+ newSubmenuIndex = submenuCount - 1;
25
+
26
+ const newState = {
27
+ ...state,
28
+ index: newIndex,
29
+ submenuIndex: newSubmenuIndex,
30
+ };
31
+
32
+ return down.listener({
33
+ state: newState,
34
+ options,
35
+ });
36
+ }
@@ -0,0 +1,29 @@
1
+ import * as down from '../down.js';
2
+
3
+ export function k({count, state, options}) {
4
+ const {
5
+ insideSubmenu,
6
+ index,
7
+ submenuIndex,
8
+ } = state;
9
+
10
+ let newIndex = insideSubmenu ? index : index - count - 1;
11
+ let newSubmenuIndex = insideSubmenu ? submenuIndex - count - 1 : submenuIndex;
12
+
13
+ if (newIndex < -1)
14
+ newIndex = -1;
15
+
16
+ if (newSubmenuIndex < -1)
17
+ newSubmenuIndex = -1;
18
+
19
+ const newState = {
20
+ ...state,
21
+ index: newIndex,
22
+ submenuIndex: newSubmenuIndex,
23
+ };
24
+
25
+ return down.listener({
26
+ state: newState,
27
+ options,
28
+ });
29
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aleman",
3
- "version": "1.6.2",
3
+ "version": "1.7.1",
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,46 +0,0 @@
1
- import * as up from './up.js';
2
-
3
- export const createVim = () => {
4
- const buffer = [];
5
-
6
- return {
7
- events,
8
- filter,
9
- listener: createListener(buffer),
10
- };
11
- };
12
-
13
- const events = ['keydown'];
14
-
15
- const filter = ({state}) => state.command === 'show';
16
-
17
- const createListener = (buffer) => ({event, state, options}) => {
18
- const {key} = event;
19
-
20
- if (!buffer.length && key === 'g') {
21
- buffer.push('g');
22
- return null;
23
- }
24
-
25
- if (buffer[0] === 'g' && key === 'g') {
26
- buffer = [];
27
- const {
28
- insideSubmenu,
29
- index,
30
- submenuIndex,
31
- } = state;
32
-
33
- const newState = {
34
- ...state,
35
- index: insideSubmenu ? index : 1,
36
- submenuIndex: insideSubmenu ? 1 : submenuIndex,
37
- };
38
-
39
- return up.listener({
40
- state: newState,
41
- options,
42
- });
43
- }
44
-
45
- buffer = [];
46
- };