Rte expose editor#666
Conversation
| if (!(window as any).dash_mantine_components) { | ||
| (window as any).dash_mantine_components = {}; | ||
| } | ||
| if (!(window as any).dash_mantine_components._editorInstances) { | ||
| (window as any).dash_mantine_components._editorInstances = {}; | ||
| } | ||
| if (!(window as any).dash_mantine_components.getEditor) { | ||
| (window as any).dash_mantine_components.getEditor = function(id: string) { | ||
| return (window as any).dash_mantine_components._editorInstances[id]; | ||
| }; | ||
| } |
There was a problem hiding this comment.
Is it necessary to create these inside the editor component? Feels like you could create and export the getEditor function and the empty _editorInstances object in the non-fragment RichTextEditor.tsx... then import just the _editorInstances object here and add / remove this editor to it, and import getEditor in the top-level index.tsx to attach it to the main namespace.
The advantages of that are (1) users can depend on getEditor existing from the beginning, whether or not an editor has been rendered, and (2) _editorInstances doesn't need to be exposed in the main namespace at all (though the latter you could accomplish by making it a constant outside the component in this file).
Also id is a string by the time it gets to the component being rendered, but to support PMCs should getEditor call stringifyId on it?
|
Thanks @BSd3v for your help getting the updated version working 🤗 |
This PR exposes the RichTextEditor editor instance using
dash_mantine_components.getEditor(id). This gives access to all the editor commands in the Tiptap API https://tiptap.dev/docs/editor/api/commandsNote - the test can be combined with #665 when it's merged.
Here's a cool use-case that can be used in the docs - a character and word counter for the content: