{"version":3,"sources":["https://lively-kernel.org/lively4/lively4-RP19-4/src/components/tools/lively-plugin-explorer.js"],"names":["Morph","babelDefault","SyntaxChecker","sourcemap","generateUUID","uuid","debounce","flatmap","executeAllTestRunners","promisedEvent","babel","PluginExplorer","defaultPluginURL","lively4url","defaultWorkspacePath","container","get","executionConsole","sourceLCM","sourceCM","editor","source","getValue","sourceAstInspector","pluginEditor","pluginLCM","livelyCodeMirror","pluginCM","currentEditor","pluginSource","getPlugin","url","fullUrl","pluginURL","module","System","import","default","transformedSourceLCM","transformedSourceCM","getURLString","workspacePath","workspaceURL","value","urlString","onWorkspacePathEntered","loadWorkspaceFile","saveButton","autoSave","bool","classList","toggle","workspace","onSave","evt","button","save","updateButton","autoUpdate","querySelector","onUpdate","updateAST","runsTestsButton","runsTests","onToggleRunsTests","executeButton","autoExecute","onExecute","execute","systemJSButton","systemJS","onToggleSystemJS","options","lively","paths","normalizePath","e","initialize","windowTitle","registerButtons","getAllSubmorphs","forEach","addEventListener","preventDefault","stopPropagation","currentTarget","dispatchEvent","MouseEvent","debouncedUpdateAST","debouncedUpdateTransformation","updateTransformation","enableSyntaxCheckForEditor","checkForSyntaxErrors","awaitEditor","then","hideToolbar","doSave","saveFile","reloadModule","on","onTransformedSourceSelectionChanged","editorLoaded","connectLivelyCodeMirror","onSourceSelectionChanged","code","Promise","all","CustomEvent","URL","response","fetch","text","ws","BabelWorkspace","deserialize","loadWorkspace","error","console","log","setURL","plugin","loadFile","setOptions","option","defaultValue","Object","entries","saveWorkspaceFile","serialize","method","body","ast","toAST","inspect","Error","message","group","self","lively4lastSystemJSBabelConfig","config","assign","originalPluginURL","replace","plugins","filter","ea","livelyLocation","concat","filename","sourceFileName","moduleIds","transformationResult","transform","transformAsAST","err","groupEnd","innerHTML","textContent","oldLog","fragments","call","join","transformedSource","modURL","swxURL","unloadModule","result","boundEval","originalPositionFor","line","column","smc","SourceMapConsumer","map","generatedPositionFor","mapEditorsFromToPosition","fromTextEditor","toTextEditor","backward","range","listSelections","start","anchor","ch","end","head","setSelection","setTimeout","isFocused","livelyPrepareSave","setAttribute","livelyMigrate","other","livelyExample","Source","json","JSON","parse","stringify"],"mappings":";;;;;;AAAOA,W;;AACAC,kB;;AAEAC,mB;;AACAC,e;;AACUC,kB,UAARC,I;AAAsBC,c,UAAAA,Q;AAAUC,a,UAAAA,O;AAASC,2B,UAAAA,qB;AAAuBC,mB,UAAAA,a;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAHzE,YAAMC,QAAQT,aAAaS,KAA3B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKe,YAAMC,cAAN,SAA6BX,KAA7B,CAAmC;;AAEhD,mBAAWY,gBAAX,GAA8B;AAAE,iBAAOC,aAAa,6DAApB;AAAoF;;AAEpH,mBAAWC,oBAAX,GAAkC;AAAE,iBAAO,mEAAP;AAA6E;;AAEjH;;AAEA,YAAIC,SAAJ,GAAgB;AAAE,iBAAO,KAAKC,GAAL,CAAS,UAAT,CAAP;AAA8B;;AAEhD,YAAIC,gBAAJ,GAAuB;AAAE,iBAAO,KAAKD,GAAL,CAAS,mBAAT,CAAP;AAAuC;;AAEhE,YAAIE,SAAJ,GAAgB;AAAE,iBAAO,KAAKF,GAAL,CAAS,SAAT,CAAP;AAA6B;AAC/C,YAAIG,QAAJ,GAAe;AAAE,iBAAO,KAAKD,SAAL,CAAeE,MAAtB;AAA+B;AAChD,YAAIC,MAAJ,GAAa;AAAE,iBAAO,KAAKF,QAAL,CAAcG,QAAd,EAAP;AAAkC;;AAEjD,YAAIC,kBAAJ,GAAyB;AAAE,iBAAO,KAAKP,GAAL,CAAS,YAAT,CAAP;AAAgC;;AAE3D,YAAIQ,YAAJ,GAAmB;AAAE,iBAAO,KAAKR,GAAL,CAAS,SAAT,CAAP;AAA6B;AAClD,YAAIS,SAAJ,GAAgB;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,mBADP,EAC4B,KAAKpB,QADjC,EAC2C,IAD3C;AAED;AACF,WALD,EAKG,CALH;AAMD;;AAED;;AAEA0K,4BAAoB;AAClB,eAAKC,YAAL,CAAkB,WAAlB,EAA+B7E,eAAee,SAAf,CAAyB,KAAK5E,SAA9B,CAA/B;AACAiE,kBAAQC,GAAR,CAAY,gCAAZ;AACD;;AAEDyE,sBAAcC,KAAd,EAAqB;AACnB;AACA,eAAK9G,gBAAL,CAAsB,YAAtB,EAAoC,MAAM;AACxC,iBAAKiC,aAAL,CAAmB6E,MAAM5I,SAAzB;AACA;AACA;AACA;AACA;AACD,WAND;AAOD;;AAED6I,wBAAgB;AACd,eAAKnJ,iBAAL,CAAuBnC,eAAeG,oBAAtC;AACD;AAlY+C;;yBAA7BH,c;;;;;;;;;;;;;;;;AAqYrB,YAAMuL,MAAN,CAAa;AACX;;;;AADW;;;;;;;;;;;;;;;AAOb,YAAMjF,cAAN,CAAqB;AACnB,eAAOC,WAAP,CAAmBiF,IAAnB,EAAyB;AACvB,iBAAOC,KAAKC,KAAL,CAAWF,IAAX,CAAP;AACA;;AAEA;AACD;;AAED,eAAOnE,SAAP,CAAiBhB,EAAjB,EAAqB;AACnB,iBAAOoF,KAAKE,SAAL,CAAetF,EAAf,CAAP;AACD;AAVkB","file":"lively-plugin-explorer.js","sourcesContent":["import Morph from 'src/components/widgets/lively-morph.js';\nimport babelDefault from 'systemjs-babel-build';\nconst babel = babelDefault.babel;\nimport SyntaxChecker from 'src/client/syntax.js'\nimport sourcemap from 'src/external/source-map.min.js'\nimport { uuid as generateUUID, debounce, flatmap, executeAllTestRunners, promisedEvent } from 'utils';\n\nexport default class PluginExplorer extends Morph {\n\n  static get defaultPluginURL() { return lively4url + \"/src/components/tools/lively-ast-explorer-example-plugin.js\"; }\n\n  static get defaultWorkspacePath() { return \"/src/components/tools/lively-plugin-explorer-playground.workspace\"; }\n\n  /*MD ## UI Accessing MD*/\n\n  get container() { return this.get(\"#content\"); }\n\n  get executionConsole() { return this.get(\"#executionConsole\"); }\n\n  get sourceLCM() { return this.get(\"#source\"); }\n  get sourceCM() { return this.sourceLCM.editor; }\n  get source() { return this.sourceCM.getValue(); }\n\n  get sourceAstInspector() { return this.get(\"#sourceAst\"); }\n  \n  get pluginEditor() { return this.get(\"#plugin\"); }\n  get pluginLCM() { return this.pluginEditor.livelyCodeMirror(); }\n  get pluginCM() { return this.pluginEditor.currentEditor(); }\n  get pluginSource() { return this.pluginCM.getValue(); }\n\n  async getPlugin() {\n    const url = this.fullUrl(this.pluginURL) || \"\";\n    const module = await System.import(url);\n    // url +=  \"?\" + Date.now(); // #HACK, we thought we don't have this to do any more, but ran into a problem when dealing with syntax errors...\n    // assumend problem: there is a bad version of the code in either the browser or system.js cache\n    // idea: we have to find and flush it...\n    // wip: the browser does not cache it, but system.js does...\n    return module.default;\n  }\n  \n  get transformedSourceLCM() { return this.get(\"#transformedSource\"); }\n  get transformedSourceCM() { return this.transformedSourceLCM.editor; }\n  \n  get pluginURL() { return this.pluginEditor.getURLString(); }\n\n  get workspacePath() { return this.get(\"#workspace-path\"); }\n  get workspaceURL() { return this.workspacePath.value; }\n  set workspaceURL(urlString) { this.workspacePath.value = urlString; }\n  onWorkspacePathEntered(urlString) { this.loadWorkspaceFile(urlString); }\n  \n  get saveButton() { return this.get(\"#save\"); }\n  get autoSave() { return false; }\n  set autoSave(bool) {\n    this.saveButton.classList.toggle(\"on\", bool);\n    this.workspace.autoSave = bool;\n  }\n  onSave(evt) {\n    if (evt.button === 2) this.autoSave = !this.autoSave;\n    this.save();\n  }\n\n  get updateButton() { return this.get(\"#update\"); }\n  get autoUpdate() { return this.workspace.autoUpdate; }\n  set autoUpdate(bool) {\n    this.updateButton.classList.toggle(\"on\", bool);\n    this.updateButton.querySelector(\"i\").classList.toggle(\"fa-spin\", bool);\n    this.workspace.autoUpdate = bool;\n  }\n  onUpdate(evt) {\n    if (evt.button === 2) this.autoUpdate = !this.autoUpdate;\n    this.updateAST();\n  }\n\n  get runsTestsButton() { return this.get(\"#toggleRunsTests\"); }\n  get runsTests() { return this.workspace.runsTests; }\n  set runsTests(bool) {\n    this.runsTestsButton.classList.toggle(\"on\", bool);\n    this.workspace.runsTests = bool;\n  }\n  onToggleRunsTests() { this.runsTests = !this.runsTests; }\n\n  get executeButton() { return this.get(\"#execute\"); }\n  get autoExecute() { return this.workspace.autoExecute; }\n  set autoExecute(bool) {\n    this.executeButton.querySelector(\"i\").classList.toggle(\"fa-spin\", bool);\n    this.executeButton.classList.toggle(\"on\", bool);\n    this.workspace.autoExecute = bool;\n  }\n  onExecute(evt) {\n    if (evt.button === 2) this.autoExecute = !this.autoExecute;\n    this.execute();\n  }\n  \n  get systemJSButton() { return this.get(\"#toggleSystemJS\"); }\n  get systemJS() { return this.workspace.systemJS; }\n  set systemJS(bool) {\n    this.systemJSButton.classList.toggle(\"on\", bool);\n    this.workspace.systemJS = bool;\n  }\n  onToggleSystemJS() { this.systemJS = !this.systemJS; }\n  \n  get options() {\n    return {\n      \"systemJS\": false,\n      \"autoExecute\": true,\n      \"runsTests\": false,\n      \"autoUpdate\": true,\n      \"autoSave\": true, \n    }\n  }\n\n  /*MD ## Initialization MD*/\n\n  fullUrl(urlString) {\n    try {\n      return lively.paths.normalizePath(urlString, \"\");\n    } catch(e) {\n      return null;\n    }\n  }\n\n  async initialize() {\n    this.windowTitle = \"Plugin Explorer\";\n    this.registerButtons();\n\n    this.workspace = {};\n\n    this.getAllSubmorphs(\"button\").forEach(button => {\n      button.addEventListener('contextmenu', e => {\n        e.preventDefault();\n        e.stopPropagation();\n        e.currentTarget.dispatchEvent(new MouseEvent(\"click\", {button: 2}));\n      });\n    });\n\n    this.debouncedUpdateAST = this.updateAST::debounce(500);\n    this.debouncedUpdateTransformation = this.updateTransformation::debounce(500);\n    \n    function enableSyntaxCheckForEditor(editor) {\n      editor.addEventListener(\"change\", (evt => SyntaxChecker.checkForSyntaxErrors(editor.editor))::debounce(200));\n    }\n\n    this.pluginEditor.awaitEditor().then(() => {\n      this.pluginEditor.hideToolbar();\n      this.pluginLCM.doSave = async () => {\n        await this.pluginEditor.saveFile();\n\n        await lively.reloadModule(\"\" + this.pluginURL);\n        this.updateAST();\n      };\n      enableSyntaxCheckForEditor(this.pluginLCM);\n      // this.pluginLCM.addEventListener(\"change\", evt => {if (this.autoUpdate) this.debouncedUpdateTransformation()});\n      this.transformedSourceCM.on(\"beforeSelectionChange\", evt => this.onTransformedSourceSelectionChanged(evt));\n    });\n\n    this.sourceLCM.editorLoaded().then(() => {\n      this.sourceAstInspector.connectLivelyCodeMirror(this.sourceLCM);\n      this.sourceLCM.doSave = async () => {\n        // TODO: Save source\n        this.updateAST();\n      };\n      enableSyntaxCheckForEditor(this.sourceLCM);\n      this.sourceLCM.addEventListener(\"change\", evt => {if (this.autoUpdate) this.debouncedUpdateAST()});\n      this.sourceCM.on(\"beforeSelectionChange\", evt => this.onSourceSelectionChanged(evt));\n    });\n\n    this.workspacePath.addEventListener(\"keyup\", evt => {\n      if (evt.code == \"Enter\") this.onWorkspacePathEntered(this.workspacePath.value);\n    });\n\n    await Promise.all([\n      this.pluginEditor.awaitEditor(),\n      this.sourceLCM.editorLoaded(),\n      this.transformedSourceLCM.editorLoaded(),\n    ]);\n    \n    this.dispatchEvent(new CustomEvent(\"initialize\"));\n  }\n\n  async loadWorkspaceFile(urlString) {\n    try {\n      const url = new URL(this.fullUrl(urlString));\n      const response = await fetch(url);\n      const text = await response.text();\n      const ws = BabelWorkspace.deserialize(text);\n      this.workspacePath.value = urlString;\n      this.loadWorkspace(ws);\n    } catch (e) {\n      lively.error(`[Plugin Explorer] Failed to load workspace.`, urlString);\n    }\n  }\n\n  async loadWorkspace(ws) {\n    console.log(ws);\n    this.workspace = ws;\n    this.pluginEditor.setURL(new URL(this.fullUrl(ws.plugin)));\n    this.pluginEditor.loadFile();\n    //TODO\n    this.sourceLCM.value = \"\"; //new URL(this.fullUrl(ws.source))\n    this.setOptions(ws);\n  }\n  \n  async setOptions(ws) {\n    for (const [option, defaultValue] of Object.entries(this.options)) {\n      console.log(option, defaultValue);\n      this[option] = option in ws ? ws[option] : defaultValue;\n    }\n  }\n\n  async saveWorkspaceFile(urlString) {\n    try {\n      const url = new URL(this.fullUrl(urlString));\n      const text = BabelWorkspace.serialize(this.workspace);\n      await fetch(url, {\n        method: 'PUT', \n        body: text,\n      });\n    } catch (e) {\n      lively.error('[Plugin Explorer] Failed to save workspace.', urlString);\n    }\n  }\n\n  /*MD ## Execution MD*/\n\n  async updateAST() {\n    try {\n      this.ast = this.source.toAST();\n      this.sourceAstInspector.inspect(this.ast);\n      this.updateTransformation();\n    } catch (e) {\n      this.ast = null;\n      this.sourceAstInspector.inspect({Error: e.message});\n    }\n  }\n\n  async updateTransformation() {\n    const plugin = await this.getPlugin();\n    \n    try {\n      console.group(\"PLUGIN TRANSFORMATION\");\n      if (!this.ast) return;\n      if (this.systemJS) {\n        // use SystemJS config do do a full transform\n        if (!self.lively4lastSystemJSBabelConfig) {\n          lively.error(\"lively4lastSystemJSBabelConfig missing\");\n          return;\n        }\n        let config = Object.assign({}, self.lively4lastSystemJSBabelConfig);\n        let url = this.fullUrl(this.pluginURL) || \"\";\n        let originalPluginURL = url.replace(/-dev/,\"\"); // name of the original plugin .... the one without -dev\n        // replace the original plugin with the one under development.... e.g. -dev\n        config.plugins = config.plugins.filter(ea => !ea.livelyLocation || !(ea.livelyLocation == originalPluginURL))\n                          .concat([plugin])\n        let filename = \"tempfile.js\";\n        config.filename = filename\n        config.sourceFileName = filename\n        config.moduleIds = false\n        this.transformationResult = babel.transform(this.source, config);\n      } else {\n        this.transformationResult = this.ast.transformAsAST(plugin);\n      }\n      \n      this.transformedSourceLCM.value = this.transformationResult.code;\n      \n      if (this.autoExecute) this.execute();\n      if (this.runsTests) executeAllTestRunners();\n    } catch(err) {\n      console.error(err);\n      this.transformedSourceLCM.value = \"Error: \" + err.message;\n    } finally {\n      console.groupEnd();\n    }\n  }\n\n  async execute() {\n    const log = this.executionConsole;\n    log.innerHTML = \"\";\n    log.textContent = \"\";\n    \n    const oldLog = console.log\n    try {\n      console.group(\"[Plugin Explorer] EXECUTE REWRITTEN FILE\");\n      console.log = (...fragments) => {\n        oldLog.call(console, ...fragments)\n        log.textContent += fragments.join(', ') + \"\\n\"\n      }\n      // #TODO active expressions...\n      var transformedSource = this.transformedSourceCM.getValue()\n      if (this.systemJS) {\n        // use systemjs to load it's module without any further transformation\n        var url = \"tmp://\" + filename // replace this with local TMP \n        \n        var modURL = lively.swxURL(url)\n        await lively.unloadModule(modURL)\n        await fetch(url, {\n          method: \"PUT\",\n          body: transformedSource \n        })\n        await System.import(modURL)\n      } else {\n        var result ='' + (await this.transformedSourceLCM.boundEval(transformedSource)).value;\n      }\n      \n      // var result ='' + eval(this.outputEditor.editor.getValue());\n      this.executionConsole.textContent += \"-> \" + result;       \n    } catch(e) {\n      console.error(e);\n      this.executionConsole.textContent += \"Error: \" + e\n    } finally {\n      console.log = oldLog\n      console.groupEnd();\n    }\n  }\n\n  save() {\n    this.pluginEditor.saveFile();\n    this.saveWorkspaceFile(this.workspaceURL);\n  }\n\n  /*MD ## Mapping Sources MD*/\n\n  originalPositionFor(line, column) {\n    var smc =  new sourcemap.SourceMapConsumer(this.transformationResult.map)\n    return smc.originalPositionFor({\n      line: line,\n      column: column\n    })\n  }\n  \n  generatedPositionFor(line, column) {\n    if (!this.transformationResult || !this.transformationResult.map) return; \n    var smc =  new sourcemap.SourceMapConsumer(this.transformationResult.map)\n    return smc.generatedPositionFor({\n      source: \"tempfile.js\",\n      line: line,\n      column: column\n    });\n  }\n  \n  mapEditorsFromToPosition(fromTextEditor, toTextEditor, backward) {\n    if (backward == true) {\n      var method = \"originalPositionFor\"\n    } else {\n      method = \"generatedPositionFor\"\n    }\n    var range = fromTextEditor.listSelections()[0]\n    var start = this[method](range.anchor.line + 1, range.anchor.ch + 1)\n    var end = this[method](range.head.line + 1, range.head.ch + 1)\n\n    //lively.notify(`start ${range.anchor.line} ch ${range.anchor.ch} ->  ${start.line} ch ${start.column} / end ${range.head.line} ch ${range.head.ch} -> ${end.line} c ${end.column}`)\n    if (!start || !end) return;\n\n    toTextEditor.setSelection(\n      {line: start.line - 1, ch:start.column - 1}, {line: end.line -  1, ch: end.column - 1})\n  }\n  \n  onSourceSelectionChanged(evt) {\n    setTimeout(() => {\n      if(this.sourceLCM.isFocused()) {\n        this.mapEditorsFromToPosition(\n          this.sourceCM, this.transformedSourceCM, false)\n      }\n    }, 0);\n  }\n  onTransformedSourceSelectionChanged(evt) {\n    setTimeout(() => {\n      if(this.transformedSourceLCM.isFocused()) {\n        this.mapEditorsFromToPosition(\n          this.transformedSourceCM, this.sourceCM, true)\n      }\n    }, 0);\n  }\n\n  /*MD ## Lively Integration MD*/\n\n  livelyPrepareSave() {\n    this.setAttribute('workspace', BabelWorkspace.serialize(this.workspace));\n    console.log(\"PREPARE SAVE (Plugin Explorer)\");\n  }\n  \n  livelyMigrate(other) {\n    // #TODO: do we still need this?\n    this.addEventListener(\"initialize\", () => {\n      this.loadWorkspace(other.workspace);\n      // this.transformedSourceCM.setValue(other.transformedSourceCM.getValue()); \n      // this.transformationResult = other.transformationResult;\n      // this.runsTests = other.runTests;\n      // this.updateAST();\n    });\n  }\n\n  livelyExample() {\n    this.loadWorkspaceFile(PluginExplorer.defaultWorkspacePath);\n  }\n}\n\nclass Source {\n  /*\n  - contents\n  - file\n  */\n}\n\nclass BabelWorkspace {\n  static deserialize(json) {\n    return JSON.parse(json);\n    // return JSON.parse(json, ([key, value]) => {\n      \n    // });\n  }\n\n  static serialize(ws) {\n    return JSON.stringify(ws);\n  }\n}"]}