Skip to content

Commit

Permalink
fix(bubble-menu): support vue node views
Browse files Browse the repository at this point in the history
  • Loading branch information
bdbch committed Mar 27, 2023
1 parent cb1aa86 commit 1503c24
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
55 changes: 53 additions & 2 deletions demos/src/Extensions/BubbleMenu/React/index.jsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,69 @@
import './styles.scss'

import { BubbleMenu, EditorContent, useEditor } from '@tiptap/react'
import {
BubbleMenu, EditorContent, Node, NodeViewWrapper, ReactNodeViewRenderer, useEditor,
} from '@tiptap/react'
import StarterKit from '@tiptap/starter-kit'
import React, { useEffect } from 'react'

const CustomNodeView = () => {
return (
<NodeViewWrapper>
<div contentEditable={false} style={{ float: 'left', aspectRatio: 1, backgroundColor: 'red' }}>This is my node view!</div>
</NodeViewWrapper>
)
}

const CustomNodeViewNode = Node.create({
name: 'customNodeView',

group: 'block',

content: 'inline*',

selectable: true,

defining: true,

atom: true,

isolating: true,

renderHTML() {
return ['div', { class: 'custom-node-view' }, 0]
},

parseHTML() {
return [
{
tag: 'div.custom-node-view',
},
]
},

addNodeView() {
return ReactNodeViewRenderer(CustomNodeView)
},
})

export default () => {
const editor = useEditor({
extensions: [
StarterKit,
CustomNodeViewNode,
],
content: `
<div class="custom-node-view"></div>
<p>
Hey, try to select some text here. There will popup a menu for selecting some inline styles. Remember: you have full control about content and styling of this menu.
</p>
<div class="custom-node-view"></div>
<div class="custom-node-view"></div>
<p>
Hey, try to select some text here. There will popup a menu for selecting some inline styles. Remember: you have full control about content and styling of this menu.
</p>
<div class="custom-node-view"></div>
<div class="custom-node-view"></div>
`,
})

Expand All @@ -30,7 +81,7 @@ export default () => {
<input type="checkbox" checked={isEditable} onChange={() => setIsEditable(!isEditable)} />
Editable
</div>
{editor && <BubbleMenu editor={editor} tippyOptions={{ duration: 100 }}>
{editor && <BubbleMenu updateDelay={2000} editor={editor} tippyOptions={{ duration: 100 }}>
<button
onClick={() => editor.chain().focus().toggleBold().run()}
className={editor.isActive('bold') ? 'is-active' : ''}
Expand Down
2 changes: 1 addition & 1 deletion packages/extension-bubble-menu/src/bubble-menu-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ export class BubbleMenuView {
if (isNodeSelection(state.selection)) {
let node = view.nodeDOM(from) as HTMLElement

const nodeViewWrapper = node.querySelector('[data-node-view-wrapper]')
const nodeViewWrapper = node.dataset.nodeViewWrapper ? node : node.querySelector('[data-node-view-wrapper]')

if (nodeViewWrapper) {
node = nodeViewWrapper.firstChild as HTMLElement
Expand Down

0 comments on commit 1503c24

Please sign in to comment.