Completed
Push — master ( 3b8b0c...578b04 )
by Michael
02:39
created

script/plugins/Menu/MenuItems/HeadingMenuItemDispatcher.js   A

Complexity

Total Complexity 5
Complexity/F 1.67

Size

Lines of Code 31
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 0
eloc 17
c 0
b 0
f 0
nc 1
dl 0
loc 31
rs 10
wmc 5
mnd 1
bc 4
fnc 3
bpm 1.3333
cpm 1.6666
noi 0

3 Functions

Rating   Name   Duplication   Size   Complexity  
A HeadingMenuItemDispatcher.js ➔ constructor 0 4 1
A HeadingMenuItemDispatcher.js ➔ isAvailable 0 3 1
A HeadingMenuItemDispatcher.js ➔ getMenuItem 0 10 2
1
import { setBlockType } from 'prosemirror-commands';
2
import AbstractMenuItemDispatcher from './AbstractMenuItemDispatcher';
3
import MenuItem from '../MenuItem';
4
import { svgIcon } from '../MDI';
5
6
export default class HeadingMenuItemDispatcher extends AbstractMenuItemDispatcher {
7
    /**
8
     * Create an MenuItemDispatcher to set the blocktype to a heading at the given level
9
     *
10
     * @param {int} level the level of the heading, from 1 to 6
11
     */
12
    constructor(level) {
13
        super();
14
        this.level = level;
15
    }
16
17
    isAvailable(schema) { // eslint-disable-line class-methods-use-this
18
        return !!schema.nodes.heading;
19
    }
20
21
    getMenuItem(schema) {
22
        if (!this.isAvailable(schema)) {
23
            throw new Error('Headings not available in this schema!');
24
        }
25
        return new MenuItem({
26
            command: setBlockType(schema.nodes.heading, { level: this.level }),
27
            icon: svgIcon(`format-header-${this.level}`),
28
            label: `Heading ${this.level}`,
29
        });
30
    }
31
}
32