@tiptap/vue-2 2.0.0-beta.21 → 2.0.0-beta.210

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.js ADDED
@@ -0,0 +1,397 @@
1
+ // src/BubbleMenu.ts
2
+ import { BubbleMenuPlugin } from "@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(BubbleMenuPlugin({
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
+ };
53
+
54
+ // src/Editor.ts
55
+ import { Editor as CoreEditor } from "@tiptap/core";
56
+ var Editor = class extends CoreEditor {
57
+ constructor() {
58
+ super(...arguments);
59
+ this.contentComponent = null;
60
+ }
61
+ };
62
+
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
+ };
117
+
118
+ // src/FloatingMenu.ts
119
+ import { FloatingMenuPlugin } from "@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(FloatingMenuPlugin({
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
+ };
166
+
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
+ };
186
+
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
+ }
214
+ };
215
+
216
+ // src/VueNodeViewRenderer.ts
217
+ import {
218
+ NodeView
219
+ } from "@tiptap/core";
220
+ import Vue2 from "vue";
221
+
222
+ // src/VueRenderer.ts
223
+ import Vue from "vue";
224
+ var VueRenderer = class {
225
+ constructor(component, props) {
226
+ const Component = typeof component === "function" ? component : Vue.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 : Vue;
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
+ }
248
+ };
249
+
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 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.observable({
300
+ value: this.getDecorationClasses()
301
+ });
302
+ const vue = (_b = (_a = this.editor.contentComponent) == null ? void 0 : _a.$options._base) != null ? _b : Vue2;
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
+ }
375
+ };
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
+ export * from "@tiptap/core";
387
+ export {
388
+ BubbleMenu,
389
+ Editor,
390
+ EditorContent,
391
+ FloatingMenu,
392
+ NodeViewContent,
393
+ NodeViewWrapper,
394
+ VueNodeViewRenderer,
395
+ VueRenderer,
396
+ nodeViewProps
397
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tiptap/vue-2",
3
3
  "description": "Vue components for tiptap",
4
- "version": "2.0.0-beta.21",
4
+ "version": "2.0.0-beta.210",
5
5
  "homepage": "https://tiptap.dev",
6
6
  "keywords": [
7
7
  "tiptap",
@@ -12,23 +12,53 @@
12
12
  "type": "github",
13
13
  "url": "https://github.com/sponsors/ueberdosis"
14
14
  },
15
- "main": "dist/tiptap-vue-2.cjs.js",
16
- "umd": "dist/tiptap-vue-2.umd.js",
17
- "module": "dist/tiptap-vue-2.esm.js",
18
- "unpkg": "dist/tiptap-vue-2.bundle.umd.min.js",
19
- "types": "dist/packages/vue-2/src/index.d.ts",
15
+ "exports": {
16
+ ".": {
17
+ "types": "./dist/index.d.ts",
18
+ "import": "./dist/index.js",
19
+ "require": "./dist/index.cjs"
20
+ }
21
+ },
22
+ "main": "dist/index.cjs",
23
+ "module": "dist/index.js",
24
+ "types": "dist/index.d.ts",
25
+ "type": "module",
20
26
  "files": [
21
27
  "src",
22
28
  "dist"
23
29
  ],
30
+ "devDependencies": {
31
+ "@tiptap/core": "^2.0.0-beta.210",
32
+ "@tiptap/pm": "^2.0.0-beta.210",
33
+ "vue": "^2.6.0"
34
+ },
24
35
  "peerDependencies": {
25
- "@tiptap/core": "^2.0.0-beta.1",
26
- "vue": "^2.6.12"
36
+ "@tiptap/core": "^2.0.0-beta.209",
37
+ "@tiptap/pm": "^2.0.0-beta.209",
38
+ "vue": "^2.6.0"
27
39
  },
28
40
  "dependencies": {
29
- "@tiptap/extension-bubble-menu": "^2.0.0-beta.9",
30
- "@tiptap/extension-floating-menu": "^2.0.0-beta.6",
31
- "prosemirror-view": "^1.18.2"
41
+ "@tiptap/extension-bubble-menu": "^2.0.0-beta.210",
42
+ "@tiptap/extension-floating-menu": "^2.0.0-beta.210"
43
+ },
44
+ "repository": {
45
+ "type": "git",
46
+ "url": "https://github.com/ueberdosis/tiptap",
47
+ "directory": "packages/vue-2"
48
+ },
49
+ "sideEffects": false,
50
+ "scripts": {
51
+ "build": "tsup"
32
52
  },
33
- "gitHead": "bd9e15d78f9159afb05d09e7ba279ff7d74a85ea"
53
+ "tsup": {
54
+ "entry": [
55
+ "src/index.ts"
56
+ ],
57
+ "dts": true,
58
+ "splitting": true,
59
+ "format": [
60
+ "esm",
61
+ "cjs"
62
+ ]
63
+ }
34
64
  }
package/src/BubbleMenu.ts CHANGED
@@ -1,33 +1,58 @@
1
- import Vue, { PropType } from 'vue'
2
- import { BubbleMenuPlugin, BubbleMenuPluginKey, BubbleMenuPluginProps } from '@tiptap/extension-bubble-menu'
1
+ import { BubbleMenuPlugin, BubbleMenuPluginProps } from '@tiptap/extension-bubble-menu'
2
+ import Vue, { Component, PropType } from 'vue'
3
3
 
4
- export const BubbleMenu = Vue.extend({
4
+ export interface BubbleMenuInterface extends Vue {
5
+ pluginKey: BubbleMenuPluginProps['pluginKey'],
6
+ editor: BubbleMenuPluginProps['editor'],
7
+ tippyOptions: BubbleMenuPluginProps['tippyOptions'],
8
+ updateDelay: BubbleMenuPluginProps['updateDelay'],
9
+ shouldShow: BubbleMenuPluginProps['shouldShow'],
10
+ }
11
+
12
+ export const BubbleMenu: Component = {
5
13
  name: 'BubbleMenu',
6
14
 
7
15
  props: {
16
+ pluginKey: {
17
+ type: [String, Object as PropType<Exclude<BubbleMenuPluginProps['pluginKey'], string>>],
18
+ default: 'bubbleMenu',
19
+ },
20
+
8
21
  editor: {
9
22
  type: Object as PropType<BubbleMenuPluginProps['editor']>,
10
23
  required: true,
11
24
  },
12
25
 
26
+ updateDelay: {
27
+ type: Number as PropType<BubbleMenuPluginProps['updateDelay']>,
28
+ },
29
+
13
30
  tippyOptions: {
14
31
  type: Object as PropType<BubbleMenuPluginProps['tippyOptions']>,
15
32
  default: () => ({}),
16
33
  },
34
+
35
+ shouldShow: {
36
+ type: Function as PropType<Exclude<BubbleMenuPluginProps['shouldShow'], null>>,
37
+ default: null,
38
+ },
17
39
  },
18
40
 
19
41
  watch: {
20
42
  editor: {
21
43
  immediate: true,
22
- handler(editor: BubbleMenuPluginProps['editor']) {
44
+ handler(this: BubbleMenuInterface, editor: BubbleMenuPluginProps['editor']) {
23
45
  if (!editor) {
24
46
  return
25
47
  }
26
48
 
27
49
  this.$nextTick(() => {
28
50
  editor.registerPlugin(BubbleMenuPlugin({
51
+ updateDelay: this.updateDelay,
29
52
  editor,
30
53
  element: this.$el as HTMLElement,
54
+ pluginKey: this.pluginKey,
55
+ shouldShow: this.shouldShow,
31
56
  tippyOptions: this.tippyOptions,
32
57
  }))
33
58
  })
@@ -35,11 +60,11 @@ export const BubbleMenu = Vue.extend({
35
60
  },
36
61
  },
37
62
 
38
- render(createElement) {
63
+ render(this: BubbleMenuInterface, createElement) {
39
64
  return createElement('div', { style: { visibility: 'hidden' } }, this.$slots.default)
40
65
  },
41
66
 
42
- beforeDestroy() {
43
- this.editor.unregisterPlugin(BubbleMenuPluginKey)
67
+ beforeDestroy(this: BubbleMenuInterface) {
68
+ this.editor.unregisterPlugin(this.pluginKey)
44
69
  },
45
- })
70
+ }
@@ -1,7 +1,12 @@
1
- import Vue, { PropType } from 'vue'
1
+ import Vue, { Component, PropType } from 'vue'
2
+
2
3
  import { Editor } from './Editor'
3
4
 
4
- export const EditorContent = Vue.extend({
5
+ export interface EditorContentInterface extends Vue {
6
+ editor: Editor,
7
+ }
8
+
9
+ export const EditorContent: Component = {
5
10
  name: 'EditorContent',
6
11
 
7
12
  props: {
@@ -14,7 +19,7 @@ export const EditorContent = Vue.extend({
14
19
  watch: {
15
20
  editor: {
16
21
  immediate: true,
17
- handler(editor: Editor) {
22
+ handler(this: EditorContentInterface, editor: Editor) {
18
23
  if (editor && editor.options.element) {
19
24
  this.$nextTick(() => {
20
25
  const element = this.$el
@@ -23,8 +28,7 @@ export const EditorContent = Vue.extend({
23
28
  return
24
29
  }
25
30
 
26
- element.appendChild(editor.options.element.firstChild)
27
-
31
+ element.append(...editor.options.element.childNodes)
28
32
  editor.contentComponent = this
29
33
 
30
34
  editor.setOptions({
@@ -42,9 +46,13 @@ export const EditorContent = Vue.extend({
42
46
  return createElement('div')
43
47
  },
44
48
 
45
- beforeDestroy() {
49
+ beforeDestroy(this: EditorContentInterface) {
46
50
  const { editor } = this
47
51
 
52
+ if (!editor) {
53
+ return
54
+ }
55
+
48
56
  if (!editor.isDestroyed) {
49
57
  editor.view.setProps({
50
58
  nodeViews: {},
@@ -59,10 +67,10 @@ export const EditorContent = Vue.extend({
59
67
 
60
68
  const newElement = document.createElement('div')
61
69
 
62
- newElement.appendChild(editor.options.element.firstChild)
70
+ newElement.append(...editor.options.element.childNodes)
63
71
 
64
72
  editor.setOptions({
65
73
  element: newElement,
66
74
  })
67
75
  },
68
- })
76
+ }
@@ -1,10 +1,22 @@
1
- import Vue, { PropType } from 'vue'
2
- import { FloatingMenuPlugin, FloatingMenuPluginKey, FloatingMenuPluginProps } from '@tiptap/extension-floating-menu'
1
+ import { FloatingMenuPlugin, FloatingMenuPluginProps } from '@tiptap/extension-floating-menu'
2
+ import Vue, { Component, PropType } from 'vue'
3
3
 
4
- export const FloatingMenu = Vue.extend({
4
+ export interface FloatingMenuInterface extends Vue {
5
+ pluginKey: FloatingMenuPluginProps['pluginKey'],
6
+ tippyOptions: FloatingMenuPluginProps['tippyOptions'],
7
+ editor: FloatingMenuPluginProps['editor'],
8
+ shouldShow: FloatingMenuPluginProps['shouldShow'],
9
+ }
10
+
11
+ export const FloatingMenu: Component = {
5
12
  name: 'FloatingMenu',
6
13
 
7
14
  props: {
15
+ pluginKey: {
16
+ type: [String, Object as PropType<Exclude<FloatingMenuPluginProps['pluginKey'], string>>],
17
+ default: 'floatingMenu',
18
+ },
19
+
8
20
  editor: {
9
21
  type: Object as PropType<FloatingMenuPluginProps['editor']>,
10
22
  required: true,
@@ -14,32 +26,39 @@ export const FloatingMenu = Vue.extend({
14
26
  type: Object as PropType<FloatingMenuPluginProps['tippyOptions']>,
15
27
  default: () => ({}),
16
28
  },
29
+
30
+ shouldShow: {
31
+ type: Function as PropType<Exclude<FloatingMenuPluginProps['shouldShow'], null>>,
32
+ default: null,
33
+ },
17
34
  },
18
35
 
19
36
  watch: {
20
37
  editor: {
21
38
  immediate: true,
22
- handler(editor: FloatingMenuPluginProps['editor']) {
39
+ handler(this: FloatingMenuInterface, editor: FloatingMenuPluginProps['editor']) {
23
40
  if (!editor) {
24
41
  return
25
42
  }
26
43
 
27
44
  this.$nextTick(() => {
28
45
  editor.registerPlugin(FloatingMenuPlugin({
46
+ pluginKey: this.pluginKey,
29
47
  editor,
30
48
  element: this.$el as HTMLElement,
31
49
  tippyOptions: this.tippyOptions,
50
+ shouldShow: this.shouldShow,
32
51
  }))
33
52
  })
34
53
  },
35
54
  },
36
55
  },
37
56
 
38
- render(createElement) {
57
+ render(this: FloatingMenuInterface, createElement) {
39
58
  return createElement('div', { style: { visibility: 'hidden' } }, this.$slots.default)
40
59
  },
41
60
 
42
- beforeDestroy() {
43
- this.editor.unregisterPlugin(FloatingMenuPluginKey)
61
+ beforeDestroy(this: FloatingMenuInterface) {
62
+ this.editor.unregisterPlugin(this.pluginKey)
44
63
  },
45
- })
64
+ }