fix: drag paragraph block from note to edgeless (#10242)

This commit is contained in:
doouding
2025-02-18 07:29:59 +00:00
parent 0af921c3fc
commit 73f3226f58
2 changed files with 9 additions and 13 deletions
@@ -30,7 +30,7 @@ import { getSnapshotRect } from '../utils.js';
export class PreviewHelper {
private readonly _calculateQuery = (
selectedIds: string[],
mode: 'page' | 'edgeless'
mode: 'block' | 'gfx'
): Query => {
const ids: Array<{ id: string; viewType: BlockViewType }> = selectedIds.map(
id => ({
@@ -59,7 +59,7 @@ export class PreviewHelper {
const children = model.children ?? [];
if (
mode === 'edgeless' &&
mode === 'gfx' &&
matchModels(model, [RootBlockModel, SurfaceBlockModel])
) {
children.forEach(child => {
@@ -86,12 +86,12 @@ export class PreviewHelper {
getPreviewStd = (
blockIds: string[],
snapshot: SliceSnapshot,
mode: 'edgeless' | 'page'
mode: 'block' | 'gfx'
) => {
const widget = this.widget;
const std = widget.std;
const sourceGfx = std.get(GfxControllerIdentifier);
const isEdgeless = mode === 'edgeless';
const isEdgeless = mode === 'gfx';
blockIds = blockIds.slice();
if (isEdgeless) {
@@ -195,7 +195,7 @@ export class PreviewHelper {
blockIds: string[];
snapshot: SliceSnapshot;
container: HTMLElement;
mode: 'page' | 'edgeless';
mode: 'block' | 'gfx';
}): void => {
const { blockIds, snapshot, container, mode } = options;
const { previewStd, width, height, scale } = this.getPreviewStd(
@@ -1067,16 +1067,12 @@ export class DragEventWatcher {
schema.safeValidate(block.flavour, 'affine:note')
);
// create note to wrap the snapshot
const pos = this.gfx.viewport.toModelCoordFromClientCoord([
point.x,
point.y,
]);
const noteId = store.addBlock(
'affine:note',
{
xywh: new Bound(
pos[0],
pos[1],
point.x,
point.y,
DEFAULT_NOTE_WIDTH,
DEFAULT_NOTE_HEIGHT
).serialize(),
@@ -1263,13 +1259,13 @@ export class DragEventWatcher {
return;
}
const { snapshot } = source.data.bsEntity;
const { snapshot, fromMode } = source.data.bsEntity;
this.previewHelper.renderDragPreview({
blockIds: source.data?.bsEntity?.modelIds,
snapshot,
container,
mode: this.mode ?? 'page',
mode: fromMode ?? 'block',
});
setOffset({ x: 0, y: 0 });