Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:AFK surf Open agent Store AddBlock

From Leeroopedia
Knowledge Sources
Domains BlockSuite, Document_Model
Last Updated 2026-10-25 00:00 GMT

Overview

Concrete API for adding a block of a given flavour into a BlockSuite doc store, used to build the page → surface → note → content tree and database rows.

Description

store.addBlock is the fundamental mutation primitive on a BlockSuite Store. It creates a new block model of the given flavour, applies the supplied props, attaches it under the optional parentId, and returns the new block id. Every structured document in Open-Agent starts with this call: a root affine:page, an affine:surface child, an affine:note container, and then content blocks (paragraphs, lists, databases, code) as children. In the database preset, rows are themselves blocks added as children of an affine:database block.

Usage

Use this whenever you need to insert a block into a live document — page scaffolding, note containers, content paragraphs, list items, database blocks, and database row children. It is the lowest-level building block for document construction and is called by both presets and user-facing commands.

Code Reference

Source Location

  • Repository: Open-Agent
  • File: blocksuite/playground/apps/starter/data/database.ts (L17-44, L70-109); block store API in @blocksuite/affine/store

Signature

store.addBlock(
  flavour: string,
  props?: Record<string, unknown>,
  parentId?: string
): string;

Import

// store is obtained from a doc:
const doc = collection.createDoc(id);
const store = doc.getStore();
// addBlock is a method on the store instance

I/O Contract

Inputs

Name Type Required Description
flavour string Yes Block type, e.g. 'affine:page', 'affine:surface', 'affine:note', 'affine:paragraph', 'affine:list', 'affine:database', 'affine:code'
props Record<string, unknown> Block properties, e.g. { title: Text }, { xywh: '[0,100,800,640]' }, { columns: [], cells: {} }, { type: 'h1', text: Text }
parentId string Parent block id; defaults to the root

Outputs

Name Type Description
blockId string The id of the newly created block; retrieve its model with store.getModelById(id)

Usage Examples

Page + Surface + Note Scaffolding

const rootId = store.addBlock('affine:page', { title: new Text('My Doc') });
store.addBlock('affine:surface', {}, rootId);
const noteId = store.addBlock('affine:note', { xywh: '[0, 100, 800, 640]' }, rootId);

Database Block + Row Children

const databaseId = store.addBlock('affine:database', { columns: [], cells: {} }, noteId);

// Rows are paragraph/list blocks parented to the database:
const rowId = store.addBlock(
  'affine:paragraph',
  { type: 'h1', text: new Text('Row content') },
  databaseId
);

Related Pages

Implements Principle

Requires Environment

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment