@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,692 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/menus/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ BubbleMenu: () => BubbleMenu2,
24
+ FloatingMenu: () => FloatingMenu2
25
+ });
26
+ module.exports = __toCommonJS(index_exports);
27
+
28
+ // ../extension-bubble-menu/dist/index.js
29
+ var import_core = require("@tiptap/core");
30
+ var import_dom = require("@floating-ui/dom");
31
+ var import_core2 = require("@tiptap/core");
32
+ var import_state = require("@tiptap/pm/state");
33
+ var import_tables = require("@tiptap/pm/tables");
34
+ function combineDOMRects(rect1, rect2) {
35
+ const top = Math.min(rect1.top, rect2.top);
36
+ const bottom = Math.max(rect1.bottom, rect2.bottom);
37
+ const left = Math.min(rect1.left, rect2.left);
38
+ const right = Math.max(rect1.right, rect2.right);
39
+ const width = right - left;
40
+ const height = bottom - top;
41
+ const x = left;
42
+ const y = top;
43
+ return new DOMRect(x, y, width, height);
44
+ }
45
+ var BubbleMenuView = class {
46
+ constructor({
47
+ editor,
48
+ element,
49
+ view,
50
+ updateDelay = 250,
51
+ resizeDelay = 60,
52
+ shouldShow,
53
+ options
54
+ }) {
55
+ this.preventHide = false;
56
+ this.isVisible = false;
57
+ this.floatingUIOptions = {
58
+ strategy: "absolute",
59
+ placement: "top",
60
+ offset: 8,
61
+ flip: {},
62
+ shift: {},
63
+ arrow: false,
64
+ size: false,
65
+ autoPlacement: false,
66
+ hide: false,
67
+ inline: false,
68
+ onShow: void 0,
69
+ onHide: void 0,
70
+ onUpdate: void 0,
71
+ onDestroy: void 0
72
+ };
73
+ this.shouldShow = ({ view: view2, state, from, to }) => {
74
+ const { doc, selection } = state;
75
+ const { empty } = selection;
76
+ const isEmptyTextBlock = !doc.textBetween(from, to).length && (0, import_core2.isTextSelection)(state.selection);
77
+ const isChildOfMenu = this.element.contains(document.activeElement);
78
+ const hasEditorFocus = view2.hasFocus() || isChildOfMenu;
79
+ if (!hasEditorFocus || empty || isEmptyTextBlock || !this.editor.isEditable) {
80
+ return false;
81
+ }
82
+ return true;
83
+ };
84
+ this.mousedownHandler = () => {
85
+ this.preventHide = true;
86
+ };
87
+ this.dragstartHandler = () => {
88
+ this.hide();
89
+ };
90
+ this.resizeHandler = () => {
91
+ if (this.resizeDebounceTimer) {
92
+ clearTimeout(this.resizeDebounceTimer);
93
+ }
94
+ this.resizeDebounceTimer = window.setTimeout(() => {
95
+ this.updatePosition();
96
+ }, this.resizeDelay);
97
+ };
98
+ this.focusHandler = () => {
99
+ setTimeout(() => this.update(this.editor.view));
100
+ };
101
+ this.blurHandler = ({ event }) => {
102
+ var _a;
103
+ if (this.preventHide) {
104
+ this.preventHide = false;
105
+ return;
106
+ }
107
+ if ((event == null ? void 0 : event.relatedTarget) && ((_a = this.element.parentNode) == null ? void 0 : _a.contains(event.relatedTarget))) {
108
+ return;
109
+ }
110
+ if ((event == null ? void 0 : event.relatedTarget) === this.editor.view.dom) {
111
+ return;
112
+ }
113
+ this.hide();
114
+ };
115
+ this.handleDebouncedUpdate = (view2, oldState) => {
116
+ const selectionChanged = !(oldState == null ? void 0 : oldState.selection.eq(view2.state.selection));
117
+ const docChanged = !(oldState == null ? void 0 : oldState.doc.eq(view2.state.doc));
118
+ if (!selectionChanged && !docChanged) {
119
+ return;
120
+ }
121
+ if (this.updateDebounceTimer) {
122
+ clearTimeout(this.updateDebounceTimer);
123
+ }
124
+ this.updateDebounceTimer = window.setTimeout(() => {
125
+ this.updateHandler(view2, selectionChanged, docChanged, oldState);
126
+ }, this.updateDelay);
127
+ };
128
+ this.updateHandler = (view2, selectionChanged, docChanged, oldState) => {
129
+ const { composing } = view2;
130
+ const isSame = !selectionChanged && !docChanged;
131
+ if (composing || isSame) {
132
+ return;
133
+ }
134
+ const shouldShow2 = this.getShouldShow(oldState);
135
+ if (!shouldShow2) {
136
+ this.hide();
137
+ return;
138
+ }
139
+ this.updatePosition();
140
+ this.show();
141
+ };
142
+ this.editor = editor;
143
+ this.element = element;
144
+ this.view = view;
145
+ this.updateDelay = updateDelay;
146
+ this.resizeDelay = resizeDelay;
147
+ this.floatingUIOptions = {
148
+ ...this.floatingUIOptions,
149
+ ...options
150
+ };
151
+ this.element.tabIndex = 0;
152
+ if (shouldShow) {
153
+ this.shouldShow = shouldShow;
154
+ }
155
+ this.element.addEventListener("mousedown", this.mousedownHandler, { capture: true });
156
+ this.view.dom.addEventListener("dragstart", this.dragstartHandler);
157
+ this.editor.on("focus", this.focusHandler);
158
+ this.editor.on("blur", this.blurHandler);
159
+ window.addEventListener("resize", this.resizeHandler);
160
+ this.update(view, view.state);
161
+ if (this.getShouldShow()) {
162
+ this.show();
163
+ }
164
+ }
165
+ get middlewares() {
166
+ const middlewares = [];
167
+ if (this.floatingUIOptions.flip) {
168
+ middlewares.push((0, import_dom.flip)(typeof this.floatingUIOptions.flip !== "boolean" ? this.floatingUIOptions.flip : void 0));
169
+ }
170
+ if (this.floatingUIOptions.shift) {
171
+ middlewares.push(
172
+ (0, import_dom.shift)(typeof this.floatingUIOptions.shift !== "boolean" ? this.floatingUIOptions.shift : void 0)
173
+ );
174
+ }
175
+ if (this.floatingUIOptions.offset) {
176
+ middlewares.push(
177
+ (0, import_dom.offset)(typeof this.floatingUIOptions.offset !== "boolean" ? this.floatingUIOptions.offset : void 0)
178
+ );
179
+ }
180
+ if (this.floatingUIOptions.arrow) {
181
+ middlewares.push((0, import_dom.arrow)(this.floatingUIOptions.arrow));
182
+ }
183
+ if (this.floatingUIOptions.size) {
184
+ middlewares.push((0, import_dom.size)(typeof this.floatingUIOptions.size !== "boolean" ? this.floatingUIOptions.size : void 0));
185
+ }
186
+ if (this.floatingUIOptions.autoPlacement) {
187
+ middlewares.push(
188
+ (0, import_dom.autoPlacement)(
189
+ typeof this.floatingUIOptions.autoPlacement !== "boolean" ? this.floatingUIOptions.autoPlacement : void 0
190
+ )
191
+ );
192
+ }
193
+ if (this.floatingUIOptions.hide) {
194
+ middlewares.push((0, import_dom.hide)(typeof this.floatingUIOptions.hide !== "boolean" ? this.floatingUIOptions.hide : void 0));
195
+ }
196
+ if (this.floatingUIOptions.inline) {
197
+ middlewares.push(
198
+ (0, import_dom.inline)(typeof this.floatingUIOptions.inline !== "boolean" ? this.floatingUIOptions.inline : void 0)
199
+ );
200
+ }
201
+ return middlewares;
202
+ }
203
+ updatePosition() {
204
+ const { selection } = this.editor.state;
205
+ let virtualElement = {
206
+ getBoundingClientRect: () => (0, import_core2.posToDOMRect)(this.view, selection.from, selection.to)
207
+ };
208
+ if (selection instanceof import_tables.CellSelection) {
209
+ const { $anchorCell, $headCell } = selection;
210
+ const from = $anchorCell ? $anchorCell.pos : $headCell.pos;
211
+ const to = $headCell ? $headCell.pos : $anchorCell.pos;
212
+ const fromDOM = this.view.nodeDOM(from);
213
+ const toDOM = this.view.nodeDOM(to);
214
+ if (!fromDOM || !toDOM) {
215
+ return;
216
+ }
217
+ const clientRect = fromDOM === toDOM ? fromDOM.getBoundingClientRect() : combineDOMRects(
218
+ fromDOM.getBoundingClientRect(),
219
+ toDOM.getBoundingClientRect()
220
+ );
221
+ virtualElement = {
222
+ getBoundingClientRect: () => clientRect
223
+ };
224
+ }
225
+ (0, import_dom.computePosition)(virtualElement, this.element, {
226
+ placement: this.floatingUIOptions.placement,
227
+ strategy: this.floatingUIOptions.strategy,
228
+ middleware: this.middlewares
229
+ }).then(({ x, y, strategy }) => {
230
+ this.element.style.width = "max-content";
231
+ this.element.style.position = strategy;
232
+ this.element.style.left = `${x}px`;
233
+ this.element.style.top = `${y}px`;
234
+ if (this.isVisible && this.floatingUIOptions.onUpdate) {
235
+ this.floatingUIOptions.onUpdate();
236
+ }
237
+ });
238
+ }
239
+ update(view, oldState) {
240
+ const { state } = view;
241
+ const hasValidSelection = state.selection.from !== state.selection.to;
242
+ if (this.updateDelay > 0 && hasValidSelection) {
243
+ this.handleDebouncedUpdate(view, oldState);
244
+ return;
245
+ }
246
+ const selectionChanged = !(oldState == null ? void 0 : oldState.selection.eq(view.state.selection));
247
+ const docChanged = !(oldState == null ? void 0 : oldState.doc.eq(view.state.doc));
248
+ this.updateHandler(view, selectionChanged, docChanged, oldState);
249
+ }
250
+ getShouldShow(oldState) {
251
+ var _a;
252
+ const { state } = this.view;
253
+ const { selection } = state;
254
+ const { ranges } = selection;
255
+ const from = Math.min(...ranges.map((range) => range.$from.pos));
256
+ const to = Math.max(...ranges.map((range) => range.$to.pos));
257
+ const shouldShow = (_a = this.shouldShow) == null ? void 0 : _a.call(this, {
258
+ editor: this.editor,
259
+ element: this.element,
260
+ view: this.view,
261
+ state,
262
+ oldState,
263
+ from,
264
+ to
265
+ });
266
+ return shouldShow;
267
+ }
268
+ show() {
269
+ var _a;
270
+ if (this.isVisible) {
271
+ return;
272
+ }
273
+ this.element.style.visibility = "visible";
274
+ this.element.style.opacity = "1";
275
+ (_a = this.view.dom.parentElement) == null ? void 0 : _a.appendChild(this.element);
276
+ if (this.floatingUIOptions.onShow) {
277
+ this.floatingUIOptions.onShow();
278
+ }
279
+ this.isVisible = true;
280
+ }
281
+ hide() {
282
+ if (!this.isVisible) {
283
+ return;
284
+ }
285
+ this.element.style.visibility = "hidden";
286
+ this.element.style.opacity = "0";
287
+ this.element.remove();
288
+ if (this.floatingUIOptions.onHide) {
289
+ this.floatingUIOptions.onHide();
290
+ }
291
+ this.isVisible = false;
292
+ }
293
+ destroy() {
294
+ this.hide();
295
+ this.element.removeEventListener("mousedown", this.mousedownHandler, { capture: true });
296
+ this.view.dom.removeEventListener("dragstart", this.dragstartHandler);
297
+ window.removeEventListener("resize", this.resizeHandler);
298
+ this.editor.off("focus", this.focusHandler);
299
+ this.editor.off("blur", this.blurHandler);
300
+ if (this.floatingUIOptions.onDestroy) {
301
+ this.floatingUIOptions.onDestroy();
302
+ }
303
+ }
304
+ };
305
+ var BubbleMenuPlugin = (options) => {
306
+ return new import_state.Plugin({
307
+ key: typeof options.pluginKey === "string" ? new import_state.PluginKey(options.pluginKey) : options.pluginKey,
308
+ view: (view) => new BubbleMenuView({ view, ...options })
309
+ });
310
+ };
311
+ var BubbleMenu = import_core.Extension.create({
312
+ name: "bubbleMenu",
313
+ addOptions() {
314
+ return {
315
+ element: null,
316
+ pluginKey: "bubbleMenu",
317
+ updateDelay: void 0,
318
+ shouldShow: null
319
+ };
320
+ },
321
+ addProseMirrorPlugins() {
322
+ if (!this.options.element) {
323
+ return [];
324
+ }
325
+ return [
326
+ BubbleMenuPlugin({
327
+ pluginKey: this.options.pluginKey,
328
+ editor: this.editor,
329
+ element: this.options.element,
330
+ updateDelay: this.options.updateDelay,
331
+ shouldShow: this.options.shouldShow
332
+ })
333
+ ];
334
+ }
335
+ });
336
+
337
+ // src/menus/BubbleMenu.ts
338
+ var import_vue = require("vue");
339
+ var BubbleMenu2 = (0, import_vue.defineComponent)({
340
+ name: "BubbleMenu",
341
+ props: {
342
+ pluginKey: {
343
+ type: [String, Object],
344
+ default: "bubbleMenu"
345
+ },
346
+ editor: {
347
+ type: Object,
348
+ required: true
349
+ },
350
+ updateDelay: {
351
+ type: Number,
352
+ default: void 0
353
+ },
354
+ resizeDelay: {
355
+ type: Number,
356
+ default: void 0
357
+ },
358
+ options: {
359
+ type: Object,
360
+ default: () => ({})
361
+ },
362
+ shouldShow: {
363
+ type: Function,
364
+ default: null
365
+ }
366
+ },
367
+ setup(props, { slots }) {
368
+ const root = (0, import_vue.ref)(null);
369
+ (0, import_vue.onMounted)(() => {
370
+ const { editor, options, pluginKey, resizeDelay, shouldShow, updateDelay } = props;
371
+ if (!root.value) {
372
+ return;
373
+ }
374
+ root.value.style.visibility = "hidden";
375
+ root.value.style.position = "absolute";
376
+ root.value.remove();
377
+ editor.registerPlugin(
378
+ BubbleMenuPlugin({
379
+ editor,
380
+ element: root.value,
381
+ options,
382
+ pluginKey,
383
+ resizeDelay,
384
+ shouldShow,
385
+ updateDelay
386
+ })
387
+ );
388
+ });
389
+ (0, import_vue.onBeforeUnmount)(() => {
390
+ const { pluginKey, editor } = props;
391
+ editor.unregisterPlugin(pluginKey);
392
+ });
393
+ return () => {
394
+ var _a;
395
+ return (0, import_vue.h)(import_vue.Teleport, { to: "body" }, (0, import_vue.h)("div", { ref: root }, (_a = slots.default) == null ? void 0 : _a.call(slots)));
396
+ };
397
+ }
398
+ });
399
+
400
+ // ../extension-floating-menu/dist/index.js
401
+ var import_core3 = require("@tiptap/core");
402
+ var import_dom2 = require("@floating-ui/dom");
403
+ var import_core4 = require("@tiptap/core");
404
+ var import_state2 = require("@tiptap/pm/state");
405
+ var FloatingMenuView = class {
406
+ constructor({ editor, element, view, options, shouldShow }) {
407
+ this.preventHide = false;
408
+ this.isVisible = false;
409
+ this.shouldShow = ({ view: view2, state }) => {
410
+ const { selection } = state;
411
+ const { $anchor, empty } = selection;
412
+ const isRootDepth = $anchor.depth === 1;
413
+ const isEmptyTextBlock = $anchor.parent.isTextblock && !$anchor.parent.type.spec.code && !$anchor.parent.textContent && $anchor.parent.childCount === 0 && !this.getTextContent($anchor.parent);
414
+ if (!view2.hasFocus() || !empty || !isRootDepth || !isEmptyTextBlock || !this.editor.isEditable) {
415
+ return false;
416
+ }
417
+ return true;
418
+ };
419
+ this.floatingUIOptions = {
420
+ strategy: "absolute",
421
+ placement: "right",
422
+ offset: 8,
423
+ flip: {},
424
+ shift: {},
425
+ arrow: false,
426
+ size: false,
427
+ autoPlacement: false,
428
+ hide: false,
429
+ inline: false
430
+ };
431
+ this.updateHandler = (view2, selectionChanged, docChanged, oldState) => {
432
+ const { composing } = view2;
433
+ const isSame = !selectionChanged && !docChanged;
434
+ if (composing || isSame) {
435
+ return;
436
+ }
437
+ const shouldShow2 = this.getShouldShow(oldState);
438
+ if (!shouldShow2) {
439
+ this.hide();
440
+ return;
441
+ }
442
+ this.updatePosition();
443
+ this.show();
444
+ };
445
+ this.mousedownHandler = () => {
446
+ this.preventHide = true;
447
+ };
448
+ this.focusHandler = () => {
449
+ setTimeout(() => this.update(this.editor.view));
450
+ };
451
+ this.blurHandler = ({ event }) => {
452
+ var _a;
453
+ if (this.preventHide) {
454
+ this.preventHide = false;
455
+ return;
456
+ }
457
+ if ((event == null ? void 0 : event.relatedTarget) && ((_a = this.element.parentNode) == null ? void 0 : _a.contains(event.relatedTarget))) {
458
+ return;
459
+ }
460
+ if ((event == null ? void 0 : event.relatedTarget) === this.editor.view.dom) {
461
+ return;
462
+ }
463
+ this.hide();
464
+ };
465
+ this.editor = editor;
466
+ this.element = element;
467
+ this.view = view;
468
+ this.floatingUIOptions = {
469
+ ...this.floatingUIOptions,
470
+ ...options
471
+ };
472
+ this.element.tabIndex = 0;
473
+ if (shouldShow) {
474
+ this.shouldShow = shouldShow;
475
+ }
476
+ this.element.addEventListener("mousedown", this.mousedownHandler, { capture: true });
477
+ this.editor.on("focus", this.focusHandler);
478
+ this.editor.on("blur", this.blurHandler);
479
+ this.update(view, view.state);
480
+ if (this.getShouldShow()) {
481
+ this.show();
482
+ }
483
+ }
484
+ getTextContent(node) {
485
+ return (0, import_core4.getText)(node, { textSerializers: (0, import_core4.getTextSerializersFromSchema)(this.editor.schema) });
486
+ }
487
+ get middlewares() {
488
+ const middlewares = [];
489
+ if (this.floatingUIOptions.flip) {
490
+ middlewares.push((0, import_dom2.flip)(typeof this.floatingUIOptions.flip !== "boolean" ? this.floatingUIOptions.flip : void 0));
491
+ }
492
+ if (this.floatingUIOptions.shift) {
493
+ middlewares.push(
494
+ (0, import_dom2.shift)(typeof this.floatingUIOptions.shift !== "boolean" ? this.floatingUIOptions.shift : void 0)
495
+ );
496
+ }
497
+ if (this.floatingUIOptions.offset) {
498
+ middlewares.push(
499
+ (0, import_dom2.offset)(typeof this.floatingUIOptions.offset !== "boolean" ? this.floatingUIOptions.offset : void 0)
500
+ );
501
+ }
502
+ if (this.floatingUIOptions.arrow) {
503
+ middlewares.push((0, import_dom2.arrow)(this.floatingUIOptions.arrow));
504
+ }
505
+ if (this.floatingUIOptions.size) {
506
+ middlewares.push((0, import_dom2.size)(typeof this.floatingUIOptions.size !== "boolean" ? this.floatingUIOptions.size : void 0));
507
+ }
508
+ if (this.floatingUIOptions.autoPlacement) {
509
+ middlewares.push(
510
+ (0, import_dom2.autoPlacement)(
511
+ typeof this.floatingUIOptions.autoPlacement !== "boolean" ? this.floatingUIOptions.autoPlacement : void 0
512
+ )
513
+ );
514
+ }
515
+ if (this.floatingUIOptions.hide) {
516
+ middlewares.push((0, import_dom2.hide)(typeof this.floatingUIOptions.hide !== "boolean" ? this.floatingUIOptions.hide : void 0));
517
+ }
518
+ if (this.floatingUIOptions.inline) {
519
+ middlewares.push(
520
+ (0, import_dom2.inline)(typeof this.floatingUIOptions.inline !== "boolean" ? this.floatingUIOptions.inline : void 0)
521
+ );
522
+ }
523
+ return middlewares;
524
+ }
525
+ getShouldShow(oldState) {
526
+ var _a;
527
+ const { state } = this.view;
528
+ const { selection } = state;
529
+ const { ranges } = selection;
530
+ const from = Math.min(...ranges.map((range) => range.$from.pos));
531
+ const to = Math.max(...ranges.map((range) => range.$to.pos));
532
+ const shouldShow = (_a = this.shouldShow) == null ? void 0 : _a.call(this, {
533
+ editor: this.editor,
534
+ view: this.view,
535
+ state,
536
+ oldState,
537
+ from,
538
+ to
539
+ });
540
+ return shouldShow;
541
+ }
542
+ updatePosition() {
543
+ const { selection } = this.editor.state;
544
+ const virtualElement = {
545
+ getBoundingClientRect: () => (0, import_core4.posToDOMRect)(this.view, selection.from, selection.to)
546
+ };
547
+ (0, import_dom2.computePosition)(virtualElement, this.element, {
548
+ placement: this.floatingUIOptions.placement,
549
+ strategy: this.floatingUIOptions.strategy,
550
+ middleware: this.middlewares
551
+ }).then(({ x, y, strategy }) => {
552
+ this.element.style.width = "max-content";
553
+ this.element.style.position = strategy;
554
+ this.element.style.left = `${x}px`;
555
+ this.element.style.top = `${y}px`;
556
+ if (this.isVisible && this.floatingUIOptions.onUpdate) {
557
+ this.floatingUIOptions.onUpdate();
558
+ }
559
+ });
560
+ }
561
+ update(view, oldState) {
562
+ const selectionChanged = !(oldState == null ? void 0 : oldState.selection.eq(view.state.selection));
563
+ const docChanged = !(oldState == null ? void 0 : oldState.doc.eq(view.state.doc));
564
+ this.updateHandler(view, selectionChanged, docChanged, oldState);
565
+ }
566
+ show() {
567
+ var _a;
568
+ if (this.isVisible) {
569
+ return;
570
+ }
571
+ this.element.style.visibility = "visible";
572
+ this.element.style.opacity = "1";
573
+ (_a = this.view.dom.parentElement) == null ? void 0 : _a.appendChild(this.element);
574
+ if (this.floatingUIOptions.onShow) {
575
+ this.floatingUIOptions.onShow();
576
+ }
577
+ this.isVisible = true;
578
+ }
579
+ hide() {
580
+ if (!this.isVisible) {
581
+ return;
582
+ }
583
+ this.element.style.visibility = "hidden";
584
+ this.element.style.opacity = "0";
585
+ this.element.remove();
586
+ if (this.floatingUIOptions.onHide) {
587
+ this.floatingUIOptions.onHide();
588
+ }
589
+ this.isVisible = false;
590
+ }
591
+ destroy() {
592
+ this.hide();
593
+ this.element.removeEventListener("mousedown", this.mousedownHandler, { capture: true });
594
+ this.editor.off("focus", this.focusHandler);
595
+ this.editor.off("blur", this.blurHandler);
596
+ if (this.floatingUIOptions.onDestroy) {
597
+ this.floatingUIOptions.onDestroy();
598
+ }
599
+ }
600
+ };
601
+ var FloatingMenuPlugin = (options) => {
602
+ return new import_state2.Plugin({
603
+ key: typeof options.pluginKey === "string" ? new import_state2.PluginKey(options.pluginKey) : options.pluginKey,
604
+ view: (view) => new FloatingMenuView({ view, ...options })
605
+ });
606
+ };
607
+ var FloatingMenu = import_core3.Extension.create({
608
+ name: "floatingMenu",
609
+ addOptions() {
610
+ return {
611
+ element: null,
612
+ options: {},
613
+ pluginKey: "floatingMenu",
614
+ shouldShow: null
615
+ };
616
+ },
617
+ addProseMirrorPlugins() {
618
+ if (!this.options.element) {
619
+ return [];
620
+ }
621
+ return [
622
+ FloatingMenuPlugin({
623
+ pluginKey: this.options.pluginKey,
624
+ editor: this.editor,
625
+ element: this.options.element,
626
+ options: this.options.options,
627
+ shouldShow: this.options.shouldShow
628
+ })
629
+ ];
630
+ }
631
+ });
632
+
633
+ // src/menus/FloatingMenu.ts
634
+ var import_vue2 = require("vue");
635
+ var FloatingMenu2 = (0, import_vue2.defineComponent)({
636
+ name: "FloatingMenu",
637
+ props: {
638
+ pluginKey: {
639
+ // TODO: TypeScript breaks :(
640
+ // type: [String, Object as PropType<Exclude<FloatingMenuPluginProps['pluginKey'], string>>],
641
+ type: null,
642
+ default: "floatingMenu"
643
+ },
644
+ editor: {
645
+ type: Object,
646
+ required: true
647
+ },
648
+ options: {
649
+ type: Object,
650
+ default: () => ({})
651
+ },
652
+ shouldShow: {
653
+ type: Function,
654
+ default: null
655
+ }
656
+ },
657
+ setup(props, { slots }) {
658
+ const root = (0, import_vue2.ref)(null);
659
+ (0, import_vue2.onMounted)(() => {
660
+ const { pluginKey, editor, options, shouldShow } = props;
661
+ if (!root.value) {
662
+ return;
663
+ }
664
+ root.value.style.visibility = "hidden";
665
+ root.value.style.position = "absolute";
666
+ root.value.remove();
667
+ editor.registerPlugin(
668
+ FloatingMenuPlugin({
669
+ pluginKey,
670
+ editor,
671
+ element: root.value,
672
+ options,
673
+ shouldShow
674
+ })
675
+ );
676
+ });
677
+ (0, import_vue2.onBeforeUnmount)(() => {
678
+ const { pluginKey, editor } = props;
679
+ editor.unregisterPlugin(pluginKey);
680
+ });
681
+ return () => {
682
+ var _a;
683
+ return (0, import_vue2.h)(import_vue2.Teleport, { to: "body" }, (0, import_vue2.h)("div", { ref: root }, (_a = slots.default) == null ? void 0 : _a.call(slots)));
684
+ };
685
+ }
686
+ });
687
+ // Annotate the CommonJS export names for ESM import in node:
688
+ 0 && (module.exports = {
689
+ BubbleMenu,
690
+ FloatingMenu
691
+ });
692
+ //# sourceMappingURL=index.cjs.map