| Total Complexity | 6 |
| Complexity/F | 1.2 |
| Lines of Code | 41 |
| Function Count | 5 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | class MenuView { |
||
| 2 | /** |
||
| 3 | * @param {[MenuItem]} items |
||
| 4 | * @param {EditorView} editorView |
||
| 5 | * |
||
| 6 | * @return {void} |
||
| 7 | */ |
||
| 8 | constructor(items, editorView) { |
||
| 9 | this.items = items; |
||
| 10 | this.editorView = editorView; |
||
| 11 | |||
| 12 | this.dom = document.createElement('div'); |
||
| 13 | this.dom.className = 'menubar'; |
||
| 14 | items.forEach(menuItem => this.dom.appendChild(menuItem.render(editorView))); |
||
| 15 | this.update(editorView); |
||
| 16 | } |
||
| 17 | |||
| 18 | /** |
||
| 19 | * Called by Prosemirror when the state of the editor changes |
||
| 20 | * |
||
| 21 | * @param {EditorView} editorView |
||
| 22 | * |
||
| 23 | * @return {void} |
||
| 24 | */ |
||
| 25 | update(editorView) { |
||
| 26 | this.items.forEach((item) => { |
||
| 27 | item.update(editorView); |
||
| 28 | }); |
||
| 29 | } |
||
| 30 | |||
| 31 | /** |
||
| 32 | * Called by Prosemirror when the menu is removed |
||
| 33 | * |
||
| 34 | * @return {void} |
||
| 35 | */ |
||
| 36 | destroy() { |
||
| 37 | this.dom.remove(); |
||
| 38 | } |
||
| 39 | } |
||
| 40 | |||
| 41 | export default MenuView; |
||
| 42 |