codemirror-toolbar
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

codemirror-toolbar

npm vercel deploy

toolbarw render for codemirror

Docs and examples

Install

yarn add codemirror-markdown-slug

Usage

import { EditorView } from '@codemirror/view';
import toolbar, { markdownItems } from 'codemirror-toolbar';

new EditorView({
    extensions: [
        toolbar({
            items: markdownItems,
        }),
    ],
});

Customize toolbar items

import { EditorView } from '@codemirror/view';
import toolbar from 'codemirror-toolbar';
import * as Items from 'codemirror-toolbar/items';
import * as MarkdownItems from 'codemirror-toolbar/items/markdown';

new EditorView({
    extensions: [
        toolbar({
            items: [
                MarkdownItems.bold,
                MarkdownItems.italic,
                MarkdownItems.strike,
                MarkdownItems.underline,
                Items.split,
                MarkdownItems.h1,
                MarkdownItems.h2,
                MarkdownItems.h3,
                MarkdownItems.h4,
                MarkdownItems.h5,
                MarkdownItems.h6,
                Items.split,
                MarkdownItems.quote,
                MarkdownItems.ul,
                MarkdownItems.ol,
                MarkdownItems.todo,
                Items.split,
                MarkdownItems.link,
                {
                    ...MarkdownItems.image,
                    command: (view: EditorView) => {
                        view.dispatch({
                            // ...
                        });
                        
                        return true;
                    }
                },
                Items.space,
                Items.fullScreen,
            ],
        }),
    ],
});

Plugin Options

import { type Command } from '@codemirror/view';

export interface ToolbarConfig {
    items: Array<ToolbarItem | ToolbarSplit | ToolbarSpace>;
}

export type ToolbarItem = {
    // icon string, html code like svg
    icon: string;
    // render label
    label: string;
    // command to execute
    command: Command;
    // unique key, default `command.name || command.displayName`
    key?: string;
}

// Split slash
export type ToolbarSplit = {
    type: 'split';
}

// Render space with `flex: 1`
export type ToolbarSpace = {
    type: 'space';
}

Package Sidebar

Install

npm i codemirror-toolbar

Weekly Downloads

37

Version

0.1.0

License

MIT

Unpacked Size

63.6 kB

Total Files

33

Last publish

Collaborators

  • yeliex