Headless BlockNote Editor
Props, options, features, link target types, events and exposed methods of the BlocknoteEditor Vue component.
Reference
The BlocknoteEditor Vue component of the @xwiki/platform-editors-blocknote-headless package renders a BlockNote editor for XWiki content. It wraps the React editor of the @xwiki/platform-editors-blocknote-react package. To use it in your own component, see Integrate BlockNote Headless in a Vue Component.
XWiki 18.10.0+ The editor instance is configured with a single options object: the options of each editor feature are grouped under features, and the services the editor needs are taken from the service container instead of being passed as callbacks. (XWiki <18.10.0 The editor was configured with the editorProps, macros, editorContent, collaboration and depsContainer properties.)
BlocknoteEditor
Props
type Props = {
/** The configuration of the editor instance */
options: HeadlessEditorOptions;
/** Content to initialize the editor with */
content: BlockType[];
};Editor Options
HeadlessEditorOptions are the options of the editor (EditorOptions, exported by @xwiki/platform-editors-blocknote-react), plus the options of the link modal shown by the Vue component.
type HeadlessEditorOptions = Omit<EditorOptions, "features"> & {
features?: EditorFeatures & {
links?: HeadlessLinkFeatureOptions | false;
};
};
type HeadlessLinkFeatureOptions = {
/**
* The link target types that the link modal doesn't offer for new links, while still using them to edit the links
* they handle. Unknown types are ignored.
*/
excludedTargetTypes?: string[];
};
type EditorOptions = {
/** The Inversify container the editor takes the services and components it needs from. */
serviceContainer: Container;
/**
* The name of the editor instance, usually the name of the form field it is attached to. When editing in realtime,
* the editor instances with the same name, in the same collaboration session, edit the same content. Realtime
* collaboration is disabled without a name.
*/
name?: string;
/**
* The reference of the document holding the edited content: the files are uploaded to it, and the references of the
* linked pages, attachments and images are relative to it. The current document (as provided by the
* `DocumentService`) when not specified.
*/
sourceDocumentReference?: DocumentReference;
/**
* The id of the syntax of the edited content (e.g. "xwiki/2.1"). Its configuration, looked up in the service
* container, determines the editor features that are available. The minimal syntax, which disables most editor
* features, is used when the syntax has no configuration.
*/
syntax: string;
/** The language of the editor UI (menus, toolbars, placeholders). */
lang: EditorLanguage;
/** The accessible name of the editing area (its `aria-label`). */
label: string;
/** Whether to focus the editor, with the caret at the start of the content, as soon as it is created. */
autofocus?: boolean;
appearance?: {
/**
* The display theme of the editor UI. It follows the color scheme preferred by the user when not specified.
*/
theme?: "light" | "dark";
/** Who styles the edited content: the editor (the default), or the page hosting the editor. */
contentStyles?: "editor" | "host";
};
/** The realtime collaboration session to join. Ignored when the editor instance has no name. */
collaboration?: Collaboration;
/**
* Whether the user can upload files to the source document (by pasting or dropping them, or with the upload
* actions). Enabled by default, as long as there's something to store the files with.
*/
upload?: boolean;
/**
* Where to keep the data about the blocks of the edited content that isn't part of the content (e.g. the output of
* the macros). A store is created for the editor instance when not specified.
*/
metadata?: BlockMetadataStore;
/** The options of each editor feature. */
features?: EditorFeatures;
};Editor Features
The options of each editor feature are keyed by the feature id. A feature is enabled when its options are missing, and setting them to false disables it.
interface EditorFeatures {
/** The CSS classes (space separated) to add to the code blocks. */
codeBlocks?: { className?: string } | false;
/** The image suggestions, the image toolbar and the image panel. */
images?: false;
/** The actions to insert and edit links. The options are those of the link editor (see HeadlessLinkFeatureOptions). */
links?: object | false;
/** The macros, with the list of client-rendered macros, if any. */
macros?: { list?: MacroWithUnknownParamsType[] } | false;
/** The subscript and superscript text styles (when the syntax supports them). */
textStyles?: false;
/**
* The block types and text styles produced by the XWiki rendering (definition list items, groups, raw content,
* verbatim text, XWiki parameters), when the xwikiRenderingFeature is bound.
*/
xwikiRendering?: false;
}The features are bound in the service container. The editor has no feature of its own: call the ComponentInit of @xwiki/platform-editors-blocknote-react to bind the generic ones (file transfer, code blocks, text styles, images, links and macros). It binds them in the order they contribute in (e.g. to the formatting toolbar). To bind only some of them, or in another order, bind the exported features yourself (fileTransferFeature, codeBlocksFeature, textStylesFeature, imagesFeature, linksFeature, macrosFeature). The xwikiRenderingFeature isn't bound by ComponentInit: bind it when the content comes from the XWiki rendering.
import {
ComponentInit as BlockNoteReactComponentInit,
editorFeatureName,
xwikiRenderingFeature,
} from "@xwiki/platform-editors-blocknote-react";
import { Container } from "inversify";
import type { EditorFeature } from "@xwiki/platform-editors-blocknote-react";
const container = new Container();
new BlockNoteReactComponentInit(container);
container
.bind<EditorFeature>(editorFeatureName)
.toConstantValue(xwikiRenderingFeature);Link Target Types
XWiki 18.10.0+ The link modal offers one link type per link target type bound in the service container, except those listed in features.links.excludedTargetTypes, sorted by their order. A link target type converts the links of one kind between their URL (used by the editor), their resource reference (used when the content is saved) and the configuration edited in the link modal. Its form, the fields edited in the link modal, is bound separately, so that the link target type doesn't depend on Vue. A link target type without a form is edited with a single text field, and its configuration is then a PlainTextLinkTargetConfig ({ location: string }).
| Package | Binds |
|---|---|
| @xwiki/platform-link-type-api | The LinkTargetTypeManager the link modal and the editor use to find the link target types. Always required. |
| @xwiki/platform-link-type-default | The built-in link target types: page (order 0), attachment (100), email (200), path (300), unc (400) and url, last since it accepts any URL. To offer fewer of them while still editing the existing links of those types, list them in excludedTargetTypes. To drop them entirely, skip its ComponentInit and bind the types you want yourself. |
| @xwiki/platform-link-type-ui | The forms of the page, attachment, email and url types. |
A link target type implements LinkTargetType (@xwiki/platform-link-type-api), bound to linkTargetTypeRole without a name; the link target types are told apart by their type:
interface LinkTargetType<TConfig = unknown> {
/** Identifies the link target type. */
readonly type: string;
/** Sorts the link type selector, and the link target types asked to parse a URL (lower first). Defaults to 1000. */
readonly order?: number;
/** The label of the link type selector entry, translated by the link target type itself. */
getLabel(locale: string): Promise<string>;
/** The configuration used when the user selects this link type. */
createDefaultConfig(): TConfig;
/** The configuration of the link with the given URL, or null when the URL isn't of this type. */
fromURL(url: string): TConfig | null;
toURL(config: TConfig, context?: LinkContext): string;
/** The text of a link left without display text. The URL of the link when not implemented. */
getDefaultLabel?(config: TConfig, context?: LinkContext): string;
/** The configuration of the link with the given reference, or null when the reference isn't of this type. */
fromReference?(reference: ResourceReference, context?: LinkContext): TConfig | null;
/** The reference of the link, or undefined when the configuration doesn't designate a target yet. */
toReference?(config: TConfig, context?: LinkContext): ResourceReference | undefined;
}The context gives the document holding the link (sourceDocument), against which relative references are resolved. When no link target type accepts the reference of an edited link, the link modal edits it as is, under its resource type.
The form implements LinkTargetTypeForm (@xwiki/platform-link-modal-ui), bound to linkTargetTypeFormRole without a name, with the type of its link target type. targetField() returns the Vue component of the field designating the target, optionFields() (optional) the one of the fields shown in the "Options" group. Both receive the configuration with v-model and the service container as the depsContainer prop; the target field also receives the autofocus and linkContext props. Each component must declare these props even when it doesn't use them.
For example, a link type for the issues of an issue tracker, edited with a single text field (no form) holding the issue key, and saved as a URL:
import { linkTargetTypeRole } from "@xwiki/platform-link-type-api";
import { injectable } from "inversify";
import type { LinkTargetType, PlainTextLinkTargetConfig } from "@xwiki/platform-link-type-api";
import type { ResourceReference } from "@xwiki/platform-rendering-api";
import type { Container } from "inversify";
const ISSUE_URL = "https://issues.example.org/browse/";
@injectable()
class IssueLinkTargetType implements LinkTargetType<PlainTextLinkTargetConfig> {
readonly type = "issue";
// Before the URL link target type, which accepts any URL.
readonly order = 250;
async getLabel(): Promise<string> {
return "Issue";
}
createDefaultConfig(): PlainTextLinkTargetConfig {
return { location: "" };
}
fromURL(url: string): PlainTextLinkTargetConfig | null {
return url.startsWith(ISSUE_URL) ? { location: url.substring(ISSUE_URL.length) } : null;
}
toURL({ location }: PlainTextLinkTargetConfig): string {
return ISSUE_URL + location.trim();
}
getDefaultLabel({ location }: PlainTextLinkTargetConfig): string {
return location.trim();
}
fromReference(reference: ResourceReference): PlainTextLinkTargetConfig | null {
return reference.type === "url" ? this.fromURL(reference.reference) : null;
}
toReference(config: PlainTextLinkTargetConfig): ResourceReference | undefined {
return config.location.trim() === ""
? undefined
: { type: "url", typed: false, reference: this.toURL(config), parameters: {} };
}
}
export function bindIssueLinkTargetType(container: Container): void {
container.bind<LinkTargetType>(linkTargetTypeRole).to(IssueLinkTargetType);
}The link target types are bound in the service container of the editor: an extension installed in XWiki can't add one to the BlockNote editor of XWiki, whose container is internal to its WebJar.
Vue Events
{
// Emitted as soon as the editor's content changes, whoever caused the change: the local user, the initial content
// being loaded, or another participant of the realtime session.
"instant-change": [];
// Emitted in the same context as "instant-change", but debounced
"debounced-change": [content: BlockType[]];
// The subset of "instant-change" caused by the local user: emitted neither when the editor is filled with its
// initial content, nor when the content changes because of another participant of the realtime session.
"local-instant-change": [];
}Vue Expose
{
// Get the editor's content
getContent(): BlockType[];
// Get the editor instance, or nothing before the editor is mounted
getEditor(): EditorType | undefined;
}More
To find more about the current topic, you can search or use the table below and filter the columns to narrow your choices.