Conditions | 3 |
Paths | 4 |
Total Lines | 26 |
Code Lines | 17 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | import AbstractMenuItemDispatcher from './AbstractMenuItemDispatcher'; |
||
16 | command: (state, dispatch) => { |
||
17 | const { $from } = state.selection; |
||
18 | |||
19 | const index = $from.index(); |
||
20 | if (!$from.parent.canReplaceWith(index, index, schema.nodes.footnote)) { |
||
21 | return false; |
||
22 | } |
||
23 | |||
24 | const selectedContent = state.selection.content().content.toJSON(); |
||
25 | const footnoteDoc = { |
||
26 | type: 'doc', |
||
27 | content: selectedContent || [{ type: 'paragraph' }], |
||
28 | }; |
||
29 | try { |
||
30 | footnoteSchema.nodeFromJSON(footnoteDoc); |
||
31 | } catch (e) { |
||
32 | return false; |
||
33 | } |
||
34 | |||
35 | if (dispatch) { |
||
36 | const footnoteNode = schema.nodes.footnote.create({ contentJSON: JSON.stringify(footnoteDoc) }); |
||
37 | dispatch(state.tr.replaceSelectionWith(footnoteNode)); |
||
38 | } |
||
39 | |||
40 | return true; |
||
41 | }, |
||
42 | icon: svgIcon('note-plus-outline'), |
||
47 |