jenkins-bot has submitted this change and it was merged. Change subject: Split AlienExtensionNode into inline and block ......................................................................
Split AlienExtensionNode into inline and block MWExtensionNode: * Inherit from LeafNode at the top level. Inline and block only differ in CE where inline has isContent set. MWAlienExtensionNode: * Inhert from MW(Inline|Block)ExtensionNode respectively. Both mixin MWAlienExtensionNode. Bonus: * Bring in paragraph unwrapping on inline nodes from MWMathNode Bug: T93712 Change-Id: Ib04234f740cf1f27c861d8b3cfeea5e323b94678 --- M modules/ve-mw/ce/nodes/ve.ce.MWAlienExtensionNode.js M modules/ve-mw/ce/nodes/ve.ce.MWExtensionNode.js M modules/ve-mw/dm/nodes/ve.dm.MWAlienExtensionNode.js M modules/ve-mw/dm/nodes/ve.dm.MWExtensionNode.js M modules/ve-mw/tests/dm/ve.dm.mwExample.js M modules/ve-mw/ui/contextitems/ve.ui.MWAlienExtensionContextItem.js M modules/ve-mw/ui/inspectors/ve.ui.MWAlienExtensionInspector.js 7 files changed, 251 insertions(+), 80 deletions(-) Approvals: Catrope: Looks good to me, approved jenkins-bot: Verified diff --git a/modules/ve-mw/ce/nodes/ve.ce.MWAlienExtensionNode.js b/modules/ve-mw/ce/nodes/ve.ce.MWAlienExtensionNode.js index f5c3f0c..9eb7137 100644 --- a/modules/ve-mw/ce/nodes/ve.ce.MWAlienExtensionNode.js +++ b/modules/ve-mw/ce/nodes/ve.ce.MWAlienExtensionNode.js @@ -9,49 +9,36 @@ * ContentEditable MediaWiki alien extension node. * * @class - * @extends ve.ce.MWBlockExtensionNode + * @abstract + * @mixins OO.ui.IconElement * * @constructor - * @param {ve.dm.MWAlienExtensionNode} model Model to observe * @param {Object} [config] Configuration options */ ve.ce.MWAlienExtensionNode = function VeCeMWAlienExtensionNode( config ) { - // Parent constructor - ve.ce.MWAlienExtensionNode.super.apply( this, arguments ); - // Mixin constructors OO.ui.IconElement.call( this, config ); + + // Events + this.connect( this, { setup: 'onAlienSetup' } ); }; /* Inheritance */ -OO.inheritClass( ve.ce.MWAlienExtensionNode, ve.ce.MWBlockExtensionNode ); +OO.initClass( ve.ce.MWAlienExtensionNode ); OO.mixinClass( ve.ce.MWAlienExtensionNode, OO.ui.IconElement ); -/* Static Properties */ - -ve.ce.MWAlienExtensionNode.static.name = 'mwAlienExtension'; +/* Static members */ ve.ce.MWAlienExtensionNode.static.primaryCommandName = 'alienExtension'; - -/* Static Methods */ - -/** - * @inheritdoc - */ -ve.ce.MWAlienExtensionNode.static.getDescription = function ( model ) { - return model.getExtensionName(); -}; /* Methods */ /** - * @inheritdoc + * Handle setup events */ -ve.ce.MWAlienExtensionNode.prototype.onSetup = function () { - ve.ce.MWAlienExtensionNode.super.prototype.onSetup.call( this ); - +ve.ce.MWAlienExtensionNode.prototype.onAlienSetup = function () { if ( !this.isVisible() ) { this.setIcon( 'alienextension' ); this.$element.first().prepend( this.$icon ); @@ -61,7 +48,7 @@ }; /** - * @inheritdoc + * @inheritdoc ve.ce.MWExtensionNode */ ve.ce.MWAlienExtensionNode.prototype.render = function ( generatedContents ) { // Since render is trigerred before onSetup, we need to make sure that the @@ -77,6 +64,76 @@ this.$element.addClass( 've-ce-mwAlienExtensionNode' ); }; +/* Static methods */ + +/** + * @inheritdoc ve.ce.MWExtensionNode + */ +ve.ce.MWAlienExtensionNode.static.getDescription = function ( model ) { + return model.getExtensionName(); +}; + +/** + * ContentEditable MediaWiki alien inline extension node. + * + * @class + * @abstract + * @extends ve.ce.MWInlineExtensionNode + * @mixins ve.ce.MWAlienExtensionNode + * + * @constructor + * @param {ve.dm.MWAlienInlineExtensionNode} model Model to observe + * @param {Object} [config] Configuration options + */ +ve.ce.MWAlienInlineExtensionNode = function VeCeMWAlienInlineExtensionNode( config ) { + // Parent constructor + ve.ce.MWAlienInlineExtensionNode.super.apply( this, arguments ); + + // Mixin constructors + ve.ce.MWAlienExtensionNode.call( this, config ); +}; + +/* Inheritance */ + +OO.inheritClass( ve.ce.MWAlienInlineExtensionNode, ve.ce.MWInlineExtensionNode ); + +OO.mixinClass( ve.ce.MWAlienInlineExtensionNode, ve.ce.MWAlienExtensionNode ); + +/* Static members */ + +ve.ce.MWAlienInlineExtensionNode.static.name = 'mwAlienInlineExtension'; + +/** + * ContentEditable MediaWiki alien block extension node. + * + * @class + * @abstract + * @extends ve.ce.MWBlockExtensionNode + * @mixins ve.ce.MWAlienExtensionNode + * + * @constructor + * @param {ve.dm.MWAlienBlockExtensionNode} model Model to observe + * @param {Object} [config] Configuration options + */ +ve.ce.MWAlienBlockExtensionNode = function VeCeMWAlienBlockExtensionNode() { + // Parent constructor + ve.ce.MWAlienBlockExtensionNode.super.apply( this, arguments ); + + // Mixin constructors + ve.ce.MWAlienExtensionNode.call( this ); +}; + +/* Inheritance */ + +OO.inheritClass( ve.ce.MWAlienBlockExtensionNode, ve.ce.MWBlockExtensionNode ); + +OO.mixinClass( ve.ce.MWAlienBlockExtensionNode, ve.ce.MWAlienExtensionNode ); + +/* Static members */ + +ve.ce.MWAlienBlockExtensionNode.static.name = 'mwAlienBlockExtension'; + /* Registration */ -ve.ce.nodeFactory.register( ve.ce.MWAlienExtensionNode ); +ve.ce.nodeFactory.register( ve.ce.MWAlienInlineExtensionNode ); +ve.ce.nodeFactory.register( ve.ce.MWAlienBlockExtensionNode ); diff --git a/modules/ve-mw/ce/nodes/ve.ce.MWExtensionNode.js b/modules/ve-mw/ce/nodes/ve.ce.MWExtensionNode.js index 669145c..405eb0b 100644 --- a/modules/ve-mw/ce/nodes/ve.ce.MWExtensionNode.js +++ b/modules/ve-mw/ce/nodes/ve.ce.MWExtensionNode.js @@ -14,12 +14,16 @@ * * @class * @abstract + * @extends ve.ce.LeafNode * @mixins ve.ce.FocusableNode * @mixins ve.ce.GeneratedContentNode * * @constructor */ ve.ce.MWExtensionNode = function VeCeMWExtensionNode() { + // Parent constructor + ve.ce.MWExtensionNode.super.apply( this, arguments ); + // Mixin constructors ve.ce.FocusableNode.call( this, this.getFocusableElement() ); ve.ce.GeneratedContentNode.call( this ); @@ -28,7 +32,6 @@ /* Inheritance */ OO.inheritClass( ve.ce.MWExtensionNode, ve.ce.LeafNode ); - OO.mixinClass( ve.ce.MWExtensionNode, ve.ce.FocusableNode ); OO.mixinClass( ve.ce.MWExtensionNode, ve.ce.GeneratedContentNode ); @@ -109,49 +112,53 @@ * * @class * @abstract - * @extends ve.ce.LeafNode - * @mixins ve.ce.MWExtensionNode + * @extends ve.ce.MWExtensionNode * * @constructor * @param {ve.dm.MWInlineExtensionNode} model Model to observe * @param {Object} [config] Configuration options */ -ve.ce.MWInlineExtensionNode = function VeCeMWInlineExtensionNode( model, config ) { +ve.ce.MWInlineExtensionNode = function VeCeMWInlineExtensionNode() { // Parent constructor - ve.ce.LeafNode.call( this, model, config ); - - // Mixin constructors - ve.ce.MWExtensionNode.call( this ); + ve.ce.MWInlineExtensionNode.super.apply( this, arguments ); }; /* Inheritance */ -OO.inheritClass( ve.ce.MWInlineExtensionNode, ve.ce.LeafNode ); +OO.inheritClass( ve.ce.MWInlineExtensionNode, ve.ce.MWExtensionNode ); -OO.mixinClass( ve.ce.MWInlineExtensionNode, ve.ce.MWExtensionNode ); +/* Methods */ + +/** + * @inheritdoc + */ +ve.ce.MWInlineExtensionNode.prototype.onParseSuccess = function ( deferred, response ) { + var data = response.visualeditor, + contentNodes = this.$( data.content ).get(); + + // Inline nodes will come back in wrapper paragraphs, so unwrap them. + if ( contentNodes[0] && contentNodes[0].childNodes ) { + contentNodes = Array.prototype.slice.apply( contentNodes[0].childNodes ); + } + deferred.resolve( contentNodes ); +}; /** * ContentEditable MediaWiki block extension node. * * @class * @abstract - * @extends ve.ce.BranchNode - * @mixins ve.ce.MWExtensionNode + * @extends ve.ce.MWExtensionNode * * @constructor * @param {ve.dm.MWBlockExtensionNode} model Model to observe * @param {Object} [config] Configuration options */ -ve.ce.MWBlockExtensionNode = function VeCeMWBlockExtensionNode( model, config ) { +ve.ce.MWBlockExtensionNode = function VeCeMWBlockExtensionNode() { // Parent constructor - ve.ce.BranchNode.call( this, model, config ); - - // Mixin constructors - ve.ce.MWExtensionNode.call( this ); + ve.ce.MWBlockExtensionNode.super.apply( this, arguments ); }; /* Inheritance */ -OO.inheritClass( ve.ce.MWBlockExtensionNode, ve.ce.BranchNode ); - -OO.mixinClass( ve.ce.MWBlockExtensionNode, ve.ce.MWExtensionNode ); +OO.inheritClass( ve.ce.MWBlockExtensionNode, ve.ce.MWExtensionNode ); diff --git a/modules/ve-mw/dm/nodes/ve.dm.MWAlienExtensionNode.js b/modules/ve-mw/dm/nodes/ve.dm.MWAlienExtensionNode.js index 6b38e06..e30b03d 100644 --- a/modules/ve-mw/dm/nodes/ve.dm.MWAlienExtensionNode.js +++ b/modules/ve-mw/dm/nodes/ve.dm.MWAlienExtensionNode.js @@ -9,22 +9,17 @@ * DataModel MediaWiki alien extension node. * * @class - * @extends ve.dm.MWBlockExtensionNode + * @abstract * * @constructor */ -ve.dm.MWAlienExtensionNode = function VeDmMWAlienExtensionNode() { - // Parent constructor - ve.dm.MWBlockExtensionNode.apply( this, arguments ); -}; +ve.dm.MWAlienExtensionNode = function VeDmMWAlienExtensionNode() {}; /* Inheritance */ -OO.inheritClass( ve.dm.MWAlienExtensionNode, ve.dm.MWBlockExtensionNode ); +OO.initClass( ve.dm.MWAlienExtensionNode ); /* Static members */ - -ve.dm.MWAlienExtensionNode.static.name = 'mwAlienExtension'; ve.dm.MWAlienExtensionNode.static.getMatchRdfaTypes = function () { return [ @@ -32,13 +27,88 @@ ]; }; -ve.dm.MWAlienExtensionNode.static.tagName = 'div'; +ve.dm.MWAlienExtensionNode.static.toDataElement = function ( domElements, converter ) { + // 'Parent' method + var element = ve.dm.MWExtensionNode.static.toDataElement( domElements, converter ), + isInline = this.isHybridInline( domElements, converter ); -/** */ + element.type = isInline ? 'mwAlienInlineExtension' : 'mwAlienBlockExtension'; + return element; +}; + +/** + * @inheritdoc ve.dm.MWExtensionNode + */ ve.dm.MWAlienExtensionNode.static.getExtensionName = function ( dataElement ) { return dataElement.attributes.mw.name; }; +/** + * DataModel MediaWiki alien inline extension node. + * + * @class + * @abstract + * @extends ve.dm.MWInlineExtensionNode + * @mixins ve.dm.MWAlienExtensionNode + * + * @constructor + * @param {Object} [element] Reference to element in linear model + */ +ve.dm.MWAlienInlineExtensionNode = function VeDmMWAlienInlineExtensionNode() { + // Parent constructor + ve.dm.MWAlienInlineExtensionNode.super.apply( this, arguments ); + + // Mixin constructors + ve.dm.MWAlienExtensionNode.call( this ); +}; + +/* Inheritance */ + +OO.inheritClass( ve.dm.MWAlienInlineExtensionNode, ve.dm.MWInlineExtensionNode ); + +OO.mixinClass( ve.dm.MWAlienInlineExtensionNode, ve.dm.MWAlienExtensionNode ); + +/* Static members */ + +ve.dm.MWAlienInlineExtensionNode.static.name = 'mwAlienInlineExtension'; + +ve.dm.MWAlienInlineExtensionNode.static.isContent = true; + +ve.dm.MWAlienInlineExtensionNode.static.tagName = 'span'; + +/** + * DataModel MediaWiki alien block extension node. + * + * @class + * @abstract + * @extends ve.dm.MWBlockExtensionNode + * @mixins ve.dm.MWAlienExtensionNode + * + * @constructor + * @param {Object} [element] Reference to element in linear model + * @param {ve.dm.Node[]} [children] + */ +ve.dm.MWAlienBlockExtensionNode = function VeDmMWAlienBlockExtensionNode() { + // Parent constructor + ve.dm.MWAlienBlockExtensionNode.super.apply( this, arguments ); + + // Mixin constructors + ve.dm.MWAlienExtensionNode.call( this ); +}; + +/* Inheritance */ + +OO.inheritClass( ve.dm.MWAlienBlockExtensionNode, ve.dm.MWBlockExtensionNode ); + +OO.mixinClass( ve.dm.MWAlienBlockExtensionNode, ve.dm.MWAlienExtensionNode ); + +/* Static members */ + +ve.dm.MWAlienBlockExtensionNode.static.name = 'mwAlienBlockExtension'; + +ve.dm.MWAlienBlockExtensionNode.static.tagName = 'div'; + /* Registration */ -ve.dm.modelRegistry.register( ve.dm.MWAlienExtensionNode ); +ve.dm.modelRegistry.register( ve.dm.MWAlienInlineExtensionNode ); +ve.dm.modelRegistry.register( ve.dm.MWAlienBlockExtensionNode ); diff --git a/modules/ve-mw/dm/nodes/ve.dm.MWExtensionNode.js b/modules/ve-mw/dm/nodes/ve.dm.MWExtensionNode.js index 9aed303..6aa9747 100644 --- a/modules/ve-mw/dm/nodes/ve.dm.MWExtensionNode.js +++ b/modules/ve-mw/dm/nodes/ve.dm.MWExtensionNode.js @@ -10,12 +10,16 @@ * * @class * @abstract + * @extends ve.dm.LeafNode * @mixins ve.dm.FocusableNode * @mixins ve.dm.GeneratedContentNode * * @constructor */ ve.dm.MWExtensionNode = function VeDmMWExtensionNode() { + // Parent constructor + ve.dm.MWExtensionNode.super.apply( this, arguments ); + // Mixin constructors ve.dm.GeneratedContentNode.call( this ); ve.dm.FocusableNode.call( this ); @@ -23,8 +27,8 @@ /* Inheritance */ +OO.inheritClass( ve.dm.MWExtensionNode, ve.dm.LeafNode ); OO.mixinClass( ve.dm.MWExtensionNode, ve.dm.FocusableNode ); - OO.mixinClass( ve.dm.MWExtensionNode, ve.dm.GeneratedContentNode ); /* Static members */ @@ -131,25 +135,19 @@ * * @class * @abstract - * @extends ve.dm.LeafNode - * @mixins ve.dm.MWExtensionNode + * @extends ve.dm.MWExtensionNode * * @constructor * @param {Object} [element] Reference to element in linear model */ ve.dm.MWInlineExtensionNode = function VeDmMWInlineExtensionNode() { // Parent constructor - ve.dm.LeafNode.apply( this, arguments ); - - // Mixin constructors - ve.dm.MWExtensionNode.call( this ); + ve.dm.MWInlineExtensionNode.super.apply( this, arguments ); }; /* Inheritance */ -OO.inheritClass( ve.dm.MWInlineExtensionNode, ve.dm.LeafNode ); - -OO.mixinClass( ve.dm.MWInlineExtensionNode, ve.dm.MWExtensionNode ); +OO.inheritClass( ve.dm.MWInlineExtensionNode, ve.dm.MWExtensionNode ); /* Static members */ @@ -160,23 +158,17 @@ * * @class * @abstract - * @extends ve.dm.BranchNode - * @mixins ve.dm.MWExtensionNode + * @extends ve.dm.MWExtensionNode * * @constructor * @param {Object} [element] Reference to element in linear model * @param {ve.dm.Node[]} [children] */ -ve.dm.MWBlockExtensionNode = function VeDmMWInlineExtensionNode() { +ve.dm.MWBlockExtensionNode = function VeDmMWBlockExtensionNode() { // Parent constructor - ve.dm.BranchNode.apply( this, arguments ); - - // Mixin constructors - ve.dm.MWExtensionNode.call( this ); + ve.dm.MWBlockExtensionNode.super.apply( this, arguments ); }; /* Inheritance */ -OO.inheritClass( ve.dm.MWBlockExtensionNode, ve.dm.BranchNode ); - -OO.mixinClass( ve.dm.MWBlockExtensionNode, ve.dm.MWExtensionNode ); +OO.inheritClass( ve.dm.MWBlockExtensionNode, ve.dm.MWExtensionNode ); diff --git a/modules/ve-mw/tests/dm/ve.dm.mwExample.js b/modules/ve-mw/tests/dm/ve.dm.mwExample.js index 59b7c1b..d2cc0b1 100644 --- a/modules/ve-mw/tests/dm/ve.dm.mwExample.js +++ b/modules/ve-mw/tests/dm/ve.dm.mwExample.js @@ -1051,7 +1051,7 @@ { type: '/internalList' } ] }, - 'mw:AlienExtension': { + 'mw:AlienBlockExtension': { body: '<div about="#mwt1" typeof="mw:Extension/syntaxhighlight"' + ' data-mw="{"name":"syntaxhighlight","attrs":{"lang":"php"},"body":{"extsrc":"\\n$foo = bar;\\n"}}"' + @@ -1067,7 +1067,7 @@ '</div>', data: [ { - type: 'mwAlienExtension', + type: 'mwAlienBlockExtension', attributes: { mw: { name: 'syntaxhighlight', @@ -1083,7 +1083,7 @@ }, originalDomElements: $( '<div about="#mwt1" data-parsoid="1"></div>' ).toArray() }, - { type: '/mwAlienExtension' }, + { type: '/mwAlienBlockExtension' }, { type: 'internalList' }, { type: '/internalList' } ], @@ -1091,6 +1091,45 @@ model.data.data[0].attributes.mw.attrs.lang = 'php5'; } }, + 'mw:AlienInlineExtension': { + body: + '<p>' + + '<img src="Foo" width="100" height="20" alt="Bar" typeof="mw:Extension/score"' + + ' data-mw="{"name":"score","attrs":{},"body":{"extsrc":"\\\\relative c' { e d c d e e e }"}}" ' + + ' data-parsoid="1" about="#mwt1" />' + + '</p>', + normalizedBody: + '<p>' + + '<span typeof="mw:Extension/score"' + + ' data-mw="{"name":"score","attrs":{},"body":{"extsrc":"\\\\relative c' { d d d e e e }"}}" ' + + ' src="Foo" width="100" height="20" alt="Bar" data-parsoid="1" about="#mwt1" />' + + '</p>', + data: [ + { type: 'paragraph' }, + { + type: 'mwAlienInlineExtension', + attributes: { + mw: { + name: 'score', + attrs: {}, + body: { + extsrc: '\\relative c\' { e d c d e e e }' + } + }, + originalIndex: 0, + originalMw: '{"name":"score","attrs":{},"body":{"extsrc":"\\\\relative c\' { e d c d e e e }"}}' + }, + originalDomElements: $( '<img src="Foo" width="100" height="20" alt="Bar" about="#mwt1" data-parsoid="1"></img>' ).toArray() + }, + { type: '/mwAlienInlineExtension' }, + { type: '/paragraph' }, + { type: 'internalList' }, + { type: '/internalList' } + ], + modify: function ( model ) { + model.data.data[1].attributes.mw.body.extsrc = '\\relative c\' { d d d e e e }'; + } + }, 'mw:Reference': { // Wikitext: // Foo<ref name="bar" /> Baz<ref group="g1" name=":0">Quux</ref> Whee<ref name="bar">[[Bar]]</ref> Yay<ref group="g1">No name</ref> Quux<ref name="bar">Different content</ref> Foo<ref group="g1" name="foo" /> diff --git a/modules/ve-mw/ui/contextitems/ve.ui.MWAlienExtensionContextItem.js b/modules/ve-mw/ui/contextitems/ve.ui.MWAlienExtensionContextItem.js index 0623f6f..534cb3e 100644 --- a/modules/ve-mw/ui/contextitems/ve.ui.MWAlienExtensionContextItem.js +++ b/modules/ve-mw/ui/contextitems/ve.ui.MWAlienExtensionContextItem.js @@ -35,7 +35,10 @@ ve.ui.MWAlienExtensionContextItem.static.icon = 'alienextension'; -ve.ui.MWAlienExtensionContextItem.static.modelClasses = [ ve.dm.MWAlienExtensionNode ]; +ve.ui.MWAlienExtensionContextItem.static.modelClasses = [ + ve.dm.MWAlienInlineExtensionNode, + ve.dm.MWAlienBlockExtensionNode +]; ve.ui.MWAlienExtensionContextItem.static.commandName = 'alienExtension'; diff --git a/modules/ve-mw/ui/inspectors/ve.ui.MWAlienExtensionInspector.js b/modules/ve-mw/ui/inspectors/ve.ui.MWAlienExtensionInspector.js index 17ea0f5..bb7c67a 100644 --- a/modules/ve-mw/ui/inspectors/ve.ui.MWAlienExtensionInspector.js +++ b/modules/ve-mw/ui/inspectors/ve.ui.MWAlienExtensionInspector.js @@ -33,7 +33,10 @@ ve.ui.MWAlienExtensionInspector.static.icon = 'alienextension'; -ve.ui.MWAlienExtensionInspector.static.modelClasses = [ ve.dm.MWAlienExtensionNode ]; +ve.ui.MWAlienExtensionInspector.static.modelClasses = [ + ve.dm.MWAlienInlineExtensionNode, + ve.dm.MWAlienBlockExtensionNode +]; /* Methods */ -- To view, visit https://gerrit.wikimedia.org/r/198740 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ib04234f740cf1f27c861d8b3cfeea5e323b94678 Gerrit-PatchSet: 7 Gerrit-Project: mediawiki/extensions/VisualEditor Gerrit-Branch: master Gerrit-Owner: Esanders <esand...@wikimedia.org> Gerrit-Reviewer: Catrope <roan.katt...@gmail.com> Gerrit-Reviewer: Jforrester <jforres...@wikimedia.org> Gerrit-Reviewer: Krinkle <krinklem...@gmail.com> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits