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

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/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  ## Introduction
8
8
  tiptap is a headless wrapper around [ProseMirror](https://ProseMirror.net) – a toolkit for building rich text WYSIWYG editors, which is already in use at many well-known companies such as *New York Times*, *The Guardian* or *Atlassian*.
9
9
 
10
- ## Offical Documentation
10
+ ## Official Documentation
11
11
  Documentation can be found on the [tiptap website](https://tiptap.dev).
12
12
 
13
13
  ## License
package/dist/index.cjs ADDED
@@ -0,0 +1,397 @@
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
+ };
53
+
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
+ };
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
+ 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
+ };
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
+
218
+
219
+
220
+ var _vue = require('vue'); var _vue2 = _interopRequireDefault(_vue);
221
+
222
+ // src/VueRenderer.ts
223
+
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
+ }
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 _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
+ }
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
+
387
+
388
+
389
+
390
+
391
+
392
+
393
+
394
+
395
+
396
+
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;
@@ -0,0 +1,104 @@
1
+ import { BubbleMenuPluginProps } from '@tiptap/extension-bubble-menu';
2
+ import Vue, { Component } from 'vue';
3
+ import * as _tiptap_core from '@tiptap/core';
4
+ import { Editor as Editor$1, NodeViewRendererOptions, NodeViewRenderer } from '@tiptap/core';
5
+ export * from '@tiptap/core';
6
+ import { FloatingMenuPluginProps } from '@tiptap/extension-floating-menu';
7
+ import { Node } from '@tiptap/pm/model';
8
+ import { Decoration } from '@tiptap/pm/view';
9
+ import { PropType, VueConstructor } from 'vue/types/umd';
10
+
11
+ interface BubbleMenuInterface extends Vue {
12
+ pluginKey: BubbleMenuPluginProps['pluginKey'];
13
+ editor: BubbleMenuPluginProps['editor'];
14
+ tippyOptions: BubbleMenuPluginProps['tippyOptions'];
15
+ updateDelay: BubbleMenuPluginProps['updateDelay'];
16
+ shouldShow: BubbleMenuPluginProps['shouldShow'];
17
+ }
18
+ declare const BubbleMenu: Component;
19
+
20
+ declare class Editor extends Editor$1 {
21
+ contentComponent: Vue | null;
22
+ }
23
+
24
+ interface EditorContentInterface extends Vue {
25
+ editor: Editor;
26
+ }
27
+ declare const EditorContent: Component;
28
+
29
+ interface FloatingMenuInterface extends Vue {
30
+ pluginKey: FloatingMenuPluginProps['pluginKey'];
31
+ tippyOptions: FloatingMenuPluginProps['tippyOptions'];
32
+ editor: FloatingMenuPluginProps['editor'];
33
+ shouldShow: FloatingMenuPluginProps['shouldShow'];
34
+ }
35
+ declare const FloatingMenu: Component;
36
+
37
+ interface NodeViewContentInterface extends Vue {
38
+ as: string;
39
+ }
40
+ declare const NodeViewContent: Component;
41
+
42
+ interface NodeViewWrapperInterface extends Vue {
43
+ as: string;
44
+ decorationClasses: {
45
+ value: string;
46
+ };
47
+ onDragStart: Function;
48
+ }
49
+ declare const NodeViewWrapper: Component;
50
+
51
+ declare const nodeViewProps: {
52
+ editor: {
53
+ type: PropType<_tiptap_core.Editor>;
54
+ required: true;
55
+ };
56
+ node: {
57
+ type: PropType<Node>;
58
+ required: true;
59
+ };
60
+ decorations: {
61
+ type: PropType<Decoration[]>;
62
+ required: true;
63
+ };
64
+ selected: {
65
+ type: PropType<boolean>;
66
+ required: true;
67
+ };
68
+ extension: {
69
+ type: PropType<_tiptap_core.Node<any, any>>;
70
+ required: true;
71
+ };
72
+ getPos: {
73
+ type: PropType<() => number>;
74
+ required: true;
75
+ };
76
+ updateAttributes: {
77
+ type: PropType<(attributes: Record<string, any>) => void>;
78
+ required: true;
79
+ };
80
+ deleteNode: {
81
+ type: PropType<() => void>;
82
+ required: true;
83
+ };
84
+ };
85
+ interface VueNodeViewRendererOptions extends NodeViewRendererOptions {
86
+ update: ((props: {
87
+ oldNode: Node;
88
+ oldDecorations: Decoration[];
89
+ newNode: Node;
90
+ newDecorations: Decoration[];
91
+ updateProps: () => void;
92
+ }) => boolean) | null;
93
+ }
94
+ declare function VueNodeViewRenderer(component: Vue | VueConstructor, options?: Partial<VueNodeViewRendererOptions>): NodeViewRenderer;
95
+
96
+ declare class VueRenderer {
97
+ ref: Vue;
98
+ constructor(component: Vue | VueConstructor, props: any);
99
+ get element(): Element;
100
+ updateProps(props?: Record<string, any>): void;
101
+ destroy(): void;
102
+ }
103
+
104
+ export { BubbleMenu, BubbleMenuInterface, Editor, EditorContent, EditorContentInterface, FloatingMenu, FloatingMenuInterface, NodeViewContent, NodeViewContentInterface, NodeViewWrapper, NodeViewWrapperInterface, VueNodeViewRenderer, VueNodeViewRendererOptions, VueRenderer, nodeViewProps };