Skip to content

BlockSuite API Documentation / @blocksuite/store

@blocksuite/store ​

Extension ​

abstract Extension ​

Understanding Extensions ​

Extensions provide a way to extend the functionality of a system using dependency injection. They allow you to register services, implementations, and factories in the DI container, which can then be retrieved and used by different parts of the application.

Extensions are particularly useful for:

  • Registering different implementations for different types
  • Creating pluggable architecture where components can be added or removed
  • Managing dependencies between different parts of the application

Usage Example: Fruit Processing System ​

Let's consider a fruit processing system where different types of fruits need different processing methods. We'll show how to implement this using extensions.

Step 1: Define the interfaces ​

ts
interface FruitProcessor {
  process(fruit: Fruit): void;
}

interface Fruit {
  type: string;
  // other properties
}

Step 2: Create a service identifier ​

ts
import { createIdentifier } from '@blocksuite/global/di';

const FruitProcessorProvider = createIdentifier<FruitProcessor>('fruit-processor-provider');

Step 3: Create implementations ​

ts
class AppleProcessor implements FruitProcessor {
  process(fruit: Fruit): void {
    console.log('Slicing apple');
    // Apple-specific processing
  }
}

class BananaProcessor implements FruitProcessor {
  process(fruit: Fruit): void {
    console.log('Peeling banana');
    // Banana-specific processing
  }
}

Step 4: Create an extension factory ​

ts
const FruitProcessorExtension = (
  fruitType: string,
  implementation: new () => FruitProcessor
): ExtensionType => {
  return {
    setup: di => {
      di.addImpl(FruitProcessorProvider(fruitType), implementation);
    }
  };
};

Step 5: Create concrete extensions ​

ts
export const AppleProcessorExtension = FruitProcessorExtension('apple', AppleProcessor);
export const BananaProcessorExtension = FruitProcessorExtension('banana', BananaProcessor);

Step 6: Use the extensions ​

ts
import { Container } from '@blocksuite/global/di';

class FruitProcessingSystem {
  provider: ServiceProvider;

  constructor(extensions: ExtensionType[]) {
    const container = new Container();

    // Set up all extensions
    extensions.forEach(ext => ext.setup(container));

    // Create a provider from the container
    this.provider = container.provider();
  }

  processFruit(fruit: Fruit) {
    // Get the appropriate processor based on fruit type
    const processor = this.provider.get(FruitProcessorProvider(fruit.type));

    // Process the fruit
    processor.process(fruit);
  }
}

// Initialize the system with extensions
const system = new FruitProcessingSystem([
  AppleProcessorExtension,
  BananaProcessorExtension
]);

// Use the system
system.processFruit({ type: 'apple' });  // Output: Slicing apple
system.processFruit({ type: 'banana' }); // Output: Peeling banana

Note: We deliberately used a non-block specific example here. In BlockSuite, the extension pattern can be applied to any entity that can be configured by third parties, not just blocks. This includes different tools in the whiteboard, different column types in database blocks, and many other extensible components. The pattern remains the same regardless of what you're extending.

Extended by ​

Constructors ​

Constructor ​

new Extension(): Extension

Returns ​

Extension

Methods ​

setup() ​

static setup(_di): void

Parameters ​
_di ​

Container

Returns ​

void


HistoryExtension ​

Store extensions are used to extend the store. They should be registered to the store. And they should be able to run in a none-dom environment.

Extends ​

Constructors ​

Constructor ​

new HistoryExtension(store): HistoryExtension

Parameters ​
store ​

Store

Returns ​

HistoryExtension

Overrides ​

StoreExtension.constructor

Properties ​

onUpdated ​

readonly onUpdated: Subject<void>

key ​

readonly static key: "history" = 'history'

The key of the store extension. You must override this property with a unique string.

Overrides ​

StoreExtension.key

Accessors ​

canRedo ​
Get Signature ​

get canRedo(): boolean

Returns ​

boolean

canRedo$ ​
Get Signature ​

get canRedo$(): Signal<boolean>

Returns ​

Signal<boolean>

canUndo ​
Get Signature ​

get canUndo(): boolean

Returns ​

boolean

canUndo$ ​
Get Signature ​

get canUndo$(): Signal<boolean>

Returns ​

Signal<boolean>

undoManager ​
Get Signature ​

get undoManager(): UndoManager

Returns ​

UndoManager

Methods ​

disposed() ​

disposed(): void

Lifecycle hook when the yjs document is disposed.

Returns ​

void

Overrides ​

StoreExtension.disposed

loaded() ​

loaded(): void

Lifecycle hook when the yjs document is loaded.

Returns ​

void

Overrides ​

StoreExtension.loaded


StoreExtension ​

Store extensions are used to extend the store. They should be registered to the store. And they should be able to run in a none-dom environment.

Extends ​

Extended by ​

Constructors ​

Constructor ​

new StoreExtension(store): StoreExtension

Parameters ​
store ​

Store

Returns ​

StoreExtension

Overrides ​

Extension.constructor

Properties ​

store ​

readonly store: Store

[storeExtensionSymbol] ​

readonly static [storeExtensionSymbol]: true = true

key ​

readonly static key: string

The key of the store extension. You must override this property with a unique string.

Methods ​

disposed() ​

disposed(): void

Lifecycle hook when the yjs document is disposed.

Returns ​

void

loaded() ​

loaded(): void

Lifecycle hook when the yjs document is loaded.

Returns ​

void

setup() ​

static setup(di): void

Parameters ​
di ​

Container

Returns ​

void

Overrides ​

Extension.setup


StoreSelectionExtension ​

Store extensions are used to extend the store. They should be registered to the store. And they should be able to run in a none-dom environment.

Extends ​

Constructors ​

Properties ​

slots ​

slots: object

changed ​

changed: Subject<BaseSelection[]>

remoteChanged ​

remoteChanged: Subject<Map<number, BaseSelection[]>>

key ​

readonly static key: "selection" = 'selection'

The key of the store extension. You must override this property with a unique string.

Overrides ​

StoreExtension.key

Accessors ​

remoteSelections ​
Get Signature ​

get remoteSelections(): Map<number, BaseSelection[]>

Returns ​

Map<number, BaseSelection[]>

value ​
Get Signature ​

get value(): BaseSelection[]

Returns ​

BaseSelection[]

Methods ​

clear() ​

clear(types?): void

Parameters ​
types? ​

string[]

Returns ​

void

clearRemote() ​

clearRemote(): void

Returns ​

void

create() ​

create<T>(Type, ...args): InstanceType<T>

Type Parameters ​
T ​

T extends SelectionConstructor<BaseSelection>

Parameters ​
Type ​

T

args ​

...ConstructorParameters<T>

Returns ​

InstanceType<T>

disposed() ​

disposed(): void

Lifecycle hook when the yjs document is disposed.

Returns ​

void

Overrides ​

StoreExtension.disposed

filter() ​

filter<T>(type): InstanceType<T>[]

Type Parameters ​
T ​

T extends SelectionConstructor<BaseSelection>

Parameters ​
type ​

T

Returns ​

InstanceType<T>[]

filter$() ​

filter$<T>(type): ReadonlySignal<InstanceType<T>[]>

Type Parameters ​
T ​

T extends SelectionConstructor<BaseSelection>

Parameters ​
type ​

T

Returns ​

ReadonlySignal<InstanceType<T>[]>

find() ​

find<T>(type): InstanceType<T> | undefined

Type Parameters ​
T ​

T extends SelectionConstructor<BaseSelection>

Parameters ​
type ​

T

Returns ​

InstanceType<T> | undefined

find$() ​

find$<T>(type): ReadonlySignal<InstanceType<T> | undefined>

Type Parameters ​
T ​

T extends SelectionConstructor<BaseSelection>

Parameters ​
type ​

T

Returns ​

ReadonlySignal<InstanceType<T> | undefined>

fromJSON() ​

fromJSON(json): void

Parameters ​
json ​

Record<string, unknown>[]

Returns ​

void

getGroup() ​

getGroup(group): BaseSelection[]

Parameters ​
group ​

string

Returns ​

BaseSelection[]

loaded() ​

loaded(): void

Lifecycle hook when the yjs document is loaded.

Returns ​

void

Overrides ​

StoreExtension.loaded

set() ​

set(selections): void

Parameters ​
selections ​

BaseSelection[]

Returns ​

void

setGroup() ​

setGroup(group, selections): void

Parameters ​
group ​

string

selections ​

BaseSelection[]

Returns ​

void

update() ​

update(fn): void

Parameters ​
fn ​

(currentSelections) => BaseSelection[]

Returns ​

void

Other ​

AssetsManager ​

Constructors ​

Constructor ​

new AssetsManager(options): AssetsManager

Parameters ​
options ​

AssetsManagerConfig

Returns ​

AssetsManager

Properties ​

uploadingAssetsMap ​

readonly uploadingAssetsMap: Map<string, { abortController?: AbortController; blob: Blob; mapInto: (blobId) => Partial<BlockProps>; }>

Methods ​

cleanup() ​

cleanup(): void

Returns ​

void

getAssets() ​

getAssets(): Map<string, Blob>

Returns ​

Map<string, Blob>

getPathBlobIdMap() ​

getPathBlobIdMap(): Map<string, string>

Returns ​

Map<string, string>

isEmpty() ​

isEmpty(): boolean

Returns ​

boolean

readFromBlob() ​

readFromBlob(blobId): Promise<void>

Parameters ​
blobId ​

string

Returns ​

Promise<void>

writeToBlob() ​

writeToBlob(blobId): Promise<void>

Parameters ​
blobId ​

string

Returns ​

Promise<void>


ASTWalker ​

Type Parameters ​

ONode ​

ONode extends object

TNode ​

TNode extends object | never

Constructors ​

Constructor ​

new ASTWalker<ONode, TNode>(): ASTWalker<ONode, TNode>

Returns ​

ASTWalker<ONode, TNode>

Methods ​

setEnter() ​

setEnter(fn): void

Parameters ​
fn ​

WalkerFn<ONode, TNode>

Returns ​

void

setLeave() ​

setLeave(fn): void

Parameters ​
fn ​

WalkerFn<ONode, TNode>

Returns ​

void

setONodeTypeGuard() ​

setONodeTypeGuard(fn): void

Parameters ​
fn ​

(node) => node is ONode

Returns ​

void

walk() ​

walk(oNode, tNode): Promise<TNode>

Parameters ​
oNode ​

ONode

tNode ​

TNode

Returns ​

Promise<TNode>

walkONode() ​

walkONode(oNode): Promise<void>

Parameters ​
oNode ​

ONode

Returns ​

Promise<void>


ASTWalkerContext ​

Type Parameters ​

TNode ​

TNode extends object

Constructors ​

Constructor ​

new ASTWalkerContext<TNode>(): ASTWalkerContext<TNode>

Returns ​

ASTWalkerContext<TNode>

Properties ​

_skip ​

_skip: boolean = false

_skipChildrenNum ​

_skipChildrenNum: number = 0

Accessors ​

stack ​
Get Signature ​

get stack(): object[]

Returns ​

object[]

Methods ​

cleanGlobalContextStack() ​

cleanGlobalContextStack(key): void

Parameters ​
key ​

string

Returns ​

void

closeNode() ​

closeNode(): ASTWalkerContext<TNode>

Returns ​

ASTWalkerContext<TNode>

currentNode() ​

currentNode(): TNode

Returns ​

TNode

getGlobalContext() ​

getGlobalContext(key): unknown

Parameters ​
key ​

string

Returns ​

unknown

getGlobalContextStack() ​

getGlobalContextStack<StackElement>(key): StackElement[]

Type Parameters ​
StackElement ​

StackElement

Parameters ​
key ​

string

Returns ​

StackElement[]

getNodeContext() ​

getNodeContext(key): unknown

Parameters ​
key ​

string

Returns ​

unknown

getPreviousNodeContext() ​

getPreviousNodeContext(key): unknown

Parameters ​
key ​

string

Returns ​

unknown

openNode() ​

openNode(node, parentProp?): ASTWalkerContext<TNode>

Parameters ​
node ​

TNode

parentProp? ​

Keyof<TNode>

Returns ​

ASTWalkerContext<TNode>

previousNode() ​

previousNode(): TNode

Returns ​

TNode

pushGlobalContextStack() ​

pushGlobalContextStack<StackElement>(key, value): void

Type Parameters ​
StackElement ​

StackElement

Parameters ​
key ​

string

value ​

StackElement

Returns ​

void

setDefaultProp() ​

setDefaultProp(parentProp): void

Parameters ​
parentProp ​

Keyof<TNode>

Returns ​

void

setGlobalContext() ​

setGlobalContext(key, value): ASTWalkerContext<TNode>

Parameters ​
key ​

string

value ​

unknown

Returns ​

ASTWalkerContext<TNode>

setGlobalContextStack() ​

setGlobalContextStack<StackElement>(key, value): void

Type Parameters ​
StackElement ​

StackElement

Parameters ​
key ​

string

value ​

StackElement[]

Returns ​

void

setNodeContext() ​

setNodeContext(key, value): ASTWalkerContext<TNode>

Parameters ​
key ​

string

value ​

unknown

Returns ​

ASTWalkerContext<TNode>

skipAllChildren() ​

skipAllChildren(): void

Returns ​

void

skipChildren() ​

skipChildren(num?): void

Parameters ​
num? ​

number = 1

Returns ​

void


AwarenessStore ​

Constructors ​

Constructor ​

new AwarenessStore(awareness): AwarenessStore

Parameters ​
awareness ​

Awareness

Returns ​

AwarenessStore

Properties ​

awareness ​

readonly awareness: Awareness

Methods ​

destroy() ​

destroy(): void

Returns ​

void

getLocalSelection() ​

getLocalSelection(selectionManagerId): readonly Record<string, unknown>[]

Parameters ​
selectionManagerId ​

string

Returns ​

readonly Record<string, unknown>[]

getLocalState() ​

getLocalState(): RawAwarenessState

Returns ​

RawAwarenessState

getStates() ​

getStates(): Map<number, RawAwarenessState>

Returns ​

Map<number, RawAwarenessState>

setLocalSelection() ​

setLocalSelection(selectionManagerId, selection): void

Parameters ​
selectionManagerId ​

string

selection ​

UserSelection

Returns ​

void

setLocalState() ​

setLocalState(state): void

Parameters ​
state ​

RawAwarenessState

Returns ​

void

setLocalStateField() ​

setLocalStateField<Field>(field, value): void

Type Parameters ​
Field ​

Field extends keyof RawAwarenessState

Parameters ​
field ​

Field

value ​

RawAwarenessState[Field]

Returns ​

void


abstract BaseAdapter ​

Type Parameters ​

AdapterTarget ​

AdapterTarget = unknown

Constructors ​

Constructor ​

new BaseAdapter<AdapterTarget>(job, provider): BaseAdapter<AdapterTarget>

Parameters ​
job ​

Transformer

provider ​

ServiceProvider

Returns ​

BaseAdapter<AdapterTarget>

Properties ​

job ​

job: Transformer

provider ​

readonly provider: ServiceProvider

Accessors ​

configs ​
Get Signature ​

get configs(): Map<string, string>

Returns ​

Map<string, string>

Methods ​

fromBlock() ​

fromBlock(model): Promise<FromBlockSnapshotResult<AdapterTarget> | undefined>

Parameters ​
model ​

BlockModel<object> | DraftModel

Returns ​

Promise<FromBlockSnapshotResult<AdapterTarget> | undefined>

fromBlockSnapshot() ​

abstract fromBlockSnapshot(payload): FromBlockSnapshotResult<AdapterTarget> | Promise<FromBlockSnapshotResult<AdapterTarget>>

Parameters ​
payload ​

FromBlockSnapshotPayload

Returns ​

FromBlockSnapshotResult<AdapterTarget> | Promise<FromBlockSnapshotResult<AdapterTarget>>

fromDoc() ​

fromDoc(doc): Promise<FromDocSnapshotResult<AdapterTarget> | undefined>

Parameters ​
doc ​

Store

Returns ​

Promise<FromDocSnapshotResult<AdapterTarget> | undefined>

fromDocSnapshot() ​

abstract fromDocSnapshot(payload): FromDocSnapshotResult<AdapterTarget> | Promise<FromDocSnapshotResult<AdapterTarget>>

Parameters ​
payload ​

FromDocSnapshotPayload

Returns ​

FromDocSnapshotResult<AdapterTarget> | Promise<FromDocSnapshotResult<AdapterTarget>>

fromSlice() ​

fromSlice(slice): Promise<FromSliceSnapshotResult<AdapterTarget> | undefined>

Parameters ​
slice ​

Slice

Returns ​

Promise<FromSliceSnapshotResult<AdapterTarget> | undefined>

fromSliceSnapshot() ​

abstract fromSliceSnapshot(payload): FromSliceSnapshotResult<AdapterTarget> | Promise<FromSliceSnapshotResult<AdapterTarget>>

Parameters ​
payload ​

FromSliceSnapshotPayload

Returns ​

FromSliceSnapshotResult<AdapterTarget> | Promise<FromSliceSnapshotResult<AdapterTarget>>

toBlock() ​

toBlock(payload, doc, parent?, index?): Promise<BlockModel<object> | undefined>

Parameters ​
payload ​

ToBlockSnapshotPayload<AdapterTarget>

doc ​

Store

parent? ​

string

index? ​

number

Returns ​

Promise<BlockModel<object> | undefined>

toBlockSnapshot() ​

abstract toBlockSnapshot(payload): BlockSnapshot | Promise<BlockSnapshot>

Parameters ​
payload ​

ToBlockSnapshotPayload<AdapterTarget>

Returns ​

BlockSnapshot | Promise<BlockSnapshot>

toDoc() ​

toDoc(payload): Promise<Store | undefined>

Parameters ​
payload ​

ToDocSnapshotPayload<AdapterTarget>

Returns ​

Promise<Store | undefined>

toDocSnapshot() ​

abstract toDocSnapshot(payload): DocSnapshot | Promise<DocSnapshot>

Parameters ​
payload ​

ToDocSnapshotPayload<AdapterTarget>

Returns ​

DocSnapshot | Promise<DocSnapshot>

toSlice() ​

toSlice(payload, doc, parent?, index?): Promise<Slice | undefined>

Parameters ​
payload ​

ToSliceSnapshotPayload<AdapterTarget>

doc ​

Store

parent? ​

string

index? ​

number

Returns ​

Promise<Slice | undefined>

toSliceSnapshot() ​

abstract toSliceSnapshot(payload): SliceSnapshot | Promise<SliceSnapshot | null> | null

Parameters ​
payload ​

ToSliceSnapshotPayload<AdapterTarget>

Returns ​

SliceSnapshot | Promise<SliceSnapshot | null> | null


BaseBlockTransformer ​

Extended by ​

Type Parameters ​

Props ​

Props extends object = object

Constructors ​

Constructor ​

new BaseBlockTransformer<Props>(transformerConfigs): BaseBlockTransformer<Props>

Parameters ​
transformerConfigs ​

Map<string, unknown>

Returns ​

BaseBlockTransformer<Props>

Properties ​

_internal ​

protected _internal: InternalPrimitives = internalPrimitives

transformerConfigs ​

readonly transformerConfigs: Map<string, unknown>

Methods ​

_propsFromSnapshot() ​

protected _propsFromSnapshot(propsJson): Props

Parameters ​
propsJson ​

Record<string, unknown>

Returns ​

Props

_propsToSnapshot() ​

protected _propsToSnapshot(model): object

Parameters ​
model ​

BlockModel<object> | DraftModel

Returns ​

object

fromSnapshot() ​

fromSnapshot(__namedParameters): SnapshotNode<Props> | Promise<SnapshotNode<Props>>

Parameters ​
__namedParameters ​

FromSnapshotPayload

Returns ​

SnapshotNode<Props> | Promise<SnapshotNode<Props>>

toSnapshot() ​

toSnapshot(__namedParameters): BlockSnapshotLeaf

Parameters ​
__namedParameters ​

ToSnapshotPayload<Props>

Returns ​

BlockSnapshotLeaf


abstract BaseSelection ​

Extended by ​

Constructors ​

Constructor ​

new BaseSelection(__namedParameters): BaseSelection

Parameters ​
__namedParameters ​

BaseSelectionOptions

Returns ​

BaseSelection

Properties ​

blockId ​

readonly blockId: string

group ​

readonly static group: string

recoverable ​

readonly static recoverable: boolean = false

type ​

readonly static type: string

Accessors ​

group ​
Get Signature ​

get group(): string

Returns ​

string

type ​
Get Signature ​

get type(): string

Returns ​

string

Methods ​

equals() ​

abstract equals(other): boolean

Parameters ​
other ​

BaseSelection

Returns ​

boolean

is() ​

is<T>(type): this is T extends SelectionConstructor<U> ? U : never

Type Parameters ​
T ​

T extends SelectionConstructor<BaseSelection>

Parameters ​
type ​

T

Returns ​

this is T extends SelectionConstructor<U> ? U : never

toJSON() ​

abstract toJSON(): Record<string, unknown>

Returns ​

Record<string, unknown>

fromJSON() ​

static fromJSON(_): BaseSelection

Parameters ​
_ ​

Record<string, unknown>

Returns ​

BaseSelection


Block ​

Constructors ​

Constructor ​

new Block(schema, yBlock, doc?, options?): Block

Parameters ​
schema ​

Schema

yBlock ​

YBlock

doc? ​

Store

options? ​

BlockOptions = {}

Returns ​

Block

Properties ​

blockViewType ​

blockViewType: BlockViewType = 'display'

doc? ​

readonly optional doc?: Store

options ​

readonly options: BlockOptions = {}

schema ​

readonly schema: Schema

yBlock ​

readonly yBlock: YBlock

Accessors ​

flavour ​
Get Signature ​

get flavour(): string

Returns ​

string

id ​
Get Signature ​

get id(): string

Returns ​

string

model ​
Get Signature ​

get model(): BlockModel<object>

Returns ​

BlockModel<object>

pop ​
Get Signature ​

get pop(): ((prop) => void) | ((prop) => void)

Returns ​

((prop) => void) | ((prop) => void)

stash ​
Get Signature ​

get stash(): ((prop) => void) | ((prop) => void)

Returns ​

((prop) => void) | ((prop) => void)

version ​
Get Signature ​

get version(): number

Returns ​

number


BlockModel ​

Extended by ​

Type Parameters ​

Props ​

Props extends object = object

Constructors ​

Constructor ​

new BlockModel<Props>(): BlockModel<Props>

Returns ​

BlockModel<Props>

Properties ​

_props ​

_props: SignaledProps<Props>

[modelLabel] ​

[modelLabel]: Props

childMap ​

childMap: ReadonlySignal<Map<string, number>>

created ​

created: Subject<void>

deleted ​

deleted: Subject<void>

id ​

id: string

keys ​

keys: string[]

pop ​

pop: (prop) => void

Parameters ​
prop ​

keyof Props & string

Returns ​

void

propsUpdated ​

propsUpdated: Subject<{ key: string; }>

schema ​

schema: object

model ​

model: object

model.children? ​

optional children?: string[] = ContentSchema

model.flavour ​

flavour: string = FlavourSchema

model.isFlatData? ​

optional isFlatData?: boolean

model.parent? ​

optional parent?: string[] = ParentSchema

model.props? ​

optional props?: (...args) => Record<string, any>

Parameters ​
args ​

...[InternalPrimitives, ...unknown[]]

Returns ​

Record<string, any>

model.role ​

role: string = RoleSchema

model.toModel? ​

optional toModel?: (...args) => BlockModel<object>

Parameters ​
args ​

...unknown[]

Returns ​

BlockModel<object>

transformer? ​

optional transformer?: (...args) => BaseBlockTransformer<object>

Parameters ​
args ​

...[Map<string, unknown>, ...unknown[]]

Returns ​

BaseBlockTransformer<object>

version ​

version: number

stash ​

stash: (prop) => void

Parameters ​
prop ​

keyof Props & string

Returns ​

void

yBlock ​

yBlock: YBlock

Accessors ​

children ​
Get Signature ​

get children(): BlockModel<object>[]

Returns ​

BlockModel<object>[]

flavour ​
Get Signature ​

get flavour(): string

Returns ​

string

parent ​
Get Signature ​

get parent(): BlockModel<object> | null

Returns ​

BlockModel<object> | null

props ​
Get Signature ​

get props(): SignaledProps<Props>

Returns ​

SignaledProps<Props>

role ​
Get Signature ​

get role(): string

Returns ​

string

store ​
Get Signature ​

get store(): Store

Returns ​

Store

Set Signature ​

set store(doc): void

Parameters ​
doc ​

Store

Returns ​

void

text ​
Get Signature ​

get text(): Text<{ bold?: true | null; code?: true | null; italic?: true | null; link?: string | null; strike?: true | null; underline?: true | null; }> | undefined

Returns ​

Text<{ bold?: true | null; code?: true | null; italic?: true | null; link?: string | null; strike?: true | null; underline?: true | null; }> | undefined

Set Signature ​

set text(text): void

Parameters ​
text ​

Text

Returns ​

void

version ​
Get Signature ​

get version(): number

Returns ​

number

Methods ​

[dispose]() ​

[dispose](): void

Returns ​

void

dispose() ​

dispose(): void

Returns ​

void

firstChild() ​

firstChild(): BlockModel<object> | null

Returns ​

BlockModel<object> | null

isEmpty() ​

isEmpty(): boolean

Returns ​

boolean

lastChild() ​

lastChild(): BlockModel<object> | null

Returns ​

BlockModel<object> | null


ReactiveFlatYMap ​

Extends ​

  • BaseReactiveYData<UnRecord, YMap<unknown>>

Constructors ​

Constructor ​

new ReactiveFlatYMap(_ySource, _onDispose, _onChange?, defaultProps?): ReactiveFlatYMap

Parameters ​
_ySource ​

YMap<unknown>

_onDispose ​

Subject<void>

_onChange? ​

OnChange

defaultProps? ​

Record<string, unknown>

Returns ​

ReactiveFlatYMap

Overrides ​

BaseReactiveYData< UnRecord, YMap<unknown> >.constructor

Properties ​

_options? ​

protected readonly optional _options?: ProxyOptions<UnRecord>

Overrides ​

BaseReactiveYData._options

_proxy ​

protected readonly _proxy: UnRecord

Overrides ​

BaseReactiveYData._proxy

_source ​

protected readonly _source: UnRecord

Overrides ​

BaseReactiveYData._source

Accessors ​

Methods ​

pop() ​

pop(prop): void

Parameters ​
prop ​

string

Returns ​

void

Overrides ​

BaseReactiveYData.pop

stash() ​

stash(prop): void

Parameters ​
prop ​

string

Returns ​

void

Overrides ​

BaseReactiveYData.stash


ReactiveYArray ​

Extends ​

  • BaseReactiveYData<unknown[], YArray<unknown>>

Constructors ​

Constructor ​

new ReactiveYArray(_source, _ySource, _options): ReactiveYArray

Parameters ​
_source ​

unknown[]

_ySource ​

YArray<unknown>

_options ​

ProxyOptions<unknown[]>

Returns ​

ReactiveYArray

Overrides ​

BaseReactiveYData< unknown[], YArray<unknown> >.constructor

Properties ​

_proxy ​

protected readonly _proxy: unknown[]

Overrides ​

BaseReactiveYData._proxy

Accessors ​

Methods ​

_getProxy() ​

protected _getProxy(): unknown[]

Returns ​

unknown[]

pop() ​

pop(prop): void

Parameters ​
prop ​

number

Returns ​

void

Overrides ​

BaseReactiveYData.pop

stash() ​

stash(prop): void

Parameters ​
prop ​

number

Returns ​

void

Overrides ​

BaseReactiveYData.stash


ReactiveYMap ​

Extends ​

  • BaseReactiveYData<UnRecord, YMap<unknown>>

Constructors ​

Constructor ​

new ReactiveYMap(_source, _ySource, _options): ReactiveYMap

Parameters ​
_source ​

UnRecord

_ySource ​

YMap<unknown>

_options ​

ProxyOptions<UnRecord>

Returns ​

ReactiveYMap

Overrides ​

BaseReactiveYData<UnRecord, YMap<unknown>>.constructor

Properties ​

_proxy ​

protected readonly _proxy: UnRecord

Overrides ​

BaseReactiveYData._proxy

Accessors ​

Methods ​

_getProxy() ​

protected _getProxy(): UnRecord

Returns ​

UnRecord

pop() ​

pop(prop): void

Parameters ​
prop ​

string

Returns ​

void

Overrides ​

BaseReactiveYData.pop

stash() ​

stash(prop): void

Parameters ​
prop ​

string

Returns ​

void

Overrides ​

BaseReactiveYData.stash


Schema ​

Represents a schema manager for block flavours and their relationships. Provides methods to register, validate, and query block schemas.

Constructors ​

Constructor ​

new Schema(): Schema

Returns ​

Schema

Properties ​

flavourSchemaMap ​

readonly flavourSchemaMap: Map<string, { model: { children?: string[]; flavour: string; isFlatData?: boolean; parent?: string[]; props?: (...args) => Record<string, any>; role: string; toModel?: (...args) => BlockModel<object>; }; transformer?: (...args) => BaseBlockTransformer<object>; version: number; }>

A map storing block flavour names to their corresponding schema definitions.

Accessors ​

versions ​
Get Signature ​

get versions(): object

Returns an object mapping each registered flavour to its version number.

Returns ​

object

Methods ​

get() ​

get(flavour): { model: { children?: string[]; flavour: string; isFlatData?: boolean; parent?: string[]; props?: (...args) => Record<string, any>; role: string; toModel?: (...args) => BlockModel<object>; }; transformer?: (...args) => BaseBlockTransformer<object>; version: number; } | undefined

Retrieves the schema for a given block flavour.

Parameters ​
flavour ​

string

The block flavour name.

Returns ​

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

The corresponding BlockSchemaType or undefined if not found.

isValid() ​

isValid(child, parent): boolean

Checks if the child flavour is valid under the parent flavour.

Parameters ​
child ​

string

The child block flavour name.

parent ​

string

The parent block flavour name.

Returns ​

boolean

True if the relationship is valid, false otherwise.

register() ​

register(blockSchema): Schema

Registers an array of block schemas into the schema manager.

Parameters ​
blockSchema ​

object[]

An array of block schema definitions to register.

Returns ​

Schema

The Schema instance (for chaining).

safeValidate() ​

safeValidate(flavour, parentFlavour?, childFlavours?): boolean

Safely validates the schema relationship for a given flavour, parent, and children. Returns true if valid, false otherwise (does not throw).

Parameters ​
flavour ​

string

The block flavour to validate.

parentFlavour? ​

string

The parent block flavour (optional).

childFlavours? ​

string[]

The child block flavours (optional).

Returns ​

boolean

True if the schema relationship is valid, false otherwise.

toJSON() ​

toJSON(): object

Serializes the schema map to a plain object for JSON output.

Returns ​

object

An object mapping each flavour to its role, parent, and children.

validate() ​

validate(flavour, parentFlavour?, childFlavours?): void

Validates the schema relationship for a given flavour, parent, and children. Throws SchemaValidateError if invalid.

Parameters ​
flavour ​

string

The block flavour to validate.

parentFlavour? ​

string

The parent block flavour (optional).

childFlavours? ​

string[]

The child block flavours (optional).

Returns ​

void

Throws ​

If the schema relationship is invalid.

validateSchema() ​

validateSchema(child, parent): void

Validates the relationship between a child and parent schema. Throws if the relationship is invalid.

Parameters ​
child ​

The child block schema.

model ​

{ children?: string[]; flavour: string; isFlatData?: boolean; parent?: string[]; props?: (...args) => Record<string, any>; role: string; toModel?: (...args) => BlockModel<object>; } = ...

model.children? ​

string[] = ContentSchema

model.flavour ​

string = FlavourSchema

model.isFlatData? ​

boolean = ...

model.parent? ​

string[] = ParentSchema

model.props? ​

(...args) => Record<string, any> = ...

model.role ​

string = RoleSchema

model.toModel? ​

(...args) => BlockModel<object> = ...

transformer? ​

(...args) => BaseBlockTransformer<object> = ...

version ​

number = ...

parent ​

The parent block schema.

model ​

{ children?: string[]; flavour: string; isFlatData?: boolean; parent?: string[]; props?: (...args) => Record<string, any>; role: string; toModel?: (...args) => BlockModel<object>; } = ...

model.children? ​

string[] = ContentSchema

model.flavour ​

string = FlavourSchema

model.isFlatData? ​

boolean = ...

model.parent? ​

string[] = ParentSchema

model.props? ​

(...args) => Record<string, any> = ...

model.role ​

string = RoleSchema

model.toModel? ​

(...args) => BlockModel<object> = ...

transformer? ​

(...args) => BaseBlockTransformer<object> = ...

version ​

number = ...

Returns ​

void

Throws ​

If the relationship is invalid.


Slice ​

Constructors ​

Constructor ​

new Slice(data): Slice

Parameters ​
data ​

SliceData

Returns ​

Slice

Properties ​

data ​

readonly data: SliceData

Accessors ​

content ​
Get Signature ​

get content(): DraftModel[]

Returns ​

DraftModel[]

docId ​
Get Signature ​

get docId(): string

Returns ​

string

workspaceId ​
Get Signature ​

get workspaceId(): string

Returns ​

string

Methods ​

fromModels() ​

static fromModels(doc, models): Slice

Parameters ​
doc ​

Store

models ​

BlockModel<object>[] | DraftModel[]

Returns ​

Slice


StoreContainer ​

Constructors ​

Constructor ​

new StoreContainer(doc): StoreContainer

Parameters ​
doc ​

Doc

Returns ​

StoreContainer

Properties ​

doc ​

readonly doc: Doc

Methods ​

getStore() ​

getStore(__namedParameters?): Store

Parameters ​
__namedParameters? ​

GetStoreOptions = {}

Returns ​

Store

removeStore() ​

removeStore(__namedParameters): void

Parameters ​
__namedParameters ​

RemoveStoreOptions

Returns ​

void


Transformer ​

Constructors ​

Constructor ​

new Transformer(__namedParameters): Transformer

Parameters ​
__namedParameters ​

TransformerOptions

Returns ​

Transformer

Accessors ​

adapterConfigs ​
Get Signature ​

get adapterConfigs(): Map<string, string>

Returns ​

Map<string, string>

assets ​
Get Signature ​

get assets(): Map<string, Blob>

Returns ​

Map<string, Blob>

assetsManager ​
Get Signature ​

get assetsManager(): AssetsManager

Returns ​

AssetsManager

docCRUD ​
Get Signature ​

get docCRUD(): DocCRUD

Returns ​

DocCRUD

schema ​
Get Signature ​

get schema(): Schema

Returns ​

Schema

Methods ​

[dispose]() ​

[dispose](): void

Returns ​

void

blockToSnapshot() ​

blockToSnapshot(model): BlockSnapshot | undefined

Parameters ​
model ​

BlockModel<object> | DraftModel

Returns ​

BlockSnapshot | undefined

docToSnapshot() ​

docToSnapshot(doc): DocSnapshot | undefined

Parameters ​
doc ​

Store

Returns ​

DocSnapshot | undefined

reset() ​

reset(): void

Returns ​

void

sliceToSnapshot() ​

sliceToSnapshot(slice): SliceSnapshot | undefined

Parameters ​
slice ​

Slice

Returns ​

SliceSnapshot | undefined

snapshotToBlock() ​

snapshotToBlock(snapshot, doc, parent?, index?): Promise<BlockModel<object> | undefined>

Parameters ​
snapshot ​

BlockSnapshot

doc ​

Store

parent? ​

string

index? ​

number

Returns ​

Promise<BlockModel<object> | undefined>

snapshotToDoc() ​

snapshotToDoc(snapshot): Promise<Store | undefined>

Parameters ​
snapshot ​

DocSnapshot

Returns ​

Promise<Store | undefined>

snapshotToModelData() ​

snapshotToModelData(snapshot): Promise<SnapshotNode<object> | undefined>

Parameters ​
snapshot ​

BlockSnapshot

Returns ​

Promise<SnapshotNode<object> | undefined>

snapshotToSlice() ​

snapshotToSlice(snapshot, doc, parent?, index?): Promise<Slice | undefined>

Parameters ​
snapshot ​

SliceSnapshot

doc ​

Store

parent? ​

string

index? ​

number

Returns ​

Promise<Slice | undefined>

walk() ​

walk(snapshot, callback): void

Parameters ​
snapshot ​

DocSnapshot

callback ​

(block) => void

Returns ​

void


AwarenessEvent ​

Properties ​

id ​

id: number

state? ​

optional state?: RawAwarenessState

type ​

type: "add" | "update" | "remove"


BlobCRUD ​

Properties ​

delete ​

delete: (key) => void | Promise<void>

Parameters ​
key ​

string

Returns ​

void | Promise<void>

get ​

get: (key) => Blob | Promise<Blob | null> | null

Parameters ​
key ​

string

Returns ​

Blob | Promise<Blob | null> | null

list ​

list: () => string[] | Promise<string[]>

Returns ​

string[] | Promise<string[]>

set ​

set: (key, value) => string | Promise<string>

Parameters ​
key ​

string

value ​

Blob

Returns ​

string | Promise<string>


Doc ​

Properties ​

id ​

readonly id: string

Accessors ​

awarenessStore ​
Get Signature ​

get awarenessStore(): AwarenessStore

Returns ​

AwarenessStore

loaded ​
Get Signature ​

get loaded(): boolean

Returns ​

boolean

meta ​
Get Signature ​

get meta(): DocMeta | undefined

Returns ​

DocMeta | undefined

ready ​
Get Signature ​

get ready(): boolean

Returns ​

boolean

rootDoc ​
Get Signature ​

get rootDoc(): Doc

Returns ​

Doc

spaceDoc ​
Get Signature ​

get spaceDoc(): Doc

Returns ​

Doc

workspace ​
Get Signature ​

get workspace(): Workspace

Returns ​

Workspace

yBlocks ​
Get Signature ​

get yBlocks(): YMap<YBlock>

Returns ​

YMap<YBlock>

Methods ​

clear() ​

clear(): void

Returns ​

void

dispose() ​

dispose(): void

Returns ​

void

getStore() ​

getStore(options?): Store

Parameters ​
options? ​

GetStoreOptions

Returns ​

Store

load() ​

load(initFn?): void

Parameters ​
initFn? ​

() => void

Returns ​

void

remove() ​

remove(): void

Returns ​

void

removeStore() ​

removeStore(options): void

Parameters ​
options ​

RemoveStoreOptions

Returns ​

void


DocCRUD ​

Properties ​

create ​

create: (id) => Store

Parameters ​
id ​

string

Returns ​

Store

delete ​

delete: (id) => void

Parameters ​
id ​

string

Returns ​

void

get ​

get: (id) => Store | null

Parameters ​
id ​

string

Returns ​

Store | null


DocMeta ​

Properties ​

createDate ​

createDate: number

favorite? ​

optional favorite?: boolean

id ​

id: string

tags ​

tags: string[]

title ​

title: string

trash? ​

optional trash?: boolean

updatedDate? ​

optional updatedDate?: number


ExtensionType ​

Methods ​

setup() ​

setup(di): void

Parameters ​
di ​

Container

Returns ​

void


InternalPrimitives ​

Properties ​

Boxed ​

Boxed: <T>(input) => Boxed<T>

Type Parameters ​
T ​

T

Parameters ​
input ​

T

Returns ​

Boxed<T>

Text ​

Text: (input?) => Text

Parameters ​
input? ​

string | YText

Returns ​

Text


OptionalAttributes ​

Properties ​

attributes? ​

optional attributes?: Record<string, any>


SelectionConstructor ​

Type Parameters ​

T ​

T extends BaseSelection = BaseSelection

Constructors ​

Constructor ​

new SelectionConstructor(...args): T

Parameters ​
args ​

...any[]

Returns ​

T

Properties ​

group ​

group: string

type ​

type: string

Methods ​

fromJSON() ​

fromJSON(json): T

Parameters ​
json ​

Record<string, unknown>

Returns ​

T


StackItem ​

Properties ​

meta ​

meta: Map<"selection-state", unknown>


UserInfo ​

Properties ​

name ​

name: string


Workspace ​

Properties ​

blobSync ​

readonly blobSync: BlobEngine

id ​

readonly id: string

idGenerator ​

readonly idGenerator: IdGenerator

meta ​

readonly meta: WorkspaceMeta

onLoadAwareness? ​

readonly optional onLoadAwareness?: (awareness) => void

Parameters ​
awareness ​

Awareness

Returns ​

void

onLoadDoc? ​

readonly optional onLoadDoc?: (doc) => void

Parameters ​
doc ​

Doc

Returns ​

void

slots ​

slots: object

docListUpdated ​

docListUpdated: Subject<void>

Accessors ​

doc ​
Get Signature ​

get doc(): Doc

Returns ​

Doc

docs ​
Get Signature ​

get docs(): Map<string, Doc>

Returns ​

Map<string, Doc>

Methods ​

createDoc() ​

createDoc(docId?): Doc

Parameters ​
docId? ​

string

Returns ​

Doc

dispose() ​

dispose(): void

Returns ​

void

getDoc() ​

getDoc(docId): Doc | null

Parameters ​
docId ​

string

Returns ​

Doc | null

removeDoc() ​

removeDoc(docId): void

Parameters ​
docId ​

string

Returns ​

void


WorkspaceMeta ​

Properties ​

docMetaAdded ​

docMetaAdded: Subject<string>

docMetaRemoved ​

docMetaRemoved: Subject<string>

docMetaUpdated ​

docMetaUpdated: Subject<void>

Accessors ​

docMetas ​
Get Signature ​

get docMetas(): DocMeta[]

Returns ​

DocMeta[]

docs ​
Get Signature ​

get docs(): unknown[] | undefined

Returns ​

unknown[] | undefined

properties ​
Get Signature ​

get properties(): DocsPropertiesMeta

Returns ​

DocsPropertiesMeta

Methods ​

addDocMeta() ​

addDocMeta(props, index?): void

Parameters ​
props ​

DocMeta

index? ​

number

Returns ​

void

getDocMeta() ​

getDocMeta(id): DocMeta | undefined

Parameters ​
id ​

string

Returns ​

DocMeta | undefined

initialize() ​

initialize(): void

Returns ​

void

removeDocMeta() ​

removeDocMeta(id): void

Parameters ​
id ​

string

Returns ​

void

setDocMeta() ​

setDocMeta(id, props): void

Parameters ​
id ​

string

props ​

Partial<DocMeta>

Returns ​

void

setProperties() ​

setProperties(meta): void

Parameters ​
meta ​

DocsPropertiesMeta

Returns ​

void


AfterExportPayload ​

AfterExportPayload = { index?: number; model: DraftModel; parent?: string; snapshot: BlockSnapshot; type: "block"; } | { page: Store; snapshot: DocSnapshot; type: "page"; } | { slice: Slice; snapshot: SliceSnapshot; type: "slice"; } | { snapshot: CollectionInfoSnapshot; type: "info"; }


AfterImportBlockPayload ​

AfterImportBlockPayload = object

Properties ​

index? ​

optional index?: number

model ​

model: BlockModel

parent? ​

optional parent?: string

snapshot ​

snapshot: BlockSnapshot

type ​

type: "block"


AfterImportPayload ​

AfterImportPayload = AfterImportBlockPayload | { page: Store; snapshot: DocSnapshot; type: "page"; } | { slice: Slice; snapshot: SliceSnapshot; type: "slice"; } | { snapshot: CollectionInfoSnapshot; type: "info"; }


BaseSelectionOptions ​

BaseSelectionOptions = object

Properties ​

blockId ​

blockId: string


BaseTextAttributes ​

BaseTextAttributes = z.infer<typeof baseTextAttributes>


BeforeExportPayload ​

BeforeExportPayload = { model: DraftModel; type: "block"; } | { page: Store; type: "page"; } | { slice: Slice; type: "slice"; } | { type: "info"; }


BeforeImportBlockPayload ​

BeforeImportBlockPayload = object

Properties ​

index? ​

optional index?: number

parent? ​

optional parent?: string

snapshot ​

snapshot: BlockSnapshot

type ​

type: "block"


BeforeImportPayload ​

BeforeImportPayload = BeforeImportBlockPayload | { snapshot: SliceSnapshot; type: "slice"; } | { snapshot: DocSnapshot; type: "page"; } | { snapshot: CollectionInfoSnapshot; type: "info"; }


BlockOptions ​

BlockOptions = object

Properties ​

onChange? ​

optional onChange?: (block, key, isLocal) => void

Parameters ​
block ​

Block

key ​

string

isLocal ​

boolean

Returns ​

void


BlockProps ​

BlockProps = BlockSysProps & Record<string, unknown>


BlockSchemaType ​

BlockSchemaType = z.infer<typeof BlockSchema>


BlockSnapshot ​

BlockSnapshot = object

Properties ​

children ​

children: BlockSnapshot[]

flavour ​

flavour: string

id ​

id: string

props ​

props: Record<string, unknown>

type ​

type: "block"

version? ​

optional version?: number


BlockSnapshotLeaf ​

BlockSnapshotLeaf = Pick<BlockSnapshot, "id" | "flavour" | "props" | "version">


BlockSysProps ​

BlockSysProps = object

Properties ​

children? ​

optional children?: BlockModel[]

flavour ​

flavour: string

id ​

id: string


BlockViewType ​

BlockViewType = "bypass" | "display" | "hidden"


CollectionInfoSnapshot ​

CollectionInfoSnapshot = object

Properties ​

id ​

id: string

properties ​

properties: DocsPropertiesMeta

type ​

type: "info"


DeltaInsert ​

DeltaInsert<TextAttributes> = object

Type Parameters ​

TextAttributes ​

TextAttributes extends BaseTextAttributes = BaseTextAttributes

Properties ​

attributes? ​

optional attributes?: TextAttributes

insert ​

insert: string


DeltaOperation ​

DeltaOperation = object & OptionalAttributes

Type Declaration ​

delete? ​

optional delete?: number

insert? ​

optional insert?: string

retain? ​

optional retain?: number


DocSnapshot ​

DocSnapshot = object

Properties ​

blocks ​

blocks: BlockSnapshot

meta ​

meta: DocMeta

type ​

type: "page"


DocsPropertiesMeta ​

DocsPropertiesMeta = object

Properties ​

tags? ​

optional tags?: object

options ​

options: Tag[]


DraftModel ​

DraftModel<Model> = Pick<Model, PropsInDraft> & object

Type Declaration ​

[draftModelSymbol] ​

[draftModelSymbol]: true

children ​

children: DraftModel[]

props ​

props: ModelProps<Model>

Type Parameters ​

Model ​

Model extends BlockModel = BlockModel


FromBlockSnapshotPayload ​

FromBlockSnapshotPayload = object

Properties ​

assets? ​

optional assets?: AssetsManager

snapshot ​

snapshot: BlockSnapshot


FromBlockSnapshotResult ​

FromBlockSnapshotResult<Target> = object

Type Parameters ​

Target ​

Target

Properties ​

assetsIds ​

assetsIds: string[]

file ​

file: Target


FromDocSnapshotPayload ​

FromDocSnapshotPayload = object

Properties ​

assets? ​

optional assets?: AssetsManager

snapshot ​

snapshot: DocSnapshot


FromDocSnapshotResult ​

FromDocSnapshotResult<Target> = object

Type Parameters ​

Target ​

Target

Properties ​

assetsIds ​

assetsIds: string[]

file ​

file: Target


FromSliceSnapshotPayload ​

FromSliceSnapshotPayload = object

Properties ​

assets? ​

optional assets?: AssetsManager

snapshot ​

snapshot: SliceSnapshot


FromSliceSnapshotResult ​

FromSliceSnapshotResult<Target> = object

Type Parameters ​

Target ​

Target

Properties ​

assetsIds ​

assetsIds: string[]

file ​

file: Target


FromSnapshotPayload ​

FromSnapshotPayload = object

Properties ​

assets ​

assets: AssetsManager

children ​

children: BlockSnapshot[]

json ​

json: BlockSnapshotLeaf


GetStoreOptions ​

GetStoreOptions = Omit<StoreOptions, "schema" | "doc">


IdGenerator ​

IdGenerator = () => string

Returns ​

string


Native2Y ​

Native2Y<T> = T extends Record<string, infer U> ? YMap<U> : T extends infer U[] ? YArray<U> : T

Type Parameters ​

T ​

T


NodeProps ​

NodeProps<Node> = object

Type Parameters ​

Node ​

Node extends object

Properties ​

index ​

index: number | null

next? ​

optional next?: Node | null

node ​

node: Node

parent ​

parent: NodeProps<Node> | null

prop ​

prop: Keyof<Node> | null


OnBoxedChange ​

OnBoxedChange = (data, isLocal) => void

Parameters ​

data ​

unknown

isLocal ​

boolean

Returns ​

void


OnTextChange ​

OnTextChange = (data, isLocal) => void

Parameters ​

data ​

Y.Text

isLocal ​

boolean

Returns ​

void


PropsGetter ​

PropsGetter<Props> = (internalPrimitives) => Props

Type Parameters ​

Props ​

Props

Parameters ​

internalPrimitives ​

InternalPrimitives

Returns ​

Props


PropsOfModel ​

PropsOfModel<T> = T extends BlockModel<infer P> ? P : never

Type Parameters ​

T ​

T


ProxyOptions ​

ProxyOptions<T> = object

Type Parameters ​

T ​

T

Properties ​

onChange? ​

optional onChange?: (data, isLocal) => void

Parameters ​
data ​

T

isLocal ​

boolean

Returns ​

void


Query ​

Query = object

Properties ​

match ​

match: QueryMatch[]

mode ​

mode: QueryMode


QueryMatch ​

QueryMatch = object

Properties ​

flavour? ​

optional flavour?: string

id? ​

optional id?: string

props? ​

optional props?: Record<string, unknown>

viewType ​

viewType: BlockViewType


RawAwarenessState ​

RawAwarenessState = object

Properties ​

color? ​

optional color?: string

selectionV2 ​

selectionV2: Record<string, UserSelection>

user? ​

optional user?: UserInfo


RemoveStoreOptions ​

RemoveStoreOptions = Pick<StoreOptions, "query" | "id" | "readonly">


RoleType ​

RoleType = "root" | "content" | string


SliceSnapshot ​

SliceSnapshot = object

Properties ​

content ​

content: BlockSnapshot[]

pageId ​

pageId: string

type ​

type: "slice"

workspaceId ​

workspaceId: string


SnapshotNode ​

SnapshotNode<Props> = object

Type Parameters ​

Props ​

Props extends object

Properties ​

flavour ​

flavour: string

id ​

id: string

props ​

props: Props

version ​

version: number


StoreOptions ​

StoreOptions = object

Properties ​

doc ​

doc: Doc

extensions? ​

optional extensions?: ExtensionType[]

id? ​

optional id?: string

provider? ​

optional provider?: ServiceProvider

query? ​

optional query?: Query

readonly? ​

optional readonly?: boolean


SubdocEvent ​

SubdocEvent = object

Properties ​

added ​

added: Set<YDoc>

loaded ​

loaded: Set<YDoc>

removed ​

removed: Set<YDoc>


Tag ​

Tag = object

Properties ​

color ​

color: string

id ​

id: string

value ​

value: string


ToBlockSnapshotPayload ​

ToBlockSnapshotPayload<Target> = object

Type Parameters ​

Target ​

Target

Properties ​

assets? ​

optional assets?: AssetsManager

file ​

file: Target


ToDocSnapshotPayload ​

ToDocSnapshotPayload<Target> = object

Type Parameters ​

Target ​

Target

Properties ​

assets? ​

optional assets?: AssetsManager

file ​

file: Target


ToSliceSnapshotPayload ​

ToSliceSnapshotPayload<Target> = object

Type Parameters ​

Target ​

Target

Properties ​

assets? ​

optional assets?: AssetsManager

file ​

file: Target


ToSnapshotPayload ​

ToSnapshotPayload<Props> = object

Type Parameters ​

Props ​

Props extends object

Properties ​

assets ​

assets: AssetsManager

model ​

model: DraftModel<BlockModel<Props>> | BlockModel<Props>


TransformerMiddleware ​

TransformerMiddleware = (options) => void | TransformerMiddlewareCleanup

Parameters ​

options ​

TransformerMiddlewareOptions

Returns ​

void | TransformerMiddlewareCleanup


TransformerOptions ​

TransformerOptions = object

Properties ​

blobCRUD ​

blobCRUD: BlobCRUD

docCRUD ​

docCRUD: DocCRUD

middlewares? ​

optional middlewares?: TransformerMiddleware[]

schema ​

schema: Schema


TransformerSlots ​

TransformerSlots = object

Properties ​

afterExport ​

afterExport: Subject<AfterExportPayload>

afterImport ​

afterImport: Subject<AfterImportPayload>

beforeExport ​

beforeExport: Subject<BeforeExportPayload>

beforeImport ​

beforeImport: Subject<BeforeImportPayload>


TransformOptions ​

TransformOptions = object

Properties ​

deep? ​

optional deep?: boolean

transform? ​

optional transform?: (value, origin) => unknown

Parameters ​
value ​

unknown

origin ​

unknown

Returns ​

unknown


UnRecord ​

UnRecord = Record<string, unknown>


YBlock ​

YBlock = Y.Map<unknown> & object

Type Declaration ​

get() ​
Call Signature ​

get(prop): string

Parameters ​
prop ​

"sys:id" | "sys:flavour"

Returns ​

string

Call Signature ​

get(prop): YArray<string>

Parameters ​
prop ​

"sys:children"

Returns ​

YArray<string>

Call Signature ​

get<T>(prop): T

Type Parameters ​
T ​

T = unknown

Parameters ​
prop ​

string

Returns ​

T


baseTextAttributes ​

const baseTextAttributes: ZodObject<{ bold: ZodCatch<ZodNullable<ZodOptional<ZodLiteral<true>>>>; code: ZodCatch<ZodNullable<ZodOptional<ZodLiteral<true>>>>; italic: ZodCatch<ZodNullable<ZodOptional<ZodLiteral<true>>>>; link: ZodCatch<ZodNullable<ZodOptional<ZodString>>>; strike: ZodCatch<ZodNullable<ZodOptional<ZodLiteral<true>>>>; underline: ZodCatch<ZodNullable<ZodOptional<ZodLiteral<true>>>>; }, "strip", ZodTypeAny, { bold?: true | null; code?: true | null; italic?: true | null; link?: string | null; strike?: true | null; underline?: true | null; }, { bold?: unknown; code?: unknown; italic?: unknown; link?: unknown; strike?: unknown; underline?: unknown; }>


BlockSchema ​

const BlockSchema: ZodObject<{ model: ZodObject<{ children: ZodOptional<ZodArray<ZodString, "many">>; flavour: ZodString; isFlatData: ZodOptional<ZodBoolean>; parent: ZodOptional<ZodArray<ZodString, "many">>; props: ZodOptional<ZodFunction<ZodTuple<[ZodType<InternalPrimitives, ZodTypeDef, InternalPrimitives>], ZodUnknown>, ZodRecord<ZodString, ZodAny>>>; role: ZodString; toModel: ZodOptional<ZodFunction<ZodTuple<[], ZodUnknown>, ZodType<BlockModel<object>, ZodTypeDef, BlockModel<object>>>>; }, "strip", ZodTypeAny, { children?: string[]; flavour: string; isFlatData?: boolean; parent?: string[]; props?: (...args) => Record<string, any>; role: string; toModel?: (...args) => BlockModel<object>; }, { children?: string[]; flavour: string; isFlatData?: boolean; parent?: string[]; props?: (...args) => Record<string, any>; role: string; toModel?: (...args) => BlockModel<object>; }>; transformer: ZodOptional<ZodFunction<ZodTuple<[ZodType<Map<string, unknown>, ZodTypeDef, Map<string, unknown>>], ZodUnknown>, ZodType<BaseBlockTransformer<object>, ZodTypeDef, BaseBlockTransformer<object>>>>; version: ZodNumber; }, "strip", ZodTypeAny, { model: { children?: string[]; flavour: string; isFlatData?: boolean; parent?: string[]; props?: (...args) => Record<string, any>; role: string; toModel?: (...args) => BlockModel<object>; }; transformer?: (...args) => BaseBlockTransformer<object>; version: number; }, { model: { children?: string[]; flavour: string; isFlatData?: boolean; parent?: string[]; props?: (...args) => Record<string, any>; role: string; toModel?: (...args) => BlockModel<object>; }; transformer?: (...args) => BaseBlockTransformer<object>; version: number; }>


BlockSchemaIdentifier ​

const BlockSchemaIdentifier: ServiceIdentifier<{ model: { children?: string[]; flavour: string; isFlatData?: boolean; parent?: string[]; props?: (...args) => Record<string, any>; role: string; toModel?: (...args) => BlockModel<object>; }; transformer?: (...args) => BaseBlockTransformer<object>; version: number; }> & <U>(variant) => ServiceIdentifier<U>


BlockSnapshotSchema ​

const BlockSnapshotSchema: z.ZodType<BlockSnapshot>


DocIdentifier ​

const DocIdentifier: ServiceIdentifier<Doc> & <U>(variant) => ServiceIdentifier<U>


DocSnapshotSchema ​

const DocSnapshotSchema: z.ZodType<DocSnapshot>


extMimeMap ​

const extMimeMap: Map<string, string>


internalPrimitives ​

const internalPrimitives: InternalPrimitives


mimeExtMap ​

const mimeExtMap: Map<string, string>


nanoid ​

const nanoid: IdGenerator


SelectionIdentifier ​

const SelectionIdentifier: ServiceIdentifier<SelectionConstructor<BaseSelection>> & <U>(variant) => ServiceIdentifier<U>


SliceSnapshotSchema ​

const SliceSnapshotSchema: z.ZodType<SliceSnapshot>


StoreExtensionIdentifier ​

const StoreExtensionIdentifier: ServiceIdentifier<StoreExtension> & <U>(variant) => ServiceIdentifier<U>


storeExtensionSymbol ​

const storeExtensionSymbol: typeof storeExtensionSymbol


StoreIdentifier ​

const StoreIdentifier: ServiceIdentifier<Store> & <U>(variant) => ServiceIdentifier<U>


uuidv4 ​

const uuidv4: IdGenerator


BlockSchemaExtension() ​

BlockSchemaExtension(blockSchema): ExtensionType

Parameters ​

blockSchema ​
model ​

{ children?: string[]; flavour: string; isFlatData?: boolean; parent?: string[]; props?: (...args) => Record<string, any>; role: string; toModel?: (...args) => BlockModel<object>; } = ...

model.children? ​

string[] = ContentSchema

model.flavour ​

string = FlavourSchema

model.isFlatData? ​

boolean = ...

model.parent? ​

string[] = ParentSchema

model.props? ​

(...args) => Record<string, any> = ...

model.role ​

string = RoleSchema

model.toModel? ​

(...args) => BlockModel<object> = ...

transformer? ​

(...args) => BaseBlockTransformer<object> = ...

version ​

number = ...

Returns ​

ExtensionType


createYProxy() ​

createYProxy<Data>(yAbstract, options?): Data

Type Parameters ​

Data ​

Data

Parameters ​

yAbstract ​

unknown

options? ​

ProxyOptions<Data> = {}

Returns ​

Data


defineBlockSchema() ​

defineBlockSchema<Flavour, Role, Props, Metadata, Model, Transformer>(options): object

Type Parameters ​

Flavour ​

Flavour extends string

Role ​

Role extends string

Props ​

Props extends object

Metadata ​

Metadata extends Readonly<{ children?: string[]; isFlatData?: boolean; parent?: string[]; role: Role; version: number; }>

Model ​

Model extends BlockModel<Props>

Transformer ​

Transformer extends BaseBlockTransformer<Props>

Parameters ​

options ​
flavour ​

Flavour

metadata ​

Metadata

props? ​

(internalPrimitives) => Props

toModel? ​

() => Model

transformer? ​

(transformerConfig) => Transformer

Returns ​

object

model ​

model: object & Metadata

Type Declaration ​
flavour ​

flavour: Flavour

props ​

props: PropsGetter<Props>

transformer? ​

optional transformer?: (transformerConfig) => Transformer

Parameters ​
transformerConfig ​

Map<string, unknown>

Returns ​

Transformer

version ​

version: number


fromJSON() ​

fromJSON(value): unknown

Parameters ​

value ​

unknown

Returns ​

unknown


getAssetName() ​

getAssetName(assets, blobId): string

Parameters ​

assets ​

Map<string, Blob>

blobId ​

string

Returns ​

string


isPureObject() ​

isPureObject(value): value is object

Parameters ​

value ​

unknown

Returns ​

value is object


isStoreExtensionConstructor() ​

isStoreExtensionConstructor(extension): extension is typeof StoreExtension

Parameters ​

extension ​

object

Returns ​

extension is typeof StoreExtension


native2Y() ​

native2Y<T>(value, __namedParameters?): Native2Y<T>

Type Parameters ​

T ​

T

Parameters ​

value ​

T

__namedParameters? ​

TransformOptions = {}

Returns ​

Native2Y<T>


popProp() ​

Call Signature ​

popProp(yMap, prop): void

Parameters ​
yMap ​

YMap<unknown>

prop ​

string

Returns ​

void

Call Signature ​

popProp(yMap, prop): void

Parameters ​
yMap ​

YArray<unknown>

prop ​

number

Returns ​

void


runQuery() ​

runQuery(query, block): void

Parameters ​

query ​

Query

block ​

Block

Returns ​

void


SelectionExtension() ​

SelectionExtension(selectionCtor): ExtensionType

Parameters ​

selectionCtor ​

SelectionConstructor

Returns ​

ExtensionType


stashProp() ​

Call Signature ​

stashProp(yMap, prop): void

Parameters ​
yMap ​

YMap<unknown>

prop ​

string

Returns ​

void

Call Signature ​

stashProp(yMap, prop): void

Parameters ​
yMap ​

YArray<unknown>

prop ​

number

Returns ​

void


toDraftModel() ​

toDraftModel<Model>(origin): DraftModel<Model>

Type Parameters ​

Model ​

Model extends BlockModel<object> = BlockModel<object>

Parameters ​

origin ​

Model

Returns ​

DraftModel<Model>


toJSON() ​

toJSON(value): unknown

Parameters ​

value ​

unknown

Returns ​

unknown


wrapFakeNote() ​

wrapFakeNote(snapshot): void

Parameters ​

snapshot ​

SliceSnapshot

Returns ​

void


y2Native() ​

y2Native(yAbstract, __namedParameters?): unknown

Parameters ​

yAbstract ​

unknown

__namedParameters? ​

TransformOptions = {}

Returns ​

unknown

Reactive ​

Boxed ​

Boxed is to store raw data in Yjs. By default, store will try to convert a object to a Y.Map. If you want to store a raw object for you want to manipulate the Y.Map directly, you can use Boxed.

NOTE

Please notice that the data will be stored in Y.Map anyway so it can not hold data structure like function.

Example ​

ts
const boxedObject = new Boxed({ a: 1, b: 2 });
const boxedYMap = new Boxed(new Y.Map());
boxedObject.getValue().a; // 1
boxedYMap.getValue().set('a', 1);
boxedObject.setValue({ foo: 'bar' });

Type Param ​

T

The type of the value stored in the Boxed.

Type Parameters ​

Value ​

Value = unknown

Constructors ​

Constructor ​

new Boxed<Value>(value): Boxed<Value>

Parameters ​
value ​

Value

Returns ​

Boxed<Value>

Methods ​

getValue() ​

getValue(): Value | undefined

Get the current value of the Boxed.

Returns ​

Value | undefined

setValue() ​

setValue(value): Value

Replace the current value of the Boxed.

Parameters ​
value ​

Value

The new value to set.

Returns ​

Value

from() ​

static from<Value>(map): Boxed<Value>

Create a Boxed from a Y.Map. It is useful when you sync a Y.Map from remote.

Type Parameters ​
Value ​

Value

The type of the value.

Parameters ​
map ​

YMap<unknown>

Returns ​

Boxed<Value>

Example ​
ts
const doc1 = new Y.Doc();
const doc2 = new Y.Doc();
keepSynced(doc1, doc2);

const data1 = doc1.getMap('data');
const boxed1 = new Boxed({ a: 1, b: 2 });
data1.set('boxed', boxed1.yMap);

const data2 = doc2.getMap('data');
const boxed2 = Boxed.from<{ a: number; b: number }>(data2.get('boxed'));
is() ​

static is(value): value is Boxed<unknown>

Check if a value is a Boxed.

Parameters ​
value ​

unknown

Returns ​

value is Boxed<unknown>

Example ​
ts
const doc = new Y.Doc();

const data = doc.getMap('data');
const boxed = new Boxed({ a: 1, b: 2 });
Boxed.is(boxed); // true

data.set('boxed', boxed.yMap);
Boxed.is(data.get('boxed)); // true

Text ​

Text is an abstraction of Y.Text. It provides useful methods to manipulate the text content.

Example ​

ts
const text = new Text('Hello, world!');
text.insert(' blocksuite', 7);
text.delete(7, 1);
text.format(7, 1, { bold: true });
text.join(new Text(' blocksuite'));
text.split(7, 1);

Text delta is a format from Y.js.

Type Parameters ​

TextAttributes ​

TextAttributes extends BaseTextAttributes = BaseTextAttributes

Constructors ​

Constructor ​

new Text<TextAttributes>(input?): Text<TextAttributes>

Parameters ​
input? ​

string | YText | DeltaInsert<TextAttributes>[]

The input can be a string, a Y.Text instance, or an array of DeltaInsert.

Returns ​

Text<TextAttributes>

Accessors ​

deltas$ ​
Get Signature ​

get deltas$(): Signal<DeltaOperation[]>

Get the text delta as a signal.

Returns ​

Signal<DeltaOperation[]>

length ​
Get Signature ​

get length(): number

Returns ​

number

yText ​
Get Signature ​

get yText(): YText

Returns ​

YText

Methods ​

applyDelta() ​

applyDelta(delta): void

Apply a delta to the text.

Parameters ​
delta ​

DeltaOperation[]

The delta to apply.

Returns ​

void

Example ​
ts
const text = new Text('Hello, world!');
text.applyDelta([{insert: ' blocksuite', attributes: { bold: true }}]);
clear() ​

clear(): void

Clear the text content.

Returns ​

void

clone() ​

clone(): Text<{ bold?: true | null; code?: true | null; italic?: true | null; link?: string | null; strike?: true | null; underline?: true | null; }>

Clone the text to a new Text instance.

Returns ​

Text<{ bold?: true | null; code?: true | null; italic?: true | null; link?: string | null; strike?: true | null; underline?: true | null; }>

A new Text instance.

delete() ​

delete(index, length): void

Delete the text content.

Parameters ​
index ​

number

The index to delete.

length ​

number

The length to delete.

Returns ​

void

format() ​

format(index, length, format): void

Format the text content.

Parameters ​
index ​

number

The index to format.

length ​

number

The length to format.

format ​

Record<string, unknown>

The format to apply.

Returns ​

void

Example ​
ts
const text = new Text('Hello, world!');
text.format(7, 1, { bold: true });
insert() ​

insert(content, index, attributes?): void

Insert content at the specified index.

Parameters ​
content ​

string

The content to insert.

index ​

number

The index to insert.

attributes? ​

Record<string, unknown>

Returns ​

void

Example ​
ts
const text = new Text('Hello, world!');
text.insert(' blocksuite', 7);
join() ​

join(other): void

Join current text with another text.

Parameters ​
other ​

Text

The other text to join.

Returns ​

void

Example ​
ts
const text = new Text('Hello, world!');
const other = new Text(' blocksuite');
text.join(other);
replace() ​

replace(index, length, content, attributes?): void

Replace the text content with a new content.

Parameters ​
index ​

number

The index to replace.

length ​

number

The length to replace.

content ​

string

The content to replace.

attributes? ​

Record<string, unknown>

The attributes to replace.

Returns ​

void

Example ​
ts
const text = new Text('Hello, world!');
text.replace(7, 1, ' blocksuite');
sliceToDelta() ​

sliceToDelta(begin, end?): DeltaOperation[]

Slice the text to a delta.

Parameters ​
begin ​

number

The begin index.

end? ​

number

The end index.

Returns ​

DeltaOperation[]

The delta of the sliced text.

split() ​

split(index, length?): Text

Split the text into another Text.

Parameters ​
index ​

number

The index to split.

length? ​

number = 0

The length to split.

Returns ​

Text

The right part of the text.

Example ​
ts
const text = new Text('Hello, world!');
text.split(7, 1);

NOTE: The string included in [index, index + length) will be deleted.

Here are three cases for point position(index + length):

[{insert: 'abc', ...}, {insert: 'def', ...}, {insert: 'ghi', ...}]
1. abc|de|fghi
   left: [{insert: 'abc', ...}]
   right: [{insert: 'f', ...}, {insert: 'ghi', ...}]
2. abc|def|ghi
   left: [{insert: 'abc', ...}]
   right: [{insert: 'ghi', ...}]
3. abc|defg|hi
   left: [{insert: 'abc', ...}]
   right: [{insert: 'hi', ...}]
toDelta() ​

toDelta(): DeltaOperation[]

Get the text delta.

Returns ​

DeltaOperation[]

The delta of the text.

toString() ​

toString(): string

Get the text content as a string. In most cases, you should not use this method. It will lose the delta attributes information.

Returns ​

string

The text content.

Store ​

Store ​

Core store class that manages blocks and their lifecycle in BlockSuite

Remarks ​

The Store class is responsible for managing the lifecycle of blocks, handling transactions, and maintaining the block tree structure. A store is a piece of data created from one or a part of a Y.Doc.

Block CRUD ​

blockSize ​
Get Signature ​

get blockSize(): number

Get the number of blocks in the store

Returns ​

number

isEmpty ​
Get Signature ​

get isEmpty(): boolean

Check if there are no blocks in the store.

Returns ​

boolean

isEmpty$ ​
Get Signature ​

get isEmpty$(): ReadonlySignal<boolean>

Get the signal for the empty state of the store.

Returns ​

ReadonlySignal<boolean>

readonly ​
Get Signature ​

get readonly(): boolean

Check if the store is readonly.

Returns ​

boolean

Set Signature ​

set readonly(value): void

Set the readonly state of the store.

Parameters ​
value ​

boolean

Returns ​

void

readonly$ ​
Get Signature ​

get readonly$(): Signal<boolean>

Get the signal for the readonly state of the store.

Returns ​

Signal<boolean>

root ​
Get Signature ​

get root(): BlockModel<object> | null

Get the root block of the store.

Returns ​

BlockModel<object> | null

addBlock() ​

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

Creates and adds a new block to the store

Type Parameters ​
T ​

T extends BlockModel<object> = BlockModel<object>

Parameters ​
flavour ​

string

The block's flavour (type)

blockProps? ​

Partial<BlockProps | PropsOfModel<T> & BlockSysProps> = {}

Optional properties for the new block

parent? ​

string | BlockModel<object> | null

Optional parent block or parent block ID

parentIndex? ​

number

Optional index position in parent's children

Returns ​

string

The ID of the newly created block

Throws ​

When store is in readonly mode

addBlocks() ​

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

Add multiple blocks to the store

Parameters ​
blocks ​

object[]

Array of blocks to add

parent? ​

string | BlockModel<object> | null

Optional parent block or parent block ID

parentIndex? ​

number

Optional index position in parent's children

Returns ​

string[]

Array of IDs of the newly created blocks

addSiblingBlocks() ​

addSiblingBlocks(targetModel, props, placement?): string[]

Add sibling blocks to the store

Parameters ​
targetModel ​

BlockModel

The target block model

props ​

Partial<BlockProps>[]

Array of block properties

placement? ​

"after" | "before"

Optional position to place the new blocks ('after' or 'before')

Returns ​

string[]

Array of IDs of the newly created blocks

deleteBlock() ​

deleteBlock(model, options?): void

Delete a block from the store

Parameters ​
model ​

string | BlockModel<object>

The block model or block ID to delete

options? ​

Optional options for the deletion

bringChildrenTo? ​

BlockModel<object>

Optional block model to bring children to

deleteChildren? ​

boolean

Optional flag to delete children

Returns ​

void

getAllModels() ​

getAllModels(): BlockModel<object>[]

Get all models in the store

Returns ​

BlockModel<object>[]

Array of all models

getBlock() ​

getBlock(id): Block | undefined

Gets a block by its ID

Parameters ​
id ​

string

The block's ID

Returns ​

Block | undefined

The block instance if found, undefined otherwise

getBlock$() ​

getBlock$(id): Block | undefined

Gets a block by its ID

Parameters ​
id ​

string

The block's ID

Returns ​

Block | undefined

The block instance in signal if found, undefined otherwise

getBlocksByFlavour() ​

getBlocksByFlavour(blockFlavour): Block[]

Gets all blocks of specified flavour(s)

Parameters ​
blockFlavour ​

string | string[]

Single flavour or array of flavours to filter by

Returns ​

Block[]

Array of matching blocks

getModelById() ​

getModelById<Model>(id): Model | null

Get a model by its ID

Type Parameters ​
Model ​

Model extends BlockModel<object> = BlockModel<object>

Parameters ​
id ​

string

The model's ID

Returns ​

Model | null

The model instance if found, null otherwise

getModelsByFlavour() ​

getModelsByFlavour(blockFlavour): BlockModel<object>[]

Get all models of specified flavour(s)

Parameters ​
blockFlavour ​

string | string[]

Single flavour or array of flavours to filter by

Returns ​

BlockModel<object>[]

Array of matching models

getNext() ​

getNext(block): BlockModel<object> | null

Get the next sibling block of a given block

Parameters ​
block ​

string | BlockModel<object>

Block model or block ID to find next sibling for

Returns ​

BlockModel<object> | null

The next sibling block model if found, null otherwise

getNexts() ​

getNexts(block): BlockModel<object>[]

Get all next sibling blocks of a given block

Parameters ​
block ​

string | BlockModel<object>

Block model or block ID to find next siblings for

Returns ​

BlockModel<object>[]

Array of next sibling blocks if found, empty array otherwise

getParent() ​

getParent(target): BlockModel<object> | null

Gets the parent block of a given block

Parameters ​
target ​

string | BlockModel<object>

Block model or block ID to find parent for

Returns ​

BlockModel<object> | null

The parent block model if found, null otherwise

getPrev() ​

getPrev(block): BlockModel<object> | null

Get the previous sibling block of a given block

Parameters ​
block ​

string | BlockModel<object>

Block model or block ID to find previous sibling for

Returns ​

BlockModel<object> | null

The previous sibling block model if found, null otherwise

getPrevs() ​

getPrevs(block): BlockModel<object>[]

Get all previous sibling blocks of a given block

Parameters ​
block ​

string | BlockModel<object>

Block model or block ID to find previous siblings for

Returns ​

BlockModel<object>[]

Array of previous sibling blocks if found, empty array otherwise

hasBlock() ​

hasBlock(id): boolean

Check if a block exists by its ID

Parameters ​
id ​

string

The block's ID

Returns ​

boolean

True if the block exists, false otherwise

moveBlocks() ​

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

Move blocks to a new parent block

Parameters ​
blocksToMove ​

BlockModel<object>[]

Array of block models to move

newParent ​

BlockModel

The new parent block model

targetSibling? ​

BlockModel<object> | null

Optional target sibling block model

shouldInsertBeforeSibling? ​

boolean = true

Optional flag to insert before sibling

Returns ​

void

updateBlock() ​

updateBlock<T>(modelOrId, callBackOrProps): void

Updates a block's properties or executes a callback in a transaction

Type Parameters ​
T ​

T extends BlockModel<object> = BlockModel<object>

Parameters ​
modelOrId ​

string | T

The block model or block ID to update

callBackOrProps ​

(() => void) | Partial<BlockProps | PropsOfModel<T> & BlockSysProps>

Either a callback function to execute or properties to update

Returns ​

void

Throws ​

When the block is not found or schema validation fails

Extension ​

get ​
Get Signature ​

get get(): <T>(identifier, options?) => T

Get an extension instance from the store

Example ​
ts
const extension = store.get(SomeExtension);
Returns ​

The extension instance

<T>(identifier, options?) => T

getOptional ​
Get Signature ​

get getOptional(): <T>(identifier, options?) => T | null

Optional get an extension instance from the store. The major difference between get and getOptional is that getOptional will not throw an error if the extension is not found.

Example ​
ts
const extension = store.getOptional(SomeExtension);
Returns ​

The extension instance

<T>(identifier, options?) => T | null

provider ​
Get Signature ​

get provider(): ServiceProvider

Get the di provider for current store.

Returns ​

ServiceProvider

History ​

canRedo ​
Get Signature ​

get canRedo(): boolean

Check if the store can redo

Returns ​

boolean

canUndo ​
Get Signature ​

get canUndo(): boolean

Check if the store can undo

Returns ​

boolean

history ​
Get Signature ​

get history(): HistoryExtension

Get the Y.UndoManager instance for current store.

Returns ​

HistoryExtension

captureSync() ​

captureSync(): void

Force the following history to be captured into a new stack.

Returns ​

void

Example ​
ts
op1();
op2();
store.captureSync();
op3();

store.undo(); // undo op3
store.undo(); // undo op1, op2
redo() ​

redo(): void

Redo the last undone transaction.

Returns ​

void

resetHistory() ​

resetHistory(): void

Reset the history of the store.

Returns ​

void

transact() ​

transact(fn, shouldTransact?): void

Execute a transaction.

Parameters ​
fn ​

() => void

shouldTransact? ​

boolean = ...

Returns ​

void

Example ​
ts
store.transact(() => {
  op1();
  op2();
});
undo() ​

undo(): void

Undo the last transaction.

Returns ​

void

withoutTransact() ​

withoutTransact(fn): void

Execute a transaction without capturing the history.

Parameters ​
fn ​

() => void

Returns ​

void

Example ​
ts
store.withoutTransact(() => {
  op1();
  op2();
});

Other ​

awarenessStore ​
Get Signature ​

get awarenessStore(): AwarenessStore

Get the AwarenessStore instance for current store

Returns ​

AwarenessStore

blobSync ​
Get Signature ​

get blobSync(): BlobEngine

Get the BlobEngine instance for current store.

Returns ​

BlobEngine

doc ​
Get Signature ​

get doc(): Doc

Get the Doc instance for current store.

Returns ​

Doc

schema ​
Get Signature ​

get schema(): Schema

Get the Schema instance of the store.

Returns ​

Schema

workspace ​
Get Signature ​

get workspace(): Workspace

Get the Workspace instance for current store.

Returns ​

Workspace

Store Lifecycle ​

disposableGroup ​

disposableGroup: DisposableGroup

Group of disposable resources managed by the store

slots ​

readonly slots: StoreSlots

Slots for receiving events from the store. All events are rxjs Subjects, you can subscribe to them like this:

ts
store.slots.ready.subscribe(() => {
  console.log('store is ready');
});

You can also use rxjs operators to handle the events.

id ​
Get Signature ​

get id(): string

Get the id of the store.

Returns ​

string

loaded ​
Get Signature ​

get loaded(): boolean

Check if the store is loaded.

Returns ​

boolean

ready ​
Get Signature ​

get ready(): boolean

Check if the store is ready. Which means the Y.Doc is loaded and the root block is added.

Returns ​

boolean

dispose() ​

dispose(): void

Disposes the store and releases all resources

Returns ​

void

load() ​

load(initFn?): Store

Initializes and loads the store

Parameters ​
initFn? ​

() => void

Optional initialization function

Returns ​

Store

The store instance

Transformer ​

getTransformer() ​

getTransformer(middlewares?): Transformer

Creates a new transformer instance for the store

Parameters ​
middlewares? ​

TransformerMiddleware[] = []

Optional array of transformer middlewares

Returns ​

Transformer

A new Transformer instance


StoreSlots ​

Slots for receiving events from the store. All events are rxjs Subjects, you can subscribe to them like this:

ts
store.slots.ready.subscribe(() => {
  console.log('store is ready');
});

You can also use rxjs operators to handle the events.

Properties ​

blockUpdated ​

blockUpdated: Subject<StoreBlockUpdatedPayloads>

This fires when a block is updated via API call or has just been updated from existing ydoc.

The payload can have three types:

  • add: When a new block is added
  • delete: When a block is removed
  • update: When a block's properties are modified
ready ​

ready: Subject<void>

This fires after doc.load is called. The Y.Doc is fully loaded and ready to use.

rootAdded ​

rootAdded: Subject<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: Subject<string>

This fires when the root block is deleted via API call or has just been removed from existing ydoc. In most cases, you don't need to subscribe to this event.