Commit 02d29686 authored by Tom Quirk's avatar Tom Quirk

Implement click-drag exploration of designs

- Adds mousedown/up/move logic to design_presentation
- stops propogation of various events in design_overlay
- adds disableCommenting prop to designOverlay
parent ef4a23ce
...@@ -126,6 +126,8 @@ to help summarize changes between versions. ...@@ -126,6 +126,8 @@ to help summarize changes between versions.
Designs can be explored in greater detail by zooming in and out of the image. Designs can be explored in greater detail by zooming in and out of the image.
Control the amount of zoom with the `+` and `-` buttons at the bottom of the image. Control the amount of zoom with the `+` and `-` buttons at the bottom of the image.
While zoomed, you can still [start new discussions](#starting-discussions-on-designs) on the image, and see any existing ones. While zoomed, you can still [start new discussions](#starting-discussions-on-designs) on the image, and see any existing ones.
[Introduced](https://gitlab.com/gitlab-org/gitlab/issues/197324) in GitLab 12.10, while zoomed in,
you can click-and-drag on the image to move around it.
![Design zooming](img/design_zooming_v12_7.png) ![Design zooming](img/design_zooming_v12_7.png)
......
...@@ -25,6 +25,11 @@ export default { ...@@ -25,6 +25,11 @@ export default {
required: false, required: false,
default: null, default: null,
}, },
disableCommenting: {
type: Boolean,
required: false,
default: false,
},
}, },
data() { data() {
return { return {
...@@ -34,11 +39,16 @@ export default { ...@@ -34,11 +39,16 @@ export default {
}, },
computed: { computed: {
overlayStyle() { overlayStyle() {
return { const style = {
width: `${this.dimensions.width}px`, width: `${this.dimensions.width}px`,
height: `${this.dimensions.height}px`, height: `${this.dimensions.height}px`,
...this.position, ...this.position,
}; };
if (this.disableCommenting) {
style.cursor = 'unset';
}
return style;
}, },
isMovingCurrentComment() { isMovingCurrentComment() {
return Boolean(this.movingNoteStartPosition && !this.movingNoteStartPosition.noteId); return Boolean(this.movingNoteStartPosition && !this.movingNoteStartPosition.noteId);
...@@ -207,6 +217,7 @@ export default { ...@@ -207,6 +217,7 @@ export default {
@mouseleave="onNoteMouseup" @mouseleave="onNoteMouseup"
> >
<button <button
v-show="!disableCommenting"
type="button" type="button"
class="btn-transparent position-absolute image-diff-overlay-add-comment w-100 h-100 js-add-image-diff-note-button" class="btn-transparent position-absolute image-diff-overlay-add-comment w-100 h-100 js-add-image-diff-note-button"
data-qa-selector="design_image_button" data-qa-selector="design_image_button"
...@@ -222,15 +233,15 @@ export default { ...@@ -222,15 +233,15 @@ export default {
? getNotePositionStyle(movingNoteNewPosition) ? getNotePositionStyle(movingNoteNewPosition)
: getNotePositionStyle(note.position) : getNotePositionStyle(note.position)
" "
@mousedown="onNoteMousedown($event, note)" @mousedown.stop="onNoteMousedown($event, note)"
@mouseup="onNoteMouseup" @mouseup.stop="onNoteMouseup"
/> />
<design-note-pin <design-note-pin
v-if="currentCommentForm" v-if="currentCommentForm"
:position="currentCommentPositionStyle" :position="currentCommentPositionStyle"
:repositioning="isMovingCurrentComment" :repositioning="isMovingCurrentComment"
@mousedown="onNoteMousedown" @mousedown.stop="onNoteMousedown"
@mouseup="onNoteMouseup" @mouseup.stop="onNoteMouseup"
/> />
</div> </div>
</template> </template>
...@@ -46,6 +46,9 @@ export default { ...@@ -46,6 +46,9 @@ export default {
height: 0, height: 0,
}, },
initialLoad: true, initialLoad: true,
mousedown: false,
lastDragPosition: null,
isDraggingDesign: false,
}; };
}, },
computed: { computed: {
...@@ -55,6 +58,13 @@ export default { ...@@ -55,6 +58,13 @@ export default {
currentCommentForm() { currentCommentForm() {
return (this.isAnnotating && this.currentAnnotationPosition) || null; return (this.isAnnotating && this.currentAnnotationPosition) || null;
}, },
presentationStyle() {
return this.isDraggingDesign
? {
cursor: 'grabbing',
}
: undefined;
},
}, },
beforeDestroy() { beforeDestroy() {
const { presentationViewport } = this.$refs; const { presentationViewport } = this.$refs;
...@@ -206,12 +216,60 @@ export default { ...@@ -206,12 +216,60 @@ export default {
const position = this.getAnnotationPositon(coordinates); const position = this.getAnnotationPositon(coordinates);
this.$emit('moveNote', { noteId, discussionId, position }); this.$emit('moveNote', { noteId, discussionId, position });
}, },
onPresentationMousedown({ clientX, clientY }) {
if (!this.isDesignOverflowing()) return;
this.lastDragPosition = {
x: clientX,
y: clientY,
};
},
onPresentationMousemove({ clientX, clientY }) {
if (!this.lastDragPosition) return;
this.isDraggingDesign = true;
const { presentationViewport } = this.$refs;
if (!presentationViewport) return;
const { scrollLeft, scrollTop } = presentationViewport;
const deltaX = this.lastDragPosition.x - clientX;
const deltaY = this.lastDragPosition.y - clientY;
presentationViewport.scrollTo(scrollLeft + deltaX, scrollTop + deltaY);
this.lastDragPosition = {
x: clientX,
y: clientY,
};
},
onPresentationMouseup() {
this.lastDragPosition = null;
this.mousedown = null;
this.isDraggingDesign = false;
},
isDesignOverflowing() {
const { presentationContainer } = this.$refs;
if (!presentationContainer) return false;
return (
presentationContainer.scrollWidth > presentationContainer.offsetWidth ||
presentationContainer.scrollHeight > presentationContainer.offsetHeight
);
},
}, },
}; };
</script> </script>
<template> <template>
<div ref="presentationViewport" class="h-100 w-100 p-3 overflow-auto position-relative"> <div
ref="presentationViewport"
class="h-100 w-100 p-3 overflow-auto position-relative"
:style="presentationStyle"
@mousedown="onPresentationMousedown"
@mousemove="onPresentationMousemove"
@mouseup="onPresentationMouseup"
@mouseleave="onPresentationMouseup"
>
<div <div
ref="presentationContainer" ref="presentationContainer"
class="h-100 w-100 d-flex align-items-center position-relative" class="h-100 w-100 d-flex align-items-center position-relative"
...@@ -229,6 +287,7 @@ export default { ...@@ -229,6 +287,7 @@ export default {
:position="overlayPosition" :position="overlayPosition"
:notes="discussionStartingNotes" :notes="discussionStartingNotes"
:current-comment-form="currentCommentForm" :current-comment-form="currentCommentForm"
:disable-commenting="isDraggingDesign"
@openCommentForm="openCommentForm" @openCommentForm="openCommentForm"
@moveNote="moveNote" @moveNote="moveNote"
/> />
......
---
title: Add ability to explore zoomed in designs via click-and-drag
merge_request: 25405
author:
type: added
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment