Skip to content

Commit a85cd0c

Browse files
authored
doc(Editor): add sample code for GetCode method (#4813)
* chore: 更新 Editor 依赖包 * doc(Editor): 增加直接代码获得组件内容方法
1 parent 1aa380d commit a85cd0c

File tree

5 files changed

+41
-23
lines changed

5 files changed

+41
-23
lines changed

src/BootstrapBlazor.Shared/BootstrapBlazor.Shared.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
<PackageReference Include="BootstrapBlazor.FileViewer" Version="9.0.0" />
3535
<PackageReference Include="BootstrapBlazor.FontAwesome" Version="9.0.1" />
3636
<PackageReference Include="BootstrapBlazor.Gantt" Version="9.0.0" />
37-
<PackageReference Include="BootstrapBlazor.Holiday" Version="9.0.0" />
37+
<PackageReference Include="BootstrapBlazor.Holiday" Version="9.0.1" />
3838
<PackageReference Include="BootstrapBlazor.Html2Pdf" Version="9.0.0" />
3939
<PackageReference Include="BootstrapBlazor.IconPark" Version="9.0.0" />
4040
<PackageReference Include="BootstrapBlazor.ImageCropper" Version="9.0.0" />
@@ -53,7 +53,7 @@
5353
<PackageReference Include="BootstrapBlazor.Sortable" Version="9.0.1" />
5454
<PackageReference Include="BootstrapBlazor.Splitting" Version="9.0.1" />
5555
<PackageReference Include="BootstrapBlazor.SvgEditor" Version="9.0.0" />
56-
<PackageReference Include="BootstrapBlazor.SummerNote" Version="9.0.1" />
56+
<PackageReference Include="BootstrapBlazor.SummerNote" Version="9.0.2" />
5757
<PackageReference Include="BootstrapBlazor.TableExport" Version="9.0.0" />
5858
<PackageReference Include="BootstrapBlazor.Topology" Version="9.0.0" />
5959
<PackageReference Include="BootstrapBlazor.VideoPlayer" Version="9.0.2" />

src/BootstrapBlazor.Shared/Components/Samples/Editors.razor

+28-19
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,24 @@
1616
<PackageTips Name="BootstrapBlazor.SummerNote" />
1717

1818
<DemoBlock Title="@Localizer["EditorNormalTitle"]" Introduction="@Localizer["EditorNormalIntro"]" Name="Normal">
19-
<p>@((MarkupString)Localizer["EditorNormalDescription"].Value)</p>
20-
<div class="form-control mb-3">@((MarkupString)Localizer["EditorNormalDiv"].Value)</div>
19+
<section ignore>
20+
<p>@((MarkupString)Localizer["EditorNormalDescription"].Value)</p>
21+
<div class="form-control mb-3">@((MarkupString)Localizer["EditorNormalDiv"].Value)</div>
22+
</section>
2123
<Editor />
2224
</DemoBlock>
2325

2426
<DemoBlock Title="@Localizer["EditorSubmitTitle"]" Introduction="@Localizer["EditorSubmitIntro"]" Name="Submit">
25-
<p>@((MarkupString)Localizer["EditorSubmitDescription"].Value)</p>
26-
<Button Text="@ButtonText" OnClick="ShowSubmit" class="mb-3"></Button>
27+
<section ignore>
28+
<p>@((MarkupString)Localizer["EditorSubmitDescription"].Value)</p>
29+
<Button Text="@ButtonText" OnClick="ShowSubmit" class="mb-3"></Button>
30+
<textarea class="form-control mt-3">@EditorValue</textarea>
31+
</section>
2732
<Editor @bind-Value="@EditorValue" IsEditor="true" ShowSubmit="ShowSubmitButton" />
28-
<textarea class="form-control mt-3">@EditorValue</textarea>
2933
</DemoBlock>
3034

3135
<DemoBlock Title="@Localizer["EditorPlaceholderTitle"]" Introduction="@Localizer["EditorPlaceholderIntro"]" Name="Placeholder">
32-
<p>@((MarkupString)Localizer["EditorPlaceholderDescription"].Value)</p>
36+
<section ignore>@((MarkupString)Localizer["EditorPlaceholderDescription"].Value)</section>
3337
<Editor PlaceHolder="@Localizer["EditorEmptyPlaceholder"]" />
3438
</DemoBlock>
3539

@@ -42,34 +46,39 @@
4246
</DemoBlock>
4347

4448
<DemoBlock Title="@Localizer["EditorOnValueChangedTitle"]" Introduction="@Localizer["EditorOnValueChangedIntro"]" Name="OnValueChanged">
45-
<p>@((MarkupString)Localizer["EditorOnValueChangedDescription"].Value)</p>
49+
<section ignore>@((MarkupString)Localizer["EditorOnValueChangedDescription"].Value)</section>
4650
<Editor @bind-Value="@ValueChangedValue" />
47-
48-
<label class="form-label mt-3">@Localizer["EditorOnValueChangedLabel"]</label>
49-
<textarea class="form-control mt-3">@ValueChangedValue</textarea>
50-
<div class="mt-3">
51-
<Button OnClick="SetValue">Reset</Button>
52-
</div>
51+
<section ignore>
52+
<label class="form-label mt-3">@Localizer["EditorOnValueChangedLabel"]</label>
53+
<textarea class="form-control mt-3">@ValueChangedValue</textarea>
54+
<div class="mt-3">
55+
<Button OnClick="SetValue">Reset</Button>
56+
</div>
57+
</section>
5358
</DemoBlock>
5459

5560
<DemoBlock Title="@Localizer["EditorCustomerToolbarButtonsTitle"]" Introduction="@Localizer["EditorCustomerToolbarButtonsIntro"]" Name="CustomerToolbarButtons">
56-
<p>@((MarkupString)Localizer["EditorCustomerToolbarButtonsDescription"].Value)</p>
61+
<section ignore>@((MarkupString)Localizer["EditorCustomerToolbarButtonsDescription"].Value)</section>
5762
<Editor IsEditor="true" OnClickButton="@PluginClick" CustomerToolbarButtons="@EditorPluginItems" />
5863
</DemoBlock>
5964

6065
<DemoBlock Title="@Localizer["EditorToolbarItemsTitle"]" Introduction="@Localizer["EditorToolbarItemsIntro"]" Name="ToolbarItems">
61-
<p>@((MarkupString)Localizer["EditorToolbarItemsDescription"].Value)</p>
66+
<section ignore>@((MarkupString)Localizer["EditorToolbarItemsDescription"].Value)</section>
6267
<Editor IsEditor="true" ToolbarItems="@ToolbarItems" />
6368
</DemoBlock>
6469

65-
<DemoBlock Title="@Localizer["DoMethodAsync"]" Introduction="@Localizer["DoMethodAsyncIntro"]" Name="DoMethodAsync">
66-
<p>@((MarkupString)Localizer["DoMethodAsyncDescription"].Value)</p>
70+
<DemoBlock Title="@Localizer["DoMethodAsyncTitle"]" Introduction="@Localizer["DoMethodAsyncIntro"]" Name="DoMethodAsync">
71+
<section ignore>@((MarkupString)Localizer["DoMethodAsyncDescription"].Value)</section>
6772
<Editor IsEditor="true" @ref="Editor" />
68-
<div class="mt-3">
73+
<section ignore class="mt-3">
6974
<Button OnClick="InsertHtmlAsync">@Localizer["DoMethodAsyncButton1"]</Button>
7075
<Button OnClick="@(async () => await Editor.DoMethodAsync("formatH2", ""))">@Localizer["DoMethodAsyncButton2"]</Button>
7176
<Button OnClick="@(async () => await Editor.DoMethodAsync("insertImage", "https://www.blazor.zone/images/avatars/150-1.jpg", "tree"))">@Localizer["DoMethodAsyncButton3"]</Button>
72-
</div>
77+
<Button OnClick="@OnGetCode">@Localizer["DoMethodAsyncButton4"]</Button>
78+
</section>
79+
<section ignore>
80+
<textarea class="form-control" rows="3" readonly>@_editorCode</textarea>
81+
</section>
7382
</DemoBlock>
7483

7584
<AttributeTable Items="@GetAttributes()" />

src/BootstrapBlazor.Shared/Components/Samples/Editors.razor.cs

+7
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,13 @@ private async Task InsertHtmlAsync()
111111
await Editor.DoMethodAsync("pasteHTML", $"<h1>{Localizer["DoMethodAsyncPasteHTML"]}</h1>");
112112
}
113113

114+
private string? _editorCode;
115+
116+
private async Task OnGetCode()
117+
{
118+
_editorCode = await Editor.GetCode();
119+
}
120+
114121
private AttributeItem[] GetAttributes() =>
115122
[
116123
new()

src/BootstrapBlazor.Shared/Locales/en-US.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -2597,7 +2597,7 @@
25972597
"Att3": "Component height",
25982598
"Att4": "Rich Text Box Toolbar Tool",
25992599
"Att5": "Custom button",
2600-
"DoMethodAsync": "Instance Method",
2600+
"DoMethodAsyncTitle": "Instance Method",
26012601
"DoMethodAsyncIntro": "Call the instance method, please refer <a href='https://summernote.org/deep-dive'>summernote api</a>",
26022602
"DoMethodAsyncDescription": "In this example, by setting the <code>ToolbarItems</code> property, the default available toolbar buttons are changed",
26032603
"EditorEmptyPlaceholder": "Customize the prompt message for empty values",
@@ -2615,6 +2615,7 @@
26152615
"DoMethodAsyncButton1": "Insert Html",
26162616
"DoMethodAsyncButton2": "Update to H2",
26172617
"DoMethodAsyncButton3": "Insert Image",
2618+
"DoMethodAsyncButton4": "Get Code",
26182619
"DoMethodAsyncPasteHTML": "Here is the content inserted by the external button"
26192620
},
26202621
"BootstrapBlazor.Shared.Components.Samples.EditorForms": {

src/BootstrapBlazor.Shared/Locales/zh-CN.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -2597,7 +2597,7 @@
25972597
"Att3": "组件高度",
25982598
"Att4": "富文本框工具栏工具",
25992599
"Att5": "自定义按钮",
2600-
"DoMethodAsync": "实例方法",
2600+
"DoMethodAsyncTitle": "实例方法",
26012601
"DoMethodAsyncIntro": "使用实例方法从外部操作 <code>Editor</code>,具体的参数参照 <a href='https://summernote.org/deep-dive'>summernote api</a>",
26022602
"DoMethodAsyncDescription": "本例中通过设置 <code>ToolbarItems</code> 属性,更改默认可用的工具栏按钮",
26032603
"EditorEmptyPlaceholder": "自定义空值的提示信息",
@@ -2615,6 +2615,7 @@
26152615
"DoMethodAsyncButton1": "插入一段 Html",
26162616
"DoMethodAsyncButton2": "将段落修改为 H2",
26172617
"DoMethodAsyncButton3": "添加一张图片",
2618+
"DoMethodAsyncButton4": "获得组件内容",
26182619
"DoMethodAsyncPasteHTML": "这里是外部按钮插入的内容"
26192620
},
26202621
"BootstrapBlazor.Shared.Components.Samples.EditorForms": {

0 commit comments

Comments
 (0)