Passed
Push — master ( 3d5c82...a8ac22 )
by Michael
02:17
created

TableMenuItemDispatcher.js ➔ getMenuItem   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 24
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 17
nc 1
nop 1
dl 0
loc 24
rs 9.55
c 1
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A TableMenuItemDispatcher.js ➔ ... ➔ ??? 0 15 3
1
import AbstractMenuItemDispatcher from './AbstractMenuItemDispatcher';
2
import { svgIcon } from '../MDI';
3
import MenuItem from '../MenuItem';
4
import { setBlockTypeNoAttrCheck } from '../../../customCommands';
5
6
export default class TableMenuItemDispatcher extends AbstractMenuItemDispatcher {
7
    static isAvailable(schema) {
8
        return !!schema.nodes.table;
9
    }
10
11
    static getMenuItem(schema) {
12
        if (!this.isAvailable(schema)) {
13
            throw new Error('Table not available in schema!');
14
        }
15
        return new MenuItem({
16
            command: (state, dispatch) => {
17
                if (!setBlockTypeNoAttrCheck(schema.nodes.table)(state)) {
18
                    return false;
19
                }
20
                if (dispatch) {
21
                    const tableCell = schema.nodes.table_cell.create();
22
                    const rowCells = [tableCell, tableCell.copy()];
23
                    const tableRow = schema.nodes.table_row.create({}, rowCells);
24
                    const tableRows = [tableRow, tableRow.copy()];
25
                    const tableNode = schema.nodes.table.create({}, tableRows);
26
                    dispatch(state.tr.replaceSelectionWith(tableNode));
27
                }
28
29
                return true;
30
            },
31
            icon: svgIcon('table-plus'),
32
            label: LANG.plugins.prosemirror['label:table'],
0 ignored issues
show
Bug introduced by
The variable LANG seems to be never declared. If this is a global, consider adding a /** global: LANG */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
33
        });
34
    }
35
}
36