@@ -8,16 +8,20 @@ import {
8
8
eventHandlerControl ,
9
9
stringExposingStateControl ,
10
10
BoolControl ,
11
+ LabelControl ,
12
+ styleControl ,
11
13
dropdownControl ,
12
14
AutoHeightControl ,
13
15
} from "lowcoder-sdk" ;
16
+ import { CodeEditorContainerStyle , LabelStyle } from "comps/controls/styleControlConstants" ;
14
17
import { useResizeDetector } from "react-resize-detector" ;
15
18
import Editor from "@monaco-editor/react" ;
16
19
import { styled } from "styled-components" ;
17
20
import { trans } from "i18n" ;
18
21
import { useRef , useCallback , useLayoutEffect } from "react" ;
19
22
import debounce from "lodash/debounce" ;
20
23
import * as monacoEditor from "monaco-editor" ;
24
+ import { formDataChildren , FormDataPropertyView } from "../../comps/formComp/formDataConstants" ;
21
25
22
26
const CodeEditorWrapper = styled . div `
23
27
border: 1px solid #dddddd;
@@ -58,6 +62,7 @@ let CodeEditorTmpComp = (function () {
58
62
language : "yaml" ,
59
63
theme : "light" ,
60
64
lineNumbers : "on" ,
65
+ wordWrap : "on" ,
61
66
lightbulb : monacoEditor . editor . ShowLightbulbIconMode . OnCode ,
62
67
enabled : true ,
63
68
disabled : false ,
@@ -76,25 +81,45 @@ let CodeEditorTmpComp = (function () {
76
81
{ label : trans ( "codeEditor.lineNumberOptions.relative" ) , value : "relative" } ,
77
82
] . sort ( ( a , b ) => a . label . localeCompare ( b . label ) )
78
83
84
+ const wordWrapOptions = [
85
+ { label : trans ( "codeEditor.wordWrapOptions.on" ) , value : "on" } ,
86
+ { label : trans ( "codeEditor.wordWrapOptions.off" ) , value : "off" } ,
87
+ { label : trans ( "codeEditor.wordWrapOptions.wordWrapColumn" ) , value : "wordWrapColumn" } ,
88
+ { label : trans ( "codeEditor.wordWrapOptions.bounded" ) , value : "bounded" } ,
89
+ ] . sort ( ( a , b ) => a . label . localeCompare ( b . label ) )
90
+
79
91
const childrenMap = {
80
92
autoHeight : withDefault ( AutoHeightControl , "auto" ) ,
81
93
language : dropdownControl ( languages , defaultValues . language ) ,
82
94
theme : dropdownControl ( themes , defaultValues . theme ) ,
83
95
lineNumbers : dropdownControl ( lineNumbersOptions , defaultValues . lineNumbers ) ,
96
+ wordWrap : dropdownControl ( wordWrapOptions , defaultValues . wordWrap ) ,
84
97
minimap : withDefault ( BoolControl , defaultValues . enabled ) ,
85
98
stickyScroll : withDefault ( BoolControl , defaultValues . enabled ) ,
86
99
lightbulb : withDefault ( BoolControl , defaultValues . enabled ) ,
87
100
hover : withDefault ( BoolControl , defaultValues . enabled ) ,
88
101
folding : withDefault ( BoolControl , defaultValues . enabled ) ,
89
102
readOnly : withDefault ( BoolControl , defaultValues . disabled ) ,
90
103
value : stringExposingStateControl ( "text" , defaultValues . value ) ,
104
+ required : withDefault ( BoolControl , defaultValues . disabled ) ,
105
+ label : withDefault ( LabelControl , {
106
+ text : "Code Editor" ,
107
+ tooltip : "" ,
108
+ hidden : false ,
109
+ widthUnit : "%" ,
110
+ position : "column" ,
111
+ align : "left"
112
+ } ) ,
113
+ style : styleControl ( CodeEditorContainerStyle , "style" ) ,
114
+ labelStyle : styleControl ( LabelStyle , 'labelStyle' ) ,
91
115
onEvent : eventHandlerControl ( [
92
116
{
93
117
label : "onChange" ,
94
118
value : "change" ,
95
119
description : "Triggers when data changes" ,
96
120
} ,
97
121
] as const ) ,
122
+ ...formDataChildren ,
98
123
} ;
99
124
100
125
return new UICompBuilder ( childrenMap , ( props ) => {
@@ -174,7 +199,10 @@ let CodeEditorTmpComp = (function () {
174
199
}
175
200
} , [ props . value . value ] ) ;
176
201
177
- return (
202
+ return props . label ( {
203
+ required : props . required ,
204
+ style : props . style ,
205
+ children : (
178
206
< CodeEditorWrapper
179
207
ref = { conRef }
180
208
style = { {
@@ -210,6 +238,7 @@ let CodeEditorTmpComp = (function () {
210
238
hover : {
211
239
enabled : props . hover ,
212
240
} ,
241
+ wordWrap : props . wordWrap as 'off' | 'on' | 'wordWrapColumn' | 'bounded' ,
213
242
folding : props . folding ,
214
243
readOnly : props . readOnly ,
215
244
lineNumbers : props . lineNumbers as monacoEditor . editor . LineNumbersType ,
@@ -219,7 +248,8 @@ let CodeEditorTmpComp = (function () {
219
248
onChange = { handleOnChange }
220
249
/>
221
250
</ CodeEditorWrapper >
222
- ) ;
251
+ )
252
+ } )
223
253
} )
224
254
. setPropertyViewFn ( ( children : any ) => {
225
255
return (
@@ -229,19 +259,33 @@ let CodeEditorTmpComp = (function () {
229
259
{ children . language . propertyView ( { label : trans ( "codeEditor.properties.language" ) } ) }
230
260
{ children . theme . propertyView ( { label : trans ( "codeEditor.properties.theme" ) } ) }
231
261
{ children . lineNumbers . propertyView ( { label : trans ( "codeEditor.properties.lineNumbers" ) } ) }
262
+ { children . wordWrap . propertyView ( { label : trans ( "codeEditor.properties.wordWrap" ) } ) }
232
263
{ children . minimap . propertyView ( { label : trans ( "codeEditor.properties.minimap" ) } ) }
233
264
{ children . stickyScroll . propertyView ( { label : trans ( "codeEditor.properties.stickyScroll" ) } ) }
234
265
{ children . lightbulb . propertyView ( { label : trans ( "codeEditor.properties.lightbulb" ) } ) }
235
266
{ children . hover . propertyView ( { label : trans ( "codeEditor.properties.hover" ) } ) }
236
267
{ children . folding . propertyView ( { label : trans ( "codeEditor.properties.folding" ) } ) }
237
- { children . readOnly . propertyView ( { label : trans ( "codeEditor.properties.readOnly" ) } ) }
238
268
</ Section >
269
+ { children . label . getPropertyView ( ) }
239
270
< Section name = "Interaction" >
240
271
{ children . onEvent . propertyView ( ) }
241
272
</ Section >
242
- < Section name = "Styles " >
273
+ < Section name = "Layout " >
243
274
{ children . autoHeight . getPropertyView ( ) }
244
275
</ Section >
276
+ < Section name = "Advanced" >
277
+ { children . readOnly . propertyView ( { label : trans ( "codeEditor.properties.readOnly" ) } ) }
278
+ </ Section >
279
+ < Section name = "Validation" >
280
+ { children . required . propertyView ( { label : trans ( "codeEditor.properties.required" ) } ) }
281
+ </ Section >
282
+ < Section name = "Style" >
283
+ { children . style . getPropertyView ( ) }
284
+ </ Section >
285
+ < Section name = "Label Style" >
286
+ { children . labelStyle . getPropertyView ( ) }
287
+ </ Section >
288
+ < FormDataPropertyView { ...children } />
245
289
</ >
246
290
) ;
247
291
} )
@@ -427,6 +471,24 @@ CodeEditorTmpComp = withMethodExposing(CodeEditorTmpComp, [
427
471
}
428
472
}
429
473
} ,
474
+ {
475
+ method : {
476
+ name : "enableWordWrap" ,
477
+ description : trans ( "codeEditor.methods.enableWordWrap" ) ,
478
+ params : [ {
479
+ name : "wordWrap" ,
480
+ type : "boolean" ,
481
+ description : "boolean"
482
+ } ] ,
483
+ } ,
484
+ execute : ( comp : any , values : any [ ] ) => {
485
+ if ( Array . isArray ( values ) ) {
486
+ comp . children . wordWrap . dispatchChangeValueAction ( values [ 0 ] ) ;
487
+ } else {
488
+ comp . children . wordWrap . dispatchChangeValueAction ( values ) ;
489
+ }
490
+ }
491
+ } ,
430
492
{
431
493
method : {
432
494
name : "setReadOnly" ,
@@ -445,17 +507,37 @@ CodeEditorTmpComp = withMethodExposing(CodeEditorTmpComp, [
445
507
}
446
508
}
447
509
} ,
510
+ {
511
+ method : {
512
+ name : "markAsRequired" ,
513
+ description : trans ( "codeEditor.methods.markAsRequired" ) ,
514
+ params : [ {
515
+ name : "required" ,
516
+ type : "boolean" ,
517
+ description : "boolean"
518
+ } ] ,
519
+ } ,
520
+ execute : ( comp : any , values : any [ ] ) => {
521
+ if ( Array . isArray ( values ) ) {
522
+ comp . children . required . dispatchChangeValueAction ( values [ 0 ] ) ;
523
+ } else {
524
+ comp . children . required . dispatchChangeValueAction ( values ) ;
525
+ }
526
+ }
527
+ } ,
448
528
] ) ;
449
529
450
530
export const CodeEditorComp = withExposingConfigs ( CodeEditorTmpComp , [
451
531
new NameConfig ( "value" , trans ( "codeEditor.properties.value" ) ) ,
452
532
new NameConfig ( "language" , trans ( "codeEditor.properties.language" ) ) ,
453
533
new NameConfig ( "theme" , trans ( "codeEditor.properties.theme" ) ) ,
454
534
new NameConfig ( "lineNumbers" , trans ( "codeEditor.properties.lineNumbers" ) ) ,
535
+ new NameConfig ( "wordWrap" , trans ( "codeEditor.properties.wordWrap" ) ) ,
455
536
new NameConfig ( "minimap" , trans ( "codeEditor.properties.minimap" ) ) ,
456
537
new NameConfig ( "stickyScroll" , trans ( "codeEditor.properties.stickyScroll" ) ) ,
457
538
new NameConfig ( "lightbulb" , trans ( "codeEditor.properties.lightbulb" ) ) ,
458
539
new NameConfig ( "hover" , trans ( "codeEditor.properties.hover" ) ) ,
459
540
new NameConfig ( "folding" , trans ( "codeEditor.properties.folding" ) ) ,
460
541
new NameConfig ( "readOnly" , trans ( "codeEditor.properties.readOnly" ) ) ,
542
+ new NameConfig ( "required" , trans ( "codeEditor.properties.required" ) ) ,
461
543
] ) ;
0 commit comments