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
@@ -219,6 +219,11 @@ const WorkbenchTab = ({
'text/uri-list': urls.join('\n'),
};
},
onDragStart: () => {
track.$.appTabsHeader.$.dragStart({
type: 'tab',
});
},
};
}, [dnd, workbench.basename, workbench.id, workbench.views]);
@@ -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 => {
@@ -125,6 +125,9 @@ export const ExplorerCollectionNode = ({
target: 'doc',
control: 'drag',
});
track.$.navigationPanel.collections.drop({
type: data.source.data.entity.type,
});
}
} else {
onDrop?.(data);
@@ -138,6 +138,9 @@ export const ExplorerDocNode = ({
track.$.navigationPanel.docs.linkDoc({
control: 'drag',
});
track.$.navigationPanel.docs.drop({
type: data.source.data.entity.type,
});
} else {
toast(t['com.affine.rootAppSidebar.doc.link-doc-only']());
}
@@ -170,6 +173,9 @@ export const ExplorerDocNode = ({
track.$.navigationPanel.docs.linkDoc({
control: 'drag',
});
track.$.navigationPanel.docs.drop({
type: data.source.data.entity.type,
});
} else {
toast(t['com.affine.rootAppSidebar.doc.link-doc-only']());
}
@@ -241,6 +241,11 @@ const ExplorerFolderNodeFolder = ({
const handleDropOnFolder = useCallback(
(data: DropTargetDropEvent<AffineDNDData>) => {
if (data.source.data.entity?.type) {
track.$.navigationPanel.folders.drop({
type: data.source.data.entity.type,
});
}
if (data.treeInstruction?.type === 'make-child') {
if (data.source.data.entity?.type === 'folder') {
if (
@@ -313,6 +318,11 @@ const ExplorerFolderNodeFolder = ({
const handleDropOnPlaceholder = useCallback(
(data: DropTargetDropEvent<AffineDNDData>) => {
if (data.source.data.entity?.type) {
track.$.navigationPanel.folders.drop({
type: data.source.data.entity.type,
});
}
if (data.source.data.entity?.type === 'folder') {
if (
node.id === data.source.data.entity.id ||
@@ -353,6 +363,11 @@ const ExplorerFolderNodeFolder = ({
if (!dropAtNode || !dropAtNode.id) {
return;
}
if (data.source.data.entity?.type) {
track.$.navigationPanel.folders.drop({
type: data.source.data.entity.type,
});
}
if (
data.treeInstruction?.type === 'reorder-above' ||
data.treeInstruction?.type === 'reorder-below'
@@ -100,6 +100,9 @@ export const ExplorerTagNode = ({
track.$.navigationPanel.tags.tagDoc({
control: 'drag',
});
track.$.navigationPanel.tags.drop({
type: data.source.data.entity.type,
});
} else {
toast(t['com.affine.rootAppSidebar.tag.doc-only']());
}
@@ -73,6 +73,9 @@ export const ExplorerFavorites = () => {
type: data.source.data.entity.type,
on: true,
});
track.$.navigationPanel.favorites.drop({
type: data.source.data.entity.type,
});
explorerSection.setCollapsed(false);
}
},
@@ -141,6 +144,9 @@ export const ExplorerFavorites = () => {
type: data.source.data.entity.type,
on: true,
});
track.$.navigationPanel.favorites.drop({
type: data.source.data.entity.type,
});
} else {
return; // not supported
}