core
This packages provides the core building blocks for the remirror editing experience. It provides the api for extensions and TypeScript types used throughout the other packages.
It should rarely be used independently.
Note that this package itself is framework agnostic and while remirror today is targeted at react users it's possible to widen the scope to angular
, vue
and other popular framework libraries.
Installation
yarn add @remirror/core
Extensions
Extensions are the building blocks of the editing experience in remirror. They provide behaviour, plugins, marks, and nodes as well as configuration at instantiation for any extension.
Create an extension
Extension can be Extension
, MarkExtension
or NodeExtension
.
Extension
Pure extensions only concern themselves with the behaviour of the editor. For example the extension called History
is a pure extension and it simply tracks all the actions and provides undo and redo commands to your configured editor.MarkExtension
These are used to add extra styling or other information to inline content. Marks are used for adding links to content, bold stying, italic and other changes which affect the content in a simple way.NodeExtension
These add make nodes available to the content of the editor. Examples include @remirror/extension-emoji
and @remirror/extension-mention
To create an extension extend from the class provided from the core library. The following example is taken from the Strikethrough extension in the @remirror/core-extensions
library.
import {
MarkExtension,
MarkExtensionSpec,
markInputRule,
markPasteRule,
SchemaMarkTypeParams,
toggleMark,
} from '@remirror/core';
export class Strike extends MarkExtension {
get name(): 'strike' {
return 'strike';
}
get schema(): MarkExtensionSpec {
return {
parseDOM: [
{
tag: 's',
},
{
tag: 'del',
},
{
tag: 'strike',
},
{
style: 'text-decoration',
getAttrs: value => (value === 'line-through' ? {} : false),
},
],
toDOM: () => ['s', 0],
};
}
public keys({ type }: SchemaMarkTypeParams) {
return {
'Mod-d': toggleMark(type),
};
}
public commands({ type }: SchemaMarkTypeParams) {
return () => toggleMark(type);
}
public inputRules({ type }: SchemaMarkTypeParams) {
return [markInputRule(/~([^~]+)~$/, type)];
}
public pasteRules({ type }: SchemaMarkTypeParams) {
return [markPasteRule(/~([^~]+)~/g, type)];
}
}
Extension Manager
The extension manager is used to manage the extensions passed into the editor. It automatically creates the nodes and marks which are used for generating a schema.
import { ExtensionManager, Doc, Text, Paragraph } from '@remirror/core';
import { Bold, Italic } from '@remirror/core-extensions';
const extensions = [new Doc(), new Text(), new Paragraph(), new Bold(), new Italic()];
console.log(extensions.nodes);
console.log(extension.marks);
extensions.createSchema();