scrapbox-editor-begin-edit
code:mod.ts
window.scrapboxEditorBeginEdit = e => {
if (e.target.tagName == 'A') return;
e.preventDefault();
setTimeout(() => {
takeCursor().focus()
}, 250);
};
code:edit_begin.js
window.scrapboxEditorBeginEdit = e => {
if (e.target.tagName == 'A') return;
let input = document.querySelector('#text-input');
if (! input) return;
let key = Object.keys(input).find(k => k.startsWith('__reactFiber'));
if (! key) return;
e.preventDefault();
let stores = inputkey.return.return.stateNode._stores; let cursor = stores.find(x => x.constructor.name === 'Cursor');
cursor.focus();
};
code:edit_begin.jss
var c=r=>{let{fetch:s=globalThis.fetch,hostName:e="scrapbox.io",...t}=r;return{fetch:s,hostName:e,...t}};var Ee=r=>typeof r=="object"&&r!==null,ve=r=>Ee(r)?(r.name===void 0||typeof r.name=="string")&&typeof r.message=="string":!1,Y=r=>{try{let s=typeof r=="string"?JSON.parse(r):r;return ve(s)?s:!1}catch(s){if(s instanceof SyntaxError)return!1;throw s}};var C=class extends Error{constructor(s){super(${s.status} ${s.statusText} when fetching ${s.url});this.response=s;this.name="UnexpectedResponseError";Error.captureStackTrace&&Error.captureStackTrace(this,C)}},p=async r=>{let s=r.clone(),e=await s.text(),t=Y(e);if(!t)throw new C(s);return{ok:!1,value:t}};var d=r=>connect.sid=${r};var w=r=>...r.map((s,e)=>s===" "?"_":!Te.includes(s)||e===r.length-1&&Ie.includes(s)?encodeURIComponent(s):s).join(""),Te='@$&+=:;",',Ie=':;",';var X=(r,s,e)=>{let{sid:t,hostName:o,followRename:n,projects:a}=c(e??{}),i=new URLSearchParams;i.append("followRename",${n??!0});for(let f of a??[])i.append("projects",f);let l=https://${o}/api/pages/${r}/${w(s)}?${i.toString()};return new Request(l,t?{headers:{Cookie:d(t)}}:void 0)},V=async r=>{if(!r.ok)return r.status===414?{ok:!1,value:{name:"TooLongURIError",message:"project ids may be too much."}}:p(r);let s=await r.json();return{ok:!0,value:s}},H=async(r,s,e)=>{let{fetch:t}=c(e??{}),o=X(r,s,e),n=await t(o);return await V(n)};H.toRequest=X;H.fromResponse=V;var J=(r,s)=>{let{sid:e,hostName:t,sort:o,limit:n,skip:a}=c(s??{}),i=new URLSearchParams;o!==void 0&&i.append("sort",o),n!==void 0&&i.append("limit",${n}),a!==void 0&&i.append("skip",${a});let l=https://${t}/api/pages/${r}?${i.toString()};return new Request(l,e?{headers:{Cookie:d(e)}}:void 0)},Z=async r=>{if(!r.ok)return p(r);let s=await r.json();return{ok:!0,value:s}},ee=async(r,s)=>{let{fetch:e}=c(s??{}),t=await e(J(r,s));return await Z(t)};ee.toRequest=J;ee.fromResponse=Z;var te=(r,s,e,t)=>{let{sid:o,hostName:n}=c(t??{}),a=https://${n}/api/table/${r}/${w(s)}/${encodeURIComponent(e)}.csv;return new Request(a,o?{headers:{Cookie:d(o)}}:void 0)},re=async r=>r.ok?{ok:!0,value:await r.text()}:r.status===404?{ok:!1,value:{name:"NotFoundError",message:"Table not found."}}:p(r),oe=async(r,s,e,t)=>{let{fetch:o}=c(t??{}),n=te(r,s,e,t),a=await o(n);return await re(a)};oe.toRequest=te;oe.fromResponse=re;var ne=(r,s)=>{let{sid:e,hostName:t}=c(s??{});return new Request(https://${t}/api/projects/${r},e?{headers:{Cookie:d(e)}}:void 0)},se=async r=>{if(!r.ok)return p(r);let s=await r.json();return{ok:!0,value:s}},q=async(r,s)=>{let{fetch:e}=c(s??{}),t=ne(r,s),o=await e(t);return se(o)};q.toRequest=ne;q.fromResponse=se;var ie=(r,s)=>{let{sid:e,hostName:t}=c(s??{}),o=new URLSearchParams;for(let n of r)o.append("ids",n);return new Request(https://${t}/api/projects?${o.toString()},e?{headers:{Cookie:d(e)}}:void 0)},ae=async r=>{if(!r.ok)return p(r);let s=await r.json();return{ok:!0,value:s}},ce=async(r,s)=>{let{fetch:e}=c(s??{}),t=await e(ie(r,s));return ae(t)};ce.toRequest=ie;ce.fromResponse=ae;var Do=new Map;var de=(r,s,e,t)=>{let{sid:o,hostName:n}=c(t??{}),a=https://${n}/api/code/${r}/${w(s)}/${w(e)};return new Request(a,o?{headers:{Cookie:d(o)}}:void 0)},pe=async r=>r.ok?{ok:!0,value:await r.text()}:r.status===404&&r.headers.get("Content-Type")?.includes?.("text/plain")?{ok:!1,value:{name:"NotFoundError",message:"Code block is not found"}}:p(r),le=async(r,s,e,t)=>{let{fetch:o}=c(t??{}),n=de(r,s,e,t),a=await o(n);return await pe(a)};le.toRequest=de;le.fromResponse=pe;var ue=new TextEncoder().encode("0123456789abcdef");function me(r){let s=new Uint8Array(r.length*2);for(let e=0;e<s.length;e++){let t=re;se*2=uet>>4,se*2+1=uet&15}return s}var fe="md5: data is invalid type",E=64,G=class{#e;#t;#r;#o;#n;#i;#s;#a;constructor(){this.#e=1732584193,this.#t=4023233417,this.#r=2562383102,this.#o=271733878,this.#n=new Uint8Array(E),this.#i=0,this.#s=0,this.#a=0}#d(s){let e=this.#s;e+=s,e>4294967295&&(this.#a+=1),this.#s=e>>>0}#c(s){let e=this.#e,t=this.#t,o=this.#r,n=this.#o,a=k=>sk|sk+1<<8|sk+2<<16|sk+3<<24,i=(k,Q)=>k<<Q|k>>>32-Q,l=a(0),f=a(4),g=a(8),x=a(12),y=a(16),v=a(20),h=a(24),L=a(28),T=a(32),I=a(36),O=a(40),B=a(44),j=a(48),F=a(52),D=a(56),U=a(60);e=t+i(((o^n)&t^n)+e+l+3614090360,7),n=e+i(((t^o)&e^o)+n+f+3905402710,12),o=n+i(((e^t)&n^t)+o+g+606105819,17),t=o+i(((n^e)&o^e)+t+x+3250441966,22),e=t+i(((o^n)&t^n)+e+y+4118548399,7),n=e+i(((t^o)&e^o)+n+v+1200080426,12),o=n+i(((e^t)&n^t)+o+h+2821735955,17),t=o+i(((n^e)&o^e)+t+L+4249261313,22),e=t+i(((o^n)&t^n)+e+T+1770035416,7),n=e+i(((t^o)&e^o)+n+I+2336552879,12),o=n+i(((e^t)&n^t)+o+O+4294925233,17),t=o+i(((n^e)&o^e)+t+B+2304563134,22),e=t+i(((o^n)&t^n)+e+j+1804603682,7),n=e+i(((t^o)&e^o)+n+F+4254626195,12),o=n+i(((e^t)&n^t)+o+D+2792965006,17),t=o+i(((n^e)&o^e)+t+U+1236535329,22),e=t+i(((t^o)&n^o)+e+f+4129170786,5),n=e+i(((e^t)&o^t)+n+h+3225465664,9),o=n+i(((n^e)&t^e)+o+B+643717713,14),t=o+i(((o^n)&e^n)+t+l+3921069994,20),e=t+i(((t^o)&n^o)+e+v+3593408605,5),n=e+i(((e^t)&o^t)+n+O+38016083,9),o=n+i(((n^e)&t^e)+o+U+3634488961,14),t=o+i(((o^n)&e^n)+t+y+3889429448,20),e=t+i(((t^o)&n^o)+e+I+568446438,5),n=e+i(((e^t)&o^t)+n+D+3275163606,9),o=n+i(((n^e)&t^e)+o+x+4107603335,14),t=o+i(((o^n)&e^n)+t+T+1163531501,20),e=t+i(((t^o)&n^o)+e+F+2850285829,5),n=e+i(((e^t)&o^t)+n+g+4243563512,9),o=n+i(((n^e)&t^e)+o+L+1735328473,14),t=o+i(((o^n)&e^n)+t+j+2368359562,20),e=t+i((t^o^n)+e+v+4294588738,4),n=e+i((e^t^o)+n+T+2272392833,11),o=n+i((n^e^t)+o+B+1839030562,16),t=o+i((o^n^e)+t+D+4259657740,23),e=t+i((t^o^n)+e+f+2763975236,4),n=e+i((e^t^o)+n+y+1272893353,11),o=n+i((n^e^t)+o+L+4139469664,16),t=o+i((o^n^e)+t+O+3200236656,23),e=t+i((t^o^n)+e+F+681279174,4),n=e+i((e^t^o)+n+l+3936430074,11),o=n+i((n^e^t)+o+x+3572445317,16),t=o+i((o^n^e)+t+h+76029189,23),e=t+i((t^o^n)+e+I+3654602809,4),n=e+i((e^t^o)+n+j+3873151461,11),o=n+i((n^e^t)+o+U+530742520,16),t=o+i((o^n^e)+t+g+3299628645,23),e=t+i((o^(t|~n))+e+l+4096336452,6),n=e+i((t^(e|~o))+n+L+1126891415,10),o=n+i((e^(n|~t))+o+D+2878612391,15),t=o+i((n^(o|~e))+t+v+4237533241,21),e=t+i((o^(t|~n))+e+j+1700485571,6),n=e+i((t^(e|~o))+n+x+2399980690,10),o=n+i((e^(n|~t))+o+O+4293915773,15),t=o+i((n^(o|~e))+t+f+2240044497,21),e=t+i((o^(t|~n))+e+T+1873313359,6),n=e+i((t^(e|~o))+n+U+4264355552,10),o=n+i((e^(n|~t))+o+h+2734768916,15),t=o+i((n^(o|~e))+t+F+1309151649,21),e=t+i((o^(t|~n))+e+y+4149444226,6),n=e+i((t^(e|~o))+n+B+3174756917,10),o=n+i((e^(n|~t))+o+g+718787259,15),t=o+i((n^(o|~e))+t+I+3951481745,21),this.#e=this.#e+e>>>0,this.#t=this.#t+t>>>0,this.#r=this.#r+o>>>0,this.#o=this.#o+n>>>0}update(s){let e;if(typeof s=="string")e=new TextEncoder().encode(s);else if(typeof s=="object")if(s instanceof ArrayBuffer||ArrayBuffer.isView(s))e=new Uint8Array(s);else throw new TypeError(fe);else throw new TypeError(fe);let t=this.#i,o=E-t;if(e.length<o)this.#n.set(e,t),t+=e.length;else{this.#n.set(e.slice(0,o),t),this.#c(this.#n);let n=o;for(;n+E<=e.length;)this.#c(e.slice(n,n+E)),n+=E;this.#n.fill(0).set(e.slice(n),0),t=e.length-n}return this.#i=t,this.#d(e.length),this}digest(){let s=E-this.#i;s<9&&(s+=E);let e=new Uint8Array(s);e0=128;let t=this.#s<<3,o=this.#a<<3|this.#s>>>29;ee.length-8=t&255,ee.length-7=t>>>8&255,ee.length-6=t>>>16&255,ee.length-5=t>>>24&255,ee.length-4=o&255,ee.length-3=o>>>8&255,ee.length-2=o>>>16&255,ee.length-1=o>>>24&255,this.update(e.buffer);let n=new ArrayBuffer(16),a=new DataView(n);return a.setUint32(0,this.#e,!0),a.setUint32(4,this.#t,!0),a.setUint32(8,this.#r,!0),a.setUint32(12,this.#o,!0),n}toString(s="hex"){let e=this.digest();switch(s){case"hex":return new TextDecoder().decode(me(new Uint8Array(e)));case"base64":{let t=new Uint8Array(e),o="";for(let n=0;n<t.length;++n)o+=String.fromCharCode(tn);return btoa(o)}default:throw new Error("md5: invalid format")}}};var ge=!1;scrapbox.addListener("lines:changed",()=>ge=!1);scrapbox.addListener("layout:changed",()=>ge=!1);var he=(r,s)=>{if(!(r instanceof HTMLTextAreaElement))throw new TypeError("${s}" must be HTMLTextAreaElement but actual is "${r}")};var M=()=>{let r=document.getElementById("text-input");if(!!r)return he(r,"textarea#text-input"),r};var K=()=>{let r=M();if(!r)throw Error("#text-input is not found.");let s=Object.keys(r).find(n=>n.startsWith("__reactFiber"));if(!s)throw Error('#text-input must has the property whose name starts with "__reactFiber"');let e=rs.return.return.stateNode._stores,t=e.find(n=>n.constructor.name==="Cursor");if(!t)throw Error('#text-input must has a "Cursor" store.');let o=e.find(n=>n.constructor.name==="Selection");if(!o)throw Error('#text-input must has a "Selection" store.');return{cursor:t,selection:o}};var ye=()=>K().cursor;var u=(r,{parseOnNested:s,parseOnQuoted:e,patterns:t})=>(o,n,a)=>{var i,l,f,g,x,y;if(!s&&n.nested)return(i=a?.())!==null&&i!==void 0?i:[];if(!e&&n.quoted)return(l=a?.())!==null&&l!==void 0?l:[];for(let v of t){let h=v.exec(o);if(h===null)continue;let L=o.substring(0,h.index),T=o.substring(h.index+((g=(f=h0)===null||f===void 0?void 0:f.length)!==null&&g!==void 0?g:0)),I=r((x=h0)!==null&&x!==void 0?x:"",n);return...N(L,n),...I,...N(T,n)}return(y=a?.())!==null&&y!==void 0?y:[]},m=r=>{type:"plain",raw:r,text:r},Ue=u(m,{parseOnNested:!0,parseOnQuoted:!0,patterns:/^()(.*)()$/}),$e=/^>.*$/,Ae=(r,s)=>s.context==="table"?m(r,s):{type:"quote",raw:r,nodes:N(r.substring(1),{...s,quoted:!0})},He=u(Ae,{parseOnNested:!1,parseOnQuoted:!1,patterns:$e}),qe=/^\? .+$/,_e=(r,s)=>s.context==="table"?m(r,s):{type:"helpfeel",raw:r,text:r.substring(2)},Ge=u(_e,{parseOnNested:!1,parseOnQuoted:!1,patterns:qe}),Ke=/\[\[https?:\/\/^\s\]+\.(?:png|jpe?g|gif|svg)\]\]/i,ze=/\[\[https?:\/\/(?:0-9a-z-+\.)?gyazo\.com\/0-9a-f{32}\]\]/,We=(r,s)=>{if(s.context==="table")return m(r,s);let e=r.substring(2,r.length-2),t=/^https?:\/\/(0-9a-z-\.)?gyazo\.com\/0-9a-f{32}$/.test(e);return[{type:"strongImage",raw:r,src:t?${e}/thumb/1000:e}]},Qe=u(We,{parseOnNested:!1,parseOnQuoted:!0,patterns:Ke,ze}),Ye=/\^[\*\.icon(?:\*1-9\d*)?\]/;function we(r){return(s,e)=>{if(r==="strongIcon"&&e.context==="table")return m(s,e);let t=r==="icon"?s.substring(1,s.length-1):s.substring(2,s.length-2),o=t.lastIndexOf(".icon"),n=t.substring(0,o),a=n.startsWith("/")?"root":"relative",i=t.substring(o+5,t.length),l=i.startsWith("*")?parseInt(i.substring(1),10):1;return new Array(l).fill({}).map(()=>({path:n,pathType:a,type:r,raw:s}))}}var Xe=we("icon"),Ve=u(Xe,{parseOnNested:!0,parseOnQuoted:!0,patterns:Ye}),Je=/\[\^[\*\.icon(?:\*\d+)?\]\]/,Ze=we("strongIcon"),et=u(Ze,{parseOnNested:!1,parseOnQuoted:!0,patterns:Je}),tt=/\[\[(?:[^[]|\^[]).*?\]*\]\]/,rt=(r,s)=>s.context==="table"?m(r,s):{type:"strong",raw:r,nodes:N(r.substring(2,r.length-2),{...s,nested:!0})},ot=u(rt,{parseOnNested:!1,parseOnQuoted:!0,patterns:tt}),nt=/\\$ .+? \/,st=/\[\$ [^\+\]/,it=(r,s)=>s.context==="table"?m(r,s):{type:"formula",raw:r,formula:r.substring(3,r.length-(r.endsWith(" ")?2:1))}],at=u(it,{parseOnNested:!1,parseOnQuoted:!0,patterns:nt,st}),ct=/\!"#%&'()*+,\-./{|}<>_~]+ (?:\[[^[\+\]|^\])+\]/,dt=(r,s)=>{if(s.context==="table")return m(r,s);let e=r.indexOf(" "),t=r.substring(1,e),o=r.substring(e+1,r.length-1),n=new Set(t);if(n.has("*")){let a=t.split("*").length-1;n.delete("*"),n.add(*-${Math.min(a,10)})}return{type:"decoration",raw:r,rawDecos:t,decos:Array.from(n),nodes:N(o,{...s,nested:!0})}},pt=u(dt,{parseOnNested:!1,parseOnQuoted:!0,patterns:ct}),lt=/.*?/,ut=(r,s)=>s.context==="table"?m(r,s):{type:"code",raw:r,text:r.substring(1,r.length-1)},mt=u(ut,{parseOnNested:!1,parseOnQuoted:!0,patterns:lt}),ft=/^$% .+$/,gt=(r,s)=>{var e;if(s.context==="table")return m(r,s);let t=(e=r0)!==null&&e!==void 0?e:"",o=r.substring(2);return{type:"commandLine",raw:r,symbol:t,text:o}},ht=u(gt,{parseOnNested:!1,parseOnQuoted:!1,patterns:ft}),xt=/\\s+\/,yt=(r,s)=>s.context==="table"?m(r,s):{type:"blank",raw:r,text:r.substring(1,r.length-1)},wt=u(yt,{parseOnNested:!1,parseOnQuoted:!0,patterns:xt}),kt=/\[https?:\/\/^\s\]+\.(?:png|jpe?g|gif|svg)(?:\?^\\s]+)?(?:\s+https?:\/\/^\s\]+)?\]/i,bt=/\[https?:\/\/^\s\]+\s+https?:\/\/^\s\]+\.(?:png|jpe?g|gif|svg)(?:\?^\\s]+)?\]/i,Et=/\[https?:\/\/(?:0-9a-z-+\.)?gyazo\.com\/0-9a-f{32}(?:\/raw)?(?:\s+https?:\/\/^\s\]+)?\]/,vt=/\[https?:\/\/^\s\]+\s+https?:\/\/(?:0-9a-z-+\.)?gyazo\.com\/0-9a-f{32}(?:\/raw)?\]/,Lt=r=>/^https?:\/\/^\s\]+\.(png|jpe?g|gif|svg)(\?^\\s]+)?$/i.test(r)||Tt(r),Tt=r=>/^https?:\/\/(0-9a-z-\.)?gyazo\.com\/0-9a-f{32}(\/raw)?$/.test(r),It=(r,s)=>{if(s.context==="table")return m(r,s);let e=r.search(/\s/),t=e!==-1?r.substring(1,e):r.substring(1,r.length-1),o=e!==-1?r.substring(e,r.length-1).trimLeft():"",n,a=Lt(o)?o,t:t,o;return[{type:"image",raw:r,src:/^https?:\/\/(0-9a-z-\.)?gyazo\.com\/0-9a-f{32}$/.test(n)?${n}/thumb/1000:n,link:a}]},Ct=u(It,{parseOnNested:!0,parseOnQuoted:!0,patterns:kt,bt,Et,vt}),Rt=/\[https?:\/\/^\s\]+\s+^\]*^\s\]/,Nt=/\^[\*^\s\s+https?:\/\/^\s\]+\]/,Pt=/\[https?:\/\/^\s\]+\]/,St=/https?:\/\/^\s+/,Mt=(r,s)=>{if(s.context==="table")return m(r,s);let e=r.startsWith("")&&r.endsWith("")?r.substring(1,r.length-1):r,t=/^https?:\/\/^\s\]/.test(e),o=(t?/^https?:\/\/^\s\]+/:/https?:\/\/^\s\]+$/).exec(e);if(o?.0===void 0)return[];let n=t?e.substring(o0.length):e.substring(0,o.index-1);return[{type:"link",raw:r,pathType:"absolute",href:o0,content:n.trim()}]},Ot=u(Mt,{parseOnNested:!0,parseOnQuoted:!0,patterns:Rt,Nt,Pt,St}),ke=/\[(^\]*^\s)\s+(NS\d+(?:\.\d+)?,EW\d+(?:\.\d+)?(?:,Z\d+)?)\]/,be=/\[(NS\d+(?:\.\d+)?,EW\d+(?:\.\d+)?(?:,Z\d+)?)(?:\s+(^\]*^\s))?\]/,Bt=r=>{lets="",e="",t=""=r.split(","),o=parseFloat(s.replace(/^N/,"").replace(/^S/,"-")),n=parseFloat(e.replace(/^E/,"").replace(/^W/,"-")),a=/^Z\d+$/.test(t)?parseInt(t.replace(/^Z/,""),10):14;return{latitude:o,longitude:n,zoom:a}},jt=(r,s)=>{var e;if(s.context==="table")return m(r,s);let t=(e=r.match(ke))!==null&&e!==void 0?e:r.match(be);if(t===null)return[];let o=r.startsWith("[N")||r.startsWith("[S"),,n="",a=""=o?t:[t0,t2,t1],{latitude:i,longitude:l,zoom:f}=Bt(n),g=a!==""?https://www.google.com/maps/place/${encodeURIComponent(a)}/@${i},${l},${f}z:https://www.google.com/maps/@${i},${l},${f}z;return{type:"googleMap",raw:r,latitude:i,longitude:l,zoom:f,place:a,url:g}},Ft=u(jt,{parseOnNested:!1,parseOnQuoted:!0,patterns:ke,be}),Dt=/\[\/?[^\]+\]/,Ut=r=>{let s=r.substring(1,r.length-1);return{type:"link",raw:r,pathType:s.startsWith("/")?"root":"relative",href:s,content:""}},$t=u(Ut,{parseOnNested:!0,parseOnQuoted:!0,patterns:Dt}),At=/(?:^|\s)#\S+/,Ht=(r,s)=>{if(s.context==="table")return m(r,s);if(r.startsWith("#"))return{type:"hashTag",raw:r,href:r.substring(1)};let e=r.substring(0,1),t=r.substring(1);return...m(e,s),{type:"hashTag",raw:t,href:t.substring(1)}},qt=u(Ht,{parseOnNested:!0,parseOnQuoted:!0,patterns:At}),_t=/^0-9+\. .*$/,Gt=(r,s)=>{if(s.context==="table")return m(r,s);let e=r.indexOf(" "),t=r.substring(0,e-1),o=parseInt(t,10),n=r.substring(e+1,r.length);return{type:"numberList",raw:r,rawNumber:t,number:o,nodes:N(n,{...s,nested:!0})}},Kt=u(Gt,{parseOnNested:!1,parseOnQuoted:!1,patterns:_t}),zt=(r,s,e)=>{var t;return r===""?[]:(t=e?.())!==null&&t!==void 0?t:[]},Wt=(...r)=>(s,e)=>r.reduceRight((t,o)=>()=>o(s,e,t),()=>Ue(s,e))(),N=Wt(zt,He,Ge,mt,ht,at,wt,pt,Qe,et,ot,Ct,Ot,Ve,Ft,$t,qt,Kt);window.scrapboxEditorBeginEdit=r=>{r.target.tagName!="A"&&(r.preventDefault(),setTimeout(()=>{ye().focus()},250))};