lakelib 0.3.11 → 0.4.0

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.min.js CHANGED
@@ -11,11 +11,11 @@ var Lake=function(e){"use strict";class t extends HTMLElement{}void 0!==customEl
11
11
  <li value="${C(i.value)}">
12
12
  <div class="lake-dropdown-menu-text">${s}</div>
13
13
  </li>
14
- `);if(e.append(o),o.on("mouseenter",(()=>{o.hasClass("lake-dropdown-item-selected")||o.addClass("lake-dropdown-item-hovered")})),o.on("mouseleave",(()=>{o.removeClass("lake-dropdown-item-hovered")})),"character"===t.menuType?(o.attr("title",s),o.find(".lake-dropdown-menu-text").text(i.value)):"color"===t.menuType&&(o.attr("title",s),o.find(".lake-dropdown-menu-text").css("background-color",i.value)),i.icon){const e=b('<div class="lake-dropdown-menu-icon"></div>');e.append(i.icon),o.prepend(e)}const r=n.get("check");if(r){const e=b('<div class="lake-dropdown-menu-check"></div>');e.append(r),o.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):b(document.body).append(t),t.on("click",(t=>{t.preventDefault(),t.stopPropagation();const s=b(t.target).closest("li");if(0===s.length)return;const o=s.attr("value");me.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=me.getValue(this.node);t.find(".lake-dropdown-menu-check").css("visibility","hidden"),!1!==e.menuCheck&&t.find("li").each((e=>{const t=b(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),me.setValue(this.node,[n]),r.length>0){const e=me.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.menuNode.remove(),this.node.remove()}}const ge=["undo","redo","|","heading","|","formatPainter","removeFormat","bold","moreStyle","|","fontColor","highlight","|","align","list","indent","link","blockQuote","hr"],fe=new Map;for(const e of W)fe.set(e.name,e);class ve{constructor(e){this.placement="top",this.allMenuMap=new Map,this.buttonItemList=[],this.dropdownItemList=[],this.dropdownList=[],this.root=b(e.root||document.body),this.items=e.items||ge,e.placement&&(this.placement=e.placement),this.container=b('<div class="lake-toolbar" />')}appendDivider(){this.container.append('<div class="lake-toolbar-divider" />')}appendNormalButton(e,t){new X({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 me({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,menuCheck:t.menuCheck,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=b(S`
14
+ `);if(e.append(o),o.on("mouseenter",(()=>{o.hasClass("lake-dropdown-item-selected")||o.addClass("lake-dropdown-item-hovered")})),o.on("mouseleave",(()=>{o.removeClass("lake-dropdown-item-hovered")})),"character"===t.menuType?(o.attr("title",s),o.find(".lake-dropdown-menu-text").text(i.value)):"color"===t.menuType&&(o.attr("title",s),o.find(".lake-dropdown-menu-text").css("background-color",i.value)),i.icon){const e=b('<div class="lake-dropdown-menu-icon"></div>');e.append(i.icon),o.prepend(e)}const r=n.get("check");if(r){const e=b('<div class="lake-dropdown-menu-check"></div>');e.append(r),o.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):b(document.body).append(t),t.on("click",(t=>{t.preventDefault(),t.stopPropagation();const s=b(t.target).closest("li");if(0===s.length)return;const o=s.attr("value");me.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","0"),e.css("right","auto")),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=me.getValue(this.node);t.find(".lake-dropdown-menu-check").css("visibility","hidden"),!1!==e.menuCheck&&t.find("li").each((e=>{const t=b(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),me.setValue(this.node,[n]),r.length>0){const e=me.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.menuNode.remove(),this.node.remove()}}const ge=["undo","redo","|","heading","|","formatPainter","removeFormat","bold","moreStyle","|","fontColor","highlight","|","align","list","indent","link","blockQuote","hr"],fe=new Map;for(const e of W)fe.set(e.name,e);class ve{constructor(e){this.placement="top",this.allMenuMap=new Map,this.buttonItemList=[],this.dropdownItemList=[],this.dropdownList=[],this.root=b(e.root||document.body),this.items=e.items||ge,e.placement&&(this.placement=e.placement),this.container=b('<div class="lake-toolbar" />')}appendDivision(e){this.container.append(`<div class="lake-toolbar-${e}" />`)}appendNormalButton(e,t){new X({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 me({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,menuCheck:t.menuCheck,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=b(S`
15
15
  <div class="lake-upload" name="${t.name}">
16
16
  <input type="file" />
17
17
  </div>
18
- `),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 X({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{requestTypes:n,requestMethod:o,requestAction:r,requestFieldName:a,requestWithCredentials:l,requestHeaders:c,transformResponse:d}=e.config[t.name],h=i.target.files||[];for(const i of h)K({selection:e.selection,boxName:t.name,file:i,requestTypes:n,requestMethod:o,requestAction:r,requestFieldName:a,requestWithCredentials:l,requestHeaders:c,transformResponse:d,onError:t=>{s.value="",e.config.onMessage("error",t)},onSuccess:()=>{s.value="",e.history.save()}})}))}updateState(e={activeItems:[]}){var t;const{activeItems:i}=e,n=e.disabledNameMap||new Map,s=e.selectedNameMap||new Map,o=e.selectedValuesMap||new Map;if(this.container.get(0).isConnected){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&&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&&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&&e.isDisabled(i)),a?r.attr("disabled","true"):r.removeAttr("disabled"),!a){me.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=fe.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,me.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()}}class we extends ve{constructor(e){if(super(e),this.scrollListener=()=>this.updatePosition(),this.resizeListener=()=>this.updatePosition(),e.target instanceof x){const t=new N;t.selectNodeContents(e.target),this.range=t}else this.range=e.target;this.container.removeClass("lake-toolbar"),this.container.addClass("lake-popup"),this.container.addClass("lake-floating-toolbar")}updatePosition(){const e=Z(this.range);if(-1===e.top&&-1===e.bottom||1===e.top&&1===e.bottom)return void this.container.css("visibility","hidden");this.container.css("visibility","");const t=this.range.get().getBoundingClientRect();this.container.show("flex");const i=t.x+window.scrollX,n=t.y+window.scrollY;let s=Number((i+t.width/2-this.container.width()/2).toFixed(1)),o=Number((n-this.container.height()-6).toFixed(1));const r=this.range.commonAncestor.closestScroller(),a=this.range.commonAncestor.closestContainer().get(0).getBoundingClientRect();let l=window.scrollX+6;r.length>0?l+=a.x+r.get(0).scrollLeft:l+=a.x+window.scrollX;const c=l+a.width-this.container.width()-12;let d=window.scrollY;r.length>0?d+=a.y+r.get(0).scrollTop+10:d+=a.y+window.scrollY,s<l?s=l:s>c&&(s=c),o<d&&(o=d),this.container.css({left:`${s}px`,top:`${o}px`})}render(){const e=this.range.commonAncestor.closest("div[contenteditable]"),t=e.length>0?P.get(e.id):void 0;if(!t)throw new Error("The range must be within the editing area.");super.render(t),this.updatePosition(),this.updateState();const i=this.range.commonAncestor.closestScroller();i.length>0?i.on("scroll",this.scrollListener):window.addEventListener("scroll",this.scrollListener),window.addEventListener("resize",this.resizeListener)}unmount(){super.unmount();const e=this.range.commonAncestor.closestScroller();e.length>0?e.off("scroll",this.scrollListener):window.removeEventListener("scroll",this.scrollListener),window.removeEventListener("resize",this.resizeListener)}}class ye{constructor(e){if(this.event=new I,this.toolbar=null,"string"==typeof e){const t=M.get(e);if(void 0===t)throw new Error(`Box "${e}" has not been defined yet.`);this.node=b(S`<lake-box type="${t.type}" name="${t.name}"></lake-box>`),t.value&&(this.value=t.value)}else{this.node=b(e);const t=M.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)}}initiate(){let e=this.getContainer();0===e.length?(this.node.html(S`
18
+ `),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 X({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{requestTypes:n,requestMethod:o,requestAction:r,requestFieldName:a,requestWithCredentials:l,requestHeaders:c,transformResponse:d}=e.config[t.name],h=i.target.files||[];for(const i of h)K({selection:e.selection,boxName:t.name,file:i,requestTypes:n,requestMethod:o,requestAction:r,requestFieldName:a,requestWithCredentials:l,requestHeaders:c,transformResponse:d,onError:t=>{s.value="",e.config.showMessage("error",t)},onSuccess:()=>{s.value="",e.history.save()}})}))}updateState(e={activeItems:[]}){var t;const{activeItems:i}=e,n=e.disabledNameMap||new Map,s=e.selectedNameMap||new Map,o=e.selectedValuesMap||new Map;if(this.container.get(0).isConnected){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&&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&&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&&e.isDisabled(i)),a?r.attr("disabled","true"):r.removeAttr("disabled"),!a){me.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.appendDivision("divider");else if("-"===t)this.appendDivision("line-break");else{let i;if("string"==typeof t){if(i=fe.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,me.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()}}class we extends ve{constructor(e){if(super(e),this.scrollListener=()=>this.updatePosition(),this.resizeListener=()=>this.updatePosition(),e.target instanceof x){const t=new N;t.selectNodeContents(e.target),this.range=t}else this.range=e.target;this.container.removeClass("lake-toolbar"),this.container.addClass("lake-popup"),this.container.addClass("lake-floating-toolbar")}updatePosition(){const e=Z(this.range);if(-1===e.top&&-1===e.bottom||1===e.top&&1===e.bottom)return void this.container.css("visibility","hidden");this.container.css("visibility","");const t=this.range.get().getBoundingClientRect();this.container.show("flex");const i=t.x+window.scrollX,n=t.y+window.scrollY;let s=Number((i+t.width/2-this.container.width()/2).toFixed(1)),o=Number((n-this.container.height()-6).toFixed(1));const r=this.range.commonAncestor.closestScroller(),a=this.range.commonAncestor.closestContainer().get(0).getBoundingClientRect();let l=window.scrollX+6;r.length>0?l+=a.x+r.get(0).scrollLeft:l+=a.x+window.scrollX;const c=l+a.width-this.container.width()-12;let d=window.scrollY;r.length>0?d+=a.y+r.get(0).scrollTop+10:d+=a.y+window.scrollY,s<l?s=l:s>c&&(s=c),o<d&&(o=d),this.container.css({left:`${s}px`,top:`${o}px`})}render(){const e=this.range.commonAncestor.closest("div[contenteditable]"),t=e.length>0?P.get(e.id):void 0;if(!t)throw new Error("The range must be within the editing area.");super.render(t),this.updatePosition(),this.updateState();const i=this.range.commonAncestor.closestScroller();i.length>0?i.on("scroll",this.scrollListener):window.addEventListener("scroll",this.scrollListener),window.addEventListener("resize",this.resizeListener)}unmount(){super.unmount();const e=this.range.commonAncestor.closestScroller();e.length>0?e.off("scroll",this.scrollListener):window.removeEventListener("scroll",this.scrollListener),window.removeEventListener("resize",this.resizeListener)}}class ye{constructor(e){if(this.event=new I,this.toolbar=null,"string"==typeof e){const t=M.get(e);if(void 0===t)throw new Error(`Box "${e}" has not been defined yet.`);this.node=b(S`<lake-box type="${t.type}" name="${t.name}"></lake-box>`),t.value&&(this.value=t.value)}else{this.node=b(e);const t=M.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)}}initiate(){let e=this.getContainer();0===e.length?(this.node.html(S`
19
19
  <span class="lake-box-strip"><br /></span>
20
20
  <div class="lake-box-container" contenteditable="false"></div>
21
21
  <span class="lake-box-strip"><br /></span>
@@ -37,7 +37,7 @@ var Lake=function(e){"use strict";class t extends HTMLElement{}void 0!==customEl
37
37
  <input type="text" name="url" placeholder="${e.urlPlaceholder}" />
38
38
  </div>
39
39
  </div>
40
- `),o=new X({root:n.find(".lake-input-field"),name:"embed",type:"primary",text:Ae(s,e.embedButtonText),onClick:()=>{const o=n.find('input[name="url"]').value();e.validUrl(o)?(t.updateValue("url",o),i.history.save(),n.remove(),_e(e,t)):i.config.onMessage("error",Ae(s,e.urlError))}});n.find('input[name="url"]').on("keydown",(e=>{Ce.isKeyHotkey("enter",e)&&(e.preventDefault(),o.node.emit("click"))})),o.render(),a.append(n)}else _e(e,t);i.readonly||function(e,t){const i=t.getEditor(),s=t.getContainer().find(".lake-iframe");s.find(".lake-corner-toolbar").length>0||new Se({locale:i.locale,root:s,items:[{name:"remove",icon:n.get("remove"),tooltip:e.deleteButtonText,onClick:e=>{e.stopPropagation(),i.selection.removeBox(t),i.history.save()}}]}).render()}(e,t)}}}class Te{constructor(e){this.fragment=null!=e?e:document.createDocumentFragment()}get(){return this.fragment}find(e){const t=[];let i=new x(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 x(t)}append(e){b(e).each((e=>{this.fragment.appendChild(e)}))}}function Ee(e){e=e.replace(/&quot;/gi,'"');const t={},i=/\s*([\w-]+)\s*:([^;]*)(?:;|$)/g;let n;for(;null!==(n=i.exec(e));){const e=n[1].toLowerCase().trim(),i=f(n[2]).trim();t[e]=i}return t}class Ie{constructor(e,t=o()){this.rules=t,this.source="string"==typeof e?this.parseHTML(e):e}parseHTML(e){const t=(new DOMParser).parseFromString(e,"text/html");return new x(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&&Ie.matchRule(n[e.name],e.value)&&o.set(e.name,e.value),"style"===e.name)){const t=n.style,i=new Map,s=Ee(e.value);for(const e of Object.keys(s)){const n=s[e];t[e]&&Ie.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,"&quot;")}; `;""!==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 C(Ie.getTrimmedText(n));else if(n.isVoid){const t=Ie.getOpenTagString(n,e);""!==t&&(yield`<${t} />`)}else if(n.isElement){const i=Ie.getOpenTagString(n,e),s=Ie.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 Me{constructor(e){this.content=e}getHTML(){let e=this.content;return e=e.replace(/ {2}/g,"  "),e=C(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 Ie(this.getHTML()).getFragment()}}function Pe(e,t){const i=e.get(),n=t.get(0);i.insertNode(n),i.setEndAfter(n),i.collapse(!1)}function He(e){if(e.commonAncestor.isOutside)return{anchor:new x,focus:new x};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 x,focus:t};if(e.isCollapsed){const t=e.clone();t.collapseToEnd();const i=b('<lake-bookmark type="focus" />');return Pe(t,i),{anchor:new x,focus:i}}const i=e.clone();i.collapseToStart();const n=b('<lake-bookmark type="anchor" />');Pe(i,n);const s=e.clone();s.collapseToEnd();const o=b('<lake-bookmark type="focus" />');return Pe(s,o),{anchor:n,focus:o}}function De(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 x(document.createTextNode("​"));e.before(i),t.setStartAfter(i),t.collapseToStart()}e.remove()}else e.remove()}function Ze(e,t){const i=t.anchor,n=t.focus;if(i.length>0&&0===n.length)De(i);else{if(n.length>0&&0===i.length){if(n.isBox){const t=xe(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 De(n,e)}if(i.length>0&&n.length>0){const t=new N;t.selectNode(i),t.collapseToEnd(),-1===t.compareAfterNode(n)?(e.setStartBefore(n),De(n),e.setEndBefore(i),De(i)):(e.setStartBefore(i),De(i),e.setEndBefore(n),De(n))}}}function Ne(e){if(0===e.length)return;const t=[];let i=e.first();for(;i.length>0;){const e=i.next();i.isText&&""===i.text()||t.push(i),i=e}(1===t.length&&"br"===t[0].name||2===t.length&&"br"===t[0].name&&t[1].isBookmark)&&t[0].remove(),2===t.length&&t[0].isBookmark&&"br"===t[1].name&&t[1].remove()}function ze(e){const t=b("<br />");let i=e;for(;i.isBlock;){let e=i.last();for(;e.isText&&e.isEmpty;)e=e.prev();if(!e.isBlock&&"br"!==e.name){i.append(t);break}i=e}return t}function Oe(e){if(e.isText)return{node:e,offset:e.text().length};const t=new N;return t.setEndAfter(e),{node:t.endNode,offset:t.endOffset}}function $e(e,t){const i=t;if(["ul","ol"].indexOf(e.name)>=0){const t=e.find("li");e=t.eq(t.length-1)}if(["ul","ol"].indexOf(t.name)>=0){const e=t.find("li");t=e.eq(0)}if(e.isText||t.isText||e.isVoid||t.isVoid)return Oe(e);Ne(e),Ne(t),e.isBlock&&e.isEmpty&&t.isEmpty&&ze(e);const n=e.last(),s=t.first();let o=s;for(;o.length>0;){const t=o.next();e.append(o),o=t}return i.remove(),n.length>0&&s.length>0&&n.isElement&&!n.isBox&&n.clone(!1).get(0).isEqualNode(s.clone(!1).get(0))?$e(n,s):0===n.length?{node:e,offset:0}:Oe(n)}function Ve(e){if(0===e.length)return;const t=e[0],i=e[e.length-1],n=[];let s=t.prev();for(;s.length>0&&"ol"===s.name;)n.push(s),s=s.prev();n.reverse(),n.push(...e);let o=i.next();for(;o.length>0&&"ol"===o.name;)n.push(o),o=o.next();let r=1;for(const e of n){const t=e.prev();if(0!==t.length&&"ol"===t.name||(r=1),"ol"===e.name){"ol"===t.name&&t.attr("indent")!==e.attr("indent")&&(r=1);const i=e.attr("start"),n=r.toString(10);i!==n&&e.attr("start",n),r++}}}function Re(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=ze(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=He(e);$e(o,s),Ve([o]),Ze(e,r)}function Fe(e,t){if(e.commonAncestor.isOutside)return;let i;t instanceof Te?i=t:t instanceof DocumentFragment?i=new Te(t):(i=new Te,i.append(t)),e.isCollapsed?e.adjustBox():Re(e);Ne(e.startNode.closestBlock());const n=e.get();n.insertNode(i.get()),n.collapse(!1),e.adjustBlock()}function qe(e){let t=e;for(;t.length>0;){let e=t.first();if(e.isText&&e.isEmpty&&(e=e.next()),t.isElement&&!t.isVoid&&0===e.length)break;t=e}return t}function We(e,t){if(t=null!=t?t:b("<p />"),0===e.length)return t;const i=qe(t=t.clone(!0));e[0].before(t);for(const t of e)i.append(t);return t}function je(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=b(t),n=i.name,s=i.get(0).attributes,o=e.getBlocks();if(o.length>0){const t=He(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=qe(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 Ze(e,t),void Ve(e.getBlocks())}if(e.isCollapsed){const t=e.getNextNode();if("br"===t.name){const i=b("<p><br /></p>");return t.replaceWith(i),void e.shrinkBefore(i)}const i=e.getPrevNode();if("br"===i.name){const t=b("<p><br /></p>");return i.replaceWith(t),void e.shrinkBefore(t)}}const r=He(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=We(a,i);if(Ze(e,r),Ve(e.getBlocks()),l.isEmpty){const t=ze(l);e.setStartBefore(t),e.collapseToStart()}}function Ue(e,t,i){const n=new N;let s;if(e.isText){s=e.parent();const i=e.splitText(t);n.setStartAfter(e),""===e.text()&&e.remove(),""===i.text()&&i.remove()}else n.setStart(e,t),s=e;if("body"===s.name||"html"===s.name)return null;if(s.get(0)===i.get(0))return null;n.collapseToStart();const o=s.clone();let r=s.first();for(;r.length>0&&!(n.compareBeforeNode(r)>=0);){const e=r.next();o.append(r),r=e}return s.before(o),s.parent().length>0&&s.parent().get(0)!==i.get(0)?Ue(s.parent(),s.index(),i):{start:o,end:s}}function Ke(e){if(e.isMark&&e.isEmpty)e.remove();else for(const t of e.getWalker())t.isMark&&t.isEmpty&&t.remove()}function Xe(e){if(e.commonAncestor.isOutside)return{start:null,end:null};e.isCollapsed?e.adjustBox():Re(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=Ue(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&&(Ke(o),ze(o)),r&&(r.isEmpty&&(Ke(r),ze(r)),e.shrinkBefore(r)),Ve(e.getBlocks()),{start:o,end:r}}function Ge(e,t){if(e.commonAncestor.isOutside)return null;const i=b(t),n=Xe(e);return n.start&&(Ke(n.start),e.setEndAfter(n.start),e.collapseToEnd()),n.end&&(Ke(n.end),n.end.isEmpty&&n.end.remove()),Fe(e,i),i.isBox||e.shrinkAfter(i),n.start&&n.start.isEmpty&&n.start.remove(),i}function Ye(e,t,i){let n=null,s=null,o=e.closestBlock();0===o.length&&(o=e.closestContainer());const r=Ue(e,t,o);return r&&(i?(Ke(r.start),Ke(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 Qe(e,t=!0){if(e.commonAncestor.isOutside)return{start:null,center:null,end:null};if(e.adjustBox(),e.isCollapsed){const i=Ye(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=Ye(e.startNode,e.startOffset,t);i.start?e.setStartAfter(i.start):i.end&&e.setStartBefore(i.end);const n=Ye(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 Je(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 et(e,t){if(e.commonAncestor.isOutside)return;let i=b(t);const n=i.name,s=Ee(i.attr("style"));if(e.isCollapsed){if(e.isBox){const t=e.startNode.closest("lake-box");if("block"===xe(t).type){const i=b("<p><br /></p>");e.isBoxStart?t.before(i):t.after(i),e.shrinkAfter(i)}else e.adjustBox()}Ne(e.startNode.closestBlock());const t=new x(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(Qe(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()){qe(i).append(t)}return Fe(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)}Qe(e);const o=e.getMarks(!0),r=He(e);for(const e of o)if(!e.isEmpty&&e.isText){const t=Je(e,n);if(t.isMark&&t.name===n)t.css(s);else{const e=i.clone();t.before(e),e.append(t)}}Ze(e,r)}function tt(e,t){if(e.commonAncestor.isOutside)return;let i;if(t){i=b(t).name}if(e.isCollapsed){if(e.isBox)return;if(i&&0===e.commonAncestor.closest(i).length)return;const t=Qe(e,!1);if(!t.start)return;t.end&&Ke(t.end);const n=new x(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),Ke(t.start),n.prev().isText?(e.setStartAfter(n.prev()),e.collapseToStart(),void n.remove()):(e.setStartAfter(n),void e.collapseToStart());return qe(s).append(n),t.start.after(s),Ke(t.start),void e.shrinkAfter(s)}Qe(e);const n=e.getMarks(),s=He(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()}!function(e){for(const t of e.getWalker())if(t.isText){const e=t.text();""===e?t.remove():e.length>1&&/\u200B/.test(e)&&(t.get(0).nodeValue=e.replace(/\u200B/g,""))}}(e.commonAncestor),Ze(e,s)}function it(e,t,i){if(e.commonAncestor.isOutside)return null;const n=xe(t);if(i&&(n.value=i),"inline"===n.type){if(Qe(e),Fe(e,n.node),n.render(),n.node.isTopInside){const e=b("<p />");n.node.before(e),e.append(n.node)}return e.selectBoxEnd(n.node),xe(n.node)}return Ge(e,n.node),n.render(),e.selectBoxEnd(n.node),xe(n.node)}function nt(e){const t=e.node.closestContainer();if(e.unmount(),e.node.remove(),t.length>0){A(t.id).delete(e.node.id);A(0).set(e.node.id,e)}return e}function st(e){if(e.commonAncestor.isOutside)return null;const t=e.commonAncestor.closest("lake-box");if(0===t.length)return null;const i=xe(t);if("block"===i.type){const n=b("<p><br /></p>");return t.before(n),e.shrinkAfter(n),nt(i)}e.setStartBefore(t),e.collapseToStart();const n=t.parent();if(nt(i),n.isEmpty){const t=ze(n);e.setStartBefore(t),e.collapseToStart()}return i}var ot,rt={exports:{}};function at(){if(ot)return rt.exports;function e(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 Object.defineProperty(h,"isPending",{get:()=>void 0!==r}),h.clear=()=>{r&&(clearTimeout(r),r=void 0)},h.flush=()=>{r&&h.trigger()},h.trigger=()=>{l=c(),h.clear()},h}return ot=1,rt.exports.debounce=e,rt.exports=e,rt.exports}var lt,ct,dt=_(at());var ht=_(ct?lt:(ct=1,lt=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 pt(e){return e.replace(/(<lake-box[^>]+>)[\s\S]*?(<\/lake-box>)/gi,"$1$2").replace(/<lake-bookmark\s+type="anchor">\s*<\/lake-bookmark>/gi,"<anchor />").replace(/<lake-bookmark\s+type="focus">\s*<\/lake-bookmark>/gi,"<focus />")}function ut(e){return e.replace(/(<lake-box[^>]+>)[\s\S]*?(<\/lake-box>|$)/gi,"$1</lake-box>").replace(/<anchor\s*\/>/gi,'<lake-bookmark type="anchor"></lake-bookmark>').replace(/<focus\s*\/>/gi,'<lake-bookmark type="focus"></lake-bookmark>')}function mt(e){const t=e.get(0),i={};if(t.hasAttributes())for(const e of t.attributes)i[e.name]=e.value;return i}class gt{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 N(e)}return new N}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 Ze(e,{anchor:new x,focus:i}),void this.sync();Ze(e,{anchor:t.find('lake-bookmark[type="anchor"]'),focus:t.find('lake-bookmark[type="focus"]')}),this.sync()}getActiveItems(){const e=[];return function(e,t){let i=t.startNode;for(i.isText&&(i=i.parent());i.length>0&&i.isContentEditable&&!i.isContainer;)e.push({node:i,name:i.name,attributes:mt(i),styles:Ee(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:mt(t),styles:Ee(t.attr("style"))}),t=t.first()}}(e,this.range),e}insertBookmark(){return He(this.range)}toBookmark(e){return Ze(this.range,e)}insertContents(e){return Fe(this.range,e)}deleteContents(){return Re(this.range)}setBlocks(e){return je(this.range,e)}splitBlock(){return Xe(this.range)}insertBlock(e){return Ge(this.range,e)}splitMarks(e){return Qe(this.range,e)}addMark(e){return et(this.range,e)}removeMark(e){return tt(this.range,e)}selectBox(e){let t=e;t=e instanceof ye?e.node:e,this.range.selectBox(t),this.sync()}insertBox(e,t){const i=it(this.range,e,t);if(!i)throw new Error(`Box "${e}" cannot be inserted into the outside of the editor.`);return i}removeBox(e=null){return e&&this.selectBox(e),st(this.range)}}class ft{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.getActiveItems();return t.isDisabled(i)}isSelected(e){const t=this.getItem(e);if(!t.isSelected)return!1;const i=this.selection.getActiveItems();return t.isSelected(i)}selectedValues(e){const t=this.getItem(e);if(!t.selectedValues)return[];const i=this.selection.getActiveItems();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),v(`Command "${e}" executed`)}}const vt=new Set;function wt(){}const yt={morphStyle:"outerHTML",callbacks:{beforeNodeAdded:wt,afterNodeAdded:wt,beforeNodeMorphed:wt,afterNodeMorphed:wt,beforeNodeRemoved:wt,afterNodeRemoved:wt,beforeAttributeUpdated:wt,afterAttributeUpdated:wt,beforeChildrenUpdated:wt},head:{style:"merge",shouldPreserve:e=>"true"===e.getAttribute("im-preserve"),shouldReAppend:e=>"true"===e.getAttribute("im-re-append"),shouldRemove:wt,afterHeadMorphed:wt}};function xt(e,t){return!e.deadIds.has(t)}function bt(e,t,i){return(e.idMap.get(i)||vt).has(t)}function kt(e,t){const i=e.idMap.get(t)||vt;for(const t of i)e.deadIds.add(t)}function Ct(e,t,i){const n=e.idMap.get(t)||vt;let s=0;for(const t of n)xt(e,t)&&bt(e,t,i)&&++s;return s}function St(e,t){const i=e.parentElement,n=e.querySelectorAll("[id]");for(const e of n){let n=e;for(;n!==i&&null!=n;){let i=t.get(n);null==i&&(i=new Set,t.set(n,i)),i.add(e.id),n=n.parentElement}}}function Bt(e,t){const i=new Map;return St(e,i),St(t,i),i}function At(e,t,i){return{target:e,newContent:t,config:i=function(e){const t={};return Object.assign(t,yt),Object.assign(t,e),t.callbacks={},Object.assign(t.callbacks,yt.callbacks),Object.assign(t.callbacks,e.callbacks),t.head={},Object.assign(t.head,yt.head),Object.assign(t.head,e.head),t}(i),morphStyle:i.morphStyle,ignoreActive:i.ignoreActive,ignoreActiveValue:i.ignoreActiveValue,idMap:Bt(e,t),deadIds:new Set,callbacks:i.callbacks,head:i.head}}function _t(e,t,i){return null!=e&&null!=t&&(e.nodeType===t.nodeType&&e.tagName===t.tagName&&(""!==e.id&&e.id===t.id||Ct(i,e,t)>0))}function Lt(e,t){return null!=e&&null!=t&&(e.nodeType===t.nodeType&&e.tagName===t.tagName)}function Tt(e,t){kt(t,e),!1!==t.callbacks.beforeNodeRemoved(e)&&(e.remove(),t.callbacks.afterNodeRemoved(e))}function Et(e,t,i){let n=e;for(;n&&n!==t;){const e=n;n=n.nextSibling,Tt(e,i)}return kt(i,t),t.nextSibling}function It(e,t,i,n,s){const o=Ct(s,i,t);let r=null;if(o>0){r=n;let t=0;for(;null!=r;){if(_t(i,r,s))return r;if(t+=Ct(s,r,e),t>o)return null;r=r.nextSibling}}return r}function Mt(e,t,i,n,s){let o=n,r=i.nextSibling,a=0;for(;null!=o;){if(Ct(s,o,e)>0)return null;if(Lt(i,o))return o;if(Lt(r,o)&&(a++,r=r?r.nextSibling:null,a>=2))return null;o=o?o.nextSibling:null}return o}function Pt(e,t,i){return Lt(e,t)?.5+Ct(i,e,t):0}function Ht(e,t,i,n){return!("value"!==e||!n.ignoreActiveValue||t!==document.activeElement)||!1===n.callbacks.beforeAttributeUpdated(e,t,i)}function Dt(e,t,i){var n;if(!i.ignoreActive||e!==document.activeElement)return null==t?!1===i.callbacks.beforeNodeRemoved(e)?e:(e.remove(),i.callbacks.afterNodeRemoved(e),null):Lt(e,t)?(!1===i.callbacks.beforeNodeMorphed(e,t)||(function(e,t,i){const n=e.nodeType;if(1===n){const n=e.attributes,s=t.attributes;for(const e of n)Ht(e.name,t,"update",i)||t.getAttribute(e.name)!==e.value&&(t.setAttribute(e.name,e.value),i.callbacks.afterAttributeUpdated(e.name,t,"update"));for(let n=s.length-1;n>=0;n--){const o=s[n];Ht(o.name,t,"remove",i)||e.hasAttribute(o.name)||(t.removeAttribute(o.name),i.callbacks.afterAttributeUpdated(o.name,t,"remove"))}}8!==n&&3!==n||t.nodeValue!==e.nodeValue&&(t.nodeValue=e.nodeValue)}(t,e,i),!1===i.callbacks.beforeChildrenUpdated(e,t)||function(e,t){return t.ignoreActiveValue&&e===document.activeElement}(e,i)||Zt(t,e,i),i.callbacks.afterNodeMorphed(e,t)),e):!1===i.callbacks.beforeNodeRemoved(e)||!1===i.callbacks.beforeNodeAdded(t)?e:(null===(n=e.parentElement)||void 0===n||n.replaceChild(t,e),i.callbacks.afterNodeAdded(t),i.callbacks.afterNodeRemoved(e),t)}function Zt(e,t,i){let n,s=e.firstChild,o=t.firstChild;for(;s;){if(n=s,s=n.nextSibling,null==o){if(!1===i.callbacks.beforeNodeAdded(n))return;t.appendChild(n),i.callbacks.afterNodeAdded(n),kt(i,n);continue}if(_t(n,o,i)){Dt(o,n,i),o=o.nextSibling,kt(i,n);continue}const r=It(e,t,n,o,i);if(r){o=Et(o,r,i),Dt(r,n,i),kt(i,n);continue}const a=Mt(e,0,n,o,i);if(a)o=Et(o,a,i),Dt(a,n,i),kt(i,n);else{if(!1===i.callbacks.beforeNodeAdded(n))return;t.insertBefore(n,o),i.callbacks.afterNodeAdded(n),kt(i,n)}}for(;null!==o;){const e=o;o=o.nextSibling,Tt(e,i)}}function Nt(e,t,i){if("innerHTML"===i.morphStyle)return Zt(t,e,i),e.children;const n=function(e,t,i){let n;n=e.firstChild;let s=n,o=0;for(;n;){const e=Pt(n,t,i);e>o&&(s=n,o=e),n=n.nextSibling}return s}(t,e,i),s=null==n?void 0:n.previousSibling,o=null==n?void 0:n.nextSibling,r=Dt(e,n,i);return n?function(e,t,i){var n,s;const o=[],r=[];let a=e;for(;null!=a;)o.push(a),a=a.previousSibling;for(;o.length>0;){const e=o.pop();r.push(e),e&&(null===(n=t.parentElement)||void 0===n||n.insertBefore(e,t))}r.push(t);let l=i;for(;null!=l;)o.push(l),r.push(l),l=l.nextSibling;for(;o.length>0;){const e=o.pop();e&&(null===(s=t.parentElement)||void 0===s||s.insertBefore(e,t.nextSibling))}return r}(s,r,o):[]}function zt(e,t,i={}){const n=function(e){if(null==e)return document.createElement("div");if(e instanceof Node){if(e.generatedByIdiomorph)return e;const t=document.createElement("div");return t.append(e),t}const t=document.createElement("div");for(const i of[...e])t.append(i);return t}(t.get(0)),s=At(e.get(0),n,i);Nt(e.get(0),n,s)}class Ot{constructor(e){this.canSave=!0,this.list=[],this.index=0,this.limit=100,this.contentRules=o(),this.event=new I,this.selection=e,this.container=e.container}removeBookmark(e){return e.replace(/(<lake-box[^>]+)\sfocus="\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 Ie(e,this.contentRules).getHTML()}addIdToBoxes(e){e.find("lake-box").each((e=>{const t=new x(e),i=`${t.attr("name")}-${t.attr("value")}`;t.attr("id",i)}))}removeIdfromBoxes(e){e.find("lake-box").each((e=>{new x(e).removeAttr("id")}))}morphContainer(e){const t=this.container,i={beforeChildrenUpdated:e=>{if("lake-box"===new x(e).name)return!1},afterAttributeUpdated:(e,i)=>{const n=new x(i);if(["name","value"].indexOf(e)>=0&&"lake-box"===n.name){xe(n).unmount();A(t.id).delete(n.id)}}},n=e.clone(!0);this.addIdToBoxes(t),this.addIdToBoxes(n),zt(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=>{xe(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),He(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),He(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(),v(`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(),v(`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),v(`History saved (index: ${this.index}, inputType: "${s}", update: ${o}, emitEvent: ${r})`),r&&this.event.emit("save",pt(l),{inputType:s,update:o,emitEvent:r}))}}class $t{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(Ce.isKeyHotkey(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(Ce.isKeyHotkey(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 Vt={value:"<p><br /></p>",readonly:!1,spellcheck:!1,tabIndex:0,placeholder:"",indentWithTab:!0,lang:"en-US",contentRules:o(),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 Rt{constructor(e){if(this.unsavedInputData="",this.unsavedInputCount=0,this.state={activeItems:[],disabledNameMap:new Map,selectedNameMap:new Map,selectedValuesMap:new Map},this.unmountPluginMap=new Map,this.event=new I,this.isComposing=!1,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 x(e.target);t.get(0).isConnected&&this.event.emit("click",t)},this.updateSelectionRange=dt((()=>{this.selection.updateByRange()}),1,{immediate:!0}),this.updateBoxSelectionStyle=dt((()=>{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=xe(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=dt((()=>{const e=this.getState();ht(e,this.state)||(this.toolbar&&this.toolbar.updateState(e),this.event.emit("statechange",e),this.state=e)}),50,{immediate:!1}),!e.root)throw new Error("The root of the config must be specified.");this.root=b(e.root),this.toolbar=e.toolbar,this.config=Object.assign({},Vt);for(const t of Object.keys(e))this.config[t]=e[t];this.containerWrapper=b('<div class="lake-container-wrapper" />'),this.container=b('<div class="lake-container" />'),this.overlayContainer=b('<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(),readonly:this.readonly?"true":"false"}),""!==this.config.placeholder&&this.container.attr("placeholder",this.config.placeholder),this.selection=new gt(this.container),this.command=new ft(this.selection),this.history=new Ot(this.selection),this.history.limit=this.config.historySize,this.history.contentRules=this.config.contentRules,this.keystroke=new $t(this.container),P.set(this.container.id,this)}togglePlaceholderClass(e){const t="lake-placeholder";"<p><br /></p>"===(e=pt(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"===xe(n).type)t.isBoxStart?(t.setStartBefore(n),t.collapseToStart()):(t.setStartAfter(n),t.collapseToStart());else{const e=b("<p />");t.isBoxStart?n.before(e):n.after(e),t.setStart(e,0),t.collapseToStart()}const s=i.text();i.html("<br />"),e.insertContents(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)}))}removeBoxGarbage(){const e=A(this.container.id);for(const t of e.values())t.node.get(0).isConnected||(t.unmount(),e.delete(t.node.id))}bindHistoryEvents(){const e=e=>{this.fixContent()&&(this.history.save({update:!0,emitEvent:!1}),e=this.getValue()),this.emitStateChangeEvent(),this.togglePlaceholderClass(e),this.scrollToCursor(),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())}))}bindPointerEvents(){this.container.on("pointerdown",(e=>{const t=e;if(null!==t.target&&t.target!==this.container.get(0))return;const i=this.container.last();if(i.isTable||i.isBlockBox){const e=i.get(0).getBoundingClientRect();if(t.clientY>e.bottom){t.preventDefault();const e=b("<p><br /></p>");i.after(e),this.selection.range.shrinkBefore(e),this.selection.sync()}}}))}get locale(){return ue(this.config.lang)}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])}fixContent(){const e=this.selection.range,t=e.commonAncestor.closest("td"),i=t.length>0?t:this.container;let n=!1,s=i.children();for(const e of s)(e.isBlock||e.isMark)&&""===e.html()&&(e.remove(),n=!0,v(`Content fixed: empty tag "${e.name}" was removed`));if(s=i.children(),0===s.length)i.html("<p><br /></p>"),e.shrinkBefore(i),n=!0,v("Content fixed: default paragraph was added");else if(1===s.length){const t=s[0];if(t.isVoid){const i=b("<p />");t.before(i),i.append(t),e.shrinkAfter(i),n=!0,v(`Content fixed: void element "${t.name}" was wrapped in paragraph`)}}return e.adjustBr(),n}renderBoxes(){this.removeBoxGarbage();const e=this.container,t=A(e.id);e.find("lake-box").each((e=>{const i=b(e);if(t.get(i.id))return;xe(i).render()}))}scrollToCursor(){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=b('<div class="lake-artificial-cursor" />'),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-cursor").remove(),this.overlayContainer.append(n),function(e,t){const i=Z(e);0===i.left&&0===i.right&&0===i.top&&0===i.bottom||e.get(0).scrollIntoView(t)}(n,{behavior:"instant",block:"nearest",inline:"nearest"}),n.remove()}hasFocus(){const e=document.activeElement;return!!e&&b(e).closest(".lake-container").get(0)===this.container.get(0)}focus(){const e=this.selection.range;this.container.contains(e.commonAncestor)&&e.isBox||this.container.focus()}blur(){this.container.blur()}getState(){const e=this.command.getNames();let t=this.selection.getActiveItems();t.length>0&&!this.container.contains(t[0].node)&&(t=[]);const i=new Map,n=new Map,s=new Map;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),t.length>0&&e.selectedValues){const i=e.selectedValues(t);i.length>0&&s.set(o,i)}}return{activeItems:t,disabledNameMap:i,selectedNameMap:n,selectedValuesMap:s}}setValue(e){e=ut(e);const t=new Ie(e,this.config.contentRules),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 Ie(e,this.config.contentRules).getHTML();return t=pt(t),t}render(){const e=ut(this.config.value),t=new Ie(e,this.config.contentRules),i=t.getFragment();if(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=Rt.plugin.loadAll(this),this.readonly||(this.selection.updateByBookmark(),this.history.save({emitEvent:!1})),this.renderBoxes(),this.toolbar){this.toolbar.render(this);const e=this.getState();this.toolbar.updateState(e)}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(),this.bindPointerEvents())}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(),v(`Plugin "${e}" unmounted`))}this.toolbar&&this.toolbar.unmount(),this.removeBoxGarbage(),this.container.find("lake-box").each((e=>{xe(b(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))}}Rt.version="0.3.11",Rt.box=new class{add(e){M.set(e.name,e)}remove(e){M.delete(e)}getNames(){return Array.from(M.keys())}},Rt.plugin=new class{constructor(){this.pluginMap=new Map}add(e,t){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}};function Ft(e,t){const i=e.get(0),n=b(S`<${t} />`);for(const e of i.attributes)n.attr(e.name,e.value);let s=e.first();for(;s.length>0;){const e=s.next();n.append(s),s=e}return e.replaceWith(n),n}const qt=Array.from(a).join(",");function Wt(e){const t=[e];for(const i of e.getWalker())t.push(i);for(const e of t)"div"===e.name?e.find(qt).length>0?e.remove(!0):Ft(e,"p"):(e.isHeading||["blockquote","li"].indexOf(e.name)>=0)&&e.find(qt).remove(!0)}function jt(e,t){const i=e.selection,n=i.range;if(0===t.childNodes.length)return;const s=new x(t.firstChild);let o=new x(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"===xe(n).type)i.isBoxStart?(i.setStartBefore(n),i.collapseToStart()):i.isBoxEnd?(i.setStartAfter(n),i.collapseToStart()):e.selection.removeBox();else{const t=b("<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=xe(t),n=""!==t.attr("value")?i.value:void 0;return e.selection.insertBox(i.name,n),void t.remove()}if(t.first().length>0&&Ne(s),s.isEmpty&&"p"===s.name)return s.replaceWith(t),t.find("lake-box").each((e=>{xe(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.insertContents(o),o.isBox?xe(o).render():o.isElement&&o.find("lake-box").each((e=>{xe(e).render()})),o=t}t.remove()}(e,s);let r=new x(t.firstChild);for(;r.length>0;){const e=r.next();"br"===r.name&&r.remove(),r=e}if(o=new x(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.insertContents(t),e.renderBoxes(),n.shrinkAfter(o)}Ve(e.container.children().filter((e=>e.isBlock))),e.history.save()}const Ut=["info","tip","warning","danger"];function Kt(e){e.selection.setBlocks("<p />")}function Xt(e){e.selection.setBlocks("<ol><li></li></ol>")}function Gt(e){e.selection.setBlocks("<ul><li></li></ul>")}function Yt(e,t){e.selection.setBlocks(`<ul type="checklist"><li value="${t}"></li></ul>`)}function Qt(e){const t=e.startNode.closest("table"),i=b("<p><br /></p>");t.replaceWith(i),e.shrinkBefore(i),v(`deleteTable: table ${t.id}`)}function Jt(e){const t=[];for(let i=0;i<e.rows.length;i++)t[i]=[];for(let i=0;i<t.length;i++){const n=e.rows[i],s=t[i];let o=0;for(let e=0;e<n.cells.length;e++){for(o=e;s[o];)o++;const r=n.cells[e];for(let e=0;e<r.colSpan;e++)for(let n=0;n<r.rowSpan;n++){const s=t[i+n];s&&(s[o+e]=r)}}}return t}function ei(e,t,i){const n=e[t];for(let e=0;e<n.length;e++){if(n[e]===i)return e}return-1}function ti(e,t,i){const n=e[t],s=e[t-1];let o=i;for(let e=0;e<i;e++){const t=n[e];if(t===n[e+1])o--;else if(s){t===s[e]&&o--}}return o}function ii(e,t){const i=e.startNode.closest("td"),n=i.closest("table"),s=i.closest("tr"),o=n.get(0),r=s.get(0),a=i.get(0),l=r.rowIndex,c=Jt(o);let d=ei(c,l,a);if("right"===t){const e=c[l];if(d++,e)for(;a===e[d];)d++}v(`insertColumn: rows ${o.rows.length}, column ${d}, ${t}`);for(let e=0;e<o.rows.length;e++){const t=o.rows[e],i=c[e],n=ti(c,e,d),s=t.cells[n];if(s&&s.colSpan>1&&s===i[d-1])s.colSpan+=1,s.rowSpan>1&&(e+=s.rowSpan-1);else{t.insertCell(n).innerHTML="<p><br /></p>"}}}function ni(e,t){const i=e.startNode.closest("td"),n=i.closest("table"),s=i.closest("tr"),o=n.get(0),r=s.get(0);let a=Jt(o);const l=a[0].length;let c;c="up"===t?r.rowIndex:r.rowIndex+1;const d=o.rows[c];v(`insertRow: rows ${o.rows.length}, target row ${c}`);const h=o.insertRow(c);if(!d){for(let e=0;e<l;e++){h.insertCell(h.cells.length).innerHTML="<p><br /></p>"}return}a=Jt(o),c=d.rowIndex;let p=-1;for(let e=0;e<l;e++){const t=ti(a,c,e);if(t!==p){p=t;const i=d.cells[t];if(!i)break;const n=h.insertCell(h.cells.length);n.innerHTML="<p><br /></p>",i.colSpan>1&&(n.colSpan=i.colSpan,e+=i.colSpan-1)}}for(let e=c-1;e>=0;e--){const t=o.rows[e].cells;for(let i=0;i<t.length;i++){const n=t[i];n.rowSpan>1&&n.rowSpan+1>c-e&&(n.rowSpan+=1)}}}const si=[{value:"insertLeft",text:e=>e.table.insertColumnLeft()},{value:"insertRight",text:e=>e.table.insertColumnRight()},{value:"delete",text:e=>e.table.deleteColumn()}],oi=[{value:"insertAbove",text:e=>e.table.insertRowAbove()},{value:"insertBelow",text:e=>e.table.insertRowBelow()},{value:"delete",text:e=>e.table.deleteRow()}],ri=[{value:"up",text:e=>e.table.mergeUp()},{value:"right",text:e=>e.table.mergeRight()},{value:"down",text:e=>e.table.mergeDown()},{value:"left",text:e=>e.table.mergeLeft()}],ai=[{value:"leftRight",text:e=>e.table.splitLeftRight()},{value:"topBottom",text:e=>e.table.splitTopBottom()}];function li(e,t){const i=[{name:"expand",type:"button",icon:n.get("expand"),tooltip:e=>e.table.fitTable(),isSelected:()=>{const t=e.selection.range.startNode.closest("table");if(0===t.length)return!1;return t.css("width")===e.container.innerWidth()-2+"px"},onClick:()=>{const t=e.selection.range.startNode.closest("table");if(0===t.length)return;const i=t.css("width"),n=e.container.innerWidth()-2+"px";i===n?t.css("width",""):t.css("width",n),e.history.save()}},{name:"backgroundColor",type:"dropdown",downIcon:n.get("down"),icon:n.get("backgroundColor"),accentIcon:n.get("backgroundColorAccent"),defaultValue:t.backgroundColor,tooltip:e=>e.table.cellBackground(),menuType:"color",menuItems:F,menuWidth:"296px",selectedValues:()=>{const t=e.selection.range.startNode.closest("td");if(t.length>0){return[f(t.computedCSS("background-color"))]}return[]},onSelect:(i,n)=>{e.selection.range.startNode.closest("td").css("background-color",n),t.backgroundColor=n,e.history.save()}},{name:"tableColumn",type:"dropdown",downIcon:n.get("down"),icon:n.get("tableColumn"),tooltip:e=>e.table.column(),menuType:"list",menuItems:si,menuCheck:!1,onSelect:(t,i)=>{const n=e.selection.range;"insertLeft"===i?ii(n,"left"):"insertRight"===i?ii(n,"right"):function(e){const t=e.startNode.closest("td"),i=t.closest("table"),n=t.closest("tr"),s=i.get(0),o=n.get(0),r=t.get(0),a=o.rowIndex,l=Jt(s),c=ei(l,a,r);let d=null;const h=r.cellIndex;o.cells[h+1]?d=o.cells[h+1]:o.cells[h-1]&&(d=o.cells[h-1]),v(`deleteColumn: rows ${s.rows.length}, column ${c}`);const p=function(e,t){for(let i=0;i<e.length;i++){const n=e[i][t],s=e[i+1];if(s&&n.colSpan!==s[t].colSpan)return!1}return!0}(l,c);for(let t=0;t<s.rows.length;t++){const i=s.rows[t],n=ti(l,t,c),o=i.cells[n];o.rowSpan>1&&(t+=o.rowSpan-1),o.colSpan>1&&!p?(o.colSpan-=1,1===o.colSpan&&o.removeAttribute("colSpan")):(o===r&&d&&e.shrinkBefore(b(d)),i.deleteCell(n))}0===s.rows[0].cells.length&&Qt(e)}(n),e.history.save()}},{name:"tableRow",type:"dropdown",downIcon:n.get("down"),icon:n.get("tableRow"),tooltip:e=>e.table.row(),menuType:"list",menuItems:oi,menuCheck:!1,onSelect:(t,i)=>{const n=e.selection.range;"insertAbove"===i?ni(n,"up"):"insertBelow"===i?ni(n,"down"):function(e){const t=e.startNode.closest("td"),i=t.closest("table"),n=t.closest("tr"),s=i.get(0),o=n.get(0),r=t.get(0),a=o.rowIndex;let l=Jt(s);const c=l[0].length,d=ei(l,a,r),h=s.rows[a+1]||s.rows[a-1];v(`deleteRow: rows ${s.rows.length}, target row ${a}, column ${d}`);for(let e=a-1;e>=0;e--){const t=s.rows[e].cells;for(let i=0;i<t.length;i++){const n=t[i];n.rowSpan>1&&n.rowSpan>a-e&&(n.rowSpan-=1,1===n.rowSpan&&n.removeAttribute("rowSpan"))}}const p=s.rows[a+1];if(p){let e=-1;for(let t=0;t<c;t++){const i=ti(l,a,t);if(i!==e){e=i;const n=o.cells[i];if(n.rowSpan>1){const e=ti(l,a+1,t);let i=p.insertCell(e);const s=n.cloneNode(!0);s.removeAttribute("rowSpan"),i.replaceWith(s),i=s,n.rowSpan>2&&(i.rowSpan=n.rowSpan-1)}}}}if(s.deleteRow(a),h){l=Jt(s);const t=ti(l,h.rowIndex,d),i=h.cells[t];i&&e.shrinkBefore(b(i))}0===s.rows.length&&Qt(e)}(n),e.history.save()}},{name:"tableMerge",type:"dropdown",downIcon:n.get("down"),icon:n.get("tableMerge"),tooltip:e=>e.table.merge(),menuType:"list",menuItems:ri,menuCheck:!1,onSelect:(t,i)=>{!function(e,t){const i=e.startNode.closest("td"),n=i.closest("table"),s=i.closest("tr"),o=n.get(0),r=s.get(0),a=i.get(0),l=r.rowIndex,c=Jt(o);if("left"===t||"right"===t){const i=a.cellIndex;let n,s,o;if("left"===t?(n=r.cells[i-1],s=i,o=a):(n=a,s=i+1,o=r.cells[s]),!n||!o)return;if(v(`mergeCells: row ${l}, cell ${i}, other row ${l}, other cell ${s}`),n.rowSpan!==o.rowSpan)return;const d=c[l],h=ei(c,l,n),p=ei(c,l,o);if(d[h+1]!==o&&d[p-1]!==n)return;return n.colSpan+=o.colSpan,$e(b(n),b(o)),void e.shrinkBefore(b(n))}const d=ei(c,l,a);let h,p,u,m,g,f;if("up"===t){h=-1,p=null;for(let e=r.rowIndex-1;e>=0;e--){const t=c[e];if(!t)break;const i=t[d];if(!i)break;if(p&&i!==p)break;h=e,p=i}u=r.rowIndex,m=r,g=a.cellIndex,f=a}else{h=r.rowIndex,p=a,u=-1,f=null,g=-1;for(let e=r.rowIndex+1;e<o.rows.length;e++){const t=c[e];if(!t)break;const i=t[d];if(!i)break;if(i!==f){u=e,f=i,g=f.cellIndex;break}}if(m=o.rows[u],!m)return}p&&f&&(v(`mergeCells: row ${h}, cell ${p.cellIndex}, other row ${u}, other cell ${g}`),p.colSpan===f.colSpan&&(p.rowSpan+=f.rowSpan,$e(b(p),b(f)),e.shrinkBefore(b(p))))}(e.selection.range,i),e.history.save()}},{name:"tableSplit",type:"dropdown",downIcon:n.get("down"),icon:n.get("tableSplit"),tooltip:e=>e.table.split(),menuType:"list",menuItems:ai,menuCheck:!1,onSelect:(t,i)=>{!function(e,t){const i=e.startNode.closest("td"),n=i.closest("table"),s=i.closest("tr"),o=n.get(0),r=s.get(0),a=i.get(0),l=r.rowIndex,c=a.rowSpan,d=a.colSpan;let h=Jt(o);const p=ei(h,l,a);if(v(`splitCell: row ${l}, cell ${p}, ${t}`),"topBottom"!==t)for(let e=0;e<h.length;e++){const t=o.rows[e],i=h[e],n=i[p];if(n===a){const i=h[e-1];if(!i||n!==i[p]){const i=ti(h,e,p),s=t.insertCell(i+1);s.innerHTML="<p><br /></p>",n.rowSpan>1&&(s.rowSpan=n.rowSpan),n.colSpan>2&&(s.colSpan=n.colSpan-1),n.removeAttribute("colSpan")}}else for(let e=p;e>=0;e--)if(0===e||n!==i[e]){1===d&&(n.colSpan+=1);break}}else{const e=h[l];for(let t=0;t<e.length;t++){const i=e[t];if(i===a){const e=c>1?o.rows[l+1]:o.insertRow(l+1),t=ti(h,l+1,p),i=e.insertCell(t);i.innerHTML="<p><br /></p>",a.colSpan>1&&(i.colSpan=a.colSpan),a.rowSpan>2&&(i.rowSpan=a.rowSpan-1),a.removeAttribute("rowSpan"),h=Jt(o)}else if(1===c){for(let e=l;e>=0;e--){const n=h[e];if(0===e||i!==n[t]){i.rowSpan+=1;break}}h=Jt(o)}i.colSpan>1&&(t+=i.colSpan-1)}}}(e.selection.range,i),e.history.save()}},{name:"remove",type:"button",icon:n.get("remove"),tooltip:e=>e.table.remove(),onClick:()=>{Qt(e.selection.range),e.history.save()}}];return i}const ci={start:"left",end:"right"};function di(e,t){if(e.isList){let i=Number.parseInt(e.attr("indent"),10)||0;if("increase"===t?i++:i--,i<=0)i=0;else if(i>10)return;return 0===i?e.removeAttr("indent"):e.attr("indent",i.toString(10)),void Ve([e])}let i=Number.parseInt(e.css("margin-left"),10)||0;"decrease"!==t||0!==i||""===e.css("text-indent")?("increase"===t?i+=40:i-=40,i<=0&&(i=0),0===i?e.css("margin-left",""):e.css("margin-left",`${i}px`)):e.css("text-indent","")}const hi="strong";const pi="sub";const ui="sup";const mi="code";const gi="lake-format-painter";function fi(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())}))}"function"==typeof SuppressedError&&SuppressedError;class vi{constructor(e){this.linkNode=null,this.scrollListener=()=>this.updatePosition(),this.resizeListener=()=>this.updatePosition(),this.config=e||{},this.locale=this.config.locale||ue("en-US"),this.container=b(S`
40
+ `),o=new X({root:n.find(".lake-input-field"),name:"embed",type:"primary",text:Ae(s,e.embedButtonText),onClick:()=>{const o=n.find('input[name="url"]').value();e.validUrl(o)?(t.updateValue("url",o),i.history.save(),n.remove(),_e(e,t)):i.config.showMessage("error",Ae(s,e.urlError))}});n.find('input[name="url"]').on("keydown",(e=>{Ce.isKeyHotkey("enter",e)&&(e.preventDefault(),o.node.emit("click"))})),o.render(),a.append(n)}else _e(e,t);i.readonly||function(e,t){const i=t.getEditor(),s=t.getContainer().find(".lake-iframe");s.find(".lake-corner-toolbar").length>0||new Se({locale:i.locale,root:s,items:[{name:"remove",icon:n.get("remove"),tooltip:e.deleteButtonText,onClick:e=>{e.stopPropagation(),i.selection.removeBox(t),i.history.save()}}]}).render()}(e,t)}}}class Te{constructor(e){this.fragment=null!=e?e:document.createDocumentFragment()}get(){return this.fragment}find(e){const t=[];let i=new x(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 x(t)}append(e){b(e).each((e=>{this.fragment.appendChild(e)}))}}function Ee(e){e=e.replace(/&quot;/gi,'"');const t={},i=/\s*([\w-]+)\s*:([^;]*)(?:;|$)/g;let n;for(;null!==(n=i.exec(e));){const e=n[1].toLowerCase().trim(),i=f(n[2]).trim();t[e]=i}return t}class Ie{constructor(e,t=o()){this.rules=t,this.source="string"==typeof e?this.parseHTML(e):e}parseHTML(e){const t=(new DOMParser).parseFromString(e,"text/html");return new x(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&&Ie.matchRule(n[e.name],e.value)&&o.set(e.name,e.value),"style"===e.name)){const t=n.style,i=new Map,s=Ee(e.value);for(const e of Object.keys(s)){const n=s[e];t[e]&&Ie.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,"&quot;")}; `;""!==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 C(Ie.getTrimmedText(n));else if(n.isVoid){const t=Ie.getOpenTagString(n,e);""!==t&&(yield`<${t} />`)}else if(n.isElement){const i=Ie.getOpenTagString(n,e),s=Ie.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 Me{constructor(e){this.content=e}getHTML(){let e=this.content;return e=e.replace(/ {2}/g,"  "),e=C(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 Ie(this.getHTML()).getFragment()}}function Pe(e,t){const i=e.get(),n=t.get(0);i.insertNode(n),i.setEndAfter(n),i.collapse(!1)}function He(e){if(e.commonAncestor.isOutside)return{anchor:new x,focus:new x};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 x,focus:t};if(e.isCollapsed){const t=e.clone();t.collapseToEnd();const i=b('<lake-bookmark type="focus" />');return Pe(t,i),{anchor:new x,focus:i}}const i=e.clone();i.collapseToStart();const n=b('<lake-bookmark type="anchor" />');Pe(i,n);const s=e.clone();s.collapseToEnd();const o=b('<lake-bookmark type="focus" />');return Pe(s,o),{anchor:n,focus:o}}function De(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 x(document.createTextNode("​"));e.before(i),t.setStartAfter(i),t.collapseToStart()}e.remove()}else e.remove()}function Ze(e,t){const i=t.anchor,n=t.focus;if(i.length>0&&0===n.length)De(i);else{if(n.length>0&&0===i.length){if(n.isBox){const t=xe(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 De(n,e)}if(i.length>0&&n.length>0){const t=new N;t.selectNode(i),t.collapseToEnd(),-1===t.compareAfterNode(n)?(e.setStartBefore(n),De(n),e.setEndBefore(i),De(i)):(e.setStartBefore(i),De(i),e.setEndBefore(n),De(n))}}}function Ne(e){if(0===e.length)return;const t=[];let i=e.first();for(;i.length>0;){const e=i.next();i.isText&&""===i.text()||t.push(i),i=e}(1===t.length&&"br"===t[0].name||2===t.length&&"br"===t[0].name&&t[1].isBookmark)&&t[0].remove(),2===t.length&&t[0].isBookmark&&"br"===t[1].name&&t[1].remove()}function ze(e){const t=b("<br />");let i=e;for(;i.isBlock;){let e=i.last();for(;e.isText&&e.isEmpty;)e=e.prev();if(!e.isBlock&&"br"!==e.name){i.append(t);break}i=e}return t}function Oe(e){if(e.isText)return{node:e,offset:e.text().length};const t=new N;return t.setEndAfter(e),{node:t.endNode,offset:t.endOffset}}function $e(e,t){const i=t;if(["ul","ol"].indexOf(e.name)>=0){const t=e.find("li");e=t.eq(t.length-1)}if(["ul","ol"].indexOf(t.name)>=0){const e=t.find("li");t=e.eq(0)}if(e.isText||t.isText||e.isVoid||t.isVoid)return Oe(e);Ne(e),Ne(t),e.isBlock&&e.isEmpty&&t.isEmpty&&ze(e);const n=e.last(),s=t.first();let o=s;for(;o.length>0;){const t=o.next();e.append(o),o=t}return i.remove(),n.length>0&&s.length>0&&n.isElement&&!n.isBox&&n.clone(!1).get(0).isEqualNode(s.clone(!1).get(0))?$e(n,s):0===n.length?{node:e,offset:0}:Oe(n)}function Ve(e){if(0===e.length)return;const t=e[0],i=e[e.length-1],n=[];let s=t.prev();for(;s.length>0&&"ol"===s.name;)n.push(s),s=s.prev();n.reverse(),n.push(...e);let o=i.next();for(;o.length>0&&"ol"===o.name;)n.push(o),o=o.next();let r=1;for(const e of n){const t=e.prev();if(0!==t.length&&"ol"===t.name||(r=1),"ol"===e.name){"ol"===t.name&&t.attr("indent")!==e.attr("indent")&&(r=1);const i=e.attr("start"),n=r.toString(10);i!==n&&e.attr("start",n),r++}}}function Re(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=ze(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=He(e);$e(o,s),Ve([o]),Ze(e,r)}function Fe(e,t){if(e.commonAncestor.isOutside)return;let i;t instanceof Te?i=t:t instanceof DocumentFragment?i=new Te(t):(i=new Te,i.append(t)),e.isCollapsed?e.adjustBox():Re(e);Ne(e.startNode.closestBlock());const n=e.get();n.insertNode(i.get()),n.collapse(!1),e.adjustBlock()}function qe(e){let t=e;for(;t.length>0;){let e=t.first();if(e.isText&&e.isEmpty&&(e=e.next()),t.isElement&&!t.isVoid&&0===e.length)break;t=e}return t}function We(e,t){if(t=null!=t?t:b("<p />"),0===e.length)return t;const i=qe(t=t.clone(!0));e[0].before(t);for(const t of e)i.append(t);return t}function je(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=b(t),n=i.name,s=i.get(0).attributes,o=e.getBlocks();if(o.length>0){const t=He(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=qe(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 Ze(e,t),void Ve(e.getBlocks())}if(e.isCollapsed){const t=e.getNextNode();if("br"===t.name){const i=b("<p><br /></p>");return t.replaceWith(i),void e.shrinkBefore(i)}const i=e.getPrevNode();if("br"===i.name){const t=b("<p><br /></p>");return i.replaceWith(t),void e.shrinkBefore(t)}}const r=He(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=We(a,i);if(Ze(e,r),Ve(e.getBlocks()),l.isEmpty){const t=ze(l);e.setStartBefore(t),e.collapseToStart()}}function Ue(e,t,i){const n=new N;let s;if(e.isText){s=e.parent();const i=e.splitText(t);n.setStartAfter(e),""===e.text()&&e.remove(),""===i.text()&&i.remove()}else n.setStart(e,t),s=e;if("body"===s.name||"html"===s.name)return null;if(s.get(0)===i.get(0))return null;n.collapseToStart();const o=s.clone();let r=s.first();for(;r.length>0&&!(n.compareBeforeNode(r)>=0);){const e=r.next();o.append(r),r=e}return s.before(o),s.parent().length>0&&s.parent().get(0)!==i.get(0)?Ue(s.parent(),s.index(),i):{start:o,end:s}}function Ke(e){if(e.isMark&&e.isEmpty)e.remove();else for(const t of e.getWalker())t.isMark&&t.isEmpty&&t.remove()}function Xe(e){if(e.commonAncestor.isOutside)return{start:null,end:null};e.isCollapsed?e.adjustBox():Re(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=Ue(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&&(Ke(o),ze(o)),r&&(r.isEmpty&&(Ke(r),ze(r)),e.shrinkBefore(r)),Ve(e.getBlocks()),{start:o,end:r}}function Ge(e,t){if(e.commonAncestor.isOutside)return null;const i=b(t),n=Xe(e);return n.start&&(Ke(n.start),e.setEndAfter(n.start),e.collapseToEnd()),n.end&&(Ke(n.end),n.end.isEmpty&&n.end.remove()),Fe(e,i),i.isBox||e.shrinkAfter(i),n.start&&n.start.isEmpty&&n.start.remove(),i}function Ye(e,t,i){let n=null,s=null,o=e.closestBlock();0===o.length&&(o=e.closestContainer());const r=Ue(e,t,o);return r&&(i?(Ke(r.start),Ke(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 Qe(e,t=!0){if(e.commonAncestor.isOutside)return{start:null,center:null,end:null};if(e.adjustBox(),e.isCollapsed){const i=Ye(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=Ye(e.startNode,e.startOffset,t);i.start?e.setStartAfter(i.start):i.end&&e.setStartBefore(i.end);const n=Ye(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 Je(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 et(e,t){if(e.commonAncestor.isOutside)return;let i=b(t);const n=i.name,s=Ee(i.attr("style"));if(e.isCollapsed){if(e.isBox){const t=e.startNode.closest("lake-box");if("block"===xe(t).type){const i=b("<p><br /></p>");e.isBoxStart?t.before(i):t.after(i),e.shrinkAfter(i)}else e.adjustBox()}Ne(e.startNode.closestBlock());const t=new x(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(Qe(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()){qe(i).append(t)}return Fe(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)}Qe(e);const o=e.getMarks(!0),r=He(e);for(const e of o)if(!e.isEmpty&&e.isText){const t=Je(e,n);if(t.isMark&&t.name===n)t.css(s);else{const e=i.clone();t.before(e),e.append(t)}}Ze(e,r)}function tt(e,t){if(e.commonAncestor.isOutside)return;let i;if(t){i=b(t).name}if(e.isCollapsed){if(e.isBox)return;if(i&&0===e.commonAncestor.closest(i).length)return;const t=Qe(e,!1);if(!t.start)return;t.end&&Ke(t.end);const n=new x(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),Ke(t.start),n.prev().isText?(e.setStartAfter(n.prev()),e.collapseToStart(),void n.remove()):(e.setStartAfter(n),void e.collapseToStart());return qe(s).append(n),t.start.after(s),Ke(t.start),void e.shrinkAfter(s)}Qe(e);const n=e.getMarks(),s=He(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()}!function(e){for(const t of e.getWalker())if(t.isText){const e=t.text();""===e?t.remove():e.length>1&&/\u200B/.test(e)&&(t.get(0).nodeValue=e.replace(/\u200B/g,""))}}(e.commonAncestor),Ze(e,s)}function it(e,t,i){if(e.commonAncestor.isOutside)return null;const n=xe(t);if(i&&(n.value=i),"inline"===n.type){if(Qe(e),Fe(e,n.node),n.render(),n.node.isTopInside){const e=b("<p />");n.node.before(e),e.append(n.node)}return e.selectBoxEnd(n.node),xe(n.node)}return Ge(e,n.node),n.render(),e.selectBoxEnd(n.node),xe(n.node)}function nt(e){const t=e.node.closestContainer();if(e.unmount(),e.node.remove(),t.length>0){A(t.id).delete(e.node.id);A(0).set(e.node.id,e)}return e}function st(e){if(e.commonAncestor.isOutside)return null;const t=e.commonAncestor.closest("lake-box");if(0===t.length)return null;const i=xe(t);if("block"===i.type){const n=b("<p><br /></p>");return t.before(n),e.shrinkAfter(n),nt(i)}e.setStartBefore(t),e.collapseToStart();const n=t.parent();if(nt(i),n.isEmpty){const t=ze(n);e.setStartBefore(t),e.collapseToStart()}return i}var ot,rt={exports:{}};function at(){if(ot)return rt.exports;function e(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 Object.defineProperty(h,"isPending",{get:()=>void 0!==r}),h.clear=()=>{r&&(clearTimeout(r),r=void 0)},h.flush=()=>{r&&h.trigger()},h.trigger=()=>{l=c(),h.clear()},h}return ot=1,rt.exports.debounce=e,rt.exports=e,rt.exports}var lt,ct,dt=_(at());var ht=_(ct?lt:(ct=1,lt=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 pt(e){return e.replace(/(<lake-box[^>]+>)[\s\S]*?(<\/lake-box>)/gi,"$1$2").replace(/<lake-bookmark\s+type="anchor">\s*<\/lake-bookmark>/gi,"<anchor />").replace(/<lake-bookmark\s+type="focus">\s*<\/lake-bookmark>/gi,"<focus />")}function ut(e){return e.replace(/(<lake-box[^>]+>)[\s\S]*?(<\/lake-box>|$)/gi,"$1</lake-box>").replace(/<anchor\s*\/>/gi,'<lake-bookmark type="anchor"></lake-bookmark>').replace(/<focus\s*\/>/gi,'<lake-bookmark type="focus"></lake-bookmark>')}function mt(e){const t=e.get(0),i={};if(t.hasAttributes())for(const e of t.attributes)i[e.name]=e.value;return i}class gt{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 N(e)}return new N}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 Ze(e,{anchor:new x,focus:i}),void this.sync();Ze(e,{anchor:t.find('lake-bookmark[type="anchor"]'),focus:t.find('lake-bookmark[type="focus"]')}),this.sync()}getActiveItems(){const e=[];return function(e,t){let i=t.startNode;for(i.isText&&(i=i.parent());i.length>0&&i.isContentEditable&&!i.isContainer;)e.push({node:i,name:i.name,attributes:mt(i),styles:Ee(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:mt(t),styles:Ee(t.attr("style"))}),t=t.first()}}(e,this.range),e}cloneContainer(){const e=this.range,t=this.container.clone(!0);if(t.find("lake-box").each((e=>{xe(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),He(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),He(r),t}insertBookmark(){return He(this.range)}toBookmark(e){return Ze(this.range,e)}insertContents(e){return Fe(this.range,e)}deleteContents(){return Re(this.range)}setBlocks(e){return je(this.range,e)}splitBlock(){return Xe(this.range)}insertBlock(e){return Ge(this.range,e)}splitMarks(e){return Qe(this.range,e)}addMark(e){return et(this.range,e)}removeMark(e){return tt(this.range,e)}selectBox(e){let t=e;t=e instanceof ye?e.node:e,this.range.selectBox(t),this.sync()}insertBox(e,t){const i=it(this.range,e,t);if(!i)throw new Error(`Box "${e}" cannot be inserted into the outside of the editor.`);return i}removeBox(e=null){return e&&this.selectBox(e),st(this.range)}}class ft{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.getActiveItems();return t.isDisabled(i)}isSelected(e){const t=this.getItem(e);if(!t.isSelected)return!1;const i=this.selection.getActiveItems();return t.isSelected(i)}selectedValues(e){const t=this.getItem(e);if(!t.selectedValues)return[];const i=this.selection.getActiveItems();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),v(`Command "${e}" executed`)}}const vt=new Set;function wt(){}const yt={morphStyle:"outerHTML",callbacks:{beforeNodeAdded:wt,afterNodeAdded:wt,beforeNodeMorphed:wt,afterNodeMorphed:wt,beforeNodeRemoved:wt,afterNodeRemoved:wt,beforeAttributeUpdated:wt,afterAttributeUpdated:wt,beforeChildrenUpdated:wt},head:{style:"merge",shouldPreserve:e=>"true"===e.getAttribute("im-preserve"),shouldReAppend:e=>"true"===e.getAttribute("im-re-append"),shouldRemove:wt,afterHeadMorphed:wt}};function xt(e,t){return!e.deadIds.has(t)}function bt(e,t,i){return(e.idMap.get(i)||vt).has(t)}function kt(e,t){const i=e.idMap.get(t)||vt;for(const t of i)e.deadIds.add(t)}function Ct(e,t,i){const n=e.idMap.get(t)||vt;let s=0;for(const t of n)xt(e,t)&&bt(e,t,i)&&++s;return s}function St(e,t){const i=e.parentElement,n=e.querySelectorAll("[id]");for(const e of n){let n=e;for(;n!==i&&null!=n;){let i=t.get(n);null==i&&(i=new Set,t.set(n,i)),i.add(e.id),n=n.parentElement}}}function Bt(e,t){const i=new Map;return St(e,i),St(t,i),i}function At(e,t,i){return{target:e,newContent:t,config:i=function(e){const t={};return Object.assign(t,yt),Object.assign(t,e),t.callbacks={},Object.assign(t.callbacks,yt.callbacks),Object.assign(t.callbacks,e.callbacks),t.head={},Object.assign(t.head,yt.head),Object.assign(t.head,e.head),t}(i),morphStyle:i.morphStyle,ignoreActive:i.ignoreActive,ignoreActiveValue:i.ignoreActiveValue,idMap:Bt(e,t),deadIds:new Set,callbacks:i.callbacks,head:i.head}}function _t(e,t,i){return null!=e&&null!=t&&(e.nodeType===t.nodeType&&e.tagName===t.tagName&&(""!==e.id&&e.id===t.id||Ct(i,e,t)>0))}function Lt(e,t){return null!=e&&null!=t&&(e.nodeType===t.nodeType&&e.tagName===t.tagName)}function Tt(e,t){kt(t,e),!1!==t.callbacks.beforeNodeRemoved(e)&&(e.remove(),t.callbacks.afterNodeRemoved(e))}function Et(e,t,i){let n=e;for(;n&&n!==t;){const e=n;n=n.nextSibling,Tt(e,i)}return kt(i,t),t.nextSibling}function It(e,t,i,n,s){const o=Ct(s,i,t);let r=null;if(o>0){r=n;let t=0;for(;null!=r;){if(_t(i,r,s))return r;if(t+=Ct(s,r,e),t>o)return null;r=r.nextSibling}}return r}function Mt(e,t,i,n,s){let o=n,r=i.nextSibling,a=0;for(;null!=o;){if(Ct(s,o,e)>0)return null;if(Lt(i,o))return o;if(Lt(r,o)&&(a++,r=r?r.nextSibling:null,a>=2))return null;o=o?o.nextSibling:null}return o}function Pt(e,t,i){return Lt(e,t)?.5+Ct(i,e,t):0}function Ht(e,t,i,n){return!("value"!==e||!n.ignoreActiveValue||t!==document.activeElement)||!1===n.callbacks.beforeAttributeUpdated(e,t,i)}function Dt(e,t,i){var n;if(!i.ignoreActive||e!==document.activeElement)return null==t?!1===i.callbacks.beforeNodeRemoved(e)?e:(e.remove(),i.callbacks.afterNodeRemoved(e),null):Lt(e,t)?(!1===i.callbacks.beforeNodeMorphed(e,t)||(function(e,t,i){const n=e.nodeType;if(1===n){const n=e.attributes,s=t.attributes;for(const e of n)Ht(e.name,t,"update",i)||t.getAttribute(e.name)!==e.value&&(t.setAttribute(e.name,e.value),i.callbacks.afterAttributeUpdated(e.name,t,"update"));for(let n=s.length-1;n>=0;n--){const o=s[n];Ht(o.name,t,"remove",i)||e.hasAttribute(o.name)||(t.removeAttribute(o.name),i.callbacks.afterAttributeUpdated(o.name,t,"remove"))}}8!==n&&3!==n||t.nodeValue!==e.nodeValue&&(t.nodeValue=e.nodeValue)}(t,e,i),!1===i.callbacks.beforeChildrenUpdated(e,t)||function(e,t){return t.ignoreActiveValue&&e===document.activeElement}(e,i)||Zt(t,e,i),i.callbacks.afterNodeMorphed(e,t)),e):!1===i.callbacks.beforeNodeRemoved(e)||!1===i.callbacks.beforeNodeAdded(t)?e:(null===(n=e.parentElement)||void 0===n||n.replaceChild(t,e),i.callbacks.afterNodeAdded(t),i.callbacks.afterNodeRemoved(e),t)}function Zt(e,t,i){let n,s=e.firstChild,o=t.firstChild;for(;s;){if(n=s,s=n.nextSibling,null==o){if(!1===i.callbacks.beforeNodeAdded(n))return;t.appendChild(n),i.callbacks.afterNodeAdded(n),kt(i,n);continue}if(_t(n,o,i)){Dt(o,n,i),o=o.nextSibling,kt(i,n);continue}const r=It(e,t,n,o,i);if(r){o=Et(o,r,i),Dt(r,n,i),kt(i,n);continue}const a=Mt(e,0,n,o,i);if(a)o=Et(o,a,i),Dt(a,n,i),kt(i,n);else{if(!1===i.callbacks.beforeNodeAdded(n))return;t.insertBefore(n,o),i.callbacks.afterNodeAdded(n),kt(i,n)}}for(;null!==o;){const e=o;o=o.nextSibling,Tt(e,i)}}function Nt(e,t,i){if("innerHTML"===i.morphStyle)return Zt(t,e,i),e.children;const n=function(e,t,i){let n;n=e.firstChild;let s=n,o=0;for(;n;){const e=Pt(n,t,i);e>o&&(s=n,o=e),n=n.nextSibling}return s}(t,e,i),s=null==n?void 0:n.previousSibling,o=null==n?void 0:n.nextSibling,r=Dt(e,n,i);return n?function(e,t,i){var n,s;const o=[],r=[];let a=e;for(;null!=a;)o.push(a),a=a.previousSibling;for(;o.length>0;){const e=o.pop();r.push(e),e&&(null===(n=t.parentElement)||void 0===n||n.insertBefore(e,t))}r.push(t);let l=i;for(;null!=l;)o.push(l),r.push(l),l=l.nextSibling;for(;o.length>0;){const e=o.pop();e&&(null===(s=t.parentElement)||void 0===s||s.insertBefore(e,t.nextSibling))}return r}(s,r,o):[]}function zt(e,t,i={}){const n=function(e){if(null==e)return document.createElement("div");if(e instanceof Node){if(e.generatedByIdiomorph)return e;const t=document.createElement("div");return t.append(e),t}const t=document.createElement("div");for(const i of[...e])t.append(i);return t}(t.get(0)),s=At(e.get(0),n,i);Nt(e.get(0),n,s)}class Ot{constructor(e){this.canSave=!0,this.list=[],this.index=0,this.limit=100,this.contentRules=o(),this.event=new I,this.selection=e,this.container=e.container}removeBookmark(e){return e.replace(/(<lake-box[^>]+)\sfocus="\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 Ie(e,this.contentRules).getHTML()}addIdToBoxes(e){e.find("lake-box").each((e=>{const t=new x(e),i=`${t.attr("name")}-${t.attr("value")}`;t.attr("id",i)}))}removeIdfromBoxes(e){e.find("lake-box").each((e=>{new x(e).removeAttr("id")}))}morphContainer(e){const t=this.container,i={beforeChildrenUpdated:e=>{if("lake-box"===new x(e).name)return!1},afterAttributeUpdated:(e,i)=>{const n=new x(i);if(["name","value"].indexOf(e)>=0&&"lake-box"===n.name){xe(n).unmount();A(t.id).delete(n.id)}}},n=e.clone(!0);this.addIdToBoxes(t),this.addIdToBoxes(n),zt(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]}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(),v(`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(),v(`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.selection.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),v(`History saved (index: ${this.index}, inputType: "${s}", update: ${o}, emitEvent: ${r})`),r&&this.event.emit("save",pt(l),{inputType:s,update:o,emitEvent:r}))}}class $t{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(Ce.isKeyHotkey(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(Ce.isKeyHotkey(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 Vt={value:"<p><br /></p>",readonly:!1,spellcheck:!1,tabIndex:0,placeholder:"",indentWithTab:!0,lang:"en-US",contentRules:o(),minChangeSize:5,historySize:100,showMessage:(e,t)=>{"success"!==e?"warning"!==e?"error"===e&&console.error(t):console.warn(t):console.log(t)},downloadFile:(e,t)=>{window.open(t)},slash:!1,mention:!1};class Rt{constructor(e){if(this.unsavedInputData="",this.unsavedInputCount=0,this.state={activeItems:[],disabledNameMap:new Map,selectedNameMap:new Map,selectedValuesMap:new Map},this.unmountPluginMap=new Map,this.event=new I,this.isComposing=!1,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 x(e.target);t.get(0).isConnected&&this.event.emit("click",t)},this.updateSelectionRange=dt((()=>{this.selection.updateByRange()}),1,{immediate:!0}),this.updateBoxSelectionStyle=dt((()=>{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=xe(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=dt((()=>{const e=this.getState();ht(e,this.state)||(this.toolbar&&this.toolbar.updateState(e),this.event.emit("statechange",e),this.state=e)}),50,{immediate:!1}),!e.root)throw new Error("The root of the config must be specified.");this.root=b(e.root),this.toolbar=e.toolbar,this.config=Object.assign({},Vt);for(const t of Object.keys(e))this.config[t]=e[t];this.containerWrapper=b('<div class="lake-container-wrapper" />'),this.container=b('<div class="lake-container" />'),this.overlayContainer=b('<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(),readonly:this.readonly?"true":"false"}),""!==this.config.placeholder&&this.container.attr("placeholder",this.config.placeholder),this.selection=new gt(this.container),this.command=new ft(this.selection),this.history=new Ot(this.selection),this.history.limit=this.config.historySize,this.history.contentRules=this.config.contentRules,this.keystroke=new $t(this.container),P.set(this.container.id,this)}togglePlaceholderClass(e){const t="lake-placeholder";"<p><br /></p>"===(e=pt(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"===xe(n).type)t.isBoxStart?(t.setStartBefore(n),t.collapseToStart()):(t.setStartAfter(n),t.collapseToStart());else{const e=b("<p />");t.isBoxStart?n.before(e):n.after(e),t.setStart(e,0),t.collapseToStart()}const s=i.text();i.html("<br />"),e.insertContents(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)}))}removeBoxGarbage(){const e=A(this.container.id);for(const t of e.values())t.node.get(0).isConnected||(t.unmount(),e.delete(t.node.id))}bindHistoryEvents(){const e=e=>{this.fixContent()&&(this.history.save({update:!0,emitEvent:!1}),e=this.getValue()),this.emitStateChangeEvent(),this.togglePlaceholderClass(e),this.scrollToCursor(),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())}))}bindPointerEvents(){this.container.on("pointerdown",(e=>{const t=e;if(null!==t.target&&t.target!==this.container.get(0))return;const i=this.container.last();if(i.isTable||i.isBlockBox){const e=i.get(0).getBoundingClientRect();if(t.clientY>e.bottom){t.preventDefault();const e=b("<p><br /></p>");i.after(e),this.selection.range.shrinkBefore(e),this.selection.sync()}}}))}get locale(){return ue(this.config.lang)}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])}fixContent(){const e=this.selection.range,t=e.commonAncestor.closest("td"),i=t.length>0?t:this.container;let n=!1,s=i.children();for(const e of s)(e.isBlock||e.isMark)&&""===e.html()&&(e.remove(),n=!0,v(`Content fixed: empty tag "${e.name}" was removed`));if(s=i.children(),0===s.length)i.html("<p><br /></p>"),e.shrinkBefore(i),n=!0,v("Content fixed: default paragraph was added");else if(1===s.length){const t=s[0];if(t.isVoid){const i=b("<p />");t.before(i),i.append(t),e.shrinkAfter(i),n=!0,v(`Content fixed: void element "${t.name}" was wrapped in paragraph`)}}return e.adjustBr(),n}renderBoxes(){this.removeBoxGarbage();const e=this.container,t=A(e.id);e.find("lake-box").each((e=>{const i=b(e);if(t.get(i.id))return;xe(i).render()}))}scrollToCursor(){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=b('<div class="lake-artificial-cursor" />'),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-cursor").remove(),this.overlayContainer.append(n),function(e,t){const i=Z(e);0===i.left&&0===i.right&&0===i.top&&0===i.bottom||e.get(0).scrollIntoView(t)}(n,{behavior:"instant",block:"nearest",inline:"nearest"}),n.remove()}hasFocus(){const e=document.activeElement;return!!e&&b(e).closest(".lake-container").get(0)===this.container.get(0)}focus(){const e=this.selection.range;this.container.contains(e.commonAncestor)&&e.isBox||this.container.focus()}blur(){this.container.blur()}getState(){const e=this.command.getNames();let t=this.selection.getActiveItems();t.length>0&&!this.container.contains(t[0].node)&&(t=[]);const i=new Map,n=new Map,s=new Map;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),t.length>0&&e.selectedValues){const i=e.selectedValues(t);i.length>0&&s.set(o,i)}}return{activeItems:t,disabledNameMap:i,selectedNameMap:n,selectedValuesMap:s}}setValue(e){e=ut(e);const t=new Ie(e,this.config.contentRules),i=t.getFragment();this.container.empty(),this.togglePlaceholderClass(t.getHTML()),this.container.append(i),this.renderBoxes(),this.selection.updateByBookmark()}getValue(){const e=this.selection.cloneContainer();let t=new Ie(e,this.config.contentRules).getHTML();return t=pt(t),t}render(){const e=ut(this.config.value),t=new Ie(e,this.config.contentRules),i=t.getFragment();if(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=Rt.plugin.loadAll(this),this.readonly||(this.selection.updateByBookmark(),this.history.save({emitEvent:!1})),this.renderBoxes(),this.toolbar){this.toolbar.render(this);const e=this.getState();this.toolbar.updateState(e)}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(),this.bindPointerEvents())}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(),v(`Plugin "${e}" unmounted`))}this.toolbar&&this.toolbar.unmount(),this.removeBoxGarbage(),this.container.find("lake-box").each((e=>{xe(b(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))}}Rt.version="0.4.0",Rt.box=new class{add(e){M.set(e.name,e)}remove(e){M.delete(e)}getNames(){return Array.from(M.keys())}},Rt.plugin=new class{constructor(){this.pluginMap=new Map}add(e,t){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}};function Ft(e,t){const i=e.get(0),n=b(S`<${t} />`);for(const e of i.attributes)n.attr(e.name,e.value);let s=e.first();for(;s.length>0;){const e=s.next();n.append(s),s=e}return e.replaceWith(n),n}const qt=Array.from(a).join(",");function Wt(e){const t=[e];for(const i of e.getWalker())t.push(i);for(const e of t)"div"===e.name?e.find(qt).length>0?e.remove(!0):Ft(e,"p"):(e.isHeading||["blockquote","li"].indexOf(e.name)>=0)&&e.find(qt).remove(!0)}function jt(e,t){const i=e.selection,n=i.range;if(0===t.childNodes.length)return;const s=new x(t.firstChild);let o=new x(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"===xe(n).type)i.isBoxStart?(i.setStartBefore(n),i.collapseToStart()):i.isBoxEnd?(i.setStartAfter(n),i.collapseToStart()):e.selection.removeBox();else{const t=b("<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=xe(t),n=""!==t.attr("value")?i.value:void 0;return e.selection.insertBox(i.name,n),void t.remove()}if(t.first().length>0&&Ne(s),s.isEmpty&&"p"===s.name)return s.replaceWith(t),t.find("lake-box").each((e=>{xe(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.insertContents(o),o.isBox?xe(o).render():o.isElement&&o.find("lake-box").each((e=>{xe(e).render()})),o=t}t.remove()}(e,s);let r=new x(t.firstChild);for(;r.length>0;){const e=r.next();"br"===r.name&&r.remove(),r=e}if(o=new x(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.insertContents(t),e.renderBoxes(),n.shrinkAfter(o)}Ve(e.container.children().filter((e=>e.isBlock))),e.history.save()}const Ut=["info","tip","warning","danger"];function Kt(e){e.selection.setBlocks("<p />")}function Xt(e){e.selection.setBlocks("<ol><li></li></ol>")}function Gt(e){e.selection.setBlocks("<ul><li></li></ul>")}function Yt(e,t){e.selection.setBlocks(`<ul type="checklist"><li value="${t}"></li></ul>`)}function Qt(e){const t=e.startNode.closest("table"),i=b("<p><br /></p>");t.replaceWith(i),e.shrinkBefore(i),v(`deleteTable: table ${t.id}`)}function Jt(e){const t=[];for(let i=0;i<e.rows.length;i++)t[i]=[];for(let i=0;i<t.length;i++){const n=e.rows[i],s=t[i];let o=0;for(let e=0;e<n.cells.length;e++){for(o=e;s[o];)o++;const r=n.cells[e];for(let e=0;e<r.colSpan;e++)for(let n=0;n<r.rowSpan;n++){const s=t[i+n];s&&(s[o+e]=r)}}}return t}function ei(e,t,i){const n=e[t];for(let e=0;e<n.length;e++){if(n[e]===i)return e}return-1}function ti(e,t,i){const n=e[t],s=e[t-1];let o=i;for(let e=0;e<i;e++){const t=n[e];if(t===n[e+1])o--;else if(s){t===s[e]&&o--}}return o}function ii(e,t){const i=e.startNode.closest("td"),n=i.closest("table"),s=i.closest("tr"),o=n.get(0),r=s.get(0),a=i.get(0),l=r.rowIndex,c=Jt(o);let d=ei(c,l,a);if("right"===t){const e=c[l];if(d++,e)for(;a===e[d];)d++}v(`insertColumn: rows ${o.rows.length}, column ${d}, ${t}`);for(let e=0;e<o.rows.length;e++){const t=o.rows[e],i=c[e],n=ti(c,e,d),s=t.cells[n];if(s&&s.colSpan>1&&s===i[d-1])s.colSpan+=1,s.rowSpan>1&&(e+=s.rowSpan-1);else{t.insertCell(n).innerHTML="<p><br /></p>"}}}function ni(e,t){const i=e.startNode.closest("td"),n=i.closest("table"),s=i.closest("tr"),o=n.get(0),r=s.get(0);let a=Jt(o);const l=a[0].length;let c;c="up"===t?r.rowIndex:r.rowIndex+1;const d=o.rows[c];v(`insertRow: rows ${o.rows.length}, target row ${c}`);const h=o.insertRow(c);if(!d){for(let e=0;e<l;e++){h.insertCell(h.cells.length).innerHTML="<p><br /></p>"}return}a=Jt(o),c=d.rowIndex;let p=-1;for(let e=0;e<l;e++){const t=ti(a,c,e);if(t!==p){p=t;const i=d.cells[t];if(!i)break;const n=h.insertCell(h.cells.length);n.innerHTML="<p><br /></p>",i.colSpan>1&&(n.colSpan=i.colSpan,e+=i.colSpan-1)}}for(let e=c-1;e>=0;e--){const t=o.rows[e].cells;for(let i=0;i<t.length;i++){const n=t[i];n.rowSpan>1&&n.rowSpan+1>c-e&&(n.rowSpan+=1)}}}const si=[{value:"insertLeft",text:e=>e.table.insertColumnLeft()},{value:"insertRight",text:e=>e.table.insertColumnRight()},{value:"delete",text:e=>e.table.deleteColumn()}],oi=[{value:"insertAbove",text:e=>e.table.insertRowAbove()},{value:"insertBelow",text:e=>e.table.insertRowBelow()},{value:"delete",text:e=>e.table.deleteRow()}],ri=[{value:"up",text:e=>e.table.mergeUp()},{value:"right",text:e=>e.table.mergeRight()},{value:"down",text:e=>e.table.mergeDown()},{value:"left",text:e=>e.table.mergeLeft()}],ai=[{value:"leftRight",text:e=>e.table.splitLeftRight()},{value:"topBottom",text:e=>e.table.splitTopBottom()}];function li(e,t){const i=[{name:"expand",type:"button",icon:n.get("expand"),tooltip:e=>e.table.fitTable(),isSelected:()=>{const t=e.selection.range.startNode.closest("table");if(0===t.length)return!1;return t.css("width")===e.container.innerWidth()-2+"px"},onClick:()=>{const t=e.selection.range.startNode.closest("table");if(0===t.length)return;const i=t.css("width"),n=e.container.innerWidth()-2+"px";i===n?t.css("width",""):t.css("width",n),e.history.save()}},{name:"backgroundColor",type:"dropdown",downIcon:n.get("down"),icon:n.get("backgroundColor"),accentIcon:n.get("backgroundColorAccent"),defaultValue:t.backgroundColor,tooltip:e=>e.table.cellBackground(),menuType:"color",menuItems:F,menuWidth:"296px",selectedValues:()=>{const t=e.selection.range.startNode.closest("td");if(t.length>0){return[f(t.computedCSS("background-color"))]}return[]},onSelect:(i,n)=>{e.selection.range.startNode.closest("td").css("background-color",n),t.backgroundColor=n,e.history.save()}},{name:"tableColumn",type:"dropdown",downIcon:n.get("down"),icon:n.get("tableColumn"),tooltip:e=>e.table.column(),menuType:"list",menuItems:si,menuCheck:!1,onSelect:(t,i)=>{const n=e.selection.range;"insertLeft"===i?ii(n,"left"):"insertRight"===i?ii(n,"right"):function(e){const t=e.startNode.closest("td"),i=t.closest("table"),n=t.closest("tr"),s=i.get(0),o=n.get(0),r=t.get(0),a=o.rowIndex,l=Jt(s),c=ei(l,a,r);let d=null;const h=r.cellIndex;o.cells[h+1]?d=o.cells[h+1]:o.cells[h-1]&&(d=o.cells[h-1]),v(`deleteColumn: rows ${s.rows.length}, column ${c}`);const p=function(e,t){for(let i=0;i<e.length;i++){const n=e[i][t],s=e[i+1];if(s&&n.colSpan!==s[t].colSpan)return!1}return!0}(l,c);for(let t=0;t<s.rows.length;t++){const i=s.rows[t],n=ti(l,t,c),o=i.cells[n];o.rowSpan>1&&(t+=o.rowSpan-1),o.colSpan>1&&!p?(o.colSpan-=1,1===o.colSpan&&o.removeAttribute("colSpan")):(o===r&&d&&e.shrinkBefore(b(d)),i.deleteCell(n))}0===s.rows[0].cells.length&&Qt(e)}(n),e.history.save()}},{name:"tableRow",type:"dropdown",downIcon:n.get("down"),icon:n.get("tableRow"),tooltip:e=>e.table.row(),menuType:"list",menuItems:oi,menuCheck:!1,onSelect:(t,i)=>{const n=e.selection.range;"insertAbove"===i?ni(n,"up"):"insertBelow"===i?ni(n,"down"):function(e){const t=e.startNode.closest("td"),i=t.closest("table"),n=t.closest("tr"),s=i.get(0),o=n.get(0),r=t.get(0),a=o.rowIndex;let l=Jt(s);const c=l[0].length,d=ei(l,a,r),h=s.rows[a+1]||s.rows[a-1];v(`deleteRow: rows ${s.rows.length}, target row ${a}, column ${d}`);for(let e=a-1;e>=0;e--){const t=s.rows[e].cells;for(let i=0;i<t.length;i++){const n=t[i];n.rowSpan>1&&n.rowSpan>a-e&&(n.rowSpan-=1,1===n.rowSpan&&n.removeAttribute("rowSpan"))}}const p=s.rows[a+1];if(p){let e=-1;for(let t=0;t<c;t++){const i=ti(l,a,t);if(i!==e){e=i;const n=o.cells[i];if(n.rowSpan>1){const e=ti(l,a+1,t);let i=p.insertCell(e);const s=n.cloneNode(!0);s.removeAttribute("rowSpan"),i.replaceWith(s),i=s,n.rowSpan>2&&(i.rowSpan=n.rowSpan-1)}}}}if(s.deleteRow(a),h){l=Jt(s);const t=ti(l,h.rowIndex,d),i=h.cells[t];i&&e.shrinkBefore(b(i))}0===s.rows.length&&Qt(e)}(n),e.history.save()}},{name:"tableMerge",type:"dropdown",downIcon:n.get("down"),icon:n.get("tableMerge"),tooltip:e=>e.table.merge(),menuType:"list",menuItems:ri,menuCheck:!1,onSelect:(t,i)=>{!function(e,t){const i=e.startNode.closest("td"),n=i.closest("table"),s=i.closest("tr"),o=n.get(0),r=s.get(0),a=i.get(0),l=r.rowIndex,c=Jt(o);if("left"===t||"right"===t){const i=a.cellIndex;let n,s,o;if("left"===t?(n=r.cells[i-1],s=i,o=a):(n=a,s=i+1,o=r.cells[s]),!n||!o)return;if(v(`mergeCells: row ${l}, cell ${i}, other row ${l}, other cell ${s}`),n.rowSpan!==o.rowSpan)return;const d=c[l],h=ei(c,l,n),p=ei(c,l,o);if(d[h+1]!==o&&d[p-1]!==n)return;return n.colSpan+=o.colSpan,$e(b(n),b(o)),void e.shrinkBefore(b(n))}const d=ei(c,l,a);let h,p,u,m,g,f;if("up"===t){h=-1,p=null;for(let e=r.rowIndex-1;e>=0;e--){const t=c[e];if(!t)break;const i=t[d];if(!i)break;if(p&&i!==p)break;h=e,p=i}u=r.rowIndex,m=r,g=a.cellIndex,f=a}else{h=r.rowIndex,p=a,u=-1,f=null,g=-1;for(let e=r.rowIndex+1;e<o.rows.length;e++){const t=c[e];if(!t)break;const i=t[d];if(!i)break;if(i!==f){u=e,f=i,g=f.cellIndex;break}}if(m=o.rows[u],!m)return}p&&f&&(v(`mergeCells: row ${h}, cell ${p.cellIndex}, other row ${u}, other cell ${g}`),p.colSpan===f.colSpan&&(p.rowSpan+=f.rowSpan,$e(b(p),b(f)),e.shrinkBefore(b(p))))}(e.selection.range,i),e.history.save()}},{name:"tableSplit",type:"dropdown",downIcon:n.get("down"),icon:n.get("tableSplit"),tooltip:e=>e.table.split(),menuType:"list",menuItems:ai,menuCheck:!1,onSelect:(t,i)=>{!function(e,t){const i=e.startNode.closest("td"),n=i.closest("table"),s=i.closest("tr"),o=n.get(0),r=s.get(0),a=i.get(0),l=r.rowIndex,c=a.rowSpan,d=a.colSpan;let h=Jt(o);const p=ei(h,l,a);if(v(`splitCell: row ${l}, cell ${p}, ${t}`),"topBottom"!==t)for(let e=0;e<h.length;e++){const t=o.rows[e],i=h[e],n=i[p];if(n===a){const i=h[e-1];if(!i||n!==i[p]){const i=ti(h,e,p),s=t.insertCell(i+1);s.innerHTML="<p><br /></p>",n.rowSpan>1&&(s.rowSpan=n.rowSpan),n.colSpan>2&&(s.colSpan=n.colSpan-1),n.removeAttribute("colSpan")}}else for(let e=p;e>=0;e--)if(0===e||n!==i[e]){1===d&&(n.colSpan+=1);break}}else{const e=h[l];for(let t=0;t<e.length;t++){const i=e[t];if(i===a){const e=c>1?o.rows[l+1]:o.insertRow(l+1),t=ti(h,l+1,p),i=e.insertCell(t);i.innerHTML="<p><br /></p>",a.colSpan>1&&(i.colSpan=a.colSpan),a.rowSpan>2&&(i.rowSpan=a.rowSpan-1),a.removeAttribute("rowSpan"),h=Jt(o)}else if(1===c){for(let e=l;e>=0;e--){const n=h[e];if(0===e||i!==n[t]){i.rowSpan+=1;break}}h=Jt(o)}i.colSpan>1&&(t+=i.colSpan-1)}}}(e.selection.range,i),e.history.save()}},{name:"remove",type:"button",icon:n.get("remove"),tooltip:e=>e.table.remove(),onClick:()=>{Qt(e.selection.range),e.history.save()}}];return i}const ci={start:"left",end:"right"};function di(e,t){if(e.isList){let i=Number.parseInt(e.attr("indent"),10)||0;if("increase"===t?i++:i--,i<=0)i=0;else if(i>10)return;return 0===i?e.removeAttr("indent"):e.attr("indent",i.toString(10)),void Ve([e])}let i=Number.parseInt(e.css("margin-left"),10)||0;"decrease"!==t||0!==i||""===e.css("text-indent")?("increase"===t?i+=40:i-=40,i<=0&&(i=0),0===i?e.css("margin-left",""):e.css("margin-left",`${i}px`)):e.css("text-indent","")}const hi="strong";const pi="sub";const ui="sup";const mi="code";const gi="lake-format-painter";function fi(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())}))}"function"==typeof SuppressedError&&SuppressedError;class vi{constructor(e){this.linkNode=null,this.scrollListener=()=>this.updatePosition(),this.resizeListener=()=>this.updatePosition(),this.config=e||{},this.locale=this.config.locale||ue("en-US"),this.container=b(S`
41
41
  <div class="lake-popup lake-link-popup">
42
42
  <div class="lake-row">${this.locale.link.url()}</div>
43
43
  <div class="lake-row lake-url-row">
@@ -63,7 +63,7 @@ function Ci(e,t,i){const n=document.createElement(t);return e&&(n.className=e),i
63
63
  <div class="lake-error-icon"></div>
64
64
  <div class="lake-error-name">${s.name||""}</div>
65
65
  </div>
66
- `),r=n.get("imageBroken");r&&o.find(".lake-error-icon").append(r);const a=b('<div class="lake-image" />');a.addClass(`lake-image-${s.status}`),new Se({locale:t.locale,root:a,items:[{name:"remove",icon:n.get("remove"),tooltip:t.locale.image.remove(),onClick:i=>{i.stopPropagation(),t.selection.removeBox(e),t.history.save()}}]}).render(),a.append(o),i.empty(),i.append(a)}))}function Jn(e){return fi(this,void 0,void 0,(function*(){const t=e.getEditor(),i=e.getContainer(),s=e.value,o=yield Yn(s.url);if(!i.get(0).isConnected)return;if(!o.width||!o.height)return void(yield Qn(e));s.originalWidth&&s.originalHeight||e.updateValue({originalWidth:o.width,originalHeight:o.height});let r=s.width,a=s.height;if(!r||!a){const i=t.container.innerWidth()-2;r=Math.round(o.width<i?o.width:i),a=Math.round(r*o.height/o.width),e.updateValue({width:r,height:a})}const l=o.node;l.addClass("lake-image-img"),l.attr({draggable:"false",alt:s.name});const c=b('<div class="lake-image" />');c.addClass(`lake-image-${s.status}`),c.css({width:`${r}px`,height:`${a}px`});const d=[];r>=80&&null!==Oi&&d.push({name:"view",icon:n.get("maximize"),tooltip:t.locale.image.view(),onClick:()=>function(e){const t=e.getEditor(),i=[];let s=0;const o=t.container.find('lake-box[name="image"]');o.each(((t,n)=>{const o=xe(t),r=o.value;"done"===r.status&&(i.push({id:n,src:r.originalUrl||r.url,width:r.originalWidth||r.width,height:r.originalHeight||r.height,alt:r.name}),e.node.id===o.node.id&&(s=n))}));const r=new Oi({pswpModule:jn,dataSource:i,mainClass:"lake-pswp",zoom:!1,returnFocus:!1,arrowPrevSVG:n.get("left"),arrowNextSVG:n.get("right"),closeSVG:n.get("close"),arrowPrevTitle:t.locale.image.previous(),arrowNextTitle:t.locale.image.next(),closeTitle:t.locale.image.close(),errorMsg:t.locale.image.loadingError()});r.on("uiRegister",(()=>{const e=r.pswp;e.ui.registerElement({name:"zoom-out-button",order:8,isButton:!0,title:t.locale.image.zoomOut(),html:n.get("zoomOut"),onClick:()=>{const t=e.currSlide,i=(t.zoomLevels.max-t.zoomLevels.min)/5,n=t.currZoomLevel-i;t.zoomTo(n,void 0,333)}}),e.ui.registerElement({name:"zoom-in-button",order:9,isButton:!0,title:t.locale.image.zoomIn(),html:n.get("zoomIn"),onClick:()=>{const t=e.currSlide,i=(t.zoomLevels.max-t.zoomLevels.min)/5,n=t.currZoomLevel+i;t.zoomTo(n,void 0,333)}})})),r.addFilter("thumbEl",((e,t)=>{const i=o.eq(t.id).find(".lake-image-img");return i.length>0?i.get(0):e})),r.addFilter("placeholderSrc",((e,t)=>{const i=o.eq(t.data.id).find(".lake-image-img");return i.length>0?i.attr("src"):e})),r.on("openingAnimationEnd",(()=>{e.event.emit("openfullscreen")})),r.on("destroy",(()=>{e.event.emit("closefullscreen")})),r.init(),r.loadAndOpen(s)}(e)}),t.readonly||d.push({name:"remove",icon:n.get("remove"),tooltip:t.locale.image.remove(),onClick:i=>{i.stopPropagation(),t.selection.removeBox(e),t.history.save()}}),new Se({locale:t.locale,root:c,items:d}).render(),c.append(l),i.empty(),i.append(c),i.css({width:`${r}px`,height:""});const h=function(e){const t=e.getEditor(),i=e.getContainer(),n=e.value.caption||"",s=b('<div class="lake-image-caption" />');if(s.text(n),i.append(s),""===n.trim()?Gn(e,s):Xn(e,s),t.readonly)return s.css("-webkit-user-modify","read-only"),s;s.attr("contenteditable","true"),s.attr("placeholder",t.locale.image.captionPlaceholder());const o=dt((i=>{t.selection.updateByRange(),t.isComposing||(e.updateValue("caption",i),t.history.save())}),1,{immediate:!1});return s.on("input",(()=>{const t=s.text();""===t?s.addClass("lake-placeholder"):s.removeClass("lake-placeholder");const i=s.height();e.node.find(".lake-box-strip").css("margin-bottom",`${i}px`),o(t)})),s.on("paste",(e=>{e.preventDefault();const t=e.clipboardData;if(!t)return;const i=t.getData("text/plain").trim();document.execCommand("insertText",!1,i)})),s.on("keydown",(i=>{Ce.isKeyHotkey("enter",i)&&(i.preventDefault(),t.selection.selectBox(e))})),s.on("focusout",(()=>{""===s.text().trim()&&Gn(e,s)})),s}(e);!function(e){const t=[{name:"caption",type:"button",icon:n.get("caption"),tooltip:e=>e.image.caption(),isSelected:()=>{const t=e.getContainer().find(".lake-image-caption");return t.length>0&&"none"!==t.computedCSS("display")},onClick:()=>{const t=e.getContainer().find(".lake-image-caption");""===t.text().trim()&&t.addClass("lake-placeholder"),Xn(e,t),t.focus(),e.toolbar&&e.toolbar.updateState()}},{name:"align",type:"dropdown",downIcon:n.get("down"),icon:n.get("alignLeft"),tooltip:e=>e.image.align(),menuType:"list",menuItems:[{value:"left",text:e=>e.image.alignLeft()},{value:"center",text:e=>e.image.alignCenter()},{value:"right",text:e=>e.image.alignRight()}],selectedValues:e=>{let t;for(const i of e)if(i.node.isBlock){t=i.node.computedCSS("text-align");break}return t?[Un[t]||t]:[]},onSelect:(e,t)=>{e.command.execute("align",t)}},{name:"resize",type:"dropdown",downIcon:n.get("down"),icon:n.get("resize"),tooltip:e=>e.image.resize(),menuType:"list",menuItems:[{value:"page",text:e=>e.image.pageWidth()},{value:"1.00",text:e=>e.image.originalWidth()},{value:"0.75",text:e=>e.image.imageWidth("75%")},{value:"0.50",text:e=>e.image.imageWidth("50%")},{value:"0.25",text:e=>e.image.imageWidth("25%")}],selectedValues:()=>{const{originalWidth:t,width:i}=e.value;let n="";return n=i===e.getEditor().container.innerWidth()-2?"page":(i/t).toFixed(2),[n]},onSelect:(t,i)=>{const{originalWidth:n,originalHeight:s}=e.value,o=e.getContainer(),r=o.find(".lake-image"),a=o.find(".lake-image-caption"),l=s/n;let c;c="page"===i?t.container.innerWidth()-2:Math.round(n*Number(i));const d=Math.round(l*c);r.css({width:`${c}px`,height:`${d}px`}),o.css("width",`${c}px`),Kn(e,a),e.updateValue({width:c,height:d}),t.history.save()}},{name:"open",type:"button",icon:n.get("open"),tooltip:e=>e.image.open(),onClick:()=>{window.open(e.value.url)}}];e.setToolbar(t)}(e),new Be({root:c,target:c,onResize:t=>{i.css("width",`${t}px`),Kn(e,h)},onStop:(i,n)=>{e.updateValue({width:i,height:n}),t.history.save()}}).render()}))}var es={type:"inline",name:"image",render:e=>{const t=e.getEditor(),i=e.value;if(t.readonly&&["uploading","loading","error"].indexOf(i.status)>=0)return void e.node.hide();const s=e.getContainer();if(i.width&&i.height&&0===s.find(".lake-progress").length){s.css({width:`${i.width}px`,height:`${i.height}px`}),s.empty();const e=b('<div class="lake-image-placeholder" />');s.append(e);const t=n.get("image");t&&e.append(t)}if(0===s.first().length&&s.append("<div />"),"loading"===i.status)return;let o;o="uploading"===i.status?function(e){return fi(this,void 0,void 0,(function*(){const t=e.getEditor(),i=e.getContainer(),s=e.value,o=yield Yn(s.url);if(!i.get(0).isConnected)return;if(!o.width||!o.height)return void(yield Qn(e));const r=t.container.innerWidth()-2,a=o.width<r?o.width:r,l=Math.round(a*o.height/o.width);e.updateValue({width:a,height:l,originalWidth:o.width,originalHeight:o.height}),i.css({width:`${a}px`,height:`${l}px`});const c=b(S`
66
+ `),r=n.get("imageBroken");r&&o.find(".lake-error-icon").append(r);const a=b('<div class="lake-image" />');a.addClass(`lake-image-${s.status}`),new Se({locale:t.locale,root:a,items:[{name:"remove",icon:n.get("remove"),tooltip:t.locale.image.remove(),onClick:i=>{i.stopPropagation(),t.selection.removeBox(e),t.history.save()}}]}).render(),a.append(o),i.empty(),i.append(a)}))}function Jn(e){return fi(this,void 0,void 0,(function*(){const t=e.getEditor(),i=e.getContainer(),s=e.value,o=yield Yn(s.url);if(!i.get(0).isConnected)return;if(!o.width||!o.height)return void(yield Qn(e));s.originalWidth&&s.originalHeight||e.updateValue({originalWidth:o.width,originalHeight:o.height});let r=s.width,a=s.height;if(!r||!a){const i=t.container.innerWidth()-2;r=Math.round(o.width<i?o.width:i),a=Math.round(r*o.height/o.width),e.updateValue({width:r,height:a})}const l=o.node;l.addClass("lake-image-img"),l.attr({draggable:"false",alt:s.name});const c=b('<div class="lake-image" />');c.addClass(`lake-image-${s.status}`),c.css({width:`${r}px`,height:`${a}px`});const d=[];r>=80&&null!==Oi&&d.push({name:"view",icon:n.get("maximize"),tooltip:t.locale.image.view(),onClick:()=>function(e){const t=e.getEditor(),i=[];let s=0;const o=t.container.find('lake-box[name="image"]');o.each(((t,n)=>{const o=xe(t),r=o.value;"done"===r.status&&(i.push({id:n,src:r.originalUrl||r.url,width:r.originalWidth||r.width,height:r.originalHeight||r.height,alt:r.name}),e.node.id===o.node.id&&(s=n))}));const r=new Oi({pswpModule:jn,dataSource:i,mainClass:"lake-pswp",zoom:!1,returnFocus:!1,arrowPrevSVG:n.get("left"),arrowNextSVG:n.get("right"),closeSVG:n.get("close"),arrowPrevTitle:t.locale.image.previous(),arrowNextTitle:t.locale.image.next(),closeTitle:t.locale.image.close(),errorMsg:t.locale.image.loadingError()});r.on("uiRegister",(()=>{const e=r.pswp;e.ui.registerElement({name:"zoom-out-button",order:8,isButton:!0,title:t.locale.image.zoomOut(),html:n.get("zoomOut"),onClick:()=>{const t=e.currSlide,i=(t.zoomLevels.max-t.zoomLevels.min)/5,n=t.currZoomLevel-i;t.zoomTo(n,void 0,333)}}),e.ui.registerElement({name:"zoom-in-button",order:9,isButton:!0,title:t.locale.image.zoomIn(),html:n.get("zoomIn"),onClick:()=>{const t=e.currSlide,i=(t.zoomLevels.max-t.zoomLevels.min)/5,n=t.currZoomLevel+i;t.zoomTo(n,void 0,333)}})})),r.addFilter("thumbEl",((e,t)=>{const i=o.eq(t.id).find(".lake-image-img");return i.length>0?i.get(0):e})),r.addFilter("placeholderSrc",((e,t)=>{const i=o.eq(t.data.id).find(".lake-image-img");return i.length>0?i.attr("src"):e})),r.on("openingAnimationEnd",(()=>{e.event.emit("openfullscreen")})),r.on("destroy",(()=>{e.event.emit("closefullscreen")})),r.init(),r.loadAndOpen(s)}(e)}),t.readonly||d.push({name:"remove",icon:n.get("remove"),tooltip:t.locale.image.remove(),onClick:i=>{i.stopPropagation(),t.selection.removeBox(e),t.history.save()}}),new Se({locale:t.locale,root:c,items:d}).render(),c.append(l),i.empty(),i.append(c),i.css({width:`${r}px`,height:""});const h=function(e){const t=e.getEditor(),i=e.getContainer(),n=e.value.caption||"",s=b('<div class="lake-image-caption" />');if(s.text(n),i.append(s),""===n.trim()?Gn(e,s):Xn(e,s),t.readonly)return s.css("-webkit-user-modify","read-only"),s;s.attr("contenteditable","true"),s.attr("placeholder",t.locale.image.captionPlaceholder());const o=dt((i=>{t.selection.updateByRange(),t.isComposing||(e.updateValue("caption",i),t.history.save())}),1,{immediate:!1});return s.on("input",(()=>{const t=s.text();""===t?s.addClass("lake-placeholder"):s.removeClass("lake-placeholder");const i=s.height();e.node.find(".lake-box-strip").css("margin-bottom",`${i}px`),o(t)})),s.on("paste",(e=>{e.preventDefault();const t=e.clipboardData;if(!t)return;const i=t.getData("text/plain").trim();document.execCommand("insertText",!1,i)})),s.on("keydown",(i=>{Ce.isKeyHotkey("enter",i)&&(i.preventDefault(),t.selection.selectBox(e))})),s.on("focusout",(()=>{""===s.text().trim()&&Gn(e,s)})),s}(e);!function(e){const t=[{name:"caption",type:"button",icon:n.get("caption"),tooltip:e=>e.image.caption(),isSelected:()=>{const t=e.getContainer().find(".lake-image-caption");return t.length>0&&"none"!==t.computedCSS("display")},onClick:()=>{const t=e.getContainer().find(".lake-image-caption");""===t.text().trim()&&t.addClass("lake-placeholder"),Xn(e,t),t.focus(),e.toolbar&&e.toolbar.updateState()}},{name:"align",type:"dropdown",downIcon:n.get("down"),icon:n.get("alignLeft"),tooltip:e=>e.image.align(),menuType:"list",menuItems:[{value:"left",text:e=>e.image.alignLeft()},{value:"center",text:e=>e.image.alignCenter()},{value:"right",text:e=>e.image.alignRight()}],selectedValues:e=>{let t;for(const i of e)if(i.node.isBlock){t=i.node.computedCSS("text-align");break}return t?[Un[t]||t]:[]},onSelect:(e,t)=>{e.command.execute("align",t)}},{name:"resize",type:"dropdown",downIcon:n.get("down"),icon:n.get("resize"),tooltip:e=>e.image.resize(),menuType:"list",menuItems:[{value:"page",text:e=>e.image.pageWidth()},{value:"1.00",text:e=>e.image.originalWidth()},{value:"0.75",text:e=>e.image.imageWidth("75%")},{value:"0.50",text:e=>e.image.imageWidth("50%")},{value:"0.25",text:e=>e.image.imageWidth("25%")}],selectedValues:()=>{const{originalWidth:t,width:i}=e.value;let n="";return n=i===e.getEditor().container.innerWidth()-2?"page":(i/t).toFixed(2),[n]},onSelect:(t,i)=>{const{originalWidth:n,originalHeight:s}=e.value,o=e.getContainer(),r=o.find(".lake-image"),a=o.find(".lake-image-caption"),l=s/n;let c;c="page"===i?t.container.innerWidth()-2:Math.round(n*Number(i));const d=Math.round(l*c);r.css({width:`${c}px`,height:`${d}px`}),o.css("width",`${c}px`),Kn(e,a),e.updateValue({width:c,height:d}),t.history.save()}},{name:"open",type:"button",icon:n.get("open"),tooltip:e=>e.image.open(),onClick:()=>{e.getEditor().config.downloadFile("image",e.value.url)}}];e.setToolbar(t)}(e),new Be({root:c,target:c,onResize:t=>{i.css("width",`${t}px`),Kn(e,h)},onStop:(i,n)=>{e.updateValue({width:i,height:n}),t.history.save()}}).render()}))}var es={type:"inline",name:"image",render:e=>{const t=e.getEditor(),i=e.value;if(t.readonly&&["uploading","loading","error"].indexOf(i.status)>=0)return void e.node.hide();const s=e.getContainer();if(i.width&&i.height&&0===s.find(".lake-progress").length){s.css({width:`${i.width}px`,height:`${i.height}px`}),s.empty();const e=b('<div class="lake-image-placeholder" />');s.append(e);const t=n.get("image");t&&e.append(t)}if(0===s.first().length&&s.append("<div />"),"loading"===i.status)return;let o;o="uploading"===i.status?function(e){return fi(this,void 0,void 0,(function*(){const t=e.getEditor(),i=e.getContainer(),s=e.value,o=yield Yn(s.url);if(!i.get(0).isConnected)return;if(!o.width||!o.height)return void(yield Qn(e));const r=t.container.innerWidth()-2,a=o.width<r?o.width:r,l=Math.round(a*o.height/o.width);e.updateValue({width:a,height:l,originalWidth:o.width,originalHeight:o.height}),i.css({width:`${a}px`,height:`${l}px`});const c=b(S`
67
67
  <div class="lake-progress">
68
68
  <div class="lake-percent">${Math.round(s.percent||0)} %</div>
69
69
  </div>
@@ -76,9 +76,9 @@ function Ci(e,t,i){const n=document.createElement(t);return e&&(n.className=e),i
76
76
  <div class="lake-progress">
77
77
  <div class="lake-percent">${Math.round(i.percent||0)} %</div>
78
78
  </div>
79
- `),t=n.get("circleNotch");t&&e.prepend(t),o.replaceWith(e)}else{const e="error"===i.status?n.get("warningCircle"):n.get("file");e&&o.append(e)}e.append(s)}))}var ss={type:"inline",name:"file",render:e=>{const t=e.getEditor(),i=e.value;if(t.readonly&&["uploading","error"].indexOf(i.status)>=0)return void e.node.hide();const s=e.getContainer(),o=b('<div class="lake-file" />');o.addClass(`lake-file-${i.status}`),ns(o,e),s.empty(),s.append(o),t.readonly?o.on("click",(()=>{window.open(i.url)})):(o.on("click",(()=>{t.selection.selectBox(e)})),function(e){let t=[{name:"download",type:"button",icon:n.get("download"),tooltip:e=>e.file.download(),onClick:()=>{window.open(e.value.url)}},{name:"remove",type:"button",icon:n.get("remove"),tooltip:e=>e.file.remove(),onClick:t=>{t.selection.removeBox(e),t.history.save()}}];"done"!==e.value.status&&(t=t.filter((e=>"remove"===e.name))),e.setToolbar(t)}(e))}},os={type:"inline",name:"emoji",render:e=>{const t=e.getEditor(),i=e.value,n=e.getContainer(),s=b(S`
79
+ `),t=n.get("circleNotch");t&&e.prepend(t),o.replaceWith(e)}else{const e="error"===i.status?n.get("warningCircle"):n.get("file");e&&o.append(e)}e.append(s)}))}var ss={type:"inline",name:"file",render:e=>{const t=e.getEditor(),i=e.value;if(t.readonly&&["uploading","error"].indexOf(i.status)>=0)return void e.node.hide();const s=e.getContainer(),o=b('<div class="lake-file" />');o.addClass(`lake-file-${i.status}`),ns(o,e),s.empty(),s.append(o),t.readonly?o.on("click",(()=>{t.config.downloadFile("file",i.url)})):(o.on("click",(()=>{t.selection.selectBox(e)})),function(e){let t=[{name:"download",type:"button",icon:n.get("download"),tooltip:e=>e.file.download(),onClick:()=>{e.getEditor().config.downloadFile("file",e.value.url)}},{name:"remove",type:"button",icon:n.get("remove"),tooltip:e=>e.file.remove(),onClick:t=>{t.selection.removeBox(e),t.history.save()}}];"done"!==e.value.status&&(t=t.filter((e=>"remove"===e.name))),e.setToolbar(t)}(e))}},os={type:"inline",name:"emoji",render:e=>{const t=e.getEditor(),i=e.value,n=e.getContainer(),s=b(S`
80
80
  <div class="lake-emoji"><img src="${i.url}" title="${i.title}" /></div>
81
- `);n.empty(),n.append(s),s.on("click",(()=>{t.selection.selectBox(e)}))}};const rs=String.raw`\sqrt{x}`;var as={type:"inline",name:"equation",render:e=>{const t=e.getEditor(),i=b('<div class="lake-equation" />'),s=e.getContainer();s.empty(),s.append(i);if(!window.katex)return void function(e){const t=e.getEditor();if(t.readonly)return void e.node.hide();const i=(e.value.code||"").trim(),n=e.getContainer().find(".lake-equation");n.addClass("lake-equation-error"),n.text(i),n.on("click",(()=>{t.selection.selectBox(e)})),t.config.onMessage("warning",`\n Box "${e.name}" (id: ${e.node.id}) failed to display because window.katex was not found.\n Please check if the "katex" library is added to this page.\n `.trim())}(e);const o=t.config.equation,r=(e.value.code||"").trim(),a=b('<div class="lake-equation-view" />');i.append(a),a.html(window.katex.renderToString(r||rs,{throwOnError:!1})),a.on("click",(()=>{t.selection.selectBox(e)}));const l=b(S`
81
+ `);n.empty(),n.append(s),s.on("click",(()=>{t.selection.selectBox(e)}))}};const rs=String.raw`\sqrt{x}`;var as={type:"inline",name:"equation",render:e=>{const t=e.getEditor(),i=b('<div class="lake-equation" />'),s=e.getContainer();s.empty(),s.append(i);if(!window.katex)return void function(e){const t=e.getEditor();if(t.readonly)return void e.node.hide();const i=(e.value.code||"").trim(),n=e.getContainer().find(".lake-equation");n.addClass("lake-equation-error"),n.text(i),n.on("click",(()=>{t.selection.selectBox(e)})),t.config.showMessage("warning",`\n Box "${e.name}" (id: ${e.node.id}) failed to display because window.katex was not found.\n Please check if the "katex" library is added to this page.\n `.trim())}(e);const o=t.config.equation,r=(e.value.code||"").trim(),a=b('<div class="lake-equation-view" />');i.append(a),a.html(window.katex.renderToString(r||rs,{throwOnError:!1})),a.on("click",(()=>{t.selection.selectBox(e)}));const l=b(S`
82
82
  <div class="lake-equation-form">
83
83
  <div class="lake-row">
84
84
  <textarea name="code" placeholder="${t.locale.equation.placeholder()}"></textarea>
@@ -101,11 +101,11 @@ function Ci(e,t,i){const n=document.createElement(t);return e&&(n.className=e),i
101
101
  <div class="lake-slash-description">${n}</div>
102
102
  </div>
103
103
  </li>
104
- `),o=t.icon;if(o&&s.find(".lake-slash-icon").append(o),"upload"===t.type){s.append('<input type="file" />');const e=s.find('input[type="file"]'),i=e.get(0);t.accept&&e.attr("accept",t.accept),!0===t.multiple&&e.attr("multiple","true"),e.on("click",(e=>e.stopPropagation())),e.on("change",(i=>this.onSelect(i,t,e))),s.on("click",(()=>i.click()))}else s.on("click",(e=>this.onSelect(e,t)));return s}search(e){const t=ue("en-US");e=e.toLowerCase();const i=[];for(const n of this.items){const s=this.getItem(n);let o="string"==typeof s.title?s.title:s.title(this.locale);o=o.toLowerCase();let r="string"==typeof s.title?s.title:s.title(t);r=r.toLowerCase(),(o.indexOf(e)>=0||o.replace(/\s+/g,"").indexOf(e)>=0||r.indexOf(e)>=0||r.replace(/\s+/g,"").indexOf(e)>=0)&&i.push("string"==typeof n?s.name:n)}return i}}const Ps=["heading1","heading2","heading3","heading4","heading5","heading6","paragraph","blockQuote","numberedList","bulletedList","checklist","table","infoAlert","tipAlert","warningAlert","dangerAlert","hr"];function Hs(e){let t=e.text().trim();return t=t.replace(/[\u200B\u2060]/g,""),/^\//.test(t)?t.substring(1):null}return Rt.box.add(wi),Rt.box.add(xi),Rt.box.add(os),Rt.box.add(as),Rt.box.add(es),Rt.box.add(is),Rt.box.add(ss),Rt.box.add(ps),Rt.box.add(fs),Rt.plugin.add("copy",(e=>{e.event.on("copy",(t=>{const i=e.selection.range;if(i.isInsideBox)return;if(!i.isCollapsed)return void i.adjust();const n=i.commonAncestor.closest("lake-box");if(0===n.length)return;if(i.isBoxStart||i.isBoxEnd)return;t.preventDefault();const s=t.clipboardData;if(!s)return;const o=xe(n).getHTML();s.setData("text/html",o)}))})),Rt.plugin.add("cut",(e=>{e.readonly||e.event.on("cut",(t=>{const i=t.clipboardData;if(!i)return;const n=e.selection.range;if(n.isInsideBox)return;if(!n.isCollapsed){t.preventDefault();const n=e.selection.range.cloneContents(),s=b("<div />");return s.append(n),i.setData("text/html",s.html()),e.selection.deleteContents(),void e.history.save()}const s=n.commonAncestor.closest("lake-box");if(0===s.length)return;if(n.isBoxStart||n.isBoxEnd)return;t.preventDefault();const o=xe(s).getHTML();i.setData("text/html",o),e.selection.removeBox(),e.history.save()}))})),Rt.plugin.add("paste",(e=>{e.readonly||e.event.on("paste",(t=>{if(e.selection.range.isInsideBox)return;t.preventDefault();const i=t.clipboardData;if(!i)return;if(e.selection.deleteContents(),i.files.length>0){for(const t of i.files){const i=0===t.type.indexOf("image/")?"image":"file",{requestTypes:n,requestMethod:s,requestAction:o,requestFieldName:r,requestWithCredentials:a,requestHeaders:l,transformResponse:c}=e.config[i];n.indexOf(t.type)>=0&&K({selection:e.selection,boxName:i,file:t,requestTypes:n,requestMethod:s,requestAction:o,requestFieldName:r,requestWithCredentials:a,requestHeaders:l,transformResponse:c,onError:t=>e.config.onMessage("error",t),onSuccess:()=>e.history.save()})}return}const n=i.types;if(1===n.length&&"text/plain"===n[0]){const t=i.getData("text/plain"),n=new Me(t).getFragment();return e.event.emit("beforepaste",n),void jt(e,n)}const s=ut(i.getData("text/html")),o=function(e){e.div=e.p;for(const t of Object.keys(e)){const i=e[t];"string"!=typeof i&&(delete i.id,delete i.class)}return e}(e.config.contentRules),r=new Ie(s,o).getFragment();e.event.emit("beforepaste",r),function(e){let t=new x(e.firstChild);for(;t.length>0;){const e=t.next();t.isBlock&&Wt(t),t=e}let i=[];for(t=new x(e.firstChild);t.length>0;){const e=t.next();t.isMark||t.isText||t.isBookmark||t.isInlineBox?i.push(t):(We(i),i=[]),t=e}We(i)}(r),jt(e,r)}))})),Rt.plugin.add("drop",(e=>{if(e.readonly)return;let t=null,i=null,n=null,s="bottom";e.container.on("dragstart",(n=>{t=null;const s=n,o=s.dataTransfer;if(!o)return;o.effectAllowed="move";const r=b(s.target).closest("lake-box");if(0===r.length)return void s.preventDefault();"inline"!==xe(r).type?(t=r,i=b(S`
104
+ `),o=t.icon;if(o&&s.find(".lake-slash-icon").append(o),"upload"===t.type){s.append('<input type="file" />');const e=s.find('input[type="file"]'),i=e.get(0);t.accept&&e.attr("accept",t.accept),!0===t.multiple&&e.attr("multiple","true"),e.on("click",(e=>e.stopPropagation())),e.on("change",(i=>this.onSelect(i,t,e))),s.on("click",(()=>i.click()))}else s.on("click",(e=>this.onSelect(e,t)));return s}search(e){const t=ue("en-US");e=e.toLowerCase();const i=[];for(const n of this.items){const s=this.getItem(n);let o="string"==typeof s.title?s.title:s.title(this.locale);o=o.toLowerCase();let r="string"==typeof s.title?s.title:s.title(t);r=r.toLowerCase(),(o.indexOf(e)>=0||o.replace(/\s+/g,"").indexOf(e)>=0||r.indexOf(e)>=0||r.replace(/\s+/g,"").indexOf(e)>=0)&&i.push("string"==typeof n?s.name:n)}return i}}const Ps=["heading1","heading2","heading3","heading4","heading5","heading6","paragraph","blockQuote","numberedList","bulletedList","checklist","table","infoAlert","tipAlert","warningAlert","dangerAlert","hr"];function Hs(e){let t=e.text().trim();return t=t.replace(/[\u200B\u2060]/g,""),/^\//.test(t)?t.substring(1):null}return Rt.box.add(wi),Rt.box.add(xi),Rt.box.add(os),Rt.box.add(as),Rt.box.add(es),Rt.box.add(is),Rt.box.add(ss),Rt.box.add(ps),Rt.box.add(fs),Rt.plugin.add("copy",(e=>{e.event.on("copy",(t=>{const i=e.selection.range;if(i.isInsideBox)return;if(!i.isCollapsed)return void i.adjust();const n=i.commonAncestor.closest("lake-box");if(0===n.length)return;if(i.isBoxStart||i.isBoxEnd)return;t.preventDefault();const s=t.clipboardData;if(!s)return;const o=xe(n).getHTML();s.setData("text/html",o)}))})),Rt.plugin.add("cut",(e=>{e.readonly||e.event.on("cut",(t=>{const i=t.clipboardData;if(!i)return;const n=e.selection.range;if(n.isInsideBox)return;if(!n.isCollapsed){t.preventDefault();const n=e.selection.range.cloneContents(),s=b("<div />");return s.append(n),i.setData("text/html",s.html()),e.selection.deleteContents(),void e.history.save()}const s=n.commonAncestor.closest("lake-box");if(0===s.length)return;if(n.isBoxStart||n.isBoxEnd)return;t.preventDefault();const o=xe(s).getHTML();i.setData("text/html",o),e.selection.removeBox(),e.history.save()}))})),Rt.plugin.add("paste",(e=>{e.readonly||e.event.on("paste",(t=>{if(e.selection.range.isInsideBox)return;t.preventDefault();const i=t.clipboardData;if(!i)return;if(e.selection.deleteContents(),i.files.length>0){for(const t of i.files){const i=0===t.type.indexOf("image/")?"image":"file",{requestTypes:n,requestMethod:s,requestAction:o,requestFieldName:r,requestWithCredentials:a,requestHeaders:l,transformResponse:c}=e.config[i];n.indexOf(t.type)>=0&&K({selection:e.selection,boxName:i,file:t,requestTypes:n,requestMethod:s,requestAction:o,requestFieldName:r,requestWithCredentials:a,requestHeaders:l,transformResponse:c,onError:t=>e.config.showMessage("error",t),onSuccess:()=>e.history.save()})}return}const n=i.types;if(1===n.length&&"text/plain"===n[0]){const t=i.getData("text/plain"),n=new Me(t).getFragment();return e.event.emit("beforepaste",n),void jt(e,n)}const s=ut(i.getData("text/html")),o=function(e){e.div=e.p;for(const t of Object.keys(e)){const i=e[t];"string"!=typeof i&&(delete i.id,delete i.class)}return e}(e.config.contentRules),r=new Ie(s,o).getFragment();e.event.emit("beforepaste",r),function(e){let t=new x(e.firstChild);for(;t.length>0;){const e=t.next();t.isBlock&&Wt(t),t=e}let i=[];for(t=new x(e.firstChild);t.length>0;){const e=t.next();t.isMark||t.isText||t.isBookmark||t.isInlineBox?i.push(t):(We(i),i=[]),t=e}We(i)}(r),jt(e,r)}))})),Rt.plugin.add("drop",(e=>{if(e.readonly)return;let t=null,i=null,n=null,s="bottom";e.container.on("dragstart",(n=>{t=null;const s=n,o=s.dataTransfer;if(!o)return;o.effectAllowed="move";const r=b(s.target).closest("lake-box");if(0===r.length)return void s.preventDefault();"inline"!==xe(r).type?(t=r,i=b(S`
105
105
  <div class="lake-drop-indication">
106
106
  <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="#000000" viewBox="0 0 256 256">
107
107
  <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>
108
108
  </svg>
109
109
  </div>
110
- `),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=b(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+Number.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+Number.parseInt(n.computedCSS("margin-bottom"),10)/2):(s="top",p=d.y-c.y-Number.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=xe(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()}}))})),Rt.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"))})))})),Rt.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)})),Rt.plugin.add("selectAll",(e=>{e.readonly||e.command.add("selectAll",{execute:()=>{const t=e.selection.range;t.selectNodeContents(e.container),t.shrink()}})})),Rt.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()}})})),Rt.plugin.add("blockQuote",(e=>{e.readonly||e.command.add("blockQuote",{isSelected:e=>!!e.find((e=>"blockquote"===e.name)),execute:t=>{t&&Ut.indexOf(t)>=0?e.selection.setBlocks(S`<blockquote type="${t}" />`):e.selection.setBlocks("<blockquote />"),e.history.save()}})})),Rt.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&&Kt(e),"bulleted"===t&&Gt(e),"checklist"===t&&Yt(e,i)):o?("numbered"===t&&Xt(e),"bulleted"===t&&Kt(e),"checklist"===t&&Yt(e,i)):r?("numbered"===t&&Xt(e),"bulleted"===t&&Gt(e),"checklist"===t&&Kt(e)):("numbered"===t&&Xt(e),"bulleted"===t&&Gt(e),"checklist"===t&&Yt(e,i)),e.history.save()}}),e.container.on("click",(t=>{const i=t;if(!i.target)return;const n=b(i.target);"li"===n.name&&""!==n.attr("value")&&i.offsetX<=18&&(n.attr("value",("true"!==n.attr("value")).toString()),e.history.save())})))})),Rt.plugin.add("table",(e=>{if(e.readonly)return;const t={backgroundColor:""};let i=null,n=null;return e.event.on("statechange",(()=>{e.container.find("table").removeClass("lake-table-focused"),e.container.find("td").removeClass("lake-td-focused"),i&&i.updateState();const s=e.selection.range.commonAncestor.closest("td"),o=s.closest("table");if(n&&n.get(0)===o.get(0))return o.addClass("lake-table-focused"),void s.addClass("lake-td-focused");if(n=o,i&&i.unmount(),o.length>0){o.addClass("lake-table-focused"),s.addClass("lake-td-focused");const n=li(e,t);i=new we({target:o,items:n}),i.render()}})),e.command.add("table",{execute:()=>{!function(e,t,i){let n="<table>";for(let e=0;e<t;e++){n+="<tr>";for(let e=0;e<i;e++)n+="<td><p><br /></p></td>";n+="</tr>"}n+="</table>";const s=b(n);Ge(e,s),e.shrinkBefore(s),v(`insertTable: table ${s.id}`)}(e.selection.range,3,2),e.history.save()}}),()=>{i&&i.unmount()}})),Rt.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?[ci[t]||t]:[]},execute:t=>{e.selection.setBlocks({"text-align":t}),e.history.save()}})})),Rt.plugin.add("indent",(e=>{e.readonly||e.command.add("indent",{execute:t=>{const i=e.selection.range.getBlocks();for(const e of i)di(e,t);e.history.save()}})})),Rt.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===hi)),execute:()=>{e.command.isSelected("bold")?e.selection.removeMark(`<${hi} />`):e.selection.addMark(`<${hi} />`),e.history.save()}}),e.keystroke.setKeydown("mod+b",(t=>{t.preventDefault(),e.command.execute("bold")})))})),Rt.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")})))})),Rt.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")})))})),Rt.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")})))})),Rt.plugin.add("subscript",(e=>{e.readonly||e.command.add("subscript",{isSelected:e=>!!e.find((e=>e.name===pi)),execute:()=>{e.command.isSelected("subscript")?e.selection.removeMark(`<${pi} />`):e.selection.addMark(`<${pi} />`),e.history.save()}})})),Rt.plugin.add("superscript",(e=>{e.readonly||e.command.add("superscript",{isSelected:e=>!!e.find((e=>e.name===ui)),execute:()=>{e.command.isSelected("superscript")?e.selection.removeMark(`<${ui} />`):e.selection.addMark(`<${ui} />`),e.history.save()}})})),Rt.plugin.add("code",(e=>{e.readonly||e.command.add("code",{isSelected:e=>!!e.find((e=>e.name===mi)),execute:()=>{e.command.isSelected("code")?e.selection.removeMark(`<${mi} />`):e.selection.addMark(`<${mi} />`),e.history.save()}})})),Rt.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()}})})),Rt.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()}})})),Rt.plugin.add("fontColor",(e=>{e.readonly||e.command.add("fontColor",{selectedValues:e=>{for(const t of e)if("span"===t.name){return[f(t.node.computedCSS("color"))]}return[]},execute:t=>{e.selection.addMark(`<span style="color: ${t};" />`),e.history.save()}})})),Rt.plugin.add("highlight",(e=>{e.readonly||e.command.add("highlight",{selectedValues:e=>{for(const t of e)if("span"===t.name){return[f(t.node.computedCSS("background-color"))]}return[]},execute:t=>{e.selection.addMark(`<span style="background-color: ${t};" />`),e.history.save()}})})),Rt.plugin.add("removeFormat",(e=>{e.readonly||e.command.add("removeFormat",{execute:()=>{e.selection.removeMark(),e.history.save()}})})),Rt.plugin.add("formatPainter",(e=>{if(e.readonly)return;let t=[];e.command.add("formatPainter",{execute:()=>{e.container.addClass(gi);const i=e.selection.getActiveItems();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(gi),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(gi),t=[])}))})),Rt.plugin.add("link",(e=>{if(e.readonly)return;const t=new vi({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=function(e,t){if(e.commonAncestor.isOutside)return null;const i=b(t);if(e.isCollapsed){let t=e.commonAncestor.closest("a");return 0===t.length?(t=i.clone(!0),Fe(e,t),t):(""!==i.attr("href")&&t.attr({href:i.attr("href")}),t)}Qe(e);const n=He(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(),Ze(e,n),s}(e.selection.range,`<a href="">${e.locale.link.newLink()}</a>`);i&&(e.history.save(),t.show(i))}}),()=>t.unmount()})),Rt.plugin.add("hr",(e=>{e.readonly||(e.event.on("beforepaste",(e=>{new Te(e).find("hr").each((e=>{const t=b(e),i=xe("hr");t.replaceWith(i.node)}))})),e.command.add("hr",{execute:()=>{e.selection.insertBox("hr"),e.history.save()}}))})),Rt.plugin.add("codeBlock",(e=>{window.LakeCodeMirror&&(e.setPluginConfig("codeBlock",{langList:bi,defaultLang:"text",colors:ki}),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")}}))})),Rt.plugin.add("image",(e=>{e.setPluginConfig("image",{requestMethod:"POST",requestTypes:["image/gif","image/jpeg","image/png","image/svg+xml","image/webp"]}),e.readonly||(e.event.on("beforepaste",(e=>{new Te(e).find("img").each((e=>{const t=b(e),i=xe("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()}}))})),Rt.plugin.add("video",(e=>{e.readonly||e.command.add("video",{execute:t=>{const i=e.selection.insertBox("video",t);if(e.history.save(),i){const e=i.getContainer().find('input[name="url"]');e.length>0&&e.focus()}}})})),Rt.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","image/webp","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()}})})),Rt.plugin.add("emoji",(e=>{e.readonly||e.command.add("emoji",{execute:t=>{e.selection.insertBox("emoji",t),e.history.save()}})})),Rt.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()}}))})),Rt.plugin.add("specialCharacter",(e=>{e.readonly||e.command.add("specialCharacter",{execute:t=>{e.selection.insertContents(document.createTextNode(t)),e.history.save()}})})),Rt.plugin.add("mention",(e=>{if(e.setPluginConfig("mention",{requestMethod:"GET",items:[],getProfileUrl:e=>`/${e.name}`}),e.readonly)return;let t=null;const i=(i,n)=>{t&&t.hide(),e.focus();const s=e.selection.range.getCharacterRange("@");s&&s.get().deleteContents(),e.selection.insertBox("mention",n),e.history.save()},n=()=>{e.popup=t},s=()=>{e.popup=null},o=()=>{const o=e.selection.range;if(!o.isCollapsed)return;const r=o.getCharacterRange("@");if(null===r)return;const a=us(o);if(null!==a)if(t)t.show(r,a);else{const{requestAction:o,items:l}=e.config.mention;if(o){const{requestMethod:l,requestWithCredentials:c,requestHeaders:d,transformResponse:h}=e.config.mention;U({onSuccess:e=>{h&&(e=h(e)),e.data&&(t=new hs({items:e.data,onSelect:i,onShow:n,onHide:s}),t.show(r,a))},action:o,method:l,withCredentials:c,headers:d})}else t=new hs({items:l,onSelect:i,onShow:n,onHide:s}),t.show(r,a)}};return e.container.on("keyup",(i=>{if(e.isComposing)return;const n=i;if(Ce.isKeyHotkey(["down","up","enter"],n))return;if(!t||!t.visible){if("@"===n.key)return void o();if(!Ce.isKeyHotkey(["backspace","delete"],n))return;o()}const s=us(e.selection.range);null!==s?t&&t.update(s):t&&t.hide()})),()=>{t&&t.unmount()}})),Rt.plugin.add("twitter",(e=>{e.readonly||e.command.add("twitter",{execute:t=>{const i=e.selection.insertBox("twitter",t);if(e.history.save(),i){const e=i.getContainer().find('input[name="url"]');e.length>0&&e.focus()}}})})),Rt.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 ys){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 xs){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 ks(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 bs){const o=s.re.exec(n);if(null!==o){const n=s.getParameters(o),r=n.shift();return!!e.command.has(r)&&(t.empty(),ks(t),i.range.shrinkAfter(t),e.command.execute(r,...n),!0)}}return!1}(e,n)?(t.preventDefault(),t.stopImmediatePropagation(),!1):void 0})))})),Rt.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 Ss(e),void e.history.save();if(i.isCollapsed){const t=i.getPrevNode(),n=i.getNextNode();if("table"===t.name||"table"===n.name){const t=b("<p><br /></p>");return e.selection.insertContents(t),i.shrinkBefore(t),void e.history.save()}}if(i.adjust(),i.isInoperative)return;if(i.isBox)return Ss(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();Cs(e,n),e.history.save()}))})),Rt.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 As(e),void e.history.save();if(i.adjust(),!i.isInoperative){if(i.isBox)return As(e),void e.history.save();Bs(e),e.history.save()}}}))})),Rt.plugin.add("backspaceKey",(e=>{e.readonly||e.keystroke.setKeydown("backspace",(t=>{const i=e.selection.range;if(i.isInsideBox){const n=xe(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(),_s(e,i),e.history.save()))}if(s.isBlock)return s.isEmpty?(t.preventDefault(),s.remove(),Ve(i.getBlocks()),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();if(i.isCollapsed){const n=i.getPrevNode();if("table"===n.name){t.preventDefault();const s=b("<p><br /></p>");return n.replaceWith(s),i.shrinkBefore(s),void e.history.save()}const s=i.getNextNode();if(n.length>0&&"table"===s.name)return t.preventDefault(),i.shrinkAfter(n),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=ze(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 di(n,"decrease"),void e.history.save();if(n.isList||"blockquote"===n.name)return e.selection.setBlocks("<p />"),void e.history.save();_s(e,n),e.history.save()}}))})),Rt.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(),Ls(e,i),e.history.save()))}if(s.isBlock)return s.isEmpty?(t.preventDefault(),s.remove(),Ve(i.getBlocks()),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();if(i.isCollapsed){const n=i.getNextNode();if("table"===n.name){t.preventDefault();const s=b("<p><br /></p>");return n.replaceWith(s),i.shrinkBefore(s),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]),Ls(e,n),e.history.save()}}))})),Rt.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")?di(e,"increase"):e.css("text-indent","2em");e.history.save()}))})),Rt.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()}})))})),Rt.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())}))})),Rt.plugin.add("slash",(e=>{if(e.setPluginConfig("slash",{items:Ps}),e.readonly)return;const t=new Ms({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(),ze(i),t.shrinkBefore(i)}(e),"upload"===n.type){if(!s)return;const{requestTypes:t,requestMethod:o,requestAction:r,requestFieldName:a,requestWithCredentials:l,requestHeaders:c,transformResponse:d}=e.config[n.name],h=i.target,p=s.get(0),u=h.files||[];for(const i of u)K({selection:e.selection,boxName:n.name,file:i,requestTypes:t,requestMethod:o,requestAction:r,requestFieldName:a,requestWithCredentials:l,requestHeaders:c,transformResponse:d,onError:t=>{p.value="",e.config.onMessage("error",t)},onSuccess:()=>{p.value="",e.history.save()}})}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||n.find("lake-box").length>0||n.closest("table").length>0)return;const s=Hs(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(Ce.isKeyHotkey(["down","up","enter"],s))return;if(!t.visible){if(Ce.isKeyHotkey("/",s))return void i();if(!Ce.isKeyHotkey(["backspace","delete"],s))return;i()}const o=e.selection.range.getBlocks()[0];if(!o)return;const r=Hs(o);null!==r?t.update(r):t.hide()})),()=>{t.unmount()}})),e.Box=ye,e.Button=X,e.Dropdown=me,e.Editor=Rt,e.Fragment=Te,e.HTMLParser=Ie,e.Nodes=x,e.Range=N,e.TextParser=Me,e.Toolbar=ve,e.addMark=et,e.createIframeBox=Le,e.deleteContents=Re,e.getBox=xe,e.getContentRules=o,e.icons=n,e.insertBlock=Ge,e.insertBookmark=He,e.insertBox=it,e.insertContents=Fe,e.query=b,e.removeBox=st,e.removeMark=tt,e.setBlocks=je,e.splitBlock=Xe,e.splitMarks=Qe,e.template=S,e.toBookmark=Ze,e.toHex=f,e}({});
110
+ `),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=b(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+Number.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+Number.parseInt(n.computedCSS("margin-bottom"),10)/2):(s="top",p=d.y-c.y-Number.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=xe(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()}}))})),Rt.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"))})))})),Rt.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)})),Rt.plugin.add("selectAll",(e=>{e.readonly||e.command.add("selectAll",{execute:()=>{const t=e.selection.range;t.selectNodeContents(e.container),t.shrink()}})})),Rt.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()}})})),Rt.plugin.add("blockQuote",(e=>{e.readonly||e.command.add("blockQuote",{isSelected:e=>!!e.find((e=>"blockquote"===e.name)),execute:t=>{t&&Ut.indexOf(t)>=0?e.selection.setBlocks(S`<blockquote type="${t}" />`):e.selection.setBlocks("<blockquote />"),e.history.save()}})})),Rt.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&&Kt(e),"bulleted"===t&&Gt(e),"checklist"===t&&Yt(e,i)):o?("numbered"===t&&Xt(e),"bulleted"===t&&Kt(e),"checklist"===t&&Yt(e,i)):r?("numbered"===t&&Xt(e),"bulleted"===t&&Gt(e),"checklist"===t&&Kt(e)):("numbered"===t&&Xt(e),"bulleted"===t&&Gt(e),"checklist"===t&&Yt(e,i)),e.history.save()}}),e.container.on("click",(t=>{const i=t;if(!i.target)return;const n=b(i.target);"li"===n.name&&""!==n.attr("value")&&i.offsetX<=18&&(n.attr("value",("true"!==n.attr("value")).toString()),e.history.save())})))})),Rt.plugin.add("table",(e=>{if(e.readonly)return;const t={backgroundColor:""};let i=null,n=null;return e.event.on("statechange",(()=>{e.container.find("table").removeClass("lake-table-focused"),e.container.find("td").removeClass("lake-td-focused"),i&&i.updateState();const s=e.selection.range.commonAncestor.closest("td"),o=s.closest("table");if(n&&n.get(0)===o.get(0))return o.addClass("lake-table-focused"),void s.addClass("lake-td-focused");if(n=o,i&&i.unmount(),o.length>0){o.addClass("lake-table-focused"),s.addClass("lake-td-focused");const n=li(e,t);i=new we({target:o,items:n}),i.render()}})),e.command.add("table",{execute:()=>{!function(e,t,i){let n="<table>";for(let e=0;e<t;e++){n+="<tr>";for(let e=0;e<i;e++)n+="<td><p><br /></p></td>";n+="</tr>"}n+="</table>";const s=b(n);Ge(e,s),e.shrinkBefore(s),v(`insertTable: table ${s.id}`)}(e.selection.range,3,2),e.history.save()}}),()=>{i&&i.unmount()}})),Rt.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?[ci[t]||t]:[]},execute:t=>{e.selection.setBlocks({"text-align":t}),e.history.save()}})})),Rt.plugin.add("indent",(e=>{e.readonly||e.command.add("indent",{execute:t=>{const i=e.selection.range.getBlocks();for(const e of i)di(e,t);e.history.save()}})})),Rt.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===hi)),execute:()=>{e.command.isSelected("bold")?e.selection.removeMark(`<${hi} />`):e.selection.addMark(`<${hi} />`),e.history.save()}}),e.keystroke.setKeydown("mod+b",(t=>{t.preventDefault(),e.command.execute("bold")})))})),Rt.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")})))})),Rt.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")})))})),Rt.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")})))})),Rt.plugin.add("subscript",(e=>{e.readonly||e.command.add("subscript",{isSelected:e=>!!e.find((e=>e.name===pi)),execute:()=>{e.command.isSelected("subscript")?e.selection.removeMark(`<${pi} />`):e.selection.addMark(`<${pi} />`),e.history.save()}})})),Rt.plugin.add("superscript",(e=>{e.readonly||e.command.add("superscript",{isSelected:e=>!!e.find((e=>e.name===ui)),execute:()=>{e.command.isSelected("superscript")?e.selection.removeMark(`<${ui} />`):e.selection.addMark(`<${ui} />`),e.history.save()}})})),Rt.plugin.add("code",(e=>{e.readonly||e.command.add("code",{isSelected:e=>!!e.find((e=>e.name===mi)),execute:()=>{e.command.isSelected("code")?e.selection.removeMark(`<${mi} />`):e.selection.addMark(`<${mi} />`),e.history.save()}})})),Rt.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()}})})),Rt.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()}})})),Rt.plugin.add("fontColor",(e=>{e.readonly||e.command.add("fontColor",{selectedValues:e=>{for(const t of e)if("span"===t.name){return[f(t.node.computedCSS("color"))]}return[]},execute:t=>{e.selection.addMark(`<span style="color: ${t};" />`),e.history.save()}})})),Rt.plugin.add("highlight",(e=>{e.readonly||e.command.add("highlight",{selectedValues:e=>{for(const t of e)if("span"===t.name){return[f(t.node.computedCSS("background-color"))]}return[]},execute:t=>{e.selection.addMark(`<span style="background-color: ${t};" />`),e.history.save()}})})),Rt.plugin.add("removeFormat",(e=>{e.readonly||e.command.add("removeFormat",{execute:()=>{e.selection.removeMark(),e.history.save()}})})),Rt.plugin.add("formatPainter",(e=>{if(e.readonly)return;let t=[];e.command.add("formatPainter",{execute:()=>{e.container.addClass(gi);const i=e.selection.getActiveItems();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(gi),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(gi),t=[])}))})),Rt.plugin.add("link",(e=>{if(e.readonly)return;const t=new vi({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=function(e,t){if(e.commonAncestor.isOutside)return null;const i=b(t);if(e.isCollapsed){let t=e.commonAncestor.closest("a");return 0===t.length?(t=i.clone(!0),Fe(e,t),t):(""!==i.attr("href")&&t.attr({href:i.attr("href")}),t)}Qe(e);const n=He(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(),Ze(e,n),s}(e.selection.range,`<a href="">${e.locale.link.newLink()}</a>`);i&&(e.history.save(),t.show(i))}}),()=>t.unmount()})),Rt.plugin.add("hr",(e=>{e.readonly||(e.event.on("beforepaste",(e=>{new Te(e).find("hr").each((e=>{const t=b(e),i=xe("hr");t.replaceWith(i.node)}))})),e.command.add("hr",{execute:()=>{e.selection.insertBox("hr"),e.history.save()}}))})),Rt.plugin.add("codeBlock",(e=>{window.LakeCodeMirror&&(e.setPluginConfig("codeBlock",{langList:bi,defaultLang:"text",colors:ki}),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")}}))})),Rt.plugin.add("image",(e=>{e.setPluginConfig("image",{requestMethod:"POST",requestTypes:["image/gif","image/jpeg","image/png","image/svg+xml","image/webp"]}),e.readonly||(e.event.on("beforepaste",(e=>{new Te(e).find("img").each((e=>{const t=b(e),i=xe("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()}}))})),Rt.plugin.add("video",(e=>{e.readonly||e.command.add("video",{execute:t=>{const i=e.selection.insertBox("video",t);if(e.history.save(),i){const e=i.getContainer().find('input[name="url"]');e.length>0&&e.focus()}}})})),Rt.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","image/webp","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()}})})),Rt.plugin.add("emoji",(e=>{e.readonly||e.command.add("emoji",{execute:t=>{e.selection.insertBox("emoji",t),e.history.save()}})})),Rt.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()}}))})),Rt.plugin.add("specialCharacter",(e=>{e.readonly||e.command.add("specialCharacter",{execute:t=>{e.selection.insertContents(document.createTextNode(t)),e.history.save()}})})),Rt.plugin.add("mention",(e=>{if(e.setPluginConfig("mention",{requestMethod:"GET",items:[],getProfileUrl:e=>`/${e.name}`}),e.readonly)return;let t=null;const i=(i,n)=>{t&&t.hide(),e.focus();const s=e.selection.range.getCharacterRange("@");s&&s.get().deleteContents(),e.selection.insertBox("mention",n),e.history.save()},n=()=>{e.popup=t},s=()=>{e.popup=null},o=()=>{const o=e.selection.range;if(!o.isCollapsed)return;const r=o.getCharacterRange("@");if(null===r)return;const a=us(o);if(null!==a)if(t)t.show(r,a);else{const{requestAction:o,items:l}=e.config.mention;if(o){const{requestMethod:l,requestWithCredentials:c,requestHeaders:d,transformResponse:h}=e.config.mention;U({onSuccess:e=>{h&&(e=h(e)),e.data&&(t=new hs({items:e.data,onSelect:i,onShow:n,onHide:s}),t.show(r,a))},action:o,method:l,withCredentials:c,headers:d})}else t=new hs({items:l,onSelect:i,onShow:n,onHide:s}),t.show(r,a)}};return e.container.on("keyup",(i=>{if(e.isComposing)return;const n=i;if(Ce.isKeyHotkey(["down","up","enter"],n))return;if(!t||!t.visible){if("@"===n.key)return void o();if(!Ce.isKeyHotkey(["backspace","delete"],n))return;o()}const s=us(e.selection.range);null!==s?t&&t.update(s):t&&t.hide()})),()=>{t&&t.unmount()}})),Rt.plugin.add("twitter",(e=>{e.readonly||e.command.add("twitter",{execute:t=>{const i=e.selection.insertBox("twitter",t);if(e.history.save(),i){const e=i.getContainer().find('input[name="url"]');e.length>0&&e.focus()}}})})),Rt.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 ys){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 xs){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 ks(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 bs){const o=s.re.exec(n);if(null!==o){const n=s.getParameters(o),r=n.shift();return!!e.command.has(r)&&(t.empty(),ks(t),i.range.shrinkAfter(t),e.command.execute(r,...n),!0)}}return!1}(e,n)?(t.preventDefault(),t.stopImmediatePropagation(),!1):void 0})))})),Rt.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 Ss(e),void e.history.save();if(i.isCollapsed){const t=i.getPrevNode(),n=i.getNextNode();if("table"===t.name||"table"===n.name){const t=b("<p><br /></p>");return e.selection.insertContents(t),i.shrinkBefore(t),void e.history.save()}}if(i.adjust(),i.isInoperative)return;if(i.isBox)return Ss(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();Cs(e,n),e.history.save()}))})),Rt.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 As(e),void e.history.save();if(i.adjust(),!i.isInoperative){if(i.isBox)return As(e),void e.history.save();Bs(e),e.history.save()}}}))})),Rt.plugin.add("backspaceKey",(e=>{e.readonly||e.keystroke.setKeydown("backspace",(t=>{const i=e.selection.range;if(i.isInsideBox){const n=xe(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(),_s(e,i),e.history.save()))}if(s.isBlock)return s.isEmpty?(t.preventDefault(),s.remove(),Ve(i.getBlocks()),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();if(i.isCollapsed){const n=i.getPrevNode();if("table"===n.name){t.preventDefault();const s=b("<p><br /></p>");return n.replaceWith(s),i.shrinkBefore(s),void e.history.save()}const s=i.getNextNode();if(n.length>0&&"table"===s.name)return t.preventDefault(),i.shrinkAfter(n),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=ze(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 di(n,"decrease"),void e.history.save();if(n.isList||"blockquote"===n.name)return e.selection.setBlocks("<p />"),void e.history.save();_s(e,n),e.history.save()}}))})),Rt.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(),Ls(e,i),e.history.save()))}if(s.isBlock)return s.isEmpty?(t.preventDefault(),s.remove(),Ve(i.getBlocks()),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();if(i.isCollapsed){const n=i.getNextNode();if("table"===n.name){t.preventDefault();const s=b("<p><br /></p>");return n.replaceWith(s),i.shrinkBefore(s),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]),Ls(e,n),e.history.save()}}))})),Rt.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")?di(e,"increase"):e.css("text-indent","2em");e.history.save()}))})),Rt.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()}})))})),Rt.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())}))})),Rt.plugin.add("slash",(e=>{if(e.setPluginConfig("slash",{items:Ps}),e.readonly)return;const t=new Ms({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(),ze(i),t.shrinkBefore(i)}(e),"upload"===n.type){if(!s)return;const{requestTypes:t,requestMethod:o,requestAction:r,requestFieldName:a,requestWithCredentials:l,requestHeaders:c,transformResponse:d}=e.config[n.name],h=i.target,p=s.get(0),u=h.files||[];for(const i of u)K({selection:e.selection,boxName:n.name,file:i,requestTypes:t,requestMethod:o,requestAction:r,requestFieldName:a,requestWithCredentials:l,requestHeaders:c,transformResponse:d,onError:t=>{p.value="",e.config.showMessage("error",t)},onSuccess:()=>{p.value="",e.history.save()}})}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||n.find("lake-box").length>0||n.closest("table").length>0)return;const s=Hs(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(Ce.isKeyHotkey(["down","up","enter"],s))return;if(!t.visible){if(Ce.isKeyHotkey("/",s))return void i();if(!Ce.isKeyHotkey(["backspace","delete"],s))return;i()}const o=e.selection.range.getBlocks()[0];if(!o)return;const r=Hs(o);null!==r?t.update(r):t.hide()})),()=>{t.unmount()}})),e.Box=ye,e.Button=X,e.Dropdown=me,e.Editor=Rt,e.Fragment=Te,e.HTMLParser=Ie,e.Nodes=x,e.Range=N,e.TextParser=Me,e.Toolbar=ve,e.addMark=et,e.createIframeBox=Le,e.deleteContents=Re,e.getBox=xe,e.getContentRules=o,e.icons=n,e.insertBlock=Ge,e.insertBookmark=He,e.insertBox=it,e.insertContents=Fe,e.query=b,e.removeBox=st,e.removeMark=tt,e.setBlocks=je,e.splitBlock=Xe,e.splitMarks=Qe,e.template=S,e.toBookmark=Ze,e.toHex=f,e}({});
111
111
  //# sourceMappingURL=lake.min.js.map