@tiptap/vue-3 2.5.0-beta.2 → 2.5.0-beta.4

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.
Files changed (188) hide show
  1. package/dist/index.cjs +453 -447
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.js +453 -445
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.umd.js +453 -447
  6. package/dist/index.umd.js.map +1 -1
  7. package/dist/packages/core/src/CommandManager.d.ts +20 -0
  8. package/dist/packages/core/src/Editor.d.ts +161 -0
  9. package/dist/packages/core/src/EventEmitter.d.ts +11 -0
  10. package/dist/packages/core/src/Extension.d.ts +343 -0
  11. package/dist/packages/core/src/ExtensionManager.d.ts +55 -0
  12. package/dist/packages/core/src/InputRule.d.ts +42 -0
  13. package/dist/packages/core/src/Mark.d.ts +451 -0
  14. package/dist/packages/core/src/Node.d.ts +611 -0
  15. package/dist/packages/core/src/NodePos.d.ts +44 -0
  16. package/dist/packages/core/src/NodeView.d.ts +31 -0
  17. package/dist/packages/core/src/PasteRule.d.ts +50 -0
  18. package/dist/packages/core/src/Tracker.d.ts +11 -0
  19. package/dist/packages/core/src/commands/blur.d.ts +13 -0
  20. package/dist/packages/core/src/commands/clearContent.d.ts +14 -0
  21. package/dist/packages/core/src/commands/clearNodes.d.ts +13 -0
  22. package/dist/packages/core/src/commands/command.d.ts +18 -0
  23. package/dist/packages/core/src/commands/createParagraphNear.d.ts +13 -0
  24. package/dist/packages/core/src/commands/cut.d.ts +20 -0
  25. package/dist/packages/core/src/commands/deleteCurrentNode.d.ts +13 -0
  26. package/dist/packages/core/src/commands/deleteNode.d.ts +15 -0
  27. package/dist/packages/core/src/commands/deleteRange.d.ts +14 -0
  28. package/dist/packages/core/src/commands/deleteSelection.d.ts +13 -0
  29. package/dist/packages/core/src/commands/enter.d.ts +13 -0
  30. package/dist/packages/core/src/commands/exitCode.d.ts +13 -0
  31. package/dist/packages/core/src/commands/extendMarkRange.d.ts +25 -0
  32. package/dist/packages/core/src/commands/first.d.ts +14 -0
  33. package/dist/packages/core/src/commands/focus.d.ts +27 -0
  34. package/dist/packages/core/src/commands/forEach.d.ts +14 -0
  35. package/dist/packages/core/src/commands/index.d.ts +55 -0
  36. package/dist/packages/core/src/commands/insertContent.d.ts +34 -0
  37. package/dist/packages/core/src/commands/insertContentAt.d.ts +47 -0
  38. package/dist/packages/core/src/commands/join.d.ts +41 -0
  39. package/dist/packages/core/src/commands/joinItemBackward.d.ts +13 -0
  40. package/dist/packages/core/src/commands/joinItemForward.d.ts +13 -0
  41. package/dist/packages/core/src/commands/joinTextblockBackward.d.ts +12 -0
  42. package/dist/packages/core/src/commands/joinTextblockForward.d.ts +12 -0
  43. package/dist/packages/core/src/commands/keyboardShortcut.d.ts +14 -0
  44. package/dist/packages/core/src/commands/lift.d.ts +17 -0
  45. package/dist/packages/core/src/commands/liftEmptyBlock.d.ts +13 -0
  46. package/dist/packages/core/src/commands/liftListItem.d.ts +15 -0
  47. package/dist/packages/core/src/commands/newlineInCode.d.ts +13 -0
  48. package/dist/packages/core/src/commands/resetAttributes.d.ts +16 -0
  49. package/dist/packages/core/src/commands/scrollIntoView.d.ts +13 -0
  50. package/dist/packages/core/src/commands/selectAll.d.ts +13 -0
  51. package/dist/packages/core/src/commands/selectNodeBackward.d.ts +13 -0
  52. package/dist/packages/core/src/commands/selectNodeForward.d.ts +13 -0
  53. package/dist/packages/core/src/commands/selectParentNode.d.ts +13 -0
  54. package/dist/packages/core/src/commands/selectTextblockEnd.d.ts +13 -0
  55. package/dist/packages/core/src/commands/selectTextblockStart.d.ts +13 -0
  56. package/dist/packages/core/src/commands/setContent.d.ts +40 -0
  57. package/dist/packages/core/src/commands/setMark.d.ts +15 -0
  58. package/dist/packages/core/src/commands/setMeta.d.ts +15 -0
  59. package/dist/packages/core/src/commands/setNode.d.ts +16 -0
  60. package/dist/packages/core/src/commands/setNodeSelection.d.ts +14 -0
  61. package/dist/packages/core/src/commands/setTextSelection.d.ts +14 -0
  62. package/dist/packages/core/src/commands/sinkListItem.d.ts +15 -0
  63. package/dist/packages/core/src/commands/splitBlock.d.ts +17 -0
  64. package/dist/packages/core/src/commands/splitListItem.d.ts +15 -0
  65. package/dist/packages/core/src/commands/toggleList.d.ts +18 -0
  66. package/dist/packages/core/src/commands/toggleMark.d.ts +30 -0
  67. package/dist/packages/core/src/commands/toggleNode.d.ts +17 -0
  68. package/dist/packages/core/src/commands/toggleWrap.d.ts +16 -0
  69. package/dist/packages/core/src/commands/undoInputRule.d.ts +13 -0
  70. package/dist/packages/core/src/commands/unsetAllMarks.d.ts +13 -0
  71. package/dist/packages/core/src/commands/unsetMark.d.ts +25 -0
  72. package/dist/packages/core/src/commands/updateAttributes.d.ts +24 -0
  73. package/dist/packages/core/src/commands/wrapIn.d.ts +16 -0
  74. package/dist/packages/core/src/commands/wrapInList.d.ts +16 -0
  75. package/dist/packages/core/src/extensions/clipboardTextSerializer.d.ts +5 -0
  76. package/dist/packages/core/src/extensions/commands.d.ts +3 -0
  77. package/dist/packages/core/src/extensions/editable.d.ts +2 -0
  78. package/dist/packages/core/src/extensions/focusEvents.d.ts +2 -0
  79. package/dist/packages/core/src/extensions/index.d.ts +6 -0
  80. package/dist/packages/core/src/extensions/keymap.d.ts +2 -0
  81. package/dist/packages/core/src/extensions/tabindex.d.ts +2 -0
  82. package/dist/packages/core/src/helpers/combineTransactionSteps.d.ts +10 -0
  83. package/dist/packages/core/src/helpers/createChainableState.d.ts +10 -0
  84. package/dist/packages/core/src/helpers/createDocument.d.ts +12 -0
  85. package/dist/packages/core/src/helpers/createNodeFromContent.d.ts +15 -0
  86. package/dist/packages/core/src/helpers/defaultBlockAt.d.ts +7 -0
  87. package/dist/packages/core/src/helpers/findChildren.d.ts +9 -0
  88. package/dist/packages/core/src/helpers/findChildrenInRange.d.ts +10 -0
  89. package/dist/packages/core/src/helpers/findParentNode.d.ts +16 -0
  90. package/dist/packages/core/src/helpers/findParentNodeClosestToPos.d.ts +17 -0
  91. package/dist/packages/core/src/helpers/generateHTML.d.ts +8 -0
  92. package/dist/packages/core/src/helpers/generateJSON.d.ts +8 -0
  93. package/dist/packages/core/src/helpers/generateText.d.ts +12 -0
  94. package/dist/packages/core/src/helpers/getAttributes.d.ts +9 -0
  95. package/dist/packages/core/src/helpers/getAttributesFromExtensions.d.ts +6 -0
  96. package/dist/packages/core/src/helpers/getChangedRanges.d.ts +11 -0
  97. package/dist/packages/core/src/helpers/getDebugJSON.d.ts +8 -0
  98. package/dist/packages/core/src/helpers/getExtensionField.d.ts +9 -0
  99. package/dist/packages/core/src/helpers/getHTMLFromFragment.d.ts +2 -0
  100. package/dist/packages/core/src/helpers/getMarkAttributes.d.ts +3 -0
  101. package/dist/packages/core/src/helpers/getMarkRange.d.ts +3 -0
  102. package/dist/packages/core/src/helpers/getMarkType.d.ts +2 -0
  103. package/dist/packages/core/src/helpers/getMarksBetween.d.ts +3 -0
  104. package/dist/packages/core/src/helpers/getNodeAtPosition.d.ts +11 -0
  105. package/dist/packages/core/src/helpers/getNodeAttributes.d.ts +3 -0
  106. package/dist/packages/core/src/helpers/getNodeType.d.ts +2 -0
  107. package/dist/packages/core/src/helpers/getRenderedAttributes.d.ts +3 -0
  108. package/dist/packages/core/src/helpers/getSchema.d.ts +4 -0
  109. package/dist/packages/core/src/helpers/getSchemaByResolvedExtensions.d.ts +10 -0
  110. package/dist/packages/core/src/helpers/getSchemaTypeByName.d.ts +8 -0
  111. package/dist/packages/core/src/helpers/getSchemaTypeNameByName.d.ts +8 -0
  112. package/dist/packages/core/src/helpers/getSplittedAttributes.d.ts +9 -0
  113. package/dist/packages/core/src/helpers/getText.d.ts +15 -0
  114. package/dist/packages/core/src/helpers/getTextBetween.d.ts +14 -0
  115. package/dist/packages/core/src/helpers/getTextContentFromNodes.d.ts +8 -0
  116. package/dist/packages/core/src/helpers/getTextSerializersFromSchema.d.ts +8 -0
  117. package/dist/packages/core/src/helpers/index.d.ts +50 -0
  118. package/dist/packages/core/src/helpers/injectExtensionAttributesToParseRule.d.ts +9 -0
  119. package/dist/packages/core/src/helpers/isActive.d.ts +2 -0
  120. package/dist/packages/core/src/helpers/isAtEndOfNode.d.ts +2 -0
  121. package/dist/packages/core/src/helpers/isAtStartOfNode.d.ts +2 -0
  122. package/dist/packages/core/src/helpers/isExtensionRulesEnabled.d.ts +2 -0
  123. package/dist/packages/core/src/helpers/isList.d.ts +2 -0
  124. package/dist/packages/core/src/helpers/isMarkActive.d.ts +3 -0
  125. package/dist/packages/core/src/helpers/isNodeActive.d.ts +3 -0
  126. package/dist/packages/core/src/helpers/isNodeEmpty.d.ts +2 -0
  127. package/dist/packages/core/src/helpers/isNodeSelection.d.ts +2 -0
  128. package/dist/packages/core/src/helpers/isTextSelection.d.ts +2 -0
  129. package/dist/packages/core/src/helpers/posToDOMRect.d.ts +2 -0
  130. package/dist/packages/core/src/helpers/resolveFocusPosition.d.ts +4 -0
  131. package/dist/packages/core/src/helpers/selectionToInsertionEnd.d.ts +2 -0
  132. package/dist/packages/core/src/helpers/splitExtensions.d.ts +9 -0
  133. package/dist/packages/core/src/index.d.ts +24 -0
  134. package/dist/packages/core/src/inputRules/index.d.ts +5 -0
  135. package/dist/packages/core/src/inputRules/markInputRule.d.ts +13 -0
  136. package/dist/packages/core/src/inputRules/nodeInputRule.d.ts +23 -0
  137. package/dist/packages/core/src/inputRules/textInputRule.d.ts +10 -0
  138. package/dist/packages/core/src/inputRules/textblockTypeInputRule.d.ts +15 -0
  139. package/dist/packages/core/src/inputRules/wrappingInputRule.d.ts +28 -0
  140. package/dist/packages/core/src/pasteRules/index.d.ts +3 -0
  141. package/dist/packages/core/src/pasteRules/markPasteRule.d.ts +13 -0
  142. package/dist/packages/core/src/pasteRules/nodePasteRule.d.ts +13 -0
  143. package/dist/packages/core/src/pasteRules/textPasteRule.d.ts +10 -0
  144. package/dist/packages/core/src/style.d.ts +1 -0
  145. package/dist/packages/core/src/types.d.ts +250 -0
  146. package/dist/packages/core/src/utilities/callOrReturn.d.ts +9 -0
  147. package/dist/packages/core/src/utilities/createStyleTag.d.ts +1 -0
  148. package/dist/packages/core/src/utilities/deleteProps.d.ts +6 -0
  149. package/dist/packages/core/src/utilities/elementFromString.d.ts +1 -0
  150. package/dist/packages/core/src/utilities/escapeForRegEx.d.ts +1 -0
  151. package/dist/packages/core/src/utilities/findDuplicates.d.ts +1 -0
  152. package/dist/packages/core/src/utilities/fromString.d.ts +1 -0
  153. package/dist/packages/core/src/utilities/index.d.ts +20 -0
  154. package/dist/packages/core/src/utilities/isAndroid.d.ts +1 -0
  155. package/dist/packages/core/src/utilities/isEmptyObject.d.ts +1 -0
  156. package/dist/packages/core/src/utilities/isFunction.d.ts +1 -0
  157. package/dist/packages/core/src/utilities/isMacOS.d.ts +1 -0
  158. package/dist/packages/core/src/utilities/isNumber.d.ts +1 -0
  159. package/dist/packages/core/src/utilities/isPlainObject.d.ts +1 -0
  160. package/dist/packages/core/src/utilities/isRegExp.d.ts +1 -0
  161. package/dist/packages/core/src/utilities/isString.d.ts +1 -0
  162. package/dist/packages/core/src/utilities/isiOS.d.ts +1 -0
  163. package/dist/packages/core/src/utilities/mergeAttributes.d.ts +1 -0
  164. package/dist/packages/core/src/utilities/mergeDeep.d.ts +1 -0
  165. package/dist/packages/core/src/utilities/minMax.d.ts +1 -0
  166. package/dist/packages/core/src/utilities/objectIncludes.d.ts +8 -0
  167. package/dist/packages/core/src/utilities/removeDuplicates.d.ts +8 -0
  168. package/dist/packages/extension-bubble-menu/src/bubble-menu-plugin.d.ts +76 -0
  169. package/dist/packages/extension-bubble-menu/src/bubble-menu.d.ts +15 -0
  170. package/dist/packages/extension-bubble-menu/src/index.d.ts +4 -0
  171. package/dist/packages/extension-floating-menu/src/floating-menu-plugin.d.ts +66 -0
  172. package/dist/packages/extension-floating-menu/src/floating-menu.d.ts +15 -0
  173. package/dist/packages/extension-floating-menu/src/index.d.ts +4 -0
  174. package/dist/packages/vue-3/src/BubbleMenu.d.ts +72 -72
  175. package/dist/packages/vue-3/src/Editor.d.ts +23 -24
  176. package/dist/packages/vue-3/src/EditorContent.d.ts +17 -17
  177. package/dist/packages/vue-3/src/FloatingMenu.d.ts +57 -57
  178. package/dist/packages/vue-3/src/NodeViewContent.d.ts +13 -13
  179. package/dist/packages/vue-3/src/NodeViewWrapper.d.ts +13 -13
  180. package/dist/packages/vue-3/src/VueNodeViewRenderer.d.ts +48 -48
  181. package/dist/packages/vue-3/src/VueRenderer.d.ts +36 -22
  182. package/dist/packages/vue-3/src/index.d.ts +10 -10
  183. package/dist/packages/vue-3/src/useEditor.d.ts +3 -3
  184. package/package.json +5 -5
  185. package/src/Editor.ts +3 -5
  186. package/src/EditorContent.ts +12 -26
  187. package/src/VueNodeViewRenderer.ts +7 -3
  188. package/src/VueRenderer.ts +32 -17
package/dist/index.umd.js CHANGED
@@ -4,466 +4,474 @@
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@tiptap/vue-3"] = {}, global.extensionBubbleMenu, global.vue, global.core, global.extensionFloatingMenu));
5
5
  })(this, (function (exports, extensionBubbleMenu, vue, core, extensionFloatingMenu) { 'use strict';
6
6
 
7
- const BubbleMenu = vue.defineComponent({
8
- name: 'BubbleMenu',
9
- props: {
10
- pluginKey: {
11
- type: [String, Object],
12
- default: 'bubbleMenu',
13
- },
14
- editor: {
15
- type: Object,
16
- required: true,
17
- },
18
- updateDelay: {
19
- type: Number,
20
- default: undefined,
21
- },
22
- tippyOptions: {
23
- type: Object,
24
- default: () => ({}),
25
- },
26
- shouldShow: {
27
- type: Function,
28
- default: null,
29
- },
30
- },
31
- setup(props, { slots }) {
32
- const root = vue.ref(null);
33
- vue.onMounted(() => {
34
- const { updateDelay, editor, pluginKey, shouldShow, tippyOptions, } = props;
35
- editor.registerPlugin(extensionBubbleMenu.BubbleMenuPlugin({
36
- updateDelay,
37
- editor,
38
- element: root.value,
39
- pluginKey,
40
- shouldShow,
41
- tippyOptions,
42
- }));
43
- });
44
- vue.onBeforeUnmount(() => {
45
- const { pluginKey, editor } = props;
46
- editor.unregisterPlugin(pluginKey);
47
- });
48
- return () => { var _a; return vue.h('div', { ref: root }, (_a = slots.default) === null || _a === void 0 ? void 0 : _a.call(slots)); };
49
- },
7
+ const BubbleMenu = vue.defineComponent({
8
+ name: 'BubbleMenu',
9
+ props: {
10
+ pluginKey: {
11
+ type: [String, Object],
12
+ default: 'bubbleMenu',
13
+ },
14
+ editor: {
15
+ type: Object,
16
+ required: true,
17
+ },
18
+ updateDelay: {
19
+ type: Number,
20
+ default: undefined,
21
+ },
22
+ tippyOptions: {
23
+ type: Object,
24
+ default: () => ({}),
25
+ },
26
+ shouldShow: {
27
+ type: Function,
28
+ default: null,
29
+ },
30
+ },
31
+ setup(props, { slots }) {
32
+ const root = vue.ref(null);
33
+ vue.onMounted(() => {
34
+ const { updateDelay, editor, pluginKey, shouldShow, tippyOptions, } = props;
35
+ editor.registerPlugin(extensionBubbleMenu.BubbleMenuPlugin({
36
+ updateDelay,
37
+ editor,
38
+ element: root.value,
39
+ pluginKey,
40
+ shouldShow,
41
+ tippyOptions,
42
+ }));
43
+ });
44
+ vue.onBeforeUnmount(() => {
45
+ const { pluginKey, editor } = props;
46
+ editor.unregisterPlugin(pluginKey);
47
+ });
48
+ return () => { var _a; return vue.h('div', { ref: root }, (_a = slots.default) === null || _a === void 0 ? void 0 : _a.call(slots)); };
49
+ },
50
50
  });
51
51
 
52
- function useDebouncedRef(value) {
53
- return vue.customRef((track, trigger) => {
54
- return {
55
- get() {
56
- track();
57
- return value;
58
- },
59
- set(newValue) {
60
- // update state
61
- value = newValue;
62
- // update view as soon as possible
63
- requestAnimationFrame(() => {
64
- requestAnimationFrame(() => {
65
- trigger();
66
- });
67
- });
68
- },
69
- };
70
- });
71
- }
72
- class Editor extends core.Editor {
73
- constructor(options = {}) {
74
- super(options);
75
- this.vueRenderers = vue.reactive(new Map());
76
- this.contentComponent = null;
77
- this.reactiveState = useDebouncedRef(this.view.state);
78
- this.reactiveExtensionStorage = useDebouncedRef(this.extensionStorage);
79
- this.on('transaction', () => {
80
- this.reactiveState.value = this.view.state;
81
- this.reactiveExtensionStorage.value = this.extensionStorage;
82
- });
83
- return vue.markRaw(this); // eslint-disable-line
84
- }
85
- get state() {
86
- return this.reactiveState ? this.reactiveState.value : this.view.state;
87
- }
88
- get storage() {
89
- return this.reactiveExtensionStorage ? this.reactiveExtensionStorage.value : super.storage;
90
- }
91
- /**
92
- * Register a ProseMirror plugin.
93
- */
94
- registerPlugin(plugin, handlePlugins) {
95
- super.registerPlugin(plugin, handlePlugins);
96
- this.reactiveState.value = this.view.state;
97
- }
98
- /**
99
- * Unregister a ProseMirror plugin.
100
- */
101
- unregisterPlugin(nameOrPluginKey) {
102
- super.unregisterPlugin(nameOrPluginKey);
103
- this.reactiveState.value = this.view.state;
104
- }
52
+ function useDebouncedRef(value) {
53
+ return vue.customRef((track, trigger) => {
54
+ return {
55
+ get() {
56
+ track();
57
+ return value;
58
+ },
59
+ set(newValue) {
60
+ // update state
61
+ value = newValue;
62
+ // update view as soon as possible
63
+ requestAnimationFrame(() => {
64
+ requestAnimationFrame(() => {
65
+ trigger();
66
+ });
67
+ });
68
+ },
69
+ };
70
+ });
71
+ }
72
+ class Editor extends core.Editor {
73
+ constructor(options = {}) {
74
+ super(options);
75
+ this.contentComponent = null;
76
+ this.appContext = null;
77
+ this.reactiveState = useDebouncedRef(this.view.state);
78
+ this.reactiveExtensionStorage = useDebouncedRef(this.extensionStorage);
79
+ this.on('transaction', () => {
80
+ this.reactiveState.value = this.view.state;
81
+ this.reactiveExtensionStorage.value = this.extensionStorage;
82
+ });
83
+ return vue.markRaw(this); // eslint-disable-line
84
+ }
85
+ get state() {
86
+ return this.reactiveState ? this.reactiveState.value : this.view.state;
87
+ }
88
+ get storage() {
89
+ return this.reactiveExtensionStorage ? this.reactiveExtensionStorage.value : super.storage;
90
+ }
91
+ /**
92
+ * Register a ProseMirror plugin.
93
+ */
94
+ registerPlugin(plugin, handlePlugins) {
95
+ super.registerPlugin(plugin, handlePlugins);
96
+ this.reactiveState.value = this.view.state;
97
+ }
98
+ /**
99
+ * Unregister a ProseMirror plugin.
100
+ */
101
+ unregisterPlugin(nameOrPluginKey) {
102
+ super.unregisterPlugin(nameOrPluginKey);
103
+ this.reactiveState.value = this.view.state;
104
+ }
105
105
  }
106
106
 
107
- const EditorContent = vue.defineComponent({
108
- name: 'EditorContent',
109
- props: {
110
- editor: {
111
- default: null,
112
- type: Object,
113
- },
114
- },
115
- setup(props) {
116
- const rootEl = vue.ref();
117
- const instance = vue.getCurrentInstance();
118
- vue.watchEffect(() => {
119
- const editor = props.editor;
120
- if (editor && editor.options.element && rootEl.value) {
121
- vue.nextTick(() => {
122
- if (!rootEl.value || !editor.options.element.firstChild) {
123
- return;
124
- }
125
- const element = vue.unref(rootEl.value);
126
- rootEl.value.append(...editor.options.element.childNodes);
127
- // @ts-ignore
128
- editor.contentComponent = instance.ctx._;
129
- editor.setOptions({
130
- element,
131
- });
132
- editor.createNodeViews();
133
- });
134
- }
135
- });
136
- vue.onBeforeUnmount(() => {
137
- const editor = props.editor;
138
- if (!editor) {
139
- return;
140
- }
141
- // destroy nodeviews before vue removes dom element
142
- if (!editor.isDestroyed) {
143
- editor.view.setProps({
144
- nodeViews: {},
145
- });
146
- }
147
- editor.contentComponent = null;
148
- if (!editor.options.element.firstChild) {
149
- return;
150
- }
151
- const newElement = document.createElement('div');
152
- newElement.append(...editor.options.element.childNodes);
153
- editor.setOptions({
154
- element: newElement,
155
- });
156
- });
157
- return { rootEl };
158
- },
159
- render() {
160
- const vueRenderers = [];
161
- if (this.editor) {
162
- this.editor.vueRenderers.forEach(vueRenderer => {
163
- const node = vue.h(vue.Teleport, {
164
- to: vueRenderer.teleportElement,
165
- key: vueRenderer.id,
166
- }, vue.h(vueRenderer.component, {
167
- ref: vueRenderer.id,
168
- ...vueRenderer.props,
169
- }));
170
- vueRenderers.push(node);
171
- });
172
- }
173
- return vue.h('div', {
174
- ref: (el) => { this.rootEl = el; },
175
- }, ...vueRenderers);
176
- },
107
+ const EditorContent = vue.defineComponent({
108
+ name: 'EditorContent',
109
+ props: {
110
+ editor: {
111
+ default: null,
112
+ type: Object,
113
+ },
114
+ },
115
+ setup(props) {
116
+ const rootEl = vue.ref();
117
+ const instance = vue.getCurrentInstance();
118
+ vue.watchEffect(() => {
119
+ const editor = props.editor;
120
+ if (editor && editor.options.element && rootEl.value) {
121
+ vue.nextTick(() => {
122
+ if (!rootEl.value || !editor.options.element.firstChild) {
123
+ return;
124
+ }
125
+ const element = vue.unref(rootEl.value);
126
+ rootEl.value.append(...editor.options.element.childNodes);
127
+ // @ts-ignore
128
+ editor.contentComponent = instance.ctx._;
129
+ if (instance) {
130
+ editor.appContext = {
131
+ ...instance.appContext,
132
+ provides: {
133
+ // @ts-ignore
134
+ ...instance.provides,
135
+ ...instance.appContext.provides,
136
+ },
137
+ };
138
+ }
139
+ editor.setOptions({
140
+ element,
141
+ });
142
+ editor.createNodeViews();
143
+ });
144
+ }
145
+ });
146
+ vue.onBeforeUnmount(() => {
147
+ const editor = props.editor;
148
+ if (!editor) {
149
+ return;
150
+ }
151
+ // destroy nodeviews before vue removes dom element
152
+ if (!editor.isDestroyed) {
153
+ editor.view.setProps({
154
+ nodeViews: {},
155
+ });
156
+ }
157
+ editor.contentComponent = null;
158
+ editor.appContext = null;
159
+ if (!editor.options.element.firstChild) {
160
+ return;
161
+ }
162
+ const newElement = document.createElement('div');
163
+ newElement.append(...editor.options.element.childNodes);
164
+ editor.setOptions({
165
+ element: newElement,
166
+ });
167
+ });
168
+ return { rootEl };
169
+ },
170
+ render() {
171
+ return vue.h('div', {
172
+ ref: (el) => { this.rootEl = el; },
173
+ });
174
+ },
177
175
  });
178
176
 
179
- const FloatingMenu = vue.defineComponent({
180
- name: 'FloatingMenu',
181
- props: {
182
- pluginKey: {
183
- // TODO: TypeScript breaks :(
184
- // type: [String, Object as PropType<Exclude<FloatingMenuPluginProps['pluginKey'], string>>],
185
- type: null,
186
- default: 'floatingMenu',
187
- },
188
- editor: {
189
- type: Object,
190
- required: true,
191
- },
192
- tippyOptions: {
193
- type: Object,
194
- default: () => ({}),
195
- },
196
- shouldShow: {
197
- type: Function,
198
- default: null,
199
- },
200
- },
201
- setup(props, { slots }) {
202
- const root = vue.ref(null);
203
- vue.onMounted(() => {
204
- const { pluginKey, editor, tippyOptions, shouldShow, } = props;
205
- editor.registerPlugin(extensionFloatingMenu.FloatingMenuPlugin({
206
- pluginKey,
207
- editor,
208
- element: root.value,
209
- tippyOptions,
210
- shouldShow,
211
- }));
212
- });
213
- vue.onBeforeUnmount(() => {
214
- const { pluginKey, editor } = props;
215
- editor.unregisterPlugin(pluginKey);
216
- });
217
- return () => { var _a; return vue.h('div', { ref: root }, (_a = slots.default) === null || _a === void 0 ? void 0 : _a.call(slots)); };
218
- },
177
+ const FloatingMenu = vue.defineComponent({
178
+ name: 'FloatingMenu',
179
+ props: {
180
+ pluginKey: {
181
+ // TODO: TypeScript breaks :(
182
+ // type: [String, Object as PropType<Exclude<FloatingMenuPluginProps['pluginKey'], string>>],
183
+ type: null,
184
+ default: 'floatingMenu',
185
+ },
186
+ editor: {
187
+ type: Object,
188
+ required: true,
189
+ },
190
+ tippyOptions: {
191
+ type: Object,
192
+ default: () => ({}),
193
+ },
194
+ shouldShow: {
195
+ type: Function,
196
+ default: null,
197
+ },
198
+ },
199
+ setup(props, { slots }) {
200
+ const root = vue.ref(null);
201
+ vue.onMounted(() => {
202
+ const { pluginKey, editor, tippyOptions, shouldShow, } = props;
203
+ editor.registerPlugin(extensionFloatingMenu.FloatingMenuPlugin({
204
+ pluginKey,
205
+ editor,
206
+ element: root.value,
207
+ tippyOptions,
208
+ shouldShow,
209
+ }));
210
+ });
211
+ vue.onBeforeUnmount(() => {
212
+ const { pluginKey, editor } = props;
213
+ editor.unregisterPlugin(pluginKey);
214
+ });
215
+ return () => { var _a; return vue.h('div', { ref: root }, (_a = slots.default) === null || _a === void 0 ? void 0 : _a.call(slots)); };
216
+ },
219
217
  });
220
218
 
221
- const NodeViewContent = vue.defineComponent({
222
- name: 'NodeViewContent',
223
- props: {
224
- as: {
225
- type: String,
226
- default: 'div',
227
- },
228
- },
229
- render() {
230
- return vue.h(this.as, {
231
- style: {
232
- whiteSpace: 'pre-wrap',
233
- },
234
- 'data-node-view-content': '',
235
- });
236
- },
219
+ const NodeViewContent = vue.defineComponent({
220
+ name: 'NodeViewContent',
221
+ props: {
222
+ as: {
223
+ type: String,
224
+ default: 'div',
225
+ },
226
+ },
227
+ render() {
228
+ return vue.h(this.as, {
229
+ style: {
230
+ whiteSpace: 'pre-wrap',
231
+ },
232
+ 'data-node-view-content': '',
233
+ });
234
+ },
237
235
  });
238
236
 
239
- const NodeViewWrapper = vue.defineComponent({
240
- name: 'NodeViewWrapper',
241
- props: {
242
- as: {
243
- type: String,
244
- default: 'div',
245
- },
246
- },
247
- inject: ['onDragStart', 'decorationClasses'],
248
- render() {
249
- var _a, _b;
250
- return vue.h(this.as, {
251
- // @ts-ignore
252
- class: this.decorationClasses,
253
- style: {
254
- whiteSpace: 'normal',
255
- },
256
- 'data-node-view-wrapper': '',
257
- // @ts-ignore (https://github.com/vuejs/vue-next/issues/3031)
258
- onDragstart: this.onDragStart,
259
- }, (_b = (_a = this.$slots).default) === null || _b === void 0 ? void 0 : _b.call(_a));
260
- },
237
+ const NodeViewWrapper = vue.defineComponent({
238
+ name: 'NodeViewWrapper',
239
+ props: {
240
+ as: {
241
+ type: String,
242
+ default: 'div',
243
+ },
244
+ },
245
+ inject: ['onDragStart', 'decorationClasses'],
246
+ render() {
247
+ var _a, _b;
248
+ return vue.h(this.as, {
249
+ // @ts-ignore
250
+ class: this.decorationClasses,
251
+ style: {
252
+ whiteSpace: 'normal',
253
+ },
254
+ 'data-node-view-wrapper': '',
255
+ // @ts-ignore (https://github.com/vuejs/vue-next/issues/3031)
256
+ onDragstart: this.onDragStart,
257
+ }, (_b = (_a = this.$slots).default) === null || _b === void 0 ? void 0 : _b.call(_a));
258
+ },
261
259
  });
262
260
 
263
- const useEditor = (options = {}) => {
264
- const editor = vue.shallowRef();
265
- vue.onMounted(() => {
266
- editor.value = new Editor(options);
267
- });
268
- vue.onBeforeUnmount(() => {
269
- var _a;
270
- (_a = editor.value) === null || _a === void 0 ? void 0 : _a.destroy();
271
- });
272
- return editor;
261
+ const useEditor = (options = {}) => {
262
+ const editor = vue.shallowRef();
263
+ vue.onMounted(() => {
264
+ editor.value = new Editor(options);
265
+ });
266
+ vue.onBeforeUnmount(() => {
267
+ var _a;
268
+ (_a = editor.value) === null || _a === void 0 ? void 0 : _a.destroy();
269
+ });
270
+ return editor;
273
271
  };
274
272
 
275
- /**
276
- * This class is used to render Vue components inside the editor.
277
- */
278
- class VueRenderer {
279
- constructor(component, { props = {}, editor }) {
280
- this.id = Math.floor(Math.random() * 0xFFFFFFFF).toString();
281
- this.editor = editor;
282
- this.component = vue.markRaw(component);
283
- this.teleportElement = document.createElement('div');
284
- this.element = this.teleportElement;
285
- this.props = vue.reactive(props);
286
- this.editor.vueRenderers.set(this.id, this);
287
- if (this.editor.contentComponent) {
288
- this.editor.contentComponent.update();
289
- if (this.teleportElement.children.length !== 1) {
290
- throw Error('VueRenderer doesn’t support multiple child elements.');
291
- }
292
- this.element = this.teleportElement.firstElementChild;
293
- }
294
- }
295
- get ref() {
296
- var _a;
297
- return (_a = this.editor.contentComponent) === null || _a === void 0 ? void 0 : _a.refs[this.id];
298
- }
299
- updateProps(props = {}) {
300
- Object
301
- .entries(props)
302
- .forEach(([key, value]) => {
303
- this.props[key] = value;
304
- });
305
- }
306
- destroy() {
307
- this.editor.vueRenderers.delete(this.id);
308
- }
273
+ /**
274
+ * This class is used to render Vue components inside the editor.
275
+ */
276
+ class VueRenderer {
277
+ constructor(component, { props = {}, editor }) {
278
+ this.id = Math.floor(Math.random() * 0xFFFFFFFF).toString();
279
+ this.editor = editor;
280
+ this.component = vue.markRaw(component);
281
+ this.el = document.createElement('div');
282
+ this.props = vue.reactive(props);
283
+ this.renderedComponent = this.renderComponent();
284
+ }
285
+ get element() {
286
+ return this.renderedComponent.el;
287
+ }
288
+ renderComponent() {
289
+ let vNode = vue.h(this.component, this.props);
290
+ if (typeof document !== 'undefined' && this.el) {
291
+ vue.render(vNode, this.el);
292
+ }
293
+ const destroy = () => {
294
+ if (this.el) {
295
+ vue.render(null, this.el);
296
+ }
297
+ this.el = null;
298
+ vNode = null;
299
+ };
300
+ return { vNode, destroy, el: this.el ? this.el.firstElementChild : null };
301
+ }
302
+ updateProps(props = {}) {
303
+ Object
304
+ .entries(props)
305
+ .forEach(([key, value]) => {
306
+ this.props[key] = value;
307
+ });
308
+ this.renderComponent();
309
+ }
310
+ destroy() {
311
+ this.renderedComponent.destroy();
312
+ }
309
313
  }
310
314
 
311
- const nodeViewProps = {
312
- editor: {
313
- type: Object,
314
- required: true,
315
- },
316
- node: {
317
- type: Object,
318
- required: true,
319
- },
320
- decorations: {
321
- type: Object,
322
- required: true,
323
- },
324
- selected: {
325
- type: Boolean,
326
- required: true,
327
- },
328
- extension: {
329
- type: Object,
330
- required: true,
331
- },
332
- getPos: {
333
- type: Function,
334
- required: true,
335
- },
336
- updateAttributes: {
337
- type: Function,
338
- required: true,
339
- },
340
- deleteNode: {
341
- type: Function,
342
- required: true,
343
- },
344
- };
345
- class VueNodeView extends core.NodeView {
346
- mount() {
347
- const props = {
348
- editor: this.editor,
349
- node: this.node,
350
- decorations: this.decorations,
351
- selected: false,
352
- extension: this.extension,
353
- getPos: () => this.getPos(),
354
- updateAttributes: (attributes = {}) => this.updateAttributes(attributes),
355
- deleteNode: () => this.deleteNode(),
356
- };
357
- const onDragStart = this.onDragStart.bind(this);
358
- this.decorationClasses = vue.ref(this.getDecorationClasses());
359
- const extendedComponent = vue.defineComponent({
360
- extends: { ...this.component },
361
- props: Object.keys(props),
362
- template: this.component.template,
363
- setup: reactiveProps => {
364
- var _a, _b;
365
- vue.provide('onDragStart', onDragStart);
366
- vue.provide('decorationClasses', this.decorationClasses);
367
- return (_b = (_a = this.component).setup) === null || _b === void 0 ? void 0 : _b.call(_a, reactiveProps, {
368
- expose: () => undefined,
369
- });
370
- },
371
- // add support for scoped styles
372
- // @ts-ignore
373
- // eslint-disable-next-line
374
- __scopeId: this.component.__scopeId,
375
- // add support for CSS Modules
376
- // @ts-ignore
377
- // eslint-disable-next-line
378
- __cssModules: this.component.__cssModules,
379
- // add support for vue devtools
380
- // @ts-ignore
381
- // eslint-disable-next-line
382
- __name: this.component.__name,
383
- // @ts-ignore
384
- // eslint-disable-next-line
385
- __file: this.component.__file,
386
- });
387
- this.renderer = new VueRenderer(extendedComponent, {
388
- editor: this.editor,
389
- props,
390
- });
391
- }
392
- get dom() {
393
- if (!this.renderer.element.hasAttribute('data-node-view-wrapper')) {
394
- throw Error('Please use the NodeViewWrapper component for your node view.');
395
- }
396
- return this.renderer.element;
397
- }
398
- get contentDOM() {
399
- if (this.node.isLeaf) {
400
- return null;
401
- }
402
- const contentElement = this.dom.querySelector('[data-node-view-content]');
403
- return (contentElement || this.dom);
404
- }
405
- update(node, decorations) {
406
- const updateProps = (props) => {
407
- this.decorationClasses.value = this.getDecorationClasses();
408
- this.renderer.updateProps(props);
409
- };
410
- if (typeof this.options.update === 'function') {
411
- const oldNode = this.node;
412
- const oldDecorations = this.decorations;
413
- this.node = node;
414
- this.decorations = decorations;
415
- return this.options.update({
416
- oldNode,
417
- oldDecorations,
418
- newNode: node,
419
- newDecorations: decorations,
420
- updateProps: () => updateProps({ node, decorations }),
421
- });
422
- }
423
- if (node.type !== this.node.type) {
424
- return false;
425
- }
426
- if (node === this.node && this.decorations === decorations) {
427
- return true;
428
- }
429
- this.node = node;
430
- this.decorations = decorations;
431
- updateProps({ node, decorations });
432
- return true;
433
- }
434
- selectNode() {
435
- this.renderer.updateProps({
436
- selected: true,
437
- });
438
- this.renderer.element.classList.add('ProseMirror-selectednode');
439
- }
440
- deselectNode() {
441
- this.renderer.updateProps({
442
- selected: false,
443
- });
444
- this.renderer.element.classList.remove('ProseMirror-selectednode');
445
- }
446
- getDecorationClasses() {
447
- return (this.decorations
448
- // @ts-ignore
449
- .map(item => item.type.attrs.class)
450
- .flat()
451
- .join(' '));
452
- }
453
- destroy() {
454
- this.renderer.destroy();
455
- }
456
- }
457
- function VueNodeViewRenderer(component, options) {
458
- return (props) => {
459
- // try to get the parent component
460
- // this is important for vue devtools to show the component hierarchy correctly
461
- // maybe it’s `undefined` because <editor-content> isn’t rendered yet
462
- if (!props.editor.contentComponent) {
463
- return {};
464
- }
465
- return new VueNodeView(component, props, options);
466
- };
315
+ const nodeViewProps = {
316
+ editor: {
317
+ type: Object,
318
+ required: true,
319
+ },
320
+ node: {
321
+ type: Object,
322
+ required: true,
323
+ },
324
+ decorations: {
325
+ type: Object,
326
+ required: true,
327
+ },
328
+ selected: {
329
+ type: Boolean,
330
+ required: true,
331
+ },
332
+ extension: {
333
+ type: Object,
334
+ required: true,
335
+ },
336
+ getPos: {
337
+ type: Function,
338
+ required: true,
339
+ },
340
+ updateAttributes: {
341
+ type: Function,
342
+ required: true,
343
+ },
344
+ deleteNode: {
345
+ type: Function,
346
+ required: true,
347
+ },
348
+ };
349
+ class VueNodeView extends core.NodeView {
350
+ mount() {
351
+ const props = {
352
+ editor: this.editor,
353
+ node: this.node,
354
+ decorations: this.decorations,
355
+ selected: false,
356
+ extension: this.extension,
357
+ getPos: () => this.getPos(),
358
+ updateAttributes: (attributes = {}) => this.updateAttributes(attributes),
359
+ deleteNode: () => this.deleteNode(),
360
+ };
361
+ const onDragStart = this.onDragStart.bind(this);
362
+ this.decorationClasses = vue.ref(this.getDecorationClasses());
363
+ const extendedComponent = vue.defineComponent({
364
+ extends: { ...this.component },
365
+ props: Object.keys(props),
366
+ template: this.component.template,
367
+ setup: reactiveProps => {
368
+ var _a, _b;
369
+ vue.provide('onDragStart', onDragStart);
370
+ vue.provide('decorationClasses', this.decorationClasses);
371
+ return (_b = (_a = this.component).setup) === null || _b === void 0 ? void 0 : _b.call(_a, reactiveProps, {
372
+ expose: () => undefined,
373
+ });
374
+ },
375
+ // add support for scoped styles
376
+ // @ts-ignore
377
+ // eslint-disable-next-line
378
+ __scopeId: this.component.__scopeId,
379
+ // add support for CSS Modules
380
+ // @ts-ignore
381
+ // eslint-disable-next-line
382
+ __cssModules: this.component.__cssModules,
383
+ // add support for vue devtools
384
+ // @ts-ignore
385
+ // eslint-disable-next-line
386
+ __name: this.component.__name,
387
+ // @ts-ignore
388
+ // eslint-disable-next-line
389
+ __file: this.component.__file,
390
+ });
391
+ this.renderer = new VueRenderer(extendedComponent, {
392
+ editor: this.editor,
393
+ props,
394
+ });
395
+ }
396
+ get dom() {
397
+ if (!this.renderer.element || !this.renderer.element.hasAttribute('data-node-view-wrapper')) {
398
+ throw Error('Please use the NodeViewWrapper component for your node view.');
399
+ }
400
+ return this.renderer.element;
401
+ }
402
+ get contentDOM() {
403
+ if (this.node.isLeaf) {
404
+ return null;
405
+ }
406
+ const contentElement = this.dom.querySelector('[data-node-view-content]');
407
+ return (contentElement || this.dom);
408
+ }
409
+ update(node, decorations) {
410
+ const updateProps = (props) => {
411
+ this.decorationClasses.value = this.getDecorationClasses();
412
+ this.renderer.updateProps(props);
413
+ };
414
+ if (typeof this.options.update === 'function') {
415
+ const oldNode = this.node;
416
+ const oldDecorations = this.decorations;
417
+ this.node = node;
418
+ this.decorations = decorations;
419
+ return this.options.update({
420
+ oldNode,
421
+ oldDecorations,
422
+ newNode: node,
423
+ newDecorations: decorations,
424
+ updateProps: () => updateProps({ node, decorations }),
425
+ });
426
+ }
427
+ if (node.type !== this.node.type) {
428
+ return false;
429
+ }
430
+ if (node === this.node && this.decorations === decorations) {
431
+ return true;
432
+ }
433
+ this.node = node;
434
+ this.decorations = decorations;
435
+ updateProps({ node, decorations });
436
+ return true;
437
+ }
438
+ selectNode() {
439
+ this.renderer.updateProps({
440
+ selected: true,
441
+ });
442
+ if (this.renderer.element) {
443
+ this.renderer.element.classList.add('ProseMirror-selectednode');
444
+ }
445
+ }
446
+ deselectNode() {
447
+ this.renderer.updateProps({
448
+ selected: false,
449
+ });
450
+ if (this.renderer.element) {
451
+ this.renderer.element.classList.remove('ProseMirror-selectednode');
452
+ }
453
+ }
454
+ getDecorationClasses() {
455
+ return (this.decorations
456
+ // @ts-ignore
457
+ .map(item => item.type.attrs.class)
458
+ .flat()
459
+ .join(' '));
460
+ }
461
+ destroy() {
462
+ this.renderer.destroy();
463
+ }
464
+ }
465
+ function VueNodeViewRenderer(component, options) {
466
+ return (props) => {
467
+ // try to get the parent component
468
+ // this is important for vue devtools to show the component hierarchy correctly
469
+ // maybe it’s `undefined` because <editor-content> isn’t rendered yet
470
+ if (!props.editor.contentComponent) {
471
+ return {};
472
+ }
473
+ return new VueNodeView(component, props, options);
474
+ };
467
475
  }
468
476
 
469
477
  exports.BubbleMenu = BubbleMenu;
@@ -477,13 +485,11 @@
477
485
  exports.nodeViewProps = nodeViewProps;
478
486
  exports.useEditor = useEditor;
479
487
  Object.keys(core).forEach(function (k) {
480
- if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
488
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
481
489
  enumerable: true,
482
490
  get: function () { return core[k]; }
483
491
  });
484
492
  });
485
493
 
486
- Object.defineProperty(exports, '__esModule', { value: true });
487
-
488
494
  }));
489
495
  //# sourceMappingURL=index.umd.js.map