BlockSuite API Documentation / @blocksuite/affine-block-embed-doc
@blocksuite/affine-block-embed-doc
Classes
Extension
EdgelessClipboardEmbedLinkedDocConfig
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
interface FruitProcessor {
process(fruit: Fruit): void;
}
interface Fruit {
type: string;
// other properties
}Step 2: Create a service identifier
import { createIdentifier } from '@blocksuite/global/di';
const FruitProcessorProvider = createIdentifier<FruitProcessor>('fruit-processor-provider');Step 3: Create implementations
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
const FruitProcessorExtension = (
fruitType: string,
implementation: new () => FruitProcessor
): ExtensionType => {
return {
setup: di => {
di.addImpl(FruitProcessorProvider(fruitType), implementation);
}
};
};Step 5: Create concrete extensions
export const AppleProcessorExtension = FruitProcessorExtension('apple', AppleProcessor);
export const BananaProcessorExtension = FruitProcessorExtension('banana', BananaProcessor);Step 6: Use the extensions
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 bananaNote: 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
key
readonlystatickey:"affine:embed-linked-doc"='affine:embed-linked-doc'
Overrides
Accessors
Methods
createBlock()
createBlock(
linkedDocEmbed):string|null
Parameters
linkedDocEmbed
Returns
string | null
Overrides
EdgelessClipboardConfig.createBlock
EdgelessClipboardEmbedSyncedDocConfig
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
interface FruitProcessor {
process(fruit: Fruit): void;
}
interface Fruit {
type: string;
// other properties
}Step 2: Create a service identifier
import { createIdentifier } from '@blocksuite/global/di';
const FruitProcessorProvider = createIdentifier<FruitProcessor>('fruit-processor-provider');Step 3: Create implementations
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
const FruitProcessorExtension = (
fruitType: string,
implementation: new () => FruitProcessor
): ExtensionType => {
return {
setup: di => {
di.addImpl(FruitProcessorProvider(fruitType), implementation);
}
};
};Step 5: Create concrete extensions
export const AppleProcessorExtension = FruitProcessorExtension('apple', AppleProcessor);
export const BananaProcessorExtension = FruitProcessorExtension('banana', BananaProcessor);Step 6: Use the extensions
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 bananaNote: 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
key
readonlystatickey:"affine:embed-synced-doc"='affine:embed-synced-doc'
Overrides
Accessors
Methods
createBlock()
createBlock(
syncedDocEmbed):string|null
Parameters
syncedDocEmbed
Returns
string | null
Overrides
EdgelessClipboardConfig.createBlock
Other
EmbedEdgelessLinkedDocBlockComponent
Extends
EmbedLinkedDocBlockComponent<this> &GfxBlockComponent<GfxBlockElementModel<GfxCompatibleProps>,BlockService,string,this>
Constructors
Other
_handleClick()
protected_handleClick(evt):void
Parameters
evt
MouseEvent
Returns
void
Overrides
toEdgelessEmbedBlock( EmbedLinkedDocBlockComponent )._handleClick
convertToEmbed()
convertToEmbed():
void
Returns
void
Overrides
toEdgelessEmbedBlock( EmbedLinkedDocBlockComponent ).convertToEmbed
attributes
controllers
dev-mode
properties
rendering
styles
updates
EmbedLinkedDocBlockComponent
Extends
Constructors
Other
_cardStyle
_cardStyle:
"list"|"citation"|"horizontal"|"horizontalThin"|"vertical"|"cube"='horizontal'
Overrides
EmbedBlockComponent._cardStyle
icon$
icon$:
ReadonlySignal<TemplateResult>
referenceInfo$
referenceInfo$:
ReadonlySignal<{description?:string;pageId:string;params?: {blockIds?:string[];commentId?:string;databaseId?:string;databaseRowId?:string;elementIds?:string[];mode?:"edgeless"|"page";xywh?:`[${number},${number},${number},${number}]`; };title?:string; }>
title$
title$:
ReadonlySignal<ReadonlySignal<string>>
styles
staticstyles:CSSResult
Overrides
EmbedBlockComponent.styles
citationService
Get Signature
get citationService():
CitationViewService
Returns
CitationViewService
docTitle
Get Signature
get docTitle():
string
Returns
string
editorMode
Get Signature
get editorMode():
DocMode
Returns
isBannerEmpty
isCitation
Get Signature
get isCitation():
boolean
Returns
boolean
isError
isNoteContentEmpty
linkedDoc
Get Signature
get linkedDoc():
Store|undefined
Returns
Store | undefined
noteContainer
readonly
Get Signature
get readonly():
boolean
Returns
boolean
_handleClick()
protected_handleClick(event):void
Parameters
event
MouseEvent
Returns
void
connectedCallback()
connectedCallback():
void
Returns
void
Overrides
EmbedBlockComponent.connectedCallback
convertToEmbed()
convertToEmbed():
void
Returns
void
convertToInline()
convertToInline():
void
Returns
void
getInitialState()
getInitialState():
object
Returns
object
isBannerEmpty?
optionalisBannerEmpty:boolean
isError?
optionalisError:boolean
isNoteContentEmpty?
optionalisNoteContentEmpty:boolean
loading?
optionalloading:boolean
open()
open(
__namedParameters):void
Parameters
__namedParameters
event?
MouseEvent
openMode?
OpenDocMode
Returns
void
refreshData()
refreshData():
void
Returns
void
renderBlock()
renderBlock():
TemplateResult<1>
Returns
TemplateResult<1>
Overrides
EmbedBlockComponent.renderBlock
attributes
controllers
dev-mode
properties
rendering
styles
updates
updated()
updated():
void
Invoked whenever the element is updated. Implement to perform post-updating tasks via DOM APIs, for example, focusing an element.
Setting properties inside this method will trigger the element to update again after this update cycle completes.
Returns
void
Overrides
EmbedBlockComponent.updated
EmbedEdgelessSyncedDocBlockComponent
Extends
EmbedSyncedDocBlockComponent<this> &GfxBlockComponent<GfxBlockElementModel<GfxCompatibleProps>,BlockService,string,this>
Constructors
Other
contentElement
headerWrapper
useCaptionEditor
Overrides
toEdgelessEmbedBlock( EmbedSyncedDocBlockComponent ).useCaptionEditor
_renderSyncedView()
protected_renderSyncedView():TemplateResult<1>
Returns
TemplateResult<1>
Overrides
toEdgelessEmbedBlock( EmbedSyncedDocBlockComponent )._renderSyncedView
convertToCard()
convertToCard(
aliasInfo?):void
Parameters
aliasInfo?
description?
string
title?
string
Returns
void
Overrides
toEdgelessEmbedBlock( EmbedSyncedDocBlockComponent ).convertToCard
renderGfxBlock()
renderGfxBlock():
unknown
Returns
unknown
Overrides
toEdgelessEmbedBlock( EmbedSyncedDocBlockComponent ).renderGfxBlock
attributes
controllers
dev-mode
properties
rendering
styles
updates
EmbedSyncedDocBlockComponent
Extends
Constructors
Other
cardStyleMap
protectedcardStyleMap:DirectiveResult<typeofStyleMapDirective>
embedContainerStyle
protectedembedContainerStyle:StyleInfo
The style of the embed card. You can use this to change the height and width of the card. By default, the height and width are set to _cardHeight and _cardWidth respectively.
Overrides
EmbedBlockComponent.embedContainerStyle
icon$
icon$:
ReadonlySignal<TemplateResult>
title$
title$:
ReadonlySignal<ReadonlySignal<string>>
styles
staticstyles:CSSResult=blockStyles
Overrides
EmbedBlockComponent.styles
_isEmptySyncedDoc
blockState
Get Signature
get blockState():
object
Returns
object
isCycle
isCycle:
boolean
isDeleted
isDeleted:
boolean
isError
isError:
boolean
isLoading
isLoading:
boolean
depth
docTitle
Get Signature
get docTitle():
string
Returns
string
docUpdatedAt
Get Signature
get docUpdatedAt():
Date
Returns
Date
editorMode
Get Signature
get editorMode():
DocMode
Returns
isPageMode
Get Signature
get
protectedisPageMode():boolean
Returns
boolean
linkedMode
Get Signature
get linkedMode():
"edgeless"|"page"|undefined
Returns
"edgeless" | "page" | undefined
referenceInfo
Get Signature
get referenceInfo():
object
Returns
object
description?
optionaldescription:string
pageId
pageId:
string
params?
optionalparams:object
params.blockIds?
optionalparams.blockIds:string[]
params.commentId?
optionalparams.commentId:string
params.databaseId?
optionalparams.databaseId:string
params.databaseRowId?
optionalparams.databaseRowId:string
params.elementIds?
optionalparams.elementIds:string[]
params.mode?
optionalparams.mode:"edgeless"|"page"
params.xywh?
optionalparams.xywh:`[${number},${number},${number},${number}]`
title?
optionaltitle:string
syncedDoc
Get Signature
get syncedDoc():
Store|null
Returns
Store | null
syncedDocCard
syncedDocEditorHost
syncedDocMode
useCaptionEditor
Overrides
EmbedBlockComponent.useCaptionEditor
_buildPreviewSpec()
protected_buildPreviewSpec(name):ExtensionType[]
Parameters
name
"preview-page" | "preview-edgeless"
Returns
_handleClick()
protected_handleClick(_event):void
Parameters
_event
MouseEvent
Returns
void
_renderSyncedView()
protected_renderSyncedView():TemplateResult<1>
Returns
TemplateResult<1>
connectedCallback()
connectedCallback():
void
Returns
void
Overrides
EmbedBlockComponent.connectedCallback
convertToCard()
convertToCard(
aliasInfo?):void
Parameters
aliasInfo?
description?
string
title?
string
Returns
void
convertToInline()
convertToInline():
void
Returns
void
open()
open(
event?):void
Parameters
event?
Partial<DocLinkClickedEvent>
Returns
void
refreshData()
refreshData():
void
Returns
void
renderBlock()
renderBlock():
TemplateResult<1>
Returns
TemplateResult<1>
Overrides
EmbedBlockComponent.renderBlock
attributes
controllers
dev-mode
properties
rendering
styles
updates
firstUpdated()
firstUpdated():
void
Invoked when the element is first updated. Implement to perform one time work on the element after update.
firstUpdated() {
this.renderRoot.getElementById('my-text-area').focus();
}Setting properties inside this method will trigger the element to update again after this update cycle completes.
Returns
void
Overrides
EmbedBlockComponent.firstUpdated
updated()
updated(
changedProperties):void
Invoked whenever the element is updated. Implement to perform post-updating tasks via DOM APIs, for example, focusing an element.
Setting properties inside this method will trigger the element to update again after this update cycle completes.
Parameters
changedProperties
PropertyValueMap<any> | Map<PropertyKey, unknown>
Returns
void
Overrides
EmbedBlockComponent.updated
Type Aliases
EmbedSyncedDocConfig
EmbedSyncedDocConfig =
object
Properties
edgelessHeader()
edgelessHeader: (
context) =>TemplateResult
Parameters
context
model
std
Returns
TemplateResult
InsertedLinkType
InsertedLinkType = {
flavour:LinkableFlavour; } |null
LinkableFlavour
LinkableFlavour =
"affine:bookmark"|"affine:embed-linked-doc"|"affine:embed-synced-doc"|"affine:embed-iframe"|"affine:embed-figma"|"affine:embed-github"|"affine:embed-loom"|"affine:embed-youtube"
Variables
embedLinkedDocBlockHtmlAdapterMatcher
constembedLinkedDocBlockHtmlAdapterMatcher:BlockHtmlAdapterMatcher
embedLinkedDocBlockMarkdownAdapterMatcher
constembedLinkedDocBlockMarkdownAdapterMatcher:BlockMarkdownAdapterMatcher
EmbedLinkedDocBlockPlainTextAdapterExtension
constEmbedLinkedDocBlockPlainTextAdapterExtension:ExtensionType&object
Type Declaration
identifier
identifier:
ServiceIdentifier<BlockPlainTextAdapterMatcher>
embedLinkedDocBlockPlainTextAdapterMatcher
constembedLinkedDocBlockPlainTextAdapterMatcher:BlockPlainTextAdapterMatcher
EmbedLinkedDocHtmlAdapterExtension
constEmbedLinkedDocHtmlAdapterExtension:ExtensionType&object
Type Declaration
identifier
identifier:
ServiceIdentifier<BlockHtmlAdapterMatcher>
EmbedLinkedDocInteraction
constEmbedLinkedDocInteraction:ExtensionType
EmbedLinkedDocMarkdownAdapterExtension
constEmbedLinkedDocMarkdownAdapterExtension:ExtensionType&object
Type Declaration
identifier
identifier:
ServiceIdentifier<BlockMarkdownAdapterMatcher>
EmbedLinkedDocViewExtensions
constEmbedLinkedDocViewExtensions:ExtensionType[]
EmbedSyncedDocBlockHtmlAdapterExtension
constEmbedSyncedDocBlockHtmlAdapterExtension:ExtensionType&object
Type Declaration
identifier
identifier:
ServiceIdentifier<BlockHtmlAdapterMatcher>
embedSyncedDocBlockHtmlAdapterMatcher
constembedSyncedDocBlockHtmlAdapterMatcher:BlockHtmlAdapterMatcher
embedSyncedDocBlockMarkdownAdapterMatcher
constembedSyncedDocBlockMarkdownAdapterMatcher:BlockMarkdownAdapterMatcher
EmbedSyncedDocBlockPlainTextAdapterExtension
constEmbedSyncedDocBlockPlainTextAdapterExtension:ExtensionType&object
Type Declaration
identifier
identifier:
ServiceIdentifier<BlockPlainTextAdapterMatcher>
embedSyncedDocBlockPlainTextAdapterMatcher
constembedSyncedDocBlockPlainTextAdapterMatcher:BlockPlainTextAdapterMatcher
EmbedSyncedDocConfigExtension
constEmbedSyncedDocConfigExtension:ConfigFactory<EmbedSyncedDocConfig>
EmbedSyncedDocMarkdownAdapterExtension
constEmbedSyncedDocMarkdownAdapterExtension:ExtensionType&object
Type Declaration
identifier
identifier:
ServiceIdentifier<BlockMarkdownAdapterMatcher>
EmbedSyncedDocViewExtensions
constEmbedSyncedDocViewExtensions:ExtensionType[]
insertEmbedLinkedDocCommand
constinsertEmbedLinkedDocCommand:Command<{docId:string;params?:ReferenceParams; }, {blockId:string; }>
insertEmbedSyncedDocCommand
constinsertEmbedSyncedDocCommand:Command<{docId:string;params?:ReferenceParams; }, {blockId:string; }>
LinkedDocSlashMenuConfigIdentifier
constLinkedDocSlashMenuConfigIdentifier:ServiceIdentifier<SlashMenuConfig>
SYNCED_MIN_HEIGHT
constSYNCED_MIN_HEIGHT:48=48
SYNCED_MIN_WIDTH
constSYNCED_MIN_WIDTH:370=370
Functions
getEmbedLinkedDocIcons()
getEmbedLinkedDocIcons(
theme,editorMode,style):EmbedCardImages
Parameters
theme
editorMode
"edgeless" | "page"
style
"list" | "citation" | "horizontal" | "horizontalThin" | "vertical" | "cube"
Returns
EmbedCardImages