forked from Willyfrog/silverbullet-plug-template
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathhello.plug.js
1 lines (1 loc) · 4.8 KB
/
hello.plug.js
1
var x=Object.defineProperty;var P=(e,r)=>{for(var o in r)x(e,o,{get:r[o],enumerable:!0})};var p=typeof window>"u"&&typeof globalThis.WebSocketPair>"u";typeof Deno>"u"&&(self.Deno={args:[],build:{arch:"x86_64"},env:{get(){}}});var l=new Map,u=0;function a(e){self.postMessage(e)}p&&(globalThis.syscall=async(e,...r)=>await new Promise((o,n)=>{u++,l.set(u,{resolve:o,reject:n}),a({type:"sys",id:u,name:e,args:r})}));function d(e,r){p&&(self.addEventListener("message",o=>{(async()=>{let n=o.data;switch(n.type){case"inv":{let i=e[n.name];if(!i)throw new Error(`Function not loaded: ${n.name}`);try{let s=await Promise.resolve(i(...n.args||[]));a({type:"invr",id:n.id,result:s})}catch(s){console.error("An exception was thrown as a result of invoking function",n.name,"error:",s.message),a({type:"invr",id:n.id,error:s.message})}}break;case"sysr":{let i=n.id,s=l.get(i);if(!s)throw Error("Invalid request id");l.delete(i),n.error?s.reject(new Error(n.error)):s.resolve(n.result)}break}})().catch(console.error)}),a({type:"manifest",manifest:r}))}function h(e){let r=atob(e),o=r.length,n=new Uint8Array(o);for(let i=0;i<o;i++)n[i]=r.charCodeAt(i);return n}function m(e){typeof e=="string"&&(e=new TextEncoder().encode(e));let r="",o=e.byteLength;for(let n=0;n<o;n++)r+=String.fromCharCode(e[n]);return btoa(r)}async function b(e,r){if(typeof e!="string"){let o=new Uint8Array(await e.arrayBuffer()),n=o.length>0?m(o):void 0;r={method:e.method,headers:Object.fromEntries(e.headers.entries()),base64Body:n},e=e.url}return syscall("sandboxFetch.fetch",e,r)}globalThis.nativeFetch=globalThis.fetch;function v(){globalThis.fetch=async function(e,r){let o=r&&r.body?m(new Uint8Array(await new Response(r.body).arrayBuffer())):void 0,n=await b(e,r&&{method:r.method,headers:r.headers,base64Body:o});return new Response(n.base64Body?h(n.base64Body):null,{status:n.status,headers:n.headers})}}p&&v();var c={};P(c,{confirm:()=>J,copyToClipboard:()=>ce,dispatch:()=>_,downloadFile:()=>q,filterBox:()=>V,flashNotification:()=>Q,fold:()=>ee,foldAll:()=>ne,getCurrentPage:()=>A,getCursor:()=>C,getSelection:()=>F,getText:()=>S,getUiOption:()=>X,goHistory:()=>L,hidePanel:()=>N,insertAtCursor:()=>Y,insertAtPos:()=>H,moveCursor:()=>$,navigate:()=>T,openCommandPalette:()=>k,openPageNavigator:()=>E,openSearchPanel:()=>ae,openUrl:()=>B,prompt:()=>j,redo:()=>se,reloadPage:()=>R,reloadSettingsAndCommands:()=>W,reloadUI:()=>D,replaceRange:()=>I,save:()=>K,setPage:()=>w,setSelection:()=>M,setText:()=>U,setUiOption:()=>Z,showPanel:()=>G,toggleFold:()=>re,undo:()=>ie,unfold:()=>te,unfoldAll:()=>oe,uploadFile:()=>O,vimEx:()=>z});typeof self>"u"&&(self={syscall:()=>{throw new Error("Not implemented here")}});var t=globalThis.syscall;function A(){return t("editor.getCurrentPage")}function w(e){return t("editor.setPage",e)}function S(){return t("editor.getText")}function U(e){return t("editor.setText",e)}function C(){return t("editor.getCursor")}function F(){return t("editor.getSelection")}function M(e,r){return t("editor.setSelection",e,r)}function K(){return t("editor.save")}function T(e,r=!1,o=!1){return t("editor.navigate",e,r,o)}function E(e="page"){return t("editor.openPageNavigator",e)}function k(){return t("editor.openCommandPalette")}function R(){return t("editor.reloadPage")}function D(){return t("editor.reloadUI")}function W(){return t("editor.reloadSettingsAndCommands")}function B(e,r=!1){return t("editor.openUrl",e,r)}function L(e){return t("editor.goHistory",e)}function q(e,r){return t("editor.downloadFile",e,r)}function O(e,r){return t("editor.uploadFile",e,r)}function Q(e,r="info"){return t("editor.flashNotification",e,r)}function V(e,r,o="",n=""){return t("editor.filterBox",e,r,o,n)}function G(e,r,o,n=""){return t("editor.showPanel",e,r,o,n)}function N(e){return t("editor.hidePanel",e)}function H(e,r){return t("editor.insertAtPos",e,r)}function I(e,r,o){return t("editor.replaceRange",e,r,o)}function $(e,r=!1){return t("editor.moveCursor",e,r)}function Y(e){return t("editor.insertAtCursor",e)}function _(e){return t("editor.dispatch",e)}function j(e,r=""){return t("editor.prompt",e,r)}function J(e){return t("editor.confirm",e)}function X(e){return t("editor.getUiOption",e)}function Z(e,r){return t("editor.setUiOption",e,r)}function z(e){return t("editor.vimEx",e)}function ee(){return t("editor.fold")}function te(){return t("editor.unfold")}function re(){return t("editor.toggleFold")}function ne(){return t("editor.foldAll")}function oe(){return t("editor.unfoldAll")}function ie(){return t("editor.undo")}function se(){return t("editor.redo")}function ae(){return t("editor.openSearchPanel")}function ce(e){return t("editor.copyToClipboard",e)}async function f(){await c.flashNotification("Hello world!")}var g={helloWorld:f},y={name:"hello",functions:{helloWorld:{path:"hello.ts:helloWorld",command:{name:"Say hello"}}},assets:{}},Ze={manifest:y,functionMapping:g};d(g,y);export{Ze as plug};