Skip to content

BlockSuite API Documentation / @blocksuite/affine-block-list

@blocksuite/affine-block-list ​

Classes ​

Extension ​

ListLayoutHandlerExtension ​

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.

Extends ​
Constructors ​
Properties ​
blockType ​

readonly blockType: "affine:list" = 'affine:list'

Overrides ​

BlockLayoutHandlerExtension.blockType

Methods ​
calculateBound() ​

calculateBound(layout): object

Parameters ​
layout ​

ListLayout

Returns ​

object

rect ​

rect: Rect

subRects ​

subRects: Rect[]

Overrides ​

BlockLayoutHandlerExtension.calculateBound

queryLayout() ​

queryLayout(model, host, viewportRecord): ListLayout | null

Parameters ​
model ​

BlockModel

host ​

EditorHost

viewportRecord ​

ViewportRecord

Returns ​

ListLayout | null

Overrides ​

BlockLayoutHandlerExtension.queryLayout

setup() ​

static setup(di): void

Parameters ​
di ​

Container

Returns ​

void

Overrides ​

BlockLayoutHandlerExtension.setup

Other ​

ListBlockComponent ​

Extends ​
Constructors ​
Other ​
styles ​

static styles: CSSResult = listBlockStyles

Overrides ​

CaptionedBlockComponent.styles

attributeRenderer ​
Get Signature ​

get attributeRenderer(): AttributeRenderer<AffineTextAttributes>

Returns ​

AttributeRenderer<AffineTextAttributes>

attributesSchema ​
Get Signature ​

get attributesSchema(): ZodType<any, ZodTypeDef, any>

Returns ​

ZodType<any, ZodTypeDef, any>

blockContainerStyles ​
Overrides ​

CaptionedBlockComponent.blockContainerStyles

embedChecker ​
Get Signature ​

get embedChecker(): (delta) => boolean

Returns ​

(delta) => boolean

inlineManager ​
Get Signature ​

get inlineManager(): InlineManager<AffineTextAttributes>

Returns ​

InlineManager<AffineTextAttributes>

topContenteditableElement ​
Get Signature ​

get topContenteditableElement(): BlockComponent<BlockModel<object>, BlockService, string> | null

Returns ​

BlockComponent<BlockModel<object>, BlockService, string> | null

Overrides ​

CaptionedBlockComponent.topContenteditableElement

connectedCallback() ​

connectedCallback(): void

Returns ​

void

Overrides ​

CaptionedBlockComponent.connectedCallback

getUpdateComplete() ​

getUpdateComplete(): Promise<boolean>

Returns ​

Promise<boolean>

Overrides ​

CaptionedBlockComponent.getUpdateComplete

renderBlock() ​

renderBlock(): TemplateResult<1>

Returns ​

TemplateResult<1>

Overrides ​

CaptionedBlockComponent.renderBlock

attributes ​
controllers ​
dev-mode ​
lifecycle ​
properties ​
rendering ​
styles ​
updates ​

Interfaces ​

ListLayout ​

Extends ​

Indexable ​

[key: string]: unknown

Properties ​

items ​

items: ListItemLayout[]

type ​

type: "affine:list"

Overrides ​

BlockLayout.type

Variables ​

canDedentListCommand ​

const canDedentListCommand: Command<Partial<Omit<IndentContext, "flavour" | "type">>, { indentContext: IndentContext; }>


canIndentListCommand ​

const canIndentListCommand: Command<Partial<Omit<IndentContext, "type" | "flavour">>, { indentContext: IndentContext; }>


convertToNumberedListCommand ​

const convertToNumberedListCommand: Command<{ id: string; order: number; stopCapturing?: boolean; }, { listConvertedId: string; }>


dedentListCommand ​

const dedentListCommand: Command<{ indentContext: IndentContext; }>


indentListCommand ​

const indentListCommand: Command<{ indentContext: IndentContext; }>


ListBlockHtmlAdapterExtension ​

const ListBlockHtmlAdapterExtension: ExtensionType & object

Type Declaration ​

identifier ​

identifier: ServiceIdentifier<BlockHtmlAdapterMatcher>


listBlockHtmlAdapterMatcher ​

const listBlockHtmlAdapterMatcher: BlockHtmlAdapterMatcher


ListBlockMarkdownAdapterExtension ​

const ListBlockMarkdownAdapterExtension: ExtensionType & object

Type Declaration ​

identifier ​

identifier: ServiceIdentifier<BlockMarkdownAdapterMatcher>


listBlockMarkdownAdapterMatcher ​

const listBlockMarkdownAdapterMatcher: BlockMarkdownAdapterMatcher


ListBlockNotionHtmlAdapterExtension ​

const ListBlockNotionHtmlAdapterExtension: ExtensionType & object

Type Declaration ​

identifier ​

identifier: ServiceIdentifier<BlockNotionHtmlAdapterMatcher>


listBlockNotionHtmlAdapterMatcher ​

const listBlockNotionHtmlAdapterMatcher: BlockNotionHtmlAdapterMatcher


ListBlockPlainTextAdapterExtension ​

const ListBlockPlainTextAdapterExtension: ExtensionType & object

Type Declaration ​

identifier ​

identifier: ServiceIdentifier<BlockPlainTextAdapterMatcher>


listBlockPlainTextAdapterMatcher ​

const listBlockPlainTextAdapterMatcher: BlockPlainTextAdapterMatcher


ListLayoutPainterExtension ​

const ListLayoutPainterExtension: ExtensionType


listToParagraphCommand ​

const listToParagraphCommand: Command<{ id: string; stopCapturing?: boolean; }, { listConvertedId: string; }>


splitListCommand ​

const splitListCommand: Command<{ blockId: string; inlineIndex: number; }>

Functions ​

correctNumberedListsOrderToPrev() ​

correctNumberedListsOrderToPrev(doc, modelOrId, transact?): void

correct target is a numbered list, which is divided into two steps:

  1. check if there is a numbered list before the target list. If so, adjust the order of the target list to the order of the previous list plus 1, otherwise set the order to 1
  2. find continuous lists starting from the target list and keep their order continuous

Parameters ​

doc ​

Store

modelOrId ​

string | BlockModel<object>

transact? ​

boolean = true

Returns ​

void