fix: drag block issue (#9902)

### Changed
- Added support for changing the preview offset during dragging.
- Fixed the preview rendering for embed block and surface-ref block
- Resolved an issue where the host element might be reused in certain cases, which could cause unexpected behavior
- Moved viewport-related constants and methods to a more appropriate location
This commit is contained in:
doouding
2025-02-05 07:25:53 +00:00
parent abeff8bb1a
commit 02122098c7
22 changed files with 177 additions and 138 deletions

View File

@@ -117,13 +117,11 @@ function createNewNote(host: EditorHost): AIItemConfig {
const newNote = doc.getBlock(noteBlockId)?.model;
if (!newNote || !matchFlavours(newNote, ['affine:note'])) return;
const newNoteBound = Bound.deserialize(newNote.xywh);
const bounds = [bound, newNoteBound];
const { zoom, centerX, centerY } = service.getFitToScreenData(
[20, 20, 20, 20],
bounds
);
service.viewport.setViewport(zoom, [centerX, centerY]);
service.gfx.fitToScreen({
bounds,
padding: [20, 20, 20, 20],
});
})
.catch(err => {
console.error(err);

View File

@@ -62,8 +62,7 @@ export const PPTBuilder = (host: EditorHost) => {
const block = snapshot.snapshot.content[0];
for (const child of block.children) {
await addDoc(child);
const { centerX, centerY, zoom } = service.getFitToScreenData();
service.viewport.setViewport(zoom, [centerX, centerY]);
service.gfx.fitToScreen();
}
} catch (e) {
console.error(e);

View File

@@ -64,12 +64,9 @@ function fitViewport(
false
);
} else {
const data = rootService.getFitToScreenData();
rootService.viewport.setViewport(
data.zoom,
[data.centerX, data.centerY],
false
);
rootService.gfx.fitToScreen({
smooth: false,
});
}
} catch (e) {
logger.warn('failed to fitViewPort', e);