Skip to content

Commit cbd1841

Browse files
committed
Initial project for RTE based on roosterjs
1 parent 75cda39 commit cbd1841

File tree

12 files changed

+137
-0
lines changed

12 files changed

+137
-0
lines changed

Blazorise.sln

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazorise.Captcha", "Source
153153
EndProject
154154
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Blazorise.Captcha.ReCaptcha", "Source\Extensions\Blazorise.Captcha.ReCaptcha\Blazorise.Captcha.ReCaptcha.csproj", "{2B4FD79A-42E2-4B81-828B-0799E4744ADA}"
155155
EndProject
156+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Blazorise.RichTextEdit.Rooster", "Source\Extensions\Blazorise.RichTextEdit.Rooster\Blazorise.RichTextEdit.Rooster.csproj", "{D03708E9-0E38-4AD1-87DF-DA349E7DC271}"
157+
EndProject
156158
Global
157159
GlobalSection(SolutionConfigurationPlatforms) = preSolution
158160
Debug|Any CPU = Debug|Any CPU

Demos/Blazorise.Demo/Blazorise.Demo.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<ProjectReference Include="..\..\Source\Extensions\Blazorise.LottieAnimation\Blazorise.LottieAnimation.csproj" />
1919
<ProjectReference Include="..\..\Source\Extensions\Blazorise.Markdown\Blazorise.Markdown.csproj" />
2020
<ProjectReference Include="..\..\Source\Extensions\Blazorise.QRCode\Blazorise.QRCode.csproj" />
21+
<ProjectReference Include="..\..\Source\Extensions\Blazorise.RichTextEdit.Rooster\Blazorise.RichTextEdit.Rooster.csproj" />
2122
<ProjectReference Include="..\..\Source\Extensions\Blazorise.RichTextEdit\Blazorise.RichTextEdit.csproj" />
2223
<ProjectReference Include="..\..\Source\Extensions\Blazorise.Sidebar\Blazorise.Sidebar.csproj" />
2324
<ProjectReference Include="..\..\Source\Extensions\Blazorise.Snackbar\Blazorise.Snackbar.csproj" />

Demos/Blazorise.Demo/Components/SideMenu.razor

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,9 @@
332332
<BarDropdownItem To="tests/richtextedit">
333333
RichTextEdit
334334
</BarDropdownItem>
335+
<BarDropdownItem To="tests/rooster">
336+
Rooster RichTextEdit
337+
</BarDropdownItem>
335338
<BarDropdownItem To="tests/selectlist">
336339
Select List
337340
</BarDropdownItem>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
@page "/tests/rooster"
2+
3+
<Row>
4+
<Column>
5+
<Card Margin="Margin.Is4.OnY">
6+
<CardHeader>
7+
<CardTitle>RichTextEdit based on rooster.js</CardTitle>
8+
</CardHeader>
9+
<CardBody>
10+
<Blazorise.RichTextEdit.Rooster.RichTextEdit />
11+
</CardBody>
12+
</Card>
13+
</Column>
14+
</Row>
15+
16+
@code {
17+
18+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Razor">
2+
3+
<Import Project="..\..\..\Build\Blazorise.props" />
4+
5+
<PropertyGroup>
6+
<PackageTags>blazorise blazor components richtextedit roosterjs</PackageTags>
7+
</PropertyGroup>
8+
9+
<PropertyGroup>
10+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
11+
</PropertyGroup>
12+
13+
<ItemGroup>
14+
<ProjectReference Include="..\..\Blazorise\Blazorise.csproj" />
15+
</ItemGroup>
16+
17+
<ItemGroup>
18+
<None Include="..\..\..\LICENSE.md" Pack="true" Visible="false" PackagePath="" />
19+
<None Include="..\..\..\NuGet\Blazorise.png" Pack="true" Visible="false" PackagePath="" />
20+
</ItemGroup>
21+
22+
</Project>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System.Threading.Tasks;
2+
using Blazorise.Modules;
3+
using Microsoft.AspNetCore.Components;
4+
using Microsoft.JSInterop;
5+
6+
namespace Blazorise.RichTextEdit.Rooster;
7+
8+
internal class JSRoosterModule : BaseJSModule, IJSDestroyableModule
9+
{
10+
public JSRoosterModule( IJSRuntime jsRuntime, IVersionProvider versionProvider )
11+
: base( jsRuntime, versionProvider )
12+
{
13+
}
14+
15+
/// <inheritdoc/>
16+
public override string ModuleFileName => $"./_content/Blazorise.RichTextEdit.Rooster/blazorise.rooster.js?v={VersionProvider.Version}";
17+
18+
public ValueTask Initialize( DotNetObjectReference<RichTextEdit> adapterReference, ElementReference elementRef, string elementId, object options )
19+
=> InvokeSafeVoidAsync( "initialize", adapterReference, elementRef, elementId, options );
20+
21+
public ValueTask Destroy( ElementReference elementRef, string elementId )
22+
=> ValueTask.CompletedTask;
23+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@namespace Blazorise.RichTextEdit.Rooster
2+
@inherits BaseComponent
3+
4+
<div @ref="@ElementRef"
5+
id="@ElementId"
6+
class="@ClassNames"
7+
style="width: 500px; height: 300px; overflow: auto; border: solid 1px black"
8+
@attributes="@Attributes">
9+
</div>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System.Threading.Tasks;
2+
using Microsoft.AspNetCore.Components;
3+
using Microsoft.JSInterop;
4+
5+
namespace Blazorise.RichTextEdit.Rooster;
6+
7+
public partial class RichTextEdit : BaseComponent
8+
{
9+
protected override async Task OnAfterRenderAsync( bool firstRender )
10+
{
11+
await base.OnAfterRenderAsync( firstRender );
12+
13+
if ( firstRender )
14+
{
15+
JSModule ??= new JSRoosterModule( JSRuntime, VersionProvider );
16+
var adapter = DotNetObjectReference.Create( this );
17+
18+
await JSModule.Initialize( adapter, ElementRef, ElementId, default );
19+
}
20+
}
21+
22+
internal JSRoosterModule JSModule { get; set; }
23+
24+
[Inject] private IJSRuntime JSRuntime { get; set; }
25+
[Inject] private IVersionProvider VersionProvider { get; set; }
26+
}
27+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@using Microsoft.AspNetCore.Components.Web
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { getRequiredElement, loadScript } from "../Blazorise/utilities.js?v=1.2.2.0";
2+
3+
const _instances = [];
4+
5+
6+
export async function initialize(dotNetAdapter, element, elementId, options) {
7+
element = getRequiredElement(element, elementId);
8+
9+
if (!element)
10+
return;
11+
12+
if (typeof roosterjs === 'undefined') {
13+
await loadScript("_content/Blazorise.RichTextEdit.Rooster/vendors/rooster.js?v=4.88.0");
14+
}
15+
16+
const instance = {
17+
options: options,
18+
adapter: dotNetAdapter,
19+
rooster: null,
20+
};
21+
22+
instance.rooster = roosterjs.createEditor(element);
23+
24+
instance.rooster.setContent('Welcome to <b>RoosterJs</b>!');
25+
26+
_instances[elementId] = instance;
27+
}
28+

0 commit comments

Comments
 (0)