Put the canvas in your own page.
SlateboxJS draws an editable SVG diagram inside an element of your page. Your code adds notes and arrows, people move and rename them, and one call gives you the whole slate as a string to store wherever you like.
MIT licensed
The button opens the same two notes in the hosted app, drawn from one typed line. The library itself needs no account. Run the quickstart in the docs ↗
import { Slate } from 'slateboxjs'
import 'slateboxjs/style.css'
const slate = new Slate('#board',
{ name: 'Listening bench' })
const evidence = slate.addNode({
...note, ...sand, id: 'evidence',
x: 0, y: 0,
text: 'Visitors stop\nto listen',
})
const decision = slate.addNode({
...note, ...mint, id: 'decision',
x: 250, y: 110,
text: 'Set a bench\nby the speaker',
})
await Promise.all(
[evidence.ready, decision.ready])
evidence.relationships.addAssociation(
decision,
{ ...arrow, id: 'evidence-decision' })
const saved = slate.exportJSON()
const { nodes } = JSON.parse(saved)
print(nodes.length + ' notes saved')
await slate.loadJSON(saved)
const drawn = slate.getAllNodes()
print(drawn.length + ' notes drawn again')
A script calls slate.addNode twice and two notes appear: “Visitors stop to listen” and “Set a bench by the speaker”. It calls addAssociation and an arrow joins them. Ines drags the second note lower and renames it “Set two benches by the speaker”; the arrow stays attached. The script calls slate.exportJSON and prints that two notes are saved, then calls slate.loadJSON with that string and the same two notes are drawn again.
How it works
An element, some notes, a string.
Give it an element
new Slate('#board', { name })turns an element with a visible height into a canvas. The quickstart in the docs is one HTML file that imports the browser module and its stylesheet.Add notes and arrows
slate.addNode(options)returns the note.note.relationships.addAssociation(other)draws the arrow. Give a note a stableidandslate.getNode(id)finds it again.Let people edit
Dragging, renaming and connecting come with the canvas. Your code can do the same with
position,setTextandsetColors.Save and load
slate.exportJSON()returns a string.await slate.loadJSON(saved)draws it again. Callslate.destroy()when the view goes away.
Native workshops
A workshop is notes on the same slate.
Give attachWorkshop the slate you already have and a workshop model. Lanes and cards are drawn as real notes beside your own, with the slate’s pan and zoom. The model stays the one saved source of truth.
import { attachWorkshop }
from 'slateboxjs/workshops/model'
const board = attachWorkshop(slate, model, {
origin: { x: 260, y: 0 },
onChange(next) { save(next) },
onRefuse({ reason }) { toast(reason) },
})- A move
- A card dropped in a lane that has room commits, and
onChangegets the new model. - A refusal
- A drop the rules close glides back. The lane shows the reason for about a second and a half, and
onRefusegets the sentence. - Your export
slate.exportJSON()never contains the workshop’s notes. They are a drawing of the model.
A slate holds two ordinary notes: “Release 3.2” and “Friday has two slots”. A workshop is attached and two lanes appear as notes on the same slate: Ships Friday, which holds two cards, and Ships Monday. Mara moves Invoice export into Friday and the lane reads 2 of 2. Dev tries to add New onboarding, and the lane refuses it with the words “It already holds 2 of 2 cards.” The card glides back to Monday.
The library draws. Your application keeps the data.
SlateboxJS creates objects in the page. Where a slate is stored, who may open it and who is on a call belong to the application around it.
- A string
exportJSON()gives the slate as text. Put it in your own database, a file or the browser’s storage.- An image
slate.svg()returns SVG markup of the board, andawait slate.png()renders a raster export.- A frame
slate.fitToContent()frames everything on the board after your code has drawn it.- A hosted slate
- To change a slate that lives in the Slatebox app, use the HTTP API instead.
The plan this needs.
- Free
- None. The library is MIT licensed and runs in your page without an account or a key.
- Pro and Team
- Nothing more is needed for this. Plans are for the hosted app.
Next
More ways to build on it.
Two notes and an arrow, in one file.
The quickstart is a single HTML file. Move the notes, rename one, then save and reload to see the same map.