1
- import { Section , sectionNames } from "lowcoder-design" ;
1
+ import { ScrollBar , Section , sectionNames } from "lowcoder-design" ;
2
2
import { UICompBuilder } from "../../generators" ;
3
3
import { NameConfigHidden , NameConfig , withExposingConfigs } from "../../generators/withExposing" ;
4
4
import { defaultData } from "./jsonConstants" ;
@@ -21,17 +21,18 @@ import {
21
21
import { useExtensions } from "base/codeEditor/extensions" ;
22
22
import { EditorContext } from "comps/editorState" ;
23
23
import { useMergeCompStyles } from "@lowcoder-ee/util/hooks" ;
24
+ import { AutoHeightControl , BoolControl } from "@lowcoder-ee/index.sdk" ;
24
25
25
26
/**
26
27
* JsonEditor Comp
27
28
*/
28
29
29
- const Wrapper = styled . div `
30
+ const Wrapper = styled . div < { $height : boolean ; $showVerticalScrollbar : boolean } > `
30
31
background-color: #fff;
31
32
border: 1px solid #d7d9e0;
32
33
border-radius: 4px;
33
- overflow: auto;
34
34
height: 100%;
35
+ overflow-y: ${ props => ( props . $showVerticalScrollbar ? 'scroll' : 'auto' ) } ;
35
36
` ;
36
37
37
38
/**
@@ -63,11 +64,13 @@ function fixOldDataSecond(oldData: any) {
63
64
}
64
65
65
66
const childrenMap = {
66
- value : jsonValueExposingStateControl ( " value" , defaultData ) ,
67
+ value : jsonValueExposingStateControl ( ' value' , defaultData ) ,
67
68
onEvent : ChangeEventHandlerControl ,
68
- label : withDefault ( LabelControl , { position : "column" } ) ,
69
+ autoHeight : withDefault ( AutoHeightControl , 'auto' ) ,
70
+ showVerticalScrollbar :BoolControl ,
71
+ label : withDefault ( LabelControl , { position : 'column' } ) ,
69
72
style : styleControl ( JsonEditorStyle , 'style' ) ,
70
- animationStyle : styleControl ( AnimationStyle , 'animationStyle' ) ,
73
+ animationStyle : styleControl ( AnimationStyle , 'animationStyle' ) ,
71
74
...formDataChildren ,
72
75
} ;
73
76
@@ -77,6 +80,8 @@ let JsonEditorTmpComp = (function () {
77
80
78
81
const wrapperRef = useRef < HTMLDivElement > ( null ) ;
79
82
const view = useRef < EditorViewType | null > ( null ) ;
83
+ const initialized = useRef ( false ) ;
84
+ const state = useRef < EditorState | null > ( null ) ;
80
85
const editContent = useRef < string > ( ) ;
81
86
const { extensions } = useExtensions ( {
82
87
codeType : "PureJSON" ,
@@ -99,15 +104,21 @@ let JsonEditorTmpComp = (function () {
99
104
} ) ;
100
105
101
106
useEffect ( ( ) => {
102
- if ( wrapperRef . current && ! view . current ) {
103
- const state = EditorState . create ( {
107
+ if ( ! initialized . current && wrapperRef . current ) {
108
+ state . current = EditorState . create ( {
104
109
doc : JSON . stringify ( props . value . value , null , 2 ) ,
105
110
extensions,
106
111
} ) ;
107
- view . current = new EditorView ( { state, parent : wrapperRef . current } ) ;
108
112
}
109
113
} , [ wrapperRef . current ] ) ;
110
114
115
+ useEffect ( ( ) => {
116
+ if ( state . current && wrapperRef . current ) {
117
+ view . current = new EditorView ( { state : state . current , parent : wrapperRef . current } ) ;
118
+ initialized . current = true ;
119
+ }
120
+ } , [ props . showVerticalScrollbar ] )
121
+
111
122
if ( wrapperRef . current && view . current && ! editContent . current ) {
112
123
const state = EditorState . create ( {
113
124
doc : JSON . stringify ( props . value . value , null , 2 ) ,
@@ -121,7 +132,16 @@ let JsonEditorTmpComp = (function () {
121
132
return props . label ( {
122
133
style : props . style ,
123
134
animationStyle : props . animationStyle ,
124
- children : < Wrapper ref = { wrapperRef } onFocus = { ( ) => ( editContent . current = "focus" ) } /> ,
135
+ children : (
136
+ < ScrollBar hideScrollbar = { ! props . showVerticalScrollbar } >
137
+ < Wrapper
138
+ ref = { wrapperRef }
139
+ onFocus = { ( ) => ( editContent . current = 'focus' ) }
140
+ $height = { props . autoHeight }
141
+ $showVerticalScrollbar = { props . showVerticalScrollbar }
142
+ />
143
+ </ ScrollBar >
144
+ ) ,
125
145
} ) ;
126
146
} )
127
147
. setPropertyViewFn ( ( children ) => {
@@ -139,7 +159,13 @@ let JsonEditorTmpComp = (function () {
139
159
{ hiddenPropertyView ( children ) }
140
160
</ Section >
141
161
) }
142
-
162
+ < Section name = { trans ( 'prop.height' ) } >
163
+ { children . autoHeight . propertyView ( { label : trans ( 'prop.height' ) } ) }
164
+ </ Section >
165
+ { ! children . autoHeight . getView ( ) && < Section name = { sectionNames . layout } >
166
+ { children . showVerticalScrollbar . propertyView ( { label : trans ( 'prop.showVerticalScrollbar' ) } ) }
167
+
168
+ </ Section > }
143
169
{ ( useContext ( EditorContext ) . editorModeStatus === "layout" || useContext ( EditorContext ) . editorModeStatus === "both" ) && ( children . label . getPropertyView ( ) ) }
144
170
{ ( useContext ( EditorContext ) . editorModeStatus === "layout" || useContext ( EditorContext ) . editorModeStatus === "both" ) && (
145
171
< >
@@ -160,7 +186,7 @@ JsonEditorTmpComp = migrateOldData(JsonEditorTmpComp, fixOldDataSecond);
160
186
161
187
JsonEditorTmpComp = class extends JsonEditorTmpComp {
162
188
override autoHeight ( ) : boolean {
163
- return false ;
189
+ return this . children . autoHeight . getView ( ) ;
164
190
}
165
191
} ;
166
192
0 commit comments