| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
ve.ui.MWLiveExtensionInspector = function VeUiMWLiveExtensionInspector() { |
| 19 |
|
| 20 |
ve.ui.MWLiveExtensionInspector.super.apply( this, arguments ); |
| 21 |
|
| 22 |
this.updatePreviewDebounced = ve.debounce( this.updatePreview.bind( this ), 1000 ); |
| 23 |
}; |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
OO.inheritClass( ve.ui.MWLiveExtensionInspector, ve.ui.MWExtensionInspector ); |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
ve.ui.MWLiveExtensionInspector.prototype.initialize = function () { |
| 35 |
|
| 36 |
ve.ui.MWLiveExtensionInspector.super.prototype.initialize.call( this ); |
| 37 |
|
| 38 |
this.generatedContentsError = new ve.ui.MWExpandableErrorElement(); |
| 39 |
this.form.$element.append( this.generatedContentsError.$element ); |
| 40 |
}; |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
ve.ui.MWLiveExtensionInspector.prototype.getSetupProcess = function ( data ) { |
| 46 |
return ve.ui.MWLiveExtensionInspector.super.prototype.getSetupProcess.call( this, data ) |
| 47 |
.next( () => { |
| 48 |
const element = this.getNewElement(); |
| 49 |
|
| 50 |
this.getFragment().getSurface().pushStaging(); |
| 51 |
|
| 52 |
if ( !this.selectedNode ) { |
| 53 |
|
| 54 |
|
| 55 |
this.fragment = this.getFragment().collapseToEnd().insertContent( [ |
| 56 |
element, |
| 57 |
{ type: '/' + element.type } |
| 58 |
] ); |
| 59 |
|
| 60 |
|
| 61 |
if ( this.getFragment().getSelection().getRange().getLength() === 4 ) { |
| 62 |
this.fragment = this.getFragment().adjustLinearSelection( 1, -1 ); |
| 63 |
} |
| 64 |
this.getFragment().select(); |
| 65 |
this.selectedNode = this.getFragment().getSelectedNode(); |
| 66 |
} |
| 67 |
this.input.on( 'change', this.onChangeHandler ); |
| 68 |
this.generatedContentsError.connect( this, { |
| 69 |
update: 'updateSize' |
| 70 |
} ); |
| 71 |
this.selectedNode.connect( this, { |
| 72 |
generatedContentsError: 'showGeneratedContentsError' |
| 73 |
} ); |
| 74 |
} ); |
| 75 |
}; |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
ve.ui.MWLiveExtensionInspector.prototype.getTeardownProcess = function ( data ) { |
| 81 |
return ve.ui.MWLiveExtensionInspector.super.prototype.getTeardownProcess.call( this, data ) |
| 82 |
.first( () => { |
| 83 |
this.input.off( 'change', this.onChangeHandler ); |
| 84 |
this.generatedContentsError.clear(); |
| 85 |
this.generatedContentsError.disconnect( this ); |
| 86 |
this.selectedNode.disconnect( this ); |
| 87 |
if ( data === undefined ) { |
| 88 |
this.getFragment().getSurface().popStaging(); |
| 89 |
} |
| 90 |
} ); |
| 91 |
}; |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
ve.ui.MWLiveExtensionInspector.prototype.insertOrUpdateNode = function () { |
| 97 |
|
| 98 |
|
| 99 |
this.updatePreview(); |
| 100 |
this.getFragment().getSurface().applyStaging(); |
| 101 |
|
| 102 |
this.selectedNode.emit( 'update', false ); |
| 103 |
}; |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
ve.ui.MWLiveExtensionInspector.prototype.removeNode = function () { |
| 109 |
this.getFragment().getSurface().popStaging(); |
| 110 |
|
| 111 |
|
| 112 |
ve.ui.MWLiveExtensionInspector.super.prototype.removeNode.call( this ); |
| 113 |
}; |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
ve.ui.MWLiveExtensionInspector.prototype.onChange = function () { |
| 119 |
|
| 120 |
ve.ui.MWLiveExtensionInspector.super.prototype.onChange.call( this ); |
| 121 |
|
| 122 |
this.updatePreviewDebounced(); |
| 123 |
}; |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
ve.ui.MWLiveExtensionInspector.prototype.updatePreview = function () { |
| 129 |
if ( !this.selectedNode ) { |
| 130 |
|
| 131 |
return; |
| 132 |
} |
| 133 |
const mwData = ve.copy( this.selectedNode.getAttribute( 'mw' ) ); |
| 134 |
|
| 135 |
this.updateMwData( mwData ); |
| 136 |
|
| 137 |
this.hideGeneratedContentsError(); |
| 138 |
|
| 139 |
if ( this.visible ) { |
| 140 |
this.getFragment().changeAttributes( { mw: mwData } ); |
| 141 |
} |
| 142 |
}; |
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
ve.ui.MWLiveExtensionInspector.prototype.showGeneratedContentsError = function ( $element ) { |
| 150 |
this.generatedContentsError.show( this.formatGeneratedContentsError( $element ) ); |
| 151 |
}; |
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
ve.ui.MWLiveExtensionInspector.prototype.hideGeneratedContentsError = function () { |
| 157 |
this.generatedContentsError.clear(); |
| 158 |
}; |
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
ve.ui.MWLiveExtensionInspector.prototype.formatGeneratedContentsError = function ( $element ) { |
| 169 |
return $element; |
| 170 |
}; |