@tiptap/vue-2 3.0.0 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +21 -0
- package/README.md +5 -1
- package/dist/index.cjs +340 -349
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +79 -0
- package/dist/index.d.ts +79 -0
- package/dist/index.js +298 -337
- package/dist/index.js.map +1 -1
- package/dist/menus/index.cjs +2273 -0
- package/dist/menus/index.cjs.map +1 -0
- package/dist/menus/index.d.cts +139 -0
- package/dist/menus/index.d.ts +139 -0
- package/dist/menus/index.js +2245 -0
- package/dist/menus/index.js.map +1 -0
- package/package.json +28 -16
- package/src/Editor.ts +1 -1
- package/src/EditorContent.ts +7 -5
- package/src/NodeViewContent.ts +3 -2
- package/src/NodeViewWrapper.ts +6 -5
- package/src/VueNodeViewRenderer.ts +80 -27
- package/src/VueRenderer.ts +5 -7
- package/src/index.ts +0 -2
- package/src/menus/BubbleMenu.ts +85 -0
- package/src/{FloatingMenu.ts → menus/FloatingMenu.ts} +24 -15
- package/src/menus/index.ts +2 -0
- package/dist/index.umd.js +0 -379
- package/dist/index.umd.js.map +0 -1
- package/dist/packages/core/src/CommandManager.d.ts +0 -20
- package/dist/packages/core/src/Editor.d.ts +0 -161
- package/dist/packages/core/src/EventEmitter.d.ts +0 -11
- package/dist/packages/core/src/Extension.d.ts +0 -343
- package/dist/packages/core/src/ExtensionManager.d.ts +0 -55
- package/dist/packages/core/src/InputRule.d.ts +0 -42
- package/dist/packages/core/src/Mark.d.ts +0 -451
- package/dist/packages/core/src/Node.d.ts +0 -611
- package/dist/packages/core/src/NodePos.d.ts +0 -44
- package/dist/packages/core/src/NodeView.d.ts +0 -31
- package/dist/packages/core/src/PasteRule.d.ts +0 -50
- package/dist/packages/core/src/Tracker.d.ts +0 -11
- package/dist/packages/core/src/commands/blur.d.ts +0 -13
- package/dist/packages/core/src/commands/clearContent.d.ts +0 -14
- package/dist/packages/core/src/commands/clearNodes.d.ts +0 -13
- package/dist/packages/core/src/commands/command.d.ts +0 -18
- package/dist/packages/core/src/commands/createParagraphNear.d.ts +0 -13
- package/dist/packages/core/src/commands/cut.d.ts +0 -20
- package/dist/packages/core/src/commands/deleteCurrentNode.d.ts +0 -13
- package/dist/packages/core/src/commands/deleteNode.d.ts +0 -15
- package/dist/packages/core/src/commands/deleteRange.d.ts +0 -14
- package/dist/packages/core/src/commands/deleteSelection.d.ts +0 -13
- package/dist/packages/core/src/commands/enter.d.ts +0 -13
- package/dist/packages/core/src/commands/exitCode.d.ts +0 -13
- package/dist/packages/core/src/commands/extendMarkRange.d.ts +0 -25
- package/dist/packages/core/src/commands/first.d.ts +0 -14
- package/dist/packages/core/src/commands/focus.d.ts +0 -27
- package/dist/packages/core/src/commands/forEach.d.ts +0 -14
- package/dist/packages/core/src/commands/index.d.ts +0 -55
- package/dist/packages/core/src/commands/insertContent.d.ts +0 -34
- package/dist/packages/core/src/commands/insertContentAt.d.ts +0 -47
- package/dist/packages/core/src/commands/join.d.ts +0 -41
- package/dist/packages/core/src/commands/joinItemBackward.d.ts +0 -13
- package/dist/packages/core/src/commands/joinItemForward.d.ts +0 -13
- package/dist/packages/core/src/commands/joinTextblockBackward.d.ts +0 -12
- package/dist/packages/core/src/commands/joinTextblockForward.d.ts +0 -12
- package/dist/packages/core/src/commands/keyboardShortcut.d.ts +0 -14
- package/dist/packages/core/src/commands/lift.d.ts +0 -17
- package/dist/packages/core/src/commands/liftEmptyBlock.d.ts +0 -13
- package/dist/packages/core/src/commands/liftListItem.d.ts +0 -15
- package/dist/packages/core/src/commands/newlineInCode.d.ts +0 -13
- package/dist/packages/core/src/commands/resetAttributes.d.ts +0 -16
- package/dist/packages/core/src/commands/scrollIntoView.d.ts +0 -13
- package/dist/packages/core/src/commands/selectAll.d.ts +0 -13
- package/dist/packages/core/src/commands/selectNodeBackward.d.ts +0 -13
- package/dist/packages/core/src/commands/selectNodeForward.d.ts +0 -13
- package/dist/packages/core/src/commands/selectParentNode.d.ts +0 -13
- package/dist/packages/core/src/commands/selectTextblockEnd.d.ts +0 -13
- package/dist/packages/core/src/commands/selectTextblockStart.d.ts +0 -13
- package/dist/packages/core/src/commands/setContent.d.ts +0 -40
- package/dist/packages/core/src/commands/setMark.d.ts +0 -15
- package/dist/packages/core/src/commands/setMeta.d.ts +0 -15
- package/dist/packages/core/src/commands/setNode.d.ts +0 -16
- package/dist/packages/core/src/commands/setNodeSelection.d.ts +0 -14
- package/dist/packages/core/src/commands/setTextSelection.d.ts +0 -14
- package/dist/packages/core/src/commands/sinkListItem.d.ts +0 -15
- package/dist/packages/core/src/commands/splitBlock.d.ts +0 -17
- package/dist/packages/core/src/commands/splitListItem.d.ts +0 -15
- package/dist/packages/core/src/commands/toggleList.d.ts +0 -18
- package/dist/packages/core/src/commands/toggleMark.d.ts +0 -30
- package/dist/packages/core/src/commands/toggleNode.d.ts +0 -17
- package/dist/packages/core/src/commands/toggleWrap.d.ts +0 -16
- package/dist/packages/core/src/commands/undoInputRule.d.ts +0 -13
- package/dist/packages/core/src/commands/unsetAllMarks.d.ts +0 -13
- package/dist/packages/core/src/commands/unsetMark.d.ts +0 -25
- package/dist/packages/core/src/commands/updateAttributes.d.ts +0 -24
- package/dist/packages/core/src/commands/wrapIn.d.ts +0 -16
- package/dist/packages/core/src/commands/wrapInList.d.ts +0 -16
- package/dist/packages/core/src/extensions/clipboardTextSerializer.d.ts +0 -5
- package/dist/packages/core/src/extensions/commands.d.ts +0 -3
- package/dist/packages/core/src/extensions/editable.d.ts +0 -2
- package/dist/packages/core/src/extensions/focusEvents.d.ts +0 -2
- package/dist/packages/core/src/extensions/index.d.ts +0 -6
- package/dist/packages/core/src/extensions/keymap.d.ts +0 -2
- package/dist/packages/core/src/extensions/tabindex.d.ts +0 -2
- package/dist/packages/core/src/helpers/combineTransactionSteps.d.ts +0 -10
- package/dist/packages/core/src/helpers/createChainableState.d.ts +0 -10
- package/dist/packages/core/src/helpers/createDocument.d.ts +0 -12
- package/dist/packages/core/src/helpers/createNodeFromContent.d.ts +0 -15
- package/dist/packages/core/src/helpers/defaultBlockAt.d.ts +0 -7
- package/dist/packages/core/src/helpers/findChildren.d.ts +0 -9
- package/dist/packages/core/src/helpers/findChildrenInRange.d.ts +0 -10
- package/dist/packages/core/src/helpers/findParentNode.d.ts +0 -16
- package/dist/packages/core/src/helpers/findParentNodeClosestToPos.d.ts +0 -17
- package/dist/packages/core/src/helpers/generateHTML.d.ts +0 -8
- package/dist/packages/core/src/helpers/generateJSON.d.ts +0 -8
- package/dist/packages/core/src/helpers/generateText.d.ts +0 -12
- package/dist/packages/core/src/helpers/getAttributes.d.ts +0 -9
- package/dist/packages/core/src/helpers/getAttributesFromExtensions.d.ts +0 -6
- package/dist/packages/core/src/helpers/getChangedRanges.d.ts +0 -11
- package/dist/packages/core/src/helpers/getDebugJSON.d.ts +0 -8
- package/dist/packages/core/src/helpers/getExtensionField.d.ts +0 -9
- package/dist/packages/core/src/helpers/getHTMLFromFragment.d.ts +0 -2
- package/dist/packages/core/src/helpers/getMarkAttributes.d.ts +0 -3
- package/dist/packages/core/src/helpers/getMarkRange.d.ts +0 -3
- package/dist/packages/core/src/helpers/getMarkType.d.ts +0 -2
- package/dist/packages/core/src/helpers/getMarksBetween.d.ts +0 -3
- package/dist/packages/core/src/helpers/getNodeAtPosition.d.ts +0 -11
- package/dist/packages/core/src/helpers/getNodeAttributes.d.ts +0 -3
- package/dist/packages/core/src/helpers/getNodeType.d.ts +0 -2
- package/dist/packages/core/src/helpers/getRenderedAttributes.d.ts +0 -3
- package/dist/packages/core/src/helpers/getSchema.d.ts +0 -4
- package/dist/packages/core/src/helpers/getSchemaByResolvedExtensions.d.ts +0 -10
- package/dist/packages/core/src/helpers/getSchemaTypeByName.d.ts +0 -8
- package/dist/packages/core/src/helpers/getSchemaTypeNameByName.d.ts +0 -8
- package/dist/packages/core/src/helpers/getSplittedAttributes.d.ts +0 -9
- package/dist/packages/core/src/helpers/getText.d.ts +0 -15
- package/dist/packages/core/src/helpers/getTextBetween.d.ts +0 -14
- package/dist/packages/core/src/helpers/getTextContentFromNodes.d.ts +0 -8
- package/dist/packages/core/src/helpers/getTextSerializersFromSchema.d.ts +0 -8
- package/dist/packages/core/src/helpers/index.d.ts +0 -50
- package/dist/packages/core/src/helpers/injectExtensionAttributesToParseRule.d.ts +0 -9
- package/dist/packages/core/src/helpers/isActive.d.ts +0 -2
- package/dist/packages/core/src/helpers/isAtEndOfNode.d.ts +0 -2
- package/dist/packages/core/src/helpers/isAtStartOfNode.d.ts +0 -2
- package/dist/packages/core/src/helpers/isExtensionRulesEnabled.d.ts +0 -2
- package/dist/packages/core/src/helpers/isList.d.ts +0 -2
- package/dist/packages/core/src/helpers/isMarkActive.d.ts +0 -3
- package/dist/packages/core/src/helpers/isNodeActive.d.ts +0 -3
- package/dist/packages/core/src/helpers/isNodeEmpty.d.ts +0 -2
- package/dist/packages/core/src/helpers/isNodeSelection.d.ts +0 -2
- package/dist/packages/core/src/helpers/isTextSelection.d.ts +0 -2
- package/dist/packages/core/src/helpers/posToDOMRect.d.ts +0 -2
- package/dist/packages/core/src/helpers/resolveFocusPosition.d.ts +0 -4
- package/dist/packages/core/src/helpers/selectionToInsertionEnd.d.ts +0 -2
- package/dist/packages/core/src/helpers/splitExtensions.d.ts +0 -9
- package/dist/packages/core/src/index.d.ts +0 -24
- package/dist/packages/core/src/inputRules/index.d.ts +0 -5
- package/dist/packages/core/src/inputRules/markInputRule.d.ts +0 -13
- package/dist/packages/core/src/inputRules/nodeInputRule.d.ts +0 -23
- package/dist/packages/core/src/inputRules/textInputRule.d.ts +0 -10
- package/dist/packages/core/src/inputRules/textblockTypeInputRule.d.ts +0 -15
- package/dist/packages/core/src/inputRules/wrappingInputRule.d.ts +0 -28
- package/dist/packages/core/src/pasteRules/index.d.ts +0 -3
- package/dist/packages/core/src/pasteRules/markPasteRule.d.ts +0 -13
- package/dist/packages/core/src/pasteRules/nodePasteRule.d.ts +0 -13
- package/dist/packages/core/src/pasteRules/textPasteRule.d.ts +0 -10
- package/dist/packages/core/src/style.d.ts +0 -1
- package/dist/packages/core/src/types.d.ts +0 -255
- package/dist/packages/core/src/utilities/callOrReturn.d.ts +0 -9
- package/dist/packages/core/src/utilities/createStyleTag.d.ts +0 -1
- package/dist/packages/core/src/utilities/deleteProps.d.ts +0 -6
- package/dist/packages/core/src/utilities/elementFromString.d.ts +0 -1
- package/dist/packages/core/src/utilities/escapeForRegEx.d.ts +0 -1
- package/dist/packages/core/src/utilities/findDuplicates.d.ts +0 -1
- package/dist/packages/core/src/utilities/fromString.d.ts +0 -1
- package/dist/packages/core/src/utilities/index.d.ts +0 -20
- package/dist/packages/core/src/utilities/isAndroid.d.ts +0 -1
- package/dist/packages/core/src/utilities/isEmptyObject.d.ts +0 -1
- package/dist/packages/core/src/utilities/isFunction.d.ts +0 -1
- package/dist/packages/core/src/utilities/isMacOS.d.ts +0 -1
- package/dist/packages/core/src/utilities/isNumber.d.ts +0 -1
- package/dist/packages/core/src/utilities/isPlainObject.d.ts +0 -1
- package/dist/packages/core/src/utilities/isRegExp.d.ts +0 -1
- package/dist/packages/core/src/utilities/isString.d.ts +0 -1
- package/dist/packages/core/src/utilities/isiOS.d.ts +0 -1
- package/dist/packages/core/src/utilities/mergeAttributes.d.ts +0 -1
- package/dist/packages/core/src/utilities/mergeDeep.d.ts +0 -1
- package/dist/packages/core/src/utilities/minMax.d.ts +0 -1
- package/dist/packages/core/src/utilities/objectIncludes.d.ts +0 -8
- package/dist/packages/core/src/utilities/removeDuplicates.d.ts +0 -8
- package/dist/packages/extension-bubble-menu/src/bubble-menu-plugin.d.ts +0 -76
- package/dist/packages/extension-bubble-menu/src/bubble-menu.d.ts +0 -15
- package/dist/packages/extension-bubble-menu/src/index.d.ts +0 -4
- package/dist/packages/extension-floating-menu/src/floating-menu-plugin.d.ts +0 -66
- package/dist/packages/extension-floating-menu/src/floating-menu.d.ts +0 -15
- package/dist/packages/extension-floating-menu/src/index.d.ts +0 -4
- package/dist/packages/vue-2/src/BubbleMenu.d.ts +0 -10
- package/dist/packages/vue-2/src/Editor.d.ts +0 -5
- package/dist/packages/vue-2/src/EditorContent.d.ts +0 -6
- package/dist/packages/vue-2/src/FloatingMenu.d.ts +0 -9
- package/dist/packages/vue-2/src/NodeViewContent.d.ts +0 -5
- package/dist/packages/vue-2/src/NodeViewWrapper.d.ts +0 -9
- package/dist/packages/vue-2/src/VueNodeViewRenderer.d.ts +0 -37
- package/dist/packages/vue-2/src/VueRenderer.d.ts +0 -12
- package/dist/packages/vue-2/src/index.d.ts +0 -9
- package/src/BubbleMenu.ts +0 -70
|
@@ -1,18 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
NodeViewRenderer,
|
|
6
|
-
NodeViewRendererOptions,
|
|
7
|
-
NodeViewRendererProps,
|
|
8
|
-
} from '@tiptap/core'
|
|
9
|
-
import { Node as ProseMirrorNode } from '@tiptap/pm/model'
|
|
10
|
-
import { Decoration, NodeView as ProseMirrorNodeView } from '@tiptap/pm/view'
|
|
1
|
+
import type { DecorationWithType, NodeViewProps, NodeViewRenderer, NodeViewRendererOptions } from '@tiptap/core'
|
|
2
|
+
import { NodeView } from '@tiptap/core'
|
|
3
|
+
import type { Node as ProseMirrorNode } from '@tiptap/pm/model'
|
|
4
|
+
import type { Decoration, DecorationSource, NodeView as ProseMirrorNodeView } from '@tiptap/pm/view'
|
|
11
5
|
import Vue from 'vue'
|
|
12
|
-
import { VueConstructor } from 'vue/types/umd'
|
|
6
|
+
import type { VueConstructor } from 'vue/types/umd'
|
|
13
7
|
import { booleanProp, functionProp, objectProp } from 'vue-ts-types'
|
|
14
8
|
|
|
15
|
-
import { Editor } from './Editor.js'
|
|
9
|
+
import type { Editor } from './Editor.js'
|
|
16
10
|
import { VueRenderer } from './VueRenderer.js'
|
|
17
11
|
|
|
18
12
|
export const nodeViewProps = {
|
|
@@ -30,9 +24,11 @@ export interface VueNodeViewRendererOptions extends NodeViewRendererOptions {
|
|
|
30
24
|
update:
|
|
31
25
|
| ((props: {
|
|
32
26
|
oldNode: ProseMirrorNode
|
|
33
|
-
oldDecorations: Decoration[]
|
|
27
|
+
oldDecorations: readonly Decoration[]
|
|
28
|
+
oldInnerDecorations: DecorationSource
|
|
34
29
|
newNode: ProseMirrorNode
|
|
35
|
-
newDecorations: Decoration[]
|
|
30
|
+
newDecorations: readonly Decoration[]
|
|
31
|
+
innerDecorations: DecorationSource
|
|
36
32
|
updateProps: () => void
|
|
37
33
|
}) => boolean)
|
|
38
34
|
| null
|
|
@@ -46,16 +42,19 @@ class VueNodeView extends NodeView<Vue | VueConstructor, Editor, VueNodeViewRend
|
|
|
46
42
|
}
|
|
47
43
|
|
|
48
44
|
mount() {
|
|
49
|
-
const props
|
|
45
|
+
const props = {
|
|
50
46
|
editor: this.editor,
|
|
51
47
|
node: this.node,
|
|
52
|
-
decorations: this.decorations,
|
|
48
|
+
decorations: this.decorations as DecorationWithType[],
|
|
49
|
+
innerDecorations: this.innerDecorations,
|
|
50
|
+
view: this.view,
|
|
53
51
|
selected: false,
|
|
54
52
|
extension: this.extension,
|
|
53
|
+
HTMLAttributes: this.HTMLAttributes,
|
|
55
54
|
getPos: () => this.getPos(),
|
|
56
55
|
updateAttributes: (attributes = {}) => this.updateAttributes(attributes),
|
|
57
56
|
deleteNode: () => this.deleteNode(),
|
|
58
|
-
}
|
|
57
|
+
} satisfies NodeViewProps
|
|
59
58
|
|
|
60
59
|
const onDragStart = this.onDragStart.bind(this)
|
|
61
60
|
|
|
@@ -76,12 +75,19 @@ class VueNodeView extends NodeView<Vue | VueConstructor, Editor, VueNodeViewRend
|
|
|
76
75
|
},
|
|
77
76
|
})
|
|
78
77
|
|
|
78
|
+
this.handleSelectionUpdate = this.handleSelectionUpdate.bind(this)
|
|
79
|
+
this.editor.on('selectionUpdate', this.handleSelectionUpdate)
|
|
80
|
+
|
|
79
81
|
this.renderer = new VueRenderer(Component, {
|
|
80
82
|
parent: this.editor.contentComponent,
|
|
81
83
|
propsData: props,
|
|
82
84
|
})
|
|
83
85
|
}
|
|
84
86
|
|
|
87
|
+
/**
|
|
88
|
+
* Return the DOM element.
|
|
89
|
+
* This is the element that will be used to display the node view.
|
|
90
|
+
*/
|
|
85
91
|
get dom() {
|
|
86
92
|
if (!this.renderer.element.hasAttribute('data-node-view-wrapper')) {
|
|
87
93
|
throw Error('Please use the NodeViewWrapper component for your node view.')
|
|
@@ -90,18 +96,51 @@ class VueNodeView extends NodeView<Vue | VueConstructor, Editor, VueNodeViewRend
|
|
|
90
96
|
return this.renderer.element as HTMLElement
|
|
91
97
|
}
|
|
92
98
|
|
|
99
|
+
/**
|
|
100
|
+
* Return the content DOM element.
|
|
101
|
+
* This is the element that will be used to display the rich-text content of the node.
|
|
102
|
+
*/
|
|
93
103
|
get contentDOM() {
|
|
94
104
|
if (this.node.isLeaf) {
|
|
95
105
|
return null
|
|
96
106
|
}
|
|
97
107
|
|
|
98
|
-
|
|
108
|
+
return this.dom.querySelector('[data-node-view-content]') as HTMLElement | null
|
|
109
|
+
}
|
|
99
110
|
|
|
100
|
-
|
|
111
|
+
/**
|
|
112
|
+
* On editor selection update, check if the node is selected.
|
|
113
|
+
* If it is, call `selectNode`, otherwise call `deselectNode`.
|
|
114
|
+
*/
|
|
115
|
+
handleSelectionUpdate() {
|
|
116
|
+
const { from, to } = this.editor.state.selection
|
|
117
|
+
const pos = this.getPos()
|
|
118
|
+
|
|
119
|
+
if (typeof pos !== 'number') {
|
|
120
|
+
return
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (from <= pos && to >= pos + this.node.nodeSize) {
|
|
124
|
+
if (this.renderer.ref.$props.selected) {
|
|
125
|
+
return
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
this.selectNode()
|
|
129
|
+
} else {
|
|
130
|
+
if (!this.renderer.ref.$props.selected) {
|
|
131
|
+
return
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
this.deselectNode()
|
|
135
|
+
}
|
|
101
136
|
}
|
|
102
137
|
|
|
103
|
-
|
|
104
|
-
|
|
138
|
+
/**
|
|
139
|
+
* On update, update the React component.
|
|
140
|
+
* To prevent unnecessary updates, the `update` option can be used.
|
|
141
|
+
*/
|
|
142
|
+
update(node: ProseMirrorNode, decorations: readonly Decoration[], innerDecorations: DecorationSource): boolean {
|
|
143
|
+
const rerenderComponent = (props?: Record<string, any>) => {
|
|
105
144
|
this.decorationClasses.value = this.getDecorationClasses()
|
|
106
145
|
this.renderer.updateProps(props)
|
|
107
146
|
}
|
|
@@ -109,16 +148,20 @@ class VueNodeView extends NodeView<Vue | VueConstructor, Editor, VueNodeViewRend
|
|
|
109
148
|
if (typeof this.options.update === 'function') {
|
|
110
149
|
const oldNode = this.node
|
|
111
150
|
const oldDecorations = this.decorations
|
|
151
|
+
const oldInnerDecorations = this.innerDecorations
|
|
112
152
|
|
|
113
153
|
this.node = node
|
|
114
154
|
this.decorations = decorations
|
|
155
|
+
this.innerDecorations = innerDecorations
|
|
115
156
|
|
|
116
157
|
return this.options.update({
|
|
117
158
|
oldNode,
|
|
118
159
|
oldDecorations,
|
|
119
160
|
newNode: node,
|
|
120
161
|
newDecorations: decorations,
|
|
121
|
-
|
|
162
|
+
oldInnerDecorations,
|
|
163
|
+
innerDecorations,
|
|
164
|
+
updateProps: () => rerenderComponent({ node, decorations, innerDecorations }),
|
|
122
165
|
})
|
|
123
166
|
}
|
|
124
167
|
|
|
@@ -126,18 +169,23 @@ class VueNodeView extends NodeView<Vue | VueConstructor, Editor, VueNodeViewRend
|
|
|
126
169
|
return false
|
|
127
170
|
}
|
|
128
171
|
|
|
129
|
-
if (node === this.node && this.decorations === decorations) {
|
|
172
|
+
if (node === this.node && this.decorations === decorations && this.innerDecorations === innerDecorations) {
|
|
130
173
|
return true
|
|
131
174
|
}
|
|
132
175
|
|
|
133
176
|
this.node = node
|
|
134
177
|
this.decorations = decorations
|
|
178
|
+
this.innerDecorations = innerDecorations
|
|
135
179
|
|
|
136
|
-
|
|
180
|
+
rerenderComponent({ node, decorations, innerDecorations })
|
|
137
181
|
|
|
138
182
|
return true
|
|
139
183
|
}
|
|
140
184
|
|
|
185
|
+
/**
|
|
186
|
+
* Select the node.
|
|
187
|
+
* Add the `selected` prop and the `ProseMirror-selectednode` class.
|
|
188
|
+
*/
|
|
141
189
|
selectNode() {
|
|
142
190
|
this.renderer.updateProps({
|
|
143
191
|
selected: true,
|
|
@@ -145,6 +193,10 @@ class VueNodeView extends NodeView<Vue | VueConstructor, Editor, VueNodeViewRend
|
|
|
145
193
|
this.renderer.element.classList.add('ProseMirror-selectednode')
|
|
146
194
|
}
|
|
147
195
|
|
|
196
|
+
/**
|
|
197
|
+
* Deselect the node.
|
|
198
|
+
* Remove the `selected` prop and the `ProseMirror-selectednode` class.
|
|
199
|
+
*/
|
|
148
200
|
deselectNode() {
|
|
149
201
|
this.renderer.updateProps({
|
|
150
202
|
selected: false,
|
|
@@ -164,6 +216,7 @@ class VueNodeView extends NodeView<Vue | VueConstructor, Editor, VueNodeViewRend
|
|
|
164
216
|
|
|
165
217
|
destroy() {
|
|
166
218
|
this.renderer.destroy()
|
|
219
|
+
this.editor.off('selectionUpdate', this.handleSelectionUpdate)
|
|
167
220
|
}
|
|
168
221
|
}
|
|
169
222
|
|
|
@@ -171,14 +224,14 @@ export function VueNodeViewRenderer(
|
|
|
171
224
|
component: Vue | VueConstructor,
|
|
172
225
|
options?: Partial<VueNodeViewRendererOptions>,
|
|
173
226
|
): NodeViewRenderer {
|
|
174
|
-
return
|
|
227
|
+
return props => {
|
|
175
228
|
// try to get the parent component
|
|
176
229
|
// this is important for vue devtools to show the component hierarchy correctly
|
|
177
230
|
// maybe it’s `undefined` because <editor-content> isn’t rendered yet
|
|
178
231
|
if (!(props.editor as Editor).contentComponent) {
|
|
179
|
-
return {}
|
|
232
|
+
return {} as unknown as ProseMirrorNodeView
|
|
180
233
|
}
|
|
181
234
|
|
|
182
|
-
return new VueNodeView(component, props, options)
|
|
235
|
+
return new VueNodeView(component, props, options)
|
|
183
236
|
}
|
|
184
237
|
}
|
package/src/VueRenderer.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import Vue from 'vue'
|
|
2
|
-
import { VueConstructor } from 'vue/types/umd'
|
|
2
|
+
import type { VueConstructor } from 'vue/types/umd'
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* The VueRenderer class is responsible for rendering a Vue component as a ProseMirror node view.
|
|
@@ -8,7 +8,7 @@ export class VueRenderer {
|
|
|
8
8
|
ref!: Vue
|
|
9
9
|
|
|
10
10
|
constructor(component: Vue | VueConstructor, props: any) {
|
|
11
|
-
const Component =
|
|
11
|
+
const Component = typeof component === 'function' ? component : Vue.extend(component)
|
|
12
12
|
|
|
13
13
|
this.ref = new Component(props).$mount()
|
|
14
14
|
}
|
|
@@ -29,11 +29,9 @@ export class VueRenderer {
|
|
|
29
29
|
|
|
30
30
|
currentVueConstructor.config.silent = true
|
|
31
31
|
|
|
32
|
-
Object
|
|
33
|
-
.
|
|
34
|
-
|
|
35
|
-
this.ref.$props[key] = value
|
|
36
|
-
})
|
|
32
|
+
Object.entries(props).forEach(([key, value]) => {
|
|
33
|
+
this.ref.$props[key] = value
|
|
34
|
+
})
|
|
37
35
|
|
|
38
36
|
currentVueConstructor.config.silent = originalSilent
|
|
39
37
|
}
|
package/src/index.ts
CHANGED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import type { BubbleMenuPluginProps } from '@tiptap/extension-bubble-menu'
|
|
2
|
+
import { BubbleMenuPlugin } from '@tiptap/extension-bubble-menu'
|
|
3
|
+
import type { Component, CreateElement, PropType } from 'vue'
|
|
4
|
+
import type Vue from 'vue'
|
|
5
|
+
|
|
6
|
+
export interface BubbleMenuInterface extends Vue {
|
|
7
|
+
pluginKey: BubbleMenuPluginProps['pluginKey']
|
|
8
|
+
editor: BubbleMenuPluginProps['editor']
|
|
9
|
+
updateDelay: BubbleMenuPluginProps['updateDelay']
|
|
10
|
+
resizeDelay: BubbleMenuPluginProps['resizeDelay']
|
|
11
|
+
shouldShow: BubbleMenuPluginProps['shouldShow']
|
|
12
|
+
options: BubbleMenuPluginProps['options']
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const BubbleMenu: Component = {
|
|
16
|
+
name: 'BubbleMenu',
|
|
17
|
+
|
|
18
|
+
props: {
|
|
19
|
+
pluginKey: {
|
|
20
|
+
type: [String, Object as PropType<Exclude<BubbleMenuPluginProps['pluginKey'], string>>],
|
|
21
|
+
default: 'bubbleMenu',
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
editor: {
|
|
25
|
+
type: Object as PropType<BubbleMenuPluginProps['editor']>,
|
|
26
|
+
required: true,
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
updateDelay: {
|
|
30
|
+
type: Number as PropType<BubbleMenuPluginProps['updateDelay']>,
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
options: {
|
|
34
|
+
type: Object as PropType<BubbleMenuPluginProps['options']>,
|
|
35
|
+
default: {},
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
resizeDelay: {
|
|
39
|
+
type: Number as PropType<BubbleMenuPluginProps['resizeDelay']>,
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
shouldShow: {
|
|
43
|
+
type: Function as PropType<Exclude<BubbleMenuPluginProps['shouldShow'], null>>,
|
|
44
|
+
default: null,
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
watch: {
|
|
49
|
+
editor: {
|
|
50
|
+
immediate: true,
|
|
51
|
+
handler(this: BubbleMenuInterface, editor: BubbleMenuPluginProps['editor']) {
|
|
52
|
+
if (!editor) {
|
|
53
|
+
return
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
;(this.$el as HTMLElement).style.visibility = 'hidden'
|
|
57
|
+
;(this.$el as HTMLElement).style.position = 'absolute'
|
|
58
|
+
|
|
59
|
+
this.$el.remove()
|
|
60
|
+
|
|
61
|
+
this.$nextTick(() => {
|
|
62
|
+
editor.registerPlugin(
|
|
63
|
+
BubbleMenuPlugin({
|
|
64
|
+
updateDelay: this.updateDelay,
|
|
65
|
+
resizeDelay: this.resizeDelay,
|
|
66
|
+
options: this.options,
|
|
67
|
+
editor,
|
|
68
|
+
element: this.$el as HTMLElement,
|
|
69
|
+
pluginKey: this.pluginKey,
|
|
70
|
+
shouldShow: this.shouldShow,
|
|
71
|
+
}),
|
|
72
|
+
)
|
|
73
|
+
})
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
render(this: BubbleMenuInterface, createElement: CreateElement) {
|
|
79
|
+
return createElement('div', { style: { visibility: 'hidden' } }, this.$slots.default)
|
|
80
|
+
},
|
|
81
|
+
|
|
82
|
+
beforeDestroy(this: BubbleMenuInterface) {
|
|
83
|
+
this.editor.unregisterPlugin(this.pluginKey)
|
|
84
|
+
},
|
|
85
|
+
}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
1
|
+
import type { FloatingMenuPluginProps } from '@tiptap/extension-floating-menu'
|
|
2
|
+
import { FloatingMenuPlugin } from '@tiptap/extension-floating-menu'
|
|
3
|
+
import type { Component, CreateElement, PropType } from 'vue'
|
|
4
|
+
import type Vue from 'vue'
|
|
3
5
|
|
|
4
6
|
export interface FloatingMenuInterface extends Vue {
|
|
5
|
-
pluginKey: FloatingMenuPluginProps['pluginKey']
|
|
6
|
-
|
|
7
|
-
editor: FloatingMenuPluginProps['editor']
|
|
8
|
-
shouldShow: FloatingMenuPluginProps['shouldShow']
|
|
7
|
+
pluginKey: FloatingMenuPluginProps['pluginKey']
|
|
8
|
+
options: FloatingMenuPluginProps['options']
|
|
9
|
+
editor: FloatingMenuPluginProps['editor']
|
|
10
|
+
shouldShow: FloatingMenuPluginProps['shouldShow']
|
|
9
11
|
}
|
|
10
12
|
|
|
11
13
|
export const FloatingMenu: Component = {
|
|
@@ -22,8 +24,8 @@ export const FloatingMenu: Component = {
|
|
|
22
24
|
required: true,
|
|
23
25
|
},
|
|
24
26
|
|
|
25
|
-
|
|
26
|
-
type: Object as PropType<FloatingMenuPluginProps['
|
|
27
|
+
options: {
|
|
28
|
+
type: Object as PropType<FloatingMenuPluginProps['options']>,
|
|
27
29
|
default: () => ({}),
|
|
28
30
|
},
|
|
29
31
|
|
|
@@ -41,14 +43,21 @@ export const FloatingMenu: Component = {
|
|
|
41
43
|
return
|
|
42
44
|
}
|
|
43
45
|
|
|
46
|
+
;(this.$el as HTMLElement).style.visibility = 'hidden'
|
|
47
|
+
;(this.$el as HTMLElement).style.position = 'absolute'
|
|
48
|
+
|
|
49
|
+
this.$el.remove()
|
|
50
|
+
|
|
44
51
|
this.$nextTick(() => {
|
|
45
|
-
editor.registerPlugin(
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
+
editor.registerPlugin(
|
|
53
|
+
FloatingMenuPlugin({
|
|
54
|
+
pluginKey: this.pluginKey,
|
|
55
|
+
editor,
|
|
56
|
+
element: this.$el as HTMLElement,
|
|
57
|
+
options: this.options,
|
|
58
|
+
shouldShow: this.shouldShow,
|
|
59
|
+
}),
|
|
60
|
+
)
|
|
52
61
|
})
|
|
53
62
|
},
|
|
54
63
|
},
|