josdejong / svelte-jsoneditor

A web-based tool to view, edit, format, repair, query, transform, and validate JSON
https://jsoneditoronline.org
Other
814 stars 108 forks source link

Feat: onRenderContextMenu return false #399

Closed 1pone closed 3 months ago

1pone commented 5 months ago

Always hide the context menu when onRenderContextMenu return false

1pone commented 5 months ago

Optimize for this pr https://github.com/josdejong/svelte-jsoneditor/pull/396

josdejong commented 4 months ago

Thanks! I think the approach to extend onRenderContextMenu to return false is the right approach. However I think implementing it neatly requires a bit more refactoring internally. The onRenderContextMenu callback should be invoked only once, and we should not introduce a "test call" with empty items to see if it does return false (that can lead to unexpected behavior.

Right now, onRenderContextMenu is called inside TreeContextMenu and TableContextMenu. I think this call should be pulled out of those components, it should be moved to the two openContextMenu() implementations: invoke onRenderContextMenu, if it returns false, cancel opening the modal, and otherwise, pass the items to the modal. Does that make sense?

1pone commented 3 months ago

Thanks for the suggestion, I've tried to rewrite this part of the code in https://github.com/josdejong/svelte-jsoneditor/pull/411, can you help me see if there's any problem?

josdejong commented 3 months ago

Published now in v0.23.0