fix(core): split view should only be dragged by the handle (#9610)

fix BS-2354
also fix AF-2096
This commit is contained in:
pengx17
2025-01-09 10:40:25 +00:00
parent 755cebfb18
commit c0ed78dc66
3 changed files with 13 additions and 12 deletions

View File

@@ -156,7 +156,8 @@ export const SplitViewPanel = memo(function SplitViewPanel({
canDrop(data) { canDrop(data) {
const entityType = data.source.data.entity?.type; const entityType = data.source.data.entity?.type;
return ( return (
data.source.data.from?.at === 'workbench:view' || (BUILD_CONFIG.isElectron &&
data.source.data.from?.at === 'workbench:view') ||
data.source.data.from?.at === 'workbench:link' || data.source.data.from?.at === 'workbench:link' ||
(!!entityType && allowedSplitViewEntityTypes.has(entityType)) (!!entityType && allowedSplitViewEntityTypes.has(entityType))
); );
@@ -166,7 +167,7 @@ export const SplitViewPanel = memo(function SplitViewPanel({
}; };
}, [index, isFirst, order, setDraggingOverView, view, views]); }, [index, isFirst, order, setDraggingOverView, view, views]);
const { dragRef, dragHandleRef } = useDraggable<AffineDNDData>(() => { const { dragRef } = useDraggable<AffineDNDData>(() => {
return { return {
data: () => { data: () => {
return { return {
@@ -189,6 +190,9 @@ export const SplitViewPanel = memo(function SplitViewPanel({
index: order, index: order,
}); });
}, },
canDrag() {
return BUILD_CONFIG.isElectron && views.length > 1;
},
disableDragPreview: true, disableDragPreview: true,
}; };
}, [ }, [
@@ -199,6 +203,7 @@ export const SplitViewPanel = memo(function SplitViewPanel({
setDraggingOverView, setDraggingOverView,
setDraggingView, setDraggingView,
view, view,
views.length,
]); ]);
const dragging = draggingView?.view.id === view.id; const dragging = draggingView?.view.id === view.id;
@@ -222,7 +227,6 @@ export const SplitViewPanel = memo(function SplitViewPanel({
data-is-first={isFirst} data-is-first={isFirst}
data-is-last={isLast} data-is-last={isLast}
data-testid="split-view-panel" data-testid="split-view-panel"
draggable={false} // only drag via drag handle
> >
{isFirst ? ( {isFirst ? (
<ResizeHandle <ResizeHandle
@@ -236,10 +240,7 @@ export const SplitViewPanel = memo(function SplitViewPanel({
/> />
) : null} ) : null}
<div <div
ref={node => { ref={dropTargetRef}
dropTargetRef.current = node;
dragRef.current = node;
}}
data-is-active={isActive && views.length > 1 && !draggingEntity} data-is-active={isActive && views.length > 1 && !draggingEntity}
className={styles.splitViewPanelDrag} className={styles.splitViewPanelDrag}
> >
@@ -251,7 +252,7 @@ export const SplitViewPanel = memo(function SplitViewPanel({
view={view} view={view}
isActive={isActive} isActive={isActive}
isDragging={dragging} isDragging={dragging}
dragHandleRef={dragHandleRef} dragHandleRef={dragRef}
menuItems={<SplitViewMenu view={view} onMove={onMove} />} menuItems={<SplitViewMenu view={view} onMove={onMove} />}
/> />
) : null} ) : null}

View File

@@ -13,7 +13,7 @@ const dropIndicatorRadius = createVar();
const expandDropIndicator = keyframes({ const expandDropIndicator = keyframes({
from: { from: {
vars: { vars: {
[resizeHandleWidth]: '30px', [resizeHandleWidth]: '50px',
[dropIndicatorWidth]: '3px', [dropIndicatorWidth]: '3px',
[dropIndicatorOpacity]: '1', [dropIndicatorOpacity]: '1',
[dropIndicatorRadius]: '10px', [dropIndicatorRadius]: '10px',
@@ -110,7 +110,7 @@ export const resizeHandle = style({
'&[data-state="drop-indicator"]': { '&[data-state="drop-indicator"]': {
vars: { vars: {
[resizeHandleWidth]: '20px', [resizeHandleWidth]: '50px',
}, },
}, },
'&[data-edge="left"]': { '&[data-edge="left"]': {

View File

@@ -39,14 +39,14 @@ test('open split view', async ({ page }) => {
'true' 'true'
); );
const firstDragHandel = page const firstDragHandle = page
.getByTestId('split-view-panel') .getByTestId('split-view-panel')
.first() .first()
.getByTestId('split-view-indicator'); .getByTestId('split-view-indicator');
await dragTo( await dragTo(
page, page,
firstDragHandel, firstDragHandle,
page.getByTestId('split-view-panel').last(), page.getByTestId('split-view-panel').last(),
'center', 'center',
true true