Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(edgeless): incorrect dragStart in surface #5985

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,37 +72,38 @@ export class EmbedBlockElement<
const blockComponent = anchorComponent as this;
const element = captureEventTarget(state.raw.target);

const canDrag =
blockComponent.contains(element) ||
!!element?.closest(AFFINE_DRAG_HANDLE_WIDGET);
if (!canDrag) return false;

const isDraggingByDragHandle = !!element?.closest(
AFFINE_DRAG_HANDLE_WIDGET
);
const isDraggingByComponent = blockComponent.contains(element);
const isInSurface = blockComponent.isInSurface;
if (!isInSurface) {

if (!isInSurface && (isDraggingByDragHandle || isDraggingByComponent)) {
this.host.selection.setGroup('note', [
this.host.selection.create('block', {
path: blockComponent.path,
}),
]);
startDragging([blockComponent], state);
return true;
} else if (isInSurface && isDraggingByDragHandle) {
const embedPortal = blockComponent.closest(
'.edgeless-block-portal-embed'
);
assertExists(embedPortal);
const dragPreviewEl = embedPortal.cloneNode() as HTMLElement;
dragPreviewEl.style.transform = '';
dragPreviewEl.style.left = '0';
dragPreviewEl.style.top = '0';
render(
blockComponent.host.renderModel(blockComponent.model),
dragPreviewEl
);

startDragging([blockComponent], state, dragPreviewEl);
return true;
}

const embedPortal = blockComponent.closest(
'.edgeless-block-portal-embed'
);
assertExists(embedPortal);
const dragPreviewEl = embedPortal.cloneNode() as HTMLElement;
dragPreviewEl.style.transform = '';
dragPreviewEl.style.left = '0';
dragPreviewEl.style.top = '0';
render(
blockComponent.host.renderModel(blockComponent.model),
dragPreviewEl
);

startDragging([blockComponent], state, dragPreviewEl);
return true;
return false;
},
onDragEnd: props => {
const { state, draggingElements, dropBlockId } = props;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export class ReferencePopup extends WithDisposable(LitElement) {
@click=${() => this._convertToCardView()}
>
${BookmarkIcon}
<affine-tooltip .offset=${12}>${'Embed view'}</affine-tooltip>
<affine-tooltip .offset=${12}>${'Card view'}</affine-tooltip>
</icon-button>
</div>

Expand Down
45 changes: 23 additions & 22 deletions packages/blocks/src/bookmark-block/bookmark-block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,37 +83,38 @@ export class BookmarkBlockComponent extends BlockElement<
const blockComponent = anchorComponent as BookmarkBlockComponent;
const element = captureEventTarget(state.raw.target);

const canDrag =
blockComponent.contains(element) ||
!!element?.closest(AFFINE_DRAG_HANDLE_WIDGET);
if (!canDrag) return false;

const isDraggingByDragHandle = !!element?.closest(
AFFINE_DRAG_HANDLE_WIDGET
);
const isDraggingByComponent = blockComponent.contains(element);
const isInSurface = blockComponent.isInSurface;
if (!isInSurface) {

if (!isInSurface && (isDraggingByDragHandle || isDraggingByComponent)) {
this.host.selection.setGroup('note', [
this.host.selection.create('block', {
path: blockComponent.path,
}),
]);
startDragging([blockComponent], state);
return true;
} else if (isInSurface && isDraggingByDragHandle) {
const bookmarkPortal = blockComponent.closest(
'.edgeless-block-portal-bookmark'
);
assertExists(bookmarkPortal);
const dragPreviewEl = bookmarkPortal.cloneNode() as HTMLElement;
dragPreviewEl.style.transform = '';
dragPreviewEl.style.left = '0';
dragPreviewEl.style.top = '0';
render(
blockComponent.host.renderModel(blockComponent.model),
dragPreviewEl
);

startDragging([blockComponent], state, dragPreviewEl);
return true;
}

const bookmarkPortal = blockComponent.closest(
'.edgeless-block-portal-bookmark'
);
assertExists(bookmarkPortal);
const dragPreviewEl = bookmarkPortal.cloneNode() as HTMLElement;
dragPreviewEl.style.transform = '';
dragPreviewEl.style.left = '0';
dragPreviewEl.style.top = '0';
render(
blockComponent.host.renderModel(blockComponent.model),
dragPreviewEl
);

startDragging([blockComponent], state, dragPreviewEl);
return true;
return false;
},
onDragEnd: props => {
const { state, draggingElements, dropBlockId } = props;
Expand Down
43 changes: 22 additions & 21 deletions packages/blocks/src/image-block/image-block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,36 +134,37 @@ export class ImageBlockComponent extends BlockElement<ImageBlockModel> {

const blockComponent = anchorComponent as ImageBlockComponent;

const canDrag =
blockComponent.contains(element) ||
!!element?.closest(AFFINE_DRAG_HANDLE_WIDGET);
if (!canDrag) return false;

const isDraggingByDragHandle = !!element?.closest(
AFFINE_DRAG_HANDLE_WIDGET
);
const isDraggingByComponent = blockComponent.contains(element);
const isInSurface = blockComponent.isInSurface;
if (!isInSurface) {

if (!isInSurface && (isDraggingByDragHandle || isDraggingByComponent)) {
this.std.selection.setGroup('note', [
this.std.selection.create('block', {
path: blockComponent.path,
}),
]);
startDragging([blockComponent], state);
return true;
} else if (isInSurface && isDraggingByDragHandle) {
const edgelessPage = getEdgelessPageByElement(blockComponent);
const scale = edgelessPage ? edgelessPage.surface.viewport.zoom : 1;
const width = blockComponent.getBoundingClientRect().width;

const dragPreviewEl = document.createElement('div');
dragPreviewEl.classList.add('affine-block-element');
dragPreviewEl.style.border = '2px solid var(--affine-border-color)';
dragPreviewEl.style.borderRadius = '4px';
dragPreviewEl.style.overflow = 'hidden';
dragPreviewEl.style.width = `${width / scale}px`;
render(blockComponent.renderModel(blockComponent.model), dragPreviewEl);

startDragging([blockComponent], state, dragPreviewEl);
return true;
}

const edgelessPage = getEdgelessPageByElement(blockComponent);
const scale = edgelessPage ? edgelessPage.surface.viewport.zoom : 1;
const width = blockComponent.getBoundingClientRect().width;

const dragPreviewEl = document.createElement('div');
dragPreviewEl.classList.add('affine-block-element');
dragPreviewEl.style.border = '2px solid var(--affine-border-color)';
dragPreviewEl.style.borderRadius = '4px';
dragPreviewEl.style.overflow = 'hidden';
dragPreviewEl.style.width = `${width / scale}px`;
render(blockComponent.renderModel(blockComponent.model), dragPreviewEl);

startDragging([blockComponent], state, dragPreviewEl);
return true;
return false;
},
onDragEnd: props => {
const { state, draggingElements } = props;
Expand Down
Loading