Debian Codegraph @

extensions/VisualEditor/lib/ve/src/ui/inspectors/ve.ui.CommentInspector.js

raw symbols SCIP
1 /*!
2 * VisualEditor UserInterface CommentInspector class.
3 *
4 * @copyright See AUTHORS.txt
5 */
6
7 /**
8 * Comment inspector.
9 *
10 * @class
11 * @extends ve.ui.NodeInspector
12 *
13 * @constructor
14 * @param {Object} [config] Configuration options
15 */
16 ve.ui.CommentInspector = function VeUiCommentInspector() {
17 // Parent constructor
18 ve.ui.CommentInspector.super.apply( this, arguments );
19 };
20
21 /* Inheritance */
22
23 OO.inheritClass( ve.ui.CommentInspector, ve.ui.NodeInspector );
24
25 /* Static properties */
26
27 ve.ui.CommentInspector.static.name = 'comment';
28
29 ve.ui.CommentInspector.static.title =
30 OO.ui.deferMsg( 'visualeditor-commentinspector-title' );
31
32 ve.ui.CommentInspector.static.modelClasses = [ ve.dm.CommentNode ];
33
34 ve.ui.CommentInspector.static.size = 'large';
35
36 ve.ui.CommentInspector.static.actions = [
37 {
38 action: 'remove',
39 label: OO.ui.deferMsg( 'visualeditor-inspector-remove-tooltip' ),
40 flags: 'destructive',
41 modes: 'edit'
42 },
43 ...ve.ui.CommentInspector.super.static.actions
44 ];
45
46 /* Methods */
47
48 /**
49 * Handle frame ready events.
50 */
51 ve.ui.CommentInspector.prototype.initialize = function () {
52 // Parent method
53 ve.ui.CommentInspector.super.prototype.initialize.call( this );
54
55 this.textWidget = new ve.ui.WhitespacePreservingTextInputWidget( {
56 autosize: true
57 } );
58 this.textWidget.connect( this, { resize: 'updateSize' } );
59 this.textWidget.$input.attr( 'aria-label', OO.ui.deferMsg( 'visualeditor-commentinspector-title' ) );
60
61 this.$content.addClass( 've-ui-commentInspector-content' );
62 this.form.$element.append( this.textWidget.$element );
63 };
64
65 /**
66 * @inheritdoc
67 */
68 ve.ui.CommentInspector.prototype.getActionProcess = function ( action ) {
69 if ( action === 'remove' || action === 'insert' ) {
70 return new OO.ui.Process( () => {
71 this.close( { action: action } );
72 } );
73 }
74 return ve.ui.CommentInspector.super.prototype.getActionProcess.call( this, action );
75 };
76
77 /**
78 * Handle the inspector being setup.
79 *
80 * @param {Object} [data] Inspector opening data
81 * @return {OO.ui.Process}
82 */
83 ve.ui.CommentInspector.prototype.getSetupProcess = function ( data ) {
84 return ve.ui.CommentInspector.super.prototype.getSetupProcess.call( this, data )
85 .next( () => {
86 this.getFragment().getSurface().pushStaging();
87
88 this.commentNode = this.getSelectedNode();
89 if ( this.commentNode ) {
90 this.textWidget.setValueAndWhitespace( this.commentNode.getAttribute( 'text' ) || '' );
91 } else {
92 this.textWidget.setWhitespace( [ ' ', ' ' ] );
93 this.getFragment().insertContent( [
94 {
95 type: 'comment',
96 attributes: { text: '' }
97 },
98 { type: '/comment' }
99 ] ).select();
100 this.commentNode = this.getSelectedNode();
101 }
102 this.textWidget.setReadOnly( this.isReadOnly() );
103 } );
104 };
105
106 /**
107 * @inheritdoc
108 */
109 ve.ui.CommentInspector.prototype.getReadyProcess = function ( data ) {
110 return ve.ui.CommentInspector.super.prototype.getReadyProcess.call( this, data )
111 .next( () => {
112 this.textWidget.focus();
113 } );
114 };
115
116 /**
117 * @inheritdoc
118 */
119 ve.ui.CommentInspector.prototype.getTeardownProcess = function ( data ) {
120 data = data || {};
121 return ve.ui.CommentInspector.super.prototype.getTeardownProcess.call( this, data )
122 .first( () => {
123 const surfaceModel = this.getFragment().getSurface();
124
125 // data.action can be 'done', 'remove' or undefined (cancel)
126 if ( data.action === 'done' && this.textWidget.getValue() !== '' ) {
127 // Edit comment node
128 this.getFragment().changeAttributes( { text: this.textWidget.getValueAndWhitespace() } );
129 surfaceModel.applyStaging();
130 } else {
131 surfaceModel.popStaging();
132 if ( data.action === 'remove' || data.action === 'done' ) {
133 this.getFragment().removeContent();
134 }
135 }
136
137 // Reset inspector
138 this.textWidget.setValueAndWhitespace( '' );
139 } );
140 };
141
142 /* Registration */
143
144 ve.ui.windowFactory.register( ve.ui.CommentInspector );