autopair 1.0.1 → 1.1.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/README.md +22 -3
- package/images/autoclose.gif +0 -0
- package/images/remove.gif +0 -0
- package/images/typethrough.gif +0 -0
- package/images/wrap.gif +0 -0
- package/package.json +5 -1
- package/src/autopair.js +8 -2
package/README.md
CHANGED
|
@@ -5,9 +5,20 @@ Lightweight autopairing + typethrough behavior for HTML `input[type=text]` and `
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
7
|
1. Automatically closes parentheses, brackets, curly braces, single quotes, and double quotes.
|
|
8
|
+
|
|
9
|
+

|
|
10
|
+
|
|
8
11
|
2. Wraps selected text. For example, selecting a word and hitting `(` will wrap the word in parentheses.
|
|
12
|
+
|
|
13
|
+

|
|
14
|
+
|
|
9
15
|
3. Atomically removes pairings. For example, when hitting backspace inside `()`, both characters are removed.
|
|
10
|
-
|
|
16
|
+
|
|
17
|
+

|
|
18
|
+
|
|
19
|
+
4. Types through closing characters. For example, hitting `)` in front of an already typed `)` simply moves the cursor past it.
|
|
20
|
+
|
|
21
|
+

|
|
11
22
|
|
|
12
23
|
## Installation
|
|
13
24
|
|
|
@@ -18,8 +29,12 @@ npm install autopair
|
|
|
18
29
|
## Usage
|
|
19
30
|
|
|
20
31
|
```html
|
|
21
|
-
<
|
|
22
|
-
|
|
32
|
+
<textarea id="editor"></textarea>
|
|
33
|
+
|
|
34
|
+
<script type="module">
|
|
35
|
+
import autopair from '/path/to/autopair.js';
|
|
36
|
+
|
|
37
|
+
// Use the autopair module
|
|
23
38
|
const textarea = document.getElementById('editor');
|
|
24
39
|
|
|
25
40
|
// Autopair with default pairings:
|
|
@@ -41,6 +56,10 @@ npm install autopair
|
|
|
41
56
|
'“': '”',
|
|
42
57
|
'*': '*' // For markdown italics
|
|
43
58
|
});
|
|
59
|
+
|
|
60
|
+
// Teardown, ie remove autopair.js functionality
|
|
61
|
+
let teardown = autopair(textarea);
|
|
62
|
+
teardown();
|
|
44
63
|
</script>
|
|
45
64
|
```
|
|
46
65
|
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/images/wrap.gif
ADDED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "autopair",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Automatically closes parentheses and similar characters.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"author": "Dennis Hackethal <engineering@dennishackethal.com>",
|
|
7
7
|
"license": "Adjusted MIT",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"exports": {
|
|
10
|
+
"import": "./src/autopair.js"
|
|
11
|
+
},
|
|
8
12
|
"homepage": "https://github.com/dchacke/autopair.js",
|
|
9
13
|
"repository": {
|
|
10
14
|
"type": "git",
|
package/src/autopair.js
CHANGED
|
@@ -5,7 +5,7 @@ export default function autopair(textarea, pairs = {
|
|
|
5
5
|
"'": "'",
|
|
6
6
|
'"': '"'
|
|
7
7
|
}) {
|
|
8
|
-
|
|
8
|
+
let handler = evt => {
|
|
9
9
|
const { selectionStart: start, selectionEnd: end, value } = textarea;
|
|
10
10
|
|
|
11
11
|
// Typethrough
|
|
@@ -65,5 +65,11 @@ export default function autopair(textarea, pairs = {
|
|
|
65
65
|
textarea.selectionStart = textarea.selectionEnd = start;
|
|
66
66
|
document.execCommand('insertText', false, evt.key + closing);
|
|
67
67
|
textarea.selectionStart = textarea.selectionEnd = start + 1;
|
|
68
|
-
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
textarea.addEventListener('keydown', handler);
|
|
71
|
+
|
|
72
|
+
return () => {
|
|
73
|
+
textarea.removeEventListener('keydown', handler);
|
|
74
|
+
};
|
|
69
75
|
}
|