-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add better handling for initial no plugins state
- Loading branch information
Showing
3 changed files
with
79 additions
and
69 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,78 @@ | ||
import { Runner } from './runner'; | ||
import { PluginEditor } from './plugin-editor'; | ||
import { ResourcesEditor } from './resources-editor'; | ||
export const EXAMPLE = ` | ||
() => { | ||
return { | ||
// use the modules option to import modules from addresses or from the plugins gist | ||
modules: [ | ||
// if a module is a web address, it can be included this way | ||
"https://unpkg.com/[email protected]/dist/kaplay.js", | ||
// this is how you can include the contents of other files from the list | ||
//'kaplay-dist.js', // <-- copy of kaplay.js can also be stored in the gist and imported like so | ||
// you can host a module on the same gist | ||
], | ||
// if passed, inkjs or bondagejs will be included in the output - can be ink or yarn | ||
parser: 'ink', | ||
// Use the script option to write your code that uses any imported modules | ||
script: () => { | ||
// since we imported kaplayjs in the modules option, we can now use it like this to render to the Test tab | ||
const k = kaplay(); | ||
k.loadSprite("bean", "public/icon.png") | ||
k.scene("main", () => { | ||
k.add([ | ||
k.pos(200, 100), | ||
k.sprite("bean"), | ||
]); | ||
k.add([ | ||
k.text("ohhimark fdfg"), | ||
]) | ||
}); | ||
k.go("main"); | ||
// inkjs becomes available because we used parser: 'ink' option | ||
} | ||
} | ||
} | ||
` | ||
export const INTERNAL_EXAMPLE = ` | ||
() => { | ||
return { | ||
name: 'ExamplePlugin', | ||
Constructor: function( { | ||
app, | ||
createButton, | ||
createToggle, | ||
getPluginStore, | ||
setPluginStore, | ||
addSettingsItem, | ||
onYarnLoadedData, | ||
onYarnEditorOpen, | ||
onYarnInPreviewMode, | ||
onYarnSavedNode, | ||
onYarnSetLanguage, | ||
onYarnLoadedStateFromLocalStorage, | ||
onYarnSavedStateToLocalStorage, | ||
onYarnSetDocumentType, | ||
onKeyUp, | ||
onKeyDown, | ||
onLoad, | ||
}) { | ||
const self = this; | ||
this.name = 'ExamplePlugin'; | ||
this.onOpenPluginEditor = ()=> { | ||
alert("YAY!") | ||
} | ||
createButton(self.name, { | ||
name: 'ExamplePlugin', | ||
attachTo: app.settings.developmentModeEnabled() ? 'appHeader': 'fileMenuDropdown', | ||
onClick: 'onOpenPluginEditor()', | ||
iconName: 'cog', | ||
}); | ||
} | ||
} | ||
} | ||
` | ||
const PLUGINS = [Runner, PluginEditor, ResourcesEditor]; | ||
|
||
const PublicLibs = {} | ||
|
@@ -230,7 +301,7 @@ export var Plugins = function (app) { | |
}; | ||
|
||
const dbStorage = app.data.db; | ||
const getVloatilePlugins = () => dbStorage.getDbValue('volatilePlugins'); | ||
const getVloatilePlugins = () => dbStorage.getDbValue('volatilePlugins', { ['example.js']: {content: EXAMPLE}}); | ||
const setVloatilePlugins = value => dbStorage.save('volatilePlugins', value); | ||
const setVloatilePlugin = (key, value) => { | ||
return getVloatilePlugins().then(prev => { | ||
|
@@ -337,7 +408,7 @@ export var Plugins = function (app) { | |
const getExtensionScriptData = (fileContents) => { | ||
try { | ||
const extension = new Function("parameters", `return ${fileContents}`);//(); | ||
//console.log({isFunction: typeof extension === 'function', fileContents}) | ||
//console.log({isFunction: typeof extension === 'function', fileContents}) | ||
if (typeof extension === 'function') { | ||
const data = extension(); | ||
if (data) { | ||
|
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import AceDiff from './ace-diff/ace-diff.min.js'; | ||
import 'ace-builds/webpack-resolver'; // needed for the webworker to work (syntax highlighting) | ||
import { EXAMPLE, INTERNAL_EXAMPLE } from './'; | ||
|
||
const addEsVersionToEditor = editor => { | ||
editor.session.$worker.send("setOptions", [{ | ||
|
@@ -21,70 +22,6 @@ const removeStyleSheet = (path, root = document) => { | |
if (el) root.getElementById(path).remove() | ||
} | ||
|
||
const EXAMPLE = ` | ||
() => { | ||
return { | ||
modules: [ | ||
// if a module is a web address, it can be included this way | ||
"https://unpkg.com/[email protected]/dist/kaplay.js", | ||
// you can host a module on the same gist | ||
// "test-local-module.js", | ||
], | ||
script: () => { | ||
const k = kaplay(); | ||
k.loadSprite("bean", "public/icon.png") | ||
k.scene("main", () => { | ||
k.add([ | ||
k.pos(200, 100), | ||
k.sprite("bean"), | ||
]); | ||
k.add([ | ||
k.text("yarr"), | ||
]) | ||
}); | ||
k.go("main"); | ||
} | ||
} | ||
} | ||
` | ||
const INTERNAL_EXAMPLE = ` | ||
() => { | ||
return { | ||
name: 'ExamplePlugin', | ||
Constructor: function( { | ||
app, | ||
createButton, | ||
createToggle, | ||
getPluginStore, | ||
setPluginStore, | ||
addSettingsItem, | ||
onYarnLoadedData, | ||
onYarnEditorOpen, | ||
onYarnInPreviewMode, | ||
onYarnSavedNode, | ||
onYarnSetLanguage, | ||
onYarnLoadedStateFromLocalStorage, | ||
onYarnSavedStateToLocalStorage, | ||
onYarnSetDocumentType, | ||
onKeyUp, | ||
onKeyDown, | ||
onLoad, | ||
}) { | ||
const self = this; | ||
this.name = 'ExamplePlugin'; | ||
this.onOpenPluginEditor = ()=> { | ||
alert("YAY!") | ||
} | ||
createButton(self.name, { | ||
name: 'ExamplePlugin', | ||
attachTo: app.settings.developmentModeEnabled() ? 'appHeader': 'fileMenuDropdown', | ||
onClick: 'onOpenPluginEditor()', | ||
iconName: 'cog', | ||
}); | ||
} | ||
} | ||
} | ||
` | ||
|
||
const getExampleOutputFunction = (error = "") => ` | ||
<head> | ||
|