tiny-markdown-editor 0.2.32 → 0.2.34
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 +21 -0
- package/dist/tiny-mde.css +3 -4
- package/dist/tiny-mde.js +3940 -6353
- package/dist/tiny-mde.min.css +1 -1
- package/dist/tiny-mde.min.js +1 -1
- package/dist/tiny-mde.tiny.js +1 -1
- package/lib/TinyMDE.d.ts +17 -0
- package/lib/TinyMDE.js +80 -10
- package/lib/TinyMDECommandBar.d.ts +10 -0
- package/lib/TinyMDECommandBar.js +37 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -263,11 +263,32 @@ Here are some methods of the Editor object that might be useful in general inter
|
|
|
263
263
|
| `paste(text, anchor, focus)` | Pastes / inserts text over either the current selection (if `anchor` and `focus` are null or omitted) or a specific range (if `anchor` and `focus` are passed in in the format as returned by `getSelection()`). |
|
|
264
264
|
| `wrapSelection(pre, post, anchor, focus)` | Wraps the current selection (if `anchor` and `focus` are `null` or omitted) or a specific selection (if `anchor` and `focus` are given) in the strings `pre` and `post`. For example, `wrapSelection('[', '](https://www.github.com)')` will wrap the selection with a link to GitHub. Fires a `change` event (and updates the linked textarea, if any). Does nothing if the selection spans more than one line. |
|
|
265
265
|
| `addEventListener(type, listener)` | Adds an [event listener](#event-listeners) to the editor. `type` is a string denoting the type (`change` or `selection`), and `listener` is a function which takes one parameter, the event. |
|
|
266
|
+
| `removeEventListener(type, listener)` | Removes an [event listener](#event-listeners) previously added with `addEventListener()`. The `listener` has to be the same function object that was passed to `addEventListener()`. |
|
|
267
|
+
| `destroy()` | Tears the editor down: removes every event listener it registered (including the one on `document`, which would otherwise keep the editor alive for the lifetime of the page), removes the editor element if TinyMDE created it, and shows the linked textarea again. An editor element you passed in yourself is left in the DOM, emptied and restored to the state it was in before. Safe to call more than once; the editor must not be used afterwards. Does **not** destroy a linked CommandBar—see [below](#commandbar-methods). |
|
|
266
268
|
| `undo()` | Undoes the last action. |
|
|
267
269
|
| `redo()` | Redoes the last undone action. |
|
|
268
270
|
| `canUndo` | `true` if there is an action that can be undone |
|
|
269
271
|
| `canRedo` | `true` if there is an action that can be redone |
|
|
270
272
|
|
|
273
|
+
### CommandBar methods
|
|
274
|
+
|
|
275
|
+
| Method | Description |
|
|
276
|
+
| ----------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
277
|
+
| `setEditor(editor)` | Links the command bar to an editor, detaching it from the editor it was previously linked to (if any). |
|
|
278
|
+
| `destroy()` | Tears the command bar down: removes every event listener it registered (including the one on `document`), detaches from its editor, and removes the command bar element from the DOM. Safe to call more than once; the command bar must not be used afterwards. |
|
|
279
|
+
|
|
280
|
+
### Tearing down an editor
|
|
281
|
+
|
|
282
|
+
If you create and destroy editors repeatedly—for example in a component-based framework such as React, Vue or Svelte, where the component holding the editor is mounted and unmounted as the user navigates—call `destroy()` when you are done with an instance. Both `Editor` and `CommandBar` register listeners on `document` that live as long as the page does otherwise.
|
|
283
|
+
|
|
284
|
+
Editor and CommandBar are destroyed independently, so destroy both:
|
|
285
|
+
|
|
286
|
+
```js
|
|
287
|
+
// on unmount
|
|
288
|
+
commandBar.destroy();
|
|
289
|
+
editor.destroy();
|
|
290
|
+
```
|
|
291
|
+
|
|
271
292
|
### Event listeners
|
|
272
293
|
|
|
273
294
|
There are two event listener types that can be registered on the editor: `change` and `selection`.
|
package/dist/tiny-mde.css
CHANGED
|
@@ -153,14 +153,13 @@
|
|
|
153
153
|
|
|
154
154
|
.TMImage {
|
|
155
155
|
text-decoration: underline;
|
|
156
|
-
|
|
157
|
-
text-decoration-color: #00ff00;
|
|
156
|
+
text-decoration-color: #00ff00;
|
|
158
157
|
}
|
|
159
158
|
|
|
159
|
+
|
|
160
160
|
.TMLink {
|
|
161
161
|
text-decoration: underline;
|
|
162
|
-
|
|
163
|
-
text-decoration-color: #0000ff;
|
|
162
|
+
text-decoration-color: #0000ff;
|
|
164
163
|
}
|
|
165
164
|
|
|
166
165
|
.TMLinkLabel {
|