|
1 | 1 | import React, {Children, cloneElement, useCallback, useEffect, useRef, useState} from 'react';
|
2 | 2 | import type * as TExcalidraw from '@weiwenda/excalidraw';
|
3 |
| -import {newElementWith, serializeLibraryAsJSON, useI18n} from '@weiwenda/excalidraw'; |
| 3 | +import {Footer, newElementWith, serializeLibraryAsJSON, useI18n} from '@weiwenda/excalidraw'; |
4 | 4 | import { parseMermaidToExcalidraw } from '@excalidraw/mermaid-to-excalidraw';
|
5 | 5 |
|
6 | 6 | import $ from 'jquery';
|
@@ -40,7 +40,7 @@ import {
|
40 | 40 | AppstoreAddOutlined,
|
41 | 41 | BranchesOutlined, CloudUploadOutlined,
|
42 | 42 | EditOutlined,
|
43 |
| - FileSearchOutlined, |
| 43 | + ApartmentOutlined, |
44 | 44 | FilterOutlined,
|
45 | 45 | MergeOutlined,
|
46 | 46 | NodeIndexOutlined,
|
@@ -102,6 +102,7 @@ export default function PkbProducer({
|
102 | 102 | const [boardX, setBoardX] = useState(70);
|
103 | 103 | const [boardY, setBoardY] = useState(17);
|
104 | 104 | const [showFilter, setShowFilter] = useState(session.clientStore.getClientSetting('curPkbShowFilter'));
|
| 105 | + const [showLayout, setShowLayout] = useState(session.clientStore.getClientSetting('curPkbShowLayout')); |
105 | 106 | const [showDetail, setShowDetail] = useState(session.clientStore.getClientSetting('curPkbShowDetail'));
|
106 | 107 | const [showShapes, setShowShapes] = useState(session.clientStore.getClientSetting('curPkbShowShapes'));
|
107 | 108 | const [showSelectedShapeActions, setShowSelectedShapeActions] = useState(session.clientStore.getClientSetting('curPkbShowSelectedShapeActions'));
|
@@ -140,6 +141,7 @@ export default function PkbProducer({
|
140 | 141 | setShowShapes(savedContent.tools?.showShapes ?? showShapes);
|
141 | 142 | setShowDetail(savedContent.tools?.showDetail ?? showDetail);
|
142 | 143 | setShowFilter(savedContent.tools?.showFilter ?? showFilter);
|
| 144 | + setShowLayout(savedContent.tools?.showLayout ?? showLayout); |
143 | 145 | setShowSelectedShapeActions(savedContent.tools?.showSelectedShapeActions ?? showSelectedShapeActions);
|
144 | 146 | // @ts-ignore
|
145 | 147 | const blob = new Blob([savedContent.libraryItems || serializeLibraryAsJSON(initialData.libraryItems)],
|
@@ -231,6 +233,7 @@ export default function PkbProducer({
|
231 | 233 | setShowLibrary(session.clientStore.getClientSetting('curPkbShowLibrary'));
|
232 | 234 | setShowShapes(session.clientStore.getClientSetting('curPkbShowShapes'));
|
233 | 235 | setShowFilter(session.clientStore.getClientSetting('curPkbShowFilter'));
|
| 236 | + setShowLayout(session.clientStore.getClientSetting('curPkbShowLayout')); |
234 | 237 | setShowDetail(session.clientStore.getClientSetting('curPkbShowDetail'));
|
235 | 238 | setShowSelectedShapeActions(session.clientStore.getClientSetting('curPkbShowSelectedShapeActions'));
|
236 | 239 | const convertedElements = convertToExcalidrawElements(elements);
|
@@ -327,6 +330,7 @@ export default function PkbProducer({
|
327 | 330 | session.clientStore.setClientSetting('curPkbScrollY', state.scrollY);
|
328 | 331 | session.clientStore.setClientSetting('curPkbShowLibrary', showLibrary);
|
329 | 332 | session.clientStore.setClientSetting('curPkbShowFilter', showFilter);
|
| 333 | + session.clientStore.setClientSetting('curPkbShowLayout', showLayout); |
330 | 334 | session.clientStore.setClientSetting('curPkbShowDetail', showDetail);
|
331 | 335 | session.clientStore.setClientSetting('curPkbShowShapes', showShapes);
|
332 | 336 | session.clientStore.setClientSetting('curPkbShowSelectedShapeActions', showSelectedShapeActions);
|
@@ -362,6 +366,48 @@ export default function PkbProducer({
|
362 | 366 | validateEmbeddable: true,
|
363 | 367 | },
|
364 | 368 | <>
|
| 369 | + {excalidrawAPI && showLayout && ( |
| 370 | + <Footer> |
| 371 | + <Flex style={{paddingLeft: '5px'}} gap={5} wrap={'wrap'} align={'center'}> |
| 372 | + <Button className={'footer-layout'} onClick={() => { |
| 373 | + doAutoLayout('org.eclipse.elk.layered', 'NETWORK_SIMPLEX' |
| 374 | + , 'RIGHT', excalidrawAPI?.getSceneElements()!).then(elements => { |
| 375 | + excalidrawAPI?.updateScene({ |
| 376 | + elements: elements |
| 377 | + }); |
| 378 | + }); |
| 379 | + }}> |
| 380 | + <img style={{position: 'relative', top: '2px'}} |
| 381 | + onClick={e => e.preventDefault()} |
| 382 | + src={`${process.env.PUBLIC_URL}/images/layout_ltr.png`} height={18} /> |
| 383 | + </Button> |
| 384 | + <Button className={'footer-layout'} onClick={() => { |
| 385 | + doAutoLayout('org.eclipse.elk.layered', 'NETWORK_SIMPLEX' |
| 386 | + , 'LEFT', excalidrawAPI?.getSceneElements()!).then(elements => { |
| 387 | + excalidrawAPI?.updateScene({ |
| 388 | + elements: elements |
| 389 | + }); |
| 390 | + }); |
| 391 | + }}> |
| 392 | + <img style={{position: 'relative', top: '2px'}} |
| 393 | + onClick={e => e.preventDefault()} |
| 394 | + src={`${process.env.PUBLIC_URL}/images/layout_rtl.png`} height={18} /> |
| 395 | + </Button> |
| 396 | + <Button className={'footer-layout'} onClick={() => { |
| 397 | + doAutoLayout('org.eclipse.elk.mrtree', '' |
| 398 | + , '', excalidrawAPI?.getSceneElements()!).then(elements => { |
| 399 | + excalidrawAPI?.updateScene({ |
| 400 | + elements: elements |
| 401 | + }); |
| 402 | + }); |
| 403 | + }}> |
| 404 | + <img style={{position: 'relative', top: '2px'}} |
| 405 | + onClick={e => e.preventDefault()} |
| 406 | + src={`${process.env.PUBLIC_URL}/images/layout_tree.png`} height={18} /> |
| 407 | + </Button> |
| 408 | + </Flex> |
| 409 | + </Footer> |
| 410 | + )} |
365 | 411 | <WelcomeScreen />
|
366 | 412 | {
|
367 | 413 | (showFilter || showSelectedShapeActions) &&
|
@@ -395,34 +441,6 @@ export default function PkbProducer({
|
395 | 441 | {/* </Tag.CheckableTag>*/}
|
396 | 442 | {/* ))}*/}
|
397 | 443 | {/*</Flex>*/}
|
398 |
| - <div className={'operation-title'}>自动布局</div> |
399 |
| - <Flex className={'operation-options'} gap={5} wrap={'wrap'}> |
400 |
| - <Button type='primary' onClick={() => { |
401 |
| - // setLanguage({ code: 'zh-CN', label: '简体中文' }); |
402 |
| - // doAutoLayout('org.eclipse.elk.layered', 'NETWORK_SIMPLEX' |
403 |
| - // , 'RIGHT', excalidrawAPI?.getSceneElements()!).then(elements => { |
404 |
| - // excalidrawAPI?.updateScene({ |
405 |
| - // elements: elements |
406 |
| - // }); |
407 |
| - // }); |
408 |
| - }}>Layer LTR</Button> |
409 |
| - <Button type='primary' onClick={() => { |
410 |
| - doAutoLayout('org.eclipse.elk.layered', 'NETWORK_SIMPLEX' |
411 |
| - , 'LEFT', excalidrawAPI?.getSceneElements()!).then(elements => { |
412 |
| - excalidrawAPI?.updateScene({ |
413 |
| - elements: elements |
414 |
| - }); |
415 |
| - }); |
416 |
| - }}>Layer RTL</Button> |
417 |
| - <Button type='primary' onClick={() => { |
418 |
| - doAutoLayout('org.eclipse.elk.mrtree', '' |
419 |
| - , '', excalidrawAPI?.getSceneElements()!).then(elements => { |
420 |
| - excalidrawAPI?.updateScene({ |
421 |
| - elements: elements |
422 |
| - }); |
423 |
| - }); |
424 |
| - }}>Tree</Button> |
425 |
| - </Flex> |
426 | 444 | <div className={'operation-title'}>节点形状</div>
|
427 | 445 | <Flex className={'operation-options'} gap={5} wrap={'wrap'} >
|
428 | 446 | {['rectangle', 'diamond', 'ellipse', 'text'].map<React.ReactNode>((tag) => (
|
@@ -763,6 +781,7 @@ export default function PkbProducer({
|
763 | 781 | showLibrary,
|
764 | 782 | showShapes,
|
765 | 783 | showFilter,
|
| 784 | + showLayout, |
766 | 785 | showSelectedShapeActions
|
767 | 786 | }
|
768 | 787 | }, undefined, 2)};
|
@@ -805,6 +824,7 @@ export default function PkbProducer({
|
805 | 824 | showDetail,
|
806 | 825 | showShapes,
|
807 | 826 | showFilter,
|
| 827 | + showLayout, |
808 | 828 | showSelectedShapeActions
|
809 | 829 | }
|
810 | 830 | }, undefined, 2)};
|
@@ -842,21 +862,27 @@ export default function PkbProducer({
|
842 | 862 | onSelect={() => setShowLibrary(!showLibrary)}>
|
843 | 863 | 素材库
|
844 | 864 | </MainMenu.Item>
|
845 |
| - <MainMenu.Item icon={<FilterOutlined />} |
846 |
| - shortcut={showFilter ? 'ON' : 'OFF'} |
847 |
| - onSelect={() => setShowFilter(!showFilter)}> |
848 |
| - 节点选择工具 |
| 865 | + <MainMenu.Item icon={<ApartmentOutlined />} |
| 866 | + shortcut={showLayout ? 'ON' : 'OFF'} |
| 867 | + onSelect={() => setShowLayout(!showLayout)}> |
| 868 | + 自动布局工具 |
| 869 | + </MainMenu.Item> |
| 870 | + <MainMenu.Item icon={<EditOutlined />} |
| 871 | + shortcut={showSelectedShapeActions ? 'ON' : 'OFF'} |
| 872 | + onSelect={() => setShowSelectedShapeActions(!showSelectedShapeActions)}> |
| 873 | + 样式编辑工具 |
849 | 874 | </MainMenu.Item>
|
850 | 875 | <MainMenu.Item icon={<ProfileOutlined />}
|
851 | 876 | shortcut={showDetail ? 'ON' : 'OFF'}
|
852 | 877 | onSelect={() => setShowDetail(!showDetail)}>
|
853 | 878 | 节点内容工具
|
854 | 879 | </MainMenu.Item>
|
855 |
| - <MainMenu.Item icon={<EditOutlined />} |
856 |
| - shortcut={showSelectedShapeActions ? 'ON' : 'OFF'} |
857 |
| - onSelect={() => setShowSelectedShapeActions(!showSelectedShapeActions)}> |
858 |
| - 样式编辑工具 |
| 880 | + <MainMenu.Item icon={<FilterOutlined />} |
| 881 | + shortcut={showFilter ? 'ON' : 'OFF'} |
| 882 | + onSelect={() => setShowFilter(!showFilter)}> |
| 883 | + 节点选择工具 |
859 | 884 | </MainMenu.Item>
|
| 885 | + |
860 | 886 | {/*<MainMenu.DefaultItems.Socials />*/}
|
861 | 887 | {/*<MainMenu.Separator />*/}
|
862 | 888 | {/*<MainMenu.DefaultItems.ToggleTheme*/}
|
|
0 commit comments