@tiptap/react 2.6.2 → 3.0.0-next.1

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