@tiptap/react 2.0.0-beta.213 → 2.0.0-beta.214
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 +391 -422
- package/dist/index.cjs.map +1 -0
- package/dist/index.js +366 -420
- package/dist/index.js.map +1 -0
- package/dist/index.umd.js +406 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/packages/react/src/BubbleMenu.d.ts +10 -0
- package/dist/packages/react/src/Editor.d.ts +12 -0
- package/dist/packages/react/src/EditorContent.d.ts +23 -0
- package/dist/packages/react/src/FloatingMenu.d.ts +9 -0
- package/dist/packages/react/src/NodeViewContent.d.ts +6 -0
- package/dist/packages/react/src/NodeViewWrapper.d.ts +6 -0
- package/dist/packages/react/src/ReactNodeViewRenderer.d.ts +15 -0
- package/dist/packages/react/src/ReactRenderer.d.ts +24 -0
- package/dist/packages/react/src/index.d.ts +10 -0
- package/dist/packages/react/src/useEditor.d.ts +4 -0
- package/dist/packages/react/src/useReactNodeView.d.ts +7 -0
- package/package.json +10 -19
- package/dist/index.d.ts +0 -101
package/dist/index.cjs
CHANGED
|
@@ -1,437 +1,406 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var extensionBubbleMenu = require('@tiptap/extension-bubble-menu');
|
|
6
|
+
var React = require('react');
|
|
7
|
+
var core = require('@tiptap/core');
|
|
8
|
+
var ReactDOM = require('react-dom');
|
|
9
|
+
var extensionFloatingMenu = require('@tiptap/extension-floating-menu');
|
|
10
|
+
|
|
11
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
12
|
+
|
|
13
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
14
|
+
var ReactDOM__default = /*#__PURE__*/_interopDefaultLegacy(ReactDOM);
|
|
15
|
+
|
|
16
|
+
const BubbleMenu = (props) => {
|
|
17
|
+
const [element, setElement] = React.useState(null);
|
|
18
|
+
React.useEffect(() => {
|
|
19
|
+
if (!element) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (props.editor.isDestroyed) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const { pluginKey = 'bubbleMenu', editor, tippyOptions = {}, updateDelay, shouldShow = null, } = props;
|
|
26
|
+
const plugin = extensionBubbleMenu.BubbleMenuPlugin({
|
|
27
|
+
updateDelay,
|
|
28
|
+
editor,
|
|
29
|
+
element,
|
|
30
|
+
pluginKey,
|
|
31
|
+
shouldShow,
|
|
32
|
+
tippyOptions,
|
|
33
|
+
});
|
|
34
|
+
editor.registerPlugin(plugin);
|
|
35
|
+
return () => editor.unregisterPlugin(pluginKey);
|
|
36
|
+
}, [props.editor, element]);
|
|
37
|
+
return (React__default["default"].createElement("div", { ref: setElement, className: props.className, style: { visibility: 'hidden' } }, props.children));
|
|
32
38
|
};
|
|
33
39
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
// src/EditorContent.tsx
|
|
44
|
-
|
|
45
|
-
var _reactdom = require('react-dom'); var _reactdom2 = _interopRequireDefault(_reactdom);
|
|
46
|
-
var Portals = ({ renderers }) => {
|
|
47
|
-
return /* @__PURE__ */ _react2.default.createElement(_react2.default.Fragment, null, Object.entries(renderers).map(([key, renderer]) => {
|
|
48
|
-
return _reactdom2.default.createPortal(
|
|
49
|
-
renderer.reactElement,
|
|
50
|
-
renderer.element,
|
|
51
|
-
key
|
|
52
|
-
);
|
|
53
|
-
}));
|
|
54
|
-
};
|
|
55
|
-
var PureEditorContent = class extends _react2.default.Component {
|
|
56
|
-
constructor(props) {
|
|
57
|
-
super(props);
|
|
58
|
-
this.editorContentRef = _react2.default.createRef();
|
|
59
|
-
this.initialized = false;
|
|
60
|
-
this.state = {
|
|
61
|
-
renderers: {}
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
componentDidMount() {
|
|
65
|
-
this.init();
|
|
66
|
-
}
|
|
67
|
-
componentDidUpdate() {
|
|
68
|
-
this.init();
|
|
69
|
-
}
|
|
70
|
-
init() {
|
|
71
|
-
const { editor } = this.props;
|
|
72
|
-
if (editor && editor.options.element) {
|
|
73
|
-
if (editor.contentComponent) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
const element = this.editorContentRef.current;
|
|
77
|
-
element.append(...editor.options.element.childNodes);
|
|
78
|
-
editor.setOptions({
|
|
79
|
-
element
|
|
80
|
-
});
|
|
81
|
-
editor.contentComponent = this;
|
|
82
|
-
editor.createNodeViews();
|
|
83
|
-
this.initialized = true;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
maybeFlushSync(fn) {
|
|
87
|
-
if (this.initialized) {
|
|
88
|
-
_reactdom.flushSync.call(void 0, fn);
|
|
89
|
-
} else {
|
|
90
|
-
fn();
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
setRenderer(id, renderer) {
|
|
94
|
-
this.maybeFlushSync(() => {
|
|
95
|
-
this.setState(({ renderers }) => ({
|
|
96
|
-
renderers: {
|
|
97
|
-
...renderers,
|
|
98
|
-
[id]: renderer
|
|
99
|
-
}
|
|
100
|
-
}));
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
removeRenderer(id) {
|
|
104
|
-
this.maybeFlushSync(() => {
|
|
105
|
-
this.setState(({ renderers }) => {
|
|
106
|
-
const nextRenderers = { ...renderers };
|
|
107
|
-
delete nextRenderers[id];
|
|
108
|
-
return { renderers: nextRenderers };
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
componentWillUnmount() {
|
|
113
|
-
const { editor } = this.props;
|
|
114
|
-
if (!editor) {
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
if (!editor.isDestroyed) {
|
|
118
|
-
editor.view.setProps({
|
|
119
|
-
nodeViews: {}
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
editor.contentComponent = null;
|
|
123
|
-
if (!editor.options.element.firstChild) {
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
const newElement = document.createElement("div");
|
|
127
|
-
newElement.append(...editor.options.element.childNodes);
|
|
128
|
-
editor.setOptions({
|
|
129
|
-
element: newElement
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
render() {
|
|
133
|
-
const { editor, ...rest } = this.props;
|
|
134
|
-
return /* @__PURE__ */ _react2.default.createElement(_react2.default.Fragment, null, /* @__PURE__ */ _react2.default.createElement("div", { ref: this.editorContentRef, ...rest }), /* @__PURE__ */ _react2.default.createElement(Portals, { renderers: this.state.renderers }));
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
var EditorContent = _react2.default.memo(PureEditorContent);
|
|
138
|
-
|
|
139
|
-
// src/FloatingMenu.tsx
|
|
140
|
-
var _extensionfloatingmenu = require('@tiptap/extension-floating-menu');
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
40
|
+
class Editor extends core.Editor {
|
|
41
|
+
constructor() {
|
|
42
|
+
super(...arguments);
|
|
43
|
+
this.contentComponent = null;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
144
46
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
47
|
+
const Portals = ({ renderers }) => {
|
|
48
|
+
return (React__default["default"].createElement(React__default["default"].Fragment, null, Object.entries(renderers).map(([key, renderer]) => {
|
|
49
|
+
return ReactDOM__default["default"].createPortal(renderer.reactElement, renderer.element, key);
|
|
50
|
+
})));
|
|
51
|
+
};
|
|
52
|
+
class PureEditorContent extends React__default["default"].Component {
|
|
53
|
+
constructor(props) {
|
|
54
|
+
super(props);
|
|
55
|
+
this.editorContentRef = React__default["default"].createRef();
|
|
56
|
+
this.initialized = false;
|
|
57
|
+
this.state = {
|
|
58
|
+
renderers: {},
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
componentDidMount() {
|
|
62
|
+
this.init();
|
|
63
|
+
}
|
|
64
|
+
componentDidUpdate() {
|
|
65
|
+
this.init();
|
|
66
|
+
}
|
|
67
|
+
init() {
|
|
68
|
+
const { editor } = this.props;
|
|
69
|
+
if (editor && editor.options.element) {
|
|
70
|
+
if (editor.contentComponent) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const element = this.editorContentRef.current;
|
|
74
|
+
element.append(...editor.options.element.childNodes);
|
|
75
|
+
editor.setOptions({
|
|
76
|
+
element,
|
|
77
|
+
});
|
|
78
|
+
editor.contentComponent = this;
|
|
79
|
+
editor.createNodeViews();
|
|
80
|
+
this.initialized = true;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
maybeFlushSync(fn) {
|
|
84
|
+
// Avoid calling flushSync until the editor is initialized.
|
|
85
|
+
// Initialization happens during the componentDidMount or componentDidUpdate
|
|
86
|
+
// lifecycle methods, and React doesn't allow calling flushSync from inside
|
|
87
|
+
// a lifecycle method.
|
|
88
|
+
if (this.initialized) {
|
|
89
|
+
ReactDOM.flushSync(fn);
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
fn();
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
setRenderer(id, renderer) {
|
|
96
|
+
this.maybeFlushSync(() => {
|
|
97
|
+
this.setState(({ renderers }) => ({
|
|
98
|
+
renderers: {
|
|
99
|
+
...renderers,
|
|
100
|
+
[id]: renderer,
|
|
101
|
+
},
|
|
102
|
+
}));
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
removeRenderer(id) {
|
|
106
|
+
this.maybeFlushSync(() => {
|
|
107
|
+
this.setState(({ renderers }) => {
|
|
108
|
+
const nextRenderers = { ...renderers };
|
|
109
|
+
delete nextRenderers[id];
|
|
110
|
+
return { renderers: nextRenderers };
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
componentWillUnmount() {
|
|
115
|
+
const { editor } = this.props;
|
|
116
|
+
if (!editor) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
if (!editor.isDestroyed) {
|
|
120
|
+
editor.view.setProps({
|
|
121
|
+
nodeViews: {},
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
editor.contentComponent = null;
|
|
125
|
+
if (!editor.options.element.firstChild) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
const newElement = document.createElement('div');
|
|
129
|
+
newElement.append(...editor.options.element.childNodes);
|
|
130
|
+
editor.setOptions({
|
|
131
|
+
element: newElement,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
render() {
|
|
135
|
+
const { editor, ...rest } = this.props;
|
|
136
|
+
return (React__default["default"].createElement(React__default["default"].Fragment, null,
|
|
137
|
+
React__default["default"].createElement("div", { ref: this.editorContentRef, ...rest }),
|
|
138
|
+
React__default["default"].createElement(Portals, { renderers: this.state.renderers })));
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
const EditorContent = React__default["default"].memo(PureEditorContent);
|
|
142
|
+
|
|
143
|
+
const FloatingMenu = (props) => {
|
|
144
|
+
const [element, setElement] = React.useState(null);
|
|
145
|
+
React.useEffect(() => {
|
|
146
|
+
if (!element) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
if (props.editor.isDestroyed) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
const { pluginKey = 'floatingMenu', editor, tippyOptions = {}, shouldShow = null, } = props;
|
|
153
|
+
const plugin = extensionFloatingMenu.FloatingMenuPlugin({
|
|
154
|
+
pluginKey,
|
|
155
|
+
editor,
|
|
156
|
+
element,
|
|
157
|
+
tippyOptions,
|
|
158
|
+
shouldShow,
|
|
159
|
+
});
|
|
160
|
+
editor.registerPlugin(plugin);
|
|
161
|
+
return () => editor.unregisterPlugin(pluginKey);
|
|
162
|
+
}, [
|
|
163
|
+
props.editor,
|
|
164
|
+
element,
|
|
165
|
+
]);
|
|
166
|
+
return (React__default["default"].createElement("div", { ref: setElement, className: props.className, style: { visibility: 'hidden' } }, props.children));
|
|
174
167
|
};
|
|
175
168
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
const Tag = props.as || "div";
|
|
189
|
-
const { nodeViewContentRef } = useReactNodeView();
|
|
190
|
-
return /* @__PURE__ */ _react2.default.createElement(
|
|
191
|
-
Tag,
|
|
192
|
-
{
|
|
193
|
-
...props,
|
|
194
|
-
ref: nodeViewContentRef,
|
|
195
|
-
"data-node-view-content": "",
|
|
196
|
-
style: {
|
|
197
|
-
whiteSpace: "pre-wrap",
|
|
198
|
-
...props.style
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
);
|
|
169
|
+
const ReactNodeViewContext = React.createContext({
|
|
170
|
+
onDragStart: undefined,
|
|
171
|
+
});
|
|
172
|
+
const useReactNodeView = () => React.useContext(ReactNodeViewContext);
|
|
173
|
+
|
|
174
|
+
const NodeViewContent = props => {
|
|
175
|
+
const Tag = props.as || 'div';
|
|
176
|
+
const { nodeViewContentRef } = useReactNodeView();
|
|
177
|
+
return (React__default["default"].createElement(Tag, { ...props, ref: nodeViewContentRef, "data-node-view-content": "", style: {
|
|
178
|
+
whiteSpace: 'pre-wrap',
|
|
179
|
+
...props.style,
|
|
180
|
+
} }));
|
|
202
181
|
};
|
|
203
182
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
{
|
|
212
|
-
...props,
|
|
213
|
-
ref,
|
|
214
|
-
"data-node-view-wrapper": "",
|
|
215
|
-
onDragStart,
|
|
216
|
-
style: {
|
|
217
|
-
whiteSpace: "normal",
|
|
218
|
-
...props.style
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
);
|
|
183
|
+
const NodeViewWrapper = React__default["default"].forwardRef((props, ref) => {
|
|
184
|
+
const { onDragStart } = useReactNodeView();
|
|
185
|
+
const Tag = props.as || 'div';
|
|
186
|
+
return (React__default["default"].createElement(Tag, { ...props, ref: ref, "data-node-view-wrapper": "", onDragStart: onDragStart, style: {
|
|
187
|
+
whiteSpace: 'normal',
|
|
188
|
+
...props.style,
|
|
189
|
+
} }));
|
|
222
190
|
});
|
|
223
191
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
192
|
+
function isClassComponent(Component) {
|
|
193
|
+
return !!(typeof Component === 'function'
|
|
194
|
+
&& Component.prototype
|
|
195
|
+
&& Component.prototype.isReactComponent);
|
|
196
|
+
}
|
|
197
|
+
function isForwardRefComponent(Component) {
|
|
198
|
+
var _a;
|
|
199
|
+
return !!(typeof Component === 'object'
|
|
200
|
+
&& ((_a = Component.$$typeof) === null || _a === void 0 ? void 0 : _a.toString()) === 'Symbol(react.forward_ref)');
|
|
201
|
+
}
|
|
202
|
+
class ReactRenderer {
|
|
203
|
+
constructor(component, { editor, props = {}, as = 'div', className = '', }) {
|
|
204
|
+
this.ref = null;
|
|
205
|
+
this.id = Math.floor(Math.random() * 0xFFFFFFFF).toString();
|
|
206
|
+
this.component = component;
|
|
207
|
+
this.editor = editor;
|
|
208
|
+
this.props = props;
|
|
209
|
+
this.element = document.createElement(as);
|
|
210
|
+
this.element.classList.add('react-renderer');
|
|
211
|
+
if (className) {
|
|
212
|
+
this.element.classList.add(...className.split(' '));
|
|
213
|
+
}
|
|
214
|
+
this.render();
|
|
215
|
+
}
|
|
216
|
+
render() {
|
|
217
|
+
var _a, _b;
|
|
218
|
+
const Component = this.component;
|
|
219
|
+
const props = this.props;
|
|
220
|
+
if (isClassComponent(Component) || isForwardRefComponent(Component)) {
|
|
221
|
+
props.ref = (ref) => {
|
|
222
|
+
this.ref = ref;
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
this.reactElement = React__default["default"].createElement(Component, { ...props });
|
|
226
|
+
(_b = (_a = this.editor) === null || _a === void 0 ? void 0 : _a.contentComponent) === null || _b === void 0 ? void 0 : _b.setRenderer(this.id, this);
|
|
227
|
+
}
|
|
228
|
+
updateProps(props = {}) {
|
|
229
|
+
this.props = {
|
|
230
|
+
...this.props,
|
|
231
|
+
...props,
|
|
232
|
+
};
|
|
233
|
+
this.render();
|
|
234
|
+
}
|
|
235
|
+
destroy() {
|
|
236
|
+
var _a, _b;
|
|
237
|
+
(_b = (_a = this.editor) === null || _a === void 0 ? void 0 : _a.contentComponent) === null || _b === void 0 ? void 0 : _b.removeRenderer(this.id);
|
|
238
|
+
}
|
|
238
239
|
}
|
|
239
|
-
var ReactRenderer = class {
|
|
240
|
-
constructor(component, {
|
|
241
|
-
editor,
|
|
242
|
-
props = {},
|
|
243
|
-
as = "div",
|
|
244
|
-
className = ""
|
|
245
|
-
}) {
|
|
246
|
-
this.ref = null;
|
|
247
|
-
this.id = Math.floor(Math.random() * 4294967295).toString();
|
|
248
|
-
this.component = component;
|
|
249
|
-
this.editor = editor;
|
|
250
|
-
this.props = props;
|
|
251
|
-
this.element = document.createElement(as);
|
|
252
|
-
this.element.classList.add("react-renderer");
|
|
253
|
-
if (className) {
|
|
254
|
-
this.element.classList.add(...className.split(" "));
|
|
255
|
-
}
|
|
256
|
-
this.render();
|
|
257
|
-
}
|
|
258
|
-
render() {
|
|
259
|
-
var _a, _b;
|
|
260
|
-
const Component = this.component;
|
|
261
|
-
const props = this.props;
|
|
262
|
-
if (isClassComponent(Component) || isForwardRefComponent(Component)) {
|
|
263
|
-
props.ref = (ref) => {
|
|
264
|
-
this.ref = ref;
|
|
265
|
-
};
|
|
266
|
-
}
|
|
267
|
-
this.reactElement = /* @__PURE__ */ _react2.default.createElement(Component, { ...props });
|
|
268
|
-
(_b = (_a = this.editor) == null ? void 0 : _a.contentComponent) == null ? void 0 : _b.setRenderer(this.id, this);
|
|
269
|
-
}
|
|
270
|
-
updateProps(props = {}) {
|
|
271
|
-
this.props = {
|
|
272
|
-
...this.props,
|
|
273
|
-
...props
|
|
274
|
-
};
|
|
275
|
-
this.render();
|
|
276
|
-
}
|
|
277
|
-
destroy() {
|
|
278
|
-
var _a, _b;
|
|
279
|
-
(_b = (_a = this.editor) == null ? void 0 : _a.contentComponent) == null ? void 0 : _b.removeRenderer(this.id);
|
|
280
|
-
}
|
|
281
|
-
};
|
|
282
240
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
241
|
+
class ReactNodeView extends core.NodeView {
|
|
242
|
+
mount() {
|
|
243
|
+
const props = {
|
|
244
|
+
editor: this.editor,
|
|
245
|
+
node: this.node,
|
|
246
|
+
decorations: this.decorations,
|
|
247
|
+
selected: false,
|
|
248
|
+
extension: this.extension,
|
|
249
|
+
getPos: () => this.getPos(),
|
|
250
|
+
updateAttributes: (attributes = {}) => this.updateAttributes(attributes),
|
|
251
|
+
deleteNode: () => this.deleteNode(),
|
|
252
|
+
};
|
|
253
|
+
if (!this.component.displayName) {
|
|
254
|
+
const capitalizeFirstChar = (string) => {
|
|
255
|
+
return string.charAt(0).toUpperCase() + string.substring(1);
|
|
256
|
+
};
|
|
257
|
+
this.component.displayName = capitalizeFirstChar(this.extension.name);
|
|
258
|
+
}
|
|
259
|
+
const ReactNodeViewProvider = componentProps => {
|
|
260
|
+
const Component = this.component;
|
|
261
|
+
const onDragStart = this.onDragStart.bind(this);
|
|
262
|
+
const nodeViewContentRef = element => {
|
|
263
|
+
if (element && this.contentDOMElement && element.firstChild !== this.contentDOMElement) {
|
|
264
|
+
element.appendChild(this.contentDOMElement);
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
return (React__default["default"].createElement(React__default["default"].Fragment, null,
|
|
268
|
+
React__default["default"].createElement(ReactNodeViewContext.Provider, { value: { onDragStart, nodeViewContentRef } },
|
|
269
|
+
React__default["default"].createElement(Component, { ...componentProps }))));
|
|
270
|
+
};
|
|
271
|
+
ReactNodeViewProvider.displayName = 'ReactNodeView';
|
|
272
|
+
this.contentDOMElement = this.node.isLeaf
|
|
273
|
+
? null
|
|
274
|
+
: document.createElement(this.node.isInline ? 'span' : 'div');
|
|
275
|
+
if (this.contentDOMElement) {
|
|
276
|
+
// For some reason the whiteSpace prop is not inherited properly in Chrome and Safari
|
|
277
|
+
// With this fix it seems to work fine
|
|
278
|
+
// See: https://github.com/ueberdosis/tiptap/issues/1197
|
|
279
|
+
this.contentDOMElement.style.whiteSpace = 'inherit';
|
|
280
|
+
}
|
|
281
|
+
let as = this.node.isInline ? 'span' : 'div';
|
|
282
|
+
if (this.options.as) {
|
|
283
|
+
as = this.options.as;
|
|
284
|
+
}
|
|
285
|
+
const { className = '' } = this.options;
|
|
286
|
+
this.renderer = new ReactRenderer(ReactNodeViewProvider, {
|
|
287
|
+
editor: this.editor,
|
|
288
|
+
props,
|
|
289
|
+
as,
|
|
290
|
+
className: `node-${this.node.type.name} ${className}`.trim(),
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
get dom() {
|
|
294
|
+
var _a;
|
|
295
|
+
if (this.renderer.element.firstElementChild
|
|
296
|
+
&& !((_a = this.renderer.element.firstElementChild) === null || _a === void 0 ? void 0 : _a.hasAttribute('data-node-view-wrapper'))) {
|
|
297
|
+
throw Error('Please use the NodeViewWrapper component for your node view.');
|
|
298
|
+
}
|
|
299
|
+
return this.renderer.element;
|
|
300
|
+
}
|
|
301
|
+
get contentDOM() {
|
|
302
|
+
if (this.node.isLeaf) {
|
|
303
|
+
return null;
|
|
304
|
+
}
|
|
305
|
+
return this.contentDOMElement;
|
|
306
|
+
}
|
|
307
|
+
update(node, decorations) {
|
|
308
|
+
const updateProps = (props) => {
|
|
309
|
+
this.renderer.updateProps(props);
|
|
310
|
+
};
|
|
311
|
+
if (node.type !== this.node.type) {
|
|
312
|
+
return false;
|
|
313
|
+
}
|
|
314
|
+
if (typeof this.options.update === 'function') {
|
|
315
|
+
const oldNode = this.node;
|
|
316
|
+
const oldDecorations = this.decorations;
|
|
317
|
+
this.node = node;
|
|
318
|
+
this.decorations = decorations;
|
|
319
|
+
return this.options.update({
|
|
320
|
+
oldNode,
|
|
321
|
+
oldDecorations,
|
|
322
|
+
newNode: node,
|
|
323
|
+
newDecorations: decorations,
|
|
324
|
+
updateProps: () => updateProps({ node, decorations }),
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
if (node === this.node && this.decorations === decorations) {
|
|
328
|
+
return true;
|
|
329
|
+
}
|
|
330
|
+
this.node = node;
|
|
331
|
+
this.decorations = decorations;
|
|
332
|
+
updateProps({ node, decorations });
|
|
333
|
+
return true;
|
|
334
|
+
}
|
|
335
|
+
selectNode() {
|
|
336
|
+
this.renderer.updateProps({
|
|
337
|
+
selected: true,
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
deselectNode() {
|
|
341
|
+
this.renderer.updateProps({
|
|
342
|
+
selected: false,
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
destroy() {
|
|
346
|
+
this.renderer.destroy();
|
|
347
|
+
this.contentDOMElement = null;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
function ReactNodeViewRenderer(component, options) {
|
|
351
|
+
return (props) => {
|
|
352
|
+
// try to get the parent component
|
|
353
|
+
// this is important for vue devtools to show the component hierarchy correctly
|
|
354
|
+
// maybe it’s `undefined` because <editor-content> isn’t rendered yet
|
|
355
|
+
if (!props.editor.contentComponent) {
|
|
356
|
+
return {};
|
|
357
|
+
}
|
|
358
|
+
return new ReactNodeView(component, props, options);
|
|
359
|
+
};
|
|
392
360
|
}
|
|
393
361
|
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
});
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
}, deps);
|
|
421
|
-
return editor;
|
|
362
|
+
function useForceUpdate() {
|
|
363
|
+
const [, setValue] = React.useState(0);
|
|
364
|
+
return () => setValue(value => value + 1);
|
|
365
|
+
}
|
|
366
|
+
const useEditor = (options = {}, deps = []) => {
|
|
367
|
+
const [editor, setEditor] = React.useState(null);
|
|
368
|
+
const forceUpdate = useForceUpdate();
|
|
369
|
+
React.useEffect(() => {
|
|
370
|
+
let isMounted = true;
|
|
371
|
+
const instance = new Editor(options);
|
|
372
|
+
setEditor(instance);
|
|
373
|
+
instance.on('transaction', () => {
|
|
374
|
+
requestAnimationFrame(() => {
|
|
375
|
+
requestAnimationFrame(() => {
|
|
376
|
+
if (isMounted) {
|
|
377
|
+
forceUpdate();
|
|
378
|
+
}
|
|
379
|
+
});
|
|
380
|
+
});
|
|
381
|
+
});
|
|
382
|
+
return () => {
|
|
383
|
+
instance.destroy();
|
|
384
|
+
isMounted = false;
|
|
385
|
+
};
|
|
386
|
+
}, deps);
|
|
387
|
+
return editor;
|
|
422
388
|
};
|
|
423
389
|
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
390
|
+
exports.BubbleMenu = BubbleMenu;
|
|
391
|
+
exports.Editor = Editor;
|
|
392
|
+
exports.EditorContent = EditorContent;
|
|
393
|
+
exports.FloatingMenu = FloatingMenu;
|
|
394
|
+
exports.NodeViewContent = NodeViewContent;
|
|
395
|
+
exports.NodeViewWrapper = NodeViewWrapper;
|
|
396
|
+
exports.PureEditorContent = PureEditorContent;
|
|
397
|
+
exports.ReactNodeViewRenderer = ReactNodeViewRenderer;
|
|
398
|
+
exports.ReactRenderer = ReactRenderer;
|
|
399
|
+
exports.useEditor = useEditor;
|
|
400
|
+
Object.keys(core).forEach(function (k) {
|
|
401
|
+
if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
|
|
402
|
+
enumerable: true,
|
|
403
|
+
get: function () { return core[k]; }
|
|
404
|
+
});
|
|
405
|
+
});
|
|
406
|
+
//# sourceMappingURL=index.cjs.map
|