@tiptap/vue-3 3.0.0 → 3.0.2

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 +693 -0
  10. package/dist/menus/index.cjs.map +1 -0
  11. package/dist/menus/index.d.cts +279 -0
  12. package/dist/menus/index.d.ts +279 -0
  13. package/dist/menus/index.js +685 -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,693 @@
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
+ options: this.options.options,
332
+ shouldShow: this.options.shouldShow
333
+ })
334
+ ];
335
+ }
336
+ });
337
+
338
+ // src/menus/BubbleMenu.ts
339
+ var import_vue = require("vue");
340
+ var BubbleMenu2 = (0, import_vue.defineComponent)({
341
+ name: "BubbleMenu",
342
+ props: {
343
+ pluginKey: {
344
+ type: [String, Object],
345
+ default: "bubbleMenu"
346
+ },
347
+ editor: {
348
+ type: Object,
349
+ required: true
350
+ },
351
+ updateDelay: {
352
+ type: Number,
353
+ default: void 0
354
+ },
355
+ resizeDelay: {
356
+ type: Number,
357
+ default: void 0
358
+ },
359
+ options: {
360
+ type: Object,
361
+ default: () => ({})
362
+ },
363
+ shouldShow: {
364
+ type: Function,
365
+ default: null
366
+ }
367
+ },
368
+ setup(props, { slots }) {
369
+ const root = (0, import_vue.ref)(null);
370
+ (0, import_vue.onMounted)(() => {
371
+ const { editor, options, pluginKey, resizeDelay, shouldShow, updateDelay } = props;
372
+ if (!root.value) {
373
+ return;
374
+ }
375
+ root.value.style.visibility = "hidden";
376
+ root.value.style.position = "absolute";
377
+ root.value.remove();
378
+ editor.registerPlugin(
379
+ BubbleMenuPlugin({
380
+ editor,
381
+ element: root.value,
382
+ options,
383
+ pluginKey,
384
+ resizeDelay,
385
+ shouldShow,
386
+ updateDelay
387
+ })
388
+ );
389
+ });
390
+ (0, import_vue.onBeforeUnmount)(() => {
391
+ const { pluginKey, editor } = props;
392
+ editor.unregisterPlugin(pluginKey);
393
+ });
394
+ return () => {
395
+ var _a;
396
+ 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)));
397
+ };
398
+ }
399
+ });
400
+
401
+ // ../extension-floating-menu/dist/index.js
402
+ var import_core3 = require("@tiptap/core");
403
+ var import_dom2 = require("@floating-ui/dom");
404
+ var import_core4 = require("@tiptap/core");
405
+ var import_state2 = require("@tiptap/pm/state");
406
+ var FloatingMenuView = class {
407
+ constructor({ editor, element, view, options, shouldShow }) {
408
+ this.preventHide = false;
409
+ this.isVisible = false;
410
+ this.shouldShow = ({ view: view2, state }) => {
411
+ const { selection } = state;
412
+ const { $anchor, empty } = selection;
413
+ const isRootDepth = $anchor.depth === 1;
414
+ const isEmptyTextBlock = $anchor.parent.isTextblock && !$anchor.parent.type.spec.code && !$anchor.parent.textContent && $anchor.parent.childCount === 0 && !this.getTextContent($anchor.parent);
415
+ if (!view2.hasFocus() || !empty || !isRootDepth || !isEmptyTextBlock || !this.editor.isEditable) {
416
+ return false;
417
+ }
418
+ return true;
419
+ };
420
+ this.floatingUIOptions = {
421
+ strategy: "absolute",
422
+ placement: "right",
423
+ offset: 8,
424
+ flip: {},
425
+ shift: {},
426
+ arrow: false,
427
+ size: false,
428
+ autoPlacement: false,
429
+ hide: false,
430
+ inline: false
431
+ };
432
+ this.updateHandler = (view2, selectionChanged, docChanged, oldState) => {
433
+ const { composing } = view2;
434
+ const isSame = !selectionChanged && !docChanged;
435
+ if (composing || isSame) {
436
+ return;
437
+ }
438
+ const shouldShow2 = this.getShouldShow(oldState);
439
+ if (!shouldShow2) {
440
+ this.hide();
441
+ return;
442
+ }
443
+ this.updatePosition();
444
+ this.show();
445
+ };
446
+ this.mousedownHandler = () => {
447
+ this.preventHide = true;
448
+ };
449
+ this.focusHandler = () => {
450
+ setTimeout(() => this.update(this.editor.view));
451
+ };
452
+ this.blurHandler = ({ event }) => {
453
+ var _a;
454
+ if (this.preventHide) {
455
+ this.preventHide = false;
456
+ return;
457
+ }
458
+ if ((event == null ? void 0 : event.relatedTarget) && ((_a = this.element.parentNode) == null ? void 0 : _a.contains(event.relatedTarget))) {
459
+ return;
460
+ }
461
+ if ((event == null ? void 0 : event.relatedTarget) === this.editor.view.dom) {
462
+ return;
463
+ }
464
+ this.hide();
465
+ };
466
+ this.editor = editor;
467
+ this.element = element;
468
+ this.view = view;
469
+ this.floatingUIOptions = {
470
+ ...this.floatingUIOptions,
471
+ ...options
472
+ };
473
+ this.element.tabIndex = 0;
474
+ if (shouldShow) {
475
+ this.shouldShow = shouldShow;
476
+ }
477
+ this.element.addEventListener("mousedown", this.mousedownHandler, { capture: true });
478
+ this.editor.on("focus", this.focusHandler);
479
+ this.editor.on("blur", this.blurHandler);
480
+ this.update(view, view.state);
481
+ if (this.getShouldShow()) {
482
+ this.show();
483
+ }
484
+ }
485
+ getTextContent(node) {
486
+ return (0, import_core4.getText)(node, { textSerializers: (0, import_core4.getTextSerializersFromSchema)(this.editor.schema) });
487
+ }
488
+ get middlewares() {
489
+ const middlewares = [];
490
+ if (this.floatingUIOptions.flip) {
491
+ middlewares.push((0, import_dom2.flip)(typeof this.floatingUIOptions.flip !== "boolean" ? this.floatingUIOptions.flip : void 0));
492
+ }
493
+ if (this.floatingUIOptions.shift) {
494
+ middlewares.push(
495
+ (0, import_dom2.shift)(typeof this.floatingUIOptions.shift !== "boolean" ? this.floatingUIOptions.shift : void 0)
496
+ );
497
+ }
498
+ if (this.floatingUIOptions.offset) {
499
+ middlewares.push(
500
+ (0, import_dom2.offset)(typeof this.floatingUIOptions.offset !== "boolean" ? this.floatingUIOptions.offset : void 0)
501
+ );
502
+ }
503
+ if (this.floatingUIOptions.arrow) {
504
+ middlewares.push((0, import_dom2.arrow)(this.floatingUIOptions.arrow));
505
+ }
506
+ if (this.floatingUIOptions.size) {
507
+ middlewares.push((0, import_dom2.size)(typeof this.floatingUIOptions.size !== "boolean" ? this.floatingUIOptions.size : void 0));
508
+ }
509
+ if (this.floatingUIOptions.autoPlacement) {
510
+ middlewares.push(
511
+ (0, import_dom2.autoPlacement)(
512
+ typeof this.floatingUIOptions.autoPlacement !== "boolean" ? this.floatingUIOptions.autoPlacement : void 0
513
+ )
514
+ );
515
+ }
516
+ if (this.floatingUIOptions.hide) {
517
+ middlewares.push((0, import_dom2.hide)(typeof this.floatingUIOptions.hide !== "boolean" ? this.floatingUIOptions.hide : void 0));
518
+ }
519
+ if (this.floatingUIOptions.inline) {
520
+ middlewares.push(
521
+ (0, import_dom2.inline)(typeof this.floatingUIOptions.inline !== "boolean" ? this.floatingUIOptions.inline : void 0)
522
+ );
523
+ }
524
+ return middlewares;
525
+ }
526
+ getShouldShow(oldState) {
527
+ var _a;
528
+ const { state } = this.view;
529
+ const { selection } = state;
530
+ const { ranges } = selection;
531
+ const from = Math.min(...ranges.map((range) => range.$from.pos));
532
+ const to = Math.max(...ranges.map((range) => range.$to.pos));
533
+ const shouldShow = (_a = this.shouldShow) == null ? void 0 : _a.call(this, {
534
+ editor: this.editor,
535
+ view: this.view,
536
+ state,
537
+ oldState,
538
+ from,
539
+ to
540
+ });
541
+ return shouldShow;
542
+ }
543
+ updatePosition() {
544
+ const { selection } = this.editor.state;
545
+ const virtualElement = {
546
+ getBoundingClientRect: () => (0, import_core4.posToDOMRect)(this.view, selection.from, selection.to)
547
+ };
548
+ (0, import_dom2.computePosition)(virtualElement, this.element, {
549
+ placement: this.floatingUIOptions.placement,
550
+ strategy: this.floatingUIOptions.strategy,
551
+ middleware: this.middlewares
552
+ }).then(({ x, y, strategy }) => {
553
+ this.element.style.width = "max-content";
554
+ this.element.style.position = strategy;
555
+ this.element.style.left = `${x}px`;
556
+ this.element.style.top = `${y}px`;
557
+ if (this.isVisible && this.floatingUIOptions.onUpdate) {
558
+ this.floatingUIOptions.onUpdate();
559
+ }
560
+ });
561
+ }
562
+ update(view, oldState) {
563
+ const selectionChanged = !(oldState == null ? void 0 : oldState.selection.eq(view.state.selection));
564
+ const docChanged = !(oldState == null ? void 0 : oldState.doc.eq(view.state.doc));
565
+ this.updateHandler(view, selectionChanged, docChanged, oldState);
566
+ }
567
+ show() {
568
+ var _a;
569
+ if (this.isVisible) {
570
+ return;
571
+ }
572
+ this.element.style.visibility = "visible";
573
+ this.element.style.opacity = "1";
574
+ (_a = this.view.dom.parentElement) == null ? void 0 : _a.appendChild(this.element);
575
+ if (this.floatingUIOptions.onShow) {
576
+ this.floatingUIOptions.onShow();
577
+ }
578
+ this.isVisible = true;
579
+ }
580
+ hide() {
581
+ if (!this.isVisible) {
582
+ return;
583
+ }
584
+ this.element.style.visibility = "hidden";
585
+ this.element.style.opacity = "0";
586
+ this.element.remove();
587
+ if (this.floatingUIOptions.onHide) {
588
+ this.floatingUIOptions.onHide();
589
+ }
590
+ this.isVisible = false;
591
+ }
592
+ destroy() {
593
+ this.hide();
594
+ this.element.removeEventListener("mousedown", this.mousedownHandler, { capture: true });
595
+ this.editor.off("focus", this.focusHandler);
596
+ this.editor.off("blur", this.blurHandler);
597
+ if (this.floatingUIOptions.onDestroy) {
598
+ this.floatingUIOptions.onDestroy();
599
+ }
600
+ }
601
+ };
602
+ var FloatingMenuPlugin = (options) => {
603
+ return new import_state2.Plugin({
604
+ key: typeof options.pluginKey === "string" ? new import_state2.PluginKey(options.pluginKey) : options.pluginKey,
605
+ view: (view) => new FloatingMenuView({ view, ...options })
606
+ });
607
+ };
608
+ var FloatingMenu = import_core3.Extension.create({
609
+ name: "floatingMenu",
610
+ addOptions() {
611
+ return {
612
+ element: null,
613
+ options: {},
614
+ pluginKey: "floatingMenu",
615
+ shouldShow: null
616
+ };
617
+ },
618
+ addProseMirrorPlugins() {
619
+ if (!this.options.element) {
620
+ return [];
621
+ }
622
+ return [
623
+ FloatingMenuPlugin({
624
+ pluginKey: this.options.pluginKey,
625
+ editor: this.editor,
626
+ element: this.options.element,
627
+ options: this.options.options,
628
+ shouldShow: this.options.shouldShow
629
+ })
630
+ ];
631
+ }
632
+ });
633
+
634
+ // src/menus/FloatingMenu.ts
635
+ var import_vue2 = require("vue");
636
+ var FloatingMenu2 = (0, import_vue2.defineComponent)({
637
+ name: "FloatingMenu",
638
+ props: {
639
+ pluginKey: {
640
+ // TODO: TypeScript breaks :(
641
+ // type: [String, Object as PropType<Exclude<FloatingMenuPluginProps['pluginKey'], string>>],
642
+ type: null,
643
+ default: "floatingMenu"
644
+ },
645
+ editor: {
646
+ type: Object,
647
+ required: true
648
+ },
649
+ options: {
650
+ type: Object,
651
+ default: () => ({})
652
+ },
653
+ shouldShow: {
654
+ type: Function,
655
+ default: null
656
+ }
657
+ },
658
+ setup(props, { slots }) {
659
+ const root = (0, import_vue2.ref)(null);
660
+ (0, import_vue2.onMounted)(() => {
661
+ const { pluginKey, editor, options, shouldShow } = props;
662
+ if (!root.value) {
663
+ return;
664
+ }
665
+ root.value.style.visibility = "hidden";
666
+ root.value.style.position = "absolute";
667
+ root.value.remove();
668
+ editor.registerPlugin(
669
+ FloatingMenuPlugin({
670
+ pluginKey,
671
+ editor,
672
+ element: root.value,
673
+ options,
674
+ shouldShow
675
+ })
676
+ );
677
+ });
678
+ (0, import_vue2.onBeforeUnmount)(() => {
679
+ const { pluginKey, editor } = props;
680
+ editor.unregisterPlugin(pluginKey);
681
+ });
682
+ return () => {
683
+ var _a;
684
+ 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)));
685
+ };
686
+ }
687
+ });
688
+ // Annotate the CommonJS export names for ESM import in node:
689
+ 0 && (module.exports = {
690
+ BubbleMenu,
691
+ FloatingMenu
692
+ });
693
+ //# sourceMappingURL=index.cjs.map