mirror of
https://github.com/hydra-synth/hydra.git
synced 2025-12-05 14:30:03 +01:00
added beautify
This commit is contained in:
@@ -6,7 +6,7 @@ export default function editorStore(state, emitter) {
|
||||
} else {
|
||||
editor.mutator.mutate({ reroll: false, changeTransform: evt.metaKey });
|
||||
editor.formatCode()
|
||||
sketches.saveLocally(editor.getValue())
|
||||
emitter.emit('gallery: save locally', editor.getValue())
|
||||
}
|
||||
})
|
||||
|
||||
@@ -17,9 +17,14 @@ export default function editorStore(state, emitter) {
|
||||
emitter.on('editor: eval all', function () {
|
||||
const editor = state.editor.editor
|
||||
const code = editor.getValue()
|
||||
repl.eval(code, (string, err) => {
|
||||
// repl.eval(code, (string, err) => {
|
||||
// editor.flashCode()
|
||||
// if (!err) sketches.saveLocally(code)
|
||||
// })
|
||||
emitter.emit('repl: eval', code, (string, err) => {
|
||||
editor.flashCode()
|
||||
if (!err) sketches.saveLocally(code)
|
||||
if (!err) emitter.emit('gallery: save locally', code)
|
||||
// sketches.saveLocally(code)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -23,7 +23,13 @@ export default function galleryStore(state, emitter) {
|
||||
let editor = state.editor.editor
|
||||
const editorText = editor.getValue()
|
||||
sketches.saveLocally(editorText)
|
||||
})
|
||||
})
|
||||
|
||||
emitter.on('gallery: save locally', function (code) {
|
||||
// let editor = state.editor.editor
|
||||
// const editorText = editor.getValue()
|
||||
sketches.saveLocally(code)
|
||||
})
|
||||
|
||||
emitter.on('gallery: clear', () => {
|
||||
sketches.clear()
|
||||
|
||||
@@ -9,13 +9,12 @@ export default function store(state, emitter) {
|
||||
// if backend gallery endpoint supplied, then enable gallery functionality
|
||||
const SERVER_URL = import.meta.env.VITE_SERVER_URL
|
||||
state.serverURL = SERVER_URL !== undefined ? SERVER_URL : null
|
||||
let sketches
|
||||
|
||||
|
||||
emitter.on('load and eval code', (code) => {
|
||||
const editor = state.editor.editor
|
||||
editor.setValue(code)
|
||||
repl.eval(code)
|
||||
emitter.emit('repl: eval', code)
|
||||
})
|
||||
|
||||
emitter.on('repl: eval', (code = '', callback) => {
|
||||
@@ -52,8 +51,6 @@ export default function store(state, emitter) {
|
||||
})
|
||||
|
||||
|
||||
|
||||
|
||||
emitter.on('hideAll', function () {
|
||||
state.showUI = !state.showUI
|
||||
emitter.emit('render')
|
||||
@@ -61,12 +58,24 @@ export default function store(state, emitter) {
|
||||
|
||||
emitter.on('toggle info', function (count) {
|
||||
if (state.showInfo) {
|
||||
state.showInfo = false
|
||||
state.showExtensions = false
|
||||
// state.showInfo = false
|
||||
// state.showExtensions = false
|
||||
emitter.emit('ui: hide info')
|
||||
} else {
|
||||
state.showInfo = true
|
||||
emitter.emit('ui: show info')
|
||||
}
|
||||
// state.showInfo = !state.showInfo
|
||||
//emitter.emit('render')
|
||||
})
|
||||
|
||||
emitter.on('ui: show info', () => {
|
||||
state.showInfo = true
|
||||
emitter.emit('render')
|
||||
})
|
||||
|
||||
emitter.on('ui: hide info', () => {
|
||||
state.showInfo = false
|
||||
state.showExtensions = false
|
||||
emitter.emit('render')
|
||||
})
|
||||
|
||||
|
||||
@@ -10,7 +10,9 @@ import 'codemirror-minified/addon/comment/comment'
|
||||
import EventEmitter from 'nanobus'
|
||||
import keymaps from './keymaps.js'
|
||||
import Mutator from './randomizer/Mutator.js'
|
||||
import { beautify_js } from 'js-beautify'
|
||||
import beautify from 'js-beautify'
|
||||
|
||||
console.log('BEAUTIFY', beautify)
|
||||
|
||||
var isShowing = true
|
||||
|
||||
@@ -82,7 +84,7 @@ export default class Editor extends EventEmitter {
|
||||
}
|
||||
|
||||
formatCode() {
|
||||
const formatted = beautify_js(this.cm.getValue(), { indent_size: 2, "break_chained_methods": true, "indent_with_tabs": true})
|
||||
const formatted = beautify(this.cm.getValue(), { indent_size: 2, "break_chained_methods": true, "indent_with_tabs": true})
|
||||
this.cm.setValue(formatted)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user