lakelib 0.2.3 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lake.css +133 -137
- package/dist/lake.min.js +7 -7
- package/dist/lake.min.js.map +1 -1
- package/lib/lake.css +133 -137
- package/lib/lake.js +60 -53
- package/lib/lake.js.map +1 -1
- package/package.json +1 -1
package/dist/lake.min.js
CHANGED
|
@@ -7,15 +7,15 @@ var Lake=function(e){"use strict";class t extends HTMLElement{}void 0!==customEl
|
|
|
7
7
|
<div class="lake-dropdown-down-icon"></div>
|
|
8
8
|
</button>
|
|
9
9
|
</div>
|
|
10
|
-
`),this.menuNode=I('<ul class="lake-popup lake-dropdown-menu
|
|
10
|
+
`),this.menuNode=I('<ul class="lake-popup lake-dropdown-menu" />'),void 0!==e.tabIndex){this.node.find(".lake-dropdown-title").attr("tabindex",e.tabIndex.toString())}}static getValue(e){const t=e.attr("value");return""===t?[]:JSON.parse(h(t))}static setValue(e,t){e.attr("value",d(JSON.stringify(t)))}static getMenuMap(e,t){const i=new Map;for(const n of e){let e="string"==typeof n.text?n.text:n.text(t);e=e.replace(/<[^>]*>/g,""),i.set(n.value,e)}return i}updateColorAccent(e,t){const i=e.find(".lake-dropdown-icon svg").eq(1),n=i.find("line");n.length>0?n.attr("stroke",t):i.find("path").attr("fill",t)}apppendMenuItems(e){const t=this.config;for(const i of t.menuItems){const o="string"==typeof i.text?i.text:i.text(this.locale),a=I(s`
|
|
11
11
|
<li value="${r(i.value)}">
|
|
12
12
|
<div class="lake-dropdown-menu-text">${o}</div>
|
|
13
13
|
</li>
|
|
14
|
-
`);if(e.append(a),a.on("mouseenter",(()=>{a.hasClass("lake-dropdown-item-selected")||a.addClass("lake-dropdown-item-hovered")})),a.on("mouseleave",(()=>{a.removeClass("lake-dropdown-item-hovered")})),"character"===t.menuType?(a.attr("title",o),a.find(".lake-dropdown-menu-text").text(i.value)):"color"===t.menuType&&(a.attr("title",o),a.find(".lake-dropdown-menu-text").css("background-color",i.value)),i.icon){const e=I('<div class="lake-dropdown-menu-icon"></div>');e.append(i.icon),a.prepend(e)}const l=n.get("check");if(l){const e=I('<div class="lake-dropdown-menu-check"></div>');e.append(l),a.prepend(e)}}}appendMenu(){const e=this.config,t=this.menuNode,i=this.node.find(".lake-dropdown-title"),n=i.find(".lake-dropdown-text");t.addClass(`lake-${e.menuType}-dropdown-menu`),e.menuWidth&&t.css("width",e.menuWidth),e.menuHeight&&(t.addClass("lake-dropdown-menu-with-scroll"),t.css("height",e.menuHeight)),this.apppendMenuItems(t),"local"===this.location?this.node.append(t):I(document.body).append(t),t.on("click",(t=>{t.preventDefault(),t.stopPropagation();const s=I(t.target).closest("li");if(0===s.length)return;const o=s.attr("value");He.setValue(this.node,[o]),n.length>0&&n.text(s.text()),"color"===e.menuType&&""!==o&&(this.node.attr("color",o),this.updateColorAccent(i,o)),e.onSelect(o),this.hideMenu()}))}updatePosition(){const e=this.menuNode,t=this.node.get(0).getBoundingClientRect(),i=e.width()-(t.x+t.width),n=t.x+e.width()-window.innerWidth,s=n+50>0&&(i<0||i<n);if("local"===this.location)return s?(e.css("left","auto"),e.css("right","0")):(e.css("left",""),e.css("right","")),void("top"===this.direction&&(e.css("top","auto"),e.css("bottom",`${t.height}px`)));const o=t.y+t.height+e.height()-window.innerHeight,r=t.x+window.scrollX,a=t.y+window.scrollY;s?e.css("left",`${r-e.width()+t.width}px`):e.css("left",`${r}px`),o>0?e.css("top",a-e.height()+"px"):e.css("top",`${a+t.height}px`)}showMenu(){const e=this.config,t=this.menuNode;if(t.get(0).isConnected||this.appendMenu(),this.node.attr("disabled"))return;const i=He.getValue(this.node);t.find(".lake-dropdown-menu-check").css("visibility","hidden"),t.find("li").each((e=>{const t=I(e);i.indexOf(t.attr("value"))>=0&&t.find(".lake-dropdown-menu-check").css("visibility","visible")})),t.css("visibility","hidden"),t.show("list"===e.menuType?"block":"flex"),this.updatePosition();const n=this.node.closestScroller();n.length>0&&n.on("scroll",this.scrollListener),document.addEventListener("click",this.clickListener),window.addEventListener("resize",this.resizeListener),t.css("visibility","")}hideMenu(){this.menuNode.hide();const e=this.node.closestScroller();e.length>0&&e.off("scroll",this.scrollListener),document.removeEventListener("click",this.clickListener),window.removeEventListener("resize",this.resizeListener)}render(){var e,t;const i=this.config,n=null!==(e=i.defaultValue)&&void 0!==e?e:"",s=this.node.find(".lake-dropdown-title");i.downIcon||s.addClass("lake-dropdown-title-no-down"),i.width&&s.css("width",i.width);const o="string"==typeof i.tooltip?i.tooltip:i.tooltip(this.locale);s.attr("title",o);const r=s.find(".lake-dropdown-text"),a=s.find(".lake-dropdown-icon");i.icon&&a.append(i.icon),i.accentIcon&&a.append(i.accentIcon);const l=s.find(".lake-dropdown-down-icon");if(i.downIcon&&l.append(i.downIcon),He.setValue(this.node,[n]),r.length>0){const e=He.getMenuMap(i.menuItems,this.locale);r.text(null!==(t=e.get(n))&&void 0!==t?t:n)}"color"===i.menuType&&this.updateColorAccent(s,n),this.node.append(s),this.root.append(this.node),"color"===i.menuType?(a.on("mouseenter",(()=>{this.node.attr("disabled")||a.addClass("lake-dropdown-icon-hovered")})),a.on("mouseleave",(()=>{a.removeClass("lake-dropdown-icon-hovered")})),l.on("mouseenter",(()=>{this.node.attr("disabled")||l.addClass("lake-dropdown-down-icon-hovered")})),l.on("mouseleave",(()=>{l.removeClass("lake-dropdown-down-icon-hovered")}))):(s.on("mouseenter",(()=>{this.node.attr("disabled")||s.addClass("lake-dropdown-title-hovered")})),s.on("mouseleave",(()=>{s.removeClass("lake-dropdown-title-hovered")}))),"color"===i.menuType&&a.on("click",(e=>{if(e.preventDefault(),this.node.attr("disabled"))return;const t=this.node.attr("color")||i.defaultValue||"";i.onSelect(t)}));("color"===i.menuType&&l?l:s).on("click",(e=>{e.preventDefault(),this.showMenu()}))}unmount(){this.hideMenu(),this.node.remove()}}class ze{constructor(e){this.buttonItemList=[],this.dropdownItemList=[],this.dropdownList=[],this.scrollListener=()=>this.updatePosition(),this.resizeListener=()=>this.updatePosition(),this.box=e.box,this.items=e.items,this.locale=e.locale||Ze("en-US"),this.placement=e.placement||"top",this.container=I('<div class="lake-popup lake-box-toolbar
|
|
14
|
+
`);if(e.append(a),a.on("mouseenter",(()=>{a.hasClass("lake-dropdown-item-selected")||a.addClass("lake-dropdown-item-hovered")})),a.on("mouseleave",(()=>{a.removeClass("lake-dropdown-item-hovered")})),"character"===t.menuType?(a.attr("title",o),a.find(".lake-dropdown-menu-text").text(i.value)):"color"===t.menuType&&(a.attr("title",o),a.find(".lake-dropdown-menu-text").css("background-color",i.value)),i.icon){const e=I('<div class="lake-dropdown-menu-icon"></div>');e.append(i.icon),a.prepend(e)}const l=n.get("check");if(l){const e=I('<div class="lake-dropdown-menu-check"></div>');e.append(l),a.prepend(e)}}}appendMenu(){const e=this.config,t=this.menuNode,i=this.node.find(".lake-dropdown-title"),n=i.find(".lake-dropdown-text");t.addClass(`lake-${e.menuType}-dropdown-menu`),e.menuWidth&&t.css("width",e.menuWidth),e.menuHeight&&(t.addClass("lake-dropdown-menu-with-scroll"),t.css("height",e.menuHeight)),this.apppendMenuItems(t),"local"===this.location?this.node.append(t):I(document.body).append(t),t.on("click",(t=>{t.preventDefault(),t.stopPropagation();const s=I(t.target).closest("li");if(0===s.length)return;const o=s.attr("value");He.setValue(this.node,[o]),n.length>0&&n.text(s.text()),"color"===e.menuType&&""!==o&&(this.node.attr("color",o),this.updateColorAccent(i,o)),e.onSelect(o),this.hideMenu()}))}updatePosition(){const e=this.menuNode,t=this.node.get(0).getBoundingClientRect(),i=e.width()-(t.x+t.width),n=t.x+e.width()-window.innerWidth,s=n+50>0&&(i<0||i<n);if("local"===this.location)return s?(e.css("left","auto"),e.css("right","0")):(e.css("left",""),e.css("right","")),void("top"===this.direction&&(e.css("top","auto"),e.css("bottom",`${t.height}px`)));const o=t.y+t.height+e.height()-window.innerHeight,r=t.x+window.scrollX,a=t.y+window.scrollY;s?e.css("left",`${r-e.width()+t.width}px`):e.css("left",`${r}px`),o>0?e.css("top",a-e.height()+"px"):e.css("top",`${a+t.height}px`)}showMenu(){const e=this.config,t=this.menuNode;if(t.get(0).isConnected||this.appendMenu(),this.node.attr("disabled"))return;const i=He.getValue(this.node);t.find(".lake-dropdown-menu-check").css("visibility","hidden"),t.find("li").each((e=>{const t=I(e);i.indexOf(t.attr("value"))>=0&&t.find(".lake-dropdown-menu-check").css("visibility","visible")})),t.css("visibility","hidden"),t.show("list"===e.menuType?"block":"flex"),this.updatePosition();const n=this.node.closestScroller();n.length>0&&n.on("scroll",this.scrollListener),document.addEventListener("click",this.clickListener),window.addEventListener("resize",this.resizeListener),t.css("visibility","")}hideMenu(){this.menuNode.hide();const e=this.node.closestScroller();e.length>0&&e.off("scroll",this.scrollListener),document.removeEventListener("click",this.clickListener),window.removeEventListener("resize",this.resizeListener)}render(){var e,t;const i=this.config,n=null!==(e=i.defaultValue)&&void 0!==e?e:"",s=this.node.find(".lake-dropdown-title");i.downIcon||s.addClass("lake-dropdown-title-no-down"),i.width&&s.css("width",i.width);const o="string"==typeof i.tooltip?i.tooltip:i.tooltip(this.locale);s.attr("title",o);const r=s.find(".lake-dropdown-text"),a=s.find(".lake-dropdown-icon");i.icon&&a.append(i.icon),i.accentIcon&&a.append(i.accentIcon);const l=s.find(".lake-dropdown-down-icon");if(i.downIcon&&l.append(i.downIcon),He.setValue(this.node,[n]),r.length>0){const e=He.getMenuMap(i.menuItems,this.locale);r.text(null!==(t=e.get(n))&&void 0!==t?t:n)}"color"===i.menuType&&this.updateColorAccent(s,n),this.node.append(s),this.root.append(this.node),"color"===i.menuType?(a.on("mouseenter",(()=>{this.node.attr("disabled")||a.addClass("lake-dropdown-icon-hovered")})),a.on("mouseleave",(()=>{a.removeClass("lake-dropdown-icon-hovered")})),l.on("mouseenter",(()=>{this.node.attr("disabled")||l.addClass("lake-dropdown-down-icon-hovered")})),l.on("mouseleave",(()=>{l.removeClass("lake-dropdown-down-icon-hovered")}))):(s.on("mouseenter",(()=>{this.node.attr("disabled")||s.addClass("lake-dropdown-title-hovered")})),s.on("mouseleave",(()=>{s.removeClass("lake-dropdown-title-hovered")}))),"color"===i.menuType&&a.on("click",(e=>{if(e.preventDefault(),this.node.attr("disabled"))return;const t=this.node.attr("color")||i.defaultValue||"";i.onSelect(t)}));("color"===i.menuType&&l?l:s).on("click",(e=>{e.preventDefault(),this.showMenu()}))}unmount(){this.hideMenu(),this.node.remove()}}class ze{constructor(e){this.buttonItemList=[],this.dropdownItemList=[],this.dropdownList=[],this.scrollListener=()=>this.updatePosition(),this.resizeListener=()=>this.updatePosition(),this.box=e.box,this.items=e.items,this.locale=e.locale||Ze("en-US"),this.placement=e.placement||"top",this.container=I('<div class="lake-popup lake-box-toolbar" />')}appendDivider(){this.container.append('<div class="lake-toolbar-divider" />')}appendButton(e){new be({root:this.container,name:e.name,icon:e.icon,tooltip:"string"==typeof e.tooltip?e.tooltip:e.tooltip(this.locale),tabIndex:-1,onClick:()=>{e.onClick(this.box,e.name)}}).render()}appendDropdown(e){const t=new He({root:this.container,locale:this.locale,name:e.name,icon:e.icon,accentIcon:e.accentIcon,downIcon:e.downIcon,defaultValue:e.defaultValue,tooltip:e.tooltip,width:e.width,menuType:e.menuType,menuItems:e.menuItems,tabIndex:-1,direction:"top"===this.placement?"bottom":"top",onSelect:t=>{e.onSelect(this.box,t)}});t.render(),this.dropdownList.push(t)}updatePosition(){const e=this.box.node,t=e.get(0).getBoundingClientRect(),i=pe(e);if(i.top<0||i.bottom+t.height<0)return void this.container.hide();this.container.show("flex");const n=t.x+window.scrollX,s=t.y+window.scrollY,o=(n+t.width/2-this.container.width()/2).toFixed(1),r=(s-this.container.height()-6).toFixed(1);this.container.css({left:`${o}px`,top:`${r}px`})}render(){I(document.body).append(this.container);for(const e of this.items)"|"===e?this.appendDivider():"button"===e.type?(this.buttonItemList.push(e),this.appendButton(e)):"dropdown"===e.type&&(this.dropdownItemList.push(e),this.appendDropdown(e));this.updatePosition();const e=this.box.node.closestScroller();e.length>0&&e.on("scroll",this.scrollListener),window.addEventListener("resize",this.resizeListener)}unmount(){for(const e of this.dropdownList)e.unmount();const e=this.box.node.closestScroller();e.length>0&&e.off("scroll",this.scrollListener),window.removeEventListener("resize",this.resizeListener),this.container.remove()}}const $e=a`
|
|
15
15
|
<span class="lake-box-strip"><br /></span>
|
|
16
16
|
<div class="lake-box-container" contenteditable="false"></div>
|
|
17
17
|
<span class="lake-box-strip"><br /></span>
|
|
18
|
-
`;class Ve{constructor(e){if(this.event=new we,"string"==typeof e){const t=ye.get(e);if(void 0===t)throw new Error(`Box "${e}" has not been defined yet.`);const i=r(t.type),n=r(t.name);this.node=I(a`<lake-box type="${i}" name="${n}"></lake-box>`),t.value&&(this.value=t.value)}else{this.node=I(e);const t=ye.get(this.name);if(void 0===t)throw new Error(`Box "${this.name}" has not been defined yet.`);t.value&&!this.node.hasAttr("value")&&(this.value=t.value)}}addFramework(){let e=this.getContainer();0===e.length?(this.node.html($e),e=this.getContainer()):(e.off("mouseenter"),e.off("mouseleave"),e.off("click")),e.on("mouseenter",(()=>{e.hasClass("lake-box-selected")||e.hasClass("lake-box-focused")||e.hasClass("lake-box-activated")||e.addClass("lake-box-hovered")})),e.on("mouseleave",(()=>{e.removeClass("lake-box-hovered")})),e.on("click",(()=>{A(`Box "${this.name}" (id = ${this.node.id}) value:`),A(this.value)})),"block"===this.type&&this.node.isContentEditable&&e.attr("draggable","true")}get type(){return this.node.attr("type")}get name(){return this.node.attr("name")}get value(){const e=this.node.attr("value");return""===e?{}:JSON.parse(h(e))}set value(e){this.node.attr("value",d(JSON.stringify(e)))}updateValue(e,t){const i=this.value;if("string"==typeof e)i[e]=t;else for(const t of Object.keys(e))i[t]=e[t];this.value=i}getEditor(){const e=this.node.closest("div[contenteditable]"),t=e.length>0?xe.get(e.id):void 0;if(!t)throw new Error(`Box "${this.name}" (id=${this.node.id}) is not rendered in the editor.`);return t}getContainer(){return this.node.find(".lake-box-container")}setToolbar(e){let t;try{t=this.getEditor()}catch(e){}let i=null;this.event.on("focus",(()=>{i=new ze({box:this,items:e,locale:t?t.locale:void 0}),i.render()})),this.event.on("blur",(()=>{i&&(i.unmount(),i=null)}))}render(){const e=ye.get(this.name);if(void 0===e)return;this.event.emit("beforeunmount"),this.event.removeAllListeners(),this.addFramework();const t=e.render(this);if(void 0!==t){const e=this.getContainer();e.empty(),e.append(t)}A(`Box "${this.name}" (id: ${this.node.id}) rendered`)}unmount(){this.event.emit("blur"),this.event.emit("beforeunmount"),this.event.removeAllListeners(),this.node.empty(),A(`Box "${this.name}" (id: ${this.node.id}) unmounted`)}getHTML(){const e=ye.get(this.name);return void 0===e?"":void 0===e.html?this.node.outerHTML():e.html(this)}}function Fe(e){const t=ge(0);if("string"==typeof e){const i=new Ve(e);return t.set(i.node.id,i),i}const i=(e=I(e)).closestContainer();if(0===i.length){let i=t.get(e.id);return i||(i=new Ve(e),t.set(e.id,i),i)}const n=ge(i.id);let s=t.get(e.id);return s?(n.set(e.id,s),t.delete(e.id),s):(s=n.get(e.id),s||(s=new Ve(e),n.set(e.id,s),s))}function Re(e){const t=e.responseText||e.response;if(!t)return t;try{return JSON.parse(t)}catch(e){return t}}function qe(e){const t=new XMLHttpRequest;e.onProgress&&t.upload&&(t.upload.onprogress=t=>{t.total>0&&(t.percent=t.loaded/t.total*100),e.onProgress&&e.onProgress(t)});const i=new FormData,n=e.data||{};if(Object.keys(n).forEach((e=>{const t=n[e];Array.isArray(t)?t.forEach((t=>{i.append(`${e}[]`,t)})):i.append(e,t)})),e.file){const t=e.filename||"file";e.file instanceof Blob?i.append(t,e.file,e.file.name):i.append(t,e.file)}t.onerror=t=>{e.onError&&e.onError(t)},t.onload=()=>{if(t.status<200||t.status>=300){if(!e.onError)return;return e.onError(function(e,t){const i=`Cannot ${e.method} ${e.action} ${t.status}'`,n=new Error(i);return n.status=t.status,n.method=e.method,n.url=e.action,n}(e,t),Re(t))}if(e.onSuccess)return e.onSuccess(Re(t),t)},t.open(e.method,e.action,!0),e.withCredentials&&"withCredentials"in t&&(t.withCredentials=!0);const s=e.headers||{};return null!==s["X-Requested-With"]&&t.setRequestHeader("X-Requested-With","XMLHttpRequest"),Object.keys(s).forEach((e=>{null!==s[e]&&t.setRequestHeader(e,s[e])})),t.send(i),t}function je(e){const{editor:t,name:i,file:n,onError:s,onSuccess:o}=e,{requestMethod:r,requestAction:a,requestTypes:l}=t.config[i];if(l.indexOf(n.type)<0)throw s&&s(`File "${n.name}" is not allowed for uploading.`),new Error(`Cannot upload file "${n.name}" because its type "${n.type}" is not found in ['${l.join("', '")}'].`);const c=t.selection.insertBox(i,{url:URL.createObjectURL(n),status:"uploading",name:n.name,size:n.size,type:n.type,lastModified:n.lastModified});let d=qe({onProgress:e=>{const t=c.node.find(".lake-percent"),i=Math.round(e.percent);t.text(`${i<100?i:99} %`)},onError:(e,t)=>{d=null,A(e.toString(),t),c.updateValue("status","error"),c.render(),s&&s(e.toString())},onSuccess:e=>{if(d=null,!e.url)return c.updateValue("status","error"),c.render(),void(s&&s("Cannot find the url field."));c.updateValue({status:"done",url:e.url}),c.render(),t.history.save(),o&&o()},file:n,action:a,method:r});return c.event.on("beforeunmount",(()=>{d&&(d.abort(),A("Upload canceled"))})),c}var We=Object.freeze({__proto__:null,appendBreak:D,camelCase:l,changeTagName:V,debug:A,denormalizeValue:f,encode:r,fileSize:w,fixNumberedList:F,fromBase64:h,getBox:Fe,getCSS:y,getDeepElement:H,inString:c,mergeNodes:Z,modifierText:v,morph:he,nodePosition:pe,normalizeValue:g,parseStyle:m,query:I,removeBreak:N,removeZWS:$,request:qe,safeTemplate:a,scrollToNode:ue,setBlockIndent:R,splitNodes:P,template:s,toBase64:d,toHex:u,toNodeList:x,uploadFile:je,wrapNodeList:z});class Ue{constructor(e){this.fragment=null!=e?e:document.createDocumentFragment()}get(){return this.fragment}find(e){const t=[];let i=new T(this.fragment.firstChild);for(;i.length>0;)i.matches(e)?t.push(i.get(0)):i.isElement&&i.find(e).each((e=>{t.push(e)})),i=i.next();return new T(t)}append(e){I(e).each((e=>{this.fragment.appendChild(e)}))}}const Ke={id:/^[\w-]+$/,class:/^[\w- ]+$/,style:{"text-align":["left","center","right","justify","start","end"],"margin-left":/^-?\d+px$/i,"text-indent":/^-?\d+em$/i}};function Ge(){return{h1:Object.assign({},Ke),h2:Object.assign({},Ke),h3:Object.assign({},Ke),h4:Object.assign({},Ke),h5:Object.assign({},Ke),h6:Object.assign({},Ke),p:Object.assign({},Ke),blockquote:Object.assign(Object.assign({},Ke),{type:["info","tip","success","warning","error","danger"]}),ul:Object.assign(Object.assign({},Ke),{type:"checklist",indent:/^\d+$/}),ol:Object.assign(Object.assign({},Ke),{start:/^\d+$/,indent:/^\d+$/}),li:{value:["true","false"]},table:{style:{width:/^-?\d+(px|%)$/i,height:/^-?\d+(px|%)$/i,border:/^[^"]+$/,"border-width":/^-?\d+px$/i,"border-style":/^[\w-]+$/,"border-color":/^[^"]+$/,"background-color":/^[^"]+$/}},tr:{style:{height:/^-?\d+(px|%)$/i}},th:"td",td:{colspan:/^\d+$/,rowspan:/^\d+$/,style:{width:/^-?\d+(px|%)$/i,height:/^-?\d+(px|%)$/i,border:/^[^"]+$/,"border-width":/^-?\d+px$/i,"border-style":/^[\w-]+$/,"border-color":/^[^"]+$/,"background-color":/^[^"]+$/,"text-align":["left","center","right","justify"]}},"lake-box":{type:["inline","block"],name:/^[\w-]+$/,value:/^[^"]+$/,focus:["start","center","end"]},br:{},hr:{},img:{src:/^[^"]+$/,width:/^-?\d+px$/i,height:/^-?\d+px$/i,"data-lake-value":/^[^"]+$/,alt:/^[^"]+$/,style:{width:/^-?\d+px$/i,height:/^-?\d+px$/i}},span:{class:/^[\w- ]+$/,style:{color:/^[^"]+$/,"background-color":/^[^"]+$/,"font-family":/^[^;]+$/,"font-size":/^[^"]+$/}},b:"strong",strong:{},em:"i",i:{},u:{},s:{},sub:{},sup:{},code:{},a:{class:/^[\w- ]+$/,name:/^[\w-]+$/,href:/^[^"]+$/,target:/^[\w-]+$/,rel:/^[^"]+$/,download:/^[^"]+$/},"lake-bookmark":{type:["anchor","focus"]}}}class Xe{constructor(e,t=Ge()){this.rules=t,this.source="string"==typeof e?this.parseHTML(e):e}parseHTML(e){const t=(new DOMParser).parseFromString(e,"text/html");return new T(t.querySelector("body"))}static matchRule(e,t){return"string"==typeof e?e===t:Array.isArray(e)?e.indexOf(t)>=0:e instanceof RegExp&&e.test(t)}static getOpenTagString(e,t){let i=e.name,n=t[i];if(!n)return"";"string"==typeof n&&(i=n,n=t[i]);const s=e.get(0);if(!s.hasAttributes())return i;const o=new Map;for(const e of s.attributes)if(n[e.name]&&("style"!==e.name&&Xe.matchRule(n[e.name],e.value)&&o.set(e.name,e.value),"style"===e.name)){const t=n.style,i=new Map,s=m(e.value);for(const e of Object.keys(s)){const n=s[e];t[e]&&Xe.matchRule(t[e],n)&&i.set(e,n)}o.set("style",i)}let r=i;for(const[e,t]of o)if("style"===e){let e="";for(const[i,n]of t)e+=`${i}: ${n.replace(/"/g,""")}; `;""!==e&&(r+=` style="${e.trim()}"`)}else r+=` ${e}="${t}"`;return r}static getClosedTagString(e,t){let i=e.name;const n=t[i];return n?("string"==typeof n&&(i=n),i):""}static getTrimmedText(e){const t=e.parent(),i=e.prev(),n=e.next();let s=e.text();return(i.isBlock||i.isBlockBox)&&(n.isBlock||n.isBlockBox)||0===i.length&&0===n.length&&t.isBlock?s=s.replace(/^[\u0020\t\r\n]+|[\u0020\t\r\n]+$/g,""):i.isBlock||i.isBlockBox||0===i.length&&t.isBlock?s=s.replace(/^[\u0020\t\r\n]+/,""):(n.isBlock||n.isBlockBox||0===n.length&&t.isBlock)&&(s=s.replace(/[\u0020\t\r\n]+$/,"")),s}getHTML(){const e=this.rules;let t="";for(const i of function*t(i){let n=i.first();for(;n.length>0;){const i=n.next();if(n.isText)yield r(Xe.getTrimmedText(n));else if(n.isVoid){const t=Xe.getOpenTagString(n,e);""!==t&&(yield`<${t} />`)}else if(n.isElement){const i=Xe.getOpenTagString(n,e),s=Xe.getClosedTagString(n,e);""!==i&&(yield`<${i}>`),n.isBox||(yield*t(n)),""!==s&&(yield`</${s}>`)}n=i}}(this.source))t+=i;return t.trim()}getFragment(){const e=this.getHTML(),t=this.parseHTML(e),i=document.createDocumentFragment();let n=t.first();for(;n.length>0;){const e=n.next();i.appendChild(n.get(0)),n=e}return i}}class Qe{constructor(e){this.content=e}getHTML(){let e=this.content;return e=e.replace(/ {2}/g," "),e=r(e.trim()),e=`<p>${e}</p>`,e=e.replace(/(\r\n){2,}/g,"</p><p><br /></p><p>"),e=e.replace(/\r\n/g,"</p><p>"),e=e.replace(/[\r\n]{2,}/g,"</p><p><br /></p><p>"),e=e.replace(/[\r\n]/g,"</p><p>"),e}getFragment(){return new Xe(this.getHTML()).getFragment()}}function Ye(e,t){if(e.commonAncestor.isOutside)return;const i=(t=I(t)).get(0),n=e.get();n.insertNode(i),n.setEndAfter(i),n.collapse(!1)}function Je(e){if(e.commonAncestor.isOutside)return{anchor:new T,focus:new T};const t=e.startNode.closest("lake-box");if(t.length>0)return e.isBoxStart?t.attr("focus","start"):e.isBoxEnd?t.attr("focus","end"):t.attr("focus","center"),{anchor:new T,focus:t};if(e.isCollapsed){const t=e.clone();t.collapseToEnd();const i=I('<lake-bookmark type="focus" />');return Ye(t,i),{anchor:new T,focus:i}}const i=e.clone();i.collapseToStart();const n=I('<lake-bookmark type="anchor" />');Ye(i,n);const s=e.clone();s.collapseToEnd();const o=I('<lake-bookmark type="focus" />');return Ye(s,o),{anchor:n,focus:o}}function et(e,t){const i=e.prev(),n=e.next();if(i.isText||n.isText){const t=e.parent();e.remove(),t.get(0).normalize()}else if(0===i.length&&0===n.length){if(e.parent().isMark&&t){const i=new T(document.createTextNode(""));e.before(i),t.setStartAfter(i),t.collapseToStart()}e.remove()}else e.remove()}function tt(e,t){const i=t.anchor,n=t.focus;if(i.length>0&&0===n.length)et(i);else{if(n.length>0&&0===i.length){if(n.isBox){const t=Fe(n);0===t.getContainer().length&&t.render();const i=n.attr("focus");return"start"===i?e.selectBoxStart(n):"center"===i?e.selectBox(n):e.selectBoxEnd(n),void n.removeAttr("focus")}return e.setStartBefore(n),e.collapseToStart(),void et(n,e)}if(i.length>0&&n.length>0){const t=new M;t.selectNode(i),t.collapseToEnd(),-1===t.compareAfterNode(n)?(e.setStartBefore(n),et(n),e.setEndBefore(i),et(i)):(e.setStartBefore(i),et(i),e.setEndBefore(n),et(n))}}}function it(e){if(e.commonAncestor.isOutside)return;F(e.getBlocks())}function nt(e){if(e.isCollapsed)return;if(e.adjustBox(),e.adjustTable(),e.isInoperative)return;const t=e.startNode.closestBlock(),i=e.endNode.closestBlock(),n=t.get(0)===i.get(0);if(e.get().deleteContents(),e.adjustBlock(),n){const t=e.getBlocks()[0];if(t&&t.isEmpty){const i=D(t);e.setStartBefore(i),e.collapseToStart()}return}const s=e.getBlocks()[0];if(!s)return;const o=s.prev();if(0===o.length)return;const r=Je(e);Z(o,s),tt(e,r),it(e)}function st(e,t){if(t instanceof Ue&&(t=t.get()),e.commonAncestor.isOutside)return;e.isCollapsed?e.adjustBox():nt(e);N(e.startNode.closestBlock());const i=Je(e);i.focus.before(t),tt(e,i),e.adjustBlock()}function ot(e,t){if(e.commonAncestor.isOutside)return;if(e.isCollapsed){if(e.commonAncestor.closest("lake-box").isBlockBox)return}if("string"!=typeof t){const i=e.getBlocks();for(const e of i)e.css(t);return}const i=I(t),n=i.name,s=i.get(0).attributes,o=e.getBlocks();if(o.length>0){const t=Je(e);for(const e of o)if(e.name===n&&0===i.first().length)for(const t of s)e.attr(t.name,t.value);else{const t=i.clone(!0);t.isList&&e.isList&&""!==e.attr("indent")&&t.attr("indent",e.attr("indent"));const n=H(t);let s=e.first();for(;s.length>0;){const e=s.next();n.append(s),n.name!==s.name&&"li"!==s.name||s.remove(!0),s=e}e.replaceWith(t)}return tt(e,t),void it(e)}const r=Je(e),a=function(e){const t=e.commonAncestor.closest('div[contenteditable="true"],td');let i=[];if(0===t.length)return i;let n=t.first(),s=!0;for(;n.length>0;){if(n.isMark||n.isText||n.isBookmark||n.isInlineBox)i.push(n);else{if(!s)break;i=[]}e.intersectsNode(n)&&(s=!1),n=n.next()}return i}(e),l=z(a,i);if(tt(e,r),it(e),l.isEmpty){const t=D(l);e.setStartBefore(t),e.collapseToStart()}}function rt(e){if(e.commonAncestor.isOutside)return{start:null,end:null};e.isCollapsed?e.adjustBox():nt(e);const t=e.startNode,i=t.closestOperableBlock();if(0===i.length)return{start:null,end:null};let n=i.parent();n.isOutside&&(n=t.closestContainer());const s=P(t,e.startOffset,n);let o=null,r=null;return s&&(o=s.start,r=s.end),!s&&t.isBlock&&(e.startOffset>0&&(o=t.children()[e.startOffset-1]),r=t.children()[e.startOffset],r&&!r.isBlock&&(r=null)),o&&o.isEmpty&&D(o),r&&(r.isEmpty&&D(r),e.shrinkBefore(r)),it(e),{start:o,end:r}}function at(e){if(e.isMark&&e.isEmpty)e.remove();else for(const t of e.getWalker())t.isMark&&t.isEmpty&&t.remove()}function lt(e,t,i){let n=null,s=null,o=e.closestBlock();0===o.length&&(o=e.closestContainer());const r=P(e,t,o);return r&&(i?(at(r.start),at(r.end),r.start.isEmpty||(n=r.start),r.end.isEmpty||(s=r.end)):(n=r.start,s=r.end)),{start:n,end:s}}function ct(e,t=!0){if(e.commonAncestor.isOutside)return{start:null,center:null,end:null};if(e.adjustBox(),e.isCollapsed){const i=lt(e.startNode,e.startOffset,t);return i.start?(e.setStartAfter(i.start),e.collapseToStart()):i.end&&(e.setStartBefore(i.end),e.collapseToStart()),{start:i.start,center:null,end:i.end}}const i=lt(e.startNode,e.startOffset,t);i.start?e.setStartAfter(i.start):i.end&&e.setStartBefore(i.end);const n=lt(e.endNode,e.endOffset,t);return n.start?e.setEndAfter(n.start):n.end&&e.setEndBefore(n.end),{start:i.start,center:n.start,end:n.end}}function dt(e,t){const i=e.text();let n=e;for(;n.length>0;){const e=n.parent();if(!e.isMark||i!==e.text()||!n.isText&&n.name===t&&""!==n.attr("style"))break;n=e}return n}function ht(e,t){if(e.commonAncestor.isOutside)return;let i=I(t);const n=i.name,s=m(i.attr("style"));if(e.isCollapsed){if(e.isBox){const t=e.startNode.closest("lake-box");if("block"===Fe(t).type){const i=I("<p><br /></p>");e.isBoxStart?t.before(i):t.after(i),e.shrinkAfter(i)}else e.adjustBox()}N(e.startNode.closestBlock());const t=new T(document.createTextNode("")),o=ct(e);if(o.start){const e=function(e){if(!e.isMark)return null;let t=e.clone(),i=e.last();for(;i.length>0;){if(i.isMark){const e=i.clone();t.append(e),t=e}i=i.last()}return t}(o.start);if(e)if(e.name===n)e.css(s),i=e;else{H(e).append(t),i.append(e)}}return""===i.text()&&i.append(t),Ye(e,i),function(e){const t=e.prev();t.length>0&&t.isText&&t.isEmpty&&t.remove();const i=e.next();i.length>0&&i.isText&&i.isEmpty&&i.remove()}(i),void e.shrinkAfter(i)}ct(e);const o=e.getMarks(!0),r=Je(e);for(const e of o)if(!e.isEmpty&&e.isText){const t=dt(e,n);if(t.isMark&&t.name===n)t.css(s);else{const e=i.clone();t.before(e),e.append(t)}}tt(e,r)}function pt(e){if(e.isMark&&e.isEmpty)e.remove();else for(const t of e.getWalker())t.isMark&&t.isEmpty&&t.remove()}function ut(e,t){if(e.commonAncestor.isOutside)return;let i;if(t){i=I(t).name}if(e.isCollapsed){if(e.isBox)return;if(i&&0===e.commonAncestor.closest(i).length)return;const t=ct(e,!1);if(!t.start)return;t.end&&pt(t.end);const n=new T(document.createTextNode("")),s=function(e,t){if(!e.isMark||!t)return null;let i=e.clone(),n=e.last();for(;n.length>0;){if(n.isMark&&n.name!==t){const e=n.clone();i.append(e),i=e}n=n.last()}if(i.name===t){if(!(i.first().length>0))return null;i=i.first()}return i}(t.start,i);if(!s)return t.start.after(n),pt(t.start),n.prev().isText?(e.setStartAfter(n.prev()),e.collapseToStart(),void n.remove()):(e.setStartAfter(n),void e.collapseToStart());return H(s).append(n),t.start.after(s),pt(t.start),void e.shrinkAfter(s)}ct(e);const n=e.getMarks(),s=Je(e);for(const e of n)if(!i||e.name===i){const t=e.parent();e.remove(!e.isEmpty),t.length>0&&t.get(0).normalize()}$(e.commonAncestor),tt(e,s)}function mt(e,t){if(e.commonAncestor.isOutside)return null;const i=I(t);if(e.isCollapsed){let t=e.commonAncestor.closest("a");if(0===t.length){t=i.clone(!0);return N(e.startNode.closestBlock()),Ye(e,t),t}return""!==i.attr("href")&&t.attr({href:i.attr("href")}),t}ct(e);const n=Je(e);for(const t of e.commonAncestor.getWalker())"a"===t.name&&e.intersectsNode(t)&&t.remove(!0);const s=i.clone(!1);n.anchor.after(s);let o=s.next();for(;o.length>0;){const e=o.next();if(!o.isMark&&!o.isText)break;s.append(o),o=e}return 0===s.first().length&&s.remove(),tt(e,n),s}function gt(e,t,i){if(e.commonAncestor.isOutside)return null;const n=Fe(t);i&&(n.value=i);const s=document.createDocumentFragment();if(s.appendChild(n.node.get(0)),"inline"===n.type)return ct(e),st(e,s),n.render(),e.selectBoxEnd(n.node),Fe(n.node);const o=rt(e);return o.start&&(e.setEndAfter(o.start),e.collapseToEnd()),o.end&&o.end.isEmpty&&o.end.remove(),st(e,s),n.render(),e.selectBoxEnd(n.node),o.start&&o.start.isEmpty&&o.start.remove(),Fe(n.node)}function ft(e){const t=e.node.closestContainer();if(e.unmount(),e.node.remove(),t.length>0){ge(t.id).delete(e.node.id);ge(0).set(e.node.id,e)}return e}function vt(e){if(e.commonAncestor.isOutside)return null;const t=e.commonAncestor.closest("lake-box");if(0===t.length)return null;const i=Fe(t);if("block"===i.type){const n=I("<p><br /></p>");return t.before(n),e.shrinkAfter(n),ft(i)}e.setStartBefore(t),e.collapseToStart();const n=t.parent();if(ft(i),n.isEmpty){const t=D(n);e.setStartBefore(t),e.collapseToStart()}return i}var wt={exports:{}};function yt(e,t=100,i={}){if("function"!=typeof e)throw new TypeError(`Expected the first parameter to be a function, got \`${typeof e}\`.`);if(t<0)throw new RangeError("`wait` must not be negative.");const{immediate:n}="boolean"==typeof i?{immediate:i}:i;let s,o,r,a,l;function c(){const t=s,i=o;return s=void 0,o=void 0,l=e.apply(t,i),l}function d(){const e=Date.now()-a;e<t&&e>=0?r=setTimeout(d,t-e):(r=void 0,n||(l=c()))}const h=function(...e){if(s&&this!==s&&Object.getPrototypeOf(this)===Object.getPrototypeOf(s))throw new Error("Debounced method called with different contexts of the same prototype.");s=this,o=e,a=Date.now();const i=n&&!r;return r||(r=setTimeout(d,t)),i&&(l=c()),l};return h.clear=()=>{r&&(clearTimeout(r),r=void 0)},h.flush=()=>{r&&h.trigger()},h.trigger=()=>{l=c(),h.clear()},h}wt.exports.debounce=yt,wt.exports=yt;var xt=fe(wt.exports),bt=fe((function e(t,i){if(t===i)return!0;if(t&&i&&"object"==typeof t&&"object"==typeof i){if(t.constructor!==i.constructor)return!1;var n,s,o;if(Array.isArray(t)){if((n=t.length)!=i.length)return!1;for(s=n;0!=s--;)if(!e(t[s],i[s]))return!1;return!0}if(t instanceof Map&&i instanceof Map){if(t.size!==i.size)return!1;for(s of t.entries())if(!i.has(s[0]))return!1;for(s of t.entries())if(!e(s[1],i.get(s[0])))return!1;return!0}if(t instanceof Set&&i instanceof Set){if(t.size!==i.size)return!1;for(s of t.entries())if(!i.has(s[0]))return!1;return!0}if(ArrayBuffer.isView(t)&&ArrayBuffer.isView(i)){if((n=t.length)!=i.length)return!1;for(s=n;0!=s--;)if(t[s]!==i[s])return!1;return!0}if(t.constructor===RegExp)return t.source===i.source&&t.flags===i.flags;if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===i.valueOf();if(t.toString!==Object.prototype.toString)return t.toString()===i.toString();if((n=(o=Object.keys(t)).length)!==Object.keys(i).length)return!1;for(s=n;0!=s--;)if(!Object.prototype.hasOwnProperty.call(i,o[s]))return!1;for(s=n;0!=s--;){var r=o[s];if(!e(t[r],i[r]))return!1}return!0}return t!=t&&i!=i}));function kt(e){const t=e.get(0),i={};if(t.hasAttributes())for(const e of t.attributes)i[e.name]=e.value;return i}class St{constructor(e){const t=window.getSelection();if(!t)throw new Error("Selection object is null.");this.selection=t,this.container=e,this.range=this.getCurrentRange()}getCurrentRange(){if(this.selection.rangeCount>0){const e=this.selection.getRangeAt(0);return new M(e)}return new M}sync(){this.container.contains(this.range.commonAncestor)&&(this.selection.removeAllRanges(),this.selection.addRange(this.range.get()))}updateByRange(){const e=this.getCurrentRange();this.container.contains(e.commonAncestor)&&(this.range.startNode.get(0)===e.startNode.get(0)&&this.range.startOffset===e.startOffset&&this.range.endNode.get(0)===e.endNode.get(0)&&this.range.endOffset===e.endOffset||(this.range=e))}updateByBookmark(){const e=this.range,t=this.container,i=t.find("lake-box[focus]");if(i.length>0)return tt(e,{anchor:new T,focus:i}),void this.sync();tt(e,{anchor:t.find('lake-bookmark[type="anchor"]'),focus:t.find('lake-bookmark[type="focus"]')}),this.sync()}getAppliedItems(){const e=[];return function(e,t){let i=t.startNode;for(i.isText&&(i=i.parent());i.length>0&&i.isInside;)e.push({node:i,name:i.name,attributes:kt(i),styles:m(i.attr("style"))}),i=i.parent()}(e,this.range),function(e,t){const i=t.startNode;let n;if(i.isText&&i.text().length===t.startOffset){const e=i.next();e.length>0&&e.isElement&&(n=e)}if(i.isElement){const e=i.children();if(e.length>0){const i=e[t.startOffset];i&&i.isElement&&(n=i)}}if(n){let t=n;for(;t.length>0;)t.isElement&&e.push({node:t,name:t.name,attributes:kt(t),styles:m(t.attr("style"))}),t=t.first()}}(e,this.range),e}insertBookmark(){return Je(this.range)}toBookmark(e){return tt(this.range,e)}insertNode(e){return Ye(this.range,e)}insertFragment(e){return st(this.range,e)}deleteContents(){return nt(this.range)}setBlocks(e){return ot(this.range,e)}splitBlock(){return rt(this.range)}splitMarks(e){return ct(this.range,e)}addMark(e){return ht(this.range,e)}removeMark(e){return ut(this.range,e)}fixList(){return it(this.range)}insertLink(e){return mt(this.range,e)}selectBox(e){let t=e;t=e instanceof Ve?e.node:e,this.range.selectBox(t),this.sync()}insertBox(e,t){const i=gt(this.range,e,t);if(!i)throw new Error(`Box "${e}" cannot be inserted outside the editor.`);return i}removeBox(e=null){return e&&this.selectBox(e),vt(this.range)}}class Ct{constructor(e){this.commandMap=new Map,this.selection=e}add(e,t){this.commandMap.set(e,t)}delete(e){this.commandMap.delete(e)}getNames(){return Array.from(this.commandMap.keys())}has(e){return void 0!==this.commandMap.get(e)}getItem(e){const t=this.commandMap.get(e);if(void 0===t)throw new Error(`Command "${e}" has not been defined yet.`);return t}isDisabled(e){const t=this.getItem(e);if(!t.isDisabled)return!1;const i=this.selection.getAppliedItems();return t.isDisabled(i)}isSelected(e){const t=this.getItem(e);if(!t.isSelected)return!1;const i=this.selection.getAppliedItems();return t.isSelected(i)}selectedValues(e){const t=this.getItem(e);if(!t.selectedValues)return[];const i=this.selection.getAppliedItems();return t.selectedValues(i)}execute(e,...t){const i=this.selection.container,n=this.selection.range;i.contains(n.commonAncestor)||n.shrinkAfter(i);this.getItem(e).execute.apply(this,t),A(`Command "${e}" executed`)}}class Bt{constructor(e){this.canSave=!0,this.list=[],this.index=0,this.limit=100,this.event=new we,this.selection=e,this.container=e.container}removeBookmark(e){return e.replace(/(<lake-box[^>]+)\s+focus="\w+"([^>]*>)/gi,"$1$2").replace(/<lake-bookmark\s+type="anchor">\s*<\/lake-bookmark>/gi,"").replace(/<lake-bookmark\s+type="focus">\s*<\/lake-bookmark>/gi,"")}getValue(e){return new Xe(e).getHTML()}addIdToBoxes(e){e.find("lake-box").each((e=>{const t=new T(e),i=`${t.attr("name")}-${t.attr("value")}`;t.attr("id",i)}))}removeIdfromBoxes(e){e.find("lake-box").each((e=>{new T(e).removeAttr("id")}))}morphContainer(e){const t=this.container,i={beforeChildrenUpdated:e=>{if("lake-box"===new T(e).name)return!1},afterAttributeUpdated:(e,i)=>{const n=new T(i);if(["name","value"].indexOf(e)>=0&&"lake-box"===n.name){Fe(n).unmount();ge(t.id).delete(n.id)}}},n=e.clone(!0);this.addIdToBoxes(t),this.addIdToBoxes(n),he(t,n,{callbacks:i}),this.removeIdfromBoxes(t),this.removeIdfromBoxes(n)}get canUndo(){return this.index>1&&!!this.list[this.index-2]}get canRedo(){return!!this.list[this.index]}cloneContainer(){const e=this.selection.range,t=this.container.clone(!0);if(t.find("lake-box").each((e=>{Fe(e).getContainer().empty()})),!this.container.contains(e.commonAncestor))return t;if(e.isInsideBox){const i=e.commonAncestor.closest("lake-box").path(),n=t.find(i),s=e.clone();return s.selectBox(n),Je(s),t}const i=e.startNode.path(),n=e.endNode.path(),s=t.find(i),o=t.find(n),r=e.clone();return r.setStart(s,e.startOffset),r.setEnd(o,e.endOffset),Je(r),t}undo(){if(!this.list[this.index-2])return;this.selection.insertBookmark();const e=this.getValue(this.container);for(;this.index>1;){const t=this.list[this.index-2];if(!t)break;this.index--;const i=this.getValue(t);if(this.removeBookmark(i)!==this.removeBookmark(e)){this.morphContainer(t),this.event.emit("undo",i);break}}this.selection.updateByBookmark(),A(`History undone (index: ${this.index})`)}redo(){if(!this.list[this.index])return;this.selection.insertBookmark();const e=this.getValue(this.container);for(;this.index<this.list.length;){const t=this.list[this.index];if(!t)break;this.index++;const i=this.getValue(t);if(this.removeBookmark(i)!==this.removeBookmark(e)){this.morphContainer(t),this.event.emit("redo",i);break}}this.selection.updateByBookmark(),A(`History redone (index: ${this.index})`)}continue(){this.canSave=!0}pause(){this.canSave=!1}save(e={}){var t,i,n;const s=null!==(t=e.inputType)&&void 0!==t?t:"",o=null!==(i=e.update)&&void 0!==i&&i,r=null===(n=e.emitEvent)||void 0===n||n;if(!this.canSave)return;const a=this.cloneContainer(),l=this.getValue(a);this.list[this.index-1]&&this.removeBookmark(this.getValue(this.list[this.index-1]))===this.removeBookmark(l)||(o?this.list.splice(this.index-1,1/0,a):(this.list.splice(this.index,1/0,a),this.index++),this.list.length>this.limit&&(this.list.shift(),this.index=this.list.length),A(`History saved (index: ${this.index}, inputType: "${s}", update: ${o}, emitEvent: ${r})`),r&&this.event.emit("save",f(l),{inputType:s,update:o,emitEvent:r}))}}var _t={};Object.defineProperty(_t,"__esModule",{value:!0});for(var At="undefined"!=typeof window&&/Mac|iPod|iPhone|iPad/.test(window.navigator.platform),Lt={alt:"altKey",control:"ctrlKey",meta:"metaKey",shift:"shiftKey"},Et={add:"+",break:"pause",cmd:"meta",command:"meta",ctl:"control",ctrl:"control",del:"delete",down:"arrowdown",esc:"escape",ins:"insert",left:"arrowleft",mod:At?"meta":"control",opt:"alt",option:"alt",return:"enter",right:"arrowright",space:" ",spacebar:" ",up:"arrowup",win:"meta",windows:"meta"},Tt={backspace:8,tab:9,enter:13,shift:16,control:17,alt:18,pause:19,capslock:20,escape:27," ":32,pageup:33,pagedown:34,end:35,home:36,arrowleft:37,arrowup:38,arrowright:39,arrowdown:40,insert:45,delete:46,meta:91,numlock:144,scrolllock:145,";":186,"=":187,",":188,"-":189,".":190,"/":191,"`":192,"[":219,"\\":220,"]":221,"'":222},It=1;It<20;It++)Tt["f"+It]=111+It;function Mt(e,t,i){t&&!("byKey"in t)&&(i=t,t=null),Array.isArray(e)||(e=[e]);var n=e.map((function(e){return Pt(e,t)})),s=function(e){return n.some((function(t){return Dt(t,e)}))};return null==i?s:s(i)}function Pt(e,t){var i=t&&t.byKey,n={},s=(e=e.replace("++","+add")).split("+"),o=s.length;for(var r in Lt)n[Lt[r]]=!1;var a=!0,l=!1,c=void 0;try{for(var d,h=s[Symbol.iterator]();!(a=(d=h.next()).done);a=!0){var p=d.value,u=p.endsWith("?")&&p.length>1;u&&(p=p.slice(0,-1));var m=Ot(p),g=Lt[m];if(p.length>1&&!g&&!Et[p]&&!Tt[m])throw new TypeError('Unknown modifier: "'+p+'"');1!==o&&g||(i?n.key=m:n.which=Nt(p)),g&&(n[g]=!u||null)}}catch(e){l=!0,c=e}finally{try{!a&&h.return&&h.return()}finally{if(l)throw c}}return n}function Dt(e,t){for(var i in e){var n=e[i],s=void 0;if(null!=n&&((null!=(s="key"===i&&null!=t.key?t.key.toLowerCase():"which"===i?91===n&&93===t.which?91:t.which:t[i])||!1!==n)&&s!==n))return!1}return!0}function Nt(e){return e=Ot(e),Tt[e]||e.toUpperCase().charCodeAt(0)}function Ot(e){return e=e.toLowerCase(),e=Et[e]||e}_t.default=Mt,_t.isHotkey=Mt,_t.isCodeHotkey=function(e,t){return Mt(e,t)};var Zt=_t.isKeyHotkey=function(e,t){return Mt(e,{byKey:!0},t)};_t.parseHotkey=Pt,_t.compareHotkey=Dt,_t.toKeyCode=Nt,_t.toKeyName=Ot;class Ht{constructor(e){this.keydownEventList=[],this.keyupEventList=[],this.container=e,this.container.on("keydown",(e=>{const t=e;if(!t.isComposing&&!t.defaultPrevented)for(const e of this.keydownEventList)if(Zt(e.type,t)&&!1===e.listener(t))break})),this.container.on("keyup",(e=>{const t=e;if(!t.isComposing&&!t.defaultPrevented)for(const e of this.keyupEventList)if(Zt(e.type,t)&&!1===e.listener(t))break}))}setKeydown(e,t){this.keydownEventList.push({type:e,listener:t})}setKeyup(e,t){this.keyupEventList.push({type:e,listener:t})}keydown(e){for(const t of this.keydownEventList)if(t.type===e&&!1===t.listener(new KeyboardEvent(e)))break}keyup(e){for(const t of this.keyupEventList)if(t.type===e&&!1===t.listener(new KeyboardEvent(e)))break}}const zt={value:"<p><br /></p>",readonly:!1,spellcheck:!1,tabIndex:0,placeholder:"",indentWithTab:!0,lang:"en-US",minChangeSize:5,historySize:100,onMessage:(e,t)=>{"success"!==e?"warning"!==e?"error"===e&&console.error(t):console.warn(t):console.log(t)},slash:!1,mention:!1};class $t{constructor(e){if(this.unsavedInputData="",this.unsavedInputCount=0,this.state={appliedItems:[],disabledNameMap:new Map,selectedNameMap:new Map,selectedValuesMap:new Map},this.unmountPluginMap=new Map,this.isComposing=!1,this.event=new we,this.box=$t.box,this.popup=null,this.copyListener=e=>{const t=this.selection.getCurrentRange();this.container.contains(t.commonAncestor)&&this.event.emit("copy",e)},this.cutListener=e=>{const t=this.selection.getCurrentRange();this.container.contains(t.commonAncestor)&&this.event.emit("cut",e)},this.pasteListener=e=>{const t=this.selection.getCurrentRange();this.container.contains(t.commonAncestor)&&this.event.emit("paste",e)},this.selectionchangeListener=()=>{this.updateSelectionRange(),this.updateBoxSelectionStyle(),this.emitStateChangeEvent()},this.clickListener=e=>{const t=new T(e.target);t.get(0).isConnected&&this.event.emit("click",t)},this.updateSelectionRange=xt((()=>{this.selection.updateByRange()}),1,{immediate:!0}),this.updateBoxSelectionStyle=xt((()=>{if(0===this.root.first().length)return;const e=this.selection.getCurrentRange(),t=e.clone();t.adjustBox(),this.container.find("lake-box").each((i=>{const n=Fe(i),s=n.getContainer();if(0!==s.length){if(e.compareBeforeNode(s)<0&&e.compareAfterNode(s)>0&&(!e.isCollapsed||e.startNode.get(0)!==s.get(0)||0!==e.startOffset))return s.removeClass("lake-box-hovered"),s.removeClass("lake-box-selected"),s.removeClass("lake-box-focused"),s.addClass("lake-box-activated"),void n.event.emit("focus");if(t.intersectsNode(n.node))return s.removeClass("lake-box-activated"),void(e.isCollapsed?(s.removeClass("lake-box-hovered"),s.removeClass("lake-box-selected"),s.addClass("lake-box-focused"),n.event.emit("focus")):(s.removeClass("lake-box-focused"),s.addClass("lake-box-selected"),n.event.emit("blur")));s.removeClass("lake-box-activated"),s.removeClass("lake-box-focused"),s.removeClass("lake-box-selected"),n.event.emit("blur")}}))}),50,{immediate:!0}),this.emitStateChangeEvent=xt((()=>{const e=this.command.getNames();let t=this.selection.getAppliedItems();t.length>0&&!this.container.contains(t[0].node)&&(t=[]);const i=new Map,n=new Map,s=new Map;if(t.length>0)for(const o of e){const e=this.command.getItem(o);if(e.isDisabled&&e.isDisabled(t)&&i.set(o,!0),e.isSelected&&e.isSelected(t)&&n.set(o,!0),e.selectedValues){const i=e.selectedValues(t);i.length>0&&s.set(o,i)}}const o={appliedItems:t,disabledNameMap:i,selectedNameMap:n,selectedValuesMap:s};bt(o,this.state)||(this.toolbar&&this.toolbar.updateState(o),this.event.emit("statechange",o),this.state=o)}),50,{immediate:!1}),!e.root)throw new Error("The root of the config must be specified.");this.root=I(e.root),this.toolbar=e.toolbar,this.config=Object.assign({},zt);for(const t of Object.keys(e))this.config[t]=e[t];this.containerWrapper=I('<div class="lake-container-wrapper" />'),this.container=I('<div class="lake-container" />'),this.overlayContainer=I('<div class="lake-overlay" />'),this.readonly=this.config.readonly,this.root.addClass("lake-custom-properties"),this.container.attr({contenteditable:this.readonly?"false":"true",spellcheck:this.config.spellcheck?"true":"false",tabindex:this.config.tabIndex.toString(),"data-readonly":this.readonly?"true":"false"}),""!==this.config.placeholder&&this.container.attr("placeholder",this.config.placeholder),this.selection=new St(this.container),this.command=new Ct(this.selection),this.history=new Bt(this.selection),this.history.limit=this.config.historySize,this.keystroke=new Ht(this.container),xe.set(this.container.id,this)}togglePlaceholderClass(e){const t="lake-placeholder";"<p><br /></p>"===(e=f(e)).replace("<focus />","")?this.container.addClass(t):this.container.removeClass(t)}moveBoxStripText(){const e=this.selection,t=e.range,i=t.startNode.closest(".lake-box-strip"),n=i.closest("lake-box");if("inline"===Fe(n).type)t.isBoxStart?(t.setStartBefore(n),t.collapseToStart()):(t.setStartAfter(n),t.collapseToStart());else{const e=I("<p />");t.isBoxStart?n.before(e):n.after(e),t.setStart(e,0),t.collapseToStart()}const s=i.text();i.html("<br />"),e.insertNode(document.createTextNode(s))}resetUnsavedInputData(){this.unsavedInputData="",this.unsavedInputCount=0}handleInputEvent(e){var t;this.selection.updateByRange();const i=this.selection.range;if(i.isInsideBox)return;if(i.isBoxStart||i.isBoxEnd)return this.moveBoxStripText(),void this.history.save();if("insertText"===(e instanceof CompositionEvent?"insertText":e.inputType)){const i=null!==(t=e.data)&&void 0!==t?t:"";return i.length>1?void this.history.save({inputType:"insertText",update:!1}):(this.unsavedInputData+=i,this.unsavedInputCount++,void(this.unsavedInputData.length<this.config.minChangeSize?this.history.save({inputType:"insertText",update:this.unsavedInputCount>1}):(this.history.save({inputType:"insertText",update:!0}),this.resetUnsavedInputData())))}this.history.save()}bindInputEvents(){this.container.on("compositionstart",(()=>{this.isComposing=!0,this.container.removeClass("lake-placeholder")})),this.container.on("compositionend",(e=>{this.isComposing=!1,this.handleInputEvent(e)})),this.container.on("input",(e=>{const t=e;this.isComposing=t.isComposing,this.isComposing||this.handleInputEvent(e)}))}bindHistoryEvents(){const e=e=>{this.fixContent()&&(this.history.save({update:!0,emitEvent:!1}),e=this.getValue()),this.emitStateChangeEvent(),this.togglePlaceholderClass(e),this.scrollToCaret(),this.event.emit("change",e)};this.history.event.on("undo",(t=>{this.renderBoxes(),e(t),this.resetUnsavedInputData()})),this.history.event.on("redo",(t=>{this.renderBoxes(),e(t),this.resetUnsavedInputData()})),this.history.event.on("save",((t,i)=>{this.removeBoxGarbage(),e(t),"insertText"!==i.inputType&&(this.selection.sync(),this.resetUnsavedInputData())}))}get hasFocus(){const e=document.activeElement;return!!e&&I(e).closest(".lake-container").get(0)===this.container.get(0)}get locale(){return Ze(this.config.lang)}fixContent(){const e=this.selection.range;let t=!1,i=this.container.children();for(const e of i)(e.isBlock||e.isMark)&&""===e.html()&&(e.remove(),t=!0,A(`Content fixed: empty tag "${e.name}" was removed`));if(i=this.container.children(),0===i.length)this.container.html("<p><br /></p>"),e.shrinkBefore(this.container),t=!0,A("Content fixed: default paragraph was added");else if(1===i.length){const n=i[0];if(n.isVoid){const i=I("<p />");n.before(i),i.append(n),e.shrinkAfter(i),t=!0,A(`Content fixed: void element "${n.name}" was wrapped in paragraph`)}}return e.adjustBr(),t}setPluginConfig(e,t){"object"!=typeof this.config[e]&&(this.config[e]={});for(const i of Object.keys(t))void 0===this.config[e][i]&&(this.config[e][i]=t[i])}removeBoxGarbage(){const e=ge(this.container.id);for(const t of e.values())t.node.get(0).isConnected||(t.unmount(),e.delete(t.node.id))}renderBoxes(){this.removeBoxGarbage();const e=this.container,t=ge(e.id);e.find("lake-box").each((e=>{const i=I(e);if(t.get(i.id))return;Fe(i).render()}))}focus(){this.container.focus()}blur(){this.container.blur()}scrollToCaret(){const e=this.selection.range;if(e.isBox)return;const t=e.getRect();if(0===t.x||0===t.y)return;const i=this.container.get(0).getBoundingClientRect(),n=I('<div class="lake-artificial-caret" />'),s=t.x-i.x,o=t.y-i.y;n.css({position:"absolute",top:`${o}px`,left:`${s}px`,width:`${t.width}px`,height:`${t.height}px`,"z-index":"-1"}),this.overlayContainer.find(".lake-artificial-caret").remove(),this.overlayContainer.append(n),ue(n,{behavior:"instant",block:"nearest",inline:"nearest"}),n.remove()}setValue(e){e=g(e);const t=new Xe(e),i=t.getFragment();this.container.empty(),this.togglePlaceholderClass(t.getHTML()),this.container.append(i),this.renderBoxes(),this.selection.updateByBookmark()}getValue(){const e=this.history.cloneContainer();let t=new Xe(e).getHTML();return t=f(t),t}render(){const e=g(this.config.value),t=new Xe(e),i=t.getFragment();this.root.empty(),this.root.append(this.containerWrapper),this.containerWrapper.append(this.container),this.containerWrapper.append(this.overlayContainer),this.togglePlaceholderClass(t.getHTML()),this.container.append(i),this.unmountPluginMap=$t.plugin.loadAll(this),this.readonly||(this.selection.updateByBookmark(),this.history.save({emitEvent:!1})),this.renderBoxes(),this.toolbar&&this.toolbar.render(this),document.addEventListener("copy",this.copyListener),this.readonly||(document.addEventListener("cut",this.cutListener),document.addEventListener("paste",this.pasteListener),document.addEventListener("selectionchange",this.selectionchangeListener),document.addEventListener("click",this.clickListener),this.bindInputEvents(),this.bindHistoryEvents())}unmount(){this.updateSelectionRange.flush(),this.updateBoxSelectionStyle.flush(),this.emitStateChangeEvent.flush();for(const e of this.unmountPluginMap.keys()){const t=this.unmountPluginMap.get(e);t&&(t(),A(`Plugin "${e}" unmounted`))}this.toolbar&&this.toolbar.unmount(),this.removeBoxGarbage(),this.container.find("lake-box").each((e=>{Fe(I(e)).unmount()})),this.event.removeAllListeners(),this.history.event.removeAllListeners(),this.root.off(),this.root.removeClass("lake-custom-properties"),this.root.empty(),document.removeEventListener("copy",this.copyListener),this.readonly||(document.removeEventListener("cut",this.cutListener),document.removeEventListener("paste",this.pasteListener),document.removeEventListener("selectionchange",this.selectionchangeListener),document.removeEventListener("click",this.clickListener))}}$t.version="0.2.3",$t.box=new class{add(e){ye.set(e.name,e)}remove(e){ye.delete(e)}getNames(){return Array.from(ye.keys())}},$t.plugin=new class{constructor(){this.pluginMap=new Map}add(e,t){if(this.pluginMap.get(e))throw new Error(`Plugin "${e}" is already defined.`);this.pluginMap.set(e,t)}loadAll(e){const t=new Map;for(const i of this.pluginMap.keys()){const n=this.pluginMap.get(i);if(n&&!1!==e.config[i]){const s=n(e);s&&t.set(i,s)}}return t}};const Vt=[{icon:n.get("numberedList"),value:"numbered",text:e=>e.toolbar.numberedList()},{icon:n.get("bulletedList"),value:"bulleted",text:e=>e.toolbar.bulletedList()},{icon:n.get("checklist"),value:"checklist",text:e=>e.toolbar.checklist()}],Ft=[{icon:n.get("alignLeft"),value:"left",text:e=>e.toolbar.alignLeft()},{icon:n.get("alignCenter"),value:"center",text:e=>e.toolbar.alignCenter()},{icon:n.get("alignRight"),value:"right",text:e=>e.toolbar.alignRight()},{icon:n.get("alignJustify"),value:"justify",text:e=>e.toolbar.alignJustify()}],Rt=[{icon:n.get("increaseIndent"),value:"increase",text:e=>e.toolbar.increaseIndent()},{icon:n.get("decreaseIndent"),value:"decrease",text:e=>e.toolbar.decreaseIndent()}],qt=[{icon:n.get("italic"),value:"italic",text:e=>e.toolbar.italic()},{icon:n.get("underline"),value:"underline",text:e=>e.toolbar.underline()},{icon:n.get("strikethrough"),value:"strikethrough",text:e=>e.toolbar.strikethrough()},{icon:n.get("superscript"),value:"superscript",text:e=>e.toolbar.superscript()},{icon:n.get("subscript"),value:"subscript",text:e=>e.toolbar.subscript()},{icon:n.get("code"),value:"code",text:e=>e.toolbar.code()}],jt=["#f5222d","#fa541c","#fa8c16","#faad14","#fadb14","#a0d911","#52c41a","#13c2c2","#1677ff","#2f54eb","#722ed1","#eb2f96","#fff1f0","#fff2e8","#fff7e6","#fffbe6","#feffe6","#fcffe6","#f6ffed","#e6fffb","#e6f4ff","#f0f5ff","#f9f0ff","#fff0f6","#ffccc7","#ffd8bf","#ffe7ba","#fff1b8","#ffffb8","#f4ffb8","#d9f7be","#b5f5ec","#bae0ff","#d6e4ff","#efdbff","#ffd6e7","#ffa39e","#ffbb96","#ffd591","#ffe58f","#fffb8f","#eaff8f","#b7eb8f","#87e8de","#91caff","#adc6ff","#d3adf7","#ffadd2","#ff7875","#ff9c6e","#ffc069","#ffd666","#fff566","#d3f261","#95de64","#5cdbd3","#69b1ff","#85a5ff","#b37feb","#ff85c0","#ff4d4f","#ff7a45","#ffa940","#ffc53d","#ffec3d","#bae637","#73d13d","#36cfc9","#4096ff","#597ef7","#9254de","#f759ab","#cf1322","#d4380d","#d46b08","#d48806","#d4b106","#7cb305","#389e0d","#08979c","#0958d9","#1d39c4","#531dab","#c41d7f","#a8071a","#ad2102","#ad4e00","#ad6800","#ad8b00","#5b8c00","#237804","#006d75","#003eb3","#10239e","#391085","#9e1068","#820014","#871400","#873800","#874d00","#876800","#3f6600","#135200","#00474f","#002c8c","#061178","#22075e","#780650","#5c0011","#610b00","#612500","#613400","#614700","#254000","#092b00","#002329","#001d66","#030852","#120338","#520339","#000000","#1f1f1f","#262626","#434343","#595959","#8c8c8c","#bfbfbf","#d9d9d9","#f0f0f0","#f5f5f5","#fafafa","#ffffff"],Wt=[{icon:n.get("removeFormat"),value:"",text:e=>e.toolbar.removeColor()}];for(const e of jt)Wt.push({value:e.toLowerCase(),text:e.toUpperCase()});const Ut=new Map([["strong","bold"],["em","italic"],["i","italic"],["u","underline"],["s","strikethrough"],["sup","superscript"],["sub","subscript"],["code","code"]]),Kt=[{name:"undo",type:"button",icon:n.get("undo"),tooltip:e=>e.toolbar.undo(),onClick:(e,t)=>{e.command.execute(t)}},{name:"redo",type:"button",icon:n.get("redo"),tooltip:e=>e.toolbar.redo(),onClick:(e,t)=>{e.command.execute(t)}},{name:"selectAll",type:"button",icon:n.get("selectAll"),tooltip:e=>e.toolbar.selectAll(),onClick:(e,t)=>{e.command.execute(t)}},{name:"paragraph",type:"button",icon:n.get("paragraph"),tooltip:e=>e.toolbar.paragraph(),isSelected:e=>!!e.find((e=>"p"===e.name)),onClick:e=>{e.command.execute("heading","p")}},{name:"blockQuote",type:"button",icon:n.get("blockQuote"),tooltip:e=>e.toolbar.blockQuote(),onClick:(e,t)=>{e.command.execute(t)}},{name:"numberedList",type:"button",icon:n.get("numberedList"),tooltip:e=>e.toolbar.numberedList(),isSelected:e=>!!e.find((e=>"ol"===e.name)),onClick:e=>{e.command.execute("list","numbered")}},{name:"bulletedList",type:"button",icon:n.get("bulletedList"),tooltip:e=>e.toolbar.bulletedList(),isSelected:e=>!!e.find((e=>"ul"===e.name&&!e.node.hasAttr("type"))),onClick:e=>{e.command.execute("list","bulleted")}},{name:"checklist",type:"button",icon:n.get("checklist"),tooltip:e=>e.toolbar.checklist(),isSelected:e=>!!e.find((e=>"ul"===e.name&&"checklist"===e.node.attr("type"))),onClick:e=>{e.command.execute("list","checklist")}},{name:"alignLeft",type:"button",icon:n.get("alignLeft"),tooltip:e=>e.toolbar.alignLeft(),isSelected:e=>!!e.find((e=>e.node.isBlock&&"left"===e.node.css("text-align"))),onClick:e=>{e.command.execute("align","left")}},{name:"alignCenter",type:"button",icon:n.get("alignCenter"),tooltip:e=>e.toolbar.alignCenter(),isSelected:e=>!!e.find((e=>e.node.isBlock&&"center"===e.node.css("text-align"))),onClick:e=>{e.command.execute("align","center")}},{name:"alignRight",type:"button",icon:n.get("alignRight"),tooltip:e=>e.toolbar.alignRight(),isSelected:e=>!!e.find((e=>e.node.isBlock&&"right"===e.node.css("text-align"))),onClick:e=>{e.command.execute("align","right")}},{name:"alignJustify",type:"button",icon:n.get("alignJustify"),tooltip:e=>e.toolbar.alignJustify(),isSelected:e=>!!e.find((e=>e.node.isBlock&&"justify"===e.node.css("text-align"))),onClick:e=>{e.command.execute("align","justify")}},{name:"increaseIndent",type:"button",icon:n.get("increaseIndent"),tooltip:e=>e.toolbar.increaseIndent(),onClick:e=>{e.command.execute("indent","increase")}},{name:"decreaseIndent",type:"button",icon:n.get("decreaseIndent"),tooltip:e=>e.toolbar.decreaseIndent(),onClick:e=>{e.command.execute("indent","decrease")}},{name:"bold",type:"button",icon:n.get("bold"),tooltip:e=>e.toolbar.bold(),onClick:(e,t)=>{e.command.execute(t)}},{name:"italic",type:"button",icon:n.get("italic"),tooltip:e=>e.toolbar.italic(),onClick:(e,t)=>{e.command.execute(t)}},{name:"underline",type:"button",icon:n.get("underline"),tooltip:e=>e.toolbar.underline(),onClick:(e,t)=>{e.command.execute(t)}},{name:"strikethrough",type:"button",icon:n.get("strikethrough"),tooltip:e=>e.toolbar.strikethrough(),onClick:(e,t)=>{e.command.execute(t)}},{name:"superscript",type:"button",icon:n.get("superscript"),tooltip:e=>e.toolbar.superscript(),onClick:(e,t)=>{e.command.execute(t)}},{name:"subscript",type:"button",icon:n.get("subscript"),tooltip:e=>e.toolbar.subscript(),onClick:(e,t)=>{e.command.execute(t)}},{name:"code",type:"button",icon:n.get("code"),tooltip:e=>e.toolbar.code(),onClick:(e,t)=>{e.command.execute(t)}},{name:"removeFormat",type:"button",icon:n.get("removeFormat"),tooltip:e=>e.toolbar.removeFormat(),onClick:(e,t)=>{e.command.execute(t)}},{name:"formatPainter",type:"button",icon:n.get("formatPainter"),tooltip:e=>e.toolbar.formatPainter(),onClick:(e,t)=>{e.command.execute(t)}},{name:"link",type:"button",icon:n.get("link"),tooltip:e=>e.toolbar.link(),onClick:(e,t)=>{e.command.execute(t)}},{name:"hr",type:"button",icon:n.get("hr"),tooltip:e=>e.toolbar.hr(),onClick:(e,t)=>{e.command.execute(t)}},{name:"codeBlock",type:"button",icon:n.get("codeBlock"),tooltip:e=>e.toolbar.codeBlock(),onClick:(e,t)=>{e.command.execute(t)}},{name:"video",type:"button",icon:n.get("video"),tooltip:e=>e.toolbar.video(),onClick:(e,t)=>{e.command.execute(t)}},{name:"equation",type:"button",icon:n.get("equation"),tooltip:e=>e.toolbar.equation(),onClick:(e,t)=>{e.command.execute(t)}},{name:"heading",type:"dropdown",downIcon:n.get("down"),defaultValue:"p",tooltip:e=>e.toolbar.heading(),width:"100px",menuType:"list",menuItems:[{value:"h1",text:e=>`<span style="font-weight: bold; font-size: 26px;">${e.toolbar.heading1()}</span>`},{value:"h2",text:e=>`<span style="font-weight: bold; font-size: 24px;">${e.toolbar.heading2()}</span>`},{value:"h3",text:e=>`<span style="font-weight: bold; font-size: 22px;">${e.toolbar.heading3()}</span>`},{value:"h4",text:e=>`<span style="font-weight: bold; font-size: 20px;">${e.toolbar.heading4()}</span>`},{value:"h5",text:e=>`<span style="font-weight: bold; font-size: 18px;">${e.toolbar.heading5()}</span>`},{value:"h6",text:e=>`<span style="font-weight: bold; font-size: 16px;">${e.toolbar.heading6()}</span>`},{value:"p",text:e=>e.toolbar.paragraph()}],onSelect:(e,t)=>{e.command.execute("heading",t)}},{name:"list",type:"dropdown",downIcon:n.get("down"),icon:n.get("list"),tooltip:e=>e.toolbar.list(),menuType:"list",menuItems:Vt,onSelect:(e,t)=>{e.command.execute("list",t)}},{name:"align",type:"dropdown",downIcon:n.get("down"),icon:n.get("alignLeft"),tooltip:e=>e.toolbar.align(),menuType:"list",menuItems:Ft,onSelect:(e,t)=>{e.command.execute("align",t)}},{name:"indent",type:"dropdown",downIcon:n.get("down"),icon:n.get("increaseIndent"),tooltip:e=>e.toolbar.indent(),menuType:"list",menuItems:Rt,onSelect:(e,t)=>{e.command.execute("indent",t)}},{name:"fontFamily",type:"dropdown",downIcon:n.get("down"),defaultValue:"Segoe UI",tooltip:e=>e.toolbar.fontFamily(),width:"100px",menuType:"list",menuItems:[{value:"Arial",text:'<span style="font-family: Arial;">Arial</span>'},{value:"Arial Black",text:"<span style=\"font-family: 'Arial Black';\">Arial Black</span>"},{value:"Comic Sans MS",text:"<span style=\"font-family: 'Comic Sans MS';\">Comic Sans MS</span>"},{value:"Courier New",text:"<span style=\"font-family: 'Courier New';\">Courier New</span>"},{value:"Georgia",text:'<span style="font-family: Georgia;">Georgia</span>'},{value:"Helvetica",text:'<span style="font-family: Helvetica;">Helvetica</span>'},{value:"Impact",text:'<span style="font-family: Impact;">Impact</span>'},{value:"Segoe UI",text:"<span style=\"font-family: 'Segoe UI';\">Segoe UI</span>"},{value:"Tahoma",text:'<span style="font-family: Tahoma;">Tahoma</span>'},{value:"Times New Roman",text:"<span style=\"font-family: 'Times New Roman';\">Times New Roman</span>"},{value:"Trebuchet MS",text:"<span style=\"font-family: 'Trebuchet MS';\">Trebuchet MS</span>"},{value:"Verdana",text:'<span style="font-family: Verdana;">Verdana</span>'}],onSelect:(e,t)=>{e.command.execute("fontFamily",t)}},{name:"fontSize",type:"dropdown",downIcon:n.get("down"),defaultValue:"16px",tooltip:e=>e.toolbar.fontSize(),width:"65px",menuType:"list",menuItems:[{value:"12px",text:"12px"},{value:"14px",text:"14px"},{value:"16px",text:"16px"},{value:"18px",text:"18px"},{value:"22px",text:"22px"},{value:"24px",text:"24px"},{value:"32px",text:"32px"}],onSelect:(e,t)=>{e.command.execute("fontSize",t)}},{name:"moreStyle",type:"dropdown",icon:n.get("more"),tooltip:e=>e.toolbar.moreStyle(),menuType:"list",menuItems:qt,selectedValues:e=>{var t;const i=[];for(const n of e)if(n.node.isMark){const e=null!==(t=Ut.get(n.name))&&void 0!==t?t:n.name;i.push(e)}return i},onSelect:(e,t)=>{e.command.execute(t)}},{name:"fontColor",type:"dropdown",downIcon:n.get("down"),icon:n.get("fontColor"),accentIcon:n.get("fontColorAccent"),defaultValue:"#f5222d",tooltip:e=>e.toolbar.fontColor(),menuType:"color",menuItems:Wt,menuWidth:"296px",onSelect:(e,t)=>{e.command.execute("fontColor",t)}},{name:"highlight",type:"dropdown",downIcon:n.get("down"),icon:n.get("highlight"),accentIcon:n.get("highlightAccent"),defaultValue:"#fadb14",tooltip:e=>e.toolbar.highlight(),menuType:"color",menuItems:Wt,menuWidth:"296px",onSelect:(e,t)=>{e.command.execute("highlight",t)}},{name:"image",type:"upload",icon:n.get("image"),tooltip:e=>e.toolbar.image(),accept:"image/*",multiple:!0},{name:"file",type:"upload",icon:n.get("attachment"),tooltip:e=>e.toolbar.file(),accept:"*",multiple:!0}],Gt=["undo","redo","|","heading","|","formatPainter","removeFormat","bold","moreStyle","|","fontColor","highlight","|","align","list","indent","link","blockQuote","hr"],Xt=new Map;for(const e of Kt)Xt.set(e.name,e);var Qt={type:"block",name:"hr",render:e=>{const t=e.getEditor(),i=e.getContainer(),n=I('<div class="lake-hr"><hr /></div>');i.empty(),i.append(n),n.on("click",(()=>{t.selection.selectBox(e)}))},html:()=>"<hr />"};const Yt="#57606a",Jt="#444d56",ei="#953800",ti="#0550ae",ii="#444d56",ni="#24292e",si="#005cc5",oi="#0550ae",ri="#444d56",ai="#444d56",li="#0a3069",ci="#0550ae",di="#0550ae",hi="#116329",pi="#0550ae",ui="#cf222e",mi="#24292f",gi="#cf222e",fi="#57606a",vi="#57606a",wi="#8250df",yi="#0550ae",xi="#f6f8fa",bi="#cf222e",ki="#0550ae",Si="#005cc5",Ci="#444d56",Bi="#444d56";function _i(e){const{HighlightStyle:t,tags:i}=e;return t.define([{tag:[i.comment,i.lineComment,i.blockComment,i.docComment],color:Yt},{tag:[i.name],color:Jt},{tag:[i.variableName,i.self],color:ei},{tag:[i.typeName,i.tagName],color:ti},{tag:[i.propertyName,i.attributeName],color:ii},{tag:[i.className],color:ni},{tag:[i.labelName],color:si},{tag:[i.namespace],color:oi},{tag:[i.macroName],color:ri},{tag:[i.literal],color:ai},{tag:[i.string,i.docString,i.character,i.attributeValue,i.unit],color:li},{tag:[i.number,i.integer,i.float],color:ci},{tag:[i.bool,i.null,i.atom],color:di},{tag:[i.regexp,i.escape,i.url],color:hi},{tag:[i.color],color:pi},{tag:[i.keyword,i.operatorKeyword,i.controlKeyword,i.definitionKeyword,i.moduleKeyword],color:ui},{tag:[i.modifier],color:mi},{tag:[i.operator,i.derefOperator,i.arithmeticOperator,i.logicOperator,i.bitwiseOperator,i.compareOperator,i.updateOperator,i.definitionOperator,i.typeOperator,i.controlOperator],color:gi},{tag:[i.punctuation,i.separator,i.bracket,i.angleBracket,i.squareBracket,i.paren,i.brace,i.contentSeparator],color:fi},{tag:[i.content],color:vi},{tag:[i.meta,i.documentMeta,i.annotation,i.processingInstruction],color:wi},{tag:i.heading,fontWeight:"bold",color:yi},{tag:i.strong,fontWeight:"bold"},{tag:i.emphasis,fontStyle:"italic"},{tag:i.link,textDecoration:"underline"},{tag:i.strikethrough,textDecoration:"line-through"},{tag:[i.invalid,i.inserted,i.deleted,i.changed],color:xi},{tag:[i.definition(i.name)],color:bi},{tag:[i.constant(i.name)],color:ki},{tag:[i.function(i.variableName)],color:Si},{tag:[i.standard(i.name)],color:Ci},{tag:[i.special(i.variableName)],color:Bi}])}var Ai={type:"block",name:"codeBlock",render:e=>{var t;const i=e.getEditor(),s=I('<div class="lake-code-block" />'),o=e.getContainer();o.empty(),o.append(s);const r=s.get(0);if(!r)return;const a=window.LakeCodeMirror;if(!a)return i.readonly?void e.node.hide():(s.addClass("lake-code-block-error"),s.text('\n The code cannot be displayed because window.LakeCodeMirror is not found.\n Please check if the "lake-codemirror" library is added to this page.\n '.trim()),void s.on("click",(()=>{i.selection.selectBox(e)})));const{EditorState:l,Compartment:c,EditorView:d,keymap:h,history:p,defaultKeymap:u,historyKeymap:m,indentWithTab:g,syntaxHighlighting:f}=a,v=a.langItems,w=i.config.codeBlock,y=v.filter((e=>w.langList.indexOf(e.value)>=0)),x=new Map;for(const e of y)x.set(e.value,e);const b=e.value,k=x.get(b.lang),S=new c,C=xt((t=>{i.selection.updateByRange(),i.isComposing||(e.updateValue("code",t),i.history.save())}),1,{immediate:!1}),B=d.updateListener.of((e=>{e.docChanged&&C(e.state.doc.toString())})),_=new d({parent:r,doc:null!==(t=b.code)&&void 0!==t?t:"",extensions:[l.readOnly.of(i.readonly),d.editable.of(!i.readonly),p(),h.of([...u,...m,g]),f(_i(a)),S.of(k&&k.component?k.component():[]),B]});s.find('[contenteditable="true"]').attr("tabindex","-1");const L=new He({root:s,name:"langType",downIcon:n.get("down"),defaultValue:k?b.lang:w.defaultLang,tooltip:i.locale.codeBlock.langType(),location:"global",menuType:"list",menuHeight:"200px",menuItems:y.map((e=>({value:e.value,text:e.text}))),onSelect:t=>{e.updateValue({lang:t}),e.unmount(),e.render(),i.selection.selectBox(e),i.history.save()}});L.render(),s.on("click",(()=>{_.hasFocus||_.focus()})),e.event.on("beforeunmount",(()=>{L.unmount(),_.destroy(),A("CodeMirror destroyed")}))}};function Li(e,t,i,n){return new(i||(i=Promise))((function(s,o){function r(e){try{l(n.next(e))}catch(e){o(e)}}function a(e){try{l(n.throw(e))}catch(e){o(e)}}function l(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,a)}l((n=n.apply(e,t||[])).next())}))}
|
|
18
|
+
`;class Ve{constructor(e){if(this.event=new we,"string"==typeof e){const t=ye.get(e);if(void 0===t)throw new Error(`Box "${e}" has not been defined yet.`);const i=r(t.type),n=r(t.name);this.node=I(a`<lake-box type="${i}" name="${n}"></lake-box>`),t.value&&(this.value=t.value)}else{this.node=I(e);const t=ye.get(this.name);if(void 0===t)throw new Error(`Box "${this.name}" has not been defined yet.`);t.value&&!this.node.hasAttr("value")&&(this.value=t.value)}}addFramework(){let e=this.getContainer();0===e.length?(this.node.html($e),e=this.getContainer()):(e.off("mouseenter"),e.off("mouseleave"),e.off("click")),e.on("mouseenter",(()=>{e.hasClass("lake-box-selected")||e.hasClass("lake-box-focused")||e.hasClass("lake-box-activated")||e.addClass("lake-box-hovered")})),e.on("mouseleave",(()=>{e.removeClass("lake-box-hovered")})),e.on("click",(()=>{A(`Box "${this.name}" (id = ${this.node.id}) value:`),A(this.value)})),"block"===this.type&&this.node.isContentEditable&&e.attr("draggable","true")}get type(){return this.node.attr("type")}get name(){return this.node.attr("name")}get value(){const e=this.node.attr("value");return""===e?{}:JSON.parse(h(e))}set value(e){this.node.attr("value",d(JSON.stringify(e)))}updateValue(e,t){const i=this.value;if("string"==typeof e)i[e]=t;else for(const t of Object.keys(e))i[t]=e[t];this.value=i}getEditor(){const e=this.node.closest("div[contenteditable]"),t=e.length>0?xe.get(e.id):void 0;if(!t)throw new Error(`Box "${this.name}" (id=${this.node.id}) is not rendered in the editor.`);return t}getContainer(){return this.node.find(".lake-box-container")}setToolbar(e){let t;try{t=this.getEditor()}catch(e){}let i=null;this.event.on("focus",(()=>{i=new ze({box:this,items:e,locale:t?t.locale:void 0}),i.render()})),this.event.on("blur",(()=>{i&&(i.unmount(),i=null)}))}render(){const e=ye.get(this.name);if(void 0===e)return;this.event.emit("beforeunmount"),this.event.removeAllListeners(),this.addFramework();const t=e.render(this);if(void 0!==t){const e=this.getContainer();e.empty(),e.append(t)}A(`Box "${this.name}" (id: ${this.node.id}) rendered`)}unmount(){this.event.emit("blur"),this.event.emit("beforeunmount"),this.event.removeAllListeners(),this.node.empty(),A(`Box "${this.name}" (id: ${this.node.id}) unmounted`)}getHTML(){const e=ye.get(this.name);return void 0===e?"":void 0===e.html?this.node.outerHTML():e.html(this)}}function Fe(e){const t=ge(0);if("string"==typeof e){const i=new Ve(e);return t.set(i.node.id,i),i}const i=(e=I(e)).closestContainer();if(0===i.length){let i=t.get(e.id);return i||(i=new Ve(e),t.set(e.id,i),i)}const n=ge(i.id);let s=t.get(e.id);return s?(n.set(e.id,s),t.delete(e.id),s):(s=n.get(e.id),s||(s=new Ve(e),n.set(e.id,s),s))}function Re(e){const t=e.responseText||e.response;if(!t)return t;try{return JSON.parse(t)}catch(e){return t}}function qe(e){const t=new XMLHttpRequest;e.onProgress&&t.upload&&(t.upload.onprogress=t=>{t.total>0&&(t.percent=t.loaded/t.total*100),e.onProgress&&e.onProgress(t)});const i=new FormData,n=e.data||{};if(Object.keys(n).forEach((e=>{const t=n[e];Array.isArray(t)?t.forEach((t=>{i.append(`${e}[]`,t)})):i.append(e,t)})),e.file){const t=e.filename||"file";e.file instanceof Blob?i.append(t,e.file,e.file.name):i.append(t,e.file)}t.onerror=t=>{e.onError&&e.onError(t)},t.onload=()=>{if(t.status<200||t.status>=300){if(!e.onError)return;return e.onError(function(e,t){const i=`Cannot ${e.method} ${e.action} ${t.status}'`,n=new Error(i);return n.status=t.status,n.method=e.method,n.url=e.action,n}(e,t),Re(t))}if(e.onSuccess)return e.onSuccess(Re(t),t)},t.open(e.method,e.action,!0),e.withCredentials&&"withCredentials"in t&&(t.withCredentials=!0);const s=e.headers||{};return null!==s["X-Requested-With"]&&t.setRequestHeader("X-Requested-With","XMLHttpRequest"),Object.keys(s).forEach((e=>{null!==s[e]&&t.setRequestHeader(e,s[e])})),t.send(i),t}function je(e){const{editor:t,name:i,file:n,onError:s,onSuccess:o}=e,{requestMethod:r,requestAction:a,requestTypes:l}=t.config[i];if(l.indexOf(n.type)<0)throw s&&s(`File "${n.name}" is not allowed for uploading.`),new Error(`Cannot upload file "${n.name}" because its type "${n.type}" is not found in ['${l.join("', '")}'].`);const c=t.selection.insertBox(i,{url:URL.createObjectURL(n),status:"uploading",name:n.name,size:n.size,type:n.type,lastModified:n.lastModified});let d=qe({onProgress:e=>{const t=c.node.find(".lake-percent"),i=Math.round(e.percent);t.text(`${i<100?i:99} %`)},onError:(e,t)=>{d=null,A(e.toString(),t),c.updateValue("status","error"),c.render(),s&&s(e.toString())},onSuccess:e=>{if(d=null,!e.url)return c.updateValue("status","error"),c.render(),void(s&&s("Cannot find the url field."));c.updateValue({status:"done",url:e.url}),c.render(),t.history.save(),o&&o()},file:n,action:a,method:r});return c.event.on("beforeunmount",(()=>{d&&(d.abort(),A("Upload canceled"))})),c}var We=Object.freeze({__proto__:null,appendBreak:D,camelCase:l,changeTagName:V,debug:A,denormalizeValue:f,encode:r,fileSize:w,fixNumberedList:F,fromBase64:h,getBox:Fe,getCSS:y,getDeepElement:H,inString:c,mergeNodes:Z,modifierText:v,morph:he,nodePosition:pe,normalizeValue:g,parseStyle:m,query:I,removeBreak:N,removeZWS:$,request:qe,safeTemplate:a,scrollToNode:ue,setBlockIndent:R,splitNodes:P,template:s,toBase64:d,toHex:u,toNodeList:x,uploadFile:je,wrapNodeList:z});class Ue{constructor(e){this.fragment=null!=e?e:document.createDocumentFragment()}get(){return this.fragment}find(e){const t=[];let i=new T(this.fragment.firstChild);for(;i.length>0;)i.matches(e)?t.push(i.get(0)):i.isElement&&i.find(e).each((e=>{t.push(e)})),i=i.next();return new T(t)}append(e){I(e).each((e=>{this.fragment.appendChild(e)}))}}const Ke={id:/^[\w-]+$/,class:/^[\w- ]+$/,style:{"text-align":["left","center","right","justify","start","end"],"margin-left":/^-?\d+px$/i,"text-indent":/^-?\d+em$/i}};function Ge(){return{h1:Object.assign({},Ke),h2:Object.assign({},Ke),h3:Object.assign({},Ke),h4:Object.assign({},Ke),h5:Object.assign({},Ke),h6:Object.assign({},Ke),p:Object.assign({},Ke),blockquote:Object.assign(Object.assign({},Ke),{type:["info","tip","success","warning","error","danger"]}),ul:Object.assign(Object.assign({},Ke),{type:"checklist",indent:/^\d+$/}),ol:Object.assign(Object.assign({},Ke),{start:/^\d+$/,indent:/^\d+$/}),li:{value:["true","false"]},table:{style:{width:/^-?\d+(px|%)$/i,height:/^-?\d+(px|%)$/i,border:/^[^"]+$/,"border-width":/^-?\d+px$/i,"border-style":/^[\w-]+$/,"border-color":/^[^"]+$/,"background-color":/^[^"]+$/}},tr:{style:{height:/^-?\d+(px|%)$/i}},th:"td",td:{colspan:/^\d+$/,rowspan:/^\d+$/,style:{width:/^-?\d+(px|%)$/i,height:/^-?\d+(px|%)$/i,border:/^[^"]+$/,"border-width":/^-?\d+px$/i,"border-style":/^[\w-]+$/,"border-color":/^[^"]+$/,"background-color":/^[^"]+$/,"text-align":["left","center","right","justify"]}},"lake-box":{type:["inline","block"],name:/^[\w-]+$/,value:/^[^"]+$/,focus:["start","center","end"]},br:{},hr:{},img:{src:/^[^"]+$/,width:/^-?\d+px$/i,height:/^-?\d+px$/i,"data-lake-value":/^[^"]+$/,alt:/^[^"]+$/,style:{width:/^-?\d+px$/i,height:/^-?\d+px$/i}},span:{class:/^[\w- ]+$/,style:{color:/^[^"]+$/,"background-color":/^[^"]+$/,"font-family":/^[^;]+$/,"font-size":/^[^"]+$/}},b:"strong",strong:{},em:"i",i:{},u:{},s:{},sub:{},sup:{},code:{},a:{class:/^[\w- ]+$/,name:/^[\w-]+$/,href:/^[^"]+$/,target:/^[\w-]+$/,rel:/^[^"]+$/,download:/^[^"]+$/},"lake-bookmark":{type:["anchor","focus"]}}}class Xe{constructor(e,t=Ge()){this.rules=t,this.source="string"==typeof e?this.parseHTML(e):e}parseHTML(e){const t=(new DOMParser).parseFromString(e,"text/html");return new T(t.querySelector("body"))}static matchRule(e,t){return"string"==typeof e?e===t:Array.isArray(e)?e.indexOf(t)>=0:e instanceof RegExp&&e.test(t)}static getOpenTagString(e,t){let i=e.name,n=t[i];if(!n)return"";"string"==typeof n&&(i=n,n=t[i]);const s=e.get(0);if(!s.hasAttributes())return i;const o=new Map;for(const e of s.attributes)if(n[e.name]&&("style"!==e.name&&Xe.matchRule(n[e.name],e.value)&&o.set(e.name,e.value),"style"===e.name)){const t=n.style,i=new Map,s=m(e.value);for(const e of Object.keys(s)){const n=s[e];t[e]&&Xe.matchRule(t[e],n)&&i.set(e,n)}o.set("style",i)}let r=i;for(const[e,t]of o)if("style"===e){let e="";for(const[i,n]of t)e+=`${i}: ${n.replace(/"/g,""")}; `;""!==e&&(r+=` style="${e.trim()}"`)}else r+=` ${e}="${t}"`;return r}static getClosedTagString(e,t){let i=e.name;const n=t[i];return n?("string"==typeof n&&(i=n),i):""}static getTrimmedText(e){const t=e.parent(),i=e.prev(),n=e.next();let s=e.text();return(i.isBlock||i.isBlockBox)&&(n.isBlock||n.isBlockBox)||0===i.length&&0===n.length&&t.isBlock?s=s.replace(/^[\u0020\t\r\n]+|[\u0020\t\r\n]+$/g,""):i.isBlock||i.isBlockBox||0===i.length&&t.isBlock?s=s.replace(/^[\u0020\t\r\n]+/,""):(n.isBlock||n.isBlockBox||0===n.length&&t.isBlock)&&(s=s.replace(/[\u0020\t\r\n]+$/,"")),s}getHTML(){const e=this.rules;let t="";for(const i of function*t(i){let n=i.first();for(;n.length>0;){const i=n.next();if(n.isText)yield r(Xe.getTrimmedText(n));else if(n.isVoid){const t=Xe.getOpenTagString(n,e);""!==t&&(yield`<${t} />`)}else if(n.isElement){const i=Xe.getOpenTagString(n,e),s=Xe.getClosedTagString(n,e);""!==i&&(yield`<${i}>`),n.isBox||(yield*t(n)),""!==s&&(yield`</${s}>`)}n=i}}(this.source))t+=i;return t.trim()}getFragment(){const e=this.getHTML(),t=this.parseHTML(e),i=document.createDocumentFragment();let n=t.first();for(;n.length>0;){const e=n.next();i.appendChild(n.get(0)),n=e}return i}}class Qe{constructor(e){this.content=e}getHTML(){let e=this.content;return e=e.replace(/ {2}/g," "),e=r(e.trim()),e=`<p>${e}</p>`,e=e.replace(/(\r\n){2,}/g,"</p><p><br /></p><p>"),e=e.replace(/\r\n/g,"</p><p>"),e=e.replace(/[\r\n]{2,}/g,"</p><p><br /></p><p>"),e=e.replace(/[\r\n]/g,"</p><p>"),e}getFragment(){return new Xe(this.getHTML()).getFragment()}}function Ye(e,t){if(e.commonAncestor.isOutside)return;const i=(t=I(t)).get(0),n=e.get();n.insertNode(i),n.setEndAfter(i),n.collapse(!1)}function Je(e){if(e.commonAncestor.isOutside)return{anchor:new T,focus:new T};const t=e.startNode.closest("lake-box");if(t.length>0)return e.isBoxStart?t.attr("focus","start"):e.isBoxEnd?t.attr("focus","end"):t.attr("focus","center"),{anchor:new T,focus:t};if(e.isCollapsed){const t=e.clone();t.collapseToEnd();const i=I('<lake-bookmark type="focus" />');return Ye(t,i),{anchor:new T,focus:i}}const i=e.clone();i.collapseToStart();const n=I('<lake-bookmark type="anchor" />');Ye(i,n);const s=e.clone();s.collapseToEnd();const o=I('<lake-bookmark type="focus" />');return Ye(s,o),{anchor:n,focus:o}}function et(e,t){const i=e.prev(),n=e.next();if(i.isText||n.isText){const t=e.parent();e.remove(),t.get(0).normalize()}else if(0===i.length&&0===n.length){if(e.parent().isMark&&t){const i=new T(document.createTextNode(""));e.before(i),t.setStartAfter(i),t.collapseToStart()}e.remove()}else e.remove()}function tt(e,t){const i=t.anchor,n=t.focus;if(i.length>0&&0===n.length)et(i);else{if(n.length>0&&0===i.length){if(n.isBox){const t=Fe(n);0===t.getContainer().length&&t.render();const i=n.attr("focus");return"start"===i?e.selectBoxStart(n):"center"===i?e.selectBox(n):e.selectBoxEnd(n),void n.removeAttr("focus")}return e.setStartBefore(n),e.collapseToStart(),void et(n,e)}if(i.length>0&&n.length>0){const t=new M;t.selectNode(i),t.collapseToEnd(),-1===t.compareAfterNode(n)?(e.setStartBefore(n),et(n),e.setEndBefore(i),et(i)):(e.setStartBefore(i),et(i),e.setEndBefore(n),et(n))}}}function it(e){if(e.commonAncestor.isOutside)return;F(e.getBlocks())}function nt(e){if(e.isCollapsed)return;if(e.adjustBox(),e.adjustTable(),e.isInoperative)return;const t=e.startNode.closestBlock(),i=e.endNode.closestBlock(),n=t.get(0)===i.get(0);if(e.get().deleteContents(),e.adjustBlock(),n){const t=e.getBlocks()[0];if(t&&t.isEmpty){const i=D(t);e.setStartBefore(i),e.collapseToStart()}return}const s=e.getBlocks()[0];if(!s)return;const o=s.prev();if(0===o.length)return;const r=Je(e);Z(o,s),tt(e,r),it(e)}function st(e,t){if(t instanceof Ue&&(t=t.get()),e.commonAncestor.isOutside)return;e.isCollapsed?e.adjustBox():nt(e);N(e.startNode.closestBlock());const i=Je(e);i.focus.before(t),tt(e,i),e.adjustBlock()}function ot(e,t){if(e.commonAncestor.isOutside)return;if(e.isCollapsed){if(e.commonAncestor.closest("lake-box").isBlockBox)return}if("string"!=typeof t){const i=e.getBlocks();for(const e of i)e.css(t);return}const i=I(t),n=i.name,s=i.get(0).attributes,o=e.getBlocks();if(o.length>0){const t=Je(e);for(const e of o)if(e.name===n&&0===i.first().length)for(const t of s)e.attr(t.name,t.value);else{const t=i.clone(!0);t.isList&&e.isList&&""!==e.attr("indent")&&t.attr("indent",e.attr("indent"));const n=H(t);let s=e.first();for(;s.length>0;){const e=s.next();n.append(s),n.name!==s.name&&"li"!==s.name||s.remove(!0),s=e}e.replaceWith(t)}return tt(e,t),void it(e)}const r=Je(e),a=function(e){const t=e.commonAncestor.closest('div[contenteditable="true"],td');let i=[];if(0===t.length)return i;let n=t.first(),s=!0;for(;n.length>0;){if(n.isMark||n.isText||n.isBookmark||n.isInlineBox)i.push(n);else{if(!s)break;i=[]}e.intersectsNode(n)&&(s=!1),n=n.next()}return i}(e),l=z(a,i);if(tt(e,r),it(e),l.isEmpty){const t=D(l);e.setStartBefore(t),e.collapseToStart()}}function rt(e){if(e.commonAncestor.isOutside)return{start:null,end:null};e.isCollapsed?e.adjustBox():nt(e);const t=e.startNode,i=t.closestOperableBlock();if(0===i.length)return{start:null,end:null};let n=i.parent();n.isOutside&&(n=t.closestContainer());const s=P(t,e.startOffset,n);let o=null,r=null;return s&&(o=s.start,r=s.end),!s&&t.isBlock&&(e.startOffset>0&&(o=t.children()[e.startOffset-1]),r=t.children()[e.startOffset],r&&!r.isBlock&&(r=null)),o&&o.isEmpty&&D(o),r&&(r.isEmpty&&D(r),e.shrinkBefore(r)),it(e),{start:o,end:r}}function at(e){if(e.isMark&&e.isEmpty)e.remove();else for(const t of e.getWalker())t.isMark&&t.isEmpty&&t.remove()}function lt(e,t,i){let n=null,s=null,o=e.closestBlock();0===o.length&&(o=e.closestContainer());const r=P(e,t,o);return r&&(i?(at(r.start),at(r.end),r.start.isEmpty||(n=r.start),r.end.isEmpty||(s=r.end)):(n=r.start,s=r.end)),{start:n,end:s}}function ct(e,t=!0){if(e.commonAncestor.isOutside)return{start:null,center:null,end:null};if(e.adjustBox(),e.isCollapsed){const i=lt(e.startNode,e.startOffset,t);return i.start?(e.setStartAfter(i.start),e.collapseToStart()):i.end&&(e.setStartBefore(i.end),e.collapseToStart()),{start:i.start,center:null,end:i.end}}const i=lt(e.startNode,e.startOffset,t);i.start?e.setStartAfter(i.start):i.end&&e.setStartBefore(i.end);const n=lt(e.endNode,e.endOffset,t);return n.start?e.setEndAfter(n.start):n.end&&e.setEndBefore(n.end),{start:i.start,center:n.start,end:n.end}}function dt(e,t){const i=e.text();let n=e;for(;n.length>0;){const e=n.parent();if(!e.isMark||i!==e.text()||!n.isText&&n.name===t&&""!==n.attr("style"))break;n=e}return n}function ht(e,t){if(e.commonAncestor.isOutside)return;let i=I(t);const n=i.name,s=m(i.attr("style"));if(e.isCollapsed){if(e.isBox){const t=e.startNode.closest("lake-box");if("block"===Fe(t).type){const i=I("<p><br /></p>");e.isBoxStart?t.before(i):t.after(i),e.shrinkAfter(i)}else e.adjustBox()}N(e.startNode.closestBlock());const t=new T(document.createTextNode("")),o=function(e){let t=e;t.isText&&(t=t.parent());let i=null;for(;t.length>0&&t.isMark;){if(i){const e=t.clone();e.append(i),i=e}else i=t.clone();t=t.parent()}return i}(e.startNode);if(ct(e),o){let e=o;for(;e.length>0;)e.name===n&&e.css(s),e=e.first();o.name===n?i=o:i.append(o)}if(""===i.text()){H(i).append(t)}return Ye(e,i),function(e){const t=e.prev();t.length>0&&t.isText&&t.isEmpty&&t.remove();const i=e.next();i.length>0&&i.isText&&i.isEmpty&&i.remove()}(i),void e.shrinkAfter(i)}ct(e);const o=e.getMarks(!0),r=Je(e);for(const e of o)if(!e.isEmpty&&e.isText){const t=dt(e,n);if(t.isMark&&t.name===n)t.css(s);else{const e=i.clone();t.before(e),e.append(t)}}tt(e,r)}function pt(e){if(e.isMark&&e.isEmpty)e.remove();else for(const t of e.getWalker())t.isMark&&t.isEmpty&&t.remove()}function ut(e,t){if(e.commonAncestor.isOutside)return;let i;if(t){i=I(t).name}if(e.isCollapsed){if(e.isBox)return;if(i&&0===e.commonAncestor.closest(i).length)return;const t=ct(e,!1);if(!t.start)return;t.end&&pt(t.end);const n=new T(document.createTextNode("")),s=function(e,t){if(!e.isMark||!t)return null;let i=null,n=null,s=e;for(;s.length>0&&s.isMark;){if(s.name!==t)if(n){const e=s.clone();n.append(e),n=e}else i=s.clone(),n=i;s=s.last()}return i}(t.start,i);if(!s)return t.start.after(n),pt(t.start),n.prev().isText?(e.setStartAfter(n.prev()),e.collapseToStart(),void n.remove()):(e.setStartAfter(n),void e.collapseToStart());return H(s).append(n),t.start.after(s),pt(t.start),void e.shrinkAfter(s)}ct(e);const n=e.getMarks(),s=Je(e);for(const e of n)if(!i||e.name===i){const t=e.parent();e.remove(!e.isEmpty),t.length>0&&t.get(0).normalize()}$(e.commonAncestor),tt(e,s)}function mt(e,t){if(e.commonAncestor.isOutside)return null;const i=I(t);if(e.isCollapsed){let t=e.commonAncestor.closest("a");if(0===t.length){t=i.clone(!0);return N(e.startNode.closestBlock()),Ye(e,t),t}return""!==i.attr("href")&&t.attr({href:i.attr("href")}),t}ct(e);const n=Je(e);for(const t of e.commonAncestor.getWalker())"a"===t.name&&e.intersectsNode(t)&&t.remove(!0);const s=i.clone(!1);n.anchor.after(s);let o=s.next();for(;o.length>0;){const e=o.next();if(!o.isMark&&!o.isText)break;s.append(o),o=e}return 0===s.first().length&&s.remove(),tt(e,n),s}function gt(e,t,i){if(e.commonAncestor.isOutside)return null;const n=Fe(t);i&&(n.value=i);const s=document.createDocumentFragment();if(s.appendChild(n.node.get(0)),"inline"===n.type)return ct(e),st(e,s),n.render(),e.selectBoxEnd(n.node),Fe(n.node);const o=rt(e);return o.start&&(e.setEndAfter(o.start),e.collapseToEnd()),o.end&&o.end.isEmpty&&o.end.remove(),st(e,s),n.render(),e.selectBoxEnd(n.node),o.start&&o.start.isEmpty&&o.start.remove(),Fe(n.node)}function ft(e){const t=e.node.closestContainer();if(e.unmount(),e.node.remove(),t.length>0){ge(t.id).delete(e.node.id);ge(0).set(e.node.id,e)}return e}function vt(e){if(e.commonAncestor.isOutside)return null;const t=e.commonAncestor.closest("lake-box");if(0===t.length)return null;const i=Fe(t);if("block"===i.type){const n=I("<p><br /></p>");return t.before(n),e.shrinkAfter(n),ft(i)}e.setStartBefore(t),e.collapseToStart();const n=t.parent();if(ft(i),n.isEmpty){const t=D(n);e.setStartBefore(t),e.collapseToStart()}return i}var wt={exports:{}};function yt(e,t=100,i={}){if("function"!=typeof e)throw new TypeError(`Expected the first parameter to be a function, got \`${typeof e}\`.`);if(t<0)throw new RangeError("`wait` must not be negative.");const{immediate:n}="boolean"==typeof i?{immediate:i}:i;let s,o,r,a,l;function c(){const t=s,i=o;return s=void 0,o=void 0,l=e.apply(t,i),l}function d(){const e=Date.now()-a;e<t&&e>=0?r=setTimeout(d,t-e):(r=void 0,n||(l=c()))}const h=function(...e){if(s&&this!==s&&Object.getPrototypeOf(this)===Object.getPrototypeOf(s))throw new Error("Debounced method called with different contexts of the same prototype.");s=this,o=e,a=Date.now();const i=n&&!r;return r||(r=setTimeout(d,t)),i&&(l=c()),l};return h.clear=()=>{r&&(clearTimeout(r),r=void 0)},h.flush=()=>{r&&h.trigger()},h.trigger=()=>{l=c(),h.clear()},h}wt.exports.debounce=yt,wt.exports=yt;var xt=fe(wt.exports),bt=fe((function e(t,i){if(t===i)return!0;if(t&&i&&"object"==typeof t&&"object"==typeof i){if(t.constructor!==i.constructor)return!1;var n,s,o;if(Array.isArray(t)){if((n=t.length)!=i.length)return!1;for(s=n;0!=s--;)if(!e(t[s],i[s]))return!1;return!0}if(t instanceof Map&&i instanceof Map){if(t.size!==i.size)return!1;for(s of t.entries())if(!i.has(s[0]))return!1;for(s of t.entries())if(!e(s[1],i.get(s[0])))return!1;return!0}if(t instanceof Set&&i instanceof Set){if(t.size!==i.size)return!1;for(s of t.entries())if(!i.has(s[0]))return!1;return!0}if(ArrayBuffer.isView(t)&&ArrayBuffer.isView(i)){if((n=t.length)!=i.length)return!1;for(s=n;0!=s--;)if(t[s]!==i[s])return!1;return!0}if(t.constructor===RegExp)return t.source===i.source&&t.flags===i.flags;if(t.valueOf!==Object.prototype.valueOf)return t.valueOf()===i.valueOf();if(t.toString!==Object.prototype.toString)return t.toString()===i.toString();if((n=(o=Object.keys(t)).length)!==Object.keys(i).length)return!1;for(s=n;0!=s--;)if(!Object.prototype.hasOwnProperty.call(i,o[s]))return!1;for(s=n;0!=s--;){var r=o[s];if(!e(t[r],i[r]))return!1}return!0}return t!=t&&i!=i}));function kt(e){const t=e.get(0),i={};if(t.hasAttributes())for(const e of t.attributes)i[e.name]=e.value;return i}class St{constructor(e){const t=window.getSelection();if(!t)throw new Error("Selection object is null.");this.selection=t,this.container=e,this.range=this.getCurrentRange()}getCurrentRange(){if(this.selection.rangeCount>0){const e=this.selection.getRangeAt(0);return new M(e)}return new M}sync(){this.container.contains(this.range.commonAncestor)&&(this.selection.removeAllRanges(),this.selection.addRange(this.range.get()))}updateByRange(){const e=this.getCurrentRange();this.container.contains(e.commonAncestor)&&(this.range.startNode.get(0)===e.startNode.get(0)&&this.range.startOffset===e.startOffset&&this.range.endNode.get(0)===e.endNode.get(0)&&this.range.endOffset===e.endOffset||(this.range=e))}updateByBookmark(){const e=this.range,t=this.container,i=t.find("lake-box[focus]");if(i.length>0)return tt(e,{anchor:new T,focus:i}),void this.sync();tt(e,{anchor:t.find('lake-bookmark[type="anchor"]'),focus:t.find('lake-bookmark[type="focus"]')}),this.sync()}getAppliedItems(){const e=[];return function(e,t){let i=t.startNode;for(i.isText&&(i=i.parent());i.length>0&&i.isInside;)e.push({node:i,name:i.name,attributes:kt(i),styles:m(i.attr("style"))}),i=i.parent()}(e,this.range),function(e,t){const i=t.startNode;let n;if(i.isText&&i.text().length===t.startOffset){const e=i.next();e.length>0&&e.isElement&&(n=e)}if(i.isElement){const e=i.children();if(e.length>0){const i=e[t.startOffset];i&&i.isElement&&(n=i)}}if(n){let t=n;for(;t.length>0;)t.isElement&&e.push({node:t,name:t.name,attributes:kt(t),styles:m(t.attr("style"))}),t=t.first()}}(e,this.range),e}insertBookmark(){return Je(this.range)}toBookmark(e){return tt(this.range,e)}insertNode(e){return Ye(this.range,e)}insertFragment(e){return st(this.range,e)}deleteContents(){return nt(this.range)}setBlocks(e){return ot(this.range,e)}splitBlock(){return rt(this.range)}splitMarks(e){return ct(this.range,e)}addMark(e){return ht(this.range,e)}removeMark(e){return ut(this.range,e)}fixList(){return it(this.range)}insertLink(e){return mt(this.range,e)}selectBox(e){let t=e;t=e instanceof Ve?e.node:e,this.range.selectBox(t),this.sync()}insertBox(e,t){const i=gt(this.range,e,t);if(!i)throw new Error(`Box "${e}" cannot be inserted outside the editor.`);return i}removeBox(e=null){return e&&this.selectBox(e),vt(this.range)}}class Ct{constructor(e){this.commandMap=new Map,this.selection=e}add(e,t){this.commandMap.set(e,t)}delete(e){this.commandMap.delete(e)}getNames(){return Array.from(this.commandMap.keys())}has(e){return void 0!==this.commandMap.get(e)}getItem(e){const t=this.commandMap.get(e);if(void 0===t)throw new Error(`Command "${e}" has not been defined yet.`);return t}isDisabled(e){const t=this.getItem(e);if(!t.isDisabled)return!1;const i=this.selection.getAppliedItems();return t.isDisabled(i)}isSelected(e){const t=this.getItem(e);if(!t.isSelected)return!1;const i=this.selection.getAppliedItems();return t.isSelected(i)}selectedValues(e){const t=this.getItem(e);if(!t.selectedValues)return[];const i=this.selection.getAppliedItems();return t.selectedValues(i)}execute(e,...t){const i=this.selection.container,n=this.selection.range;i.contains(n.commonAncestor)||n.shrinkAfter(i);this.getItem(e).execute.apply(this,t),A(`Command "${e}" executed`)}}class Bt{constructor(e){this.canSave=!0,this.list=[],this.index=0,this.limit=100,this.event=new we,this.selection=e,this.container=e.container}removeBookmark(e){return e.replace(/(<lake-box[^>]+)\s+focus="\w+"([^>]*>)/gi,"$1$2").replace(/<lake-bookmark\s+type="anchor">\s*<\/lake-bookmark>/gi,"").replace(/<lake-bookmark\s+type="focus">\s*<\/lake-bookmark>/gi,"")}getValue(e){return new Xe(e).getHTML()}addIdToBoxes(e){e.find("lake-box").each((e=>{const t=new T(e),i=`${t.attr("name")}-${t.attr("value")}`;t.attr("id",i)}))}removeIdfromBoxes(e){e.find("lake-box").each((e=>{new T(e).removeAttr("id")}))}morphContainer(e){const t=this.container,i={beforeChildrenUpdated:e=>{if("lake-box"===new T(e).name)return!1},afterAttributeUpdated:(e,i)=>{const n=new T(i);if(["name","value"].indexOf(e)>=0&&"lake-box"===n.name){Fe(n).unmount();ge(t.id).delete(n.id)}}},n=e.clone(!0);this.addIdToBoxes(t),this.addIdToBoxes(n),he(t,n,{callbacks:i}),this.removeIdfromBoxes(t),this.removeIdfromBoxes(n)}get canUndo(){return this.index>1&&!!this.list[this.index-2]}get canRedo(){return!!this.list[this.index]}cloneContainer(){const e=this.selection.range,t=this.container.clone(!0);if(t.find("lake-box").each((e=>{Fe(e).getContainer().empty()})),!this.container.contains(e.commonAncestor))return t;if(e.isInsideBox){const i=e.commonAncestor.closest("lake-box").path(),n=t.find(i),s=e.clone();return s.selectBox(n),Je(s),t}const i=e.startNode.path(),n=e.endNode.path(),s=t.find(i),o=t.find(n),r=e.clone();return r.setStart(s,e.startOffset),r.setEnd(o,e.endOffset),Je(r),t}undo(){if(!this.list[this.index-2])return;this.selection.insertBookmark();const e=this.getValue(this.container);for(;this.index>1;){const t=this.list[this.index-2];if(!t)break;this.index--;const i=this.getValue(t);if(this.removeBookmark(i)!==this.removeBookmark(e)){this.morphContainer(t),this.event.emit("undo",i);break}}this.selection.updateByBookmark(),A(`History undone (index: ${this.index})`)}redo(){if(!this.list[this.index])return;this.selection.insertBookmark();const e=this.getValue(this.container);for(;this.index<this.list.length;){const t=this.list[this.index];if(!t)break;this.index++;const i=this.getValue(t);if(this.removeBookmark(i)!==this.removeBookmark(e)){this.morphContainer(t),this.event.emit("redo",i);break}}this.selection.updateByBookmark(),A(`History redone (index: ${this.index})`)}continue(){this.canSave=!0}pause(){this.canSave=!1}save(e={}){var t,i,n;const s=null!==(t=e.inputType)&&void 0!==t?t:"",o=null!==(i=e.update)&&void 0!==i&&i,r=null===(n=e.emitEvent)||void 0===n||n;if(!this.canSave)return;const a=this.cloneContainer(),l=this.getValue(a);this.list[this.index-1]&&this.removeBookmark(this.getValue(this.list[this.index-1]))===this.removeBookmark(l)||(o?this.list.splice(this.index-1,1/0,a):(this.list.splice(this.index,1/0,a),this.index++),this.list.length>this.limit&&(this.list.shift(),this.index=this.list.length),A(`History saved (index: ${this.index}, inputType: "${s}", update: ${o}, emitEvent: ${r})`),r&&this.event.emit("save",f(l),{inputType:s,update:o,emitEvent:r}))}}var _t={};Object.defineProperty(_t,"__esModule",{value:!0});for(var At="undefined"!=typeof window&&/Mac|iPod|iPhone|iPad/.test(window.navigator.platform),Lt={alt:"altKey",control:"ctrlKey",meta:"metaKey",shift:"shiftKey"},Et={add:"+",break:"pause",cmd:"meta",command:"meta",ctl:"control",ctrl:"control",del:"delete",down:"arrowdown",esc:"escape",ins:"insert",left:"arrowleft",mod:At?"meta":"control",opt:"alt",option:"alt",return:"enter",right:"arrowright",space:" ",spacebar:" ",up:"arrowup",win:"meta",windows:"meta"},Tt={backspace:8,tab:9,enter:13,shift:16,control:17,alt:18,pause:19,capslock:20,escape:27," ":32,pageup:33,pagedown:34,end:35,home:36,arrowleft:37,arrowup:38,arrowright:39,arrowdown:40,insert:45,delete:46,meta:91,numlock:144,scrolllock:145,";":186,"=":187,",":188,"-":189,".":190,"/":191,"`":192,"[":219,"\\":220,"]":221,"'":222},It=1;It<20;It++)Tt["f"+It]=111+It;function Mt(e,t,i){t&&!("byKey"in t)&&(i=t,t=null),Array.isArray(e)||(e=[e]);var n=e.map((function(e){return Pt(e,t)})),s=function(e){return n.some((function(t){return Dt(t,e)}))};return null==i?s:s(i)}function Pt(e,t){var i=t&&t.byKey,n={},s=(e=e.replace("++","+add")).split("+"),o=s.length;for(var r in Lt)n[Lt[r]]=!1;var a=!0,l=!1,c=void 0;try{for(var d,h=s[Symbol.iterator]();!(a=(d=h.next()).done);a=!0){var p=d.value,u=p.endsWith("?")&&p.length>1;u&&(p=p.slice(0,-1));var m=Ot(p),g=Lt[m];if(p.length>1&&!g&&!Et[p]&&!Tt[m])throw new TypeError('Unknown modifier: "'+p+'"');1!==o&&g||(i?n.key=m:n.which=Nt(p)),g&&(n[g]=!u||null)}}catch(e){l=!0,c=e}finally{try{!a&&h.return&&h.return()}finally{if(l)throw c}}return n}function Dt(e,t){for(var i in e){var n=e[i],s=void 0;if(null!=n&&((null!=(s="key"===i&&null!=t.key?t.key.toLowerCase():"which"===i?91===n&&93===t.which?91:t.which:t[i])||!1!==n)&&s!==n))return!1}return!0}function Nt(e){return e=Ot(e),Tt[e]||e.toUpperCase().charCodeAt(0)}function Ot(e){return e=e.toLowerCase(),e=Et[e]||e}_t.default=Mt,_t.isHotkey=Mt,_t.isCodeHotkey=function(e,t){return Mt(e,t)};var Zt=_t.isKeyHotkey=function(e,t){return Mt(e,{byKey:!0},t)};_t.parseHotkey=Pt,_t.compareHotkey=Dt,_t.toKeyCode=Nt,_t.toKeyName=Ot;class Ht{constructor(e){this.keydownEventList=[],this.keyupEventList=[],this.container=e,this.container.on("keydown",(e=>{const t=e;if(!t.isComposing&&!t.defaultPrevented)for(const e of this.keydownEventList)if(Zt(e.type,t)&&!1===e.listener(t))break})),this.container.on("keyup",(e=>{const t=e;if(!t.isComposing&&!t.defaultPrevented)for(const e of this.keyupEventList)if(Zt(e.type,t)&&!1===e.listener(t))break}))}setKeydown(e,t){this.keydownEventList.push({type:e,listener:t})}setKeyup(e,t){this.keyupEventList.push({type:e,listener:t})}keydown(e){for(const t of this.keydownEventList)if(t.type===e&&!1===t.listener(new KeyboardEvent(e)))break}keyup(e){for(const t of this.keyupEventList)if(t.type===e&&!1===t.listener(new KeyboardEvent(e)))break}}const zt={value:"<p><br /></p>",readonly:!1,spellcheck:!1,tabIndex:0,placeholder:"",indentWithTab:!0,lang:"en-US",minChangeSize:5,historySize:100,onMessage:(e,t)=>{"success"!==e?"warning"!==e?"error"===e&&console.error(t):console.warn(t):console.log(t)},slash:!1,mention:!1};class $t{constructor(e){if(this.unsavedInputData="",this.unsavedInputCount=0,this.state={appliedItems:[],disabledNameMap:new Map,selectedNameMap:new Map,selectedValuesMap:new Map},this.unmountPluginMap=new Map,this.isComposing=!1,this.event=new we,this.box=$t.box,this.popup=null,this.copyListener=e=>{const t=this.selection.getCurrentRange();this.container.contains(t.commonAncestor)&&this.event.emit("copy",e)},this.cutListener=e=>{const t=this.selection.getCurrentRange();this.container.contains(t.commonAncestor)&&this.event.emit("cut",e)},this.pasteListener=e=>{const t=this.selection.getCurrentRange();this.container.contains(t.commonAncestor)&&this.event.emit("paste",e)},this.selectionchangeListener=()=>{this.updateSelectionRange(),this.updateBoxSelectionStyle(),this.emitStateChangeEvent()},this.clickListener=e=>{const t=new T(e.target);t.get(0).isConnected&&this.event.emit("click",t)},this.updateSelectionRange=xt((()=>{this.selection.updateByRange()}),1,{immediate:!0}),this.updateBoxSelectionStyle=xt((()=>{if(0===this.root.first().length)return;const e=this.selection.getCurrentRange(),t=e.clone();t.adjustBox(),this.container.find("lake-box").each((i=>{const n=Fe(i),s=n.getContainer();if(0!==s.length){if(e.compareBeforeNode(s)<0&&e.compareAfterNode(s)>0&&(!e.isCollapsed||e.startNode.get(0)!==s.get(0)||0!==e.startOffset))return s.removeClass("lake-box-hovered"),s.removeClass("lake-box-selected"),s.removeClass("lake-box-focused"),s.addClass("lake-box-activated"),void n.event.emit("focus");if(t.intersectsNode(n.node))return s.removeClass("lake-box-activated"),void(e.isCollapsed?(s.removeClass("lake-box-hovered"),s.removeClass("lake-box-selected"),s.addClass("lake-box-focused"),n.event.emit("focus")):(s.removeClass("lake-box-focused"),s.addClass("lake-box-selected"),n.event.emit("blur")));s.removeClass("lake-box-activated"),s.removeClass("lake-box-focused"),s.removeClass("lake-box-selected"),n.event.emit("blur")}}))}),50,{immediate:!0}),this.emitStateChangeEvent=xt((()=>{const e=this.command.getNames();let t=this.selection.getAppliedItems();t.length>0&&!this.container.contains(t[0].node)&&(t=[]);const i=new Map,n=new Map,s=new Map;if(t.length>0)for(const o of e){const e=this.command.getItem(o);if(e.isDisabled&&e.isDisabled(t)&&i.set(o,!0),e.isSelected&&e.isSelected(t)&&n.set(o,!0),e.selectedValues){const i=e.selectedValues(t);i.length>0&&s.set(o,i)}}const o={appliedItems:t,disabledNameMap:i,selectedNameMap:n,selectedValuesMap:s};bt(o,this.state)||(this.toolbar&&this.toolbar.updateState(o),this.event.emit("statechange",o),this.state=o)}),50,{immediate:!1}),!e.root)throw new Error("The root of the config must be specified.");this.root=I(e.root),this.toolbar=e.toolbar,this.config=Object.assign({},zt);for(const t of Object.keys(e))this.config[t]=e[t];this.containerWrapper=I('<div class="lake-container-wrapper" />'),this.container=I('<div class="lake-container" />'),this.overlayContainer=I('<div class="lake-overlay" />'),this.readonly=this.config.readonly,this.container.attr({contenteditable:this.readonly?"false":"true",spellcheck:this.config.spellcheck?"true":"false",tabindex:this.config.tabIndex.toString(),"data-readonly":this.readonly?"true":"false"}),""!==this.config.placeholder&&this.container.attr("placeholder",this.config.placeholder),this.selection=new St(this.container),this.command=new Ct(this.selection),this.history=new Bt(this.selection),this.history.limit=this.config.historySize,this.keystroke=new Ht(this.container),xe.set(this.container.id,this)}togglePlaceholderClass(e){const t="lake-placeholder";"<p><br /></p>"===(e=f(e)).replace("<focus />","")?this.container.addClass(t):this.container.removeClass(t)}moveBoxStripText(){const e=this.selection,t=e.range,i=t.startNode.closest(".lake-box-strip"),n=i.closest("lake-box");if("inline"===Fe(n).type)t.isBoxStart?(t.setStartBefore(n),t.collapseToStart()):(t.setStartAfter(n),t.collapseToStart());else{const e=I("<p />");t.isBoxStart?n.before(e):n.after(e),t.setStart(e,0),t.collapseToStart()}const s=i.text();i.html("<br />"),e.insertNode(document.createTextNode(s))}resetUnsavedInputData(){this.unsavedInputData="",this.unsavedInputCount=0}handleInputEvent(e){var t;this.selection.updateByRange();const i=this.selection.range;if(i.isInsideBox)return;if(i.isBoxStart||i.isBoxEnd)return this.moveBoxStripText(),void this.history.save();if("insertText"===(e instanceof CompositionEvent?"insertText":e.inputType)){const i=null!==(t=e.data)&&void 0!==t?t:"";return i.length>1?void this.history.save({inputType:"insertText",update:!1}):(this.unsavedInputData+=i,this.unsavedInputCount++,void(this.unsavedInputData.length<this.config.minChangeSize?this.history.save({inputType:"insertText",update:this.unsavedInputCount>1}):(this.history.save({inputType:"insertText",update:!0}),this.resetUnsavedInputData())))}this.history.save()}bindInputEvents(){this.container.on("compositionstart",(()=>{this.isComposing=!0,this.container.removeClass("lake-placeholder")})),this.container.on("compositionend",(e=>{this.isComposing=!1,this.handleInputEvent(e)})),this.container.on("input",(e=>{const t=e;this.isComposing=t.isComposing,this.isComposing||this.handleInputEvent(e)}))}bindHistoryEvents(){const e=e=>{this.fixContent()&&(this.history.save({update:!0,emitEvent:!1}),e=this.getValue()),this.emitStateChangeEvent(),this.togglePlaceholderClass(e),this.scrollToCaret(),this.event.emit("change",e)};this.history.event.on("undo",(t=>{this.renderBoxes(),e(t),this.resetUnsavedInputData()})),this.history.event.on("redo",(t=>{this.renderBoxes(),e(t),this.resetUnsavedInputData()})),this.history.event.on("save",((t,i)=>{this.removeBoxGarbage(),e(t),"insertText"!==i.inputType&&(this.selection.sync(),this.resetUnsavedInputData())}))}get hasFocus(){const e=document.activeElement;return!!e&&I(e).closest(".lake-container").get(0)===this.container.get(0)}get locale(){return Ze(this.config.lang)}fixContent(){const e=this.selection.range;let t=!1,i=this.container.children();for(const e of i)(e.isBlock||e.isMark)&&""===e.html()&&(e.remove(),t=!0,A(`Content fixed: empty tag "${e.name}" was removed`));if(i=this.container.children(),0===i.length)this.container.html("<p><br /></p>"),e.shrinkBefore(this.container),t=!0,A("Content fixed: default paragraph was added");else if(1===i.length){const n=i[0];if(n.isVoid){const i=I("<p />");n.before(i),i.append(n),e.shrinkAfter(i),t=!0,A(`Content fixed: void element "${n.name}" was wrapped in paragraph`)}}return e.adjustBr(),t}setPluginConfig(e,t){"object"!=typeof this.config[e]&&(this.config[e]={});for(const i of Object.keys(t))void 0===this.config[e][i]&&(this.config[e][i]=t[i])}removeBoxGarbage(){const e=ge(this.container.id);for(const t of e.values())t.node.get(0).isConnected||(t.unmount(),e.delete(t.node.id))}renderBoxes(){this.removeBoxGarbage();const e=this.container,t=ge(e.id);e.find("lake-box").each((e=>{const i=I(e);if(t.get(i.id))return;Fe(i).render()}))}focus(){this.container.focus()}blur(){this.container.blur()}scrollToCaret(){const e=this.selection.range;if(e.isBox)return;const t=e.getRect();if(0===t.x||0===t.y)return;const i=this.container.get(0).getBoundingClientRect(),n=I('<div class="lake-artificial-caret" />'),s=t.x-i.x,o=t.y-i.y;n.css({position:"absolute",top:`${o}px`,left:`${s}px`,width:`${t.width}px`,height:`${t.height}px`,"z-index":"-1"}),this.overlayContainer.find(".lake-artificial-caret").remove(),this.overlayContainer.append(n),ue(n,{behavior:"instant",block:"nearest",inline:"nearest"}),n.remove()}setValue(e){e=g(e);const t=new Xe(e),i=t.getFragment();this.container.empty(),this.togglePlaceholderClass(t.getHTML()),this.container.append(i),this.renderBoxes(),this.selection.updateByBookmark()}getValue(){const e=this.history.cloneContainer();let t=new Xe(e).getHTML();return t=f(t),t}render(){const e=g(this.config.value),t=new Xe(e),i=t.getFragment();this.root.empty(),this.root.append(this.containerWrapper),this.containerWrapper.append(this.container),this.containerWrapper.append(this.overlayContainer),this.togglePlaceholderClass(t.getHTML()),this.container.append(i),this.unmountPluginMap=$t.plugin.loadAll(this),this.readonly||(this.selection.updateByBookmark(),this.history.save({emitEvent:!1})),this.renderBoxes(),this.toolbar&&this.toolbar.render(this),document.addEventListener("copy",this.copyListener),this.readonly||(document.addEventListener("cut",this.cutListener),document.addEventListener("paste",this.pasteListener),document.addEventListener("selectionchange",this.selectionchangeListener),document.addEventListener("click",this.clickListener),this.bindInputEvents(),this.bindHistoryEvents())}unmount(){this.updateSelectionRange.flush(),this.updateBoxSelectionStyle.flush(),this.emitStateChangeEvent.flush();for(const e of this.unmountPluginMap.keys()){const t=this.unmountPluginMap.get(e);t&&(t(),A(`Plugin "${e}" unmounted`))}this.toolbar&&this.toolbar.unmount(),this.removeBoxGarbage(),this.container.find("lake-box").each((e=>{Fe(I(e)).unmount()})),this.event.removeAllListeners(),this.history.event.removeAllListeners(),this.root.off(),this.root.empty(),document.removeEventListener("copy",this.copyListener),this.readonly||(document.removeEventListener("cut",this.cutListener),document.removeEventListener("paste",this.pasteListener),document.removeEventListener("selectionchange",this.selectionchangeListener),document.removeEventListener("click",this.clickListener))}}$t.version="0.2.4",$t.box=new class{add(e){ye.set(e.name,e)}remove(e){ye.delete(e)}getNames(){return Array.from(ye.keys())}},$t.plugin=new class{constructor(){this.pluginMap=new Map}add(e,t){if(this.pluginMap.get(e))throw new Error(`Plugin "${e}" is already defined.`);this.pluginMap.set(e,t)}loadAll(e){const t=new Map;for(const i of this.pluginMap.keys()){const n=this.pluginMap.get(i);if(n&&!1!==e.config[i]){const s=n(e);s&&t.set(i,s)}}return t}};const Vt=[{icon:n.get("numberedList"),value:"numbered",text:e=>e.toolbar.numberedList()},{icon:n.get("bulletedList"),value:"bulleted",text:e=>e.toolbar.bulletedList()},{icon:n.get("checklist"),value:"checklist",text:e=>e.toolbar.checklist()}],Ft=[{icon:n.get("alignLeft"),value:"left",text:e=>e.toolbar.alignLeft()},{icon:n.get("alignCenter"),value:"center",text:e=>e.toolbar.alignCenter()},{icon:n.get("alignRight"),value:"right",text:e=>e.toolbar.alignRight()},{icon:n.get("alignJustify"),value:"justify",text:e=>e.toolbar.alignJustify()}],Rt=[{icon:n.get("increaseIndent"),value:"increase",text:e=>e.toolbar.increaseIndent()},{icon:n.get("decreaseIndent"),value:"decrease",text:e=>e.toolbar.decreaseIndent()}],qt=[{icon:n.get("italic"),value:"italic",text:e=>e.toolbar.italic()},{icon:n.get("underline"),value:"underline",text:e=>e.toolbar.underline()},{icon:n.get("strikethrough"),value:"strikethrough",text:e=>e.toolbar.strikethrough()},{icon:n.get("superscript"),value:"superscript",text:e=>e.toolbar.superscript()},{icon:n.get("subscript"),value:"subscript",text:e=>e.toolbar.subscript()},{icon:n.get("code"),value:"code",text:e=>e.toolbar.code()}],jt=["#f5222d","#fa541c","#fa8c16","#faad14","#fadb14","#a0d911","#52c41a","#13c2c2","#1677ff","#2f54eb","#722ed1","#eb2f96","#fff1f0","#fff2e8","#fff7e6","#fffbe6","#feffe6","#fcffe6","#f6ffed","#e6fffb","#e6f4ff","#f0f5ff","#f9f0ff","#fff0f6","#ffccc7","#ffd8bf","#ffe7ba","#fff1b8","#ffffb8","#f4ffb8","#d9f7be","#b5f5ec","#bae0ff","#d6e4ff","#efdbff","#ffd6e7","#ffa39e","#ffbb96","#ffd591","#ffe58f","#fffb8f","#eaff8f","#b7eb8f","#87e8de","#91caff","#adc6ff","#d3adf7","#ffadd2","#ff7875","#ff9c6e","#ffc069","#ffd666","#fff566","#d3f261","#95de64","#5cdbd3","#69b1ff","#85a5ff","#b37feb","#ff85c0","#ff4d4f","#ff7a45","#ffa940","#ffc53d","#ffec3d","#bae637","#73d13d","#36cfc9","#4096ff","#597ef7","#9254de","#f759ab","#cf1322","#d4380d","#d46b08","#d48806","#d4b106","#7cb305","#389e0d","#08979c","#0958d9","#1d39c4","#531dab","#c41d7f","#a8071a","#ad2102","#ad4e00","#ad6800","#ad8b00","#5b8c00","#237804","#006d75","#003eb3","#10239e","#391085","#9e1068","#820014","#871400","#873800","#874d00","#876800","#3f6600","#135200","#00474f","#002c8c","#061178","#22075e","#780650","#5c0011","#610b00","#612500","#613400","#614700","#254000","#092b00","#002329","#001d66","#030852","#120338","#520339","#000000","#1f1f1f","#262626","#434343","#595959","#8c8c8c","#bfbfbf","#d9d9d9","#f0f0f0","#f5f5f5","#fafafa","#ffffff"],Wt=[{icon:n.get("removeFormat"),value:"",text:e=>e.toolbar.removeColor()}];for(const e of jt)Wt.push({value:e.toLowerCase(),text:e.toUpperCase()});const Ut=new Map([["strong","bold"],["em","italic"],["i","italic"],["u","underline"],["s","strikethrough"],["sup","superscript"],["sub","subscript"],["code","code"]]),Kt=[{name:"undo",type:"button",icon:n.get("undo"),tooltip:e=>e.toolbar.undo(),onClick:(e,t)=>{e.command.execute(t)}},{name:"redo",type:"button",icon:n.get("redo"),tooltip:e=>e.toolbar.redo(),onClick:(e,t)=>{e.command.execute(t)}},{name:"selectAll",type:"button",icon:n.get("selectAll"),tooltip:e=>e.toolbar.selectAll(),onClick:(e,t)=>{e.command.execute(t)}},{name:"paragraph",type:"button",icon:n.get("paragraph"),tooltip:e=>e.toolbar.paragraph(),isSelected:e=>!!e.find((e=>"p"===e.name)),onClick:e=>{e.command.execute("heading","p")}},{name:"blockQuote",type:"button",icon:n.get("blockQuote"),tooltip:e=>e.toolbar.blockQuote(),onClick:(e,t)=>{e.command.execute(t)}},{name:"numberedList",type:"button",icon:n.get("numberedList"),tooltip:e=>e.toolbar.numberedList(),isSelected:e=>!!e.find((e=>"ol"===e.name)),onClick:e=>{e.command.execute("list","numbered")}},{name:"bulletedList",type:"button",icon:n.get("bulletedList"),tooltip:e=>e.toolbar.bulletedList(),isSelected:e=>!!e.find((e=>"ul"===e.name&&!e.node.hasAttr("type"))),onClick:e=>{e.command.execute("list","bulleted")}},{name:"checklist",type:"button",icon:n.get("checklist"),tooltip:e=>e.toolbar.checklist(),isSelected:e=>!!e.find((e=>"ul"===e.name&&"checklist"===e.node.attr("type"))),onClick:e=>{e.command.execute("list","checklist")}},{name:"alignLeft",type:"button",icon:n.get("alignLeft"),tooltip:e=>e.toolbar.alignLeft(),isSelected:e=>!!e.find((e=>e.node.isBlock&&"left"===e.node.css("text-align"))),onClick:e=>{e.command.execute("align","left")}},{name:"alignCenter",type:"button",icon:n.get("alignCenter"),tooltip:e=>e.toolbar.alignCenter(),isSelected:e=>!!e.find((e=>e.node.isBlock&&"center"===e.node.css("text-align"))),onClick:e=>{e.command.execute("align","center")}},{name:"alignRight",type:"button",icon:n.get("alignRight"),tooltip:e=>e.toolbar.alignRight(),isSelected:e=>!!e.find((e=>e.node.isBlock&&"right"===e.node.css("text-align"))),onClick:e=>{e.command.execute("align","right")}},{name:"alignJustify",type:"button",icon:n.get("alignJustify"),tooltip:e=>e.toolbar.alignJustify(),isSelected:e=>!!e.find((e=>e.node.isBlock&&"justify"===e.node.css("text-align"))),onClick:e=>{e.command.execute("align","justify")}},{name:"increaseIndent",type:"button",icon:n.get("increaseIndent"),tooltip:e=>e.toolbar.increaseIndent(),onClick:e=>{e.command.execute("indent","increase")}},{name:"decreaseIndent",type:"button",icon:n.get("decreaseIndent"),tooltip:e=>e.toolbar.decreaseIndent(),onClick:e=>{e.command.execute("indent","decrease")}},{name:"bold",type:"button",icon:n.get("bold"),tooltip:e=>e.toolbar.bold(),onClick:(e,t)=>{e.command.execute(t)}},{name:"italic",type:"button",icon:n.get("italic"),tooltip:e=>e.toolbar.italic(),onClick:(e,t)=>{e.command.execute(t)}},{name:"underline",type:"button",icon:n.get("underline"),tooltip:e=>e.toolbar.underline(),onClick:(e,t)=>{e.command.execute(t)}},{name:"strikethrough",type:"button",icon:n.get("strikethrough"),tooltip:e=>e.toolbar.strikethrough(),onClick:(e,t)=>{e.command.execute(t)}},{name:"superscript",type:"button",icon:n.get("superscript"),tooltip:e=>e.toolbar.superscript(),onClick:(e,t)=>{e.command.execute(t)}},{name:"subscript",type:"button",icon:n.get("subscript"),tooltip:e=>e.toolbar.subscript(),onClick:(e,t)=>{e.command.execute(t)}},{name:"code",type:"button",icon:n.get("code"),tooltip:e=>e.toolbar.code(),onClick:(e,t)=>{e.command.execute(t)}},{name:"removeFormat",type:"button",icon:n.get("removeFormat"),tooltip:e=>e.toolbar.removeFormat(),onClick:(e,t)=>{e.command.execute(t)}},{name:"formatPainter",type:"button",icon:n.get("formatPainter"),tooltip:e=>e.toolbar.formatPainter(),onClick:(e,t)=>{e.command.execute(t)}},{name:"link",type:"button",icon:n.get("link"),tooltip:e=>e.toolbar.link(),onClick:(e,t)=>{e.command.execute(t)}},{name:"hr",type:"button",icon:n.get("hr"),tooltip:e=>e.toolbar.hr(),onClick:(e,t)=>{e.command.execute(t)}},{name:"codeBlock",type:"button",icon:n.get("codeBlock"),tooltip:e=>e.toolbar.codeBlock(),onClick:(e,t)=>{e.command.execute(t)}},{name:"video",type:"button",icon:n.get("video"),tooltip:e=>e.toolbar.video(),onClick:(e,t)=>{e.command.execute(t)}},{name:"equation",type:"button",icon:n.get("equation"),tooltip:e=>e.toolbar.equation(),onClick:(e,t)=>{e.command.execute(t)}},{name:"heading",type:"dropdown",downIcon:n.get("down"),defaultValue:"p",tooltip:e=>e.toolbar.heading(),width:"100px",menuType:"list",menuItems:[{value:"h1",text:e=>`<span style="font-weight: bold; font-size: 26px;">${e.toolbar.heading1()}</span>`},{value:"h2",text:e=>`<span style="font-weight: bold; font-size: 24px;">${e.toolbar.heading2()}</span>`},{value:"h3",text:e=>`<span style="font-weight: bold; font-size: 22px;">${e.toolbar.heading3()}</span>`},{value:"h4",text:e=>`<span style="font-weight: bold; font-size: 20px;">${e.toolbar.heading4()}</span>`},{value:"h5",text:e=>`<span style="font-weight: bold; font-size: 18px;">${e.toolbar.heading5()}</span>`},{value:"h6",text:e=>`<span style="font-weight: bold; font-size: 16px;">${e.toolbar.heading6()}</span>`},{value:"p",text:e=>e.toolbar.paragraph()}],onSelect:(e,t)=>{e.command.execute("heading",t)}},{name:"list",type:"dropdown",downIcon:n.get("down"),icon:n.get("list"),tooltip:e=>e.toolbar.list(),menuType:"list",menuItems:Vt,onSelect:(e,t)=>{e.command.execute("list",t)}},{name:"align",type:"dropdown",downIcon:n.get("down"),icon:n.get("alignLeft"),tooltip:e=>e.toolbar.align(),menuType:"list",menuItems:Ft,onSelect:(e,t)=>{e.command.execute("align",t)}},{name:"indent",type:"dropdown",downIcon:n.get("down"),icon:n.get("increaseIndent"),tooltip:e=>e.toolbar.indent(),menuType:"list",menuItems:Rt,onSelect:(e,t)=>{e.command.execute("indent",t)}},{name:"fontFamily",type:"dropdown",downIcon:n.get("down"),defaultValue:"Segoe UI",tooltip:e=>e.toolbar.fontFamily(),width:"100px",menuType:"list",menuItems:[{value:"Arial",text:'<span style="font-family: Arial;">Arial</span>'},{value:"Arial Black",text:"<span style=\"font-family: 'Arial Black';\">Arial Black</span>"},{value:"Comic Sans MS",text:"<span style=\"font-family: 'Comic Sans MS';\">Comic Sans MS</span>"},{value:"Courier New",text:"<span style=\"font-family: 'Courier New';\">Courier New</span>"},{value:"Georgia",text:'<span style="font-family: Georgia;">Georgia</span>'},{value:"Helvetica",text:'<span style="font-family: Helvetica;">Helvetica</span>'},{value:"Impact",text:'<span style="font-family: Impact;">Impact</span>'},{value:"Segoe UI",text:"<span style=\"font-family: 'Segoe UI';\">Segoe UI</span>"},{value:"Tahoma",text:'<span style="font-family: Tahoma;">Tahoma</span>'},{value:"Times New Roman",text:"<span style=\"font-family: 'Times New Roman';\">Times New Roman</span>"},{value:"Trebuchet MS",text:"<span style=\"font-family: 'Trebuchet MS';\">Trebuchet MS</span>"},{value:"Verdana",text:'<span style="font-family: Verdana;">Verdana</span>'}],onSelect:(e,t)=>{e.command.execute("fontFamily",t)}},{name:"fontSize",type:"dropdown",downIcon:n.get("down"),defaultValue:"16px",tooltip:e=>e.toolbar.fontSize(),width:"65px",menuType:"list",menuItems:[{value:"12px",text:"12px"},{value:"14px",text:"14px"},{value:"16px",text:"16px"},{value:"18px",text:"18px"},{value:"22px",text:"22px"},{value:"24px",text:"24px"},{value:"32px",text:"32px"}],onSelect:(e,t)=>{e.command.execute("fontSize",t)}},{name:"moreStyle",type:"dropdown",icon:n.get("more"),tooltip:e=>e.toolbar.moreStyle(),menuType:"list",menuItems:qt,selectedValues:e=>{var t;const i=[];for(const n of e)if(n.node.isMark){const e=null!==(t=Ut.get(n.name))&&void 0!==t?t:n.name;i.push(e)}return i},onSelect:(e,t)=>{e.command.execute(t)}},{name:"fontColor",type:"dropdown",downIcon:n.get("down"),icon:n.get("fontColor"),accentIcon:n.get("fontColorAccent"),defaultValue:"#f5222d",tooltip:e=>e.toolbar.fontColor(),menuType:"color",menuItems:Wt,menuWidth:"296px",onSelect:(e,t)=>{e.command.execute("fontColor",t)}},{name:"highlight",type:"dropdown",downIcon:n.get("down"),icon:n.get("highlight"),accentIcon:n.get("highlightAccent"),defaultValue:"#fadb14",tooltip:e=>e.toolbar.highlight(),menuType:"color",menuItems:Wt,menuWidth:"296px",onSelect:(e,t)=>{e.command.execute("highlight",t)}},{name:"image",type:"upload",icon:n.get("image"),tooltip:e=>e.toolbar.image(),accept:"image/*",multiple:!0},{name:"file",type:"upload",icon:n.get("attachment"),tooltip:e=>e.toolbar.file(),accept:"*",multiple:!0}],Gt=["undo","redo","|","heading","|","formatPainter","removeFormat","bold","moreStyle","|","fontColor","highlight","|","align","list","indent","link","blockQuote","hr"],Xt=new Map;for(const e of Kt)Xt.set(e.name,e);var Qt={type:"block",name:"hr",render:e=>{const t=e.getEditor(),i=e.getContainer(),n=I('<div class="lake-hr"><hr /></div>');i.empty(),i.append(n),n.on("click",(()=>{t.selection.selectBox(e)}))},html:()=>"<hr />"};const Yt="#57606a",Jt="#444d56",ei="#953800",ti="#0550ae",ii="#444d56",ni="#24292e",si="#005cc5",oi="#0550ae",ri="#444d56",ai="#444d56",li="#0a3069",ci="#0550ae",di="#0550ae",hi="#116329",pi="#0550ae",ui="#cf222e",mi="#24292f",gi="#cf222e",fi="#57606a",vi="#57606a",wi="#8250df",yi="#0550ae",xi="#f6f8fa",bi="#cf222e",ki="#0550ae",Si="#005cc5",Ci="#444d56",Bi="#444d56";function _i(e){const{HighlightStyle:t,tags:i}=e;return t.define([{tag:[i.comment,i.lineComment,i.blockComment,i.docComment],color:Yt},{tag:[i.name],color:Jt},{tag:[i.variableName,i.self],color:ei},{tag:[i.typeName,i.tagName],color:ti},{tag:[i.propertyName,i.attributeName],color:ii},{tag:[i.className],color:ni},{tag:[i.labelName],color:si},{tag:[i.namespace],color:oi},{tag:[i.macroName],color:ri},{tag:[i.literal],color:ai},{tag:[i.string,i.docString,i.character,i.attributeValue,i.unit],color:li},{tag:[i.number,i.integer,i.float],color:ci},{tag:[i.bool,i.null,i.atom],color:di},{tag:[i.regexp,i.escape,i.url],color:hi},{tag:[i.color],color:pi},{tag:[i.keyword,i.operatorKeyword,i.controlKeyword,i.definitionKeyword,i.moduleKeyword],color:ui},{tag:[i.modifier],color:mi},{tag:[i.operator,i.derefOperator,i.arithmeticOperator,i.logicOperator,i.bitwiseOperator,i.compareOperator,i.updateOperator,i.definitionOperator,i.typeOperator,i.controlOperator],color:gi},{tag:[i.punctuation,i.separator,i.bracket,i.angleBracket,i.squareBracket,i.paren,i.brace,i.contentSeparator],color:fi},{tag:[i.content],color:vi},{tag:[i.meta,i.documentMeta,i.annotation,i.processingInstruction],color:wi},{tag:i.heading,fontWeight:"bold",color:yi},{tag:i.strong,fontWeight:"bold"},{tag:i.emphasis,fontStyle:"italic"},{tag:i.link,textDecoration:"underline"},{tag:i.strikethrough,textDecoration:"line-through"},{tag:[i.invalid,i.inserted,i.deleted,i.changed],color:xi},{tag:[i.definition(i.name)],color:bi},{tag:[i.constant(i.name)],color:ki},{tag:[i.function(i.variableName)],color:Si},{tag:[i.standard(i.name)],color:Ci},{tag:[i.special(i.variableName)],color:Bi}])}var Ai={type:"block",name:"codeBlock",render:e=>{var t;const i=e.getEditor(),s=I('<div class="lake-code-block" />'),o=e.getContainer();o.empty(),o.append(s);const r=s.get(0);if(!r)return;const a=window.LakeCodeMirror;if(!a)return i.readonly?void e.node.hide():(s.addClass("lake-code-block-error"),s.text('\n The code cannot be displayed because window.LakeCodeMirror is not found.\n Please check if the "lake-codemirror" library is added to this page.\n '.trim()),void s.on("click",(()=>{i.selection.selectBox(e)})));const{EditorState:l,Compartment:c,EditorView:d,keymap:h,history:p,defaultKeymap:u,historyKeymap:m,indentWithTab:g,syntaxHighlighting:f}=a,v=a.langItems,w=i.config.codeBlock,y=v.filter((e=>w.langList.indexOf(e.value)>=0)),x=new Map;for(const e of y)x.set(e.value,e);const b=e.value,k=x.get(b.lang),S=new c,C=xt((t=>{i.selection.updateByRange(),i.isComposing||(e.updateValue("code",t),i.history.save())}),1,{immediate:!1}),B=d.updateListener.of((e=>{e.docChanged&&C(e.state.doc.toString())})),_=new d({parent:r,doc:null!==(t=b.code)&&void 0!==t?t:"",extensions:[l.readOnly.of(i.readonly),d.editable.of(!i.readonly),p(),h.of([...u,...m,g]),f(_i(a)),S.of(k&&k.component?k.component():[]),B]});s.find('[contenteditable="true"]').attr("tabindex","-1");const L=new He({root:s,name:"langType",downIcon:n.get("down"),defaultValue:k?b.lang:w.defaultLang,tooltip:i.locale.codeBlock.langType(),location:"global",menuType:"list",menuHeight:"200px",menuItems:y.map((e=>({value:e.value,text:e.text}))),onSelect:t=>{e.updateValue({lang:t}),e.unmount(),e.render(),i.selection.selectBox(e),i.history.save()}});L.render(),s.on("click",(()=>{_.hasFocus||_.focus()})),e.event.on("beforeunmount",(()=>{L.unmount(),_.destroy(),A("CodeMirror destroyed")}))}};function Li(e,t,i,n){return new(i||(i=Promise))((function(s,o){function r(e){try{l(n.next(e))}catch(e){o(e)}}function a(e){try{l(n.throw(e))}catch(e){o(e)}}function l(e){var t;e.done?s(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(r,a)}l((n=n.apply(e,t||[])).next())}))}
|
|
19
19
|
/*!
|
|
20
20
|
* PhotoSwipe Lightbox 5.4.4 - https://photoswipe.com
|
|
21
21
|
* (c) 2024 Dmytro Semenov
|
|
@@ -92,7 +92,7 @@ function Ei(e,t,i){const n=document.createElement(t);return e&&(n.className=e),i
|
|
|
92
92
|
`);i.append(c);const d=c.find("textarea");d.value(r),d.on("input",(()=>{const t=d.value().trim();l.html(window.katex.renderToString(t||hs,{throwOnError:!1})),e.updateValue("code",t)}));new be({root:c.find(".lake-button-row"),name:"save",type:"primary",text:t.locale.equation.save(),onClick:()=>{t.selection.range.selectBoxEnd(e.node),t.selection.sync(),t.history.save()}}).render();new be({root:c.find(".lake-button-row"),name:"help",icon:n.get("question"),tooltip:t.locale.equation.help(),onClick:()=>{window.open(o.helpUrl)}}).render()}},us={type:"inline",name:"mention",render:e=>{var t;const i=e.getEditor(),{getProfileUrl:n}=i.config.mention,s=e.value,o=n?n(s):"#",r=e.getContainer(),l=I(a`
|
|
93
93
|
<div class="lake-mention"><a href="${o}">@${null!==(t=s.nickname)&&void 0!==t?t:s.name}</a></div>
|
|
94
94
|
`);r.empty(),r.append(l),l.on("click",(()=>{i.selection.selectBox(e)})),i.readonly||l.find("a").on("click",(e=>{e.preventDefault()}))}};const ms=Array.from(b).join(",");function gs(e){const t=[e];for(const i of e.getWalker())t.push(i);for(const e of t)"div"===e.name?e.find(ms).length>0?e.remove(!0):V(e,"p"):(e.isHeading||["blockquote","li"].indexOf(e.name)>=0)&&e.find(ms).remove(!0)}function fs(e,t){const i=e.selection,n=i.range;if(0===t.childNodes.length)return;const s=new T(t.firstChild);let o=new T(t.lastChild);0===n.getBlocks().length&&i.setBlocks("<p />"),function(e,t){const i=e.selection.range,n=i.startNode.closest("lake-box");if(n.length>0)if("inline"===Fe(n).type)i.isBoxStart?(i.setStartBefore(n),i.collapseToStart()):i.isBoxEnd?(i.setStartAfter(n),i.collapseToStart()):e.selection.removeBox();else{const t=I("<p />");i.isBoxStart?(n.before(t),i.shrinkAfter(t)):i.isBoxEnd?(n.after(t),i.shrinkAfter(t)):e.selection.removeBox()}const s=i.startNode.closestBlock();if(t.isBlockBox){const i=Fe(t),n=""!==t.attr("value")?i.value:void 0;return e.selection.insertBox(i.name,n),void t.remove()}if(t.first().length>0&&N(s),s.isEmpty&&"p"===s.name)return s.replaceWith(t),t.find("lake-box").each((e=>{Fe(e).render()})),void i.shrinkAfter(t);let o=t.first();for(;o.length>0;){"li"===o.name&&(o=o.first());const t=o.next();e.selection.insertNode(o),o.isBox?Fe(o).render():o.isElement&&o.find("lake-box").each((e=>{Fe(e).render()})),o=t}t.remove()}(e,s);let r=new T(t.firstChild);for(;r.length>0;){const e=r.next();"br"===r.name&&r.remove(),r=e}if(o=new T(t.lastChild),t.childNodes.length>0){const s=i.splitBlock();s.start&&(n.setEndAfter(s.start),n.collapseToEnd()),s.end&&s.end.isEmpty&&s.end.remove(),i.insertFragment(t),e.renderBoxes(),n.shrinkAfter(o)}F(e.container.children().filter((e=>e.isBlock))),e.history.save()}const vs=["info","tip","warning","danger"];function ws(e){e.selection.setBlocks("<p />")}function ys(e){e.selection.setBlocks("<ol><li></li></ol>")}function xs(e){e.selection.setBlocks("<ul><li></li></ul>")}function bs(e,t){e.selection.setBlocks(`<ul type="checklist"><li value="${t}"></li></ul>`)}const ks={start:"left",end:"right"};const Ss="strong";const Cs="sub";const Bs="sup";const _s="code";const As="lake-format-painter";class Ls{constructor(e){this.linkNode=null,this.scrollListener=()=>this.position(),this.resizeListener=()=>this.position(),this.config=e||{},this.locale=this.config.locale||Ze("en-US"),this.container=I(a`
|
|
95
|
-
<div class="lake-popup lake-link-popup
|
|
95
|
+
<div class="lake-popup lake-link-popup">
|
|
96
96
|
<div class="lake-row">${this.locale.link.url()}</div>
|
|
97
97
|
<div class="lake-row lake-url-row">
|
|
98
98
|
<input type="text" name="url" />
|
|
@@ -103,7 +103,7 @@ function Ei(e,t,i){const n=document.createElement(t);return e&&(n.className=e),i
|
|
|
103
103
|
</div>
|
|
104
104
|
<div class="lake-row lake-button-row"></div>
|
|
105
105
|
</div>
|
|
106
|
-
`)}writeClipboardText(e){return Li(this,void 0,void 0,(function*(){let t=!1;try{window.LAKE_TEST?t=window.LAKE_ERROR:yield navigator.clipboard.writeText(e)}catch(e){t=!0}return new Promise((e=>{e(t)}))}))}appendCopyButton(){const e=this.config;let t=null;const i=new be({root:this.container.find(".lake-url-row"),name:"copy",icon:n.get("copy"),tooltip:this.locale.link.copy(),onClick:()=>{if(!this.linkNode)return;const i=this.container.find('input[name="url"]').value();this.writeClipboardText(i).then((i=>{const n=this.container.find('button[name="copy"] svg');if(n.hide(),i)return n.eq(2).show("inline"),void(e.onCopy&&e.onCopy(i));n.eq(1).show("inline"),e.onCopy&&e.onCopy(i),t&&window.clearTimeout(t),t=window.setTimeout((()=>{n.hide(),n.eq(0).show("inline")}),2e3)}))}});i.render();const s=n.get("checkCircle");s&&i.node.append(s);const o=n.get("warningCircle");o&&i.node.append(o)}appendOpenButton(){new be({root:this.container.find(".lake-url-row"),name:"open",icon:n.get("open"),tooltip:this.locale.link.open(),onClick:()=>{if(!this.linkNode)return;const e=this.container.find('input[name="url"]').value();window.open(e)}}).render()}appendSaveButton(){const e=new be({root:this.container.find(".lake-button-row"),name:"save",icon:n.get("check"),text:this.locale.link.save(),onClick:()=>{if(!this.linkNode)return;const e=this.linkNode;this.save(),this.hide(),this.config.onSave&&this.config.onSave(e)}});e.render(),this.container.find('input[name="url"]').on("keydown",(t=>{Zt("enter",t)&&(t.preventDefault(),e.node.emit("click"))})),this.container.find('input[name="title"]').on("keydown",(t=>{Zt("enter",t)&&(t.preventDefault(),e.node.emit("click"))}))}appendUnlinkButton(){new be({root:this.container.find(".lake-button-row"),name:"unlink",icon:n.get("unlink"),text:this.locale.link.unlink(),onClick:()=>{if(!this.linkNode)return;const e=this.linkNode.last();this.linkNode.remove(!0),this.hide(),this.config.onRemove&&this.config.onRemove(e)}}).render()}get visible(){return this.container.get(0).isConnected&&"none"!==this.container.computedCSS("display")}save(){if(!this.linkNode)return;const e=this.container.find('input[name="url"]').value();let t=this.container.find('input[name="title"]').value();""!==e||""!==t?(""===t&&(t=e),this.linkNode.attr("href",e),this.linkNode.text(t)):this.linkNode.remove()}position(){if(!this.linkNode)return;const e=pe(this.linkNode);if(e.left<0||e.right<0||e.top<0||e.bottom<0)return void this.container.css("visibility","hidden");this.container.css("visibility","");const t=this.linkNode.get(0).getBoundingClientRect(),i=t.x+window.scrollX,n=t.y+window.scrollY;t.x+this.container.width()>window.innerWidth?this.container.css("left",`${i-this.container.width()+t.width}px`):this.container.css("left",`${i}px`),t.y+t.height+this.container.height()>window.innerHeight?this.container.css("top",n-this.container.height()+"px"):this.container.css("top",`${n+t.height}px`)}show(e){if(this.container.get(0).isConnected||(this.appendCopyButton(),this.appendOpenButton(),this.appendSaveButton(),this.appendUnlinkButton(),I(document.body).append(this.container)),this.linkNode&&this.linkNode.get(0)===e.get(0))return;this.linkNode=e;const t=e.attr("href"),i=e.text();this.container.find('input[name="url"]').value(t),i!==t&&this.container.find('input[name="title"]').value(i),this.container.css("visibility","hidden"),this.container.show(),this.position(),this.container.css("visibility",""),this.container.find('input[name="url"]').focus();const n=e.closestScroller();n.length>0&&n.on("scroll",this.scrollListener),window.addEventListener("resize",this.resizeListener),this.config.onShow&&this.config.onShow()}hide(){if(this.linkNode){const e=this.linkNode.closestScroller();e.length>0&&e.off("scroll",this.scrollListener)}this.linkNode=null,this.container.hide(),window.removeEventListener("resize",this.resizeListener),this.config.onHide&&this.config.onHide()}unmount(){this.hide(),this.container.remove()}}const Es=["text","c","csharp","cpp","css","go","html","java","javascript","json","markdown","php","python","rust","sql","typescript","xml","yaml"];const Ts=()=>{};class Is{constructor(e){this.horizontalDirection="right",this.verticalDirection="bottom",this.range=null,this.noMouseEvent=!1,this.keydownListener=e=>{if(Zt("escape",e))return e.preventDefault(),void this.hide();const t=Zt("down",e),i=Zt("up",e),n=Zt("enter",e);if(!t&&!i&&!n)return;const s=this.container.find(".lake-menu-item-selected");if(0===s.length){const e=this.container.find(".lake-menu-item").eq(0);return ue(e,{behavior:"instant",block:"start"}),void e.addClass("lake-menu-item-selected")}if(this.noMouseEvent=!0,t){e.preventDefault();let t=s.next();0===t.length&&(t=this.container.find(".lake-menu-item").eq(0)),ue(t,{behavior:"instant",block:"end"}),this.container.find(".lake-menu-item").removeClass("lake-menu-item-selected"),t.addClass("lake-menu-item-selected")}else if(i){e.preventDefault();let t=s.prev();if(0===t.length){const e=this.container.find(".lake-menu-item");t=e.eq(e.length-1)}ue(t,{behavior:"instant",block:"start"}),this.container.find(".lake-menu-item").removeClass("lake-menu-item-selected"),t.addClass("lake-menu-item-selected")}else n&&(e.preventDefault(),s.emit("click"));window.setTimeout((()=>{this.noMouseEvent=!1}),50)},this.clickListener=e=>{const t=new T(e.target);t.get(0).isConnected&&(this.container.contains(t)||this.hide())},this.scrollListener=()=>this.updatePosition(),this.resizeListener=()=>this.updatePosition(),this.items=e.items,this.onShow=e.onShow||Ts,this.onHide=e.onHide||Ts,this.container=I('<ul class="lake-popup lake-menu
|
|
106
|
+
`)}writeClipboardText(e){return Li(this,void 0,void 0,(function*(){let t=!1;try{window.LAKE_TEST?t=window.LAKE_ERROR:yield navigator.clipboard.writeText(e)}catch(e){t=!0}return new Promise((e=>{e(t)}))}))}appendCopyButton(){const e=this.config;let t=null;const i=new be({root:this.container.find(".lake-url-row"),name:"copy",icon:n.get("copy"),tooltip:this.locale.link.copy(),onClick:()=>{if(!this.linkNode)return;const i=this.container.find('input[name="url"]').value();this.writeClipboardText(i).then((i=>{const n=this.container.find('button[name="copy"] svg');if(n.hide(),i)return n.eq(2).show("inline"),void(e.onCopy&&e.onCopy(i));n.eq(1).show("inline"),e.onCopy&&e.onCopy(i),t&&window.clearTimeout(t),t=window.setTimeout((()=>{n.hide(),n.eq(0).show("inline")}),2e3)}))}});i.render();const s=n.get("checkCircle");s&&i.node.append(s);const o=n.get("warningCircle");o&&i.node.append(o)}appendOpenButton(){new be({root:this.container.find(".lake-url-row"),name:"open",icon:n.get("open"),tooltip:this.locale.link.open(),onClick:()=>{if(!this.linkNode)return;const e=this.container.find('input[name="url"]').value();window.open(e)}}).render()}appendSaveButton(){const e=new be({root:this.container.find(".lake-button-row"),name:"save",icon:n.get("check"),text:this.locale.link.save(),onClick:()=>{if(!this.linkNode)return;const e=this.linkNode;this.save(),this.hide(),this.config.onSave&&this.config.onSave(e)}});e.render(),this.container.find('input[name="url"]').on("keydown",(t=>{Zt("enter",t)&&(t.preventDefault(),e.node.emit("click"))})),this.container.find('input[name="title"]').on("keydown",(t=>{Zt("enter",t)&&(t.preventDefault(),e.node.emit("click"))}))}appendUnlinkButton(){new be({root:this.container.find(".lake-button-row"),name:"unlink",icon:n.get("unlink"),text:this.locale.link.unlink(),onClick:()=>{if(!this.linkNode)return;const e=this.linkNode.last();this.linkNode.remove(!0),this.hide(),this.config.onRemove&&this.config.onRemove(e)}}).render()}get visible(){return this.container.get(0).isConnected&&"none"!==this.container.computedCSS("display")}save(){if(!this.linkNode)return;const e=this.container.find('input[name="url"]').value();let t=this.container.find('input[name="title"]').value();""!==e||""!==t?(""===t&&(t=e),this.linkNode.attr("href",e),this.linkNode.text(t)):this.linkNode.remove()}position(){if(!this.linkNode)return;const e=pe(this.linkNode);if(e.left<0||e.right<0||e.top<0||e.bottom<0)return void this.container.css("visibility","hidden");this.container.css("visibility","");const t=this.linkNode.get(0).getBoundingClientRect(),i=t.x+window.scrollX,n=t.y+window.scrollY;t.x+this.container.width()>window.innerWidth?this.container.css("left",`${i-this.container.width()+t.width}px`):this.container.css("left",`${i}px`),t.y+t.height+this.container.height()>window.innerHeight?this.container.css("top",n-this.container.height()+"px"):this.container.css("top",`${n+t.height}px`)}show(e){if(this.container.get(0).isConnected||(this.appendCopyButton(),this.appendOpenButton(),this.appendSaveButton(),this.appendUnlinkButton(),I(document.body).append(this.container)),this.linkNode&&this.linkNode.get(0)===e.get(0))return;this.linkNode=e;const t=e.attr("href"),i=e.text();this.container.find('input[name="url"]').value(t),i!==t&&this.container.find('input[name="title"]').value(i),this.container.css("visibility","hidden"),this.container.show(),this.position(),this.container.css("visibility",""),this.container.find('input[name="url"]').focus();const n=e.closestScroller();n.length>0&&n.on("scroll",this.scrollListener),window.addEventListener("resize",this.resizeListener),this.config.onShow&&this.config.onShow()}hide(){if(this.linkNode){const e=this.linkNode.closestScroller();e.length>0&&e.off("scroll",this.scrollListener)}this.linkNode=null,this.container.hide(),window.removeEventListener("resize",this.resizeListener),this.config.onHide&&this.config.onHide()}unmount(){this.hide(),this.container.remove()}}const Es=["text","c","csharp","cpp","css","go","html","java","javascript","json","markdown","php","python","rust","sql","typescript","xml","yaml"];const Ts=()=>{};class Is{constructor(e){this.horizontalDirection="right",this.verticalDirection="bottom",this.range=null,this.noMouseEvent=!1,this.keydownListener=e=>{if(Zt("escape",e))return e.preventDefault(),void this.hide();const t=Zt("down",e),i=Zt("up",e),n=Zt("enter",e);if(!t&&!i&&!n)return;const s=this.container.find(".lake-menu-item-selected");if(0===s.length){const e=this.container.find(".lake-menu-item").eq(0);return ue(e,{behavior:"instant",block:"start"}),void e.addClass("lake-menu-item-selected")}if(this.noMouseEvent=!0,t){e.preventDefault();let t=s.next();0===t.length&&(t=this.container.find(".lake-menu-item").eq(0)),ue(t,{behavior:"instant",block:"end"}),this.container.find(".lake-menu-item").removeClass("lake-menu-item-selected"),t.addClass("lake-menu-item-selected")}else if(i){e.preventDefault();let t=s.prev();if(0===t.length){const e=this.container.find(".lake-menu-item");t=e.eq(e.length-1)}ue(t,{behavior:"instant",block:"start"}),this.container.find(".lake-menu-item").removeClass("lake-menu-item-selected"),t.addClass("lake-menu-item-selected")}else n&&(e.preventDefault(),s.emit("click"));window.setTimeout((()=>{this.noMouseEvent=!1}),50)},this.clickListener=e=>{const t=new T(e.target);t.get(0).isConnected&&(this.container.contains(t)||this.hide())},this.scrollListener=()=>this.updatePosition(),this.resizeListener=()=>this.updatePosition(),this.items=e.items,this.onShow=e.onShow||Ts,this.onHide=e.onHide||Ts,this.container=I('<ul class="lake-popup lake-menu" />')}appendItemNode(e){e.on("mouseenter",(()=>{this.noMouseEvent||(this.container.find(".lake-menu-item").removeClass("lake-menu-item-selected"),e.addClass("lake-menu-item-selected"))})),e.on("mouseleave",(()=>{this.noMouseEvent||e.removeClass("lake-menu-item-selected")})),this.container.append(e)}appendItems(e){this.container.empty();for(const t of e){const e=this.getItemNode(t);e.addClass("lake-menu-item"),this.appendItemNode(e)}}selectFirstItemNodeIfNeeded(){0===this.container.find(".lake-menu-item-selected").length&&this.container.find(".lake-menu-item").eq(0).addClass("lake-menu-item-selected")}updatePosition(e=!1){if(!this.range||this.range.isCollapsed)return;const t=this.range.get().getBoundingClientRect(),i=t.x+window.scrollX,n=t.y+window.scrollY;e||(t.x+this.container.width()>window.innerWidth?this.horizontalDirection="left":this.horizontalDirection="right",t.y+t.height+this.container.height()>window.innerHeight?this.verticalDirection="top":this.verticalDirection="bottom"),"left"===this.horizontalDirection?this.container.css("left",`${i-this.container.width()+t.width}px`):this.container.css("left",`${i}px`),"top"===this.verticalDirection?this.container.css("top",n-this.container.height()-5+"px"):this.container.css("top",`${n+t.height+5}px`)}get visible(){return this.container.get(0).isConnected&&"none"!==this.container.computedCSS("display")}update(e){const t=this.search(e);0!==t.length?(this.appendItems(t),this.selectFirstItemNodeIfNeeded(),this.updatePosition(!0),this.container.css("visibility","")):this.hide()}show(e,t){if(e.isCollapsed)return;if(0===this.items.length)return;this.container.get(0).isConnected||I(document.body).append(this.container),this.appendItems(this.items),this.selectFirstItemNodeIfNeeded(),this.range=e,this.container.css("visibility","hidden"),this.container.show(),this.container.get(0).scrollTo(0,0),this.updatePosition(),this.container.css("width",""),this.container.css("width",`${this.container.width()}px`);const i=e.commonAncestor.closestScroller();if(i.length>0&&i.on("scroll",this.scrollListener),document.addEventListener("keydown",this.keydownListener,!0),document.addEventListener("click",this.clickListener),window.addEventListener("resize",this.resizeListener),t){const e=this.search(t);if(0===e.length)return;this.appendItems(e),this.selectFirstItemNodeIfNeeded(),this.updatePosition(!0)}this.container.css("visibility",""),this.onShow()}hide(){if(this.range){const e=this.range.commonAncestor.closestScroller();e.length>0&&e.off("scroll",this.scrollListener)}this.range=null,this.container.hide(),document.removeEventListener("keydown",this.keydownListener,!0),document.removeEventListener("click",this.clickListener),window.removeEventListener("resize",this.resizeListener),this.onHide()}unmount(){this.hide(),this.container.remove()}}const Ms=()=>{};class Ps extends Is{constructor(e){super(e),this.onSelect=e.onSelect||Ms,this.container.addClass("lake-mention-menu")}getItemNode(e){var t;const i=I(a`
|
|
107
107
|
<li>
|
|
108
108
|
<div class="lake-mention-avatar"></div>
|
|
109
109
|
<div class="lake-mention-nickname">${null!==(t=e.nickname)&&void 0!==t?t:e.name}</div>
|
|
@@ -123,9 +123,9 @@ function Ei(e,t,i){const n=document.createElement(t);return e&&(n.className=e),i
|
|
|
123
123
|
<path d="M181.66,133.66l-80,80A8,8,0,0,1,88,208V48a8,8,0,0,1,13.66-5.66l80,80A8,8,0,0,1,181.66,133.66Z"></path>
|
|
124
124
|
</svg>
|
|
125
125
|
</div>
|
|
126
|
-
`),e.overlayContainer.append(i)):s.preventDefault()})),e.container.on("dragover",(t=>{const o=t;o.preventDefault();const r=o.dataTransfer;if(!r)return;if(r.dropEffect="move",!i)return;const a=I(o.target);if(a.isContainer)return;const l=a.closest("lake-box");n=l.length>0?l.isBlockBox?l:l.closestBlock():a.closestBlock();const c=e.container.get(0).getBoundingClientRect();let d=n.get(0).getBoundingClientRect();s="bottom";let h=d.x-c.x,p=d.y+d.height-c.y+parseInt(n.computedCSS("margin-bottom"),10)/2;if(o.clientY<d.y+d.height/2){const t=n.prev();t.length>0&&t.isBlock||t.isBlockBox?(n=t,d=n.get(0).getBoundingClientRect(),h=d.x-c.x,p=d.y+d.height-c.y+parseInt(n.computedCSS("margin-bottom"),10)/2):(s="top",p=d.y-c.y-parseInt(e.container.computedCSS("padding-top"),10)/2)}i.css({top:`${p}px`,left:`${h}px`,width:`${d.width}px`,display:"block"})})),e.container.on("dragend",(()=>{i&&(i.remove(),i=null)})),e.container.on("drop",(o=>{const r=o;if(r.dataTransfer&&i&&(i.remove(),i=null,t&&n&&t.isBox)){if(t.get(0)===n.get(0))return;if("bottom"===s&&t.get(0)===n.next().get(0))return;r.preventDefault();const i=Fe(t),o=e.selection.range;n.isBox?"top"===s?o.selectBoxStart(n):o.selectBoxEnd(n):(o.selectNodeContents(n),"top"===s?o.collapseToStart():o.collapseToEnd()),e.selection.insertBox(i.name,i.value),t.remove(),e.history.save()}}))})),$t.plugin.add("undo",(e=>{e.readonly||(e.command.add("undo",{isDisabled:()=>!e.history.canUndo,execute:()=>{e.history.undo()}}),e.keystroke.setKeydown("mod+z",(t=>{e.selection.range.isInsideBox||(t.preventDefault(),e.command.execute("undo"))})))})),$t.plugin.add("redo",(e=>{if(e.readonly)return;e.command.add("redo",{isDisabled:()=>!e.history.canRedo,execute:()=>{e.history.redo()}});const t=t=>{e.selection.range.isInsideBox||(t.preventDefault(),e.command.execute("redo"))};e.keystroke.setKeydown("mod+y",t),e.keystroke.setKeydown("mod+shift+z",t)})),$t.plugin.add("selectAll",(e=>{e.readonly||e.command.add("selectAll",{execute:()=>{const t=e.selection.range;t.selectNodeContents(e.container),t.shrink()}})})),$t.plugin.add("heading",(e=>{e.readonly||e.command.add("heading",{selectedValues:e=>{const t=e.find((e=>e.node.isHeading||"p"===e.name));return t?[t.name]:[]},execute:t=>{e.selection.setBlocks(`<${t} />`),e.history.save()}})})),$t.plugin.add("blockQuote",(e=>{e.readonly||e.command.add("blockQuote",{isSelected:e=>!!e.find((e=>"blockquote"===e.name)),execute:t=>{t&&vs.indexOf(t)>=0?e.selection.setBlocks(a`<blockquote type="${t}" />`):e.selection.setBlocks("<blockquote />"),e.history.save()}})})),$t.plugin.add("list",(e=>{e.readonly||(e.command.add("list",{selectedValues:e=>{let t;for(const i of e){if("ol"===i.name){t="numbered";break}if("ul"===i.name&&!i.node.hasAttr("type")){t="bulleted";break}if("ul"===i.name&&"checklist"===i.node.attr("type")){t="checklist";break}}return t?[t]:[]},execute:(t,i=!1)=>{const n=e.selection.range.getBlocks();let s=!1,o=!1,r=!1;for(const e of n)s||"ol"!==e.name||(s=!0),o||"ul"!==e.name||e.hasAttr("type")||(o=!0),r||"ul"!==e.name||"checklist"!==e.attr("type")||(r=!0);s?("numbered"===t&&ws(e),"bulleted"===t&&xs(e),"checklist"===t&&bs(e,i)):o?("numbered"===t&&ys(e),"bulleted"===t&&ws(e),"checklist"===t&&bs(e,i)):r?("numbered"===t&&ys(e),"bulleted"===t&&xs(e),"checklist"===t&&ws(e)):("numbered"===t&&ys(e),"bulleted"===t&&xs(e),"checklist"===t&&bs(e,i)),e.history.save()}}),e.container.on("click",(t=>{const i=t;if(!i.target)return;const n=I(i.target);"li"===n.name&&""!==n.attr("value")&&i.offsetX<=18&&(n.attr("value",("true"!==n.attr("value")).toString()),e.history.save())})))})),$t.plugin.add("align",(e=>{e.readonly||e.command.add("align",{selectedValues:e=>{let t;for(const i of e)if(i.node.isBlock){t=i.node.computedCSS("text-align");break}return t?[ks[t]||t]:[]},execute:t=>{e.selection.setBlocks({"text-align":t}),e.history.save()}})})),$t.plugin.add("indent",(e=>{e.readonly||e.command.add("indent",{execute:t=>{const i=e.selection.range.getBlocks();for(const e of i)R(e,t);e.history.save()}})})),$t.plugin.add("bold",(e=>{e.readonly||(e.command.add("bold",{isDisabled:e=>!!e.find((e=>e.node.isHeading)),isSelected:e=>!!e.find((e=>e.name===Ss)),execute:()=>{e.command.isSelected("bold")?e.selection.removeMark(`<${Ss} />`):e.selection.addMark(`<${Ss} />`),e.history.save()}}),e.keystroke.setKeydown("mod+b",(t=>{t.preventDefault(),e.command.execute("bold")})))})),$t.plugin.add("italic",(e=>{e.readonly||(e.command.add("italic",{isSelected:e=>!!e.find((e=>"i"===e.name)),execute:()=>{e.command.isSelected("italic")?e.selection.removeMark("<i />"):e.selection.addMark("<i />"),e.history.save()}}),e.keystroke.setKeydown("mod+i",(t=>{t.preventDefault(),e.command.execute("italic")})))})),$t.plugin.add("underline",(e=>{e.readonly||(e.command.add("underline",{isSelected:e=>!!e.find((e=>"u"===e.name)),execute:()=>{e.command.isSelected("underline")?e.selection.removeMark("<u />"):e.selection.addMark("<u />"),e.history.save()}}),e.keystroke.setKeydown("mod+u",(t=>{t.preventDefault(),e.command.execute("underline")})))})),$t.plugin.add("strikethrough",(e=>{e.readonly||(e.command.add("strikethrough",{isSelected:e=>!!e.find((e=>"s"===e.name)),execute:()=>{e.command.isSelected("strikethrough")?e.selection.removeMark("<s />"):e.selection.addMark("<s />"),e.history.save()}}),e.keystroke.setKeydown("mod+shift+x",(t=>{t.preventDefault(),e.command.execute("strikethrough")})))})),$t.plugin.add("subscript",(e=>{e.readonly||e.command.add("subscript",{isSelected:e=>!!e.find((e=>e.name===Cs)),execute:()=>{e.command.isSelected("subscript")?e.selection.removeMark(`<${Cs} />`):e.selection.addMark(`<${Cs} />`),e.history.save()}})})),$t.plugin.add("superscript",(e=>{e.readonly||e.command.add("superscript",{isSelected:e=>!!e.find((e=>e.name===Bs)),execute:()=>{e.command.isSelected("superscript")?e.selection.removeMark(`<${Bs} />`):e.selection.addMark(`<${Bs} />`),e.history.save()}})})),$t.plugin.add("code",(e=>{e.readonly||e.command.add("code",{isSelected:e=>!!e.find((e=>e.name===_s)),execute:()=>{e.command.isSelected("code")?e.selection.removeMark(`<${_s} />`):e.selection.addMark(`<${_s} />`),e.history.save()}})})),$t.plugin.add("fontFamily",(e=>{e.readonly||e.command.add("fontFamily",{selectedValues:e=>{for(const t of e)if("span"===t.name){return[t.node.css("font-family").replace(/['"]/g,"")]}return[]},execute:t=>{e.selection.addMark(`<span style="font-family: ${t};" />`),e.history.save()}})})),$t.plugin.add("fontSize",(e=>{e.readonly||e.command.add("fontSize",{isDisabled:e=>!!e.find((e=>e.node.isHeading)),selectedValues:e=>{for(const t of e)if("span"===t.name){return[t.node.css("font-size").replace(/\.\d+/,"")]}return[]},execute:t=>{e.selection.addMark(`<span style="font-size: ${t};" />`),e.history.save()}})})),$t.plugin.add("fontColor",(e=>{e.readonly||e.command.add("fontColor",{selectedValues:e=>{for(const t of e)if("span"===t.name){return[u(t.node.computedCSS("color"))]}return[]},execute:t=>{e.selection.addMark(`<span style="color: ${t};" />`),e.history.save()}})})),$t.plugin.add("highlight",(e=>{e.readonly||e.command.add("highlight",{selectedValues:e=>{for(const t of e)if("span"===t.name){return[u(t.node.computedCSS("background-color"))]}return[]},execute:t=>{e.selection.addMark(`<span style="background-color: ${t};" />`),e.history.save()}})})),$t.plugin.add("removeFormat",(e=>{e.readonly||e.command.add("removeFormat",{execute:()=>{e.selection.removeMark(),e.history.save()}})})),$t.plugin.add("formatPainter",(e=>{if(e.readonly)return;let t=[];e.command.add("formatPainter",{execute:()=>{e.container.addClass(As);const i=e.selection.getAppliedItems();for(const e of i){const i=e.node.clone();i.isMark&&"a"!==i.name&&t.push(i)}}}),e.container.on("click",(()=>{if(e.container.removeClass(As),0!==t.length){for(const i of t)e.selection.addMark(i);t=[],e.history.save()}})),e.event.on("click",(i=>{e.container.contains(i)||i.closest('button[name="formatPainter"]').length>0||(e.container.removeClass(As),t=[])}))})),$t.plugin.add("link",(e=>{if(e.readonly)return;const t=new Ls({locale:e.locale,onSave:t=>{const i=e.selection.range;i.setStartAfter(t),i.collapseToStart(),e.selection.sync(),e.history.save()},onRemove:t=>{const i=e.selection.range;i.setStartAfter(t),i.collapseToStart(),e.selection.sync(),e.history.save()},onShow:()=>{e.popup=t},onHide:()=>{e.popup=null}});return e.event.on("click",(i=>{if(t.container.contains(i))return;if(i.closest('button[name="link"]').length>0)return;const n=i.closest("a");if(0===n.length||!e.container.contains(n)||n.closest("lake-box").length>0){if(!t.visible)return;return e.selection.sync(),void t.hide()}t.show(n)})),e.command.add("link",{execute:()=>{const i=e.selection.insertLink(`<a href="">${e.locale.link.newLink()}</a>`);i&&(e.history.save(),t.show(i))}}),()=>t.unmount()})),$t.plugin.add("hr",(e=>{e.readonly||(e.event.on("beforepaste",(e=>{new Ue(e).find("hr").each((e=>{const t=I(e),i=Fe("hr");t.replaceWith(i.node)}))})),e.command.add("hr",{execute:()=>{e.selection.insertBox("hr"),e.history.save()}}))})),$t.plugin.add("codeBlock",(e=>{window.LakeCodeMirror&&(e.setPluginConfig("codeBlock",{langList:Es,defaultLang:"text"}),e.readonly||e.command.add("codeBlock",{execute:t=>{const i=e.selection.insertBox("codeBlock",t);e.history.save(),i.getContainer().find(".lake-code-block").emit("click")}}))})),$t.plugin.add("image",(e=>{e.setPluginConfig("image",{requestMethod:"POST",requestTypes:["image/gif","image/jpeg","image/png","image/svg+xml"]}),e.readonly||(e.event.on("beforepaste",(e=>{new Ue(e).find("img").each((e=>{const t=I(e),i=Fe("image"),n=t.attr("data-lake-value");""===n?i.value={url:t.attr("src"),status:"done"}:i.node.attr("value",n),t.replaceWith(i.node)}))})),e.command.add("image",{execute:t=>{e.selection.insertBox("image",t),e.history.save()}}))})),$t.plugin.add("video",(e=>{e.readonly||e.command.add("video",{execute:t=>{const i=e.selection.insertBox("video",t);e.history.save(),i&&i.getContainer().find('input[name="url"]').focus()}})})),$t.plugin.add("file",(e=>{e.setPluginConfig("file",{requestMethod:"POST",requestTypes:["application/zip","application/x-zip-compressed","application/vnd.rar","image/gif","image/jpeg","image/png","image/svg+xml","text/plain","text/html","application/pdf","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","application/vnd.ms-powerpoint","application/vnd.openxmlformats-officedocument.presentationml.presentation"]}),e.readonly||e.command.add("file",{execute:t=>{e.selection.insertBox("file",t),e.history.save()}})})),$t.plugin.add("emoji",(e=>{e.readonly||e.command.add("emoji",{execute:t=>{e.selection.insertBox("emoji",t),e.history.save()}})})),$t.plugin.add("equation",(e=>{window.katex&&(e.setPluginConfig("equation",{helpUrl:"https://katex.org/docs/supported"}),e.readonly||e.command.add("equation",{execute:t=>{const i=e.selection.insertBox("equation",t);e.history.save();const n=i.getContainer();n.addClass("lake-box-activated"),n.find("textarea").focus()}}))})),$t.plugin.add("specialCharacter",(e=>{e.readonly||e.command.add("specialCharacter",{execute:t=>{const i=new Ue;i.append(document.createTextNode(t)),e.selection.insertFragment(i),e.history.save()}})})),$t.plugin.add("mention",(e=>{if(e.setPluginConfig("mention",{requestMethod:"GET",items:[],getProfileUrl:e=>`/${e.name}`}),e.readonly)return;const{requestAction:t,requestMethod:i,items:n}=e.config.mention;let s=null;const o=(t,i)=>{s&&s.hide(),e.focus();const n=e.selection.range.getCharacterRange("@");n&&n.get().deleteContents(),e.selection.insertBox("mention",i),e.history.save()},r=()=>{e.popup=s},a=()=>{e.popup=null},l=()=>{const l=e.selection.range;if(!l.isCollapsed)return;const c=l.getCharacterRange("@");if(null===c)return;const d=Ds(l);null!==d&&(s?s.show(c,d):t?qe({onSuccess:e=>{e.data&&(s=new Ps({items:e.data,onSelect:o,onShow:r,onHide:a}),s.show(c,d))},action:t,method:i}):(s=new Ps({items:n,onSelect:o,onShow:r,onHide:a}),s.show(c,d)))};return e.container.on("keyup",(t=>{if(e.isComposing)return;const i=t;if(Zt(["down","up","enter"],i))return;if(!s||!s.visible){if("@"===i.key)return void l();if(!Zt(["backspace","delete"],i))return;l()}const n=Ds(e.selection.range);null!==n?s&&s.update(n):s&&s.hide()})),()=>{s&&s.unmount()}})),$t.plugin.add("markdown",(e=>{e.readonly||(e.keystroke.setKeydown("space",(t=>{const i=e.selection.range;if(i.isBox)return;const n=function(e){const t=e.selection.range;let i=t.startNode,n=t.startOffset;if(0!==n){if(i.isElement){const e=i.children()[n-1];if(!e||!e.isText)return;i=e,n=i.text().length}if(!(n<1))return{node:i,offset:n}}}(e);if(!n)return;if(function(e,t){const i=e.selection,n=i.range,s=t.offset,o=t.node.text().slice(0,s);for(const t of Zs){const r=t.re.exec(o);if(null!==r){const o=t.getParameters(),a=o.shift();if(!e.command.has(a))return!1;e.history.pause();const l=i.insertBookmark(),c=l.focus.prev(),d=c.text(),h=`${d.replace(t.re,"$1")}`;return c.get(0).nodeValue=h,n.setStart(c,s-r[0].length),n.setEnd(c,s-(d.length-h.length)-1),e.command.execute(a,...o),i.toBookmark(l),e.history.continue(),e.history.save(),!0}}return!1}(e,n))return void t.preventDefault();const s=i.getBlocks()[0];s&&(s.isHeading||"p"===s.name)&&function(e,t){const i=e.selection,n=t.offset;let s=t.node.text().slice(0,n);s=s.replace(/[\u200B\u2060]/g,"");for(const t of Hs){const n=t.re.exec(s);if(null!==n){const s=t.getParameters(n),o=s.shift();if(!e.command.has(o))return!1;const r=i.insertBookmark();r.focus.prev().remove();const a=r.focus.closestBlock();return $s(a),i.range.shrinkAfter(a),i.toBookmark(r),e.command.execute(o,...s),!0}}return!1}(e,n)&&t.preventDefault()})),e.keystroke.setKeydown("enter",(t=>{const i=e.selection.range;if(i.isBox)return;const n=i.getBlocks()[0];return!n||!n.isHeading&&"p"!==n.name||n.find("lake-box").length>0||""!==i.getEndText()?void 0:function(e,t){const i=e.selection;let n=t.text();n=n.replace(/[\u200B\u2060]/g,"");for(const s of zs){const o=s.re.exec(n);if(null!==o){const n=s.getParameters(o),r=n.shift();return!!e.command.has(r)&&(t.empty(),$s(t),i.range.shrinkAfter(t),e.command.execute(r,...n),!0)}}return!1}(e,n)?(t.preventDefault(),t.stopImmediatePropagation(),!1):void 0})))})),$t.plugin.add("enterKey",(e=>{e.readonly||e.keystroke.setKeydown("enter",(t=>{const i=e.selection.range;if(i.isInsideBox)return;if(t.preventDefault(),e.fixContent(),i.isBox)return Fs(e),void e.history.save();if(i.adjust(),i.isInoperative)return;if(i.isBox)return Fs(e),void e.history.save();let n=i.getBlocks()[0];if(n||(e.selection.setBlocks("<p />"),n=i.getBlocks()[0]),n.isEmpty&&"p"!==n.name)return e.selection.setBlocks("<p />"),void e.history.save();Vs(e,n),e.history.save()}))})),$t.plugin.add("shiftEnterKey",(e=>{e.readonly||e.keystroke.setKeydown("shift+enter",(t=>{const i=e.selection.range;if(!i.isInsideBox){if(e.fixContent(),t.preventDefault(),i.isBox)return qs(e),void e.history.save();if(i.adjust(),!i.isInoperative){if(i.isBox)return qs(e),void e.history.save();Rs(e),e.history.save()}}}))})),$t.plugin.add("backspaceKey",(e=>{e.readonly||e.keystroke.setKeydown("backspace",(t=>{const i=e.selection.range;if(i.isInsideBox){const n=Fe(i.commonAncestor.closest("lake-box")),s=n.value;return void(!i.isCollapsed||"codeBlock"!==n.name||void 0!==s.code&&""!==s.code||(t.preventDefault(),e.selection.removeBox(n),e.history.save()))}if(e.fixContent(),i.isBoxStart){const n=i.startNode.closest("lake-box"),s=n.prev();if(0===s.length){const i=n.closestBlock();return void(i.length>0&&!i.isContainer&&(t.preventDefault(),js(e,i),e.history.save()))}if(s.isBlock)return s.isEmpty?(t.preventDefault(),s.remove(),e.selection.fixList(),void e.history.save()):(t.preventDefault(),void i.shrinkAfter(s));if(s.isText&&1===s.text().length)return t.preventDefault(),s.remove(),void e.history.save();i.adjustBox()}if(i.isBox)return t.preventDefault(),e.selection.removeBox(),void e.history.save();if(!i.isCollapsed)return t.preventDefault(),e.selection.deleteContents(),""===e.container.html().trim()&&e.setValue("<p><br /><focus /></p>"),void e.history.save();i.adjust();const n=i.getPrevNode();if(n.isBox)return t.preventDefault(),e.selection.removeBox(n),void e.history.save();if((n.isMark||"a"===n.name)&&n.isEmpty)return t.preventDefault(),n.remove(),void e.history.save();if(n.isText&&1===n.text().length&&n.parent().isBlock){t.preventDefault();const s=n.closestBlock();if(i.setStartBefore(n),i.collapseToStart(),n.remove(),s.isEmpty){const e=D(s);i.setStartBefore(e),i.collapseToStart()}return void e.history.save()}const s=i.getNextNode();if("br"===n.name&&s.length>0)return t.preventDefault(),i.setStartBefore(n),i.collapseToStart(),n.remove(),void e.history.save();if(""===i.getStartText()){t.preventDefault();let n=i.getBlocks()[0];if(n||(e.selection.setBlocks("<p />"),n=i.getBlocks()[0]),""!==n.css("margin-left")||""!==n.css("text-indent")||""!==n.attr("indent"))return R(n,"decrease"),void e.history.save();if(n.isList||"blockquote"===n.name)return e.selection.setBlocks("<p />"),void e.history.save();js(e,n),e.history.save()}}))})),$t.plugin.add("deleteKey",(e=>{e.readonly||e.keystroke.setKeydown("delete",(t=>{const i=e.selection.range;if(i.isInsideBox)return;if(e.fixContent(),i.isBoxEnd){const n=i.startNode.closest("lake-box"),s=n.next();if(0===s.length){const i=n.closestBlock();return void(i.length>0&&!i.isContainer&&(t.preventDefault(),Ws(e,i),e.history.save()))}if(s.isBlock)return s.isEmpty?(t.preventDefault(),s.remove(),e.selection.fixList(),void e.history.save()):(t.preventDefault(),void i.shrinkBefore(s));i.adjustBox()}if(i.isBox)return t.preventDefault(),e.selection.removeBox(),void e.history.save();if(!i.isCollapsed)return t.preventDefault(),e.selection.deleteContents(),""===e.container.html().trim()&&e.setValue("<p><br /><focus /></p>"),void e.history.save();i.adjust();const n=i.getNextNode();if(n.isBox)return t.preventDefault(),e.selection.removeBox(n),void e.history.save();"br"===n.name&&n.next().length>0&&(t.preventDefault(),i.setStartBefore(n),i.collapseToStart(),n.remove(),e.history.save());if(""===i.getEndText()){t.preventDefault();let n=i.getBlocks()[0];n||(e.selection.setBlocks("<p />"),n=i.getBlocks()[0]),Ws(e,n),e.history.save()}}))})),$t.plugin.add("tabKey",(e=>{e.readonly||e.keystroke.setKeydown("tab",(t=>{if(!1===e.config.indentWithTab)return;const i=e.selection.range;if(i.isInsideBox)return;t.preventDefault();const n=i.getBlocks();for(const e of n)"p"!==e.name||"2em"===e.css("text-indent")?R(e,"increase"):e.css("text-indent","2em");e.history.save()}))})),$t.plugin.add("arrowKeys",(e=>{e.readonly||(e.keystroke.setKeydown("left",(t=>{const i=e.selection.range;if(i.isInsideBox)return;const n=i.commonAncestor.closest("lake-box");if(n.length>0){if(i.isBoxStart){const e=n.prev();return e.isBlock||e.isBox?(t.preventDefault(),e.isInlineBox?void i.selectBox(e):void i.shrinkAfter(e)):(i.setStartBefore(n),void i.collapseToStart())}return i.isBoxEnd?(t.preventDefault(),void i.selectBox(n)):(t.preventDefault(),void i.selectBoxStart(n))}if(!i.isCollapsed)return;const s=i.getPrevNode();s.isBox&&(t.preventDefault(),i.selectBox(s))})),e.keystroke.setKeydown("right",(t=>{const i=e.selection.range;if(i.isInsideBox)return;const n=i.commonAncestor.closest("lake-box");if(n.length>0){if(i.isBoxStart)return t.preventDefault(),void i.selectBox(n);if(i.isBoxEnd){const e=n.next();return e.isBlock||e.isBox?(t.preventDefault(),e.isInlineBox?void i.selectBox(e):void i.shrinkBefore(e)):(i.setStartAfter(n),void i.collapseToStart())}return t.preventDefault(),void i.selectBoxEnd(n)}if(!i.isCollapsed)return;const s=i.getNextNode();s.isBox&&(t.preventDefault(),i.selectBox(s))})),e.keystroke.setKeydown("up",(t=>{const i=e.selection.range;if(i.isInsideBox)return;const n=i.commonAncestor.closest("lake-box");if(n.length>0){if(n.isBlockBox){const e=n.prev();if(e.isBlock||e.isBox)return t.preventDefault(),void i.shrinkAfter(e)}i.setStartBefore(n),i.collapseToStart()}})),e.keystroke.setKeydown("down",(t=>{const i=e.selection.range;if(i.isInsideBox)return;const n=i.commonAncestor.closest("lake-box");if(n.length>0){if(n.isBlockBox){const e=n.next();if(e.isBlock||e.isBox)return t.preventDefault(),void i.shrinkBefore(e)}i.setStartAfter(n),i.collapseToStart()}})))})),$t.plugin.add("escapeKey",(e=>{e.readonly||e.keystroke.setKeydown("escape",(t=>{const i=e.selection,n=i.range;if(n.isBoxCenter||n.isInsideBox){t.preventDefault();const e=n.commonAncestor.closest("lake-box");return n.selectBoxEnd(e),void i.sync()}e.hasFocus&&(t.preventDefault(),e.blur())}))})),$t.plugin.add("slash",(e=>{if(e.setPluginConfig("slash",{items:Qs}),e.readonly)return;const t=new Xs({locale:e.locale,items:e.config.slash.items,onSelect:(i,n,s)=>{if(t&&t.hide(),e.focus(),function(e){const t=e.selection.range,i=t.commonAncestor.closestBlock();i.empty(),D(i),t.shrinkBefore(i)}(e),"upload"===n.type){if(!s)return;const t=i.target,o=s.get(0),r=t.files||[];for(const t of r)je({editor:e,name:n.name,file:t,onError:t=>{o.value="",e.config.onMessage("error",t)},onSuccess:()=>{o.value=""}})}else n.onClick(e,n.name)},onShow:()=>{e.popup=t},onHide:()=>{e.popup=null}}),i=()=>{const i=e.selection.range;if(!i.isCollapsed)return;const n=i.getBlocks()[0];if(!n)return;if(n.find("lake-box").length>0)return;const s=Ys(n);if(null===s)return;const o=i.clone();o.selectNodeContents(n),t.show(o,s)};return e.container.on("keyup",(n=>{if(e.isComposing)return;const s=n;if(Zt(["down","up","enter"],s))return;if(!t.visible){if(Zt("/",s))return void i();if(!Zt(["backspace","delete"],s))return;i()}const o=e.selection.range.getBlocks()[0];if(!o)return;const r=Ys(o);null!==r?t.update(r):t.hide()})),()=>{t.unmount()}})),e.Box=Ve,e.Button=be,e.Dropdown=He,e.Editor=$t,e.Fragment=Ue,e.HTMLParser=Xe,e.Nodes=T,e.Range=M,e.TextParser=Qe,e.Toolbar=class{constructor(e){this.placement="top",this.allMenuMap=new Map,this.buttonItemList=[],this.dropdownItemList=[],this.dropdownList=[],this.root=I(e.root),this.items=e.items||Gt,e.placement&&(this.placement=e.placement),this.container=I('<div class="lake-toolbar" />'),this.root.addClass("lake-custom-properties")}appendDivider(){this.container.append('<div class="lake-toolbar-divider" />')}appendNormalButton(e,t){new be({root:this.container,name:t.name,icon:t.icon,tooltip:"string"==typeof t.tooltip?t.tooltip:t.tooltip(e.locale),tabIndex:-1,onClick:()=>{e.focus(),t.onClick(e,t.name)}}).render()}appendDropdown(e,t){const i=new He({root:this.container,locale:e.locale,name:t.name,icon:t.icon,accentIcon:t.accentIcon,downIcon:t.downIcon,defaultValue:t.defaultValue,tooltip:t.tooltip,width:t.width,menuType:t.menuType,menuItems:t.menuItems,menuWidth:t.menuWidth,menuHeight:t.menuHeight,tabIndex:-1,location:"local",direction:"top"===this.placement?"bottom":"top",onSelect:i=>{e.focus(),t.onSelect(e,i)}});i.render(),this.dropdownList.push(i)}appendUploadButton(e,t){const i=I(a`
|
|
126
|
+
`),e.overlayContainer.append(i)):s.preventDefault()})),e.container.on("dragover",(t=>{const o=t;o.preventDefault();const r=o.dataTransfer;if(!r)return;if(r.dropEffect="move",!i)return;const a=I(o.target);if(a.isContainer)return;const l=a.closest("lake-box");n=l.length>0?l.isBlockBox?l:l.closestBlock():a.closestBlock();const c=e.container.get(0).getBoundingClientRect();let d=n.get(0).getBoundingClientRect();s="bottom";let h=d.x-c.x,p=d.y+d.height-c.y+parseInt(n.computedCSS("margin-bottom"),10)/2;if(o.clientY<d.y+d.height/2){const t=n.prev();t.length>0&&t.isBlock||t.isBlockBox?(n=t,d=n.get(0).getBoundingClientRect(),h=d.x-c.x,p=d.y+d.height-c.y+parseInt(n.computedCSS("margin-bottom"),10)/2):(s="top",p=d.y-c.y-parseInt(e.container.computedCSS("padding-top"),10)/2)}i.css({top:`${p}px`,left:`${h}px`,width:`${d.width}px`,display:"block"})})),e.container.on("dragend",(()=>{i&&(i.remove(),i=null)})),e.container.on("drop",(o=>{const r=o;if(r.dataTransfer&&i&&(i.remove(),i=null,t&&n&&t.isBox)){if(t.get(0)===n.get(0))return;if("bottom"===s&&t.get(0)===n.next().get(0))return;r.preventDefault();const i=Fe(t),o=e.selection.range;n.isBox?"top"===s?o.selectBoxStart(n):o.selectBoxEnd(n):(o.selectNodeContents(n),"top"===s?o.collapseToStart():o.collapseToEnd()),e.selection.insertBox(i.name,i.value),t.remove(),e.history.save()}}))})),$t.plugin.add("undo",(e=>{e.readonly||(e.command.add("undo",{isDisabled:()=>!e.history.canUndo,execute:()=>{e.history.undo()}}),e.keystroke.setKeydown("mod+z",(t=>{e.selection.range.isInsideBox||(t.preventDefault(),e.command.execute("undo"))})))})),$t.plugin.add("redo",(e=>{if(e.readonly)return;e.command.add("redo",{isDisabled:()=>!e.history.canRedo,execute:()=>{e.history.redo()}});const t=t=>{e.selection.range.isInsideBox||(t.preventDefault(),e.command.execute("redo"))};e.keystroke.setKeydown("mod+y",t),e.keystroke.setKeydown("mod+shift+z",t)})),$t.plugin.add("selectAll",(e=>{e.readonly||e.command.add("selectAll",{execute:()=>{const t=e.selection.range;t.selectNodeContents(e.container),t.shrink()}})})),$t.plugin.add("heading",(e=>{e.readonly||e.command.add("heading",{selectedValues:e=>{const t=e.find((e=>e.node.isHeading||"p"===e.name));return t?[t.name]:[]},execute:t=>{e.selection.setBlocks(`<${t} />`),e.history.save()}})})),$t.plugin.add("blockQuote",(e=>{e.readonly||e.command.add("blockQuote",{isSelected:e=>!!e.find((e=>"blockquote"===e.name)),execute:t=>{t&&vs.indexOf(t)>=0?e.selection.setBlocks(a`<blockquote type="${t}" />`):e.selection.setBlocks("<blockquote />"),e.history.save()}})})),$t.plugin.add("list",(e=>{e.readonly||(e.command.add("list",{selectedValues:e=>{let t;for(const i of e){if("ol"===i.name){t="numbered";break}if("ul"===i.name&&!i.node.hasAttr("type")){t="bulleted";break}if("ul"===i.name&&"checklist"===i.node.attr("type")){t="checklist";break}}return t?[t]:[]},execute:(t,i=!1)=>{const n=e.selection.range.getBlocks();let s=!1,o=!1,r=!1;for(const e of n)s||"ol"!==e.name||(s=!0),o||"ul"!==e.name||e.hasAttr("type")||(o=!0),r||"ul"!==e.name||"checklist"!==e.attr("type")||(r=!0);s?("numbered"===t&&ws(e),"bulleted"===t&&xs(e),"checklist"===t&&bs(e,i)):o?("numbered"===t&&ys(e),"bulleted"===t&&ws(e),"checklist"===t&&bs(e,i)):r?("numbered"===t&&ys(e),"bulleted"===t&&xs(e),"checklist"===t&&ws(e)):("numbered"===t&&ys(e),"bulleted"===t&&xs(e),"checklist"===t&&bs(e,i)),e.history.save()}}),e.container.on("click",(t=>{const i=t;if(!i.target)return;const n=I(i.target);"li"===n.name&&""!==n.attr("value")&&i.offsetX<=18&&(n.attr("value",("true"!==n.attr("value")).toString()),e.history.save())})))})),$t.plugin.add("align",(e=>{e.readonly||e.command.add("align",{selectedValues:e=>{let t;for(const i of e)if(i.node.isBlock){t=i.node.computedCSS("text-align");break}return t?[ks[t]||t]:[]},execute:t=>{e.selection.setBlocks({"text-align":t}),e.history.save()}})})),$t.plugin.add("indent",(e=>{e.readonly||e.command.add("indent",{execute:t=>{const i=e.selection.range.getBlocks();for(const e of i)R(e,t);e.history.save()}})})),$t.plugin.add("bold",(e=>{e.readonly||(e.command.add("bold",{isDisabled:e=>!!e.find((e=>e.node.isHeading)),isSelected:e=>!!e.find((e=>e.name===Ss)),execute:()=>{e.command.isSelected("bold")?e.selection.removeMark(`<${Ss} />`):e.selection.addMark(`<${Ss} />`),e.history.save()}}),e.keystroke.setKeydown("mod+b",(t=>{t.preventDefault(),e.command.execute("bold")})))})),$t.plugin.add("italic",(e=>{e.readonly||(e.command.add("italic",{isSelected:e=>!!e.find((e=>"i"===e.name)),execute:()=>{e.command.isSelected("italic")?e.selection.removeMark("<i />"):e.selection.addMark("<i />"),e.history.save()}}),e.keystroke.setKeydown("mod+i",(t=>{t.preventDefault(),e.command.execute("italic")})))})),$t.plugin.add("underline",(e=>{e.readonly||(e.command.add("underline",{isSelected:e=>!!e.find((e=>"u"===e.name)),execute:()=>{e.command.isSelected("underline")?e.selection.removeMark("<u />"):e.selection.addMark("<u />"),e.history.save()}}),e.keystroke.setKeydown("mod+u",(t=>{t.preventDefault(),e.command.execute("underline")})))})),$t.plugin.add("strikethrough",(e=>{e.readonly||(e.command.add("strikethrough",{isSelected:e=>!!e.find((e=>"s"===e.name)),execute:()=>{e.command.isSelected("strikethrough")?e.selection.removeMark("<s />"):e.selection.addMark("<s />"),e.history.save()}}),e.keystroke.setKeydown("mod+shift+x",(t=>{t.preventDefault(),e.command.execute("strikethrough")})))})),$t.plugin.add("subscript",(e=>{e.readonly||e.command.add("subscript",{isSelected:e=>!!e.find((e=>e.name===Cs)),execute:()=>{e.command.isSelected("subscript")?e.selection.removeMark(`<${Cs} />`):e.selection.addMark(`<${Cs} />`),e.history.save()}})})),$t.plugin.add("superscript",(e=>{e.readonly||e.command.add("superscript",{isSelected:e=>!!e.find((e=>e.name===Bs)),execute:()=>{e.command.isSelected("superscript")?e.selection.removeMark(`<${Bs} />`):e.selection.addMark(`<${Bs} />`),e.history.save()}})})),$t.plugin.add("code",(e=>{e.readonly||e.command.add("code",{isSelected:e=>!!e.find((e=>e.name===_s)),execute:()=>{e.command.isSelected("code")?e.selection.removeMark(`<${_s} />`):e.selection.addMark(`<${_s} />`),e.history.save()}})})),$t.plugin.add("fontFamily",(e=>{e.readonly||e.command.add("fontFamily",{selectedValues:e=>{for(const t of e)if("span"===t.name){return[t.node.css("font-family").replace(/['"]/g,"")]}return[]},execute:t=>{e.selection.addMark(`<span style="font-family: ${t};" />`),e.history.save()}})})),$t.plugin.add("fontSize",(e=>{e.readonly||e.command.add("fontSize",{isDisabled:e=>!!e.find((e=>e.node.isHeading)),selectedValues:e=>{for(const t of e)if("span"===t.name){return[t.node.css("font-size").replace(/\.\d+/,"")]}return[]},execute:t=>{e.selection.addMark(`<span style="font-size: ${t};" />`),e.history.save()}})})),$t.plugin.add("fontColor",(e=>{e.readonly||e.command.add("fontColor",{selectedValues:e=>{for(const t of e)if("span"===t.name){return[u(t.node.computedCSS("color"))]}return[]},execute:t=>{e.selection.addMark(`<span style="color: ${t};" />`),e.history.save()}})})),$t.plugin.add("highlight",(e=>{e.readonly||e.command.add("highlight",{selectedValues:e=>{for(const t of e)if("span"===t.name){return[u(t.node.computedCSS("background-color"))]}return[]},execute:t=>{e.selection.addMark(`<span style="background-color: ${t};" />`),e.history.save()}})})),$t.plugin.add("removeFormat",(e=>{e.readonly||e.command.add("removeFormat",{execute:()=>{e.selection.removeMark(),e.history.save()}})})),$t.plugin.add("formatPainter",(e=>{if(e.readonly)return;let t=[];e.command.add("formatPainter",{execute:()=>{e.container.addClass(As);const i=e.selection.getAppliedItems();for(const e of i){const i=e.node.clone();i.isMark&&"a"!==i.name&&t.push(i)}}}),e.container.on("click",(()=>{if(e.container.removeClass(As),0!==t.length){for(const i of t)e.selection.addMark(i);t=[],e.history.save()}})),e.event.on("click",(i=>{e.container.contains(i)||i.closest('button[name="formatPainter"]').length>0||(e.container.removeClass(As),t=[])}))})),$t.plugin.add("link",(e=>{if(e.readonly)return;const t=new Ls({locale:e.locale,onSave:t=>{const i=e.selection.range;i.setStartAfter(t),i.collapseToStart(),e.selection.sync(),e.history.save()},onRemove:t=>{const i=e.selection.range;i.setStartAfter(t),i.collapseToStart(),e.selection.sync(),e.history.save()},onShow:()=>{e.popup=t},onHide:()=>{e.popup=null}});return e.event.on("click",(i=>{if(t.container.contains(i))return;if(i.closest('button[name="link"]').length>0)return;const n=i.closest("a");if(0===n.length||!e.container.contains(n)||n.closest("lake-box").length>0){if(!t.visible)return;return e.selection.sync(),void t.hide()}t.show(n)})),e.command.add("link",{execute:()=>{const i=e.selection.insertLink(`<a href="">${e.locale.link.newLink()}</a>`);i&&(e.history.save(),t.show(i))}}),()=>t.unmount()})),$t.plugin.add("hr",(e=>{e.readonly||(e.event.on("beforepaste",(e=>{new Ue(e).find("hr").each((e=>{const t=I(e),i=Fe("hr");t.replaceWith(i.node)}))})),e.command.add("hr",{execute:()=>{e.selection.insertBox("hr"),e.history.save()}}))})),$t.plugin.add("codeBlock",(e=>{window.LakeCodeMirror&&(e.setPluginConfig("codeBlock",{langList:Es,defaultLang:"text"}),e.readonly||e.command.add("codeBlock",{execute:t=>{const i=e.selection.insertBox("codeBlock",t);e.history.save(),i.getContainer().find(".lake-code-block").emit("click")}}))})),$t.plugin.add("image",(e=>{e.setPluginConfig("image",{requestMethod:"POST",requestTypes:["image/gif","image/jpeg","image/png","image/svg+xml"]}),e.readonly||(e.event.on("beforepaste",(e=>{new Ue(e).find("img").each((e=>{const t=I(e),i=Fe("image"),n=t.attr("data-lake-value");""===n?i.value={url:t.attr("src"),status:"done"}:i.node.attr("value",n),t.replaceWith(i.node)}))})),e.command.add("image",{execute:t=>{e.selection.insertBox("image",t),e.history.save()}}))})),$t.plugin.add("video",(e=>{e.readonly||e.command.add("video",{execute:t=>{const i=e.selection.insertBox("video",t);e.history.save(),i&&i.getContainer().find('input[name="url"]').focus()}})})),$t.plugin.add("file",(e=>{e.setPluginConfig("file",{requestMethod:"POST",requestTypes:["application/zip","application/x-zip-compressed","application/vnd.rar","image/gif","image/jpeg","image/png","image/svg+xml","text/plain","text/html","application/pdf","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","application/vnd.ms-powerpoint","application/vnd.openxmlformats-officedocument.presentationml.presentation"]}),e.readonly||e.command.add("file",{execute:t=>{e.selection.insertBox("file",t),e.history.save()}})})),$t.plugin.add("emoji",(e=>{e.readonly||e.command.add("emoji",{execute:t=>{e.selection.insertBox("emoji",t),e.history.save()}})})),$t.plugin.add("equation",(e=>{window.katex&&(e.setPluginConfig("equation",{helpUrl:"https://katex.org/docs/supported"}),e.readonly||e.command.add("equation",{execute:t=>{const i=e.selection.insertBox("equation",t);e.history.save();const n=i.getContainer();n.addClass("lake-box-activated"),n.find("textarea").focus()}}))})),$t.plugin.add("specialCharacter",(e=>{e.readonly||e.command.add("specialCharacter",{execute:t=>{const i=new Ue;i.append(document.createTextNode(t)),e.selection.insertFragment(i),e.history.save()}})})),$t.plugin.add("mention",(e=>{if(e.setPluginConfig("mention",{requestMethod:"GET",items:[],getProfileUrl:e=>`/${e.name}`}),e.readonly)return;const{requestAction:t,requestMethod:i,items:n}=e.config.mention;let s=null;const o=(t,i)=>{s&&s.hide(),e.focus();const n=e.selection.range.getCharacterRange("@");n&&n.get().deleteContents(),e.selection.insertBox("mention",i),e.history.save()},r=()=>{e.popup=s},a=()=>{e.popup=null},l=()=>{const l=e.selection.range;if(!l.isCollapsed)return;const c=l.getCharacterRange("@");if(null===c)return;const d=Ds(l);null!==d&&(s?s.show(c,d):t?qe({onSuccess:e=>{e.data&&(s=new Ps({items:e.data,onSelect:o,onShow:r,onHide:a}),s.show(c,d))},action:t,method:i}):(s=new Ps({items:n,onSelect:o,onShow:r,onHide:a}),s.show(c,d)))};return e.container.on("keyup",(t=>{if(e.isComposing)return;const i=t;if(Zt(["down","up","enter"],i))return;if(!s||!s.visible){if("@"===i.key)return void l();if(!Zt(["backspace","delete"],i))return;l()}const n=Ds(e.selection.range);null!==n?s&&s.update(n):s&&s.hide()})),()=>{s&&s.unmount()}})),$t.plugin.add("markdown",(e=>{e.readonly||(e.keystroke.setKeydown("space",(t=>{const i=e.selection.range;if(i.isBox)return;const n=function(e){const t=e.selection.range;let i=t.startNode,n=t.startOffset;if(0!==n){if(i.isElement){const e=i.children()[n-1];if(!e||!e.isText)return;i=e,n=i.text().length}if(!(n<1))return{node:i,offset:n}}}(e);if(!n)return;if(function(e,t){const i=e.selection,n=i.range,s=t.offset,o=t.node.text().slice(0,s);for(const t of Zs){const r=t.re.exec(o);if(null!==r){const o=t.getParameters(),a=o.shift();if(!e.command.has(a))return!1;e.history.pause();const l=i.insertBookmark(),c=l.focus.prev(),d=c.text(),h=`${d.replace(t.re,"$1")}`;return c.get(0).nodeValue=h,n.setStart(c,s-r[0].length),n.setEnd(c,s-(d.length-h.length)-1),e.command.execute(a,...o),i.toBookmark(l),e.history.continue(),e.history.save(),!0}}return!1}(e,n))return void t.preventDefault();const s=i.getBlocks()[0];s&&(s.isHeading||"p"===s.name)&&function(e,t){const i=e.selection,n=t.offset;let s=t.node.text().slice(0,n);s=s.replace(/[\u200B\u2060]/g,"");for(const t of Hs){const n=t.re.exec(s);if(null!==n){const s=t.getParameters(n),o=s.shift();if(!e.command.has(o))return!1;const r=i.insertBookmark();r.focus.prev().remove();const a=r.focus.closestBlock();return $s(a),i.range.shrinkAfter(a),i.toBookmark(r),e.command.execute(o,...s),!0}}return!1}(e,n)&&t.preventDefault()})),e.keystroke.setKeydown("enter",(t=>{const i=e.selection.range;if(i.isBox)return;const n=i.getBlocks()[0];return!n||!n.isHeading&&"p"!==n.name||n.find("lake-box").length>0||""!==i.getEndText()?void 0:function(e,t){const i=e.selection;let n=t.text();n=n.replace(/[\u200B\u2060]/g,"");for(const s of zs){const o=s.re.exec(n);if(null!==o){const n=s.getParameters(o),r=n.shift();return!!e.command.has(r)&&(t.empty(),$s(t),i.range.shrinkAfter(t),e.command.execute(r,...n),!0)}}return!1}(e,n)?(t.preventDefault(),t.stopImmediatePropagation(),!1):void 0})))})),$t.plugin.add("enterKey",(e=>{e.readonly||e.keystroke.setKeydown("enter",(t=>{const i=e.selection.range;if(i.isInsideBox)return;if(t.preventDefault(),e.fixContent(),i.isBox)return Fs(e),void e.history.save();if(i.adjust(),i.isInoperative)return;if(i.isBox)return Fs(e),void e.history.save();let n=i.getBlocks()[0];if(n||(e.selection.setBlocks("<p />"),n=i.getBlocks()[0]),n.isEmpty&&"p"!==n.name)return e.selection.setBlocks("<p />"),void e.history.save();Vs(e,n),e.history.save()}))})),$t.plugin.add("shiftEnterKey",(e=>{e.readonly||e.keystroke.setKeydown("shift+enter",(t=>{const i=e.selection.range;if(!i.isInsideBox){if(e.fixContent(),t.preventDefault(),i.isBox)return qs(e),void e.history.save();if(i.adjust(),!i.isInoperative){if(i.isBox)return qs(e),void e.history.save();Rs(e),e.history.save()}}}))})),$t.plugin.add("backspaceKey",(e=>{e.readonly||e.keystroke.setKeydown("backspace",(t=>{const i=e.selection.range;if(i.isInsideBox){const n=Fe(i.commonAncestor.closest("lake-box")),s=n.value;return void(!i.isCollapsed||"codeBlock"!==n.name||void 0!==s.code&&""!==s.code||(t.preventDefault(),e.selection.removeBox(n),e.history.save()))}if(e.fixContent(),i.isBoxStart){const n=i.startNode.closest("lake-box"),s=n.prev();if(0===s.length){const i=n.closestBlock();return void(i.length>0&&!i.isContainer&&(t.preventDefault(),js(e,i),e.history.save()))}if(s.isBlock)return s.isEmpty?(t.preventDefault(),s.remove(),e.selection.fixList(),void e.history.save()):(t.preventDefault(),void i.shrinkAfter(s));if(s.isText&&1===s.text().length)return t.preventDefault(),s.remove(),void e.history.save();i.adjustBox()}if(i.isBox)return t.preventDefault(),e.selection.removeBox(),void e.history.save();if(!i.isCollapsed)return t.preventDefault(),e.selection.deleteContents(),""===e.container.html().trim()&&e.setValue("<p><br /><focus /></p>"),void e.history.save();i.adjust();const n=i.getPrevNode();if(n.isBox)return t.preventDefault(),e.selection.removeBox(n),void e.history.save();if((n.isMark||"a"===n.name)&&n.isEmpty)return t.preventDefault(),n.remove(),void e.history.save();if(n.isText&&1===n.text().length&&n.parent().isBlock){t.preventDefault();const s=n.closestBlock();if(i.setStartBefore(n),i.collapseToStart(),n.remove(),s.isEmpty){const e=D(s);i.setStartBefore(e),i.collapseToStart()}return void e.history.save()}const s=i.getNextNode();if("br"===n.name&&s.length>0)return t.preventDefault(),i.setStartBefore(n),i.collapseToStart(),n.remove(),void e.history.save();if(""===i.getStartText()){t.preventDefault();let n=i.getBlocks()[0];if(n||(e.selection.setBlocks("<p />"),n=i.getBlocks()[0]),""!==n.css("margin-left")||""!==n.css("text-indent")||""!==n.attr("indent"))return R(n,"decrease"),void e.history.save();if(n.isList||"blockquote"===n.name)return e.selection.setBlocks("<p />"),void e.history.save();js(e,n),e.history.save()}}))})),$t.plugin.add("deleteKey",(e=>{e.readonly||e.keystroke.setKeydown("delete",(t=>{const i=e.selection.range;if(i.isInsideBox)return;if(e.fixContent(),i.isBoxEnd){const n=i.startNode.closest("lake-box"),s=n.next();if(0===s.length){const i=n.closestBlock();return void(i.length>0&&!i.isContainer&&(t.preventDefault(),Ws(e,i),e.history.save()))}if(s.isBlock)return s.isEmpty?(t.preventDefault(),s.remove(),e.selection.fixList(),void e.history.save()):(t.preventDefault(),void i.shrinkBefore(s));i.adjustBox()}if(i.isBox)return t.preventDefault(),e.selection.removeBox(),void e.history.save();if(!i.isCollapsed)return t.preventDefault(),e.selection.deleteContents(),""===e.container.html().trim()&&e.setValue("<p><br /><focus /></p>"),void e.history.save();i.adjust();const n=i.getNextNode();if(n.isBox)return t.preventDefault(),e.selection.removeBox(n),void e.history.save();"br"===n.name&&n.next().length>0&&(t.preventDefault(),i.setStartBefore(n),i.collapseToStart(),n.remove(),e.history.save());if(""===i.getEndText()){t.preventDefault();let n=i.getBlocks()[0];n||(e.selection.setBlocks("<p />"),n=i.getBlocks()[0]),Ws(e,n),e.history.save()}}))})),$t.plugin.add("tabKey",(e=>{e.readonly||e.keystroke.setKeydown("tab",(t=>{if(!1===e.config.indentWithTab)return;const i=e.selection.range;if(i.isInsideBox)return;t.preventDefault();const n=i.getBlocks();for(const e of n)"p"!==e.name||"2em"===e.css("text-indent")?R(e,"increase"):e.css("text-indent","2em");e.history.save()}))})),$t.plugin.add("arrowKeys",(e=>{e.readonly||(e.keystroke.setKeydown("left",(t=>{const i=e.selection.range;if(i.isInsideBox)return;const n=i.commonAncestor.closest("lake-box");if(n.length>0){if(i.isBoxStart){const e=n.prev();return e.isBlock||e.isBox?(t.preventDefault(),e.isInlineBox?void i.selectBox(e):void i.shrinkAfter(e)):(i.setStartBefore(n),void i.collapseToStart())}return i.isBoxEnd?(t.preventDefault(),void i.selectBox(n)):(t.preventDefault(),void i.selectBoxStart(n))}if(!i.isCollapsed)return;const s=i.getPrevNode();s.isBox&&(t.preventDefault(),i.selectBox(s))})),e.keystroke.setKeydown("right",(t=>{const i=e.selection.range;if(i.isInsideBox)return;const n=i.commonAncestor.closest("lake-box");if(n.length>0){if(i.isBoxStart)return t.preventDefault(),void i.selectBox(n);if(i.isBoxEnd){const e=n.next();return e.isBlock||e.isBox?(t.preventDefault(),e.isInlineBox?void i.selectBox(e):void i.shrinkBefore(e)):(i.setStartAfter(n),void i.collapseToStart())}return t.preventDefault(),void i.selectBoxEnd(n)}if(!i.isCollapsed)return;const s=i.getNextNode();s.isBox&&(t.preventDefault(),i.selectBox(s))})),e.keystroke.setKeydown("up",(t=>{const i=e.selection.range;if(i.isInsideBox)return;const n=i.commonAncestor.closest("lake-box");if(n.length>0){if(n.isBlockBox){const e=n.prev();if(e.isBlock||e.isBox)return t.preventDefault(),void i.shrinkAfter(e)}i.setStartBefore(n),i.collapseToStart()}})),e.keystroke.setKeydown("down",(t=>{const i=e.selection.range;if(i.isInsideBox)return;const n=i.commonAncestor.closest("lake-box");if(n.length>0){if(n.isBlockBox){const e=n.next();if(e.isBlock||e.isBox)return t.preventDefault(),void i.shrinkBefore(e)}i.setStartAfter(n),i.collapseToStart()}})))})),$t.plugin.add("escapeKey",(e=>{e.readonly||e.keystroke.setKeydown("escape",(t=>{const i=e.selection,n=i.range;if(n.isBoxCenter||n.isInsideBox){t.preventDefault();const e=n.commonAncestor.closest("lake-box");return n.selectBoxEnd(e),void i.sync()}e.hasFocus&&(t.preventDefault(),e.blur())}))})),$t.plugin.add("slash",(e=>{if(e.setPluginConfig("slash",{items:Qs}),e.readonly)return;const t=new Xs({locale:e.locale,items:e.config.slash.items,onSelect:(i,n,s)=>{if(t&&t.hide(),e.focus(),function(e){const t=e.selection.range,i=t.commonAncestor.closestBlock();i.empty(),D(i),t.shrinkBefore(i)}(e),"upload"===n.type){if(!s)return;const t=i.target,o=s.get(0),r=t.files||[];for(const t of r)je({editor:e,name:n.name,file:t,onError:t=>{o.value="",e.config.onMessage("error",t)},onSuccess:()=>{o.value=""}})}else n.onClick(e,n.name)},onShow:()=>{e.popup=t},onHide:()=>{e.popup=null}}),i=()=>{const i=e.selection.range;if(!i.isCollapsed)return;const n=i.getBlocks()[0];if(!n)return;if(n.find("lake-box").length>0)return;const s=Ys(n);if(null===s)return;const o=i.clone();o.selectNodeContents(n),t.show(o,s)};return e.container.on("keyup",(n=>{if(e.isComposing)return;const s=n;if(Zt(["down","up","enter"],s))return;if(!t.visible){if(Zt("/",s))return void i();if(!Zt(["backspace","delete"],s))return;i()}const o=e.selection.range.getBlocks()[0];if(!o)return;const r=Ys(o);null!==r?t.update(r):t.hide()})),()=>{t.unmount()}})),e.Box=Ve,e.Button=be,e.Dropdown=He,e.Editor=$t,e.Fragment=Ue,e.HTMLParser=Xe,e.Nodes=T,e.Range=M,e.TextParser=Qe,e.Toolbar=class{constructor(e){this.placement="top",this.allMenuMap=new Map,this.buttonItemList=[],this.dropdownItemList=[],this.dropdownList=[],this.root=I(e.root),this.items=e.items||Gt,e.placement&&(this.placement=e.placement),this.container=I('<div class="lake-toolbar" />')}appendDivider(){this.container.append('<div class="lake-toolbar-divider" />')}appendNormalButton(e,t){new be({root:this.container,name:t.name,icon:t.icon,tooltip:"string"==typeof t.tooltip?t.tooltip:t.tooltip(e.locale),tabIndex:-1,onClick:()=>{e.focus(),t.onClick(e,t.name)}}).render()}appendDropdown(e,t){const i=new He({root:this.container,locale:e.locale,name:t.name,icon:t.icon,accentIcon:t.accentIcon,downIcon:t.downIcon,defaultValue:t.defaultValue,tooltip:t.tooltip,width:t.width,menuType:t.menuType,menuItems:t.menuItems,menuWidth:t.menuWidth,menuHeight:t.menuHeight,tabIndex:-1,location:"local",direction:"top"===this.placement?"bottom":"top",onSelect:i=>{e.focus(),t.onSelect(e,i)}});i.render(),this.dropdownList.push(i)}appendUploadButton(e,t){const i=I(a`
|
|
127
127
|
<div class="lake-upload" name="${t.name}">
|
|
128
128
|
<input type="file" />
|
|
129
129
|
</div>
|
|
130
|
-
`),n=i.find('input[type="file"]'),s=n.get(0);t.accept&&n.attr("accept",t.accept),!0===t.multiple&&n.attr("multiple","true");new be({root:i,name:t.name,icon:t.icon,tooltip:"string"==typeof t.tooltip?t.tooltip:t.tooltip(e.locale),tabIndex:-1,onClick:()=>{e.focus(),s.click()}}).render(),this.container.append(i),n.on("click",(e=>e.stopPropagation())),n.on("change",(i=>{const n=i.target.files||[];for(const i of n)je({editor:e,name:t.name,file:i,onError:t=>{s.value="",e.config.onMessage("error",t)},onSuccess:()=>{s.value=""}})}))}updateState(e){var t;const{appliedItems:i,disabledNameMap:n,selectedNameMap:s,selectedValuesMap:o}=e;for(const e of this.buttonItemList){const t="lake-button-selected",o=this.container.find(`button[name="${e.name}"]`);let r=n.get(e.name);if(void 0===r&&(r=!!(e.isDisabled&&i.length>0)&&e.isDisabled(i)),r?(o.attr("disabled","true"),o.removeClass(t)):o.removeAttr("disabled"),!r){let n=s.get(e.name);void 0===n&&(n=!!(e.isSelected&&i.length>0)&&e.isSelected(i)),n?o.addClass(t):o.removeClass(t)}}for(const e of this.dropdownItemList){let s=o.get(e.name);void 0===s&&(s=e.selectedValues&&i.length>0?e.selectedValues(i):[]);const r=this.container.find(`div.lake-dropdown[name="${e.name}"]`);let a=n.get(e.name);if(void 0===a&&(a=!!(e.isDisabled&&i.length>0)&&e.isDisabled(i)),a?r.attr("disabled","true"):r.removeAttr("disabled"),!a){He.setValue(r,s);const i=r.find(".lake-dropdown-text");if(i.length>0){const n=s[0]||e.defaultValue||"",o=this.allMenuMap.get(e.name),r=null!==(t=o&&o.get(n))&&void 0!==t?t:n;i.text(r)}}}}render(e){this.root.append(this.container);for(const t of this.items)if("|"===t)this.appendDivider();else{let i;if("string"==typeof t){if(i=Xt.get(t),!i)throw new Error(`ToolbarItem "${t}" has not been defined yet.`)}else i=t;"button"===i.type?(this.buttonItemList.push(i),this.appendNormalButton(e,i)):"dropdown"===i.type?(this.allMenuMap.set(i.name,He.getMenuMap(i.menuItems,e.locale)),this.dropdownItemList.push(i),this.appendDropdown(e,i)):"upload"===i.type&&this.appendUploadButton(e,i)}}unmount(){for(const e of this.dropdownList)e.unmount();this.
|
|
130
|
+
`),n=i.find('input[type="file"]'),s=n.get(0);t.accept&&n.attr("accept",t.accept),!0===t.multiple&&n.attr("multiple","true");new be({root:i,name:t.name,icon:t.icon,tooltip:"string"==typeof t.tooltip?t.tooltip:t.tooltip(e.locale),tabIndex:-1,onClick:()=>{e.focus(),s.click()}}).render(),this.container.append(i),n.on("click",(e=>e.stopPropagation())),n.on("change",(i=>{const n=i.target.files||[];for(const i of n)je({editor:e,name:t.name,file:i,onError:t=>{s.value="",e.config.onMessage("error",t)},onSuccess:()=>{s.value=""}})}))}updateState(e){var t;const{appliedItems:i,disabledNameMap:n,selectedNameMap:s,selectedValuesMap:o}=e;for(const e of this.buttonItemList){const t="lake-button-selected",o=this.container.find(`button[name="${e.name}"]`);let r=n.get(e.name);if(void 0===r&&(r=!!(e.isDisabled&&i.length>0)&&e.isDisabled(i)),r?(o.attr("disabled","true"),o.removeClass(t)):o.removeAttr("disabled"),!r){let n=s.get(e.name);void 0===n&&(n=!!(e.isSelected&&i.length>0)&&e.isSelected(i)),n?o.addClass(t):o.removeClass(t)}}for(const e of this.dropdownItemList){let s=o.get(e.name);void 0===s&&(s=e.selectedValues&&i.length>0?e.selectedValues(i):[]);const r=this.container.find(`div.lake-dropdown[name="${e.name}"]`);let a=n.get(e.name);if(void 0===a&&(a=!!(e.isDisabled&&i.length>0)&&e.isDisabled(i)),a?r.attr("disabled","true"):r.removeAttr("disabled"),!a){He.setValue(r,s);const i=r.find(".lake-dropdown-text");if(i.length>0){const n=s[0]||e.defaultValue||"",o=this.allMenuMap.get(e.name),r=null!==(t=o&&o.get(n))&&void 0!==t?t:n;i.text(r)}}}}render(e){this.root.append(this.container);for(const t of this.items)if("|"===t)this.appendDivider();else{let i;if("string"==typeof t){if(i=Xt.get(t),!i)throw new Error(`ToolbarItem "${t}" has not been defined yet.`)}else i=t;"button"===i.type?(this.buttonItemList.push(i),this.appendNormalButton(e,i)):"dropdown"===i.type?(this.allMenuMap.set(i.name,He.getMenuMap(i.menuItems,e.locale)),this.dropdownItemList.push(i),this.appendDropdown(e,i)):"upload"===i.type&&this.appendUploadButton(e,i)}}unmount(){for(const e of this.dropdownList)e.unmount();this.container.remove()}},e.Utils=We,e.addMark=ht,e.deleteContents=nt,e.fixList=it,e.icons=n,e.insertBookmark=Je,e.insertBox=gt,e.insertFragment=st,e.insertLink=mt,e.insertNode=Ye,e.removeBox=vt,e.removeMark=ut,e.setBlocks=ot,e.splitBlock=rt,e.splitMarks=ct,e.toBookmark=tt,e}({});
|
|
131
131
|
//# sourceMappingURL=lake.min.js.map
|