@tiptap/react 2.5.0-beta.2 → 2.5.0-beta.3

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 (186) hide show
  1. package/dist/index.cjs +529 -536
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.js +527 -527
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.umd.js +529 -536
  6. package/dist/index.umd.js.map +1 -1
  7. package/dist/packages/core/src/CommandManager.d.ts +20 -0
  8. package/dist/packages/core/src/Editor.d.ts +161 -0
  9. package/dist/packages/core/src/EventEmitter.d.ts +11 -0
  10. package/dist/packages/core/src/Extension.d.ts +343 -0
  11. package/dist/packages/core/src/ExtensionManager.d.ts +55 -0
  12. package/dist/packages/core/src/InputRule.d.ts +42 -0
  13. package/dist/packages/core/src/Mark.d.ts +451 -0
  14. package/dist/packages/core/src/Node.d.ts +611 -0
  15. package/dist/packages/core/src/NodePos.d.ts +44 -0
  16. package/dist/packages/core/src/NodeView.d.ts +31 -0
  17. package/dist/packages/core/src/PasteRule.d.ts +50 -0
  18. package/dist/packages/core/src/Tracker.d.ts +11 -0
  19. package/dist/packages/core/src/commands/blur.d.ts +13 -0
  20. package/dist/packages/core/src/commands/clearContent.d.ts +14 -0
  21. package/dist/packages/core/src/commands/clearNodes.d.ts +13 -0
  22. package/dist/packages/core/src/commands/command.d.ts +18 -0
  23. package/dist/packages/core/src/commands/createParagraphNear.d.ts +13 -0
  24. package/dist/packages/core/src/commands/cut.d.ts +20 -0
  25. package/dist/packages/core/src/commands/deleteCurrentNode.d.ts +13 -0
  26. package/dist/packages/core/src/commands/deleteNode.d.ts +15 -0
  27. package/dist/packages/core/src/commands/deleteRange.d.ts +14 -0
  28. package/dist/packages/core/src/commands/deleteSelection.d.ts +13 -0
  29. package/dist/packages/core/src/commands/enter.d.ts +13 -0
  30. package/dist/packages/core/src/commands/exitCode.d.ts +13 -0
  31. package/dist/packages/core/src/commands/extendMarkRange.d.ts +25 -0
  32. package/dist/packages/core/src/commands/first.d.ts +14 -0
  33. package/dist/packages/core/src/commands/focus.d.ts +27 -0
  34. package/dist/packages/core/src/commands/forEach.d.ts +14 -0
  35. package/dist/packages/core/src/commands/index.d.ts +55 -0
  36. package/dist/packages/core/src/commands/insertContent.d.ts +34 -0
  37. package/dist/packages/core/src/commands/insertContentAt.d.ts +47 -0
  38. package/dist/packages/core/src/commands/join.d.ts +41 -0
  39. package/dist/packages/core/src/commands/joinItemBackward.d.ts +13 -0
  40. package/dist/packages/core/src/commands/joinItemForward.d.ts +13 -0
  41. package/dist/packages/core/src/commands/joinTextblockBackward.d.ts +12 -0
  42. package/dist/packages/core/src/commands/joinTextblockForward.d.ts +12 -0
  43. package/dist/packages/core/src/commands/keyboardShortcut.d.ts +14 -0
  44. package/dist/packages/core/src/commands/lift.d.ts +17 -0
  45. package/dist/packages/core/src/commands/liftEmptyBlock.d.ts +13 -0
  46. package/dist/packages/core/src/commands/liftListItem.d.ts +15 -0
  47. package/dist/packages/core/src/commands/newlineInCode.d.ts +13 -0
  48. package/dist/packages/core/src/commands/resetAttributes.d.ts +16 -0
  49. package/dist/packages/core/src/commands/scrollIntoView.d.ts +13 -0
  50. package/dist/packages/core/src/commands/selectAll.d.ts +13 -0
  51. package/dist/packages/core/src/commands/selectNodeBackward.d.ts +13 -0
  52. package/dist/packages/core/src/commands/selectNodeForward.d.ts +13 -0
  53. package/dist/packages/core/src/commands/selectParentNode.d.ts +13 -0
  54. package/dist/packages/core/src/commands/selectTextblockEnd.d.ts +13 -0
  55. package/dist/packages/core/src/commands/selectTextblockStart.d.ts +13 -0
  56. package/dist/packages/core/src/commands/setContent.d.ts +40 -0
  57. package/dist/packages/core/src/commands/setMark.d.ts +15 -0
  58. package/dist/packages/core/src/commands/setMeta.d.ts +15 -0
  59. package/dist/packages/core/src/commands/setNode.d.ts +16 -0
  60. package/dist/packages/core/src/commands/setNodeSelection.d.ts +14 -0
  61. package/dist/packages/core/src/commands/setTextSelection.d.ts +14 -0
  62. package/dist/packages/core/src/commands/sinkListItem.d.ts +15 -0
  63. package/dist/packages/core/src/commands/splitBlock.d.ts +17 -0
  64. package/dist/packages/core/src/commands/splitListItem.d.ts +15 -0
  65. package/dist/packages/core/src/commands/toggleList.d.ts +18 -0
  66. package/dist/packages/core/src/commands/toggleMark.d.ts +30 -0
  67. package/dist/packages/core/src/commands/toggleNode.d.ts +17 -0
  68. package/dist/packages/core/src/commands/toggleWrap.d.ts +16 -0
  69. package/dist/packages/core/src/commands/undoInputRule.d.ts +13 -0
  70. package/dist/packages/core/src/commands/unsetAllMarks.d.ts +13 -0
  71. package/dist/packages/core/src/commands/unsetMark.d.ts +25 -0
  72. package/dist/packages/core/src/commands/updateAttributes.d.ts +24 -0
  73. package/dist/packages/core/src/commands/wrapIn.d.ts +16 -0
  74. package/dist/packages/core/src/commands/wrapInList.d.ts +16 -0
  75. package/dist/packages/core/src/extensions/clipboardTextSerializer.d.ts +5 -0
  76. package/dist/packages/core/src/extensions/commands.d.ts +3 -0
  77. package/dist/packages/core/src/extensions/editable.d.ts +2 -0
  78. package/dist/packages/core/src/extensions/focusEvents.d.ts +2 -0
  79. package/dist/packages/core/src/extensions/index.d.ts +6 -0
  80. package/dist/packages/core/src/extensions/keymap.d.ts +2 -0
  81. package/dist/packages/core/src/extensions/tabindex.d.ts +2 -0
  82. package/dist/packages/core/src/helpers/combineTransactionSteps.d.ts +10 -0
  83. package/dist/packages/core/src/helpers/createChainableState.d.ts +10 -0
  84. package/dist/packages/core/src/helpers/createDocument.d.ts +12 -0
  85. package/dist/packages/core/src/helpers/createNodeFromContent.d.ts +15 -0
  86. package/dist/packages/core/src/helpers/defaultBlockAt.d.ts +7 -0
  87. package/dist/packages/core/src/helpers/findChildren.d.ts +9 -0
  88. package/dist/packages/core/src/helpers/findChildrenInRange.d.ts +10 -0
  89. package/dist/packages/core/src/helpers/findParentNode.d.ts +16 -0
  90. package/dist/packages/core/src/helpers/findParentNodeClosestToPos.d.ts +17 -0
  91. package/dist/packages/core/src/helpers/generateHTML.d.ts +8 -0
  92. package/dist/packages/core/src/helpers/generateJSON.d.ts +8 -0
  93. package/dist/packages/core/src/helpers/generateText.d.ts +12 -0
  94. package/dist/packages/core/src/helpers/getAttributes.d.ts +9 -0
  95. package/dist/packages/core/src/helpers/getAttributesFromExtensions.d.ts +6 -0
  96. package/dist/packages/core/src/helpers/getChangedRanges.d.ts +11 -0
  97. package/dist/packages/core/src/helpers/getDebugJSON.d.ts +8 -0
  98. package/dist/packages/core/src/helpers/getExtensionField.d.ts +9 -0
  99. package/dist/packages/core/src/helpers/getHTMLFromFragment.d.ts +2 -0
  100. package/dist/packages/core/src/helpers/getMarkAttributes.d.ts +3 -0
  101. package/dist/packages/core/src/helpers/getMarkRange.d.ts +3 -0
  102. package/dist/packages/core/src/helpers/getMarkType.d.ts +2 -0
  103. package/dist/packages/core/src/helpers/getMarksBetween.d.ts +3 -0
  104. package/dist/packages/core/src/helpers/getNodeAtPosition.d.ts +11 -0
  105. package/dist/packages/core/src/helpers/getNodeAttributes.d.ts +3 -0
  106. package/dist/packages/core/src/helpers/getNodeType.d.ts +2 -0
  107. package/dist/packages/core/src/helpers/getRenderedAttributes.d.ts +3 -0
  108. package/dist/packages/core/src/helpers/getSchema.d.ts +4 -0
  109. package/dist/packages/core/src/helpers/getSchemaByResolvedExtensions.d.ts +10 -0
  110. package/dist/packages/core/src/helpers/getSchemaTypeByName.d.ts +8 -0
  111. package/dist/packages/core/src/helpers/getSchemaTypeNameByName.d.ts +8 -0
  112. package/dist/packages/core/src/helpers/getSplittedAttributes.d.ts +9 -0
  113. package/dist/packages/core/src/helpers/getText.d.ts +15 -0
  114. package/dist/packages/core/src/helpers/getTextBetween.d.ts +14 -0
  115. package/dist/packages/core/src/helpers/getTextContentFromNodes.d.ts +8 -0
  116. package/dist/packages/core/src/helpers/getTextSerializersFromSchema.d.ts +8 -0
  117. package/dist/packages/core/src/helpers/index.d.ts +50 -0
  118. package/dist/packages/core/src/helpers/injectExtensionAttributesToParseRule.d.ts +9 -0
  119. package/dist/packages/core/src/helpers/isActive.d.ts +2 -0
  120. package/dist/packages/core/src/helpers/isAtEndOfNode.d.ts +2 -0
  121. package/dist/packages/core/src/helpers/isAtStartOfNode.d.ts +2 -0
  122. package/dist/packages/core/src/helpers/isExtensionRulesEnabled.d.ts +2 -0
  123. package/dist/packages/core/src/helpers/isList.d.ts +2 -0
  124. package/dist/packages/core/src/helpers/isMarkActive.d.ts +3 -0
  125. package/dist/packages/core/src/helpers/isNodeActive.d.ts +3 -0
  126. package/dist/packages/core/src/helpers/isNodeEmpty.d.ts +2 -0
  127. package/dist/packages/core/src/helpers/isNodeSelection.d.ts +2 -0
  128. package/dist/packages/core/src/helpers/isTextSelection.d.ts +2 -0
  129. package/dist/packages/core/src/helpers/posToDOMRect.d.ts +2 -0
  130. package/dist/packages/core/src/helpers/resolveFocusPosition.d.ts +4 -0
  131. package/dist/packages/core/src/helpers/selectionToInsertionEnd.d.ts +2 -0
  132. package/dist/packages/core/src/helpers/splitExtensions.d.ts +9 -0
  133. package/dist/packages/core/src/index.d.ts +24 -0
  134. package/dist/packages/core/src/inputRules/index.d.ts +5 -0
  135. package/dist/packages/core/src/inputRules/markInputRule.d.ts +13 -0
  136. package/dist/packages/core/src/inputRules/nodeInputRule.d.ts +23 -0
  137. package/dist/packages/core/src/inputRules/textInputRule.d.ts +10 -0
  138. package/dist/packages/core/src/inputRules/textblockTypeInputRule.d.ts +15 -0
  139. package/dist/packages/core/src/inputRules/wrappingInputRule.d.ts +28 -0
  140. package/dist/packages/core/src/pasteRules/index.d.ts +3 -0
  141. package/dist/packages/core/src/pasteRules/markPasteRule.d.ts +13 -0
  142. package/dist/packages/core/src/pasteRules/nodePasteRule.d.ts +13 -0
  143. package/dist/packages/core/src/pasteRules/textPasteRule.d.ts +10 -0
  144. package/dist/packages/core/src/style.d.ts +1 -0
  145. package/dist/packages/core/src/types.d.ts +250 -0
  146. package/dist/packages/core/src/utilities/callOrReturn.d.ts +9 -0
  147. package/dist/packages/core/src/utilities/createStyleTag.d.ts +1 -0
  148. package/dist/packages/core/src/utilities/deleteProps.d.ts +6 -0
  149. package/dist/packages/core/src/utilities/elementFromString.d.ts +1 -0
  150. package/dist/packages/core/src/utilities/escapeForRegEx.d.ts +1 -0
  151. package/dist/packages/core/src/utilities/findDuplicates.d.ts +1 -0
  152. package/dist/packages/core/src/utilities/fromString.d.ts +1 -0
  153. package/dist/packages/core/src/utilities/index.d.ts +20 -0
  154. package/dist/packages/core/src/utilities/isAndroid.d.ts +1 -0
  155. package/dist/packages/core/src/utilities/isEmptyObject.d.ts +1 -0
  156. package/dist/packages/core/src/utilities/isFunction.d.ts +1 -0
  157. package/dist/packages/core/src/utilities/isMacOS.d.ts +1 -0
  158. package/dist/packages/core/src/utilities/isNumber.d.ts +1 -0
  159. package/dist/packages/core/src/utilities/isPlainObject.d.ts +1 -0
  160. package/dist/packages/core/src/utilities/isRegExp.d.ts +1 -0
  161. package/dist/packages/core/src/utilities/isString.d.ts +1 -0
  162. package/dist/packages/core/src/utilities/isiOS.d.ts +1 -0
  163. package/dist/packages/core/src/utilities/mergeAttributes.d.ts +1 -0
  164. package/dist/packages/core/src/utilities/mergeDeep.d.ts +1 -0
  165. package/dist/packages/core/src/utilities/minMax.d.ts +1 -0
  166. package/dist/packages/core/src/utilities/objectIncludes.d.ts +8 -0
  167. package/dist/packages/core/src/utilities/removeDuplicates.d.ts +8 -0
  168. package/dist/packages/extension-bubble-menu/src/bubble-menu-plugin.d.ts +76 -0
  169. package/dist/packages/extension-bubble-menu/src/bubble-menu.d.ts +15 -0
  170. package/dist/packages/extension-bubble-menu/src/index.d.ts +4 -0
  171. package/dist/packages/extension-floating-menu/src/floating-menu-plugin.d.ts +66 -0
  172. package/dist/packages/extension-floating-menu/src/floating-menu.d.ts +15 -0
  173. package/dist/packages/extension-floating-menu/src/index.d.ts +4 -0
  174. package/dist/packages/react/src/BubbleMenu.d.ts +11 -11
  175. package/dist/packages/react/src/Context.d.ts +15 -15
  176. package/dist/packages/react/src/Editor.d.ts +12 -12
  177. package/dist/packages/react/src/EditorContent.d.ts +24 -24
  178. package/dist/packages/react/src/FloatingMenu.d.ts +10 -10
  179. package/dist/packages/react/src/NodeViewContent.d.ts +6 -6
  180. package/dist/packages/react/src/NodeViewWrapper.d.ts +6 -6
  181. package/dist/packages/react/src/ReactNodeViewRenderer.d.ts +16 -16
  182. package/dist/packages/react/src/ReactRenderer.d.ts +62 -62
  183. package/dist/packages/react/src/index.d.ts +12 -12
  184. package/dist/packages/react/src/useEditor.d.ts +11 -11
  185. package/dist/packages/react/src/useReactNodeView.d.ts +7 -7
  186. package/package.json +5 -5
package/dist/index.umd.js CHANGED
@@ -4,558 +4,553 @@
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@tiptap/react"] = {}, global.extensionBubbleMenu, global.React, global.ReactDOM, global.core, global.extensionFloatingMenu));
5
5
  })(this, (function (exports, extensionBubbleMenu, React, ReactDOM, core, extensionFloatingMenu) { 'use strict';
6
6
 
7
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
-
9
- var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
10
- var ReactDOM__default = /*#__PURE__*/_interopDefaultLegacy(ReactDOM);
11
-
12
- const mergeRefs = (...refs) => {
13
- return (node) => {
14
- refs.forEach(ref => {
15
- if (typeof ref === 'function') {
16
- ref(node);
17
- }
18
- else if (ref) {
19
- ref.current = node;
20
- }
21
- });
22
- };
23
- };
24
- const Portals = ({ renderers }) => {
25
- return (React__default["default"].createElement(React__default["default"].Fragment, null, Object.entries(renderers).map(([key, renderer]) => {
26
- return ReactDOM__default["default"].createPortal(renderer.reactElement, renderer.element, key);
27
- })));
28
- };
29
- class PureEditorContent extends React__default["default"].Component {
30
- constructor(props) {
31
- super(props);
32
- this.editorContentRef = React__default["default"].createRef();
33
- this.initialized = false;
34
- this.state = {
35
- renderers: {},
36
- };
37
- }
38
- componentDidMount() {
39
- this.init();
40
- }
41
- componentDidUpdate() {
42
- this.init();
43
- }
44
- init() {
45
- const { editor } = this.props;
46
- if (editor && !editor.isDestroyed && editor.options.element) {
47
- if (editor.contentComponent) {
48
- return;
49
- }
50
- const element = this.editorContentRef.current;
51
- element.append(...editor.options.element.childNodes);
52
- editor.setOptions({
53
- element,
54
- });
55
- editor.contentComponent = this;
56
- editor.createNodeViews();
57
- this.initialized = true;
58
- }
59
- }
60
- maybeFlushSync(fn) {
61
- // Avoid calling flushSync until the editor is initialized.
62
- // Initialization happens during the componentDidMount or componentDidUpdate
63
- // lifecycle methods, and React doesn't allow calling flushSync from inside
64
- // a lifecycle method.
65
- if (this.initialized) {
66
- ReactDOM.flushSync(fn);
67
- }
68
- else {
69
- fn();
70
- }
71
- }
72
- setRenderer(id, renderer) {
73
- this.maybeFlushSync(() => {
74
- this.setState(({ renderers }) => ({
75
- renderers: {
76
- ...renderers,
77
- [id]: renderer,
78
- },
79
- }));
80
- });
81
- }
82
- removeRenderer(id) {
83
- this.maybeFlushSync(() => {
84
- this.setState(({ renderers }) => {
85
- const nextRenderers = { ...renderers };
86
- delete nextRenderers[id];
87
- return { renderers: nextRenderers };
88
- });
89
- });
90
- }
91
- componentWillUnmount() {
92
- const { editor } = this.props;
93
- if (!editor) {
94
- return;
95
- }
96
- this.initialized = false;
97
- if (!editor.isDestroyed) {
98
- editor.view.setProps({
99
- nodeViews: {},
100
- });
101
- }
102
- editor.contentComponent = null;
103
- if (!editor.options.element.firstChild) {
104
- return;
105
- }
106
- const newElement = document.createElement('div');
107
- newElement.append(...editor.options.element.childNodes);
108
- editor.setOptions({
109
- element: newElement,
110
- });
111
- }
112
- render() {
113
- const { editor, innerRef, ...rest } = this.props;
114
- return (React__default["default"].createElement(React__default["default"].Fragment, null,
115
- React__default["default"].createElement("div", { ref: mergeRefs(innerRef, this.editorContentRef), ...rest }),
116
- React__default["default"].createElement(Portals, { renderers: this.state.renderers })));
117
- }
118
- }
119
- // EditorContent should be re-created whenever the Editor instance changes
120
- const EditorContentWithKey = React.forwardRef((props, ref) => {
121
- const key = React__default["default"].useMemo(() => {
122
- return Math.floor(Math.random() * 0xFFFFFFFF).toString();
123
- }, [props.editor]);
124
- // Can't use JSX here because it conflicts with the type definition of Vue's JSX, so use createElement
125
- return React__default["default"].createElement(PureEditorContent, {
126
- key,
127
- innerRef: ref,
128
- ...props,
129
- });
130
- });
131
- const EditorContent = React__default["default"].memo(EditorContentWithKey);
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);
132
127
 
133
- class Editor extends core.Editor {
134
- constructor() {
135
- super(...arguments);
136
- this.contentComponent = null;
137
- }
128
+ class Editor extends core.Editor {
129
+ constructor() {
130
+ super(...arguments);
131
+ this.contentComponent = null;
132
+ }
138
133
  }
139
134
 
140
- /**
141
- * This hook allows you to create an editor instance.
142
- * @param options The editor options
143
- * @param deps The dependencies to watch for changes
144
- * @returns The editor instance
145
- * @example const editor = useEditor({ extensions: [...] })
146
- */
147
- const useEditor = (options = {}, deps = []) => {
148
- const editorRef = React.useRef(null);
149
- const [, forceUpdate] = React.useState({});
150
- const { onBeforeCreate, onBlur, onCreate, onDestroy, onFocus, onSelectionUpdate, onTransaction, onUpdate, onContentError, } = options;
151
- const onBeforeCreateRef = React.useRef(onBeforeCreate);
152
- const onBlurRef = React.useRef(onBlur);
153
- const onCreateRef = React.useRef(onCreate);
154
- const onDestroyRef = React.useRef(onDestroy);
155
- const onFocusRef = React.useRef(onFocus);
156
- const onSelectionUpdateRef = React.useRef(onSelectionUpdate);
157
- const onTransactionRef = React.useRef(onTransaction);
158
- const onUpdateRef = React.useRef(onUpdate);
159
- const onContentErrorRef = React.useRef(onContentError);
160
- // This effect will handle updating the editor instance
161
- // when the event handlers change.
162
- React.useEffect(() => {
163
- if (!editorRef.current) {
164
- return;
165
- }
166
- if (onBeforeCreate) {
167
- editorRef.current.off('beforeCreate', onBeforeCreateRef.current);
168
- editorRef.current.on('beforeCreate', onBeforeCreate);
169
- onBeforeCreateRef.current = onBeforeCreate;
170
- }
171
- if (onBlur) {
172
- editorRef.current.off('blur', onBlurRef.current);
173
- editorRef.current.on('blur', onBlur);
174
- onBlurRef.current = onBlur;
175
- }
176
- if (onCreate) {
177
- editorRef.current.off('create', onCreateRef.current);
178
- editorRef.current.on('create', onCreate);
179
- onCreateRef.current = onCreate;
180
- }
181
- if (onDestroy) {
182
- editorRef.current.off('destroy', onDestroyRef.current);
183
- editorRef.current.on('destroy', onDestroy);
184
- onDestroyRef.current = onDestroy;
185
- }
186
- if (onFocus) {
187
- editorRef.current.off('focus', onFocusRef.current);
188
- editorRef.current.on('focus', onFocus);
189
- onFocusRef.current = onFocus;
190
- }
191
- if (onSelectionUpdate) {
192
- editorRef.current.off('selectionUpdate', onSelectionUpdateRef.current);
193
- editorRef.current.on('selectionUpdate', onSelectionUpdate);
194
- onSelectionUpdateRef.current = onSelectionUpdate;
195
- }
196
- if (onTransaction) {
197
- editorRef.current.off('transaction', onTransactionRef.current);
198
- editorRef.current.on('transaction', onTransaction);
199
- onTransactionRef.current = onTransaction;
200
- }
201
- if (onUpdate) {
202
- editorRef.current.off('update', onUpdateRef.current);
203
- editorRef.current.on('update', onUpdate);
204
- onUpdateRef.current = onUpdate;
205
- }
206
- if (onContentError) {
207
- editorRef.current.off('contentError', onContentErrorRef.current);
208
- editorRef.current.on('contentError', onContentError);
209
- onContentErrorRef.current = onContentError;
210
- }
211
- }, [onBeforeCreate, onBlur, onCreate, onDestroy, onFocus, onSelectionUpdate, onTransaction, onUpdate, editorRef.current]);
212
- React.useEffect(() => {
213
- let isMounted = true;
214
- const editor = new Editor(options);
215
- editorRef.current = editor;
216
- editorRef.current.on('transaction', () => {
217
- requestAnimationFrame(() => {
218
- requestAnimationFrame(() => {
219
- if (isMounted) {
220
- forceUpdate({});
221
- }
222
- });
223
- });
224
- });
225
- return () => {
226
- isMounted = false;
227
- editor.destroy();
228
- };
229
- }, deps);
230
- return editorRef.current;
135
+ /**
136
+ * This hook allows you to create an editor instance.
137
+ * @param options The editor options
138
+ * @param deps The dependencies to watch for changes
139
+ * @returns The editor instance
140
+ * @example const editor = useEditor({ extensions: [...] })
141
+ */
142
+ const useEditor = (options = {}, deps = []) => {
143
+ const editorRef = React.useRef(null);
144
+ const [, forceUpdate] = React.useState({});
145
+ const { onBeforeCreate, onBlur, onCreate, onDestroy, onFocus, onSelectionUpdate, onTransaction, onUpdate, onContentError, } = options;
146
+ const onBeforeCreateRef = React.useRef(onBeforeCreate);
147
+ const onBlurRef = React.useRef(onBlur);
148
+ const onCreateRef = React.useRef(onCreate);
149
+ const onDestroyRef = React.useRef(onDestroy);
150
+ const onFocusRef = React.useRef(onFocus);
151
+ const onSelectionUpdateRef = React.useRef(onSelectionUpdate);
152
+ const onTransactionRef = React.useRef(onTransaction);
153
+ const onUpdateRef = React.useRef(onUpdate);
154
+ const onContentErrorRef = React.useRef(onContentError);
155
+ // This effect will handle updating the editor instance
156
+ // when the event handlers change.
157
+ React.useEffect(() => {
158
+ if (!editorRef.current) {
159
+ return;
160
+ }
161
+ if (onBeforeCreate) {
162
+ editorRef.current.off('beforeCreate', onBeforeCreateRef.current);
163
+ editorRef.current.on('beforeCreate', onBeforeCreate);
164
+ onBeforeCreateRef.current = onBeforeCreate;
165
+ }
166
+ if (onBlur) {
167
+ editorRef.current.off('blur', onBlurRef.current);
168
+ editorRef.current.on('blur', onBlur);
169
+ onBlurRef.current = onBlur;
170
+ }
171
+ if (onCreate) {
172
+ editorRef.current.off('create', onCreateRef.current);
173
+ editorRef.current.on('create', onCreate);
174
+ onCreateRef.current = onCreate;
175
+ }
176
+ if (onDestroy) {
177
+ editorRef.current.off('destroy', onDestroyRef.current);
178
+ editorRef.current.on('destroy', onDestroy);
179
+ onDestroyRef.current = onDestroy;
180
+ }
181
+ if (onFocus) {
182
+ editorRef.current.off('focus', onFocusRef.current);
183
+ editorRef.current.on('focus', onFocus);
184
+ onFocusRef.current = onFocus;
185
+ }
186
+ if (onSelectionUpdate) {
187
+ editorRef.current.off('selectionUpdate', onSelectionUpdateRef.current);
188
+ editorRef.current.on('selectionUpdate', onSelectionUpdate);
189
+ onSelectionUpdateRef.current = onSelectionUpdate;
190
+ }
191
+ if (onTransaction) {
192
+ editorRef.current.off('transaction', onTransactionRef.current);
193
+ editorRef.current.on('transaction', onTransaction);
194
+ onTransactionRef.current = onTransaction;
195
+ }
196
+ if (onUpdate) {
197
+ editorRef.current.off('update', onUpdateRef.current);
198
+ editorRef.current.on('update', onUpdate);
199
+ onUpdateRef.current = onUpdate;
200
+ }
201
+ if (onContentError) {
202
+ editorRef.current.off('contentError', onContentErrorRef.current);
203
+ editorRef.current.on('contentError', onContentError);
204
+ onContentErrorRef.current = onContentError;
205
+ }
206
+ }, [onBeforeCreate, onBlur, onCreate, onDestroy, onFocus, onSelectionUpdate, onTransaction, onUpdate, editorRef.current]);
207
+ React.useEffect(() => {
208
+ let isMounted = true;
209
+ const editor = new Editor(options);
210
+ editorRef.current = editor;
211
+ editorRef.current.on('transaction', () => {
212
+ requestAnimationFrame(() => {
213
+ requestAnimationFrame(() => {
214
+ if (isMounted) {
215
+ forceUpdate({});
216
+ }
217
+ });
218
+ });
219
+ });
220
+ return () => {
221
+ isMounted = false;
222
+ editor.destroy();
223
+ };
224
+ }, deps);
225
+ return editorRef.current;
231
226
  };
232
227
 
233
- const EditorContext = React.createContext({
234
- editor: null,
235
- });
236
- const EditorConsumer = EditorContext.Consumer;
237
- const useCurrentEditor = () => React.useContext(EditorContext);
238
- const EditorProvider = ({ children, slotAfter, slotBefore, ...editorOptions }) => {
239
- const editor = useEditor(editorOptions);
240
- if (!editor) {
241
- return null;
242
- }
243
- return (React__default["default"].createElement(EditorContext.Provider, { value: { editor } },
244
- slotBefore,
245
- React__default["default"].createElement(EditorConsumer, null, ({ editor: currentEditor }) => (React__default["default"].createElement(EditorContent, { editor: currentEditor }))),
246
- children,
247
- slotAfter));
228
+ const EditorContext = React.createContext({
229
+ editor: null,
230
+ });
231
+ const EditorConsumer = EditorContext.Consumer;
232
+ const useCurrentEditor = () => React.useContext(EditorContext);
233
+ const EditorProvider = ({ children, slotAfter, slotBefore, ...editorOptions }) => {
234
+ const editor = useEditor(editorOptions);
235
+ if (!editor) {
236
+ return null;
237
+ }
238
+ return (React.createElement(EditorContext.Provider, { value: { editor } },
239
+ slotBefore,
240
+ React.createElement(EditorConsumer, null, ({ editor: currentEditor }) => (React.createElement(EditorContent, { editor: currentEditor }))),
241
+ children,
242
+ slotAfter));
248
243
  };
249
244
 
250
- const BubbleMenu = (props) => {
251
- const [element, setElement] = React.useState(null);
252
- const { editor: currentEditor } = useCurrentEditor();
253
- React.useEffect(() => {
254
- var _a;
255
- if (!element) {
256
- return;
257
- }
258
- if (((_a = props.editor) === null || _a === void 0 ? void 0 : _a.isDestroyed) || (currentEditor === null || currentEditor === void 0 ? void 0 : currentEditor.isDestroyed)) {
259
- return;
260
- }
261
- const { pluginKey = 'bubbleMenu', editor, tippyOptions = {}, updateDelay, shouldShow = null, } = props;
262
- const menuEditor = editor || currentEditor;
263
- if (!menuEditor) {
264
- console.warn('BubbleMenu component is not rendered inside of an editor component or does not have editor prop.');
265
- return;
266
- }
267
- const plugin = extensionBubbleMenu.BubbleMenuPlugin({
268
- updateDelay,
269
- editor: menuEditor,
270
- element,
271
- pluginKey,
272
- shouldShow,
273
- tippyOptions,
274
- });
275
- menuEditor.registerPlugin(plugin);
276
- return () => menuEditor.unregisterPlugin(pluginKey);
277
- }, [props.editor, currentEditor, element]);
278
- return (React__default["default"].createElement("div", { ref: setElement, className: props.className, style: { visibility: 'hidden' } }, props.children));
245
+ const BubbleMenu = (props) => {
246
+ const [element, setElement] = React.useState(null);
247
+ const { editor: currentEditor } = useCurrentEditor();
248
+ React.useEffect(() => {
249
+ var _a;
250
+ if (!element) {
251
+ return;
252
+ }
253
+ if (((_a = props.editor) === null || _a === void 0 ? void 0 : _a.isDestroyed) || (currentEditor === null || currentEditor === void 0 ? void 0 : currentEditor.isDestroyed)) {
254
+ return;
255
+ }
256
+ const { pluginKey = 'bubbleMenu', editor, tippyOptions = {}, updateDelay, shouldShow = null, } = props;
257
+ const menuEditor = editor || currentEditor;
258
+ if (!menuEditor) {
259
+ console.warn('BubbleMenu component is not rendered inside of an editor component or does not have editor prop.');
260
+ return;
261
+ }
262
+ const plugin = extensionBubbleMenu.BubbleMenuPlugin({
263
+ updateDelay,
264
+ editor: menuEditor,
265
+ element,
266
+ pluginKey,
267
+ shouldShow,
268
+ tippyOptions,
269
+ });
270
+ menuEditor.registerPlugin(plugin);
271
+ return () => menuEditor.unregisterPlugin(pluginKey);
272
+ }, [props.editor, currentEditor, element]);
273
+ return (React.createElement("div", { ref: setElement, className: props.className, style: { visibility: 'hidden' } }, props.children));
279
274
  };
280
275
 
281
- const FloatingMenu = (props) => {
282
- const [element, setElement] = React.useState(null);
283
- const { editor: currentEditor } = useCurrentEditor();
284
- React.useEffect(() => {
285
- var _a;
286
- if (!element) {
287
- return;
288
- }
289
- if (((_a = props.editor) === null || _a === void 0 ? void 0 : _a.isDestroyed) || (currentEditor === null || currentEditor === void 0 ? void 0 : currentEditor.isDestroyed)) {
290
- return;
291
- }
292
- const { pluginKey = 'floatingMenu', editor, tippyOptions = {}, shouldShow = null, } = props;
293
- const menuEditor = editor || currentEditor;
294
- if (!menuEditor) {
295
- console.warn('FloatingMenu component is not rendered inside of an editor component or does not have editor prop.');
296
- return;
297
- }
298
- const plugin = extensionFloatingMenu.FloatingMenuPlugin({
299
- pluginKey,
300
- editor: menuEditor,
301
- element,
302
- tippyOptions,
303
- shouldShow,
304
- });
305
- menuEditor.registerPlugin(plugin);
306
- return () => menuEditor.unregisterPlugin(pluginKey);
307
- }, [
308
- props.editor,
309
- currentEditor,
310
- element,
311
- ]);
312
- return (React__default["default"].createElement("div", { ref: setElement, className: props.className, style: { visibility: 'hidden' } }, props.children));
276
+ const FloatingMenu = (props) => {
277
+ const [element, setElement] = React.useState(null);
278
+ const { editor: currentEditor } = useCurrentEditor();
279
+ React.useEffect(() => {
280
+ var _a;
281
+ if (!element) {
282
+ return;
283
+ }
284
+ if (((_a = props.editor) === null || _a === void 0 ? void 0 : _a.isDestroyed) || (currentEditor === null || currentEditor === void 0 ? void 0 : currentEditor.isDestroyed)) {
285
+ return;
286
+ }
287
+ const { pluginKey = 'floatingMenu', editor, tippyOptions = {}, shouldShow = null, } = props;
288
+ const menuEditor = editor || currentEditor;
289
+ if (!menuEditor) {
290
+ console.warn('FloatingMenu component is not rendered inside of an editor component or does not have editor prop.');
291
+ return;
292
+ }
293
+ const plugin = extensionFloatingMenu.FloatingMenuPlugin({
294
+ pluginKey,
295
+ editor: menuEditor,
296
+ element,
297
+ tippyOptions,
298
+ shouldShow,
299
+ });
300
+ menuEditor.registerPlugin(plugin);
301
+ return () => menuEditor.unregisterPlugin(pluginKey);
302
+ }, [
303
+ props.editor,
304
+ currentEditor,
305
+ element,
306
+ ]);
307
+ return (React.createElement("div", { ref: setElement, className: props.className, style: { visibility: 'hidden' } }, props.children));
313
308
  };
314
309
 
315
- const ReactNodeViewContext = React.createContext({
316
- onDragStart: undefined,
317
- });
310
+ const ReactNodeViewContext = React.createContext({
311
+ onDragStart: undefined,
312
+ });
318
313
  const useReactNodeView = () => React.useContext(ReactNodeViewContext);
319
314
 
320
- const NodeViewContent = props => {
321
- const Tag = props.as || 'div';
322
- const { nodeViewContentRef } = useReactNodeView();
323
- return (React__default["default"].createElement(Tag, { ...props, ref: nodeViewContentRef, "data-node-view-content": "", style: {
324
- whiteSpace: 'pre-wrap',
325
- ...props.style,
326
- } }));
315
+ const NodeViewContent = props => {
316
+ const Tag = props.as || 'div';
317
+ const { nodeViewContentRef } = useReactNodeView();
318
+ return (React.createElement(Tag, { ...props, ref: nodeViewContentRef, "data-node-view-content": "", style: {
319
+ whiteSpace: 'pre-wrap',
320
+ ...props.style,
321
+ } }));
327
322
  };
328
323
 
329
- const NodeViewWrapper = React__default["default"].forwardRef((props, ref) => {
330
- const { onDragStart } = useReactNodeView();
331
- const Tag = props.as || 'div';
332
- return (React__default["default"].createElement(Tag, { ...props, ref: ref, "data-node-view-wrapper": "", onDragStart: onDragStart, style: {
333
- whiteSpace: 'normal',
334
- ...props.style,
335
- } }));
324
+ const NodeViewWrapper = React.forwardRef((props, ref) => {
325
+ const { onDragStart } = useReactNodeView();
326
+ const Tag = props.as || 'div';
327
+ return (React.createElement(Tag, { ...props, ref: ref, "data-node-view-wrapper": "", onDragStart: onDragStart, style: {
328
+ whiteSpace: 'normal',
329
+ ...props.style,
330
+ } }));
336
331
  });
337
332
 
338
- /**
339
- * Check if a component is a class component.
340
- * @param Component
341
- * @returns {boolean}
342
- */
343
- function isClassComponent(Component) {
344
- return !!(typeof Component === 'function'
345
- && Component.prototype
346
- && Component.prototype.isReactComponent);
347
- }
348
- /**
349
- * Check if a component is a forward ref component.
350
- * @param Component
351
- * @returns {boolean}
352
- */
353
- function isForwardRefComponent(Component) {
354
- var _a;
355
- return !!(typeof Component === 'object'
356
- && ((_a = Component.$$typeof) === null || _a === void 0 ? void 0 : _a.toString()) === 'Symbol(react.forward_ref)');
357
- }
358
- /**
359
- * The ReactRenderer class. It's responsible for rendering React components inside the editor.
360
- * @example
361
- * new ReactRenderer(MyComponent, {
362
- * editor,
363
- * props: {
364
- * foo: 'bar',
365
- * },
366
- * as: 'span',
367
- * })
368
- */
369
- class ReactRenderer {
370
- constructor(component, { editor, props = {}, as = 'div', className = '', attrs, }) {
371
- this.ref = null;
372
- this.id = Math.floor(Math.random() * 0xFFFFFFFF).toString();
373
- this.component = component;
374
- this.editor = editor;
375
- this.props = props;
376
- this.element = document.createElement(as);
377
- this.element.classList.add('react-renderer');
378
- if (className) {
379
- this.element.classList.add(...className.split(' '));
380
- }
381
- if (attrs) {
382
- Object.keys(attrs).forEach(key => {
383
- this.element.setAttribute(key, attrs[key]);
384
- });
385
- }
386
- this.render();
387
- }
388
- render() {
389
- var _a, _b;
390
- const Component = this.component;
391
- const props = this.props;
392
- if (isClassComponent(Component) || isForwardRefComponent(Component)) {
393
- props.ref = (ref) => {
394
- this.ref = ref;
395
- };
396
- }
397
- this.reactElement = React__default["default"].createElement(Component, { ...props });
398
- (_b = (_a = this.editor) === null || _a === void 0 ? void 0 : _a.contentComponent) === null || _b === void 0 ? void 0 : _b.setRenderer(this.id, this);
399
- }
400
- updateProps(props = {}) {
401
- this.props = {
402
- ...this.props,
403
- ...props,
404
- };
405
- this.render();
406
- }
407
- destroy() {
408
- var _a, _b;
409
- (_b = (_a = this.editor) === null || _a === void 0 ? void 0 : _a.contentComponent) === null || _b === void 0 ? void 0 : _b.removeRenderer(this.id);
410
- }
333
+ /**
334
+ * Check if a component is a class component.
335
+ * @param Component
336
+ * @returns {boolean}
337
+ */
338
+ function isClassComponent(Component) {
339
+ return !!(typeof Component === 'function'
340
+ && Component.prototype
341
+ && Component.prototype.isReactComponent);
342
+ }
343
+ /**
344
+ * Check if a component is a forward ref component.
345
+ * @param Component
346
+ * @returns {boolean}
347
+ */
348
+ function isForwardRefComponent(Component) {
349
+ var _a;
350
+ return !!(typeof Component === 'object'
351
+ && ((_a = Component.$$typeof) === null || _a === void 0 ? void 0 : _a.toString()) === 'Symbol(react.forward_ref)');
352
+ }
353
+ /**
354
+ * The ReactRenderer class. It's responsible for rendering React components inside the editor.
355
+ * @example
356
+ * new ReactRenderer(MyComponent, {
357
+ * editor,
358
+ * props: {
359
+ * foo: 'bar',
360
+ * },
361
+ * as: 'span',
362
+ * })
363
+ */
364
+ class ReactRenderer {
365
+ constructor(component, { editor, props = {}, as = 'div', className = '', attrs, }) {
366
+ this.ref = null;
367
+ this.id = Math.floor(Math.random() * 0xFFFFFFFF).toString();
368
+ this.component = component;
369
+ this.editor = editor;
370
+ this.props = props;
371
+ this.element = document.createElement(as);
372
+ this.element.classList.add('react-renderer');
373
+ if (className) {
374
+ this.element.classList.add(...className.split(' '));
375
+ }
376
+ if (attrs) {
377
+ Object.keys(attrs).forEach(key => {
378
+ this.element.setAttribute(key, attrs[key]);
379
+ });
380
+ }
381
+ this.render();
382
+ }
383
+ render() {
384
+ var _a, _b;
385
+ const Component = this.component;
386
+ const props = this.props;
387
+ if (isClassComponent(Component) || isForwardRefComponent(Component)) {
388
+ props.ref = (ref) => {
389
+ this.ref = ref;
390
+ };
391
+ }
392
+ this.reactElement = React.createElement(Component, { ...props });
393
+ (_b = (_a = this.editor) === null || _a === void 0 ? void 0 : _a.contentComponent) === null || _b === void 0 ? void 0 : _b.setRenderer(this.id, this);
394
+ }
395
+ updateProps(props = {}) {
396
+ this.props = {
397
+ ...this.props,
398
+ ...props,
399
+ };
400
+ this.render();
401
+ }
402
+ destroy() {
403
+ var _a, _b;
404
+ (_b = (_a = this.editor) === null || _a === void 0 ? void 0 : _a.contentComponent) === null || _b === void 0 ? void 0 : _b.removeRenderer(this.id);
405
+ }
411
406
  }
412
407
 
413
- class ReactNodeView extends core.NodeView {
414
- mount() {
415
- const props = {
416
- editor: this.editor,
417
- node: this.node,
418
- decorations: this.decorations,
419
- selected: false,
420
- extension: this.extension,
421
- getPos: () => this.getPos(),
422
- updateAttributes: (attributes = {}) => this.updateAttributes(attributes),
423
- deleteNode: () => this.deleteNode(),
424
- };
425
- if (!this.component.displayName) {
426
- const capitalizeFirstChar = (string) => {
427
- return string.charAt(0).toUpperCase() + string.substring(1);
428
- };
429
- this.component.displayName = capitalizeFirstChar(this.extension.name);
430
- }
431
- const ReactNodeViewProvider = componentProps => {
432
- const Component = this.component;
433
- const onDragStart = this.onDragStart.bind(this);
434
- const nodeViewContentRef = element => {
435
- if (element && this.contentDOMElement && element.firstChild !== this.contentDOMElement) {
436
- element.appendChild(this.contentDOMElement);
437
- }
438
- };
439
- return (React__default["default"].createElement(React__default["default"].Fragment, null,
440
- React__default["default"].createElement(ReactNodeViewContext.Provider, { value: { onDragStart, nodeViewContentRef } },
441
- React__default["default"].createElement(Component, { ...componentProps }))));
442
- };
443
- ReactNodeViewProvider.displayName = 'ReactNodeView';
444
- if (this.node.isLeaf) {
445
- this.contentDOMElement = null;
446
- }
447
- else if (this.options.contentDOMElementTag) {
448
- this.contentDOMElement = document.createElement(this.options.contentDOMElementTag);
449
- }
450
- else {
451
- this.contentDOMElement = document.createElement(this.node.isInline ? 'span' : 'div');
452
- }
453
- if (this.contentDOMElement) {
454
- // For some reason the whiteSpace prop is not inherited properly in Chrome and Safari
455
- // With this fix it seems to work fine
456
- // See: https://github.com/ueberdosis/tiptap/issues/1197
457
- this.contentDOMElement.style.whiteSpace = 'inherit';
458
- }
459
- let as = this.node.isInline ? 'span' : 'div';
460
- if (this.options.as) {
461
- as = this.options.as;
462
- }
463
- const { className = '' } = this.options;
464
- this.handleSelectionUpdate = this.handleSelectionUpdate.bind(this);
465
- this.editor.on('selectionUpdate', this.handleSelectionUpdate);
466
- this.renderer = new ReactRenderer(ReactNodeViewProvider, {
467
- editor: this.editor,
468
- props,
469
- as,
470
- className: `node-${this.node.type.name} ${className}`.trim(),
471
- attrs: this.options.attrs,
472
- });
473
- }
474
- get dom() {
475
- var _a;
476
- if (this.renderer.element.firstElementChild
477
- && !((_a = this.renderer.element.firstElementChild) === null || _a === void 0 ? void 0 : _a.hasAttribute('data-node-view-wrapper'))) {
478
- throw Error('Please use the NodeViewWrapper component for your node view.');
479
- }
480
- return this.renderer.element;
481
- }
482
- get contentDOM() {
483
- if (this.node.isLeaf) {
484
- return null;
485
- }
486
- return this.contentDOMElement;
487
- }
488
- handleSelectionUpdate() {
489
- const { from, to } = this.editor.state.selection;
490
- if (from <= this.getPos() && to >= this.getPos() + this.node.nodeSize) {
491
- if (this.renderer.props.selected) {
492
- return;
493
- }
494
- this.selectNode();
495
- }
496
- else {
497
- if (!this.renderer.props.selected) {
498
- return;
499
- }
500
- this.deselectNode();
501
- }
502
- }
503
- update(node, decorations) {
504
- const updateProps = (props) => {
505
- this.renderer.updateProps(props);
506
- };
507
- if (node.type !== this.node.type) {
508
- return false;
509
- }
510
- if (typeof this.options.update === 'function') {
511
- const oldNode = this.node;
512
- const oldDecorations = this.decorations;
513
- this.node = node;
514
- this.decorations = decorations;
515
- return this.options.update({
516
- oldNode,
517
- oldDecorations,
518
- newNode: node,
519
- newDecorations: decorations,
520
- updateProps: () => updateProps({ node, decorations }),
521
- });
522
- }
523
- if (node === this.node && this.decorations === decorations) {
524
- return true;
525
- }
526
- this.node = node;
527
- this.decorations = decorations;
528
- updateProps({ node, decorations });
529
- return true;
530
- }
531
- selectNode() {
532
- this.renderer.updateProps({
533
- selected: true,
534
- });
535
- this.renderer.element.classList.add('ProseMirror-selectednode');
536
- }
537
- deselectNode() {
538
- this.renderer.updateProps({
539
- selected: false,
540
- });
541
- this.renderer.element.classList.remove('ProseMirror-selectednode');
542
- }
543
- destroy() {
544
- this.renderer.destroy();
545
- this.editor.off('selectionUpdate', this.handleSelectionUpdate);
546
- this.contentDOMElement = null;
547
- }
548
- }
549
- function ReactNodeViewRenderer(component, options) {
550
- return (props) => {
551
- // try to get the parent component
552
- // this is important for vue devtools to show the component hierarchy correctly
553
- // maybe it’s `undefined` because <editor-content> isn’t rendered yet
554
- if (!props.editor.contentComponent) {
555
- return {};
556
- }
557
- return new ReactNodeView(component, props, options);
558
- };
408
+ class ReactNodeView extends core.NodeView {
409
+ mount() {
410
+ const props = {
411
+ editor: this.editor,
412
+ node: this.node,
413
+ decorations: this.decorations,
414
+ selected: false,
415
+ extension: this.extension,
416
+ getPos: () => this.getPos(),
417
+ updateAttributes: (attributes = {}) => this.updateAttributes(attributes),
418
+ deleteNode: () => this.deleteNode(),
419
+ };
420
+ if (!this.component.displayName) {
421
+ const capitalizeFirstChar = (string) => {
422
+ return string.charAt(0).toUpperCase() + string.substring(1);
423
+ };
424
+ this.component.displayName = capitalizeFirstChar(this.extension.name);
425
+ }
426
+ const ReactNodeViewProvider = componentProps => {
427
+ const Component = this.component;
428
+ const onDragStart = this.onDragStart.bind(this);
429
+ const nodeViewContentRef = element => {
430
+ if (element && this.contentDOMElement && element.firstChild !== this.contentDOMElement) {
431
+ element.appendChild(this.contentDOMElement);
432
+ }
433
+ };
434
+ return (React.createElement(React.Fragment, null,
435
+ React.createElement(ReactNodeViewContext.Provider, { value: { onDragStart, nodeViewContentRef } },
436
+ React.createElement(Component, { ...componentProps }))));
437
+ };
438
+ ReactNodeViewProvider.displayName = 'ReactNodeView';
439
+ if (this.node.isLeaf) {
440
+ this.contentDOMElement = null;
441
+ }
442
+ else if (this.options.contentDOMElementTag) {
443
+ this.contentDOMElement = document.createElement(this.options.contentDOMElementTag);
444
+ }
445
+ else {
446
+ this.contentDOMElement = document.createElement(this.node.isInline ? 'span' : 'div');
447
+ }
448
+ if (this.contentDOMElement) {
449
+ // For some reason the whiteSpace prop is not inherited properly in Chrome and Safari
450
+ // With this fix it seems to work fine
451
+ // See: https://github.com/ueberdosis/tiptap/issues/1197
452
+ this.contentDOMElement.style.whiteSpace = 'inherit';
453
+ }
454
+ let as = this.node.isInline ? 'span' : 'div';
455
+ if (this.options.as) {
456
+ as = this.options.as;
457
+ }
458
+ const { className = '' } = this.options;
459
+ this.handleSelectionUpdate = this.handleSelectionUpdate.bind(this);
460
+ this.editor.on('selectionUpdate', this.handleSelectionUpdate);
461
+ this.renderer = new ReactRenderer(ReactNodeViewProvider, {
462
+ editor: this.editor,
463
+ props,
464
+ as,
465
+ className: `node-${this.node.type.name} ${className}`.trim(),
466
+ attrs: this.options.attrs,
467
+ });
468
+ }
469
+ get dom() {
470
+ var _a;
471
+ if (this.renderer.element.firstElementChild
472
+ && !((_a = this.renderer.element.firstElementChild) === null || _a === void 0 ? void 0 : _a.hasAttribute('data-node-view-wrapper'))) {
473
+ throw Error('Please use the NodeViewWrapper component for your node view.');
474
+ }
475
+ return this.renderer.element;
476
+ }
477
+ get contentDOM() {
478
+ if (this.node.isLeaf) {
479
+ return null;
480
+ }
481
+ return this.contentDOMElement;
482
+ }
483
+ handleSelectionUpdate() {
484
+ const { from, to } = this.editor.state.selection;
485
+ if (from <= this.getPos() && to >= this.getPos() + this.node.nodeSize) {
486
+ if (this.renderer.props.selected) {
487
+ return;
488
+ }
489
+ this.selectNode();
490
+ }
491
+ else {
492
+ if (!this.renderer.props.selected) {
493
+ return;
494
+ }
495
+ this.deselectNode();
496
+ }
497
+ }
498
+ update(node, decorations) {
499
+ const updateProps = (props) => {
500
+ this.renderer.updateProps(props);
501
+ };
502
+ if (node.type !== this.node.type) {
503
+ return false;
504
+ }
505
+ if (typeof this.options.update === 'function') {
506
+ const oldNode = this.node;
507
+ const oldDecorations = this.decorations;
508
+ this.node = node;
509
+ this.decorations = decorations;
510
+ return this.options.update({
511
+ oldNode,
512
+ oldDecorations,
513
+ newNode: node,
514
+ newDecorations: decorations,
515
+ updateProps: () => updateProps({ node, decorations }),
516
+ });
517
+ }
518
+ if (node === this.node && this.decorations === decorations) {
519
+ return true;
520
+ }
521
+ this.node = node;
522
+ this.decorations = decorations;
523
+ updateProps({ node, decorations });
524
+ return true;
525
+ }
526
+ selectNode() {
527
+ this.renderer.updateProps({
528
+ selected: true,
529
+ });
530
+ this.renderer.element.classList.add('ProseMirror-selectednode');
531
+ }
532
+ deselectNode() {
533
+ this.renderer.updateProps({
534
+ selected: false,
535
+ });
536
+ this.renderer.element.classList.remove('ProseMirror-selectednode');
537
+ }
538
+ destroy() {
539
+ this.renderer.destroy();
540
+ this.editor.off('selectionUpdate', this.handleSelectionUpdate);
541
+ this.contentDOMElement = null;
542
+ }
543
+ }
544
+ function ReactNodeViewRenderer(component, options) {
545
+ return (props) => {
546
+ // try to get the parent component
547
+ // this is important for vue devtools to show the component hierarchy correctly
548
+ // maybe it’s `undefined` because <editor-content> isn’t rendered yet
549
+ if (!props.editor.contentComponent) {
550
+ return {};
551
+ }
552
+ return new ReactNodeView(component, props, options);
553
+ };
559
554
  }
560
555
 
561
556
  exports.BubbleMenu = BubbleMenu;
@@ -575,13 +570,11 @@
575
570
  exports.useEditor = useEditor;
576
571
  exports.useReactNodeView = useReactNodeView;
577
572
  Object.keys(core).forEach(function (k) {
578
- if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
573
+ if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
579
574
  enumerable: true,
580
575
  get: function () { return core[k]; }
581
576
  });
582
577
  });
583
578
 
584
- Object.defineProperty(exports, '__esModule', { value: true });
585
-
586
579
  }));
587
580
  //# sourceMappingURL=index.umd.js.map