2023-08-18 14:51:42 +08:00

3.0 KiB
Raw Blame History

Export plugin

The Export plugin provides the export function.

Register

import MindMap from 'simple-mind-map'
import Export from 'simple-mind-map/src/plugins/Export.js'
// import Export from 'simple-mind-map/src/Export.js' Use this path for versions below v0.6.0

MindMap.usePlugin(Export)

After registration and instantiation of MindMap, the instance can be obtained through mindMap.doExport.

Methods

All exported methods are asynchronous and return an instance of Promise. You can use the then method to obtain data, or use the async await function to obtain:

mindMap.doExport.png().then((data) => {
  // ...
})

const export = async () => {
  let data = await mindMap.doExport.png()
  // ...
}

The returned data is in the format of data:URL. You can create an a tag to trigger the download:

let a = document.createElement('a')
a.href = 'xxx.png'// .png、.svg、.pdf、.md、.json、.smm
a.download = 'xxx'
a.click()

png(name, transparent = false, rotateWhenWidthLongerThenHeight)

  • name: Name, optional

  • transparent: v0.5.7+, Specify whether the background of the exported image is transparent

  • rotateWhenWidthLongerThenHeight: v0.6.15+Boolean, false, Automatically rotate 90 degrees when the image has a width to height ratio

Exports as png.

svg(name, plusCssText)

  • namesvg title

  • plusCssTextv0.4.0+, When node rich text editing is enabled and domToImage passes false, additional css styles can be added. If there is a dom node in svg, you can set some styles for the node through this parameter, such as:

svg(
  '', 
  false, 
  `* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
  }`
)

Exports as svg.

pdf(name, useMultiPageExport)

v0.2.1+

  • nameFile name

  • useMultiPageExport: v0.6.15+, Boolean, false, Whether to export multiple pages, default to single page

Export as pdf. Unlike other export methods, this method does not return data and directly triggers the download.

After v0.6.0, an additional ExportPDF plugin needs to be registered

import ExportPDF from 'simple-mind-map/src/plugins/ExportPDF.js'
MindMap.usePlugin(ExportPDF)

json(name, withConfig)

nameIt is temporarily useless, just pass an empty string

withConfig``Boolean, default true, Whether the data contains configuration, otherwise it is pure mind map node data

Return json data.

md()

v0.4.7+

Export as markdown file.

getSvgData()

Gets svg data, an async method that returns an object:

{
  node // svg node
  str // svg string
}

xmind(name)

v0.6.6+, an additional ExportXMind plugin needs to be registered

import ExportXMind from 'simple-mind-map/src/plugins/ExportXMind.js'
MindMap.usePlugin(ExportXMind)

Export as an xmind file type, asynchronous method, returns a Promise instance, and the returned data is the data:url data of a zip compressed package, which can be directly downloaded.