lakelib 0.3.0 → 0.3.1

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/README.md CHANGED
@@ -6,9 +6,9 @@
6
6
 
7
7
  ---
8
8
 
9
- Lake is a browser-based rich text editor designed for creating content like blogs, comments, and emails. It strikes a balance between being feature-rich and lightweight, offering an easy-to-use programming interface for easy customization and extension.
9
+ Lake is a browser-based rich text editor designed for creating content such as blogs, comments, and emails. It tries to keep a balance between being feature-rich and lightweight, offering an easy-to-use programming interface for further extension.
10
10
 
11
- [Examples](https://lakejs.org/examples/) · [Getting started](https://lakejs.org/guide/) · [Reference](https://lakejs.org/reference/)
11
+ [Examples](https://lakejs.org/examples/) · [Getting started](https://lakejs.org/guide/getting-started) · [Reference](https://lakejs.org/reference/)
12
12
 
13
13
  ## Development
14
14
 
@@ -27,7 +27,7 @@ You can now visit `http://localhost:8080/examples/` to try the demos in your loc
27
27
 
28
28
  ## Test
29
29
 
30
- Lake depends on a lot of browser APIs, so running its test cases needs a real browser environment. You can run the tests visibly by visiting `http://localhost:8080/tests/`, or execute the `pnpm test` command to run them in headless mode.
30
+ Lake depends on many browser APIs, so running its test cases needs a real browser environment. You can run the tests visibly by visiting `http://localhost:8080/tests/`, or execute the `pnpm test` command to run them in headless mode.
31
31
 
32
32
  ## License
33
33
 
package/dist/lake.min.js CHANGED
@@ -19,7 +19,7 @@ var Lake=function(e){"use strict";class t extends HTMLElement{}void 0!==customEl
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>
22
- `),e=this.getContainer()):(e.off("mouseenter"),e.off("mouseleave"),e.off("click")),e.on("mouseenter",(()=>{e.hasClass("lake-box-selected")||e.hasClass("lake-box-focused")||e.hasClass("lake-box-activated")||e.addClass("lake-box-hovered")})),e.on("mouseleave",(()=>{e.removeClass("lake-box-hovered")})),e.on("click",(()=>{g(`Box "${this.name}" (id = ${this.node.id}) value:`),g(this.value)})),"block"===this.type&&this.node.isContentEditable&&e.attr("draggable","true")}get type(){return this.node.attr("type")}get name(){return this.node.attr("name")}get value(){const e=this.node.attr("value");return""===e?{}:JSON.parse(P(e))}set value(e){this.node.attr("value",M(JSON.stringify(e)))}updateValue(e,t){const i=this.value;if("string"==typeof e)i[e]=t;else for(const t of Object.keys(e))i[t]=e[t];this.value=i}getEditor(){const e=this.node.closest("div[contenteditable]"),t=e.length>0?I.get(e.id):void 0;if(!t)throw new Error(`Box "${this.name}" (id=${this.node.id}) is not rendered in the editor.`);return t}getContainer(){return this.node.find(".lake-box-container")}setToolbar(e){const t=this.getEditor();this.event.on("focus",(()=>{this.toolbar&&this.toolbar.unmount(),this.toolbar=new ge({target:this.node,items:e}),this.toolbar.render();const i=t.selection.getActiveItems();this.toolbar.updateState({activeItems:i}),this.event.emit("renderfloatingtoolbar")})),this.event.on("blur",(()=>{this.toolbar&&(this.toolbar.unmount(),this.toolbar=null)}))}render(){const e=E.get(this.name);if(void 0===e)return;this.event.emit("beforeunmount"),this.event.removeAllListeners(),this.initiate();const t=e.render(this);if(void 0!==t){const e=this.getContainer();e.empty(),e.append(t)}g(`Box "${this.name}" (id: ${this.node.id}) rendered`)}unmount(){this.event.emit("blur"),this.event.emit("beforeunmount"),this.event.removeAllListeners(),this.node.empty(),g(`Box "${this.name}" (id: ${this.node.id}) unmounted`)}getHTML(){const e=E.get(this.name);return void 0===e?"":void 0===e.html?this.node.outerHTML():e.html(this)}}const ve={id:/^[\w-]+$/,class:/^[\w- ]+$/,style:{"text-align":["left","center","right","justify","start","end"],"margin-left":/^-?\d+px$/i,"text-indent":/^-?\d+em$/i}};function we(){return{h1:Object.assign({},ve),h2:Object.assign({},ve),h3:Object.assign({},ve),h4:Object.assign({},ve),h5:Object.assign({},ve),h6:Object.assign({},ve),p:Object.assign({},ve),blockquote:Object.assign(Object.assign({},ve),{type:["info","tip","success","warning","error","danger"]}),ul:Object.assign(Object.assign({},ve),{type:"checklist",indent:/^\d+$/}),ol:Object.assign(Object.assign({},ve),{start:/^\d+$/,indent:/^\d+$/}),li:{value:["true","false"]},table:{style:{width:/^-?\d+(px|%)$/i,height:/^-?\d+(px|%)$/i,border:/^[^"]+$/,"border-width":/^-?\d+px$/i,"border-style":/^[\w-]+$/,"border-color":/^[^"]+$/,"background-color":/^[^"]+$/}},tr:{style:{height:/^-?\d+(px|%)$/i}},th:"td",td:{colspan:/^\d+$/,rowspan:/^\d+$/,style:{width:/^-?\d+(px|%)$/i,height:/^-?\d+(px|%)$/i,border:/^[^"]+$/,"border-width":/^-?\d+px$/i,"border-style":/^[\w-]+$/,"border-color":/^[^"]+$/,"background-color":/^[^"]+$/,"text-align":["left","center","right","justify"]}},"lake-box":{type:["inline","block"],name:/^[\w-]+$/,value:/^[^"]+$/,focus:["start","center","end"]},br:{},hr:{},img:{src:/^[^"]+$/,width:/^-?\d+px$/i,height:/^-?\d+px$/i,"data-lake-value":/^[^"]+$/,alt:/^[^"]+$/,style:{width:/^-?\d+px$/i,height:/^-?\d+px$/i}},span:{class:/^[\w- ]+$/,style:{color:/^[^"]+$/,"background-color":/^[^"]+$/,"font-family":/^[^;]+$/,"font-size":/^[^"]+$/}},b:"strong",strong:{},em:"i",i:{},u:{},s:{},sub:{},sup:{},code:{},a:{class:/^[\w- ]+$/,name:/^[\w-]+$/,href:/^[^"]+$/,target:/^[\w-]+$/,rel:/^[^"]+$/,download:/^[^"]+$/},"lake-bookmark":{type:["anchor","focus"]}}}function ye(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=m(n[2]).trim();t[e]=i}return t}class xe{constructor(e,t=we()){this.rules=t,this.source="string"==typeof e?this.parseHTML(e):e}parseHTML(e){const t=(new DOMParser).parseFromString(e,"text/html");return new w(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 o=e.get(0);if(!o.hasAttributes())return i;const s=new Map;for(const e of o.attributes)if(n[e.name]&&("style"!==e.name&&xe.matchRule(n[e.name],e.value)&&s.set(e.name,e.value),"style"===e.name)){const t=n.style,i=new Map,o=ye(e.value);for(const e of Object.keys(o)){const n=o[e];t[e]&&xe.matchRule(t[e],n)&&i.set(e,n)}s.set("style",i)}let r=i;for(const[e,t]of s)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 o=e.text();return(i.isBlock||i.isBlockBox)&&(n.isBlock||n.isBlockBox)||0===i.length&&0===n.length&&t.isBlock?o=o.replace(/^[\u0020\t\r\n]+|[\u0020\t\r\n]+$/g,""):i.isBlock||i.isBlockBox||0===i.length&&t.isBlock?o=o.replace(/^[\u0020\t\r\n]+/,""):(n.isBlock||n.isBlockBox||0===n.length&&t.isBlock)&&(o=o.replace(/[\u0020\t\r\n]+$/,"")),o}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 b(xe.getTrimmedText(n));else if(n.isVoid){const t=xe.getOpenTagString(n,e);""!==t&&(yield`<${t} />`)}else if(n.isElement){const i=xe.getOpenTagString(n,e),o=xe.getClosedTagString(n,e);""!==i&&(yield`<${i}>`),n.isBox||(yield*t(n)),""!==o&&(yield`</${o}>`)}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 be{constructor(e){this.content=e}getHTML(){let e=this.content;return e=e.replace(/ {2}/g,"  "),e=b(e.trim()),e=`<p>${e}</p>`,e=e.replace(/(\r\n){2,}/g,"</p><p><br /></p><p>"),e=e.replace(/\r\n/g,"</p><p>"),e=e.replace(/[\r\n]{2,}/g,"</p><p><br /></p><p>"),e=e.replace(/[\r\n]/g,"</p><p>"),e}getFragment(){return new xe(this.getHTML()).getFragment()}}function ke(e,t){const i=e.get(),n=t.get(0);i.insertNode(n),i.setEndAfter(n),i.collapse(!1)}function Ce(e){if(e.commonAncestor.isOutside)return{anchor:new w,focus:new w};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 w,focus:t};if(e.isCollapsed){const t=e.clone();t.collapseToEnd();const i=y('<lake-bookmark type="focus" />');return ke(t,i),{anchor:new w,focus:i}}const i=e.clone();i.collapseToStart();const n=y('<lake-bookmark type="anchor" />');ke(i,n);const o=e.clone();o.collapseToEnd();const s=y('<lake-bookmark type="focus" />');return ke(o,s),{anchor:n,focus:s}}const Se=new Map;function Be(e){let t=Se.get(e);return t||(t=new Map,Se.set(e,t),t)}function _e(e){const t=Be(0);if("string"==typeof e){const i=new fe(e);return t.set(i.node.id,i),i}const i=(e=y(e)).closestContainer();if(0===i.length){let i=t.get(e.id);return i||(i=new fe(e),t.set(e.id,i),i)}const n=Be(i.id);let o=t.get(e.id);return o?(n.set(e.id,o),t.delete(e.id),o):(o=n.get(e.id),o||(o=new fe(e),n.set(e.id,o),o))}function Ae(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 w(document.createTextNode("​"));e.before(i),t.setStartAfter(i),t.collapseToStart()}e.remove()}else e.remove()}function Le(e,t){const i=t.anchor,n=t.focus;if(i.length>0&&0===n.length)Ae(i);else{if(n.length>0&&0===i.length){if(n.isBox){const t=_e(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 Ae(n,e)}if(i.length>0&&n.length>0){const t=new S;t.selectNode(i),t.collapseToEnd(),-1===t.compareAfterNode(n)?(e.setStartBefore(n),Ae(n),e.setEndBefore(i),Ae(i)):(e.setStartBefore(i),Ae(i),e.setEndBefore(n),Ae(n))}}}function Te(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 Ee(e){const t=y("<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 Ie(e){if(e.isText)return{node:e,offset:e.text().length};const t=new S;return t.setEndAfter(e),{node:t.endNode,offset:t.endOffset}}function Me(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 Ie(e);Te(e),Te(t),e.isBlock&&e.isEmpty&&t.isEmpty&&Ee(e);const n=e.last(),o=t.first();let s=o;for(;s.length>0;){const t=s.next();e.append(s),s=t}return i.remove(),n.length>0&&o.length>0&&n.isElement&&!n.isBox&&n.clone(!1).get(0).isEqualNode(o.clone(!1).get(0))?Me(n,o):0===n.length?{node:e,offset:0}:Ie(n)}function Pe(e){if(0===e.length)return;const t=e[0],i=e[e.length-1],n=[];let o=t.prev();for(;o.length>0&&"ol"===o.name;)n.push(o),o=o.prev();n.reverse(),n.push(...e);let s=i.next();for(;s.length>0&&"ol"===s.name;)n.push(s),s=s.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 He(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=Ee(t);e.setStartBefore(i),e.collapseToStart()}return}const o=e.getBlocks()[0];if(!o)return;const s=o.prev();if(0===s.length)return;const r=Ce(e);Me(s,o),Pe([s]),Le(e,r)}function Ze(e,t){if(e.commonAncestor.isOutside)return;let i;t instanceof C?i=t:t instanceof DocumentFragment?i=new C(t):(i=new C,i.append(t)),e.isCollapsed?e.adjustBox():He(e);Te(e.startNode.closestBlock());const n=e.get();n.insertNode(i.get()),n.collapse(!1),e.adjustBlock()}function De(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 Ne(e,t){if(t=null!=t?t:y("<p />"),0===e.length)return t;const i=De(t=t.clone(!0));e[0].before(t);for(const t of e)i.append(t);return t}function Oe(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=y(t),n=i.name,o=i.get(0).attributes,s=e.getBlocks();if(s.length>0){const t=Ce(e);for(const e of s)if(e.name===n&&0===i.first().length)for(const t of o)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=De(t);let o=e.first();for(;o.length>0;){const e=o.next();n.append(o),n.name!==o.name&&"li"!==o.name||o.remove(!0),o=e}e.replaceWith(t)}return Le(e,t),void Pe(e.getBlocks())}if(e.isCollapsed){const t=e.getNextNode();if("br"===t.name){const i=y("<p><br /></p>");return t.replaceWith(i),void e.shrinkBefore(i)}const i=e.getPrevNode();if("br"===i.name){const t=y("<p><br /></p>");return i.replaceWith(t),void e.shrinkBefore(t)}}const r=Ce(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(),o=!0;for(;n.length>0;){if(n.isMark||n.isText||n.isBookmark||n.isInlineBox)i.push(n);else{if(!o)break;i=[]}e.intersectsNode(n)&&(o=!1),n=n.next()}return i}(e),l=Ne(a,i);if(Le(e,r),Pe(e.getBlocks()),l.isEmpty){const t=Ee(l);e.setStartBefore(t),e.collapseToStart()}}function ze(e,t,i){const n=new S;let o;if(e.isText){o=e.parent();const i=e.splitText(t);n.setStartAfter(e),""===e.text()&&e.remove(),""===i.text()&&i.remove()}else n.setStart(e,t),o=e;if("body"===o.name||"html"===o.name)return null;if(o.get(0)===i.get(0))return null;n.collapseToStart();const s=o.clone();let r=o.first();for(;r.length>0&&!(n.compareBeforeNode(r)>=0);){const e=r.next();s.append(r),r=e}return o.before(s),o.parent().length>0&&o.parent().get(0)!==i.get(0)?ze(o.parent(),o.index(),i):{start:s,end:o}}function $e(e){if(e.isMark&&e.isEmpty)e.remove();else for(const t of e.getWalker())t.isMark&&t.isEmpty&&t.remove()}function Ve(e){if(e.commonAncestor.isOutside)return{start:null,end:null};e.isCollapsed?e.adjustBox():He(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 o=ze(t,e.startOffset,n);let s=null,r=null;return o&&(s=o.start,r=o.end),!o&&t.isBlock&&(e.startOffset>0&&(s=t.children()[e.startOffset-1]),r=t.children()[e.startOffset],r&&!r.isBlock&&(r=null)),s&&s.isEmpty&&($e(s),Ee(s)),r&&(r.isEmpty&&($e(r),Ee(r)),e.shrinkBefore(r)),Pe(e.getBlocks()),{start:s,end:r}}function Re(e,t){if(e.commonAncestor.isOutside)return null;const i=y(t),n=Ve(e);return n.start&&($e(n.start),e.setEndAfter(n.start),e.collapseToEnd()),n.end&&($e(n.end),n.end.isEmpty&&n.end.remove()),Ze(e,i),i.isBox||e.shrinkAfter(i),n.start&&n.start.isEmpty&&n.start.remove(),i}function Fe(e,t,i){let n=null,o=null,s=e.closestBlock();0===s.length&&(s=e.closestContainer());const r=ze(e,t,s);return r&&(i?($e(r.start),$e(r.end),r.start.isEmpty||(n=r.start),r.end.isEmpty||(o=r.end)):(n=r.start,o=r.end)),{start:n,end:o}}function We(e,t=!0){if(e.commonAncestor.isOutside)return{start:null,center:null,end:null};if(e.adjustBox(),e.isCollapsed){const i=Fe(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=Fe(e.startNode,e.startOffset,t);i.start?e.setStartAfter(i.start):i.end&&e.setStartBefore(i.end);const n=Fe(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 qe(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 je(e,t){if(e.commonAncestor.isOutside)return;let i=y(t);const n=i.name,o=ye(i.attr("style"));if(e.isCollapsed){if(e.isBox){const t=e.startNode.closest("lake-box");if("block"===_e(t).type){const i=y("<p><br /></p>");e.isBoxStart?t.before(i):t.after(i),e.shrinkAfter(i)}else e.adjustBox()}Te(e.startNode.closestBlock());const t=new w(document.createTextNode("​")),s=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(We(e),s){let e=s;for(;e.length>0;)e.name===n&&e.css(o),e=e.first();s.name===n?i=s:i.append(s)}if(""===i.text()){De(i).append(t)}return Ze(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)}We(e);const s=e.getMarks(!0),r=Ce(e);for(const e of s)if(!e.isEmpty&&e.isText){const t=qe(e,n);if(t.isMark&&t.name===n)t.css(o);else{const e=i.clone();t.before(e),e.append(t)}}Le(e,r)}function Ue(e,t){if(e.commonAncestor.isOutside)return;let i;if(t){i=y(t).name}if(e.isCollapsed){if(e.isBox)return;if(i&&0===e.commonAncestor.closest(i).length)return;const t=We(e,!1);if(!t.start)return;t.end&&$e(t.end);const n=new w(document.createTextNode("​")),o=function(e,t){if(!e.isMark||!t)return null;let i=null,n=null,o=e;for(;o.length>0&&o.isMark;){if(o.name!==t)if(n){const e=o.clone();n.append(e),n=e}else i=o.clone(),n=i;o=o.last()}return i}(t.start,i);if(!o)return t.start.after(n),$e(t.start),n.prev().isText?(e.setStartAfter(n.prev()),e.collapseToStart(),void n.remove()):(e.setStartAfter(n),void e.collapseToStart());return De(o).append(n),t.start.after(o),$e(t.start),void e.shrinkAfter(o)}We(e);const n=e.getMarks(),o=Ce(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),Le(e,o)}function Ke(e,t,i){if(e.commonAncestor.isOutside)return null;const n=_e(t);if(i&&(n.value=i),"inline"===n.type){if(We(e),Ze(e,n.node),n.render(),n.node.isTopInside){const e=y("<p />");n.node.before(e),e.append(n.node)}return e.selectBoxEnd(n.node),_e(n.node)}return Re(e,n.node),n.render(),e.selectBoxEnd(n.node),_e(n.node)}function Ge(e){const t=e.node.closestContainer();if(e.unmount(),e.node.remove(),t.length>0){Be(t.id).delete(e.node.id);Be(0).set(e.node.id,e)}return e}function Xe(e){if(e.commonAncestor.isOutside)return null;const t=e.commonAncestor.closest("lake-box");if(0===t.length)return null;const i=_e(t);if("block"===i.type){const n=y("<p><br /></p>");return t.before(n),e.shrinkAfter(n),Ge(i)}e.setStartBefore(t),e.collapseToStart();const n=t.parent();if(Ge(i),n.isEmpty){const t=Ee(n);e.setStartBefore(t),e.collapseToStart()}return i}var Qe,Ye={exports:{}};function Je(){if(Qe)return Ye.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 o,s,r,a,l;function c(){const t=o,i=s;return o=void 0,s=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(o&&this!==o&&Object.getPrototypeOf(this)===Object.getPrototypeOf(o))throw new Error("Debounced method called with different contexts of the same prototype.");o=this,s=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 Qe=1,Ye.exports.debounce=e,Ye.exports=e,Ye.exports}var et,tt,it=B(Je());var nt=B(tt?et:(tt=1,et=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,o,s;if(Array.isArray(t)){if((n=t.length)!=i.length)return!1;for(o=n;0!=o--;)if(!e(t[o],i[o]))return!1;return!0}if(t instanceof Map&&i instanceof Map){if(t.size!==i.size)return!1;for(o of t.entries())if(!i.has(o[0]))return!1;for(o of t.entries())if(!e(o[1],i.get(o[0])))return!1;return!0}if(t instanceof Set&&i instanceof Set){if(t.size!==i.size)return!1;for(o of t.entries())if(!i.has(o[0]))return!1;return!0}if(ArrayBuffer.isView(t)&&ArrayBuffer.isView(i)){if((n=t.length)!=i.length)return!1;for(o=n;0!=o--;)if(t[o]!==i[o])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=(s=Object.keys(t)).length)!==Object.keys(i).length)return!1;for(o=n;0!=o--;)if(!Object.prototype.hasOwnProperty.call(i,s[o]))return!1;for(o=n;0!=o--;){var r=s[o];if(!e(t[r],i[r]))return!1}return!0}return t!=t&&i!=i}));function ot(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 st(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 rt(e,t){const i=H(e);0===i.left&&0===i.right&&0===i.top&&0===i.bottom||e.get(0).scrollIntoView(t)}function at(e){const t=e.get(0),i={};if(t.hasAttributes())for(const e of t.attributes)i[e.name]=e.value;return i}class lt{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 S(e)}return new S}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 Le(e,{anchor:new w,focus:i}),void this.sync();Le(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:at(i),styles:ye(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:at(t),styles:ye(t.attr("style"))}),t=t.first()}}(e,this.range),e}insertBookmark(){return Ce(this.range)}toBookmark(e){return Le(this.range,e)}insertContents(e){return Ze(this.range,e)}deleteContents(){return He(this.range)}setBlocks(e){return Oe(this.range,e)}splitBlock(){return Ve(this.range)}insertBlock(e){return Re(this.range,e)}splitMarks(e){return We(this.range,e)}addMark(e){return je(this.range,e)}removeMark(e){return Ue(this.range,e)}selectBox(e){let t=e;t=e instanceof fe?e.node:e,this.range.selectBox(t),this.sync()}insertBox(e,t){const i=Ke(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),Xe(this.range)}}class ct{constructor(e){this.commandMap=new Map,this.selection=e}add(e,t){this.commandMap.set(e,t)}delete(e){this.commandMap.delete(e)}getNames(){return Array.from(this.commandMap.keys())}has(e){return void 0!==this.commandMap.get(e)}getItem(e){const t=this.commandMap.get(e);if(void 0===t)throw new Error(`Command "${e}" has not been defined yet.`);return t}isDisabled(e){const t=this.getItem(e);if(!t.isDisabled)return!1;const i=this.selection.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),g(`Command "${e}" executed`)}}const dt=new Set;function ht(){}const pt={morphStyle:"outerHTML",callbacks:{beforeNodeAdded:ht,afterNodeAdded:ht,beforeNodeMorphed:ht,afterNodeMorphed:ht,beforeNodeRemoved:ht,afterNodeRemoved:ht,beforeAttributeUpdated:ht,afterAttributeUpdated:ht,beforeChildrenUpdated:ht},head:{style:"merge",shouldPreserve:e=>"true"===e.getAttribute("im-preserve"),shouldReAppend:e=>"true"===e.getAttribute("im-re-append"),shouldRemove:ht,afterHeadMorphed:ht}};function ut(e,t){return!e.deadIds.has(t)}function mt(e,t,i){return(e.idMap.get(i)||dt).has(t)}function gt(e,t){const i=e.idMap.get(t)||dt;for(const t of i)e.deadIds.add(t)}function ft(e,t,i){const n=e.idMap.get(t)||dt;let o=0;for(const t of n)ut(e,t)&&mt(e,t,i)&&++o;return o}function vt(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 wt(e,t){const i=new Map;return vt(e,i),vt(t,i),i}function yt(e,t,i){return{target:e,newContent:t,config:i=function(e){const t={};return Object.assign(t,pt),Object.assign(t,e),t.callbacks={},Object.assign(t.callbacks,pt.callbacks),Object.assign(t.callbacks,e.callbacks),t.head={},Object.assign(t.head,pt.head),Object.assign(t.head,e.head),t}(i),morphStyle:i.morphStyle,ignoreActive:i.ignoreActive,ignoreActiveValue:i.ignoreActiveValue,idMap:wt(e,t),deadIds:new Set,callbacks:i.callbacks,head:i.head}}function xt(e,t,i){return null!=e&&null!=t&&(e.nodeType===t.nodeType&&e.tagName===t.tagName&&(""!==e.id&&e.id===t.id||ft(i,e,t)>0))}function bt(e,t){return null!=e&&null!=t&&(e.nodeType===t.nodeType&&e.tagName===t.tagName)}function kt(e,t){gt(t,e),!1!==t.callbacks.beforeNodeRemoved(e)&&(e.remove(),t.callbacks.afterNodeRemoved(e))}function Ct(e,t,i){let n=e;for(;n&&n!==t;){const e=n;n=n.nextSibling,kt(e,i)}return gt(i,t),t.nextSibling}function St(e,t,i,n,o){const s=ft(o,i,t);let r=null;if(s>0){r=n;let t=0;for(;null!=r;){if(xt(i,r,o))return r;if(t+=ft(o,r,e),t>s)return null;r=r.nextSibling}}return r}function Bt(e,t,i,n,o){let s=n,r=i.nextSibling,a=0;for(;null!=s;){if(ft(o,s,e)>0)return null;if(bt(i,s))return s;if(bt(r,s)&&(a++,r=r?r.nextSibling:null,a>=2))return null;s=s?s.nextSibling:null}return s}function _t(e,t,i){return bt(e,t)?.5+ft(i,e,t):0}function At(e,t,i,n){return!("value"!==e||!n.ignoreActiveValue||t!==document.activeElement)||!1===n.callbacks.beforeAttributeUpdated(e,t,i)}function Lt(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):bt(e,t)?(!1===i.callbacks.beforeNodeMorphed(e,t)||(function(e,t,i){const n=e.nodeType;if(1===n){const n=e.attributes,o=t.attributes;for(const e of n)At(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=o.length-1;n>=0;n--){const s=o[n];At(s.name,t,"remove",i)||e.hasAttribute(s.name)||(t.removeAttribute(s.name),i.callbacks.afterAttributeUpdated(s.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)||Tt(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 Tt(e,t,i){let n,o=e.firstChild,s=t.firstChild;for(;o;){if(n=o,o=n.nextSibling,null==s){if(!1===i.callbacks.beforeNodeAdded(n))return;t.appendChild(n),i.callbacks.afterNodeAdded(n),gt(i,n);continue}if(xt(n,s,i)){Lt(s,n,i),s=s.nextSibling,gt(i,n);continue}const r=St(e,t,n,s,i);if(r){s=Ct(s,r,i),Lt(r,n,i),gt(i,n);continue}const a=Bt(e,0,n,s,i);if(a)s=Ct(s,a,i),Lt(a,n,i),gt(i,n);else{if(!1===i.callbacks.beforeNodeAdded(n))return;t.insertBefore(n,s),i.callbacks.afterNodeAdded(n),gt(i,n)}}for(;null!==s;){const e=s;s=s.nextSibling,kt(e,i)}}function Et(e,t,i){if("innerHTML"===i.morphStyle)return Tt(t,e,i),e.children;if("outerHTML"===i.morphStyle||null==i.morphStyle){const n=function(e,t,i){let n;n=e.firstChild;let o=n,s=0;for(;n;){const e=_t(n,t,i);e>s&&(o=n,s=e),n=n.nextSibling}return o}(t,e,i),o=null==n?void 0:n.previousSibling,s=null==n?void 0:n.nextSibling,r=Lt(e,n,i);return n?function(e,t,i){var n,o;const s=[],r=[];let a=e;for(;null!=a;)s.push(a),a=a.previousSibling;for(;s.length>0;){const e=s.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;)s.push(l),r.push(l),l=l.nextSibling;for(;s.length>0;){const e=s.pop();e&&(null===(o=t.parentElement)||void 0===o||o.insertBefore(e,t.nextSibling))}return r}(o,r,s):[]}throw`Do not understand how to morph style ${i.morphStyle}`}function It(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)),o=yt(e.get(0),n,i);Et(e.get(0),n,o)}class Mt{constructor(e){this.canSave=!0,this.list=[],this.index=0,this.limit=100,this.event=new T,this.selection=e,this.container=e.container}removeBookmark(e){return e.replace(/(<lake-box[^>]+)\s+focus="\w+"([^>]*>)/gi,"$1$2").replace(/<lake-bookmark\s+type="anchor">\s*<\/lake-bookmark>/gi,"").replace(/<lake-bookmark\s+type="focus">\s*<\/lake-bookmark>/gi,"")}getValue(e){return new xe(e).getHTML()}addIdToBoxes(e){e.find("lake-box").each((e=>{const t=new w(e),i=`${t.attr("name")}-${t.attr("value")}`;t.attr("id",i)}))}removeIdfromBoxes(e){e.find("lake-box").each((e=>{new w(e).removeAttr("id")}))}morphContainer(e){const t=this.container,i={beforeChildrenUpdated:e=>{if("lake-box"===new w(e).name)return!1},afterAttributeUpdated:(e,i)=>{const n=new w(i);if(["name","value"].indexOf(e)>=0&&"lake-box"===n.name){_e(n).unmount();Be(t.id).delete(n.id)}}},n=e.clone(!0);this.addIdToBoxes(t),this.addIdToBoxes(n),It(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=>{_e(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),o=e.clone();return o.selectBox(n),Ce(o),t}const i=e.startNode.path(),n=e.endNode.path(),o=t.find(i),s=t.find(n),r=e.clone();return r.setStart(o,e.startOffset),r.setEnd(s,e.endOffset),Ce(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(),g(`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(),g(`History redone (index: ${this.index})`)}continue(){this.canSave=!0}pause(){this.canSave=!1}save(e={}){var t,i,n;const o=null!==(t=e.inputType)&&void 0!==t?t:"",s=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)||(s?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),g(`History saved (index: ${this.index}, inputType: "${o}", update: ${s}, emitEvent: ${r})`),r&&this.event.emit("save",ot(l),{inputType:o,update:s,emitEvent:r}))}}var Pt,Ht={};var Zt=function(){if(Pt)return Ht;Pt=1,Object.defineProperty(Ht,"__esModule",{value:!0});for(var e="undefined"!=typeof window&&/Mac|iPod|iPhone|iPad/.test(window.navigator.platform),t={alt:"altKey",control:"ctrlKey",meta:"metaKey",shift:"shiftKey"},i={add:"+",break:"pause",cmd:"meta",command:"meta",ctl:"control",ctrl:"control",del:"delete",down:"arrowdown",esc:"escape",ins:"insert",left:"arrowleft",mod:e?"meta":"control",opt:"alt",option:"alt",return:"enter",right:"arrowright",space:" ",spacebar:" ",up:"arrowup",win:"meta",windows:"meta"},n={backspace:8,tab:9,enter:13,shift:16,control:17,alt:18,pause:19,capslock:20,escape:27," ":32,pageup:33,pagedown:34,end:35,home:36,arrowleft:37,arrowup:38,arrowright:39,arrowdown:40,insert:45,delete:46,meta:91,numlock:144,scrolllock:145,";":186,"=":187,",":188,"-":189,".":190,"/":191,"`":192,"[":219,"\\":220,"]":221,"'":222},o=1;o<20;o++)n["f"+o]=111+o;function s(e,t,i){t&&!("byKey"in t)&&(i=t,t=null),Array.isArray(e)||(e=[e]);var n=e.map((function(e){return r(e,t)})),o=function(e){return n.some((function(t){return a(t,e)}))};return null==i?o:o(i)}function r(e,o){var s=o&&o.byKey,r={},a=(e=e.replace("++","+add")).split("+"),d=a.length;for(var h in t)r[t[h]]=!1;var p=!0,u=!1,m=void 0;try{for(var g,f=a[Symbol.iterator]();!(p=(g=f.next()).done);p=!0){var v=g.value,w=v.endsWith("?")&&v.length>1;w&&(v=v.slice(0,-1));var y=c(v),x=t[y];if(v.length>1&&!x&&!i[v]&&!n[y])throw new TypeError('Unknown modifier: "'+v+'"');1!==d&&x||(s?r.key=y:r.which=l(v)),x&&(r[x]=!w||null)}}catch(e){u=!0,m=e}finally{try{!p&&f.return&&f.return()}finally{if(u)throw m}}return r}function a(e,t){for(var i in e){var n=e[i],o=void 0;if(null!=n&&((null!=(o="key"===i&&null!=t.key?t.key.toLowerCase():"which"===i?91===n&&93===t.which?91:t.which:t[i])||!1!==n)&&o!==n))return!1}return!0}function l(e){return e=c(e),n[e]||e.toUpperCase().charCodeAt(0)}function c(e){return e=e.toLowerCase(),e=i[e]||e}return Ht.default=s,Ht.isHotkey=s,Ht.isCodeHotkey=function(e,t){return s(e,t)},Ht.isKeyHotkey=function(e,t){return s(e,{byKey:!0},t)},Ht.parseHotkey=r,Ht.compareHotkey=a,Ht.toKeyCode=l,Ht.toKeyName=c,Ht}();class Dt{constructor(e){this.keydownEventList=[],this.keyupEventList=[],this.container=e,this.container.on("keydown",(e=>{const t=e;if(!t.isComposing&&!t.defaultPrevented)for(const e of this.keydownEventList)if(Zt.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(Zt.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 Nt={value:"<p><br /></p>",readonly:!1,spellcheck:!1,tabIndex:0,placeholder:"",indentWithTab:!0,lang:"en-US",minChangeSize:5,historySize:100,onMessage:(e,t)=>{"success"!==e?"warning"!==e?"error"===e&&console.error(t):console.warn(t):console.log(t)},slash:!1,mention:!1};class Ot{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.isComposing=!1,this.event=new T,this.box=Ot.box,this.popup=null,this.copyListener=e=>{const t=this.selection.getCurrentRange();this.container.contains(t.commonAncestor)&&this.event.emit("copy",e)},this.cutListener=e=>{const t=this.selection.getCurrentRange();this.container.contains(t.commonAncestor)&&this.event.emit("cut",e)},this.pasteListener=e=>{const t=this.selection.getCurrentRange();this.container.contains(t.commonAncestor)&&this.event.emit("paste",e)},this.selectionchangeListener=()=>{this.updateSelectionRange(),this.updateBoxSelectionStyle(),this.emitStateChangeEvent()},this.clickListener=e=>{const t=new w(e.target);t.get(0).isConnected&&this.event.emit("click",t)},this.updateSelectionRange=it((()=>{this.selection.updateByRange()}),1,{immediate:!0}),this.updateBoxSelectionStyle=it((()=>{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=_e(i),o=n.getContainer();if(0!==o.length){if(e.compareBeforeNode(o)<0&&e.compareAfterNode(o)>0&&(!e.isCollapsed||e.startNode.get(0)!==o.get(0)||0!==e.startOffset))return o.removeClass("lake-box-hovered"),o.removeClass("lake-box-selected"),o.removeClass("lake-box-focused"),o.addClass("lake-box-activated"),void n.event.emit("focus");if(t.intersectsNode(n.node))return o.removeClass("lake-box-activated"),void(e.isCollapsed?(o.removeClass("lake-box-hovered"),o.removeClass("lake-box-selected"),o.addClass("lake-box-focused"),n.event.emit("focus")):(o.removeClass("lake-box-focused"),o.addClass("lake-box-selected"),n.event.emit("blur")));o.removeClass("lake-box-activated"),o.removeClass("lake-box-focused"),o.removeClass("lake-box-selected"),n.event.emit("blur")}}))}),50,{immediate:!0}),this.emitStateChangeEvent=it((()=>{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,o=new Map;if(t.length>0)for(const s of e){const e=this.command.getItem(s);if(e.isDisabled&&e.isDisabled(t)&&i.set(s,!0),e.isSelected&&e.isSelected(t)&&n.set(s,!0),e.selectedValues){const i=e.selectedValues(t);i.length>0&&o.set(s,i)}}const s={activeItems:t,disabledNameMap:i,selectedNameMap:n,selectedValuesMap:o};nt(s,this.state)||(this.toolbar&&this.toolbar.updateState(s),this.event.emit("statechange",s),this.state=s)}),50,{immediate:!1}),!e.root)throw new Error("The root of the config must be specified.");this.root=y(e.root),this.toolbar=e.toolbar,this.config=Object.assign({},Nt);for(const t of Object.keys(e))this.config[t]=e[t];this.containerWrapper=y('<div class="lake-container-wrapper" />'),this.container=y('<div class="lake-container" />'),this.overlayContainer=y('<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 lt(this.container),this.command=new ct(this.selection),this.history=new Mt(this.selection),this.history.limit=this.config.historySize,this.keystroke=new Dt(this.container),I.set(this.container.id,this)}togglePlaceholderClass(e){const t="lake-placeholder";"<p><br /></p>"===(e=ot(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"===_e(n).type)t.isBoxStart?(t.setStartBefore(n),t.collapseToStart()):(t.setStartAfter(n),t.collapseToStart());else{const e=y("<p />");t.isBoxStart?n.before(e):n.after(e),t.setStart(e,0),t.collapseToStart()}const o=i.text();i.html("<br />"),e.insertContents(document.createTextNode(o))}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=Be(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.scrollToCaret(),this.event.emit("change",e)};this.history.event.on("undo",(t=>{this.renderBoxes(),e(t),this.resetUnsavedInputData()})),this.history.event.on("redo",(t=>{this.renderBoxes(),e(t),this.resetUnsavedInputData()})),this.history.event.on("save",((t,i)=>{this.removeBoxGarbage(),e(t),"insertText"!==i.inputType&&(this.selection.sync(),this.resetUnsavedInputData())}))}get hasFocus(){const e=document.activeElement;return!!e&&y(e).closest(".lake-container").get(0)===this.container.get(0)}get locale(){return de(this.config.lang)}fixContent(){const e=this.selection.range,t=e.commonAncestor.closest("td"),i=t.length>0?t:this.container;let n=!1,o=i.children();for(const e of o)(e.isBlock||e.isMark)&&""===e.html()&&(e.remove(),n=!0,g(`Content fixed: empty tag "${e.name}" was removed`));if(o=i.children(),0===o.length)i.html("<p><br /></p>"),e.shrinkBefore(i),n=!0,g("Content fixed: default paragraph was added");else if(1===o.length){const t=o[0];if(t.isVoid){const i=y("<p />");t.before(i),i.append(t),e.shrinkAfter(i),n=!0,g(`Content fixed: void element "${t.name}" was wrapped in paragraph`)}}return e.adjustBr(),n}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])}renderBoxes(){this.removeBoxGarbage();const e=this.container,t=Be(e.id);e.find("lake-box").each((e=>{const i=y(e);if(t.get(i.id))return;_e(i).render()}))}focus(){const e=this.selection.range;this.container.contains(e.commonAncestor)&&e.isBox||this.container.focus()}blur(){this.container.blur()}scrollToCaret(){const e=this.selection.range;if(e.isBox)return;const t=e.getRect();if(0===t.x||0===t.y)return;const i=this.container.get(0).getBoundingClientRect(),n=y('<div class="lake-artificial-caret" />'),o=t.x-i.x,s=t.y-i.y;n.css({position:"absolute",top:`${s}px`,left:`${o}px`,width:`${t.width}px`,height:`${t.height}px`,"z-index":"-1"}),this.overlayContainer.find(".lake-artificial-caret").remove(),this.overlayContainer.append(n),rt(n,{behavior:"instant",block:"nearest",inline:"nearest"}),n.remove()}setValue(e){e=st(e);const t=new xe(e),i=t.getFragment();this.container.empty(),this.togglePlaceholderClass(t.getHTML()),this.container.append(i),this.renderBoxes(),this.selection.updateByBookmark()}getValue(){const e=this.history.cloneContainer();let t=new xe(e).getHTML();return t=ot(t),t}render(){const e=st(this.config.value),t=new xe(e),i=t.getFragment();this.root.empty(),this.root.append(this.containerWrapper),this.containerWrapper.append(this.container),this.containerWrapper.append(this.overlayContainer),this.togglePlaceholderClass(t.getHTML()),this.container.append(i),this.unmountPluginMap=Ot.plugin.loadAll(this),this.readonly||(this.selection.updateByBookmark(),this.history.save({emitEvent:!1})),this.renderBoxes(),this.toolbar&&this.toolbar.render(this),document.addEventListener("copy",this.copyListener),this.readonly||(document.addEventListener("cut",this.cutListener),document.addEventListener("paste",this.pasteListener),document.addEventListener("selectionchange",this.selectionchangeListener),document.addEventListener("click",this.clickListener),this.bindInputEvents(),this.bindHistoryEvents())}unmount(){this.updateSelectionRange.flush(),this.updateBoxSelectionStyle.flush(),this.emitStateChangeEvent.flush();for(const e of this.unmountPluginMap.keys()){const t=this.unmountPluginMap.get(e);t&&(t(),g(`Plugin "${e}" unmounted`))}this.toolbar&&this.toolbar.unmount(),this.removeBoxGarbage(),this.container.find("lake-box").each((e=>{_e(y(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))}}Ot.version="0.3.0",Ot.box=new class{add(e){E.set(e.name,e)}remove(e){E.delete(e)}getNames(){return Array.from(E.keys())}},Ot.plugin=new class{constructor(){this.pluginMap=new Map}add(e,t){if(this.pluginMap.get(e))throw new Error(`Plugin "${e}" is already defined.`);this.pluginMap.set(e,t)}loadAll(e){const t=new Map;for(const i of this.pluginMap.keys()){const n=this.pluginMap.get(i);if(n&&!1!==e.config[i]){const o=n(e);o&&t.set(i,o)}}return t}};function zt(e,t){const i=e.get(0),n=y(k`<${t} />`);for(const e of i.attributes)n.attr(e.name,e.value);let o=e.first();for(;o.length>0;){const e=o.next();n.append(o),o=e}return e.replaceWith(n),n}const $t=Array.from(s).join(",");function Vt(e){const t=[e];for(const i of e.getWalker())t.push(i);for(const e of t)"div"===e.name?e.find($t).length>0?e.remove(!0):zt(e,"p"):(e.isHeading||["blockquote","li"].indexOf(e.name)>=0)&&e.find($t).remove(!0)}function Rt(e,t){const i=e.selection,n=i.range;if(0===t.childNodes.length)return;const o=new w(t.firstChild);let s=new w(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"===_e(n).type)i.isBoxStart?(i.setStartBefore(n),i.collapseToStart()):i.isBoxEnd?(i.setStartAfter(n),i.collapseToStart()):e.selection.removeBox();else{const t=y("<p />");i.isBoxStart?(n.before(t),i.shrinkAfter(t)):i.isBoxEnd?(n.after(t),i.shrinkAfter(t)):e.selection.removeBox()}const o=i.startNode.closestBlock();if(t.isBlockBox){const i=_e(t),n=""!==t.attr("value")?i.value:void 0;return e.selection.insertBox(i.name,n),void t.remove()}if(t.first().length>0&&Te(o),o.isEmpty&&"p"===o.name)return o.replaceWith(t),t.find("lake-box").each((e=>{_e(e).render()})),void i.shrinkAfter(t);let s=t.first();for(;s.length>0;){"li"===s.name&&(s=s.first());const t=s.next();e.selection.insertContents(s),s.isBox?_e(s).render():s.isElement&&s.find("lake-box").each((e=>{_e(e).render()})),s=t}t.remove()}(e,o);let r=new w(t.firstChild);for(;r.length>0;){const e=r.next();"br"===r.name&&r.remove(),r=e}if(s=new w(t.lastChild),t.childNodes.length>0){const o=i.splitBlock();o.start&&(n.setEndAfter(o.start),n.collapseToEnd()),o.end&&o.end.isEmpty&&o.end.remove(),i.insertContents(t),e.renderBoxes(),n.shrinkAfter(s)}Pe(e.container.children().filter((e=>e.isBlock))),e.history.save()}const Ft=["info","tip","warning","danger"];function Wt(e){e.selection.setBlocks("<p />")}function qt(e){e.selection.setBlocks("<ol><li></li></ol>")}function jt(e){e.selection.setBlocks("<ul><li></li></ul>")}function Ut(e,t){e.selection.setBlocks(`<ul type="checklist"><li value="${t}"></li></ul>`)}function Kt(e){const t=e.startNode.closest("table"),i=y("<p><br /></p>");t.replaceWith(i),e.shrinkBefore(i),g(`deleteTable: table ${t.id}`)}function Gt(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],o=t[i];let s=0;for(let e=0;e<n.cells.length;e++){for(s=e;o[s];)s++;const r=n.cells[e];for(let e=0;e<r.colSpan;e++)for(let n=0;n<r.rowSpan;n++){const o=t[i+n];o&&(o[s+e]=r)}}}return t}function Xt(e,t,i){const n=e[t];for(let e=0;e<n.length;e++){if(n[e]===i)return e}return-1}function Qt(e,t,i){const n=e[t],o=e[t-1];let s=i;for(let e=0;e<i;e++){const t=n[e];if(t===n[e+1])s--;else if(o){t===o[e]&&s--}}return s}function Yt(e,t){const i=e.startNode.closest("td"),n=i.closest("table"),o=i.closest("tr"),s=n.get(0),r=o.get(0),a=i.get(0),l=r.rowIndex,c=Gt(s);let d=Xt(c,l,a);if("right"===t){const e=c[l];for(d++;e&&a===e[d];)d++}g(`insertColumn: rows ${s.rows.length}, column ${d}, ${t}`);for(let e=0;e<s.rows.length;e++){const t=s.rows[e],i=c[e],n=Qt(c,e,d),o=t.cells[n];if(o&&o.colSpan>1&&o===i[d-1])o.colSpan+=1,o.rowSpan>1&&(e+=o.rowSpan-1);else{t.insertCell(n).innerHTML="<p><br /></p>"}}}function Jt(e,t){const i=e.startNode.closest("td"),n=i.closest("table"),o=i.closest("tr"),s=n.get(0),r=o.get(0);let a=Gt(s);const l=a[0].length;let c;c="up"===t?r.rowIndex:r.rowIndex+1;const d=s.rows[c];g(`insertRow: rows ${s.rows.length}, target row ${c}`);const h=s.insertRow(c);if(!d){for(let e=0;e<l;e++){h.insertCell(h.cells.length).innerHTML="<p><br /></p>"}return}a=Gt(s),c=d.rowIndex;let p=-1;for(let e=0;e<l;e++){const t=Qt(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=s.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 ei=[{value:"insertLeft",text:e=>e.table.insertColumnLeft()},{value:"insertRight",text:e=>e.table.insertColumnRight()},{value:"delete",text:e=>e.table.deleteColumn()}],ti=[{value:"insertAbove",text:e=>e.table.insertRowAbove()},{value:"insertBelow",text:e=>e.table.insertRowBelow()},{value:"delete",text:e=>e.table.deleteRow()}],ii=[{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()}],ni=[{value:"leftRight",text:e=>e.table.splitLeftRight()},{value:"topBottom",text:e=>e.table.splitTopBottom()}];function oi(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:$,menuWidth:"296px",selectedValues:()=>{const t=e.selection.range.startNode.closest("td");if(t.length>0){return[m(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:ei,menuCheck:!1,onSelect:(t,i)=>{const n=e.selection.range;"insertLeft"===i?Yt(n,"left"):"insertRight"===i?Yt(n,"right"):function(e){const t=e.startNode.closest("td"),i=t.closest("table"),n=t.closest("tr"),o=i.get(0),s=n.get(0),r=t.get(0),a=s.rowIndex,l=Gt(o),c=Xt(l,a,r);let d=null;const h=r.cellIndex;s.cells[h+1]?d=s.cells[h+1]:s.cells[h-1]&&(d=s.cells[h-1]),g(`deleteColumn: rows ${o.rows.length}, column ${c}`);const p=function(e,t){for(let i=0;i<e.length;i++){const n=e[i][t],o=e[i+1];if(o&&n.colSpan!==o[t].colSpan)return!1}return!0}(l,c);for(let t=0;t<o.rows.length;t++){const i=o.rows[t],n=Qt(l,t,c),s=i.cells[n];s.rowSpan>1&&(t+=s.rowSpan-1),s.colSpan>1&&!p?(s.colSpan-=1,1===s.colSpan&&s.removeAttribute("colSpan")):(s===r&&d&&e.shrinkBefore(y(d)),i.deleteCell(n))}0===o.rows[0].cells.length&&Kt(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:ti,menuCheck:!1,onSelect:(t,i)=>{const n=e.selection.range;"insertAbove"===i?Jt(n,"up"):"insertBelow"===i?Jt(n,"down"):function(e){const t=e.startNode.closest("td"),i=t.closest("table"),n=t.closest("tr"),o=i.get(0),s=n.get(0),r=t.get(0),a=s.rowIndex;let l=Gt(o);const c=l[0].length,d=Xt(l,a,r),h=o.rows[a+1]||o.rows[a-1];g(`deleteRow: rows ${o.rows.length}, target row ${a}, column ${d}`);for(let e=a-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>a-e&&(n.rowSpan-=1,1===n.rowSpan&&n.removeAttribute("rowSpan"))}}const p=o.rows[a+1];if(p){let e=-1;for(let t=0;t<c;t++){const i=Qt(l,a,t);if(i!==e){e=i;const n=s.cells[i];if(n.rowSpan>1){const e=Qt(l,a+1,t);let i=p.insertCell(e);const o=n.cloneNode(!0);o.removeAttribute("rowSpan"),i.replaceWith(o),i=o,n.rowSpan>2&&(i.rowSpan=n.rowSpan-1)}}}}if(o.deleteRow(a),h){l=Gt(o);const t=Qt(l,h.rowIndex,d),i=h.cells[t];i&&e.shrinkBefore(y(i))}0===o.rows.length&&Kt(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:ii,menuCheck:!1,onSelect:(t,i)=>{!function(e,t){const i=e.startNode.closest("td"),n=i.closest("table"),o=i.closest("tr"),s=n.get(0),r=o.get(0),a=i.get(0),l=r.rowIndex,c=Gt(s);if("left"===t||"right"===t){const i=a.cellIndex;let n,o,s;if("left"===t?(n=r.cells[i-1],o=i,s=a):(n=a,o=i+1,s=r.cells[o]),!n||!s)return;if(g(`mergeCells: row ${l}, cell ${i}, other row ${l}, other cell ${o}`),n.rowSpan!==s.rowSpan)return;const d=c[l],h=Xt(c,l,n),p=Xt(c,l,s);if(d[h+1]!==s&&d[p-1]!==n)return;return n.colSpan+=s.colSpan,Me(y(n),y(s)),void e.shrinkBefore(y(n))}const d=Xt(c,l,a);let h,p,u,m,f,v;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,f=a.cellIndex,v=a}else{h=r.rowIndex,p=a,u=-1,v=null,f=-1;for(let e=r.rowIndex+1;e<s.rows.length;e++){const t=c[e];if(!t)break;const i=t[d];if(!i)break;if(i!==v){u=e,v=i,f=v.cellIndex;break}}if(m=s.rows[u],!m)return}p&&v&&(g(`mergeCells: row ${h}, cell ${p.cellIndex}, other row ${u}, other cell ${f}`),p.colSpan===v.colSpan&&(p.rowSpan+=v.rowSpan,Me(y(p),y(v)),e.shrinkBefore(y(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:ni,menuCheck:!1,onSelect:(t,i)=>{!function(e,t){const i=e.startNode.closest("td"),n=i.closest("table"),o=i.closest("tr"),s=n.get(0),r=o.get(0),a=i.get(0),l=r.rowIndex,c=a.rowSpan,d=a.colSpan;let h=Gt(s);const p=Xt(h,l,a);if(g(`splitCell: row ${l}, cell ${p}, ${t}`),"topBottom"!==t)for(let e=0;e<h.length;e++){const t=s.rows[e],i=h[e],n=i[p];if(n===a){const i=h[e-1];if(!i||n!==i[p]){const i=Qt(h,e,p),o=t.insertCell(i+1);o.innerHTML="<p><br /></p>",n.rowSpan>1&&(o.rowSpan=n.rowSpan),n.colSpan>2&&(o.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?s.rows[l+1]:s.insertRow(l+1),t=Qt(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=Gt(s)}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=Gt(s)}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:()=>{Kt(e.selection.range),e.history.save()}}];return i}const si={start:"left",end:"right"};function ri(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 Pe([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 ai="strong";const li="sub";const ci="sup";const di="code";const hi="lake-format-painter";function pi(e,t,i,n){return new(i||(i=Promise))((function(o,s){function r(e){try{l(n.next(e))}catch(e){s(e)}}function a(e){try{l(n.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?o(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 ui{constructor(e){this.linkNode=null,this.scrollListener=()=>this.updatePosition(),this.resizeListener=()=>this.updatePosition(),this.config=e||{},this.locale=this.config.locale||de("en-US"),this.container=y(k`
22
+ `),e=this.getContainer()):(e.off("mouseenter"),e.off("mouseleave"),e.off("click")),e.on("mouseenter",(()=>{e.hasClass("lake-box-selected")||e.hasClass("lake-box-focused")||e.hasClass("lake-box-activated")||e.addClass("lake-box-hovered")})),e.on("mouseleave",(()=>{e.removeClass("lake-box-hovered")})),e.on("click",(()=>{g(`Box "${this.name}" (id = ${this.node.id}) value:`),g(this.value)})),"block"===this.type&&this.node.isContentEditable&&e.attr("draggable","true")}get type(){return this.node.attr("type")}get name(){return this.node.attr("name")}get value(){const e=this.node.attr("value");return""===e?{}:JSON.parse(P(e))}set value(e){this.node.attr("value",M(JSON.stringify(e)))}updateValue(e,t){const i=this.value;if("string"==typeof e)i[e]=t;else for(const t of Object.keys(e))i[t]=e[t];this.value=i}getEditor(){const e=this.node.closest("div[contenteditable]"),t=e.length>0?I.get(e.id):void 0;if(!t)throw new Error(`Box "${this.name}" (id=${this.node.id}) is not rendered in the editor.`);return t}getContainer(){return this.node.find(".lake-box-container")}setToolbar(e){const t=this.getEditor();this.event.on("focus",(()=>{this.toolbar&&this.toolbar.unmount(),this.toolbar=new ge({target:this.node,items:e}),this.toolbar.render();const i=t.selection.getActiveItems();this.toolbar.updateState({activeItems:i}),this.event.emit("renderfloatingtoolbar")})),this.event.on("blur",(()=>{this.toolbar&&(this.toolbar.unmount(),this.toolbar=null)}))}render(){const e=E.get(this.name);if(void 0===e)return;this.event.emit("beforeunmount"),this.event.removeAllListeners(),this.initiate();const t=e.render(this);if(void 0!==t){const e=this.getContainer();e.empty(),e.append(t)}g(`Box "${this.name}" (id: ${this.node.id}) rendered`)}unmount(){this.event.emit("blur"),this.event.emit("beforeunmount"),this.event.removeAllListeners(),this.node.empty(),g(`Box "${this.name}" (id: ${this.node.id}) unmounted`)}getHTML(){const e=E.get(this.name);return void 0===e?"":void 0===e.html?this.node.outerHTML():e.html(this)}}const ve={id:/^[\w-]+$/,class:/^[\w- ]+$/,style:{"text-align":["left","center","right","justify","start","end"],"margin-left":/^-?\d+px$/i,"text-indent":/^-?\d+em$/i}};function we(){return{h1:Object.assign({},ve),h2:Object.assign({},ve),h3:Object.assign({},ve),h4:Object.assign({},ve),h5:Object.assign({},ve),h6:Object.assign({},ve),p:Object.assign({},ve),blockquote:Object.assign(Object.assign({},ve),{type:["info","tip","success","warning","error","danger"]}),ul:Object.assign(Object.assign({},ve),{type:"checklist",indent:/^\d+$/}),ol:Object.assign(Object.assign({},ve),{start:/^\d+$/,indent:/^\d+$/}),li:{value:["true","false"]},table:{style:{width:/^-?\d+(px|%)$/i,height:/^-?\d+(px|%)$/i,border:/^[^"]+$/,"border-width":/^-?\d+px$/i,"border-style":/^[\w-]+$/,"border-color":/^[^"]+$/,"background-color":/^[^"]+$/}},tr:{style:{height:/^-?\d+(px|%)$/i}},th:"td",td:{colspan:/^\d+$/,rowspan:/^\d+$/,style:{width:/^-?\d+(px|%)$/i,height:/^-?\d+(px|%)$/i,border:/^[^"]+$/,"border-width":/^-?\d+px$/i,"border-style":/^[\w-]+$/,"border-color":/^[^"]+$/,"background-color":/^[^"]+$/,"text-align":["left","center","right","justify"]}},"lake-box":{type:["inline","block"],name:/^[\w-]+$/,value:/^[^"]+$/,focus:["start","center","end"]},br:{},hr:{},img:{src:/^[^"]+$/,width:/^-?\d+px$/i,height:/^-?\d+px$/i,"data-lake-value":/^[^"]+$/,alt:/^[^"]+$/,style:{width:/^-?\d+px$/i,height:/^-?\d+px$/i}},span:{class:/^[\w- ]+$/,style:{color:/^[^"]+$/,"background-color":/^[^"]+$/,"font-family":/^[^;]+$/,"font-size":/^[^"]+$/}},b:"strong",strong:{},em:"i",i:{},u:{},s:{},sub:{},sup:{},code:{},a:{class:/^[\w- ]+$/,name:/^[\w-]+$/,href:/^[^"]+$/,target:/^[\w-]+$/,rel:/^[^"]+$/,download:/^[^"]+$/},"lake-bookmark":{type:["anchor","focus"]}}}function ye(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=m(n[2]).trim();t[e]=i}return t}class xe{constructor(e,t=we()){this.rules=t,this.source="string"==typeof e?this.parseHTML(e):e}parseHTML(e){const t=(new DOMParser).parseFromString(e,"text/html");return new w(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 o=e.get(0);if(!o.hasAttributes())return i;const s=new Map;for(const e of o.attributes)if(n[e.name]&&("style"!==e.name&&xe.matchRule(n[e.name],e.value)&&s.set(e.name,e.value),"style"===e.name)){const t=n.style,i=new Map,o=ye(e.value);for(const e of Object.keys(o)){const n=o[e];t[e]&&xe.matchRule(t[e],n)&&i.set(e,n)}s.set("style",i)}let r=i;for(const[e,t]of s)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 o=e.text();return(i.isBlock||i.isBlockBox)&&(n.isBlock||n.isBlockBox)||0===i.length&&0===n.length&&t.isBlock?o=o.replace(/^[\u0020\t\r\n]+|[\u0020\t\r\n]+$/g,""):i.isBlock||i.isBlockBox||0===i.length&&t.isBlock?o=o.replace(/^[\u0020\t\r\n]+/,""):(n.isBlock||n.isBlockBox||0===n.length&&t.isBlock)&&(o=o.replace(/[\u0020\t\r\n]+$/,"")),o}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 b(xe.getTrimmedText(n));else if(n.isVoid){const t=xe.getOpenTagString(n,e);""!==t&&(yield`<${t} />`)}else if(n.isElement){const i=xe.getOpenTagString(n,e),o=xe.getClosedTagString(n,e);""!==i&&(yield`<${i}>`),n.isBox||(yield*t(n)),""!==o&&(yield`</${o}>`)}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 be{constructor(e){this.content=e}getHTML(){let e=this.content;return e=e.replace(/ {2}/g,"  "),e=b(e.trim()),e=`<p>${e}</p>`,e=e.replace(/(\r\n){2,}/g,"</p><p><br /></p><p>"),e=e.replace(/\r\n/g,"</p><p>"),e=e.replace(/[\r\n]{2,}/g,"</p><p><br /></p><p>"),e=e.replace(/[\r\n]/g,"</p><p>"),e}getFragment(){return new xe(this.getHTML()).getFragment()}}function ke(e,t){const i=e.get(),n=t.get(0);i.insertNode(n),i.setEndAfter(n),i.collapse(!1)}function Ce(e){if(e.commonAncestor.isOutside)return{anchor:new w,focus:new w};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 w,focus:t};if(e.isCollapsed){const t=e.clone();t.collapseToEnd();const i=y('<lake-bookmark type="focus" />');return ke(t,i),{anchor:new w,focus:i}}const i=e.clone();i.collapseToStart();const n=y('<lake-bookmark type="anchor" />');ke(i,n);const o=e.clone();o.collapseToEnd();const s=y('<lake-bookmark type="focus" />');return ke(o,s),{anchor:n,focus:s}}const Se=new Map;function Be(e){let t=Se.get(e);return t||(t=new Map,Se.set(e,t),t)}function _e(e){const t=Be(0);if("string"==typeof e){const i=new fe(e);return t.set(i.node.id,i),i}const i=(e=y(e)).closestContainer();if(0===i.length){let i=t.get(e.id);return i||(i=new fe(e),t.set(e.id,i),i)}const n=Be(i.id);let o=t.get(e.id);return o?(n.set(e.id,o),t.delete(e.id),o):(o=n.get(e.id),o||(o=new fe(e),n.set(e.id,o),o))}function Ae(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 w(document.createTextNode("​"));e.before(i),t.setStartAfter(i),t.collapseToStart()}e.remove()}else e.remove()}function Le(e,t){const i=t.anchor,n=t.focus;if(i.length>0&&0===n.length)Ae(i);else{if(n.length>0&&0===i.length){if(n.isBox){const t=_e(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 Ae(n,e)}if(i.length>0&&n.length>0){const t=new S;t.selectNode(i),t.collapseToEnd(),-1===t.compareAfterNode(n)?(e.setStartBefore(n),Ae(n),e.setEndBefore(i),Ae(i)):(e.setStartBefore(i),Ae(i),e.setEndBefore(n),Ae(n))}}}function Te(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 Ee(e){const t=y("<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 Ie(e){if(e.isText)return{node:e,offset:e.text().length};const t=new S;return t.setEndAfter(e),{node:t.endNode,offset:t.endOffset}}function Me(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 Ie(e);Te(e),Te(t),e.isBlock&&e.isEmpty&&t.isEmpty&&Ee(e);const n=e.last(),o=t.first();let s=o;for(;s.length>0;){const t=s.next();e.append(s),s=t}return i.remove(),n.length>0&&o.length>0&&n.isElement&&!n.isBox&&n.clone(!1).get(0).isEqualNode(o.clone(!1).get(0))?Me(n,o):0===n.length?{node:e,offset:0}:Ie(n)}function Pe(e){if(0===e.length)return;const t=e[0],i=e[e.length-1],n=[];let o=t.prev();for(;o.length>0&&"ol"===o.name;)n.push(o),o=o.prev();n.reverse(),n.push(...e);let s=i.next();for(;s.length>0&&"ol"===s.name;)n.push(s),s=s.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 He(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=Ee(t);e.setStartBefore(i),e.collapseToStart()}return}const o=e.getBlocks()[0];if(!o)return;const s=o.prev();if(0===s.length)return;const r=Ce(e);Me(s,o),Pe([s]),Le(e,r)}function Ze(e,t){if(e.commonAncestor.isOutside)return;let i;t instanceof C?i=t:t instanceof DocumentFragment?i=new C(t):(i=new C,i.append(t)),e.isCollapsed?e.adjustBox():He(e);Te(e.startNode.closestBlock());const n=e.get();n.insertNode(i.get()),n.collapse(!1),e.adjustBlock()}function De(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 Ne(e,t){if(t=null!=t?t:y("<p />"),0===e.length)return t;const i=De(t=t.clone(!0));e[0].before(t);for(const t of e)i.append(t);return t}function Oe(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=y(t),n=i.name,o=i.get(0).attributes,s=e.getBlocks();if(s.length>0){const t=Ce(e);for(const e of s)if(e.name===n&&0===i.first().length)for(const t of o)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=De(t);let o=e.first();for(;o.length>0;){const e=o.next();n.append(o),n.name!==o.name&&"li"!==o.name||o.remove(!0),o=e}e.replaceWith(t)}return Le(e,t),void Pe(e.getBlocks())}if(e.isCollapsed){const t=e.getNextNode();if("br"===t.name){const i=y("<p><br /></p>");return t.replaceWith(i),void e.shrinkBefore(i)}const i=e.getPrevNode();if("br"===i.name){const t=y("<p><br /></p>");return i.replaceWith(t),void e.shrinkBefore(t)}}const r=Ce(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(),o=!0;for(;n.length>0;){if(n.isMark||n.isText||n.isBookmark||n.isInlineBox)i.push(n);else{if(!o)break;i=[]}e.intersectsNode(n)&&(o=!1),n=n.next()}return i}(e),l=Ne(a,i);if(Le(e,r),Pe(e.getBlocks()),l.isEmpty){const t=Ee(l);e.setStartBefore(t),e.collapseToStart()}}function ze(e,t,i){const n=new S;let o;if(e.isText){o=e.parent();const i=e.splitText(t);n.setStartAfter(e),""===e.text()&&e.remove(),""===i.text()&&i.remove()}else n.setStart(e,t),o=e;if("body"===o.name||"html"===o.name)return null;if(o.get(0)===i.get(0))return null;n.collapseToStart();const s=o.clone();let r=o.first();for(;r.length>0&&!(n.compareBeforeNode(r)>=0);){const e=r.next();s.append(r),r=e}return o.before(s),o.parent().length>0&&o.parent().get(0)!==i.get(0)?ze(o.parent(),o.index(),i):{start:s,end:o}}function $e(e){if(e.isMark&&e.isEmpty)e.remove();else for(const t of e.getWalker())t.isMark&&t.isEmpty&&t.remove()}function Ve(e){if(e.commonAncestor.isOutside)return{start:null,end:null};e.isCollapsed?e.adjustBox():He(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 o=ze(t,e.startOffset,n);let s=null,r=null;return o&&(s=o.start,r=o.end),!o&&t.isBlock&&(e.startOffset>0&&(s=t.children()[e.startOffset-1]),r=t.children()[e.startOffset],r&&!r.isBlock&&(r=null)),s&&s.isEmpty&&($e(s),Ee(s)),r&&(r.isEmpty&&($e(r),Ee(r)),e.shrinkBefore(r)),Pe(e.getBlocks()),{start:s,end:r}}function Re(e,t){if(e.commonAncestor.isOutside)return null;const i=y(t),n=Ve(e);return n.start&&($e(n.start),e.setEndAfter(n.start),e.collapseToEnd()),n.end&&($e(n.end),n.end.isEmpty&&n.end.remove()),Ze(e,i),i.isBox||e.shrinkAfter(i),n.start&&n.start.isEmpty&&n.start.remove(),i}function Fe(e,t,i){let n=null,o=null,s=e.closestBlock();0===s.length&&(s=e.closestContainer());const r=ze(e,t,s);return r&&(i?($e(r.start),$e(r.end),r.start.isEmpty||(n=r.start),r.end.isEmpty||(o=r.end)):(n=r.start,o=r.end)),{start:n,end:o}}function We(e,t=!0){if(e.commonAncestor.isOutside)return{start:null,center:null,end:null};if(e.adjustBox(),e.isCollapsed){const i=Fe(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=Fe(e.startNode,e.startOffset,t);i.start?e.setStartAfter(i.start):i.end&&e.setStartBefore(i.end);const n=Fe(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 qe(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 je(e,t){if(e.commonAncestor.isOutside)return;let i=y(t);const n=i.name,o=ye(i.attr("style"));if(e.isCollapsed){if(e.isBox){const t=e.startNode.closest("lake-box");if("block"===_e(t).type){const i=y("<p><br /></p>");e.isBoxStart?t.before(i):t.after(i),e.shrinkAfter(i)}else e.adjustBox()}Te(e.startNode.closestBlock());const t=new w(document.createTextNode("​")),s=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(We(e),s){let e=s;for(;e.length>0;)e.name===n&&e.css(o),e=e.first();s.name===n?i=s:i.append(s)}if(""===i.text()){De(i).append(t)}return Ze(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)}We(e);const s=e.getMarks(!0),r=Ce(e);for(const e of s)if(!e.isEmpty&&e.isText){const t=qe(e,n);if(t.isMark&&t.name===n)t.css(o);else{const e=i.clone();t.before(e),e.append(t)}}Le(e,r)}function Ue(e,t){if(e.commonAncestor.isOutside)return;let i;if(t){i=y(t).name}if(e.isCollapsed){if(e.isBox)return;if(i&&0===e.commonAncestor.closest(i).length)return;const t=We(e,!1);if(!t.start)return;t.end&&$e(t.end);const n=new w(document.createTextNode("​")),o=function(e,t){if(!e.isMark||!t)return null;let i=null,n=null,o=e;for(;o.length>0&&o.isMark;){if(o.name!==t)if(n){const e=o.clone();n.append(e),n=e}else i=o.clone(),n=i;o=o.last()}return i}(t.start,i);if(!o)return t.start.after(n),$e(t.start),n.prev().isText?(e.setStartAfter(n.prev()),e.collapseToStart(),void n.remove()):(e.setStartAfter(n),void e.collapseToStart());return De(o).append(n),t.start.after(o),$e(t.start),void e.shrinkAfter(o)}We(e);const n=e.getMarks(),o=Ce(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),Le(e,o)}function Ke(e,t,i){if(e.commonAncestor.isOutside)return null;const n=_e(t);if(i&&(n.value=i),"inline"===n.type){if(We(e),Ze(e,n.node),n.render(),n.node.isTopInside){const e=y("<p />");n.node.before(e),e.append(n.node)}return e.selectBoxEnd(n.node),_e(n.node)}return Re(e,n.node),n.render(),e.selectBoxEnd(n.node),_e(n.node)}function Ge(e){const t=e.node.closestContainer();if(e.unmount(),e.node.remove(),t.length>0){Be(t.id).delete(e.node.id);Be(0).set(e.node.id,e)}return e}function Xe(e){if(e.commonAncestor.isOutside)return null;const t=e.commonAncestor.closest("lake-box");if(0===t.length)return null;const i=_e(t);if("block"===i.type){const n=y("<p><br /></p>");return t.before(n),e.shrinkAfter(n),Ge(i)}e.setStartBefore(t),e.collapseToStart();const n=t.parent();if(Ge(i),n.isEmpty){const t=Ee(n);e.setStartBefore(t),e.collapseToStart()}return i}var Qe,Ye={exports:{}};function Je(){if(Qe)return Ye.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 o,s,r,a,l;function c(){const t=o,i=s;return o=void 0,s=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(o&&this!==o&&Object.getPrototypeOf(this)===Object.getPrototypeOf(o))throw new Error("Debounced method called with different contexts of the same prototype.");o=this,s=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 Qe=1,Ye.exports.debounce=e,Ye.exports=e,Ye.exports}var et,tt,it=B(Je());var nt=B(tt?et:(tt=1,et=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,o,s;if(Array.isArray(t)){if((n=t.length)!=i.length)return!1;for(o=n;0!=o--;)if(!e(t[o],i[o]))return!1;return!0}if(t instanceof Map&&i instanceof Map){if(t.size!==i.size)return!1;for(o of t.entries())if(!i.has(o[0]))return!1;for(o of t.entries())if(!e(o[1],i.get(o[0])))return!1;return!0}if(t instanceof Set&&i instanceof Set){if(t.size!==i.size)return!1;for(o of t.entries())if(!i.has(o[0]))return!1;return!0}if(ArrayBuffer.isView(t)&&ArrayBuffer.isView(i)){if((n=t.length)!=i.length)return!1;for(o=n;0!=o--;)if(t[o]!==i[o])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=(s=Object.keys(t)).length)!==Object.keys(i).length)return!1;for(o=n;0!=o--;)if(!Object.prototype.hasOwnProperty.call(i,s[o]))return!1;for(o=n;0!=o--;){var r=s[o];if(!e(t[r],i[r]))return!1}return!0}return t!=t&&i!=i}));function ot(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 st(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 rt(e,t){const i=H(e);0===i.left&&0===i.right&&0===i.top&&0===i.bottom||e.get(0).scrollIntoView(t)}function at(e){const t=e.get(0),i={};if(t.hasAttributes())for(const e of t.attributes)i[e.name]=e.value;return i}class lt{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 S(e)}return new S}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 Le(e,{anchor:new w,focus:i}),void this.sync();Le(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:at(i),styles:ye(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:at(t),styles:ye(t.attr("style"))}),t=t.first()}}(e,this.range),e}insertBookmark(){return Ce(this.range)}toBookmark(e){return Le(this.range,e)}insertContents(e){return Ze(this.range,e)}deleteContents(){return He(this.range)}setBlocks(e){return Oe(this.range,e)}splitBlock(){return Ve(this.range)}insertBlock(e){return Re(this.range,e)}splitMarks(e){return We(this.range,e)}addMark(e){return je(this.range,e)}removeMark(e){return Ue(this.range,e)}selectBox(e){let t=e;t=e instanceof fe?e.node:e,this.range.selectBox(t),this.sync()}insertBox(e,t){const i=Ke(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),Xe(this.range)}}class ct{constructor(e){this.commandMap=new Map,this.selection=e}add(e,t){this.commandMap.set(e,t)}delete(e){this.commandMap.delete(e)}getNames(){return Array.from(this.commandMap.keys())}has(e){return void 0!==this.commandMap.get(e)}getItem(e){const t=this.commandMap.get(e);if(void 0===t)throw new Error(`Command "${e}" has not been defined yet.`);return t}isDisabled(e){const t=this.getItem(e);if(!t.isDisabled)return!1;const i=this.selection.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),g(`Command "${e}" executed`)}}const dt=new Set;function ht(){}const pt={morphStyle:"outerHTML",callbacks:{beforeNodeAdded:ht,afterNodeAdded:ht,beforeNodeMorphed:ht,afterNodeMorphed:ht,beforeNodeRemoved:ht,afterNodeRemoved:ht,beforeAttributeUpdated:ht,afterAttributeUpdated:ht,beforeChildrenUpdated:ht},head:{style:"merge",shouldPreserve:e=>"true"===e.getAttribute("im-preserve"),shouldReAppend:e=>"true"===e.getAttribute("im-re-append"),shouldRemove:ht,afterHeadMorphed:ht}};function ut(e,t){return!e.deadIds.has(t)}function mt(e,t,i){return(e.idMap.get(i)||dt).has(t)}function gt(e,t){const i=e.idMap.get(t)||dt;for(const t of i)e.deadIds.add(t)}function ft(e,t,i){const n=e.idMap.get(t)||dt;let o=0;for(const t of n)ut(e,t)&&mt(e,t,i)&&++o;return o}function vt(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 wt(e,t){const i=new Map;return vt(e,i),vt(t,i),i}function yt(e,t,i){return{target:e,newContent:t,config:i=function(e){const t={};return Object.assign(t,pt),Object.assign(t,e),t.callbacks={},Object.assign(t.callbacks,pt.callbacks),Object.assign(t.callbacks,e.callbacks),t.head={},Object.assign(t.head,pt.head),Object.assign(t.head,e.head),t}(i),morphStyle:i.morphStyle,ignoreActive:i.ignoreActive,ignoreActiveValue:i.ignoreActiveValue,idMap:wt(e,t),deadIds:new Set,callbacks:i.callbacks,head:i.head}}function xt(e,t,i){return null!=e&&null!=t&&(e.nodeType===t.nodeType&&e.tagName===t.tagName&&(""!==e.id&&e.id===t.id||ft(i,e,t)>0))}function bt(e,t){return null!=e&&null!=t&&(e.nodeType===t.nodeType&&e.tagName===t.tagName)}function kt(e,t){gt(t,e),!1!==t.callbacks.beforeNodeRemoved(e)&&(e.remove(),t.callbacks.afterNodeRemoved(e))}function Ct(e,t,i){let n=e;for(;n&&n!==t;){const e=n;n=n.nextSibling,kt(e,i)}return gt(i,t),t.nextSibling}function St(e,t,i,n,o){const s=ft(o,i,t);let r=null;if(s>0){r=n;let t=0;for(;null!=r;){if(xt(i,r,o))return r;if(t+=ft(o,r,e),t>s)return null;r=r.nextSibling}}return r}function Bt(e,t,i,n,o){let s=n,r=i.nextSibling,a=0;for(;null!=s;){if(ft(o,s,e)>0)return null;if(bt(i,s))return s;if(bt(r,s)&&(a++,r=r?r.nextSibling:null,a>=2))return null;s=s?s.nextSibling:null}return s}function _t(e,t,i){return bt(e,t)?.5+ft(i,e,t):0}function At(e,t,i,n){return!("value"!==e||!n.ignoreActiveValue||t!==document.activeElement)||!1===n.callbacks.beforeAttributeUpdated(e,t,i)}function Lt(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):bt(e,t)?(!1===i.callbacks.beforeNodeMorphed(e,t)||(function(e,t,i){const n=e.nodeType;if(1===n){const n=e.attributes,o=t.attributes;for(const e of n)At(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=o.length-1;n>=0;n--){const s=o[n];At(s.name,t,"remove",i)||e.hasAttribute(s.name)||(t.removeAttribute(s.name),i.callbacks.afterAttributeUpdated(s.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)||Tt(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 Tt(e,t,i){let n,o=e.firstChild,s=t.firstChild;for(;o;){if(n=o,o=n.nextSibling,null==s){if(!1===i.callbacks.beforeNodeAdded(n))return;t.appendChild(n),i.callbacks.afterNodeAdded(n),gt(i,n);continue}if(xt(n,s,i)){Lt(s,n,i),s=s.nextSibling,gt(i,n);continue}const r=St(e,t,n,s,i);if(r){s=Ct(s,r,i),Lt(r,n,i),gt(i,n);continue}const a=Bt(e,0,n,s,i);if(a)s=Ct(s,a,i),Lt(a,n,i),gt(i,n);else{if(!1===i.callbacks.beforeNodeAdded(n))return;t.insertBefore(n,s),i.callbacks.afterNodeAdded(n),gt(i,n)}}for(;null!==s;){const e=s;s=s.nextSibling,kt(e,i)}}function Et(e,t,i){if("innerHTML"===i.morphStyle)return Tt(t,e,i),e.children;if("outerHTML"===i.morphStyle||null==i.morphStyle){const n=function(e,t,i){let n;n=e.firstChild;let o=n,s=0;for(;n;){const e=_t(n,t,i);e>s&&(o=n,s=e),n=n.nextSibling}return o}(t,e,i),o=null==n?void 0:n.previousSibling,s=null==n?void 0:n.nextSibling,r=Lt(e,n,i);return n?function(e,t,i){var n,o;const s=[],r=[];let a=e;for(;null!=a;)s.push(a),a=a.previousSibling;for(;s.length>0;){const e=s.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;)s.push(l),r.push(l),l=l.nextSibling;for(;s.length>0;){const e=s.pop();e&&(null===(o=t.parentElement)||void 0===o||o.insertBefore(e,t.nextSibling))}return r}(o,r,s):[]}throw`Do not understand how to morph style ${i.morphStyle}`}function It(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)),o=yt(e.get(0),n,i);Et(e.get(0),n,o)}class Mt{constructor(e){this.canSave=!0,this.list=[],this.index=0,this.limit=100,this.event=new T,this.selection=e,this.container=e.container}removeBookmark(e){return e.replace(/(<lake-box[^>]+)\s+focus="\w+"([^>]*>)/gi,"$1$2").replace(/<lake-bookmark\s+type="anchor">\s*<\/lake-bookmark>/gi,"").replace(/<lake-bookmark\s+type="focus">\s*<\/lake-bookmark>/gi,"")}getValue(e){return new xe(e).getHTML()}addIdToBoxes(e){e.find("lake-box").each((e=>{const t=new w(e),i=`${t.attr("name")}-${t.attr("value")}`;t.attr("id",i)}))}removeIdfromBoxes(e){e.find("lake-box").each((e=>{new w(e).removeAttr("id")}))}morphContainer(e){const t=this.container,i={beforeChildrenUpdated:e=>{if("lake-box"===new w(e).name)return!1},afterAttributeUpdated:(e,i)=>{const n=new w(i);if(["name","value"].indexOf(e)>=0&&"lake-box"===n.name){_e(n).unmount();Be(t.id).delete(n.id)}}},n=e.clone(!0);this.addIdToBoxes(t),this.addIdToBoxes(n),It(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=>{_e(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),o=e.clone();return o.selectBox(n),Ce(o),t}const i=e.startNode.path(),n=e.endNode.path(),o=t.find(i),s=t.find(n),r=e.clone();return r.setStart(o,e.startOffset),r.setEnd(s,e.endOffset),Ce(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(),g(`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(),g(`History redone (index: ${this.index})`)}continue(){this.canSave=!0}pause(){this.canSave=!1}save(e={}){var t,i,n;const o=null!==(t=e.inputType)&&void 0!==t?t:"",s=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)||(s?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),g(`History saved (index: ${this.index}, inputType: "${o}", update: ${s}, emitEvent: ${r})`),r&&this.event.emit("save",ot(l),{inputType:o,update:s,emitEvent:r}))}}var Pt,Ht={};var Zt=function(){if(Pt)return Ht;Pt=1,Object.defineProperty(Ht,"__esModule",{value:!0});for(var e="undefined"!=typeof window&&/Mac|iPod|iPhone|iPad/.test(window.navigator.platform),t={alt:"altKey",control:"ctrlKey",meta:"metaKey",shift:"shiftKey"},i={add:"+",break:"pause",cmd:"meta",command:"meta",ctl:"control",ctrl:"control",del:"delete",down:"arrowdown",esc:"escape",ins:"insert",left:"arrowleft",mod:e?"meta":"control",opt:"alt",option:"alt",return:"enter",right:"arrowright",space:" ",spacebar:" ",up:"arrowup",win:"meta",windows:"meta"},n={backspace:8,tab:9,enter:13,shift:16,control:17,alt:18,pause:19,capslock:20,escape:27," ":32,pageup:33,pagedown:34,end:35,home:36,arrowleft:37,arrowup:38,arrowright:39,arrowdown:40,insert:45,delete:46,meta:91,numlock:144,scrolllock:145,";":186,"=":187,",":188,"-":189,".":190,"/":191,"`":192,"[":219,"\\":220,"]":221,"'":222},o=1;o<20;o++)n["f"+o]=111+o;function s(e,t,i){t&&!("byKey"in t)&&(i=t,t=null),Array.isArray(e)||(e=[e]);var n=e.map((function(e){return r(e,t)})),o=function(e){return n.some((function(t){return a(t,e)}))};return null==i?o:o(i)}function r(e,o){var s=o&&o.byKey,r={},a=(e=e.replace("++","+add")).split("+"),d=a.length;for(var h in t)r[t[h]]=!1;var p=!0,u=!1,m=void 0;try{for(var g,f=a[Symbol.iterator]();!(p=(g=f.next()).done);p=!0){var v=g.value,w=v.endsWith("?")&&v.length>1;w&&(v=v.slice(0,-1));var y=c(v),x=t[y];if(v.length>1&&!x&&!i[v]&&!n[y])throw new TypeError('Unknown modifier: "'+v+'"');1!==d&&x||(s?r.key=y:r.which=l(v)),x&&(r[x]=!w||null)}}catch(e){u=!0,m=e}finally{try{!p&&f.return&&f.return()}finally{if(u)throw m}}return r}function a(e,t){for(var i in e){var n=e[i],o=void 0;if(null!=n&&((null!=(o="key"===i&&null!=t.key?t.key.toLowerCase():"which"===i?91===n&&93===t.which?91:t.which:t[i])||!1!==n)&&o!==n))return!1}return!0}function l(e){return e=c(e),n[e]||e.toUpperCase().charCodeAt(0)}function c(e){return e=e.toLowerCase(),e=i[e]||e}return Ht.default=s,Ht.isHotkey=s,Ht.isCodeHotkey=function(e,t){return s(e,t)},Ht.isKeyHotkey=function(e,t){return s(e,{byKey:!0},t)},Ht.parseHotkey=r,Ht.compareHotkey=a,Ht.toKeyCode=l,Ht.toKeyName=c,Ht}();class Dt{constructor(e){this.keydownEventList=[],this.keyupEventList=[],this.container=e,this.container.on("keydown",(e=>{const t=e;if(!t.isComposing&&!t.defaultPrevented)for(const e of this.keydownEventList)if(Zt.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(Zt.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 Nt={value:"<p><br /></p>",readonly:!1,spellcheck:!1,tabIndex:0,placeholder:"",indentWithTab:!0,lang:"en-US",minChangeSize:5,historySize:100,onMessage:(e,t)=>{"success"!==e?"warning"!==e?"error"===e&&console.error(t):console.warn(t):console.log(t)},slash:!1,mention:!1};class Ot{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 T,this.box=Ot.box,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 w(e.target);t.get(0).isConnected&&this.event.emit("click",t)},this.updateSelectionRange=it((()=>{this.selection.updateByRange()}),1,{immediate:!0}),this.updateBoxSelectionStyle=it((()=>{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=_e(i),o=n.getContainer();if(0!==o.length){if(e.compareBeforeNode(o)<0&&e.compareAfterNode(o)>0&&(!e.isCollapsed||e.startNode.get(0)!==o.get(0)||0!==e.startOffset))return o.removeClass("lake-box-hovered"),o.removeClass("lake-box-selected"),o.removeClass("lake-box-focused"),o.addClass("lake-box-activated"),void n.event.emit("focus");if(t.intersectsNode(n.node))return o.removeClass("lake-box-activated"),void(e.isCollapsed?(o.removeClass("lake-box-hovered"),o.removeClass("lake-box-selected"),o.addClass("lake-box-focused"),n.event.emit("focus")):(o.removeClass("lake-box-focused"),o.addClass("lake-box-selected"),n.event.emit("blur")));o.removeClass("lake-box-activated"),o.removeClass("lake-box-focused"),o.removeClass("lake-box-selected"),n.event.emit("blur")}}))}),50,{immediate:!0}),this.emitStateChangeEvent=it((()=>{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,o=new Map;if(t.length>0)for(const s of e){const e=this.command.getItem(s);if(e.isDisabled&&e.isDisabled(t)&&i.set(s,!0),e.isSelected&&e.isSelected(t)&&n.set(s,!0),e.selectedValues){const i=e.selectedValues(t);i.length>0&&o.set(s,i)}}const s={activeItems:t,disabledNameMap:i,selectedNameMap:n,selectedValuesMap:o};nt(s,this.state)||(this.toolbar&&this.toolbar.updateState(s),this.event.emit("statechange",s),this.state=s)}),50,{immediate:!1}),!e.root)throw new Error("The root of the config must be specified.");this.root=y(e.root),this.toolbar=e.toolbar,this.config=Object.assign({},Nt);for(const t of Object.keys(e))this.config[t]=e[t];this.containerWrapper=y('<div class="lake-container-wrapper" />'),this.container=y('<div class="lake-container" />'),this.overlayContainer=y('<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 lt(this.container),this.command=new ct(this.selection),this.history=new Mt(this.selection),this.history.limit=this.config.historySize,this.keystroke=new Dt(this.container),I.set(this.container.id,this)}togglePlaceholderClass(e){const t="lake-placeholder";"<p><br /></p>"===(e=ot(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"===_e(n).type)t.isBoxStart?(t.setStartBefore(n),t.collapseToStart()):(t.setStartAfter(n),t.collapseToStart());else{const e=y("<p />");t.isBoxStart?n.before(e):n.after(e),t.setStart(e,0),t.collapseToStart()}const o=i.text();i.html("<br />"),e.insertContents(document.createTextNode(o))}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=Be(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())}))}get locale(){return de(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,o=i.children();for(const e of o)(e.isBlock||e.isMark)&&""===e.html()&&(e.remove(),n=!0,g(`Content fixed: empty tag "${e.name}" was removed`));if(o=i.children(),0===o.length)i.html("<p><br /></p>"),e.shrinkBefore(i),n=!0,g("Content fixed: default paragraph was added");else if(1===o.length){const t=o[0];if(t.isVoid){const i=y("<p />");t.before(i),i.append(t),e.shrinkAfter(i),n=!0,g(`Content fixed: void element "${t.name}" was wrapped in paragraph`)}}return e.adjustBr(),n}renderBoxes(){this.removeBoxGarbage();const e=this.container,t=Be(e.id);e.find("lake-box").each((e=>{const i=y(e);if(t.get(i.id))return;_e(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=y('<div class="lake-artificial-cursor" />'),o=t.x-i.x,s=t.y-i.y;n.css({position:"absolute",top:`${s}px`,left:`${o}px`,width:`${t.width}px`,height:`${t.height}px`,"z-index":"-1"}),this.overlayContainer.find(".lake-artificial-cursor").remove(),this.overlayContainer.append(n),rt(n,{behavior:"instant",block:"nearest",inline:"nearest"}),n.remove()}hasFocus(){const e=document.activeElement;return!!e&&y(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()}setValue(e){e=st(e);const t=new xe(e),i=t.getFragment();this.container.empty(),this.togglePlaceholderClass(t.getHTML()),this.container.append(i),this.renderBoxes(),this.selection.updateByBookmark()}getValue(){const e=this.history.cloneContainer();let t=new xe(e).getHTML();return t=ot(t),t}render(){const e=st(this.config.value),t=new xe(e),i=t.getFragment();this.root.empty(),this.root.append(this.containerWrapper),this.containerWrapper.append(this.container),this.containerWrapper.append(this.overlayContainer),this.togglePlaceholderClass(t.getHTML()),this.container.append(i),this.unmountPluginMap=Ot.plugin.loadAll(this),this.readonly||(this.selection.updateByBookmark(),this.history.save({emitEvent:!1})),this.renderBoxes(),this.toolbar&&this.toolbar.render(this),document.addEventListener("copy",this.copyListener),this.readonly||(document.addEventListener("cut",this.cutListener),document.addEventListener("paste",this.pasteListener),document.addEventListener("selectionchange",this.selectionchangeListener),document.addEventListener("click",this.clickListener),this.bindInputEvents(),this.bindHistoryEvents())}unmount(){this.updateSelectionRange.flush(),this.updateBoxSelectionStyle.flush(),this.emitStateChangeEvent.flush();for(const e of this.unmountPluginMap.keys()){const t=this.unmountPluginMap.get(e);t&&(t(),g(`Plugin "${e}" unmounted`))}this.toolbar&&this.toolbar.unmount(),this.removeBoxGarbage(),this.container.find("lake-box").each((e=>{_e(y(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))}}Ot.version="0.3.1",Ot.box=new class{add(e){E.set(e.name,e)}remove(e){E.delete(e)}getNames(){return Array.from(E.keys())}},Ot.plugin=new class{constructor(){this.pluginMap=new Map}add(e,t){if(this.pluginMap.get(e))throw new Error(`Plugin "${e}" is already defined.`);this.pluginMap.set(e,t)}loadAll(e){const t=new Map;for(const i of this.pluginMap.keys()){const n=this.pluginMap.get(i);if(n&&!1!==e.config[i]){const o=n(e);o&&t.set(i,o)}}return t}};function zt(e,t){const i=e.get(0),n=y(k`<${t} />`);for(const e of i.attributes)n.attr(e.name,e.value);let o=e.first();for(;o.length>0;){const e=o.next();n.append(o),o=e}return e.replaceWith(n),n}const $t=Array.from(s).join(",");function Vt(e){const t=[e];for(const i of e.getWalker())t.push(i);for(const e of t)"div"===e.name?e.find($t).length>0?e.remove(!0):zt(e,"p"):(e.isHeading||["blockquote","li"].indexOf(e.name)>=0)&&e.find($t).remove(!0)}function Rt(e,t){const i=e.selection,n=i.range;if(0===t.childNodes.length)return;const o=new w(t.firstChild);let s=new w(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"===_e(n).type)i.isBoxStart?(i.setStartBefore(n),i.collapseToStart()):i.isBoxEnd?(i.setStartAfter(n),i.collapseToStart()):e.selection.removeBox();else{const t=y("<p />");i.isBoxStart?(n.before(t),i.shrinkAfter(t)):i.isBoxEnd?(n.after(t),i.shrinkAfter(t)):e.selection.removeBox()}const o=i.startNode.closestBlock();if(t.isBlockBox){const i=_e(t),n=""!==t.attr("value")?i.value:void 0;return e.selection.insertBox(i.name,n),void t.remove()}if(t.first().length>0&&Te(o),o.isEmpty&&"p"===o.name)return o.replaceWith(t),t.find("lake-box").each((e=>{_e(e).render()})),void i.shrinkAfter(t);let s=t.first();for(;s.length>0;){"li"===s.name&&(s=s.first());const t=s.next();e.selection.insertContents(s),s.isBox?_e(s).render():s.isElement&&s.find("lake-box").each((e=>{_e(e).render()})),s=t}t.remove()}(e,o);let r=new w(t.firstChild);for(;r.length>0;){const e=r.next();"br"===r.name&&r.remove(),r=e}if(s=new w(t.lastChild),t.childNodes.length>0){const o=i.splitBlock();o.start&&(n.setEndAfter(o.start),n.collapseToEnd()),o.end&&o.end.isEmpty&&o.end.remove(),i.insertContents(t),e.renderBoxes(),n.shrinkAfter(s)}Pe(e.container.children().filter((e=>e.isBlock))),e.history.save()}const Ft=["info","tip","warning","danger"];function Wt(e){e.selection.setBlocks("<p />")}function qt(e){e.selection.setBlocks("<ol><li></li></ol>")}function jt(e){e.selection.setBlocks("<ul><li></li></ul>")}function Ut(e,t){e.selection.setBlocks(`<ul type="checklist"><li value="${t}"></li></ul>`)}function Kt(e){const t=e.startNode.closest("table"),i=y("<p><br /></p>");t.replaceWith(i),e.shrinkBefore(i),g(`deleteTable: table ${t.id}`)}function Gt(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],o=t[i];let s=0;for(let e=0;e<n.cells.length;e++){for(s=e;o[s];)s++;const r=n.cells[e];for(let e=0;e<r.colSpan;e++)for(let n=0;n<r.rowSpan;n++){const o=t[i+n];o&&(o[s+e]=r)}}}return t}function Xt(e,t,i){const n=e[t];for(let e=0;e<n.length;e++){if(n[e]===i)return e}return-1}function Qt(e,t,i){const n=e[t],o=e[t-1];let s=i;for(let e=0;e<i;e++){const t=n[e];if(t===n[e+1])s--;else if(o){t===o[e]&&s--}}return s}function Yt(e,t){const i=e.startNode.closest("td"),n=i.closest("table"),o=i.closest("tr"),s=n.get(0),r=o.get(0),a=i.get(0),l=r.rowIndex,c=Gt(s);let d=Xt(c,l,a);if("right"===t){const e=c[l];for(d++;e&&a===e[d];)d++}g(`insertColumn: rows ${s.rows.length}, column ${d}, ${t}`);for(let e=0;e<s.rows.length;e++){const t=s.rows[e],i=c[e],n=Qt(c,e,d),o=t.cells[n];if(o&&o.colSpan>1&&o===i[d-1])o.colSpan+=1,o.rowSpan>1&&(e+=o.rowSpan-1);else{t.insertCell(n).innerHTML="<p><br /></p>"}}}function Jt(e,t){const i=e.startNode.closest("td"),n=i.closest("table"),o=i.closest("tr"),s=n.get(0),r=o.get(0);let a=Gt(s);const l=a[0].length;let c;c="up"===t?r.rowIndex:r.rowIndex+1;const d=s.rows[c];g(`insertRow: rows ${s.rows.length}, target row ${c}`);const h=s.insertRow(c);if(!d){for(let e=0;e<l;e++){h.insertCell(h.cells.length).innerHTML="<p><br /></p>"}return}a=Gt(s),c=d.rowIndex;let p=-1;for(let e=0;e<l;e++){const t=Qt(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=s.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 ei=[{value:"insertLeft",text:e=>e.table.insertColumnLeft()},{value:"insertRight",text:e=>e.table.insertColumnRight()},{value:"delete",text:e=>e.table.deleteColumn()}],ti=[{value:"insertAbove",text:e=>e.table.insertRowAbove()},{value:"insertBelow",text:e=>e.table.insertRowBelow()},{value:"delete",text:e=>e.table.deleteRow()}],ii=[{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()}],ni=[{value:"leftRight",text:e=>e.table.splitLeftRight()},{value:"topBottom",text:e=>e.table.splitTopBottom()}];function oi(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:$,menuWidth:"296px",selectedValues:()=>{const t=e.selection.range.startNode.closest("td");if(t.length>0){return[m(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:ei,menuCheck:!1,onSelect:(t,i)=>{const n=e.selection.range;"insertLeft"===i?Yt(n,"left"):"insertRight"===i?Yt(n,"right"):function(e){const t=e.startNode.closest("td"),i=t.closest("table"),n=t.closest("tr"),o=i.get(0),s=n.get(0),r=t.get(0),a=s.rowIndex,l=Gt(o),c=Xt(l,a,r);let d=null;const h=r.cellIndex;s.cells[h+1]?d=s.cells[h+1]:s.cells[h-1]&&(d=s.cells[h-1]),g(`deleteColumn: rows ${o.rows.length}, column ${c}`);const p=function(e,t){for(let i=0;i<e.length;i++){const n=e[i][t],o=e[i+1];if(o&&n.colSpan!==o[t].colSpan)return!1}return!0}(l,c);for(let t=0;t<o.rows.length;t++){const i=o.rows[t],n=Qt(l,t,c),s=i.cells[n];s.rowSpan>1&&(t+=s.rowSpan-1),s.colSpan>1&&!p?(s.colSpan-=1,1===s.colSpan&&s.removeAttribute("colSpan")):(s===r&&d&&e.shrinkBefore(y(d)),i.deleteCell(n))}0===o.rows[0].cells.length&&Kt(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:ti,menuCheck:!1,onSelect:(t,i)=>{const n=e.selection.range;"insertAbove"===i?Jt(n,"up"):"insertBelow"===i?Jt(n,"down"):function(e){const t=e.startNode.closest("td"),i=t.closest("table"),n=t.closest("tr"),o=i.get(0),s=n.get(0),r=t.get(0),a=s.rowIndex;let l=Gt(o);const c=l[0].length,d=Xt(l,a,r),h=o.rows[a+1]||o.rows[a-1];g(`deleteRow: rows ${o.rows.length}, target row ${a}, column ${d}`);for(let e=a-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>a-e&&(n.rowSpan-=1,1===n.rowSpan&&n.removeAttribute("rowSpan"))}}const p=o.rows[a+1];if(p){let e=-1;for(let t=0;t<c;t++){const i=Qt(l,a,t);if(i!==e){e=i;const n=s.cells[i];if(n.rowSpan>1){const e=Qt(l,a+1,t);let i=p.insertCell(e);const o=n.cloneNode(!0);o.removeAttribute("rowSpan"),i.replaceWith(o),i=o,n.rowSpan>2&&(i.rowSpan=n.rowSpan-1)}}}}if(o.deleteRow(a),h){l=Gt(o);const t=Qt(l,h.rowIndex,d),i=h.cells[t];i&&e.shrinkBefore(y(i))}0===o.rows.length&&Kt(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:ii,menuCheck:!1,onSelect:(t,i)=>{!function(e,t){const i=e.startNode.closest("td"),n=i.closest("table"),o=i.closest("tr"),s=n.get(0),r=o.get(0),a=i.get(0),l=r.rowIndex,c=Gt(s);if("left"===t||"right"===t){const i=a.cellIndex;let n,o,s;if("left"===t?(n=r.cells[i-1],o=i,s=a):(n=a,o=i+1,s=r.cells[o]),!n||!s)return;if(g(`mergeCells: row ${l}, cell ${i}, other row ${l}, other cell ${o}`),n.rowSpan!==s.rowSpan)return;const d=c[l],h=Xt(c,l,n),p=Xt(c,l,s);if(d[h+1]!==s&&d[p-1]!==n)return;return n.colSpan+=s.colSpan,Me(y(n),y(s)),void e.shrinkBefore(y(n))}const d=Xt(c,l,a);let h,p,u,m,f,v;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,f=a.cellIndex,v=a}else{h=r.rowIndex,p=a,u=-1,v=null,f=-1;for(let e=r.rowIndex+1;e<s.rows.length;e++){const t=c[e];if(!t)break;const i=t[d];if(!i)break;if(i!==v){u=e,v=i,f=v.cellIndex;break}}if(m=s.rows[u],!m)return}p&&v&&(g(`mergeCells: row ${h}, cell ${p.cellIndex}, other row ${u}, other cell ${f}`),p.colSpan===v.colSpan&&(p.rowSpan+=v.rowSpan,Me(y(p),y(v)),e.shrinkBefore(y(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:ni,menuCheck:!1,onSelect:(t,i)=>{!function(e,t){const i=e.startNode.closest("td"),n=i.closest("table"),o=i.closest("tr"),s=n.get(0),r=o.get(0),a=i.get(0),l=r.rowIndex,c=a.rowSpan,d=a.colSpan;let h=Gt(s);const p=Xt(h,l,a);if(g(`splitCell: row ${l}, cell ${p}, ${t}`),"topBottom"!==t)for(let e=0;e<h.length;e++){const t=s.rows[e],i=h[e],n=i[p];if(n===a){const i=h[e-1];if(!i||n!==i[p]){const i=Qt(h,e,p),o=t.insertCell(i+1);o.innerHTML="<p><br /></p>",n.rowSpan>1&&(o.rowSpan=n.rowSpan),n.colSpan>2&&(o.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?s.rows[l+1]:s.insertRow(l+1),t=Qt(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=Gt(s)}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=Gt(s)}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:()=>{Kt(e.selection.range),e.history.save()}}];return i}const si={start:"left",end:"right"};function ri(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 Pe([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 ai="strong";const li="sub";const ci="sup";const di="code";const hi="lake-format-painter";function pi(e,t,i,n){return new(i||(i=Promise))((function(o,s){function r(e){try{l(n.next(e))}catch(e){s(e)}}function a(e){try{l(n.throw(e))}catch(e){s(e)}}function l(e){var t;e.done?o(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 ui{constructor(e){this.linkNode=null,this.scrollListener=()=>this.updatePosition(),this.resizeListener=()=>this.updatePosition(),this.config=e||{},this.locale=this.config.locale||de("en-US"),this.container=y(k`
23
23
  <div class="lake-popup lake-link-popup">
24
24
  <div class="lake-row">${this.locale.link.url()}</div>
25
25
  <div class="lake-row lake-url-row">
@@ -112,5 +112,5 @@ function ji(e,t,i){const n=document.createElement(t);return e&&(n.className=e),i
112
112
  <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>
113
113
  </svg>
114
114
  </div>
115
- `),e.overlayContainer.append(i)):o.preventDefault()})),e.container.on("dragover",(t=>{const s=t;s.preventDefault();const r=s.dataTransfer;if(!r)return;if(r.dropEffect="move",!i)return;const a=y(s.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();o="bottom";let h=d.x-c.x,p=d.y+d.height-c.y+parseInt(n.computedCSS("margin-bottom"),10)/2;if(s.clientY<d.y+d.height/2){const t=n.prev();t.length>0&&t.isBlock||t.isBlockBox?(n=t,d=n.get(0).getBoundingClientRect(),h=d.x-c.x,p=d.y+d.height-c.y+parseInt(n.computedCSS("margin-bottom"),10)/2):(o="top",p=d.y-c.y-parseInt(e.container.computedCSS("padding-top"),10)/2)}i.css({top:`${p}px`,left:`${h}px`,width:`${d.width}px`,display:"block"})})),e.container.on("dragend",(()=>{i&&(i.remove(),i=null)})),e.container.on("drop",(s=>{const r=s;if(r.dataTransfer&&i&&(i.remove(),i=null,t&&n&&t.isBox)){if(t.get(0)===n.get(0))return;if("bottom"===o&&t.get(0)===n.next().get(0))return;r.preventDefault();const i=_e(t),s=e.selection.range;n.isBox?"top"===o?s.selectBoxStart(n):s.selectBoxEnd(n):(s.selectNodeContents(n),"top"===o?s.collapseToStart():s.collapseToEnd()),e.selection.insertBox(i.name,i.value),t.remove(),e.history.save()}}))})),Ot.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"))})))})),Ot.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)})),Ot.plugin.add("selectAll",(e=>{e.readonly||e.command.add("selectAll",{execute:()=>{const t=e.selection.range;t.selectNodeContents(e.container),t.shrink()}})})),Ot.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()}})})),Ot.plugin.add("blockQuote",(e=>{e.readonly||e.command.add("blockQuote",{isSelected:e=>!!e.find((e=>"blockquote"===e.name)),execute:t=>{t&&Ft.indexOf(t)>=0?e.selection.setBlocks(k`<blockquote type="${t}" />`):e.selection.setBlocks("<blockquote />"),e.history.save()}})})),Ot.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 o=!1,s=!1,r=!1;for(const e of n)o||"ol"!==e.name||(o=!0),s||"ul"!==e.name||e.hasAttr("type")||(s=!0),r||"ul"!==e.name||"checklist"!==e.attr("type")||(r=!0);o?("numbered"===t&&Wt(e),"bulleted"===t&&jt(e),"checklist"===t&&Ut(e,i)):s?("numbered"===t&&qt(e),"bulleted"===t&&Wt(e),"checklist"===t&&Ut(e,i)):r?("numbered"===t&&qt(e),"bulleted"===t&&jt(e),"checklist"===t&&Wt(e)):("numbered"===t&&qt(e),"bulleted"===t&&jt(e),"checklist"===t&&Ut(e,i)),e.history.save()}}),e.container.on("click",(t=>{const i=t;if(!i.target)return;const n=y(i.target);"li"===n.name&&""!==n.attr("value")&&i.offsetX<=18&&(n.attr("value",("true"!==n.attr("value")).toString()),e.history.save())})))})),Ot.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 o=e.selection.range.commonAncestor.closest("td"),s=o.closest("table");if(n&&n.get(0)===s.get(0))return s.addClass("lake-table-focused"),void o.addClass("lake-td-focused");if(n=s,i&&i.unmount(),s.length>0){s.addClass("lake-table-focused"),o.addClass("lake-td-focused");const n=oi(e,t);i=new ge({target:s,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 o=y(n);Re(e,o),e.shrinkBefore(o),g(`insertTable: table ${o.id}`)}(e.selection.range,3,2),e.history.save()}}),()=>{i&&i.unmount()}})),Ot.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?[si[t]||t]:[]},execute:t=>{e.selection.setBlocks({"text-align":t}),e.history.save()}})})),Ot.plugin.add("indent",(e=>{e.readonly||e.command.add("indent",{execute:t=>{const i=e.selection.range.getBlocks();for(const e of i)ri(e,t);e.history.save()}})})),Ot.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===ai)),execute:()=>{e.command.isSelected("bold")?e.selection.removeMark(`<${ai} />`):e.selection.addMark(`<${ai} />`),e.history.save()}}),e.keystroke.setKeydown("mod+b",(t=>{t.preventDefault(),e.command.execute("bold")})))})),Ot.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")})))})),Ot.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")})))})),Ot.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")})))})),Ot.plugin.add("subscript",(e=>{e.readonly||e.command.add("subscript",{isSelected:e=>!!e.find((e=>e.name===li)),execute:()=>{e.command.isSelected("subscript")?e.selection.removeMark(`<${li} />`):e.selection.addMark(`<${li} />`),e.history.save()}})})),Ot.plugin.add("superscript",(e=>{e.readonly||e.command.add("superscript",{isSelected:e=>!!e.find((e=>e.name===ci)),execute:()=>{e.command.isSelected("superscript")?e.selection.removeMark(`<${ci} />`):e.selection.addMark(`<${ci} />`),e.history.save()}})})),Ot.plugin.add("code",(e=>{e.readonly||e.command.add("code",{isSelected:e=>!!e.find((e=>e.name===di)),execute:()=>{e.command.isSelected("code")?e.selection.removeMark(`<${di} />`):e.selection.addMark(`<${di} />`),e.history.save()}})})),Ot.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()}})})),Ot.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()}})})),Ot.plugin.add("fontColor",(e=>{e.readonly||e.command.add("fontColor",{selectedValues:e=>{for(const t of e)if("span"===t.name){return[m(t.node.computedCSS("color"))]}return[]},execute:t=>{e.selection.addMark(`<span style="color: ${t};" />`),e.history.save()}})})),Ot.plugin.add("highlight",(e=>{e.readonly||e.command.add("highlight",{selectedValues:e=>{for(const t of e)if("span"===t.name){return[m(t.node.computedCSS("background-color"))]}return[]},execute:t=>{e.selection.addMark(`<span style="background-color: ${t};" />`),e.history.save()}})})),Ot.plugin.add("removeFormat",(e=>{e.readonly||e.command.add("removeFormat",{execute:()=>{e.selection.removeMark(),e.history.save()}})})),Ot.plugin.add("formatPainter",(e=>{if(e.readonly)return;let t=[];e.command.add("formatPainter",{execute:()=>{e.container.addClass(hi);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(hi),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(hi),t=[])}))})),Ot.plugin.add("link",(e=>{if(e.readonly)return;const t=new ui({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=y(t);if(e.isCollapsed){let t=e.commonAncestor.closest("a");return 0===t.length?(t=i.clone(!0),Ze(e,t),t):(""!==i.attr("href")&&t.attr({href:i.attr("href")}),t)}We(e);const n=Ce(e);for(const t of e.commonAncestor.getWalker())"a"===t.name&&e.intersectsNode(t)&&t.remove(!0);const o=i.clone(!1);n.anchor.after(o);let s=o.next();for(;s.length>0;){const e=s.next();if(!s.isMark&&!s.isText)break;o.append(s),s=e}return 0===o.first().length&&o.remove(),Le(e,n),o}(e.selection.range,`<a href="">${e.locale.link.newLink()}</a>`);i&&(e.history.save(),t.show(i))}}),()=>t.unmount()})),Ot.plugin.add("hr",(e=>{e.readonly||(e.event.on("beforepaste",(e=>{new C(e).find("hr").each((e=>{const t=y(e),i=_e("hr");t.replaceWith(i.node)}))})),e.command.add("hr",{execute:()=>{e.selection.insertBox("hr"),e.history.save()}}))})),Ot.plugin.add("codeBlock",(e=>{window.LakeCodeMirror&&(e.setPluginConfig("codeBlock",{langList:qi,defaultLang:"text"}),e.readonly||e.command.add("codeBlock",{execute:t=>{const i=e.selection.insertBox("codeBlock",t);e.history.save(),i.getContainer().find(".lake-code-block").emit("click")}}))})),Ot.plugin.add("image",(e=>{e.setPluginConfig("image",{requestMethod:"POST",requestTypes:["image/gif","image/jpeg","image/png","image/svg+xml"]}),e.readonly||(e.event.on("beforepaste",(e=>{new C(e).find("img").each((e=>{const t=y(e),i=_e("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()}}))})),Ot.plugin.add("video",(e=>{e.readonly||e.command.add("video",{execute:t=>{const i=e.selection.insertBox("video",t);e.history.save(),i&&i.getContainer().find('input[name="url"]').focus()}})})),Ot.plugin.add("file",(e=>{e.setPluginConfig("file",{requestMethod:"POST",requestTypes:["application/zip","application/x-zip-compressed","application/vnd.rar","image/gif","image/jpeg","image/png","image/svg+xml","text/plain","text/html","application/pdf","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","application/vnd.ms-powerpoint","application/vnd.openxmlformats-officedocument.presentationml.presentation"]}),e.readonly||e.command.add("file",{execute:t=>{e.selection.insertBox("file",t),e.history.save()}})})),Ot.plugin.add("emoji",(e=>{e.readonly||e.command.add("emoji",{execute:t=>{e.selection.insertBox("emoji",t),e.history.save()}})})),Ot.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()}}))})),Ot.plugin.add("specialCharacter",(e=>{e.readonly||e.command.add("specialCharacter",{execute:t=>{e.selection.insertContents(document.createTextNode(t)),e.history.save()}})})),Ot.plugin.add("mention",(e=>{if(e.setPluginConfig("mention",{requestMethod:"GET",items:[],getProfileUrl:e=>`/${e.name}`}),e.readonly)return;const{requestAction:t,requestMethod:i,items:n}=e.config.mention;let o=null;const s=(t,i)=>{o&&o.hide(),e.focus();const n=e.selection.range.getCharacterRange("@");n&&n.get().deleteContents(),e.selection.insertBox("mention",i),e.history.save()},r=()=>{e.popup=o},a=()=>{e.popup=null},l=()=>{const l=e.selection.range;if(!l.isCollapsed)return;const c=l.getCharacterRange("@");if(null===c)return;const d=Vo(l);null!==d&&(o?o.show(c,d):t?W({onSuccess:e=>{e.data&&(o=new zo({items:e.data,onSelect:s,onShow:r,onHide:a}),o.show(c,d))},action:t,method:i}):(o=new zo({items:n,onSelect:s,onShow:r,onHide:a}),o.show(c,d)))};return e.container.on("keyup",(t=>{if(e.isComposing)return;const i=t;if(Zt.isKeyHotkey(["down","up","enter"],i))return;if(!o||!o.visible){if("@"===i.key)return void l();if(!Zt.isKeyHotkey(["backspace","delete"],i))return;l()}const n=Vo(e.selection.range);null!==n?o&&o.update(n):o&&o.hide()})),()=>{o&&o.unmount()}})),Ot.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,o=t.offset,s=t.node.text().slice(0,o);for(const t of Wo){const r=t.re.exec(s);if(null!==r){const s=t.getParameters(),a=s.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,o-r[0].length),n.setEnd(c,o-(d.length-h.length)-1),e.command.execute(a,...s),i.toBookmark(l),e.history.continue(),e.history.save(),!0}}return!1}(e,n))return void t.preventDefault();const o=i.getBlocks()[0];o&&(o.isHeading||"p"===o.name)&&function(e,t){const i=e.selection,n=t.offset;let o=t.node.text().slice(0,n);o=o.replace(/[\u200B\u2060]/g,"");for(const t of qo){const n=t.re.exec(o);if(null!==n){const o=t.getParameters(n),s=o.shift();if(!e.command.has(s))return!1;const r=i.insertBookmark();r.focus.prev().remove();const a=r.focus.closestBlock();return Uo(a),i.range.shrinkAfter(a),i.toBookmark(r),e.command.execute(s,...o),!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 o of jo){const s=o.re.exec(n);if(null!==s){const n=o.getParameters(s),r=n.shift();return!!e.command.has(r)&&(t.empty(),Uo(t),i.range.shrinkAfter(t),e.command.execute(r,...n),!0)}}return!1}(e,n)?(t.preventDefault(),t.stopImmediatePropagation(),!1):void 0})))})),Ot.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 Go(e),void e.history.save();if(i.isCollapsed){const t=i.getPrevNode(),n=i.getNextNode();if("table"===t.name||"table"===n.name){const t=y("<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 Go(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();Ko(e,n),e.history.save()}))})),Ot.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 Qo(e),void e.history.save();if(i.adjust(),!i.isInoperative){if(i.isBox)return Qo(e),void e.history.save();Xo(e),e.history.save()}}}))})),Ot.plugin.add("backspaceKey",(e=>{e.readonly||e.keystroke.setKeydown("backspace",(t=>{const i=e.selection.range;if(i.isInsideBox){const n=_e(i.commonAncestor.closest("lake-box")),o=n.value;return void(!i.isCollapsed||"codeBlock"!==n.name||void 0!==o.code&&""!==o.code||(t.preventDefault(),e.selection.removeBox(n),e.history.save()))}if(e.fixContent(),i.isBoxStart){const n=i.startNode.closest("lake-box"),o=n.prev();if(0===o.length){const i=n.closestBlock();return void(i.length>0&&!i.isContainer&&(t.preventDefault(),Yo(e,i),e.history.save()))}if(o.isBlock)return o.isEmpty?(t.preventDefault(),o.remove(),Pe(i.getBlocks()),void e.history.save()):(t.preventDefault(),void i.shrinkAfter(o));if(o.isText&&1===o.text().length)return t.preventDefault(),o.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 o=y("<p><br /></p>");return n.replaceWith(o),i.shrinkBefore(o),void e.history.save()}const o=i.getNextNode();if(n.length>0&&"table"===o.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 o=n.closestBlock();if(i.setStartBefore(n),i.collapseToStart(),n.remove(),o.isEmpty){const e=Ee(o);i.setStartBefore(e),i.collapseToStart()}return void e.history.save()}const o=i.getNextNode();if("br"===n.name&&o.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 ri(n,"decrease"),void e.history.save();if(n.isList||"blockquote"===n.name)return e.selection.setBlocks("<p />"),void e.history.save();Yo(e,n),e.history.save()}}))})),Ot.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"),o=n.next();if(0===o.length){const i=n.closestBlock();return void(i.length>0&&!i.isContainer&&(t.preventDefault(),Jo(e,i),e.history.save()))}if(o.isBlock)return o.isEmpty?(t.preventDefault(),o.remove(),Pe(i.getBlocks()),void e.history.save()):(t.preventDefault(),void i.shrinkBefore(o));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 o=y("<p><br /></p>");return n.replaceWith(o),i.shrinkBefore(o),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]),Jo(e,n),e.history.save()}}))})),Ot.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")?ri(e,"increase"):e.css("text-indent","2em");e.history.save()}))})),Ot.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 o=i.getPrevNode();o.isBox&&(t.preventDefault(),i.selectBox(o))})),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 o=i.getNextNode();o.isBox&&(t.preventDefault(),i.selectBox(o))})),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()}})))})),Ot.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())}))})),Ot.plugin.add("slash",(e=>{if(e.setPluginConfig("slash",{items:os}),e.readonly)return;const t=new ns({locale:e.locale,items:e.config.slash.items,onSelect:(i,n,o)=>{if(t&&t.hide(),e.focus(),function(e){const t=e.selection.range,i=t.commonAncestor.closestBlock();i.empty(),Ee(i),t.shrinkBefore(i)}(e),"upload"===n.type){if(!o)return;const t=i.target,s=o.get(0),r=t.files||[];for(const t of r)q({editor:e,name:n.name,file:t,onError:t=>{s.value="",e.config.onMessage("error",t)},onSuccess:()=>{s.value=""}})}else n.onClick(e,n.name)},onShow:()=>{e.popup=t},onHide:()=>{e.popup=null}}),i=()=>{const i=e.selection.range;if(!i.isCollapsed)return;const n=i.getBlocks()[0];if(!n||n.find("lake-box").length>0||n.closest("table").length>0)return;const o=ss(n);if(null===o)return;const s=i.clone();s.selectNodeContents(n),t.show(s,o)};return e.container.on("keyup",(n=>{if(e.isComposing)return;const o=n;if(Zt.isKeyHotkey(["down","up","enter"],o))return;if(!t.visible){if(Zt.isKeyHotkey("/",o))return void i();if(!Zt.isKeyHotkey(["backspace","delete"],o))return;i()}const s=e.selection.range.getBlocks()[0];if(!s)return;const r=ss(s);null!==r?t.update(r):t.hide()})),()=>{t.unmount()}})),e.Box=fe,e.Button=j,e.Dropdown=he,e.Editor=Ot,e.Fragment=C,e.HTMLParser=xe,e.Nodes=w,e.Range=S,e.TextParser=be,e.Toolbar=me,e.addMark=je,e.deleteContents=He,e.icons=n,e.insertBlock=Re,e.insertBookmark=Ce,e.insertBox=Ke,e.insertContents=Ze,e.query=y,e.removeBox=Xe,e.removeMark=Ue,e.setBlocks=Oe,e.splitBlock=Ve,e.splitMarks=We,e.template=k,e.toBookmark=Le,e.toHex=m,e}({});
115
+ `),e.overlayContainer.append(i)):o.preventDefault()})),e.container.on("dragover",(t=>{const s=t;s.preventDefault();const r=s.dataTransfer;if(!r)return;if(r.dropEffect="move",!i)return;const a=y(s.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();o="bottom";let h=d.x-c.x,p=d.y+d.height-c.y+parseInt(n.computedCSS("margin-bottom"),10)/2;if(s.clientY<d.y+d.height/2){const t=n.prev();t.length>0&&t.isBlock||t.isBlockBox?(n=t,d=n.get(0).getBoundingClientRect(),h=d.x-c.x,p=d.y+d.height-c.y+parseInt(n.computedCSS("margin-bottom"),10)/2):(o="top",p=d.y-c.y-parseInt(e.container.computedCSS("padding-top"),10)/2)}i.css({top:`${p}px`,left:`${h}px`,width:`${d.width}px`,display:"block"})})),e.container.on("dragend",(()=>{i&&(i.remove(),i=null)})),e.container.on("drop",(s=>{const r=s;if(r.dataTransfer&&i&&(i.remove(),i=null,t&&n&&t.isBox)){if(t.get(0)===n.get(0))return;if("bottom"===o&&t.get(0)===n.next().get(0))return;r.preventDefault();const i=_e(t),s=e.selection.range;n.isBox?"top"===o?s.selectBoxStart(n):s.selectBoxEnd(n):(s.selectNodeContents(n),"top"===o?s.collapseToStart():s.collapseToEnd()),e.selection.insertBox(i.name,i.value),t.remove(),e.history.save()}}))})),Ot.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"))})))})),Ot.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)})),Ot.plugin.add("selectAll",(e=>{e.readonly||e.command.add("selectAll",{execute:()=>{const t=e.selection.range;t.selectNodeContents(e.container),t.shrink()}})})),Ot.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()}})})),Ot.plugin.add("blockQuote",(e=>{e.readonly||e.command.add("blockQuote",{isSelected:e=>!!e.find((e=>"blockquote"===e.name)),execute:t=>{t&&Ft.indexOf(t)>=0?e.selection.setBlocks(k`<blockquote type="${t}" />`):e.selection.setBlocks("<blockquote />"),e.history.save()}})})),Ot.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 o=!1,s=!1,r=!1;for(const e of n)o||"ol"!==e.name||(o=!0),s||"ul"!==e.name||e.hasAttr("type")||(s=!0),r||"ul"!==e.name||"checklist"!==e.attr("type")||(r=!0);o?("numbered"===t&&Wt(e),"bulleted"===t&&jt(e),"checklist"===t&&Ut(e,i)):s?("numbered"===t&&qt(e),"bulleted"===t&&Wt(e),"checklist"===t&&Ut(e,i)):r?("numbered"===t&&qt(e),"bulleted"===t&&jt(e),"checklist"===t&&Wt(e)):("numbered"===t&&qt(e),"bulleted"===t&&jt(e),"checklist"===t&&Ut(e,i)),e.history.save()}}),e.container.on("click",(t=>{const i=t;if(!i.target)return;const n=y(i.target);"li"===n.name&&""!==n.attr("value")&&i.offsetX<=18&&(n.attr("value",("true"!==n.attr("value")).toString()),e.history.save())})))})),Ot.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 o=e.selection.range.commonAncestor.closest("td"),s=o.closest("table");if(n&&n.get(0)===s.get(0))return s.addClass("lake-table-focused"),void o.addClass("lake-td-focused");if(n=s,i&&i.unmount(),s.length>0){s.addClass("lake-table-focused"),o.addClass("lake-td-focused");const n=oi(e,t);i=new ge({target:s,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 o=y(n);Re(e,o),e.shrinkBefore(o),g(`insertTable: table ${o.id}`)}(e.selection.range,3,2),e.history.save()}}),()=>{i&&i.unmount()}})),Ot.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?[si[t]||t]:[]},execute:t=>{e.selection.setBlocks({"text-align":t}),e.history.save()}})})),Ot.plugin.add("indent",(e=>{e.readonly||e.command.add("indent",{execute:t=>{const i=e.selection.range.getBlocks();for(const e of i)ri(e,t);e.history.save()}})})),Ot.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===ai)),execute:()=>{e.command.isSelected("bold")?e.selection.removeMark(`<${ai} />`):e.selection.addMark(`<${ai} />`),e.history.save()}}),e.keystroke.setKeydown("mod+b",(t=>{t.preventDefault(),e.command.execute("bold")})))})),Ot.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")})))})),Ot.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")})))})),Ot.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")})))})),Ot.plugin.add("subscript",(e=>{e.readonly||e.command.add("subscript",{isSelected:e=>!!e.find((e=>e.name===li)),execute:()=>{e.command.isSelected("subscript")?e.selection.removeMark(`<${li} />`):e.selection.addMark(`<${li} />`),e.history.save()}})})),Ot.plugin.add("superscript",(e=>{e.readonly||e.command.add("superscript",{isSelected:e=>!!e.find((e=>e.name===ci)),execute:()=>{e.command.isSelected("superscript")?e.selection.removeMark(`<${ci} />`):e.selection.addMark(`<${ci} />`),e.history.save()}})})),Ot.plugin.add("code",(e=>{e.readonly||e.command.add("code",{isSelected:e=>!!e.find((e=>e.name===di)),execute:()=>{e.command.isSelected("code")?e.selection.removeMark(`<${di} />`):e.selection.addMark(`<${di} />`),e.history.save()}})})),Ot.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()}})})),Ot.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()}})})),Ot.plugin.add("fontColor",(e=>{e.readonly||e.command.add("fontColor",{selectedValues:e=>{for(const t of e)if("span"===t.name){return[m(t.node.computedCSS("color"))]}return[]},execute:t=>{e.selection.addMark(`<span style="color: ${t};" />`),e.history.save()}})})),Ot.plugin.add("highlight",(e=>{e.readonly||e.command.add("highlight",{selectedValues:e=>{for(const t of e)if("span"===t.name){return[m(t.node.computedCSS("background-color"))]}return[]},execute:t=>{e.selection.addMark(`<span style="background-color: ${t};" />`),e.history.save()}})})),Ot.plugin.add("removeFormat",(e=>{e.readonly||e.command.add("removeFormat",{execute:()=>{e.selection.removeMark(),e.history.save()}})})),Ot.plugin.add("formatPainter",(e=>{if(e.readonly)return;let t=[];e.command.add("formatPainter",{execute:()=>{e.container.addClass(hi);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(hi),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(hi),t=[])}))})),Ot.plugin.add("link",(e=>{if(e.readonly)return;const t=new ui({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=y(t);if(e.isCollapsed){let t=e.commonAncestor.closest("a");return 0===t.length?(t=i.clone(!0),Ze(e,t),t):(""!==i.attr("href")&&t.attr({href:i.attr("href")}),t)}We(e);const n=Ce(e);for(const t of e.commonAncestor.getWalker())"a"===t.name&&e.intersectsNode(t)&&t.remove(!0);const o=i.clone(!1);n.anchor.after(o);let s=o.next();for(;s.length>0;){const e=s.next();if(!s.isMark&&!s.isText)break;o.append(s),s=e}return 0===o.first().length&&o.remove(),Le(e,n),o}(e.selection.range,`<a href="">${e.locale.link.newLink()}</a>`);i&&(e.history.save(),t.show(i))}}),()=>t.unmount()})),Ot.plugin.add("hr",(e=>{e.readonly||(e.event.on("beforepaste",(e=>{new C(e).find("hr").each((e=>{const t=y(e),i=_e("hr");t.replaceWith(i.node)}))})),e.command.add("hr",{execute:()=>{e.selection.insertBox("hr"),e.history.save()}}))})),Ot.plugin.add("codeBlock",(e=>{window.LakeCodeMirror&&(e.setPluginConfig("codeBlock",{langList:qi,defaultLang:"text"}),e.readonly||e.command.add("codeBlock",{execute:t=>{const i=e.selection.insertBox("codeBlock",t);e.history.save(),i.getContainer().find(".lake-code-block").emit("click")}}))})),Ot.plugin.add("image",(e=>{e.setPluginConfig("image",{requestMethod:"POST",requestTypes:["image/gif","image/jpeg","image/png","image/svg+xml"]}),e.readonly||(e.event.on("beforepaste",(e=>{new C(e).find("img").each((e=>{const t=y(e),i=_e("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()}}))})),Ot.plugin.add("video",(e=>{e.readonly||e.command.add("video",{execute:t=>{const i=e.selection.insertBox("video",t);e.history.save(),i&&i.getContainer().find('input[name="url"]').focus()}})})),Ot.plugin.add("file",(e=>{e.setPluginConfig("file",{requestMethod:"POST",requestTypes:["application/zip","application/x-zip-compressed","application/vnd.rar","image/gif","image/jpeg","image/png","image/svg+xml","text/plain","text/html","application/pdf","application/msword","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.ms-excel","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","application/vnd.ms-powerpoint","application/vnd.openxmlformats-officedocument.presentationml.presentation"]}),e.readonly||e.command.add("file",{execute:t=>{e.selection.insertBox("file",t),e.history.save()}})})),Ot.plugin.add("emoji",(e=>{e.readonly||e.command.add("emoji",{execute:t=>{e.selection.insertBox("emoji",t),e.history.save()}})})),Ot.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()}}))})),Ot.plugin.add("specialCharacter",(e=>{e.readonly||e.command.add("specialCharacter",{execute:t=>{e.selection.insertContents(document.createTextNode(t)),e.history.save()}})})),Ot.plugin.add("mention",(e=>{if(e.setPluginConfig("mention",{requestMethod:"GET",items:[],getProfileUrl:e=>`/${e.name}`}),e.readonly)return;const{requestAction:t,requestMethod:i,items:n}=e.config.mention;let o=null;const s=(t,i)=>{o&&o.hide(),e.focus();const n=e.selection.range.getCharacterRange("@");n&&n.get().deleteContents(),e.selection.insertBox("mention",i),e.history.save()},r=()=>{e.popup=o},a=()=>{e.popup=null},l=()=>{const l=e.selection.range;if(!l.isCollapsed)return;const c=l.getCharacterRange("@");if(null===c)return;const d=Vo(l);null!==d&&(o?o.show(c,d):t?W({onSuccess:e=>{e.data&&(o=new zo({items:e.data,onSelect:s,onShow:r,onHide:a}),o.show(c,d))},action:t,method:i}):(o=new zo({items:n,onSelect:s,onShow:r,onHide:a}),o.show(c,d)))};return e.container.on("keyup",(t=>{if(e.isComposing)return;const i=t;if(Zt.isKeyHotkey(["down","up","enter"],i))return;if(!o||!o.visible){if("@"===i.key)return void l();if(!Zt.isKeyHotkey(["backspace","delete"],i))return;l()}const n=Vo(e.selection.range);null!==n?o&&o.update(n):o&&o.hide()})),()=>{o&&o.unmount()}})),Ot.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,o=t.offset,s=t.node.text().slice(0,o);for(const t of Wo){const r=t.re.exec(s);if(null!==r){const s=t.getParameters(),a=s.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,o-r[0].length),n.setEnd(c,o-(d.length-h.length)-1),e.command.execute(a,...s),i.toBookmark(l),e.history.continue(),e.history.save(),!0}}return!1}(e,n))return void t.preventDefault();const o=i.getBlocks()[0];o&&(o.isHeading||"p"===o.name)&&function(e,t){const i=e.selection,n=t.offset;let o=t.node.text().slice(0,n);o=o.replace(/[\u200B\u2060]/g,"");for(const t of qo){const n=t.re.exec(o);if(null!==n){const o=t.getParameters(n),s=o.shift();if(!e.command.has(s))return!1;const r=i.insertBookmark();r.focus.prev().remove();const a=r.focus.closestBlock();return Uo(a),i.range.shrinkAfter(a),i.toBookmark(r),e.command.execute(s,...o),!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 o of jo){const s=o.re.exec(n);if(null!==s){const n=o.getParameters(s),r=n.shift();return!!e.command.has(r)&&(t.empty(),Uo(t),i.range.shrinkAfter(t),e.command.execute(r,...n),!0)}}return!1}(e,n)?(t.preventDefault(),t.stopImmediatePropagation(),!1):void 0})))})),Ot.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 Go(e),void e.history.save();if(i.isCollapsed){const t=i.getPrevNode(),n=i.getNextNode();if("table"===t.name||"table"===n.name){const t=y("<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 Go(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();Ko(e,n),e.history.save()}))})),Ot.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 Qo(e),void e.history.save();if(i.adjust(),!i.isInoperative){if(i.isBox)return Qo(e),void e.history.save();Xo(e),e.history.save()}}}))})),Ot.plugin.add("backspaceKey",(e=>{e.readonly||e.keystroke.setKeydown("backspace",(t=>{const i=e.selection.range;if(i.isInsideBox){const n=_e(i.commonAncestor.closest("lake-box")),o=n.value;return void(!i.isCollapsed||"codeBlock"!==n.name||void 0!==o.code&&""!==o.code||(t.preventDefault(),e.selection.removeBox(n),e.history.save()))}if(e.fixContent(),i.isBoxStart){const n=i.startNode.closest("lake-box"),o=n.prev();if(0===o.length){const i=n.closestBlock();return void(i.length>0&&!i.isContainer&&(t.preventDefault(),Yo(e,i),e.history.save()))}if(o.isBlock)return o.isEmpty?(t.preventDefault(),o.remove(),Pe(i.getBlocks()),void e.history.save()):(t.preventDefault(),void i.shrinkAfter(o));if(o.isText&&1===o.text().length)return t.preventDefault(),o.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 o=y("<p><br /></p>");return n.replaceWith(o),i.shrinkBefore(o),void e.history.save()}const o=i.getNextNode();if(n.length>0&&"table"===o.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 o=n.closestBlock();if(i.setStartBefore(n),i.collapseToStart(),n.remove(),o.isEmpty){const e=Ee(o);i.setStartBefore(e),i.collapseToStart()}return void e.history.save()}const o=i.getNextNode();if("br"===n.name&&o.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 ri(n,"decrease"),void e.history.save();if(n.isList||"blockquote"===n.name)return e.selection.setBlocks("<p />"),void e.history.save();Yo(e,n),e.history.save()}}))})),Ot.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"),o=n.next();if(0===o.length){const i=n.closestBlock();return void(i.length>0&&!i.isContainer&&(t.preventDefault(),Jo(e,i),e.history.save()))}if(o.isBlock)return o.isEmpty?(t.preventDefault(),o.remove(),Pe(i.getBlocks()),void e.history.save()):(t.preventDefault(),void i.shrinkBefore(o));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 o=y("<p><br /></p>");return n.replaceWith(o),i.shrinkBefore(o),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]),Jo(e,n),e.history.save()}}))})),Ot.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")?ri(e,"increase"):e.css("text-indent","2em");e.history.save()}))})),Ot.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 o=i.getPrevNode();o.isBox&&(t.preventDefault(),i.selectBox(o))})),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 o=i.getNextNode();o.isBox&&(t.preventDefault(),i.selectBox(o))})),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()}})))})),Ot.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())}))})),Ot.plugin.add("slash",(e=>{if(e.setPluginConfig("slash",{items:os}),e.readonly)return;const t=new ns({locale:e.locale,items:e.config.slash.items,onSelect:(i,n,o)=>{if(t&&t.hide(),e.focus(),function(e){const t=e.selection.range,i=t.commonAncestor.closestBlock();i.empty(),Ee(i),t.shrinkBefore(i)}(e),"upload"===n.type){if(!o)return;const t=i.target,s=o.get(0),r=t.files||[];for(const t of r)q({editor:e,name:n.name,file:t,onError:t=>{s.value="",e.config.onMessage("error",t)},onSuccess:()=>{s.value=""}})}else n.onClick(e,n.name)},onShow:()=>{e.popup=t},onHide:()=>{e.popup=null}}),i=()=>{const i=e.selection.range;if(!i.isCollapsed)return;const n=i.getBlocks()[0];if(!n||n.find("lake-box").length>0||n.closest("table").length>0)return;const o=ss(n);if(null===o)return;const s=i.clone();s.selectNodeContents(n),t.show(s,o)};return e.container.on("keyup",(n=>{if(e.isComposing)return;const o=n;if(Zt.isKeyHotkey(["down","up","enter"],o))return;if(!t.visible){if(Zt.isKeyHotkey("/",o))return void i();if(!Zt.isKeyHotkey(["backspace","delete"],o))return;i()}const s=e.selection.range.getBlocks()[0];if(!s)return;const r=ss(s);null!==r?t.update(r):t.hide()})),()=>{t.unmount()}})),e.Box=fe,e.Button=j,e.Dropdown=he,e.Editor=Ot,e.Fragment=C,e.HTMLParser=xe,e.Nodes=w,e.Range=S,e.TextParser=be,e.Toolbar=me,e.addMark=je,e.deleteContents=He,e.icons=n,e.insertBlock=Re,e.insertBookmark=Ce,e.insertBox=Ke,e.insertContents=Ze,e.query=y,e.removeBox=Xe,e.removeMark=Ue,e.setBlocks=Oe,e.splitBlock=Ve,e.splitMarks=We,e.template=k,e.toBookmark=Le,e.toHex=m,e}({});
116
116
  //# sourceMappingURL=lake.min.js.map