@tiptap/vue-3 2.0.0-beta.213 → 2.0.0-beta.215
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 +459 -506
- package/dist/index.cjs.map +1 -0
- package/dist/index.js +441 -506
- package/dist/index.js.map +1 -0
- package/dist/index.umd.js +477 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/packages/vue-3/src/BubbleMenu.d.ts +72 -0
- package/dist/packages/vue-3/src/Editor.d.ts +24 -0
- package/dist/packages/vue-3/src/EditorContent.d.ts +17 -0
- package/dist/packages/vue-3/src/FloatingMenu.d.ts +57 -0
- package/dist/packages/vue-3/src/NodeViewContent.d.ts +13 -0
- package/dist/packages/vue-3/src/NodeViewWrapper.d.ts +13 -0
- package/dist/packages/vue-3/src/VueNodeViewRenderer.d.ts +48 -0
- package/dist/packages/vue-3/src/VueRenderer.d.ts +19 -0
- package/dist/packages/vue-3/src/index.d.ts +10 -0
- package/dist/packages/vue-3/src/useEditor.d.ts +3 -0
- package/package.json +10 -19
- package/dist/index.d.ts +0 -271
package/dist/index.cjs
CHANGED
|
@@ -1,523 +1,476 @@
|
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
editor.unregisterPlugin(pluginKey);
|
|
56
|
-
});
|
|
57
|
-
return () => {
|
|
58
|
-
var _a;
|
|
59
|
-
return _vue.h.call(void 0, "div", { ref: root }, (_a = slots.default) == null ? void 0 : _a.call(slots));
|
|
60
|
-
};
|
|
61
|
-
}
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var extensionBubbleMenu = require('@tiptap/extension-bubble-menu');
|
|
6
|
+
var vue = require('vue');
|
|
7
|
+
var core = require('@tiptap/core');
|
|
8
|
+
var extensionFloatingMenu = require('@tiptap/extension-floating-menu');
|
|
9
|
+
|
|
10
|
+
const BubbleMenu = vue.defineComponent({
|
|
11
|
+
name: 'BubbleMenu',
|
|
12
|
+
props: {
|
|
13
|
+
pluginKey: {
|
|
14
|
+
// TODO: TypeScript breaks :(
|
|
15
|
+
// type: [String, Object as PropType<Exclude<BubbleMenuPluginProps['pluginKey'], string>>],
|
|
16
|
+
type: null,
|
|
17
|
+
default: 'bubbleMenu',
|
|
18
|
+
},
|
|
19
|
+
editor: {
|
|
20
|
+
type: Object,
|
|
21
|
+
required: true,
|
|
22
|
+
},
|
|
23
|
+
updateDelay: {
|
|
24
|
+
type: Number,
|
|
25
|
+
default: undefined,
|
|
26
|
+
},
|
|
27
|
+
tippyOptions: {
|
|
28
|
+
type: Object,
|
|
29
|
+
default: () => ({}),
|
|
30
|
+
},
|
|
31
|
+
shouldShow: {
|
|
32
|
+
type: Function,
|
|
33
|
+
default: null,
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
setup(props, { slots }) {
|
|
37
|
+
const root = vue.ref(null);
|
|
38
|
+
vue.onMounted(() => {
|
|
39
|
+
const { updateDelay, editor, pluginKey, shouldShow, tippyOptions, } = props;
|
|
40
|
+
editor.registerPlugin(extensionBubbleMenu.BubbleMenuPlugin({
|
|
41
|
+
updateDelay,
|
|
42
|
+
editor,
|
|
43
|
+
element: root.value,
|
|
44
|
+
pluginKey,
|
|
45
|
+
shouldShow,
|
|
46
|
+
tippyOptions,
|
|
47
|
+
}));
|
|
48
|
+
});
|
|
49
|
+
vue.onBeforeUnmount(() => {
|
|
50
|
+
const { pluginKey, editor } = props;
|
|
51
|
+
editor.unregisterPlugin(pluginKey);
|
|
52
|
+
});
|
|
53
|
+
return () => { var _a; return vue.h('div', { ref: root }, (_a = slots.default) === null || _a === void 0 ? void 0 : _a.call(slots)); };
|
|
54
|
+
},
|
|
62
55
|
});
|
|
63
56
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
57
|
+
function useDebouncedRef(value) {
|
|
58
|
+
return vue.customRef((track, trigger) => {
|
|
59
|
+
return {
|
|
60
|
+
get() {
|
|
61
|
+
track();
|
|
62
|
+
return value;
|
|
63
|
+
},
|
|
64
|
+
set(newValue) {
|
|
65
|
+
// update state
|
|
66
|
+
value = newValue;
|
|
67
|
+
// update view as soon as possible
|
|
68
|
+
requestAnimationFrame(() => {
|
|
69
|
+
requestAnimationFrame(() => {
|
|
70
|
+
trigger();
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
class Editor extends core.Editor {
|
|
78
|
+
constructor(options = {}) {
|
|
79
|
+
super(options);
|
|
80
|
+
this.vueRenderers = vue.reactive(new Map());
|
|
81
|
+
this.contentComponent = null;
|
|
82
|
+
this.reactiveState = useDebouncedRef(this.view.state);
|
|
83
|
+
this.reactiveExtensionStorage = useDebouncedRef(this.extensionStorage);
|
|
84
|
+
this.on('transaction', () => {
|
|
85
|
+
this.reactiveState.value = this.view.state;
|
|
86
|
+
this.reactiveExtensionStorage.value = this.extensionStorage;
|
|
87
|
+
});
|
|
88
|
+
return vue.markRaw(this); // eslint-disable-line
|
|
89
|
+
}
|
|
90
|
+
get state() {
|
|
91
|
+
return this.reactiveState ? this.reactiveState.value : this.view.state;
|
|
92
|
+
}
|
|
93
|
+
get storage() {
|
|
94
|
+
return this.reactiveExtensionStorage ? this.reactiveExtensionStorage.value : super.storage;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Register a ProseMirror plugin.
|
|
98
|
+
*/
|
|
99
|
+
registerPlugin(plugin, handlePlugins) {
|
|
100
|
+
super.registerPlugin(plugin, handlePlugins);
|
|
101
|
+
this.reactiveState.value = this.view.state;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Unregister a ProseMirror plugin.
|
|
105
|
+
*/
|
|
106
|
+
unregisterPlugin(nameOrPluginKey) {
|
|
107
|
+
super.unregisterPlugin(nameOrPluginKey);
|
|
108
|
+
this.reactiveState.value = this.view.state;
|
|
109
|
+
}
|
|
88
110
|
}
|
|
89
|
-
var Editor = class extends _core.Editor {
|
|
90
|
-
constructor(options = {}) {
|
|
91
|
-
super(options);
|
|
92
|
-
this.vueRenderers = _vue.reactive.call(void 0, /* @__PURE__ */ new Map());
|
|
93
|
-
this.contentComponent = null;
|
|
94
|
-
this.reactiveState = useDebouncedRef(this.view.state);
|
|
95
|
-
this.reactiveExtensionStorage = useDebouncedRef(this.extensionStorage);
|
|
96
|
-
this.on("transaction", () => {
|
|
97
|
-
this.reactiveState.value = this.view.state;
|
|
98
|
-
this.reactiveExtensionStorage.value = this.extensionStorage;
|
|
99
|
-
});
|
|
100
|
-
return _vue.markRaw.call(void 0, this);
|
|
101
|
-
}
|
|
102
|
-
get state() {
|
|
103
|
-
return this.reactiveState ? this.reactiveState.value : this.view.state;
|
|
104
|
-
}
|
|
105
|
-
get storage() {
|
|
106
|
-
return this.reactiveExtensionStorage ? this.reactiveExtensionStorage.value : super.storage;
|
|
107
|
-
}
|
|
108
|
-
registerPlugin(plugin, handlePlugins) {
|
|
109
|
-
super.registerPlugin(plugin, handlePlugins);
|
|
110
|
-
this.reactiveState.value = this.view.state;
|
|
111
|
-
}
|
|
112
|
-
unregisterPlugin(nameOrPluginKey) {
|
|
113
|
-
super.unregisterPlugin(nameOrPluginKey);
|
|
114
|
-
this.reactiveState.value = this.view.state;
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
// src/EditorContent.ts
|
|
119
|
-
|
|
120
|
-
|
|
121
111
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
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
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
{
|
|
193
|
-
ref: vueRenderer.id,
|
|
194
|
-
...vueRenderer.props
|
|
195
|
-
}
|
|
196
|
-
)
|
|
197
|
-
);
|
|
198
|
-
vueRenderers.push(node);
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
return _vue.h.call(void 0,
|
|
202
|
-
"div",
|
|
203
|
-
{
|
|
204
|
-
ref: (el) => {
|
|
205
|
-
this.rootEl = el;
|
|
206
|
-
}
|
|
207
|
-
},
|
|
208
|
-
...vueRenderers
|
|
209
|
-
);
|
|
210
|
-
}
|
|
112
|
+
const EditorContent = vue.defineComponent({
|
|
113
|
+
name: 'EditorContent',
|
|
114
|
+
props: {
|
|
115
|
+
editor: {
|
|
116
|
+
default: null,
|
|
117
|
+
type: Object,
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
setup(props) {
|
|
121
|
+
const rootEl = vue.ref();
|
|
122
|
+
const instance = vue.getCurrentInstance();
|
|
123
|
+
vue.watchEffect(() => {
|
|
124
|
+
const editor = props.editor;
|
|
125
|
+
if (editor && editor.options.element && rootEl.value) {
|
|
126
|
+
vue.nextTick(() => {
|
|
127
|
+
if (!rootEl.value || !editor.options.element.firstChild) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
const element = vue.unref(rootEl.value);
|
|
131
|
+
rootEl.value.append(...editor.options.element.childNodes);
|
|
132
|
+
// @ts-ignore
|
|
133
|
+
editor.contentComponent = instance.ctx._;
|
|
134
|
+
editor.setOptions({
|
|
135
|
+
element,
|
|
136
|
+
});
|
|
137
|
+
editor.createNodeViews();
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
vue.onBeforeUnmount(() => {
|
|
142
|
+
const editor = props.editor;
|
|
143
|
+
if (!editor) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
// destroy nodeviews before vue removes dom element
|
|
147
|
+
if (!editor.isDestroyed) {
|
|
148
|
+
editor.view.setProps({
|
|
149
|
+
nodeViews: {},
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
editor.contentComponent = null;
|
|
153
|
+
if (!editor.options.element.firstChild) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
const newElement = document.createElement('div');
|
|
157
|
+
newElement.append(...editor.options.element.childNodes);
|
|
158
|
+
editor.setOptions({
|
|
159
|
+
element: newElement,
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
return { rootEl };
|
|
163
|
+
},
|
|
164
|
+
render() {
|
|
165
|
+
const vueRenderers = [];
|
|
166
|
+
if (this.editor) {
|
|
167
|
+
this.editor.vueRenderers.forEach(vueRenderer => {
|
|
168
|
+
const node = vue.h(vue.Teleport, {
|
|
169
|
+
to: vueRenderer.teleportElement,
|
|
170
|
+
key: vueRenderer.id,
|
|
171
|
+
}, vue.h(vueRenderer.component, {
|
|
172
|
+
ref: vueRenderer.id,
|
|
173
|
+
...vueRenderer.props,
|
|
174
|
+
}));
|
|
175
|
+
vueRenderers.push(node);
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
return vue.h('div', {
|
|
179
|
+
ref: (el) => { this.rootEl = el; },
|
|
180
|
+
}, ...vueRenderers);
|
|
181
|
+
},
|
|
211
182
|
});
|
|
212
183
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
editor,
|
|
254
|
-
element: root.value,
|
|
255
|
-
tippyOptions,
|
|
256
|
-
shouldShow
|
|
257
|
-
}));
|
|
258
|
-
});
|
|
259
|
-
_vue.onBeforeUnmount.call(void 0, () => {
|
|
260
|
-
const { pluginKey, editor } = props;
|
|
261
|
-
editor.unregisterPlugin(pluginKey);
|
|
262
|
-
});
|
|
263
|
-
return () => {
|
|
264
|
-
var _a;
|
|
265
|
-
return _vue.h.call(void 0, "div", { ref: root }, (_a = slots.default) == null ? void 0 : _a.call(slots));
|
|
266
|
-
};
|
|
267
|
-
}
|
|
184
|
+
const FloatingMenu = vue.defineComponent({
|
|
185
|
+
name: 'FloatingMenu',
|
|
186
|
+
props: {
|
|
187
|
+
pluginKey: {
|
|
188
|
+
// TODO: TypeScript breaks :(
|
|
189
|
+
// type: [String, Object as PropType<Exclude<FloatingMenuPluginProps['pluginKey'], string>>],
|
|
190
|
+
type: null,
|
|
191
|
+
default: 'floatingMenu',
|
|
192
|
+
},
|
|
193
|
+
editor: {
|
|
194
|
+
type: Object,
|
|
195
|
+
required: true,
|
|
196
|
+
},
|
|
197
|
+
tippyOptions: {
|
|
198
|
+
type: Object,
|
|
199
|
+
default: () => ({}),
|
|
200
|
+
},
|
|
201
|
+
shouldShow: {
|
|
202
|
+
type: Function,
|
|
203
|
+
default: null,
|
|
204
|
+
},
|
|
205
|
+
},
|
|
206
|
+
setup(props, { slots }) {
|
|
207
|
+
const root = vue.ref(null);
|
|
208
|
+
vue.onMounted(() => {
|
|
209
|
+
const { pluginKey, editor, tippyOptions, shouldShow, } = props;
|
|
210
|
+
editor.registerPlugin(extensionFloatingMenu.FloatingMenuPlugin({
|
|
211
|
+
pluginKey,
|
|
212
|
+
editor,
|
|
213
|
+
element: root.value,
|
|
214
|
+
tippyOptions,
|
|
215
|
+
shouldShow,
|
|
216
|
+
}));
|
|
217
|
+
});
|
|
218
|
+
vue.onBeforeUnmount(() => {
|
|
219
|
+
const { pluginKey, editor } = props;
|
|
220
|
+
editor.unregisterPlugin(pluginKey);
|
|
221
|
+
});
|
|
222
|
+
return () => { var _a; return vue.h('div', { ref: root }, (_a = slots.default) === null || _a === void 0 ? void 0 : _a.call(slots)); };
|
|
223
|
+
},
|
|
268
224
|
});
|
|
269
225
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
});
|
|
286
|
-
}
|
|
226
|
+
const NodeViewContent = vue.defineComponent({
|
|
227
|
+
props: {
|
|
228
|
+
as: {
|
|
229
|
+
type: String,
|
|
230
|
+
default: 'div',
|
|
231
|
+
},
|
|
232
|
+
},
|
|
233
|
+
render() {
|
|
234
|
+
return vue.h(this.as, {
|
|
235
|
+
style: {
|
|
236
|
+
whiteSpace: 'pre-wrap',
|
|
237
|
+
},
|
|
238
|
+
'data-node-view-content': '',
|
|
239
|
+
});
|
|
240
|
+
},
|
|
287
241
|
});
|
|
288
242
|
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
},
|
|
311
|
-
(_b = (_a = this.$slots).default) == null ? void 0 : _b.call(_a)
|
|
312
|
-
);
|
|
313
|
-
}
|
|
243
|
+
const NodeViewWrapper = vue.defineComponent({
|
|
244
|
+
props: {
|
|
245
|
+
as: {
|
|
246
|
+
type: String,
|
|
247
|
+
default: 'div',
|
|
248
|
+
},
|
|
249
|
+
},
|
|
250
|
+
inject: ['onDragStart', 'decorationClasses'],
|
|
251
|
+
render() {
|
|
252
|
+
var _a, _b;
|
|
253
|
+
return vue.h(this.as, {
|
|
254
|
+
// @ts-ignore
|
|
255
|
+
class: this.decorationClasses,
|
|
256
|
+
style: {
|
|
257
|
+
whiteSpace: 'normal',
|
|
258
|
+
},
|
|
259
|
+
'data-node-view-wrapper': '',
|
|
260
|
+
// @ts-ignore (https://github.com/vuejs/vue-next/issues/3031)
|
|
261
|
+
onDragstart: this.onDragStart,
|
|
262
|
+
}, (_b = (_a = this.$slots).default) === null || _b === void 0 ? void 0 : _b.call(_a));
|
|
263
|
+
},
|
|
314
264
|
});
|
|
315
265
|
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
});
|
|
327
|
-
return editor;
|
|
328
|
-
};
|
|
329
|
-
|
|
330
|
-
// src/VueNodeViewRenderer.ts
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
// src/VueRenderer.ts
|
|
341
|
-
|
|
342
|
-
var VueRenderer = class {
|
|
343
|
-
constructor(component, { props = {}, editor }) {
|
|
344
|
-
this.id = Math.floor(Math.random() * 4294967295).toString();
|
|
345
|
-
this.editor = editor;
|
|
346
|
-
this.component = _vue.markRaw.call(void 0, component);
|
|
347
|
-
this.teleportElement = document.createElement("div");
|
|
348
|
-
this.element = this.teleportElement;
|
|
349
|
-
this.props = _vue.reactive.call(void 0, props);
|
|
350
|
-
this.editor.vueRenderers.set(this.id, this);
|
|
351
|
-
if (this.editor.contentComponent) {
|
|
352
|
-
this.editor.contentComponent.update();
|
|
353
|
-
if (this.teleportElement.children.length !== 1) {
|
|
354
|
-
throw Error("VueRenderer doesn\u2019t support multiple child elements.");
|
|
355
|
-
}
|
|
356
|
-
this.element = this.teleportElement.firstElementChild;
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
get ref() {
|
|
360
|
-
var _a;
|
|
361
|
-
return (_a = this.editor.contentComponent) == null ? void 0 : _a.refs[this.id];
|
|
362
|
-
}
|
|
363
|
-
updateProps(props = {}) {
|
|
364
|
-
Object.entries(props).forEach(([key, value]) => {
|
|
365
|
-
this.props[key] = value;
|
|
366
|
-
});
|
|
367
|
-
}
|
|
368
|
-
destroy() {
|
|
369
|
-
this.editor.vueRenderers.delete(this.id);
|
|
370
|
-
}
|
|
266
|
+
const useEditor = (options = {}) => {
|
|
267
|
+
const editor = vue.shallowRef();
|
|
268
|
+
vue.onMounted(() => {
|
|
269
|
+
editor.value = new Editor(options);
|
|
270
|
+
});
|
|
271
|
+
vue.onBeforeUnmount(() => {
|
|
272
|
+
var _a;
|
|
273
|
+
(_a = editor.value) === null || _a === void 0 ? void 0 : _a.destroy();
|
|
274
|
+
});
|
|
275
|
+
return editor;
|
|
371
276
|
};
|
|
372
277
|
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
type: Function,
|
|
405
|
-
required: true
|
|
406
|
-
}
|
|
407
|
-
};
|
|
408
|
-
var VueNodeView = class extends _core.NodeView {
|
|
409
|
-
mount() {
|
|
410
|
-
const props = {
|
|
411
|
-
editor: this.editor,
|
|
412
|
-
node: this.node,
|
|
413
|
-
decorations: this.decorations,
|
|
414
|
-
selected: false,
|
|
415
|
-
extension: this.extension,
|
|
416
|
-
getPos: () => this.getPos(),
|
|
417
|
-
updateAttributes: (attributes = {}) => this.updateAttributes(attributes),
|
|
418
|
-
deleteNode: () => this.deleteNode()
|
|
419
|
-
};
|
|
420
|
-
const onDragStart = this.onDragStart.bind(this);
|
|
421
|
-
this.decorationClasses = _vue.ref.call(void 0, this.getDecorationClasses());
|
|
422
|
-
const extendedComponent = _vue.defineComponent.call(void 0, {
|
|
423
|
-
extends: { ...this.component },
|
|
424
|
-
props: Object.keys(props),
|
|
425
|
-
template: this.component.template,
|
|
426
|
-
setup: (reactiveProps) => {
|
|
427
|
-
var _a, _b;
|
|
428
|
-
_vue.provide.call(void 0, "onDragStart", onDragStart);
|
|
429
|
-
_vue.provide.call(void 0, "decorationClasses", this.decorationClasses);
|
|
430
|
-
return (_b = (_a = this.component).setup) == null ? void 0 : _b.call(_a, reactiveProps, {
|
|
431
|
-
expose: () => void 0
|
|
432
|
-
});
|
|
433
|
-
},
|
|
434
|
-
__scopeId: this.component.__scopeId,
|
|
435
|
-
__cssModules: this.component.__cssModules
|
|
436
|
-
});
|
|
437
|
-
this.renderer = new VueRenderer(extendedComponent, {
|
|
438
|
-
editor: this.editor,
|
|
439
|
-
props
|
|
440
|
-
});
|
|
441
|
-
}
|
|
442
|
-
get dom() {
|
|
443
|
-
if (!this.renderer.element.hasAttribute("data-node-view-wrapper")) {
|
|
444
|
-
throw Error("Please use the NodeViewWrapper component for your node view.");
|
|
445
|
-
}
|
|
446
|
-
return this.renderer.element;
|
|
447
|
-
}
|
|
448
|
-
get contentDOM() {
|
|
449
|
-
if (this.node.isLeaf) {
|
|
450
|
-
return null;
|
|
451
|
-
}
|
|
452
|
-
const contentElement = this.dom.querySelector("[data-node-view-content]");
|
|
453
|
-
return contentElement || this.dom;
|
|
454
|
-
}
|
|
455
|
-
update(node, decorations) {
|
|
456
|
-
const updateProps = (props) => {
|
|
457
|
-
this.decorationClasses.value = this.getDecorationClasses();
|
|
458
|
-
this.renderer.updateProps(props);
|
|
459
|
-
};
|
|
460
|
-
if (typeof this.options.update === "function") {
|
|
461
|
-
const oldNode = this.node;
|
|
462
|
-
const oldDecorations = this.decorations;
|
|
463
|
-
this.node = node;
|
|
464
|
-
this.decorations = decorations;
|
|
465
|
-
return this.options.update({
|
|
466
|
-
oldNode,
|
|
467
|
-
oldDecorations,
|
|
468
|
-
newNode: node,
|
|
469
|
-
newDecorations: decorations,
|
|
470
|
-
updateProps: () => updateProps({ node, decorations })
|
|
471
|
-
});
|
|
472
|
-
}
|
|
473
|
-
if (node.type !== this.node.type) {
|
|
474
|
-
return false;
|
|
475
|
-
}
|
|
476
|
-
if (node === this.node && this.decorations === decorations) {
|
|
477
|
-
return true;
|
|
478
|
-
}
|
|
479
|
-
this.node = node;
|
|
480
|
-
this.decorations = decorations;
|
|
481
|
-
updateProps({ node, decorations });
|
|
482
|
-
return true;
|
|
483
|
-
}
|
|
484
|
-
selectNode() {
|
|
485
|
-
this.renderer.updateProps({
|
|
486
|
-
selected: true
|
|
487
|
-
});
|
|
488
|
-
}
|
|
489
|
-
deselectNode() {
|
|
490
|
-
this.renderer.updateProps({
|
|
491
|
-
selected: false
|
|
492
|
-
});
|
|
493
|
-
}
|
|
494
|
-
getDecorationClasses() {
|
|
495
|
-
return this.decorations.map((item) => item.type.attrs.class).flat().join(" ");
|
|
496
|
-
}
|
|
497
|
-
destroy() {
|
|
498
|
-
this.renderer.destroy();
|
|
499
|
-
}
|
|
500
|
-
};
|
|
501
|
-
function VueNodeViewRenderer(component, options) {
|
|
502
|
-
return (props) => {
|
|
503
|
-
if (!props.editor.contentComponent) {
|
|
504
|
-
return {};
|
|
505
|
-
}
|
|
506
|
-
return new VueNodeView(component, props, options);
|
|
507
|
-
};
|
|
278
|
+
class VueRenderer {
|
|
279
|
+
constructor(component, { props = {}, editor }) {
|
|
280
|
+
this.id = Math.floor(Math.random() * 0xFFFFFFFF).toString();
|
|
281
|
+
this.editor = editor;
|
|
282
|
+
this.component = vue.markRaw(component);
|
|
283
|
+
this.teleportElement = document.createElement('div');
|
|
284
|
+
this.element = this.teleportElement;
|
|
285
|
+
this.props = vue.reactive(props);
|
|
286
|
+
this.editor.vueRenderers.set(this.id, this);
|
|
287
|
+
if (this.editor.contentComponent) {
|
|
288
|
+
this.editor.contentComponent.update();
|
|
289
|
+
if (this.teleportElement.children.length !== 1) {
|
|
290
|
+
throw Error('VueRenderer doesn’t support multiple child elements.');
|
|
291
|
+
}
|
|
292
|
+
this.element = this.teleportElement.firstElementChild;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
get ref() {
|
|
296
|
+
var _a;
|
|
297
|
+
return (_a = this.editor.contentComponent) === null || _a === void 0 ? void 0 : _a.refs[this.id];
|
|
298
|
+
}
|
|
299
|
+
updateProps(props = {}) {
|
|
300
|
+
Object
|
|
301
|
+
.entries(props)
|
|
302
|
+
.forEach(([key, value]) => {
|
|
303
|
+
this.props[key] = value;
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
destroy() {
|
|
307
|
+
this.editor.vueRenderers.delete(this.id);
|
|
308
|
+
}
|
|
508
309
|
}
|
|
509
310
|
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
311
|
+
const nodeViewProps = {
|
|
312
|
+
editor: {
|
|
313
|
+
type: Object,
|
|
314
|
+
required: true,
|
|
315
|
+
},
|
|
316
|
+
node: {
|
|
317
|
+
type: Object,
|
|
318
|
+
required: true,
|
|
319
|
+
},
|
|
320
|
+
decorations: {
|
|
321
|
+
type: Object,
|
|
322
|
+
required: true,
|
|
323
|
+
},
|
|
324
|
+
selected: {
|
|
325
|
+
type: Boolean,
|
|
326
|
+
required: true,
|
|
327
|
+
},
|
|
328
|
+
extension: {
|
|
329
|
+
type: Object,
|
|
330
|
+
required: true,
|
|
331
|
+
},
|
|
332
|
+
getPos: {
|
|
333
|
+
type: Function,
|
|
334
|
+
required: true,
|
|
335
|
+
},
|
|
336
|
+
updateAttributes: {
|
|
337
|
+
type: Function,
|
|
338
|
+
required: true,
|
|
339
|
+
},
|
|
340
|
+
deleteNode: {
|
|
341
|
+
type: Function,
|
|
342
|
+
required: true,
|
|
343
|
+
},
|
|
344
|
+
};
|
|
345
|
+
class VueNodeView extends core.NodeView {
|
|
346
|
+
mount() {
|
|
347
|
+
const props = {
|
|
348
|
+
editor: this.editor,
|
|
349
|
+
node: this.node,
|
|
350
|
+
decorations: this.decorations,
|
|
351
|
+
selected: false,
|
|
352
|
+
extension: this.extension,
|
|
353
|
+
getPos: () => this.getPos(),
|
|
354
|
+
updateAttributes: (attributes = {}) => this.updateAttributes(attributes),
|
|
355
|
+
deleteNode: () => this.deleteNode(),
|
|
356
|
+
};
|
|
357
|
+
const onDragStart = this.onDragStart.bind(this);
|
|
358
|
+
this.decorationClasses = vue.ref(this.getDecorationClasses());
|
|
359
|
+
const extendedComponent = vue.defineComponent({
|
|
360
|
+
extends: { ...this.component },
|
|
361
|
+
props: Object.keys(props),
|
|
362
|
+
template: this.component.template,
|
|
363
|
+
setup: reactiveProps => {
|
|
364
|
+
var _a, _b;
|
|
365
|
+
vue.provide('onDragStart', onDragStart);
|
|
366
|
+
vue.provide('decorationClasses', this.decorationClasses);
|
|
367
|
+
return (_b = (_a = this.component).setup) === null || _b === void 0 ? void 0 : _b.call(_a, reactiveProps, {
|
|
368
|
+
expose: () => undefined,
|
|
369
|
+
});
|
|
370
|
+
},
|
|
371
|
+
// add support for scoped styles
|
|
372
|
+
// @ts-ignore
|
|
373
|
+
// eslint-disable-next-line
|
|
374
|
+
__scopeId: this.component.__scopeId,
|
|
375
|
+
// add support for CSS Modules
|
|
376
|
+
// @ts-ignore
|
|
377
|
+
// eslint-disable-next-line
|
|
378
|
+
__cssModules: this.component.__cssModules,
|
|
379
|
+
});
|
|
380
|
+
this.renderer = new VueRenderer(extendedComponent, {
|
|
381
|
+
editor: this.editor,
|
|
382
|
+
props,
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
get dom() {
|
|
386
|
+
if (!this.renderer.element.hasAttribute('data-node-view-wrapper')) {
|
|
387
|
+
throw Error('Please use the NodeViewWrapper component for your node view.');
|
|
388
|
+
}
|
|
389
|
+
return this.renderer.element;
|
|
390
|
+
}
|
|
391
|
+
get contentDOM() {
|
|
392
|
+
if (this.node.isLeaf) {
|
|
393
|
+
return null;
|
|
394
|
+
}
|
|
395
|
+
const contentElement = this.dom.querySelector('[data-node-view-content]');
|
|
396
|
+
return (contentElement || this.dom);
|
|
397
|
+
}
|
|
398
|
+
update(node, decorations) {
|
|
399
|
+
const updateProps = (props) => {
|
|
400
|
+
this.decorationClasses.value = this.getDecorationClasses();
|
|
401
|
+
this.renderer.updateProps(props);
|
|
402
|
+
};
|
|
403
|
+
if (typeof this.options.update === 'function') {
|
|
404
|
+
const oldNode = this.node;
|
|
405
|
+
const oldDecorations = this.decorations;
|
|
406
|
+
this.node = node;
|
|
407
|
+
this.decorations = decorations;
|
|
408
|
+
return this.options.update({
|
|
409
|
+
oldNode,
|
|
410
|
+
oldDecorations,
|
|
411
|
+
newNode: node,
|
|
412
|
+
newDecorations: decorations,
|
|
413
|
+
updateProps: () => updateProps({ node, decorations }),
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
if (node.type !== this.node.type) {
|
|
417
|
+
return false;
|
|
418
|
+
}
|
|
419
|
+
if (node === this.node && this.decorations === decorations) {
|
|
420
|
+
return true;
|
|
421
|
+
}
|
|
422
|
+
this.node = node;
|
|
423
|
+
this.decorations = decorations;
|
|
424
|
+
updateProps({ node, decorations });
|
|
425
|
+
return true;
|
|
426
|
+
}
|
|
427
|
+
selectNode() {
|
|
428
|
+
this.renderer.updateProps({
|
|
429
|
+
selected: true,
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
deselectNode() {
|
|
433
|
+
this.renderer.updateProps({
|
|
434
|
+
selected: false,
|
|
435
|
+
});
|
|
436
|
+
}
|
|
437
|
+
getDecorationClasses() {
|
|
438
|
+
return (this.decorations
|
|
439
|
+
// @ts-ignore
|
|
440
|
+
.map(item => item.type.attrs.class)
|
|
441
|
+
.flat()
|
|
442
|
+
.join(' '));
|
|
443
|
+
}
|
|
444
|
+
destroy() {
|
|
445
|
+
this.renderer.destroy();
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
function VueNodeViewRenderer(component, options) {
|
|
449
|
+
return (props) => {
|
|
450
|
+
// try to get the parent component
|
|
451
|
+
// this is important for vue devtools to show the component hierarchy correctly
|
|
452
|
+
// maybe it’s `undefined` because <editor-content> isn’t rendered yet
|
|
453
|
+
if (!props.editor.contentComponent) {
|
|
454
|
+
return {};
|
|
455
|
+
}
|
|
456
|
+
return new VueNodeView(component, props, options);
|
|
457
|
+
};
|
|
458
|
+
}
|
|
522
459
|
|
|
523
|
-
exports.BubbleMenu = BubbleMenu;
|
|
460
|
+
exports.BubbleMenu = BubbleMenu;
|
|
461
|
+
exports.Editor = Editor;
|
|
462
|
+
exports.EditorContent = EditorContent;
|
|
463
|
+
exports.FloatingMenu = FloatingMenu;
|
|
464
|
+
exports.NodeViewContent = NodeViewContent;
|
|
465
|
+
exports.NodeViewWrapper = NodeViewWrapper;
|
|
466
|
+
exports.VueNodeViewRenderer = VueNodeViewRenderer;
|
|
467
|
+
exports.VueRenderer = VueRenderer;
|
|
468
|
+
exports.nodeViewProps = nodeViewProps;
|
|
469
|
+
exports.useEditor = useEditor;
|
|
470
|
+
Object.keys(core).forEach(function (k) {
|
|
471
|
+
if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
|
|
472
|
+
enumerable: true,
|
|
473
|
+
get: function () { return core[k]; }
|
|
474
|
+
});
|
|
475
|
+
});
|
|
476
|
+
//# sourceMappingURL=index.cjs.map
|