@tiptap/react 3.0.0-next.0 → 3.0.0-next.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (201) hide show
  1. package/dist/index.cjs +996 -1126
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.cts +334 -0
  4. package/dist/index.d.ts +334 -0
  5. package/dist/index.js +960 -1098
  6. package/dist/index.js.map +1 -1
  7. package/package.json +14 -15
  8. package/src/BubbleMenu.tsx +70 -50
  9. package/src/Context.tsx +15 -7
  10. package/src/Editor.ts +7 -8
  11. package/src/EditorContent.tsx +98 -50
  12. package/src/FloatingMenu.tsx +51 -45
  13. package/src/NodeViewContent.tsx +1 -0
  14. package/src/NodeViewWrapper.tsx +1 -0
  15. package/src/ReactNodeViewRenderer.tsx +163 -53
  16. package/src/ReactRenderer.tsx +42 -23
  17. package/src/index.ts +0 -1
  18. package/src/useEditor.ts +253 -92
  19. package/src/useEditorState.ts +122 -69
  20. package/dist/index.umd.js +0 -1176
  21. package/dist/index.umd.js.map +0 -1
  22. package/dist/packages/core/src/CommandManager.d.ts +0 -20
  23. package/dist/packages/core/src/Editor.d.ts +0 -159
  24. package/dist/packages/core/src/EventEmitter.d.ts +0 -11
  25. package/dist/packages/core/src/Extension.d.ts +0 -343
  26. package/dist/packages/core/src/ExtensionManager.d.ts +0 -55
  27. package/dist/packages/core/src/InputRule.d.ts +0 -42
  28. package/dist/packages/core/src/Mark.d.ts +0 -451
  29. package/dist/packages/core/src/Node.d.ts +0 -611
  30. package/dist/packages/core/src/NodePos.d.ts +0 -44
  31. package/dist/packages/core/src/NodeView.d.ts +0 -31
  32. package/dist/packages/core/src/PasteRule.d.ts +0 -50
  33. package/dist/packages/core/src/Tracker.d.ts +0 -11
  34. package/dist/packages/core/src/commands/blur.d.ts +0 -13
  35. package/dist/packages/core/src/commands/clearContent.d.ts +0 -14
  36. package/dist/packages/core/src/commands/clearNodes.d.ts +0 -13
  37. package/dist/packages/core/src/commands/command.d.ts +0 -18
  38. package/dist/packages/core/src/commands/createParagraphNear.d.ts +0 -13
  39. package/dist/packages/core/src/commands/cut.d.ts +0 -20
  40. package/dist/packages/core/src/commands/deleteCurrentNode.d.ts +0 -13
  41. package/dist/packages/core/src/commands/deleteNode.d.ts +0 -15
  42. package/dist/packages/core/src/commands/deleteRange.d.ts +0 -14
  43. package/dist/packages/core/src/commands/deleteSelection.d.ts +0 -13
  44. package/dist/packages/core/src/commands/enter.d.ts +0 -13
  45. package/dist/packages/core/src/commands/exitCode.d.ts +0 -13
  46. package/dist/packages/core/src/commands/extendMarkRange.d.ts +0 -25
  47. package/dist/packages/core/src/commands/first.d.ts +0 -14
  48. package/dist/packages/core/src/commands/focus.d.ts +0 -27
  49. package/dist/packages/core/src/commands/forEach.d.ts +0 -14
  50. package/dist/packages/core/src/commands/index.d.ts +0 -55
  51. package/dist/packages/core/src/commands/insertContent.d.ts +0 -34
  52. package/dist/packages/core/src/commands/insertContentAt.d.ts +0 -47
  53. package/dist/packages/core/src/commands/join.d.ts +0 -41
  54. package/dist/packages/core/src/commands/joinItemBackward.d.ts +0 -13
  55. package/dist/packages/core/src/commands/joinItemForward.d.ts +0 -13
  56. package/dist/packages/core/src/commands/joinTextblockBackward.d.ts +0 -12
  57. package/dist/packages/core/src/commands/joinTextblockForward.d.ts +0 -12
  58. package/dist/packages/core/src/commands/keyboardShortcut.d.ts +0 -14
  59. package/dist/packages/core/src/commands/lift.d.ts +0 -17
  60. package/dist/packages/core/src/commands/liftEmptyBlock.d.ts +0 -13
  61. package/dist/packages/core/src/commands/liftListItem.d.ts +0 -15
  62. package/dist/packages/core/src/commands/newlineInCode.d.ts +0 -13
  63. package/dist/packages/core/src/commands/resetAttributes.d.ts +0 -16
  64. package/dist/packages/core/src/commands/scrollIntoView.d.ts +0 -13
  65. package/dist/packages/core/src/commands/selectAll.d.ts +0 -13
  66. package/dist/packages/core/src/commands/selectNodeBackward.d.ts +0 -13
  67. package/dist/packages/core/src/commands/selectNodeForward.d.ts +0 -13
  68. package/dist/packages/core/src/commands/selectParentNode.d.ts +0 -13
  69. package/dist/packages/core/src/commands/selectTextblockEnd.d.ts +0 -13
  70. package/dist/packages/core/src/commands/selectTextblockStart.d.ts +0 -13
  71. package/dist/packages/core/src/commands/setContent.d.ts +0 -40
  72. package/dist/packages/core/src/commands/setMark.d.ts +0 -15
  73. package/dist/packages/core/src/commands/setMeta.d.ts +0 -15
  74. package/dist/packages/core/src/commands/setNode.d.ts +0 -16
  75. package/dist/packages/core/src/commands/setNodeSelection.d.ts +0 -14
  76. package/dist/packages/core/src/commands/setTextSelection.d.ts +0 -14
  77. package/dist/packages/core/src/commands/sinkListItem.d.ts +0 -15
  78. package/dist/packages/core/src/commands/splitBlock.d.ts +0 -17
  79. package/dist/packages/core/src/commands/splitListItem.d.ts +0 -15
  80. package/dist/packages/core/src/commands/toggleList.d.ts +0 -18
  81. package/dist/packages/core/src/commands/toggleMark.d.ts +0 -30
  82. package/dist/packages/core/src/commands/toggleNode.d.ts +0 -17
  83. package/dist/packages/core/src/commands/toggleWrap.d.ts +0 -16
  84. package/dist/packages/core/src/commands/undoInputRule.d.ts +0 -13
  85. package/dist/packages/core/src/commands/unsetAllMarks.d.ts +0 -13
  86. package/dist/packages/core/src/commands/unsetMark.d.ts +0 -25
  87. package/dist/packages/core/src/commands/updateAttributes.d.ts +0 -24
  88. package/dist/packages/core/src/commands/wrapIn.d.ts +0 -16
  89. package/dist/packages/core/src/commands/wrapInList.d.ts +0 -16
  90. package/dist/packages/core/src/extensions/clipboardTextSerializer.d.ts +0 -5
  91. package/dist/packages/core/src/extensions/commands.d.ts +0 -3
  92. package/dist/packages/core/src/extensions/editable.d.ts +0 -2
  93. package/dist/packages/core/src/extensions/focusEvents.d.ts +0 -2
  94. package/dist/packages/core/src/extensions/index.d.ts +0 -6
  95. package/dist/packages/core/src/extensions/keymap.d.ts +0 -2
  96. package/dist/packages/core/src/extensions/tabindex.d.ts +0 -2
  97. package/dist/packages/core/src/helpers/combineTransactionSteps.d.ts +0 -10
  98. package/dist/packages/core/src/helpers/createChainableState.d.ts +0 -10
  99. package/dist/packages/core/src/helpers/createDocument.d.ts +0 -12
  100. package/dist/packages/core/src/helpers/createNodeFromContent.d.ts +0 -15
  101. package/dist/packages/core/src/helpers/defaultBlockAt.d.ts +0 -7
  102. package/dist/packages/core/src/helpers/findChildren.d.ts +0 -9
  103. package/dist/packages/core/src/helpers/findChildrenInRange.d.ts +0 -10
  104. package/dist/packages/core/src/helpers/findParentNode.d.ts +0 -16
  105. package/dist/packages/core/src/helpers/findParentNodeClosestToPos.d.ts +0 -17
  106. package/dist/packages/core/src/helpers/generateHTML.d.ts +0 -8
  107. package/dist/packages/core/src/helpers/generateJSON.d.ts +0 -8
  108. package/dist/packages/core/src/helpers/generateText.d.ts +0 -12
  109. package/dist/packages/core/src/helpers/getAttributes.d.ts +0 -9
  110. package/dist/packages/core/src/helpers/getAttributesFromExtensions.d.ts +0 -6
  111. package/dist/packages/core/src/helpers/getChangedRanges.d.ts +0 -11
  112. package/dist/packages/core/src/helpers/getDebugJSON.d.ts +0 -8
  113. package/dist/packages/core/src/helpers/getExtensionField.d.ts +0 -9
  114. package/dist/packages/core/src/helpers/getHTMLFromFragment.d.ts +0 -2
  115. package/dist/packages/core/src/helpers/getMarkAttributes.d.ts +0 -3
  116. package/dist/packages/core/src/helpers/getMarkRange.d.ts +0 -3
  117. package/dist/packages/core/src/helpers/getMarkType.d.ts +0 -2
  118. package/dist/packages/core/src/helpers/getMarksBetween.d.ts +0 -3
  119. package/dist/packages/core/src/helpers/getNodeAtPosition.d.ts +0 -11
  120. package/dist/packages/core/src/helpers/getNodeAttributes.d.ts +0 -3
  121. package/dist/packages/core/src/helpers/getNodeType.d.ts +0 -2
  122. package/dist/packages/core/src/helpers/getRenderedAttributes.d.ts +0 -3
  123. package/dist/packages/core/src/helpers/getSchema.d.ts +0 -4
  124. package/dist/packages/core/src/helpers/getSchemaByResolvedExtensions.d.ts +0 -10
  125. package/dist/packages/core/src/helpers/getSchemaTypeByName.d.ts +0 -8
  126. package/dist/packages/core/src/helpers/getSchemaTypeNameByName.d.ts +0 -8
  127. package/dist/packages/core/src/helpers/getSplittedAttributes.d.ts +0 -9
  128. package/dist/packages/core/src/helpers/getText.d.ts +0 -15
  129. package/dist/packages/core/src/helpers/getTextBetween.d.ts +0 -14
  130. package/dist/packages/core/src/helpers/getTextContentFromNodes.d.ts +0 -8
  131. package/dist/packages/core/src/helpers/getTextSerializersFromSchema.d.ts +0 -8
  132. package/dist/packages/core/src/helpers/index.d.ts +0 -50
  133. package/dist/packages/core/src/helpers/injectExtensionAttributesToParseRule.d.ts +0 -9
  134. package/dist/packages/core/src/helpers/isActive.d.ts +0 -2
  135. package/dist/packages/core/src/helpers/isAtEndOfNode.d.ts +0 -2
  136. package/dist/packages/core/src/helpers/isAtStartOfNode.d.ts +0 -2
  137. package/dist/packages/core/src/helpers/isExtensionRulesEnabled.d.ts +0 -2
  138. package/dist/packages/core/src/helpers/isList.d.ts +0 -2
  139. package/dist/packages/core/src/helpers/isMarkActive.d.ts +0 -3
  140. package/dist/packages/core/src/helpers/isNodeActive.d.ts +0 -3
  141. package/dist/packages/core/src/helpers/isNodeEmpty.d.ts +0 -8
  142. package/dist/packages/core/src/helpers/isNodeSelection.d.ts +0 -2
  143. package/dist/packages/core/src/helpers/isTextSelection.d.ts +0 -2
  144. package/dist/packages/core/src/helpers/posToDOMRect.d.ts +0 -2
  145. package/dist/packages/core/src/helpers/resolveFocusPosition.d.ts +0 -4
  146. package/dist/packages/core/src/helpers/selectionToInsertionEnd.d.ts +0 -2
  147. package/dist/packages/core/src/helpers/splitExtensions.d.ts +0 -9
  148. package/dist/packages/core/src/index.d.ts +0 -24
  149. package/dist/packages/core/src/inputRules/index.d.ts +0 -5
  150. package/dist/packages/core/src/inputRules/markInputRule.d.ts +0 -13
  151. package/dist/packages/core/src/inputRules/nodeInputRule.d.ts +0 -23
  152. package/dist/packages/core/src/inputRules/textInputRule.d.ts +0 -10
  153. package/dist/packages/core/src/inputRules/textblockTypeInputRule.d.ts +0 -15
  154. package/dist/packages/core/src/inputRules/wrappingInputRule.d.ts +0 -28
  155. package/dist/packages/core/src/pasteRules/index.d.ts +0 -3
  156. package/dist/packages/core/src/pasteRules/markPasteRule.d.ts +0 -13
  157. package/dist/packages/core/src/pasteRules/nodePasteRule.d.ts +0 -13
  158. package/dist/packages/core/src/pasteRules/textPasteRule.d.ts +0 -10
  159. package/dist/packages/core/src/style.d.ts +0 -1
  160. package/dist/packages/core/src/types.d.ts +0 -253
  161. package/dist/packages/core/src/utilities/callOrReturn.d.ts +0 -9
  162. package/dist/packages/core/src/utilities/createStyleTag.d.ts +0 -1
  163. package/dist/packages/core/src/utilities/deleteProps.d.ts +0 -6
  164. package/dist/packages/core/src/utilities/elementFromString.d.ts +0 -1
  165. package/dist/packages/core/src/utilities/escapeForRegEx.d.ts +0 -1
  166. package/dist/packages/core/src/utilities/findDuplicates.d.ts +0 -1
  167. package/dist/packages/core/src/utilities/fromString.d.ts +0 -1
  168. package/dist/packages/core/src/utilities/index.d.ts +0 -20
  169. package/dist/packages/core/src/utilities/isAndroid.d.ts +0 -1
  170. package/dist/packages/core/src/utilities/isEmptyObject.d.ts +0 -1
  171. package/dist/packages/core/src/utilities/isFunction.d.ts +0 -1
  172. package/dist/packages/core/src/utilities/isMacOS.d.ts +0 -1
  173. package/dist/packages/core/src/utilities/isNumber.d.ts +0 -1
  174. package/dist/packages/core/src/utilities/isPlainObject.d.ts +0 -1
  175. package/dist/packages/core/src/utilities/isRegExp.d.ts +0 -1
  176. package/dist/packages/core/src/utilities/isString.d.ts +0 -1
  177. package/dist/packages/core/src/utilities/isiOS.d.ts +0 -1
  178. package/dist/packages/core/src/utilities/mergeAttributes.d.ts +0 -1
  179. package/dist/packages/core/src/utilities/mergeDeep.d.ts +0 -1
  180. package/dist/packages/core/src/utilities/minMax.d.ts +0 -1
  181. package/dist/packages/core/src/utilities/objectIncludes.d.ts +0 -8
  182. package/dist/packages/core/src/utilities/removeDuplicates.d.ts +0 -8
  183. package/dist/packages/extension-bubble-menu/src/bubble-menu-plugin.d.ts +0 -99
  184. package/dist/packages/extension-bubble-menu/src/bubble-menu.d.ts +0 -15
  185. package/dist/packages/extension-bubble-menu/src/index.d.ts +0 -4
  186. package/dist/packages/extension-floating-menu/src/floating-menu-plugin.d.ts +0 -81
  187. package/dist/packages/extension-floating-menu/src/floating-menu.d.ts +0 -15
  188. package/dist/packages/extension-floating-menu/src/index.d.ts +0 -4
  189. package/dist/packages/react/src/BubbleMenu.d.ts +0 -13
  190. package/dist/packages/react/src/Context.d.ts +0 -23
  191. package/dist/packages/react/src/Editor.d.ts +0 -12
  192. package/dist/packages/react/src/EditorContent.d.ts +0 -24
  193. package/dist/packages/react/src/FloatingMenu.d.ts +0 -11
  194. package/dist/packages/react/src/NodeViewContent.d.ts +0 -6
  195. package/dist/packages/react/src/NodeViewWrapper.d.ts +0 -6
  196. package/dist/packages/react/src/ReactNodeViewRenderer.d.ts +0 -16
  197. package/dist/packages/react/src/ReactRenderer.d.ts +0 -62
  198. package/dist/packages/react/src/index.d.ts +0 -13
  199. package/dist/packages/react/src/useEditor.d.ts +0 -39
  200. package/dist/packages/react/src/useEditorState.d.ts +0 -22
  201. package/dist/packages/react/src/useReactNodeView.d.ts +0 -6
package/dist/index.js CHANGED
@@ -1,1153 +1,1015 @@
1
- import { BubbleMenuPlugin } from '@tiptap/extension-bubble-menu';
2
- import React, { forwardRef, useState, useEffect, useDebugValue, useRef, createContext, useContext } from 'react';
3
- import ReactDOM, { flushSync, createPortal } 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/BubbleMenu.tsx
2
+ import { BubbleMenuPlugin } from "@tiptap/extension-bubble-menu";
3
+ import React3, { useEffect as useEffect3, useRef as useRef2 } from "react";
4
+ import { createPortal } from "react-dom";
5
+
6
+ // src/Context.tsx
7
+ import React2, {
8
+ createContext,
9
+ useContext,
10
+ useMemo
11
+ } from "react";
12
+
13
+ // src/EditorContent.tsx
14
+ import React, {
15
+ forwardRef
16
+ } from "react";
17
+ import ReactDOM from "react-dom";
18
+ import { useSyncExternalStore } from "use-sync-external-store/shim";
19
+ var mergeRefs = (...refs) => {
20
+ return (node) => {
21
+ refs.forEach((ref) => {
22
+ if (typeof ref === "function") {
23
+ ref(node);
24
+ } else if (ref) {
25
+ ref.current = node;
26
+ }
27
+ });
28
+ };
19
29
  };
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
- })));
30
+ var Portals = ({
31
+ contentComponent
32
+ }) => {
33
+ const renderers = useSyncExternalStore(
34
+ contentComponent.subscribe,
35
+ contentComponent.getSnapshot,
36
+ contentComponent.getServerSnapshot
37
+ );
38
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, Object.values(renderers));
24
39
  };
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();
40
+ function getInstance() {
41
+ const subscribers = /* @__PURE__ */ new Set();
42
+ let renderers = {};
43
+ return {
44
+ /**
45
+ * Subscribe to the editor instance's changes.
46
+ */
47
+ subscribe(callback) {
48
+ subscribers.add(callback);
49
+ return () => {
50
+ subscribers.delete(callback);
51
+ };
52
+ },
53
+ getSnapshot() {
54
+ return renderers;
55
+ },
56
+ getServerSnapshot() {
57
+ return renderers;
58
+ },
59
+ /**
60
+ * Adds a new NodeView Renderer to the editor.
61
+ */
62
+ setRenderer(id, renderer) {
63
+ renderers = {
64
+ ...renderers,
65
+ [id]: ReactDOM.createPortal(renderer.reactElement, renderer.element, id)
66
+ };
67
+ subscribers.forEach((subscriber) => subscriber());
68
+ },
69
+ /**
70
+ * Removes a NodeView Renderer from the editor.
71
+ */
72
+ removeRenderer(id) {
73
+ const nextRenderers = { ...renderers };
74
+ delete nextRenderers[id];
75
+ renderers = nextRenderers;
76
+ subscribers.forEach((subscriber) => subscriber());
39
77
  }
40
- init() {
41
- const { editor } = this.props;
42
- if (editor && !editor.isDestroyed && editor.options.element) {
43
- if (editor.contentComponent) {
44
- return;
78
+ };
79
+ }
80
+ var PureEditorContent = class extends React.Component {
81
+ constructor(props) {
82
+ var _a;
83
+ super(props);
84
+ this.editorContentRef = React.createRef();
85
+ this.initialized = false;
86
+ this.state = {
87
+ hasContentComponentInitialized: Boolean((_a = props.editor) == null ? void 0 : _a.contentComponent)
88
+ };
89
+ }
90
+ componentDidMount() {
91
+ this.init();
92
+ }
93
+ componentDidUpdate() {
94
+ this.init();
95
+ }
96
+ init() {
97
+ const editor = this.props.editor;
98
+ if (editor && !editor.isDestroyed && editor.options.element) {
99
+ if (editor.contentComponent) {
100
+ return;
101
+ }
102
+ const element = this.editorContentRef.current;
103
+ element.append(...editor.options.element.childNodes);
104
+ editor.setOptions({
105
+ element
106
+ });
107
+ editor.contentComponent = getInstance();
108
+ if (!this.state.hasContentComponentInitialized) {
109
+ this.unsubscribeToContentComponent = editor.contentComponent.subscribe(() => {
110
+ this.setState((prevState) => {
111
+ if (!prevState.hasContentComponentInitialized) {
112
+ return {
113
+ hasContentComponentInitialized: true
114
+ };
45
115
  }
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
- }));
116
+ return prevState;
117
+ });
118
+ if (this.unsubscribeToContentComponent) {
119
+ this.unsubscribeToContentComponent();
120
+ }
76
121
  });
122
+ }
123
+ editor.createNodeViews();
124
+ this.initialized = true;
77
125
  }
78
- removeRenderer(id) {
79
- this.maybeFlushSync(() => {
80
- this.setState(({ renderers }) => {
81
- const nextRenderers = { ...renderers };
82
- delete nextRenderers[id];
83
- return { renderers: nextRenderers };
84
- });
85
- });
126
+ }
127
+ componentWillUnmount() {
128
+ const editor = this.props.editor;
129
+ if (!editor) {
130
+ return;
86
131
  }
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
- });
132
+ this.initialized = false;
133
+ if (!editor.isDestroyed) {
134
+ editor.view.setProps({
135
+ nodeViews: {}
136
+ });
107
137
  }
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 })));
138
+ if (this.unsubscribeToContentComponent) {
139
+ this.unsubscribeToContentComponent();
113
140
  }
114
- }
115
- // EditorContent should be re-created whenever the Editor instance changes
116
- const EditorContentWithKey = forwardRef((props, ref) => {
141
+ editor.contentComponent = null;
142
+ if (!editor.options.element.firstChild) {
143
+ return;
144
+ }
145
+ const newElement = document.createElement("div");
146
+ newElement.append(...editor.options.element.childNodes);
147
+ editor.setOptions({
148
+ element: newElement
149
+ });
150
+ }
151
+ render() {
152
+ const { editor, innerRef, ...rest } = this.props;
153
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", { ref: mergeRefs(innerRef, this.editorContentRef), ...rest }), (editor == null ? void 0 : editor.contentComponent) && /* @__PURE__ */ React.createElement(Portals, { contentComponent: editor.contentComponent }));
154
+ }
155
+ };
156
+ var EditorContentWithKey = forwardRef(
157
+ (props, ref) => {
117
158
  const key = React.useMemo(() => {
118
- return Math.floor(Math.random() * 0xFFFFFFFF).toString();
159
+ return Math.floor(Math.random() * 4294967295).toString();
119
160
  }, [props.editor]);
120
- // Can't use JSX here because it conflicts with the type definition of Vue's JSX, so use createElement
121
161
  return React.createElement(PureEditorContent, {
122
- key,
123
- innerRef: ref,
124
- ...props,
162
+ key,
163
+ innerRef: ref,
164
+ ...props
125
165
  });
126
- });
127
- const EditorContent = React.memo(EditorContentWithKey);
128
-
129
- class Editor extends Editor$1 {
130
- constructor() {
131
- super(...arguments);
132
- this.contentComponent = null;
166
+ }
167
+ );
168
+ var EditorContent = React.memo(EditorContentWithKey);
169
+
170
+ // src/useEditor.ts
171
+ import { Editor } from "@tiptap/core";
172
+ import {
173
+ useDebugValue as useDebugValue2,
174
+ useEffect as useEffect2,
175
+ useRef,
176
+ useState as useState2
177
+ } from "react";
178
+ import { useSyncExternalStore as useSyncExternalStore2 } from "use-sync-external-store/shim";
179
+
180
+ // src/useEditorState.ts
181
+ import deepEqual from "fast-deep-equal/es6/react";
182
+ import {
183
+ useDebugValue,
184
+ useEffect,
185
+ useLayoutEffect,
186
+ useState
187
+ } from "react";
188
+ import { useSyncExternalStoreWithSelector } from "use-sync-external-store/shim/with-selector";
189
+ var useIsomorphicLayoutEffect = typeof window !== "undefined" ? useLayoutEffect : useEffect;
190
+ var EditorStateManager = class {
191
+ constructor(initialEditor) {
192
+ this.transactionNumber = 0;
193
+ this.lastTransactionNumber = 0;
194
+ this.subscribers = /* @__PURE__ */ new Set();
195
+ this.editor = initialEditor;
196
+ this.lastSnapshot = { editor: initialEditor, transactionNumber: 0 };
197
+ this.getSnapshot = this.getSnapshot.bind(this);
198
+ this.getServerSnapshot = this.getServerSnapshot.bind(this);
199
+ this.watch = this.watch.bind(this);
200
+ this.subscribe = this.subscribe.bind(this);
201
+ }
202
+ /**
203
+ * Get the current editor instance.
204
+ */
205
+ getSnapshot() {
206
+ if (this.transactionNumber === this.lastTransactionNumber) {
207
+ return this.lastSnapshot;
133
208
  }
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
- },
209
+ this.lastTransactionNumber = this.transactionNumber;
210
+ this.lastSnapshot = { editor: this.editor, transactionNumber: this.transactionNumber };
211
+ return this.lastSnapshot;
212
+ }
213
+ /**
214
+ * Always disable the editor on the server-side.
215
+ */
216
+ getServerSnapshot() {
217
+ return { editor: null, transactionNumber: 0 };
218
+ }
219
+ /**
220
+ * Subscribe to the editor instance's changes.
221
+ */
222
+ subscribe(callback) {
223
+ this.subscribers.add(callback);
224
+ return () => {
225
+ this.subscribers.delete(callback);
684
226
  };
685
- return editorInstance;
686
- }
227
+ }
228
+ /**
229
+ * Watch the editor instance for changes.
230
+ */
231
+ watch(nextEditor) {
232
+ this.editor = nextEditor;
233
+ if (this.editor) {
234
+ const fn = () => {
235
+ this.transactionNumber += 1;
236
+ this.subscribers.forEach((callback) => callback());
237
+ };
238
+ const currentEditor = this.editor;
239
+ currentEditor.on("transaction", fn);
240
+ return () => {
241
+ currentEditor.off("transaction", fn);
242
+ };
243
+ }
244
+ return void 0;
245
+ }
246
+ };
687
247
  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;
248
+ var _a;
249
+ const [editorStateManager] = useState(() => new EditorStateManager(options.editor));
250
+ const selectedState = useSyncExternalStoreWithSelector(
251
+ editorStateManager.subscribe,
252
+ editorStateManager.getSnapshot,
253
+ editorStateManager.getServerSnapshot,
254
+ options.selector,
255
+ (_a = options.equalityFn) != null ? _a : deepEqual
256
+ );
257
+ useIsomorphicLayoutEffect(() => {
258
+ return editorStateManager.watch(options.editor);
259
+ }, [options.editor, editorStateManager]);
260
+ useDebugValue(selectedState);
261
+ return selectedState;
696
262
  }
697
263
 
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
- /**
702
- * Create a new editor instance. And attach event listeners.
703
- */
704
- function createEditor(options) {
705
- const editor = new Editor(options.current);
706
- editor.on('beforeCreate', (...args) => { var _a, _b; return (_b = (_a = options.current).onBeforeCreate) === null || _b === void 0 ? void 0 : _b.call(_a, ...args); });
707
- editor.on('blur', (...args) => { var _a, _b; return (_b = (_a = options.current).onBlur) === null || _b === void 0 ? void 0 : _b.call(_a, ...args); });
708
- editor.on('create', (...args) => { var _a, _b; return (_b = (_a = options.current).onCreate) === null || _b === void 0 ? void 0 : _b.call(_a, ...args); });
709
- editor.on('destroy', (...args) => { var _a, _b; return (_b = (_a = options.current).onDestroy) === null || _b === void 0 ? void 0 : _b.call(_a, ...args); });
710
- editor.on('focus', (...args) => { var _a, _b; return (_b = (_a = options.current).onFocus) === null || _b === void 0 ? void 0 : _b.call(_a, ...args); });
711
- editor.on('selectionUpdate', (...args) => { var _a, _b; return (_b = (_a = options.current).onSelectionUpdate) === null || _b === void 0 ? void 0 : _b.call(_a, ...args); });
712
- editor.on('transaction', (...args) => { var _a, _b; return (_b = (_a = options.current).onTransaction) === null || _b === void 0 ? void 0 : _b.call(_a, ...args); });
713
- editor.on('update', (...args) => { var _a, _b; return (_b = (_a = options.current).onUpdate) === null || _b === void 0 ? void 0 : _b.call(_a, ...args); });
714
- editor.on('contentError', (...args) => { var _a, _b; return (_b = (_a = options.current).onContentError) === null || _b === void 0 ? void 0 : _b.call(_a, ...args); });
715
- return editor;
716
- }
717
- function useEditor(options = {}, deps = []) {
718
- const mostRecentOptions = useRef(options);
719
- const [editor, setEditor] = useState(() => {
720
- if (options.immediatelyRender === undefined) {
721
- if (isSSR || isNext) {
722
- // TODO in the next major release, we should throw an error here
723
- if (isDev) {
724
- /**
725
- * Throw an error in development, to make sure the developer is aware that tiptap cannot be SSR'd
726
- * and that they need to set `immediatelyRender` to `false` to avoid hydration mismatches.
727
- */
728
- console.warn('Tiptap Error: SSR has been detected, please set `immediatelyRender` explicitly to `false` to avoid hydration mismatches.');
729
- }
730
- // Best faith effort in production, run the code in the legacy mode to avoid hydration mismatches and errors in production
731
- return null;
732
- }
733
- // Default to immediately rendering when client-side rendering
734
- return createEditor(mostRecentOptions);
735
- }
736
- if (options.immediatelyRender && isSSR && isDev) {
737
- // Warn in development, to make sure the developer is aware that tiptap cannot be SSR'd, set `immediatelyRender` to `false` to avoid hydration mismatches.
738
- 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.');
739
- }
740
- if (options.immediatelyRender) {
741
- return createEditor(mostRecentOptions);
264
+ // src/useEditor.ts
265
+ var isDev = process.env.NODE_ENV !== "production";
266
+ var isSSR = typeof window === "undefined";
267
+ var isNext = isSSR || Boolean(typeof window !== "undefined" && window.next);
268
+ var EditorInstanceManager = class {
269
+ constructor(options) {
270
+ /**
271
+ * The current editor instance.
272
+ */
273
+ this.editor = null;
274
+ /**
275
+ * The subscriptions to notify when the editor instance
276
+ * has been created or destroyed.
277
+ */
278
+ this.subscriptions = /* @__PURE__ */ new Set();
279
+ /**
280
+ * Whether the editor has been mounted.
281
+ */
282
+ this.isComponentMounted = false;
283
+ /**
284
+ * The most recent dependencies array.
285
+ */
286
+ this.previousDeps = null;
287
+ /**
288
+ * The unique instance ID. This is used to identify the editor instance. And will be re-generated for each new instance.
289
+ */
290
+ this.instanceId = "";
291
+ this.options = options;
292
+ this.subscriptions = /* @__PURE__ */ new Set();
293
+ this.setEditor(this.getInitialEditor());
294
+ this.scheduleDestroy();
295
+ this.getEditor = this.getEditor.bind(this);
296
+ this.getServerSnapshot = this.getServerSnapshot.bind(this);
297
+ this.subscribe = this.subscribe.bind(this);
298
+ this.refreshEditorInstance = this.refreshEditorInstance.bind(this);
299
+ this.scheduleDestroy = this.scheduleDestroy.bind(this);
300
+ this.onRender = this.onRender.bind(this);
301
+ this.createEditor = this.createEditor.bind(this);
302
+ }
303
+ setEditor(editor) {
304
+ this.editor = editor;
305
+ this.instanceId = Math.random().toString(36).slice(2, 9);
306
+ this.subscriptions.forEach((cb) => cb());
307
+ }
308
+ getInitialEditor() {
309
+ if (this.options.current.immediatelyRender === void 0) {
310
+ if (isSSR || isNext) {
311
+ if (isDev) {
312
+ throw new Error(
313
+ "Tiptap Error: SSR has been detected, please set `immediatelyRender` explicitly to `false` to avoid hydration mismatches."
314
+ );
742
315
  }
743
316
  return null;
744
- });
745
- const mostRecentEditor = useRef(editor);
746
- mostRecentEditor.current = editor;
747
- useDebugValue(editor);
748
- // This effect will handle creating/updating the editor instance
749
- useEffect(() => {
750
- const destroyUnusedEditor = (editorInstance) => {
751
- if (editorInstance) {
752
- // We need to destroy the editor asynchronously to avoid memory leaks
753
- // because the editor instance is still being used in the component.
754
- setTimeout(() => {
755
- // re-use the editor instance if it hasn't been replaced yet
756
- // otherwise, asynchronously destroy the old editor instance
757
- if (editorInstance !== mostRecentEditor.current && !editorInstance.isDestroyed) {
758
- editorInstance.destroy();
759
- }
760
- });
761
- }
762
- };
763
- let editorInstance = mostRecentEditor.current;
764
- if (!editorInstance) {
765
- editorInstance = createEditor(mostRecentOptions);
766
- setEditor(editorInstance);
767
- return () => destroyUnusedEditor(editorInstance);
768
- }
769
- if (!Array.isArray(deps) || deps.length === 0) {
770
- // if the editor does exist & deps are empty, we don't need to re-initialize the editor
771
- // we can fast-path to update the editor options on the existing instance
772
- editorInstance.setOptions(options);
773
- return () => destroyUnusedEditor(editorInstance);
774
- }
775
- // We need to destroy the editor instance and re-initialize it
776
- // when the deps array changes
777
- editorInstance.destroy();
778
- // the deps array is used to re-initialize the editor instance
779
- editorInstance = createEditor(mostRecentOptions);
780
- setEditor(editorInstance);
781
- return () => destroyUnusedEditor(editorInstance);
782
- }, deps);
783
- // The default behavior is to re-render on each transaction
784
- // This is legacy behavior that will be removed in future versions
785
- useEditorState({
786
- editor,
787
- selector: ({ transactionNumber }) => {
788
- if (options.shouldRerenderOnTransaction === false) {
789
- // This will prevent the editor from re-rendering on each transaction
790
- return null;
791
- }
792
- // This will avoid re-rendering on the first transaction when `immediatelyRender` is set to `true`
793
- if (options.immediatelyRender && transactionNumber === 0) {
794
- return 0;
795
- }
796
- return transactionNumber + 1;
797
- },
798
- });
317
+ }
318
+ return this.createEditor();
319
+ }
320
+ if (this.options.current.immediatelyRender && isSSR && isDev) {
321
+ throw new Error(
322
+ "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."
323
+ );
324
+ }
325
+ if (this.options.current.immediatelyRender) {
326
+ return this.createEditor();
327
+ }
328
+ return null;
329
+ }
330
+ /**
331
+ * Create a new editor instance. And attach event listeners.
332
+ */
333
+ createEditor() {
334
+ const optionsToApply = {
335
+ ...this.options.current,
336
+ // Always call the most recent version of the callback function by default
337
+ onBeforeCreate: (...args) => {
338
+ var _a, _b;
339
+ return (_b = (_a = this.options.current).onBeforeCreate) == null ? void 0 : _b.call(_a, ...args);
340
+ },
341
+ onBlur: (...args) => {
342
+ var _a, _b;
343
+ return (_b = (_a = this.options.current).onBlur) == null ? void 0 : _b.call(_a, ...args);
344
+ },
345
+ onCreate: (...args) => {
346
+ var _a, _b;
347
+ return (_b = (_a = this.options.current).onCreate) == null ? void 0 : _b.call(_a, ...args);
348
+ },
349
+ onDestroy: (...args) => {
350
+ var _a, _b;
351
+ return (_b = (_a = this.options.current).onDestroy) == null ? void 0 : _b.call(_a, ...args);
352
+ },
353
+ onFocus: (...args) => {
354
+ var _a, _b;
355
+ return (_b = (_a = this.options.current).onFocus) == null ? void 0 : _b.call(_a, ...args);
356
+ },
357
+ onSelectionUpdate: (...args) => {
358
+ var _a, _b;
359
+ return (_b = (_a = this.options.current).onSelectionUpdate) == null ? void 0 : _b.call(_a, ...args);
360
+ },
361
+ onTransaction: (...args) => {
362
+ var _a, _b;
363
+ return (_b = (_a = this.options.current).onTransaction) == null ? void 0 : _b.call(_a, ...args);
364
+ },
365
+ onUpdate: (...args) => {
366
+ var _a, _b;
367
+ return (_b = (_a = this.options.current).onUpdate) == null ? void 0 : _b.call(_a, ...args);
368
+ },
369
+ onContentError: (...args) => {
370
+ var _a, _b;
371
+ return (_b = (_a = this.options.current).onContentError) == null ? void 0 : _b.call(_a, ...args);
372
+ },
373
+ onDrop: (...args) => {
374
+ var _a, _b;
375
+ return (_b = (_a = this.options.current).onDrop) == null ? void 0 : _b.call(_a, ...args);
376
+ },
377
+ onPaste: (...args) => {
378
+ var _a, _b;
379
+ return (_b = (_a = this.options.current).onPaste) == null ? void 0 : _b.call(_a, ...args);
380
+ }
381
+ };
382
+ const editor = new Editor(optionsToApply);
799
383
  return editor;
384
+ }
385
+ /**
386
+ * Get the current editor instance.
387
+ */
388
+ getEditor() {
389
+ return this.editor;
390
+ }
391
+ /**
392
+ * Always disable the editor on the server-side.
393
+ */
394
+ getServerSnapshot() {
395
+ return null;
396
+ }
397
+ /**
398
+ * Subscribe to the editor instance's changes.
399
+ */
400
+ subscribe(onStoreChange) {
401
+ this.subscriptions.add(onStoreChange);
402
+ return () => {
403
+ this.subscriptions.delete(onStoreChange);
404
+ };
405
+ }
406
+ /**
407
+ * On each render, we will create, update, or destroy the editor instance.
408
+ * @param deps The dependencies to watch for changes
409
+ * @returns A cleanup function
410
+ */
411
+ onRender(deps) {
412
+ return () => {
413
+ this.isComponentMounted = true;
414
+ clearTimeout(this.scheduledDestructionTimeout);
415
+ if (this.editor && !this.editor.isDestroyed && deps.length === 0) {
416
+ this.editor.setOptions({
417
+ ...this.options.current,
418
+ editable: this.editor.isEditable
419
+ });
420
+ } else {
421
+ this.refreshEditorInstance(deps);
422
+ }
423
+ return () => {
424
+ this.isComponentMounted = false;
425
+ this.scheduleDestroy();
426
+ };
427
+ };
428
+ }
429
+ /**
430
+ * Recreate the editor instance if the dependencies have changed.
431
+ */
432
+ refreshEditorInstance(deps) {
433
+ if (this.editor && !this.editor.isDestroyed) {
434
+ if (this.previousDeps === null) {
435
+ this.previousDeps = deps;
436
+ return;
437
+ }
438
+ const depsAreEqual = this.previousDeps.length === deps.length && this.previousDeps.every((dep, index) => dep === deps[index]);
439
+ if (depsAreEqual) {
440
+ return;
441
+ }
442
+ }
443
+ if (this.editor && !this.editor.isDestroyed) {
444
+ this.editor.destroy();
445
+ }
446
+ this.setEditor(this.createEditor());
447
+ this.previousDeps = deps;
448
+ }
449
+ /**
450
+ * Schedule the destruction of the editor instance.
451
+ * This will only destroy the editor if it was not mounted on the next tick.
452
+ * This is to avoid destroying the editor instance when it's actually still mounted.
453
+ */
454
+ scheduleDestroy() {
455
+ const currentInstanceId = this.instanceId;
456
+ const currentEditor = this.editor;
457
+ this.scheduledDestructionTimeout = setTimeout(() => {
458
+ if (this.isComponentMounted && this.instanceId === currentInstanceId) {
459
+ if (currentEditor) {
460
+ currentEditor.setOptions(this.options.current);
461
+ }
462
+ return;
463
+ }
464
+ if (currentEditor && !currentEditor.isDestroyed) {
465
+ currentEditor.destroy();
466
+ if (this.instanceId === currentInstanceId) {
467
+ this.setEditor(null);
468
+ }
469
+ }
470
+ }, 1);
471
+ }
472
+ };
473
+ function useEditor(options = {}, deps = []) {
474
+ const mostRecentOptions = useRef(options);
475
+ mostRecentOptions.current = options;
476
+ const [instanceManager] = useState2(() => new EditorInstanceManager(mostRecentOptions));
477
+ const editor = useSyncExternalStore2(
478
+ instanceManager.subscribe,
479
+ instanceManager.getEditor,
480
+ instanceManager.getServerSnapshot
481
+ );
482
+ useDebugValue2(editor);
483
+ useEffect2(instanceManager.onRender(deps));
484
+ useEditorState({
485
+ editor,
486
+ selector: ({ transactionNumber }) => {
487
+ if (options.shouldRerenderOnTransaction === false || options.shouldRerenderOnTransaction === void 0) {
488
+ return null;
489
+ }
490
+ if (options.immediatelyRender && transactionNumber === 0) {
491
+ return 0;
492
+ }
493
+ return transactionNumber + 1;
494
+ }
495
+ });
496
+ return editor;
800
497
  }
801
498
 
802
- const EditorContext = createContext({
803
- editor: null,
499
+ // src/Context.tsx
500
+ var EditorContext = createContext({
501
+ editor: null
804
502
  });
805
- const EditorConsumer = EditorContext.Consumer;
806
- /**
807
- * A hook to get the current editor instance.
808
- */
809
- const useCurrentEditor = () => useContext(EditorContext);
810
- /**
811
- * This is the provider component for the editor.
812
- * It allows the editor to be accessible across the entire component tree
813
- * with `useCurrentEditor`.
814
- */
815
- function EditorProvider({ children, slotAfter, slotBefore, ...editorOptions }) {
816
- const editor = useEditor(editorOptions);
817
- if (!editor) {
818
- return null;
819
- }
820
- return (React.createElement(EditorContext.Provider, { value: { editor } },
821
- slotBefore,
822
- React.createElement(EditorConsumer, null, ({ editor: currentEditor }) => (React.createElement(EditorContent, { editor: currentEditor }))),
823
- children,
824
- slotAfter));
503
+ var EditorConsumer = EditorContext.Consumer;
504
+ var useCurrentEditor = () => useContext(EditorContext);
505
+ function EditorProvider({
506
+ children,
507
+ slotAfter,
508
+ slotBefore,
509
+ editorContainerProps = {},
510
+ ...editorOptions
511
+ }) {
512
+ const editor = useEditor(editorOptions);
513
+ const contextValue = useMemo(() => ({ editor }), [editor]);
514
+ if (!editor) {
515
+ return null;
516
+ }
517
+ return /* @__PURE__ */ React2.createElement(EditorContext.Provider, { value: contextValue }, slotBefore, /* @__PURE__ */ React2.createElement(EditorConsumer, null, ({ editor: currentEditor }) => /* @__PURE__ */ React2.createElement(EditorContent, { editor: currentEditor, ...editorContainerProps })), children, slotAfter);
825
518
  }
826
519
 
827
- const BubbleMenu = (props) => {
828
- const menuEl = useRef(document.createElement('div'));
520
+ // src/BubbleMenu.tsx
521
+ var BubbleMenu = React3.forwardRef(
522
+ ({
523
+ pluginKey = "bubbleMenu",
524
+ editor,
525
+ updateDelay,
526
+ resizeDelay,
527
+ shouldShow = null,
528
+ options,
529
+ children,
530
+ ...restProps
531
+ }, ref) => {
532
+ const menuEl = useRef2(document.createElement("div"));
533
+ if (typeof ref === "function") {
534
+ ref(menuEl.current);
535
+ } else if (ref) {
536
+ ref.current = menuEl.current;
537
+ }
829
538
  const { editor: currentEditor } = useCurrentEditor();
830
- useEffect(() => {
831
- var _a;
832
- menuEl.current.style.visibility = 'hidden';
833
- menuEl.current.style.position = 'absolute';
834
- if (((_a = props.editor) === null || _a === void 0 ? void 0 : _a.isDestroyed) || (currentEditor === null || currentEditor === void 0 ? void 0 : currentEditor.isDestroyed)) {
835
- return;
836
- }
837
- const { pluginKey = 'bubbleMenu', editor, updateDelay, resizeDelay, shouldShow = null, } = props;
838
- const menuEditor = editor || currentEditor;
839
- if (!menuEditor) {
840
- console.warn('BubbleMenu component is not rendered inside of an editor component or does not have editor prop.');
841
- return;
842
- }
843
- const plugin = BubbleMenuPlugin({
844
- updateDelay,
845
- resizeDelay,
846
- editor: menuEditor,
847
- element: menuEl.current,
848
- pluginKey,
849
- shouldShow,
850
- options: props.options,
539
+ useEffect3(() => {
540
+ const bubbleMenuElement = menuEl.current;
541
+ bubbleMenuElement.style.visibility = "hidden";
542
+ bubbleMenuElement.style.position = "absolute";
543
+ if ((editor == null ? void 0 : editor.isDestroyed) || (currentEditor == null ? void 0 : currentEditor.isDestroyed)) {
544
+ return;
545
+ }
546
+ const attachToEditor = editor || currentEditor;
547
+ if (!attachToEditor) {
548
+ console.warn(
549
+ "BubbleMenu component is not rendered inside of an editor component or does not have editor prop."
550
+ );
551
+ return;
552
+ }
553
+ const plugin = BubbleMenuPlugin({
554
+ updateDelay,
555
+ resizeDelay,
556
+ editor: attachToEditor,
557
+ element: bubbleMenuElement,
558
+ pluginKey,
559
+ shouldShow,
560
+ options
561
+ });
562
+ attachToEditor.registerPlugin(plugin);
563
+ return () => {
564
+ attachToEditor.unregisterPlugin(pluginKey);
565
+ window.requestAnimationFrame(() => {
566
+ if (bubbleMenuElement.parentNode) {
567
+ bubbleMenuElement.parentNode.removeChild(bubbleMenuElement);
568
+ }
851
569
  });
852
- menuEditor.registerPlugin(plugin);
853
- return () => {
854
- menuEditor.unregisterPlugin(pluginKey);
855
- window.requestAnimationFrame(() => {
856
- if (menuEl.current.parentNode) {
857
- menuEl.current.parentNode.removeChild(menuEl.current);
858
- }
859
- });
860
- };
861
- }, [props.editor, currentEditor]);
862
- const portal = createPortal((React.createElement("div", { className: props.className }, props.children)), menuEl.current);
863
- return (React.createElement(React.Fragment, null, portal));
864
- };
570
+ };
571
+ }, [editor, currentEditor]);
572
+ return createPortal(
573
+ /* @__PURE__ */ React3.createElement(
574
+ "div",
575
+ {
576
+ ...restProps
577
+ },
578
+ children
579
+ ),
580
+ menuEl.current
581
+ );
582
+ }
583
+ );
584
+
585
+ // src/FloatingMenu.tsx
586
+ import { FloatingMenuPlugin } from "@tiptap/extension-floating-menu";
587
+ import React4, { useEffect as useEffect4, useRef as useRef3 } from "react";
588
+ import { createPortal as createPortal2 } from "react-dom";
589
+ var FloatingMenu = React4.forwardRef(({
590
+ pluginKey = "floatingMenu",
591
+ editor,
592
+ shouldShow = null,
593
+ options,
594
+ children,
595
+ ...restProps
596
+ }, ref) => {
597
+ const menuEl = useRef3(document.createElement("div"));
598
+ if (typeof ref === "function") {
599
+ ref(menuEl.current);
600
+ } else if (ref) {
601
+ ref.current = menuEl.current;
602
+ }
603
+ const { editor: currentEditor } = useCurrentEditor();
604
+ useEffect4(() => {
605
+ const floatingMenuElement = menuEl.current;
606
+ floatingMenuElement.style.visibility = "hidden";
607
+ floatingMenuElement.style.position = "absolute";
608
+ if ((editor == null ? void 0 : editor.isDestroyed) || (currentEditor == null ? void 0 : currentEditor.isDestroyed)) {
609
+ return;
610
+ }
611
+ const attachToEditor = editor || currentEditor;
612
+ if (!attachToEditor) {
613
+ console.warn(
614
+ "FloatingMenu component is not rendered inside of an editor component or does not have editor prop."
615
+ );
616
+ return;
617
+ }
618
+ const plugin = FloatingMenuPlugin({
619
+ editor: attachToEditor,
620
+ element: floatingMenuElement,
621
+ pluginKey,
622
+ shouldShow,
623
+ options
624
+ });
625
+ attachToEditor.registerPlugin(plugin);
626
+ return () => {
627
+ attachToEditor.unregisterPlugin(pluginKey);
628
+ window.requestAnimationFrame(() => {
629
+ if (floatingMenuElement.parentNode) {
630
+ floatingMenuElement.parentNode.removeChild(floatingMenuElement);
631
+ }
632
+ });
633
+ };
634
+ }, [editor, currentEditor]);
635
+ return createPortal2(
636
+ /* @__PURE__ */ React4.createElement(
637
+ "div",
638
+ {
639
+ ...restProps
640
+ },
641
+ children
642
+ ),
643
+ menuEl.current
644
+ );
645
+ });
865
646
 
866
- const FloatingMenu = (props) => {
867
- const menuEl = useRef(document.createElement('div'));
868
- const { editor: currentEditor } = useCurrentEditor();
869
- useEffect(() => {
870
- var _a;
871
- menuEl.current.style.visibility = 'hidden';
872
- menuEl.current.style.position = 'absolute';
873
- if (((_a = props.editor) === null || _a === void 0 ? void 0 : _a.isDestroyed) || (currentEditor === null || currentEditor === void 0 ? void 0 : currentEditor.isDestroyed)) {
874
- return;
875
- }
876
- const { pluginKey = 'floatingMenu', editor, options, shouldShow = null, } = props;
877
- const menuEditor = editor || currentEditor;
878
- if (!menuEditor) {
879
- console.warn('FloatingMenu component is not rendered inside of an editor component or does not have editor prop.');
880
- return;
881
- }
882
- const plugin = FloatingMenuPlugin({
883
- pluginKey,
884
- editor: menuEditor,
885
- element: menuEl.current,
886
- options,
887
- shouldShow,
888
- });
889
- menuEditor.registerPlugin(plugin);
890
- return () => {
891
- menuEditor.unregisterPlugin(pluginKey);
892
- window.requestAnimationFrame(() => {
893
- if (menuEl.current.parentNode) {
894
- menuEl.current.parentNode.removeChild(menuEl.current);
895
- }
896
- });
897
- };
898
- }, [
899
- props.editor,
900
- currentEditor,
901
- ]);
902
- const portal = createPortal((React.createElement("div", { className: props.className }, props.children)), menuEl.current);
903
- return (React.createElement(React.Fragment, null, portal));
904
- };
647
+ // src/NodeViewContent.tsx
648
+ import React5 from "react";
905
649
 
906
- const ReactNodeViewContext = createContext({
907
- onDragStart: undefined,
650
+ // src/useReactNodeView.ts
651
+ import { createContext as createContext2, useContext as useContext2 } from "react";
652
+ var ReactNodeViewContext = createContext2({
653
+ onDragStart: void 0
908
654
  });
909
- const useReactNodeView = () => useContext(ReactNodeViewContext);
910
-
911
- const NodeViewContent = props => {
912
- const Tag = props.as || 'div';
913
- const { nodeViewContentRef } = useReactNodeView();
914
- return (React.createElement(Tag, { ...props, ref: nodeViewContentRef, "data-node-view-content": "", style: {
915
- whiteSpace: 'pre-wrap',
916
- ...props.style,
917
- } }));
655
+ var useReactNodeView = () => useContext2(ReactNodeViewContext);
656
+
657
+ // src/NodeViewContent.tsx
658
+ var NodeViewContent = (props) => {
659
+ const Tag = props.as || "div";
660
+ const { nodeViewContentRef } = useReactNodeView();
661
+ return (
662
+ // @ts-ignore
663
+ /* @__PURE__ */ React5.createElement(
664
+ Tag,
665
+ {
666
+ ...props,
667
+ ref: nodeViewContentRef,
668
+ "data-node-view-content": "",
669
+ style: {
670
+ whiteSpace: "pre-wrap",
671
+ ...props.style
672
+ }
673
+ }
674
+ )
675
+ );
918
676
  };
919
677
 
920
- const NodeViewWrapper = React.forwardRef((props, ref) => {
921
- const { onDragStart } = useReactNodeView();
922
- const Tag = props.as || 'div';
923
- return (React.createElement(Tag, { ...props, ref: ref, "data-node-view-wrapper": "", onDragStart: onDragStart, style: {
924
- whiteSpace: 'normal',
925
- ...props.style,
926
- } }));
678
+ // src/NodeViewWrapper.tsx
679
+ import React6 from "react";
680
+ var NodeViewWrapper = React6.forwardRef((props, ref) => {
681
+ const { onDragStart } = useReactNodeView();
682
+ const Tag = props.as || "div";
683
+ return (
684
+ // @ts-ignore
685
+ /* @__PURE__ */ React6.createElement(
686
+ Tag,
687
+ {
688
+ ...props,
689
+ ref,
690
+ "data-node-view-wrapper": "",
691
+ onDragStart,
692
+ style: {
693
+ whiteSpace: "normal",
694
+ ...props.style
695
+ }
696
+ }
697
+ )
698
+ );
927
699
  });
928
700
 
929
- /**
930
- * Check if a component is a class component.
931
- * @param Component
932
- * @returns {boolean}
933
- */
701
+ // src/ReactNodeViewRenderer.tsx
702
+ import {
703
+ getRenderedAttributes,
704
+ NodeView
705
+ } from "@tiptap/core";
706
+ import React8 from "react";
707
+
708
+ // src/ReactRenderer.tsx
709
+ import React7 from "react";
710
+ import { flushSync } from "react-dom";
934
711
  function isClassComponent(Component) {
935
- return !!(typeof Component === 'function'
936
- && Component.prototype
937
- && Component.prototype.isReactComponent);
712
+ return !!(typeof Component === "function" && Component.prototype && Component.prototype.isReactComponent);
938
713
  }
939
- /**
940
- * Check if a component is a forward ref component.
941
- * @param Component
942
- * @returns {boolean}
943
- */
944
714
  function isForwardRefComponent(Component) {
945
- var _a;
946
- return !!(typeof Component === 'object'
947
- && ((_a = Component.$$typeof) === null || _a === void 0 ? void 0 : _a.toString()) === 'Symbol(react.forward_ref)');
715
+ var _a;
716
+ return !!(typeof Component === "object" && ((_a = Component.$$typeof) == null ? void 0 : _a.toString()) === "Symbol(react.forward_ref)");
948
717
  }
949
- /**
950
- * The ReactRenderer class. It's responsible for rendering React components inside the editor.
951
- * @example
952
- * new ReactRenderer(MyComponent, {
953
- * editor,
954
- * props: {
955
- * foo: 'bar',
956
- * },
957
- * as: 'span',
958
- * })
959
- */
960
- class ReactRenderer {
961
- constructor(component, { editor, props = {}, as = 'div', className = '', attrs, }) {
962
- this.ref = null;
963
- this.id = Math.floor(Math.random() * 0xFFFFFFFF).toString();
964
- this.component = component;
965
- this.editor = editor;
966
- this.props = props;
967
- this.element = document.createElement(as);
968
- this.element.classList.add('react-renderer');
969
- if (className) {
970
- this.element.classList.add(...className.split(' '));
971
- }
972
- if (attrs) {
973
- Object.keys(attrs).forEach(key => {
974
- this.element.setAttribute(key, attrs[key]);
975
- });
976
- }
977
- this.render();
718
+ var ReactRenderer = class {
719
+ /**
720
+ * Immediately creates element and renders the provided React component.
721
+ */
722
+ constructor(component, {
723
+ editor,
724
+ props = {},
725
+ as = "div",
726
+ className = ""
727
+ }) {
728
+ this.ref = null;
729
+ this.id = Math.floor(Math.random() * 4294967295).toString();
730
+ this.component = component;
731
+ this.editor = editor;
732
+ this.props = props;
733
+ this.element = document.createElement(as);
734
+ this.element.classList.add("react-renderer");
735
+ if (className) {
736
+ this.element.classList.add(...className.split(" "));
978
737
  }
979
- render() {
980
- var _a, _b;
981
- const Component = this.component;
982
- const props = this.props;
983
- if (isClassComponent(Component) || isForwardRefComponent(Component)) {
984
- props.ref = (ref) => {
985
- this.ref = ref;
986
- };
987
- }
988
- this.reactElement = React.createElement(Component, { ...props });
989
- (_b = (_a = this.editor) === null || _a === void 0 ? void 0 : _a.contentComponent) === null || _b === void 0 ? void 0 : _b.setRenderer(this.id, this);
990
- }
991
- updateProps(props = {}) {
992
- this.props = {
993
- ...this.props,
994
- ...props,
995
- };
738
+ if (this.editor.isInitialized) {
739
+ flushSync(() => {
996
740
  this.render();
741
+ });
742
+ } else {
743
+ this.render();
997
744
  }
998
- destroy() {
999
- var _a, _b;
1000
- (_b = (_a = this.editor) === null || _a === void 0 ? void 0 : _a.contentComponent) === null || _b === void 0 ? void 0 : _b.removeRenderer(this.id);
745
+ }
746
+ /**
747
+ * Render the React component.
748
+ */
749
+ render() {
750
+ var _a;
751
+ const Component = this.component;
752
+ const props = this.props;
753
+ const editor = this.editor;
754
+ if (isClassComponent(Component) || isForwardRefComponent(Component)) {
755
+ props.ref = (ref) => {
756
+ this.ref = ref;
757
+ };
1001
758
  }
1002
- }
759
+ this.reactElement = /* @__PURE__ */ React7.createElement(Component, { ...props });
760
+ (_a = editor == null ? void 0 : editor.contentComponent) == null ? void 0 : _a.setRenderer(this.id, this);
761
+ }
762
+ /**
763
+ * Re-renders the React component with new props.
764
+ */
765
+ updateProps(props = {}) {
766
+ this.props = {
767
+ ...this.props,
768
+ ...props
769
+ };
770
+ this.render();
771
+ }
772
+ /**
773
+ * Destroy the React component.
774
+ */
775
+ destroy() {
776
+ var _a;
777
+ const editor = this.editor;
778
+ (_a = editor == null ? void 0 : editor.contentComponent) == null ? void 0 : _a.removeRenderer(this.id);
779
+ }
780
+ /**
781
+ * Update the attributes of the element that holds the React component.
782
+ */
783
+ updateAttributes(attributes) {
784
+ Object.keys(attributes).forEach((key) => {
785
+ this.element.setAttribute(key, attributes[key]);
786
+ });
787
+ }
788
+ };
1003
789
 
1004
- class ReactNodeView extends NodeView {
1005
- mount() {
1006
- const props = {
1007
- editor: this.editor,
1008
- node: this.node,
1009
- decorations: this.decorations,
1010
- selected: false,
1011
- extension: this.extension,
1012
- getPos: () => this.getPos(),
1013
- updateAttributes: (attributes = {}) => this.updateAttributes(attributes),
1014
- deleteNode: () => this.deleteNode(),
1015
- };
1016
- if (!this.component.displayName) {
1017
- const capitalizeFirstChar = (string) => {
1018
- return string.charAt(0).toUpperCase() + string.substring(1);
1019
- };
1020
- this.component.displayName = capitalizeFirstChar(this.extension.name);
1021
- }
1022
- const ReactNodeViewProvider = componentProps => {
1023
- const Component = this.component;
1024
- const onDragStart = this.onDragStart.bind(this);
1025
- const nodeViewContentRef = element => {
1026
- if (element && this.contentDOMElement && element.firstChild !== this.contentDOMElement) {
1027
- element.appendChild(this.contentDOMElement);
1028
- }
1029
- };
1030
- return (React.createElement(React.Fragment, null,
1031
- React.createElement(ReactNodeViewContext.Provider, { value: { onDragStart, nodeViewContentRef } },
1032
- React.createElement(Component, { ...componentProps }))));
1033
- };
1034
- ReactNodeViewProvider.displayName = 'ReactNodeView';
1035
- if (this.node.isLeaf) {
1036
- this.contentDOMElement = null;
1037
- }
1038
- else if (this.options.contentDOMElementTag) {
1039
- this.contentDOMElement = document.createElement(this.options.contentDOMElementTag);
1040
- }
1041
- else {
1042
- this.contentDOMElement = document.createElement(this.node.isInline ? 'span' : 'div');
1043
- }
1044
- if (this.contentDOMElement) {
1045
- // For some reason the whiteSpace prop is not inherited properly in Chrome and Safari
1046
- // With this fix it seems to work fine
1047
- // See: https://github.com/ueberdosis/tiptap/issues/1197
1048
- this.contentDOMElement.style.whiteSpace = 'inherit';
1049
- }
1050
- let as = this.node.isInline ? 'span' : 'div';
1051
- if (this.options.as) {
1052
- as = this.options.as;
1053
- }
1054
- const { className = '' } = this.options;
1055
- this.handleSelectionUpdate = this.handleSelectionUpdate.bind(this);
1056
- this.editor.on('selectionUpdate', this.handleSelectionUpdate);
1057
- this.renderer = new ReactRenderer(ReactNodeViewProvider, {
1058
- editor: this.editor,
1059
- props,
1060
- as,
1061
- className: `node-${this.node.type.name} ${className}`.trim(),
1062
- attrs: this.options.attrs,
1063
- });
790
+ // src/ReactNodeViewRenderer.tsx
791
+ var ReactNodeView = class extends NodeView {
792
+ /**
793
+ * Setup the React component.
794
+ * Called on initialization.
795
+ */
796
+ mount() {
797
+ const props = {
798
+ editor: this.editor,
799
+ node: this.node,
800
+ decorations: this.decorations,
801
+ innerDecorations: this.innerDecorations,
802
+ view: this.view,
803
+ selected: false,
804
+ extension: this.extension,
805
+ HTMLAttributes: this.HTMLAttributes,
806
+ getPos: () => this.getPos(),
807
+ updateAttributes: (attributes = {}) => this.updateAttributes(attributes),
808
+ deleteNode: () => this.deleteNode()
809
+ };
810
+ if (!this.component.displayName) {
811
+ const capitalizeFirstChar = (string) => {
812
+ return string.charAt(0).toUpperCase() + string.substring(1);
813
+ };
814
+ this.component.displayName = capitalizeFirstChar(this.extension.name);
1064
815
  }
1065
- get dom() {
1066
- var _a;
1067
- if (this.renderer.element.firstElementChild
1068
- && !((_a = this.renderer.element.firstElementChild) === null || _a === void 0 ? void 0 : _a.hasAttribute('data-node-view-wrapper'))) {
1069
- throw Error('Please use the NodeViewWrapper component for your node view.');
1070
- }
1071
- return this.renderer.element;
816
+ const onDragStart = this.onDragStart.bind(this);
817
+ const nodeViewContentRef = (element) => {
818
+ if (element && this.contentDOMElement && element.firstChild !== this.contentDOMElement) {
819
+ element.appendChild(this.contentDOMElement);
820
+ }
821
+ };
822
+ const context = { onDragStart, nodeViewContentRef };
823
+ const Component = this.component;
824
+ const ReactNodeViewProvider = React8.memo(
825
+ (componentProps) => {
826
+ return /* @__PURE__ */ React8.createElement(ReactNodeViewContext.Provider, { value: context }, React8.createElement(Component, componentProps));
827
+ }
828
+ );
829
+ ReactNodeViewProvider.displayName = "ReactNodeView";
830
+ if (this.node.isLeaf) {
831
+ this.contentDOMElement = null;
832
+ } else if (this.options.contentDOMElementTag) {
833
+ this.contentDOMElement = document.createElement(this.options.contentDOMElementTag);
834
+ } else {
835
+ this.contentDOMElement = document.createElement(this.node.isInline ? "span" : "div");
1072
836
  }
1073
- get contentDOM() {
1074
- if (this.node.isLeaf) {
1075
- return null;
1076
- }
1077
- return this.contentDOMElement;
837
+ if (this.contentDOMElement) {
838
+ this.contentDOMElement.dataset.nodeViewContentReact = "";
839
+ this.contentDOMElement.style.whiteSpace = "inherit";
1078
840
  }
1079
- handleSelectionUpdate() {
1080
- const { from, to } = this.editor.state.selection;
1081
- if (from <= this.getPos() && to >= this.getPos() + this.node.nodeSize) {
1082
- if (this.renderer.props.selected) {
1083
- return;
1084
- }
1085
- this.selectNode();
1086
- }
1087
- else {
1088
- if (!this.renderer.props.selected) {
1089
- return;
1090
- }
1091
- this.deselectNode();
1092
- }
841
+ let as = this.node.isInline ? "span" : "div";
842
+ if (this.options.as) {
843
+ as = this.options.as;
1093
844
  }
1094
- update(node, decorations) {
1095
- const updateProps = (props) => {
1096
- this.renderer.updateProps(props);
1097
- };
1098
- if (node.type !== this.node.type) {
1099
- return false;
1100
- }
1101
- if (typeof this.options.update === 'function') {
1102
- const oldNode = this.node;
1103
- const oldDecorations = this.decorations;
1104
- this.node = node;
1105
- this.decorations = decorations;
1106
- return this.options.update({
1107
- oldNode,
1108
- oldDecorations,
1109
- newNode: node,
1110
- newDecorations: decorations,
1111
- updateProps: () => updateProps({ node, decorations }),
1112
- });
1113
- }
1114
- if (node === this.node && this.decorations === decorations) {
1115
- return true;
1116
- }
1117
- this.node = node;
1118
- this.decorations = decorations;
1119
- updateProps({ node, decorations });
1120
- return true;
845
+ const { className = "" } = this.options;
846
+ this.handleSelectionUpdate = this.handleSelectionUpdate.bind(this);
847
+ this.editor.on("selectionUpdate", this.handleSelectionUpdate);
848
+ this.renderer = new ReactRenderer(ReactNodeViewProvider, {
849
+ editor: this.editor,
850
+ props,
851
+ as,
852
+ className: `node-${this.node.type.name} ${className}`.trim()
853
+ });
854
+ this.updateElementAttributes();
855
+ }
856
+ /**
857
+ * Return the DOM element.
858
+ * This is the element that will be used to display the node view.
859
+ */
860
+ get dom() {
861
+ var _a;
862
+ if (this.renderer.element.firstElementChild && !((_a = this.renderer.element.firstElementChild) == null ? void 0 : _a.hasAttribute("data-node-view-wrapper"))) {
863
+ throw Error("Please use the NodeViewWrapper component for your node view.");
1121
864
  }
1122
- selectNode() {
1123
- this.renderer.updateProps({
1124
- selected: true,
1125
- });
1126
- this.renderer.element.classList.add('ProseMirror-selectednode');
865
+ return this.renderer.element;
866
+ }
867
+ /**
868
+ * Return the content DOM element.
869
+ * This is the element that will be used to display the rich-text content of the node.
870
+ */
871
+ get contentDOM() {
872
+ if (this.node.isLeaf) {
873
+ return null;
1127
874
  }
1128
- deselectNode() {
1129
- this.renderer.updateProps({
1130
- selected: false,
1131
- });
1132
- this.renderer.element.classList.remove('ProseMirror-selectednode');
875
+ return this.contentDOMElement;
876
+ }
877
+ /**
878
+ * On editor selection update, check if the node is selected.
879
+ * If it is, call `selectNode`, otherwise call `deselectNode`.
880
+ */
881
+ handleSelectionUpdate() {
882
+ const { from, to } = this.editor.state.selection;
883
+ const pos = this.getPos();
884
+ if (typeof pos !== "number") {
885
+ return;
1133
886
  }
1134
- destroy() {
1135
- this.renderer.destroy();
1136
- this.editor.off('selectionUpdate', this.handleSelectionUpdate);
1137
- this.contentDOMElement = null;
887
+ if (from <= pos && to >= pos + this.node.nodeSize) {
888
+ if (this.renderer.props.selected) {
889
+ return;
890
+ }
891
+ this.selectNode();
892
+ } else {
893
+ if (!this.renderer.props.selected) {
894
+ return;
895
+ }
896
+ this.deselectNode();
1138
897
  }
1139
- }
1140
- function ReactNodeViewRenderer(component, options) {
1141
- return (props) => {
1142
- // try to get the parent component
1143
- // this is important for vue devtools to show the component hierarchy correctly
1144
- // maybe it’s `undefined` because <editor-content> isn’t rendered yet
1145
- if (!props.editor.contentComponent) {
1146
- return {};
1147
- }
1148
- return new ReactNodeView(component, props, options);
898
+ }
899
+ /**
900
+ * On update, update the React component.
901
+ * To prevent unnecessary updates, the `update` option can be used.
902
+ */
903
+ update(node, decorations, innerDecorations) {
904
+ const rerenderComponent = (props) => {
905
+ this.renderer.updateProps(props);
906
+ if (typeof this.options.attrs === "function") {
907
+ this.updateElementAttributes();
908
+ }
1149
909
  };
910
+ if (node.type !== this.node.type) {
911
+ return false;
912
+ }
913
+ if (typeof this.options.update === "function") {
914
+ const oldNode = this.node;
915
+ const oldDecorations = this.decorations;
916
+ const oldInnerDecorations = this.innerDecorations;
917
+ this.node = node;
918
+ this.decorations = decorations;
919
+ this.innerDecorations = innerDecorations;
920
+ return this.options.update({
921
+ oldNode,
922
+ oldDecorations,
923
+ newNode: node,
924
+ newDecorations: decorations,
925
+ oldInnerDecorations,
926
+ innerDecorations,
927
+ updateProps: () => rerenderComponent({ node, decorations, innerDecorations })
928
+ });
929
+ }
930
+ if (node === this.node && this.decorations === decorations && this.innerDecorations === innerDecorations) {
931
+ return true;
932
+ }
933
+ this.node = node;
934
+ this.decorations = decorations;
935
+ this.innerDecorations = innerDecorations;
936
+ rerenderComponent({ node, decorations, innerDecorations });
937
+ return true;
938
+ }
939
+ /**
940
+ * Select the node.
941
+ * Add the `selected` prop and the `ProseMirror-selectednode` class.
942
+ */
943
+ selectNode() {
944
+ this.renderer.updateProps({
945
+ selected: true
946
+ });
947
+ this.renderer.element.classList.add("ProseMirror-selectednode");
948
+ }
949
+ /**
950
+ * Deselect the node.
951
+ * Remove the `selected` prop and the `ProseMirror-selectednode` class.
952
+ */
953
+ deselectNode() {
954
+ this.renderer.updateProps({
955
+ selected: false
956
+ });
957
+ this.renderer.element.classList.remove("ProseMirror-selectednode");
958
+ }
959
+ /**
960
+ * Destroy the React component instance.
961
+ */
962
+ destroy() {
963
+ this.renderer.destroy();
964
+ this.editor.off("selectionUpdate", this.handleSelectionUpdate);
965
+ this.contentDOMElement = null;
966
+ }
967
+ /**
968
+ * Update the attributes of the top-level element that holds the React component.
969
+ * Applying the attributes defined in the `attrs` option.
970
+ */
971
+ updateElementAttributes() {
972
+ if (this.options.attrs) {
973
+ let attrsObj = {};
974
+ if (typeof this.options.attrs === "function") {
975
+ const extensionAttributes = this.editor.extensionManager.attributes;
976
+ const HTMLAttributes2 = getRenderedAttributes(this.node, extensionAttributes);
977
+ attrsObj = this.options.attrs({ node: this.node, HTMLAttributes: HTMLAttributes2 });
978
+ } else {
979
+ attrsObj = this.options.attrs;
980
+ }
981
+ this.renderer.updateAttributes(attrsObj);
982
+ }
983
+ }
984
+ };
985
+ function ReactNodeViewRenderer(component, options) {
986
+ return (props) => {
987
+ if (!props.editor.contentComponent) {
988
+ return {};
989
+ }
990
+ return new ReactNodeView(component, props, options);
991
+ };
1150
992
  }
1151
993
 
1152
- export { BubbleMenu, Editor, EditorConsumer, EditorContent, EditorContext, EditorProvider, FloatingMenu, NodeViewContent, NodeViewWrapper, PureEditorContent, ReactNodeViewContext, ReactNodeViewRenderer, ReactRenderer, useCurrentEditor, useEditor, useEditorState, useReactNodeView };
1153
- //# sourceMappingURL=index.js.map
994
+ // src/index.ts
995
+ export * from "@tiptap/core";
996
+ export {
997
+ BubbleMenu,
998
+ EditorConsumer,
999
+ EditorContent,
1000
+ EditorContext,
1001
+ EditorProvider,
1002
+ FloatingMenu,
1003
+ NodeViewContent,
1004
+ NodeViewWrapper,
1005
+ PureEditorContent,
1006
+ ReactNodeView,
1007
+ ReactNodeViewContext,
1008
+ ReactNodeViewRenderer,
1009
+ ReactRenderer,
1010
+ useCurrentEditor,
1011
+ useEditor,
1012
+ useEditorState,
1013
+ useReactNodeView
1014
+ };
1015
+ //# sourceMappingURL=index.js.map