diff --git a/demos/src/Extensions/FloatingMenu/React/index.jsx b/demos/src/Extensions/FloatingMenu/React/index.jsx index 7fcb176de..24c21ea2c 100644 --- a/demos/src/Extensions/FloatingMenu/React/index.jsx +++ b/demos/src/Extensions/FloatingMenu/React/index.jsx @@ -1,13 +1,50 @@ import './styles.scss' -import { EditorContent, FloatingMenu, useEditor } from '@tiptap/react' +import { + EditorContent, FloatingMenu, mergeAttributes, + Node, useEditor, +} from '@tiptap/react' import StarterKit from '@tiptap/starter-kit' import React, { useEffect } from 'react' +const Foo = Node.create({ + name: 'foo', + + group: 'inline', + + inline: true, + + parseHTML() { + return [ + { + tag: 'span', + getAttrs: node => node.hasAttribute('data-foo') && null, + }, + ] + }, + + renderHTML({ HTMLAttributes }) { + return ['span', mergeAttributes({ 'data-foo': '', HTMLAttributes }), 'foo'] + }, + + renderText() { + return 'foo' + }, + + addCommands() { + return { + insertFoo: () => ({ commands }) => { + return commands.insertContent({ type: this.name }) + }, + } + }, +}) + export default () => { const editor = useEditor({ extensions: [ StarterKit, + Foo, ], content: `

@@ -32,9 +69,10 @@ export default () => { setIsEditable(!isEditable)} /> Editable + {editor && -

+