@@ -8,16 +8,20 @@ import {
88eventHandlerControl ,
99stringExposingStateControl ,
1010BoolControl ,
11+ LabelControl ,
12+ styleControl ,
1113dropdownControl ,
1214AutoHeightControl ,
1315} from "lowcoder-sdk" ;
16+ import { CodeEditorContainerStyle , LabelStyle } from "comps/controls/styleControlConstants" ;
1417import { useResizeDetector } from "react-resize-detector" ;
1518import Editor from "@monaco-editor/react" ;
1619import { styled } from "styled-components" ;
1720import { trans } from "i18n" ;
1821import { useRef , useCallback , useLayoutEffect } from "react" ;
1922import debounce from "lodash/debounce" ;
2023import * as monacoEditor from "monaco-editor" ;
24+ import { formDataChildren , FormDataPropertyView } from "../../comps/formComp/formDataConstants" ;
2125
2226const CodeEditorWrapper = styled . div `
2327 border: 1px solid #dddddd;
@@ -58,6 +62,7 @@ let CodeEditorTmpComp = (function () {
5862language :"yaml" ,
5963theme :"light" ,
6064lineNumbers :"on" ,
65+ wordWrap :"on" ,
6166lightbulb :monacoEditor . editor . ShowLightbulbIconMode . OnCode ,
6267enabled :true ,
6368disabled :false ,
@@ -76,25 +81,45 @@ let CodeEditorTmpComp = (function () {
7681{ label :trans ( "codeEditor.lineNumberOptions.relative" ) , value :"relative" } ,
7782] . sort ( ( a , b ) => a . label . localeCompare ( b . label ) )
7883
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+
7991const childrenMap = {
8092autoHeight :withDefault ( AutoHeightControl , "auto" ) ,
8193language :dropdownControl ( languages , defaultValues . language ) ,
8294theme :dropdownControl ( themes , defaultValues . theme ) ,
8395lineNumbers :dropdownControl ( lineNumbersOptions , defaultValues . lineNumbers ) ,
96+ wordWrap :dropdownControl ( wordWrapOptions , defaultValues . wordWrap ) ,
8497minimap :withDefault ( BoolControl , defaultValues . enabled ) ,
8598stickyScroll :withDefault ( BoolControl , defaultValues . enabled ) ,
8699lightbulb :withDefault ( BoolControl , defaultValues . enabled ) ,
87100hover :withDefault ( BoolControl , defaultValues . enabled ) ,
88101folding :withDefault ( BoolControl , defaultValues . enabled ) ,
89102readOnly :withDefault ( BoolControl , defaultValues . disabled ) ,
90103value :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' ) ,
91115onEvent :eventHandlerControl ( [
92116{
93117label :"onChange" ,
94118value :"change" ,
95119description :"Triggers when data changes" ,
96120} ,
97121] as const ) ,
122+ ...formDataChildren ,
98123} ;
99124
100125return new UICompBuilder ( childrenMap , ( props ) => {
@@ -174,7 +199,10 @@ let CodeEditorTmpComp = (function () {
174199}
175200} , [ props . value . value ] ) ;
176201
177- return (
202+ return props . label ( {
203+ required :props . required ,
204+ style :props . style ,
205+ children :(
178206< CodeEditorWrapper
179207ref = { conRef }
180208style = { {
@@ -210,6 +238,7 @@ let CodeEditorTmpComp = (function () {
210238hover :{
211239enabled :props . hover ,
212240} ,
241+ wordWrap :props . wordWrap as 'off' | 'on' | 'wordWrapColumn' | 'bounded' ,
213242folding :props . folding ,
214243readOnly :props . readOnly ,
215244lineNumbers :props . lineNumbers as monacoEditor . editor . LineNumbersType ,
@@ -219,7 +248,8 @@ let CodeEditorTmpComp = (function () {
219248onChange = { handleOnChange }
220249/>
221250</ CodeEditorWrapper >
222- ) ;
251+ )
252+ } )
223253} )
224254. setPropertyViewFn ( ( children :any ) => {
225255return (
@@ -229,19 +259,33 @@ let CodeEditorTmpComp = (function () {
229259{ children . language . propertyView ( { label :trans ( "codeEditor.properties.language" ) } ) }
230260{ children . theme . propertyView ( { label :trans ( "codeEditor.properties.theme" ) } ) }
231261{ children . lineNumbers . propertyView ( { label :trans ( "codeEditor.properties.lineNumbers" ) } ) }
262+ { children . wordWrap . propertyView ( { label :trans ( "codeEditor.properties.wordWrap" ) } ) }
232263{ children . minimap . propertyView ( { label :trans ( "codeEditor.properties.minimap" ) } ) }
233264{ children . stickyScroll . propertyView ( { label :trans ( "codeEditor.properties.stickyScroll" ) } ) }
234265{ children . lightbulb . propertyView ( { label :trans ( "codeEditor.properties.lightbulb" ) } ) }
235266{ children . hover . propertyView ( { label :trans ( "codeEditor.properties.hover" ) } ) }
236267{ children . folding . propertyView ( { label :trans ( "codeEditor.properties.folding" ) } ) }
237- { children . readOnly . propertyView ( { label :trans ( "codeEditor.properties.readOnly" ) } ) }
238268</ Section >
269+ { children . label . getPropertyView ( ) }
239270< Section name = "Interaction" >
240271{ children . onEvent . propertyView ( ) }
241272</ Section >
242- < Section name = "Styles " >
273+ < Section name = "Layout " >
243274{ children . autoHeight . getPropertyView ( ) }
244275</ 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 } />
245289</ >
246290) ;
247291} )
@@ -427,6 +471,24 @@ CodeEditorTmpComp = withMethodExposing(CodeEditorTmpComp, [
427471}
428472}
429473} ,
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+ } ,
430492{
431493method :{
432494name :"setReadOnly" ,
@@ -445,17 +507,37 @@ CodeEditorTmpComp = withMethodExposing(CodeEditorTmpComp, [
445507}
446508}
447509} ,
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+ } ,
448528] ) ;
449529
450530export const CodeEditorComp = withExposingConfigs ( CodeEditorTmpComp , [
451531new NameConfig ( "value" , trans ( "codeEditor.properties.value" ) ) ,
452532new NameConfig ( "language" , trans ( "codeEditor.properties.language" ) ) ,
453533new NameConfig ( "theme" , trans ( "codeEditor.properties.theme" ) ) ,
454534new NameConfig ( "lineNumbers" , trans ( "codeEditor.properties.lineNumbers" ) ) ,
535+ new NameConfig ( "wordWrap" , trans ( "codeEditor.properties.wordWrap" ) ) ,
455536new NameConfig ( "minimap" , trans ( "codeEditor.properties.minimap" ) ) ,
456537new NameConfig ( "stickyScroll" , trans ( "codeEditor.properties.stickyScroll" ) ) ,
457538new NameConfig ( "lightbulb" , trans ( "codeEditor.properties.lightbulb" ) ) ,
458539new NameConfig ( "hover" , trans ( "codeEditor.properties.hover" ) ) ,
459540new NameConfig ( "folding" , trans ( "codeEditor.properties.folding" ) ) ,
460541new NameConfig ( "readOnly" , trans ( "codeEditor.properties.readOnly" ) ) ,
542+ new NameConfig ( "required" , trans ( "codeEditor.properties.required" ) ) ,
461543] ) ;