From 2e6a0132034447a2bb73013c3cbf793e18b7c04d Mon Sep 17 00:00:00 2001 From: fantasticit Date: Tue, 26 Apr 2022 19:13:37 +0800 Subject: [PATCH] tiptap: add center method in mind --- packages/client/global.d.ts | 3 + .../src/components/resizeable/resizeable.tsx | 9 +- packages/client/src/tiptap/extensions/mind.ts | 4 + .../client/src/tiptap/menus/mind/bubble.tsx | 26 +- .../client/src/tiptap/wrappers/mind/index.tsx | 147 +- .../src/tiptap/wrappers/mind/jsmind.jsx | 3172 ----------------- .../tiptap/wrappers/mind/kityminder/index.ts | 10 +- .../mind/kityminder/kity-core/core/module.js | 278 +- .../kityminder/kity-core/core/template.js | 167 +- .../mind/kityminder/kity-core/module/view.js | 750 ++-- packages/client/tsconfig.json | 2 +- 11 files changed, 750 insertions(+), 3818 deletions(-) create mode 100644 packages/client/global.d.ts delete mode 100644 packages/client/src/tiptap/wrappers/mind/jsmind.jsx diff --git a/packages/client/global.d.ts b/packages/client/global.d.ts new file mode 100644 index 0000000..8964b54 --- /dev/null +++ b/packages/client/global.d.ts @@ -0,0 +1,3 @@ +interface Window { + kityminder: any; +} diff --git a/packages/client/src/components/resizeable/resizeable.tsx b/packages/client/src/components/resizeable/resizeable.tsx index f3aa18b..2e5ea50 100644 --- a/packages/client/src/components/resizeable/resizeable.tsx +++ b/packages/client/src/components/resizeable/resizeable.tsx @@ -7,14 +7,15 @@ import styles from './style.module.scss'; interface IProps { width: number; height: number; - onChange: (arg: { width: number; height: number }) => void; + onChange?: (arg: { width: number; height: number }) => void; + onChangeEnd?: (arg: { width: number; height: number }) => void; className?: string; } const MIN_WIDTH = 50; const MIN_HEIGHT = 50; -export const Resizeable: React.FC = ({ width, height, className, onChange, children }) => { +export const Resizeable: React.FC = ({ width, height, className, onChange, onChangeEnd, children }) => { const $container = useRef(null); const $topLeft = useRef(null); const $topRight = useRef(null); @@ -52,6 +53,10 @@ export const Resizeable: React.FC = ({ width, height, className, onChang Object.assign(event.target.dataset, { x, y }); onChange && onChange({ width, height }); }, + end: function (event) { + let { width, height } = event.rect; + onChangeEnd && onChangeEnd({ width, height }); + }, }, }); }, []); diff --git a/packages/client/src/tiptap/extensions/mind.ts b/packages/client/src/tiptap/extensions/mind.ts index a359c64..10075ec 100644 --- a/packages/client/src/tiptap/extensions/mind.ts +++ b/packages/client/src/tiptap/extensions/mind.ts @@ -51,6 +51,10 @@ export const Mind = Node.create({ default: 100, parseHTML: getDatasetAttribute('zoom'), }, + callCenterCount: { + default: 0, + parseHTML: (element) => Number(getDatasetAttribute('callcentercount')(element)), + }, }; }, diff --git a/packages/client/src/tiptap/menus/mind/bubble.tsx b/packages/client/src/tiptap/menus/mind/bubble.tsx index f1d6900..be0d161 100644 --- a/packages/client/src/tiptap/menus/mind/bubble.tsx +++ b/packages/client/src/tiptap/menus/mind/bubble.tsx @@ -1,8 +1,7 @@ import { useCallback } from 'react'; -import { useRouter } from 'next/router'; import cls from 'classnames'; -import { Space, Button, List, Popover, Typography, RadioGroup, Radio } from '@douyinfe/semi-ui'; -import { IconEdit, IconDelete } from '@douyinfe/semi-icons'; +import { Space, Button, Popover, Typography } from '@douyinfe/semi-ui'; +import { IconAlignCenter, IconDelete } from '@douyinfe/semi-icons'; import { Tooltip } from 'components/tooltip'; import { IconStructure, IconDrawBoard, IconZoomIn, IconZoomOut } from 'components/icons'; import { BubbleMenu } from '../../views/bubble-menu'; @@ -15,7 +14,7 @@ import styles from './bubble.module.scss'; const { Text } = Typography; export const MindBubbleMenu = ({ editor }) => { - const { template, theme, zoom } = editor.getAttributes(Mind.name); + const { template, theme, zoom, callCenterCount } = editor.getAttributes(Mind.name); const setZoom = useCallback( (type: 'minus' | 'plus') => { @@ -32,6 +31,18 @@ export const MindBubbleMenu = ({ editor }) => { [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 @@ -91,6 +102,11 @@ export const MindBubbleMenu = ({ editor }) => { /> + +