Skip to content

BlockSuite API Documentation / @blocksuite/affine-widget-linked-doc

@blocksuite/affine-widget-linked-doc

Classes

AffineLinkedDocWidget

Extends

Constructors

Other

config
Get Signature

get config(): LinkedWidgetConfig

Returns

LinkedWidgetConfig

connectedCallback()

connectedCallback(): void

Invoked when the component is added to the document's DOM.

In connectedCallback() you should setup tasks that should only occur when the element is connected to the document. The most common of these is adding event listeners to nodes external to the element, like a keydown event handler added to the window.

ts
connectedCallback() {
  super.connectedCallback();
  addEventListener('keydown', this._handleKeydown);
}

Typically, anything done in connectedCallback() should be undone when the element is disconnected, in disconnectedCallback().

Returns

void

Overrides

WidgetComponent.connectedCallback

render()

render(): TemplateResult<1> | typeof nothing

Invoked on each update to perform rendering tasks. This method may return any value renderable by lit-html's ChildPart - typically a TemplateResult. Setting properties inside this method will not trigger the element to update.

Returns

TemplateResult<1> | typeof nothing

Overrides

WidgetComponent.render

show()

show(props?): void

Parameters
props?
addTriggerKey?

boolean

inlineEditor?

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

mode?

"desktop" | "mobile"

primaryTriggerKey?

string

Returns

void

attributes

controllers

dev-mode

lifecycle

properties

rendering

styles

styles

static styles: CSSResult = linkedDocWidgetStyles

Array of styles to apply to the element. The styles should be defined using the css tag function, via constructible stylesheets, or imported from native CSS module scripts.

Note on Content Security Policy:

Element styles are implemented with <style> tags when the browser doesn't support adopted StyleSheets. To use such <style> tags with the style-src CSP directive, the style-src value must either include 'unsafe-inline' or nonce-<base64-value> with <base64-value> replaced be a server-generated nonce.

To provide a nonce to use on generated <style> elements, set window.litNonce to a server-generated nonce in your page's HTML, before loading application code:

html
<script>
  // Generated and unique per request:
  window.litNonce = 'a1b2c3d4';
</script>
Nocollapse
Overrides

WidgetComponent.styles

updates

Type Aliases

LinkedDocContext

LinkedDocContext = object

Properties

close()

close: () => void

Returns

void

config

config: LinkedWidgetConfig

inlineEditor

inlineEditor: AffineInlineEditor

startNativeRange

startNativeRange: Range

startRange

startRange: InlineRange

std

std: BlockStdScope

triggerKey

triggerKey: string


LinkedMenuAction()

LinkedMenuAction = () => Promise<void> | void

Returns

Promise<void> | void


LinkedMenuGroup

LinkedMenuGroup = object

Properties

hidden?

optional hidden: boolean | Signal<boolean>

items

items: LinkedMenuItem[] | Signal<LinkedMenuItem[]>

loading?

optional loading: boolean | Signal<boolean>

maxDisplay?

optional maxDisplay: number

name

name: string

overflowText?

optional overflowText: string | Signal<string>

styles?

optional styles: string


LinkedMenuItem

LinkedMenuItem = object

Properties

action

action: LinkedMenuAction

icon

icon: TemplateResult<1>

key

key: string

name

name: string | TemplateResult<1>

suffix?

optional suffix: string | TemplateResult<1>


LinkedWidgetConfig

LinkedWidgetConfig = Required<Omit<LinkedDocViewExtensionOptions, "autoFocusedItemKey">> & Pick<LinkedDocViewExtensionOptions, "autoFocusedItemKey">

Variables

AFFINE_LINKED_DOC_WIDGET

const AFFINE_LINKED_DOC_WIDGET: "affine-linked-doc-widget" = 'affine-linked-doc-widget'


BearTransformer

const BearTransformer: object

Public API for importing Bear .bear2bk backup archives.

Type Declaration

importBearBackup()

importBearBackup: (__namedParameters) => Promise<BearImportResult>

Import a Bear .bear2bk backup file. Uses JSZip for lazy/streaming decompression to handle large backups.

Parameters
__namedParameters

BearImportOptions

Returns

Promise<BearImportResult>


DocxTransformer

const DocxTransformer: object

Type Declaration

importDocx()

importDocx: (options) => Promise<string | undefined>

Imports a .docx file into a doc.

Parameters
options

ImportDocxOptions

The import options.

Returns

Promise<string | undefined>

A Promise that resolves to the ID of the newly created doc, or undefined if import fails.


HtmlTransformer

const HtmlTransformer: object

Type Declaration

exportDoc()

exportDoc: (doc) => Promise<void>

Exports a doc to HTML format.

Parameters
doc

Store

The doc to be exported.

Returns

Promise<void>

A Promise that resolves when the export is complete.

importHTMLToDoc()

importHTMLToDoc: (options) => Promise<string | undefined>

Imports HTML content into a new doc within a collection.

Parameters
options

ImportHTMLToDocOptions

The import options.

Returns

Promise<string | undefined>

A Promise that resolves to the ID of the newly created doc, or undefined if import fails.

importHTMLZip()

importHTMLZip: (options) => Promise<string[]>

Imports a zip file containing HTML files and assets into a collection.

Parameters
options

ImportHTMLZipOptions

The import options.

Returns

Promise<string[]>

A Promise that resolves to an array of IDs of the newly created docs.


linkedDocWidget

const linkedDocWidget: ExtensionType


LinkedWidgetConfigExtension

const LinkedWidgetConfigExtension: ConfigFactory<Partial<LinkedWidgetConfig>>


LinkedWidgetUtils

const LinkedWidgetUtils: object

Type Declaration

createNewDocMenuGroup()

createNewDocMenuGroup: (query, abort, editorHost, inlineEditor) => LinkedMenuGroup

Parameters
query

string

abort

() => void

editorHost

EditorHost

inlineEditor

AffineInlineEditor

Returns

LinkedMenuGroup

insertLinkedNode()

insertLinkedNode: (__namedParameters) => void

Parameters
__namedParameters
docId

string

inlineEditor

AffineInlineEditor

Returns

void


MarkdownTransformer

const MarkdownTransformer: object

Type Declaration

exportDoc()

exportDoc: (doc) => Promise<void>

Exports a doc to a Markdown file or a zip archive containing Markdown and assets.

Parameters
doc

Store

The doc to export

Returns

Promise<void>

A Promise that resolves when the export is complete

importMarkdownToBlock()

importMarkdownToBlock: (options) => Promise<void>

Imports Markdown content into a specific block within a doc.

Parameters
options

ImportMarkdownToBlockOptions

Object containing import options

Returns

Promise<void>

A Promise that resolves when the import is complete

importMarkdownToDoc()

importMarkdownToDoc: (options) => Promise<string | undefined>

Imports Markdown content into a new doc within a collection.

Parameters
options

ImportMarkdownToDocOptions

Object containing import options

Returns

Promise<string | undefined>

A Promise that resolves to the ID of the newly created doc, or undefined if import fails

importMarkdownZip()

importMarkdownZip: (__namedParameters) => Promise<{ docIds: string[]; folderHierarchy?: FolderHierarchy; }>

Parameters
__namedParameters

ImportMarkdownZipOptions

Returns

Promise<{ docIds: string[]; folderHierarchy?: FolderHierarchy; }>


NotionHtmlTransformer

const NotionHtmlTransformer: object

Type Declaration

importNotionZip()

importNotionZip: (options) => Promise<ImportNotionZipResult>

Imports a Notion zip file into the BlockSuite collection.

Parameters
options

ImportNotionZipOptions

The options for importing.

Returns

Promise<ImportNotionZipResult>

A promise that resolves to an object containing: - entryId: The ID of the entry page (if any). - pageIds: An array of imported page IDs. - isWorkspaceFile: Whether the imported file is a workspace file. - hasMarkdown: Whether the zip contains markdown files. - folderHierarchy: The parsed folder hierarchy from the Notion export.


ObsidianTransformer

const ObsidianTransformer: object

Type Declaration

importObsidianVault()

importObsidianVault: (__namedParameters) => Promise<ImportObsidianVaultResult>

Parameters
__namedParameters

ImportObsidianVaultOptions

Returns

Promise<ImportObsidianVaultResult>


PdfTransformer

const PdfTransformer: object

Type Declaration

exportDoc()

exportDoc: (doc) => Promise<void>

Parameters
doc

Store

Returns

Promise<void>


ZipTransformer

const ZipTransformer: object

Type Declaration

exportDocs()

exportDocs: (collection, schema, docs) => Promise<void>

Parameters
collection

Workspace

schema

Schema

docs

Store[]

Returns

Promise<void>

importDocs()

importDocs: (collection, schema, imported) => Promise<(Store | undefined)[]>

Parameters
collection

Workspace

schema

Schema

imported

Blob

Returns

Promise<(Store | undefined)[]>

Functions

createAssetsArchive()

createAssetsArchive(assetsMap, assetsIds): Promise<Zip>

Parameters

assetsMap

Map<string, Blob>

assetsIds

string[]

Returns

Promise<Zip>


createLinkedDocMenuGroup()

createLinkedDocMenuGroup(query, abort, editorHost, inlineEditor): object

Parameters

query

string

abort

() => void

editorHost

EditorHost

inlineEditor

AffineInlineEditor

Returns

object

items

items: object[]

maxDisplay

maxDisplay: number = MAX_DOCS

name

name: string = 'Link to Doc'

overflowText

overflowText: string


createNewDocMenuGroup()

createNewDocMenuGroup(query, abort, editorHost, inlineEditor): LinkedMenuGroup

Parameters

query

string

abort

() => void

editorHost

EditorHost

inlineEditor

AffineInlineEditor

Returns

LinkedMenuGroup


download()

download(blob, name): void

Parameters

blob

Blob

name

string

Returns

void


getMenus()

getMenus(query, abort, editorHost, inlineEditor): Promise<LinkedMenuGroup[]>

Parameters

query

string

abort

() => void

editorHost

EditorHost

inlineEditor

AffineInlineEditor

Returns

Promise<LinkedMenuGroup[]>


showImportModal()

showImportModal(__namedParameters): ImportDoc

Parameters

__namedParameters
abortController?

AbortController = ...

collection

Workspace

container?

HTMLElement = document.body

extensions

ExtensionType[]

multiple?

boolean

onFail?

OnFailHandler

onSuccess?

OnSuccessHandler

schema

Schema

Returns

ImportDoc