Adds ability to disable dropCursor on Nodes #13
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "patch-2"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This PR adds a
disableClasswhich can be placed on certain Nodes that you might not want thedropCursorto appear on.Use case: Imagine a custom atom Node that allows files to be dragged into it from the OS. Without this check to disable the dropCursor it will display the cursor above or below this custom Node, incorrectly indicating that the file will be dropped outside of the Node.
I don't think using DOM classes for this is the best approach here. But I'd be okay with having a node spec property (say
disableDropCursor) that has this effect.@marijnh Thanks for your reply. I agree, using DOM classes isn't the best and would be more than happy to adjust this PR to your suggested approach. I'm quite new to ProseMirror and therefore not entirely educated on the entirety of its capabilities in terms of customisation. I believe this is the Node spec you're referring to - my assumption then is that adding a
disableDropCursorproperty would not be something a plugin is capable of doing and therefore would require a change to theNodeclass itself - please correct me if I'm wrong. Any guidance on a way forward would be appreciated. Thanks!The raw object that the user provides as node spec is stored in
NodeType.spec, so it is possible for extensions to recognize new node spec properties without changing the model package.@marijnh I update the PR to check against a Node spec property instead. Works well. The only thing I found was it would also disable the drop cursor when dragging around existing Nodes within the document - so if you wanted to re-arrange text, it wouldn't display the drop cursor when a Node with
disableDropCursoris its sibling (which makes sense). As my use case is catered towards dragging external sources into the editor, I added a check against the editor state to see if it's actually document nodes being dragged. This makes me wonder if the propertydisableDropCursoris descriptive enough. Something likedisableDropCursorWhenSourceExternalwould be more accurate, but also quite verbose.pos.insideis a more appropriate position to query (if you drag over the end of a leaf node,pos.posmight point after that node)view.draggingdoesn't have to be hard-coded? That way you could even inspect thedataTransferto figure out whether files are being dragged to further refine the behavior. (Could pass the view and the node's resolved position to the function.)I like the idea of a predicate function for better flexibility so I've added one as an option, but I may have misunderstood you as it sounds more like the predicate should be returned in some manor with the view and resolved node position.
Ah, what I meant was that a node spec could contain a predicate function. Maybe have a
disableDropCursorproperty that can be either a boolean or a function, and will be called with a view and a resolved position (returning a boolean) when it is a function.Got it, that makes a lot more sense now that I have a fresh head. Updated the code to reflect this.
Thanks. I've merged this and followed up with attached patch, which adds documentation and fixes some corner cases (such as when pos is null) and code style. Could you see if the result works for you?