Skip to content

BlockSuite API Documentation / @blocksuite/store / Doc

Class: Doc

Constructors

new Doc()

new Doc(__namedParameters): Doc

Parameters

__namedParameters

DocOptions

Returns

Doc

Defined in

packages/framework/store/src/store/doc/doc.ts:269

Properties

_blockCollection

protected readonly _blockCollection: BlockCollection

Defined in

packages/framework/store/src/store/doc/doc.ts:28


_blocks

protected readonly _blocks: Signal<Record<string, Block>>

Defined in

packages/framework/store/src/store/doc/doc.ts:30


_crud

protected readonly _crud: DocCRUD

Defined in

packages/framework/store/src/store/doc/doc.ts:32


_disposeBlockUpdated

protected readonly _disposeBlockUpdated: Disposable

Defined in

packages/framework/store/src/store/doc/doc.ts:34


_query

protected readonly _query: Query

Defined in

packages/framework/store/src/store/doc/doc.ts:36


_readonly?

protected readonly optional _readonly: boolean

Defined in

packages/framework/store/src/store/doc/doc.ts:41


_schema

protected readonly _schema: Schema

Defined in

packages/framework/store/src/store/doc/doc.ts:43


slots

readonly slots: object & object

Type declaration

historyUpdated

historyUpdated: Slot<void>

yBlockUpdated

yBlockUpdated: Slot<{ id: string; type: "add"; } | { id: string; type: "delete"; }>

Type declaration

blockUpdated

blockUpdated: Slot<{ flavour: string; id: string; init: boolean; model: BlockModel<object, SignaledProps<object>>; type: "add"; } | { flavour: string; id: string; model: BlockModel<object, SignaledProps<object>>; parent: string; type: "delete"; } | { flavour: string; id: string; props: { key: string; }; type: "update"; }>

ready

ready: Slot<void>

This is always triggered after doc.load is called.

rootAdded

rootAdded: Slot<string>

This fires when the root block is added via API call or has just been initialized from existing ydoc. useful for internal block UI components to start subscribing following up events. Note that at this moment, the whole block tree may not be fully initialized yet.

rootDeleted

rootDeleted: Slot<string>

Defined in

packages/framework/store/src/store/doc/doc.ts:45


updateBlock()

updateBlock: <T>(model, props) => void(model, callback) => void

Type Parameters

T extends Partial<BlockProps>

Parameters

model

BlockModel<object, SignaledProps<object>>

props

T

Returns

void

Parameters

model

BlockModel<object, SignaledProps<object>>

callback

() => void

Returns

void

Defined in

packages/framework/store/src/store/doc/doc.ts:79

Accessors

awarenessStore

Get Signature

get awarenessStore(): AwarenessStore<BlockSuiteFlags>

Returns

AwarenessStore<BlockSuiteFlags>

Defined in

packages/framework/store/src/store/doc/doc.ts:144


awarenessSync

Get Signature

get awarenessSync(): AwarenessEngine

Returns

AwarenessEngine

Defined in

packages/framework/store/src/store/doc/doc.ts:148


blobSync

Get Signature

get blobSync(): BlobEngine

Returns

BlobEngine

Defined in

packages/framework/store/src/store/doc/doc.ts:152


blockCollection

Get Signature

get blockCollection(): BlockCollection

Returns

BlockCollection

Defined in

packages/framework/store/src/store/doc/doc.ts:156


blocks

Get Signature

get blocks(): Signal<Record<string, Block>>

Returns

Signal<Record<string, Block>>

Defined in

packages/framework/store/src/store/doc/doc.ts:160


blockSize

Get Signature

get blockSize(): number

Returns

number

Defined in

packages/framework/store/src/store/doc/doc.ts:164


canRedo

Get Signature

get canRedo(): boolean

Returns

boolean

Defined in

packages/framework/store/src/store/doc/doc.ts:168


canUndo

Get Signature

get canUndo(): boolean

Returns

boolean

Defined in

packages/framework/store/src/store/doc/doc.ts:172


captureSync

Get Signature

get captureSync(): () => void

Returns

Function

Capture current operations to undo stack synchronously.

Returns

void

Defined in

packages/framework/store/src/store/doc/doc.ts:176


clear

Get Signature

get clear(): () => void

Returns

Function

Returns

void

Defined in

packages/framework/store/src/store/doc/doc.ts:180


collection

Get Signature

get collection(): DocCollection

Returns

DocCollection

Defined in

packages/framework/store/src/store/doc/doc.ts:184


docSync

Get Signature

get docSync(): DocEngine

Returns

DocEngine

Defined in

packages/framework/store/src/store/doc/doc.ts:188


generateBlockId

Get Signature

get generateBlockId(): () => string

Returns

Function

Returns

string

Defined in

packages/framework/store/src/store/doc/doc.ts:192


history

Get Signature

get history(): UndoManager

Returns

UndoManager

Defined in

packages/framework/store/src/store/doc/doc.ts:196


id

Get Signature

get id(): string

Returns

string

Defined in

packages/framework/store/src/store/doc/doc.ts:200


isEmpty

Get Signature

get isEmpty(): boolean

Returns

boolean

Defined in

packages/framework/store/src/store/doc/doc.ts:204


loaded

Get Signature

get loaded(): boolean

Returns

boolean

Defined in

packages/framework/store/src/store/doc/doc.ts:208


meta

Get Signature

get meta(): undefined | DocMeta

Returns

undefined | DocMeta

Defined in

packages/framework/store/src/store/doc/doc.ts:212


readonly

Get Signature

get readonly(): boolean

Returns

boolean

Defined in

packages/framework/store/src/store/doc/doc.ts:216


ready

Get Signature

get ready(): boolean

Returns

boolean

Defined in

packages/framework/store/src/store/doc/doc.ts:223


redo

Get Signature

get redo(): () => void

Returns

Function

Returns

void

Defined in

packages/framework/store/src/store/doc/doc.ts:227


resetHistory

Get Signature

get resetHistory(): () => void

Returns

Function

Returns

void

Defined in

packages/framework/store/src/store/doc/doc.ts:231


root

Get Signature

get root(): null | BlockModel<object, SignaledProps<object>>

Returns

null | BlockModel<object, SignaledProps<object>>

Defined in

packages/framework/store/src/store/doc/doc.ts:235


rootDoc

Get Signature

get rootDoc(): BlockSuiteDoc

Returns

BlockSuiteDoc

Defined in

packages/framework/store/src/store/doc/doc.ts:241


schema

Get Signature

get schema(): Schema

Returns

Schema

Defined in

packages/framework/store/src/store/doc/doc.ts:245


spaceDoc

Get Signature

get spaceDoc(): Doc

Returns

Doc

Defined in

packages/framework/store/src/store/doc/doc.ts:249


Text

Get Signature

get Text(): typeof Text

Returns

typeof Text

Defined in

packages/framework/store/src/store/doc/doc.ts:253


transact

Get Signature

get transact(): (fn, shouldTransact) => void

Returns

Function

If shouldTransact is false, the transaction will not be push to the history stack.

Parameters
fn

() => void

shouldTransact

boolean = ...

Returns

void

Defined in

packages/framework/store/src/store/doc/doc.ts:257


undo

Get Signature

get undo(): () => void

Returns

Function

Returns

void

Defined in

packages/framework/store/src/store/doc/doc.ts:261


withoutTransact

Get Signature

get withoutTransact(): (callback) => void

Returns

Function

Parameters
callback

() => void

Returns

void

Defined in

packages/framework/store/src/store/doc/doc.ts:265

Methods

addBlock()

Call Signature

addBlock<Key>(flavour, blockProps?, parent?, parentIndex?): string

Type Parameters

Key extends Flavour

Parameters
flavour

Key

blockProps?

Partial<BlockModels[Key] extends BlockModel<U, SignaledProps<U>> ? U : never>

parent?

null | string | BlockModel<object, SignaledProps<object>>

parentIndex?

number

Returns

string

Defined in

packages/framework/store/src/store/doc/doc.ts:408

Call Signature

addBlock(flavour, blockProps?, parent?, parentIndex?): string

Parameters
flavour

never

blockProps?

Partial<BlockSysProps & Record<string, unknown> & Omit<BlockProps, "flavour">>

parent?

null | string | BlockModel<object, SignaledProps<object>>

parentIndex?

number

Returns

string

Defined in

packages/framework/store/src/store/doc/doc.ts:415


addBlocks()

addBlocks(blocks, parent?, parentIndex?): string[]

Parameters

blocks

object[]

parent?

null | string | BlockModel<object, SignaledProps<object>>

parentIndex?

number

Returns

string[]

Defined in

packages/framework/store/src/store/doc/doc.ts:450


addSiblingBlocks()

addSiblingBlocks(targetModel, props, place): string[]

Parameters

targetModel

BlockModel<object, SignaledProps<object>>

props

Partial<BlockProps>[]

place

"after" | "before"

Returns

string[]

Defined in

packages/framework/store/src/store/doc/doc.ts:473


deleteBlock()

deleteBlock(model, options): void

Parameters

model

DraftModel

options
bringChildrenTo

BlockModel<object, SignaledProps<object>>

deleteChildren

boolean

Returns

void

Defined in

packages/framework/store/src/store/doc/doc.ts:510


dispose()

dispose(): void

Returns

void

Defined in

packages/framework/store/src/store/doc/doc.ts:541


getBlock()

getBlock(id): undefined | Block

Parameters

id

string

Returns

undefined | Block

Defined in

packages/framework/store/src/store/doc/doc.ts:549


getBlock$()

getBlock$(id): undefined | Block

Parameters

id

string

Returns

undefined | Block

Defined in

packages/framework/store/src/store/doc/doc.ts:553


getBlockByFlavour()

getBlockByFlavour(blockFlavour): BlockModel<object, SignaledProps<object>>[]

Parameters

blockFlavour

string | string[]

Returns

BlockModel<object, SignaledProps<object>>[]

Deprecated

Use getBlocksByFlavour instead.

Defined in

packages/framework/store/src/store/doc/doc.ts:561


getBlockById()

getBlockById<Model>(id): null | Model

Type Parameters

Model extends BlockModel<object, SignaledProps<object>> = BlockModel<object, SignaledProps<object>>

Parameters

id

string

Returns

null | Model

Deprecated

Use getBlock instead.

Defined in

packages/framework/store/src/store/doc/doc.ts:569


getBlocks()

getBlocks(): BlockModel<object, SignaledProps<object>>[]

Returns

BlockModel<object, SignaledProps<object>>[]

Defined in

packages/framework/store/src/store/doc/doc.ts:575


getBlocksByFlavour()

getBlocksByFlavour(blockFlavour): Block[]

Parameters

blockFlavour

string | string[]

Returns

Block[]

Defined in

packages/framework/store/src/store/doc/doc.ts:579


getNext()

getNext(block): null | BlockModel<object, SignaledProps<object>>

Parameters

block

string | BlockModel<object, SignaledProps<object>>

Returns

null | BlockModel<object, SignaledProps<object>>

Defined in

packages/framework/store/src/store/doc/doc.ts:588


getNexts()

getNexts(block): BlockModel<object, SignaledProps<object>>[]

Parameters

block

string | BlockModel<object, SignaledProps<object>>

Returns

BlockModel<object, SignaledProps<object>>[]

Defined in

packages/framework/store/src/store/doc/doc.ts:595


getParent()

getParent(target): null | BlockModel<object, SignaledProps<object>>

Parameters

target

string | BlockModel<object, SignaledProps<object>>

Returns

null | BlockModel<object, SignaledProps<object>>

Defined in

packages/framework/store/src/store/doc/doc.ts:603


getPrev()

getPrev(block): null | BlockModel<object, SignaledProps<object>>

Parameters

block

string | BlockModel<object, SignaledProps<object>>

Returns

null | BlockModel<object, SignaledProps<object>>

Defined in

packages/framework/store/src/store/doc/doc.ts:614


getPrevs()

getPrevs(block): BlockModel<object, SignaledProps<object>>[]

Parameters

block

string | BlockModel<object, SignaledProps<object>>

Returns

BlockModel<object, SignaledProps<object>>[]

Defined in

packages/framework/store/src/store/doc/doc.ts:621


getSchemaByFlavour()

getSchemaByFlavour(flavour): undefined | { model: { children: string[]; flavour: string; parent: string[]; props: (...args) => Record<string, any>; role: "root" | "hub" | "content"; toModel: (...args) => BlockModel<object, SignaledProps<object>>; }; transformer: (...args) => BaseBlockTransformer<object>; version: number; }

Parameters

flavour

Flavour

Returns

undefined | { model: { children: string[]; flavour: string; parent: string[]; props: (...args) => Record<string, any>; role: "root" | "hub" | "content"; toModel: (...args) => BlockModel<object, SignaledProps<object>>; }; transformer: (...args) => BaseBlockTransformer<object>; version: number; }

Defined in

packages/framework/store/src/store/doc/doc.ts:629


hasBlock()

hasBlock(id): boolean

Parameters

id

string

Returns

boolean

Defined in

packages/framework/store/src/store/doc/doc.ts:633


hasBlockById()

hasBlockById(id): boolean

Parameters

id

string

Returns

boolean

Deprecated

Use hasBlock instead.

Defined in

packages/framework/store/src/store/doc/doc.ts:641


load()

load(initFn?): Doc

Parameters

initFn?

() => void

Returns

Doc

Defined in

packages/framework/store/src/store/doc/doc.ts:645


moveBlocks()

moveBlocks(blocksToMove, newParent, targetSibling, shouldInsertBeforeSibling): void

Parameters

blocksToMove

BlockModel<object, SignaledProps<object>>[]

newParent

BlockModel<object, SignaledProps<object>>

targetSibling

null | BlockModel<object, SignaledProps<object>>

shouldInsertBeforeSibling

boolean = true

Returns

void

Defined in

packages/framework/store/src/store/doc/doc.ts:651