editorjs-mentions is an Editor.js plugin that enables mention-style autocomplete (similar to JIRA/Confluence).
- Trigger autocomplete with
@(or custom trigger symbols). - Pluggable provider API for mention data.
- Standard mention model:
id: stringdisplayName: stringdescription?: stringimage?: stringlink?: string
- Sample REST server with:
- in-memory demo users
- Active Directory-backed example provider
packages/editorjs-mentions: plugin package (TypeScript)examples/server: sample REST backend (Express + TypeScript)examples/demo: minimal integration example
npm install
npm run buildRun linting:
npm run lintRun tests:
npm test --workspace @editorjs-mentions/pluginRun sample server:
npm run dev:serverRun demo app:
npm run dev:demoimport EditorJS from "@editorjs/editorjs";
import {
EditorJSMentions,
createRestMentionProvider
} from "@editorjs-mentions/plugin";
const editor = new EditorJS({ holder: "editor" });
await editor.isReady;
const mentions = new EditorJSMentions({
holder: "editor",
triggerSymbols: ["@"],
provider: createRestMentionProvider({
endpoint: "http://localhost:3001/api/mentions/users"
})
});
// later:
// mentions.destroy();holder: string | HTMLElement- Editor.js holder element or id.provider- mention source function/object (required).triggerSymbols?: string[]- defaults to["@"].maxResults?: number- defaults to8.minChars?: number- defaults to0.debounceMs?: number- defaults to160.className?: string- custom dropdown class.onSelect?: (item) => void.renderItem?: (item) => string.renderMention?: (args) => void.mentionRenderContext?: unknown.
type MentionItem = {
id: string;
displayName: string;
description?: string;
image?: string;
link?: string;
};Use helper functions to send stable mention IDs to backend and restore output for Editor.js.
import { encodeMentionsInOutput, decodeMentionsInOutput } from "@editorjs-mentions/plugin";
const nativeOutput = await editor.save();
const payloadForServer = encodeMentionsInOutput(nativeOutput);
// later when loading:
const payloadForEditor = decodeMentionsInOutput(payloadForServer);Example serialized paragraph:
{
"type": "paragraph",
"data": {
"text": "@John Doe @Raj Patel",
"entities": [
{
"type": "mention",
"id": "u-1001",
"displayName": "John Doe",
"start": 0,
"end": 9
}
]
}
}const mentions = new EditorJSMentions({
holder: "editor",
provider,
mentionRenderContext: { currentUserId: "u-1002" },
renderMention: ({ item, defaultText, element, context }) => {
const ctx = context as { currentUserId?: string } | undefined;
element.textContent = defaultText;
element.style.fontWeight = ctx?.currentUserId === item.id ? "700" : "400";
}
});
mentions.setMentionRenderContext({ currentUserId: "u-1001" });
mentions.refreshMentionRendering();Use built-in provider factory:
createRestMentionProvider({
endpoint: "http://localhost:3001/api/mentions/users"
});Expected endpoint example:
GET /api/mentions/users?query=jo&trigger=@&limit=8
Response:
{
"items": [
{
"id": "u-1001",
"displayName": "John Doe",
"description": "Engineering",
"image": "https://..."
}
]
}See examples/server/.env.example and set:
AD_ENABLED=trueAD_URLAD_BIND_DNAD_BIND_PASSWORDAD_BASE_DN
When enabled, the server switches to LDAP-backed lookup.
For quick local LDAP testing with Docker, see examples/server/README.md.
Shortcuts:
npm run dev:ldap:upnpm run dev:ldap:down
Only plugin package version needs bumping.
Recommended flow:
- Bump plugin version:
- patch:
npm run version:plugin:patch - minor:
npm run version:plugin:minor - major:
npm run version:plugin:major
- patch:
- Refresh lockfile:
npm install
- Verify:
npm run typecheck --workspace @editorjs-mentions/pluginnpm run build --workspace @editorjs-mentions/plugin
- Commit changed files (
packages/editorjs-mentions/package.json,package-lock.json). - Create tag/release (for GitHub Actions publish workflow).
Notes:
examples/demouses local dependency (file:../../packages/editorjs-mentions) so demo version does not require manual sync.- Root package is private and does not require release version bump.
License: MIT (LICENSE).
- CI build workflow:
.github/workflows/ci.yml - npm publish workflow:
.github/workflows/publish-npm.yml
For npm publish workflow, configure repository secret:
NPM_TOKEN- npm automation token with publish permissions for@editorjs-mentions/plugin.
