@tiptap/react 2.11.7 → 3.0.0-beta.1

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