We use clj-devtools
within re-frame-10x
. We use clj-devtools
to render CLJS data to browse-able HTML and let the programmer inspect it. And it is really good, thanks!
(So, just to be crystal clear, our use is outside of Chrome devtools - we're using this library to render CLJS data structures in a normal HTML page setting)
When a user of re-frame10x
is browsing around the data structures, the user would like to be able to right-click on an arbitrary node (within the rendering) and obtain information about that node, specifically the path from the root of the data structure to the point they are clicking.
So, by right-clicking on some value in the rendering, they might get a popup menu and choose the "path to clipboard" option, which might put a string like this into the clipboard:
[:a :path :to 5 :the :item] ;; 5 is meant to indicate some index into a vector
Now, obviously this is not possible currently. And previously when this has come up we've just said "no" can't be done, end of story. But it came up again recently and in the process of saying "no", I had a further thought ...
Could this be achieved using the following technique:
- during the render process ... decorate each HTML element with an attribute, called say
data-clj-path
, which would carry the [:a :path :to 5 :the :item]
information as a string.
- then, in the context of re-frame-10x, we could wrap a right-click handler around our use of clj-devtools and, in the handler, inspect the source HTML element for its
data-clj-path
. Bingo, now we have the path and can write it to the clipboard ... or whatever else).
I'd be prepared to have a go at making this happen, but before I take on the learning curve, I wanted to check in with you:
- off the top of your head, does this seem possible to you? Ie. can the current path be rendered into the HTML as a
data-*
attribute? Or should I just stop right now and abandon all hope. :-)
- Would you be willing to accept a PR for this, assuming I can find some time to do it?
- (optional) if you would be willing to accept a PR, do you have any hints about where I should look first?