REFACTOR ui state + production build

pull/1/head
serapath 8 years ago
parent 39491d97fe
commit f09f5a38a3
  1. 30
      package.json
  2. 37
      src/app.js
  3. 5
      src/app/file-explorer.js
  4. 12
      src/app/storage.js

@ -5,38 +5,12 @@
"description": "Minimalistic browser-based Solidity IDE", "description": "Minimalistic browser-based Solidity IDE",
"devDependencies": { "devDependencies": {
"async": "^2.1.2", "async": "^2.1.2",
"babel-cli": "^6.16.0",
"babel-eslint": "^7.1.1", "babel-eslint": "^7.1.1",
"babel-plugin-check-es2015-constants": "^6.8.0",
"babel-plugin-transform-es2015-arrow-functions": "^6.8.0",
"babel-plugin-transform-es2015-block-scoped-functions": "^6.8.0",
"babel-plugin-transform-es2015-block-scoping": "^6.18.0",
"babel-plugin-transform-es2015-classes": "^6.18.0",
"babel-plugin-transform-es2015-computed-properties": "^6.8.0",
"babel-plugin-transform-es2015-destructuring": "^6.18.0",
"babel-plugin-transform-es2015-duplicate-keys": "^6.8.0",
"babel-plugin-transform-es2015-for-of": "^6.18.0",
"babel-plugin-transform-es2015-function-name": "^6.9.0",
"babel-plugin-transform-es2015-literals": "^6.8.0",
"babel-plugin-transform-es2015-object-super": "^6.8.0",
"babel-plugin-transform-es2015-parameters": "^6.18.0",
"babel-plugin-transform-es2015-shorthand-properties": "^6.18.0",
"babel-plugin-transform-es2015-spread": "^6.8.0",
"babel-plugin-transform-es2015-sticky-regex": "^6.8.0",
"babel-plugin-transform-es2015-template-literals": "^6.8.0",
"babel-plugin-transform-es2015-unicode-regex": "^6.11.0",
"babel-plugin-transform-regenerator": "^6.16.1",
"babel-polyfill": "^6.22.0",
"babel-plugin-yo-yoify": "^0.3.3", "babel-plugin-yo-yoify": "^0.3.3",
"babel-polyfill": "^6.22.0",
"babel-preset-es2015": "^6.24.0", "babel-preset-es2015": "^6.24.0",
"babelify": "^7.3.0", "babelify": "^7.3.0",
"brace": "^0.8.0", "brace": "^0.8.0",
"browserify": "^13.0.0",
"browserify-reload": "^1.0.3", "browserify-reload": "^1.0.3",
"csjs-inject": "^1.0.1", "csjs-inject": "^1.0.1",
"csslint": "^1.0.2", "csslint": "^1.0.2",
@ -161,6 +135,6 @@
"start": "npm-run-all -lpr serve watch onchange", "start": "npm-run-all -lpr serve watch onchange",
"test": "standard; npm run csslint; node test/index.js", "test": "standard; npm run csslint; node test/index.js",
"test-browser": "npm-run-all -lpr selenium downloadsolc make-mock-compiler serve browsertest", "test-browser": "npm-run-all -lpr selenium downloadsolc make-mock-compiler serve browsertest",
"watch": "watchify src/index.js -dv --delay 0 -p browserify-reload -o '| npm run sourcemap'" "watch": "watchify src/index.js --transform-key=development -dv -p browserify-reload -o build/app.js"
} }
} }

@ -46,10 +46,13 @@ window.addEventListener('message', function (ev) {
var run = function () { var run = function () {
var self = this var self = this
this.event = new EventManager() this.event = new EventManager()
var storage = new Storage() var fileStorage = new Storage('sol:')
var files = new Files(storage) var files = new Files(fileStorage)
var config = new Config(storage) var config = new Config(fileStorage)
var currentFile var uiStorage = new Storage('sol-ui:')
var ui = new Files(uiStorage)
ui.set('currentFile', '')
// return all the files, except the temporary/readonly ones // return all the files, except the temporary/readonly ones
function packageFiles () { function packageFiles () {
@ -183,7 +186,8 @@ var run = function () {
filepanel.className = css.filepanel filepanel.className = css.filepanel
var FilePanelAPI = { var FilePanelAPI = {
createName: createNonClashingName, createName: createNonClashingName,
switchToFile: switchToFile switchToFile: switchToFile,
ui: ui.event
} }
var el = new FilePanel(FilePanelAPI, files) var el = new FilePanel(FilePanelAPI, files)
filepanel.appendChild(el) filepanel.appendChild(el)
@ -220,7 +224,7 @@ var run = function () {
}) })
}) })
files.event.register('fileRemoved', function (path) { files.event.register('fileRemoved', function (path) {
if (path === currentFile) currentFile = null if (path === ui.get('currentFile')) ui.set('currentFile', '')
}) })
// ------------------ gist publish -------------- // ------------------ gist publish --------------
@ -318,7 +322,7 @@ var run = function () {
if (!files.rename(originalName, newName)) { if (!files.rename(originalName, newName)) {
alert('Error while renaming file') alert('Error while renaming file')
} else { } else {
currentFile = null ui.set('currentFile', '')
switchToFile(newName) switchToFile(newName)
editor.discard(originalName) editor.discard(originalName)
} }
@ -339,7 +343,7 @@ var run = function () {
if (!files.remove(name)) { if (!files.remove(name)) {
alert('Error while removing file') alert('Error while removing file')
} else { } else {
currentFile = null ui.set('currentFile', '')
switchToNextFile() switchToNextFile()
editor.discard(name) editor.discard(name)
} }
@ -352,9 +356,7 @@ var run = function () {
function switchToFile (file) { function switchToFile (file) {
editorSyncFile() editorSyncFile()
currentFile = file ui.set('currentFile', file)
files.event.trigger('fileFocus', [file])
if (files.isReadOnly(file)) { if (files.isReadOnly(file)) {
editor.openReadOnly(file, files.get(file)) editor.openReadOnly(file, files.get(file))
@ -385,10 +387,10 @@ var run = function () {
$filesEl.append($('<li class="file"><span class="name">' + name + '</span><span class="remove"><i class="fa fa-close"></i></span></li>')) $filesEl.append($('<li class="file"><span class="name">' + name + '</span><span class="remove"><i class="fa fa-close"></i></span></li>'))
} }
var currentFileOpen = !!currentFile var currentFileOpen = !!ui.get('currentFile')
if (currentFileOpen) { if (currentFileOpen) {
var active = $('#files .file').filter(function () { return $(this).find('.name').text() === currentFile }) var active = $('#files .file').filter(function () { return $(this).find('.name').text() === ui.get('currentFile') })
active.addClass('active') active.addClass('active')
} }
$('#input').toggle(currentFileOpen) $('#input').toggle(currentFileOpen)
@ -636,7 +638,7 @@ var run = function () {
this.fullLineMarker = null this.fullLineMarker = null
if (lineColumnPos) { if (lineColumnPos) {
var source = compiler.lastCompilationResult.data.sourceList[location.file] // auto switch to that tab var source = compiler.lastCompilationResult.data.sourceList[location.file] // auto switch to that tab
if (currentFile !== source) { if (ui.get('currentFile') !== source) {
switchToFile(source) switchToFile(source)
} }
this.statementMarker = editor.addMarker(lineColumnPos, 'highlightcode') this.statementMarker = editor.addMarker(lineColumnPos, 'highlightcode')
@ -760,12 +762,12 @@ var run = function () {
var rendererAPI = { var rendererAPI = {
error: (file, error) => { error: (file, error) => {
if (file === currentFile) { if (file === ui.get('currentFile')) {
editor.addAnnotation(error) editor.addAnnotation(error)
} }
}, },
errorClick: (errFile, errLine, errCol) => { errorClick: (errFile, errLine, errCol) => {
if (errFile !== currentFile && files.exists(errFile)) { if (errFile !== ui.get('currentFile') && files.exists(errFile)) {
switchToFile(errFile) switchToFile(errFile)
} }
editor.gotoLine(errLine, errCol) editor.gotoLine(errLine, errCol)
@ -814,6 +816,7 @@ var run = function () {
function runCompiler () { function runCompiler () {
editorSyncFile() editorSyncFile()
var currentFile = ui.get('currentFile')
if (currentFile) { if (currentFile) {
var target = currentFile var target = currentFile
var sources = {} var sources = {}
@ -823,6 +826,7 @@ var run = function () {
} }
function editorSyncFile () { function editorSyncFile () {
var currentFile = ui.get('currentFile')
if (currentFile) { if (currentFile) {
var input = editor.get(currentFile) var input = editor.get(currentFile)
files.set(currentFile, input) files.set(currentFile, input)
@ -834,6 +838,7 @@ var run = function () {
var saveTimeout = null var saveTimeout = null
function editorOnChange () { function editorOnChange () {
var currentFile = ui.get('currentFile')
if (!currentFile) { if (!currentFile) {
return return
} }

@ -37,6 +37,7 @@ module.exports = fileExplorer
function fileExplorer (appAPI, files) { function fileExplorer (appAPI, files) {
var fileEvents = files.event var fileEvents = files.event
var appUI = appAPI.ui
var tv = new Treeview({ var tv = new Treeview({
extractData: function (value, tree, key) { extractData: function (value, tree, key) {
var newValue = {} var newValue = {}
@ -75,7 +76,7 @@ function fileExplorer (appAPI, files) {
</span> </span>
` `
fileEvents.register('fileFocus', fileFocus) appUI.register('currentFile', fileFocus)
fileEvents.register('fileRemoved', fileRemoved) fileEvents.register('fileRemoved', fileRemoved)
fileEvents.register('fileRenamed', fileRenamed) fileEvents.register('fileRenamed', fileRenamed)
fileEvents.register('fileAdded', fileAdded) fileEvents.register('fileAdded', fileAdded)
@ -182,7 +183,7 @@ function fileExplorer (appAPI, files) {
var allPaths = Object.keys(files.list()) var allPaths = Object.keys(files.list())
for (var i = 0, len = allPaths.length, path, err; i < len; i++) { for (var i = 0, len = allPaths.length, path, err; i < len; i++) {
path = allPaths[i] path = allPaths[i]
if (files.IsReadOnly(path)) { if (files.isReadOnly(path)) {
err = 'path contains readonly elements' err = 'path contains readonly elements'
break break
} else if (path.indexOf(newPath) === 0) { } else if (path.indexOf(newPath) === 0) {

@ -1,17 +1,17 @@
'use strict' 'use strict'
function Storage () { function Storage (prefix) {
this.exists = function (name) { this.exists = function (name) {
return this.get(name) !== null return this.get(name) !== null
} }
this.get = function (name) { this.get = function (name) {
return window.localStorage.getItem('sol:' + name) return window.localStorage.getItem(prefix + name)
} }
this.set = function (name, content) { this.set = function (name, content) {
try { try {
window.localStorage.setItem('sol:' + name, content) window.localStorage.setItem(prefix + name, content)
} catch (exception) { } catch (exception) {
return false return false
} }
@ -19,7 +19,7 @@ function Storage () {
} }
this.remove = function (name) { this.remove = function (name) {
window.localStorage.removeItem('sol:' + name) window.localStorage.removeItem(prefix + name)
return true return true
} }
@ -40,7 +40,7 @@ function Storage () {
this.keys = function () { this.keys = function () {
return safeKeys() return safeKeys()
// filter any names not including sol: // filter any names not including sol:
.filter(function (item) { return item.indexOf('sol:', 0) === 0 }) .filter(function (item) { return item.indexOf(prefix, 0) === 0 })
// remove sol: from filename // remove sol: from filename
.map(function (item) { return item.replace(/^sol:/, '') }) .map(function (item) { return item.replace(/^sol:/, '') })
} }
@ -49,7 +49,7 @@ function Storage () {
safeKeys().forEach(function (name) { safeKeys().forEach(function (name) {
if (name.indexOf('sol-cache-file-', 0) === 0) { if (name.indexOf('sol-cache-file-', 0) === 0) {
var content = window.localStorage.getItem(name) var content = window.localStorage.getItem(name)
window.localStorage.setItem(name.replace(/^sol-cache-file-/, 'sol:'), content) window.localStorage.setItem(name.replace(/^sol-cache-file-/, prefix), content)
window.localStorage.removeItem(name) window.localStorage.removeItem(name)
} }
}) })

Loading…
Cancel
Save