Files
standardnotes-app-web/public/components/org.standardnotes.code-editor/dist/main.js
Mo 66d8efd090 feat: native components (#789)
* wip: component viewer

* feat: get component status from component viewer

* feat: native components

* fix: remove unused property

* fix: remove unused func

* chore(deps): snjs 2.29.0

* fix: import location

* feat: native components

* fix: remove unused func

* feat: component viewer (#781)

* wip: component viewer

* feat: get component status from component viewer

* fix: remove unused property

* chore(deps): snjs 2.29.0

* fix: import location

* chore: use cp instead of webpack copy

* fix: types

* chore: misc
2021-12-30 14:25:40 -06:00

2 lines
2.9 KiB
JavaScript

document.addEventListener("DOMContentLoaded",(function(){const e=CodeMirror.modeInfo.reduce((function(e,t){return e[t.mode]?e[t.mode].push(t):e[t.mode]=[t],e}),{}),t=CodeMirror.modeInfo.reduce((function(e,t){return e[t.name]={mode:t.mode,mime:t.mime},e}),{}),n=Object.keys(t);let o,a,i,d,m,r,c,s=!1,u=!0;function l(){if(a){let e=a;o.saveItemWithPresave(e,(()=>{d=r.getValue(),e.content.text=d,e.clientData=i,e.content.preview_plain=null,e.content.preview_html=null}))}}function f(o){if(!o)return;const a=function(n){const o=function(e){return e?{name:e.name,mode:e.mode,mime:e.mime}:null},a=/.+\.([^.]+)$/.exec(n),i=/\//.test(n);if(a)return o(CodeMirror.findModeByExtension(a[1]));if(i)return o(CodeMirror.findModeByMIME(i[1]));if(t[n])return{name:n,mode:t[n].mode,mime:t[n].mime};if(e[n]){const t=e[n][0];return{name:t.name,mode:t.mode,mime:t.mime}}return{name:n,mode:n,mime:n}}(o);a?(r.setOption("mode",a.mime),CodeMirror.autoLoadMode(r,a.mode),i&&(i.mode=a.name),document.getElementById("language-select").selectedIndex=n.indexOf(a.name)):console.error("Could not find a mode corresponding to "+o)}function g(e){const t=document.getElementById("toggle-vim-mode-button"),n="vim"===e?"Disable":"Enable",o="vim"===e?"danger":"success";t.innerHTML=`${n} Vim mode`,t.classList.remove("danger"),t.classList.remove("success"),t.classList.add(o)}window.setKeyMap=function(e){r.setOption("keyMap",e)},window.onLanguageSelect=function(){f(n[c.selectedIndex]),l()},window.setDefaultLanguage=function(){const e=n[c.selectedIndex];o.setComponentDataValueForKey("language",e);const t=document.getElementById("default-label"),a=t.innerHTML;t.innerHTML="Success",t.classList.add("success"),setTimeout((function(){t.classList.remove("success"),t.innerHTML=a}),750)},window.toggleVimMode=function(){let e;e="default"===(o.getComponentDataValueForKey("keyMap")??"default")?"vim":"default",window.setKeyMap(e),o.setComponentDataValueForKey("keyMap",e),g(e)},CodeMirror.commands.save=function(){l()},r=CodeMirror.fromTextArea(document.getElementById("code"),{extraKeys:{"Alt-F":"findPersistent"},lineNumbers:!0,styleSelectedText:!0,lineWrapping:!0}),r.setSize("100%","100%"),setTimeout((function(){f("JavaScript")}),1),function(){c=document.getElementById("language-select");for(let e=0;e<n.length;e++){const t=document.createElement("option");t.value=e,t.innerHTML=n[e],c.appendChild(t)}}(),r.on("change",(function(){s||l()})),o=new ComponentRelay({targetWindow:window,onReady:()=>{const e=o.platform;e&&document.body.classList.add(e);const t=o.getComponentDataValueForKey("keyMap")??"default";window.setKeyMap(t),g(t)}}),o.streamContextItem((e=>{!function(e){if(e.uuid!==m&&(d=null,u=!0,m=e.uuid),a=e,e.isMetadataUpdate)return;i=e.clientData;f(i.mode||o.getComponentDataValueForKey("language")),r&&(e.content.text!==d&&(s=!0,r.getDoc().setValue(a.content.text),s=!1),u&&(u=!1,r.getDoc().clearHistory()))}(e)}))}));
//# sourceMappingURL=main.js.map