Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow copy node's path #13

Closed
elvuel opened this issue Jun 18, 2021 · 14 comments · Fixed by #164
Closed

Allow copy node's path #13

elvuel opened this issue Jun 18, 2021 · 14 comments · Fixed by #164
Labels
enhancement New feature or request

Comments

@elvuel
Copy link

elvuel commented Jun 18, 2021

Could be copy on ContextMenu or emit on mousedown.

@josdejong josdejong added the enhancement New feature or request label Jun 23, 2021
@josdejong
Copy link
Owner

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

@elvuel
Copy link
Author

elvuel commented Jun 24, 2021

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

@josdejong
Copy link
Owner

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
Copy link
Owner

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

@dranitski
Copy link

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

@feidhlimx
Copy link

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...

@josdejong
Copy link
Owner

josdejong commented Oct 12, 2022

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?

@dranitski
Copy link

dranitski commented Oct 12, 2022

@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

@josdejong
Copy link
Owner

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?

@dranitski
Copy link

@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.

@josdejong
Copy link
Owner

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
Copy link
Owner

First version now published in v0.7.10.

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

@feidhlimx
Copy link

feidhlimx commented Jan 31, 2023

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...

@josdejong
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants