autopair 1.0.2 → 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 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
+ ![Automatically close parentheses](./images/autoclose.gif)
10
+
8
11
  2. Wraps selected text. For example, selecting a word and hitting `(` will wrap the word in parentheses.
12
+
13
+ ![Wrap selected text](./images/wrap.gif)
14
+
9
15
  3. Atomically removes pairings. For example, when hitting backspace inside `()`, both characters are removed.
10
- 4. Types through closing characters. For example, hitting `]` in front of an already typed `]` simply moves the cursor past it.
16
+
17
+ ![Atomically remove pairings](./images/remove.gif)
18
+
19
+ 4. Types through closing characters. For example, hitting `)` in front of an already typed `)` simply moves the cursor past it.
20
+
21
+ ![Type through closing characters](./images/typethrough.gif)
11
22
 
12
23
  ## Installation
13
24
 
@@ -18,8 +29,12 @@ npm install autopair
18
29
  ## Usage
19
30
 
20
31
  ```html
21
- <script src="path/to/autopair.js"></script>
22
- <script>
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
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "autopair",
3
- "version": "1.0.2",
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>",
package/src/autopair.js CHANGED
@@ -5,7 +5,7 @@ export default function autopair(textarea, pairs = {
5
5
  "'": "'",
6
6
  '"': '"'
7
7
  }) {
8
- textarea.addEventListener('keydown', (evt) => {
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
  }