Integrate BlockNote Headless in a Vue Component
Last modified by Vincent Massol on 2026/11/30 17:29
A BlockNote editor for XWiki content can run inside your own Vue component, taking its features from a service container.
Steps
- XWiki 18.10.0+ Add @xwiki/platform-editors-blocknote-headless, @xwiki/platform-editors-blocknote-react, @xwiki/platform-link-type-api, @xwiki/platform-link-type-default, @xwiki/platform-link-type-ui, @xwiki/platform-xwiki-syntax-config, @xwiki/platform-minimal-syntax-config and inversify to the dependencies of your package.
- Create, in a module of its own, the service container the BlocknoteEditor Vue component takes its services and features from:
// editorContainer.ts import { ComponentInit as BlockNoteReactComponentInit } from "@xwiki/platform-editors-blocknote-react"; import { ComponentInit as LinkTypeComponentInit } from "@xwiki/platform-link-type-api"; import { ComponentInit as LinkTypeDefaultComponentInit } from "@xwiki/platform-link-type-default"; import { ComponentInit as LinkTypeUIComponentInit } from "@xwiki/platform-link-type-ui"; import { ComponentInit as MinimalSyntaxConfig } from "@xwiki/platform-minimal-syntax-config"; import { ComponentInit as XWikiSyntaxConfig } from "@xwiki/platform-xwiki-syntax-config"; import { Container } from "inversify"; const container = new Container(); // The configurations of the syntaxes the editor can edit. The editor falls back to the minimal syntax. new MinimalSyntaxConfig(container); new XWikiSyntaxConfig(container); // Bind here the other services the editor uses, e.g. the RemoteURLSerializerProvider needed by the macros. // The link types offered by the link modal, and their forms. new LinkTypeComponentInit(container); new LinkTypeDefaultComponentInit(container); new LinkTypeUIComponentInit(container); // The editor features (code blocks, images, links, macros, ...). new BlockNoteReactComponentInit(container); export { container };The container of the BlockNote WebJar binds all the services of an XWiki integration.
- Render the BlocknoteEditor component, passing the editor options and the initial content:
<script setup lang="ts"> import { container } from "./editorContainer"; import { BlocknoteEditor } from "@xwiki/platform-editors-blocknote-headless"; import type { HeadlessEditorOptions } from "@xwiki/platform-editors-blocknote-headless"; import type { BlockType } from "@xwiki/platform-editors-blocknote-react"; const options: HeadlessEditorOptions = { serviceContainer: container, name: "content", syntax: "xwiki/2.1", lang: "en", label: "Content", features: { codeBlocks: { className: "box code" }, }, }; const content: BlockType[] = [ { id: "1", type: "paragraph", props: { textAlignment: "left", textColor: "default", backgroundColor: "default", }, content: [{ type: "text", text: "Hello world!", styles: { bold: true } }], children: [], }, ]; function onChange(content: BlockType[]) { console.log(content); } </script> <template> <BlocknoteEditor :options="options" :content="content" @debounced-change="onChange" /> </template>See the editor features for the options of each feature. See the link target types to change the link types offered by the link modal.
- Edit the content: the editor shows the initial content, and the debounced-change event gives the edited content once the user stops typing:
[{ id: "1", type: "paragraph", content: [{ type: "text", text: "Hello world!", styles: { bold: true } }], ... }]