| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
ve.dm.TableSectionNode = function VeDmTableSectionNode() { |
| 18 |
|
| 19 |
ve.dm.TableSectionNode.super.apply( this, arguments ); |
| 20 |
|
| 21 |
|
| 22 |
this.connect( this, { splice: 'onSplice' } ); |
| 23 |
}; |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
OO.inheritClass( ve.dm.TableSectionNode, ve.dm.BranchNode ); |
| 28 |
|
| 29 |
|
| 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 |
|
| 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 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 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 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
ve.dm.TableSectionNode.prototype.onCellAttributeChange = function ( cell ) { |
| 87 |
this.emit( 'cellAttributeChange', cell ); |
| 88 |
}; |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
ve.dm.modelRegistry.register( ve.dm.TableSectionNode ); |