tiny-markdown-editor 0.2.31 → 0.2.33

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
@@ -261,13 +261,34 @@ Here are some methods of the Editor object that might be useful in general inter
261
261
  | `getSelection(getAnchor)` | Gets the current selection / cursor position inside the editor. The parameter `getAnchor` (defaults to false) determines if the anchor (starting point) of the selection should be returned—if `getAnchor` is false (or omitted), the focus (end point) is returned, otherwise the starting point. If the selection is not inside the editor, `null` is returned. The method returns an object with the attributes `row` and `col` which contain the zero-based row (line) and column number of the selection position. |
262
262
  | `setSelection(focus, anchor)` | Sets the selection within the editor. The parameters `focus` and `offset` are both of the format returned by `getSelection()` (containing attributes `row` and `col`). If `anchor` is `null` or omitted, a single-point selection (cursor position) will be set. |
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
- | `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. |
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
@@ -5,7 +5,15 @@
5
5
  line-height:24px;
6
6
  outline: none;
7
7
  padding:5px;
8
- height: 100%;
8
+ /* Count the padding towards the height below, so a fixed-height container
9
+ doesn't end up 10px short of fitting its own editor. Also makes the box
10
+ behave the same whether or not the embedding page has a border-box reset. */
11
+ box-sizing: border-box;
12
+ /* min-height rather than height so the editor fills a fixed-height container
13
+ when it's near-empty, but still grows with the content when it overflows.
14
+ With height:100% the box stayed at the container's height and the
15
+ background stopped painting at the fold (#182). */
16
+ min-height: 100%;
9
17
  }
10
18
 
11
19
  .TinyMDE.TinyMDE_empty {
@@ -145,14 +153,13 @@
145
153
 
146
154
  .TMImage {
147
155
  text-decoration: underline;
148
- -webkit-text-decoration-color: #00ff00;
149
- text-decoration-color: #00ff00;
156
+ text-decoration-color: #00ff00;
150
157
  }
151
158
 
159
+
152
160
  .TMLink {
153
161
  text-decoration: underline;
154
- -webkit-text-decoration-color: #0000ff;
155
- text-decoration-color: #0000ff;
162
+ text-decoration-color: #0000ff;
156
163
  }
157
164
 
158
165
  .TMLinkLabel {