mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00:00
fix(core): some dnd perf issues (#9661)
1. page list item are bound two draggables. adding `draggable` prop to WorkbenchLink to mitigate the issue. 2. DndService may not resolve datatransfer when dragging.
This commit is contained in:
@@ -382,7 +382,7 @@ const PageListItemWrapper = forwardRef(
|
||||
|
||||
if (to) {
|
||||
return (
|
||||
<WorkbenchLink ref={ref} {...commonProps} to={to}>
|
||||
<WorkbenchLink ref={ref} draggable={false} {...commonProps} to={to}>
|
||||
{children}
|
||||
</WorkbenchLink>
|
||||
);
|
||||
|
||||
@@ -81,7 +81,7 @@ export class DndService extends Service {
|
||||
isDropEvent?: boolean
|
||||
) => {
|
||||
if (!isDropEvent) {
|
||||
return this.resolveBlocksuiteExternalData(args.source) || {};
|
||||
return {};
|
||||
}
|
||||
|
||||
let resolved: AffineDNDData['draggable'] | null = null;
|
||||
@@ -168,30 +168,24 @@ export class DndService extends Service {
|
||||
if (!dndAPI) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (source.types.includes(dndAPI.mimeType)) {
|
||||
const from = {
|
||||
at: 'blocksuite-editor',
|
||||
} as const;
|
||||
|
||||
let entity: Entity | null = null;
|
||||
|
||||
const encoded = source.getStringData(dndAPI.mimeType);
|
||||
const snapshot = encoded ? dndAPI.decodeSnapshot(encoded) : null;
|
||||
entity = snapshot ? this.resolveBlockSnapshot(snapshot) : null;
|
||||
|
||||
if (!entity) {
|
||||
return {
|
||||
from,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
entity,
|
||||
from,
|
||||
};
|
||||
}
|
||||
const encoded = source.getStringData(dndAPI.mimeType);
|
||||
if (!encoded) {
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
const snapshot = dndAPI.decodeSnapshot(encoded);
|
||||
if (!snapshot) {
|
||||
return null;
|
||||
}
|
||||
const entity = this.resolveBlockSnapshot(snapshot);
|
||||
if (!entity) {
|
||||
return null;
|
||||
}
|
||||
return {
|
||||
entity,
|
||||
from: {
|
||||
at: 'blocksuite-editor',
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
private readonly resolveHTML: EntityResolver = html => {
|
||||
|
||||
@@ -47,7 +47,10 @@ function resolveToEntity(
|
||||
}
|
||||
|
||||
export const WorkbenchLink = forwardRef<HTMLAnchorElement, WorkbenchLinkProps>(
|
||||
function WorkbenchLink({ to, onClick, replaceHistory, ...other }, ref) {
|
||||
function WorkbenchLink(
|
||||
{ to, onClick, draggable = true, replaceHistory, ...other },
|
||||
ref
|
||||
) {
|
||||
const { workbenchService } = useServices({
|
||||
WorkbenchService,
|
||||
});
|
||||
@@ -79,8 +82,10 @@ export const WorkbenchLink = forwardRef<HTMLAnchorElement, WorkbenchLinkProps>(
|
||||
to: stringTo,
|
||||
},
|
||||
},
|
||||
canDrag:
|
||||
typeof draggable === 'boolean' ? draggable : draggable === 'true',
|
||||
};
|
||||
}, [to, basename, stringTo]);
|
||||
}, [to, basename, stringTo, draggable]);
|
||||
|
||||
return (
|
||||
<a
|
||||
|
||||
Reference in New Issue
Block a user