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