drawio-integration

diagrams.net Integration

Integration, or “embed mode” is used for cases where the storage of the diagram is taken care of by a host application, and diagrams.net is used for diagram editing. In this case, diagrams.net is used inside an iframe or window with special URL parameters, and is remote controlled using the HTML5 Messaging API. Use embed.diagrams.net only for embed mode.

The basic flow is as follows:

  1. Load embed.diagrams.net with special URL parameters inside an iframe
  2. Send the diagram data to the iframe for editing
  3. Receive and save diagram data from the iframe
  4. Remove iframe

Depending on the requirements, a PNG or SVG image or the XML for the diagram can be used as the storage format. Consider the following when picking the storage format:

The storage can be any persistence mechanism. The image or XML file can be stored and used in the output of the host application, such as an image tag, SVG DOM or HTML viewer. Authentication, file descriptors, revisions etc must be handled by the host application. All communication between the host application and diagrams.net happens on the client-side. The protocol specification is here.

The basic flow of the protocol is as follows:

  1. Wait for init event
  2. Send load action
  3. Wait for save/exit event

In some cases, additional steps may be required to check for a draft state or to export the diagram as an image. Special messages are available in the protocol to show draft states or a template dialog.

Fonts, colors, default styles, libraries, CSS and more can be configured to match the environment and style of the host application by using the configure=1 URL parameter. See localstorage-svg.html.

The following examples are available: