Merge pull request #649 from ethereum/serapathMaster

Serapath master - app.js - refactor
pull/1/head
yann300 7 years ago committed by GitHub
commit b087feff9c
  1. 79
      assets/css/browser-solidity.css
  2. 211
      src/app.js
  3. 240
      src/app/editor-panel.js
  4. 14
      src/app/editor.js
  5. 91
      src/app/file-panel.js
  6. 123
      src/app/righthand-panel.js

@ -1,43 +1,3 @@
.scroller {
position: absolute;
z-index: 999;
text-align: center;
cursor: pointer;
display: none;
padding: 0 0.9em;
vertical-align: middle;
background-color: rgba(255, 255, 255, 0.8);
height: 100%;
font-size: 1.3em;
}
.scroller i {
line-height: 3em;
}
.scroller-right {
right: 0;
}
.scroller-left {
left: 0;
}
#files {
list-style: none;
margin: 0;
font-size: 15px;
height: 2.5em;
box-sizing: border-box;
line-height: 2em;
padding: 0.5em 0 0;
position: relative;
left: 40px;
top:0;
min-width:3000px;
border-bottom: 0 none;
}
#files .file { #files .file {
padding: 0 0.6em; padding: 0 0.6em;
box-sizing: border-box; box-sizing: border-box;
@ -51,22 +11,6 @@
color: #999; color: #999;
} }
.toggleRHP {
display: block;
float: left;
margin-top: 0.5em;
padding: 0.6em;
font-weight: bold;
cursor: pointer;
color: black;
}
.toggleRHP {
float: right;
position: absolute;
right: 0;
}
#files .file.active { #files .file.active {
color: black; color: black;
font-weight: bold; font-weight: bold;
@ -98,18 +42,6 @@
display: inline-block; display: inline-block;
} }
#righthand-panel {
position: absolute;
top: 0;
width: 37em;
max-width: 80vw;
right: 0;
bottom: 0;
overflow: auto;
box-sizing: border-box;
overflow: hidden;
}
#header { #header {
font-size: 13px; font-size: 13px;
height: 100%; height: 100%;
@ -378,17 +310,6 @@
border: .2em dotted #ffbd01; border: .2em dotted #ffbd01;
} }
#ghostbar {
width: 1px;
background-color: red;
opacity: 0.5;
position: absolute;
cursor: col-resize;
z-index: 9999;
top: 0;
bottom: 0;
}
input[readonly] { input[readonly] {
display: block; display: block;
width: 100%; width: 100%;

@ -26,6 +26,7 @@ var ExecutionContext = require('./app/execution-context')
var Debugger = require('./app/debugger') var Debugger = require('./app/debugger')
var StaticAnalysis = require('./app/staticanalysis/staticAnalysisView') var StaticAnalysis = require('./app/staticanalysis/staticAnalysisView')
var FilePanel = require('./app/file-panel') var FilePanel = require('./app/file-panel')
var EditorPanel = require('./app/editor-panel')
var RighthandPanel = require('./app/righthand-panel') var RighthandPanel = require('./app/righthand-panel')
var examples = require('./app/example-contracts') var examples = require('./app/example-contracts')
@ -43,44 +44,88 @@ var css = csjs`
position : relative; position : relative;
width : 100vw; width : 100vw;
height : 100vh; height : 100vh;
overflow : hidden;
} }
.centerpanel { .centerpanel {
display : flex; display : flex;
flex-direction : column; flex-direction : column;
position : absolute; position : absolute;
top : 0; top : 0;
left : 200px;
right : 0;
bottom : 0; bottom : 0;
}
.tabsbar {
overflow : hidden; overflow : hidden;
} }
.leftpanel { .leftpanel {
display : flex; display : flex;
flex-direction : column;
position : absolute; position : absolute;
top : 0; top : 0;
left : 0;
right : 0;
bottom : 0; bottom : 0;
width : 200px; left : 0;
overflow : hidden;
} }
.dragbar2 { .rightpanel {
background-color : transparent; display : flex;
flex-direction : column;
position : absolute; position : absolute;
width : 0.5em; top : 0;
top : 3em; right : 0;
bottom : 0; bottom : 0;
cursor : col-resize; overflow : hidden;
z-index : 999;
border-right : 2px solid hsla(215, 81%, 79%, .3);
} }
` `
class App { class App {
constructor (opts = {}) { constructor (opts = {}) {
var self = this var self = this
self._api = {}
var fileStorage = new Storage('sol:')
self._api.config = new Config(fileStorage)
self._api.filesProviders = {}
self._api.filesProviders['browser'] = new Browserfiles(fileStorage)
self._api.filesProviders['localhost'] = new SharedFolder(new Remixd())
self._view = {} self._view = {}
self._components = {}
self.data = {
_layout: {
right: {
offset: self._api.config.get('right-offset') || 400,
show: true
}, // @TODO: adapt sizes proportionally to browser window size
left: {
offset: self._api.config.get('left-offset') || 200,
show: true
}
}
}
// ----------------- editor ----------------------------
self._components.editor = new Editor({}) // @TODO: put into editorpanel
// ----------------- editor panel ----------------------
self._components.editorpanel = new EditorPanel({
api: { editor: self._components.editor }
})
self._components.editorpanel.event.register('resize', direction => self._adjustLayout(direction))
}
_adjustLayout (direction, delta) {
var self = this
var layout = self.data._layout[direction]
if (layout) {
if (delta === undefined) {
layout.show = !layout.show
if (layout.show) delta = layout.offset
else delta = 0
} else {
self._api.config.set(`${direction}-offset`, delta)
layout.offset = delta
}
}
if (direction === 'left') {
self._view.leftpanel.style.width = delta + 'px'
self._view.centerpanel.style.left = delta + 'px'
}
if (direction === 'right') {
self._view.rightpanel.style.width = delta + 'px'
self._view.centerpanel.style.right = delta + 'px'
}
} }
init () { init () {
var self = this var self = this
@ -89,31 +134,31 @@ class App {
render () { render () {
var self = this var self = this
if (self._view.el) return self._view.el if (self._view.el) return self._view.el
/***************************************************************************/ self._view.leftpanel = yo`
self._view.leftpanel = yo`<div id="filepanel" class=${css.leftpanel}></div>` <div id="filepanel" class=${css.leftpanel}>
self._view.rightpanel = yo`<div></div>` ${''}
self._view.tabsbar = yo`
<div class=${css.tabsbar}>
<div class="scroller scroller-left"><i class="fa fa-chevron-left "></i></div>
<div class="scroller scroller-right"><i class="fa fa-chevron-right "></i></div>
<ul id="files" class="nav nav-tabs"></ul>
</div> </div>
` `
self._view.centerpanel = yo` self._view.centerpanel = yo`
<div id="editor-container" class=${css.centerpanel}> <div id="editor-container" class=${css.centerpanel}>
${self._view.tabsbar} ${self._components.editorpanel.render()}
<div id="input"></div> </div>
`
self._view.rightpanel = yo`
<div class=${css.rightpanel}>
${''}
</div> </div>
` `
self._view.el = yo` self._view.el = yo`
<div class=${css.browsersolidity}> <div class=${css.browsersolidity}>
${self._view.leftpanel} ${self._view.leftpanel}
<span class="toggleRHP" title="Toggle right hand panel"><i class="fa fa-angle-double-right"></i></span>
${self._view.centerpanel} ${self._view.centerpanel}
<div id="dragbar" class=${css.dragbar2}></div>
${self._view.rightpanel} ${self._view.rightpanel}
</div> </div>
` `
// INIT
self._adjustLayout('left', self.data._layout.left.offset)
self._adjustLayout('right', self.data._layout.right.offset)
return self._view.el return self._view.el
} }
} }
@ -126,6 +171,7 @@ function run () {
var queryParams = new QueryParams() var queryParams = new QueryParams()
var gistHandler = new GistHandler() var gistHandler = new GistHandler()
var editor = self._components.editor
// The event listener needs to be registered as early as possible, because the // The event listener needs to be registered as early as possible, because the
// parent will send the message upon the "load" event. // parent will send the message upon the "load" event.
var filesToLoad = null var filesToLoad = null
@ -138,12 +184,9 @@ function run () {
}, false) }, false)
this.event = new EventManager() this.event = new EventManager()
var fileStorage = new Storage('sol:')
var config = new Config(fileStorage) var config = self._api.config
var remixd = new Remixd() var filesProviders = self._api.filesProviders
var filesProviders = {}
filesProviders['browser'] = new Browserfiles(fileStorage)
filesProviders['localhost'] = new SharedFolder(remixd)
var tabbedFiles = {} // list of files displayed in the tabs bar var tabbedFiles = {} // list of files displayed in the tabs bar
@ -271,9 +314,6 @@ function run () {
createName: createNonClashingName, createName: createNonClashingName,
switchToFile: switchToFile, switchToFile: switchToFile,
event: this.event, event: this.event,
editorFontSize: function (incr) {
editor.editorFontSize(incr)
},
currentFile: function () { currentFile: function () {
return config.get('currentFile') return config.get('currentFile')
}, },
@ -288,29 +328,9 @@ function run () {
// TODO this should happen inside file-panel.js // TODO this should happen inside file-panel.js
var filepanelContainer = document.querySelector('#filepanel') var filepanelContainer = document.querySelector('#filepanel')
filepanelContainer.appendChild(filePanel) filepanelContainer.appendChild(filePanel.render())
filePanel.events.register('ui-hidden', function changeLayout (isHidden) { filePanel.event.register('resize', delta => self._adjustLayout('left', delta))
var value
if (isHidden) {
value = -parseInt(self._view.leftpanel.style.width)
value = (isNaN(value) ? -self._view.leftpanel.getBoundingClientRect().width : value)
self._view.leftpanel.style.position = 'absolute'
self._view.leftpanel.style.left = (value - 5) + 'px'
self._view.leftpanel.style.width = -value + 'px'
self._view.centerpanel.style.left = '45px'
} else {
value = -parseInt(self._view.leftpanel.style.left) + 'px'
self._view.leftpanel.style.position = 'static'
self._view.leftpanel.style.width = value
self._view.leftpanel.style.left = ''
self._view.centerpanel.style.left = value
}
})
filePanel.events.register('ui-resize', function changeLayout (width) {
self._view.leftpanel.style.width = width + 'px'
self._view.centerpanel.style.left = width + 'px'
})
function fileRenamedEvent (oldName, newName, isFolder) { function fileRenamedEvent (oldName, newName, isFolder) {
// TODO please never use 'window' when it is possible to use a variable // TODO please never use 'window' when it is possible to use a variable
@ -411,12 +431,8 @@ function run () {
}) })
}) })
// ----------------- editor ----------------------
var editor = new Editor(document.getElementById('input'))
// --------------------Files tabs----------------------------- // --------------------Files tabs-----------------------------
var $filesEl = $('#files') var $filesEl = $('#files')
var FILE_SCROLL_DELTA = 300
// Switch tab // Switch tab
$filesEl.on('click', '.file:not(.active)', function (ev) { $filesEl.on('click', '.file:not(.active)', function (ev) {
@ -497,7 +513,6 @@ function run () {
for (var file in tabbedFiles) { for (var file in tabbedFiles) {
$filesEl.append($('<li class="file"><span class="name">' + file + '</span><span class="remove"><i class="fa fa-close"></i></span></li>')) $filesEl.append($('<li class="file"><span class="name">' + file + '</span><span class="remove"><i class="fa fa-close"></i></span></li>'))
} }
var currentFileOpen = !!config.get('currentFile') var currentFileOpen = !!config.get('currentFile')
if (currentFileOpen) { if (currentFileOpen) {
@ -506,57 +521,9 @@ function run () {
} }
$('#input').toggle(currentFileOpen) $('#input').toggle(currentFileOpen)
$('#output').toggle(currentFileOpen) $('#output').toggle(currentFileOpen)
self._components.editorpanel.refresh()
} }
var $scrollerRight = $('.scroller-right')
var $scrollerLeft = $('.scroller-left')
function widthOfList () {
var itemsWidth = 0
$('.file').each(function () {
var itemWidth = $(this).outerWidth()
itemsWidth += itemWidth
})
return itemsWidth
}
function widthOfVisible () {
return document.querySelector('#editor-container').offsetWidth
}
function getLeftPosi () {
return $filesEl.position().left
}
function reAdjust () {
if (widthOfList() + getLeftPosi() > widthOfVisible()) {
$scrollerRight.fadeIn('fast')
} else {
$scrollerRight.fadeOut('fast')
}
if (getLeftPosi() < 0) {
$scrollerLeft.fadeIn('fast')
} else {
$scrollerLeft.fadeOut('fast')
$filesEl.animate({ left: getLeftPosi() + 'px' }, 'slow')
}
}
$scrollerRight.click(function () {
var delta = (getLeftPosi() - FILE_SCROLL_DELTA)
$filesEl.animate({ left: delta + 'px' }, 'slow', function () {
reAdjust()
})
})
$scrollerLeft.click(function () {
var delta = Math.min((getLeftPosi() + FILE_SCROLL_DELTA), 0)
$filesEl.animate({ left: delta + 'px' }, 'slow', function () {
reAdjust()
})
})
var compiler = new Compiler(handleImportCall) var compiler = new Compiler(handleImportCall)
var offsetToLineColumnConverter = new OffsetToLineColumnConverter(compiler.event) var offsetToLineColumnConverter = new OffsetToLineColumnConverter(compiler.event)
@ -703,18 +670,9 @@ function run () {
// ---------------- Righthand-panel -------------------- // ---------------- Righthand-panel --------------------
var rhpAPI = { var rhpAPI = {
config: config, config: config,
setEditorSize (delta) {
$('#righthand-panel').css('width', delta)
self._view.centerpanel.style.right = delta + 'px'
document.querySelector(`.${css.dragbar2}`).style.right = delta + 'px'
onResize()
},
reAdjust: reAdjust,
warnCompilerLoading: (msg) => { warnCompilerLoading: (msg) => {
renderer.clear() renderer.clear()
if (msg) { if (msg) renderer.error(msg, $('#output'), {type: 'warning'})
renderer.error(msg, $('#output'), {type: 'warning'})
}
}, },
executionContextChange: (context) => { executionContextChange: (context) => {
return executionContext.executionContextChange(context) return executionContext.executionContextChange(context)
@ -728,17 +686,16 @@ function run () {
app: self.event, app: self.event,
udapp: udapp.event udapp: udapp.event
} }
var righthandPanel = new RighthandPanel(rhpAPI, rhpEvents, {}) // eslint-disable-line self._components.righthandpanel = new RighthandPanel(rhpAPI, rhpEvents, {})
self._view.rightpanel.appendChild(righthandPanel.render()) self._view.rightpanel.appendChild(self._components.righthandpanel.render())
righthandPanel.init() self._components.righthandpanel.init()
self._components.righthandpanel.event.register('resize', delta => self._adjustLayout('right', delta))
// ----------------- editor resize --------------- // ----------------- editor resize ---------------
function onResize () { function onResize () {
editor.resize(document.querySelector('#editorWrap').checked) editor.resize(document.querySelector('#editorWrap').checked)
reAdjust()
} }
window.onresize = onResize
onResize() onResize()
self._view.el.addEventListener('change', onResize) self._view.el.addEventListener('change', onResize)

@ -0,0 +1,240 @@
var csjs = require('csjs-inject')
var yo = require('yo-yo')
var EventManager = require('ethereum-remix').lib.EventManager
var css = csjs`
.tabsbar {
display : flex;
overflow : hidden;
}
.tabs {
position : relative;
display : flex;
margin : 0;
left : 10px;
margin-right : 10px;
width : 100%;
overflow : hidden;
}
.files {
position : relative;
list-style : none;
margin : 0;
font-size : 15px;
height : 2.5em;
box-sizing : border-box;
line-height : 2em;
padding : 0.5em 0 0;
top : 0;
border-bottom : 0 none;
}
.changeeditorfontsize {
margin : 0;
}
.changeeditorfontsize i {
cursor : pointer;
display : block;
color : #111111;
}
.changeeditorfontsize i {
cursor : pointer;
}
.changeeditorfontsize i:hover {
color : orange;
}
.buttons {
display : flex;
flex-direction : row;
justify-content : space-around;
align-items : center;
min-width : 45px;
}
.toggleLHP {
display : flex;
padding : 10px;
width : 100%;
font-weight : bold;
color : black;
}
.toggleLHP i {
cursor : pointer;
}
.toggleLHP i:hover {
color : orange;
}
.scroller {
position : absolute;
z-index : 999;
text-align : center;
cursor : pointer;
padding : 0 0.9em;
vertical-align : middle;
background-color : rgba(255, 255, 255, 0.8);
height : 100%;
font-size : 1.3em;
}
.scroller i {
line-height : 3em;
}
.scrollerright {
right : 0;
margin-right : 15px;
}
.scrollerleft {
left : 0;
}
.toggleRHP {
margin-top : 0.5em;
padding : 0.6em;
font-weight : bold;
color : black;
right : 0;
}
.toggleRHP i {
cursor : pointer;
}
.toggleRHP i:hover {
color : orange;
}
.show {
opacity : 1;
transition : .3s opacity ease-in;
}
.hide {
opacity : 0;
pointer-events : none;
transition : .3s opacity ease-in;
}
`
class EditorPanel {
constructor (opts = {}) {
var self = this
self.data = {
_FILE_SCROLL_DELTA: 200
}
self._view = {}
self._api = { editor: opts.api.editor }
self.event = new EventManager()
}
refresh () {
var self = this
self._view.tabs.onmouseenter()
}
render () {
var self = this
if (self._view.el) return self._view.el
self._view.el = [
self._renderTabsbar(),
self._api.editor.render()
]
return self._view.el
}
_renderTabsbar () {
var self = this
if (self._view.tabsbar) return self._view.tabsbar
self._view.filetabs = yo`<ul id="files" class="${css.files} nav nav-tabs"></ul>`
self._view.tabs = yo`
<div class=${css.tabs} onmouseenter=${toggleScrollers} onmouseleave=${toggleScrollers}>
<div onclick=${scrollLeft} class="${css.scroller} ${css.hide} ${css.scrollerleft}">
<i class="fa fa-chevron-left "></i>
</div>
${self._view.filetabs}
<div onclick=${scrollRight} class="${css.scroller} ${css.hide} ${css.scrollerright}">
<i class="fa fa-chevron-right "></i>
</div>
</div>
`
self._view.tabsbar = yo`
<div class=${css.tabsbar}>
<div class=${css.buttons}>
<span class=${css.toggleLHP} onclick=${toggleLHP} title="Toggle left hand panel">
<i class="fa fa-angle-double-left"></i>
</span>
<span class=${css.changeeditorfontsize} >
<i class="increditorsize fa fa-plus" onclick=${increase} aria-hidden="true" title="increase editor font size"></i>
<i class="decreditorsize fa fa-minus" onclick=${decrease} aria-hidden="true" title="decrease editor font size"></i>
</span>
</div>
${self._view.tabs}
<span class="${css.toggleRHP}" onclick=${toggleRHP} title="Toggle right hand panel">
<i class="fa fa-angle-double-right"></i>
</span>
</div>
`
return self._view.tabsbar
function toggleScrollers (event = {}) {
if (event.type) self.data._focus = event.type
var isMouseEnter = self.data._focus === 'mouseenter'
var leftArrow = this.children[0]
var rightArrow = this.children[2]
if (isMouseEnter && this.children[1].offsetWidth > this.offsetWidth) {
var hiddenLength = self._view.filetabs.offsetWidth - self._view.tabs.offsetWidth
var currentLeft = self._view.filetabs.offsetLeft || 0
var hiddenRight = hiddenLength + currentLeft
if (currentLeft < 0) {
leftArrow.classList.add(css.show)
leftArrow.classList.remove(css.hide)
}
if (hiddenRight > 0) {
rightArrow.classList.add(css.show)
rightArrow.classList.remove(css.hide)
}
} else {
leftArrow.classList.remove(css.show)
leftArrow.classList.add(css.hide)
rightArrow.classList.remove(css.show)
rightArrow.classList.add(css.hide)
}
}
function toggleLHP (event) {
this.children[0].classList.toggle('fa-angle-double-right')
this.children[0].classList.toggle('fa-angle-double-left')
self.event.trigger('resize', ['left'])
}
function toggleRHP (event) {
this.children[0].classList.toggle('fa-angle-double-right')
this.children[0].classList.toggle('fa-angle-double-left')
self.event.trigger('resize', ['right'])
}
function increase () { self._api.editor.editorFontSize(1) }
function decrease () { self._api.editor.editorFontSize(-1) }
function scrollLeft (event) {
var leftArrow = this
var rightArrow = this.nextElementSibling.nextElementSibling
var currentLeft = self._view.filetabs.offsetLeft || 0
if (currentLeft < 0) {
rightArrow.classList.add(css.show)
rightArrow.classList.remove(css.hide)
if (currentLeft < -self.data._FILE_SCROLL_DELTA) {
self._view.filetabs.style.left = `${currentLeft + self.data._FILE_SCROLL_DELTA}px`
} else {
self._view.filetabs.style.left = `${currentLeft - currentLeft}px`
leftArrow.classList.remove(css.show)
leftArrow.classList.add(css.hide)
}
}
}
function scrollRight (event) {
var rightArrow = this
var leftArrow = this.previousElementSibling.previousElementSibling
var hiddenLength = self._view.filetabs.offsetWidth - self._view.tabs.offsetWidth
var currentLeft = self._view.filetabs.offsetLeft || 0
var hiddenRight = hiddenLength + currentLeft
if (hiddenRight > 0) {
leftArrow.classList.add(css.show)
leftArrow.classList.remove(css.hide)
if (hiddenRight > self.data._FILE_SCROLL_DELTA) {
self._view.filetabs.style.left = `${currentLeft - self.data._FILE_SCROLL_DELTA}px`
} else {
self._view.filetabs.style.left = `${currentLeft - hiddenRight}px`
rightArrow.classList.remove(css.show)
rightArrow.classList.add(css.hide)
}
}
}
}
}
module.exports = EditorPanel

@ -24,12 +24,15 @@ document.head.appendChild(yo`
</style> </style>
`) `)
function Editor (editorElement) { function Editor (opts = {}) {
var editor = ace.edit(editorElement) var self = this
editorElement.editor = editor // required to access the editor during tests var el = yo`<div id="input"></div>`
editorElement.className += ' ' + css['ace-editor'] var editor = ace.edit(el)
el.className += ' ' + css['ace-editor']
el.editor = editor // required to access the editor during tests
self.render = function () { return el }
var event = new EventManager() var event = new EventManager()
this.event = event self.event = event
var sessions = {} var sessions = {}
var sourceAnnotations = [] var sourceAnnotations = []
var readOnlySessions = {} var readOnlySessions = {}
@ -37,7 +40,6 @@ function Editor (editorElement) {
var emptySession = createSession('') var emptySession = createSession('')
var self = this
editor.on('guttermousedown', function (e) { editor.on('guttermousedown', function (e) {
var target = e.domEvent.target var target = e.domEvent.target
if (target.className.indexOf('ace_gutter-cell') === -1) { if (target.className.indexOf('ace_gutter-cell') === -1) {

@ -13,6 +13,7 @@ var css = csjs`
display : flex; display : flex;
flex-direction : row; flex-direction : row;
width : 100%; width : 100%;
height : 100%;
box-sizing : border-box; box-sizing : border-box;
} }
.fileexplorer { .fileexplorer {
@ -28,37 +29,39 @@ var css = csjs`
.newFile { .newFile {
padding : 10px; padding : 10px;
} }
.newFile i {
cursor : pointer;
}
.newFile i:hover {
color : orange;
}
.connectToLocalhost { .connectToLocalhost {
padding : 10px; padding : 10px;
} }
.uploadFile { .connectToLocalhost i {
padding : 10px; cursor : pointer;
} }
.toggleLHP { .connectToLocalhost i:hover {
display : flex; color : orange;
justify-content : flex-end; }
.uploadFile {
padding : 10px; padding : 10px;
width : 100%;
font-weight : bold;
cursor : pointer;
color : black;
} }
.isVisible { .uploadFile label:hover {
position : absolute; color : orange;
left : 35px;
} }
.isHidden { .uploadFile label {
position : absolute; cursor : pointer;
height : 99%;
left : -101%;
} }
.treeview { .treeview {
background-color : white; background-color : white;
} }
.dragbar { .dragbar {
position : relative; position : absolute;
top : 36px; top : 37px;
left : 2px; width : 0.5em;
right : 0;
bottom : 0;
cursor : col-resize; cursor : col-resize;
z-index : 999; z-index : 999;
border-right : 2px solid hsla(215, 81%, 79%, .3); border-right : 2px solid hsla(215, 81%, 79%, .3);
@ -73,13 +76,6 @@ var css = csjs`
top : 0; top : 0;
bottom : 0; bottom : 0;
} }
.changeeditorfontsize {
padding: 10px;
}
.changeeditorfontsize i {
display: block;
color: #111111;
}
` `
var limit = 60 var limit = 60
@ -87,6 +83,7 @@ var canUpload = window.File || window.FileReader || window.FileList || window.Bl
var ghostbar = yo`<div class=${css.ghostbar}></div>` var ghostbar = yo`<div class=${css.ghostbar}></div>`
function filepanel (appAPI, filesProvider) { function filepanel (appAPI, filesProvider) {
var self = this
var fileExplorer = new FileExplorer(appAPI, filesProvider['browser']) var fileExplorer = new FileExplorer(appAPI, filesProvider['browser'])
var fileSystemExplorer = new FileExplorer(appAPI, filesProvider['localhost']) var fileSystemExplorer = new FileExplorer(appAPI, filesProvider['localhost'])
var dragbar = yo`<div onmousedown=${mousedown} class=${css.dragbar}></div>` var dragbar = yo`<div onmousedown=${mousedown} class=${css.dragbar}></div>`
@ -119,13 +116,6 @@ function filepanel (appAPI, filesProvider) {
<span onclick=${connectToLocalhost} class="${css.connectToLocalhost}"> <span onclick=${connectToLocalhost} class="${css.connectToLocalhost}">
<i class="websocketconn fa fa-link" title="Connect to Localhost"></i> <i class="websocketconn fa fa-link" title="Connect to Localhost"></i>
</span> </span>
<span class=${css.changeeditorfontsize} >
<i class="increditorsize fa fa-plus" aria-hidden="true" title="increase editor font size"></i>
<i class="decreditorsize fa fa-minus" aria-hidden="true" title="decrease editor font size"></i>
</span>
<span class=${css.toggleLHP} onclick=${toggle} title="Toggle left hand panel">
<i class="fa fa-angle-double-left"></i>
</span>
</div> </div>
<div class=${css.treeview}>${fileExplorer.init()}</div> <div class=${css.treeview}>${fileExplorer.init()}</div>
<div class="filesystemexplorer ${css.treeview}"></div> <div class="filesystemexplorer ${css.treeview}"></div>
@ -135,10 +125,10 @@ function filepanel (appAPI, filesProvider) {
` `
} }
var events = new EventManager() var event = new EventManager()
self.event = event
var element = template() var element = template()
element.querySelector('.increditorsize').addEventListener('click', () => { appAPI.editorFontSize(1) })
element.querySelector('.decreditorsize').addEventListener('click', () => { appAPI.editorFontSize(-1) })
var containerFileSystem = element.querySelector('.filesystemexplorer') var containerFileSystem = element.querySelector('.filesystemexplorer')
var websocketconn = element.querySelector('.websocketconn') var websocketconn = element.querySelector('.websocketconn')
filesProvider['localhost'].remixd.event.register('connecting', (event) => { filesProvider['localhost'].remixd.event.register('connecting', (event) => {
@ -166,9 +156,7 @@ function filepanel (appAPI, filesProvider) {
containerFileSystem.removeChild(fileSystemExplorer.element) containerFileSystem.removeChild(fileSystemExplorer.element)
} }
}) })
// TODO please do not add custom javascript objects, which have no
// relation to the DOM to DOM nodes
element.events = events
fileExplorer.events.register('focus', function (path) { fileExplorer.events.register('focus', function (path) {
appAPI.switchToFile(path) appAPI.switchToFile(path)
}) })
@ -177,15 +165,7 @@ function filepanel (appAPI, filesProvider) {
appAPI.switchToFile(path) appAPI.switchToFile(path)
}) })
return element self.render = function render () { return element }
function toggle (event) {
var isHidden = element.classList.toggle(css.isHidden)
this.classList.toggle(css.isVisible)
this.children[0].classList.toggle('fa-angle-double-right')
this.children[0].classList.toggle('fa-angle-double-left')
events.trigger('ui-hidden', [isHidden])
}
function uploadFile (event) { function uploadFile (event) {
// TODO The file explorer is merely a view on the current state of // TODO The file explorer is merely a view on the current state of
@ -195,6 +175,7 @@ function filepanel (appAPI, filesProvider) {
;[...this.files].forEach(fileExplorer.api.addFile) ;[...this.files].forEach(fileExplorer.api.addFile)
} }
// ----------------- resizeable ui ---------------
function mousedown (event) { function mousedown (event) {
event.preventDefault() event.preventDefault()
if (event.which === 1) { if (event.which === 1) {
@ -213,21 +194,21 @@ function filepanel (appAPI, filesProvider) {
document.removeEventListener('keydown', cancelGhostbar) document.removeEventListener('keydown', cancelGhostbar)
} }
} }
function moveGhostbar (event) { function getPosition (event) {
var rhp = window['righthand-panel'].offsetLeft var rhp = document.body.offsetWidth - window['righthand-panel'].offsetWidth
var newpos = (event.pageX < limit) ? limit : event.pageX var newpos = (event.pageX < limit) ? limit : event.pageX
newpos = (newpos < (rhp - limit)) ? newpos : (rhp - limit) newpos = (newpos < (rhp - limit)) ? newpos : (rhp - limit)
ghostbar.style.left = newpos + 'px' return newpos
}
function moveGhostbar (event) {
ghostbar.style.left = getPosition(event) + 'px'
} }
function removeGhostbar (event) { function removeGhostbar (event) {
document.body.removeChild(ghostbar) document.body.removeChild(ghostbar)
document.removeEventListener('mousemove', moveGhostbar) document.removeEventListener('mousemove', moveGhostbar)
document.removeEventListener('mouseup', removeGhostbar) document.removeEventListener('mouseup', removeGhostbar)
document.removeEventListener('keydown', cancelGhostbar) document.removeEventListener('keydown', cancelGhostbar)
var width = (event.pageX < limit) ? limit : event.pageX self.event.trigger('resize', [getPosition(event)])
element.style.width = width + 'px'
events.trigger('ui-resize', [width])
} }
function createNewFile () { function createNewFile () {

@ -1,5 +1,6 @@
var csjs = require('csjs-inject')
var yo = require('yo-yo') var yo = require('yo-yo')
var $ = require('jquery') var EventManager = require('ethereum-remix').lib.EventManager
var tabbedMenu = require('./tabbed-menu') var tabbedMenu = require('./tabbed-menu')
var contractTab = require('./contract-tab') var contractTab = require('./contract-tab')
@ -8,8 +9,6 @@ var analysisTab = require('./analysis-tab')
var debuggerTab = require('./debugger-tab') var debuggerTab = require('./debugger-tab')
var filesTab = require('./files-tab') var filesTab = require('./files-tab')
var csjs = require('csjs-inject')
var css = csjs` var css = csjs`
.options { .options {
float: left; float: left;
@ -21,6 +20,28 @@ var css = csjs`
margin-right: 0.5em; margin-right: 0.5em;
font-size: 1em; font-size: 1em;
} }
.dragbar {
position : absolute;
width : 0.5em;
top : 3em;
bottom : 0;
cursor : col-resize;
z-index : 999;
border-left : 2px solid hsla(215, 81%, 79%, .3);
}
.ghostbar {
width : 3px;
background-color : #C6CFF7;
opacity : 0.5;
position : absolute;
cursor : col-resize;
z-index : 9999;
top : 0;
bottom : 0;
}
.panel {
height : 100%;
}
` `
// ------------------------------------------------------------------ // ------------------------------------------------------------------
@ -30,6 +51,9 @@ module.exports = RighthandPanel
function RighthandPanel (appAPI, events, opts) { function RighthandPanel (appAPI, events, opts) {
var self = this var self = this
self._api = appAPI self._api = appAPI
self.event = new EventManager()
self._view = {}
var optionViews = yo`<div id="optionViews" class="settingsView"></div>` var optionViews = yo`<div id="optionViews" class="settingsView"></div>`
var options = yo` var options = yo`
<ul id="options"> <ul id="options">
@ -41,8 +65,10 @@ function RighthandPanel (appAPI, events, opts) {
<li id="helpButton"><a href="https://remix.readthedocs.org" target="_blank" title="Open Documentation">Docs</a></li> <li id="helpButton"><a href="https://remix.readthedocs.org" target="_blank" title="Open Documentation">Docs</a></li>
</ul> </ul>
` `
var element = yo` self._view.dragbar = yo`<div id="dragbar" class=${css.dragbar}></div>`
<div id="righthand-panel"> self._view.element = yo`
<div id="righthand-panel" class=${css.panel}>
${self._view.dragbar}
<div id="header"> <div id="header">
<div id="menu"> <div id="menu">
<img id="solIcon" title="Solidity realtime compiler and runtime" src="assets/img/remix_logo_512x512.svg" alt="Solidity realtime compiler and runtime"> <img id="solIcon" title="Solidity realtime compiler and runtime" src="assets/img/remix_logo_512x512.svg" alt="Solidity realtime compiler and runtime">
@ -58,19 +84,10 @@ function RighthandPanel (appAPI, events, opts) {
debuggerTab(optionViews, appAPI, events, opts) debuggerTab(optionViews, appAPI, events, opts)
filesTab(optionViews, appAPI, events, opts) filesTab(optionViews, appAPI, events, opts)
self.render = function () { return element } self.render = function () { return self._view.element }
self.init = function () { self.init = function () {
;[...options.children].forEach((el) => { el.classList.add(css.options) }) ;[...options.children].forEach((el) => { el.classList.add(css.options) })
// ----------------- toggle right hand panel -----------------
var hidingRHP = false
$('.toggleRHP').click(function () {
hidingRHP = !hidingRHP
self._api.setEditorSize(hidingRHP ? 0 : appAPI.config.get(EDITOR_WINDOW_SIZE))
$('.toggleRHP i').toggleClass('fa-angle-double-right', !hidingRHP)
$('.toggleRHP i').toggleClass('fa-angle-double-left', hidingRHP)
})
// ----------------- tabbed menu ----------------- // ----------------- tabbed menu -----------------
var tabbedMenuAPI = { var tabbedMenuAPI = {
@ -81,49 +98,43 @@ function RighthandPanel (appAPI, events, opts) {
tabbedMenu(options, tabbedMenuAPI, tabEvents, {}) tabbedMenu(options, tabbedMenuAPI, tabEvents, {})
// ----------------- resizeable ui --------------- // ----------------- resizeable ui ---------------
var limit = 60
var EDITOR_WINDOW_SIZE = 'editorWindowSize' self._view.dragbar.addEventListener('mousedown', mousedown)
var ghostbar = yo`<div class=${css.ghostbar}></div>`
var dragging = false function mousedown (event) {
$('#dragbar').mousedown(function (e) { event.preventDefault()
e.preventDefault() if (event.which === 1) {
dragging = true moveGhostbar(event)
var main = $('#righthand-panel') document.body.appendChild(ghostbar)
var ghostbar = $('<div id="ghostbar">', { document.addEventListener('mousemove', moveGhostbar)
css: { document.addEventListener('mouseup', removeGhostbar)
top: main.offset().top, document.addEventListener('keydown', cancelGhostbar)
left: main.offset().left }
}
}).prependTo('body')
$(document).mousemove(function (e) {
ghostbar.css('left', e.pageX + 2)
})
})
var $body = $('body')
function getEditorSize () {
return $('#righthand-panel').width()
} }
function cancelGhostbar (event) {
$(document).mouseup(function (e) { if (event.keyCode === 27) {
if (dragging) { document.body.removeChild(ghostbar)
var delta = $body.width() - e.pageX + 2 document.removeEventListener('mousemove', moveGhostbar)
$('#ghostbar').remove() document.removeEventListener('mouseup', removeGhostbar)
$(document).unbind('mousemove') document.removeEventListener('keydown', cancelGhostbar)
dragging = false
delta = (delta < 50) ? 50 : delta
self._api.setEditorSize(delta)
appAPI.config.set(EDITOR_WINDOW_SIZE, delta)
appAPI.reAdjust()
} }
}) }
function getPosition (event) {
if (appAPI.config.exists(EDITOR_WINDOW_SIZE)) { var lhp = window['filepanel'].offsetWidth
self._api.setEditorSize(appAPI.config.get(EDITOR_WINDOW_SIZE)) var max = document.body.offsetWidth - limit
} else { var newpos = (event.pageX > max) ? max : event.pageX
appAPI.config.set(EDITOR_WINDOW_SIZE, getEditorSize()) newpos = (newpos > (lhp + limit)) ? newpos : lhp + limit
return newpos
}
function moveGhostbar (event) {
ghostbar.style.left = getPosition(event) + 'px'
}
function removeGhostbar (event) {
document.body.removeChild(ghostbar)
document.removeEventListener('mousemove', moveGhostbar)
document.removeEventListener('mouseup', removeGhostbar)
document.removeEventListener('keydown', cancelGhostbar)
self.event.trigger('resize', [document.body.offsetWidth - getPosition(event)])
} }
} }
} }

Loading…
Cancel
Save