1+ using System . Text . Json . Nodes ;
12using Microsoft . AspNetCore . Components ;
23using Microsoft . JSInterop ;
34
@@ -40,6 +41,18 @@ public sealed partial class MudHtmlEditor : IAsyncDisposable
4041 [ Parameter ]
4142 public EventCallback < string > HtmlChanged { get ; set ; }
4243
44+ /// <summary>
45+ /// The delta contents from the editor.
46+ /// </summary>
47+ [ Parameter ]
48+ public JsonObject Contents { get ; set ; } = new JsonObject ( ) ;
49+
50+ /// <summary>
51+ /// Raised when the <see cref="Contents"/> property changes.
52+ /// </summary>
53+ [ Parameter ]
54+ public EventCallback < JsonObject > ContentsChanged { get ; set ; }
55+
4356 /// <summary>
4457 /// The plain-text content from the editor.
4558 /// </summary>
@@ -83,6 +96,7 @@ public async Task SetHtml(string html)
8396
8497 HandleHtmlContentChanged ( html ) ;
8598 HandleTextContentChanged ( await GetText ( ) ) ;
99+ HandleContentsChanged ( await GetContents ( ) ) ;
86100 }
87101
88102 /// <summary>
@@ -96,6 +110,17 @@ public async Task<string> GetHtml()
96110 return "" ;
97111 }
98112
113+ /// <summary>
114+ /// Gets the current delta contents of the editor.
115+ /// </summary>
116+ public async Task < JsonObject > GetContents ( )
117+ {
118+ if ( _quill is not null )
119+ return await _quill . InvokeAsync < JsonObject > ( "getContents" ) ;
120+
121+ return new JsonObject ( ) ;
122+ }
123+
99124 /// <summary>
100125 /// Gets the current plain-text content of the editor.
101126 /// </summary>
@@ -149,6 +174,15 @@ public async void HandleTextContentChanged(string text)
149174 await TextChanged . InvokeAsync ( text ) ;
150175 }
151176
177+ [ JSInvokable ]
178+ public async void HandleContentsChanged ( JsonObject contents )
179+ {
180+ if ( JsonObject . Equals ( Contents , contents ) ) return ; // nothing changed
181+
182+ Contents = contents ;
183+ await ContentsChanged . InvokeAsync ( contents ) ;
184+ }
185+
152186 async ValueTask IAsyncDisposable . DisposeAsync ( )
153187 {
154188 if ( _quill is not null )
0 commit comments