tiny-markdown-editor 0.2.32 → 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 +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/lib/TinyMDECommandBar.js
CHANGED
|
@@ -128,6 +128,9 @@ class CommandBar {
|
|
|
128
128
|
this.buttons = {};
|
|
129
129
|
this.state = {};
|
|
130
130
|
this.hotkeys = [];
|
|
131
|
+
this.cleanupFns = [];
|
|
132
|
+
this.detachEditor = null;
|
|
133
|
+
this.destroyed = false;
|
|
131
134
|
this.e = null;
|
|
132
135
|
this.editor = null;
|
|
133
136
|
this.commands = {};
|
|
@@ -167,7 +170,7 @@ class CommandBar {
|
|
|
167
170
|
"insertLink",
|
|
168
171
|
"insertImage",
|
|
169
172
|
]);
|
|
170
|
-
|
|
173
|
+
this.addListener(document, "keydown", (e) => this.handleKeydown(e));
|
|
171
174
|
if (props.editor)
|
|
172
175
|
this.setEditor(props.editor);
|
|
173
176
|
}
|
|
@@ -274,7 +277,7 @@ class CommandBar {
|
|
|
274
277
|
this.buttons[commandName].className = "TMCommandButton TMCommandButton_Disabled";
|
|
275
278
|
this.buttons[commandName].title = title;
|
|
276
279
|
this.buttons[commandName].innerHTML = this.commands[commandName].innerHTML || "?";
|
|
277
|
-
this.buttons[commandName]
|
|
280
|
+
this.addListener(this.buttons[commandName], "mousedown", (e) => this.handleClick(commandName, e));
|
|
278
281
|
this.e.appendChild(this.buttons[commandName]);
|
|
279
282
|
}
|
|
280
283
|
}
|
|
@@ -304,8 +307,12 @@ class CommandBar {
|
|
|
304
307
|
}
|
|
305
308
|
}
|
|
306
309
|
setEditor(editor) {
|
|
310
|
+
if (this.detachEditor)
|
|
311
|
+
this.detachEditor();
|
|
307
312
|
this.editor = editor;
|
|
308
|
-
|
|
313
|
+
const handler = (e) => this.handleSelection(e);
|
|
314
|
+
editor.addEventListener("selection", handler);
|
|
315
|
+
this.detachEditor = () => editor.removeEventListener("selection", handler);
|
|
309
316
|
}
|
|
310
317
|
handleSelection(event) {
|
|
311
318
|
if (event.commandState) {
|
|
@@ -351,6 +358,33 @@ class CommandBar {
|
|
|
351
358
|
}
|
|
352
359
|
}
|
|
353
360
|
}
|
|
361
|
+
addListener(target, type, handler) {
|
|
362
|
+
target.addEventListener(type, handler);
|
|
363
|
+
this.cleanupFns.push(() => target.removeEventListener(type, handler));
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Removes all listeners registered by this instance, including the document-level keydown
|
|
367
|
+
* listener and the selection listener on its editor, and detaches the command bar element.
|
|
368
|
+
* Safe to call multiple times.
|
|
369
|
+
*/
|
|
370
|
+
destroy() {
|
|
371
|
+
if (this.destroyed)
|
|
372
|
+
return;
|
|
373
|
+
this.destroyed = true;
|
|
374
|
+
if (this.detachEditor) {
|
|
375
|
+
this.detachEditor();
|
|
376
|
+
this.detachEditor = null;
|
|
377
|
+
}
|
|
378
|
+
for (const cleanup of this.cleanupFns)
|
|
379
|
+
cleanup();
|
|
380
|
+
this.cleanupFns = [];
|
|
381
|
+
if (this.e && this.e.parentNode) {
|
|
382
|
+
this.e.parentNode.removeChild(this.e);
|
|
383
|
+
}
|
|
384
|
+
this.editor = null;
|
|
385
|
+
this.e = null;
|
|
386
|
+
this.buttons = {};
|
|
387
|
+
}
|
|
354
388
|
}
|
|
355
389
|
exports.CommandBar = CommandBar;
|
|
356
390
|
exports.default = CommandBar;
|