Skip to content

Commit 26eb288

Browse files
Merge pull request #1091 from MenamAfzal/json-components-height
Json components height
2 parents 1f140ab + 0a1c920 commit 26eb288

File tree

4 files changed

+75
-27
lines changed

4 files changed

+75
-27
lines changed

client/packages/lowcoder/src/comps/comps/jsonComp/jsonEditorComp.tsx

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Section, sectionNames } from "lowcoder-design";
1+
import { ScrollBar, Section, sectionNames } from "lowcoder-design";
22
import { UICompBuilder } from "../../generators";
33
import { NameConfigHidden, NameConfig, withExposingConfigs } from "../../generators/withExposing";
44
import { defaultData } from "./jsonConstants";
@@ -21,17 +21,18 @@ import {
2121
import { useExtensions } from "base/codeEditor/extensions";
2222
import { EditorContext } from "comps/editorState";
2323
import { useMergeCompStyles } from "@lowcoder-ee/util/hooks";
24+
import { AutoHeightControl, BoolControl } from "@lowcoder-ee/index.sdk";
2425

2526
/**
2627
* JsonEditor Comp
2728
*/
2829

29-
const Wrapper = styled.div`
30+
const Wrapper = styled.div<{$height: boolean; $showVerticalScrollbar: boolean}>`
3031
background-color: #fff;
3132
border: 1px solid #d7d9e0;
3233
border-radius: 4px;
33-
overflow: auto;
3434
height: 100%;
35+
overflow-y: ${props => (props.$showVerticalScrollbar ? 'scroll' : 'auto')};
3536
`;
3637

3738
/**
@@ -63,11 +64,13 @@ function fixOldDataSecond(oldData: any) {
6364
}
6465

6566
const childrenMap = {
66-
value: jsonValueExposingStateControl("value", defaultData),
67+
value: jsonValueExposingStateControl('value', defaultData),
6768
onEvent: ChangeEventHandlerControl,
68-
label: withDefault(LabelControl, { position: "column" }),
69+
autoHeight: withDefault(AutoHeightControl,'auto'),
70+
showVerticalScrollbar:BoolControl,
71+
label: withDefault(LabelControl, {position: 'column'}),
6972
style: styleControl(JsonEditorStyle, 'style'),
70-
animationStyle: styleControl(AnimationStyle , 'animationStyle'),
73+
animationStyle: styleControl(AnimationStyle, 'animationStyle'),
7174
...formDataChildren,
7275
};
7376

@@ -77,6 +80,8 @@ let JsonEditorTmpComp = (function () {
7780

7881
const wrapperRef = useRef<HTMLDivElement>(null);
7982
const view = useRef<EditorViewType | null>(null);
83+
const initialized = useRef(false);
84+
const state = useRef<EditorState | null>(null);
8085
const editContent = useRef<string>();
8186
const { extensions } = useExtensions({
8287
codeType: "PureJSON",
@@ -99,15 +104,21 @@ let JsonEditorTmpComp = (function () {
99104
});
100105

101106
useEffect(() => {
102-
if (wrapperRef.current && !view.current) {
103-
const state = EditorState.create({
107+
if (!initialized.current && wrapperRef.current) {
108+
state.current = EditorState.create({
104109
doc: JSON.stringify(props.value.value, null, 2),
105110
extensions,
106111
});
107-
view.current = new EditorView({ state, parent: wrapperRef.current });
108112
}
109113
}, [wrapperRef.current]);
110114

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+
111122
if (wrapperRef.current && view.current && !editContent.current) {
112123
const state = EditorState.create({
113124
doc: JSON.stringify(props.value.value, null, 2),
@@ -121,7 +132,16 @@ let JsonEditorTmpComp = (function () {
121132
return props.label({
122133
style: props.style,
123134
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+
),
125145
});
126146
})
127147
.setPropertyViewFn((children) => {
@@ -139,7 +159,13 @@ let JsonEditorTmpComp = (function () {
139159
{hiddenPropertyView(children)}
140160
</Section>
141161
)}
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>}
143169
{(useContext(EditorContext).editorModeStatus === "layout" || useContext(EditorContext).editorModeStatus === "both") && ( children.label.getPropertyView() )}
144170
{(useContext(EditorContext).editorModeStatus === "layout" || useContext(EditorContext).editorModeStatus === "both") && (
145171
<>
@@ -160,7 +186,7 @@ JsonEditorTmpComp = migrateOldData(JsonEditorTmpComp, fixOldDataSecond);
160186

161187
JsonEditorTmpComp = class extends JsonEditorTmpComp {
162188
override autoHeight(): boolean {
163-
return false;
189+
return this.children.autoHeight.getView();
164190
}
165191
};
166192

client/packages/lowcoder/src/comps/comps/jsonComp/jsonExplorerComp.tsx

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Section, sectionNames } from "lowcoder-design";
1+
import { ScrollBar, Section, sectionNames } from "lowcoder-design";
22
import { UICompBuilder, withDefault } from "../../generators";
33
import { NameConfigHidden, NameConfig, withExposingConfigs } from "../../generators/withExposing";
44
import ReactJson, { type ThemeKeys } from "react-json-view";
@@ -14,6 +14,7 @@ import { useContext, useEffect } from "react";
1414
import { AnimationStyle, AnimationStyleType } from "@lowcoder-ee/comps/controls/styleControlConstants";
1515
import { styleControl } from "@lowcoder-ee/comps/controls/styleControl";
1616
import { useMergeCompStyles } from "@lowcoder-ee/util/hooks";
17+
import { AutoHeightControl } from "@lowcoder-ee/index.sdk";
1718

1819
/**
1920
* JsonExplorer Comp
@@ -44,7 +45,7 @@ const JsonExplorerContainer = styled.div<{
4445
${(props) => props.$animationStyle}
4546
height: 100%;
4647
overflow-y: scroll;
47-
background-color: ${(props) => bgColorMap[props.$theme] || "#ffffff"};
48+
background-color: ${(props) => bgColorMap[props.$theme] || '#ffffff'};
4849
border: 1px solid #d7d9e0;
4950
border-radius: 4px;
5051
padding: 10px;
@@ -53,6 +54,8 @@ const JsonExplorerContainer = styled.div<{
5354
let JsonExplorerTmpComp = (function () {
5455
const childrenMap = {
5556
value: withDefault(ArrayOrJSONObjectControl, JSON.stringify(defaultData, null, 2)),
57+
autoHeight: withDefault(AutoHeightControl, 'auto'),
58+
showVerticalScrollbar:BoolControl,
5659
indent: withDefault(NumberControl, 4),
5760
expandToggle: BoolControl.DEFAULT_TRUE,
5861
theme: dropdownControl(themeOptions, 'shapeshifter:inverted'),
@@ -66,22 +69,24 @@ let JsonExplorerTmpComp = (function () {
6669
$theme={props.theme as keyof typeof bgColorMap}
6770
$animationStyle={props.animationStyle}
6871
>
69-
<ReactJson
70-
name={false}
71-
src={props.value}
72-
theme={props.theme as ThemeKeys}
73-
collapsed={!props.expandToggle}
74-
displayDataTypes={false}
75-
indentWidth={props.indent}
76-
/>
72+
<ScrollBar hideScrollbar={!props.showVerticalScrollbar}>
73+
<ReactJson
74+
name={false}
75+
src={props.value}
76+
theme={props.theme as ThemeKeys}
77+
collapsed={!props.expandToggle}
78+
displayDataTypes={false}
79+
indentWidth={props.indent}
80+
/>
81+
</ScrollBar>
7782
</JsonExplorerContainer>
78-
)
83+
);
7984
})
8085
.setPropertyViewFn((children) => {
8186
return (
8287
<>
8388
<Section name={sectionNames.basic}>
84-
{children.value.propertyView({ label: trans("export.jsonEditorDesc") })}
89+
{children.value.propertyView({ label: trans("export.jsonEditorDesc") })}
8590
</Section>
8691

8792
{(useContext(EditorContext).editorModeStatus === "logic" || useContext(EditorContext).editorModeStatus === "both") && (
@@ -96,7 +101,14 @@ let JsonExplorerTmpComp = (function () {
96101
{children.indent.propertyView({ label: trans("jsonExplorer.indent") })}
97102
</Section>
98103
)}
99-
104+
<Section name={trans('prop.height')}>
105+
{children.autoHeight.propertyView({label: trans('prop.height')})}
106+
</Section>
107+
{!children.autoHeight.getView()&&<Section name={sectionNames.layout}>
108+
{children.showVerticalScrollbar.propertyView({
109+
label: trans('prop.showVerticalScrollbar'),
110+
})}
111+
</Section>}
100112
{(useContext(EditorContext).editorModeStatus === 'layout' ||
101113
useContext(EditorContext).editorModeStatus === 'both') && (
102114
<>
@@ -118,7 +130,7 @@ let JsonExplorerTmpComp = (function () {
118130

119131
JsonExplorerTmpComp = class extends JsonExplorerTmpComp {
120132
override autoHeight(): boolean {
121-
return false;
133+
return this.children.autoHeight.getView();
122134
}
123135
};
124136

client/packages/lowcoder/src/constants/themeConstants.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,15 @@ const checkbox = {
164164
}
165165
}
166166

167+
const tree = {
168+
...input.inputFieldStyle,
169+
labelStyle: {
170+
borderWidth: '0px',
171+
},
172+
style: { background: theme.primarySurface }
173+
174+
}
175+
167176

168177
export const defaultTheme: ThemeDetail = {
169178
...theme,
@@ -197,5 +206,6 @@ export const defaultTheme: ThemeDetail = {
197206
select: select,
198207
multiSelect: select,
199208
treeSelect: select,
209+
tree:tree
200210
},
201211
};

client/packages/lowcoder/src/i18n/locales/en.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ export const en = {
198198
"toggleClose": "Enable Close Button",
199199
"showMask": "Show Mask",
200200
"textOverflow": "Text Overflow",
201-
"scrollbar" : "Show Scrollbars",
201+
"scrollbar": "Show Scrollbars",
202202
"siderScrollbar" : "Show Scrollbars in Sider",
203203
"siderRight" : "Show sider on the Right",
204204
"siderWidth" : "Sider Width",

0 commit comments

Comments
 (0)