chore(core): some dnd events (#9206)

fix AF-1999
This commit is contained in:
pengx17
2024-12-19 07:42:13 +00:00
parent 30588783ef
commit da0f3d0b56
11 changed files with 104 additions and 24 deletions

View File

@@ -38,7 +38,15 @@ export class DndService extends Service {
if (source.types.includes(type)) {
const stringData = source.getStringData(type);
if (stringData) {
return resolver(stringData);
const entity = resolver(stringData);
if (entity) {
return {
entity,
from: {
at: 'external',
},
};
}
}
}
return null;
@@ -48,7 +56,7 @@ export class DndService extends Service {
private readonly resolvers: ((
source: ExternalDragPayload
) => Entity | null)[] = [];
) => AffineDNDData['draggable'] | null)[] = [];
getBlocksuiteDndAPI(sourceDocId?: string) {
const collection = this.workspaceService.workspace.docCollection;
@@ -74,29 +82,23 @@ export class DndService extends Service {
if (!isDropEvent) {
return {};
}
const from: AffineDNDData['draggable']['from'] = {
at: 'external',
};
let entity: Entity | null = null;
let resolved: AffineDNDData['draggable'] | null = null;
// in the order of the resolvers instead of the order of the types
for (const resolver of this.resolvers) {
const candidate = resolver(args.source);
if (candidate) {
entity = candidate;
resolved = candidate;
break;
}
}
if (!entity) {
if (!resolved) {
return {}; // no resolver can handle this data
}
return {
from,
entity,
};
return resolved;
};
toExternalData: toExternalData<AffineDNDData> = (args, data) => {
@@ -160,7 +162,7 @@ export class DndService extends Service {
private readonly resolveBlocksuiteExternalData = (
source: ExternalDragPayload
): Entity | null => {
): AffineDNDData['draggable'] | null => {
const dndAPI = this.getBlocksuiteDndAPI();
if (!dndAPI) {
return null;
@@ -173,7 +175,16 @@ export class DndService extends Service {
if (!snapshot) {
return null;
}
return this.resolveBlockSnapshot(snapshot);
const entity = this.resolveBlockSnapshot(snapshot);
if (!entity) {
return null;
}
return {
entity,
from: {
at: 'blocksuite-editor',
},
};
};
private readonly resolveHTML: EntityResolver = html => {