-
-
Notifications
You must be signed in to change notification settings - Fork 363
feat(Vditor): add Vditor component #6228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
70d0f62
doc: 更新示例说明文档
ArgoZhang 47af8a0
doc: 增加示例文档
ArgoZhang d705fb2
test: 增加单元测试
ArgoZhang ecac050
doc: 增加菜单
ArgoZhang de76d81
doc: 增加源码映射
ArgoZhang 202371f
doc: 增加方法示例
ArgoZhang 9558211
refactor: 更新 Pre 样式
ArgoZhang 01c9de8
doc: 更新 Vditor 组件示例
ArgoZhang 2651814
chore: 增加 Vditor 依赖
ArgoZhang 699b4a7
Merge branch 'main' into feat-vditor
ArgoZhang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/BootstrapBlazor.Server/Components/Samples/Vditors.razor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,54 @@ | ||||||||||||||
| @page "/vditor" | ||||||||||||||
| @inject IOptionsMonitor<WebsiteOptions> WebsiteOption | ||||||||||||||
|
|
||||||||||||||
| <h3>@Localizer["VditorTitle"]</h3> | ||||||||||||||
|
|
||||||||||||||
| <h4>@Localizer["VditorSubTitle"]</h4> | ||||||||||||||
|
|
||||||||||||||
| <PackageTips Name="BootstrapBlazor.Vditor" /> | ||||||||||||||
|
|
||||||||||||||
| <p>@((MarkupString)Localizer["MarkdownsNote"].Value)</p> | ||||||||||||||
|
|
||||||||||||||
| <Pre class="no-highlight">builder.Services.Configure<HubOptions>(option => option.MaximumReceiveMessageSize = null);</Pre> | ||||||||||||||
|
|
||||||||||||||
| <DemoBlock Title="@Localizer["BaseUsageTitle"]" Introduction="@Localizer["BaseUsageIntro"]" Name="Normal"> | ||||||||||||||
| <section ignore class="row g-3"> | ||||||||||||||
| <div class="col-12"> | ||||||||||||||
| <BootstrapInputGroup> | ||||||||||||||
| <BootstrapInputGroupLabel DisplayText="Mode"></BootstrapInputGroupLabel> | ||||||||||||||
| <Segmented Value="_mode" OnValueChanged="OnModeChanged"> | ||||||||||||||
| @foreach (var item in Enum.GetValues(typeof(VditorMode)).Cast<VditorMode>()) | ||||||||||||||
| { | ||||||||||||||
| <SegmentedItem Value="@item" Text="@item.ToString()" /> | ||||||||||||||
| } | ||||||||||||||
| </Segmented> | ||||||||||||||
| </BootstrapInputGroup> | ||||||||||||||
| </div> | ||||||||||||||
| <div class="col-12"> | ||||||||||||||
| <Button Text="GetValue" OnClick="OnTriggerGetValueAsync" IsDisabled="_isDisabled"></Button> | ||||||||||||||
| <Button Text="InsertValue" OnClick="OnTriggerInsertValueAsync" IsDisabled="_isDisabled"></Button> | ||||||||||||||
| <Button Text="GetHtml" OnClick="OnTriggerGetHtmlAsync" IsDisabled="_isDisabled"></Button> | ||||||||||||||
| <Button Text="GetSelection" OnClick="OnTriggerGetSelectionAsync" IsDisabled="_isDisabled"></Button> | ||||||||||||||
| <Button Text="Enable" OnClick="OnTriggerEnableAsync" IsDisabled="!_isDisabled"></Button> | ||||||||||||||
| <Button Text="Disable" OnClick="OnTriggerDisableAsync" IsDisabled="_isDisabled"></Button> | ||||||||||||||
| <Button Text="Focus" OnClick="OnTriggerFocusAsync" IsDisabled="_isDisabled"></Button> | ||||||||||||||
| <Button Text="Blur" OnClick="OnTriggerBlurAsync" IsDisabled="_isDisabled"></Button> | ||||||||||||||
| </div> | ||||||||||||||
| </section> | ||||||||||||||
| <Vditor Value="@_vditorValueString" Options="_vditorOptions" @ref="_vditor" | ||||||||||||||
| OnRenderedAsync="OnRenderAsync" | ||||||||||||||
| OnFocusAsync="OnFocusAsync" OnBlurAsync="OnBlurAsync" | ||||||||||||||
| OnEscapeAsync="OnEscapeAsync" OnCtrlEnterAsync="OnCtrlEnterAsync" | ||||||||||||||
| OnSelectAsync="OnSelectAsync" OnInputAsync="OnInputAsync"></Vditor> | ||||||||||||||
| <section ignore class="mt-3"> | ||||||||||||||
| <p> | ||||||||||||||
| <textarea class="form-control" rows="6" disabled="disabled">@_vditorValueString</textarea> | ||||||||||||||
| </p> | ||||||||||||||
| <p> | ||||||||||||||
| <textarea class="form-control" rows="6" disabled="disabled"> @_htmlString</textarea> | ||||||||||||||
| </p> | ||||||||||||||
|
Comment on lines
+47
to
+49
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: Remove leading space before binding The whitespace before
Suggested change
|
||||||||||||||
| <ConsoleLogger @ref="_logger"></ConsoleLogger> | ||||||||||||||
| </section> | ||||||||||||||
| </DemoBlock> | ||||||||||||||
|
|
||||||||||||||
| <AttributeTable Items="GetAttributes()" /> | ||||||||||||||
195 changes: 195 additions & 0 deletions
195
src/BootstrapBlazor.Server/Components/Samples/Vditors.razor.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,195 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the Apache 2.0 License | ||
| // See the LICENSE file in the project root for more information. | ||
| // Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone | ||
|
|
||
| namespace BootstrapBlazor.Server.Components.Samples; | ||
|
|
||
| /// <summary> | ||
| /// Vditors 组件示例代码 | ||
| /// </summary> | ||
| public partial class Vditors | ||
| { | ||
| [Inject] | ||
| [NotNull] | ||
| private IStringLocalizer<Vditors>? Localizer { get; set; } | ||
|
|
||
| private VditorOptions _vditorOptions = new() | ||
| { | ||
| Height = "500px" | ||
| }; | ||
|
|
||
| private Vditor _vditor = default!; | ||
| private string? _htmlString; | ||
| private string _vditorValueString = "## 所见即所得(WYSIWYG)\n所见即所得模式对不熟悉 Markdown 的用户较为友好,熟悉 Markdown 的话也可以无缝使用。"; | ||
| private VditorMode _mode = VditorMode.WYSIWYG; | ||
| private ConsoleLogger _logger = default!; | ||
|
|
||
| private async Task OnModeChanged(VditorMode mode) | ||
| { | ||
| _mode = mode; | ||
| _vditorOptions.Mode = mode; | ||
| if (mode == VditorMode.WYSIWYG) | ||
| { | ||
| _vditorValueString = "## 所见即所得(WYSIWYG)\n所见即所得模式对不熟悉 Markdown 的用户较为友好,熟悉 Markdown 的话也可以无缝使用。"; | ||
| } | ||
| else if (mode == VditorMode.IR) | ||
| { | ||
| _vditorValueString = "## 即时渲染(IR)\n即时渲染模式对熟悉 Typora 的用户应该不会感到陌生,理论上这是最优雅的 Markdown 编辑方式。"; | ||
| } | ||
| else if (mode == VditorMode.SV) | ||
| { | ||
| _vditorValueString = "## 分屏预览(SV)\n传统的分屏预览模式适合大屏下的 Markdown 编辑。"; | ||
| } | ||
|
|
||
| _htmlString = await _vditor.GetHtmlAsync(); | ||
| StateHasChanged(); | ||
| } | ||
|
|
||
| private Task OnRenderAsync() | ||
| { | ||
| _logger.Log($"Trigger OnRenderAsync"); | ||
| return Task.CompletedTask; | ||
| } | ||
|
|
||
| private Task OnFocusAsync(string value) | ||
| { | ||
| _logger.Log($"Trigger OnFocusAsync"); | ||
| return Task.CompletedTask; | ||
| } | ||
|
|
||
| private async Task OnBlurAsync(string value) | ||
| { | ||
| _vditorValueString = value; | ||
| _logger.Log($"Trigger OnBlurAsync"); | ||
|
|
||
| _htmlString = await _vditor.GetHtmlAsync(); | ||
| StateHasChanged(); | ||
| } | ||
|
|
||
| private Task OnEscapeAsync(string value) | ||
| { | ||
| _logger.Log($"Trigger OnEscapeAsync"); | ||
| return Task.CompletedTask; | ||
| } | ||
|
|
||
| private Task OnSelectAsync(string value) | ||
| { | ||
| _logger.Log($"Trigger OnSelectAsync"); | ||
| return Task.CompletedTask; | ||
| } | ||
|
|
||
| private async Task OnInputAsync(string value) | ||
| { | ||
| _vditorValueString = value; | ||
| _htmlString = await _vditor.GetHtmlAsync(); | ||
|
|
||
| _logger.Log($"Trigger OnInputAsync"); | ||
| StateHasChanged(); | ||
| } | ||
|
|
||
| private async Task OnCtrlEnterAsync(string value) | ||
| { | ||
| _vditorValueString = value; | ||
| _htmlString = await _vditor.GetHtmlAsync(); | ||
|
|
||
| _logger.Log($"Trigger OnCtrlEnterAsync"); | ||
| StateHasChanged(); | ||
| } | ||
|
|
||
| private async Task OnTriggerGetValueAsync() | ||
| { | ||
| _vditorValueString = await _vditor.GetValueAsync() ?? ""; | ||
| } | ||
|
|
||
| private async Task OnTriggerInsertValueAsync() | ||
| { | ||
| await _vditor.InsertValueAsync("光标处插入当前值"); | ||
| } | ||
|
|
||
| private async Task OnTriggerGetHtmlAsync() | ||
| { | ||
| _htmlString = await _vditor.GetHtmlAsync(); | ||
| } | ||
|
|
||
| private async Task OnTriggerGetSelectionAsync() | ||
| { | ||
| var selection = await _vditor.GetSelectionAsync() ?? ""; | ||
| _logger.Log($"Trigger OnTriggerGetSelectionAsync: {selection}"); | ||
| } | ||
|
|
||
| private bool _isDisabled = false; | ||
| private async Task OnTriggerEnableAsync() | ||
| { | ||
| await _vditor.EnableAsync(); | ||
| _isDisabled = false; | ||
| } | ||
|
|
||
| private async Task OnTriggerDisableAsync() | ||
| { | ||
| await _vditor.DisableAsync(); | ||
| _isDisabled = true; | ||
| } | ||
|
|
||
| private async Task OnTriggerFocusAsync() | ||
| { | ||
| await _vditor.FocusAsync(); | ||
| } | ||
|
|
||
| private async Task OnTriggerBlurAsync() | ||
| { | ||
| await _vditor.BlurAsync(); | ||
| } | ||
|
|
||
| private static AttributeItem[] GetAttributes() => | ||
| [ | ||
| new() | ||
| { | ||
| Name = "EditorSettings", | ||
| Description = "编辑器设置", | ||
| Type = "EditorSettings", | ||
| ValueList = " — ", | ||
| DefaultValue = " — " | ||
| }, | ||
| new() | ||
| { | ||
| Name = "ToolbarSettings", | ||
| Description = "工具栏设置", | ||
| Type = "ToolbarSettings", | ||
| ValueList = " — ", | ||
| DefaultValue = " — " | ||
| }, | ||
| new() | ||
| { | ||
| Name = "Value", | ||
| Description = "组件值", | ||
| Type = "string", | ||
| ValueList = " — ", | ||
| DefaultValue = " — " | ||
| }, | ||
| new() | ||
| { | ||
| Name = "Html", | ||
| Description = "组件 Html 代码", | ||
| Type = "string", | ||
| ValueList = " — ", | ||
| DefaultValue = " — " | ||
| }, | ||
| new() | ||
| { | ||
| Name = "OnFileUpload", | ||
| Description = "文件上传回调方法", | ||
| Type = "Func<CherryMarkdownUploadFile, Task<string>>", | ||
| ValueList = " — ", | ||
| DefaultValue = " — " | ||
| }, | ||
| new() | ||
| { | ||
| Name = "IsViewer", | ||
| Description = "组件是否为浏览器模式", | ||
| Type = "bool", | ||
| ValueList = "true/false", | ||
| DefaultValue = "false" | ||
| } | ||
| ]; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Remove unused injected service
Since
WebsiteOptionis not used, removing it will eliminate unnecessary warnings and dependencies.