2015-11-18 07:25:01 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor UserInterface MWExtensionPreviewDialog class.
|
|
|
|
*
|
2023-12-01 16:06:11 +00:00
|
|
|
* @copyright See AUTHORS.txt
|
2015-11-18 07:25:01 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Dialog for editing generic MediaWiki extensions with a preview.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @abstract
|
|
|
|
* @extends ve.ui.MWExtensionDialog
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {Object} [config] Configuration options
|
|
|
|
*/
|
|
|
|
ve.ui.MWExtensionPreviewDialog = function VeUiMWExtensionPreviewDialog() {
|
|
|
|
// Parent constructor
|
|
|
|
ve.ui.MWExtensionPreviewDialog.super.apply( this, arguments );
|
|
|
|
|
2022-07-14 16:14:37 +00:00
|
|
|
this.updatePreviewDebounced = ve.debounce( this.updatePreview.bind( this ), 1000 );
|
2015-11-18 07:25:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
OO.inheritClass( ve.ui.MWExtensionPreviewDialog, ve.ui.MWExtensionDialog );
|
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWExtensionPreviewDialog.prototype.initialize = function () {
|
|
|
|
// Parent method
|
|
|
|
ve.ui.MWExtensionPreviewDialog.super.prototype.initialize.call( this );
|
|
|
|
|
|
|
|
// Properties
|
|
|
|
this.previewNode = null;
|
2015-11-23 22:28:57 +00:00
|
|
|
this.previewElement = new ve.ui.MWPreviewElement();
|
2015-11-18 07:25:01 +00:00
|
|
|
|
|
|
|
// Initialization
|
|
|
|
this.$element.addClass( 've-ui-mwExtensionPreviewDialog' );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWExtensionPreviewDialog.prototype.getSetupProcess = function ( data ) {
|
|
|
|
return ve.ui.MWExtensionPreviewDialog.super.prototype.getSetupProcess.call( this, data )
|
2024-04-30 21:25:39 +00:00
|
|
|
.next( () => {
|
2024-05-21 14:22:56 +00:00
|
|
|
let element;
|
2015-11-18 07:25:01 +00:00
|
|
|
if ( this.selectedNode ) {
|
2016-07-26 15:06:07 +00:00
|
|
|
element = this.selectedNode.getClonedElement();
|
2015-11-18 07:25:01 +00:00
|
|
|
} else {
|
|
|
|
element = this.getNewElement();
|
|
|
|
}
|
2024-05-29 16:03:23 +00:00
|
|
|
const linearData = [ element, { type: '/' + element.type } ];
|
2016-07-26 15:06:07 +00:00
|
|
|
if ( ve.dm.nodeFactory.isNodeContent( element.type ) ) {
|
2024-05-29 16:03:23 +00:00
|
|
|
linearData.unshift( { type: 'paragraph' } );
|
|
|
|
linearData.push( { type: '/paragraph' } );
|
2016-07-26 15:06:07 +00:00
|
|
|
}
|
2024-05-29 16:03:23 +00:00
|
|
|
linearData.push(
|
2016-07-26 15:06:07 +00:00
|
|
|
{ type: 'internalList' },
|
|
|
|
{ type: '/internalList' }
|
2024-05-29 16:03:23 +00:00
|
|
|
);
|
|
|
|
// We assume that WindowAction pass
|
|
|
|
const doc = data.fragment.getDocument().cloneWithData( linearData );
|
2016-07-26 15:06:07 +00:00
|
|
|
|
2024-05-21 14:22:56 +00:00
|
|
|
const rootNode = doc.getDocumentNode().children[ 0 ];
|
2016-07-26 15:06:07 +00:00
|
|
|
this.previewNode = doc.getNodesByType( element.type )[ 0 ];
|
|
|
|
this.previewElement.setModel( rootNode );
|
2024-04-30 21:25:39 +00:00
|
|
|
} );
|
2015-11-18 07:25:01 +00:00
|
|
|
};
|
|
|
|
|
2017-01-14 23:03:36 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.ui.MWExtensionPreviewDialog.prototype.onChange = function () {
|
|
|
|
// Parent method
|
|
|
|
ve.ui.MWExtensionPreviewDialog.super.prototype.onChange.call( this );
|
|
|
|
|
|
|
|
this.updatePreviewDebounced();
|
|
|
|
};
|
|
|
|
|
2015-11-18 07:25:01 +00:00
|
|
|
/**
|
|
|
|
* Update the node rendering to reflect the current content in the dialog.
|
|
|
|
*/
|
|
|
|
ve.ui.MWExtensionPreviewDialog.prototype.updatePreview = function () {
|
2024-05-21 14:22:56 +00:00
|
|
|
const mwData = ve.copy( this.previewNode.getAttribute( 'mw' ) ),
|
2015-11-18 07:25:01 +00:00
|
|
|
doc = this.previewNode.getDocument();
|
|
|
|
|
|
|
|
this.updateMwData( mwData );
|
|
|
|
|
|
|
|
doc.commit(
|
2016-11-30 22:03:03 +00:00
|
|
|
ve.dm.TransactionBuilder.static.newFromAttributeChanges(
|
2015-11-18 07:25:01 +00:00
|
|
|
doc, this.previewNode.getOuterRange().start, { mw: mwData }
|
|
|
|
)
|
|
|
|
);
|
|
|
|
this.previewElement.updatePreview();
|
|
|
|
};
|