Skip to content

Commit 5323da5

Browse files
author
FalkWolsky
committed
[WIP] Own Display for Layers
1 parent 27079d9 commit 5323da5

File tree

7 files changed

+532
-293
lines changed

7 files changed

+532
-293
lines changed

client/packages/lowcoder-design/src/icons/index.ts

Lines changed: 157 additions & 155 deletions
Large diffs are not rendered by default.

client/packages/lowcoder/src/layout/gridItem.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,18 @@ export type GridItemProps = {
8282

8383
export const IsDroppable = React.createContext(true);
8484

85-
const ResizableStyled = styled(Resizable)<{ $zIndex: number }>`
86-
z-index: ${props => props.$zIndex};
87-
&:hover {
88-
z-index: 1;
89-
}
85+
/* const ResizableStyled = styled(Resizable)<{ $zIndex: number, isDroppable : boolean}>`
86+
z-index: ${props => props.$zIndex * 10};
87+
${props => props.isDroppable && `
88+
&:hover {
89+
z-index: 1;
90+
}
91+
`}
92+
`; */
93+
94+
// changed to remove &:hover { z-index: 1; as it lead into flickering
95+
const ResizableStyled = styled(Resizable)<{ $zIndex: number, isDroppable : boolean}>`
96+
z-index: ${props => props.$zIndex * 10};
9097
`;
9198

9299
/**
@@ -183,6 +190,7 @@ export function GridItem(props: GridItemProps) {
183190
resizeHandles={resizeHandles}
184191
handle={Handle}
185192
$zIndex={zIndex}
193+
isDroppable={draggingUtils.getData("i") !== props.i}
186194
>
187195
{child}
188196
</ResizableStyled>

client/packages/lowcoder/src/pages/editor/LeftContent.tsx

Lines changed: 22 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import {
66
CollapseTitle as Title,
77
CopyTextButton,
88
FoldedIcon,
9-
LeftClose,
109
LeftCommon,
11-
LeftOpen,
10+
LeftInfoFill,
11+
LeftInfoLine,
1212
PadDiv,
1313
ScrollBar,
1414
Tooltip,
@@ -36,6 +36,7 @@ import cloneDeep from 'lodash/cloneDeep';
3636
import { useDispatch } from "react-redux";
3737
import { useApplicationId } from "util/hooks";
3838
import { updateApplication } from "redux/reduxActions/applicationActions";
39+
import { Divider } from "antd";
3940

4041
const CollapseTitleWrapper = styled.div`
4142
display: flex;
@@ -195,6 +196,8 @@ const CollapseView = React.memo(
195196

196197
interface LeftContentProps {
197198
uiComp: InstanceType<typeof UIComp>;
199+
checkable?: boolean;
200+
isDraggable?: boolean;
198201
}
199202

200203
enum LeftTabKey {
@@ -250,6 +253,8 @@ export const LeftContent = (props: LeftContentProps) => {
250253
const [showData, setShowData] = useState<NodeInfo[]>([]);
251254
const dispatch = useDispatch();
252255
const applicationId = useApplicationId();
256+
const checkable = props.checkable || false;
257+
const isDraggable = props.isDraggable || false;
253258

254259
const getTree = (tree: CompTree, result: NodeItem[], key?: string) => {
255260
const { items, children } = tree;
@@ -362,7 +367,7 @@ export const LeftContent = (props: LeftContentProps) => {
362367
setShowData(newData);
363368
}}
364369
>
365-
<LeftOpen />
370+
<LeftInfoLine/>
366371
</div>
367372
</Tooltip>
368373
) : (
@@ -395,7 +400,7 @@ export const LeftContent = (props: LeftContentProps) => {
395400
setShowData(newData);
396401
}}
397402
>
398-
<LeftClose />
403+
<LeftInfoFill />
399404
</div>
400405
</Tooltip>
401406
))}
@@ -438,7 +443,7 @@ export const LeftContent = (props: LeftContentProps) => {
438443
const explorerData: NodeItem[] = getTree(tree, []);
439444
// TODO: handle sorting inside modals/drawers
440445
if(type === TreeUIKey.Modals) return explorerData;
441-
446+
442447
const dsl = editorState.rootComp.toJsonValue();
443448
explorerData.forEach(data => {
444449
data['pos'] = dsl.ui.layout[data.key].pos;
@@ -452,85 +457,7 @@ export const LeftContent = (props: LeftContentProps) => {
452457
});
453458
return explorerData;
454459
}
455-
456-
interface DropInfo {
457-
node: { key: string; pos: string };
458-
dragNode: { key: string; pos: string };
459-
}
460-
461-
const handleDragEnter = (info: { node?: any; expandedKeys?: any; }) => {
462-
// Assuming 'info' has a property 'expandedKeys' which is an array of keys
463-
const { expandedKeys } = info;
464-
if (!expandedKeys.includes(info.node.key)) {
465-
setExpandedKeys(expandedKeys);
466-
}
467-
};
468-
469-
const handleDrop = (info: { node: { key: any; pos: string; }; dragNode: { key: any; pos: string; }; }, type: TreeUIKey) => {
470-
const dropPos = info.node.pos.split('-');
471-
const dragPos = info.dragNode.pos.split('-');
472-
473-
if (dropPos.length === dragPos.length) {
474-
setComponentTreeData(prevData => {
475-
let newTreeData = cloneDeep(prevData);
476-
const dropIndex = Number(dropPos[dropPos.length - 1]);
477-
const dragIndex = Number(dragPos[dragPos.length - 1]);
478-
const parentNodePos = dropPos.slice(0, -1).join('-');
479-
480-
// TODO: handle drag and drop for childen of root (container components for example)
481-
// findNodeByPos does not work yet
482-
const parentNode = parentNodePos === "0" ? { children: newTreeData } : findNodeByPos(newTreeData, parentNodePos);
483-
484-
console.log('parentNode', parentNode);
485-
486-
if (parentNode && parentNode.children) {
487-
const draggedNodeIndex = parentNode.children.findIndex(node => node.key === info.dragNode.key);
488-
if (draggedNodeIndex !== -1) {
489-
const [draggedNode] = parentNode.children.splice(draggedNodeIndex, 1);
490-
parentNode.children.splice(dropIndex > dragIndex ? dropIndex - 1 : dropIndex, 0, draggedNode);
491-
}
492-
}
493-
494-
const dsl = editorState.rootComp.toJsonValue();
495-
let layout: any = {};
496-
parentNode.children.forEach((data, index) => {
497-
layout[data.key] = {
498-
...dsl.ui.layout[data.key],
499-
pos: index,
500-
};
501-
})
502-
503-
if ( type === TreeUIKey.Modals) return newTreeData;
504-
505-
dispatch(
506-
updateApplication({
507-
applicationId: applicationId,
508-
editingApplicationDSL: {
509-
...dsl,
510-
ui: {
511-
...dsl.ui,
512-
layout,
513-
}
514-
} as object,
515-
})
516-
);
517-
editorState.rootComp.children.ui.dispatchChangeValueAction({
518-
...dsl.ui,
519-
layout,
520-
})
521-
return newTreeData;
522-
});
523-
}
524-
};
525460

526-
const findNodeByPos = (nodes: NodeItem[], pos: string): { children: NodeItem[] } => {
527-
const posArr = pos.split('-').map(p => Number(p));
528-
let currentNode = { children: nodes };
529-
for (let i = 0; i < posArr.length; i++) {
530-
currentNode = currentNode.children[posArr[i]];
531-
}
532-
return currentNode;
533-
};
534461

535462
const getTreeUI = (type: TreeUIKey) => {
536463
// here the components get sorted by name
@@ -559,21 +486,22 @@ export const LeftContent = (props: LeftContentProps) => {
559486
}
560487

561488
return (
562-
<DirectoryTreeStyle
563-
draggable={type === TreeUIKey.Components ? true : false}
564-
onDragEnter={handleDragEnter}
565-
onDrop={(info) => handleDrop(info, type)}
489+
<><DirectoryTreeStyle
566490
treeData={type === TreeUIKey.Components ? componentTreeData : modalsTreeData}
567-
icon={(props: any) => props.type && (CompStateIcon[props.type as UICompType] || <LeftCommon />)}
568-
switcherIcon={(props: any) =>
569-
props.expanded ? <FoldedIcon /> : <UnfoldIcon />
570-
}
491+
icon={(props: any) => props.type && (
492+
<div style={{ margin: '3px 0 0 -3px'}}> {/* Adjust the margin as needed */}
493+
{CompStateIcon[props.type as UICompType] || <LeftCommon />}
494+
</div>
495+
)}
496+
switcherIcon={(props: any) => props.expanded ? <FoldedIcon /> : <UnfoldIcon />}
571497
expandedKeys={expandedKeys}
572498
onExpand={(keys) => setExpandedKeys(keys)}
573499
onClick={(e, node) => handleNodeClick(e, node, uiCompInfos)}
574500
selectedKeys={selectedKeys}
575-
titleRender={(nodeData) => getTreeNode(nodeData as NodeItem, uiCompInfos)}
576-
/>
501+
titleRender={(nodeData) => getTreeNode(nodeData as NodeItem, uiCompInfos)} />
502+
<Divider />
503+
<div></div>
504+
</>
577505
);
578506
};
579507

@@ -623,6 +551,7 @@ export const LeftContent = (props: LeftContentProps) => {
623551
}, [editorState]);
624552

625553
const moduleLayoutComp = uiComp.getModuleLayoutComp();
554+
626555
const stateContent = (
627556
<ScrollBar>
628557
<div style={{ paddingBottom: 80 }}>

0 commit comments

Comments
 (0)