markon-core 0.15.14

markon core - Mark it on.
1
"use strict";(()=>{var d=window.__MARKON_I18N__?.t||(e=>e),k=document.getElementById("dir-heading");k?.dataset.i18nKey&&(k.textContent=d(k.dataset.i18nKey));var ue={"dir-current-label":"web.dir.current","dir-footer":"web.footer","dir-feedback-link":"web.footer.feedback","dir-kbd-link":"web.kbd.link"};for(let[e,t]of Object.entries(ue)){let n=document.getElementById(e);n&&(n.textContent=d(t))}document.querySelectorAll("[data-i18n]").forEach(e=>{e.textContent=d(e.getAttribute("data-i18n")||"")});document.querySelectorAll("[data-i18n-placeholder]").forEach(e=>{e.setAttribute("placeholder",d(e.getAttribute("data-i18n-placeholder")||""))});document.querySelectorAll("[data-i18n-aria]").forEach(e=>{e.setAttribute("aria-label",d(e.getAttribute("data-i18n-aria")||""))});document.querySelectorAll("[data-workspace-spotlight-trigger]").forEach(e=>{e.setAttribute("aria-label",d("web.wsnav.open")),e.setAttribute("title",d("web.wsnav.open"))});function D(e){let t=e==="all"?"all":"markdown";document.querySelectorAll(".dir-list[data-file-filter]").forEach(n=>{n.setAttribute("data-file-filter",t)}),document.querySelectorAll("[data-file-filter-switch] [data-file-filter-value]").forEach(n=>{let a=n.getAttribute("data-file-filter-value")===t;n.classList.toggle("is-active",a),n.setAttribute("aria-pressed",a?"true":"false")})}document.querySelectorAll("[data-file-filter-switch]").forEach(e=>{e.addEventListener("click",t=>{let n=t.target,a=n&&n.closest?n.closest("[data-file-filter-value]"):null;a&&(t.preventDefault(),D(a.getAttribute("data-file-filter-value")))})});D("markdown");function me(e){let t={};return e.forEach(n=>{t[n.getAttribute("data-feature-key")||""]=n.checked}),t}function C(e,t){let n=e.getAttribute("data-can-edit")==="true";e.querySelectorAll("input[data-feature-key]").forEach(a=>{a.disabled=t||!n;let r=a.closest(".workspace-feature-switch");r&&r.classList.toggle("is-pending",t)})}function _(e){let t=e.closest(".workspace-feature-switch");t&&t.classList.toggle("is-on",e.checked)}function fe(){let e=document.querySelector("[data-workspace-feature-form]");if(!e)return;let t=Array.from(e.querySelectorAll("input[data-feature-key]"));t.forEach(_),e.getAttribute("data-can-edit")==="true"&&t.forEach(n=>{n.addEventListener("change",()=>{let a=!n.checked;_(n),C(e,!0),fetch(e.getAttribute("data-update-url")||"",{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json"},body:JSON.stringify(me(t))}).then(r=>r.text().then(o=>{let i={};try{i=o?JSON.parse(o):{}}catch{}if(!r.ok||i.success===!1)throw new Error(i.message||o||r.statusText);C(e,!1)})).catch(r=>{n.checked=a,_(n),C(e,!1),window.alert(`${d("web.ws.feature.update_failed")}: ${A(r)}`)})})})}fe();function A(e){return e instanceof Error?e.message:String(e)}function X(e){if(navigator.clipboard&&navigator.clipboard.writeText)return navigator.clipboard.writeText(e).then(()=>!0,()=>!1);let t=document.createElement("textarea");t.value=e,t.setAttribute("readonly","readonly"),t.style.position="fixed",t.style.left="-9999px",document.body.appendChild(t),t.select();let n=!1;try{n=document.execCommand("copy")}catch{n=!1}return t.remove(),Promise.resolve(n)}document.querySelectorAll("[data-copy-text]").forEach(e=>{e.addEventListener("click",()=>{let t=e.getAttribute("data-copy-text")||"",n=d(e.getAttribute("data-i18n")||"web.ws.meta.copy_id");X(t).then(a=>{e.textContent=d(a?"web.ws.meta.copied":"web.ws.meta.copy_failed"),window.setTimeout(()=>{e.textContent=n},1200)})})});document.querySelectorAll("[data-copy-current-url]").forEach(e=>{e.addEventListener("click",()=>{let t=e.textContent;X(window.location.href).then(n=>{e.textContent=d(n?"web.ws.meta.copied":"web.ws.meta.copy_failed"),window.setTimeout(()=>{e.textContent=t},1200)})})});document.querySelectorAll("[data-set-alias]").forEach(e=>{e.addEventListener("click",()=>{let t=e.getAttribute("data-alias-url")||"";if(!t)return;let n=e.getAttribute("data-current-alias")||"",a=window.prompt(d("web.ws.set_alias_prompt"),n);a!==null&&fetch(t,{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json"},body:JSON.stringify({alias:a.trim()})}).then(r=>{r.ok?window.location.reload():window.alert(d("web.ws.set_alias_failed"))}).catch(()=>window.alert(d("web.ws.set_alias_failed")))})});document.querySelectorAll("[data-workspace-dropdown] > button").forEach(e=>{e.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation();let n=e.closest("[data-workspace-dropdown]");if(!n)return;let a=n.classList.contains("is-open");if(document.querySelectorAll("[data-workspace-dropdown].is-open").forEach(r=>{r!==n&&r.classList.remove("is-open")}),n.classList.toggle("is-open",!a),!a){let r=n.querySelector("[data-branch-filter]");r&&window.setTimeout(()=>r.focus(),0)}})});document.addEventListener("click",()=>{document.querySelectorAll("[data-workspace-dropdown].is-open").forEach(e=>{e.classList.remove("is-open")})});document.querySelectorAll("[data-checkout-branch]").forEach(e=>{e.addEventListener("click",t=>{t.preventDefault();let n=e.getAttribute("data-checkout-branch")||"",a=document.querySelector("[data-workspace-workbench]"),r=a&&a.getAttribute("data-checkout-url");!n||!r||e.disabled||fetch(r,{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json"},body:JSON.stringify({branch:n})}).then(o=>o.text().then(i=>{let s={};try{s=i?JSON.parse(i):{}}catch{}if(!o.ok||s.success===!1)throw new Error(s.message||i||o.statusText);window.location.reload()})).catch(o=>{window.alert(A(o))})})});document.querySelectorAll("[data-branch-panel]").forEach(e=>{e.addEventListener("click",l=>l.stopPropagation());let t=e.closest("[data-workspace-dropdown]"),n=e.querySelector("[data-branch-panel-close]");n&&t&&n.addEventListener("click",()=>t.classList.remove("is-open"));let a=Array.from(e.querySelectorAll("[data-branch-tab]")),r=Array.from(e.querySelectorAll("[data-branch-pane]")),o=e.querySelector("[data-branch-panel-search]");a.forEach(l=>{l.addEventListener("click",()=>{let c=l.getAttribute("data-branch-tab");a.forEach(w=>w.classList.toggle("is-active",w===l)),r.forEach(w=>{w.hidden=w.getAttribute("data-branch-pane")!==c}),o&&(o.hidden=c!=="branches")})});let i=e.querySelector("[data-branch-filter]"),s=Array.from(e.querySelectorAll("[data-branch-item]")),u=e.querySelector("[data-branch-empty]");i&&i.addEventListener("input",()=>{let l=i.value.trim().toLowerCase(),c=0;s.forEach(w=>{let y=w.getAttribute("data-branch-name-lower")||"",b=!l||y.includes(l);w.hidden=!b,b&&(c+=1)}),u&&(u.hidden=c!==0)})});function G(e){if(!e)return;e.classList.add("is-open"),e.setAttribute("aria-hidden","false");let t=e.querySelector("input, textarea, button");t&&window.setTimeout(()=>{t.focus()},0)}function O(){document.querySelectorAll(".workspace-modal.is-open").forEach(e=>{e.classList.remove("is-open"),e.setAttribute("aria-hidden","true")})}document.querySelectorAll("[data-close-workspace-modal]").forEach(e=>{e.addEventListener("click",O)});document.querySelectorAll(".workspace-modal").forEach(e=>{e.addEventListener("click",t=>{t.target===e&&O()})});var R=document.querySelector(".workspace-repo-file-list[data-dir-data-url]"),$=R&&R.getAttribute("data-dir-data-url")||"",I=new Map;function Q(e){let t=I.get(e);if(t)return t;if(!$)return Promise.resolve([]);let n=$+"?path="+encodeURIComponent(e),a=fetch(n,{credentials:"same-origin"}).then(r=>{if(!r.ok)throw new Error(r.statusText);return r.json()}).then(r=>r||[]).catch(r=>{throw I.delete(e),r});return I.set(e,a),a}function U(e){let t=document.createElement("span");return t.className="dir-icon dir-icon-"+e,t.setAttribute("aria-hidden","true"),t}function Y(e,t,n){let a=`${(n+1)*18+5}px`;if(!t.length){let r=document.createElement("li"),o=document.createElement("div");o.className="workspace-tree-empty",o.style.paddingLeft=a,o.textContent=d("web.ws.tree.empty"),r.appendChild(o),e.appendChild(r);return}for(let r of t){let o=document.createElement("li");o.className="workspace-tree-item",o.setAttribute("data-entry-path",r.rel_git_path),o.setAttribute("data-filter-visible-markdown",r.show_in_markdown?"true":"false");let i=document.createElement("div");i.className="workspace-tree-row";let s=document.createElement("div");if(s.className="workspace-tree-name",s.style.paddingLeft=a,r.is_dir){o.setAttribute("data-tree-dir",""),o.setAttribute("data-tree-path",r.rel_git_path),o.dataset.depth=String(n),i.setAttribute("role","button"),i.setAttribute("tabindex","0"),i.setAttribute("aria-expanded","false");let c=document.createElement("span");c.className="workspace-tree-label",c.textContent=r.name+"/",s.appendChild(U("folder")),s.appendChild(c)}else{let c=document.createElement("a");c.href=r.link,c.textContent=r.name,s.appendChild(U("file")),s.appendChild(c)}let u=document.createElement("div");u.className="workspace-entry-commit",r.last_commit_subject&&(u.textContent=r.last_commit_subject,u.title=r.last_commit_subject);let l=document.createElement("div");if(l.className="workspace-entry-time",r.last_commit_time&&(l.textContent=r.last_commit_time),i.appendChild(s),i.appendChild(u),i.appendChild(l),o.appendChild(i),r.is_dir){let c=document.createElement("ul");c.className="workspace-tree is-collapsed",o.appendChild(c)}e.appendChild(o)}}function Z(){let e=window.location.hash.replace(/^#/,"");if(!e)return"";try{return decodeURIComponent(e).replace(/\/+$/,"")}catch{return e.replace(/\/+$/,"")}}function ee(e){let t=window.location.pathname+window.location.search,n=e?"#"+e.split("/").map(encodeURIComponent).join("/")+"/":"";window.history.replaceState(null,"",t+n)}function te(e){e&&(T(),ee(e))}function ne(e){let t=Z();e&&(t===e||t.startsWith(e+"/"))&&(T(),ee(""))}function re(e){let t=e.querySelector(":scope > .workspace-tree-row"),n=e.querySelector(":scope > ul.workspace-tree");if(!t||!n)return Promise.resolve(null);if(t.setAttribute("aria-expanded","true"),n.getAttribute("data-built"))return n.classList.remove("is-collapsed"),Promise.resolve(n);let a=parseInt(e.dataset.depth||"0",10);return Q(e.getAttribute("data-tree-path")||"").then(r=>t.getAttribute("aria-expanded")!=="true"?null:(n.getAttribute("data-built")||(Y(n,r,a+1),n.setAttribute("data-built","1")),n.classList.remove("is-collapsed"),n)).catch(()=>(t.setAttribute("aria-expanded","false"),null))}function ae(e){let t=e.querySelector(":scope > .workspace-tree-row"),n=e.querySelector(":scope > ul.workspace-tree");if(!t||!n)return;let a=e.getAttribute("data-tree-path")||"";if(t.getAttribute("aria-expanded")==="true"){n.classList.add("is-collapsed"),t.setAttribute("aria-expanded","false"),ne(a);return}te(a),re(e)}function P(e,t){let n=e.nextElementSibling;return n&&n.matches("[data-dir-children]")&&n.getAttribute("data-parent")===t?n:null}function oe(e){let t=e.closest("[data-entry-kind]");if(!t)return Promise.resolve(null);let n=e.getAttribute("data-dir-path")||"";e.setAttribute("aria-expanded","true");let a=P(t,n);return a?(a.classList.remove("is-collapsed"),Promise.resolve(a.querySelector(":scope > ul.workspace-tree"))):Q(n).then(r=>{if(e.getAttribute("aria-expanded")!=="true")return null;let o=P(t,n);if(o)return o.classList.remove("is-collapsed"),o.querySelector(":scope > ul.workspace-tree");let i=document.createElement("li");i.className="workspace-entry-children",i.setAttribute("data-dir-children",""),i.setAttribute("data-parent",n),i.setAttribute("data-filter-visible-markdown",t.getAttribute("data-filter-visible-markdown")||"false");let s=document.createElement("ul");return s.className="workspace-tree",Y(s,r,0),i.appendChild(s),t.parentNode&&t.parentNode.insertBefore(i,t.nextSibling),s}).catch(()=>(e.setAttribute("aria-expanded","false"),null))}function pe(e){let t=e.closest("[data-entry-kind]");if(!t)return;let n=e.getAttribute("data-dir-path")||"";if(e.getAttribute("aria-expanded")==="true"){let a=P(t,n);a&&a.classList.add("is-collapsed"),e.setAttribute("aria-expanded","false"),ne(n);return}te(n),oe(e)}document.querySelectorAll("[data-dir-toggle]").forEach(e=>{e.addEventListener("click",t=>{t.preventDefault(),pe(e)})});document.addEventListener("click",e=>{let t=e.target,n=t&&t.closest?t.closest('.workspace-tree-row[role="button"]'):null;if(!n)return;let a=n.closest("[data-tree-dir]");a&&ae(a)});document.addEventListener("keydown",e=>{if(e.key!=="Enter"&&e.key!==" ")return;let t=e.target;if(!t?.classList?.contains("workspace-tree-row")||t.getAttribute("role")!=="button")return;let n=t.closest("[data-tree-dir]");n&&(e.preventDefault(),ae(n))});var z=0;function T(){document.querySelectorAll(".is-workspace-target").forEach(e=>{e.classList.remove("is-workspace-target")})}function B(e){return e?(e.getAttribute("data-filter-visible-markdown")==="false"&&D("all"),T(),e.classList.add("is-workspace-target"),e.scrollIntoView({block:"center"}),!0):!1}function he(e,t){return e&&Array.from(e.querySelectorAll(":scope > li[data-entry-path]")).find(n=>n.getAttribute("data-entry-path")===t)||null}function we(e){return Array.from(document.querySelectorAll(".workspace-repo-file-list > li[data-entry-path]")).find(t=>t.getAttribute("data-entry-path")===e)||null}function N(){let e=Z();if(!e){T();return}let t=e.split("/").filter(Boolean);if(!t.length)return;let n=++z;if(B(we(e)))return;let a=Array.from(document.querySelectorAll("[data-dir-toggle]")).find(i=>i.getAttribute("data-dir-path")===t[0]);if(!a)return;let r=i=>{((i?(i.closest("[data-dir-children]")||i).previousElementSibling:null)||i)?.scrollIntoView({block:"nearest"})},o=(i,s)=>{if(n!==z||!i)return;if(s>=t.length){r(i);return}let u=t.slice(0,s+1).join("/"),l=Array.from(i.querySelectorAll(":scope > li[data-tree-dir]")).find(c=>c.getAttribute("data-tree-path")===u)||null;if(!l){B(he(i,e))||r(i);return}re(l).then(c=>o(c,s+1))};oe(a).then(i=>o(i,1))}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",N,{once:!0}):N();window.addEventListener("hashchange",N);(function(){let t=document.querySelector("[data-col-resize]");if(!t)return;let n=Array.from(t.querySelectorAll("[data-col-handle]"));if(n.length<2)return;let[a,r]=n;if(!a||!r)return;let o=t,i=a,s=r,u=18,l=72,c=64,y="markon:ws-cols:"+(o.getAttribute("data-ws-id")||""),b=()=>window.matchMedia("(max-width: 720px)").matches,f=320,p=420;try{let m=window.localStorage.getItem(y);if(m){let h=JSON.parse(m);typeof h.name=="number"&&h.name>0&&(f=h.name),typeof h.commit=="number"&&h.commit>0&&(p=h.commit)}}catch{}function ie(){let m=o.clientWidth||0;if(m<=0)return;let h=Math.max(l,m-2*u-p-c);f=Math.max(l,Math.min(f,h));let E=Math.max(l,m-2*u-f-c);p=Math.max(l,Math.min(p,E))}function M(){o.style.setProperty("--ws-col-name",`${f}px`),o.style.setProperty("--ws-col-commit",`${p}px`)}function H(){i.style.left=`${f+u/2}px`,s.style.left=`${f+u+p+u/2}px`}function se(){try{window.localStorage.setItem(y,JSON.stringify({name:f,commit:p}))}catch{}}function F(){ie(),M(),H()}if(n.forEach(m=>{m.hidden=!0}),n.length)return;n.forEach((m,h)=>{m.hidden=!1,m.addEventListener("pointerdown",E=>{if(b())return;E.preventDefault();let le=E.clientX,ce=f,de=p,j=o.clientWidth||0;m.classList.add("is-dragging");try{m.setPointerCapture(E.pointerId)}catch{}let W=x=>{let J=x.clientX-le;if(h===0){let q=Math.max(l,j-2*u-p-c);f=Math.max(l,Math.min(ce+J,q))}else{let q=Math.max(l,j-2*u-f-c);p=Math.max(l,Math.min(de+J,q))}M(),H()},L=x=>{m.classList.remove("is-dragging");try{m.releasePointerCapture(x.pointerId)}catch{}m.removeEventListener("pointermove",W),m.removeEventListener("pointerup",L),m.removeEventListener("pointercancel",L),se()};m.addEventListener("pointermove",W),m.addEventListener("pointerup",L),m.addEventListener("pointercancel",L)})}),M(),H();let S=()=>F();document.readyState==="loading"?window.addEventListener("DOMContentLoaded",()=>requestAnimationFrame(S),{once:!0}):requestAnimationFrame(S),window.addEventListener("load",S,{once:!0}),window.addEventListener("resize",F)})();document.querySelectorAll("[data-open-add-file]").forEach(e=>{e.addEventListener("click",t=>{t.preventDefault(),G(document.querySelector("[data-add-file-modal]"))})});var g=document.querySelector("[data-add-file-form]");g&&g.addEventListener("submit",e=>{e.preventDefault();let t=document.querySelector("[data-add-file-modal]"),n=g.querySelector("[data-add-file-path]"),a=g.querySelector("[data-add-file-content]"),r=g.querySelector("[data-add-file-status]"),o=(n&&n.value||"").trim(),i=o.split("/").pop();if(o&&i&&!i.includes(".")&&(o+=".md"),!o){r&&(r.textContent=d("web.ws.create_file.path_required"));return}r&&(r.textContent=d("web.ws.create_file.creating")),fetch(t&&t.getAttribute("data-create-file-url")||"",{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:o,content:a?a.value:""})}).then(s=>s.text().then(u=>{let l={};try{l=u?JSON.parse(u):{}}catch{}if(!s.ok||l.success===!1)throw new Error(l.message||u||s.statusText);window.location.href=l.url||window.location.href})).catch(s=>{r&&(r.textContent=A(s))})});document.querySelectorAll("[data-open-add-folder]").forEach(e=>{e.addEventListener("click",t=>{t.preventDefault(),G(document.querySelector("[data-add-folder-modal]"))})});var v=document.querySelector("[data-add-folder-form]");v&&v.addEventListener("submit",e=>{e.preventDefault();let t=document.querySelector("[data-add-folder-modal]"),n=v.querySelector("[data-add-folder-path]"),a=v.querySelector("[data-add-folder-status]"),r=(n&&n.value||"").trim();if(!r){a&&(a.textContent=d("web.ws.create_folder.path_required"));return}a&&(a.textContent=d("web.ws.create_folder.creating")),fetch(t&&t.getAttribute("data-create-folder-url")||"",{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:r})}).then(o=>o.text().then(i=>{let s={};try{s=i?JSON.parse(i):{}}catch{}if(!o.ok||s.success===!1)throw new Error(s.message||i||o.statusText);window.location.href=s.url||window.location.href})).catch(o=>{a&&(a.textContent=A(o))})});document.addEventListener("keydown",e=>{e.key==="Escape"&&O()});var K=document.querySelector("[data-add-file-path]");K&&(K.placeholder=d("web.ws.create_file.placeholder"));var V=document.querySelector("[data-add-folder-path]");V&&(V.placeholder=d("web.ws.create_folder.placeholder"));document.title=d(k?.dataset.titleKey||"web.title.dir");})();