├── .github ├── FUNDING.yml └── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── .gitignore ├── Blazor.JsonEditor.Demo.Wasm ├── App.razor ├── Blazor.JsonEditor.Demo.Wasm.csproj ├── Blazor.JsonEditor.Demo.Wasm.csproj.user ├── Client │ └── Program.cs ├── Component │ ├── JsonItemCustomEditor.razor │ ├── JsonItemCustomEditor.razor.cs │ ├── JsonItemCustomEditor.razor.css │ ├── JsonItemCustomView.razor │ ├── JsonItemCustomView.razor.cs │ ├── JsonItemCustomView.razor.css │ ├── JsonObjectCustomView.razor │ ├── JsonObjectCustomView.razor.cs │ └── JsonObjectCustomView.razor.css ├── Model │ └── IndexModel.cs ├── Pages │ ├── Index.razor │ ├── Index.razor.cs │ └── Index.razor.css ├── Properties │ └── launchSettings.json ├── Shared │ ├── MainLayout.razor │ └── MainLayout.razor.css ├── _Imports.razor └── wwwroot │ ├── css │ ├── app.css │ ├── bootstrap │ │ ├── bootstrap.min.css │ │ └── bootstrap.min.css.map │ └── open-iconic │ │ ├── FONT-LICENSE │ │ ├── ICON-LICENSE │ │ ├── README.md │ │ └── font │ │ ├── css │ │ └── open-iconic-bootstrap.min.css │ │ └── fonts │ │ ├── open-iconic.eot │ │ ├── open-iconic.otf │ │ ├── open-iconic.svg │ │ ├── open-iconic.ttf │ │ └── open-iconic.woff │ ├── favicon.png │ ├── icon-192.png │ ├── index.html │ └── sample-data │ └── weather.json ├── Blazor.JsonEditor.Demo ├── App.razor ├── Blazor.JsonEditor.Demo.csproj ├── Blazor.JsonEditor.Demo.csproj.user ├── Component │ ├── JsonItemCustomEditor.razor │ ├── JsonItemCustomEditor.razor.cs │ ├── JsonItemCustomEditor.razor.css │ ├── JsonItemCustomView.razor │ ├── JsonItemCustomView.razor.cs │ ├── JsonItemCustomView.razor.css │ ├── JsonObjectCustomView.razor │ ├── JsonObjectCustomView.razor.cs │ └── JsonObjectCustomView.razor.css ├── Data │ ├── WeatherForecast.cs │ └── WeatherForecastService.cs ├── Model │ └── IndexModel.cs ├── Pages │ ├── Index.razor │ ├── Index.razor.cs │ ├── Index.razor.css │ └── _Host.cshtml ├── Program.cs ├── Properties │ └── launchSettings.json ├── Shared │ ├── MainLayout.razor │ └── MainLayout.razor.css ├── _Imports.razor ├── appsettings.Development.json ├── appsettings.json └── wwwroot │ ├── css │ ├── bootstrap │ │ ├── bootstrap.min.css │ │ └── bootstrap.min.css.map │ ├── open-iconic │ │ ├── FONT-LICENSE │ │ ├── ICON-LICENSE │ │ ├── README.md │ │ └── font │ │ │ ├── css │ │ │ └── open-iconic-bootstrap.min.css │ │ │ └── fonts │ │ │ ├── open-iconic.eot │ │ │ ├── open-iconic.otf │ │ │ ├── open-iconic.svg │ │ │ ├── open-iconic.ttf │ │ │ └── open-iconic.woff │ └── site.css │ └── favicon.png ├── Blazor.JsonEditor.sln ├── Blazor.JsonEditor ├── Attribute │ └── RequiredIfAttribute.cs ├── Blazor.JsonEditor.csproj ├── Component │ ├── Editor │ │ ├── JsonItemDefaultEditor.razor │ │ ├── JsonItemDefaultEditor.razor.cs │ │ ├── JsonItemDefaultEditor.razor.css │ │ ├── JsonItemEditor.razor │ │ ├── JsonItemEditor.razor.cs │ │ └── JsonItemEditor.razor.css │ ├── InternalJsonEditor.razor │ ├── InternalJsonEditor.razor.cs │ ├── InternalJsonEditor.razor.css │ ├── JsonEditor.razor │ ├── JsonEditor.razor.cs │ ├── JsonEditor.razor.css │ └── Viewer │ │ ├── Item │ │ ├── JsonItemDefaultView.razor │ │ ├── JsonItemDefaultView.razor.cs │ │ ├── JsonItemDefaultView.razor.css │ │ ├── JsonItemView.razor │ │ └── JsonItemView.razor.cs │ │ └── Object │ │ ├── JsonObjectDefaultView.razor │ │ ├── JsonObjectDefaultView.razor.cs │ │ ├── JsonObjectDefaultView.razor.css │ │ ├── JsonObjectView.razor │ │ └── JsonObjectView.razor.cs ├── Helper │ └── JsonHelper.cs ├── LICENSE.txt ├── Model │ └── JsonItem.cs ├── README.md ├── _Imports.razor └── wwwroot │ └── Blazor.JsonEditor.js ├── LICENSE └── README.md /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: [joghyrt] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: joghyrt 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry 13 | custom: ['https://www.buymeacoffee.com/joghyrt'] 14 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | 31 | **Smartphone (please complete the following information):** 32 | - Device: [e.g. iPhone6] 33 | - OS: [e.g. iOS8.1] 34 | - Browser [e.g. stock browser, safari] 35 | - Version [e.g. 22] 36 | 37 | **Additional context** 38 | Add any other context about the problem here. 39 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | */bin/ 3 | */obj/ 4 | .vs/ 5 | */release/* 6 | release/ 7 | -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo.Wasm/App.razor: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | Not found 8 | 9 |

Sorry, there's nothing at this address.

10 |
11 |
12 |
13 | -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo.Wasm/Blazor.JsonEditor.Demo.Wasm.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | net7.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo.Wasm/Blazor.JsonEditor.Demo.Wasm.csproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | https 5 | 6 | -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo.Wasm/Client/Program.cs: -------------------------------------------------------------------------------- 1 | using Blazor.JsonEditor.Demo.Wasm; 2 | using Microsoft.AspNetCore.Components.Web; 3 | using Microsoft.AspNetCore.Components.WebAssembly.Hosting; 4 | 5 | namespace Blazor.JsonEditor.Demo.Wasm 6 | { 7 | public class Program 8 | { 9 | public static async Task Main(string[] args) 10 | { 11 | var builder = WebAssemblyHostBuilder.CreateDefault(args); 12 | builder.RootComponents.Add("#app"); 13 | builder.RootComponents.Add("head::after"); 14 | 15 | builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); 16 | 17 | await builder.Build().RunAsync(); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo.Wasm/Component/JsonItemCustomEditor.razor: -------------------------------------------------------------------------------- 1 | @using System.Text.Json 2 | 3 | 4 | 15 | 16 | @if (IsShowEditor) 17 | { 18 | 19 | 20 |
21 | @if (ValidationMessage != null) 22 | { 23 |
24 | @ValidationMessage 25 |
26 | } 27 |
28 |
29 | 30 | 31 | 32 |
33 |
34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 |
45 |
46 |
47 | @if (JsonItem.ValueKind != JsonValueKind.Undefined) 48 | { 49 | 50 | } 51 | @if (JsonItem.ValueKind == JsonValueKind.String || JsonItem.ValueKind == JsonValueKind.Array) 52 | { 53 | 54 | 55 | } 56 | else if (JsonItem.ValueKind == JsonValueKind.Number) 57 | { 58 | 59 | 60 | } 61 | else if (JsonItem.ValueKind == JsonValueKind.True) 62 | { 63 | 64 | 65 | 66 | 67 | 68 | 69 | } 70 | else if (JsonItem.ValueKind == JsonValueKind.False && KeyValues?.Count > 0) 71 | { 72 | 73 | 74 | @foreach (var kv in KeyValues) 75 | { 76 | 77 | } 78 | 79 | 80 | } 81 |
82 |
83 | 86 | @if (JsonItemToEdit != null) 87 | { 88 | 89 | 92 | 93 | } 94 |
95 |
96 |
97 | } -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo.Wasm/Component/JsonItemCustomEditor.razor.cs: -------------------------------------------------------------------------------- 1 | using System.Globalization; 2 | using System.Text.Json; 3 | using System.Text.Json.Nodes; 4 | using Blazor.JsonEditor.Helper; 5 | using Blazor.JsonEditor.Model; 6 | using Microsoft.AspNetCore.Components; 7 | 8 | namespace Blazor.JsonEditor.Demo.Wasm.Component 9 | { 10 | public partial class JsonItemCustomEditor 11 | { 12 | [Parameter] 13 | public JsonObject? JsonObject { get; set; } 14 | 15 | [Parameter] 16 | public EventCallback JsonObjectChanged { get; set; } 17 | 18 | [Parameter] 19 | public Dictionary? KeyValues { get; set; } 20 | 21 | [Parameter] 22 | public KeyValuePair? JsonItemToEdit { get; set; } 23 | 24 | private bool IsShowEditor; 25 | 26 | private bool IsEditMode 27 | { 28 | get 29 | { 30 | return JsonItemToEdit != null; 31 | } 32 | } 33 | 34 | private string? ValidationMessage; 35 | 36 | private JsonItem? JsonItem { get; set; } 37 | 38 | private void ToggleEditor() 39 | { 40 | IsShowEditor = !IsShowEditor; 41 | ValidationMessage = null; 42 | StateHasChanged(); 43 | } 44 | 45 | protected override void OnParametersSet() 46 | { 47 | JsonItem = new JsonItem(); 48 | if (JsonItemToEdit == null) 49 | { 50 | JsonItem.ValueKind = JsonValueKind.Undefined; 51 | return; 52 | } 53 | 54 | this.ProcessEditMode(); 55 | } 56 | 57 | private void ProcessEditMode() 58 | { 59 | JsonItem.PropertyName = JsonItemToEdit.Value.Key; 60 | 61 | var jsonObjectValue = JsonObject?.FirstOrDefault(x => x.Key.Equals(JsonItemToEdit.Value.Key)).Value; 62 | 63 | var jsonElement = new JsonElement(); 64 | 65 | if (jsonObjectValue != null) 66 | { 67 | jsonElement = JsonSerializer.Deserialize(jsonObjectValue.ToJsonString()); 68 | JsonItem.ValueKind = jsonElement.ValueKind; 69 | } 70 | 71 | switch (jsonElement.ValueKind) 72 | { 73 | case JsonValueKind.String: 74 | JsonItem.Value = jsonElement.ToString(); 75 | break; 76 | case JsonValueKind.Number: 77 | if (!double.TryParse(jsonElement.ToString(), CultureInfo.InvariantCulture, out var numericValue)) 78 | { 79 | throw new ArgumentException($"Not able to parse value {jsonElement.ToString()} to double."); 80 | } 81 | 82 | JsonItem.NumericValue = numericValue; 83 | break; 84 | case JsonValueKind.True: 85 | JsonItem.Value = "true"; 86 | break; 87 | case JsonValueKind.False: 88 | JsonItem.Value = "false"; 89 | JsonItem.ValueKind = JsonValueKind.True; 90 | break; 91 | case JsonValueKind.Array: 92 | { 93 | var arrayValue = jsonElement.ToString(); 94 | JsonItem.Value = arrayValue.Substring(1, arrayValue.Length - 2); 95 | break; 96 | } 97 | case JsonValueKind.Null: 98 | JsonItem.ValueKind = JsonValueKind.Undefined; 99 | break; 100 | } 101 | } 102 | 103 | private async Task SaveNodeAsync() 104 | { 105 | try 106 | { 107 | ValidationMessage = null; 108 | 109 | if (JsonItem == null) 110 | { 111 | ToggleEditor(); 112 | return; 113 | } 114 | 115 | if (!this.IsEditMode) 116 | { 117 | this.AddNode(); 118 | } 119 | else 120 | { 121 | this.EditNode(); 122 | } 123 | 124 | await JsonObjectChanged.InvokeAsync(JsonObject); 125 | JsonItem = null; 126 | ToggleEditor(); 127 | } 128 | catch (ArgumentException ex) 129 | { 130 | ValidationMessage = ex.Message; 131 | } 132 | } 133 | 134 | private void AddNode() 135 | { 136 | if (JsonItem == null || string.IsNullOrEmpty(JsonItem.PropertyName)) 137 | { 138 | return; 139 | } 140 | 141 | if (JsonObject == null) 142 | { 143 | JsonObject = new JsonObject(); 144 | } 145 | 146 | JsonHelper.AddNodeValue(JsonObject, JsonItem); 147 | } 148 | 149 | private void EditNode() 150 | { 151 | if (JsonObject == null) 152 | { 153 | return; 154 | } 155 | 156 | if (JsonItem == null) 157 | { 158 | return; 159 | } 160 | 161 | if (JsonItemToEdit == null) 162 | { 163 | return; 164 | } 165 | 166 | JsonHelper.EditNodeValue(JsonObject, JsonItem, JsonItemToEdit.Value.Key); 167 | } 168 | 169 | private async Task RemoveNode() 170 | { 171 | if (this.JsonObject == null) 172 | { 173 | return; 174 | } 175 | 176 | if (this.JsonItemToEdit == null) 177 | { 178 | return; 179 | } 180 | 181 | this.JsonObject.Remove(this.JsonItemToEdit.Value.Key); 182 | await JsonObjectChanged.InvokeAsync(JsonObject); 183 | ToggleEditor(); 184 | this.StateHasChanged(); 185 | } 186 | } 187 | } -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo.Wasm/Component/JsonItemCustomEditor.razor.css: -------------------------------------------------------------------------------- 1 | .json-content { 2 | padding: 5px; 3 | border: 1px solid #ccc; 4 | } 5 | 6 | .json-object-body { 7 | margin-left:20px; 8 | min-width:500px 9 | } 10 | 11 | .json-object-body-empty { 12 | margin-left:20px; 13 | } 14 | 15 | .json-property-name { 16 | padding: 3px; 17 | color: brown; 18 | } 19 | 20 | .json-value-content { 21 | padding: 3px; 22 | font-style: italic; 23 | } 24 | 25 | .json-button { 26 | padding: 4px; 27 | border-radius: 4px; 28 | border: 1px solid #ccc; 29 | line-height: 1px; 30 | font-family: 'Wingdings 2'; 31 | font-size: 10px; 32 | } 33 | 34 | .json-button-submit { 35 | padding: 8px; 36 | border-radius: 5px; 37 | border: 1px solid #ccc; 38 | line-height: 1px; 39 | font-family: 'Wingdings 2'; 40 | font-size: 14px; 41 | width: 110px; 42 | color: white; 43 | background-color: green; 44 | margin-right: 10px; 45 | } 46 | 47 | .json-close-button{ 48 | padding: 8px; 49 | border-radius: 5px; 50 | border: 1px solid #ccc; 51 | line-height: 1px; 52 | font-family: 'Wingdings 2'; 53 | font-size: 14px; 54 | width: 110px; 55 | color: white; 56 | background-color: grey; 57 | margin-right: 10px; 58 | } 59 | 60 | .json-button-delete { 61 | padding: 8px; 62 | border-radius: 5px; 63 | border: 1px solid #ccc; 64 | line-height: 1px; 65 | font-family: 'Wingdings 2'; 66 | font-size: 14px; 67 | width: 110px; 68 | color: white; 69 | background-color: darkred; 70 | } 71 | 72 | .json-button-danger { 73 | color: red; 74 | } 75 | 76 | .json-input-text { 77 | padding: 2px 5px; 78 | border-radius: 5px; 79 | border: 1px solid #ccc; 80 | width: 100%; 81 | line-height: 1.2em; 82 | } 83 | 84 | .json-validation-error { 85 | color: red; 86 | } 87 | 88 | .json-value-string { 89 | color: darkgoldenrod; 90 | } 91 | 92 | .json-value-number { 93 | color: blueviolet; 94 | } 95 | 96 | .json-value-array { 97 | color: darkgreen; 98 | } 99 | 100 | .json-new-item-form-container { 101 | background: #fff; 102 | border: 1px solid #808080; 103 | padding: 10px; 104 | border-radius: 5px; 105 | box-shadow: 3px 3px 10px #1d1d1d; 106 | width: 400px; 107 | } 108 | 109 | .json-input-group { 110 | display: flex; 111 | flex-direction: column; 112 | } 113 | 114 | .json-input-group > label { 115 | font-style: italic; 116 | font-weight: 600; 117 | } 118 | 119 | .json-button-container { 120 | margin-top: 20px; 121 | display: flex; 122 | width: 100%; 123 | } -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo.Wasm/Component/JsonItemCustomView.razor: -------------------------------------------------------------------------------- 1 | @using System.Text.Json 2 | @using Blazor.JsonEditor.Helper 3 | 4 | @if (JsonHelper.IsInJsonValueKind(JsonItem, new List { JsonValueKind.Number, JsonValueKind.True, JsonValueKind.False })) 5 | { 6 | "@JsonItem.Key" 7 | 8 | @JsonItem.Value.ToString() 9 | } 10 | else if (JsonItem.Value == null) 11 | { 12 | "@JsonItem.Key" 13 | 14 | null 15 | } 16 | else if (JsonHelper.IsInJsonValueKind(JsonItem, new List { JsonValueKind.String })) 17 | { 18 | "@JsonItem.Key" 19 | 20 | "@JsonItem.Value.ToString()" 21 | } 22 | else if (JsonHelper.IsInJsonValueKind(JsonItem, new List { JsonValueKind.Array })) 23 | { 24 | "@JsonItem.Key" 25 | 26 | @JsonItem.Value.ToJsonString() 27 | } -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo.Wasm/Component/JsonItemCustomView.razor.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json.Nodes; 2 | using Microsoft.AspNetCore.Components; 3 | 4 | namespace Blazor.JsonEditor.Demo.Wasm.Component 5 | { 6 | public partial class JsonItemCustomView 7 | { 8 | [Parameter] 9 | public KeyValuePair JsonItem { get; set; } 10 | 11 | [Parameter] 12 | public JsonObject? JsonObject { get; set; } 13 | 14 | [Parameter] 15 | public EventCallback ValueChanged { get; set; } 16 | 17 | [Parameter] 18 | public Dictionary? KeyValues { get; set; } 19 | 20 | [Parameter] 21 | public bool AllowEdit { get; set; } = true; 22 | 23 | [Parameter] 24 | public Type? CustomEditor { get; set; } 25 | 26 | [Parameter] 27 | public Type? CustomItemView { get; set; } 28 | 29 | [Parameter] 30 | public Type? CustomObjectView { get; set; } 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo.Wasm/Component/JsonItemCustomView.razor.css: -------------------------------------------------------------------------------- 1 | .json-property-name { 2 | padding: 3px; 3 | color: brown; 4 | } 5 | 6 | .json-content { 7 | padding: 5px; 8 | border: 1px solid #ccc; 9 | } 10 | 11 | .json-value-content { 12 | padding: 3px; 13 | font-style: italic; 14 | } 15 | 16 | .json-value-string { 17 | color: darkgoldenrod; 18 | } 19 | 20 | .json-value-number { 21 | color: blueviolet; 22 | } 23 | 24 | .json-value-array { 25 | color: darkgreen; 26 | } -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo.Wasm/Component/JsonObjectCustomView.razor: -------------------------------------------------------------------------------- 1 | @using Blazor.JsonEditor.Component 2 | 3 | "@JsonItem.Key" 4 | 5 | 6 | 7 | 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo.Wasm/Component/JsonObjectCustomView.razor.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json.Nodes; 2 | using Microsoft.AspNetCore.Components; 3 | 4 | namespace Blazor.JsonEditor.Demo.Wasm.Component 5 | { 6 | public partial class JsonObjectCustomView 7 | { 8 | 9 | [Parameter] 10 | public KeyValuePair JsonItem { get; set; } 11 | 12 | [Parameter] 13 | public EventCallback ValueChanged { get; set; } 14 | 15 | [Parameter] 16 | public Dictionary? KeyValues { get; set; } 17 | 18 | [Parameter] 19 | public bool AllowEdit { get; set; } = true; 20 | 21 | [Parameter] 22 | public Type? CustomEditor { get; set; } 23 | 24 | [Parameter] 25 | public Type? CustomItemView { get; set; } 26 | 27 | [Parameter] 28 | public Type? CustomObjectView { get; set; } 29 | 30 | } 31 | } 32 | 33 | -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo.Wasm/Component/JsonObjectCustomView.razor.css: -------------------------------------------------------------------------------- 1 | .json-property-name { 2 | padding: 3px; 3 | color: brown; 4 | } -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo.Wasm/Model/IndexModel.cs: -------------------------------------------------------------------------------- 1 | namespace Blazor.JsonEditor.Demo.Wasm.Model 2 | { 3 | public class IndexModel 4 | { 5 | public string Json { get; set; } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo.Wasm/Pages/Index.razor: -------------------------------------------------------------------------------- 1 | @page "/" 2 | 3 | @using Blazor.JsonEditor.Demo.Wasm.Model 4 | @using Blazor.JsonEditor.Demo.Wasm.Component 5 | 6 | Index 7 | 8 |
9 |

Json Viewer

10 | You can easily make json viewer from json editor. Just pass AllowEdit="false" 11 | 12 | 13 | 14 |
15 |
16 |

Json Editor

17 | Here is json editor. If you find any bugs or you would like to see any improvements please contact me here 18 | 19 | 20 | 21 |
22 | @*
*@ 23 | @*

Json Editor with custom components

*@ 24 | @* Here we use custom Edit template for Json node and customer view template for Item and Object. You can create your own component and use it as editor template. More information in documentation here *@ 25 | @* *@ 26 | @* *@ 27 | @* *@ 28 | @*
*@ 29 | -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo.Wasm/Pages/Index.razor.cs: -------------------------------------------------------------------------------- 1 | using Blazor.JsonEditor.Demo.Wasm.Model; 2 | 3 | namespace Blazor.JsonEditor.Demo.Wasm.Pages 4 | { 5 | public partial class Index 6 | { 7 | private IndexModel DemoJson { get; set; } = new() 8 | { 9 | Json = 10 | "{\"Nullable\": null, \"String\": \"random\", \"Number\": 1, \"Array\": [1,2,3], \"True\": true, \"False\": false, \"Object\": { \"Nullable\": null, \"String\": \"random\", \"Number\": 1, \"Array\": [1,2,3], \"True\": true, \"False\": false, \"ObjectsArray\": [{ \"Name\":\"First Object\", \"Property\": 1}, {\"Name\":\"Second Object\", \"Property\": 1}]}}" }; 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo.Wasm/Pages/Index.razor.css: -------------------------------------------------------------------------------- 1 | .section-container { 2 | margin: 10px 10px 30px; 3 | } -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo.Wasm/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:55227", 7 | "sslPort": 44307 8 | } 9 | }, 10 | "profiles": { 11 | "http": { 12 | "commandName": "Project", 13 | "dotnetRunMessages": true, 14 | "launchBrowser": true, 15 | "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", 16 | "applicationUrl": "http://localhost:5062", 17 | "environmentVariables": { 18 | "ASPNETCORE_ENVIRONMENT": "Development" 19 | } 20 | }, 21 | "https": { 22 | "commandName": "Project", 23 | "dotnetRunMessages": true, 24 | "launchBrowser": true, 25 | "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", 26 | "applicationUrl": "https://localhost:7188;http://localhost:5062", 27 | "environmentVariables": { 28 | "ASPNETCORE_ENVIRONMENT": "Development" 29 | } 30 | }, 31 | "IIS Express": { 32 | "commandName": "IISExpress", 33 | "launchBrowser": true, 34 | "inspectUri": "{wsProtocol}://{url.hostname}:{url.port}/_framework/debug/ws-proxy?browser={browserInspectUri}", 35 | "environmentVariables": { 36 | "ASPNETCORE_ENVIRONMENT": "Development" 37 | } 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo.Wasm/Shared/MainLayout.razor: -------------------------------------------------------------------------------- 1 | @inherits LayoutComponentBase 2 | 3 |
4 |
5 | 15 | 16 |
17 | @Body 18 |
19 |
20 |
21 | -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo.Wasm/Shared/MainLayout.razor.css: -------------------------------------------------------------------------------- 1 | .page { 2 | position: relative; 3 | display: flex; 4 | flex-direction: column; 5 | } 6 | 7 | main { 8 | flex: 1; 9 | } 10 | 11 | .sidebar { 12 | background-image: linear-gradient(180deg, rgb(5, 39, 103) 0%, #3a0647 70%); 13 | } 14 | 15 | .top-row { 16 | background-color: #f7f7f7; 17 | border-bottom: 1px solid #d6d5d5; 18 | justify-content: flex-end; 19 | height: 3.5rem; 20 | display: flex; 21 | align-items: center; 22 | } 23 | 24 | .top-row ::deep a, .top-row ::deep .btn-link { 25 | white-space: nowrap; 26 | margin-left: 1.5rem; 27 | text-decoration: none; 28 | } 29 | 30 | .top-row ::deep a:hover, .top-row ::deep .btn-link:hover { 31 | text-decoration: underline; 32 | } 33 | 34 | .top-row ::deep a:first-child { 35 | overflow: hidden; 36 | text-overflow: ellipsis; 37 | } 38 | 39 | @media (max-width: 640.98px) { 40 | .top-row:not(.auth) { 41 | display: none; 42 | } 43 | 44 | .top-row.auth { 45 | justify-content: space-between; 46 | } 47 | 48 | .top-row ::deep a, .top-row ::deep .btn-link { 49 | margin-left: 0; 50 | } 51 | } 52 | 53 | @media (min-width: 641px) { 54 | .page { 55 | flex-direction: row; 56 | } 57 | 58 | .sidebar { 59 | width: 250px; 60 | height: 100vh; 61 | position: sticky; 62 | top: 0; 63 | } 64 | 65 | .top-row { 66 | position: sticky; 67 | top: 0; 68 | z-index: 1; 69 | } 70 | 71 | .top-row.auth ::deep a:first-child { 72 | flex: 1; 73 | text-align: right; 74 | width: 0; 75 | } 76 | 77 | .top-row, article { 78 | padding-left: 2rem !important; 79 | padding-right: 1.5rem !important; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo.Wasm/_Imports.razor: -------------------------------------------------------------------------------- 1 | @using System.Net.Http 2 | @using System.Net.Http.Json 3 | @using Microsoft.AspNetCore.Components.Forms 4 | @using Microsoft.AspNetCore.Components.Routing 5 | @using Microsoft.AspNetCore.Components.Web 6 | @using Microsoft.AspNetCore.Components.Web.Virtualization 7 | @using Microsoft.AspNetCore.Components.WebAssembly.Http 8 | @using Microsoft.JSInterop 9 | @using Blazor.JsonEditor.Demo.Wasm 10 | @using Blazor.JsonEditor.Demo.Wasm.Shared 11 | @using Blazor.JsonEditor.Component -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo.Wasm/wwwroot/css/app.css: -------------------------------------------------------------------------------- 1 | @import url('open-iconic/font/css/open-iconic-bootstrap.min.css'); 2 | 3 | html, body { 4 | font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; 5 | } 6 | 7 | h1:focus { 8 | outline: none; 9 | } 10 | 11 | a, .btn-link { 12 | color: #0071c1; 13 | } 14 | 15 | .btn-primary { 16 | color: #fff; 17 | background-color: #1b6ec2; 18 | border-color: #1861ac; 19 | } 20 | 21 | .btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus { 22 | box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem #258cfb; 23 | } 24 | 25 | .content { 26 | padding-top: 1.1rem; 27 | } 28 | 29 | .valid.modified:not([type=checkbox]) { 30 | outline: 1px solid #26b050; 31 | } 32 | 33 | .invalid { 34 | outline: 1px solid red; 35 | } 36 | 37 | .validation-message { 38 | color: red; 39 | } 40 | 41 | #blazor-error-ui { 42 | background: lightyellow; 43 | bottom: 0; 44 | box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2); 45 | display: none; 46 | left: 0; 47 | padding: 0.6rem 1.25rem 0.7rem 1.25rem; 48 | position: fixed; 49 | width: 100%; 50 | z-index: 1000; 51 | } 52 | 53 | #blazor-error-ui .dismiss { 54 | cursor: pointer; 55 | position: absolute; 56 | right: 0.75rem; 57 | top: 0.5rem; 58 | } 59 | 60 | .blazor-error-boundary { 61 | background: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTYiIGhlaWdodD0iNDkiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIG92ZXJmbG93PSJoaWRkZW4iPjxkZWZzPjxjbGlwUGF0aCBpZD0iY2xpcDAiPjxyZWN0IHg9IjIzNSIgeT0iNTEiIHdpZHRoPSI1NiIgaGVpZ2h0PSI0OSIvPjwvY2xpcFBhdGg+PC9kZWZzPjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMCkiIHRyYW5zZm9ybT0idHJhbnNsYXRlKC0yMzUgLTUxKSI+PHBhdGggZD0iTTI2My41MDYgNTFDMjY0LjcxNyA1MSAyNjUuODEzIDUxLjQ4MzcgMjY2LjYwNiA1Mi4yNjU4TDI2Ny4wNTIgNTIuNzk4NyAyNjcuNTM5IDUzLjYyODMgMjkwLjE4NSA5Mi4xODMxIDI5MC41NDUgOTIuNzk1IDI5MC42NTYgOTIuOTk2QzI5MC44NzcgOTMuNTEzIDI5MSA5NC4wODE1IDI5MSA5NC42NzgyIDI5MSA5Ny4wNjUxIDI4OS4wMzggOTkgMjg2LjYxNyA5OUwyNDAuMzgzIDk5QzIzNy45NjMgOTkgMjM2IDk3LjA2NTEgMjM2IDk0LjY3ODIgMjM2IDk0LjM3OTkgMjM2LjAzMSA5NC4wODg2IDIzNi4wODkgOTMuODA3MkwyMzYuMzM4IDkzLjAxNjIgMjM2Ljg1OCA5Mi4xMzE0IDI1OS40NzMgNTMuNjI5NCAyNTkuOTYxIDUyLjc5ODUgMjYwLjQwNyA1Mi4yNjU4QzI2MS4yIDUxLjQ4MzcgMjYyLjI5NiA1MSAyNjMuNTA2IDUxWk0yNjMuNTg2IDY2LjAxODNDMjYwLjczNyA2Ni4wMTgzIDI1OS4zMTMgNjcuMTI0NSAyNTkuMzEzIDY5LjMzNyAyNTkuMzEzIDY5LjYxMDIgMjU5LjMzMiA2OS44NjA4IDI1OS4zNzEgNzAuMDg4N0wyNjEuNzk1IDg0LjAxNjEgMjY1LjM4IDg0LjAxNjEgMjY3LjgyMSA2OS43NDc1QzI2Ny44NiA2OS43MzA5IDI2Ny44NzkgNjkuNTg3NyAyNjcuODc5IDY5LjMxNzkgMjY3Ljg3OSA2Ny4xMTgyIDI2Ni40NDggNjYuMDE4MyAyNjMuNTg2IDY2LjAxODNaTTI2My41NzYgODYuMDU0N0MyNjEuMDQ5IDg2LjA1NDcgMjU5Ljc4NiA4Ny4zMDA1IDI1OS43ODYgODkuNzkyMSAyNTkuNzg2IDkyLjI4MzcgMjYxLjA0OSA5My41Mjk1IDI2My41NzYgOTMuNTI5NSAyNjYuMTE2IDkzLjUyOTUgMjY3LjM4NyA5Mi4yODM3IDI2Ny4zODcgODkuNzkyMSAyNjcuMzg3IDg3LjMwMDUgMjY2LjExNiA4Ni4wNTQ3IDI2My41NzYgODYuMDU0N1oiIGZpbGw9IiNGRkU1MDAiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjwvZz48L3N2Zz4=) no-repeat 1rem/1.8rem, #b32121; 62 | padding: 1rem 1rem 1rem 3.7rem; 63 | color: white; 64 | } 65 | 66 | .blazor-error-boundary::after { 67 | content: "An error has occurred." 68 | } 69 | 70 | .loading-progress { 71 | position: relative; 72 | display: block; 73 | width: 8rem; 74 | height: 8rem; 75 | margin: 20vh auto 1rem auto; 76 | } 77 | 78 | .loading-progress circle { 79 | fill: none; 80 | stroke: #e0e0e0; 81 | stroke-width: 0.6rem; 82 | transform-origin: 50% 50%; 83 | transform: rotate(-90deg); 84 | } 85 | 86 | .loading-progress circle:last-child { 87 | stroke: #1b6ec2; 88 | stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%; 89 | transition: stroke-dasharray 0.05s ease-in-out; 90 | } 91 | 92 | .loading-progress-text { 93 | position: absolute; 94 | text-align: center; 95 | font-weight: bold; 96 | inset: calc(20vh + 3.25rem) 0 auto 0.2rem; 97 | } 98 | 99 | .loading-progress-text:after { 100 | content: var(--blazor-load-percentage-text, "Loading"); 101 | } 102 | -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo.Wasm/wwwroot/css/open-iconic/FONT-LICENSE: -------------------------------------------------------------------------------- 1 | SIL OPEN FONT LICENSE Version 1.1 2 | 3 | Copyright (c) 2014 Waybury 4 | 5 | PREAMBLE 6 | The goals of the Open Font License (OFL) are to stimulate worldwide 7 | development of collaborative font projects, to support the font creation 8 | efforts of academic and linguistic communities, and to provide a free and 9 | open framework in which fonts may be shared and improved in partnership 10 | with others. 11 | 12 | The OFL allows the licensed fonts to be used, studied, modified and 13 | redistributed freely as long as they are not sold by themselves. The 14 | fonts, including any derivative works, can be bundled, embedded, 15 | redistributed and/or sold with any software provided that any reserved 16 | names are not used by derivative works. The fonts and derivatives, 17 | however, cannot be released under any other type of license. The 18 | requirement for fonts to remain under this license does not apply 19 | to any document created using the fonts or their derivatives. 20 | 21 | DEFINITIONS 22 | "Font Software" refers to the set of files released by the Copyright 23 | Holder(s) under this license and clearly marked as such. This may 24 | include source files, build scripts and documentation. 25 | 26 | "Reserved Font Name" refers to any names specified as such after the 27 | copyright statement(s). 28 | 29 | "Original Version" refers to the collection of Font Software components as 30 | distributed by the Copyright Holder(s). 31 | 32 | "Modified Version" refers to any derivative made by adding to, deleting, 33 | or substituting -- in part or in whole -- any of the components of the 34 | Original Version, by changing formats or by porting the Font Software to a 35 | new environment. 36 | 37 | "Author" refers to any designer, engineer, programmer, technical 38 | writer or other person who contributed to the Font Software. 39 | 40 | PERMISSION & CONDITIONS 41 | Permission is hereby granted, free of charge, to any person obtaining 42 | a copy of the Font Software, to use, study, copy, merge, embed, modify, 43 | redistribute, and sell modified and unmodified copies of the Font 44 | Software, subject to the following conditions: 45 | 46 | 1) Neither the Font Software nor any of its individual components, 47 | in Original or Modified Versions, may be sold by itself. 48 | 49 | 2) Original or Modified Versions of the Font Software may be bundled, 50 | redistributed and/or sold with any software, provided that each copy 51 | contains the above copyright notice and this license. These can be 52 | included either as stand-alone text files, human-readable headers or 53 | in the appropriate machine-readable metadata fields within text or 54 | binary files as long as those fields can be easily viewed by the user. 55 | 56 | 3) No Modified Version of the Font Software may use the Reserved Font 57 | Name(s) unless explicit written permission is granted by the corresponding 58 | Copyright Holder. This restriction only applies to the primary font name as 59 | presented to the users. 60 | 61 | 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font 62 | Software shall not be used to promote, endorse or advertise any 63 | Modified Version, except to acknowledge the contribution(s) of the 64 | Copyright Holder(s) and the Author(s) or with their explicit written 65 | permission. 66 | 67 | 5) The Font Software, modified or unmodified, in part or in whole, 68 | must be distributed entirely under this license, and must not be 69 | distributed under any other license. The requirement for fonts to 70 | remain under this license does not apply to any document created 71 | using the Font Software. 72 | 73 | TERMINATION 74 | This license becomes null and void if any of the above conditions are 75 | not met. 76 | 77 | DISCLAIMER 78 | THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 79 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF 80 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT 81 | OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE 82 | COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 83 | INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL 84 | DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 85 | FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM 86 | OTHER DEALINGS IN THE FONT SOFTWARE. 87 | -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo.Wasm/wwwroot/css/open-iconic/ICON-LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Waybury 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo.Wasm/wwwroot/css/open-iconic/README.md: -------------------------------------------------------------------------------- 1 | [Open Iconic v1.1.1](https://github.com/iconic/open-iconic) 2 | =========== 3 | 4 | ### Open Iconic is the open source sibling of [Iconic](https://github.com/iconic/open-iconic). It is a hyper-legible collection of 223 icons with a tiny footprint—ready to use with Bootstrap and Foundation. [View the collection](https://github.com/iconic/open-iconic) 5 | 6 | 7 | 8 | ## What's in Open Iconic? 9 | 10 | * 223 icons designed to be legible down to 8 pixels 11 | * Super-light SVG files - 61.8 for the entire set 12 | * SVG sprite—the modern replacement for icon fonts 13 | * Webfont (EOT, OTF, SVG, TTF, WOFF), PNG and WebP formats 14 | * Webfont stylesheets (including versions for Bootstrap and Foundation) in CSS, LESS, SCSS and Stylus formats 15 | * PNG and WebP raster images in 8px, 16px, 24px, 32px, 48px and 64px. 16 | 17 | 18 | ## Getting Started 19 | 20 | #### For code samples and everything else you need to get started with Open Iconic, check out our [Icons](https://github.com/iconic/open-iconic) and [Reference](https://github.com/iconic/open-iconic) sections. 21 | 22 | ### General Usage 23 | 24 | #### Using Open Iconic's SVGs 25 | 26 | We like SVGs and we think they're the way to display icons on the web. Since Open Iconic are just basic SVGs, we suggest you display them like you would any other image (don't forget the `alt` attribute). 27 | 28 | ``` 29 | icon name 30 | ``` 31 | 32 | #### Using Open Iconic's SVG Sprite 33 | 34 | Open Iconic also comes in a SVG sprite which allows you to display all the icons in the set with a single request. It's like an icon font, without being a hack. 35 | 36 | Adding an icon from an SVG sprite is a little different than what you're used to, but it's still a piece of cake. *Tip: To make your icons easily style able, we suggest adding a general class to the* `` *tag and a unique class name for each different icon in the* `` *tag.* 37 | 38 | ``` 39 | 40 | 41 | 42 | ``` 43 | 44 | Sizing icons only needs basic CSS. All the icons are in a square format, so just set the `` tag with equal width and height dimensions. 45 | 46 | ``` 47 | .icon { 48 | width: 16px; 49 | height: 16px; 50 | } 51 | ``` 52 | 53 | Coloring icons is even easier. All you need to do is set the `fill` rule on the `` tag. 54 | 55 | ``` 56 | .icon-account-login { 57 | fill: #f00; 58 | } 59 | ``` 60 | 61 | To learn more about SVG Sprites, read [Chris Coyier's guide](http://css-tricks.com/svg-sprites-use-better-icon-fonts/). 62 | 63 | #### Using Open Iconic's Icon Font... 64 | 65 | 66 | ##### …with Bootstrap 67 | 68 | You can find our Bootstrap stylesheets in `font/css/open-iconic-bootstrap.{css, less, scss, styl}` 69 | 70 | 71 | ``` 72 | 73 | ``` 74 | 75 | 76 | ``` 77 | 78 | ``` 79 | 80 | ##### …with Foundation 81 | 82 | You can find our Foundation stylesheets in `font/css/open-iconic-foundation.{css, less, scss, styl}` 83 | 84 | ``` 85 | 86 | ``` 87 | 88 | 89 | ``` 90 | 91 | ``` 92 | 93 | ##### …on its own 94 | 95 | You can find our default stylesheets in `font/css/open-iconic.{css, less, scss, styl}` 96 | 97 | ``` 98 | 99 | ``` 100 | 101 | ``` 102 | 103 | ``` 104 | 105 | 106 | ## License 107 | 108 | ### Icons 109 | 110 | All code (including SVG markup) is under the [MIT License](http://opensource.org/licenses/MIT). 111 | 112 | ### Fonts 113 | 114 | All fonts are under the [SIL Licensed](http://scripts.sil.org/cms/scripts/page.php?item_id=OFL_web). 115 | -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo.Wasm/wwwroot/css/open-iconic/font/css/open-iconic-bootstrap.min.css: -------------------------------------------------------------------------------- 1 | @font-face{font-family:Icons;src:url(../fonts/open-iconic.eot);src:url(../fonts/open-iconic.eot?#iconic-sm) format('embedded-opentype'),url(../fonts/open-iconic.woff) format('woff'),url(../fonts/open-iconic.ttf) format('truetype'),url(../fonts/open-iconic.otf) format('opentype'),url(../fonts/open-iconic.svg#iconic-sm) format('svg');font-weight:400;font-style:normal}.oi{position:relative;top:1px;display:inline-block;speak:none;font-family:Icons;font-style:normal;font-weight:400;line-height:1;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.oi:empty:before{width:1em;text-align:center;box-sizing:content-box}.oi.oi-align-center:before{text-align:center}.oi.oi-align-left:before{text-align:left}.oi.oi-align-right:before{text-align:right}.oi.oi-flip-horizontal:before{-webkit-transform:scale(-1,1);-ms-transform:scale(-1,1);transform:scale(-1,1)}.oi.oi-flip-vertical:before{-webkit-transform:scale(1,-1);-ms-transform:scale(-1,1);transform:scale(1,-1)}.oi.oi-flip-horizontal-vertical:before{-webkit-transform:scale(-1,-1);-ms-transform:scale(-1,1);transform:scale(-1,-1)}.oi-account-login:before{content:'\e000'}.oi-account-logout:before{content:'\e001'}.oi-action-redo:before{content:'\e002'}.oi-action-undo:before{content:'\e003'}.oi-align-center:before{content:'\e004'}.oi-align-left:before{content:'\e005'}.oi-align-right:before{content:'\e006'}.oi-aperture:before{content:'\e007'}.oi-arrow-bottom:before{content:'\e008'}.oi-arrow-circle-bottom:before{content:'\e009'}.oi-arrow-circle-left:before{content:'\e00a'}.oi-arrow-circle-right:before{content:'\e00b'}.oi-arrow-circle-top:before{content:'\e00c'}.oi-arrow-left:before{content:'\e00d'}.oi-arrow-right:before{content:'\e00e'}.oi-arrow-thick-bottom:before{content:'\e00f'}.oi-arrow-thick-left:before{content:'\e010'}.oi-arrow-thick-right:before{content:'\e011'}.oi-arrow-thick-top:before{content:'\e012'}.oi-arrow-top:before{content:'\e013'}.oi-audio-spectrum:before{content:'\e014'}.oi-audio:before{content:'\e015'}.oi-badge:before{content:'\e016'}.oi-ban:before{content:'\e017'}.oi-bar-chart:before{content:'\e018'}.oi-basket:before{content:'\e019'}.oi-battery-empty:before{content:'\e01a'}.oi-battery-full:before{content:'\e01b'}.oi-beaker:before{content:'\e01c'}.oi-bell:before{content:'\e01d'}.oi-bluetooth:before{content:'\e01e'}.oi-bold:before{content:'\e01f'}.oi-bolt:before{content:'\e020'}.oi-book:before{content:'\e021'}.oi-bookmark:before{content:'\e022'}.oi-box:before{content:'\e023'}.oi-briefcase:before{content:'\e024'}.oi-british-pound:before{content:'\e025'}.oi-browser:before{content:'\e026'}.oi-brush:before{content:'\e027'}.oi-bug:before{content:'\e028'}.oi-bullhorn:before{content:'\e029'}.oi-calculator:before{content:'\e02a'}.oi-calendar:before{content:'\e02b'}.oi-camera-slr:before{content:'\e02c'}.oi-caret-bottom:before{content:'\e02d'}.oi-caret-left:before{content:'\e02e'}.oi-caret-right:before{content:'\e02f'}.oi-caret-top:before{content:'\e030'}.oi-cart:before{content:'\e031'}.oi-chat:before{content:'\e032'}.oi-check:before{content:'\e033'}.oi-chevron-bottom:before{content:'\e034'}.oi-chevron-left:before{content:'\e035'}.oi-chevron-right:before{content:'\e036'}.oi-chevron-top:before{content:'\e037'}.oi-circle-check:before{content:'\e038'}.oi-circle-x:before{content:'\e039'}.oi-clipboard:before{content:'\e03a'}.oi-clock:before{content:'\e03b'}.oi-cloud-download:before{content:'\e03c'}.oi-cloud-upload:before{content:'\e03d'}.oi-cloud:before{content:'\e03e'}.oi-cloudy:before{content:'\e03f'}.oi-code:before{content:'\e040'}.oi-cog:before{content:'\e041'}.oi-collapse-down:before{content:'\e042'}.oi-collapse-left:before{content:'\e043'}.oi-collapse-right:before{content:'\e044'}.oi-collapse-up:before{content:'\e045'}.oi-command:before{content:'\e046'}.oi-comment-square:before{content:'\e047'}.oi-compass:before{content:'\e048'}.oi-contrast:before{content:'\e049'}.oi-copywriting:before{content:'\e04a'}.oi-credit-card:before{content:'\e04b'}.oi-crop:before{content:'\e04c'}.oi-dashboard:before{content:'\e04d'}.oi-data-transfer-download:before{content:'\e04e'}.oi-data-transfer-upload:before{content:'\e04f'}.oi-delete:before{content:'\e050'}.oi-dial:before{content:'\e051'}.oi-document:before{content:'\e052'}.oi-dollar:before{content:'\e053'}.oi-double-quote-sans-left:before{content:'\e054'}.oi-double-quote-sans-right:before{content:'\e055'}.oi-double-quote-serif-left:before{content:'\e056'}.oi-double-quote-serif-right:before{content:'\e057'}.oi-droplet:before{content:'\e058'}.oi-eject:before{content:'\e059'}.oi-elevator:before{content:'\e05a'}.oi-ellipses:before{content:'\e05b'}.oi-envelope-closed:before{content:'\e05c'}.oi-envelope-open:before{content:'\e05d'}.oi-euro:before{content:'\e05e'}.oi-excerpt:before{content:'\e05f'}.oi-expand-down:before{content:'\e060'}.oi-expand-left:before{content:'\e061'}.oi-expand-right:before{content:'\e062'}.oi-expand-up:before{content:'\e063'}.oi-external-link:before{content:'\e064'}.oi-eye:before{content:'\e065'}.oi-eyedropper:before{content:'\e066'}.oi-file:before{content:'\e067'}.oi-fire:before{content:'\e068'}.oi-flag:before{content:'\e069'}.oi-flash:before{content:'\e06a'}.oi-folder:before{content:'\e06b'}.oi-fork:before{content:'\e06c'}.oi-fullscreen-enter:before{content:'\e06d'}.oi-fullscreen-exit:before{content:'\e06e'}.oi-globe:before{content:'\e06f'}.oi-graph:before{content:'\e070'}.oi-grid-four-up:before{content:'\e071'}.oi-grid-three-up:before{content:'\e072'}.oi-grid-two-up:before{content:'\e073'}.oi-hard-drive:before{content:'\e074'}.oi-header:before{content:'\e075'}.oi-headphones:before{content:'\e076'}.oi-heart:before{content:'\e077'}.oi-home:before{content:'\e078'}.oi-image:before{content:'\e079'}.oi-inbox:before{content:'\e07a'}.oi-infinity:before{content:'\e07b'}.oi-info:before{content:'\e07c'}.oi-italic:before{content:'\e07d'}.oi-justify-center:before{content:'\e07e'}.oi-justify-left:before{content:'\e07f'}.oi-justify-right:before{content:'\e080'}.oi-key:before{content:'\e081'}.oi-laptop:before{content:'\e082'}.oi-layers:before{content:'\e083'}.oi-lightbulb:before{content:'\e084'}.oi-link-broken:before{content:'\e085'}.oi-link-intact:before{content:'\e086'}.oi-list-rich:before{content:'\e087'}.oi-list:before{content:'\e088'}.oi-location:before{content:'\e089'}.oi-lock-locked:before{content:'\e08a'}.oi-lock-unlocked:before{content:'\e08b'}.oi-loop-circular:before{content:'\e08c'}.oi-loop-square:before{content:'\e08d'}.oi-loop:before{content:'\e08e'}.oi-magnifying-glass:before{content:'\e08f'}.oi-map-marker:before{content:'\e090'}.oi-map:before{content:'\e091'}.oi-media-pause:before{content:'\e092'}.oi-media-play:before{content:'\e093'}.oi-media-record:before{content:'\e094'}.oi-media-skip-backward:before{content:'\e095'}.oi-media-skip-forward:before{content:'\e096'}.oi-media-step-backward:before{content:'\e097'}.oi-media-step-forward:before{content:'\e098'}.oi-media-stop:before{content:'\e099'}.oi-medical-cross:before{content:'\e09a'}.oi-menu:before{content:'\e09b'}.oi-microphone:before{content:'\e09c'}.oi-minus:before{content:'\e09d'}.oi-monitor:before{content:'\e09e'}.oi-moon:before{content:'\e09f'}.oi-move:before{content:'\e0a0'}.oi-musical-note:before{content:'\e0a1'}.oi-paperclip:before{content:'\e0a2'}.oi-pencil:before{content:'\e0a3'}.oi-people:before{content:'\e0a4'}.oi-person:before{content:'\e0a5'}.oi-phone:before{content:'\e0a6'}.oi-pie-chart:before{content:'\e0a7'}.oi-pin:before{content:'\e0a8'}.oi-play-circle:before{content:'\e0a9'}.oi-plus:before{content:'\e0aa'}.oi-power-standby:before{content:'\e0ab'}.oi-print:before{content:'\e0ac'}.oi-project:before{content:'\e0ad'}.oi-pulse:before{content:'\e0ae'}.oi-puzzle-piece:before{content:'\e0af'}.oi-question-mark:before{content:'\e0b0'}.oi-rain:before{content:'\e0b1'}.oi-random:before{content:'\e0b2'}.oi-reload:before{content:'\e0b3'}.oi-resize-both:before{content:'\e0b4'}.oi-resize-height:before{content:'\e0b5'}.oi-resize-width:before{content:'\e0b6'}.oi-rss-alt:before{content:'\e0b7'}.oi-rss:before{content:'\e0b8'}.oi-script:before{content:'\e0b9'}.oi-share-boxed:before{content:'\e0ba'}.oi-share:before{content:'\e0bb'}.oi-shield:before{content:'\e0bc'}.oi-signal:before{content:'\e0bd'}.oi-signpost:before{content:'\e0be'}.oi-sort-ascending:before{content:'\e0bf'}.oi-sort-descending:before{content:'\e0c0'}.oi-spreadsheet:before{content:'\e0c1'}.oi-star:before{content:'\e0c2'}.oi-sun:before{content:'\e0c3'}.oi-tablet:before{content:'\e0c4'}.oi-tag:before{content:'\e0c5'}.oi-tags:before{content:'\e0c6'}.oi-target:before{content:'\e0c7'}.oi-task:before{content:'\e0c8'}.oi-terminal:before{content:'\e0c9'}.oi-text:before{content:'\e0ca'}.oi-thumb-down:before{content:'\e0cb'}.oi-thumb-up:before{content:'\e0cc'}.oi-timer:before{content:'\e0cd'}.oi-transfer:before{content:'\e0ce'}.oi-trash:before{content:'\e0cf'}.oi-underline:before{content:'\e0d0'}.oi-vertical-align-bottom:before{content:'\e0d1'}.oi-vertical-align-center:before{content:'\e0d2'}.oi-vertical-align-top:before{content:'\e0d3'}.oi-video:before{content:'\e0d4'}.oi-volume-high:before{content:'\e0d5'}.oi-volume-low:before{content:'\e0d6'}.oi-volume-off:before{content:'\e0d7'}.oi-warning:before{content:'\e0d8'}.oi-wifi:before{content:'\e0d9'}.oi-wrench:before{content:'\e0da'}.oi-x:before{content:'\e0db'}.oi-yen:before{content:'\e0dc'}.oi-zoom-in:before{content:'\e0dd'}.oi-zoom-out:before{content:'\e0de'} -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo.Wasm/wwwroot/css/open-iconic/font/fonts/open-iconic.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joghyrt/Blazor.JsonEditor/8cd1d6ad3a2fe423b6f5bae4517999625ebcc5f0/Blazor.JsonEditor.Demo.Wasm/wwwroot/css/open-iconic/font/fonts/open-iconic.eot -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo.Wasm/wwwroot/css/open-iconic/font/fonts/open-iconic.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joghyrt/Blazor.JsonEditor/8cd1d6ad3a2fe423b6f5bae4517999625ebcc5f0/Blazor.JsonEditor.Demo.Wasm/wwwroot/css/open-iconic/font/fonts/open-iconic.otf -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo.Wasm/wwwroot/css/open-iconic/font/fonts/open-iconic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joghyrt/Blazor.JsonEditor/8cd1d6ad3a2fe423b6f5bae4517999625ebcc5f0/Blazor.JsonEditor.Demo.Wasm/wwwroot/css/open-iconic/font/fonts/open-iconic.ttf -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo.Wasm/wwwroot/css/open-iconic/font/fonts/open-iconic.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joghyrt/Blazor.JsonEditor/8cd1d6ad3a2fe423b6f5bae4517999625ebcc5f0/Blazor.JsonEditor.Demo.Wasm/wwwroot/css/open-iconic/font/fonts/open-iconic.woff -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo.Wasm/wwwroot/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joghyrt/Blazor.JsonEditor/8cd1d6ad3a2fe423b6f5bae4517999625ebcc5f0/Blazor.JsonEditor.Demo.Wasm/wwwroot/favicon.png -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo.Wasm/wwwroot/icon-192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joghyrt/Blazor.JsonEditor/8cd1d6ad3a2fe423b6f5bae4517999625ebcc5f0/Blazor.JsonEditor.Demo.Wasm/wwwroot/icon-192.png -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo.Wasm/wwwroot/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Blazor.JsonEditor.Demo.Wasm 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 |
23 |
24 | 25 |
26 | An unhandled error has occurred. 27 | Reload 28 | 🗙 29 |
30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo.Wasm/wwwroot/sample-data/weather.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "date": "2022-01-06", 4 | "temperatureC": 1, 5 | "summary": "Freezing" 6 | }, 7 | { 8 | "date": "2022-01-07", 9 | "temperatureC": 14, 10 | "summary": "Bracing" 11 | }, 12 | { 13 | "date": "2022-01-08", 14 | "temperatureC": -13, 15 | "summary": "Freezing" 16 | }, 17 | { 18 | "date": "2022-01-09", 19 | "temperatureC": -16, 20 | "summary": "Balmy" 21 | }, 22 | { 23 | "date": "2022-01-10", 24 | "temperatureC": -2, 25 | "summary": "Chilly" 26 | } 27 | ] 28 | -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo/App.razor: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | Not found 8 | 9 |

Sorry, there's nothing at this address.

10 |
11 |
12 |
13 | -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo/Blazor.JsonEditor.Demo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net7.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo/Blazor.JsonEditor.Demo.csproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | https 5 | 6 | -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo/Component/JsonItemCustomEditor.razor: -------------------------------------------------------------------------------- 1 | @using System.Text.Json 2 | 3 | 4 | 15 | 16 | @if (IsShowEditor) 17 | { 18 | 19 | 20 |
21 | @if (ValidationMessage != null) 22 | { 23 |
24 | @ValidationMessage 25 |
26 | } 27 |
28 |
29 | 30 | 31 | 32 |
33 |
34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 |
45 |
46 |
47 | @if (JsonItem.ValueKind != JsonValueKind.Undefined) 48 | { 49 | 50 | } 51 | @if (JsonItem.ValueKind == JsonValueKind.String) 52 | { 53 | 54 | 55 | } 56 | else if(JsonItem.ValueKind == JsonValueKind.Array) 57 | { 58 |
59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 |
68 | 69 | 70 | 71 | } 72 | else if (JsonItem.ValueKind == JsonValueKind.Number) 73 | { 74 | 75 | 76 | } 77 | else if (JsonItem.ValueKind == JsonValueKind.True) 78 | { 79 | 80 | 81 | 82 | 83 | 84 | 85 | } 86 | else if (JsonItem.ValueKind == JsonValueKind.False && KeyValues?.Count > 0) 87 | { 88 | 89 | 90 | @foreach (var kv in KeyValues) 91 | { 92 | 93 | } 94 | 95 | 96 | } 97 |
98 |
99 | 102 | @if (JsonItemToEdit != null) 103 | { 104 | 105 | 108 | 109 | } 110 |
111 |
112 |
113 | } -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo/Component/JsonItemCustomEditor.razor.cs: -------------------------------------------------------------------------------- 1 | using System.Globalization; 2 | using System.Text.Json; 3 | using System.Text.Json.Nodes; 4 | using Blazor.JsonEditor.Helper; 5 | using Blazor.JsonEditor.Model; 6 | using Microsoft.AspNetCore.Components; 7 | 8 | namespace Blazor.JsonEditor.Demo.Component 9 | { 10 | public partial class JsonItemCustomEditor 11 | { 12 | [Parameter] 13 | public JsonObject? JsonObject { get; set; } 14 | 15 | [Parameter] 16 | public EventCallback JsonObjectChanged { get; set; } 17 | 18 | [Parameter] 19 | public Dictionary? KeyValues { get; set; } 20 | 21 | [Parameter] 22 | public KeyValuePair? JsonItemToEdit { get; set; } 23 | 24 | private bool IsShowEditor; 25 | 26 | private bool IsEditMode 27 | { 28 | get 29 | { 30 | return JsonItemToEdit != null; 31 | } 32 | } 33 | 34 | private string? ValidationMessage; 35 | 36 | private JsonItem? JsonItem { get; set; } 37 | 38 | private void ToggleEditor() 39 | { 40 | IsShowEditor = !IsShowEditor; 41 | ValidationMessage = null; 42 | StateHasChanged(); 43 | } 44 | 45 | protected override void OnParametersSet() 46 | { 47 | JsonItem = new JsonItem(); 48 | if (JsonItemToEdit == null) 49 | { 50 | JsonItem.ValueKind = JsonValueKind.Undefined; 51 | return; 52 | } 53 | 54 | this.ProcessEditMode(); 55 | } 56 | 57 | private void ProcessEditMode() 58 | { 59 | JsonItem.PropertyName = JsonItemToEdit.Value.Key; 60 | 61 | var jsonObjectValue = JsonObject?.FirstOrDefault(x => x.Key.Equals(JsonItemToEdit.Value.Key)).Value; 62 | 63 | var jsonElement = new JsonElement(); 64 | 65 | if (jsonObjectValue != null) 66 | { 67 | jsonElement = JsonSerializer.Deserialize(jsonObjectValue.ToJsonString()); 68 | JsonItem.ValueKind = jsonElement.ValueKind; 69 | } 70 | 71 | switch (jsonElement.ValueKind) 72 | { 73 | case JsonValueKind.String: 74 | JsonItem.Value = jsonElement.ToString(); 75 | break; 76 | case JsonValueKind.Number: 77 | if (!double.TryParse(jsonElement.ToString(), CultureInfo.InvariantCulture, out var numericValue)) 78 | { 79 | throw new ArgumentException($"Not able to parse value {jsonElement.ToString()} to double."); 80 | } 81 | 82 | JsonItem.NumericValue = numericValue; 83 | break; 84 | case JsonValueKind.True: 85 | JsonItem.Value = "true"; 86 | break; 87 | case JsonValueKind.False: 88 | JsonItem.Value = "false"; 89 | JsonItem.ValueKind = JsonValueKind.True; 90 | break; 91 | case JsonValueKind.Array: 92 | { 93 | var arrayValue = jsonElement.ToString(); 94 | JsonItem.Value = arrayValue.Substring(1, arrayValue.Length - 2); 95 | break; 96 | } 97 | case JsonValueKind.Null: 98 | JsonItem.ValueKind = JsonValueKind.Undefined; 99 | break; 100 | } 101 | } 102 | 103 | private async Task SaveNodeAsync() 104 | { 105 | try 106 | { 107 | ValidationMessage = null; 108 | 109 | if (JsonItem == null) 110 | { 111 | ToggleEditor(); 112 | return; 113 | } 114 | 115 | if (!this.IsEditMode) 116 | { 117 | this.AddNode(); 118 | } 119 | else 120 | { 121 | this.EditNode(); 122 | } 123 | 124 | await JsonObjectChanged.InvokeAsync(JsonObject); 125 | JsonItem = null; 126 | ToggleEditor(); 127 | } 128 | catch (ArgumentException ex) 129 | { 130 | ValidationMessage = ex.Message; 131 | } 132 | } 133 | 134 | private void AddNode() 135 | { 136 | if (JsonItem == null || string.IsNullOrEmpty(JsonItem.PropertyName)) 137 | { 138 | return; 139 | } 140 | 141 | if (JsonObject == null) 142 | { 143 | JsonObject = new JsonObject(); 144 | } 145 | 146 | JsonHelper.AddNodeValue(JsonObject, JsonItem); 147 | } 148 | 149 | private void EditNode() 150 | { 151 | if (JsonObject == null) 152 | { 153 | return; 154 | } 155 | 156 | if (JsonItem == null) 157 | { 158 | return; 159 | } 160 | 161 | if (JsonItemToEdit == null) 162 | { 163 | return; 164 | } 165 | 166 | JsonHelper.EditNodeValue(JsonObject, JsonItem, JsonItemToEdit.Value.Key); 167 | } 168 | 169 | private async Task RemoveNode() 170 | { 171 | if (this.JsonObject == null) 172 | { 173 | return; 174 | } 175 | 176 | if (this.JsonItemToEdit == null) 177 | { 178 | return; 179 | } 180 | 181 | this.JsonObject.Remove(this.JsonItemToEdit.Value.Key); 182 | await JsonObjectChanged.InvokeAsync(JsonObject); 183 | ToggleEditor(); 184 | this.StateHasChanged(); 185 | } 186 | } 187 | } -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo/Component/JsonItemCustomEditor.razor.css: -------------------------------------------------------------------------------- 1 | .json-content { 2 | padding: 5px; 3 | border: 1px solid #ccc; 4 | } 5 | 6 | .json-object-body { 7 | margin-left:20px; 8 | min-width:500px 9 | } 10 | 11 | .json-object-body-empty { 12 | margin-left:20px; 13 | } 14 | 15 | .json-property-name { 16 | padding: 3px; 17 | color: brown; 18 | } 19 | 20 | .json-value-content { 21 | padding: 3px; 22 | font-style: italic; 23 | } 24 | 25 | .json-button { 26 | padding: 4px; 27 | border-radius: 4px; 28 | border: 1px solid #ccc; 29 | line-height: 1px; 30 | font-family: 'Wingdings 2'; 31 | font-size: 10px; 32 | } 33 | 34 | .json-button-submit { 35 | padding: 8px; 36 | border-radius: 5px; 37 | border: 1px solid #ccc; 38 | line-height: 1px; 39 | font-family: 'Wingdings 2'; 40 | font-size: 14px; 41 | width: 110px; 42 | color: white; 43 | background-color: green; 44 | margin-right: 10px; 45 | } 46 | 47 | .json-close-button{ 48 | padding: 8px; 49 | border-radius: 5px; 50 | border: 1px solid #ccc; 51 | line-height: 1px; 52 | font-family: 'Wingdings 2'; 53 | font-size: 14px; 54 | width: 110px; 55 | color: white; 56 | background-color: grey; 57 | margin-right: 10px; 58 | } 59 | 60 | .json-button-delete { 61 | padding: 8px; 62 | border-radius: 5px; 63 | border: 1px solid #ccc; 64 | line-height: 1px; 65 | font-family: 'Wingdings 2'; 66 | font-size: 14px; 67 | width: 110px; 68 | color: white; 69 | background-color: darkred; 70 | } 71 | 72 | .json-button-danger { 73 | color: red; 74 | } 75 | 76 | .json-input-text { 77 | padding: 2px 5px; 78 | border-radius: 5px; 79 | border: 1px solid #ccc; 80 | width: 100%; 81 | line-height: 1.2em; 82 | } 83 | 84 | .json-validation-error { 85 | color: red; 86 | } 87 | 88 | .json-value-string { 89 | color: darkgoldenrod; 90 | } 91 | 92 | .json-value-number { 93 | color: blueviolet; 94 | } 95 | 96 | .json-value-array { 97 | color: darkgreen; 98 | } 99 | 100 | .json-new-item-form-container { 101 | background: #fff; 102 | border: 1px solid #808080; 103 | padding: 10px; 104 | border-radius: 5px; 105 | box-shadow: 3px 3px 10px #1d1d1d; 106 | width: 400px; 107 | } 108 | 109 | .json-input-group { 110 | display: flex; 111 | flex-direction: column; 112 | } 113 | 114 | .json-input-group > label { 115 | font-style: italic; 116 | font-weight: 600; 117 | } 118 | 119 | .json-button-container { 120 | margin-top: 20px; 121 | display: flex; 122 | width: 100%; 123 | } -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo/Component/JsonItemCustomView.razor: -------------------------------------------------------------------------------- 1 | @using System.Text.Json 2 | @using System.Text.Json.Nodes 3 | @using Blazor.JsonEditor.Helper 4 | @using Blazor.JsonEditor.Component 5 | 6 | @if (JsonHelper.IsInJsonValueKind(JsonItem, new List { JsonValueKind.Number, JsonValueKind.True, JsonValueKind.False })) 7 | { 8 | "@JsonItem.Key" 9 | 10 | @JsonItem.Value.ToString() 11 | } 12 | else if (JsonItem.Value == null) 13 | { 14 | "@JsonItem.Key" 15 | 16 | null 17 | } 18 | else if (JsonHelper.IsInJsonValueKind(JsonItem, new List { JsonValueKind.String })) 19 | { 20 | "@JsonItem.Key" 21 | 22 | "@JsonItem.Value.ToString()" 23 | } 24 | else if (JsonHelper.IsInJsonValueKind(JsonItem, new List { JsonValueKind.Array })) 25 | { 26 | "@JsonItem.Key" 27 | : 28 | 29 | var isObjectArray = JsonItem.Value.AsArray().Any() && JsonItem.Value.AsArray().First() is JsonObject; 30 | 31 | if (isObjectArray) 32 | { 33 | [ 34 |
35 | var jsonArray = JsonItem.Value.AsArray(); 36 | var latestValue = jsonArray.Last(); 37 | for (var i = 0; i < jsonArray.Count; i++) 38 | { 39 | var value = jsonArray[i]; 40 | var index = i; 41 | 42 | { 43 | 50 | 51 | @if (value.Equals(latestValue)) 52 | { 53 | } 54 | } 55 | else 56 | { 57 | }, 58 | } 59 |
60 |
61 | } 62 | 63 | 64 | 65 | ] 66 | } 67 | else 68 | { 69 | @JsonItem.Value.ToJsonString() 70 | } 71 | } -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo/Component/JsonItemCustomView.razor.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json.Nodes; 2 | using Microsoft.AspNetCore.Components; 3 | 4 | namespace Blazor.JsonEditor.Demo.Component 5 | { 6 | public partial class JsonItemCustomView 7 | { 8 | [Parameter] 9 | public KeyValuePair JsonItem { get; set; } 10 | 11 | [Parameter] 12 | public JsonObject? JsonObject { get; set; } 13 | 14 | [Parameter] 15 | public EventCallback ValueChanged { get; set; } 16 | 17 | [Parameter] 18 | public Dictionary? KeyValues { get; set; } 19 | 20 | [Parameter] 21 | public bool AllowEdit { get; set; } = true; 22 | 23 | [Parameter] 24 | public Type? CustomEditor { get; set; } 25 | 26 | [Parameter] 27 | public Type? CustomItemView { get; set; } 28 | 29 | [Parameter] 30 | public Type? CustomObjectView { get; set; } 31 | 32 | private void JsonObjectUpdated(int index, string value) 33 | { 34 | var jsonValue = JsonItem.Value as JsonArray; 35 | 36 | jsonValue[index] = JsonNode.Parse(value); 37 | 38 | JsonItem = new KeyValuePair(JsonItem.Key, jsonValue); 39 | 40 | ValueChanged.InvokeAsync(JsonItem.Value.ToJsonString()); 41 | } 42 | } 43 | } 44 | 45 | -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo/Component/JsonItemCustomView.razor.css: -------------------------------------------------------------------------------- 1 | .json-property-name { 2 | padding: 3px; 3 | color: brown; 4 | } 5 | 6 | .json-content { 7 | padding: 5px; 8 | border: 1px solid #ccc; 9 | } 10 | 11 | .json-value-content { 12 | padding: 3px; 13 | font-style: italic; 14 | } 15 | 16 | .json-value-string { 17 | color: darkgoldenrod; 18 | } 19 | 20 | .json-value-number { 21 | color: blueviolet; 22 | } 23 | 24 | .json-value-array { 25 | color: darkgreen; 26 | } -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo/Component/JsonObjectCustomView.razor: -------------------------------------------------------------------------------- 1 | @using Blazor.JsonEditor.Component 2 | 3 | "@JsonItem.Key" 4 | 5 | 6 | 7 | 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo/Component/JsonObjectCustomView.razor.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json.Nodes; 2 | using Microsoft.AspNetCore.Components; 3 | 4 | namespace Blazor.JsonEditor.Demo.Component 5 | { 6 | public partial class JsonObjectCustomView 7 | { 8 | 9 | [Parameter] 10 | public KeyValuePair JsonItem { get; set; } 11 | 12 | [Parameter] 13 | public JsonObject? JsonObject { get; set; } 14 | 15 | [Parameter] 16 | public EventCallback ValueChanged { get; set; } 17 | 18 | [Parameter] 19 | public Dictionary? KeyValues { get; set; } 20 | 21 | [Parameter] 22 | public bool AllowEdit { get; set; } = true; 23 | 24 | [Parameter] 25 | public Type? CustomEditor { get; set; } 26 | 27 | [Parameter] 28 | public Type? CustomItemView { get; set; } 29 | 30 | [Parameter] 31 | public Type? CustomObjectView { get; set; } 32 | } 33 | } 34 | 35 | -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo/Component/JsonObjectCustomView.razor.css: -------------------------------------------------------------------------------- 1 | .json-property-name { 2 | padding: 3px; 3 | color: brown; 4 | } -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo/Data/WeatherForecast.cs: -------------------------------------------------------------------------------- 1 | namespace Blazor.JsonEditor.Demo.Data 2 | { 3 | public class WeatherForecast 4 | { 5 | public DateOnly Date { get; set; } 6 | 7 | public int TemperatureC { get; set; } 8 | 9 | public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); 10 | 11 | public string? Summary { get; set; } 12 | } 13 | } -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo/Data/WeatherForecastService.cs: -------------------------------------------------------------------------------- 1 | namespace Blazor.JsonEditor.Demo.Data 2 | { 3 | public class WeatherForecastService 4 | { 5 | private static readonly string[] Summaries = new[] 6 | { 7 | "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" 8 | }; 9 | 10 | public Task GetForecastAsync(DateOnly startDate) 11 | { 12 | return Task.FromResult(Enumerable.Range(1, 5).Select(index => new WeatherForecast 13 | { 14 | Date = startDate.AddDays(index), 15 | TemperatureC = Random.Shared.Next(-20, 55), 16 | Summary = Summaries[Random.Shared.Next(Summaries.Length)] 17 | }).ToArray()); 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo/Model/IndexModel.cs: -------------------------------------------------------------------------------- 1 | namespace Blazor.JsonEditor.Demo.Model 2 | { 3 | public class IndexModel 4 | { 5 | public string Json { get; set; } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo/Pages/Index.razor: -------------------------------------------------------------------------------- 1 | @page "/" 2 | 3 | @using Blazor.JsonEditor.Component 4 | @using Blazor.JsonEditor.Demo.Component 5 | @using Blazor.JsonEditor.Demo.Model 6 | 7 | Index 8 | 9 |
10 |

Json Viewer

11 | You can easily make json viewer from json editor. Just pass AllowEdit="false" 12 | 13 | 14 | 15 |
16 |
17 |

Json Editor

18 | Here is json editor. If you find any bugs or you would like to see any improvements please contact me here 19 | 20 | 21 | 22 |
23 | @*
*@ 24 | @*

Json Editor with custom components

*@ 25 | @* Here we use custom Edit template for Json node and customer view template for Item and Object. You can create your own component and use it as editor template. More information in documentation here *@ 26 | @* *@ 27 | @* *@ 28 | @* *@ 29 | @*
*@ 30 | 31 | 32 | -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo/Pages/Index.razor.cs: -------------------------------------------------------------------------------- 1 | using Blazor.JsonEditor.Demo.Model; 2 | 3 | namespace Blazor.JsonEditor.Demo.Pages 4 | { 5 | public partial class Index 6 | { 7 | private IndexModel DemoJson { get; set; } = new() 8 | { 9 | Json = 10 | "{\"Nullable\": null, \"String\": \"random\", \"Number\": 1, \"Array\": [1,2,3], \"True\": true, \"False\": false, \"Object\": { \"Nullable\": null, \"String\": \"random\", \"Number\": 1, \"Array\": [1,2,3], \"True\": true, \"False\": false, \"ObjectsArray\": [ { \"Name\":\"First Object\", \"Property\": 1}, {\"Name\":\"Second Object\", \"Property\": 1}]}}" 11 | 12 | }; 13 | } 14 | } -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo/Pages/Index.razor.css: -------------------------------------------------------------------------------- 1 | .section-container { 2 | margin: 10px 10px 30px; 3 | } -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo/Pages/_Host.cshtml: -------------------------------------------------------------------------------- 1 | @page "/" 2 | @using Microsoft.AspNetCore.Components.Web 3 | @namespace Blazor.JsonEditor.Demo.Pages 4 | @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | An error has occurred. This application may no longer respond until reloaded. 25 | 26 | 27 | An unhandled exception has occurred. See browser dev tools for details. 28 | 29 | Reload 30 | 🗙 31 |
32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo/Program.cs: -------------------------------------------------------------------------------- 1 | using Blazor.JsonEditor.Demo.Data; 2 | using Microsoft.AspNetCore.Components; 3 | using Microsoft.AspNetCore.Components.Web; 4 | 5 | var builder = WebApplication.CreateBuilder(args); 6 | 7 | // Add services to the container. 8 | builder.Services.AddRazorPages(); 9 | builder.Services.AddServerSideBlazor(); 10 | builder.Services.AddSingleton(); 11 | 12 | var app = builder.Build(); 13 | 14 | // Configure the HTTP request pipeline. 15 | if (!app.Environment.IsDevelopment()) 16 | { 17 | app.UseExceptionHandler("/Error"); 18 | // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. 19 | app.UseHsts(); 20 | } 21 | 22 | app.UseHttpsRedirection(); 23 | 24 | app.UseStaticFiles(); 25 | 26 | app.UseRouting(); 27 | 28 | app.MapBlazorHub(); 29 | app.MapFallbackToPage("/_Host"); 30 | 31 | app.Run(); 32 | -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "iisSettings": { 3 | "windowsAuthentication": false, 4 | "anonymousAuthentication": true, 5 | "iisExpress": { 6 | "applicationUrl": "http://localhost:28089", 7 | "sslPort": 44369 8 | } 9 | }, 10 | "profiles": { 11 | "http": { 12 | "commandName": "Project", 13 | "dotnetRunMessages": true, 14 | "launchBrowser": true, 15 | "applicationUrl": "http://localhost:5233", 16 | "environmentVariables": { 17 | "ASPNETCORE_ENVIRONMENT": "Development" 18 | } 19 | }, 20 | "https": { 21 | "commandName": "Project", 22 | "dotnetRunMessages": true, 23 | "launchBrowser": true, 24 | "applicationUrl": "https://localhost:7164;http://localhost:5233", 25 | "environmentVariables": { 26 | "ASPNETCORE_ENVIRONMENT": "Development" 27 | } 28 | }, 29 | "IIS Express": { 30 | "commandName": "IISExpress", 31 | "launchBrowser": true, 32 | "environmentVariables": { 33 | "ASPNETCORE_ENVIRONMENT": "Development" 34 | } 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo/Shared/MainLayout.razor: -------------------------------------------------------------------------------- 1 | @inherits LayoutComponentBase 2 | 3 | Blazor.JsonEditor.Demo 4 | 5 |
6 |
7 | 21 | 22 |
23 | @Body 24 |
25 |
26 |
-------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo/Shared/MainLayout.razor.css: -------------------------------------------------------------------------------- 1 | .page { 2 | position: relative; 3 | display: flex; 4 | flex-direction: column; 5 | } 6 | 7 | main { 8 | flex: 1; 9 | } 10 | 11 | .sidebar { 12 | background-image: linear-gradient(180deg, rgb(5, 39, 103) 0%, #3a0647 70%); 13 | } 14 | 15 | .top-row { 16 | background-color: #f7f7f7; 17 | border-bottom: 1px solid #d6d5d5; 18 | justify-content: flex-end; 19 | height: 3.5rem; 20 | display: flex; 21 | align-items: center; 22 | } 23 | 24 | .top-row ::deep a, .top-row .btn-link { 25 | white-space: nowrap; 26 | margin-left: 1.5rem; 27 | } 28 | 29 | .top-row a:first-child { 30 | overflow: hidden; 31 | text-overflow: ellipsis; 32 | } 33 | 34 | @media (max-width: 640.98px) { 35 | .top-row:not(.auth) { 36 | display: none; 37 | } 38 | 39 | .top-row.auth { 40 | justify-content: space-between; 41 | } 42 | 43 | .top-row a, .top-row .btn-link { 44 | margin-left: 0; 45 | } 46 | } 47 | 48 | @media (min-width: 641px) { 49 | .page { 50 | flex-direction: row; 51 | } 52 | 53 | .sidebar { 54 | width: 250px; 55 | height: 100vh; 56 | position: sticky; 57 | top: 0; 58 | } 59 | 60 | .top-row { 61 | position: sticky; 62 | top: 0; 63 | z-index: 1; 64 | } 65 | 66 | .top-row, article { 67 | padding-left: 2rem !important; 68 | padding-right: 1.5rem !important; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo/_Imports.razor: -------------------------------------------------------------------------------- 1 | @using System.Net.Http 2 | @using Microsoft.AspNetCore.Authorization 3 | @using Microsoft.AspNetCore.Components.Authorization 4 | @using Microsoft.AspNetCore.Components.Forms 5 | @using Microsoft.AspNetCore.Components.Routing 6 | @using Microsoft.AspNetCore.Components.Web 7 | @using Microsoft.AspNetCore.Components.Web.Virtualization 8 | @using Microsoft.JSInterop 9 | @using Blazor.JsonEditor.Demo 10 | @using Blazor.JsonEditor.Demo.Shared 11 | -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "DetailedErrors": true, 3 | "Logging": { 4 | "LogLevel": { 5 | "Default": "Information", 6 | "Microsoft.AspNetCore": "Warning" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | }, 8 | "AllowedHosts": "*" 9 | } 10 | -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo/wwwroot/css/open-iconic/FONT-LICENSE: -------------------------------------------------------------------------------- 1 | SIL OPEN FONT LICENSE Version 1.1 2 | 3 | Copyright (c) 2014 Waybury 4 | 5 | PREAMBLE 6 | The goals of the Open Font License (OFL) are to stimulate worldwide 7 | development of collaborative font projects, to support the font creation 8 | efforts of academic and linguistic communities, and to provide a free and 9 | open framework in which fonts may be shared and improved in partnership 10 | with others. 11 | 12 | The OFL allows the licensed fonts to be used, studied, modified and 13 | redistributed freely as long as they are not sold by themselves. The 14 | fonts, including any derivative works, can be bundled, embedded, 15 | redistributed and/or sold with any software provided that any reserved 16 | names are not used by derivative works. The fonts and derivatives, 17 | however, cannot be released under any other type of license. The 18 | requirement for fonts to remain under this license does not apply 19 | to any document created using the fonts or their derivatives. 20 | 21 | DEFINITIONS 22 | "Font Software" refers to the set of files released by the Copyright 23 | Holder(s) under this license and clearly marked as such. This may 24 | include source files, build scripts and documentation. 25 | 26 | "Reserved Font Name" refers to any names specified as such after the 27 | copyright statement(s). 28 | 29 | "Original Version" refers to the collection of Font Software components as 30 | distributed by the Copyright Holder(s). 31 | 32 | "Modified Version" refers to any derivative made by adding to, deleting, 33 | or substituting -- in part or in whole -- any of the components of the 34 | Original Version, by changing formats or by porting the Font Software to a 35 | new environment. 36 | 37 | "Author" refers to any designer, engineer, programmer, technical 38 | writer or other person who contributed to the Font Software. 39 | 40 | PERMISSION & CONDITIONS 41 | Permission is hereby granted, free of charge, to any person obtaining 42 | a copy of the Font Software, to use, study, copy, merge, embed, modify, 43 | redistribute, and sell modified and unmodified copies of the Font 44 | Software, subject to the following conditions: 45 | 46 | 1) Neither the Font Software nor any of its individual components, 47 | in Original or Modified Versions, may be sold by itself. 48 | 49 | 2) Original or Modified Versions of the Font Software may be bundled, 50 | redistributed and/or sold with any software, provided that each copy 51 | contains the above copyright notice and this license. These can be 52 | included either as stand-alone text files, human-readable headers or 53 | in the appropriate machine-readable metadata fields within text or 54 | binary files as long as those fields can be easily viewed by the user. 55 | 56 | 3) No Modified Version of the Font Software may use the Reserved Font 57 | Name(s) unless explicit written permission is granted by the corresponding 58 | Copyright Holder. This restriction only applies to the primary font name as 59 | presented to the users. 60 | 61 | 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font 62 | Software shall not be used to promote, endorse or advertise any 63 | Modified Version, except to acknowledge the contribution(s) of the 64 | Copyright Holder(s) and the Author(s) or with their explicit written 65 | permission. 66 | 67 | 5) The Font Software, modified or unmodified, in part or in whole, 68 | must be distributed entirely under this license, and must not be 69 | distributed under any other license. The requirement for fonts to 70 | remain under this license does not apply to any document created 71 | using the Font Software. 72 | 73 | TERMINATION 74 | This license becomes null and void if any of the above conditions are 75 | not met. 76 | 77 | DISCLAIMER 78 | THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 79 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF 80 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT 81 | OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE 82 | COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 83 | INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL 84 | DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 85 | FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM 86 | OTHER DEALINGS IN THE FONT SOFTWARE. 87 | -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo/wwwroot/css/open-iconic/ICON-LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Waybury 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo/wwwroot/css/open-iconic/README.md: -------------------------------------------------------------------------------- 1 | [Open Iconic v1.1.1](https://github.com/iconic/open-iconic) 2 | =========== 3 | 4 | ### Open Iconic is the open source sibling of [Iconic](https://github.com/iconic/open-iconic). It is a hyper-legible collection of 223 icons with a tiny footprint—ready to use with Bootstrap and Foundation. [View the collection](https://github.com/iconic/open-iconic) 5 | 6 | 7 | 8 | ## What's in Open Iconic? 9 | 10 | * 223 icons designed to be legible down to 8 pixels 11 | * Super-light SVG files - 61.8 for the entire set 12 | * SVG sprite—the modern replacement for icon fonts 13 | * Webfont (EOT, OTF, SVG, TTF, WOFF), PNG and WebP formats 14 | * Webfont stylesheets (including versions for Bootstrap and Foundation) in CSS, LESS, SCSS and Stylus formats 15 | * PNG and WebP raster images in 8px, 16px, 24px, 32px, 48px and 64px. 16 | 17 | 18 | ## Getting Started 19 | 20 | #### For code samples and everything else you need to get started with Open Iconic, check out our [Icons](https://github.com/iconic/open-iconic) and [Reference](https://github.com/iconic/open-iconic) sections. 21 | 22 | ### General Usage 23 | 24 | #### Using Open Iconic's SVGs 25 | 26 | We like SVGs and we think they're the way to display icons on the web. Since Open Iconic are just basic SVGs, we suggest you display them like you would any other image (don't forget the `alt` attribute). 27 | 28 | ``` 29 | icon name 30 | ``` 31 | 32 | #### Using Open Iconic's SVG Sprite 33 | 34 | Open Iconic also comes in a SVG sprite which allows you to display all the icons in the set with a single request. It's like an icon font, without being a hack. 35 | 36 | Adding an icon from an SVG sprite is a little different than what you're used to, but it's still a piece of cake. *Tip: To make your icons easily style able, we suggest adding a general class to the* `` *tag and a unique class name for each different icon in the* `` *tag.* 37 | 38 | ``` 39 | 40 | 41 | 42 | ``` 43 | 44 | Sizing icons only needs basic CSS. All the icons are in a square format, so just set the `` tag with equal width and height dimensions. 45 | 46 | ``` 47 | .icon { 48 | width: 16px; 49 | height: 16px; 50 | } 51 | ``` 52 | 53 | Coloring icons is even easier. All you need to do is set the `fill` rule on the `` tag. 54 | 55 | ``` 56 | .icon-account-login { 57 | fill: #f00; 58 | } 59 | ``` 60 | 61 | To learn more about SVG Sprites, read [Chris Coyier's guide](http://css-tricks.com/svg-sprites-use-better-icon-fonts/). 62 | 63 | #### Using Open Iconic's Icon Font... 64 | 65 | 66 | ##### …with Bootstrap 67 | 68 | You can find our Bootstrap stylesheets in `font/css/open-iconic-bootstrap.{css, less, scss, styl}` 69 | 70 | 71 | ``` 72 | 73 | ``` 74 | 75 | 76 | ``` 77 | 78 | ``` 79 | 80 | ##### …with Foundation 81 | 82 | You can find our Foundation stylesheets in `font/css/open-iconic-foundation.{css, less, scss, styl}` 83 | 84 | ``` 85 | 86 | ``` 87 | 88 | 89 | ``` 90 | 91 | ``` 92 | 93 | ##### …on its own 94 | 95 | You can find our default stylesheets in `font/css/open-iconic.{css, less, scss, styl}` 96 | 97 | ``` 98 | 99 | ``` 100 | 101 | ``` 102 | 103 | ``` 104 | 105 | 106 | ## License 107 | 108 | ### Icons 109 | 110 | All code (including SVG markup) is under the [MIT License](http://opensource.org/licenses/MIT). 111 | 112 | ### Fonts 113 | 114 | All fonts are under the [SIL Licensed](http://scripts.sil.org/cms/scripts/page.php?item_id=OFL_web). 115 | -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo/wwwroot/css/open-iconic/font/css/open-iconic-bootstrap.min.css: -------------------------------------------------------------------------------- 1 | @font-face{font-family:Icons;src:url(../fonts/open-iconic.eot);src:url(../fonts/open-iconic.eot?#iconic-sm) format('embedded-opentype'),url(../fonts/open-iconic.woff) format('woff'),url(../fonts/open-iconic.ttf) format('truetype'),url(../fonts/open-iconic.otf) format('opentype'),url(../fonts/open-iconic.svg#iconic-sm) format('svg');font-weight:400;font-style:normal}.oi{position:relative;top:1px;display:inline-block;speak:none;font-family:Icons;font-style:normal;font-weight:400;line-height:1;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale}.oi:empty:before{width:1em;text-align:center;box-sizing:content-box}.oi.oi-align-center:before{text-align:center}.oi.oi-align-left:before{text-align:left}.oi.oi-align-right:before{text-align:right}.oi.oi-flip-horizontal:before{-webkit-transform:scale(-1,1);-ms-transform:scale(-1,1);transform:scale(-1,1)}.oi.oi-flip-vertical:before{-webkit-transform:scale(1,-1);-ms-transform:scale(-1,1);transform:scale(1,-1)}.oi.oi-flip-horizontal-vertical:before{-webkit-transform:scale(-1,-1);-ms-transform:scale(-1,1);transform:scale(-1,-1)}.oi-account-login:before{content:'\e000'}.oi-account-logout:before{content:'\e001'}.oi-action-redo:before{content:'\e002'}.oi-action-undo:before{content:'\e003'}.oi-align-center:before{content:'\e004'}.oi-align-left:before{content:'\e005'}.oi-align-right:before{content:'\e006'}.oi-aperture:before{content:'\e007'}.oi-arrow-bottom:before{content:'\e008'}.oi-arrow-circle-bottom:before{content:'\e009'}.oi-arrow-circle-left:before{content:'\e00a'}.oi-arrow-circle-right:before{content:'\e00b'}.oi-arrow-circle-top:before{content:'\e00c'}.oi-arrow-left:before{content:'\e00d'}.oi-arrow-right:before{content:'\e00e'}.oi-arrow-thick-bottom:before{content:'\e00f'}.oi-arrow-thick-left:before{content:'\e010'}.oi-arrow-thick-right:before{content:'\e011'}.oi-arrow-thick-top:before{content:'\e012'}.oi-arrow-top:before{content:'\e013'}.oi-audio-spectrum:before{content:'\e014'}.oi-audio:before{content:'\e015'}.oi-badge:before{content:'\e016'}.oi-ban:before{content:'\e017'}.oi-bar-chart:before{content:'\e018'}.oi-basket:before{content:'\e019'}.oi-battery-empty:before{content:'\e01a'}.oi-battery-full:before{content:'\e01b'}.oi-beaker:before{content:'\e01c'}.oi-bell:before{content:'\e01d'}.oi-bluetooth:before{content:'\e01e'}.oi-bold:before{content:'\e01f'}.oi-bolt:before{content:'\e020'}.oi-book:before{content:'\e021'}.oi-bookmark:before{content:'\e022'}.oi-box:before{content:'\e023'}.oi-briefcase:before{content:'\e024'}.oi-british-pound:before{content:'\e025'}.oi-browser:before{content:'\e026'}.oi-brush:before{content:'\e027'}.oi-bug:before{content:'\e028'}.oi-bullhorn:before{content:'\e029'}.oi-calculator:before{content:'\e02a'}.oi-calendar:before{content:'\e02b'}.oi-camera-slr:before{content:'\e02c'}.oi-caret-bottom:before{content:'\e02d'}.oi-caret-left:before{content:'\e02e'}.oi-caret-right:before{content:'\e02f'}.oi-caret-top:before{content:'\e030'}.oi-cart:before{content:'\e031'}.oi-chat:before{content:'\e032'}.oi-check:before{content:'\e033'}.oi-chevron-bottom:before{content:'\e034'}.oi-chevron-left:before{content:'\e035'}.oi-chevron-right:before{content:'\e036'}.oi-chevron-top:before{content:'\e037'}.oi-circle-check:before{content:'\e038'}.oi-circle-x:before{content:'\e039'}.oi-clipboard:before{content:'\e03a'}.oi-clock:before{content:'\e03b'}.oi-cloud-download:before{content:'\e03c'}.oi-cloud-upload:before{content:'\e03d'}.oi-cloud:before{content:'\e03e'}.oi-cloudy:before{content:'\e03f'}.oi-code:before{content:'\e040'}.oi-cog:before{content:'\e041'}.oi-collapse-down:before{content:'\e042'}.oi-collapse-left:before{content:'\e043'}.oi-collapse-right:before{content:'\e044'}.oi-collapse-up:before{content:'\e045'}.oi-command:before{content:'\e046'}.oi-comment-square:before{content:'\e047'}.oi-compass:before{content:'\e048'}.oi-contrast:before{content:'\e049'}.oi-copywriting:before{content:'\e04a'}.oi-credit-card:before{content:'\e04b'}.oi-crop:before{content:'\e04c'}.oi-dashboard:before{content:'\e04d'}.oi-data-transfer-download:before{content:'\e04e'}.oi-data-transfer-upload:before{content:'\e04f'}.oi-delete:before{content:'\e050'}.oi-dial:before{content:'\e051'}.oi-document:before{content:'\e052'}.oi-dollar:before{content:'\e053'}.oi-double-quote-sans-left:before{content:'\e054'}.oi-double-quote-sans-right:before{content:'\e055'}.oi-double-quote-serif-left:before{content:'\e056'}.oi-double-quote-serif-right:before{content:'\e057'}.oi-droplet:before{content:'\e058'}.oi-eject:before{content:'\e059'}.oi-elevator:before{content:'\e05a'}.oi-ellipses:before{content:'\e05b'}.oi-envelope-closed:before{content:'\e05c'}.oi-envelope-open:before{content:'\e05d'}.oi-euro:before{content:'\e05e'}.oi-excerpt:before{content:'\e05f'}.oi-expand-down:before{content:'\e060'}.oi-expand-left:before{content:'\e061'}.oi-expand-right:before{content:'\e062'}.oi-expand-up:before{content:'\e063'}.oi-external-link:before{content:'\e064'}.oi-eye:before{content:'\e065'}.oi-eyedropper:before{content:'\e066'}.oi-file:before{content:'\e067'}.oi-fire:before{content:'\e068'}.oi-flag:before{content:'\e069'}.oi-flash:before{content:'\e06a'}.oi-folder:before{content:'\e06b'}.oi-fork:before{content:'\e06c'}.oi-fullscreen-enter:before{content:'\e06d'}.oi-fullscreen-exit:before{content:'\e06e'}.oi-globe:before{content:'\e06f'}.oi-graph:before{content:'\e070'}.oi-grid-four-up:before{content:'\e071'}.oi-grid-three-up:before{content:'\e072'}.oi-grid-two-up:before{content:'\e073'}.oi-hard-drive:before{content:'\e074'}.oi-header:before{content:'\e075'}.oi-headphones:before{content:'\e076'}.oi-heart:before{content:'\e077'}.oi-home:before{content:'\e078'}.oi-image:before{content:'\e079'}.oi-inbox:before{content:'\e07a'}.oi-infinity:before{content:'\e07b'}.oi-info:before{content:'\e07c'}.oi-italic:before{content:'\e07d'}.oi-justify-center:before{content:'\e07e'}.oi-justify-left:before{content:'\e07f'}.oi-justify-right:before{content:'\e080'}.oi-key:before{content:'\e081'}.oi-laptop:before{content:'\e082'}.oi-layers:before{content:'\e083'}.oi-lightbulb:before{content:'\e084'}.oi-link-broken:before{content:'\e085'}.oi-link-intact:before{content:'\e086'}.oi-list-rich:before{content:'\e087'}.oi-list:before{content:'\e088'}.oi-location:before{content:'\e089'}.oi-lock-locked:before{content:'\e08a'}.oi-lock-unlocked:before{content:'\e08b'}.oi-loop-circular:before{content:'\e08c'}.oi-loop-square:before{content:'\e08d'}.oi-loop:before{content:'\e08e'}.oi-magnifying-glass:before{content:'\e08f'}.oi-map-marker:before{content:'\e090'}.oi-map:before{content:'\e091'}.oi-media-pause:before{content:'\e092'}.oi-media-play:before{content:'\e093'}.oi-media-record:before{content:'\e094'}.oi-media-skip-backward:before{content:'\e095'}.oi-media-skip-forward:before{content:'\e096'}.oi-media-step-backward:before{content:'\e097'}.oi-media-step-forward:before{content:'\e098'}.oi-media-stop:before{content:'\e099'}.oi-medical-cross:before{content:'\e09a'}.oi-menu:before{content:'\e09b'}.oi-microphone:before{content:'\e09c'}.oi-minus:before{content:'\e09d'}.oi-monitor:before{content:'\e09e'}.oi-moon:before{content:'\e09f'}.oi-move:before{content:'\e0a0'}.oi-musical-note:before{content:'\e0a1'}.oi-paperclip:before{content:'\e0a2'}.oi-pencil:before{content:'\e0a3'}.oi-people:before{content:'\e0a4'}.oi-person:before{content:'\e0a5'}.oi-phone:before{content:'\e0a6'}.oi-pie-chart:before{content:'\e0a7'}.oi-pin:before{content:'\e0a8'}.oi-play-circle:before{content:'\e0a9'}.oi-plus:before{content:'\e0aa'}.oi-power-standby:before{content:'\e0ab'}.oi-print:before{content:'\e0ac'}.oi-project:before{content:'\e0ad'}.oi-pulse:before{content:'\e0ae'}.oi-puzzle-piece:before{content:'\e0af'}.oi-question-mark:before{content:'\e0b0'}.oi-rain:before{content:'\e0b1'}.oi-random:before{content:'\e0b2'}.oi-reload:before{content:'\e0b3'}.oi-resize-both:before{content:'\e0b4'}.oi-resize-height:before{content:'\e0b5'}.oi-resize-width:before{content:'\e0b6'}.oi-rss-alt:before{content:'\e0b7'}.oi-rss:before{content:'\e0b8'}.oi-script:before{content:'\e0b9'}.oi-share-boxed:before{content:'\e0ba'}.oi-share:before{content:'\e0bb'}.oi-shield:before{content:'\e0bc'}.oi-signal:before{content:'\e0bd'}.oi-signpost:before{content:'\e0be'}.oi-sort-ascending:before{content:'\e0bf'}.oi-sort-descending:before{content:'\e0c0'}.oi-spreadsheet:before{content:'\e0c1'}.oi-star:before{content:'\e0c2'}.oi-sun:before{content:'\e0c3'}.oi-tablet:before{content:'\e0c4'}.oi-tag:before{content:'\e0c5'}.oi-tags:before{content:'\e0c6'}.oi-target:before{content:'\e0c7'}.oi-task:before{content:'\e0c8'}.oi-terminal:before{content:'\e0c9'}.oi-text:before{content:'\e0ca'}.oi-thumb-down:before{content:'\e0cb'}.oi-thumb-up:before{content:'\e0cc'}.oi-timer:before{content:'\e0cd'}.oi-transfer:before{content:'\e0ce'}.oi-trash:before{content:'\e0cf'}.oi-underline:before{content:'\e0d0'}.oi-vertical-align-bottom:before{content:'\e0d1'}.oi-vertical-align-center:before{content:'\e0d2'}.oi-vertical-align-top:before{content:'\e0d3'}.oi-video:before{content:'\e0d4'}.oi-volume-high:before{content:'\e0d5'}.oi-volume-low:before{content:'\e0d6'}.oi-volume-off:before{content:'\e0d7'}.oi-warning:before{content:'\e0d8'}.oi-wifi:before{content:'\e0d9'}.oi-wrench:before{content:'\e0da'}.oi-x:before{content:'\e0db'}.oi-yen:before{content:'\e0dc'}.oi-zoom-in:before{content:'\e0dd'}.oi-zoom-out:before{content:'\e0de'} -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo/wwwroot/css/open-iconic/font/fonts/open-iconic.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joghyrt/Blazor.JsonEditor/8cd1d6ad3a2fe423b6f5bae4517999625ebcc5f0/Blazor.JsonEditor.Demo/wwwroot/css/open-iconic/font/fonts/open-iconic.eot -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo/wwwroot/css/open-iconic/font/fonts/open-iconic.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joghyrt/Blazor.JsonEditor/8cd1d6ad3a2fe423b6f5bae4517999625ebcc5f0/Blazor.JsonEditor.Demo/wwwroot/css/open-iconic/font/fonts/open-iconic.otf -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo/wwwroot/css/open-iconic/font/fonts/open-iconic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joghyrt/Blazor.JsonEditor/8cd1d6ad3a2fe423b6f5bae4517999625ebcc5f0/Blazor.JsonEditor.Demo/wwwroot/css/open-iconic/font/fonts/open-iconic.ttf -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo/wwwroot/css/open-iconic/font/fonts/open-iconic.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joghyrt/Blazor.JsonEditor/8cd1d6ad3a2fe423b6f5bae4517999625ebcc5f0/Blazor.JsonEditor.Demo/wwwroot/css/open-iconic/font/fonts/open-iconic.woff -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo/wwwroot/css/site.css: -------------------------------------------------------------------------------- 1 | @import url('open-iconic/font/css/open-iconic-bootstrap.min.css'); 2 | 3 | html, body { 4 | font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; 5 | } 6 | 7 | h1:focus { 8 | outline: none; 9 | } 10 | 11 | a, .btn-link { 12 | color: #0071c1; 13 | } 14 | 15 | .btn-primary { 16 | color: #fff; 17 | background-color: #1b6ec2; 18 | border-color: #1861ac; 19 | } 20 | 21 | .btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus { 22 | box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem #258cfb; 23 | } 24 | 25 | .content { 26 | padding-top: 1.1rem; 27 | } 28 | 29 | .valid.modified:not([type=checkbox]) { 30 | outline: 1px solid #26b050; 31 | } 32 | 33 | .invalid { 34 | outline: 1px solid red; 35 | } 36 | 37 | .validation-message { 38 | color: red; 39 | } 40 | 41 | #blazor-error-ui { 42 | background: lightyellow; 43 | bottom: 0; 44 | box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2); 45 | display: none; 46 | left: 0; 47 | padding: 0.6rem 1.25rem 0.7rem 1.25rem; 48 | position: fixed; 49 | width: 100%; 50 | z-index: 1000; 51 | } 52 | 53 | #blazor-error-ui .dismiss { 54 | cursor: pointer; 55 | position: absolute; 56 | right: 0.75rem; 57 | top: 0.5rem; 58 | } 59 | 60 | .blazor-error-boundary { 61 | background: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTYiIGhlaWdodD0iNDkiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIG92ZXJmbG93PSJoaWRkZW4iPjxkZWZzPjxjbGlwUGF0aCBpZD0iY2xpcDAiPjxyZWN0IHg9IjIzNSIgeT0iNTEiIHdpZHRoPSI1NiIgaGVpZ2h0PSI0OSIvPjwvY2xpcFBhdGg+PC9kZWZzPjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMCkiIHRyYW5zZm9ybT0idHJhbnNsYXRlKC0yMzUgLTUxKSI+PHBhdGggZD0iTTI2My41MDYgNTFDMjY0LjcxNyA1MSAyNjUuODEzIDUxLjQ4MzcgMjY2LjYwNiA1Mi4yNjU4TDI2Ny4wNTIgNTIuNzk4NyAyNjcuNTM5IDUzLjYyODMgMjkwLjE4NSA5Mi4xODMxIDI5MC41NDUgOTIuNzk1IDI5MC42NTYgOTIuOTk2QzI5MC44NzcgOTMuNTEzIDI5MSA5NC4wODE1IDI5MSA5NC42NzgyIDI5MSA5Ny4wNjUxIDI4OS4wMzggOTkgMjg2LjYxNyA5OUwyNDAuMzgzIDk5QzIzNy45NjMgOTkgMjM2IDk3LjA2NTEgMjM2IDk0LjY3ODIgMjM2IDk0LjM3OTkgMjM2LjAzMSA5NC4wODg2IDIzNi4wODkgOTMuODA3MkwyMzYuMzM4IDkzLjAxNjIgMjM2Ljg1OCA5Mi4xMzE0IDI1OS40NzMgNTMuNjI5NCAyNTkuOTYxIDUyLjc5ODUgMjYwLjQwNyA1Mi4yNjU4QzI2MS4yIDUxLjQ4MzcgMjYyLjI5NiA1MSAyNjMuNTA2IDUxWk0yNjMuNTg2IDY2LjAxODNDMjYwLjczNyA2Ni4wMTgzIDI1OS4zMTMgNjcuMTI0NSAyNTkuMzEzIDY5LjMzNyAyNTkuMzEzIDY5LjYxMDIgMjU5LjMzMiA2OS44NjA4IDI1OS4zNzEgNzAuMDg4N0wyNjEuNzk1IDg0LjAxNjEgMjY1LjM4IDg0LjAxNjEgMjY3LjgyMSA2OS43NDc1QzI2Ny44NiA2OS43MzA5IDI2Ny44NzkgNjkuNTg3NyAyNjcuODc5IDY5LjMxNzkgMjY3Ljg3OSA2Ny4xMTgyIDI2Ni40NDggNjYuMDE4MyAyNjMuNTg2IDY2LjAxODNaTTI2My41NzYgODYuMDU0N0MyNjEuMDQ5IDg2LjA1NDcgMjU5Ljc4NiA4Ny4zMDA1IDI1OS43ODYgODkuNzkyMSAyNTkuNzg2IDkyLjI4MzcgMjYxLjA0OSA5My41Mjk1IDI2My41NzYgOTMuNTI5NSAyNjYuMTE2IDkzLjUyOTUgMjY3LjM4NyA5Mi4yODM3IDI2Ny4zODcgODkuNzkyMSAyNjcuMzg3IDg3LjMwMDUgMjY2LjExNiA4Ni4wNTQ3IDI2My41NzYgODYuMDU0N1oiIGZpbGw9IiNGRkU1MDAiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjwvZz48L3N2Zz4=) no-repeat 1rem/1.8rem, #b32121; 62 | padding: 1rem 1rem 1rem 3.7rem; 63 | color: white; 64 | } 65 | 66 | .blazor-error-boundary::after { 67 | content: "An error has occurred." 68 | } 69 | -------------------------------------------------------------------------------- /Blazor.JsonEditor.Demo/wwwroot/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joghyrt/Blazor.JsonEditor/8cd1d6ad3a2fe423b6f5bae4517999625ebcc5f0/Blazor.JsonEditor.Demo/wwwroot/favicon.png -------------------------------------------------------------------------------- /Blazor.JsonEditor.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.7.34009.444 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazor.JsonEditor", "Blazor.JsonEditor\Blazor.JsonEditor.csproj", "{E3356A2B-D324-4D73-B91E-C477A55B07D0}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazor.JsonEditor.Demo", "Blazor.JsonEditor.Demo\Blazor.JsonEditor.Demo.csproj", "{7AEFB1DE-AF6A-4478-812F-D77A8CF2CD96}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Blazor.JsonEditor.Demo.Wasm", "Blazor.JsonEditor.Demo.Wasm\Blazor.JsonEditor.Demo.Wasm.csproj", "{B6CF0C7B-F2EB-48D0-96F4-E0E155F1DFD1}" 11 | EndProject 12 | Global 13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 14 | Debug|Any CPU = Debug|Any CPU 15 | Release|Any CPU = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {E3356A2B-D324-4D73-B91E-C477A55B07D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {E3356A2B-D324-4D73-B91E-C477A55B07D0}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {E3356A2B-D324-4D73-B91E-C477A55B07D0}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | {E3356A2B-D324-4D73-B91E-C477A55B07D0}.Release|Any CPU.Build.0 = Release|Any CPU 22 | {7AEFB1DE-AF6A-4478-812F-D77A8CF2CD96}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 23 | {7AEFB1DE-AF6A-4478-812F-D77A8CF2CD96}.Debug|Any CPU.Build.0 = Debug|Any CPU 24 | {7AEFB1DE-AF6A-4478-812F-D77A8CF2CD96}.Release|Any CPU.ActiveCfg = Release|Any CPU 25 | {7AEFB1DE-AF6A-4478-812F-D77A8CF2CD96}.Release|Any CPU.Build.0 = Release|Any CPU 26 | {B6CF0C7B-F2EB-48D0-96F4-E0E155F1DFD1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 27 | {B6CF0C7B-F2EB-48D0-96F4-E0E155F1DFD1}.Debug|Any CPU.Build.0 = Debug|Any CPU 28 | {B6CF0C7B-F2EB-48D0-96F4-E0E155F1DFD1}.Release|Any CPU.ActiveCfg = Release|Any CPU 29 | {B6CF0C7B-F2EB-48D0-96F4-E0E155F1DFD1}.Release|Any CPU.Build.0 = Release|Any CPU 30 | EndGlobalSection 31 | GlobalSection(SolutionProperties) = preSolution 32 | HideSolutionNode = FALSE 33 | EndGlobalSection 34 | GlobalSection(ExtensibilityGlobals) = postSolution 35 | SolutionGuid = {FC1316EA-9016-42E8-8ED5-909ED73A7C5E} 36 | EndGlobalSection 37 | EndGlobal 38 | -------------------------------------------------------------------------------- /Blazor.JsonEditor/Attribute/RequiredIfAttribute.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.ComponentModel.DataAnnotations; 3 | using System.Linq; 4 | 5 | namespace Blazor.JsonEditor.Attribute 6 | { 7 | internal class RequiredIfAttribute : ValidationAttribute 8 | { 9 | RequiredAttribute _innerAttribute = new RequiredAttribute(); 10 | internal string _dependentProperty { get; set; } 11 | internal List _targetValues { get; set; } 12 | 13 | 14 | internal RequiredIfAttribute(string propertyName, params object[] dependents) 15 | { 16 | _dependentProperty = propertyName; 17 | _targetValues = dependents.ToList(); 18 | } 19 | 20 | protected override ValidationResult IsValid(object value, ValidationContext validationContext) 21 | { 22 | var field = validationContext.ObjectType.GetProperty(_dependentProperty); 23 | if (field != null) 24 | { 25 | var dependentValue = field.GetValue(validationContext.ObjectInstance, null); 26 | if (_targetValues?.Any(x => x.Equals(dependentValue)) == true) 27 | { 28 | _innerAttribute.ErrorMessage = "Required!"; 29 | return _innerAttribute.GetValidationResult(value, validationContext); 30 | } 31 | 32 | return ValidationResult.Success; 33 | } 34 | else 35 | { 36 | return new ValidationResult(FormatErrorMessage(_dependentProperty)); 37 | } 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Blazor.JsonEditor/Blazor.JsonEditor.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net7.0 5 | enable 6 | enable 7 | true 8 | Blazor.JsonEditor 9 | Ivan Akimov 10 | Json Editor and Viewer for Blazor 11 | https://github.com/joghyrt/Blazor.JsonEditor 12 | MIT 13 | README.md 14 | LICENSE.txt 15 | Item view and object view customization added 16 | 1.1.1 17 | https://github.com/joghyrt/Blazor.JsonEditor 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | <_ContentIncludedByDefault Remove="Component\Viewer\Body\JsonBodyView.razor" /> 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /Blazor.JsonEditor/Component/Editor/JsonItemDefaultEditor.razor: -------------------------------------------------------------------------------- 1 | @using System.Text.Json 2 | 3 | 4 | 21 | 22 | @if (IsShowEditor) 23 | { 24 | 25 | 26 |
27 | @if (ValidationMessage != null) 28 | { 29 |
30 | @ValidationMessage 31 |
32 | } 33 |
34 |
35 | 36 | 37 | 38 |
39 |
40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 |
51 |
52 |
53 | @if (JsonItem.ValueKind != JsonValueKind.Undefined && JsonItem.ValueKind != JsonValueKind.Array) 54 | { 55 | 56 | } 57 | @if (JsonItem.ValueKind == JsonValueKind.String) 58 | { 59 | 60 | 61 | } 62 | else if(JsonItem.ValueKind == JsonValueKind.Array) 63 | { 64 |
65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 |
74 | 75 | 76 | 77 | } 78 | else if (JsonItem.ValueKind == JsonValueKind.Number) 79 | { 80 | 81 | 82 | } 83 | else if (JsonItem.ValueKind == JsonValueKind.True) 84 | { 85 | 86 | 87 | 88 | 89 | 90 | 91 | } 92 | else if (JsonItem.ValueKind == JsonValueKind.False && KeyValues?.Count > 0) 93 | { 94 | 95 | 96 | @foreach (var kv in KeyValues) 97 | { 98 | 99 | } 100 | 101 | 102 | } 103 |
104 | 107 |
108 |
109 | } 110 | 111 | @if (JsonItemToEdit != null) 112 | { 113 | 114 | 117 | 118 | } -------------------------------------------------------------------------------- /Blazor.JsonEditor/Component/Editor/JsonItemDefaultEditor.razor.cs: -------------------------------------------------------------------------------- 1 | using System.Globalization; 2 | using System.Text.Json; 3 | using System.Text.Json.Nodes; 4 | using Blazor.JsonEditor.Helper; 5 | using Blazor.JsonEditor.Model; 6 | using Microsoft.AspNetCore.Components; 7 | 8 | namespace Blazor.JsonEditor.Component.Editor 9 | { 10 | public partial class JsonItemDefaultEditor 11 | { 12 | [Parameter] 13 | public JsonObject? JsonObject { get; set; } 14 | 15 | [Parameter] 16 | public EventCallback JsonObjectChanged { get; set; } 17 | 18 | [Parameter] 19 | public Dictionary? KeyValues { get; set; } 20 | 21 | [Parameter] 22 | public KeyValuePair? JsonItemToEdit { get; set; } 23 | 24 | private bool IsShowEditor; 25 | 26 | private bool IsEditMode 27 | { 28 | get 29 | { 30 | return JsonItemToEdit != null; 31 | } 32 | } 33 | 34 | private string? ValidationMessage; 35 | 36 | private JsonItem? JsonItem { get; set; } 37 | 38 | private void ToggleEditor() 39 | { 40 | IsShowEditor = !IsShowEditor; 41 | ValidationMessage = null; 42 | StateHasChanged(); 43 | } 44 | 45 | protected override void OnParametersSet() 46 | { 47 | JsonItem = new JsonItem(); 48 | 49 | if (JsonItemToEdit == null) 50 | { 51 | JsonItem.ValueKind = JsonValueKind.Undefined; 52 | JsonItem.ArrayType = JsonValueKind.String; 53 | return; 54 | } 55 | 56 | this.ProcessEditMode(); 57 | } 58 | 59 | private void ProcessEditMode() 60 | { 61 | JsonItem.PropertyName = JsonItemToEdit.Value.Key; 62 | 63 | var jsonObjectValue = JsonObject?.FirstOrDefault(x => x.Key.Equals(JsonItemToEdit.Value.Key)).Value; 64 | 65 | var jsonElement = new JsonElement(); 66 | 67 | if (jsonObjectValue != null) 68 | { 69 | jsonElement = JsonSerializer.Deserialize(jsonObjectValue.ToJsonString()); 70 | JsonItem.ValueKind = jsonElement.ValueKind; 71 | } 72 | 73 | switch (jsonElement.ValueKind) 74 | { 75 | case JsonValueKind.String: 76 | JsonItem.Value = jsonElement.ToString(); 77 | break; 78 | case JsonValueKind.Number: 79 | if (!double.TryParse(jsonElement.ToString(), CultureInfo.InvariantCulture, out var numericValue)) 80 | { 81 | throw new ArgumentException($"Not able to parse value {jsonElement.ToString()} to double."); 82 | } 83 | 84 | JsonItem.NumericValue = numericValue; 85 | break; 86 | case JsonValueKind.True: 87 | JsonItem.Value = "true"; 88 | break; 89 | case JsonValueKind.False: 90 | JsonItem.Value = "false"; 91 | JsonItem.ValueKind = JsonValueKind.True; 92 | break; 93 | case JsonValueKind.Array: 94 | { 95 | var arrayValue = jsonElement.ToString(); 96 | JsonItem.Value = arrayValue.Substring(1, arrayValue.Length - 2); 97 | 98 | var firstElement = jsonElement.EnumerateArray().FirstOrDefault(); 99 | if (firstElement.ValueKind == JsonValueKind.Undefined) 100 | { 101 | JsonItem.ValueKind = JsonValueKind.Undefined; 102 | break; 103 | } 104 | 105 | JsonItem.ArrayType = firstElement.ValueKind; 106 | break; 107 | } 108 | case JsonValueKind.Null: 109 | JsonItem.ValueKind = JsonValueKind.Undefined; 110 | break; 111 | } 112 | } 113 | 114 | private async Task SaveNodeAsync() 115 | { 116 | try 117 | { 118 | ValidationMessage = null; 119 | 120 | if (JsonItem == null) 121 | { 122 | IsShowEditor = false; 123 | return; 124 | } 125 | 126 | if (!this.IsEditMode) 127 | { 128 | this.AddNode(); 129 | } 130 | else 131 | { 132 | this.EditNode(); 133 | } 134 | 135 | await JsonObjectChanged.InvokeAsync(JsonObject); 136 | JsonItem = null; 137 | IsShowEditor = false; 138 | } 139 | catch (ArgumentException ex) 140 | { 141 | ValidationMessage = ex.Message; 142 | } 143 | } 144 | 145 | private void AddNode() 146 | { 147 | if (JsonItem == null || string.IsNullOrEmpty(JsonItem.PropertyName)) 148 | { 149 | return; 150 | } 151 | 152 | if (JsonObject == null) 153 | { 154 | JsonObject = new JsonObject(); 155 | } 156 | 157 | JsonHelper.AddNodeValue(JsonObject, JsonItem); 158 | } 159 | 160 | private void EditNode() 161 | { 162 | if (JsonObject == null) 163 | { 164 | return; 165 | } 166 | 167 | if (JsonItem == null) 168 | { 169 | return; 170 | } 171 | 172 | if (JsonItemToEdit == null) 173 | { 174 | return; 175 | } 176 | 177 | JsonHelper.EditNodeValue(JsonObject, JsonItem, JsonItemToEdit.Value.Key); 178 | } 179 | 180 | private async Task RemoveNodeAsync() 181 | { 182 | if (this.JsonObject == null) 183 | { 184 | return; 185 | } 186 | 187 | if (this.JsonItemToEdit == null) 188 | { 189 | return; 190 | } 191 | 192 | this.JsonObject.Remove(this.JsonItemToEdit.Value.Key); 193 | await JsonObjectChanged.InvokeAsync(JsonObject); 194 | this.StateHasChanged(); 195 | } 196 | } 197 | } -------------------------------------------------------------------------------- /Blazor.JsonEditor/Component/Editor/JsonItemDefaultEditor.razor.css: -------------------------------------------------------------------------------- 1 | .json-content { 2 | padding: 5px; 3 | border: 1px solid #ccc; 4 | } 5 | 6 | .json-object-body { 7 | margin-left:20px; 8 | min-width:500px 9 | } 10 | 11 | .json-object-body-empty { 12 | margin-left:20px; 13 | } 14 | 15 | .json-property-name { 16 | padding: 3px; 17 | color: brown; 18 | } 19 | 20 | .json-value-content { 21 | padding: 3px; 22 | font-style: italic; 23 | } 24 | 25 | .json-button { 26 | padding: 4px; 27 | border-radius: 4px; 28 | border: 1px solid #ccc; 29 | line-height: 1px; 30 | font-family: 'Wingdings 2'; 31 | font-size: 10px; 32 | } 33 | 34 | .json-button-submit { 35 | padding: 8px; 36 | border-radius: 5px; 37 | border: 1px solid #ccc; 38 | line-height: 1px; 39 | font-family: 'Wingdings 2'; 40 | font-size: 14px; 41 | } 42 | 43 | .json-button-danger { 44 | color: red; 45 | } 46 | 47 | .json-input-text { 48 | padding: 2px 5px; 49 | border-radius: 5px; 50 | border: 1px solid #ccc; 51 | width: 100%; 52 | line-height: 1.2em; 53 | } 54 | 55 | .json-validation-error { 56 | color: red; 57 | } 58 | 59 | .json-value-string { 60 | color: darkgoldenrod; 61 | } 62 | 63 | .json-value-number { 64 | color: blueviolet; 65 | } 66 | 67 | .json-value-array { 68 | color: darkgreen; 69 | } 70 | 71 | .json-new-item-form-container { 72 | background: #fff; 73 | border: 1px solid #808080; 74 | padding: 10px; 75 | border-radius: 5px; 76 | box-shadow: 3px 3px 10px #1d1d1d; 77 | width: 400px; 78 | } -------------------------------------------------------------------------------- /Blazor.JsonEditor/Component/Editor/JsonItemEditor.razor: -------------------------------------------------------------------------------- 1 | @{ 2 | if (Component != null) 3 | { 4 | 5 | } 6 | else 7 | { 8 | 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Blazor.JsonEditor/Component/Editor/JsonItemEditor.razor.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Components; 2 | using System.Text.Json.Nodes; 3 | 4 | namespace Blazor.JsonEditor.Component.Editor 5 | { 6 | public partial class JsonItemEditor 7 | { 8 | [Parameter] 9 | public Type? Component { get; set; } 10 | 11 | [Parameter] 12 | public JsonObject? JsonObject { get; set; } 13 | 14 | [Parameter] 15 | public EventCallback JsonObjectChanged { get; set; } 16 | 17 | [Parameter] 18 | public Dictionary? KeyValues { get; set; } 19 | 20 | [Parameter] 21 | public KeyValuePair? JsonItemToEdit { get; set; } 22 | 23 | private Dictionary DynamicComponentParameters = new(); 24 | 25 | protected override async Task OnParametersSetAsync() 26 | { 27 | if (Component != null) 28 | { 29 | AddOrUpdateParameter("JsonObject", JsonObject); 30 | AddOrUpdateParameter("JsonObjectChanged", JsonObjectChanged); 31 | AddOrUpdateParameter("KeyValues", KeyValues); 32 | AddOrUpdateParameter("JsonItemToEdit", JsonItemToEdit); 33 | } 34 | } 35 | 36 | private void AddOrUpdateParameter(string key, object value) 37 | { 38 | if (DynamicComponentParameters.TryAdd(key, value)) 39 | { 40 | return; 41 | } 42 | 43 | DynamicComponentParameters.Remove(key); 44 | DynamicComponentParameters.TryAdd(key, value); 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /Blazor.JsonEditor/Component/Editor/JsonItemEditor.razor.css: -------------------------------------------------------------------------------- 1 | .json-content { 2 | padding: 5px; 3 | border: 1px solid #ccc; 4 | } 5 | 6 | .json-object-body { 7 | margin-left:20px; 8 | min-width:500px 9 | } 10 | 11 | .json-object-body-empty { 12 | margin-left:20px; 13 | } 14 | 15 | .json-property-name { 16 | padding: 3px; 17 | color: brown; 18 | } 19 | 20 | .json-value-content { 21 | padding: 3px; 22 | font-style: italic; 23 | } 24 | 25 | .json-button { 26 | padding: 4px; 27 | border-radius: 4px; 28 | border: 1px solid #ccc; 29 | line-height: 1px; 30 | font-family: 'Wingdings 2'; 31 | font-size: 10px; 32 | } 33 | 34 | .json-button-submit { 35 | padding: 8px; 36 | border-radius: 5px; 37 | border: 1px solid #ccc; 38 | line-height: 1px; 39 | font-family: 'Wingdings 2'; 40 | font-size: 14px; 41 | } 42 | 43 | .json-button-danger { 44 | color: red; 45 | } 46 | 47 | .json-input-text { 48 | padding: 2px 5px; 49 | border-radius: 5px; 50 | border: 1px solid #ccc; 51 | width: 100%; 52 | line-height: 1.2em; 53 | } 54 | 55 | .json-validation-error { 56 | color: red; 57 | } 58 | 59 | .json-value-string { 60 | color: darkgoldenrod; 61 | } 62 | 63 | .json-value-number { 64 | color: blueviolet; 65 | } 66 | 67 | .json-value-array { 68 | color: darkgreen; 69 | } 70 | 71 | .json-new-item-form-container { 72 | background: #fff; 73 | border: 1px solid #808080; 74 | padding: 10px; 75 | border-radius: 5px; 76 | box-shadow: 3px 3px 10px #1d1d1d; 77 | width: 400px; 78 | } -------------------------------------------------------------------------------- /Blazor.JsonEditor/Component/InternalJsonEditor.razor: -------------------------------------------------------------------------------- 1 | @using System.Text.Json 2 | @using System.Text.Json.Nodes 3 | @using Blazor.JsonEditor.Helper 4 | @using Blazor.JsonEditor.Component.Editor 5 | @using Blazor.JsonEditor.Component.Viewer.Item 6 | @using Blazor.JsonEditor.Component.Viewer.Object 7 | 8 | 9 | @if (Json != null) 10 | { 11 |
12 | @foreach (var jsonItem in Json) 13 | { 14 |
15 | @if (!JsonHelper.IsObjectValueKind(jsonItem)) 16 | { 17 | 24 | } 25 | else 26 | { 27 | 34 | } 35 | 36 | @if (JsonHelper.IsShowComma(Json, jsonItem)) 37 | { 38 | , 39 | } 40 | 41 | @if (this.AllowEdit) 42 | { 43 | 45 | 46 | } 47 |
48 | } 49 | @if (this.AllowEdit) 50 | { 51 |
52 | 53 |
54 | } 55 |
56 | } 57 | else 58 | { 59 | @if (this.AllowEdit) 60 | { 61 |
62 | 63 |
64 | } 65 | } -------------------------------------------------------------------------------- /Blazor.JsonEditor/Component/InternalJsonEditor.razor.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Components; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Text.Json.Nodes; 7 | using System.Text.Json; 8 | using System.Threading.Tasks; 9 | 10 | namespace Blazor.JsonEditor.Component 11 | { 12 | public partial class InternalJsonEditor 13 | { 14 | [Parameter] 15 | public string? Value { get; set; } 16 | 17 | [Parameter] 18 | public EventCallback ValueChanged { get; set; } 19 | 20 | [Parameter] 21 | public Dictionary? KeyValues { get; set; } 22 | 23 | [Parameter] 24 | public bool AllowEdit { get; set; } = true; 25 | 26 | [Parameter] public Type? CustomEditor { get; set; } 27 | 28 | [Parameter] 29 | public Type? CustomItemView { get; set; } 30 | 31 | [Parameter] 32 | public Type? CustomObjectView { get; set; } 33 | 34 | private JsonObject? Json { get; set; } 35 | 36 | protected override async Task OnParametersSetAsync() 37 | { 38 | if (Value != null) 39 | { 40 | Json = JsonNode.Parse(Value) as JsonObject; 41 | } 42 | await base.OnParametersSetAsync(); 43 | } 44 | 45 | private void ValueUpdated(JsonObject jsonObject) 46 | { 47 | this.Json = jsonObject; 48 | this.ValueChanged.InvokeAsync(jsonObject.ToJsonString()); 49 | this.StateHasChanged(); 50 | } 51 | 52 | private void JsonObjectUpdated(string prop, string value) 53 | { 54 | if (this.Json == null) 55 | { 56 | return; 57 | } 58 | 59 | this.Json[prop] = JsonNode.Parse(value); 60 | this.ValueChanged.InvokeAsync(Json.ToJsonString()); 61 | this.StateHasChanged(); 62 | } 63 | 64 | private void RemoveValue(string prop) 65 | { 66 | if (this.Json == null) 67 | { 68 | return; 69 | } 70 | 71 | this.Json.Remove(prop); 72 | this.ValueChanged.InvokeAsync(Json.ToJsonString()); 73 | this.StateHasChanged(); 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /Blazor.JsonEditor/Component/InternalJsonEditor.razor.css: -------------------------------------------------------------------------------- 1 | .json-content { 2 | padding: 5px; 3 | border: 1px solid #ccc; 4 | } 5 | 6 | .json-object-body { 7 | margin-left:20px; 8 | min-width:500px 9 | } 10 | 11 | .json-object-body-empty { 12 | margin-left:20px; 13 | } 14 | 15 | .json-property-name { 16 | padding: 3px; 17 | color: brown; 18 | } 19 | 20 | .json-value-content { 21 | padding: 3px; 22 | font-style: italic; 23 | } 24 | 25 | .json-button { 26 | padding: 4px; 27 | border-radius: 4px; 28 | border: 1px solid #ccc; 29 | line-height: 1px; 30 | font-family: 'Wingdings 2'; 31 | font-size: 10px; 32 | } 33 | 34 | .json-button-submit { 35 | padding: 8px; 36 | border-radius: 5px; 37 | border: 1px solid #ccc; 38 | line-height: 1px; 39 | font-family: 'Wingdings 2'; 40 | font-size: 14px; 41 | } 42 | 43 | .json-button-danger { 44 | color: red; 45 | } 46 | 47 | .json-input-text { 48 | padding: 2px 5px; 49 | border-radius: 5px; 50 | border: 1px solid #ccc; 51 | width: 100%; 52 | line-height: 1.2em; 53 | } 54 | 55 | .json-validation-error { 56 | color: red; 57 | } 58 | 59 | .json-value-string { 60 | color: darkgoldenrod; 61 | } 62 | 63 | .json-value-number { 64 | color: blueviolet; 65 | } 66 | 67 | .json-value-array { 68 | color: darkgreen; 69 | } 70 | 71 | .json-new-item-form-container { 72 | background: #fff; 73 | border: 1px solid #808080; 74 | padding: 10px; 75 | border-radius: 5px; 76 | box-shadow: 3px 3px 10px #1d1d1d; 77 | width: 400px; 78 | } -------------------------------------------------------------------------------- /Blazor.JsonEditor/Component/JsonEditor.razor: -------------------------------------------------------------------------------- 1 | @using Blazor.JsonEditor.Helper 2 | @using Blazor.JsonEditor.Component.Editor 3 | @using Blazor.JsonEditor.Component.Viewer.Object 4 | @using Blazor.JsonEditor.Component.Viewer.Item 5 | 6 | @inherits InputBase 7 | @inject IJSRuntime JS 8 | 9 |
10 | { 11 | @if (Json != null) 12 | { 13 |
14 | @foreach (var jsonItem in Json) 15 | { 16 |
17 | @if (!JsonHelper.IsObjectValueKind(jsonItem)) 18 | { 19 | 26 | } 27 | else 28 | { 29 | 36 | } 37 | 38 | @if (JsonHelper.IsShowComma(Json, jsonItem)) 39 | { 40 | , 41 | } 42 | 43 | @if (this.AllowEdit) 44 | { 45 | 50 | 51 | } 52 |
53 | } 54 | @if (this.AllowEdit) 55 | { 56 |
57 | 58 |
59 | } 60 |
61 | } 62 | else 63 | { 64 | @if (this.AllowEdit) 65 | { 66 |
67 | 68 |
69 | } 70 | } 71 | } 72 |
73 | -------------------------------------------------------------------------------- /Blazor.JsonEditor/Component/JsonEditor.razor.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Components.Forms; 2 | using Microsoft.AspNetCore.Components; 3 | using System.Linq.Expressions; 4 | using System.Text.Json; 5 | using System.Text.Json.Nodes; 6 | using Blazor.JsonEditor.Model; 7 | 8 | namespace Blazor.JsonEditor.Component 9 | { 10 | public partial class JsonEditor 11 | { 12 | [Parameter] 13 | public Dictionary? KeyValues { get; set; } 14 | [Parameter] 15 | public Expression>? ValidationFor { get; set; } 16 | [Parameter] 17 | public string? FieldName { get; set; } 18 | 19 | [Parameter] 20 | public bool AllowEdit { get; set; } = true; 21 | 22 | [Parameter] 23 | public Type? CustomEditor { get; set; } 24 | 25 | [Parameter] 26 | public Type? CustomItemView { get; set; } 27 | 28 | [Parameter] 29 | public Type? CustomObjectView { get; set; } 30 | 31 | private JsonObject? Json { get; set; } 32 | 33 | protected override async Task OnParametersSetAsync() 34 | { 35 | if (Value != null) 36 | { 37 | Json = JsonNode.Parse(Value) as JsonObject; 38 | } 39 | 40 | await base.OnParametersSetAsync(); 41 | } 42 | 43 | protected override bool TryParseValueFromString(string value, out string? result, 44 | out string? validationErrorMessage) 45 | { 46 | result = value; 47 | validationErrorMessage = null; 48 | return true; 49 | } 50 | 51 | private void ValueUpdated(JsonObject jsonObject) 52 | { 53 | Json = jsonObject; 54 | 55 | TryParseValueFromString(jsonObject.ToJsonString(), out string? JsonObjectString, out string? vm); 56 | ValueChanged.InvokeAsync(JsonObjectString); 57 | EditContext.NotifyFieldChanged(new FieldIdentifier(EditContext.Model, FieldName)); 58 | 59 | StateHasChanged(); 60 | } 61 | 62 | private void JsonObjectUpdated(string prop, string value) 63 | { 64 | if (Json == null) 65 | { 66 | return; 67 | } 68 | 69 | Json[prop] = JsonNode.Parse(value); 70 | TryParseValueFromString(Json.ToJsonString(), out string? JsonObjectString, out string? vm); 71 | ValueChanged.InvokeAsync(JsonObjectString); 72 | EditContext.NotifyFieldChanged(new FieldIdentifier(EditContext.Model, FieldName)); 73 | StateHasChanged(); 74 | } 75 | 76 | private void RemoveValue(string prop) 77 | { 78 | if (Json == null) 79 | { 80 | return; 81 | } 82 | 83 | Json.Remove(prop); 84 | TryParseValueFromString(Json.ToJsonString(), out string? JsonObjectString, out string? vm); 85 | ValueChanged.InvokeAsync(JsonObjectString); 86 | EditContext.NotifyFieldChanged(new FieldIdentifier(EditContext.Model, FieldName)); 87 | StateHasChanged(); 88 | } 89 | } 90 | } -------------------------------------------------------------------------------- /Blazor.JsonEditor/Component/JsonEditor.razor.css: -------------------------------------------------------------------------------- 1 | .json-content { 2 | padding: 5px; 3 | border: 1px solid #ccc; 4 | } 5 | 6 | .json-object-body { 7 | margin-left:20px; 8 | min-width:500px 9 | } 10 | 11 | .json-object-body-empty { 12 | margin-left:20px; 13 | } 14 | 15 | .json-property-name { 16 | padding: 3px; 17 | color: brown; 18 | } 19 | 20 | .json-value-content { 21 | padding: 3px; 22 | font-style: italic; 23 | } 24 | 25 | .json-button { 26 | padding: 4px; 27 | border-radius: 4px; 28 | border: 1px solid #ccc; 29 | line-height: 1px; 30 | font-family: 'Wingdings 2'; 31 | font-size: 10px; 32 | } 33 | 34 | .json-button-submit { 35 | padding: 8px; 36 | border-radius: 5px; 37 | border: 1px solid #ccc; 38 | line-height: 1px; 39 | font-family: 'Wingdings 2'; 40 | font-size: 14px; 41 | } 42 | 43 | .json-button-danger { 44 | color: red; 45 | } 46 | 47 | .json-input-text { 48 | padding: 2px 5px; 49 | border-radius: 5px; 50 | border: 1px solid #ccc; 51 | width: 100%; 52 | line-height: 1.2em; 53 | } 54 | 55 | .json-validation-error { 56 | color: red; 57 | } 58 | 59 | .json-value-string { 60 | color: darkgoldenrod; 61 | } 62 | 63 | .json-value-number { 64 | color: blueviolet; 65 | } 66 | 67 | .json-value-array { 68 | color: darkgreen; 69 | } 70 | 71 | .json-new-item-form-container { 72 | background: #fff; 73 | border: 1px solid #808080; 74 | padding: 10px; 75 | border-radius: 5px; 76 | box-shadow: 3px 3px 10px #1d1d1d; 77 | width: 400px; 78 | } -------------------------------------------------------------------------------- /Blazor.JsonEditor/Component/Viewer/Item/JsonItemDefaultView.razor: -------------------------------------------------------------------------------- 1 | @using System.Text.Json 2 | @using System.Text.Json.Nodes 3 | @using Blazor.JsonEditor.Helper 4 | 5 | 6 | @if (JsonHelper.IsInJsonValueKind(JsonItem, new List { JsonValueKind.Number, JsonValueKind.True, JsonValueKind.False })) 7 | { 8 | "@JsonItem.Key" 9 | : 10 | @JsonItem.Value.ToString() 11 | } 12 | else if (JsonItem.Value == null) 13 | { 14 | "@JsonItem.Key" 15 | : 16 | null 17 | } 18 | else if (JsonHelper.IsInJsonValueKind(JsonItem, new List { JsonValueKind.String })) 19 | { 20 | "@JsonItem.Key" 21 | : 22 | "@JsonItem.Value.ToString()" 23 | } 24 | else if (JsonHelper.IsInJsonValueKind(JsonItem, new List { JsonValueKind.Array })) 25 | { 26 | "@JsonItem.Key" 27 | : 28 | 29 | var isObjectArray = JsonItem.Value.AsArray().Any() && JsonItem.Value.AsArray().First() is JsonObject; 30 | 31 | if (isObjectArray) 32 | { 33 | [ 34 |
35 | var jsonArray = JsonItem.Value.AsArray(); 36 | var latestValue = jsonArray.Last(); 37 | for (var i = 0; i < jsonArray.Count; i++) 38 | { 39 | var value = jsonArray[i]; 40 | var index = i; 41 | 42 | { 43 | 50 | 51 | @if (value.Equals(latestValue)) 52 | { 53 | } 54 | } 55 | else 56 | { 57 | }, 58 | } 59 |
60 |
61 | } 62 | 63 | 64 | 65 | ] 66 | } 67 | else 68 | { 69 | @JsonItem.Value.ToJsonString() 70 | } 71 | } -------------------------------------------------------------------------------- /Blazor.JsonEditor/Component/Viewer/Item/JsonItemDefaultView.razor.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json.Nodes; 2 | using Microsoft.AspNetCore.Components; 3 | 4 | namespace Blazor.JsonEditor.Component.Viewer.Item 5 | { 6 | public partial class JsonItemDefaultView 7 | { 8 | [Parameter] 9 | public KeyValuePair JsonItem { get; set; } 10 | 11 | [Parameter] 12 | public JsonObject? JsonObject { get; set; } 13 | 14 | [Parameter] 15 | public EventCallback ValueChanged { get; set; } 16 | 17 | [Parameter] 18 | public Dictionary? KeyValues { get; set; } 19 | 20 | [Parameter] 21 | public bool AllowEdit { get; set; } = true; 22 | 23 | [Parameter] 24 | public Type? CustomEditor { get; set; } 25 | 26 | [Parameter] 27 | public Type? CustomItemView { get; set; } 28 | 29 | [Parameter] 30 | public Type? CustomObjectView { get; set; } 31 | 32 | private void JsonObjectUpdated(int index, string value) 33 | { 34 | var jsonValue = JsonItem.Value as JsonArray; 35 | 36 | jsonValue[index] = JsonNode.Parse(value); 37 | 38 | JsonItem = new KeyValuePair(JsonItem.Key, jsonValue); 39 | 40 | ValueChanged.InvokeAsync(JsonItem.Value.ToJsonString()); 41 | } 42 | } 43 | } 44 | 45 | -------------------------------------------------------------------------------- /Blazor.JsonEditor/Component/Viewer/Item/JsonItemDefaultView.razor.css: -------------------------------------------------------------------------------- 1 | .json-property-name { 2 | padding: 3px; 3 | color: brown; 4 | } 5 | 6 | .json-content { 7 | padding: 5px; 8 | border: 1px solid #ccc; 9 | } 10 | 11 | .json-value-content { 12 | padding: 3px; 13 | font-style: italic; 14 | } 15 | 16 | .json-value-string { 17 | color: darkgoldenrod; 18 | } 19 | 20 | .json-value-number { 21 | color: blueviolet; 22 | } 23 | 24 | .json-value-array { 25 | color: darkgreen; 26 | } -------------------------------------------------------------------------------- /Blazor.JsonEditor/Component/Viewer/Item/JsonItemView.razor: -------------------------------------------------------------------------------- 1 | @{ 2 | if (Component != null) 3 | { 4 | 5 | } 6 | else 7 | { 8 | 9 | } 10 | } -------------------------------------------------------------------------------- /Blazor.JsonEditor/Component/Viewer/Item/JsonItemView.razor.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json.Nodes; 2 | using Microsoft.AspNetCore.Components; 3 | 4 | namespace Blazor.JsonEditor.Component.Viewer.Item 5 | { 6 | public partial class JsonItemView 7 | { 8 | [Parameter] 9 | public Type? Component { get; set; } 10 | 11 | [Parameter] 12 | public KeyValuePair JsonItem { get; set; } 13 | 14 | [Parameter] 15 | public JsonObject? JsonObject { get; set; } 16 | 17 | [Parameter] 18 | public EventCallback ValueChanged { get; set; } 19 | 20 | [Parameter] 21 | public Dictionary? KeyValues { get; set; } 22 | 23 | [Parameter] 24 | public bool AllowEdit { get; set; } = true; 25 | 26 | [Parameter] 27 | public Type? CustomEditor { get; set; } 28 | 29 | [Parameter] 30 | public Type? CustomItemView { get; set; } 31 | 32 | [Parameter] 33 | public Type? CustomObjectView { get; set; } 34 | 35 | private Dictionary DynamicComponentParameters = new(); 36 | 37 | protected override async Task OnParametersSetAsync() 38 | { 39 | if (Component != null) 40 | { 41 | AddOrUpdateParameter("JsonItem", JsonItem); 42 | AddOrUpdateParameter("ValueChanged", ValueChanged); 43 | AddOrUpdateParameter("KeyValues", KeyValues); 44 | AddOrUpdateParameter("AllowEdit", AllowEdit); 45 | AddOrUpdateParameter("CustomEditor", CustomEditor); 46 | AddOrUpdateParameter("CustomItemView", CustomItemView); 47 | AddOrUpdateParameter("CustomObjectView", CustomObjectView); 48 | } 49 | } 50 | 51 | private void AddOrUpdateParameter(string key, object value) 52 | { 53 | if (DynamicComponentParameters.TryAdd(key, value)) 54 | { 55 | return; 56 | } 57 | 58 | DynamicComponentParameters.Remove(key); 59 | DynamicComponentParameters.TryAdd(key, value); 60 | } 61 | } 62 | } 63 | 64 | -------------------------------------------------------------------------------- /Blazor.JsonEditor/Component/Viewer/Object/JsonObjectDefaultView.razor: -------------------------------------------------------------------------------- 1 | "@JsonItem.Key" 2 | : 3 | 4 | { 5 | 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Blazor.JsonEditor/Component/Viewer/Object/JsonObjectDefaultView.razor.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json.Nodes; 2 | using Microsoft.AspNetCore.Components; 3 | 4 | namespace Blazor.JsonEditor.Component.Viewer.Object 5 | { 6 | public partial class JsonObjectDefaultView 7 | { 8 | 9 | [Parameter] 10 | public KeyValuePair JsonItem { get; set; } 11 | 12 | [Parameter] 13 | public JsonObject? JsonObject { get; set; } 14 | 15 | [Parameter] 16 | public EventCallback ValueChanged { get; set; } 17 | 18 | [Parameter] 19 | public Dictionary? KeyValues { get; set; } 20 | 21 | [Parameter] 22 | public bool AllowEdit { get; set; } = true; 23 | 24 | [Parameter] 25 | public Type? CustomEditor { get; set; } 26 | 27 | [Parameter] 28 | public Type? CustomItemView { get; set; } 29 | 30 | [Parameter] 31 | public Type? CustomObjectView { get; set; } 32 | 33 | } 34 | } 35 | 36 | -------------------------------------------------------------------------------- /Blazor.JsonEditor/Component/Viewer/Object/JsonObjectDefaultView.razor.css: -------------------------------------------------------------------------------- 1 | .json-property-name { 2 | padding: 3px; 3 | color: brown; 4 | } -------------------------------------------------------------------------------- /Blazor.JsonEditor/Component/Viewer/Object/JsonObjectView.razor: -------------------------------------------------------------------------------- 1 | @{ 2 | if (Component != null) 3 | { 4 | 5 | } 6 | else 7 | { 8 | 9 | } 10 | } -------------------------------------------------------------------------------- /Blazor.JsonEditor/Component/Viewer/Object/JsonObjectView.razor.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json.Nodes; 2 | using Microsoft.AspNetCore.Components; 3 | 4 | namespace Blazor.JsonEditor.Component.Viewer.Object 5 | { 6 | public partial class JsonObjectView 7 | { 8 | [Parameter] 9 | public Type? Component { get; set; } 10 | 11 | [Parameter] 12 | public KeyValuePair JsonItem { get; set; } 13 | 14 | [Parameter] 15 | public EventCallback ValueChanged { get; set; } 16 | 17 | [Parameter] 18 | public Dictionary? KeyValues { get; set; } 19 | 20 | [Parameter] 21 | public bool AllowEdit { get; set; } = true; 22 | 23 | [Parameter] 24 | public Type? CustomEditor { get; set; } 25 | 26 | [Parameter] 27 | public Type? CustomItemView { get; set; } 28 | 29 | [Parameter] 30 | public Type? CustomObjectView { get; set; } 31 | 32 | private Dictionary DynamicComponentParameters = new(); 33 | 34 | protected override async Task OnParametersSetAsync() 35 | { 36 | if (Component != null) 37 | { 38 | AddOrUpdateParameter("JsonItem", JsonItem); 39 | AddOrUpdateParameter("ValueChanged", ValueChanged); 40 | AddOrUpdateParameter("KeyValues", KeyValues); 41 | AddOrUpdateParameter("AllowEdit", AllowEdit); 42 | AddOrUpdateParameter("CustomEditor", CustomEditor); 43 | AddOrUpdateParameter("CustomItemView", CustomItemView); 44 | AddOrUpdateParameter("CustomObjectView", CustomObjectView); 45 | } 46 | } 47 | 48 | private void AddOrUpdateParameter(string key, object value) 49 | { 50 | if (DynamicComponentParameters.TryAdd(key, value)) 51 | { 52 | return; 53 | } 54 | 55 | DynamicComponentParameters.Remove(key); 56 | DynamicComponentParameters.TryAdd(key, value); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Blazor.JsonEditor/Helper/JsonHelper.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json; 2 | using System.Text.Json.Nodes; 3 | using Blazor.JsonEditor.Model; 4 | 5 | namespace Blazor.JsonEditor.Helper 6 | { 7 | public static class JsonHelper 8 | { 9 | public static bool IsInJsonValueKind(KeyValuePair jsonObjectValue, 10 | IEnumerable jsonValueKinds) 11 | { 12 | if (jsonObjectValue.Value == null) 13 | { 14 | return false; 15 | } 16 | 17 | var jsonElement = JsonSerializer.Deserialize(jsonObjectValue.Value.ToJsonString()); 18 | 19 | return jsonValueKinds.Any(x => jsonElement.ValueKind.Equals(x)); 20 | } 21 | 22 | public static bool IsObjectValueKind(KeyValuePair jsonObjectValue) 23 | { 24 | if (jsonObjectValue.Value == null) 25 | { 26 | return false; 27 | } 28 | 29 | var jsonElement = JsonSerializer.Deserialize(jsonObjectValue.Value.ToJsonString()); 30 | 31 | return jsonElement.ValueKind.Equals(JsonValueKind.Object); 32 | } 33 | 34 | public static void EditNodeValue(JsonObject jsonObject, JsonItem jsonItem, string editPropertyName) 35 | { 36 | switch (jsonItem.ValueKind) 37 | { 38 | case JsonValueKind.String when !string.IsNullOrWhiteSpace(jsonItem.Value): 39 | jsonObject[editPropertyName] = jsonItem.Value; 40 | break; 41 | case JsonValueKind.Number when jsonItem.NumericValue != null: 42 | jsonObject[editPropertyName] = jsonItem.NumericValue.Value; 43 | break; 44 | case JsonValueKind.Undefined: 45 | jsonObject[editPropertyName] = null; 46 | break; 47 | case JsonValueKind.Object: 48 | jsonObject[editPropertyName] = new JsonObject(); 49 | break; 50 | case JsonValueKind.Array when !jsonItem.ArrayType.Equals(JsonValueKind.Object): 51 | { 52 | List nodeArray = jsonItem.Value.Split(',').Select(x => JsonNode.Parse(x)).ToList(); 53 | 54 | jsonObject[editPropertyName] = new JsonArray(nodeArray.ToArray()); 55 | break; 56 | } 57 | case JsonValueKind.Array when jsonItem.ArrayType.Equals(JsonValueKind.Object): 58 | { 59 | var document = JsonDocument.Parse($"[{jsonItem.Value}]"); 60 | 61 | var jsonArray = new JsonArray(); 62 | foreach (var element in document.RootElement.EnumerateArray()) 63 | { 64 | jsonArray.Add(JsonNode.Parse(element.GetRawText())); 65 | } 66 | 67 | jsonObject[editPropertyName] = jsonArray; 68 | break; 69 | } 70 | case JsonValueKind.True when jsonItem.Value != null: 71 | jsonObject[editPropertyName] = Convert.ToBoolean(jsonItem.Value); 72 | break; 73 | case JsonValueKind.False: 74 | jsonObject[editPropertyName] = Convert.ToBoolean(jsonItem.Value); 75 | break; 76 | case JsonValueKind.Null: 77 | jsonObject[editPropertyName] = null; 78 | break; 79 | default: 80 | throw new ArgumentOutOfRangeException(); 81 | } 82 | } 83 | 84 | public static void AddNodeValue(JsonObject jsonObject, JsonItem jsonItem) 85 | { 86 | switch (jsonItem.ValueKind) 87 | { 88 | case JsonValueKind.String when !string.IsNullOrWhiteSpace(jsonItem.Value): 89 | jsonObject.Add(jsonItem.PropertyName, jsonItem.Value); 90 | break; 91 | case JsonValueKind.Number when jsonItem.NumericValue != null: 92 | jsonObject.Add(jsonItem.PropertyName, jsonItem.NumericValue.Value); 93 | break; 94 | case JsonValueKind.Undefined: 95 | jsonObject.Add(jsonItem.PropertyName, null); 96 | break; 97 | case JsonValueKind.Object: 98 | jsonObject.Add(jsonItem.PropertyName, new JsonObject()); 99 | break; 100 | case JsonValueKind.Array when !jsonItem.ArrayType.Equals(JsonValueKind.Object): 101 | { 102 | List nodeArray = jsonItem.Value.Split(',').Select(x => JsonNode.Parse(x)).ToList(); 103 | 104 | jsonObject.Add(jsonItem.PropertyName, new JsonArray(nodeArray.ToArray())); 105 | break; 106 | } 107 | case JsonValueKind.Array when jsonItem.ArrayType.Equals(JsonValueKind.Object): 108 | { 109 | var document = JsonDocument.Parse($"[{jsonItem.Value}]"); 110 | 111 | var jsonArray = new JsonArray(); 112 | foreach (var element in document.RootElement.EnumerateArray()) 113 | { 114 | jsonArray.Add(JsonNode.Parse(element.GetRawText())); 115 | } 116 | 117 | jsonObject.Add(jsonItem.PropertyName, jsonArray); 118 | break; 119 | } 120 | case JsonValueKind.True when jsonItem.Value != null: 121 | jsonObject.Add(jsonItem.PropertyName, Convert.ToBoolean(jsonItem.Value)); 122 | break; 123 | case JsonValueKind.False or JsonValueKind.Null when !string.IsNullOrEmpty(jsonItem.Value): 124 | { 125 | if (!jsonItem.Value.StartsWith("{")) 126 | { 127 | jsonItem.Value = "{" + jsonItem.Value + "}"; 128 | } 129 | 130 | var node = (JsonObject)JsonNode.Parse(jsonItem.Value); 131 | 132 | var pr = node.Select(x => x.Key).ToList(); 133 | if (pr?.Count > 0) 134 | { 135 | foreach (var pn in pr) 136 | { 137 | var jsNode = node.FirstOrDefault(x => x.Key.Equals(pn)).Value; 138 | jsonObject.Add(pn, jsNode.Root); 139 | } 140 | } 141 | 142 | break; 143 | } 144 | } 145 | } 146 | 147 | internal static bool IsShowComma(JsonObject json, KeyValuePair jsonItem) 148 | { 149 | if (json == null) 150 | { 151 | return false; 152 | } 153 | 154 | return !json.LastOrDefault().Key.Equals(jsonItem.Key); 155 | } 156 | } 157 | } -------------------------------------------------------------------------------- /Blazor.JsonEditor/LICENSE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Ivan Akimov 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Blazor.JsonEditor/Model/JsonItem.cs: -------------------------------------------------------------------------------- 1 | using Blazor.JsonEditor.Attribute; 2 | using System.Text.Json; 3 | 4 | namespace Blazor.JsonEditor.Model 5 | { 6 | public class JsonItem 7 | { 8 | [RequiredIf(nameof(JsonItem.ValueKind), JsonValueKind.Undefined, JsonValueKind.Number, JsonValueKind.String, 9 | JsonValueKind.Object, JsonValueKind.Array, JsonValueKind.True)] 10 | public string? PropertyName { get; set; } 11 | 12 | [RequiredIf(nameof(JsonItem.ValueKind), JsonValueKind.String, JsonValueKind.False, 13 | JsonValueKind.Null, JsonValueKind.True)] 14 | public string? Value { get; set; } 15 | 16 | [RequiredIf(nameof(JsonItem.ValueKind), JsonValueKind.Number)] 17 | public double? NumericValue { get; set; } 18 | 19 | [RequiredIf(nameof(JsonItem.ValueKind), JsonValueKind.Array)] 20 | public JsonValueKind ArrayType { get; set; } 21 | 22 | public JsonValueKind ValueKind { get; set; } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Blazor.JsonEditor/README.md: -------------------------------------------------------------------------------- 1 | # Blazor.JsonEditor 2 | Json Editor and Viewer for Blazor Server App and Wasm. Rewrited and working version of **[Blazoring.JsonEditor](https://github.com/vmakharashvili/Blazoring-JsonEditor)** 3 | 4 | ## Demo: 5 | 6 | [Click me to see the demo](https://66546b0fe74ef3008ca00fd0--cool-pasca-c1252e.netlify.app/) 7 | 8 | ## Json Editor and Viewer tool 9 | 10 | * To install the package run following command: 11 | 12 | **`Install-Package Blazor.JsonEditor`** 13 | or search **Blazor.JsonEditor** in Nuget gallery. 14 | 15 | This will install Blazor.JsonEditor in your project. You also need to add in **_Imports.razor**: 16 | ```html 17 | @using Blazor.JsonEditor.Component 18 | ``` 19 | Also, you need to add javascript file in _Host.cshtml ( Server app) or index.html ( Wasm) file: 20 | 21 | ```html 22 | 23 | ``` 24 | For icons suppor JsonEditor uses Font-Awesome icons library. You need to add link to _Host.cshtml ( Server app) or index.html ( Wasm) file: 25 | ```html 26 | 27 | ``` 28 | 29 | ### Using in code to have an editor: 30 | 31 | ```html 32 | 33 | 34 | 35 | ``` 36 | 37 | ### Using in code to have a viewer: 38 | 39 | ```html 40 | 41 | 42 | 43 | ``` 44 | 45 | Blazor.JsonEditor doesn't work without EditForm. Also, validation is required. 46 | 47 | # Customization 48 | 49 | ## Editor template: 50 | 51 | You can customize and pass your own editor template as dynamic component. Editor template is everything that you see after property name and value like buttons and editor window itself. For this you need to set parameter CustomEditor. As an example **CustomEditor="typeof([JsonItemCustomEditor](https://github.com/joghyrt/Blazor.JsonEditor/tree/main/Blazor.JsonEditor.Demo/Component))"** 52 | 53 | ```html 54 | 55 | 56 | 57 | ``` 58 | 59 | In your custom component you need to have parameters: 60 | 61 | ```c# 62 | //Main Json object 63 | [Parameter] 64 | public JsonObject? JsonObject { get; set; } 65 | 66 | //Event that you need to invoke on every object change 67 | [Parameter] 68 | public EventCallback JsonObjectChanged { get; set; } 69 | 70 | //Values for dropdown 71 | [Parameter] 72 | public Dictionary? KeyValues { get; set; } 73 | 74 | //Edit item in case of edit 75 | [Parameter] 76 | public KeyValuePair? JsonItemToEdit { get; set; } 77 | ``` 78 | 79 | Also on add and edit you need to pass data to **JsonHelper**. We have two methods for this: AddNodeValue and EditNodeValue 80 | 81 | ```c# 82 | public static void AddNodeValue(JsonObject jsonObject, JsonItem jsonItem) 83 | 84 | public static void EditNodeValue(JsonObject jsonObject, JsonItem jsonItem, string editPropertyName) 85 | ``` 86 | 87 | After Add/Edit/Delete do not forget to Invoke JsonObjectChanged 88 | 89 | ```c# 90 | await JsonObjectChanged.InvokeAsync(JsonObject); 91 | ``` 92 | 93 | ## View templates: 94 | 95 | You can customize view template for an item and an object. Item is key: value template. Object view template is an object template that contains a lot of items template in it. 96 | 97 | ```json 98 | { 99 | "Nullable" : null, //item view template 100 | "String" : "random", //item view template 101 | "Number" : 1, //item view template 102 | "Array" : [1,2,3], //item view template 103 | "True" : true, //item view template 104 | "False" : false, //item view template 105 | "Object" : { //!OBJECT! view template 106 | "Nullable" : null, //item view template 107 | "String" : "random", //item view template 108 | "Number" : 1, //item view template 109 | "Array" : [1,2,3], //item view template 110 | "True" : true, //item view template 111 | "False" : false //item view template 112 | } 113 | } 114 | ``` 115 | 116 | ### Item view template: 117 | 118 | ```html 119 | 120 | 121 | 122 | ``` 123 | 124 | In your custom component you need to have parameters: 125 | 126 | ```c# 127 | [Parameter] 128 | public KeyValuePair JsonItem { get; set; } 129 | ``` 130 | 131 | You can find example in repository. 132 | 133 | ### Object view template: 134 | 135 | ```html 136 | 137 | 138 | 139 | ``` 140 | 141 | In your custom component you need to have parameters: 142 | 143 | ```c# 144 | [Parameter] 145 | public KeyValuePair JsonItem { get; set; } 146 | 147 | [Parameter] 148 | public EventCallback ValueChanged { get; set; } 149 | 150 | [Parameter] 151 | public Dictionary? KeyValues { get; set; } 152 | 153 | [Parameter] 154 | public bool AllowEdit { get; set; } = true; 155 | 156 | [Parameter] 157 | public Type? CustomEditor { get; set; } 158 | 159 | [Parameter] 160 | public Type? CustomItemView { get; set; } 161 | 162 | [Parameter] 163 | public Type? CustomObjectView { get; set; } 164 | ``` 165 | 166 | Don't forget to include **InternalJsonEditor** inside you custom template to allow build lower object level. 167 | 168 | Example: 169 | 170 | ```html 171 | 178 | 179 | ``` 180 | 181 | You can find example in repository. 182 | 183 | ## Next steps 184 | 185 | - Refactor 186 | 187 | ## If you like it please support: 188 | 189 | [Buy me a coffee](https://www.buymeacoffee.com/joghyrt) 190 | 191 | [Ko-Fi](https://ko-fi.com/joghyrt) 192 | 193 | [GitHub](https://github.com/sponsors/joghyrt) 194 | -------------------------------------------------------------------------------- /Blazor.JsonEditor/_Imports.razor: -------------------------------------------------------------------------------- 1 |  2 | @using Microsoft.AspNetCore.Components.Forms 3 | @using Microsoft.AspNetCore.Components.Routing 4 | @using Microsoft.AspNetCore.Components.Web 5 | @using Microsoft.AspNetCore.Components.Web.Virtualization 6 | @using Microsoft.JSInterop -------------------------------------------------------------------------------- /Blazor.JsonEditor/wwwroot/Blazor.JsonEditor.js: -------------------------------------------------------------------------------- 1 | window.CopyToClipboard = (txt) => { 2 | var el = document.createElement('textarea'); 3 | el.value = txt; 4 | el.setAttribute('readonly', ''); 5 | document.body.appendChild(el); 6 | el.select(); 7 | document.execCommand('copy'); 8 | document.body.removeChild(el); 9 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Ivan Akimov 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Blazor.JsonEditor 2 | 3 | JSON Editor and Viewer ( with customization) for Blazor Server App and Wasm. Rewrited and working version of **[Blazoring.JsonEditor](https://github.com/vmakharashvili/Blazoring-JsonEditor)** 4 | 5 | ## Demo: 6 | 7 | [Click me to see the demo](https://66546b0fe74ef3008ca00fd0--cool-pasca-c1252e.netlify.app/) 8 | 9 | 10 | ## Json Editor and Viewer tool 11 | 12 | * To install the package run the following command: 13 | 14 | **`Install-Package Blazor.JsonEditor`** 15 | or search **Blazor.JsonEditor** in Nuget gallery. 16 | 17 | This will install Blazor.JsonEditor in your project. You also need to add in **_Imports.razor**: 18 | ```html 19 | @using Blazor.JsonEditor.Component 20 | ``` 21 | Also, you need to add a javascript file in _Host.cshtml ( Server app) or index.html ( Wasm) file: 22 | 23 | ```html 24 | 25 | ``` 26 | For icon support, JsonEditor uses the Font-Awesome icons library. You need to add a link to _Host.cshtml ( Server app) or index.html ( Wasm) file: 27 | ```html 28 | 29 | ``` 30 | 31 | ### Using in code to have an editor: 32 | 33 | ```html 34 | 35 | 38 | 39 | 40 | ``` 41 | 42 | ### Using in code to have a viewer: 43 | 44 | ```html 45 | 46 | 50 | 51 | 52 | ``` 53 | 54 | Blazor.JsonEditor doesn't work without EditForm. Also, validation is required. 55 | 56 | # Customization 57 | 58 | ## Editor template: 59 | 60 | You can customize and pass your own editor template as a dynamic component. The editor template is everything that you see after the property name and value like buttons and the editor window itself. For this, you need to set the parameter CustomEditor. As an example **CustomEditor="typeof([JsonItemCustomEditor](https://github.com/joghyrt/Blazor.JsonEditor/tree/main/Blazor.JsonEditor.Demo/Component))"** 61 | 62 | ```html 63 | 64 | 68 | 69 | 70 | ``` 71 | 72 | In your custom component you need to have parameters: 73 | 74 | ```c# 75 | //Main Json object 76 | [Parameter] 77 | public JsonObject? JsonObject { get; set; } 78 | 79 | //Event that you need to invoke on every object change 80 | [Parameter] 81 | public EventCallback JsonObjectChanged { get; set; } 82 | 83 | //Values for dropdown 84 | [Parameter] 85 | public Dictionary? KeyValues { get; set; } 86 | 87 | //Edit item in case of edit 88 | [Parameter] 89 | public KeyValuePair? JsonItemToEdit { get; set; } 90 | ``` 91 | 92 | Also on add and edit, you need to pass data to **JsonHelper**. We have two methods for this: AddNodeValue and EditNodeValue 93 | 94 | ```c# 95 | public static void AddNodeValue(JsonObject jsonObject, JsonItem jsonItem) 96 | 97 | public static void EditNodeValue(JsonObject jsonObject, JsonItem jsonItem, string editPropertyName) 98 | ``` 99 | 100 | After Add/Edit/Delete do not forget to Invoke JsonObjectChanged 101 | 102 | ```c# 103 | await JsonObjectChanged.InvokeAsync(JsonObject); 104 | ``` 105 | 106 | ## View templates: 107 | 108 | You can customize the view template for an item and an object. Item is key: value template. An object view template is an object template that contains a lot of items template in it. 109 | 110 | ```json 111 | { 112 | "Nullable" : null, //item view template 113 | "String" : "random", //item view template 114 | "Number" : 1, //item view template 115 | "Array" : [1,2,3], //item view template 116 | "True" : true, //item view template 117 | "False" : false, //item view template 118 | "Object" : { //!OBJECT! view template 119 | "Nullable" : null, //item view template 120 | "String" : "random", //item view template 121 | "Number" : 1, //item view template 122 | "Array" : [1,2,3], //item view template 123 | "True" : true, //item view template 124 | "False" : false //item view template 125 | } 126 | } 127 | ``` 128 | 129 | ### Item view template: 130 | 131 | ```html 132 | 133 | 137 | 138 | 139 | ``` 140 | 141 | In your custom component you need to have parameters: 142 | 143 | ```c# 144 | [Parameter] 145 | public KeyValuePair JsonItem { get; set; } 146 | ``` 147 | 148 | You can find an example in [repository](https://github.com/joghyrt/Blazor.JsonEditor/tree/main/Blazor.JsonEditor.Demo.Wasm/Component). 149 | 150 | ### Object view template: 151 | 152 | ```html 153 | 154 | 158 | 159 | 160 | ``` 161 | 162 | In your custom component you need to have parameters: 163 | 164 | ```c# 165 | [Parameter] 166 | public KeyValuePair JsonItem { get; set; } 167 | 168 | [Parameter] 169 | public EventCallback ValueChanged { get; set; } 170 | 171 | [Parameter] 172 | public Dictionary? KeyValues { get; set; } 173 | 174 | [Parameter] 175 | public bool AllowEdit { get; set; } = true; 176 | 177 | [Parameter] 178 | public Type? CustomEditor { get; set; } 179 | 180 | [Parameter] 181 | public Type? CustomItemView { get; set; } 182 | 183 | [Parameter] 184 | public Type? CustomObjectView { get; set; } 185 | ``` 186 | 187 | Don't forget to include **InternalJsonEditor** inside you custom template to allow build lower object level. 188 | 189 | Example: 190 | 191 | ```html 192 | 199 | 200 | ``` 201 | 202 | You can find an example in [repository](https://github.com/joghyrt/Blazor.JsonEditor/tree/main/Blazor.JsonEditor.Demo.Wasm/Component). 203 | 204 | ## Next steps 205 | 206 | - Refactor 207 | 208 | ## If you like it please support: 209 | 210 | [Buy me a coffee](https://www.buymeacoffee.com/joghyrt) 211 | 212 | bmc_qr 213 | 214 | 215 | [Donate](https://ko-fi.com/joghyrt) 216 | 217 | 218 | 219 | 220 | 221 | 222 | --------------------------------------------------------------------------------