1- import { Section , sectionNames } from "lowcoder-design" ;
1+ import { ScrollBar , Section , sectionNames } from "lowcoder-design" ;
22import { UICompBuilder } from "../../generators" ;
33import { NameConfigHidden , NameConfig , withExposingConfigs } from "../../generators/withExposing" ;
44import { defaultData } from "./jsonConstants" ;
@@ -20,18 +20,18 @@ import {
2020} from "base/codeEditor/codeMirror" ;
2121import { useExtensions } from "base/codeEditor/extensions" ;
2222import { EditorContext } from "comps/editorState" ;
23- import { useMergeCompStyles } from "@lowcoder-ee/util/hooks " ;
23+ import { AutoHeightControl , BoolControl } from "@lowcoder-ee/index.sdk " ;
2424
2525/**
2626 * JsonEditor Comp
2727 */
2828
29- const Wrapper = styled . div `
29+ const Wrapper = styled . div < { $height : boolean ; $showVerticalScrollbar : boolean } > `
3030 background-color: #fff;
3131 border: 1px solid #d7d9e0;
3232 border-radius: 4px;
33- overflow: auto;
3433 height: 100%;
34+ overflow-y: ${ props => ( props . $showVerticalScrollbar ? 'scroll' : 'auto' ) } ;
3535` ;
3636
3737/**
@@ -63,20 +63,22 @@ function fixOldDataSecond(oldData: any) {
6363}
6464
6565const childrenMap = {
66- value : jsonValueExposingStateControl ( " value" , defaultData ) ,
66+ value : jsonValueExposingStateControl ( ' value' , defaultData ) ,
6767 onEvent : ChangeEventHandlerControl ,
68- label : withDefault ( LabelControl , { position : "column" } ) ,
68+ autoHeight : withDefault ( AutoHeightControl , 'auto' ) ,
69+ showVerticalScrollbar :BoolControl ,
70+ label : withDefault ( LabelControl , { position : 'column' } ) ,
6971 style : styleControl ( JsonEditorStyle , 'style' ) ,
70- animationStyle : styleControl ( AnimationStyle , 'animationStyle' ) ,
72+ animationStyle : styleControl ( AnimationStyle , 'animationStyle' ) ,
7173 ...formDataChildren ,
7274} ;
7375
7476let JsonEditorTmpComp = ( function ( ) {
75- return new UICompBuilder ( childrenMap , ( props , dispatch ) => {
76- useMergeCompStyles ( props as Record < string , any > , dispatch ) ;
77-
77+ return new UICompBuilder ( childrenMap , ( props ) => {
7878 const wrapperRef = useRef < HTMLDivElement > ( null ) ;
7979 const view = useRef < EditorViewType | null > ( null ) ;
80+ const initialized = useRef ( false ) ;
81+ const state = useRef < EditorState | null > ( null ) ;
8082 const editContent = useRef < string > ( ) ;
8183 const { extensions } = useExtensions ( {
8284 codeType : "PureJSON" ,
@@ -99,15 +101,21 @@ let JsonEditorTmpComp = (function () {
99101 } ) ;
100102
101103 useEffect ( ( ) => {
102- if ( wrapperRef . current && ! view . current ) {
103- const state = EditorState . create ( {
104+ if ( ! initialized . current && wrapperRef . current ) {
105+ state . current = EditorState . create ( {
104106 doc : JSON . stringify ( props . value . value , null , 2 ) ,
105107 extensions,
106108 } ) ;
107- view . current = new EditorView ( { state, parent : wrapperRef . current } ) ;
108109 }
109110 } , [ wrapperRef . current ] ) ;
110111
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+
111119 if ( wrapperRef . current && view . current && ! editContent . current ) {
112120 const state = EditorState . create ( {
113121 doc : JSON . stringify ( props . value . value , null , 2 ) ,
@@ -121,7 +129,16 @@ let JsonEditorTmpComp = (function () {
121129 return props . label ( {
122130 style : props . style ,
123131 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+ ) ,
125142 } ) ;
126143 } )
127144 . setPropertyViewFn ( ( children ) => {
@@ -139,7 +156,13 @@ let JsonEditorTmpComp = (function () {
139156 { hiddenPropertyView ( children ) }
140157 </ Section >
141158 ) }
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 > }
143166 { ( useContext ( EditorContext ) . editorModeStatus === "layout" || useContext ( EditorContext ) . editorModeStatus === "both" ) && ( children . label . getPropertyView ( ) ) }
144167 { ( useContext ( EditorContext ) . editorModeStatus === "layout" || useContext ( EditorContext ) . editorModeStatus === "both" ) && (
145168 < >
@@ -160,7 +183,7 @@ JsonEditorTmpComp = migrateOldData(JsonEditorTmpComp, fixOldDataSecond);
160183
161184JsonEditorTmpComp = class extends JsonEditorTmpComp {
162185 override autoHeight ( ) : boolean {
163- return false ;
186+ return this . children . autoHeight . getView ( ) ;
164187 }
165188} ;
166189
0 commit comments