-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Feature request - events handling with more informations #39
Comments
Interesting idea. This will give you as developer indeed more flexibility to interact with the editor. I'm still thinking about how to shape this in a compact but flexible way. JSONEditor uses one delegated
Where the |
You're right about the generic event callback, it would be basically the same. However there are a few small differences that should be considered :
As for the parameters, I would recommend keeping the "target" param at least : because when clicking on a node it allows you to know if the field or the value was clicked, which is critical if you want to change either the field or the value from outside. So the parameters would be : event, target, node Another point regarding the API : I tried to add subelements in an object or array. I did as follow, inside a "double click event" : node._onInsertAfter('test', 'toto', 'string');
if(node.type=="object" || node.type=="array")
{
var createdNode=node._nextNode();
var nodePrev=node.childs[0];
node.moveBefore(createdNode, nodePrev);
} I'm not sure it's the best solution, but I noticed I need to call "private" methods ( underscore prefixed). I believe such things as : add node after, add node inside, remove, move, update field, update value, should be done with a simple api call. Actually I think the only missing method would be : add node inside, right ? Regarding new methods, I think it would be interesting to have to new easy to use functions :
What do you think of these ? Do they already exist ? (I must confess I did not check on those 2) |
Thanks for your thoughts. I think we should reckon two types of developers who may use the editor:
The first group is happy to set some options and a callback on change of the data, maybe override the style of the editor and that's it. For the second group (you are amongst them I suppose), the editor as it is comes close to what they need, but misses some essential things for their specific use case. They want to integrate the editor tightly in a large web application. They want to manipulate the internals of the editor: Nodes, HTML Events, HTML DOM, etc. This requires knowledge about how the editor internally works, else you can easily mess up the DOM, node tree, history, etc. The first group does not want to know about these internals, whilst the second group does want easy access to it. Trying to create one API for both groups would definetely fail: the first group will drown in a complex, extensive API, and the second group will never have enough options for all their specific needs. I think the API should aim for the first group of developers, and should be clean, compact, and straightforward. For the second group, the internal structure of the editor should be as easy as possible to adjust and extend, and I'm sure we can improve on that a lot. It should be easy to extend the JSONEditor prototype with your own MySuperJSONEditor prototype, override and extend some methods and event handlers and tune it as you wish. |
I agree with you about the two groups, but actually I think I'm still in the first one : I surely don't wan't to touch the editor's internal, since any modification could be lost with the next update. For me, there are two axes :
Anything else should probably developped outside of the lib IMHO : like for example context menu to change a field label or value, automatically adding subitems to an object etc. |
Nice discussion. I think we are on the same page, though our idea on what should be "standard" functionality differs a little. I try to beware of feature creep, that is why I want to keep the API simple and concise. For you, manipulating HTML events and the node tree should be standard functionality, but for me this falls under the "advanced" usage, as (right now) these kind of manipulations require you to have knowledge of the internal workings of the Editor - you can mess up stuff when not doing this correctly. So far I only focused on exposing a simple API for using the Editor as is, with just a few configuration options. I didn't focus on an API allowing you to manipulate nodes, the node tree, the actions menu, etc. This "advanced" API is almost there though, with private methods like Maybe we end up with three levels of API:
|
I completely agree with the three levels you describe, but now, as everyone has limited time ressources, you probably have to make a choice : what to develop first. |
Indeed, working out this API will make the editor much more versatile in usage. So far the focus has been on the end user: making a nicely working editor. With the recent release of version 2, these editing features start to mature. Currently I'm replacing the plain text editor with Ace (see beta), replacing the build script with jake, and merging/reorganizing the code. After that I hope to address the API, documentation, and examples. And another important wish is to improve the performance of the editor with large files. |
Hi Jos, |
Thanks for your input @Asc2011 . I've recently started rewriting JSONEditor from scratch (see this branch), with an architecture allowing customization via hooks. The |
I am using the jsoneditor with sceditor editor and I could not use the code and no error occurred but did not display the message, was it just an idea in speech or is there such an option? |
This event handling API is indeed not yet implemented. |
Need this also badly |
Hi,
I want to use jsoneditor in a large project, but to do so I need to interact more deeply with the editor. To do so I need to handle events like : click, double click, right click, etc.
I patched the latest editor release but I'm unsure how to submit my modifications si here is a proposition :
Line 2753 add :
Line 2735 add :
Line 2711 add :
Line 2693 add :
Line 2662 add :
Line 524 add :
This allows me basically to fully handle events, including interacting with the clicked elements etc.
The text was updated successfully, but these errors were encountered: