@@ -2,20 +2,13 @@ import React from 'react';
2
2
import lodash from 'lodash' ;
3
3
import { PropTypes } from 'prop-types' ;
4
4
import { Resizable } from 'react-resizable' ;
5
- import 'brace' ;
6
- import AceEditor from 'react-ace' ;
5
+ import AceEditor from 'react-ace-builds' ;
7
6
import { Button , ButtonGroup , ButtonToolbar , OverlayTrigger , Tooltip } from 'react-bootstrap' ;
8
7
9
8
import { ClipboardButton } from 'components/common' ;
10
9
11
- import 'brace/mode/json' ;
12
- import 'brace/mode/lua' ;
13
- import 'brace/mode/markdown' ;
14
- import 'brace/mode/text' ;
15
- import 'brace/mode/yaml' ;
16
- import 'brace/theme/tomorrow' ;
17
- import 'brace/theme/monokai' ;
18
10
import style from './SourceCodeEditor.css' ;
11
+ import './webpack-resolver' ;
19
12
20
13
/**
21
14
* Component that renders a source code editor input. This is what powers the pipeline rules and collector
@@ -74,7 +67,7 @@ class SourceCodeEditor extends React.Component {
74
67
toolbar : true ,
75
68
value : '' ,
76
69
width : Infinity ,
77
- }
70
+ } ;
78
71
79
72
constructor ( props ) {
80
73
super ( props ) ;
@@ -86,61 +79,81 @@ class SourceCodeEditor extends React.Component {
86
79
}
87
80
88
81
componentDidUpdate ( prevProps ) {
89
- if ( this . props . height !== prevProps . height || this . props . width !== prevProps . width ) {
82
+ const { height, width } = this . props ;
83
+ if ( height !== prevProps . height || width !== prevProps . width ) {
90
84
this . reloadEditor ( ) ;
91
85
}
92
86
}
93
87
94
88
handleResize = ( event , { size } ) => {
95
89
const { height, width } = size ;
96
90
this . setState ( { height : height , width : width } , this . reloadEditor ) ;
97
- }
91
+ } ;
98
92
99
93
reloadEditor = ( ) => {
100
- if ( this . props . resizable ) {
94
+ const { resizable } = this . props ;
95
+ if ( resizable ) {
101
96
this . reactAce . editor . resize ( ) ;
102
97
}
103
- }
98
+ } ;
104
99
100
+ /* eslint-disable-next-line react/destructuring-assignment */
105
101
isCopyDisabled = ( ) => this . props . readOnly || this . state . selectedText === '' ;
106
102
103
+ /* eslint-disable-next-line react/destructuring-assignment */
107
104
isPasteDisabled = ( ) => this . props . readOnly ;
108
105
106
+ /* eslint-disable-next-line react/destructuring-assignment */
109
107
isRedoDisabled = ( ) => this . props . readOnly || ! this . reactAce || ! this . reactAce . editor . getSession ( ) . getUndoManager ( ) . hasRedo ( ) ;
110
108
109
+ /* eslint-disable-next-line react/destructuring-assignment */
111
110
isUndoDisabled = ( ) => this . props . readOnly || ! this . reactAce || ! this . reactAce . editor . getSession ( ) . getUndoManager ( ) . hasUndo ( ) ;
112
111
113
112
handleRedo = ( ) => {
114
113
this . reactAce . editor . redo ( ) ;
115
114
this . focusEditor ( ) ;
116
- }
115
+ } ;
117
116
118
117
handleUndo = ( ) => {
119
118
this . reactAce . editor . undo ( ) ;
120
119
this . focusEditor ( ) ;
121
- }
120
+ } ;
122
121
123
122
handleSelectionChange = ( selection ) => {
124
- if ( ! this . reactAce || ! this . props . toolbar || this . props . readOnly ) {
123
+ const { toolbar, readOnly } = this . props ;
124
+ if ( ! this . reactAce || ! toolbar || readOnly ) {
125
125
return ;
126
126
}
127
127
const selectedText = this . reactAce . editor . getSession ( ) . getTextRange ( selection . getRange ( ) ) ;
128
128
this . setState ( { selectedText : selectedText } ) ;
129
- }
129
+ } ;
130
130
131
131
focusEditor = ( ) => {
132
132
this . reactAce . editor . focus ( ) ;
133
- }
133
+ } ;
134
134
135
135
render ( ) {
136
- const { height, width } = this . state ;
137
- const { theme, resizable } = this . props ;
136
+ const { height, width, selectedText } = this . state ;
137
+ const {
138
+ theme,
139
+ resizable,
140
+ toolbar,
141
+ annotations,
142
+ focus,
143
+ fontSize,
144
+ mode,
145
+ id,
146
+ onLoad,
147
+ onChange,
148
+ readOnly,
149
+ value,
150
+ } = this . props ;
138
151
const validCssWidth = lodash . isFinite ( width ) ? width : '100%' ;
139
152
const containerStyle = `${ style . sourceCodeEditor } ${ theme !== 'light' && style . darkMode } ${ ! resizable && style . static } ` ;
140
153
const overlay = < Tooltip id = "paste-button-tooltip" > Press Ctrl+V (⌘V in macOS) or select Edit → Paste to paste from clipboard.</ Tooltip > ;
141
154
return (
142
155
< div >
143
- { this . props . toolbar
156
+ { toolbar
144
157
&& (
145
158
< div className = { style . toolbar } style = { { width : validCssWidth } } >
146
159
< ButtonToolbar >
@@ -149,7 +162,7 @@ class SourceCodeEditor extends React.Component {
149
162
bsStyle = "link"
150
163
bsSize = "sm"
151
164
onSuccess = { this . focusEditor }
152
- text = { this . state . selectedText }
165
+ text = { selectedText }
153
166
buttonTitle = "Copy (Ctrl+C / ⌘C)"
154
167
disabled = { this . isCopyDisabled ( ) } />
155
168
< OverlayTrigger placement = "top" trigger = "click" overlay = { overlay } rootClose >
@@ -184,19 +197,19 @@ class SourceCodeEditor extends React.Component {
184
197
onResize = { this . handleResize } >
185
198
< div className = { containerStyle } style = { { height : height , width : validCssWidth } } >
186
199
< AceEditor ref = { ( c ) => { this . reactAce = c ; } }
187
- annotations = { this . props . annotations }
200
+ annotations = { annotations }
188
201
editorProps = { { $blockScrolling : 'Infinity' } }
189
- focus = { this . props . focus }
190
- fontSize = { this . props . fontSize }
191
- mode = { this . props . mode }
192
- theme = { this . props . theme === 'light' ? 'tomorrow' : 'monokai' }
193
- name = { this . props . id }
202
+ focus = { focus }
203
+ fontSize = { fontSize }
204
+ mode = { mode }
205
+ theme = { theme === 'light' ? 'tomorrow' : 'monokai' }
206
+ name = { id }
194
207
height = "100%"
195
- onLoad = { this . props . onLoad }
196
- onChange = { this . props . onChange }
208
+ onLoad = { onLoad }
209
+ onChange = { onChange }
197
210
onSelectionChange = { this . handleSelectionChange }
198
- readOnly = { this . props . readOnly }
199
- value = { this . props . value }
211
+ readOnly = { readOnly }
212
+ value = { value }
200
213
width = "100%" />
201
214
</ div >
202
215
</ Resizable >
0 commit comments