Add extensible customer buttons#1215
Conversation
…mples\25_custom_buttons.html
|
Thanks Daniel, I think your PR will address #831, right? I think we have to think a couple of things through:
|
|
Yes, the idea is consistent with address #831 although I've never seen it, but it addressed by chance. The three points you mentioned came into my mind as soon as I submitted the PR today , haha. 1|2. Because I wanted to send JSON directly to my server in my application, I found a extra button in my page looks a little ugly or disharmony, so I first extended this feature and found it to be very useful, We can simply add a mode option to determine which mode the button is applied in; 3.We can add a option [index] and then we can add an array [hidden] to decide which buttons not to display whether it's built in or the custom, We can even manage the built-in buttons in such a data format in one place, and unify their behavior and use the same rendering method in different modes. So finally the option buttons like this: That's all I can think of for now, and then I'll implement it in my branch and show you, and I think we can make it better |
1.Move regular buttons configuration into component defaultOptions.js 2.Use editor._createButtons() to render the specified button for their mode 3.Add option disableButtons to disable buttons by the name of their configuration 4.User can manage the customer button order by button's index configuration
|
Hi, 1.Move regular buttons configuration into component defaultOptions.js It doesn't look perfect, let's optimize it next step. |
|
Thanks for the updates Daniel, and sorry for my late reply, I have sometimes trouble keeping up with all open issues and PR's. Very neat that you extracted the default buttons into I like your API proposal where you can pass an array to I'm still a bit in doubt about the index. It can get tricky when in the future a new built-in button will be added, and (though not a show stopper), you can't create one button for multiple modes when they need a different index. I have another idea: we can do exactly the same as for the context menu, which has a const options = {
onCreateMainMenu: function (items, mode, editor) {
// add buttons at the position you want (beginning, end, or somewhere in the middle)
// remove buttons you do not want
// determine whether or not to add/remove buttons depending on the current mode
const extendedItems = items.concat([myNewButton1, myNewButton2])
return extendedItems
}
}What do you think? |
|
@josdejong |
|
@vlador4ik it is on the wishlist yes. On a side note: the successor of jsoneditor, svelte-jsoneditor, is fully built around supporting copying/pasting data. You can give it a try at https://jsoneditoronline.org/beta/. Just select something in the editor and use cut/copy/paste. |
Added the ability to add customer buttons to the menu bar and the examples\25_custom_buttons.html
1.add a new option ( buttons ) which contains the configuration of a custom buttons array,
the button config fileds are [
title(description of this button's function),
className(define the custom button icon),
target(function to call onclick) ];
2.Render the buttons after create-mode-box step in text mode.