Skip to content

Commit

Permalink
Added TinyMCE to DragonFly.Client
Browse files Browse the repository at this point in the history
  • Loading branch information
usercode committed Jan 28, 2024
1 parent 0fef0ea commit f18cd96
Show file tree
Hide file tree
Showing 10 changed files with 458 additions and 17 deletions.
7 changes: 6 additions & 1 deletion src/DragonFly.App.Client/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using DragonFly.Client;
using DragonFly;

var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<DragonFly.App.Client.App>("app");
Expand All @@ -14,7 +15,11 @@
.AddRestClient()
.AddBlockField()
.AddIdentity()
.AddApiKeys();
.AddApiKeys()
.PostInit(x =>
{
x.ContentField().Add<HtmlField>().WithTinyMceView();
});

WebAssemblyHost host = builder.Build();

Expand Down
3 changes: 3 additions & 0 deletions src/DragonFly.App.Server/Models/Product2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public partial class Product2
[FloatField(Index = true, QueryField = true)]
private double? _quantity2;

[HtmlField]
private BlockField _htmlContent;

[BlockField]
private BlockField _mainContent;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@
<ItemGroup>
<None Include="..\..\logo.png" Pack="true" PackagePath="" />
<None Include="..\..\readme.md" Pack="true" PackagePath="" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="TinyMCE.Blazor" Version="1.0.4" />
</ItemGroup>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\DragonFly.BlockField.Core\DragonFly.BlockField.Core.csproj" />
Expand Down
4 changes: 4 additions & 0 deletions src/DragonFly.Client/DragonFly.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="8.0.1" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="TinyMCE.Blazor" Version="1.0.4" />
</ItemGroup>

<ItemGroup>
<None Include="..\..\logo.png" Pack="true" PackagePath="" />
<None Include="..\..\readme.md" Pack="true" PackagePath="" />
Expand Down
23 changes: 23 additions & 0 deletions src/DragonFly.Client/Extensions/FieldAdded2Extensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) usercode
// https://github.com/usercode/DragonFly
// MIT License

using System;
using DragonFly.Client;
using DragonFly.Client.Pages.ContentItems.Fields;

namespace DragonFly;

public static class FieldAdded2Extensions
{
/// <summary>
/// Adds TinyMCE view for <typeparamref name="T"/>.
/// </summary>
public static IFieldAdded<T> WithTinyMceView<T>(this IFieldAdded<T> field)
where T : TextBaseField
{
ComponentManager.Default.Add(typeof(T), typeof(TinyMceFieldView));

return field;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace DragonFly;

public static class DragonFlyApiExtensions
public static class FieldAddedExtensions
{
//public static IFieldAdded<T> WithFieldView2<T>(this IFieldAdded<T> field, Func<IFieldComponent<T>> component)
// where T : ContentField
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
// https://github.com/usercode/DragonFly
// MIT License

namespace DragonFly.BlockField.Client.Helpers;
using System.Collections.Generic;

namespace DragonFly.Client;

public class TinyMceConfiguration
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@inherits FieldComponent<TextBaseField>

<div class="tinymce-field">
<TinyMCE.Blazor.Editor Field="() => Field.Value"
@bind-Value="Field.Value"
Conf="TinyMceConfiguration.Editor" />
</div>
Loading

0 comments on commit f18cd96

Please sign in to comment.