Debian Codegraph @

extensions/VisualEditor/lib/ve/src/dm/nodes/ve.dm.TableSectionNode.js

raw symbols SCIP
1 /*!
2 * VisualEditor DataModel TableSelectionNode class.
3 *
4 * @copyright See AUTHORS.txt
5 */
6
7 /**
8 * DataModel table section node.
9 *
10 * @class
11 * @extends ve.dm.BranchNode
12 *
13 * @constructor
14 * @param {Object} [element] Reference to element in linear model
15 * @param {ve.dm.Node[]} [children]
16 */
17 ve.dm.TableSectionNode = function VeDmTableSectionNode() {
18 // Parent constructor
19 ve.dm.TableSectionNode.super.apply( this, arguments );
20
21 // Events
22 this.connect( this, { splice: 'onSplice' } );
23 };
24
25 /* Inheritance */
26
27 OO.inheritClass( ve.dm.TableSectionNode, ve.dm.BranchNode );
28
29 /* Static Properties */
30
31 ve.dm.TableSectionNode.static.name = 'tableSection';
32
33 ve.dm.TableSectionNode.static.childNodeTypes = [ 'tableRow' ];
34
35 ve.dm.TableSectionNode.static.parentNodeTypes = [ 'table' ];
36
37 ve.dm.TableSectionNode.static.defaultAttributes = { style: 'body' };
38
39 ve.dm.TableSectionNode.static.matchTagNames = [ 'thead', 'tbody', 'tfoot' ];
40
41 /* Static Methods */
42
43 ve.dm.TableSectionNode.static.toDataElement = function ( domElements ) {
44 const styles = {
45 thead: 'header',
46 tbody: 'body',
47 tfoot: 'footer'
48 },
49 style = styles[ domElements[ 0 ].nodeName.toLowerCase() ] || 'body';
50 return { type: this.name, attributes: { style: style } };
51 };
52
53 ve.dm.TableSectionNode.static.toDomElements = function ( dataElement, doc ) {
54 const tags = {
55 header: 'thead',
56 body: 'tbody',
57 footer: 'tfoot'
58 },
59 tag = tags[ dataElement.attributes && dataElement.attributes.style || 'body' ];
60 return [ doc.createElement( tag ) ];
61 };
62
63 /* Methods */
64
65 /**
66 * Handle splicing of child nodes
67 */
68 ve.dm.TableSectionNode.prototype.onSplice = function () {
69 if ( this.getRoot() ) {
70 this.getParent().getMatrix().invalidate();
71 }
72 const nodes = Array.prototype.slice.call( arguments, 2 );
73 for ( let i = 0; i < nodes.length; i++ ) {
74 nodes[ i ].connect( this, {
75 cellAttributeChange: 'onCellAttributeChange'
76 } );
77 }
78 };
79
80 /**
81 * Handle cell attribute changes
82 *
83 * @param {ve.dm.TableCellableNode} cell
84 * @fires ve.dm.TableNode#cellAttributeChange
85 */
86 ve.dm.TableSectionNode.prototype.onCellAttributeChange = function ( cell ) {
87 this.emit( 'cellAttributeChange', cell );
88 };
89
90 /* Registration */
91
92 ve.dm.modelRegistry.register( ve.dm.TableSectionNode );