tinymce / tinymce-blazor

Blazor integration
MIT License
45 stars 13 forks source link

Sample on how to define Key "setup" in Editor.Conf Dictionary #73

Open davidmfritz opened 10 months ago

davidmfritz commented 10 months ago

Hi there,

I'd like to have an example on how to define a reference to a JavaScript function for Editor.Conf that actually gets executed when tinymceBlazorWrapper.init is run.

<Editor Value="@Text" ScriptSrc="/js/tinymce/tinymce.min.js" Conf="@_editorConf" ValueChanged="ValueChanged" />

@code {

// ...

    private readonly Dictionary<string, object> _editorConf = new()
    {
        {"setup", "<<What to write here?>>"}
    };
}

Can you help me with this issue?

Thank you in advance! Best regards, David

exalate-issue-sync[bot] commented 10 months ago

Internal Ref: INT-3238

abhijeetgupta1988 commented 10 months ago

Refer following :

private Dictionary<string, object> editorConf = new Dictionary<string, object>{
{"toolbar", "undo redo | casechange blocks | bold italic backcolor | alignleft aligncenter alignright alignjustify | bullist numlist checklist outdent indent | removeformat | code table help"},
{"width", 800},
{"plugins","code,advlist,autolink,lists,link,image,charmap,preview,anchor,searchreplace,visualblocks,fullscreen,insertdatetime,media,table,help,wordcount"}

};

davidmfritz commented 10 months ago

Thank you, @abhijeetgupta1988, but that doesn't solve my issue on how to define a JavaScript function in a C# string that then gets executed with this NuGet Package.

spocke commented 8 months ago

There isn't a way currently the config js JSON serialized and so you can't pass in a function reference to it.

Not sure exactly how one would solve this maybe have a list of options that are callbacks then treat strings inside them as things you resolve in the global namespace. So setting "setup: "myFunc" in the C# record would then basically do "setup: myFunc" if myFunc is a global function if one want to hide that then one could have it be namespaced like setup: "foo.bar.baz.myFunc" can't think of any other idea so others are welcome.

spocke commented 8 months ago

You can set things client side using the https://www.tiny.cloud/docs/tinymce/6/blazor-ref/#jsconfsrc though it really depends in what you need inside that setup function call. If it's all client side JS then the JsConfSrc should work.