11import { Node } from "@tiptap/core" ;
22import { TagParseRule } from "@tiptap/pm/model" ;
3- import { nodeToCustomInlineContent } from "../../api/nodeConversions/nodeConversions" ;
3+ import {
4+ inlineContentToNodes ,
5+ nodeToCustomInlineContent ,
6+ } from "../../api/nodeConversions/nodeConversions" ;
47import { propsToAttributes } from "../blocks/internal" ;
58import { Props } from "../propTypes" ;
69import { StyleSchema } from "../styles/types" ;
@@ -11,15 +14,15 @@ import {
1114} from "./internal" ;
1215import {
1316 CustomInlineContentConfig ,
14- InlineContentConfig ,
1517 InlineContentFromConfig ,
1618 InlineContentSpec ,
19+ PartialCustomInlineContentFromConfig ,
1720} from "./types" ;
1821
1922// TODO: support serialization
2023
2124export type CustomInlineContentImplementation <
22- T extends InlineContentConfig ,
25+ T extends CustomInlineContentConfig ,
2326 // B extends BlockSchema,
2427 // I extends InlineContentSchema,
2528 S extends StyleSchema
@@ -28,7 +31,10 @@ export type CustomInlineContentImplementation<
2831 /**
2932 * The custom inline content to render
3033 */
31- inlineContent : InlineContentFromConfig < T , S >
34+ inlineContent : InlineContentFromConfig < T , S > ,
35+ updateInlineContent : (
36+ update : PartialCustomInlineContentFromConfig < T , S >
37+ ) => void
3238 /**
3339 * The BlockNote editor instance
3440 * This is typed generically. If you want an editor with your custom schema, you need to
@@ -100,7 +106,10 @@ export function createInlineContentSpec<
100106 node ,
101107 editor . schema . inlineContentSchema ,
102108 editor . schema . styleSchema
103- ) as any as InlineContentFromConfig < T , S > // TODO: fix cast
109+ ) as any as InlineContentFromConfig < T , S > , // TODO: fix cast
110+ ( ) => {
111+ // No-op
112+ }
104113 ) ;
105114
106115 return addInlineContentAttributes (
@@ -110,6 +119,46 @@ export function createInlineContentSpec<
110119 inlineContentConfig . propSchema
111120 ) ;
112121 } ,
122+
123+ addNodeView ( ) {
124+ return ( { node, getPos } ) => {
125+ const editor = this . options . editor ;
126+
127+ const output = inlineContentImplementation . render (
128+ nodeToCustomInlineContent (
129+ node ,
130+ editor . schema . inlineContentSchema ,
131+ editor . schema . styleSchema
132+ ) as any as InlineContentFromConfig < T , S > , // TODO: fix cast
133+ ( update ) => {
134+ if ( typeof getPos === "boolean" ) {
135+ return ;
136+ }
137+
138+ const content = inlineContentToNodes (
139+ [ update ] ,
140+ editor . _tiptapEditor . schema ,
141+ editor . schema . styleSchema
142+ ) ;
143+
144+ editor . _tiptapEditor . view . dispatch (
145+ editor . _tiptapEditor . view . state . tr . replaceWith (
146+ getPos ( ) ,
147+ getPos ( ) + node . nodeSize ,
148+ content
149+ )
150+ ) ;
151+ }
152+ ) ;
153+
154+ return addInlineContentAttributes (
155+ output ,
156+ inlineContentConfig . type ,
157+ node . attrs as Props < T [ "propSchema" ] > ,
158+ inlineContentConfig . propSchema
159+ ) ;
160+ } ;
161+ } ,
113162 } ) ;
114163
115164 return createInlineContentSpecFromTipTapNode (
0 commit comments