-
-
Notifications
You must be signed in to change notification settings - Fork 6
feat(Vditor): redesign javascript interop #931
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
8 commits
Select commit
Hold shift + click to select a range
f561900
doc: 更新注释
ArgoZhang 74e9423
chore: bump version 10.0.3
ArgoZhang 57e1dca
refactor: 增加 Id 参数
ArgoZhang ec0df3b
refactor: 更正 Invoke 参数顺序
ArgoZhang 9872bbb
feat: 增加 getResult 方法
ArgoZhang b485b5e
refactor: 精简代码
ArgoZhang 524678e
refactor: 精简代码
ArgoZhang 9fdb913
Merge branch 'master' into dev-vidtor
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
2 changes: 1 addition & 1 deletion
2
src/components/BootstrapBlazor.Vditor/BootstrapBlazor.Vditor.csproj
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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -7,54 +7,63 @@ | |||||
| namespace BootstrapBlazor.Components; | ||||||
|
|
||||||
| /// <summary> | ||||||
| /// Vditor markdown component | ||||||
| /// <para lang="zh">Vditor Markdown 组件</para> | ||||||
| /// <para lang="en">Vditor markdown component</para> | ||||||
| /// </summary> | ||||||
| public partial class Vditor | ||||||
| { | ||||||
| /// <summary> | ||||||
| /// 获得/设置 组件 <see cref="VditorOptions"/> 实例 默认 null | ||||||
| /// <para lang="zh">获得/设置 组件 <see cref="VditorOptions"/> 实例 默认 null</para> | ||||||
| /// <para lang="en">Gets or sets the <see cref="VditorOptions"/> instance. Default is null.</para> | ||||||
| /// </summary> | ||||||
| [Parameter] | ||||||
| public VditorOptions? Options { get; set; } | ||||||
|
|
||||||
| /// <summary> | ||||||
| /// 获得/设置 组件渲染完毕回调方法 默认 null | ||||||
| /// <para lang="zh">获得/设置 组件渲染完毕回调方法 默认 null</para> | ||||||
| /// <para lang="en">Gets or sets the callback method when component rendering is complete. Default is null.</para> | ||||||
| /// </summary> | ||||||
| [Parameter] | ||||||
| public Func<Task>? OnRenderedAsync { get; set; } | ||||||
|
|
||||||
| /// <summary> | ||||||
| /// 获得/设置 组件输入时回调方法 高频触发 默认 null | ||||||
| /// <para lang="zh">获得/设置 组件输入时回调方法 高频触发 默认 null</para> | ||||||
| /// <para lang="en">Gets or sets the callback method on input. High frequency trigger. Default is null.</para> | ||||||
| /// </summary> | ||||||
| [Parameter] | ||||||
| public Func<string, Task>? OnInputAsync { get; set; } | ||||||
|
|
||||||
| /// <summary> | ||||||
| /// 获得/设置 组件获得焦点时回调方法 默认 null | ||||||
| /// <para lang="zh">获得/设置 组件获得焦点时回调方法 默认 null</para> | ||||||
| /// <para lang="en">Gets or sets the callback method when the component gains focus. Default is null.</para> | ||||||
| /// </summary> | ||||||
| [Parameter] | ||||||
| public Func<string, Task>? OnFocusAsync { get; set; } | ||||||
|
|
||||||
| /// <summary> | ||||||
| /// 获得/设置 组件失去焦点时回调方法 默认 null | ||||||
| /// <para lang="zh">获得/设置 组件失去焦点时回调方法 默认 null</para> | ||||||
| /// <para lang="en">Gets or sets the callback method when the component loses focus. Default is null.</para> | ||||||
| /// </summary> | ||||||
| [Parameter] | ||||||
| public Func<string, Task>? OnBlurAsync { get; set; } | ||||||
|
|
||||||
| /// <summary> | ||||||
| /// 获得/设置 组件选择内容时回调方法 默认 null | ||||||
| /// <para lang="zh">获得/设置 组件选择内容时回调方法 默认 null</para> | ||||||
| /// <para lang="en">Gets or sets the callback method when content is selected. Default is null.</para> | ||||||
| /// </summary> | ||||||
| [Parameter] | ||||||
| public Func<string, Task>? OnSelectAsync { get; set; } | ||||||
|
|
||||||
| /// <summary> | ||||||
| /// 获得/设置 组件按 ESC 案件时回调方法 默认 null | ||||||
| /// <para lang="zh">获得/设置 组件按 ESC 按键时回调方法 默认 null</para> | ||||||
| /// <para lang="en">Gets or sets the callback method when ESC key is pressed. Default is null.</para> | ||||||
| /// </summary> | ||||||
| [Parameter] | ||||||
| public Func<string, Task>? OnEscapeAsync { get; set; } | ||||||
|
|
||||||
| /// <summary> | ||||||
| /// 获得/设置 组件按 Ctrl + Enter 组合案件时回调方法 默认 null | ||||||
| /// <para lang="zh">获得/设置 组件按 Ctrl + Enter 组合按键时回调方法 默认 null</para> | ||||||
| /// <para lang="en">Gets or sets the callback method when Ctrl + Enter is pressed. Default is null.</para> | ||||||
| /// </summary> | ||||||
| [Parameter] | ||||||
| public Func<string, Task>? OnCtrlEnterAsync { get; set; } | ||||||
|
|
@@ -66,13 +75,11 @@ public partial class Vditor | |||||
| .Build(); | ||||||
|
|
||||||
| private string? _lastValue; | ||||||
| private IJSObjectReference? _vditor; | ||||||
|
|
||||||
| /// <summary> | ||||||
| /// <inheritdoc/> | ||||||
| /// </summary> | ||||||
| /// <param name="firstRender"></param> | ||||||
| /// <returns></returns> | ||||||
| protected override async Task OnAfterRenderAsync(bool firstRender) | ||||||
| { | ||||||
| await base.OnAfterRenderAsync(firstRender); | ||||||
|
|
@@ -85,141 +92,88 @@ protected override async Task OnAfterRenderAsync(bool firstRender) | |||||
| if (_lastValue != Value) | ||||||
| { | ||||||
| _lastValue = Value; | ||||||
| if (_vditor != null) | ||||||
| { | ||||||
| await _vditor.InvokeVoidAsync("setValue", Value, true); | ||||||
| } | ||||||
| await InvokeVoidAsync("execute", Id, "setValue", new object?[] { Value, true }); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| /// <summary> | ||||||
| /// <inheritdoc/> | ||||||
| /// </summary> | ||||||
| /// <returns></returns> | ||||||
| protected override async Task InvokeInitAsync() | ||||||
| protected override Task InvokeInitAsync() => InvokeAsync<IJSObjectReference>("init", Id, Interop, new | ||||||
| { | ||||||
| _vditor = await InvokeAsync<IJSObjectReference>("init", Id, Interop, new | ||||||
| { | ||||||
| Options, | ||||||
| Value | ||||||
| }); | ||||||
| } | ||||||
| Options, | ||||||
| Value | ||||||
| }); | ||||||
|
|
||||||
| /// <summary> | ||||||
| /// 重新设置编辑器方法 | ||||||
| /// <para lang="zh">重新设置编辑器方法</para> | ||||||
| /// <para lang="en">Resets the editor.</para> | ||||||
| /// </summary> | ||||||
| /// <param name="value"></param> | ||||||
| /// <param name="options"></param> | ||||||
| /// <returns></returns> | ||||||
| public async Task Reset(string value, VditorOptions options) | ||||||
| { | ||||||
| if (!string.IsNullOrEmpty(value)) | ||||||
| { | ||||||
| Value = value; | ||||||
| } | ||||||
| _vditor = await InvokeAsync<IJSObjectReference>("reset", Id, Value, Options); | ||||||
| await InvokeVoidAsync("reset", Id, Value, Options); | ||||||
| } | ||||||
|
|
||||||
| /// <summary> | ||||||
| /// 在焦点处插入内容,并默认进行 Markdown 渲染 | ||||||
| /// <para lang="zh">在焦点处插入内容 并默认进行 Markdown 渲染</para> | ||||||
| /// <para lang="en">Inserts content at the cursor position and renders Markdown by default.</para> | ||||||
| /// </summary> | ||||||
| /// <param name="value">要插入的 markdown 值</param> | ||||||
| /// <param name="render">是否渲染</param> | ||||||
| public async ValueTask InsertValueAsync(string? value, bool render = true) | ||||||
| { | ||||||
| if (_vditor != null) | ||||||
| { | ||||||
| await _vditor.InvokeVoidAsync("insertValue", value, render); | ||||||
| } | ||||||
| } | ||||||
| /// <param name="value"></param> | ||||||
| /// <param name="render"></param> | ||||||
| public Task InsertValueAsync(string? value, bool render = true) => InvokeVoidAsync("execute", Id, "insertValue", new object?[] { value, render }); | ||||||
|
|
||||||
| /// <summary> | ||||||
| /// 获取编辑器的 markdown 内容 | ||||||
| /// <para lang="zh">获取编辑器的 Markdown 内容</para> | ||||||
| /// <para lang="en">Gets the markdown content of the editor.</para> | ||||||
| /// </summary> | ||||||
| public async ValueTask<string?> GetValueAsync() | ||||||
| { | ||||||
| string? ret = null; | ||||||
| if (_vditor != null) | ||||||
| { | ||||||
| ret = await _vditor.InvokeAsync<string?>("getValue"); | ||||||
| } | ||||||
| return ret; | ||||||
| } | ||||||
| public Task<string?> GetValueAsync() => InvokeAsync<string?>("execute", Id, "getValue"); | ||||||
|
|
||||||
| /// <summary> | ||||||
| /// 获取 markdown 渲染后的 HTML | ||||||
| /// <para lang="zh">获取 Markdown 渲染后的 HTML</para> | ||||||
| /// <para lang="en">Gets the HTML rendered from markdown.</para> | ||||||
| /// </summary> | ||||||
| public async ValueTask<string?> GetHtmlAsync() | ||||||
| { | ||||||
| string? ret = null; | ||||||
| if (_vditor != null) | ||||||
| { | ||||||
| ret = await _vditor.InvokeAsync<string?>("getHTML"); | ||||||
| } | ||||||
| return ret; | ||||||
| } | ||||||
| public Task<string?> GetHtmlAsync() => InvokeAsync<string?>("execute", Id, "getHTML"); | ||||||
|
|
||||||
| /// <summary> | ||||||
| /// 返回选中的字符串 | ||||||
| /// <para lang="zh">获取 返回选中的字符串</para> | ||||||
|
||||||
| /// <para lang="zh">获取 返回选中的字符串</para> | |
| /// <para lang="zh">获取选中的字符串</para> |
Oops, something went wrong.
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.
The InvokeInitAsync method is calling InvokeAsync with a generic type parameter IJSObjectReference, but the JavaScript init function no longer returns the vditor object (the return statement was removed at line 18 of the diff). This will cause the C# code to receive an undefined value. Since the returned value is no longer used, this should be changed to InvokeVoidAsync instead of InvokeAsync.