@domternal/vue 0.10.0 → 0.11.0

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/index.js CHANGED
@@ -10,7 +10,7 @@ function useEditor(options = {}) {
10
10
  let pendingContent = null;
11
11
  function wireEvents(ed) {
12
12
  ed.on("transaction", ({ transaction }) => {
13
- if (transaction.docChanged) {
13
+ if (transaction.docChanged && !transaction.getMeta("skipUpdate")) {
14
14
  options.onUpdate?.({ editor: ed });
15
15
  }
16
16
  if (!transaction.docChanged && transaction.selectionSet) {
@@ -40,17 +40,19 @@ function useEditor(options = {}) {
40
40
  options.onCreate?.(ed);
41
41
  return ed;
42
42
  }
43
- function destroyCurrentEditor() {
43
+ function destroyCurrentEditor(insertClone = true) {
44
44
  const current = editor.value;
45
45
  if (current && !current.isDestroyed) {
46
46
  pendingContent = current.getJSON();
47
47
  options.onDestroy?.();
48
- const dom = current.view.dom;
49
- const parent = dom.parentNode;
50
- if (parent) {
51
- const clone = dom.cloneNode(true);
52
- clone.style.pointerEvents = "none";
53
- parent.insertBefore(clone, dom);
48
+ if (insertClone) {
49
+ const dom = current.view.dom;
50
+ const parent = dom.parentNode;
51
+ if (parent) {
52
+ const clone = dom.cloneNode(true);
53
+ clone.style.pointerEvents = "none";
54
+ parent.insertBefore(clone, dom);
55
+ }
54
56
  }
55
57
  current.destroy();
56
58
  }
@@ -61,7 +63,14 @@ function useEditor(options = {}) {
61
63
  createEditorInstance(element, options.content ?? "", options.autofocus ?? false);
62
64
  }
63
65
  onMounted(() => {
64
- if (editor.value) return;
66
+ const ed = editor.value;
67
+ if (ed) {
68
+ const mount = editorRef.value;
69
+ if (mount && ed.view.dom.parentElement !== mount) {
70
+ mount.appendChild(ed.view.dom);
71
+ }
72
+ return;
73
+ }
65
74
  const element = editorRef.value ?? document.createElement("div");
66
75
  const initialContent = pendingContent ?? options.content ?? "";
67
76
  pendingContent = null;
@@ -85,7 +94,7 @@ function useEditor(options = {}) {
85
94
  if (!editor.value || editor.value.isDestroyed) return;
86
95
  if (newExtensions === oldExtensions) return;
87
96
  const element = editor.value.view.dom.parentElement ?? document.createElement("div");
88
- destroyCurrentEditor();
97
+ destroyCurrentEditor(false);
89
98
  const initialContent = pendingContent ?? "";
90
99
  pendingContent = null;
91
100
  createEditorInstance(element, initialContent, false);