{"version":3,"sources":["https://lively-kernel.org/lively4/lively4-tom/src/components/tools/lively-ast-explorer.js"],"names":["Morph","babelDefault","SyntaxChecker","sourcemap","generateUUID","uuid","debounce","flatmap","executeAllTestRunners","promisedEvent","babel","ASTExplorer","defaultSourceURL","container","get","sourceEditor","sourceLCM","livelyCodeMirror","sourceCM","currentEditor","source","getValue","astInspector","sourcePath","sourceURL","value","urlString","onSourcePathEntered","loadSourceFile","updateButton","autoUpdate","_autoUpdate","bool","classList","toggle","querySelector","onUpdate","evt","button","update","console","log","setURL","lively","paths","normalizePath","loadFile","initialize","windowTitle","registerButtons","getAllSubmorphs","forEach","addEventListener","e","preventDefault","stopPropagation","currentTarget","dispatchEvent","MouseEvent","debouncedUpdate","awaitEditor","hideToolbar","connectEditor","doSave","save","checkForSyntaxErrors","code","getAttribute","CustomEvent","inspect","toAST","Error","message","saveFile","livelyPrepareSave","setAttribute","livelyMigrate","other","livelyExample"],"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,WAAN,SAA0BX,KAA1B,CAAgC;;AAE7C,mBAAWY,gBAAX,GAA8B;AAAE,iBAAO,6DAAP;AAAuE;;AAEvG;;AAEA,YAAIC,SAAJ,GAAgB;AAAE,iBAAO,KAAKC,GAAL,CAAS,UAAT,CAAP;AAA8B;;AAEhD,YAAIC,YAAJ,GAAmB;AAAE,iBAAO,KAAKD,GAAL,CAAS,SAAT,CAAP;AAA6B;AAClD,YAAIE,SAAJ,GA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;AAEA,eAAKpC,UAAL,CAAgB6B,gBAAhB,CAAiC,OAAjC,EAA0Cf,OAAO;AAC/C,gBAAIA,IAAI6B,IAAJ,IAAY,OAAhB,EAAyB,KAAKvC,mBAAL,CAAyB,KAAKJ,UAAL,CAAgBE,KAAzC;AAC1B,WAFD;;AAIA,gBAAML,SAAS,KAAK+C,YAAL,CAAkB,QAAlB,CAAf;AACA,cAAI/C,MAAJ,EAAY,KAAKQ,cAAL,CAAoBR,MAApB;AACZ,eAAKU,UAAL,GAAkB,IAAlB;;AAEA,eAAK2B,aAAL,CAAmB,IAAIW,WAAJ,CAAgB,YAAhB,CAAnB;AACD;;AAED;;AAEA,cAAM7B,MAAN,GAAe;AACb,cAAI;AACF,iBAAKjB,YAAL,CAAkB+C,OAAlB,CAA0B,KAAKjD,MAAL,CAAYkD,KAAZ,EAA1B;AACD,WAFD,CAEE,OAAOjB,CAAP,EAAU;AACV,iBAAK/B,YAAL,CAAkB+C,OAAlB,CAA0B,EAACE,OAAOlB,EAAEmB,OAAV,EAA1B;AACD;AACF;;AAED,cAAMR,IAAN,GAAa;AACX,cAAI,KAAKxC,SAAT,EAAoB;AAClB,kBAAM,KAAKT,YAAL,CAAkB0D,QAAlB,EAAN;AACD;AACD,eAAKlC,MAAL;AACD;;AAED;;AAEAmC,4BAAoB;AAClB,eAAKC,YAAL,CAAkB,QAAlB,EAA4B,KAAKnD,SAAjC;AACAgB,kBAAQC,GAAR,CAAY,6BAAZ;AACD;;AAEDmC,sBAAcC,KAAd,EAAqB;AACnB;AACA,eAAKzB,gBAAL,CAAsB,YAAtB,EAAoC,MAAM;AACxC,iBAAKxB,cAAL,CAAoBiD,MAAMrD,SAA1B;AACD,WAFD;AAGD;;AAEDsD,wBAAgB;AACd,eAAKlD,cAAL,CAAoBjB,YAAYC,gBAAhC;AACD;AA9G4C;;yBAA1BD,W","file":"lively-ast-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 ASTExplorer extends Morph {\n\n  static get defaultSourceURL() { return \"/src/components/tools/lively-ast-explorer-example-source.js\"; }\n\n  /*MD ## UI Accessing MD*/\n\n  get container() { return this.get(\"#content\"); }\n\n  get sourceEditor() { return this.get(\"#source\"); }\n  get sourceLCM() { return this.sourceEditor.livelyCodeMirror(); }\n  get sourceCM() { return this.sourceEditor.currentEditor(); }\n  get source() { return this.sourceCM.getValue(); }\n\n  get astInspector() { return this.get(\"#ast\"); }\n  \n  get sourcePath() { return this.get(\"#sourcePath\"); }\n  get sourceURL() { return this.sourcePath.value; }\n  set sourceURL(urlString) { this.sourcePath.value = urlString; }\n  onSourcePathEntered(urlString) { this.loadSourceFile(urlString); }\n  \n  get updateButton() { return this.get(\"#update\"); }\n  get autoUpdate() { return this._autoUpdate; }\n  set autoUpdate(bool) {\n    this.updateButton.classList.toggle(\"on\", bool);\n    this.updateButton.querySelector(\"i\").classList.toggle(\"fa-spin\", bool);\n    this._autoUpdate = bool;\n  }\n  onUpdate(evt) {\n    if (evt.button === 2) this.autoUpdate = !this.autoUpdate;\n    this.update();\n  }\n\n  /*MD ## Initialization MD*/\n\n  async loadSourceFile(urlString) {\n    console.log(\"LOAD \", urlString);\n    this.sourceURL = urlString;\n    this.sourceEditor.setURL(lively.paths.normalizePath(urlString, \"\"));\n    await this.sourceEditor.loadFile();\n    this.update();\n  }\n\n  async initialize() {\n    this.windowTitle = \"AST Explorer\";\n    this.registerButtons();\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.debouncedUpdate = this.update::debounce(500);\n    \n    await this.sourceEditor.awaitEditor();\n    \n    this.sourceEditor.hideToolbar();\n    this.astInspector.connectEditor(this.sourceEditor);\n    this.sourceLCM.doSave = async () => {\n      this.save();\n    };\n    this.sourceLCM.addEventListener(\"change\", (evt => SyntaxChecker.checkForSyntaxErrors(this.sourceCM))::debounce(200));\n    this.sourceLCM.addEventListener(\"change\", evt => {if (this.autoUpdate) this.debouncedUpdate()});\n    \n    this.sourcePath.addEventListener(\"keyup\", evt => {\n      if (evt.code == \"Enter\") this.onSourcePathEntered(this.sourcePath.value);\n    });\n\n    const source = this.getAttribute(\"source\");\n    if (source) this.loadSourceFile(source);\n    this.autoUpdate = true;\n    \n    this.dispatchEvent(new CustomEvent(\"initialize\"));\n  }\n\n  /*MD ## Execution MD*/\n\n  async update() {\n    try {\n      this.astInspector.inspect(this.source.toAST());\n    } catch (e) {\n      this.astInspector.inspect({Error: e.message});\n    }\n  }\n\n  async save() {\n    if (this.sourceURL) {\n      await this.sourceEditor.saveFile();\n    }\n    this.update();\n  }\n\n  /*MD ## Lively Integration MD*/\n\n  livelyPrepareSave() {\n    this.setAttribute('source', this.sourceURL);\n    console.log(\"PREPARE SAVE (AST Explorer)\");\n  }\n  \n  livelyMigrate(other) {\n    // #TODO: do we still need this?\n    this.addEventListener(\"initialize\", () => {\n      this.loadSourceFile(other.sourceURL);\n    });\n  }\n\n  livelyExample() {\n    this.loadSourceFile(ASTExplorer.defaultSourceURL);\n  }\n}"]}