tiny-essentials 1.17.1 โ 1.18.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/dist/legacy/get/countObj.cjs +2 -2
- package/dist/legacy/get/countObj.d.mts +1 -1
- package/dist/legacy/get/countObj.mjs +1 -1
- package/dist/legacy/index.cjs +2 -1
- package/dist/v1/TinyBasicsEs.js +559 -411
- package/dist/v1/TinyBasicsEs.min.js +1 -1
- package/dist/v1/TinyClipboard.js +459 -0
- package/dist/v1/TinyClipboard.min.js +1 -0
- package/dist/v1/TinyDragger.js +170 -2454
- package/dist/v1/TinyDragger.min.js +1 -2
- package/dist/v1/TinyEssentials.js +1093 -63
- package/dist/v1/TinyEssentials.min.js +1 -1
- package/dist/v1/TinyHtml.js +164 -21
- package/dist/v1/TinyHtml.min.js +1 -1
- package/dist/v1/TinySmartScroller.js +164 -21
- package/dist/v1/TinySmartScroller.min.js +1 -1
- package/dist/v1/TinyTextRangeEditor.js +497 -0
- package/dist/v1/TinyTextRangeEditor.min.js +1 -0
- package/dist/v1/TinyUploadClicker.js +219 -467
- package/dist/v1/TinyUploadClicker.min.js +1 -1
- package/dist/v1/basics/html.cjs +3 -3
- package/dist/v1/basics/html.mjs +1 -1
- package/dist/v1/basics/index.cjs +3 -2
- package/dist/v1/basics/index.d.mts +2 -2
- package/dist/v1/basics/index.mjs +2 -1
- package/dist/v1/basics/objChecker.cjs +46 -0
- package/dist/v1/basics/objChecker.d.mts +29 -0
- package/dist/v1/basics/objChecker.mjs +45 -0
- package/dist/v1/basics/objFilter.cjs +4 -45
- package/dist/v1/basics/objFilter.d.mts +3 -28
- package/dist/v1/basics/objFilter.mjs +2 -45
- package/dist/v1/build/TinyClipboard.cjs +7 -0
- package/dist/v1/build/TinyClipboard.d.mts +3 -0
- package/dist/v1/build/TinyClipboard.mjs +2 -0
- package/dist/v1/build/TinyTextRangeEditor.cjs +7 -0
- package/dist/v1/build/TinyTextRangeEditor.d.mts +3 -0
- package/dist/v1/build/TinyTextRangeEditor.mjs +2 -0
- package/dist/v1/index.cjs +7 -2
- package/dist/v1/index.d.mts +5 -3
- package/dist/v1/index.mjs +5 -2
- package/dist/v1/libs/TinyClipboard.cjs +420 -0
- package/dist/v1/libs/TinyClipboard.d.mts +155 -0
- package/dist/v1/libs/TinyClipboard.mjs +398 -0
- package/dist/v1/libs/TinyDragger.cjs +3 -3
- package/dist/v1/libs/TinyDragger.mjs +1 -1
- package/dist/v1/libs/TinyHtml.cjs +164 -21
- package/dist/v1/libs/TinyHtml.d.mts +150 -27
- package/dist/v1/libs/TinyHtml.mjs +158 -20
- package/dist/v1/libs/TinyTextRangeEditor.cjs +458 -0
- package/dist/v1/libs/TinyTextRangeEditor.d.mts +200 -0
- package/dist/v1/libs/TinyTextRangeEditor.mjs +424 -0
- package/dist/v1/libs/TinyUploadClicker.cjs +5 -4
- package/docs/v1/README.md +3 -0
- package/docs/v1/basics/objChecker.md +47 -0
- package/docs/v1/basics/objFilter.md +0 -40
- package/docs/v1/libs/TinyClipboard.md +213 -0
- package/docs/v1/libs/TinyHtml.md +112 -15
- package/docs/v1/libs/TinyTextRangeEditor.md +208 -0
- package/package.json +1 -1
- package/dist/v1/TinyDragger.min.js.LICENSE.txt +0 -8
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
# ๐ TinyClipboard Documentation
|
|
2
|
+
|
|
3
|
+
A lightweight utility class for clipboard interactions with support for modern Clipboard API, custom overrides, and legacy fallback methods like `execCommand`.
|
|
4
|
+
|
|
5
|
+
## ๐ Features
|
|
6
|
+
|
|
7
|
+
* โ
Supports copying and reading **plain text**
|
|
8
|
+
* โ
Supports copying and reading **binary data (Blob)**
|
|
9
|
+
* โ
Automatically detects support for modern Clipboard API
|
|
10
|
+
* โ
Fallback for legacy `document.execCommand()`
|
|
11
|
+
* โ
Allows **custom clipboard handler overrides** for Electron, Capacitor, etc.
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## ๐๏ธ Class: `TinyClipboard`
|
|
16
|
+
|
|
17
|
+
### ๐ง Constructor
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
new TinyClipboard()
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Initializes the clipboard utility and detects available clipboard APIs.
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## โ๏ธ Copy Methods
|
|
28
|
+
|
|
29
|
+
### ๐ `copyText(text: string): Promise<void>`
|
|
30
|
+
|
|
31
|
+
Copies a plain text string to the clipboard.
|
|
32
|
+
|
|
33
|
+
#### Parameters:
|
|
34
|
+
|
|
35
|
+
* `text` โ The string to copy.
|
|
36
|
+
|
|
37
|
+
#### Throws:
|
|
38
|
+
|
|
39
|
+
* `TypeError` if the input is not a string.
|
|
40
|
+
* `Error` if no clipboard method is available.
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
### ๐งฉ `copyBlob(blob: Blob): Promise<void>`
|
|
45
|
+
|
|
46
|
+
Copies binary data (e.g., images, files) to the clipboard.
|
|
47
|
+
|
|
48
|
+
#### Parameters:
|
|
49
|
+
|
|
50
|
+
* `blob` โ The Blob object to copy.
|
|
51
|
+
|
|
52
|
+
#### Throws:
|
|
53
|
+
|
|
54
|
+
* `TypeError` if the input is not a Blob.
|
|
55
|
+
* `Error` if clipboard API is unavailable.
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## ๐ง Override Methods
|
|
60
|
+
|
|
61
|
+
### ๐ ๏ธ `setCopyText(callback: (text: string) => Promise<void>)`
|
|
62
|
+
|
|
63
|
+
Overrides the default text copy handler (e.g., for Electron or Capacitor).
|
|
64
|
+
|
|
65
|
+
#### Throws:
|
|
66
|
+
|
|
67
|
+
* `TypeError` if the callback is not a function.
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
### ๐ ๏ธ `setCopyBlob(callback: (blob: Blob) => Promise<void>)`
|
|
72
|
+
|
|
73
|
+
Overrides the default Blob copy handler.
|
|
74
|
+
|
|
75
|
+
#### Throws:
|
|
76
|
+
|
|
77
|
+
* `TypeError` if the callback is not a function.
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
## ๐ฅ Read Methods
|
|
82
|
+
|
|
83
|
+
### ๐งพ `readText(index?: number = 0): Promise<string|null>`
|
|
84
|
+
|
|
85
|
+
Reads plain text from a specific clipboard index.
|
|
86
|
+
|
|
87
|
+
#### Throws:
|
|
88
|
+
|
|
89
|
+
* `Error` if the result is not a string.
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
### ๐ผ๏ธ `readCustom(mimeFormat?: string, fixValue?: boolean, index?: number): Promise<Blob|null>`
|
|
94
|
+
|
|
95
|
+
Reads a custom MIME-type item from the clipboard.
|
|
96
|
+
|
|
97
|
+
#### Parameters:
|
|
98
|
+
|
|
99
|
+
* `mimeFormat` โ MIME type or prefix (e.g., `"image/"`)
|
|
100
|
+
* `fixValue` โ Whether to match the MIME type exactly
|
|
101
|
+
* `index` โ The clipboard item index
|
|
102
|
+
|
|
103
|
+
#### Throws:
|
|
104
|
+
|
|
105
|
+
* `Error` if the result is not a Blob.
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
### ๐ `readAllTexts(): Promise<string[]>`
|
|
110
|
+
|
|
111
|
+
Reads all plain text entries from the clipboard.
|
|
112
|
+
|
|
113
|
+
#### Throws:
|
|
114
|
+
|
|
115
|
+
* `Error` if any entry is not a string.
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
### ๐งณ `readAllCustom(mimeFormat?: string, fixValue?: boolean): Promise<Blob[]>`
|
|
120
|
+
|
|
121
|
+
Reads all custom MIME-type items from the clipboard.
|
|
122
|
+
|
|
123
|
+
#### Throws:
|
|
124
|
+
|
|
125
|
+
* `Error` if any entry is not a Blob.
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
### ๐ `readAllData(type?: 'text' | 'custom', mimeFormat?: string): Promise<Array<string | Blob>>`
|
|
130
|
+
|
|
131
|
+
Reads all clipboard content filtered by type or MIME.
|
|
132
|
+
|
|
133
|
+
#### Returns:
|
|
134
|
+
|
|
135
|
+
* An array of strings or Blobs.
|
|
136
|
+
|
|
137
|
+
---
|
|
138
|
+
|
|
139
|
+
### ๐ข `readIndex(index: number): Promise<ClipboardItem|null>`
|
|
140
|
+
|
|
141
|
+
Reads a single clipboard item by index.
|
|
142
|
+
|
|
143
|
+
---
|
|
144
|
+
|
|
145
|
+
### ๐๏ธ `readAll(): Promise<ClipboardItem[]>`
|
|
146
|
+
|
|
147
|
+
Reads all clipboard items.
|
|
148
|
+
|
|
149
|
+
#### Throws:
|
|
150
|
+
|
|
151
|
+
* `Error` if the returned items are not all valid `ClipboardItem` instances.
|
|
152
|
+
|
|
153
|
+
---
|
|
154
|
+
|
|
155
|
+
## ๐งช Internal (Private) Helpers
|
|
156
|
+
|
|
157
|
+
> These methods are not intended for external use.
|
|
158
|
+
|
|
159
|
+
* `_handleBlob(type: string, item: ClipboardItem): Promise<Blob>`
|
|
160
|
+
* `_handleText(type: string, item: ClipboardItem): Promise<string>`
|
|
161
|
+
* `_read(index: number|null): Promise<ClipboardItem|ClipboardItem[]>`
|
|
162
|
+
* `_readData(...)`: Internal filter mechanism used by public `read*` methods.
|
|
163
|
+
|
|
164
|
+
---
|
|
165
|
+
|
|
166
|
+
## โ
Getters
|
|
167
|
+
|
|
168
|
+
### ๐ `isExecCommandAvailable(): boolean`
|
|
169
|
+
|
|
170
|
+
Returns `true` if legacy `document.execCommand()` is available.
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
### ๐ `isNavigatorClipboardAvailable(): boolean`
|
|
175
|
+
|
|
176
|
+
Returns `true` if modern `navigator.clipboard` is available.
|
|
177
|
+
|
|
178
|
+
---
|
|
179
|
+
|
|
180
|
+
### ๐งช `getCopyTextFunc(): ((text: string) => Promise<void>) | null`
|
|
181
|
+
|
|
182
|
+
Gets the current function used for copying text.
|
|
183
|
+
|
|
184
|
+
---
|
|
185
|
+
|
|
186
|
+
### ๐งช `getCopyBlobFunc(): ((blob: Blob) => Promise<void>) | null`
|
|
187
|
+
|
|
188
|
+
Gets the current function used for copying blobs.
|
|
189
|
+
|
|
190
|
+
---
|
|
191
|
+
|
|
192
|
+
## ๐ง Usage Example
|
|
193
|
+
|
|
194
|
+
```ts
|
|
195
|
+
import TinyClipboard from './TinyClipboard.js';
|
|
196
|
+
|
|
197
|
+
const clipboard = new TinyClipboard();
|
|
198
|
+
|
|
199
|
+
// Copy text
|
|
200
|
+
await clipboard.copyText("Hello world!");
|
|
201
|
+
|
|
202
|
+
// Read text
|
|
203
|
+
const value = await clipboard.readText();
|
|
204
|
+
console.log(value);
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
---
|
|
208
|
+
|
|
209
|
+
## ๐ Notes
|
|
210
|
+
|
|
211
|
+
* Browser permission is required to access the clipboard.
|
|
212
|
+
* Clipboard access may be restricted to user interactions (e.g., click events).
|
|
213
|
+
* This utility is designed for use in environments with **Clipboard API** support or suitable **fallbacks**.
|
package/docs/v1/libs/TinyHtml.md
CHANGED
|
@@ -90,8 +90,32 @@ ElementAndWinAndDoc | TinyHtml
|
|
|
90
90
|
|
|
91
91
|
---
|
|
92
92
|
|
|
93
|
+
#### `TinyElementWithDoc`
|
|
94
|
+
|
|
95
|
+
Accepts both raw DOM elements, the `document` object, or a `TinyHtml` wrapper.
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
ElementWithDoc | TinyHtml
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Used to abstract interactions with either native elements or enhanced wrappers.
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
93
105
|
### ๐ Union Types
|
|
94
106
|
|
|
107
|
+
#### `ElementWithDoc`
|
|
108
|
+
|
|
109
|
+
A raw DOM `Element` or the `document` object.
|
|
110
|
+
|
|
111
|
+
```ts
|
|
112
|
+
Element | Document
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
Commonly used when the target might be either a single HTML element or the whole document, particularly in layout and measurement utilities.
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
95
119
|
#### `ElementAndWinAndDoc`
|
|
96
120
|
|
|
97
121
|
Used for scrollable or measurable targets.
|
|
@@ -133,18 +157,6 @@ Window | Element | Document | Text
|
|
|
133
157
|
|
|
134
158
|
---
|
|
135
159
|
|
|
136
|
-
### ๐ฏ Event System Types
|
|
137
|
-
|
|
138
|
-
#### `EventRegistryHandle`
|
|
139
|
-
|
|
140
|
-
A basic event listener handler function.
|
|
141
|
-
|
|
142
|
-
```ts
|
|
143
|
-
(e: Event) => any
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
---
|
|
147
|
-
|
|
148
160
|
#### `EventRegistryOptions`
|
|
149
161
|
|
|
150
162
|
Options for `addEventListener` and `removeEventListener`.
|
|
@@ -161,7 +173,7 @@ Describes an individual event registration.
|
|
|
161
173
|
|
|
162
174
|
```ts
|
|
163
175
|
{
|
|
164
|
-
handler:
|
|
176
|
+
handler: EventListenerOrEventListenerObject | null,
|
|
165
177
|
options?: EventRegistryOptions
|
|
166
178
|
}
|
|
167
179
|
```
|
|
@@ -446,8 +458,10 @@ Each method below ensures type and returns raw DOM objects:
|
|
|
446
458
|
| `_preEventTargetElem(...)` | `EventTarget` | `EventTarget` |
|
|
447
459
|
| `_preElemsAndWindow(...)` | `Element\|Window` | `ElementAndWindow[]` |
|
|
448
460
|
| `_preElemAndWindow(...)` | `Element\|Window` | `ElementAndWindow` |
|
|
449
|
-
| `_preElemsAndWinAndDoc(...)`
|
|
450
|
-
| `_preElemAndWinAndDoc(...)`
|
|
461
|
+
| `_preElemsAndWinAndDoc(...)` | `Element\|Window\|Document` | `ElementAndWindow[]` |
|
|
462
|
+
| `_preElemAndWinAndDoc(...)` | `Element\|Window\|Document` | `ElementAndWindow` |
|
|
463
|
+
| `_preElemsWithDoc(...)` | `Element\|Document` | `ElementWithDoc[]` |
|
|
464
|
+
| `_preElemWithDoc(...)` | `Element\|Document` | `ElementWithDoc` |
|
|
451
465
|
|
|
452
466
|
---
|
|
453
467
|
|
|
@@ -1236,6 +1250,89 @@ All event listeners are tracked in a private registry for full control.
|
|
|
1236
1250
|
|
|
1237
1251
|
---
|
|
1238
1252
|
|
|
1253
|
+
### ๐ `listenForPaste()`
|
|
1254
|
+
|
|
1255
|
+
Handling Pasted Files and Text
|
|
1256
|
+
|
|
1257
|
+
```js
|
|
1258
|
+
element.listenForPaste({
|
|
1259
|
+
onFilePaste(item, file) {
|
|
1260
|
+
console.log("Pasted file:", file.name);
|
|
1261
|
+
},
|
|
1262
|
+
onTextPaste(item, text) {
|
|
1263
|
+
console.log("Pasted text:", text);
|
|
1264
|
+
},
|
|
1265
|
+
});
|
|
1266
|
+
```
|
|
1267
|
+
|
|
1268
|
+
Registers a listener for the `"paste"` event to extract files or plain text directly from the clipboard.
|
|
1269
|
+
|
|
1270
|
+
* `onFilePaste(item, file)` โ Triggered once for each file pasted (e.g., images or documents).
|
|
1271
|
+
* `onTextPaste(item, text)` โ Triggered when plain text is pasted.
|
|
1272
|
+
|
|
1273
|
+
Use this to build file dropzones, rich editors, or custom paste behavior.
|
|
1274
|
+
You can also use the static version for multiple elements:
|
|
1275
|
+
|
|
1276
|
+
```js
|
|
1277
|
+
TinyHtml.listenForPaste([el1, el2], {
|
|
1278
|
+
onFilePaste(item, file) {
|
|
1279
|
+
console.log("Pasted a file into multiple elements!");
|
|
1280
|
+
}
|
|
1281
|
+
});
|
|
1282
|
+
```
|
|
1283
|
+
|
|
1284
|
+
Returns the internal paste handler function.
|
|
1285
|
+
|
|
1286
|
+
---
|
|
1287
|
+
|
|
1288
|
+
### ๐ก `hasEventListener()`
|
|
1289
|
+
|
|
1290
|
+
Checking for Event Presence
|
|
1291
|
+
|
|
1292
|
+
```js
|
|
1293
|
+
if (element.hasEventListener("click")) {
|
|
1294
|
+
console.log("Click handler already registered.");
|
|
1295
|
+
}
|
|
1296
|
+
```
|
|
1297
|
+
|
|
1298
|
+
Checks whether any handler is currently registered on `__eventRegistry` for the given event name on an element.
|
|
1299
|
+
|
|
1300
|
+
* Returns `true` if any listener exists for the event, otherwise `false`.
|
|
1301
|
+
|
|
1302
|
+
Also available as a static version:
|
|
1303
|
+
|
|
1304
|
+
```js
|
|
1305
|
+
TinyHtml.hasEventListener(el, "paste");
|
|
1306
|
+
```
|
|
1307
|
+
|
|
1308
|
+
---
|
|
1309
|
+
|
|
1310
|
+
### ๐ฏ `hasExactEventListener()`
|
|
1311
|
+
|
|
1312
|
+
Checking for a Specific Handler
|
|
1313
|
+
|
|
1314
|
+
```js
|
|
1315
|
+
function onClick() {}
|
|
1316
|
+
element.on("click", onClick);
|
|
1317
|
+
|
|
1318
|
+
if (element.hasExactEventListener("click", onClick)) {
|
|
1319
|
+
console.log("The exact click handler is registered.");
|
|
1320
|
+
}
|
|
1321
|
+
```
|
|
1322
|
+
|
|
1323
|
+
Checks whether an element has **that exact function** registered on `__eventRegistry` for the given event.
|
|
1324
|
+
|
|
1325
|
+
* Returns `true` only if the same reference to the function is found.
|
|
1326
|
+
* Helps prevent duplicate listeners or for conditional removal logic.
|
|
1327
|
+
|
|
1328
|
+
Also available as a static version:
|
|
1329
|
+
|
|
1330
|
+
```js
|
|
1331
|
+
TinyHtml.hasExactEventListener(el, "click", onClick);
|
|
1332
|
+
```
|
|
1333
|
+
|
|
1334
|
+
---
|
|
1335
|
+
|
|
1239
1336
|
### ๐ฅ `on()` / `once()`
|
|
1240
1337
|
|
|
1241
1338
|
Registering Events
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
# ๐ฆ `TinyTextRangeEditor` Documentation
|
|
2
|
+
|
|
3
|
+
A lightweight but powerful text range utility class for `<input>` and `<textarea>` elements, ideal for building BBCode or other tag-based markup editors.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## ๐ Constructor
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
new TinyTextRangeEditor(element, options?)
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### Parameters:
|
|
14
|
+
|
|
15
|
+
* `element` **(HTMLInputElement | HTMLTextAreaElement)** โ Target editable element.
|
|
16
|
+
* `options` **(Object)** *(optional)* โ Customize tag delimiters.
|
|
17
|
+
|
|
18
|
+
* `openTag` **(string)** โ Default: `'['`
|
|
19
|
+
* `closeTag` **(string)** โ Default: `']'`
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## ๐ง Core Methods
|
|
24
|
+
|
|
25
|
+
### `getOpenTag()` โ `string`
|
|
26
|
+
|
|
27
|
+
Returns the current **opening tag symbol**.
|
|
28
|
+
|
|
29
|
+
### `getCloseTag()` โ `string`
|
|
30
|
+
|
|
31
|
+
Returns the current **closing tag symbol**.
|
|
32
|
+
|
|
33
|
+
### `setOpenTag(tag: string)`
|
|
34
|
+
|
|
35
|
+
Changes the **opening tag symbol**.
|
|
36
|
+
|
|
37
|
+
### `setCloseTag(tag: string)`
|
|
38
|
+
|
|
39
|
+
Changes the **closing tag symbol**.
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## ๐ฏ Selection & Focus
|
|
44
|
+
|
|
45
|
+
### `focus()` โ `this`
|
|
46
|
+
|
|
47
|
+
Focuses the target element.
|
|
48
|
+
|
|
49
|
+
### `ensureFocus()` โ `this`
|
|
50
|
+
|
|
51
|
+
Focuses the element only if not already focused.
|
|
52
|
+
|
|
53
|
+
### `getSelectionRange()` โ `{ start: number, end: number }`
|
|
54
|
+
|
|
55
|
+
Returns the current **text selection range**.
|
|
56
|
+
|
|
57
|
+
### `setSelectionRange(start, end, preserveScroll = true)` โ `this`
|
|
58
|
+
|
|
59
|
+
Sets the selection range.
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## ๐ Value Access
|
|
64
|
+
|
|
65
|
+
### `getValue()` โ `string`
|
|
66
|
+
|
|
67
|
+
Returns the entire value of the field.
|
|
68
|
+
|
|
69
|
+
### `setValue(value: string)` โ `this`
|
|
70
|
+
|
|
71
|
+
Sets the entire content.
|
|
72
|
+
|
|
73
|
+
### `getSelectedText()` โ `string`
|
|
74
|
+
|
|
75
|
+
Returns the currently selected text.
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## โ๏ธ Text Manipulation
|
|
80
|
+
|
|
81
|
+
### `insertText(text, options?)` โ `this`
|
|
82
|
+
|
|
83
|
+
Inserts (and replaces) text at selection.
|
|
84
|
+
|
|
85
|
+
#### Options:
|
|
86
|
+
|
|
87
|
+
* `newCursor`: `"start" | "end" | "preserve"` *(default: `'end'`)*
|
|
88
|
+
* `autoSpacing`: *(boolean)* Add space if needed on both sides.
|
|
89
|
+
* `autoSpaceLeft` / `autoSpaceRight`: *(boolean)* Fine-grained spacing control.
|
|
90
|
+
|
|
91
|
+
---
|
|
92
|
+
|
|
93
|
+
### `deleteSelection()` โ `this`
|
|
94
|
+
|
|
95
|
+
Deletes selected text.
|
|
96
|
+
|
|
97
|
+
### `transformSelection(fn)` โ `this`
|
|
98
|
+
|
|
99
|
+
Applies a transformation function to the selected text.
|
|
100
|
+
|
|
101
|
+
### `surroundSelection(prefix, suffix)` โ `this`
|
|
102
|
+
|
|
103
|
+
Wraps selected text with custom strings.
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
## ๐ช Tag Operations
|
|
108
|
+
|
|
109
|
+
### `wrapWithTag(tagName, attributes?)` โ `this`
|
|
110
|
+
|
|
111
|
+
Wraps the selection in a custom tag.
|
|
112
|
+
|
|
113
|
+
```js
|
|
114
|
+
editor.wrapWithTag("b");
|
|
115
|
+
editor.wrapWithTag("color", { value: "red" });
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### `insertTag(tagName, content?, attributes?)` โ `this`
|
|
119
|
+
|
|
120
|
+
Inserts an opening and closing tag with optional content.
|
|
121
|
+
|
|
122
|
+
```js
|
|
123
|
+
editor.insertTag("quote", "Hello!", { user: "Yasmin" });
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### `insertSelfClosingTag(tagName, attributes?)` โ `this`
|
|
127
|
+
|
|
128
|
+
Inserts a self-closing tag.
|
|
129
|
+
|
|
130
|
+
```js
|
|
131
|
+
editor.insertSelfClosingTag("br");
|
|
132
|
+
editor.insertSelfClosingTag("img", { src: "link.jpg", alt: "image" });
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### `toggleTag(tagName, attributes?)` โ `this`
|
|
136
|
+
|
|
137
|
+
Wraps or **unwraps** the selection with a tag.
|
|
138
|
+
|
|
139
|
+
```js
|
|
140
|
+
editor.toggleTag("b");
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### `toggleCode(codeName)` โ `this`
|
|
144
|
+
|
|
145
|
+
Wraps or **unwraps** the selection with a code.
|
|
146
|
+
|
|
147
|
+
```js
|
|
148
|
+
editor.toggleTag("**");
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
## ๐ง Utility
|
|
154
|
+
|
|
155
|
+
### `moveCaret(offset: number)` โ `this`
|
|
156
|
+
|
|
157
|
+
Moves the caret by an offset.
|
|
158
|
+
|
|
159
|
+
### `selectAll()` โ `this`
|
|
160
|
+
|
|
161
|
+
Selects all the content.
|
|
162
|
+
|
|
163
|
+
### `expandSelection(before, after)` โ `this`
|
|
164
|
+
|
|
165
|
+
Expands the selection range by the given number of characters.
|
|
166
|
+
|
|
167
|
+
### `replaceAll(regex, replacerFn)` โ `this`
|
|
168
|
+
|
|
169
|
+
Performs regex replacement over the full text.
|
|
170
|
+
|
|
171
|
+
---
|
|
172
|
+
|
|
173
|
+
### `replaceInSelection(regex, replacerFn)`
|
|
174
|
+
|
|
175
|
+
Replaces all matches of a regular expression **only within the currently selected text** in the editor.
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
## ๐งฉ Internal Attribute Helper
|
|
180
|
+
|
|
181
|
+
### `_insertAttr(attributes)` โ `string`
|
|
182
|
+
|
|
183
|
+
Serializes tag attributes to string format. Supports:
|
|
184
|
+
|
|
185
|
+
* โ
Object: `{ color: "red" } โ color="red"`
|
|
186
|
+
* โ
Array: `["checked", "readonly"] โ checked readonly`
|
|
187
|
+
|
|
188
|
+
---
|
|
189
|
+
|
|
190
|
+
## ๐งช Example Use
|
|
191
|
+
|
|
192
|
+
```js
|
|
193
|
+
const textarea = document.querySelector('textarea');
|
|
194
|
+
const editor = new TinyTextRangeEditor(textarea);
|
|
195
|
+
|
|
196
|
+
editor.wrapWithTag("b");
|
|
197
|
+
editor.insertTag("color", "red text", { color: "red" });
|
|
198
|
+
editor.insertSelfClosingTag("br");
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
---
|
|
202
|
+
|
|
203
|
+
## ๐ Notes
|
|
204
|
+
|
|
205
|
+
* All methods are **chainable** (`return this`)
|
|
206
|
+
* Throws detailed **TypeErrors** if used incorrectly
|
|
207
|
+
* Does **not** depend on any external library
|
|
208
|
+
* Useful for BBCode editors, markdown-like syntax, or custom in-text macros
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tiny-essentials",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.18.1",
|
|
4
4
|
"description": "Collection of small, essential scripts designed to be used across various projects. These simple utilities are crafted for speed, ease of use, and versatility.",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "npm run test:mjs && npm run test:cjs && npm run test:js",
|