From 67f0a2516b68d69151aa162093ea01b8a7f38a40 Mon Sep 17 00:00:00 2001 From: LuciNyan <453440680@qq.com> Date: Fri, 12 Aug 2022 23:27:27 +0800 Subject: [PATCH 1/2] fix(libs): remove line after drop --- .../src/menu/group-menu/GropuMenu.tsx | 23 ++++--------------- 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/libs/components/editor-plugins/src/menu/group-menu/GropuMenu.tsx b/libs/components/editor-plugins/src/menu/group-menu/GropuMenu.tsx index 781c2c3a25..118600aaa5 100644 --- a/libs/components/editor-plugins/src/menu/group-menu/GropuMenu.tsx +++ b/libs/components/editor-plugins/src/menu/group-menu/GropuMenu.tsx @@ -4,7 +4,7 @@ import { PluginHooks, Virgo, } from '@toeverything/components/editor-core'; -import { Point } from '@toeverything/utils'; +import { Point, sleep } from '@toeverything/utils'; import { GroupDirection } from '@toeverything/framework/virgo'; import React, { useCallback, useEffect, useRef, useState } from 'react'; import { DragItem } from './DragItem'; @@ -75,21 +75,6 @@ export const GroupMenu = function ({ editor, hooks }: GroupMenuProps) { [editor, groupBlock] ); - const handleRootDrop = useCallback( - async (e: React.DragEvent) => { - let groupBlockOnDrop = null; - if (editor.dragDropManager.isDragGroup(e)) { - groupBlockOnDrop = await editor.getGroupBlockByPoint( - new Point(e.clientX, e.clientY) - ); - if (groupBlockOnDrop?.id === groupBlock?.id) { - groupBlockOnDrop = null; - } - } - }, - [editor, groupBlock] - ); - const handleRootMouseLeave = useCallback(() => setGroupBlock(null), []); const handleRootDragEnd = () => { @@ -128,7 +113,6 @@ export const GroupMenu = function ({ editor, hooks }: GroupMenuProps) { handleRootMouseMove, handleRootMouseDown, handleRootDragOver, - handleRootDrop, handleRootMouseLeave, ]); @@ -170,7 +154,10 @@ export const GroupMenu = function ({ editor, hooks }: GroupMenuProps) { setShowMenu(false); if (groupBlock) { - const unobserve = groupBlock.onUpdate(() => setGroupBlock(null)); + const unobserve = groupBlock.onUpdate(async () => { + await sleep(); + setGroupBlock(null); + }); return unobserve; } return undefined; From 3a4bc73d386deac3080a5fbc5fdaf5c239b2bc90 Mon Sep 17 00:00:00 2001 From: LuciNyan <453440680@qq.com> Date: Wed, 17 Aug 2022 21:49:43 +0800 Subject: [PATCH 2/2] fix: convert sleep to raf --- .../editor-plugins/src/menu/group-menu/GropuMenu.tsx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/libs/components/editor-plugins/src/menu/group-menu/GropuMenu.tsx b/libs/components/editor-plugins/src/menu/group-menu/GropuMenu.tsx index 118600aaa5..8ccf8b5e55 100644 --- a/libs/components/editor-plugins/src/menu/group-menu/GropuMenu.tsx +++ b/libs/components/editor-plugins/src/menu/group-menu/GropuMenu.tsx @@ -4,7 +4,7 @@ import { PluginHooks, Virgo, } from '@toeverything/components/editor-core'; -import { Point, sleep } from '@toeverything/utils'; +import { Point } from '@toeverything/utils'; import { GroupDirection } from '@toeverything/framework/virgo'; import React, { useCallback, useEffect, useRef, useState } from 'react'; import { DragItem } from './DragItem'; @@ -154,9 +154,10 @@ export const GroupMenu = function ({ editor, hooks }: GroupMenuProps) { setShowMenu(false); if (groupBlock) { - const unobserve = groupBlock.onUpdate(async () => { - await sleep(); - setGroupBlock(null); + const unobserve = groupBlock.onUpdate(() => { + requestAnimationFrame(() => { + setGroupBlock(null); + }); }); return unobserve; }