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

Allow copy node's path

Open elvuel opened this issue 3 years ago • 5 comments

Could be copy on ContextMenu or emit on mousedown.

elvuel avatar Jun 18 '21 03:06 elvuel

Thanks, good suggestion. I think this should be an explicit button in the ContextMenu, and possibly also a quick key.

josdejong avatar Jun 23 '21 07:06 josdejong

@josdejong how about copy JSONPath instead of or over slice?

elvuel avatar Jun 24 '21 04:06 elvuel

Good point about what format to use: JSONPath, JSONPointer, JavaScript notation...

An other idea: I also want to implement a path (like "bread crumbs" on top, like in the old editor:

afbeelding

We could also make the copy button there.

josdejong avatar Jun 26 '21 14:06 josdejong

Another idea it would be nice if you could paste a path too, and then scroll towards this path in the document.

josdejong avatar Apr 16 '22 08:04 josdejong

vote up for copy node path button near the breadcrumbs. Very handy and easy to implement :+1:

dranitski avatar May 26 '22 11:05 dranitski

Hi, I had to recently work around this issue by getting the path from a selected node through onChange (patchResult.from) function then reverting the changes in the document - basically making the doc readOnly but keeping the editable state in order to get the currently selected path. This fix to the API would be really helpful, as the info is already on hand... The path should be available on the API onClick or something similar...

feidhlimx avatar Sep 30 '22 07:09 feidhlimx

I'm working on this feature right now.

I was wondering: what kind of path notation do you guys use? A JSON Path like $.data[2].nested.property, or a JSON Pointer like /data/2/nested/property?

josdejong avatar Oct 12 '22 07:10 josdejong

@josdejong thanks a lot! I guess any will be fine if we can easily parse, split, modify it as we want. Some kind of trigger (onNodePathCopy) will be cool.

personally I like the first one $.data[2].nested.property as default

dranitski avatar Oct 12 '22 13:10 dranitski

Yes I prefer a notation like $.data[2].nested.property better too. I'll start with that.

What would be the use case for a onNodePathCopy callback?

josdejong avatar Oct 12 '22 14:10 josdejong

@josdejong it would let anyone to parse and copy node path in the way one wants, not only as default $.data[2].nested.property format. Just an idea.

dranitski avatar Oct 12 '22 15:10 dranitski

Yes, that makes sense. I have a PR #164 ready. I have implemented a new option pathParser: { parse, stringify }, allowing you to customize how the path is parsed/stringified. By default it uses a JSON Path notation, but you can configure it to use JSON Pointer instead or anything you want.

josdejong avatar Oct 13 '22 09:10 josdejong

First version now published in v0.7.10.

Feedback is very welcome, I can imagine there are good ideas to refine this solution further.

josdejong avatar Oct 13 '22 09:10 josdejong

What would be the use case for a onNodePathCopy callback?

It would be nice to have the JSON path value through the API - on the current selected node, not just after a copy.

This would basically be the same info that is displayed in the navigation bar, but in the API.

How could I achieve this?

I imagine it would be part of the exposed object jsonEditor - which there is a ref to...

feidhlimx avatar Jan 31 '23 07:01 feidhlimx

@feidhlimx there are plans to implement an API to get and set the selection, see #163. I think that will address your suggestion.

josdejong avatar Jan 31 '23 15:01 josdejong