Skip to content

Commit 036dbd7

Browse files
authored
fix(Editor): not throw exception when call reset method (#659)
* refactor: 增加 ClassString 样式 * refactor: 增加验证样式 * fix: 修复脚本报错问题 * refactor: 更细逻辑 * chore: bump version 9.0.9
1 parent 8fcad75 commit 036dbd7

5 files changed

Lines changed: 26 additions & 18 deletions

File tree

src/components/BootstrapBlazor.SummerNote/BootstrapBlazor.SummerNote.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

33
<PropertyGroup>
4-
<Version>9.0.8</Version>
4+
<Version>9.0.9</Version>
55
</PropertyGroup>
66

77
<PropertyGroup>

src/components/BootstrapBlazor.SummerNote/Components/Editor/Editor.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
{
88
<BootstrapLabel required="@Required" for="@Id" ShowLabelTooltip="ShowLabelTooltip" Value="@DisplayText" />
99
}
10-
<div @attributes="@AdditionalAttributes" id="@Id" class="editor" data-bb-submit="@ShowSubmitString">
10+
<div @attributes="@AdditionalAttributes" id="@Id" class="@ClassString" data-bb-submit="@ShowSubmitString">
1111
<div class="@EditClassString" placeholder="@PlaceHolder"></div>
1212
</div>

src/components/BootstrapBlazor.SummerNote/Components/Editor/Editor.razor.cs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ namespace BootstrapBlazor.Components;
1313
/// </summary>
1414
public partial class Editor
1515
{
16+
private string? ClassString => CssBuilder.Default("editor")
17+
.AddClass(CssClass).AddClass(ValidCss)
18+
.Build();
19+
1620
/// <summary>
1721
/// 获得 Editor 样式
1822
/// </summary>
@@ -182,20 +186,10 @@ protected override async Task InvokeInitAsync()
182186
/// </summary>
183187
/// <param name="value"></param>
184188
[JSInvokable]
185-
public async Task Update(string value)
189+
public void Update(string value)
186190
{
187-
Value = value;
188-
_lastValue = Value;
189-
190-
if (ValueChanged.HasDelegate)
191-
{
192-
await ValueChanged.InvokeAsync(Value);
193-
}
194-
195-
if (OnValueChanged != null)
196-
{
197-
await OnValueChanged.Invoke(value);
198-
}
191+
CurrentValue = value;
192+
_lastValue = value;
199193
}
200194

201195
/// <summary>

src/components/BootstrapBlazor.SummerNote/Components/Editor/Editor.razor.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import '../../js/summernote-bs5.min.js'
1+
import '../../js/summernote-bs5.min.js'
22
import { addLink, addScript } from '../../../BootstrapBlazor/modules/utility.js'
33
import Data from '../../../BootstrapBlazor/modules/data.js'
44
import EventHandler from '../../../BootstrapBlazor/modules/event-handler.js'
@@ -175,7 +175,11 @@ export function getCode(id) {
175175
}
176176

177177
export function reset(id) {
178-
const editor = Data.get(id)
178+
const editor = Data.get(id);
179+
if (!editor.$editor) {
180+
return;
181+
}
182+
179183
const context = editor.$editor.data('summernote')
180184

181185
const showSubmit = editor.el.getAttribute("data-bb-submit") === "true"

src/components/BootstrapBlazor.SummerNote/wwwroot/css/editor.css

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.editor .editor-body {
1+
.editor .editor-body {
22
cursor: pointer;
33
min-height: 50px;
44
height: auto;
@@ -58,6 +58,16 @@
5858
display: block;
5959
}
6060

61+
.editor.is-invalid .note-frame,
62+
.editor.is-invalid > .form-control {
63+
border: 1px solid var(--bs-danger) !important;
64+
}
65+
66+
.editor.is-valid .note-frame,
67+
.editor.is-valid > .form-control {
68+
border: 1px solid var(--bs-success) !important;
69+
}
70+
6171
.modal-body .note-form-group:not(:last-child) {
6272
margin-bottom: 0.5rem;
6373
}

0 commit comments

Comments
 (0)