14
14
// You should have received a copy of the GNU Affero General Public License
15
15
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16
16
17
- import React , { useState } from "react" ;
17
+ import React from "react" ;
18
18
import Grid from "@mui/material/Grid" ;
19
- import "codemirror/theme/dracula.css" ;
20
- /** Code mirror */
21
- import CodeMirror , { Extension } from "@uiw/react-codemirror" ;
22
- import { StreamLanguage } from "@codemirror/stream-parser" ;
23
- import { json } from "@codemirror/lang-json" ;
24
- import { yaml } from "@codemirror/legacy-modes/mode/yaml" ;
25
-
26
- /** Code mirror */
27
19
import { Box , InputLabel , Tooltip } from "@mui/material" ;
28
20
import { Theme } from "@mui/material/styles" ;
29
21
import createStyles from "@mui/styles/createStyles" ;
30
22
import withStyles from "@mui/styles/withStyles" ;
31
23
import HelpIcon from "../../../../../icons/HelpIcon" ;
32
24
import { fieldBasic } from "../common/styleLibrary" ;
33
- import { CopyIcon , EditorThemeSwitchIcon } from "../../../../../icons" ;
25
+ import { CopyIcon } from "../../../../../icons" ;
34
26
import RBIconButton from "../../../Buckets/BucketDetails/SummaryItems/RBIconButton" ;
35
27
import CopyToClipboard from "react-copy-to-clipboard" ;
36
- import { EditorView } from "@codemirror/view " ;
28
+ import CodeEditor from "@uiw/react-textarea-code-editor " ;
37
29
38
30
interface ICodeWrapper {
39
31
value : string ;
@@ -52,104 +44,6 @@ const styles = (theme: Theme) =>
52
44
...fieldBasic ,
53
45
} ) ;
54
46
55
- const langHighlight : Record < string , any > = {
56
- json,
57
- yaml : ( ) => StreamLanguage . define ( yaml as any ) ,
58
- } ;
59
-
60
- const lightTheme = EditorView . theme (
61
- {
62
- "&" : {
63
- backgroundColor : "#FBFAFA" ,
64
- } ,
65
- ".cm-content" : {
66
- caretColor : "#05122B" ,
67
- } ,
68
- "&.cm-focused .cm-cursor" : {
69
- borderLeftColor : "#05122B" ,
70
- } ,
71
- ".cm-gutters" : {
72
- backgroundColor : "#FBFAFA" ,
73
- color : "#000000" ,
74
- border : "none" ,
75
- } ,
76
- ".cm-gutter.cm-foldGutter" : {
77
- borderRight : "1px solid #eaeaea" ,
78
- } ,
79
- ".cm-gutterElement" : {
80
- fontSize : "13px" ,
81
- } ,
82
- ".cm-line" : {
83
- fontSize : "13px" ,
84
- color : "#2781B0" ,
85
- "& .ͼc" : {
86
- color : "#C83B51" ,
87
- } ,
88
- } ,
89
- "& .ͼb" : {
90
- color : "#2781B0" ,
91
- } ,
92
- ".cm-activeLine" : {
93
- backgroundColor : "#dde1f1" ,
94
- } ,
95
- ".cm-matchingBracket" : {
96
- backgroundColor : "#05122B" ,
97
- color : "#ffffff" ,
98
- } ,
99
- ".cm-selectionMatch" : {
100
- backgroundColor : "#ebe7f1" ,
101
- } ,
102
- ".cm-selectionLayer" : {
103
- fontWeight : 500 ,
104
- } ,
105
- " .cm-selectionBackground" : {
106
- backgroundColor : "#a180c7" ,
107
- color : "#ffffff" ,
108
- } ,
109
- } ,
110
- {
111
- dark : false ,
112
- }
113
- ) ;
114
-
115
- const darkTheme = EditorView . theme (
116
- {
117
- "&" : {
118
- backgroundColor : "#282a36" ,
119
- color : "#ffb86c" ,
120
- } ,
121
-
122
- ".cm-gutter.cm-foldGutter" : {
123
- borderRight : "1px solid #eaeaea" ,
124
- } ,
125
- ".cm-gutterElement" : {
126
- fontSize : "13px" ,
127
- } ,
128
- ".cm-line" : {
129
- fontSize : "13px" ,
130
- "& .ͼd, & .ͼc" : {
131
- color : "#8e6cef" ,
132
- } ,
133
- } ,
134
- "& .ͼb" : {
135
- color : "#2781B0" ,
136
- } ,
137
- ".cm-activeLine" : {
138
- backgroundColor : "#44475a" ,
139
- } ,
140
- ".cm-matchingBracket" : {
141
- backgroundColor : "#842de5" ,
142
- color : "#ff79c6" ,
143
- } ,
144
- ".cm-selectionLayer .cm-selectionBackground" : {
145
- backgroundColor : "green" ,
146
- } ,
147
- } ,
148
- {
149
- dark : true ,
150
- }
151
- ) ;
152
-
153
47
const CodeMirrorWrapper = ( {
154
48
value,
155
49
label = "" ,
@@ -160,104 +54,75 @@ const CodeMirrorWrapper = ({
160
54
readOnly = false ,
161
55
editorHeight = "250px" ,
162
56
} : ICodeWrapper ) => {
163
- const [ isDarkTheme , setIsDarkTheme ] = useState < boolean > ( false ) ;
164
-
165
- //based on the language mode pick . default to json
166
- let extensionList : Extension [ ] = [ ] ;
167
- if ( langHighlight [ mode ] ) {
168
- extensionList = [ ...extensionList , langHighlight [ mode ] ( ) ] ;
169
- }
170
-
171
57
return (
172
58
< React . Fragment >
173
- < InputLabel className = { classes . inputLabel } >
174
- < span > { label } </ span >
175
- { tooltip !== "" && (
176
- < div className = { classes . tooltipContainer } >
177
- < Tooltip title = { tooltip } placement = "top-start" >
178
- < div className = { classes . tooltip } >
179
- < HelpIcon />
180
- </ div >
181
- </ Tooltip >
182
- </ div >
183
- ) }
184
- </ InputLabel >
185
59
< Grid item xs = { 12 } >
186
- < br />
60
+ < InputLabel className = { classes . inputLabel } >
61
+ < span > { label } </ span >
62
+ { tooltip !== "" && (
63
+ < div className = { classes . tooltipContainer } >
64
+ < Tooltip title = { tooltip } placement = "top-start" >
65
+ < div className = { classes . tooltip } >
66
+ < HelpIcon />
67
+ </ div >
68
+ </ Tooltip >
69
+ </ div >
70
+ ) }
71
+ </ InputLabel >
187
72
</ Grid >
188
73
74
+ < Grid item xs = { 12 } style = { { maxHeight : editorHeight , overflow : "auto" } } >
75
+ < CodeEditor
76
+ value = { value }
77
+ language = { mode }
78
+ onChange = { ( evn ) => {
79
+ onBeforeChange ( null , null , evn . target . value ) ;
80
+ } }
81
+ padding = { 15 }
82
+ style = { {
83
+ fontSize : 12 ,
84
+ backgroundColor : "#fefefe" ,
85
+ fontFamily :
86
+ "ui-monospace,SFMono-Regular,SF Mono,Consolas,Liberation Mono,Menlo,monospace" ,
87
+ } }
88
+ />
89
+ </ Grid >
189
90
< Grid
190
91
item
191
92
xs = { 12 }
192
93
sx = { {
193
- border : "1px solid #eaeaea" ,
94
+ borderTop : "1px solid #eaeaea" ,
95
+ background : "#f7f7f7" ,
194
96
} }
195
97
>
196
- < Grid item xs = { 12 } >
197
- < CodeMirror
198
- value = { value }
199
- theme = { isDarkTheme ? darkTheme : lightTheme }
200
- extensions = { extensionList }
201
- editable = { ! readOnly }
202
- basicSetup = { true }
203
- height = { editorHeight }
204
- onChange = { ( v : string , vu : any ) => {
205
- onBeforeChange ( null , null , v ) ;
206
- } }
207
- />
208
- </ Grid >
209
- < Grid
210
- item
211
- xs = { 12 }
98
+ < Box
212
99
sx = { {
213
- borderTop : "1px solid #eaeaea" ,
214
- background : isDarkTheme ? "#282c34" : "#f7f7f7" ,
215
- } }
216
- >
217
- < Box
218
- className = { isDarkTheme ? "dark-theme" : "" }
219
- sx = { {
220
- display : "flex" ,
221
- alignItems : "center" ,
100
+ display : "flex" ,
101
+ alignItems : "center" ,
102
+ padding : "2px" ,
103
+ paddingRight : "5px" ,
104
+ justifyContent : "flex-end" ,
105
+ "& button" : {
106
+ height : "26px" ,
107
+ width : "26px" ,
222
108
padding : "2px" ,
223
- paddingRight : "5px" ,
224
- justifyContent : "flex-end" ,
225
- "& button" : {
226
- height : "26px" ,
227
- width : "26px" ,
228
- padding : "2px" ,
229
- " .min-icon" : {
230
- marginLeft : "0" ,
231
- } ,
109
+ " .min-icon" : {
110
+ marginLeft : "0" ,
232
111
} ,
233
-
234
- "&.dark-theme button" : {
235
- background : "#FFFFFF" ,
236
- } ,
237
- } }
238
- >
112
+ } ,
113
+ } }
114
+ >
115
+ < CopyToClipboard text = { value } >
239
116
< RBIconButton
240
- tooltip = { "Change theme" }
241
- onClick = { ( ) => {
242
- setIsDarkTheme ( ! isDarkTheme ) ;
243
- } }
117
+ tooltip = { "Copy to Clipboard" }
118
+ onClick = { ( ) => { } }
244
119
text = { "" }
245
- icon = { < EditorThemeSwitchIcon /> }
120
+ icon = { < CopyIcon /> }
246
121
color = { "primary" }
247
122
variant = { "outlined" }
248
123
/>
249
- < CopyToClipboard text = { value } >
250
- < RBIconButton
251
- tooltip = { "Copy to Clipboard" }
252
- onClick = { ( ) => { } }
253
- text = { "" }
254
- icon = { < CopyIcon /> }
255
- color = { "primary" }
256
- variant = { "outlined" }
257
- />
258
- </ CopyToClipboard >
259
- </ Box >
260
- </ Grid >
124
+ </ CopyToClipboard >
125
+ </ Box >
261
126
</ Grid >
262
127
</ React . Fragment >
263
128
) ;
0 commit comments