Skip to content

开源白板工具(SaaS),一体化白板,包含思维导图、流程图、自由画等。All in one open-source whiteboard tool with mind, flowchart, freehand and etc.

feat(app-toolbar): add trash and duplicate in app-toolbar (#28)

pubuzhixing88fb6e90a57ba
diff --git a/packages/drawnix/src/components/icons.tsx b/packages/drawnix/src/components/icons.tsx
index 6ca0516..dc002b9 100644
--- a/packages/drawnix/src/components/icons.tsx
+++ b/packages/drawnix/src/components/icons.tsx
@@ -415,3 +415,21 @@ export const RedoIcon = createIcon(
</g>
</svg>
);
+
+export const TrashIcon = createIcon(
+ <svg role="img" viewBox="0 0 20 20" fill="none" stroke="currentColor">
+ <path
+ strokeWidth="1.25"
+ d="M3.333 5.833h13.334M8.333 9.167v5M11.667 9.167v5M4.167 5.833l.833 10c0 .92.746 1.667 1.667 1.667h6.666c.92 0 1.667-.746 1.667-1.667l.833-10M7.5 5.833v-2.5c0-.46.373-.833.833-.833h3.334c.46 0 .833.373.833.833v2.5"
+ ></path>
+ </svg>
+);
+
+export const DuplicateIcon = createIcon(
+ <svg role="img" viewBox="0 0 20 20" fill="none" stroke="currentColor">
+ <g strokeWidth="1.25">
+ <path d="M14.375 6.458H8.958a2.5 2.5 0 0 0-2.5 2.5v5.417a2.5 2.5 0 0 0 2.5 2.5h5.417a2.5 2.5 0 0 0 2.5-2.5V8.958a2.5 2.5 0 0 0-2.5-2.5Z"></path>
+ <path d="M11.667 3.125c.517 0 .986.21 1.325.55.34.338.55.807.55 1.325v1.458H8.333c-.485 0-.927.185-1.26.487-.343.312-.57.75-.609 1.24l-.005 5.357H5a1.87 1.87 0 0 1-1.326-.55 1.87 1.87 0 0 1-.549-1.325V5c0-.518.21-.987.55-1.326.338-.34.807-.549 1.325-.549h6.667Z"></path>
+ </g>
+ </svg>
+);
diff --git a/packages/drawnix/src/components/toolbar/app-toolbar/app-toolbar.tsx b/packages/drawnix/src/components/toolbar/app-toolbar/app-toolbar.tsx
index e067d6a..25896ef 100644
--- a/packages/drawnix/src/components/toolbar/app-toolbar/app-toolbar.tsx
+++ b/packages/drawnix/src/components/toolbar/app-toolbar/app-toolbar.tsx
@@ -1,9 +1,21 @@
import { useBoard } from '@plait/react-board';
import Stack from '../../stack';
import { ToolButton } from '../../tool-button';
-import { MenuIcon, RedoIcon, UndoIcon } from '../../icons';
+import {
+ DuplicateIcon,
+ MenuIcon,
+ RedoIcon,
+ TrashIcon,
+ UndoIcon,
+} from '../../icons';
import classNames from 'classnames';
-import { ATTACHED_ELEMENT_CLASS_NAME, PlaitBoard } from '@plait/core';
+import {
+ ATTACHED_ELEMENT_CLASS_NAME,
+ deleteFragment,
+ duplicateElements,
+ getSelectedElements,
+ PlaitBoard,
+} from '@plait/core';
import { Island } from '../../island';
import { Popover, PopoverContent, PopoverTrigger } from '../../popover/popover';
import { useState } from 'react';
@@ -14,6 +26,7 @@ import MenuSeparator from '../../menu/menu-separator';
export const AppToolbar: React.FC<{}> = () => {
const board = useBoard();
const container = PlaitBoard.getBoardContainer(board);
+ const selectedElements = getSelectedElements(board);
const [appMenuOpen, setAppMenuOpen] = useState(false);
const isUndoDisabled = board.history.undos.length <= 0;
const isRedoDisabled = board.history.redos.length <= 0;
@@ -83,6 +96,35 @@ export const AppToolbar: React.FC<{}> = () => {
}}
disabled={isRedoDisabled}
/>
+ {selectedElements.length > 0 && (
+ <ToolButton
+ className="duplicate"
+ key={3}
+ type="icon"
+ icon={DuplicateIcon}
+ visible={true}
+ title={`Duplicate`}
+ aria-label={`Duplicate`}
+ onPointerUp={() => {
+ duplicateElements(board);
+ }}
+ />
+ )}
+ {selectedElements.length > 0 && (
+ <ToolButton
+ className="trash"
+ key={4}
+ type="icon"
+ icon={TrashIcon}
+ visible={true}
+ title={`Trash`}
+ aria-label={`Trash`}
+ onPointerUp={() => {
+ deleteFragment(board);
+ }}
+ />
+ )}
+
</Stack.Row>
</Island>
);