Storage

editor.storage.diagrams holds functions that tell you what is in the document and what the editor can draw. You call them directly, not as commands.
const charts = editor.storage.diagrams.listCharts()
const text = editor.storage.diagrams.read({ pos: charts[0].pos, format: 'chart-syntax' })

Most of these functions only read. Only requestSync changes the document: it runs the syncChartData command on every chart linked to the source. registerSource, setZoom, setPan and setMaximized change only this editor.

Charts, diagrams and tables in the document

FunctionReturns
listCharts()Every chart, see Chart fields
listDiagrams()Every diagram, see Diagram fields
listTables()Every table a chart or a diagram can follow, see Table fields. Empty without chart.linkTables
getOpenInput()The Quick Input or input table the cursor is in, see The open input. null outside one

Chart fields

FieldValue
posThe chart's position
dataThe Chart Data
specThe Chart Spec
rendererThe Renderer the chart names
sourceIts Data Source
delimiterIts delimiter
previewUrlIts preview URL
layoutWhether it stands alone, follows a table, or is hidden below it (setChartLayout)
tableIdThe table it follows, or null
tableReadHow it reads that table, { header?, range? } with only what differs from the default, or null

Diagram fields

FieldValue
posThe diagram's position
formatIts format
sourceIts source
titleIts title
descriptionIts description
viewIts view
optionsIts options
kindThe kind of Mermaid diagram, or null
drawableWhether a Diagram Renderer for its format can draw the source
linkThe table it is drawn from, { tableId, columns }, or null
lanesThe lanes of a diagram drawn from a table, in the order they appear

Table fields

FieldValue
posThe table's position
tableIdIts id, once a chart follows it, or null
headerIts first row
headerCellstrue when the first row is made of header cells. A first row of plain cells names the columns only when it holds no number outside the first column
chartsHow many charts follow it
diagramsHow many diagrams are drawn from it
followersEach chart and diagram that follows it, as { pos, kind: 'chart' | 'diagram' }, in document order

The open input

getOpenInput() returns { pos, view: 'chart-syntax' | 'table', type, delimiter, editing }. editing is set when the input holds an existing chart you are changing, not a new one.

Reading a chart's data

FunctionReturns
read({ pos?, format? })A chart as text in a format, 'chart-json' by default
readGrid({ pos? })The data as a grid of strings. Row 0 is the header
readTable({ pos? })The data as table JSON, or null without a table node in the schema
readText({ pos? }){ format, text } of a chart or a diagram, as an author edits it, or null (Text beside the picture)
parseFormat(format, content, type?){ data, spec, delimiter } parsed from content
getFormat(id)A registered format, for its serialize

parseFormat throws an error with a message when it cannot parse the content.

What the editor can draw

FunctionReturns
describeCapabilities()Chart types ({ id, label, shape, description? }), formats, Renderers and their types, the default Renderer, sources, delimiters, trigger and styles
chartTypesThe built-in chart types and those of the chartTypes option. This is a property, not a function
canRender(spec)Whether a registered Renderer draws the type
rendererFor(spec, preferred?)The Renderer a chart would be drawn with
diagramRendererFor(format)The Diagram Renderer a diagram of that format would be drawn with, or null
rulesFor(renderer)The rules a Renderer's charts and diagrams follow, its own and those of rendererRules: { attribution?, exports? }
refresh()Nothing. It draws every chart and diagram again. Call it after a theme change made only in CSS

Export

FunctionReturns
export(target, options?)A chart or a diagram as a file, see export
exportAll(options?)Every chart and diagram that can be drawn, as files with their pos, in document order
exportDocx(options?)A promise of a Word document with native charts and diagrams as pictures: { blob, notes }. See Word

Data Sources

FunctionWhat it does
readSource(source)Returns a promise of the data a source returns now. It writes nothing
requestSync(source)Reads a source and writes the data into every chart linked to it. Returns a promise of true when it wrote data
registerSource(provider)Adds a provider at run time and returns a function that removes it
getSource(id), listSources()Return the registered providers

requestSync resolves to false when the read fails or no chart is linked to the source. A failed read keeps the last snapshot and goes to onSourceError.

Zoom, pan and maximize on screen

setZoom, getZoom, setPan, getPan, getShownSize, setMaximized and getMaximized change or read how this editor shows a chart or a diagram. They never change the document. See View functions.

setMaximized also dispatches an empty transaction, so a UI that listens to transaction updates. That transaction is not added to the undo history.