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