svelte-jsoneditor
svelte-jsoneditor copied to clipboard
New feature added: custom drop down button with custom items possible
Regarding issue #82: "Implement an onRenderContextMenu to customize the context menu #82" I modified the context menu in such a way that it is possible to show a custom dropdown button. The items of this special button can be customized. If one does not want this functionality, one can just leave the button invisible. The code is backward compatible.
Thanks for picking this up @mercurio123 👍
I think this is a step into the right direction, but I would like to go a step further. The solution in this PR allows adding a custom dropdown button, but it does not allow hiding or rearranging buttons for example and cannot be used in React since you have to provide a Svelte component.
What I have in mind is a solution similar to the onRenderMenu
function. This callback gets a list of items (as data, not as Svelte components), and can output a changed list with items. That has some advantages: you can add/remove/move items as you like, and insert new items at the start or end or somewhere halfway, and it can be used in any framework, not only Svelte.
To make a more generic solution similar to onRenderMenu
working we'll need to refactor ContextMenu.svelte to work based on a list with data items, and after that we can implement a callback that allows to change the list before rendering. Does an approach like that make sense to you?
Thank you for your feedback @josdejong
That's correct. At first, I wanted to do it as it has been done with the menu bar. Since I'm new to svelte and JavaScript I constrained it to implement a customizable dropdown button with custom snippets items.
Yes, it makes sense, I will change ContextMenu.svelte as it has been done for the onRenderMenu so that a similar function for the context menu can be implemented.
👍
If you're new to both JavaScript and Svelte, I think this will be a relatively complex undertaking. Feel free to give it a try, but if it is too complicated just let me know (It's on my list but I'm not sure when I'll have time for it).
@josdejong I will, but I will come to it after I have finished the other parts of my project.
Thanks for the update. No problem at all. I'll close this PR for the time being, and maybe it's easiest to create a new PR when you are working on it again.
@josdejong @mercurio123 was this feature ever picked up into a new PR?
No, though in the mean time I've done some internal refactoring that should make it relatively easy to implement an onRenderContextMenu
callback.