@tiptap/vue-2 3.30.1 → 3.30.3
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 +402 -488
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +84 -79
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +84 -79
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +371 -449
- package/dist/index.js.map +1 -1
- package/dist/menus/index.cjs +151 -2537
- package/dist/menus/index.cjs.map +1 -1
- package/dist/menus/index.d.cts +39 -222
- package/dist/menus/index.d.cts.map +1 -0
- package/dist/menus/index.d.ts +39 -222
- package/dist/menus/index.d.ts.map +1 -0
- package/dist/menus/index.js +149 -2509
- package/dist/menus/index.js.map +1 -1
- package/package.json +8 -8
package/dist/index.cjs
CHANGED
|
@@ -1,516 +1,430 @@
|
|
|
1
|
-
"
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
2
3
|
var __create = Object.create;
|
|
3
4
|
var __defProp = Object.defineProperty;
|
|
4
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
7
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
8
|
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 });
|
|
11
|
-
};
|
|
12
9
|
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
|
+
get: ((k) => from[k]).bind(null, key),
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
19
18
|
};
|
|
20
|
-
var
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
)
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
EditorContent: () => EditorContent,
|
|
36
|
-
NodeViewContent: () => NodeViewContent,
|
|
37
|
-
NodeViewWrapper: () => NodeViewWrapper,
|
|
38
|
-
VueNodeViewRenderer: () => VueNodeViewRenderer,
|
|
39
|
-
VueRenderer: () => VueRenderer,
|
|
40
|
-
VueWidgetRenderer: () => VueWidgetRenderer,
|
|
41
|
-
nodeViewProps: () => nodeViewProps
|
|
42
|
-
});
|
|
43
|
-
module.exports = __toCommonJS(index_exports);
|
|
44
|
-
|
|
45
|
-
// src/Editor.ts
|
|
46
|
-
var import_core = require("@tiptap/core");
|
|
47
|
-
var Editor = class extends import_core.Editor {
|
|
48
|
-
constructor() {
|
|
49
|
-
super(...arguments);
|
|
50
|
-
this.contentComponent = null;
|
|
51
|
-
}
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
20
|
+
value: mod,
|
|
21
|
+
enumerable: true
|
|
22
|
+
}) : target, mod));
|
|
23
|
+
//#endregion
|
|
24
|
+
let _tiptap_core = require("@tiptap/core");
|
|
25
|
+
let vue_ts_types = require("vue-ts-types");
|
|
26
|
+
let vue = require("vue");
|
|
27
|
+
vue = __toESM(vue, 1);
|
|
28
|
+
//#region src/Editor.ts
|
|
29
|
+
var Editor = class extends _tiptap_core.Editor {
|
|
30
|
+
constructor(..._args) {
|
|
31
|
+
super(..._args);
|
|
32
|
+
this.contentComponent = null;
|
|
33
|
+
}
|
|
52
34
|
};
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
var _a;
|
|
90
|
-
const { editor } = this;
|
|
91
|
-
if (!editor) {
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
if (!editor.isDestroyed) {
|
|
95
|
-
editor.view.setProps({
|
|
96
|
-
nodeViews: {}
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
editor.contentComponent = null;
|
|
100
|
-
if (!((_a = editor.view.dom) == null ? void 0 : _a.parentNode)) {
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
const newElement = document.createElement("div");
|
|
104
|
-
newElement.append(...editor.view.dom.parentNode.childNodes);
|
|
105
|
-
editor.setOptions({
|
|
106
|
-
element: newElement
|
|
107
|
-
});
|
|
108
|
-
}
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region src/EditorContent.ts
|
|
37
|
+
const EditorContent = {
|
|
38
|
+
name: "EditorContent",
|
|
39
|
+
props: { editor: {
|
|
40
|
+
default: null,
|
|
41
|
+
type: Object
|
|
42
|
+
} },
|
|
43
|
+
watch: { editor: {
|
|
44
|
+
immediate: true,
|
|
45
|
+
handler(editor) {
|
|
46
|
+
if (editor && editor.options.element) this.$nextTick(() => {
|
|
47
|
+
var _editor$view$dom;
|
|
48
|
+
const element = this.$el;
|
|
49
|
+
if (!element || !((_editor$view$dom = editor.view.dom) === null || _editor$view$dom === void 0 ? void 0 : _editor$view$dom.parentNode)) return;
|
|
50
|
+
element.append(...editor.view.dom.parentNode.childNodes);
|
|
51
|
+
editor.contentComponent = this;
|
|
52
|
+
editor.setOptions({ element });
|
|
53
|
+
editor.createNodeViews();
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
} },
|
|
57
|
+
render(createElement) {
|
|
58
|
+
return createElement("div");
|
|
59
|
+
},
|
|
60
|
+
beforeDestroy() {
|
|
61
|
+
var _editor$view$dom2;
|
|
62
|
+
const { editor } = this;
|
|
63
|
+
if (!editor) return;
|
|
64
|
+
if (!editor.isDestroyed) editor.view.setProps({ nodeViews: {} });
|
|
65
|
+
editor.contentComponent = null;
|
|
66
|
+
if (!((_editor$view$dom2 = editor.view.dom) === null || _editor$view$dom2 === void 0 ? void 0 : _editor$view$dom2.parentNode)) return;
|
|
67
|
+
const newElement = document.createElement("div");
|
|
68
|
+
newElement.append(...editor.view.dom.parentNode.childNodes);
|
|
69
|
+
editor.setOptions({ element: newElement });
|
|
70
|
+
}
|
|
109
71
|
};
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}
|
|
131
|
-
},
|
|
132
|
-
render(createElement) {
|
|
133
|
-
return createElement(this.as, {
|
|
134
|
-
style: {
|
|
135
|
-
whiteSpace: "pre-wrap"
|
|
136
|
-
},
|
|
137
|
-
attrs: {
|
|
138
|
-
"data-node-view-content": ""
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
}
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region src/NodeViewContent.ts
|
|
74
|
+
const NodeViewContent = {
|
|
75
|
+
props: { as: {
|
|
76
|
+
type: String,
|
|
77
|
+
default: "div"
|
|
78
|
+
} },
|
|
79
|
+
inject: { nodeViewContentRef: { default: void 0 } },
|
|
80
|
+
mounted() {
|
|
81
|
+
if (this.nodeViewContentRef && this.$el) this.nodeViewContentRef(this.$el);
|
|
82
|
+
},
|
|
83
|
+
beforeDestroy() {
|
|
84
|
+
if (this.nodeViewContentRef) this.nodeViewContentRef(null);
|
|
85
|
+
},
|
|
86
|
+
render(createElement) {
|
|
87
|
+
return createElement(this.as, {
|
|
88
|
+
style: { whiteSpace: "pre-wrap" },
|
|
89
|
+
attrs: { "data-node-view-content": "" }
|
|
90
|
+
});
|
|
91
|
+
}
|
|
142
92
|
};
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
whiteSpace: "normal"
|
|
160
|
-
},
|
|
161
|
-
attrs: {
|
|
162
|
-
"data-node-view-wrapper": ""
|
|
163
|
-
},
|
|
164
|
-
on: {
|
|
165
|
-
dragstart: this.onDragStart
|
|
166
|
-
}
|
|
167
|
-
},
|
|
168
|
-
this.$slots.default
|
|
169
|
-
);
|
|
170
|
-
}
|
|
93
|
+
//#endregion
|
|
94
|
+
//#region src/NodeViewWrapper.ts
|
|
95
|
+
const NodeViewWrapper = {
|
|
96
|
+
props: { as: {
|
|
97
|
+
type: String,
|
|
98
|
+
default: "div"
|
|
99
|
+
} },
|
|
100
|
+
inject: ["onDragStart", "decorationClasses"],
|
|
101
|
+
render(createElement) {
|
|
102
|
+
return createElement(this.as, {
|
|
103
|
+
class: this.decorationClasses.value,
|
|
104
|
+
style: { whiteSpace: "normal" },
|
|
105
|
+
attrs: { "data-node-view-wrapper": "" },
|
|
106
|
+
on: { dragstart: this.onDragStart }
|
|
107
|
+
}, this.$slots.default);
|
|
108
|
+
}
|
|
171
109
|
};
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
// src/VueRenderer.ts
|
|
110
|
+
//#endregion
|
|
111
|
+
//#region src/Vue.ts
|
|
112
|
+
const Vue = vue.default;
|
|
113
|
+
//#endregion
|
|
114
|
+
//#region src/VueRenderer.ts
|
|
115
|
+
/**
|
|
116
|
+
* The VueRenderer class is responsible for rendering a Vue component as a ProseMirror node view.
|
|
117
|
+
*/
|
|
182
118
|
var VueRenderer = class {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
this.ref.$destroy();
|
|
205
|
-
}
|
|
119
|
+
constructor(component, props) {
|
|
120
|
+
const Component = typeof component === "function" ? component : Vue.extend(component);
|
|
121
|
+
this.ref = new Component(props).$mount();
|
|
122
|
+
}
|
|
123
|
+
get element() {
|
|
124
|
+
return this.ref.$el;
|
|
125
|
+
}
|
|
126
|
+
updateProps(props = {}) {
|
|
127
|
+
var _this$ref$$props$edit, _this$ref$$props$edit2;
|
|
128
|
+
if (!this.ref.$props) return;
|
|
129
|
+
const currentVueConstructor = (_this$ref$$props$edit = (_this$ref$$props$edit2 = this.ref.$props.editor) === null || _this$ref$$props$edit2 === void 0 || (_this$ref$$props$edit2 = _this$ref$$props$edit2.contentComponent) === null || _this$ref$$props$edit2 === void 0 ? void 0 : _this$ref$$props$edit2.$options._base) !== null && _this$ref$$props$edit !== void 0 ? _this$ref$$props$edit : Vue;
|
|
130
|
+
const originalSilent = currentVueConstructor.config.silent;
|
|
131
|
+
currentVueConstructor.config.silent = true;
|
|
132
|
+
Object.entries(props).forEach(([key, value]) => {
|
|
133
|
+
this.ref.$props[key] = value;
|
|
134
|
+
});
|
|
135
|
+
currentVueConstructor.config.silent = originalSilent;
|
|
136
|
+
}
|
|
137
|
+
destroy() {
|
|
138
|
+
this.ref.$destroy();
|
|
139
|
+
}
|
|
206
140
|
};
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
141
|
+
//#endregion
|
|
142
|
+
//#region src/VueNodeViewRenderer.ts
|
|
143
|
+
const nodeViewProps = {
|
|
144
|
+
editor: (0, vue_ts_types.objectProp)().required,
|
|
145
|
+
node: (0, vue_ts_types.objectProp)().required,
|
|
146
|
+
decorations: (0, vue_ts_types.objectProp)().required,
|
|
147
|
+
selected: (0, vue_ts_types.booleanProp)().required,
|
|
148
|
+
extension: (0, vue_ts_types.objectProp)().required,
|
|
149
|
+
getPos: (0, vue_ts_types.functionProp)().required,
|
|
150
|
+
updateAttributes: (0, vue_ts_types.functionProp)().required,
|
|
151
|
+
deleteNode: (0, vue_ts_types.functionProp)().required
|
|
218
152
|
};
|
|
219
|
-
var VueNodeView = class extends
|
|
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
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
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
|
-
* Select the node.
|
|
391
|
-
* Add the `selected` prop and the `ProseMirror-selectednode` class.
|
|
392
|
-
*/
|
|
393
|
-
selectNode() {
|
|
394
|
-
this.renderer.updateProps({
|
|
395
|
-
selected: true
|
|
396
|
-
});
|
|
397
|
-
this.renderer.element.classList.add("ProseMirror-selectednode");
|
|
398
|
-
}
|
|
399
|
-
/**
|
|
400
|
-
* Deselect the node.
|
|
401
|
-
* Remove the `selected` prop and the `ProseMirror-selectednode` class.
|
|
402
|
-
*/
|
|
403
|
-
deselectNode() {
|
|
404
|
-
this.renderer.updateProps({
|
|
405
|
-
selected: false
|
|
406
|
-
});
|
|
407
|
-
this.renderer.element.classList.remove("ProseMirror-selectednode");
|
|
408
|
-
}
|
|
409
|
-
getDecorationClasses() {
|
|
410
|
-
return this.decorations.flatMap((item) => item.type.attrs.class).join(" ");
|
|
411
|
-
}
|
|
412
|
-
destroy() {
|
|
413
|
-
this.renderer.destroy();
|
|
414
|
-
this.editor.off("selectionUpdate", this.handleSelectionUpdate);
|
|
415
|
-
if (this.options.trackNodeViewPosition) {
|
|
416
|
-
this.editor.off("update", this.handlePositionUpdate);
|
|
417
|
-
}
|
|
418
|
-
this.contentDOMElement = null;
|
|
419
|
-
}
|
|
153
|
+
var VueNodeView = class extends _tiptap_core.NodeView {
|
|
154
|
+
constructor(component, props, options) {
|
|
155
|
+
super(component, props, options);
|
|
156
|
+
this.handlePositionUpdate = () => {
|
|
157
|
+
const newPos = this.getPos();
|
|
158
|
+
if (typeof newPos !== "number" || newPos === this.currentPos) return;
|
|
159
|
+
this.currentPos = newPos;
|
|
160
|
+
this.renderer.updateProps({ getPos: () => this.getPos() });
|
|
161
|
+
};
|
|
162
|
+
if (this.options.trackNodeViewPosition) this.editor.on("update", this.handlePositionUpdate);
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Called when the node view is mounted.
|
|
166
|
+
*/
|
|
167
|
+
mount() {
|
|
168
|
+
var _this$editor$contentC, _this$editor$contentC2;
|
|
169
|
+
const props = {
|
|
170
|
+
editor: this.editor,
|
|
171
|
+
node: this.node,
|
|
172
|
+
decorations: this.decorations,
|
|
173
|
+
innerDecorations: this.innerDecorations,
|
|
174
|
+
view: this.view,
|
|
175
|
+
selected: false,
|
|
176
|
+
extension: this.extension,
|
|
177
|
+
HTMLAttributes: this.HTMLAttributes,
|
|
178
|
+
getPos: () => this.getPos(),
|
|
179
|
+
updateAttributes: (attributes = {}) => this.updateAttributes(attributes),
|
|
180
|
+
deleteNode: () => this.deleteNode()
|
|
181
|
+
};
|
|
182
|
+
const mountProps = props;
|
|
183
|
+
const onDragStart = this.onDragStart.bind(this);
|
|
184
|
+
this.decorationClasses = Vue.observable({ value: this.getDecorationClasses() });
|
|
185
|
+
const Component = ((_this$editor$contentC = (_this$editor$contentC2 = this.editor.contentComponent) === null || _this$editor$contentC2 === void 0 ? void 0 : _this$editor$contentC2.$options._base) !== null && _this$editor$contentC !== void 0 ? _this$editor$contentC : Vue).extend(this.component).extend({
|
|
186
|
+
props: Object.keys(props),
|
|
187
|
+
provide: () => {
|
|
188
|
+
return {
|
|
189
|
+
onDragStart,
|
|
190
|
+
decorationClasses: this.decorationClasses,
|
|
191
|
+
nodeViewContentRef: (el) => {
|
|
192
|
+
if (!this.contentDOMElement) return;
|
|
193
|
+
if (el && el.firstChild !== this.contentDOMElement) el.appendChild(this.contentDOMElement);
|
|
194
|
+
}
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
this.handleSelectionUpdate = this.handleSelectionUpdate.bind(this);
|
|
199
|
+
this.editor.on("selectionUpdate", this.handleSelectionUpdate);
|
|
200
|
+
this.currentPos = this.getPos();
|
|
201
|
+
if (!this.node.isLeaf) {
|
|
202
|
+
if (this.options.contentDOMElementTag) this.contentDOMElement = document.createElement(this.options.contentDOMElementTag);
|
|
203
|
+
else this.contentDOMElement = document.createElement(this.node.isInline ? "span" : "div");
|
|
204
|
+
this.contentDOMElement.style.whiteSpace = "inherit";
|
|
205
|
+
this.contentDOMElement.dataset.nodeViewContentVue = "";
|
|
206
|
+
}
|
|
207
|
+
this.renderer = new VueRenderer(Component, {
|
|
208
|
+
parent: this.editor.contentComponent,
|
|
209
|
+
propsData: mountProps
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Return the DOM element.
|
|
214
|
+
* This is the element that will be used to display the node view.
|
|
215
|
+
*/
|
|
216
|
+
get dom() {
|
|
217
|
+
if (!this.renderer.element.hasAttribute("data-node-view-wrapper")) throw Error("Please use the NodeViewWrapper component for your node view.");
|
|
218
|
+
return this.renderer.element;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Return the content DOM element.
|
|
222
|
+
* This is the element that will be used to display the rich-text content of the node.
|
|
223
|
+
*/
|
|
224
|
+
get contentDOM() {
|
|
225
|
+
if (this.node.isLeaf) return null;
|
|
226
|
+
return this.contentDOMElement;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* On editor selection update, check if the node is selected.
|
|
230
|
+
* If it is, call `selectNode`, otherwise call `deselectNode`.
|
|
231
|
+
*/
|
|
232
|
+
handleSelectionUpdate() {
|
|
233
|
+
const pos = this.getPos();
|
|
234
|
+
if (typeof pos !== "number") return;
|
|
235
|
+
if ((0, _tiptap_core.isNodeViewSelected)({
|
|
236
|
+
selection: this.editor.state.selection,
|
|
237
|
+
pos,
|
|
238
|
+
nodeSize: this.node.nodeSize,
|
|
239
|
+
selectedOnTextSelection: this.options.selectedOnTextSelection
|
|
240
|
+
})) {
|
|
241
|
+
if (this.renderer.ref.$props.selected) return;
|
|
242
|
+
this.selectNode();
|
|
243
|
+
} else {
|
|
244
|
+
if (!this.renderer.ref.$props.selected) return;
|
|
245
|
+
this.deselectNode();
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* On update, update the React component.
|
|
250
|
+
* To prevent unnecessary updates, the `update` option can be used.
|
|
251
|
+
*/
|
|
252
|
+
update(node, decorations, innerDecorations) {
|
|
253
|
+
const rerenderComponent = (props) => {
|
|
254
|
+
this.decorationClasses.value = this.getDecorationClasses();
|
|
255
|
+
this.renderer.updateProps(props);
|
|
256
|
+
};
|
|
257
|
+
if (typeof this.options.update === "function") {
|
|
258
|
+
const oldNode = this.node;
|
|
259
|
+
const oldDecorations = this.decorations;
|
|
260
|
+
const oldInnerDecorations = this.innerDecorations;
|
|
261
|
+
this.node = node;
|
|
262
|
+
this.decorations = decorations;
|
|
263
|
+
this.innerDecorations = innerDecorations;
|
|
264
|
+
return this.options.update({
|
|
265
|
+
oldNode,
|
|
266
|
+
oldDecorations,
|
|
267
|
+
newNode: node,
|
|
268
|
+
newDecorations: decorations,
|
|
269
|
+
oldInnerDecorations,
|
|
270
|
+
innerDecorations,
|
|
271
|
+
updateProps: () => rerenderComponent({
|
|
272
|
+
node,
|
|
273
|
+
decorations,
|
|
274
|
+
innerDecorations
|
|
275
|
+
})
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
if (node.type !== this.node.type) return false;
|
|
279
|
+
if (!(node !== this.node)) {
|
|
280
|
+
this.node = node;
|
|
281
|
+
this.decorations = decorations;
|
|
282
|
+
this.innerDecorations = innerDecorations;
|
|
283
|
+
this.decorationClasses.value = this.getDecorationClasses();
|
|
284
|
+
return true;
|
|
285
|
+
}
|
|
286
|
+
this.node = node;
|
|
287
|
+
this.decorations = decorations;
|
|
288
|
+
this.innerDecorations = innerDecorations;
|
|
289
|
+
this.currentPos = this.getPos();
|
|
290
|
+
const extraProps = {
|
|
291
|
+
node,
|
|
292
|
+
decorations,
|
|
293
|
+
innerDecorations
|
|
294
|
+
};
|
|
295
|
+
if (this.options.trackNodeViewPosition) extraProps.getPos = () => this.getPos();
|
|
296
|
+
rerenderComponent(extraProps);
|
|
297
|
+
return true;
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Select the node.
|
|
301
|
+
* Add the `selected` prop and the `ProseMirror-selectednode` class.
|
|
302
|
+
*/
|
|
303
|
+
selectNode() {
|
|
304
|
+
this.renderer.updateProps({ selected: true });
|
|
305
|
+
this.renderer.element.classList.add("ProseMirror-selectednode");
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Deselect the node.
|
|
309
|
+
* Remove the `selected` prop and the `ProseMirror-selectednode` class.
|
|
310
|
+
*/
|
|
311
|
+
deselectNode() {
|
|
312
|
+
this.renderer.updateProps({ selected: false });
|
|
313
|
+
this.renderer.element.classList.remove("ProseMirror-selectednode");
|
|
314
|
+
}
|
|
315
|
+
getDecorationClasses() {
|
|
316
|
+
return this.decorations.flatMap((item) => item.type.attrs.class).join(" ");
|
|
317
|
+
}
|
|
318
|
+
destroy() {
|
|
319
|
+
this.renderer.destroy();
|
|
320
|
+
this.editor.off("selectionUpdate", this.handleSelectionUpdate);
|
|
321
|
+
if (this.options.trackNodeViewPosition) this.editor.off("update", this.handlePositionUpdate);
|
|
322
|
+
this.contentDOMElement = null;
|
|
323
|
+
}
|
|
420
324
|
};
|
|
421
325
|
function VueNodeViewRenderer(component, options) {
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
return new VueNodeView(component, props, options);
|
|
427
|
-
};
|
|
326
|
+
return (props) => {
|
|
327
|
+
if (!props.editor.contentComponent) return {};
|
|
328
|
+
return new VueNodeView(component, props, options);
|
|
329
|
+
};
|
|
428
330
|
}
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
331
|
+
//#endregion
|
|
332
|
+
//#region src/utils/createWidgetConstructor.ts
|
|
333
|
+
/**
|
|
334
|
+
* Builds the Vue 2 constructor for a widget component.
|
|
335
|
+
*
|
|
336
|
+
* Extends the editor's own Vue constructor so the widget shares its context,
|
|
337
|
+
* then auto-declares every passed prop the component does not declare itself.
|
|
338
|
+
* Vue 2 fixes the prop list at construction, so undeclared keys would be
|
|
339
|
+
* dropped. Existing declarations keep their type, default and validator.
|
|
340
|
+
*
|
|
341
|
+
* @param base The editor's Vue constructor, or undefined to fall back to `Vue`.
|
|
342
|
+
* @param component The widget component.
|
|
343
|
+
* @param props The props the widget is mounted with.
|
|
344
|
+
* @returns A constructor that accepts every key in `props`.
|
|
345
|
+
* @example
|
|
346
|
+
* createWidgetConstructor(undefined, MyWidget, { editor, getPos, label: 'a' })
|
|
347
|
+
*/
|
|
434
348
|
function createWidgetConstructor(base, component, props) {
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
};
|
|
440
|
-
for (const name of Object.keys(props)) {
|
|
441
|
-
if (!Object.prototype.hasOwnProperty.call(declaredProps, name)) {
|
|
442
|
-
declaredProps[name] = null;
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
return Extended.extend({ props: declaredProps });
|
|
349
|
+
const Extended = (base !== null && base !== void 0 ? base : Vue).extend(component);
|
|
350
|
+
const declaredProps = { ...Extended.options.props };
|
|
351
|
+
for (const name of Object.keys(props)) if (!Object.prototype.hasOwnProperty.call(declaredProps, name)) declaredProps[name] = null;
|
|
352
|
+
return Extended.extend({ props: declaredProps });
|
|
446
353
|
}
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
354
|
+
//#endregion
|
|
355
|
+
//#region src/VueWidgetRenderer.ts
|
|
356
|
+
const WIDGET_CACHE = Symbol("tiptapVue2WidgetCache");
|
|
357
|
+
const isDev = process.env.NODE_ENV !== "production";
|
|
451
358
|
function warnUndeclaredProps(renderer, props, key) {
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
const declared = (_a = renderer.ref.$props) != null ? _a : {};
|
|
457
|
-
for (const name of Object.keys(props)) {
|
|
458
|
-
if (!(name in declared)) {
|
|
459
|
-
console.warn(
|
|
460
|
-
`[tiptap warn]: VueWidgetRenderer prop "${name}" was not passed on first mount for widget "${key}".`,
|
|
461
|
-
"Vue 2 cannot declare new props after mount, so this value is ignored."
|
|
462
|
-
);
|
|
463
|
-
}
|
|
464
|
-
}
|
|
359
|
+
var _renderer$ref$$props;
|
|
360
|
+
if (!isDev) return;
|
|
361
|
+
const declared = (_renderer$ref$$props = renderer.ref.$props) !== null && _renderer$ref$$props !== void 0 ? _renderer$ref$$props : {};
|
|
362
|
+
for (const name of Object.keys(props)) if (!(name in declared)) console.warn(`[tiptap warn]: VueWidgetRenderer prop "${name}" was not passed on first mount for widget "${key}".`, "Vue 2 cannot declare new props after mount, so this value is ignored.");
|
|
465
363
|
}
|
|
466
364
|
function withPropWarnings(renderer, key) {
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
365
|
+
return {
|
|
366
|
+
renderer,
|
|
367
|
+
updateProps: (props) => {
|
|
368
|
+
warnUndeclaredProps(renderer, props, key);
|
|
369
|
+
renderer.updateProps(props);
|
|
370
|
+
},
|
|
371
|
+
destroy: () => renderer.destroy()
|
|
372
|
+
};
|
|
475
373
|
}
|
|
374
|
+
/**
|
|
375
|
+
* Renders a Vue 2 component into a ProseMirror widget decoration.
|
|
376
|
+
* Reuses Tiptap's `VueRenderer` so the component is mounted under the editor's
|
|
377
|
+
* content component (inject/provide works as usual). Use a stable `key` for
|
|
378
|
+
* stateful widgets. The component must render a single root element.
|
|
379
|
+
* @example
|
|
380
|
+
* addDecorations() {
|
|
381
|
+
* return {
|
|
382
|
+
* create: ({ editor, state }) =>
|
|
383
|
+
* findMatches(state.doc).map(match =>
|
|
384
|
+
* VueWidgetRenderer(MyWidget, {
|
|
385
|
+
* editor, pos: match.pos, key: `match-${match.id}`,
|
|
386
|
+
* props: { label: match.label },
|
|
387
|
+
* }),
|
|
388
|
+
* ),
|
|
389
|
+
* }
|
|
390
|
+
* }
|
|
391
|
+
*/
|
|
476
392
|
function VueWidgetRenderer(component, options) {
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
key
|
|
496
|
-
);
|
|
497
|
-
},
|
|
498
|
-
materialize: (entry) => entry.renderer.element
|
|
499
|
-
});
|
|
393
|
+
const { editor, key, props = {} } = options;
|
|
394
|
+
return (0, _tiptap_core.createWidgetDecoration)({
|
|
395
|
+
...options,
|
|
396
|
+
props,
|
|
397
|
+
cacheKey: WIDGET_CACHE,
|
|
398
|
+
context: (getPos) => ({
|
|
399
|
+
editor,
|
|
400
|
+
getPos
|
|
401
|
+
}),
|
|
402
|
+
create: (renderProps) => {
|
|
403
|
+
var _editor$contentCompon;
|
|
404
|
+
return withPropWarnings(new VueRenderer(createWidgetConstructor((_editor$contentCompon = editor.contentComponent) === null || _editor$contentCompon === void 0 || (_editor$contentCompon = _editor$contentCompon.$options) === null || _editor$contentCompon === void 0 ? void 0 : _editor$contentCompon._base, component, renderProps), {
|
|
405
|
+
parent: editor.contentComponent,
|
|
406
|
+
propsData: renderProps
|
|
407
|
+
}), key);
|
|
408
|
+
},
|
|
409
|
+
materialize: (entry) => entry.renderer.element
|
|
410
|
+
});
|
|
500
411
|
}
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
412
|
+
//#endregion
|
|
413
|
+
exports.Editor = Editor;
|
|
414
|
+
exports.EditorContent = EditorContent;
|
|
415
|
+
exports.NodeViewContent = NodeViewContent;
|
|
416
|
+
exports.NodeViewWrapper = NodeViewWrapper;
|
|
417
|
+
exports.VueNodeViewRenderer = VueNodeViewRenderer;
|
|
418
|
+
exports.VueRenderer = VueRenderer;
|
|
419
|
+
exports.VueWidgetRenderer = VueWidgetRenderer;
|
|
420
|
+
exports.nodeViewProps = nodeViewProps;
|
|
421
|
+
Object.keys(_tiptap_core).forEach(function(k) {
|
|
422
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
423
|
+
enumerable: true,
|
|
424
|
+
get: function() {
|
|
425
|
+
return _tiptap_core[k];
|
|
426
|
+
}
|
|
427
|
+
});
|
|
515
428
|
});
|
|
429
|
+
|
|
516
430
|
//# sourceMappingURL=index.cjs.map
|