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
Breaking: Remove hover behavior to display dialogs #155
Conversation
Verified that @pramodsum has signed the CLA. Thanks for the pull request! |
- Remove min-height animation when opening dialog - Remove hover to open/close dialogs, dialogs open when indicator is clicked and close when you click outside
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great start! This will remove a ton of tech debt
@@ -59,11 +59,6 @@ class AnnotationDialog extends EventEmitter { | |||
this.clickHandler = this.clickHandler.bind(this); | |||
this.stopPropagation = this.stopPropagation.bind(this); | |||
this.validateTextArea = this.validateTextArea.bind(this); | |||
|
|||
if (!this.isMobile) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🍾
src/AnnotationDialog.js
Outdated
@@ -356,6 +351,11 @@ class AnnotationDialog extends EventEmitter { | |||
this.element.addEventListener('wheel', this.stopPropagation); | |||
this.element.addEventListener('mouseup', this.stopPropagation); | |||
|
|||
if (!this.isMobile) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this being bound earlier now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no particular reason. I think it was just shuffled around
src/AnnotationDialog.js
Outdated
break; | ||
// Clicking inside reply text area | ||
case constants.DATA_TYPE_REPLY_TEXTAREA: | ||
this.activateReply(); | ||
break; | ||
// Canceling a reply | ||
case constants.DATA_TYPE_CANCEL_REPLY: | ||
this.deactivateReply(true); | ||
// this.deactivateReply(true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this line
src/AnnotationDialog.js
Outdated
break; | ||
// Clicking inside reply text area | ||
case constants.DATA_TYPE_REPLY_TEXTAREA: | ||
this.activateReply(); | ||
break; | ||
// Canceling a reply | ||
case constants.DATA_TYPE_CANCEL_REPLY: | ||
this.deactivateReply(true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we weren't hiding the dialog before on comment cancel, should we now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope. Undoing this
src/AnnotationThread.js
Outdated
@@ -132,7 +132,11 @@ class AnnotationThread extends EventEmitter { | |||
* @return {void} | |||
*/ | |||
showDialog() { | |||
// Prevents the annotations dialog from being created each mousemove | |||
if (this.state !== STATES.pending && util.isInAnnotationMode(this.container, TYPES.point)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why can't we allow showing a dialog in point mode?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's more for consistency w/ drawing annotations. I'm on board w/ allowing users to select existing drawings while in drawing mode if that's a behavior we want to add.
src/AnnotationThread.js
Outdated
return; | ||
} | ||
|
||
// Prevents the annotations dialog from being every call |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you clarify this comment a bit?
@@ -177,6 +178,12 @@ class DrawingModeController extends AnnotationModeController { | |||
thread.handleStart(location); | |||
} | |||
|
|||
/** @inheritdoc */ | |||
exit() { | |||
this.annotatedElement.classList.remove(CLASS_ANNOTATION_DRAW_MODE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are the mode CSS classes used for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Functional tests mostly
src/doc/DocAnnotator.js
Outdated
} | ||
|
||
// Hide open threads when clicking on document | ||
this.annotatedElement.addEventListener( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make this click
if possible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
src/doc/DocDrawingDialog.js
Outdated
@@ -164,6 +164,10 @@ class DocDrawingDialog extends AnnotationDialog { | |||
this.pageEl = this.annotatedElement.querySelector(`[data-page-number="${this.location.page}"]`); | |||
} | |||
|
|||
if (!this.element) { | |||
this.setup([]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kinda weird that we have to pass in an empty array here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Fixed
- Point mode: All point annotations are triggerable - Drawing mode: No existing dialogs are triggerable - When not in a mode: all existing annotation dialogs are triggerable
this.pushElementHandler( | ||
this.annotatedElement, | ||
'click', | ||
(event) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you extract this function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did it for all the drawing handlers while i was at it
src/AnnotationDialog.js
Outdated
@@ -373,8 +370,7 @@ class AnnotationDialog extends EventEmitter { | |||
|
|||
if (!this.isMobile) { | |||
this.element.addEventListener('click', this.clickHandler); | |||
this.element.addEventListener('mouseenter', this.mouseenterHandler); | |||
this.element.addEventListener('mouseleave', this.mouseleaveHandler); | |||
this.element.addEventListener('click', this.stopPropagation); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this needed? And why not just add stopPropagation() to the clickHandler?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Turns out it's already there in clickHandler
src/AnnotationThread.js
Outdated
@@ -428,6 +420,8 @@ class AnnotationThread extends EventEmitter { | |||
this.dialog.removeAllListeners('annotationcreate'); | |||
this.dialog.removeAllListeners('annotationcancel'); | |||
this.dialog.removeAllListeners('annotationdelete'); | |||
this.dialog.removeAllListeners('annotationshow'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either switch to removeListener or pass in an array https://nodejs.org/api/events.html#events_emitter_removealllisteners_eventname
@@ -296,6 +297,27 @@ class Annotator extends EventEmitter { | |||
this.mobileDialogEl.removeChild(this.mobileDialogEl.lastChild); | |||
} | |||
|
|||
/** | |||
* Hides all non-pending annotations if mouse event occurs outside an |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if you have a pending annotation open and you click on a different point icon?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it'll close the pending annotation and open the clicked on one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does that data get saved in the pending annotation so you can come back to it?
@@ -213,6 +209,7 @@ class AnnotationDialog extends EventEmitter { | |||
|
|||
util.hideElement(this.element); | |||
this.deactivateReply(); | |||
this.emit('annotationhide'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a requirement to merge but you do have most of these as constants elsewhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea i think I never moved the constants that were are emitted from AnnotationDialog.js. I can clean it up later
@@ -330,6 +333,12 @@ class AnnotationModeController extends EventEmitter { | |||
this.hadPendingThreads = false; | |||
this.emit(data.event, data.data); | |||
break; | |||
case THREAD_EVENT.show: | |||
this.visibleThreadID = data.data.threadID; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unpack data and event at the top for readability?
@@ -362,17 +371,19 @@ class AnnotationModeController extends EventEmitter { | |||
* @param {HTMLElement} element - The element to bind the listener to | |||
* @param {Array|string} type - An array of event types to listen for or the event name to listen for | |||
* @param {Function} handlerFn - The callback to be invoked when the element emits a specified eventname | |||
* @param {boolean} useCapture - Whether or not to prioritize handler call |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this prioritize or block the event from reaching other places?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prioritize
}, | ||
true | ||
); | ||
this.pushElementHandler(this.annotatedElement, ['mousedown', 'touchstart'], this.drawingStartHandler, true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is pretty confusing, can you add a comment why we need to push two element handlers? and why is click separated from mousedown and touchstart?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
both are needed for the surface edge cases and click is separate because it more or less just prevents any click events other than drawing ones from ever triggering on the document specifically
@@ -678,142 +659,6 @@ class DocAnnotator extends Annotator { | |||
} | |||
} | |||
|
|||
/** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as Justin would say, "10/10"
src/util.js
Outdated
* @param {Event} event Mouse event | ||
* @return {boolean} Whether or not mouse is inside dialog | ||
*/ | ||
export function isInAnnotation(event) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rename this because it applies to either being in an annotation or clicking on an annotation icon.
this.undoDrawing = this.undoDrawing.bind(this); | ||
this.redoDrawing = this.redoDrawing.bind(this); | ||
|
||
this.pushElementHandler(this.annotatedElement, 'click', this.stopPropagation, true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not stop propagation to drawingStart?
Based off of #137