@tiptap/vue-3 3.0.0 → 3.0.1

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 (206) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +5 -1
  3. package/dist/index.cjs +577 -455
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.d.cts +228 -0
  6. package/dist/index.d.ts +228 -0
  7. package/dist/index.js +541 -443
  8. package/dist/index.js.map +1 -1
  9. package/dist/menus/index.cjs +692 -0
  10. package/dist/menus/index.cjs.map +1 -0
  11. package/dist/menus/index.d.cts +273 -0
  12. package/dist/menus/index.d.ts +273 -0
  13. package/dist/menus/index.js +684 -0
  14. package/dist/menus/index.js.map +1 -0
  15. package/package.json +28 -17
  16. package/src/Editor.ts +23 -17
  17. package/src/EditorContent.ts +14 -44
  18. package/src/VueMarkViewRenderer.ts +130 -0
  19. package/src/VueNodeViewRenderer.ts +99 -36
  20. package/src/VueRenderer.ts +27 -18
  21. package/src/index.ts +1 -2
  22. package/src/menus/BubbleMenu.ts +78 -0
  23. package/src/menus/FloatingMenu.ts +68 -0
  24. package/src/menus/index.ts +2 -0
  25. package/src/useEditor.ts +7 -1
  26. package/dist/index.umd.js +0 -495
  27. package/dist/index.umd.js.map +0 -1
  28. package/dist/packages/core/src/CommandManager.d.ts +0 -20
  29. package/dist/packages/core/src/Editor.d.ts +0 -161
  30. package/dist/packages/core/src/EventEmitter.d.ts +0 -11
  31. package/dist/packages/core/src/Extension.d.ts +0 -343
  32. package/dist/packages/core/src/ExtensionManager.d.ts +0 -55
  33. package/dist/packages/core/src/InputRule.d.ts +0 -42
  34. package/dist/packages/core/src/Mark.d.ts +0 -451
  35. package/dist/packages/core/src/Node.d.ts +0 -611
  36. package/dist/packages/core/src/NodePos.d.ts +0 -44
  37. package/dist/packages/core/src/NodeView.d.ts +0 -31
  38. package/dist/packages/core/src/PasteRule.d.ts +0 -50
  39. package/dist/packages/core/src/Tracker.d.ts +0 -11
  40. package/dist/packages/core/src/commands/blur.d.ts +0 -13
  41. package/dist/packages/core/src/commands/clearContent.d.ts +0 -14
  42. package/dist/packages/core/src/commands/clearNodes.d.ts +0 -13
  43. package/dist/packages/core/src/commands/command.d.ts +0 -18
  44. package/dist/packages/core/src/commands/createParagraphNear.d.ts +0 -13
  45. package/dist/packages/core/src/commands/cut.d.ts +0 -20
  46. package/dist/packages/core/src/commands/deleteCurrentNode.d.ts +0 -13
  47. package/dist/packages/core/src/commands/deleteNode.d.ts +0 -15
  48. package/dist/packages/core/src/commands/deleteRange.d.ts +0 -14
  49. package/dist/packages/core/src/commands/deleteSelection.d.ts +0 -13
  50. package/dist/packages/core/src/commands/enter.d.ts +0 -13
  51. package/dist/packages/core/src/commands/exitCode.d.ts +0 -13
  52. package/dist/packages/core/src/commands/extendMarkRange.d.ts +0 -25
  53. package/dist/packages/core/src/commands/first.d.ts +0 -14
  54. package/dist/packages/core/src/commands/focus.d.ts +0 -27
  55. package/dist/packages/core/src/commands/forEach.d.ts +0 -14
  56. package/dist/packages/core/src/commands/index.d.ts +0 -55
  57. package/dist/packages/core/src/commands/insertContent.d.ts +0 -34
  58. package/dist/packages/core/src/commands/insertContentAt.d.ts +0 -47
  59. package/dist/packages/core/src/commands/join.d.ts +0 -41
  60. package/dist/packages/core/src/commands/joinItemBackward.d.ts +0 -13
  61. package/dist/packages/core/src/commands/joinItemForward.d.ts +0 -13
  62. package/dist/packages/core/src/commands/joinTextblockBackward.d.ts +0 -12
  63. package/dist/packages/core/src/commands/joinTextblockForward.d.ts +0 -12
  64. package/dist/packages/core/src/commands/keyboardShortcut.d.ts +0 -14
  65. package/dist/packages/core/src/commands/lift.d.ts +0 -17
  66. package/dist/packages/core/src/commands/liftEmptyBlock.d.ts +0 -13
  67. package/dist/packages/core/src/commands/liftListItem.d.ts +0 -15
  68. package/dist/packages/core/src/commands/newlineInCode.d.ts +0 -13
  69. package/dist/packages/core/src/commands/resetAttributes.d.ts +0 -16
  70. package/dist/packages/core/src/commands/scrollIntoView.d.ts +0 -13
  71. package/dist/packages/core/src/commands/selectAll.d.ts +0 -13
  72. package/dist/packages/core/src/commands/selectNodeBackward.d.ts +0 -13
  73. package/dist/packages/core/src/commands/selectNodeForward.d.ts +0 -13
  74. package/dist/packages/core/src/commands/selectParentNode.d.ts +0 -13
  75. package/dist/packages/core/src/commands/selectTextblockEnd.d.ts +0 -13
  76. package/dist/packages/core/src/commands/selectTextblockStart.d.ts +0 -13
  77. package/dist/packages/core/src/commands/setContent.d.ts +0 -40
  78. package/dist/packages/core/src/commands/setMark.d.ts +0 -15
  79. package/dist/packages/core/src/commands/setMeta.d.ts +0 -15
  80. package/dist/packages/core/src/commands/setNode.d.ts +0 -16
  81. package/dist/packages/core/src/commands/setNodeSelection.d.ts +0 -14
  82. package/dist/packages/core/src/commands/setTextSelection.d.ts +0 -14
  83. package/dist/packages/core/src/commands/sinkListItem.d.ts +0 -15
  84. package/dist/packages/core/src/commands/splitBlock.d.ts +0 -17
  85. package/dist/packages/core/src/commands/splitListItem.d.ts +0 -15
  86. package/dist/packages/core/src/commands/toggleList.d.ts +0 -18
  87. package/dist/packages/core/src/commands/toggleMark.d.ts +0 -30
  88. package/dist/packages/core/src/commands/toggleNode.d.ts +0 -17
  89. package/dist/packages/core/src/commands/toggleWrap.d.ts +0 -16
  90. package/dist/packages/core/src/commands/undoInputRule.d.ts +0 -13
  91. package/dist/packages/core/src/commands/unsetAllMarks.d.ts +0 -13
  92. package/dist/packages/core/src/commands/unsetMark.d.ts +0 -25
  93. package/dist/packages/core/src/commands/updateAttributes.d.ts +0 -24
  94. package/dist/packages/core/src/commands/wrapIn.d.ts +0 -16
  95. package/dist/packages/core/src/commands/wrapInList.d.ts +0 -16
  96. package/dist/packages/core/src/extensions/clipboardTextSerializer.d.ts +0 -5
  97. package/dist/packages/core/src/extensions/commands.d.ts +0 -3
  98. package/dist/packages/core/src/extensions/editable.d.ts +0 -2
  99. package/dist/packages/core/src/extensions/focusEvents.d.ts +0 -2
  100. package/dist/packages/core/src/extensions/index.d.ts +0 -6
  101. package/dist/packages/core/src/extensions/keymap.d.ts +0 -2
  102. package/dist/packages/core/src/extensions/tabindex.d.ts +0 -2
  103. package/dist/packages/core/src/helpers/combineTransactionSteps.d.ts +0 -10
  104. package/dist/packages/core/src/helpers/createChainableState.d.ts +0 -10
  105. package/dist/packages/core/src/helpers/createDocument.d.ts +0 -12
  106. package/dist/packages/core/src/helpers/createNodeFromContent.d.ts +0 -15
  107. package/dist/packages/core/src/helpers/defaultBlockAt.d.ts +0 -7
  108. package/dist/packages/core/src/helpers/findChildren.d.ts +0 -9
  109. package/dist/packages/core/src/helpers/findChildrenInRange.d.ts +0 -10
  110. package/dist/packages/core/src/helpers/findParentNode.d.ts +0 -16
  111. package/dist/packages/core/src/helpers/findParentNodeClosestToPos.d.ts +0 -17
  112. package/dist/packages/core/src/helpers/generateHTML.d.ts +0 -8
  113. package/dist/packages/core/src/helpers/generateJSON.d.ts +0 -8
  114. package/dist/packages/core/src/helpers/generateText.d.ts +0 -12
  115. package/dist/packages/core/src/helpers/getAttributes.d.ts +0 -9
  116. package/dist/packages/core/src/helpers/getAttributesFromExtensions.d.ts +0 -6
  117. package/dist/packages/core/src/helpers/getChangedRanges.d.ts +0 -11
  118. package/dist/packages/core/src/helpers/getDebugJSON.d.ts +0 -8
  119. package/dist/packages/core/src/helpers/getExtensionField.d.ts +0 -9
  120. package/dist/packages/core/src/helpers/getHTMLFromFragment.d.ts +0 -2
  121. package/dist/packages/core/src/helpers/getMarkAttributes.d.ts +0 -3
  122. package/dist/packages/core/src/helpers/getMarkRange.d.ts +0 -3
  123. package/dist/packages/core/src/helpers/getMarkType.d.ts +0 -2
  124. package/dist/packages/core/src/helpers/getMarksBetween.d.ts +0 -3
  125. package/dist/packages/core/src/helpers/getNodeAtPosition.d.ts +0 -11
  126. package/dist/packages/core/src/helpers/getNodeAttributes.d.ts +0 -3
  127. package/dist/packages/core/src/helpers/getNodeType.d.ts +0 -2
  128. package/dist/packages/core/src/helpers/getRenderedAttributes.d.ts +0 -3
  129. package/dist/packages/core/src/helpers/getSchema.d.ts +0 -4
  130. package/dist/packages/core/src/helpers/getSchemaByResolvedExtensions.d.ts +0 -10
  131. package/dist/packages/core/src/helpers/getSchemaTypeByName.d.ts +0 -8
  132. package/dist/packages/core/src/helpers/getSchemaTypeNameByName.d.ts +0 -8
  133. package/dist/packages/core/src/helpers/getSplittedAttributes.d.ts +0 -9
  134. package/dist/packages/core/src/helpers/getText.d.ts +0 -15
  135. package/dist/packages/core/src/helpers/getTextBetween.d.ts +0 -14
  136. package/dist/packages/core/src/helpers/getTextContentFromNodes.d.ts +0 -8
  137. package/dist/packages/core/src/helpers/getTextSerializersFromSchema.d.ts +0 -8
  138. package/dist/packages/core/src/helpers/index.d.ts +0 -50
  139. package/dist/packages/core/src/helpers/injectExtensionAttributesToParseRule.d.ts +0 -9
  140. package/dist/packages/core/src/helpers/isActive.d.ts +0 -2
  141. package/dist/packages/core/src/helpers/isAtEndOfNode.d.ts +0 -2
  142. package/dist/packages/core/src/helpers/isAtStartOfNode.d.ts +0 -2
  143. package/dist/packages/core/src/helpers/isExtensionRulesEnabled.d.ts +0 -2
  144. package/dist/packages/core/src/helpers/isList.d.ts +0 -2
  145. package/dist/packages/core/src/helpers/isMarkActive.d.ts +0 -3
  146. package/dist/packages/core/src/helpers/isNodeActive.d.ts +0 -3
  147. package/dist/packages/core/src/helpers/isNodeEmpty.d.ts +0 -2
  148. package/dist/packages/core/src/helpers/isNodeSelection.d.ts +0 -2
  149. package/dist/packages/core/src/helpers/isTextSelection.d.ts +0 -2
  150. package/dist/packages/core/src/helpers/posToDOMRect.d.ts +0 -2
  151. package/dist/packages/core/src/helpers/resolveFocusPosition.d.ts +0 -4
  152. package/dist/packages/core/src/helpers/selectionToInsertionEnd.d.ts +0 -2
  153. package/dist/packages/core/src/helpers/splitExtensions.d.ts +0 -9
  154. package/dist/packages/core/src/index.d.ts +0 -24
  155. package/dist/packages/core/src/inputRules/index.d.ts +0 -5
  156. package/dist/packages/core/src/inputRules/markInputRule.d.ts +0 -13
  157. package/dist/packages/core/src/inputRules/nodeInputRule.d.ts +0 -23
  158. package/dist/packages/core/src/inputRules/textInputRule.d.ts +0 -10
  159. package/dist/packages/core/src/inputRules/textblockTypeInputRule.d.ts +0 -15
  160. package/dist/packages/core/src/inputRules/wrappingInputRule.d.ts +0 -28
  161. package/dist/packages/core/src/pasteRules/index.d.ts +0 -3
  162. package/dist/packages/core/src/pasteRules/markPasteRule.d.ts +0 -13
  163. package/dist/packages/core/src/pasteRules/nodePasteRule.d.ts +0 -13
  164. package/dist/packages/core/src/pasteRules/textPasteRule.d.ts +0 -10
  165. package/dist/packages/core/src/style.d.ts +0 -1
  166. package/dist/packages/core/src/types.d.ts +0 -255
  167. package/dist/packages/core/src/utilities/callOrReturn.d.ts +0 -9
  168. package/dist/packages/core/src/utilities/createStyleTag.d.ts +0 -1
  169. package/dist/packages/core/src/utilities/deleteProps.d.ts +0 -6
  170. package/dist/packages/core/src/utilities/elementFromString.d.ts +0 -1
  171. package/dist/packages/core/src/utilities/escapeForRegEx.d.ts +0 -1
  172. package/dist/packages/core/src/utilities/findDuplicates.d.ts +0 -1
  173. package/dist/packages/core/src/utilities/fromString.d.ts +0 -1
  174. package/dist/packages/core/src/utilities/index.d.ts +0 -20
  175. package/dist/packages/core/src/utilities/isAndroid.d.ts +0 -1
  176. package/dist/packages/core/src/utilities/isEmptyObject.d.ts +0 -1
  177. package/dist/packages/core/src/utilities/isFunction.d.ts +0 -1
  178. package/dist/packages/core/src/utilities/isMacOS.d.ts +0 -1
  179. package/dist/packages/core/src/utilities/isNumber.d.ts +0 -1
  180. package/dist/packages/core/src/utilities/isPlainObject.d.ts +0 -1
  181. package/dist/packages/core/src/utilities/isRegExp.d.ts +0 -1
  182. package/dist/packages/core/src/utilities/isString.d.ts +0 -1
  183. package/dist/packages/core/src/utilities/isiOS.d.ts +0 -1
  184. package/dist/packages/core/src/utilities/mergeAttributes.d.ts +0 -1
  185. package/dist/packages/core/src/utilities/mergeDeep.d.ts +0 -1
  186. package/dist/packages/core/src/utilities/minMax.d.ts +0 -1
  187. package/dist/packages/core/src/utilities/objectIncludes.d.ts +0 -8
  188. package/dist/packages/core/src/utilities/removeDuplicates.d.ts +0 -8
  189. package/dist/packages/extension-bubble-menu/src/bubble-menu-plugin.d.ts +0 -76
  190. package/dist/packages/extension-bubble-menu/src/bubble-menu.d.ts +0 -15
  191. package/dist/packages/extension-bubble-menu/src/index.d.ts +0 -4
  192. package/dist/packages/extension-floating-menu/src/floating-menu-plugin.d.ts +0 -66
  193. package/dist/packages/extension-floating-menu/src/floating-menu.d.ts +0 -15
  194. package/dist/packages/extension-floating-menu/src/index.d.ts +0 -4
  195. package/dist/packages/vue-3/src/BubbleMenu.d.ts +0 -59
  196. package/dist/packages/vue-3/src/Editor.d.ts +0 -23
  197. package/dist/packages/vue-3/src/EditorContent.d.ts +0 -17
  198. package/dist/packages/vue-3/src/FloatingMenu.d.ts +0 -48
  199. package/dist/packages/vue-3/src/NodeViewContent.d.ts +0 -13
  200. package/dist/packages/vue-3/src/NodeViewWrapper.d.ts +0 -13
  201. package/dist/packages/vue-3/src/VueNodeViewRenderer.d.ts +0 -48
  202. package/dist/packages/vue-3/src/VueRenderer.d.ts +0 -36
  203. package/dist/packages/vue-3/src/index.d.ts +0 -10
  204. package/dist/packages/vue-3/src/useEditor.d.ts +0 -3
  205. package/src/BubbleMenu.ts +0 -71
  206. package/src/FloatingMenu.ts +0 -66
@@ -0,0 +1,684 @@
1
+ // ../extension-bubble-menu/dist/index.js
2
+ import { Extension } from "@tiptap/core";
3
+ import {
4
+ arrow,
5
+ autoPlacement,
6
+ computePosition,
7
+ flip,
8
+ hide,
9
+ inline,
10
+ offset,
11
+ shift,
12
+ size
13
+ } from "@floating-ui/dom";
14
+ import { isTextSelection, posToDOMRect } from "@tiptap/core";
15
+ import { Plugin, PluginKey } from "@tiptap/pm/state";
16
+ import { CellSelection } from "@tiptap/pm/tables";
17
+ function combineDOMRects(rect1, rect2) {
18
+ const top = Math.min(rect1.top, rect2.top);
19
+ const bottom = Math.max(rect1.bottom, rect2.bottom);
20
+ const left = Math.min(rect1.left, rect2.left);
21
+ const right = Math.max(rect1.right, rect2.right);
22
+ const width = right - left;
23
+ const height = bottom - top;
24
+ const x = left;
25
+ const y = top;
26
+ return new DOMRect(x, y, width, height);
27
+ }
28
+ var BubbleMenuView = class {
29
+ constructor({
30
+ editor,
31
+ element,
32
+ view,
33
+ updateDelay = 250,
34
+ resizeDelay = 60,
35
+ shouldShow,
36
+ options
37
+ }) {
38
+ this.preventHide = false;
39
+ this.isVisible = false;
40
+ this.floatingUIOptions = {
41
+ strategy: "absolute",
42
+ placement: "top",
43
+ offset: 8,
44
+ flip: {},
45
+ shift: {},
46
+ arrow: false,
47
+ size: false,
48
+ autoPlacement: false,
49
+ hide: false,
50
+ inline: false,
51
+ onShow: void 0,
52
+ onHide: void 0,
53
+ onUpdate: void 0,
54
+ onDestroy: void 0
55
+ };
56
+ this.shouldShow = ({ view: view2, state, from, to }) => {
57
+ const { doc, selection } = state;
58
+ const { empty } = selection;
59
+ const isEmptyTextBlock = !doc.textBetween(from, to).length && isTextSelection(state.selection);
60
+ const isChildOfMenu = this.element.contains(document.activeElement);
61
+ const hasEditorFocus = view2.hasFocus() || isChildOfMenu;
62
+ if (!hasEditorFocus || empty || isEmptyTextBlock || !this.editor.isEditable) {
63
+ return false;
64
+ }
65
+ return true;
66
+ };
67
+ this.mousedownHandler = () => {
68
+ this.preventHide = true;
69
+ };
70
+ this.dragstartHandler = () => {
71
+ this.hide();
72
+ };
73
+ this.resizeHandler = () => {
74
+ if (this.resizeDebounceTimer) {
75
+ clearTimeout(this.resizeDebounceTimer);
76
+ }
77
+ this.resizeDebounceTimer = window.setTimeout(() => {
78
+ this.updatePosition();
79
+ }, this.resizeDelay);
80
+ };
81
+ this.focusHandler = () => {
82
+ setTimeout(() => this.update(this.editor.view));
83
+ };
84
+ this.blurHandler = ({ event }) => {
85
+ var _a;
86
+ if (this.preventHide) {
87
+ this.preventHide = false;
88
+ return;
89
+ }
90
+ if ((event == null ? void 0 : event.relatedTarget) && ((_a = this.element.parentNode) == null ? void 0 : _a.contains(event.relatedTarget))) {
91
+ return;
92
+ }
93
+ if ((event == null ? void 0 : event.relatedTarget) === this.editor.view.dom) {
94
+ return;
95
+ }
96
+ this.hide();
97
+ };
98
+ this.handleDebouncedUpdate = (view2, oldState) => {
99
+ const selectionChanged = !(oldState == null ? void 0 : oldState.selection.eq(view2.state.selection));
100
+ const docChanged = !(oldState == null ? void 0 : oldState.doc.eq(view2.state.doc));
101
+ if (!selectionChanged && !docChanged) {
102
+ return;
103
+ }
104
+ if (this.updateDebounceTimer) {
105
+ clearTimeout(this.updateDebounceTimer);
106
+ }
107
+ this.updateDebounceTimer = window.setTimeout(() => {
108
+ this.updateHandler(view2, selectionChanged, docChanged, oldState);
109
+ }, this.updateDelay);
110
+ };
111
+ this.updateHandler = (view2, selectionChanged, docChanged, oldState) => {
112
+ const { composing } = view2;
113
+ const isSame = !selectionChanged && !docChanged;
114
+ if (composing || isSame) {
115
+ return;
116
+ }
117
+ const shouldShow2 = this.getShouldShow(oldState);
118
+ if (!shouldShow2) {
119
+ this.hide();
120
+ return;
121
+ }
122
+ this.updatePosition();
123
+ this.show();
124
+ };
125
+ this.editor = editor;
126
+ this.element = element;
127
+ this.view = view;
128
+ this.updateDelay = updateDelay;
129
+ this.resizeDelay = resizeDelay;
130
+ this.floatingUIOptions = {
131
+ ...this.floatingUIOptions,
132
+ ...options
133
+ };
134
+ this.element.tabIndex = 0;
135
+ if (shouldShow) {
136
+ this.shouldShow = shouldShow;
137
+ }
138
+ this.element.addEventListener("mousedown", this.mousedownHandler, { capture: true });
139
+ this.view.dom.addEventListener("dragstart", this.dragstartHandler);
140
+ this.editor.on("focus", this.focusHandler);
141
+ this.editor.on("blur", this.blurHandler);
142
+ window.addEventListener("resize", this.resizeHandler);
143
+ this.update(view, view.state);
144
+ if (this.getShouldShow()) {
145
+ this.show();
146
+ }
147
+ }
148
+ get middlewares() {
149
+ const middlewares = [];
150
+ if (this.floatingUIOptions.flip) {
151
+ middlewares.push(flip(typeof this.floatingUIOptions.flip !== "boolean" ? this.floatingUIOptions.flip : void 0));
152
+ }
153
+ if (this.floatingUIOptions.shift) {
154
+ middlewares.push(
155
+ shift(typeof this.floatingUIOptions.shift !== "boolean" ? this.floatingUIOptions.shift : void 0)
156
+ );
157
+ }
158
+ if (this.floatingUIOptions.offset) {
159
+ middlewares.push(
160
+ offset(typeof this.floatingUIOptions.offset !== "boolean" ? this.floatingUIOptions.offset : void 0)
161
+ );
162
+ }
163
+ if (this.floatingUIOptions.arrow) {
164
+ middlewares.push(arrow(this.floatingUIOptions.arrow));
165
+ }
166
+ if (this.floatingUIOptions.size) {
167
+ middlewares.push(size(typeof this.floatingUIOptions.size !== "boolean" ? this.floatingUIOptions.size : void 0));
168
+ }
169
+ if (this.floatingUIOptions.autoPlacement) {
170
+ middlewares.push(
171
+ autoPlacement(
172
+ typeof this.floatingUIOptions.autoPlacement !== "boolean" ? this.floatingUIOptions.autoPlacement : void 0
173
+ )
174
+ );
175
+ }
176
+ if (this.floatingUIOptions.hide) {
177
+ middlewares.push(hide(typeof this.floatingUIOptions.hide !== "boolean" ? this.floatingUIOptions.hide : void 0));
178
+ }
179
+ if (this.floatingUIOptions.inline) {
180
+ middlewares.push(
181
+ inline(typeof this.floatingUIOptions.inline !== "boolean" ? this.floatingUIOptions.inline : void 0)
182
+ );
183
+ }
184
+ return middlewares;
185
+ }
186
+ updatePosition() {
187
+ const { selection } = this.editor.state;
188
+ let virtualElement = {
189
+ getBoundingClientRect: () => posToDOMRect(this.view, selection.from, selection.to)
190
+ };
191
+ if (selection instanceof CellSelection) {
192
+ const { $anchorCell, $headCell } = selection;
193
+ const from = $anchorCell ? $anchorCell.pos : $headCell.pos;
194
+ const to = $headCell ? $headCell.pos : $anchorCell.pos;
195
+ const fromDOM = this.view.nodeDOM(from);
196
+ const toDOM = this.view.nodeDOM(to);
197
+ if (!fromDOM || !toDOM) {
198
+ return;
199
+ }
200
+ const clientRect = fromDOM === toDOM ? fromDOM.getBoundingClientRect() : combineDOMRects(
201
+ fromDOM.getBoundingClientRect(),
202
+ toDOM.getBoundingClientRect()
203
+ );
204
+ virtualElement = {
205
+ getBoundingClientRect: () => clientRect
206
+ };
207
+ }
208
+ computePosition(virtualElement, this.element, {
209
+ placement: this.floatingUIOptions.placement,
210
+ strategy: this.floatingUIOptions.strategy,
211
+ middleware: this.middlewares
212
+ }).then(({ x, y, strategy }) => {
213
+ this.element.style.width = "max-content";
214
+ this.element.style.position = strategy;
215
+ this.element.style.left = `${x}px`;
216
+ this.element.style.top = `${y}px`;
217
+ if (this.isVisible && this.floatingUIOptions.onUpdate) {
218
+ this.floatingUIOptions.onUpdate();
219
+ }
220
+ });
221
+ }
222
+ update(view, oldState) {
223
+ const { state } = view;
224
+ const hasValidSelection = state.selection.from !== state.selection.to;
225
+ if (this.updateDelay > 0 && hasValidSelection) {
226
+ this.handleDebouncedUpdate(view, oldState);
227
+ return;
228
+ }
229
+ const selectionChanged = !(oldState == null ? void 0 : oldState.selection.eq(view.state.selection));
230
+ const docChanged = !(oldState == null ? void 0 : oldState.doc.eq(view.state.doc));
231
+ this.updateHandler(view, selectionChanged, docChanged, oldState);
232
+ }
233
+ getShouldShow(oldState) {
234
+ var _a;
235
+ const { state } = this.view;
236
+ const { selection } = state;
237
+ const { ranges } = selection;
238
+ const from = Math.min(...ranges.map((range) => range.$from.pos));
239
+ const to = Math.max(...ranges.map((range) => range.$to.pos));
240
+ const shouldShow = (_a = this.shouldShow) == null ? void 0 : _a.call(this, {
241
+ editor: this.editor,
242
+ element: this.element,
243
+ view: this.view,
244
+ state,
245
+ oldState,
246
+ from,
247
+ to
248
+ });
249
+ return shouldShow;
250
+ }
251
+ show() {
252
+ var _a;
253
+ if (this.isVisible) {
254
+ return;
255
+ }
256
+ this.element.style.visibility = "visible";
257
+ this.element.style.opacity = "1";
258
+ (_a = this.view.dom.parentElement) == null ? void 0 : _a.appendChild(this.element);
259
+ if (this.floatingUIOptions.onShow) {
260
+ this.floatingUIOptions.onShow();
261
+ }
262
+ this.isVisible = true;
263
+ }
264
+ hide() {
265
+ if (!this.isVisible) {
266
+ return;
267
+ }
268
+ this.element.style.visibility = "hidden";
269
+ this.element.style.opacity = "0";
270
+ this.element.remove();
271
+ if (this.floatingUIOptions.onHide) {
272
+ this.floatingUIOptions.onHide();
273
+ }
274
+ this.isVisible = false;
275
+ }
276
+ destroy() {
277
+ this.hide();
278
+ this.element.removeEventListener("mousedown", this.mousedownHandler, { capture: true });
279
+ this.view.dom.removeEventListener("dragstart", this.dragstartHandler);
280
+ window.removeEventListener("resize", this.resizeHandler);
281
+ this.editor.off("focus", this.focusHandler);
282
+ this.editor.off("blur", this.blurHandler);
283
+ if (this.floatingUIOptions.onDestroy) {
284
+ this.floatingUIOptions.onDestroy();
285
+ }
286
+ }
287
+ };
288
+ var BubbleMenuPlugin = (options) => {
289
+ return new Plugin({
290
+ key: typeof options.pluginKey === "string" ? new PluginKey(options.pluginKey) : options.pluginKey,
291
+ view: (view) => new BubbleMenuView({ view, ...options })
292
+ });
293
+ };
294
+ var BubbleMenu = Extension.create({
295
+ name: "bubbleMenu",
296
+ addOptions() {
297
+ return {
298
+ element: null,
299
+ pluginKey: "bubbleMenu",
300
+ updateDelay: void 0,
301
+ shouldShow: null
302
+ };
303
+ },
304
+ addProseMirrorPlugins() {
305
+ if (!this.options.element) {
306
+ return [];
307
+ }
308
+ return [
309
+ BubbleMenuPlugin({
310
+ pluginKey: this.options.pluginKey,
311
+ editor: this.editor,
312
+ element: this.options.element,
313
+ updateDelay: this.options.updateDelay,
314
+ shouldShow: this.options.shouldShow
315
+ })
316
+ ];
317
+ }
318
+ });
319
+
320
+ // src/menus/BubbleMenu.ts
321
+ import { defineComponent, h, onBeforeUnmount, onMounted, ref, Teleport } from "vue";
322
+ var BubbleMenu2 = defineComponent({
323
+ name: "BubbleMenu",
324
+ props: {
325
+ pluginKey: {
326
+ type: [String, Object],
327
+ default: "bubbleMenu"
328
+ },
329
+ editor: {
330
+ type: Object,
331
+ required: true
332
+ },
333
+ updateDelay: {
334
+ type: Number,
335
+ default: void 0
336
+ },
337
+ resizeDelay: {
338
+ type: Number,
339
+ default: void 0
340
+ },
341
+ options: {
342
+ type: Object,
343
+ default: () => ({})
344
+ },
345
+ shouldShow: {
346
+ type: Function,
347
+ default: null
348
+ }
349
+ },
350
+ setup(props, { slots }) {
351
+ const root = ref(null);
352
+ onMounted(() => {
353
+ const { editor, options, pluginKey, resizeDelay, shouldShow, updateDelay } = props;
354
+ if (!root.value) {
355
+ return;
356
+ }
357
+ root.value.style.visibility = "hidden";
358
+ root.value.style.position = "absolute";
359
+ root.value.remove();
360
+ editor.registerPlugin(
361
+ BubbleMenuPlugin({
362
+ editor,
363
+ element: root.value,
364
+ options,
365
+ pluginKey,
366
+ resizeDelay,
367
+ shouldShow,
368
+ updateDelay
369
+ })
370
+ );
371
+ });
372
+ onBeforeUnmount(() => {
373
+ const { pluginKey, editor } = props;
374
+ editor.unregisterPlugin(pluginKey);
375
+ });
376
+ return () => {
377
+ var _a;
378
+ return h(Teleport, { to: "body" }, h("div", { ref: root }, (_a = slots.default) == null ? void 0 : _a.call(slots)));
379
+ };
380
+ }
381
+ });
382
+
383
+ // ../extension-floating-menu/dist/index.js
384
+ import { Extension as Extension2 } from "@tiptap/core";
385
+ import {
386
+ arrow as arrow2,
387
+ autoPlacement as autoPlacement2,
388
+ computePosition as computePosition2,
389
+ flip as flip2,
390
+ hide as hide2,
391
+ inline as inline2,
392
+ offset as offset2,
393
+ shift as shift2,
394
+ size as size2
395
+ } from "@floating-ui/dom";
396
+ import { getText, getTextSerializersFromSchema, posToDOMRect as posToDOMRect2 } from "@tiptap/core";
397
+ import { Plugin as Plugin2, PluginKey as PluginKey2 } from "@tiptap/pm/state";
398
+ var FloatingMenuView = class {
399
+ constructor({ editor, element, view, options, shouldShow }) {
400
+ this.preventHide = false;
401
+ this.isVisible = false;
402
+ this.shouldShow = ({ view: view2, state }) => {
403
+ const { selection } = state;
404
+ const { $anchor, empty } = selection;
405
+ const isRootDepth = $anchor.depth === 1;
406
+ const isEmptyTextBlock = $anchor.parent.isTextblock && !$anchor.parent.type.spec.code && !$anchor.parent.textContent && $anchor.parent.childCount === 0 && !this.getTextContent($anchor.parent);
407
+ if (!view2.hasFocus() || !empty || !isRootDepth || !isEmptyTextBlock || !this.editor.isEditable) {
408
+ return false;
409
+ }
410
+ return true;
411
+ };
412
+ this.floatingUIOptions = {
413
+ strategy: "absolute",
414
+ placement: "right",
415
+ offset: 8,
416
+ flip: {},
417
+ shift: {},
418
+ arrow: false,
419
+ size: false,
420
+ autoPlacement: false,
421
+ hide: false,
422
+ inline: false
423
+ };
424
+ this.updateHandler = (view2, selectionChanged, docChanged, oldState) => {
425
+ const { composing } = view2;
426
+ const isSame = !selectionChanged && !docChanged;
427
+ if (composing || isSame) {
428
+ return;
429
+ }
430
+ const shouldShow2 = this.getShouldShow(oldState);
431
+ if (!shouldShow2) {
432
+ this.hide();
433
+ return;
434
+ }
435
+ this.updatePosition();
436
+ this.show();
437
+ };
438
+ this.mousedownHandler = () => {
439
+ this.preventHide = true;
440
+ };
441
+ this.focusHandler = () => {
442
+ setTimeout(() => this.update(this.editor.view));
443
+ };
444
+ this.blurHandler = ({ event }) => {
445
+ var _a;
446
+ if (this.preventHide) {
447
+ this.preventHide = false;
448
+ return;
449
+ }
450
+ if ((event == null ? void 0 : event.relatedTarget) && ((_a = this.element.parentNode) == null ? void 0 : _a.contains(event.relatedTarget))) {
451
+ return;
452
+ }
453
+ if ((event == null ? void 0 : event.relatedTarget) === this.editor.view.dom) {
454
+ return;
455
+ }
456
+ this.hide();
457
+ };
458
+ this.editor = editor;
459
+ this.element = element;
460
+ this.view = view;
461
+ this.floatingUIOptions = {
462
+ ...this.floatingUIOptions,
463
+ ...options
464
+ };
465
+ this.element.tabIndex = 0;
466
+ if (shouldShow) {
467
+ this.shouldShow = shouldShow;
468
+ }
469
+ this.element.addEventListener("mousedown", this.mousedownHandler, { capture: true });
470
+ this.editor.on("focus", this.focusHandler);
471
+ this.editor.on("blur", this.blurHandler);
472
+ this.update(view, view.state);
473
+ if (this.getShouldShow()) {
474
+ this.show();
475
+ }
476
+ }
477
+ getTextContent(node) {
478
+ return getText(node, { textSerializers: getTextSerializersFromSchema(this.editor.schema) });
479
+ }
480
+ get middlewares() {
481
+ const middlewares = [];
482
+ if (this.floatingUIOptions.flip) {
483
+ middlewares.push(flip2(typeof this.floatingUIOptions.flip !== "boolean" ? this.floatingUIOptions.flip : void 0));
484
+ }
485
+ if (this.floatingUIOptions.shift) {
486
+ middlewares.push(
487
+ shift2(typeof this.floatingUIOptions.shift !== "boolean" ? this.floatingUIOptions.shift : void 0)
488
+ );
489
+ }
490
+ if (this.floatingUIOptions.offset) {
491
+ middlewares.push(
492
+ offset2(typeof this.floatingUIOptions.offset !== "boolean" ? this.floatingUIOptions.offset : void 0)
493
+ );
494
+ }
495
+ if (this.floatingUIOptions.arrow) {
496
+ middlewares.push(arrow2(this.floatingUIOptions.arrow));
497
+ }
498
+ if (this.floatingUIOptions.size) {
499
+ middlewares.push(size2(typeof this.floatingUIOptions.size !== "boolean" ? this.floatingUIOptions.size : void 0));
500
+ }
501
+ if (this.floatingUIOptions.autoPlacement) {
502
+ middlewares.push(
503
+ autoPlacement2(
504
+ typeof this.floatingUIOptions.autoPlacement !== "boolean" ? this.floatingUIOptions.autoPlacement : void 0
505
+ )
506
+ );
507
+ }
508
+ if (this.floatingUIOptions.hide) {
509
+ middlewares.push(hide2(typeof this.floatingUIOptions.hide !== "boolean" ? this.floatingUIOptions.hide : void 0));
510
+ }
511
+ if (this.floatingUIOptions.inline) {
512
+ middlewares.push(
513
+ inline2(typeof this.floatingUIOptions.inline !== "boolean" ? this.floatingUIOptions.inline : void 0)
514
+ );
515
+ }
516
+ return middlewares;
517
+ }
518
+ getShouldShow(oldState) {
519
+ var _a;
520
+ const { state } = this.view;
521
+ const { selection } = state;
522
+ const { ranges } = selection;
523
+ const from = Math.min(...ranges.map((range) => range.$from.pos));
524
+ const to = Math.max(...ranges.map((range) => range.$to.pos));
525
+ const shouldShow = (_a = this.shouldShow) == null ? void 0 : _a.call(this, {
526
+ editor: this.editor,
527
+ view: this.view,
528
+ state,
529
+ oldState,
530
+ from,
531
+ to
532
+ });
533
+ return shouldShow;
534
+ }
535
+ updatePosition() {
536
+ const { selection } = this.editor.state;
537
+ const virtualElement = {
538
+ getBoundingClientRect: () => posToDOMRect2(this.view, selection.from, selection.to)
539
+ };
540
+ computePosition2(virtualElement, this.element, {
541
+ placement: this.floatingUIOptions.placement,
542
+ strategy: this.floatingUIOptions.strategy,
543
+ middleware: this.middlewares
544
+ }).then(({ x, y, strategy }) => {
545
+ this.element.style.width = "max-content";
546
+ this.element.style.position = strategy;
547
+ this.element.style.left = `${x}px`;
548
+ this.element.style.top = `${y}px`;
549
+ if (this.isVisible && this.floatingUIOptions.onUpdate) {
550
+ this.floatingUIOptions.onUpdate();
551
+ }
552
+ });
553
+ }
554
+ update(view, oldState) {
555
+ const selectionChanged = !(oldState == null ? void 0 : oldState.selection.eq(view.state.selection));
556
+ const docChanged = !(oldState == null ? void 0 : oldState.doc.eq(view.state.doc));
557
+ this.updateHandler(view, selectionChanged, docChanged, oldState);
558
+ }
559
+ show() {
560
+ var _a;
561
+ if (this.isVisible) {
562
+ return;
563
+ }
564
+ this.element.style.visibility = "visible";
565
+ this.element.style.opacity = "1";
566
+ (_a = this.view.dom.parentElement) == null ? void 0 : _a.appendChild(this.element);
567
+ if (this.floatingUIOptions.onShow) {
568
+ this.floatingUIOptions.onShow();
569
+ }
570
+ this.isVisible = true;
571
+ }
572
+ hide() {
573
+ if (!this.isVisible) {
574
+ return;
575
+ }
576
+ this.element.style.visibility = "hidden";
577
+ this.element.style.opacity = "0";
578
+ this.element.remove();
579
+ if (this.floatingUIOptions.onHide) {
580
+ this.floatingUIOptions.onHide();
581
+ }
582
+ this.isVisible = false;
583
+ }
584
+ destroy() {
585
+ this.hide();
586
+ this.element.removeEventListener("mousedown", this.mousedownHandler, { capture: true });
587
+ this.editor.off("focus", this.focusHandler);
588
+ this.editor.off("blur", this.blurHandler);
589
+ if (this.floatingUIOptions.onDestroy) {
590
+ this.floatingUIOptions.onDestroy();
591
+ }
592
+ }
593
+ };
594
+ var FloatingMenuPlugin = (options) => {
595
+ return new Plugin2({
596
+ key: typeof options.pluginKey === "string" ? new PluginKey2(options.pluginKey) : options.pluginKey,
597
+ view: (view) => new FloatingMenuView({ view, ...options })
598
+ });
599
+ };
600
+ var FloatingMenu = Extension2.create({
601
+ name: "floatingMenu",
602
+ addOptions() {
603
+ return {
604
+ element: null,
605
+ options: {},
606
+ pluginKey: "floatingMenu",
607
+ shouldShow: null
608
+ };
609
+ },
610
+ addProseMirrorPlugins() {
611
+ if (!this.options.element) {
612
+ return [];
613
+ }
614
+ return [
615
+ FloatingMenuPlugin({
616
+ pluginKey: this.options.pluginKey,
617
+ editor: this.editor,
618
+ element: this.options.element,
619
+ options: this.options.options,
620
+ shouldShow: this.options.shouldShow
621
+ })
622
+ ];
623
+ }
624
+ });
625
+
626
+ // src/menus/FloatingMenu.ts
627
+ import { defineComponent as defineComponent2, h as h2, onBeforeUnmount as onBeforeUnmount2, onMounted as onMounted2, ref as ref2, Teleport as Teleport2 } from "vue";
628
+ var FloatingMenu2 = defineComponent2({
629
+ name: "FloatingMenu",
630
+ props: {
631
+ pluginKey: {
632
+ // TODO: TypeScript breaks :(
633
+ // type: [String, Object as PropType<Exclude<FloatingMenuPluginProps['pluginKey'], string>>],
634
+ type: null,
635
+ default: "floatingMenu"
636
+ },
637
+ editor: {
638
+ type: Object,
639
+ required: true
640
+ },
641
+ options: {
642
+ type: Object,
643
+ default: () => ({})
644
+ },
645
+ shouldShow: {
646
+ type: Function,
647
+ default: null
648
+ }
649
+ },
650
+ setup(props, { slots }) {
651
+ const root = ref2(null);
652
+ onMounted2(() => {
653
+ const { pluginKey, editor, options, shouldShow } = props;
654
+ if (!root.value) {
655
+ return;
656
+ }
657
+ root.value.style.visibility = "hidden";
658
+ root.value.style.position = "absolute";
659
+ root.value.remove();
660
+ editor.registerPlugin(
661
+ FloatingMenuPlugin({
662
+ pluginKey,
663
+ editor,
664
+ element: root.value,
665
+ options,
666
+ shouldShow
667
+ })
668
+ );
669
+ });
670
+ onBeforeUnmount2(() => {
671
+ const { pluginKey, editor } = props;
672
+ editor.unregisterPlugin(pluginKey);
673
+ });
674
+ return () => {
675
+ var _a;
676
+ return h2(Teleport2, { to: "body" }, h2("div", { ref: root }, (_a = slots.default) == null ? void 0 : _a.call(slots)));
677
+ };
678
+ }
679
+ });
680
+ export {
681
+ BubbleMenu2 as BubbleMenu,
682
+ FloatingMenu2 as FloatingMenu
683
+ };
684
+ //# sourceMappingURL=index.js.map