From 2ad45a880e705fa2074772ffdd1c948814458217 Mon Sep 17 00:00:00 2001 From: fantasticit Date: Wed, 27 Apr 2022 16:23:14 +0800 Subject: [PATCH] tiptap: fix mind toolbar --- packages/client/src/tiptap/divider.tsx | 3 +- .../client/src/tiptap/menus/mind/bubble.tsx | 151 +---------- .../tiptap/wrappers/mind/index.module.scss | 14 +- .../client/src/tiptap/wrappers/mind/index.tsx | 143 +++++----- .../tiptap/wrappers/mind/kityminder/index.ts | 5 +- .../mind/kityminder/kity-core/core/focus.js | 2 +- .../kityminder/kity-core/core/readonly.js | 101 ++++---- .../mind/kityminder/kity-core/module/view.js | 33 +-- .../kity-editor/runtime/receiver.js | 244 +++++++++--------- .../mind/toolbar}/constant.ts | 0 .../mind/toolbar/index.module.scss} | 19 ++ .../tiptap/wrappers/mind/toolbar/index.tsx | 157 +++++++++++ 12 files changed, 449 insertions(+), 423 deletions(-) rename packages/client/src/tiptap/{menus/mind => wrappers/mind/toolbar}/constant.ts (100%) rename packages/client/src/tiptap/{menus/mind/bubble.module.scss => wrappers/mind/toolbar/index.module.scss} (65%) create mode 100644 packages/client/src/tiptap/wrappers/mind/toolbar/index.tsx diff --git a/packages/client/src/tiptap/divider.tsx b/packages/client/src/tiptap/divider.tsx index 6ce90844..eb451e75 100644 --- a/packages/client/src/tiptap/divider.tsx +++ b/packages/client/src/tiptap/divider.tsx @@ -1,4 +1,4 @@ -export const Divider = () => { +export const Divider = ({ vertical = false }) => { return (
{ height: 24, margin: '0 6px', backgroundColor: 'var(--semi-color-border)', + transform: `rotate(${vertical ? 90 : 0}deg)`, }} >
); diff --git a/packages/client/src/tiptap/menus/mind/bubble.tsx b/packages/client/src/tiptap/menus/mind/bubble.tsx index 56d79214..b4547bfb 100644 --- a/packages/client/src/tiptap/menus/mind/bubble.tsx +++ b/packages/client/src/tiptap/menus/mind/bubble.tsx @@ -1,74 +1,11 @@ import { useCallback } from 'react'; -import cls from 'classnames'; -import { Space, Button, Popover, Typography } from '@douyinfe/semi-ui'; -import { IconAlignCenter, IconDelete } from '@douyinfe/semi-icons'; +import { Space, Button } from '@douyinfe/semi-ui'; +import { IconDelete } from '@douyinfe/semi-icons'; import { Tooltip } from 'components/tooltip'; -import { IconStructure, IconDrawBoard, IconZoomIn, IconZoomOut } from 'components/icons'; import { BubbleMenu } from '../../views/bubble-menu'; import { Mind } from '../../extensions/mind'; -import { Divider } from '../../divider'; -import { clamp } from '../../utils/clamp'; -import { TEMPLATES, THEMES, MAX_ZOOM, MIN_ZOOM, ZOOM_STEP } from './constant'; -import styles from './bubble.module.scss'; - -const { Text } = Typography; export const MindBubbleMenu = ({ editor }) => { - const { template, theme, zoom, callCenterCount } = editor.getAttributes(Mind.name); - - const setZoom = useCallback( - (type: 'minus' | 'plus') => { - return () => { - editor - .chain() - .updateAttributes(Mind.name, { - zoom: clamp(type === 'minus' ? parseInt(zoom) - ZOOM_STEP : parseInt(zoom) + ZOOM_STEP, MIN_ZOOM, MAX_ZOOM), - }) - .focus() - .run(); - }; - }, - [editor, zoom] - ); - - const setCenter = useCallback(() => { - const nextValue = Number.isNaN(callCenterCount) ? 1 : Number(callCenterCount) + 1; - - editor - .chain() - .updateAttributes(Mind.name, { - callCenterCount: nextValue, - }) - .focus() - .run(); - }, [editor, callCenterCount]); - - const setTemplate = useCallback( - (template) => { - editor - .chain() - .updateAttributes(Mind.name, { - template, - }) - .focus() - .run(); - }, - [editor] - ); - - const setTheme = useCallback( - (theme) => { - editor - .chain() - .updateAttributes(Mind.name, { - theme, - }) - .focus() - .run(); - }, - [editor] - ); - const deleteNode = useCallback(() => editor.chain().deleteSelection().run(), [editor]); return ( @@ -80,90 +17,6 @@ export const MindBubbleMenu = ({ editor }) => { tippyOptions={{ maxWidth: 'calc(100vw - 100px)' }} > - -