aleman 1.7.0 → 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,8 @@
1
+ 2025.09.13, v1.7.1
2
+
3
+ feature:
4
+ - c5ddd5d vim: restructure
5
+
1
6
  2025.09.13, v1.7.0
2
7
 
3
8
  feature:
@@ -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,
@@ -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.7.0",
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,124 +0,0 @@
1
- import * as up from './up.js';
2
- import * as down from './down.js';
3
- import {getSubmenu} from './submenu/index.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
- const {index} = state;
24
-
25
- const menuCount = Object.keys(options.menu).length;
26
- const submenuCount = Object.keys(getSubmenu({
27
- index,
28
- options,
29
- })).length;
30
-
31
- if (!buffer.length && key === 'g') {
32
- buffer.push('g');
33
- return null;
34
- }
35
-
36
- if (!buffer.length && /\d/.test(key)) {
37
- buffer.push(Number(key));
38
- return null;
39
- }
40
-
41
- if (!buffer.length && key === 'j')
42
- buffer.push(1);
43
-
44
- if (!buffer.length && key === 'k')
45
- buffer.push(1);
46
-
47
- const [first] = buffer;
48
-
49
- if (isNumber(first) && key === 'j') {
50
- buffer = [];
51
- const {insideSubmenu, submenuIndex} = state;
52
-
53
- let newIndex = insideSubmenu ? index : index + first - 1;
54
- let newSubmenuIndex = insideSubmenu ? submenuIndex + first : submenuIndex;
55
-
56
- if (newIndex > menuCount - 1)
57
- newIndex = menuCount - 1;
58
-
59
- if (newSubmenuIndex > submenuCount - 1)
60
- newSubmenuIndex = submenuCount - 1;
61
-
62
- const newState = {
63
- ...state,
64
- index: newIndex,
65
- submenuIndex: newSubmenuIndex,
66
- };
67
-
68
- return down.listener({
69
- state: newState,
70
- options,
71
- });
72
- }
73
-
74
- if (isNumber(first) && key === 'k') {
75
- buffer = [];
76
- const {
77
- insideSubmenu,
78
- index,
79
- submenuIndex,
80
- } = state;
81
-
82
- let newIndex = insideSubmenu ? index : index - first - 1;
83
- let newSubmenuIndex = insideSubmenu ? submenuIndex - first - 1 : submenuIndex;
84
-
85
- if (newIndex < -1)
86
- newIndex = -1;
87
-
88
- if (newSubmenuIndex < -1)
89
- newSubmenuIndex = -1;
90
-
91
- const newState = {
92
- ...state,
93
- index: newIndex,
94
- submenuIndex: newSubmenuIndex,
95
- };
96
-
97
- return down.listener({
98
- state: newState,
99
- options,
100
- });
101
- }
102
-
103
- if (first === 'g' && key === 'g') {
104
- buffer = [];
105
- const {
106
- insideSubmenu,
107
- index,
108
- submenuIndex,
109
- } = state;
110
-
111
- const newState = {
112
- ...state,
113
- index: insideSubmenu ? index : 1,
114
- submenuIndex: insideSubmenu ? 1 : submenuIndex,
115
- };
116
-
117
- return up.listener({
118
- state: newState,
119
- options,
120
- });
121
- }
122
-
123
- buffer = [];
124
- };