Skip to content
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

Add CancellationToken overloads. #77

Merged
merged 6 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,20 +146,18 @@ Below is a list of all the options available on the Text Editor.
BlazoredTextEditor QuillHtml;
string QuillHTMLContent;

public async void GetHTML()
public async Task GetHTML()
{
QuillHTMLContent = await this.QuillHtml.GetHTML();
StateHasChanged();
}

public async void SetHTML()
public async Task SetHTML()
{
string QuillContent =
@"<a href='http://BlazorHelpWebsite.com/'>" +
"<img src='images/BlazorHelpWebsite.gif' /></a>";

await this.QuillHtml.LoadHTMLContent(QuillContent);
StateHasChanged();
}
}
```
Expand Down
32 changes: 17 additions & 15 deletions samples/BlazorClientSide/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -220,51 +220,53 @@ console.<span class="hljs-built_in">log</span>("I love " <span class="hljs-opera

bool mode = false;

public async void GetHTML()
public async Task GetHTML()
{
QuillHTMLContent = await this.QuillHtml.GetHTML();
StateHasChanged();
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(1));

try
{
QuillHTMLContent = await this.QuillHtml.GetHTML(cts.Token);
}
catch (TaskCanceledException e)
{
QuillHTMLContent = "<p>ERROR: Timeout</p>";
}
}

public async void SetHTML()
public async Task SetHTML()
{
string QuillContent =
@"<a href='http://BlazorHelpWebsite.com/'>" +
"<img src='images/BlazorHelpWebsite.gif' /></a>";

await this.QuillHtml.LoadHTMLContent(QuillContent);
StateHasChanged();
}

public async void GetContent()
public async Task GetContent()
{
QuillContent = await this.QuillNative.GetContent();
StateHasChanged();
}
public async void LoadContent()
public async Task LoadContent()
{
await this.QuillNative.LoadContent(QuillContent);
StateHasChanged();
}
public async void InsertImage()
public async Task InsertImage()
{
await this.QuillNative.InsertImage("images/BlazorHelpWebsite.gif");
StateHasChanged();
}
public async void InsertText()
public async Task InsertText()
{
await this.QuillNative.InsertText("Some Text");
StateHasChanged();
}
async Task ToggleQuillEditor()
{
mode = (mode) ? false : true;
await this.QuillReadOnly.EnableEditor(mode);
}

public async void GetHTMLCode()
public async Task GetHTMLCode()
{
QuillHTMLCodeContent = await this.QuillCode.GetHTML();
StateHasChanged();
}
}
1 change: 1 addition & 0 deletions samples/BlazorClientSide/_Imports.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@using System.Net.Http
@using System.Threading
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web
Expand Down
34 changes: 18 additions & 16 deletions samples/BlazorServerSide/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -212,49 +212,52 @@ console.<span class="hljs-built_in">log</span>("I love " <span class="hljs-opera

string QuillHTMLContent;
string QuillContent;
string QuillReadOnlyContent =
string QuillReadOnlyContent =
@"<span><b>Read Only</b> <u>Content</u></span>";
string QuillHTMLCodeContent;

bool mode = false;

public async void GetHTML()
public async Task GetHTML()
{
QuillHTMLContent = await this.QuillHtml.GetHTML();
StateHasChanged();
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(1));

try
{
QuillHTMLContent = await this.QuillHtml.GetHTML(cts.Token);
}
catch (TaskCanceledException e)
{
QuillHTMLContent = "<p>ERROR: Timeout</p>";
}
}

public async void SetHTML()
public async Task SetHTML()
{
string QuillContent =
@"<a href='http://BlazorHelpWebsite.com/'>" +
"<img src='images/BlazorHelpWebsite.gif' /></a>";

await this.QuillHtml.LoadHTMLContent(QuillContent);
StateHasChanged();
}

public async void GetContent()
public async Task GetContent()
{
QuillContent = await this.QuillNative.GetContent();
StateHasChanged();
}
public async void LoadContent()
public async Task LoadContent()
{
await this.QuillNative.LoadContent(QuillContent);
StateHasChanged();
}

public async void InsertImage()
public async Task InsertImage()
{
await this.QuillNative.InsertImage("images/BlazorHelpWebsite.gif");
StateHasChanged();
}

public async void InsertText()
public async Task InsertText()
{
await this.QuillNative.InsertText("Some Text");
StateHasChanged();
}

async Task ToggleQuillEditor()
Expand All @@ -263,9 +266,8 @@ console.<span class="hljs-built_in">log</span>("I love " <span class="hljs-opera
await this.QuillReadOnly.EnableEditor(mode);
}

public async void GetHTMLCode()
public async Task GetHTMLCode()
{
QuillHTMLCodeContent = await this.QuillCode.GetHTML();
StateHasChanged();
}
}
1 change: 1 addition & 0 deletions samples/BlazorServerSide/_Imports.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@using System.Net.Http
@using System.Threading
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Components.Authorization
@using Microsoft.AspNetCore.Components.Forms
Expand Down
53 changes: 53 additions & 0 deletions src/Blazored.TextEditor/BlazoredTextEditor.razor
Original file line number Diff line number Diff line change
Expand Up @@ -106,51 +106,104 @@
JSRuntime, QuillElement);
}

public async Task<string> GetText(CancellationToken cancellationToken)
{
return await Interop.GetText(
JSRuntime, QuillElement, cancellationToken);
}

public async Task<string> GetHTML()
{
return await Interop.GetHTML(
JSRuntime, QuillElement);
}

public async Task<string> GetHTML(CancellationToken cancellationToken)
{
return await Interop.GetHTML(
JSRuntime, QuillElement, cancellationToken);
}

public async Task<string> GetContent()
{
return await Interop.GetContent(
JSRuntime, QuillElement);
}

public async Task<string> GetContent(CancellationToken cancellationToken)
{
return await Interop.GetContent(
JSRuntime, QuillElement, cancellationToken);
}

public async Task LoadContent(string Content)
{
var QuillDelta =
await Interop.LoadQuillContent(
JSRuntime, QuillElement, Content);
}

public async Task LoadContent(string Content, CancellationToken cancellationToken)
{
var QuillDelta =
await Interop.LoadQuillContent(
JSRuntime, QuillElement, Content, cancellationToken);
}

public async Task LoadHTMLContent(string quillHTMLContent)
{
var QuillDelta =
await Interop.LoadQuillHTMLContent(
JSRuntime, QuillElement, quillHTMLContent);
}

public async Task LoadHTMLContent(string quillHTMLContent, CancellationToken cancellationToken)
{
var QuillDelta =
await Interop.LoadQuillHTMLContent(
JSRuntime, QuillElement, quillHTMLContent, cancellationToken);
}

public async Task InsertImage(string ImageURL)
{
var QuillDelta =
await Interop.InsertQuillImage(
JSRuntime, QuillElement, ImageURL);
}

public async Task InsertImage(string ImageURL, CancellationToken cancellationToken)
{
var QuillDelta =
await Interop.InsertQuillImage(
JSRuntime, QuillElement, ImageURL, cancellationToken);
}

public async Task InsertText(string text)
{
var QuillDelta =
await Interop.InsertQuillText(
JSRuntime, QuillElement, text);
}

public async Task InsertText(string text, CancellationToken cancellationToken)
{
var QuillDelta =
await Interop.InsertQuillText(
JSRuntime, QuillElement, text, cancellationToken);
}

public async Task EnableEditor(bool mode)
{
var QuillDelta =
await Interop.EnableQuillEditor(
JSRuntime, QuillElement, mode);
}

public async Task EnableEditor(bool mode, CancellationToken cancellationToken)
{
var QuillDelta =
await Interop.EnableQuillEditor(
JSRuntime, QuillElement, mode, cancellationToken);
}

}
Loading