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:268

Properties

_blockCollection

protected readonly _blockCollection: BlockCollection

Defined in

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


_blocks

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

Defined in

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


_crud

protected readonly _crud: DocCRUD

Defined in

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


_disposeBlockUpdated

protected readonly _disposeBlockUpdated: Disposable

Defined in

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


_query

protected readonly _query: Query

Defined in

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


_readonly?

protected readonly optional _readonly: boolean

Defined in

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


_schema

protected readonly _schema: Schema

Defined in

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


slots

readonly slots: object & object

Type declaration

historyUpdated

historyUpdated: Slot<void>

yBlockUpdated

yBlockUpdated: Slot<object | object>

Type declaration

blockUpdated

blockUpdated: Slot<object | object | object>

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:44


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

Returns

void

Defined in

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

Accessors

awarenessStore

get awarenessStore(): AwarenessStore<BlockSuiteFlags>

Returns

AwarenessStore<BlockSuiteFlags>

Defined in

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


awarenessSync

get awarenessSync(): AwarenessEngine

Returns

AwarenessEngine

Defined in

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


blobSync

get blobSync(): BlobEngine

Returns

BlobEngine

Defined in

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


blockCollection

get blockCollection(): BlockCollection

Returns

BlockCollection

Defined in

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


blocks

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

Returns

Signal<Record<string, Block>>

Defined in

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


blockSize

get blockSize(): number

Returns

number

Defined in

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


canRedo

get canRedo(): boolean

Returns

boolean

Defined in

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


canUndo

get canUndo(): boolean

Returns

boolean

Defined in

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


captureSync

get captureSync(): () => void

Returns

Function

Capture current operations to undo stack synchronously.

Returns

void

Defined in

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


clear

get clear(): () => void

Returns

Function

Returns

void

Defined in

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


collection

get collection(): DocCollection

Returns

DocCollection

Defined in

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


docSync

get docSync(): DocEngine

Returns

DocEngine

Defined in

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


generateBlockId

get generateBlockId(): () => string

Returns

Function

Returns

string

Defined in

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


history

get history(): UndoManager

Returns

UndoManager

Defined in

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


id

get id(): string

Returns

string

Defined in

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


isEmpty

get isEmpty(): boolean

Returns

boolean

Defined in

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


loaded

get loaded(): boolean

Returns

boolean

Defined in

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


meta

get meta(): undefined | DocMeta

Returns

undefined | DocMeta

Defined in

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


readonly

get readonly(): boolean

Returns

boolean

Defined in

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


ready

get ready(): boolean

Returns

boolean

Defined in

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


redo

get redo(): () => void

Returns

Function

Returns

void

Defined in

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


resetHistory

get resetHistory(): () => void

Returns

Function

Returns

void

Defined in

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


root

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

Returns

null | BlockModel<object, SignaledProps<object>>

Defined in

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


rootDoc

get rootDoc(): BlockSuiteDoc

Returns

BlockSuiteDoc

Defined in

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


schema

get schema(): Schema

Returns

Schema

Defined in

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


spaceDoc

get spaceDoc(): Doc

Returns

Doc

Defined in

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


Text

get Text(): typeof Text

Returns

typeof Text

Defined in

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


transact

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

Returns

Function

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

Parameters

fn

shouldTransact: boolean = ...

Returns

void

Defined in

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


undo

get undo(): () => void

Returns

Function

Returns

void

Defined in

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


withoutTransact

get withoutTransact(): (callback) => void

Returns

Function

Parameters

callback

Returns

void

Defined in

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

Methods

addBlock()

addBlock(flavour, blockProps, parent, parentIndex)

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:407

addBlock(flavour, blockProps, parent, parentIndex)

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:414


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:449


addSiblingBlocks()

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

Parameters

targetModel: BlockModel<object, SignaledProps<object>>

props: Partial<BlockProps>[]

place: "after" | "before" = 'after'

Returns

string[]

Defined in

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


deleteBlock()

deleteBlock(model, options): void

Parameters

model: BlockModel<object, SignaledProps<object>>

options = ...

options.bringChildrenTo?: BlockModel<object, SignaledProps<object>>

options.deleteChildren?: boolean

Returns

void

Defined in

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


dispose()

dispose(): void

Returns

void

Defined in

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


getBlock()

getBlock(id): undefined | Block

Parameters

id: string

Returns

undefined | Block

Defined in

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


getBlock$()

getBlock$(id): undefined | Block

Parameters

id: string

Returns

undefined | Block

Defined in

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


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:560


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:568


getBlocks()

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

Returns

BlockModel<object, SignaledProps<object>>[]

Defined in

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


getBlocksByFlavour()

getBlocksByFlavour(blockFlavour): Block[]

Parameters

blockFlavour: string | string[]

Returns

Block[]

Defined in

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


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:587


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:594


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:602


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:613


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:620


getSchemaByFlavour()

getSchemaByFlavour(flavour): undefined | object

Parameters

flavour: Flavour

Returns

undefined | object

Defined in

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


hasBlock()

hasBlock(id): boolean

Parameters

id: string

Returns

boolean

Defined in

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


hasBlockById()

hasBlockById(id): boolean

Parameters

id: string

Returns

boolean

Deprecated

Use hasBlock instead.

Defined in

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


load()

load(initFn?): Doc

Parameters

initFn?

Returns

Doc

Defined in

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


moveBlocks()

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

Parameters

blocksToMove: BlockModel<object, SignaledProps<object>>[]

newParent: BlockModel<object, SignaledProps<object>>

targetSibling: null | BlockModel<object, SignaledProps<object>> = null

shouldInsertBeforeSibling: boolean = true

Returns

void

Defined in

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