From 387c7867687b3761da5dd664b8fda3994bb8c57f Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Sat, 4 Jan 2025 22:22:17 +0000 Subject: [PATCH] Updated version and assets for release v24.12.1 --- public/dist/markdown.js | 2 +- version | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/public/dist/markdown.js b/public/dist/markdown.js index 477a105ee1d..fef42325ea3 100644 --- a/public/dist/markdown.js +++ b/public/dist/markdown.js @@ -18,6 +18,6 @@ var Kt=Object.create;var ne=Object.defineProperty;var Yt=Object.getOwnPropertyDe `).map(f=>f.indexOf(`drawio-diagram="${n}"`)!==-1?a:f).join(` `);E(this,C,Qu).call(this,s,r),Ku()}catch(c){throw this.handleDrawingUploadError(c),new Error(`Failed to save image with error: ${c}`)}})}handleDrawingUploadError(e){e.status===413?window.$events.emit("error",this.editor.config.text.serverUploadLimit):window.$events.emit("error",this.editor.config.text.imageUploadError),console.error(e)}fullScreen(){let{container:e}=this.editor.config,t=e.classList.contains("fullscreen");e.classList.toggle("fullscreen",!t),document.body.classList.toggle("markdown-fullscreen",!t)}scrollToText(e){if(!e)return;let t=this.editor.cm.state.doc,r=1,n=-1;for(let i of t.iterLines()){if(i.includes(e)){n=r;break}r+=1}if(n===-1)return;let o=t.line(n);E(this,C,Vt).call(this,o.from,o.to,!0),this.focus()}focus(){this.editor.cm.hasFocus||this.editor.cm.focus()}insertContent(e){E(this,C,au).call(this,e,e.length)}prependContent(e){e=E(this,C,w0).call(this,e);let r=E(this,C,q).call(this).from+e.length+1;E(this,C,z).call(this,0,0,`${e} `,r),this.focus()}appendContent(e){e=E(this,C,w0).call(this,e),E(this,C,z).call(this,this.editor.cm.state.doc.length,` -${e}`),this.focus()}replaceContent(e){E(this,C,Qu).call(this,e)}replaceLineStart(e){let t=E(this,C,q).call(this),r=this.editor.cm.state.doc.lineAt(t.from),n=r.text,o=n.split(" ")[0];if(o===e){let s=n.replace(`${e} `,""),f=t.from+(s.length-n.length);E(this,C,z).call(this,r.from,r.to,s,f);return}let i=n;/^[#>`]/.test(o)?i=n.replace(o,e).trim():e!==""&&(i=`${e} ${n}`);let a=t.from+(i.length-n.length);E(this,C,z).call(this,r.from,r.to,i,a)}wrapSelection(e,t){let r=E(this,C,q).call(this),n=E(this,C,bu).call(this,r);if(!n){E(this,C,ue).call(this,e,t);return}let o=n,i;n.startsWith(e)&&n.endsWith(t)?(o=n.slice(e.length,n.length-t.length),i=r.extend(r.from,r.to-(e.length+t.length))):(o=`${e}${n}${t}`,i=r.extend(r.from,r.to+(e.length+t.length))),E(this,C,z).call(this,r.from,r.to,o,i.anchor,i.head)}replaceLineStartForOrderedList(){let e=E(this,C,q).call(this),t=this.editor.cm.state.doc.lineAt(e.from),n=this.editor.cm.state.doc.line(t.number-1).text.match(/^(\s*)(\d)([).])\s/)||[],o=(Number(n[2])||0)+1,i=n[1]||"",c=n[3]||".",a=`${i}${o}${c}`;return this.replaceLineStart(a)}cycleCalloutTypeAtSelection(){let e=E(this,C,q).call(this),t=this.editor.cm.state.doc.lineAt(e.from),r=["info","success","warning","danger"],n=r.join("|"),i=new RegExp(`class="((${n})\\s+callout|callout\\s+(${n}))"`,"i").exec(t.text),c=(i?i[2]||i[3]:"").toLowerCase();if(c===r[r.length-1])E(this,C,ue).call(this,`

`,"

");else if(c==="")E(this,C,ue).call(this,'

',"

");else{let a=r.indexOf(c)+1,s=r[a],f=t.text.replace(i[0],i[0].replace(c,s)),d=f.length-t.text.length;E(this,C,z).call(this,t.from,t.to,f,e.anchor+d,e.head+d)}}syncDisplayPosition(e){let t=e.target;if(Math.abs(t.scrollHeight-t.clientHeight-t.scrollTop)<1){this.editor.display.scrollToIndex(-1);return}let n=this.editor.cm.lineBlockAtHeight(t.scrollTop),o=this.editor.cm.state.sliceDoc(0,n.from),a=new DOMParser().parseFromString(this.editor.markdown.render(o),"text/html").documentElement.querySelectorAll("body > *");this.editor.display.scrollToIndex(a.length)}async insertTemplate(e,t,r){let n=this.editor.cm.posAtCoords({x:t,y:r},!1),{data:o}=await window.$http.get(`/templates/${e}`),i=o.markdown||o.html;E(this,C,z).call(this,n,n,i,n)}insertClipboardImages(e,t,r){let n=this.editor.cm.posAtCoords({x:t,y:r},!1);for(let o of e)this.uploadImage(o,n)}async uploadImage(e,t=null){if(e===null||e.type.indexOf("image")!==0)return;let r="png";if(t===null&&(t=E(this,C,q).call(this).from),e.name){let s=e.name.match(/\.(.+)$/);s.length>1&&(r=s[1])}let n=`image-${Math.random().toString(16).slice(2)}`,i=`![](${window.baseUrl(`/loading.gif#upload${n}`)})`;E(this,C,z).call(this,t,t,i,t);let c=`image-${Date.now()}.${r}`,a=new FormData;a.append("file",e,c),a.append("uploaded_to",this.editor.config.pageId);try{let{data:s}=await window.$http.post("/images/gallery",a),f=`[![](${s.thumbs.display})](${s.url})`;E(this,C,A0).call(this,i,f)}catch(s){window.$events.error(s?.data?.message||this.editor.config.text.imageUploadError),E(this,C,A0).call(this,i,""),console.error(s)}}};C=new WeakSet,E0=function(e,t){let r=`
`;E(this,C,au).call(this,r,r.length,t)},Yu=function(){return this.editor.cm.state.doc.toString()},Qu=function(e,t=null){t=t||E(this,C,q).call(this);let r=this.editor.cm.state.toText(e),n=Math.min(t.from,r.length);E(this,C,z).call(this,0,this.editor.cm.state.doc.length,e,n),this.focus()},au=function(e,t=0,r=null){r=r||this.editor.cm.state.selection.main;let n=r.from+t;E(this,C,z).call(this,r.from,r.to,e,n),this.focus()},bu=function(e=null){return e=e||E(this,C,q).call(this),this.editor.cm.state.sliceDoc(e.from,e.to)},q=function(){return this.editor.cm.state.selection.main},w0=function(e){return e.replace(/\r\n|\r/g,` +${e}`),this.focus()}replaceContent(e){E(this,C,Qu).call(this,e)}replaceLineStart(e){let t=E(this,C,q).call(this),r=this.editor.cm.state.doc.lineAt(t.from),n=r.text,o=n.split(" ")[0];if(o===e){let s=n.replace(`${e} `,""),f=t.from+(s.length-n.length);E(this,C,z).call(this,r.from,r.to,s,f);return}let i=n;/^[#>`]/.test(o)?i=n.replace(o,e).trim():e!==""&&(i=`${e} ${n}`);let a=t.from+(i.length-n.length);E(this,C,z).call(this,r.from,r.to,i,a)}wrapSelection(e,t){let r=E(this,C,q).call(this),n=E(this,C,bu).call(this,r);if(!n){E(this,C,ue).call(this,e,t);return}let o=n,i;n.startsWith(e)&&n.endsWith(t)?(o=n.slice(e.length,n.length-t.length),i=r.extend(r.from,r.to-(e.length+t.length))):(o=`${e}${n}${t}`,i=r.extend(r.from,r.to+(e.length+t.length))),E(this,C,z).call(this,r.from,r.to,o,i.anchor,i.head)}replaceLineStartForOrderedList(){let e=E(this,C,q).call(this),t=this.editor.cm.state.doc.lineAt(e.from),n=this.editor.cm.state.doc.line(t.number-1).text.match(/^(\s*)(\d)([).])\s/)||[],o=(Number(n[2])||0)+1,i=n[1]||"",c=n[3]||".",a=`${i}${o}${c}`;return this.replaceLineStart(a)}cycleCalloutTypeAtSelection(){let e=E(this,C,q).call(this),t=this.editor.cm.state.doc.lineAt(e.from),r=["info","success","warning","danger"],n=r.join("|"),i=new RegExp(`class="((${n})\\s+callout|callout\\s+(${n}))"`,"i").exec(t.text),c=(i?i[2]||i[3]:"").toLowerCase();if(c===r[r.length-1])E(this,C,ue).call(this,`

`,"

");else if(c==="")E(this,C,ue).call(this,'

',"

");else{let a=r.indexOf(c)+1,s=r[a],f=t.text.replace(i[0],i[0].replace(c,s)),d=f.length-t.text.length;E(this,C,z).call(this,t.from,t.to,f,e.anchor+d,e.head+d)}}syncDisplayPosition(e){let t=e.target;if(Math.abs(t.scrollHeight-t.clientHeight-t.scrollTop)<1){this.editor.display.scrollToIndex(-1);return}let n=this.editor.cm.lineBlockAtHeight(t.scrollTop),o=this.editor.cm.state.sliceDoc(0,n.from),a=new DOMParser().parseFromString(this.editor.markdown.render(o),"text/html").documentElement.querySelectorAll("body > *");this.editor.display.scrollToIndex(a.length)}async insertTemplate(e,t,r){let n=this.editor.cm.posAtCoords({x:t,y:r},!1),{data:o}=await window.$http.get(`/templates/${e}`),i=o.markdown||o.html;E(this,C,z).call(this,n,n,i,n)}insertClipboardImages(e,t,r){let n=this.editor.cm.posAtCoords({x:t,y:r},!1);for(let o of e)this.uploadImage(o,n)}async uploadImage(e,t=null){if(e===null||e.type.indexOf("image")!==0)return;let r="png";if(t===null&&(t=E(this,C,q).call(this).from),e.name){let s=e.name.match(/\.(.+)$/);s.length>1&&(r=s[1])}let n=`image-${Math.random().toString(16).slice(2)}`,i=`![](${window.baseUrl(`/loading.gif#upload${n}`)})`;E(this,C,z).call(this,t,t,i,t);let c=`image-${Date.now()}.${r}`,a=new FormData;a.append("file",e,c),a.append("uploaded_to",this.editor.config.pageId);try{let{data:s}=await window.$http.post("/images/gallery",a),f=`[![](${s.thumbs.display})](${s.url})`;E(this,C,A0).call(this,i,f)}catch(s){window.$events.error(s?.data?.message||this.editor.config.text.imageUploadError),E(this,C,A0).call(this,i,""),console.error(s)}}};C=new WeakSet,E0=function(e,t){let r=`
`;E(this,C,au).call(this,r,r.length,t)},Yu=function(){return this.editor.cm.state.doc.toString()},Qu=function(e,t=null){t=t||E(this,C,q).call(this);let r=this.editor.cm.state.toText(e),n=Math.min(t.from,r.length),o=this.editor.cm.scrollDOM.scrollTop;E(this,C,z).call(this,0,this.editor.cm.state.doc.length,e,n),this.focus(),window.requestAnimationFrame(()=>{this.editor.cm.scrollDOM.scrollTop=o})},au=function(e,t=0,r=null){r=r||this.editor.cm.state.selection.main;let n=r.from+t;E(this,C,z).call(this,r.from,r.to,e,n),this.focus()},bu=function(e=null){return e=e||E(this,C,q).call(this),this.editor.cm.state.sliceDoc(e.from,e.to)},q=function(){return this.editor.cm.state.selection.main},w0=function(e){return e.replace(/\r\n|\r/g,` `)},A0=function(e,t){let r=E(this,C,Yu).call(this).replace(e,t);E(this,C,Qu).call(this,r)},ue=function(e,t){let r=E(this,C,q).call(this),n=this.editor.cm.state.doc.lineAt(r.from),o=n.text,i,c=0;o.startsWith(e)&&o.endsWith(t)?(i=o.slice(e.length,o.length-t.length),c=-e.length):(i=`${e}${o}${t}`,c=e.length),E(this,C,z).call(this,n.from,n.to,i,r.from+c)},z=function(e,t=null,r=null,n=null,o=null){let i={changes:{from:e,to:t,insert:r}};n&&(i.selection={anchor:n},o&&(i.selection.head=o)),this.editor.cm.dispatch(i)},Vt=function(e,t,r=!1){this.editor.cm.dispatch({selection:{anchor:e,head:t},scrollIntoView:r})};var te=class{constructor(e){this.settingMap={scrollSync:!0,showPreview:!0,editorWidth:50},this.changeListeners={},this.loadFromLocalStorage(),this.applyToInputs(e),this.listenToInputChanges(e)}applyToInputs(e){for(let t of e){let r=t.getAttribute("name").replace("md-","");t.checked=this.settingMap[r]}}listenToInputChanges(e){for(let t of e)t.addEventListener("change",()=>{let r=t.getAttribute("name").replace("md-","");this.set(r,t.checked)})}loadFromLocalStorage(){let e=window.localStorage.getItem("md-editor-settings");if(!e)return;let t=JSON.parse(e);for(let[r,n]of Object.entries(t))n!==null&&this.settingMap[r]!==void 0&&(this.settingMap[r]=n)}set(e,t){this.settingMap[e]=t,window.localStorage.setItem("md-editor-settings",JSON.stringify(this.settingMap));for(let r of this.changeListeners[e]||[])r(t)}get(e){return this.settingMap[e]||null}onChange(e,t){let r=this.changeListeners[e]||[];r.push(t),this.changeListeners[e]=r}};function re({html:u,markdown:e}){return e||u}function Zt(u){window.$events.listen("editor::replace",e=>{let t=re(e);u.actions.replaceContent(t)}),window.$events.listen("editor::append",e=>{let t=re(e);u.actions.appendContent(t)}),window.$events.listen("editor::prepend",e=>{let t=re(e);u.actions.prependContent(t)}),window.$events.listen("editor::insert",e=>{let t=re(e);u.actions.insertContent(t)}),window.$events.listen("editor::focus",()=>{u.actions.focus()})}function Zo(u){let e={};return e["Shift-Mod-i"]=()=>u.actions.insertImage(),e["Mod-s"]=()=>window.$events.emit("editor-save-draft"),e["Mod-Enter"]=()=>window.$events.emit("editor-save-page"),e["Shift-Mod-k"]=()=>u.actions.showLinkSelector(),e["Mod-k"]=()=>u.actions.insertLink(),e["Mod-1"]=()=>u.actions.replaceLineStart("##"),e["Mod-2"]=()=>u.actions.replaceLineStart("###"),e["Mod-3"]=()=>u.actions.replaceLineStart("####"),e["Mod-4"]=()=>u.actions.replaceLineStart("#####"),e["Mod-5"]=()=>u.actions.replaceLineStart(""),e["Mod-d"]=()=>u.actions.replaceLineStart(""),e["Mod-6"]=()=>u.actions.replaceLineStart(">"),e["Mod-q"]=()=>u.actions.replaceLineStart(">"),e["Mod-7"]=()=>u.actions.wrapSelection("\n```\n","\n```"),e["Mod-8"]=()=>u.actions.wrapSelection("`","`"),e["Shift-Mod-e"]=()=>u.actions.wrapSelection("`","`"),e["Mod-9"]=()=>u.actions.cycleCalloutTypeAtSelection(),e["Mod-p"]=()=>u.actions.replaceLineStart("-"),e["Mod-o"]=()=>u.actions.replaceLineStartForOrderedList(),e}function Gt(u){let e=Zo(u),t=[],r=n=>()=>(n(),!0);for(let[n,o]of Object.entries(e))t.push({key:n,run:r(o),preventDefault:!0});return t}function Wt(u,e,t){let r=null;return function(...o){let i=this,c=function(){r=null,t||u.apply(i,o)},a=t&&!r;r&&clearTimeout(r),r=window.setTimeout(c,e),a&&u.apply(i,o)}}var Cu=class{constructor(e){this.data=e}hasItems(){return!!this.data&&!!this.data.types&&this.data.types.length>0}containsTabularData(){let e=this.data.getData("text/rtf");return!!e&&e.includes("\\trowd")}getImages(){return this.getFiles().filter(e=>e.type.includes("image"))}getFiles(){let{files:e}=this.data;return[...e]}};async function Xt(u){let e=await window.importVersioned("code");function t(c){c.docChanged&&u.actions.updateAndRender()}let r=Wt(u.actions.syncDisplayPosition.bind(u.actions),100,!1),n=u.settings.get("scrollSync");u.settings.onChange("scrollSync",c=>{n=c});let o={scroll:c=>n&&r(c),drop:c=>{let a=c.dataTransfer.getData("bookstack/template");a&&(c.preventDefault(),u.actions.insertTemplate(a,c.pageX,c.pageY));let f=new Cu(c.dataTransfer).getImages();f.length>0&&(c.stopPropagation(),c.preventDefault(),u.actions.insertClipboardImages(f,c.pageX,c.pageY))},dragover:c=>{c.preventDefault()},paste:c=>{let a=new Cu(c.clipboardData||c.dataTransfer);if(!a.hasItems()||a.containsTabularData())return;let s=a.getImages();for(let f of s)u.actions.uploadImage(f)}},i=e.markdownEditor(u.config.inputEl,t,o,Gt(u));return window.mdEditorView=i,i}async function ul(u){let e={config:u,markdown:new Uu,settings:new te(u.settingInputs)};return e.actions=new ee(e),e.display=new Gu(e),e.cm=await Xt(e),Zt(e),e}export{ul as init}; //# sourceMappingURL=markdown.js.map diff --git a/version b/version index a75b21c8751..39a22c219d4 100644 --- a/version +++ b/version @@ -1 +1 @@ -v24.12 +v24.12.1