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