@tiptap/react 3.0.0-next.4 → 3.0.0-next.6
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.
- package/LICENSE.md +1 -1
- package/dist/index.cjs +178 -160
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +35 -22
- package/dist/index.d.ts +35 -22
- package/dist/index.js +147 -131
- package/dist/index.js.map +1 -1
- package/dist/menus/index.cjs +142 -0
- package/dist/menus/index.cjs.map +1 -0
- package/dist/menus/index.d.cts +19 -0
- package/dist/menus/index.d.ts +19 -0
- package/dist/menus/index.js +104 -0
- package/dist/menus/index.js.map +1 -0
- package/package.json +17 -7
- package/src/EditorContent.tsx +2 -1
- package/src/ReactMarkViewRenderer.tsx +108 -0
- package/src/ReactNodeViewRenderer.tsx +1 -1
- package/src/index.ts +1 -2
- package/src/{BubbleMenu.tsx → menus/BubbleMenu.tsx} +2 -3
- package/src/{FloatingMenu.tsx → menus/FloatingMenu.tsx} +2 -3
- package/src/menus/index.ts +2 -0
- package/src/useEditor.ts +51 -6
package/LICENSE.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -31,15 +31,17 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
// src/index.ts
|
|
32
32
|
var index_exports = {};
|
|
33
33
|
__export(index_exports, {
|
|
34
|
-
BubbleMenu: () => BubbleMenu,
|
|
35
34
|
EditorConsumer: () => EditorConsumer,
|
|
36
35
|
EditorContent: () => EditorContent,
|
|
37
36
|
EditorContext: () => EditorContext,
|
|
38
37
|
EditorProvider: () => EditorProvider,
|
|
39
|
-
|
|
38
|
+
MarkViewContent: () => MarkViewContent,
|
|
40
39
|
NodeViewContent: () => NodeViewContent,
|
|
41
40
|
NodeViewWrapper: () => NodeViewWrapper,
|
|
42
41
|
PureEditorContent: () => PureEditorContent,
|
|
42
|
+
ReactMarkView: () => ReactMarkView,
|
|
43
|
+
ReactMarkViewContext: () => ReactMarkViewContext,
|
|
44
|
+
ReactMarkViewRenderer: () => ReactMarkViewRenderer,
|
|
43
45
|
ReactNodeView: () => ReactNodeView,
|
|
44
46
|
ReactNodeViewContentProvider: () => ReactNodeViewContentProvider,
|
|
45
47
|
ReactNodeViewContext: () => ReactNodeViewContext,
|
|
@@ -52,18 +54,14 @@ __export(index_exports, {
|
|
|
52
54
|
});
|
|
53
55
|
module.exports = __toCommonJS(index_exports);
|
|
54
56
|
|
|
55
|
-
// src/BubbleMenu.tsx
|
|
56
|
-
var import_extension_bubble_menu = require("@tiptap/extension-bubble-menu");
|
|
57
|
-
var import_react6 = __toESM(require("react"), 1);
|
|
58
|
-
var import_react_dom2 = require("react-dom");
|
|
59
|
-
|
|
60
57
|
// src/Context.tsx
|
|
61
|
-
var import_react5 =
|
|
58
|
+
var import_react5 = require("react");
|
|
62
59
|
|
|
63
60
|
// src/EditorContent.tsx
|
|
64
61
|
var import_react = __toESM(require("react"), 1);
|
|
65
62
|
var import_react_dom = __toESM(require("react-dom"), 1);
|
|
66
63
|
var import_shim = require("use-sync-external-store/shim");
|
|
64
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
67
65
|
var mergeRefs = (...refs) => {
|
|
68
66
|
return (node) => {
|
|
69
67
|
refs.forEach((ref) => {
|
|
@@ -82,7 +80,7 @@ var Portals = ({ contentComponent }) => {
|
|
|
82
80
|
contentComponent.getSnapshot,
|
|
83
81
|
contentComponent.getServerSnapshot
|
|
84
82
|
);
|
|
85
|
-
return /* @__PURE__ */
|
|
83
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: Object.values(renderers) });
|
|
86
84
|
};
|
|
87
85
|
function getInstance() {
|
|
88
86
|
const subscribers = /* @__PURE__ */ new Set();
|
|
@@ -172,6 +170,7 @@ var PureEditorContent = class extends import_react.default.Component {
|
|
|
172
170
|
}
|
|
173
171
|
}
|
|
174
172
|
componentWillUnmount() {
|
|
173
|
+
var _a;
|
|
175
174
|
const editor = this.props.editor;
|
|
176
175
|
if (!editor) {
|
|
177
176
|
return;
|
|
@@ -186,7 +185,7 @@ var PureEditorContent = class extends import_react.default.Component {
|
|
|
186
185
|
this.unsubscribeToContentComponent();
|
|
187
186
|
}
|
|
188
187
|
editor.contentComponent = null;
|
|
189
|
-
if (!editor.options.element.firstChild) {
|
|
188
|
+
if (!((_a = editor.options.element) == null ? void 0 : _a.firstChild)) {
|
|
190
189
|
return;
|
|
191
190
|
}
|
|
192
191
|
const newElement = document.createElement("div");
|
|
@@ -197,7 +196,10 @@ var PureEditorContent = class extends import_react.default.Component {
|
|
|
197
196
|
}
|
|
198
197
|
render() {
|
|
199
198
|
const { editor, innerRef, ...rest } = this.props;
|
|
200
|
-
return /* @__PURE__ */
|
|
199
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
200
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { ref: mergeRefs(innerRef, this.editorContentRef), ...rest }),
|
|
201
|
+
(editor == null ? void 0 : editor.contentComponent) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Portals, { contentComponent: editor.contentComponent })
|
|
202
|
+
] });
|
|
201
203
|
}
|
|
202
204
|
};
|
|
203
205
|
var EditorContentWithKey = (0, import_react.forwardRef)(
|
|
@@ -302,7 +304,7 @@ function useEditorState(options) {
|
|
|
302
304
|
var isDev = process.env.NODE_ENV !== "production";
|
|
303
305
|
var isSSR = typeof window === "undefined";
|
|
304
306
|
var isNext = isSSR || Boolean(typeof window !== "undefined" && window.next);
|
|
305
|
-
var EditorInstanceManager = class {
|
|
307
|
+
var EditorInstanceManager = class _EditorInstanceManager {
|
|
306
308
|
constructor(options) {
|
|
307
309
|
/**
|
|
308
310
|
* The current editor instance.
|
|
@@ -414,6 +416,10 @@ var EditorInstanceManager = class {
|
|
|
414
416
|
onPaste: (...args) => {
|
|
415
417
|
var _a, _b;
|
|
416
418
|
return (_b = (_a = this.options.current).onPaste) == null ? void 0 : _b.call(_a, ...args);
|
|
419
|
+
},
|
|
420
|
+
onDelete: (...args) => {
|
|
421
|
+
var _a, _b;
|
|
422
|
+
return (_b = (_a = this.options.current).onDelete) == null ? void 0 : _b.call(_a, ...args);
|
|
417
423
|
}
|
|
418
424
|
};
|
|
419
425
|
const editor = new import_core.Editor(optionsToApply);
|
|
@@ -440,6 +446,41 @@ var EditorInstanceManager = class {
|
|
|
440
446
|
this.subscriptions.delete(onStoreChange);
|
|
441
447
|
};
|
|
442
448
|
}
|
|
449
|
+
static compareOptions(a, b) {
|
|
450
|
+
return Object.keys(a).every((key) => {
|
|
451
|
+
if ([
|
|
452
|
+
"onCreate",
|
|
453
|
+
"onBeforeCreate",
|
|
454
|
+
"onDestroy",
|
|
455
|
+
"onUpdate",
|
|
456
|
+
"onTransaction",
|
|
457
|
+
"onFocus",
|
|
458
|
+
"onBlur",
|
|
459
|
+
"onSelectionUpdate",
|
|
460
|
+
"onContentError",
|
|
461
|
+
"onDrop",
|
|
462
|
+
"onPaste"
|
|
463
|
+
].includes(key)) {
|
|
464
|
+
return true;
|
|
465
|
+
}
|
|
466
|
+
if (key === "extensions" && a.extensions && b.extensions) {
|
|
467
|
+
if (a.extensions.length !== b.extensions.length) {
|
|
468
|
+
return false;
|
|
469
|
+
}
|
|
470
|
+
return a.extensions.every((extension, index) => {
|
|
471
|
+
var _a;
|
|
472
|
+
if (extension !== ((_a = b.extensions) == null ? void 0 : _a[index])) {
|
|
473
|
+
return false;
|
|
474
|
+
}
|
|
475
|
+
return true;
|
|
476
|
+
});
|
|
477
|
+
}
|
|
478
|
+
if (a[key] !== b[key]) {
|
|
479
|
+
return false;
|
|
480
|
+
}
|
|
481
|
+
return true;
|
|
482
|
+
});
|
|
483
|
+
}
|
|
443
484
|
/**
|
|
444
485
|
* On each render, we will create, update, or destroy the editor instance.
|
|
445
486
|
* @param deps The dependencies to watch for changes
|
|
@@ -450,10 +491,12 @@ var EditorInstanceManager = class {
|
|
|
450
491
|
this.isComponentMounted = true;
|
|
451
492
|
clearTimeout(this.scheduledDestructionTimeout);
|
|
452
493
|
if (this.editor && !this.editor.isDestroyed && deps.length === 0) {
|
|
453
|
-
this.editor.
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
494
|
+
if (!_EditorInstanceManager.compareOptions(this.options.current, this.editor.options)) {
|
|
495
|
+
this.editor.setOptions({
|
|
496
|
+
...this.options.current,
|
|
497
|
+
editable: this.editor.isEditable
|
|
498
|
+
});
|
|
499
|
+
}
|
|
457
500
|
} else {
|
|
458
501
|
this.refreshEditorInstance(deps);
|
|
459
502
|
}
|
|
@@ -534,6 +577,7 @@ function useEditor(options = {}, deps = []) {
|
|
|
534
577
|
}
|
|
535
578
|
|
|
536
579
|
// src/Context.tsx
|
|
580
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
537
581
|
var EditorContext = (0, import_react5.createContext)({
|
|
538
582
|
editor: null
|
|
539
583
|
});
|
|
@@ -551,108 +595,17 @@ function EditorProvider({
|
|
|
551
595
|
if (!editor) {
|
|
552
596
|
return null;
|
|
553
597
|
}
|
|
554
|
-
return /* @__PURE__ */
|
|
598
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(EditorContext.Provider, { value: contextValue, children: [
|
|
599
|
+
slotBefore,
|
|
600
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(EditorConsumer, { children: ({ editor: currentEditor }) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(EditorContent, { editor: currentEditor, ...editorContainerProps }) }),
|
|
601
|
+
children,
|
|
602
|
+
slotAfter
|
|
603
|
+
] });
|
|
555
604
|
}
|
|
556
605
|
|
|
557
|
-
// src/BubbleMenu.tsx
|
|
558
|
-
var BubbleMenu = import_react6.default.forwardRef(
|
|
559
|
-
({ pluginKey = "bubbleMenu", editor, updateDelay, resizeDelay, shouldShow = null, options, children, ...restProps }, ref) => {
|
|
560
|
-
const menuEl = (0, import_react6.useRef)(document.createElement("div"));
|
|
561
|
-
if (typeof ref === "function") {
|
|
562
|
-
ref(menuEl.current);
|
|
563
|
-
} else if (ref) {
|
|
564
|
-
ref.current = menuEl.current;
|
|
565
|
-
}
|
|
566
|
-
const { editor: currentEditor } = useCurrentEditor();
|
|
567
|
-
(0, import_react6.useEffect)(() => {
|
|
568
|
-
const bubbleMenuElement = menuEl.current;
|
|
569
|
-
bubbleMenuElement.style.visibility = "hidden";
|
|
570
|
-
bubbleMenuElement.style.position = "absolute";
|
|
571
|
-
if ((editor == null ? void 0 : editor.isDestroyed) || (currentEditor == null ? void 0 : currentEditor.isDestroyed)) {
|
|
572
|
-
return;
|
|
573
|
-
}
|
|
574
|
-
const attachToEditor = editor || currentEditor;
|
|
575
|
-
if (!attachToEditor) {
|
|
576
|
-
console.warn("BubbleMenu component is not rendered inside of an editor component or does not have editor prop.");
|
|
577
|
-
return;
|
|
578
|
-
}
|
|
579
|
-
const plugin = (0, import_extension_bubble_menu.BubbleMenuPlugin)({
|
|
580
|
-
updateDelay,
|
|
581
|
-
resizeDelay,
|
|
582
|
-
editor: attachToEditor,
|
|
583
|
-
element: bubbleMenuElement,
|
|
584
|
-
pluginKey,
|
|
585
|
-
shouldShow,
|
|
586
|
-
options
|
|
587
|
-
});
|
|
588
|
-
attachToEditor.registerPlugin(plugin);
|
|
589
|
-
return () => {
|
|
590
|
-
attachToEditor.unregisterPlugin(pluginKey);
|
|
591
|
-
window.requestAnimationFrame(() => {
|
|
592
|
-
if (bubbleMenuElement.parentNode) {
|
|
593
|
-
bubbleMenuElement.parentNode.removeChild(bubbleMenuElement);
|
|
594
|
-
}
|
|
595
|
-
});
|
|
596
|
-
};
|
|
597
|
-
}, [editor, currentEditor]);
|
|
598
|
-
return (0, import_react_dom2.createPortal)(/* @__PURE__ */ import_react6.default.createElement("div", { ...restProps }, children), menuEl.current);
|
|
599
|
-
}
|
|
600
|
-
);
|
|
601
|
-
|
|
602
|
-
// src/FloatingMenu.tsx
|
|
603
|
-
var import_extension_floating_menu = require("@tiptap/extension-floating-menu");
|
|
604
|
-
var import_react7 = __toESM(require("react"), 1);
|
|
605
|
-
var import_react_dom3 = require("react-dom");
|
|
606
|
-
var FloatingMenu = import_react7.default.forwardRef(
|
|
607
|
-
({ pluginKey = "floatingMenu", editor, shouldShow = null, options, children, ...restProps }, ref) => {
|
|
608
|
-
const menuEl = (0, import_react7.useRef)(document.createElement("div"));
|
|
609
|
-
if (typeof ref === "function") {
|
|
610
|
-
ref(menuEl.current);
|
|
611
|
-
} else if (ref) {
|
|
612
|
-
ref.current = menuEl.current;
|
|
613
|
-
}
|
|
614
|
-
const { editor: currentEditor } = useCurrentEditor();
|
|
615
|
-
(0, import_react7.useEffect)(() => {
|
|
616
|
-
const floatingMenuElement = menuEl.current;
|
|
617
|
-
floatingMenuElement.style.visibility = "hidden";
|
|
618
|
-
floatingMenuElement.style.position = "absolute";
|
|
619
|
-
if ((editor == null ? void 0 : editor.isDestroyed) || (currentEditor == null ? void 0 : currentEditor.isDestroyed)) {
|
|
620
|
-
return;
|
|
621
|
-
}
|
|
622
|
-
const attachToEditor = editor || currentEditor;
|
|
623
|
-
if (!attachToEditor) {
|
|
624
|
-
console.warn(
|
|
625
|
-
"FloatingMenu component is not rendered inside of an editor component or does not have editor prop."
|
|
626
|
-
);
|
|
627
|
-
return;
|
|
628
|
-
}
|
|
629
|
-
const plugin = (0, import_extension_floating_menu.FloatingMenuPlugin)({
|
|
630
|
-
editor: attachToEditor,
|
|
631
|
-
element: floatingMenuElement,
|
|
632
|
-
pluginKey,
|
|
633
|
-
shouldShow,
|
|
634
|
-
options
|
|
635
|
-
});
|
|
636
|
-
attachToEditor.registerPlugin(plugin);
|
|
637
|
-
return () => {
|
|
638
|
-
attachToEditor.unregisterPlugin(pluginKey);
|
|
639
|
-
window.requestAnimationFrame(() => {
|
|
640
|
-
if (floatingMenuElement.parentNode) {
|
|
641
|
-
floatingMenuElement.parentNode.removeChild(floatingMenuElement);
|
|
642
|
-
}
|
|
643
|
-
});
|
|
644
|
-
};
|
|
645
|
-
}, [editor, currentEditor]);
|
|
646
|
-
return (0, import_react_dom3.createPortal)(/* @__PURE__ */ import_react7.default.createElement("div", { ...restProps }, children), menuEl.current);
|
|
647
|
-
}
|
|
648
|
-
);
|
|
649
|
-
|
|
650
|
-
// src/NodeViewContent.tsx
|
|
651
|
-
var import_react9 = __toESM(require("react"), 1);
|
|
652
|
-
|
|
653
606
|
// src/useReactNodeView.ts
|
|
654
|
-
var
|
|
655
|
-
var ReactNodeViewContext = (0,
|
|
607
|
+
var import_react6 = require("react");
|
|
608
|
+
var ReactNodeViewContext = (0, import_react6.createContext)({
|
|
656
609
|
onDragStart: () => {
|
|
657
610
|
},
|
|
658
611
|
nodeViewContentChildren: void 0,
|
|
@@ -660,64 +613,66 @@ var ReactNodeViewContext = (0, import_react8.createContext)({
|
|
|
660
613
|
}
|
|
661
614
|
});
|
|
662
615
|
var ReactNodeViewContentProvider = ({ children, content }) => {
|
|
663
|
-
return (0,
|
|
616
|
+
return (0, import_react6.createElement)(ReactNodeViewContext.Provider, { value: { nodeViewContentChildren: content } }, children);
|
|
664
617
|
};
|
|
665
|
-
var useReactNodeView = () => (0,
|
|
618
|
+
var useReactNodeView = () => (0, import_react6.useContext)(ReactNodeViewContext);
|
|
666
619
|
|
|
667
620
|
// src/NodeViewContent.tsx
|
|
621
|
+
var import_jsx_runtime3 = (
|
|
622
|
+
// @ts-ignore
|
|
623
|
+
require("react/jsx-runtime")
|
|
624
|
+
);
|
|
668
625
|
function NodeViewContent({
|
|
669
626
|
as: Tag = "div",
|
|
670
627
|
...props
|
|
671
628
|
}) {
|
|
672
629
|
const { nodeViewContentRef, nodeViewContentChildren } = useReactNodeView();
|
|
673
|
-
return (
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
style
|
|
682
|
-
whiteSpace: "pre-wrap",
|
|
683
|
-
...props.style
|
|
684
|
-
}
|
|
630
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
631
|
+
Tag,
|
|
632
|
+
{
|
|
633
|
+
...props,
|
|
634
|
+
ref: nodeViewContentRef,
|
|
635
|
+
"data-node-view-content": "",
|
|
636
|
+
style: {
|
|
637
|
+
whiteSpace: "pre-wrap",
|
|
638
|
+
...props.style
|
|
685
639
|
},
|
|
686
|
-
nodeViewContentChildren
|
|
687
|
-
|
|
640
|
+
children: nodeViewContentChildren
|
|
641
|
+
}
|
|
688
642
|
);
|
|
689
643
|
}
|
|
690
644
|
|
|
691
645
|
// src/NodeViewWrapper.tsx
|
|
692
|
-
var
|
|
693
|
-
var
|
|
646
|
+
var import_react7 = __toESM(require("react"), 1);
|
|
647
|
+
var import_jsx_runtime4 = (
|
|
648
|
+
// @ts-ignore
|
|
649
|
+
require("react/jsx-runtime")
|
|
650
|
+
);
|
|
651
|
+
var NodeViewWrapper = import_react7.default.forwardRef((props, ref) => {
|
|
694
652
|
const { onDragStart } = useReactNodeView();
|
|
695
653
|
const Tag = props.as || "div";
|
|
696
|
-
return (
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
style
|
|
706
|
-
whiteSpace: "normal",
|
|
707
|
-
...props.style
|
|
708
|
-
}
|
|
654
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
655
|
+
Tag,
|
|
656
|
+
{
|
|
657
|
+
...props,
|
|
658
|
+
ref,
|
|
659
|
+
"data-node-view-wrapper": "",
|
|
660
|
+
onDragStart,
|
|
661
|
+
style: {
|
|
662
|
+
whiteSpace: "normal",
|
|
663
|
+
...props.style
|
|
709
664
|
}
|
|
710
|
-
|
|
665
|
+
}
|
|
711
666
|
);
|
|
712
667
|
});
|
|
713
668
|
|
|
714
|
-
// src/
|
|
669
|
+
// src/ReactMarkViewRenderer.tsx
|
|
715
670
|
var import_core2 = require("@tiptap/core");
|
|
716
|
-
var
|
|
671
|
+
var import_react8 = __toESM(require("react"), 1);
|
|
717
672
|
|
|
718
673
|
// src/ReactRenderer.tsx
|
|
719
|
-
var
|
|
720
|
-
var
|
|
674
|
+
var import_react_dom2 = require("react-dom");
|
|
675
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
721
676
|
function isClassComponent(Component) {
|
|
722
677
|
return !!(typeof Component === "function" && Component.prototype && Component.prototype.isReactComponent);
|
|
723
678
|
}
|
|
@@ -741,7 +696,7 @@ var ReactRenderer = class {
|
|
|
741
696
|
this.element.classList.add(...className.split(" "));
|
|
742
697
|
}
|
|
743
698
|
if (this.editor.isInitialized) {
|
|
744
|
-
(0,
|
|
699
|
+
(0, import_react_dom2.flushSync)(() => {
|
|
745
700
|
this.render();
|
|
746
701
|
});
|
|
747
702
|
} else {
|
|
@@ -761,7 +716,7 @@ var ReactRenderer = class {
|
|
|
761
716
|
this.ref = ref;
|
|
762
717
|
};
|
|
763
718
|
}
|
|
764
|
-
this.reactElement = /* @__PURE__ */
|
|
719
|
+
this.reactElement = /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Component, { ...props });
|
|
765
720
|
(_a = editor == null ? void 0 : editor.contentComponent) == null ? void 0 : _a.setRenderer(this.id, this);
|
|
766
721
|
}
|
|
767
722
|
/**
|
|
@@ -792,8 +747,69 @@ var ReactRenderer = class {
|
|
|
792
747
|
}
|
|
793
748
|
};
|
|
794
749
|
|
|
750
|
+
// src/ReactMarkViewRenderer.tsx
|
|
751
|
+
var import_jsx_runtime6 = (
|
|
752
|
+
// @ts-ignore
|
|
753
|
+
require("react/jsx-runtime")
|
|
754
|
+
);
|
|
755
|
+
var ReactMarkViewContext = import_react8.default.createContext({
|
|
756
|
+
markViewContentRef: () => {
|
|
757
|
+
}
|
|
758
|
+
});
|
|
759
|
+
var MarkViewContent = (props) => {
|
|
760
|
+
const Tag = props.as || "span";
|
|
761
|
+
const { markViewContentRef } = import_react8.default.useContext(ReactMarkViewContext);
|
|
762
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Tag, { ...props, ref: markViewContentRef, "data-mark-view-content": "" });
|
|
763
|
+
};
|
|
764
|
+
var ReactMarkView = class extends import_core2.MarkView {
|
|
765
|
+
constructor(component, props, options) {
|
|
766
|
+
super(component, props, options);
|
|
767
|
+
this.didMountContentDomElement = false;
|
|
768
|
+
const { as = "span", attrs, className = "" } = options || {};
|
|
769
|
+
const componentProps = props;
|
|
770
|
+
this.contentDOMElement = document.createElement("span");
|
|
771
|
+
const markViewContentRef = (el) => {
|
|
772
|
+
if (el && this.contentDOMElement && el.firstChild !== this.contentDOMElement) {
|
|
773
|
+
el.appendChild(this.contentDOMElement);
|
|
774
|
+
this.didMountContentDomElement = true;
|
|
775
|
+
}
|
|
776
|
+
};
|
|
777
|
+
const context = {
|
|
778
|
+
markViewContentRef
|
|
779
|
+
};
|
|
780
|
+
const ReactMarkViewProvider = import_react8.default.memo((componentProps2) => {
|
|
781
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ReactMarkViewContext.Provider, { value: context, children: import_react8.default.createElement(component, componentProps2) });
|
|
782
|
+
});
|
|
783
|
+
ReactMarkViewProvider.displayName = "ReactNodeView";
|
|
784
|
+
this.renderer = new ReactRenderer(ReactMarkViewProvider, {
|
|
785
|
+
editor: props.editor,
|
|
786
|
+
props: componentProps,
|
|
787
|
+
as,
|
|
788
|
+
className: `mark-${props.mark.type.name} ${className}`.trim()
|
|
789
|
+
});
|
|
790
|
+
if (attrs) {
|
|
791
|
+
this.renderer.updateAttributes(attrs);
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
get dom() {
|
|
795
|
+
return this.renderer.element;
|
|
796
|
+
}
|
|
797
|
+
get contentDOM() {
|
|
798
|
+
if (!this.didMountContentDomElement) {
|
|
799
|
+
return null;
|
|
800
|
+
}
|
|
801
|
+
return this.contentDOMElement;
|
|
802
|
+
}
|
|
803
|
+
};
|
|
804
|
+
function ReactMarkViewRenderer(component, options = {}) {
|
|
805
|
+
return (props) => new ReactMarkView(component, props, options);
|
|
806
|
+
}
|
|
807
|
+
|
|
795
808
|
// src/ReactNodeViewRenderer.tsx
|
|
796
|
-
var
|
|
809
|
+
var import_core3 = require("@tiptap/core");
|
|
810
|
+
var import_react9 = __toESM(require("react"), 1);
|
|
811
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
812
|
+
var ReactNodeView = class extends import_core3.NodeView {
|
|
797
813
|
/**
|
|
798
814
|
* Setup the React component.
|
|
799
815
|
* Called on initialization.
|
|
@@ -826,8 +842,8 @@ var ReactNodeView = class extends import_core2.NodeView {
|
|
|
826
842
|
};
|
|
827
843
|
const context = { onDragStart, nodeViewContentRef };
|
|
828
844
|
const Component = this.component;
|
|
829
|
-
const ReactNodeViewProvider =
|
|
830
|
-
return /* @__PURE__ */
|
|
845
|
+
const ReactNodeViewProvider = import_react9.default.memo((componentProps) => {
|
|
846
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ReactNodeViewContext.Provider, { value: context, children: import_react9.default.createElement(Component, componentProps) });
|
|
831
847
|
});
|
|
832
848
|
ReactNodeViewProvider.displayName = "ReactNodeView";
|
|
833
849
|
if (this.node.isLeaf) {
|
|
@@ -847,13 +863,13 @@ var ReactNodeView = class extends import_core2.NodeView {
|
|
|
847
863
|
}
|
|
848
864
|
const { className = "" } = this.options;
|
|
849
865
|
this.handleSelectionUpdate = this.handleSelectionUpdate.bind(this);
|
|
850
|
-
this.editor.on("selectionUpdate", this.handleSelectionUpdate);
|
|
851
866
|
this.renderer = new ReactRenderer(ReactNodeViewProvider, {
|
|
852
867
|
editor: this.editor,
|
|
853
868
|
props,
|
|
854
869
|
as,
|
|
855
870
|
className: `node-${this.node.type.name} ${className}`.trim()
|
|
856
871
|
});
|
|
872
|
+
this.editor.on("selectionUpdate", this.handleSelectionUpdate);
|
|
857
873
|
this.updateElementAttributes();
|
|
858
874
|
}
|
|
859
875
|
/**
|
|
@@ -976,7 +992,7 @@ var ReactNodeView = class extends import_core2.NodeView {
|
|
|
976
992
|
let attrsObj = {};
|
|
977
993
|
if (typeof this.options.attrs === "function") {
|
|
978
994
|
const extensionAttributes = this.editor.extensionManager.attributes;
|
|
979
|
-
const HTMLAttributes2 = (0,
|
|
995
|
+
const HTMLAttributes2 = (0, import_core3.getRenderedAttributes)(this.node, extensionAttributes);
|
|
980
996
|
attrsObj = this.options.attrs({ node: this.node, HTMLAttributes: HTMLAttributes2 });
|
|
981
997
|
} else {
|
|
982
998
|
attrsObj = this.options.attrs;
|
|
@@ -998,15 +1014,17 @@ function ReactNodeViewRenderer(component, options) {
|
|
|
998
1014
|
__reExport(index_exports, require("@tiptap/core"), module.exports);
|
|
999
1015
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1000
1016
|
0 && (module.exports = {
|
|
1001
|
-
BubbleMenu,
|
|
1002
1017
|
EditorConsumer,
|
|
1003
1018
|
EditorContent,
|
|
1004
1019
|
EditorContext,
|
|
1005
1020
|
EditorProvider,
|
|
1006
|
-
|
|
1021
|
+
MarkViewContent,
|
|
1007
1022
|
NodeViewContent,
|
|
1008
1023
|
NodeViewWrapper,
|
|
1009
1024
|
PureEditorContent,
|
|
1025
|
+
ReactMarkView,
|
|
1026
|
+
ReactMarkViewContext,
|
|
1027
|
+
ReactMarkViewRenderer,
|
|
1010
1028
|
ReactNodeView,
|
|
1011
1029
|
ReactNodeViewContentProvider,
|
|
1012
1030
|
ReactNodeViewContext,
|