@tiptap/vue-2 2.11.7 → 3.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +21 -0
- package/README.md +5 -1
- package/dist/index.cjs +340 -407
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +79 -0
- package/dist/index.d.ts +78 -9
- package/dist/index.js +298 -391
- package/dist/index.js.map +1 -1
- package/dist/menus/index.cjs +2140 -0
- package/dist/menus/index.cjs.map +1 -0
- package/dist/menus/index.d.cts +131 -0
- package/dist/menus/index.d.ts +131 -0
- package/dist/menus/index.js +2112 -0
- package/dist/menus/index.js.map +1 -0
- package/package.json +25 -13
- package/src/Editor.ts +1 -1
- package/src/EditorContent.ts +7 -5
- package/src/NodeViewContent.ts +3 -2
- package/src/NodeViewWrapper.ts +6 -5
- package/src/VueNodeViewRenderer.ts +18 -29
- package/src/VueRenderer.ts +5 -7
- package/src/index.ts +0 -2
- package/src/menus/BubbleMenu.ts +85 -0
- package/src/{FloatingMenu.ts → menus/FloatingMenu.ts} +24 -15
- package/src/menus/index.ts +2 -0
- package/dist/BubbleMenu.d.ts +0 -11
- package/dist/BubbleMenu.d.ts.map +0 -1
- package/dist/Editor.d.ts +0 -6
- package/dist/Editor.d.ts.map +0 -1
- package/dist/EditorContent.d.ts +0 -7
- package/dist/EditorContent.d.ts.map +0 -1
- package/dist/FloatingMenu.d.ts +0 -10
- package/dist/FloatingMenu.d.ts.map +0 -1
- package/dist/NodeViewContent.d.ts +0 -6
- package/dist/NodeViewContent.d.ts.map +0 -1
- package/dist/NodeViewWrapper.d.ts +0 -10
- package/dist/NodeViewWrapper.d.ts.map +0 -1
- package/dist/VueNodeViewRenderer.d.ts +0 -40
- package/dist/VueNodeViewRenderer.d.ts.map +0 -1
- package/dist/VueRenderer.d.ts +0 -13
- package/dist/VueRenderer.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.umd.js +0 -433
- package/dist/index.umd.js.map +0 -1
- package/src/BubbleMenu.ts +0 -70
package/dist/index.cjs
CHANGED
|
@@ -1,437 +1,370 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
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 });
|
|
11
|
+
};
|
|
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;
|
|
19
|
+
};
|
|
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);
|
|
10
30
|
|
|
11
|
-
|
|
31
|
+
// src/index.ts
|
|
32
|
+
var index_exports = {};
|
|
33
|
+
__export(index_exports, {
|
|
34
|
+
Editor: () => Editor,
|
|
35
|
+
EditorContent: () => EditorContent,
|
|
36
|
+
NodeViewContent: () => NodeViewContent,
|
|
37
|
+
NodeViewWrapper: () => NodeViewWrapper,
|
|
38
|
+
VueNodeViewRenderer: () => VueNodeViewRenderer,
|
|
39
|
+
VueRenderer: () => VueRenderer,
|
|
40
|
+
nodeViewProps: () => nodeViewProps
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(index_exports);
|
|
12
43
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
editor: {
|
|
21
|
-
type: Object,
|
|
22
|
-
required: true,
|
|
23
|
-
},
|
|
24
|
-
updateDelay: {
|
|
25
|
-
type: Number,
|
|
26
|
-
},
|
|
27
|
-
tippyOptions: {
|
|
28
|
-
type: Object,
|
|
29
|
-
default: () => ({}),
|
|
30
|
-
},
|
|
31
|
-
shouldShow: {
|
|
32
|
-
type: Function,
|
|
33
|
-
default: null,
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
watch: {
|
|
37
|
-
editor: {
|
|
38
|
-
immediate: true,
|
|
39
|
-
handler(editor) {
|
|
40
|
-
if (!editor) {
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
this.$nextTick(() => {
|
|
44
|
-
editor.registerPlugin(extensionBubbleMenu.BubbleMenuPlugin({
|
|
45
|
-
updateDelay: this.updateDelay,
|
|
46
|
-
editor,
|
|
47
|
-
element: this.$el,
|
|
48
|
-
pluginKey: this.pluginKey,
|
|
49
|
-
shouldShow: this.shouldShow,
|
|
50
|
-
tippyOptions: this.tippyOptions,
|
|
51
|
-
}));
|
|
52
|
-
});
|
|
53
|
-
},
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
render(createElement) {
|
|
57
|
-
return createElement('div', { style: { visibility: 'hidden' } }, this.$slots.default);
|
|
58
|
-
},
|
|
59
|
-
beforeDestroy() {
|
|
60
|
-
this.editor.unregisterPlugin(this.pluginKey);
|
|
61
|
-
},
|
|
44
|
+
// src/Editor.ts
|
|
45
|
+
var import_core = require("@tiptap/core");
|
|
46
|
+
var Editor = class extends import_core.Editor {
|
|
47
|
+
constructor() {
|
|
48
|
+
super(...arguments);
|
|
49
|
+
this.contentComponent = null;
|
|
50
|
+
}
|
|
62
51
|
};
|
|
63
52
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
53
|
+
// src/EditorContent.ts
|
|
54
|
+
var EditorContent = {
|
|
55
|
+
name: "EditorContent",
|
|
56
|
+
props: {
|
|
57
|
+
editor: {
|
|
58
|
+
default: null,
|
|
59
|
+
type: Object
|
|
68
60
|
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
editor
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const element = this.$el;
|
|
86
|
-
if (!element || !editor.options.element.firstChild) {
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
element.append(...editor.options.element.childNodes);
|
|
90
|
-
editor.contentComponent = this;
|
|
91
|
-
editor.setOptions({
|
|
92
|
-
element,
|
|
93
|
-
});
|
|
94
|
-
editor.createNodeViews();
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
},
|
|
98
|
-
},
|
|
99
|
-
},
|
|
100
|
-
render(createElement) {
|
|
101
|
-
return createElement('div');
|
|
102
|
-
},
|
|
103
|
-
beforeDestroy() {
|
|
104
|
-
const { editor } = this;
|
|
105
|
-
if (!editor) {
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
108
|
-
if (!editor.isDestroyed) {
|
|
109
|
-
editor.view.setProps({
|
|
110
|
-
nodeViews: {},
|
|
61
|
+
},
|
|
62
|
+
watch: {
|
|
63
|
+
editor: {
|
|
64
|
+
immediate: true,
|
|
65
|
+
handler(editor) {
|
|
66
|
+
if (editor && editor.options.element) {
|
|
67
|
+
this.$nextTick(() => {
|
|
68
|
+
var _a;
|
|
69
|
+
const element = this.$el;
|
|
70
|
+
if (!element || !((_a = editor.options.element) == null ? void 0 : _a.firstChild)) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
element.append(...editor.options.element.childNodes);
|
|
74
|
+
editor.contentComponent = this;
|
|
75
|
+
editor.setOptions({
|
|
76
|
+
element
|
|
111
77
|
});
|
|
78
|
+
editor.createNodeViews();
|
|
79
|
+
});
|
|
112
80
|
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
render(createElement) {
|
|
85
|
+
return createElement("div");
|
|
86
|
+
},
|
|
87
|
+
beforeDestroy() {
|
|
88
|
+
var _a;
|
|
89
|
+
const { editor } = this;
|
|
90
|
+
if (!editor) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
if (!editor.isDestroyed) {
|
|
94
|
+
editor.view.setProps({
|
|
95
|
+
nodeViews: {}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
editor.contentComponent = null;
|
|
99
|
+
if (!((_a = editor.options.element) == null ? void 0 : _a.firstChild)) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const newElement = document.createElement("div");
|
|
103
|
+
newElement.append(...editor.options.element.childNodes);
|
|
104
|
+
editor.setOptions({
|
|
105
|
+
element: newElement
|
|
106
|
+
});
|
|
107
|
+
}
|
|
123
108
|
};
|
|
124
109
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
},
|
|
144
|
-
},
|
|
145
|
-
watch: {
|
|
146
|
-
editor: {
|
|
147
|
-
immediate: true,
|
|
148
|
-
handler(editor) {
|
|
149
|
-
if (!editor) {
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
this.$nextTick(() => {
|
|
153
|
-
editor.registerPlugin(extensionFloatingMenu.FloatingMenuPlugin({
|
|
154
|
-
pluginKey: this.pluginKey,
|
|
155
|
-
editor,
|
|
156
|
-
element: this.$el,
|
|
157
|
-
tippyOptions: this.tippyOptions,
|
|
158
|
-
shouldShow: this.shouldShow,
|
|
159
|
-
}));
|
|
160
|
-
});
|
|
161
|
-
},
|
|
162
|
-
},
|
|
163
|
-
},
|
|
164
|
-
render(createElement) {
|
|
165
|
-
return createElement('div', { style: { visibility: 'hidden' } }, this.$slots.default);
|
|
166
|
-
},
|
|
167
|
-
beforeDestroy() {
|
|
168
|
-
this.editor.unregisterPlugin(this.pluginKey);
|
|
169
|
-
},
|
|
110
|
+
// src/NodeViewContent.ts
|
|
111
|
+
var NodeViewContent = {
|
|
112
|
+
props: {
|
|
113
|
+
as: {
|
|
114
|
+
type: String,
|
|
115
|
+
default: "div"
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
render(createElement) {
|
|
119
|
+
return createElement(this.as, {
|
|
120
|
+
style: {
|
|
121
|
+
whiteSpace: "pre-wrap"
|
|
122
|
+
},
|
|
123
|
+
attrs: {
|
|
124
|
+
"data-node-view-content": ""
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
}
|
|
170
128
|
};
|
|
171
129
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
130
|
+
// src/NodeViewWrapper.ts
|
|
131
|
+
var NodeViewWrapper = {
|
|
132
|
+
props: {
|
|
133
|
+
as: {
|
|
134
|
+
type: String,
|
|
135
|
+
default: "div"
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
inject: ["onDragStart", "decorationClasses"],
|
|
139
|
+
render(createElement) {
|
|
140
|
+
return createElement(
|
|
141
|
+
this.as,
|
|
142
|
+
{
|
|
143
|
+
class: this.decorationClasses.value,
|
|
144
|
+
style: {
|
|
145
|
+
whiteSpace: "normal"
|
|
177
146
|
},
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
return createElement(this.as, {
|
|
181
|
-
style: {
|
|
182
|
-
whiteSpace: 'pre-wrap',
|
|
183
|
-
},
|
|
184
|
-
attrs: {
|
|
185
|
-
'data-node-view-content': '',
|
|
186
|
-
},
|
|
187
|
-
});
|
|
188
|
-
},
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
const NodeViewWrapper = {
|
|
192
|
-
props: {
|
|
193
|
-
as: {
|
|
194
|
-
type: String,
|
|
195
|
-
default: 'div',
|
|
147
|
+
attrs: {
|
|
148
|
+
"data-node-view-wrapper": ""
|
|
196
149
|
},
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
},
|
|
205
|
-
attrs: {
|
|
206
|
-
'data-node-view-wrapper': '',
|
|
207
|
-
},
|
|
208
|
-
on: {
|
|
209
|
-
dragstart: this.onDragStart,
|
|
210
|
-
},
|
|
211
|
-
}, this.$slots.default);
|
|
212
|
-
},
|
|
150
|
+
on: {
|
|
151
|
+
dragstart: this.onDragStart
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
this.$slots.default
|
|
155
|
+
);
|
|
156
|
+
}
|
|
213
157
|
};
|
|
214
158
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
const originalSilent = currentVueConstructor.config.silent;
|
|
235
|
-
currentVueConstructor.config.silent = true;
|
|
236
|
-
Object
|
|
237
|
-
.entries(props)
|
|
238
|
-
.forEach(([key, value]) => {
|
|
239
|
-
this.ref.$props[key] = value;
|
|
240
|
-
});
|
|
241
|
-
currentVueConstructor.config.silent = originalSilent;
|
|
242
|
-
}
|
|
243
|
-
destroy() {
|
|
244
|
-
this.ref.$destroy();
|
|
159
|
+
// src/VueNodeViewRenderer.ts
|
|
160
|
+
var import_core2 = require("@tiptap/core");
|
|
161
|
+
var import_vue2 = __toESM(require("vue"), 1);
|
|
162
|
+
var import_vue_ts_types = require("vue-ts-types");
|
|
163
|
+
|
|
164
|
+
// src/VueRenderer.ts
|
|
165
|
+
var import_vue = __toESM(require("vue"), 1);
|
|
166
|
+
var VueRenderer = class {
|
|
167
|
+
constructor(component, props) {
|
|
168
|
+
const Component = typeof component === "function" ? component : import_vue.default.extend(component);
|
|
169
|
+
this.ref = new Component(props).$mount();
|
|
170
|
+
}
|
|
171
|
+
get element() {
|
|
172
|
+
return this.ref.$el;
|
|
173
|
+
}
|
|
174
|
+
updateProps(props = {}) {
|
|
175
|
+
var _a, _b, _c;
|
|
176
|
+
if (!this.ref.$props) {
|
|
177
|
+
return;
|
|
245
178
|
}
|
|
246
|
-
|
|
179
|
+
const currentVueConstructor = (_c = (_b = (_a = this.ref.$props.editor) == null ? void 0 : _a.contentComponent) == null ? void 0 : _b.$options._base) != null ? _c : import_vue.default;
|
|
180
|
+
const originalSilent = currentVueConstructor.config.silent;
|
|
181
|
+
currentVueConstructor.config.silent = true;
|
|
182
|
+
Object.entries(props).forEach(([key, value]) => {
|
|
183
|
+
this.ref.$props[key] = value;
|
|
184
|
+
});
|
|
185
|
+
currentVueConstructor.config.silent = originalSilent;
|
|
186
|
+
}
|
|
187
|
+
destroy() {
|
|
188
|
+
this.ref.$destroy();
|
|
189
|
+
}
|
|
190
|
+
};
|
|
247
191
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
192
|
+
// src/VueNodeViewRenderer.ts
|
|
193
|
+
var nodeViewProps = {
|
|
194
|
+
editor: (0, import_vue_ts_types.objectProp)().required,
|
|
195
|
+
node: (0, import_vue_ts_types.objectProp)().required,
|
|
196
|
+
decorations: (0, import_vue_ts_types.objectProp)().required,
|
|
197
|
+
selected: (0, import_vue_ts_types.booleanProp)().required,
|
|
198
|
+
extension: (0, import_vue_ts_types.objectProp)().required,
|
|
199
|
+
getPos: (0, import_vue_ts_types.functionProp)().required,
|
|
200
|
+
updateAttributes: (0, import_vue_ts_types.functionProp)().required,
|
|
201
|
+
deleteNode: (0, import_vue_ts_types.functionProp)().required
|
|
257
202
|
};
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
203
|
+
var VueNodeView = class extends import_core2.NodeView {
|
|
204
|
+
mount() {
|
|
205
|
+
var _a, _b;
|
|
206
|
+
const props = {
|
|
207
|
+
editor: this.editor,
|
|
208
|
+
node: this.node,
|
|
209
|
+
decorations: this.decorations,
|
|
210
|
+
innerDecorations: this.innerDecorations,
|
|
211
|
+
view: this.view,
|
|
212
|
+
selected: false,
|
|
213
|
+
extension: this.extension,
|
|
214
|
+
HTMLAttributes: this.HTMLAttributes,
|
|
215
|
+
getPos: () => this.getPos(),
|
|
216
|
+
updateAttributes: (attributes = {}) => this.updateAttributes(attributes),
|
|
217
|
+
deleteNode: () => this.deleteNode()
|
|
218
|
+
};
|
|
219
|
+
const onDragStart = this.onDragStart.bind(this);
|
|
220
|
+
this.decorationClasses = import_vue2.default.observable({
|
|
221
|
+
value: this.getDecorationClasses()
|
|
222
|
+
});
|
|
223
|
+
const vue = (_b = (_a = this.editor.contentComponent) == null ? void 0 : _a.$options._base) != null ? _b : import_vue2.default;
|
|
224
|
+
const Component = vue.extend(this.component).extend({
|
|
225
|
+
props: Object.keys(props),
|
|
226
|
+
provide: () => {
|
|
227
|
+
return {
|
|
228
|
+
onDragStart,
|
|
229
|
+
decorationClasses: this.decorationClasses
|
|
273
230
|
};
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
this.editor.on('selectionUpdate', this.handleSelectionUpdate);
|
|
291
|
-
this.renderer = new VueRenderer(Component, {
|
|
292
|
-
parent: this.editor.contentComponent,
|
|
293
|
-
propsData: props,
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
|
-
/**
|
|
297
|
-
* Return the DOM element.
|
|
298
|
-
* This is the element that will be used to display the node view.
|
|
299
|
-
*/
|
|
300
|
-
get dom() {
|
|
301
|
-
if (!this.renderer.element.hasAttribute('data-node-view-wrapper')) {
|
|
302
|
-
throw Error('Please use the NodeViewWrapper component for your node view.');
|
|
303
|
-
}
|
|
304
|
-
return this.renderer.element;
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
this.handleSelectionUpdate = this.handleSelectionUpdate.bind(this);
|
|
234
|
+
this.editor.on("selectionUpdate", this.handleSelectionUpdate);
|
|
235
|
+
this.renderer = new VueRenderer(Component, {
|
|
236
|
+
parent: this.editor.contentComponent,
|
|
237
|
+
propsData: props
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Return the DOM element.
|
|
242
|
+
* This is the element that will be used to display the node view.
|
|
243
|
+
*/
|
|
244
|
+
get dom() {
|
|
245
|
+
if (!this.renderer.element.hasAttribute("data-node-view-wrapper")) {
|
|
246
|
+
throw Error("Please use the NodeViewWrapper component for your node view.");
|
|
305
247
|
}
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
return (contentElement || this.dom);
|
|
316
|
-
}
|
|
317
|
-
/**
|
|
318
|
-
* On editor selection update, check if the node is selected.
|
|
319
|
-
* If it is, call `selectNode`, otherwise call `deselectNode`.
|
|
320
|
-
*/
|
|
321
|
-
handleSelectionUpdate() {
|
|
322
|
-
const { from, to } = this.editor.state.selection;
|
|
323
|
-
const pos = this.getPos();
|
|
324
|
-
if (typeof pos !== 'number') {
|
|
325
|
-
return;
|
|
326
|
-
}
|
|
327
|
-
if (from <= pos && to >= pos + this.node.nodeSize) {
|
|
328
|
-
if (this.renderer.ref.$props.selected) {
|
|
329
|
-
return;
|
|
330
|
-
}
|
|
331
|
-
this.selectNode();
|
|
332
|
-
}
|
|
333
|
-
else {
|
|
334
|
-
if (!this.renderer.ref.$props.selected) {
|
|
335
|
-
return;
|
|
336
|
-
}
|
|
337
|
-
this.deselectNode();
|
|
338
|
-
}
|
|
248
|
+
return this.renderer.element;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Return the content DOM element.
|
|
252
|
+
* This is the element that will be used to display the rich-text content of the node.
|
|
253
|
+
*/
|
|
254
|
+
get contentDOM() {
|
|
255
|
+
if (this.node.isLeaf) {
|
|
256
|
+
return null;
|
|
339
257
|
}
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
const oldDecorations = this.decorations;
|
|
352
|
-
const oldInnerDecorations = this.innerDecorations;
|
|
353
|
-
this.node = node;
|
|
354
|
-
this.decorations = decorations;
|
|
355
|
-
this.innerDecorations = innerDecorations;
|
|
356
|
-
return this.options.update({
|
|
357
|
-
oldNode,
|
|
358
|
-
oldDecorations,
|
|
359
|
-
newNode: node,
|
|
360
|
-
newDecorations: decorations,
|
|
361
|
-
oldInnerDecorations,
|
|
362
|
-
innerDecorations,
|
|
363
|
-
updateProps: () => rerenderComponent({ node, decorations, innerDecorations }),
|
|
364
|
-
});
|
|
365
|
-
}
|
|
366
|
-
if (node.type !== this.node.type) {
|
|
367
|
-
return false;
|
|
368
|
-
}
|
|
369
|
-
if (node === this.node && this.decorations === decorations && this.innerDecorations === innerDecorations) {
|
|
370
|
-
return true;
|
|
371
|
-
}
|
|
372
|
-
this.node = node;
|
|
373
|
-
this.decorations = decorations;
|
|
374
|
-
this.innerDecorations = innerDecorations;
|
|
375
|
-
rerenderComponent({ node, decorations, innerDecorations });
|
|
376
|
-
return true;
|
|
258
|
+
return this.dom.querySelector("[data-node-view-content]");
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* On editor selection update, check if the node is selected.
|
|
262
|
+
* If it is, call `selectNode`, otherwise call `deselectNode`.
|
|
263
|
+
*/
|
|
264
|
+
handleSelectionUpdate() {
|
|
265
|
+
const { from, to } = this.editor.state.selection;
|
|
266
|
+
const pos = this.getPos();
|
|
267
|
+
if (typeof pos !== "number") {
|
|
268
|
+
return;
|
|
377
269
|
}
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
270
|
+
if (from <= pos && to >= pos + this.node.nodeSize) {
|
|
271
|
+
if (this.renderer.ref.$props.selected) {
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
this.selectNode();
|
|
275
|
+
} else {
|
|
276
|
+
if (!this.renderer.ref.$props.selected) {
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
this.deselectNode();
|
|
387
280
|
}
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* On update, update the React component.
|
|
284
|
+
* To prevent unnecessary updates, the `update` option can be used.
|
|
285
|
+
*/
|
|
286
|
+
update(node, decorations, innerDecorations) {
|
|
287
|
+
const rerenderComponent = (props) => {
|
|
288
|
+
this.decorationClasses.value = this.getDecorationClasses();
|
|
289
|
+
this.renderer.updateProps(props);
|
|
290
|
+
};
|
|
291
|
+
if (typeof this.options.update === "function") {
|
|
292
|
+
const oldNode = this.node;
|
|
293
|
+
const oldDecorations = this.decorations;
|
|
294
|
+
const oldInnerDecorations = this.innerDecorations;
|
|
295
|
+
this.node = node;
|
|
296
|
+
this.decorations = decorations;
|
|
297
|
+
this.innerDecorations = innerDecorations;
|
|
298
|
+
return this.options.update({
|
|
299
|
+
oldNode,
|
|
300
|
+
oldDecorations,
|
|
301
|
+
newNode: node,
|
|
302
|
+
newDecorations: decorations,
|
|
303
|
+
oldInnerDecorations,
|
|
304
|
+
innerDecorations,
|
|
305
|
+
updateProps: () => rerenderComponent({ node, decorations, innerDecorations })
|
|
306
|
+
});
|
|
397
307
|
}
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
// @ts-ignore
|
|
401
|
-
.map(item => item.type.attrs.class)
|
|
402
|
-
.flat()
|
|
403
|
-
.join(' '));
|
|
308
|
+
if (node.type !== this.node.type) {
|
|
309
|
+
return false;
|
|
404
310
|
}
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
this.editor.off('selectionUpdate', this.handleSelectionUpdate);
|
|
311
|
+
if (node === this.node && this.decorations === decorations && this.innerDecorations === innerDecorations) {
|
|
312
|
+
return true;
|
|
408
313
|
}
|
|
409
|
-
|
|
314
|
+
this.node = node;
|
|
315
|
+
this.decorations = decorations;
|
|
316
|
+
this.innerDecorations = innerDecorations;
|
|
317
|
+
rerenderComponent({ node, decorations, innerDecorations });
|
|
318
|
+
return true;
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Select the node.
|
|
322
|
+
* Add the `selected` prop and the `ProseMirror-selectednode` class.
|
|
323
|
+
*/
|
|
324
|
+
selectNode() {
|
|
325
|
+
this.renderer.updateProps({
|
|
326
|
+
selected: true
|
|
327
|
+
});
|
|
328
|
+
this.renderer.element.classList.add("ProseMirror-selectednode");
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Deselect the node.
|
|
332
|
+
* Remove the `selected` prop and the `ProseMirror-selectednode` class.
|
|
333
|
+
*/
|
|
334
|
+
deselectNode() {
|
|
335
|
+
this.renderer.updateProps({
|
|
336
|
+
selected: false
|
|
337
|
+
});
|
|
338
|
+
this.renderer.element.classList.remove("ProseMirror-selectednode");
|
|
339
|
+
}
|
|
340
|
+
getDecorationClasses() {
|
|
341
|
+
return this.decorations.map((item) => item.type.attrs.class).flat().join(" ");
|
|
342
|
+
}
|
|
343
|
+
destroy() {
|
|
344
|
+
this.renderer.destroy();
|
|
345
|
+
this.editor.off("selectionUpdate", this.handleSelectionUpdate);
|
|
346
|
+
}
|
|
347
|
+
};
|
|
410
348
|
function VueNodeViewRenderer(component, options) {
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
}
|
|
418
|
-
return new VueNodeView(component, props, options);
|
|
419
|
-
};
|
|
349
|
+
return (props) => {
|
|
350
|
+
if (!props.editor.contentComponent) {
|
|
351
|
+
return {};
|
|
352
|
+
}
|
|
353
|
+
return new VueNodeView(component, props, options);
|
|
354
|
+
};
|
|
420
355
|
}
|
|
421
356
|
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
exports
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
get: function () { return core[k]; }
|
|
435
|
-
});
|
|
357
|
+
// src/index.ts
|
|
358
|
+
__reExport(index_exports, require("@tiptap/core"), module.exports);
|
|
359
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
360
|
+
0 && (module.exports = {
|
|
361
|
+
Editor,
|
|
362
|
+
EditorContent,
|
|
363
|
+
NodeViewContent,
|
|
364
|
+
NodeViewWrapper,
|
|
365
|
+
VueNodeViewRenderer,
|
|
366
|
+
VueRenderer,
|
|
367
|
+
nodeViewProps,
|
|
368
|
+
...require("@tiptap/core")
|
|
436
369
|
});
|
|
437
|
-
//# sourceMappingURL=index.cjs.map
|
|
370
|
+
//# sourceMappingURL=index.cjs.map
|