svelte-jsoneditor icon indicating copy to clipboard operation
svelte-jsoneditor copied to clipboard

customize the collapsed render text for a node

Open noahhai opened this issue 3 years ago • 2 comments

Awesome component, thank you!

Wondering if there is any way to modify what gets rendered for collapsed nodes. For arrays it shows 'n items' and for objects it shows 'n props'.

Eg for objects I would want something like prop of "renderCollapsedDesc" which could be Func[node], so could render for example {Object, key=${node.name}} to give more information on the node when in collapsed mode.

I didn't see this as configurable so wanted to check. If it's not supported, would you be able to point me to where that formatting is done in the code so I could take a stab at it?

noahhai avatar Sep 21 '22 08:09 noahhai

Thanks for your suggestion. The displayed text is hard coded right now, the code is here for objects:

https://github.com/josdejong/svelte-jsoneditor/blob/baf8ebe791c3042dc2f38d6f0a0ada9a00ae52fd/src/lib/components/modes/treemode/JSONNode.svelte#L755-L758

And here for arrays:

https://github.com/josdejong/svelte-jsoneditor/blob/baf8ebe791c3042dc2f38d6f0a0ada9a00ae52fd/src/lib/components/modes/treemode/JSONNode.svelte#L629-L642

I'm open to implementing a configuration option to customize the text with a callback function. Maybe people would like to be able to fully hide the text, that could also be an option.

josdejong avatar Sep 23 '22 12:09 josdejong

Thanks, I'll take a look!

noahhai avatar Oct 08 '22 20:10 noahhai

An easy way to hide and/or change the view of properties/items of an object is exactly my current task... Would be really nice config feature in my opinion.

simeonackermann avatar Oct 26 '22 08:10 simeonackermann

Moving this idea to the Discussions > Ideas section since we are not actively working on it. Help implementing this would be welcome.

josdejong avatar Dec 13 '23 08:12 josdejong