Skip to content

Commit

Permalink
fix: 修复toolbar问题.
Browse files Browse the repository at this point in the history
  • Loading branch information
JackySoft committed Aug 26, 2024
1 parent cf09e6b commit 19494a6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ git merge upstream/main

- 2024-08-17: 项目[在线文档](http://docs.marsview.cc/)发布
- 2024-08-13: 开源文章登上掘金论坛热榜第一
- 掘金[文章热榜](https://juejin.cn/hot/articles/)
- 2024-08-10: 项目开源
- 公告项目开源,发布开源文章:[我的低代码平台 Marsview 终于开源了](https://juejin.cn/post/7401009128204894244)
- 2024-07-16: 项目首次在掘金论坛预告
Expand Down
16 changes: 12 additions & 4 deletions packages/editor/src/components/Toolbar/Toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { usePageStore } from '@/stores/pageStore';
import './index.less';
const Toolbar = memo(({ hoverTarget, copyElement, pastElement, delElement }: any) => {
// 页面组件
const { selectedElement, elements, isFirstNode, nodeNav, isUpdateToolbar, setSelectedElement, moveElements } = usePageStore((state) => {
const { selectedElement, elements, nodeNav, isUpdateToolbar, setSelectedElement, moveElements } = usePageStore((state) => {
const currentId = state.selectedElement?.id;
const element = currentId ? state.page.elementsMap[currentId] : null;
const nodeNav: { [key: string]: { id: string; type: string; name: string } } = {};
Expand All @@ -27,7 +27,6 @@ const Toolbar = memo(({ hoverTarget, copyElement, pastElement, delElement }: any
return {
selectedElement: state.selectedElement,
elements: state.page.elements,
isFirstNode: state.page.elements[0]?.id === currentId,
nodeNav,
isUpdateToolbar: state.isUpdateToolbar,
setSelectedElement: state.setSelectedElement,
Expand All @@ -37,15 +36,24 @@ const Toolbar = memo(({ hoverTarget, copyElement, pastElement, delElement }: any

const [selectedStyle, setSelectedStyle] = useState({});
const [hoverStyle, setHoverStyle] = useState({});
const [direction, setDirection] = useState<string>('rightTop');

/**
* 当元素属性发生变化时,重新渲染工具条
*/
useEffect(() => {
if (!selectedElement) return;
setTimeout(() => {
const target = document.querySelector(`[data-id=${selectedElement?.id}]`);
const target: HTMLElement | null = document.querySelector(`[data-id=${selectedElement?.id}]`);
if (!target) return;
const style = getBoundingClientRect(target);
if (target.offsetLeft < 144 - style.width) {
setDirection('bottomLeft');
} else if (target.offsetTop < 24) {
setDirection('bottomRight');
} else {
setDirection('rightTop');
}
setSelectedStyle(style);
});
}, [selectedElement, elements, isUpdateToolbar]);
Expand Down Expand Up @@ -88,7 +96,7 @@ const Toolbar = memo(({ hoverTarget, copyElement, pastElement, delElement }: any
return (
<>
<div className={selectedElement ? 'toolbar-box selected' : 'toolbar-box'} style={selectedStyle} id="editorToolbar">
<div className={isFirstNode ? 'tool-bar first' : 'tool-bar'}>
<div className={'tool-bar ' + direction}>
{/* 节点导航:只渲染父节点、当前节点和子节点 */}
<div className="node-nav">
{nodeNav.parent && (
Expand Down
8 changes: 7 additions & 1 deletion packages/editor/src/components/Toolbar/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,16 @@
background-color: @primary-color;
color: #fff;
pointer-events: auto;
&.first {
min-width: 144px;
&.bottomRight {
top: auto;
bottom: -25px;
}
&.bottomLeft {
left: -1px;
top: auto;
bottom: -24px;
}
}
}
}

0 comments on commit 19494a6

Please sign in to comment.