2014-10-27 14:26:47 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor DataModel MWTable class.
|
|
|
|
*
|
2020-01-08 17:13:04 +00:00
|
|
|
* @copyright 2011-2020 VisualEditor Team and others; see AUTHORS.txt
|
2014-10-27 14:26:47 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* DataModel MediaWiki table node.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends ve.dm.TableNode
|
|
|
|
* @mixins ve.dm.ClassAttributeNode
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {Object} [element] Reference to element in linear model
|
|
|
|
* @param {ve.dm.Node[]} [children]
|
|
|
|
*/
|
|
|
|
ve.dm.MWTableNode = function VeDmMWTableNode() {
|
|
|
|
// Parent constructor
|
|
|
|
ve.dm.MWTableNode.super.apply( this, arguments );
|
|
|
|
|
|
|
|
// Mixin constructors
|
|
|
|
ve.dm.ClassAttributeNode.call( this );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
OO.inheritClass( ve.dm.MWTableNode, ve.dm.TableNode );
|
|
|
|
|
|
|
|
OO.mixinClass( ve.dm.MWTableNode, ve.dm.ClassAttributeNode );
|
|
|
|
|
|
|
|
/* Static Properties */
|
|
|
|
|
|
|
|
ve.dm.MWTableNode.static.name = 'mwTable';
|
|
|
|
|
|
|
|
ve.dm.MWTableNode.static.classAttributes = {
|
|
|
|
wikitable: { wikitable: true },
|
2017-02-03 21:36:52 +00:00
|
|
|
sortable: { sortable: true },
|
|
|
|
'mw-collapsible': { collapsible: true },
|
|
|
|
'mw-collapsed': { collapsed: true }
|
2014-10-27 14:26:47 +00:00
|
|
|
};
|
|
|
|
|
2017-04-27 17:30:23 +00:00
|
|
|
// Tables in wikitext only work in some contexts, they're impossible e.g. in list items
|
2018-09-06 16:45:52 +00:00
|
|
|
ve.dm.MWTableNode.static.suggestedParentNodeTypes = [
|
2019-02-13 13:21:26 +00:00
|
|
|
'document', 'div', 'tableCell', 'tableCaption', 'mwImageCaption', 'section',
|
2018-09-06 16:45:52 +00:00
|
|
|
// TODO: `paragraph` isn't really a suggested table parent. However,
|
|
|
|
// allowing it here interacts with our post-insertion cleanup for block
|
|
|
|
// nodes so that empty paragraphs get properly removed. We should find a
|
|
|
|
// cleaner way to do this. See: T201573.
|
|
|
|
'paragraph'
|
|
|
|
];
|
2017-04-27 17:30:23 +00:00
|
|
|
|
2014-10-27 14:26:47 +00:00
|
|
|
// HACK: users of parentNodeTypes should be fixed to check for inherited classes.
|
|
|
|
ve.dm.TableSectionNode.static.parentNodeTypes.push( 'mwTable' );
|
2014-10-30 18:38:26 +00:00
|
|
|
ve.dm.TableCaptionNode.static.parentNodeTypes.push( 'mwTable' );
|
2015-08-03 14:25:03 +00:00
|
|
|
ve.dm.TableRowNode.static.childNodeTypes.push( 'mwTransclusionTableCell' );
|
2014-10-27 14:26:47 +00:00
|
|
|
|
2016-01-29 17:44:02 +00:00
|
|
|
ve.dm.MWTableNode.static.toDataElement = function ( domElements ) {
|
2014-10-27 14:26:47 +00:00
|
|
|
var attributes = {},
|
|
|
|
dataElement = { type: this.name },
|
2015-08-19 17:33:02 +00:00
|
|
|
classAttr = domElements[ 0 ].getAttribute( 'class' );
|
2014-10-27 14:26:47 +00:00
|
|
|
|
|
|
|
this.setClassAttributes( attributes, classAttr );
|
|
|
|
|
|
|
|
if ( !ve.isEmptyObject( attributes ) ) {
|
|
|
|
dataElement.attributes = attributes;
|
|
|
|
}
|
|
|
|
return dataElement;
|
|
|
|
};
|
|
|
|
|
|
|
|
ve.dm.MWTableNode.static.toDomElements = function ( dataElement, doc ) {
|
|
|
|
var element = doc.createElement( 'table' ),
|
2014-10-29 21:50:50 +00:00
|
|
|
classAttr = dataElement.attributes && this.getClassAttrFromAttributes( dataElement.attributes );
|
2014-10-27 14:26:47 +00:00
|
|
|
|
|
|
|
if ( classAttr ) {
|
2020-04-09 13:33:54 +00:00
|
|
|
// eslint-disable-next-line mediawiki/class-doc
|
2014-10-27 14:26:47 +00:00
|
|
|
element.className = classAttr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return [ element ];
|
|
|
|
};
|
|
|
|
|
2016-01-29 17:44:02 +00:00
|
|
|
ve.dm.MWTableNode.static.sanitize = function ( dataElement ) {
|
|
|
|
// Mixin method
|
|
|
|
ve.dm.ClassAttributeNode.static.sanitize.call( this, dataElement );
|
|
|
|
|
|
|
|
ve.setProp( dataElement, 'attributes', 'wikitable', true );
|
|
|
|
};
|
|
|
|
|
2014-10-27 14:26:47 +00:00
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
ve.dm.modelRegistry.register( ve.dm.MWTableNode );
|