@jackuait/blok 0.15.0 → 0.15.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.
@@ -1,4 +1,4 @@
1
- const e=require(`./chunk-BL1yB9zm.cjs`),t=require(`./constants-D5cYHg42.cjs`),n=require(`./objectSpread2-iNkE6aJh.cjs`),r=require(`./tw-fzSjDKon.cjs`),i=require(`./lightweight-i18n-CNdX4sc2.cjs`),a=require(`./sanitize-url-C41J7vod.cjs`);var o=[`empty:before:pointer-events-none`,`empty:before:text-gray-text`,`empty:before:cursor-text`,`empty:before:content-[attr(data-placeholder)]`,`data-[blok-empty=true]:before:pointer-events-none`,`data-[blok-empty=true]:before:text-gray-text`,`data-[blok-empty=true]:before:cursor-text`,`data-[blok-empty=true]:before:content-[attr(data-placeholder)]`],s=[`empty:before:pointer-events-none`,`empty:before:text-gray-text`,`empty:before:cursor-text`,`empty:before:content-[attr(data-blok-placeholder-active)]`,`data-[empty=true]:before:pointer-events-none`,`data-[empty=true]:before:text-gray-text`,`data-[empty=true]:before:cursor-text`,`data-[empty=true]:before:content-[attr(data-blok-placeholder-active)]`],c=[`empty:focus:before:pointer-events-none`,`empty:focus:before:text-gray-text`,`empty:focus:before:cursor-text`,`empty:focus:before:content-[attr(data-blok-placeholder-active)]`,`[&[data-empty=true]:focus]:before:pointer-events-none`,`[&[data-empty=true]:focus]:before:text-gray-text`,`[&[data-empty=true]:focus]:before:cursor-text`,`[&[data-empty=true]:focus]:before:content-[attr(data-blok-placeholder-active)]`],l=[`empty:in-data-[blok-empty=true]:before:pointer-events-none`,`empty:in-data-[blok-empty=true]:before:text-gray-text`,`empty:in-data-[blok-empty=true]:before:cursor-text`,`empty:in-data-[blok-empty=true]:before:content-[attr(data-blok-placeholder-active)]`,`[[data-blok-empty=true]_&[data-empty=true]]:before:pointer-events-none`,`[[data-blok-empty=true]_&[data-empty=true]]:before:text-gray-text`,`[[data-blok-empty=true]_&[data-empty=true]]:before:cursor-text`,`[[data-blok-empty=true]_&[data-empty=true]]:before:content-[attr(data-blok-placeholder-active)]`],u=e=>{let t=e.innerHTML.trim();return t===``||t===`<br>`},d=e=>{e.innerHTML===`<br>`&&(e.innerHTML=``);let t=window.getSelection();if(!t)return;let n=document.createRange();n.selectNodeContents(e),n.collapse(!0),t.removeAllRanges(),t.addRange(n)},f=e=>{u(e)&&d(e)},p=(e,t,n=`data-placeholder`)=>{e.setAttribute(n,t==null?``:t);let r=()=>f(e);return e.addEventListener(`focus`,r),()=>{e.removeEventListener(`focus`,r),e.removeAttribute(n)}},m,h=e=>{let t=document.createElement(`div`);t.innerHTML=e.trim();let n=document.createDocumentFragment();return n.append(...Array.from(t.childNodes)),n},g=class e{static get DEFAULT_PLACEHOLDER(){return`tools.paragraph.placeholder`}constructor({data:t,config:n,api:r,readOnly:i}){var a,o,s;this.placeholderCleanup=null,this.api=r,this.readOnly=i,this.onKeyUp=this.onKeyUp.bind(this),this._placeholder=(a=n==null?void 0:n.placeholder)==null?e.DEFAULT_PLACEHOLDER:a,this._data=t==null?{text:``}:t,this._element=null,this._preserveBlank=(o=n==null?void 0:n.preserveBlank)==null?!1:o,this._styles=(s=n==null?void 0:n.styles)==null?{}:s}onKeyUp(e){if(e.code!==`Backspace`&&e.code!==`Delete`||!this._element)return;let{textContent:t}=this._element;t===``&&(this._element.innerHTML=``)}buildInlineStyles(){let e={};return this._styles.size&&(e.fontSize=this._styles.size),this._styles.lineHeight&&(e.lineHeight=this._styles.lineHeight),this._styles.marginTop&&(e.marginTop=this._styles.marginTop),this._styles.marginBottom&&(e.marginBottom=this._styles.marginBottom),e}drawView(){let n=document.createElement(`DIV`);n.className=r.n(this.api.styles.block,e.WRAPPER_CLASSES,c,l),n.setAttribute(t.hi.tool,`paragraph`),n.contentEditable=`false`;let i=this.buildInlineStyles();return Object.keys(i).length>0&&Object.assign(n.style,i),this._data.text?n.innerHTML=this._data.text:this.readOnly&&(n.innerHTML=`<br>`),this.readOnly||(n.contentEditable=`true`,n.addEventListener(`keyup`,this.onKeyUp),this.placeholderCleanup=p(n,this.api.i18n.t(this._placeholder),`data-blok-placeholder-active`)),n}render(){return this._element||(this._element=this.drawView()),this._element}setReadOnly(e){this._element&&(this.readOnly=e,e?(this._element.contentEditable=`false`,this._element.removeEventListener(`keyup`,this.onKeyUp),this.placeholderCleanup&&(this.placeholderCleanup(),this.placeholderCleanup=null),u(this._element)&&(this._element.innerHTML=`<br>`)):(this._element.contentEditable=`true`,this._element.addEventListener(`keyup`,this.onKeyUp),this.placeholderCleanup=p(this._element,this.api.i18n.t(this._placeholder),`data-blok-placeholder-active`),this._element.innerHTML===`<br>`&&(this._element.innerHTML=``)))}merge(e){if(!this._element)return;this._data.text+=e.text;let t=h(e.text);this._element.appendChild(t),this._element.normalize()}validate(e){return!(e.text.trim()===``&&!this._preserveBlank)}save(e){return{text:t.Vr(e.innerHTML)}}onPaste(e){let t=e.detail;if(!(`data`in t))return;let n={text:t.data.innerHTML};this._data=n,this._element&&(this._element.innerHTML=this._data.text||``)}static get conversionConfig(){return{export:`text`,import:`text`}}static get sanitize(){return{text:{br:!0,img:{src:!0,style:!0},p:!0,ul:!0,li:!0}}}static get isReadOnlySupported(){return!0}static get pasteConfig(){return{tags:[`P`]}}static get toolbox(){return{icon:t.vn,titleKey:`text`,searchTerms:[`p`,`paragraph`,`plain`],searchTermKeys:[`paragraph`,`plain`]}}};m=g,m.WRAPPER_CLASSES=[`leading-[1.5]`,`outline-hidden`,`mt-px`,`mb-px`,`[&>p:first-of-type]:mt-0`,`[&>p:last-of-type]:mb-0`];var _=e=>{let{data:n,readOnly:r,isOpen:i,keydownHandler:a,onArrowClick:o,onBodyPlaceholderClick:s}=e,c=document.createElement(`div`);c.className=t.a,c.setAttribute(t.hi.tool,t.p),c.setAttribute(t.u.toggleOpen,String(i)),c.setAttribute(t.u.toggleEmpty,`true`);let l=document.createElement(`div`);l.className=t.f;let u=v(i,o,{},e.ariaLabels),d=b(n,r,a);l.appendChild(u),l.appendChild(d);let f=y(s,e.bodyPlaceholderText),p=document.createElement(`div`);return p.className=t.d,p.setAttribute(t.u.toggleChildren,``),p.setAttribute(t.hi.nestedBlocks,``),p.setAttribute(`data-blok-mutation-free`,`true`),p.id=`toggle-children-${Date.now()}-${Math.random().toString(36).slice(2)}`,u.setAttribute(`aria-controls`,p.id),c.appendChild(l),c.appendChild(f),c.appendChild(p),{wrapper:c,arrowElement:u,contentElement:d,bodyPlaceholderElement:f,childContainerElement:p}},v=(e,n,r={},i={collapse:`Collapse`,expand:`Expand`})=>{let a=document.createElement(`span`);a.className=t.i,a.setAttribute(t.u.toggleArrow,``),a.setAttribute(t.hi.mutationFree,`true`),a.setAttribute(`role`,`button`),a.setAttribute(`tabindex`,`0`),a.setAttribute(`aria-label`,e?i.collapse:i.expand),a.setAttribute(`aria-expanded`,String(e)),r.contentEditableFalse===!0&&(a.contentEditable=`false`),a.innerHTML=t.r;let o=a.querySelector(`svg`);return o&&(o.style.transition=`transform 200ms ease-in-out`,e&&(o.style.transform=`rotate(90deg)`)),n&&(a.addEventListener(`click`,e=>{e.stopPropagation(),n()}),a.addEventListener(`keydown`,e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),e.stopPropagation(),n())})),a},y=(e,n)=>{let r=document.createElement(`div`);return r.className=t.s,r.setAttribute(t.u.toggleBodyPlaceholder,``),r.setAttribute(`data-blok-mutation-free`,`true`),r.textContent=n,e&&r.addEventListener(`click`,e),r},b=(e,n,i)=>{let a=document.createElement(`div`);return a.className=r.n(t.c,s,l),a.setAttribute(t.u.toggleContent,``),a.contentEditable=n?`false`:`true`,a.innerHTML=e.text,i&&a.addEventListener(`keydown`,i),a},x=(e,n)=>{for(let r of n){if(r.holder.parentElement===e)continue;let n=r.holder.closest(`[${t.hi.nestedBlocks}]`);if(n!==null&&n!==e&&n.hasAttribute(`data-blok-columns`)&&n.contains(e)){e.appendChild(r.holder);continue}n===null&&e.appendChild(r.holder)}},S=(e,n)=>{var r;if(e===null)return;let i=((r=n==null?void 0:n.textContent)==null?``:r).trim()===``;e.setAttribute(t.u.toggleEmpty,String(i))},C=e=>{let t=_(e);return t.contentElement&&p(t.contentElement,e.placeholder,`data-blok-placeholder-active`),t},w=(e,n,r,i={collapse:`Collapse`,expand:`Expand`})=>{let a=e.querySelector(`svg`);a&&(a.style.transform=r?`rotate(90deg)`:``),e.setAttribute(`aria-label`,r?i.collapse:i.expand),e.setAttribute(`aria-expanded`,String(r)),n.setAttribute(t.u.toggleOpen,String(r))},T=(e,t,n,r,i)=>{let a=e.blocks.getChildren(t);!n&&r&&i&&r.contains(document.activeElement)&&i.focus(),r&&x(r,a);for(let e of a)n?e.holder.classList.remove(`hidden`):e.holder.classList.add(`hidden`);r&&(n?r.removeAttribute(`aria-hidden`):r.setAttribute(`aria-hidden`,`true`))},E=(e,t,n,r,i)=>{if(e===null)return;if(i){e.classList.add(`hidden`);return}let a=t.blocks.getChildren(n);r&&a.length===0?e.classList.remove(`hidden`):e.classList.add(`hidden`)},D=async e=>{var n;let{api:r,blockId:i,data:a,getContentElement:o,syncContentFromDOM:s,isOpen:c}=e;if(s(),i===void 0)return;let l=o(),u=window.getSelection();if(!l||!u||u.rangeCount===0)return;let{beforeContent:d,afterContent:f}=A(l,u.getRangeAt(0)),p=(n=r.blocks.getBlockIndex(i))==null?r.blocks.getCurrentBlockIndex():n;if(c&&f===``){let e=k(r,i,p),t=r.blocks.insertInsideParent(i,e);r.caret.setToBlock(t.id,`start`);return}r.blocks.splitBlock(i,{text:d},t.p,{text:f},p+1),a.text=d},O=async(e,n)=>{let{api:r,blockId:i,data:a,getContentElement:o,syncContentFromDOM:s}=e;if(s(),i===void 0)return;let c=o();if(!c||!t.tr(c))return;let l=a.text;l===``&&(n.preventDefault(),await r.blocks.convert(i,`paragraph`,{text:l}))},k=(e,t,n)=>{var r;let i=e.blocks.getChildren(t);if(i.length===0)return n+1;let a=i[i.length-1],o=(r=e.blocks.getBlockIndex(a.id))==null?n:r;return k(e,a.id,o)},A=(e,t)=>{if(!e.lastChild)return{beforeContent:``,afterContent:``};let n=document.createRange();n.setStart(e,0),n.setEnd(t.startContainer,t.startOffset);let r=document.createRange();r.setStart(t.endContainer,t.endOffset),r.setEndAfter(e.lastChild);let i=document.createElement(`div`);i.appendChild(n.cloneContents());let a=document.createElement(`div`);return a.appendChild(r.cloneContents()),{beforeContent:i.innerHTML,afterContent:a.innerHTML}},j=async e=>{var t;let{api:n,blockId:r,getContentElement:i,syncContentFromDOM:a,isOpen:o,currentLevel:s}=e;if(a(),r===void 0)return;let c=i(),l=window.getSelection();if(!c||!l||l.rangeCount===0)return;let{beforeContent:u,afterContent:d}=A(c,l.getRangeAt(0)),f=(t=n.blocks.getBlockIndex(r))==null?n.blocks.getCurrentBlockIndex():t;if(o&&d===``){let e=k(n,r,f),t=n.blocks.insertInsideParent(r,e);n.caret.setToBlock(t.id,`start`);return}n.blocks.splitBlock(r,{text:u,level:s,isToggleable:!0},`header`,{text:d,level:s,isToggleable:!0},f+1)},M=async(e,n)=>{let{api:r,blockId:i,getText:a,getContentElement:o,syncContentFromDOM:s,currentLevel:c}=e;if(s(),i===void 0)return;let l=o();if(!l||!t.tr(l))return;let u=a();u===``&&(n.preventDefault(),await r.blocks.convert(i,`header`,{text:u,level:c}))},N,P=class e{constructor({data:e,config:t,api:n,readOnly:r,block:i}){var a;this.placeholderCleanup=null,this._arrowElement=null,this._wrapper=null,this._headerRow=null,this._childContainerElement=null,this._bodyPlaceholderElement=null,this.handleChildContainerInput=()=>{S(this._wrapper,this._childContainerElement)},this.handleKeyDown=e=>{if(e.key===`Enter`&&!e.shiftKey){e.preventDefault(),this.handleEnter();return}e.key===`Backspace`&&M(this.createKeyboardContext(),e)},this.handleBlockChanged=e=>{this.isBlockChangedPayload(e)&&(e.event.type===`block-removed`||e.event.type===`block-added`)&&this.updateBodyPlaceholderVisibility()},this.api=n,this.readOnly=r,this._settings=t||{},this._data=this.normalizeData(e),this._isOpen=(a=this._data.isOpen)==null?!0:a,this._element=this.getTag(),i&&(this.blockId=i.id),!r&&this._data.isToggleable&&this.api.events.on(`block changed`,this.handleBlockChanged)}get _CSS(){return{block:this.api.styles.block,wrapper:``}}isHeaderData(e){return typeof e==`object`&&!!e&&`text`in e}normalizeData(e){if(!this.isHeaderData(e))return{text:``,level:this.defaultLevel.number};let n=parseInt(String(e.level)),r=e.level!==void 0&&!isNaN(n),i={text:e.text||``,level:r?n:this.defaultLevel.number};if(e.isToggleable===!0&&(i.isToggleable=!0),typeof e.isOpen==`boolean`&&(i.isOpen=e.isOpen),i.text){let e=document.createElement(`div`);e.innerHTML=i.text;let n=e.querySelector(`[${t.u.toggleArrow}]`);n&&(n.remove(),i.text=e.innerHTML)}return i}render(){return this._data.isToggleable?(this._wrapper=this.buildWrapper(),this._wrapper):this._element}rendered(){this._data.isToggleable&&(this.updateChildrenVisibility(),this.updateBodyPlaceholderVisibility())}removed(){this.api.events.off(`block changed`,this.handleBlockChanged),this._element.removeEventListener(`keydown`,this.handleKeyDown)}setReadOnly(e){if(this._element)if(this.readOnly=e,e)this._element.contentEditable=`false`,this._data.isToggleable&&this._element.removeEventListener(`keydown`,this.handleKeyDown),this.placeholderCleanup&&(this.placeholderCleanup(),this.placeholderCleanup=null);else{this._element.contentEditable=`true`,this._data.isToggleable&&this._element.addEventListener(`keydown`,this.handleKeyDown);let e=this.api.i18n.t(this.currentLevel.nameKey),t=this.resolvePlaceholderText(e);this.placeholderCleanup=p(this._element,t)}}expand(){!this._data.isToggleable||this._isOpen||(this._isOpen=!0,this._arrowElement&&this._element&&w(this._arrowElement,this._element,this._isOpen,{collapse:this.api.i18n.t(`tools.toggle.ariaLabelCollapse`),expand:this.api.i18n.t(`tools.toggle.ariaLabelExpand`)}),this.updateChildrenVisibility(),this.updateBodyPlaceholderVisibility())}collapse(){!this._data.isToggleable||!this._isOpen||(this._isOpen=!1,this._arrowElement&&this._element&&w(this._arrowElement,this._element,this._isOpen,{collapse:this.api.i18n.t(`tools.toggle.ariaLabelCollapse`),expand:this.api.i18n.t(`tools.toggle.ariaLabelExpand`)}),this.updateChildrenVisibility(),this.updateBodyPlaceholderVisibility())}renderSettings(){return this.levels.map(e=>{let t=this.api.i18n.t(e.nameKey),n=t===e.nameKey?e.name:t;return{icon:e.icon,title:n,onActivate:()=>this.setLevel(e.number),closeOnActivate:!0,isActive:this.currentLevel.number===e.number,dataset:{"blok-header-level":String(e.number)}}})}setLevel(e){this.data={level:e,text:this.data.text,isToggleable:this._data.isToggleable}}merge(e){let n=document.createElement(`div`);n.innerHTML=e.text;let r=n.querySelector(`[${t.u.toggleArrow}]`);r&&r.remove(),this._element.insertAdjacentHTML(`beforeend`,n.innerHTML)}validate(e){return typeof e.text==`string`}setData(e){return this._data=this.normalizeData(e),typeof e.text==`string`&&(this._element.innerHTML=e.text),this._data.isToggleable&&typeof this._data.isOpen==`boolean`&&(this._isOpen=this._data.isOpen,this._arrowElement&&this._element&&w(this._arrowElement,this._element,this._isOpen,{collapse:this.api.i18n.t(`tools.toggle.ariaLabelCollapse`),expand:this.api.i18n.t(`tools.toggle.ariaLabelExpand`)}),this.updateChildrenVisibility(),this.updateBodyPlaceholderVisibility()),!0}save(e){let t={text:this._element.innerHTML,level:this.currentLevel.number};return this._data.isToggleable===!0&&(t.isToggleable=!0,t.isOpen=this._isOpen),t}static get conversionConfig(){return{export:`text`,import:`text`}}static get sanitize(){return{level:!1,text:{},isToggleable:!1,isOpen:!1}}static get isReadOnlySupported(){return!0}get data(){return this._data.text=this._element.innerHTML,this._data.level=this.currentLevel.number,this._data}set data(n){if(this._data=this.normalizeData(n),n.level!==void 0&&this._element.parentNode){this._element.removeEventListener(`keydown`,this.handleKeyDown);let e=this.getTag();e.innerHTML=this._element.innerHTML,this._element.parentNode.replaceChild(e,this._element),this._element=e}if(n.text!==void 0&&(this._element.innerHTML=this._data.text||``),this._data.isToggleable){if(this._element.setAttribute(t.u.toggleOpen,String(this._isOpen)),this._element.className=r.n(e.BASE_STYLES,this.currentLevel.styles,o,`pl-8`),!this._wrapper)this.createToggleWrapper();else if(!this._wrapper.querySelector(`[${t.u.toggleArrow}]`)){var i;let e=this.buildArrow();this._arrowElement=e,((i=this._headerRow)==null?this._wrapper:i).prepend(e)}}else if(this._element.removeAttribute(t.u.toggleOpen),this._element.className=r.n(e.BASE_STYLES,this.currentLevel.styles,o),this._arrowElement=null,this._wrapper){let e=this._wrapper.parentNode;e&&e.replaceChild(this._element,this._wrapper),this._wrapper=null,this._headerRow=null}}resolvePlaceholderText(e){return this._settings.placeholder?this.api.i18n.t(this._settings.placeholder):e===this.currentLevel.nameKey?this.currentLevel.name:e}getTag(){let n=document.createElement(this.currentLevel.tag);n.innerHTML=this._data.text||``,n.className=r.n(e.BASE_STYLES,this.currentLevel.styles,o,this._data.isToggleable?`pl-8`:``);let{inlineStyles:i}=this.currentLevel;i&&Object.assign(n.style,i),n.setAttribute(t.hi.tool,`header`),n.contentEditable=this.readOnly?`false`:`true`,this._data.isToggleable&&n.setAttribute(t.u.toggleOpen,String(this._isOpen));let a=this.api.i18n.t(this.currentLevel.nameKey),s=this.resolvePlaceholderText(a);return this.readOnly?n.setAttribute(`data-placeholder`,s):this.placeholderCleanup=p(n,s),!this.readOnly&&this._data.isToggleable&&n.addEventListener(`keydown`,this.handleKeyDown),n}buildArrow(){let e=v(this._isOpen,()=>this.toggleOpen(),{},{collapse:this.api.i18n.t(`tools.toggle.ariaLabelCollapse`),expand:this.api.i18n.t(`tools.toggle.ariaLabelExpand`)});return e.classList.add(`absolute`,`left-0`,`top-1/2`,`-translate-y-1/2`),e}buildWrapper(){let e=document.createElement(`div`);e.setAttribute(t.u.toggleEmpty,`true`);let n=document.createElement(`div`);n.className=`relative`,this._headerRow=n;let i=this.buildArrow();this._arrowElement=i,n.appendChild(i),n.appendChild(this._element),e.appendChild(n);let a=document.createElement(`div`);a.className=r.n(t.s,`pl-8`),a.setAttribute(t.u.toggleBodyPlaceholder,``),a.setAttribute(`data-blok-mutation-free`,`true`),a.textContent=this.api.i18n.t(`tools.toggle.bodyPlaceholder`),this.readOnly||a.addEventListener(`click`,()=>this.handleBodyPlaceholderClick()),this._bodyPlaceholderElement=a,e.appendChild(a);let o=document.createElement(`div`);return o.className=`pl-8`,o.setAttribute(t.u.toggleChildren,``),o.setAttribute(t.hi.nestedBlocks,``),o.setAttribute(`data-blok-mutation-free`,`true`),o.addEventListener(`input`,this.handleChildContainerInput),this._childContainerElement=o,e.appendChild(o),e}createToggleWrapper(){let e=this._element.parentNode;this._wrapper=document.createElement(`div`),this._wrapper.setAttribute(t.u.toggleEmpty,`true`);let n=document.createElement(`div`);n.className=`relative`,this._headerRow=n;let r=this.buildArrow();this._arrowElement=r,n.appendChild(r),e&&e.replaceChild(this._wrapper,this._element),n.appendChild(this._element),this._wrapper.appendChild(n)}createKeyboardContext(){return{api:this.api,blockId:this.blockId,getText:()=>this._element.innerHTML,getContentElement:()=>this._element,syncContentFromDOM:()=>{this._data.text=this._element.innerHTML},isOpen:this._isOpen,currentLevel:this.currentLevel.number}}async handleEnter(){var e=this;await j(e.createKeyboardContext()),e.updateChildrenVisibility(),e.updateBodyPlaceholderVisibility()}toggleOpen(){this._isOpen=!this._isOpen,this._arrowElement&&this._element&&w(this._arrowElement,this._element,this._isOpen,{collapse:this.api.i18n.t(`tools.toggle.ariaLabelCollapse`),expand:this.api.i18n.t(`tools.toggle.ariaLabelExpand`)}),this.updateChildrenVisibility(),this.updateBodyPlaceholderVisibility()}updateChildrenVisibility(){this.blockId!==void 0&&T(this.api,this.blockId,this._isOpen,this._childContainerElement,this._arrowElement)}updateBodyPlaceholderVisibility(){this.blockId!==void 0&&(E(this._bodyPlaceholderElement,this.api,this.blockId,this._isOpen,this.readOnly),S(this._wrapper,this._childContainerElement))}handleBodyPlaceholderClick(){var e;if(this.blockId===void 0)return;let t=this.api.blocks.getBlockIndex(this.blockId);if(t===void 0)return;let n=this.api.blocks.insertInsideParent(this.blockId,t+1);this.api.caret.setToBlock(n.id,`start`),(e=this._bodyPlaceholderElement)==null||e.classList.add(`hidden`)}isBlockChangedPayload(e){return typeof e==`object`&&!!e&&`event`in e&&typeof e.event==`object`&&e.event!==null&&`type`in e.event&&typeof e.event.type==`string`}get currentLevel(){let e=this.levels.find(e=>e.number===this._data.level);return e==null?this.defaultLevel:e}get defaultLevel(){return this._settings.defaultLevel?this.levels.find(e=>e.number===this._settings.defaultLevel)||(console.warn(`(ง'̀-'́)ง Heading Tool: the default level specified was not found in available levels`),this.levels[1]):this.levels[1]}get levels(){let t=this._settings.levelOverrides||{},n=e.DEFAULT_LEVELS.map(e=>{var n;let r=t[e.number]||{},i={};return r.size&&(i.fontSize=r.size),r.marginTop&&(i.marginTop=r.marginTop),r.marginBottom&&(i.marginBottom=r.marginBottom),{number:e.number,tag:((n=r.tag)==null?void 0:n.toUpperCase())||e.tag,nameKey:e.nameKey,name:r.name||e.name,icon:e.icon,styles:e.styles,inlineStyles:i}}),r=this._settings.levels;return r?n.filter(e=>r.includes(e.number)):n}onPaste(e){var t;let n=e.detail;if(!(`data`in n))return;let r=n.data,i=(t={H1:1,H2:2,H3:3,H4:4,H5:5,H6:6}[r.tagName])==null?this.defaultLevel.number:t,a=this._settings.levels?this._settings.levels.reduce((e,t)=>Math.abs(t-i)<Math.abs(e-i)?t:e):i;this.data={level:a,text:r.innerHTML}}static get pasteConfig(){return{tags:[`H1`,`H2`,`H3`,`H4`,`H5`,`H6`]}}static get toolbox(){let n=e.DEFAULT_LEVELS.map(e=>({icon:e.icon,title:e.name,titleKey:e.nameKey,name:`header-${e.number}`,data:{level:e.number},searchTerms:[`h${e.number}`,`title`,`header`,`heading`],searchTermKeys:[`title`,`header`,`heading`],shortcut:`#`.repeat(e.number)})),r={1:t.yn,2:t.bn,3:t.xn},i=e.DEFAULT_LEVELS.filter(e=>e.number<=3).map(e=>({icon:r[e.number],title:`Toggle heading ${e.number}`,titleKey:`tools.header.toggleHeading${e.number}`,name:`toggle-header-${e.number}`,data:{level:e.number,isToggleable:!0},searchTerms:[`toggle`,`heading`,`h${e.number}`,`collapsible`],searchTermKeys:[`toggle`,`heading`,`collapsible`],shortcut:`>`+`#`.repeat(e.number)}));return[...n,...i]}};N=P,N.BASE_STYLES=`py-[7px] px-[2px] m-0 leading-[1.3]! outline-hidden [&_p]:p-0! [&_p]:m-0! [&_div]:p-0! [&_div]:m-0!`,N.DEFAULT_LEVELS=[{number:1,tag:`H1`,nameKey:`tools.header.heading1`,name:`Heading 1`,icon:t.Ct,styles:`text-3xl font-semibold mt-8 mb-px`},{number:2,tag:`H2`,nameKey:`tools.header.heading2`,name:`Heading 2`,icon:t.wt,styles:`text-2xl font-semibold mt-[26px] mb-px`},{number:3,tag:`H3`,nameKey:`tools.header.heading3`,name:`Heading 3`,icon:t.Tt,styles:`text-xl font-semibold mt-5 mb-px`},{number:4,tag:`H4`,nameKey:`tools.header.heading4`,name:`Heading 4`,icon:t.Et,styles:`text-lg font-semibold mt-3 mb-px`},{number:5,tag:`H5`,nameKey:`tools.header.heading5`,name:`Heading 5`,icon:t.Dt,styles:`text-base font-semibold mt-3 mb-px`},{number:6,tag:`H6`,nameKey:`tools.header.heading6`,name:`Heading 6`,icon:t.Ot,styles:`text-sm font-semibold mt-3 mb-px`}];var ee=`outline-hidden py-[7px] mt-[2px] mb-px`,te=`outline-hidden pl-0.5 leading-[1.5] items-start`,ne=`flex items-start pl-0.5`,re=`mt-0.5 w-5 mr-2 h-5 cursor-pointer accent-current`,ie=`tools.list.placeholder`,ae=`list`,F={contentContainer:`list-content-container`,checklistContent:`list-checklist-content`},oe=(e,t)=>{let n=e;n._placeholder=t,Object.defineProperty(n,`getPlaceholder`,{value:()=>n._placeholder,writable:!1,enumerable:!0,configurable:!1})},se=e=>{let{data:t,keydownHandler:n,readOnly:r}=e,i=ce(e),a=t.style===`checklist`?ue(e):le(e);i.appendChild(a),!r&&n&&i.addEventListener(`keydown`,n);let o=a.querySelector(`[data-list-marker]`),s=a.querySelector(`input[type="checkbox"]`),c=t.style===`checklist`?a.querySelector(`[data-blok-testid="${F.checklistContent}"]`):a.querySelector(`[data-blok-testid="${F.contentContainer}"]`);return{wrapper:i,contentElement:c==null?a:c,markerElement:o,checkboxElement:s}},ce=e=>{var n;let{data:r}=e,i=document.createElement(`div`);return i.className=ee,i.setAttribute(t.hi.tool,ae),i.setAttribute(`data-list-style`,r.style),i.setAttribute(`data-list-depth`,String((n=r.depth)==null?0:n)),r.start!==void 0&&r.start!==1&&i.setAttribute(`data-list-start`,String(r.start)),i},le=e=>{var t;let{data:n,itemColor:i,itemSize:a,placeholder:s,markerDepth:c}=e,l=document.createElement(`div`);l.setAttribute(`role`,`listitem`),l.className=r.n(te,`flex`,...o),i&&(l.style.color=i),a&&(l.style.fontSize=a);let u=(t=n.depth)==null?0:t;if(u>0){let e=n.style===`ordered`?26:27;l.style.marginLeft=`${u*e}px`}let d=de(n.style,c==null?u:c);d.setAttribute(`data-list-marker`,`true`),d.setAttribute(`data-blok-mutation-free`,`true`),l.appendChild(d);let f=document.createElement(`div`);return f.className=r.n(`flex-1 min-w-0 outline-hidden`,...o),f.setAttribute(`data-blok-testid`,F.contentContainer),f.contentEditable=e.readOnly?`false`:`true`,f.innerHTML=n.text,oe(f,s),l.appendChild(f),l},ue=e=>{var t;let{data:n,itemColor:i,itemSize:a,placeholder:s,readOnly:c}=e,l=document.createElement(`div`);l.setAttribute(`role`,`listitem`),l.className=ne,i&&(l.style.color=i),a&&(l.style.fontSize=a);let u=(t=n.depth)==null?0:t;u>0&&(l.style.marginLeft=`${u*27}px`);let d=document.createElement(`input`);d.type=`checkbox`,d.className=re,d.checked=!!n.checked,d.disabled=c;let f=document.createElement(`div`);return f.className=r.n(`flex-1 outline-hidden leading-[1.5]`,n.checked?`line-through opacity-60`:``,...o),f.setAttribute(`data-blok-testid`,F.checklistContent),f.setAttribute(`data-checked`,String(n.checked)),f.contentEditable=c?`false`:`true`,f.innerHTML=n.text,oe(f,s),l.appendChild(d),l.appendChild(f),l},de=(e,t)=>{let n=document.createElement(`span`);return n.className=`shrink-0 select-none`,n.setAttribute(`aria-hidden`,`true`),n.contentEditable=`false`,e===`ordered`?(n.textContent=`1.`,n.className=r.n(n.className,`text-right`),n.style.paddingRight=`11px`,n.style.minWidth=`fit-content`):(n.textContent=fe(t),n.className=r.n(n.className,`w-6 text-center flex justify-center`),n.style.paddingLeft=`1px`,n.style.paddingRight=`13px`,n.style.fontSize=`24px`,n.style.fontFamily=`Arial`,n.style.lineHeight=`1.5rem`),n},fe=e=>{let t=[`•`,`◦`,`▪`];return t[e%t.length]},pe=e=>{let{data:t,readOnly:n,placeholder:r,itemColor:i,itemSize:a,markerDepth:o,element:s,setupItemPlaceholder:c,onCheckboxChange:l,keydownHandler:u}=e;if(!s)return null;let d=s.parentNode;if(!d)return null;let f=se({data:t,readOnly:n,placeholder:r,itemColor:i,itemSize:a,markerDepth:o,keydownHandler:u});if(f.contentElement&&c(f.contentElement),f.checkboxElement&&!n){let e=f.checkboxElement;e.addEventListener(`change`,()=>{l(e.checked,f.contentElement)})}return d.replaceChild(f.wrapper,s),f.wrapper},me=(e,r,i)=>{if(!r)return e;let a=i(),o=n.t({text:a?t.Vr(a.innerHTML):e.text,style:e.style},e.style===`checklist`?{checked:!!e.checked}:{});return e.start!==void 0&&e.start!==1&&(o.start=e.start),e.depth!==void 0&&e.depth>0&&(o.depth=e.depth),o},he=(e,t,r,i,a)=>{var o,s;if(!r)return{newData:e,inPlace:!1};let c=(o=e.depth)==null?0:o,l=(s=t.depth)==null?0:s,u=e.style,d=t.style;if(u!==d)return{newData:e,inPlace:!1};let f=`depth`in t?t.depth:0,p=n.t(n.t(n.t({},e),t),{},{depth:f}),m=i();if(m&&typeof t.text==`string`&&(m.innerHTML=t.text),c!==l)return a.adjustDepthTo(l),a.updateMarkerForDepth(l,d),{newData:p,inPlace:!0};if(d===`checklist`){var h;a.updateCheckboxState((h=t.checked)==null?!1:h)}return{newData:p,inPlace:!0}},ge=(e,t)=>{let{element:n,getContentElement:r,parseHTML:i,data:a}=e;if(!n)return;a.text+=t.text;let o=r();if(o&&t.text){let e=i(t.text);o.appendChild(e),o.normalize()}},_e=(e,t,n,r)=>e.map(e=>({icon:e.icon,title:n(`toolNames.${e.titleKey}`),onActivate:()=>r(e.style),closeOnActivate:!0,isActive:t===e.style})),ve=e=>{if(!e)return;let t=(e.getAttribute(`style`)||``).match(/margin-left:\s*(\d+)px/);if(!t)return;let n=parseInt(t[1],10);return n>0?{left:n}:void 0},ye=e=>{let t=e.closest(`[data-list-depth]`);if(!t)return;let n=t.getAttribute(`data-list-depth`);if(n===null)return;let r=parseInt(n,10);return r>0?{left:r*27}:void 0},be=e=>{let t=ve(e.closest(`[role="listitem"]`)||e.querySelector(`[role="listitem"]`));return t===void 0?ye(e):t},xe=(e,t)=>{let n=document.createRange();if(n.setStart(e,0),n.setEnd(t.startContainer,t.startOffset),!e.lastChild)return{beforeContent:``,afterContent:``};let r=document.createRange();return r.setStart(t.endContainer,t.endOffset),r.setEndAfter(e.lastChild),{beforeContent:Se(n.cloneContents()),afterContent:Se(r.cloneContents())}},Se=e=>{let t=document.createElement(`div`);return t.appendChild(e),t.innerHTML},Ce=e=>{let t=document.createElement(`div`);t.innerHTML=e.trim();let n=document.createDocumentFragment();return n.append(...Array.from(t.childNodes)),n},we=(e,t)=>{let n=document.createRange();return n.selectNodeContents(e),n.setEnd(t.startContainer,t.startOffset),n.toString().length===0},Te=(e,t)=>{let n=document.createRange();n.selectNodeContents(e),n.setEnd(t.startContainer,t.startOffset);let r=n.toString().length===0,i=document.createRange();i.selectNodeContents(e),i.setStart(t.endContainer,t.endOffset);let a=i.toString().length===0;return r&&a},Ee=e=>{if(typeof e!=`object`||!e)return!1;let t=Object.entries(e).find(([e])=>e===`items`);return t===void 0?!1:Array.isArray(t[1])},De=e=>typeof e==`object`&&!!e,Oe=e=>typeof e==`string`?e:``,ke=(e,t)=>e===`unordered`||e===`ordered`||e===`checklist`?e:t,Ae=e=>!!e,je=(e,t)=>typeof e==`number`?e:t,Me=(e,t)=>{let r=t.defaultStyle||`unordered`;if(!e||typeof e!=`object`)return{text:``,style:r,checked:!1,depth:0};if(Ee(e)){let{text:t,checked:i}=(e=>{if(typeof e==`string`)return{text:e,checked:!1};if(typeof e==`object`&&e){var t,n,r;return{text:(t=(n=e.content)==null?e.text:n)==null?``:t,checked:(r=e.checked)==null?!1:r}}return{text:``,checked:!1}})(e.items[0]);return n.t({text:t,style:e.style||r,checked:!!i,depth:0},e.start!==void 0&&e.start!==1?{start:e.start}:{})}if(De(e)){let t=Oe(e.text),i=ke(e.style,r),a=Ae(e.checked),o=je(e.depth,0),s=e.start,c=typeof s==`number`&&s!==void 0&&s!==1?s:void 0;return n.t({text:t,style:i,checked:a,depth:o},c===void 0?{}:{start:c})}return{text:``,style:r,checked:!1,depth:0}},Ne=class{constructor(e){this.blocks=e}getMaxAllowedDepth(e){if(e===0)return 1;let t=this.blocks.getBlockByIndex(e-1);return!t||t.name!==`list`?1:this.getBlockDepth(t)+1}getTargetDepthForMove(e){let{blockIndex:t,currentDepth:n,skipDepthPromotion:r}=e,i=this.getMaxAllowedDepth(t);if(n>i)return i;if(r)return n;let a=this.blocks.getBlockByIndex(t+1),o=a&&a.name===`list`,s=o?this.getBlockDepth(a):0;if(o&&s>n&&s<=i)return s;let c=t>0?this.blocks.getBlockByIndex(t-1):void 0,l=c&&c.name===`list`,u=l?this.getBlockDepth(c):0;return l&&!o&&u>n&&u<=i?u:n}isValidDepth(e,t){let n=this.getMaxAllowedDepth(e);return t>=0&&t<=n}getBlockDepth(e){var t;if(!e)return 0;let n=(t=e.holder)==null||(t=t.querySelector(`[role="listitem"]`))==null?void 0:t.getAttribute(`style`),r=n==null?void 0:n.match(/margin-left:\s*(\d+)px/);return r?Math.round(parseInt(r[1],10)/27):0}},Pe=(e,t)=>{if(!e)return null;if(t===`checklist`){let t=e.querySelector(`[data-blok-testid="list-checklist-content"]`);return t instanceof HTMLElement?t:null}let n=e.querySelector(`[data-blok-testid="list-content-container"]`);return n instanceof HTMLElement?n:null},Fe=(e,t,n)=>{e&&e.setAttribute(`data-list-depth`,String(n));let r=e==null?void 0:e.querySelector(`[role="listitem"]`);r instanceof HTMLElement&&(r.style.marginLeft=n>0?`${n*27}px`:``),t.depth=n},Ie=(e,t)=>t.getBlockDepth(e),Le=(e,t)=>t.getBlockStyle(e),Re=(e,t)=>t.getBulletCharacter(e),ze=(e,t,n,r,i)=>{var a;let o=e?(a=r.getBlockIndex(e))==null?r.getCurrentBlockIndex():a:r.getCurrentBlockIndex();return o<=0?0:i.getSiblingIndex(o,t,n)},Be=(e,t,n,r,i,a)=>{var o;if(e===0){var s;return(s=r.start)==null?1:s}let c=n?(o=i.getBlockIndex(n))==null?i.getCurrentBlockIndex():o:i.getCurrentBlockIndex(),l=a.findFirstItemIndex(c-1,t,e,r.style);return l===null?1:a.getBlockStartValue(l)},Ve=(e,t,n,r,i,a)=>{var o;let s=Be(e,t,r,n,i,a)+e,c=r?(o=i.getBlockIndex(r))==null?i.getCurrentBlockIndex():o:i.getCurrentBlockIndex(),l=a.getVisualDepth(c,t);return a.formatNumber(s,l)},He=(e,t,n,r)=>r.findGroupStart(e,t,n),Ue=(e,t,n,r)=>{if(!e)return;let i=e.holder,a=i==null?void 0:i.querySelector(`[data-list-style="ordered"]`);if(!a)return;let o=a.querySelector(`[data-list-marker]`);if(!o)return;let s=t.getBlockIndex(e.id);if(s==null)return;let c=Ie(e,n),l=Le(e,r)||`ordered`,u=r.getSiblingIndex(s,c,l),d=r.getGroupStartValue(s,c,u,l)+u,f=r.getVisualDepth(s,c);o.textContent=r.formatNumber(d,f)},We=(e,t,n,r,i,a,o,s)=>{let c=e=>{if(e>=t)return;if(e===n){c(e+1);return}let l=a.getBlockByIndex(e);if(!l||l.name!==`list`)return;let u=Ie(l,o);if(!(u<r)){if(u>r){c(e+1);return}Le(l,s)===i&&(Ue(l,a,o,s),c(e+1))}};c(e)},Ge=(e,t,n)=>{let r=e.getBlocksCount();Array.from({length:r},(e,t)=>t).forEach(r=>{let i=e.getBlockByIndex(r);if(!i||i.name!==`list`)return;let a=i.holder;a!=null&&a.querySelector(`[data-list-style="ordered"]`)&&Ue(i,e,t,n)})},Ke=(e,t,n=`end`)=>{let r=()=>{let r=t.holder;if(!r)return;let i=r.querySelector(`[contenteditable="true"]`);if(!(i instanceof HTMLElement)){e.caret.setToBlock(t,n),e.caret.updateLastCaretAfterPosition();return}i.focus();let a=window.getSelection();if(!a)return;let o=document.createRange();n===`start`?(o.setStart(i,0),o.collapse(!0)):(o.selectNodeContents(i),o.collapse(!1)),a.removeAllRanges(),a.addRange(o),e.caret.updateLastCaretAfterPosition()},i=t.holder;(i==null?void 0:i.querySelector(`[contenteditable="true"]`))instanceof HTMLElement?r():requestAnimationFrame(()=>r())},qe=async(e,t)=>{var r;let{api:i,blockId:a,data:o,element:s,getContentElement:c}=e,l=window.getSelection();if(!l||!s)return;let u=c();if(!u)return;let d=u.innerHTML.trim();if(d===``||d===`<br>`){await Je(e,t);return}let{beforeContent:f,afterContent:p}=xe(u,l.getRangeAt(0)),m=a?(r=i.blocks.getBlockIndex(a))==null?i.blocks.getCurrentBlockIndex():r:i.blocks.getCurrentBlockIndex();if(!a){u.innerHTML=f,o.text=f,Ke(i,i.blocks.insert(ae,n.t(n.t({text:p,style:o.style},o.style===`checklist`?{checked:!!o.checked}:{}),{},{depth:o.depth}),void 0,m+1,!0),`start`);return}let h=i.blocks.splitBlock(a,{text:f},ae,n.t(n.t({text:p,style:o.style},o.style===`checklist`?{checked:!!o.checked}:{}),{},{depth:o.depth}),m+1);o.text=f,Ke(i,h,`start`)},Je=async(e,t)=>{let{api:n,blockId:r,getDepth:i}=e;if(i()>0){await Qe(e,t);return}r!==void 0&&Ke(n,await n.blocks.convert(r,`paragraph`,{text:``}),`start`)},Ye=async(e,t)=>{let{api:n,blockId:r,data:i,element:a,getContentElement:o,getDepth:s,syncContentFromDOM:c}=e,l=window.getSelection();if(!l||!a)return;let u=l.getRangeAt(0),d=o();if(!d)return;c();let f=i.text,p=s();if(Te(d,u)&&!l.isCollapsed){t.preventDefault(),d.innerHTML=``,i.text=``;let e=document.createRange();e.setStart(d,0),e.collapse(!0),l.removeAllRanges(),l.addRange(e);return}if(!we(d,u)||(t.preventDefault(),r===void 0))return;let m=await n.blocks.convert(r,`paragraph`,{text:f});p>0&&requestAnimationFrame(()=>{let e=m.holder;e&&(e.style.marginLeft=`${p*27}px`,e.setAttribute(`data-blok-depth`,String(p)))}),Ke(n,m,`start`)},Xe=async(e,t)=>{let{api:r,blockId:i,data:a,syncContentFromDOM:o,getDepth:s}=e,c=r.blocks.getCurrentBlockIndex(),l=s();if(l>=t.getMaxAllowedDepth(c))return;o();let u=l+1;a.depth=u,Ke(r,await r.blocks.update(i||``,n.t(n.t({},a),{},{depth:u})))},Ze=async(e,t,n,r)=>{var i;let a=t?(i=e.blocks.getBlockIndex(t))==null?e.blocks.getCurrentBlockIndex():i:e.blocks.getCurrentBlockIndex(),o=e.blocks.getBlocksCount(),s=async t=>{if(t>=o)return;let i=e.blocks.getBlockByIndex(t);if(!i||i.name!==`list`)return;let a=r.getBlockDepth(i);a<=n||(await e.blocks.update(i.id,{depth:a-1}),await s(t+1))};await s(a+1)},Qe=async(e,t)=>{let{api:r,blockId:i,data:a,syncContentFromDOM:o,getDepth:s}=e,c=s();if(c===0)return;o();let l=c-1;a.depth=l;let u=await r.blocks.update(i||``,n.t(n.t({},a),{},{depth:l}));t&&await Ze(r,i,c,t),Ke(r,u)},$e=e=>{let{data:t,readOnly:n,placeholder:r,itemColor:i,itemSize:a,markerDepth:o,setupItemPlaceholder:s,onCheckboxChange:c,keydownHandler:l}=e,u=se({data:t,readOnly:n,placeholder:r,itemColor:i,itemSize:a,markerDepth:o,keydownHandler:l});if(u.contentElement&&s(u.contentElement),u.checkboxElement&&!n){let e=u.checkboxElement;e.addEventListener(`change`,()=>{c(e.checked,u.contentElement)})}return u.wrapper},et=e=>{let t=e=>{if(e<=0)return``;let n=e-1;return t(Math.floor(n/26))+String.fromCharCode(97+n%26)};return t(e)},tt=e=>{let t=[[1e3,`m`],[900,`cm`],[500,`d`],[400,`cd`],[100,`c`],[90,`xc`],[50,`l`],[40,`xl`],[10,`x`],[9,`ix`],[5,`v`],[4,`iv`],[1,`i`]],n=(e,r)=>{if(e<=0||r>=t.length)return``;let[i,a]=t[r];return e>=i?a+n(e-i,r):n(e,r+1)};return n(e,0)},nt=class{constructor(e){this.blocks=e}getMarkerText(e){let{blockIndex:t,depth:n,style:r,start:i}=e;if(r!==`ordered`)return this.getBulletCharacter(n);let a=this.getSiblingIndex(t,n,r),o=(i==null?this.getGroupStartValue(t,n,a,r):i)+a;return this.formatNumber(o,n)}getBulletCharacter(e){let t=[`•`,`◦`,`▪`];return t[e%t.length]}getSiblingIndex(e,t,n){return e<=0?0:this.countPrecedingAtDepth(e-1,t,n)}findGroupStart(e,t,n){return this.findGroupStartRecursive(e-1,e,t,n)}formatNumber(e,t){let n=t%3;return n===1?`${et(e)}.`:n===2?`${tt(e)}.`:`${e}.`}getGroupStartValue(e,t,n,r){if(n===0)return this.getBlockStartValue(e);let i=this.findFirstItemIndex(e-1,t,n,r);return i===null?1:this.getBlockStartValue(i)}getBlockStartValue(e){var t;let n=this.blocks.getBlockByIndex(e);if(!n)return 1;let r=(t=n.holder)==null?void 0:t.querySelector(`[data-list-style]`);if(!r)return 1;let i=r.getAttribute(`data-list-start`);return i?parseInt(i,10):1}findFirstItemIndex(e,t,n,r){if(e<0||n<=0)return e+1;let i=this.blocks.getBlockByIndex(e);if(!i||i.name!==`list`)return e+1;let a=this.getBlockDepth(i);if(a<t)return e+1;if(a>t)return this.findFirstItemIndex(e-1,t,n,r);let o=this.getBlockStyle(i);return r!==void 0&&o!==r?e+1:this.findFirstItemIndex(e-1,t,n-1,r)}getGroupBaseDepth(e){let t=e=>{if(e<=0)return 0;let n=this.blocks.getBlockByIndex(e-1);return!n||n.name!==`list`?e:t(e-1)},n=t(e),r=this.blocks.getBlockByIndex(n);return this.getBlockDepth(r)}getVisualDepth(e,t){return Math.max(0,t-this.getGroupBaseDepth(e))}getBlockDepth(e){var t;if(!e)return 0;let n=(t=e.holder)==null||(t=t.querySelector(`[role="listitem"]`))==null?void 0:t.getAttribute(`style`),r=n==null?void 0:n.match(/margin-left:\s*(\d+)px/);return r?Math.round(parseInt(r[1],10)/27):0}getBlockStyle(e){var t;if(!e)return null;let n=(t=e.holder)==null||(t=t.querySelector(`[data-list-style]`))==null?void 0:t.getAttribute(`data-list-style`);return this.isValidListItemStyle(n)?n:null}isValidListItemStyle(e){return e===`unordered`||e===`ordered`||e===`checklist`}countPrecedingAtDepth(e,t,n){if(e<0)return 0;let r=this.blocks.getBlockByIndex(e);if(!r||r.name!==`list`)return 0;let i=this.getBlockDepth(r);return i<t?0:i>t?this.countPrecedingAtDepth(e-1,t,n):this.getBlockStyle(r)===n?1+this.countPrecedingAtDepth(e-1,t,n):0}findGroupStartRecursive(e,t,n,r){if(e<0)return t;let i=this.blocks.getBlockByIndex(e);if(!i||i.name!==`list`)return t;let a=this.getBlockDepth(i);return a<n?t:a>n?this.findGroupStartRecursive(e-1,t,n,r):this.getBlockStyle(i)===r?this.findGroupStartRecursive(e-1,e,n,r):t}},rt={value:!1},it=class{constructor(e){this.blocks=e,this.depthValidator=new Ne(e),this.markerCalculator=new nt(e)}updateMarker(e,t,n){let r=e.querySelector(`[data-list-marker]`);if(!r)return;let i=this.markerCalculator.getSiblingIndex(t,n,`ordered`),a=this.markerCalculator.getGroupStartValue(t,n,i,`ordered`),o=(i===0&&a===1?(()=>{let t=e.getAttribute(`data-list-start`);if(!t)return a;let n=parseInt(t,10);return isNaN(n)?a:n})():a)+i,s=this.markerCalculator.getVisualDepth(t,n);r.textContent=this.markerCalculator.formatNumber(o,s)}updateSiblingMarkers(e,t){let n=this.blocks.getBlocksCount(),r=this.findListGroupStartIndex(e,t,`ordered`);this.updateMarkersInRange(r,n,e,t,`ordered`)}updateAllMarkers(){let e=this.blocks.getBlocksCount();for(let t of Array.from({length:e},(e,t)=>t)){let e=this.blocks.getBlockByIndex(t);if(!e||e.name!==`list`)continue;let n=e.holder;n!=null&&n.querySelector(`[data-list-style="ordered"]`)&&this.updateBlockMarker(e)}}scheduleUpdateAll(){rt.value||(rt.value=!0,requestAnimationFrame(()=>{rt.value=!1,this.updateAllMarkers()}))}findListGroupStartIndex(e,t,n){return this.markerCalculator.findGroupStart(e,t,n)}updateMarkersInRange(e,t,n,r,i){let a=Array.from({length:t-e},(t,n)=>e+n);for(let e of a){if(e===n)continue;let t=this.blocks.getBlockByIndex(e);if(!t||t.name!==`list`)return;let a=this.depthValidator.getBlockDepth(t);if(a<r)return;if(!(a>r)){if(this.getBlockStyle(t)!==i)return;this.updateBlockMarker(t)}}}getBlockStyle(e){return this.markerCalculator.getBlockStyle(e)}updateBlockMarker(e){if(!e)return;let t=e.holder,n=t==null?void 0:t.querySelector(`[data-list-style="ordered"]`);if(!n)return;let r=n.querySelector(`[data-list-marker]`);if(!r)return;let i=this.blocks.getBlockIndex(e.id);if(i==null)return;let a=this.depthValidator.getBlockDepth(e),o=this.getBlockStyle(e)||`ordered`,s=this.markerCalculator.getSiblingIndex(i,a,o),c=this.markerCalculator.getGroupStartValue(i,a,s,o),l=(s===0&&c===1?(()=>{let e=n.closest(`[data-list-start]`),t=e==null?void 0:e.getAttribute(`data-list-start`);if(!t)return c;let r=parseInt(t,10);return isNaN(r)?c:r})():c)+s,u=this.markerCalculator.getVisualDepth(i,a);r.textContent=this.markerCalculator.formatNumber(l,u)}},at=e=>e instanceof HTMLElement,ot=new Set(`decimal.decimal-leading-zero.lower-roman.upper-roman.lower-greek.lower-latin.upper-latin.lower-alpha.upper-alpha.arabic-indic.armenian.bengali.cambodian.cjk-decimal.devanagari.georgian.gujarati.gurmukhi.hebrew.kannada.khmer.lao.malayalam.mongolian.myanmar.oriya.persian.telugu.thai.tibetan`.split(`.`)),st=new Set([`disc`,`circle`,`square`,`none`]),ct=e=>{let t=e.getAttribute(`data-list-style`);if(t===`ordered`)return`ordered`;if(t===`unordered`)return`unordered`;let n=e.getAttribute(`style`);if(!n)return null;let r=n.match(/list-style-type\s*:\s*([^;]+)/);if(!r)return null;let i=r[1].trim().toLowerCase();return ot.has(i)?`ordered`:st.has(i)?`unordered`:null},lt=(e,t)=>{let n=e.parentElement;return(n==null?void 0:n.tagName)===`OL`?`ordered`:(n==null?void 0:n.tagName)===`UL`?e.querySelector(`input[type="checkbox"]`)?`checklist`:`unordered`:ct(e)||t},ut=e=>{let t=e.innerHTML||e.textContent||``,n=e.querySelector(`input[type="checkbox"]`);return{text:t,checked:n instanceof HTMLInputElement?n.checked:!1}},dt=e=>{let t=e.getAttribute(`aria-level`);return t?Math.max(0,parseInt(t,10)-1):0},ft=()=>({text:{br:!0,a:{href:!0,target:`_blank`,rel:`nofollow`},b:!0,i:!0}}),pt=()=>({tags:[{li:{style:!0,"aria-level":!0}}]}),mt=()=>({export:e=>e.text,import:e=>({text:e,style:`unordered`,checked:!1})}),ht=[{name:`bulletedList`,titleKey:`bulletedList`,style:`unordered`,icon:t.Kt},{name:`numberedList`,titleKey:`numberedList`,style:`ordered`,icon:t.Jt},{name:`todoList`,titleKey:`todoList`,style:`checklist`,icon:t.qt}],gt=()=>[{icon:t.Kt,titleKey:`bulletedList`,data:{style:`unordered`},name:`bulleted-list`,searchTerms:[`ul`,`bullet`,`unordered`,`list`],searchTermKeys:[`bullet`,`unordered`,`list`],shortcut:`-`},{icon:t.Jt,titleKey:`numberedList`,data:{style:`ordered`},name:`numbered-list`,searchTerms:[`ol`,`ordered`,`number`,`list`],searchTermKeys:[`ordered`,`number`,`list`],shortcut:`1.`},{icon:t.qt,titleKey:`todoList`,data:{style:`checklist`},name:`check-list`,searchTerms:[`checkbox`,`task`,`todo`,`check`,`list`],searchTermKeys:[`checkbox`,`task`,`todo`,`check`,`list`],shortcut:`[]`}],_t=class{constructor({data:e,config:t,api:n,readOnly:r,block:i}){this._element=null,this.placeholderCleanup=null,this.boundHandleKeyDown=null,this.handleBlockChanged=e=>{if(this.isBlockChangedEventPayload(e)&&(e.event.type===`block-removed`||e.event.type===`block-added`)){var t;(t=this.markerManager)==null||t.scheduleUpdateAll()}},this.api=n,this.readOnly=r,this._settings=t||{},this._data=this.normalizeData(e),this.depthValidator=new Ne(n.blocks),this.markerCalculator=new nt(n.blocks),this.markerManager=this._data.style===`ordered`?new it(n.blocks):null,i&&(this.blockId=i.id),this._data.style===`ordered`&&this.api.events.on(`block changed`,this.handleBlockChanged)}isBlockChangedEventPayload(e){return typeof e==`object`&&!!e&&`event`in e&&typeof e.event==`object`&&e.event!==null&&`type`in e.event&&typeof e.event.type==`string`}normalizeData(e){return Me(e,this._settings)}get availableStyles(){let e=this._settings.styles;return!e||e.length===0?ht:ht.filter(t=>e.includes(t.style))}get itemColor(){return this._settings.itemColor}get itemSize(){return this._settings.itemSize}get placeholder(){return this.api.i18n.t(ie)}setupItemPlaceholder(e){this.readOnly||(this.placeholderCleanup=p(e,this.placeholder))}render(){var e,t;if(this._element)return this._element;let n=this.blockId?(e=this.api.blocks.getBlockIndex(this.blockId))==null?this.api.blocks.getCurrentBlockIndex():e:this.api.blocks.getCurrentBlockIndex(),r=(t=this._data.depth)==null?0:t,i=this.markerCalculator.getVisualDepth(n,r);return this.boundHandleKeyDown||(this.boundHandleKeyDown=this.handleKeyDown.bind(this)),this._element=$e({data:this._data,readOnly:this.readOnly,placeholder:this.placeholder,itemColor:this.itemColor,itemSize:this.itemSize,markerDepth:i,setupItemPlaceholder:this.setupItemPlaceholder.bind(this),onCheckboxChange:(e,t)=>{this._data.checked=e,t instanceof HTMLElement&&(t.classList.toggle(`line-through`,e),t.classList.toggle(`opacity-60`,e))},keydownHandler:this.readOnly?void 0:this.boundHandleKeyDown}),this._element}setReadOnly(e){if(!this._element)return;this.readOnly=e;let t=this.getContentElement();t&&(t.contentEditable=e?`false`:`true`);let n=this._element.querySelector(`input[type="checkbox"]`);n&&(n.disabled=e),e?(this.boundHandleKeyDown&&this._element.removeEventListener(`keydown`,this.boundHandleKeyDown),this.placeholderCleanup&&(this.placeholderCleanup(),this.placeholderCleanup=null)):(this.boundHandleKeyDown&&this._element.addEventListener(`keydown`,this.boundHandleKeyDown),t&&(this.placeholderCleanup=p(t,this.placeholder)))}rendered(){this.updateMarkersAfterPositionChange()}moved(e){this.validateAndAdjustDepthAfterMove(e.toIndex,e.isGroupMove),this.updateMarkersAfterPositionChange()}updateMarkersAfterPositionChange(){this._data.style!==`ordered`||!this._element||(this.updateMarker(),this.updateSiblingListMarkers())}validateAndAdjustDepthAfterMove(e,t){let n=this.getDepth(),r=this.depthValidator.getTargetDepthForMove({blockIndex:e,currentDepth:n,skipDepthPromotion:t});n!==r&&this.adjustDepthTo(r)}adjustDepthTo(e){Fe(this._element,this._data,e)}removed(){var e;this._data.style===`ordered`&&(this.api.events.off(`block changed`,this.handleBlockChanged),(e=this.markerManager)==null||e.scheduleUpdateAll())}updateAllOrderedListMarkers(){Ge(this.api.blocks,this.depthValidator,this.markerCalculator)}updateMarker(){var e;let t=(e=this._element)==null?void 0:e.querySelector(`[data-list-marker]`);if(!t)return;let n=this.getDepth();t.textContent=Ve(ze(this.blockId,n,this._data.style,this.api.blocks,this.markerCalculator),n,this._data,this.blockId,this.api.blocks,this.markerCalculator)}updateSiblingListMarkers(){var e;let t=this.blockId?(e=this.api.blocks.getBlockIndex(this.blockId))==null?this.api.blocks.getCurrentBlockIndex():e:this.api.blocks.getCurrentBlockIndex(),n=this.getDepth(),r=this._data.style,i=this.api.blocks.getBlocksCount();We(He(t,n,r,this.markerCalculator),i,t,n,r,this.api.blocks,this.depthValidator,this.markerCalculator)}updateMarkerForDepth(e,t){var n,r;let i=(n=this._element)==null?void 0:n.querySelector(`[aria-hidden="true"]`);if(!(i instanceof HTMLElement))return;let a=this.blockId?(r=this.api.blocks.getBlockIndex(this.blockId))==null?this.api.blocks.getCurrentBlockIndex():r:this.api.blocks.getCurrentBlockIndex(),o=this.markerCalculator.getVisualDepth(a,e);t===`ordered`?i.textContent=Ve(ze(this.blockId,e,this._data.style,this.api.blocks,this.markerCalculator),e,this._data,this.blockId,this.api.blocks,this.markerCalculator):i.textContent=Re(o,this.markerCalculator)}updateCheckboxState(e){var t;let n=(t=this._element)==null?void 0:t.querySelector(`input[type="checkbox"]`);n instanceof HTMLInputElement&&(n.checked=e)}getDepth(){var e;return(e=this._data.depth)==null?0:e}handleKeyDown(e){if(e.key===`Enter`&&!e.shiftKey){e.preventDefault(),this.handleEnter();return}if(e.key===`Backspace`){this.handleBackspace(e);return}if(e.key===`Tab`&&!(document.querySelectorAll(`[data-blok-selected="true"]`).length>1)){if(e.preventDefault(),e.shiftKey){this.handleOutdent();return}this.handleIndent()}}async handleEnter(){var e=this;await qe({api:e.api,blockId:e.blockId,data:e._data,element:e._element,getContentElement:e.getContentElement.bind(e),syncContentFromDOM:e.syncContentFromDOM.bind(e),getDepth:e.getDepth.bind(e)},e.depthValidator)}async handleBackspace(e){var t=this;await Ye({api:t.api,blockId:t.blockId,data:t._data,element:t._element,getContentElement:t.getContentElement.bind(t),syncContentFromDOM:t.syncContentFromDOM.bind(t),getDepth:t.getDepth.bind(t)},e)}async handleIndent(){var e=this;await Xe({api:e.api,blockId:e.blockId,data:e._data,element:e._element,getContentElement:e.getContentElement.bind(e),syncContentFromDOM:e.syncContentFromDOM.bind(e),getDepth:e.getDepth.bind(e)},e.depthValidator)}async handleOutdent(){var e=this;await Qe({api:e.api,blockId:e.blockId,data:e._data,element:e._element,getContentElement:e.getContentElement.bind(e),syncContentFromDOM:e.syncContentFromDOM.bind(e),getDepth:e.getDepth.bind(e)},e.depthValidator)}syncContentFromDOM(){var e;let t=this.getContentElement();if(t&&(this._data.text=t.innerHTML),this._data.style!==`checklist`)return;let n=(e=this._element)==null?void 0:e.querySelector(`input[type="checkbox"]`);n instanceof HTMLInputElement&&(this._data.checked=n.checked)}getContentElement(){return Pe(this._element,this._data.style)}renderSettings(){return _e(this.availableStyles,this._data.style,this.api.i18n.t,e=>this.setStyle(e))}setStyle(e){let t=this._data.style;if(this._data.style=e,this.rerender(),t!==e){var n;(n=this.markerManager)==null||n.scheduleUpdateAll()}}rerender(){var e,t,n;let r=this.blockId?(e=this.api.blocks.getBlockIndex(this.blockId))==null?this.api.blocks.getCurrentBlockIndex():e:this.api.blocks.getCurrentBlockIndex(),i=(t=this._data.depth)==null?0:t,a=pe({data:this._data,readOnly:this.readOnly,placeholder:this.placeholder,itemColor:this.itemColor,itemSize:this.itemSize,markerDepth:this.markerCalculator.getVisualDepth(r,i),element:this._element,setupItemPlaceholder:this.setupItemPlaceholder.bind(this),onCheckboxChange:(e,t)=>{this._data.checked=e,t instanceof HTMLElement&&(t.classList.toggle(`line-through`,e),t.classList.toggle(`opacity-60`,e))},keydownHandler:this.readOnly||(n=this.boundHandleKeyDown)==null?void 0:n});a&&(this._element=a,this.updateMarkersAfterPositionChange())}validate(e){return typeof e.text==`string`}save(){return me(this._data,this._element,this.getContentElement.bind(this))}setData(e){let t=he(this._data,e,this._element,this.getContentElement.bind(this),{adjustDepthTo:this.adjustDepthTo.bind(this),updateMarkerForDepth:this.updateMarkerForDepth.bind(this),updateCheckboxState:this.updateCheckboxState.bind(this)});return this._data=t.newData,t.inPlace}merge(e){ge({data:this._data,element:this._element,getContentElement:this.getContentElement.bind(this),parseHTML:Ce},e)}static get conversionConfig(){return mt()}static get sanitize(){return ft()}static get pasteConfig(){return pt()}onPaste(e){let t=e.detail;if(!(`data`in t))return;let n=t.data;if(!at(n))return;let{text:r,checked:i}=ut(n),a=dt(n);this._data={text:r,style:lt(n,this._data.style),checked:i,depth:a},this.rerender()}static get isReadOnlySupported(){return!0}getContentOffset(e){return be(e)}static get toolbox(){return gt()}},vt=`data-blok-table-add-row`,yt=`data-blok-table-add-col`,bt=150,xt=5,St=40,Ct=[`flex`,`items-center`,`justify-center`,`transition-opacity`,`duration-150`],wt=[`flex`,`items-center`,`justify-center`,`border`,`border-gray-300`,`rounded-sm`,`group-hover/add:bg-gray-50`],Tt=`12`,Et=class{constructor(e){this.rowHideTimeout=null,this.colHideTimeout=null,this.rowVisible=!1,this.colVisible=!1,this.interactive=!0,this.dragState=null,this.scrollContainer=null,this.boundScrollHandler=null,this.scrollContainerResizeObserver=null,this.wrapper=e.wrapper,this.grid=e.grid,this.i18n=e.i18n,this.boundAddRowClick=e.onAddRow,this.boundAddColClick=e.onAddColumn,this.onDragStart=e.onDragStart,this.onDragAddRow=e.onDragAddRow,this.onDragRemoveRow=e.onDragRemoveRow,this.onDragAddCol=e.onDragAddCol,this.onDragRemoveCol=e.onDragRemoveCol,this.onDragEnd=e.onDragEnd,this.getTableSize=e.getTableSize,this.getNewColumnWidth=e.getNewColumnWidth,this.boundMouseMove=this.handleMouseMove.bind(this),this.boundDocumentMouseMove=this.handleDocumentMouseMove.bind(this),this.boundMouseLeave=this.handleMouseLeave.bind(this),this.boundPointerMove=this.handlePointerMove.bind(this),this.boundPointerUp=this.handlePointerUp.bind(this),this.boundPointerCancel=this.handlePointerCancel.bind(this),this.boundRowPointerDown=e=>this.handlePointerDown(`row`,e),this.boundColPointerDown=e=>this.handlePointerDown(`col`,e),this.addRowBtn=this.createAddRowButton(),this.addColBtn=this.createAddColumnButton(),this.wrapper.appendChild(this.addRowBtn),this.wrapper.appendChild(this.addColBtn),this.syncRowButtonWidth(),this.wrapper.addEventListener(`mousemove`,this.boundMouseMove),this.wrapper.addEventListener(`mouseleave`,this.boundMouseLeave),document.addEventListener(`mousemove`,this.boundDocumentMouseMove),this.addRowBtn.addEventListener(`pointerdown`,this.boundRowPointerDown),this.addColBtn.addEventListener(`pointerdown`,this.boundColPointerDown)}computeVisibleWidth(e,t,n){if(!t||n===null)return e;let r=this.wrapper.getBoundingClientRect();if(r.width>0){let e=this.grid.getBoundingClientRect(),t=n.getBoundingClientRect();return Math.min(e.right,t.right)-r.left}return n.clientWidth>0?Math.min(e,n.clientWidth):e}syncRowButtonWidth(){let e=this.grid.style.width;if(e&&e.endsWith(`px`)){let t=parseFloat(e),n=this.grid.parentElement,r=n!==null&&n!==this.wrapper,i=this.computeVisibleWidth(t,r,n);this.addRowBtn.style.width=`${i}px`,this.addRowBtn.style.right=``,this.addRowBtn.style.left=`0px`,this.addRowBtn.style.transform=``,this.addColBtn.style.left=`${i+4}px`,this.addColBtn.style.right=``}else{this.addRowBtn.style.width=``,this.addRowBtn.style.left=`0px`,this.addRowBtn.style.transform=``;let e=parseFloat(getComputedStyle(this.wrapper).paddingRight)||0;this.addRowBtn.style.right=`${e}px`,this.addColBtn.style.left=``,this.addColBtn.style.right=`${e-36}px`}let t=this.grid.getBoundingClientRect(),n=this.wrapper.getBoundingClientRect(),r=t.height;if(r>0){this.addColBtn.style.height=`${r}px`,this.addColBtn.style.bottom=``;let e=t.bottom-n.top;this.addRowBtn.style.top=`${e+4}px`,this.addRowBtn.style.bottom=``}else this.addColBtn.style.height=``,this.addColBtn.style.bottom=`0px`,this.addRowBtn.style.top=``,this.addRowBtn.style.bottom=`-36px`}setDisplay(e){let t=e?``:`none`;this.addRowBtn.style.display=t,this.addColBtn.style.display=t}setInteractive(e){if(this.interactive=e,!e){this.addRowBtn.style.pointerEvents=`none`,this.addColBtn.style.pointerEvents=`none`;return}this.addRowBtn.style.pointerEvents=this.rowVisible?``:`none`,this.addColBtn.style.pointerEvents=this.colVisible?``:`none`}attachScrollContainer(e){var t;this.scrollContainer&&this.boundScrollHandler&&this.scrollContainer.removeEventListener(`scroll`,this.boundScrollHandler),(t=this.scrollContainerResizeObserver)==null||t.disconnect(),this.scrollContainer=e,this.boundScrollHandler=()=>{this.syncRowButtonWidth()},e.addEventListener(`scroll`,this.boundScrollHandler,{passive:!0}),this.scrollContainerResizeObserver=new ResizeObserver(()=>{this.syncRowButtonWidth()}),this.scrollContainerResizeObserver.observe(e)}destroy(){var e;if(this.scrollContainer&&this.boundScrollHandler&&(this.scrollContainer.removeEventListener(`scroll`,this.boundScrollHandler),this.scrollContainer=null,this.boundScrollHandler=null),(e=this.scrollContainerResizeObserver)==null||e.disconnect(),this.scrollContainerResizeObserver=null,this.wrapper.removeEventListener(`mousemove`,this.boundMouseMove),this.wrapper.removeEventListener(`mouseleave`,this.boundMouseLeave),document.removeEventListener(`mousemove`,this.boundDocumentMouseMove),this.addRowBtn.removeEventListener(`pointerdown`,this.boundRowPointerDown),this.addColBtn.removeEventListener(`pointerdown`,this.boundColPointerDown),this.dragState){let e=this.dragState.axis===`row`?this.addRowBtn:this.addColBtn;e.removeEventListener(`pointermove`,this.boundPointerMove),e.removeEventListener(`pointerup`,this.boundPointerUp),e.removeEventListener(`pointercancel`,this.boundPointerCancel),document.body.style.cursor=``,this.dragState=null}this.clearRowTimeout(),this.clearColTimeout(),this.addRowBtn.remove(),this.addColBtn.remove()}showDimensionTooltip(){if(!this.dragState)return;let e=this.getTableSize(),n=this.dragState.axis===`row`?this.addRowBtn:this.addColBtn,r=this.dragState.axis===`row`?{placement:`bottom`,marginTop:-16}:{placement:`bottom`};t.sr(n,`${e.cols}\u00D7${e.rows}`,r)}handlePointerDown(e,t){t.preventDefault();let n=e===`row`?this.addRowBtn:this.addColBtn;n.setPointerCapture(t.pointerId);let r=this.measureUnitSize(e);this.dragState={axis:e,startPos:e===`row`?t.clientY:t.clientX,unitSize:r,addedCount:0,pointerId:t.pointerId,didDrag:!1},n.addEventListener(`pointermove`,this.boundPointerMove),n.addEventListener(`pointerup`,this.boundPointerUp),n.addEventListener(`pointercancel`,this.boundPointerCancel)}handlePointerMove(e){if(!this.dragState)return;let{axis:t,startPos:n,unitSize:r}=this.dragState,i=(t===`row`?e.clientY:e.clientX)-n,a=Math.floor(i/r);for(;this.dragState.addedCount<a;)t===`row`?this.onDragAddRow():this.onDragAddCol(),this.dragState.addedCount++;for(;this.dragState.addedCount>a;)t===`row`?this.onDragRemoveRow():this.onDragRemoveCol(),this.dragState.addedCount--;if(Math.abs(i)>xt&&!this.dragState.didDrag){this.dragState.didDrag=!0,document.body.style.cursor=t===`row`?`row-resize`:`col-resize`,this.showDimensionTooltip(),this.onDragStart();return}this.dragState.didDrag&&this.showDimensionTooltip(),this.dragState.didDrag&&this.showDimensionTooltip()}handlePointerUp(e){if(!this.dragState)return;let{axis:n,pointerId:r,didDrag:i}=this.dragState,a=n===`row`?this.addRowBtn:this.addColBtn;if(a.releasePointerCapture(r),a.removeEventListener(`pointermove`,this.boundPointerMove),a.removeEventListener(`pointerup`,this.boundPointerUp),a.removeEventListener(`pointercancel`,this.boundPointerCancel),document.body.style.cursor=``,t.ar(),this.dragState=null,!i){(n===`row`?this.boundAddRowClick:this.boundAddColClick)();return}this.onDragEnd()}handlePointerCancel(e){if(!this.dragState)return;let{axis:n,didDrag:r}=this.dragState,i=n===`row`?this.addRowBtn:this.addColBtn;i.removeEventListener(`pointermove`,this.boundPointerMove),i.removeEventListener(`pointerup`,this.boundPointerUp),i.removeEventListener(`pointercancel`,this.boundPointerCancel),document.body.style.cursor=``,t.ar(),this.dragState=null,r&&this.onDragEnd()}measureUnitSize(e){if(e===`row`){let e=this.grid.querySelectorAll(`[data-blok-table-row]`),t=e[e.length-1];return(t==null?void 0:t.offsetHeight)||30}if(this.getNewColumnWidth)return this.getNewColumnWidth()||100;let t=this.grid.querySelector(`[data-blok-table-row]`);if(!t)return 100;let n=t.querySelectorAll(`[data-blok-table-cell]`),r=n[n.length-1];return(r==null?void 0:r.offsetWidth)||100}handleMouseMove(e){let t=this.grid.getBoundingClientRect(),n=this.grid.parentElement,r=n!==null&&n!==this.wrapper?Math.min(t.right,n.getBoundingClientRect().right):t.right,i=Math.abs(e.clientY-t.bottom),a=Math.abs(e.clientX-r);i<=St?this.showRow():this.scheduleHideRow(),a<=St?this.showCol():this.scheduleHideCol()}handleMouseLeave(){this.scheduleHideRow(),this.scheduleHideCol()}handleDocumentMouseMove(e){if(this.wrapper.contains(e.target))return;let t=this.grid.getBoundingClientRect(),n=St;e.clientX>=t.left-n&&e.clientX<=t.right+n&&e.clientY>=t.top-n&&e.clientY<=t.bottom+n?this.handleMouseMove(e):(this.scheduleHideRow(),this.scheduleHideCol())}showRow(){this.clearRowTimeout(),this.rowVisible||(this.addRowBtn.style.opacity=`1`,this.addRowBtn.style.pointerEvents=this.interactive?``:`none`,this.rowVisible=!0)}showCol(){this.clearColTimeout(),this.colVisible||(this.addColBtn.style.opacity=`1`,this.addColBtn.style.pointerEvents=this.interactive?``:`none`,this.colVisible=!0)}scheduleHideRow(){var e;!this.rowVisible||this.rowHideTimeout!==null||((e=this.dragState)==null?void 0:e.axis)===`row`||(this.rowHideTimeout=setTimeout(()=>{this.addRowBtn.style.opacity=`0`,this.addRowBtn.style.pointerEvents=`none`,this.rowVisible=!1,this.rowHideTimeout=null},bt))}scheduleHideCol(){var e;!this.colVisible||this.colHideTimeout!==null||((e=this.dragState)==null?void 0:e.axis)===`col`||(this.colHideTimeout=setTimeout(()=>{this.addColBtn.style.opacity=`0`,this.addColBtn.style.pointerEvents=`none`,this.colVisible=!1,this.colHideTimeout=null},bt))}clearRowTimeout(){this.rowHideTimeout!==null&&(clearTimeout(this.rowHideTimeout),this.rowHideTimeout=null)}clearColTimeout(){this.colHideTimeout!==null&&(clearTimeout(this.colHideTimeout),this.colHideTimeout=null)}createAddRowButton(){let e=document.createElement(`div`);e.className=r.n(Ct,`group/add`,`items-start`,`cursor-row-resize`),e.setAttribute(vt,``),e.setAttribute(`contenteditable`,`false`),e.style.opacity=`0`,e.style.pointerEvents=`none`,e.style.position=`absolute`,e.style.left=`0`,e.style.bottom=`-36px`,e.style.zIndex=`1`,e.style.height=`32px`;let n=document.createElement(`div`);return n.className=r.n(wt),n.style.width=`100%`,n.style.height=`16px`,this.appendIcon(n),e.appendChild(n),t.or(e,t.h([this.i18n.t(`tools.table.clickToAddRow`),this.i18n.t(`tools.table.dragToAddRemoveRows`)]),{placement:`bottom`,marginTop:-16}),e}createAddColumnButton(){let e=document.createElement(`div`);e.className=r.n(Ct,`group/add`,`justify-start`,`cursor-col-resize`),e.setAttribute(yt,``),e.setAttribute(`contenteditable`,`false`),e.style.opacity=`0`,e.style.pointerEvents=`none`,e.style.position=`absolute`,e.style.right=`-36px`,e.style.top=`0px`,e.style.bottom=`0px`,e.style.width=`32px`;let n=document.createElement(`div`);return n.className=r.n(wt),n.style.width=`16px`,n.style.height=`100%`,this.appendIcon(n),e.appendChild(n),t.or(e,t.h([this.i18n.t(`tools.table.clickToAddColumn`),this.i18n.t(`tools.table.dragToAddRemoveColumns`)]),{placement:`bottom`}),e}appendIcon(e){e.insertAdjacentHTML(`beforeend`,t.sn);let n=e.querySelector(`svg`);n&&(n.setAttribute(`width`,Tt),n.setAttribute(`height`,Tt),n.setAttribute(`viewBox`,`0 0 24 24`),n.classList.add(`text-gray-500`,`pointer-events-none`))}},I=`data-blok-table-row`,L=`data-blok-table-cell`,R=`data-blok-table-cell-row`,z=`data-blok-table-cell-col`,Dt=`1px solid var(--blok-table-border)`,Ot=[`py-1`,`px-2`,`min-h-[2em]`,`outline-hidden`,`leading-none`,`text-sm`,`cursor-text`],kt=e=>{let t=Math.round(100/e*100)/100;return Array.from({length:e},()=>t)},At=class{constructor(e){this.readOnly=e.readOnly}createGrid(e,t,n){let r=document.createElement(`table`);r.style.tableLayout=`fixed`,r.style.width=`100%`,r.style.borderCollapse=`separate`,r.style.borderSpacing=`0px`,r.style.borderTop=Dt,r.style.borderLeft=Dt;let i=n==null?kt(t):n,a=document.createElement(`colgroup`);i.forEach(e=>{a.appendChild(this.createCol(e))}),r.appendChild(a);let o=document.createElement(`tbody`);return Array.from({length:e}).forEach((e,n)=>{o.appendChild(this.createRow(t,n))}),r.appendChild(o),r}fillGrid(e,t){}createGridFromModel(e){var t;let n=document.createElement(`table`);n.style.tableLayout=`fixed`,n.style.width=`100%`,n.style.borderCollapse=`separate`,n.style.borderSpacing=`0px`,n.style.borderTop=Dt,n.style.borderLeft=Dt;let r=document.createElement(`colgroup`);((t=e.colWidths)==null?kt(e.cols):t).forEach(e=>r.appendChild(this.createCol(e))),n.appendChild(r);let i=document.createElement(`tbody`);return Array.from({length:e.rows}).forEach((t,n)=>{let r=document.createElement(`tr`);r.setAttribute(I,``),Array.from({length:e.cols}).forEach((t,i)=>{if(e.isSpannedCell(n,i))return;let a=this.createCell(n,i),o=e.getCellSpan(n,i);o.colspan>1&&(a.colSpan=o.colspan),o.rowspan>1&&(a.rowSpan=o.rowspan),r.appendChild(a)}),i.appendChild(r)}),n.appendChild(i),n}addRow(e,t){var n;let r=this.getColumnCount(e),i=this.createRow(r),a=(n=e.querySelector(`tbody`))==null?e:n,o=a.querySelectorAll(`[${I}]`);return t!==void 0&&t<o.length?a.insertBefore(i,o[t]):a.appendChild(i),this.reindexCoordinates(e),i}deleteRow(e,t){let n=e.querySelectorAll(`[${I}]`);t<n.length&&n[t].remove(),this.reindexCoordinates(e)}addColumn(e,t,n,r){let i=e.querySelector(`colgroup`),a=(i?Array.from(i.querySelectorAll(`col`)):[]).length,o=n!==void 0&&n.length===a,s=o||this.detectWidthUnit(e)===`px`;return o&&i&&this.applyWidthsToCols(i,n),s?this.addColumnPx(e,a,t,r):this.addColumnPercent(e,a,t),this.reindexCoordinates(e),!0}applyWidthsToCols(e,t){let n=Array.from(e.querySelectorAll(`col`));t.forEach((e,t)=>{t<n.length&&(n[t].style.width=`${e}px`)})}addColumnPx(e,t,n,r){let i=`${r==null?this.computeHalfAvgWidth(e,t):r}px`;this.insertColumn(e,n,i)}computeHalfAvgWidth(e,t){let n=e.querySelector(`colgroup`),r=(n?Array.from(n.querySelectorAll(`col`)):[]).reduce((e,t)=>e+(parseFloat(t.style.width)||0),0);return t>0?Math.round(r/t/2*100)/100:0}addColumnPercent(e,t,n){let r=1-.5/t,i=e.querySelector(`colgroup`);(i?Array.from(i.querySelectorAll(`col`)):[]).forEach(e=>{let n=e,i=parseFloat(n.style.width)||100/t,a=Math.round(i*r*100)/100;n.style.width=`${a}%`});let a=Math.round(100/t/2*100)/100;this.insertColumn(e,n,`${a}%`)}insertColumn(e,t,n){let r=e.querySelector(`colgroup`);if(r){let e=document.createElement(`col`);e.style.width=n;let i=r.querySelectorAll(`col`);t===void 0||t>=i.length?r.appendChild(e):r.insertBefore(e,i[t])}e.querySelectorAll(`[${I}]`).forEach(e=>{let n=e.querySelectorAll(`[${L}]`),r=t===void 0||t>=n.length,i=this.createCell();r?e.appendChild(i):e.insertBefore(i,n[t])})}deleteColumn(e,t){let n=e.querySelector(`colgroup`);if(n){let e=n.querySelectorAll(`col`);t<e.length&&e[t].remove()}e.querySelectorAll(`[${I}]`).forEach(e=>{let n=e.querySelectorAll(`[${L}]`);t>=n.length||n[t].remove()}),this.reindexCoordinates(e)}moveRow(e,t,n){var r;if(t===n)return;let i=(r=e.querySelector(`tbody`))==null?e:r,a=Array.from(i.querySelectorAll(`[${I}]`));if(t>=a.length||n>=a.length)return;let o=a[t];o.remove();let s=Array.from(i.querySelectorAll(`[${I}]`));n>=s.length?i.appendChild(o):i.insertBefore(o,s[n]),this.reindexCoordinates(e)}moveColumn(e,t,n){t!==n&&(this.reorderColElement(e,t,n),e.querySelectorAll(`[${I}]`).forEach(e=>{let r=Array.from(e.querySelectorAll(`[${L}]`));if(t>=r.length||n>=r.length)return;let i=r[t];i.remove();let a=Array.from(e.querySelectorAll(`[${L}]`));n>=a.length?e.appendChild(i):e.insertBefore(i,a[n])}),this.reindexCoordinates(e))}reindexCoordinates(e){let t=Array.from(e.querySelectorAll(`[${I}]`)),n=new Map;t.forEach((e,t)=>{var r;let i=Array.from(e.querySelectorAll(`[${L}]`)),a=(r=n.get(t))==null?new Set:r;i.reduce((e,r)=>{let i=r,o=e=>a.has(e)?o(e+1):e,s=o(e);r.setAttribute(R,String(t)),r.setAttribute(z,String(s));let c=i.colSpan||1,l=i.rowSpan||1;return l>1&&this.blockRowspanCols(n,t,s,l,c),s+c},0),n.delete(t)})}blockRowspanCols(e,t,n,r,i){Array.from({length:r-1},(e,t)=>t+1).forEach(r=>{let a=t+r;e.has(a)||e.set(a,new Set);let o=e.get(a);Array.from({length:i},(e,t)=>t).forEach(e=>{o.add(n+e)})})}getRowCount(e){return e.querySelectorAll(`[${I}]`).length}getColumnCount(e){let t=e.querySelector(`colgroup`);if(t)return t.querySelectorAll(`col`).length;let n=e.querySelector(`[${I}]`);return n?n.querySelectorAll(`[${L}]`).length:0}getCell(e,t,n){let r=e.querySelector(`[${R}="${t}"][${z}="${n}"]`);if(r)return r;let i=e.querySelectorAll(`[${I}]`);if(t>=i.length)return null;let a=i[t].querySelectorAll(`[${L}]`);return n>=a.length?null:a[n]}getColWidths(e){let t=e.querySelector(`colgroup`);if(!t)return[];let n=t.querySelectorAll(`col`),r=[];return n.forEach(e=>{let t=parseFloat(e.style.width);r.push(isNaN(t)?0:t)}),r}getColgroup(e){return e.querySelector(`colgroup`)}applyColWidths(e,t){let n=e.querySelector(`colgroup`);if(!n)return;let r=Array.from(n.querySelectorAll(`col`));t.forEach((e,t)=>{t<r.length&&(r[t].style.width=`${e}px`)})}reorderColElement(e,t,n){let r=e.querySelector(`colgroup`);if(!r)return;let i=Array.from(r.querySelectorAll(`col`));if(t>=i.length||n>=i.length)return;let a=i[t];a.remove();let o=Array.from(r.querySelectorAll(`col`));n>=o.length?r.appendChild(a):r.insertBefore(a,o[n])}detectWidthUnit(e){let t=e.querySelector(`colgroup`);if(!t)return`%`;let n=t.querySelector(`col`);return n&&n.style.width.endsWith(`px`)?`px`:`%`}createCol(e){let t=document.createElement(`col`);return t.style.width=typeof e==`string`?e:`${e}%`,t}createRow(e,t){let n=document.createElement(`tr`);return n.setAttribute(I,``),Array.from({length:e}).forEach((e,r)=>{n.appendChild(this.createCell(t,t===void 0?void 0:r))}),n}createCell(e,n){let i=document.createElement(`td`);i.className=r.n(Ot),i.style.borderRight=Dt,i.style.borderBottom=Dt,i.style.overflow=`hidden`,i.style.overflowWrap=`break-word`,i.style.height=`0`,i.setAttribute(L,``),e!==void 0&&n!==void 0&&(i.setAttribute(R,String(e)),i.setAttribute(z,String(n)));let a=document.createElement(`div`);return a.setAttribute(V,``),a.setAttribute(t.hi.nestedBlocks,``),a.style.display=`flex`,a.style.flexDirection=`column`,a.style.minHeight=`100%`,i.appendChild(a),i}},B=e=>typeof e==`object`&&!!e&&`blocks`in e,V=`data-blok-table-cell-blocks`,jt=class{constructor(e){var t;this._activeCellWithBlocks=null,this.cellsPendingCheck=new Set,this.pendingCheckScheduled=!1,this.removedBlockCells=new Map,this.deferredEvents=[],this.isExitingTable=!1,this.handleBlockMutation=e=>{if(this.isStructuralOpActive()&&!this.api.blocks.isSyncingFromYjs){this.deferredEvents.push(e);return}if(this.isExitingTable||!this.isBlockMutationEvent(e))return;let{type:t,detail:n}=e.event;if(t===`block-removed`){this.handleBlockRemoved(n);return}if(t===`block-moved`){this.handleBlockMoved(n);return}if(t!==`block-added`||n.target.id===this.tableBlockId)return;let r=this.model.findCellForBlock(n.target.id);if(r){let e=this.gridElement.querySelector(`[${R}="${r.row}"][${z}="${r.col}"]`);if(e){this.claimBlockForCell(e,n.target.id),this.cellsPendingCheck.delete(e);return}}let i=n.index;if(i===void 0)return;let a=this.findRemovedEntryForIndex(i);if(a&&this.isAdjacentToThisTable(i)){this.claimBlockForCell(a.cell,n.target.id),this.syncBlockToModel(a.cell,n.target.id),this.cellsPendingCheck.delete(a.cell);return}let o=n.target.holder,s=o.closest(`[${V}]`);s&&this.stripPlaceholders(s);let c=s&&!this.model.findCellForBlock(n.target.id)?s.closest(`[${L}]`):null;if(c&&this.syncBlockToModel(c,n.target.id),s)return;if(!this.gridElement.contains(o)){let e=this.api.blocks.getBlockIndex(this.tableBlockId),t=e===void 0?null:this.api.blocks.getBlockByIndex(e);if(t&&!t.holder.contains(o))return;let r=this.api.blocks.getCurrentBlockIndex(),a=r>=0?this.api.blocks.getBlockByIndex(r):null;if(!(a!=null&&this.getOwnedCellForBlock(a.id)!==null))return;let s=this.findCellForNewBlock(i);s&&(this.claimBlockForCell(s,n.target.id),this.syncBlockToModel(s,n.target.id),this.cellsPendingCheck.delete(s));return}let l=this.findCellForNewBlock(i);l&&(this.claimBlockForCell(l,n.target.id),this.syncBlockToModel(l,n.target.id),this.cellsPendingCheck.delete(l))},this.handleCellBlankSpaceClick=e=>{let t=e.target;if(!t)return;let n=t.hasAttribute(L),r=t.hasAttribute(V);if(!n&&!r)return;let i=n?t:t.closest(`[${L}]`);if(!i)return;let a=n?i.querySelector(`[${V}]`):t;if(!a)return;let o=a.querySelectorAll(`[data-blok-id]`),s=o[o.length-1];if(!s)return;let c=s.getAttribute(`data-blok-id`);c&&this.api.caret.setToBlock(c,`end`)},this.api=e.api,this.gridElement=e.gridElement,this.tableBlockId=e.tableBlockId,this.model=e.model,this.onNavigateToCell=e.onNavigateToCell,this.isStructuralOpActive=(t=e.isStructuralOpActive)==null?(()=>!1):t,this.api.events.on(`block changed`,this.handleBlockMutation),this.gridElement.addEventListener(`click`,this.handleCellBlankSpaceClick)}get activeCellWithBlocks(){return this._activeCellWithBlocks}setActiveCellWithBlocks(e){this._activeCellWithBlocks=e}clearActiveCellWithBlocks(){this._activeCellWithBlocks=null}handleKeyDown(e,t){if(e.key===`Tab`&&!e.shiftKey){e.preventDefault(),this.handleTabNavigation(t);return}if(e.key===`Tab`&&e.shiftKey){e.preventDefault(),this.handleShiftTabNavigation(t);return}e.key===`ArrowDown`&&!e.defaultPrevented&&t.row===this.getRowCount()-1&&(e.preventDefault(),this.exitTableForward())}handleTabNavigation(e){let t=e.col+1;if(t<this.getColumnCount()){this.navigateToCell({row:e.row,col:t});return}let n=e.row+1;if(n<this.getRowCount()){this.navigateToCell({row:n,col:0});return}this.exitTableForward()}handleShiftTabNavigation(e){let t=e.col-1;if(t>=0){this.navigateToCell({row:e.row,col:t},!0);return}let n=e.row-1;if(n>=0){this.navigateToCell({row:n,col:this.getColumnCount()-1},!0);return}this.exitTableBackward()}exitTableForward(){let e=this.api.blocks.getBlockIndex(this.tableBlockId);if(e===void 0)return;let t=this.findFirstBlockAfterTable(e);if(t!==null){this.api.caret.setToBlock(t.id,`start`);return}this.isExitingTable=!0;try{let t=this.api.blocks.getBlocksCount(),n=this.api.blocks.insert(void 0,{},{},t,!0),r=this.gridElement.contains(n.holder)?this.api.blocks.getBlockByIndex(e):null;r&&r.holder.after(n.holder),this.api.caret.setToBlock(n.id,`start`)}finally{this.isExitingTable=!1}}exitTableBackward(){let e=this.api.blocks.getBlockIndex(this.tableBlockId);if(e===void 0||e===0)return;let t=this.api.blocks.getBlockByIndex(e-1);t&&this.api.caret.setToBlock(t.id,`end`)}findFirstBlockAfterTable(e){var t;let n=this.api.blocks.getBlocksCount();return(t=Array.from({length:n-e-1},(t,n)=>this.api.blocks.getBlockByIndex(e+1+n)).find(e=>e!=null&&!this.gridElement.contains(e.holder)))==null?null:t}navigateToCell(e,t=!1){var n;this.clearActiveCellWithBlocks();let r=this.getCell(e.row,e.col);if(!r)return;let i=r.querySelector(`[${V}]`);if(!i)return;let a=i.querySelectorAll(`[contenteditable="true"]`);a.length!==0&&((t?a[a.length-1]:a[0]).focus(),(n=this.onNavigateToCell)==null||n.call(this,e))}getRowCount(){return this.gridElement.querySelectorAll(`[data-blok-table-row]`).length}getColumnCount(){var e;let t=this.gridElement.querySelector(`colgroup`);if(t)return t.querySelectorAll(`col`).length;let n=this.gridElement.querySelector(`[data-blok-table-row]`);return(e=n==null?void 0:n.querySelectorAll(`[data-blok-table-cell]`).length)==null?0:e}getCell(e,t){var n;let r=this.gridElement.querySelectorAll(`[data-blok-table-row]`)[e];return r?(n=r.querySelector(`[data-blok-table-cell-col="${t}"]`))==null?null:n:null}initializeCells(e){let t=this.gridElement.querySelectorAll(`[${I}]`),r=[];return e.forEach((e,i)=>{let a=t[i];if(!a)return;let o=[];e.forEach((e,t)=>{let r=a.querySelector(`[${z}="${t}"]`);if(!r)return;let i=r.querySelector(`[${V}]`);if(!i)return;let s=B(e)&&e.blocks.length>0?[...e.blocks]:null,{mountedIds:c,replacements:l}=s?this.mountBlocksInCell(i,s):{mountedIds:[],replacements:new Map},u={};if(B(e)&&(e.color!==void 0&&(u.color=e.color),e.textColor!==void 0&&(u.textColor=e.textColor)),c.length>0){let e=s==null?c:s,t=l.size>0?e.map(e=>{var t;return(t=l.get(e))==null?e:t}):e;o.push(n.t({blocks:t},u))}else{var d;let t=typeof e==`string`?e:(d=e.text)==null?``:d,r=t.split(/<br\s*\/?>/i).map(e=>e.trim()).filter(Boolean),a=r.length>0?r:[t],c=[];for(let e of a){let t=this.api.blocks.insert(`paragraph`,{text:e},{},this.api.blocks.getBlocksCount(),!1);i.appendChild(t.holder),this.api.blocks.setBlockParent(t.id,this.tableBlockId),c.push(t.id)}o.push(n.t({blocks:s===null?c:[...s,...c]},u))}this.stripPlaceholders(i)}),r.push(o)}),r}reclaimReferencedBlocks(){this.model.snapshot().content.forEach((e,t)=>{e.forEach((e,n)=>{if(!B(e)||e.blocks.length===0)return;let r=this.gridElement.querySelector(`[${R}="${t}"][${z}="${n}"]`);if(!r)return;let i=r.querySelector(`[${V}]`);if(i)for(let t of e.blocks){let e=this.api.blocks.getBlockIndex,n=this.api.blocks.getBlockByIndex;if(typeof e!=`function`||typeof n!=`function`)return;let a=e(t);if(a===void 0)continue;let o=n(a);o&&(i.contains(o.holder)||this.claimBlockForCell(r,t))}})})}stripPlaceholders(e){e.querySelectorAll(`[data-blok-placeholder-active]`).forEach(e=>{e.removeAttribute(`data-blok-placeholder-active`)}),e.querySelectorAll(`[data-placeholder]`).forEach(e=>{e.removeAttribute(`data-placeholder`)})}mountBlocksInCell(e,n){let r=[],i=new Map;for(let a of n){let n=this.api.blocks.getBlockIndex(a);if(n===void 0)continue;let o=this.api.blocks.getBlockByIndex(n);if(!o)continue;let s=o.parentId!=null&&o.parentId!==``&&o.parentId!==this.tableBlockId;if(o.holder.closest(`[${t.hi.nestedBlocks}]`)||s){let t=this.api.blocks.insert(o.name,o.preservedData,{},this.api.blocks.getBlocksCount(),!1);e.appendChild(t.holder),this.api.blocks.setBlockParent(t.id,this.tableBlockId),r.push(t.id),i.set(a,t.id);continue}e.appendChild(o.holder),this.api.blocks.setBlockParent(a,this.tableBlockId),r.push(a)}return{mountedIds:r,replacements:i}}claimBlockForCell(e,n){var r,i;let a=e.querySelector(`[${V}]`);if(!a)return;let o=this.api.blocks.getBlockIndex(n);if(o===void 0)return;let s=this.api.blocks.getBlockByIndex(o);if(!s||s.holder.contains(a))return;let c=s.parentId!=null&&s.parentId!==``&&s.parentId!==this.tableBlockId;if(s.holder.closest(`[${t.hi.nestedBlocks}]`)||c)return;let l=this.api.blocks.getBlocksCount(),u=(r=(i=Array.from({length:l-o-1},(e,t)=>this.api.blocks.getBlockByIndex(o+1+t)).find(e=>(e==null?void 0:e.holder.parentElement)===a))==null?void 0:i.holder)==null?null:r;a.insertBefore(s.holder,u),this.api.blocks.setBlockParent(n,this.tableBlockId),this.stripPlaceholders(a)}findCellForNewBlock(e){return this.findCellForAdjacentBlock(e-1)||this.findCellForAdjacentBlock(e+1)}findCellForAdjacentBlock(e){if(e<0||e>=this.api.blocks.getBlocksCount())return null;let t=this.api.blocks.getBlockByIndex(e),n=t==null?void 0:t.holder.closest(`[${L}]`);return n&&this.gridElement.contains(n)?n:null}ensureCellHasBlock(e){var t,n;let r=e.querySelector(`[${V}]`);r&&r.querySelector(`[data-blok-id]`)===null&&((t=(n=this.api.blocks).transactWithoutCapture)==null||t.call(n,()=>{let t=this.api.blocks.insert(`paragraph`,{text:``},{},this.api.blocks.getBlocksCount(),!0);r.appendChild(t.holder),this.api.blocks.setBlockParent(t.id,this.tableBlockId),this.syncBlockToModel(e,t.id),this.stripPlaceholders(r)}))}handleBlockRemoved(e){this.recordRemovedBlockCell(e);let t=e.target.id,n=this.model.findCellForBlock(t);if(!n){this.schedulePendingCellCheck();return}this.model.removeBlockFromCell(n.row,n.col,t);let r=this.getCell(n.row,n.col);r&&this.cellsPendingCheck.add(r),this.schedulePendingCellCheck()}handleBlockMoved(e){let t=e.target.id,n=this.model.findCellForBlock(t);n&&(this.gridElement.contains(e.target.holder)||this.model.removeBlockFromCell(n.row,n.col,t))}syncBlockToModel(e,t){let n=this.getCellPosition(e);n&&this.model.addBlockToCell(n.row,n.col,t)}getCellPosition(e){let t=e.closest(`[${I}]`);if(!t)return null;let n=Array.from(this.gridElement.querySelectorAll(`[${I}]`)).indexOf(t);if(n<0)return null;let r=Array.from(t.querySelectorAll(`[${L}]`)).indexOf(e);return r<0?null:{row:n,col:r}}recordRemovedBlockCell(e){if(e.index===void 0)return;let t=e.target.holder.closest(`[${L}]`);t&&this.gridElement.contains(t)&&this.removedBlockCells.set(e.target.id,{cell:t,index:e.index})}findRemovedEntryForIndex(e){for(let[t,n]of this.removedBlockCells)if(n.index===e)return this.removedBlockCells.delete(t),n;return null}getOwnedCellForBlock(e){let t=this.model.findCellForBlock(e);if(!t)return null;let n=this.getCell(t.row,t.col);return n&&this.gridElement.contains(n)?n:null}isAdjacentToThisTable(e){let t=this.api.blocks.getBlocksCount();for(let n of[-1,1]){let r=e+n;if(r<0||r>=t)continue;let i=this.api.blocks.getBlockByIndex(r);if(i&&this.getOwnedCellForBlock(i.id))return!0}if(!this.isTableBlockAtPrevIndex(e))return!1;let n=e+1;if(n>=t)return!0;let r=this.api.blocks.getBlockByIndex(n);return r?this.getOwnedCellForBlock(r.id)!==null:!0}isTableBlockAtPrevIndex(e){let t=e-1;if(t<0)return!1;let n=this.api.blocks.getBlockByIndex(t);return(n==null?void 0:n.id)===this.tableBlockId}schedulePendingCellCheck(){this.pendingCheckScheduled||(this.pendingCheckScheduled=!0,queueMicrotask(()=>{if(this.pendingCheckScheduled=!1,!this.api.blocks.isSyncingFromYjs)for(let e of this.cellsPendingCheck)this.ensureCellHasBlock(e);this.cellsPendingCheck.clear(),this.removedBlockCells.clear()}))}isBlockMutationEvent(e){return typeof e==`object`&&!!e&&`event`in e&&typeof e.event==`object`&&e.event!==null}getBlockIdsFromCells(e){let t=[];return Array.from(e).forEach(e=>{let n=e.querySelector(`[${V}]`);n&&n.querySelectorAll(`[data-blok-id]`).forEach(e=>{let n=e.getAttribute(`data-blok-id`);n&&t.push(n)})}),t}deleteBlocks(e){let t=e.map(e=>this.api.blocks.getBlockIndex(e)).filter(e=>e!==void 0).sort((e,t)=>t-e),n=window.scrollY,r=t.map(e=>this.api.blocks.delete(e));Promise.all(r).then(()=>{window.scrollY!==n&&window.scrollTo(0,n)})}deleteAllBlocks(){let e=this.gridElement.querySelectorAll(`[${L}]`),t=this.getBlockIdsFromCells(e);this.deleteBlocks(t)}destroy(){this.gridElement.removeEventListener(`click`,this.handleCellBlankSpaceClick),this.api.events.off(`block changed`,this.handleBlockMutation),this._activeCellWithBlocks=null,this.cellsPendingCheck.clear(),this.removedBlockCells.clear(),this.deferredEvents.length=0}flushDeferredEvents(){let e=[...this.deferredEvents];this.deferredEvents.length=0;for(let t of e)this.handleBlockMutation(t)}discardDeferredEvents(){this.deferredEvents.length=0}};function Mt(){var e,n;let r=document.documentElement.getAttribute(`data-blok-theme`);return r===`dark`?t.Un:r===`light`?t.Hn:typeof window<`u`&&(e=(n=window).matchMedia)!=null&&e.call(n,`(prefers-color-scheme: dark)`).matches?t.Un:t.Hn}function Nt(e,n){if(e===n)return!0;let r=t.zn(e),i=t.zn(n);return r===null||i===null?!1:r[0]===i[0]&&r[1]===i[1]&&r[2]===i[2]}var Pt=`var(--blok-swatch-neutral-bg)`;function Ft(e){let{i18n:n,modes:i,testIdPrefix:a,onColorSelect:o}=e,s={activeColors:Object.fromEntries(i.map(e=>[e.key,null]))},c=document.createElement(`div`);c.setAttribute(`data-blok-testid`,`${a}-picker`),c.className=`flex flex-col gap-3 p-2`;let l=[];i.forEach(e=>{let t=document.createElement(`div`);t.setAttribute(`data-blok-testid`,`${a}-section-${e.key}`),t.className=`flex flex-col gap-1`;let r=document.createElement(`div`);r.className=`text-xs font-medium text-text-primary/60 px-0.5`,r.textContent=n.t(e.labelKey);let i=document.createElement(`div`);i.className=`grid gap-1`,i.style.gridTemplateColumns=`repeat(5, 2.25rem)`,l.push(i),t.appendChild(r),t.appendChild(i),c.appendChild(t)});let u=e=>{let c=l[e],u=i[e],d=Mt();c.innerHTML=``;let f=s.activeColors[u.key],p=document.createElement(`button`),m=f===null;p.setAttribute(`data-blok-testid`,`${a}-swatch-${u.key}-default`),p.className=r.n(`w-9 h-9 rounded-md cursor-pointer border-none outline-hidden`,`flex items-center justify-center text-sm font-semibold`,`transition-[box-shadow,transform] ring-inset hover:ring-2 hover:ring-swatch-ring-hover active:scale-90`,m&&`ring-2 ring-swatch-ring-hover`),p.textContent=u.presetField===`text`?`A`:``,u.presetField===`text`&&(p.style.color=`var(--blok-text-primary)`),p.style.backgroundColor=Pt,p.addEventListener(`click`,()=>{o(null,u.key)});let h=n.t(`tools.colorPicker.defaultSwatchLabel`).replace(`{default}`,n.t(`tools.marker.default`)).replace(`{mode}`,n.t(u.labelKey).toLowerCase());t.or(p,h.charAt(0).toUpperCase()+h.slice(1),{placement:`top`}),c.appendChild(p);for(let e of d){let i=document.createElement(`button`),s=u.presetField===`text`?e.text:e.bg,l=f!==null&&Nt(s,f);i.setAttribute(`data-blok-testid`,`${a}-swatch-${u.key}-${e.name}`),i.className=r.n(`w-9 h-9 rounded-md cursor-pointer border-none outline-hidden`,`flex items-center justify-center text-sm font-semibold`,`transition-[box-shadow,transform] ring-inset hover:ring-2 hover:ring-swatch-ring-hover active:scale-90`,l&&`ring-2 ring-swatch-ring-hover`),i.textContent=u.presetField===`text`?`A`:``,u.presetField===`text`?(i.style.color=e.text,i.style.backgroundColor=Pt):(i.style.color=d===t.Un?e.text:`#37352f`,i.style.backgroundColor=e.bg),i.addEventListener(`click`,()=>{o(s,u.key)});let p=n.t(`tools.colorPicker.colorSwatchLabel`).replace(`{color}`,n.t(`tools.colorPicker.color.`+e.name)).replace(`{mode}`,n.t(u.labelKey).toLowerCase());t.or(i,p.charAt(0).toUpperCase()+p.slice(1),{placement:`top`}),c.appendChild(i)}},d=()=>{i.forEach((e,t)=>u(t))};return d(),{element:c,setActiveColor:(e,t)=>{let n=i.findIndex(e=>e.key===t);n!==-1&&(s.activeColors[t]=e,u(n))},reset:()=>{for(let e of i)s.activeColors[e.key]=null;d()}}}var It=e=>{let t=Ft({i18n:e.i18n,testIdPrefix:`cell-color`,modes:[{key:`textColor`,labelKey:`tools.marker.textColor`,presetField:`text`},{key:`backgroundColor`,labelKey:`tools.marker.background`,presetField:`bg`}],onColorSelect:(n,r)=>{t.setActiveColor(n,r),e.onColorSelect(n,r)}});return{element:t.element}},Lt=[`top-left`,`top-center`,`top-right`,`middle-left`,`middle-center`,`middle-right`,`bottom-left`,`bottom-center`,`bottom-right`],Rt={"top-left":`tools.table.placementTopLeft`,"top-center":`tools.table.placementTopCenter`,"top-right":`tools.table.placementTopRight`,"middle-left":`tools.table.placementMiddleLeft`,"middle-center":`tools.table.placementMiddleCenter`,"middle-right":`tools.table.placementMiddleRight`,"bottom-left":`tools.table.placementBottomLeft`,"bottom-center":`tools.table.placementBottomCenter`,"bottom-right":`tools.table.placementBottomRight`},zt={top:`flex-start`,middle:`center`,bottom:`flex-end`},Bt={left:`flex-start`,center:`center`,right:`flex-end`},Vt=e=>{var t;let n=(t=e.currentPlacement)==null?`top-left`:t,r=document.createElement(`div`);r.style.padding=`8px`;let i=document.createElement(`div`);i.style.display=`grid`,i.style.gridTemplateColumns=`repeat(3, 1fr)`,i.style.gap=`3px`;let a=document.createElement(`div`);a.style.textAlign=`center`,a.style.fontSize=`11px`,a.style.marginTop=`6px`,a.style.color=`var(--blok-text-secondary, #707684)`,a.textContent=e.i18n.t(Rt[n]);for(let t of Lt){let[r,o]=t.split(`-`),s=document.createElement(`div`);s.setAttribute(`data-placement`,t),s.style.width=`32px`,s.style.height=`26px`,s.style.borderRadius=`3px`,s.style.display=`flex`,s.style.flexDirection=`column`,s.style.alignItems=Bt[o],s.style.justifyContent=zt[r],s.style.padding=`3px`,s.style.cursor=`pointer`,s.style.gap=`1px`,t===n?(s.setAttribute(`data-active`,`true`),s.style.outline=`2px solid var(--blok-color-primary, #388AE5)`,s.style.outlineOffset=`-2px`,s.style.backgroundColor=`var(--blok-item-focus-bg, rgba(35, 131, 226, 0.14))`):s.style.backgroundColor=`var(--blok-bg-light, #eff2f5)`;let c=document.createElement(`div`);c.style.width=`14px`,c.style.height=`2px`,c.style.borderRadius=`1px`,c.style.backgroundColor=`currentColor`,c.style.opacity=`0.6`;let l=document.createElement(`div`);l.style.width=`9px`,l.style.height=`2px`,l.style.borderRadius=`1px`,l.style.backgroundColor=`currentColor`,l.style.opacity=`0.3`,s.appendChild(c),s.appendChild(l),s.addEventListener(`click`,()=>{i.querySelectorAll(`[data-placement]`).forEach(e=>{let t=e;t.removeAttribute(`data-active`),t.style.outline=``,t.style.outlineOffset=``,t.style.backgroundColor=`var(--blok-bg-tertiary, #f0f0f0)`}),s.setAttribute(`data-active`,`true`),s.style.outline=`2px solid var(--blok-color-primary, #388AE5)`,s.style.outlineOffset=`-2px`,s.style.backgroundColor=`var(--blok-item-focus-bg, rgba(35, 131, 226, 0.14))`,a.textContent=e.i18n.t(Rt[t]),e.onPlacementSelect(t)}),i.appendChild(s)}return r.appendChild(i),r.appendChild(a),{element:r}},Ht=(e,t,n)=>{t===`col`?Object.assign(e.style,{height:`${n}px`}):Object.assign(e.style,{width:`${n}px`})},Ut=[[2,2],[8,2],[2,7],[8,7],[2,12],[8,12]],Wt=[[2,2],[7,2],[12,2],[2,8],[7,8],[12,8]],Gt=e=>{let t=document.createElementNS(`http://www.w3.org/2000/svg`,`svg`),n=e===`horizontal`;t.setAttribute(`width`,n?`14`:`10`),t.setAttribute(`height`,n?`10`:`14`),t.setAttribute(`viewBox`,n?`0 0 14 10`:`0 0 10 14`),t.setAttribute(`fill`,`currentColor`),t.classList.add(`opacity-0`,`transition-opacity`,`duration-150`,`text-gray-400`,`pointer-events-none`);let r=n?Wt:Ut;for(let[e,n]of r){let r=document.createElementNS(`http://www.w3.org/2000/svg`,`circle`);r.setAttribute(`cx`,String(e)),r.setAttribute(`cy`,String(n)),r.setAttribute(`r`,`1.5`),t.appendChild(r)}return t},Kt=(e,t)=>{t===`col`?Object.assign(e.style,{height:`16px`}):Object.assign(e.style,{width:`16px`}),e.classList.add(`bg-gray-200`),e.classList.remove(`bg-gray-300`);let n=e.querySelector(`svg`);n&&(n.classList.remove(`opacity-0`),n.classList.add(`opacity-100`))},qt=(e,t,n)=>{Ht(e,t,n),e.classList.remove(`bg-gray-200`),e.classList.add(`bg-gray-300`);let r=e.querySelector(`svg`);r&&(r.classList.add(`opacity-0`),r.classList.remove(`opacity-100`))},Jt=`data-blok-table-cell-selected`,Yt=`2px solid #3b82f6`,Xt=`data-blok-table-selection-pill`,Zt=16,Qt=20,$t=4,en=[`absolute`,`z-3`,`rounded-sm`,`select-none`,`transition-[opacity,background-color,width]`,`duration-150`,`flex`,`items-center`,`justify-center`,`overflow-hidden`,`cursor-pointer`,`bg-blue-500`],tn=e=>e.style.userSelect===`none`,nn=class{constructor(e){this.anchorCell=null,this.extentCell=null,this.isSelecting=!1,this.hasSelection=!1,this.selectedCells=[],this.overlay=null,this.pill=null,this.pillPopover=null,this.resizeObserver=null,this.lastPaintedRange=null,this.preExpansionWasSingleCell=!1,this.grid=e.grid,this.rectangleSelection=e.rectangleSelection,this.onSelectionActiveChange=e.onSelectionActiveChange,this.onClearContent=e.onClearContent,this.onCopy=e.onCopy,this.onCut=e.onCut,this.onCopyViaButton=e.onCopyViaButton,this.onColorChange=e.onColorChange,this.onPlacementChange=e.onPlacementChange,this.getCellPlacement=e.getCellPlacement,this.onSelectionRangeChange=e.onSelectionRangeChange,this.onPointerDragActiveChange=e.onPointerDragActiveChange,this.isPopoverOpen=e.isPopoverOpen,this.canMergeCells=e.canMergeCells,this.onMergeCells=e.onMergeCells,this.isMergedCell=e.isMergedCell,this.onSplitCell=e.onSplitCell,this.getCellSpan=e.getCellSpan,this.i18n=e.i18n,this.grid.style.position=`relative`,this.boundPointerDown=this.handlePointerDown.bind(this),this.boundPointerMove=this.handlePointerMove.bind(this),this.boundPointerUp=this.handlePointerUp.bind(this),this.boundClearSelection=this.handleClearSelection.bind(this),this.boundCancelRectangle=this.handleCancelRectangle.bind(this),this.boundKeyDown=this.handleKeyDown.bind(this),this.boundCopyHandler=this.handleCopy.bind(this),this.boundCutHandler=this.handleCut.bind(this),this.boundPreventDragStart=this.handleDragStart.bind(this),this.grid.addEventListener(`pointerdown`,this.boundPointerDown),this.grid.addEventListener(`dragstart`,this.boundPreventDragStart),document.addEventListener(`keydown`,this.boundKeyDown),document.addEventListener(`copy`,this.boundCopyHandler),document.addEventListener(`cut`,this.boundCutHandler)}destroy(){if(this.destroyPillPopover(),this.disconnectResizeObserver(),this.clearSelection(),this.anchorCell){var e;(e=this.onPointerDragActiveChange)==null||e.call(this,!1),this.grid.style.userSelect=``}this.grid.removeEventListener(`pointerdown`,this.boundPointerDown),this.grid.removeEventListener(`dragstart`,this.boundPreventDragStart),document.removeEventListener(`pointermove`,this.boundPointerMove),document.removeEventListener(`pointerup`,this.boundPointerUp),document.removeEventListener(`pointercancel`,this.boundPointerUp),document.removeEventListener(`pointerdown`,this.boundClearSelection),document.removeEventListener(`mousemove`,this.boundCancelRectangle,!0),document.removeEventListener(`keydown`,this.boundKeyDown),document.removeEventListener(`copy`,this.boundCopyHandler),document.removeEventListener(`cut`,this.boundCutHandler)}selectRow(e){let t=this.getLogicalColumnCount();t!==0&&this.showProgrammaticSelection(e,0,e,t-1)}selectColumn(e){let t=this.grid.querySelectorAll(`[${I}]`).length;t!==0&&this.showProgrammaticSelection(0,e,t-1,e)}clearActiveSelection(){this.clearSelection()}getSelectedRange(){return this.hasSelection?this.lastPaintedRange:null}selectRange(e){this.showProgrammaticSelection(e.minRow,e.minCol,e.maxRow,e.maxCol)}handleDragStart(e){this.anchorCell&&e.preventDefault()}handlePointerDown(e){var t;if(tn(this.grid)||e.button!==0)return;let n=e.target;if(n.closest(`[data-blok-table-grip]`)||n.closest(`[data-blok-table-resize]`)||n.closest(`[${Xt}]`))return;let r=this.resolveCellCoord(n);r&&(this.hasSelection&&this.lastPaintedRange!==null&&this.lastPaintedRange.minRow===r.row&&this.lastPaintedRange.maxRow===r.row&&this.lastPaintedRange.minCol===r.col&&this.lastPaintedRange.maxCol===r.col?document.removeEventListener(`pointerdown`,this.boundClearSelection):this.hasSelection&&this.clearSelection(),this.anchorCell=r,this.isSelecting=!1,(t=this.onPointerDragActiveChange)==null||t.call(this,!0),document.addEventListener(`mousemove`,this.boundCancelRectangle,!0),document.addEventListener(`pointermove`,this.boundPointerMove),document.addEventListener(`pointerup`,this.boundPointerUp),document.addEventListener(`pointercancel`,this.boundPointerUp))}handlePointerMove(e){if(!this.anchorCell)return;let t=document.elementFromPoint(e.clientX,e.clientY);if(!t)return;let n=this.resolveCellCoord(t);if(!n){this.clampExtentToEdge(e);return}if(!(!this.isSelecting&&n.row===this.anchorCell.row&&n.col===this.anchorCell.col)){if(!this.isSelecting){var r,i;this.isSelecting=!0,(r=this.onSelectionActiveChange)==null||r.call(this,!0),this.grid.style.userSelect=`none`,(i=window.getSelection())==null||i.removeAllRanges()}(!this.extentCell||this.extentCell.row!==n.row||this.extentCell.col!==n.col)&&(this.extentCell=n,this.paintSelection())}}handleCancelRectangle(e){if(!this.rectangleSelection)return;this.rectangleSelection.cancelActiveSelection();let t=document.querySelector(`[data-blok-overlay-rectangle]`);if(!t)return;let n=t;n.style.display=`none`}handlePointerUp(){var e;if(document.removeEventListener(`mousemove`,this.boundCancelRectangle,!0),document.removeEventListener(`pointermove`,this.boundPointerMove),document.removeEventListener(`pointerup`,this.boundPointerUp),document.removeEventListener(`pointercancel`,this.boundPointerUp),(e=this.onPointerDragActiveChange)==null||e.call(this,!1),this.isSelecting){if(this.grid.style.userSelect=``,this.hasSelection=!0,this.lastPaintedRange){var t;(t=this.onSelectionRangeChange)==null||t.call(this,this.lastPaintedRange)}document.addEventListener(`pointerdown`,this.boundClearSelection)}else this.anchorCell&&(this.hasSelection?document.addEventListener(`pointerdown`,this.boundClearSelection):this.showProgrammaticSelection(this.anchorCell.row,this.anchorCell.col,this.anchorCell.row,this.anchorCell.col));this.isSelecting=!1,this.anchorCell=null,this.extentCell=null}handleClearSelection(e){let t=e.target;t instanceof HTMLElement&&t.closest(`[${Xt}]`)||t instanceof HTMLElement&&t.closest(`[data-blok-popover-opened]`)!==null||(this.pillPopover!==null&&this.destroyPillPopover(),document.removeEventListener(`pointerdown`,this.boundClearSelection),this.clearSelection())}handleKeyDown(e){var t;this.hasSelection&&(e.key!==`Delete`&&e.key!==`Backspace`||this.selectedCells.length<=1||(e.preventDefault(),(t=this.onClearContent)==null||t.call(this,[...this.selectedCells]),this.clearSelection()))}handleCopy(e){var t;!this.hasSelection||!e.clipboardData||this.selectedCells.length<=1&&this.hasNativeTextSelection()||(e.preventDefault(),(t=this.onCopy)==null||t.call(this,[...this.selectedCells],e.clipboardData))}handleCut(e){var t,n;!this.hasSelection||!e.clipboardData||this.selectedCells.length<=1&&this.hasNativeTextSelection()||(e.preventDefault(),(t=this.onCut)==null||t.call(this,[...this.selectedCells],e.clipboardData),(n=this.onClearContent)==null||n.call(this,[...this.selectedCells]),this.clearSelection())}hasNativeTextSelection(){let e=window.getSelection();return e!==null&&!e.isCollapsed}clearSelection(){let e=this.hasSelection;if(this.restoreModifiedCells(),this.hasSelection=!1,this.lastPaintedRange=null,this.preExpansionWasSingleCell=!1,e){var t;(t=this.onSelectionActiveChange)==null||t.call(this,!1)}}restoreModifiedCells(){this.destroyPillPopover(),this.disconnectResizeObserver(),this.selectedCells.forEach(e=>{e.removeAttribute(Jt)}),this.pill&&(this.pill.remove(),this.pill=null),this.overlay&&(this.overlay.remove(),this.overlay=null),this.selectedCells=[]}showProgrammaticSelection(e,t,n,r){var i;if(this.clearSelection(),this.anchorCell={row:e,col:t},this.extentCell={row:n,col:r},this.paintSelection(),this.hasSelection=!0,(i=this.onSelectionActiveChange)==null||i.call(this,!0),this.lastPaintedRange){var a;(a=this.onSelectionRangeChange)==null||a.call(this,this.lastPaintedRange)}this.anchorCell=null,this.extentCell=null,document.addEventListener(`pointerdown`,this.boundClearSelection)}expandRectToMergedSpans(e){return this.getCellSpan?this.expandRectStep(e):e}expandRectStep(e){let t=this.getCellSpan;if(!t)return e;let n=Array.from({length:e.maxRow-e.minRow+1},(t,n)=>e.minRow+n),r=Array.from({length:e.maxCol-e.minCol+1},(t,n)=>e.minCol+n),i=n.reduce((e,n)=>r.reduce((e,r)=>{let{colspan:i,rowspan:a}=t(n,r);return{minRow:e.minRow,maxRow:Math.max(e.maxRow,n+a-1),minCol:e.minCol,maxCol:Math.max(e.maxCol,r+i-1)}},e),e);return i.maxRow!==e.maxRow||i.maxCol!==e.maxCol?this.expandRectStep(i):i}paintSelection(){if(!this.anchorCell||!this.extentCell)return;this.selectedCells.forEach(e=>{e.removeAttribute(Jt)}),this.selectedCells=[];let e=Math.min(this.anchorCell.row,this.extentCell.row),t=Math.max(this.anchorCell.row,this.extentCell.row),n=Math.min(this.anchorCell.col,this.extentCell.col),r=Math.max(this.anchorCell.col,this.extentCell.col);this.preExpansionWasSingleCell=e===t&&n===r,this.lastPaintedRange=this.expandRectToMergedSpans({minRow:e,maxRow:t,minCol:n,maxCol:r});let{minRow:i,maxRow:a,minCol:o,maxCol:s}=this.lastPaintedRange,c=this.grid.querySelectorAll(`[${I}]`);this.selectedCells=this.collectCellsInRange(c,i,a,o,s),this.selectedCells.forEach(e=>{e.setAttribute(Jt,``)});let l=this.findCellByCoordOrIndex(c,i,o),u=this.findCellByCoordOrIndex(c,a,s);if(!l||!u)return;let d=this.grid.getBoundingClientRect(),f=l.getBoundingClientRect(),p=u.getBoundingClientRect(),m=getComputedStyle(this.grid),h=parseFloat(m.borderTopWidth)||0,g=parseFloat(m.borderLeftWidth)||0,_=p.right-f.left+1,v=p.bottom-f.top+1,y=f.top-d.top-h-1,b=f.left-d.left-g-1;this.overlay||(this.overlay=document.createElement(`div`),this.overlay.setAttribute(`data-blok-table-selection-overlay`,``),this.overlay.style.position=`absolute`,this.overlay.style.border=Yt,this.overlay.style.pointerEvents=`none`,this.overlay.style.boxSizing=`border-box`,this.overlay.style.borderRadius=`2px`,this.grid.appendChild(this.overlay)),this.overlay.style.top=`${y}px`,this.overlay.style.left=`${b}px`,this.overlay.style.width=`${_}px`,this.overlay.style.height=`${v}px`,this.pill||(this.pill=this.createPill(),this.grid.appendChild(this.pill)),this.pill.style.left=`${b+_-1}px`,this.pill.style.top=`${y+v/2}px`,this.observeCellResizes()}repositionOverlay(){let e=this.lastPaintedRange;if(!e||!this.overlay)return;let t=this.grid.querySelectorAll(`[${I}]`),n=this.findCellByCoordOrIndex(t,e.minRow,e.minCol),r=this.findCellByCoordOrIndex(t,e.maxRow,e.maxCol);if(!n||!r)return;let i=this.grid.getBoundingClientRect(),a=n.getBoundingClientRect(),o=r.getBoundingClientRect(),s=getComputedStyle(this.grid),c=parseFloat(s.borderTopWidth)||0,l=parseFloat(s.borderLeftWidth)||0,u=o.right-a.left+1,d=o.bottom-a.top+1,f=a.top-i.top-c-1,p=a.left-i.left-l-1;this.overlay.style.top=`${f}px`,this.overlay.style.left=`${p}px`,this.overlay.style.width=`${u}px`,this.overlay.style.height=`${d}px`,this.pill&&(this.pill.style.left=`${p+u-1}px`,this.pill.style.top=`${f+d/2}px`)}observeCellResizes(){if(this.disconnectResizeObserver(),this.selectedCells.length!==0){this.resizeObserver=new ResizeObserver(()=>{this.repositionOverlay()});for(let e of this.selectedCells)this.resizeObserver.observe(e)}}disconnectResizeObserver(){this.resizeObserver&&(this.resizeObserver.disconnect(),this.resizeObserver=null)}createPill(){let e=document.createElement(`div`);e.setAttribute(Xt,``),e.setAttribute(`contenteditable`,`false`),e.className=r.n(en),e.style.width=`${$t}px`,e.style.height=`${Qt}px`,e.style.pointerEvents=`auto`,e.style.transform=`translate(-50%, -50%)`,e.style.outline=`2px solid var(--blok-table-grip-outline, transparent)`;let t=Gt(`vertical`);return t.classList.remove(`text-gray-400`),t.classList.add(`text-white`),e.appendChild(t),e.addEventListener(`mouseenter`,()=>{this.pillPopover===null&&this.expandPill()}),e.addEventListener(`mouseleave`,()=>{this.pillPopover===null&&this.collapsePill()}),e.addEventListener(`pointerdown`,e=>{e.stopPropagation(),e.preventDefault(),this.openPillPopover()}),e}openPillPopover(){if(this.destroyPillPopover(),!this.pill)return;this.expandPill();let e=t.vr===`Meta`?`⌘C`:`Ctrl+C`,n=[];if(this.onColorChange!==void 0){let{element:e}=It({i18n:this.i18n,onColorSelect:(e,t)=>{var n;(n=this.onColorChange)==null||n.call(this,[...this.selectedCells],e,t)}});n.push({icon:t.Zt,title:this.i18n.t(`tools.table.cellColor`),name:`cellColor`,children:{items:[{type:t.pr.Html,element:e}],isFlippable:!1}})}let r=[];if(this.onPlacementChange!==void 0){let e=this.lastPaintedRange&&this.getCellPlacement?this.getCellPlacement(this.lastPaintedRange.minRow,this.lastPaintedRange.minCol):void 0,{element:n}=Vt({i18n:this.i18n,currentPlacement:e,onPlacementSelect:e=>{var t;(t=this.onPlacementChange)==null||t.call(this,[...this.selectedCells],e)}});r.push({icon:t.on,title:this.i18n.t(`tools.table.placement`),name:`cellPlacement`,children:{items:[{type:t.pr.Html,element:n}],isFlippable:!1}})}let i=[];if(this.lastPaintedRange&&this.onMergeCells){var a;let e=this.lastPaintedRange;(e.minRow!==e.maxRow||e.minCol!==e.maxCol)&&!this.preExpansionWasSingleCell&&(a=this.canMergeCells)!=null&&a.call(this,e)&&i.push({icon:t.$t,title:this.i18n.t(`tools.table.mergeCells`),closeOnActivate:!0,onActivate:()=>{var t;(t=this.onMergeCells)==null||t.call(this,e),this.clearSelection()}})}if(this.lastPaintedRange&&this.onSplitCell){var o,s;let e=this.lastPaintedRange,n=e.minRow===e.maxRow&&e.minCol===e.maxCol,r=this.preExpansionWasSingleCell&&((o=this.isMergedCell)==null?void 0:o.call(this,e.minRow,e.minCol));(n||r)&&(s=this.isMergedCell)!=null&&s.call(this,e.minRow,e.minCol)&&i.push({icon:t.mn,title:this.i18n.t(`tools.table.splitCell`),closeOnActivate:!0,onActivate:()=>{var t;(t=this.onSplitCell)==null||t.call(this,e.minRow,e.minCol),this.clearSelection()}})}let c=[...n,...r,...i,{icon:t.nt,title:this.i18n.t(`tools.table.copySelection`),secondaryLabel:e,closeOnActivate:!0,onActivate:()=>{var e;(e=this.onCopyViaButton)==null||e.call(this,[...this.selectedCells])}},{icon:t.at,title:this.i18n.t(`tools.table.clearSelection`),secondaryLabel:`Del`,closeOnActivate:!0,onActivate:()=>{var e;(e=this.onClearContent)==null||e.call(this,[...this.selectedCells]),this.clearSelection()}}];this.pillPopover=new t.C({items:c,trigger:this.pill,flippable:!0}),this.pillPopover.on(t.T.Closed,()=>{this.pillPopover!==null&&(this.destroyPillPopover(),this.collapsePill())}),this.pillPopover.show()}expandPill(){if(!this.pill)return;this.pill.style.width=`${Zt}px`;let e=this.pill.querySelector(`svg`);e&&(e.classList.remove(`opacity-0`),e.classList.add(`opacity-100`))}collapsePill(){if(!this.pill)return;this.pill.style.width=`${$t}px`;let e=this.pill.querySelector(`svg`);e&&(e.classList.add(`opacity-0`),e.classList.remove(`opacity-100`))}destroyPillPopover(){if(this.pillPopover!==null){let e=this.pillPopover;this.pillPopover=null,e.destroy()}}resolveCellCoord(e){let t=e.closest(`[${L}]`);if(!t)return null;let n=t.closest(`[${I}]`);if(!n||!this.grid.contains(n))return null;let r=t.getAttribute(R),i=t.getAttribute(z);if(r!==null&&i!==null){let e=parseInt(r,10),t=parseInt(i,10);if(!isNaN(e)&&!isNaN(t))return{row:e,col:t}}let a=Array.from(this.grid.querySelectorAll(`[${I}]`)).indexOf(n);if(a<0)return null;let o=Array.from(n.querySelectorAll(`[${L}]`)).indexOf(t);return o<0?null:{row:a,col:o}}clampExtentToEdge(e){var t,n,r,i;if(!this.anchorCell||!this.isSelecting)return;let a=this.grid.getBoundingClientRect(),o=this.grid.querySelectorAll(`[${I}]`).length,s=this.getLogicalColumnCount();if(o===0||s===0)return;let c={row:this.clampAxis(e.clientY,a.top,a.bottom,o,(t=(n=this.extentCell)==null?void 0:n.row)==null?this.anchorCell.row:t),col:this.clampAxis(e.clientX,a.left,a.right,s,(r=(i=this.extentCell)==null?void 0:i.col)==null?this.anchorCell.col:r)};(!this.extentCell||this.extentCell.row!==c.row||this.extentCell.col!==c.col)&&(this.extentCell=c,this.paintSelection())}collectCellsInRange(e,t,n,r,i){if(this.grid.querySelector(`[data-blok-table-cell-row]`)===null)return Array.from(e).slice(t,n+1).flatMap(e=>{let t=e.querySelectorAll(`[${L}]`);return Array.from(t).slice(r,i+1).filter(e=>e instanceof HTMLElement)});let a=this.grid.querySelectorAll(`[${L}]`);return Array.from(a).filter(e=>{let a=e.getAttribute(R),o=e.getAttribute(z);if(a===null||o===null)return!1;let s=Number(a),c=Number(o),l=e,u=s+(l.rowSpan||1)-1,d=c+(l.colSpan||1)-1;return s<=n&&u>=t&&c<=i&&d>=r})}findCellByCoordOrIndex(e,t,n){var r,i,a;return this.grid.querySelector(`[${R}="${t}"][${z}="${n}"]`)||((r=e[t])==null?void 0:r.querySelectorAll(`[${L}]`)[n])||Array.from((i=(a=e[t])==null?void 0:a.querySelectorAll(`[data-blok-table-cell]`))==null?[]:i).find(e=>{let t=Number(e.getAttribute(z)),r=e.colSpan||1;return t<=n&&t+r-1>=n})}getLogicalColumnCount(){var e,t;let n=(e=this.grid.querySelector(`colgroup`))==null?void 0:e.querySelectorAll(`col`).length;if(n!==void 0&&n>0)return n;let r=this.grid.querySelector(`[${I}]`);return(t=r==null?void 0:r.querySelectorAll(`[data-blok-table-cell]`).length)==null?0:t}clampAxis(e,t,n,r,i){return e<t?0:e>n?r-1:i}},H=e=>{let t=e.querySelector(`colgroup`);if(!t)return[];let n=t.querySelectorAll(`col`),r=n[0];if(r&&r.style.width.endsWith(`%`)){let t=e.querySelector(`[${I}]`);if(t)return Array.from(t.querySelectorAll(`[${L}]`)).map(e=>Math.round(e.getBoundingClientRect().width))}return Array.from(n).map(e=>parseFloat(e.style.width)||0)},rn=(e,t)=>{let n=t.reduce((e,t)=>e+t,0),r=e;r.style.width=`${n+1}px`;let i=e.querySelector(`colgroup`);if(!i)return;let a=Array.from(i.querySelectorAll(`col`));t.forEach((e,t)=>{t<a.length&&(a[t].style.width=`${e}px`)})},an=(e,t)=>{let n=Array.from(e.querySelectorAll(`[${I}]`)),r=n.findIndex(e=>Array.from(e.querySelectorAll(`[${L}]`)).includes(t));return r===-1?null:{row:r,col:Array.from(n[r].querySelectorAll(`[${L}]`)).indexOf(t)}},on=e=>{var t;let n=e.querySelector(`[${V}]`);return n?((t=n.textContent)==null?``:t).trim().length===0:!0},sn=(e,t)=>{let n=e.querySelectorAll(`[${I}]`)[t];if(!n)return!0;let r=n.querySelectorAll(`[${L}]`);return Array.from(r).every(e=>on(e))},cn=(e,t)=>{let n=e.querySelectorAll(`[${I}]`);return Array.from(n).every(e=>{let n=e.querySelector(`[${z}="${t}"]`);return!n||on(n)})},ln=e=>{let t=e.querySelector(`colgroup`);if(!t)return;let n=t.querySelectorAll(`col`),r=Array.from(n).reduce((e,t)=>e+(parseFloat(t.style.width)||0),0);if(r<=0)return;let i=100/r;n.forEach(e=>{let t=e,n=parseFloat(t.style.width)||0;t.style.width=`${Math.round(n*i*100)/100}%`})},un=(e,t,n)=>{if(!e)return e;let r=[...e],[i]=r.splice(t,1);return r.splice(n,0,i),r},dn=(e,t)=>{if(!e)return e;let n=[...e];return n.splice(t,1),n.length>0?n:void 0},fn=(e,t,n,r,i)=>{let a=n==null?H(e):n,o=r===void 0?pn(a):Math.round(r/2*100)/100;i.addColumn(e,t,a,o);let s=[...a];return s.splice(t,0,o),s},pn=e=>Math.round(e.reduce((e,t)=>e+t,0)/e.length/2*100)/100,mn=e=>e.length===0?0:Math.round(e.reduce((e,t)=>e+t,0)/e.length*100)/100,hn=(e,t,n)=>{var r;if(!e)return[];let i=e.querySelectorAll(`[${I}]`)[n];return i?(r=t==null?void 0:t.getBlockIdsFromCells(i.querySelectorAll(`[data-blok-table-cell]`)))==null?[]:r:[]},gn=(e,t,n)=>{var r;if(!e)return[];let i=e.querySelectorAll(`[${I}]`),a=[];return i.forEach(e=>{let t=e.querySelector(`[${z}="${n}"]`);t&&a.push(t)}),(r=t==null?void 0:t.getBlockIdsFromCells(a))==null?[]:r},U=(e,t)=>{e.querySelectorAll(`[${L}]`).forEach(e=>{t==null||t.ensureCellHasBlock(e)})},_n=(e,n,r,i)=>{let a=e.querySelectorAll(`[${I}]`);n.forEach((e,n)=>{let o=a[n];o&&e.forEach((e,n)=>{var a;let s=o.querySelector(`[${z}="${n}"]`);if(!s)return;let c=s.querySelector(`[${V}]`);if(!c)return;let l=c.querySelectorAll(`[data-blok-id]`).length>0;if(!(!B(e)&&l)){if(!B(e)){let t=document.createElement(`div`);t.className=`leading-[1.5]`,t.innerHTML=e,c.replaceChildren(t);return}(l||((a=c.textContent)==null?``:a).length>0)&&c.replaceChildren();for(let n of e.blocks){let e=r.blocks.getBlockIndex(n);if(e===void 0)continue;let a=r.blocks.getBlockByIndex(e);if(a&&!(a.parentId!==null&&a.parentId!==void 0&&a.parentId!==i)){if(a.holder.closest(`[${t.hi.nestedBlocks}]`)){c.appendChild(a.holder.cloneNode(!0));continue}c.appendChild(a.holder)}}c.querySelectorAll(`[data-blok-placeholder-active]`).forEach(e=>{e.removeAttribute(`data-blok-placeholder-active`)}),c.querySelectorAll(`[data-placeholder]`).forEach(e=>{e.removeAttribute(`data-placeholder`)})}})})},vn=(e,t)=>{var n,r,i,a,o,s,c;if(!(typeof e==`object`&&e&&`content`in e)){var l,u;return{withHeadings:(l=t.withHeadings)==null?!1:l,withHeadingColumn:!1,stretched:(u=t.stretched)==null?!1:u,content:[]}}let d=e,f=(n=d.content)==null||(n=n[0])==null?void 0:n.length,p=d.colWidths,m=p&&f&&p.length===f?p:void 0;return{withHeadings:(r=(i=d.withHeadings)==null?t.withHeadings:i)==null?!1:r,withHeadingColumn:(a=d.withHeadingColumn)==null?!1:a,stretched:(o=(s=d.stretched)==null?t.stretched:s)==null?!1:o,content:(c=d.content)==null?[]:c,colWidths:m,initialColWidth:d.initialColWidth}},yn=(e,t)=>{let n=n=>{let r=n.target.closest(`[${L}]`);if(!r)return;let i=an(e,r);i&&(t==null||t.handleKeyDown(n,i))};return e.addEventListener(`keydown`,n),()=>{e.removeEventListener(`keydown`,n)}},bn=[`overflow-x-auto`,`overflow-y-hidden`],xn=e=>{e==null||e.classList.add(...bn)},Sn=(e,t)=>{if(!e)return;let n=e.querySelectorAll(`[${I}]`);n.forEach(e=>{e.removeAttribute(`data-blok-table-heading`)}),t&&n.length>0&&n[0].setAttribute(`data-blok-table-heading`,``)},Cn=(e,t)=>{let n=e.querySelectorAll(`[${I}]`);t.forEach((e,t)=>{t>=n.length||e.forEach((e,r)=>{let i=n[t].querySelector(`[${z}="${r}"]`);i&&(B(e)&&e.color?i.style.backgroundColor=e.color:i.style.backgroundColor=``,B(e)&&e.textColor?i.style.color=e.textColor:i.style.color=``)})})},wn=(e,t)=>{let n=e.querySelectorAll(`[${I}]`);t.forEach((e,t)=>{t>=n.length||e.forEach((e,r)=>{let i=n[t].querySelector(`[${z}="${r}"]`);if(!i)return;let a=i.querySelector(`[${V}]`);a&&(B(e)&&e.placement&&e.placement!==`top-left`?a.setAttribute(`data-blok-cell-placement`,e.placement):a.removeAttribute(`data-blok-cell-placement`))})})},W=(e,t)=>{e&&(e.querySelectorAll(`[${L}]`).forEach(e=>{e.removeAttribute(`data-blok-table-heading-col`)}),t&&e.querySelectorAll(`[${I}]`).forEach(e=>{let t=e.querySelector(`[${L}]`);t&&t.setAttribute(`data-blok-table-heading-col`,``)}))},Tn=e=>!!(/^#[0-9a-f]{3,4}$/i.test(e)||/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(e)||/^rgba?\(\s*[\d.]+\s*,\s*[\d.]+\s*,\s*[\d.]+\s*(,\s*[\d.]+\s*)?\)$/i.test(e)||/^hsla?\(\s*[\d.]+\s*,\s*[\d.]+%\s*,\s*[\d.]+%\s*(,\s*[\d.]+\s*)?\)$/i.test(e)||e===`transparent`),En=class{constructor(e){var t,n,r;this.withHeadingsValue=(t=e==null?void 0:e.withHeadings)==null?!1:t,this.withHeadingColumnValue=(n=e==null?void 0:e.withHeadingColumn)==null?!1:n,this.stretchedValue=(r=e==null?void 0:e.stretched)==null?!1:r,this.colWidthsValue=e!=null&&e.colWidths?[...e.colWidths]:void 0,this.initialColWidthValue=e==null?void 0:e.initialColWidth,this.contentGrid=this.normalizeContent(e==null?void 0:e.content),this.blockCellMap=new Map,this.rebuildBlockCellMap()}get rows(){return this.contentGrid.length}get cols(){return this.contentGrid.length>0?this.contentGrid[0].length:0}get withHeadings(){return this.withHeadingsValue}get withHeadingColumn(){return this.withHeadingColumnValue}get stretched(){return this.stretchedValue}get colWidths(){return this.colWidthsValue?[...this.colWidthsValue]:void 0}get initialColWidth(){return this.initialColWidthValue}snapshot(){let e={withHeadings:this.withHeadingsValue,withHeadingColumn:this.withHeadingColumnValue,stretched:this.stretchedValue,content:this.contentGrid.map(e=>e.map(e=>{let t={blocks:[...e.blocks]};return e.color!==void 0&&(t.color=e.color),e.textColor!==void 0&&(t.textColor=e.textColor),e.placement!==void 0&&(t.placement=e.placement),e.colspan!==void 0&&e.colspan>1&&(t.colspan=e.colspan),e.rowspan!==void 0&&e.rowspan>1&&(t.rowspan=e.rowspan),e.mergedInto!==void 0&&(t.mergedInto=[...e.mergedInto]),t}))};return this.colWidthsValue!==void 0&&(e.colWidths=[...this.colWidthsValue]),this.initialColWidthValue!==void 0&&(e.initialColWidth=this.initialColWidthValue),e}findCellForBlock(e){var t;return(t=this.blockCellMap.get(e))==null?null:t}addBlockToCell(e,t,n){if(!this.isInBounds(e,t)||this.isSpannedCell(e,t))return;let r=this.blockCellMap.get(n);if(r){let e=this.contentGrid[r.row][r.col];e.blocks=e.blocks.filter(e=>e!==n)}this.contentGrid[e][t].blocks.push(n),this.blockCellMap.set(n,{row:e,col:t})}removeBlockFromCell(e,t,n){if(!this.isInBounds(e,t))return;let r=this.contentGrid[e][t],i=r.blocks.indexOf(n);i!==-1&&(r.blocks.splice(i,1),this.blockCellMap.delete(n))}setCellBlocks(e,t,n){if(this.isInBounds(e,t)&&!this.isSpannedCell(e,t)){for(let n of this.contentGrid[e][t].blocks)this.blockCellMap.delete(n);for(let r of n){let n=this.blockCellMap.get(r);if(n!==void 0&&(n.row!==e||n.col!==t)){let e=this.contentGrid[n.row][n.col];e.blocks=e.blocks.filter(e=>e!==r)}}this.contentGrid[e][t].blocks=[...n];for(let r of n)this.blockCellMap.set(r,{row:e,col:t})}}getCellBlocks(e,t){return this.isInBounds(e,t)?[...this.contentGrid[e][t].blocks]:[]}setCellColor(e,t,n){this.isInBounds(e,t)&&(n===void 0?delete this.contentGrid[e][t].color:Tn(n)&&(this.contentGrid[e][t].color=n))}getCellColor(e,t){if(this.isInBounds(e,t))return this.contentGrid[e][t].color}setCellTextColor(e,t,n){this.isInBounds(e,t)&&(n===void 0?delete this.contentGrid[e][t].textColor:Tn(n)&&(this.contentGrid[e][t].textColor=n))}getCellTextColor(e,t){if(this.isInBounds(e,t))return this.contentGrid[e][t].textColor}setCellPlacement(e,t,n){this.isInBounds(e,t)&&(n===void 0?delete this.contentGrid[e][t].placement:this.contentGrid[e][t].placement=n)}getCellPlacement(e,t){if(this.isInBounds(e,t))return this.contentGrid[e][t].placement}addRow(e){let t=e===void 0?this.contentGrid.length:Math.min(Math.max(0,e),this.contentGrid.length),n=this.cols,r=Array.from({length:n},()=>({blocks:[]}));return this.contentGrid.splice(t,0,r),this.shiftMergedIntoRows(t,1),this.expandSpansForInsertedRow(t),this.rebuildBlockCellMap(),{type:`add-row`,index:t,cellsToPopulate:n}}deleteRow(e){if(!this.isRowInBounds(e))return{type:`delete-row`,index:e,blocksToDelete:[]};this.contractSpansForDeletedRow(e);let t=this.collectBlocksInRow(e);this.contentGrid.splice(e,1);for(let e of t)this.blockCellMap.delete(e);return this.shiftMergedIntoRows(e,-1),this.rebuildBlockCellMap(),{type:`delete-row`,index:e,blocksToDelete:t}}moveRow(e,t){if(!this.isRowInBounds(e)||!this.isRowInBounds(t)||e===t||this.isRowInvolvedInMerge(e))return{type:`move-row`,index:e,toIndex:t};let[n]=this.contentGrid.splice(e,1);return this.contentGrid.splice(t,0,n),this.rebuildMergedIntoRowCoordinates(e,t),this.rebuildBlockCellMap(),{type:`move-row`,index:e,toIndex:t}}addColumn(e,t){let n=e===void 0?this.cols:Math.min(Math.max(0,e),this.cols),r=[];if(this.contentGrid.forEach((e,t)=>{e.splice(n,0,{blocks:[]}),r.push({row:t,col:n})}),this.colWidthsValue!==void 0){let e=t==null?0:t;this.colWidthsValue.splice(n,0,e)}return this.shiftMergedIntoCols(n,1),this.expandSpansForInsertedCol(n),this.rebuildBlockCellMap(),{type:`add-column`,index:n,cellsToPopulate:r}}deleteColumn(e){var t;if(!this.isColInBounds(e))return{type:`delete-column`,index:e,blocksToDelete:[]};this.contractSpansForDeletedCol(e);let n=this.collectBlocksInColumn(e);for(let t of this.contentGrid)t.splice(e,1);for(let e of n)this.blockCellMap.delete(e);return this.colWidthsValue!==void 0&&this.colWidthsValue.splice(e,1),((t=this.colWidthsValue)==null?void 0:t.length)===0&&(this.colWidthsValue=void 0),this.shiftMergedIntoCols(e,-1),this.rebuildBlockCellMap(),{type:`delete-column`,index:e,blocksToDelete:n}}moveColumn(e,t){if(!this.isColInBounds(e)||!this.isColInBounds(t)||e===t||this.isColInvolvedInMerge(e))return{type:`move-column`,index:e,toIndex:t};for(let n of this.contentGrid){let[r]=n.splice(e,1);n.splice(t,0,r)}if(this.colWidthsValue!==void 0){let[n]=this.colWidthsValue.splice(e,1);this.colWidthsValue.splice(t,0,n)}return this.rebuildMergedIntoColCoordinates(e,t),this.rebuildBlockCellMap(),{type:`move-column`,index:e,toIndex:t}}replaceAll(e){var t;this.withHeadingsValue=e.withHeadings,this.withHeadingColumnValue=e.withHeadingColumn,this.stretchedValue=(t=e.stretched)==null?!1:t,this.colWidthsValue=e.colWidths?[...e.colWidths]:void 0,this.initialColWidthValue=e.initialColWidth,this.contentGrid=this.normalizeContent(e.content),this.blockCellMap.clear(),this.rebuildBlockCellMap()}canMergeCells(e){let{minRow:t,maxRow:n,minCol:r,maxCol:i}=e;return t===n&&r===i||t<0||n>=this.rows||r<0||i>=this.cols?!1:this.contentGrid.slice(t,n+1).every((e,a)=>{let o=t+a;return e.slice(r,i+1).every((e,a)=>{var s,c;let l=r+a,u=(s=e.colspan)==null?1:s,d=(c=e.rowspan)==null?1:c;if((u>1||d>1)&&(o+d-1>n||l+u-1>i))return!1;if(e.mergedInto!==void 0){let[n,i]=e.mergedInto;if(n<t||i<r)return!1}return!0})})}mergeCells(e){var t,n;let{minRow:r,maxRow:i,minCol:a,maxCol:o}=e,s={blocksToRelocate:[]};if(!this.canMergeCells(e))return s;let c=this.contentGrid[r][a];this.contentGrid.slice(r,i+1).forEach((e,t)=>{let n=r+t;e.slice(a,o+1).forEach((e,t)=>{var i,o;let s=a+t;n===r&&s===a||(((i=e.colspan)==null?1:i)>1||((o=e.rowspan)==null?1:o)>1)&&this.splitCellInternal(n,s)})}),(((t=c.colspan)==null?1:t)>1||((n=c.rowspan)==null?1:n)>1)&&this.splitCellInternal(r,a);let l=[];return this.contentGrid.slice(r,i+1).forEach((e,t)=>{let n=r+t;this.contentGrid[n].slice(a,o+1).forEach((e,t)=>{let i=a+t,o=this.contentGrid[n][i];for(let e of o.blocks)l.push(e),(n!==r||i!==a)&&s.blocksToRelocate.push(e);(n!==r||i!==a)&&(o.blocks=[],o.mergedInto=[r,a],delete o.colspan,delete o.rowspan)})}),c.blocks=l,c.colspan=o-a+1,c.rowspan=i-r+1,delete c.mergedInto,delete c.placement,c.colspan===1&&delete c.colspan,c.rowspan===1&&delete c.rowspan,this.rebuildBlockCellMap(),s}splitCell(e,t){var n,r;if(!this.isInBounds(e,t))return;let i=this.contentGrid[e][t];((n=i.colspan)==null?1:n)<=1&&((r=i.rowspan)==null?1:r)<=1||(this.splitCellInternal(e,t),this.rebuildBlockCellMap())}isMergedCell(e,t){var n,r;if(!this.isInBounds(e,t))return!1;let i=this.contentGrid[e][t];return((n=i.colspan)==null?1:n)>1||((r=i.rowspan)==null?1:r)>1}isSpannedCell(e,t){return this.isInBounds(e,t)?this.contentGrid[e][t].mergedInto!==void 0:!1}getCellSpan(e,t){var n,r;if(!this.isInBounds(e,t))return{colspan:1,rowspan:1};let i=this.contentGrid[e][t];return{colspan:(n=i.colspan)==null?1:n,rowspan:(r=i.rowspan)==null?1:r}}splitCellInternal(e,t){var n,r;let i=this.contentGrid[e][t],a=(n=i.colspan)==null?1:n,o=(r=i.rowspan)==null?1:r;this.contentGrid.slice(e,Math.min(e+o,this.rows)).forEach((n,r)=>{let i=e+r;this.contentGrid[i].slice(t,Math.min(t+a,this.cols)).forEach((n,r)=>{let a=t+r;if(i===e&&a===t)return;let o=this.contentGrid[i][a];delete o.mergedInto,o.blocks=[],delete o.placement})}),delete i.colspan,delete i.rowspan,delete i.placement}setWithHeadings(e){this.withHeadingsValue=e}setWithHeadingColumn(e){this.withHeadingColumnValue=e}setStretched(e){this.stretchedValue=e}setColWidths(e){this.colWidthsValue=e?[...e]:void 0}setInitialColWidth(e){this.initialColWidthValue=e}validateInvariants(){if(this.contentGrid.length>0){let e=this.contentGrid[0].length;this.contentGrid.forEach((t,n)=>{if(t.length!==e)throw Error(`Invariant violation: row ${n} has ${t.length} columns, expected ${e}`)})}if(this.colWidthsValue!==void 0&&this.contentGrid.length>0&&this.colWidthsValue.length!==this.contentGrid[0].length)throw Error(`Invariant violation: colWidths has ${this.colWidthsValue.length} entries but grid has ${this.contentGrid[0].length} columns`);let e=new Set;if(this.contentGrid.forEach((t,n)=>{t.forEach((t,r)=>{for(let i of t.blocks){if(e.has(i))throw Error(`Invariant violation: block "${i}" appears in multiple cells`);e.add(i);let t=this.blockCellMap.get(i);if(!t)throw Error(`Invariant violation: block "${i}" at [${n},${r}] not in blockCellMap`);if(t.row!==n||t.col!==r)throw Error(`Invariant violation: block "${i}" at [${n},${r}] mapped to [${t.row},${t.col}]`)}})}),this.contentGrid.forEach((e,t)=>{e.forEach((e,n)=>{var r,i;let a=(r=e.colspan)==null?1:r,o=(i=e.rowspan)==null?1:i;if(a>1||o>1){var s,c;if(t+o>this.contentGrid.length||n+a>((s=(c=this.contentGrid[0])==null?void 0:c.length)==null?0:s)){var l,u;throw Error(`Invariant violation: origin [${t},${n}] span extends beyond grid bounds (colspan=${a}, rowspan=${o}, rows=${this.contentGrid.length}, cols=${(l=(u=this.contentGrid[0])==null?void 0:u.length)==null?0:l})`)}}})}),this.contentGrid.forEach((e,t)=>{e.forEach((e,n)=>{var r,i,a,o;if(e.mergedInto===void 0)return;let[s,c]=e.mergedInto;if(s<0||s>=this.contentGrid.length||c<0||c>=((r=(i=this.contentGrid[0])==null?void 0:i.length)==null?0:r))throw Error(`Invariant violation: mergedInto at [${t},${n}] points to out-of-bounds [${s},${c}]`);let l=this.contentGrid[s][c],u=(a=l.colspan)==null?1:a,d=(o=l.rowspan)==null?1:o;if(u<=1&&d<=1)throw Error(`Invariant violation: mergedInto at [${t},${n}] points to [${s},${c}] which is not a merge origin`);if(t<s||t>=s+d||n<c||n>=c+u)throw Error(`Invariant violation: mergedInto at [${t},${n}] is outside the span of origin [${s},${c}] (colspan=${u}, rowspan=${d})`)})}),this.contentGrid.forEach((e,t)=>{e.forEach((e,n)=>{var r,i;let a=(r=e.colspan)==null?1:r,o=(i=e.rowspan)==null?1:i;a<=1&&o<=1||this.contentGrid.slice(t,t+o).forEach((e,r)=>{let i=t+r;e.slice(n,n+a).forEach((e,r)=>{let a=n+r;if(!(i===t&&a===n)&&!(e!=null&&e.mergedInto))throw Error(`Invariant violation: cell [${i},${a}] is within span of origin [${t},${n}] but has no mergedInto`)})})})}),this.blockCellMap.size!==e.size)throw Error(`Invariant violation: blockCellMap has ${this.blockCellMap.size} entries but grid has ${e.size} blocks`)}shiftMergedIntoRows(e,t){this.contentGrid.forEach((n,r)=>{this.contentGrid[r].forEach((n,i)=>{let a=this.contentGrid[r][i];a.mergedInto!==void 0&&a.mergedInto[0]>=e&&(a.mergedInto=[a.mergedInto[0]+t,a.mergedInto[1]])})})}shiftMergedIntoCols(e,t){this.contentGrid.forEach((n,r)=>{this.contentGrid[r].forEach((n,i)=>{let a=this.contentGrid[r][i];a.mergedInto!==void 0&&a.mergedInto[1]>=e&&(a.mergedInto=[a.mergedInto[0],a.mergedInto[1]+t])})})}expandSpansForInsertedRow(e){this.contentGrid.forEach((t,n)=>{this.contentGrid[n].forEach((t,r)=>{var i,a;let o=this.contentGrid[n][r],s=(i=o.rowspan)==null?1:i,c=(a=o.colspan)==null?1:a;s<=1&&c<=1||n>=e||n+s<=e||(o.rowspan=s+1,this.markInsertedRowCells(e,n,r,c))})})}markInsertedRowCells(e,t,n,r){this.contentGrid[e].slice(n,n+r).forEach((r,i)=>{let a=n+i;if(a===n&&t===e)return;let o=this.contentGrid[e][a];o.mergedInto=[t,n],o.blocks=[]})}expandSpansForInsertedCol(e){this.contentGrid.forEach((t,n)=>{this.contentGrid[n].forEach((t,r)=>{var i,a;let o=this.contentGrid[n][r],s=(i=o.rowspan)==null?1:i,c=(a=o.colspan)==null?1:a;s<=1&&c<=1||r>=e||r+c<=e||(o.colspan=c+1,this.markInsertedColCells(e,n,r,s))})})}markInsertedColCells(e,t,n,r){this.contentGrid.slice(t,t+r).forEach((r,i)=>{let a=t+i;if(a===t&&e===n)return;let o=this.contentGrid[a][e];o.mergedInto=[t,n],o.blocks=[]})}contractSpansForDeletedRow(e){this.contentGrid[e].forEach((t,n)=>{var r,i;let a=this.contentGrid[e][n];((r=a.colspan)==null?1:r)>1||((i=a.rowspan)==null?1:i)>1?this.handleOriginInDeletedRow(e,n):a.mergedInto!==void 0&&this.handleCoveredInDeletedRow(e,n)})}handleOriginInDeletedRow(e,t){var n,r;let i=this.contentGrid[e][t],a=(n=i.rowspan)==null?1:n,o=(r=i.colspan)==null?1:r;if(a<=1)return;let s=a-1,c=e+1;c<this.contentGrid.length&&this.transferOriginToNextRow(e,t,c,a,o,s),delete i.colspan,delete i.rowspan}transferOriginToNextRow(e,t,n,r,i,a){let o=this.contentGrid[e][t],s=this.contentGrid[n][t];if(s.blocks=[...o.blocks],o.blocks=[],delete s.mergedInto,a===1&&i===1){delete s.colspan,delete s.rowspan,this.clearMergedIntoRefs(n,e+r,t,t+i,e,t,n,t,void 0);return}a>1?s.rowspan=a:delete s.rowspan,i>1?s.colspan=i:delete s.colspan,this.clearMergedIntoRefs(n,e+r,t,t+i,e,t,n,t,[n,t])}handleCoveredInDeletedRow(e,t){var n,r,i;let[a,o]=this.contentGrid[e][t].mergedInto;if(a===e)return;let s=(n=this.contentGrid[a])==null?void 0:n[o];if(!s)return;let c=(r=s.rowspan)==null?1:r,l=(i=s.colspan)==null?1:i,u=c-1;u===1&&l===1?(delete s.colspan,delete s.rowspan,this.clearMergedIntoRefsForDissolve(a,a+c,o,o+l,a,o,e)):u>1?s.rowspan=u:delete s.rowspan}clearMergedIntoRefs(e,t,n,r,i,a,o,s,c){this.contentGrid.slice(e,t).forEach((t,l)=>{let u=e+l;this.contentGrid[u].slice(n,r).forEach((e,t)=>{var r,l,d;let f=n+t;if(u===o&&f===s)return;let p=(r=this.contentGrid[u])==null?void 0:r[f];(p==null||(l=p.mergedInto)==null?void 0:l[0])===i&&(p==null||(d=p.mergedInto)==null?void 0:d[1])===a&&(c===void 0?delete p.mergedInto:p.mergedInto=c)})})}clearMergedIntoRefsForDissolve(e,t,n,r,i,a,o){this.contentGrid.slice(e,t).forEach((t,s)=>{let c=e+s;c!==o&&this.contentGrid[c].slice(n,r).forEach((e,t)=>{var r;let o=n+t;if(c===i&&o===a)return;let s=(r=this.contentGrid[c])==null?void 0:r[o];s!=null&&s.mergedInto&&delete s.mergedInto})})}contractSpansForDeletedCol(e){this.contentGrid.forEach((t,n)=>{var r,i;let a=this.contentGrid[n][e];((r=a.colspan)==null?1:r)>1||((i=a.rowspan)==null?1:i)>1?this.handleOriginInDeletedCol(e,n):a.mergedInto!==void 0&&this.handleCoveredInDeletedCol(e,n)})}handleOriginInDeletedCol(e,t){var n,r,i,a;let o=this.contentGrid[t][e],s=(n=o.rowspan)==null?1:n,c=(r=o.colspan)==null?1:r;if(c<=1)return;let l=c-1,u=e+1;u<((i=(a=this.contentGrid[t])==null?void 0:a.length)==null?0:i)&&this.transferOriginToNextCol(e,t,u,s,c,l),delete o.colspan,delete o.rowspan}transferOriginToNextCol(e,t,n,r,i,a){let o=this.contentGrid[t][e],s=this.contentGrid[t][n];if(s.blocks=[...o.blocks],o.blocks=[],delete s.mergedInto,a===1&&r===1){delete s.colspan,delete s.rowspan,this.clearMergedIntoRefs(t,t+r,n,e+i,t,e,t,n,void 0);return}a>1?s.colspan=a:delete s.colspan,r>1?s.rowspan=r:delete s.rowspan,this.clearMergedIntoRefs(t,t+r,n,e+i,t,e,t,n,[t,n])}handleCoveredInDeletedCol(e,t){var n,r,i;let[a,o]=this.contentGrid[t][e].mergedInto;if(o===e)return;let s=(n=this.contentGrid[a])==null?void 0:n[o];if(!s)return;let c=(r=s.colspan)==null?1:r,l=(i=s.rowspan)==null?1:i,u=c-1;u===1&&l===1?(delete s.colspan,delete s.rowspan,this.clearMergedIntoRefsForDissolveCol(a,a+l,o,o+c,a,o,e)):u>1?s.colspan=u:delete s.colspan}clearMergedIntoRefsForDissolveCol(e,t,n,r,i,a,o){this.contentGrid.slice(e,t).forEach((t,s)=>{let c=e+s;this.contentGrid[c].slice(n,r).forEach((e,t)=>{var r;let s=n+t;if(c===i&&s===a||s===o)return;let l=(r=this.contentGrid[c])==null?void 0:r[s];l!=null&&l.mergedInto&&delete l.mergedInto})})}isRowInvolvedInMerge(e){return this.contentGrid[e].some(t=>{var n;return((n=t.rowspan)==null?1:n)>1?!0:t.mergedInto!==void 0&&t.mergedInto[0]!==e})}isColInvolvedInMerge(e){return this.contentGrid.some(t=>{var n;let r=t[e];return((n=r.colspan)==null?1:n)>1?!0:r.mergedInto!==void 0&&r.mergedInto[1]!==e})}rebuildMergedIntoRowCoordinates(e,t){let n=this.contentGrid.length,r=this.buildMoveMapping(n,e,t);this.contentGrid.forEach((e,t)=>{this.contentGrid[t].forEach((e,n)=>{let i=this.contentGrid[t][n];i.mergedInto!==void 0&&(i.mergedInto=[r[i.mergedInto[0]],i.mergedInto[1]])})})}rebuildMergedIntoColCoordinates(e,t){let n=this.cols,r=this.buildMoveMapping(n,e,t);this.contentGrid.forEach((e,t)=>{this.contentGrid[t].forEach((e,n)=>{let i=this.contentGrid[t][n];if(i.mergedInto!==void 0){let e=i.mergedInto[1];i.mergedInto=[i.mergedInto[0],r[e]]}})})}buildMoveMapping(e,t,n){return Array.from({length:e},(e,r)=>{if(r===t)return n;let i=r>t?r-1:r;return i>=n?i+1:i})}normalizeContent(e){if(!e||!Array.isArray(e))return[];let t=new Set;return e.map(e=>(e==null?[]:e).map(e=>{let n=this.normalizeCell(e);return n.blocks=n.blocks.filter(e=>t.has(e)?!1:(t.add(e),!0)),n}))}normalizeCell(e){if(B(e)){let t={blocks:[...e.blocks]};return e.color!==void 0&&Tn(e.color)&&(t.color=e.color),e.textColor!==void 0&&Tn(e.textColor)&&(t.textColor=e.textColor),e.placement!==void 0&&(t.placement=e.placement),e.colspan!==void 0&&e.colspan>1&&(t.colspan=e.colspan),e.rowspan!==void 0&&e.rowspan>1&&(t.rowspan=e.rowspan),e.mergedInto!==void 0&&(t.mergedInto=[...e.mergedInto]),t}return{blocks:[]}}rebuildBlockCellMap(){this.blockCellMap.clear(),this.contentGrid.forEach((e,t)=>{e.forEach((e,n)=>{for(let r of e.blocks)this.blockCellMap.set(r,{row:t,col:n})})})}isInBounds(e,t){return e>=0&&e<this.contentGrid.length&&t>=0&&(this.contentGrid.length===0||t<this.contentGrid[e].length)}isRowInBounds(e){return e>=0&&e<this.contentGrid.length}isColInBounds(e){return e>=0&&this.contentGrid.length>0&&e<this.contentGrid[0].length}collectBlocksInRow(e){let t=[];for(let n of this.contentGrid[e])t.push(...n.blocks);return t}collectBlocksInColumn(e){let t=[];for(let n of this.contentGrid)e<n.length&&t.push(...n[e].blocks);return t}},Dn=`data-blok-table-resize`,On=50,kn=16,An=class{get enabled(){return this._enabled}set enabled(e){this._enabled=e;let t=e?``:`none`;this.handles.forEach(e=>{let n=e;n.style.pointerEvents=t})}constructor(e,t,n,r,i,a=!1){this._enabled=!0,this.isDragging=!1,this.dragStartX=0,this.dragColIndex=-1,this.startColWidth=0,this.dragColElements=null,this.handles=[],this.gridEl=e,this.colWidths=[...t],this.onChange=n,this.onDragStart=r==null?null:r,this.onDrag=i==null?null:i,this.needsInitialApply=a,this.boundPointerDown=this.onPointerDown.bind(this),this.boundPointerMove=this.onPointerMove.bind(this),this.boundPointerUp=this.onPointerUp.bind(this),this.gridEl.style.position=`relative`,a||this.applyWidths(),this.createHandles(),this.gridEl.addEventListener(`pointerdown`,this.boundPointerDown)}destroy(){this.gridEl.removeEventListener(`pointerdown`,this.boundPointerDown),document.removeEventListener(`pointermove`,this.boundPointerMove),document.removeEventListener(`pointerup`,this.boundPointerUp),this.dragColElements=null,this.handles.forEach(e=>e.remove()),this.handles=[]}createHandles(){let e=this.colWidths.length;e<2||Array.from({length:e}).forEach((e,t)=>{let n=this.createHandle(t);this.handles.push(n),this.gridEl.appendChild(n)})}createHandle(e){let t=document.createElement(`div`),n=this.getHandleLeftPx(e);return t.setAttribute(Dn,``),t.setAttribute(`data-col`,String(e)),t.style.position=`absolute`,t.style.top=`-1px`,t.style.bottom=`0px`,t.style.width=`${kn}px`,t.style.left=`${n-kn/2}px`,t.style.cursor=`col-resize`,t.style.zIndex=`2`,t.style.background=`linear-gradient(to right, transparent 7px, #3b82f6 7px, #3b82f6 9px, transparent 9px)`,t.style.opacity=`0`,t.style.transition=`opacity 150ms ease`,t.setAttribute(`contenteditable`,`false`),t.addEventListener(`mouseenter`,()=>{this.isDragging||(t.style.opacity=`1`)}),t.addEventListener(`mouseleave`,()=>{this.isDragging||(t.style.opacity=`0`)}),t}getHandleLeftPx(e){return this.colWidths.slice(0,e+1).reduce((e,t)=>e+t,0)}updateHandlePositions(){this.handles.forEach((e,t)=>{let n=this.getHandleLeftPx(t),r=e;r.style.left=`${n-kn/2}px`})}onPointerDown(e){var t;if(!this._enabled)return;let n=e.target;if(!n.hasAttribute(Dn))return;e.preventDefault(),this.needsInitialApply&&(this.applyWidths(),this.updateHandlePositions(),this.needsInitialApply=!1);let r=n.getAttribute(`data-col`);r!==null&&(this.dragColIndex=Number(r),this.isDragging=!0,this.dragStartX=e.clientX,this.startColWidth=this.colWidths[this.dragColIndex],this.dragColElements=this.resolveColElements(),(t=this.onDragStart)==null||t.call(this),this.gridEl.style.userSelect=`none`,n.style.opacity=`1`,n.setPointerCapture&&n.setPointerCapture(e.pointerId),document.addEventListener(`pointermove`,this.boundPointerMove),document.addEventListener(`pointerup`,this.boundPointerUp))}onPointerMove(e){var t,n;if(!this.isDragging)return;let r=e.clientX-this.dragStartX,i=this.startColWidth+r,a=Math.max(On,i);this.colWidths[this.dragColIndex]=a,this.applyWidths((t=this.dragColElements)==null?void 0:t),this.updateHandlePositions(),(n=this.onDrag)==null||n.call(this)}onPointerUp(){if(!this.isDragging)return;this.isDragging=!1,this.gridEl.style.userSelect=``;let e=this.handles[this.dragColIndex];e&&(e.style.opacity=`0`),document.removeEventListener(`pointermove`,this.boundPointerMove),document.removeEventListener(`pointerup`,this.boundPointerUp),this.dragColElements=null,this.onChange([...this.colWidths])}resolveColElements(){let e=this.gridEl.querySelector(`colgroup`);return e?Array.from(e.querySelectorAll(`col`)):[]}applyWidths(e=this.resolveColElements()){let t=this.colWidths.reduce((e,t)=>e+t,0);this.gridEl.style.width=`${t+1}px`,e.forEach((e,t)=>{if(t<this.colWidths.length){let n=e;n.style.width=`${this.colWidths[t]}px`}})}},jn=(e,t,n)=>(n.grid.addRow(e,t),U(e,n.cellBlocks),{pendingHighlight:{type:`row`,index:t},moveSelection:null,colWidths:n.data.colWidths,withHeadings:n.data.withHeadings,withHeadingColumn:n.data.withHeadingColumn}),Mn=(e,t,n)=>{let r=fn(e,t,n.data.colWidths,n.data.initialColWidth,n.grid);return U(e,n.cellBlocks),{pendingHighlight:{type:`col`,index:t},moveSelection:null,colWidths:r,withHeadings:n.data.withHeadings,withHeadingColumn:n.data.withHeadingColumn}},Nn=(e,t,n,r)=>(r.grid.moveRow(e,t,n),{pendingHighlight:null,moveSelection:{type:`row`,index:n},colWidths:r.data.colWidths,withHeadings:r.data.withHeadings,withHeadingColumn:r.data.withHeadingColumn}),Pn=(e,t,n,r)=>(r.grid.moveColumn(e,t,n),{pendingHighlight:null,moveSelection:{type:`col`,index:n},colWidths:un(r.data.colWidths,t,n),withHeadings:r.data.withHeadings,withHeadingColumn:r.data.withHeadingColumn}),Fn=(e,t,n)=>{var r,i;return(r=n.cellBlocks)==null||r.deleteBlocks((i=n.blocksToDelete)==null?[]:i),n.grid.deleteRow(e,t),{pendingHighlight:{type:`row`,index:t<n.grid.getRowCount(e)?t:t-1},moveSelection:null,colWidths:n.data.colWidths,withHeadings:n.data.withHeadings,withHeadingColumn:n.data.withHeadingColumn}},In=(e,t,n)=>{var r,i;(r=n.cellBlocks)==null||r.deleteBlocks((i=n.blocksToDelete)==null?[]:i),n.grid.deleteColumn(e,t);let a=dn(n.data.colWidths,t);return a?rn(e,a):ln(e),{pendingHighlight:{type:`col`,index:t<n.grid.getColumnCount(e)?t:t-1},moveSelection:null,colWidths:a,withHeadings:n.data.withHeadings,withHeadingColumn:n.data.withHeadingColumn}},Ln=(e,t,n)=>{switch(t.type){case`insert-row-above`:return jn(e,t.index,n);case`insert-row-below`:return jn(e,t.index+1,n);case`insert-col-left`:return Mn(e,t.index,n);case`insert-col-right`:return Mn(e,t.index+1,n);case`move-row`:return Nn(e,t.fromIndex,t.toIndex,n);case`move-col`:return Pn(e,t.fromIndex,t.toIndex,n);case`delete-row`:return Fn(e,t.index,n);case`delete-col`:return In(e,t.index,n);case`toggle-heading`:return{pendingHighlight:{type:`row`,index:0},moveSelection:null,colWidths:n.data.colWidths,withHeadings:!n.data.withHeadings,withHeadingColumn:n.data.withHeadingColumn};case`toggle-heading-column`:return{pendingHighlight:{type:`col`,index:0},moveSelection:null,colWidths:n.data.colWidths,withHeadings:n.data.withHeadings,withHeadingColumn:!n.data.withHeadingColumn}}},Rn=10,zn=`data-blok-table-drag-ghost`,Bn=e=>{let t=e.querySelector(`colgroup`);if(t)return Array.from(t.querySelectorAll(`col`)).reduce((e,t)=>{let n=e[e.length-1],r=t.offsetWidth||parseFloat(t.style.width)||0;return[...e,n+r]},[0]);let n=e.querySelector(`[${I}]`);return n?Array.from(n.querySelectorAll(`[${L}]`)).reduce((e,t)=>{let n=e[e.length-1];return[...e,n+t.offsetWidth]},[0]):[0]},Vn=class{constructor(e){var t;this.isDragging=!1,this.dragType=null,this.dragFromIndex=-1,this.dragStartX=0,this.dragStartY=0,this.dropIndicator=null,this.dragOverlayCells=[],this.ghostEl=null,this.ghostOffsetX=0,this.ghostOffsetY=0,this.resolveTracking=null,this.grid=e.grid,this.onAction=e.onAction,this.onDragStateChange=(t=e.onDragStateChange)==null?null:t,this.boundDocPointerMove=this.handleDocPointerMove.bind(this),this.boundDocPointerUp=this.handleDocPointerUp.bind(this),this.boundDocPointerCancel=this.handleDocPointerCancel.bind(this)}beginTracking(e,t,n,r){return this.dragType=e,this.dragFromIndex=t,this.dragStartX=n,this.dragStartY=r,document.addEventListener(`pointermove`,this.boundDocPointerMove),document.addEventListener(`pointerup`,this.boundDocPointerUp),document.addEventListener(`pointercancel`,this.boundDocPointerCancel),new Promise(e=>{this.resolveTracking=e})}cleanup(){var e,t,n;this.grid.style.userSelect=``,document.body.style.cursor=``,this.dragOverlayCells.forEach(e=>{let t=e;t.style.backgroundColor=``,t.style.opacity=``}),this.dragOverlayCells=[],(e=this.dropIndicator)==null||e.remove(),this.dropIndicator=null,(t=this.ghostEl)==null||t.remove(),this.ghostEl=null,document.removeEventListener(`pointermove`,this.boundDocPointerMove),document.removeEventListener(`pointerup`,this.boundDocPointerUp),document.removeEventListener(`pointercancel`,this.boundDocPointerCancel),(n=this.onDragStateChange)==null||n.call(this,!1,null),this.isDragging=!1,this.dragType=null,this.dragFromIndex=-1,this.resolveTracking=null}handleDocPointerMove(e){let t=Math.abs(e.clientX-this.dragStartX),n=Math.abs(e.clientY-this.dragStartY);!this.isDragging&&(t>Rn||n>Rn)&&(this.isDragging=!0,this.startDrag()),this.isDragging&&(this.updateDragIndicator(e),this.updateGhostPosition(e))}handleDocPointerUp(e){if(document.removeEventListener(`pointermove`,this.boundDocPointerMove),document.removeEventListener(`pointerup`,this.boundDocPointerUp),document.removeEventListener(`pointercancel`,this.boundDocPointerCancel),this.isDragging){var t;this.finishDrag(e),(t=this.resolveTracking)==null||t.call(this,!0)}else{var n;(n=this.resolveTracking)==null||n.call(this,!1)}this.cleanup()}handleDocPointerCancel(){var e;(e=this.resolveTracking)==null||e.call(this,this.isDragging),this.cleanup()}startDrag(){var e;this.grid.style.userSelect=`none`,document.body.style.cursor=`grabbing`,(e=this.onDragStateChange)==null||e.call(this,!0,this.dragType),this.highlightSourceCells(),this.createDropIndicator(),this.createGhost()}highlightSourceCells(){let e=this.grid.querySelectorAll(`[${I}]`);if(this.dragType===`row`){this.highlightRowCells(e);return}this.dragType===`col`&&this.highlightColumnCells(e)}highlightRowCells(e){let t=e[this.dragFromIndex];if(!t)return;let n=this.getDragSourceBg();t.querySelectorAll(`[${L}]`).forEach(e=>{let t=e;t.style.backgroundColor=n,t.style.opacity=`0.7`,this.dragOverlayCells.push(t)})}highlightColumnCells(e){let t=this.getDragSourceBg();e.forEach(e=>{let n=e.querySelector(`[${z}="${this.dragFromIndex}"]`);n&&(n.style.backgroundColor=t,n.style.opacity=`0.7`,this.dragOverlayCells.push(n))})}getDragSourceBg(){return getComputedStyle(this.grid).getPropertyValue(`--blok-table-drag-source-bg`).trim()||`#f3f4f6`}isDarkMode(){var e,t,n;let r=document.documentElement.getAttribute(`data-blok-theme`);return r===`dark`?!0:r===`light`||(e=(t=(n=window).matchMedia)==null?void 0:t.call(n,`(prefers-color-scheme: dark)`).matches)==null?!1:e}createDropIndicator(){this.dropIndicator=document.createElement(`div`);let e=this.dropIndicator.style;if(e.position=`absolute`,e.backgroundColor=`#3b82f6`,e.borderRadius=`1.5px`,e.zIndex=`5`,e.pointerEvents=`none`,this.dropIndicator.setAttribute(`contenteditable`,`false`),this.dragType===`row`)e.height=`3px`,e.left=`-1px`,e.right=`0`,e.transition=`top 100ms ease`;else{let t=this.grid.querySelectorAll(`[${I}]`),n=t[t.length-1],r=n?n.offsetTop+n.offsetHeight:0;e.width=`3px`,e.top=`-1px`,e.height=`${r+1}px`,e.transition=`left 100ms ease`}this.grid.appendChild(this.dropIndicator)}updateDragIndicator(e){if(!this.dropIndicator)return;let t=this.grid.getBoundingClientRect();if(this.dragType===`row`){this.updateRowIndicator(e,t);return}this.dragType===`col`&&this.updateColIndicator(e,t)}updateRowIndicator(e,t){if(!this.dropIndicator)return;let n=e.clientY-t.top,r=this.getRowDropIndex(n),i=this.getRowDropTopPx(r);this.dropIndicator.style.top=`${i-1.5}px`}updateColIndicator(e,t){var n;if(!this.dropIndicator)return;let r=e.clientX-t.left,i=this.getColDropIndex(r),a=Bn(this.grid);this.dropIndicator.style.left=`${((n=a[i])==null?0:n)-1.5}px`}finishDrag(e){let t=this.grid.getBoundingClientRect();if(this.dragType===`row`){this.finishRowDrag(e,t);return}this.dragType===`col`&&this.finishColDrag(e,t)}finishRowDrag(e,t){let n=e.clientY-t.top,r=this.getRowDropIndex(n),i=r>this.dragFromIndex?r-1:r;i!==this.dragFromIndex&&this.onAction({type:`move-row`,fromIndex:this.dragFromIndex,toIndex:i})}finishColDrag(e,t){let n=e.clientX-t.left,r=this.getColDropIndex(n),i=r>this.dragFromIndex?r-1:r;i!==this.dragFromIndex&&this.onAction({type:`move-col`,fromIndex:this.dragFromIndex,toIndex:i})}createGhost(){let e=document.createElement(`div`);e.setAttribute(zn,``),e.setAttribute(`contenteditable`,`false`);let t=e.style;t.position=`fixed`,t.pointerEvents=`none`,t.opacity=`0.5`,t.zIndex=`50`,t.borderRadius=`4px`,t.overflow=`hidden`,t.boxShadow=this.isDarkMode()?`0 8px 24px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 255, 255, 0.08)`:`0 4px 12px rgba(0, 0, 0, 0.15)`,this.ghostEl=e;let n=this.getSourceRect();this.dragType===`row`&&this.buildRowGhost(),this.dragType===`col`&&this.buildColumnGhost(),document.body.appendChild(e),n&&(t.left=`${n.left}px`,t.top=`${n.top}px`,this.ghostOffsetX=this.dragStartX-n.left,this.ghostOffsetY=this.dragStartY-n.top)}getSourceRect(){return this.dragType===`row`?this.getRowSourceRect():this.dragType===`col`?this.getColSourceRect():null}getRowSourceRect(){var e;let t=this.grid.querySelectorAll(`[${I}]`)[this.dragFromIndex];return(e=t==null?void 0:t.getBoundingClientRect())==null?null:e}getColSourceRect(){let e=this.grid.querySelectorAll(`[${I}]`),t=e[0],n=e[e.length-1];if(!t||!n)return null;let r=t.querySelector(`[${z}="${this.dragFromIndex}"]`),i=n.querySelector(`[${z}="${this.dragFromIndex}"]`);if(!r||!i)return null;let a=r.getBoundingClientRect(),o=i.getBoundingClientRect();return new DOMRect(a.left,a.top,a.width,o.bottom-a.top)}buildRowGhost(){let e=this.grid.querySelectorAll(`[${I}]`)[this.dragFromIndex];if(!e||!this.ghostEl)return;let t=this.ghostEl.style;t.display=`flex`,t.height=`${e.offsetHeight}px`,e.querySelectorAll(`[${L}]`).forEach(e=>{var t;let n=e,r=n.cloneNode(!0);r.style.width=`${n.offsetWidth}px`,r.style.flexShrink=`0`,r.removeAttribute(`contenteditable`),(t=this.ghostEl)==null||t.appendChild(r)})}buildColumnGhost(){if(!this.ghostEl)return;let e=this.grid.querySelectorAll(`[${I}]`),t=this.ghostEl.style;t.display=`flex`,t.flexDirection=`column`,e.forEach(e=>{var t;let n=e.querySelector(`[${z}="${this.dragFromIndex}"]`);if(!n)return;let r=n.cloneNode(!0);r.style.width=`${n.offsetWidth}px`,r.style.height=`${n.offsetHeight}px`,r.removeAttribute(`contenteditable`),(t=this.ghostEl)==null||t.appendChild(r)})}updateGhostPosition(e){if(!this.ghostEl)return;let t=this.ghostEl.style;this.dragType===`row`&&(t.top=`${e.clientY-this.ghostOffsetY}px`),this.dragType===`col`&&(t.left=`${e.clientX-this.ghostOffsetX}px`)}getRowDropIndex(e){let t=Array.from(this.grid.querySelectorAll(`[${I}]`)),n=t.map(e=>e.offsetTop);if(t.length>0){let e=t[t.length-1];n.push(e.offsetTop+e.offsetHeight)}let r=n.map(t=>Math.abs(e-t)),i=Math.min(...r);return r.indexOf(i)}getRowDropTopPx(e){let t=this.grid.querySelectorAll(`[${I}]`);if(e<t.length)return t[e].offsetTop;if(t.length>0){let e=t[t.length-1];return e.offsetTop+e.offsetHeight}return 0}getColDropIndex(e){let t=Bn(this.grid).map(t=>Math.abs(e-t)),n=Math.min(...t);return t.indexOf(n)}},Hn=[`flex`,`items-center`,`select-none`,`border-none`,`bg-transparent`,`rounded-md`,`p-(--item-padding)`,`text-text-primary`,`mb-px`,`cursor-pointer`,`can-hover:hover:bg-item-hover-bg`],Un=[`flex`,`items-center`,`justify-center`,`w-[26px]`,`h-[26px]`,`mr-2`,`[&_svg]:w-icon`,`[&_svg]:h-icon`],Wn=[`mr-auto`,`truncate`,`text-sm`,`font-medium`,`leading-5`],Gn=[`relative`,`w-[30px]`,`h-[18px]`,`rounded-full`,`transition-colors`,`duration-[180ms]`,`ease-out`,`shrink-0`,`ml-2`],Kn=[`absolute`,`top-[2px]`,`w-[14px]`,`h-[14px]`,`rounded-full`,`bg-white`,`transition-[left]`,`duration-[220ms]`,`[transition-timing-function:cubic-bezier(0.34,1.56,0.64,1)]`],qn=e=>{let{icon:t,label:n,isActive:i,onToggle:a}=e,o={active:i},s=document.createElement(`div`);s.className=r.n(Hn);let c=document.createElement(`div`);c.className=r.n(Un),c.innerHTML=t,s.appendChild(c);let l=document.createElement(`span`);l.className=r.n(Wn),l.textContent=n,s.appendChild(l);let u=document.createElement(`div`);u.className=r.n(Gn);let d=document.createElement(`div`);d.className=r.n(Kn),u.appendChild(d),s.appendChild(u);let f=()=>{u.style.backgroundColor=o.active?`var(--blok-toggle-on-bg)`:`var(--blok-toggle-off-bg)`,d.style.left=o.active?`14px`:`2px`,d.style.backgroundColor=o.active?`var(--blok-toggle-thumb-on-bg)`:``,d.style.boxShadow=o.active?`0 1px 3px rgba(0,0,0,0.35), 0 0 0 1px rgba(0,0,0,0.04)`:`0 1px 3px rgba(0,0,0,0.25), 0 0 0 1px rgba(0,0,0,0.06)`};return f(),s.addEventListener(`click`,e=>{e.stopPropagation(),o.active=!o.active,f(),a(o.active)}),s},Jn=(e,n)=>{let r=e===0?[{type:t.pr.Html,element:qn({icon:t.At,label:n.i18n.t(`tools.table.headerColumn`),isActive:n.isHeadingColumn(),onToggle:()=>{n.onAction({type:`toggle-heading-column`})}})},{type:t.pr.Separator}]:[],i=[{icon:t.zt,title:n.i18n.t(`tools.table.insertColumnLeft`),closeOnActivate:!0,onActivate:()=>{n.onAction({type:`insert-col-left`,index:e})}},{icon:t.Bt,title:n.i18n.t(`tools.table.insertColumnRight`),closeOnActivate:!0,onActivate:()=>{n.onAction({type:`insert-col-right`,index:e})}}],a=n.getColumnCount()>1,o=[{type:t.pr.Separator},{icon:t.Cn,title:n.i18n.t(`tools.table.deleteColumn`),isDestructive:!0,isDisabled:!a,closeOnActivate:!0,onActivate:()=>{n.onAction({type:`delete-col`,index:e})}}];return[...r,...i,...o]},Yn=(e,n)=>{let r=e===0?[{type:t.pr.Html,element:qn({icon:t.jt,label:n.i18n.t(`tools.table.headerRow`),isActive:n.isHeadingRow(),onToggle:()=>{n.onAction({type:`toggle-heading`})}})},{type:t.pr.Separator}]:[],i=[{icon:t.Lt,title:n.i18n.t(`tools.table.insertRowAbove`),closeOnActivate:!0,onActivate:()=>{n.onAction({type:`insert-row-above`,index:e})}},{icon:t.Rt,title:n.i18n.t(`tools.table.insertRowBelow`),closeOnActivate:!0,onActivate:()=>{n.onAction({type:`insert-row-below`,index:e})}}],a=n.getRowCount()>1,o=[{type:t.pr.Separator},{icon:t.Cn,title:n.i18n.t(`tools.table.deleteRow`),isDestructive:!0,isDisabled:!a,closeOnActivate:!0,onActivate:()=>{n.onAction({type:`delete-row`,index:e})}}];return[...r,...i,...o]},Xn=(e,n,r,i,a)=>{a.destroyPopover(),a.clearHideTimeout();let o=e===`col`?r.col[n]:r.row[n];if(!o)return{popover:null,grip:null};let s=new t.C({items:e===`col`?Jn(n,i):Yn(n,i),trigger:o,flippable:!0});return s.on(t.T.Closed,()=>{var e;a.destroyPopover(),a.applyVisibleClasses(o),a.scheduleHideAll(),(e=a.onGripPopoverClose)==null||e.call(a)}),a.hideAllGripsExcept(o),a.applyActiveClasses(o),e===`col`?o.style.height=`16px`:o.style.width=`16px`,{popover:s,grip:o}},Zn=`data-blok-table-grip`,Qn=`data-blok-table-grip-col`,$n=`data-blok-table-grip-row`,er=150,tr=24,nr=4,rr=4,ir=20,ar=[`absolute`,`z-3`,`rounded-sm`,`cursor-grab`,`select-none`,`transition-[opacity,background-color,width,height]`,`duration-150`,`group`,`flex`,`items-center`,`justify-center`,`overflow-hidden`],or=[`bg-gray-300`,`opacity-0`,`pointer-events-none`],sr=[`bg-gray-300`,`opacity-100`,`pointer-events-auto`],cr=[`bg-blue-500`,`text-white`,`opacity-100`,`pointer-events-auto`],lr=class{constructor(e){this.colGrips=[],this.rowGrips=[],this.popoverState={popover:null,grip:null},this.lockedGrip=null,this.hideTimeout=null,this.activeColGripIndex=-1,this.activeRowGripIndex=-1,this.isInsideTable=!1,this.rowResizeObserver=null,this.boundScrollHandler=null,this.grid=e.grid,this.overlay=e.overlay,this.scrollContainer=e.scrollContainer,this.getColumnCount=e.getColumnCount,this.getRowCount=e.getRowCount,this.isHeadingRow=e.isHeadingRow,this.isHeadingColumn=e.isHeadingColumn,this.onAction=e.onAction,this.onGripClick=e.onGripClick,this.onGripPopoverClose=e.onGripPopoverClose,this.i18n=e.i18n,this.drag=new Vn({grid:this.grid,onAction:this.onAction,onDragStateChange:(t,n)=>{var r;this.handleDragStateChange(t,n),(r=e.onDragStateChange)==null||r.call(e,t,n)}}),this.boundMouseOver=this.handleMouseOver.bind(this),this.boundMouseLeave=this.handleMouseLeave.bind(this),this.boundPointerDown=this.handlePointerDown.bind(this),this.boundUnlockGrip=this.handleUnlockGrip.bind(this),this.createGrips(),this.grid.addEventListener(`mouseover`,this.boundMouseOver),this.grid.addEventListener(`mouseleave`,this.boundMouseLeave)}refresh(){let e=this.popoverState.grip?this.detectGripType(this.popoverState.grip):null;if(this.destroyGrips(),this.createGrips(),!e)return;let t=e.type===`col`?this.colGrips[e.index]:this.rowGrips[e.index];t&&(this.popoverState.grip=t,this.hideAllGripsExcept(t),this.applyActiveClasses(t),e.type===`col`?t.style.height=`16px`:t.style.width=`16px`)}setActiveGrip(e,t){let n=e===`col`?this.colGrips[t]:this.rowGrips[t];n&&(this.unlockGrip(),this.clearHideTimeout(),this.hideAllGripsExcept(n),this.applyActiveClasses(n),e===`col`?n.style.height=`16px`:n.style.width=`16px`,this.lockedGrip=n,document.addEventListener(`pointerdown`,this.boundUnlockGrip))}handleUnlockGrip(e){document.removeEventListener(`pointerdown`,this.boundUnlockGrip),this.lockedGrip&&(this.applyIdleClasses(this.lockedGrip),this.lockedGrip=null);let t=e.target instanceof HTMLElement?e.target:null,n=t==null?void 0:t.closest(`[${L}]`);if(n){let e=this.getCellPosition(n);e&&(this.clearHideTimeout(),this.showColGrip(e.col),this.showRowGrip(e.row),this.isInsideTable=!0)}}unlockGrip(){document.removeEventListener(`pointerdown`,this.boundUnlockGrip),this.lockedGrip=null}getVisibleGripIndices(){return this.activeColGripIndex<0&&this.activeRowGripIndex<0?null:{col:this.activeColGripIndex,row:this.activeRowGripIndex}}restoreVisibleGrips(e,t){this.isInsideTable=e>=0||t>=0,e>=0&&this.showColGrip(e),t>=0&&this.showRowGrip(t)}get isPopoverOpen(){return this.popoverState.popover!==null}destroy(){this.destroyPopover(),this.unlockGrip(),this.drag.cleanup(),this.grid.removeEventListener(`mouseover`,this.boundMouseOver),this.grid.removeEventListener(`mouseleave`,this.boundMouseLeave),this.clearHideTimeout(),this.destroyGrips()}createGrips(){var e;let t=this.getColumnCount(),n=this.getRowCount(),r=(e=this.overlay)==null?this.grid:e;Array.from({length:t}).forEach((e,t)=>{let n=this.createGripElement(`col`,t);this.colGrips.push(n),r.appendChild(n)}),Array.from({length:n}).forEach((e,t)=>{let n=this.createGripElement(`row`,t);this.rowGrips.push(n),r.appendChild(n)}),this.positionGrips(),this.observeRowHeights(),this.attachScrollListener()}attachScrollListener(){this.overlay&&this.scrollContainer&&(this.boundScrollHandler=()=>this.positionGrips(),this.scrollContainer.addEventListener(`scroll`,this.boundScrollHandler))}detachScrollListener(){this.boundScrollHandler&&this.scrollContainer&&(this.scrollContainer.removeEventListener(`scroll`,this.boundScrollHandler),this.boundScrollHandler=null)}destroyGrips(){var e;(e=this.rowResizeObserver)==null||e.disconnect(),this.rowResizeObserver=null,this.detachScrollListener(),this.colGrips.forEach(e=>e.remove()),this.rowGrips.forEach(e=>e.remove()),this.colGrips=[],this.rowGrips=[],this.activeColGripIndex=-1,this.activeRowGripIndex=-1,this.isInsideTable=!1}createGripElement(e,t){let n=document.createElement(`div`);n.className=r.n(ar,or),n.setAttribute(Zn,``),n.setAttribute(e===`col`?Qn:$n,String(t)),n.setAttribute(`contenteditable`,`false`);let i=e===`col`?tr:rr,a=e===`col`?nr:ir,o=e===`col`?nr:rr;return n.style.width=`${i}px`,n.style.height=`${a}px`,n.style.transform=`translate(-50%, -50%)`,n.style.outline=`2px solid var(--blok-table-grip-outline, transparent)`,n.appendChild(Gt(e===`col`?`horizontal`:`vertical`)),n.addEventListener(`pointerdown`,this.boundPointerDown),n.addEventListener(`mouseenter`,()=>{this.overlay&&this.clearHideTimeout(),this.isGripInteractionLocked()||Kt(n,e)}),n.addEventListener(`mouseleave`,()=>{this.isGripInteractionLocked()||(qt(n,e,o),this.overlay&&this.scheduleHideAll())}),n}positionGrips(){let e=this.grid.querySelectorAll(`[${I}]`);if(!e[0])return;let t=Bn(this.grid),n=this.overlay&&this.scrollContainer?this.scrollContainer.scrollLeft:0,r=this.overlay&&this.scrollContainer?this.scrollContainer.clientWidth:1/0;this.colGrips.forEach((e,i)=>{if(i+1>=t.length)return;let a=(t[i]+t[i+1])/2-n,o=e.style;o.top=`${-1/2}px`,o.left=`${a}px`,this.overlay&&(o.visibility=a<0||a>r?`hidden`:``)}),this.rowGrips.forEach((t,n)=>{if(n>=e.length)return;let r=e[n],i=this.grid.querySelectorAll(`[${R}="${n}"]`),a=Array.from(i).reduce((e,t)=>{let n=t,r=e===null?0:e.rowSpan||1;return(n.rowSpan||1)>r?n:e},null);if((a===null?1:a.rowSpan||1)>1&&a!==null){var o;let e=((o=this.overlay)==null?this.grid:o).getBoundingClientRect(),n=a.getBoundingClientRect(),r=n.top-e.top+n.height/2,i=t.style;i.left=`${-1/2}px`,i.top=`${r}px`}else{let e=r.offsetTop+r.offsetHeight/2,n=t.style;n.left=`${-1/2}px`,n.top=`${e}px`}})}observeRowHeights(){var e;(e=this.rowResizeObserver)==null||e.disconnect(),this.rowResizeObserver=new ResizeObserver(()=>{this.positionGrips()}),this.grid.querySelectorAll(`[${I}]`).forEach(e=>{var t;(t=this.rowResizeObserver)==null||t.observe(e)})}isGripInteractionLocked(){return this.popoverState.popover!==null||this.lockedGrip!==null}handleMouseOver(e){if(this.isGripInteractionLocked())return;let t=e.target.closest(`[${L}]`);if(!t)return;this.clearHideTimeout();let n=this.getCellPosition(t);n&&(this.showColGrip(n.col),this.showRowGrip(n.row),this.isInsideTable=!0)}handleMouseLeave(){this.isGripInteractionLocked()||this.scheduleHideAll()}getCellPosition(e){let t=e.getAttribute(R),n=e.getAttribute(z);if(t===null||n===null)return null;let r=parseInt(t,10),i=parseInt(n,10);return isNaN(r)||isNaN(i)?null:{row:r,col:i}}setGripsDisplay(e){let t=e?``:`none`;[...this.colGrips,...this.rowGrips].forEach(n=>{let r=n;!e&&n===this.popoverState.grip||(r.style.display=t)})}hideAllGrips(){this.clearHideTimeout(),this.hideColGrip(),this.hideRowGrip(),this.isInsideTable=!1}showColGrip(e){this.activeColGripIndex!==e&&(this.hideColGrip(),this.activeColGripIndex=e,this.applyVisibleClasses(this.colGrips[e]))}hideColGrip(){this.activeColGripIndex>=0&&this.activeColGripIndex<this.colGrips.length&&this.applyIdleClasses(this.colGrips[this.activeColGripIndex]),this.activeColGripIndex=-1}showRowGrip(e){this.activeRowGripIndex!==e&&(this.hideRowGrip(),this.activeRowGripIndex=e,this.applyVisibleClasses(this.rowGrips[e]))}hideRowGrip(){this.activeRowGripIndex>=0&&this.activeRowGripIndex<this.rowGrips.length&&this.applyIdleClasses(this.rowGrips[this.activeRowGripIndex]),this.activeRowGripIndex=-1}applyVisibleClasses(e){let t=e,n=t.hasAttribute(Qn);Ht(t,n?`col`:`row`,n?nr:rr),this.isInsideTable&&(t.style.transition=`none`),t.className=r.n(ar,sr),t.setAttribute(`data-blok-table-grip-visible`,``),this.isInsideTable&&(t.offsetHeight,t.style.transition=``);let i=t.querySelector(`svg`);i&&(i.classList.remove(`text-white`,`opacity-100`),i.classList.add(`text-gray-400`,`opacity-0`))}applyActiveClasses(e){Object.assign(e,{className:r.n(ar,cr)}),e.setAttribute(`data-blok-table-grip-visible`,``);let t=e.querySelector(`svg`);t&&(t.classList.remove(`text-gray-400`,`opacity-0`),t.classList.add(`text-white`,`opacity-100`))}hideAllGripsExcept(e){[...this.colGrips,...this.rowGrips].forEach(t=>{t!==e&&this.applyIdleClasses(t)})}applyIdleClasses(e){let t=e,n=t.hasAttribute(Qn),i=n?`col`:`row`,a=n?nr+12:rr+12;this.isInsideTable&&(t.style.transition=`none`),Ht(t,i,a),t.className=r.n(ar,or),t.removeAttribute(`data-blok-table-grip-visible`);let o=t.querySelector(`svg`);o&&(o.classList.add(`opacity-0`),o.classList.remove(`opacity-100`)),this.isInsideTable&&(t.offsetHeight,t.style.transition=``)}handleDragStateChange(e,t){[...this.colGrips,...this.rowGrips].forEach(t=>{let n=t;n.style.display=e?`none`:``})}scheduleHideAll(){this.hideTimeout=setTimeout(()=>{this.hideColGrip(),this.hideRowGrip(),this.isInsideTable=!1,this.hideTimeout=null},er)}clearHideTimeout(){this.hideTimeout!==null&&(clearTimeout(this.hideTimeout),this.hideTimeout=null)}handlePointerDown(e){let t=e.target.closest(`[${Zn}]`);if(!t)return;e.preventDefault(),e.stopPropagation();let n=this.detectGripType(t);n&&this.drag.beginTracking(n.type,n.index,e.clientX,e.clientY).then(e=>{e||this.openPopover(n.type,n.index)})}detectGripType(e){let t=e.getAttribute(Qn);if(t!==null)return{type:`col`,index:Number(t)};let n=e.getAttribute($n);return n===null?null:{type:`row`,index:Number(n)}}openPopover(e,t){var n,r;this.popoverState=Xn(e,t,{col:this.colGrips,row:this.rowGrips},{getColumnCount:this.getColumnCount,getRowCount:this.getRowCount,isHeadingRow:this.isHeadingRow,isHeadingColumn:this.isHeadingColumn,onAction:this.onAction,i18n:this.i18n},{clearHideTimeout:()=>this.clearHideTimeout(),hideAllGripsExcept:e=>this.hideAllGripsExcept(e),applyActiveClasses:e=>this.applyActiveClasses(e),applyVisibleClasses:e=>this.applyVisibleClasses(e),scheduleHideAll:()=>this.scheduleHideAll(),destroyPopover:()=>this.destroyPopover(),onGripPopoverClose:this.onGripPopoverClose}),(n=this.popoverState.popover)==null||n.show(),(r=this.onGripClick)==null||r.call(this,e,t)}destroyPopover(){if(this.popoverState.popover!==null){let e=this.popoverState.popover;this.popoverState={popover:null,grip:null},e.destroy()}}},ur=`data-blok-table-corner-drag`,dr=5,fr=class{constructor(e){var t;this.dragState=null,this.wrapper=e.wrapper,this.gridEl=e.gridEl,this.getTableSize=e.getTableSize,this.onAddRow=e.onAddRow,this.onAddColumn=e.onAddColumn,this.onRemoveLastRow=e.onRemoveLastRow,this.onRemoveLastColumn=e.onRemoveLastColumn,this.onDragStart=e.onDragStart,this.onDragEnd=e.onDragEnd,this.canRemoveLastRow=e.canRemoveLastRow,this.canRemoveLastColumn=e.canRemoveLastColumn,this.onClickAdd=(t=e.onClickAdd)==null?null:t,this.hitZone=document.createElement(`div`),this.hitZone.setAttribute(ur,``),this.hitZone.setAttribute(`contenteditable`,`false`),this.hitZone.style.position=`absolute`,this.hitZone.style.width=`36px`,this.hitZone.style.height=`36px`,this.hitZone.style.cursor=`nwse-resize`,this.hitZone.style.zIndex=`2`,this.hitZone.style.pointerEvents=`auto`,this.hitZone.style.bottom=`-36px`,this.hitZone.style.right=`-16px`,this.boundMouseEnter=this.handleMouseEnter.bind(this),this.boundMouseLeave=this.handleMouseLeave.bind(this),this.boundPointerDown=this.handlePointerDown.bind(this),this.boundPointerMove=this.handlePointerMove.bind(this),this.boundPointerUp=this.handlePointerUp.bind(this),this.hitZone.addEventListener(`mouseenter`,this.boundMouseEnter),this.hitZone.addEventListener(`mouseleave`,this.boundMouseLeave),this.hitZone.addEventListener(`pointerdown`,this.boundPointerDown),this.wrapper.appendChild(this.hitZone)}updateTooltip(){let e=this.getTableSize();t.sr(this.hitZone,`${e.cols}\u00D7${e.rows}`,{placement:`bottom`})}handleMouseEnter(){this.updateTooltip()}handleMouseLeave(){this.dragState===null&&t.ar()}measureUnitHeight(){let e=this.gridEl.querySelectorAll(`[data-blok-table-row]`),t=e[e.length-1];return(t==null?void 0:t.offsetHeight)||30}measureUnitWidth(){let e=this.gridEl.querySelector(`[data-blok-table-row]`);if(!e)return 100;let t=e.querySelectorAll(`[data-blok-table-cell]`),n=t[t.length-1];return(n==null?void 0:n.offsetWidth)||100}handlePointerDown(e){this.dragState={startX:e.clientX,startY:e.clientY,unitWidth:this.measureUnitWidth(),unitHeight:this.measureUnitHeight(),addedRows:0,addedCols:0,pointerId:e.pointerId,didDrag:!1},this.updateTooltip(),this.hitZone.setPointerCapture(e.pointerId),this.hitZone.addEventListener(`pointermove`,this.boundPointerMove),this.hitZone.addEventListener(`pointerup`,this.boundPointerUp)}handlePointerMove(e){if(this.dragState===null)return;let t=e.clientX-this.dragState.startX,n=e.clientY-this.dragState.startY;if(!this.dragState.didDrag){if(Math.sqrt(t*t+n*n)<dr)return;this.dragState.didDrag=!0,document.body.style.cursor=`nwse-resize`,document.body.style.userSelect=`none`,this.onDragStart()}let{unitHeight:r,unitWidth:i}=this.dragState,a=Math.trunc(n/r),o=Math.trunc(t/i);for(;this.dragState.addedRows<a;)this.onAddRow(),this.dragState.addedRows++;for(;this.dragState.addedRows>a&&this.canRemoveLastRow();)this.onRemoveLastRow(),this.dragState.addedRows--;for(;this.dragState.addedCols<o;)this.onAddColumn(),this.dragState.addedCols++;for(;this.dragState.addedCols>o&&this.canRemoveLastColumn();)this.onRemoveLastColumn(),this.dragState.addedCols--;this.updateTooltip()}handlePointerUp(e){if(this.dragState===null)return;let{didDrag:n,pointerId:r}=this.dragState;this.dragState=null,t.ar(),this.hitZone.releasePointerCapture(r),this.hitZone.removeEventListener(`pointermove`,this.boundPointerMove),this.hitZone.removeEventListener(`pointerup`,this.boundPointerUp),n?(document.body.style.cursor=``,document.body.style.userSelect=``,this.onDragEnd()):this.onClickAdd?this.onClickAdd():(this.onAddRow(),this.onAddColumn())}setDisplay(e){this.hitZone.style.display=e?``:`none`}setInteractive(e){this.hitZone.style.pointerEvents=e?`auto`:`none`}destroy(){var e;this.hitZone.removeEventListener(`mouseenter`,this.boundMouseEnter),this.hitZone.removeEventListener(`mouseleave`,this.boundMouseLeave),this.hitZone.removeEventListener(`pointerdown`,this.boundPointerDown),this.hitZone.removeEventListener(`pointermove`,this.boundPointerMove),this.hitZone.removeEventListener(`pointerup`,this.boundPointerUp),(e=this.dragState)!=null&&e.didDrag&&(document.body.style.cursor=``,document.body.style.userSelect=``),this.dragState=null,t.ar(),this.hitZone.remove()}},pr=`data-blok-table-haze`,mr=`data-blok-table-haze-visible`,hr=1,gr=[`absolute`,`top-0`,`bottom-0`,`w-12`,`pointer-events-none`,`opacity-0`,`transition-opacity`,`duration-150`,`z-1`],_r=[`left-0`,`bg-linear-to-r`,`from-white/80`,`to-transparent`],vr=[`right-5`,`bg-linear-to-l`,`from-white/80`,`to-transparent`],yr=class{constructor(){this.leftHaze=null,this.rightHaze=null,this.scrollContainer=null,this.boundOnScroll=null,this.ticking=!1}init(e,t){this.scrollContainer=t,this.leftHaze=this.createHazeElement(`left`),this.rightHaze=this.createHazeElement(`right`),e.appendChild(this.leftHaze),e.appendChild(this.rightHaze),this.boundOnScroll=()=>{this.ticking||(requestAnimationFrame(()=>{this.syncVisibility(),this.ticking=!1}),this.ticking=!0)},t.addEventListener(`scroll`,this.boundOnScroll,{passive:!0}),this.syncVisibility()}update(){this.syncVisibility()}destroy(){var e,t;this.boundOnScroll&&this.scrollContainer&&this.scrollContainer.removeEventListener(`scroll`,this.boundOnScroll),(e=this.leftHaze)==null||e.remove(),(t=this.rightHaze)==null||t.remove(),this.leftHaze=null,this.rightHaze=null,this.scrollContainer=null,this.boundOnScroll=null,this.ticking=!1}createHazeElement(e){let t=document.createElement(`div`);return t.setAttribute(pr,e),t.setAttribute(`aria-hidden`,`true`),t.classList.add(...gr,...e===`left`?_r:vr),t}syncVisibility(){let e=this.scrollContainer;if(!e)return;let{overflowX:t}=getComputedStyle(e);if(!(t===`auto`||t===`scroll`)){this.setVisible(this.leftHaze,!1),this.setVisible(this.rightHaze,!1);return}let{scrollLeft:n,scrollWidth:r,clientWidth:i}=e,a=r-i;this.setVisible(this.leftHaze,n>hr),this.setVisible(this.rightHaze,a>hr&&n<a-hr)}setVisible(e,t){e&&(t?e.setAttribute(mr,``):e.removeAttribute(mr))}},br=3,xr=3,Sr=[`my-2`,`pr-5`],Cr=[`relative`,`mb-7`,`after:content-[""]`,`after:absolute`,`after:-bottom-10`,`after:left-0`,`after:right-0`,`after:h-10`,`after:pointer-events-none`],wr=class{constructor({data:e,config:n,api:r,readOnly:i,block:a}){this.initialContent=null,this.resize=null,this.addControls=null,this.rowColControls=null,this.cellBlocks=null,this.cellSelection=null,this.cornerDrag=null,this.scrollHaze=null,this.element=null,this.gridElement=null,this.scrollContainer=null,this.gripOverlay=null,this.pendingHighlight=null,this.isNewTable=!1,this.unregisterRestrictedTools=null,this.gridPasteCleanup=null,this.keyboardNavCleanup=null,this.setDataGeneration=0,this.structuralOpDepth=0,this.api=r,this.readOnly=i,this.config=n==null?{}:n;let o=vn(e,this.config);this.initialContent=o.content,this.grid=new At({readOnly:i}),this.model=new En(o),this.blockId=a==null?void 0:a.id,this.config.restrictedTools!==void 0&&(this.unregisterRestrictedTools=t.Pr(this.config.restrictedTools))}runStructuralOp(e,t=!1){this.structuralOpDepth++;try{return e()}finally{this.structuralOpDepth--;let e=this.structuralOpDepth===0;if(e&&t){var n;(n=this.cellBlocks)==null||n.discardDeferredEvents()}if(e&&!t){var r;(r=this.cellBlocks)==null||r.flushDeferredEvents()}}}runTransactedStructuralOp(e,t=!1){if(!this.api.blocks.transact)return this.runStructuralOp(e,t);let n={current:void 0};return this.api.blocks.transact(()=>{n.current=this.runStructuralOp(e,t)}),n.current}teardownSubsystems(){var e,t,n,r,i,a,o,s;(e=this.resize)==null||e.destroy(),this.resize=null,(t=this.addControls)==null||t.destroy(),this.addControls=null,(n=this.cornerDrag)==null||n.destroy(),this.cornerDrag=null,(r=this.rowColControls)==null||r.destroy(),this.rowColControls=null,(i=this.cellSelection)==null||i.destroy(),this.cellSelection=null,(a=this.scrollHaze)==null||a.destroy(),this.scrollHaze=null,(o=this.gridPasteCleanup)==null||o.call(this),this.gridPasteCleanup=null,(s=this.keyboardNavCleanup)==null||s.call(this),this.keyboardNavCleanup=null}rebuildTableBody(){let e=this.gridElement;if(!e)return;let t=e.querySelector(`tbody`);if(!t)return;let n=new Map;t.querySelectorAll(`[data-blok-id]`).forEach(e=>{let t=e.getAttribute(`data-blok-id`);t&&n.set(t,e)});let r=this.grid.createGridFromModel(this.model).querySelector(`tbody`);if(!r)return;let i=this.model.snapshot().content;this.mountBlockHoldersInNewTbody(i,r,n),t.replaceWith(r)}mountBlockHoldersInNewTbody(e,t,n){let r=new Set;e.forEach((e,i)=>{e.forEach((e,a)=>{if(typeof e==`string`||e.mergedInto)return;let o=t.querySelector(`[${R}="${i}"][${z}="${a}"]`);if(!o)return;let s=o.querySelector(`[${V}]`);s&&e.blocks.forEach(e=>{let t=n.get(e);t&&!r.has(e)&&(s.appendChild(t),r.add(e))})})})}modelHasMerges(){return this.model.snapshot().content.some(e=>e.some(e=>{var t,n;return typeof e!=`string`&&(((t=e.colspan)==null?1:t)>1||((n=e.rowspan)==null?1:n)>1)}))}createFlatGrid(){var e,t;let n=((e=this.initialContent)==null?void 0:e.length)||this.config.rows||br,r=((t=this.initialContent)==null?void 0:t.reduce((e,t)=>{var n;return Math.max(e,(n=t==null?void 0:t.length)==null?0:n)},0))||this.config.cols||xr;return this.grid.createGrid(n,r,this.model.colWidths)}initSubsystems(e){this.initResize(e),this.initAddControls(e),this.initCornerDrag(e),this.initRowColControls(e),this.initCellSelection(e),this.initGridPasteListener(e),this.initScrollHaze()}static get toolbox(){return{icon:t._n,titleKey:`tools.table.title`,searchTerms:[`table`,`grid`,`spreadsheet`],searchTermKeys:[`table`,`grid`,`spreadsheet`]}}static get isReadOnlySupported(){return!0}static get enableLineBreaks(){return!0}static get pasteConfig(){return{tags:[`TABLE`,`TR`,{TH:{style:!0}},{TD:{style:!0}}]}}static get sanitize(){return{content:{br:!0,b:!0,i:!0,strong:!0,em:!0,mark:e=>{let n=e.style,r=Array.from({length:n.length},(e,t)=>n.item(t));for(let e of r)t.g.has(e)||n.removeProperty(e);return n.length>0?{style:!0}:{}},a:{href:!0,target:`_blank`,rel:`nofollow`},input:{type:!0,checked:!0}}}}ensureScrollContainer(){var e;if(this.scrollContainer)return this.scrollContainer;let t=document.createElement(`div`);t.setAttribute(`data-blok-table-scroll`,``);let n=this.gridElement;return n&&this.element&&(this.element.insertBefore(t,n),t.appendChild(n)),this.scrollContainer=t,(e=this.addControls)==null||e.attachScrollContainer(t),t}render(){var e,n,i,a;let o=document.createElement(`div`);o.className=r.n(Sr,!this.readOnly&&Cr),o.setAttribute(t.hi.tool,`table`),this.readOnly&&o.setAttribute(`data-blok-table-readonly`,``),this.isNewTable=((e=(n=this.initialContent)==null?void 0:n.length)==null?0:e)===0;let s=((i=(a=this.initialContent)==null?void 0:a.length)==null?0:i)>0,c=s&&this.modelHasMerges(),l=c?this.grid.createGridFromModel(this.model):this.createFlatGrid();if(s&&!c){var u;this.grid.fillGrid(l,(u=this.initialContent)==null?[]:u)}if(this.model.colWidths&&rn(l,this.model.colWidths),this.gridElement=l,this.model.colWidths||!this.readOnly){let e=document.createElement(`div`);e.setAttribute(`data-blok-table-scroll`,``);let t=this.model.colWidths?bn:[];e.classList.add(...t),e.appendChild(l),o.appendChild(e),this.scrollContainer=e}else o.appendChild(l),this.scrollContainer=null;if(!this.readOnly){let e=document.createElement(`div`);e.setAttribute(`data-blok-table-grip-overlay`,``),e.style.position=`absolute`,e.style.inset=`0`,e.style.pointerEvents=`none`,e.style.zIndex=`3`,o.appendChild(e),this.gripOverlay=e}return this.element=o,this.model.withHeadings&&Sn(this.gridElement,this.model.withHeadings),this.model.withHeadingColumn&&W(this.gridElement,this.model.withHeadingColumn),this.readOnly||(this.initCellBlocks(l),this.keyboardNavCleanup=yn(l,this.cellBlocks)),o}rendered(){if(!this.element||this.initialContent===null)return;let e=this.gridElement;if(!e)return;let t=this.initialContent;if(this.initialContent=null,this.readOnly){var r;_n(e,t,this.api,(r=this.blockId)==null?``:r);let n=this.model.snapshot();Cn(e,n.content),wn(e,n.content),this.initScrollHaze();return}if(this.runTransactedStructuralOp(()=>{var r,i;let a=(r=(i=this.cellBlocks)==null?void 0:i.initializeCells(t))==null?t:r,o=this.isNewTable&&a.length===0?Array.from(e.querySelectorAll(`[${I}]`),e=>{let t=e.querySelectorAll(`[${L}]`).length;return Array.from({length:t},()=>({blocks:[]}))}):a;this.model.replaceAll(n.t(n.t({},this.model.snapshot()),{},{content:o})),this.isNewTable&&U(e,this.cellBlocks),this.removeGhostChildren()},!0),this.model.initialColWidth===void 0){var i;let t=(i=this.model.colWidths)==null?H(e):i;this.model.setInitialColWidth(t.length>0?mn(t):void 0)}this.initSubsystems(e);let a=this.model.snapshot();if(Cn(e,a.content),wn(e,a.content),this.isNewTable){var o;(o=this.cellSelection)==null||o.selectRange({minRow:0,maxRow:0,minCol:0,maxCol:0})}}setReadOnly(e){let t=this.element,n=this.gridElement;if(!(!t||!n))if(this.readOnly=e,e){var r,i;this.teardownSubsystems(),(r=this.cellBlocks)==null||r.destroy(),this.cellBlocks=null,this.gripOverlay&&(this.gripOverlay.remove(),this.gripOverlay=null),Cr.forEach(e=>t.classList.remove(e)),t.setAttribute(`data-blok-table-readonly`,``),_n(n,this.model.snapshot().content,this.api,(i=this.blockId)==null?``:i)}else{t.removeAttribute(`data-blok-table-readonly`),Cr.forEach(e=>t.classList.add(e));let e=document.createElement(`div`);e.setAttribute(`data-blok-table-grip-overlay`,``),e.style.position=`absolute`,e.style.inset=`0`,e.style.pointerEvents=`none`,e.style.zIndex=`3`,t.appendChild(e),this.gripOverlay=e,this.initCellBlocks(n),this.keyboardNavCleanup=yn(n,this.cellBlocks),this.initSubsystems(n)}}removeGhostChildren(){let e=this.blockId;if(e===void 0)return;let t=this.api.blocks.getChildren(e).filter(e=>this.model.findCellForBlock(e.id)===null).map(e=>({id:e.id,index:this.api.blocks.getBlockIndex(e.id)})).filter(e=>e.index!==void 0).sort((e,t)=>t.index-e.index);for(let{index:e}of t)this.api.blocks.delete(e)}save(e){var t;let r=this.model.snapshot(),i=(t=this.blockId)==null?``:t,a=this.gridElement;return r.content=r.content.map((e,t)=>e.map((e,r)=>{if(!B(e))return e;let o=e.blocks.filter(e=>{var t,n,r;let a=(t=(n=this.api.blocks).getById)==null?void 0:t.call(n,e);return a!=null&&((r=a.parentId)==null?``:r)===i});if(o.length===0&&a){let o=a.querySelector(`[${R}="${t}"][${z}="${r}"]`),s=o==null?void 0:o.querySelector(`[${V}]`),c=s?Array.from(s.querySelectorAll(`[data-blok-id]`)).map(e=>{var t;return(t=e.getAttribute(`data-blok-id`))==null?``:t}).filter(e=>{var t,n,r;if(!e)return!1;let a=(t=(n=this.api.blocks).getById)==null?void 0:t.call(n,e);return a!=null&&((r=a.parentId)==null?``:r)===i}):[];if(c.length>0)return n.t(n.t({},e),{},{blocks:c})}return n.t(n.t({},e),{},{blocks:o})})),r}validate(e){return e.content.length>0}setData(e){var t,r,i,a,o;this.setDataGeneration++;let s=this.setDataGeneration,c=vn(n.t(n.t({},this.model.snapshot()),e),this.config);this.initialContent=c.content,this.model.replaceAll(c),this.api.blocks.isSyncingFromYjs||this.runStructuralOp(()=>{var e;(e=this.cellBlocks)==null||e.deleteAllBlocks()},!0),(t=this.cellBlocks)==null||t.destroy();let l=this.element;if(!(l!=null&&l.parentNode)||s!==this.setDataGeneration)return;let u=(r=(i=this.cellSelection)==null?void 0:i.getSelectedRange())==null?null:r,d=(a=(o=this.rowColControls)==null?void 0:o.getVisibleGripIndices())==null?null:a;this.teardownSubsystems();let f=this.render();l.parentNode.replaceChild(f,l);let p=this.gridElement;if(!p)return;if(this.readOnly){let e=this.model.snapshot();Cn(p,e.content),wn(p,e.content);return}if(s!==this.setDataGeneration)return;let m=this.api.blocks.isSyncingFromYjs;if(this.runStructuralOp(()=>{var e,t,r,i;let a=(e=(t=(r=this.cellBlocks)==null?void 0:r.initializeCells((i=this.initialContent)==null?[]:i))==null?this.initialContent:t)==null?[]:e;if(s===this.setDataGeneration){if(this.api.blocks.isSyncingFromYjs&&a.length===0&&p){let e=Array.from(p.querySelectorAll(`[${I}]`),e=>{let t=e.querySelectorAll(`[${L}]`).length;return Array.from({length:t},()=>({blocks:[]}))});this.model.replaceAll(n.t(n.t({},this.model.snapshot()),{},{content:e}))}else this.model.replaceAll(n.t(n.t({},this.model.snapshot()),{},{content:a}));this.initialContent=null}},!0),s!==this.setDataGeneration)return;this.initSubsystems(p),u!==null&&this.cellSelection!==null&&this.cellSelection.selectRange(u),d!==null&&this.rowColControls!==null&&this.rowColControls.restoreVisibleGrips(d.col,d.row);let h=this.model.snapshot();if(Cn(p,h.content),wn(p,h.content),m){var g;(g=this.cellBlocks)==null||g.reclaimReferencedBlocks(),Promise.resolve().then(()=>{var e;s===this.setDataGeneration&&((e=this.cellBlocks)==null||e.reclaimReferencedBlocks())})}}onPaste(e){var r,i;let a=e.detail.data,o=a.querySelectorAll(`tr`),s=[],c=[];o.forEach(e=>{let n=e.querySelectorAll(`td, th`),r=[],i=[];n.forEach(e=>{var n;r.push(e.innerHTML);let a=(n=e.getAttribute(`style`))==null?``:n,o={},s=/background-color\s*:\s*([^;]+)/i.exec(a);s!=null&&s[1]&&(o.color=t.Ln(s[1].trim(),`bg`));let c=RegExp(`(?<![a-z-])color\\s*:\\s*([^;]+)`,`i`).exec(a);c!=null&&c[1]&&!t.y(c[1].trim())&&(o.textColor=t.Ln(c[1].trim(),`text`)),i.push(o)}),r.length>0&&(s.push(r),c.push(i))});let l=a.querySelector(`thead`)!==null,u=((r=o[0])==null?void 0:r.querySelector(`th`))!==null,d=l||u;this.initialContent=s,this.model.setWithHeadings(d),this.model.setWithHeadingColumn(!1),this.model.setColWidths(void 0),this.runStructuralOp(()=>{var e;(e=this.cellBlocks)==null||e.deleteAllBlocks()},!0),(i=this.cellBlocks)==null||i.destroy(),this.teardownSubsystems();let f=this.element;if(!(f!=null&&f.parentNode))return;let p=this.render();f.parentNode.replaceChild(p,f);let m=this.gridElement;if(!this.readOnly&&m){this.runStructuralOp(()=>{var e,t,r,i;let a=(e=(t=(r=this.cellBlocks)==null?void 0:r.initializeCells((i=this.initialContent)==null?[]:i))==null?this.initialContent:t)==null?[]:e;this.model.replaceAll(n.t(n.t({},this.model.snapshot()),{},{content:a})),this.initialContent=null,c.forEach((e,t)=>{e.forEach((e,n)=>{e.color!==void 0&&this.model.setCellColor(t,n,e.color),e.textColor!==void 0&&this.model.setCellTextColor(t,n,e.textColor)})})},!0),this.initSubsystems(m);let e=this.model.snapshot();Cn(m,e.content),wn(m,e.content)}}destroy(){var e,t;if((e=this.unregisterRestrictedTools)==null||e.call(this),this.unregisterRestrictedTools=null,!this.api.blocks.isSyncingFromYjs){var n;(n=this.cellBlocks)==null||n.deleteAllBlocks()}this.teardownSubsystems(),(t=this.cellBlocks)==null||t.destroy(),this.cellBlocks=null,this.gridElement=null,this.scrollContainer=null,this.element=null}deleteRowWithCleanup(e){let t=this.gridElement;t&&this.runTransactedStructuralOp(()=>{var n;let{blocksToDelete:r}=this.model.deleteRow(e);(n=this.cellBlocks)==null||n.deleteBlocks(r),this.grid.deleteRow(t,e)})}deleteColumnWithCleanup(e){let t=this.gridElement;t&&this.runTransactedStructuralOp(()=>{var n;let{blocksToDelete:r}=this.model.deleteColumn(e);(n=this.cellBlocks)==null||n.deleteBlocks(r),this.grid.deleteColumn(t,e)})}getBlockIdsInRow(e){return hn(this.element,this.cellBlocks,e)}getBlockIdsInColumn(e){return gn(this.element,this.cellBlocks,e)}initAddControls(e){var t;if((t=this.addControls)==null||t.destroy(),!this.element)return;let n={addedCols:0};this.addControls=new Et({wrapper:this.element,grid:e,i18n:this.api.i18n,getTableSize:()=>({rows:this.model.rows,cols:this.model.cols}),getNewColumnWidth:()=>{var t;let n=(t=this.model.colWidths)==null?H(e):t;return this.model.initialColWidth===void 0?pn(n):Math.round(this.model.initialColWidth/2*100)/100},onAddRow:()=>{this.runTransactedStructuralOp(()=>{var t,n;this.grid.addRow(e),this.model.addRow(),U(e,this.cellBlocks),Sn(this.gridElement,this.model.withHeadings),W(this.gridElement,this.model.withHeadingColumn),this.initResize(e),(t=this.addControls)==null||t.syncRowButtonWidth(),(n=this.rowColControls)==null||n.refresh()})},onAddColumn:()=>{this.runTransactedStructuralOp(()=>{var t,n,r;let i=(t=this.model.colWidths)==null?H(e):t,a=this.model.initialColWidth===void 0?pn(i):Math.round(this.model.initialColWidth/2*100)/100;this.grid.addColumn(e,void 0,i,a),this.model.addColumn(void 0,a),this.model.setColWidths([...i,a]),U(e,this.cellBlocks),W(this.gridElement,this.model.withHeadingColumn),this.initResize(e),(n=this.rowColControls)==null||n.refresh(),this.scrollContainer&&(this.scrollContainer.scrollLeft=this.scrollContainer.scrollWidth),(r=this.addControls)==null||r.syncRowButtonWidth()})},onDragStart:()=>{var e,t;this.resize&&(this.resize.enabled=!1),(e=this.rowColControls)==null||e.hideAllGrips(),(t=this.rowColControls)==null||t.setGripsDisplay(!1)},onDragAddRow:()=>{this.runTransactedStructuralOp(()=>{this.grid.addRow(e),this.model.addRow(),U(e,this.cellBlocks),Sn(this.gridElement,this.model.withHeadings),W(this.gridElement,this.model.withHeadingColumn)})},onDragRemoveRow:()=>{this.runTransactedStructuralOp(()=>{let t=this.grid.getRowCount(e);if(t>1&&sn(e,t-1)){var n;let{blocksToDelete:r}=this.model.deleteRow(t-1);(n=this.cellBlocks)==null||n.deleteBlocks(r),this.grid.deleteRow(e,t-1)}})},onDragAddCol:()=>{this.runTransactedStructuralOp(()=>{var t;let r=(t=this.model.colWidths)==null?H(e):t,i=this.model.initialColWidth===void 0?pn(r):Math.round(this.model.initialColWidth/2*100)/100,a=[...r,i];this.grid.addColumn(e,void 0,r,i),this.model.addColumn(void 0,i),this.model.setColWidths(a),rn(e,a),U(e,this.cellBlocks),W(this.gridElement,this.model.withHeadingColumn),this.initResize(e),n.addedCols++,this.scrollContainer&&(this.scrollContainer.scrollLeft=this.scrollContainer.scrollWidth)})},onDragRemoveCol:()=>{this.runTransactedStructuralOp(()=>{var t;let r=this.grid.getColumnCount(e);if(r<=1||!cn(e,r-1))return;let{blocksToDelete:i}=this.model.deleteColumn(r-1);(t=this.cellBlocks)==null||t.deleteBlocks(i),this.grid.deleteColumn(e,r-1);let a=this.model.colWidths;a&&rn(e,a),this.initResize(e),n.addedCols--})},onDragEnd:()=>{var t,r;this.initResize(e),(t=this.rowColControls)==null||t.refresh(),this.scrollContainer&&(this.scrollContainer.scrollLeft=n.addedCols>0?this.scrollContainer.scrollWidth:0),(r=this.addControls)==null||r.syncRowButtonWidth(),n.addedCols=0}}),this.scrollContainer&&this.addControls.attachScrollContainer(this.scrollContainer)}initCornerDrag(e){var t;(t=this.cornerDrag)==null||t.destroy(),this.element&&(this.cornerDrag=new fr({wrapper:this.element,gridEl:e,onAddRow:()=>{this.runStructuralOp(()=>{this.grid.addRow(e),this.model.addRow(),U(e,this.cellBlocks),Sn(this.gridElement,this.model.withHeadings),W(this.gridElement,this.model.withHeadingColumn)})},onAddColumn:()=>{this.runStructuralOp(()=>{var t;let n=(t=this.model.colWidths)==null?H(e):t,r=this.model.initialColWidth===void 0?pn(n):Math.round(this.model.initialColWidth/2*100)/100,i=[...n,r];this.grid.addColumn(e,void 0,n,r),this.model.addColumn(void 0,r),this.model.setColWidths(i),rn(e,i),xn(this.ensureScrollContainer()),U(e,this.cellBlocks),W(this.gridElement,this.model.withHeadingColumn)})},onRemoveLastRow:()=>{this.runStructuralOp(()=>{var t;let n=this.grid.getRowCount(e);if(n<=1)return;let{blocksToDelete:r}=this.model.deleteRow(n-1);(t=this.cellBlocks)==null||t.deleteBlocks(r),this.grid.deleteRow(e,n-1)})},onRemoveLastColumn:()=>{this.runStructuralOp(()=>{var t;let n=this.grid.getColumnCount(e);if(n<=1)return;let{blocksToDelete:r}=this.model.deleteColumn(n-1);(t=this.cellBlocks)==null||t.deleteBlocks(r),this.grid.deleteColumn(e,n-1);let i=this.model.colWidths;i&&rn(e,i)})},onDragStart:()=>{var e,t,n;this.resize&&(this.resize.enabled=!1),(e=this.rowColControls)==null||e.hideAllGrips(),(t=this.rowColControls)==null||t.setGripsDisplay(!1),(n=this.addControls)==null||n.setDisplay(!1)},onDragEnd:()=>{var t,n,r;this.initResize(e),(t=this.rowColControls)==null||t.refresh(),(n=this.addControls)==null||n.setDisplay(!0),(r=this.addControls)==null||r.syncRowButtonWidth()},getTableSize:()=>({rows:this.model.rows,cols:this.model.cols}),canRemoveLastRow:()=>this.model.rows>1&&sn(e,this.model.rows-1),canRemoveLastColumn:()=>this.model.cols>1&&cn(e,this.model.cols-1),onClickAdd:()=>{this.runTransactedStructuralOp(()=>{var t,n,r;this.grid.addRow(e),this.model.addRow(),U(e,this.cellBlocks),Sn(this.gridElement,this.model.withHeadings),W(this.gridElement,this.model.withHeadingColumn);let i=(t=this.model.colWidths)==null?H(e):t,a=this.model.initialColWidth===void 0?pn(i):Math.round(this.model.initialColWidth/2*100)/100,o=[...i,a];this.grid.addColumn(e,void 0,i,a),this.model.addColumn(void 0,a),this.model.setColWidths(o),rn(e,o),U(e,this.cellBlocks),W(this.gridElement,this.model.withHeadingColumn),this.initResize(e),(n=this.rowColControls)==null||n.refresh(),(r=this.addControls)==null||r.syncRowButtonWidth()})}}))}initRowColControls(e){var t,n,r;(t=this.rowColControls)==null||t.destroy(),this.element&&(this.rowColControls=new lr({grid:e,overlay:(n=this.gripOverlay)==null?void 0:n,scrollContainer:(r=this.scrollContainer)==null?void 0:r,getColumnCount:()=>this.grid.getColumnCount(e),getRowCount:()=>this.grid.getRowCount(e),isHeadingRow:()=>this.model.withHeadings,isHeadingColumn:()=>this.model.withHeadingColumn,i18n:this.api.i18n,onAction:t=>this.handleRowColAction(e,t),onDragStateChange:e=>{var t,n;this.resize&&(this.resize.enabled=!e),(t=this.addControls)==null||t.setDisplay(!e),(n=this.cornerDrag)==null||n.setDisplay(!e),e&&this.api.toolbar.close({setExplicitlyClosed:!1})},onGripClick:(e,t)=>{if(e===`row`){var n;(n=this.cellSelection)==null||n.selectRow(t)}else{var r;(r=this.cellSelection)==null||r.selectColumn(t)}},onGripPopoverClose:()=>{if(this.pendingHighlight){var e;let{type:t,index:n}=this.pendingHighlight;this.pendingHighlight=null,(e=this.rowColControls)==null||e.setActiveGrip(t,n),requestAnimationFrame(()=>{if(t===`row`){var e;(e=this.cellSelection)==null||e.selectRow(n)}else{var r;(r=this.cellSelection)==null||r.selectColumn(n)}})}else{var t;(t=this.cellSelection)==null||t.clearActiveSelection()}}}))}handleRowColAction(e,t){let n=this.setDataGeneration;this.runTransactedStructuralOp(()=>{var r,i;if(n!==this.setDataGeneration||this.gridElement!==e)return;let a=this.model.colWidths,{blocksToDelete:o}=this.syncModelForAction(t),s=Ln(e,t,{grid:this.grid,data:{colWidths:a,withHeadings:this.model.withHeadings,withHeadingColumn:this.model.withHeadingColumn,initialColWidth:this.model.initialColWidth},cellBlocks:this.cellBlocks,blocksToDelete:o});if(n!==this.setDataGeneration||this.gridElement!==e)return;if(this.model.setColWidths(s.colWidths),this.model.setWithHeadings(s.withHeadings),this.model.setWithHeadingColumn(s.withHeadingColumn),this.pendingHighlight=s.pendingHighlight,Sn(this.gridElement,this.model.withHeadings),W(this.gridElement,this.model.withHeadingColumn),this.initResize(e),(r=this.addControls)==null||r.syncRowButtonWidth(),!(t.type===`toggle-heading`||t.type===`toggle-heading-column`)){var c;(c=this.rowColControls)==null||c.refresh()}if(!s.moveSelection)return;let{type:l,index:u}=s.moveSelection;if(l===`row`){var d;(d=this.cellSelection)==null||d.selectRow(u)}else{var f;(f=this.cellSelection)==null||f.selectColumn(u)}(i=this.rowColControls)==null||i.setActiveGrip(l,u)})}syncModelForAction(e){switch(e.type){case`insert-row-above`:this.model.addRow(e.index);break;case`insert-row-below`:this.model.addRow(e.index+1);break;case`insert-col-left`:this.model.addColumn(e.index);break;case`insert-col-right`:this.model.addColumn(e.index+1);break;case`move-row`:this.model.moveRow(e.fromIndex,e.toIndex);break;case`move-col`:this.model.moveColumn(e.fromIndex,e.toIndex);break;case`delete-row`:return this.model.deleteRow(e.index);case`delete-col`:return this.model.deleteColumn(e.index);case`toggle-heading`:case`toggle-heading-column`:break}return{}}initResize(e){var t,n;(t=this.resize)==null||t.destroy();let r=this.model.colWidths===void 0,i=(n=this.model.colWidths)==null?H(e):n;r||xn(this.ensureScrollContainer()),this.resize=new An(e,i,e=>{var t,n,r;this.model.setColWidths(e),xn(this.ensureScrollContainer()),(t=this.rowColControls)==null||t.positionGrips(),(n=this.addControls)==null||n.syncRowButtonWidth(),(r=this.scrollHaze)==null||r.update()},()=>{var e;(e=this.rowColControls)==null||e.hideAllGrips()},()=>{var e,t;(e=this.addControls)==null||e.syncRowButtonWidth(),(t=this.scrollHaze)==null||t.update()},r)}initCellBlocks(e){var t;this.cellBlocks=new jt({api:this.api,gridElement:e,tableBlockId:(t=this.blockId)==null?``:t,model:this.model,isStructuralOpActive:()=>this.structuralOpDepth>0})}handleCellCopy(e,n){let r=this.collectCellBlockData(e);if(r.length===0)return;let i=t.S(r);n.setData(`text/html`,t._(i)),n.setData(`text/plain`,t.v(i))}handleCellCopyViaButton(e){let n=this.collectCellBlockData(e);if(n.length===0)return;let r=t.S(n),i=t._(r),a=t.v(r),o=new Blob([i],{type:`text/html`}),s=new Blob([a],{type:`text/plain`});navigator.clipboard.write([new ClipboardItem({"text/html":o,"text/plain":s})])}handleCellColorChange(e,t,n){let r=this.gridElement;r&&this.runTransactedStructuralOp(()=>{for(let i of e){let e=an(r,i);e&&(n===`backgroundColor`?(this.model.setCellColor(e.row,e.col,t==null?void 0:t),i.style.backgroundColor=t==null?``:t):(this.model.setCellTextColor(e.row,e.col,t==null?void 0:t),i.style.color=t==null?``:t))}})}handleCellPlacementChange(e,t){let n=this.gridElement;n&&this.runTransactedStructuralOp(()=>{for(let r of e){let e=an(n,r);if(!e)continue;this.model.setCellPlacement(e.row,e.col,t===`top-left`?void 0:t);let i=r.querySelector(`[${V}]`);i&&(t===`top-left`?i.removeAttribute(`data-blok-cell-placement`):i.setAttribute(`data-blok-cell-placement`,t))}})}collectCellBlockData(e){return this.gridElement?e.map(e=>{var t,r,i;let a=parseInt((t=e.getAttribute(`data-blok-table-cell-row`))==null?`0`:t,10),o=parseInt((r=e.getAttribute(`data-blok-table-cell-col`))==null?`0`:r,10),s=e.querySelector(`[${V}]`),c=[];if(!s)return{row:a,col:o,blocks:c};s.querySelectorAll(`[data-blok-id]`).forEach(e=>{let t=e.getAttribute(`data-blok-id`);if(!t)return;let r=this.api.blocks.getBlockIndex(t);if(r===void 0)return;let i=this.api.blocks.getBlockByIndex(r);i&&c.push(n.t({tool:i.name,data:i.preservedData},Object.keys(i.preservedTunes).length>0?{tunes:i.preservedTunes}:{}))});let l=c.length===0?((i=s.innerHTML)==null?``:i).trim():``;c.length===0&&l.length>0&&c.push({tool:`paragraph`,data:{text:l}});let u=this.model.getCellColor(a,o),d=this.model.getCellTextColor(a,o);return n.t(n.t({row:a,col:o,blocks:c},u===void 0?{}:{color:u}),d===void 0?{}:{textColor:d})}):[]}initCellSelection(e){var t;(t=this.cellSelection)==null||t.destroy();let n=this.api.rectangleSelection;this.cellSelection=new nn({grid:e,rectangleSelection:n,i18n:this.api.i18n,isPopoverOpen:()=>{var e,t;return(e=(t=this.rowColControls)==null?void 0:t.isPopoverOpen)==null?!1:e},onPointerDragActiveChange:e=>{var t,n;(t=(n=this.api.blocks).setPointerDragActive)==null||t.call(n,e)},onSelectionActiveChange:e=>{var t,n,r;this.resize&&(this.resize.enabled=!e),(t=this.addControls)==null||t.setInteractive(!e),(n=this.cornerDrag)==null||n.setInteractive(!e),(r=this.rowColControls)==null||r.setGripsDisplay(!e)},onSelectionRangeChange:()=>{var e;(e=this.rowColControls)==null||e.setGripsDisplay(!0)},onClearContent:e=>{let t=this.cellBlocks;t&&this.runTransactedStructuralOp(()=>{let n=t.getBlockIdsFromCells(e);t.deleteBlocks(n);let r=this.gridElement;if(r)for(let t of e){let e=an(r,t);e&&(this.model.setCellColor(e.row,e.col,void 0),this.model.setCellTextColor(e.row,e.col,void 0),t.style.backgroundColor=``,t.style.color=``)}})},onCopy:(e,t)=>{this.handleCellCopy(e,t)},onCut:(e,t)=>{this.handleCellCopy(e,t)},onCopyViaButton:e=>{this.handleCellCopyViaButton(e)},onColorChange:(e,t,n)=>{this.handleCellColorChange(e,t,n)},onPlacementChange:(e,t)=>{this.handleCellPlacementChange(e,t)},getCellPlacement:(e,t)=>this.model.getCellPlacement(e,t),canMergeCells:e=>this.model.canMergeCells(e),onMergeCells:e=>{this.runTransactedStructuralOp(()=>{this.model.mergeCells(e),this.rebuildTableBody()})},isMergedCell:(e,t)=>this.model.isMergedCell(e,t),onSplitCell:(e,t)=>{this.runTransactedStructuralOp(()=>{this.model.splitCell(e,t),this.rebuildTableBody()})},getCellSpan:(e,t)=>this.model.getCellSpan(e,t)})}initScrollHaze(){var e;(e=this.scrollHaze)==null||e.destroy(),!(!this.element||!this.scrollContainer)&&(this.scrollHaze=new yr,this.scrollHaze.init(this.element,this.scrollContainer))}initGridPasteListener(e){let t=t=>{this.handleGridPaste(t,e)};e.addEventListener(`paste`,t),this.gridPasteCleanup=()=>{e.removeEventListener(`paste`,t)}}handleGridPaste(e,n){var r,i;if(this.readOnly||!e.clipboardData||e.defaultPrevented)return;let a=e.clipboardData.getData(`text/html`),o=t.b(a),s=o===null?t.x(a):null,c=o==null?s:o;if(!c||s!==null&&new DOMParser().parseFromString(a,`text/html`).querySelectorAll(`table`).length>1)return;let l=document.activeElement;if(!l)return;let u=l.closest(`[${L}]`);if(!u||!n.contains(u)||!u.closest(`[data-blok-table-row]`))return;if(c.rows===1&&c.cols===1){e.preventDefault(),e.stopPropagation(),this.insertSingleCellPayloadInline(c.cells[0][0]);return}e.preventDefault(),e.stopPropagation();let d=parseInt((r=u.getAttribute(`data-blok-table-cell-row`))==null?`0`:r,10),f=parseInt((i=u.getAttribute(`data-blok-table-cell-col`))==null?`0`:i,10);this.pastePayloadIntoCells(n,c,d,f)}insertSingleCellPayloadInline(e){let t=e.blocks.map(e=>typeof e.data.text==`string`?e.data.text:``).filter(Boolean).join(`<br>`);if(!t)return;let n=window.getSelection();if(!n||n.rangeCount===0)return;let r=n.getRangeAt(0);r.collapsed||r.deleteContents();let i=document.createDocumentFragment(),a=document.createElement(`div`);a.innerHTML=t,Array.from(a.childNodes).forEach(e=>i.appendChild(e)),i.childNodes.length===0&&i.appendChild(new Text);let o=i.lastChild;r.insertNode(i);let s=document.createRange(),c=o.nodeType===Node.TEXT_NODE?o:o.firstChild;c!==null&&c.textContent!==null&&s.setStart(c,c.textContent.length),n.removeAllRanges(),n.addRange(s)}pastePayloadIntoCells(e,t,n,r){this.runTransactedStructuralOp(()=>{var i,a;this.expandGridForPaste(e,n+t.rows,r+t.cols);let o=e.querySelectorAll(`[${I}]`);Array.from({length:t.rows},(e,t)=>t).forEach(e=>{let i=o[n+e];if(!i)return;let a=i.querySelectorAll(`[${L}]`);Array.from({length:t.cols},(e,t)=>t).forEach(i=>{let o=a[r+i];if(o){var s,c,l,u;let a=t.cells[e][i];this.pasteCellPayload(o,a);let d=(s=(c=this.cellBlocks)==null?void 0:c.getBlockIdsFromCells([o]))==null?[]:s;this.model.setCellBlocks(n+e,r+i,d);let f=n+e,p=r+i;this.model.setCellColor(f,p,a.color),o.style.backgroundColor=(l=a.color)==null?``:l,this.model.setCellTextColor(f,p,a.textColor),o.style.color=(u=a.textColor)==null?``:u}})}),this.initResize(e),(i=this.addControls)==null||i.syncRowButtonWidth(),(a=this.rowColControls)==null||a.refresh()});let i=e.querySelectorAll(`[${I}]`)[n+t.rows-1],a=i==null?void 0:i.querySelectorAll(`[${L}]`)[r+t.cols-1];if(!a||!this.cellBlocks||!this.api.caret)return;let o=this.cellBlocks.getBlockIdsFromCells([a]),s=o[o.length-1];s!==void 0&&this.api.caret.setToBlock(s,`end`)}expandGridForPaste(e,t,n){let r=this.grid.getRowCount(e),i=this.grid.getColumnCount(e);Array.from({length:Math.max(0,t-r)}).forEach(()=>{this.grid.addRow(e),this.model.addRow(),U(e,this.cellBlocks),Sn(this.gridElement,this.model.withHeadings),W(this.gridElement,this.model.withHeadingColumn)}),Array.from({length:Math.max(0,n-i)}).forEach(()=>{var t;let n=(t=this.model.colWidths)==null?H(e):t,r=this.model.initialColWidth===void 0?pn(n):Math.round(this.model.initialColWidth/2*100)/100;this.grid.addColumn(e,void 0,n,r),this.model.addColumn(void 0,r),this.model.setColWidths([...n,r]),U(e,this.cellBlocks),W(this.gridElement,this.model.withHeadingColumn)})}pasteCellPayload(e,t){if(this.cellBlocks){let t=this.cellBlocks.getBlockIdsFromCells([e]);this.cellBlocks.deleteBlocks(t)}let n=e.querySelector(`[${V}]`);if(n){if(t.blocks.length===0){var r;(r=this.cellBlocks)==null||r.ensureCellHasBlock(e);return}for(let e of t.blocks){var i;let t=this.api.blocks.insert(e.tool,e.data,{},this.api.blocks.getBlocksCount(),!1);n.appendChild(t.holder),this.api.blocks.setBlockParent(t.id,(i=this.blockId)==null?``:i)}}}},Tr=e=>{let t=document.createElement(`div`);t.innerHTML=e.trim();let n=document.createDocumentFragment();return n.append(...Array.from(t.childNodes)),n},Er=(e,n,r,i)=>{if(!n)return e;let a=r();return{text:a?t.Vr(a.innerHTML):e.text,isOpen:i}},Dr=(e,t)=>{let{data:n,getContentElement:r}=e;n.text+=t.text;let i=r();if(i&&t.text){let n=e.parseHTML(t.text);i.appendChild(n),i.normalize()}},Or=(e,t,r)=>{let i=r();if(!i)return{newData:e,inPlace:!1};let a=n.t(n.t({},e),t);return typeof t.text==`string`&&(i.innerHTML=t.text),{newData:a,inPlace:!0}},kr=class e{constructor({data:e,config:t,api:n,readOnly:r,block:i}){var a;this._element=null,this._contentElement=null,this._arrowElement=null,this._bodyPlaceholderElement=null,this._childContainerElement=null,this.handleChildContainerInput=()=>{S(this._element,this._childContainerElement)},this.handleBlockChanged=e=>{this.isBlockChangedPayload(e)&&(e.event.type===`block-removed`||e.event.type===`block-added`)&&this.updateBodyPlaceholderVisibility()},this.api=n,this.readOnly=r,this._settings=t||{},this._data=this.normalizeData(e),this._isOpen=(a=this._data.isOpen)==null?!0:a,i&&(this.blockId=i.id),r||this.api.events.on(`block changed`,this.handleBlockChanged)}normalizeData(e){if(typeof e==`object`&&e&&`text`in e){let t={text:typeof e.text==`string`?e.text:``};return typeof e.isOpen==`boolean`&&(t.isOpen=e.isOpen),t}if(typeof e==`object`&&e&&`title`in e){let t=e,n={text:typeof t.title==`string`?t.title:``};return typeof t.isExpanded==`boolean`&&(n.isOpen=t.isExpanded),n}return{text:``}}get placeholder(){if(this._settings.placeholder)return this._settings.placeholder;let e=this.api.i18n.t(t.l);return e===`tools.toggle.placeholder`?`Toggle`:e}render(){let e=C({data:this._data,readOnly:this.readOnly,isOpen:this._isOpen,placeholder:this.placeholder,keydownHandler:this.readOnly?null:this.handleKeyDown.bind(this),onArrowClick:()=>this.toggleOpen(),onBodyPlaceholderClick:this.readOnly?null:()=>this.handleBodyPlaceholderClick(),bodyPlaceholderText:this.api.i18n.t(t.o),ariaLabels:{collapse:this.api.i18n.t(t.t),expand:this.api.i18n.t(t.n)}});return this._element=e.wrapper,this._contentElement=e.contentElement,this._arrowElement=e.arrowElement,this._bodyPlaceholderElement=e.bodyPlaceholderElement,this._childContainerElement=e.childContainerElement,this._childContainerElement.addEventListener(`input`,this.handleChildContainerInput),this._element}rendered(){this.updateChildrenVisibility(),this.updateBodyPlaceholderVisibility()}save(){return Er(this._data,this._element,this.getContentElement.bind(this),this._isOpen)}validate(e){return!0}merge(e){Dr({data:this._data,getContentElement:this.getContentElement.bind(this),parseHTML:Tr},e)}onPaste(n){let r=n.detail;if(!(`data`in r))return;let i=r.data,a=i.querySelector(`summary`),o=t.ur(a===null?i.innerHTML:a.innerHTML,e.sanitize.text);this._data={text:o};let s=this.getContentElement();s!==null&&(s.innerHTML=o)}setData(e){let n=Or(this._data,e,this.getContentElement.bind(this));return this._data=n.newData,typeof this._data.isOpen==`boolean`&&(this._isOpen=this._data.isOpen),this._arrowElement&&this._element&&w(this._arrowElement,this._element,this._isOpen,{collapse:this.api.i18n.t(t.t),expand:this.api.i18n.t(t.n)}),this.updateChildrenVisibility(),this.updateBodyPlaceholderVisibility(),n.inPlace}renderSettings(){return[]}expand(){this._isOpen||this.setOpenState(!0)}collapse(){this._isOpen&&this.setOpenState(!1)}setReadOnly(e){if(!this._element)return;let t=this.readOnly;this.readOnly=e,this._contentElement&&(this._contentElement.contentEditable=e?`false`:`true`),e&&!t?this.api.events.off(`block changed`,this.handleBlockChanged):!e&&t&&this.api.events.on(`block changed`,this.handleBlockChanged),this.updateBodyPlaceholderVisibility()}removed(){this.api.events.off(`block changed`,this.handleBlockChanged)}isBlockChangedPayload(e){return typeof e==`object`&&!!e&&`event`in e&&typeof e.event==`object`&&e.event!==null&&`type`in e.event&&typeof e.event.type==`string`}getContentElement(){return this._contentElement}setOpenState(e){this._isOpen=e,this._arrowElement&&this._element&&w(this._arrowElement,this._element,this._isOpen,{collapse:this.api.i18n.t(t.t),expand:this.api.i18n.t(t.n)}),this.updateChildrenVisibility(),this.updateBodyPlaceholderVisibility()}toggleOpen(){this.setOpenState(!this._isOpen)}updateChildrenVisibility(){this.blockId!==void 0&&T(this.api,this.blockId,this._isOpen,this._childContainerElement,this._arrowElement)}updateBodyPlaceholderVisibility(){this.blockId!==void 0&&(E(this._bodyPlaceholderElement,this.api,this.blockId,this._isOpen,this.readOnly),S(this._element,this._childContainerElement))}handleBodyPlaceholderClick(){var e;if(this.blockId===void 0)return;let t=this.api.blocks.getBlockIndex(this.blockId);if(t===void 0)return;let n=this.api.blocks.insertInsideParent(this.blockId,t+1);this.api.caret.setToBlock(n.id,`start`),(e=this._bodyPlaceholderElement)==null||e.classList.add(`hidden`)}handleKeyDown(e){if(e.key===`Enter`&&!e.shiftKey){e.preventDefault(),this.handleEnter();return}if(e.key===`Backspace`){this.handleBackspace(e);return}}createKeyboardContext(){return{api:this.api,blockId:this.blockId,data:this._data,element:this._element,getContentElement:this.getContentElement.bind(this),syncContentFromDOM:this.syncContentFromDOM.bind(this),isOpen:this._isOpen,setOpen:e=>{this._isOpen=e}}}async handleEnter(){var e=this;await D(e.createKeyboardContext()),e.updateBodyPlaceholderVisibility()}async handleBackspace(e){await O(this.createKeyboardContext(),e)}syncContentFromDOM(){let e=this.getContentElement();e&&(this._data.text=e.innerHTML)}static get toolbox(){return{icon:t.Sn,titleKey:`toggleList`,name:t.p,searchTerms:[`toggle`,`collapse`,`expand`,`accordion`],searchTermKeys:[`toggle`,`collapse`,`expand`,`accordion`],shortcut:`>`}}static get conversionConfig(){return{export:`text`,import:`text`}}static get sanitize(){return{text:{br:!0,a:{href:!0,target:`_blank`,rel:`nofollow`},b:!0,i:!0,mark:{class:!0,style:!0},code:!0}}}static get pasteConfig(){return{tags:[`DETAILS`]}}static get isReadOnlySupported(){return!0}},Ar=`callout`,jr=`tools.callout.color`,Mr=`tools.callout.editIcon`,Nr=`tools.callout.addEmoji`,Pr=`tools.callout.removeEmoji`,Fr=`tools.callout.filterEmojis`,Ir=`tools.callout.calloutEmojiCategory`,Lr=`tools.callout.noEmojisFound`,Rr=`tools.callout.pickRandom`,zr=`tools.callout.skinTone`,Br=`tools.callout.emojiCategoryPeople`,Vr=`tools.callout.emojiCategoryNature`,Hr=`tools.callout.emojiCategoryFood`,Ur=`tools.callout.emojiCategoryActivity`,Wr=`tools.callout.emojiCategoryTravel`,Gr=`tools.callout.emojiCategoryObjects`,Kr=`tools.callout.emojiCategorySymbols`,qr=`tools.callout.emojiCategoryFlags`,Jr=`💡`,Yr=`rounded-xl pl-8 pr-4 py-[5px] my-1 flex items-start gap-2 relative`,Xr=`text-[1.5rem] leading-[1] cursor-pointer bg-transparent border-0 px-0 py-[7px] h-[38px] flex-shrink-0 select-none`,Zr=`flex-1 min-w-0`;function Qr(e){let{emoji:n,readOnly:r,addEmojiLabel:i}=e,a=document.createElement(`div`);a.className=Yr;let o=document.createElement(`button`);o.type=`button`,o.className=Xr,o.textContent=n||``,o.setAttribute(`aria-label`,n===``?i:n),o.setAttribute(`tabindex`,`0`),o.setAttribute(`data-blok-testid`,`callout-emoji-btn`),r&&(o.disabled=!0);let s=document.createElement(`div`);return s.className=Zr,s.setAttribute(t.u.toggleChildren,``),s.setAttribute(t.hi.nestedBlocks,``),s.setAttribute(`data-blok-child-toolbar`,``),s.setAttribute(`data-blok-mutation-free`,`true`),a.appendChild(o),a.appendChild(s),{wrapper:a,emojiButton:o,childContainer:s}}function $r(e){return{emoji:e.emoji,textColor:e.textColor,backgroundColor:e.backgroundColor}}async function ei(e){if(e.calloutBlockId===void 0)return;let t=e.api.blocks.getChildren(e.calloutBlockId);if(e.event.preventDefault(),t.length<=1){await e.api.blocks.convert(e.calloutBlockId,`paragraph`);return}let n=e.api.blocks.getBlockIndex(e.firstChildBlockId);n!==void 0&&await e.api.blocks.delete(n);let r=e.api.blocks.getBlockIndex(e.calloutBlockId);r!==void 0&&r>0&&e.api.caret.setToBlock(r-1,`end`)}var ti=[`💡`,`👉`,`☝️`,`✅`,`⚠️`,`🔑`,`🔥`,`📌`,`✂️`,`❓`,`🚫`,`⏰`,`♻️`,`🔒`,`📖`,`👣`,`➡️`,`📢`,`🛠️`,`⚙️`],ni={data:null};function ri(e,t){let n=[];for(let r of e.emojis){let i=t[r];if(i===void 0)continue;let a=i.skins[0];a!==void 0&&n.push({native:a.native,skins:i.skins.map(e=>e.native),id:i.id,name:i.name,keywords:i.keywords,category:e.id})}return n}async function ii(){if(ni.data!==null)return ni.data;let e=await Promise.resolve().then(()=>require(`./native-BGo-1wHi.cjs`)),t=`default`in e&&e.default!==void 0?e.default:e,n=t.categories.flatMap(e=>ri(e,t.emojis));return ni.data=n,n}function ai(e,t,n){let r=t.toLowerCase();return e.filter(e=>{if(e.name.toLowerCase().includes(r)||e.keywords.some(e=>e.includes(r)))return!0;let t=n==null?void 0:n[e.native];return t===void 0?!1:t.n.toLowerCase().includes(r)||t.k!==void 0&&t.k.some(e=>e.toLowerCase().includes(r))})}function oi(e){let t=new Map;for(let r of e){var n;let e=(n=t.get(r.category))==null?[]:n;e.push(r),t.set(r.category,e)}return t}var si=new Map,ci={am:()=>Promise.resolve().then(()=>require(`./am-CXUHahfU.cjs`)),ar:()=>Promise.resolve().then(()=>require(`./ar-dMOvWpJ-.cjs`)),az:()=>Promise.resolve().then(()=>require(`./az-3AbIE3nE.cjs`)),bg:()=>Promise.resolve().then(()=>require(`./bg-Y0RPNL0Z.cjs`)),bn:()=>Promise.resolve().then(()=>require(`./bn-D15VfEKd.cjs`)),bs:()=>Promise.resolve().then(()=>require(`./bs-B9nWVl_9.cjs`)),cs:()=>Promise.resolve().then(()=>require(`./cs-C9BEO4yn.cjs`)),da:()=>Promise.resolve().then(()=>require(`./da-BhLipA1M.cjs`)),de:()=>Promise.resolve().then(()=>require(`./de-BgNy5oYG.cjs`)),el:()=>Promise.resolve().then(()=>require(`./el-Ui4jHL2s.cjs`)),es:()=>Promise.resolve().then(()=>require(`./es-BsNXkteq.cjs`)),et:()=>Promise.resolve().then(()=>require(`./et-yMa1l80R.cjs`)),fa:()=>Promise.resolve().then(()=>require(`./fa-D6mf3izM.cjs`)),fi:()=>Promise.resolve().then(()=>require(`./fi-CYnlvPFq.cjs`)),fil:()=>Promise.resolve().then(()=>require(`./fil-DuFCrHoY.cjs`)),fr:()=>Promise.resolve().then(()=>require(`./fr-BBK6Wz6C.cjs`)),gu:()=>Promise.resolve().then(()=>require(`./gu-BJKCBJyD.cjs`)),he:()=>Promise.resolve().then(()=>require(`./he-BcUX_UQ1.cjs`)),hi:()=>Promise.resolve().then(()=>require(`./hi-BGf8Lxf8.cjs`)),hr:()=>Promise.resolve().then(()=>require(`./hr-hDDrHtNU.cjs`)),hu:()=>Promise.resolve().then(()=>require(`./hu-3HqqKEVc.cjs`)),hy:()=>Promise.resolve().then(()=>require(`./hy-Dzrc71XE.cjs`)),id:()=>Promise.resolve().then(()=>require(`./id-F9h4091H.cjs`)),it:()=>Promise.resolve().then(()=>require(`./it-DJji6i7E.cjs`)),ja:()=>Promise.resolve().then(()=>require(`./ja-C_pXoRgb.cjs`)),ka:()=>Promise.resolve().then(()=>require(`./ka-DGtVwGYl.cjs`)),km:()=>Promise.resolve().then(()=>require(`./km-DZ5rHPWc.cjs`)),kn:()=>Promise.resolve().then(()=>require(`./kn-DwwLaTD6.cjs`)),ko:()=>Promise.resolve().then(()=>require(`./ko-BBEtqxQR.cjs`)),ku:()=>Promise.resolve().then(()=>require(`./ku-Dd2x74MF.cjs`)),lo:()=>Promise.resolve().then(()=>require(`./lo-C61Y3F1a.cjs`)),lt:()=>Promise.resolve().then(()=>require(`./lt-pqg5xvGS.cjs`)),lv:()=>Promise.resolve().then(()=>require(`./lv-g3FCWRN0.cjs`)),mk:()=>Promise.resolve().then(()=>require(`./mk-bBMWHEZ-.cjs`)),ml:()=>Promise.resolve().then(()=>require(`./ml-Cm0IOve2.cjs`)),mn:()=>Promise.resolve().then(()=>require(`./mn-BTXL9HyI.cjs`)),mr:()=>Promise.resolve().then(()=>require(`./mr-xqL99Sd8.cjs`)),ms:()=>Promise.resolve().then(()=>require(`./ms-ClORsi5r.cjs`)),my:()=>Promise.resolve().then(()=>require(`./my-B-isOX0B.cjs`)),ne:()=>Promise.resolve().then(()=>require(`./ne-BGws6s0Y.cjs`)),nl:()=>Promise.resolve().then(()=>require(`./nl-CX2wzRTJ.cjs`)),no:()=>Promise.resolve().then(()=>require(`./no-CkkRSiCD.cjs`)),pa:()=>Promise.resolve().then(()=>require(`./pa-ZPS7mc5i.cjs`)),pl:()=>Promise.resolve().then(()=>require(`./pl-BqsMUtmm.cjs`)),ps:()=>Promise.resolve().then(()=>require(`./ps-CfUVIVqL.cjs`)),pt:()=>Promise.resolve().then(()=>require(`./pt-DqrVMzTM.cjs`)),ro:()=>Promise.resolve().then(()=>require(`./ro-fExo_FSc.cjs`)),ru:()=>Promise.resolve().then(()=>require(`./ru-LOwQVd_T.cjs`)),sd:()=>Promise.resolve().then(()=>require(`./sd-CretDKhM.cjs`)),si:()=>Promise.resolve().then(()=>require(`./si-DtQVOOio.cjs`)),sk:()=>Promise.resolve().then(()=>require(`./sk-CYibO0jl.cjs`)),sl:()=>Promise.resolve().then(()=>require(`./sl-7kJGMwOr.cjs`)),sq:()=>Promise.resolve().then(()=>require(`./sq-B63iyaS4.cjs`)),sr:()=>Promise.resolve().then(()=>require(`./sr-CH3ORyMw.cjs`)),sv:()=>Promise.resolve().then(()=>require(`./sv-Bcx8ebyq.cjs`)),sw:()=>Promise.resolve().then(()=>require(`./sw-BvKSTskt.cjs`)),ta:()=>Promise.resolve().then(()=>require(`./ta-DMUhMZIx.cjs`)),te:()=>Promise.resolve().then(()=>require(`./te-CGA7e7rg.cjs`)),th:()=>Promise.resolve().then(()=>require(`./th-fRbW65W8.cjs`)),tr:()=>Promise.resolve().then(()=>require(`./tr-W2-8Rsq1.cjs`)),ug:()=>Promise.resolve().then(()=>require(`./ug-NOltpjZX.cjs`)),uk:()=>Promise.resolve().then(()=>require(`./uk-CifV3wfH.cjs`)),ur:()=>Promise.resolve().then(()=>require(`./ur-DUJVuENS.cjs`)),vi:()=>Promise.resolve().then(()=>require(`./vi-DyluRTg6.cjs`)),zh:()=>Promise.resolve().then(()=>require(`./zh-BEYGMTUQ.cjs`))};async function li(e){if(e===`en`)return null;let t=si.get(e);if(t!==void 0)return t;let n=ci[e];if(n===void 0)return null;try{let t=(await n()).default;return si.set(e,t),t}catch(e){return null}}var ui={callout:Ir,people:Br,nature:Vr,foods:Hr,activity:Ur,places:Wr,objects:Gr,symbols:Kr,flags:qr},di=[[`callout`,t._t],[`people`,t.ht],[`nature`,t.gt],[`foods`,t.vt],[`activity`,t.ft],[`places`,t.St],[`objects`,t.mt],[`symbols`,t.kt],[`flags`,t.pt]],fi=[`✋`,`✋🏻`,`✋🏼`,`✋🏽`,`✋🏾`,`✋🏿`],pi=`blok-emoji-skin-tone`;function mi(){try{let e=localStorage.getItem(pi);if(e===null)return 0;let t=parseInt(e,10);return t>=0&&t<=5?t:0}catch(e){return 0}}function hi(e){try{localStorage.setItem(pi,String(e))}catch(e){}}var gi=t.st,_i=class{constructor(e){this._localeData=null,this._open=!1,this._allEmojis=[],this._skinTone=0,this._showingEmptyState=!1,this._anchorEl=null,this._backdrop=null,this._savedOverflow=``,this._navButtons=new Map,this._sectionEls=new Map,this._activeNavId=``,this._navRafId=0,this._skinToneButtons=[],this.onSelect=e.onSelect,this.onRemove=e.onRemove,this.i18n=e.i18n,this._locale=e.locale,this._element=this.buildElement();let t=this._element.querySelector(`[data-emoji-picker-body]`),n=this._element.querySelector(`[data-emoji-picker-nav]`),r=this._element.querySelector(`input[type="text"]`);if(t===null||n===null||r===null)throw Error(`EmojiPicker: failed to build required elements`);this._body=t,this._nav=n,this._filterInput=r,this._body.addEventListener(`scroll`,()=>{cancelAnimationFrame(this._navRafId),this._navRafId=requestAnimationFrame(()=>this.updateActiveNav())},{passive:!0})}getElement(){return this._element}isOpen(){return this._open}async open(e){var t=this;t._anchorEl=e,t._open=!0,t._filterInput.value=``,t._element.setAttribute(`data-theme`,t.resolveTheme());let n=mi();if(n!==t._skinTone){t._skinTone=n,t._skinToneToggle.textContent=fi[n];for(let[e,r]of t._skinToneButtons.entries())t.applySkinToneActiveStyle(r,e===n)}if(t._allEmojis.length===0&&(t._allEmojis=await ii()),t._locale!==`en`&&t._localeData===null){let e=await li(t._locale);e!==null&&(t._localeData=e)}t.renderEmojiGrid(t._allEmojis),t.showBackdrop(),t._element.style.animation=`none`,t._element.hidden=!1,t.position(e),t._element.offsetHeight,t._element.style.animation=``,t._filterInput.focus()}close(){var e;this._open=!1,this._element.hidden=!0,this.closeSkinTonePopover(),this.removeBackdrop(),(e=this._anchorEl)==null||e.focus()}buildElement(){let e=document.createElement(`div`);e.setAttribute(`data-blok-emoji-picker`,``),e.className=[`fixed z-50 w-[400px] overflow-hidden rounded-xl`,`border border-neutral-200/70 bg-white shadow-2xl`,`theme-dark:border-neutral-700/50 theme-dark:bg-neutral-900`].join(` `),e.hidden=!0;let n=document.createElement(`div`);n.className=`flex items-center gap-2.5 px-3 pt-3 pb-2`;let r=document.createElement(`div`);r.className=`relative flex-1 min-w-0`;let i=document.createElement(`span`);i.className=[`pointer-events-none absolute left-2.5 top-1/2 -translate-y-1/2 flex items-center`,`text-neutral-400 theme-dark:text-neutral-500 [&>svg]:w-[16px] [&>svg]:h-[16px]`].join(` `),i.innerHTML=t.fn;let a=document.createElement(`input`);a.type=`text`,a.placeholder=this.i18n.t(Fr),a.className=[`w-full text-[13px] rounded-lg py-[7px] pl-8 pr-3 outline-hidden`,`bg-neutral-100 text-neutral-800 placeholder:text-neutral-400`,`theme-dark:bg-neutral-800 theme-dark:text-neutral-200 theme-dark:placeholder:text-neutral-500`,`focus:ring-2 focus:ring-neutral-300/60 theme-dark:focus:ring-neutral-600/60`,`transition-shadow duration-150`].join(` `),a.addEventListener(`input`,()=>this.handleFilterChange(a.value)),r.appendChild(i),r.appendChild(a);let o=document.createElement(`div`);o.className=`relative flex-shrink-0`;let s=document.createElement(`button`);s.type=`button`,s.setAttribute(`data-emoji-picker-skin-toggle`,``),s.setAttribute(`aria-label`,this.i18n.t(zr)),s.title=this.i18n.t(zr),s.className=[`w-[28px] h-[28px] flex items-center justify-center rounded-lg`,`text-[14px] leading-none cursor-pointer select-none`,`hover:bg-neutral-100 theme-dark:hover:bg-neutral-800`,`active:scale-90 transition-all duration-100`].join(` `),s.textContent=fi[this._skinTone],s.addEventListener(`click`,()=>this.toggleSkinTonePopover()),this._skinToneToggle=s,o.appendChild(s),this._skinTonePopover=this.buildSkinTonePopover(),o.appendChild(this._skinTonePopover);let c=document.createElement(`button`);c.type=`button`,c.setAttribute(`data-emoji-picker-random`,``),c.setAttribute(`aria-label`,this.i18n.t(Rr)),c.className=[`flex-shrink-0 w-[34px] h-[34px] flex items-center justify-center rounded-lg`,`text-neutral-400 hover:bg-neutral-100 hover:text-neutral-600`,`theme-dark:hover:bg-neutral-800 theme-dark:hover:text-neutral-300`,`transition-colors duration-100 cursor-pointer`].join(` `),c.innerHTML=gi,c.addEventListener(`click`,()=>this.pickRandom()),t.or(c,this.i18n.t(Rr),{placement:`bottom`});let l=document.createElement(`button`);l.type=`button`,l.setAttribute(`data-emoji-picker-remove`,``),l.setAttribute(`aria-label`,this.i18n.t(Pr)),l.className=[`flex-shrink-0 w-[34px] h-[34px] flex items-center justify-center rounded-lg`,`text-neutral-400 hover:bg-neutral-100 hover:text-neutral-600`,`theme-dark:hover:bg-neutral-800 theme-dark:hover:text-neutral-300`,`transition-colors duration-100 cursor-pointer`].join(` `),l.innerHTML=t.Z,l.addEventListener(`click`,()=>{this.onRemove(),this.close()}),t.or(l,this.i18n.t(Pr),{placement:`bottom`});let u=document.createElement(`div`);u.className=`flex items-center gap-1`,u.appendChild(c),u.appendChild(l),n.appendChild(r),n.appendChild(o),n.appendChild(u),e.appendChild(n);let d=document.createElement(`div`);d.setAttribute(`data-emoji-picker-body`,``),d.className=`overflow-y-auto max-h-[260px] px-1.5 pb-2`,e.appendChild(d);let f=document.createElement(`div`);return f.setAttribute(`data-emoji-picker-nav`,``),f.className=[`flex items-center gap-1 px-2 pt-1 pb-1`,`border-t border-neutral-100 theme-dark:border-neutral-800`].join(` `),e.appendChild(f),e.addEventListener(`mousedown`,e=>{let t=e.target;!this._skinTonePopover.hidden&&!this._skinTonePopover.contains(t)&&!this._skinToneToggle.contains(t)&&this.closeSkinTonePopover()}),e.addEventListener(`keydown`,e=>{if(e.key===`Escape`){if(!this._skinTonePopover.hidden){this.closeSkinTonePopover();return}this.close()}}),e}buildSkinTonePopover(){let e=document.createElement(`div`);e.setAttribute(`data-emoji-picker-skin-tone`,``),e.className=[`absolute right-0 top-full mt-1.5 z-20`,`flex items-center gap-0.5 p-1 rounded-xl`,`bg-white border border-neutral-200/70 shadow-lg`,`theme-dark:bg-neutral-800 theme-dark:border-neutral-700/50`].join(` `),e.hidden=!0,this._skinToneButtons=[];for(let[t,n]of fi.entries()){let r=document.createElement(`button`);r.type=`button`,r.textContent=n,r.setAttribute(`aria-label`,`${this.i18n.t(zr)} ${t+1}`),r.className=[`w-[32px] h-[32px] flex items-center justify-center rounded-lg`,`text-[1.2rem] leading-none cursor-pointer select-none`,`hover:bg-neutral-100 theme-dark:hover:bg-neutral-700`,`active:scale-90 transition-all duration-100`].join(` `),this.applySkinToneActiveStyle(r,t===this._skinTone),r.addEventListener(`click`,()=>{this.setSkinTone(t),this.closeSkinTonePopover()}),e.appendChild(r),this._skinToneButtons.push(r)}return e}applySkinToneActiveStyle(e,t){let n=[`bg-neutral-100`,`theme-dark:bg-neutral-700`,`ring-2`,`ring-neutral-300/60`,`theme-dark:ring-neutral-600/60`];t?e.classList.add(...n):e.classList.remove(...n)}toggleSkinTonePopover(){this._skinTonePopover.hidden=!this._skinTonePopover.hidden,this.updateSkinToneToggleActive()}closeSkinTonePopover(){this._skinTonePopover.hidden=!0,this.updateSkinToneToggleActive()}updateSkinToneToggleActive(){let e=!this._skinTonePopover.hidden,t=[`bg-neutral-100`,`theme-dark:bg-neutral-700`];e?this._skinToneToggle.classList.add(...t):this._skinToneToggle.classList.remove(...t)}setSkinTone(e){this._skinTone=e,hi(e),this._skinToneToggle.textContent=fi[e];for(let[t,n]of this._skinToneButtons.entries())this.applySkinToneActiveStyle(n,t===e);let t=Array.from(this._body.querySelectorAll(`[data-emoji-native]`));for(let e of t){let t=e.getAttribute(`data-emoji-native`);if(t===null)continue;let n=this._allEmojis.find(e=>e.native===t);n!==void 0&&(e.textContent=this.getSkinnedNative(n))}}pickRandom(){if(this._allEmojis.length===0)return;let e=Math.floor(Math.random()*this._allEmojis.length),t=this._allEmojis[e];t!==void 0&&this.onSelect(this.getSkinnedNative(t))}buildCategoryNav(e){this._nav.innerHTML=``,this._navButtons.clear(),this._activeNavId=``;for(let[t,n]of di){if(!e.has(t))continue;let r=this.translateCategory(t),i=document.createElement(`button`);i.type=`button`,i.innerHTML=n,i.title=r,i.setAttribute(`aria-label`,r),i.setAttribute(`data-emoji-nav`,t),i.className=[`flex-1 h-[36px] flex items-center justify-center`,`rounded-lg cursor-pointer opacity-50`,`text-neutral-500 theme-dark:text-neutral-400`,`[&>svg]:w-[20px] [&>svg]:h-[20px]`,`hover:opacity-100 hover:bg-neutral-100`,`theme-dark:hover:bg-neutral-800`,`transition-all duration-100`].join(` `),i.addEventListener(`click`,()=>this.scrollToSection(t)),this._nav.appendChild(i),this._navButtons.set(t,i)}}scrollToSection(e){let t=this._sectionEls.get(e);if(t===void 0)return;let n=this._body.getBoundingClientRect(),r=t.getBoundingClientRect();this._body.scrollTo({top:this._body.scrollTop+(r.top-n.top),behavior:`smooth`})}updateActiveNav(){let e=this._body.getBoundingClientRect().top,t=[...this._sectionEls.entries()].filter(([,t])=>t.getBoundingClientRect().top-e<=20).reduce((e,[t])=>t,``);if(t!==this._activeNavId){this._activeNavId=t;for(let[e,n]of this._navButtons)e===t?(n.classList.remove(`opacity-50`),n.classList.add(`opacity-100`,`bg-neutral-100`,`theme-dark:bg-neutral-800`)):(n.classList.remove(`opacity-100`,`bg-neutral-100`,`theme-dark:bg-neutral-800`),n.classList.add(`opacity-50`))}}getSkinnedNative(e){var t;return(t=e.skins[this._skinTone])==null?e.native:t}handleFilterChange(e){if(e.trim()===``){this._nav.hidden=!1,this.renderEmojiGrid(this._allEmojis);return}this._nav.hidden=!0;let t=ai(this._allEmojis,e,this._localeData);if(t.length===0)this._showingEmptyState||this.renderEmptyState();else{this._body.innerHTML=``,this._sectionEls.clear(),this._showingEmptyState=!1;let e=oi(t);for(let[t,n]of e){let e=this.buildSection(this.translateCategory(t),n);e.setAttribute(`data-emoji-section`,t),this._sectionEls.set(t,e),this._body.appendChild(e)}}}renderEmojiGrid(e){this._body.innerHTML=``,this._sectionEls.clear(),this._showingEmptyState=!1;let t=new Set,n=ti.map(t=>e.find(e=>e.native===t)).filter(e=>e!==void 0);if(n.length>0){t.add(`callout`);let e=this.buildSection(this.translateCategory(`callout`),n);e.setAttribute(`data-emoji-section`,`callout`),this._sectionEls.set(`callout`,e),this._body.appendChild(e)}let r=new Set(ti),i=oi(e.filter(e=>!r.has(e.native)));for(let[e,n]of i){t.add(e);let r=this.buildSection(this.translateCategory(e),n);r.setAttribute(`data-emoji-section`,e),this._sectionEls.set(e,r),this._body.appendChild(r)}this.buildCategoryNav(t),this._nav.hidden=!1,requestAnimationFrame(()=>this.updateActiveNav())}renderEmptyState(){this._body.innerHTML=``,this._showingEmptyState=!0,this._sectionEls.clear();let e=document.createElement(`div`);e.className=[`flex flex-col items-center justify-center py-10`,`text-neutral-400 theme-dark:text-neutral-500 select-none`,`animate-[blok-emoji-empty-in_300ms_ease-out_both]`].join(` `);let n=document.createElement(`span`);n.className=`mb-3 opacity-20 [&>svg]:w-9 [&>svg]:h-9`,n.innerHTML=t.fn;let r=document.createElement(`span`);r.className=`text-[13px] font-medium`,r.textContent=this.i18n.t(Lr),e.appendChild(n),e.appendChild(r),this._body.appendChild(e)}translateCategory(e){let t=ui[e];return t===void 0?e:this.i18n.t(t)}buildSection(e,t){let n=document.createElement(`div`),r=document.createElement(`div`);return r.className=[`text-[11px] font-semibold uppercase tracking-wider px-2 pt-3 pb-1.5`,`text-neutral-400/80 theme-dark:text-neutral-500/80`,`sticky top-0 bg-white theme-dark:bg-neutral-900 z-10`].join(` `),r.textContent=e,n.appendChild(r),n.appendChild(this.buildGrid(t)),n}getDisplayName(e){var t,n;return((t=(n=this._localeData)==null||(n=n[e.native])==null?void 0:n.n)==null?e.name:t).toLocaleLowerCase()}buildGrid(e){let n=document.createElement(`div`);n.className=`grid grid-cols-10 gap-0.5 px-0.5 pt-1`;for(let r of e){let e=document.createElement(`button`);e.type=`button`,e.textContent=this.getSkinnedNative(r),e.setAttribute(`data-emoji-native`,r.native),e.className=[`aspect-square flex items-center justify-center`,`text-[1.25rem] leading-none rounded-lg cursor-pointer`,`hover:bg-neutral-100 theme-dark:hover:bg-neutral-800`,`hover:scale-110 active:scale-95`,`transition-transform duration-75`].join(` `),e.addEventListener(`click`,()=>{this.onSelect(this.getSkinnedNative(r)),this.close()}),t.or(e,this.getDisplayName(r),{placement:`bottom`}),n.appendChild(e)}return n}resolveTheme(){let e=document.documentElement.getAttribute(`data-blok-theme`);return e===`dark`?`dark`:e===`light`?`light`:window.matchMedia(`(prefers-color-scheme: dark)`).matches?`dark`:`light`}showBackdrop(){var e;this.removeBackdrop();let t=document.createElement(`div`);t.setAttribute(`data-blok-emoji-picker-backdrop`,``),t.style.position=`fixed`,t.style.inset=`0`,t.style.zIndex=`50`,t.addEventListener(`mousedown`,e=>{e.target===t&&this.close()}),(e=this._element.parentElement)==null||e.insertBefore(t,this._element),t.appendChild(this._element),this._backdrop=t,this._savedOverflow=document.documentElement.style.overflow,document.documentElement.style.overflow=`hidden`}removeBackdrop(){var e;this._backdrop!==null&&(document.documentElement.style.overflow=this._savedOverflow,(e=this._backdrop.parentElement)==null||e.insertBefore(this._element,this._backdrop),this._backdrop.remove(),this._backdrop=null)}position(e){let t=e.getBoundingClientRect(),n=this._element.getBoundingClientRect(),r=window.innerHeight,i=window.innerWidth,a=t.bottom+n.height>r?t.top-n.height-4:t.bottom+4,o=t.left-8,s=o+n.width>i?t.right-n.width:Math.max(0,o);this._element.style.top=`${a}px`,this._element.style.left=`${s}px`}};function vi(e){return e.isEmojiVisible===!1?``:typeof e.emoji==`string`&&e.emoji.length>0?e.emoji:Jr}var yi={general:null,note:`blue`,important:`purple`,warning:`orange`,additional:`yellow`,recommendation:`green`,caution:`red`},bi=class{constructor({data:e,api:t,readOnly:n,block:r,config:i}){this._dom=null,this._emojiPicker=null,this._colorPicker=null,this._pendingChildText=null,this.api=t,this.readOnly=n;let a=typeof e.__importedText==`string`?e.__importedText:null;a!==null&&a.length>0&&(this._pendingChildText=a),this._data=this.normalizeData(e),r&&(this.blockId=r.id),this._customEmojiPicker=i==null?void 0:i.emojiPicker}normalizeData(e){let t=e;return`variant`in t||`isEmojiVisible`in t?this.normalizeLegacyData(t):{emoji:typeof e.emoji==`string`?e.emoji:Jr,textColor:typeof e.textColor==`string`?e.textColor:null,backgroundColor:typeof e.backgroundColor==`string`?e.backgroundColor:null}}normalizeLegacyData(e){let t=typeof e.variant==`string`?e.variant:`general`,n=t in yi?yi[t]:null;return{emoji:vi(e),textColor:null,backgroundColor:n==null?null:n}}render(){if(this._dom)return this._dom.wrapper;let e=Qr({emoji:this._data.emoji,readOnly:this.readOnly,addEmojiLabel:this.api.i18n.t(Nr)});return this._dom=e,this.applyColors(),this.readOnly||(e.emojiButton.addEventListener(`click`,()=>this.openEmojiPicker()),e.emojiButton.addEventListener(`keydown`,e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),this.openEmojiPicker())}),e.childContainer.addEventListener(`keydown`,e=>{e.key===`Backspace`&&this.handleChildBackspace(e)})),e.wrapper}rendered(){if(this.blockId===void 0||this._dom===null)return;let e=this.api.blocks.getChildren(this.blockId);if(x(this._dom.childContainer,e),e.length===0){let e=this.api.blocks.getBlockIndex(this.blockId);if(e!==void 0){let t=this._pendingChildText;this._pendingChildText=null;let n=t!==null&&t.length>0?{text:t}:void 0,r=this.api.blocks.insertInsideParent(this.blockId,e+1,n);this._dom.childContainer.appendChild(r.holder),this.api.caret.setToBlock(r.id,t===null?`start`:`end`)}}}save(){return $r({emoji:this._data.emoji,textColor:this._data.textColor,backgroundColor:this._data.backgroundColor})}validate(e){return!0}onPaste(e){var n;let r=(n=e.detail.data.getAttribute(`style`))==null?``:n,i=/background(?:-color)?\s*:\s*([^;]+)/i.exec(r);if(i!=null&&i[1]){let e=t.Rn(i[1].trim(),`bg`);e&&(this._data.backgroundColor=e)}this.applyColors()}renderSettings(){if(this._colorPicker===null){let e=Ft({i18n:this.api.i18n,testIdPrefix:`callout-color`,modes:[{key:`color`,labelKey:`tools.marker.textColor`,presetField:`text`},{key:`background-color`,labelKey:`tools.marker.background`,presetField:`bg`}],onColorSelect:(n,r)=>{let i=n===null?null:t.Rn(n,r===`color`?`text`:`bg`);r===`color`?this._data.textColor=i:this._data.backgroundColor=i,e.setActiveColor(n,r),this.applyColors()}});this._colorPicker=e}return this.syncPickerActiveColors(),[{icon:t.ht,title:this.api.i18n.t(Mr),name:`callout-edit-icon`,closeOnActivate:!0,onActivate:()=>this.openEmojiPicker()},{icon:t.in,title:this.api.i18n.t(jr),name:`callout-color`,children:{items:[{type:t.pr.Html,element:this._colorPicker.element}]}}]}removed(){}setReadOnly(e){this.readOnly=e,this._dom&&(this._dom.emojiButton.disabled=e)}syncPickerActiveColors(){if(this._colorPicker===null)return;let e=this._data.textColor,n=this._data.backgroundColor;this._colorPicker.setActiveColor(e===null?null:t.Wn(e,`text`),`color`),this._colorPicker.setActiveColor(n===null?null:t.Wn(n,`bg`),`background-color`)}applyColors(){if(this._dom===null)return;let{textColor:e,backgroundColor:n}=this._data;if(e===null?this._dom.wrapper.style.color=``:this._dom.wrapper.style.color=t.Wn(e,`text`),n!==null){let e=t.Wn(n,`bg`);this._dom.wrapper.style.backgroundColor=e,this._dom.wrapper.style.border=``,this._dom.wrapper.style.setProperty(`--blok-search-input-bg`,`light-dark(color-mix(in srgb, ${e} 70%, white), color-mix(in srgb, ${e} 85%, white))`)}else this._dom.wrapper.style.backgroundColor=``,this._dom.wrapper.style.border=`1px solid var(--blok-callout-default-border, #e5e7eb)`,this._dom.wrapper.style.removeProperty(`--blok-search-input-bg`),this._dom.wrapper.style.removeProperty(`--blok-search-input-border`)}handleChildBackspace(e){if(this.blockId===void 0||this._dom===null)return;let t=this.api.blocks.getChildren(this.blockId);if(t.length===0)return;let n=t[0],r=e.target;if(!n.holder.contains(r))return;let i=window.getSelection(),a=i!==null&&i.rangeCount>0&&i.getRangeAt(0).startOffset===0&&i.getRangeAt(0).collapsed;n.holder.textContent!==``||!a||ei({api:this.api,calloutBlockId:this.blockId,firstChildBlockId:n.id,event:e})}openEmojiPicker(){if(this._dom!==null){if(this._customEmojiPicker!==void 0){this._customEmojiPicker(e=>this.setEmoji(e));return}this._emojiPicker===null&&(this._emojiPicker=new _i({onSelect:e=>this.setEmoji(e),onRemove:()=>this.setEmoji(``),i18n:this.api.i18n,locale:this.api.i18n.getLocale()}),document.body.appendChild(this._emojiPicker.getElement())),this._emojiPicker.open(this._dom.emojiButton)}}setEmoji(e){this._data.emoji=e,this._dom!==null&&(this._dom.emojiButton.textContent=e,this._dom.emojiButton.setAttribute(`aria-label`,e===``?this.api.i18n.t(Nr):e))}static get toolbox(){return{icon:t.U,titleKey:`callout`,name:Ar,searchTerms:[`callout`,`note`,`info`,`warning`,`tip`,`alert`],searchTermKeys:[`callout`,`note`,`info`,`warning`,`tip`,`alert`]}}static get conversionConfig(){return{import:e=>({emoji:Jr,textColor:null,backgroundColor:null,__importedText:e})}}static get pasteConfig(){return{tags:[{ASIDE:{style:!0}}]}}static get sanitize(){return{emoji:!1,textColor:!1,backgroundColor:!1}}static get isReadOnlySupported(){return!0}},xi=`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz`;function Si(e,t,n){let r=n[0];if(t!=null&&e>=t)throw Error(e+` >= `+t);if(e.slice(-1)===r||t&&t.slice(-1)===r)throw Error(`trailing zero`);if(t){let i=0;for(;(e[i]||r)===t[i];)i++;if(i>0)return t.slice(0,i)+Si(e.slice(i),t.slice(i),n)}let i=e?n.indexOf(e[0]):0,a=t==null?n.length:n.indexOf(t[0]);return a-i>1?n[Math.round(.5*(i+a))]:t&&t.length>1?t.slice(0,1):n[i]+Si(e.slice(1),null,n)}function Ci(e){if(e.length!==wi(e[0]))throw Error(`invalid integer part of order key: `+e)}function wi(e){if(e>=`a`&&e<=`z`)return e.charCodeAt(0)-97+2;if(e>=`A`&&e<=`Z`)return 90-e.charCodeAt(0)+2;throw Error(`invalid order key head: `+e)}function Ti(e){let t=wi(e[0]);if(t>e.length)throw Error(`invalid order key: `+e);return e.slice(0,t)}function Ei(e,t){if(e===`A`+t[0].repeat(26))throw Error(`invalid order key: `+e);let n=Ti(e);if(e.slice(n.length).slice(-1)===t[0])throw Error(`invalid order key: `+e)}function Di(e,t){Ci(e);let[n,...r]=e.split(``),i=!0;for(let e=r.length-1;i&&e>=0;e--){let n=t.indexOf(r[e])+1;n===t.length?r[e]=t[0]:(r[e]=t[n],i=!1)}if(i){if(n===`Z`)return`a`+t[0];if(n===`z`)return null;let e=String.fromCharCode(n.charCodeAt(0)+1);return e>`a`?r.push(t[0]):r.pop(),e+r.join(``)}else return n+r.join(``)}function Oi(e,t){Ci(e);let[n,...r]=e.split(``),i=!0;for(let e=r.length-1;i&&e>=0;e--){let n=t.indexOf(r[e])-1;n===-1?r[e]=t.slice(-1):(r[e]=t[n],i=!1)}if(i){if(n===`a`)return`Z`+t.slice(-1);if(n===`A`)return null;let e=String.fromCharCode(n.charCodeAt(0)-1);return e<`Z`?r.push(t.slice(-1)):r.pop(),e+r.join(``)}else return n+r.join(``)}function ki(e,t,n=xi){if(e!=null&&Ei(e,n),t!=null&&Ei(t,n),e!=null&&t!=null&&e>=t)throw Error(e+` >= `+t);if(e==null){if(t==null)return`a`+n[0];let e=Ti(t),r=t.slice(e.length);if(e===`A`+n[0].repeat(26))return e+Si(``,r,n);if(e<t)return e;let i=Oi(e,n);if(i==null)throw Error(`cannot decrement any more`);return i}if(t==null){let t=Ti(e),r=e.slice(t.length),i=Di(t,n);return i==null?t+Si(r,null,n):i}let r=Ti(e),i=e.slice(r.length),a=Ti(t),o=t.slice(a.length);if(r===a)return r+Si(i,o,n);let s=Di(r,n);if(s==null)throw Error(`cannot increment any more`);return s<t?s:r+Si(i,null,n)}var Ai={notStarted:[`Not`,`started`].join(` `),inProgress:[`In`,`progress`].join(` `),done:[`Do`,`ne`].join(``)},ji=class e{constructor(t){if(this.rows=[],(t==null?void 0:t.schema)!==void 0&&t.schema.length>0?this.schema=t.schema.map(e=>n.t({},e)):this.schema=e.createDefaultSchema(),(t==null?void 0:t.views)!==void 0&&t.views.length>0)this.views=t.views.map(e=>n.t(n.t({},e),{},{sorts:[...e.sorts],filters:[...e.filters],visibleProperties:[...e.visibleProperties]}));else{let t=this.schema.find(e=>e.type===`select`);this.views=[e.createDefaultView(t==null?void 0:t.id)]}this.activeViewId=(t==null?void 0:t.activeViewId)||(this.views.length>0?this.views[0].id:``)}getSchema(){return[...this.schema]}getProperty(e){return this.schema.find(t=>t.id===e)}addProperty(e,r,i){let a=this.schema.length>0?this.schema[this.schema.length-1].position:null,o=n.t({id:t.Ur(),name:e,type:r,position:ki(a,null)},i===void 0?{}:{config:i});return this.schema.push(o),o}updateProperty(e,t){let n=this.schema.find(t=>t.id===e);n!==void 0&&(t.name!==void 0&&(n.name=t.name),t.config!==void 0&&(n.config=t.config))}deleteProperty(e){this.schema=this.schema.filter(t=>t.id!==e)}setRows(e){this.rows=e}getOrderedRows(){return[...this.rows].sort((e,t)=>e.position.localeCompare(t.position))}getRow(e){return this.rows.find(t=>t.id===e)}createRowData(e){let n=this.getOrderedRows(),r=n.length>0?n[n.length-1].position:null;return{id:t.Ur(),position:ki(r,null),properties:e==null?{}:e}}getRowsGroupedBy(e){let t=new Map,n=this.getOrderedRows();for(let r of n){let n=r.properties[e],i=this.toGroupKey(n),a=t.get(i);a===void 0?t.set(i,[r]):a.push(r)}return t}getSelectOptions(e){var t,n;let r=this.getProperty(e);return r===void 0||r.type!==`select`&&r.type!==`multiSelect`?[]:[...(t=(n=r.config)==null?void 0:n.options)==null?[]:t].sort((e,t)=>e.position<t.position?-1:1)}getViews(){return[...this.views]}getView(e){return this.views.find(t=>t.id===e)}addView(e,n,r={}){var i,a,o;let s=[...this.views].sort((e,t)=>e.position<t.position?-1:1),c=s.length>0?s[s.length-1].position:null,l={id:t.Ur(),name:e,type:n,position:ki(c,null),groupBy:r.groupBy,sorts:(i=r.sorts)==null?[]:i,filters:(a=r.filters)==null?[]:a,visibleProperties:(o=r.visibleProperties)==null?[]:o};return this.views.push(l),l}updateView(e,t){let n=this.views.find(t=>t.id===e);n!==void 0&&Object.assign(n,t)}deleteView(e){this.views=this.views.filter(t=>t.id!==e)}hydrate(e){e.schema!==void 0&&(this.schema=structuredClone(e.schema)),e.views!==void 0&&(this.views=structuredClone(e.views))}snapshot(){return{schema:structuredClone(this.schema),views:structuredClone(this.views),activeViewId:this.activeViewId}}toGroupKey(e){return e==null?``:typeof e==`string`?e:typeof e==`boolean`||typeof e==`number`?String(e):``}static positionBetween(e,t){return ki(e,t)}static createDefaultSchema(){return[{id:t.Ur(),name:`Title`,type:`title`,position:`a0`},{id:t.Ur(),name:`Status`,type:`select`,position:`a1`,config:{options:[{id:t.Ur(),label:Ai.notStarted,color:`gray`,position:`a0`},{id:t.Ur(),label:Ai.inProgress,color:`blue`,position:`a1`},{id:t.Ur(),label:Ai.done,color:`green`,position:`a2`}]}}]}static createDefaultView(e){return{id:t.Ur(),name:`Board`,type:`board`,position:`a0`,groupBy:e,sorts:[],filters:[],visibleProperties:[]}}},Mi=class{constructor({readOnly:e,i18n:t,options:n,getRows:r,titlePropertyId:i,onTitleEdit:a}){this.readOnly=e,this.i18n=t,this.options=n,this.getRows=r,this.titlePropertyId=i,this.onTitleEdit=a}createView(){let e=document.createElement(`div`);e.setAttribute(`data-blok-tool`,`database`),e.setAttribute(`role`,`region`),e.setAttribute(`aria-label`,this.i18n.t(`tools.database.kanbanBoard`)),e.style.display=`flex`;let t=document.createElement(`div`);t.setAttribute(`data-blok-database-board`,``),t.style.display=`flex`,t.style.overflowX=`auto`,t.style.alignItems=`flex-start`,t.style.gap=`12px`,t.style.paddingBottom=`24px`,t.style.flex=`1`,t.style.minWidth=`0`;for(let e of this.options){let n=this.createColumnElement(e,this.getRows(e.id),this.titlePropertyId);t.appendChild(n)}if(!this.readOnly){let e=document.createElement(`button`);e.setAttribute(`data-blok-database-add-column`,``),e.setAttribute(`aria-label`,this.i18n.t(`tools.database.addColumn`)),e.textContent=`+ `+this.i18n.t(`tools.database.addColumn`),e.style.minWidth=`260px`,e.style.flex=`0 0 260px`,t.appendChild(e)}return e.appendChild(t),e}appendRow(e,t){let n=this.createCardElement(t,this.titlePropertyId);e.appendChild(n),this.updateColumnCount(e)}removeRow(e,t){let n=e.querySelector(`[data-row-id="${t}"]`),r=n==null?void 0:n.closest(`[data-blok-database-cards]`);n==null||n.remove(),r!==null&&this.updateColumnCount(r)}updateRowTitle(e,t,n){let r=e.querySelector(`[data-row-id="${t}"]`),i=r==null?void 0:r.querySelector(`[data-blok-database-card-title]`);i!=null&&(n?(i.textContent=n,i.removeAttribute(`data-placeholder`),r==null||r.removeAttribute(`data-empty`)):(i.textContent=this.i18n.t(`tools.database.cardTitlePlaceholder`),i.setAttribute(`data-placeholder`,``),r==null||r.setAttribute(`data-empty`,``)))}appendGroup(e,t){let n=this.createColumnElement(t,[],``),r=e.querySelector(`[data-blok-database-board]`),i=r==null?e:r,a=i.querySelector(`[data-blok-database-add-column]`);a?i.insertBefore(n,a):i.appendChild(n)}removeGroup(e,t){let n=e.querySelector(`[data-option-id="${t}"]`);n==null||n.remove()}createColumnElement(e,n,r){let i=document.createElement(`div`);i.setAttribute(`data-blok-database-column`,``),i.setAttribute(`data-option-id`,e.id),i.setAttribute(`role`,`group`),i.setAttribute(`aria-label`,e.label),i.style.display=`flex`,i.style.flexDirection=`column`,i.style.minWidth=`260px`,i.style.flex=`0 0 260px`,e.color!==void 0&&(i.style.backgroundColor=`var(--blok-color-${e.color}-bg)`,i.setAttribute(`data-color`,e.color));let a=document.createElement(`div`);a.setAttribute(`data-blok-database-column-header`,``),a.style.display=`flex`,a.style.alignItems=`center`,a.style.padding=`0 0 6px 0`,a.style.borderRadius=`4px`,a.style.gap=`6px`,a.style.cursor=`grab`;let o=document.createElement(`div`);if(o.setAttribute(`data-blok-database-column-pill`,``),e.color!==void 0){o.style.backgroundColor=`color-mix(in srgb, var(--blok-color-${e.color}-text) 20%, var(--blok-color-${e.color}-bg))`,o.style.color=`var(--blok-color-${e.color}-text)`;let t=document.createElement(`span`);t.setAttribute(`data-blok-database-column-dot`,``),t.style.backgroundColor=`var(--blok-color-${e.color}-text)`,o.appendChild(t)}let s=document.createElement(`div`);s.setAttribute(`data-blok-database-column-title`,``),s.textContent=e.label,o.appendChild(s),a.appendChild(o);let c=document.createElement(`span`);c.setAttribute(`data-blok-database-column-count`,``),c.textContent=String(n.length),e.color!==void 0&&(c.style.color=`var(--blok-color-${e.color}-text)`),a.appendChild(c),i.appendChild(a);let l=document.createElement(`div`);l.setAttribute(`data-blok-database-cards`,``),l.setAttribute(`role`,`list`),l.style.display=`flex`,l.style.flexDirection=`column`,l.style.gap=`8px`,l.style.paddingTop=`6px`,l.style.minHeight=`40px`;for(let e of n){let t=this.createCardElement(e,r);l.appendChild(t)}if(i.appendChild(l),!this.readOnly){let n=document.createElement(`button`);n.setAttribute(`data-blok-database-add-card`,``),n.setAttribute(`data-option-id`,e.id),n.setAttribute(`aria-label`,this.i18n.t(`tools.database.addCard`));let r=document.createElement(`span`);r.setAttribute(`data-blok-database-add-card-icon`,``),r.innerHTML=t.sn,n.appendChild(r);let a=document.createElement(`span`);a.textContent=this.i18n.t(`tools.database.newPage`),n.appendChild(a),e.color!==void 0&&(n.style.borderColor=`color-mix(in srgb, var(--blok-color-${e.color}-text) 30%, transparent)`,n.style.color=`var(--blok-color-${e.color}-text)`),i.appendChild(n)}return i}createCardElement(e,n){var r;let i=document.createElement(`div`),a=(r=e.properties[n])==null?``:r;i.setAttribute(`data-blok-database-card`,``),i.setAttribute(`data-row-id`,e.id),i.setAttribute(`role`,`listitem`),i.style.padding=`10px 12px`,i.style.borderRadius=`10px`,i.style.cursor=`pointer`,i.style.position=`relative`,i.style.backgroundColor=`var(--blok-database-card-bg)`,i.style.boxShadow=`var(--blok-database-card-shadow)`;let o=document.createElement(`div`);if(o.setAttribute(`data-blok-database-card-title`,``),a?o.textContent=a:(o.textContent=this.i18n.t(`tools.database.cardTitlePlaceholder`),o.setAttribute(`data-placeholder`,``),i.setAttribute(`data-empty`,``)),i.appendChild(o),!this.readOnly){let n=document.createElement(`div`);n.setAttribute(`data-blok-database-card-actions`,``);let r=document.createElement(`button`);r.setAttribute(`data-blok-database-edit-card`,``),r.setAttribute(`data-row-id`,e.id),r.setAttribute(`aria-label`,this.i18n.t(`tools.database.editCardTitle`)),r.innerHTML=t.an,r.addEventListener(`click`,t=>{t.stopPropagation(),this.startCardTitleEdit(i,e.id)});let a=document.createElement(`button`);a.setAttribute(`data-blok-database-card-menu`,``),a.setAttribute(`data-row-id`,e.id),a.setAttribute(`aria-label`,this.i18n.t(`tools.database.cardMenuLabel`)),a.innerHTML=t.lt,n.appendChild(r),n.appendChild(a),i.appendChild(n)}return i}startCardTitleEdit(e,t){var n;let r=e.querySelector(`[data-blok-database-card-title]`);if(r===null)return;let i=(n=r.textContent)==null?``:n,a=document.createElement(`input`);a.type=`text`,a.value=i,a.setAttribute(`data-blok-database-card-title-input`,``),a.setAttribute(`aria-label`,this.i18n.t(`tools.database.editCardTitle`)),a.style.width=`100%`,a.style.boxSizing=`border-box`;let o={committed:!1},s=()=>{if(o.committed)return;o.committed=!0;let n=a.value.trim()||i,r=document.createElement(`div`);if(r.setAttribute(`data-blok-database-card-title`,``),r.textContent=n,a.replaceWith(r),n!==i){var s;(s=this.onTitleEdit)==null||s.call(this,t,n)}n&&e.removeAttribute(`data-empty`)},c=()=>{if(o.committed)return;o.committed=!0;let e=document.createElement(`div`);e.setAttribute(`data-blok-database-card-title`,``),e.textContent=i,a.replaceWith(e)};a.addEventListener(`blur`,s),a.addEventListener(`keydown`,e=>{e.stopPropagation(),e.key===`Enter`?(a.removeEventListener(`blur`,s),s()):e.key===`Escape`&&(a.removeEventListener(`blur`,s),c())}),r.replaceWith(a),a.focus(),a.select()}updateColumnCount(e){let t=e.closest(`[data-blok-database-column]`);if(t===null)return;let n=t.querySelector(`[data-blok-database-column-count]`);if(n!==null){let t=e.querySelectorAll(`[data-blok-database-card]`).length;n.textContent=String(t)}}},Ni=class{constructor({readOnly:e,i18n:t,rows:n,titlePropertyId:r,schema:i,visiblePropertyIds:a,options:o,getRows:s}){this.readOnly=e,this.i18n=t,this.rows=n,this.titlePropertyId=r,this.schema=i,this.visiblePropertyIds=a,this.groupOptions=o,this.getGroupRows=s}createView(){let e=document.createElement(`div`);if(e.setAttribute(`data-blok-database-list`,``),this.groupOptions!==void 0&&this.groupOptions.length>0&&this.getGroupRows!==void 0)for(let t of this.groupOptions){let n=this.getGroupRows(t.id),r=this.createGroupElement(t,n);e.appendChild(r)}else{e.setAttribute(`role`,`list`),e.setAttribute(`aria-label`,this.i18n.t(`tools.database.listView`));for(let t of this.rows){let n=this.createRowElement(t);e.appendChild(n)}if(!this.readOnly){let t=this.createAddRowButton();e.appendChild(t)}}return e}createGroupElement(e,t){let n=document.createElement(`div`);n.setAttribute(`data-blok-database-list-group`,``),n.setAttribute(`data-option-id`,e.id);let r=document.createElement(`div`);r.setAttribute(`data-blok-database-list-group-header`,``);let i=document.createElement(`span`);i.setAttribute(`data-blok-database-list-group-toggle`,``),i.textContent=`▼`;let a=document.createElement(`span`);a.setAttribute(`data-blok-database-list-group-dot`,``),e.color!==void 0&&(a.style.backgroundColor=`var(--blok-color-${e.color}-text)`);let o=document.createElement(`span`);o.setAttribute(`data-blok-database-list-group-title`,``),o.textContent=e.label;let s=document.createElement(`span`);s.setAttribute(`data-blok-database-list-group-count`,``),s.textContent=String(t.length),r.appendChild(i),r.appendChild(a),r.appendChild(o),r.appendChild(s);let c=document.createElement(`div`);c.setAttribute(`data-blok-database-list-rows`,``),c.setAttribute(`role`,`list`);for(let e of t){let t=this.createRowElement(e);c.appendChild(t)}let l=this.readOnly?null:this.createAddRowButton(e.id);return r.addEventListener(`click`,()=>{let e=c.style.display===`none`;c.style.display=e?``:`none`,i.textContent=e?`▼`:`▶`,l!==null&&(l.style.display=e?``:`none`)}),n.appendChild(r),n.appendChild(c),l!==null&&n.appendChild(l),n}appendRow(e,t){let n=this.createRowElement(t),r=e.querySelector(`[data-blok-database-add-row]`);r===null?e.appendChild(n):e.insertBefore(n,r)}removeRow(e,t){let n=e.querySelector(`[data-row-id="${t}"]`);n==null||n.remove()}updateRowTitle(e,t,n){let r=e.querySelector(`[data-row-id="${t}"]`),i=r==null?void 0:r.querySelector(`[data-blok-database-list-row-title]`);i!=null&&(n?(i.textContent=n,i.removeAttribute(`data-placeholder`)):(i.textContent=this.i18n.t(`tools.database.rowTitlePlaceholder`),i.setAttribute(`data-placeholder`,``)))}createRowElement(e){var t;let n=document.createElement(`div`),r=(t=e.properties[this.titlePropertyId])==null?``:t;n.setAttribute(`data-blok-database-list-row`,``),n.setAttribute(`data-row-id`,e.id),n.setAttribute(`role`,`listitem`);let i=document.createElement(`div`);i.setAttribute(`data-blok-database-list-row-title`,``),r?i.textContent=r:(i.textContent=this.i18n.t(`tools.database.rowTitlePlaceholder`),i.setAttribute(`data-placeholder`,``)),n.appendChild(i);let a=this.createPropertiesElement(e);return n.appendChild(a),n}createPropertiesElement(e){let t=document.createElement(`div`);t.setAttribute(`data-blok-database-list-row-properties`,``);for(let n of this.visiblePropertyIds){let r=this.schema.find(e=>e.id===n);if(r===void 0)continue;let i=e.properties[n],a=this.createPropertyBadge(r,i);a!==null&&t.appendChild(a)}let n=document.createElement(`button`);if(n.setAttribute(`data-blok-database-list-row-open`,``),n.setAttribute(`aria-label`,this.i18n.t(`tools.database.openRow`)),t.appendChild(n),!this.readOnly){let n=document.createElement(`button`);n.setAttribute(`data-blok-database-delete-row`,``),n.setAttribute(`data-row-id`,e.id),n.setAttribute(`aria-label`,this.i18n.t(`tools.database.deleteRow`)),n.textContent=`×`,t.appendChild(n)}return t}createPropertyBadge(e,t){if(t==null)return null;let n=document.createElement(`span`);if(n.setAttribute(`data-blok-database-list-row-property`,``),n.setAttribute(`data-property-id`,e.id),e.type===`select`){var r,i;let a=((r=(i=e.config)==null?void 0:i.options)==null?[]:r).find(e=>e.id===t);if(a===void 0)return null;n.textContent=a.label,a.color!==void 0&&(n.style.backgroundColor=`var(--blok-color-${a.color}-bg)`,n.style.color=`var(--blok-color-${a.color}-text)`)}else if(e.type===`checkbox`){let e=document.createElement(`input`);e.type=`checkbox`,e.checked=t===!0,n.appendChild(e)}else if(typeof t==`string`||typeof t==`number`)n.textContent=String(t);else return null;return n}createAddRowButton(e){let t=document.createElement(`button`);return t.setAttribute(`data-blok-database-add-row`,``),t.setAttribute(`aria-label`,this.i18n.t(`tools.database.addRow`)),t.textContent=`+ `+this.i18n.t(`tools.database.newRow`),e!==void 0&&t.setAttribute(`data-option-id`,e),t}},Pi=500,Fi=class{constructor(e,t){this.pendingTimers=new Map,this.pendingUpdates=new Map,this.pendingPropertyTimers=new Map,this.pendingPropertyUpdates=new Map,this.adapter=e,this.onError=t}async safeCall(e){var t=this;if(t.adapter!==void 0)try{return await e(t.adapter)}catch(e){var n;(n=t.onError)==null||n.call(t,e);return}}async syncLoadDatabase(){return this.safeCall(e=>e.loadDatabase())}async syncCreateRow(e){return this.safeCall(t=>t.createRow(e))}syncUpdateRow(e){if(this.adapter===void 0)return;let{rowId:t}=e,r=this.pendingTimers.get(t);r!==void 0&&clearTimeout(r);let i=this.pendingUpdates.get(t);this.pendingUpdates.set(t,i===void 0?e:n.t(n.t(n.t({},i),e),{},{properties:n.t(n.t({},i.properties),e.properties)})),this.pendingTimers.set(t,setTimeout(()=>{this.flushRow(t)},Pi))}async syncMoveRow(e){var t=this;return t.flushRow(e.rowId),t.safeCall(t=>t.moveRow(e))}async syncDeleteRow(e){await this.safeCall(t=>t.deleteRow(e))}async syncCreateProperty(e){return this.safeCall(t=>t.createProperty(e))}async syncUpdateProperty(e){return this.safeCall(t=>t.updateProperty(e))}syncUpdatePropertyDebounced(e){if(this.adapter===void 0)return;let{propertyId:t}=e,n=this.pendingPropertyTimers.get(t);n!==void 0&&clearTimeout(n),this.pendingPropertyUpdates.set(t,e),this.pendingPropertyTimers.set(t,setTimeout(()=>{this.flushProperty(t)},Pi))}async syncDeleteProperty(e){await this.safeCall(t=>t.deleteProperty(e))}async syncCreateView(e){return this.safeCall(t=>t.createView(e))}async syncUpdateView(e){return this.safeCall(t=>t.updateView(e))}async syncDeleteView(e){await this.safeCall(t=>t.deleteView(e))}flushPendingUpdates(){for(let e of this.pendingTimers.keys())this.flushRow(e)}flushPendingPropertyUpdates(){for(let e of this.pendingPropertyTimers.keys())this.flushProperty(e)}destroy(){for(let e of this.pendingTimers.values())clearTimeout(e);this.pendingTimers.clear(),this.pendingUpdates.clear();for(let e of this.pendingPropertyTimers.values())clearTimeout(e);this.pendingPropertyTimers.clear(),this.pendingPropertyUpdates.clear()}flushRow(e){let t=this.pendingTimers.get(e);t!==void 0&&clearTimeout(t),this.pendingTimers.delete(e);let n=this.pendingUpdates.get(e);this.pendingUpdates.delete(e),n!==void 0&&this.safeCall(e=>e.updateRow(n))}flushProperty(e){let t=this.pendingPropertyTimers.get(e);t!==void 0&&clearTimeout(t),this.pendingPropertyTimers.delete(e);let n=this.pendingPropertyUpdates.get(e);this.pendingPropertyUpdates.delete(e),n!==void 0&&this.safeCall(e=>e.updateProperty(n))}},Ii=10,Li=class{constructor(e){this.isDragging=!1,this.rowId=``,this.startX=0,this.startY=0,this.ghostEl=null,this.sourceCard=null,this.sourceCardHeight=0,this.ghostOffsetX=0,this.ghostOffsetY=0,this.gapTarget=null,this.gapContainer=null,this.wrapper=e.wrapper,this.onDrop=e.onDrop,this.boundPointerMove=this.handlePointerMove.bind(this),this.boundPointerUp=this.handlePointerUp.bind(this),this.boundPointerCancel=this.handlePointerCancel.bind(this),this.boundKeyDown=this.handleKeyDown.bind(this)}beginTracking(e,t,n){this.cleanup(),this.rowId=e,this.startX=t,this.startY=n,this.isDragging=!1,this.sourceCard=this.wrapper.querySelector(`[data-row-id="${e}"]`),document.addEventListener(`pointermove`,this.boundPointerMove),document.addEventListener(`pointerup`,this.boundPointerUp),document.addEventListener(`pointercancel`,this.boundPointerCancel),document.addEventListener(`keydown`,this.boundKeyDown)}cleanup(){var e;document.removeEventListener(`pointermove`,this.boundPointerMove),document.removeEventListener(`pointerup`,this.boundPointerUp),document.removeEventListener(`pointercancel`,this.boundPointerCancel),document.removeEventListener(`keydown`,this.boundKeyDown),(e=this.ghostEl)==null||e.remove(),this.ghostEl=null,this.clearGap(),this.wrapper.removeAttribute(`data-blok-database-dragging`),this.sourceCard&&(this.sourceCard.style.opacity=``,this.sourceCard=null),this.isDragging=!1,this.rowId=``,this.sourceCardHeight=0,this.ghostOffsetX=0,this.ghostOffsetY=0}destroy(){this.cleanup()}handlePointerMove(e){let t=Math.abs(e.clientX-this.startX),n=Math.abs(e.clientY-this.startY);!this.isDragging&&(t>Ii||n>Ii)&&(this.isDragging=!0,this.startActiveDrag(e)),this.isDragging&&(this.updateGhostPosition(e),this.updateDropIndicator(e))}handlePointerUp(e){this.isDragging&&this.commitDrop(e),this.cleanup()}handlePointerCancel(){this.cleanup()}handleKeyDown(e){e.key===`Escape`&&this.cleanup()}startActiveDrag(e){if(this.sourceCard){let e=this.sourceCard.getBoundingClientRect();this.sourceCardHeight=e.height,this.ghostOffsetX=this.startX-e.left,this.ghostOffsetY=this.startY-e.top,this.sourceCard.style.opacity=`0.4`}this.wrapper.setAttribute(`data-blok-database-dragging`,``),this.createGhost(e)}createGhost(e){let t=document.createElement(`div`);t.setAttribute(`data-blok-database-ghost`,``),t.setAttribute(`contenteditable`,`false`);let n=t.style;if(n.position=`fixed`,n.pointerEvents=`none`,n.opacity=`0.85`,n.zIndex=`50`,n.boxShadow=`0 12px 28px rgba(0, 0, 0, 0.2), 0 4px 10px rgba(0, 0, 0, 0.1)`,n.borderRadius=`8px`,n.overflow=`hidden`,n.transform=`rotate(2deg) scale(1.02)`,n.transformOrigin=`center center`,this.sourceCard){let r=this.sourceCard.cloneNode(!0);r.style.opacity=``,t.appendChild(r);let i=this.sourceCard.getBoundingClientRect();n.left=`${e.clientX-this.ghostOffsetX}px`,n.top=`${e.clientY-this.ghostOffsetY}px`,n.width=`${i.width}px`}else n.left=`${e.clientX}px`,n.top=`${e.clientY}px`;document.body.appendChild(t),this.ghostEl=t}updateGhostPosition(e){this.ghostEl&&(this.ghostEl.style.left=`${e.clientX-this.ghostOffsetX}px`,this.ghostEl.style.top=`${e.clientY-this.ghostOffsetY}px`)}updateDropIndicator(e){let t=this.findTargetColumn(e.clientX);if(!t){this.clearGap();return}let n=this.getDropPosition(t,e.clientY).beforeEl;if(n){if(n===this.gapTarget)return;this.clearGap(),n.style.marginTop=`${this.sourceCardHeight}px`,this.gapTarget=n}else{let e=t.querySelector(`[data-blok-database-cards]`);if(!e){this.clearGap();return}if(e===this.gapContainer)return;this.clearGap(),e.style.paddingBottom=`${this.sourceCardHeight}px`,this.gapContainer=e}}clearGap(){this.gapTarget&&(this.gapTarget.style.marginTop=``,this.gapTarget=null),this.gapContainer&&(this.gapContainer.style.paddingBottom=``,this.gapContainer=null)}findTargetColumn(e){let t=Array.from(this.wrapper.querySelectorAll(`[data-blok-database-column]`));for(let n of t){let t=n.getBoundingClientRect();if(e>=t.left&&e<=t.right)return n}return null}getDropPosition(e,t){let n=Array.from(e.querySelectorAll(`[data-blok-database-card]`)).filter(e=>e.getAttribute(`data-row-id`)!==this.rowId);for(let e of n){let n=e.getBoundingClientRect();if(t<n.top+n.height/2)return{beforeEl:e}}return{beforeEl:null}}resolveAfterRowId(e,t,n){return e?n>0?t[n-1].getAttribute(`data-row-id`):null:t.length>0?t[t.length-1].getAttribute(`data-row-id`):null}commitDrop(e){var t;let n=this.findTargetColumn(e.clientX);if(!n)return;let r=(t=n.getAttribute(`data-option-id`))==null?``:t,i=this.getDropPosition(n,e.clientY),a=Array.from(n.querySelectorAll(`[data-blok-database-card]`)).filter(e=>e.getAttribute(`data-row-id`)!==this.rowId),o=i.beforeEl?i.beforeEl.getAttribute(`data-row-id`):null,s=i.beforeEl?a.indexOf(i.beforeEl):-1,c=this.resolveAfterRowId(i.beforeEl,a,s);this.onDrop({rowId:this.rowId,toOptionId:r,beforeRowId:o,afterRowId:c})}},Ri=10,zi=class{constructor(e){this.isDragging=!1,this.optionId=``,this.startX=0,this.startY=0,this.ghostEl=null,this.sourceColumn=null,this.sourceColumnWidth=0,this.ghostOffsetX=0,this.gapTarget=null,this.gapContainer=null,this.wrapper=e.wrapper,this.onDrop=e.onDrop,this.boundPointerMove=this.handlePointerMove.bind(this),this.boundPointerUp=this.handlePointerUp.bind(this),this.boundPointerCancel=this.handlePointerCancel.bind(this),this.boundKeyDown=this.handleKeyDown.bind(this)}beginTracking(e,t,n){this.cleanup(),this.optionId=e,this.startX=t,this.startY=n,this.isDragging=!1,this.sourceColumn=this.wrapper.querySelector(`[data-option-id="${e}"]`),document.addEventListener(`pointermove`,this.boundPointerMove),document.addEventListener(`pointerup`,this.boundPointerUp),document.addEventListener(`pointercancel`,this.boundPointerCancel),document.addEventListener(`keydown`,this.boundKeyDown)}cleanup(){var e;document.removeEventListener(`pointermove`,this.boundPointerMove),document.removeEventListener(`pointerup`,this.boundPointerUp),document.removeEventListener(`pointercancel`,this.boundPointerCancel),document.removeEventListener(`keydown`,this.boundKeyDown),(e=this.ghostEl)==null||e.remove(),this.ghostEl=null,this.clearGap(),this.wrapper.removeAttribute(`data-blok-database-column-reordering`),this.sourceColumn&&(this.sourceColumn.style.opacity=``,this.sourceColumn=null),this.isDragging=!1,this.optionId=``,this.sourceColumnWidth=0,this.ghostOffsetX=0}destroy(){this.cleanup()}handlePointerMove(e){let t=Math.abs(e.clientX-this.startX);!this.isDragging&&t>Ri&&(this.isDragging=!0,this.startActiveDrag(e)),this.isDragging&&(this.updateGhostPosition(e),this.updateDropIndicator(e.clientX))}handlePointerUp(e){this.isDragging&&this.commitDrop(e),this.cleanup()}handlePointerCancel(){this.cleanup()}handleKeyDown(e){e.key===`Escape`&&this.cleanup()}startActiveDrag(e){if(this.sourceColumn){let e=this.sourceColumn.getBoundingClientRect();this.sourceColumnWidth=e.width,this.ghostOffsetX=this.startX-e.left,this.sourceColumn.style.opacity=`0.4`}this.wrapper.setAttribute(`data-blok-database-column-reordering`,``),this.createGhost(e)}createGhost(e){let t=document.createElement(`div`);t.setAttribute(`data-blok-database-column-ghost`,``),t.setAttribute(`contenteditable`,`false`);let n=t.style;if(n.position=`fixed`,n.pointerEvents=`none`,n.opacity=`0.85`,n.zIndex=`50`,n.boxShadow=`0 12px 28px rgba(0, 0, 0, 0.2), 0 4px 10px rgba(0, 0, 0, 0.1)`,n.borderRadius=`10px`,n.overflow=`hidden`,n.transform=`rotate(1deg) scale(1.02)`,n.transformOrigin=`center center`,this.sourceColumn){let r=this.sourceColumn.cloneNode(!0);r.style.opacity=``,t.appendChild(r);let i=this.sourceColumn.getBoundingClientRect();n.left=`${e.clientX-this.ghostOffsetX}px`,n.top=`${i.top}px`,n.width=`${i.width}px`}else n.left=`${e.clientX}px`,n.top=`${e.clientY}px`;document.body.appendChild(t),this.ghostEl=t}updateGhostPosition(e){this.ghostEl&&(this.ghostEl.style.left=`${e.clientX-this.ghostOffsetX}px`)}updateDropIndicator(e){let t=this.getDropPosition(e);if(t.beforeColumn){if(t.beforeColumn===this.gapTarget)return;this.clearGap(),t.beforeColumn.style.marginLeft=`${this.sourceColumnWidth}px`,this.gapTarget=t.beforeColumn}else this.applyEndGap()}applyEndGap(){let e=this.wrapper.querySelector(`[data-blok-database-board]`);!e||e===this.gapContainer||(this.clearGap(),e.style.paddingRight=`${this.sourceColumnWidth}px`,this.gapContainer=e)}clearGap(){this.gapTarget&&(this.gapTarget.style.marginLeft=``,this.gapTarget=null),this.gapContainer&&(this.gapContainer.style.paddingRight=``,this.gapContainer=null)}getDropPosition(e){let t=Array.from(this.wrapper.querySelectorAll(`[data-blok-database-column]`)).filter(e=>e.getAttribute(`data-option-id`)!==this.optionId);for(let n of t){let r=n.getBoundingClientRect();if(e<r.left+r.width/2){let e=t.indexOf(n);return{beforeColumn:n,afterColumn:e>0?t[e-1]:null}}}return{beforeColumn:null,afterColumn:t.length>0?t[t.length-1]:null}}commitDrop(e){let t=this.getDropPosition(e.clientX),n=t.beforeColumn?t.beforeColumn.getAttribute(`data-option-id`):null,r=t.afterColumn?t.afterColumn.getAttribute(`data-option-id`):null;this.onDrop({optionId:this.optionId,beforeOptionId:n,afterOptionId:r})}},Bi=class{constructor(e){this.options=e,this.i18n=e.i18n}makeEditable(e,t){let n=e.querySelector(`[data-blok-database-column-title]`);if(n){var r;let e=document.createElement(`input`);e.type=`text`,e.value=(r=n.textContent)==null?``:r,e.setAttribute(`data-blok-database-column-title-input`,``),e.setAttribute(`aria-label`,this.i18n.t(`tools.database.renameColumn`));let i=()=>{e.size=Math.max(e.value.length,1)};i(),e.addEventListener(`input`,i),e.addEventListener(`change`,()=>{this.options.onRename(t,e.value)}),n.replaceWith(e)}this.appendDeleteButton(e,t)}appendDeleteButton(e,t){let n=document.createElement(`button`);n.setAttribute(`data-blok-database-delete-column`,``),n.setAttribute(`aria-label`,this.i18n.t(`tools.database.deleteColumn`)),n.setAttribute(`data-option-id`,t),n.addEventListener(`click`,()=>{this.options.onDelete(t)}),e.appendChild(n)}makePillTitleEditable(e,t){let n=e.querySelector(`[data-blok-database-column-title]`);n!==null&&(n.style.cursor=`text`,n.addEventListener(`click`,r=>{var i;r.stopPropagation();let a=(i=n.textContent)==null?``:i,o=document.createElement(`input`);o.type=`text`,o.value=a,o.setAttribute(`data-blok-database-column-title-input`,``),o.setAttribute(`aria-label`,this.i18n.t(`tools.database.renameColumn`));let s=()=>{o.size=Math.max(o.value.length,1)};s(),o.addEventListener(`input`,s),o.addEventListener(`input`,()=>{var e,n;(e=(n=this.options).onRenameInput)==null||e.call(n,t,o.value)});let c={done:!1},l=e=>{let t=document.createElement(`div`);return t.setAttribute(`data-blok-database-column-title`,``),t.style.cursor=`text`,t.textContent=e,t},u=()=>{if(c.done)return;c.done=!0;let n=o.value.trim()||a,r=l(n);if(o.replaceWith(r),this.makePillTitleEditable(e,t),n!==a){var i,s;(i=(s=this.options).onRenameCommit)==null||i.call(s,t,n),this.options.onRename(t,n)}},d=()=>{if(c.done)return;c.done=!0;let n=l(a);o.replaceWith(n),this.makePillTitleEditable(e,t)};o.addEventListener(`blur`,u),o.addEventListener(`keydown`,e=>{e.stopPropagation(),e.key===`Enter`?u():e.key===`Escape`&&(o.removeEventListener(`blur`,u),d())}),n.replaceWith(o),o.focus(),o.select()}))}destroy(){}},Vi=10,Hi=class{constructor(e){this.isDragging=!1,this.rowId=``,this.startY=0,this.ghostEl=null,this.sourceRow=null,this.sourceRowHeight=0,this.ghostOffsetY=0,this.gapTarget=null,this.wrapper=e.wrapper,this.onDrop=e.onDrop,this.boundPointerMove=this.handlePointerMove.bind(this),this.boundPointerUp=this.handlePointerUp.bind(this),this.boundPointerCancel=this.handlePointerCancel.bind(this),this.boundKeyDown=this.handleKeyDown.bind(this)}beginTracking(e,t,n){this.cleanup(),this.rowId=e,this.startY=n,this.isDragging=!1,this.sourceRow=this.wrapper.querySelector(`[data-row-id="${e}"]`),document.addEventListener(`pointermove`,this.boundPointerMove),document.addEventListener(`pointerup`,this.boundPointerUp),document.addEventListener(`pointercancel`,this.boundPointerCancel),document.addEventListener(`keydown`,this.boundKeyDown)}cleanup(){var e;document.removeEventListener(`pointermove`,this.boundPointerMove),document.removeEventListener(`pointerup`,this.boundPointerUp),document.removeEventListener(`pointercancel`,this.boundPointerCancel),document.removeEventListener(`keydown`,this.boundKeyDown),(e=this.ghostEl)==null||e.remove(),this.ghostEl=null,this.clearGap(),this.sourceRow&&(this.sourceRow.style.opacity=``,this.sourceRow=null),this.isDragging=!1,this.rowId=``,this.sourceRowHeight=0,this.ghostOffsetY=0}destroy(){this.cleanup()}handlePointerMove(e){let t=Math.abs(e.clientY-this.startY);!this.isDragging&&t>Vi&&(this.isDragging=!0,this.startActiveDrag(e)),this.isDragging&&(this.updateGhostPosition(e),this.updateDropIndicator(e))}handlePointerUp(e){this.isDragging&&this.commitDrop(e),this.cleanup()}handlePointerCancel(){this.cleanup()}handleKeyDown(e){e.key===`Escape`&&this.cleanup()}startActiveDrag(e){if(this.sourceRow){let e=this.sourceRow.getBoundingClientRect();this.sourceRowHeight=e.height,this.ghostOffsetY=this.startY-e.top,this.sourceRow.style.opacity=`0.4`}this.createGhost(e)}createGhost(e){let t=document.createElement(`div`);t.setAttribute(`data-blok-database-ghost`,``),t.setAttribute(`contenteditable`,`false`);let n=t.style;if(n.position=`fixed`,n.pointerEvents=`none`,n.opacity=`0.85`,n.zIndex=`50`,n.boxShadow=`0 12px 28px rgba(0, 0, 0, 0.2), 0 4px 10px rgba(0, 0, 0, 0.1)`,n.borderRadius=`8px`,n.overflow=`hidden`,this.sourceRow){let r=this.sourceRow.cloneNode(!0);r.style.opacity=``,t.appendChild(r);let i=this.sourceRow.getBoundingClientRect();n.left=`${i.left}px`,n.top=`${e.clientY-this.ghostOffsetY}px`,n.width=`${i.width}px`}else n.left=`0px`,n.top=`${e.clientY}px`;document.body.appendChild(t),this.ghostEl=t}updateGhostPosition(e){this.ghostEl&&(this.ghostEl.style.top=`${e.clientY-this.ghostOffsetY}px`)}updateDropIndicator(e){let t=this.getDropPosition(e.clientY).beforeEl;if(t){if(t===this.gapTarget)return;this.clearGap(),t.style.marginTop=`${this.sourceRowHeight}px`,this.gapTarget=t}else this.clearGap()}clearGap(){this.gapTarget&&(this.gapTarget.style.marginTop=``,this.gapTarget=null)}getDropPosition(e){let t=Array.from(this.wrapper.querySelectorAll(`[data-blok-database-list-row]`)).filter(e=>e.getAttribute(`data-row-id`)!==this.rowId);for(let n of t){let t=n.getBoundingClientRect();if(e<t.top+t.height/2)return{beforeEl:n}}return{beforeEl:null}}commitDrop(e){let t=this.getDropPosition(e.clientY),n=Array.from(this.wrapper.querySelectorAll(`[data-blok-database-list-row]`)).filter(e=>e.getAttribute(`data-row-id`)!==this.rowId),r=t.beforeEl?t.beforeEl.getAttribute(`data-row-id`):null,i=t.beforeEl?n.indexOf(t.beforeEl):-1,a=this.resolveAfterRowId(t.beforeEl,n,i);this.onDrop({rowId:this.rowId,beforeRowId:r,afterRowId:a})}resolveAfterRowId(e,t,n){return e?n>0?t[n-1].getAttribute(`data-row-id`):null:t.length>0?t[t.length-1].getAttribute(`data-row-id`):null}},Ui=[{type:`text`,icon:t.vn,labelKey:`tools.database.propertyTypeText`},{type:`number`,icon:t.kt,labelKey:`tools.database.propertyTypeNumber`},{type:`select`,icon:t.pn,labelKey:`tools.database.propertyTypeSelect`},{type:`multiSelect`,icon:t.nn,labelKey:`tools.database.propertyTypeMultiSelect`},{type:`date`,icon:t.H,labelKey:`tools.database.propertyTypeDate`},{type:`checkbox`,icon:t.qt,labelKey:`tools.database.propertyTypeCheckbox`},{type:`url`,icon:t.St,labelKey:`tools.database.propertyTypeUrl`}],Wi=class{constructor(e){this.popoverEl=null,this.boundOutsideClick=null,this.onSelect=e.onSelect,this.i18n=e.i18n}open(e){var t,n;this.close();let r=document.createElement(`div`);r.setAttribute(`data-blok-popover`,``),r.setAttribute(`data-blok-popover-opened`,``),r.setAttribute(`data-blok-database-property-type-popover`,``),r.style.position=`fixed`,r.style.zIndex=`1000`;let i=e.getBoundingClientRect();r.style.top=`${i.bottom+4}px`,r.style.left=`${i.left}px`;let a=document.createElement(`div`);a.setAttribute(`data-blok-database-property-type-heading`,``),a.textContent=(t=(n=this.i18n)==null?void 0:n.t(`tools.database.propertyTypeHeading`))==null?`tools.database.propertyTypeHeading`:t,r.appendChild(a);for(let e of Ui){var o,s;let t=document.createElement(`div`);t.setAttribute(`data-blok-database-property-type-option`,e.type);let n=document.createElement(`div`);n.setAttribute(`data-blok-database-property-type-option-icon`,``),n.innerHTML=e.icon,t.appendChild(n);let i=document.createElement(`span`);i.textContent=(o=(s=this.i18n)==null?void 0:s.t(e.labelKey))==null?e.labelKey:o,t.appendChild(i),t.addEventListener(`click`,()=>{this.onSelect(e.type),this.close()}),r.appendChild(t)}document.body.appendChild(r),this.popoverEl=r,this.boundOutsideClick=t=>{let n=t.target;!r.contains(n)&&!e.contains(n)&&this.close()},document.addEventListener(`mousedown`,this.boundOutsideClick)}close(){this.popoverEl!==null&&(this.popoverEl.remove(),this.popoverEl=null),this.boundOutsideClick!==null&&(document.removeEventListener(`mousedown`,this.boundOutsideClick),this.boundOutsideClick=null)}destroy(){this.close()}},Gi=class{constructor(e){this.drawer=null,this.currentRowId=null,this.currentRow=null,this.blokInstance=null,this.escapeHandler=null,this.outsideClickHandler=null,this.propertyTypePopover=null,this.wrapper=e.wrapper,this.readOnly=e.readOnly,this.i18n=e.i18n,this.toolsConfig=e.toolsConfig,this.titlePropertyId=e.titlePropertyId,this.descriptionPropertyId=e.descriptionPropertyId,this.schema=e.schema,this.onTitleChange=e.onTitleChange,this.onDescriptionChange=e.onDescriptionChange,this.onClose=e.onClose,this.onAddProperty=e.onAddProperty}get isOpen(){return this.drawer!==null}open(e){var n,r,i,a,o,s,c;if(this.drawer){if(e.id===this.currentRowId)return;this.loadCard(e);return}let l=this.wrapper.querySelector(`[data-blok-database-drawer]`);l==null||l.remove(),this.currentRowId=e.id,this.currentRow=e,this.updateActiveCard(e.id);let u=(n=e.properties[this.titlePropertyId])==null?``:n,d=document.createElement(`div`);d.setAttribute(`data-blok-database-drawer`,``),d.setAttribute(`role`,`complementary`),d.setAttribute(`aria-label`,(r=(i=this.i18n)==null?void 0:i.t(`tools.database.cardDetails`))==null?`tools.database.cardDetails`:r);let f=document.createElement(`div`);f.setAttribute(`data-blok-database-drawer-toolbar`,``);let p=document.createElement(`button`);p.setAttribute(`data-blok-database-drawer-close`,``),p.setAttribute(`aria-label`,`Close`),p.innerHTML=t.X+t.X,p.addEventListener(`click`,()=>{this.close()}),f.appendChild(p),d.appendChild(f);let m=document.createElement(`div`);m.setAttribute(`data-blok-database-drawer-content`,``);let h=document.createElement(`textarea`);h.setAttribute(`data-blok-database-drawer-title`,``),h.setAttribute(`aria-label`,(a=(o=this.i18n)==null?void 0:o.t(`tools.database.cardTitle`))==null?`tools.database.cardTitle`:a),h.placeholder=(s=(c=this.i18n)==null?void 0:c.t(`tools.database.cardTitlePlaceholder`))==null?`Empty page`:s,h.value=u,h.rows=1,h.readOnly=this.readOnly,h.addEventListener(`input`,()=>{this.currentRowId!==null&&this.onTitleChange(this.currentRowId,h.value),this.autoResizeTitle(h)}),h.addEventListener(`keydown`,e=>{e.key===`Enter`&&e.preventDefault()}),m.appendChild(h);let g=this.getRenderableSchema();m.appendChild(this.buildPropsSection(g,e));let _=document.createElement(`hr`);m.appendChild(_);let v=document.createElement(`div`);v.setAttribute(`data-blok-database-drawer-editor`,``),m.appendChild(v),d.appendChild(m),this.wrapper.appendChild(d),this.drawer=d,requestAnimationFrame(()=>{d.style.width=`45%`,d.addEventListener(`transitionend`,()=>{this.autoResizeTitle(h),u||h.focus()},{once:!0})}),this.initNestedEditor(v,e),this.escapeHandler=e=>{if(e.key!==`Escape`)return;let t=e.target;t&&v.contains(t)||this.close()},document.addEventListener(`keydown`,this.escapeHandler),this.outsideClickHandler=e=>{let t=e.target;t&&d.contains(t)||t instanceof Element&&t.closest(`[data-blok-popover-opened]`)!==null||t instanceof Element&&t.closest(`[data-blok-database-tab-bar]`)!==null||this.close()},document.addEventListener(`mousedown`,this.outsideClickHandler),h.focus()}loadCard(e){var t,n,r;if(this.drawer===null)return;this.cleanupEditor(),this.currentRowId=e.id,this.currentRow=e,this.updateActiveCard(e.id);let i=(t=e.properties[this.titlePropertyId])==null?``:t,a=this.drawer.querySelector(`[data-blok-database-drawer-title]`);a!==null&&(a.value=i,this.autoResizeTitle(a),i||a.focus()),(n=this.drawer.querySelector(`[data-blok-database-drawer-props]`))==null||n.remove();let o=this.getRenderableSchema(),s=this.drawer.querySelector(`[data-blok-database-drawer-content]`),c=(r=s==null?void 0:s.querySelector(`hr`))==null?null:r;s!==null&&s.insertBefore(this.buildPropsSection(o,e),c);let l=this.drawer.querySelector(`[data-blok-database-drawer-editor]`);l!==null&&(l.innerHTML=``,this.initNestedEditor(l,e))}close(){let e=this.drawer!==null;if(this.updateActiveCard(null),this.cleanupListeners(),this.cleanupEditor(),this.drawer){let e=this.drawer;this.drawer=null,e.style.width=`0px`,e.addEventListener(`transitionend`,()=>{e.remove()},{once:!0})}this.currentRowId=null,this.currentRow=null,e&&this.onClose()}destroy(){var e;this.cleanupListeners(),this.cleanupEditor(),(e=this.propertyTypePopover)==null||e.destroy(),this.propertyTypePopover=null,this.drawer&&(this.drawer.remove(),this.drawer=null);let t=this.wrapper.querySelector(`[data-blok-database-drawer]`);t==null||t.remove(),this.currentRowId=null,this.currentRow=null}refreshSchema(e){var t,n;if(this.schema=e,this.drawer===null||this.currentRow===null)return;(t=this.drawer.querySelector(`[data-blok-database-drawer-props]`))==null||t.remove();let r=this.getRenderableSchema(),i=this.drawer.querySelector(`[data-blok-database-drawer-content]`),a=(n=i==null?void 0:i.querySelector(`hr`))==null?null:n;i!==null&&i.insertBefore(this.buildPropsSection(r,this.currentRow),a)}buildPropsSection(e,t){let n=document.createElement(`div`);n.setAttribute(`data-blok-database-drawer-props`,``);for(let i of e){var r;n.appendChild(this.createPropertyRow(i,(r=t.properties[i.id])==null?null:r))}if(!this.readOnly){let e=document.createElement(`button`);e.setAttribute(`data-blok-database-drawer-add-prop`,``),e.textContent=`+ Add a property`,e.addEventListener(`click`,()=>{this.propertyTypePopover===null&&(this.propertyTypePopover=new Wi({onSelect:e=>{var t,n;(t=this.onAddProperty)==null||t.call(this,e),(n=this.propertyTypePopover)==null||n.close()},i18n:this.i18n})),this.propertyTypePopover.open(e)}),n.appendChild(e)}return n}getRenderableSchema(){return[...this.schema].filter(e=>e.type!==`title`&&e.type!==`richText`).sort((e,t)=>e.position<t.position?-1:+(e.position>t.position))}createSelectPill(e){let t=document.createElement(`span`);if(t.setAttribute(`data-blok-database-drawer-prop-pill`,``),e.color!==void 0){t.style.backgroundColor=`var(--blok-color-${e.color}-bg)`,t.style.color=`var(--blok-color-${e.color}-text)`;let n=document.createElement(`span`);n.setAttribute(`data-blok-database-drawer-prop-dot`,``),n.style.backgroundColor=`var(--blok-color-${e.color}-text)`,t.appendChild(n)}let n=document.createElement(`span`);return n.textContent=e.label,t.appendChild(n),t}createPropertyRow(e,t){let n=document.createElement(`div`);n.setAttribute(`data-blok-database-drawer-prop-row`,``);let r=document.createElement(`span`);r.setAttribute(`data-blok-database-drawer-prop-label`,``),r.textContent=e.name,n.appendChild(r);let i=document.createElement(`span`);if(i.setAttribute(`data-blok-database-drawer-prop-value`,``),e.type===`select`){let n=e.config,r=typeof t==`string`?t:null,a=n==null?void 0:n.options.find(e=>e.id===r);a!==void 0&&i.appendChild(this.createSelectPill(a))}else if(e.type===`multiSelect`){let n=e.config;(Array.isArray(t)?t:[]).map(e=>n==null?void 0:n.options.find(t=>t.id===e)).filter(e=>e!==void 0).forEach(e=>i.appendChild(this.createSelectPill(e)))}else (typeof t==`string`||typeof t==`number`||typeof t==`boolean`)&&(i.textContent=String(t));return n.appendChild(i),n}updateActiveCard(e){let t=this.wrapper.querySelector(`[data-blok-database-card-active]`);if(t==null||t.removeAttribute(`data-blok-database-card-active`),e!==null){let t=this.wrapper.querySelector(`[data-blok-database-card][data-row-id="${e}"]`);t==null||t.setAttribute(`data-blok-database-card-active`,``)}}cleanupListeners(){this.escapeHandler&&(document.removeEventListener(`keydown`,this.escapeHandler),this.escapeHandler=null),this.outsideClickHandler&&(document.removeEventListener(`mousedown`,this.outsideClickHandler),this.outsideClickHandler=null)}cleanupEditor(){if(this.blokInstance){try{let e=this.blokInstance,t=this.currentRowId;e.save().then(n=>{t!==null&&this.onDescriptionChange(t,n),e.destroy()}).catch(()=>{e.destroy()})}catch(e){}this.blokInstance=null}}autoResizeTitle(e){let{style:t}=e;t.height=`auto`,e.scrollHeight>0&&(t.height=`${e.scrollHeight}px`)}initNestedEditor(e,t){var r=this;Promise.resolve().then(()=>require(`../blok.cjs`)).then(({Blok:i})=>{let a=t.id,o=this.descriptionPropertyId===void 0?void 0:t.properties[this.descriptionPropertyId],s=new i(n.t(n.t({},this.toolsConfig),{},{holder:e,data:o,readOnly:this.readOnly,onChange:async()=>{try{var e;let t=await((e=r.blokInstance)==null?void 0:e.save());t!==void 0&&r.onDescriptionChange(a,t)}catch(e){}}}));this.blokInstance=s}).catch(()=>{})}},Ki=class{constructor(e){this.boundKeydown=null,this.wrapper=e.wrapper,this.onEscape=e.onEscape}attach(){this.boundKeydown=e=>{e.key===`Escape`&&this.onEscape()&&e.stopPropagation()},this.wrapper.addEventListener(`keydown`,this.boundKeydown)}destroy(){this.boundKeydown&&(this.wrapper.removeEventListener(`keydown`,this.boundKeydown),this.boundKeydown=null)}},qi=[{type:`board`,icon:t.z,labelKey:`tools.database.viewTypeBoard`,descriptionKey:`tools.database.viewTypeBoardDescription`},{type:`list`,icon:t.Gt,labelKey:`tools.database.viewTypeList`,descriptionKey:`tools.database.viewTypeListDescription`}],Ji=class{constructor(e){this.popover=null,this.onSelect=e.onSelect,this.onClose=e.onClose,this.api=e.api}translate(e,t){var n,r;return(n=(r=this.api)==null?void 0:r.i18n.t(e))==null?t:n}open(e){this.close();let n=document.createElement(`div`);n.setAttribute(`data-blok-database-view-popover-heading`,``),n.textContent=this.translate(`tools.database.addView`,[`Add`,`view`].join(` `));let r=[{type:t.pr.Html,element:n},...qi.map(e=>{let n=this.createViewItem(e);return{type:t.pr.Html,element:n,closeOnActivate:!0}})];this.popover=new t.C({items:r,trigger:e,width:`auto`,minWidth:`200px`,flippable:!1,autoFocusFirstItem:!1}),this.popover.on(t.T.Closed,()=>{if(this.popover!==null){var e;let t=this.popover;this.popover=null,t.destroy(),(e=this.onClose)==null||e.call(this)}}),this.popover.show()}createViewItem(e){let t=document.createElement(`div`);t.setAttribute(`data-blok-database-view-option`,e.type);let n=document.createElement(`div`);n.setAttribute(`data-blok-database-view-option-icon`,``),n.innerHTML=e.icon,t.appendChild(n);let r=document.createElement(`div`);r.setAttribute(`data-blok-database-view-option-text`,``);let i=document.createElement(`span`);i.setAttribute(`data-blok-database-view-option-label`,``),i.textContent=this.translate(e.labelKey,``),r.appendChild(i);let a=document.createElement(`span`);return a.setAttribute(`data-blok-database-view-option-desc`,``),a.textContent=this.translate(e.descriptionKey,``),r.appendChild(a),t.appendChild(r),t.addEventListener(`click`,()=>{this.onSelect(e.type)}),t}close(){if(this.popover!==null){var e;let t=this.popover;this.popover=null,t.destroy(),(e=this.onClose)==null||e.call(this)}}destroy(){this.close()}},Yi=10,Xi={board:t.z,list:t.Gt},Zi=class{constructor(e){var t;this.element=null,this.barEl=null,this.addBtnEl=null,this.viewPopover=null,this.contextPopover=null,this.overflowDropdownEl=null,this.boundOverflowClose=null,this.moreBtnEl=null,this.isDragging=!1,this.dragViewId=``,this.dragStartX=0,this.ghostEl=null,this.options=e,this.views=e.views,this.onReorder=e.onReorder,this.readOnly=(t=e.readOnly)==null?!1:t,this.boundDragMove=this.handleDragMove.bind(this),this.boundDragUp=this.handleDragUp.bind(this),this.boundDragCancel=this.cleanupDrag.bind(this),this.boundDragKeyDown=e=>{e.key===`Escape`&&this.cleanupDrag()}}render(){let e=document.createElement(`div`);e.setAttribute(`data-blok-database-tab-bar`,``),this.barEl=e,this.element=e;let n=[...this.options.views].sort((e,t)=>e.position<t.position?-1:1);for(let t of n)e.appendChild(this.createTab(t));let r=document.createElement(`button`);return r.setAttribute(`data-blok-database-add-view`,``),r.innerHTML=t.sn,r.addEventListener(`click`,()=>{this.openViewPopover(r)}),this.addBtnEl=r,this.readOnly||e.appendChild(r),e.addEventListener(`click`,e=>{let t=e.target.closest(`[data-blok-database-tab]`);if(!(t instanceof HTMLElement))return;let n=t.getAttribute(`data-view-id`);n!==null&&(t.hasAttribute(`data-active`)||this.options.onTabClick(n))}),e.addEventListener(`contextmenu`,e=>{let t=e.target.closest(`[data-blok-database-tab]`);if(!(t instanceof HTMLElement))return;e.preventDefault();let n=t.getAttribute(`data-view-id`);n!==null&&this.openContextPopover(t,n)}),e.addEventListener(`dblclick`,e=>{let t=e.target.closest(`[data-blok-database-tab]`);if(!(t instanceof HTMLElement))return;let n=t.getAttribute(`data-view-id`);n!==null&&this.openContextPopover(t,n)}),e.addEventListener(`pointerdown`,e=>{let t=e.target.closest(`[data-blok-database-tab]`);if(t===null)return;let n=t.getAttribute(`data-view-id`);n!==null&&(this.dragViewId=n,this.dragStartX=e.clientX,this.isDragging=!1,document.addEventListener(`pointermove`,this.boundDragMove),document.addEventListener(`pointerup`,this.boundDragUp),document.addEventListener(`pointercancel`,this.boundDragCancel),document.addEventListener(`keydown`,this.boundDragKeyDown))}),typeof ResizeObserver<`u`&&new ResizeObserver(()=>{var e;if(this.element===null)return;let t=Array.from(this.element.querySelectorAll(`[data-blok-database-tab]`));for(let e of t)e.style.display=``;(e=this.moreBtnEl)==null||e.remove(),this.moreBtnEl=null;let n=this.element.clientWidth,r=t.findIndex((e,r)=>40+t.slice(0,r+1).reduce((e,t)=>e+t.offsetWidth+2,0)>n),i=r===-1?t.length:r;i<t.length&&this.handleOverflow(i)}).observe(e),e}createTab(e){var t;let n=document.createElement(`div`);n.setAttribute(`data-blok-database-tab`,``),n.setAttribute(`data-view-id`,e.id),e.id===this.options.activeViewId&&n.setAttribute(`data-active`,``);let r=document.createElement(`span`);r.innerHTML=(t=Xi[e.type])==null?``:t,n.appendChild(r);let i=document.createElement(`span`);return i.setAttribute(`data-blok-database-tab-name`,``),i.textContent=e.name,n.appendChild(i),n}openContextPopover(e,n){this.closeContextPopover();let r=this.options.views.length>1,i=(e,t)=>{var n,r;return(n=(r=this.options.api)==null?void 0:r.i18n.t(e))==null?t:n},a=[{icon:t.an,title:i(`tools.database.renameView`,`Rename`),closeOnActivate:!0,onActivate:()=>{this.startInlineRename(e,n)}},{icon:t.nt,title:i(`tools.database.duplicateView`,`Duplicate`),closeOnActivate:!0,onActivate:()=>{this.options.onDuplicate(n)}}],o=r?[{type:t.pr.Separator},{icon:t.Cn,title:i(`tools.database.deleteView`,`Delete`),isDestructive:!0,closeOnActivate:!0,onActivate:()=>{this.options.onDelete(n)}}]:[];this.contextPopover=new t.C({trigger:e,width:`auto`,minWidth:`160px`,autoFocusFirstItem:!1,items:[...a,...o]}),this.contextPopover.on(t.T.Closed,()=>{if(this.contextPopover!==null){let e=this.contextPopover;this.contextPopover=null,e.destroy()}}),this.contextPopover.show()}closeContextPopover(){if(this.contextPopover!==null){let e=this.contextPopover;this.contextPopover=null,e.destroy()}}startInlineRename(e,t){var n;let r=e.querySelector(`[data-blok-database-tab-name]`);if(!(r instanceof HTMLElement))return;let i=(n=r.textContent)==null?``:n,a=document.createElement(`input`);a.setAttribute(`data-blok-database-tab-rename-input`,``),a.value=i,r.replaceWith(a),a.focus(),a.select();let o=()=>{let e=a.value.trim()||i,n=document.createElement(`span`);n.setAttribute(`data-blok-database-tab-name`,``),n.textContent=e,a.replaceWith(n),e!==i&&this.options.onRename(t,e)};a.addEventListener(`blur`,o),a.addEventListener(`keydown`,e=>{if(e.stopPropagation(),e.key===`Enter`)a.blur();else if(e.key===`Escape`){a.removeEventListener(`blur`,o);let e=document.createElement(`span`);e.setAttribute(`data-blok-database-tab-name`,``),e.textContent=i,a.replaceWith(e)}})}openViewPopover(e){var t;this.viewPopover!==null&&this.viewPopover.destroy(),e.setAttribute(`data-popover-open`,``),(t=this.barEl)==null||t.setAttribute(`data-popover-open`,``),this.viewPopover=new Ji({onSelect:e=>{this.options.onAddView(e)},onClose:()=>{var t;e.removeAttribute(`data-popover-open`),(t=this.barEl)==null||t.removeAttribute(`data-popover-open`)},api:this.options.api}),this.viewPopover.open(e)}handleOverflow(e){var t;if(this.element===null)return;(t=this.moreBtnEl)==null||t.remove();let n=[...this.views].sort((e,t)=>e.position<t.position?-1:1).length-e;if(n<=0)return;let r=Array.from(this.element.querySelectorAll(`[data-blok-database-tab]`));for(let t of r.slice(e))t.style.display=`none`;let i=document.createElement(`div`);i.setAttribute(`data-blok-database-tab-more`,``),i.textContent=`${n} more...`,i.style.cursor=`pointer`,i.addEventListener(`click`,()=>{this.openOverflowDropdown(i)});let a=this.element.querySelector(`[data-blok-database-add-view]`);a===null?this.element.appendChild(i):this.element.insertBefore(i,a),this.moreBtnEl=i}openOverflowDropdown(e){var t;this.closeOverflowDropdown();let n=document.createElement(`div`);n.setAttribute(`data-blok-popover`,``),n.setAttribute(`data-blok-database-tab-overflow-dropdown`,``),n.style.position=`fixed`,n.style.zIndex=`1000`;let r=e.getBoundingClientRect();n.style.top=`${r.bottom+4}px`,n.style.left=`${r.left}px`;let i=[...this.views].sort((e,t)=>e.position<t.position?-1:1);for(let e of i){var a;let t=document.createElement(`div`);t.setAttribute(`data-blok-database-tab-overflow-item`,``),t.setAttribute(`data-view-id`,e.id),e.id===this.options.activeViewId&&t.setAttribute(`data-active`,``);let r=document.createElement(`span`);r.innerHTML=(a=Xi[e.type])==null?``:a,t.appendChild(r);let i=document.createElement(`span`);i.textContent=e.name,t.appendChild(i),t.addEventListener(`click`,()=>{e.id!==this.options.activeViewId&&this.options.onTabClick(e.id),this.closeOverflowDropdown()}),n.appendChild(t)}let o=document.createElement(`div`);o.setAttribute(`data-blok-database-tab-overflow-separator`,``),n.appendChild(o);let s=(t=this.element)==null?void 0:t.querySelector(`[data-blok-database-add-view]`),c=document.createElement(`div`);c.setAttribute(`data-blok-database-tab-overflow-new`,``),c.textContent=`+ New view`,c.addEventListener(`click`,()=>{this.closeOverflowDropdown(),s!=null&&this.openViewPopover(s)}),n.appendChild(c),document.body.appendChild(n),this.overflowDropdownEl=n,this.boundOverflowClose=t=>{let r=t.target;!n.contains(r)&&!e.contains(r)&&this.closeOverflowDropdown()},document.addEventListener(`mousedown`,this.boundOverflowClose)}closeOverflowDropdown(){this.overflowDropdownEl!==null&&(this.overflowDropdownEl.remove(),this.overflowDropdownEl=null),this.boundOverflowClose!==null&&(document.removeEventListener(`mousedown`,this.boundOverflowClose),this.boundOverflowClose=null)}handleDragMove(e){let t=Math.abs(e.clientX-this.dragStartX);if(!(!this.isDragging&&t<Yi)){if(!this.isDragging){var n,r;this.isDragging=!0,(n=this.element)==null||n.setAttribute(`data-dragging`,``);let e=(r=this.element)==null?void 0:r.querySelector(`[data-view-id="${this.dragViewId}"]`);if(e!==null){this.ghostEl=e.cloneNode(!0),this.ghostEl.setAttribute(`data-blok-database-tab-ghost`,``),this.ghostEl.style.position=`fixed`,this.ghostEl.style.pointerEvents=`none`,this.ghostEl.style.zIndex=`50`,this.ghostEl.style.opacity=`0.7`;let t=e.getBoundingClientRect();this.ghostEl.style.top=`${t.top}px`,this.ghostEl.style.width=`${t.width}px`,document.body.appendChild(this.ghostEl),e.style.opacity=`0.4`}}this.ghostEl!==null&&(this.ghostEl.style.left=`${e.clientX-50}px`)}}handleDragUp(e){var t,n,r,i;if(!this.isDragging){this.removeDragListeners();return}let a=Array.from((t=(n=this.element)==null?void 0:n.querySelectorAll(`[data-blok-database-tab]`))==null?[]:t).filter(e=>e.getAttribute(`data-view-id`)!==this.dragViewId),o=a.findIndex(t=>{let n=t.getBoundingClientRect();return e.clientX<(n.left+n.right)/2}),s=o>=0?a[o].getAttribute(`data-view-id`):null,c=o>0?a[o-1].getAttribute(`data-view-id`):o===-1&&a.length>0?a[a.length-1].getAttribute(`data-view-id`):null,l=[...this.views].sort((e,t)=>e.position<t.position?-1:1),u=s===null?null:l.find(e=>e.id===s),d=c===null?null:l.find(e=>e.id===c),f=ki((r=d==null?void 0:d.position)==null?null:r,(i=u==null?void 0:u.position)==null?null:i);this.cleanupDrag(),this.onReorder(this.dragViewId,f)}cleanupDrag(){var e,t;this.ghostEl!==null&&(this.ghostEl.remove(),this.ghostEl=null),(e=this.element)==null||e.removeAttribute(`data-dragging`);let n=(t=this.element)==null?void 0:t.querySelector(`[data-view-id="${this.dragViewId}"]`);n!==null&&(n.style.opacity=``),this.isDragging=!1,this.removeDragListeners()}removeDragListeners(){document.removeEventListener(`pointermove`,this.boundDragMove),document.removeEventListener(`pointerup`,this.boundDragUp),document.removeEventListener(`pointercancel`,this.boundDragCancel),document.removeEventListener(`keydown`,this.boundDragKeyDown)}setReadOnly(e){this.readOnly!==e&&(this.readOnly=e,!(this.barEl===null||this.addBtnEl===null)&&(e?this.addBtnEl.remove():this.addBtnEl.isConnected||this.barEl.appendChild(this.addBtnEl)))}destroy(){this.cleanupDrag(),this.closeContextPopover(),this.closeOverflowDropdown(),this.viewPopover!==null&&(this.viewPopover.destroy(),this.viewPopover=null)}getAddBtnEl(){return this.addBtnEl}},Qi=class{constructor({data:e,config:t,api:n,block:r,readOnly:i}){var a,o;this.element=null,this.titleElement=null,this.titleRowElement=null,this.boardContainer=null,this.tabBar=null,this.cardDrag=null,this.columnDrag=null,this.columnControls=null,this.listRowDrag=null,this.cardDrawer=null,this.keyboard=null,this.cardMenuPopover=null,this.api=n,this.block=r,this.readOnly=i,this.config=t==null?{}:t,this.title=(a=e==null?void 0:e.title)==null?``:a,this.model=new ji(e);let s=this.model.getViews();this.activeViewId=(o=e==null?void 0:e.activeViewId)==null?s.length>0?s[0].id:``:o,this.activateView(this.activeViewId)}static get toolbox(){return[{icon:t.ot,titleKey:`database`,name:`database`,searchTerms:[`database`,`kanban`,`board`,`cards`,`columns`]},{icon:t.z,titleKey:`board`,name:`board`,searchTerms:[`board`,`kanban`,`cards`,`columns`,`database`]}]}static get isReadOnlySupported(){return!0}render(){let e=document.createElement(`div`);e.setAttribute(`data-blok-tool`,`database`),e.setAttribute(`data-blok-database-wrapper`,``),e.style.display=`flex`,e.style.flexDirection=`column`,this.element=e;let t=this.createTitleElement();this.titleElement=t;let n=document.createElement(`div`);n.setAttribute(`data-blok-database-title-row`,``),n.appendChild(t),this.titleRowElement=n,e.appendChild(n),this.tabBar=this.createTabBar(),e.appendChild(this.tabBar.render()),this.syncTitleRowAddBtn();let r=document.createElement(`div`);r.setAttribute(`data-blok-database-board-container`,``),r.style.overflow=`hidden`,r.style.position=`relative`,this.boardContainer=r,e.appendChild(r),this.syncRowsFromBlocks();let i=this.renderActiveView();return r.appendChild(i),this.readOnly||(this.attachViewListeners(i),this.initSubsystems(i)),e}createTitleElement(){let e=document.createElement(`div`);return e.setAttribute(`data-blok-database-title`,``),e.textContent=this.title,e.style.fontSize=`1.5rem`,e.style.fontWeight=`600`,e.style.lineHeight=`1.3`,e.style.color=`var(--blok-text-primary)`,e.style.outline=`none`,e.style.cursor=`text`,e.style.wordBreak=`break-word`,e.className=o.join(` `),p(e,`New database`),this.readOnly||(e.setAttribute(`contenteditable`,`true`),e.addEventListener(`keydown`,t=>{(t.key===`Enter`||t.key===`Tab`)&&(t.preventDefault(),e.blur())})),e}rendered(){this.block.stretched=!0;let e=this.model.getOrderedRows().length>0;this.syncRowsFromBlocks(),!e&&this.model.getOrderedRows().length>0&&this.rerenderView(),this.config.adapter!==void 0&&this.loadFromBackend()}async loadFromBackend(){var e=this;let t=await e.sync.syncLoadDatabase();if(t===void 0)return;e.model.hydrate(t);let n=e.model.getViews();n.length>0&&!n.some(t=>t.id===e.activeViewId)&&(e.activeViewId=n[0].id),e.rerenderView()}save(e){var t,r;let i=(t=(r=this.titleElement)==null?void 0:r.textContent)==null?this.title:t;return n.t(n.t({},this.model.snapshot()),{},{title:i,activeViewId:this.activeViewId})}validate(e){var t,n,r,i;let a=((t=(n=e.schema)==null?void 0:n.filter(e=>e.type===`title`).length)==null?0:t)===1,o=e.views!==void 0&&e.views.length>0,s=(r=(i=e.views)==null?void 0:i.filter(e=>e.type===`board`).every(e=>e.groupBy!==void 0))==null?!0:r;return a&&o&&s}destroy(){var e,t,n,r,i,a,o;(e=this.cardDrag)==null||e.destroy(),(t=this.columnDrag)==null||t.destroy(),(n=this.columnControls)==null||n.destroy(),(r=this.listRowDrag)==null||r.destroy(),this.listRowDrag=null,(i=this.cardDrawer)==null||i.destroy(),(a=this.keyboard)==null||a.destroy(),(o=this.tabBar)==null||o.destroy(),this.sync.flushPendingUpdates(),this.sync.flushPendingPropertyUpdates(),this.sync.destroy(),this.element=null,this.boardContainer=null,this.tabBar=null}setReadOnly(e){var t;this.readOnly!==e&&(this.readOnly=e,this.titleElement!==null&&this.titleElement.setAttribute(`contenteditable`,e?`false`:`true`),(t=this.tabBar)==null||t.setReadOnly(e),this.syncTitleRowAddBtn(),this.rerenderView())}getToolbarAnchorElement(){var e;return(e=this.titleElement)==null?void 0:e}syncRowsFromBlocks(){let e=this.api.blocks.getChildren(this.block.id).filter(e=>e.name===`database-row`).map(e=>{var t,n,r,i;return{id:e.id,position:(t=(n=e.preservedData)==null?void 0:n.position)==null?``:t,properties:(r=(i=e.preservedData)==null?void 0:i.properties)==null?{}:r}});this.model.setRows(e)}deleteRowBlock(e){let t=this.api.blocks.getBlockIndex(e);t!==void 0&&this.api.blocks.delete(t),this.syncRowsFromBlocks()}updateRowBlock(e,t){let n=this.api.blocks.getChildren(this.block.id).find(t=>t.id===e);n!==void 0&&(n.call(`updateProperties`,t),n.dispatchChange()),this.syncRowsFromBlocks()}moveRowBlock(e,t){let n=this.api.blocks.getChildren(this.block.id).find(t=>t.id===e);n!==void 0&&(n.call(`updatePosition`,{position:t}),n.dispatchChange()),this.syncRowsFromBlocks()}activateView(e){this.model.getView(e)!==void 0&&(this.activeViewId=e,this.sync=new Fi(this.config.adapter,e=>{let t=String(e).replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`).replace(/'/g,`&#39;`);this.api.notifier.show({message:t,style:`error`})}))}switchView(e){var t,n,r,i,a;if(e===this.activeViewId||this.boardContainer===null)return;(t=this.cardDrag)==null||t.destroy(),(n=this.columnDrag)==null||n.destroy(),(r=this.columnControls)==null||r.destroy(),(i=this.listRowDrag)==null||i.destroy(),(a=this.keyboard)==null||a.destroy(),this.cardDrag=null,this.columnDrag=null,this.columnControls=null,this.listRowDrag=null,this.keyboard=null,this.sync.flushPendingUpdates(),this.sync.flushPendingPropertyUpdates(),this.sync.destroy(),this.activateView(e),this.boardContainer.innerHTML=``,this.syncRowsFromBlocks();let o=this.renderActiveView();this.boardContainer.appendChild(o),this.readOnly||(this.attachViewListeners(o),this.initSubsystems(o)),this.rebuildTabBar()}addView(e){let t=this.model.getSchema().find(e=>e.type===`select`),n=e===`list`?`List`:`Board`,r=this.model.addView(n,e,{groupBy:e===`board`?t==null?void 0:t.id:void 0});this.sync.syncCreateView({id:r.id,name:r.name,type:r.type,position:r.position,groupBy:r.groupBy}),this.switchView(r.id)}renameView(e,t){this.model.updateView(e,{name:t}),this.sync.syncUpdateView({viewId:e,changes:{name:t}})}duplicateView(e){let t=this.model.getView(e);if(t===void 0)return;let n=this.model.addView(t.name,t.type,{groupBy:t.groupBy,sorts:[...t.sorts],filters:[...t.filters],visibleProperties:[...t.visibleProperties]});this.sync.syncCreateView({id:n.id,name:n.name,type:n.type,position:n.position,groupBy:n.groupBy}),this.switchView(n.id)}deleteView(e){let t=this.model.getViews();if(t.length<=1)return;let n=t.findIndex(t=>t.id===e);if(n===-1)return;let r=e===this.activeViewId;if(this.model.deleteView(e),this.sync.syncDeleteView({viewId:e}),r){let e=this.model.getViews(),t=Math.min(n,e.length-1);this.switchView(e[t].id)}else this.rebuildTabBar()}reorderView(e,t){this.model.updateView(e,{position:t}),this.sync.syncUpdateView({viewId:e,changes:{position:t}}),this.rebuildTabBar()}rebuildTabBar(){if(this.element===null||this.tabBar===null)return;let e=this.element.querySelector(`[data-blok-database-tab-bar]`);this.tabBar.destroy(),this.tabBar=this.createTabBar();let t=this.tabBar.render();e===null?this.element.insertBefore(t,this.boardContainer):e.replaceWith(t),this.syncTitleRowAddBtn()}syncTitleRowAddBtn(){if(this.element===null||this.titleRowElement===null||this.tabBar===null)return;let e=this.element.querySelector(`[data-blok-database-tab-bar]`),t=this.model.getViews(),n=this.tabBar.getAddBtnEl();t.length===1&&!this.readOnly&&n!==null?(this.titleRowElement.appendChild(n),this.titleRowElement.setAttribute(`data-single-view`,``),e instanceof HTMLElement&&(e.style.display=`none`)):(this.titleRowElement.removeAttribute(`data-single-view`),this.titleRowElement.querySelectorAll(`[data-blok-database-add-view]`).forEach(e=>{e.remove()}),!this.readOnly&&n!==null&&e!==null&&!e.contains(n)&&e.appendChild(n),e instanceof HTMLElement&&(e.style.display=t.length>=2?``:`none`))}createTabBar(){return new Zi({views:this.model.getViews(),activeViewId:this.activeViewId,onTabClick:e=>this.switchView(e),onAddView:e=>this.addView(e),onRename:(e,t)=>this.renameView(e,t),onDuplicate:e=>this.duplicateView(e),onDelete:e=>this.deleteView(e),onReorder:(e,t)=>this.reorderView(e,t),readOnly:this.readOnly})}renderActiveView(){var e;let t=this.model.getView(this.activeViewId),n=this.model.getSchema().find(e=>e.type===`title`),r=(e=n==null?void 0:n.id)==null?``:e,i=t==null?void 0:t.groupBy;return(t==null?void 0:t.type)===`list`?this.renderListView(r,i,t):this.renderBoardView(r,i)}renderBoardView(e,t){let n=t===void 0?[]:this.model.getSelectOptions(t),r=t===void 0?new Map:this.model.getRowsGroupedBy(t);return this.view=new Mi({readOnly:this.readOnly,i18n:this.api.i18n,options:n,getRows:e=>{var t;return(t=r.get(e))==null?[]:t},titlePropertyId:e,onTitleEdit:(e,t)=>{var n;let r=this.model.getSchema().find(e=>e.type===`title`),i=(n=r==null?void 0:r.id)==null?``:n;this.updateRowBlock(e,{[i]:t}),this.sync.syncUpdateRow({rowId:e,properties:{[i]:t}})}}),this.view.createView()}renderListView(e,t,n){let r=this.model.getSchema();if(t!==void 0){let i=this.model.getSelectOptions(t),a=this.model.getRowsGroupedBy(t);this.view=new Ni({readOnly:this.readOnly,i18n:this.api.i18n,rows:[],titlePropertyId:e,schema:r,visiblePropertyIds:n.visibleProperties,options:i,getRows:e=>{var t;return(t=a.get(e))==null?[]:t}})}else this.view=new Ni({readOnly:this.readOnly,i18n:this.api.i18n,rows:this.model.getOrderedRows(),titlePropertyId:e,schema:r,visiblePropertyIds:n.visibleProperties});return this.view.createView()}attachViewListeners(e){e.addEventListener(`click`,t=>{let n=t.target,r=n.closest(`[data-blok-database-add-card]`);if(r!==null){let t=r.getAttribute(`data-option-id`);t!==null&&this.handleAddRow(t,e);return}if(n.closest(`[data-blok-database-add-column]`)!==null){this.handleAddColumn(e);return}let i=n.closest(`[data-blok-database-card-menu]`);if(i instanceof HTMLElement){let n=i.getAttribute(`data-row-id`),r=i.closest(`[data-blok-database-card]`);n!==null&&r instanceof HTMLElement&&(t.stopPropagation(),this.openCardMenu(i,r,n,e));return}let a=n.closest(`[data-blok-database-add-row]`);if(a!==null){let t=a.getAttribute(`data-option-id`);this.handleAddListRow(t,e);return}let o=n.closest(`[data-blok-database-delete-row]`);if(o!==null){let n=o.getAttribute(`data-row-id`);n!==null&&(t.stopPropagation(),this.deleteRowBlock(n),this.view.removeRow(e,n),this.sync.syncDeleteRow({rowId:n}));return}let s=n.closest(`[data-blok-database-list-row]`);if(s!==null){let e=s.getAttribute(`data-row-id`);e!==null&&this.handleRowClick(e);return}let c=n.closest(`[data-blok-database-card]`);if(c!==null){let e=c.getAttribute(`data-row-id`);e!==null&&this.handleRowClick(e)}})}openCardMenu(e,n,r,i){n.setAttribute(`data-popover-open`,``),this.cardMenuPopover=new t.C({trigger:e,width:`auto`,minWidth:`140px`,autoFocusFirstItem:!1,items:[{type:t.pr.Default,title:this.api.i18n.t(`tools.database.deleteCard`),icon:t.Cn,onActivate:()=>{this.deleteRowBlock(r),this.view.removeRow(i,r),this.sync.syncDeleteRow({rowId:r})}}]}),this.cardMenuPopover.on(t.T.Closed,()=>{if(n.removeAttribute(`data-popover-open`),this.cardMenuPopover!==null){let e=this.cardMenuPopover;this.cardMenuPopover=null,e.destroy()}}),this.cardMenuPopover.show()}handleAddListRow(e,t){var n,r;let i=this.model.getSchema().find(e=>e.type===`title`),a=(n=i==null?void 0:i.id)==null?``:n,o=this.model.getView(this.activeViewId),s=o==null?void 0:o.groupBy,c={[a]:``};s!==void 0&&e!==null&&(c[s]=e);let l=this.model.createRowData(c),u=(r=this.api.blocks.getBlockIndex(this.block.id))==null?0:r;this.api.blocks.insert(`database-row`,{properties:l.properties,position:l.position},{},u+1,!1,!1,l.id),this.api.blocks.setBlockParent(l.id,this.block.id),this.syncRowsFromBlocks(),this.view.appendRow(t,l),this.sync.syncCreateRow({id:l.id,properties:l.properties,position:l.position})}handleAddRow(e,t){var n,r;let i=this.model.getView(this.activeViewId),a=i==null?void 0:i.groupBy;if(a===void 0)return;let o=this.model.getSchema().find(e=>e.type===`title`),s=(n=o==null?void 0:o.id)==null?``:n,c=this.model.createRowData({[s]:``,[a]:e}),l=(r=this.api.blocks.getBlockIndex(this.block.id))==null?0:r;this.api.blocks.insert(`database-row`,{properties:c.properties,position:c.position},{},l+1,!1,!1,c.id),this.api.blocks.setBlockParent(c.id,this.block.id),this.syncRowsFromBlocks();let u=t.querySelector(`[data-option-id="${e}"][data-blok-database-column]`);if(u===null)return;let d=u.querySelector(`[data-blok-database-cards]`);d!==null&&(this.view.appendRow(d,c),this.sync.syncCreateRow({id:c.id,properties:c.properties,position:c.position}))}handleAddColumn(e){var n,r;let i=this.model.getView(this.activeViewId),a=i==null?void 0:i.groupBy;if(a===void 0)return;let o=this.model.getProperty(a);if((o==null?void 0:o.config)===void 0)return;let s=o.config.options,c=s.length>0?s[s.length-1].position:null,l={id:t.Ur(),label:this.api.i18n.t(`tools.database.columnTitlePlaceholder`),position:ji.positionBetween(c,null)};this.model.updateProperty(a,{config:{options:[...s,l]}}),(n=(r=this.view).appendGroup)==null||n.call(r,e,l),this.sync.syncUpdateProperty({propertyId:a,changes:{config:{options:[...s,l]}}})}initSubsystems(e){var t;if(this.element===null)return;let r=this.model.getView(this.activeViewId),i=(r==null?void 0:r.type)===`list`,a=this.model.getSchema().find(e=>e.type===`title`),o=(t=a==null?void 0:a.id)==null?``:t,s=this.model.getSchema().find(e=>e.type===`richText`),c=s==null?void 0:s.id;i?this.listRowDrag=new Hi({wrapper:e,onDrop:e=>this.handleListRowDrop(e)}):(this.cardDrag=new Li({wrapper:e,onDrop:e=>this.handleRowDrop(e)}),this.columnDrag=new zi({wrapper:e,onDrop:e=>this.handleGroupDrop(e)}),this.columnControls=new Bi({i18n:this.api.i18n,onRename:(e,t)=>this.handleOptionRename(e,t),onDelete:t=>this.handleOptionDelete(t,e),onRenameInput:(e,t)=>{this.handleOptionRename(e,t)},onRenameCommit:(e,t)=>{let r=this.model.getView(this.activeViewId),i=r==null?void 0:r.groupBy;if(i===void 0)return;let a=this.model.getProperty(i);if((a==null?void 0:a.config)===void 0)return;let o=a.config.options.map(r=>r.id===e?n.t(n.t({},r),{},{label:t}):r);this.sync.syncUpdatePropertyDebounced({propertyId:i,changes:{config:{options:o}}})}}),this.makeColumnHeadersEditable(e)),this.cardDrawer===null&&(this.cardDrawer=new Gi({wrapper:this.element,readOnly:this.readOnly,i18n:this.api.i18n,toolsConfig:this.api.tools.getToolsConfig(),titlePropertyId:o,descriptionPropertyId:c,schema:this.model.getSchema(),onTitleChange:(e,t)=>{var n,r,i;this.updateRowBlock(e,{[o]:t});let a=(n=(r=this.boardContainer)==null?void 0:r.querySelector(`[data-blok-database-board]`))==null?(i=this.boardContainer)==null?void 0:i.querySelector(`[data-blok-database-list]`):n;a!=null&&this.view.updateRowTitle(a,e,t),this.sync.syncUpdateRow({rowId:e,properties:{[o]:t}})},onDescriptionChange:(e,t)=>{c!==void 0&&(this.updateRowBlock(e,{[c]:t}),this.sync.syncUpdateRow({rowId:e,properties:{[c]:t}}))},onClose:()=>{},onAddProperty:e=>{var t;let n=this.model.addProperty(`Property`,e);this.sync.syncCreateProperty({id:n.id,name:n.name,type:n.type,position:n.position}),(t=this.cardDrawer)==null||t.refreshSchema(this.model.getSchema())}})),this.keyboard=new Ki({wrapper:e,onEscape:()=>{var e;return(e=this.cardDrawer)!=null&&e.isOpen?(this.cardDrawer.close(),!0):!1}}),this.keyboard.attach(),e.addEventListener(`pointerdown`,e=>{let t=e.target,n=t.closest(`[data-blok-database-column-header]`);if(n!==null){var r;if(t.closest(`[data-blok-database-column-pill]`)!==null)return;let a=n.closest(`[data-blok-database-column]`),o=(r=a==null?void 0:a.getAttribute(`data-option-id`))==null?null:r;if(o!==null){var i;e.preventDefault(),e.stopPropagation(),(i=this.columnDrag)==null||i.beginTracking(o,e.clientX,e.clientY)}return}let a=t.closest(`[data-blok-database-card]`);if(a!==null){let t=a.getAttribute(`data-row-id`);if(t!==null){var o;e.preventDefault(),e.stopPropagation(),(o=this.cardDrag)==null||o.beginTracking(t,e.clientX,e.clientY)}return}let s=t.closest(`[data-blok-database-list-row]`);if(s!==null){let t=s.getAttribute(`data-row-id`);if(t!==null){var c;e.preventDefault(),e.stopPropagation(),(c=this.listRowDrag)==null||c.beginTracking(t,e.clientX,e.clientY)}}})}makeColumnHeadersEditable(e){if(this.columnControls===null)return;let t=Array.from(e.querySelectorAll(`[data-blok-database-column-header]`));for(let e of t){let t=e.closest(`[data-blok-database-column]`),n=t==null?void 0:t.getAttribute(`data-option-id`);n!=null&&(this.columnControls.makePillTitleEditable(e,n),this.columnControls.appendDeleteButton(e,n))}}handleListRowDrop(e){var t,n;let{rowId:r,beforeRowId:i,afterRowId:a}=e,o=i===null?void 0:this.model.getRow(i),s=a===null?void 0:this.model.getRow(a),c=ji.positionBetween((t=s==null?void 0:s.position)==null?null:t,(n=o==null?void 0:o.position)==null?null:n);this.moveRowBlock(r,c),this.rerenderView(),this.sync.syncMoveRow({rowId:r,position:c})}handleRowDrop(e){var t,n;let{rowId:r,toOptionId:i,beforeRowId:a,afterRowId:o}=e,s=this.model.getView(this.activeViewId),c=s==null?void 0:s.groupBy;if(c===void 0)return;let l=a===null?void 0:this.model.getRow(a),u=o===null?void 0:this.model.getRow(o),d=ji.positionBetween((t=u==null?void 0:u.position)==null?null:t,(n=l==null?void 0:l.position)==null?null:n);this.updateRowBlock(r,{[c]:i}),this.moveRowBlock(r,d),this.rerenderView(),this.sync.syncUpdateRow({rowId:r,properties:{[c]:i}}),this.sync.syncMoveRow({rowId:r,position:d})}handleGroupDrop(e){var t,r;let{optionId:i,beforeOptionId:a,afterOptionId:o}=e,s=this.model.getView(this.activeViewId),c=s==null?void 0:s.groupBy;if(c===void 0)return;let l=this.model.getProperty(c);if((l==null?void 0:l.config)===void 0)return;let u=[...l.config.options],d=u.findIndex(e=>e.id===i);if(d===-1)return;let f=a===null?void 0:u.find(e=>e.id===a),p=o===null?void 0:u.find(e=>e.id===o),m=ji.positionBetween((t=p==null?void 0:p.position)==null?null:t,(r=f==null?void 0:f.position)==null?null:r);u[d]=n.t(n.t({},u[d]),{},{position:m}),this.model.updateProperty(c,{config:{options:u}}),this.moveColumnInDom(i,a),this.sync.syncUpdateProperty({propertyId:c,changes:{config:{options:u}}})}moveColumnInDom(e,t){var n;let r=(n=this.boardContainer)==null?void 0:n.querySelector(`[data-blok-database-board]`);if(r==null)return;let i=r.querySelector(`[data-option-id="${e}"]`);if(i!==null)if(t!==null){let e=r.querySelector(`[data-option-id="${t}"]`);e!==null&&r.insertBefore(i,e)}else{let e=r.querySelector(`[data-blok-database-add-column]`);e===null?r.appendChild(i):r.insertBefore(i,e)}}handleOptionRename(e,t){let r=this.model.getView(this.activeViewId),i=r==null?void 0:r.groupBy;if(i===void 0)return;let a=this.model.getProperty(i);if((a==null?void 0:a.config)===void 0)return;let o=a.config.options.map(r=>r.id===e?n.t(n.t({},r),{},{label:t}):r);this.model.updateProperty(i,{config:{options:o}}),this.sync.syncUpdateProperty({propertyId:i,changes:{config:{options:o}}})}handleOptionDelete(e,t){var n,r,i;let a=this.model.getView(this.activeViewId),o=a==null?void 0:a.groupBy;if(o===void 0)return;let s=this.model.getProperty(o);if((s==null?void 0:s.config)===void 0||s.config.options.length<=1)return;let c=(n=this.model.getRowsGroupedBy(o).get(e))==null?[]:n;for(let e of c)this.deleteRowBlock(e.id),this.sync.syncDeleteRow({rowId:e.id});let l=s.config.options.filter(t=>t.id!==e);this.model.updateProperty(o,{config:{options:l}}),(r=(i=this.view).removeGroup)==null||r.call(i,t,e),this.sync.syncUpdateProperty({propertyId:o,changes:{config:{options:l}}})}handleRowClick(e){var t;let n=this.model.getRow(e);n!==void 0&&((t=this.cardDrawer)==null||t.open(n))}rerenderView(){var e,t,n,r,i,a,o,s,c,l;if(this.boardContainer===null)return;let u=(e=(t=(n=this.boardContainer.querySelector(`[data-blok-database-board]`))==null?void 0:n.closest(`[data-blok-tool]`))==null?this.boardContainer.querySelector(`[data-blok-database-list]`):t)==null?this.boardContainer.firstElementChild:e,d=this.boardContainer.querySelector(`[data-blok-database-board]`),f=(r=d==null?void 0:d.scrollLeft)==null?0:r;(i=this.cardDrag)==null||i.destroy(),(a=this.columnDrag)==null||a.destroy(),(o=this.columnControls)==null||o.destroy(),(s=this.listRowDrag)==null||s.destroy(),this.listRowDrag=null,(c=this.cardDrawer)==null||c.destroy(),this.cardDrawer=null,(l=this.keyboard)==null||l.destroy(),this.syncRowsFromBlocks();let p=this.renderActiveView();u==null?this.boardContainer.appendChild(p):u.replaceWith(p);let m=p.querySelector(`[data-blok-database-board]`);m!==null&&(m.scrollLeft=f),this.attachViewListeners(p),this.initSubsystems(p)}},$i=class{constructor({data:e}){var t,n;this._data={properties:(t=e.properties)==null?{}:t,position:(n=e.position)==null?`a0`:n}}render(){let e=document.createElement(`div`);return e.setAttribute(`data-blok-tool`,`database-row`),e}save(e){return{properties:this._data.properties,position:this._data.position}}validate(e){return e.properties!==null&&e.properties!==void 0&&typeof e.properties==`object`}updateProperties(e){Object.assign(this._data.properties,e)}updatePosition(e){this._data.position=e.position}getProperties(){return this._data.properties}getPosition(){return this._data.position}static get isReadOnlySupported(){return!0}setReadOnly(e){}},ea=class{constructor(e){this.element=null}render(){let e=document.createElement(`div`);e.className=r.n(`py-3`,`leading-[1px]`);let t=document.createElement(`hr`);return t.setAttribute(`data-blok-divider`,``),t.className=r.n(`border-t`,`border-border-primary`,`border-b-0`,`border-l-0`,`border-r-0`),e.appendChild(t),this.element=e,e}save(){return{}}validate(e){return!0}static get toolbox(){return{icon:t.ct,titleKey:`divider`,shortcut:`---`,searchTerms:[`hr`,`line`,`separator`,`rule`,`---`,`divider`,`delimiter`,`splitter`],searchTermKeys:[`divider`,`separator`,`delimiter`,`splitter`]}}static get isReadOnlySupported(){return!0}static get pasteConfig(){return{tags:[`HR`],patterns:{divider:/^-{3,}$/}}}onPaste(e){}setReadOnly(e){}static get sanitize(){return{}}},ta=`tools.quote.placeholder`,na=[`border-l-[3px]`,`border-current`,`pl-[0.9em]`,`pr-[0.9em]`,`py-[0.2em]`,`leading-[1.5]`,`outline-hidden`,`mt-[0.3em]`,`mb-[0.3em]`],ra=`text-[1.2em]`,ia=class{constructor({data:e,api:t,readOnly:n}){var r,i;this.placeholderCleanup=null,this._element=null,this.api=t,this.readOnly=n,this._data={text:(r=e==null?void 0:e.text)==null?``:r,size:(i=e==null?void 0:e.size)==null?`default`:i},this.onKeyUp=this.onKeyUp.bind(this)}onKeyUp(e){e.code!==`Backspace`&&e.code!==`Delete`||this._element&&this._element.textContent===``&&(this._element.innerHTML=``)}drawView(){let e=document.createElement(`blockquote`);return e.className=r.n(this.api.styles.block,na,c,this._data.size===`large`?ra:``),e.setAttribute(t.hi.tool,`quote`),e.contentEditable=`false`,this._data.text?e.innerHTML=this._data.text:this.readOnly&&(e.innerHTML=`<br>`),this.readOnly||(e.contentEditable=`true`,e.addEventListener(`keyup`,this.onKeyUp),this.placeholderCleanup=p(e,this.api.i18n.t(ta),`data-blok-placeholder-active`)),e}render(){return this._element||(this._element=this.drawView()),this._element}setReadOnly(e){this._element&&(this.readOnly=e,e?(this._element.contentEditable=`false`,this._element.removeEventListener(`keyup`,this.onKeyUp),this.placeholderCleanup&&(this.placeholderCleanup(),this.placeholderCleanup=null),u(this._element)&&(this._element.innerHTML=`<br>`)):(this._element.contentEditable=`true`,this._element.addEventListener(`keyup`,this.onKeyUp),this.placeholderCleanup=p(this._element,this.api.i18n.t(ta),`data-blok-placeholder-active`),this._element.innerHTML===`<br>`&&(this._element.innerHTML=``)))}save(e){return{text:t.Vr(e.innerHTML),size:this._data.size}}validate(e){return e.text.trim()!==``}merge(e){if(!this._element)return;this._data.text+=e.text;let t=document.createElement(`div`);t.innerHTML=e.text.trim();let n=document.createDocumentFragment();n.append(...Array.from(t.childNodes)),this._element.appendChild(n),this._element.normalize()}renderSettings(){return[{icon:t.ln,title:this.api.i18n.t(`tools.quote.size`),name:`quote-size`,children:{items:[{icon:t.ln,title:this.api.i18n.t(`tools.quote.defaultSize`),onActivate:()=>this.setSize(`default`),closeOnActivate:!0,isActive:this._data.size===`default`},{icon:t.ln,title:this.api.i18n.t(`tools.quote.largeSize`),onActivate:()=>this.setSize(`large`),closeOnActivate:!0,isActive:this._data.size===`large`}]}}]}setSize(e){this._data.size=e,this._element&&(this._element.className=r.n(this.api.styles.block,na,c,e===`large`?ra:``))}onPaste(e){let t=e.detail;if(!(`data`in t))return;let n=t.data;this._data={text:n.innerHTML,size:this._data.size},this._element&&(this._element.innerHTML=this._data.text||``)}static get toolbox(){return{icon:t.ln,titleKey:`quote`,shortcut:`"`,searchTerms:[`quote`,`blockquote`,`citation`],searchTermKeys:[`quote`,`blockquote`,`citation`]}}static get conversionConfig(){return{export:`text`,import:`text`}}static get sanitize(){return{text:{br:!0,b:!0,i:!0,a:!0,mark:{style:!0}}}}static get isReadOnlySupported(){return!0}static get pasteConfig(){return{tags:[`BLOCKQUOTE`]}}},aa=`tools.code.language`,oa=`tools.code.copied`,sa=`tools.code.copyCode`,ca=`tools.code.searchLanguage`,la=`plain text`,ua=[{id:`plain text`,name:`Plain Text`},{id:`javascript`,name:`JavaScript`},{id:`typescript`,name:`TypeScript`},{id:`python`,name:`Python`},{id:`java`,name:`Java`},{id:`c`,name:`C`},{id:`cpp`,name:`C++`},{id:`csharp`,name:`C#`},{id:`go`,name:`Go`},{id:`rust`,name:`Rust`},{id:`ruby`,name:`Ruby`},{id:`php`,name:`PHP`},{id:`swift`,name:`Swift`},{id:`kotlin`,name:`Kotlin`},{id:`latex`,name:`LaTeX`},{id:`mermaid`,name:`Mermaid`},{id:`sql`,name:`SQL`},{id:`html`,name:`HTML`},{id:`css`,name:`CSS`},{id:`json`,name:`JSON`},{id:`yaml`,name:`YAML`},{id:`markdown`,name:`Markdown`},{id:`bash`,name:`Bash`},{id:`shell`,name:`Shell`},{id:`dockerfile`,name:`Dockerfile`},{id:`xml`,name:`XML`},{id:`graphql`,name:`GraphQL`},{id:`r`,name:`R`},{id:`scala`,name:`Scala`},{id:`dart`,name:`Dart`},{id:`lua`,name:`Lua`}],da=`group/code flex flex-col rounded-xl border border-border-secondary bg-bg-secondary overflow-hidden my-2`,fa=`flex items-center gap-1 px-3 py-1.5 text-xs text-gray-text`,pa=`inline-flex items-center px-1.5 py-0.5 rounded cursor-pointer bg-transparent border-0 text-xs text-gray-text font-medium transition-colors can-hover:hover:bg-item-hover-bg select-none`,ma=`flex items-center gap-1 opacity-0 group-hover/code:opacity-100 transition-opacity`,ha=`p-1 rounded cursor-pointer bg-transparent border-0 text-gray-text transition-colors can-hover:hover:bg-item-hover-bg flex items-center justify-center`,ga=`p-1.5 rounded-lg cursor-pointer bg-transparent border-0 text-gray-text transition-colors can-hover:hover:bg-item-hover-bg flex items-center justify-center`,_a=`block px-4 py-3 font-mono text-sm leading-relaxed outline-hidden whitespace-pre-wrap overflow-x-auto min-h-[1.5em] caret-text-primary`,va=`text-xs text-gray-text font-medium select-none`,ya=new Set([`latex`,`mermaid`]),ba=`tools.code.codeTab`,xa=`tools.code.previewTab`,Sa=`px-4 py-3 overflow-x-auto min-h-[1.5em] flex justify-center`,Ca=`tools.code.sideBySide`,wa=`flex items-center rounded-lg border border-border-secondary p-0.5 gap-0.5`,Ta=`p-1 rounded cursor-pointer bg-transparent border-0 text-gray-text transition-colors flex items-center justify-center`,Ea=`p-1 rounded cursor-pointer bg-item-hover-bg border-0 text-primary transition-colors flex items-center justify-center`,Da=`flex flex-col overflow-hidden`,Oa=`flex flex-row overflow-hidden`,ka=`flex-1 min-w-0 overflow-hidden`,Aa=new Set(ua.map(e=>e.id).filter(e=>e!==la)),ja=`flex overflow-hidden`,Ma=`select-none text-right pl-4 pr-3 py-3 font-mono text-sm leading-relaxed text-gray-text/40 shrink-0`,Na=`leading-relaxed cursor-text`;function Pa(e){let n=document.createElement(`div`);n.className=wa,n.setAttribute(`role`,`group`),n.setAttribute(`data-blok-testid`,`code-view-mode`);let r=[{mode:`code`,icon:t.Q,label:e.code},{mode:`preview`,icon:t.cn,label:e.preview},{mode:`split`,icon:t.hn,label:e.split}];for(let{mode:e,icon:t,label:i}of r){let r=document.createElement(`button`);r.type=`button`,r.className=Ta,r.innerHTML=t,r.setAttribute(`aria-label`,i),r.setAttribute(`aria-pressed`,`false`),r.setAttribute(`data-blok-testid`,`code-mode-${e}`),r.setAttribute(`data-mode`,e),n.appendChild(r)}let i=document.createElement(`div`);i.className=Sa,i.setAttribute(`data-blok-testid`,`code-preview`);let a=document.createElement(`div`);return a.className=Da,a.setAttribute(`data-blok-testid`,`code-split-container`),{viewModeContainer:n,previewElement:i,splitContainer:a}}function Fa(e,t){let n=Array.from(e.querySelectorAll(`[data-mode]`));for(let e of n){let n=e.getAttribute(`data-mode`)===t;e.setAttribute(`aria-pressed`,String(n)),e.className=n?Ea:Ta}}function Ia(e){var n,r,i;let{code:a,languageName:o,readOnly:s,copyLabel:c,previewable:l,viewModeLabels:u}=e,d=document.createElement(`div`);d.className=da;let f=document.createElement(`div`);f.className=fa;let p=document.createElement(`button`);p.type=`button`,p.className=pa,p.setAttribute(`aria-haspopup`,`listbox`),p.setAttribute(`data-blok-testid`,`code-language-btn`);let m=document.createElement(`span`);m.textContent=o,p.appendChild(m);let h=document.createElement(`span`);h.className=`inline-flex items-center ml-0.5 -mr-0.5`,h.innerHTML=t.J,p.appendChild(h);let g=document.createElement(`div`);g.className=`flex-1`;let _=!s&&u?Pa(u):null,v=(n=_==null?void 0:_.viewModeContainer)==null?null:n,y=(r=_==null?void 0:_.previewElement)==null?null:r,b=(i=_==null?void 0:_.splitContainer)==null?null:i;v&&(v.hidden=!l);let x=document.createElement(`button`);x.type=`button`,x.className=l?ga:ha,x.innerHTML=t.nt,x.setAttribute(`aria-label`,c),x.setAttribute(`data-blok-testid`,`code-copy-btn`);let S=document.createElement(`code`);S.className=_a,S.setAttribute(`data-blok-testid`,`code-content`),a&&(S.textContent=a),s||(S.setAttribute(`contenteditable`,`plaintext-only`),S.setAttribute(`spellcheck`,`false`));let C=document.createElement(`div`);C.className=Ma,C.setAttribute(`aria-hidden`,`true`),C.setAttribute(`data-blok-testid`,`code-gutter`);let w=a?a.split(`
1
+ const e=require(`./chunk-BL1yB9zm.cjs`),t=require(`./constants-Cz29UuPH.cjs`),n=require(`./objectSpread2-iNkE6aJh.cjs`),r=require(`./tw-fzSjDKon.cjs`),i=require(`./lightweight-i18n-CNdX4sc2.cjs`),a=require(`./sanitize-url-C41J7vod.cjs`);var o=[`empty:before:pointer-events-none`,`empty:before:text-gray-text`,`empty:before:cursor-text`,`empty:before:content-[attr(data-placeholder)]`,`data-[blok-empty=true]:before:pointer-events-none`,`data-[blok-empty=true]:before:text-gray-text`,`data-[blok-empty=true]:before:cursor-text`,`data-[blok-empty=true]:before:content-[attr(data-placeholder)]`],s=[`empty:before:pointer-events-none`,`empty:before:text-gray-text`,`empty:before:cursor-text`,`empty:before:content-[attr(data-blok-placeholder-active)]`,`data-[empty=true]:before:pointer-events-none`,`data-[empty=true]:before:text-gray-text`,`data-[empty=true]:before:cursor-text`,`data-[empty=true]:before:content-[attr(data-blok-placeholder-active)]`],c=[`empty:focus:before:pointer-events-none`,`empty:focus:before:text-gray-text`,`empty:focus:before:cursor-text`,`empty:focus:before:content-[attr(data-blok-placeholder-active)]`,`[&[data-empty=true]:focus]:before:pointer-events-none`,`[&[data-empty=true]:focus]:before:text-gray-text`,`[&[data-empty=true]:focus]:before:cursor-text`,`[&[data-empty=true]:focus]:before:content-[attr(data-blok-placeholder-active)]`],l=[`empty:in-data-[blok-empty=true]:before:pointer-events-none`,`empty:in-data-[blok-empty=true]:before:text-gray-text`,`empty:in-data-[blok-empty=true]:before:cursor-text`,`empty:in-data-[blok-empty=true]:before:content-[attr(data-blok-placeholder-active)]`,`[[data-blok-empty=true]_&[data-empty=true]]:before:pointer-events-none`,`[[data-blok-empty=true]_&[data-empty=true]]:before:text-gray-text`,`[[data-blok-empty=true]_&[data-empty=true]]:before:cursor-text`,`[[data-blok-empty=true]_&[data-empty=true]]:before:content-[attr(data-blok-placeholder-active)]`],u=e=>{let t=e.innerHTML.trim();return t===``||t===`<br>`},d=e=>{e.innerHTML===`<br>`&&(e.innerHTML=``);let t=window.getSelection();if(!t)return;let n=document.createRange();n.selectNodeContents(e),n.collapse(!0),t.removeAllRanges(),t.addRange(n)},f=e=>{u(e)&&d(e)},p=(e,t,n=`data-placeholder`)=>{e.setAttribute(n,t==null?``:t);let r=()=>f(e);return e.addEventListener(`focus`,r),()=>{e.removeEventListener(`focus`,r),e.removeAttribute(n)}},m,h=e=>{let t=document.createElement(`div`);t.innerHTML=e.trim();let n=document.createDocumentFragment();return n.append(...Array.from(t.childNodes)),n},g=class e{static get DEFAULT_PLACEHOLDER(){return`tools.paragraph.placeholder`}constructor({data:t,config:n,api:r,readOnly:i}){var a,o,s;this.placeholderCleanup=null,this.api=r,this.readOnly=i,this.onKeyUp=this.onKeyUp.bind(this),this._placeholder=(a=n==null?void 0:n.placeholder)==null?e.DEFAULT_PLACEHOLDER:a,this._data=t==null?{text:``}:t,this._element=null,this._preserveBlank=(o=n==null?void 0:n.preserveBlank)==null?!1:o,this._styles=(s=n==null?void 0:n.styles)==null?{}:s}onKeyUp(e){if(e.code!==`Backspace`&&e.code!==`Delete`||!this._element)return;let{textContent:t}=this._element;t===``&&(this._element.innerHTML=``)}buildInlineStyles(){let e={};return this._styles.size&&(e.fontSize=this._styles.size),this._styles.lineHeight&&(e.lineHeight=this._styles.lineHeight),this._styles.marginTop&&(e.marginTop=this._styles.marginTop),this._styles.marginBottom&&(e.marginBottom=this._styles.marginBottom),e}drawView(){let n=document.createElement(`DIV`);n.className=r.n(this.api.styles.block,e.WRAPPER_CLASSES,c,l),n.setAttribute(t.hi.tool,`paragraph`),n.contentEditable=`false`;let i=this.buildInlineStyles();return Object.keys(i).length>0&&Object.assign(n.style,i),this._data.text?n.innerHTML=this._data.text:this.readOnly&&(n.innerHTML=`<br>`),this.readOnly||(n.contentEditable=`true`,n.addEventListener(`keyup`,this.onKeyUp),this.placeholderCleanup=p(n,this.api.i18n.t(this._placeholder),`data-blok-placeholder-active`)),n}render(){return this._element||(this._element=this.drawView()),this._element}setReadOnly(e){this._element&&(this.readOnly=e,e?(this._element.contentEditable=`false`,this._element.removeEventListener(`keyup`,this.onKeyUp),this.placeholderCleanup&&(this.placeholderCleanup(),this.placeholderCleanup=null),u(this._element)&&(this._element.innerHTML=`<br>`)):(this._element.contentEditable=`true`,this._element.addEventListener(`keyup`,this.onKeyUp),this.placeholderCleanup=p(this._element,this.api.i18n.t(this._placeholder),`data-blok-placeholder-active`),this._element.innerHTML===`<br>`&&(this._element.innerHTML=``)))}merge(e){if(!this._element)return;this._data.text+=e.text;let t=h(e.text);this._element.appendChild(t),this._element.normalize()}validate(e){return!(e.text.trim()===``&&!this._preserveBlank)}save(e){return{text:t.Vr(e.innerHTML)}}onPaste(e){let t=e.detail;if(!(`data`in t))return;let n={text:t.data.innerHTML};this._data=n,this._element&&(this._element.innerHTML=this._data.text||``)}static get conversionConfig(){return{export:`text`,import:`text`}}static get sanitize(){return{text:{br:!0,img:{src:!0,style:!0},p:!0,ul:!0,li:!0}}}static get isReadOnlySupported(){return!0}static get pasteConfig(){return{tags:[`P`]}}static get toolbox(){return{icon:t.vn,titleKey:`text`,searchTerms:[`p`,`paragraph`,`plain`],searchTermKeys:[`paragraph`,`plain`]}}};m=g,m.WRAPPER_CLASSES=[`leading-[1.5]`,`outline-hidden`,`mt-px`,`mb-px`,`[&>p:first-of-type]:mt-0`,`[&>p:last-of-type]:mb-0`];var _=e=>{let{data:n,readOnly:r,isOpen:i,keydownHandler:a,onArrowClick:o,onBodyPlaceholderClick:s}=e,c=document.createElement(`div`);c.className=t.a,c.setAttribute(t.hi.tool,t.p),c.setAttribute(t.u.toggleOpen,String(i)),c.setAttribute(t.u.toggleEmpty,`true`);let l=document.createElement(`div`);l.className=t.f;let u=v(i,o,{},e.ariaLabels),d=b(n,r,a);l.appendChild(u),l.appendChild(d);let f=y(s,e.bodyPlaceholderText),p=document.createElement(`div`);return p.className=t.d,p.setAttribute(t.u.toggleChildren,``),p.setAttribute(t.hi.nestedBlocks,``),p.setAttribute(`data-blok-mutation-free`,`true`),p.id=`toggle-children-${Date.now()}-${Math.random().toString(36).slice(2)}`,u.setAttribute(`aria-controls`,p.id),c.appendChild(l),c.appendChild(f),c.appendChild(p),{wrapper:c,arrowElement:u,contentElement:d,bodyPlaceholderElement:f,childContainerElement:p}},v=(e,n,r={},i={collapse:`Collapse`,expand:`Expand`})=>{let a=document.createElement(`span`);a.className=t.i,a.setAttribute(t.u.toggleArrow,``),a.setAttribute(t.hi.mutationFree,`true`),a.setAttribute(`role`,`button`),a.setAttribute(`tabindex`,`0`),a.setAttribute(`aria-label`,e?i.collapse:i.expand),a.setAttribute(`aria-expanded`,String(e)),r.contentEditableFalse===!0&&(a.contentEditable=`false`),a.innerHTML=t.r;let o=a.querySelector(`svg`);return o&&(o.style.transition=`transform 200ms ease-in-out`,e&&(o.style.transform=`rotate(90deg)`)),n&&(a.addEventListener(`click`,e=>{e.stopPropagation(),n()}),a.addEventListener(`keydown`,e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),e.stopPropagation(),n())})),a},y=(e,n)=>{let r=document.createElement(`div`);return r.className=t.s,r.setAttribute(t.u.toggleBodyPlaceholder,``),r.setAttribute(`data-blok-mutation-free`,`true`),r.textContent=n,e&&r.addEventListener(`click`,e),r},b=(e,n,i)=>{let a=document.createElement(`div`);return a.className=r.n(t.c,s,l),a.setAttribute(t.u.toggleContent,``),a.contentEditable=n?`false`:`true`,a.innerHTML=e.text,i&&a.addEventListener(`keydown`,i),a},x=(e,n)=>{for(let r of n){if(r.holder.parentElement===e)continue;let n=r.holder.closest(`[${t.hi.nestedBlocks}]`);if(n!==null&&n!==e&&n.hasAttribute(`data-blok-columns`)&&n.contains(e)){e.appendChild(r.holder);continue}n===null&&e.appendChild(r.holder)}},S=(e,n)=>{var r;if(e===null)return;let i=((r=n==null?void 0:n.textContent)==null?``:r).trim()===``;e.setAttribute(t.u.toggleEmpty,String(i))},C=e=>{let t=_(e);return t.contentElement&&p(t.contentElement,e.placeholder,`data-blok-placeholder-active`),t},w=(e,n,r,i={collapse:`Collapse`,expand:`Expand`})=>{let a=e.querySelector(`svg`);a&&(a.style.transform=r?`rotate(90deg)`:``),e.setAttribute(`aria-label`,r?i.collapse:i.expand),e.setAttribute(`aria-expanded`,String(r)),n.setAttribute(t.u.toggleOpen,String(r))},T=(e,t,n,r,i)=>{let a=e.blocks.getChildren(t);!n&&r&&i&&r.contains(document.activeElement)&&i.focus(),r&&x(r,a);for(let e of a)n?e.holder.classList.remove(`hidden`):e.holder.classList.add(`hidden`);r&&(n?r.removeAttribute(`aria-hidden`):r.setAttribute(`aria-hidden`,`true`))},E=(e,t,n,r,i)=>{if(e===null)return;if(i){e.classList.add(`hidden`);return}let a=t.blocks.getChildren(n);r&&a.length===0?e.classList.remove(`hidden`):e.classList.add(`hidden`)},D=async e=>{var n;let{api:r,blockId:i,data:a,getContentElement:o,syncContentFromDOM:s,isOpen:c}=e;if(s(),i===void 0)return;let l=o(),u=window.getSelection();if(!l||!u||u.rangeCount===0)return;let{beforeContent:d,afterContent:f}=A(l,u.getRangeAt(0)),p=(n=r.blocks.getBlockIndex(i))==null?r.blocks.getCurrentBlockIndex():n;if(c&&f===``){let e=k(r,i,p),t=r.blocks.insertInsideParent(i,e);r.caret.setToBlock(t.id,`start`);return}r.blocks.splitBlock(i,{text:d},t.p,{text:f},p+1),a.text=d},O=async(e,n)=>{let{api:r,blockId:i,data:a,getContentElement:o,syncContentFromDOM:s}=e;if(s(),i===void 0)return;let c=o();if(!c||!t.tr(c))return;let l=a.text;l===``&&(n.preventDefault(),await r.blocks.convert(i,`paragraph`,{text:l}))},k=(e,t,n)=>{var r;let i=e.blocks.getChildren(t);if(i.length===0)return n+1;let a=i[i.length-1],o=(r=e.blocks.getBlockIndex(a.id))==null?n:r;return k(e,a.id,o)},A=(e,t)=>{if(!e.lastChild)return{beforeContent:``,afterContent:``};let n=document.createRange();n.setStart(e,0),n.setEnd(t.startContainer,t.startOffset);let r=document.createRange();r.setStart(t.endContainer,t.endOffset),r.setEndAfter(e.lastChild);let i=document.createElement(`div`);i.appendChild(n.cloneContents());let a=document.createElement(`div`);return a.appendChild(r.cloneContents()),{beforeContent:i.innerHTML,afterContent:a.innerHTML}},j=async e=>{var t;let{api:n,blockId:r,getContentElement:i,syncContentFromDOM:a,isOpen:o,currentLevel:s}=e;if(a(),r===void 0)return;let c=i(),l=window.getSelection();if(!c||!l||l.rangeCount===0)return;let{beforeContent:u,afterContent:d}=A(c,l.getRangeAt(0)),f=(t=n.blocks.getBlockIndex(r))==null?n.blocks.getCurrentBlockIndex():t;if(o&&d===``){let e=k(n,r,f),t=n.blocks.insertInsideParent(r,e);n.caret.setToBlock(t.id,`start`);return}n.blocks.splitBlock(r,{text:u,level:s,isToggleable:!0},`header`,{text:d,level:s,isToggleable:!0},f+1)},M=async(e,n)=>{let{api:r,blockId:i,getText:a,getContentElement:o,syncContentFromDOM:s,currentLevel:c}=e;if(s(),i===void 0)return;let l=o();if(!l||!t.tr(l))return;let u=a();u===``&&(n.preventDefault(),await r.blocks.convert(i,`header`,{text:u,level:c}))},N,P=class e{constructor({data:e,config:t,api:n,readOnly:r,block:i}){var a;this.placeholderCleanup=null,this._arrowElement=null,this._wrapper=null,this._headerRow=null,this._childContainerElement=null,this._bodyPlaceholderElement=null,this.handleChildContainerInput=()=>{S(this._wrapper,this._childContainerElement)},this.handleKeyDown=e=>{if(e.key===`Enter`&&!e.shiftKey){e.preventDefault(),this.handleEnter();return}e.key===`Backspace`&&M(this.createKeyboardContext(),e)},this.handleBlockChanged=e=>{this.isBlockChangedPayload(e)&&(e.event.type===`block-removed`||e.event.type===`block-added`)&&this.updateBodyPlaceholderVisibility()},this.api=n,this.readOnly=r,this._settings=t||{},this._data=this.normalizeData(e),this._isOpen=(a=this._data.isOpen)==null?!0:a,this._element=this.getTag(),i&&(this.blockId=i.id),!r&&this._data.isToggleable&&this.api.events.on(`block changed`,this.handleBlockChanged)}get _CSS(){return{block:this.api.styles.block,wrapper:``}}isHeaderData(e){return typeof e==`object`&&!!e&&`text`in e}normalizeData(e){if(!this.isHeaderData(e))return{text:``,level:this.defaultLevel.number};let n=parseInt(String(e.level)),r=e.level!==void 0&&!isNaN(n),i={text:e.text||``,level:r?n:this.defaultLevel.number};if(e.isToggleable===!0&&(i.isToggleable=!0),typeof e.isOpen==`boolean`&&(i.isOpen=e.isOpen),i.text){let e=document.createElement(`div`);e.innerHTML=i.text;let n=e.querySelector(`[${t.u.toggleArrow}]`);n&&(n.remove(),i.text=e.innerHTML)}return i}render(){return this._data.isToggleable?(this._wrapper=this.buildWrapper(),this._wrapper):this._element}rendered(){this._data.isToggleable&&(this.updateChildrenVisibility(),this.updateBodyPlaceholderVisibility())}removed(){this.api.events.off(`block changed`,this.handleBlockChanged),this._element.removeEventListener(`keydown`,this.handleKeyDown)}setReadOnly(e){if(this._element)if(this.readOnly=e,e)this._element.contentEditable=`false`,this._data.isToggleable&&this._element.removeEventListener(`keydown`,this.handleKeyDown),this.placeholderCleanup&&(this.placeholderCleanup(),this.placeholderCleanup=null);else{this._element.contentEditable=`true`,this._data.isToggleable&&this._element.addEventListener(`keydown`,this.handleKeyDown);let e=this.api.i18n.t(this.currentLevel.nameKey),t=this.resolvePlaceholderText(e);this.placeholderCleanup=p(this._element,t)}}expand(){!this._data.isToggleable||this._isOpen||(this._isOpen=!0,this._arrowElement&&this._element&&w(this._arrowElement,this._element,this._isOpen,{collapse:this.api.i18n.t(`tools.toggle.ariaLabelCollapse`),expand:this.api.i18n.t(`tools.toggle.ariaLabelExpand`)}),this.updateChildrenVisibility(),this.updateBodyPlaceholderVisibility())}collapse(){!this._data.isToggleable||!this._isOpen||(this._isOpen=!1,this._arrowElement&&this._element&&w(this._arrowElement,this._element,this._isOpen,{collapse:this.api.i18n.t(`tools.toggle.ariaLabelCollapse`),expand:this.api.i18n.t(`tools.toggle.ariaLabelExpand`)}),this.updateChildrenVisibility(),this.updateBodyPlaceholderVisibility())}renderSettings(){return this.levels.map(e=>{let t=this.api.i18n.t(e.nameKey),n=t===e.nameKey?e.name:t;return{icon:e.icon,title:n,onActivate:()=>this.setLevel(e.number),closeOnActivate:!0,isActive:this.currentLevel.number===e.number,dataset:{"blok-header-level":String(e.number)}}})}setLevel(e){this.data={level:e,text:this.data.text,isToggleable:this._data.isToggleable}}merge(e){let n=document.createElement(`div`);n.innerHTML=e.text;let r=n.querySelector(`[${t.u.toggleArrow}]`);r&&r.remove(),this._element.insertAdjacentHTML(`beforeend`,n.innerHTML)}validate(e){return typeof e.text==`string`}setData(e){return this._data=this.normalizeData(e),typeof e.text==`string`&&(this._element.innerHTML=e.text),this._data.isToggleable&&typeof this._data.isOpen==`boolean`&&(this._isOpen=this._data.isOpen,this._arrowElement&&this._element&&w(this._arrowElement,this._element,this._isOpen,{collapse:this.api.i18n.t(`tools.toggle.ariaLabelCollapse`),expand:this.api.i18n.t(`tools.toggle.ariaLabelExpand`)}),this.updateChildrenVisibility(),this.updateBodyPlaceholderVisibility()),!0}save(e){let t={text:this._element.innerHTML,level:this.currentLevel.number};return this._data.isToggleable===!0&&(t.isToggleable=!0,t.isOpen=this._isOpen),t}static get conversionConfig(){return{export:`text`,import:`text`}}static get sanitize(){return{level:!1,text:{},isToggleable:!1,isOpen:!1}}static get isReadOnlySupported(){return!0}get data(){return this._data.text=this._element.innerHTML,this._data.level=this.currentLevel.number,this._data}set data(n){if(this._data=this.normalizeData(n),n.level!==void 0&&this._element.parentNode){this._element.removeEventListener(`keydown`,this.handleKeyDown);let e=this.getTag();e.innerHTML=this._element.innerHTML,this._element.parentNode.replaceChild(e,this._element),this._element=e}if(n.text!==void 0&&(this._element.innerHTML=this._data.text||``),this._data.isToggleable){if(this._element.setAttribute(t.u.toggleOpen,String(this._isOpen)),this._element.className=r.n(e.BASE_STYLES,this.currentLevel.styles,o,`pl-8`),!this._wrapper)this.createToggleWrapper();else if(!this._wrapper.querySelector(`[${t.u.toggleArrow}]`)){var i;let e=this.buildArrow();this._arrowElement=e,((i=this._headerRow)==null?this._wrapper:i).prepend(e)}}else if(this._element.removeAttribute(t.u.toggleOpen),this._element.className=r.n(e.BASE_STYLES,this.currentLevel.styles,o),this._arrowElement=null,this._wrapper){let e=this._wrapper.parentNode;e&&e.replaceChild(this._element,this._wrapper),this._wrapper=null,this._headerRow=null}}resolvePlaceholderText(e){return this._settings.placeholder?this.api.i18n.t(this._settings.placeholder):e===this.currentLevel.nameKey?this.currentLevel.name:e}getTag(){let n=document.createElement(this.currentLevel.tag);n.innerHTML=this._data.text||``,n.className=r.n(e.BASE_STYLES,this.currentLevel.styles,o,this._data.isToggleable?`pl-8`:``);let{inlineStyles:i}=this.currentLevel;i&&Object.assign(n.style,i),n.setAttribute(t.hi.tool,`header`),n.contentEditable=this.readOnly?`false`:`true`,this._data.isToggleable&&n.setAttribute(t.u.toggleOpen,String(this._isOpen));let a=this.api.i18n.t(this.currentLevel.nameKey),s=this.resolvePlaceholderText(a);return this.readOnly?n.setAttribute(`data-placeholder`,s):this.placeholderCleanup=p(n,s),!this.readOnly&&this._data.isToggleable&&n.addEventListener(`keydown`,this.handleKeyDown),n}buildArrow(){let e=v(this._isOpen,()=>this.toggleOpen(),{},{collapse:this.api.i18n.t(`tools.toggle.ariaLabelCollapse`),expand:this.api.i18n.t(`tools.toggle.ariaLabelExpand`)});return e.classList.add(`absolute`,`left-0`,`top-1/2`,`-translate-y-1/2`),e}buildWrapper(){let e=document.createElement(`div`);e.setAttribute(t.u.toggleEmpty,`true`);let n=document.createElement(`div`);n.className=`relative`,this._headerRow=n;let i=this.buildArrow();this._arrowElement=i,n.appendChild(i),n.appendChild(this._element),e.appendChild(n);let a=document.createElement(`div`);a.className=r.n(t.s,`pl-8`),a.setAttribute(t.u.toggleBodyPlaceholder,``),a.setAttribute(`data-blok-mutation-free`,`true`),a.textContent=this.api.i18n.t(`tools.toggle.bodyPlaceholder`),this.readOnly||a.addEventListener(`click`,()=>this.handleBodyPlaceholderClick()),this._bodyPlaceholderElement=a,e.appendChild(a);let o=document.createElement(`div`);return o.className=`pl-8`,o.setAttribute(t.u.toggleChildren,``),o.setAttribute(t.hi.nestedBlocks,``),o.setAttribute(`data-blok-mutation-free`,`true`),o.addEventListener(`input`,this.handleChildContainerInput),this._childContainerElement=o,e.appendChild(o),e}createToggleWrapper(){let e=this._element.parentNode;this._wrapper=document.createElement(`div`),this._wrapper.setAttribute(t.u.toggleEmpty,`true`);let n=document.createElement(`div`);n.className=`relative`,this._headerRow=n;let r=this.buildArrow();this._arrowElement=r,n.appendChild(r),e&&e.replaceChild(this._wrapper,this._element),n.appendChild(this._element),this._wrapper.appendChild(n)}createKeyboardContext(){return{api:this.api,blockId:this.blockId,getText:()=>this._element.innerHTML,getContentElement:()=>this._element,syncContentFromDOM:()=>{this._data.text=this._element.innerHTML},isOpen:this._isOpen,currentLevel:this.currentLevel.number}}async handleEnter(){var e=this;await j(e.createKeyboardContext()),e.updateChildrenVisibility(),e.updateBodyPlaceholderVisibility()}toggleOpen(){this._isOpen=!this._isOpen,this._arrowElement&&this._element&&w(this._arrowElement,this._element,this._isOpen,{collapse:this.api.i18n.t(`tools.toggle.ariaLabelCollapse`),expand:this.api.i18n.t(`tools.toggle.ariaLabelExpand`)}),this.updateChildrenVisibility(),this.updateBodyPlaceholderVisibility()}updateChildrenVisibility(){this.blockId!==void 0&&T(this.api,this.blockId,this._isOpen,this._childContainerElement,this._arrowElement)}updateBodyPlaceholderVisibility(){this.blockId!==void 0&&(E(this._bodyPlaceholderElement,this.api,this.blockId,this._isOpen,this.readOnly),S(this._wrapper,this._childContainerElement))}handleBodyPlaceholderClick(){var e;if(this.blockId===void 0)return;let t=this.api.blocks.getBlockIndex(this.blockId);if(t===void 0)return;let n=this.api.blocks.insertInsideParent(this.blockId,t+1);this.api.caret.setToBlock(n.id,`start`),(e=this._bodyPlaceholderElement)==null||e.classList.add(`hidden`)}isBlockChangedPayload(e){return typeof e==`object`&&!!e&&`event`in e&&typeof e.event==`object`&&e.event!==null&&`type`in e.event&&typeof e.event.type==`string`}get currentLevel(){let e=this.levels.find(e=>e.number===this._data.level);return e==null?this.defaultLevel:e}get defaultLevel(){return this._settings.defaultLevel?this.levels.find(e=>e.number===this._settings.defaultLevel)||(console.warn(`(ง'̀-'́)ง Heading Tool: the default level specified was not found in available levels`),this.levels[1]):this.levels[1]}get levels(){let t=this._settings.levelOverrides||{},n=e.DEFAULT_LEVELS.map(e=>{var n;let r=t[e.number]||{},i={};return r.size&&(i.fontSize=r.size),r.marginTop&&(i.marginTop=r.marginTop),r.marginBottom&&(i.marginBottom=r.marginBottom),{number:e.number,tag:((n=r.tag)==null?void 0:n.toUpperCase())||e.tag,nameKey:e.nameKey,name:r.name||e.name,icon:e.icon,styles:e.styles,inlineStyles:i}}),r=this._settings.levels;return r?n.filter(e=>r.includes(e.number)):n}onPaste(e){var t;let n=e.detail;if(!(`data`in n))return;let r=n.data,i=(t={H1:1,H2:2,H3:3,H4:4,H5:5,H6:6}[r.tagName])==null?this.defaultLevel.number:t,a=this._settings.levels?this._settings.levels.reduce((e,t)=>Math.abs(t-i)<Math.abs(e-i)?t:e):i;this.data={level:a,text:r.innerHTML}}static get pasteConfig(){return{tags:[`H1`,`H2`,`H3`,`H4`,`H5`,`H6`]}}static get toolbox(){let n=e.DEFAULT_LEVELS.map(e=>({icon:e.icon,title:e.name,titleKey:e.nameKey,name:`header-${e.number}`,data:{level:e.number},searchTerms:[`h${e.number}`,`title`,`header`,`heading`],searchTermKeys:[`title`,`header`,`heading`],shortcut:`#`.repeat(e.number)})),r={1:t.yn,2:t.bn,3:t.xn},i=e.DEFAULT_LEVELS.filter(e=>e.number<=3).map(e=>({icon:r[e.number],title:`Toggle heading ${e.number}`,titleKey:`tools.header.toggleHeading${e.number}`,name:`toggle-header-${e.number}`,data:{level:e.number,isToggleable:!0},searchTerms:[`toggle`,`heading`,`h${e.number}`,`collapsible`],searchTermKeys:[`toggle`,`heading`,`collapsible`],shortcut:`>`+`#`.repeat(e.number)}));return[...n,...i]}};N=P,N.BASE_STYLES=`py-[7px] px-[2px] m-0 leading-[1.3]! outline-hidden [&_p]:p-0! [&_p]:m-0! [&_div]:p-0! [&_div]:m-0!`,N.DEFAULT_LEVELS=[{number:1,tag:`H1`,nameKey:`tools.header.heading1`,name:`Heading 1`,icon:t.Ct,styles:`text-3xl font-semibold mt-8 mb-px`},{number:2,tag:`H2`,nameKey:`tools.header.heading2`,name:`Heading 2`,icon:t.wt,styles:`text-2xl font-semibold mt-[26px] mb-px`},{number:3,tag:`H3`,nameKey:`tools.header.heading3`,name:`Heading 3`,icon:t.Tt,styles:`text-xl font-semibold mt-5 mb-px`},{number:4,tag:`H4`,nameKey:`tools.header.heading4`,name:`Heading 4`,icon:t.Et,styles:`text-lg font-semibold mt-3 mb-px`},{number:5,tag:`H5`,nameKey:`tools.header.heading5`,name:`Heading 5`,icon:t.Dt,styles:`text-base font-semibold mt-3 mb-px`},{number:6,tag:`H6`,nameKey:`tools.header.heading6`,name:`Heading 6`,icon:t.Ot,styles:`text-sm font-semibold mt-3 mb-px`}];var ee=`outline-hidden py-[7px] mt-[2px] mb-px`,te=`outline-hidden pl-0.5 leading-[1.5] items-start`,ne=`flex items-start pl-0.5`,re=`mt-0.5 w-5 mr-2 h-5 cursor-pointer accent-current`,ie=`tools.list.placeholder`,ae=`list`,F={contentContainer:`list-content-container`,checklistContent:`list-checklist-content`},oe=(e,t)=>{let n=e;n._placeholder=t,Object.defineProperty(n,`getPlaceholder`,{value:()=>n._placeholder,writable:!1,enumerable:!0,configurable:!1})},se=e=>{let{data:t,keydownHandler:n,readOnly:r}=e,i=ce(e),a=t.style===`checklist`?ue(e):le(e);i.appendChild(a),!r&&n&&i.addEventListener(`keydown`,n);let o=a.querySelector(`[data-list-marker]`),s=a.querySelector(`input[type="checkbox"]`),c=t.style===`checklist`?a.querySelector(`[data-blok-testid="${F.checklistContent}"]`):a.querySelector(`[data-blok-testid="${F.contentContainer}"]`);return{wrapper:i,contentElement:c==null?a:c,markerElement:o,checkboxElement:s}},ce=e=>{var n;let{data:r}=e,i=document.createElement(`div`);return i.className=ee,i.setAttribute(t.hi.tool,ae),i.setAttribute(`data-list-style`,r.style),i.setAttribute(`data-list-depth`,String((n=r.depth)==null?0:n)),r.start!==void 0&&r.start!==1&&i.setAttribute(`data-list-start`,String(r.start)),i},le=e=>{var t;let{data:n,itemColor:i,itemSize:a,placeholder:s,markerDepth:c}=e,l=document.createElement(`div`);l.setAttribute(`role`,`listitem`),l.className=r.n(te,`flex`,...o),i&&(l.style.color=i),a&&(l.style.fontSize=a);let u=(t=n.depth)==null?0:t;if(u>0){let e=n.style===`ordered`?26:27;l.style.marginLeft=`${u*e}px`}let d=de(n.style,c==null?u:c);d.setAttribute(`data-list-marker`,`true`),d.setAttribute(`data-blok-mutation-free`,`true`),l.appendChild(d);let f=document.createElement(`div`);return f.className=r.n(`flex-1 min-w-0 outline-hidden`,...o),f.setAttribute(`data-blok-testid`,F.contentContainer),f.contentEditable=e.readOnly?`false`:`true`,f.innerHTML=n.text,oe(f,s),l.appendChild(f),l},ue=e=>{var t;let{data:n,itemColor:i,itemSize:a,placeholder:s,readOnly:c}=e,l=document.createElement(`div`);l.setAttribute(`role`,`listitem`),l.className=ne,i&&(l.style.color=i),a&&(l.style.fontSize=a);let u=(t=n.depth)==null?0:t;u>0&&(l.style.marginLeft=`${u*27}px`);let d=document.createElement(`input`);d.type=`checkbox`,d.className=re,d.checked=!!n.checked,d.disabled=c;let f=document.createElement(`div`);return f.className=r.n(`flex-1 outline-hidden leading-[1.5]`,n.checked?`line-through opacity-60`:``,...o),f.setAttribute(`data-blok-testid`,F.checklistContent),f.setAttribute(`data-checked`,String(n.checked)),f.contentEditable=c?`false`:`true`,f.innerHTML=n.text,oe(f,s),l.appendChild(d),l.appendChild(f),l},de=(e,t)=>{let n=document.createElement(`span`);return n.className=`shrink-0 select-none`,n.setAttribute(`aria-hidden`,`true`),n.contentEditable=`false`,e===`ordered`?(n.textContent=`1.`,n.className=r.n(n.className,`text-right`),n.style.paddingRight=`11px`,n.style.minWidth=`fit-content`):(n.textContent=fe(t),n.className=r.n(n.className,`w-6 text-center flex justify-center`),n.style.paddingLeft=`1px`,n.style.paddingRight=`13px`,n.style.fontSize=`24px`,n.style.fontFamily=`Arial`,n.style.lineHeight=`1.5rem`),n},fe=e=>{let t=[`•`,`◦`,`▪`];return t[e%t.length]},pe=e=>{let{data:t,readOnly:n,placeholder:r,itemColor:i,itemSize:a,markerDepth:o,element:s,setupItemPlaceholder:c,onCheckboxChange:l,keydownHandler:u}=e;if(!s)return null;let d=s.parentNode;if(!d)return null;let f=se({data:t,readOnly:n,placeholder:r,itemColor:i,itemSize:a,markerDepth:o,keydownHandler:u});if(f.contentElement&&c(f.contentElement),f.checkboxElement&&!n){let e=f.checkboxElement;e.addEventListener(`change`,()=>{l(e.checked,f.contentElement)})}return d.replaceChild(f.wrapper,s),f.wrapper},me=(e,r,i)=>{if(!r)return e;let a=i(),o=n.t({text:a?t.Vr(a.innerHTML):e.text,style:e.style},e.style===`checklist`?{checked:!!e.checked}:{});return e.start!==void 0&&e.start!==1&&(o.start=e.start),e.depth!==void 0&&e.depth>0&&(o.depth=e.depth),o},he=(e,t,r,i,a)=>{var o,s;if(!r)return{newData:e,inPlace:!1};let c=(o=e.depth)==null?0:o,l=(s=t.depth)==null?0:s,u=e.style,d=t.style;if(u!==d)return{newData:e,inPlace:!1};let f=`depth`in t?t.depth:0,p=n.t(n.t(n.t({},e),t),{},{depth:f}),m=i();if(m&&typeof t.text==`string`&&(m.innerHTML=t.text),c!==l)return a.adjustDepthTo(l),a.updateMarkerForDepth(l,d),{newData:p,inPlace:!0};if(d===`checklist`){var h;a.updateCheckboxState((h=t.checked)==null?!1:h)}return{newData:p,inPlace:!0}},ge=(e,t)=>{let{element:n,getContentElement:r,parseHTML:i,data:a}=e;if(!n)return;a.text+=t.text;let o=r();if(o&&t.text){let e=i(t.text);o.appendChild(e),o.normalize()}},_e=(e,t,n,r)=>e.map(e=>({icon:e.icon,title:n(`toolNames.${e.titleKey}`),onActivate:()=>r(e.style),closeOnActivate:!0,isActive:t===e.style})),ve=e=>{if(!e)return;let t=(e.getAttribute(`style`)||``).match(/margin-left:\s*(\d+)px/);if(!t)return;let n=parseInt(t[1],10);return n>0?{left:n}:void 0},ye=e=>{let t=e.closest(`[data-list-depth]`);if(!t)return;let n=t.getAttribute(`data-list-depth`);if(n===null)return;let r=parseInt(n,10);return r>0?{left:r*27}:void 0},be=e=>{let t=ve(e.closest(`[role="listitem"]`)||e.querySelector(`[role="listitem"]`));return t===void 0?ye(e):t},xe=(e,t)=>{let n=document.createRange();if(n.setStart(e,0),n.setEnd(t.startContainer,t.startOffset),!e.lastChild)return{beforeContent:``,afterContent:``};let r=document.createRange();return r.setStart(t.endContainer,t.endOffset),r.setEndAfter(e.lastChild),{beforeContent:Se(n.cloneContents()),afterContent:Se(r.cloneContents())}},Se=e=>{let t=document.createElement(`div`);return t.appendChild(e),t.innerHTML},Ce=e=>{let t=document.createElement(`div`);t.innerHTML=e.trim();let n=document.createDocumentFragment();return n.append(...Array.from(t.childNodes)),n},we=(e,t)=>{let n=document.createRange();return n.selectNodeContents(e),n.setEnd(t.startContainer,t.startOffset),n.toString().length===0},Te=(e,t)=>{let n=document.createRange();n.selectNodeContents(e),n.setEnd(t.startContainer,t.startOffset);let r=n.toString().length===0,i=document.createRange();i.selectNodeContents(e),i.setStart(t.endContainer,t.endOffset);let a=i.toString().length===0;return r&&a},Ee=e=>{if(typeof e!=`object`||!e)return!1;let t=Object.entries(e).find(([e])=>e===`items`);return t===void 0?!1:Array.isArray(t[1])},De=e=>typeof e==`object`&&!!e,Oe=e=>typeof e==`string`?e:``,ke=(e,t)=>e===`unordered`||e===`ordered`||e===`checklist`?e:t,Ae=e=>!!e,je=(e,t)=>typeof e==`number`?e:t,Me=(e,t)=>{let r=t.defaultStyle||`unordered`;if(!e||typeof e!=`object`)return{text:``,style:r,checked:!1,depth:0};if(Ee(e)){let{text:t,checked:i}=(e=>{if(typeof e==`string`)return{text:e,checked:!1};if(typeof e==`object`&&e){var t,n,r;return{text:(t=(n=e.content)==null?e.text:n)==null?``:t,checked:(r=e.checked)==null?!1:r}}return{text:``,checked:!1}})(e.items[0]);return n.t({text:t,style:e.style||r,checked:!!i,depth:0},e.start!==void 0&&e.start!==1?{start:e.start}:{})}if(De(e)){let t=Oe(e.text),i=ke(e.style,r),a=Ae(e.checked),o=je(e.depth,0),s=e.start,c=typeof s==`number`&&s!==void 0&&s!==1?s:void 0;return n.t({text:t,style:i,checked:a,depth:o},c===void 0?{}:{start:c})}return{text:``,style:r,checked:!1,depth:0}},Ne=class{constructor(e){this.blocks=e}getMaxAllowedDepth(e){if(e===0)return 1;let t=this.blocks.getBlockByIndex(e-1);return!t||t.name!==`list`?1:this.getBlockDepth(t)+1}getTargetDepthForMove(e){let{blockIndex:t,currentDepth:n,skipDepthPromotion:r}=e,i=this.getMaxAllowedDepth(t);if(n>i)return i;if(r)return n;let a=this.blocks.getBlockByIndex(t+1),o=a&&a.name===`list`,s=o?this.getBlockDepth(a):0;if(o&&s>n&&s<=i)return s;let c=t>0?this.blocks.getBlockByIndex(t-1):void 0,l=c&&c.name===`list`,u=l?this.getBlockDepth(c):0;return l&&!o&&u>n&&u<=i?u:n}isValidDepth(e,t){let n=this.getMaxAllowedDepth(e);return t>=0&&t<=n}getBlockDepth(e){var t;if(!e)return 0;let n=(t=e.holder)==null||(t=t.querySelector(`[role="listitem"]`))==null?void 0:t.getAttribute(`style`),r=n==null?void 0:n.match(/margin-left:\s*(\d+)px/);return r?Math.round(parseInt(r[1],10)/27):0}},Pe=(e,t)=>{if(!e)return null;if(t===`checklist`){let t=e.querySelector(`[data-blok-testid="list-checklist-content"]`);return t instanceof HTMLElement?t:null}let n=e.querySelector(`[data-blok-testid="list-content-container"]`);return n instanceof HTMLElement?n:null},Fe=(e,t,n)=>{e&&e.setAttribute(`data-list-depth`,String(n));let r=e==null?void 0:e.querySelector(`[role="listitem"]`);r instanceof HTMLElement&&(r.style.marginLeft=n>0?`${n*27}px`:``),t.depth=n},Ie=(e,t)=>t.getBlockDepth(e),Le=(e,t)=>t.getBlockStyle(e),Re=(e,t)=>t.getBulletCharacter(e),ze=(e,t,n,r,i)=>{var a;let o=e?(a=r.getBlockIndex(e))==null?r.getCurrentBlockIndex():a:r.getCurrentBlockIndex();return o<=0?0:i.getSiblingIndex(o,t,n)},Be=(e,t,n,r,i,a)=>{var o;if(e===0){var s;return(s=r.start)==null?1:s}let c=n?(o=i.getBlockIndex(n))==null?i.getCurrentBlockIndex():o:i.getCurrentBlockIndex(),l=a.findFirstItemIndex(c-1,t,e,r.style);return l===null?1:a.getBlockStartValue(l)},Ve=(e,t,n,r,i,a)=>{var o;let s=Be(e,t,r,n,i,a)+e,c=r?(o=i.getBlockIndex(r))==null?i.getCurrentBlockIndex():o:i.getCurrentBlockIndex(),l=a.getVisualDepth(c,t);return a.formatNumber(s,l)},He=(e,t,n,r)=>r.findGroupStart(e,t,n),Ue=(e,t,n,r)=>{if(!e)return;let i=e.holder,a=i==null?void 0:i.querySelector(`[data-list-style="ordered"]`);if(!a)return;let o=a.querySelector(`[data-list-marker]`);if(!o)return;let s=t.getBlockIndex(e.id);if(s==null)return;let c=Ie(e,n),l=Le(e,r)||`ordered`,u=r.getSiblingIndex(s,c,l),d=r.getGroupStartValue(s,c,u,l)+u,f=r.getVisualDepth(s,c);o.textContent=r.formatNumber(d,f)},We=(e,t,n,r,i,a,o,s)=>{let c=e=>{if(e>=t)return;if(e===n){c(e+1);return}let l=a.getBlockByIndex(e);if(!l||l.name!==`list`)return;let u=Ie(l,o);if(!(u<r)){if(u>r){c(e+1);return}Le(l,s)===i&&(Ue(l,a,o,s),c(e+1))}};c(e)},Ge=(e,t,n)=>{let r=e.getBlocksCount();Array.from({length:r},(e,t)=>t).forEach(r=>{let i=e.getBlockByIndex(r);if(!i||i.name!==`list`)return;let a=i.holder;a!=null&&a.querySelector(`[data-list-style="ordered"]`)&&Ue(i,e,t,n)})},Ke=(e,t,n=`end`)=>{let r=()=>{let r=t.holder;if(!r)return;let i=r.querySelector(`[contenteditable="true"]`);if(!(i instanceof HTMLElement)){e.caret.setToBlock(t,n),e.caret.updateLastCaretAfterPosition();return}i.focus();let a=window.getSelection();if(!a)return;let o=document.createRange();n===`start`?(o.setStart(i,0),o.collapse(!0)):(o.selectNodeContents(i),o.collapse(!1)),a.removeAllRanges(),a.addRange(o),e.caret.updateLastCaretAfterPosition()},i=t.holder;(i==null?void 0:i.querySelector(`[contenteditable="true"]`))instanceof HTMLElement?r():requestAnimationFrame(()=>r())},qe=async(e,t)=>{var r;let{api:i,blockId:a,data:o,element:s,getContentElement:c}=e,l=window.getSelection();if(!l||!s)return;let u=c();if(!u)return;let d=u.innerHTML.trim();if(d===``||d===`<br>`){await Je(e,t);return}let{beforeContent:f,afterContent:p}=xe(u,l.getRangeAt(0)),m=a?(r=i.blocks.getBlockIndex(a))==null?i.blocks.getCurrentBlockIndex():r:i.blocks.getCurrentBlockIndex();if(!a){u.innerHTML=f,o.text=f,Ke(i,i.blocks.insert(ae,n.t(n.t({text:p,style:o.style},o.style===`checklist`?{checked:!!o.checked}:{}),{},{depth:o.depth}),void 0,m+1,!0),`start`);return}let h=i.blocks.splitBlock(a,{text:f},ae,n.t(n.t({text:p,style:o.style},o.style===`checklist`?{checked:!!o.checked}:{}),{},{depth:o.depth}),m+1);o.text=f,Ke(i,h,`start`)},Je=async(e,t)=>{let{api:n,blockId:r,getDepth:i}=e;if(i()>0){await Qe(e,t);return}r!==void 0&&Ke(n,await n.blocks.convert(r,`paragraph`,{text:``}),`start`)},Ye=async(e,t)=>{let{api:n,blockId:r,data:i,element:a,getContentElement:o,getDepth:s,syncContentFromDOM:c}=e,l=window.getSelection();if(!l||!a)return;let u=l.getRangeAt(0),d=o();if(!d)return;c();let f=i.text,p=s();if(Te(d,u)&&!l.isCollapsed){t.preventDefault(),d.innerHTML=``,i.text=``;let e=document.createRange();e.setStart(d,0),e.collapse(!0),l.removeAllRanges(),l.addRange(e);return}if(!we(d,u)||(t.preventDefault(),r===void 0))return;let m=await n.blocks.convert(r,`paragraph`,{text:f});p>0&&requestAnimationFrame(()=>{let e=m.holder;e&&(e.style.marginLeft=`${p*27}px`,e.setAttribute(`data-blok-depth`,String(p)))}),Ke(n,m,`start`)},Xe=async(e,t)=>{let{api:r,blockId:i,data:a,syncContentFromDOM:o,getDepth:s}=e,c=r.blocks.getCurrentBlockIndex(),l=s();if(l>=t.getMaxAllowedDepth(c))return;o();let u=l+1;a.depth=u,Ke(r,await r.blocks.update(i||``,n.t(n.t({},a),{},{depth:u})))},Ze=async(e,t,n,r)=>{var i;let a=t?(i=e.blocks.getBlockIndex(t))==null?e.blocks.getCurrentBlockIndex():i:e.blocks.getCurrentBlockIndex(),o=e.blocks.getBlocksCount(),s=async t=>{if(t>=o)return;let i=e.blocks.getBlockByIndex(t);if(!i||i.name!==`list`)return;let a=r.getBlockDepth(i);a<=n||(await e.blocks.update(i.id,{depth:a-1}),await s(t+1))};await s(a+1)},Qe=async(e,t)=>{let{api:r,blockId:i,data:a,syncContentFromDOM:o,getDepth:s}=e,c=s();if(c===0)return;o();let l=c-1;a.depth=l;let u=await r.blocks.update(i||``,n.t(n.t({},a),{},{depth:l}));t&&await Ze(r,i,c,t),Ke(r,u)},$e=e=>{let{data:t,readOnly:n,placeholder:r,itemColor:i,itemSize:a,markerDepth:o,setupItemPlaceholder:s,onCheckboxChange:c,keydownHandler:l}=e,u=se({data:t,readOnly:n,placeholder:r,itemColor:i,itemSize:a,markerDepth:o,keydownHandler:l});if(u.contentElement&&s(u.contentElement),u.checkboxElement&&!n){let e=u.checkboxElement;e.addEventListener(`change`,()=>{c(e.checked,u.contentElement)})}return u.wrapper},et=e=>{let t=e=>{if(e<=0)return``;let n=e-1;return t(Math.floor(n/26))+String.fromCharCode(97+n%26)};return t(e)},tt=e=>{let t=[[1e3,`m`],[900,`cm`],[500,`d`],[400,`cd`],[100,`c`],[90,`xc`],[50,`l`],[40,`xl`],[10,`x`],[9,`ix`],[5,`v`],[4,`iv`],[1,`i`]],n=(e,r)=>{if(e<=0||r>=t.length)return``;let[i,a]=t[r];return e>=i?a+n(e-i,r):n(e,r+1)};return n(e,0)},nt=class{constructor(e){this.blocks=e}getMarkerText(e){let{blockIndex:t,depth:n,style:r,start:i}=e;if(r!==`ordered`)return this.getBulletCharacter(n);let a=this.getSiblingIndex(t,n,r),o=(i==null?this.getGroupStartValue(t,n,a,r):i)+a;return this.formatNumber(o,n)}getBulletCharacter(e){let t=[`•`,`◦`,`▪`];return t[e%t.length]}getSiblingIndex(e,t,n){return e<=0?0:this.countPrecedingAtDepth(e-1,t,n)}findGroupStart(e,t,n){return this.findGroupStartRecursive(e-1,e,t,n)}formatNumber(e,t){let n=t%3;return n===1?`${et(e)}.`:n===2?`${tt(e)}.`:`${e}.`}getGroupStartValue(e,t,n,r){if(n===0)return this.getBlockStartValue(e);let i=this.findFirstItemIndex(e-1,t,n,r);return i===null?1:this.getBlockStartValue(i)}getBlockStartValue(e){var t;let n=this.blocks.getBlockByIndex(e);if(!n)return 1;let r=(t=n.holder)==null?void 0:t.querySelector(`[data-list-style]`);if(!r)return 1;let i=r.getAttribute(`data-list-start`);return i?parseInt(i,10):1}findFirstItemIndex(e,t,n,r){if(e<0||n<=0)return e+1;let i=this.blocks.getBlockByIndex(e);if(!i||i.name!==`list`)return e+1;let a=this.getBlockDepth(i);if(a<t)return e+1;if(a>t)return this.findFirstItemIndex(e-1,t,n,r);let o=this.getBlockStyle(i);return r!==void 0&&o!==r?e+1:this.findFirstItemIndex(e-1,t,n-1,r)}getGroupBaseDepth(e){let t=e=>{if(e<=0)return 0;let n=this.blocks.getBlockByIndex(e-1);return!n||n.name!==`list`?e:t(e-1)},n=t(e),r=this.blocks.getBlockByIndex(n);return this.getBlockDepth(r)}getVisualDepth(e,t){return Math.max(0,t-this.getGroupBaseDepth(e))}getBlockDepth(e){var t;if(!e)return 0;let n=(t=e.holder)==null||(t=t.querySelector(`[role="listitem"]`))==null?void 0:t.getAttribute(`style`),r=n==null?void 0:n.match(/margin-left:\s*(\d+)px/);return r?Math.round(parseInt(r[1],10)/27):0}getBlockStyle(e){var t;if(!e)return null;let n=(t=e.holder)==null||(t=t.querySelector(`[data-list-style]`))==null?void 0:t.getAttribute(`data-list-style`);return this.isValidListItemStyle(n)?n:null}isValidListItemStyle(e){return e===`unordered`||e===`ordered`||e===`checklist`}countPrecedingAtDepth(e,t,n){if(e<0)return 0;let r=this.blocks.getBlockByIndex(e);if(!r||r.name!==`list`)return 0;let i=this.getBlockDepth(r);return i<t?0:i>t?this.countPrecedingAtDepth(e-1,t,n):this.getBlockStyle(r)===n?1+this.countPrecedingAtDepth(e-1,t,n):0}findGroupStartRecursive(e,t,n,r){if(e<0)return t;let i=this.blocks.getBlockByIndex(e);if(!i||i.name!==`list`)return t;let a=this.getBlockDepth(i);return a<n?t:a>n?this.findGroupStartRecursive(e-1,t,n,r):this.getBlockStyle(i)===r?this.findGroupStartRecursive(e-1,e,n,r):t}},rt={value:!1},it=class{constructor(e){this.blocks=e,this.depthValidator=new Ne(e),this.markerCalculator=new nt(e)}updateMarker(e,t,n){let r=e.querySelector(`[data-list-marker]`);if(!r)return;let i=this.markerCalculator.getSiblingIndex(t,n,`ordered`),a=this.markerCalculator.getGroupStartValue(t,n,i,`ordered`),o=(i===0&&a===1?(()=>{let t=e.getAttribute(`data-list-start`);if(!t)return a;let n=parseInt(t,10);return isNaN(n)?a:n})():a)+i,s=this.markerCalculator.getVisualDepth(t,n);r.textContent=this.markerCalculator.formatNumber(o,s)}updateSiblingMarkers(e,t){let n=this.blocks.getBlocksCount(),r=this.findListGroupStartIndex(e,t,`ordered`);this.updateMarkersInRange(r,n,e,t,`ordered`)}updateAllMarkers(){let e=this.blocks.getBlocksCount();for(let t of Array.from({length:e},(e,t)=>t)){let e=this.blocks.getBlockByIndex(t);if(!e||e.name!==`list`)continue;let n=e.holder;n!=null&&n.querySelector(`[data-list-style="ordered"]`)&&this.updateBlockMarker(e)}}scheduleUpdateAll(){rt.value||(rt.value=!0,requestAnimationFrame(()=>{rt.value=!1,this.updateAllMarkers()}))}findListGroupStartIndex(e,t,n){return this.markerCalculator.findGroupStart(e,t,n)}updateMarkersInRange(e,t,n,r,i){let a=Array.from({length:t-e},(t,n)=>e+n);for(let e of a){if(e===n)continue;let t=this.blocks.getBlockByIndex(e);if(!t||t.name!==`list`)return;let a=this.depthValidator.getBlockDepth(t);if(a<r)return;if(!(a>r)){if(this.getBlockStyle(t)!==i)return;this.updateBlockMarker(t)}}}getBlockStyle(e){return this.markerCalculator.getBlockStyle(e)}updateBlockMarker(e){if(!e)return;let t=e.holder,n=t==null?void 0:t.querySelector(`[data-list-style="ordered"]`);if(!n)return;let r=n.querySelector(`[data-list-marker]`);if(!r)return;let i=this.blocks.getBlockIndex(e.id);if(i==null)return;let a=this.depthValidator.getBlockDepth(e),o=this.getBlockStyle(e)||`ordered`,s=this.markerCalculator.getSiblingIndex(i,a,o),c=this.markerCalculator.getGroupStartValue(i,a,s,o),l=(s===0&&c===1?(()=>{let e=n.closest(`[data-list-start]`),t=e==null?void 0:e.getAttribute(`data-list-start`);if(!t)return c;let r=parseInt(t,10);return isNaN(r)?c:r})():c)+s,u=this.markerCalculator.getVisualDepth(i,a);r.textContent=this.markerCalculator.formatNumber(l,u)}},at=e=>e instanceof HTMLElement,ot=new Set(`decimal.decimal-leading-zero.lower-roman.upper-roman.lower-greek.lower-latin.upper-latin.lower-alpha.upper-alpha.arabic-indic.armenian.bengali.cambodian.cjk-decimal.devanagari.georgian.gujarati.gurmukhi.hebrew.kannada.khmer.lao.malayalam.mongolian.myanmar.oriya.persian.telugu.thai.tibetan`.split(`.`)),st=new Set([`disc`,`circle`,`square`,`none`]),ct=e=>{let t=e.getAttribute(`data-list-style`);if(t===`ordered`)return`ordered`;if(t===`unordered`)return`unordered`;let n=e.getAttribute(`style`);if(!n)return null;let r=n.match(/list-style-type\s*:\s*([^;]+)/);if(!r)return null;let i=r[1].trim().toLowerCase();return ot.has(i)?`ordered`:st.has(i)?`unordered`:null},lt=(e,t)=>{let n=e.parentElement;return(n==null?void 0:n.tagName)===`OL`?`ordered`:(n==null?void 0:n.tagName)===`UL`?e.querySelector(`input[type="checkbox"]`)?`checklist`:`unordered`:ct(e)||t},ut=e=>{let t=e.innerHTML||e.textContent||``,n=e.querySelector(`input[type="checkbox"]`);return{text:t,checked:n instanceof HTMLInputElement?n.checked:!1}},dt=e=>{let t=e.getAttribute(`aria-level`);return t?Math.max(0,parseInt(t,10)-1):0},ft=()=>({text:{br:!0,a:{href:!0,target:`_blank`,rel:`nofollow`},b:!0,i:!0}}),pt=()=>({tags:[{li:{style:!0,"aria-level":!0}}]}),mt=()=>({export:e=>e.text,import:e=>({text:e,style:`unordered`,checked:!1})}),ht=[{name:`bulletedList`,titleKey:`bulletedList`,style:`unordered`,icon:t.Kt},{name:`numberedList`,titleKey:`numberedList`,style:`ordered`,icon:t.Jt},{name:`todoList`,titleKey:`todoList`,style:`checklist`,icon:t.qt}],gt=()=>[{icon:t.Kt,titleKey:`bulletedList`,data:{style:`unordered`},name:`bulleted-list`,searchTerms:[`ul`,`bullet`,`unordered`,`list`],searchTermKeys:[`bullet`,`unordered`,`list`],shortcut:`-`},{icon:t.Jt,titleKey:`numberedList`,data:{style:`ordered`},name:`numbered-list`,searchTerms:[`ol`,`ordered`,`number`,`list`],searchTermKeys:[`ordered`,`number`,`list`],shortcut:`1.`},{icon:t.qt,titleKey:`todoList`,data:{style:`checklist`},name:`check-list`,searchTerms:[`checkbox`,`task`,`todo`,`check`,`list`],searchTermKeys:[`checkbox`,`task`,`todo`,`check`,`list`],shortcut:`[]`}],_t=class{constructor({data:e,config:t,api:n,readOnly:r,block:i}){this._element=null,this.placeholderCleanup=null,this.boundHandleKeyDown=null,this.handleBlockChanged=e=>{if(this.isBlockChangedEventPayload(e)&&(e.event.type===`block-removed`||e.event.type===`block-added`)){var t;(t=this.markerManager)==null||t.scheduleUpdateAll()}},this.api=n,this.readOnly=r,this._settings=t||{},this._data=this.normalizeData(e),this.depthValidator=new Ne(n.blocks),this.markerCalculator=new nt(n.blocks),this.markerManager=this._data.style===`ordered`?new it(n.blocks):null,i&&(this.blockId=i.id),this._data.style===`ordered`&&this.api.events.on(`block changed`,this.handleBlockChanged)}isBlockChangedEventPayload(e){return typeof e==`object`&&!!e&&`event`in e&&typeof e.event==`object`&&e.event!==null&&`type`in e.event&&typeof e.event.type==`string`}normalizeData(e){return Me(e,this._settings)}get availableStyles(){let e=this._settings.styles;return!e||e.length===0?ht:ht.filter(t=>e.includes(t.style))}get itemColor(){return this._settings.itemColor}get itemSize(){return this._settings.itemSize}get placeholder(){return this.api.i18n.t(ie)}setupItemPlaceholder(e){this.readOnly||(this.placeholderCleanup=p(e,this.placeholder))}render(){var e,t;if(this._element)return this._element;let n=this.blockId?(e=this.api.blocks.getBlockIndex(this.blockId))==null?this.api.blocks.getCurrentBlockIndex():e:this.api.blocks.getCurrentBlockIndex(),r=(t=this._data.depth)==null?0:t,i=this.markerCalculator.getVisualDepth(n,r);return this.boundHandleKeyDown||(this.boundHandleKeyDown=this.handleKeyDown.bind(this)),this._element=$e({data:this._data,readOnly:this.readOnly,placeholder:this.placeholder,itemColor:this.itemColor,itemSize:this.itemSize,markerDepth:i,setupItemPlaceholder:this.setupItemPlaceholder.bind(this),onCheckboxChange:(e,t)=>{this._data.checked=e,t instanceof HTMLElement&&(t.classList.toggle(`line-through`,e),t.classList.toggle(`opacity-60`,e))},keydownHandler:this.readOnly?void 0:this.boundHandleKeyDown}),this._element}setReadOnly(e){if(!this._element)return;this.readOnly=e;let t=this.getContentElement();t&&(t.contentEditable=e?`false`:`true`);let n=this._element.querySelector(`input[type="checkbox"]`);n&&(n.disabled=e),e?(this.boundHandleKeyDown&&this._element.removeEventListener(`keydown`,this.boundHandleKeyDown),this.placeholderCleanup&&(this.placeholderCleanup(),this.placeholderCleanup=null)):(this.boundHandleKeyDown&&this._element.addEventListener(`keydown`,this.boundHandleKeyDown),t&&(this.placeholderCleanup=p(t,this.placeholder)))}rendered(){this.updateMarkersAfterPositionChange()}moved(e){this.validateAndAdjustDepthAfterMove(e.toIndex,e.isGroupMove),this.updateMarkersAfterPositionChange()}updateMarkersAfterPositionChange(){this._data.style!==`ordered`||!this._element||(this.updateMarker(),this.updateSiblingListMarkers())}validateAndAdjustDepthAfterMove(e,t){let n=this.getDepth(),r=this.depthValidator.getTargetDepthForMove({blockIndex:e,currentDepth:n,skipDepthPromotion:t});n!==r&&this.adjustDepthTo(r)}adjustDepthTo(e){Fe(this._element,this._data,e)}removed(){var e;this._data.style===`ordered`&&(this.api.events.off(`block changed`,this.handleBlockChanged),(e=this.markerManager)==null||e.scheduleUpdateAll())}updateAllOrderedListMarkers(){Ge(this.api.blocks,this.depthValidator,this.markerCalculator)}updateMarker(){var e;let t=(e=this._element)==null?void 0:e.querySelector(`[data-list-marker]`);if(!t)return;let n=this.getDepth();t.textContent=Ve(ze(this.blockId,n,this._data.style,this.api.blocks,this.markerCalculator),n,this._data,this.blockId,this.api.blocks,this.markerCalculator)}updateSiblingListMarkers(){var e;let t=this.blockId?(e=this.api.blocks.getBlockIndex(this.blockId))==null?this.api.blocks.getCurrentBlockIndex():e:this.api.blocks.getCurrentBlockIndex(),n=this.getDepth(),r=this._data.style,i=this.api.blocks.getBlocksCount();We(He(t,n,r,this.markerCalculator),i,t,n,r,this.api.blocks,this.depthValidator,this.markerCalculator)}updateMarkerForDepth(e,t){var n,r;let i=(n=this._element)==null?void 0:n.querySelector(`[aria-hidden="true"]`);if(!(i instanceof HTMLElement))return;let a=this.blockId?(r=this.api.blocks.getBlockIndex(this.blockId))==null?this.api.blocks.getCurrentBlockIndex():r:this.api.blocks.getCurrentBlockIndex(),o=this.markerCalculator.getVisualDepth(a,e);t===`ordered`?i.textContent=Ve(ze(this.blockId,e,this._data.style,this.api.blocks,this.markerCalculator),e,this._data,this.blockId,this.api.blocks,this.markerCalculator):i.textContent=Re(o,this.markerCalculator)}updateCheckboxState(e){var t;let n=(t=this._element)==null?void 0:t.querySelector(`input[type="checkbox"]`);n instanceof HTMLInputElement&&(n.checked=e)}getDepth(){var e;return(e=this._data.depth)==null?0:e}handleKeyDown(e){if(e.key===`Enter`&&!e.shiftKey){e.preventDefault(),this.handleEnter();return}if(e.key===`Backspace`){this.handleBackspace(e);return}if(e.key===`Tab`&&!(document.querySelectorAll(`[data-blok-selected="true"]`).length>1)){if(e.preventDefault(),e.shiftKey){this.handleOutdent();return}this.handleIndent()}}async handleEnter(){var e=this;await qe({api:e.api,blockId:e.blockId,data:e._data,element:e._element,getContentElement:e.getContentElement.bind(e),syncContentFromDOM:e.syncContentFromDOM.bind(e),getDepth:e.getDepth.bind(e)},e.depthValidator)}async handleBackspace(e){var t=this;await Ye({api:t.api,blockId:t.blockId,data:t._data,element:t._element,getContentElement:t.getContentElement.bind(t),syncContentFromDOM:t.syncContentFromDOM.bind(t),getDepth:t.getDepth.bind(t)},e)}async handleIndent(){var e=this;await Xe({api:e.api,blockId:e.blockId,data:e._data,element:e._element,getContentElement:e.getContentElement.bind(e),syncContentFromDOM:e.syncContentFromDOM.bind(e),getDepth:e.getDepth.bind(e)},e.depthValidator)}async handleOutdent(){var e=this;await Qe({api:e.api,blockId:e.blockId,data:e._data,element:e._element,getContentElement:e.getContentElement.bind(e),syncContentFromDOM:e.syncContentFromDOM.bind(e),getDepth:e.getDepth.bind(e)},e.depthValidator)}syncContentFromDOM(){var e;let t=this.getContentElement();if(t&&(this._data.text=t.innerHTML),this._data.style!==`checklist`)return;let n=(e=this._element)==null?void 0:e.querySelector(`input[type="checkbox"]`);n instanceof HTMLInputElement&&(this._data.checked=n.checked)}getContentElement(){return Pe(this._element,this._data.style)}renderSettings(){return _e(this.availableStyles,this._data.style,this.api.i18n.t,e=>this.setStyle(e))}setStyle(e){let t=this._data.style;if(this._data.style=e,this.rerender(),t!==e){var n;(n=this.markerManager)==null||n.scheduleUpdateAll()}}rerender(){var e,t,n;let r=this.blockId?(e=this.api.blocks.getBlockIndex(this.blockId))==null?this.api.blocks.getCurrentBlockIndex():e:this.api.blocks.getCurrentBlockIndex(),i=(t=this._data.depth)==null?0:t,a=pe({data:this._data,readOnly:this.readOnly,placeholder:this.placeholder,itemColor:this.itemColor,itemSize:this.itemSize,markerDepth:this.markerCalculator.getVisualDepth(r,i),element:this._element,setupItemPlaceholder:this.setupItemPlaceholder.bind(this),onCheckboxChange:(e,t)=>{this._data.checked=e,t instanceof HTMLElement&&(t.classList.toggle(`line-through`,e),t.classList.toggle(`opacity-60`,e))},keydownHandler:this.readOnly||(n=this.boundHandleKeyDown)==null?void 0:n});a&&(this._element=a,this.updateMarkersAfterPositionChange())}validate(e){return typeof e.text==`string`}save(){return me(this._data,this._element,this.getContentElement.bind(this))}setData(e){let t=he(this._data,e,this._element,this.getContentElement.bind(this),{adjustDepthTo:this.adjustDepthTo.bind(this),updateMarkerForDepth:this.updateMarkerForDepth.bind(this),updateCheckboxState:this.updateCheckboxState.bind(this)});return this._data=t.newData,t.inPlace}merge(e){ge({data:this._data,element:this._element,getContentElement:this.getContentElement.bind(this),parseHTML:Ce},e)}static get conversionConfig(){return mt()}static get sanitize(){return ft()}static get pasteConfig(){return pt()}onPaste(e){let t=e.detail;if(!(`data`in t))return;let n=t.data;if(!at(n))return;let{text:r,checked:i}=ut(n),a=dt(n);this._data={text:r,style:lt(n,this._data.style),checked:i,depth:a},this.rerender()}static get isReadOnlySupported(){return!0}getContentOffset(e){return be(e)}static get toolbox(){return gt()}},vt=`data-blok-table-add-row`,yt=`data-blok-table-add-col`,bt=150,xt=5,St=40,Ct=[`flex`,`items-center`,`justify-center`,`transition-opacity`,`duration-150`],wt=[`flex`,`items-center`,`justify-center`,`border`,`border-gray-300`,`rounded-sm`,`group-hover/add:bg-gray-50`],Tt=`12`,Et=class{constructor(e){this.rowHideTimeout=null,this.colHideTimeout=null,this.rowVisible=!1,this.colVisible=!1,this.interactive=!0,this.dragState=null,this.scrollContainer=null,this.boundScrollHandler=null,this.scrollContainerResizeObserver=null,this.wrapper=e.wrapper,this.grid=e.grid,this.i18n=e.i18n,this.boundAddRowClick=e.onAddRow,this.boundAddColClick=e.onAddColumn,this.onDragStart=e.onDragStart,this.onDragAddRow=e.onDragAddRow,this.onDragRemoveRow=e.onDragRemoveRow,this.onDragAddCol=e.onDragAddCol,this.onDragRemoveCol=e.onDragRemoveCol,this.onDragEnd=e.onDragEnd,this.getTableSize=e.getTableSize,this.getNewColumnWidth=e.getNewColumnWidth,this.boundMouseMove=this.handleMouseMove.bind(this),this.boundDocumentMouseMove=this.handleDocumentMouseMove.bind(this),this.boundMouseLeave=this.handleMouseLeave.bind(this),this.boundPointerMove=this.handlePointerMove.bind(this),this.boundPointerUp=this.handlePointerUp.bind(this),this.boundPointerCancel=this.handlePointerCancel.bind(this),this.boundRowPointerDown=e=>this.handlePointerDown(`row`,e),this.boundColPointerDown=e=>this.handlePointerDown(`col`,e),this.addRowBtn=this.createAddRowButton(),this.addColBtn=this.createAddColumnButton(),this.wrapper.appendChild(this.addRowBtn),this.wrapper.appendChild(this.addColBtn),this.syncRowButtonWidth(),this.wrapper.addEventListener(`mousemove`,this.boundMouseMove),this.wrapper.addEventListener(`mouseleave`,this.boundMouseLeave),document.addEventListener(`mousemove`,this.boundDocumentMouseMove),this.addRowBtn.addEventListener(`pointerdown`,this.boundRowPointerDown),this.addColBtn.addEventListener(`pointerdown`,this.boundColPointerDown)}computeVisibleWidth(e,t,n){if(!t||n===null)return e;let r=this.wrapper.getBoundingClientRect();if(r.width>0){let e=this.grid.getBoundingClientRect(),t=n.getBoundingClientRect();return Math.min(e.right,t.right)-r.left}return n.clientWidth>0?Math.min(e,n.clientWidth):e}syncRowButtonWidth(){let e=this.grid.style.width;if(e&&e.endsWith(`px`)){let t=parseFloat(e),n=this.grid.parentElement,r=n!==null&&n!==this.wrapper,i=this.computeVisibleWidth(t,r,n);this.addRowBtn.style.width=`${i}px`,this.addRowBtn.style.right=``,this.addRowBtn.style.left=`0px`,this.addRowBtn.style.transform=``,this.addColBtn.style.left=`${i+4}px`,this.addColBtn.style.right=``}else{this.addRowBtn.style.width=``,this.addRowBtn.style.left=`0px`,this.addRowBtn.style.transform=``;let e=parseFloat(getComputedStyle(this.wrapper).paddingRight)||0;this.addRowBtn.style.right=`${e}px`,this.addColBtn.style.left=``,this.addColBtn.style.right=`${e-36}px`}let t=this.grid.getBoundingClientRect(),n=this.wrapper.getBoundingClientRect(),r=t.height;if(r>0){this.addColBtn.style.height=`${r}px`,this.addColBtn.style.bottom=``;let e=t.bottom-n.top;this.addRowBtn.style.top=`${e+4}px`,this.addRowBtn.style.bottom=``}else this.addColBtn.style.height=``,this.addColBtn.style.bottom=`0px`,this.addRowBtn.style.top=``,this.addRowBtn.style.bottom=`-36px`}setDisplay(e){let t=e?``:`none`;this.addRowBtn.style.display=t,this.addColBtn.style.display=t}setInteractive(e){if(this.interactive=e,!e){this.addRowBtn.style.pointerEvents=`none`,this.addColBtn.style.pointerEvents=`none`;return}this.addRowBtn.style.pointerEvents=this.rowVisible?``:`none`,this.addColBtn.style.pointerEvents=this.colVisible?``:`none`}attachScrollContainer(e){var t;this.scrollContainer&&this.boundScrollHandler&&this.scrollContainer.removeEventListener(`scroll`,this.boundScrollHandler),(t=this.scrollContainerResizeObserver)==null||t.disconnect(),this.scrollContainer=e,this.boundScrollHandler=()=>{this.syncRowButtonWidth()},e.addEventListener(`scroll`,this.boundScrollHandler,{passive:!0}),this.scrollContainerResizeObserver=new ResizeObserver(()=>{this.syncRowButtonWidth()}),this.scrollContainerResizeObserver.observe(e)}destroy(){var e;if(this.scrollContainer&&this.boundScrollHandler&&(this.scrollContainer.removeEventListener(`scroll`,this.boundScrollHandler),this.scrollContainer=null,this.boundScrollHandler=null),(e=this.scrollContainerResizeObserver)==null||e.disconnect(),this.scrollContainerResizeObserver=null,this.wrapper.removeEventListener(`mousemove`,this.boundMouseMove),this.wrapper.removeEventListener(`mouseleave`,this.boundMouseLeave),document.removeEventListener(`mousemove`,this.boundDocumentMouseMove),this.addRowBtn.removeEventListener(`pointerdown`,this.boundRowPointerDown),this.addColBtn.removeEventListener(`pointerdown`,this.boundColPointerDown),this.dragState){let e=this.dragState.axis===`row`?this.addRowBtn:this.addColBtn;e.removeEventListener(`pointermove`,this.boundPointerMove),e.removeEventListener(`pointerup`,this.boundPointerUp),e.removeEventListener(`pointercancel`,this.boundPointerCancel),document.body.style.cursor=``,this.dragState=null}this.clearRowTimeout(),this.clearColTimeout(),this.addRowBtn.remove(),this.addColBtn.remove()}showDimensionTooltip(){if(!this.dragState)return;let e=this.getTableSize(),n=this.dragState.axis===`row`?this.addRowBtn:this.addColBtn,r=this.dragState.axis===`row`?{placement:`bottom`,marginTop:-16}:{placement:`bottom`};t.sr(n,`${e.cols}\u00D7${e.rows}`,r)}handlePointerDown(e,t){t.preventDefault();let n=e===`row`?this.addRowBtn:this.addColBtn;n.setPointerCapture(t.pointerId);let r=this.measureUnitSize(e);this.dragState={axis:e,startPos:e===`row`?t.clientY:t.clientX,unitSize:r,addedCount:0,pointerId:t.pointerId,didDrag:!1},n.addEventListener(`pointermove`,this.boundPointerMove),n.addEventListener(`pointerup`,this.boundPointerUp),n.addEventListener(`pointercancel`,this.boundPointerCancel)}handlePointerMove(e){if(!this.dragState)return;let{axis:t,startPos:n,unitSize:r}=this.dragState,i=(t===`row`?e.clientY:e.clientX)-n,a=Math.floor(i/r);for(;this.dragState.addedCount<a;)t===`row`?this.onDragAddRow():this.onDragAddCol(),this.dragState.addedCount++;for(;this.dragState.addedCount>a;)t===`row`?this.onDragRemoveRow():this.onDragRemoveCol(),this.dragState.addedCount--;if(Math.abs(i)>xt&&!this.dragState.didDrag){this.dragState.didDrag=!0,document.body.style.cursor=t===`row`?`row-resize`:`col-resize`,this.showDimensionTooltip(),this.onDragStart();return}this.dragState.didDrag&&this.showDimensionTooltip(),this.dragState.didDrag&&this.showDimensionTooltip()}handlePointerUp(e){if(!this.dragState)return;let{axis:n,pointerId:r,didDrag:i}=this.dragState,a=n===`row`?this.addRowBtn:this.addColBtn;if(a.releasePointerCapture(r),a.removeEventListener(`pointermove`,this.boundPointerMove),a.removeEventListener(`pointerup`,this.boundPointerUp),a.removeEventListener(`pointercancel`,this.boundPointerCancel),document.body.style.cursor=``,t.ar(),this.dragState=null,!i){(n===`row`?this.boundAddRowClick:this.boundAddColClick)();return}this.onDragEnd()}handlePointerCancel(e){if(!this.dragState)return;let{axis:n,didDrag:r}=this.dragState,i=n===`row`?this.addRowBtn:this.addColBtn;i.removeEventListener(`pointermove`,this.boundPointerMove),i.removeEventListener(`pointerup`,this.boundPointerUp),i.removeEventListener(`pointercancel`,this.boundPointerCancel),document.body.style.cursor=``,t.ar(),this.dragState=null,r&&this.onDragEnd()}measureUnitSize(e){if(e===`row`){let e=this.grid.querySelectorAll(`[data-blok-table-row]`),t=e[e.length-1];return(t==null?void 0:t.offsetHeight)||30}if(this.getNewColumnWidth)return this.getNewColumnWidth()||100;let t=this.grid.querySelector(`[data-blok-table-row]`);if(!t)return 100;let n=t.querySelectorAll(`[data-blok-table-cell]`),r=n[n.length-1];return(r==null?void 0:r.offsetWidth)||100}handleMouseMove(e){let t=this.grid.getBoundingClientRect(),n=this.grid.parentElement,r=n!==null&&n!==this.wrapper?Math.min(t.right,n.getBoundingClientRect().right):t.right,i=Math.abs(e.clientY-t.bottom),a=Math.abs(e.clientX-r);i<=St?this.showRow():this.scheduleHideRow(),a<=St?this.showCol():this.scheduleHideCol()}handleMouseLeave(){this.scheduleHideRow(),this.scheduleHideCol()}handleDocumentMouseMove(e){if(this.wrapper.contains(e.target))return;let t=this.grid.getBoundingClientRect(),n=St;e.clientX>=t.left-n&&e.clientX<=t.right+n&&e.clientY>=t.top-n&&e.clientY<=t.bottom+n?this.handleMouseMove(e):(this.scheduleHideRow(),this.scheduleHideCol())}showRow(){this.clearRowTimeout(),this.rowVisible||(this.addRowBtn.style.opacity=`1`,this.addRowBtn.style.pointerEvents=this.interactive?``:`none`,this.rowVisible=!0)}showCol(){this.clearColTimeout(),this.colVisible||(this.addColBtn.style.opacity=`1`,this.addColBtn.style.pointerEvents=this.interactive?``:`none`,this.colVisible=!0)}scheduleHideRow(){var e;!this.rowVisible||this.rowHideTimeout!==null||((e=this.dragState)==null?void 0:e.axis)===`row`||(this.rowHideTimeout=setTimeout(()=>{this.addRowBtn.style.opacity=`0`,this.addRowBtn.style.pointerEvents=`none`,this.rowVisible=!1,this.rowHideTimeout=null},bt))}scheduleHideCol(){var e;!this.colVisible||this.colHideTimeout!==null||((e=this.dragState)==null?void 0:e.axis)===`col`||(this.colHideTimeout=setTimeout(()=>{this.addColBtn.style.opacity=`0`,this.addColBtn.style.pointerEvents=`none`,this.colVisible=!1,this.colHideTimeout=null},bt))}clearRowTimeout(){this.rowHideTimeout!==null&&(clearTimeout(this.rowHideTimeout),this.rowHideTimeout=null)}clearColTimeout(){this.colHideTimeout!==null&&(clearTimeout(this.colHideTimeout),this.colHideTimeout=null)}createAddRowButton(){let e=document.createElement(`div`);e.className=r.n(Ct,`group/add`,`items-start`,`cursor-row-resize`),e.setAttribute(vt,``),e.setAttribute(`contenteditable`,`false`),e.style.opacity=`0`,e.style.pointerEvents=`none`,e.style.position=`absolute`,e.style.left=`0`,e.style.bottom=`-36px`,e.style.zIndex=`1`,e.style.height=`32px`;let n=document.createElement(`div`);return n.className=r.n(wt),n.style.width=`100%`,n.style.height=`16px`,this.appendIcon(n),e.appendChild(n),t.or(e,t.h([this.i18n.t(`tools.table.clickToAddRow`),this.i18n.t(`tools.table.dragToAddRemoveRows`)]),{placement:`bottom`,marginTop:-16}),e}createAddColumnButton(){let e=document.createElement(`div`);e.className=r.n(Ct,`group/add`,`justify-start`,`cursor-col-resize`),e.setAttribute(yt,``),e.setAttribute(`contenteditable`,`false`),e.style.opacity=`0`,e.style.pointerEvents=`none`,e.style.position=`absolute`,e.style.right=`-36px`,e.style.top=`0px`,e.style.bottom=`0px`,e.style.width=`32px`;let n=document.createElement(`div`);return n.className=r.n(wt),n.style.width=`16px`,n.style.height=`100%`,this.appendIcon(n),e.appendChild(n),t.or(e,t.h([this.i18n.t(`tools.table.clickToAddColumn`),this.i18n.t(`tools.table.dragToAddRemoveColumns`)]),{placement:`bottom`}),e}appendIcon(e){e.insertAdjacentHTML(`beforeend`,t.sn);let n=e.querySelector(`svg`);n&&(n.setAttribute(`width`,Tt),n.setAttribute(`height`,Tt),n.setAttribute(`viewBox`,`0 0 24 24`),n.classList.add(`text-gray-500`,`pointer-events-none`))}},I=`data-blok-table-row`,L=`data-blok-table-cell`,R=`data-blok-table-cell-row`,z=`data-blok-table-cell-col`,Dt=`1px solid var(--blok-table-border)`,Ot=[`py-1`,`px-2`,`min-h-[2em]`,`outline-hidden`,`leading-none`,`text-sm`,`cursor-text`],kt=e=>{let t=Math.round(100/e*100)/100;return Array.from({length:e},()=>t)},At=class{constructor(e){this.readOnly=e.readOnly}createGrid(e,t,n){let r=document.createElement(`table`);r.style.tableLayout=`fixed`,r.style.width=`100%`,r.style.borderCollapse=`separate`,r.style.borderSpacing=`0px`,r.style.borderTop=Dt,r.style.borderLeft=Dt;let i=n==null?kt(t):n,a=document.createElement(`colgroup`);i.forEach(e=>{a.appendChild(this.createCol(e))}),r.appendChild(a);let o=document.createElement(`tbody`);return Array.from({length:e}).forEach((e,n)=>{o.appendChild(this.createRow(t,n))}),r.appendChild(o),r}fillGrid(e,t){}createGridFromModel(e){var t;let n=document.createElement(`table`);n.style.tableLayout=`fixed`,n.style.width=`100%`,n.style.borderCollapse=`separate`,n.style.borderSpacing=`0px`,n.style.borderTop=Dt,n.style.borderLeft=Dt;let r=document.createElement(`colgroup`);((t=e.colWidths)==null?kt(e.cols):t).forEach(e=>r.appendChild(this.createCol(e))),n.appendChild(r);let i=document.createElement(`tbody`);return Array.from({length:e.rows}).forEach((t,n)=>{let r=document.createElement(`tr`);r.setAttribute(I,``),Array.from({length:e.cols}).forEach((t,i)=>{if(e.isSpannedCell(n,i))return;let a=this.createCell(n,i),o=e.getCellSpan(n,i);o.colspan>1&&(a.colSpan=o.colspan),o.rowspan>1&&(a.rowSpan=o.rowspan),r.appendChild(a)}),i.appendChild(r)}),n.appendChild(i),n}addRow(e,t){var n;let r=this.getColumnCount(e),i=this.createRow(r),a=(n=e.querySelector(`tbody`))==null?e:n,o=a.querySelectorAll(`[${I}]`);return t!==void 0&&t<o.length?a.insertBefore(i,o[t]):a.appendChild(i),this.reindexCoordinates(e),i}deleteRow(e,t){let n=e.querySelectorAll(`[${I}]`);t<n.length&&n[t].remove(),this.reindexCoordinates(e)}addColumn(e,t,n,r){let i=e.querySelector(`colgroup`),a=(i?Array.from(i.querySelectorAll(`col`)):[]).length,o=n!==void 0&&n.length===a,s=o||this.detectWidthUnit(e)===`px`;return o&&i&&this.applyWidthsToCols(i,n),s?this.addColumnPx(e,a,t,r):this.addColumnPercent(e,a,t),this.reindexCoordinates(e),!0}applyWidthsToCols(e,t){let n=Array.from(e.querySelectorAll(`col`));t.forEach((e,t)=>{t<n.length&&(n[t].style.width=`${e}px`)})}addColumnPx(e,t,n,r){let i=`${r==null?this.computeHalfAvgWidth(e,t):r}px`;this.insertColumn(e,n,i)}computeHalfAvgWidth(e,t){let n=e.querySelector(`colgroup`),r=(n?Array.from(n.querySelectorAll(`col`)):[]).reduce((e,t)=>e+(parseFloat(t.style.width)||0),0);return t>0?Math.round(r/t/2*100)/100:0}addColumnPercent(e,t,n){let r=1-.5/t,i=e.querySelector(`colgroup`);(i?Array.from(i.querySelectorAll(`col`)):[]).forEach(e=>{let n=e,i=parseFloat(n.style.width)||100/t,a=Math.round(i*r*100)/100;n.style.width=`${a}%`});let a=Math.round(100/t/2*100)/100;this.insertColumn(e,n,`${a}%`)}insertColumn(e,t,n){let r=e.querySelector(`colgroup`);if(r){let e=document.createElement(`col`);e.style.width=n;let i=r.querySelectorAll(`col`);t===void 0||t>=i.length?r.appendChild(e):r.insertBefore(e,i[t])}e.querySelectorAll(`[${I}]`).forEach(e=>{let n=e.querySelectorAll(`[${L}]`),r=t===void 0||t>=n.length,i=this.createCell();r?e.appendChild(i):e.insertBefore(i,n[t])})}deleteColumn(e,t){let n=e.querySelector(`colgroup`);if(n){let e=n.querySelectorAll(`col`);t<e.length&&e[t].remove()}e.querySelectorAll(`[${I}]`).forEach(e=>{let n=e.querySelectorAll(`[${L}]`);t>=n.length||n[t].remove()}),this.reindexCoordinates(e)}moveRow(e,t,n){var r;if(t===n)return;let i=(r=e.querySelector(`tbody`))==null?e:r,a=Array.from(i.querySelectorAll(`[${I}]`));if(t>=a.length||n>=a.length)return;let o=a[t];o.remove();let s=Array.from(i.querySelectorAll(`[${I}]`));n>=s.length?i.appendChild(o):i.insertBefore(o,s[n]),this.reindexCoordinates(e)}moveColumn(e,t,n){t!==n&&(this.reorderColElement(e,t,n),e.querySelectorAll(`[${I}]`).forEach(e=>{let r=Array.from(e.querySelectorAll(`[${L}]`));if(t>=r.length||n>=r.length)return;let i=r[t];i.remove();let a=Array.from(e.querySelectorAll(`[${L}]`));n>=a.length?e.appendChild(i):e.insertBefore(i,a[n])}),this.reindexCoordinates(e))}reindexCoordinates(e){let t=Array.from(e.querySelectorAll(`[${I}]`)),n=new Map;t.forEach((e,t)=>{var r;let i=Array.from(e.querySelectorAll(`[${L}]`)),a=(r=n.get(t))==null?new Set:r;i.reduce((e,r)=>{let i=r,o=e=>a.has(e)?o(e+1):e,s=o(e);r.setAttribute(R,String(t)),r.setAttribute(z,String(s));let c=i.colSpan||1,l=i.rowSpan||1;return l>1&&this.blockRowspanCols(n,t,s,l,c),s+c},0),n.delete(t)})}blockRowspanCols(e,t,n,r,i){Array.from({length:r-1},(e,t)=>t+1).forEach(r=>{let a=t+r;e.has(a)||e.set(a,new Set);let o=e.get(a);Array.from({length:i},(e,t)=>t).forEach(e=>{o.add(n+e)})})}getRowCount(e){return e.querySelectorAll(`[${I}]`).length}getColumnCount(e){let t=e.querySelector(`colgroup`);if(t)return t.querySelectorAll(`col`).length;let n=e.querySelector(`[${I}]`);return n?n.querySelectorAll(`[${L}]`).length:0}getCell(e,t,n){let r=e.querySelector(`[${R}="${t}"][${z}="${n}"]`);if(r)return r;let i=e.querySelectorAll(`[${I}]`);if(t>=i.length)return null;let a=i[t].querySelectorAll(`[${L}]`);return n>=a.length?null:a[n]}getColWidths(e){let t=e.querySelector(`colgroup`);if(!t)return[];let n=t.querySelectorAll(`col`),r=[];return n.forEach(e=>{let t=parseFloat(e.style.width);r.push(isNaN(t)?0:t)}),r}getColgroup(e){return e.querySelector(`colgroup`)}applyColWidths(e,t){let n=e.querySelector(`colgroup`);if(!n)return;let r=Array.from(n.querySelectorAll(`col`));t.forEach((e,t)=>{t<r.length&&(r[t].style.width=`${e}px`)})}reorderColElement(e,t,n){let r=e.querySelector(`colgroup`);if(!r)return;let i=Array.from(r.querySelectorAll(`col`));if(t>=i.length||n>=i.length)return;let a=i[t];a.remove();let o=Array.from(r.querySelectorAll(`col`));n>=o.length?r.appendChild(a):r.insertBefore(a,o[n])}detectWidthUnit(e){let t=e.querySelector(`colgroup`);if(!t)return`%`;let n=t.querySelector(`col`);return n&&n.style.width.endsWith(`px`)?`px`:`%`}createCol(e){let t=document.createElement(`col`);return t.style.width=typeof e==`string`?e:`${e}%`,t}createRow(e,t){let n=document.createElement(`tr`);return n.setAttribute(I,``),Array.from({length:e}).forEach((e,r)=>{n.appendChild(this.createCell(t,t===void 0?void 0:r))}),n}createCell(e,n){let i=document.createElement(`td`);i.className=r.n(Ot),i.style.borderRight=Dt,i.style.borderBottom=Dt,i.style.overflow=`hidden`,i.style.overflowWrap=`break-word`,i.style.height=`0`,i.setAttribute(L,``),e!==void 0&&n!==void 0&&(i.setAttribute(R,String(e)),i.setAttribute(z,String(n)));let a=document.createElement(`div`);return a.setAttribute(V,``),a.setAttribute(t.hi.nestedBlocks,``),a.style.display=`flex`,a.style.flexDirection=`column`,a.style.minHeight=`100%`,i.appendChild(a),i}},B=e=>typeof e==`object`&&!!e&&`blocks`in e,V=`data-blok-table-cell-blocks`,jt=class{constructor(e){var t;this._activeCellWithBlocks=null,this.cellsPendingCheck=new Set,this.pendingCheckScheduled=!1,this.removedBlockCells=new Map,this.deferredEvents=[],this.isExitingTable=!1,this.handleBlockMutation=e=>{if(this.isStructuralOpActive()&&!this.api.blocks.isSyncingFromYjs){this.deferredEvents.push(e);return}if(this.isExitingTable||!this.isBlockMutationEvent(e))return;let{type:t,detail:n}=e.event;if(t===`block-removed`){this.handleBlockRemoved(n);return}if(t===`block-moved`){this.handleBlockMoved(n);return}if(t!==`block-added`||n.target.id===this.tableBlockId)return;let r=this.model.findCellForBlock(n.target.id);if(r){let e=this.gridElement.querySelector(`[${R}="${r.row}"][${z}="${r.col}"]`);if(e){this.claimBlockForCell(e,n.target.id),this.cellsPendingCheck.delete(e);return}}let i=n.index;if(i===void 0)return;let a=this.findRemovedEntryForIndex(i);if(a&&this.isAdjacentToThisTable(i)){this.claimBlockForCell(a.cell,n.target.id),this.syncBlockToModel(a.cell,n.target.id),this.cellsPendingCheck.delete(a.cell);return}let o=n.target.holder,s=o.closest(`[${V}]`);s&&this.stripPlaceholders(s);let c=s&&!this.model.findCellForBlock(n.target.id)?s.closest(`[${L}]`):null;if(c&&this.syncBlockToModel(c,n.target.id),s)return;if(!this.gridElement.contains(o)){let e=this.api.blocks.getBlockIndex(this.tableBlockId),t=e===void 0?null:this.api.blocks.getBlockByIndex(e);if(t&&!t.holder.contains(o))return;let r=this.api.blocks.getCurrentBlockIndex(),a=r>=0?this.api.blocks.getBlockByIndex(r):null;if(!(a!=null&&this.getOwnedCellForBlock(a.id)!==null))return;let s=this.findCellForNewBlock(i);s&&(this.claimBlockForCell(s,n.target.id),this.syncBlockToModel(s,n.target.id),this.cellsPendingCheck.delete(s));return}let l=this.findCellForNewBlock(i);l&&(this.claimBlockForCell(l,n.target.id),this.syncBlockToModel(l,n.target.id),this.cellsPendingCheck.delete(l))},this.handleCellBlankSpaceClick=e=>{let t=e.target;if(!t)return;let n=t.hasAttribute(L),r=t.hasAttribute(V);if(!n&&!r)return;let i=n?t:t.closest(`[${L}]`);if(!i)return;let a=n?i.querySelector(`[${V}]`):t;if(!a)return;let o=a.querySelectorAll(`[data-blok-id]`),s=o[o.length-1];if(!s)return;let c=s.getAttribute(`data-blok-id`);c&&this.api.caret.setToBlock(c,`end`)},this.api=e.api,this.gridElement=e.gridElement,this.tableBlockId=e.tableBlockId,this.model=e.model,this.onNavigateToCell=e.onNavigateToCell,this.isStructuralOpActive=(t=e.isStructuralOpActive)==null?(()=>!1):t,this.api.events.on(`block changed`,this.handleBlockMutation),this.gridElement.addEventListener(`click`,this.handleCellBlankSpaceClick)}get activeCellWithBlocks(){return this._activeCellWithBlocks}setActiveCellWithBlocks(e){this._activeCellWithBlocks=e}clearActiveCellWithBlocks(){this._activeCellWithBlocks=null}handleKeyDown(e,t){if(e.key===`Tab`&&!e.shiftKey){e.preventDefault(),this.handleTabNavigation(t);return}if(e.key===`Tab`&&e.shiftKey){e.preventDefault(),this.handleShiftTabNavigation(t);return}e.key===`ArrowDown`&&!e.defaultPrevented&&t.row===this.getRowCount()-1&&(e.preventDefault(),this.exitTableForward())}handleTabNavigation(e){let t=e.col+1;if(t<this.getColumnCount()){this.navigateToCell({row:e.row,col:t});return}let n=e.row+1;if(n<this.getRowCount()){this.navigateToCell({row:n,col:0});return}this.exitTableForward()}handleShiftTabNavigation(e){let t=e.col-1;if(t>=0){this.navigateToCell({row:e.row,col:t},!0);return}let n=e.row-1;if(n>=0){this.navigateToCell({row:n,col:this.getColumnCount()-1},!0);return}this.exitTableBackward()}exitTableForward(){let e=this.api.blocks.getBlockIndex(this.tableBlockId);if(e===void 0)return;let t=this.findFirstBlockAfterTable(e);if(t!==null){this.api.caret.setToBlock(t.id,`start`);return}this.isExitingTable=!0;try{let t=this.api.blocks.getBlocksCount(),n=this.api.blocks.insert(void 0,{},{},t,!0),r=this.gridElement.contains(n.holder)?this.api.blocks.getBlockByIndex(e):null;r&&r.holder.after(n.holder),this.api.caret.setToBlock(n.id,`start`)}finally{this.isExitingTable=!1}}exitTableBackward(){let e=this.api.blocks.getBlockIndex(this.tableBlockId);if(e===void 0||e===0)return;let t=this.api.blocks.getBlockByIndex(e-1);t&&this.api.caret.setToBlock(t.id,`end`)}findFirstBlockAfterTable(e){var t;let n=this.api.blocks.getBlocksCount();return(t=Array.from({length:n-e-1},(t,n)=>this.api.blocks.getBlockByIndex(e+1+n)).find(e=>e!=null&&!this.gridElement.contains(e.holder)))==null?null:t}navigateToCell(e,t=!1){var n;this.clearActiveCellWithBlocks();let r=this.getCell(e.row,e.col);if(!r)return;let i=r.querySelector(`[${V}]`);if(!i)return;let a=i.querySelectorAll(`[contenteditable="true"]`);a.length!==0&&((t?a[a.length-1]:a[0]).focus(),(n=this.onNavigateToCell)==null||n.call(this,e))}getRowCount(){return this.gridElement.querySelectorAll(`[data-blok-table-row]`).length}getColumnCount(){var e;let t=this.gridElement.querySelector(`colgroup`);if(t)return t.querySelectorAll(`col`).length;let n=this.gridElement.querySelector(`[data-blok-table-row]`);return(e=n==null?void 0:n.querySelectorAll(`[data-blok-table-cell]`).length)==null?0:e}getCell(e,t){var n;let r=this.gridElement.querySelectorAll(`[data-blok-table-row]`)[e];return r?(n=r.querySelector(`[data-blok-table-cell-col="${t}"]`))==null?null:n:null}initializeCells(e){let t=this.gridElement.querySelectorAll(`[${I}]`),r=[];return e.forEach((e,i)=>{let a=t[i];if(!a)return;let o=[];e.forEach((e,t)=>{let r=a.querySelector(`[${z}="${t}"]`);if(!r)return;let i=r.querySelector(`[${V}]`);if(!i)return;let s=B(e)&&e.blocks.length>0?[...e.blocks]:null,{mountedIds:c,replacements:l}=s?this.mountBlocksInCell(i,s):{mountedIds:[],replacements:new Map},u={};if(B(e)&&(e.color!==void 0&&(u.color=e.color),e.textColor!==void 0&&(u.textColor=e.textColor)),c.length>0){let e=s==null?c:s,t=l.size>0?e.map(e=>{var t;return(t=l.get(e))==null?e:t}):e;o.push(n.t({blocks:t},u))}else{var d;let t=typeof e==`string`?e:(d=e.text)==null?``:d,r=t.split(/<br\s*\/?>/i).map(e=>e.trim()).filter(Boolean),a=r.length>0?r:[t],c=[];for(let e of a){let t=this.api.blocks.insert(`paragraph`,{text:e},{},this.api.blocks.getBlocksCount(),!1);i.appendChild(t.holder),this.api.blocks.setBlockParent(t.id,this.tableBlockId),c.push(t.id)}o.push(n.t({blocks:s===null?c:[...s,...c]},u))}this.stripPlaceholders(i)}),r.push(o)}),r}reclaimReferencedBlocks(){this.model.snapshot().content.forEach((e,t)=>{e.forEach((e,n)=>{if(!B(e)||e.blocks.length===0)return;let r=this.gridElement.querySelector(`[${R}="${t}"][${z}="${n}"]`);if(!r)return;let i=r.querySelector(`[${V}]`);if(i)for(let t of e.blocks){let e=this.api.blocks.getBlockIndex,n=this.api.blocks.getBlockByIndex;if(typeof e!=`function`||typeof n!=`function`)return;let a=e(t);if(a===void 0)continue;let o=n(a);o&&(i.contains(o.holder)||this.claimBlockForCell(r,t))}})})}stripPlaceholders(e){e.querySelectorAll(`[data-blok-placeholder-active]`).forEach(e=>{e.removeAttribute(`data-blok-placeholder-active`)}),e.querySelectorAll(`[data-placeholder]`).forEach(e=>{e.removeAttribute(`data-placeholder`)})}mountBlocksInCell(e,n){let r=[],i=new Map;for(let a of n){let n=this.api.blocks.getBlockIndex(a);if(n===void 0)continue;let o=this.api.blocks.getBlockByIndex(n);if(!o)continue;let s=o.parentId!=null&&o.parentId!==``&&o.parentId!==this.tableBlockId;if(o.holder.closest(`[${t.hi.nestedBlocks}]`)||s){let t=this.api.blocks.insert(o.name,o.preservedData,{},this.api.blocks.getBlocksCount(),!1);e.appendChild(t.holder),this.api.blocks.setBlockParent(t.id,this.tableBlockId),r.push(t.id),i.set(a,t.id);continue}e.appendChild(o.holder),this.api.blocks.setBlockParent(a,this.tableBlockId),r.push(a)}return{mountedIds:r,replacements:i}}claimBlockForCell(e,n){var r,i;let a=e.querySelector(`[${V}]`);if(!a)return;let o=this.api.blocks.getBlockIndex(n);if(o===void 0)return;let s=this.api.blocks.getBlockByIndex(o);if(!s||s.holder.contains(a))return;let c=s.parentId!=null&&s.parentId!==``&&s.parentId!==this.tableBlockId;if(s.holder.closest(`[${t.hi.nestedBlocks}]`)||c)return;let l=this.api.blocks.getBlocksCount(),u=(r=(i=Array.from({length:l-o-1},(e,t)=>this.api.blocks.getBlockByIndex(o+1+t)).find(e=>(e==null?void 0:e.holder.parentElement)===a))==null?void 0:i.holder)==null?null:r;a.insertBefore(s.holder,u),this.api.blocks.setBlockParent(n,this.tableBlockId),this.stripPlaceholders(a)}findCellForNewBlock(e){return this.findCellForAdjacentBlock(e-1)||this.findCellForAdjacentBlock(e+1)}findCellForAdjacentBlock(e){if(e<0||e>=this.api.blocks.getBlocksCount())return null;let t=this.api.blocks.getBlockByIndex(e),n=t==null?void 0:t.holder.closest(`[${L}]`);return n&&this.gridElement.contains(n)?n:null}ensureCellHasBlock(e){var t,n;let r=e.querySelector(`[${V}]`);r&&r.querySelector(`[data-blok-id]`)===null&&((t=(n=this.api.blocks).transactWithoutCapture)==null||t.call(n,()=>{let t=this.api.blocks.insert(`paragraph`,{text:``},{},this.api.blocks.getBlocksCount(),!0);r.appendChild(t.holder),this.api.blocks.setBlockParent(t.id,this.tableBlockId),this.syncBlockToModel(e,t.id),this.stripPlaceholders(r)}))}handleBlockRemoved(e){this.recordRemovedBlockCell(e);let t=e.target.id,n=this.model.findCellForBlock(t);if(!n){this.schedulePendingCellCheck();return}this.model.removeBlockFromCell(n.row,n.col,t);let r=this.getCell(n.row,n.col);r&&this.cellsPendingCheck.add(r),this.schedulePendingCellCheck()}handleBlockMoved(e){let t=e.target.id,n=this.model.findCellForBlock(t);n&&(this.gridElement.contains(e.target.holder)||this.model.removeBlockFromCell(n.row,n.col,t))}syncBlockToModel(e,t){let n=this.getCellPosition(e);n&&this.model.addBlockToCell(n.row,n.col,t)}getCellPosition(e){let t=e.closest(`[${I}]`);if(!t)return null;let n=Array.from(this.gridElement.querySelectorAll(`[${I}]`)).indexOf(t);if(n<0)return null;let r=Array.from(t.querySelectorAll(`[${L}]`)).indexOf(e);return r<0?null:{row:n,col:r}}recordRemovedBlockCell(e){if(e.index===void 0)return;let t=e.target.holder.closest(`[${L}]`);t&&this.gridElement.contains(t)&&this.removedBlockCells.set(e.target.id,{cell:t,index:e.index})}findRemovedEntryForIndex(e){for(let[t,n]of this.removedBlockCells)if(n.index===e)return this.removedBlockCells.delete(t),n;return null}getOwnedCellForBlock(e){let t=this.model.findCellForBlock(e);if(!t)return null;let n=this.getCell(t.row,t.col);return n&&this.gridElement.contains(n)?n:null}isAdjacentToThisTable(e){let t=this.api.blocks.getBlocksCount();for(let n of[-1,1]){let r=e+n;if(r<0||r>=t)continue;let i=this.api.blocks.getBlockByIndex(r);if(i&&this.getOwnedCellForBlock(i.id))return!0}if(!this.isTableBlockAtPrevIndex(e))return!1;let n=e+1;if(n>=t)return!0;let r=this.api.blocks.getBlockByIndex(n);return r?this.getOwnedCellForBlock(r.id)!==null:!0}isTableBlockAtPrevIndex(e){let t=e-1;if(t<0)return!1;let n=this.api.blocks.getBlockByIndex(t);return(n==null?void 0:n.id)===this.tableBlockId}schedulePendingCellCheck(){this.pendingCheckScheduled||(this.pendingCheckScheduled=!0,queueMicrotask(()=>{if(this.pendingCheckScheduled=!1,!this.api.blocks.isSyncingFromYjs)for(let e of this.cellsPendingCheck)this.ensureCellHasBlock(e);this.cellsPendingCheck.clear(),this.removedBlockCells.clear()}))}isBlockMutationEvent(e){return typeof e==`object`&&!!e&&`event`in e&&typeof e.event==`object`&&e.event!==null}getBlockIdsFromCells(e){let t=[];return Array.from(e).forEach(e=>{let n=e.querySelector(`[${V}]`);n&&n.querySelectorAll(`[data-blok-id]`).forEach(e=>{let n=e.getAttribute(`data-blok-id`);n&&t.push(n)})}),t}deleteBlocks(e){let t=e.map(e=>this.api.blocks.getBlockIndex(e)).filter(e=>e!==void 0).sort((e,t)=>t-e),n=window.scrollY,r=t.map(e=>this.api.blocks.delete(e));Promise.all(r).then(()=>{window.scrollY!==n&&window.scrollTo(0,n)})}deleteAllBlocks(){let e=this.gridElement.querySelectorAll(`[${L}]`),t=this.getBlockIdsFromCells(e);this.deleteBlocks(t)}destroy(){this.gridElement.removeEventListener(`click`,this.handleCellBlankSpaceClick),this.api.events.off(`block changed`,this.handleBlockMutation),this._activeCellWithBlocks=null,this.cellsPendingCheck.clear(),this.removedBlockCells.clear(),this.deferredEvents.length=0}flushDeferredEvents(){let e=[...this.deferredEvents];this.deferredEvents.length=0;for(let t of e)this.handleBlockMutation(t)}discardDeferredEvents(){this.deferredEvents.length=0}};function Mt(){var e,n;let r=document.documentElement.getAttribute(`data-blok-theme`);return r===`dark`?t.Un:r===`light`?t.Hn:typeof window<`u`&&(e=(n=window).matchMedia)!=null&&e.call(n,`(prefers-color-scheme: dark)`).matches?t.Un:t.Hn}function Nt(e,n){if(e===n)return!0;let r=t.zn(e),i=t.zn(n);return r===null||i===null?!1:r[0]===i[0]&&r[1]===i[1]&&r[2]===i[2]}var Pt=`var(--blok-swatch-neutral-bg)`;function Ft(e){let{i18n:n,modes:i,testIdPrefix:a,onColorSelect:o}=e,s={activeColors:Object.fromEntries(i.map(e=>[e.key,null]))},c=document.createElement(`div`);c.setAttribute(`data-blok-testid`,`${a}-picker`),c.className=`flex flex-col gap-3 p-2`;let l=[];i.forEach(e=>{let t=document.createElement(`div`);t.setAttribute(`data-blok-testid`,`${a}-section-${e.key}`),t.className=`flex flex-col gap-1`;let r=document.createElement(`div`);r.className=`text-xs font-medium text-text-primary/60 px-0.5`,r.textContent=n.t(e.labelKey);let i=document.createElement(`div`);i.className=`grid gap-1`,i.style.gridTemplateColumns=`repeat(5, 2.25rem)`,l.push(i),t.appendChild(r),t.appendChild(i),c.appendChild(t)});let u=e=>{let c=l[e],u=i[e],d=Mt();c.innerHTML=``;let f=s.activeColors[u.key],p=document.createElement(`button`),m=f===null;p.setAttribute(`data-blok-testid`,`${a}-swatch-${u.key}-default`),p.className=r.n(`w-9 h-9 rounded-md cursor-pointer border-none outline-hidden`,`flex items-center justify-center text-sm font-semibold`,`transition-[box-shadow,transform] ring-inset hover:ring-2 hover:ring-swatch-ring-hover active:scale-90`,m&&`ring-2 ring-swatch-ring-hover`),p.textContent=u.presetField===`text`?`A`:``,u.presetField===`text`&&(p.style.color=`var(--blok-text-primary)`),p.style.backgroundColor=Pt,p.addEventListener(`click`,()=>{o(null,u.key)});let h=n.t(`tools.colorPicker.defaultSwatchLabel`).replace(`{default}`,n.t(`tools.marker.default`)).replace(`{mode}`,n.t(u.labelKey).toLowerCase());t.or(p,h.charAt(0).toUpperCase()+h.slice(1),{placement:`top`}),c.appendChild(p);for(let e of d){let i=document.createElement(`button`),s=u.presetField===`text`?e.text:e.bg,l=f!==null&&Nt(s,f);i.setAttribute(`data-blok-testid`,`${a}-swatch-${u.key}-${e.name}`),i.className=r.n(`w-9 h-9 rounded-md cursor-pointer border-none outline-hidden`,`flex items-center justify-center text-sm font-semibold`,`transition-[box-shadow,transform] ring-inset hover:ring-2 hover:ring-swatch-ring-hover active:scale-90`,l&&`ring-2 ring-swatch-ring-hover`),i.textContent=u.presetField===`text`?`A`:``,u.presetField===`text`?(i.style.color=e.text,i.style.backgroundColor=Pt):(i.style.color=d===t.Un?e.text:`#37352f`,i.style.backgroundColor=e.bg),i.addEventListener(`click`,()=>{o(s,u.key)});let p=n.t(`tools.colorPicker.colorSwatchLabel`).replace(`{color}`,n.t(`tools.colorPicker.color.`+e.name)).replace(`{mode}`,n.t(u.labelKey).toLowerCase());t.or(i,p.charAt(0).toUpperCase()+p.slice(1),{placement:`top`}),c.appendChild(i)}},d=()=>{i.forEach((e,t)=>u(t))};return d(),{element:c,setActiveColor:(e,t)=>{let n=i.findIndex(e=>e.key===t);n!==-1&&(s.activeColors[t]=e,u(n))},reset:()=>{for(let e of i)s.activeColors[e.key]=null;d()}}}var It=e=>{let t=Ft({i18n:e.i18n,testIdPrefix:`cell-color`,modes:[{key:`textColor`,labelKey:`tools.marker.textColor`,presetField:`text`},{key:`backgroundColor`,labelKey:`tools.marker.background`,presetField:`bg`}],onColorSelect:(n,r)=>{t.setActiveColor(n,r),e.onColorSelect(n,r)}});return{element:t.element}},Lt=[`top-left`,`top-center`,`top-right`,`middle-left`,`middle-center`,`middle-right`,`bottom-left`,`bottom-center`,`bottom-right`],Rt={"top-left":`tools.table.placementTopLeft`,"top-center":`tools.table.placementTopCenter`,"top-right":`tools.table.placementTopRight`,"middle-left":`tools.table.placementMiddleLeft`,"middle-center":`tools.table.placementMiddleCenter`,"middle-right":`tools.table.placementMiddleRight`,"bottom-left":`tools.table.placementBottomLeft`,"bottom-center":`tools.table.placementBottomCenter`,"bottom-right":`tools.table.placementBottomRight`},zt={top:`flex-start`,middle:`center`,bottom:`flex-end`},Bt={left:`flex-start`,center:`center`,right:`flex-end`},Vt=e=>{var t;let n=(t=e.currentPlacement)==null?`top-left`:t,r=document.createElement(`div`);r.style.padding=`8px`;let i=document.createElement(`div`);i.style.display=`grid`,i.style.gridTemplateColumns=`repeat(3, 1fr)`,i.style.gap=`3px`;let a=document.createElement(`div`);a.style.textAlign=`center`,a.style.fontSize=`11px`,a.style.marginTop=`6px`,a.style.color=`var(--blok-text-secondary, #707684)`,a.textContent=e.i18n.t(Rt[n]);for(let t of Lt){let[r,o]=t.split(`-`),s=document.createElement(`div`);s.setAttribute(`data-placement`,t),s.style.width=`32px`,s.style.height=`26px`,s.style.borderRadius=`3px`,s.style.display=`flex`,s.style.flexDirection=`column`,s.style.alignItems=Bt[o],s.style.justifyContent=zt[r],s.style.padding=`3px`,s.style.cursor=`pointer`,s.style.gap=`1px`,t===n?(s.setAttribute(`data-active`,`true`),s.style.outline=`2px solid var(--blok-color-primary, #388AE5)`,s.style.outlineOffset=`-2px`,s.style.backgroundColor=`var(--blok-item-focus-bg, rgba(35, 131, 226, 0.14))`):s.style.backgroundColor=`var(--blok-bg-light, #eff2f5)`;let c=document.createElement(`div`);c.style.width=`14px`,c.style.height=`2px`,c.style.borderRadius=`1px`,c.style.backgroundColor=`currentColor`,c.style.opacity=`0.6`;let l=document.createElement(`div`);l.style.width=`9px`,l.style.height=`2px`,l.style.borderRadius=`1px`,l.style.backgroundColor=`currentColor`,l.style.opacity=`0.3`,s.appendChild(c),s.appendChild(l),s.addEventListener(`click`,()=>{i.querySelectorAll(`[data-placement]`).forEach(e=>{let t=e;t.removeAttribute(`data-active`),t.style.outline=``,t.style.outlineOffset=``,t.style.backgroundColor=`var(--blok-bg-tertiary, #f0f0f0)`}),s.setAttribute(`data-active`,`true`),s.style.outline=`2px solid var(--blok-color-primary, #388AE5)`,s.style.outlineOffset=`-2px`,s.style.backgroundColor=`var(--blok-item-focus-bg, rgba(35, 131, 226, 0.14))`,a.textContent=e.i18n.t(Rt[t]),e.onPlacementSelect(t)}),i.appendChild(s)}return r.appendChild(i),r.appendChild(a),{element:r}},Ht=(e,t,n)=>{t===`col`?Object.assign(e.style,{height:`${n}px`}):Object.assign(e.style,{width:`${n}px`})},Ut=[[2,2],[8,2],[2,7],[8,7],[2,12],[8,12]],Wt=[[2,2],[7,2],[12,2],[2,8],[7,8],[12,8]],Gt=e=>{let t=document.createElementNS(`http://www.w3.org/2000/svg`,`svg`),n=e===`horizontal`;t.setAttribute(`width`,n?`14`:`10`),t.setAttribute(`height`,n?`10`:`14`),t.setAttribute(`viewBox`,n?`0 0 14 10`:`0 0 10 14`),t.setAttribute(`fill`,`currentColor`),t.classList.add(`opacity-0`,`transition-opacity`,`duration-150`,`text-gray-400`,`pointer-events-none`);let r=n?Wt:Ut;for(let[e,n]of r){let r=document.createElementNS(`http://www.w3.org/2000/svg`,`circle`);r.setAttribute(`cx`,String(e)),r.setAttribute(`cy`,String(n)),r.setAttribute(`r`,`1.5`),t.appendChild(r)}return t},Kt=(e,t)=>{t===`col`?Object.assign(e.style,{height:`16px`}):Object.assign(e.style,{width:`16px`}),e.classList.add(`bg-gray-200`),e.classList.remove(`bg-gray-300`);let n=e.querySelector(`svg`);n&&(n.classList.remove(`opacity-0`),n.classList.add(`opacity-100`))},qt=(e,t,n)=>{Ht(e,t,n),e.classList.remove(`bg-gray-200`),e.classList.add(`bg-gray-300`);let r=e.querySelector(`svg`);r&&(r.classList.add(`opacity-0`),r.classList.remove(`opacity-100`))},Jt=`data-blok-table-cell-selected`,Yt=`2px solid #3b82f6`,Xt=`data-blok-table-selection-pill`,Zt=16,Qt=20,$t=4,en=[`absolute`,`z-3`,`rounded-sm`,`select-none`,`transition-[opacity,background-color,width]`,`duration-150`,`flex`,`items-center`,`justify-center`,`overflow-hidden`,`cursor-pointer`,`bg-blue-500`],tn=e=>e.style.userSelect===`none`,nn=class{constructor(e){this.anchorCell=null,this.extentCell=null,this.isSelecting=!1,this.hasSelection=!1,this.selectedCells=[],this.overlay=null,this.pill=null,this.pillPopover=null,this.resizeObserver=null,this.lastPaintedRange=null,this.preExpansionWasSingleCell=!1,this.grid=e.grid,this.rectangleSelection=e.rectangleSelection,this.onSelectionActiveChange=e.onSelectionActiveChange,this.onClearContent=e.onClearContent,this.onCopy=e.onCopy,this.onCut=e.onCut,this.onCopyViaButton=e.onCopyViaButton,this.onColorChange=e.onColorChange,this.onPlacementChange=e.onPlacementChange,this.getCellPlacement=e.getCellPlacement,this.onSelectionRangeChange=e.onSelectionRangeChange,this.onPointerDragActiveChange=e.onPointerDragActiveChange,this.isPopoverOpen=e.isPopoverOpen,this.canMergeCells=e.canMergeCells,this.onMergeCells=e.onMergeCells,this.isMergedCell=e.isMergedCell,this.onSplitCell=e.onSplitCell,this.getCellSpan=e.getCellSpan,this.i18n=e.i18n,this.grid.style.position=`relative`,this.boundPointerDown=this.handlePointerDown.bind(this),this.boundPointerMove=this.handlePointerMove.bind(this),this.boundPointerUp=this.handlePointerUp.bind(this),this.boundClearSelection=this.handleClearSelection.bind(this),this.boundCancelRectangle=this.handleCancelRectangle.bind(this),this.boundKeyDown=this.handleKeyDown.bind(this),this.boundCopyHandler=this.handleCopy.bind(this),this.boundCutHandler=this.handleCut.bind(this),this.boundPreventDragStart=this.handleDragStart.bind(this),this.grid.addEventListener(`pointerdown`,this.boundPointerDown),this.grid.addEventListener(`dragstart`,this.boundPreventDragStart),document.addEventListener(`keydown`,this.boundKeyDown),document.addEventListener(`copy`,this.boundCopyHandler),document.addEventListener(`cut`,this.boundCutHandler)}destroy(){if(this.destroyPillPopover(),this.disconnectResizeObserver(),this.clearSelection(),this.anchorCell){var e;(e=this.onPointerDragActiveChange)==null||e.call(this,!1),this.grid.style.userSelect=``}this.grid.removeEventListener(`pointerdown`,this.boundPointerDown),this.grid.removeEventListener(`dragstart`,this.boundPreventDragStart),document.removeEventListener(`pointermove`,this.boundPointerMove),document.removeEventListener(`pointerup`,this.boundPointerUp),document.removeEventListener(`pointercancel`,this.boundPointerUp),document.removeEventListener(`pointerdown`,this.boundClearSelection),document.removeEventListener(`mousemove`,this.boundCancelRectangle,!0),document.removeEventListener(`keydown`,this.boundKeyDown),document.removeEventListener(`copy`,this.boundCopyHandler),document.removeEventListener(`cut`,this.boundCutHandler)}selectRow(e){let t=this.getLogicalColumnCount();t!==0&&this.showProgrammaticSelection(e,0,e,t-1)}selectColumn(e){let t=this.grid.querySelectorAll(`[${I}]`).length;t!==0&&this.showProgrammaticSelection(0,e,t-1,e)}clearActiveSelection(){this.clearSelection()}getSelectedRange(){return this.hasSelection?this.lastPaintedRange:null}selectRange(e){this.showProgrammaticSelection(e.minRow,e.minCol,e.maxRow,e.maxCol)}handleDragStart(e){this.anchorCell&&e.preventDefault()}handlePointerDown(e){var t;if(tn(this.grid)||e.button!==0)return;let n=e.target;if(n.closest(`[data-blok-table-grip]`)||n.closest(`[data-blok-table-resize]`)||n.closest(`[${Xt}]`))return;let r=this.resolveCellCoord(n);r&&(this.hasSelection&&this.lastPaintedRange!==null&&this.lastPaintedRange.minRow===r.row&&this.lastPaintedRange.maxRow===r.row&&this.lastPaintedRange.minCol===r.col&&this.lastPaintedRange.maxCol===r.col?document.removeEventListener(`pointerdown`,this.boundClearSelection):this.hasSelection&&this.clearSelection(),this.anchorCell=r,this.isSelecting=!1,(t=this.onPointerDragActiveChange)==null||t.call(this,!0),document.addEventListener(`mousemove`,this.boundCancelRectangle,!0),document.addEventListener(`pointermove`,this.boundPointerMove),document.addEventListener(`pointerup`,this.boundPointerUp),document.addEventListener(`pointercancel`,this.boundPointerUp))}handlePointerMove(e){if(!this.anchorCell)return;let t=document.elementFromPoint(e.clientX,e.clientY);if(!t)return;let n=this.resolveCellCoord(t);if(!n){this.clampExtentToEdge(e);return}if(!(!this.isSelecting&&n.row===this.anchorCell.row&&n.col===this.anchorCell.col)){if(!this.isSelecting){var r,i;this.isSelecting=!0,(r=this.onSelectionActiveChange)==null||r.call(this,!0),this.grid.style.userSelect=`none`,(i=window.getSelection())==null||i.removeAllRanges()}(!this.extentCell||this.extentCell.row!==n.row||this.extentCell.col!==n.col)&&(this.extentCell=n,this.paintSelection())}}handleCancelRectangle(e){if(!this.rectangleSelection)return;this.rectangleSelection.cancelActiveSelection();let t=document.querySelector(`[data-blok-overlay-rectangle]`);if(!t)return;let n=t;n.style.display=`none`}handlePointerUp(){var e;if(document.removeEventListener(`mousemove`,this.boundCancelRectangle,!0),document.removeEventListener(`pointermove`,this.boundPointerMove),document.removeEventListener(`pointerup`,this.boundPointerUp),document.removeEventListener(`pointercancel`,this.boundPointerUp),(e=this.onPointerDragActiveChange)==null||e.call(this,!1),this.isSelecting){if(this.grid.style.userSelect=``,this.hasSelection=!0,this.lastPaintedRange){var t;(t=this.onSelectionRangeChange)==null||t.call(this,this.lastPaintedRange)}document.addEventListener(`pointerdown`,this.boundClearSelection)}else this.anchorCell&&(this.hasSelection?document.addEventListener(`pointerdown`,this.boundClearSelection):this.showProgrammaticSelection(this.anchorCell.row,this.anchorCell.col,this.anchorCell.row,this.anchorCell.col));this.isSelecting=!1,this.anchorCell=null,this.extentCell=null}handleClearSelection(e){let t=e.target;t instanceof HTMLElement&&t.closest(`[${Xt}]`)||t instanceof HTMLElement&&t.closest(`[data-blok-popover-opened]`)!==null||(this.pillPopover!==null&&this.destroyPillPopover(),document.removeEventListener(`pointerdown`,this.boundClearSelection),this.clearSelection())}handleKeyDown(e){var t;this.hasSelection&&(e.key!==`Delete`&&e.key!==`Backspace`||this.selectedCells.length<=1||(e.preventDefault(),(t=this.onClearContent)==null||t.call(this,[...this.selectedCells]),this.clearSelection()))}handleCopy(e){var t;!this.hasSelection||!e.clipboardData||this.selectedCells.length<=1&&this.hasNativeTextSelection()||(e.preventDefault(),(t=this.onCopy)==null||t.call(this,[...this.selectedCells],e.clipboardData))}handleCut(e){var t,n;!this.hasSelection||!e.clipboardData||this.selectedCells.length<=1&&this.hasNativeTextSelection()||(e.preventDefault(),(t=this.onCut)==null||t.call(this,[...this.selectedCells],e.clipboardData),(n=this.onClearContent)==null||n.call(this,[...this.selectedCells]),this.clearSelection())}hasNativeTextSelection(){let e=window.getSelection();return e!==null&&!e.isCollapsed}clearSelection(){let e=this.hasSelection;if(this.restoreModifiedCells(),this.hasSelection=!1,this.lastPaintedRange=null,this.preExpansionWasSingleCell=!1,e){var t;(t=this.onSelectionActiveChange)==null||t.call(this,!1)}}restoreModifiedCells(){this.destroyPillPopover(),this.disconnectResizeObserver(),this.selectedCells.forEach(e=>{e.removeAttribute(Jt)}),this.pill&&(this.pill.remove(),this.pill=null),this.overlay&&(this.overlay.remove(),this.overlay=null),this.selectedCells=[]}showProgrammaticSelection(e,t,n,r){var i;if(this.clearSelection(),this.anchorCell={row:e,col:t},this.extentCell={row:n,col:r},this.paintSelection(),this.hasSelection=!0,(i=this.onSelectionActiveChange)==null||i.call(this,!0),this.lastPaintedRange){var a;(a=this.onSelectionRangeChange)==null||a.call(this,this.lastPaintedRange)}this.anchorCell=null,this.extentCell=null,document.addEventListener(`pointerdown`,this.boundClearSelection)}expandRectToMergedSpans(e){return this.getCellSpan?this.expandRectStep(e):e}expandRectStep(e){let t=this.getCellSpan;if(!t)return e;let n=Array.from({length:e.maxRow-e.minRow+1},(t,n)=>e.minRow+n),r=Array.from({length:e.maxCol-e.minCol+1},(t,n)=>e.minCol+n),i=n.reduce((e,n)=>r.reduce((e,r)=>{let{colspan:i,rowspan:a}=t(n,r);return{minRow:e.minRow,maxRow:Math.max(e.maxRow,n+a-1),minCol:e.minCol,maxCol:Math.max(e.maxCol,r+i-1)}},e),e);return i.maxRow!==e.maxRow||i.maxCol!==e.maxCol?this.expandRectStep(i):i}paintSelection(){if(!this.anchorCell||!this.extentCell)return;this.selectedCells.forEach(e=>{e.removeAttribute(Jt)}),this.selectedCells=[];let e=Math.min(this.anchorCell.row,this.extentCell.row),t=Math.max(this.anchorCell.row,this.extentCell.row),n=Math.min(this.anchorCell.col,this.extentCell.col),r=Math.max(this.anchorCell.col,this.extentCell.col);this.preExpansionWasSingleCell=e===t&&n===r,this.lastPaintedRange=this.expandRectToMergedSpans({minRow:e,maxRow:t,minCol:n,maxCol:r});let{minRow:i,maxRow:a,minCol:o,maxCol:s}=this.lastPaintedRange,c=this.grid.querySelectorAll(`[${I}]`);this.selectedCells=this.collectCellsInRange(c,i,a,o,s),this.selectedCells.forEach(e=>{e.setAttribute(Jt,``)});let l=this.findCellByCoordOrIndex(c,i,o),u=this.findCellByCoordOrIndex(c,a,s);if(!l||!u)return;let d=this.grid.getBoundingClientRect(),f=l.getBoundingClientRect(),p=u.getBoundingClientRect(),m=getComputedStyle(this.grid),h=parseFloat(m.borderTopWidth)||0,g=parseFloat(m.borderLeftWidth)||0,_=p.right-f.left+1,v=p.bottom-f.top+1,y=f.top-d.top-h-1,b=f.left-d.left-g-1;this.overlay||(this.overlay=document.createElement(`div`),this.overlay.setAttribute(`data-blok-table-selection-overlay`,``),this.overlay.style.position=`absolute`,this.overlay.style.border=Yt,this.overlay.style.pointerEvents=`none`,this.overlay.style.boxSizing=`border-box`,this.overlay.style.borderRadius=`2px`,this.grid.appendChild(this.overlay)),this.overlay.style.top=`${y}px`,this.overlay.style.left=`${b}px`,this.overlay.style.width=`${_}px`,this.overlay.style.height=`${v}px`,this.pill||(this.pill=this.createPill(),this.grid.appendChild(this.pill)),this.pill.style.left=`${b+_-1}px`,this.pill.style.top=`${y+v/2}px`,this.observeCellResizes()}repositionOverlay(){let e=this.lastPaintedRange;if(!e||!this.overlay)return;let t=this.grid.querySelectorAll(`[${I}]`),n=this.findCellByCoordOrIndex(t,e.minRow,e.minCol),r=this.findCellByCoordOrIndex(t,e.maxRow,e.maxCol);if(!n||!r)return;let i=this.grid.getBoundingClientRect(),a=n.getBoundingClientRect(),o=r.getBoundingClientRect(),s=getComputedStyle(this.grid),c=parseFloat(s.borderTopWidth)||0,l=parseFloat(s.borderLeftWidth)||0,u=o.right-a.left+1,d=o.bottom-a.top+1,f=a.top-i.top-c-1,p=a.left-i.left-l-1;this.overlay.style.top=`${f}px`,this.overlay.style.left=`${p}px`,this.overlay.style.width=`${u}px`,this.overlay.style.height=`${d}px`,this.pill&&(this.pill.style.left=`${p+u-1}px`,this.pill.style.top=`${f+d/2}px`)}observeCellResizes(){if(this.disconnectResizeObserver(),this.selectedCells.length!==0){this.resizeObserver=new ResizeObserver(()=>{this.repositionOverlay()});for(let e of this.selectedCells)this.resizeObserver.observe(e)}}disconnectResizeObserver(){this.resizeObserver&&(this.resizeObserver.disconnect(),this.resizeObserver=null)}createPill(){let e=document.createElement(`div`);e.setAttribute(Xt,``),e.setAttribute(`contenteditable`,`false`),e.className=r.n(en),e.style.width=`${$t}px`,e.style.height=`${Qt}px`,e.style.pointerEvents=`auto`,e.style.transform=`translate(-50%, -50%)`,e.style.outline=`2px solid var(--blok-table-grip-outline, transparent)`;let t=Gt(`vertical`);return t.classList.remove(`text-gray-400`),t.classList.add(`text-white`),e.appendChild(t),e.addEventListener(`mouseenter`,()=>{this.pillPopover===null&&this.expandPill()}),e.addEventListener(`mouseleave`,()=>{this.pillPopover===null&&this.collapsePill()}),e.addEventListener(`pointerdown`,e=>{e.stopPropagation(),e.preventDefault(),this.openPillPopover()}),e}openPillPopover(){if(this.destroyPillPopover(),!this.pill)return;this.expandPill();let e=t.vr===`Meta`?`⌘C`:`Ctrl+C`,n=[];if(this.onColorChange!==void 0){let{element:e}=It({i18n:this.i18n,onColorSelect:(e,t)=>{var n;(n=this.onColorChange)==null||n.call(this,[...this.selectedCells],e,t)}});n.push({icon:t.Zt,title:this.i18n.t(`tools.table.cellColor`),name:`cellColor`,children:{items:[{type:t.pr.Html,element:e}],isFlippable:!1}})}let r=[];if(this.onPlacementChange!==void 0){let e=this.lastPaintedRange&&this.getCellPlacement?this.getCellPlacement(this.lastPaintedRange.minRow,this.lastPaintedRange.minCol):void 0,{element:n}=Vt({i18n:this.i18n,currentPlacement:e,onPlacementSelect:e=>{var t;(t=this.onPlacementChange)==null||t.call(this,[...this.selectedCells],e)}});r.push({icon:t.on,title:this.i18n.t(`tools.table.placement`),name:`cellPlacement`,children:{items:[{type:t.pr.Html,element:n}],isFlippable:!1}})}let i=[];if(this.lastPaintedRange&&this.onMergeCells){var a;let e=this.lastPaintedRange;(e.minRow!==e.maxRow||e.minCol!==e.maxCol)&&!this.preExpansionWasSingleCell&&(a=this.canMergeCells)!=null&&a.call(this,e)&&i.push({icon:t.$t,title:this.i18n.t(`tools.table.mergeCells`),closeOnActivate:!0,onActivate:()=>{var t;(t=this.onMergeCells)==null||t.call(this,e),this.clearSelection()}})}if(this.lastPaintedRange&&this.onSplitCell){var o,s;let e=this.lastPaintedRange,n=e.minRow===e.maxRow&&e.minCol===e.maxCol,r=this.preExpansionWasSingleCell&&((o=this.isMergedCell)==null?void 0:o.call(this,e.minRow,e.minCol));(n||r)&&(s=this.isMergedCell)!=null&&s.call(this,e.minRow,e.minCol)&&i.push({icon:t.mn,title:this.i18n.t(`tools.table.splitCell`),closeOnActivate:!0,onActivate:()=>{var t;(t=this.onSplitCell)==null||t.call(this,e.minRow,e.minCol),this.clearSelection()}})}let c=[...n,...r,...i,{icon:t.nt,title:this.i18n.t(`tools.table.copySelection`),secondaryLabel:e,closeOnActivate:!0,onActivate:()=>{var e;(e=this.onCopyViaButton)==null||e.call(this,[...this.selectedCells])}},{icon:t.at,title:this.i18n.t(`tools.table.clearSelection`),secondaryLabel:`Del`,closeOnActivate:!0,onActivate:()=>{var e;(e=this.onClearContent)==null||e.call(this,[...this.selectedCells]),this.clearSelection()}}];this.pillPopover=new t.C({items:c,trigger:this.pill,flippable:!0}),this.pillPopover.on(t.T.Closed,()=>{this.pillPopover!==null&&(this.destroyPillPopover(),this.collapsePill())}),this.pillPopover.show()}expandPill(){if(!this.pill)return;this.pill.style.width=`${Zt}px`;let e=this.pill.querySelector(`svg`);e&&(e.classList.remove(`opacity-0`),e.classList.add(`opacity-100`))}collapsePill(){if(!this.pill)return;this.pill.style.width=`${$t}px`;let e=this.pill.querySelector(`svg`);e&&(e.classList.add(`opacity-0`),e.classList.remove(`opacity-100`))}destroyPillPopover(){if(this.pillPopover!==null){let e=this.pillPopover;this.pillPopover=null,e.destroy()}}resolveCellCoord(e){let t=e.closest(`[${L}]`);if(!t)return null;let n=t.closest(`[${I}]`);if(!n||!this.grid.contains(n))return null;let r=t.getAttribute(R),i=t.getAttribute(z);if(r!==null&&i!==null){let e=parseInt(r,10),t=parseInt(i,10);if(!isNaN(e)&&!isNaN(t))return{row:e,col:t}}let a=Array.from(this.grid.querySelectorAll(`[${I}]`)).indexOf(n);if(a<0)return null;let o=Array.from(n.querySelectorAll(`[${L}]`)).indexOf(t);return o<0?null:{row:a,col:o}}clampExtentToEdge(e){var t,n,r,i;if(!this.anchorCell||!this.isSelecting)return;let a=this.grid.getBoundingClientRect(),o=this.grid.querySelectorAll(`[${I}]`).length,s=this.getLogicalColumnCount();if(o===0||s===0)return;let c={row:this.clampAxis(e.clientY,a.top,a.bottom,o,(t=(n=this.extentCell)==null?void 0:n.row)==null?this.anchorCell.row:t),col:this.clampAxis(e.clientX,a.left,a.right,s,(r=(i=this.extentCell)==null?void 0:i.col)==null?this.anchorCell.col:r)};(!this.extentCell||this.extentCell.row!==c.row||this.extentCell.col!==c.col)&&(this.extentCell=c,this.paintSelection())}collectCellsInRange(e,t,n,r,i){if(this.grid.querySelector(`[data-blok-table-cell-row]`)===null)return Array.from(e).slice(t,n+1).flatMap(e=>{let t=e.querySelectorAll(`[${L}]`);return Array.from(t).slice(r,i+1).filter(e=>e instanceof HTMLElement)});let a=this.grid.querySelectorAll(`[${L}]`);return Array.from(a).filter(e=>{let a=e.getAttribute(R),o=e.getAttribute(z);if(a===null||o===null)return!1;let s=Number(a),c=Number(o),l=e,u=s+(l.rowSpan||1)-1,d=c+(l.colSpan||1)-1;return s<=n&&u>=t&&c<=i&&d>=r})}findCellByCoordOrIndex(e,t,n){var r,i,a;return this.grid.querySelector(`[${R}="${t}"][${z}="${n}"]`)||((r=e[t])==null?void 0:r.querySelectorAll(`[${L}]`)[n])||Array.from((i=(a=e[t])==null?void 0:a.querySelectorAll(`[data-blok-table-cell]`))==null?[]:i).find(e=>{let t=Number(e.getAttribute(z)),r=e.colSpan||1;return t<=n&&t+r-1>=n})}getLogicalColumnCount(){var e,t;let n=(e=this.grid.querySelector(`colgroup`))==null?void 0:e.querySelectorAll(`col`).length;if(n!==void 0&&n>0)return n;let r=this.grid.querySelector(`[${I}]`);return(t=r==null?void 0:r.querySelectorAll(`[data-blok-table-cell]`).length)==null?0:t}clampAxis(e,t,n,r,i){return e<t?0:e>n?r-1:i}},H=e=>{let t=e.querySelector(`colgroup`);if(!t)return[];let n=t.querySelectorAll(`col`),r=n[0];if(r&&r.style.width.endsWith(`%`)){let t=e.querySelector(`[${I}]`);if(t)return Array.from(t.querySelectorAll(`[${L}]`)).map(e=>Math.round(e.getBoundingClientRect().width))}return Array.from(n).map(e=>parseFloat(e.style.width)||0)},rn=(e,t)=>{let n=t.reduce((e,t)=>e+t,0),r=e;r.style.width=`${n+1}px`;let i=e.querySelector(`colgroup`);if(!i)return;let a=Array.from(i.querySelectorAll(`col`));t.forEach((e,t)=>{t<a.length&&(a[t].style.width=`${e}px`)})},an=(e,t)=>{let n=Array.from(e.querySelectorAll(`[${I}]`)),r=n.findIndex(e=>Array.from(e.querySelectorAll(`[${L}]`)).includes(t));return r===-1?null:{row:r,col:Array.from(n[r].querySelectorAll(`[${L}]`)).indexOf(t)}},on=e=>{var t;let n=e.querySelector(`[${V}]`);return n?((t=n.textContent)==null?``:t).trim().length===0:!0},sn=(e,t)=>{let n=e.querySelectorAll(`[${I}]`)[t];if(!n)return!0;let r=n.querySelectorAll(`[${L}]`);return Array.from(r).every(e=>on(e))},cn=(e,t)=>{let n=e.querySelectorAll(`[${I}]`);return Array.from(n).every(e=>{let n=e.querySelector(`[${z}="${t}"]`);return!n||on(n)})},ln=e=>{let t=e.querySelector(`colgroup`);if(!t)return;let n=t.querySelectorAll(`col`),r=Array.from(n).reduce((e,t)=>e+(parseFloat(t.style.width)||0),0);if(r<=0)return;let i=100/r;n.forEach(e=>{let t=e,n=parseFloat(t.style.width)||0;t.style.width=`${Math.round(n*i*100)/100}%`})},un=(e,t,n)=>{if(!e)return e;let r=[...e],[i]=r.splice(t,1);return r.splice(n,0,i),r},dn=(e,t)=>{if(!e)return e;let n=[...e];return n.splice(t,1),n.length>0?n:void 0},fn=(e,t,n,r,i)=>{let a=n==null?H(e):n,o=r===void 0?pn(a):Math.round(r/2*100)/100;i.addColumn(e,t,a,o);let s=[...a];return s.splice(t,0,o),s},pn=e=>Math.round(e.reduce((e,t)=>e+t,0)/e.length/2*100)/100,mn=e=>e.length===0?0:Math.round(e.reduce((e,t)=>e+t,0)/e.length*100)/100,hn=(e,t,n)=>{var r;if(!e)return[];let i=e.querySelectorAll(`[${I}]`)[n];return i?(r=t==null?void 0:t.getBlockIdsFromCells(i.querySelectorAll(`[data-blok-table-cell]`)))==null?[]:r:[]},gn=(e,t,n)=>{var r;if(!e)return[];let i=e.querySelectorAll(`[${I}]`),a=[];return i.forEach(e=>{let t=e.querySelector(`[${z}="${n}"]`);t&&a.push(t)}),(r=t==null?void 0:t.getBlockIdsFromCells(a))==null?[]:r},U=(e,t)=>{e.querySelectorAll(`[${L}]`).forEach(e=>{t==null||t.ensureCellHasBlock(e)})},_n=(e,n,r,i)=>{let a=e.querySelectorAll(`[${I}]`);n.forEach((e,n)=>{let o=a[n];o&&e.forEach((e,n)=>{var a;let s=o.querySelector(`[${z}="${n}"]`);if(!s)return;let c=s.querySelector(`[${V}]`);if(!c)return;let l=c.querySelectorAll(`[data-blok-id]`).length>0;if(!(!B(e)&&l)){if(!B(e)){let t=document.createElement(`div`);t.className=`leading-[1.5]`,t.innerHTML=e,c.replaceChildren(t);return}(l||((a=c.textContent)==null?``:a).length>0)&&c.replaceChildren();for(let n of e.blocks){let e=r.blocks.getBlockIndex(n);if(e===void 0)continue;let a=r.blocks.getBlockByIndex(e);if(a&&!(a.parentId!==null&&a.parentId!==void 0&&a.parentId!==i)){if(a.holder.closest(`[${t.hi.nestedBlocks}]`)){c.appendChild(a.holder.cloneNode(!0));continue}c.appendChild(a.holder)}}c.querySelectorAll(`[data-blok-placeholder-active]`).forEach(e=>{e.removeAttribute(`data-blok-placeholder-active`)}),c.querySelectorAll(`[data-placeholder]`).forEach(e=>{e.removeAttribute(`data-placeholder`)})}})})},vn=(e,t)=>{var n,r,i,a,o,s,c;if(!(typeof e==`object`&&e&&`content`in e)){var l,u;return{withHeadings:(l=t.withHeadings)==null?!1:l,withHeadingColumn:!1,stretched:(u=t.stretched)==null?!1:u,content:[]}}let d=e,f=(n=d.content)==null||(n=n[0])==null?void 0:n.length,p=d.colWidths,m=p&&f&&p.length===f?p:void 0;return{withHeadings:(r=(i=d.withHeadings)==null?t.withHeadings:i)==null?!1:r,withHeadingColumn:(a=d.withHeadingColumn)==null?!1:a,stretched:(o=(s=d.stretched)==null?t.stretched:s)==null?!1:o,content:(c=d.content)==null?[]:c,colWidths:m,initialColWidth:d.initialColWidth}},yn=(e,t)=>{let n=n=>{let r=n.target.closest(`[${L}]`);if(!r)return;let i=an(e,r);i&&(t==null||t.handleKeyDown(n,i))};return e.addEventListener(`keydown`,n),()=>{e.removeEventListener(`keydown`,n)}},bn=[`overflow-x-auto`,`overflow-y-hidden`],xn=e=>{e==null||e.classList.add(...bn)},Sn=(e,t)=>{if(!e)return;let n=e.querySelectorAll(`[${I}]`);n.forEach(e=>{e.removeAttribute(`data-blok-table-heading`)}),t&&n.length>0&&n[0].setAttribute(`data-blok-table-heading`,``)},Cn=(e,t)=>{let n=e.querySelectorAll(`[${I}]`);t.forEach((e,t)=>{t>=n.length||e.forEach((e,r)=>{let i=n[t].querySelector(`[${z}="${r}"]`);i&&(B(e)&&e.color?i.style.backgroundColor=e.color:i.style.backgroundColor=``,B(e)&&e.textColor?i.style.color=e.textColor:i.style.color=``)})})},wn=(e,t)=>{let n=e.querySelectorAll(`[${I}]`);t.forEach((e,t)=>{t>=n.length||e.forEach((e,r)=>{let i=n[t].querySelector(`[${z}="${r}"]`);if(!i)return;let a=i.querySelector(`[${V}]`);a&&(B(e)&&e.placement&&e.placement!==`top-left`?a.setAttribute(`data-blok-cell-placement`,e.placement):a.removeAttribute(`data-blok-cell-placement`))})})},W=(e,t)=>{e&&(e.querySelectorAll(`[${L}]`).forEach(e=>{e.removeAttribute(`data-blok-table-heading-col`)}),t&&e.querySelectorAll(`[${I}]`).forEach(e=>{let t=e.querySelector(`[${L}]`);t&&t.setAttribute(`data-blok-table-heading-col`,``)}))},Tn=e=>!!(/^#[0-9a-f]{3,4}$/i.test(e)||/^#[0-9a-f]{6}([0-9a-f]{2})?$/i.test(e)||/^rgba?\(\s*[\d.]+\s*,\s*[\d.]+\s*,\s*[\d.]+\s*(,\s*[\d.]+\s*)?\)$/i.test(e)||/^hsla?\(\s*[\d.]+\s*,\s*[\d.]+%\s*,\s*[\d.]+%\s*(,\s*[\d.]+\s*)?\)$/i.test(e)||e===`transparent`),En=class{constructor(e){var t,n,r;this.withHeadingsValue=(t=e==null?void 0:e.withHeadings)==null?!1:t,this.withHeadingColumnValue=(n=e==null?void 0:e.withHeadingColumn)==null?!1:n,this.stretchedValue=(r=e==null?void 0:e.stretched)==null?!1:r,this.colWidthsValue=e!=null&&e.colWidths?[...e.colWidths]:void 0,this.initialColWidthValue=e==null?void 0:e.initialColWidth,this.contentGrid=this.normalizeContent(e==null?void 0:e.content),this.blockCellMap=new Map,this.rebuildBlockCellMap()}get rows(){return this.contentGrid.length}get cols(){return this.contentGrid.length>0?this.contentGrid[0].length:0}get withHeadings(){return this.withHeadingsValue}get withHeadingColumn(){return this.withHeadingColumnValue}get stretched(){return this.stretchedValue}get colWidths(){return this.colWidthsValue?[...this.colWidthsValue]:void 0}get initialColWidth(){return this.initialColWidthValue}snapshot(){let e={withHeadings:this.withHeadingsValue,withHeadingColumn:this.withHeadingColumnValue,stretched:this.stretchedValue,content:this.contentGrid.map(e=>e.map(e=>{let t={blocks:[...e.blocks]};return e.color!==void 0&&(t.color=e.color),e.textColor!==void 0&&(t.textColor=e.textColor),e.placement!==void 0&&(t.placement=e.placement),e.colspan!==void 0&&e.colspan>1&&(t.colspan=e.colspan),e.rowspan!==void 0&&e.rowspan>1&&(t.rowspan=e.rowspan),e.mergedInto!==void 0&&(t.mergedInto=[...e.mergedInto]),t}))};return this.colWidthsValue!==void 0&&(e.colWidths=[...this.colWidthsValue]),this.initialColWidthValue!==void 0&&(e.initialColWidth=this.initialColWidthValue),e}findCellForBlock(e){var t;return(t=this.blockCellMap.get(e))==null?null:t}addBlockToCell(e,t,n){if(!this.isInBounds(e,t)||this.isSpannedCell(e,t))return;let r=this.blockCellMap.get(n);if(r){let e=this.contentGrid[r.row][r.col];e.blocks=e.blocks.filter(e=>e!==n)}this.contentGrid[e][t].blocks.push(n),this.blockCellMap.set(n,{row:e,col:t})}removeBlockFromCell(e,t,n){if(!this.isInBounds(e,t))return;let r=this.contentGrid[e][t],i=r.blocks.indexOf(n);i!==-1&&(r.blocks.splice(i,1),this.blockCellMap.delete(n))}setCellBlocks(e,t,n){if(this.isInBounds(e,t)&&!this.isSpannedCell(e,t)){for(let n of this.contentGrid[e][t].blocks)this.blockCellMap.delete(n);for(let r of n){let n=this.blockCellMap.get(r);if(n!==void 0&&(n.row!==e||n.col!==t)){let e=this.contentGrid[n.row][n.col];e.blocks=e.blocks.filter(e=>e!==r)}}this.contentGrid[e][t].blocks=[...n];for(let r of n)this.blockCellMap.set(r,{row:e,col:t})}}getCellBlocks(e,t){return this.isInBounds(e,t)?[...this.contentGrid[e][t].blocks]:[]}setCellColor(e,t,n){this.isInBounds(e,t)&&(n===void 0?delete this.contentGrid[e][t].color:Tn(n)&&(this.contentGrid[e][t].color=n))}getCellColor(e,t){if(this.isInBounds(e,t))return this.contentGrid[e][t].color}setCellTextColor(e,t,n){this.isInBounds(e,t)&&(n===void 0?delete this.contentGrid[e][t].textColor:Tn(n)&&(this.contentGrid[e][t].textColor=n))}getCellTextColor(e,t){if(this.isInBounds(e,t))return this.contentGrid[e][t].textColor}setCellPlacement(e,t,n){this.isInBounds(e,t)&&(n===void 0?delete this.contentGrid[e][t].placement:this.contentGrid[e][t].placement=n)}getCellPlacement(e,t){if(this.isInBounds(e,t))return this.contentGrid[e][t].placement}addRow(e){let t=e===void 0?this.contentGrid.length:Math.min(Math.max(0,e),this.contentGrid.length),n=this.cols,r=Array.from({length:n},()=>({blocks:[]}));return this.contentGrid.splice(t,0,r),this.shiftMergedIntoRows(t,1),this.expandSpansForInsertedRow(t),this.rebuildBlockCellMap(),{type:`add-row`,index:t,cellsToPopulate:n}}deleteRow(e){if(!this.isRowInBounds(e))return{type:`delete-row`,index:e,blocksToDelete:[]};this.contractSpansForDeletedRow(e);let t=this.collectBlocksInRow(e);this.contentGrid.splice(e,1);for(let e of t)this.blockCellMap.delete(e);return this.shiftMergedIntoRows(e,-1),this.rebuildBlockCellMap(),{type:`delete-row`,index:e,blocksToDelete:t}}moveRow(e,t){if(!this.isRowInBounds(e)||!this.isRowInBounds(t)||e===t||this.isRowInvolvedInMerge(e))return{type:`move-row`,index:e,toIndex:t};let[n]=this.contentGrid.splice(e,1);return this.contentGrid.splice(t,0,n),this.rebuildMergedIntoRowCoordinates(e,t),this.rebuildBlockCellMap(),{type:`move-row`,index:e,toIndex:t}}addColumn(e,t){let n=e===void 0?this.cols:Math.min(Math.max(0,e),this.cols),r=[];if(this.contentGrid.forEach((e,t)=>{e.splice(n,0,{blocks:[]}),r.push({row:t,col:n})}),this.colWidthsValue!==void 0){let e=t==null?0:t;this.colWidthsValue.splice(n,0,e)}return this.shiftMergedIntoCols(n,1),this.expandSpansForInsertedCol(n),this.rebuildBlockCellMap(),{type:`add-column`,index:n,cellsToPopulate:r}}deleteColumn(e){var t;if(!this.isColInBounds(e))return{type:`delete-column`,index:e,blocksToDelete:[]};this.contractSpansForDeletedCol(e);let n=this.collectBlocksInColumn(e);for(let t of this.contentGrid)t.splice(e,1);for(let e of n)this.blockCellMap.delete(e);return this.colWidthsValue!==void 0&&this.colWidthsValue.splice(e,1),((t=this.colWidthsValue)==null?void 0:t.length)===0&&(this.colWidthsValue=void 0),this.shiftMergedIntoCols(e,-1),this.rebuildBlockCellMap(),{type:`delete-column`,index:e,blocksToDelete:n}}moveColumn(e,t){if(!this.isColInBounds(e)||!this.isColInBounds(t)||e===t||this.isColInvolvedInMerge(e))return{type:`move-column`,index:e,toIndex:t};for(let n of this.contentGrid){let[r]=n.splice(e,1);n.splice(t,0,r)}if(this.colWidthsValue!==void 0){let[n]=this.colWidthsValue.splice(e,1);this.colWidthsValue.splice(t,0,n)}return this.rebuildMergedIntoColCoordinates(e,t),this.rebuildBlockCellMap(),{type:`move-column`,index:e,toIndex:t}}replaceAll(e){var t;this.withHeadingsValue=e.withHeadings,this.withHeadingColumnValue=e.withHeadingColumn,this.stretchedValue=(t=e.stretched)==null?!1:t,this.colWidthsValue=e.colWidths?[...e.colWidths]:void 0,this.initialColWidthValue=e.initialColWidth,this.contentGrid=this.normalizeContent(e.content),this.blockCellMap.clear(),this.rebuildBlockCellMap()}canMergeCells(e){let{minRow:t,maxRow:n,minCol:r,maxCol:i}=e;return t===n&&r===i||t<0||n>=this.rows||r<0||i>=this.cols?!1:this.contentGrid.slice(t,n+1).every((e,a)=>{let o=t+a;return e.slice(r,i+1).every((e,a)=>{var s,c;let l=r+a,u=(s=e.colspan)==null?1:s,d=(c=e.rowspan)==null?1:c;if((u>1||d>1)&&(o+d-1>n||l+u-1>i))return!1;if(e.mergedInto!==void 0){let[n,i]=e.mergedInto;if(n<t||i<r)return!1}return!0})})}mergeCells(e){var t,n;let{minRow:r,maxRow:i,minCol:a,maxCol:o}=e,s={blocksToRelocate:[]};if(!this.canMergeCells(e))return s;let c=this.contentGrid[r][a];this.contentGrid.slice(r,i+1).forEach((e,t)=>{let n=r+t;e.slice(a,o+1).forEach((e,t)=>{var i,o;let s=a+t;n===r&&s===a||(((i=e.colspan)==null?1:i)>1||((o=e.rowspan)==null?1:o)>1)&&this.splitCellInternal(n,s)})}),(((t=c.colspan)==null?1:t)>1||((n=c.rowspan)==null?1:n)>1)&&this.splitCellInternal(r,a);let l=[];return this.contentGrid.slice(r,i+1).forEach((e,t)=>{let n=r+t;this.contentGrid[n].slice(a,o+1).forEach((e,t)=>{let i=a+t,o=this.contentGrid[n][i];for(let e of o.blocks)l.push(e),(n!==r||i!==a)&&s.blocksToRelocate.push(e);(n!==r||i!==a)&&(o.blocks=[],o.mergedInto=[r,a],delete o.colspan,delete o.rowspan)})}),c.blocks=l,c.colspan=o-a+1,c.rowspan=i-r+1,delete c.mergedInto,delete c.placement,c.colspan===1&&delete c.colspan,c.rowspan===1&&delete c.rowspan,this.rebuildBlockCellMap(),s}splitCell(e,t){var n,r;if(!this.isInBounds(e,t))return;let i=this.contentGrid[e][t];((n=i.colspan)==null?1:n)<=1&&((r=i.rowspan)==null?1:r)<=1||(this.splitCellInternal(e,t),this.rebuildBlockCellMap())}isMergedCell(e,t){var n,r;if(!this.isInBounds(e,t))return!1;let i=this.contentGrid[e][t];return((n=i.colspan)==null?1:n)>1||((r=i.rowspan)==null?1:r)>1}isSpannedCell(e,t){return this.isInBounds(e,t)?this.contentGrid[e][t].mergedInto!==void 0:!1}getCellSpan(e,t){var n,r;if(!this.isInBounds(e,t))return{colspan:1,rowspan:1};let i=this.contentGrid[e][t];return{colspan:(n=i.colspan)==null?1:n,rowspan:(r=i.rowspan)==null?1:r}}splitCellInternal(e,t){var n,r;let i=this.contentGrid[e][t],a=(n=i.colspan)==null?1:n,o=(r=i.rowspan)==null?1:r;this.contentGrid.slice(e,Math.min(e+o,this.rows)).forEach((n,r)=>{let i=e+r;this.contentGrid[i].slice(t,Math.min(t+a,this.cols)).forEach((n,r)=>{let a=t+r;if(i===e&&a===t)return;let o=this.contentGrid[i][a];delete o.mergedInto,o.blocks=[],delete o.placement})}),delete i.colspan,delete i.rowspan,delete i.placement}setWithHeadings(e){this.withHeadingsValue=e}setWithHeadingColumn(e){this.withHeadingColumnValue=e}setStretched(e){this.stretchedValue=e}setColWidths(e){this.colWidthsValue=e?[...e]:void 0}setInitialColWidth(e){this.initialColWidthValue=e}validateInvariants(){if(this.contentGrid.length>0){let e=this.contentGrid[0].length;this.contentGrid.forEach((t,n)=>{if(t.length!==e)throw Error(`Invariant violation: row ${n} has ${t.length} columns, expected ${e}`)})}if(this.colWidthsValue!==void 0&&this.contentGrid.length>0&&this.colWidthsValue.length!==this.contentGrid[0].length)throw Error(`Invariant violation: colWidths has ${this.colWidthsValue.length} entries but grid has ${this.contentGrid[0].length} columns`);let e=new Set;if(this.contentGrid.forEach((t,n)=>{t.forEach((t,r)=>{for(let i of t.blocks){if(e.has(i))throw Error(`Invariant violation: block "${i}" appears in multiple cells`);e.add(i);let t=this.blockCellMap.get(i);if(!t)throw Error(`Invariant violation: block "${i}" at [${n},${r}] not in blockCellMap`);if(t.row!==n||t.col!==r)throw Error(`Invariant violation: block "${i}" at [${n},${r}] mapped to [${t.row},${t.col}]`)}})}),this.contentGrid.forEach((e,t)=>{e.forEach((e,n)=>{var r,i;let a=(r=e.colspan)==null?1:r,o=(i=e.rowspan)==null?1:i;if(a>1||o>1){var s,c;if(t+o>this.contentGrid.length||n+a>((s=(c=this.contentGrid[0])==null?void 0:c.length)==null?0:s)){var l,u;throw Error(`Invariant violation: origin [${t},${n}] span extends beyond grid bounds (colspan=${a}, rowspan=${o}, rows=${this.contentGrid.length}, cols=${(l=(u=this.contentGrid[0])==null?void 0:u.length)==null?0:l})`)}}})}),this.contentGrid.forEach((e,t)=>{e.forEach((e,n)=>{var r,i,a,o;if(e.mergedInto===void 0)return;let[s,c]=e.mergedInto;if(s<0||s>=this.contentGrid.length||c<0||c>=((r=(i=this.contentGrid[0])==null?void 0:i.length)==null?0:r))throw Error(`Invariant violation: mergedInto at [${t},${n}] points to out-of-bounds [${s},${c}]`);let l=this.contentGrid[s][c],u=(a=l.colspan)==null?1:a,d=(o=l.rowspan)==null?1:o;if(u<=1&&d<=1)throw Error(`Invariant violation: mergedInto at [${t},${n}] points to [${s},${c}] which is not a merge origin`);if(t<s||t>=s+d||n<c||n>=c+u)throw Error(`Invariant violation: mergedInto at [${t},${n}] is outside the span of origin [${s},${c}] (colspan=${u}, rowspan=${d})`)})}),this.contentGrid.forEach((e,t)=>{e.forEach((e,n)=>{var r,i;let a=(r=e.colspan)==null?1:r,o=(i=e.rowspan)==null?1:i;a<=1&&o<=1||this.contentGrid.slice(t,t+o).forEach((e,r)=>{let i=t+r;e.slice(n,n+a).forEach((e,r)=>{let a=n+r;if(!(i===t&&a===n)&&!(e!=null&&e.mergedInto))throw Error(`Invariant violation: cell [${i},${a}] is within span of origin [${t},${n}] but has no mergedInto`)})})})}),this.blockCellMap.size!==e.size)throw Error(`Invariant violation: blockCellMap has ${this.blockCellMap.size} entries but grid has ${e.size} blocks`)}shiftMergedIntoRows(e,t){this.contentGrid.forEach((n,r)=>{this.contentGrid[r].forEach((n,i)=>{let a=this.contentGrid[r][i];a.mergedInto!==void 0&&a.mergedInto[0]>=e&&(a.mergedInto=[a.mergedInto[0]+t,a.mergedInto[1]])})})}shiftMergedIntoCols(e,t){this.contentGrid.forEach((n,r)=>{this.contentGrid[r].forEach((n,i)=>{let a=this.contentGrid[r][i];a.mergedInto!==void 0&&a.mergedInto[1]>=e&&(a.mergedInto=[a.mergedInto[0],a.mergedInto[1]+t])})})}expandSpansForInsertedRow(e){this.contentGrid.forEach((t,n)=>{this.contentGrid[n].forEach((t,r)=>{var i,a;let o=this.contentGrid[n][r],s=(i=o.rowspan)==null?1:i,c=(a=o.colspan)==null?1:a;s<=1&&c<=1||n>=e||n+s<=e||(o.rowspan=s+1,this.markInsertedRowCells(e,n,r,c))})})}markInsertedRowCells(e,t,n,r){this.contentGrid[e].slice(n,n+r).forEach((r,i)=>{let a=n+i;if(a===n&&t===e)return;let o=this.contentGrid[e][a];o.mergedInto=[t,n],o.blocks=[]})}expandSpansForInsertedCol(e){this.contentGrid.forEach((t,n)=>{this.contentGrid[n].forEach((t,r)=>{var i,a;let o=this.contentGrid[n][r],s=(i=o.rowspan)==null?1:i,c=(a=o.colspan)==null?1:a;s<=1&&c<=1||r>=e||r+c<=e||(o.colspan=c+1,this.markInsertedColCells(e,n,r,s))})})}markInsertedColCells(e,t,n,r){this.contentGrid.slice(t,t+r).forEach((r,i)=>{let a=t+i;if(a===t&&e===n)return;let o=this.contentGrid[a][e];o.mergedInto=[t,n],o.blocks=[]})}contractSpansForDeletedRow(e){this.contentGrid[e].forEach((t,n)=>{var r,i;let a=this.contentGrid[e][n];((r=a.colspan)==null?1:r)>1||((i=a.rowspan)==null?1:i)>1?this.handleOriginInDeletedRow(e,n):a.mergedInto!==void 0&&this.handleCoveredInDeletedRow(e,n)})}handleOriginInDeletedRow(e,t){var n,r;let i=this.contentGrid[e][t],a=(n=i.rowspan)==null?1:n,o=(r=i.colspan)==null?1:r;if(a<=1)return;let s=a-1,c=e+1;c<this.contentGrid.length&&this.transferOriginToNextRow(e,t,c,a,o,s),delete i.colspan,delete i.rowspan}transferOriginToNextRow(e,t,n,r,i,a){let o=this.contentGrid[e][t],s=this.contentGrid[n][t];if(s.blocks=[...o.blocks],o.blocks=[],delete s.mergedInto,a===1&&i===1){delete s.colspan,delete s.rowspan,this.clearMergedIntoRefs(n,e+r,t,t+i,e,t,n,t,void 0);return}a>1?s.rowspan=a:delete s.rowspan,i>1?s.colspan=i:delete s.colspan,this.clearMergedIntoRefs(n,e+r,t,t+i,e,t,n,t,[n,t])}handleCoveredInDeletedRow(e,t){var n,r,i;let[a,o]=this.contentGrid[e][t].mergedInto;if(a===e)return;let s=(n=this.contentGrid[a])==null?void 0:n[o];if(!s)return;let c=(r=s.rowspan)==null?1:r,l=(i=s.colspan)==null?1:i,u=c-1;u===1&&l===1?(delete s.colspan,delete s.rowspan,this.clearMergedIntoRefsForDissolve(a,a+c,o,o+l,a,o,e)):u>1?s.rowspan=u:delete s.rowspan}clearMergedIntoRefs(e,t,n,r,i,a,o,s,c){this.contentGrid.slice(e,t).forEach((t,l)=>{let u=e+l;this.contentGrid[u].slice(n,r).forEach((e,t)=>{var r,l,d;let f=n+t;if(u===o&&f===s)return;let p=(r=this.contentGrid[u])==null?void 0:r[f];(p==null||(l=p.mergedInto)==null?void 0:l[0])===i&&(p==null||(d=p.mergedInto)==null?void 0:d[1])===a&&(c===void 0?delete p.mergedInto:p.mergedInto=c)})})}clearMergedIntoRefsForDissolve(e,t,n,r,i,a,o){this.contentGrid.slice(e,t).forEach((t,s)=>{let c=e+s;c!==o&&this.contentGrid[c].slice(n,r).forEach((e,t)=>{var r;let o=n+t;if(c===i&&o===a)return;let s=(r=this.contentGrid[c])==null?void 0:r[o];s!=null&&s.mergedInto&&delete s.mergedInto})})}contractSpansForDeletedCol(e){this.contentGrid.forEach((t,n)=>{var r,i;let a=this.contentGrid[n][e];((r=a.colspan)==null?1:r)>1||((i=a.rowspan)==null?1:i)>1?this.handleOriginInDeletedCol(e,n):a.mergedInto!==void 0&&this.handleCoveredInDeletedCol(e,n)})}handleOriginInDeletedCol(e,t){var n,r,i,a;let o=this.contentGrid[t][e],s=(n=o.rowspan)==null?1:n,c=(r=o.colspan)==null?1:r;if(c<=1)return;let l=c-1,u=e+1;u<((i=(a=this.contentGrid[t])==null?void 0:a.length)==null?0:i)&&this.transferOriginToNextCol(e,t,u,s,c,l),delete o.colspan,delete o.rowspan}transferOriginToNextCol(e,t,n,r,i,a){let o=this.contentGrid[t][e],s=this.contentGrid[t][n];if(s.blocks=[...o.blocks],o.blocks=[],delete s.mergedInto,a===1&&r===1){delete s.colspan,delete s.rowspan,this.clearMergedIntoRefs(t,t+r,n,e+i,t,e,t,n,void 0);return}a>1?s.colspan=a:delete s.colspan,r>1?s.rowspan=r:delete s.rowspan,this.clearMergedIntoRefs(t,t+r,n,e+i,t,e,t,n,[t,n])}handleCoveredInDeletedCol(e,t){var n,r,i;let[a,o]=this.contentGrid[t][e].mergedInto;if(o===e)return;let s=(n=this.contentGrid[a])==null?void 0:n[o];if(!s)return;let c=(r=s.colspan)==null?1:r,l=(i=s.rowspan)==null?1:i,u=c-1;u===1&&l===1?(delete s.colspan,delete s.rowspan,this.clearMergedIntoRefsForDissolveCol(a,a+l,o,o+c,a,o,e)):u>1?s.colspan=u:delete s.colspan}clearMergedIntoRefsForDissolveCol(e,t,n,r,i,a,o){this.contentGrid.slice(e,t).forEach((t,s)=>{let c=e+s;this.contentGrid[c].slice(n,r).forEach((e,t)=>{var r;let s=n+t;if(c===i&&s===a||s===o)return;let l=(r=this.contentGrid[c])==null?void 0:r[s];l!=null&&l.mergedInto&&delete l.mergedInto})})}isRowInvolvedInMerge(e){return this.contentGrid[e].some(t=>{var n;return((n=t.rowspan)==null?1:n)>1?!0:t.mergedInto!==void 0&&t.mergedInto[0]!==e})}isColInvolvedInMerge(e){return this.contentGrid.some(t=>{var n;let r=t[e];return((n=r.colspan)==null?1:n)>1?!0:r.mergedInto!==void 0&&r.mergedInto[1]!==e})}rebuildMergedIntoRowCoordinates(e,t){let n=this.contentGrid.length,r=this.buildMoveMapping(n,e,t);this.contentGrid.forEach((e,t)=>{this.contentGrid[t].forEach((e,n)=>{let i=this.contentGrid[t][n];i.mergedInto!==void 0&&(i.mergedInto=[r[i.mergedInto[0]],i.mergedInto[1]])})})}rebuildMergedIntoColCoordinates(e,t){let n=this.cols,r=this.buildMoveMapping(n,e,t);this.contentGrid.forEach((e,t)=>{this.contentGrid[t].forEach((e,n)=>{let i=this.contentGrid[t][n];if(i.mergedInto!==void 0){let e=i.mergedInto[1];i.mergedInto=[i.mergedInto[0],r[e]]}})})}buildMoveMapping(e,t,n){return Array.from({length:e},(e,r)=>{if(r===t)return n;let i=r>t?r-1:r;return i>=n?i+1:i})}normalizeContent(e){if(!e||!Array.isArray(e))return[];let t=new Set;return e.map(e=>(e==null?[]:e).map(e=>{let n=this.normalizeCell(e);return n.blocks=n.blocks.filter(e=>t.has(e)?!1:(t.add(e),!0)),n}))}normalizeCell(e){if(B(e)){let t={blocks:[...e.blocks]};return e.color!==void 0&&Tn(e.color)&&(t.color=e.color),e.textColor!==void 0&&Tn(e.textColor)&&(t.textColor=e.textColor),e.placement!==void 0&&(t.placement=e.placement),e.colspan!==void 0&&e.colspan>1&&(t.colspan=e.colspan),e.rowspan!==void 0&&e.rowspan>1&&(t.rowspan=e.rowspan),e.mergedInto!==void 0&&(t.mergedInto=[...e.mergedInto]),t}return{blocks:[]}}rebuildBlockCellMap(){this.blockCellMap.clear(),this.contentGrid.forEach((e,t)=>{e.forEach((e,n)=>{for(let r of e.blocks)this.blockCellMap.set(r,{row:t,col:n})})})}isInBounds(e,t){return e>=0&&e<this.contentGrid.length&&t>=0&&(this.contentGrid.length===0||t<this.contentGrid[e].length)}isRowInBounds(e){return e>=0&&e<this.contentGrid.length}isColInBounds(e){return e>=0&&this.contentGrid.length>0&&e<this.contentGrid[0].length}collectBlocksInRow(e){let t=[];for(let n of this.contentGrid[e])t.push(...n.blocks);return t}collectBlocksInColumn(e){let t=[];for(let n of this.contentGrid)e<n.length&&t.push(...n[e].blocks);return t}},Dn=`data-blok-table-resize`,On=50,kn=16,An=class{get enabled(){return this._enabled}set enabled(e){this._enabled=e;let t=e?``:`none`;this.handles.forEach(e=>{let n=e;n.style.pointerEvents=t})}constructor(e,t,n,r,i,a=!1){this._enabled=!0,this.isDragging=!1,this.dragStartX=0,this.dragColIndex=-1,this.startColWidth=0,this.dragColElements=null,this.handles=[],this.gridEl=e,this.colWidths=[...t],this.onChange=n,this.onDragStart=r==null?null:r,this.onDrag=i==null?null:i,this.needsInitialApply=a,this.boundPointerDown=this.onPointerDown.bind(this),this.boundPointerMove=this.onPointerMove.bind(this),this.boundPointerUp=this.onPointerUp.bind(this),this.gridEl.style.position=`relative`,a||this.applyWidths(),this.createHandles(),this.gridEl.addEventListener(`pointerdown`,this.boundPointerDown)}destroy(){this.gridEl.removeEventListener(`pointerdown`,this.boundPointerDown),document.removeEventListener(`pointermove`,this.boundPointerMove),document.removeEventListener(`pointerup`,this.boundPointerUp),this.dragColElements=null,this.handles.forEach(e=>e.remove()),this.handles=[]}createHandles(){let e=this.colWidths.length;e<2||Array.from({length:e}).forEach((e,t)=>{let n=this.createHandle(t);this.handles.push(n),this.gridEl.appendChild(n)})}createHandle(e){let t=document.createElement(`div`),n=this.getHandleLeftPx(e);return t.setAttribute(Dn,``),t.setAttribute(`data-col`,String(e)),t.style.position=`absolute`,t.style.top=`-1px`,t.style.bottom=`0px`,t.style.width=`${kn}px`,t.style.left=`${n-kn/2}px`,t.style.cursor=`col-resize`,t.style.zIndex=`2`,t.style.background=`linear-gradient(to right, transparent 7px, #3b82f6 7px, #3b82f6 9px, transparent 9px)`,t.style.opacity=`0`,t.style.transition=`opacity 150ms ease`,t.setAttribute(`contenteditable`,`false`),t.addEventListener(`mouseenter`,()=>{this.isDragging||(t.style.opacity=`1`)}),t.addEventListener(`mouseleave`,()=>{this.isDragging||(t.style.opacity=`0`)}),t}getHandleLeftPx(e){return this.colWidths.slice(0,e+1).reduce((e,t)=>e+t,0)}updateHandlePositions(){this.handles.forEach((e,t)=>{let n=this.getHandleLeftPx(t),r=e;r.style.left=`${n-kn/2}px`})}onPointerDown(e){var t;if(!this._enabled)return;let n=e.target;if(!n.hasAttribute(Dn))return;e.preventDefault(),this.needsInitialApply&&(this.applyWidths(),this.updateHandlePositions(),this.needsInitialApply=!1);let r=n.getAttribute(`data-col`);r!==null&&(this.dragColIndex=Number(r),this.isDragging=!0,this.dragStartX=e.clientX,this.startColWidth=this.colWidths[this.dragColIndex],this.dragColElements=this.resolveColElements(),(t=this.onDragStart)==null||t.call(this),this.gridEl.style.userSelect=`none`,n.style.opacity=`1`,n.setPointerCapture&&n.setPointerCapture(e.pointerId),document.addEventListener(`pointermove`,this.boundPointerMove),document.addEventListener(`pointerup`,this.boundPointerUp))}onPointerMove(e){var t,n;if(!this.isDragging)return;let r=e.clientX-this.dragStartX,i=this.startColWidth+r,a=Math.max(On,i);this.colWidths[this.dragColIndex]=a,this.applyWidths((t=this.dragColElements)==null?void 0:t),this.updateHandlePositions(),(n=this.onDrag)==null||n.call(this)}onPointerUp(){if(!this.isDragging)return;this.isDragging=!1,this.gridEl.style.userSelect=``;let e=this.handles[this.dragColIndex];e&&(e.style.opacity=`0`),document.removeEventListener(`pointermove`,this.boundPointerMove),document.removeEventListener(`pointerup`,this.boundPointerUp),this.dragColElements=null,this.onChange([...this.colWidths])}resolveColElements(){let e=this.gridEl.querySelector(`colgroup`);return e?Array.from(e.querySelectorAll(`col`)):[]}applyWidths(e=this.resolveColElements()){let t=this.colWidths.reduce((e,t)=>e+t,0);this.gridEl.style.width=`${t+1}px`,e.forEach((e,t)=>{if(t<this.colWidths.length){let n=e;n.style.width=`${this.colWidths[t]}px`}})}},jn=(e,t,n)=>(n.grid.addRow(e,t),U(e,n.cellBlocks),{pendingHighlight:{type:`row`,index:t},moveSelection:null,colWidths:n.data.colWidths,withHeadings:n.data.withHeadings,withHeadingColumn:n.data.withHeadingColumn}),Mn=(e,t,n)=>{let r=fn(e,t,n.data.colWidths,n.data.initialColWidth,n.grid);return U(e,n.cellBlocks),{pendingHighlight:{type:`col`,index:t},moveSelection:null,colWidths:r,withHeadings:n.data.withHeadings,withHeadingColumn:n.data.withHeadingColumn}},Nn=(e,t,n,r)=>(r.grid.moveRow(e,t,n),{pendingHighlight:null,moveSelection:{type:`row`,index:n},colWidths:r.data.colWidths,withHeadings:r.data.withHeadings,withHeadingColumn:r.data.withHeadingColumn}),Pn=(e,t,n,r)=>(r.grid.moveColumn(e,t,n),{pendingHighlight:null,moveSelection:{type:`col`,index:n},colWidths:un(r.data.colWidths,t,n),withHeadings:r.data.withHeadings,withHeadingColumn:r.data.withHeadingColumn}),Fn=(e,t,n)=>{var r,i;return(r=n.cellBlocks)==null||r.deleteBlocks((i=n.blocksToDelete)==null?[]:i),n.grid.deleteRow(e,t),{pendingHighlight:{type:`row`,index:t<n.grid.getRowCount(e)?t:t-1},moveSelection:null,colWidths:n.data.colWidths,withHeadings:n.data.withHeadings,withHeadingColumn:n.data.withHeadingColumn}},In=(e,t,n)=>{var r,i;(r=n.cellBlocks)==null||r.deleteBlocks((i=n.blocksToDelete)==null?[]:i),n.grid.deleteColumn(e,t);let a=dn(n.data.colWidths,t);return a?rn(e,a):ln(e),{pendingHighlight:{type:`col`,index:t<n.grid.getColumnCount(e)?t:t-1},moveSelection:null,colWidths:a,withHeadings:n.data.withHeadings,withHeadingColumn:n.data.withHeadingColumn}},Ln=(e,t,n)=>{switch(t.type){case`insert-row-above`:return jn(e,t.index,n);case`insert-row-below`:return jn(e,t.index+1,n);case`insert-col-left`:return Mn(e,t.index,n);case`insert-col-right`:return Mn(e,t.index+1,n);case`move-row`:return Nn(e,t.fromIndex,t.toIndex,n);case`move-col`:return Pn(e,t.fromIndex,t.toIndex,n);case`delete-row`:return Fn(e,t.index,n);case`delete-col`:return In(e,t.index,n);case`toggle-heading`:return{pendingHighlight:{type:`row`,index:0},moveSelection:null,colWidths:n.data.colWidths,withHeadings:!n.data.withHeadings,withHeadingColumn:n.data.withHeadingColumn};case`toggle-heading-column`:return{pendingHighlight:{type:`col`,index:0},moveSelection:null,colWidths:n.data.colWidths,withHeadings:n.data.withHeadings,withHeadingColumn:!n.data.withHeadingColumn}}},Rn=10,zn=`data-blok-table-drag-ghost`,Bn=e=>{let t=e.querySelector(`colgroup`);if(t)return Array.from(t.querySelectorAll(`col`)).reduce((e,t)=>{let n=e[e.length-1],r=t.offsetWidth||parseFloat(t.style.width)||0;return[...e,n+r]},[0]);let n=e.querySelector(`[${I}]`);return n?Array.from(n.querySelectorAll(`[${L}]`)).reduce((e,t)=>{let n=e[e.length-1];return[...e,n+t.offsetWidth]},[0]):[0]},Vn=class{constructor(e){var t;this.isDragging=!1,this.dragType=null,this.dragFromIndex=-1,this.dragStartX=0,this.dragStartY=0,this.dropIndicator=null,this.dragOverlayCells=[],this.ghostEl=null,this.ghostOffsetX=0,this.ghostOffsetY=0,this.resolveTracking=null,this.grid=e.grid,this.onAction=e.onAction,this.onDragStateChange=(t=e.onDragStateChange)==null?null:t,this.boundDocPointerMove=this.handleDocPointerMove.bind(this),this.boundDocPointerUp=this.handleDocPointerUp.bind(this),this.boundDocPointerCancel=this.handleDocPointerCancel.bind(this)}beginTracking(e,t,n,r){return this.dragType=e,this.dragFromIndex=t,this.dragStartX=n,this.dragStartY=r,document.addEventListener(`pointermove`,this.boundDocPointerMove),document.addEventListener(`pointerup`,this.boundDocPointerUp),document.addEventListener(`pointercancel`,this.boundDocPointerCancel),new Promise(e=>{this.resolveTracking=e})}cleanup(){var e,t,n;this.grid.style.userSelect=``,document.body.style.cursor=``,this.dragOverlayCells.forEach(e=>{let t=e;t.style.backgroundColor=``,t.style.opacity=``}),this.dragOverlayCells=[],(e=this.dropIndicator)==null||e.remove(),this.dropIndicator=null,(t=this.ghostEl)==null||t.remove(),this.ghostEl=null,document.removeEventListener(`pointermove`,this.boundDocPointerMove),document.removeEventListener(`pointerup`,this.boundDocPointerUp),document.removeEventListener(`pointercancel`,this.boundDocPointerCancel),(n=this.onDragStateChange)==null||n.call(this,!1,null),this.isDragging=!1,this.dragType=null,this.dragFromIndex=-1,this.resolveTracking=null}handleDocPointerMove(e){let t=Math.abs(e.clientX-this.dragStartX),n=Math.abs(e.clientY-this.dragStartY);!this.isDragging&&(t>Rn||n>Rn)&&(this.isDragging=!0,this.startDrag()),this.isDragging&&(this.updateDragIndicator(e),this.updateGhostPosition(e))}handleDocPointerUp(e){if(document.removeEventListener(`pointermove`,this.boundDocPointerMove),document.removeEventListener(`pointerup`,this.boundDocPointerUp),document.removeEventListener(`pointercancel`,this.boundDocPointerCancel),this.isDragging){var t;this.finishDrag(e),(t=this.resolveTracking)==null||t.call(this,!0)}else{var n;(n=this.resolveTracking)==null||n.call(this,!1)}this.cleanup()}handleDocPointerCancel(){var e;(e=this.resolveTracking)==null||e.call(this,this.isDragging),this.cleanup()}startDrag(){var e;this.grid.style.userSelect=`none`,document.body.style.cursor=`grabbing`,(e=this.onDragStateChange)==null||e.call(this,!0,this.dragType),this.highlightSourceCells(),this.createDropIndicator(),this.createGhost()}highlightSourceCells(){let e=this.grid.querySelectorAll(`[${I}]`);if(this.dragType===`row`){this.highlightRowCells(e);return}this.dragType===`col`&&this.highlightColumnCells(e)}highlightRowCells(e){let t=e[this.dragFromIndex];if(!t)return;let n=this.getDragSourceBg();t.querySelectorAll(`[${L}]`).forEach(e=>{let t=e;t.style.backgroundColor=n,t.style.opacity=`0.7`,this.dragOverlayCells.push(t)})}highlightColumnCells(e){let t=this.getDragSourceBg();e.forEach(e=>{let n=e.querySelector(`[${z}="${this.dragFromIndex}"]`);n&&(n.style.backgroundColor=t,n.style.opacity=`0.7`,this.dragOverlayCells.push(n))})}getDragSourceBg(){return getComputedStyle(this.grid).getPropertyValue(`--blok-table-drag-source-bg`).trim()||`#f3f4f6`}isDarkMode(){var e,t,n;let r=document.documentElement.getAttribute(`data-blok-theme`);return r===`dark`?!0:r===`light`||(e=(t=(n=window).matchMedia)==null?void 0:t.call(n,`(prefers-color-scheme: dark)`).matches)==null?!1:e}createDropIndicator(){this.dropIndicator=document.createElement(`div`);let e=this.dropIndicator.style;if(e.position=`absolute`,e.backgroundColor=`#3b82f6`,e.borderRadius=`1.5px`,e.zIndex=`5`,e.pointerEvents=`none`,this.dropIndicator.setAttribute(`contenteditable`,`false`),this.dragType===`row`)e.height=`3px`,e.left=`-1px`,e.right=`0`,e.transition=`top 100ms ease`;else{let t=this.grid.querySelectorAll(`[${I}]`),n=t[t.length-1],r=n?n.offsetTop+n.offsetHeight:0;e.width=`3px`,e.top=`-1px`,e.height=`${r+1}px`,e.transition=`left 100ms ease`}this.grid.appendChild(this.dropIndicator)}updateDragIndicator(e){if(!this.dropIndicator)return;let t=this.grid.getBoundingClientRect();if(this.dragType===`row`){this.updateRowIndicator(e,t);return}this.dragType===`col`&&this.updateColIndicator(e,t)}updateRowIndicator(e,t){if(!this.dropIndicator)return;let n=e.clientY-t.top,r=this.getRowDropIndex(n),i=this.getRowDropTopPx(r);this.dropIndicator.style.top=`${i-1.5}px`}updateColIndicator(e,t){var n;if(!this.dropIndicator)return;let r=e.clientX-t.left,i=this.getColDropIndex(r),a=Bn(this.grid);this.dropIndicator.style.left=`${((n=a[i])==null?0:n)-1.5}px`}finishDrag(e){let t=this.grid.getBoundingClientRect();if(this.dragType===`row`){this.finishRowDrag(e,t);return}this.dragType===`col`&&this.finishColDrag(e,t)}finishRowDrag(e,t){let n=e.clientY-t.top,r=this.getRowDropIndex(n),i=r>this.dragFromIndex?r-1:r;i!==this.dragFromIndex&&this.onAction({type:`move-row`,fromIndex:this.dragFromIndex,toIndex:i})}finishColDrag(e,t){let n=e.clientX-t.left,r=this.getColDropIndex(n),i=r>this.dragFromIndex?r-1:r;i!==this.dragFromIndex&&this.onAction({type:`move-col`,fromIndex:this.dragFromIndex,toIndex:i})}createGhost(){let e=document.createElement(`div`);e.setAttribute(zn,``),e.setAttribute(`contenteditable`,`false`);let t=e.style;t.position=`fixed`,t.pointerEvents=`none`,t.opacity=`0.5`,t.zIndex=`50`,t.borderRadius=`4px`,t.overflow=`hidden`,t.boxShadow=this.isDarkMode()?`0 8px 24px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 255, 255, 0.08)`:`0 4px 12px rgba(0, 0, 0, 0.15)`,this.ghostEl=e;let n=this.getSourceRect();this.dragType===`row`&&this.buildRowGhost(),this.dragType===`col`&&this.buildColumnGhost(),document.body.appendChild(e),n&&(t.left=`${n.left}px`,t.top=`${n.top}px`,this.ghostOffsetX=this.dragStartX-n.left,this.ghostOffsetY=this.dragStartY-n.top)}getSourceRect(){return this.dragType===`row`?this.getRowSourceRect():this.dragType===`col`?this.getColSourceRect():null}getRowSourceRect(){var e;let t=this.grid.querySelectorAll(`[${I}]`)[this.dragFromIndex];return(e=t==null?void 0:t.getBoundingClientRect())==null?null:e}getColSourceRect(){let e=this.grid.querySelectorAll(`[${I}]`),t=e[0],n=e[e.length-1];if(!t||!n)return null;let r=t.querySelector(`[${z}="${this.dragFromIndex}"]`),i=n.querySelector(`[${z}="${this.dragFromIndex}"]`);if(!r||!i)return null;let a=r.getBoundingClientRect(),o=i.getBoundingClientRect();return new DOMRect(a.left,a.top,a.width,o.bottom-a.top)}buildRowGhost(){let e=this.grid.querySelectorAll(`[${I}]`)[this.dragFromIndex];if(!e||!this.ghostEl)return;let t=this.ghostEl.style;t.display=`flex`,t.height=`${e.offsetHeight}px`,e.querySelectorAll(`[${L}]`).forEach(e=>{var t;let n=e,r=n.cloneNode(!0);r.style.width=`${n.offsetWidth}px`,r.style.flexShrink=`0`,r.removeAttribute(`contenteditable`),(t=this.ghostEl)==null||t.appendChild(r)})}buildColumnGhost(){if(!this.ghostEl)return;let e=this.grid.querySelectorAll(`[${I}]`),t=this.ghostEl.style;t.display=`flex`,t.flexDirection=`column`,e.forEach(e=>{var t;let n=e.querySelector(`[${z}="${this.dragFromIndex}"]`);if(!n)return;let r=n.cloneNode(!0);r.style.width=`${n.offsetWidth}px`,r.style.height=`${n.offsetHeight}px`,r.removeAttribute(`contenteditable`),(t=this.ghostEl)==null||t.appendChild(r)})}updateGhostPosition(e){if(!this.ghostEl)return;let t=this.ghostEl.style;this.dragType===`row`&&(t.top=`${e.clientY-this.ghostOffsetY}px`),this.dragType===`col`&&(t.left=`${e.clientX-this.ghostOffsetX}px`)}getRowDropIndex(e){let t=Array.from(this.grid.querySelectorAll(`[${I}]`)),n=t.map(e=>e.offsetTop);if(t.length>0){let e=t[t.length-1];n.push(e.offsetTop+e.offsetHeight)}let r=n.map(t=>Math.abs(e-t)),i=Math.min(...r);return r.indexOf(i)}getRowDropTopPx(e){let t=this.grid.querySelectorAll(`[${I}]`);if(e<t.length)return t[e].offsetTop;if(t.length>0){let e=t[t.length-1];return e.offsetTop+e.offsetHeight}return 0}getColDropIndex(e){let t=Bn(this.grid).map(t=>Math.abs(e-t)),n=Math.min(...t);return t.indexOf(n)}},Hn=[`flex`,`items-center`,`select-none`,`border-none`,`bg-transparent`,`rounded-md`,`p-(--item-padding)`,`text-text-primary`,`mb-px`,`cursor-pointer`,`can-hover:hover:bg-item-hover-bg`],Un=[`flex`,`items-center`,`justify-center`,`w-[26px]`,`h-[26px]`,`mr-2`,`[&_svg]:w-icon`,`[&_svg]:h-icon`],Wn=[`mr-auto`,`truncate`,`text-sm`,`font-medium`,`leading-5`],Gn=[`relative`,`w-[30px]`,`h-[18px]`,`rounded-full`,`transition-colors`,`duration-[180ms]`,`ease-out`,`shrink-0`,`ml-2`],Kn=[`absolute`,`top-[2px]`,`w-[14px]`,`h-[14px]`,`rounded-full`,`bg-white`,`transition-[left]`,`duration-[220ms]`,`[transition-timing-function:cubic-bezier(0.34,1.56,0.64,1)]`],qn=e=>{let{icon:t,label:n,isActive:i,onToggle:a}=e,o={active:i},s=document.createElement(`div`);s.className=r.n(Hn);let c=document.createElement(`div`);c.className=r.n(Un),c.innerHTML=t,s.appendChild(c);let l=document.createElement(`span`);l.className=r.n(Wn),l.textContent=n,s.appendChild(l);let u=document.createElement(`div`);u.className=r.n(Gn);let d=document.createElement(`div`);d.className=r.n(Kn),u.appendChild(d),s.appendChild(u);let f=()=>{u.style.backgroundColor=o.active?`var(--blok-toggle-on-bg)`:`var(--blok-toggle-off-bg)`,d.style.left=o.active?`14px`:`2px`,d.style.backgroundColor=o.active?`var(--blok-toggle-thumb-on-bg)`:``,d.style.boxShadow=o.active?`0 1px 3px rgba(0,0,0,0.35), 0 0 0 1px rgba(0,0,0,0.04)`:`0 1px 3px rgba(0,0,0,0.25), 0 0 0 1px rgba(0,0,0,0.06)`};return f(),s.addEventListener(`click`,e=>{e.stopPropagation(),o.active=!o.active,f(),a(o.active)}),s},Jn=(e,n)=>{let r=e===0?[{type:t.pr.Html,element:qn({icon:t.At,label:n.i18n.t(`tools.table.headerColumn`),isActive:n.isHeadingColumn(),onToggle:()=>{n.onAction({type:`toggle-heading-column`})}})},{type:t.pr.Separator}]:[],i=[{icon:t.zt,title:n.i18n.t(`tools.table.insertColumnLeft`),closeOnActivate:!0,onActivate:()=>{n.onAction({type:`insert-col-left`,index:e})}},{icon:t.Bt,title:n.i18n.t(`tools.table.insertColumnRight`),closeOnActivate:!0,onActivate:()=>{n.onAction({type:`insert-col-right`,index:e})}}],a=n.getColumnCount()>1,o=[{type:t.pr.Separator},{icon:t.Cn,title:n.i18n.t(`tools.table.deleteColumn`),isDestructive:!0,isDisabled:!a,closeOnActivate:!0,onActivate:()=>{n.onAction({type:`delete-col`,index:e})}}];return[...r,...i,...o]},Yn=(e,n)=>{let r=e===0?[{type:t.pr.Html,element:qn({icon:t.jt,label:n.i18n.t(`tools.table.headerRow`),isActive:n.isHeadingRow(),onToggle:()=>{n.onAction({type:`toggle-heading`})}})},{type:t.pr.Separator}]:[],i=[{icon:t.Lt,title:n.i18n.t(`tools.table.insertRowAbove`),closeOnActivate:!0,onActivate:()=>{n.onAction({type:`insert-row-above`,index:e})}},{icon:t.Rt,title:n.i18n.t(`tools.table.insertRowBelow`),closeOnActivate:!0,onActivate:()=>{n.onAction({type:`insert-row-below`,index:e})}}],a=n.getRowCount()>1,o=[{type:t.pr.Separator},{icon:t.Cn,title:n.i18n.t(`tools.table.deleteRow`),isDestructive:!0,isDisabled:!a,closeOnActivate:!0,onActivate:()=>{n.onAction({type:`delete-row`,index:e})}}];return[...r,...i,...o]},Xn=(e,n,r,i,a)=>{a.destroyPopover(),a.clearHideTimeout();let o=e===`col`?r.col[n]:r.row[n];if(!o)return{popover:null,grip:null};let s=new t.C({items:e===`col`?Jn(n,i):Yn(n,i),trigger:o,flippable:!0});return s.on(t.T.Closed,()=>{var e;a.destroyPopover(),a.applyVisibleClasses(o),a.scheduleHideAll(),(e=a.onGripPopoverClose)==null||e.call(a)}),a.hideAllGripsExcept(o),a.applyActiveClasses(o),e===`col`?o.style.height=`16px`:o.style.width=`16px`,{popover:s,grip:o}},Zn=`data-blok-table-grip`,Qn=`data-blok-table-grip-col`,$n=`data-blok-table-grip-row`,er=150,tr=24,nr=4,rr=4,ir=20,ar=[`absolute`,`z-3`,`rounded-sm`,`cursor-grab`,`select-none`,`transition-[opacity,background-color,width,height]`,`duration-150`,`group`,`flex`,`items-center`,`justify-center`,`overflow-hidden`],or=[`bg-gray-300`,`opacity-0`,`pointer-events-none`],sr=[`bg-gray-300`,`opacity-100`,`pointer-events-auto`],cr=[`bg-blue-500`,`text-white`,`opacity-100`,`pointer-events-auto`],lr=class{constructor(e){this.colGrips=[],this.rowGrips=[],this.popoverState={popover:null,grip:null},this.lockedGrip=null,this.hideTimeout=null,this.activeColGripIndex=-1,this.activeRowGripIndex=-1,this.isInsideTable=!1,this.rowResizeObserver=null,this.boundScrollHandler=null,this.grid=e.grid,this.overlay=e.overlay,this.scrollContainer=e.scrollContainer,this.getColumnCount=e.getColumnCount,this.getRowCount=e.getRowCount,this.isHeadingRow=e.isHeadingRow,this.isHeadingColumn=e.isHeadingColumn,this.onAction=e.onAction,this.onGripClick=e.onGripClick,this.onGripPopoverClose=e.onGripPopoverClose,this.i18n=e.i18n,this.drag=new Vn({grid:this.grid,onAction:this.onAction,onDragStateChange:(t,n)=>{var r;this.handleDragStateChange(t,n),(r=e.onDragStateChange)==null||r.call(e,t,n)}}),this.boundMouseOver=this.handleMouseOver.bind(this),this.boundMouseLeave=this.handleMouseLeave.bind(this),this.boundPointerDown=this.handlePointerDown.bind(this),this.boundUnlockGrip=this.handleUnlockGrip.bind(this),this.createGrips(),this.grid.addEventListener(`mouseover`,this.boundMouseOver),this.grid.addEventListener(`mouseleave`,this.boundMouseLeave)}refresh(){let e=this.popoverState.grip?this.detectGripType(this.popoverState.grip):null;if(this.destroyGrips(),this.createGrips(),!e)return;let t=e.type===`col`?this.colGrips[e.index]:this.rowGrips[e.index];t&&(this.popoverState.grip=t,this.hideAllGripsExcept(t),this.applyActiveClasses(t),e.type===`col`?t.style.height=`16px`:t.style.width=`16px`)}setActiveGrip(e,t){let n=e===`col`?this.colGrips[t]:this.rowGrips[t];n&&(this.unlockGrip(),this.clearHideTimeout(),this.hideAllGripsExcept(n),this.applyActiveClasses(n),e===`col`?n.style.height=`16px`:n.style.width=`16px`,this.lockedGrip=n,document.addEventListener(`pointerdown`,this.boundUnlockGrip))}handleUnlockGrip(e){document.removeEventListener(`pointerdown`,this.boundUnlockGrip),this.lockedGrip&&(this.applyIdleClasses(this.lockedGrip),this.lockedGrip=null);let t=e.target instanceof HTMLElement?e.target:null,n=t==null?void 0:t.closest(`[${L}]`);if(n){let e=this.getCellPosition(n);e&&(this.clearHideTimeout(),this.showColGrip(e.col),this.showRowGrip(e.row),this.isInsideTable=!0)}}unlockGrip(){document.removeEventListener(`pointerdown`,this.boundUnlockGrip),this.lockedGrip=null}getVisibleGripIndices(){return this.activeColGripIndex<0&&this.activeRowGripIndex<0?null:{col:this.activeColGripIndex,row:this.activeRowGripIndex}}restoreVisibleGrips(e,t){this.isInsideTable=e>=0||t>=0,e>=0&&this.showColGrip(e),t>=0&&this.showRowGrip(t)}get isPopoverOpen(){return this.popoverState.popover!==null}destroy(){this.destroyPopover(),this.unlockGrip(),this.drag.cleanup(),this.grid.removeEventListener(`mouseover`,this.boundMouseOver),this.grid.removeEventListener(`mouseleave`,this.boundMouseLeave),this.clearHideTimeout(),this.destroyGrips()}createGrips(){var e;let t=this.getColumnCount(),n=this.getRowCount(),r=(e=this.overlay)==null?this.grid:e;Array.from({length:t}).forEach((e,t)=>{let n=this.createGripElement(`col`,t);this.colGrips.push(n),r.appendChild(n)}),Array.from({length:n}).forEach((e,t)=>{let n=this.createGripElement(`row`,t);this.rowGrips.push(n),r.appendChild(n)}),this.positionGrips(),this.observeRowHeights(),this.attachScrollListener()}attachScrollListener(){this.overlay&&this.scrollContainer&&(this.boundScrollHandler=()=>this.positionGrips(),this.scrollContainer.addEventListener(`scroll`,this.boundScrollHandler))}detachScrollListener(){this.boundScrollHandler&&this.scrollContainer&&(this.scrollContainer.removeEventListener(`scroll`,this.boundScrollHandler),this.boundScrollHandler=null)}destroyGrips(){var e;(e=this.rowResizeObserver)==null||e.disconnect(),this.rowResizeObserver=null,this.detachScrollListener(),this.colGrips.forEach(e=>e.remove()),this.rowGrips.forEach(e=>e.remove()),this.colGrips=[],this.rowGrips=[],this.activeColGripIndex=-1,this.activeRowGripIndex=-1,this.isInsideTable=!1}createGripElement(e,t){let n=document.createElement(`div`);n.className=r.n(ar,or),n.setAttribute(Zn,``),n.setAttribute(e===`col`?Qn:$n,String(t)),n.setAttribute(`contenteditable`,`false`);let i=e===`col`?tr:rr,a=e===`col`?nr:ir,o=e===`col`?nr:rr;return n.style.width=`${i}px`,n.style.height=`${a}px`,n.style.transform=`translate(-50%, -50%)`,n.style.outline=`2px solid var(--blok-table-grip-outline, transparent)`,n.appendChild(Gt(e===`col`?`horizontal`:`vertical`)),n.addEventListener(`pointerdown`,this.boundPointerDown),n.addEventListener(`mouseenter`,()=>{this.overlay&&this.clearHideTimeout(),this.isGripInteractionLocked()||Kt(n,e)}),n.addEventListener(`mouseleave`,()=>{this.isGripInteractionLocked()||(qt(n,e,o),this.overlay&&this.scheduleHideAll())}),n}positionGrips(){let e=this.grid.querySelectorAll(`[${I}]`);if(!e[0])return;let t=Bn(this.grid),n=this.overlay&&this.scrollContainer?this.scrollContainer.scrollLeft:0,r=this.overlay&&this.scrollContainer?this.scrollContainer.clientWidth:1/0;this.colGrips.forEach((e,i)=>{if(i+1>=t.length)return;let a=(t[i]+t[i+1])/2-n,o=e.style;o.top=`${-1/2}px`,o.left=`${a}px`,this.overlay&&(o.visibility=a<0||a>r?`hidden`:``)}),this.rowGrips.forEach((t,n)=>{if(n>=e.length)return;let r=e[n],i=this.grid.querySelectorAll(`[${R}="${n}"]`),a=Array.from(i).reduce((e,t)=>{let n=t,r=e===null?0:e.rowSpan||1;return(n.rowSpan||1)>r?n:e},null);if((a===null?1:a.rowSpan||1)>1&&a!==null){var o;let e=((o=this.overlay)==null?this.grid:o).getBoundingClientRect(),n=a.getBoundingClientRect(),r=n.top-e.top+n.height/2,i=t.style;i.left=`${-1/2}px`,i.top=`${r}px`}else{let e=r.offsetTop+r.offsetHeight/2,n=t.style;n.left=`${-1/2}px`,n.top=`${e}px`}})}observeRowHeights(){var e;(e=this.rowResizeObserver)==null||e.disconnect(),this.rowResizeObserver=new ResizeObserver(()=>{this.positionGrips()}),this.grid.querySelectorAll(`[${I}]`).forEach(e=>{var t;(t=this.rowResizeObserver)==null||t.observe(e)})}isGripInteractionLocked(){return this.popoverState.popover!==null||this.lockedGrip!==null}handleMouseOver(e){if(this.isGripInteractionLocked())return;let t=e.target.closest(`[${L}]`);if(!t)return;this.clearHideTimeout();let n=this.getCellPosition(t);n&&(this.showColGrip(n.col),this.showRowGrip(n.row),this.isInsideTable=!0)}handleMouseLeave(){this.isGripInteractionLocked()||this.scheduleHideAll()}getCellPosition(e){let t=e.getAttribute(R),n=e.getAttribute(z);if(t===null||n===null)return null;let r=parseInt(t,10),i=parseInt(n,10);return isNaN(r)||isNaN(i)?null:{row:r,col:i}}setGripsDisplay(e){let t=e?``:`none`;[...this.colGrips,...this.rowGrips].forEach(n=>{let r=n;!e&&n===this.popoverState.grip||(r.style.display=t)})}hideAllGrips(){this.clearHideTimeout(),this.hideColGrip(),this.hideRowGrip(),this.isInsideTable=!1}showColGrip(e){this.activeColGripIndex!==e&&(this.hideColGrip(),this.activeColGripIndex=e,this.applyVisibleClasses(this.colGrips[e]))}hideColGrip(){this.activeColGripIndex>=0&&this.activeColGripIndex<this.colGrips.length&&this.applyIdleClasses(this.colGrips[this.activeColGripIndex]),this.activeColGripIndex=-1}showRowGrip(e){this.activeRowGripIndex!==e&&(this.hideRowGrip(),this.activeRowGripIndex=e,this.applyVisibleClasses(this.rowGrips[e]))}hideRowGrip(){this.activeRowGripIndex>=0&&this.activeRowGripIndex<this.rowGrips.length&&this.applyIdleClasses(this.rowGrips[this.activeRowGripIndex]),this.activeRowGripIndex=-1}applyVisibleClasses(e){let t=e,n=t.hasAttribute(Qn);Ht(t,n?`col`:`row`,n?nr:rr),this.isInsideTable&&(t.style.transition=`none`),t.className=r.n(ar,sr),t.setAttribute(`data-blok-table-grip-visible`,``),this.isInsideTable&&(t.offsetHeight,t.style.transition=``);let i=t.querySelector(`svg`);i&&(i.classList.remove(`text-white`,`opacity-100`),i.classList.add(`text-gray-400`,`opacity-0`))}applyActiveClasses(e){Object.assign(e,{className:r.n(ar,cr)}),e.setAttribute(`data-blok-table-grip-visible`,``);let t=e.querySelector(`svg`);t&&(t.classList.remove(`text-gray-400`,`opacity-0`),t.classList.add(`text-white`,`opacity-100`))}hideAllGripsExcept(e){[...this.colGrips,...this.rowGrips].forEach(t=>{t!==e&&this.applyIdleClasses(t)})}applyIdleClasses(e){let t=e,n=t.hasAttribute(Qn),i=n?`col`:`row`,a=n?nr+12:rr+12;this.isInsideTable&&(t.style.transition=`none`),Ht(t,i,a),t.className=r.n(ar,or),t.removeAttribute(`data-blok-table-grip-visible`);let o=t.querySelector(`svg`);o&&(o.classList.add(`opacity-0`),o.classList.remove(`opacity-100`)),this.isInsideTable&&(t.offsetHeight,t.style.transition=``)}handleDragStateChange(e,t){[...this.colGrips,...this.rowGrips].forEach(t=>{let n=t;n.style.display=e?`none`:``})}scheduleHideAll(){this.hideTimeout=setTimeout(()=>{this.hideColGrip(),this.hideRowGrip(),this.isInsideTable=!1,this.hideTimeout=null},er)}clearHideTimeout(){this.hideTimeout!==null&&(clearTimeout(this.hideTimeout),this.hideTimeout=null)}handlePointerDown(e){let t=e.target.closest(`[${Zn}]`);if(!t)return;e.preventDefault(),e.stopPropagation();let n=this.detectGripType(t);n&&this.drag.beginTracking(n.type,n.index,e.clientX,e.clientY).then(e=>{e||this.openPopover(n.type,n.index)})}detectGripType(e){let t=e.getAttribute(Qn);if(t!==null)return{type:`col`,index:Number(t)};let n=e.getAttribute($n);return n===null?null:{type:`row`,index:Number(n)}}openPopover(e,t){var n,r;this.popoverState=Xn(e,t,{col:this.colGrips,row:this.rowGrips},{getColumnCount:this.getColumnCount,getRowCount:this.getRowCount,isHeadingRow:this.isHeadingRow,isHeadingColumn:this.isHeadingColumn,onAction:this.onAction,i18n:this.i18n},{clearHideTimeout:()=>this.clearHideTimeout(),hideAllGripsExcept:e=>this.hideAllGripsExcept(e),applyActiveClasses:e=>this.applyActiveClasses(e),applyVisibleClasses:e=>this.applyVisibleClasses(e),scheduleHideAll:()=>this.scheduleHideAll(),destroyPopover:()=>this.destroyPopover(),onGripPopoverClose:this.onGripPopoverClose}),(n=this.popoverState.popover)==null||n.show(),(r=this.onGripClick)==null||r.call(this,e,t)}destroyPopover(){if(this.popoverState.popover!==null){let e=this.popoverState.popover;this.popoverState={popover:null,grip:null},e.destroy()}}},ur=`data-blok-table-corner-drag`,dr=5,fr=class{constructor(e){var t;this.dragState=null,this.wrapper=e.wrapper,this.gridEl=e.gridEl,this.getTableSize=e.getTableSize,this.onAddRow=e.onAddRow,this.onAddColumn=e.onAddColumn,this.onRemoveLastRow=e.onRemoveLastRow,this.onRemoveLastColumn=e.onRemoveLastColumn,this.onDragStart=e.onDragStart,this.onDragEnd=e.onDragEnd,this.canRemoveLastRow=e.canRemoveLastRow,this.canRemoveLastColumn=e.canRemoveLastColumn,this.onClickAdd=(t=e.onClickAdd)==null?null:t,this.hitZone=document.createElement(`div`),this.hitZone.setAttribute(ur,``),this.hitZone.setAttribute(`contenteditable`,`false`),this.hitZone.style.position=`absolute`,this.hitZone.style.width=`36px`,this.hitZone.style.height=`36px`,this.hitZone.style.cursor=`nwse-resize`,this.hitZone.style.zIndex=`2`,this.hitZone.style.pointerEvents=`auto`,this.hitZone.style.bottom=`-36px`,this.hitZone.style.right=`-16px`,this.boundMouseEnter=this.handleMouseEnter.bind(this),this.boundMouseLeave=this.handleMouseLeave.bind(this),this.boundPointerDown=this.handlePointerDown.bind(this),this.boundPointerMove=this.handlePointerMove.bind(this),this.boundPointerUp=this.handlePointerUp.bind(this),this.hitZone.addEventListener(`mouseenter`,this.boundMouseEnter),this.hitZone.addEventListener(`mouseleave`,this.boundMouseLeave),this.hitZone.addEventListener(`pointerdown`,this.boundPointerDown),this.wrapper.appendChild(this.hitZone)}updateTooltip(){let e=this.getTableSize();t.sr(this.hitZone,`${e.cols}\u00D7${e.rows}`,{placement:`bottom`})}handleMouseEnter(){this.updateTooltip()}handleMouseLeave(){this.dragState===null&&t.ar()}measureUnitHeight(){let e=this.gridEl.querySelectorAll(`[data-blok-table-row]`),t=e[e.length-1];return(t==null?void 0:t.offsetHeight)||30}measureUnitWidth(){let e=this.gridEl.querySelector(`[data-blok-table-row]`);if(!e)return 100;let t=e.querySelectorAll(`[data-blok-table-cell]`),n=t[t.length-1];return(n==null?void 0:n.offsetWidth)||100}handlePointerDown(e){this.dragState={startX:e.clientX,startY:e.clientY,unitWidth:this.measureUnitWidth(),unitHeight:this.measureUnitHeight(),addedRows:0,addedCols:0,pointerId:e.pointerId,didDrag:!1},this.updateTooltip(),this.hitZone.setPointerCapture(e.pointerId),this.hitZone.addEventListener(`pointermove`,this.boundPointerMove),this.hitZone.addEventListener(`pointerup`,this.boundPointerUp)}handlePointerMove(e){if(this.dragState===null)return;let t=e.clientX-this.dragState.startX,n=e.clientY-this.dragState.startY;if(!this.dragState.didDrag){if(Math.sqrt(t*t+n*n)<dr)return;this.dragState.didDrag=!0,document.body.style.cursor=`nwse-resize`,document.body.style.userSelect=`none`,this.onDragStart()}let{unitHeight:r,unitWidth:i}=this.dragState,a=Math.trunc(n/r),o=Math.trunc(t/i);for(;this.dragState.addedRows<a;)this.onAddRow(),this.dragState.addedRows++;for(;this.dragState.addedRows>a&&this.canRemoveLastRow();)this.onRemoveLastRow(),this.dragState.addedRows--;for(;this.dragState.addedCols<o;)this.onAddColumn(),this.dragState.addedCols++;for(;this.dragState.addedCols>o&&this.canRemoveLastColumn();)this.onRemoveLastColumn(),this.dragState.addedCols--;this.updateTooltip()}handlePointerUp(e){if(this.dragState===null)return;let{didDrag:n,pointerId:r}=this.dragState;this.dragState=null,t.ar(),this.hitZone.releasePointerCapture(r),this.hitZone.removeEventListener(`pointermove`,this.boundPointerMove),this.hitZone.removeEventListener(`pointerup`,this.boundPointerUp),n?(document.body.style.cursor=``,document.body.style.userSelect=``,this.onDragEnd()):this.onClickAdd?this.onClickAdd():(this.onAddRow(),this.onAddColumn())}setDisplay(e){this.hitZone.style.display=e?``:`none`}setInteractive(e){this.hitZone.style.pointerEvents=e?`auto`:`none`}destroy(){var e;this.hitZone.removeEventListener(`mouseenter`,this.boundMouseEnter),this.hitZone.removeEventListener(`mouseleave`,this.boundMouseLeave),this.hitZone.removeEventListener(`pointerdown`,this.boundPointerDown),this.hitZone.removeEventListener(`pointermove`,this.boundPointerMove),this.hitZone.removeEventListener(`pointerup`,this.boundPointerUp),(e=this.dragState)!=null&&e.didDrag&&(document.body.style.cursor=``,document.body.style.userSelect=``),this.dragState=null,t.ar(),this.hitZone.remove()}},pr=`data-blok-table-haze`,mr=`data-blok-table-haze-visible`,hr=1,gr=[`absolute`,`top-0`,`bottom-0`,`w-12`,`pointer-events-none`,`opacity-0`,`transition-opacity`,`duration-150`,`z-1`],_r=[`left-0`,`bg-linear-to-r`,`from-white/80`,`to-transparent`],vr=[`right-5`,`bg-linear-to-l`,`from-white/80`,`to-transparent`],yr=class{constructor(){this.leftHaze=null,this.rightHaze=null,this.scrollContainer=null,this.boundOnScroll=null,this.ticking=!1}init(e,t){this.scrollContainer=t,this.leftHaze=this.createHazeElement(`left`),this.rightHaze=this.createHazeElement(`right`),e.appendChild(this.leftHaze),e.appendChild(this.rightHaze),this.boundOnScroll=()=>{this.ticking||(requestAnimationFrame(()=>{this.syncVisibility(),this.ticking=!1}),this.ticking=!0)},t.addEventListener(`scroll`,this.boundOnScroll,{passive:!0}),this.syncVisibility()}update(){this.syncVisibility()}destroy(){var e,t;this.boundOnScroll&&this.scrollContainer&&this.scrollContainer.removeEventListener(`scroll`,this.boundOnScroll),(e=this.leftHaze)==null||e.remove(),(t=this.rightHaze)==null||t.remove(),this.leftHaze=null,this.rightHaze=null,this.scrollContainer=null,this.boundOnScroll=null,this.ticking=!1}createHazeElement(e){let t=document.createElement(`div`);return t.setAttribute(pr,e),t.setAttribute(`aria-hidden`,`true`),t.classList.add(...gr,...e===`left`?_r:vr),t}syncVisibility(){let e=this.scrollContainer;if(!e)return;let{overflowX:t}=getComputedStyle(e);if(!(t===`auto`||t===`scroll`)){this.setVisible(this.leftHaze,!1),this.setVisible(this.rightHaze,!1);return}let{scrollLeft:n,scrollWidth:r,clientWidth:i}=e,a=r-i;this.setVisible(this.leftHaze,n>hr),this.setVisible(this.rightHaze,a>hr&&n<a-hr)}setVisible(e,t){e&&(t?e.setAttribute(mr,``):e.removeAttribute(mr))}},br=3,xr=3,Sr=[`my-2`,`pr-5`],Cr=[`relative`,`mb-7`,`after:content-[""]`,`after:absolute`,`after:-bottom-10`,`after:left-0`,`after:right-0`,`after:h-10`,`after:pointer-events-none`],wr=class{constructor({data:e,config:n,api:r,readOnly:i,block:a}){this.initialContent=null,this.resize=null,this.addControls=null,this.rowColControls=null,this.cellBlocks=null,this.cellSelection=null,this.cornerDrag=null,this.scrollHaze=null,this.element=null,this.gridElement=null,this.scrollContainer=null,this.gripOverlay=null,this.pendingHighlight=null,this.isNewTable=!1,this.unregisterRestrictedTools=null,this.gridPasteCleanup=null,this.keyboardNavCleanup=null,this.setDataGeneration=0,this.structuralOpDepth=0,this.api=r,this.readOnly=i,this.config=n==null?{}:n;let o=vn(e,this.config);this.initialContent=o.content,this.grid=new At({readOnly:i}),this.model=new En(o),this.blockId=a==null?void 0:a.id,this.config.restrictedTools!==void 0&&(this.unregisterRestrictedTools=t.Pr(this.config.restrictedTools))}runStructuralOp(e,t=!1){this.structuralOpDepth++;try{return e()}finally{this.structuralOpDepth--;let e=this.structuralOpDepth===0;if(e&&t){var n;(n=this.cellBlocks)==null||n.discardDeferredEvents()}if(e&&!t){var r;(r=this.cellBlocks)==null||r.flushDeferredEvents()}}}runTransactedStructuralOp(e,t=!1){if(!this.api.blocks.transact)return this.runStructuralOp(e,t);let n={current:void 0};return this.api.blocks.transact(()=>{n.current=this.runStructuralOp(e,t)}),n.current}teardownSubsystems(){var e,t,n,r,i,a,o,s;(e=this.resize)==null||e.destroy(),this.resize=null,(t=this.addControls)==null||t.destroy(),this.addControls=null,(n=this.cornerDrag)==null||n.destroy(),this.cornerDrag=null,(r=this.rowColControls)==null||r.destroy(),this.rowColControls=null,(i=this.cellSelection)==null||i.destroy(),this.cellSelection=null,(a=this.scrollHaze)==null||a.destroy(),this.scrollHaze=null,(o=this.gridPasteCleanup)==null||o.call(this),this.gridPasteCleanup=null,(s=this.keyboardNavCleanup)==null||s.call(this),this.keyboardNavCleanup=null}rebuildTableBody(){let e=this.gridElement;if(!e)return;let t=e.querySelector(`tbody`);if(!t)return;let n=new Map;t.querySelectorAll(`[data-blok-id]`).forEach(e=>{let t=e.getAttribute(`data-blok-id`);t&&n.set(t,e)});let r=this.grid.createGridFromModel(this.model).querySelector(`tbody`);if(!r)return;let i=this.model.snapshot().content;this.mountBlockHoldersInNewTbody(i,r,n),t.replaceWith(r)}mountBlockHoldersInNewTbody(e,t,n){let r=new Set;e.forEach((e,i)=>{e.forEach((e,a)=>{if(typeof e==`string`||e.mergedInto)return;let o=t.querySelector(`[${R}="${i}"][${z}="${a}"]`);if(!o)return;let s=o.querySelector(`[${V}]`);s&&e.blocks.forEach(e=>{let t=n.get(e);t&&!r.has(e)&&(s.appendChild(t),r.add(e))})})})}modelHasMerges(){return this.model.snapshot().content.some(e=>e.some(e=>{var t,n;return typeof e!=`string`&&(((t=e.colspan)==null?1:t)>1||((n=e.rowspan)==null?1:n)>1)}))}createFlatGrid(){var e,t;let n=((e=this.initialContent)==null?void 0:e.length)||this.config.rows||br,r=((t=this.initialContent)==null?void 0:t.reduce((e,t)=>{var n;return Math.max(e,(n=t==null?void 0:t.length)==null?0:n)},0))||this.config.cols||xr;return this.grid.createGrid(n,r,this.model.colWidths)}initSubsystems(e){this.initResize(e),this.initAddControls(e),this.initCornerDrag(e),this.initRowColControls(e),this.initCellSelection(e),this.initGridPasteListener(e),this.initScrollHaze()}static get toolbox(){return{icon:t._n,titleKey:`tools.table.title`,searchTerms:[`table`,`grid`,`spreadsheet`],searchTermKeys:[`table`,`grid`,`spreadsheet`]}}static get isReadOnlySupported(){return!0}static get enableLineBreaks(){return!0}static get pasteConfig(){return{tags:[`TABLE`,`TR`,{TH:{style:!0}},{TD:{style:!0}}]}}static get sanitize(){return{content:{br:!0,b:!0,i:!0,strong:!0,em:!0,mark:e=>{let n=e.style,r=Array.from({length:n.length},(e,t)=>n.item(t));for(let e of r)t.g.has(e)||n.removeProperty(e);return n.length>0?{style:!0}:{}},a:{href:!0,target:`_blank`,rel:`nofollow`},input:{type:!0,checked:!0}}}}ensureScrollContainer(){var e;if(this.scrollContainer)return this.scrollContainer;let t=document.createElement(`div`);t.setAttribute(`data-blok-table-scroll`,``);let n=this.gridElement;return n&&this.element&&(this.element.insertBefore(t,n),t.appendChild(n)),this.scrollContainer=t,(e=this.addControls)==null||e.attachScrollContainer(t),t}render(){var e,n,i,a;let o=document.createElement(`div`);o.className=r.n(Sr,!this.readOnly&&Cr),o.setAttribute(t.hi.tool,`table`),this.readOnly&&o.setAttribute(`data-blok-table-readonly`,``),this.isNewTable=((e=(n=this.initialContent)==null?void 0:n.length)==null?0:e)===0;let s=((i=(a=this.initialContent)==null?void 0:a.length)==null?0:i)>0,c=s&&this.modelHasMerges(),l=c?this.grid.createGridFromModel(this.model):this.createFlatGrid();if(s&&!c){var u;this.grid.fillGrid(l,(u=this.initialContent)==null?[]:u)}if(this.model.colWidths&&rn(l,this.model.colWidths),this.gridElement=l,this.model.colWidths||!this.readOnly){let e=document.createElement(`div`);e.setAttribute(`data-blok-table-scroll`,``);let t=this.model.colWidths?bn:[];e.classList.add(...t),e.appendChild(l),o.appendChild(e),this.scrollContainer=e}else o.appendChild(l),this.scrollContainer=null;if(!this.readOnly){let e=document.createElement(`div`);e.setAttribute(`data-blok-table-grip-overlay`,``),e.style.position=`absolute`,e.style.inset=`0`,e.style.pointerEvents=`none`,e.style.zIndex=`3`,o.appendChild(e),this.gripOverlay=e}return this.element=o,this.model.withHeadings&&Sn(this.gridElement,this.model.withHeadings),this.model.withHeadingColumn&&W(this.gridElement,this.model.withHeadingColumn),this.readOnly||(this.initCellBlocks(l),this.keyboardNavCleanup=yn(l,this.cellBlocks)),o}rendered(){if(!this.element||this.initialContent===null)return;let e=this.gridElement;if(!e)return;let t=this.initialContent;if(this.initialContent=null,this.readOnly){var r;_n(e,t,this.api,(r=this.blockId)==null?``:r);let n=this.model.snapshot();Cn(e,n.content),wn(e,n.content),this.initScrollHaze();return}if(this.runTransactedStructuralOp(()=>{var r,i;let a=(r=(i=this.cellBlocks)==null?void 0:i.initializeCells(t))==null?t:r,o=this.isNewTable&&a.length===0?Array.from(e.querySelectorAll(`[${I}]`),e=>{let t=e.querySelectorAll(`[${L}]`).length;return Array.from({length:t},()=>({blocks:[]}))}):a;this.model.replaceAll(n.t(n.t({},this.model.snapshot()),{},{content:o})),this.isNewTable&&U(e,this.cellBlocks),this.removeGhostChildren()},!0),this.model.initialColWidth===void 0){var i;let t=(i=this.model.colWidths)==null?H(e):i;this.model.setInitialColWidth(t.length>0?mn(t):void 0)}this.initSubsystems(e);let a=this.model.snapshot();if(Cn(e,a.content),wn(e,a.content),this.isNewTable){var o;(o=this.cellSelection)==null||o.selectRange({minRow:0,maxRow:0,minCol:0,maxCol:0})}}setReadOnly(e){let t=this.element,n=this.gridElement;if(!(!t||!n))if(this.readOnly=e,e){var r,i;this.teardownSubsystems(),(r=this.cellBlocks)==null||r.destroy(),this.cellBlocks=null,this.gripOverlay&&(this.gripOverlay.remove(),this.gripOverlay=null),Cr.forEach(e=>t.classList.remove(e)),t.setAttribute(`data-blok-table-readonly`,``),_n(n,this.model.snapshot().content,this.api,(i=this.blockId)==null?``:i)}else{t.removeAttribute(`data-blok-table-readonly`),Cr.forEach(e=>t.classList.add(e));let e=document.createElement(`div`);e.setAttribute(`data-blok-table-grip-overlay`,``),e.style.position=`absolute`,e.style.inset=`0`,e.style.pointerEvents=`none`,e.style.zIndex=`3`,t.appendChild(e),this.gripOverlay=e,this.initCellBlocks(n),this.keyboardNavCleanup=yn(n,this.cellBlocks),this.initSubsystems(n)}}removeGhostChildren(){let e=this.blockId;if(e===void 0)return;let t=this.api.blocks.getChildren(e).filter(e=>this.model.findCellForBlock(e.id)===null).map(e=>({id:e.id,index:this.api.blocks.getBlockIndex(e.id)})).filter(e=>e.index!==void 0).sort((e,t)=>t.index-e.index);for(let{index:e}of t)this.api.blocks.delete(e)}save(e){var t;let r=this.model.snapshot(),i=(t=this.blockId)==null?``:t,a=this.gridElement;return r.content=r.content.map((e,t)=>e.map((e,r)=>{if(!B(e))return e;let o=e.blocks.filter(e=>{var t,n,r;let a=(t=(n=this.api.blocks).getById)==null?void 0:t.call(n,e);return a!=null&&((r=a.parentId)==null?``:r)===i});if(o.length===0&&a){let o=a.querySelector(`[${R}="${t}"][${z}="${r}"]`),s=o==null?void 0:o.querySelector(`[${V}]`),c=s?Array.from(s.querySelectorAll(`[data-blok-id]`)).map(e=>{var t;return(t=e.getAttribute(`data-blok-id`))==null?``:t}).filter(e=>{var t,n,r;if(!e)return!1;let a=(t=(n=this.api.blocks).getById)==null?void 0:t.call(n,e);return a!=null&&((r=a.parentId)==null?``:r)===i}):[];if(c.length>0)return n.t(n.t({},e),{},{blocks:c})}return n.t(n.t({},e),{},{blocks:o})})),r}validate(e){return e.content.length>0}setData(e){var t,r,i,a,o;this.setDataGeneration++;let s=this.setDataGeneration,c=vn(n.t(n.t({},this.model.snapshot()),e),this.config);this.initialContent=c.content,this.model.replaceAll(c),this.api.blocks.isSyncingFromYjs||this.runStructuralOp(()=>{var e;(e=this.cellBlocks)==null||e.deleteAllBlocks()},!0),(t=this.cellBlocks)==null||t.destroy();let l=this.element;if(!(l!=null&&l.parentNode)||s!==this.setDataGeneration)return;let u=(r=(i=this.cellSelection)==null?void 0:i.getSelectedRange())==null?null:r,d=(a=(o=this.rowColControls)==null?void 0:o.getVisibleGripIndices())==null?null:a;this.teardownSubsystems();let f=this.render();l.parentNode.replaceChild(f,l);let p=this.gridElement;if(!p)return;if(this.readOnly){let e=this.model.snapshot();Cn(p,e.content),wn(p,e.content);return}if(s!==this.setDataGeneration)return;let m=this.api.blocks.isSyncingFromYjs;if(this.runStructuralOp(()=>{var e,t,r,i;let a=(e=(t=(r=this.cellBlocks)==null?void 0:r.initializeCells((i=this.initialContent)==null?[]:i))==null?this.initialContent:t)==null?[]:e;if(s===this.setDataGeneration){if(this.api.blocks.isSyncingFromYjs&&a.length===0&&p){let e=Array.from(p.querySelectorAll(`[${I}]`),e=>{let t=e.querySelectorAll(`[${L}]`).length;return Array.from({length:t},()=>({blocks:[]}))});this.model.replaceAll(n.t(n.t({},this.model.snapshot()),{},{content:e}))}else this.model.replaceAll(n.t(n.t({},this.model.snapshot()),{},{content:a}));this.initialContent=null}},!0),s!==this.setDataGeneration)return;this.initSubsystems(p),u!==null&&this.cellSelection!==null&&this.cellSelection.selectRange(u),d!==null&&this.rowColControls!==null&&this.rowColControls.restoreVisibleGrips(d.col,d.row);let h=this.model.snapshot();if(Cn(p,h.content),wn(p,h.content),m){var g;(g=this.cellBlocks)==null||g.reclaimReferencedBlocks(),Promise.resolve().then(()=>{var e;s===this.setDataGeneration&&((e=this.cellBlocks)==null||e.reclaimReferencedBlocks())})}}onPaste(e){var r,i;let a=e.detail.data,o=a.querySelectorAll(`tr`),s=[],c=[];o.forEach(e=>{let n=e.querySelectorAll(`td, th`),r=[],i=[];n.forEach(e=>{var n;r.push(e.innerHTML);let a=(n=e.getAttribute(`style`))==null?``:n,o={},s=/background-color\s*:\s*([^;]+)/i.exec(a);s!=null&&s[1]&&(o.color=t.Ln(s[1].trim(),`bg`));let c=RegExp(`(?<![a-z-])color\\s*:\\s*([^;]+)`,`i`).exec(a);c!=null&&c[1]&&!t.y(c[1].trim())&&(o.textColor=t.Ln(c[1].trim(),`text`)),i.push(o)}),r.length>0&&(s.push(r),c.push(i))});let l=a.querySelector(`thead`)!==null,u=((r=o[0])==null?void 0:r.querySelector(`th`))!==null,d=l||u;this.initialContent=s,this.model.setWithHeadings(d),this.model.setWithHeadingColumn(!1),this.model.setColWidths(void 0),this.runStructuralOp(()=>{var e;(e=this.cellBlocks)==null||e.deleteAllBlocks()},!0),(i=this.cellBlocks)==null||i.destroy(),this.teardownSubsystems();let f=this.element;if(!(f!=null&&f.parentNode))return;let p=this.render();f.parentNode.replaceChild(p,f);let m=this.gridElement;if(!this.readOnly&&m){this.runStructuralOp(()=>{var e,t,r,i;let a=(e=(t=(r=this.cellBlocks)==null?void 0:r.initializeCells((i=this.initialContent)==null?[]:i))==null?this.initialContent:t)==null?[]:e;this.model.replaceAll(n.t(n.t({},this.model.snapshot()),{},{content:a})),this.initialContent=null,c.forEach((e,t)=>{e.forEach((e,n)=>{e.color!==void 0&&this.model.setCellColor(t,n,e.color),e.textColor!==void 0&&this.model.setCellTextColor(t,n,e.textColor)})})},!0),this.initSubsystems(m);let e=this.model.snapshot();Cn(m,e.content),wn(m,e.content)}}destroy(){var e,t;if((e=this.unregisterRestrictedTools)==null||e.call(this),this.unregisterRestrictedTools=null,!this.api.blocks.isSyncingFromYjs){var n;(n=this.cellBlocks)==null||n.deleteAllBlocks()}this.teardownSubsystems(),(t=this.cellBlocks)==null||t.destroy(),this.cellBlocks=null,this.gridElement=null,this.scrollContainer=null,this.element=null}deleteRowWithCleanup(e){let t=this.gridElement;t&&this.runTransactedStructuralOp(()=>{var n;let{blocksToDelete:r}=this.model.deleteRow(e);(n=this.cellBlocks)==null||n.deleteBlocks(r),this.grid.deleteRow(t,e)})}deleteColumnWithCleanup(e){let t=this.gridElement;t&&this.runTransactedStructuralOp(()=>{var n;let{blocksToDelete:r}=this.model.deleteColumn(e);(n=this.cellBlocks)==null||n.deleteBlocks(r),this.grid.deleteColumn(t,e)})}getBlockIdsInRow(e){return hn(this.element,this.cellBlocks,e)}getBlockIdsInColumn(e){return gn(this.element,this.cellBlocks,e)}initAddControls(e){var t;if((t=this.addControls)==null||t.destroy(),!this.element)return;let n={addedCols:0};this.addControls=new Et({wrapper:this.element,grid:e,i18n:this.api.i18n,getTableSize:()=>({rows:this.model.rows,cols:this.model.cols}),getNewColumnWidth:()=>{var t;let n=(t=this.model.colWidths)==null?H(e):t;return this.model.initialColWidth===void 0?pn(n):Math.round(this.model.initialColWidth/2*100)/100},onAddRow:()=>{this.runTransactedStructuralOp(()=>{var t,n;this.grid.addRow(e),this.model.addRow(),U(e,this.cellBlocks),Sn(this.gridElement,this.model.withHeadings),W(this.gridElement,this.model.withHeadingColumn),this.initResize(e),(t=this.addControls)==null||t.syncRowButtonWidth(),(n=this.rowColControls)==null||n.refresh()})},onAddColumn:()=>{this.runTransactedStructuralOp(()=>{var t,n,r;let i=(t=this.model.colWidths)==null?H(e):t,a=this.model.initialColWidth===void 0?pn(i):Math.round(this.model.initialColWidth/2*100)/100;this.grid.addColumn(e,void 0,i,a),this.model.addColumn(void 0,a),this.model.setColWidths([...i,a]),U(e,this.cellBlocks),W(this.gridElement,this.model.withHeadingColumn),this.initResize(e),(n=this.rowColControls)==null||n.refresh(),this.scrollContainer&&(this.scrollContainer.scrollLeft=this.scrollContainer.scrollWidth),(r=this.addControls)==null||r.syncRowButtonWidth()})},onDragStart:()=>{var e,t;this.resize&&(this.resize.enabled=!1),(e=this.rowColControls)==null||e.hideAllGrips(),(t=this.rowColControls)==null||t.setGripsDisplay(!1)},onDragAddRow:()=>{this.runTransactedStructuralOp(()=>{this.grid.addRow(e),this.model.addRow(),U(e,this.cellBlocks),Sn(this.gridElement,this.model.withHeadings),W(this.gridElement,this.model.withHeadingColumn)})},onDragRemoveRow:()=>{this.runTransactedStructuralOp(()=>{let t=this.grid.getRowCount(e);if(t>1&&sn(e,t-1)){var n;let{blocksToDelete:r}=this.model.deleteRow(t-1);(n=this.cellBlocks)==null||n.deleteBlocks(r),this.grid.deleteRow(e,t-1)}})},onDragAddCol:()=>{this.runTransactedStructuralOp(()=>{var t;let r=(t=this.model.colWidths)==null?H(e):t,i=this.model.initialColWidth===void 0?pn(r):Math.round(this.model.initialColWidth/2*100)/100,a=[...r,i];this.grid.addColumn(e,void 0,r,i),this.model.addColumn(void 0,i),this.model.setColWidths(a),rn(e,a),U(e,this.cellBlocks),W(this.gridElement,this.model.withHeadingColumn),this.initResize(e),n.addedCols++,this.scrollContainer&&(this.scrollContainer.scrollLeft=this.scrollContainer.scrollWidth)})},onDragRemoveCol:()=>{this.runTransactedStructuralOp(()=>{var t;let r=this.grid.getColumnCount(e);if(r<=1||!cn(e,r-1))return;let{blocksToDelete:i}=this.model.deleteColumn(r-1);(t=this.cellBlocks)==null||t.deleteBlocks(i),this.grid.deleteColumn(e,r-1);let a=this.model.colWidths;a&&rn(e,a),this.initResize(e),n.addedCols--})},onDragEnd:()=>{var t,r;this.initResize(e),(t=this.rowColControls)==null||t.refresh(),this.scrollContainer&&(this.scrollContainer.scrollLeft=n.addedCols>0?this.scrollContainer.scrollWidth:0),(r=this.addControls)==null||r.syncRowButtonWidth(),n.addedCols=0}}),this.scrollContainer&&this.addControls.attachScrollContainer(this.scrollContainer)}initCornerDrag(e){var t;(t=this.cornerDrag)==null||t.destroy(),this.element&&(this.cornerDrag=new fr({wrapper:this.element,gridEl:e,onAddRow:()=>{this.runStructuralOp(()=>{this.grid.addRow(e),this.model.addRow(),U(e,this.cellBlocks),Sn(this.gridElement,this.model.withHeadings),W(this.gridElement,this.model.withHeadingColumn)})},onAddColumn:()=>{this.runStructuralOp(()=>{var t;let n=(t=this.model.colWidths)==null?H(e):t,r=this.model.initialColWidth===void 0?pn(n):Math.round(this.model.initialColWidth/2*100)/100,i=[...n,r];this.grid.addColumn(e,void 0,n,r),this.model.addColumn(void 0,r),this.model.setColWidths(i),rn(e,i),xn(this.ensureScrollContainer()),U(e,this.cellBlocks),W(this.gridElement,this.model.withHeadingColumn)})},onRemoveLastRow:()=>{this.runStructuralOp(()=>{var t;let n=this.grid.getRowCount(e);if(n<=1)return;let{blocksToDelete:r}=this.model.deleteRow(n-1);(t=this.cellBlocks)==null||t.deleteBlocks(r),this.grid.deleteRow(e,n-1)})},onRemoveLastColumn:()=>{this.runStructuralOp(()=>{var t;let n=this.grid.getColumnCount(e);if(n<=1)return;let{blocksToDelete:r}=this.model.deleteColumn(n-1);(t=this.cellBlocks)==null||t.deleteBlocks(r),this.grid.deleteColumn(e,n-1);let i=this.model.colWidths;i&&rn(e,i)})},onDragStart:()=>{var e,t,n;this.resize&&(this.resize.enabled=!1),(e=this.rowColControls)==null||e.hideAllGrips(),(t=this.rowColControls)==null||t.setGripsDisplay(!1),(n=this.addControls)==null||n.setDisplay(!1)},onDragEnd:()=>{var t,n,r;this.initResize(e),(t=this.rowColControls)==null||t.refresh(),(n=this.addControls)==null||n.setDisplay(!0),(r=this.addControls)==null||r.syncRowButtonWidth()},getTableSize:()=>({rows:this.model.rows,cols:this.model.cols}),canRemoveLastRow:()=>this.model.rows>1&&sn(e,this.model.rows-1),canRemoveLastColumn:()=>this.model.cols>1&&cn(e,this.model.cols-1),onClickAdd:()=>{this.runTransactedStructuralOp(()=>{var t,n,r;this.grid.addRow(e),this.model.addRow(),U(e,this.cellBlocks),Sn(this.gridElement,this.model.withHeadings),W(this.gridElement,this.model.withHeadingColumn);let i=(t=this.model.colWidths)==null?H(e):t,a=this.model.initialColWidth===void 0?pn(i):Math.round(this.model.initialColWidth/2*100)/100,o=[...i,a];this.grid.addColumn(e,void 0,i,a),this.model.addColumn(void 0,a),this.model.setColWidths(o),rn(e,o),U(e,this.cellBlocks),W(this.gridElement,this.model.withHeadingColumn),this.initResize(e),(n=this.rowColControls)==null||n.refresh(),(r=this.addControls)==null||r.syncRowButtonWidth()})}}))}initRowColControls(e){var t,n,r;(t=this.rowColControls)==null||t.destroy(),this.element&&(this.rowColControls=new lr({grid:e,overlay:(n=this.gripOverlay)==null?void 0:n,scrollContainer:(r=this.scrollContainer)==null?void 0:r,getColumnCount:()=>this.grid.getColumnCount(e),getRowCount:()=>this.grid.getRowCount(e),isHeadingRow:()=>this.model.withHeadings,isHeadingColumn:()=>this.model.withHeadingColumn,i18n:this.api.i18n,onAction:t=>this.handleRowColAction(e,t),onDragStateChange:e=>{var t,n;this.resize&&(this.resize.enabled=!e),(t=this.addControls)==null||t.setDisplay(!e),(n=this.cornerDrag)==null||n.setDisplay(!e),e&&this.api.toolbar.close({setExplicitlyClosed:!1})},onGripClick:(e,t)=>{if(e===`row`){var n;(n=this.cellSelection)==null||n.selectRow(t)}else{var r;(r=this.cellSelection)==null||r.selectColumn(t)}},onGripPopoverClose:()=>{if(this.pendingHighlight){var e;let{type:t,index:n}=this.pendingHighlight;this.pendingHighlight=null,(e=this.rowColControls)==null||e.setActiveGrip(t,n),requestAnimationFrame(()=>{if(t===`row`){var e;(e=this.cellSelection)==null||e.selectRow(n)}else{var r;(r=this.cellSelection)==null||r.selectColumn(n)}})}else{var t;(t=this.cellSelection)==null||t.clearActiveSelection()}}}))}handleRowColAction(e,t){let n=this.setDataGeneration;this.runTransactedStructuralOp(()=>{var r,i;if(n!==this.setDataGeneration||this.gridElement!==e)return;let a=this.model.colWidths,{blocksToDelete:o}=this.syncModelForAction(t),s=Ln(e,t,{grid:this.grid,data:{colWidths:a,withHeadings:this.model.withHeadings,withHeadingColumn:this.model.withHeadingColumn,initialColWidth:this.model.initialColWidth},cellBlocks:this.cellBlocks,blocksToDelete:o});if(n!==this.setDataGeneration||this.gridElement!==e)return;if(this.model.setColWidths(s.colWidths),this.model.setWithHeadings(s.withHeadings),this.model.setWithHeadingColumn(s.withHeadingColumn),this.pendingHighlight=s.pendingHighlight,Sn(this.gridElement,this.model.withHeadings),W(this.gridElement,this.model.withHeadingColumn),this.initResize(e),(r=this.addControls)==null||r.syncRowButtonWidth(),!(t.type===`toggle-heading`||t.type===`toggle-heading-column`)){var c;(c=this.rowColControls)==null||c.refresh()}if(!s.moveSelection)return;let{type:l,index:u}=s.moveSelection;if(l===`row`){var d;(d=this.cellSelection)==null||d.selectRow(u)}else{var f;(f=this.cellSelection)==null||f.selectColumn(u)}(i=this.rowColControls)==null||i.setActiveGrip(l,u)})}syncModelForAction(e){switch(e.type){case`insert-row-above`:this.model.addRow(e.index);break;case`insert-row-below`:this.model.addRow(e.index+1);break;case`insert-col-left`:this.model.addColumn(e.index);break;case`insert-col-right`:this.model.addColumn(e.index+1);break;case`move-row`:this.model.moveRow(e.fromIndex,e.toIndex);break;case`move-col`:this.model.moveColumn(e.fromIndex,e.toIndex);break;case`delete-row`:return this.model.deleteRow(e.index);case`delete-col`:return this.model.deleteColumn(e.index);case`toggle-heading`:case`toggle-heading-column`:break}return{}}initResize(e){var t,n;(t=this.resize)==null||t.destroy();let r=this.model.colWidths===void 0,i=(n=this.model.colWidths)==null?H(e):n;r||xn(this.ensureScrollContainer()),this.resize=new An(e,i,e=>{var t,n,r;this.model.setColWidths(e),xn(this.ensureScrollContainer()),(t=this.rowColControls)==null||t.positionGrips(),(n=this.addControls)==null||n.syncRowButtonWidth(),(r=this.scrollHaze)==null||r.update()},()=>{var e;(e=this.rowColControls)==null||e.hideAllGrips()},()=>{var e,t;(e=this.addControls)==null||e.syncRowButtonWidth(),(t=this.scrollHaze)==null||t.update()},r)}initCellBlocks(e){var t;this.cellBlocks=new jt({api:this.api,gridElement:e,tableBlockId:(t=this.blockId)==null?``:t,model:this.model,isStructuralOpActive:()=>this.structuralOpDepth>0})}handleCellCopy(e,n){let r=this.collectCellBlockData(e);if(r.length===0)return;let i=t.S(r);n.setData(`text/html`,t._(i)),n.setData(`text/plain`,t.v(i))}handleCellCopyViaButton(e){let n=this.collectCellBlockData(e);if(n.length===0)return;let r=t.S(n),i=t._(r),a=t.v(r),o=new Blob([i],{type:`text/html`}),s=new Blob([a],{type:`text/plain`});navigator.clipboard.write([new ClipboardItem({"text/html":o,"text/plain":s})])}handleCellColorChange(e,t,n){let r=this.gridElement;r&&this.runTransactedStructuralOp(()=>{for(let i of e){let e=an(r,i);e&&(n===`backgroundColor`?(this.model.setCellColor(e.row,e.col,t==null?void 0:t),i.style.backgroundColor=t==null?``:t):(this.model.setCellTextColor(e.row,e.col,t==null?void 0:t),i.style.color=t==null?``:t))}})}handleCellPlacementChange(e,t){let n=this.gridElement;n&&this.runTransactedStructuralOp(()=>{for(let r of e){let e=an(n,r);if(!e)continue;this.model.setCellPlacement(e.row,e.col,t===`top-left`?void 0:t);let i=r.querySelector(`[${V}]`);i&&(t===`top-left`?i.removeAttribute(`data-blok-cell-placement`):i.setAttribute(`data-blok-cell-placement`,t))}})}collectCellBlockData(e){return this.gridElement?e.map(e=>{var t,r,i;let a=parseInt((t=e.getAttribute(`data-blok-table-cell-row`))==null?`0`:t,10),o=parseInt((r=e.getAttribute(`data-blok-table-cell-col`))==null?`0`:r,10),s=e.querySelector(`[${V}]`),c=[];if(!s)return{row:a,col:o,blocks:c};s.querySelectorAll(`[data-blok-id]`).forEach(e=>{let t=e.getAttribute(`data-blok-id`);if(!t)return;let r=this.api.blocks.getBlockIndex(t);if(r===void 0)return;let i=this.api.blocks.getBlockByIndex(r);i&&c.push(n.t({tool:i.name,data:i.preservedData},Object.keys(i.preservedTunes).length>0?{tunes:i.preservedTunes}:{}))});let l=c.length===0?((i=s.innerHTML)==null?``:i).trim():``;c.length===0&&l.length>0&&c.push({tool:`paragraph`,data:{text:l}});let u=this.model.getCellColor(a,o),d=this.model.getCellTextColor(a,o);return n.t(n.t({row:a,col:o,blocks:c},u===void 0?{}:{color:u}),d===void 0?{}:{textColor:d})}):[]}initCellSelection(e){var t;(t=this.cellSelection)==null||t.destroy();let n=this.api.rectangleSelection;this.cellSelection=new nn({grid:e,rectangleSelection:n,i18n:this.api.i18n,isPopoverOpen:()=>{var e,t;return(e=(t=this.rowColControls)==null?void 0:t.isPopoverOpen)==null?!1:e},onPointerDragActiveChange:e=>{var t,n;(t=(n=this.api.blocks).setPointerDragActive)==null||t.call(n,e)},onSelectionActiveChange:e=>{var t,n,r;this.resize&&(this.resize.enabled=!e),(t=this.addControls)==null||t.setInteractive(!e),(n=this.cornerDrag)==null||n.setInteractive(!e),(r=this.rowColControls)==null||r.setGripsDisplay(!e)},onSelectionRangeChange:()=>{var e;(e=this.rowColControls)==null||e.setGripsDisplay(!0)},onClearContent:e=>{let t=this.cellBlocks;t&&this.runTransactedStructuralOp(()=>{let n=t.getBlockIdsFromCells(e);t.deleteBlocks(n);let r=this.gridElement;if(r)for(let t of e){let e=an(r,t);e&&(this.model.setCellColor(e.row,e.col,void 0),this.model.setCellTextColor(e.row,e.col,void 0),t.style.backgroundColor=``,t.style.color=``)}})},onCopy:(e,t)=>{this.handleCellCopy(e,t)},onCut:(e,t)=>{this.handleCellCopy(e,t)},onCopyViaButton:e=>{this.handleCellCopyViaButton(e)},onColorChange:(e,t,n)=>{this.handleCellColorChange(e,t,n)},onPlacementChange:(e,t)=>{this.handleCellPlacementChange(e,t)},getCellPlacement:(e,t)=>this.model.getCellPlacement(e,t),canMergeCells:e=>this.model.canMergeCells(e),onMergeCells:e=>{this.runTransactedStructuralOp(()=>{this.model.mergeCells(e),this.rebuildTableBody()})},isMergedCell:(e,t)=>this.model.isMergedCell(e,t),onSplitCell:(e,t)=>{this.runTransactedStructuralOp(()=>{this.model.splitCell(e,t),this.rebuildTableBody()})},getCellSpan:(e,t)=>this.model.getCellSpan(e,t)})}initScrollHaze(){var e;(e=this.scrollHaze)==null||e.destroy(),!(!this.element||!this.scrollContainer)&&(this.scrollHaze=new yr,this.scrollHaze.init(this.element,this.scrollContainer))}initGridPasteListener(e){let t=t=>{this.handleGridPaste(t,e)};e.addEventListener(`paste`,t),this.gridPasteCleanup=()=>{e.removeEventListener(`paste`,t)}}handleGridPaste(e,n){var r,i;if(this.readOnly||!e.clipboardData||e.defaultPrevented)return;let a=e.clipboardData.getData(`text/html`),o=t.b(a),s=o===null?t.x(a):null,c=o==null?s:o;if(!c||s!==null&&new DOMParser().parseFromString(a,`text/html`).querySelectorAll(`table`).length>1)return;let l=document.activeElement;if(!l)return;let u=l.closest(`[${L}]`);if(!u||!n.contains(u)||!u.closest(`[data-blok-table-row]`))return;if(c.rows===1&&c.cols===1){e.preventDefault(),e.stopPropagation(),this.insertSingleCellPayloadInline(c.cells[0][0]);return}e.preventDefault(),e.stopPropagation();let d=parseInt((r=u.getAttribute(`data-blok-table-cell-row`))==null?`0`:r,10),f=parseInt((i=u.getAttribute(`data-blok-table-cell-col`))==null?`0`:i,10);this.pastePayloadIntoCells(n,c,d,f)}insertSingleCellPayloadInline(e){let t=e.blocks.map(e=>typeof e.data.text==`string`?e.data.text:``).filter(Boolean).join(`<br>`);if(!t)return;let n=window.getSelection();if(!n||n.rangeCount===0)return;let r=n.getRangeAt(0);r.collapsed||r.deleteContents();let i=document.createDocumentFragment(),a=document.createElement(`div`);a.innerHTML=t,Array.from(a.childNodes).forEach(e=>i.appendChild(e)),i.childNodes.length===0&&i.appendChild(new Text);let o=i.lastChild;r.insertNode(i);let s=document.createRange(),c=o.nodeType===Node.TEXT_NODE?o:o.firstChild;c!==null&&c.textContent!==null&&s.setStart(c,c.textContent.length),n.removeAllRanges(),n.addRange(s)}pastePayloadIntoCells(e,t,n,r){this.runTransactedStructuralOp(()=>{var i,a;this.expandGridForPaste(e,n+t.rows,r+t.cols);let o=e.querySelectorAll(`[${I}]`);Array.from({length:t.rows},(e,t)=>t).forEach(e=>{let i=o[n+e];if(!i)return;let a=i.querySelectorAll(`[${L}]`);Array.from({length:t.cols},(e,t)=>t).forEach(i=>{let o=a[r+i];if(o){var s,c,l,u;let a=t.cells[e][i];this.pasteCellPayload(o,a);let d=(s=(c=this.cellBlocks)==null?void 0:c.getBlockIdsFromCells([o]))==null?[]:s;this.model.setCellBlocks(n+e,r+i,d);let f=n+e,p=r+i;this.model.setCellColor(f,p,a.color),o.style.backgroundColor=(l=a.color)==null?``:l,this.model.setCellTextColor(f,p,a.textColor),o.style.color=(u=a.textColor)==null?``:u}})}),this.initResize(e),(i=this.addControls)==null||i.syncRowButtonWidth(),(a=this.rowColControls)==null||a.refresh()});let i=e.querySelectorAll(`[${I}]`)[n+t.rows-1],a=i==null?void 0:i.querySelectorAll(`[${L}]`)[r+t.cols-1];if(!a||!this.cellBlocks||!this.api.caret)return;let o=this.cellBlocks.getBlockIdsFromCells([a]),s=o[o.length-1];s!==void 0&&this.api.caret.setToBlock(s,`end`)}expandGridForPaste(e,t,n){let r=this.grid.getRowCount(e),i=this.grid.getColumnCount(e);Array.from({length:Math.max(0,t-r)}).forEach(()=>{this.grid.addRow(e),this.model.addRow(),U(e,this.cellBlocks),Sn(this.gridElement,this.model.withHeadings),W(this.gridElement,this.model.withHeadingColumn)}),Array.from({length:Math.max(0,n-i)}).forEach(()=>{var t;let n=(t=this.model.colWidths)==null?H(e):t,r=this.model.initialColWidth===void 0?pn(n):Math.round(this.model.initialColWidth/2*100)/100;this.grid.addColumn(e,void 0,n,r),this.model.addColumn(void 0,r),this.model.setColWidths([...n,r]),U(e,this.cellBlocks),W(this.gridElement,this.model.withHeadingColumn)})}pasteCellPayload(e,t){if(this.cellBlocks){let t=this.cellBlocks.getBlockIdsFromCells([e]);this.cellBlocks.deleteBlocks(t)}let n=e.querySelector(`[${V}]`);if(n){if(t.blocks.length===0){var r;(r=this.cellBlocks)==null||r.ensureCellHasBlock(e);return}for(let e of t.blocks){var i;let t=this.api.blocks.insert(e.tool,e.data,{},this.api.blocks.getBlocksCount(),!1);n.appendChild(t.holder),this.api.blocks.setBlockParent(t.id,(i=this.blockId)==null?``:i)}}}},Tr=e=>{let t=document.createElement(`div`);t.innerHTML=e.trim();let n=document.createDocumentFragment();return n.append(...Array.from(t.childNodes)),n},Er=(e,n,r,i)=>{if(!n)return e;let a=r();return{text:a?t.Vr(a.innerHTML):e.text,isOpen:i}},Dr=(e,t)=>{let{data:n,getContentElement:r}=e;n.text+=t.text;let i=r();if(i&&t.text){let n=e.parseHTML(t.text);i.appendChild(n),i.normalize()}},Or=(e,t,r)=>{let i=r();if(!i)return{newData:e,inPlace:!1};let a=n.t(n.t({},e),t);return typeof t.text==`string`&&(i.innerHTML=t.text),{newData:a,inPlace:!0}},kr=class e{constructor({data:e,config:t,api:n,readOnly:r,block:i}){var a;this._element=null,this._contentElement=null,this._arrowElement=null,this._bodyPlaceholderElement=null,this._childContainerElement=null,this.handleChildContainerInput=()=>{S(this._element,this._childContainerElement)},this.handleBlockChanged=e=>{this.isBlockChangedPayload(e)&&(e.event.type===`block-removed`||e.event.type===`block-added`)&&this.updateBodyPlaceholderVisibility()},this.api=n,this.readOnly=r,this._settings=t||{},this._data=this.normalizeData(e),this._isOpen=(a=this._data.isOpen)==null?!0:a,i&&(this.blockId=i.id),r||this.api.events.on(`block changed`,this.handleBlockChanged)}normalizeData(e){if(typeof e==`object`&&e&&`text`in e){let t={text:typeof e.text==`string`?e.text:``};return typeof e.isOpen==`boolean`&&(t.isOpen=e.isOpen),t}if(typeof e==`object`&&e&&`title`in e){let t=e,n={text:typeof t.title==`string`?t.title:``};return typeof t.isExpanded==`boolean`&&(n.isOpen=t.isExpanded),n}return{text:``}}get placeholder(){if(this._settings.placeholder)return this._settings.placeholder;let e=this.api.i18n.t(t.l);return e===`tools.toggle.placeholder`?`Toggle`:e}render(){let e=C({data:this._data,readOnly:this.readOnly,isOpen:this._isOpen,placeholder:this.placeholder,keydownHandler:this.readOnly?null:this.handleKeyDown.bind(this),onArrowClick:()=>this.toggleOpen(),onBodyPlaceholderClick:this.readOnly?null:()=>this.handleBodyPlaceholderClick(),bodyPlaceholderText:this.api.i18n.t(t.o),ariaLabels:{collapse:this.api.i18n.t(t.t),expand:this.api.i18n.t(t.n)}});return this._element=e.wrapper,this._contentElement=e.contentElement,this._arrowElement=e.arrowElement,this._bodyPlaceholderElement=e.bodyPlaceholderElement,this._childContainerElement=e.childContainerElement,this._childContainerElement.addEventListener(`input`,this.handleChildContainerInput),this._element}rendered(){this.updateChildrenVisibility(),this.updateBodyPlaceholderVisibility()}save(){return Er(this._data,this._element,this.getContentElement.bind(this),this._isOpen)}validate(e){return!0}merge(e){Dr({data:this._data,getContentElement:this.getContentElement.bind(this),parseHTML:Tr},e)}onPaste(n){let r=n.detail;if(!(`data`in r))return;let i=r.data,a=i.querySelector(`summary`),o=t.ur(a===null?i.innerHTML:a.innerHTML,e.sanitize.text);this._data={text:o};let s=this.getContentElement();s!==null&&(s.innerHTML=o)}setData(e){let n=Or(this._data,e,this.getContentElement.bind(this));return this._data=n.newData,typeof this._data.isOpen==`boolean`&&(this._isOpen=this._data.isOpen),this._arrowElement&&this._element&&w(this._arrowElement,this._element,this._isOpen,{collapse:this.api.i18n.t(t.t),expand:this.api.i18n.t(t.n)}),this.updateChildrenVisibility(),this.updateBodyPlaceholderVisibility(),n.inPlace}renderSettings(){return[]}expand(){this._isOpen||this.setOpenState(!0)}collapse(){this._isOpen&&this.setOpenState(!1)}setReadOnly(e){if(!this._element)return;let t=this.readOnly;this.readOnly=e,this._contentElement&&(this._contentElement.contentEditable=e?`false`:`true`),e&&!t?this.api.events.off(`block changed`,this.handleBlockChanged):!e&&t&&this.api.events.on(`block changed`,this.handleBlockChanged),this.updateBodyPlaceholderVisibility()}removed(){this.api.events.off(`block changed`,this.handleBlockChanged)}isBlockChangedPayload(e){return typeof e==`object`&&!!e&&`event`in e&&typeof e.event==`object`&&e.event!==null&&`type`in e.event&&typeof e.event.type==`string`}getContentElement(){return this._contentElement}setOpenState(e){this._isOpen=e,this._arrowElement&&this._element&&w(this._arrowElement,this._element,this._isOpen,{collapse:this.api.i18n.t(t.t),expand:this.api.i18n.t(t.n)}),this.updateChildrenVisibility(),this.updateBodyPlaceholderVisibility()}toggleOpen(){this.setOpenState(!this._isOpen)}updateChildrenVisibility(){this.blockId!==void 0&&T(this.api,this.blockId,this._isOpen,this._childContainerElement,this._arrowElement)}updateBodyPlaceholderVisibility(){this.blockId!==void 0&&(E(this._bodyPlaceholderElement,this.api,this.blockId,this._isOpen,this.readOnly),S(this._element,this._childContainerElement))}handleBodyPlaceholderClick(){var e;if(this.blockId===void 0)return;let t=this.api.blocks.getBlockIndex(this.blockId);if(t===void 0)return;let n=this.api.blocks.insertInsideParent(this.blockId,t+1);this.api.caret.setToBlock(n.id,`start`),(e=this._bodyPlaceholderElement)==null||e.classList.add(`hidden`)}handleKeyDown(e){if(e.key===`Enter`&&!e.shiftKey){e.preventDefault(),this.handleEnter();return}if(e.key===`Backspace`){this.handleBackspace(e);return}}createKeyboardContext(){return{api:this.api,blockId:this.blockId,data:this._data,element:this._element,getContentElement:this.getContentElement.bind(this),syncContentFromDOM:this.syncContentFromDOM.bind(this),isOpen:this._isOpen,setOpen:e=>{this._isOpen=e}}}async handleEnter(){var e=this;await D(e.createKeyboardContext()),e.updateBodyPlaceholderVisibility()}async handleBackspace(e){await O(this.createKeyboardContext(),e)}syncContentFromDOM(){let e=this.getContentElement();e&&(this._data.text=e.innerHTML)}static get toolbox(){return{icon:t.Sn,titleKey:`toggleList`,name:t.p,searchTerms:[`toggle`,`collapse`,`expand`,`accordion`],searchTermKeys:[`toggle`,`collapse`,`expand`,`accordion`],shortcut:`>`}}static get conversionConfig(){return{export:`text`,import:`text`}}static get sanitize(){return{text:{br:!0,a:{href:!0,target:`_blank`,rel:`nofollow`},b:!0,i:!0,mark:{class:!0,style:!0},code:!0}}}static get pasteConfig(){return{tags:[`DETAILS`]}}static get isReadOnlySupported(){return!0}},Ar=`callout`,jr=`tools.callout.color`,Mr=`tools.callout.editIcon`,Nr=`tools.callout.addEmoji`,Pr=`tools.callout.removeEmoji`,Fr=`tools.callout.filterEmojis`,Ir=`tools.callout.calloutEmojiCategory`,Lr=`tools.callout.noEmojisFound`,Rr=`tools.callout.pickRandom`,zr=`tools.callout.skinTone`,Br=`tools.callout.emojiCategoryPeople`,Vr=`tools.callout.emojiCategoryNature`,Hr=`tools.callout.emojiCategoryFood`,Ur=`tools.callout.emojiCategoryActivity`,Wr=`tools.callout.emojiCategoryTravel`,Gr=`tools.callout.emojiCategoryObjects`,Kr=`tools.callout.emojiCategorySymbols`,qr=`tools.callout.emojiCategoryFlags`,Jr=`💡`,Yr=`rounded-xl pl-8 pr-4 py-[5px] my-1 flex items-start gap-2 relative`,Xr=`text-[1.5rem] leading-[1] cursor-pointer bg-transparent border-0 px-0 py-[7px] h-[38px] flex-shrink-0 select-none`,Zr=`flex-1 min-w-0`;function Qr(e){let{emoji:n,readOnly:r,addEmojiLabel:i}=e,a=document.createElement(`div`);a.className=Yr;let o=document.createElement(`button`);o.type=`button`,o.className=Xr,o.textContent=n||``,o.setAttribute(`aria-label`,n===``?i:n),o.setAttribute(`tabindex`,`0`),o.setAttribute(`data-blok-testid`,`callout-emoji-btn`),r&&(o.disabled=!0);let s=document.createElement(`div`);return s.className=Zr,s.setAttribute(t.u.toggleChildren,``),s.setAttribute(t.hi.nestedBlocks,``),s.setAttribute(`data-blok-child-toolbar`,``),s.setAttribute(`data-blok-mutation-free`,`true`),a.appendChild(o),a.appendChild(s),{wrapper:a,emojiButton:o,childContainer:s}}function $r(e){return{emoji:e.emoji,textColor:e.textColor,backgroundColor:e.backgroundColor}}async function ei(e){if(e.calloutBlockId===void 0)return;let t=e.api.blocks.getChildren(e.calloutBlockId);if(e.event.preventDefault(),t.length<=1){await e.api.blocks.convert(e.calloutBlockId,`paragraph`);return}let n=e.api.blocks.getBlockIndex(e.firstChildBlockId);n!==void 0&&await e.api.blocks.delete(n);let r=e.api.blocks.getBlockIndex(e.calloutBlockId);r!==void 0&&r>0&&e.api.caret.setToBlock(r-1,`end`)}var ti=[`💡`,`👉`,`☝️`,`✅`,`⚠️`,`🔑`,`🔥`,`📌`,`✂️`,`❓`,`🚫`,`⏰`,`♻️`,`🔒`,`📖`,`👣`,`➡️`,`📢`,`🛠️`,`⚙️`],ni={data:null};function ri(e,t){let n=[];for(let r of e.emojis){let i=t[r];if(i===void 0)continue;let a=i.skins[0];a!==void 0&&n.push({native:a.native,skins:i.skins.map(e=>e.native),id:i.id,name:i.name,keywords:i.keywords,category:e.id})}return n}async function ii(){if(ni.data!==null)return ni.data;let e=await Promise.resolve().then(()=>require(`./native-BGo-1wHi.cjs`)),t=`default`in e&&e.default!==void 0?e.default:e,n=t.categories.flatMap(e=>ri(e,t.emojis));return ni.data=n,n}function ai(e,t,n){let r=t.toLowerCase();return e.filter(e=>{if(e.name.toLowerCase().includes(r)||e.keywords.some(e=>e.includes(r)))return!0;let t=n==null?void 0:n[e.native];return t===void 0?!1:t.n.toLowerCase().includes(r)||t.k!==void 0&&t.k.some(e=>e.toLowerCase().includes(r))})}function oi(e){let t=new Map;for(let r of e){var n;let e=(n=t.get(r.category))==null?[]:n;e.push(r),t.set(r.category,e)}return t}var si=new Map,ci={am:()=>Promise.resolve().then(()=>require(`./am-CXUHahfU.cjs`)),ar:()=>Promise.resolve().then(()=>require(`./ar-dMOvWpJ-.cjs`)),az:()=>Promise.resolve().then(()=>require(`./az-3AbIE3nE.cjs`)),bg:()=>Promise.resolve().then(()=>require(`./bg-Y0RPNL0Z.cjs`)),bn:()=>Promise.resolve().then(()=>require(`./bn-D15VfEKd.cjs`)),bs:()=>Promise.resolve().then(()=>require(`./bs-B9nWVl_9.cjs`)),cs:()=>Promise.resolve().then(()=>require(`./cs-C9BEO4yn.cjs`)),da:()=>Promise.resolve().then(()=>require(`./da-BhLipA1M.cjs`)),de:()=>Promise.resolve().then(()=>require(`./de-BgNy5oYG.cjs`)),el:()=>Promise.resolve().then(()=>require(`./el-Ui4jHL2s.cjs`)),es:()=>Promise.resolve().then(()=>require(`./es-BsNXkteq.cjs`)),et:()=>Promise.resolve().then(()=>require(`./et-yMa1l80R.cjs`)),fa:()=>Promise.resolve().then(()=>require(`./fa-D6mf3izM.cjs`)),fi:()=>Promise.resolve().then(()=>require(`./fi-CYnlvPFq.cjs`)),fil:()=>Promise.resolve().then(()=>require(`./fil-DuFCrHoY.cjs`)),fr:()=>Promise.resolve().then(()=>require(`./fr-BBK6Wz6C.cjs`)),gu:()=>Promise.resolve().then(()=>require(`./gu-BJKCBJyD.cjs`)),he:()=>Promise.resolve().then(()=>require(`./he-BcUX_UQ1.cjs`)),hi:()=>Promise.resolve().then(()=>require(`./hi-BGf8Lxf8.cjs`)),hr:()=>Promise.resolve().then(()=>require(`./hr-hDDrHtNU.cjs`)),hu:()=>Promise.resolve().then(()=>require(`./hu-3HqqKEVc.cjs`)),hy:()=>Promise.resolve().then(()=>require(`./hy-Dzrc71XE.cjs`)),id:()=>Promise.resolve().then(()=>require(`./id-F9h4091H.cjs`)),it:()=>Promise.resolve().then(()=>require(`./it-DJji6i7E.cjs`)),ja:()=>Promise.resolve().then(()=>require(`./ja-C_pXoRgb.cjs`)),ka:()=>Promise.resolve().then(()=>require(`./ka-DGtVwGYl.cjs`)),km:()=>Promise.resolve().then(()=>require(`./km-DZ5rHPWc.cjs`)),kn:()=>Promise.resolve().then(()=>require(`./kn-DwwLaTD6.cjs`)),ko:()=>Promise.resolve().then(()=>require(`./ko-BBEtqxQR.cjs`)),ku:()=>Promise.resolve().then(()=>require(`./ku-Dd2x74MF.cjs`)),lo:()=>Promise.resolve().then(()=>require(`./lo-C61Y3F1a.cjs`)),lt:()=>Promise.resolve().then(()=>require(`./lt-pqg5xvGS.cjs`)),lv:()=>Promise.resolve().then(()=>require(`./lv-g3FCWRN0.cjs`)),mk:()=>Promise.resolve().then(()=>require(`./mk-bBMWHEZ-.cjs`)),ml:()=>Promise.resolve().then(()=>require(`./ml-Cm0IOve2.cjs`)),mn:()=>Promise.resolve().then(()=>require(`./mn-BTXL9HyI.cjs`)),mr:()=>Promise.resolve().then(()=>require(`./mr-xqL99Sd8.cjs`)),ms:()=>Promise.resolve().then(()=>require(`./ms-ClORsi5r.cjs`)),my:()=>Promise.resolve().then(()=>require(`./my-B-isOX0B.cjs`)),ne:()=>Promise.resolve().then(()=>require(`./ne-BGws6s0Y.cjs`)),nl:()=>Promise.resolve().then(()=>require(`./nl-CX2wzRTJ.cjs`)),no:()=>Promise.resolve().then(()=>require(`./no-CkkRSiCD.cjs`)),pa:()=>Promise.resolve().then(()=>require(`./pa-ZPS7mc5i.cjs`)),pl:()=>Promise.resolve().then(()=>require(`./pl-BqsMUtmm.cjs`)),ps:()=>Promise.resolve().then(()=>require(`./ps-CfUVIVqL.cjs`)),pt:()=>Promise.resolve().then(()=>require(`./pt-DqrVMzTM.cjs`)),ro:()=>Promise.resolve().then(()=>require(`./ro-fExo_FSc.cjs`)),ru:()=>Promise.resolve().then(()=>require(`./ru-LOwQVd_T.cjs`)),sd:()=>Promise.resolve().then(()=>require(`./sd-CretDKhM.cjs`)),si:()=>Promise.resolve().then(()=>require(`./si-DtQVOOio.cjs`)),sk:()=>Promise.resolve().then(()=>require(`./sk-CYibO0jl.cjs`)),sl:()=>Promise.resolve().then(()=>require(`./sl-7kJGMwOr.cjs`)),sq:()=>Promise.resolve().then(()=>require(`./sq-B63iyaS4.cjs`)),sr:()=>Promise.resolve().then(()=>require(`./sr-CH3ORyMw.cjs`)),sv:()=>Promise.resolve().then(()=>require(`./sv-Bcx8ebyq.cjs`)),sw:()=>Promise.resolve().then(()=>require(`./sw-BvKSTskt.cjs`)),ta:()=>Promise.resolve().then(()=>require(`./ta-DMUhMZIx.cjs`)),te:()=>Promise.resolve().then(()=>require(`./te-CGA7e7rg.cjs`)),th:()=>Promise.resolve().then(()=>require(`./th-fRbW65W8.cjs`)),tr:()=>Promise.resolve().then(()=>require(`./tr-W2-8Rsq1.cjs`)),ug:()=>Promise.resolve().then(()=>require(`./ug-NOltpjZX.cjs`)),uk:()=>Promise.resolve().then(()=>require(`./uk-CifV3wfH.cjs`)),ur:()=>Promise.resolve().then(()=>require(`./ur-DUJVuENS.cjs`)),vi:()=>Promise.resolve().then(()=>require(`./vi-DyluRTg6.cjs`)),zh:()=>Promise.resolve().then(()=>require(`./zh-BEYGMTUQ.cjs`))};async function li(e){if(e===`en`)return null;let t=si.get(e);if(t!==void 0)return t;let n=ci[e];if(n===void 0)return null;try{let t=(await n()).default;return si.set(e,t),t}catch(e){return null}}var ui={callout:Ir,people:Br,nature:Vr,foods:Hr,activity:Ur,places:Wr,objects:Gr,symbols:Kr,flags:qr},di=[[`callout`,t._t],[`people`,t.ht],[`nature`,t.gt],[`foods`,t.vt],[`activity`,t.ft],[`places`,t.St],[`objects`,t.mt],[`symbols`,t.kt],[`flags`,t.pt]],fi=[`✋`,`✋🏻`,`✋🏼`,`✋🏽`,`✋🏾`,`✋🏿`],pi=`blok-emoji-skin-tone`;function mi(){try{let e=localStorage.getItem(pi);if(e===null)return 0;let t=parseInt(e,10);return t>=0&&t<=5?t:0}catch(e){return 0}}function hi(e){try{localStorage.setItem(pi,String(e))}catch(e){}}var gi=t.st,_i=class{constructor(e){this._localeData=null,this._open=!1,this._allEmojis=[],this._skinTone=0,this._showingEmptyState=!1,this._anchorEl=null,this._backdrop=null,this._savedOverflow=``,this._navButtons=new Map,this._sectionEls=new Map,this._activeNavId=``,this._navRafId=0,this._skinToneButtons=[],this.onSelect=e.onSelect,this.onRemove=e.onRemove,this.i18n=e.i18n,this._locale=e.locale,this._element=this.buildElement();let t=this._element.querySelector(`[data-emoji-picker-body]`),n=this._element.querySelector(`[data-emoji-picker-nav]`),r=this._element.querySelector(`input[type="text"]`);if(t===null||n===null||r===null)throw Error(`EmojiPicker: failed to build required elements`);this._body=t,this._nav=n,this._filterInput=r,this._body.addEventListener(`scroll`,()=>{cancelAnimationFrame(this._navRafId),this._navRafId=requestAnimationFrame(()=>this.updateActiveNav())},{passive:!0})}getElement(){return this._element}isOpen(){return this._open}async open(e){var t=this;t._anchorEl=e,t._open=!0,t._filterInput.value=``,t._element.setAttribute(`data-theme`,t.resolveTheme());let n=mi();if(n!==t._skinTone){t._skinTone=n,t._skinToneToggle.textContent=fi[n];for(let[e,r]of t._skinToneButtons.entries())t.applySkinToneActiveStyle(r,e===n)}if(t._allEmojis.length===0&&(t._allEmojis=await ii()),t._locale!==`en`&&t._localeData===null){let e=await li(t._locale);e!==null&&(t._localeData=e)}t.renderEmojiGrid(t._allEmojis),t.showBackdrop(),t._element.style.animation=`none`,t._element.hidden=!1,t.position(e),t._element.offsetHeight,t._element.style.animation=``,t._filterInput.focus()}close(){var e;this._open=!1,this._element.hidden=!0,this.closeSkinTonePopover(),this.removeBackdrop(),(e=this._anchorEl)==null||e.focus()}buildElement(){let e=document.createElement(`div`);e.setAttribute(`data-blok-emoji-picker`,``),e.className=[`fixed z-50 w-[400px] overflow-hidden rounded-xl`,`border border-neutral-200/70 bg-white shadow-2xl`,`theme-dark:border-neutral-700/50 theme-dark:bg-neutral-900`].join(` `),e.hidden=!0;let n=document.createElement(`div`);n.className=`flex items-center gap-2.5 px-3 pt-3 pb-2`;let r=document.createElement(`div`);r.className=`relative flex-1 min-w-0`;let i=document.createElement(`span`);i.className=[`pointer-events-none absolute left-2.5 top-1/2 -translate-y-1/2 flex items-center`,`text-neutral-400 theme-dark:text-neutral-500 [&>svg]:w-[16px] [&>svg]:h-[16px]`].join(` `),i.innerHTML=t.fn;let a=document.createElement(`input`);a.type=`text`,a.placeholder=this.i18n.t(Fr),a.className=[`w-full text-[13px] rounded-lg py-[7px] pl-8 pr-3 outline-hidden`,`bg-neutral-100 text-neutral-800 placeholder:text-neutral-400`,`theme-dark:bg-neutral-800 theme-dark:text-neutral-200 theme-dark:placeholder:text-neutral-500`,`focus:ring-2 focus:ring-neutral-300/60 theme-dark:focus:ring-neutral-600/60`,`transition-shadow duration-150`].join(` `),a.addEventListener(`input`,()=>this.handleFilterChange(a.value)),r.appendChild(i),r.appendChild(a);let o=document.createElement(`div`);o.className=`relative flex-shrink-0`;let s=document.createElement(`button`);s.type=`button`,s.setAttribute(`data-emoji-picker-skin-toggle`,``),s.setAttribute(`aria-label`,this.i18n.t(zr)),s.title=this.i18n.t(zr),s.className=[`w-[28px] h-[28px] flex items-center justify-center rounded-lg`,`text-[14px] leading-none cursor-pointer select-none`,`hover:bg-neutral-100 theme-dark:hover:bg-neutral-800`,`active:scale-90 transition-all duration-100`].join(` `),s.textContent=fi[this._skinTone],s.addEventListener(`click`,()=>this.toggleSkinTonePopover()),this._skinToneToggle=s,o.appendChild(s),this._skinTonePopover=this.buildSkinTonePopover(),o.appendChild(this._skinTonePopover);let c=document.createElement(`button`);c.type=`button`,c.setAttribute(`data-emoji-picker-random`,``),c.setAttribute(`aria-label`,this.i18n.t(Rr)),c.className=[`flex-shrink-0 w-[34px] h-[34px] flex items-center justify-center rounded-lg`,`text-neutral-400 hover:bg-neutral-100 hover:text-neutral-600`,`theme-dark:hover:bg-neutral-800 theme-dark:hover:text-neutral-300`,`transition-colors duration-100 cursor-pointer`].join(` `),c.innerHTML=gi,c.addEventListener(`click`,()=>this.pickRandom()),t.or(c,this.i18n.t(Rr),{placement:`bottom`});let l=document.createElement(`button`);l.type=`button`,l.setAttribute(`data-emoji-picker-remove`,``),l.setAttribute(`aria-label`,this.i18n.t(Pr)),l.className=[`flex-shrink-0 w-[34px] h-[34px] flex items-center justify-center rounded-lg`,`text-neutral-400 hover:bg-neutral-100 hover:text-neutral-600`,`theme-dark:hover:bg-neutral-800 theme-dark:hover:text-neutral-300`,`transition-colors duration-100 cursor-pointer`].join(` `),l.innerHTML=t.Z,l.addEventListener(`click`,()=>{this.onRemove(),this.close()}),t.or(l,this.i18n.t(Pr),{placement:`bottom`});let u=document.createElement(`div`);u.className=`flex items-center gap-1`,u.appendChild(c),u.appendChild(l),n.appendChild(r),n.appendChild(o),n.appendChild(u),e.appendChild(n);let d=document.createElement(`div`);d.setAttribute(`data-emoji-picker-body`,``),d.className=`overflow-y-auto max-h-[260px] px-1.5 pb-2`,e.appendChild(d);let f=document.createElement(`div`);return f.setAttribute(`data-emoji-picker-nav`,``),f.className=[`flex items-center gap-1 px-2 pt-1 pb-1`,`border-t border-neutral-100 theme-dark:border-neutral-800`].join(` `),e.appendChild(f),e.addEventListener(`mousedown`,e=>{let t=e.target;!this._skinTonePopover.hidden&&!this._skinTonePopover.contains(t)&&!this._skinToneToggle.contains(t)&&this.closeSkinTonePopover()}),e.addEventListener(`keydown`,e=>{if(e.key===`Escape`){if(!this._skinTonePopover.hidden){this.closeSkinTonePopover();return}this.close()}}),e}buildSkinTonePopover(){let e=document.createElement(`div`);e.setAttribute(`data-emoji-picker-skin-tone`,``),e.className=[`absolute right-0 top-full mt-1.5 z-20`,`flex items-center gap-0.5 p-1 rounded-xl`,`bg-white border border-neutral-200/70 shadow-lg`,`theme-dark:bg-neutral-800 theme-dark:border-neutral-700/50`].join(` `),e.hidden=!0,this._skinToneButtons=[];for(let[t,n]of fi.entries()){let r=document.createElement(`button`);r.type=`button`,r.textContent=n,r.setAttribute(`aria-label`,`${this.i18n.t(zr)} ${t+1}`),r.className=[`w-[32px] h-[32px] flex items-center justify-center rounded-lg`,`text-[1.2rem] leading-none cursor-pointer select-none`,`hover:bg-neutral-100 theme-dark:hover:bg-neutral-700`,`active:scale-90 transition-all duration-100`].join(` `),this.applySkinToneActiveStyle(r,t===this._skinTone),r.addEventListener(`click`,()=>{this.setSkinTone(t),this.closeSkinTonePopover()}),e.appendChild(r),this._skinToneButtons.push(r)}return e}applySkinToneActiveStyle(e,t){let n=[`bg-neutral-100`,`theme-dark:bg-neutral-700`,`ring-2`,`ring-neutral-300/60`,`theme-dark:ring-neutral-600/60`];t?e.classList.add(...n):e.classList.remove(...n)}toggleSkinTonePopover(){this._skinTonePopover.hidden=!this._skinTonePopover.hidden,this.updateSkinToneToggleActive()}closeSkinTonePopover(){this._skinTonePopover.hidden=!0,this.updateSkinToneToggleActive()}updateSkinToneToggleActive(){let e=!this._skinTonePopover.hidden,t=[`bg-neutral-100`,`theme-dark:bg-neutral-700`];e?this._skinToneToggle.classList.add(...t):this._skinToneToggle.classList.remove(...t)}setSkinTone(e){this._skinTone=e,hi(e),this._skinToneToggle.textContent=fi[e];for(let[t,n]of this._skinToneButtons.entries())this.applySkinToneActiveStyle(n,t===e);let t=Array.from(this._body.querySelectorAll(`[data-emoji-native]`));for(let e of t){let t=e.getAttribute(`data-emoji-native`);if(t===null)continue;let n=this._allEmojis.find(e=>e.native===t);n!==void 0&&(e.textContent=this.getSkinnedNative(n))}}pickRandom(){if(this._allEmojis.length===0)return;let e=Math.floor(Math.random()*this._allEmojis.length),t=this._allEmojis[e];t!==void 0&&this.onSelect(this.getSkinnedNative(t))}buildCategoryNav(e){this._nav.innerHTML=``,this._navButtons.clear(),this._activeNavId=``;for(let[t,n]of di){if(!e.has(t))continue;let r=this.translateCategory(t),i=document.createElement(`button`);i.type=`button`,i.innerHTML=n,i.title=r,i.setAttribute(`aria-label`,r),i.setAttribute(`data-emoji-nav`,t),i.className=[`flex-1 h-[36px] flex items-center justify-center`,`rounded-lg cursor-pointer opacity-50`,`text-neutral-500 theme-dark:text-neutral-400`,`[&>svg]:w-[20px] [&>svg]:h-[20px]`,`hover:opacity-100 hover:bg-neutral-100`,`theme-dark:hover:bg-neutral-800`,`transition-all duration-100`].join(` `),i.addEventListener(`click`,()=>this.scrollToSection(t)),this._nav.appendChild(i),this._navButtons.set(t,i)}}scrollToSection(e){let t=this._sectionEls.get(e);if(t===void 0)return;let n=this._body.getBoundingClientRect(),r=t.getBoundingClientRect();this._body.scrollTo({top:this._body.scrollTop+(r.top-n.top),behavior:`smooth`})}updateActiveNav(){let e=this._body.getBoundingClientRect().top,t=[...this._sectionEls.entries()].filter(([,t])=>t.getBoundingClientRect().top-e<=20).reduce((e,[t])=>t,``);if(t!==this._activeNavId){this._activeNavId=t;for(let[e,n]of this._navButtons)e===t?(n.classList.remove(`opacity-50`),n.classList.add(`opacity-100`,`bg-neutral-100`,`theme-dark:bg-neutral-800`)):(n.classList.remove(`opacity-100`,`bg-neutral-100`,`theme-dark:bg-neutral-800`),n.classList.add(`opacity-50`))}}getSkinnedNative(e){var t;return(t=e.skins[this._skinTone])==null?e.native:t}handleFilterChange(e){if(e.trim()===``){this._nav.hidden=!1,this.renderEmojiGrid(this._allEmojis);return}this._nav.hidden=!0;let t=ai(this._allEmojis,e,this._localeData);if(t.length===0)this._showingEmptyState||this.renderEmptyState();else{this._body.innerHTML=``,this._sectionEls.clear(),this._showingEmptyState=!1;let e=oi(t);for(let[t,n]of e){let e=this.buildSection(this.translateCategory(t),n);e.setAttribute(`data-emoji-section`,t),this._sectionEls.set(t,e),this._body.appendChild(e)}}}renderEmojiGrid(e){this._body.innerHTML=``,this._sectionEls.clear(),this._showingEmptyState=!1;let t=new Set,n=ti.map(t=>e.find(e=>e.native===t)).filter(e=>e!==void 0);if(n.length>0){t.add(`callout`);let e=this.buildSection(this.translateCategory(`callout`),n);e.setAttribute(`data-emoji-section`,`callout`),this._sectionEls.set(`callout`,e),this._body.appendChild(e)}let r=new Set(ti),i=oi(e.filter(e=>!r.has(e.native)));for(let[e,n]of i){t.add(e);let r=this.buildSection(this.translateCategory(e),n);r.setAttribute(`data-emoji-section`,e),this._sectionEls.set(e,r),this._body.appendChild(r)}this.buildCategoryNav(t),this._nav.hidden=!1,requestAnimationFrame(()=>this.updateActiveNav())}renderEmptyState(){this._body.innerHTML=``,this._showingEmptyState=!0,this._sectionEls.clear();let e=document.createElement(`div`);e.className=[`flex flex-col items-center justify-center py-10`,`text-neutral-400 theme-dark:text-neutral-500 select-none`,`animate-[blok-emoji-empty-in_300ms_ease-out_both]`].join(` `);let n=document.createElement(`span`);n.className=`mb-3 opacity-20 [&>svg]:w-9 [&>svg]:h-9`,n.innerHTML=t.fn;let r=document.createElement(`span`);r.className=`text-[13px] font-medium`,r.textContent=this.i18n.t(Lr),e.appendChild(n),e.appendChild(r),this._body.appendChild(e)}translateCategory(e){let t=ui[e];return t===void 0?e:this.i18n.t(t)}buildSection(e,t){let n=document.createElement(`div`),r=document.createElement(`div`);return r.className=[`text-[11px] font-semibold uppercase tracking-wider px-2 pt-3 pb-1.5`,`text-neutral-400/80 theme-dark:text-neutral-500/80`,`sticky top-0 bg-white theme-dark:bg-neutral-900 z-10`].join(` `),r.textContent=e,n.appendChild(r),n.appendChild(this.buildGrid(t)),n}getDisplayName(e){var t,n;return((t=(n=this._localeData)==null||(n=n[e.native])==null?void 0:n.n)==null?e.name:t).toLocaleLowerCase()}buildGrid(e){let n=document.createElement(`div`);n.className=`grid grid-cols-10 gap-0.5 px-0.5 pt-1`;for(let r of e){let e=document.createElement(`button`);e.type=`button`,e.textContent=this.getSkinnedNative(r),e.setAttribute(`data-emoji-native`,r.native),e.className=[`aspect-square flex items-center justify-center`,`text-[1.25rem] leading-none rounded-lg cursor-pointer`,`hover:bg-neutral-100 theme-dark:hover:bg-neutral-800`,`hover:scale-110 active:scale-95`,`transition-transform duration-75`].join(` `),e.addEventListener(`click`,()=>{this.onSelect(this.getSkinnedNative(r)),this.close()}),t.or(e,this.getDisplayName(r),{placement:`bottom`}),n.appendChild(e)}return n}resolveTheme(){let e=document.documentElement.getAttribute(`data-blok-theme`);return e===`dark`?`dark`:e===`light`?`light`:window.matchMedia(`(prefers-color-scheme: dark)`).matches?`dark`:`light`}showBackdrop(){var e;this.removeBackdrop();let t=document.createElement(`div`);t.setAttribute(`data-blok-emoji-picker-backdrop`,``),t.style.position=`fixed`,t.style.inset=`0`,t.style.zIndex=`50`,t.addEventListener(`mousedown`,e=>{e.target===t&&this.close()}),(e=this._element.parentElement)==null||e.insertBefore(t,this._element),t.appendChild(this._element),this._backdrop=t,this._savedOverflow=document.documentElement.style.overflow,document.documentElement.style.overflow=`hidden`}removeBackdrop(){var e;this._backdrop!==null&&(document.documentElement.style.overflow=this._savedOverflow,(e=this._backdrop.parentElement)==null||e.insertBefore(this._element,this._backdrop),this._backdrop.remove(),this._backdrop=null)}position(e){let t=e.getBoundingClientRect(),n=this._element.getBoundingClientRect(),r=window.innerHeight,i=window.innerWidth,a=t.bottom+n.height>r?t.top-n.height-4:t.bottom+4,o=t.left-8,s=o+n.width>i?t.right-n.width:Math.max(0,o);this._element.style.top=`${a}px`,this._element.style.left=`${s}px`}};function vi(e){return e.isEmojiVisible===!1?``:typeof e.emoji==`string`&&e.emoji.length>0?e.emoji:Jr}var yi={general:null,note:`blue`,important:`purple`,warning:`orange`,additional:`yellow`,recommendation:`green`,caution:`red`},bi=class{constructor({data:e,api:t,readOnly:n,block:r,config:i}){this._dom=null,this._emojiPicker=null,this._colorPicker=null,this._pendingChildText=null,this.api=t,this.readOnly=n;let a=typeof e.__importedText==`string`?e.__importedText:null;a!==null&&a.length>0&&(this._pendingChildText=a),this._data=this.normalizeData(e),r&&(this.blockId=r.id),this._customEmojiPicker=i==null?void 0:i.emojiPicker}normalizeData(e){let t=e;return`variant`in t||`isEmojiVisible`in t?this.normalizeLegacyData(t):{emoji:typeof e.emoji==`string`?e.emoji:Jr,textColor:typeof e.textColor==`string`?e.textColor:null,backgroundColor:typeof e.backgroundColor==`string`?e.backgroundColor:null}}normalizeLegacyData(e){let t=typeof e.variant==`string`?e.variant:`general`,n=t in yi?yi[t]:null;return{emoji:vi(e),textColor:null,backgroundColor:n==null?null:n}}render(){if(this._dom)return this._dom.wrapper;let e=Qr({emoji:this._data.emoji,readOnly:this.readOnly,addEmojiLabel:this.api.i18n.t(Nr)});return this._dom=e,this.applyColors(),this.readOnly||(e.emojiButton.addEventListener(`click`,()=>this.openEmojiPicker()),e.emojiButton.addEventListener(`keydown`,e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),this.openEmojiPicker())}),e.childContainer.addEventListener(`keydown`,e=>{e.key===`Backspace`&&this.handleChildBackspace(e)})),e.wrapper}rendered(){if(this.blockId===void 0||this._dom===null)return;let e=this.api.blocks.getChildren(this.blockId);if(x(this._dom.childContainer,e),e.length===0){let e=this.api.blocks.getBlockIndex(this.blockId);if(e!==void 0){let t=this._pendingChildText;this._pendingChildText=null;let n=t!==null&&t.length>0?{text:t}:void 0,r=this.api.blocks.insertInsideParent(this.blockId,e+1,n);this._dom.childContainer.appendChild(r.holder),this.api.caret.setToBlock(r.id,t===null?`start`:`end`)}}}save(){return $r({emoji:this._data.emoji,textColor:this._data.textColor,backgroundColor:this._data.backgroundColor})}validate(e){return!0}onPaste(e){var n;let r=(n=e.detail.data.getAttribute(`style`))==null?``:n,i=/background(?:-color)?\s*:\s*([^;]+)/i.exec(r);if(i!=null&&i[1]){let e=t.Rn(i[1].trim(),`bg`);e&&(this._data.backgroundColor=e)}this.applyColors()}renderSettings(){if(this._colorPicker===null){let e=Ft({i18n:this.api.i18n,testIdPrefix:`callout-color`,modes:[{key:`color`,labelKey:`tools.marker.textColor`,presetField:`text`},{key:`background-color`,labelKey:`tools.marker.background`,presetField:`bg`}],onColorSelect:(n,r)=>{let i=n===null?null:t.Rn(n,r===`color`?`text`:`bg`);r===`color`?this._data.textColor=i:this._data.backgroundColor=i,e.setActiveColor(n,r),this.applyColors()}});this._colorPicker=e}return this.syncPickerActiveColors(),[{icon:t.ht,title:this.api.i18n.t(Mr),name:`callout-edit-icon`,closeOnActivate:!0,onActivate:()=>this.openEmojiPicker()},{icon:t.in,title:this.api.i18n.t(jr),name:`callout-color`,children:{items:[{type:t.pr.Html,element:this._colorPicker.element}]}}]}removed(){}setReadOnly(e){this.readOnly=e,this._dom&&(this._dom.emojiButton.disabled=e)}syncPickerActiveColors(){if(this._colorPicker===null)return;let e=this._data.textColor,n=this._data.backgroundColor;this._colorPicker.setActiveColor(e===null?null:t.Wn(e,`text`),`color`),this._colorPicker.setActiveColor(n===null?null:t.Wn(n,`bg`),`background-color`)}applyColors(){if(this._dom===null)return;let{textColor:e,backgroundColor:n}=this._data;if(e===null?this._dom.wrapper.style.color=``:this._dom.wrapper.style.color=t.Wn(e,`text`),n!==null){let e=t.Wn(n,`bg`);this._dom.wrapper.style.backgroundColor=e,this._dom.wrapper.style.border=``,this._dom.wrapper.style.setProperty(`--blok-search-input-bg`,`light-dark(color-mix(in srgb, ${e} 70%, white), color-mix(in srgb, ${e} 85%, white))`)}else this._dom.wrapper.style.backgroundColor=``,this._dom.wrapper.style.border=`1px solid var(--blok-callout-default-border, #e5e7eb)`,this._dom.wrapper.style.removeProperty(`--blok-search-input-bg`),this._dom.wrapper.style.removeProperty(`--blok-search-input-border`)}handleChildBackspace(e){if(this.blockId===void 0||this._dom===null)return;let t=this.api.blocks.getChildren(this.blockId);if(t.length===0)return;let n=t[0],r=e.target;if(!n.holder.contains(r))return;let i=window.getSelection(),a=i!==null&&i.rangeCount>0&&i.getRangeAt(0).startOffset===0&&i.getRangeAt(0).collapsed;n.holder.textContent!==``||!a||ei({api:this.api,calloutBlockId:this.blockId,firstChildBlockId:n.id,event:e})}openEmojiPicker(){if(this._dom!==null){if(this._customEmojiPicker!==void 0){this._customEmojiPicker(e=>this.setEmoji(e));return}this._emojiPicker===null&&(this._emojiPicker=new _i({onSelect:e=>this.setEmoji(e),onRemove:()=>this.setEmoji(``),i18n:this.api.i18n,locale:this.api.i18n.getLocale()}),document.body.appendChild(this._emojiPicker.getElement())),this._emojiPicker.open(this._dom.emojiButton)}}setEmoji(e){this._data.emoji=e,this._dom!==null&&(this._dom.emojiButton.textContent=e,this._dom.emojiButton.setAttribute(`aria-label`,e===``?this.api.i18n.t(Nr):e))}static get toolbox(){return{icon:t.U,titleKey:`callout`,name:Ar,searchTerms:[`callout`,`note`,`info`,`warning`,`tip`,`alert`],searchTermKeys:[`callout`,`note`,`info`,`warning`,`tip`,`alert`]}}static get conversionConfig(){return{import:e=>({emoji:Jr,textColor:null,backgroundColor:null,__importedText:e})}}static get pasteConfig(){return{tags:[{ASIDE:{style:!0}}]}}static get sanitize(){return{emoji:!1,textColor:!1,backgroundColor:!1}}static get isReadOnlySupported(){return!0}},xi=`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz`;function Si(e,t,n){let r=n[0];if(t!=null&&e>=t)throw Error(e+` >= `+t);if(e.slice(-1)===r||t&&t.slice(-1)===r)throw Error(`trailing zero`);if(t){let i=0;for(;(e[i]||r)===t[i];)i++;if(i>0)return t.slice(0,i)+Si(e.slice(i),t.slice(i),n)}let i=e?n.indexOf(e[0]):0,a=t==null?n.length:n.indexOf(t[0]);return a-i>1?n[Math.round(.5*(i+a))]:t&&t.length>1?t.slice(0,1):n[i]+Si(e.slice(1),null,n)}function Ci(e){if(e.length!==wi(e[0]))throw Error(`invalid integer part of order key: `+e)}function wi(e){if(e>=`a`&&e<=`z`)return e.charCodeAt(0)-97+2;if(e>=`A`&&e<=`Z`)return 90-e.charCodeAt(0)+2;throw Error(`invalid order key head: `+e)}function Ti(e){let t=wi(e[0]);if(t>e.length)throw Error(`invalid order key: `+e);return e.slice(0,t)}function Ei(e,t){if(e===`A`+t[0].repeat(26))throw Error(`invalid order key: `+e);let n=Ti(e);if(e.slice(n.length).slice(-1)===t[0])throw Error(`invalid order key: `+e)}function Di(e,t){Ci(e);let[n,...r]=e.split(``),i=!0;for(let e=r.length-1;i&&e>=0;e--){let n=t.indexOf(r[e])+1;n===t.length?r[e]=t[0]:(r[e]=t[n],i=!1)}if(i){if(n===`Z`)return`a`+t[0];if(n===`z`)return null;let e=String.fromCharCode(n.charCodeAt(0)+1);return e>`a`?r.push(t[0]):r.pop(),e+r.join(``)}else return n+r.join(``)}function Oi(e,t){Ci(e);let[n,...r]=e.split(``),i=!0;for(let e=r.length-1;i&&e>=0;e--){let n=t.indexOf(r[e])-1;n===-1?r[e]=t.slice(-1):(r[e]=t[n],i=!1)}if(i){if(n===`a`)return`Z`+t.slice(-1);if(n===`A`)return null;let e=String.fromCharCode(n.charCodeAt(0)-1);return e<`Z`?r.push(t.slice(-1)):r.pop(),e+r.join(``)}else return n+r.join(``)}function ki(e,t,n=xi){if(e!=null&&Ei(e,n),t!=null&&Ei(t,n),e!=null&&t!=null&&e>=t)throw Error(e+` >= `+t);if(e==null){if(t==null)return`a`+n[0];let e=Ti(t),r=t.slice(e.length);if(e===`A`+n[0].repeat(26))return e+Si(``,r,n);if(e<t)return e;let i=Oi(e,n);if(i==null)throw Error(`cannot decrement any more`);return i}if(t==null){let t=Ti(e),r=e.slice(t.length),i=Di(t,n);return i==null?t+Si(r,null,n):i}let r=Ti(e),i=e.slice(r.length),a=Ti(t),o=t.slice(a.length);if(r===a)return r+Si(i,o,n);let s=Di(r,n);if(s==null)throw Error(`cannot increment any more`);return s<t?s:r+Si(i,null,n)}var Ai={notStarted:[`Not`,`started`].join(` `),inProgress:[`In`,`progress`].join(` `),done:[`Do`,`ne`].join(``)},ji=class e{constructor(t){if(this.rows=[],(t==null?void 0:t.schema)!==void 0&&t.schema.length>0?this.schema=t.schema.map(e=>n.t({},e)):this.schema=e.createDefaultSchema(),(t==null?void 0:t.views)!==void 0&&t.views.length>0)this.views=t.views.map(e=>n.t(n.t({},e),{},{sorts:[...e.sorts],filters:[...e.filters],visibleProperties:[...e.visibleProperties]}));else{let t=this.schema.find(e=>e.type===`select`);this.views=[e.createDefaultView(t==null?void 0:t.id)]}this.activeViewId=(t==null?void 0:t.activeViewId)||(this.views.length>0?this.views[0].id:``)}getSchema(){return[...this.schema]}getProperty(e){return this.schema.find(t=>t.id===e)}addProperty(e,r,i){let a=this.schema.length>0?this.schema[this.schema.length-1].position:null,o=n.t({id:t.Ur(),name:e,type:r,position:ki(a,null)},i===void 0?{}:{config:i});return this.schema.push(o),o}updateProperty(e,t){let n=this.schema.find(t=>t.id===e);n!==void 0&&(t.name!==void 0&&(n.name=t.name),t.config!==void 0&&(n.config=t.config))}deleteProperty(e){this.schema=this.schema.filter(t=>t.id!==e)}setRows(e){this.rows=e}getOrderedRows(){return[...this.rows].sort((e,t)=>e.position.localeCompare(t.position))}getRow(e){return this.rows.find(t=>t.id===e)}createRowData(e){let n=this.getOrderedRows(),r=n.length>0?n[n.length-1].position:null;return{id:t.Ur(),position:ki(r,null),properties:e==null?{}:e}}getRowsGroupedBy(e){let t=new Map,n=this.getOrderedRows();for(let r of n){let n=r.properties[e],i=this.toGroupKey(n),a=t.get(i);a===void 0?t.set(i,[r]):a.push(r)}return t}getSelectOptions(e){var t,n;let r=this.getProperty(e);return r===void 0||r.type!==`select`&&r.type!==`multiSelect`?[]:[...(t=(n=r.config)==null?void 0:n.options)==null?[]:t].sort((e,t)=>e.position<t.position?-1:1)}getViews(){return[...this.views]}getView(e){return this.views.find(t=>t.id===e)}addView(e,n,r={}){var i,a,o;let s=[...this.views].sort((e,t)=>e.position<t.position?-1:1),c=s.length>0?s[s.length-1].position:null,l={id:t.Ur(),name:e,type:n,position:ki(c,null),groupBy:r.groupBy,sorts:(i=r.sorts)==null?[]:i,filters:(a=r.filters)==null?[]:a,visibleProperties:(o=r.visibleProperties)==null?[]:o};return this.views.push(l),l}updateView(e,t){let n=this.views.find(t=>t.id===e);n!==void 0&&Object.assign(n,t)}deleteView(e){this.views=this.views.filter(t=>t.id!==e)}hydrate(e){e.schema!==void 0&&(this.schema=structuredClone(e.schema)),e.views!==void 0&&(this.views=structuredClone(e.views))}snapshot(){return{schema:structuredClone(this.schema),views:structuredClone(this.views),activeViewId:this.activeViewId}}toGroupKey(e){return e==null?``:typeof e==`string`?e:typeof e==`boolean`||typeof e==`number`?String(e):``}static positionBetween(e,t){return ki(e,t)}static createDefaultSchema(){return[{id:t.Ur(),name:`Title`,type:`title`,position:`a0`},{id:t.Ur(),name:`Status`,type:`select`,position:`a1`,config:{options:[{id:t.Ur(),label:Ai.notStarted,color:`gray`,position:`a0`},{id:t.Ur(),label:Ai.inProgress,color:`blue`,position:`a1`},{id:t.Ur(),label:Ai.done,color:`green`,position:`a2`}]}}]}static createDefaultView(e){return{id:t.Ur(),name:`Board`,type:`board`,position:`a0`,groupBy:e,sorts:[],filters:[],visibleProperties:[]}}},Mi=class{constructor({readOnly:e,i18n:t,options:n,getRows:r,titlePropertyId:i,onTitleEdit:a}){this.readOnly=e,this.i18n=t,this.options=n,this.getRows=r,this.titlePropertyId=i,this.onTitleEdit=a}createView(){let e=document.createElement(`div`);e.setAttribute(`data-blok-tool`,`database`),e.setAttribute(`role`,`region`),e.setAttribute(`aria-label`,this.i18n.t(`tools.database.kanbanBoard`)),e.style.display=`flex`;let t=document.createElement(`div`);t.setAttribute(`data-blok-database-board`,``),t.style.display=`flex`,t.style.overflowX=`auto`,t.style.alignItems=`flex-start`,t.style.gap=`12px`,t.style.paddingBottom=`24px`,t.style.flex=`1`,t.style.minWidth=`0`;for(let e of this.options){let n=this.createColumnElement(e,this.getRows(e.id),this.titlePropertyId);t.appendChild(n)}if(!this.readOnly){let e=document.createElement(`button`);e.setAttribute(`data-blok-database-add-column`,``),e.setAttribute(`aria-label`,this.i18n.t(`tools.database.addColumn`)),e.textContent=`+ `+this.i18n.t(`tools.database.addColumn`),e.style.minWidth=`260px`,e.style.flex=`0 0 260px`,t.appendChild(e)}return e.appendChild(t),e}appendRow(e,t){let n=this.createCardElement(t,this.titlePropertyId);e.appendChild(n),this.updateColumnCount(e)}removeRow(e,t){let n=e.querySelector(`[data-row-id="${t}"]`),r=n==null?void 0:n.closest(`[data-blok-database-cards]`);n==null||n.remove(),r!==null&&this.updateColumnCount(r)}updateRowTitle(e,t,n){let r=e.querySelector(`[data-row-id="${t}"]`),i=r==null?void 0:r.querySelector(`[data-blok-database-card-title]`);i!=null&&(n?(i.textContent=n,i.removeAttribute(`data-placeholder`),r==null||r.removeAttribute(`data-empty`)):(i.textContent=this.i18n.t(`tools.database.cardTitlePlaceholder`),i.setAttribute(`data-placeholder`,``),r==null||r.setAttribute(`data-empty`,``)))}appendGroup(e,t){let n=this.createColumnElement(t,[],``),r=e.querySelector(`[data-blok-database-board]`),i=r==null?e:r,a=i.querySelector(`[data-blok-database-add-column]`);a?i.insertBefore(n,a):i.appendChild(n)}removeGroup(e,t){let n=e.querySelector(`[data-option-id="${t}"]`);n==null||n.remove()}createColumnElement(e,n,r){let i=document.createElement(`div`);i.setAttribute(`data-blok-database-column`,``),i.setAttribute(`data-option-id`,e.id),i.setAttribute(`role`,`group`),i.setAttribute(`aria-label`,e.label),i.style.display=`flex`,i.style.flexDirection=`column`,i.style.minWidth=`260px`,i.style.flex=`0 0 260px`,e.color!==void 0&&(i.style.backgroundColor=`var(--blok-color-${e.color}-bg)`,i.setAttribute(`data-color`,e.color));let a=document.createElement(`div`);a.setAttribute(`data-blok-database-column-header`,``),a.style.display=`flex`,a.style.alignItems=`center`,a.style.padding=`0 0 6px 0`,a.style.borderRadius=`4px`,a.style.gap=`6px`,a.style.cursor=`grab`;let o=document.createElement(`div`);if(o.setAttribute(`data-blok-database-column-pill`,``),e.color!==void 0){o.style.backgroundColor=`color-mix(in srgb, var(--blok-color-${e.color}-text) 20%, var(--blok-color-${e.color}-bg))`,o.style.color=`var(--blok-color-${e.color}-text)`;let t=document.createElement(`span`);t.setAttribute(`data-blok-database-column-dot`,``),t.style.backgroundColor=`var(--blok-color-${e.color}-text)`,o.appendChild(t)}let s=document.createElement(`div`);s.setAttribute(`data-blok-database-column-title`,``),s.textContent=e.label,o.appendChild(s),a.appendChild(o);let c=document.createElement(`span`);c.setAttribute(`data-blok-database-column-count`,``),c.textContent=String(n.length),e.color!==void 0&&(c.style.color=`var(--blok-color-${e.color}-text)`),a.appendChild(c),i.appendChild(a);let l=document.createElement(`div`);l.setAttribute(`data-blok-database-cards`,``),l.setAttribute(`role`,`list`),l.style.display=`flex`,l.style.flexDirection=`column`,l.style.gap=`8px`,l.style.paddingTop=`6px`,l.style.minHeight=`40px`;for(let e of n){let t=this.createCardElement(e,r);l.appendChild(t)}if(i.appendChild(l),!this.readOnly){let n=document.createElement(`button`);n.setAttribute(`data-blok-database-add-card`,``),n.setAttribute(`data-option-id`,e.id),n.setAttribute(`aria-label`,this.i18n.t(`tools.database.addCard`));let r=document.createElement(`span`);r.setAttribute(`data-blok-database-add-card-icon`,``),r.innerHTML=t.sn,n.appendChild(r);let a=document.createElement(`span`);a.textContent=this.i18n.t(`tools.database.newPage`),n.appendChild(a),e.color!==void 0&&(n.style.borderColor=`color-mix(in srgb, var(--blok-color-${e.color}-text) 30%, transparent)`,n.style.color=`var(--blok-color-${e.color}-text)`),i.appendChild(n)}return i}createCardElement(e,n){var r;let i=document.createElement(`div`),a=(r=e.properties[n])==null?``:r;i.setAttribute(`data-blok-database-card`,``),i.setAttribute(`data-row-id`,e.id),i.setAttribute(`role`,`listitem`),i.style.padding=`10px 12px`,i.style.borderRadius=`10px`,i.style.cursor=`pointer`,i.style.position=`relative`,i.style.backgroundColor=`var(--blok-database-card-bg)`,i.style.boxShadow=`var(--blok-database-card-shadow)`;let o=document.createElement(`div`);if(o.setAttribute(`data-blok-database-card-title`,``),a?o.textContent=a:(o.textContent=this.i18n.t(`tools.database.cardTitlePlaceholder`),o.setAttribute(`data-placeholder`,``),i.setAttribute(`data-empty`,``)),i.appendChild(o),!this.readOnly){let n=document.createElement(`div`);n.setAttribute(`data-blok-database-card-actions`,``);let r=document.createElement(`button`);r.setAttribute(`data-blok-database-edit-card`,``),r.setAttribute(`data-row-id`,e.id),r.setAttribute(`aria-label`,this.i18n.t(`tools.database.editCardTitle`)),r.innerHTML=t.an,r.addEventListener(`click`,t=>{t.stopPropagation(),this.startCardTitleEdit(i,e.id)});let a=document.createElement(`button`);a.setAttribute(`data-blok-database-card-menu`,``),a.setAttribute(`data-row-id`,e.id),a.setAttribute(`aria-label`,this.i18n.t(`tools.database.cardMenuLabel`)),a.innerHTML=t.lt,n.appendChild(r),n.appendChild(a),i.appendChild(n)}return i}startCardTitleEdit(e,t){var n;let r=e.querySelector(`[data-blok-database-card-title]`);if(r===null)return;let i=(n=r.textContent)==null?``:n,a=document.createElement(`input`);a.type=`text`,a.value=i,a.setAttribute(`data-blok-database-card-title-input`,``),a.setAttribute(`aria-label`,this.i18n.t(`tools.database.editCardTitle`)),a.style.width=`100%`,a.style.boxSizing=`border-box`;let o={committed:!1},s=()=>{if(o.committed)return;o.committed=!0;let n=a.value.trim()||i,r=document.createElement(`div`);if(r.setAttribute(`data-blok-database-card-title`,``),r.textContent=n,a.replaceWith(r),n!==i){var s;(s=this.onTitleEdit)==null||s.call(this,t,n)}n&&e.removeAttribute(`data-empty`)},c=()=>{if(o.committed)return;o.committed=!0;let e=document.createElement(`div`);e.setAttribute(`data-blok-database-card-title`,``),e.textContent=i,a.replaceWith(e)};a.addEventListener(`blur`,s),a.addEventListener(`keydown`,e=>{e.stopPropagation(),e.key===`Enter`?(a.removeEventListener(`blur`,s),s()):e.key===`Escape`&&(a.removeEventListener(`blur`,s),c())}),r.replaceWith(a),a.focus(),a.select()}updateColumnCount(e){let t=e.closest(`[data-blok-database-column]`);if(t===null)return;let n=t.querySelector(`[data-blok-database-column-count]`);if(n!==null){let t=e.querySelectorAll(`[data-blok-database-card]`).length;n.textContent=String(t)}}},Ni=class{constructor({readOnly:e,i18n:t,rows:n,titlePropertyId:r,schema:i,visiblePropertyIds:a,options:o,getRows:s}){this.readOnly=e,this.i18n=t,this.rows=n,this.titlePropertyId=r,this.schema=i,this.visiblePropertyIds=a,this.groupOptions=o,this.getGroupRows=s}createView(){let e=document.createElement(`div`);if(e.setAttribute(`data-blok-database-list`,``),this.groupOptions!==void 0&&this.groupOptions.length>0&&this.getGroupRows!==void 0)for(let t of this.groupOptions){let n=this.getGroupRows(t.id),r=this.createGroupElement(t,n);e.appendChild(r)}else{e.setAttribute(`role`,`list`),e.setAttribute(`aria-label`,this.i18n.t(`tools.database.listView`));for(let t of this.rows){let n=this.createRowElement(t);e.appendChild(n)}if(!this.readOnly){let t=this.createAddRowButton();e.appendChild(t)}}return e}createGroupElement(e,t){let n=document.createElement(`div`);n.setAttribute(`data-blok-database-list-group`,``),n.setAttribute(`data-option-id`,e.id);let r=document.createElement(`div`);r.setAttribute(`data-blok-database-list-group-header`,``);let i=document.createElement(`span`);i.setAttribute(`data-blok-database-list-group-toggle`,``),i.textContent=`▼`;let a=document.createElement(`span`);a.setAttribute(`data-blok-database-list-group-dot`,``),e.color!==void 0&&(a.style.backgroundColor=`var(--blok-color-${e.color}-text)`);let o=document.createElement(`span`);o.setAttribute(`data-blok-database-list-group-title`,``),o.textContent=e.label;let s=document.createElement(`span`);s.setAttribute(`data-blok-database-list-group-count`,``),s.textContent=String(t.length),r.appendChild(i),r.appendChild(a),r.appendChild(o),r.appendChild(s);let c=document.createElement(`div`);c.setAttribute(`data-blok-database-list-rows`,``),c.setAttribute(`role`,`list`);for(let e of t){let t=this.createRowElement(e);c.appendChild(t)}let l=this.readOnly?null:this.createAddRowButton(e.id);return r.addEventListener(`click`,()=>{let e=c.style.display===`none`;c.style.display=e?``:`none`,i.textContent=e?`▼`:`▶`,l!==null&&(l.style.display=e?``:`none`)}),n.appendChild(r),n.appendChild(c),l!==null&&n.appendChild(l),n}appendRow(e,t){let n=this.createRowElement(t),r=e.querySelector(`[data-blok-database-add-row]`);r===null?e.appendChild(n):e.insertBefore(n,r)}removeRow(e,t){let n=e.querySelector(`[data-row-id="${t}"]`);n==null||n.remove()}updateRowTitle(e,t,n){let r=e.querySelector(`[data-row-id="${t}"]`),i=r==null?void 0:r.querySelector(`[data-blok-database-list-row-title]`);i!=null&&(n?(i.textContent=n,i.removeAttribute(`data-placeholder`)):(i.textContent=this.i18n.t(`tools.database.rowTitlePlaceholder`),i.setAttribute(`data-placeholder`,``)))}createRowElement(e){var t;let n=document.createElement(`div`),r=(t=e.properties[this.titlePropertyId])==null?``:t;n.setAttribute(`data-blok-database-list-row`,``),n.setAttribute(`data-row-id`,e.id),n.setAttribute(`role`,`listitem`);let i=document.createElement(`div`);i.setAttribute(`data-blok-database-list-row-title`,``),r?i.textContent=r:(i.textContent=this.i18n.t(`tools.database.rowTitlePlaceholder`),i.setAttribute(`data-placeholder`,``)),n.appendChild(i);let a=this.createPropertiesElement(e);return n.appendChild(a),n}createPropertiesElement(e){let t=document.createElement(`div`);t.setAttribute(`data-blok-database-list-row-properties`,``);for(let n of this.visiblePropertyIds){let r=this.schema.find(e=>e.id===n);if(r===void 0)continue;let i=e.properties[n],a=this.createPropertyBadge(r,i);a!==null&&t.appendChild(a)}let n=document.createElement(`button`);if(n.setAttribute(`data-blok-database-list-row-open`,``),n.setAttribute(`aria-label`,this.i18n.t(`tools.database.openRow`)),t.appendChild(n),!this.readOnly){let n=document.createElement(`button`);n.setAttribute(`data-blok-database-delete-row`,``),n.setAttribute(`data-row-id`,e.id),n.setAttribute(`aria-label`,this.i18n.t(`tools.database.deleteRow`)),n.textContent=`×`,t.appendChild(n)}return t}createPropertyBadge(e,t){if(t==null)return null;let n=document.createElement(`span`);if(n.setAttribute(`data-blok-database-list-row-property`,``),n.setAttribute(`data-property-id`,e.id),e.type===`select`){var r,i;let a=((r=(i=e.config)==null?void 0:i.options)==null?[]:r).find(e=>e.id===t);if(a===void 0)return null;n.textContent=a.label,a.color!==void 0&&(n.style.backgroundColor=`var(--blok-color-${a.color}-bg)`,n.style.color=`var(--blok-color-${a.color}-text)`)}else if(e.type===`checkbox`){let e=document.createElement(`input`);e.type=`checkbox`,e.checked=t===!0,n.appendChild(e)}else if(typeof t==`string`||typeof t==`number`)n.textContent=String(t);else return null;return n}createAddRowButton(e){let t=document.createElement(`button`);return t.setAttribute(`data-blok-database-add-row`,``),t.setAttribute(`aria-label`,this.i18n.t(`tools.database.addRow`)),t.textContent=`+ `+this.i18n.t(`tools.database.newRow`),e!==void 0&&t.setAttribute(`data-option-id`,e),t}},Pi=500,Fi=class{constructor(e,t){this.pendingTimers=new Map,this.pendingUpdates=new Map,this.pendingPropertyTimers=new Map,this.pendingPropertyUpdates=new Map,this.adapter=e,this.onError=t}async safeCall(e){var t=this;if(t.adapter!==void 0)try{return await e(t.adapter)}catch(e){var n;(n=t.onError)==null||n.call(t,e);return}}async syncLoadDatabase(){return this.safeCall(e=>e.loadDatabase())}async syncCreateRow(e){return this.safeCall(t=>t.createRow(e))}syncUpdateRow(e){if(this.adapter===void 0)return;let{rowId:t}=e,r=this.pendingTimers.get(t);r!==void 0&&clearTimeout(r);let i=this.pendingUpdates.get(t);this.pendingUpdates.set(t,i===void 0?e:n.t(n.t(n.t({},i),e),{},{properties:n.t(n.t({},i.properties),e.properties)})),this.pendingTimers.set(t,setTimeout(()=>{this.flushRow(t)},Pi))}async syncMoveRow(e){var t=this;return t.flushRow(e.rowId),t.safeCall(t=>t.moveRow(e))}async syncDeleteRow(e){await this.safeCall(t=>t.deleteRow(e))}async syncCreateProperty(e){return this.safeCall(t=>t.createProperty(e))}async syncUpdateProperty(e){return this.safeCall(t=>t.updateProperty(e))}syncUpdatePropertyDebounced(e){if(this.adapter===void 0)return;let{propertyId:t}=e,n=this.pendingPropertyTimers.get(t);n!==void 0&&clearTimeout(n),this.pendingPropertyUpdates.set(t,e),this.pendingPropertyTimers.set(t,setTimeout(()=>{this.flushProperty(t)},Pi))}async syncDeleteProperty(e){await this.safeCall(t=>t.deleteProperty(e))}async syncCreateView(e){return this.safeCall(t=>t.createView(e))}async syncUpdateView(e){return this.safeCall(t=>t.updateView(e))}async syncDeleteView(e){await this.safeCall(t=>t.deleteView(e))}flushPendingUpdates(){for(let e of this.pendingTimers.keys())this.flushRow(e)}flushPendingPropertyUpdates(){for(let e of this.pendingPropertyTimers.keys())this.flushProperty(e)}destroy(){for(let e of this.pendingTimers.values())clearTimeout(e);this.pendingTimers.clear(),this.pendingUpdates.clear();for(let e of this.pendingPropertyTimers.values())clearTimeout(e);this.pendingPropertyTimers.clear(),this.pendingPropertyUpdates.clear()}flushRow(e){let t=this.pendingTimers.get(e);t!==void 0&&clearTimeout(t),this.pendingTimers.delete(e);let n=this.pendingUpdates.get(e);this.pendingUpdates.delete(e),n!==void 0&&this.safeCall(e=>e.updateRow(n))}flushProperty(e){let t=this.pendingPropertyTimers.get(e);t!==void 0&&clearTimeout(t),this.pendingPropertyTimers.delete(e);let n=this.pendingPropertyUpdates.get(e);this.pendingPropertyUpdates.delete(e),n!==void 0&&this.safeCall(e=>e.updateProperty(n))}},Ii=10,Li=class{constructor(e){this.isDragging=!1,this.rowId=``,this.startX=0,this.startY=0,this.ghostEl=null,this.sourceCard=null,this.sourceCardHeight=0,this.ghostOffsetX=0,this.ghostOffsetY=0,this.gapTarget=null,this.gapContainer=null,this.wrapper=e.wrapper,this.onDrop=e.onDrop,this.boundPointerMove=this.handlePointerMove.bind(this),this.boundPointerUp=this.handlePointerUp.bind(this),this.boundPointerCancel=this.handlePointerCancel.bind(this),this.boundKeyDown=this.handleKeyDown.bind(this)}beginTracking(e,t,n){this.cleanup(),this.rowId=e,this.startX=t,this.startY=n,this.isDragging=!1,this.sourceCard=this.wrapper.querySelector(`[data-row-id="${e}"]`),document.addEventListener(`pointermove`,this.boundPointerMove),document.addEventListener(`pointerup`,this.boundPointerUp),document.addEventListener(`pointercancel`,this.boundPointerCancel),document.addEventListener(`keydown`,this.boundKeyDown)}cleanup(){var e;document.removeEventListener(`pointermove`,this.boundPointerMove),document.removeEventListener(`pointerup`,this.boundPointerUp),document.removeEventListener(`pointercancel`,this.boundPointerCancel),document.removeEventListener(`keydown`,this.boundKeyDown),(e=this.ghostEl)==null||e.remove(),this.ghostEl=null,this.clearGap(),this.wrapper.removeAttribute(`data-blok-database-dragging`),this.sourceCard&&(this.sourceCard.style.opacity=``,this.sourceCard=null),this.isDragging=!1,this.rowId=``,this.sourceCardHeight=0,this.ghostOffsetX=0,this.ghostOffsetY=0}destroy(){this.cleanup()}handlePointerMove(e){let t=Math.abs(e.clientX-this.startX),n=Math.abs(e.clientY-this.startY);!this.isDragging&&(t>Ii||n>Ii)&&(this.isDragging=!0,this.startActiveDrag(e)),this.isDragging&&(this.updateGhostPosition(e),this.updateDropIndicator(e))}handlePointerUp(e){this.isDragging&&this.commitDrop(e),this.cleanup()}handlePointerCancel(){this.cleanup()}handleKeyDown(e){e.key===`Escape`&&this.cleanup()}startActiveDrag(e){if(this.sourceCard){let e=this.sourceCard.getBoundingClientRect();this.sourceCardHeight=e.height,this.ghostOffsetX=this.startX-e.left,this.ghostOffsetY=this.startY-e.top,this.sourceCard.style.opacity=`0.4`}this.wrapper.setAttribute(`data-blok-database-dragging`,``),this.createGhost(e)}createGhost(e){let t=document.createElement(`div`);t.setAttribute(`data-blok-database-ghost`,``),t.setAttribute(`contenteditable`,`false`);let n=t.style;if(n.position=`fixed`,n.pointerEvents=`none`,n.opacity=`0.85`,n.zIndex=`50`,n.boxShadow=`0 12px 28px rgba(0, 0, 0, 0.2), 0 4px 10px rgba(0, 0, 0, 0.1)`,n.borderRadius=`8px`,n.overflow=`hidden`,n.transform=`rotate(2deg) scale(1.02)`,n.transformOrigin=`center center`,this.sourceCard){let r=this.sourceCard.cloneNode(!0);r.style.opacity=``,t.appendChild(r);let i=this.sourceCard.getBoundingClientRect();n.left=`${e.clientX-this.ghostOffsetX}px`,n.top=`${e.clientY-this.ghostOffsetY}px`,n.width=`${i.width}px`}else n.left=`${e.clientX}px`,n.top=`${e.clientY}px`;document.body.appendChild(t),this.ghostEl=t}updateGhostPosition(e){this.ghostEl&&(this.ghostEl.style.left=`${e.clientX-this.ghostOffsetX}px`,this.ghostEl.style.top=`${e.clientY-this.ghostOffsetY}px`)}updateDropIndicator(e){let t=this.findTargetColumn(e.clientX);if(!t){this.clearGap();return}let n=this.getDropPosition(t,e.clientY).beforeEl;if(n){if(n===this.gapTarget)return;this.clearGap(),n.style.marginTop=`${this.sourceCardHeight}px`,this.gapTarget=n}else{let e=t.querySelector(`[data-blok-database-cards]`);if(!e){this.clearGap();return}if(e===this.gapContainer)return;this.clearGap(),e.style.paddingBottom=`${this.sourceCardHeight}px`,this.gapContainer=e}}clearGap(){this.gapTarget&&(this.gapTarget.style.marginTop=``,this.gapTarget=null),this.gapContainer&&(this.gapContainer.style.paddingBottom=``,this.gapContainer=null)}findTargetColumn(e){let t=Array.from(this.wrapper.querySelectorAll(`[data-blok-database-column]`));for(let n of t){let t=n.getBoundingClientRect();if(e>=t.left&&e<=t.right)return n}return null}getDropPosition(e,t){let n=Array.from(e.querySelectorAll(`[data-blok-database-card]`)).filter(e=>e.getAttribute(`data-row-id`)!==this.rowId);for(let e of n){let n=e.getBoundingClientRect();if(t<n.top+n.height/2)return{beforeEl:e}}return{beforeEl:null}}resolveAfterRowId(e,t,n){return e?n>0?t[n-1].getAttribute(`data-row-id`):null:t.length>0?t[t.length-1].getAttribute(`data-row-id`):null}commitDrop(e){var t;let n=this.findTargetColumn(e.clientX);if(!n)return;let r=(t=n.getAttribute(`data-option-id`))==null?``:t,i=this.getDropPosition(n,e.clientY),a=Array.from(n.querySelectorAll(`[data-blok-database-card]`)).filter(e=>e.getAttribute(`data-row-id`)!==this.rowId),o=i.beforeEl?i.beforeEl.getAttribute(`data-row-id`):null,s=i.beforeEl?a.indexOf(i.beforeEl):-1,c=this.resolveAfterRowId(i.beforeEl,a,s);this.onDrop({rowId:this.rowId,toOptionId:r,beforeRowId:o,afterRowId:c})}},Ri=10,zi=class{constructor(e){this.isDragging=!1,this.optionId=``,this.startX=0,this.startY=0,this.ghostEl=null,this.sourceColumn=null,this.sourceColumnWidth=0,this.ghostOffsetX=0,this.gapTarget=null,this.gapContainer=null,this.wrapper=e.wrapper,this.onDrop=e.onDrop,this.boundPointerMove=this.handlePointerMove.bind(this),this.boundPointerUp=this.handlePointerUp.bind(this),this.boundPointerCancel=this.handlePointerCancel.bind(this),this.boundKeyDown=this.handleKeyDown.bind(this)}beginTracking(e,t,n){this.cleanup(),this.optionId=e,this.startX=t,this.startY=n,this.isDragging=!1,this.sourceColumn=this.wrapper.querySelector(`[data-option-id="${e}"]`),document.addEventListener(`pointermove`,this.boundPointerMove),document.addEventListener(`pointerup`,this.boundPointerUp),document.addEventListener(`pointercancel`,this.boundPointerCancel),document.addEventListener(`keydown`,this.boundKeyDown)}cleanup(){var e;document.removeEventListener(`pointermove`,this.boundPointerMove),document.removeEventListener(`pointerup`,this.boundPointerUp),document.removeEventListener(`pointercancel`,this.boundPointerCancel),document.removeEventListener(`keydown`,this.boundKeyDown),(e=this.ghostEl)==null||e.remove(),this.ghostEl=null,this.clearGap(),this.wrapper.removeAttribute(`data-blok-database-column-reordering`),this.sourceColumn&&(this.sourceColumn.style.opacity=``,this.sourceColumn=null),this.isDragging=!1,this.optionId=``,this.sourceColumnWidth=0,this.ghostOffsetX=0}destroy(){this.cleanup()}handlePointerMove(e){let t=Math.abs(e.clientX-this.startX);!this.isDragging&&t>Ri&&(this.isDragging=!0,this.startActiveDrag(e)),this.isDragging&&(this.updateGhostPosition(e),this.updateDropIndicator(e.clientX))}handlePointerUp(e){this.isDragging&&this.commitDrop(e),this.cleanup()}handlePointerCancel(){this.cleanup()}handleKeyDown(e){e.key===`Escape`&&this.cleanup()}startActiveDrag(e){if(this.sourceColumn){let e=this.sourceColumn.getBoundingClientRect();this.sourceColumnWidth=e.width,this.ghostOffsetX=this.startX-e.left,this.sourceColumn.style.opacity=`0.4`}this.wrapper.setAttribute(`data-blok-database-column-reordering`,``),this.createGhost(e)}createGhost(e){let t=document.createElement(`div`);t.setAttribute(`data-blok-database-column-ghost`,``),t.setAttribute(`contenteditable`,`false`);let n=t.style;if(n.position=`fixed`,n.pointerEvents=`none`,n.opacity=`0.85`,n.zIndex=`50`,n.boxShadow=`0 12px 28px rgba(0, 0, 0, 0.2), 0 4px 10px rgba(0, 0, 0, 0.1)`,n.borderRadius=`10px`,n.overflow=`hidden`,n.transform=`rotate(1deg) scale(1.02)`,n.transformOrigin=`center center`,this.sourceColumn){let r=this.sourceColumn.cloneNode(!0);r.style.opacity=``,t.appendChild(r);let i=this.sourceColumn.getBoundingClientRect();n.left=`${e.clientX-this.ghostOffsetX}px`,n.top=`${i.top}px`,n.width=`${i.width}px`}else n.left=`${e.clientX}px`,n.top=`${e.clientY}px`;document.body.appendChild(t),this.ghostEl=t}updateGhostPosition(e){this.ghostEl&&(this.ghostEl.style.left=`${e.clientX-this.ghostOffsetX}px`)}updateDropIndicator(e){let t=this.getDropPosition(e);if(t.beforeColumn){if(t.beforeColumn===this.gapTarget)return;this.clearGap(),t.beforeColumn.style.marginLeft=`${this.sourceColumnWidth}px`,this.gapTarget=t.beforeColumn}else this.applyEndGap()}applyEndGap(){let e=this.wrapper.querySelector(`[data-blok-database-board]`);!e||e===this.gapContainer||(this.clearGap(),e.style.paddingRight=`${this.sourceColumnWidth}px`,this.gapContainer=e)}clearGap(){this.gapTarget&&(this.gapTarget.style.marginLeft=``,this.gapTarget=null),this.gapContainer&&(this.gapContainer.style.paddingRight=``,this.gapContainer=null)}getDropPosition(e){let t=Array.from(this.wrapper.querySelectorAll(`[data-blok-database-column]`)).filter(e=>e.getAttribute(`data-option-id`)!==this.optionId);for(let n of t){let r=n.getBoundingClientRect();if(e<r.left+r.width/2){let e=t.indexOf(n);return{beforeColumn:n,afterColumn:e>0?t[e-1]:null}}}return{beforeColumn:null,afterColumn:t.length>0?t[t.length-1]:null}}commitDrop(e){let t=this.getDropPosition(e.clientX),n=t.beforeColumn?t.beforeColumn.getAttribute(`data-option-id`):null,r=t.afterColumn?t.afterColumn.getAttribute(`data-option-id`):null;this.onDrop({optionId:this.optionId,beforeOptionId:n,afterOptionId:r})}},Bi=class{constructor(e){this.options=e,this.i18n=e.i18n}makeEditable(e,t){let n=e.querySelector(`[data-blok-database-column-title]`);if(n){var r;let e=document.createElement(`input`);e.type=`text`,e.value=(r=n.textContent)==null?``:r,e.setAttribute(`data-blok-database-column-title-input`,``),e.setAttribute(`aria-label`,this.i18n.t(`tools.database.renameColumn`));let i=()=>{e.size=Math.max(e.value.length,1)};i(),e.addEventListener(`input`,i),e.addEventListener(`change`,()=>{this.options.onRename(t,e.value)}),n.replaceWith(e)}this.appendDeleteButton(e,t)}appendDeleteButton(e,t){let n=document.createElement(`button`);n.setAttribute(`data-blok-database-delete-column`,``),n.setAttribute(`aria-label`,this.i18n.t(`tools.database.deleteColumn`)),n.setAttribute(`data-option-id`,t),n.addEventListener(`click`,()=>{this.options.onDelete(t)}),e.appendChild(n)}makePillTitleEditable(e,t){let n=e.querySelector(`[data-blok-database-column-title]`);n!==null&&(n.style.cursor=`text`,n.addEventListener(`click`,r=>{var i;r.stopPropagation();let a=(i=n.textContent)==null?``:i,o=document.createElement(`input`);o.type=`text`,o.value=a,o.setAttribute(`data-blok-database-column-title-input`,``),o.setAttribute(`aria-label`,this.i18n.t(`tools.database.renameColumn`));let s=()=>{o.size=Math.max(o.value.length,1)};s(),o.addEventListener(`input`,s),o.addEventListener(`input`,()=>{var e,n;(e=(n=this.options).onRenameInput)==null||e.call(n,t,o.value)});let c={done:!1},l=e=>{let t=document.createElement(`div`);return t.setAttribute(`data-blok-database-column-title`,``),t.style.cursor=`text`,t.textContent=e,t},u=()=>{if(c.done)return;c.done=!0;let n=o.value.trim()||a,r=l(n);if(o.replaceWith(r),this.makePillTitleEditable(e,t),n!==a){var i,s;(i=(s=this.options).onRenameCommit)==null||i.call(s,t,n),this.options.onRename(t,n)}},d=()=>{if(c.done)return;c.done=!0;let n=l(a);o.replaceWith(n),this.makePillTitleEditable(e,t)};o.addEventListener(`blur`,u),o.addEventListener(`keydown`,e=>{e.stopPropagation(),e.key===`Enter`?u():e.key===`Escape`&&(o.removeEventListener(`blur`,u),d())}),n.replaceWith(o),o.focus(),o.select()}))}destroy(){}},Vi=10,Hi=class{constructor(e){this.isDragging=!1,this.rowId=``,this.startY=0,this.ghostEl=null,this.sourceRow=null,this.sourceRowHeight=0,this.ghostOffsetY=0,this.gapTarget=null,this.wrapper=e.wrapper,this.onDrop=e.onDrop,this.boundPointerMove=this.handlePointerMove.bind(this),this.boundPointerUp=this.handlePointerUp.bind(this),this.boundPointerCancel=this.handlePointerCancel.bind(this),this.boundKeyDown=this.handleKeyDown.bind(this)}beginTracking(e,t,n){this.cleanup(),this.rowId=e,this.startY=n,this.isDragging=!1,this.sourceRow=this.wrapper.querySelector(`[data-row-id="${e}"]`),document.addEventListener(`pointermove`,this.boundPointerMove),document.addEventListener(`pointerup`,this.boundPointerUp),document.addEventListener(`pointercancel`,this.boundPointerCancel),document.addEventListener(`keydown`,this.boundKeyDown)}cleanup(){var e;document.removeEventListener(`pointermove`,this.boundPointerMove),document.removeEventListener(`pointerup`,this.boundPointerUp),document.removeEventListener(`pointercancel`,this.boundPointerCancel),document.removeEventListener(`keydown`,this.boundKeyDown),(e=this.ghostEl)==null||e.remove(),this.ghostEl=null,this.clearGap(),this.sourceRow&&(this.sourceRow.style.opacity=``,this.sourceRow=null),this.isDragging=!1,this.rowId=``,this.sourceRowHeight=0,this.ghostOffsetY=0}destroy(){this.cleanup()}handlePointerMove(e){let t=Math.abs(e.clientY-this.startY);!this.isDragging&&t>Vi&&(this.isDragging=!0,this.startActiveDrag(e)),this.isDragging&&(this.updateGhostPosition(e),this.updateDropIndicator(e))}handlePointerUp(e){this.isDragging&&this.commitDrop(e),this.cleanup()}handlePointerCancel(){this.cleanup()}handleKeyDown(e){e.key===`Escape`&&this.cleanup()}startActiveDrag(e){if(this.sourceRow){let e=this.sourceRow.getBoundingClientRect();this.sourceRowHeight=e.height,this.ghostOffsetY=this.startY-e.top,this.sourceRow.style.opacity=`0.4`}this.createGhost(e)}createGhost(e){let t=document.createElement(`div`);t.setAttribute(`data-blok-database-ghost`,``),t.setAttribute(`contenteditable`,`false`);let n=t.style;if(n.position=`fixed`,n.pointerEvents=`none`,n.opacity=`0.85`,n.zIndex=`50`,n.boxShadow=`0 12px 28px rgba(0, 0, 0, 0.2), 0 4px 10px rgba(0, 0, 0, 0.1)`,n.borderRadius=`8px`,n.overflow=`hidden`,this.sourceRow){let r=this.sourceRow.cloneNode(!0);r.style.opacity=``,t.appendChild(r);let i=this.sourceRow.getBoundingClientRect();n.left=`${i.left}px`,n.top=`${e.clientY-this.ghostOffsetY}px`,n.width=`${i.width}px`}else n.left=`0px`,n.top=`${e.clientY}px`;document.body.appendChild(t),this.ghostEl=t}updateGhostPosition(e){this.ghostEl&&(this.ghostEl.style.top=`${e.clientY-this.ghostOffsetY}px`)}updateDropIndicator(e){let t=this.getDropPosition(e.clientY).beforeEl;if(t){if(t===this.gapTarget)return;this.clearGap(),t.style.marginTop=`${this.sourceRowHeight}px`,this.gapTarget=t}else this.clearGap()}clearGap(){this.gapTarget&&(this.gapTarget.style.marginTop=``,this.gapTarget=null)}getDropPosition(e){let t=Array.from(this.wrapper.querySelectorAll(`[data-blok-database-list-row]`)).filter(e=>e.getAttribute(`data-row-id`)!==this.rowId);for(let n of t){let t=n.getBoundingClientRect();if(e<t.top+t.height/2)return{beforeEl:n}}return{beforeEl:null}}commitDrop(e){let t=this.getDropPosition(e.clientY),n=Array.from(this.wrapper.querySelectorAll(`[data-blok-database-list-row]`)).filter(e=>e.getAttribute(`data-row-id`)!==this.rowId),r=t.beforeEl?t.beforeEl.getAttribute(`data-row-id`):null,i=t.beforeEl?n.indexOf(t.beforeEl):-1,a=this.resolveAfterRowId(t.beforeEl,n,i);this.onDrop({rowId:this.rowId,beforeRowId:r,afterRowId:a})}resolveAfterRowId(e,t,n){return e?n>0?t[n-1].getAttribute(`data-row-id`):null:t.length>0?t[t.length-1].getAttribute(`data-row-id`):null}},Ui=[{type:`text`,icon:t.vn,labelKey:`tools.database.propertyTypeText`},{type:`number`,icon:t.kt,labelKey:`tools.database.propertyTypeNumber`},{type:`select`,icon:t.pn,labelKey:`tools.database.propertyTypeSelect`},{type:`multiSelect`,icon:t.nn,labelKey:`tools.database.propertyTypeMultiSelect`},{type:`date`,icon:t.H,labelKey:`tools.database.propertyTypeDate`},{type:`checkbox`,icon:t.qt,labelKey:`tools.database.propertyTypeCheckbox`},{type:`url`,icon:t.St,labelKey:`tools.database.propertyTypeUrl`}],Wi=class{constructor(e){this.popoverEl=null,this.boundOutsideClick=null,this.onSelect=e.onSelect,this.i18n=e.i18n}open(e){var t,n;this.close();let r=document.createElement(`div`);r.setAttribute(`data-blok-popover`,``),r.setAttribute(`data-blok-popover-opened`,``),r.setAttribute(`data-blok-database-property-type-popover`,``),r.style.position=`fixed`,r.style.zIndex=`1000`;let i=e.getBoundingClientRect();r.style.top=`${i.bottom+4}px`,r.style.left=`${i.left}px`;let a=document.createElement(`div`);a.setAttribute(`data-blok-database-property-type-heading`,``),a.textContent=(t=(n=this.i18n)==null?void 0:n.t(`tools.database.propertyTypeHeading`))==null?`tools.database.propertyTypeHeading`:t,r.appendChild(a);for(let e of Ui){var o,s;let t=document.createElement(`div`);t.setAttribute(`data-blok-database-property-type-option`,e.type);let n=document.createElement(`div`);n.setAttribute(`data-blok-database-property-type-option-icon`,``),n.innerHTML=e.icon,t.appendChild(n);let i=document.createElement(`span`);i.textContent=(o=(s=this.i18n)==null?void 0:s.t(e.labelKey))==null?e.labelKey:o,t.appendChild(i),t.addEventListener(`click`,()=>{this.onSelect(e.type),this.close()}),r.appendChild(t)}document.body.appendChild(r),this.popoverEl=r,this.boundOutsideClick=t=>{let n=t.target;!r.contains(n)&&!e.contains(n)&&this.close()},document.addEventListener(`mousedown`,this.boundOutsideClick)}close(){this.popoverEl!==null&&(this.popoverEl.remove(),this.popoverEl=null),this.boundOutsideClick!==null&&(document.removeEventListener(`mousedown`,this.boundOutsideClick),this.boundOutsideClick=null)}destroy(){this.close()}},Gi=class{constructor(e){this.drawer=null,this.currentRowId=null,this.currentRow=null,this.blokInstance=null,this.escapeHandler=null,this.outsideClickHandler=null,this.propertyTypePopover=null,this.wrapper=e.wrapper,this.readOnly=e.readOnly,this.i18n=e.i18n,this.toolsConfig=e.toolsConfig,this.titlePropertyId=e.titlePropertyId,this.descriptionPropertyId=e.descriptionPropertyId,this.schema=e.schema,this.onTitleChange=e.onTitleChange,this.onDescriptionChange=e.onDescriptionChange,this.onClose=e.onClose,this.onAddProperty=e.onAddProperty}get isOpen(){return this.drawer!==null}open(e){var n,r,i,a,o,s,c;if(this.drawer){if(e.id===this.currentRowId)return;this.loadCard(e);return}let l=this.wrapper.querySelector(`[data-blok-database-drawer]`);l==null||l.remove(),this.currentRowId=e.id,this.currentRow=e,this.updateActiveCard(e.id);let u=(n=e.properties[this.titlePropertyId])==null?``:n,d=document.createElement(`div`);d.setAttribute(`data-blok-database-drawer`,``),d.setAttribute(`role`,`complementary`),d.setAttribute(`aria-label`,(r=(i=this.i18n)==null?void 0:i.t(`tools.database.cardDetails`))==null?`tools.database.cardDetails`:r);let f=document.createElement(`div`);f.setAttribute(`data-blok-database-drawer-toolbar`,``);let p=document.createElement(`button`);p.setAttribute(`data-blok-database-drawer-close`,``),p.setAttribute(`aria-label`,`Close`),p.innerHTML=t.X+t.X,p.addEventListener(`click`,()=>{this.close()}),f.appendChild(p),d.appendChild(f);let m=document.createElement(`div`);m.setAttribute(`data-blok-database-drawer-content`,``);let h=document.createElement(`textarea`);h.setAttribute(`data-blok-database-drawer-title`,``),h.setAttribute(`aria-label`,(a=(o=this.i18n)==null?void 0:o.t(`tools.database.cardTitle`))==null?`tools.database.cardTitle`:a),h.placeholder=(s=(c=this.i18n)==null?void 0:c.t(`tools.database.cardTitlePlaceholder`))==null?`Empty page`:s,h.value=u,h.rows=1,h.readOnly=this.readOnly,h.addEventListener(`input`,()=>{this.currentRowId!==null&&this.onTitleChange(this.currentRowId,h.value),this.autoResizeTitle(h)}),h.addEventListener(`keydown`,e=>{e.key===`Enter`&&e.preventDefault()}),m.appendChild(h);let g=this.getRenderableSchema();m.appendChild(this.buildPropsSection(g,e));let _=document.createElement(`hr`);m.appendChild(_);let v=document.createElement(`div`);v.setAttribute(`data-blok-database-drawer-editor`,``),m.appendChild(v),d.appendChild(m),this.wrapper.appendChild(d),this.drawer=d,requestAnimationFrame(()=>{d.style.width=`45%`,d.addEventListener(`transitionend`,()=>{this.autoResizeTitle(h),u||h.focus()},{once:!0})}),this.initNestedEditor(v,e),this.escapeHandler=e=>{if(e.key!==`Escape`)return;let t=e.target;t&&v.contains(t)||this.close()},document.addEventListener(`keydown`,this.escapeHandler),this.outsideClickHandler=e=>{let t=e.target;t&&d.contains(t)||t instanceof Element&&t.closest(`[data-blok-popover-opened]`)!==null||t instanceof Element&&t.closest(`[data-blok-database-tab-bar]`)!==null||this.close()},document.addEventListener(`mousedown`,this.outsideClickHandler),h.focus()}loadCard(e){var t,n,r;if(this.drawer===null)return;this.cleanupEditor(),this.currentRowId=e.id,this.currentRow=e,this.updateActiveCard(e.id);let i=(t=e.properties[this.titlePropertyId])==null?``:t,a=this.drawer.querySelector(`[data-blok-database-drawer-title]`);a!==null&&(a.value=i,this.autoResizeTitle(a),i||a.focus()),(n=this.drawer.querySelector(`[data-blok-database-drawer-props]`))==null||n.remove();let o=this.getRenderableSchema(),s=this.drawer.querySelector(`[data-blok-database-drawer-content]`),c=(r=s==null?void 0:s.querySelector(`hr`))==null?null:r;s!==null&&s.insertBefore(this.buildPropsSection(o,e),c);let l=this.drawer.querySelector(`[data-blok-database-drawer-editor]`);l!==null&&(l.innerHTML=``,this.initNestedEditor(l,e))}close(){let e=this.drawer!==null;if(this.updateActiveCard(null),this.cleanupListeners(),this.cleanupEditor(),this.drawer){let e=this.drawer;this.drawer=null,e.style.width=`0px`,e.addEventListener(`transitionend`,()=>{e.remove()},{once:!0})}this.currentRowId=null,this.currentRow=null,e&&this.onClose()}destroy(){var e;this.cleanupListeners(),this.cleanupEditor(),(e=this.propertyTypePopover)==null||e.destroy(),this.propertyTypePopover=null,this.drawer&&(this.drawer.remove(),this.drawer=null);let t=this.wrapper.querySelector(`[data-blok-database-drawer]`);t==null||t.remove(),this.currentRowId=null,this.currentRow=null}refreshSchema(e){var t,n;if(this.schema=e,this.drawer===null||this.currentRow===null)return;(t=this.drawer.querySelector(`[data-blok-database-drawer-props]`))==null||t.remove();let r=this.getRenderableSchema(),i=this.drawer.querySelector(`[data-blok-database-drawer-content]`),a=(n=i==null?void 0:i.querySelector(`hr`))==null?null:n;i!==null&&i.insertBefore(this.buildPropsSection(r,this.currentRow),a)}buildPropsSection(e,t){let n=document.createElement(`div`);n.setAttribute(`data-blok-database-drawer-props`,``);for(let i of e){var r;n.appendChild(this.createPropertyRow(i,(r=t.properties[i.id])==null?null:r))}if(!this.readOnly){let e=document.createElement(`button`);e.setAttribute(`data-blok-database-drawer-add-prop`,``),e.textContent=`+ Add a property`,e.addEventListener(`click`,()=>{this.propertyTypePopover===null&&(this.propertyTypePopover=new Wi({onSelect:e=>{var t,n;(t=this.onAddProperty)==null||t.call(this,e),(n=this.propertyTypePopover)==null||n.close()},i18n:this.i18n})),this.propertyTypePopover.open(e)}),n.appendChild(e)}return n}getRenderableSchema(){return[...this.schema].filter(e=>e.type!==`title`&&e.type!==`richText`).sort((e,t)=>e.position<t.position?-1:+(e.position>t.position))}createSelectPill(e){let t=document.createElement(`span`);if(t.setAttribute(`data-blok-database-drawer-prop-pill`,``),e.color!==void 0){t.style.backgroundColor=`var(--blok-color-${e.color}-bg)`,t.style.color=`var(--blok-color-${e.color}-text)`;let n=document.createElement(`span`);n.setAttribute(`data-blok-database-drawer-prop-dot`,``),n.style.backgroundColor=`var(--blok-color-${e.color}-text)`,t.appendChild(n)}let n=document.createElement(`span`);return n.textContent=e.label,t.appendChild(n),t}createPropertyRow(e,t){let n=document.createElement(`div`);n.setAttribute(`data-blok-database-drawer-prop-row`,``);let r=document.createElement(`span`);r.setAttribute(`data-blok-database-drawer-prop-label`,``),r.textContent=e.name,n.appendChild(r);let i=document.createElement(`span`);if(i.setAttribute(`data-blok-database-drawer-prop-value`,``),e.type===`select`){let n=e.config,r=typeof t==`string`?t:null,a=n==null?void 0:n.options.find(e=>e.id===r);a!==void 0&&i.appendChild(this.createSelectPill(a))}else if(e.type===`multiSelect`){let n=e.config;(Array.isArray(t)?t:[]).map(e=>n==null?void 0:n.options.find(t=>t.id===e)).filter(e=>e!==void 0).forEach(e=>i.appendChild(this.createSelectPill(e)))}else (typeof t==`string`||typeof t==`number`||typeof t==`boolean`)&&(i.textContent=String(t));return n.appendChild(i),n}updateActiveCard(e){let t=this.wrapper.querySelector(`[data-blok-database-card-active]`);if(t==null||t.removeAttribute(`data-blok-database-card-active`),e!==null){let t=this.wrapper.querySelector(`[data-blok-database-card][data-row-id="${e}"]`);t==null||t.setAttribute(`data-blok-database-card-active`,``)}}cleanupListeners(){this.escapeHandler&&(document.removeEventListener(`keydown`,this.escapeHandler),this.escapeHandler=null),this.outsideClickHandler&&(document.removeEventListener(`mousedown`,this.outsideClickHandler),this.outsideClickHandler=null)}cleanupEditor(){if(this.blokInstance){try{let e=this.blokInstance,t=this.currentRowId;e.save().then(n=>{t!==null&&this.onDescriptionChange(t,n),e.destroy()}).catch(()=>{e.destroy()})}catch(e){}this.blokInstance=null}}autoResizeTitle(e){let{style:t}=e;t.height=`auto`,e.scrollHeight>0&&(t.height=`${e.scrollHeight}px`)}initNestedEditor(e,t){var r=this;Promise.resolve().then(()=>require(`../blok.cjs`)).then(({Blok:i})=>{let a=t.id,o=this.descriptionPropertyId===void 0?void 0:t.properties[this.descriptionPropertyId],s=new i(n.t(n.t({},this.toolsConfig),{},{holder:e,data:o,readOnly:this.readOnly,onChange:async()=>{try{var e;let t=await((e=r.blokInstance)==null?void 0:e.save());t!==void 0&&r.onDescriptionChange(a,t)}catch(e){}}}));this.blokInstance=s}).catch(()=>{})}},Ki=class{constructor(e){this.boundKeydown=null,this.wrapper=e.wrapper,this.onEscape=e.onEscape}attach(){this.boundKeydown=e=>{e.key===`Escape`&&this.onEscape()&&e.stopPropagation()},this.wrapper.addEventListener(`keydown`,this.boundKeydown)}destroy(){this.boundKeydown&&(this.wrapper.removeEventListener(`keydown`,this.boundKeydown),this.boundKeydown=null)}},qi=[{type:`board`,icon:t.z,labelKey:`tools.database.viewTypeBoard`,descriptionKey:`tools.database.viewTypeBoardDescription`},{type:`list`,icon:t.Gt,labelKey:`tools.database.viewTypeList`,descriptionKey:`tools.database.viewTypeListDescription`}],Ji=class{constructor(e){this.popover=null,this.onSelect=e.onSelect,this.onClose=e.onClose,this.api=e.api}translate(e,t){var n,r;return(n=(r=this.api)==null?void 0:r.i18n.t(e))==null?t:n}open(e){this.close();let n=document.createElement(`div`);n.setAttribute(`data-blok-database-view-popover-heading`,``),n.textContent=this.translate(`tools.database.addView`,[`Add`,`view`].join(` `));let r=[{type:t.pr.Html,element:n},...qi.map(e=>{let n=this.createViewItem(e);return{type:t.pr.Html,element:n,closeOnActivate:!0}})];this.popover=new t.C({items:r,trigger:e,width:`auto`,minWidth:`200px`,flippable:!1,autoFocusFirstItem:!1}),this.popover.on(t.T.Closed,()=>{if(this.popover!==null){var e;let t=this.popover;this.popover=null,t.destroy(),(e=this.onClose)==null||e.call(this)}}),this.popover.show()}createViewItem(e){let t=document.createElement(`div`);t.setAttribute(`data-blok-database-view-option`,e.type);let n=document.createElement(`div`);n.setAttribute(`data-blok-database-view-option-icon`,``),n.innerHTML=e.icon,t.appendChild(n);let r=document.createElement(`div`);r.setAttribute(`data-blok-database-view-option-text`,``);let i=document.createElement(`span`);i.setAttribute(`data-blok-database-view-option-label`,``),i.textContent=this.translate(e.labelKey,``),r.appendChild(i);let a=document.createElement(`span`);return a.setAttribute(`data-blok-database-view-option-desc`,``),a.textContent=this.translate(e.descriptionKey,``),r.appendChild(a),t.appendChild(r),t.addEventListener(`click`,()=>{this.onSelect(e.type)}),t}close(){if(this.popover!==null){var e;let t=this.popover;this.popover=null,t.destroy(),(e=this.onClose)==null||e.call(this)}}destroy(){this.close()}},Yi=10,Xi={board:t.z,list:t.Gt},Zi=class{constructor(e){var t;this.element=null,this.barEl=null,this.addBtnEl=null,this.viewPopover=null,this.contextPopover=null,this.overflowDropdownEl=null,this.boundOverflowClose=null,this.moreBtnEl=null,this.isDragging=!1,this.dragViewId=``,this.dragStartX=0,this.ghostEl=null,this.options=e,this.views=e.views,this.onReorder=e.onReorder,this.readOnly=(t=e.readOnly)==null?!1:t,this.boundDragMove=this.handleDragMove.bind(this),this.boundDragUp=this.handleDragUp.bind(this),this.boundDragCancel=this.cleanupDrag.bind(this),this.boundDragKeyDown=e=>{e.key===`Escape`&&this.cleanupDrag()}}render(){let e=document.createElement(`div`);e.setAttribute(`data-blok-database-tab-bar`,``),this.barEl=e,this.element=e;let n=[...this.options.views].sort((e,t)=>e.position<t.position?-1:1);for(let t of n)e.appendChild(this.createTab(t));let r=document.createElement(`button`);return r.setAttribute(`data-blok-database-add-view`,``),r.innerHTML=t.sn,r.addEventListener(`click`,()=>{this.openViewPopover(r)}),this.addBtnEl=r,this.readOnly||e.appendChild(r),e.addEventListener(`click`,e=>{let t=e.target.closest(`[data-blok-database-tab]`);if(!(t instanceof HTMLElement))return;let n=t.getAttribute(`data-view-id`);n!==null&&(t.hasAttribute(`data-active`)||this.options.onTabClick(n))}),e.addEventListener(`contextmenu`,e=>{let t=e.target.closest(`[data-blok-database-tab]`);if(!(t instanceof HTMLElement))return;e.preventDefault();let n=t.getAttribute(`data-view-id`);n!==null&&this.openContextPopover(t,n)}),e.addEventListener(`dblclick`,e=>{let t=e.target.closest(`[data-blok-database-tab]`);if(!(t instanceof HTMLElement))return;let n=t.getAttribute(`data-view-id`);n!==null&&this.openContextPopover(t,n)}),e.addEventListener(`pointerdown`,e=>{let t=e.target.closest(`[data-blok-database-tab]`);if(t===null)return;let n=t.getAttribute(`data-view-id`);n!==null&&(this.dragViewId=n,this.dragStartX=e.clientX,this.isDragging=!1,document.addEventListener(`pointermove`,this.boundDragMove),document.addEventListener(`pointerup`,this.boundDragUp),document.addEventListener(`pointercancel`,this.boundDragCancel),document.addEventListener(`keydown`,this.boundDragKeyDown))}),typeof ResizeObserver<`u`&&new ResizeObserver(()=>{var e;if(this.element===null)return;let t=Array.from(this.element.querySelectorAll(`[data-blok-database-tab]`));for(let e of t)e.style.display=``;(e=this.moreBtnEl)==null||e.remove(),this.moreBtnEl=null;let n=this.element.clientWidth,r=t.findIndex((e,r)=>40+t.slice(0,r+1).reduce((e,t)=>e+t.offsetWidth+2,0)>n),i=r===-1?t.length:r;i<t.length&&this.handleOverflow(i)}).observe(e),e}createTab(e){var t;let n=document.createElement(`div`);n.setAttribute(`data-blok-database-tab`,``),n.setAttribute(`data-view-id`,e.id),e.id===this.options.activeViewId&&n.setAttribute(`data-active`,``);let r=document.createElement(`span`);r.innerHTML=(t=Xi[e.type])==null?``:t,n.appendChild(r);let i=document.createElement(`span`);return i.setAttribute(`data-blok-database-tab-name`,``),i.textContent=e.name,n.appendChild(i),n}openContextPopover(e,n){this.closeContextPopover();let r=this.options.views.length>1,i=(e,t)=>{var n,r;return(n=(r=this.options.api)==null?void 0:r.i18n.t(e))==null?t:n},a=[{icon:t.an,title:i(`tools.database.renameView`,`Rename`),closeOnActivate:!0,onActivate:()=>{this.startInlineRename(e,n)}},{icon:t.nt,title:i(`tools.database.duplicateView`,`Duplicate`),closeOnActivate:!0,onActivate:()=>{this.options.onDuplicate(n)}}],o=r?[{type:t.pr.Separator},{icon:t.Cn,title:i(`tools.database.deleteView`,`Delete`),isDestructive:!0,closeOnActivate:!0,onActivate:()=>{this.options.onDelete(n)}}]:[];this.contextPopover=new t.C({trigger:e,width:`auto`,minWidth:`160px`,autoFocusFirstItem:!1,items:[...a,...o]}),this.contextPopover.on(t.T.Closed,()=>{if(this.contextPopover!==null){let e=this.contextPopover;this.contextPopover=null,e.destroy()}}),this.contextPopover.show()}closeContextPopover(){if(this.contextPopover!==null){let e=this.contextPopover;this.contextPopover=null,e.destroy()}}startInlineRename(e,t){var n;let r=e.querySelector(`[data-blok-database-tab-name]`);if(!(r instanceof HTMLElement))return;let i=(n=r.textContent)==null?``:n,a=document.createElement(`input`);a.setAttribute(`data-blok-database-tab-rename-input`,``),a.value=i,r.replaceWith(a),a.focus(),a.select();let o=()=>{let e=a.value.trim()||i,n=document.createElement(`span`);n.setAttribute(`data-blok-database-tab-name`,``),n.textContent=e,a.replaceWith(n),e!==i&&this.options.onRename(t,e)};a.addEventListener(`blur`,o),a.addEventListener(`keydown`,e=>{if(e.stopPropagation(),e.key===`Enter`)a.blur();else if(e.key===`Escape`){a.removeEventListener(`blur`,o);let e=document.createElement(`span`);e.setAttribute(`data-blok-database-tab-name`,``),e.textContent=i,a.replaceWith(e)}})}openViewPopover(e){var t;this.viewPopover!==null&&this.viewPopover.destroy(),e.setAttribute(`data-popover-open`,``),(t=this.barEl)==null||t.setAttribute(`data-popover-open`,``),this.viewPopover=new Ji({onSelect:e=>{this.options.onAddView(e)},onClose:()=>{var t;e.removeAttribute(`data-popover-open`),(t=this.barEl)==null||t.removeAttribute(`data-popover-open`)},api:this.options.api}),this.viewPopover.open(e)}handleOverflow(e){var t;if(this.element===null)return;(t=this.moreBtnEl)==null||t.remove();let n=[...this.views].sort((e,t)=>e.position<t.position?-1:1).length-e;if(n<=0)return;let r=Array.from(this.element.querySelectorAll(`[data-blok-database-tab]`));for(let t of r.slice(e))t.style.display=`none`;let i=document.createElement(`div`);i.setAttribute(`data-blok-database-tab-more`,``),i.textContent=`${n} more...`,i.style.cursor=`pointer`,i.addEventListener(`click`,()=>{this.openOverflowDropdown(i)});let a=this.element.querySelector(`[data-blok-database-add-view]`);a===null?this.element.appendChild(i):this.element.insertBefore(i,a),this.moreBtnEl=i}openOverflowDropdown(e){var t;this.closeOverflowDropdown();let n=document.createElement(`div`);n.setAttribute(`data-blok-popover`,``),n.setAttribute(`data-blok-database-tab-overflow-dropdown`,``),n.style.position=`fixed`,n.style.zIndex=`1000`;let r=e.getBoundingClientRect();n.style.top=`${r.bottom+4}px`,n.style.left=`${r.left}px`;let i=[...this.views].sort((e,t)=>e.position<t.position?-1:1);for(let e of i){var a;let t=document.createElement(`div`);t.setAttribute(`data-blok-database-tab-overflow-item`,``),t.setAttribute(`data-view-id`,e.id),e.id===this.options.activeViewId&&t.setAttribute(`data-active`,``);let r=document.createElement(`span`);r.innerHTML=(a=Xi[e.type])==null?``:a,t.appendChild(r);let i=document.createElement(`span`);i.textContent=e.name,t.appendChild(i),t.addEventListener(`click`,()=>{e.id!==this.options.activeViewId&&this.options.onTabClick(e.id),this.closeOverflowDropdown()}),n.appendChild(t)}let o=document.createElement(`div`);o.setAttribute(`data-blok-database-tab-overflow-separator`,``),n.appendChild(o);let s=(t=this.element)==null?void 0:t.querySelector(`[data-blok-database-add-view]`),c=document.createElement(`div`);c.setAttribute(`data-blok-database-tab-overflow-new`,``),c.textContent=`+ New view`,c.addEventListener(`click`,()=>{this.closeOverflowDropdown(),s!=null&&this.openViewPopover(s)}),n.appendChild(c),document.body.appendChild(n),this.overflowDropdownEl=n,this.boundOverflowClose=t=>{let r=t.target;!n.contains(r)&&!e.contains(r)&&this.closeOverflowDropdown()},document.addEventListener(`mousedown`,this.boundOverflowClose)}closeOverflowDropdown(){this.overflowDropdownEl!==null&&(this.overflowDropdownEl.remove(),this.overflowDropdownEl=null),this.boundOverflowClose!==null&&(document.removeEventListener(`mousedown`,this.boundOverflowClose),this.boundOverflowClose=null)}handleDragMove(e){let t=Math.abs(e.clientX-this.dragStartX);if(!(!this.isDragging&&t<Yi)){if(!this.isDragging){var n,r;this.isDragging=!0,(n=this.element)==null||n.setAttribute(`data-dragging`,``);let e=(r=this.element)==null?void 0:r.querySelector(`[data-view-id="${this.dragViewId}"]`);if(e!==null){this.ghostEl=e.cloneNode(!0),this.ghostEl.setAttribute(`data-blok-database-tab-ghost`,``),this.ghostEl.style.position=`fixed`,this.ghostEl.style.pointerEvents=`none`,this.ghostEl.style.zIndex=`50`,this.ghostEl.style.opacity=`0.7`;let t=e.getBoundingClientRect();this.ghostEl.style.top=`${t.top}px`,this.ghostEl.style.width=`${t.width}px`,document.body.appendChild(this.ghostEl),e.style.opacity=`0.4`}}this.ghostEl!==null&&(this.ghostEl.style.left=`${e.clientX-50}px`)}}handleDragUp(e){var t,n,r,i;if(!this.isDragging){this.removeDragListeners();return}let a=Array.from((t=(n=this.element)==null?void 0:n.querySelectorAll(`[data-blok-database-tab]`))==null?[]:t).filter(e=>e.getAttribute(`data-view-id`)!==this.dragViewId),o=a.findIndex(t=>{let n=t.getBoundingClientRect();return e.clientX<(n.left+n.right)/2}),s=o>=0?a[o].getAttribute(`data-view-id`):null,c=o>0?a[o-1].getAttribute(`data-view-id`):o===-1&&a.length>0?a[a.length-1].getAttribute(`data-view-id`):null,l=[...this.views].sort((e,t)=>e.position<t.position?-1:1),u=s===null?null:l.find(e=>e.id===s),d=c===null?null:l.find(e=>e.id===c),f=ki((r=d==null?void 0:d.position)==null?null:r,(i=u==null?void 0:u.position)==null?null:i);this.cleanupDrag(),this.onReorder(this.dragViewId,f)}cleanupDrag(){var e,t;this.ghostEl!==null&&(this.ghostEl.remove(),this.ghostEl=null),(e=this.element)==null||e.removeAttribute(`data-dragging`);let n=(t=this.element)==null?void 0:t.querySelector(`[data-view-id="${this.dragViewId}"]`);n!==null&&(n.style.opacity=``),this.isDragging=!1,this.removeDragListeners()}removeDragListeners(){document.removeEventListener(`pointermove`,this.boundDragMove),document.removeEventListener(`pointerup`,this.boundDragUp),document.removeEventListener(`pointercancel`,this.boundDragCancel),document.removeEventListener(`keydown`,this.boundDragKeyDown)}setReadOnly(e){this.readOnly!==e&&(this.readOnly=e,!(this.barEl===null||this.addBtnEl===null)&&(e?this.addBtnEl.remove():this.addBtnEl.isConnected||this.barEl.appendChild(this.addBtnEl)))}destroy(){this.cleanupDrag(),this.closeContextPopover(),this.closeOverflowDropdown(),this.viewPopover!==null&&(this.viewPopover.destroy(),this.viewPopover=null)}getAddBtnEl(){return this.addBtnEl}},Qi=class{constructor({data:e,config:t,api:n,block:r,readOnly:i}){var a,o;this.element=null,this.titleElement=null,this.titleRowElement=null,this.boardContainer=null,this.tabBar=null,this.cardDrag=null,this.columnDrag=null,this.columnControls=null,this.listRowDrag=null,this.cardDrawer=null,this.keyboard=null,this.cardMenuPopover=null,this.api=n,this.block=r,this.readOnly=i,this.config=t==null?{}:t,this.title=(a=e==null?void 0:e.title)==null?``:a,this.model=new ji(e);let s=this.model.getViews();this.activeViewId=(o=e==null?void 0:e.activeViewId)==null?s.length>0?s[0].id:``:o,this.activateView(this.activeViewId)}static get toolbox(){return[{icon:t.ot,titleKey:`database`,name:`database`,searchTerms:[`database`,`kanban`,`board`,`cards`,`columns`]},{icon:t.z,titleKey:`board`,name:`board`,searchTerms:[`board`,`kanban`,`cards`,`columns`,`database`]}]}static get isReadOnlySupported(){return!0}render(){let e=document.createElement(`div`);e.setAttribute(`data-blok-tool`,`database`),e.setAttribute(`data-blok-database-wrapper`,``),e.style.display=`flex`,e.style.flexDirection=`column`,this.element=e;let t=this.createTitleElement();this.titleElement=t;let n=document.createElement(`div`);n.setAttribute(`data-blok-database-title-row`,``),n.appendChild(t),this.titleRowElement=n,e.appendChild(n),this.tabBar=this.createTabBar(),e.appendChild(this.tabBar.render()),this.syncTitleRowAddBtn();let r=document.createElement(`div`);r.setAttribute(`data-blok-database-board-container`,``),r.style.overflow=`hidden`,r.style.position=`relative`,this.boardContainer=r,e.appendChild(r),this.syncRowsFromBlocks();let i=this.renderActiveView();return r.appendChild(i),this.readOnly||(this.attachViewListeners(i),this.initSubsystems(i)),e}createTitleElement(){let e=document.createElement(`div`);return e.setAttribute(`data-blok-database-title`,``),e.textContent=this.title,e.style.fontSize=`1.5rem`,e.style.fontWeight=`600`,e.style.lineHeight=`1.3`,e.style.color=`var(--blok-text-primary)`,e.style.outline=`none`,e.style.cursor=`text`,e.style.wordBreak=`break-word`,e.className=o.join(` `),p(e,`New database`),this.readOnly||(e.setAttribute(`contenteditable`,`true`),e.addEventListener(`keydown`,t=>{(t.key===`Enter`||t.key===`Tab`)&&(t.preventDefault(),e.blur())})),e}rendered(){this.block.stretched=!0;let e=this.model.getOrderedRows().length>0;this.syncRowsFromBlocks(),!e&&this.model.getOrderedRows().length>0&&this.rerenderView(),this.config.adapter!==void 0&&this.loadFromBackend()}async loadFromBackend(){var e=this;let t=await e.sync.syncLoadDatabase();if(t===void 0)return;e.model.hydrate(t);let n=e.model.getViews();n.length>0&&!n.some(t=>t.id===e.activeViewId)&&(e.activeViewId=n[0].id),e.rerenderView()}save(e){var t,r;let i=(t=(r=this.titleElement)==null?void 0:r.textContent)==null?this.title:t;return n.t(n.t({},this.model.snapshot()),{},{title:i,activeViewId:this.activeViewId})}validate(e){var t,n,r,i;let a=((t=(n=e.schema)==null?void 0:n.filter(e=>e.type===`title`).length)==null?0:t)===1,o=e.views!==void 0&&e.views.length>0,s=(r=(i=e.views)==null?void 0:i.filter(e=>e.type===`board`).every(e=>e.groupBy!==void 0))==null?!0:r;return a&&o&&s}destroy(){var e,t,n,r,i,a,o;(e=this.cardDrag)==null||e.destroy(),(t=this.columnDrag)==null||t.destroy(),(n=this.columnControls)==null||n.destroy(),(r=this.listRowDrag)==null||r.destroy(),this.listRowDrag=null,(i=this.cardDrawer)==null||i.destroy(),(a=this.keyboard)==null||a.destroy(),(o=this.tabBar)==null||o.destroy(),this.sync.flushPendingUpdates(),this.sync.flushPendingPropertyUpdates(),this.sync.destroy(),this.element=null,this.boardContainer=null,this.tabBar=null}setReadOnly(e){var t;this.readOnly!==e&&(this.readOnly=e,this.titleElement!==null&&this.titleElement.setAttribute(`contenteditable`,e?`false`:`true`),(t=this.tabBar)==null||t.setReadOnly(e),this.syncTitleRowAddBtn(),this.rerenderView())}getToolbarAnchorElement(){var e;return(e=this.titleElement)==null?void 0:e}syncRowsFromBlocks(){let e=this.api.blocks.getChildren(this.block.id).filter(e=>e.name===`database-row`).map(e=>{var t,n,r,i;return{id:e.id,position:(t=(n=e.preservedData)==null?void 0:n.position)==null?``:t,properties:(r=(i=e.preservedData)==null?void 0:i.properties)==null?{}:r}});this.model.setRows(e)}deleteRowBlock(e){let t=this.api.blocks.getBlockIndex(e);t!==void 0&&this.api.blocks.delete(t),this.syncRowsFromBlocks()}updateRowBlock(e,t){let n=this.api.blocks.getChildren(this.block.id).find(t=>t.id===e);n!==void 0&&(n.call(`updateProperties`,t),n.dispatchChange()),this.syncRowsFromBlocks()}moveRowBlock(e,t){let n=this.api.blocks.getChildren(this.block.id).find(t=>t.id===e);n!==void 0&&(n.call(`updatePosition`,{position:t}),n.dispatchChange()),this.syncRowsFromBlocks()}activateView(e){this.model.getView(e)!==void 0&&(this.activeViewId=e,this.sync=new Fi(this.config.adapter,e=>{let t=String(e).replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`).replace(/'/g,`&#39;`);this.api.notifier.show({message:t,style:`error`})}))}switchView(e){var t,n,r,i,a;if(e===this.activeViewId||this.boardContainer===null)return;(t=this.cardDrag)==null||t.destroy(),(n=this.columnDrag)==null||n.destroy(),(r=this.columnControls)==null||r.destroy(),(i=this.listRowDrag)==null||i.destroy(),(a=this.keyboard)==null||a.destroy(),this.cardDrag=null,this.columnDrag=null,this.columnControls=null,this.listRowDrag=null,this.keyboard=null,this.sync.flushPendingUpdates(),this.sync.flushPendingPropertyUpdates(),this.sync.destroy(),this.activateView(e),this.boardContainer.innerHTML=``,this.syncRowsFromBlocks();let o=this.renderActiveView();this.boardContainer.appendChild(o),this.readOnly||(this.attachViewListeners(o),this.initSubsystems(o)),this.rebuildTabBar()}addView(e){let t=this.model.getSchema().find(e=>e.type===`select`),n=e===`list`?`List`:`Board`,r=this.model.addView(n,e,{groupBy:e===`board`?t==null?void 0:t.id:void 0});this.sync.syncCreateView({id:r.id,name:r.name,type:r.type,position:r.position,groupBy:r.groupBy}),this.switchView(r.id)}renameView(e,t){this.model.updateView(e,{name:t}),this.sync.syncUpdateView({viewId:e,changes:{name:t}})}duplicateView(e){let t=this.model.getView(e);if(t===void 0)return;let n=this.model.addView(t.name,t.type,{groupBy:t.groupBy,sorts:[...t.sorts],filters:[...t.filters],visibleProperties:[...t.visibleProperties]});this.sync.syncCreateView({id:n.id,name:n.name,type:n.type,position:n.position,groupBy:n.groupBy}),this.switchView(n.id)}deleteView(e){let t=this.model.getViews();if(t.length<=1)return;let n=t.findIndex(t=>t.id===e);if(n===-1)return;let r=e===this.activeViewId;if(this.model.deleteView(e),this.sync.syncDeleteView({viewId:e}),r){let e=this.model.getViews(),t=Math.min(n,e.length-1);this.switchView(e[t].id)}else this.rebuildTabBar()}reorderView(e,t){this.model.updateView(e,{position:t}),this.sync.syncUpdateView({viewId:e,changes:{position:t}}),this.rebuildTabBar()}rebuildTabBar(){if(this.element===null||this.tabBar===null)return;let e=this.element.querySelector(`[data-blok-database-tab-bar]`);this.tabBar.destroy(),this.tabBar=this.createTabBar();let t=this.tabBar.render();e===null?this.element.insertBefore(t,this.boardContainer):e.replaceWith(t),this.syncTitleRowAddBtn()}syncTitleRowAddBtn(){if(this.element===null||this.titleRowElement===null||this.tabBar===null)return;let e=this.element.querySelector(`[data-blok-database-tab-bar]`),t=this.model.getViews(),n=this.tabBar.getAddBtnEl();t.length===1&&!this.readOnly&&n!==null?(this.titleRowElement.appendChild(n),this.titleRowElement.setAttribute(`data-single-view`,``),e instanceof HTMLElement&&(e.style.display=`none`)):(this.titleRowElement.removeAttribute(`data-single-view`),this.titleRowElement.querySelectorAll(`[data-blok-database-add-view]`).forEach(e=>{e.remove()}),!this.readOnly&&n!==null&&e!==null&&!e.contains(n)&&e.appendChild(n),e instanceof HTMLElement&&(e.style.display=t.length>=2?``:`none`))}createTabBar(){return new Zi({views:this.model.getViews(),activeViewId:this.activeViewId,onTabClick:e=>this.switchView(e),onAddView:e=>this.addView(e),onRename:(e,t)=>this.renameView(e,t),onDuplicate:e=>this.duplicateView(e),onDelete:e=>this.deleteView(e),onReorder:(e,t)=>this.reorderView(e,t),readOnly:this.readOnly})}renderActiveView(){var e;let t=this.model.getView(this.activeViewId),n=this.model.getSchema().find(e=>e.type===`title`),r=(e=n==null?void 0:n.id)==null?``:e,i=t==null?void 0:t.groupBy;return(t==null?void 0:t.type)===`list`?this.renderListView(r,i,t):this.renderBoardView(r,i)}renderBoardView(e,t){let n=t===void 0?[]:this.model.getSelectOptions(t),r=t===void 0?new Map:this.model.getRowsGroupedBy(t);return this.view=new Mi({readOnly:this.readOnly,i18n:this.api.i18n,options:n,getRows:e=>{var t;return(t=r.get(e))==null?[]:t},titlePropertyId:e,onTitleEdit:(e,t)=>{var n;let r=this.model.getSchema().find(e=>e.type===`title`),i=(n=r==null?void 0:r.id)==null?``:n;this.updateRowBlock(e,{[i]:t}),this.sync.syncUpdateRow({rowId:e,properties:{[i]:t}})}}),this.view.createView()}renderListView(e,t,n){let r=this.model.getSchema();if(t!==void 0){let i=this.model.getSelectOptions(t),a=this.model.getRowsGroupedBy(t);this.view=new Ni({readOnly:this.readOnly,i18n:this.api.i18n,rows:[],titlePropertyId:e,schema:r,visiblePropertyIds:n.visibleProperties,options:i,getRows:e=>{var t;return(t=a.get(e))==null?[]:t}})}else this.view=new Ni({readOnly:this.readOnly,i18n:this.api.i18n,rows:this.model.getOrderedRows(),titlePropertyId:e,schema:r,visiblePropertyIds:n.visibleProperties});return this.view.createView()}attachViewListeners(e){e.addEventListener(`click`,t=>{let n=t.target,r=n.closest(`[data-blok-database-add-card]`);if(r!==null){let t=r.getAttribute(`data-option-id`);t!==null&&this.handleAddRow(t,e);return}if(n.closest(`[data-blok-database-add-column]`)!==null){this.handleAddColumn(e);return}let i=n.closest(`[data-blok-database-card-menu]`);if(i instanceof HTMLElement){let n=i.getAttribute(`data-row-id`),r=i.closest(`[data-blok-database-card]`);n!==null&&r instanceof HTMLElement&&(t.stopPropagation(),this.openCardMenu(i,r,n,e));return}let a=n.closest(`[data-blok-database-add-row]`);if(a!==null){let t=a.getAttribute(`data-option-id`);this.handleAddListRow(t,e);return}let o=n.closest(`[data-blok-database-delete-row]`);if(o!==null){let n=o.getAttribute(`data-row-id`);n!==null&&(t.stopPropagation(),this.deleteRowBlock(n),this.view.removeRow(e,n),this.sync.syncDeleteRow({rowId:n}));return}let s=n.closest(`[data-blok-database-list-row]`);if(s!==null){let e=s.getAttribute(`data-row-id`);e!==null&&this.handleRowClick(e);return}let c=n.closest(`[data-blok-database-card]`);if(c!==null){let e=c.getAttribute(`data-row-id`);e!==null&&this.handleRowClick(e)}})}openCardMenu(e,n,r,i){n.setAttribute(`data-popover-open`,``),this.cardMenuPopover=new t.C({trigger:e,width:`auto`,minWidth:`140px`,autoFocusFirstItem:!1,items:[{type:t.pr.Default,title:this.api.i18n.t(`tools.database.deleteCard`),icon:t.Cn,onActivate:()=>{this.deleteRowBlock(r),this.view.removeRow(i,r),this.sync.syncDeleteRow({rowId:r})}}]}),this.cardMenuPopover.on(t.T.Closed,()=>{if(n.removeAttribute(`data-popover-open`),this.cardMenuPopover!==null){let e=this.cardMenuPopover;this.cardMenuPopover=null,e.destroy()}}),this.cardMenuPopover.show()}handleAddListRow(e,t){var n,r;let i=this.model.getSchema().find(e=>e.type===`title`),a=(n=i==null?void 0:i.id)==null?``:n,o=this.model.getView(this.activeViewId),s=o==null?void 0:o.groupBy,c={[a]:``};s!==void 0&&e!==null&&(c[s]=e);let l=this.model.createRowData(c),u=(r=this.api.blocks.getBlockIndex(this.block.id))==null?0:r;this.api.blocks.insert(`database-row`,{properties:l.properties,position:l.position},{},u+1,!1,!1,l.id),this.api.blocks.setBlockParent(l.id,this.block.id),this.syncRowsFromBlocks(),this.view.appendRow(t,l),this.sync.syncCreateRow({id:l.id,properties:l.properties,position:l.position})}handleAddRow(e,t){var n,r;let i=this.model.getView(this.activeViewId),a=i==null?void 0:i.groupBy;if(a===void 0)return;let o=this.model.getSchema().find(e=>e.type===`title`),s=(n=o==null?void 0:o.id)==null?``:n,c=this.model.createRowData({[s]:``,[a]:e}),l=(r=this.api.blocks.getBlockIndex(this.block.id))==null?0:r;this.api.blocks.insert(`database-row`,{properties:c.properties,position:c.position},{},l+1,!1,!1,c.id),this.api.blocks.setBlockParent(c.id,this.block.id),this.syncRowsFromBlocks();let u=t.querySelector(`[data-option-id="${e}"][data-blok-database-column]`);if(u===null)return;let d=u.querySelector(`[data-blok-database-cards]`);d!==null&&(this.view.appendRow(d,c),this.sync.syncCreateRow({id:c.id,properties:c.properties,position:c.position}))}handleAddColumn(e){var n,r;let i=this.model.getView(this.activeViewId),a=i==null?void 0:i.groupBy;if(a===void 0)return;let o=this.model.getProperty(a);if((o==null?void 0:o.config)===void 0)return;let s=o.config.options,c=s.length>0?s[s.length-1].position:null,l={id:t.Ur(),label:this.api.i18n.t(`tools.database.columnTitlePlaceholder`),position:ji.positionBetween(c,null)};this.model.updateProperty(a,{config:{options:[...s,l]}}),(n=(r=this.view).appendGroup)==null||n.call(r,e,l),this.sync.syncUpdateProperty({propertyId:a,changes:{config:{options:[...s,l]}}})}initSubsystems(e){var t;if(this.element===null)return;let r=this.model.getView(this.activeViewId),i=(r==null?void 0:r.type)===`list`,a=this.model.getSchema().find(e=>e.type===`title`),o=(t=a==null?void 0:a.id)==null?``:t,s=this.model.getSchema().find(e=>e.type===`richText`),c=s==null?void 0:s.id;i?this.listRowDrag=new Hi({wrapper:e,onDrop:e=>this.handleListRowDrop(e)}):(this.cardDrag=new Li({wrapper:e,onDrop:e=>this.handleRowDrop(e)}),this.columnDrag=new zi({wrapper:e,onDrop:e=>this.handleGroupDrop(e)}),this.columnControls=new Bi({i18n:this.api.i18n,onRename:(e,t)=>this.handleOptionRename(e,t),onDelete:t=>this.handleOptionDelete(t,e),onRenameInput:(e,t)=>{this.handleOptionRename(e,t)},onRenameCommit:(e,t)=>{let r=this.model.getView(this.activeViewId),i=r==null?void 0:r.groupBy;if(i===void 0)return;let a=this.model.getProperty(i);if((a==null?void 0:a.config)===void 0)return;let o=a.config.options.map(r=>r.id===e?n.t(n.t({},r),{},{label:t}):r);this.sync.syncUpdatePropertyDebounced({propertyId:i,changes:{config:{options:o}}})}}),this.makeColumnHeadersEditable(e)),this.cardDrawer===null&&(this.cardDrawer=new Gi({wrapper:this.element,readOnly:this.readOnly,i18n:this.api.i18n,toolsConfig:this.api.tools.getToolsConfig(),titlePropertyId:o,descriptionPropertyId:c,schema:this.model.getSchema(),onTitleChange:(e,t)=>{var n,r,i;this.updateRowBlock(e,{[o]:t});let a=(n=(r=this.boardContainer)==null?void 0:r.querySelector(`[data-blok-database-board]`))==null?(i=this.boardContainer)==null?void 0:i.querySelector(`[data-blok-database-list]`):n;a!=null&&this.view.updateRowTitle(a,e,t),this.sync.syncUpdateRow({rowId:e,properties:{[o]:t}})},onDescriptionChange:(e,t)=>{c!==void 0&&(this.updateRowBlock(e,{[c]:t}),this.sync.syncUpdateRow({rowId:e,properties:{[c]:t}}))},onClose:()=>{},onAddProperty:e=>{var t;let n=this.model.addProperty(`Property`,e);this.sync.syncCreateProperty({id:n.id,name:n.name,type:n.type,position:n.position}),(t=this.cardDrawer)==null||t.refreshSchema(this.model.getSchema())}})),this.keyboard=new Ki({wrapper:e,onEscape:()=>{var e;return(e=this.cardDrawer)!=null&&e.isOpen?(this.cardDrawer.close(),!0):!1}}),this.keyboard.attach(),e.addEventListener(`pointerdown`,e=>{let t=e.target,n=t.closest(`[data-blok-database-column-header]`);if(n!==null){var r;if(t.closest(`[data-blok-database-column-pill]`)!==null)return;let a=n.closest(`[data-blok-database-column]`),o=(r=a==null?void 0:a.getAttribute(`data-option-id`))==null?null:r;if(o!==null){var i;e.preventDefault(),e.stopPropagation(),(i=this.columnDrag)==null||i.beginTracking(o,e.clientX,e.clientY)}return}let a=t.closest(`[data-blok-database-card]`);if(a!==null){let t=a.getAttribute(`data-row-id`);if(t!==null){var o;e.preventDefault(),e.stopPropagation(),(o=this.cardDrag)==null||o.beginTracking(t,e.clientX,e.clientY)}return}let s=t.closest(`[data-blok-database-list-row]`);if(s!==null){let t=s.getAttribute(`data-row-id`);if(t!==null){var c;e.preventDefault(),e.stopPropagation(),(c=this.listRowDrag)==null||c.beginTracking(t,e.clientX,e.clientY)}}})}makeColumnHeadersEditable(e){if(this.columnControls===null)return;let t=Array.from(e.querySelectorAll(`[data-blok-database-column-header]`));for(let e of t){let t=e.closest(`[data-blok-database-column]`),n=t==null?void 0:t.getAttribute(`data-option-id`);n!=null&&(this.columnControls.makePillTitleEditable(e,n),this.columnControls.appendDeleteButton(e,n))}}handleListRowDrop(e){var t,n;let{rowId:r,beforeRowId:i,afterRowId:a}=e,o=i===null?void 0:this.model.getRow(i),s=a===null?void 0:this.model.getRow(a),c=ji.positionBetween((t=s==null?void 0:s.position)==null?null:t,(n=o==null?void 0:o.position)==null?null:n);this.moveRowBlock(r,c),this.rerenderView(),this.sync.syncMoveRow({rowId:r,position:c})}handleRowDrop(e){var t,n;let{rowId:r,toOptionId:i,beforeRowId:a,afterRowId:o}=e,s=this.model.getView(this.activeViewId),c=s==null?void 0:s.groupBy;if(c===void 0)return;let l=a===null?void 0:this.model.getRow(a),u=o===null?void 0:this.model.getRow(o),d=ji.positionBetween((t=u==null?void 0:u.position)==null?null:t,(n=l==null?void 0:l.position)==null?null:n);this.updateRowBlock(r,{[c]:i}),this.moveRowBlock(r,d),this.rerenderView(),this.sync.syncUpdateRow({rowId:r,properties:{[c]:i}}),this.sync.syncMoveRow({rowId:r,position:d})}handleGroupDrop(e){var t,r;let{optionId:i,beforeOptionId:a,afterOptionId:o}=e,s=this.model.getView(this.activeViewId),c=s==null?void 0:s.groupBy;if(c===void 0)return;let l=this.model.getProperty(c);if((l==null?void 0:l.config)===void 0)return;let u=[...l.config.options],d=u.findIndex(e=>e.id===i);if(d===-1)return;let f=a===null?void 0:u.find(e=>e.id===a),p=o===null?void 0:u.find(e=>e.id===o),m=ji.positionBetween((t=p==null?void 0:p.position)==null?null:t,(r=f==null?void 0:f.position)==null?null:r);u[d]=n.t(n.t({},u[d]),{},{position:m}),this.model.updateProperty(c,{config:{options:u}}),this.moveColumnInDom(i,a),this.sync.syncUpdateProperty({propertyId:c,changes:{config:{options:u}}})}moveColumnInDom(e,t){var n;let r=(n=this.boardContainer)==null?void 0:n.querySelector(`[data-blok-database-board]`);if(r==null)return;let i=r.querySelector(`[data-option-id="${e}"]`);if(i!==null)if(t!==null){let e=r.querySelector(`[data-option-id="${t}"]`);e!==null&&r.insertBefore(i,e)}else{let e=r.querySelector(`[data-blok-database-add-column]`);e===null?r.appendChild(i):r.insertBefore(i,e)}}handleOptionRename(e,t){let r=this.model.getView(this.activeViewId),i=r==null?void 0:r.groupBy;if(i===void 0)return;let a=this.model.getProperty(i);if((a==null?void 0:a.config)===void 0)return;let o=a.config.options.map(r=>r.id===e?n.t(n.t({},r),{},{label:t}):r);this.model.updateProperty(i,{config:{options:o}}),this.sync.syncUpdateProperty({propertyId:i,changes:{config:{options:o}}})}handleOptionDelete(e,t){var n,r,i;let a=this.model.getView(this.activeViewId),o=a==null?void 0:a.groupBy;if(o===void 0)return;let s=this.model.getProperty(o);if((s==null?void 0:s.config)===void 0||s.config.options.length<=1)return;let c=(n=this.model.getRowsGroupedBy(o).get(e))==null?[]:n;for(let e of c)this.deleteRowBlock(e.id),this.sync.syncDeleteRow({rowId:e.id});let l=s.config.options.filter(t=>t.id!==e);this.model.updateProperty(o,{config:{options:l}}),(r=(i=this.view).removeGroup)==null||r.call(i,t,e),this.sync.syncUpdateProperty({propertyId:o,changes:{config:{options:l}}})}handleRowClick(e){var t;let n=this.model.getRow(e);n!==void 0&&((t=this.cardDrawer)==null||t.open(n))}rerenderView(){var e,t,n,r,i,a,o,s,c,l;if(this.boardContainer===null)return;let u=(e=(t=(n=this.boardContainer.querySelector(`[data-blok-database-board]`))==null?void 0:n.closest(`[data-blok-tool]`))==null?this.boardContainer.querySelector(`[data-blok-database-list]`):t)==null?this.boardContainer.firstElementChild:e,d=this.boardContainer.querySelector(`[data-blok-database-board]`),f=(r=d==null?void 0:d.scrollLeft)==null?0:r;(i=this.cardDrag)==null||i.destroy(),(a=this.columnDrag)==null||a.destroy(),(o=this.columnControls)==null||o.destroy(),(s=this.listRowDrag)==null||s.destroy(),this.listRowDrag=null,(c=this.cardDrawer)==null||c.destroy(),this.cardDrawer=null,(l=this.keyboard)==null||l.destroy(),this.syncRowsFromBlocks();let p=this.renderActiveView();u==null?this.boardContainer.appendChild(p):u.replaceWith(p);let m=p.querySelector(`[data-blok-database-board]`);m!==null&&(m.scrollLeft=f),this.attachViewListeners(p),this.initSubsystems(p)}},$i=class{constructor({data:e}){var t,n;this._data={properties:(t=e.properties)==null?{}:t,position:(n=e.position)==null?`a0`:n}}render(){let e=document.createElement(`div`);return e.setAttribute(`data-blok-tool`,`database-row`),e}save(e){return{properties:this._data.properties,position:this._data.position}}validate(e){return e.properties!==null&&e.properties!==void 0&&typeof e.properties==`object`}updateProperties(e){Object.assign(this._data.properties,e)}updatePosition(e){this._data.position=e.position}getProperties(){return this._data.properties}getPosition(){return this._data.position}static get isReadOnlySupported(){return!0}setReadOnly(e){}},ea=class{constructor(e){this.element=null}render(){let e=document.createElement(`div`);e.className=r.n(`py-3`,`leading-[1px]`);let t=document.createElement(`hr`);return t.setAttribute(`data-blok-divider`,``),t.className=r.n(`border-t`,`border-border-primary`,`border-b-0`,`border-l-0`,`border-r-0`),e.appendChild(t),this.element=e,e}save(){return{}}validate(e){return!0}static get toolbox(){return{icon:t.ct,titleKey:`divider`,shortcut:`---`,searchTerms:[`hr`,`line`,`separator`,`rule`,`---`,`divider`,`delimiter`,`splitter`],searchTermKeys:[`divider`,`separator`,`delimiter`,`splitter`]}}static get isReadOnlySupported(){return!0}static get pasteConfig(){return{tags:[`HR`],patterns:{divider:/^-{3,}$/}}}onPaste(e){}setReadOnly(e){}static get sanitize(){return{}}},ta=`tools.quote.placeholder`,na=[`border-l-[3px]`,`border-current`,`pl-[0.9em]`,`pr-[0.9em]`,`py-[0.2em]`,`leading-[1.5]`,`outline-hidden`,`mt-[0.3em]`,`mb-[0.3em]`],ra=`text-[1.2em]`,ia=class{constructor({data:e,api:t,readOnly:n}){var r,i;this.placeholderCleanup=null,this._element=null,this.api=t,this.readOnly=n,this._data={text:(r=e==null?void 0:e.text)==null?``:r,size:(i=e==null?void 0:e.size)==null?`default`:i},this.onKeyUp=this.onKeyUp.bind(this)}onKeyUp(e){e.code!==`Backspace`&&e.code!==`Delete`||this._element&&this._element.textContent===``&&(this._element.innerHTML=``)}drawView(){let e=document.createElement(`blockquote`);return e.className=r.n(this.api.styles.block,na,c,this._data.size===`large`?ra:``),e.setAttribute(t.hi.tool,`quote`),e.contentEditable=`false`,this._data.text?e.innerHTML=this._data.text:this.readOnly&&(e.innerHTML=`<br>`),this.readOnly||(e.contentEditable=`true`,e.addEventListener(`keyup`,this.onKeyUp),this.placeholderCleanup=p(e,this.api.i18n.t(ta),`data-blok-placeholder-active`)),e}render(){return this._element||(this._element=this.drawView()),this._element}setReadOnly(e){this._element&&(this.readOnly=e,e?(this._element.contentEditable=`false`,this._element.removeEventListener(`keyup`,this.onKeyUp),this.placeholderCleanup&&(this.placeholderCleanup(),this.placeholderCleanup=null),u(this._element)&&(this._element.innerHTML=`<br>`)):(this._element.contentEditable=`true`,this._element.addEventListener(`keyup`,this.onKeyUp),this.placeholderCleanup=p(this._element,this.api.i18n.t(ta),`data-blok-placeholder-active`),this._element.innerHTML===`<br>`&&(this._element.innerHTML=``)))}save(e){return{text:t.Vr(e.innerHTML),size:this._data.size}}validate(e){return e.text.trim()!==``}merge(e){if(!this._element)return;this._data.text+=e.text;let t=document.createElement(`div`);t.innerHTML=e.text.trim();let n=document.createDocumentFragment();n.append(...Array.from(t.childNodes)),this._element.appendChild(n),this._element.normalize()}renderSettings(){return[{icon:t.ln,title:this.api.i18n.t(`tools.quote.size`),name:`quote-size`,children:{items:[{icon:t.ln,title:this.api.i18n.t(`tools.quote.defaultSize`),onActivate:()=>this.setSize(`default`),closeOnActivate:!0,isActive:this._data.size===`default`},{icon:t.ln,title:this.api.i18n.t(`tools.quote.largeSize`),onActivate:()=>this.setSize(`large`),closeOnActivate:!0,isActive:this._data.size===`large`}]}}]}setSize(e){this._data.size=e,this._element&&(this._element.className=r.n(this.api.styles.block,na,c,e===`large`?ra:``))}onPaste(e){let t=e.detail;if(!(`data`in t))return;let n=t.data;this._data={text:n.innerHTML,size:this._data.size},this._element&&(this._element.innerHTML=this._data.text||``)}static get toolbox(){return{icon:t.ln,titleKey:`quote`,shortcut:`"`,searchTerms:[`quote`,`blockquote`,`citation`],searchTermKeys:[`quote`,`blockquote`,`citation`]}}static get conversionConfig(){return{export:`text`,import:`text`}}static get sanitize(){return{text:{br:!0,b:!0,i:!0,a:!0,mark:{style:!0}}}}static get isReadOnlySupported(){return!0}static get pasteConfig(){return{tags:[`BLOCKQUOTE`]}}},aa=`tools.code.language`,oa=`tools.code.copied`,sa=`tools.code.copyCode`,ca=`tools.code.searchLanguage`,la=`plain text`,ua=[{id:`plain text`,name:`Plain Text`},{id:`javascript`,name:`JavaScript`},{id:`typescript`,name:`TypeScript`},{id:`python`,name:`Python`},{id:`java`,name:`Java`},{id:`c`,name:`C`},{id:`cpp`,name:`C++`},{id:`csharp`,name:`C#`},{id:`go`,name:`Go`},{id:`rust`,name:`Rust`},{id:`ruby`,name:`Ruby`},{id:`php`,name:`PHP`},{id:`swift`,name:`Swift`},{id:`kotlin`,name:`Kotlin`},{id:`latex`,name:`LaTeX`},{id:`mermaid`,name:`Mermaid`},{id:`sql`,name:`SQL`},{id:`html`,name:`HTML`},{id:`css`,name:`CSS`},{id:`json`,name:`JSON`},{id:`yaml`,name:`YAML`},{id:`markdown`,name:`Markdown`},{id:`bash`,name:`Bash`},{id:`shell`,name:`Shell`},{id:`dockerfile`,name:`Dockerfile`},{id:`xml`,name:`XML`},{id:`graphql`,name:`GraphQL`},{id:`r`,name:`R`},{id:`scala`,name:`Scala`},{id:`dart`,name:`Dart`},{id:`lua`,name:`Lua`}],da=`group/code flex flex-col rounded-xl border border-border-secondary bg-bg-secondary overflow-hidden my-2`,fa=`flex items-center gap-1 px-3 py-1.5 text-xs text-gray-text`,pa=`inline-flex items-center px-1.5 py-0.5 rounded cursor-pointer bg-transparent border-0 text-xs text-gray-text font-medium transition-colors can-hover:hover:bg-item-hover-bg select-none`,ma=`flex items-center gap-1 opacity-0 group-hover/code:opacity-100 transition-opacity`,ha=`p-1 rounded cursor-pointer bg-transparent border-0 text-gray-text transition-colors can-hover:hover:bg-item-hover-bg flex items-center justify-center`,ga=`p-1.5 rounded-lg cursor-pointer bg-transparent border-0 text-gray-text transition-colors can-hover:hover:bg-item-hover-bg flex items-center justify-center`,_a=`block px-4 py-3 font-mono text-sm leading-relaxed outline-hidden whitespace-pre-wrap overflow-x-auto min-h-[1.5em] caret-text-primary`,va=`text-xs text-gray-text font-medium select-none`,ya=new Set([`latex`,`mermaid`]),ba=`tools.code.codeTab`,xa=`tools.code.previewTab`,Sa=`px-4 py-3 overflow-x-auto min-h-[1.5em] flex justify-center`,Ca=`tools.code.sideBySide`,wa=`flex items-center rounded-lg border border-border-secondary p-0.5 gap-0.5`,Ta=`p-1 rounded cursor-pointer bg-transparent border-0 text-gray-text transition-colors flex items-center justify-center`,Ea=`p-1 rounded cursor-pointer bg-item-hover-bg border-0 text-primary transition-colors flex items-center justify-center`,Da=`flex flex-col overflow-hidden`,Oa=`flex flex-row overflow-hidden`,ka=`flex-1 min-w-0 overflow-hidden`,Aa=new Set(ua.map(e=>e.id).filter(e=>e!==la)),ja=`flex overflow-hidden`,Ma=`select-none text-right pl-4 pr-3 py-3 font-mono text-sm leading-relaxed text-gray-text/40 shrink-0`,Na=`leading-relaxed cursor-text`;function Pa(e){let n=document.createElement(`div`);n.className=wa,n.setAttribute(`role`,`group`),n.setAttribute(`data-blok-testid`,`code-view-mode`);let r=[{mode:`code`,icon:t.Q,label:e.code},{mode:`preview`,icon:t.cn,label:e.preview},{mode:`split`,icon:t.hn,label:e.split}];for(let{mode:e,icon:t,label:i}of r){let r=document.createElement(`button`);r.type=`button`,r.className=Ta,r.innerHTML=t,r.setAttribute(`aria-label`,i),r.setAttribute(`aria-pressed`,`false`),r.setAttribute(`data-blok-testid`,`code-mode-${e}`),r.setAttribute(`data-mode`,e),n.appendChild(r)}let i=document.createElement(`div`);i.className=Sa,i.setAttribute(`data-blok-testid`,`code-preview`);let a=document.createElement(`div`);return a.className=Da,a.setAttribute(`data-blok-testid`,`code-split-container`),{viewModeContainer:n,previewElement:i,splitContainer:a}}function Fa(e,t){let n=Array.from(e.querySelectorAll(`[data-mode]`));for(let e of n){let n=e.getAttribute(`data-mode`)===t;e.setAttribute(`aria-pressed`,String(n)),e.className=n?Ea:Ta}}function Ia(e){var n,r,i;let{code:a,languageName:o,readOnly:s,copyLabel:c,previewable:l,viewModeLabels:u}=e,d=document.createElement(`div`);d.className=da;let f=document.createElement(`div`);f.className=fa;let p=document.createElement(`button`);p.type=`button`,p.className=pa,p.setAttribute(`aria-haspopup`,`listbox`),p.setAttribute(`data-blok-testid`,`code-language-btn`);let m=document.createElement(`span`);m.textContent=o,p.appendChild(m);let h=document.createElement(`span`);h.className=`inline-flex items-center ml-0.5 -mr-0.5`,h.innerHTML=t.J,p.appendChild(h);let g=document.createElement(`div`);g.className=`flex-1`;let _=!s&&u?Pa(u):null,v=(n=_==null?void 0:_.viewModeContainer)==null?null:n,y=(r=_==null?void 0:_.previewElement)==null?null:r,b=(i=_==null?void 0:_.splitContainer)==null?null:i;v&&(v.hidden=!l);let x=document.createElement(`button`);x.type=`button`,x.className=l?ga:ha,x.innerHTML=t.nt,x.setAttribute(`aria-label`,c),x.setAttribute(`data-blok-testid`,`code-copy-btn`);let S=document.createElement(`code`);S.className=_a,S.setAttribute(`data-blok-testid`,`code-content`),a&&(S.textContent=a),s||(S.setAttribute(`contenteditable`,`plaintext-only`),S.setAttribute(`spellcheck`,`false`));let C=document.createElement(`div`);C.className=Ma,C.setAttribute(`aria-hidden`,`true`),C.setAttribute(`data-blok-testid`,`code-gutter`);let w=a?a.split(`
2
2
  `).length:1;Array.from({length:w},(e,t)=>{let n=document.createElement(`div`);n.className=Na,n.textContent=String(t+1),n.setAttribute(`data-line-index`,String(t)),C.appendChild(n)}),f.appendChild(p),f.appendChild(g);let T=document.createElement(`div`);T.className=ma,v&&T.appendChild(v),T.appendChild(x),f.appendChild(T);let E=document.createElement(`pre`);E.className=`flex-1 min-w-0`,E.appendChild(S);let D=document.createElement(`div`);if(D.className=ja,D.appendChild(C),D.appendChild(E),d.appendChild(f),b&&y){let e=document.createElement(`div`);e.className=ka,e.appendChild(D);let t=document.createElement(`div`);t.className=ka,t.appendChild(y),b.appendChild(e),b.appendChild(t),d.appendChild(b)}else d.appendChild(D);return{wrapper:d,languageButton:p,copyButton:x,preElement:E,codeElement:S,gutterElement:C,viewModeContainer:v,previewElement:y,splitContainer:b}}function La(e,t,n){return e.key===`Enter`&&e.shiftKey?(n(),!0):e.key===`Enter`?(za(t),!0):e.key===`Tab`&&!e.shiftKey?(Ha(),!0):e.key===`Tab`&&e.shiftKey?(Wa(t),!0):!1}var Ra={"{":`}`,"(":`)`,"[":`]`};function za(e){var t;let n=window.getSelection();if(!n||n.rangeCount===0)return;let r=n.getRangeAt(0),i=Va(e,r.startContainer,r.startOffset),a=Va(e,r.endContainer,r.endOffset),o=(t=e.textContent)==null?``:t,s=o.substring(0,i),c=o.substring(a),l=s.lastIndexOf(`
3
3
  `)+1,u=s.substring(l).match(/^[ \t]*/),d=u?u[0]:``,f=Ra[s.length>0?s.charAt(s.length-1):``],p=c.charAt(0),{inserted:m,caretDelta:h}=Ba({indent:d,afterOpener:f!==void 0,betweenMatchedPair:f!==void 0&&p===f});for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(document.createTextNode(s+m+c)),Ga(e,i+h)}function Ba(e){let{indent:t,afterOpener:n,betweenMatchedPair:r}=e;return r?{inserted:`\n${t} \n${t}`,caretDelta:1+t.length+2}:n?{inserted:`\n${t} `,caretDelta:1+t.length+2}:{inserted:`\n${t}`,caretDelta:1+t.length}}function Va(e,t,n){let r=document.createRange();return r.selectNodeContents(e),r.setEnd(t,n),r.toString().length}function Ha(){let e=window.getSelection();if(!e||e.rangeCount===0)return;let t=e.getRangeAt(0);t.deleteContents();let n=document.createTextNode(` `);t.insertNode(n),t.setStartAfter(n),t.collapse(!0),e.removeAllRanges(),e.addRange(t)}function Ua(e){let t=Math.min(2,e.length),n=e.substring(0,t).match(/^ */);return n?n[0].length:0}function Wa(e){var t;let n=window.getSelection();if(!n||n.rangeCount===0)return;let r=n.getRangeAt(0),i=(t=e.textContent)==null?``:t,a=r.cloneRange();a.selectNodeContents(e),a.setEnd(r.startContainer,r.startOffset);let o=a.toString().length,s=i.lastIndexOf(`
4
4
  `,o-1)+1,c=Ua(i.substring(s));if(c===0)return;let l=i.substring(0,s)+i.substring(s+c);for(;e.firstChild;)e.removeChild(e.firstChild);e.appendChild(document.createTextNode(l)),Ga(e,Math.max(s,o-c))}function Ga(e,t){let n=window.getSelection();if(!n)return;let r=document.createTreeWalker(e,NodeFilter.SHOW_TEXT),i=e=>{var a;let o=r.nextNode();if(!o)return;let s=((a=o.textContent)==null?``:a).length;if(e+s>=t){let r=document.createRange();r.setStart(o,t-e),r.collapse(!0),n.removeAllRanges(),n.addRange(r);return}i(e+s)};i(0)}var Ka={katexPromise:null,cssInjected:!1};function qa(){if(Ka.cssInjected)return;Ka.cssInjected=!0;let e=document.createElement(`link`);e.rel=`stylesheet`,e.setAttribute(`data-katex-css`,``),e.href=`https://cdn.jsdelivr.net/npm/katex@latest/dist/katex.min.css`,document.head.appendChild(e)}async function Ja(){return Ka.katexPromise||(Ka.katexPromise=Promise.resolve().then(()=>require(`./katex-BH7WMnlH.cjs`)).then(e=>e.n).then(e=>e.default)),Ka.katexPromise}async function Ya(e){qa();try{return(await Ja()).renderToString(e,{throwOnError:!1,displayMode:!0})}catch(e){return`<span class="text-red-500 text-sm">${e instanceof Error?e.message:`Unknown error`}</span>`}}var Xa={mermaidPromise:null,initialized:!1};async function Za(){Xa.mermaidPromise||(Xa.mermaidPromise=Promise.resolve().then(()=>require(`./mermaid.core-BRsCWNyd.cjs`)).then(e=>e.default));let e=await Xa.mermaidPromise;return Xa.initialized||(Xa.initialized=!0,e.initialize({startOnLoad:!1,securityLevel:`strict`})),e}async function Qa(e){try{let t=await Za();if(await t.parse(e,{suppressErrors:!0})===!1)return`<span class="text-red-500 text-sm">Invalid Mermaid syntax</span>`;let n=`mermaid-${crypto.randomUUID()}`;return(await t.render(n,e)).svg}catch(e){return`<span class="text-red-500 text-sm">${e instanceof Error?e.message:`Unknown error`}</span>`}}var $a=e.t(((e,t)=>{var n=function(e){var t=/(?:^|\s)lang(?:uage)?-([\w-]+)(?=\s|$)/i,n=0,r={},i={manual:e.Prism&&e.Prism.manual,disableWorkerMessageHandler:e.Prism&&e.Prism.disableWorkerMessageHandler,util:{encode:function e(t){return t instanceof a?new a(t.type,e(t.content),t.alias):Array.isArray(t)?t.map(e):t.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/\u00a0/g,` `)},type:function(e){return Object.prototype.toString.call(e).slice(8,-1)},objId:function(e){return e.__id||Object.defineProperty(e,`__id`,{value:++n}),e.__id},clone:function e(t,n){n=n||{};var r,a;switch(i.util.type(t)){case`Object`:if(a=i.util.objId(t),n[a])return n[a];for(var o in r={},n[a]=r,t)t.hasOwnProperty(o)&&(r[o]=e(t[o],n));return r;case`Array`:return a=i.util.objId(t),n[a]?n[a]:(r=[],n[a]=r,t.forEach(function(t,i){r[i]=e(t,n)}),r);default:return t}},getLanguage:function(e){for(;e;){var n=t.exec(e.className);if(n)return n[1].toLowerCase();e=e.parentElement}return`none`},setLanguage:function(e,n){e.className=e.className.replace(RegExp(t,`gi`),``),e.classList.add(`language-`+n)},currentScript:function(){if(typeof document>`u`)return null;if(document.currentScript&&document.currentScript.tagName===`SCRIPT`)return document.currentScript;try{throw Error()}catch(r){var e=(/at [^(\r\n]*\((.*):[^:]+:[^:]+\)$/i.exec(r.stack)||[])[1];if(e){var t=document.getElementsByTagName(`script`);for(var n in t)if(t[n].src==e)return t[n]}return null}},isActive:function(e,t,n){for(var r=`no-`+t;e;){var i=e.classList;if(i.contains(t))return!0;if(i.contains(r))return!1;e=e.parentElement}return!!n}},languages:{plain:r,plaintext:r,text:r,txt:r,extend:function(e,t){var n=i.util.clone(i.languages[e]);for(var r in t)n[r]=t[r];return n},insertBefore:function(e,t,n,r){r=r||i.languages;var a=r[e],o={};for(var s in a)if(a.hasOwnProperty(s)){if(s==t)for(var c in n)n.hasOwnProperty(c)&&(o[c]=n[c]);n.hasOwnProperty(s)||(o[s]=a[s])}var l=r[e];return r[e]=o,i.languages.DFS(i.languages,function(t,n){n===l&&t!=e&&(this[t]=o)}),o},DFS:function e(t,n,r,a){a=a||{};var o=i.util.objId;for(var s in t)if(t.hasOwnProperty(s)){n.call(t,s,t[s],r||s);var c=t[s],l=i.util.type(c);l===`Object`&&!a[o(c)]?(a[o(c)]=!0,e(c,n,null,a)):l===`Array`&&!a[o(c)]&&(a[o(c)]=!0,e(c,n,s,a))}}},plugins:{},highlightAll:function(e,t){i.highlightAllUnder(document,e,t)},highlightAllUnder:function(e,t,n){var r={callback:n,container:e,selector:`code[class*="language-"], [class*="language-"] code, code[class*="lang-"], [class*="lang-"] code`};i.hooks.run(`before-highlightall`,r),r.elements=Array.prototype.slice.apply(r.container.querySelectorAll(r.selector)),i.hooks.run(`before-all-elements-highlight`,r);for(var a=0,o;o=r.elements[a++];)i.highlightElement(o,t===!0,r.callback)},highlightElement:function(t,n,r){var a=i.util.getLanguage(t),o=i.languages[a];i.util.setLanguage(t,a);var s=t.parentElement;s&&s.nodeName.toLowerCase()===`pre`&&i.util.setLanguage(s,a);var c={element:t,language:a,grammar:o,code:t.textContent};function l(e){c.highlightedCode=e,i.hooks.run(`before-insert`,c),c.element.innerHTML=c.highlightedCode,i.hooks.run(`after-highlight`,c),i.hooks.run(`complete`,c),r&&r.call(c.element)}if(i.hooks.run(`before-sanity-check`,c),s=c.element.parentElement,s&&s.nodeName.toLowerCase()===`pre`&&!s.hasAttribute(`tabindex`)&&s.setAttribute(`tabindex`,`0`),!c.code){i.hooks.run(`complete`,c),r&&r.call(c.element);return}if(i.hooks.run(`before-highlight`,c),!c.grammar){l(i.util.encode(c.code));return}if(n&&e.Worker){var u=new Worker(i.filename);u.onmessage=function(e){l(e.data)},u.postMessage(JSON.stringify({language:c.language,code:c.code,immediateClose:!0}))}else l(i.highlight(c.code,c.grammar,c.language))},highlight:function(e,t,n){var r={code:e,grammar:t,language:n};if(i.hooks.run(`before-tokenize`,r),!r.grammar)throw Error(`The language "`+r.language+`" has no grammar.`);return r.tokens=i.tokenize(r.code,r.grammar),i.hooks.run(`after-tokenize`,r),a.stringify(i.util.encode(r.tokens),r.language)},tokenize:function(e,t){var n=t.rest;if(n){for(var r in n)t[r]=n[r];delete t.rest}var i=new c;return l(i,i.head,e),s(e,i,t,i.head,0),d(i)},hooks:{all:{},add:function(e,t){var n=i.hooks.all;n[e]=n[e]||[],n[e].push(t)},run:function(e,t){var n=i.hooks.all[e];if(!(!n||!n.length))for(var r=0,a;a=n[r++];)a(t)}},Token:a};e.Prism=i;function a(e,t,n,r){this.type=e,this.content=t,this.alias=n,this.length=(r||``).length|0}a.stringify=function e(t,n){if(typeof t==`string`)return t;if(Array.isArray(t)){var r=``;return t.forEach(function(t){r+=e(t,n)}),r}var a={type:t.type,content:e(t.content,n),tag:`span`,classes:[`token`,t.type],attributes:{},language:n},o=t.alias;o&&(Array.isArray(o)?Array.prototype.push.apply(a.classes,o):a.classes.push(o)),i.hooks.run(`wrap`,a);var s=``;for(var c in a.attributes)s+=` `+c+`="`+(a.attributes[c]||``).replace(/"/g,`&quot;`)+`"`;return`<`+a.tag+` class="`+a.classes.join(` `)+`"`+s+`>`+a.content+`</`+a.tag+`>`};function o(e,t,n,r){e.lastIndex=t;var i=e.exec(n);if(i&&r&&i[1]){var a=i[1].length;i.index+=a,i[0]=i[0].slice(a)}return i}function s(e,t,n,r,c,d){for(var f in n)if(!(!n.hasOwnProperty(f)||!n[f])){var p=n[f];p=Array.isArray(p)?p:[p];for(var m=0;m<p.length;++m){if(d&&d.cause==f+`,`+m)return;var h=p[m],g=h.inside,_=!!h.lookbehind,v=!!h.greedy,y=h.alias;if(v&&!h.pattern.global){var b=h.pattern.toString().match(/[imsuy]*$/)[0];h.pattern=RegExp(h.pattern.source,b+`g`)}for(var x=h.pattern||h,S=r.next,C=c;S!==t.tail&&!(d&&C>=d.reach);C+=S.value.length,S=S.next){var w=S.value;if(t.length>e.length)return;if(!(w instanceof a)){var T=1,E;if(v){if(E=o(x,C,e,_),!E||E.index>=e.length)break;var D=E.index,O=E.index+E[0].length,k=C;for(k+=S.value.length;D>=k;)S=S.next,k+=S.value.length;if(k-=S.value.length,C=k,S.value instanceof a)continue;for(var A=S;A!==t.tail&&(k<O||typeof A.value==`string`);A=A.next)T++,k+=A.value.length;T--,w=e.slice(C,k),E.index-=C}else if(E=o(x,0,w,_),!E)continue;var D=E.index,j=E[0],M=w.slice(0,D),N=w.slice(D+j.length),P=C+w.length;d&&P>d.reach&&(d.reach=P);var ee=S.prev;M&&(ee=l(t,ee,M),C+=M.length),u(t,ee,T);var te=new a(f,g?i.tokenize(j,g):j,y,j);if(S=l(t,ee,te),N&&l(t,S,N),T>1){var ne={cause:f+`,`+m,reach:P};s(e,t,n,S.prev,C,ne),d&&ne.reach>d.reach&&(d.reach=ne.reach)}}}}}}function c(){var e={value:null,prev:null,next:null},t={value:null,prev:e,next:null};e.next=t,this.head=e,this.tail=t,this.length=0}function l(e,t,n){var r=t.next,i={value:n,prev:t,next:r};return t.next=i,r.prev=i,e.length++,i}function u(e,t,n){for(var r=t.next,i=0;i<n&&r!==e.tail;i++)r=r.next;t.next=r,r.prev=t,e.length-=i}function d(e){for(var t=[],n=e.head.next;n!==e.tail;)t.push(n.value),n=n.next;return t}if(!e.document)return e.addEventListener&&(i.disableWorkerMessageHandler||e.addEventListener(`message`,function(t){var n=JSON.parse(t.data),r=n.language,a=n.code,o=n.immediateClose;e.postMessage(i.highlight(a,i.languages[r],r)),o&&e.close()},!1)),i;var f=i.util.currentScript();f&&(i.filename=f.src,f.hasAttribute(`data-manual`)&&(i.manual=!0));function p(){i.manual||i.highlightAll()}if(!i.manual){var m=document.readyState;m===`loading`||m===`interactive`&&f&&f.defer?document.addEventListener(`DOMContentLoaded`,p):window.requestAnimationFrame?window.requestAnimationFrame(p):window.setTimeout(p,16)}return i}(typeof window<`u`?window:typeof WorkerGlobalScope<`u`&&self instanceof WorkerGlobalScope?self:{});t!==void 0&&t.exports&&(t.exports=n),typeof global<`u`&&(global.Prism=n),n.languages.markup={comment:{pattern:/<!--(?:(?!<!--)[\s\S])*?-->/,greedy:!0},prolog:{pattern:/<\?[\s\S]+?\?>/,greedy:!0},doctype:{pattern:/<!DOCTYPE(?:[^>"'[\]]|"[^"]*"|'[^']*')+(?:\[(?:[^<"'\]]|"[^"]*"|'[^']*'|<(?!!--)|<!--(?:[^-]|-(?!->))*-->)*\]\s*)?>/i,greedy:!0,inside:{"internal-subset":{pattern:/(^[^\[]*\[)[\s\S]+(?=\]>$)/,lookbehind:!0,greedy:!0,inside:null},string:{pattern:/"[^"]*"|'[^']*'/,greedy:!0},punctuation:/^<!|>$|[[\]]/,"doctype-tag":/^DOCTYPE/i,name:/[^\s<>'"]+/}},cdata:{pattern:/<!\[CDATA\[[\s\S]*?\]\]>/i,greedy:!0},tag:{pattern:/<\/?(?!\d)[^\s>\/=$<%]+(?:\s(?:\s*[^\s>\/=]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+(?=[\s>]))|(?=[\s/>])))+)?\s*\/?>/,greedy:!0,inside:{tag:{pattern:/^<\/?[^\s>\/]+/,inside:{punctuation:/^<\/?/,namespace:/^[^\s>\/:]+:/}},"special-attr":[],"attr-value":{pattern:/=\s*(?:"[^"]*"|'[^']*'|[^\s'">=]+)/,inside:{punctuation:[{pattern:/^=/,alias:`attr-equals`},{pattern:/^(\s*)["']|["']$/,lookbehind:!0}]}},punctuation:/\/?>/,"attr-name":{pattern:/[^\s>\/]+/,inside:{namespace:/^[^\s>\/:]+:/}}}},entity:[{pattern:/&[\da-z]{1,8};/i,alias:`named-entity`},/&#x?[\da-f]{1,8};/i]},n.languages.markup.tag.inside[`attr-value`].inside.entity=n.languages.markup.entity,n.languages.markup.doctype.inside[`internal-subset`].inside=n.languages.markup,n.hooks.add(`wrap`,function(e){e.type===`entity`&&(e.attributes.title=e.content.replace(/&amp;/,`&`))}),Object.defineProperty(n.languages.markup.tag,`addInlined`,{value:function(e,t){var r={};r[`language-`+t]={pattern:/(^<!\[CDATA\[)[\s\S]+?(?=\]\]>$)/i,lookbehind:!0,inside:n.languages[t]},r.cdata=/^<!\[CDATA\[|\]\]>$/i;var i={"included-cdata":{pattern:/<!\[CDATA\[[\s\S]*?\]\]>/i,inside:r}};i[`language-`+t]={pattern:/[\s\S]+/,inside:n.languages[t]};var a={};a[e]={pattern:RegExp(`(<__[^>]*>)(?:<!\\[CDATA\\[(?:[^\\]]|\\](?!\\]>))*\\]\\]>|(?!<!\\[CDATA\\[)[\\s\\S])*?(?=<\\/__>)`.replace(/__/g,function(){return e}),`i`),lookbehind:!0,greedy:!0,inside:i},n.languages.insertBefore(`markup`,`cdata`,a)}}),Object.defineProperty(n.languages.markup.tag,`addAttribute`,{value:function(e,t){n.languages.markup.tag.inside[`special-attr`].push({pattern:RegExp(`(^|["'\\s])(?:`+e+`)\\s*=\\s*(?:"[^"]*"|'[^']*'|[^\\s'">=]+(?=[\\s>]))`,`i`),lookbehind:!0,inside:{"attr-name":/^[^\s=]+/,"attr-value":{pattern:/=[\s\S]+/,inside:{value:{pattern:/(^=\s*(["']|(?!["'])))\S[\s\S]*(?=\2$)/,lookbehind:!0,alias:[t,`language-`+t],inside:n.languages[t]},punctuation:[{pattern:/^=/,alias:`attr-equals`},/"|'/]}}}})}}),n.languages.html=n.languages.markup,n.languages.mathml=n.languages.markup,n.languages.svg=n.languages.markup,n.languages.xml=n.languages.extend(`markup`,{}),n.languages.ssml=n.languages.xml,n.languages.atom=n.languages.xml,n.languages.rss=n.languages.xml,(function(e){var t=/(?:"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"|'(?:\\(?:\r\n|[\s\S])|[^'\\\r\n])*')/;e.languages.css={comment:/\/\*[\s\S]*?\*\//,atrule:{pattern:RegExp(`@[\\w-](?:[^;{\\s"']|\\s+(?!\\s)|`+t.source+`)*?(?:;|(?=\\s*\\{))`),inside:{rule:/^@[\w-]+/,"selector-function-argument":{pattern:/(\bselector\s*\(\s*(?![\s)]))(?:[^()\s]|\s+(?![\s)])|\((?:[^()]|\([^()]*\))*\))+(?=\s*\))/,lookbehind:!0,alias:`selector`},keyword:{pattern:/(^|[^\w-])(?:and|not|only|or)(?![\w-])/,lookbehind:!0}}},url:{pattern:RegExp(`\\burl\\((?:`+t.source+`|(?:[^\\\\\\r\\n()"']|\\\\[\\s\\S])*)\\)`,`i`),greedy:!0,inside:{function:/^url/i,punctuation:/^\(|\)$/,string:{pattern:RegExp(`^`+t.source+`$`),alias:`url`}}},selector:{pattern:RegExp(`(^|[{}\\s])[^{}\\s](?:[^{};"'\\s]|\\s+(?![\\s{])|`+t.source+`)*(?=\\s*\\{)`),lookbehind:!0},string:{pattern:t,greedy:!0},property:{pattern:/(^|[^-\w\xA0-\uFFFF])(?!\s)[-_a-z\xA0-\uFFFF](?:(?!\s)[-\w\xA0-\uFFFF])*(?=\s*:)/i,lookbehind:!0},important:/!important\b/i,function:{pattern:/(^|[^-a-z0-9])[-a-z0-9]+(?=\()/i,lookbehind:!0},punctuation:/[(){};:,]/},e.languages.css.atrule.inside.rest=e.languages.css;var n=e.languages.markup;n&&(n.tag.addInlined(`style`,`css`),n.tag.addAttribute(`style`,`css`))})(n),n.languages.clike={comment:[{pattern:/(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/,lookbehind:!0,greedy:!0},{pattern:/(^|[^\\:])\/\/.*/,lookbehind:!0,greedy:!0}],string:{pattern:/(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,greedy:!0},"class-name":{pattern:/(\b(?:class|extends|implements|instanceof|interface|new|trait)\s+|\bcatch\s+\()[\w.\\]+/i,lookbehind:!0,inside:{punctuation:/[.\\]/}},keyword:/\b(?:break|catch|continue|do|else|finally|for|function|if|in|instanceof|new|null|return|throw|try|while)\b/,boolean:/\b(?:false|true)\b/,function:/\b\w+(?=\()/,number:/\b0x[\da-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?/i,operator:/[<>]=?|[!=]=?=?|--?|\+\+?|&&?|\|\|?|[?*/~^%]/,punctuation:/[{}[\];(),.:]/},n.languages.javascript=n.languages.extend(`clike`,{"class-name":[n.languages.clike[`class-name`],{pattern:/(^|[^$\w\xA0-\uFFFF])(?!\s)[_$A-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\.(?:constructor|prototype))/,lookbehind:!0}],keyword:[{pattern:/((?:^|\})\s*)catch\b/,lookbehind:!0},{pattern:/(^|[^.]|\.\.\.\s*)\b(?:as|assert(?=\s*\{)|async(?=\s*(?:function\b|\(|[$\w\xA0-\uFFFF]|$))|await|break|case|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally(?=\s*(?:\{|$))|for|from(?=\s*(?:['"]|$))|function|(?:get|set)(?=\s*(?:[#\[$\w\xA0-\uFFFF]|$))|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)\b/,lookbehind:!0}],function:/#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*(?:\.\s*(?:apply|bind|call)\s*)?\()/,number:{pattern:RegExp(`(^|[^\\w$])(?:NaN|Infinity|0[bB][01]+(?:_[01]+)*n?|0[oO][0-7]+(?:_[0-7]+)*n?|0[xX][\\dA-Fa-f]+(?:_[\\dA-Fa-f]+)*n?|\\d+(?:_\\d+)*n|(?:\\d+(?:_\\d+)*(?:\\.(?:\\d+(?:_\\d+)*)?)?|\\.\\d+(?:_\\d+)*)(?:[Ee][+-]?\\d+(?:_\\d+)*)?)(?![\\w$])`),lookbehind:!0},operator:/--|\+\+|\*\*=?|=>|&&=?|\|\|=?|[!=]==|<<=?|>>>?=?|[-+*/%&|^!=<>]=?|\.{3}|\?\?=?|\?\.?|[~:]/}),n.languages.javascript[`class-name`][0].pattern=/(\b(?:class|extends|implements|instanceof|interface|new)\s+)[\w.\\]+/,n.languages.insertBefore(`javascript`,`keyword`,{regex:{pattern:RegExp(`((?:^|[^$\\w\\xA0-\\uFFFF."'\\])\\s]|\\b(?:return|yield))\\s*)\\/(?:(?:\\[(?:[^\\]\\\\\\r\\n]|\\\\.)*\\]|\\\\.|[^/\\\\\\[\\r\\n])+\\/[dgimyus]{0,7}|(?:\\[(?:[^[\\]\\\\\\r\\n]|\\\\.|\\[(?:[^[\\]\\\\\\r\\n]|\\\\.|\\[(?:[^[\\]\\\\\\r\\n]|\\\\.)*\\])*\\])*\\]|\\\\.|[^/\\\\\\[\\r\\n])+\\/[dgimyus]{0,7}v[dgimyus]{0,7})(?=(?:\\s|\\/\\*(?:[^*]|\\*(?!\\/))*\\*\\/)*(?:$|[\\r\\n,.;:})\\]]|\\/\\/))`),lookbehind:!0,greedy:!0,inside:{"regex-source":{pattern:/^(\/)[\s\S]+(?=\/[a-z]*$)/,lookbehind:!0,alias:`language-regex`,inside:n.languages.regex},"regex-delimiter":/^\/|\/$/,"regex-flags":/^[a-z]+$/}},"function-variable":{pattern:/#?(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*[=:]\s*(?:async\s*)?(?:\bfunction\b|(?:\((?:[^()]|\([^()]*\))*\)|(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)\s*=>))/,alias:`function`},parameter:[{pattern:/(function(?:\s+(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)?\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\))/,lookbehind:!0,inside:n.languages.javascript},{pattern:/(^|[^$\w\xA0-\uFFFF])(?!\s)[_$a-z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*=>)/i,lookbehind:!0,inside:n.languages.javascript},{pattern:/(\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*=>)/,lookbehind:!0,inside:n.languages.javascript},{pattern:/((?:\b|\s|^)(?!(?:as|async|await|break|case|catch|class|const|continue|debugger|default|delete|do|else|enum|export|extends|finally|for|from|function|get|if|implements|import|in|instanceof|interface|let|new|null|of|package|private|protected|public|return|set|static|super|switch|this|throw|try|typeof|undefined|var|void|while|with|yield)(?![$\w\xA0-\uFFFF]))(?:(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*\s*)\(\s*|\]\s*\(\s*)(?!\s)(?:[^()\s]|\s+(?![\s)])|\([^()]*\))+(?=\s*\)\s*\{)/,lookbehind:!0,inside:n.languages.javascript}],constant:/\b[A-Z](?:[A-Z_]|\dx?)*\b/}),n.languages.insertBefore(`javascript`,`string`,{hashbang:{pattern:/^#!.*/,greedy:!0,alias:`comment`},"template-string":{pattern:/`(?:\\[\s\S]|\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}|(?!\$\{)[^\\`])*`/,greedy:!0,inside:{"template-punctuation":{pattern:/^`|`$/,alias:`string`},interpolation:{pattern:/((?:^|[^\\])(?:\\{2})*)\$\{(?:[^{}]|\{(?:[^{}]|\{[^}]*\})*\})+\}/,lookbehind:!0,inside:{"interpolation-punctuation":{pattern:/^\$\{|\}$/,alias:`punctuation`},rest:n.languages.javascript}},string:/[\s\S]+/}},"string-property":{pattern:/((?:^|[,{])[ \t]*)(["'])(?:\\(?:\r\n|[\s\S])|(?!\2)[^\\\r\n])*\2(?=\s*:)/m,lookbehind:!0,greedy:!0,alias:`property`}}),n.languages.insertBefore(`javascript`,`operator`,{"literal-property":{pattern:/((?:^|[,{])[ \t]*)(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*(?=\s*:)/m,lookbehind:!0,alias:`property`}}),n.languages.markup&&(n.languages.markup.tag.addInlined(`script`,`javascript`),n.languages.markup.tag.addAttribute(`on(?:abort|blur|change|click|composition(?:end|start|update)|dblclick|error|focus(?:in|out)?|key(?:down|up)|load|mouse(?:down|enter|leave|move|out|over|up)|reset|resize|scroll|select|slotchange|submit|unload|wheel)`,`javascript`)),n.languages.js=n.languages.javascript,(function(){if(n===void 0||typeof document>`u`)return;Element.prototype.matches||(Element.prototype.matches=Element.prototype.msMatchesSelector||Element.prototype.webkitMatchesSelector);var e=`Loading…`,t=function(e,t){return`✖ Error `+e+` while fetching file: `+t},r=`✖ Error: File does not exist or is empty`,i={js:`javascript`,py:`python`,rb:`ruby`,ps1:`powershell`,psm1:`powershell`,sh:`bash`,bat:`batch`,h:`c`,tex:`latex`},a=`data-src-status`,o=`loading`,s=`loaded`,c=`failed`,l=`pre[data-src]:not([`+a+`="`+s+`"]):not([`+a+`="`+o+`"])`;function u(e,n,i){var a=new XMLHttpRequest;a.open(`GET`,e,!0),a.onreadystatechange=function(){a.readyState==4&&(a.status<400&&a.responseText?n(a.responseText):a.status>=400?i(t(a.status,a.statusText)):i(r))},a.send(null)}function d(e){var t=/^\s*(\d+)\s*(?:(,)\s*(?:(\d+)\s*)?)?$/.exec(e||``);if(t){var n=Number(t[1]),r=t[2],i=t[3];return r?i?[n,Number(i)]:[n,void 0]:[n,n]}}n.hooks.add(`before-highlightall`,function(e){e.selector+=`, `+l}),n.hooks.add(`before-sanity-check`,function(t){var r=t.element;if(r.matches(l)){t.code=``,r.setAttribute(a,o);var f=r.appendChild(document.createElement(`CODE`));f.textContent=e;var p=r.getAttribute(`data-src`),m=t.language;if(m===`none`){var h=(/\.(\w+)$/.exec(p)||[,`none`])[1];m=i[h]||h}n.util.setLanguage(f,m),n.util.setLanguage(r,m);var g=n.plugins.autoloader;g&&g.loadLanguages(m),u(p,function(e){r.setAttribute(a,s);var t=d(r.getAttribute(`data-range`));if(t){var i=e.split(/\r\n?|\n/g),o=t[0],c=t[1]==null?i.length:t[1];o<0&&(o+=i.length),o=Math.max(0,Math.min(o-1,i.length)),c<0&&(c+=i.length),c=Math.max(0,Math.min(c,i.length)),e=i.slice(o,c).join(`