@tiptap/vue-2 3.0.0-next.4 → 3.0.0-next.5
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 +1 -1
- package/dist/index.cjs +4 -124
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -22
- package/dist/index.d.ts +2 -22
- package/dist/index.js +4 -122
- package/dist/index.js.map +1 -1
- package/dist/menus/index.cjs +2194 -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 +2166 -0
- package/dist/menus/index.js.map +1 -0
- package/package.json +17 -7
- package/src/EditorContent.ts +3 -2
- package/src/index.ts +0 -2
- package/src/menus/index.ts +2 -0
- /package/src/{BubbleMenu.ts → menus/BubbleMenu.ts} +0 -0
- /package/src/{FloatingMenu.ts → menus/FloatingMenu.ts} +0 -0
package/LICENSE.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -31,10 +31,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
// src/index.ts
|
|
32
32
|
var index_exports = {};
|
|
33
33
|
__export(index_exports, {
|
|
34
|
-
BubbleMenu: () => BubbleMenu,
|
|
35
34
|
Editor: () => Editor,
|
|
36
35
|
EditorContent: () => EditorContent,
|
|
37
|
-
FloatingMenu: () => FloatingMenu,
|
|
38
36
|
NodeViewContent: () => NodeViewContent,
|
|
39
37
|
NodeViewWrapper: () => NodeViewWrapper,
|
|
40
38
|
VueNodeViewRenderer: () => VueNodeViewRenderer,
|
|
@@ -43,69 +41,6 @@ __export(index_exports, {
|
|
|
43
41
|
});
|
|
44
42
|
module.exports = __toCommonJS(index_exports);
|
|
45
43
|
|
|
46
|
-
// src/BubbleMenu.ts
|
|
47
|
-
var import_extension_bubble_menu = require("@tiptap/extension-bubble-menu");
|
|
48
|
-
var BubbleMenu = {
|
|
49
|
-
name: "BubbleMenu",
|
|
50
|
-
props: {
|
|
51
|
-
pluginKey: {
|
|
52
|
-
type: [String, Object],
|
|
53
|
-
default: "bubbleMenu"
|
|
54
|
-
},
|
|
55
|
-
editor: {
|
|
56
|
-
type: Object,
|
|
57
|
-
required: true
|
|
58
|
-
},
|
|
59
|
-
updateDelay: {
|
|
60
|
-
type: Number
|
|
61
|
-
},
|
|
62
|
-
options: {
|
|
63
|
-
type: Object,
|
|
64
|
-
default: {}
|
|
65
|
-
},
|
|
66
|
-
resizeDelay: {
|
|
67
|
-
type: Number
|
|
68
|
-
},
|
|
69
|
-
shouldShow: {
|
|
70
|
-
type: Function,
|
|
71
|
-
default: null
|
|
72
|
-
}
|
|
73
|
-
},
|
|
74
|
-
watch: {
|
|
75
|
-
editor: {
|
|
76
|
-
immediate: true,
|
|
77
|
-
handler(editor) {
|
|
78
|
-
if (!editor) {
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
;
|
|
82
|
-
this.$el.style.visibility = "hidden";
|
|
83
|
-
this.$el.style.position = "absolute";
|
|
84
|
-
this.$el.remove();
|
|
85
|
-
this.$nextTick(() => {
|
|
86
|
-
editor.registerPlugin(
|
|
87
|
-
(0, import_extension_bubble_menu.BubbleMenuPlugin)({
|
|
88
|
-
updateDelay: this.updateDelay,
|
|
89
|
-
resizeDelay: this.resizeDelay,
|
|
90
|
-
options: this.options,
|
|
91
|
-
editor,
|
|
92
|
-
element: this.$el,
|
|
93
|
-
pluginKey: this.pluginKey,
|
|
94
|
-
shouldShow: this.shouldShow
|
|
95
|
-
})
|
|
96
|
-
);
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
},
|
|
101
|
-
render(createElement) {
|
|
102
|
-
return createElement("div", { style: { visibility: "hidden" } }, this.$slots.default);
|
|
103
|
-
},
|
|
104
|
-
beforeDestroy() {
|
|
105
|
-
this.editor.unregisterPlugin(this.pluginKey);
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
|
|
109
44
|
// src/Editor.ts
|
|
110
45
|
var import_core = require("@tiptap/core");
|
|
111
46
|
var Editor = class extends import_core.Editor {
|
|
@@ -130,8 +65,9 @@ var EditorContent = {
|
|
|
130
65
|
handler(editor) {
|
|
131
66
|
if (editor && editor.options.element) {
|
|
132
67
|
this.$nextTick(() => {
|
|
68
|
+
var _a;
|
|
133
69
|
const element = this.$el;
|
|
134
|
-
if (!element || !editor.options.element.firstChild) {
|
|
70
|
+
if (!element || !((_a = editor.options.element) == null ? void 0 : _a.firstChild)) {
|
|
135
71
|
return;
|
|
136
72
|
}
|
|
137
73
|
element.append(...editor.options.element.childNodes);
|
|
@@ -149,6 +85,7 @@ var EditorContent = {
|
|
|
149
85
|
return createElement("div");
|
|
150
86
|
},
|
|
151
87
|
beforeDestroy() {
|
|
88
|
+
var _a;
|
|
152
89
|
const { editor } = this;
|
|
153
90
|
if (!editor) {
|
|
154
91
|
return;
|
|
@@ -159,7 +96,7 @@ var EditorContent = {
|
|
|
159
96
|
});
|
|
160
97
|
}
|
|
161
98
|
editor.contentComponent = null;
|
|
162
|
-
if (!editor.options.element.firstChild) {
|
|
99
|
+
if (!((_a = editor.options.element) == null ? void 0 : _a.firstChild)) {
|
|
163
100
|
return;
|
|
164
101
|
}
|
|
165
102
|
const newElement = document.createElement("div");
|
|
@@ -170,61 +107,6 @@ var EditorContent = {
|
|
|
170
107
|
}
|
|
171
108
|
};
|
|
172
109
|
|
|
173
|
-
// src/FloatingMenu.ts
|
|
174
|
-
var import_extension_floating_menu = require("@tiptap/extension-floating-menu");
|
|
175
|
-
var FloatingMenu = {
|
|
176
|
-
name: "FloatingMenu",
|
|
177
|
-
props: {
|
|
178
|
-
pluginKey: {
|
|
179
|
-
type: [String, Object],
|
|
180
|
-
default: "floatingMenu"
|
|
181
|
-
},
|
|
182
|
-
editor: {
|
|
183
|
-
type: Object,
|
|
184
|
-
required: true
|
|
185
|
-
},
|
|
186
|
-
options: {
|
|
187
|
-
type: Object,
|
|
188
|
-
default: () => ({})
|
|
189
|
-
},
|
|
190
|
-
shouldShow: {
|
|
191
|
-
type: Function,
|
|
192
|
-
default: null
|
|
193
|
-
}
|
|
194
|
-
},
|
|
195
|
-
watch: {
|
|
196
|
-
editor: {
|
|
197
|
-
immediate: true,
|
|
198
|
-
handler(editor) {
|
|
199
|
-
if (!editor) {
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
;
|
|
203
|
-
this.$el.style.visibility = "hidden";
|
|
204
|
-
this.$el.style.position = "absolute";
|
|
205
|
-
this.$el.remove();
|
|
206
|
-
this.$nextTick(() => {
|
|
207
|
-
editor.registerPlugin(
|
|
208
|
-
(0, import_extension_floating_menu.FloatingMenuPlugin)({
|
|
209
|
-
pluginKey: this.pluginKey,
|
|
210
|
-
editor,
|
|
211
|
-
element: this.$el,
|
|
212
|
-
options: this.options,
|
|
213
|
-
shouldShow: this.shouldShow
|
|
214
|
-
})
|
|
215
|
-
);
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
},
|
|
220
|
-
render(createElement) {
|
|
221
|
-
return createElement("div", { style: { visibility: "hidden" } }, this.$slots.default);
|
|
222
|
-
},
|
|
223
|
-
beforeDestroy() {
|
|
224
|
-
this.editor.unregisterPlugin(this.pluginKey);
|
|
225
|
-
}
|
|
226
|
-
};
|
|
227
|
-
|
|
228
110
|
// src/NodeViewContent.ts
|
|
229
111
|
var NodeViewContent = {
|
|
230
112
|
props: {
|
|
@@ -477,10 +359,8 @@ function VueNodeViewRenderer(component, options) {
|
|
|
477
359
|
__reExport(index_exports, require("@tiptap/core"), module.exports);
|
|
478
360
|
// Annotate the CommonJS export names for ESM import in node:
|
|
479
361
|
0 && (module.exports = {
|
|
480
|
-
BubbleMenu,
|
|
481
362
|
Editor,
|
|
482
363
|
EditorContent,
|
|
483
|
-
FloatingMenu,
|
|
484
364
|
NodeViewContent,
|
|
485
365
|
NodeViewWrapper,
|
|
486
366
|
VueNodeViewRenderer,
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/BubbleMenu.ts","../src/Editor.ts","../src/EditorContent.ts","../src/FloatingMenu.ts","../src/NodeViewContent.ts","../src/NodeViewWrapper.ts","../src/VueNodeViewRenderer.ts","../src/VueRenderer.ts"],"sourcesContent":["export * from './BubbleMenu.js'\nexport { Editor } from './Editor.js'\nexport * from './EditorContent.js'\nexport * from './FloatingMenu.js'\nexport * from './NodeViewContent.js'\nexport * from './NodeViewWrapper.js'\nexport * from './VueNodeViewRenderer.js'\nexport * from './VueRenderer.js'\nexport * from '@tiptap/core'\n","import { BubbleMenuPlugin, BubbleMenuPluginProps } from '@tiptap/extension-bubble-menu'\nimport Vue, { Component, CreateElement, PropType } from 'vue'\n\nexport interface BubbleMenuInterface extends Vue {\n pluginKey: BubbleMenuPluginProps['pluginKey']\n editor: BubbleMenuPluginProps['editor']\n updateDelay: BubbleMenuPluginProps['updateDelay']\n resizeDelay: BubbleMenuPluginProps['resizeDelay']\n shouldShow: BubbleMenuPluginProps['shouldShow']\n options: BubbleMenuPluginProps['options']\n}\n\nexport const BubbleMenu: Component = {\n name: 'BubbleMenu',\n\n props: {\n pluginKey: {\n type: [String, Object as PropType<Exclude<BubbleMenuPluginProps['pluginKey'], string>>],\n default: 'bubbleMenu',\n },\n\n editor: {\n type: Object as PropType<BubbleMenuPluginProps['editor']>,\n required: true,\n },\n\n updateDelay: {\n type: Number as PropType<BubbleMenuPluginProps['updateDelay']>,\n },\n\n options: {\n type: Object as PropType<BubbleMenuPluginProps['options']>,\n default: {},\n },\n\n resizeDelay: {\n type: Number as PropType<BubbleMenuPluginProps['resizeDelay']>,\n },\n\n shouldShow: {\n type: Function as PropType<Exclude<BubbleMenuPluginProps['shouldShow'], null>>,\n default: null,\n },\n },\n\n watch: {\n editor: {\n immediate: true,\n handler(this: BubbleMenuInterface, editor: BubbleMenuPluginProps['editor']) {\n if (!editor) {\n return\n }\n\n ;(this.$el as HTMLElement).style.visibility = 'hidden'\n ;(this.$el as HTMLElement).style.position = 'absolute'\n\n this.$el.remove()\n\n this.$nextTick(() => {\n editor.registerPlugin(\n BubbleMenuPlugin({\n updateDelay: this.updateDelay,\n resizeDelay: this.resizeDelay,\n options: this.options,\n editor,\n element: this.$el as HTMLElement,\n pluginKey: this.pluginKey,\n shouldShow: this.shouldShow,\n }),\n )\n })\n },\n },\n },\n\n render(this: BubbleMenuInterface, createElement: CreateElement) {\n return createElement('div', { style: { visibility: 'hidden' } }, this.$slots.default)\n },\n\n beforeDestroy(this: BubbleMenuInterface) {\n this.editor.unregisterPlugin(this.pluginKey)\n },\n}\n","import { Editor as CoreEditor } from '@tiptap/core'\nimport Vue from 'vue'\n\nexport class Editor extends CoreEditor {\n public contentComponent: Vue | null = null\n}\n","import Vue, { Component, CreateElement, PropType } from 'vue'\n\nimport { Editor } from './Editor.js'\n\nexport interface EditorContentInterface extends Vue {\n editor: Editor\n}\n\nexport const EditorContent: Component = {\n name: 'EditorContent',\n\n props: {\n editor: {\n default: null,\n type: Object as PropType<Editor>,\n },\n },\n\n watch: {\n editor: {\n immediate: true,\n handler(this: EditorContentInterface, editor: Editor) {\n if (editor && editor.options.element) {\n this.$nextTick(() => {\n const element = this.$el\n\n if (!element || !editor.options.element.firstChild) {\n return\n }\n\n element.append(...editor.options.element.childNodes)\n editor.contentComponent = this\n\n editor.setOptions({\n element,\n })\n\n editor.createNodeViews()\n })\n }\n },\n },\n },\n\n render(createElement: CreateElement) {\n return createElement('div')\n },\n\n beforeDestroy(this: EditorContentInterface) {\n const { editor } = this\n\n if (!editor) {\n return\n }\n\n if (!editor.isDestroyed) {\n editor.view.setProps({\n nodeViews: {},\n })\n }\n\n editor.contentComponent = null\n\n if (!editor.options.element.firstChild) {\n return\n }\n\n const newElement = document.createElement('div')\n\n newElement.append(...editor.options.element.childNodes)\n\n editor.setOptions({\n element: newElement,\n })\n },\n}\n","import { FloatingMenuPlugin, FloatingMenuPluginProps } from '@tiptap/extension-floating-menu'\nimport Vue, { Component, CreateElement, PropType } from 'vue'\n\nexport interface FloatingMenuInterface extends Vue {\n pluginKey: FloatingMenuPluginProps['pluginKey']\n options: FloatingMenuPluginProps['options']\n editor: FloatingMenuPluginProps['editor']\n shouldShow: FloatingMenuPluginProps['shouldShow']\n}\n\nexport const FloatingMenu: Component = {\n name: 'FloatingMenu',\n\n props: {\n pluginKey: {\n type: [String, Object as PropType<Exclude<FloatingMenuPluginProps['pluginKey'], string>>],\n default: 'floatingMenu',\n },\n\n editor: {\n type: Object as PropType<FloatingMenuPluginProps['editor']>,\n required: true,\n },\n\n options: {\n type: Object as PropType<FloatingMenuPluginProps['options']>,\n default: () => ({}),\n },\n\n shouldShow: {\n type: Function as PropType<Exclude<FloatingMenuPluginProps['shouldShow'], null>>,\n default: null,\n },\n },\n\n watch: {\n editor: {\n immediate: true,\n handler(this: FloatingMenuInterface, editor: FloatingMenuPluginProps['editor']) {\n if (!editor) {\n return\n }\n\n ;(this.$el as HTMLElement).style.visibility = 'hidden'\n ;(this.$el as HTMLElement).style.position = 'absolute'\n\n this.$el.remove()\n\n this.$nextTick(() => {\n editor.registerPlugin(\n FloatingMenuPlugin({\n pluginKey: this.pluginKey,\n editor,\n element: this.$el as HTMLElement,\n options: this.options,\n shouldShow: this.shouldShow,\n }),\n )\n })\n },\n },\n },\n\n render(this: FloatingMenuInterface, createElement: CreateElement) {\n return createElement('div', { style: { visibility: 'hidden' } }, this.$slots.default)\n },\n\n beforeDestroy(this: FloatingMenuInterface) {\n this.editor.unregisterPlugin(this.pluginKey)\n },\n}\n","import Vue, { Component, CreateElement } from 'vue'\n\nexport interface NodeViewContentInterface extends Vue {\n as: string\n}\n\nexport const NodeViewContent: Component = {\n props: {\n as: {\n type: String,\n default: 'div',\n },\n },\n\n render(this: NodeViewContentInterface, createElement: CreateElement) {\n return createElement(this.as, {\n style: {\n whiteSpace: 'pre-wrap',\n },\n attrs: {\n 'data-node-view-content': '',\n },\n })\n },\n}\n","import Vue, { Component, CreateElement } from 'vue'\n\nexport interface NodeViewWrapperInterface extends Vue {\n as: string\n decorationClasses: {\n value: string\n }\n onDragStart: () => void\n}\n\nexport const NodeViewWrapper: Component = {\n props: {\n as: {\n type: String,\n default: 'div',\n },\n },\n\n inject: ['onDragStart', 'decorationClasses'],\n\n render(this: NodeViewWrapperInterface, createElement: CreateElement) {\n return createElement(\n this.as,\n {\n class: this.decorationClasses.value,\n style: {\n whiteSpace: 'normal',\n },\n attrs: {\n 'data-node-view-wrapper': '',\n },\n on: {\n dragstart: this.onDragStart,\n },\n },\n this.$slots.default,\n )\n },\n}\n","import { DecorationWithType, NodeView, NodeViewProps, NodeViewRenderer, NodeViewRendererOptions } from '@tiptap/core'\nimport { Node as ProseMirrorNode } from '@tiptap/pm/model'\nimport { Decoration, DecorationSource, NodeView as ProseMirrorNodeView } from '@tiptap/pm/view'\nimport Vue from 'vue'\nimport { VueConstructor } from 'vue/types/umd'\nimport { booleanProp, functionProp, objectProp } from 'vue-ts-types'\n\nimport { Editor } from './Editor.js'\nimport { VueRenderer } from './VueRenderer.js'\n\nexport const nodeViewProps = {\n editor: objectProp<NodeViewProps['editor']>().required,\n node: objectProp<NodeViewProps['node']>().required,\n decorations: objectProp<NodeViewProps['decorations']>().required,\n selected: booleanProp().required,\n extension: objectProp<NodeViewProps['extension']>().required,\n getPos: functionProp<NodeViewProps['getPos']>().required,\n updateAttributes: functionProp<NodeViewProps['updateAttributes']>().required,\n deleteNode: functionProp<NodeViewProps['deleteNode']>().required,\n}\n\nexport interface VueNodeViewRendererOptions extends NodeViewRendererOptions {\n update:\n | ((props: {\n oldNode: ProseMirrorNode\n oldDecorations: readonly Decoration[]\n oldInnerDecorations: DecorationSource\n newNode: ProseMirrorNode\n newDecorations: readonly Decoration[]\n innerDecorations: DecorationSource\n updateProps: () => void\n }) => boolean)\n | null\n}\n\nclass VueNodeView extends NodeView<Vue | VueConstructor, Editor, VueNodeViewRendererOptions> {\n renderer!: VueRenderer\n\n decorationClasses!: {\n value: string\n }\n\n mount() {\n const props = {\n editor: this.editor,\n node: this.node,\n decorations: this.decorations as DecorationWithType[],\n innerDecorations: this.innerDecorations,\n view: this.view,\n selected: false,\n extension: this.extension,\n HTMLAttributes: this.HTMLAttributes,\n getPos: () => this.getPos(),\n updateAttributes: (attributes = {}) => this.updateAttributes(attributes),\n deleteNode: () => this.deleteNode(),\n } satisfies NodeViewProps\n\n const onDragStart = this.onDragStart.bind(this)\n\n this.decorationClasses = Vue.observable({\n value: this.getDecorationClasses(),\n })\n\n // @ts-ignore\n const vue = this.editor.contentComponent?.$options._base ?? Vue // eslint-disable-line\n\n const Component = vue.extend(this.component).extend({\n props: Object.keys(props),\n provide: () => {\n return {\n onDragStart,\n decorationClasses: this.decorationClasses,\n }\n },\n })\n\n this.handleSelectionUpdate = this.handleSelectionUpdate.bind(this)\n this.editor.on('selectionUpdate', this.handleSelectionUpdate)\n\n this.renderer = new VueRenderer(Component, {\n parent: this.editor.contentComponent,\n propsData: props,\n })\n }\n\n /**\n * Return the DOM element.\n * This is the element that will be used to display the node view.\n */\n get dom() {\n if (!this.renderer.element.hasAttribute('data-node-view-wrapper')) {\n throw Error('Please use the NodeViewWrapper component for your node view.')\n }\n\n return this.renderer.element as HTMLElement\n }\n\n /**\n * Return the content DOM element.\n * This is the element that will be used to display the rich-text content of the node.\n */\n get contentDOM() {\n if (this.node.isLeaf) {\n return null\n }\n\n const contentElement = this.dom.querySelector('[data-node-view-content]')\n\n return (contentElement || this.dom) as HTMLElement | null\n }\n\n /**\n * On editor selection update, check if the node is selected.\n * If it is, call `selectNode`, otherwise call `deselectNode`.\n */\n handleSelectionUpdate() {\n const { from, to } = this.editor.state.selection\n const pos = this.getPos()\n\n if (typeof pos !== 'number') {\n return\n }\n\n if (from <= pos && to >= pos + this.node.nodeSize) {\n if (this.renderer.ref.$props.selected) {\n return\n }\n\n this.selectNode()\n } else {\n if (!this.renderer.ref.$props.selected) {\n return\n }\n\n this.deselectNode()\n }\n }\n\n /**\n * On update, update the React component.\n * To prevent unnecessary updates, the `update` option can be used.\n */\n update(node: ProseMirrorNode, decorations: readonly Decoration[], innerDecorations: DecorationSource): boolean {\n const rerenderComponent = (props?: Record<string, any>) => {\n this.decorationClasses.value = this.getDecorationClasses()\n this.renderer.updateProps(props)\n }\n\n if (typeof this.options.update === 'function') {\n const oldNode = this.node\n const oldDecorations = this.decorations\n const oldInnerDecorations = this.innerDecorations\n\n this.node = node\n this.decorations = decorations\n this.innerDecorations = innerDecorations\n\n return this.options.update({\n oldNode,\n oldDecorations,\n newNode: node,\n newDecorations: decorations,\n oldInnerDecorations,\n innerDecorations,\n updateProps: () => rerenderComponent({ node, decorations, innerDecorations }),\n })\n }\n\n if (node.type !== this.node.type) {\n return false\n }\n\n if (node === this.node && this.decorations === decorations && this.innerDecorations === innerDecorations) {\n return true\n }\n\n this.node = node\n this.decorations = decorations\n this.innerDecorations = innerDecorations\n\n rerenderComponent({ node, decorations, innerDecorations })\n\n return true\n }\n\n /**\n * Select the node.\n * Add the `selected` prop and the `ProseMirror-selectednode` class.\n */\n selectNode() {\n this.renderer.updateProps({\n selected: true,\n })\n this.renderer.element.classList.add('ProseMirror-selectednode')\n }\n\n /**\n * Deselect the node.\n * Remove the `selected` prop and the `ProseMirror-selectednode` class.\n */\n deselectNode() {\n this.renderer.updateProps({\n selected: false,\n })\n this.renderer.element.classList.remove('ProseMirror-selectednode')\n }\n\n getDecorationClasses() {\n return (\n this.decorations\n // @ts-ignore\n .map(item => item.type.attrs.class)\n .flat()\n .join(' ')\n )\n }\n\n destroy() {\n this.renderer.destroy()\n this.editor.off('selectionUpdate', this.handleSelectionUpdate)\n }\n}\n\nexport function VueNodeViewRenderer(\n component: Vue | VueConstructor,\n options?: Partial<VueNodeViewRendererOptions>,\n): NodeViewRenderer {\n return props => {\n // try to get the parent component\n // this is important for vue devtools to show the component hierarchy correctly\n // maybe it’s `undefined` because <editor-content> isn’t rendered yet\n if (!(props.editor as Editor).contentComponent) {\n return {} as unknown as ProseMirrorNodeView\n }\n\n return new VueNodeView(component, props, options)\n }\n}\n","import Vue from 'vue'\nimport { VueConstructor } from 'vue/types/umd'\n\n/**\n * The VueRenderer class is responsible for rendering a Vue component as a ProseMirror node view.\n */\nexport class VueRenderer {\n ref!: Vue\n\n constructor(component: Vue | VueConstructor, props: any) {\n const Component = typeof component === 'function' ? component : Vue.extend(component)\n\n this.ref = new Component(props).$mount()\n }\n\n get element(): Element {\n return this.ref.$el\n }\n\n updateProps(props: Record<string, any> = {}): void {\n if (!this.ref.$props) {\n return\n }\n\n // prevents `Avoid mutating a prop directly` error message\n // Fix: `VueNodeViewRenderer` change vue Constructor `config.silent` not working\n const currentVueConstructor = this.ref.$props.editor?.contentComponent?.$options._base ?? Vue // eslint-disable-line\n const originalSilent = currentVueConstructor.config.silent\n\n currentVueConstructor.config.silent = true\n\n Object.entries(props).forEach(([key, value]) => {\n this.ref.$props[key] = value\n })\n\n currentVueConstructor.config.silent = originalSilent\n }\n\n destroy(): void {\n this.ref.$destroy()\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mCAAwD;AAYjD,IAAM,aAAwB;AAAA,EACnC,MAAM;AAAA,EAEN,OAAO;AAAA,IACL,WAAW;AAAA,MACT,MAAM,CAAC,QAAQ,MAAuE;AAAA,MACtF,SAAS;AAAA,IACX;AAAA,IAEA,QAAQ;AAAA,MACN,MAAM;AAAA,MACN,UAAU;AAAA,IACZ;AAAA,IAEA,aAAa;AAAA,MACX,MAAM;AAAA,IACR;AAAA,IAEA,SAAS;AAAA,MACP,MAAM;AAAA,MACN,SAAS,CAAC;AAAA,IACZ;AAAA,IAEA,aAAa;AAAA,MACX,MAAM;AAAA,IACR;AAAA,IAEA,YAAY;AAAA,MACV,MAAM;AAAA,MACN,SAAS;AAAA,IACX;AAAA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AA,IACT;AAEA,SAAK,OAAO;AACZ,SAAK,cAAc;AACnB,SAAK,mBAAmB;AAExB,sBAAkB,EAAE,MAAM,aAAa,iBAAiB,CAAC;AAEzD,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,aAAa;AACX,SAAK,SAAS,YAAY;AAAA,MACxB,UAAU;AAAA,IACZ,CAAC;AACD,SAAK,SAAS,QAAQ,UAAU,IAAI,0BAA0B;AAAA,EAChE;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,eAAe;AACb,SAAK,SAAS,YAAY;AAAA,MACxB,UAAU;AAAA,IACZ,CAAC;AACD,SAAK,SAAS,QAAQ,UAAU,OAAO,0BAA0B;AAAA,EACnE;AAAA,EAEA,uBAAuB;AACrB,WACE,KAAK,YAEF,IAAI,UAAQ,KAAK,KAAK,MAAM,KAAK,EACjC,KAAK,EACL,KAAK,GAAG;AAAA,EAEf;AAAA,EAEA,UAAU;AACR,SAAK,SAAS,QAAQ;AACtB,SAAK,OAAO,IAAI,mBAAmB,KAAK,qBAAqB;AAAA,EAC/D;AACF;AAEO,SAAS,oBACd,WACA,SACkB;AAClB,SAAO,WAAS;AAId,QAAI,CAAE,MAAM,OAAkB,kBAAkB;AAC9C,aAAO,CAAC;AAAA,IACV;AAEA,WAAO,IAAI,YAAY,WAAW,OAAO,OAAO;AAAA,EAClD;AACF;;;APrOA,0BAAc,yBARd;","names":["CoreEditor","import_core","import_vue","Vue","Vue"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/Editor.ts","../src/EditorContent.ts","../src/NodeViewContent.ts","../src/NodeViewWrapper.ts","../src/VueNodeViewRenderer.ts","../src/VueRenderer.ts"],"sourcesContent":["export { Editor } from './Editor.js'\nexport * from './EditorContent.js'\nexport * from './NodeViewContent.js'\nexport * from './NodeViewWrapper.js'\nexport * from './VueNodeViewRenderer.js'\nexport * from './VueRenderer.js'\nexport * from '@tiptap/core'\n","import { Editor as CoreEditor } from '@tiptap/core'\nimport Vue from 'vue'\n\nexport class Editor extends CoreEditor {\n public contentComponent: Vue | null = null\n}\n","import Vue, { Component, CreateElement, PropType } from 'vue'\n\nimport { Editor } from './Editor.js'\n\nexport interface EditorContentInterface extends Vue {\n editor: Editor\n}\n\nexport const EditorContent: Component = {\n name: 'EditorContent',\n\n props: {\n editor: {\n default: null,\n type: Object as PropType<Editor>,\n },\n },\n\n watch: {\n editor: {\n immediate: true,\n handler(this: EditorContentInterface, editor: Editor) {\n if (editor && editor.options.element) {\n this.$nextTick(() => {\n const element = this.$el\n\n if (!element || !editor.options.element?.firstChild) {\n return\n }\n\n element.append(...editor.options.element.childNodes)\n editor.contentComponent = this\n\n editor.setOptions({\n element,\n })\n\n editor.createNodeViews()\n })\n }\n },\n },\n },\n\n render(createElement: CreateElement) {\n return createElement('div')\n },\n\n beforeDestroy(this: EditorContentInterface) {\n const { editor } = this\n\n if (!editor) {\n return\n }\n\n if (!editor.isDestroyed) {\n editor.view.setProps({\n nodeViews: {},\n })\n }\n\n editor.contentComponent = null\n\n if (!editor.options.element?.firstChild) {\n return\n }\n\n // TODO using the new editor.mount method might allow us to remove this\n const newElement = document.createElement('div')\n\n newElement.append(...editor.options.element.childNodes)\n\n editor.setOptions({\n element: newElement,\n })\n },\n}\n","import Vue, { Component, CreateElement } from 'vue'\n\nexport interface NodeViewContentInterface extends Vue {\n as: string\n}\n\nexport const NodeViewContent: Component = {\n props: {\n as: {\n type: String,\n default: 'div',\n },\n },\n\n render(this: NodeViewContentInterface, createElement: CreateElement) {\n return createElement(this.as, {\n style: {\n whiteSpace: 'pre-wrap',\n },\n attrs: {\n 'data-node-view-content': '',\n },\n })\n },\n}\n","import Vue, { Component, CreateElement } from 'vue'\n\nexport interface NodeViewWrapperInterface extends Vue {\n as: string\n decorationClasses: {\n value: string\n }\n onDragStart: () => void\n}\n\nexport const NodeViewWrapper: Component = {\n props: {\n as: {\n type: String,\n default: 'div',\n },\n },\n\n inject: ['onDragStart', 'decorationClasses'],\n\n render(this: NodeViewWrapperInterface, createElement: CreateElement) {\n return createElement(\n this.as,\n {\n class: this.decorationClasses.value,\n style: {\n whiteSpace: 'normal',\n },\n attrs: {\n 'data-node-view-wrapper': '',\n },\n on: {\n dragstart: this.onDragStart,\n },\n },\n this.$slots.default,\n )\n },\n}\n","import { DecorationWithType, NodeView, NodeViewProps, NodeViewRenderer, NodeViewRendererOptions } from '@tiptap/core'\nimport { Node as ProseMirrorNode } from '@tiptap/pm/model'\nimport { Decoration, DecorationSource, NodeView as ProseMirrorNodeView } from '@tiptap/pm/view'\nimport Vue from 'vue'\nimport { VueConstructor } from 'vue/types/umd'\nimport { booleanProp, functionProp, objectProp } from 'vue-ts-types'\n\nimport { Editor } from './Editor.js'\nimport { VueRenderer } from './VueRenderer.js'\n\nexport const nodeViewProps = {\n editor: objectProp<NodeViewProps['editor']>().required,\n node: objectProp<NodeViewProps['node']>().required,\n decorations: objectProp<NodeViewProps['decorations']>().required,\n selected: booleanProp().required,\n extension: objectProp<NodeViewProps['extension']>().required,\n getPos: functionProp<NodeViewProps['getPos']>().required,\n updateAttributes: functionProp<NodeViewProps['updateAttributes']>().required,\n deleteNode: functionProp<NodeViewProps['deleteNode']>().required,\n}\n\nexport interface VueNodeViewRendererOptions extends NodeViewRendererOptions {\n update:\n | ((props: {\n oldNode: ProseMirrorNode\n oldDecorations: readonly Decoration[]\n oldInnerDecorations: DecorationSource\n newNode: ProseMirrorNode\n newDecorations: readonly Decoration[]\n innerDecorations: DecorationSource\n updateProps: () => void\n }) => boolean)\n | null\n}\n\nclass VueNodeView extends NodeView<Vue | VueConstructor, Editor, VueNodeViewRendererOptions> {\n renderer!: VueRenderer\n\n decorationClasses!: {\n value: string\n }\n\n mount() {\n const props = {\n editor: this.editor,\n node: this.node,\n decorations: this.decorations as DecorationWithType[],\n innerDecorations: this.innerDecorations,\n view: this.view,\n selected: false,\n extension: this.extension,\n HTMLAttributes: this.HTMLAttributes,\n getPos: () => this.getPos(),\n updateAttributes: (attributes = {}) => this.updateAttributes(attributes),\n deleteNode: () => this.deleteNode(),\n } satisfies NodeViewProps\n\n const onDragStart = this.onDragStart.bind(this)\n\n this.decorationClasses = Vue.observable({\n value: this.getDecorationClasses(),\n })\n\n // @ts-ignore\n const vue = this.editor.contentComponent?.$options._base ?? Vue // eslint-disable-line\n\n const Component = vue.extend(this.component).extend({\n props: Object.keys(props),\n provide: () => {\n return {\n onDragStart,\n decorationClasses: this.decorationClasses,\n }\n },\n })\n\n this.handleSelectionUpdate = this.handleSelectionUpdate.bind(this)\n this.editor.on('selectionUpdate', this.handleSelectionUpdate)\n\n this.renderer = new VueRenderer(Component, {\n parent: this.editor.contentComponent,\n propsData: props,\n })\n }\n\n /**\n * Return the DOM element.\n * This is the element that will be used to display the node view.\n */\n get dom() {\n if (!this.renderer.element.hasAttribute('data-node-view-wrapper')) {\n throw Error('Please use the NodeViewWrapper component for your node view.')\n }\n\n return this.renderer.element as HTMLElement\n }\n\n /**\n * Return the content DOM element.\n * This is the element that will be used to display the rich-text content of the node.\n */\n get contentDOM() {\n if (this.node.isLeaf) {\n return null\n }\n\n const contentElement = this.dom.querySelector('[data-node-view-content]')\n\n return (contentElement || this.dom) as HTMLElement | null\n }\n\n /**\n * On editor selection update, check if the node is selected.\n * If it is, call `selectNode`, otherwise call `deselectNode`.\n */\n handleSelectionUpdate() {\n const { from, to } = this.editor.state.selection\n const pos = this.getPos()\n\n if (typeof pos !== 'number') {\n return\n }\n\n if (from <= pos && to >= pos + this.node.nodeSize) {\n if (this.renderer.ref.$props.selected) {\n return\n }\n\n this.selectNode()\n } else {\n if (!this.renderer.ref.$props.selected) {\n return\n }\n\n this.deselectNode()\n }\n }\n\n /**\n * On update, update the React component.\n * To prevent unnecessary updates, the `update` option can be used.\n */\n update(node: ProseMirrorNode, decorations: readonly Decoration[], innerDecorations: DecorationSource): boolean {\n const rerenderComponent = (props?: Record<string, any>) => {\n this.decorationClasses.value = this.getDecorationClasses()\n this.renderer.updateProps(props)\n }\n\n if (typeof this.options.update === 'function') {\n const oldNode = this.node\n const oldDecorations = this.decorations\n const oldInnerDecorations = this.innerDecorations\n\n this.node = node\n this.decorations = decorations\n this.innerDecorations = innerDecorations\n\n return this.options.update({\n oldNode,\n oldDecorations,\n newNode: node,\n newDecorations: decorations,\n oldInnerDecorations,\n innerDecorations,\n updateProps: () => rerenderComponent({ node, decorations, innerDecorations }),\n })\n }\n\n if (node.type !== this.node.type) {\n return false\n }\n\n if (node === this.node && this.decorations === decorations && this.innerDecorations === innerDecorations) {\n return true\n }\n\n this.node = node\n this.decorations = decorations\n this.innerDecorations = innerDecorations\n\n rerenderComponent({ node, decorations, innerDecorations })\n\n return true\n }\n\n /**\n * Select the node.\n * Add the `selected` prop and the `ProseMirror-selectednode` class.\n */\n selectNode() {\n this.renderer.updateProps({\n selected: true,\n })\n this.renderer.element.classList.add('ProseMirror-selectednode')\n }\n\n /**\n * Deselect the node.\n * Remove the `selected` prop and the `ProseMirror-selectednode` class.\n */\n deselectNode() {\n this.renderer.updateProps({\n selected: false,\n })\n this.renderer.element.classList.remove('ProseMirror-selectednode')\n }\n\n getDecorationClasses() {\n return (\n this.decorations\n // @ts-ignore\n .map(item => item.type.attrs.class)\n .flat()\n .join(' ')\n )\n }\n\n destroy() {\n this.renderer.destroy()\n this.editor.off('selectionUpdate', this.handleSelectionUpdate)\n }\n}\n\nexport function VueNodeViewRenderer(\n component: Vue | VueConstructor,\n options?: Partial<VueNodeViewRendererOptions>,\n): NodeViewRenderer {\n return props => {\n // try to get the parent component\n // this is important for vue devtools to show the component hierarchy correctly\n // maybe it’s `undefined` because <editor-content> isn’t rendered yet\n if (!(props.editor as Editor).contentComponent) {\n return {} as unknown as ProseMirrorNodeView\n }\n\n return new VueNodeView(component, props, options)\n }\n}\n","import Vue from 'vue'\nimport { VueConstructor } from 'vue/types/umd'\n\n/**\n * The VueRenderer class is responsible for rendering a Vue component as a ProseMirror node view.\n */\nexport class VueRenderer {\n ref!: Vue\n\n constructor(component: Vue | VueConstructor, props: any) {\n const Component = typeof component === 'function' ? component : Vue.extend(component)\n\n this.ref = new Component(props).$mount()\n }\n\n get element(): Element {\n return this.ref.$el\n }\n\n updateProps(props: Record<string, any> = {}): void {\n if (!this.ref.$props) {\n return\n }\n\n // prevents `Avoid mutating a prop directly` error message\n // Fix: `VueNodeViewRenderer` change vue Constructor `config.silent` not working\n const currentVueConstructor = this.ref.$props.editor?.contentComponent?.$options._base ?? Vue // eslint-disable-line\n const originalSilent = currentVueConstructor.config.silent\n\n currentVueConstructor.config.silent = true\n\n Object.entries(props).forEach(([key, value]) => {\n this.ref.$props[key] = value\n })\n\n currentVueConstructor.config.silent = originalSilent\n }\n\n destroy(): void {\n this.ref.$destroy()\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAAqC;AAG9B,IAAM,SAAN,cAAqB,YAAAA,OAAW;AAAA,EAAhC;AAAA;AACL,SAAO,mBAA+B;AAAA;AACxC;;;ACGO,IAAM,gBAA2B;AAAA,EACtC,MAAM;AAAA,EAEN,OAAO;AAAA,IACL,QAAQ;AAAA,MACN,SAAS;AAAA,MACT,MAAM;AAAA,IACR;AAAA,EACF;AAAA,EAEA,OAAO;AAAA,IACL,QAAQ;AAAA,MACN,WAAW;AAAA,MACX,QAAsC,QAAgB;AACpD,YAAI,UAAU,OAAO,QAAQ,SAAS;AACpC,eAAK,UAAU,MAAM;AAvB/B;AAwBY,kBAAM,UAAU,KAAK;AAErB,gBAAI,CAAC,WAAW,GAAC,YAAO,QAAQ,YAAf,mBAAwB,aAAY;AACnD;AAAA,YACF;AAEA,oBAAQ,OAAO,GAAG,OAAO,QAAQ,QAAQ,UAAU;AACnD,mBAAO,mBAAmB;AAE1B,mBAAO,WAAW;AAAA,cAChB;AAAA,YACF,CAAC;AAED,mBAAO,gBAAgB;AAAA,UACzB,CAAC;AAAA,Q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AK,QAAQ,KAAK,gBAAgB,eAAe,KAAK,qBAAqB,kBAAkB;AACxG,aAAO;AAAA,IACT;AAEA,SAAK,OAAO;AACZ,SAAK,cAAc;AACnB,SAAK,mBAAmB;AAExB,sBAAkB,EAAE,MAAM,aAAa,iBAAiB,CAAC;AAEzD,WAAO;AAAA,EACT;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,aAAa;AACX,SAAK,SAAS,YAAY;AAAA,MACxB,UAAU;AAAA,IACZ,CAAC;AACD,SAAK,SAAS,QAAQ,UAAU,IAAI,0BAA0B;AAAA,EAChE;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,eAAe;AACb,SAAK,SAAS,YAAY;AAAA,MACxB,UAAU;AAAA,IACZ,CAAC;AACD,SAAK,SAAS,QAAQ,UAAU,OAAO,0BAA0B;AAAA,EACnE;AAAA,EAEA,uBAAuB;AACrB,WACE,KAAK,YAEF,IAAI,UAAQ,KAAK,KAAK,MAAM,KAAK,EACjC,KAAK,EACL,KAAK,GAAG;AAAA,EAEf;AAAA,EAEA,UAAU;AACR,SAAK,SAAS,QAAQ;AACtB,SAAK,OAAO,IAAI,mBAAmB,KAAK,qBAAqB;AAAA,EAC/D;AACF;AAEO,SAAS,oBACd,WACA,SACkB;AAClB,SAAO,WAAS;AAId,QAAI,CAAE,MAAM,OAAkB,kBAAkB;AAC9C,aAAO,CAAC;AAAA,IACV;AAEA,WAAO,IAAI,YAAY,WAAW,OAAO,OAAO;AAAA,EAClD;AACF;;;ALvOA,0BAAc,yBANd;","names":["CoreEditor","import_core","import_vue","Vue","Vue"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,24 +1,12 @@
|
|
|
1
|
-
import { BubbleMenuPluginProps } from '@tiptap/extension-bubble-menu';
|
|
2
|
-
import Vue, { Component } from 'vue';
|
|
3
1
|
import * as _tiptap_core from '@tiptap/core';
|
|
4
2
|
import { Editor as Editor$1, DecorationWithType, NodeViewRendererOptions, NodeViewRenderer } from '@tiptap/core';
|
|
5
3
|
export * from '@tiptap/core';
|
|
6
|
-
import {
|
|
4
|
+
import Vue, { Component } from 'vue';
|
|
7
5
|
import * as vue_ts_types_dist_types_js from 'vue-ts-types/dist/types.js';
|
|
8
6
|
import { Node } from '@tiptap/pm/model';
|
|
9
7
|
import { Decoration, DecorationSource } from '@tiptap/pm/view';
|
|
10
8
|
import { VueConstructor } from 'vue/types/umd';
|
|
11
9
|
|
|
12
|
-
interface BubbleMenuInterface extends Vue {
|
|
13
|
-
pluginKey: BubbleMenuPluginProps['pluginKey'];
|
|
14
|
-
editor: BubbleMenuPluginProps['editor'];
|
|
15
|
-
updateDelay: BubbleMenuPluginProps['updateDelay'];
|
|
16
|
-
resizeDelay: BubbleMenuPluginProps['resizeDelay'];
|
|
17
|
-
shouldShow: BubbleMenuPluginProps['shouldShow'];
|
|
18
|
-
options: BubbleMenuPluginProps['options'];
|
|
19
|
-
}
|
|
20
|
-
declare const BubbleMenu: Component;
|
|
21
|
-
|
|
22
10
|
declare class Editor extends Editor$1 {
|
|
23
11
|
contentComponent: Vue | null;
|
|
24
12
|
}
|
|
@@ -28,14 +16,6 @@ interface EditorContentInterface extends Vue {
|
|
|
28
16
|
}
|
|
29
17
|
declare const EditorContent: Component;
|
|
30
18
|
|
|
31
|
-
interface FloatingMenuInterface extends Vue {
|
|
32
|
-
pluginKey: FloatingMenuPluginProps['pluginKey'];
|
|
33
|
-
options: FloatingMenuPluginProps['options'];
|
|
34
|
-
editor: FloatingMenuPluginProps['editor'];
|
|
35
|
-
shouldShow: FloatingMenuPluginProps['shouldShow'];
|
|
36
|
-
}
|
|
37
|
-
declare const FloatingMenu: Component;
|
|
38
|
-
|
|
39
19
|
interface NodeViewContentInterface extends Vue {
|
|
40
20
|
as: string;
|
|
41
21
|
}
|
|
@@ -96,4 +76,4 @@ declare class VueRenderer {
|
|
|
96
76
|
destroy(): void;
|
|
97
77
|
}
|
|
98
78
|
|
|
99
|
-
export {
|
|
79
|
+
export { Editor, EditorContent, type EditorContentInterface, NodeViewContent, type NodeViewContentInterface, NodeViewWrapper, type NodeViewWrapperInterface, VueNodeViewRenderer, type VueNodeViewRendererOptions, VueRenderer, nodeViewProps };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,24 +1,12 @@
|
|
|
1
|
-
import { BubbleMenuPluginProps } from '@tiptap/extension-bubble-menu';
|
|
2
|
-
import Vue, { Component } from 'vue';
|
|
3
1
|
import * as _tiptap_core from '@tiptap/core';
|
|
4
2
|
import { Editor as Editor$1, DecorationWithType, NodeViewRendererOptions, NodeViewRenderer } from '@tiptap/core';
|
|
5
3
|
export * from '@tiptap/core';
|
|
6
|
-
import {
|
|
4
|
+
import Vue, { Component } from 'vue';
|
|
7
5
|
import * as vue_ts_types_dist_types_js from 'vue-ts-types/dist/types.js';
|
|
8
6
|
import { Node } from '@tiptap/pm/model';
|
|
9
7
|
import { Decoration, DecorationSource } from '@tiptap/pm/view';
|
|
10
8
|
import { VueConstructor } from 'vue/types/umd';
|
|
11
9
|
|
|
12
|
-
interface BubbleMenuInterface extends Vue {
|
|
13
|
-
pluginKey: BubbleMenuPluginProps['pluginKey'];
|
|
14
|
-
editor: BubbleMenuPluginProps['editor'];
|
|
15
|
-
updateDelay: BubbleMenuPluginProps['updateDelay'];
|
|
16
|
-
resizeDelay: BubbleMenuPluginProps['resizeDelay'];
|
|
17
|
-
shouldShow: BubbleMenuPluginProps['shouldShow'];
|
|
18
|
-
options: BubbleMenuPluginProps['options'];
|
|
19
|
-
}
|
|
20
|
-
declare const BubbleMenu: Component;
|
|
21
|
-
|
|
22
10
|
declare class Editor extends Editor$1 {
|
|
23
11
|
contentComponent: Vue | null;
|
|
24
12
|
}
|
|
@@ -28,14 +16,6 @@ interface EditorContentInterface extends Vue {
|
|
|
28
16
|
}
|
|
29
17
|
declare const EditorContent: Component;
|
|
30
18
|
|
|
31
|
-
interface FloatingMenuInterface extends Vue {
|
|
32
|
-
pluginKey: FloatingMenuPluginProps['pluginKey'];
|
|
33
|
-
options: FloatingMenuPluginProps['options'];
|
|
34
|
-
editor: FloatingMenuPluginProps['editor'];
|
|
35
|
-
shouldShow: FloatingMenuPluginProps['shouldShow'];
|
|
36
|
-
}
|
|
37
|
-
declare const FloatingMenu: Component;
|
|
38
|
-
|
|
39
19
|
interface NodeViewContentInterface extends Vue {
|
|
40
20
|
as: string;
|
|
41
21
|
}
|
|
@@ -96,4 +76,4 @@ declare class VueRenderer {
|
|
|
96
76
|
destroy(): void;
|
|
97
77
|
}
|
|
98
78
|
|
|
99
|
-
export {
|
|
79
|
+
export { Editor, EditorContent, type EditorContentInterface, NodeViewContent, type NodeViewContentInterface, NodeViewWrapper, type NodeViewWrapperInterface, VueNodeViewRenderer, type VueNodeViewRendererOptions, VueRenderer, nodeViewProps };
|
package/dist/index.js
CHANGED
|
@@ -1,66 +1,3 @@
|
|
|
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
|
-
options: {
|
|
18
|
-
type: Object,
|
|
19
|
-
default: {}
|
|
20
|
-
},
|
|
21
|
-
resizeDelay: {
|
|
22
|
-
type: Number
|
|
23
|
-
},
|
|
24
|
-
shouldShow: {
|
|
25
|
-
type: Function,
|
|
26
|
-
default: null
|
|
27
|
-
}
|
|
28
|
-
},
|
|
29
|
-
watch: {
|
|
30
|
-
editor: {
|
|
31
|
-
immediate: true,
|
|
32
|
-
handler(editor) {
|
|
33
|
-
if (!editor) {
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
;
|
|
37
|
-
this.$el.style.visibility = "hidden";
|
|
38
|
-
this.$el.style.position = "absolute";
|
|
39
|
-
this.$el.remove();
|
|
40
|
-
this.$nextTick(() => {
|
|
41
|
-
editor.registerPlugin(
|
|
42
|
-
BubbleMenuPlugin({
|
|
43
|
-
updateDelay: this.updateDelay,
|
|
44
|
-
resizeDelay: this.resizeDelay,
|
|
45
|
-
options: this.options,
|
|
46
|
-
editor,
|
|
47
|
-
element: this.$el,
|
|
48
|
-
pluginKey: this.pluginKey,
|
|
49
|
-
shouldShow: this.shouldShow
|
|
50
|
-
})
|
|
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
|
-
}
|
|
62
|
-
};
|
|
63
|
-
|
|
64
1
|
// src/Editor.ts
|
|
65
2
|
import { Editor as CoreEditor } from "@tiptap/core";
|
|
66
3
|
var Editor = class extends CoreEditor {
|
|
@@ -85,8 +22,9 @@ var EditorContent = {
|
|
|
85
22
|
handler(editor) {
|
|
86
23
|
if (editor && editor.options.element) {
|
|
87
24
|
this.$nextTick(() => {
|
|
25
|
+
var _a;
|
|
88
26
|
const element = this.$el;
|
|
89
|
-
if (!element || !editor.options.element.firstChild) {
|
|
27
|
+
if (!element || !((_a = editor.options.element) == null ? void 0 : _a.firstChild)) {
|
|
90
28
|
return;
|
|
91
29
|
}
|
|
92
30
|
element.append(...editor.options.element.childNodes);
|
|
@@ -104,6 +42,7 @@ var EditorContent = {
|
|
|
104
42
|
return createElement("div");
|
|
105
43
|
},
|
|
106
44
|
beforeDestroy() {
|
|
45
|
+
var _a;
|
|
107
46
|
const { editor } = this;
|
|
108
47
|
if (!editor) {
|
|
109
48
|
return;
|
|
@@ -114,7 +53,7 @@ var EditorContent = {
|
|
|
114
53
|
});
|
|
115
54
|
}
|
|
116
55
|
editor.contentComponent = null;
|
|
117
|
-
if (!editor.options.element.firstChild) {
|
|
56
|
+
if (!((_a = editor.options.element) == null ? void 0 : _a.firstChild)) {
|
|
118
57
|
return;
|
|
119
58
|
}
|
|
120
59
|
const newElement = document.createElement("div");
|
|
@@ -125,61 +64,6 @@ var EditorContent = {
|
|
|
125
64
|
}
|
|
126
65
|
};
|
|
127
66
|
|
|
128
|
-
// src/FloatingMenu.ts
|
|
129
|
-
import { FloatingMenuPlugin } from "@tiptap/extension-floating-menu";
|
|
130
|
-
var FloatingMenu = {
|
|
131
|
-
name: "FloatingMenu",
|
|
132
|
-
props: {
|
|
133
|
-
pluginKey: {
|
|
134
|
-
type: [String, Object],
|
|
135
|
-
default: "floatingMenu"
|
|
136
|
-
},
|
|
137
|
-
editor: {
|
|
138
|
-
type: Object,
|
|
139
|
-
required: true
|
|
140
|
-
},
|
|
141
|
-
options: {
|
|
142
|
-
type: Object,
|
|
143
|
-
default: () => ({})
|
|
144
|
-
},
|
|
145
|
-
shouldShow: {
|
|
146
|
-
type: Function,
|
|
147
|
-
default: null
|
|
148
|
-
}
|
|
149
|
-
},
|
|
150
|
-
watch: {
|
|
151
|
-
editor: {
|
|
152
|
-
immediate: true,
|
|
153
|
-
handler(editor) {
|
|
154
|
-
if (!editor) {
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
;
|
|
158
|
-
this.$el.style.visibility = "hidden";
|
|
159
|
-
this.$el.style.position = "absolute";
|
|
160
|
-
this.$el.remove();
|
|
161
|
-
this.$nextTick(() => {
|
|
162
|
-
editor.registerPlugin(
|
|
163
|
-
FloatingMenuPlugin({
|
|
164
|
-
pluginKey: this.pluginKey,
|
|
165
|
-
editor,
|
|
166
|
-
element: this.$el,
|
|
167
|
-
options: this.options,
|
|
168
|
-
shouldShow: this.shouldShow
|
|
169
|
-
})
|
|
170
|
-
);
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
},
|
|
175
|
-
render(createElement) {
|
|
176
|
-
return createElement("div", { style: { visibility: "hidden" } }, this.$slots.default);
|
|
177
|
-
},
|
|
178
|
-
beforeDestroy() {
|
|
179
|
-
this.editor.unregisterPlugin(this.pluginKey);
|
|
180
|
-
}
|
|
181
|
-
};
|
|
182
|
-
|
|
183
67
|
// src/NodeViewContent.ts
|
|
184
68
|
var NodeViewContent = {
|
|
185
69
|
props: {
|
|
@@ -431,10 +315,8 @@ function VueNodeViewRenderer(component, options) {
|
|
|
431
315
|
// src/index.ts
|
|
432
316
|
export * from "@tiptap/core";
|
|
433
317
|
export {
|
|
434
|
-
BubbleMenu,
|
|
435
318
|
Editor,
|
|
436
319
|
EditorContent,
|
|
437
|
-
FloatingMenu,
|
|
438
320
|
NodeViewContent,
|
|
439
321
|
NodeViewWrapper,
|
|
440
322
|
VueNodeViewRenderer,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/BubbleMenu.ts","../src/Editor.ts","../src/EditorContent.ts","../src/FloatingMenu.ts","../src/NodeViewContent.ts","../src/NodeViewWrapper.ts","../src/VueNodeViewRenderer.ts","../src/VueRenderer.ts","../src/index.ts"],"sourcesContent":["import { BubbleMenuPlugin, BubbleMenuPluginProps } from '@tiptap/extension-bubble-menu'\nimport Vue, { Component, CreateElement, PropType } from 'vue'\n\nexport interface BubbleMenuInterface extends Vue {\n pluginKey: BubbleMenuPluginProps['pluginKey']\n editor: BubbleMenuPluginProps['editor']\n updateDelay: BubbleMenuPluginProps['updateDelay']\n resizeDelay: BubbleMenuPluginProps['resizeDelay']\n shouldShow: BubbleMenuPluginProps['shouldShow']\n options: BubbleMenuPluginProps['options']\n}\n\nexport const BubbleMenu: Component = {\n name: 'BubbleMenu',\n\n props: {\n pluginKey: {\n type: [String, Object as PropType<Exclude<BubbleMenuPluginProps['pluginKey'], string>>],\n default: 'bubbleMenu',\n },\n\n editor: {\n type: Object as PropType<BubbleMenuPluginProps['editor']>,\n required: true,\n },\n\n updateDelay: {\n type: Number as PropType<BubbleMenuPluginProps['updateDelay']>,\n },\n\n options: {\n type: Object as PropType<BubbleMenuPluginProps['options']>,\n default: {},\n },\n\n resizeDelay: {\n type: Number as PropType<BubbleMenuPluginProps['resizeDelay']>,\n },\n\n shouldShow: {\n type: Function as PropType<Exclude<BubbleMenuPluginProps['shouldShow'], null>>,\n default: null,\n },\n },\n\n watch: {\n editor: {\n immediate: true,\n handler(this: BubbleMenuInterface, editor: BubbleMenuPluginProps['editor']) {\n if (!editor) {\n return\n }\n\n ;(this.$el as HTMLElement).style.visibility = 'hidden'\n ;(this.$el as HTMLElement).style.position = 'absolute'\n\n this.$el.remove()\n\n this.$nextTick(() => {\n editor.registerPlugin(\n BubbleMenuPlugin({\n updateDelay: this.updateDelay,\n resizeDelay: this.resizeDelay,\n options: this.options,\n editor,\n element: this.$el as HTMLElement,\n pluginKey: this.pluginKey,\n shouldShow: this.shouldShow,\n }),\n )\n })\n },\n },\n },\n\n render(this: BubbleMenuInterface, createElement: CreateElement) {\n return createElement('div', { style: { visibility: 'hidden' } }, this.$slots.default)\n },\n\n beforeDestroy(this: BubbleMenuInterface) {\n this.editor.unregisterPlugin(this.pluginKey)\n },\n}\n","import { Editor as CoreEditor } from '@tiptap/core'\nimport Vue from 'vue'\n\nexport class Editor extends CoreEditor {\n public contentComponent: Vue | null = null\n}\n","import Vue, { Component, CreateElement, PropType } from 'vue'\n\nimport { Editor } from './Editor.js'\n\nexport interface EditorContentInterface extends Vue {\n editor: Editor\n}\n\nexport const EditorContent: Component = {\n name: 'EditorContent',\n\n props: {\n editor: {\n default: null,\n type: Object as PropType<Editor>,\n },\n },\n\n watch: {\n editor: {\n immediate: true,\n handler(this: EditorContentInterface, editor: Editor) {\n if (editor && editor.options.element) {\n this.$nextTick(() => {\n const element = this.$el\n\n if (!element || !editor.options.element.firstChild) {\n return\n }\n\n element.append(...editor.options.element.childNodes)\n editor.contentComponent = this\n\n editor.setOptions({\n element,\n })\n\n editor.createNodeViews()\n })\n }\n },\n },\n },\n\n render(createElement: CreateElement) {\n return createElement('div')\n },\n\n beforeDestroy(this: EditorContentInterface) {\n const { editor } = this\n\n if (!editor) {\n return\n }\n\n if (!editor.isDestroyed) {\n editor.view.setProps({\n nodeViews: {},\n })\n }\n\n editor.contentComponent = null\n\n if (!editor.options.element.firstChild) {\n return\n }\n\n const newElement = document.createElement('div')\n\n newElement.append(...editor.options.element.childNodes)\n\n editor.setOptions({\n element: newElement,\n })\n },\n}\n","import { FloatingMenuPlugin, FloatingMenuPluginProps } from '@tiptap/extension-floating-menu'\nimport Vue, { Component, CreateElement, PropType } from 'vue'\n\nexport interface FloatingMenuInterface extends Vue {\n pluginKey: FloatingMenuPluginProps['pluginKey']\n options: FloatingMenuPluginProps['options']\n editor: FloatingMenuPluginProps['editor']\n shouldShow: FloatingMenuPluginProps['shouldShow']\n}\n\nexport const FloatingMenu: Component = {\n name: 'FloatingMenu',\n\n props: {\n pluginKey: {\n type: [String, Object as PropType<Exclude<FloatingMenuPluginProps['pluginKey'], string>>],\n default: 'floatingMenu',\n },\n\n editor: {\n type: Object as PropType<FloatingMenuPluginProps['editor']>,\n required: true,\n },\n\n options: {\n type: Object as PropType<FloatingMenuPluginProps['options']>,\n default: () => ({}),\n },\n\n shouldShow: {\n type: Function as PropType<Exclude<FloatingMenuPluginProps['shouldShow'], null>>,\n default: null,\n },\n },\n\n watch: {\n editor: {\n immediate: true,\n handler(this: FloatingMenuInterface, editor: FloatingMenuPluginProps['editor']) {\n if (!editor) {\n return\n }\n\n ;(this.$el as HTMLElement).style.visibility = 'hidden'\n ;(this.$el as HTMLElement).style.position = 'absolute'\n\n this.$el.remove()\n\n this.$nextTick(() => {\n editor.registerPlugin(\n FloatingMenuPlugin({\n pluginKey: this.pluginKey,\n editor,\n element: this.$el as HTMLElement,\n options: this.options,\n shouldShow: this.shouldShow,\n }),\n )\n })\n },\n },\n },\n\n render(this: FloatingMenuInterface, createElement: CreateElement) {\n return createElement('div', { style: { visibility: 'hidden' } }, this.$slots.default)\n },\n\n beforeDestroy(this: FloatingMenuInterface) {\n this.editor.unregisterPlugin(this.pluginKey)\n },\n}\n","import Vue, { Component, CreateElement } from 'vue'\n\nexport interface NodeViewContentInterface extends Vue {\n as: string\n}\n\nexport const NodeViewContent: Component = {\n props: {\n as: {\n type: String,\n default: 'div',\n },\n },\n\n render(this: NodeViewContentInterface, createElement: CreateElement) {\n return createElement(this.as, {\n style: {\n whiteSpace: 'pre-wrap',\n },\n attrs: {\n 'data-node-view-content': '',\n },\n })\n },\n}\n","import Vue, { Component, CreateElement } from 'vue'\n\nexport interface NodeViewWrapperInterface extends Vue {\n as: string\n decorationClasses: {\n value: string\n }\n onDragStart: () => void\n}\n\nexport const NodeViewWrapper: Component = {\n props: {\n as: {\n type: String,\n default: 'div',\n },\n },\n\n inject: ['onDragStart', 'decorationClasses'],\n\n render(this: NodeViewWrapperInterface, createElement: CreateElement) {\n return createElement(\n this.as,\n {\n class: this.decorationClasses.value,\n style: {\n whiteSpace: 'normal',\n },\n attrs: {\n 'data-node-view-wrapper': '',\n },\n on: {\n dragstart: this.onDragStart,\n },\n },\n this.$slots.default,\n )\n },\n}\n","import { DecorationWithType, NodeView, NodeViewProps, NodeViewRenderer, NodeViewRendererOptions } from '@tiptap/core'\nimport { Node as ProseMirrorNode } from '@tiptap/pm/model'\nimport { Decoration, DecorationSource, NodeView as ProseMirrorNodeView } from '@tiptap/pm/view'\nimport Vue from 'vue'\nimport { VueConstructor } from 'vue/types/umd'\nimport { booleanProp, functionProp, objectProp } from 'vue-ts-types'\n\nimport { Editor } from './Editor.js'\nimport { VueRenderer } from './VueRenderer.js'\n\nexport const nodeViewProps = {\n editor: objectProp<NodeViewProps['editor']>().required,\n node: objectProp<NodeViewProps['node']>().required,\n decorations: objectProp<NodeViewProps['decorations']>().required,\n selected: booleanProp().required,\n extension: objectProp<NodeViewProps['extension']>().required,\n getPos: functionProp<NodeViewProps['getPos']>().required,\n updateAttributes: functionProp<NodeViewProps['updateAttributes']>().required,\n deleteNode: functionProp<NodeViewProps['deleteNode']>().required,\n}\n\nexport interface VueNodeViewRendererOptions extends NodeViewRendererOptions {\n update:\n | ((props: {\n oldNode: ProseMirrorNode\n oldDecorations: readonly Decoration[]\n oldInnerDecorations: DecorationSource\n newNode: ProseMirrorNode\n newDecorations: readonly Decoration[]\n innerDecorations: DecorationSource\n updateProps: () => void\n }) => boolean)\n | null\n}\n\nclass VueNodeView extends NodeView<Vue | VueConstructor, Editor, VueNodeViewRendererOptions> {\n renderer!: VueRenderer\n\n decorationClasses!: {\n value: string\n }\n\n mount() {\n const props = {\n editor: this.editor,\n node: this.node,\n decorations: this.decorations as DecorationWithType[],\n innerDecorations: this.innerDecorations,\n view: this.view,\n selected: false,\n extension: this.extension,\n HTMLAttributes: this.HTMLAttributes,\n getPos: () => this.getPos(),\n updateAttributes: (attributes = {}) => this.updateAttributes(attributes),\n deleteNode: () => this.deleteNode(),\n } satisfies NodeViewProps\n\n const onDragStart = this.onDragStart.bind(this)\n\n this.decorationClasses = Vue.observable({\n value: this.getDecorationClasses(),\n })\n\n // @ts-ignore\n const vue = this.editor.contentComponent?.$options._base ?? Vue // eslint-disable-line\n\n const Component = vue.extend(this.component).extend({\n props: Object.keys(props),\n provide: () => {\n return {\n onDragStart,\n decorationClasses: this.decorationClasses,\n }\n },\n })\n\n this.handleSelectionUpdate = this.handleSelectionUpdate.bind(this)\n this.editor.on('selectionUpdate', this.handleSelectionUpdate)\n\n this.renderer = new VueRenderer(Component, {\n parent: this.editor.contentComponent,\n propsData: props,\n })\n }\n\n /**\n * Return the DOM element.\n * This is the element that will be used to display the node view.\n */\n get dom() {\n if (!this.renderer.element.hasAttribute('data-node-view-wrapper')) {\n throw Error('Please use the NodeViewWrapper component for your node view.')\n }\n\n return this.renderer.element as HTMLElement\n }\n\n /**\n * Return the content DOM element.\n * This is the element that will be used to display the rich-text content of the node.\n */\n get contentDOM() {\n if (this.node.isLeaf) {\n return null\n }\n\n const contentElement = this.dom.querySelector('[data-node-view-content]')\n\n return (contentElement || this.dom) as HTMLElement | null\n }\n\n /**\n * On editor selection update, check if the node is selected.\n * If it is, call `selectNode`, otherwise call `deselectNode`.\n */\n handleSelectionUpdate() {\n const { from, to } = this.editor.state.selection\n const pos = this.getPos()\n\n if (typeof pos !== 'number') {\n return\n }\n\n if (from <= pos && to >= pos + this.node.nodeSize) {\n if (this.renderer.ref.$props.selected) {\n return\n }\n\n this.selectNode()\n } else {\n if (!this.renderer.ref.$props.selected) {\n return\n }\n\n this.deselectNode()\n }\n }\n\n /**\n * On update, update the React component.\n * To prevent unnecessary updates, the `update` option can be used.\n */\n update(node: ProseMirrorNode, decorations: readonly Decoration[], innerDecorations: DecorationSource): boolean {\n const rerenderComponent = (props?: Record<string, any>) => {\n this.decorationClasses.value = this.getDecorationClasses()\n this.renderer.updateProps(props)\n }\n\n if (typeof this.options.update === 'function') {\n const oldNode = this.node\n const oldDecorations = this.decorations\n const oldInnerDecorations = this.innerDecorations\n\n this.node = node\n this.decorations = decorations\n this.innerDecorations = innerDecorations\n\n return this.options.update({\n oldNode,\n oldDecorations,\n newNode: node,\n newDecorations: decorations,\n oldInnerDecorations,\n innerDecorations,\n updateProps: () => rerenderComponent({ node, decorations, innerDecorations }),\n })\n }\n\n if (node.type !== this.node.type) {\n return false\n }\n\n if (node === this.node && this.decorations === decorations && this.innerDecorations === innerDecorations) {\n return true\n }\n\n this.node = node\n this.decorations = decorations\n this.innerDecorations = innerDecorations\n\n rerenderComponent({ node, decorations, innerDecorations })\n\n return true\n }\n\n /**\n * Select the node.\n * Add the `selected` prop and the `ProseMirror-selectednode` class.\n */\n selectNode() {\n this.renderer.updateProps({\n selected: true,\n })\n this.renderer.element.classList.add('ProseMirror-selectednode')\n }\n\n /**\n * Deselect the node.\n * Remove the `selected` prop and the `ProseMirror-selectednode` class.\n */\n deselectNode() {\n this.renderer.updateProps({\n selected: false,\n })\n this.renderer.element.classList.remove('ProseMirror-selectednode')\n }\n\n getDecorationClasses() {\n return (\n this.decorations\n // @ts-ignore\n .map(item => item.type.attrs.class)\n .flat()\n .join(' ')\n )\n }\n\n destroy() {\n this.renderer.destroy()\n this.editor.off('selectionUpdate', this.handleSelectionUpdate)\n }\n}\n\nexport function VueNodeViewRenderer(\n component: Vue | VueConstructor,\n options?: Partial<VueNodeViewRendererOptions>,\n): NodeViewRenderer {\n return props => {\n // try to get the parent component\n // this is important for vue devtools to show the component hierarchy correctly\n // maybe it’s `undefined` because <editor-content> isn’t rendered yet\n if (!(props.editor as Editor).contentComponent) {\n return {} as unknown as ProseMirrorNodeView\n }\n\n return new VueNodeView(component, props, options)\n }\n}\n","import Vue from 'vue'\nimport { VueConstructor } from 'vue/types/umd'\n\n/**\n * The VueRenderer class is responsible for rendering a Vue component as a ProseMirror node view.\n */\nexport class VueRenderer {\n ref!: Vue\n\n constructor(component: Vue | VueConstructor, props: any) {\n const Component = typeof component === 'function' ? component : Vue.extend(component)\n\n this.ref = new Component(props).$mount()\n }\n\n get element(): Element {\n return this.ref.$el\n }\n\n updateProps(props: Record<string, any> = {}): void {\n if (!this.ref.$props) {\n return\n }\n\n // prevents `Avoid mutating a prop directly` error message\n // Fix: `VueNodeViewRenderer` change vue Constructor `config.silent` not working\n const currentVueConstructor = this.ref.$props.editor?.contentComponent?.$options._base ?? Vue // eslint-disable-line\n const originalSilent = currentVueConstructor.config.silent\n\n currentVueConstructor.config.silent = true\n\n Object.entries(props).forEach(([key, value]) => {\n this.ref.$props[key] = value\n })\n\n currentVueConstructor.config.silent = originalSilent\n }\n\n destroy(): void {\n this.ref.$destroy()\n }\n}\n","export * from './BubbleMenu.js'\nexport { Editor } from './Editor.js'\nexport * from './EditorContent.js'\nexport * from './FloatingMenu.js'\nexport * from './NodeViewContent.js'\nexport * from './NodeViewWrapper.js'\nexport * from './VueNodeViewRenderer.js'\nexport * from './VueRenderer.js'\nexport * from '@tiptap/core'\n"],"mappings":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AA,IACV;AAEA,WAAO,IAAI,YAAY,WAAW,OAAO,OAAO;AAAA,EAClD;AACF;;;AErOA,cAAc;","names":["Vue","Vue"]}
|
|
1
|
+
{"version":3,"sources":["../src/Editor.ts","../src/EditorContent.ts","../src/NodeViewContent.ts","../src/NodeViewWrapper.ts","../src/VueNodeViewRenderer.ts","../src/VueRenderer.ts","../src/index.ts"],"sourcesContent":["import { Editor as CoreEditor } from '@tiptap/core'\nimport Vue from 'vue'\n\nexport class Editor extends CoreEditor {\n public contentComponent: Vue | null = null\n}\n","import Vue, { Component, CreateElement, PropType } from 'vue'\n\nimport { Editor } from './Editor.js'\n\nexport interface EditorContentInterface extends Vue {\n editor: Editor\n}\n\nexport const EditorContent: Component = {\n name: 'EditorContent',\n\n props: {\n editor: {\n default: null,\n type: Object as PropType<Editor>,\n },\n },\n\n watch: {\n editor: {\n immediate: true,\n handler(this: EditorContentInterface, editor: Editor) {\n if (editor && editor.options.element) {\n this.$nextTick(() => {\n const element = this.$el\n\n if (!element || !editor.options.element?.firstChild) {\n return\n }\n\n element.append(...editor.options.element.childNodes)\n editor.contentComponent = this\n\n editor.setOptions({\n element,\n })\n\n editor.createNodeViews()\n })\n }\n },\n },\n },\n\n render(createElement: CreateElement) {\n return createElement('div')\n },\n\n beforeDestroy(this: EditorContentInterface) {\n const { editor } = this\n\n if (!editor) {\n return\n }\n\n if (!editor.isDestroyed) {\n editor.view.setProps({\n nodeViews: {},\n })\n }\n\n editor.contentComponent = null\n\n if (!editor.options.element?.firstChild) {\n return\n }\n\n // TODO using the new editor.mount method might allow us to remove this\n const newElement = document.createElement('div')\n\n newElement.append(...editor.options.element.childNodes)\n\n editor.setOptions({\n element: newElement,\n })\n },\n}\n","import Vue, { Component, CreateElement } from 'vue'\n\nexport interface NodeViewContentInterface extends Vue {\n as: string\n}\n\nexport const NodeViewContent: Component = {\n props: {\n as: {\n type: String,\n default: 'div',\n },\n },\n\n render(this: NodeViewContentInterface, createElement: CreateElement) {\n return createElement(this.as, {\n style: {\n whiteSpace: 'pre-wrap',\n },\n attrs: {\n 'data-node-view-content': '',\n },\n })\n },\n}\n","import Vue, { Component, CreateElement } from 'vue'\n\nexport interface NodeViewWrapperInterface extends Vue {\n as: string\n decorationClasses: {\n value: string\n }\n onDragStart: () => void\n}\n\nexport const NodeViewWrapper: Component = {\n props: {\n as: {\n type: String,\n default: 'div',\n },\n },\n\n inject: ['onDragStart', 'decorationClasses'],\n\n render(this: NodeViewWrapperInterface, createElement: CreateElement) {\n return createElement(\n this.as,\n {\n class: this.decorationClasses.value,\n style: {\n whiteSpace: 'normal',\n },\n attrs: {\n 'data-node-view-wrapper': '',\n },\n on: {\n dragstart: this.onDragStart,\n },\n },\n this.$slots.default,\n )\n },\n}\n","import { DecorationWithType, NodeView, NodeViewProps, NodeViewRenderer, NodeViewRendererOptions } from '@tiptap/core'\nimport { Node as ProseMirrorNode } from '@tiptap/pm/model'\nimport { Decoration, DecorationSource, NodeView as ProseMirrorNodeView } from '@tiptap/pm/view'\nimport Vue from 'vue'\nimport { VueConstructor } from 'vue/types/umd'\nimport { booleanProp, functionProp, objectProp } from 'vue-ts-types'\n\nimport { Editor } from './Editor.js'\nimport { VueRenderer } from './VueRenderer.js'\n\nexport const nodeViewProps = {\n editor: objectProp<NodeViewProps['editor']>().required,\n node: objectProp<NodeViewProps['node']>().required,\n decorations: objectProp<NodeViewProps['decorations']>().required,\n selected: booleanProp().required,\n extension: objectProp<NodeViewProps['extension']>().required,\n getPos: functionProp<NodeViewProps['getPos']>().required,\n updateAttributes: functionProp<NodeViewProps['updateAttributes']>().required,\n deleteNode: functionProp<NodeViewProps['deleteNode']>().required,\n}\n\nexport interface VueNodeViewRendererOptions extends NodeViewRendererOptions {\n update:\n | ((props: {\n oldNode: ProseMirrorNode\n oldDecorations: readonly Decoration[]\n oldInnerDecorations: DecorationSource\n newNode: ProseMirrorNode\n newDecorations: readonly Decoration[]\n innerDecorations: DecorationSource\n updateProps: () => void\n }) => boolean)\n | null\n}\n\nclass VueNodeView extends NodeView<Vue | VueConstructor, Editor, VueNodeViewRendererOptions> {\n renderer!: VueRenderer\n\n decorationClasses!: {\n value: string\n }\n\n mount() {\n const props = {\n editor: this.editor,\n node: this.node,\n decorations: this.decorations as DecorationWithType[],\n innerDecorations: this.innerDecorations,\n view: this.view,\n selected: false,\n extension: this.extension,\n HTMLAttributes: this.HTMLAttributes,\n getPos: () => this.getPos(),\n updateAttributes: (attributes = {}) => this.updateAttributes(attributes),\n deleteNode: () => this.deleteNode(),\n } satisfies NodeViewProps\n\n const onDragStart = this.onDragStart.bind(this)\n\n this.decorationClasses = Vue.observable({\n value: this.getDecorationClasses(),\n })\n\n // @ts-ignore\n const vue = this.editor.contentComponent?.$options._base ?? Vue // eslint-disable-line\n\n const Component = vue.extend(this.component).extend({\n props: Object.keys(props),\n provide: () => {\n return {\n onDragStart,\n decorationClasses: this.decorationClasses,\n }\n },\n })\n\n this.handleSelectionUpdate = this.handleSelectionUpdate.bind(this)\n this.editor.on('selectionUpdate', this.handleSelectionUpdate)\n\n this.renderer = new VueRenderer(Component, {\n parent: this.editor.contentComponent,\n propsData: props,\n })\n }\n\n /**\n * Return the DOM element.\n * This is the element that will be used to display the node view.\n */\n get dom() {\n if (!this.renderer.element.hasAttribute('data-node-view-wrapper')) {\n throw Error('Please use the NodeViewWrapper component for your node view.')\n }\n\n return this.renderer.element as HTMLElement\n }\n\n /**\n * Return the content DOM element.\n * This is the element that will be used to display the rich-text content of the node.\n */\n get contentDOM() {\n if (this.node.isLeaf) {\n return null\n }\n\n const contentElement = this.dom.querySelector('[data-node-view-content]')\n\n return (contentElement || this.dom) as HTMLElement | null\n }\n\n /**\n * On editor selection update, check if the node is selected.\n * If it is, call `selectNode`, otherwise call `deselectNode`.\n */\n handleSelectionUpdate() {\n const { from, to } = this.editor.state.selection\n const pos = this.getPos()\n\n if (typeof pos !== 'number') {\n return\n }\n\n if (from <= pos && to >= pos + this.node.nodeSize) {\n if (this.renderer.ref.$props.selected) {\n return\n }\n\n this.selectNode()\n } else {\n if (!this.renderer.ref.$props.selected) {\n return\n }\n\n this.deselectNode()\n }\n }\n\n /**\n * On update, update the React component.\n * To prevent unnecessary updates, the `update` option can be used.\n */\n update(node: ProseMirrorNode, decorations: readonly Decoration[], innerDecorations: DecorationSource): boolean {\n const rerenderComponent = (props?: Record<string, any>) => {\n this.decorationClasses.value = this.getDecorationClasses()\n this.renderer.updateProps(props)\n }\n\n if (typeof this.options.update === 'function') {\n const oldNode = this.node\n const oldDecorations = this.decorations\n const oldInnerDecorations = this.innerDecorations\n\n this.node = node\n this.decorations = decorations\n this.innerDecorations = innerDecorations\n\n return this.options.update({\n oldNode,\n oldDecorations,\n newNode: node,\n newDecorations: decorations,\n oldInnerDecorations,\n innerDecorations,\n updateProps: () => rerenderComponent({ node, decorations, innerDecorations }),\n })\n }\n\n if (node.type !== this.node.type) {\n return false\n }\n\n if (node === this.node && this.decorations === decorations && this.innerDecorations === innerDecorations) {\n return true\n }\n\n this.node = node\n this.decorations = decorations\n this.innerDecorations = innerDecorations\n\n rerenderComponent({ node, decorations, innerDecorations })\n\n return true\n }\n\n /**\n * Select the node.\n * Add the `selected` prop and the `ProseMirror-selectednode` class.\n */\n selectNode() {\n this.renderer.updateProps({\n selected: true,\n })\n this.renderer.element.classList.add('ProseMirror-selectednode')\n }\n\n /**\n * Deselect the node.\n * Remove the `selected` prop and the `ProseMirror-selectednode` class.\n */\n deselectNode() {\n this.renderer.updateProps({\n selected: false,\n })\n this.renderer.element.classList.remove('ProseMirror-selectednode')\n }\n\n getDecorationClasses() {\n return (\n this.decorations\n // @ts-ignore\n .map(item => item.type.attrs.class)\n .flat()\n .join(' ')\n )\n }\n\n destroy() {\n this.renderer.destroy()\n this.editor.off('selectionUpdate', this.handleSelectionUpdate)\n }\n}\n\nexport function VueNodeViewRenderer(\n component: Vue | VueConstructor,\n options?: Partial<VueNodeViewRendererOptions>,\n): NodeViewRenderer {\n return props => {\n // try to get the parent component\n // this is important for vue devtools to show the component hierarchy correctly\n // maybe it’s `undefined` because <editor-content> isn’t rendered yet\n if (!(props.editor as Editor).contentComponent) {\n return {} as unknown as ProseMirrorNodeView\n }\n\n return new VueNodeView(component, props, options)\n }\n}\n","import Vue from 'vue'\nimport { VueConstructor } from 'vue/types/umd'\n\n/**\n * The VueRenderer class is responsible for rendering a Vue component as a ProseMirror node view.\n */\nexport class VueRenderer {\n ref!: Vue\n\n constructor(component: Vue | VueConstructor, props: any) {\n const Component = typeof component === 'function' ? component : Vue.extend(component)\n\n this.ref = new Component(props).$mount()\n }\n\n get element(): Element {\n return this.ref.$el\n }\n\n updateProps(props: Record<string, any> = {}): void {\n if (!this.ref.$props) {\n return\n }\n\n // prevents `Avoid mutating a prop directly` error message\n // Fix: `VueNodeViewRenderer` change vue Constructor `config.silent` not working\n const currentVueConstructor = this.ref.$props.editor?.contentComponent?.$options._base ?? Vue // eslint-disable-line\n const originalSilent = currentVueConstructor.config.silent\n\n currentVueConstructor.config.silent = true\n\n Object.entries(props).forEach(([key, value]) => {\n this.ref.$props[key] = value\n })\n\n currentVueConstructor.config.silent = originalSilent\n }\n\n destroy(): void {\n this.ref.$destroy()\n }\n}\n","export { Editor } from './Editor.js'\nexport * from './EditorContent.js'\nexport * from './NodeViewContent.js'\nexport * from './NodeViewWrapper.js'\nexport * from './VueNodeViewRenderer.js'\nexport * from './VueRenderer.js'\nexport * from '@tiptap/core'\n"],"mappings":";AAAA,SAAS,UAAU,kBAAkB;AAG9B,IAAM,SAAN,cAAqB,WAAW;AAAA,EAAhC;AAAA;AACL,SAAO,mBAA+B;AAAA;AACxC;;;ACGO,IAAM,gBAA2B;AAAA,EACtC,MAAM;AAAA,EAEN,OAAO;AAAA,IACL,QAAQ;AAAA,MACN,SAAS;AAAA,MACT,MAAM;AAAA,IACR;AAAA,EACF;AAAA,EAEA,OAAO;AAAA,IACL,QAAQ;AAAA,MACN,WAAW;AAAA,MACX,QAAsC,QAAgB;AACpD,YAAI,UAAU,OAAO,QAAQ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