@tiptap/react 3.0.0 → 3.0.2-beta.0

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