@tiptap/react 3.0.0 → 3.0.2-beta.0

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 (215) hide show
  1. package/LICENSE.md +21 -0
  2. package/README.md +5 -1
  3. package/dist/index.cjs +1030 -1163
  4. package/dist/index.cjs.map +1 -1
  5. package/dist/index.d.cts +350 -0
  6. package/dist/index.d.ts +350 -0
  7. package/dist/index.js +970 -1138
  8. package/dist/index.js.map +1 -1
  9. package/dist/menus/index.cjs +142 -0
  10. package/dist/menus/index.cjs.map +1 -0
  11. package/dist/menus/index.d.cts +19 -0
  12. package/dist/menus/index.d.ts +19 -0
  13. package/dist/menus/index.js +104 -0
  14. package/dist/menus/index.js.map +1 -0
  15. package/package.json +34 -21
  16. package/src/Context.tsx +18 -12
  17. package/src/Editor.ts +10 -11
  18. package/src/EditorContent.tsx +104 -64
  19. package/src/NodeViewContent.tsx +13 -8
  20. package/src/NodeViewWrapper.tsx +3 -2
  21. package/src/ReactMarkViewRenderer.tsx +111 -0
  22. package/src/ReactNodeViewRenderer.tsx +184 -67
  23. package/src/ReactRenderer.tsx +152 -51
  24. package/src/index.ts +2 -3
  25. package/src/menus/BubbleMenu.tsx +68 -0
  26. package/src/menus/FloatingMenu.tsx +68 -0
  27. package/src/menus/index.ts +2 -0
  28. package/src/types.ts +6 -0
  29. package/src/useEditor.ts +286 -166
  30. package/src/useEditorState.ts +133 -85
  31. package/src/useReactNodeView.ts +21 -5
  32. package/dist/index.umd.js +0 -1219
  33. package/dist/index.umd.js.map +0 -1
  34. package/dist/packages/core/src/CommandManager.d.ts +0 -20
  35. package/dist/packages/core/src/Editor.d.ts +0 -161
  36. package/dist/packages/core/src/EventEmitter.d.ts +0 -11
  37. package/dist/packages/core/src/Extension.d.ts +0 -343
  38. package/dist/packages/core/src/ExtensionManager.d.ts +0 -55
  39. package/dist/packages/core/src/InputRule.d.ts +0 -42
  40. package/dist/packages/core/src/Mark.d.ts +0 -451
  41. package/dist/packages/core/src/Node.d.ts +0 -611
  42. package/dist/packages/core/src/NodePos.d.ts +0 -44
  43. package/dist/packages/core/src/NodeView.d.ts +0 -31
  44. package/dist/packages/core/src/PasteRule.d.ts +0 -50
  45. package/dist/packages/core/src/Tracker.d.ts +0 -11
  46. package/dist/packages/core/src/commands/blur.d.ts +0 -13
  47. package/dist/packages/core/src/commands/clearContent.d.ts +0 -14
  48. package/dist/packages/core/src/commands/clearNodes.d.ts +0 -13
  49. package/dist/packages/core/src/commands/command.d.ts +0 -18
  50. package/dist/packages/core/src/commands/createParagraphNear.d.ts +0 -13
  51. package/dist/packages/core/src/commands/cut.d.ts +0 -20
  52. package/dist/packages/core/src/commands/deleteCurrentNode.d.ts +0 -13
  53. package/dist/packages/core/src/commands/deleteNode.d.ts +0 -15
  54. package/dist/packages/core/src/commands/deleteRange.d.ts +0 -14
  55. package/dist/packages/core/src/commands/deleteSelection.d.ts +0 -13
  56. package/dist/packages/core/src/commands/enter.d.ts +0 -13
  57. package/dist/packages/core/src/commands/exitCode.d.ts +0 -13
  58. package/dist/packages/core/src/commands/extendMarkRange.d.ts +0 -25
  59. package/dist/packages/core/src/commands/first.d.ts +0 -14
  60. package/dist/packages/core/src/commands/focus.d.ts +0 -27
  61. package/dist/packages/core/src/commands/forEach.d.ts +0 -14
  62. package/dist/packages/core/src/commands/index.d.ts +0 -55
  63. package/dist/packages/core/src/commands/insertContent.d.ts +0 -34
  64. package/dist/packages/core/src/commands/insertContentAt.d.ts +0 -47
  65. package/dist/packages/core/src/commands/join.d.ts +0 -41
  66. package/dist/packages/core/src/commands/joinItemBackward.d.ts +0 -13
  67. package/dist/packages/core/src/commands/joinItemForward.d.ts +0 -13
  68. package/dist/packages/core/src/commands/joinTextblockBackward.d.ts +0 -12
  69. package/dist/packages/core/src/commands/joinTextblockForward.d.ts +0 -12
  70. package/dist/packages/core/src/commands/keyboardShortcut.d.ts +0 -14
  71. package/dist/packages/core/src/commands/lift.d.ts +0 -17
  72. package/dist/packages/core/src/commands/liftEmptyBlock.d.ts +0 -13
  73. package/dist/packages/core/src/commands/liftListItem.d.ts +0 -15
  74. package/dist/packages/core/src/commands/newlineInCode.d.ts +0 -13
  75. package/dist/packages/core/src/commands/resetAttributes.d.ts +0 -16
  76. package/dist/packages/core/src/commands/scrollIntoView.d.ts +0 -13
  77. package/dist/packages/core/src/commands/selectAll.d.ts +0 -13
  78. package/dist/packages/core/src/commands/selectNodeBackward.d.ts +0 -13
  79. package/dist/packages/core/src/commands/selectNodeForward.d.ts +0 -13
  80. package/dist/packages/core/src/commands/selectParentNode.d.ts +0 -13
  81. package/dist/packages/core/src/commands/selectTextblockEnd.d.ts +0 -13
  82. package/dist/packages/core/src/commands/selectTextblockStart.d.ts +0 -13
  83. package/dist/packages/core/src/commands/setContent.d.ts +0 -40
  84. package/dist/packages/core/src/commands/setMark.d.ts +0 -15
  85. package/dist/packages/core/src/commands/setMeta.d.ts +0 -15
  86. package/dist/packages/core/src/commands/setNode.d.ts +0 -16
  87. package/dist/packages/core/src/commands/setNodeSelection.d.ts +0 -14
  88. package/dist/packages/core/src/commands/setTextSelection.d.ts +0 -14
  89. package/dist/packages/core/src/commands/sinkListItem.d.ts +0 -15
  90. package/dist/packages/core/src/commands/splitBlock.d.ts +0 -17
  91. package/dist/packages/core/src/commands/splitListItem.d.ts +0 -15
  92. package/dist/packages/core/src/commands/toggleList.d.ts +0 -18
  93. package/dist/packages/core/src/commands/toggleMark.d.ts +0 -30
  94. package/dist/packages/core/src/commands/toggleNode.d.ts +0 -17
  95. package/dist/packages/core/src/commands/toggleWrap.d.ts +0 -16
  96. package/dist/packages/core/src/commands/undoInputRule.d.ts +0 -13
  97. package/dist/packages/core/src/commands/unsetAllMarks.d.ts +0 -13
  98. package/dist/packages/core/src/commands/unsetMark.d.ts +0 -25
  99. package/dist/packages/core/src/commands/updateAttributes.d.ts +0 -24
  100. package/dist/packages/core/src/commands/wrapIn.d.ts +0 -16
  101. package/dist/packages/core/src/commands/wrapInList.d.ts +0 -16
  102. package/dist/packages/core/src/extensions/clipboardTextSerializer.d.ts +0 -5
  103. package/dist/packages/core/src/extensions/commands.d.ts +0 -3
  104. package/dist/packages/core/src/extensions/editable.d.ts +0 -2
  105. package/dist/packages/core/src/extensions/focusEvents.d.ts +0 -2
  106. package/dist/packages/core/src/extensions/index.d.ts +0 -6
  107. package/dist/packages/core/src/extensions/keymap.d.ts +0 -2
  108. package/dist/packages/core/src/extensions/tabindex.d.ts +0 -2
  109. package/dist/packages/core/src/helpers/combineTransactionSteps.d.ts +0 -10
  110. package/dist/packages/core/src/helpers/createChainableState.d.ts +0 -10
  111. package/dist/packages/core/src/helpers/createDocument.d.ts +0 -12
  112. package/dist/packages/core/src/helpers/createNodeFromContent.d.ts +0 -15
  113. package/dist/packages/core/src/helpers/defaultBlockAt.d.ts +0 -7
  114. package/dist/packages/core/src/helpers/findChildren.d.ts +0 -9
  115. package/dist/packages/core/src/helpers/findChildrenInRange.d.ts +0 -10
  116. package/dist/packages/core/src/helpers/findParentNode.d.ts +0 -16
  117. package/dist/packages/core/src/helpers/findParentNodeClosestToPos.d.ts +0 -17
  118. package/dist/packages/core/src/helpers/generateHTML.d.ts +0 -8
  119. package/dist/packages/core/src/helpers/generateJSON.d.ts +0 -8
  120. package/dist/packages/core/src/helpers/generateText.d.ts +0 -12
  121. package/dist/packages/core/src/helpers/getAttributes.d.ts +0 -9
  122. package/dist/packages/core/src/helpers/getAttributesFromExtensions.d.ts +0 -6
  123. package/dist/packages/core/src/helpers/getChangedRanges.d.ts +0 -11
  124. package/dist/packages/core/src/helpers/getDebugJSON.d.ts +0 -8
  125. package/dist/packages/core/src/helpers/getExtensionField.d.ts +0 -9
  126. package/dist/packages/core/src/helpers/getHTMLFromFragment.d.ts +0 -2
  127. package/dist/packages/core/src/helpers/getMarkAttributes.d.ts +0 -3
  128. package/dist/packages/core/src/helpers/getMarkRange.d.ts +0 -3
  129. package/dist/packages/core/src/helpers/getMarkType.d.ts +0 -2
  130. package/dist/packages/core/src/helpers/getMarksBetween.d.ts +0 -3
  131. package/dist/packages/core/src/helpers/getNodeAtPosition.d.ts +0 -11
  132. package/dist/packages/core/src/helpers/getNodeAttributes.d.ts +0 -3
  133. package/dist/packages/core/src/helpers/getNodeType.d.ts +0 -2
  134. package/dist/packages/core/src/helpers/getRenderedAttributes.d.ts +0 -3
  135. package/dist/packages/core/src/helpers/getSchema.d.ts +0 -4
  136. package/dist/packages/core/src/helpers/getSchemaByResolvedExtensions.d.ts +0 -10
  137. package/dist/packages/core/src/helpers/getSchemaTypeByName.d.ts +0 -8
  138. package/dist/packages/core/src/helpers/getSchemaTypeNameByName.d.ts +0 -8
  139. package/dist/packages/core/src/helpers/getSplittedAttributes.d.ts +0 -9
  140. package/dist/packages/core/src/helpers/getText.d.ts +0 -15
  141. package/dist/packages/core/src/helpers/getTextBetween.d.ts +0 -14
  142. package/dist/packages/core/src/helpers/getTextContentFromNodes.d.ts +0 -8
  143. package/dist/packages/core/src/helpers/getTextSerializersFromSchema.d.ts +0 -8
  144. package/dist/packages/core/src/helpers/index.d.ts +0 -50
  145. package/dist/packages/core/src/helpers/injectExtensionAttributesToParseRule.d.ts +0 -9
  146. package/dist/packages/core/src/helpers/isActive.d.ts +0 -2
  147. package/dist/packages/core/src/helpers/isAtEndOfNode.d.ts +0 -2
  148. package/dist/packages/core/src/helpers/isAtStartOfNode.d.ts +0 -2
  149. package/dist/packages/core/src/helpers/isExtensionRulesEnabled.d.ts +0 -2
  150. package/dist/packages/core/src/helpers/isList.d.ts +0 -2
  151. package/dist/packages/core/src/helpers/isMarkActive.d.ts +0 -3
  152. package/dist/packages/core/src/helpers/isNodeActive.d.ts +0 -3
  153. package/dist/packages/core/src/helpers/isNodeEmpty.d.ts +0 -2
  154. package/dist/packages/core/src/helpers/isNodeSelection.d.ts +0 -2
  155. package/dist/packages/core/src/helpers/isTextSelection.d.ts +0 -2
  156. package/dist/packages/core/src/helpers/posToDOMRect.d.ts +0 -2
  157. package/dist/packages/core/src/helpers/resolveFocusPosition.d.ts +0 -4
  158. package/dist/packages/core/src/helpers/selectionToInsertionEnd.d.ts +0 -2
  159. package/dist/packages/core/src/helpers/splitExtensions.d.ts +0 -9
  160. package/dist/packages/core/src/index.d.ts +0 -24
  161. package/dist/packages/core/src/inputRules/index.d.ts +0 -5
  162. package/dist/packages/core/src/inputRules/markInputRule.d.ts +0 -13
  163. package/dist/packages/core/src/inputRules/nodeInputRule.d.ts +0 -23
  164. package/dist/packages/core/src/inputRules/textInputRule.d.ts +0 -10
  165. package/dist/packages/core/src/inputRules/textblockTypeInputRule.d.ts +0 -15
  166. package/dist/packages/core/src/inputRules/wrappingInputRule.d.ts +0 -28
  167. package/dist/packages/core/src/pasteRules/index.d.ts +0 -3
  168. package/dist/packages/core/src/pasteRules/markPasteRule.d.ts +0 -13
  169. package/dist/packages/core/src/pasteRules/nodePasteRule.d.ts +0 -13
  170. package/dist/packages/core/src/pasteRules/textPasteRule.d.ts +0 -10
  171. package/dist/packages/core/src/style.d.ts +0 -1
  172. package/dist/packages/core/src/types.d.ts +0 -255
  173. package/dist/packages/core/src/utilities/callOrReturn.d.ts +0 -9
  174. package/dist/packages/core/src/utilities/createStyleTag.d.ts +0 -1
  175. package/dist/packages/core/src/utilities/deleteProps.d.ts +0 -6
  176. package/dist/packages/core/src/utilities/elementFromString.d.ts +0 -1
  177. package/dist/packages/core/src/utilities/escapeForRegEx.d.ts +0 -1
  178. package/dist/packages/core/src/utilities/findDuplicates.d.ts +0 -1
  179. package/dist/packages/core/src/utilities/fromString.d.ts +0 -1
  180. package/dist/packages/core/src/utilities/index.d.ts +0 -20
  181. package/dist/packages/core/src/utilities/isAndroid.d.ts +0 -1
  182. package/dist/packages/core/src/utilities/isEmptyObject.d.ts +0 -1
  183. package/dist/packages/core/src/utilities/isFunction.d.ts +0 -1
  184. package/dist/packages/core/src/utilities/isMacOS.d.ts +0 -1
  185. package/dist/packages/core/src/utilities/isNumber.d.ts +0 -1
  186. package/dist/packages/core/src/utilities/isPlainObject.d.ts +0 -1
  187. package/dist/packages/core/src/utilities/isRegExp.d.ts +0 -1
  188. package/dist/packages/core/src/utilities/isString.d.ts +0 -1
  189. package/dist/packages/core/src/utilities/isiOS.d.ts +0 -1
  190. package/dist/packages/core/src/utilities/mergeAttributes.d.ts +0 -1
  191. package/dist/packages/core/src/utilities/mergeDeep.d.ts +0 -1
  192. package/dist/packages/core/src/utilities/minMax.d.ts +0 -1
  193. package/dist/packages/core/src/utilities/objectIncludes.d.ts +0 -8
  194. package/dist/packages/core/src/utilities/removeDuplicates.d.ts +0 -8
  195. package/dist/packages/extension-bubble-menu/src/bubble-menu-plugin.d.ts +0 -76
  196. package/dist/packages/extension-bubble-menu/src/bubble-menu.d.ts +0 -15
  197. package/dist/packages/extension-bubble-menu/src/index.d.ts +0 -4
  198. package/dist/packages/extension-floating-menu/src/floating-menu-plugin.d.ts +0 -66
  199. package/dist/packages/extension-floating-menu/src/floating-menu.d.ts +0 -15
  200. package/dist/packages/extension-floating-menu/src/index.d.ts +0 -4
  201. package/dist/packages/react/src/BubbleMenu.d.ts +0 -11
  202. package/dist/packages/react/src/Context.d.ts +0 -23
  203. package/dist/packages/react/src/Editor.d.ts +0 -12
  204. package/dist/packages/react/src/EditorContent.d.ts +0 -24
  205. package/dist/packages/react/src/FloatingMenu.d.ts +0 -10
  206. package/dist/packages/react/src/NodeViewContent.d.ts +0 -6
  207. package/dist/packages/react/src/NodeViewWrapper.d.ts +0 -6
  208. package/dist/packages/react/src/ReactNodeViewRenderer.d.ts +0 -16
  209. package/dist/packages/react/src/ReactRenderer.d.ts +0 -62
  210. package/dist/packages/react/src/index.d.ts +0 -13
  211. package/dist/packages/react/src/useEditor.d.ts +0 -39
  212. package/dist/packages/react/src/useEditorState.d.ts +0 -22
  213. package/dist/packages/react/src/useReactNodeView.d.ts +0 -6
  214. package/src/BubbleMenu.tsx +0 -57
  215. package/src/FloatingMenu.tsx +0 -64
package/dist/index.js CHANGED
@@ -1,1196 +1,1028 @@
1
- import { BubbleMenuPlugin } from '@tiptap/extension-bubble-menu';
2
- import React, { forwardRef, useState, useEffect, useDebugValue, useRef, createContext, useContext } from 'react';
3
- import ReactDOM, { flushSync } from 'react-dom';
4
- import { Editor as Editor$1, NodeView } from '@tiptap/core';
5
- export * from '@tiptap/core';
6
- import { FloatingMenuPlugin } from '@tiptap/extension-floating-menu';
7
-
8
- const mergeRefs = (...refs) => {
9
- return (node) => {
10
- refs.forEach(ref => {
11
- if (typeof ref === 'function') {
12
- ref(node);
13
- }
14
- else if (ref) {
15
- ref.current = node;
16
- }
17
- });
18
- };
1
+ // src/Context.tsx
2
+ import { createContext, useContext, useMemo } from "react";
3
+
4
+ // src/EditorContent.tsx
5
+ import React, { forwardRef } from "react";
6
+ import ReactDOM from "react-dom";
7
+ import { useSyncExternalStore } from "use-sync-external-store/shim/index.js";
8
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
9
+ var mergeRefs = (...refs) => {
10
+ return (node) => {
11
+ refs.forEach((ref) => {
12
+ if (typeof ref === "function") {
13
+ ref(node);
14
+ } else if (ref) {
15
+ ;
16
+ ref.current = node;
17
+ }
18
+ });
19
+ };
19
20
  };
20
- const Portals = ({ renderers }) => {
21
- return (React.createElement(React.Fragment, null, Object.entries(renderers).map(([key, renderer]) => {
22
- return ReactDOM.createPortal(renderer.reactElement, renderer.element, key);
23
- })));
21
+ var Portals = ({ contentComponent }) => {
22
+ const renderers = useSyncExternalStore(
23
+ contentComponent.subscribe,
24
+ contentComponent.getSnapshot,
25
+ contentComponent.getServerSnapshot
26
+ );
27
+ return /* @__PURE__ */ jsx(Fragment, { children: Object.values(renderers) });
24
28
  };
25
- class PureEditorContent extends React.Component {
26
- constructor(props) {
27
- super(props);
28
- this.editorContentRef = React.createRef();
29
- this.initialized = false;
30
- this.state = {
31
- renderers: {},
32
- };
33
- }
34
- componentDidMount() {
35
- this.init();
36
- }
37
- componentDidUpdate() {
38
- this.init();
29
+ function getInstance() {
30
+ const subscribers = /* @__PURE__ */ new Set();
31
+ let renderers = {};
32
+ return {
33
+ /**
34
+ * Subscribe to the editor instance's changes.
35
+ */
36
+ subscribe(callback) {
37
+ subscribers.add(callback);
38
+ return () => {
39
+ subscribers.delete(callback);
40
+ };
41
+ },
42
+ getSnapshot() {
43
+ return renderers;
44
+ },
45
+ getServerSnapshot() {
46
+ return renderers;
47
+ },
48
+ /**
49
+ * Adds a new NodeView Renderer to the editor.
50
+ */
51
+ setRenderer(id, renderer) {
52
+ renderers = {
53
+ ...renderers,
54
+ [id]: ReactDOM.createPortal(renderer.reactElement, renderer.element, id)
55
+ };
56
+ subscribers.forEach((subscriber) => subscriber());
57
+ },
58
+ /**
59
+ * Removes a NodeView Renderer from the editor.
60
+ */
61
+ removeRenderer(id) {
62
+ const nextRenderers = { ...renderers };
63
+ delete nextRenderers[id];
64
+ renderers = nextRenderers;
65
+ subscribers.forEach((subscriber) => subscriber());
39
66
  }
40
- init() {
41
- const { editor } = this.props;
42
- if (editor && !editor.isDestroyed && editor.options.element) {
43
- if (editor.contentComponent) {
44
- return;
67
+ };
68
+ }
69
+ var PureEditorContent = class extends React.Component {
70
+ constructor(props) {
71
+ var _a;
72
+ super(props);
73
+ this.editorContentRef = React.createRef();
74
+ this.initialized = false;
75
+ this.state = {
76
+ hasContentComponentInitialized: Boolean((_a = props.editor) == null ? void 0 : _a.contentComponent)
77
+ };
78
+ }
79
+ componentDidMount() {
80
+ this.init();
81
+ }
82
+ componentDidUpdate() {
83
+ this.init();
84
+ }
85
+ init() {
86
+ const editor = this.props.editor;
87
+ if (editor && !editor.isDestroyed && editor.options.element) {
88
+ if (editor.contentComponent) {
89
+ return;
90
+ }
91
+ const element = this.editorContentRef.current;
92
+ element.append(...editor.options.element.childNodes);
93
+ editor.setOptions({
94
+ element
95
+ });
96
+ editor.contentComponent = getInstance();
97
+ if (!this.state.hasContentComponentInitialized) {
98
+ this.unsubscribeToContentComponent = editor.contentComponent.subscribe(() => {
99
+ this.setState((prevState) => {
100
+ if (!prevState.hasContentComponentInitialized) {
101
+ return {
102
+ hasContentComponentInitialized: true
103
+ };
45
104
  }
46
- const element = this.editorContentRef.current;
47
- element.append(...editor.options.element.childNodes);
48
- editor.setOptions({
49
- element,
50
- });
51
- editor.contentComponent = this;
52
- editor.createNodeViews();
53
- this.initialized = true;
54
- }
55
- }
56
- maybeFlushSync(fn) {
57
- // Avoid calling flushSync until the editor is initialized.
58
- // Initialization happens during the componentDidMount or componentDidUpdate
59
- // lifecycle methods, and React doesn't allow calling flushSync from inside
60
- // a lifecycle method.
61
- if (this.initialized) {
62
- flushSync(fn);
63
- }
64
- else {
65
- fn();
66
- }
67
- }
68
- setRenderer(id, renderer) {
69
- this.maybeFlushSync(() => {
70
- this.setState(({ renderers }) => ({
71
- renderers: {
72
- ...renderers,
73
- [id]: renderer,
74
- },
75
- }));
105
+ return prevState;
106
+ });
107
+ if (this.unsubscribeToContentComponent) {
108
+ this.unsubscribeToContentComponent();
109
+ }
76
110
  });
111
+ }
112
+ editor.createNodeViews();
113
+ this.initialized = true;
77
114
  }
78
- removeRenderer(id) {
79
- this.maybeFlushSync(() => {
80
- this.setState(({ renderers }) => {
81
- const nextRenderers = { ...renderers };
82
- delete nextRenderers[id];
83
- return { renderers: nextRenderers };
84
- });
85
- });
115
+ }
116
+ componentWillUnmount() {
117
+ var _a;
118
+ const editor = this.props.editor;
119
+ if (!editor) {
120
+ return;
86
121
  }
87
- componentWillUnmount() {
88
- const { editor } = this.props;
89
- if (!editor) {
90
- return;
91
- }
92
- this.initialized = false;
93
- if (!editor.isDestroyed) {
94
- editor.view.setProps({
95
- nodeViews: {},
96
- });
97
- }
98
- editor.contentComponent = null;
99
- if (!editor.options.element.firstChild) {
100
- return;
101
- }
102
- const newElement = document.createElement('div');
103
- newElement.append(...editor.options.element.childNodes);
104
- editor.setOptions({
105
- element: newElement,
106
- });
122
+ this.initialized = false;
123
+ if (!editor.isDestroyed) {
124
+ editor.view.setProps({
125
+ nodeViews: {}
126
+ });
107
127
  }
108
- render() {
109
- const { editor, innerRef, ...rest } = this.props;
110
- return (React.createElement(React.Fragment, null,
111
- React.createElement("div", { ref: mergeRefs(innerRef, this.editorContentRef), ...rest }),
112
- React.createElement(Portals, { renderers: this.state.renderers })));
128
+ if (this.unsubscribeToContentComponent) {
129
+ this.unsubscribeToContentComponent();
113
130
  }
114
- }
115
- // EditorContent should be re-created whenever the Editor instance changes
116
- const EditorContentWithKey = forwardRef((props, ref) => {
131
+ editor.contentComponent = null;
132
+ if (!((_a = editor.options.element) == null ? void 0 : _a.firstChild)) {
133
+ return;
134
+ }
135
+ const newElement = document.createElement("div");
136
+ newElement.append(...editor.options.element.childNodes);
137
+ editor.setOptions({
138
+ element: newElement
139
+ });
140
+ }
141
+ render() {
142
+ const { editor, innerRef, ...rest } = this.props;
143
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
144
+ /* @__PURE__ */ jsx("div", { ref: mergeRefs(innerRef, this.editorContentRef), ...rest }),
145
+ (editor == null ? void 0 : editor.contentComponent) && /* @__PURE__ */ jsx(Portals, { contentComponent: editor.contentComponent })
146
+ ] });
147
+ }
148
+ };
149
+ var EditorContentWithKey = forwardRef(
150
+ (props, ref) => {
117
151
  const key = React.useMemo(() => {
118
- return Math.floor(Math.random() * 0xFFFFFFFF).toString();
152
+ return Math.floor(Math.random() * 4294967295).toString();
119
153
  }, [props.editor]);
120
- // Can't use JSX here because it conflicts with the type definition of Vue's JSX, so use createElement
121
154
  return React.createElement(PureEditorContent, {
122
- key,
123
- innerRef: ref,
124
- ...props,
155
+ key,
156
+ innerRef: ref,
157
+ ...props
125
158
  });
126
- });
127
- const EditorContent = React.memo(EditorContentWithKey);
128
-
129
- class Editor extends Editor$1 {
130
- constructor() {
131
- super(...arguments);
132
- this.contentComponent = null;
159
+ }
160
+ );
161
+ var EditorContent = React.memo(EditorContentWithKey);
162
+
163
+ // src/useEditor.ts
164
+ import { Editor } from "@tiptap/core";
165
+ import { useDebugValue as useDebugValue2, useEffect as useEffect2, useRef, useState as useState2 } from "react";
166
+ import { useSyncExternalStore as useSyncExternalStore2 } from "use-sync-external-store/shim/index.js";
167
+
168
+ // src/useEditorState.ts
169
+ import deepEqual from "fast-deep-equal/es6/react.js";
170
+ import { useDebugValue, useEffect, useLayoutEffect, useState } from "react";
171
+ import { useSyncExternalStoreWithSelector } from "use-sync-external-store/shim/with-selector.js";
172
+ var useIsomorphicLayoutEffect = typeof window !== "undefined" ? useLayoutEffect : useEffect;
173
+ var EditorStateManager = class {
174
+ constructor(initialEditor) {
175
+ this.transactionNumber = 0;
176
+ this.lastTransactionNumber = 0;
177
+ this.subscribers = /* @__PURE__ */ new Set();
178
+ this.editor = initialEditor;
179
+ this.lastSnapshot = { editor: initialEditor, transactionNumber: 0 };
180
+ this.getSnapshot = this.getSnapshot.bind(this);
181
+ this.getServerSnapshot = this.getServerSnapshot.bind(this);
182
+ this.watch = this.watch.bind(this);
183
+ this.subscribe = this.subscribe.bind(this);
184
+ }
185
+ /**
186
+ * Get the current editor instance.
187
+ */
188
+ getSnapshot() {
189
+ if (this.transactionNumber === this.lastTransactionNumber) {
190
+ return this.lastSnapshot;
133
191
  }
134
- }
135
-
136
- var withSelector = {exports: {}};
137
-
138
- var withSelector_production_min = {};
139
-
140
- var shim = {exports: {}};
141
-
142
- var useSyncExternalStoreShim_production_min = {};
143
-
144
- /**
145
- * @license React
146
- * use-sync-external-store-shim.production.min.js
147
- *
148
- * Copyright (c) Facebook, Inc. and its affiliates.
149
- *
150
- * This source code is licensed under the MIT license found in the
151
- * LICENSE file in the root directory of this source tree.
152
- */
153
-
154
- var hasRequiredUseSyncExternalStoreShim_production_min;
155
-
156
- function requireUseSyncExternalStoreShim_production_min () {
157
- if (hasRequiredUseSyncExternalStoreShim_production_min) return useSyncExternalStoreShim_production_min;
158
- hasRequiredUseSyncExternalStoreShim_production_min = 1;
159
- var e=React;function h(a,b){return a===b&&(0!==a||1/a===1/b)||a!==a&&b!==b}var k="function"===typeof Object.is?Object.is:h,l=e.useState,m=e.useEffect,n=e.useLayoutEffect,p=e.useDebugValue;function q(a,b){var d=b(),f=l({inst:{value:d,getSnapshot:b}}),c=f[0].inst,g=f[1];n(function(){c.value=d;c.getSnapshot=b;r(c)&&g({inst:c});},[a,d,b]);m(function(){r(c)&&g({inst:c});return a(function(){r(c)&&g({inst:c});})},[a]);p(d);return d}
160
- function r(a){var b=a.getSnapshot;a=a.value;try{var d=b();return !k(a,d)}catch(f){return !0}}function t(a,b){return b()}var u="undefined"===typeof window||"undefined"===typeof window.document||"undefined"===typeof window.document.createElement?t:q;useSyncExternalStoreShim_production_min.useSyncExternalStore=void 0!==e.useSyncExternalStore?e.useSyncExternalStore:u;
161
- return useSyncExternalStoreShim_production_min;
162
- }
163
-
164
- var useSyncExternalStoreShim_development = {};
165
-
166
- /**
167
- * @license React
168
- * use-sync-external-store-shim.development.js
169
- *
170
- * Copyright (c) Facebook, Inc. and its affiliates.
171
- *
172
- * This source code is licensed under the MIT license found in the
173
- * LICENSE file in the root directory of this source tree.
174
- */
175
-
176
- var hasRequiredUseSyncExternalStoreShim_development;
177
-
178
- function requireUseSyncExternalStoreShim_development () {
179
- if (hasRequiredUseSyncExternalStoreShim_development) return useSyncExternalStoreShim_development;
180
- hasRequiredUseSyncExternalStoreShim_development = 1;
181
-
182
- if (process.env.NODE_ENV !== "production") {
183
- (function() {
184
-
185
- /* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
186
- if (
187
- typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
188
- typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart ===
189
- 'function'
190
- ) {
191
- __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
192
- }
193
- var React$1 = React;
194
-
195
- var ReactSharedInternals = React$1.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
196
-
197
- function error(format) {
198
- {
199
- {
200
- for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
201
- args[_key2 - 1] = arguments[_key2];
202
- }
203
-
204
- printWarning('error', format, args);
205
- }
206
- }
207
- }
208
-
209
- function printWarning(level, format, args) {
210
- // When changing this logic, you might want to also
211
- // update consoleWithStackDev.www.js as well.
212
- {
213
- var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
214
- var stack = ReactDebugCurrentFrame.getStackAddendum();
215
-
216
- if (stack !== '') {
217
- format += '%s';
218
- args = args.concat([stack]);
219
- } // eslint-disable-next-line react-internal/safe-string-coercion
220
-
221
-
222
- var argsWithFormat = args.map(function (item) {
223
- return String(item);
224
- }); // Careful: RN currently depends on this prefix
225
-
226
- argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it
227
- // breaks IE9: https://github.com/facebook/react/issues/13610
228
- // eslint-disable-next-line react-internal/no-production-logging
229
-
230
- Function.prototype.apply.call(console[level], console, argsWithFormat);
231
- }
232
- }
233
-
234
- /**
235
- * inlined Object.is polyfill to avoid requiring consumers ship their own
236
- * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
237
- */
238
- function is(x, y) {
239
- return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare
240
- ;
241
- }
242
-
243
- var objectIs = typeof Object.is === 'function' ? Object.is : is;
244
-
245
- // dispatch for CommonJS interop named imports.
246
-
247
- var useState = React$1.useState,
248
- useEffect = React$1.useEffect,
249
- useLayoutEffect = React$1.useLayoutEffect,
250
- useDebugValue = React$1.useDebugValue;
251
- var didWarnOld18Alpha = false;
252
- var didWarnUncachedGetSnapshot = false; // Disclaimer: This shim breaks many of the rules of React, and only works
253
- // because of a very particular set of implementation details and assumptions
254
- // -- change any one of them and it will break. The most important assumption
255
- // is that updates are always synchronous, because concurrent rendering is
256
- // only available in versions of React that also have a built-in
257
- // useSyncExternalStore API. And we only use this shim when the built-in API
258
- // does not exist.
259
- //
260
- // Do not assume that the clever hacks used by this hook also work in general.
261
- // The point of this shim is to replace the need for hacks by other libraries.
262
-
263
- function useSyncExternalStore(subscribe, getSnapshot, // Note: The shim does not use getServerSnapshot, because pre-18 versions of
264
- // React do not expose a way to check if we're hydrating. So users of the shim
265
- // will need to track that themselves and return the correct value
266
- // from `getSnapshot`.
267
- getServerSnapshot) {
268
- {
269
- if (!didWarnOld18Alpha) {
270
- if (React$1.startTransition !== undefined) {
271
- didWarnOld18Alpha = true;
272
-
273
- error('You are using an outdated, pre-release alpha of React 18 that ' + 'does not support useSyncExternalStore. The ' + 'use-sync-external-store shim will not work correctly. Upgrade ' + 'to a newer pre-release.');
274
- }
275
- }
276
- } // Read the current snapshot from the store on every render. Again, this
277
- // breaks the rules of React, and only works here because of specific
278
- // implementation details, most importantly that updates are
279
- // always synchronous.
280
-
281
-
282
- var value = getSnapshot();
283
-
284
- {
285
- if (!didWarnUncachedGetSnapshot) {
286
- var cachedValue = getSnapshot();
287
-
288
- if (!objectIs(value, cachedValue)) {
289
- error('The result of getSnapshot should be cached to avoid an infinite loop');
290
-
291
- didWarnUncachedGetSnapshot = true;
292
- }
293
- }
294
- } // Because updates are synchronous, we don't queue them. Instead we force a
295
- // re-render whenever the subscribed state changes by updating an some
296
- // arbitrary useState hook. Then, during render, we call getSnapshot to read
297
- // the current value.
298
- //
299
- // Because we don't actually use the state returned by the useState hook, we
300
- // can save a bit of memory by storing other stuff in that slot.
301
- //
302
- // To implement the early bailout, we need to track some things on a mutable
303
- // object. Usually, we would put that in a useRef hook, but we can stash it in
304
- // our useState hook instead.
305
- //
306
- // To force a re-render, we call forceUpdate({inst}). That works because the
307
- // new object always fails an equality check.
308
-
309
-
310
- var _useState = useState({
311
- inst: {
312
- value: value,
313
- getSnapshot: getSnapshot
314
- }
315
- }),
316
- inst = _useState[0].inst,
317
- forceUpdate = _useState[1]; // Track the latest getSnapshot function with a ref. This needs to be updated
318
- // in the layout phase so we can access it during the tearing check that
319
- // happens on subscribe.
320
-
321
-
322
- useLayoutEffect(function () {
323
- inst.value = value;
324
- inst.getSnapshot = getSnapshot; // Whenever getSnapshot or subscribe changes, we need to check in the
325
- // commit phase if there was an interleaved mutation. In concurrent mode
326
- // this can happen all the time, but even in synchronous mode, an earlier
327
- // effect may have mutated the store.
328
-
329
- if (checkIfSnapshotChanged(inst)) {
330
- // Force a re-render.
331
- forceUpdate({
332
- inst: inst
333
- });
334
- }
335
- }, [subscribe, value, getSnapshot]);
336
- useEffect(function () {
337
- // Check for changes right before subscribing. Subsequent changes will be
338
- // detected in the subscription handler.
339
- if (checkIfSnapshotChanged(inst)) {
340
- // Force a re-render.
341
- forceUpdate({
342
- inst: inst
343
- });
344
- }
345
-
346
- var handleStoreChange = function () {
347
- // TODO: Because there is no cross-renderer API for batching updates, it's
348
- // up to the consumer of this library to wrap their subscription event
349
- // with unstable_batchedUpdates. Should we try to detect when this isn't
350
- // the case and print a warning in development?
351
- // The store changed. Check if the snapshot changed since the last time we
352
- // read from the store.
353
- if (checkIfSnapshotChanged(inst)) {
354
- // Force a re-render.
355
- forceUpdate({
356
- inst: inst
357
- });
358
- }
359
- }; // Subscribe to the store and return a clean-up function.
360
-
361
-
362
- return subscribe(handleStoreChange);
363
- }, [subscribe]);
364
- useDebugValue(value);
365
- return value;
366
- }
367
-
368
- function checkIfSnapshotChanged(inst) {
369
- var latestGetSnapshot = inst.getSnapshot;
370
- var prevValue = inst.value;
371
-
372
- try {
373
- var nextValue = latestGetSnapshot();
374
- return !objectIs(prevValue, nextValue);
375
- } catch (error) {
376
- return true;
377
- }
378
- }
379
-
380
- function useSyncExternalStore$1(subscribe, getSnapshot, getServerSnapshot) {
381
- // Note: The shim does not use getServerSnapshot, because pre-18 versions of
382
- // React do not expose a way to check if we're hydrating. So users of the shim
383
- // will need to track that themselves and return the correct value
384
- // from `getSnapshot`.
385
- return getSnapshot();
386
- }
387
-
388
- var canUseDOM = !!(typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined');
389
-
390
- var isServerEnvironment = !canUseDOM;
391
-
392
- var shim = isServerEnvironment ? useSyncExternalStore$1 : useSyncExternalStore;
393
- var useSyncExternalStore$2 = React$1.useSyncExternalStore !== undefined ? React$1.useSyncExternalStore : shim;
394
-
395
- useSyncExternalStoreShim_development.useSyncExternalStore = useSyncExternalStore$2;
396
- /* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
397
- if (
398
- typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
399
- typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop ===
400
- 'function'
401
- ) {
402
- __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
403
- }
404
-
405
- })();
406
- }
407
- return useSyncExternalStoreShim_development;
408
- }
409
-
410
- var hasRequiredShim;
411
-
412
- function requireShim () {
413
- if (hasRequiredShim) return shim.exports;
414
- hasRequiredShim = 1;
415
-
416
- if (process.env.NODE_ENV === 'production') {
417
- shim.exports = requireUseSyncExternalStoreShim_production_min();
418
- } else {
419
- shim.exports = requireUseSyncExternalStoreShim_development();
420
- }
421
- return shim.exports;
422
- }
423
-
424
- /**
425
- * @license React
426
- * use-sync-external-store-shim/with-selector.production.min.js
427
- *
428
- * Copyright (c) Facebook, Inc. and its affiliates.
429
- *
430
- * This source code is licensed under the MIT license found in the
431
- * LICENSE file in the root directory of this source tree.
432
- */
433
-
434
- var hasRequiredWithSelector_production_min;
435
-
436
- function requireWithSelector_production_min () {
437
- if (hasRequiredWithSelector_production_min) return withSelector_production_min;
438
- hasRequiredWithSelector_production_min = 1;
439
- var h=React,n=requireShim();function p(a,b){return a===b&&(0!==a||1/a===1/b)||a!==a&&b!==b}var q="function"===typeof Object.is?Object.is:p,r=n.useSyncExternalStore,t=h.useRef,u=h.useEffect,v=h.useMemo,w=h.useDebugValue;
440
- withSelector_production_min.useSyncExternalStoreWithSelector=function(a,b,e,l,g){var c=t(null);if(null===c.current){var f={hasValue:!1,value:null};c.current=f;}else f=c.current;c=v(function(){function a(a){if(!c){c=!0;d=a;a=l(a);if(void 0!==g&&f.hasValue){var b=f.value;if(g(b,a))return k=b}return k=a}b=k;if(q(d,a))return b;var e=l(a);if(void 0!==g&&g(b,e))return b;d=a;return k=e}var c=!1,d,k,m=void 0===e?null:e;return [function(){return a(b())},null===m?void 0:function(){return a(m())}]},[b,e,l,g]);var d=r(a,c[0],c[1]);
441
- u(function(){f.hasValue=!0;f.value=d;},[d]);w(d);return d};
442
- return withSelector_production_min;
443
- }
444
-
445
- var withSelector_development = {};
446
-
447
- /**
448
- * @license React
449
- * use-sync-external-store-shim/with-selector.development.js
450
- *
451
- * Copyright (c) Facebook, Inc. and its affiliates.
452
- *
453
- * This source code is licensed under the MIT license found in the
454
- * LICENSE file in the root directory of this source tree.
455
- */
456
-
457
- var hasRequiredWithSelector_development;
458
-
459
- function requireWithSelector_development () {
460
- if (hasRequiredWithSelector_development) return withSelector_development;
461
- hasRequiredWithSelector_development = 1;
462
-
463
- if (process.env.NODE_ENV !== "production") {
464
- (function() {
465
-
466
- /* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
467
- if (
468
- typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
469
- typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart ===
470
- 'function'
471
- ) {
472
- __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
473
- }
474
- var React$1 = React;
475
- var shim = requireShim();
476
-
477
- /**
478
- * inlined Object.is polyfill to avoid requiring consumers ship their own
479
- * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
480
- */
481
- function is(x, y) {
482
- return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y // eslint-disable-line no-self-compare
483
- ;
484
- }
485
-
486
- var objectIs = typeof Object.is === 'function' ? Object.is : is;
487
-
488
- var useSyncExternalStore = shim.useSyncExternalStore;
489
-
490
- // for CommonJS interop.
491
-
492
- var useRef = React$1.useRef,
493
- useEffect = React$1.useEffect,
494
- useMemo = React$1.useMemo,
495
- useDebugValue = React$1.useDebugValue; // Same as useSyncExternalStore, but supports selector and isEqual arguments.
496
-
497
- function useSyncExternalStoreWithSelector(subscribe, getSnapshot, getServerSnapshot, selector, isEqual) {
498
- // Use this to track the rendered snapshot.
499
- var instRef = useRef(null);
500
- var inst;
501
-
502
- if (instRef.current === null) {
503
- inst = {
504
- hasValue: false,
505
- value: null
506
- };
507
- instRef.current = inst;
508
- } else {
509
- inst = instRef.current;
510
- }
511
-
512
- var _useMemo = useMemo(function () {
513
- // Track the memoized state using closure variables that are local to this
514
- // memoized instance of a getSnapshot function. Intentionally not using a
515
- // useRef hook, because that state would be shared across all concurrent
516
- // copies of the hook/component.
517
- var hasMemo = false;
518
- var memoizedSnapshot;
519
- var memoizedSelection;
520
-
521
- var memoizedSelector = function (nextSnapshot) {
522
- if (!hasMemo) {
523
- // The first time the hook is called, there is no memoized result.
524
- hasMemo = true;
525
- memoizedSnapshot = nextSnapshot;
526
-
527
- var _nextSelection = selector(nextSnapshot);
528
-
529
- if (isEqual !== undefined) {
530
- // Even if the selector has changed, the currently rendered selection
531
- // may be equal to the new selection. We should attempt to reuse the
532
- // current value if possible, to preserve downstream memoizations.
533
- if (inst.hasValue) {
534
- var currentSelection = inst.value;
535
-
536
- if (isEqual(currentSelection, _nextSelection)) {
537
- memoizedSelection = currentSelection;
538
- return currentSelection;
539
- }
540
- }
541
- }
542
-
543
- memoizedSelection = _nextSelection;
544
- return _nextSelection;
545
- } // We may be able to reuse the previous invocation's result.
546
-
547
-
548
- // We may be able to reuse the previous invocation's result.
549
- var prevSnapshot = memoizedSnapshot;
550
- var prevSelection = memoizedSelection;
551
-
552
- if (objectIs(prevSnapshot, nextSnapshot)) {
553
- // The snapshot is the same as last time. Reuse the previous selection.
554
- return prevSelection;
555
- } // The snapshot has changed, so we need to compute a new selection.
556
-
557
-
558
- // The snapshot has changed, so we need to compute a new selection.
559
- var nextSelection = selector(nextSnapshot); // If a custom isEqual function is provided, use that to check if the data
560
- // has changed. If it hasn't, return the previous selection. That signals
561
- // to React that the selections are conceptually equal, and we can bail
562
- // out of rendering.
563
-
564
- // If a custom isEqual function is provided, use that to check if the data
565
- // has changed. If it hasn't, return the previous selection. That signals
566
- // to React that the selections are conceptually equal, and we can bail
567
- // out of rendering.
568
- if (isEqual !== undefined && isEqual(prevSelection, nextSelection)) {
569
- return prevSelection;
570
- }
571
-
572
- memoizedSnapshot = nextSnapshot;
573
- memoizedSelection = nextSelection;
574
- return nextSelection;
575
- }; // Assigning this to a constant so that Flow knows it can't change.
576
-
577
-
578
- // Assigning this to a constant so that Flow knows it can't change.
579
- var maybeGetServerSnapshot = getServerSnapshot === undefined ? null : getServerSnapshot;
580
-
581
- var getSnapshotWithSelector = function () {
582
- return memoizedSelector(getSnapshot());
583
- };
584
-
585
- var getServerSnapshotWithSelector = maybeGetServerSnapshot === null ? undefined : function () {
586
- return memoizedSelector(maybeGetServerSnapshot());
587
- };
588
- return [getSnapshotWithSelector, getServerSnapshotWithSelector];
589
- }, [getSnapshot, getServerSnapshot, selector, isEqual]),
590
- getSelection = _useMemo[0],
591
- getServerSelection = _useMemo[1];
592
-
593
- var value = useSyncExternalStore(subscribe, getSelection, getServerSelection);
594
- useEffect(function () {
595
- inst.hasValue = true;
596
- inst.value = value;
597
- }, [value]);
598
- useDebugValue(value);
599
- return value;
600
- }
601
-
602
- withSelector_development.useSyncExternalStoreWithSelector = useSyncExternalStoreWithSelector;
603
- /* global __REACT_DEVTOOLS_GLOBAL_HOOK__ */
604
- if (
605
- typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ !== 'undefined' &&
606
- typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop ===
607
- 'function'
608
- ) {
609
- __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
610
- }
611
-
612
- })();
613
- }
614
- return withSelector_development;
615
- }
616
-
617
- if (process.env.NODE_ENV === 'production') {
618
- withSelector.exports = requireWithSelector_production_min();
619
- } else {
620
- withSelector.exports = requireWithSelector_development();
621
- }
622
-
623
- var withSelectorExports = withSelector.exports;
624
-
625
- /**
626
- * To synchronize the editor instance with the component state,
627
- * we need to create a separate instance that is not affected by the component re-renders.
628
- */
629
- function makeEditorStateInstance(initialEditor) {
630
- let transactionNumber = 0;
631
- let lastTransactionNumber = 0;
632
- let lastSnapshot = { editor: initialEditor, transactionNumber: 0 };
633
- let editor = initialEditor;
634
- const subscribers = new Set();
635
- const editorInstance = {
636
- /**
637
- * Get the current editor instance.
638
- */
639
- getSnapshot() {
640
- if (transactionNumber === lastTransactionNumber) {
641
- return lastSnapshot;
642
- }
643
- lastTransactionNumber = transactionNumber;
644
- lastSnapshot = { editor, transactionNumber };
645
- return lastSnapshot;
646
- },
647
- /**
648
- * Always disable the editor on the server-side.
649
- */
650
- getServerSnapshot() {
651
- return { editor: null, transactionNumber: 0 };
652
- },
653
- /**
654
- * Subscribe to the editor instance's changes.
655
- */
656
- subscribe(callback) {
657
- subscribers.add(callback);
658
- return () => {
659
- subscribers.delete(callback);
660
- };
661
- },
662
- /**
663
- * Watch the editor instance for changes.
664
- */
665
- watch(nextEditor) {
666
- editor = nextEditor;
667
- if (editor) {
668
- /**
669
- * This will force a re-render when the editor state changes.
670
- * This is to support things like `editor.can().toggleBold()` in components that `useEditor`.
671
- * This could be more efficient, but it's a good trade-off for now.
672
- */
673
- const fn = () => {
674
- transactionNumber += 1;
675
- subscribers.forEach(callback => callback());
676
- };
677
- const currentEditor = editor;
678
- currentEditor.on('transaction', fn);
679
- return () => {
680
- currentEditor.off('transaction', fn);
681
- };
682
- }
683
- },
192
+ this.lastTransactionNumber = this.transactionNumber;
193
+ this.lastSnapshot = { editor: this.editor, transactionNumber: this.transactionNumber };
194
+ return this.lastSnapshot;
195
+ }
196
+ /**
197
+ * Always disable the editor on the server-side.
198
+ */
199
+ getServerSnapshot() {
200
+ return { editor: null, transactionNumber: 0 };
201
+ }
202
+ /**
203
+ * Subscribe to the editor instance's changes.
204
+ */
205
+ subscribe(callback) {
206
+ this.subscribers.add(callback);
207
+ return () => {
208
+ this.subscribers.delete(callback);
684
209
  };
685
- return editorInstance;
686
- }
210
+ }
211
+ /**
212
+ * Watch the editor instance for changes.
213
+ */
214
+ watch(nextEditor) {
215
+ this.editor = nextEditor;
216
+ if (this.editor) {
217
+ const fn = () => {
218
+ this.transactionNumber += 1;
219
+ this.subscribers.forEach((callback) => callback());
220
+ };
221
+ const currentEditor = this.editor;
222
+ currentEditor.on("transaction", fn);
223
+ return () => {
224
+ currentEditor.off("transaction", fn);
225
+ };
226
+ }
227
+ return void 0;
228
+ }
229
+ };
687
230
  function useEditorState(options) {
688
- const [editorInstance] = useState(() => makeEditorStateInstance(options.editor));
689
- // Using the `useSyncExternalStore` hook to sync the editor instance with the component state
690
- const selectedState = withSelectorExports.useSyncExternalStoreWithSelector(editorInstance.subscribe, editorInstance.getSnapshot, editorInstance.getServerSnapshot, options.selector, options.equalityFn);
691
- useEffect(() => {
692
- return editorInstance.watch(options.editor);
693
- }, [options.editor]);
694
- useDebugValue(selectedState);
695
- return selectedState;
231
+ var _a;
232
+ const [editorStateManager] = useState(() => new EditorStateManager(options.editor));
233
+ const selectedState = useSyncExternalStoreWithSelector(
234
+ editorStateManager.subscribe,
235
+ editorStateManager.getSnapshot,
236
+ editorStateManager.getServerSnapshot,
237
+ options.selector,
238
+ (_a = options.equalityFn) != null ? _a : deepEqual
239
+ );
240
+ useIsomorphicLayoutEffect(() => {
241
+ return editorStateManager.watch(options.editor);
242
+ }, [options.editor, editorStateManager]);
243
+ useDebugValue(selectedState);
244
+ return selectedState;
696
245
  }
697
246
 
698
- const isDev = process.env.NODE_ENV !== 'production';
699
- const isSSR = typeof window === 'undefined';
700
- const isNext = isSSR || Boolean(typeof window !== 'undefined' && window.next);
701
- function useEditor(options = {}, deps = []) {
702
- const isMounted = useRef(false);
703
- const [editor, setEditor] = useState(() => {
704
- if (options.immediatelyRender === undefined) {
705
- if (isSSR || isNext) {
706
- // TODO in the next major release, we should throw an error here
707
- if (isDev) {
708
- /**
709
- * Throw an error in development, to make sure the developer is aware that tiptap cannot be SSR'd
710
- * and that they need to set `immediatelyRender` to `false` to avoid hydration mismatches.
711
- */
712
- console.warn('Tiptap Error: SSR has been detected, please set `immediatelyRender` explicitly to `false` to avoid hydration mismatches.');
713
- }
714
- // Best faith effort in production, run the code in the legacy mode to avoid hydration mismatches and errors in production
715
- return null;
716
- }
717
- // Default to immediately rendering when client-side rendering
718
- return new Editor(options);
719
- }
720
- if (options.immediatelyRender && isSSR && isDev) {
721
- // Warn in development, to make sure the developer is aware that tiptap cannot be SSR'd, set `immediatelyRender` to `false` to avoid hydration mismatches.
722
- throw new Error('Tiptap Error: SSR has been detected, and `immediatelyRender` has been set to `true` this is an unsupported configuration that may result in errors, explicitly set `immediatelyRender` to `false` to avoid hydration mismatches.');
723
- }
724
- if (options.immediatelyRender) {
725
- return new Editor(options);
247
+ // src/useEditor.ts
248
+ var isDev = process.env.NODE_ENV !== "production";
249
+ var isSSR = typeof window === "undefined";
250
+ var isNext = isSSR || Boolean(typeof window !== "undefined" && window.next);
251
+ var EditorInstanceManager = class _EditorInstanceManager {
252
+ constructor(options) {
253
+ /**
254
+ * The current editor instance.
255
+ */
256
+ this.editor = null;
257
+ /**
258
+ * The subscriptions to notify when the editor instance
259
+ * has been created or destroyed.
260
+ */
261
+ this.subscriptions = /* @__PURE__ */ new Set();
262
+ /**
263
+ * Whether the editor has been mounted.
264
+ */
265
+ this.isComponentMounted = false;
266
+ /**
267
+ * The most recent dependencies array.
268
+ */
269
+ this.previousDeps = null;
270
+ /**
271
+ * The unique instance ID. This is used to identify the editor instance. And will be re-generated for each new instance.
272
+ */
273
+ this.instanceId = "";
274
+ this.options = options;
275
+ this.subscriptions = /* @__PURE__ */ new Set();
276
+ this.setEditor(this.getInitialEditor());
277
+ this.scheduleDestroy();
278
+ this.getEditor = this.getEditor.bind(this);
279
+ this.getServerSnapshot = this.getServerSnapshot.bind(this);
280
+ this.subscribe = this.subscribe.bind(this);
281
+ this.refreshEditorInstance = this.refreshEditorInstance.bind(this);
282
+ this.scheduleDestroy = this.scheduleDestroy.bind(this);
283
+ this.onRender = this.onRender.bind(this);
284
+ this.createEditor = this.createEditor.bind(this);
285
+ }
286
+ setEditor(editor) {
287
+ this.editor = editor;
288
+ this.instanceId = Math.random().toString(36).slice(2, 9);
289
+ this.subscriptions.forEach((cb) => cb());
290
+ }
291
+ getInitialEditor() {
292
+ if (this.options.current.immediatelyRender === void 0) {
293
+ if (isSSR || isNext) {
294
+ if (isDev) {
295
+ throw new Error(
296
+ "Tiptap Error: SSR has been detected, please set `immediatelyRender` explicitly to `false` to avoid hydration mismatches."
297
+ );
726
298
  }
727
299
  return null;
728
- });
729
- useDebugValue(editor);
730
- // This effect will handle creating/updating the editor instance
731
- useEffect(() => {
732
- let editorInstance = editor;
733
- if (!editorInstance) {
734
- editorInstance = new Editor(options);
735
- // instantiate the editor if it doesn't exist
736
- // for ssr, this is the first time the editor is created
737
- setEditor(editorInstance);
738
- }
739
- else {
740
- // if the editor does exist, update the editor options accordingly
741
- editorInstance.setOptions(options);
742
- }
743
- }, deps);
744
- const { onBeforeCreate, onBlur, onCreate, onDestroy, onFocus, onSelectionUpdate, onTransaction, onUpdate, onContentError, } = options;
745
- const onBeforeCreateRef = useRef(onBeforeCreate);
746
- const onBlurRef = useRef(onBlur);
747
- const onCreateRef = useRef(onCreate);
748
- const onDestroyRef = useRef(onDestroy);
749
- const onFocusRef = useRef(onFocus);
750
- const onSelectionUpdateRef = useRef(onSelectionUpdate);
751
- const onTransactionRef = useRef(onTransaction);
752
- const onUpdateRef = useRef(onUpdate);
753
- const onContentErrorRef = useRef(onContentError);
754
- // This effect will handle updating the editor instance
755
- // when the event handlers change.
756
- useEffect(() => {
757
- if (!editor) {
758
- return;
759
- }
760
- if (onBeforeCreate) {
761
- editor.off('beforeCreate', onBeforeCreateRef.current);
762
- editor.on('beforeCreate', onBeforeCreate);
763
- onBeforeCreateRef.current = onBeforeCreate;
764
- }
765
- if (onBlur) {
766
- editor.off('blur', onBlurRef.current);
767
- editor.on('blur', onBlur);
768
- onBlurRef.current = onBlur;
769
- }
770
- if (onCreate) {
771
- editor.off('create', onCreateRef.current);
772
- editor.on('create', onCreate);
773
- onCreateRef.current = onCreate;
774
- }
775
- if (onDestroy) {
776
- editor.off('destroy', onDestroyRef.current);
777
- editor.on('destroy', onDestroy);
778
- onDestroyRef.current = onDestroy;
779
- }
780
- if (onFocus) {
781
- editor.off('focus', onFocusRef.current);
782
- editor.on('focus', onFocus);
783
- onFocusRef.current = onFocus;
784
- }
785
- if (onSelectionUpdate) {
786
- editor.off('selectionUpdate', onSelectionUpdateRef.current);
787
- editor.on('selectionUpdate', onSelectionUpdate);
788
- onSelectionUpdateRef.current = onSelectionUpdate;
300
+ }
301
+ return this.createEditor();
302
+ }
303
+ if (this.options.current.immediatelyRender && isSSR && isDev) {
304
+ throw new Error(
305
+ "Tiptap Error: SSR has been detected, and `immediatelyRender` has been set to `true` this is an unsupported configuration that may result in errors, explicitly set `immediatelyRender` to `false` to avoid hydration mismatches."
306
+ );
307
+ }
308
+ if (this.options.current.immediatelyRender) {
309
+ return this.createEditor();
310
+ }
311
+ return null;
312
+ }
313
+ /**
314
+ * Create a new editor instance. And attach event listeners.
315
+ */
316
+ createEditor() {
317
+ const optionsToApply = {
318
+ ...this.options.current,
319
+ // Always call the most recent version of the callback function by default
320
+ onBeforeCreate: (...args) => {
321
+ var _a, _b;
322
+ return (_b = (_a = this.options.current).onBeforeCreate) == null ? void 0 : _b.call(_a, ...args);
323
+ },
324
+ onBlur: (...args) => {
325
+ var _a, _b;
326
+ return (_b = (_a = this.options.current).onBlur) == null ? void 0 : _b.call(_a, ...args);
327
+ },
328
+ onCreate: (...args) => {
329
+ var _a, _b;
330
+ return (_b = (_a = this.options.current).onCreate) == null ? void 0 : _b.call(_a, ...args);
331
+ },
332
+ onDestroy: (...args) => {
333
+ var _a, _b;
334
+ return (_b = (_a = this.options.current).onDestroy) == null ? void 0 : _b.call(_a, ...args);
335
+ },
336
+ onFocus: (...args) => {
337
+ var _a, _b;
338
+ return (_b = (_a = this.options.current).onFocus) == null ? void 0 : _b.call(_a, ...args);
339
+ },
340
+ onSelectionUpdate: (...args) => {
341
+ var _a, _b;
342
+ return (_b = (_a = this.options.current).onSelectionUpdate) == null ? void 0 : _b.call(_a, ...args);
343
+ },
344
+ onTransaction: (...args) => {
345
+ var _a, _b;
346
+ return (_b = (_a = this.options.current).onTransaction) == null ? void 0 : _b.call(_a, ...args);
347
+ },
348
+ onUpdate: (...args) => {
349
+ var _a, _b;
350
+ return (_b = (_a = this.options.current).onUpdate) == null ? void 0 : _b.call(_a, ...args);
351
+ },
352
+ onContentError: (...args) => {
353
+ var _a, _b;
354
+ return (_b = (_a = this.options.current).onContentError) == null ? void 0 : _b.call(_a, ...args);
355
+ },
356
+ onDrop: (...args) => {
357
+ var _a, _b;
358
+ return (_b = (_a = this.options.current).onDrop) == null ? void 0 : _b.call(_a, ...args);
359
+ },
360
+ onPaste: (...args) => {
361
+ var _a, _b;
362
+ return (_b = (_a = this.options.current).onPaste) == null ? void 0 : _b.call(_a, ...args);
363
+ },
364
+ onDelete: (...args) => {
365
+ var _a, _b;
366
+ return (_b = (_a = this.options.current).onDelete) == null ? void 0 : _b.call(_a, ...args);
367
+ }
368
+ };
369
+ const editor = new Editor(optionsToApply);
370
+ return editor;
371
+ }
372
+ /**
373
+ * Get the current editor instance.
374
+ */
375
+ getEditor() {
376
+ return this.editor;
377
+ }
378
+ /**
379
+ * Always disable the editor on the server-side.
380
+ */
381
+ getServerSnapshot() {
382
+ return null;
383
+ }
384
+ /**
385
+ * Subscribe to the editor instance's changes.
386
+ */
387
+ subscribe(onStoreChange) {
388
+ this.subscriptions.add(onStoreChange);
389
+ return () => {
390
+ this.subscriptions.delete(onStoreChange);
391
+ };
392
+ }
393
+ static compareOptions(a, b) {
394
+ return Object.keys(a).every((key) => {
395
+ if ([
396
+ "onCreate",
397
+ "onBeforeCreate",
398
+ "onDestroy",
399
+ "onUpdate",
400
+ "onTransaction",
401
+ "onFocus",
402
+ "onBlur",
403
+ "onSelectionUpdate",
404
+ "onContentError",
405
+ "onDrop",
406
+ "onPaste"
407
+ ].includes(key)) {
408
+ return true;
409
+ }
410
+ if (key === "extensions" && a.extensions && b.extensions) {
411
+ if (a.extensions.length !== b.extensions.length) {
412
+ return false;
789
413
  }
790
- if (onTransaction) {
791
- editor.off('transaction', onTransactionRef.current);
792
- editor.on('transaction', onTransaction);
793
- onTransactionRef.current = onTransaction;
414
+ return a.extensions.every((extension, index) => {
415
+ var _a;
416
+ if (extension !== ((_a = b.extensions) == null ? void 0 : _a[index])) {
417
+ return false;
418
+ }
419
+ return true;
420
+ });
421
+ }
422
+ if (a[key] !== b[key]) {
423
+ return false;
424
+ }
425
+ return true;
426
+ });
427
+ }
428
+ /**
429
+ * On each render, we will create, update, or destroy the editor instance.
430
+ * @param deps The dependencies to watch for changes
431
+ * @returns A cleanup function
432
+ */
433
+ onRender(deps) {
434
+ return () => {
435
+ this.isComponentMounted = true;
436
+ clearTimeout(this.scheduledDestructionTimeout);
437
+ if (this.editor && !this.editor.isDestroyed && deps.length === 0) {
438
+ if (!_EditorInstanceManager.compareOptions(this.options.current, this.editor.options)) {
439
+ this.editor.setOptions({
440
+ ...this.options.current,
441
+ editable: this.editor.isEditable
442
+ });
794
443
  }
795
- if (onUpdate) {
796
- editor.off('update', onUpdateRef.current);
797
- editor.on('update', onUpdate);
798
- onUpdateRef.current = onUpdate;
444
+ } else {
445
+ this.refreshEditorInstance(deps);
446
+ }
447
+ return () => {
448
+ this.isComponentMounted = false;
449
+ this.scheduleDestroy();
450
+ };
451
+ };
452
+ }
453
+ /**
454
+ * Recreate the editor instance if the dependencies have changed.
455
+ */
456
+ refreshEditorInstance(deps) {
457
+ if (this.editor && !this.editor.isDestroyed) {
458
+ if (this.previousDeps === null) {
459
+ this.previousDeps = deps;
460
+ return;
461
+ }
462
+ const depsAreEqual = this.previousDeps.length === deps.length && this.previousDeps.every((dep, index) => dep === deps[index]);
463
+ if (depsAreEqual) {
464
+ return;
465
+ }
466
+ }
467
+ if (this.editor && !this.editor.isDestroyed) {
468
+ this.editor.destroy();
469
+ }
470
+ this.setEditor(this.createEditor());
471
+ this.previousDeps = deps;
472
+ }
473
+ /**
474
+ * Schedule the destruction of the editor instance.
475
+ * This will only destroy the editor if it was not mounted on the next tick.
476
+ * This is to avoid destroying the editor instance when it's actually still mounted.
477
+ */
478
+ scheduleDestroy() {
479
+ const currentInstanceId = this.instanceId;
480
+ const currentEditor = this.editor;
481
+ this.scheduledDestructionTimeout = setTimeout(() => {
482
+ if (this.isComponentMounted && this.instanceId === currentInstanceId) {
483
+ if (currentEditor) {
484
+ currentEditor.setOptions(this.options.current);
799
485
  }
800
- if (onContentError) {
801
- editor.off('contentError', onContentErrorRef.current);
802
- editor.on('contentError', onContentError);
803
- onContentErrorRef.current = onContentError;
486
+ return;
487
+ }
488
+ if (currentEditor && !currentEditor.isDestroyed) {
489
+ currentEditor.destroy();
490
+ if (this.instanceId === currentInstanceId) {
491
+ this.setEditor(null);
804
492
  }
805
- }, [
806
- onBeforeCreate,
807
- onBlur,
808
- onCreate,
809
- onDestroy,
810
- onFocus,
811
- onSelectionUpdate,
812
- onTransaction,
813
- onUpdate,
814
- onContentError,
815
- editor,
816
- ]);
817
- /**
818
- * Destroy the editor instance when the component completely unmounts
819
- * As opposed to the cleanup function in the effect above, this will
820
- * only be called when the component is removed from the DOM, since it has no deps.
821
- * */
822
- useEffect(() => {
823
- isMounted.current = true;
824
- return () => {
825
- isMounted.current = false;
826
- if (editor) {
827
- // We need to destroy the editor asynchronously to avoid memory leaks
828
- // because the editor instance is still being used in the component.
829
- setTimeout(() => {
830
- // re-use the editor instance if it hasn't been destroyed yet
831
- // and the component is still mounted
832
- // otherwise, asynchronously destroy the editor instance
833
- if (!isMounted.current && !editor.isDestroyed) {
834
- editor.destroy();
835
- }
836
- });
837
- }
838
- };
839
- }, []);
840
- // The default behavior is to re-render on each transaction
841
- // This is legacy behavior that will be removed in future versions
842
- useEditorState({
843
- editor,
844
- selector: ({ transactionNumber }) => {
845
- if (options.shouldRerenderOnTransaction === false) {
846
- // This will prevent the editor from re-rendering on each transaction
847
- return null;
848
- }
849
- // This will avoid re-rendering on the first transaction when `immediatelyRender` is set to `true`
850
- if (options.immediatelyRender && transactionNumber === 0) {
851
- return 0;
852
- }
853
- return transactionNumber + 1;
854
- },
855
- });
856
- return editor;
493
+ }
494
+ }, 1);
495
+ }
496
+ };
497
+ function useEditor(options = {}, deps = []) {
498
+ const mostRecentOptions = useRef(options);
499
+ mostRecentOptions.current = options;
500
+ const [instanceManager] = useState2(() => new EditorInstanceManager(mostRecentOptions));
501
+ const editor = useSyncExternalStore2(
502
+ instanceManager.subscribe,
503
+ instanceManager.getEditor,
504
+ instanceManager.getServerSnapshot
505
+ );
506
+ useDebugValue2(editor);
507
+ useEffect2(instanceManager.onRender(deps));
508
+ useEditorState({
509
+ editor,
510
+ selector: ({ transactionNumber }) => {
511
+ if (options.shouldRerenderOnTransaction === false || options.shouldRerenderOnTransaction === void 0) {
512
+ return null;
513
+ }
514
+ if (options.immediatelyRender && transactionNumber === 0) {
515
+ return 0;
516
+ }
517
+ return transactionNumber + 1;
518
+ }
519
+ });
520
+ return editor;
857
521
  }
858
522
 
859
- const EditorContext = createContext({
860
- editor: null,
523
+ // src/Context.tsx
524
+ import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
525
+ var EditorContext = createContext({
526
+ editor: null
861
527
  });
862
- const EditorConsumer = EditorContext.Consumer;
863
- /**
864
- * A hook to get the current editor instance.
865
- */
866
- const useCurrentEditor = () => useContext(EditorContext);
867
- /**
868
- * This is the provider component for the editor.
869
- * It allows the editor to be accessible across the entire component tree
870
- * with `useCurrentEditor`.
871
- */
872
- function EditorProvider({ children, slotAfter, slotBefore, ...editorOptions }) {
873
- const editor = useEditor(editorOptions);
874
- if (!editor) {
875
- return null;
876
- }
877
- return (React.createElement(EditorContext.Provider, { value: { editor } },
878
- slotBefore,
879
- React.createElement(EditorConsumer, null, ({ editor: currentEditor }) => (React.createElement(EditorContent, { editor: currentEditor }))),
880
- children,
881
- slotAfter));
528
+ var EditorConsumer = EditorContext.Consumer;
529
+ var useCurrentEditor = () => useContext(EditorContext);
530
+ function EditorProvider({
531
+ children,
532
+ slotAfter,
533
+ slotBefore,
534
+ editorContainerProps = {},
535
+ ...editorOptions
536
+ }) {
537
+ const editor = useEditor(editorOptions);
538
+ const contextValue = useMemo(() => ({ editor }), [editor]);
539
+ if (!editor) {
540
+ return null;
541
+ }
542
+ return /* @__PURE__ */ jsxs2(EditorContext.Provider, { value: contextValue, children: [
543
+ slotBefore,
544
+ /* @__PURE__ */ jsx2(EditorConsumer, { children: ({ editor: currentEditor }) => /* @__PURE__ */ jsx2(EditorContent, { editor: currentEditor, ...editorContainerProps }) }),
545
+ children,
546
+ slotAfter
547
+ ] });
882
548
  }
883
549
 
884
- const BubbleMenu = (props) => {
885
- const [element, setElement] = useState(null);
886
- const { editor: currentEditor } = useCurrentEditor();
887
- useEffect(() => {
888
- var _a;
889
- if (!element) {
890
- return;
891
- }
892
- if (((_a = props.editor) === null || _a === void 0 ? void 0 : _a.isDestroyed) || (currentEditor === null || currentEditor === void 0 ? void 0 : currentEditor.isDestroyed)) {
893
- return;
894
- }
895
- const { pluginKey = 'bubbleMenu', editor, tippyOptions = {}, updateDelay, shouldShow = null, } = props;
896
- const menuEditor = editor || currentEditor;
897
- if (!menuEditor) {
898
- console.warn('BubbleMenu component is not rendered inside of an editor component or does not have editor prop.');
899
- return;
900
- }
901
- const plugin = BubbleMenuPlugin({
902
- updateDelay,
903
- editor: menuEditor,
904
- element,
905
- pluginKey,
906
- shouldShow,
907
- tippyOptions,
908
- });
909
- menuEditor.registerPlugin(plugin);
910
- return () => menuEditor.unregisterPlugin(pluginKey);
911
- }, [props.editor, currentEditor, element]);
912
- return (React.createElement("div", { ref: setElement, className: props.className, style: { visibility: 'hidden' } }, props.children));
550
+ // src/useReactNodeView.ts
551
+ import { createContext as createContext2, createElement, useContext as useContext2 } from "react";
552
+ var ReactNodeViewContext = createContext2({
553
+ onDragStart: () => {
554
+ },
555
+ nodeViewContentChildren: void 0,
556
+ nodeViewContentRef: () => {
557
+ }
558
+ });
559
+ var ReactNodeViewContentProvider = ({ children, content }) => {
560
+ return createElement(ReactNodeViewContext.Provider, { value: { nodeViewContentChildren: content } }, children);
913
561
  };
562
+ var useReactNodeView = () => useContext2(ReactNodeViewContext);
563
+
564
+ // src/NodeViewContent.tsx
565
+ import { jsx as jsx3 } from "react/jsx-runtime";
566
+ function NodeViewContent({
567
+ as: Tag = "div",
568
+ ...props
569
+ }) {
570
+ const { nodeViewContentRef, nodeViewContentChildren } = useReactNodeView();
571
+ return (
572
+ // @ts-ignore
573
+ /* @__PURE__ */ jsx3(
574
+ Tag,
575
+ {
576
+ ...props,
577
+ ref: nodeViewContentRef,
578
+ "data-node-view-content": "",
579
+ style: {
580
+ whiteSpace: "pre-wrap",
581
+ ...props.style
582
+ },
583
+ children: nodeViewContentChildren
584
+ }
585
+ )
586
+ );
587
+ }
914
588
 
915
- const FloatingMenu = (props) => {
916
- const [element, setElement] = useState(null);
917
- const { editor: currentEditor } = useCurrentEditor();
918
- useEffect(() => {
919
- var _a;
920
- if (!element) {
921
- return;
922
- }
923
- if (((_a = props.editor) === null || _a === void 0 ? void 0 : _a.isDestroyed) || (currentEditor === null || currentEditor === void 0 ? void 0 : currentEditor.isDestroyed)) {
924
- return;
925
- }
926
- const { pluginKey = 'floatingMenu', editor, tippyOptions = {}, shouldShow = null, } = props;
927
- const menuEditor = editor || currentEditor;
928
- if (!menuEditor) {
929
- console.warn('FloatingMenu component is not rendered inside of an editor component or does not have editor prop.');
930
- return;
589
+ // src/NodeViewWrapper.tsx
590
+ import React3 from "react";
591
+ import { jsx as jsx4 } from "react/jsx-runtime";
592
+ var NodeViewWrapper = React3.forwardRef((props, ref) => {
593
+ const { onDragStart } = useReactNodeView();
594
+ const Tag = props.as || "div";
595
+ return (
596
+ // @ts-ignore
597
+ /* @__PURE__ */ jsx4(
598
+ Tag,
599
+ {
600
+ ...props,
601
+ ref,
602
+ "data-node-view-wrapper": "",
603
+ onDragStart,
604
+ style: {
605
+ whiteSpace: "normal",
606
+ ...props.style
931
607
  }
932
- const plugin = FloatingMenuPlugin({
933
- pluginKey,
934
- editor: menuEditor,
935
- element,
936
- tippyOptions,
937
- shouldShow,
938
- });
939
- menuEditor.registerPlugin(plugin);
940
- return () => menuEditor.unregisterPlugin(pluginKey);
941
- }, [
942
- props.editor,
943
- currentEditor,
944
- element,
945
- ]);
946
- return (React.createElement("div", { ref: setElement, className: props.className, style: { visibility: 'hidden' } }, props.children));
947
- };
948
-
949
- const ReactNodeViewContext = createContext({
950
- onDragStart: undefined,
608
+ }
609
+ )
610
+ );
951
611
  });
952
- const useReactNodeView = () => useContext(ReactNodeViewContext);
953
612
 
954
- const NodeViewContent = props => {
955
- const Tag = props.as || 'div';
956
- const { nodeViewContentRef } = useReactNodeView();
957
- return (React.createElement(Tag, { ...props, ref: nodeViewContentRef, "data-node-view-content": "", style: {
958
- whiteSpace: 'pre-wrap',
959
- ...props.style,
960
- } }));
961
- };
613
+ // src/ReactMarkViewRenderer.tsx
614
+ import { MarkView } from "@tiptap/core";
615
+ import React4 from "react";
962
616
 
963
- const NodeViewWrapper = React.forwardRef((props, ref) => {
964
- const { onDragStart } = useReactNodeView();
965
- const Tag = props.as || 'div';
966
- return (React.createElement(Tag, { ...props, ref: ref, "data-node-view-wrapper": "", onDragStart: onDragStart, style: {
967
- whiteSpace: 'normal',
968
- ...props.style,
969
- } }));
970
- });
971
-
972
- /**
973
- * Check if a component is a class component.
974
- * @param Component
975
- * @returns {boolean}
976
- */
617
+ // src/ReactRenderer.tsx
618
+ import { version as reactVersion } from "react";
619
+ import { flushSync } from "react-dom";
620
+ import { jsx as jsx5 } from "react/jsx-runtime";
977
621
  function isClassComponent(Component) {
978
- return !!(typeof Component === 'function'
979
- && Component.prototype
980
- && Component.prototype.isReactComponent);
622
+ return !!(typeof Component === "function" && Component.prototype && Component.prototype.isReactComponent);
981
623
  }
982
- /**
983
- * Check if a component is a forward ref component.
984
- * @param Component
985
- * @returns {boolean}
986
- */
987
624
  function isForwardRefComponent(Component) {
988
- var _a;
989
- return !!(typeof Component === 'object'
990
- && ((_a = Component.$$typeof) === null || _a === void 0 ? void 0 : _a.toString()) === 'Symbol(react.forward_ref)');
625
+ return !!(typeof Component === "object" && Component.$$typeof && (Component.$$typeof.toString() === "Symbol(react.forward_ref)" || Component.$$typeof.description === "react.forward_ref"));
991
626
  }
992
- /**
993
- * The ReactRenderer class. It's responsible for rendering React components inside the editor.
994
- * @example
995
- * new ReactRenderer(MyComponent, {
996
- * editor,
997
- * props: {
998
- * foo: 'bar',
999
- * },
1000
- * as: 'span',
1001
- * })
1002
- */
1003
- class ReactRenderer {
1004
- constructor(component, { editor, props = {}, as = 'div', className = '', attrs, }) {
1005
- this.ref = null;
1006
- this.id = Math.floor(Math.random() * 0xFFFFFFFF).toString();
1007
- this.component = component;
1008
- this.editor = editor;
1009
- this.props = props;
1010
- this.element = document.createElement(as);
1011
- this.element.classList.add('react-renderer');
1012
- if (className) {
1013
- this.element.classList.add(...className.split(' '));
1014
- }
1015
- if (attrs) {
1016
- Object.keys(attrs).forEach(key => {
1017
- this.element.setAttribute(key, attrs[key]);
1018
- });
1019
- }
1020
- this.render();
627
+ function isMemoComponent(Component) {
628
+ return !!(typeof Component === "object" && Component.$$typeof && (Component.$$typeof.toString() === "Symbol(react.memo)" || Component.$$typeof.description === "react.memo"));
629
+ }
630
+ function canReceiveRef(Component) {
631
+ if (isClassComponent(Component)) {
632
+ return true;
633
+ }
634
+ if (isForwardRefComponent(Component)) {
635
+ return true;
636
+ }
637
+ if (isMemoComponent(Component)) {
638
+ const wrappedComponent = Component.type;
639
+ if (wrappedComponent) {
640
+ return isClassComponent(wrappedComponent) || isForwardRefComponent(wrappedComponent);
1021
641
  }
1022
- render() {
1023
- var _a, _b;
1024
- const Component = this.component;
1025
- const props = this.props;
1026
- if (isClassComponent(Component) || isForwardRefComponent(Component)) {
1027
- props.ref = (ref) => {
1028
- this.ref = ref;
1029
- };
1030
- }
1031
- this.reactElement = React.createElement(Component, { ...props });
1032
- (_b = (_a = this.editor) === null || _a === void 0 ? void 0 : _a.contentComponent) === null || _b === void 0 ? void 0 : _b.setRenderer(this.id, this);
642
+ }
643
+ return false;
644
+ }
645
+ function isReact19Plus() {
646
+ try {
647
+ if (reactVersion) {
648
+ const majorVersion = parseInt(reactVersion.split(".")[0], 10);
649
+ return majorVersion >= 19;
1033
650
  }
1034
- updateProps(props = {}) {
1035
- this.props = {
1036
- ...this.props,
1037
- ...props,
1038
- };
651
+ } catch {
652
+ }
653
+ return false;
654
+ }
655
+ var ReactRenderer = class {
656
+ /**
657
+ * Immediately creates element and renders the provided React component.
658
+ */
659
+ constructor(component, { editor, props = {}, as = "div", className = "" }) {
660
+ this.ref = null;
661
+ this.id = Math.floor(Math.random() * 4294967295).toString();
662
+ this.component = component;
663
+ this.editor = editor;
664
+ this.props = props;
665
+ this.element = document.createElement(as);
666
+ this.element.classList.add("react-renderer");
667
+ if (className) {
668
+ this.element.classList.add(...className.split(" "));
669
+ }
670
+ if (this.editor.isInitialized) {
671
+ flushSync(() => {
1039
672
  this.render();
673
+ });
674
+ } else {
675
+ queueMicrotask(() => {
676
+ this.render();
677
+ });
1040
678
  }
1041
- destroy() {
1042
- var _a, _b;
1043
- (_b = (_a = this.editor) === null || _a === void 0 ? void 0 : _a.contentComponent) === null || _b === void 0 ? void 0 : _b.removeRenderer(this.id);
679
+ }
680
+ /**
681
+ * Render the React component.
682
+ */
683
+ render() {
684
+ var _a;
685
+ const Component = this.component;
686
+ const props = this.props;
687
+ const editor = this.editor;
688
+ const isReact19 = isReact19Plus();
689
+ const componentCanReceiveRef = canReceiveRef(Component);
690
+ const elementProps = { ...props };
691
+ if (elementProps.ref && !(isReact19 || componentCanReceiveRef)) {
692
+ delete elementProps.ref;
693
+ }
694
+ if (!elementProps.ref && (isReact19 || componentCanReceiveRef)) {
695
+ elementProps.ref = (ref) => {
696
+ this.ref = ref;
697
+ };
1044
698
  }
699
+ this.reactElement = /* @__PURE__ */ jsx5(Component, { ...elementProps });
700
+ (_a = editor == null ? void 0 : editor.contentComponent) == null ? void 0 : _a.setRenderer(this.id, this);
701
+ }
702
+ /**
703
+ * Re-renders the React component with new props.
704
+ */
705
+ updateProps(props = {}) {
706
+ this.props = {
707
+ ...this.props,
708
+ ...props
709
+ };
710
+ this.render();
711
+ }
712
+ /**
713
+ * Destroy the React component.
714
+ */
715
+ destroy() {
716
+ var _a;
717
+ const editor = this.editor;
718
+ (_a = editor == null ? void 0 : editor.contentComponent) == null ? void 0 : _a.removeRenderer(this.id);
719
+ }
720
+ /**
721
+ * Update the attributes of the element that holds the React component.
722
+ */
723
+ updateAttributes(attributes) {
724
+ Object.keys(attributes).forEach((key) => {
725
+ this.element.setAttribute(key, attributes[key]);
726
+ });
727
+ }
728
+ };
729
+
730
+ // src/ReactMarkViewRenderer.tsx
731
+ import { jsx as jsx6 } from "react/jsx-runtime";
732
+ var ReactMarkViewContext = React4.createContext({
733
+ markViewContentRef: () => {
734
+ }
735
+ });
736
+ var MarkViewContent = (props) => {
737
+ const { as: Tag = "span", ...rest } = props;
738
+ const { markViewContentRef } = React4.useContext(ReactMarkViewContext);
739
+ return (
740
+ // @ts-ignore
741
+ /* @__PURE__ */ jsx6(Tag, { ...rest, ref: markViewContentRef, "data-mark-view-content": "" })
742
+ );
743
+ };
744
+ var ReactMarkView = class extends MarkView {
745
+ constructor(component, props, options) {
746
+ super(component, props, options);
747
+ this.didMountContentDomElement = false;
748
+ const { as = "span", attrs, className = "" } = options || {};
749
+ const componentProps = { ...props, updateAttributes: this.updateAttributes.bind(this) };
750
+ this.contentDOMElement = document.createElement("span");
751
+ const markViewContentRef = (el) => {
752
+ if (el && this.contentDOMElement && el.firstChild !== this.contentDOMElement) {
753
+ el.appendChild(this.contentDOMElement);
754
+ this.didMountContentDomElement = true;
755
+ }
756
+ };
757
+ const context = {
758
+ markViewContentRef
759
+ };
760
+ const ReactMarkViewProvider = React4.memo((componentProps2) => {
761
+ return /* @__PURE__ */ jsx6(ReactMarkViewContext.Provider, { value: context, children: React4.createElement(component, componentProps2) });
762
+ });
763
+ ReactMarkViewProvider.displayName = "ReactNodeView";
764
+ this.renderer = new ReactRenderer(ReactMarkViewProvider, {
765
+ editor: props.editor,
766
+ props: componentProps,
767
+ as,
768
+ className: `mark-${props.mark.type.name} ${className}`.trim()
769
+ });
770
+ if (attrs) {
771
+ this.renderer.updateAttributes(attrs);
772
+ }
773
+ }
774
+ get dom() {
775
+ return this.renderer.element;
776
+ }
777
+ get contentDOM() {
778
+ if (!this.didMountContentDomElement) {
779
+ return null;
780
+ }
781
+ return this.contentDOMElement;
782
+ }
783
+ };
784
+ function ReactMarkViewRenderer(component, options = {}) {
785
+ return (props) => new ReactMarkView(component, props, options);
1045
786
  }
1046
787
 
1047
- class ReactNodeView extends NodeView {
1048
- mount() {
1049
- const props = {
1050
- editor: this.editor,
1051
- node: this.node,
1052
- decorations: this.decorations,
1053
- selected: false,
1054
- extension: this.extension,
1055
- getPos: () => this.getPos(),
1056
- updateAttributes: (attributes = {}) => this.updateAttributes(attributes),
1057
- deleteNode: () => this.deleteNode(),
1058
- };
1059
- if (!this.component.displayName) {
1060
- const capitalizeFirstChar = (string) => {
1061
- return string.charAt(0).toUpperCase() + string.substring(1);
1062
- };
1063
- this.component.displayName = capitalizeFirstChar(this.extension.name);
1064
- }
1065
- const ReactNodeViewProvider = componentProps => {
1066
- const Component = this.component;
1067
- const onDragStart = this.onDragStart.bind(this);
1068
- const nodeViewContentRef = element => {
1069
- if (element && this.contentDOMElement && element.firstChild !== this.contentDOMElement) {
1070
- element.appendChild(this.contentDOMElement);
1071
- }
1072
- };
1073
- return (React.createElement(React.Fragment, null,
1074
- React.createElement(ReactNodeViewContext.Provider, { value: { onDragStart, nodeViewContentRef } },
1075
- React.createElement(Component, { ...componentProps }))));
1076
- };
1077
- ReactNodeViewProvider.displayName = 'ReactNodeView';
1078
- if (this.node.isLeaf) {
1079
- this.contentDOMElement = null;
1080
- }
1081
- else if (this.options.contentDOMElementTag) {
1082
- this.contentDOMElement = document.createElement(this.options.contentDOMElementTag);
1083
- }
1084
- else {
1085
- this.contentDOMElement = document.createElement(this.node.isInline ? 'span' : 'div');
1086
- }
1087
- if (this.contentDOMElement) {
1088
- // For some reason the whiteSpace prop is not inherited properly in Chrome and Safari
1089
- // With this fix it seems to work fine
1090
- // See: https://github.com/ueberdosis/tiptap/issues/1197
1091
- this.contentDOMElement.style.whiteSpace = 'inherit';
1092
- }
1093
- let as = this.node.isInline ? 'span' : 'div';
1094
- if (this.options.as) {
1095
- as = this.options.as;
1096
- }
1097
- const { className = '' } = this.options;
1098
- this.handleSelectionUpdate = this.handleSelectionUpdate.bind(this);
1099
- this.editor.on('selectionUpdate', this.handleSelectionUpdate);
1100
- this.renderer = new ReactRenderer(ReactNodeViewProvider, {
1101
- editor: this.editor,
1102
- props,
1103
- as,
1104
- className: `node-${this.node.type.name} ${className}`.trim(),
1105
- attrs: this.options.attrs,
1106
- });
788
+ // src/ReactNodeViewRenderer.tsx
789
+ import { getRenderedAttributes, NodeView } from "@tiptap/core";
790
+ import { createElement as createElement2, createRef, memo } from "react";
791
+ import { jsx as jsx7 } from "react/jsx-runtime";
792
+ var ReactNodeView = class extends NodeView {
793
+ constructor(component, props, options) {
794
+ super(component, props, options);
795
+ if (!this.node.isLeaf) {
796
+ if (this.options.contentDOMElementTag) {
797
+ this.contentDOMElement = document.createElement(this.options.contentDOMElementTag);
798
+ } else {
799
+ this.contentDOMElement = document.createElement(this.node.isInline ? "span" : "div");
800
+ }
801
+ this.contentDOMElement.dataset.nodeViewContentReact = "";
802
+ this.contentDOMElement.dataset.nodeViewWrapper = "";
803
+ this.contentDOMElement.style.whiteSpace = "inherit";
804
+ const contentTarget = this.dom.querySelector("[data-node-view-content]");
805
+ if (!contentTarget) {
806
+ return;
807
+ }
808
+ contentTarget.appendChild(this.contentDOMElement);
1107
809
  }
1108
- get dom() {
1109
- var _a;
1110
- if (this.renderer.element.firstElementChild
1111
- && !((_a = this.renderer.element.firstElementChild) === null || _a === void 0 ? void 0 : _a.hasAttribute('data-node-view-wrapper'))) {
1112
- throw Error('Please use the NodeViewWrapper component for your node view.');
1113
- }
1114
- return this.renderer.element;
810
+ }
811
+ /**
812
+ * Setup the React component.
813
+ * Called on initialization.
814
+ */
815
+ mount() {
816
+ const props = {
817
+ editor: this.editor,
818
+ node: this.node,
819
+ decorations: this.decorations,
820
+ innerDecorations: this.innerDecorations,
821
+ view: this.view,
822
+ selected: false,
823
+ extension: this.extension,
824
+ HTMLAttributes: this.HTMLAttributes,
825
+ getPos: () => this.getPos(),
826
+ updateAttributes: (attributes = {}) => this.updateAttributes(attributes),
827
+ deleteNode: () => this.deleteNode(),
828
+ ref: createRef()
829
+ };
830
+ if (!this.component.displayName) {
831
+ const capitalizeFirstChar = (string) => {
832
+ return string.charAt(0).toUpperCase() + string.substring(1);
833
+ };
834
+ this.component.displayName = capitalizeFirstChar(this.extension.name);
1115
835
  }
1116
- get contentDOM() {
1117
- if (this.node.isLeaf) {
1118
- return null;
836
+ const onDragStart = this.onDragStart.bind(this);
837
+ const nodeViewContentRef = (element) => {
838
+ if (element && this.contentDOMElement && element.firstChild !== this.contentDOMElement) {
839
+ if (element.hasAttribute("data-node-view-wrapper")) {
840
+ element.removeAttribute("data-node-view-wrapper");
1119
841
  }
1120
- return this.contentDOMElement;
842
+ element.appendChild(this.contentDOMElement);
843
+ }
844
+ };
845
+ const context = { onDragStart, nodeViewContentRef };
846
+ const Component = this.component;
847
+ const ReactNodeViewProvider = memo((componentProps) => {
848
+ return /* @__PURE__ */ jsx7(ReactNodeViewContext.Provider, { value: context, children: createElement2(Component, componentProps) });
849
+ });
850
+ ReactNodeViewProvider.displayName = "ReactNodeView";
851
+ let as = this.node.isInline ? "span" : "div";
852
+ if (this.options.as) {
853
+ as = this.options.as;
1121
854
  }
1122
- handleSelectionUpdate() {
1123
- const { from, to } = this.editor.state.selection;
1124
- if (from <= this.getPos() && to >= this.getPos() + this.node.nodeSize) {
1125
- if (this.renderer.props.selected) {
1126
- return;
1127
- }
1128
- this.selectNode();
1129
- }
1130
- else {
1131
- if (!this.renderer.props.selected) {
1132
- return;
1133
- }
1134
- this.deselectNode();
1135
- }
855
+ const { className = "" } = this.options;
856
+ this.handleSelectionUpdate = this.handleSelectionUpdate.bind(this);
857
+ this.renderer = new ReactRenderer(ReactNodeViewProvider, {
858
+ editor: this.editor,
859
+ props,
860
+ as,
861
+ className: `node-${this.node.type.name} ${className}`.trim()
862
+ });
863
+ this.editor.on("selectionUpdate", this.handleSelectionUpdate);
864
+ this.updateElementAttributes();
865
+ }
866
+ /**
867
+ * Return the DOM element.
868
+ * This is the element that will be used to display the node view.
869
+ */
870
+ get dom() {
871
+ var _a;
872
+ if (this.renderer.element.firstElementChild && !((_a = this.renderer.element.firstElementChild) == null ? void 0 : _a.hasAttribute("data-node-view-wrapper"))) {
873
+ throw Error("Please use the NodeViewWrapper component for your node view.");
1136
874
  }
1137
- update(node, decorations) {
1138
- const updateProps = (props) => {
1139
- this.renderer.updateProps(props);
1140
- };
1141
- if (node.type !== this.node.type) {
1142
- return false;
1143
- }
1144
- if (typeof this.options.update === 'function') {
1145
- const oldNode = this.node;
1146
- const oldDecorations = this.decorations;
1147
- this.node = node;
1148
- this.decorations = decorations;
1149
- return this.options.update({
1150
- oldNode,
1151
- oldDecorations,
1152
- newNode: node,
1153
- newDecorations: decorations,
1154
- updateProps: () => updateProps({ node, decorations }),
1155
- });
1156
- }
1157
- if (node === this.node && this.decorations === decorations) {
1158
- return true;
1159
- }
1160
- this.node = node;
1161
- this.decorations = decorations;
1162
- updateProps({ node, decorations });
1163
- return true;
875
+ return this.renderer.element;
876
+ }
877
+ /**
878
+ * Return the content DOM element.
879
+ * This is the element that will be used to display the rich-text content of the node.
880
+ */
881
+ get contentDOM() {
882
+ if (this.node.isLeaf) {
883
+ return null;
1164
884
  }
1165
- selectNode() {
1166
- this.renderer.updateProps({
1167
- selected: true,
1168
- });
1169
- this.renderer.element.classList.add('ProseMirror-selectednode');
885
+ return this.contentDOMElement;
886
+ }
887
+ /**
888
+ * On editor selection update, check if the node is selected.
889
+ * If it is, call `selectNode`, otherwise call `deselectNode`.
890
+ */
891
+ handleSelectionUpdate() {
892
+ const { from, to } = this.editor.state.selection;
893
+ const pos = this.getPos();
894
+ if (typeof pos !== "number") {
895
+ return;
1170
896
  }
1171
- deselectNode() {
1172
- this.renderer.updateProps({
1173
- selected: false,
1174
- });
1175
- this.renderer.element.classList.remove('ProseMirror-selectednode');
897
+ if (from <= pos && to >= pos + this.node.nodeSize) {
898
+ if (this.renderer.props.selected) {
899
+ return;
900
+ }
901
+ this.selectNode();
902
+ } else {
903
+ if (!this.renderer.props.selected) {
904
+ return;
905
+ }
906
+ this.deselectNode();
1176
907
  }
1177
- destroy() {
1178
- this.renderer.destroy();
1179
- this.editor.off('selectionUpdate', this.handleSelectionUpdate);
1180
- this.contentDOMElement = null;
908
+ }
909
+ /**
910
+ * On update, update the React component.
911
+ * To prevent unnecessary updates, the `update` option can be used.
912
+ */
913
+ update(node, decorations, innerDecorations) {
914
+ const rerenderComponent = (props) => {
915
+ this.renderer.updateProps(props);
916
+ if (typeof this.options.attrs === "function") {
917
+ this.updateElementAttributes();
918
+ }
919
+ };
920
+ if (node.type !== this.node.type) {
921
+ return false;
1181
922
  }
1182
- }
923
+ if (typeof this.options.update === "function") {
924
+ const oldNode = this.node;
925
+ const oldDecorations = this.decorations;
926
+ const oldInnerDecorations = this.innerDecorations;
927
+ this.node = node;
928
+ this.decorations = decorations;
929
+ this.innerDecorations = innerDecorations;
930
+ return this.options.update({
931
+ oldNode,
932
+ oldDecorations,
933
+ newNode: node,
934
+ newDecorations: decorations,
935
+ oldInnerDecorations,
936
+ innerDecorations,
937
+ updateProps: () => rerenderComponent({ node, decorations, innerDecorations })
938
+ });
939
+ }
940
+ if (node === this.node && this.decorations === decorations && this.innerDecorations === innerDecorations) {
941
+ return true;
942
+ }
943
+ this.node = node;
944
+ this.decorations = decorations;
945
+ this.innerDecorations = innerDecorations;
946
+ rerenderComponent({ node, decorations, innerDecorations });
947
+ return true;
948
+ }
949
+ /**
950
+ * Select the node.
951
+ * Add the `selected` prop and the `ProseMirror-selectednode` class.
952
+ */
953
+ selectNode() {
954
+ this.renderer.updateProps({
955
+ selected: true
956
+ });
957
+ this.renderer.element.classList.add("ProseMirror-selectednode");
958
+ }
959
+ /**
960
+ * Deselect the node.
961
+ * Remove the `selected` prop and the `ProseMirror-selectednode` class.
962
+ */
963
+ deselectNode() {
964
+ this.renderer.updateProps({
965
+ selected: false
966
+ });
967
+ this.renderer.element.classList.remove("ProseMirror-selectednode");
968
+ }
969
+ /**
970
+ * Destroy the React component instance.
971
+ */
972
+ destroy() {
973
+ this.renderer.destroy();
974
+ this.editor.off("selectionUpdate", this.handleSelectionUpdate);
975
+ this.contentDOMElement = null;
976
+ }
977
+ /**
978
+ * Update the attributes of the top-level element that holds the React component.
979
+ * Applying the attributes defined in the `attrs` option.
980
+ */
981
+ updateElementAttributes() {
982
+ if (this.options.attrs) {
983
+ let attrsObj = {};
984
+ if (typeof this.options.attrs === "function") {
985
+ const extensionAttributes = this.editor.extensionManager.attributes;
986
+ const HTMLAttributes = getRenderedAttributes(this.node, extensionAttributes);
987
+ attrsObj = this.options.attrs({ node: this.node, HTMLAttributes });
988
+ } else {
989
+ attrsObj = this.options.attrs;
990
+ }
991
+ this.renderer.updateAttributes(attrsObj);
992
+ }
993
+ }
994
+ };
1183
995
  function ReactNodeViewRenderer(component, options) {
1184
- return (props) => {
1185
- // try to get the parent component
1186
- // this is important for vue devtools to show the component hierarchy correctly
1187
- // maybe it’s `undefined` because <editor-content> isn’t rendered yet
1188
- if (!props.editor.contentComponent) {
1189
- return {};
1190
- }
1191
- return new ReactNodeView(component, props, options);
1192
- };
996
+ return (props) => {
997
+ if (!props.editor.contentComponent) {
998
+ return {};
999
+ }
1000
+ return new ReactNodeView(component, props, options);
1001
+ };
1193
1002
  }
1194
1003
 
1195
- export { BubbleMenu, Editor, EditorConsumer, EditorContent, EditorContext, EditorProvider, FloatingMenu, NodeViewContent, NodeViewWrapper, PureEditorContent, ReactNodeViewContext, ReactNodeViewRenderer, ReactRenderer, useCurrentEditor, useEditor, useEditorState, useReactNodeView };
1196
- //# sourceMappingURL=index.js.map
1004
+ // src/index.ts
1005
+ export * from "@tiptap/core";
1006
+ export {
1007
+ EditorConsumer,
1008
+ EditorContent,
1009
+ EditorContext,
1010
+ EditorProvider,
1011
+ MarkViewContent,
1012
+ NodeViewContent,
1013
+ NodeViewWrapper,
1014
+ PureEditorContent,
1015
+ ReactMarkView,
1016
+ ReactMarkViewContext,
1017
+ ReactMarkViewRenderer,
1018
+ ReactNodeView,
1019
+ ReactNodeViewContentProvider,
1020
+ ReactNodeViewContext,
1021
+ ReactNodeViewRenderer,
1022
+ ReactRenderer,
1023
+ useCurrentEditor,
1024
+ useEditor,
1025
+ useEditorState,
1026
+ useReactNodeView
1027
+ };
1028
+ //# sourceMappingURL=index.js.map