| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
ve.ui.MWExtensionPreviewDialog = function VeUiMWExtensionPreviewDialog() { |
| 19 |
|
| 20 |
ve.ui.MWExtensionPreviewDialog.super.apply( this, arguments ); |
| 21 |
|
| 22 |
this.updatePreviewDebounced = ve.debounce( this.updatePreview.bind( this ), 1000 ); |
| 23 |
}; |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
OO.inheritClass( ve.ui.MWExtensionPreviewDialog, ve.ui.MWExtensionDialog ); |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
ve.ui.MWExtensionPreviewDialog.prototype.initialize = function () { |
| 35 |
|
| 36 |
ve.ui.MWExtensionPreviewDialog.super.prototype.initialize.call( this ); |
| 37 |
|
| 38 |
|
| 39 |
this.previewNode = null; |
| 40 |
this.previewElement = new ve.ui.MWPreviewElement(); |
| 41 |
|
| 42 |
|
| 43 |
this.$element.addClass( 've-ui-mwExtensionPreviewDialog' ); |
| 44 |
}; |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
ve.ui.MWExtensionPreviewDialog.prototype.getSetupProcess = function ( data ) { |
| 50 |
return ve.ui.MWExtensionPreviewDialog.super.prototype.getSetupProcess.call( this, data ) |
| 51 |
.next( () => { |
| 52 |
let element; |
| 53 |
if ( this.selectedNode ) { |
| 54 |
element = this.selectedNode.getClonedElement(); |
| 55 |
} else { |
| 56 |
element = this.getNewElement(); |
| 57 |
} |
| 58 |
const linearData = [ element, { type: '/' + element.type } ]; |
| 59 |
if ( ve.dm.nodeFactory.isNodeContent( element.type ) ) { |
| 60 |
linearData.unshift( { type: 'paragraph' } ); |
| 61 |
linearData.push( { type: '/paragraph' } ); |
| 62 |
} |
| 63 |
linearData.push( |
| 64 |
{ type: 'internalList' }, |
| 65 |
{ type: '/internalList' } |
| 66 |
); |
| 67 |
|
| 68 |
const doc = data.fragment.getDocument().cloneWithData( linearData ); |
| 69 |
|
| 70 |
const rootNode = doc.getDocumentNode().children[ 0 ]; |
| 71 |
this.previewNode = doc.getNodesByType( element.type )[ 0 ]; |
| 72 |
this.previewElement.setModel( rootNode ); |
| 73 |
} ); |
| 74 |
}; |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
ve.ui.MWExtensionPreviewDialog.prototype.onChange = function () { |
| 80 |
|
| 81 |
ve.ui.MWExtensionPreviewDialog.super.prototype.onChange.call( this ); |
| 82 |
|
| 83 |
this.updatePreviewDebounced(); |
| 84 |
}; |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
ve.ui.MWExtensionPreviewDialog.prototype.updatePreview = function () { |
| 90 |
const mwData = ve.copy( this.previewNode.getAttribute( 'mw' ) ), |
| 91 |
doc = this.previewNode.getDocument(); |
| 92 |
|
| 93 |
this.updateMwData( mwData ); |
| 94 |
|
| 95 |
doc.commit( |
| 96 |
ve.dm.TransactionBuilder.static.newFromAttributeChanges( |
| 97 |
doc, this.previewNode.getOuterRange().start, { mw: mwData } |
| 98 |
) |
| 99 |
); |
| 100 |
this.previewElement.updatePreview(); |
| 101 |
}; |