Slatebox Docs
Browse documentation

Keep a connection when you reopen a slate

Make two native notes, link them, and round-trip the document through SlateJSON.

Sound mapSlateboxJS
Loading canvas…

Make a note for a field recording and another for its transcript. Draw a connection between them. Reopen the slate and move the transcript. The end of the line follows the note.

Copy slateboxjs.mjs and slateboxjs.css from the pinned file build’s dist/ directory beside your HTML page. Serve the page over HTTP with this container and stylesheet.

<link rel="stylesheet" href="./slateboxjs.css">
<div id="slate" style="height:420px"></div>

Run the following in a <script type="module"> on that page.

import { Slate } from './slateboxjs.mjs'

const slate = new Slate('#slate')
const recording = slate.addNode({ id: 'audio', x: 60, y: 80, width: 170, height: 75, text: 'Field recording' })
const transcript = slate.addNode({ id: 'words', x: 340, y: 80, width: 170, height: 75, text: 'Transcript' })
await Promise.all([recording.ready, transcript.ready])
recording.relationships.addAssociation(transcript)
const saved = slate.exportJSON()
await slate.loadJSON(saved)
slate.fitToContent()
console.log(slate.getNode('audio').relationships.associations.map(link => link.childId))

Expect ['words'] and a visible line between the two notes. Store the exported JSON string in your application’s document store to reopen it in a later session.

Open a blank slate