dragging fields from a sidebar into a document is an awesome UI design, and it seems like it should be easy, but it is complicated and may be impossible to do
The reason drag and drop is complicated/impossible is:- The sidebar is running in an iFrame, it has limited access to the parent frame in the browser, so managing drag 'n drop from iFrame to parent editor is unreliable
- Detecting where the drop happens, then translating that to a document insertion point is also complicated - The add-on has limited programmatic access to the "editor viewport"
Your add-on does have access to the current insertion point, selection, and document object. These are not enough for drag 'n drop, but do allow you to achieve a similar result with a different design
The option you have available is:
- User puts the cursor in the document where they want the field
- They chose an action in your add-on sidebar (like "insert signature") and your add-on adds it as an element into the document
- Element is added at the current insertion point, and the user can then reposition the element using the Google Docs editor
This approach is not as graceful as drag 'n drop, but works reliably.
Ed