Skip to content

BlockSuite API Documentation / @blocksuite/affine-inline-comment

@blocksuite/affine-inline-comment

Classes

InlineCommentManager

A life cycle watcher is an extension that watches the life cycle of the editor. It is used to perform actions when the editor is created, mounted, rendered, or unmounted.

When creating a life cycle watcher, you must define a key that is unique to the watcher. The key is used to identify the watcher in the dependency injection container.

ts
class MyLifeCycleWatcher extends LifeCycleWatcher {
 static override readonly key = 'my-life-cycle-watcher';

In the life cycle watcher, the methods will be called in the following order:

  1. created: Called when the std is created.
  2. rendered: Called when std.render is called.
  3. mounted: Called when the editor host is mounted.
  4. unmounted: Called when the editor host is unmounted.

Extends

Constructors

Properties

key

static key: string = 'inline-comment-manager'

Overrides

LifeCycleWatcher.key

Methods

getCommentsInEditor()

getCommentsInEditor(): string[]

Returns

string[]

mounted()

mounted(): void

Called when editor host is mounted. Which means the editor host emit the connectedCallback lifecycle event.

Returns

void

Overrides

LifeCycleWatcher.mounted

unmounted()

unmounted(): void

Called when editor host is unmounted. Which means the editor host emit the disconnectedCallback lifecycle event.

Returns

void

Overrides

LifeCycleWatcher.unmounted


InlineCommentViewExtension

A specialized extension provider for view-related functionality. Extends the base provider with view-specific scope and configuration.

Example

ts
// Create a view provider with custom options
class MyViewProvider extends ViewExtensionProvider<{ theme: string }> {
  override name = 'MyViewProvider';

  override schema = z.object({
    theme: z.enum(['light', 'dark'])
  });

  override setup(context: ViewExtensionContext, options?: { theme: string }) {
    super.setup(context, options);

    context.register([CommonExt]);
    if (context.scope === 'page') {
      context.register([PageExt]);
    } else if (context.scope === 'edgeless') {
      context.register([EdgelessExt]);
    }
    if (options?.theme === 'dark') {
      context.register([DarkModeExt]);
    }
  }

  // Override effect to run one-time initialization logic
  override effect() {
    // This will only run once per provider class
    console.log('Initializing MyViewProvider');
  }
}

Extends

Constructors

Properties

name

name: string = 'affine-inline-comment'

The name of the view extension provider

Overrides

ViewExtensionProvider.name

schema

schema: ZodObject<{ enabled: ZodDefault<ZodOptional<ZodBoolean>>; }, "strip", ZodTypeAny, { enabled: boolean; }, { enabled?: boolean; }> = optionsSchema

Zod schema for validating provider options

Overrides

ViewExtensionProvider.schema

Methods

effect()

effect(): void

Override this method to implement one-time initialization logic for the provider. This method will be called automatically during setup, but only once per provider class.

Returns

void

Example
ts
override effect() {
  super.effect();
  // Register lit elements
  registerLitElements();
}
Overrides

ViewExtensionProvider.effect

setup()

setup(context, options?): void

Sets up the provider with the given context and options. Validates the options against the schema if provided.

Parameters
context

ViewExtensionContext

The context object containing scope and registration function

options?
enabled

boolean = ...

Returns

void

Overrides

ViewExtensionProvider.setup

Variables

CommentInlineSpecExtension

const CommentInlineSpecExtension: ExtensionType & object

Type Declaration

identifier

identifier: ServiceIdentifier<InlineSpecs<AffineTextAttributes>>


NullCommentInlineSpecExtension

const NullCommentInlineSpecExtension: ExtensionType & object

Type Declaration

identifier

identifier: ServiceIdentifier<InlineSpecs<AffineTextAttributes>>

Functions

extractCommentIdFromDelta()

extractCommentIdFromDelta(delta): string[]

Parameters

delta

DeltaInsert<AffineTextAttributes>

Returns

string[]


findAllCommentedTexts()

findAllCommentedTexts(store): Map<TextSelection, string>

Parameters

store

Store

Returns

Map<TextSelection, string>


findCommentedTexts()

findCommentedTexts(store, commentId): TextSelection[]

Parameters

store

Store

commentId

string

Returns

TextSelection[]