Total Complexity | 7 |
Complexity/F | 2.33 |
Lines of Code | 49 |
Function Count | 3 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import { Schema } from 'prosemirror-model'; |
||
2 | |||
3 | import AbstractMenuItemDispatcher from './AbstractMenuItemDispatcher'; |
||
4 | import MenuItem from '../MenuItem'; |
||
5 | import { svgIcon } from '../MDI'; |
||
6 | import getFootnoteSpec from '../../../nodeviews/Footnote/footnoteSchema'; |
||
7 | |||
8 | export default class FootnoteMenuItemDispatcher extends AbstractMenuItemDispatcher { |
||
9 | static isAvailable(schema) { |
||
10 | return !!schema.nodes.footnote; |
||
11 | } |
||
12 | |||
13 | static getMenuItem(schema) { |
||
14 | if (!this.isAvailable(schema)) { |
||
15 | throw new Error('Footnote not available in schema!'); |
||
16 | } |
||
17 | return new MenuItem({ |
||
18 | command: (state, dispatch) => { |
||
19 | const { $from } = state.selection; |
||
20 | |||
21 | const index = $from.index(); |
||
22 | if (!$from.parent.canReplaceWith(index, index, schema.nodes.footnote)) { |
||
23 | return false; |
||
24 | } |
||
25 | |||
26 | const selectedContent = state.selection.content().content.toJSON(); |
||
27 | const footnoteDoc = { |
||
28 | type: 'doc', |
||
29 | content: selectedContent || [{ type: 'paragraph' }], |
||
30 | }; |
||
31 | try { |
||
32 | const footnoteSchema = new Schema(getFootnoteSpec()); |
||
33 | footnoteSchema.nodeFromJSON(footnoteDoc); |
||
34 | } catch (e) { |
||
35 | return false; |
||
36 | } |
||
37 | |||
38 | if (dispatch) { |
||
39 | const footnoteNode = schema.nodes.footnote.create({ contentJSON: JSON.stringify(footnoteDoc) }); |
||
40 | dispatch(state.tr.replaceSelectionWith(footnoteNode)); |
||
41 | } |
||
42 | |||
43 | return true; |
||
44 | }, |
||
45 | icon: svgIcon('note-plus-outline'), |
||
46 | label: LANG.plugins.prosemirror['label:footnote'], |
||
|
|||
47 | }); |
||
48 | } |
||
49 | } |
||
50 |
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.