DocumentStore manages the collection of shapes and their ordering on the canvas.
@tsdraw/core
Document store
API reference for the DocumentStore class
The
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
API reference for the DocumentStore class
DocumentStore manages the collection of shapes and their ordering on the canvas.
import { DocumentStore } from '@tsdraw/core'
| Method | Returns | Description |
|---|---|---|
createShape(shape) | void | Add a shape to the store |
updateShape(id, partial) | void | Update shape properties |
deleteShape(id) | void | Remove a shape |
getShape(id) | Shape | undefined | Get a shape by ID |
getCurrentPageShapes() | Shape[] | All shapes in insertion order |
getCurrentPageShapesSorted() | Shape[] | Shapes sorted by z-index |
getCurrentPageRenderingShapesSorted() | Shape[] | Shapes filtered and sorted for rendering |
getShapeIdsInBounds(bounds) | ShapeId[] | Find shapes that overlap with a bounding rectangle |
const unsubscribe = store.addListener(() => {
console.log('Shapes changed:', store.getCurrentPageShapes().length)
})
// later
unsubscribe()
interface TsdrawDocumentSnapshot {
records: TsdrawPersistedRecord[]
}
interface TsdrawPersistedRecord {
typeName: 'page' | 'shape'
// ... record data
}
import { documentSnapshotToRecords, recordsToDocumentSnapshot } from '@tsdraw/core'
const records = documentSnapshotToRecords(snapshot)
const snapshot = recordsToDocumentSnapshot(records)