| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
ve.dm.TableCellNode = function VeDmTableCellNode() { |
| 19 |
|
| 20 |
ve.dm.TableCellNode.super.apply( this, arguments ); |
| 21 |
|
| 22 |
|
| 23 |
ve.dm.TableCellableNode.call( this ); |
| 24 |
}; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
OO.inheritClass( ve.dm.TableCellNode, ve.dm.BranchNode ); |
| 29 |
|
| 30 |
OO.mixinClass( ve.dm.TableCellNode, ve.dm.TableCellableNode ); |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
ve.dm.TableCellNode.static.name = 'tableCell'; |
| 35 |
|
| 36 |
ve.dm.TableCellNode.static.isUnwrappable = false; |
| 37 |
|
| 38 |
ve.dm.TableCellNode.static.parentNodeTypes = [ 'tableRow' ]; |
| 39 |
|
| 40 |
ve.dm.TableCellNode.static.defaultAttributes = { style: 'data' }; |
| 41 |
|
| 42 |
ve.dm.TableCellNode.static.matchTagNames = [ 'td', 'th' ]; |
| 43 |
|
| 44 |
ve.dm.TableCellNode.static.isCellEditable = true; |
| 45 |
|
| 46 |
|
| 47 |
ve.dm.TableCellNode.static.preserveHtmlAttributes = function ( attribute ) { |
| 48 |
return attribute !== 'colspan' && attribute !== 'rowspan'; |
| 49 |
}; |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
ve.dm.TableCellNode.static.toDataElement = function ( domElements ) { |
| 54 |
const attributes = {}; |
| 55 |
|
| 56 |
ve.dm.TableCellableNode.static.setAttributes( attributes, domElements ); |
| 57 |
|
| 58 |
return { |
| 59 |
type: this.name, |
| 60 |
attributes: attributes |
| 61 |
}; |
| 62 |
}; |
| 63 |
|
| 64 |
ve.dm.TableCellNode.static.toDomElements = function ( dataElement, doc ) { |
| 65 |
const tag = dataElement.attributes && dataElement.attributes.style === 'header' ? 'th' : 'td', |
| 66 |
domElement = doc.createElement( tag ), |
| 67 |
attributes = dataElement.attributes; |
| 68 |
|
| 69 |
ve.dm.TableCellableNode.static.applyAttributes( attributes, domElement ); |
| 70 |
|
| 71 |
return [ domElement ]; |
| 72 |
}; |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
ve.dm.TableCellNode.static.createData = function ( options ) { |
| 85 |
options = options || {}; |
| 86 |
const opening = { |
| 87 |
type: 'tableCell', |
| 88 |
attributes: { |
| 89 |
style: options.style || 'data', |
| 90 |
rowspan: options.rowspan || 1, |
| 91 |
colspan: options.colspan || 1 |
| 92 |
} |
| 93 |
}; |
| 94 |
const content = options.content || [ |
| 95 |
{ type: 'paragraph', internal: { generated: 'wrapper' } }, |
| 96 |
{ type: '/paragraph' } |
| 97 |
]; |
| 98 |
return [ opening ].concat( content, { type: '/tableCell' } ); |
| 99 |
}; |
| 100 |
|
| 101 |
ve.dm.TableCellNode.static.describeChange = function ( key, change ) { |
| 102 |
if ( key === 'style' ) { |
| 103 |
return ve.htmlMsg( 'visualeditor-changedesc-no-key', |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
this.wrapText( 'del', ve.msg( 'visualeditor-table-format-' + change.from ) ), |
| 108 |
this.wrapText( 'ins', ve.msg( 'visualeditor-table-format-' + change.to ) ) |
| 109 |
); |
| 110 |
} else if ( key === 'colspan' || key === 'rowspan' ) { |
| 111 |
|
| 112 |
if ( change.from === 1 ) { |
| 113 |
change.from = undefined; |
| 114 |
} |
| 115 |
if ( change.to === 1 ) { |
| 116 |
change.to = undefined; |
| 117 |
} |
| 118 |
|
| 119 |
if ( change.from === change.to ) { |
| 120 |
return null; |
| 121 |
} |
| 122 |
} else if ( key === 'originalColspan' || key === 'originalRowspan' ) { |
| 123 |
return null; |
| 124 |
} |
| 125 |
|
| 126 |
|
| 127 |
return ve.dm.TableCellNode.super.static.describeChange.call( this, key, change ); |
| 128 |
}; |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
ve.dm.modelRegistry.register( ve.dm.TableCellNode ); |