I have doubt about adding elements to a widget. I managed to make it work but I wanted to make sure that I did it the right way.
I wanted to use the elem-dragdrop element. So i forked it, then in my widget.js I added a chilipeppr.load method and added this method to the init of the widget.
I also added a div for the element to the HTML.
I did it like this - basically following the tutorial on how to add a widget to a workspace - because if I understood it right the workspace is a widget that contains widgets? So I added the element as ifi it were a widget to my widget.
Is this the right way to add elements to a widget?
I’m assuming you forked a workspace like TinyG or Grbl. If so, then elem-dragdrop is already in that workspace. So you should not try to create your own version of that element. You should instead subscribe to it’s pubsub.
com-chilipeppr-elem-dragdrop/ondropped When the file is dropped. Payload contains the file.
/com-chilipeppr-elem-dragdrop/ondragover When the mouse is hovering over drop area so you can hilite/react. Empty payload.
/com-chilipeppr-elem-dragdrop/ondragleave When mouse stops hovering so you can remove hilites. Empty payload.
/com-chilipeppr-elem-dragdrop/ondragdone When user drops the file onto browser so you can remove hilites. Empty payload. Don’t confuse this with ondropped which is the pubsub that actually contains file that was dropped.
Ahh. Yes, in that case you did it correctly. You can add an element as if it is a widget. In hindsight, I probably should have just named the drag drop element as a widget, but I thought I might end up with more elements than I did.