@@ -12,39 +12,62 @@ namespace MudExtensions;
1212public partial class MudJsonTreeView : MudComponentBase
1313{
1414 private string ? _json ;
15+ private JsonNode ? _root ;
1516
1617 /// <summary>
17- /// Gets or sets the JSON to be displayed.
18+ /// The JSON to be displayed.
1819 /// </summary>
20+ /// <remarks>
21+ /// Use the <see cref="Root"/> parameter instead if you have a <see cref="JsonNode"/> available.
22+ /// </remarks>
1923 [ Parameter ]
20- [ EditorRequired ]
2124 public string ? Json
2225 {
2326 get => _json ;
2427 set => SetJson ( value ) ;
2528 }
2629
30+ /// <summary>
31+ /// The root node of the JSON to display.
32+ /// </summary>
33+ /// <remarks>
34+ /// Use the <see cref="Json"/> parameter instead if you only have JSON available as a string.
35+ /// </remarks>
36+ [ Parameter ]
37+ public JsonNode ? Root
38+ {
39+ get => _root ;
40+ set => SetJson ( value ) ;
41+ }
42+
2743 /// <summary>
2844 /// Sets the <see cref="Json"/> property and raises the <see cref="OnJsonChanged"/> event.
2945 /// </summary>
3046 /// <param name="json">The new JSON to use.</param>
3147 protected void SetJson ( string ? json )
3248 {
3349 _json = json ;
34- Root = string . IsNullOrEmpty ( _json ) ? null : JsonNode . Parse ( _json ) ;
35- OnJsonChanged . InvokeAsync ( _json ) ;
50+ _root = string . IsNullOrEmpty ( _json ) ? null : JsonNode . Parse ( _json ) ;
51+ OnJsonChanged . InvokeAsync ( Root ) ;
3652 StateHasChanged ( ) ;
3753 }
3854
3955 /// <summary>
40- /// Occurs when the JSON has changed .
56+ /// Sets the <see cref="Json"/> property and raises the <see cref="OnJsonChanged"/> event .
4157 /// </summary>
42- public EventCallback < string > OnJsonChanged { get ; set ; }
58+ /// <param name="json">The new JSON to use.</param>
59+ protected void SetJson ( JsonNode ? json )
60+ {
61+ _json = json ? . ToJsonString ( ) ;
62+ _root = json ;
63+ OnJsonChanged . InvokeAsync ( Root ) ;
64+ StateHasChanged ( ) ;
65+ }
4366
4467 /// <summary>
45- /// Gets or sets the root node of the JSON to display .
68+ /// Occurs when the JSON has changed .
4669 /// </summary>
47- public JsonNode ? Root { get ; set ; }
70+ public EventCallback < JsonNode > OnJsonChanged { get ; set ; }
4871
4972 /// <summary>
5073 /// Gets or sets a value indicating whether the tree contents are compacted.
0 commit comments