mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-25 14:56:20 +00:00
Allow hybrids across Model subclasses
A node could already implement a toDataElements() function that returns a data element of another node type, but it couldn't return an annotation or a meta item. This is fixed now, and any dm.Model subclass can now morph into any other dm.Model subclass. I didn't originally plan to do this today at all, but doing this now makes my upcoming converter changes easier. Surprise feature! Change-Id: Ief6ac302094df084221a5a97c32a522b929c2960
This commit is contained in:
parent
76b080dce1
commit
1b5a376c28
|
@ -387,7 +387,7 @@ ve.dm.Converter.prototype.getDataFromDomRecursion = function ( domElement, wrapp
|
|||
|
||||
var i, childDomElement, childDomElements, childDataElement, text, childTypes, matches,
|
||||
wrappingParagraph, prevElement, childAnnotations, modelName, modelClass,
|
||||
annotation, annotationData, childIsContent, aboutGroup,
|
||||
annotation, childIsContent, aboutGroup,
|
||||
data = [],
|
||||
nextWhitespace = '',
|
||||
wrappedWhitespace = '',
|
||||
|
@ -420,10 +420,20 @@ ve.dm.Converter.prototype.getDataFromDomRecursion = function ( domElement, wrapp
|
|||
modelName = this.modelRegistry.matchElement( childDomElement );
|
||||
modelClass = this.modelRegistry.lookup( modelName ) || ve.dm.AlienNode;
|
||||
if ( modelClass.prototype instanceof ve.dm.Annotation ) {
|
||||
annotationData = this.createDataElement( modelClass, [ childDomElement ] );
|
||||
childDataElement = this.createDataElement( modelClass, [ childDomElement ] );
|
||||
} else {
|
||||
// Node or meta item
|
||||
aboutGroup = getAboutGroup( childDomElement );
|
||||
childDomElements = modelClass.static.enableAboutGrouping ?
|
||||
aboutGroup : [ childDomElement ];
|
||||
childDataElement = this.createDataElement( modelClass, childDomElements );
|
||||
}
|
||||
if ( modelClass.prototype instanceof ve.dm.Annotation && annotationData ) {
|
||||
annotation = this.annotationFactory.create( modelName, annotationData );
|
||||
|
||||
// Update modelClass to reflect the type we got back
|
||||
modelClass = this.modelRegistry.lookup( childDataElement.type );
|
||||
// Now take the appropriate action based on that
|
||||
if ( modelClass.prototype instanceof ve.dm.Annotation ) {
|
||||
annotation = this.annotationFactory.create( modelName, childDataElement );
|
||||
// Start wrapping if needed
|
||||
if ( !context.inWrapper && !context.expectingContent ) {
|
||||
startWrapping();
|
||||
|
@ -437,11 +447,6 @@ ve.dm.Converter.prototype.getDataFromDomRecursion = function ( domElement, wrapp
|
|||
);
|
||||
} else {
|
||||
// Node or meta item
|
||||
aboutGroup = getAboutGroup( childDomElement );
|
||||
childDomElements = modelClass.static.enableAboutGrouping ?
|
||||
aboutGroup : [ childDomElement ];
|
||||
childDataElement = this.createDataElement( modelClass, childDomElements );
|
||||
|
||||
if ( modelClass.prototype instanceof ve.dm.MetaItem ) {
|
||||
// No additional processing needed
|
||||
// Write to data and continue
|
||||
|
|
Loading…
Reference in a new issue