From c1d30341e7e8938e6354db3333662e5fa228604f Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Fri, 15 Sep 2023 13:49:40 +0100 Subject: [PATCH] Updated version and assets for release v23.08.3 --- public/dist/app.js | 2 +- version | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/public/dist/app.js b/public/dist/app.js index ebf34ef72..211f00f55 100644 --- a/public/dist/app.js +++ b/public/dist/app.js @@ -22,7 +22,7 @@ In order to be iterable, non-array objects must have a [Symbol.iterator]() metho `,i),this.focus()}appendContent(e){e=T(this,nn,Ro).call(this,e),T(this,he,ve).call(this,this.editor.cm.state.doc.length,` ${e}`),this.focus()}replaceContent(e){T(this,kt,Ai).call(this,e)}replaceLineStart(e){let t=T(this,ie,ue).call(this),i=this.editor.cm.state.doc.lineAt(t.from),r=i.text,o=r.split(" ")[0];if(o===e){let c=r.replace(`${e} `,""),u=t.from+(c.length-r.length);T(this,he,ve).call(this,i.from,i.to,c,u);return}let s=r;/^[#>`]/.test(o)?s=r.replace(o,e).trim():e!==""&&(s=`${e} ${r}`);let l=t.from+(s.length-r.length);T(this,he,ve).call(this,i.from,i.to,s,l)}wrapSelection(e,t){let i=T(this,ie,ue).call(this),r=T(this,We,yt).call(this,i);if(!r){T(this,Ct,Di).call(this,e,t);return}let o=r,s;r.startsWith(e)&&r.endsWith(t)?(o=r.slice(e.length,r.length-t.length),s=i.extend(i.from,i.to-(e.length+t.length))):(o=`${e}${r}${t}`,s=i.extend(i.from,i.to+(e.length+t.length))),T(this,he,ve).call(this,i.from,i.to,o,s.anchor,s.head)}replaceLineStartForOrderedList(){let e=T(this,ie,ue).call(this),t=this.editor.cm.state.doc.lineAt(e.from),r=this.editor.cm.state.doc.line(t.number-1).text.match(/^(\s*)(\d)([).])\s/)||[],o=(Number(r[2])||0)+1,s=r[1]||"",a=r[3]||".",l=`${s}${o}${a}`;return this.replaceLineStart(l)}cycleCalloutTypeAtSelection(){let e=T(this,ie,ue).call(this),t=this.editor.cm.state.doc.lineAt(e.from),i=["info","success","warning","danger"],r=i.join("|"),s=new RegExp(`class="((${r})\\s+callout|callout\\s+(${r}))"`,"i").exec(t.text),a=(s?s[2]||s[3]:"").toLowerCase();if(a===i[i.length-1])T(this,Ct,Di).call(this,`

`,"

");else if(a==="")T(this,Ct,Di).call(this,'

',"

");else{let l=i.indexOf(a)+1,c=i[l],u=t.text.replace(s[0],s[0].replace(a,c)),h=u.length-t.text.length;T(this,he,ve).call(this,t.from,t.to,u,e.anchor+h,e.head+h)}}syncDisplayPosition(e){let t=e.target;if(Math.abs(t.scrollHeight-t.clientHeight-t.scrollTop)<1){this.editor.display.scrollToIndex(-1);return}let r=this.editor.cm.lineBlockAtHeight(t.scrollTop),o=this.editor.cm.state.sliceDoc(0,r.from),l=new DOMParser().parseFromString(this.editor.markdown.render(o),"text/html").documentElement.querySelectorAll("body > *");this.editor.display.scrollToIndex(l.length)}async insertTemplate(e,t,i){let r=this.editor.cm.posAtCoords({x:t,y:i},!1),{data:o}=await window.$http.get(`/templates/${e}`),s=o.markdown||o.html;T(this,he,ve).call(this,r,r,s,r)}insertClipboardImages(e,t,i){let r=this.editor.cm.posAtCoords({x:t,y:i},!1);for(let o of e)this.uploadImage(o,r)}async uploadImage(e,t=null){if(e===null||e.type.indexOf("image")!==0)return;let i="png";if(t===null&&(t=T(this,ie,ue).call(this).from),e.name){let c=e.name.match(/\.(.+)$/);c.length>1&&(i=c[1])}let r=`image-${Math.random().toString(16).slice(2)}`,s=`![](${window.baseUrl(`/loading.gif#upload${r}`)})`;T(this,he,ve).call(this,t,t,s,t);let a=`image-${Date.now()}.${i}`,l=new FormData;l.append("file",e,a),l.append("uploaded_to",this.editor.config.pageId);try{let{data:c}=await window.$http.post("/images/gallery",l),u=`[![](${c.thumbs.display})](${c.url})`;T(this,rn,No).call(this,s,u)}catch(c){window.$events.emit("error",this.editor.config.text.imageUploadError),T(this,rn,No).call(this,s,""),console.error(c)}}};tn=new WeakSet,Oo=function(e,t){let i=`
`;T(this,Pe,nt).call(this,i,i.length,t)},xt=new WeakSet,Si=function(){return this.editor.cm.state.doc.toString()},kt=new WeakSet,Ai=function(e,t=null){t=t||T(this,ie,ue).call(this);let i=this.editor.cm.state.toText(e),r=Math.min(t.from,i.length);T(this,he,ve).call(this,0,this.editor.cm.state.doc.length,e,r),this.focus()},Pe=new WeakSet,nt=function(e,t=0,i=null){i=i||this.editor.cm.state.selection.main;let r=i.from+t;T(this,he,ve).call(this,i.from,i.to,e,r),this.focus()},We=new WeakSet,yt=function(e=null){return e=e||T(this,ie,ue).call(this),this.editor.cm.state.sliceDoc(e.from,e.to)},ie=new WeakSet,ue=function(){return this.editor.cm.state.selection.main},nn=new WeakSet,Ro=function(e){return e.replace(/\r\n|\r/g,` `)},rn=new WeakSet,No=function(e,t){let i=T(this,xt,Si).call(this).replace(e,t);T(this,kt,Ai).call(this,i)},Ct=new WeakSet,Di=function(e,t){let i=T(this,ie,ue).call(this),r=this.editor.cm.state.doc.lineAt(i.from),o=r.text,s,a=0;o.startsWith(e)&&o.endsWith(t)?(s=o.slice(e.length,o.length-t.length),a=-e.length):(s=`${e}${o}${t}`,a=e.length),T(this,he,ve).call(this,r.from,r.to,s,i.from+a)},he=new WeakSet,ve=function(e,t=null,i=null,r=null,o=null){let s={changes:{from:e,to:t,insert:i}};r&&(s.selection={anchor:r},o&&(s.selection.head=o)),this.editor.cm.dispatch(s)},Li=new WeakSet,Qc=function(e,t,i=!1){this.editor.cm.dispatch({selection:{anchor:e,head:t},scrollIntoView:i})};var Ii=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 i=t.getAttribute("name").replace("md-","");t.checked=this.settingMap[i]}}listenToInputChanges(e){for(let t of e)t.addEventListener("change",()=>{let i=t.getAttribute("name").replace("md-","");this.set(i,t.checked)})}loadFromLocalStorage(){let e=window.localStorage.getItem("md-editor-settings");if(!e)return;let t=JSON.parse(e);for(let[i,r]of Object.entries(t))r!==null&&this.settingMap[i]!==void 0&&(this.settingMap[i]=r)}set(e,t){this.settingMap[e]=t,window.localStorage.setItem("md-editor-settings",JSON.stringify(this.settingMap));for(let i of this.changeListeners[e]||[])i(t)}get(e){return this.settingMap[e]||null}onChange(e,t){let i=this.changeListeners[e]||[];i.push(t),this.changeListeners[e]=i}};function $i({html:n,markdown:e}){return e||n}function eu(n){window.$events.listen("editor::replace",e=>{let t=$i(e);n.actions.replaceContent(t)}),window.$events.listen("editor::append",e=>{let t=$i(e);n.actions.appendContent(t)}),window.$events.listen("editor::prepend",e=>{let t=$i(e);n.actions.prependContent(t)}),window.$events.listen("editor::insert",e=>{let t=$i(e);n.actions.insertContent(t)}),window.$events.listen("editor::focus",()=>{n.actions.focus()})}function qf(n){let e={};return e["Shift-Mod-i"]=()=>n.actions.insertImage(),e["Mod-s"]=()=>window.$events.emit("editor-save-draft"),e["Mod-Enter"]=()=>window.$events.emit("editor-save-page"),e["Shift-Mod-k"]=()=>n.actions.showLinkSelector(),e["Mod-k"]=()=>n.actions.insertLink(),e["Mod-1"]=()=>n.actions.replaceLineStart("##"),e["Mod-2"]=()=>n.actions.replaceLineStart("###"),e["Mod-3"]=()=>n.actions.replaceLineStart("####"),e["Mod-4"]=()=>n.actions.replaceLineStart("#####"),e["Mod-5"]=()=>n.actions.replaceLineStart(""),e["Mod-d"]=()=>n.actions.replaceLineStart(""),e["Mod-6"]=()=>n.actions.replaceLineStart(">"),e["Mod-q"]=()=>n.actions.replaceLineStart(">"),e["Mod-7"]=()=>n.actions.wrapSelection("\n```\n","\n```"),e["Mod-8"]=()=>n.actions.wrapSelection("`","`"),e["Shift-Mod-e"]=()=>n.actions.wrapSelection("`","`"),e["Mod-9"]=()=>n.actions.cycleCalloutTypeAtSelection(),e["Mod-p"]=()=>n.actions.replaceLineStart("-"),e["Mod-o"]=()=>n.actions.replaceLineStartForOrderedList(),e}function tu(n){let e=qf(n),t=[],i=r=>()=>(r(),!0);for(let[r,o]of Object.entries(e))t.push({key:r,run:i(o),preventDefault:!0});return t}async function nu(n){let e=await window.importVersioned("code");function t(a){a.docChanged&&n.actions.updateAndRender()}let i=Ne(n.actions.syncDisplayPosition.bind(n.actions),100,!1),r=n.settings.get("scrollSync");n.settings.onChange("scrollSync",a=>{r=a});let o={scroll:a=>r&&i(a),drop:a=>{let l=a.dataTransfer.getData("bookstack/template");l&&(a.preventDefault(),n.actions.insertTemplate(l,a.pageX,a.pageY));let u=new Fe(a.dataTransfer).getImages();u.length>0&&(a.stopPropagation(),a.preventDefault(),n.actions.insertClipboardImages(u,a.pageX,a.pageY))},paste:a=>{let l=new Fe(a.clipboardData||a.dataTransfer);if(!l.hasItems()||l.containsTabularData())return;let c=l.getImages();for(let u of c)n.actions.uploadImage(u)}},s=e.markdownEditor(n.config.inputEl,t,o,tu(n));return window.mdEditorView=s,s}async function iu(n){let e={config:n,markdown:new wi,settings:new Ii(n.settingInputs)};return e.actions=new Ti(e),e.display=new ki(e),e.cm=await nu(e),eu(e),e}var Mi=class extends g{setup(){this.elem=this.$el,this.pageId=this.$opts.pageId,this.textDirection=this.$opts.textDirection,this.imageUploadErrorText=this.$opts.imageUploadErrorText,this.serverUploadLimitText=this.$opts.serverUploadLimitText,this.display=this.$refs.display,this.input=this.$refs.input,this.divider=this.$refs.divider,this.displayWrap=this.$refs.displayWrap;let{settingContainer:e}=this.$refs,t=e.querySelectorAll('input[type="checkbox"]');this.editor=null,iu({pageId:this.pageId,container:this.elem,displayEl:this.display,inputEl:this.input,drawioUrl:this.getDrawioUrl(),settingInputs:Array.from(t),text:{serverUploadLimit:this.serverUploadLimitText,imageUploadError:this.imageUploadErrorText}}).then(i=>{this.editor=i,this.setupListeners(),this.emitEditorEvents(),this.scrollToTextIfNeeded(),this.editor.actions.updateAndRender()})}emitEditorEvents(){window.$events.emitPublic(this.elem,"editor-markdown::setup",{markdownIt:this.editor.markdown.getRenderer(),displayEl:this.display,cmEditorView:this.editor.cm})}setupListeners(){this.elem.addEventListener("click",e=>{let t=e.target.closest("button[data-action]");if(t===null)return;let i=t.getAttribute("data-action");if(i==="insertImage"&&this.editor.actions.showImageInsert(),i==="insertLink"&&this.editor.actions.showLinkSelector(),i==="insertDrawing"&&(e.ctrlKey||e.metaKey)){this.editor.actions.showImageManager();return}i==="insertDrawing"&&this.editor.actions.startDrawing(),i==="fullscreen"&&this.editor.actions.fullScreen()}),this.elem.addEventListener("click",e=>{let t=e.target.closest(".editor-toolbar-label");if(!t)return;let i=this.elem.querySelectorAll(".markdown-editor-wrap");for(let r of i)r.classList.remove("active");t.closest(".markdown-editor-wrap").classList.add("active")}),this.handleDividerDrag()}handleDividerDrag(){this.divider.addEventListener("pointerdown",()=>{let t=this.elem.getBoundingClientRect(),i=o=>{let s=o.pageX-t.left,a=Math.min(Math.max(20,Math.floor(s/t.width*100)),80);this.displayWrap.style.flexBasis=`${100-a}%`,this.editor.settings.set("editorWidth",a)},r=()=>{window.removeEventListener("pointermove",i),window.removeEventListener("pointerup",r),this.display.style.pointerEvents=null,document.body.style.userSelect=null};this.display.style.pointerEvents="none",document.body.style.userSelect="none",window.addEventListener("pointermove",i),window.addEventListener("pointerup",r)});let e=this.editor.settings.get("editorWidth");e&&(this.displayWrap.style.flexBasis=`${100-e}%`)}scrollToTextIfNeeded(){let t=new URL(window.location).searchParams.get("content-text");t&&this.editor.actions.scrollToText(t)}getDrawioUrl(){let e=document.querySelector("[drawio-url]");return e&&e.getAttribute("drawio-url")||""}getContent(){return this.editor.actions.getContent()}};var Fi=class extends g{setup(){this.container=this.$el,this.inputContainer=this.$refs.inputContainer,this.inviteOption=this.container.querySelector("input[name=send_invite]"),this.inviteOption&&(this.inviteOption.addEventListener("change",this.inviteOptionChange.bind(this)),this.inviteOptionChange())}inviteOptionChange(){let e=this.inviteOption.value==="true",t=this.container.querySelectorAll("input[type=password]");for(let i of t)i.disabled=e;this.inputContainer.style.display=e?"none":"block"}};var qi=class extends g{setup(){this.container=this.$el,this.type=this.$opts.type,this.textElem=this.container.querySelector("span"),this.autoHide=this.$opts.autoHide==="true",this.initialShow=this.$opts.show==="true",this.container.style.display="grid",window.$events.listen(this.type,e=>{this.show(e)}),this.container.addEventListener("click",this.hide.bind(this)),this.initialShow&&setTimeout(()=>this.show(this.textElem.textContent),100),this.hideCleanup=this.hideCleanup.bind(this)}show(e=""){if(this.container.removeEventListener("transitionend",this.hideCleanup),this.textElem.textContent=e,this.container.style.display="grid",setTimeout(()=>{this.container.classList.add("showing")},1),this.autoHide){let t=e.split(" ").length,i=Math.max(2e3,1e3+250*t);setTimeout(this.hide.bind(this),i)}}hide(){this.container.classList.remove("showing"),this.container.addEventListener("transitionend",this.hideCleanup)}hideCleanup(){this.container.style.display="none",this.container.removeEventListener("transitionend",this.hideCleanup)}};var Bi=class extends g{setup(){this.removeButton=this.$refs.remove,this.showButton=this.$refs.show,this.input=this.$refs.input,this.setupListeners()}setupListeners(){O(this.removeButton,()=>{this.input.value="",this.input.classList.add("hidden"),this.removeButton.classList.add("hidden"),this.showButton.classList.remove("hidden")}),O(this.showButton,()=>{this.input.classList.remove("hidden"),this.removeButton.classList.remove("hidden"),this.showButton.classList.add("hidden")})}};var Pi=class extends g{setup(){this.commentId=this.$opts.commentId,this.commentLocalId=this.$opts.commentLocalId,this.commentParentId=this.$opts.commentParentId,this.deletedText=this.$opts.deletedText,this.updatedText=this.$opts.updatedText,this.container=this.$el,this.contentContainer=this.$refs.contentContainer,this.form=this.$refs.form,this.formCancel=this.$refs.formCancel,this.editButton=this.$refs.editButton,this.deleteButton=this.$refs.deleteButton,this.replyButton=this.$refs.replyButton,this.input=this.$refs.input,this.setupListeners()}setupListeners(){this.replyButton&&this.replyButton.addEventListener("click",()=>this.$emit("reply",{id:this.commentLocalId,element:this.container})),this.editButton&&(this.editButton.addEventListener("click",this.startEdit.bind(this)),this.form.addEventListener("submit",this.update.bind(this)),this.formCancel.addEventListener("click",()=>this.toggleEditMode(!1))),this.deleteButton&&this.deleteButton.addEventListener("click",this.delete.bind(this))}toggleEditMode(e){this.contentContainer.toggleAttribute("hidden",e),this.form.toggleAttribute("hidden",!e)}startEdit(){this.toggleEditMode(!0);let e=this.$refs.input.value.split(` -`).length;this.$refs.input.style.height=`${e*20+40}px`}async update(e){e.preventDefault();let t=this.showLoading();this.form.toggleAttribute("hidden",!0);let i={text:this.input.value,parent_id:this.parentId||null};try{let r=await window.$http.put(`/comment/${this.commentId}`,i),o=_e(r.data);this.container.replaceWith(o),window.$events.success(this.updatedText)}catch(r){console.error(r),window.$events.showValidationErrors(r),this.form.toggleAttribute("hidden",!1),t.remove()}}async delete(){this.showLoading(),await window.$http.delete(`/comment/${this.commentId}`),this.container.closest(".comment-branch").remove(),window.$events.success(this.deletedText),this.$emit("delete")}showLoading(){let e=at();return e.classList.add("px-l"),this.container.append(e),e}};var Oi=class extends g{setup(){this.elem=this.$el,this.pageId=Number(this.$opts.pageId),this.container=this.$refs.commentContainer,this.commentCountBar=this.$refs.commentCountBar,this.commentsTitle=this.$refs.commentsTitle,this.addButtonContainer=this.$refs.addButtonContainer,this.replyToRow=this.$refs.replyToRow,this.formContainer=this.$refs.formContainer,this.form=this.$refs.form,this.formInput=this.$refs.formInput,this.formReplyLink=this.$refs.formReplyLink,this.addCommentButton=this.$refs.addCommentButton,this.hideFormButton=this.$refs.hideFormButton,this.removeReplyToButton=this.$refs.removeReplyToButton,this.createdText=this.$opts.createdText,this.countText=this.$opts.countText,this.parentId=null,this.formReplyText=this.formReplyLink.textContent,this.setupListeners()}setupListeners(){this.removeReplyToButton.addEventListener("click",this.removeReplyTo.bind(this)),this.hideFormButton.addEventListener("click",this.hideForm.bind(this)),this.addCommentButton.addEventListener("click",this.showForm.bind(this)),this.elem.addEventListener("page-comment-delete",()=>{this.updateCount(),this.hideForm()}),this.elem.addEventListener("page-comment-reply",e=>{this.setReply(e.detail.id,e.detail.element)}),this.form&&this.form.addEventListener("submit",this.saveComment.bind(this))}saveComment(e){e.preventDefault(),e.stopPropagation();let t=at();t.classList.add("px-l"),this.form.after(t),this.form.toggleAttribute("hidden",!0);let r={text:this.formInput.value,parent_id:this.parentId||null};window.$http.post(`/comment/${this.pageId}`,r).then(o=>{let s=_e(o.data);this.formContainer.after(s),window.$events.success(this.createdText),this.hideForm(),this.updateCount()}).catch(o=>{this.form.toggleAttribute("hidden",!1),window.$events.showValidationErrors(o)}),this.form.toggleAttribute("hidden",!1),t.remove()}updateCount(){let e=this.getCommentCount();this.commentsTitle.textContent=window.trans_plural(this.countText,e,{count:e})}resetForm(){this.formInput.value="",this.parentId=null,this.replyToRow.toggleAttribute("hidden",!0),this.container.append(this.formContainer)}showForm(){this.formContainer.toggleAttribute("hidden",!1),this.addButtonContainer.toggleAttribute("hidden",!0),this.formContainer.scrollIntoView({behavior:"smooth",block:"nearest"}),setTimeout(()=>{this.formInput.focus()},100)}hideForm(){this.resetForm(),this.formContainer.toggleAttribute("hidden",!0),this.getCommentCount()>0?this.elem.append(this.addButtonContainer):this.commentCountBar.append(this.addButtonContainer),this.addButtonContainer.toggleAttribute("hidden",!1)}getCommentCount(){return this.container.querySelectorAll('[component="page-comment"]').length}setReply(e,t){t.closest(".comment-branch").querySelector(".comment-branch-children").append(this.formContainer),this.showForm(),this.parentId=e,this.replyToRow.toggleAttribute("hidden",!1);let r=this.replyToRow.querySelector("a");r.textContent=this.formReplyText.replace("1234",this.parentId),r.href=`#comment${this.parentId}`}removeReplyTo(){this.parentId=null,this.replyToRow.toggleAttribute("hidden",!0),this.container.append(this.formContainer),this.showForm()}};function Bf(n,e){yr(`#page-navigation a[href="#${n}"]`,t=>{t.closest("li").classList.toggle("current-heading",e)})}function Pf(n){for(let e of n){let t=e.intersectionRatio===1;Bf(e.target.id,t)}}function Of(n){let e={rootMargin:"0px 0px 0px 0px",threshold:1},t=new IntersectionObserver(Pf,e);for(let i of n)t.observe(i)}var Ri=class extends g{setup(){if(this.container=this.$el,this.pageId=this.$opts.pageId,window.importVersioned("code").then(t=>t.highlight()),this.setupNavHighlighting(),this.setupDetailsCodeBlockRefresh(),window.location.hash){let t=window.location.hash.replace(/%20/g," ").substring(1);this.goToText(t)}let e=document.querySelector(".sidebar-page-nav");e&&K(e,"a","click",(t,i)=>{t.preventDefault(),window.$components.first("tri-layout").showContent();let r=i.getAttribute("href").substr(1);this.goToText(r),window.history.pushState(null,null,`#${r}`)})}goToText(e){let t=document.getElementById(e);if(yr(".page-content [data-highlighted]",i=>{i.removeAttribute("data-highlighted"),i.style.backgroundColor=null}),t!==null)kr(t);else{let i=Qo(".page-content > div > *",e);i&&kr(i)}}setupNavHighlighting(){let e=document.querySelector(".sidebar-page-nav"),t=document.querySelector(".page-content").querySelectorAll("h1, h2, h3, h4, h5, h6");t.length>0&&e!==null&&Of(t)}setupDetailsCodeBlockRefresh(){let e=i=>{[...i.target.querySelectorAll(".CodeMirror")].forEach(o=>o.CodeMirror&&o.CodeMirror.refresh())};[...this.container.querySelectorAll("details")].forEach(i=>i.addEventListener("toggle",e))}};function ru(n){let e=new Date(n*1e3),t=e.getHours(),i=e.getMinutes();return`${(t>9?"":"0")+t}:${(i>9?"":"0")+i}`}var Ni=class extends g{setup(){this.draftsEnabled=this.$opts.draftsEnabled==="true",this.editorType=this.$opts.editorType,this.pageId=Number(this.$opts.pageId),this.isNewDraft=this.$opts.pageNewDraft==="true",this.hasDefaultTitle=this.$opts.hasDefaultTitle||!1,this.container=this.$el,this.titleElem=this.$refs.titleContainer.querySelector("input"),this.saveDraftButton=this.$refs.saveDraft,this.discardDraftButton=this.$refs.discardDraft,this.discardDraftWrap=this.$refs.discardDraftWrap,this.deleteDraftButton=this.$refs.deleteDraft,this.deleteDraftWrap=this.$refs.deleteDraftWrap,this.draftDisplay=this.$refs.draftDisplay,this.draftDisplayIcon=this.$refs.draftDisplayIcon,this.changelogInput=this.$refs.changelogInput,this.changelogDisplay=this.$refs.changelogDisplay,this.changeEditorButtons=this.$manyRefs.changeEditor||[],this.switchDialogContainer=this.$refs.switchDialog,this.deleteDraftDialogContainer=this.$refs.deleteDraftDialog,this.draftText=this.$opts.draftText,this.autosaveFailText=this.$opts.autosaveFailText,this.editingPageText=this.$opts.editingPageText,this.draftDiscardedText=this.$opts.draftDiscardedText,this.draftDeleteText=this.$opts.draftDeleteText,this.draftDeleteFailText=this.$opts.draftDeleteFailText,this.setChangelogText=this.$opts.setChangelogText,this.autoSave={interval:null,frequency:3e4,last:0,pendingChange:!1},this.shownWarningsCache=new Set,this.pageId!==0&&this.draftsEnabled&&window.setTimeout(()=>{this.startAutoSave()},1e3),this.draftDisplay.innerHTML=this.draftText,this.setupListeners(),this.setInitialFocus()}setupListeners(){window.$events.listen("editor-save-draft",this.saveDraft.bind(this)),window.$events.listen("editor-save-page",this.savePage.bind(this));let e=()=>{this.autoSave.pendingChange=!0};window.$events.listen("editor-html-change",e),window.$events.listen("editor-markdown-change",e),this.titleElem.addEventListener("input",e);let t=Ne(this.updateChangelogDisplay.bind(this),300,!1);this.changelogInput.addEventListener("input",t),O(this.saveDraftButton,this.saveDraft.bind(this)),O(this.discardDraftButton,this.discardDraft.bind(this)),O(this.deleteDraftButton,this.deleteDraft.bind(this)),O(this.changeEditorButtons,this.changeEditor.bind(this))}setInitialFocus(){if(this.hasDefaultTitle){this.titleElem.select();return}window.setTimeout(()=>{window.$events.emit("editor::focus","")},500)}startAutoSave(){this.autoSave.interval=window.setInterval(this.runAutoSave.bind(this),this.autoSave.frequency)}runAutoSave(){Date.now()-this.autoSave.last{this.draftDisplayIcon.classList.remove("visible")},2e3)}async discardDraft(e=!0){let t;try{t=await window.$http.get(`/ajax/page/${this.pageId}`)}catch(i){console.error(i);return}this.autoSave.interval&&window.clearInterval(this.autoSave.interval),this.draftDisplay.innerText=this.editingPageText,this.discardDraftWrap.toggleAttribute("hidden",!0),window.$events.emit("editor::replace",{html:t.data.html,markdown:t.data.markdown}),this.titleElem.value=t.data.name,window.setTimeout(()=>{this.startAutoSave()},1e3),e&&window.$events.success(this.draftDiscardedText)}async deleteDraft(){if(await window.$components.firstOnElement(this.deleteDraftDialogContainer,"confirm-dialog").show())try{let i=this.discardDraft(!1),r=window.$http.delete(`/page-revisions/user-drafts/${this.pageId}`);await Promise.all([i,r]),window.$events.success(this.draftDeleteText),this.deleteDraftWrap.toggleAttribute("hidden",!0)}catch(i){console.error(i),window.$events.error(this.draftDeleteFailText)}}updateChangelogDisplay(){let e=this.changelogInput.value.trim();e.length===0?e=this.setChangelogText:e.length>16&&(e=`${e.slice(0,16)}...`),this.changelogDisplay.innerText=e}async changeEditor(e){e.preventDefault();let t=e.target.closest("a").href,i=window.$components.firstOnElement(this.switchDialogContainer,"confirm-dialog"),[r,o]=await Promise.all([this.saveDraft(),i.show()]);r&&o&&(window.location=t)}getEditorComponent(){return window.$components.first("markdown-editor")||window.$components.first("wysiwyg-editor")}};function zi(n,e){n.style.display=e?null:"none"}var Hi=class extends g{setup(){this.input=this.$refs.input,this.resetButton=this.$refs.resetButton,this.selectButton=this.$refs.selectButton,this.display=this.$refs.display,this.defaultDisplay=this.$refs.defaultDisplay,this.buttonSep=this.$refs.buttonSeperator,this.value=this.input.value,this.setupListeners()}setupListeners(){this.selectButton.addEventListener("click",this.showPopup.bind(this)),this.display.parentElement.addEventListener("click",this.showPopup.bind(this)),this.resetButton.addEventListener("click",()=>{this.setValue("","")})}showPopup(){window.$components.first("entity-selector-popup").show(t=>{this.setValue(t.id,t.name)})}setValue(e,t){this.value=e,this.input.value=e,this.controlView(t)}controlView(e){let t=this.value&&this.value!==0;if(zi(this.resetButton,t),zi(this.buttonSep,t),zi(this.defaultDisplay,!t),zi(this.display,t),t){let i=this.getAssetIdFromVal();this.display.textContent=`#${i}, ${e}`,this.display.href=window.baseUrl(`/link/${i}`)}}getAssetIdFromVal(){return Number(this.value)}};var Ui=class extends g{setup(){this.container=this.$el,this.cellSelector=this.$opts.cellSelector||"td,th",this.rowSelector=this.$opts.rowSelector||"tr";for(let e of this.$manyRefs.toggleAll||[])e.addEventListener("click",this.toggleAllClick.bind(this));for(let e of this.$manyRefs.toggleRow||[])e.addEventListener("click",this.toggleRowClick.bind(this));for(let e of this.$manyRefs.toggleColumn||[])e.addEventListener("click",this.toggleColumnClick.bind(this))}toggleAllClick(e){e.preventDefault(),this.toggleAllInElement(this.container)}toggleRowClick(e){e.preventDefault(),this.toggleAllInElement(e.target.closest(this.rowSelector))}toggleColumnClick(e){e.preventDefault();let t=e.target.closest(this.cellSelector),i=Array.from(t.parentElement.children).indexOf(t),r=this.container.querySelectorAll(this.rowSelector),o=[];for(let s of r){let a=s.children[i];a&&o.push(...a.querySelectorAll("input[type=checkbox]"))}this.toggleAllInputs(o)}toggleAllInElement(e){let t=e.querySelectorAll("input[type=checkbox]");this.toggleAllInputs(t)}toggleAllInputs(e){let t=e.length>0?e[0].checked:!1;for(let i of e)i.checked=!t,i.dispatchEvent(new Event("change"))}};var ji=class extends g{setup(){this.container=this.$el,this.pointer=this.$refs.pointer,this.linkInput=this.$refs.linkInput,this.linkButton=this.$refs.linkButton,this.includeInput=this.$refs.includeInput,this.includeButton=this.$refs.includeButton,this.sectionModeButton=this.$refs.sectionModeButton,this.modeToggles=this.$manyRefs.modeToggle,this.modeSections=this.$manyRefs.modeSection,this.pageId=this.$opts.pageId,this.showing=!1,this.isSelection=!1,this.setupListeners()}setupListeners(){this.includeButton.addEventListener("click",()=>Vr(this.includeInput.value)),this.linkButton.addEventListener("click",()=>Vr(this.linkInput.value)),O([this.includeInput,this.linkInput],t=>{t.target.select(),t.stopPropagation()}),ln(this.pointer,["click","focus"],t=>{t.stopPropagation()}),ln(document.body,["click","focus"],()=>{!this.showing||this.isSelection||this.hidePointer()}),Jo(this.pointer,this.hidePointer.bind(this));let e=document.querySelector(".page-content");ln(e,["mouseup","keyup"],t=>{t.stopPropagation();let i=t.target.closest('[id^="bkmrk"]');i&&window.getSelection().toString().length>0&&this.showPointerAtTarget(i,t.pageX,!1)}),O(this.sectionModeButton,this.enterSectionSelectMode.bind(this)),O(this.modeToggles,t=>{for(let i of this.modeSections){let r=!i.contains(t.target);i.toggleAttribute("hidden",!r)}this.modeToggles.find(i=>i!==t.target).focus()})}hidePointer(){this.pointer.style.display=null,this.showing=!1}showPointerAtTarget(e,t,i){this.updateForTarget(e),this.pointer.style.display="block";let r=e.getBoundingClientRect(),o=this.pointer.getBoundingClientRect(),a=Math.min(Math.max(t,r.left),r.right)-o.width/2,l=r.top-o.height-16;this.pointer.style.left=`${a}px`,this.pointer.style.top=`${l}px`,this.showing=!0,this.isSelection=!0,setTimeout(()=>{this.isSelection=!1},100);let c=()=>{this.hidePointer(),window.removeEventListener("scroll",c,{passive:!0})};e.parentElement.insertBefore(this.pointer,e),i||window.addEventListener("scroll",c,{passive:!0})}updateForTarget(e){let t=window.baseUrl(`/link/${this.pageId}#${e.id}`),i=`{{@${this.pageId}#${e.id}}}`;this.linkInput.value=t,this.includeInput.value=i;let r=this.pointer.querySelector("#pointer-edit");if(r&&e){let{editHref:o}=r.dataset,s=e.id,a=e.textContent&&e.textContent.substring(0,50);r.href=`${o}?content-id=${s}&content-text=${encodeURIComponent(a)}`}}enterSectionSelectMode(){let e=Array.from(document.querySelectorAll('.page-content [id^="bkmrk"]'));for(let t of e)t.setAttribute("tabindex","0");e[0].focus(),st(e,t=>{this.showPointerAtTarget(t.target,0,!0),this.pointer.focus()})}};var Vi=class extends g{setup(){this.container=this.$el,this.hideButtons=this.$manyRefs.hide||[],this.onkeyup=null,this.onHide=null,this.setupListeners()}setupListeners(){let e=null;this.container.addEventListener("mousedown",t=>{e=t.target}),this.container.addEventListener("click",t=>{t.target===this.container&&e===this.container&&this.hide()}),O(this.hideButtons,()=>this.hide())}hide(e=null){Ls(this.container,120,e),this.onkeyup&&(window.removeEventListener("keyup",this.onkeyup),this.onkeyup=null),this.onHide&&this.onHide()}show(e=null,t=null){Ts(this.container,120,e),this.onkeyup=i=>{i.key==="Escape"&&this.hide()},window.addEventListener("keyup",this.onkeyup),this.onHide=t}};var Wi=class extends g{setup(){this.container=this.$el,this.mode=this.$opts.mode,this.lightContainer=this.$refs.lightContainer,this.darkContainer=this.$refs.darkContainer,this.container.addEventListener("tabs-change",t=>{let r=t.detail.showing==="color-scheme-panel-light"?"light":"dark";this.handleModeChange(r)});let e=t=>{this.updateAppColorsFromInputs(),t.target.name.startsWith("setting-app-color")&&this.updateLightForInput(t.target)};this.container.addEventListener("change",e),this.container.addEventListener("input",e)}handleModeChange(e){this.mode=e;let t=e==="dark";document.documentElement.classList.toggle("dark-mode",t),this.updateAppColorsFromInputs()}updateAppColorsFromInputs(){let t=(this.mode==="dark"?this.darkContainer:this.lightContainer).querySelectorAll('input[type="color"]');for(let i of t){let r=i.name.split("-"),o=r.indexOf("color"),s=r.slice(1,o).join("-");s==="app"&&(s="primary");let a=`--color-${s}`;document.body.style.setProperty(a,i.value)}}updateLightForInput(e){let t=e.name.replace("-color","-color-light"),i=e.value,r=this.hexToRgb(i),o=`rgba(${[r.r,r.g,r.b,"0.15"].join(",")})`,s=this.container.querySelector(`input[name="${t}"][type="hidden"]`);s.value=o}hexToRgb(e){let t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);return{r:t?parseInt(t[1],16):0,g:t?parseInt(t[2],16):0,b:t?parseInt(t[3],16):0}}};var Gi=class extends g{setup(){this.colorInput=this.$refs.input,this.resetButton=this.$refs.resetButton,this.defaultButton=this.$refs.defaultButton,this.currentColor=this.$opts.current,this.defaultColor=this.$opts.default,this.resetButton.addEventListener("click",()=>this.setValue(this.currentColor)),this.defaultButton.addEventListener("click",()=>this.setValue(this.defaultColor))}setValue(e){this.colorInput.value=e,this.colorInput.dispatchEvent(new Event("change",{bubbles:!0}))}};var Ki=class extends g{setup(){this.typeControl=this.$refs.typeControl,this.pagePickerContainer=this.$refs.pagePickerContainer,this.typeControl.addEventListener("change",this.controlPagePickerVisibility.bind(this)),this.controlPagePickerVisibility()}controlPagePickerVisibility(){let e=this.typeControl.value==="page";this.pagePickerContainer.style.display=e?"block":"none"}};var Nf={move_up(n){let e=n.parentNode,t=Array.from(e.children).indexOf(n),i=Math.max(t-1,0);e.insertBefore(n,e.children[i]||null)},move_down(n){let e=n.parentNode,t=Array.from(e.children).indexOf(n),i=Math.min(t+2,e.children.length);e.insertBefore(n,e.children[i]||null)},remove(n,e,t){t.appendChild(n)},add(n,e){e.appendChild(n)}},Zi=class extends g{setup(){this.elem=this.$el,this.input=this.$refs.input,this.shelfBookList=this.$refs.shelfBookList,this.allBookList=this.$refs.allBookList,this.bookSearchInput=this.$refs.bookSearch,this.sortButtonContainer=this.$refs.sortButtonContainer,this.lastSort=null,this.initSortable(),this.setupListeners()}initSortable(){let e=this.elem.querySelectorAll(".scroll-box");for(let t of e)new Ye(t,{group:"shelf-books",ghostClass:"primary-background-light",handle:".handle",animation:150,onSort:this.onChange.bind(this)})}setupListeners(){this.elem.addEventListener("click",e=>{let t=e.target.closest(".scroll-box-item button[data-action]");t&&this.sortItemActionClick(t)}),this.bookSearchInput.addEventListener("input",()=>{this.filterBooksByName(this.bookSearchInput.value)}),this.sortButtonContainer.addEventListener("click",e=>{let t=e.target.closest("button[data-sort]");t&&this.sortShelfBooks(t.dataset.sort)})}filterBooksByName(e){this.allBookList.style.height||(this.allBookList.style.height=`${this.allBookList.getBoundingClientRect().height}px`);let t=this.allBookList.children,i=e.trim().toLowerCase();for(let r of t){let o=!e||r.textContent.toLowerCase().includes(i);r.style.display=o?null:"none"}}sortItemActionClick(e){let t=e.closest(".scroll-box-item"),{action:i}=e.dataset,r=Nf[i];r(t,this.shelfBookList,this.allBookList),this.onChange()}onChange(){let e=Array.from(this.shelfBookList.querySelectorAll("[data-id]"));this.input.value=e.map(t=>t.getAttribute("data-id")).join(",")}sortShelfBooks(e){let t=Array.from(this.shelfBookList.children),i=e===this.lastSort;t.sort((r,o)=>{let s=r.dataset[e].toLowerCase(),a=o.dataset[e].toLowerCase();return i?a.localeCompare(s):s.localeCompare(a)});for(let r of t)this.shelfBookList.append(r);this.lastSort=this.lastSort===e?null:e,this.onChange()}};function zf(n){let e={};for(let[t,i]of Object.entries(n))e[i]=t;return e}var Xi=class extends g{setup(){this.container=this.$el,this.mapById=JSON.parse(this.$opts.keyMap),this.mapByShortcut=zf(this.mapById),this.hintsShowing=!1,this.hideHints=this.hideHints.bind(this),this.hintAbortController=null,this.setupListeners()}setupListeners(){window.addEventListener("keydown",e=>{e.target.closest("input, select, textarea, .cm-editor")||this.handleShortcutPress(e)}),window.addEventListener("keydown",e=>{e.key==="?"&&(this.hintsShowing?this.hideHints():this.showHints())})}handleShortcutPress(e){let i=[e.ctrlKey?"Ctrl":"",e.metaKey?"Cmd":"",e.key].filter(o=>!!o).join(" + "),r=this.mapByShortcut[i];r&&this.runShortcut(r)&&e.preventDefault()}runShortcut(e){let t=this.container.querySelector(`[data-shortcut="${e}"]`);return t?t.matches("input, textarea, select")?(t.focus(),!0):t.matches("a, button")?(t.click(),!0):t.matches("div[tabindex]")?(t.click(),t.focus(),!0):(console.error("Shortcut attempted to be ran for element type that does not have handling setup",t),!1):!1}showHints(){let e=document.createElement("div");e.classList.add("shortcut-container"),this.container.append(e);let t=this.container.querySelectorAll("[data-shortcut]"),i=new Set;for(let o of t){let s=o.getAttribute("data-shortcut");if(i.has(s))continue;let a=this.mapById[s];this.showHintLabel(o,a,e),i.add(s)}this.hintAbortController=new AbortController;let r=this.hintAbortController.signal;window.addEventListener("scroll",this.hideHints,{signal:r}),window.addEventListener("focus",this.hideHints,{signal:r}),window.addEventListener("blur",this.hideHints,{signal:r}),window.addEventListener("click",this.hideHints,{signal:r}),this.hintsShowing=!0}showHintLabel(e,t,i){let r=e.getBoundingClientRect(),o=document.createElement("div");o.classList.add("shortcut-hint"),o.textContent=t;let s=document.createElement("div");s.classList.add("shortcut-linkage"),s.style.left=`${r.x}px`,s.style.top=`${r.y}px`,s.style.width=`${r.width}px`,s.style.height=`${r.height}px`,i.append(o,s);let a=o.getBoundingClientRect();o.style.insetInlineStart=`${r.x+r.width-(a.width+6)}px`,o.style.insetBlockStart=`${r.y+(r.height-a.height)/2}px`}hideHints(){this.container.querySelector(".shortcut-container").remove(),this.hintAbortController?.abort(),this.hintsShowing=!1}};var Hf=["Control","Alt","Shift","Meta","Super"," ","+","Tab","Escape"],Yi=class extends g{setup(){this.input=this.$el,this.setupListeners()}setupListeners(){this.listenerRecordKey=this.listenerRecordKey.bind(this),this.input.addEventListener("focus",()=>{this.startListeningForInput()}),this.input.addEventListener("blur",()=>{this.stopListeningForInput()})}startListeningForInput(){this.input.addEventListener("keydown",this.listenerRecordKey)}listenerRecordKey(e){if(Hf.includes(e.key))return;let t=[e.ctrlKey?"Ctrl":"",e.metaKey?"Cmd":"",e.key];this.input.value=t.filter(i=>!!i).join(" + ")}stopListeningForInput(){this.input.removeEventListener("keydown",this.listenerRecordKey)}};var Ji=class extends g{setup(){this.container=this.$el,this.handleSelector=this.$opts.handleSelector;let e=new Ye(this.container,{handle:this.handleSelector,animation:150,onSort:()=>{this.$emit("sort",{ids:e.toArray()})},setData(t,i){let r=i.getAttribute("data-drag-content");if(r){let o=JSON.parse(r);for(let[s,a]of Object.entries(o))t.setData(s,a)}},revertOnSpill:!0,dropBubble:!0,dragoverBubble:!1})}};var Qi=class extends g{setup(){this.filter=this.$opts.filter,this.$el.addEventListener("change",e=>{if(this.filter&&!e.target.matches(this.filter))return;let t=this.$el.closest("form");t&&t.submit()})}};var er=class extends g{setup(){this.container=this.$el,this.tabList=this.container.querySelector('[role="tablist"]'),this.tabs=Array.from(this.tabList.querySelectorAll('[role="tab"]')),this.panels=Array.from(this.container.querySelectorAll(':scope > [role="tabpanel"], :scope > * > [role="tabpanel"]')),this.activeUnder=this.$opts.activeUnder?Number(this.$opts.activeUnder):1e4,this.active=null,this.container.addEventListener("click",e=>{let t=e.target.closest('[role="tab"]');t&&this.tabs.includes(t)&&this.show(t.getAttribute("aria-controls"))}),window.addEventListener("resize",this.updateActiveState.bind(this),{passive:!0}),this.updateActiveState()}show(e){for(let t of this.panels)t.toggleAttribute("hidden",t.id!==e);for(let t of this.tabs){let r=t.getAttribute("aria-controls")===e;t.setAttribute("aria-selected",r?"true":"false")}this.$emit("change",{showing:e})}updateActiveState(){let e=window.innerWidth!t.hasAttribute("hidden"))||this.panels[0];this.show(e.id),this.tabList.toggleAttribute("hidden",!1)}deactivate(){for(let e of this.panels)e.removeAttribute("hidden");for(let e of this.tabs)e.setAttribute("aria-selected","false");this.tabList.toggleAttribute("hidden",!0)}};var tr=class extends g{setup(){this.addRemoveComponentEl=this.$refs.addRemove,this.container=this.$el,this.rowSelector=this.$opts.rowSelector,this.setupListeners()}setupListeners(){this.container.addEventListener("input",e=>{let t=window.$components.firstOnElement(this.addRemoveComponentEl,"add-remove-rows");!this.hasEmptyRows()&&e.target.value&&t.add()})}hasEmptyRows(){return[...this.container.querySelectorAll(this.rowSelector)].find(i=>[...i.querySelectorAll("input")].filter(r=>r.value).length===0)!==void 0}};var nr=class extends g{setup(){this.container=this.$el,this.list=this.$refs.list,this.searchInput=this.$refs.searchInput,this.searchButton=this.$refs.searchButton,this.searchCancel=this.$refs.searchCancel,this.setupListeners()}setupListeners(){K(this.container,"[template-action]","click",this.handleTemplateActionClick.bind(this)),K(this.container,".pagination a","click",this.handlePaginationClick.bind(this)),K(this.container,".template-item-content","click",this.handleTemplateItemClick.bind(this)),K(this.container,".template-item","dragstart",this.handleTemplateItemDragStart.bind(this)),this.searchInput.addEventListener("keypress",e=>{e.key==="Enter"&&(e.preventDefault(),this.performSearch())}),this.searchButton.addEventListener("click",()=>this.performSearch()),this.searchCancel.addEventListener("click",()=>{this.searchInput.value="",this.performSearch()})}handleTemplateItemClick(e,t){let i=t.closest("[template-id]").getAttribute("template-id");this.insertTemplate(i,"replace")}handleTemplateItemDragStart(e,t){let i=t.closest("[template-id]").getAttribute("template-id");e.dataTransfer.setData("bookstack/template",i),e.dataTransfer.setData("text/plain",i)}handleTemplateActionClick(e,t){e.stopPropagation();let i=t.getAttribute("template-action"),r=t.closest("[template-id]").getAttribute("template-id");this.insertTemplate(r,i)}async insertTemplate(e,t="replace"){let i=await window.$http.get(`/templates/${e}`),r=`editor::${t}`;window.$events.emit(r,i.data)}async handlePaginationClick(e,t){e.preventDefault();let i=t.getAttribute("href"),r=await window.$http.get(i);this.list.innerHTML=r.data}async performSearch(){let e=this.searchInput.value,t=await window.$http.get("/templates",{search:e});this.searchCancel.style.display=e?"block":"none",this.list.innerHTML=t.data}};var ir=class extends g{setup(){this.input=this.$el.querySelector("input[type=hidden]"),this.checkbox=this.$el.querySelector("input[type=checkbox]"),this.checkbox.addEventListener("change",this.stateChange.bind(this))}stateChange(){this.input.value=this.checkbox.checked?"true":"false";let e=new Event("change");this.input.dispatchEvent(e)}};var rr=class extends g{setup(){this.container=this.$refs.container,this.tabs=this.$manyRefs.tab,this.lastLayoutType="none",this.onDestroy=null,this.scrollCache={content:0,info:0},this.lastTabShown="content",this.mobileTabClick=this.mobileTabClick.bind(this),this.updateLayout(),window.addEventListener("resize",()=>{this.updateLayout()},{passive:!0})}updateLayout(){let e="tablet";window.innerWidth<=1e3&&(e="mobile"),window.innerWidth>=1400&&(e="desktop"),e!==this.lastLayoutType&&(this.onDestroy&&(this.onDestroy(),this.onDestroy=null),e==="desktop"?this.setupDesktop():e==="mobile"&&this.setupMobile(),this.lastLayoutType=e)}setupMobile(){for(let e of this.tabs)e.addEventListener("click",this.mobileTabClick);this.onDestroy=()=>{for(let e of this.tabs)e.removeEventListener("click",this.mobileTabClick)}}setupDesktop(){}mobileTabClick(e){let{tab:t}=e.target.dataset;this.showTab(t)}showContent(){this.showTab("content",!1)}showTab(e,t=!0){this.scrollCache[this.lastTabShown]=document.documentElement.scrollTop;for(let r of this.tabs){let o=r.dataset.tab===e;r.setAttribute("aria-selected",o?"true":"false")}let i=e==="info";if(this.container.classList.toggle("show-info",i),t){let o=document.querySelector("header").getBoundingClientRect().bottom;document.documentElement.scrollTop=this.scrollCache[e]||o,setTimeout(()=>{document.documentElement.scrollTop=this.scrollCache[e]||o},50)}this.lastTabShown=e}};var or=class extends g{setup(){this.container=this.$el,this.input=this.$refs.input,this.userInfoContainer=this.$refs.userInfo,K(this.container,"a.dropdown-search-item","click",this.selectUser.bind(this))}selectUser(e,t){e.preventDefault(),this.input.value=t.getAttribute("data-id"),this.userInfoContainer.innerHTML=t.innerHTML,this.input.dispatchEvent(new Event("change",{bubbles:!0})),this.hide()}hide(){window.$components.firstOnElement(this.container,"dropdown").hide()}};var sr=class extends g{setup(){this.checkboxes=this.$el.querySelectorAll('input[type="checkbox"]'),this.allCheckbox=this.$el.querySelector('input[type="checkbox"][value="all"]'),this.$el.addEventListener("change",e=>{e.target.checked&&e.target===this.allCheckbox?this.deselectIndividualEvents():e.target.checked&&(this.allCheckbox.checked=!1)})}deselectIndividualEvents(){for(let e of this.checkboxes)e!==this.allCheckbox&&(e.checked=!1)}};function ou(n){for(let e=1;e<5;e++)n.shortcuts.add(`meta+${e}`,"",["FormatBlock",!1,`h${e+1}`]);n.shortcuts.add("meta+5","",["FormatBlock",!1,"p"]),n.shortcuts.add("meta+d","",["FormatBlock",!1,"p"]),n.shortcuts.add("meta+6","",["FormatBlock",!1,"blockquote"]),n.shortcuts.add("meta+q","",["FormatBlock",!1,"blockquote"]),n.shortcuts.add("meta+7","",["codeeditor",!1,"pre"]),n.shortcuts.add("meta+e","",["codeeditor",!1,"pre"]),n.shortcuts.add("meta+8","",["FormatBlock",!1,"code"]),n.shortcuts.add("meta+shift+E","",["FormatBlock",!1,"code"]),n.shortcuts.add("meta+o","","InsertOrderedList"),n.shortcuts.add("meta+p","","InsertUnorderedList"),n.shortcuts.add("meta+S","",()=>{window.$events.emit("editor-save-draft")}),n.shortcuts.add("meta+13","",()=>{window.$events.emit("editor-save-page")}),n.shortcuts.add("meta+9","",()=>{let e=n.selection.getNode(),t=e?e.closest(".callout"):null,i=["info","success","warning","danger"],o=(i.findIndex(a=>t&&t.classList.contains(a))+1)%i.length,s=i[o];n.formatter.apply(`callout${s}`)}),n.shortcuts.add("meta+shift+K","",()=>{window.$components.first("entity-selector-popup").show(t=>{n.selection.isCollapsed()?n.insertContent(n.dom.createHTML("a",{href:t.link},n.dom.encode(t.name))):n.formatter.apply("link",{href:t.link}),n.selection.collapse(!1),n.focus()})})}function su(n){window.$events.listen("editor::replace",({html:e})=>{n.setContent(e)}),window.$events.listen("editor::append",({html:e})=>{let t=n.getContent()+e;n.setContent(t)}),window.$events.listen("editor::prepend",({html:e})=>{let t=e+n.getContent();n.setContent(t)}),window.$events.listen("editor::insert",({html:e})=>{n.insertContent(e)}),window.$events.listen("editor::focus",()=>{n.initialized&&n.focus()})}function Uf(n,e){let t=n.dom.get(encodeURIComponent(e).replace(/!/g,"%21"));t&&(t.scrollIntoView(),n.selection.select(t,!0),n.selection.collapse(!1),n.focus())}function au(n){let t=new URL(window.location).searchParams.get("content-id");t&&Uf(n,t)}var it,ar;function jf(n){return n&&!!(n.textContent||n.innerText)}async function Vf(n,e){if(n===null||n.type.indexOf("image")!==0)throw new Error("Not an image file");let t=n.name||`image-${Date.now()}.png`,i=new FormData;return i.append("file",n,t),i.append("uploaded_to",e),(await window.$http.post(window.baseUrl("/images/gallery"),i)).data}function lu(n,e,t){let i=new Fe(t.clipboardData||t.dataTransfer);if(!i.hasItems()||i.containsTabularData())return;let r=i.getImages();for(let o of r){let s=`image-${Math.random().toString(16).slice(2)}`,a=window.baseUrl("/loading.gif");t.preventDefault(),setTimeout(()=>{n.insertContent(`

`),Vf(o,e.pageId).then(l=>{let c=l.name.replace(/"/g,""),u=`${c}`,h=n.dom.create("a",{target:"_blank",href:l.url},u);n.dom.replace(h,s)}).catch(l=>{n.dom.remove(s),window.$events.emit("error",e.translations.imageUploadErrorText),console.error(l)})},10)}}function Wf(n){let e=n.selection.getNode();e.nodeName==="IMG"&&(it=n.dom.getParent(e,".mceTemp"),!it&&e.parentNode.nodeName==="A"&&!jf(e.parentNode)&&(it=e.parentNode)),e.hasAttribute("contenteditable")&&e.getAttribute("contenteditable")==="false"&&(ar=e)}function Gf(n,e,t){let{dom:i}=n,r=window.tinymce.dom.RangeUtils.getCaretRangeFromPoint(t.clientX,t.clientY,n.getDoc()),o=t.dataTransfer&&t.dataTransfer.getData("bookstack/template");o&&(t.preventDefault(),window.$http.get(`/templates/${o}`).then(s=>{n.selection.setRng(r),n.undoManager.transact(()=>{n.execCommand("mceInsertContent",!1,s.data.html)})})),i.getParent(r.startContainer,".mceTemp")?t.preventDefault():it&&(t.preventDefault(),n.undoManager.transact(()=>{n.selection.setRng(r),n.selection.setNode(it),i.remove(it)})),!t.isDefaultPrevented()&&ar&&(t.preventDefault(),n.undoManager.transact(()=>{let s=n.selection.getNode(),a=n.selection.getRng(),l=s.closest("body > *");a.startOffset>a.startContainer.length/2?l.after(ar):l.before(ar)})),t.isDefaultPrevented()||lu(n,e,t),it=null}function cu(n,e){n.on("dragstart",()=>Wf(n)),n.on("drop",t=>Gf(n,e,t)),n.on("paste",t=>lu(n,e,t))}function uu(n){return["undo redo","styles","bold italic underline forecolor backcolor formatoverflow","alignleft aligncenter alignright alignjustify","bullist numlist listoverflow",n.textDirection==="rtl"?"ltr rtl":"","link table imagemanager-insert insertoverflow","code about fullscreen"].filter(i=>!!i).join(" | ")}function Kf(n){n.ui.registry.addGroupToolbarButton("formatoverflow",{icon:"more-drawer",tooltip:"More",items:"strikethrough superscript subscript inlinecode removeformat"}),n.ui.registry.addGroupToolbarButton("listoverflow",{icon:"more-drawer",tooltip:"More",items:"tasklist outdent indent"}),n.ui.registry.addGroupToolbarButton("insertoverflow",{icon:"more-drawer",tooltip:"More",items:"customhr codeeditor drawio media details"})}function Zf(n){n.ui.registry.addContextToolbar("linkcontexttoolbar",{predicate(e){return e.closest("a")!==null},position:"node",scope:"node",items:"link unlink openlink"})}function Xf(n){n.ui.registry.addContextToolbar("imagecontexttoolbar",{predicate(e){return e.closest("img")!==null},position:"node",scope:"node",items:"image"})}function hu(n){Kf(n),Zf(n),Xf(n)}var Yf={"table-delete-column":'',"table-delete-row":'',"table-insert-column-after":'',"table-insert-column-before":'',"table-insert-row-above":'',"table-insert-row-after":'',table:'',"table-delete-table":''};function du(n){for(let[e,t]of Object.entries(Yf))n.ui.registry.addIcon(e,t)}function Jf(n){n.serializer.addNodeFilter("br",e=>{for(let t of e)if(t.parent&&t.parent.name==="code"){let i=window.tinymce.html.Node.create("#text");i.value=` +`).length;this.$refs.input.style.height=`${e*20+40}px`}async update(e){e.preventDefault();let t=this.showLoading();this.form.toggleAttribute("hidden",!0);let i={text:this.input.value,parent_id:this.parentId||null};try{let r=await window.$http.put(`/comment/${this.commentId}`,i),o=_e(r.data);this.container.replaceWith(o),window.$events.success(this.updatedText)}catch(r){console.error(r),window.$events.showValidationErrors(r),this.form.toggleAttribute("hidden",!1),t.remove()}}async delete(){this.showLoading(),await window.$http.delete(`/comment/${this.commentId}`),this.container.closest(".comment-branch").remove(),window.$events.success(this.deletedText),this.$emit("delete")}showLoading(){let e=at();return e.classList.add("px-l"),this.container.append(e),e}};var Oi=class extends g{setup(){this.elem=this.$el,this.pageId=Number(this.$opts.pageId),this.container=this.$refs.commentContainer,this.commentCountBar=this.$refs.commentCountBar,this.commentsTitle=this.$refs.commentsTitle,this.addButtonContainer=this.$refs.addButtonContainer,this.replyToRow=this.$refs.replyToRow,this.formContainer=this.$refs.formContainer,this.form=this.$refs.form,this.formInput=this.$refs.formInput,this.formReplyLink=this.$refs.formReplyLink,this.addCommentButton=this.$refs.addCommentButton,this.hideFormButton=this.$refs.hideFormButton,this.removeReplyToButton=this.$refs.removeReplyToButton,this.createdText=this.$opts.createdText,this.countText=this.$opts.countText,this.parentId=null,this.formReplyText=this.formReplyLink?.textContent||"",this.setupListeners()}setupListeners(){this.elem.addEventListener("page-comment-delete",()=>{this.updateCount(),this.hideForm()}),this.elem.addEventListener("page-comment-reply",e=>{this.setReply(e.detail.id,e.detail.element)}),this.form&&(this.removeReplyToButton.addEventListener("click",this.removeReplyTo.bind(this)),this.hideFormButton.addEventListener("click",this.hideForm.bind(this)),this.addCommentButton.addEventListener("click",this.showForm.bind(this)),this.form.addEventListener("submit",this.saveComment.bind(this)))}saveComment(e){e.preventDefault(),e.stopPropagation();let t=at();t.classList.add("px-l"),this.form.after(t),this.form.toggleAttribute("hidden",!0);let r={text:this.formInput.value,parent_id:this.parentId||null};window.$http.post(`/comment/${this.pageId}`,r).then(o=>{let s=_e(o.data);this.formContainer.after(s),window.$events.success(this.createdText),this.hideForm(),this.updateCount()}).catch(o=>{this.form.toggleAttribute("hidden",!1),window.$events.showValidationErrors(o)}),this.form.toggleAttribute("hidden",!1),t.remove()}updateCount(){let e=this.getCommentCount();this.commentsTitle.textContent=window.trans_plural(this.countText,e,{count:e})}resetForm(){this.formInput.value="",this.parentId=null,this.replyToRow.toggleAttribute("hidden",!0),this.container.append(this.formContainer)}showForm(){this.formContainer.toggleAttribute("hidden",!1),this.addButtonContainer.toggleAttribute("hidden",!0),this.formContainer.scrollIntoView({behavior:"smooth",block:"nearest"}),setTimeout(()=>{this.formInput.focus()},100)}hideForm(){this.resetForm(),this.formContainer.toggleAttribute("hidden",!0),this.getCommentCount()>0?this.elem.append(this.addButtonContainer):this.commentCountBar.append(this.addButtonContainer),this.addButtonContainer.toggleAttribute("hidden",!1)}getCommentCount(){return this.container.querySelectorAll('[component="page-comment"]').length}setReply(e,t){t.closest(".comment-branch").querySelector(".comment-branch-children").append(this.formContainer),this.showForm(),this.parentId=e,this.replyToRow.toggleAttribute("hidden",!1),this.formReplyLink.textContent=this.formReplyText.replace("1234",this.parentId),this.formReplyLink.href=`#comment${this.parentId}`}removeReplyTo(){this.parentId=null,this.replyToRow.toggleAttribute("hidden",!0),this.container.append(this.formContainer),this.showForm()}};function Bf(n,e){yr(`#page-navigation a[href="#${n}"]`,t=>{t.closest("li").classList.toggle("current-heading",e)})}function Pf(n){for(let e of n){let t=e.intersectionRatio===1;Bf(e.target.id,t)}}function Of(n){let e={rootMargin:"0px 0px 0px 0px",threshold:1},t=new IntersectionObserver(Pf,e);for(let i of n)t.observe(i)}var Ri=class extends g{setup(){if(this.container=this.$el,this.pageId=this.$opts.pageId,window.importVersioned("code").then(t=>t.highlight()),this.setupNavHighlighting(),this.setupDetailsCodeBlockRefresh(),window.location.hash){let t=window.location.hash.replace(/%20/g," ").substring(1);this.goToText(t)}let e=document.querySelector(".sidebar-page-nav");e&&K(e,"a","click",(t,i)=>{t.preventDefault(),window.$components.first("tri-layout").showContent();let r=i.getAttribute("href").substr(1);this.goToText(r),window.history.pushState(null,null,`#${r}`)})}goToText(e){let t=document.getElementById(e);if(yr(".page-content [data-highlighted]",i=>{i.removeAttribute("data-highlighted"),i.style.backgroundColor=null}),t!==null)kr(t);else{let i=Qo(".page-content > div > *",e);i&&kr(i)}}setupNavHighlighting(){let e=document.querySelector(".sidebar-page-nav"),t=document.querySelector(".page-content").querySelectorAll("h1, h2, h3, h4, h5, h6");t.length>0&&e!==null&&Of(t)}setupDetailsCodeBlockRefresh(){let e=i=>{[...i.target.querySelectorAll(".CodeMirror")].forEach(o=>o.CodeMirror&&o.CodeMirror.refresh())};[...this.container.querySelectorAll("details")].forEach(i=>i.addEventListener("toggle",e))}};function ru(n){let e=new Date(n*1e3),t=e.getHours(),i=e.getMinutes();return`${(t>9?"":"0")+t}:${(i>9?"":"0")+i}`}var Ni=class extends g{setup(){this.draftsEnabled=this.$opts.draftsEnabled==="true",this.editorType=this.$opts.editorType,this.pageId=Number(this.$opts.pageId),this.isNewDraft=this.$opts.pageNewDraft==="true",this.hasDefaultTitle=this.$opts.hasDefaultTitle||!1,this.container=this.$el,this.titleElem=this.$refs.titleContainer.querySelector("input"),this.saveDraftButton=this.$refs.saveDraft,this.discardDraftButton=this.$refs.discardDraft,this.discardDraftWrap=this.$refs.discardDraftWrap,this.deleteDraftButton=this.$refs.deleteDraft,this.deleteDraftWrap=this.$refs.deleteDraftWrap,this.draftDisplay=this.$refs.draftDisplay,this.draftDisplayIcon=this.$refs.draftDisplayIcon,this.changelogInput=this.$refs.changelogInput,this.changelogDisplay=this.$refs.changelogDisplay,this.changeEditorButtons=this.$manyRefs.changeEditor||[],this.switchDialogContainer=this.$refs.switchDialog,this.deleteDraftDialogContainer=this.$refs.deleteDraftDialog,this.draftText=this.$opts.draftText,this.autosaveFailText=this.$opts.autosaveFailText,this.editingPageText=this.$opts.editingPageText,this.draftDiscardedText=this.$opts.draftDiscardedText,this.draftDeleteText=this.$opts.draftDeleteText,this.draftDeleteFailText=this.$opts.draftDeleteFailText,this.setChangelogText=this.$opts.setChangelogText,this.autoSave={interval:null,frequency:3e4,last:0,pendingChange:!1},this.shownWarningsCache=new Set,this.pageId!==0&&this.draftsEnabled&&window.setTimeout(()=>{this.startAutoSave()},1e3),this.draftDisplay.innerHTML=this.draftText,this.setupListeners(),this.setInitialFocus()}setupListeners(){window.$events.listen("editor-save-draft",this.saveDraft.bind(this)),window.$events.listen("editor-save-page",this.savePage.bind(this));let e=()=>{this.autoSave.pendingChange=!0};window.$events.listen("editor-html-change",e),window.$events.listen("editor-markdown-change",e),this.titleElem.addEventListener("input",e);let t=Ne(this.updateChangelogDisplay.bind(this),300,!1);this.changelogInput.addEventListener("input",t),O(this.saveDraftButton,this.saveDraft.bind(this)),O(this.discardDraftButton,this.discardDraft.bind(this)),O(this.deleteDraftButton,this.deleteDraft.bind(this)),O(this.changeEditorButtons,this.changeEditor.bind(this))}setInitialFocus(){if(this.hasDefaultTitle){this.titleElem.select();return}window.setTimeout(()=>{window.$events.emit("editor::focus","")},500)}startAutoSave(){this.autoSave.interval=window.setInterval(this.runAutoSave.bind(this),this.autoSave.frequency)}runAutoSave(){Date.now()-this.autoSave.last{this.draftDisplayIcon.classList.remove("visible")},2e3)}async discardDraft(e=!0){let t;try{t=await window.$http.get(`/ajax/page/${this.pageId}`)}catch(i){console.error(i);return}this.autoSave.interval&&window.clearInterval(this.autoSave.interval),this.draftDisplay.innerText=this.editingPageText,this.discardDraftWrap.toggleAttribute("hidden",!0),window.$events.emit("editor::replace",{html:t.data.html,markdown:t.data.markdown}),this.titleElem.value=t.data.name,window.setTimeout(()=>{this.startAutoSave()},1e3),e&&window.$events.success(this.draftDiscardedText)}async deleteDraft(){if(await window.$components.firstOnElement(this.deleteDraftDialogContainer,"confirm-dialog").show())try{let i=this.discardDraft(!1),r=window.$http.delete(`/page-revisions/user-drafts/${this.pageId}`);await Promise.all([i,r]),window.$events.success(this.draftDeleteText),this.deleteDraftWrap.toggleAttribute("hidden",!0)}catch(i){console.error(i),window.$events.error(this.draftDeleteFailText)}}updateChangelogDisplay(){let e=this.changelogInput.value.trim();e.length===0?e=this.setChangelogText:e.length>16&&(e=`${e.slice(0,16)}...`),this.changelogDisplay.innerText=e}async changeEditor(e){e.preventDefault();let t=e.target.closest("a").href,i=window.$components.firstOnElement(this.switchDialogContainer,"confirm-dialog"),[r,o]=await Promise.all([this.saveDraft(),i.show()]);r&&o&&(window.location=t)}getEditorComponent(){return window.$components.first("markdown-editor")||window.$components.first("wysiwyg-editor")}};function zi(n,e){n.style.display=e?null:"none"}var Hi=class extends g{setup(){this.input=this.$refs.input,this.resetButton=this.$refs.resetButton,this.selectButton=this.$refs.selectButton,this.display=this.$refs.display,this.defaultDisplay=this.$refs.defaultDisplay,this.buttonSep=this.$refs.buttonSeperator,this.value=this.input.value,this.setupListeners()}setupListeners(){this.selectButton.addEventListener("click",this.showPopup.bind(this)),this.display.parentElement.addEventListener("click",this.showPopup.bind(this)),this.resetButton.addEventListener("click",()=>{this.setValue("","")})}showPopup(){window.$components.first("entity-selector-popup").show(t=>{this.setValue(t.id,t.name)})}setValue(e,t){this.value=e,this.input.value=e,this.controlView(t)}controlView(e){let t=this.value&&this.value!==0;if(zi(this.resetButton,t),zi(this.buttonSep,t),zi(this.defaultDisplay,!t),zi(this.display,t),t){let i=this.getAssetIdFromVal();this.display.textContent=`#${i}, ${e}`,this.display.href=window.baseUrl(`/link/${i}`)}}getAssetIdFromVal(){return Number(this.value)}};var Ui=class extends g{setup(){this.container=this.$el,this.cellSelector=this.$opts.cellSelector||"td,th",this.rowSelector=this.$opts.rowSelector||"tr";for(let e of this.$manyRefs.toggleAll||[])e.addEventListener("click",this.toggleAllClick.bind(this));for(let e of this.$manyRefs.toggleRow||[])e.addEventListener("click",this.toggleRowClick.bind(this));for(let e of this.$manyRefs.toggleColumn||[])e.addEventListener("click",this.toggleColumnClick.bind(this))}toggleAllClick(e){e.preventDefault(),this.toggleAllInElement(this.container)}toggleRowClick(e){e.preventDefault(),this.toggleAllInElement(e.target.closest(this.rowSelector))}toggleColumnClick(e){e.preventDefault();let t=e.target.closest(this.cellSelector),i=Array.from(t.parentElement.children).indexOf(t),r=this.container.querySelectorAll(this.rowSelector),o=[];for(let s of r){let a=s.children[i];a&&o.push(...a.querySelectorAll("input[type=checkbox]"))}this.toggleAllInputs(o)}toggleAllInElement(e){let t=e.querySelectorAll("input[type=checkbox]");this.toggleAllInputs(t)}toggleAllInputs(e){let t=e.length>0?e[0].checked:!1;for(let i of e)i.checked=!t,i.dispatchEvent(new Event("change"))}};var ji=class extends g{setup(){this.container=this.$el,this.pointer=this.$refs.pointer,this.linkInput=this.$refs.linkInput,this.linkButton=this.$refs.linkButton,this.includeInput=this.$refs.includeInput,this.includeButton=this.$refs.includeButton,this.sectionModeButton=this.$refs.sectionModeButton,this.modeToggles=this.$manyRefs.modeToggle,this.modeSections=this.$manyRefs.modeSection,this.pageId=this.$opts.pageId,this.showing=!1,this.isSelection=!1,this.setupListeners()}setupListeners(){this.includeButton.addEventListener("click",()=>Vr(this.includeInput.value)),this.linkButton.addEventListener("click",()=>Vr(this.linkInput.value)),O([this.includeInput,this.linkInput],t=>{t.target.select(),t.stopPropagation()}),ln(this.pointer,["click","focus"],t=>{t.stopPropagation()}),ln(document.body,["click","focus"],()=>{!this.showing||this.isSelection||this.hidePointer()}),Jo(this.pointer,this.hidePointer.bind(this));let e=document.querySelector(".page-content");ln(e,["mouseup","keyup"],t=>{t.stopPropagation();let i=t.target.closest('[id^="bkmrk"]');i&&window.getSelection().toString().length>0&&this.showPointerAtTarget(i,t.pageX,!1)}),O(this.sectionModeButton,this.enterSectionSelectMode.bind(this)),O(this.modeToggles,t=>{for(let i of this.modeSections){let r=!i.contains(t.target);i.toggleAttribute("hidden",!r)}this.modeToggles.find(i=>i!==t.target).focus()})}hidePointer(){this.pointer.style.display=null,this.showing=!1}showPointerAtTarget(e,t,i){this.updateForTarget(e),this.pointer.style.display="block";let r=e.getBoundingClientRect(),o=this.pointer.getBoundingClientRect(),a=Math.min(Math.max(t,r.left),r.right)-o.width/2,l=r.top-o.height-16;this.pointer.style.left=`${a}px`,this.pointer.style.top=`${l}px`,this.showing=!0,this.isSelection=!0,setTimeout(()=>{this.isSelection=!1},100);let c=()=>{this.hidePointer(),window.removeEventListener("scroll",c,{passive:!0})};e.parentElement.insertBefore(this.pointer,e),i||window.addEventListener("scroll",c,{passive:!0})}updateForTarget(e){let t=window.baseUrl(`/link/${this.pageId}#${e.id}`),i=`{{@${this.pageId}#${e.id}}}`;this.linkInput.value=t,this.includeInput.value=i;let r=this.pointer.querySelector("#pointer-edit");if(r&&e){let{editHref:o}=r.dataset,s=e.id,a=e.textContent&&e.textContent.substring(0,50);r.href=`${o}?content-id=${s}&content-text=${encodeURIComponent(a)}`}}enterSectionSelectMode(){let e=Array.from(document.querySelectorAll('.page-content [id^="bkmrk"]'));for(let t of e)t.setAttribute("tabindex","0");e[0].focus(),st(e,t=>{this.showPointerAtTarget(t.target,0,!0),this.pointer.focus()})}};var Vi=class extends g{setup(){this.container=this.$el,this.hideButtons=this.$manyRefs.hide||[],this.onkeyup=null,this.onHide=null,this.setupListeners()}setupListeners(){let e=null;this.container.addEventListener("mousedown",t=>{e=t.target}),this.container.addEventListener("click",t=>{t.target===this.container&&e===this.container&&this.hide()}),O(this.hideButtons,()=>this.hide())}hide(e=null){Ls(this.container,120,e),this.onkeyup&&(window.removeEventListener("keyup",this.onkeyup),this.onkeyup=null),this.onHide&&this.onHide()}show(e=null,t=null){Ts(this.container,120,e),this.onkeyup=i=>{i.key==="Escape"&&this.hide()},window.addEventListener("keyup",this.onkeyup),this.onHide=t}};var Wi=class extends g{setup(){this.container=this.$el,this.mode=this.$opts.mode,this.lightContainer=this.$refs.lightContainer,this.darkContainer=this.$refs.darkContainer,this.container.addEventListener("tabs-change",t=>{let r=t.detail.showing==="color-scheme-panel-light"?"light":"dark";this.handleModeChange(r)});let e=t=>{this.updateAppColorsFromInputs(),t.target.name.startsWith("setting-app-color")&&this.updateLightForInput(t.target)};this.container.addEventListener("change",e),this.container.addEventListener("input",e)}handleModeChange(e){this.mode=e;let t=e==="dark";document.documentElement.classList.toggle("dark-mode",t),this.updateAppColorsFromInputs()}updateAppColorsFromInputs(){let t=(this.mode==="dark"?this.darkContainer:this.lightContainer).querySelectorAll('input[type="color"]');for(let i of t){let r=i.name.split("-"),o=r.indexOf("color"),s=r.slice(1,o).join("-");s==="app"&&(s="primary");let a=`--color-${s}`;document.body.style.setProperty(a,i.value)}}updateLightForInput(e){let t=e.name.replace("-color","-color-light"),i=e.value,r=this.hexToRgb(i),o=`rgba(${[r.r,r.g,r.b,"0.15"].join(",")})`,s=this.container.querySelector(`input[name="${t}"][type="hidden"]`);s.value=o}hexToRgb(e){let t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);return{r:t?parseInt(t[1],16):0,g:t?parseInt(t[2],16):0,b:t?parseInt(t[3],16):0}}};var Gi=class extends g{setup(){this.colorInput=this.$refs.input,this.resetButton=this.$refs.resetButton,this.defaultButton=this.$refs.defaultButton,this.currentColor=this.$opts.current,this.defaultColor=this.$opts.default,this.resetButton.addEventListener("click",()=>this.setValue(this.currentColor)),this.defaultButton.addEventListener("click",()=>this.setValue(this.defaultColor))}setValue(e){this.colorInput.value=e,this.colorInput.dispatchEvent(new Event("change",{bubbles:!0}))}};var Ki=class extends g{setup(){this.typeControl=this.$refs.typeControl,this.pagePickerContainer=this.$refs.pagePickerContainer,this.typeControl.addEventListener("change",this.controlPagePickerVisibility.bind(this)),this.controlPagePickerVisibility()}controlPagePickerVisibility(){let e=this.typeControl.value==="page";this.pagePickerContainer.style.display=e?"block":"none"}};var Nf={move_up(n){let e=n.parentNode,t=Array.from(e.children).indexOf(n),i=Math.max(t-1,0);e.insertBefore(n,e.children[i]||null)},move_down(n){let e=n.parentNode,t=Array.from(e.children).indexOf(n),i=Math.min(t+2,e.children.length);e.insertBefore(n,e.children[i]||null)},remove(n,e,t){t.appendChild(n)},add(n,e){e.appendChild(n)}},Zi=class extends g{setup(){this.elem=this.$el,this.input=this.$refs.input,this.shelfBookList=this.$refs.shelfBookList,this.allBookList=this.$refs.allBookList,this.bookSearchInput=this.$refs.bookSearch,this.sortButtonContainer=this.$refs.sortButtonContainer,this.lastSort=null,this.initSortable(),this.setupListeners()}initSortable(){let e=this.elem.querySelectorAll(".scroll-box");for(let t of e)new Ye(t,{group:"shelf-books",ghostClass:"primary-background-light",handle:".handle",animation:150,onSort:this.onChange.bind(this)})}setupListeners(){this.elem.addEventListener("click",e=>{let t=e.target.closest(".scroll-box-item button[data-action]");t&&this.sortItemActionClick(t)}),this.bookSearchInput.addEventListener("input",()=>{this.filterBooksByName(this.bookSearchInput.value)}),this.sortButtonContainer.addEventListener("click",e=>{let t=e.target.closest("button[data-sort]");t&&this.sortShelfBooks(t.dataset.sort)})}filterBooksByName(e){this.allBookList.style.height||(this.allBookList.style.height=`${this.allBookList.getBoundingClientRect().height}px`);let t=this.allBookList.children,i=e.trim().toLowerCase();for(let r of t){let o=!e||r.textContent.toLowerCase().includes(i);r.style.display=o?null:"none"}}sortItemActionClick(e){let t=e.closest(".scroll-box-item"),{action:i}=e.dataset,r=Nf[i];r(t,this.shelfBookList,this.allBookList),this.onChange()}onChange(){let e=Array.from(this.shelfBookList.querySelectorAll("[data-id]"));this.input.value=e.map(t=>t.getAttribute("data-id")).join(",")}sortShelfBooks(e){let t=Array.from(this.shelfBookList.children),i=e===this.lastSort;t.sort((r,o)=>{let s=r.dataset[e].toLowerCase(),a=o.dataset[e].toLowerCase();return i?a.localeCompare(s):s.localeCompare(a)});for(let r of t)this.shelfBookList.append(r);this.lastSort=this.lastSort===e?null:e,this.onChange()}};function zf(n){let e={};for(let[t,i]of Object.entries(n))e[i]=t;return e}var Xi=class extends g{setup(){this.container=this.$el,this.mapById=JSON.parse(this.$opts.keyMap),this.mapByShortcut=zf(this.mapById),this.hintsShowing=!1,this.hideHints=this.hideHints.bind(this),this.hintAbortController=null,this.setupListeners()}setupListeners(){window.addEventListener("keydown",e=>{e.target.closest("input, select, textarea, .cm-editor")||this.handleShortcutPress(e)}),window.addEventListener("keydown",e=>{e.key==="?"&&(this.hintsShowing?this.hideHints():this.showHints())})}handleShortcutPress(e){let i=[e.ctrlKey?"Ctrl":"",e.metaKey?"Cmd":"",e.key].filter(o=>!!o).join(" + "),r=this.mapByShortcut[i];r&&this.runShortcut(r)&&e.preventDefault()}runShortcut(e){let t=this.container.querySelector(`[data-shortcut="${e}"]`);return t?t.matches("input, textarea, select")?(t.focus(),!0):t.matches("a, button")?(t.click(),!0):t.matches("div[tabindex]")?(t.click(),t.focus(),!0):(console.error("Shortcut attempted to be ran for element type that does not have handling setup",t),!1):!1}showHints(){let e=document.createElement("div");e.classList.add("shortcut-container"),this.container.append(e);let t=this.container.querySelectorAll("[data-shortcut]"),i=new Set;for(let o of t){let s=o.getAttribute("data-shortcut");if(i.has(s))continue;let a=this.mapById[s];this.showHintLabel(o,a,e),i.add(s)}this.hintAbortController=new AbortController;let r=this.hintAbortController.signal;window.addEventListener("scroll",this.hideHints,{signal:r}),window.addEventListener("focus",this.hideHints,{signal:r}),window.addEventListener("blur",this.hideHints,{signal:r}),window.addEventListener("click",this.hideHints,{signal:r}),this.hintsShowing=!0}showHintLabel(e,t,i){let r=e.getBoundingClientRect(),o=document.createElement("div");o.classList.add("shortcut-hint"),o.textContent=t;let s=document.createElement("div");s.classList.add("shortcut-linkage"),s.style.left=`${r.x}px`,s.style.top=`${r.y}px`,s.style.width=`${r.width}px`,s.style.height=`${r.height}px`,i.append(o,s);let a=o.getBoundingClientRect();o.style.insetInlineStart=`${r.x+r.width-(a.width+6)}px`,o.style.insetBlockStart=`${r.y+(r.height-a.height)/2}px`}hideHints(){this.container.querySelector(".shortcut-container").remove(),this.hintAbortController?.abort(),this.hintsShowing=!1}};var Hf=["Control","Alt","Shift","Meta","Super"," ","+","Tab","Escape"],Yi=class extends g{setup(){this.input=this.$el,this.setupListeners()}setupListeners(){this.listenerRecordKey=this.listenerRecordKey.bind(this),this.input.addEventListener("focus",()=>{this.startListeningForInput()}),this.input.addEventListener("blur",()=>{this.stopListeningForInput()})}startListeningForInput(){this.input.addEventListener("keydown",this.listenerRecordKey)}listenerRecordKey(e){if(Hf.includes(e.key))return;let t=[e.ctrlKey?"Ctrl":"",e.metaKey?"Cmd":"",e.key];this.input.value=t.filter(i=>!!i).join(" + ")}stopListeningForInput(){this.input.removeEventListener("keydown",this.listenerRecordKey)}};var Ji=class extends g{setup(){this.container=this.$el,this.handleSelector=this.$opts.handleSelector;let e=new Ye(this.container,{handle:this.handleSelector,animation:150,onSort:()=>{this.$emit("sort",{ids:e.toArray()})},setData(t,i){let r=i.getAttribute("data-drag-content");if(r){let o=JSON.parse(r);for(let[s,a]of Object.entries(o))t.setData(s,a)}},revertOnSpill:!0,dropBubble:!0,dragoverBubble:!1})}};var Qi=class extends g{setup(){this.filter=this.$opts.filter,this.$el.addEventListener("change",e=>{if(this.filter&&!e.target.matches(this.filter))return;let t=this.$el.closest("form");t&&t.submit()})}};var er=class extends g{setup(){this.container=this.$el,this.tabList=this.container.querySelector('[role="tablist"]'),this.tabs=Array.from(this.tabList.querySelectorAll('[role="tab"]')),this.panels=Array.from(this.container.querySelectorAll(':scope > [role="tabpanel"], :scope > * > [role="tabpanel"]')),this.activeUnder=this.$opts.activeUnder?Number(this.$opts.activeUnder):1e4,this.active=null,this.container.addEventListener("click",e=>{let t=e.target.closest('[role="tab"]');t&&this.tabs.includes(t)&&this.show(t.getAttribute("aria-controls"))}),window.addEventListener("resize",this.updateActiveState.bind(this),{passive:!0}),this.updateActiveState()}show(e){for(let t of this.panels)t.toggleAttribute("hidden",t.id!==e);for(let t of this.tabs){let r=t.getAttribute("aria-controls")===e;t.setAttribute("aria-selected",r?"true":"false")}this.$emit("change",{showing:e})}updateActiveState(){let e=window.innerWidth!t.hasAttribute("hidden"))||this.panels[0];this.show(e.id),this.tabList.toggleAttribute("hidden",!1)}deactivate(){for(let e of this.panels)e.removeAttribute("hidden");for(let e of this.tabs)e.setAttribute("aria-selected","false");this.tabList.toggleAttribute("hidden",!0)}};var tr=class extends g{setup(){this.addRemoveComponentEl=this.$refs.addRemove,this.container=this.$el,this.rowSelector=this.$opts.rowSelector,this.setupListeners()}setupListeners(){this.container.addEventListener("input",e=>{let t=window.$components.firstOnElement(this.addRemoveComponentEl,"add-remove-rows");!this.hasEmptyRows()&&e.target.value&&t.add()})}hasEmptyRows(){return[...this.container.querySelectorAll(this.rowSelector)].find(i=>[...i.querySelectorAll("input")].filter(r=>r.value).length===0)!==void 0}};var nr=class extends g{setup(){this.container=this.$el,this.list=this.$refs.list,this.searchInput=this.$refs.searchInput,this.searchButton=this.$refs.searchButton,this.searchCancel=this.$refs.searchCancel,this.setupListeners()}setupListeners(){K(this.container,"[template-action]","click",this.handleTemplateActionClick.bind(this)),K(this.container,".pagination a","click",this.handlePaginationClick.bind(this)),K(this.container,".template-item-content","click",this.handleTemplateItemClick.bind(this)),K(this.container,".template-item","dragstart",this.handleTemplateItemDragStart.bind(this)),this.searchInput.addEventListener("keypress",e=>{e.key==="Enter"&&(e.preventDefault(),this.performSearch())}),this.searchButton.addEventListener("click",()=>this.performSearch()),this.searchCancel.addEventListener("click",()=>{this.searchInput.value="",this.performSearch()})}handleTemplateItemClick(e,t){let i=t.closest("[template-id]").getAttribute("template-id");this.insertTemplate(i,"replace")}handleTemplateItemDragStart(e,t){let i=t.closest("[template-id]").getAttribute("template-id");e.dataTransfer.setData("bookstack/template",i),e.dataTransfer.setData("text/plain",i)}handleTemplateActionClick(e,t){e.stopPropagation();let i=t.getAttribute("template-action"),r=t.closest("[template-id]").getAttribute("template-id");this.insertTemplate(r,i)}async insertTemplate(e,t="replace"){let i=await window.$http.get(`/templates/${e}`),r=`editor::${t}`;window.$events.emit(r,i.data)}async handlePaginationClick(e,t){e.preventDefault();let i=t.getAttribute("href"),r=await window.$http.get(i);this.list.innerHTML=r.data}async performSearch(){let e=this.searchInput.value,t=await window.$http.get("/templates",{search:e});this.searchCancel.style.display=e?"block":"none",this.list.innerHTML=t.data}};var ir=class extends g{setup(){this.input=this.$el.querySelector("input[type=hidden]"),this.checkbox=this.$el.querySelector("input[type=checkbox]"),this.checkbox.addEventListener("change",this.stateChange.bind(this))}stateChange(){this.input.value=this.checkbox.checked?"true":"false";let e=new Event("change");this.input.dispatchEvent(e)}};var rr=class extends g{setup(){this.container=this.$refs.container,this.tabs=this.$manyRefs.tab,this.lastLayoutType="none",this.onDestroy=null,this.scrollCache={content:0,info:0},this.lastTabShown="content",this.mobileTabClick=this.mobileTabClick.bind(this),this.updateLayout(),window.addEventListener("resize",()=>{this.updateLayout()},{passive:!0})}updateLayout(){let e="tablet";window.innerWidth<=1e3&&(e="mobile"),window.innerWidth>=1400&&(e="desktop"),e!==this.lastLayoutType&&(this.onDestroy&&(this.onDestroy(),this.onDestroy=null),e==="desktop"?this.setupDesktop():e==="mobile"&&this.setupMobile(),this.lastLayoutType=e)}setupMobile(){for(let e of this.tabs)e.addEventListener("click",this.mobileTabClick);this.onDestroy=()=>{for(let e of this.tabs)e.removeEventListener("click",this.mobileTabClick)}}setupDesktop(){}mobileTabClick(e){let{tab:t}=e.target.dataset;this.showTab(t)}showContent(){this.showTab("content",!1)}showTab(e,t=!0){this.scrollCache[this.lastTabShown]=document.documentElement.scrollTop;for(let r of this.tabs){let o=r.dataset.tab===e;r.setAttribute("aria-selected",o?"true":"false")}let i=e==="info";if(this.container.classList.toggle("show-info",i),t){let o=document.querySelector("header").getBoundingClientRect().bottom;document.documentElement.scrollTop=this.scrollCache[e]||o,setTimeout(()=>{document.documentElement.scrollTop=this.scrollCache[e]||o},50)}this.lastTabShown=e}};var or=class extends g{setup(){this.container=this.$el,this.input=this.$refs.input,this.userInfoContainer=this.$refs.userInfo,K(this.container,"a.dropdown-search-item","click",this.selectUser.bind(this))}selectUser(e,t){e.preventDefault(),this.input.value=t.getAttribute("data-id"),this.userInfoContainer.innerHTML=t.innerHTML,this.input.dispatchEvent(new Event("change",{bubbles:!0})),this.hide()}hide(){window.$components.firstOnElement(this.container,"dropdown").hide()}};var sr=class extends g{setup(){this.checkboxes=this.$el.querySelectorAll('input[type="checkbox"]'),this.allCheckbox=this.$el.querySelector('input[type="checkbox"][value="all"]'),this.$el.addEventListener("change",e=>{e.target.checked&&e.target===this.allCheckbox?this.deselectIndividualEvents():e.target.checked&&(this.allCheckbox.checked=!1)})}deselectIndividualEvents(){for(let e of this.checkboxes)e!==this.allCheckbox&&(e.checked=!1)}};function ou(n){for(let e=1;e<5;e++)n.shortcuts.add(`meta+${e}`,"",["FormatBlock",!1,`h${e+1}`]);n.shortcuts.add("meta+5","",["FormatBlock",!1,"p"]),n.shortcuts.add("meta+d","",["FormatBlock",!1,"p"]),n.shortcuts.add("meta+6","",["FormatBlock",!1,"blockquote"]),n.shortcuts.add("meta+q","",["FormatBlock",!1,"blockquote"]),n.shortcuts.add("meta+7","",["codeeditor",!1,"pre"]),n.shortcuts.add("meta+e","",["codeeditor",!1,"pre"]),n.shortcuts.add("meta+8","",["FormatBlock",!1,"code"]),n.shortcuts.add("meta+shift+E","",["FormatBlock",!1,"code"]),n.shortcuts.add("meta+o","","InsertOrderedList"),n.shortcuts.add("meta+p","","InsertUnorderedList"),n.shortcuts.add("meta+S","",()=>{window.$events.emit("editor-save-draft")}),n.shortcuts.add("meta+13","",()=>{window.$events.emit("editor-save-page")}),n.shortcuts.add("meta+9","",()=>{let e=n.selection.getNode(),t=e?e.closest(".callout"):null,i=["info","success","warning","danger"],o=(i.findIndex(a=>t&&t.classList.contains(a))+1)%i.length,s=i[o];n.formatter.apply(`callout${s}`)}),n.shortcuts.add("meta+shift+K","",()=>{window.$components.first("entity-selector-popup").show(t=>{n.selection.isCollapsed()?n.insertContent(n.dom.createHTML("a",{href:t.link},n.dom.encode(t.name))):n.formatter.apply("link",{href:t.link}),n.selection.collapse(!1),n.focus()})})}function su(n){window.$events.listen("editor::replace",({html:e})=>{n.setContent(e)}),window.$events.listen("editor::append",({html:e})=>{let t=n.getContent()+e;n.setContent(t)}),window.$events.listen("editor::prepend",({html:e})=>{let t=e+n.getContent();n.setContent(t)}),window.$events.listen("editor::insert",({html:e})=>{n.insertContent(e)}),window.$events.listen("editor::focus",()=>{n.initialized&&n.focus()})}function Uf(n,e){let t=n.dom.get(encodeURIComponent(e).replace(/!/g,"%21"));t&&(t.scrollIntoView(),n.selection.select(t,!0),n.selection.collapse(!1),n.focus())}function au(n){let t=new URL(window.location).searchParams.get("content-id");t&&Uf(n,t)}var it,ar;function jf(n){return n&&!!(n.textContent||n.innerText)}async function Vf(n,e){if(n===null||n.type.indexOf("image")!==0)throw new Error("Not an image file");let t=n.name||`image-${Date.now()}.png`,i=new FormData;return i.append("file",n,t),i.append("uploaded_to",e),(await window.$http.post(window.baseUrl("/images/gallery"),i)).data}function lu(n,e,t){let i=new Fe(t.clipboardData||t.dataTransfer);if(!i.hasItems()||i.containsTabularData())return;let r=i.getImages();for(let o of r){let s=`image-${Math.random().toString(16).slice(2)}`,a=window.baseUrl("/loading.gif");t.preventDefault(),setTimeout(()=>{n.insertContent(`

`),Vf(o,e.pageId).then(l=>{let c=l.name.replace(/"/g,""),u=`${c}`,h=n.dom.create("a",{target:"_blank",href:l.url},u);n.dom.replace(h,s)}).catch(l=>{n.dom.remove(s),window.$events.emit("error",e.translations.imageUploadErrorText),console.error(l)})},10)}}function Wf(n){let e=n.selection.getNode();e.nodeName==="IMG"&&(it=n.dom.getParent(e,".mceTemp"),!it&&e.parentNode.nodeName==="A"&&!jf(e.parentNode)&&(it=e.parentNode)),e.hasAttribute("contenteditable")&&e.getAttribute("contenteditable")==="false"&&(ar=e)}function Gf(n,e,t){let{dom:i}=n,r=window.tinymce.dom.RangeUtils.getCaretRangeFromPoint(t.clientX,t.clientY,n.getDoc()),o=t.dataTransfer&&t.dataTransfer.getData("bookstack/template");o&&(t.preventDefault(),window.$http.get(`/templates/${o}`).then(s=>{n.selection.setRng(r),n.undoManager.transact(()=>{n.execCommand("mceInsertContent",!1,s.data.html)})})),i.getParent(r.startContainer,".mceTemp")?t.preventDefault():it&&(t.preventDefault(),n.undoManager.transact(()=>{n.selection.setRng(r),n.selection.setNode(it),i.remove(it)})),!t.isDefaultPrevented()&&ar&&(t.preventDefault(),n.undoManager.transact(()=>{let s=n.selection.getNode(),a=n.selection.getRng(),l=s.closest("body > *");a.startOffset>a.startContainer.length/2?l.after(ar):l.before(ar)})),t.isDefaultPrevented()||lu(n,e,t),it=null}function cu(n,e){n.on("dragstart",()=>Wf(n)),n.on("drop",t=>Gf(n,e,t)),n.on("paste",t=>lu(n,e,t))}function uu(n){return["undo redo","styles","bold italic underline forecolor backcolor formatoverflow","alignleft aligncenter alignright alignjustify","bullist numlist listoverflow",n.textDirection==="rtl"?"ltr rtl":"","link table imagemanager-insert insertoverflow","code about fullscreen"].filter(i=>!!i).join(" | ")}function Kf(n){n.ui.registry.addGroupToolbarButton("formatoverflow",{icon:"more-drawer",tooltip:"More",items:"strikethrough superscript subscript inlinecode removeformat"}),n.ui.registry.addGroupToolbarButton("listoverflow",{icon:"more-drawer",tooltip:"More",items:"tasklist outdent indent"}),n.ui.registry.addGroupToolbarButton("insertoverflow",{icon:"more-drawer",tooltip:"More",items:"customhr codeeditor drawio media details"})}function Zf(n){n.ui.registry.addContextToolbar("linkcontexttoolbar",{predicate(e){return e.closest("a")!==null},position:"node",scope:"node",items:"link unlink openlink"})}function Xf(n){n.ui.registry.addContextToolbar("imagecontexttoolbar",{predicate(e){return e.closest("img")!==null},position:"node",scope:"node",items:"image"})}function hu(n){Kf(n),Zf(n),Xf(n)}var Yf={"table-delete-column":'',"table-delete-row":'',"table-insert-column-after":'',"table-insert-column-before":'',"table-insert-row-above":'',"table-insert-row-after":'',table:'',"table-delete-table":''};function du(n){for(let[e,t]of Object.entries(Yf))n.ui.registry.addIcon(e,t)}function Jf(n){n.serializer.addNodeFilter("br",e=>{for(let t of e)if(t.parent&&t.parent.name==="code"){let i=window.tinymce.html.Node.create("#text");i.value=` `,t.replace(i)}})}function Qf(n){n.parser.addNodeFilter("div",e=>{for(let t of e){let i=t.attr("id")||"",r=t.attr("class")||"";(i==="pointer"||r.includes("pointer"))&&t.remove()}})}function pu(n){Jf(n),Qf(n)}function fu(n){return n.tagName.toLowerCase()==="code-block"}function gu(n,e,t,i){let r=window.$components.first("code-editor"),o=n.selection.getBookmark();r.open(e,t,(s,a)=>{i(s,a),n.focus(),n.selection.moveToBookmark(o)},()=>{n.focus(),n.selection.moveToBookmark(o)})}function mu(n,e){gu(n,e.getContent(),e.getLanguage(),(t,i)=>{e.setContent(t,i)})}function em(n){let e=n.getDoc(),t=e.defaultView;class i extends t.HTMLElement{constructor(){super();se(this,"editor",null);this.attachShadow({mode:"open"});let s=document.head.querySelectorAll('link[rel="stylesheet"]:not([media="print"]),style'),a=Array.from(s).map(c=>c.cloneNode(!0)),l=document.createElement("div");l.style.pointerEvents="none",l.contentEditable="false",l.classList.add("CodeMirrorContainer"),l.classList.toggle("dark-mode",document.documentElement.classList.contains("dark-mode")),this.shadowRoot.append(...a,l)}getLanguage(){let s=c=>(c.split(" ").filter(h=>h.startsWith("language-"))[0]||"").replace("language-",""),a=this.querySelector("code"),l=this.querySelector("pre");return s(l.className)||a&&s(a.className)||""}setContent(s,a){this.editor&&(this.editor.setContent(s),this.editor.setMode(a,s));let l=this.querySelector("pre");l||(l=e.createElement("pre"),this.append(l)),l.innerHTML="";let c=e.createElement("code");l.append(c),c.innerText=s,c.className=`language-${a}`}getContent(){let s=this.querySelector("code")||this.querySelector("pre"),a=document.createElement("pre");a.innerHTML=s.innerHTML.replace(/\ufeff/g,"");let l=a.querySelectorAll("br");for(let c of l)c.replaceWith(` `);return a.textContent}connectedCallback(){let s=Date.now();if(this.editor)return;this.cleanChildContent();let a=this.getContent(),c=a.split(` `).length*19.2+18+24;this.style.height=`${c}px`;let u=this.shadowRoot.querySelector(".CodeMirrorContainer"),h=d=>{this.editor=d.wysiwygView(u,this.shadowRoot,a,this.getLanguage()),setTimeout(()=>{this.style.height=null},12)};window.importVersioned("code").then(d=>{let p=Date.now()-s<20?20:0;setTimeout(()=>h(d),p)})}cleanChildContent(){let s=this.querySelector("pre");if(s)for(let a of s.childNodes)a.nodeName==="#text"&&a.textContent==="\uFEFF"&&a.remove()}}t.customElements.define("code-block",i)}function tm(n){n.ui.registry.addIcon("codeblock",''),n.ui.registry.addButton("codeeditor",{tooltip:"Insert code block",icon:"codeblock",onAction(){n.execCommand("codeeditor")}}),n.ui.registry.addButton("editcodeeditor",{tooltip:"Edit code block",icon:"edit-block",onAction(){n.execCommand("codeeditor")}}),n.addCommand("codeeditor",()=>{let e=n.selection.getNode(),t=e.ownerDocument;if(fu(e))mu(n,e);else{let i=n.selection.getContent({format:"text"});gu(n,i,"",(r,o)=>{let s=t.createElement("pre"),a=t.createElement("code");a.classList.add(`language-${o}`),a.innerText=r,s.append(a),n.insertContent(s.outerHTML)})}}),n.on("dblclick",()=>{let e=n.selection.getNode();fu(e)&&mu(n,e)}),n.on("PreInit",()=>{n.parser.addNodeFilter("pre",e=>{for(let t of e){let i=window.tinymce.html.Node.create("code-block",{contenteditable:"false"}),r=t.getAll("span");for(let o of r)o.unwrap();t.attr("style",null),t.wrap(i)}}),n.parser.addNodeFilter("code-block",e=>{for(let t of e)t.attr("contenteditable","false")}),n.serializer.addNodeFilter("code-block",e=>{for(let t of e)t.unwrap()})}),n.ui.registry.addContextToolbar("codeeditor",{predicate(e){return e.nodeName.toLowerCase()==="code-block"},items:"editcodeeditor",position:"node",scope:"node"}),n.on("PreInit",()=>{em(n)})}function bu(){return tm}var de=null,ot=null,rt={};function zo(n){return n.hasAttribute("drawio-diagram")}function nm(n,e=null){de=n,ot=e,window.$components.first("image-manager").show(i=>{if(e){let r=e.querySelector("img");de.undoManager.transact(()=>{de.dom.setAttrib(r,"src",i.url),de.dom.setAttrib(e,"drawio-diagram",i.id)})}else{let r=`
`;de.insertContent(r)}},"drawio")}async function im(n){let e=window.baseUrl("/loading.gif"),t=o=>{o.status===413?window.$events.emit("error",rt.translations.serverUploadLimitText):window.$events.emit("error",rt.translations.imageUploadErrorText),console.error(o)};if(ot){tt();let o=ot.querySelector("img");try{let s=await Po(n,rt.pageId);de.undoManager.transact(()=>{de.dom.setAttrib(o,"src",s.url),de.dom.setAttrib(ot,"drawio-diagram",s.id)})}catch(s){throw t(s),new Error(`Failed to save image with error: ${s}`)}return}await ns(5);let i=`drawing-${Math.random().toString(16).slice(2)}`,r=`drawing-wrap-${Math.random().toString(16).slice(2)}`;de.insertContent(`
`),tt();try{let o=await Po(n,rt.pageId);de.undoManager.transact(()=>{de.dom.setAttrib(i,"src",o.url),de.dom.setAttrib(r,"drawio-diagram",o.id)})}catch(o){throw de.dom.remove(r),t(o),new Error(`Failed to save image with error: ${o}`)}}function rm(){if(!ot)return Promise.resolve("");let n=ot.getAttribute("drawio-diagram");return _i(n)}function vu(n,e=null){de=n,ot=e,en(rt.drawioUrl,rm,im)}function om(n){n.addCommand("drawio",()=>{let e=n.selection.getNode();vu(n,zo(e)?e:null)}),n.ui.registry.addIcon("diagram",``),n.ui.registry.addSplitButton("drawio",{tooltip:"Insert/edit drawing",icon:"diagram",onAction(){n.execCommand("drawio"),window.document.body.dispatchEvent(new Event("mousedown",{bubbles:!0}))},fetch(e){e([{type:"choiceitem",text:"Drawing manager",value:"drawing-manager"}])},onItemAction(e,t){if(t==="drawing-manager"){let i=n.selection.getNode();nm(n,zo(i)?i:null)}}}),n.on("dblclick",()=>{let e=n.selection.getNode();zo(e)&&vu(n,e)}),n.on("SetContent",()=>{let e=n.dom.select("body > div[drawio-diagram]");e.length&&n.undoManager.transact(()=>{for(let t of e)t.setAttribute("contenteditable","false")})})}function wu(n){return rt=n,om}function sm(n){n.addCommand("InsertHorizontalRule",()=>{let e=document.createElement("hr"),t=n.selection.getNode(),{parentNode:i}=t;i.insertBefore(e,t)}),n.ui.registry.addButton("customhr",{icon:"horizontal-rule",tooltip:"Insert horizontal line",onAction(){n.execCommand("InsertHorizontalRule")}})}function yu(){return sm}function am(n){n.ui.registry.addButton("imagemanager-insert",{title:"Insert image",icon:"image",tooltip:"Insert image",onAction(){window.$components.first("image-manager").show(t=>{let i=t.thumbs.display||t.url,r=``;r+=`${t.name}`,r+="",n.execCommand("mceInsertContent",!1,r)},"gallery")}})}function xu(){return am}function lm(n){let e={title:"About the WYSIWYG Editor",url:window.baseUrl("/help/wysiwyg")};n.ui.registry.addButton("about",{icon:"help",tooltip:"About the editor",onAction(){window.tinymce.activeEditor.windowManager.openUrl(e)}})}function ku(){return lm}var Cu=["p","h1","h2","h3","h4","h5","h6","div","blockquote","pre","code-block","details","ul","ol","table","hr"];function lr(n){return n.selection.getNode().closest("details")}function cm(n,e){let t=lr(n);t&&n.undoManager.transact(()=>{let i=t.querySelector("summary");i||(i=document.createElement("summary"),t.prepend(i)),i.textContent=e})}function um(n){return{title:"Edit collapsible block",body:{type:"panel",items:[{type:"input",name:"summary",label:"Toggle label"}]},buttons:[{type:"cancel",text:"Cancel"},{type:"submit",text:"Save",primary:!0}],onSubmit(e){let{summary:t}=e.getData();cm(n,t),e.close()}}}function hm(n){let e=n.querySelector("summary");return e?e.textContent:""}function Eu(n){let e=lr(n);n.windowManager.open(um(n)).setData({summary:hm(e)})}function dm(n){let e=n.selection.getNode().closest("details"),t=n.selection.getBookmark();if(e){let i=e.querySelectorAll("details > *:not(summary, doc-root), doc-root > *");n.undoManager.transact(()=>{for(let r of i)e.parentNode.insertBefore(r,e);e.remove()})}n.focus(),n.selection.moveToBookmark(t)}function Ho(n){n.attr("contenteditable",null);let e=!1;for(let t of n.children())t.name==="doc-root"&&(t.unwrap(),e=!0);e&&Ho(n)}function pm(n){Ho(n),n.attr("contenteditable","false");let e=window.tinymce.html.Node.create("doc-root",{contenteditable:"true"}),t=null;for(let i of n.children()){if(i.name==="summary")continue;Cu.includes(i.name)?(e.append(i),t=null):(t||(t=window.tinymce.html.Node.create("p"),e.append(t)),t.append(i))}n.append(e)}function fm(n){n.parser.addNodeFilter("details",e=>{for(let t of e)pm(t)}),n.serializer.addNodeFilter("details",e=>{for(let t of e)Ho(t),t.attr("open",null)}),n.serializer.addNodeFilter("doc-root",e=>{for(let t of e)t.unwrap()})}function mm(n){n.ui.registry.addIcon("details",''),n.ui.registry.addIcon("togglefold",''),n.ui.registry.addIcon("togglelabel",''),n.ui.registry.addButton("details",{icon:"details",tooltip:"Insert collapsible block",onAction(){n.execCommand("InsertDetailsBlock")}}),n.ui.registry.addButton("removedetails",{icon:"table-delete-table",tooltip:"Unwrap",onAction(){dm(n)}}),n.ui.registry.addButton("editdetials",{icon:"togglelabel",tooltip:"Edit label",onAction(){Eu(n)}}),n.on("dblclick",e=>{!lr(n)||e.target.closest("doc-root")||Eu(n)}),n.ui.registry.addButton("toggledetails",{icon:"togglefold",tooltip:"Toggle open/closed",onAction(){lr(n).toggleAttribute("open"),n.focus()}}),n.addCommand("InsertDetailsBlock",()=>{let e=n.selection.getContent({format:"html"}),t=document.createElement("details"),i=document.createElement("summary"),r=`details-${Date.now()}`;t.setAttribute("data-id",r),t.appendChild(i),e||(e="


"),t.innerHTML+=e,n.insertContent(t.outerHTML),n.focus();let o=n.dom.select(`[data-id="${r}"]`)[0]||null;if(o){let s=o.querySelector("doc-root > *");s&&s.focus(),o.removeAttribute("data-id")}}),n.ui.registry.addContextToolbar("details",{predicate(e){return e.nodeName.toLowerCase()==="details"},items:"editdetials toggledetails removedetails",position:"node",scope:"node"}),n.on("PreInit",()=>{fm(n)})}function _u(){return mm}function gm(n){let e=n.closest("li");return e&&e.parentNode.nodeName==="UL"&&e.classList.contains("task-list-item")}function bm(n,e,t){let i=e.getBoundingClientRect();n.clientX<=i.right&&n.clientX>=i.left&&n.clientY>=i.top&&n.clientY<=i.bottom||t.undoManager.transact(()=>{e.hasAttribute("checked")?e.removeAttribute("checked"):e.setAttribute("checked","checked")})}function vm(n){n.attr("class","task-list-item");for(let e of n.children())e.name==="input"&&(e.attr("checked")==="checked"&&n.attr("checked","checked"),e.remove())}function wm(n){let e=n.attr("checked")==="checked";n.attr("checked",null);let t={type:"checkbox",disabled:"disabled"};e&&(t.checked="checked");let i=window.tinymce.html.Node.create("input",t);i.shortEnded=!0,n.firstChild?n.insert(i,n.firstChild,!0):n.append(i)}function ym(n){n.ui.registry.addIcon("tasklist",''),n.ui.registry.addToggleButton("tasklist",{tooltip:"Task list",icon:"tasklist",active:!1,onAction(i){i.isActive()?n.execCommand("RemoveList"):n.execCommand("InsertUnorderedList",null,{"list-item-attributes":{class:"task-list-item"},"list-style-type":"tasklist"})},onSetup(i){n.on("NodeChange",r=>{let o=r.parents.find(a=>a.nodeName==="LI"),s=o&&o.classList.contains("task-list-item");i.setActive(!!s)})}});let e=n.ui.registry.getAll().buttons.bullist;e.onSetup=function(r){n.on("NodeChange",o=>{let s=o.parents.find(c=>c.nodeName==="LI"),a=s&&s.classList.contains("task-list-item"),l=s&&s.parentNode.nodeName==="UL";r.setActive(!!(l&&!a))})},e.onAction=function(){gm(n.selection.getNode())&&n.execCommand("InsertOrderedList",null,{"list-item-attributes":{class:null}}),n.execCommand("InsertUnorderedList",null,{"list-item-attributes":{class:null}})};let t=n.ui.registry.getAll().buttons.numlist;t.onAction=function(){n.execCommand("InsertOrderedList",null,{"list-item-attributes":{class:null}})},n.on("PreInit",()=>{n.parser.addNodeFilter("li",i=>{for(let r of i)r.attributes.map.class==="task-list-item"&&vm(r)}),n.serializer.addNodeFilter("li",i=>{for(let r of i)r.attributes.map.class==="task-list-item"&&wm(r)})}),n.on("click",i=>{let r=i.target;r.nodeName==="LI"&&r.classList.contains("task-list-item")&&(bm(i,r,n),i.preventDefault())})}function Su(){return ym}var xm=[{title:"Large Header",format:"h2",preview:"color: blue;"},{title:"Medium Header",format:"h3"},{title:"Small Header",format:"h4"},{title:"Tiny Header",format:"h5"},{title:"Paragraph",format:"p",exact:!0,classes:""},{title:"Blockquote",format:"blockquote"},{title:"Callouts",items:[{title:"Information",format:"calloutinfo"},{title:"Success",format:"calloutsuccess"},{title:"Warning",format:"calloutwarning"},{title:"Danger",format:"calloutdanger"}]}],km={alignleft:{selector:"p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img",classes:"align-left"},aligncenter:{selector:"p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img",classes:"align-center"},alignright:{selector:"p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li,table,img",classes:"align-right"},calloutsuccess:{block:"p",exact:!0,attributes:{class:"callout success"}},calloutinfo:{block:"p",exact:!0,attributes:{class:"callout info"}},calloutwarning:{block:"p",exact:!0,attributes:{class:"callout warning"}},calloutdanger:{block:"p",exact:!0,attributes:{class:"callout danger"}}},Cm=["#BFEDD2","","#FBEEB8","","#F8CAC6","","#ECCAFA","","#C2E0F4","","#2DC26B","","#F1C40F","","#E03E2D","","#B96AD9","","#3598DB","","#169179","","#E67E23","","#BA372A","","#843FA1","","#236FA1","","#ECF0F1","","#CED4D9","","#95A5A6","","#7E8C8D","","#34495E","","#000000","","#ffffff",""];function Em(n,e,t){t.filetype==="file"&&window.$components.first("entity-selector-popup").show(r=>{n(r.link,{text:r.name,title:r.name})}),t.filetype==="image"&&window.$components.first("image-manager").show(r=>{n(r.url,{alt:r.name})},"gallery")}function _m(n){let e=["image","table","link","autolink","fullscreen","code","customhr","autosave","lists","codeeditor","media","imagemanager","about","details","tasklist",n.textDirection==="rtl"?"directionality":""];return window.tinymce.PluginManager.add("codeeditor",bu()),window.tinymce.PluginManager.add("customhr",yu()),window.tinymce.PluginManager.add("imagemanager",xu()),window.tinymce.PluginManager.add("about",ku()),window.tinymce.PluginManager.add("details",_u()),window.tinymce.PluginManager.add("tasklist",Su()),n.drawioUrl&&(window.tinymce.PluginManager.add("drawio",wu(n)),e.push("drawio")),e.filter(t=>!!t)}function Sm(){let n=document.head.innerHTML.split(` diff --git a/version b/version index 05edb56cc..f086edcc5 100644 --- a/version +++ b/version @@ -1 +1 @@ -v23.09-dev +v23.08.3