aleman 1.0.1 → 1.0.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/README.md +28 -1
- package/lib/addons/input-change.js +7 -5
- package/lib/aleman/add-listeners.js +2 -1
- package/package.json +1 -1
- package/lib/rules/menu/index.spec.js +0 -34
- package/lib/rules/remove-button/index.spec.js +0 -20
- package/lib/rules/select-next/index.spec.js +0 -18
- package/lib/rules/set-value/index.spec.js +0 -29
package/README.md
CHANGED
|
@@ -12,12 +12,39 @@
|
|
|
12
12
|
>
|
|
13
13
|
> Yamamoto Tsunetomo, Hagakure
|
|
14
14
|
|
|
15
|
-
##
|
|
15
|
+
## Install
|
|
16
16
|
|
|
17
17
|
```
|
|
18
18
|
bun i aleman
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
+
## Usage Example
|
|
22
|
+
|
|
23
|
+
Addon:
|
|
24
|
+
|
|
25
|
+
```js
|
|
26
|
+
export const events = ['keydown'];
|
|
27
|
+
|
|
28
|
+
export const filter = ({event, state}) => {
|
|
29
|
+
if (event.key !== 'ArrowDown')
|
|
30
|
+
return false;
|
|
31
|
+
|
|
32
|
+
const {command} = state['menu-toggler'] || {
|
|
33
|
+
command: 'show',
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
return command !== 'hide';
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export const listener = ({state, render, element}) => {
|
|
40
|
+
const index = element.index || 0;
|
|
41
|
+
|
|
42
|
+
render('select-next', {
|
|
43
|
+
index: index + 1,
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
```
|
|
47
|
+
|
|
21
48
|
## Licence
|
|
22
49
|
|
|
23
50
|
MIT
|
|
@@ -4,9 +4,7 @@ export const events = [
|
|
|
4
4
|
'change',
|
|
5
5
|
];
|
|
6
6
|
|
|
7
|
-
export const
|
|
8
|
-
let {value} = element;
|
|
9
|
-
|
|
7
|
+
export const filter = ({state, event}) => {
|
|
10
8
|
const {key} = event;
|
|
11
9
|
const keys = [
|
|
12
10
|
'Shift',
|
|
@@ -15,8 +13,12 @@ export const listener = ({render, event, element}) => {
|
|
|
15
13
|
'ArrowRight',
|
|
16
14
|
];
|
|
17
15
|
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
return !keys.includes(key);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const listener = ({render, event, element}) => {
|
|
20
|
+
const {key} = event;
|
|
21
|
+
let {value} = element;
|
|
20
22
|
|
|
21
23
|
if (isTextSelected(element) && key === 'Backspace')
|
|
22
24
|
value = '';
|
|
@@ -36,7 +36,7 @@ const createListener = ({name, filter = success, state, render, listener, storag
|
|
|
36
36
|
};
|
|
37
37
|
|
|
38
38
|
export function addListeners({render, addons, storage}) {
|
|
39
|
-
for (const {name, events, listener} of addons) {
|
|
39
|
+
for (const {name, events, listener, filter} of addons) {
|
|
40
40
|
for (const event of events) {
|
|
41
41
|
const element = document.querySelector(`[data-name='${name}']`);
|
|
42
42
|
|
|
@@ -47,6 +47,7 @@ export function addListeners({render, addons, storage}) {
|
|
|
47
47
|
name,
|
|
48
48
|
render,
|
|
49
49
|
listener,
|
|
50
|
+
filter,
|
|
50
51
|
storage,
|
|
51
52
|
}));
|
|
52
53
|
}
|
package/package.json
CHANGED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import {createTest} from '@putout/test';
|
|
2
|
-
import * as plugin from './index.js';
|
|
3
|
-
|
|
4
|
-
const test = createTest(import.meta.url, {
|
|
5
|
-
plugins: [
|
|
6
|
-
['show-menu', plugin],
|
|
7
|
-
],
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
test('lib: show-menu: report', (t) => {
|
|
11
|
-
t.reportWithOptions('hide-menu', `Hide menu`, {
|
|
12
|
-
command: 'hide',
|
|
13
|
-
});
|
|
14
|
-
t.end();
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
test('lib: show-menu: transform with options: show-menu', (t) => {
|
|
18
|
-
t.transformWithOptions('show-menu', {
|
|
19
|
-
command: 'show',
|
|
20
|
-
});
|
|
21
|
-
t.end();
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
test('lib: show-menu: transform with options: hide-menu', (t) => {
|
|
25
|
-
t.transformWithOptions('hide-menu', {
|
|
26
|
-
command: 'hide',
|
|
27
|
-
});
|
|
28
|
-
t.end();
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
test('lib: show-menu: no report: no-menu', (t) => {
|
|
32
|
-
t.noReport('no-menu');
|
|
33
|
-
t.end();
|
|
34
|
-
});
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import {createTest} from '@putout/test';
|
|
2
|
-
import * as plugin from './index.js';
|
|
3
|
-
|
|
4
|
-
const test = createTest(import.meta.url, {
|
|
5
|
-
plugins: [
|
|
6
|
-
['remove-button', plugin],
|
|
7
|
-
],
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
test('html: remove-button: report', (t) => {
|
|
11
|
-
t.reportWithOptions('remove-button', `Remove button`, {
|
|
12
|
-
name: 'start',
|
|
13
|
-
});
|
|
14
|
-
t.end();
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
test('html: remove-button: transform', (t) => {
|
|
18
|
-
t.transform('remove-button');
|
|
19
|
-
t.end();
|
|
20
|
-
});
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import {createTest} from '@putout/test';
|
|
2
|
-
import * as plugin from './index.js';
|
|
3
|
-
|
|
4
|
-
const test = createTest(import.meta.url, {
|
|
5
|
-
plugins: [
|
|
6
|
-
['select-next', plugin],
|
|
7
|
-
],
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
test('lib: select-next: report', (t) => {
|
|
11
|
-
t.report('select-next', `Select next item`);
|
|
12
|
-
t.end();
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
test('lib: select-next: transform', (t) => {
|
|
16
|
-
t.transform('select-next');
|
|
17
|
-
t.end();
|
|
18
|
-
});
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import {createTest} from '@putout/test';
|
|
2
|
-
import * as plugin from './index.js';
|
|
3
|
-
|
|
4
|
-
const test = createTest(import.meta.url, {
|
|
5
|
-
plugins: [
|
|
6
|
-
['set-value', plugin],
|
|
7
|
-
],
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
test('aleman: set-value: report', (t) => {
|
|
11
|
-
t.reportWithOptions('set-value', `Use 'if condition' instead of 'ternary expression'`, {
|
|
12
|
-
name: 'x',
|
|
13
|
-
});
|
|
14
|
-
t.end();
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
test('aleman: set-value: transform with options', (t) => {
|
|
18
|
-
t.transformWithOptions('set-value', {
|
|
19
|
-
name: 'x',
|
|
20
|
-
});
|
|
21
|
-
t.end();
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
test('aleman: set-value: no transform with options: data-name', (t) => {
|
|
25
|
-
t.noTransformWithOptions('data-name', {
|
|
26
|
-
name: 'x',
|
|
27
|
-
});
|
|
28
|
-
t.end();
|
|
29
|
-
});
|