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

Expose currently expanded paths #417

Open sallaben opened 3 months ago

sallaben commented 3 months ago

Hi! Is it possible to get a list of the currently expanded paths from the editor instance in any way?

josdejong commented 3 months ago

The predecessor, jsoneditor has a callback onExpand that is invoked when a path is expanded/collapsed. We can look into implementing something like that.

More broadly thinking: it would be neat to implement an API where you can fully control the expanded state, similarly to how you can pass content and selection, with 2-way binding in Svelte, and extra getter/setter methods for the vanilla editor. This may require refactoring the data models of the expanded state, not sure, but we'll have to think that through before making it public.

nbabaka2023 commented 3 months ago

That would be great! I used a predecessor but found this project more powerful for my needs!

sallaben commented 3 months ago

The predecessor, jsoneditor has a callback onExpand that is invoked when a path is expanded/collapsed. We can look into implementing something like that.

More broadly thinking: it would be neat to implement an API where you can fully control the expanded state, similarly to how you can pass content and selection, with 2-way binding in Svelte, and extra getter/setter methods for the vanilla editor. This may require refactoring the data models of the expanded state, not sure, but we'll have to think that through before making it public.

Thanks for the reply! That is my intended usage too - I'd like to be able to store the entire editor state (content, selection, expanded, and any other pieces) in localstorage so that the editor loads the same way it was previously set to, persisting across page refresh.