import { Node, mergeAttributes } from '@tiptap/core' import React from 'react' import { NodeViewWrapper, ReactNodeViewRenderer } from '@tiptap/react' declare module '@tiptap/core' { interface Commands { readonlyText: { insertReadonlyText: (text: string) => ReturnType } } } export const ReadonlyText = Node.create({ name: 'readonlyText', group: 'inline', inline: true, atom: true, // δΈε―ζ‹†εˆ† selectable: false, addAttributes() { return { text: { default: '', }, } }, parseHTML() { return [ { tag: 'span[data-readonly-text]', }, ] }, renderHTML({ HTMLAttributes }) { return [ 'span', mergeAttributes(HTMLAttributes, { 'data-readonly-text': '', }), ] }, addNodeView() { return ReactNodeViewRenderer(ReadonlyTextView) }, addCommands() { return { insertReadonlyText: (text: string) => ({ commands }) => { return commands.insertContent({ type: this.name, attrs: { text }, }) }, } }, }) const ReadonlyTextView = (props: any) => { return ( {props.node.attrs.text} ) }