Debian Codegraph @

extensions/VisualEditor/lib/ve/rebaser/editor.js

raw symbols SCIP
1 /*!
2 * VisualEditor rebaser demo
3 *
4 * @copyright See AUTHORS.txt
5 */
6
7 ( function () {
8 function RebaserTarget() {
9 RebaserTarget.super.apply( this, arguments );
10
11 // HACK: Disable redo command until supported (T185706)
12 ve.ui.commandRegistry.unregister( 'redo' );
13 }
14
15 OO.inheritClass( RebaserTarget, ve.init.sa.Target );
16
17 const linkIndex = RebaserTarget.static.toolbarGroups.findIndex( ( group ) => group.name === 'link' );
18 RebaserTarget.static.toolbarGroups = ve.copy( RebaserTarget.static.toolbarGroups );
19 RebaserTarget.static.toolbarGroups.splice( linkIndex + 1, 0, {
20 name: 'commentAnnotation',
21 include: [ 'commentAnnotation' ]
22 } );
23 RebaserTarget.static.toolbarGroups.push(
24 {
25 name: 'authorList',
26 align: 'after',
27 include: [ 'authorList' ]
28 }
29 );
30
31 new ve.init.sa.Platform( ve.messagePaths ).initialize().done( function () {
32 const progressDeferred = ve.createDeferred(),
33 panel = new OO.ui.PanelLayout( {
34 // eslint-disable-next-line no-jquery/no-global-selector
35 $element: $( '.ve-demo-editor' ),
36 expanded: false,
37 framed: true
38 } ),
39 target = new RebaserTarget();
40
41 panel.$element.append( target.$element );
42
43 // Add a dummy surface while the doc is loading
44 const dummySurface = target.addSurface( ve.dm.converter.getModelFromDom( ve.createDocumentFromHtml( '' ) ) );
45 dummySurface.setReadOnly( true );
46
47 // TODO: Create the correct model surface type (ve.ui.Surface#createModel)
48 const surfaceModel = new ve.dm.Surface( ve.dm.converter.getModelFromDom( ve.createDocumentFromHtml( '' ) ) );
49 surfaceModel.createSynchronizer(
50 ve.docName,
51 { server: this.rebaserUrl }
52 );
53
54 dummySurface.createProgress( progressDeferred.promise(), ve.msg( 'visualeditor-rebase-client-connecting' ), true );
55
56 surfaceModel.synchronizer.once( 'initDoc', ( error ) => {
57 progressDeferred.resolve();
58 target.clearSurfaces();
59 if ( error ) {
60 OO.ui.alert(
61 $( '<p>' ).append(
62 ve.htmlMsg( 'visualeditor-rebase-corrupted-document-error', $( '<pre>' ).text( error.stack ) )
63 ),
64 { title: ve.msg( 'visualeditor-rebase-corrupted-document-title' ), size: 'large' }
65 ).then( () => {
66 // TODO: Go back to landing page?
67 } );
68 return;
69 }
70 // Don't add the surface until the history has been applied
71 target.addSurface( surfaceModel );
72 target.getSurface().getView().focus();
73 } );
74
75 } );
76 }() );