@tiptap/vue-2 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 CHANGED
@@ -1,397 +1,403 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _createStarExport(obj) { Object.keys(obj) .filter((key) => key !== "default" && key !== "__esModule") .forEach((key) => { if (exports.hasOwnProperty(key)) { return; } Object.defineProperty(exports, key, {enumerable: true, configurable: true, get: () => obj[key]}); }); }// src/BubbleMenu.ts
2
- var _extensionbubblemenu = require('@tiptap/extension-bubble-menu');
3
- var BubbleMenu = {
4
- name: "BubbleMenu",
5
- props: {
6
- pluginKey: {
7
- type: [String, Object],
8
- default: "bubbleMenu"
9
- },
10
- editor: {
11
- type: Object,
12
- required: true
13
- },
14
- updateDelay: {
15
- type: Number
16
- },
17
- tippyOptions: {
18
- type: Object,
19
- default: () => ({})
20
- },
21
- shouldShow: {
22
- type: Function,
23
- default: null
24
- }
25
- },
26
- watch: {
27
- editor: {
28
- immediate: true,
29
- handler(editor) {
30
- if (!editor) {
31
- return;
32
- }
33
- this.$nextTick(() => {
34
- editor.registerPlugin(_extensionbubblemenu.BubbleMenuPlugin.call(void 0, {
35
- updateDelay: this.updateDelay,
36
- editor,
37
- element: this.$el,
38
- pluginKey: this.pluginKey,
39
- shouldShow: this.shouldShow,
40
- tippyOptions: this.tippyOptions
41
- }));
42
- });
43
- }
44
- }
45
- },
46
- render(createElement) {
47
- return createElement("div", { style: { visibility: "hidden" } }, this.$slots.default);
48
- },
49
- beforeDestroy() {
50
- this.editor.unregisterPlugin(this.pluginKey);
51
- }
52
- };
1
+ 'use strict';
53
2
 
54
- // src/Editor.ts
55
- var _core = require('@tiptap/core'); _createStarExport(_core);
56
- var Editor = class extends _core.Editor {
57
- constructor() {
58
- super(...arguments);
59
- this.contentComponent = null;
60
- }
61
- };
3
+ Object.defineProperty(exports, '__esModule', { value: true });
62
4
 
63
- // src/EditorContent.ts
64
- var EditorContent = {
65
- name: "EditorContent",
66
- props: {
67
- editor: {
68
- default: null,
69
- type: Object
70
- }
71
- },
72
- watch: {
73
- editor: {
74
- immediate: true,
75
- handler(editor) {
76
- if (editor && editor.options.element) {
77
- this.$nextTick(() => {
78
- const element = this.$el;
79
- if (!element || !editor.options.element.firstChild) {
80
- return;
81
- }
82
- element.append(...editor.options.element.childNodes);
83
- editor.contentComponent = this;
84
- editor.setOptions({
85
- element
86
- });
87
- editor.createNodeViews();
88
- });
89
- }
90
- }
91
- }
92
- },
93
- render(createElement) {
94
- return createElement("div");
95
- },
96
- beforeDestroy() {
97
- const { editor } = this;
98
- if (!editor) {
99
- return;
100
- }
101
- if (!editor.isDestroyed) {
102
- editor.view.setProps({
103
- nodeViews: {}
104
- });
105
- }
106
- editor.contentComponent = null;
107
- if (!editor.options.element.firstChild) {
108
- return;
109
- }
110
- const newElement = document.createElement("div");
111
- newElement.append(...editor.options.element.childNodes);
112
- editor.setOptions({
113
- element: newElement
114
- });
115
- }
116
- };
5
+ var extensionBubbleMenu = require('@tiptap/extension-bubble-menu');
6
+ var core = require('@tiptap/core');
7
+ var extensionFloatingMenu = require('@tiptap/extension-floating-menu');
8
+ var Vue = require('vue');
117
9
 
118
- // src/FloatingMenu.ts
119
- var _extensionfloatingmenu = require('@tiptap/extension-floating-menu');
120
- var FloatingMenu = {
121
- name: "FloatingMenu",
122
- props: {
123
- pluginKey: {
124
- type: [String, Object],
125
- default: "floatingMenu"
126
- },
127
- editor: {
128
- type: Object,
129
- required: true
130
- },
131
- tippyOptions: {
132
- type: Object,
133
- default: () => ({})
134
- },
135
- shouldShow: {
136
- type: Function,
137
- default: null
138
- }
139
- },
140
- watch: {
141
- editor: {
142
- immediate: true,
143
- handler(editor) {
144
- if (!editor) {
145
- return;
146
- }
147
- this.$nextTick(() => {
148
- editor.registerPlugin(_extensionfloatingmenu.FloatingMenuPlugin.call(void 0, {
149
- pluginKey: this.pluginKey,
150
- editor,
151
- element: this.$el,
152
- tippyOptions: this.tippyOptions,
153
- shouldShow: this.shouldShow
154
- }));
155
- });
156
- }
157
- }
158
- },
159
- render(createElement) {
160
- return createElement("div", { style: { visibility: "hidden" } }, this.$slots.default);
161
- },
162
- beforeDestroy() {
163
- this.editor.unregisterPlugin(this.pluginKey);
164
- }
165
- };
10
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
166
11
 
167
- // src/NodeViewContent.ts
168
- var NodeViewContent = {
169
- props: {
170
- as: {
171
- type: String,
172
- default: "div"
173
- }
174
- },
175
- render(createElement) {
176
- return createElement(this.as, {
177
- style: {
178
- whiteSpace: "pre-wrap"
179
- },
180
- attrs: {
181
- "data-node-view-content": ""
182
- }
183
- });
184
- }
185
- };
12
+ var Vue__default = /*#__PURE__*/_interopDefaultLegacy(Vue);
186
13
 
187
- // src/NodeViewWrapper.ts
188
- var NodeViewWrapper = {
189
- props: {
190
- as: {
191
- type: String,
192
- default: "div"
193
- }
194
- },
195
- inject: ["onDragStart", "decorationClasses"],
196
- render(createElement) {
197
- return createElement(
198
- this.as,
199
- {
200
- class: this.decorationClasses.value,
201
- style: {
202
- whiteSpace: "normal"
203
- },
204
- attrs: {
205
- "data-node-view-wrapper": ""
206
- },
207
- on: {
208
- dragstart: this.onDragStart
209
- }
210
- },
211
- this.$slots.default
212
- );
213
- }
14
+ const BubbleMenu = {
15
+ name: 'BubbleMenu',
16
+ props: {
17
+ pluginKey: {
18
+ type: [String, Object],
19
+ default: 'bubbleMenu',
20
+ },
21
+ editor: {
22
+ type: Object,
23
+ required: true,
24
+ },
25
+ updateDelay: {
26
+ type: Number,
27
+ },
28
+ tippyOptions: {
29
+ type: Object,
30
+ default: () => ({}),
31
+ },
32
+ shouldShow: {
33
+ type: Function,
34
+ default: null,
35
+ },
36
+ },
37
+ watch: {
38
+ editor: {
39
+ immediate: true,
40
+ handler(editor) {
41
+ if (!editor) {
42
+ return;
43
+ }
44
+ this.$nextTick(() => {
45
+ editor.registerPlugin(extensionBubbleMenu.BubbleMenuPlugin({
46
+ updateDelay: this.updateDelay,
47
+ editor,
48
+ element: this.$el,
49
+ pluginKey: this.pluginKey,
50
+ shouldShow: this.shouldShow,
51
+ tippyOptions: this.tippyOptions,
52
+ }));
53
+ });
54
+ },
55
+ },
56
+ },
57
+ render(createElement) {
58
+ return createElement('div', { style: { visibility: 'hidden' } }, this.$slots.default);
59
+ },
60
+ beforeDestroy() {
61
+ this.editor.unregisterPlugin(this.pluginKey);
62
+ },
214
63
  };
215
64
 
216
- // src/VueNodeViewRenderer.ts
217
-
218
-
219
-
220
- var _vue = require('vue'); var _vue2 = _interopRequireDefault(_vue);
221
-
222
- // src/VueRenderer.ts
65
+ class Editor extends core.Editor {
66
+ constructor() {
67
+ super(...arguments);
68
+ this.contentComponent = null;
69
+ }
70
+ }
223
71
 
224
- var VueRenderer = class {
225
- constructor(component, props) {
226
- const Component = typeof component === "function" ? component : _vue2.default.extend(component);
227
- this.ref = new Component(props).$mount();
228
- }
229
- get element() {
230
- return this.ref.$el;
231
- }
232
- updateProps(props = {}) {
233
- var _a, _b, _c;
234
- if (!this.ref.$props) {
235
- return;
236
- }
237
- const currentVueConstructor = (_c = (_b = (_a = this.ref.$props.editor) == null ? void 0 : _a.contentComponent) == null ? void 0 : _b.$options._base) != null ? _c : _vue2.default;
238
- const originalSilent = currentVueConstructor.config.silent;
239
- currentVueConstructor.config.silent = true;
240
- Object.entries(props).forEach(([key, value]) => {
241
- this.ref.$props[key] = value;
242
- });
243
- currentVueConstructor.config.silent = originalSilent;
244
- }
245
- destroy() {
246
- this.ref.$destroy();
247
- }
72
+ const EditorContent = {
73
+ name: 'EditorContent',
74
+ props: {
75
+ editor: {
76
+ default: null,
77
+ type: Object,
78
+ },
79
+ },
80
+ watch: {
81
+ editor: {
82
+ immediate: true,
83
+ handler(editor) {
84
+ if (editor && editor.options.element) {
85
+ this.$nextTick(() => {
86
+ const element = this.$el;
87
+ if (!element || !editor.options.element.firstChild) {
88
+ return;
89
+ }
90
+ element.append(...editor.options.element.childNodes);
91
+ editor.contentComponent = this;
92
+ editor.setOptions({
93
+ element,
94
+ });
95
+ editor.createNodeViews();
96
+ });
97
+ }
98
+ },
99
+ },
100
+ },
101
+ render(createElement) {
102
+ return createElement('div');
103
+ },
104
+ beforeDestroy() {
105
+ const { editor } = this;
106
+ if (!editor) {
107
+ return;
108
+ }
109
+ if (!editor.isDestroyed) {
110
+ editor.view.setProps({
111
+ nodeViews: {},
112
+ });
113
+ }
114
+ editor.contentComponent = null;
115
+ if (!editor.options.element.firstChild) {
116
+ return;
117
+ }
118
+ const newElement = document.createElement('div');
119
+ newElement.append(...editor.options.element.childNodes);
120
+ editor.setOptions({
121
+ element: newElement,
122
+ });
123
+ },
248
124
  };
249
125
 
250
- // src/VueNodeViewRenderer.ts
251
- var nodeViewProps = {
252
- editor: {
253
- type: Object,
254
- required: true
255
- },
256
- node: {
257
- type: Object,
258
- required: true
259
- },
260
- decorations: {
261
- type: Object,
262
- required: true
263
- },
264
- selected: {
265
- type: Boolean,
266
- required: true
267
- },
268
- extension: {
269
- type: Object,
270
- required: true
271
- },
272
- getPos: {
273
- type: Function,
274
- required: true
275
- },
276
- updateAttributes: {
277
- type: Function,
278
- required: true
279
- },
280
- deleteNode: {
281
- type: Function,
282
- required: true
283
- }
284
- };
285
- var VueNodeView = class extends _core.NodeView {
286
- mount() {
287
- var _a, _b;
288
- const props = {
289
- editor: this.editor,
290
- node: this.node,
291
- decorations: this.decorations,
292
- selected: false,
293
- extension: this.extension,
294
- getPos: () => this.getPos(),
295
- updateAttributes: (attributes = {}) => this.updateAttributes(attributes),
296
- deleteNode: () => this.deleteNode()
297
- };
298
- const onDragStart = this.onDragStart.bind(this);
299
- this.decorationClasses = _vue2.default.observable({
300
- value: this.getDecorationClasses()
301
- });
302
- const vue = (_b = (_a = this.editor.contentComponent) == null ? void 0 : _a.$options._base) != null ? _b : _vue2.default;
303
- const Component = vue.extend(this.component).extend({
304
- props: Object.keys(props),
305
- provide: () => {
306
- return {
307
- onDragStart,
308
- decorationClasses: this.decorationClasses
309
- };
310
- }
311
- });
312
- this.renderer = new VueRenderer(Component, {
313
- parent: this.editor.contentComponent,
314
- propsData: props
315
- });
316
- }
317
- get dom() {
318
- if (!this.renderer.element.hasAttribute("data-node-view-wrapper")) {
319
- throw Error("Please use the NodeViewWrapper component for your node view.");
320
- }
321
- return this.renderer.element;
322
- }
323
- get contentDOM() {
324
- if (this.node.isLeaf) {
325
- return null;
326
- }
327
- const contentElement = this.dom.querySelector("[data-node-view-content]");
328
- return contentElement || this.dom;
329
- }
330
- update(node, decorations) {
331
- const updateProps = (props) => {
332
- this.decorationClasses.value = this.getDecorationClasses();
333
- this.renderer.updateProps(props);
334
- };
335
- if (typeof this.options.update === "function") {
336
- const oldNode = this.node;
337
- const oldDecorations = this.decorations;
338
- this.node = node;
339
- this.decorations = decorations;
340
- return this.options.update({
341
- oldNode,
342
- oldDecorations,
343
- newNode: node,
344
- newDecorations: decorations,
345
- updateProps: () => updateProps({ node, decorations })
346
- });
347
- }
348
- if (node.type !== this.node.type) {
349
- return false;
350
- }
351
- if (node === this.node && this.decorations === decorations) {
352
- return true;
353
- }
354
- this.node = node;
355
- this.decorations = decorations;
356
- updateProps({ node, decorations });
357
- return true;
358
- }
359
- selectNode() {
360
- this.renderer.updateProps({
361
- selected: true
362
- });
363
- }
364
- deselectNode() {
365
- this.renderer.updateProps({
366
- selected: false
367
- });
368
- }
369
- getDecorationClasses() {
370
- return this.decorations.map((item) => item.type.attrs.class).flat().join(" ");
371
- }
372
- destroy() {
373
- this.renderer.destroy();
374
- }
126
+ const FloatingMenu = {
127
+ name: 'FloatingMenu',
128
+ props: {
129
+ pluginKey: {
130
+ type: [String, Object],
131
+ default: 'floatingMenu',
132
+ },
133
+ editor: {
134
+ type: Object,
135
+ required: true,
136
+ },
137
+ tippyOptions: {
138
+ type: Object,
139
+ default: () => ({}),
140
+ },
141
+ shouldShow: {
142
+ type: Function,
143
+ default: null,
144
+ },
145
+ },
146
+ watch: {
147
+ editor: {
148
+ immediate: true,
149
+ handler(editor) {
150
+ if (!editor) {
151
+ return;
152
+ }
153
+ this.$nextTick(() => {
154
+ editor.registerPlugin(extensionFloatingMenu.FloatingMenuPlugin({
155
+ pluginKey: this.pluginKey,
156
+ editor,
157
+ element: this.$el,
158
+ tippyOptions: this.tippyOptions,
159
+ shouldShow: this.shouldShow,
160
+ }));
161
+ });
162
+ },
163
+ },
164
+ },
165
+ render(createElement) {
166
+ return createElement('div', { style: { visibility: 'hidden' } }, this.$slots.default);
167
+ },
168
+ beforeDestroy() {
169
+ this.editor.unregisterPlugin(this.pluginKey);
170
+ },
375
171
  };
376
- function VueNodeViewRenderer(component, options) {
377
- return (props) => {
378
- if (!props.editor.contentComponent) {
379
- return {};
380
- }
381
- return new VueNodeView(component, props, options);
382
- };
383
- }
384
-
385
- // src/index.ts
386
-
387
-
388
-
389
-
390
-
391
-
392
172
 
173
+ const NodeViewContent = {
174
+ props: {
175
+ as: {
176
+ type: String,
177
+ default: 'div',
178
+ },
179
+ },
180
+ render(createElement) {
181
+ return createElement(this.as, {
182
+ style: {
183
+ whiteSpace: 'pre-wrap',
184
+ },
185
+ attrs: {
186
+ 'data-node-view-content': '',
187
+ },
188
+ });
189
+ },
190
+ };
393
191
 
192
+ const NodeViewWrapper = {
193
+ props: {
194
+ as: {
195
+ type: String,
196
+ default: 'div',
197
+ },
198
+ },
199
+ inject: ['onDragStart', 'decorationClasses'],
200
+ render(createElement) {
201
+ return createElement(this.as, {
202
+ class: this.decorationClasses.value,
203
+ style: {
204
+ whiteSpace: 'normal',
205
+ },
206
+ attrs: {
207
+ 'data-node-view-wrapper': '',
208
+ },
209
+ on: {
210
+ dragstart: this.onDragStart,
211
+ },
212
+ }, this.$slots.default);
213
+ },
214
+ };
394
215
 
216
+ class VueRenderer {
217
+ constructor(component, props) {
218
+ const Component = (typeof component === 'function') ? component : Vue__default["default"].extend(component);
219
+ this.ref = new Component(props).$mount();
220
+ }
221
+ get element() {
222
+ return this.ref.$el;
223
+ }
224
+ updateProps(props = {}) {
225
+ var _a, _b, _c;
226
+ if (!this.ref.$props) {
227
+ return;
228
+ }
229
+ // prevents `Avoid mutating a prop directly` error message
230
+ // Fix: `VueNodeViewRenderer` change vue Constructor `config.silent` not working
231
+ const currentVueConstructor = (_c = (_b = (_a = this.ref.$props.editor) === null || _a === void 0 ? void 0 : _a.contentComponent) === null || _b === void 0 ? void 0 : _b.$options._base) !== null && _c !== void 0 ? _c : Vue__default["default"]; // eslint-disable-line
232
+ const originalSilent = currentVueConstructor.config.silent;
233
+ currentVueConstructor.config.silent = true;
234
+ Object
235
+ .entries(props)
236
+ .forEach(([key, value]) => {
237
+ this.ref.$props[key] = value;
238
+ });
239
+ currentVueConstructor.config.silent = originalSilent;
240
+ }
241
+ destroy() {
242
+ this.ref.$destroy();
243
+ }
244
+ }
395
245
 
246
+ const nodeViewProps = {
247
+ editor: {
248
+ type: Object,
249
+ required: true,
250
+ },
251
+ node: {
252
+ type: Object,
253
+ required: true,
254
+ },
255
+ decorations: {
256
+ type: Object,
257
+ required: true,
258
+ },
259
+ selected: {
260
+ type: Boolean,
261
+ required: true,
262
+ },
263
+ extension: {
264
+ type: Object,
265
+ required: true,
266
+ },
267
+ getPos: {
268
+ type: Function,
269
+ required: true,
270
+ },
271
+ updateAttributes: {
272
+ type: Function,
273
+ required: true,
274
+ },
275
+ deleteNode: {
276
+ type: Function,
277
+ required: true,
278
+ },
279
+ };
280
+ class VueNodeView extends core.NodeView {
281
+ mount() {
282
+ var _a, _b;
283
+ const props = {
284
+ editor: this.editor,
285
+ node: this.node,
286
+ decorations: this.decorations,
287
+ selected: false,
288
+ extension: this.extension,
289
+ getPos: () => this.getPos(),
290
+ updateAttributes: (attributes = {}) => this.updateAttributes(attributes),
291
+ deleteNode: () => this.deleteNode(),
292
+ };
293
+ const onDragStart = this.onDragStart.bind(this);
294
+ this.decorationClasses = Vue__default["default"].observable({
295
+ value: this.getDecorationClasses(),
296
+ });
297
+ // @ts-ignore
298
+ const vue = (_b = (_a = this.editor.contentComponent) === null || _a === void 0 ? void 0 : _a.$options._base) !== null && _b !== void 0 ? _b : Vue__default["default"]; // eslint-disable-line
299
+ const Component = vue.extend(this.component).extend({
300
+ props: Object.keys(props),
301
+ provide: () => {
302
+ return {
303
+ onDragStart,
304
+ decorationClasses: this.decorationClasses,
305
+ };
306
+ },
307
+ });
308
+ this.renderer = new VueRenderer(Component, {
309
+ parent: this.editor.contentComponent,
310
+ propsData: props,
311
+ });
312
+ }
313
+ get dom() {
314
+ if (!this.renderer.element.hasAttribute('data-node-view-wrapper')) {
315
+ throw Error('Please use the NodeViewWrapper component for your node view.');
316
+ }
317
+ return this.renderer.element;
318
+ }
319
+ get contentDOM() {
320
+ if (this.node.isLeaf) {
321
+ return null;
322
+ }
323
+ const contentElement = this.dom.querySelector('[data-node-view-content]');
324
+ return (contentElement || this.dom);
325
+ }
326
+ update(node, decorations) {
327
+ const updateProps = (props) => {
328
+ this.decorationClasses.value = this.getDecorationClasses();
329
+ this.renderer.updateProps(props);
330
+ };
331
+ if (typeof this.options.update === 'function') {
332
+ const oldNode = this.node;
333
+ const oldDecorations = this.decorations;
334
+ this.node = node;
335
+ this.decorations = decorations;
336
+ return this.options.update({
337
+ oldNode,
338
+ oldDecorations,
339
+ newNode: node,
340
+ newDecorations: decorations,
341
+ updateProps: () => updateProps({ node, decorations }),
342
+ });
343
+ }
344
+ if (node.type !== this.node.type) {
345
+ return false;
346
+ }
347
+ if (node === this.node && this.decorations === decorations) {
348
+ return true;
349
+ }
350
+ this.node = node;
351
+ this.decorations = decorations;
352
+ updateProps({ node, decorations });
353
+ return true;
354
+ }
355
+ selectNode() {
356
+ this.renderer.updateProps({
357
+ selected: true,
358
+ });
359
+ }
360
+ deselectNode() {
361
+ this.renderer.updateProps({
362
+ selected: false,
363
+ });
364
+ }
365
+ getDecorationClasses() {
366
+ return (this.decorations
367
+ // @ts-ignore
368
+ .map(item => item.type.attrs.class)
369
+ .flat()
370
+ .join(' '));
371
+ }
372
+ destroy() {
373
+ this.renderer.destroy();
374
+ }
375
+ }
376
+ function VueNodeViewRenderer(component, options) {
377
+ return (props) => {
378
+ // try to get the parent component
379
+ // this is important for vue devtools to show the component hierarchy correctly
380
+ // maybe it’s `undefined` because <editor-content> isn’t rendered yet
381
+ if (!props.editor.contentComponent) {
382
+ return {};
383
+ }
384
+ return new VueNodeView(component, props, options);
385
+ };
386
+ }
396
387
 
397
- exports.BubbleMenu = BubbleMenu; exports.Editor = Editor; exports.EditorContent = EditorContent; exports.FloatingMenu = FloatingMenu; exports.NodeViewContent = NodeViewContent; exports.NodeViewWrapper = NodeViewWrapper; exports.VueNodeViewRenderer = VueNodeViewRenderer; exports.VueRenderer = VueRenderer; exports.nodeViewProps = nodeViewProps;
388
+ exports.BubbleMenu = BubbleMenu;
389
+ exports.Editor = Editor;
390
+ exports.EditorContent = EditorContent;
391
+ exports.FloatingMenu = FloatingMenu;
392
+ exports.NodeViewContent = NodeViewContent;
393
+ exports.NodeViewWrapper = NodeViewWrapper;
394
+ exports.VueNodeViewRenderer = VueNodeViewRenderer;
395
+ exports.VueRenderer = VueRenderer;
396
+ exports.nodeViewProps = nodeViewProps;
397
+ Object.keys(core).forEach(function (k) {
398
+ if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
399
+ enumerable: true,
400
+ get: function () { return core[k]; }
401
+ });
402
+ });
403
+ //# sourceMappingURL=index.cjs.map