|
|
@ -7,9 +7,13 @@ var csjs = require('csjs-inject') |
|
|
|
|
|
|
|
|
|
|
|
var css = csjs` |
|
|
|
var css = csjs` |
|
|
|
.contextview { |
|
|
|
.contextview { |
|
|
|
position : absolute; |
|
|
|
|
|
|
|
background-color : ${styles.colors.backgroundBlue}; |
|
|
|
background-color : ${styles.colors.backgroundBlue}; |
|
|
|
opacity : 0.8; |
|
|
|
opacity : 0.8; |
|
|
|
|
|
|
|
width : 20em; |
|
|
|
|
|
|
|
height : 5em; |
|
|
|
|
|
|
|
border-color : transparent; |
|
|
|
|
|
|
|
border-radius : 3px; |
|
|
|
|
|
|
|
border : .3px solid hsla(0, 0%, 40%, .2); |
|
|
|
} |
|
|
|
} |
|
|
|
` |
|
|
|
` |
|
|
|
|
|
|
|
|
|
|
@ -26,6 +30,7 @@ class ContextView { |
|
|
|
this._event = event |
|
|
|
this._event = event |
|
|
|
this._view |
|
|
|
this._view |
|
|
|
this._nodes |
|
|
|
this._nodes |
|
|
|
|
|
|
|
this._current |
|
|
|
event.contextualListener.register('contextChanged', nodes => { |
|
|
|
event.contextualListener.register('contextChanged', nodes => { |
|
|
|
this._nodes = nodes |
|
|
|
this._nodes = nodes |
|
|
|
this.update() |
|
|
|
this.update() |
|
|
@ -35,36 +40,59 @@ class ContextView { |
|
|
|
render () { |
|
|
|
render () { |
|
|
|
var view = yo`<div class=${css.contextview}>
|
|
|
|
var view = yo`<div class=${css.contextview}>
|
|
|
|
<div> |
|
|
|
<div> |
|
|
|
<span>${this._renderItems()}</span> |
|
|
|
<span>${this._renderTarget()}</span> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
</div>` |
|
|
|
</div>` |
|
|
|
if (!this._view) { |
|
|
|
if (!this._view) { |
|
|
|
this._view = view |
|
|
|
this._view = view |
|
|
|
|
|
|
|
this.hide() |
|
|
|
} |
|
|
|
} |
|
|
|
return view |
|
|
|
return view |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
hide () { |
|
|
|
|
|
|
|
if (this._view) { |
|
|
|
|
|
|
|
this._view.style.display = 'none' |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
show () { |
|
|
|
|
|
|
|
if (this._view) { |
|
|
|
|
|
|
|
this._view.style.display = 'block' |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
update () { |
|
|
|
update () { |
|
|
|
if (this._view) { |
|
|
|
if (this._view) { |
|
|
|
yo.update(this._view, this.render()) |
|
|
|
yo.update(this._view, this.render()) |
|
|
|
|
|
|
|
this._view.style.display = this._current ? 'block' : 'none' |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
_renderItems () { |
|
|
|
_renderTarget () { |
|
|
|
|
|
|
|
this._current = null |
|
|
|
if (this._nodes && this._nodes.length) { |
|
|
|
if (this._nodes && this._nodes.length) { |
|
|
|
var last = this._nodes[this._nodes.length - 1] |
|
|
|
var last = this._nodes[this._nodes.length - 1] |
|
|
|
if (this._api.contextualListener.declarationOf(last)) { |
|
|
|
if (last.name === 'ContractDefinition' || last.name === 'FunctionDefinition' || last.name === 'ModifierDefinition' || last.name === 'VariableDeclaration') { |
|
|
|
return renderReference(last) |
|
|
|
this._current = last |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
var target = this._api.contextualListener.declarationOf(last) |
|
|
|
|
|
|
|
if (target) { |
|
|
|
|
|
|
|
this._current = target |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return yo`` |
|
|
|
return this._renderDeclarations(this._current) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_renderDeclarations (node) { |
|
|
|
function renderReference (node) { |
|
|
|
if (!node) return yo`<div></div>` |
|
|
|
yo`<div><span>${node.name}</span></div>` |
|
|
|
var references = this._api.contextualListener.referencesOf(node) |
|
|
|
|
|
|
|
references = yo`<div>${references ? references.length : '0'} references</div>` |
|
|
|
|
|
|
|
return yo`<div><div>${node.attributes.type} ${node.attributes.name} (${node.name})</div>
|
|
|
|
|
|
|
|
<div>${references}</div> |
|
|
|
|
|
|
|
</div>` |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
module.exports = ContextView |
|
|
|
module.exports = ContextView |
|
|
|