diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Pages/create.js b/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Pages/create.js index 62d05abd4d..51c405e03f 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Pages/create.js +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.Web/Pages/CmsKit/Pages/create.js @@ -176,9 +176,16 @@ $(function () { let content = editor.getMarkdown(); localStorage.setItem('content', content); - - volo.cmsKit.contents.content.parseAsHtml(content).then(function (data) { - editor.setHTML(data); + + $.post("/CmsKitCommonWidgets/ContentPreview", { content: content }, function (result) { + + let style = styleEditor.getValue(); + + $('#editor-preview-style').remove(); + + $('head').append(''); + + editor.setHTML(result); }); } else if ($(this).attr("aria-label") == 'Write'){ diff --git a/modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Contents/DefaultContentDto.cs b/modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Contents/DefaultContentDto.cs new file mode 100644 index 0000000000..731e346df4 --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Contents/DefaultContentDto.cs @@ -0,0 +1,8 @@ +using System.Collections.Generic; + +namespace Volo.CmsKit.Contents; + +public class DefaultContentDto : IContent +{ + public List ContentFragments { get; set; } +} diff --git a/modules/cms-kit/src/Volo.CmsKit.Common.HttpApi/Volo/CmsKit/Contents/ContentController.cs b/modules/cms-kit/src/Volo.CmsKit.Common.HttpApi/Volo/CmsKit/Contents/ContentController.cs deleted file mode 100644 index e0bcf5586a..0000000000 --- a/modules/cms-kit/src/Volo.CmsKit.Common.HttpApi/Volo/CmsKit/Contents/ContentController.cs +++ /dev/null @@ -1,82 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Text.Encodings.Web; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.Rendering; -using Microsoft.AspNetCore.Mvc.ViewComponents; -using Microsoft.AspNetCore.Mvc.ViewEngines; -using Microsoft.AspNetCore.Mvc.ViewFeatures; -using Microsoft.AspNetCore.Mvc.ViewFeatures.Buffers; -using Microsoft.Extensions.DependencyInjection; -using Volo.Abp; -using Volo.Abp.GlobalFeatures; -using Volo.CmsKit.GlobalFeatures; - -namespace Volo.CmsKit.Contents; - -[RequiresGlobalFeature(typeof(PagesFeature))] -[RemoteService(Name = CmsKitCommonRemoteServiceConsts.RemoteServiceName)] -[Area(CmsKitCommonRemoteServiceConsts.ModuleName)] -[Route("api/cms-kit/contents")] -public class ContentController : Controller, IContentAppService -{ - protected IContentAppService ContentAppService { get; } - - public ContentController(IContentAppService contentAppService) - { - ContentAppService = contentAppService; - } - - [HttpGet] - [Route("{parseashtml}")] - public virtual async Task ParseAsHtmlAsync(string content) - { - var fragments = await ParseAsync(content); - return await RenderViewComponent("ContentFragment", new PageDto() { ContentFragments = fragments }); - } - public virtual Task> ParseAsync(string content) - { - return ContentAppService.ParseAsync(content); - } - - private async Task RenderViewComponent(string viewComponent, object args) - { - var sp = HttpContext.RequestServices; - - var helper = new DefaultViewComponentHelper( - sp.GetRequiredService(), - HtmlEncoder.Default, - sp.GetRequiredService(), - sp.GetRequiredService(), - sp.GetRequiredService()); - - using (var writer = new StringWriter()) - { - var context = new ViewContext(ControllerContext, NullView.Instance, ViewData, TempData, writer, new HtmlHelperOptions()); - helper.Contextualize(context); - var result = await helper.InvokeAsync(viewComponent, args); - result.WriteTo(writer, HtmlEncoder.Default); - await writer.FlushAsync(); - return writer.ToString(); - } - } - - internal class NullView : IView - { - public static readonly NullView Instance = new(); - - public string Path => string.Empty; - - public Task RenderAsync(ViewContext context) - { - if (context == null) - { - throw new ArgumentNullException(nameof(context)); - } - - return Task.CompletedTask; - } - } -} diff --git a/modules/cms-kit/src/Volo.CmsKit.Common.Web/Controllers/CmsKitCommonWidgetsController.cs b/modules/cms-kit/src/Volo.CmsKit.Common.Web/Controllers/CmsKitCommonWidgetsController.cs new file mode 100644 index 0000000000..8e226a31f2 --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Common.Web/Controllers/CmsKitCommonWidgetsController.cs @@ -0,0 +1,14 @@ +using Microsoft.AspNetCore.Mvc; +using Volo.Abp.AspNetCore.Mvc; +using Volo.CmsKit.Web.Pages.CmsKit.Components.ContentPreview; + +namespace Volo.CmsKit.Web.Controllers; + +public class CmsKitCommonWidgetsController : AbpController +{ + [HttpPost] + public IActionResult ContentPreview(ContentPreviewDto dto) + { + return ViewComponent(typeof(ContentPreviewViewComponent), new { content = dto.Content }); + } +} diff --git a/modules/cms-kit/src/Volo.CmsKit.Common.Web/Pages/CmsKit/Components/ContentPreview/ContentPreviewDto.cs b/modules/cms-kit/src/Volo.CmsKit.Common.Web/Pages/CmsKit/Components/ContentPreview/ContentPreviewDto.cs new file mode 100644 index 0000000000..9c01a325bf --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Common.Web/Pages/CmsKit/Components/ContentPreview/ContentPreviewDto.cs @@ -0,0 +1,9 @@ +using System; + +namespace Volo.CmsKit.Web.Pages.CmsKit.Components.ContentPreview; + +[Serializable] +public class ContentPreviewDto +{ + public string Content { get; set; } +} diff --git a/modules/cms-kit/src/Volo.CmsKit.Common.Web/Pages/CmsKit/Components/ContentPreview/ContentPreviewViewComponent.cs b/modules/cms-kit/src/Volo.CmsKit.Common.Web/Pages/CmsKit/Components/ContentPreview/ContentPreviewViewComponent.cs new file mode 100644 index 0000000000..987c404e31 --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Common.Web/Pages/CmsKit/Components/ContentPreview/ContentPreviewViewComponent.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Volo.Abp.AspNetCore.Mvc; +using Volo.CmsKit.Contents; + +namespace Volo.CmsKit.Web.Pages.CmsKit.Components.ContentPreview; + +public class ContentPreviewViewComponent : AbpViewComponent +{ + protected IContentAppService ContentAppService { get; } + + public ContentPreviewViewComponent(IContentAppService contentAppService) + { + ContentAppService = contentAppService; + } + + public virtual async Task InvokeAsync(string content) + { + var fragments = await ContentAppService.ParseAsync(content); + + return View("~/Pages/CmsKit/Components/ContentPreview/Default.cshtml", new DefaultContentDto + { + ContentFragments = fragments + }); + } +} diff --git a/modules/cms-kit/src/Volo.CmsKit.Common.Web/Pages/CmsKit/Components/ContentPreview/Default.cshtml b/modules/cms-kit/src/Volo.CmsKit.Common.Web/Pages/CmsKit/Components/ContentPreview/Default.cshtml new file mode 100644 index 0000000000..6baf41716e --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Common.Web/Pages/CmsKit/Components/ContentPreview/Default.cshtml @@ -0,0 +1,10 @@ +@using Volo.CmsKit.Contents +@using Volo.CmsKit.Web.Pages.CmsKit.Components.Contents + +@model DefaultContentDto + +
+ + @await Component.InvokeAsync(typeof(ContentFragmentViewComponent), Model) + +
\ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Common.Web/Contents/ContentFragment.cshtml b/modules/cms-kit/src/Volo.CmsKit.Common.Web/Pages/CmsKit/Components/Contents/ContentFragment.cshtml similarity index 87% rename from modules/cms-kit/src/Volo.CmsKit.Common.Web/Contents/ContentFragment.cshtml rename to modules/cms-kit/src/Volo.CmsKit.Common.Web/Pages/CmsKit/Components/Contents/ContentFragment.cshtml index f0dce03b75..0fa7d59064 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Common.Web/Contents/ContentFragment.cshtml +++ b/modules/cms-kit/src/Volo.CmsKit.Common.Web/Pages/CmsKit/Components/Contents/ContentFragment.cshtml @@ -1,7 +1,7 @@ -@using Volo.CmsKit.Web.Contents; -@using System.Dynamic +@using System.Dynamic @using Volo.Abp.Data @using Volo.CmsKit.Web.Renderers; +@using Volo.CmsKit.Web.Pages.CmsKit.Components.Contents; @model ContentFragmentViewComponent diff --git a/modules/cms-kit/src/Volo.CmsKit.Common.Web/Contents/ContentFragmentViewComponent.cs b/modules/cms-kit/src/Volo.CmsKit.Common.Web/Pages/CmsKit/Components/Contents/ContentFragmentViewComponent.cs similarity index 68% rename from modules/cms-kit/src/Volo.CmsKit.Common.Web/Contents/ContentFragmentViewComponent.cs rename to modules/cms-kit/src/Volo.CmsKit.Common.Web/Pages/CmsKit/Components/Contents/ContentFragmentViewComponent.cs index 6deeb90e22..d276165982 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Common.Web/Contents/ContentFragmentViewComponent.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Common.Web/Pages/CmsKit/Components/Contents/ContentFragmentViewComponent.cs @@ -4,7 +4,7 @@ using Volo.Abp.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc.UI.Widgets; using Volo.CmsKit.Contents; -namespace Volo.CmsKit.Web.Contents; +namespace Volo.CmsKit.Web.Pages.CmsKit.Components.Contents; [ViewComponent(Name = "ContentFragment")] [Widget( @@ -16,7 +16,6 @@ public class ContentFragmentViewComponent : AbpViewComponent public virtual async Task InvokeAsync(IContent contentDto) { - return View("~/Contents/ContentFragment.cshtml", new ContentFragmentViewComponent() { ContentDto = contentDto }); + return View("~/Pages/CmsKit/Components/Contents/ContentFragment.cshtml", new ContentFragmentViewComponent() { ContentDto = contentDto }); } -} - +} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Common.Web/Contents/IContentRenderer.cs b/modules/cms-kit/src/Volo.CmsKit.Common.Web/Pages/CmsKit/Components/Contents/IContentRenderer.cs similarity index 66% rename from modules/cms-kit/src/Volo.CmsKit.Common.Web/Contents/IContentRenderer.cs rename to modules/cms-kit/src/Volo.CmsKit.Common.Web/Pages/CmsKit/Components/Contents/IContentRenderer.cs index 879b27cda7..b33c044392 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Common.Web/Contents/IContentRenderer.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Common.Web/Pages/CmsKit/Components/Contents/IContentRenderer.cs @@ -1,6 +1,6 @@ using System.Threading.Tasks; -namespace Volo.CmsKit.Web.Contents; +namespace Volo.CmsKit.Web.Pages.CmsKit.Components.Contents; public interface IContentRenderer { diff --git a/modules/cms-kit/src/Volo.CmsKit.Common.Web/Contents/PlainTextContentRenderer.cs b/modules/cms-kit/src/Volo.CmsKit.Common.Web/Pages/CmsKit/Components/Contents/PlainTextContentRenderer.cs similarity index 80% rename from modules/cms-kit/src/Volo.CmsKit.Common.Web/Contents/PlainTextContentRenderer.cs rename to modules/cms-kit/src/Volo.CmsKit.Common.Web/Pages/CmsKit/Components/Contents/PlainTextContentRenderer.cs index cf68e25e15..3fcc78f658 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Common.Web/Contents/PlainTextContentRenderer.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Common.Web/Pages/CmsKit/Components/Contents/PlainTextContentRenderer.cs @@ -1,7 +1,7 @@ using System.Threading.Tasks; using Volo.Abp.DependencyInjection; -namespace Volo.CmsKit.Web.Contents; +namespace Volo.CmsKit.Web.Pages.CmsKit.Components.Contents; public class PlainTextContentRenderer : IContentRenderer, ITransientDependency {