diff --git a/BootstrapBlazor.sln b/BootstrapBlazor.sln index 169abe8d930ad660dc516bee1645b17328a8632d..9417a81444858ed4b7a0ed02db2abf39fc760199 100644 --- a/BootstrapBlazor.sln +++ b/BootstrapBlazor.sln @@ -120,7 +120,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BootstrapBlazor.AzureSpeech EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BootstrapBlazor.BaiduSpeech", "src\Extensions\Components\BootstrapBlazor.BaiduSpeech\BootstrapBlazor.BaiduSpeech.csproj", "{4ED606D8-D252-4573-8F0F-B69502ADB7ED}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BootstrapBlazor.SummerNote", "src\Extensions\Components\BootstrapBlazor.SummerNote\BootstrapBlazor.SummerNote.csproj", "{2FFC1564-EF75-454B-9D8E-A437A1737CEC}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BootstrapBlazor.SummerNote", "src\Extensions\Components\BootstrapBlazor.SummerNote\BootstrapBlazor.SummerNote.csproj", "{2FFC1564-EF75-454B-9D8E-A437A1737CEC}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitTestEditor", "test\UnitTestEditor\UnitTestEditor.csproj", "{9552B649-17E2-4BCA-8774-664C83A960CB}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -200,6 +202,10 @@ Global {2FFC1564-EF75-454B-9D8E-A437A1737CEC}.Debug|Any CPU.Build.0 = Debug|Any CPU {2FFC1564-EF75-454B-9D8E-A437A1737CEC}.Release|Any CPU.ActiveCfg = Release|Any CPU {2FFC1564-EF75-454B-9D8E-A437A1737CEC}.Release|Any CPU.Build.0 = Release|Any CPU + {9552B649-17E2-4BCA-8774-664C83A960CB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {9552B649-17E2-4BCA-8774-664C83A960CB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9552B649-17E2-4BCA-8774-664C83A960CB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {9552B649-17E2-4BCA-8774-664C83A960CB}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -233,6 +239,7 @@ Global {42108A8A-C773-4F35-A870-3673BDD383E4} = {CD062AB6-244D-402A-8F33-C37DAC5856CC} {4ED606D8-D252-4573-8F0F-B69502ADB7ED} = {CD062AB6-244D-402A-8F33-C37DAC5856CC} {2FFC1564-EF75-454B-9D8E-A437A1737CEC} = {CD062AB6-244D-402A-8F33-C37DAC5856CC} + {9552B649-17E2-4BCA-8774-664C83A960CB} = {7C1D79F1-87BC-42C1-BD5A-CDE4044AC1BD} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {0DCB0756-34FA-4FD0-AE1D-D3F08B5B3A6B} diff --git a/src/BootstrapBlazor.Shared/BootstrapBlazor.Shared.csproj b/src/BootstrapBlazor.Shared/BootstrapBlazor.Shared.csproj index f24dbc8eeae0a4239f9bc50d9ff3ae4207f61fc9..8997d09f3adb6e13c4c475bb84c29c79af6dfb6f 100644 --- a/src/BootstrapBlazor.Shared/BootstrapBlazor.Shared.csproj +++ b/src/BootstrapBlazor.Shared/BootstrapBlazor.Shared.csproj @@ -18,7 +18,7 @@ - + diff --git a/src/BootstrapBlazor.Shared/Locales/en.json b/src/BootstrapBlazor.Shared/Locales/en.json index a36b2309430012a39becdf2b6206b99fc2818aa6..c90a7af4951d6477a45158bce8d16cf7c3108531 100644 --- a/src/BootstrapBlazor.Shared/Locales/en.json +++ b/src/BootstrapBlazor.Shared/Locales/en.json @@ -1070,7 +1070,7 @@ "BootstrapBlazor.Shared.Samples.Editors": { "Title": "Editor", "H1": "Convert the entered text into html code snippets", - "P1": "The Editor component is a secondary package of Summernote component, such as If you need to use the localization function, please download the corresponding language pack from the official website and quote it by yourself", + "P1": "The Editor component is a secondary package of Summernote component, such as If you need to use the localization function, please download the corresponding language pack from the official website and quote it by yourself. zh-CN en-US has been built in;the required css javascript dynamically loaded on demand", "Block1Title": "Basic usage", "Block1Intro": "The default rendering is div and it becomes a rich text edit box when clicked", "P2": "Set the IsEditor attribute value to control whether the component defaults to div or editor", diff --git a/src/BootstrapBlazor.Shared/Locales/zh.json b/src/BootstrapBlazor.Shared/Locales/zh.json index ff252379d09bb76c82900c55ba5749cbc6dfcf30..93ebc782ae6850ed35e9e19c8449ec68edabe85b 100644 --- a/src/BootstrapBlazor.Shared/Locales/zh.json +++ b/src/BootstrapBlazor.Shared/Locales/zh.json @@ -1070,7 +1070,7 @@ "BootstrapBlazor.Shared.Samples.Editors": { "Title": "Editor 富文本框", "H1": "将输入的文字转化为 html 代码片段", - "P1": "Editor 组件是对 Summernote 组件 的二次封装,如需使用本地化功能请自行官网下载相对应语言包,自行引用即可", + "P1": "Editor 组件是对 Summernote 组件 的二次封装,如需使用本地化功能请自行官网下载相对应语言包,自行引用即可,zh-CN en-US 已内置;组件所需 css javascript 均按需动态加载,使用者无需设置", "Block1Title": "基础用法", "Block1Intro": "默认呈现为 div 点击后变为富文本编辑框", "P2": "通过设置 IsEditor 属性值来控制组件默认是 div 还是 editor", diff --git a/src/BootstrapBlazor.Shared/Samples/Editors.razor b/src/BootstrapBlazor.Shared/Samples/Editors.razor index 394aef2ab0fdaddfd01343fe28adc26a439a1a86..1e0e0e77189e6ff399ec811ef24ec295cf873375 100644 --- a/src/BootstrapBlazor.Shared/Samples/Editors.razor +++ b/src/BootstrapBlazor.Shared/Samples/Editors.razor @@ -1,5 +1,6 @@ @page "/editors" @inject SwalService SwalService +@inject VersionService VersionManager @inject IStringLocalizer Localizer

@Localizer["Title"]

@@ -8,6 +9,15 @@

@((MarkupString)Localizer["P1"].Value)

+
.NET CLI
+
dotnet add package BootstrapBlazor.SummerNote --version @Version
+ +
PackageReference
+
<PackageReference Include="BootstrapBlazor.SummerNote" Version="@Version" />
+ +
Package Manager
+
Install-Package BootstrapBlazor.SummerNote -Version @Version
+

@((MarkupString)Localizer["P2"].Value)

@((MarkupString)Localizer["Div1"].Value)
diff --git a/src/BootstrapBlazor.Shared/Samples/Editors.razor.cs b/src/BootstrapBlazor.Shared/Samples/Editors.razor.cs index d791639ced2c5ecc867040d6636370b359109c90..0256ae52486c8923a15617d48c789fce3a2b62a2 100644 --- a/src/BootstrapBlazor.Shared/Samples/Editors.razor.cs +++ b/src/BootstrapBlazor.Shared/Samples/Editors.razor.cs @@ -12,11 +12,25 @@ namespace BootstrapBlazor.Shared.Samples; /// public sealed partial class Editors { + /// + /// 获得/设置 版本号字符串 + /// + private string Version { get; set; } = "fetching"; + private string? EditorValue { get; set; } [NotNull] private Editor? Editor { get; set; } + /// + /// OnInitializedAsync 方法 + /// + /// + protected override async Task OnInitializedAsync() + { + Version = await VersionManager.GetVersionAsync("bootstrapblazor.summernote"); + } + private Task OnValueChanged(string val) { EditorValue = val; diff --git a/src/BootstrapBlazor/Components/EditorForm/EditorForm.razor.cs b/src/BootstrapBlazor/Components/EditorForm/EditorForm.razor.cs index 884d108127e9605f31ad928f0a4eaed50f35d7ac..d2fe81e1353ac419cee00e1f9c907d1d807fdb64 100644 --- a/src/BootstrapBlazor/Components/EditorForm/EditorForm.razor.cs +++ b/src/BootstrapBlazor/Components/EditorForm/EditorForm.razor.cs @@ -14,7 +14,7 @@ namespace BootstrapBlazor.Components; #if NET6_0_OR_GREATER [CascadingTypeParameter(nameof(TModel))] #endif -public sealed partial class EditorForm : IShowLabel +public partial class EditorForm : IShowLabel { /// /// 支持每行多少个控件功能 diff --git a/test/UnitTest/Components/EditorTest.cs b/test/UnitTest/Components/EditorTest.cs deleted file mode 100644 index c42e2c016a89ab85d50fef205087f8797cd22843..0000000000000000000000000000000000000000 --- a/test/UnitTest/Components/EditorTest.cs +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright (c) Argo Zhang (argo@163.com). All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -// Website: https://www.blazor.zone or https://argozhang.github.io/ - -using BootstrapBlazor.Shared; - -namespace UnitTest.Components; - -public class EditorTest : BootstrapBlazorTestBase -{ - //[Fact] - //public async Task Editor_Ok() - //{ - // var value = new Foo(); - // var cut = Context.RenderComponent(pb => - // { - // pb.Add(a => a.Value, value.Name); - // pb.Add(a => a.ValueChanged, v => value.Name = v); - // pb.Add(a => a.IsEditor, false); - // pb.Add(a => a.Height, 200); - // }); - - // await cut.InvokeAsync(() => cut.Instance.Update("Test")); - // Assert.Equal("Test", value.Name); - - // cut.SetParametersAndRender(pb => - // { - // pb.Add(a => a.OnValueChanged, v => - // { - // value.Name = v; - // return Task.CompletedTask; - // }); - // }); - - // await cut.InvokeAsync(() => cut.Instance.Update("Test1")); - // Assert.Equal("Test1", value.Name); - //} - - //[Fact] - //public async Task CustomerToolbarButtons_Ok() - //{ - // var cut = Context.RenderComponent(pb => - // { - // pb.Add(a => a.Value, "Test"); - // pb.Add(a => a.CustomerToolbarButtons, new EditorToolbarButton[] - // { - // new EditorToolbarButton() - // { - // ButtonName = "Test1", - // IconClass = "Class1", - // Tooltip = "Tooltip1" - // } - // }); - // }); - - // IEnumerable? buttons = null; - // await cut.InvokeAsync(async () => buttons = await cut.Instance.GetToolBar()); - // Assert.NotNull(buttons); - - // IEnumerable? btns = null; - // await cut.InvokeAsync(async () => btns = await cut.Instance.GetPluginAttrs()); - // Assert.Single(btns); - // Assert.Equal("Class1", btns!.First().IconClass); - // Assert.Equal("Tooltip1", btns!.First().Tooltip); - - // var name = ""; - // cut.SetParametersAndRender(pb => - // { - // pb.Add(a => a.OnClickButton, v => - // { - // return Task.FromResult("Test"); - // }); - // pb.Add(a => a.Value, null); - // }); - // await cut.InvokeAsync(async () => name = await cut.Instance.ClickPluginItem("Test1")); - // Assert.Equal("Test", name); - //} - - //[Fact] - //public void DoMethodAysnc_Ok() - //{ - // var cut = Context.RenderComponent(pb => - // { - // pb.Add(a => a.Value, "Test"); - // }); - // cut.Instance.DoMethodAysnc("test", new object[] { "1" }); - //} -} diff --git a/test/UnitTestEditor/EditorTest.cs b/test/UnitTestEditor/EditorTest.cs new file mode 100644 index 0000000000000000000000000000000000000000..71d8bb6eded7f72cc1a6d96084adcd78903386bf --- /dev/null +++ b/test/UnitTestEditor/EditorTest.cs @@ -0,0 +1,88 @@ +// Copyright (c) Argo Zhang (argo@163.com). All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// Website: https://www.blazor.zone or https://argozhang.github.io/ + +using BootstrapBlazor.Shared; + +namespace UnitTest.Components; + +public class EditorTest : Core.BootstrapBlazorTestBase +{ + [Fact] + public async Task Editor_Ok() + { + var value = new Foo(); + var cut = Context.RenderComponent(pb => + { + pb.Add(a => a.Value, value.Name); + pb.Add(a => a.ValueChanged, v => value.Name = v); + pb.Add(a => a.IsEditor, false); + pb.Add(a => a.Height, 200); + }); + + await cut.InvokeAsync(() => cut.Instance.Update("Test")); + Assert.Equal("Test", value.Name); + + cut.SetParametersAndRender(pb => + { + pb.Add(a => a.OnValueChanged, v => + { + value.Name = v; + return Task.CompletedTask; + }); + }); + + await cut.InvokeAsync(() => cut.Instance.Update("Test1")); + Assert.Equal("Test1", value.Name); + } + + [Fact] + public async Task CustomerToolbarButtons_Ok() + { + var cut = Context.RenderComponent(pb => + { + pb.Add(a => a.Value, "Test"); + pb.Add(a => a.CustomerToolbarButtons, new EditorToolbarButton[] + { + new EditorToolbarButton() + { + ButtonName = "Test1", + IconClass = "Class1", + Tooltip = "Tooltip1" + } + }); + }); + + IEnumerable? buttons = null; + await cut.InvokeAsync(async () => buttons = await cut.Instance.GetToolBar()); + Assert.NotNull(buttons); + + IEnumerable? btns = null; + await cut.InvokeAsync(async () => btns = await cut.Instance.GetPluginAttrs()); + Assert.Single(btns); + Assert.Equal("Class1", btns!.First().IconClass); + Assert.Equal("Tooltip1", btns!.First().Tooltip); + + var name = ""; + cut.SetParametersAndRender(pb => + { + pb.Add(a => a.OnClickButton, v => + { + return Task.FromResult("Test"); + }); + pb.Add(a => a.Value, null); + }); + await cut.InvokeAsync(async () => name = await cut.Instance.ClickPluginItem("Test1")); + Assert.Equal("Test", name); + } + + [Fact] + public void DoMethodAysnc_Ok() + { + var cut = Context.RenderComponent(pb => + { + pb.Add(a => a.Value, "Test"); + }); + cut.Instance.DoMethodAysnc("test", new object[] { "1" }); + } +} diff --git a/test/UnitTestEditor/UnitTestEditor.csproj b/test/UnitTestEditor/UnitTestEditor.csproj new file mode 100644 index 0000000000000000000000000000000000000000..f1fde5c24f6e7b42bf605ccb0aa1cc84560b3033 --- /dev/null +++ b/test/UnitTestEditor/UnitTestEditor.csproj @@ -0,0 +1,27 @@ + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + + + + + + + + + +