@tiptap/vue-3 2.5.0-beta.1 → 2.5.0-beta.3

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