autopair 1.0.2 → 1.1.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/LICENSE.md CHANGED
@@ -2,7 +2,7 @@ Adjusted MIT License
2
2
 
3
3
  Copyright (c) 2025 Dennis Hackethal
4
4
 
5
- Permission is hereby granted, free of charge, to any person* obtaining a copy
5
+ Permission is hereby granted, free of charge, to any person[^1] obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
7
7
  in the Software without restriction, including without limitation the rights
8
8
  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@@ -20,7 +20,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
20
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  SOFTWARE.
22
22
 
23
- * Exception: no one in the public sector may use this software. That means
23
+ [^1]: Exception: no one in the public sector may use this software. That means
24
24
  no politicians, public-school teachers, police, intelligence services, etc.
25
25
  Private recipients of public moneys may not use this software either unless
26
26
  they oppose the welfare state and consider such moneys restitution. No one
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.1",
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
  }