-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCkEditor.razor.cs
47 lines (39 loc) · 1.36 KB
/
CkEditor.razor.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
namespace Kimi.CkEditor;
public partial class CkEditor : IAsyncDisposable
{
[Inject]
public KimiJsInterop JsInterop { get; set; } = null!;
[Parameter]
public bool IsReadonly { get; set; } = false;
[Parameter]
public bool IsFullScreen { get; set; } = false;
private string editorId { get; set; } = "kimi-ckeditor-8973";
private string kimiCkEditorDiv { get; set; } = "kimiCkEditorDiv-8973";
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
string funcName = nameof(this.EditorDataChanged)!;
await JsInterop.createCkEditor(editorId, editorId, CurrentValue!, IsReadonly, funcName, DotNetObjectReference.Create(this));
await JsInterop.SetCkEditorReadonly(editorId, IsReadonly);
await JsInterop.SetAllSubElementsWithSameSelector(kimiCkEditorDiv);
if (IsFullScreen)
{
await JsInterop.setNotScrollMaxHeightByClass("ck-editor__main", 0);
}
}
}
[JSInvokable]
public Task EditorDataChanged(string data)
{
CurrentValue = data;
StateHasChanged();
return Task.CompletedTask;
}
public async ValueTask DisposeAsync()
{
await JsInterop.DisposeCkEditor(editorId);
}
}