-
Notifications
You must be signed in to change notification settings - Fork 3.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create isolated elements inside Slate #3425
Comments
When you try to render your custom node inside a slate editable, are you wrapping them inside a |
I think the problem is with custom elements, and assumptions made by slate-react about text DOM nodes. It seems that Here is minimal repro: |
I need this too.
I thinks this is caused by slate handling all
Currently I use the same hack just like #3426 said. adddin |
I found another feature request from a while ago (#2072) that wanted to introduce an Island component to essentially achieve this isolated behaviour. The conversation seems to have dropped off but it bought up a few good things to be aware of/factor in. In regards to a possible implementation, from what I can see in the codebase the Editable component has a method called hasEditableTarget. This is called as a check before a number of the event handlers (onDOMBeforeInput, OnKeyDown, ect). This method then calls ReactEditor.hasDOMNode which checks if one of the ancestors of the element in question is the editor element. I could see an Island/Isolate component just wrapping a component with a div that has an attribute data-isolate, and we add another check into ReactEditor.hasDOMNode that checks if an ancestor has this attribute. If it does than it returns false and the check fails, thereby telling Slate not to worry about this node. This is still definitely overlooking some of the issues bought up in #2072 such as what happens to the focus when you click on this isolate component. I'm going to put in some time next week into seeing if I can get something working. I would also really like to explore what can be done to mitigate a few other issues I have discovered since integrating Slate and CodeMirror:
|
I Agree. @Francesco-Lanciana |
@ryanmitts I had a look at your changes and it seems to me like they at least allow for elements to exist within slate that can steal focus from Slate and not cause an error to occur, which is a big step forward. The main other thing that needs to be addressed is how we can allow for isolated nodes that don't need to contain a child text node. Since this is one of the underlying assumptions behind Slate it probably needs a bit of thought however, especially if we want to give an API that allows for focus to be transferred between the isolated element and Slate in a simple manner. My thoughts so far is that this needs to be a new concept that is seperate to a void element since they are aiming to do two seperate things. |
@Francesco-Lanciana That makes sense, my biggest struggle is I don’t really know what a void node is supposed to behave like fully because it’s not really documented and the behavior is different between pre .50 and after (like why would a void Node need text). My main intention is to be able to recreate what I have in the older Slate version in the newer. That probably gives me a bias to how void nodes behave. I’d like to think about an implementation that accounts with maybe some other concept, I guess I might need some help comparing and contrasting void nodes vs. this new concept. |
Do you want to request a feature or report a bug?
Feature Request
What's the current behavior?
If you have an element inside the React Editor that doesn't contain a text node and can receive focus (and therefore steal it from Slate) then you get the error: Cannot resolve a Slate node from DOM node.
This is an issue when you want to add something like CodeMirror inside the editor as it needs focus.
What's the expected behavior?
It would be great if Slate gave you the ability to have isolated elements inside the Editor so you could have an escape hatch from slates event handlers. This would be useful for adding in elements that need to steal focus from the editor, for example a code editor like CodeMirror. It would also be useful for adding things like the hover toolbar that Notion has, where it needs to be positioned relative to one of slates elements.
![Screen Shot 2020-01-07 at 11 42 09 am](https://user-images.githubusercontent.com/20393195/72300089-e3156780-36b6-11ea-8852-09a5c65ff913.png)
Let me know if I'm just missing a key concept that makes this doable. Otherwise I'm happy to contribute a PR, I would just need a little guidance in terms of scoping the issue - i.e. what are all the things I haven't considered.
The text was updated successfully, but these errors were encountered: