Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

fix: embed block style when dragging doc from sidebar doc list to edgeless (#10122)

dooudingf0a99851aaec
diff --git a/blocksuite/affine/widget-drag-handle/src/watchers/drag-event-watcher.ts b/blocksuite/affine/widget-drag-handle/src/watchers/drag-event-watcher.ts
index 9b845a5310..00384c8b72 100644
--- a/blocksuite/affine/widget-drag-handle/src/watchers/drag-event-watcher.ts
+++ b/blocksuite/affine/widget-drag-handle/src/watchers/drag-event-watcher.ts
@@ -37,6 +37,7 @@ import {
type DropPayload,
} from '@blocksuite/block-std';
import {
+ GfxBlockElementModel,
GfxControllerIdentifier,
GfxGroupLikeElementModel,
type GfxModel,
@@ -55,6 +56,7 @@ import {
import {
type BlockModel,
type BlockSnapshot,
+ internalPrimitives,
Slice,
type SliceSnapshot,
toDraftModel,
@@ -893,9 +895,7 @@ export class DragEventWatcher {
point: Point,
ignoreOriginalPos: boolean = false
) => {
- const rect = getSnapshotRect(snapshot);
-
- if (!rect) return;
+ const rect = getSnapshotRect(snapshot) ?? new Bound(0, 0, 0, 0);
const { x: modelX, y: modelY } = point;
const rewrite = (block: BlockSnapshot) => {
@@ -920,10 +920,23 @@ export class DragEventWatcher {
});
}
block.children.forEach(rewrite);
- } else if (block.props.xywh) {
- const blockBound = Bound.deserialize(
- block.props.xywh as SerializedXYWH
- );
+ } else {
+ const schema = this.std.store.schema.get(block.flavour);
+ const isGfxModel =
+ schema?.model.toModel?.() instanceof GfxBlockElementModel;
+
+ if (!isGfxModel) {
+ return;
+ }
+
+ if (!block.props.xywh) {
+ block.props.xywh =
+ schema?.model.props?.(internalPrimitives).xywh ?? '[0,0,100,100]';
+ }
+
+ const blockBound =
+ Bound.deserialize(block.props.xywh as SerializedXYWH) ??
+ new Bound(0, 0, 0, 0);
if (
block.flavour === 'affine:attachment' ||