Skip to content

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

refactor(toolbar): refactor toolbar structure

pubuzhixing85d183a554ecd
diff --git a/packages/drawnix/src/components/toolbar/arrow-panel.tsx b/packages/drawnix/src/components/arrow-picker.tsx
similarity index 87%
rename from packages/drawnix/src/components/toolbar/arrow-panel.tsx
rename to packages/drawnix/src/components/arrow-picker.tsx
index 1e54e4b..796ac7d 100644
--- a/packages/drawnix/src/components/toolbar/arrow-panel.tsx
+++ b/packages/drawnix/src/components/arrow-picker.tsx
@@ -1,8 +1,8 @@
import classNames from 'classnames';
-import { Island } from '../island';
-import Stack from '../stack';
-import { ToolButton } from '../tool-button';
-import { StraightArrowIcon, ElbowArrowIcon, CurveArrowIcon } from '../icons';
+import { Island } from './island';
+import Stack from './stack';
+import { ToolButton } from './tool-button';
+import { StraightArrowIcon, ElbowArrowIcon, CurveArrowIcon } from './icons';
import { useBoard } from '@plait/react-board';
import { BoardTransforms } from '@plait/core';
import React from 'react';
@@ -33,11 +33,11 @@ const ARROWS: ArrowProps[] = [
},
];
-export type ArrowPanelProps = {
+export type ArrowPickerProps = {
onPointerUp: (pointer: DrawPointerType) => void;
};
-export const ArrowPanel: React.FC<ArrowPanelProps> = ({ onPointerUp }) => {
+export const ArrowPicker: React.FC<ArrowPickerProps> = ({ onPointerUp }) => {
const board = useBoard();
return (
<Island padding={1}>
diff --git a/packages/drawnix/src/components/toolbar/shape-panel.tsx b/packages/drawnix/src/components/shape-picker.tsx
similarity index 90%
rename from packages/drawnix/src/components/toolbar/shape-panel.tsx
rename to packages/drawnix/src/components/shape-picker.tsx
index 386059e..1281212 100644
--- a/packages/drawnix/src/components/toolbar/shape-panel.tsx
+++ b/packages/drawnix/src/components/shape-picker.tsx
@@ -1,7 +1,7 @@
import classNames from 'classnames';
-import { Island } from '../island';
-import Stack from '../stack';
-import { ToolButton } from '../tool-button';
+import { Island } from './island';
+import Stack from './stack';
+import { ToolButton } from './tool-button';
import {
RectangleIcon,
EllipseIcon,
@@ -9,13 +9,13 @@ import {
DiamondIcon,
ParallelogramIcon,
RoundRectangleIcon,
-} from '../icons';
+} from './icons';
import { BoardTransforms } from '@plait/core';
import React from 'react';
import { BoardCreationMode, setCreationMode } from '@plait/common';
import { BasicShapes, DrawPointerType } from '@plait/draw';
import { useBoard } from '@plait/react-board';
-import { splitRows } from '../../utils/common';
+import { splitRows } from '../utils/common';
export interface ShapeProps {
icon: React.ReactNode;
@@ -58,11 +58,11 @@ const SHAPES: ShapeProps[] = [
const ROW_SHAPES = splitRows(SHAPES, 5);
-export type ShapePanelProps = {
+export type ShapePickerProps = {
onPointerUp: (pointer: DrawPointerType) => void;
};
-export const ShapePanel: React.FC<ShapePanelProps> = ({
+export const ShapePicker: React.FC<ShapePickerProps> = ({
onPointerUp,
}) => {
const board = useBoard();
diff --git a/packages/drawnix/src/components/toolbar/draw-toolbar.tsx b/packages/drawnix/src/components/toolbar/creation-toolbar.tsx
similarity index 95%
rename from packages/drawnix/src/components/toolbar/draw-toolbar.tsx
rename to packages/drawnix/src/components/toolbar/creation-toolbar.tsx
index 6b14bf9..f47e359 100644
--- a/packages/drawnix/src/components/toolbar/draw-toolbar.tsx
+++ b/packages/drawnix/src/components/toolbar/creation-toolbar.tsx
@@ -21,8 +21,8 @@ import { MindPointerType } from '@plait/mind';
import { DrawnixPointerType } from '../../drawnix';
import { BoardCreationMode, setCreationMode } from '@plait/common';
import { ArrowLineShape, BasicShapes, DrawPointerType } from '@plait/draw';
-import { ShapePanel } from './shape-panel';
-import { ArrowPanel } from './arrow-panel';
+import { ShapePicker } from '../shape-picker';
+import { ArrowPicker } from '../arrow-picker';
import { useState } from 'react';
import { Popover, PopoverContent, PopoverTrigger } from '../popover/popover';
@@ -80,7 +80,7 @@ export const BUTTONS: AppToolButtonProps[] = [
},
];
-export type DrawToolbarProps = {
+export type CreationToolbarProps = {
setPointer: (pointer: DrawnixPointerType) => void;
};
@@ -93,7 +93,7 @@ export const isShapePointer = (board: PlaitBoard) => {
return Object.keys(BasicShapes).includes(board.pointer);
};
-export const DrawToolbar: React.FC<DrawToolbarProps> = ({ setPointer }) => {
+export const CreationToolbar: React.FC<CreationToolbarProps> = ({ setPointer }) => {
const board = useBoard();
const container = PlaitBoard.getBoardContainer(board);
@@ -163,12 +163,12 @@ export const DrawToolbar: React.FC<DrawToolbarProps> = ({ setPointer }) => {
/>
</PopoverTrigger>
<PopoverContent container={container}>
- <ShapePanel
+ <ShapePicker
onPointerUp={(pointer: DrawPointerType) => {
setShapeOpen(false);
setPointer(pointer);
}}
- ></ShapePanel>
+ ></ShapePicker>
</PopoverContent>
</Popover>
);
@@ -203,12 +203,12 @@ export const DrawToolbar: React.FC<DrawToolbarProps> = ({ setPointer }) => {
/>
</PopoverTrigger>
<PopoverContent container={container}>
- <ArrowPanel
+ <ArrowPicker
onPointerUp={(pointer: DrawPointerType) => {
setArrowOpen(false);
setPointer(pointer);
}}
- ></ArrowPanel>
+ ></ArrowPicker>
</PopoverContent>
</Popover>
);
diff --git a/packages/drawnix/src/components/popup-toolbar/fill-button.tsx b/packages/drawnix/src/components/toolbar/popup-toolbar/fill-button.tsx
similarity index 86%
rename from packages/drawnix/src/components/popup-toolbar/fill-button.tsx
rename to packages/drawnix/src/components/toolbar/popup-toolbar/fill-button.tsx
index 7236f03..d001ff0 100644
--- a/packages/drawnix/src/components/popup-toolbar/fill-button.tsx
+++ b/packages/drawnix/src/components/toolbar/popup-toolbar/fill-button.tsx
@@ -1,5 +1,5 @@
-import React, { ReactNode, useState } from 'react';
-import { ToolButton } from '../tool-button';
+import React, { useState } from 'react';
+import { ToolButton } from '../../tool-button';
import classNames from 'classnames';
import {
autoUpdate,
@@ -12,10 +12,10 @@ import {
useRole,
} from '@floating-ui/react';
import { ATTACHED_ELEMENT_CLASS_NAME } from '@plait/core';
-import { Island } from '../island';
-import { ColorPicker } from '../color-picker';
-import { isTransparent, removeHexAlpha } from '../../utils/color';
-import { BackgroundColorIcon } from '../icons';
+import { Island } from '../../island';
+import { ColorPicker } from '../../color-picker';
+import { isTransparent, removeHexAlpha } from '../../../utils/color';
+import { BackgroundColorIcon } from '../../icons';
export type PopupFillButtonProps = {
currentColor: string | undefined;
diff --git a/packages/drawnix/src/components/popup-toolbar/font-color-button.tsx b/packages/drawnix/src/components/toolbar/popup-toolbar/font-color-button.tsx
similarity index 92%
rename from packages/drawnix/src/components/popup-toolbar/font-color-button.tsx
rename to packages/drawnix/src/components/toolbar/popup-toolbar/font-color-button.tsx
index 3bee42a..ab0d05d 100644
--- a/packages/drawnix/src/components/popup-toolbar/font-color-button.tsx
+++ b/packages/drawnix/src/components/toolbar/popup-toolbar/font-color-button.tsx
@@ -1,6 +1,6 @@
import React, { ReactNode, useState } from 'react';
-import { ColorPicker } from '../color-picker';
-import { ToolButton } from '../tool-button';
+import { ColorPicker } from '../../color-picker';
+import { ToolButton } from '../../tool-button';
import classNames from 'classnames';
import {
autoUpdate,
@@ -12,7 +12,7 @@ import {
useInteractions,
useRole,
} from '@floating-ui/react';
-import { Island } from '../island';
+import { Island } from '../../island';
import { ATTACHED_ELEMENT_CLASS_NAME } from '@plait/core';
export type PopupFontColorButtonProps = {
diff --git a/packages/drawnix/src/components/popup-toolbar/popup-toolbar.scss b/packages/drawnix/src/components/toolbar/popup-toolbar/popup-toolbar.scss
similarity index 100%
rename from packages/drawnix/src/components/popup-toolbar/popup-toolbar.scss
rename to packages/drawnix/src/components/toolbar/popup-toolbar/popup-toolbar.scss
diff --git a/packages/drawnix/src/components/popup-toolbar/popup-toolbar.tsx b/packages/drawnix/src/components/toolbar/popup-toolbar/popup-toolbar.tsx
similarity index 97%
rename from packages/drawnix/src/components/popup-toolbar/popup-toolbar.tsx
rename to packages/drawnix/src/components/toolbar/popup-toolbar/popup-toolbar.tsx
index 19457b5..69c553d 100644
--- a/packages/drawnix/src/components/popup-toolbar/popup-toolbar.tsx
+++ b/packages/drawnix/src/components/toolbar/popup-toolbar/popup-toolbar.tsx
@@ -1,5 +1,5 @@
-import Stack from '../stack';
-import { FontColorIcon } from '../icons';
+import Stack from '../../stack';
+import { FontColorIcon } from '../../icons';
import {
ATTACHED_ELEMENT_CLASS_NAME,
getSelectedElements,
@@ -16,7 +16,7 @@ import {
import React, { useEffect, useRef, useState } from 'react';
import { useBoard } from '@plait/react-board';
import { flip, offset, useFloating } from '@floating-ui/react';
-import { Island } from '../island';
+import { Island } from '../../island';
import classNames from 'classnames';
import { getStrokeByMindElement, MindElement } from '@plait/mind';
import './popup-toolbar.scss';
@@ -38,8 +38,8 @@ import {
import { PopupFontColorButton } from './font-color-button';
import { PopupStrokeButton } from './stroke-button';
import { PopupFillButton } from './fill-button';
-import { isWhite, removeHexAlpha } from '../../utils/color';
-import { TRANSPARENT } from '../../constants/color';
+import { isWhite, removeHexAlpha } from '../../../utils/color';
+import { TRANSPARENT } from '../../../constants/color';
export type PopupToolbarProps = {};
diff --git a/packages/drawnix/src/components/popup-toolbar/stroke-button.tsx b/packages/drawnix/src/components/toolbar/popup-toolbar/stroke-button.tsx
similarity index 85%
rename from packages/drawnix/src/components/popup-toolbar/stroke-button.tsx
rename to packages/drawnix/src/components/toolbar/popup-toolbar/stroke-button.tsx
index 1552aaf..6f50485 100644
--- a/packages/drawnix/src/components/popup-toolbar/stroke-button.tsx
+++ b/packages/drawnix/src/components/toolbar/popup-toolbar/stroke-button.tsx
@@ -1,5 +1,5 @@
-import React, { ReactNode, useState } from 'react';
-import { ToolButton } from '../tool-button';
+import React, { useState } from 'react';
+import { ToolButton } from '../../tool-button';
import classNames from 'classnames';
import {
autoUpdate,
@@ -12,10 +12,10 @@ import {
useRole,
} from '@floating-ui/react';
import { ATTACHED_ELEMENT_CLASS_NAME } from '@plait/core';
-import { Island } from '../island';
-import { ColorPicker } from '../color-picker';
-import { isTransparent, isWhite, removeHexAlpha } from '../../utils/color';
-import { StrokeIcon, StrokeWhiteIcon } from '../icons';
+import { Island } from '../../island';
+import { ColorPicker } from '../../color-picker';
+import { isTransparent, isWhite, removeHexAlpha } from '../../../utils/color';
+import { StrokeIcon, StrokeWhiteIcon } from '../../icons';
export type PopupStrokeButtonProps = {
currentColor: string | undefined;
diff --git a/packages/drawnix/src/drawnix.tsx b/packages/drawnix/src/drawnix.tsx
index 6ffc609..cc33e5b 100644
--- a/packages/drawnix/src/drawnix.tsx
+++ b/packages/drawnix/src/drawnix.tsx
@@ -15,12 +15,12 @@ import { DrawPointerType, withDraw } from '@plait/draw';
import { MindPointerType, withMind } from '@plait/mind';
import { withMindExtend } from './plugins/with-mind-extend';
import { withCommonPlugin } from './plugins/with-common';
-import { DrawToolbar } from './components/toolbar/draw-toolbar';
+import { CreationToolbar } from './components/toolbar/creation-toolbar';
import './styles/index.scss';
import { MainMenu } from './components/main-menu/main-menu';
import { ZoomToolbar } from './components/toolbar/zoom-toolbar';
-import { PopupToolbar } from './components/popup-toolbar/popup-toolbar';
+import { PopupToolbar } from './components/toolbar/popup-toolbar/popup-toolbar';
export type DrawnixProps = {
value: PlaitElement[];
@@ -75,11 +75,11 @@ export const Drawnix: React.FC<DrawnixProps> = ({
>
<Board></Board>
<MainMenu></MainMenu>
- <DrawToolbar
+ <CreationToolbar
setPointer={(pointer: DrawnixPointerType) => {
setAppState({ pointer });
}}
- ></DrawToolbar>
+ ></CreationToolbar>
<ZoomToolbar></ZoomToolbar>
<PopupToolbar></PopupToolbar>
</Wrapper>