forked from vuejs/devtools-v6
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Select component from dom tree (vuejs#476)
* Add select component example * Extracted component selection to class and moved select icon * Add test, fix codestyle * Fix error when no component has been highlighted * Use inspect-instance method for selecting instance * Remove isDark * Increase wide and tall vars (we are starting to have lots of buttons) * Header improvements * Highlighter improvements * Selector improvements (blocks events + better component search) * Updated testing components * WIP fixing tests * Icon pulse * Button text changes * Fix tests * Unecessary style * Rename searchComponent * Fixes selecting not disabled if component selected in tree * Keyboard shortcut
- Loading branch information
Showing
16 changed files
with
302 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { highlight, unHighlight } from './highlighter' | ||
import { findRelatedComponent } from './utils' | ||
|
||
export default class ComponentSelector { | ||
constructor (bridge, instanceMap) { | ||
const self = this | ||
self.bridge = bridge | ||
self.instanceMap = instanceMap | ||
self.bindMethods() | ||
|
||
bridge.on('start-component-selector', self.startSelecting) | ||
bridge.on('stop-component-selector', self.stopSelecting) | ||
} | ||
|
||
/** | ||
* Adds event listeners for mouseover and mouseup | ||
*/ | ||
startSelecting () { | ||
document.body.addEventListener('mouseover', this.elementMouseOver, true) | ||
document.body.addEventListener('click', this.elementClicked, true) | ||
document.body.addEventListener('mouseout', this.cancelEvent, true) | ||
document.body.addEventListener('mouseenter', this.cancelEvent, true) | ||
document.body.addEventListener('mouseleave', this.cancelEvent, true) | ||
document.body.addEventListener('mousedown', this.cancelEvent, true) | ||
document.body.addEventListener('mouseup', this.cancelEvent, true) | ||
} | ||
|
||
/** | ||
* Removes event listeners | ||
*/ | ||
stopSelecting () { | ||
document.body.removeEventListener('mouseover', this.elementMouseOver, true) | ||
document.body.removeEventListener('click', this.elementClicked, true) | ||
document.body.removeEventListener('mouseout', this.cancelEvent, true) | ||
document.body.removeEventListener('mouseenter', this.cancelEvent, true) | ||
document.body.removeEventListener('mouseleave', this.cancelEvent, true) | ||
document.body.removeEventListener('mousedown', this.cancelEvent, true) | ||
document.body.removeEventListener('mouseup', this.cancelEvent, true) | ||
|
||
unHighlight() | ||
} | ||
|
||
/** | ||
* Highlights a component on element mouse over | ||
* @param {MouseEvent} e | ||
*/ | ||
elementMouseOver (e) { | ||
this.cancelEvent(e) | ||
|
||
const el = e.target | ||
if (el) { | ||
this.selectedInstance = findRelatedComponent(el) | ||
} | ||
|
||
unHighlight() | ||
if (this.selectedInstance) { | ||
highlight(this.selectedInstance) | ||
} | ||
} | ||
|
||
/** | ||
* Selects an instance in the component view | ||
* @param {MouseEvent} e | ||
*/ | ||
elementClicked (e) { | ||
this.cancelEvent(e) | ||
|
||
if (this.selectedInstance) { | ||
this.bridge.send('inspect-instance', this.selectedInstance.__VUE_DEVTOOLS_UID__) | ||
} | ||
|
||
this.stopSelecting() | ||
} | ||
|
||
/** | ||
* Cancel a mouse event | ||
* @param {MouseEvent} e | ||
*/ | ||
cancelEvent (e) { | ||
e.stopImmediatePropagation() | ||
e.preventDefault() | ||
} | ||
|
||
/** | ||
* Bind class methods to the class scope to avoid rebind for event listeners | ||
*/ | ||
bindMethods () { | ||
this.startSelecting = this.startSelecting.bind(this) | ||
this.stopSelecting = this.stopSelecting.bind(this) | ||
this.elementMouseOver = this.elementMouseOver.bind(this) | ||
this.elementClicked = this.elementClicked.bind(this) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export function findRelatedComponent (el) { | ||
while (!el.__vue__ && el.parentElement) { | ||
el = el.parentElement | ||
} | ||
return el.__vue__ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 10 additions & 13 deletions
23
src/devtools/mixins/key-nav.js → src/devtools/mixins/keyboard.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.