1 | class AbstractNodeView { |
||
2 | /** |
||
3 | * |
||
4 | * @param {Node} node |
||
5 | * @param {EditorView} view |
||
6 | * @param {function} getPos |
||
7 | */ |
||
8 | constructor(node, view, getPos) { |
||
9 | this.node = node; |
||
10 | this.outerView = view; |
||
11 | this.getPos = getPos; |
||
12 | |||
13 | this.renderNode(node.attrs); |
||
14 | } |
||
15 | |||
16 | /** |
||
17 | * Render the node into this.dom |
||
18 | * |
||
19 | * This method must be overwritten by the subclasses! |
||
20 | * |
||
21 | * @param {object} attrs the attributes for the node |
||
22 | */ |
||
23 | renderNode(attrs) { |
||
24 | console.log(this.node, attrs); |
||
0 ignored issues
–
show
Debugging Code
introduced
by
![]() |
|||
25 | throw new Error('renderNode must be implemented by child class!'); |
||
26 | } |
||
27 | |||
28 | /** |
||
29 | * Helper method to remove all keys with a given prefix from an object |
||
30 | * |
||
31 | * @param {string} prefix |
||
32 | * @param {object} attributes |
||
33 | * |
||
34 | * @return {object} a shallow copy of the initial object with the respective keys removed |
||
35 | */ |
||
36 | static unsetPrefixAttributes(prefix, attributes) { |
||
37 | const cleanedAttributes = {}; |
||
38 | Object.keys(attributes).forEach((attr) => { |
||
39 | if (attr.substr(0, prefix.length) !== prefix) { |
||
40 | cleanedAttributes[attr] = attributes[attr]; |
||
41 | } |
||
42 | }); |
||
43 | return cleanedAttributes; |
||
44 | } |
||
45 | } |
||
46 | |||
47 | export default AbstractNodeView; |
||
48 | window.AbstractNodeView = AbstractNodeView; |
||
49 |