Files
2026-04-28 15:13:50 +02:00

6 lines
31 KiB
JavaScript

import{U as W,aq as A,d as Q,q as j,u as z}from"./app-core.ae890a3f.js";import{Q as l}from"./vendor-quill.fa67f709.js";import{h as B,_ as S}from"./vendor-other.7b559694.js";import{B as K}from"./Input.8918dec2.js";import{S as Z}from"./Caret.a017b70a.js";import{S as J}from"./Plus.97dee933.js";import{_ as X}from"./Trash.d35f8063.js";import{aq as I,f as b,i as T,j as f,P as Y,M as y,B as O,O as D,ad as G,Y as E,a5 as v,U as M,a0 as N}from"./vendor-vue-ui.de3ab35f.js";import{_ as tt}from"./_plugin-vue_export-helper.eefbdd86.js";const et=(n,t,e)=>{const i=n;return Object.keys(t).forEach(s=>{-1<e.indexOf(s)?i.dataset[s]=t[s]:delete i.dataset[s]}),i},R=(n,t)=>t.reduce((e,i)=>{const s=n.lastIndexOf(i);return s>e.mentionCharIndex?{mentionChar:i,mentionCharIndex:s}:{mentionChar:e.mentionChar,mentionCharIndex:e.mentionCharIndex}},{mentionChar:null,mentionCharIndex:-1}),it=(n,t)=>t.test(n),st=(n,t,e)=>-1<n?!(e&&!(n===0||t[n-1].match(/\s/g))):!1,nt=l.import("blots/embed");class C extends nt{constructor(t,e){super(t,e),this.clickHandler=this.clickHandler.bind(this),e.addEventListener("click",this.clickHandler)}static getQuillInstance(t){let e=l.find(t);if(e){for(;e.parent;)e=e.parent;return e.domNode.parentNode?l.find(e.domNode.parentNode):null}}clickHandler(){const t=C.getQuillInstance(this.domNode),e=t.getModule("mention");if(e.currentBlot=this,e.currentNode=this.domNode,e.isOpen)return this.domNode.querySelector(".aioseo-tag .tag-toggle svg").classList.remove("rotated"),e.hideMentionList();this.domNode.querySelector(".aioseo-tag .tag-toggle svg").classList.add("rotated"),e.mentionCharPos=this.offset(t.scroll),e.options.source("",e.renderList.bind(e,this.domNode.dataset.denotationChar),this.domNode.dataset.denotationChar)}static create(t){const e=super.create(),i=document.createElement("span");if(i.className="ql-mention-denotation-char",i.innerHTML=t.denotationChar||"#",e.appendChild(i),e.innerHTML+=t.value,t.custom&&t.customValue){let s=e.querySelector(".tag-custom");if(!s){s=document.createElement("span"),s.classList.add("tag-custom");const a=e.querySelector(".tag-name");a.parentNode.insertBefore(s,a.nextSibling)}s.innerHTML="&nbsp;-&nbsp;"+(t.customValue||"")}return setTimeout(()=>{const s=C.getQuillInstance(e);if(s){const a=s.getModule("mention");a.currentNode=e}},0),C.setDataValues(e,t)}static setDataValues(t,e){const i=t;return Object.keys(e).forEach(s=>{i.dataset[s]=e[s]}),i}static value(t){return t.dataset}format(t,e){t==="customValue"&&e?this.domNode.dataset.customValue=e:super.format(t,e)}}C.blotName="mention";C.tagName="span";C.className="mention";l.register(C);const m={TAB:"Tab",ENTER:"Enter",ESCAPE:"Escape",UP:"ArrowUp",DOWN:"ArrowDown",SPACE:" "};class ot{constructor(t,e){this.isOpen=!1,this.itemIndex=0,this.mentionCharPos=null,this.cursorPos=null,this.values=[],this.suspendMouseEnter=!1,this.activeElement=null,this.currentBlot=null,this.currentNode=null,this.quill=t,this.silentInsert=!1,this.insertingCustomItem=!1,this.options={source:null,renderItem(r){return`${r.value}`},onSelect(r,h){h(r)},mentionDenotationChars:["@"],showDenotationChar:!0,allowedChars:/^[a-zA-Z0-9_]*$/,minChars:0,maxChars:1e3,offsetTop:2,offsetLeft:0,isolateCharacter:!1,fixMentionsToQuill:!1,defaultMenuOrientation:"bottom",dataAttributes:["id","value","denotationChar","link","target"],linkTarget:"_blank",onOpen(){return!0},onClose(){return!0},listItemClass:"ql-mention-list-item",mentionContainerClass:"ql-mention-list-container",mentionListClass:"ql-mention-list",spaceAfterInsert:!0,selectKeys:[m.ENTER]},Object.assign(this.options,e,{dataAttributes:Array.isArray(e.dataAttributes)?this.options.dataAttributes.concat(e.dataAttributes):this.options.dataAttributes}),this.mentionContainer=document.createElement("div"),this.mentionContainer.className=this.options.mentionContainerClass?this.options.mentionContainerClass:"",this.mentionContainer.style.cssText="display: none; position: absolute;",this.mentionContainer.onmousemove=this.onContainerMouseMove.bind(this),this.options.fixMentionsToQuill&&(this.mentionContainer.style.width="auto"),this.customFieldInput=document.createElement("div"),this.customFieldInput.className=this.options.mentionPrependClassCustom?this.options.mentionPrependClassCustom:"",this.customFieldInput.innerHTML=this.options.customFieldInput||"",this.mentionContainer.appendChild(this.customFieldInput),this.mentionSearch=document.createElement("div"),this.mentionSearch.className=this.options.mentionPrependClass?this.options.mentionPrependClass:"",this.mentionSearch.innerHTML=this.options.prependMentionList||"",this.mentionContainer.appendChild(this.mentionSearch);const i=this.mentionSearch.querySelector(".aioseo-trash");i&&i.addEventListener("click",()=>{this.currentBlot.remove(),this.hideMentionList(),this.removeOrphanedMentionChar()}),this.customFieldInput.addEventListener("click",r=>{this.activeElement=r.target;const h=r.target.querySelector("input");h&&setTimeout(()=>{h.focus()},0)});const s=this.customFieldInput.querySelector("input");s&&s.addEventListener("input",r=>{if(this.currentNode){let h=this.currentNode.querySelector(".tag-custom");if(!h){h=document.createElement("span"),h.classList.add("tag-custom");const u=this.currentNode.querySelector(".tag-name");u.parentNode.insertBefore(h,u.nextSibling)}h.innerHTML=r.target.value?"&nbsp;-&nbsp;"+r.target.value:"",this.currentBlot=l.find(this.currentNode),this.currentBlot.format("customValue",r.target.value)}}),this.customFieldInput.addEventListener("keydown",r=>{m.ENTER===r.key&&(this.hideMentionList(),this.removeOrphanedMentionChar(),r.preventDefault()),m.ESCAPE===r.key&&(this.hideMentionList(),this.removeOrphanedMentionChar()),m.SPACE===r.key&&r.preventDefault()}),this.mentionSearch.addEventListener("click",r=>{this.activeElement=r.target}),this.mentionSearch.addEventListener("keydown",r=>{m.DOWN===r.key&&this.nextItem(),m.UP===r.key&&this.prevItem(),m.ENTER===r.key&&(this.selectItem(),r.preventDefault()),m.ESCAPE===r.key&&this.hideMentionList()});const a=this.mentionSearch.querySelector("input");a&&a.addEventListener("input",r=>{const h=this.getTextBeforeCursor(),{mentionChar:u}=R(h,this.options.mentionDenotationChars);if(!u&&!this.currentBlot)return;const d=u||this.currentBlot.domNode.dataset.denotationChar;this.options.source(r.target.value,this.renderList.bind(this,d),d)}),this.mentionList=document.createElement("ul"),this.mentionList.id="quill-mention-list",t.root.setAttribute("aria-owns","quill-mention-list"),this.mentionList.className=this.options.mentionListClass?this.options.mentionListClass:"",this.mentionContainer.appendChild(this.mentionList);const o=document.createElement("div");o.className="aioseo-documentation-link",o.innerHTML=this.options.documentationDiv||"",o.addEventListener("click",r=>{this.activeElement=r.target}),this.mentionContainer.appendChild(o),this.quill.container.appendChild(this.mentionContainer),t.on("text-change",this.onTextChange.bind(this)),t.on("selection-change",this.onSelectionChange.bind(this)),t.container.addEventListener("paste",()=>{setTimeout(()=>{const r=t.getSelection();this.onSelectionChange(r)})}),t.keyboard.addBinding({key:m.TAB},this.selectHandler.bind(this)),t.keyboard.bindings[m.TAB].unshift(t.keyboard.bindings[m.TAB].pop());for(const r of this.options.selectKeys??[])t.keyboard.addBinding({key:r},this.selectHandler.bind(this));t.keyboard.bindings[m.ENTER].unshift(t.keyboard.bindings[m.ENTER].pop()),t.keyboard.addBinding({key:m.ESCAPE},this.escapeHandler.bind(this)),t.keyboard.addBinding({key:m.UP},this.upHandler.bind(this)),t.keyboard.addBinding({key:m.DOWN},this.downHandler.bind(this)),t.clipboard.addMatcher(Node.TEXT_NODE,this.clipboardHandler.bind(this))}selectHandler(){return this.isOpen?(this.selectItem(),!1):!0}escapeHandler(){return this.isOpen?(this.hideMentionList(),this.removeOrphanedMentionChar(),!1):!0}removeOrphanedMentionChar(t=!1){let e=!1;!t&&!this.quill.hasFocus()&&(this.quill.focus(),e=!0);const i=this.getTextBeforeCursor();i.charAt(i.length-1)==="#"&&this.quill.deleteText(this.quill.getSelection().index-1,1,l.sources.USER),e&&this.quill.blur()}upHandler(){return this.isOpen?(this.prevItem(),!1):!0}downHandler(){return this.isOpen?(this.nextItem(),!1):!0}clipboardHandler(t,e){if(typeof t.data!="string")return;const i=new RegExp(`${this.options.mentionDenotationChars.join("|")}[A-Za-z0-9_-]+`,"g"),s=t.data.match(i);if(s&&0<s.length){const a=[];let o=t.data;this.mentionCharPos=0,s.forEach(r=>{const h=r.charAt(0),u=r.substr(1).split("-"),d=u[0];delete u[0];const p=u.filter(U=>U).join("-"),g=this.options.source(d,this.renderList.bind(this,h),h,!0,p||null);if(!g)return;const L={denotationChar:this.options.showDenotationChar?h:"",...g};p!==void 0&&(L.customValue=p);const x=o.split(r),P=x.shift();a.push({insert:P}),a.push({insert:{mention:L}}),o=x.join(r)}),a.push({insert:o}),e.ops=a}return e}showMentionList(){if(this.mentionContainer.style.visibility="hidden",this.mentionContainer.style.display="",this.setMentionContainerPosition(),this.customFieldInput.style.display="none",this.currentNode&&this.currentNode.dataset.custom){this.customFieldInput.style.display="block";const e=this.customFieldInput&&this.customFieldInput.querySelector("input"),i=this.currentNode.querySelector(".tag-custom");e&&i&&(e.value=i.innerHTML.replace("&nbsp;-&nbsp;","").trim())}const t=this.mentionSearch.querySelector(".aioseo-trash");t&&(t.style.display="block",this.currentBlot||(t.style.display="none")),this.setIsOpen(!0)}hideMentionList(){document.querySelectorAll(".aioseo-tag .tag-toggle svg").forEach(s=>{s.classList.remove("rotated")});const e=this.mentionSearch&&this.mentionSearch.querySelector("input");e&&(e.value="");const i=this.customFieldInput&&this.customFieldInput.querySelector("input");i&&(i.value=""),this.currentBlot=null,this.currentNode=null,this.mentionContainer.style.display="none",this.setIsOpen(!1)}highlightItem(t=!0){if(!this.mentionList.childNodes[this.itemIndex])return;for(let i=0;i<this.mentionList.childNodes.length;i+=1){const s=this.mentionList.childNodes[i];s instanceof HTMLElement&&s.classList.remove("selected")}const e=this.mentionList.childNodes[this.itemIndex];if(!(this.itemIndex===-1||e.dataset.disabled==="true")&&(e.classList.add("selected"),this.quill.root.setAttribute("aria-activedescendant",e.id),t)){const i=e.offsetHeight,s=e.offsetTop-this.mentionSearch.offsetHeight,a=this.mentionList.scrollTop,o=a+this.mentionList.offsetHeight;s<a?this.mentionList.scrollTop=s:s>o-i&&(this.mentionList.scrollTop+=s-o+i)}}getItemData(){const{link:t}=this.mentionList.childNodes[this.itemIndex].dataset,e=typeof t<"u",i=this.mentionList.childNodes[this.itemIndex].dataset.target;return e&&(this.mentionList.childNodes[this.itemIndex].dataset.value=`<a href="${t}" target=${i||this.options.linkTarget}>${this.mentionList.childNodes[this.itemIndex].dataset.value}`),this.mentionList.childNodes[this.itemIndex].dataset}onContainerMouseMove(){this.suspendMouseEnter=!1}selectItem(){const t=this.getItemData();if(!t.id)return this.hideMentionList();this.options.onSelect(t,e=>{this.insertItem(e)}),t.custom||this.hideMentionList()}insertItem(t){const e=t;if(e===null)return;this.options.showDenotationChar||(e.denotationChar=""),t.custom&&(this.insertingCustomItem=!0,setTimeout(()=>{this.insertingCustomItem=!1},50),this.customFieldInput.style.display="block",this.customFieldInput.click());const i=this.mentionCharPos;this.quill.deleteText(this.mentionCharPos,this.cursorPos-this.mentionCharPos,l.sources.USER),this.quill.insertEmbed(i,"mention",e,l.sources.USER),this.options.spaceAfterInsert?(this.quill.insertText(i+1," ",l.sources.USER),this.quill.setSelection(i+2,l.sources.USER)):this.quill.setSelection(i+1,l.sources.USER),t.custom||this.hideMentionList()}onItemMouseEnter(t){if(this.suspendMouseEnter)return;const e=Number(t.target.dataset.index);!Number.isNaN(e)&&e!==this.itemIndex&&(this.itemIndex=e,this.highlightItem(!1))}onItemClick(t){t.preventDefault(),t.stopImmediatePropagation(),this.itemIndex=t.currentTarget.dataset.index,this.highlightItem(),this.selectItem()}renderList(t,e,i,s=!1,a=!1){if(this.mentionList.innerHTML="",e&&0<e.length){if(this.values=e,this.values.length===1&&(this.values[0].name===i||this.values[0].id===i)){if(s)return this.values[0];this.insertItem(this.values[0]);return}else if(s){const o=this.values.find(r=>r.name===i||r.id===i);if(o)return o}else if(a){const o=this.values.find(r=>r.name===i||r.id===i);o&&this.insertItem(o)}for(let o=0;o<e.length;o+=1){const r=document.createElement("li");r.className=this.options.listItemClass?this.options.listItemClass:"",r.dataset.index=o,r.innerHTML=this.options.renderItem(e[o],i),r.onmouseenter=this.onItemMouseEnter.bind(this),r.dataset.denotationChar=t,r.onclick=this.onItemClick.bind(this),this.mentionList.appendChild(et(r,e[o],this.options.dataAttributes))}this.itemIndex=0,this.highlightItem()}else{const o=document.createElement("li");o.className=this.options.listItemClassNoMatch?this.options.listItemClassNoMatch:"",o.innerHTML=this.options.renderItemNoMatch(),this.mentionList.appendChild(o)}this.showMentionList()}nextItem(){this.itemIndex=(this.itemIndex+1)%this.values.length,this.suspendMouseEnter=!0,this.highlightItem()}prevItem(){this.itemIndex=(this.itemIndex+this.values.length-1)%this.values.length,this.suspendMouseEnter=!0,this.highlightItem()}containerBottomIsNotVisible(){return this.mentionContainer.getBoundingClientRect().bottom>window.innerHeight}containerRightIsNotVisible(t,e){return this.options.fixMentionsToQuill?!1:e.width<t+this.mentionContainer.offsetWidth}setIsOpen(t){this.isOpen!==t&&(t?this.options.onOpen():this.options.onClose(),this.isOpen=t)}setMentionContainerPosition(){const t=this.quill.container.getBoundingClientRect(),e=this.quill.getBounds(this.mentionCharPos),i=this.mentionContainer.offsetHeight;let s=this.options.offsetTop,a=this.options.offsetLeft;if(this.options.fixMentionsToQuill?this.mentionContainer.style.right="0px":a+=e.left,this.containerRightIsNotVisible(a,t)){const o=this.mentionContainer.offsetWidth+this.options.offsetLeft;a=t.width-o}if(this.options.defaultMenuOrientation==="top"){if(this.options.fixMentionsToQuill?s=-1*(i+this.options.offsetTop):s=e.top-(i+this.options.offsetTop),0>=s+t.top){let o=this.options.offsetTop;this.options.fixMentionsToQuill?o+=t.height:o+=e.bottom,s=o}}else if(this.options.fixMentionsToQuill?s+=t.height:s+=e.bottom,this.containerBottomIsNotVisible(s,t)){let o=this.options.offsetTop*-1;this.options.fixMentionsToQuill||(o+=e.top),s=o-i}0<=s?this.options.mentionContainerClass.split(" ").forEach(o=>{this.mentionContainer.classList.add(`${o}-bottom`),this.mentionContainer.classList.remove(`${o}-top`)}):this.options.mentionContainerClass.split(" ").forEach(o=>{this.mentionContainer.classList.add(`${o}-top`),this.mentionContainer.classList.remove(`${o}-bottom`)}),this.mentionContainer.style.top=`${s}px`,this.mentionContainer.style.left=`${a}px`,this.mentionContainer.style.visibility="visible"}getTextBeforeCursor(){const t=Math.max(0,(this.cursorPos??0)-this.options.maxChars);return this.quill.getText(t,(this.cursorPos??0)-t)}onSomethingChange(){const t=this.quill.getSelection();if(t===null||this.insertingCustomItem)return;this.cursorPos=t.index;const e=this.getTextBeforeCursor(),{mentionChar:i,mentionCharIndex:s}=R(e,this.options.mentionDenotationChars);if(st(s,e,this.options.isolateCharacter)){const a=this.cursorPos-(e.length-s);this.mentionCharPos=a;const o=e.substring(s+i.length);o.length>=this.options.minChars&&it(o,this.options.allowedChars)?this.options.source(o,this.renderList.bind(this,i),i):this.hideMentionList()}else this.hideMentionList()}onTextChange(t,e,i){i==="user"&&setTimeout(this.onSomethingChange.bind(this),0)}onSelectionChange(t){t&&t.length===0?this.onSomethingChange():setTimeout(()=>{this.activeElement?this.activeElement.classList.contains("aioseo-tag-custom")||(this.activeElement=null):this.hideMentionList.bind(this)},0)}}l.register("modules/mention",ot);const rt=l.import("modules/toolbar");class V extends rt{}V.DEFAULTS.handlers.autoLink=function(){const n=this.quill.getSelection(),t=this.quill.getModule("autoLink"),e=this.quill.getContents();e.ops.forEach(i=>{i?.attributes?.link&&delete i.attributes.link}),this.quill.setContents(e,l.sources.SILENT),this.quill.setSelection(n,l.sources.SILENT),this.quill.format("link",t.options.url,l.sources.USER)};l.register("modules/toolbar",V,!0);class at{constructor(t,e){this.quill=t,this.options=e,this.container=document.querySelector(e.container)}}l.register("modules/autoLink",at,!0);class lt{constructor(t,e){this.quill=t,this.options=e,this.container=document.querySelector(e.container),t.on("text-change",this.update.bind(this)),this.update()}calculate(){let t=this.quill.getText()?this.quill.root.innerHTML:"";const e=document.createRange().createContextualFragment(t),i=document.createRange().createContextualFragment("");e.childNodes.forEach(a=>{if(a.tagName!=="P")return;a.childNodes.forEach(r=>{if(r.nodeType===3){i.appendChild(r.cloneNode(!0));return}if(r.tagName==="SPAN"){const h=r.querySelector(".aioseo-tag .tag-name");if(h){const u=this.options.tags.find(g=>g.name===h.textContent);let d=typeof u.valueText=="string"?B.decode(u.valueText):u.valueText;d=W(d,!1);const p=document.createTextNode(d);i.appendChild(p)}}});const o=document.createElement("br");i.appendChild(o)}),i.normalize();const s=document.createElement("div");return s.appendChild(i.cloneNode(!0)),t=s.innerHTML.replace(/&nbsp;/gi," ").replace(/<br\s*[/]?>/gi,this.single?"":`
`).trim(),{length:B.decode(t).length,text:t}}update(){const{length:t}=this.calculate();let e=this.options.unit;t!==1&&(e+="s"),this.container&&(this.container.innerText=t+" "+e)}}l.register("modules/counter",lt);const ct=l.import("modules/clipboard"),ht=l.import("delta");class ut extends ct{onPaste(t,{html:e,text:i}){const s=this.options,a=this.quill.getFormat(t.index),o=this.convert({text:i,html:e},a),r=new ht().retain(t.index).delete(t.length).concat(o);s.newLines===!1&&r.ops.map(function(h){return typeof h.insert=="string"&&(h.insert=h.insert.replace(/(\r\n|\n|\r)/gm," ")),h}),this.quill.updateContents(r,l.sources.USER),this.quill.setSelection(r.length()-t.length,l.sources.SILENT),this.quill.scrollSelectionIntoView()}convert({html:t,text:e}){return typeof t=="string"&&(t=t.replace(/>\r?\n +</g,"><")),super.convert({html:t,text:e})}}l.register("modules/clipboard",ut,!0);class dt{constructor(t,e){this.quill=t,this.options={defaultLength:1,...e},this.container=e.container,t.on("text-change",this.update.bind(this)),this.update()}update(){for(;this.container.firstChild;)this.container.removeChild(this.container.firstChild);const t=this.quill.getLines();if(this.options.defaultLength>t.length)for(let s=t.length;this.options.defaultLength>s;s++)t.push({});let e=0;for(let s=0;s<t.length;s++){const a=t[s].domNode?t[s].domNode.offsetHeight:25,o=document.createElement("div");o.style.minHeight=`${a}px`,o.innerHTML=s+1,this.container.appendChild(o),e+=a}const i=this.quill.container.querySelector(".ql-editor");if(i){const s=window.getComputedStyle(i);i.style.minHeight=`${e+parseInt(s.getPropertyValue("padding-top"))+parseInt(s.getPropertyValue("padding-bottom"))}px`}}}l.register("modules/lineNumbers",dt,!0);const _=(n,t,e)=>(n.forEach(i=>{e[i]&&t.setAttribute(i,e[i]),i==="data-*"&&Object.keys(e).forEach(s=>{s.indexOf("data-")===0&&t.setAttribute(s,e[s])})}),t),q=(n,t)=>n.reduce((e,i)=>(t.hasAttribute(i)&&(e[i]=t.getAttribute(i)),i==="data-*"&&Object.keys(t.dataset).forEach(s=>{s="data-"+s.replace(/[A-Z]/g,a=>`-${a.toLowerCase()}`),e[s]=t.getAttribute(s)}),e),{}),mt=l.import("formats/link"),w=["href","rel","target","class","data-*","style"];class pt extends mt{static linkAttributesCache={};static create(t){typeof t=="string"&&(t=this.linkAttributesCache);const e=_(w,super.create(t),t);return w.forEach(i=>{i==="href"&&(t[i]=this.sanitize(t[i]),e.setAttribute(i,t[i]))}),this.linkAttributesCache=t,e}static formats(t){return q(w,t)}}l.register("formats/link",pt,!0);const k=["style","class","data-*"],ft=l.import("blots/inline");class H extends ft{static create(t){return _(k,super.create(t),t)}static formats(t){return q(k,t)}}H.blotName="aioseoInline";H.tagName="aioseo-inline";l.register("formats/aioseoInline",H,!0);const gt=l.import("formats/italic");class Ct extends gt{static create(t){return _(k,super.create(t),t)}static formats(t){return q(k,t)}}l.register("formats/italic",Ct,!0);class bt{constructor(t,e){this.quill=t,this.options=e,this.preserveWhitespace=e.preserveWhitespace||!1,t.clipboard.addMatcher(Node.TEXT_NODE,this.clipboardHandler.bind(this)),t.container.style.whiteSpace="pre-line"}clipboardHandler(t,e){if(t.data.match(/^\t/)&&this.preserveWhitespace){const i=l.import("delta");return new i().insert(t.data)}return e}}l.register("modules/preserveWhiteSpace",bt);const Tt=n=>{const{invalidClosingTags:t,invalidOpeningTags:e,tagNamePattern:i}=F(n);let s=n;return t.forEach(a=>{s=`<${a.match(i)[1]}>`+s}),e.forEach(a=>{const o=a.match(i)[1];s=s+`</${o}>`}),s},Lt=(n,t)=>{const{invalidClosingTags:e,invalidOpeningTags:i,tagNamePattern:s}=F(n);return e.forEach(a=>{const o=a.match(s)[1],r=new RegExp(`^<${o}>`);t=t.replace(r,"")}),i.forEach(a=>{const o=a.match(s)[1],r=new RegExp(`<\\/${o}>$`);t=t.replace(r,"")}),t},F=n=>{const t=new RegExp(/(<[^<>]*>)/),e=new RegExp(/<\s?\/[^<>]*>/),i=new RegExp(/<\s?\/?([^<\s>]*).*?>/,"s"),s=n.split(t),a=[];s.forEach(u=>{u.match(t)&&a.push(u)});const o=[];a.forEach((u,d)=>{if(!u)return;if(u.match(e)){o.push(u),a[d]="";return}const p=u.match(i)[1];let g=!1;a.forEach((L,x)=>{if(d===x||!L||g||!L.match(e))return;const P=L.match(i)[1];if(p===P){a[d]="",a[x]="",g=!0;return}o.push(u),a[d]=""})});const r=[],h=[];return o.forEach(u=>{if(u.match(t)){if(u.match(e)){h.push(u);return}r.push(u)}}),{invalidClosingTags:h,invalidOpeningTags:r,tagNamePattern:i}},$="all-in-one-seo-pack",c=[],xt={emits:["counter","selection-change","updateEditor","focus","blur","update:modelValue","paste"],setup(){return{links:Q,postEditorStore:z(),tagsStore:j()}},components:{BaseInput:K,SvgCaret:Z,SvgPlus:J,SvgTrash:X},props:{modelValue:{type:String,default:""},minimumLineNumbers:{type:Number,default(){return 5}},single:Boolean,lineNumbers:Boolean,allowTags:Boolean,disabled:Boolean,tagsContext:String,forceUpdates:Boolean,monospace:Boolean,defaultMenuOrientation:String,description:Boolean,showToolbar:Boolean,preserveWhitespace:Boolean,autoLink:{type:[Object,Boolean],default(){return!1}}},data(){return{tags:A,localTags:[],quill:null,html:"",insertExact:!1,cachedPhrase:"",strings:{searchPlaceholder:S("Search for an item...",$),enterCustomFieldName:S("Enter a custom field/taxonomy name...",$),learnMoreSmartTags:S("Learn more about Smart Tags",$),removeSmartTag:S("Remove Smart Tag",$)}}},watch:{disabled(){this.disabled?c[this.$.uid].disable():c[this.$.uid].enable()},modelValue(){this.forceUpdates&&this.startup(!0)},"tagsStore.liveTags":{deep:!0,handler(){this.localTags=this.getTags();const n=c[this.$.uid].getModule("counter");n&&(n.options.tags=this.localTags,this.$emit("counter",n.calculate()))}},tags:{deep:!0,handler(){const n=this.getTags();JSON.stringify(this.localTags)!==JSON.stringify(n)&&(this.localTags=n,this.startup(!0))}}},methods:{emitPasteEvent(n){this.$emit("paste",n)},getTags(){return(this.tagsContext?[...A.context(this.tagsContext)]:[...this.tagsStore.tags].filter(t=>!t.deprecated)).map((t,e)=>{const i=this.postEditorStore.currentPost&&this.tagsStore.liveTags[t.id]||t.value;return{...t,valueText:i,value:this.$refs["select-template"]?.[e]?.innerHTML||"",menuHtml:this.$refs["menu-template"]?.[e]?.innerHTML||""}})},update(){if(this.allowTags){const s=c[this.$.uid].getModule("counter");this.$emit("counter",s.calculate())}let n=c[this.$.uid].getText()?c[this.$.uid].root.innerHTML:"";const t=document.createRange().createContextualFragment(n),e=document.createRange().createContextualFragment("");t.childNodes.forEach(s=>{if(s.tagName!=="P")return;s.childNodes.forEach(o=>{if(o.nodeType===3){e.appendChild(o.cloneNode(!0));return}if(o.tagName==="SPAN"&&this.allowTags){const r=o.querySelector(".aioseo-tag");if(r){const h=r.querySelector(".tag-name");if(h){const u=this.localTags.find(p=>p.name===h.textContent);if(u.custom){const p=r.querySelector(".tag-custom");if(p){const g=document.createTextNode(`#${u.id}-${p.innerHTML.replace("&nbsp;-&nbsp;","")}`);e.appendChild(g);return}}const d=document.createTextNode(`#${u.id}`);e.appendChild(d)}}}});const a=document.createElement("br");e.appendChild(a)}),e.normalize();const i=document.createElement("div");i.appendChild(e.cloneNode(!0)),n=i.innerHTML.replace(/<br\s*[/]?>/gi,this.single?"":`
`).trim(),n=n.replace(/&nbsp;/gi," ").trim(),this.$emit("update:modelValue",n)},insertToCursor(n){c[this.$.uid].focus(),c[this.$.uid].insertText(c[this.$.uid].getSelection().index,n,l.sources.USER),c[this.$.uid].setSelection(c[this.$.uid].getSelection().index+n.length,l.sources.USER)},insertTag(n){const t=c[this.$.uid].getModule("mention");t.removeOrphanedMentionChar();const e=t.getTextBeforeCursor();this.insertExact=!0;const i=n?this.localTags.find(o=>o.id===n):null;let s=i?`#${i.id}`:e.charAt(e.length-1)==="#"?"":"#";const a=c[this.$.uid].getContents(0,t.cursorPos);a.ops.length&&(typeof a.ops.pop().insert!="string"||!e.match(/\s$/))&&(s=" "+s),c[this.$.uid].focus(),n&&t.removeOrphanedMentionChar(),c[this.$.uid].insertText(c[this.$.uid].getSelection().index,s,l.sources.USER),c[this.$.uid].setSelection(c[this.$.uid].getSelection().index+s.length,l.sources.USER),this.insertExact=!1,n?t.hideMentionList():setTimeout(()=>{t.mentionCharPos=c[this.$.uid].getSelection().index-1,t.silentInsert=!0,t.showMentionList()},0)},maybeCloseMenu(n){const t=n.target;if(t.classList.contains("aioseo-tag")||t.closest(".aioseo-tag")||t.closest(".add-tags"))return;if(t.classList.contains("ql-mention-list-container")||t.closest(".ql-mention-list-container")){const i=t.classList.contains("prepend-icon")?t:t.closest(".prepend-icon");i&&i.nextSibling.focus();return}const e=c[this.$.uid].getModule("mention");e?.isOpen&&(e.hideMentionList(),e.removeOrphanedMentionChar())},startup(n=!1){if(this.allowTags&&!this.$refs["tag-search"])return;c[this.$.uid]=this.startQuill(),n&&c[this.$.uid].setText("");let t=this.modelValue;t&&t.length&&t.match(/#[^\s]*$/)&&(t=t.trim()+"&nbsp;"),t=t&&(this.single?t.replace(`
`," "):"<p>"+t.split(`
`).map(s=>s===""?"<br>":s).join("</p><p>")+"</p>");const e=c[this.$.uid].clipboard.convert({html:t,text:""});c[this.$.uid].setContents(e);const i=c[this.$.uid].getModule("mention");if(i?.isOpen?(i.hideMentionList(),i.removeOrphanedMentionChar()):i&&i.removeOrphanedMentionChar(!0),this.allowTags){const s=c[this.$.uid].getModule("counter");this.$emit("counter",s.calculate())}this.removeTrailingNewLine(),this.$nextTick(()=>{c[this.$.uid].on("text-change",()=>this.update()),c[this.$.uid].on("selection-change",(s,a,o)=>{o==="api"&&this.update(),s?this.$emit("focus",c[this.$.uid]):this.$emit("blur",c[this.$.uid]),this.$emit("selection-change",{range:s,oldRange:a,source:o})}),document.addEventListener("click",this.maybeCloseMenu),this.disabled&&c[this.$.uid].disable(),n||c[this.$.uid].history.clear()})},startQuill(){return new l(this.$refs.quill,{modules:{toolbar:this.showToolbar?["bold","italic","underline","autoLink"]:[],lineNumbers:this.lineNumbers?{container:this.$refs["line-numbers"],defaultLength:this.minimumLineNumbers}:null,mention:this.allowTags?{defaultMenuOrientation:this.defaultMenuOrientation||"bottom",dataAttributes:["id","value","denotationChar","link","target","custom","customValue"],allowedChars:/^[A-Za-z\s_]*$/,mentionDenotationChars:["#"],spaceAfterInsert:!0,mentionPrependClass:"aioseo-tag-search",mentionPrependClassCustom:"aioseo-tag-custom",prependMentionList:this.$refs["tag-search"].innerHTML,customFieldInput:this.$refs["tag-custom"].innerHTML,documentationDiv:this.$refs["documentation-div"].innerHTML,listItemClassNoMatch:"aioseo-tag-no-match",renderItemNoMatch(){return"No matches found"},renderItem(n){return`${n.menuHtml}`},source:(n,t,e,i=!1,s="")=>{const a=[...this.localTags];if(a[0].custom&&(a[0].customValue=s),n.length===0)return t(a,n,i,this.insertExact);const o=[];for(let r=0;r<a.length;r++)(~a[r].name.toLowerCase().indexOf(n.toLowerCase())||~a[r].id.toLowerCase().indexOf(n.toLowerCase()))&&o.push(a[r]);return t(o,n,i,this.insertExact)}}:null,counter:this.allowTags?{tags:this.localTags}:null,clipboard:{newLines:!this.single},autoLink:{enabled:!!this.autoLink,...this.autoLink},keyboard:{bindings:{enter:{key:13,handler:()=>!this.single}}},preserveWhiteSpace:this.preserveWhitespace},theme:"snow",formats:this.showToolbar?["bold","underline","italic","link","list","aioseoInline"]:["mention"]})},setPhrase(n){this.cachedPhrase=n,n=Tt(n),n=n.replace(/<span([^>]*)>/g,"<aioseo-inline$1>").replace(/<\/span>/g,"</aioseo-inline>");const t=c[this.$.uid].clipboard.convert({html:n,text:""});c[this.$.uid].setContents(t)},getPhrase(){return c[this.$.uid].getText()},getPhraseWithFormats(){return c[this.$.uid].getContents()},getPhraseHtml(){let n=c[this.$.uid].root.childNodes[0].innerHTML;return n=n.replace(/<aioseo-inline([^>]*)>/g,"<span$1>").replace(/<\/aioseo-inline>/g,"</span>"),n=Lt(this.cachedPhrase,n),n},removeTrailingNewLine(){const n=document.querySelector(".aioseo-editor-description .ql-editor");this.description&&n&&(n.innerHTML=n.innerHTML.replace(/<p><br><\/p>$/i,""))}},mounted(){this.localTags=this.getTags(),this.startup(!0),this.tagsContext&&window.aioseoBus.$on("updateEditor"+this.tagsContext,n=>{n!==this.$.uid&&this.startup(!0)})},beforeUnmount(){document.removeEventListener("click",this.maybeCloseMenu)},unmounted(){this.tagsContext&&window.aioseoBus.$emit("updateEditor"+this.tagsContext,this.$.uid)}},Et={class:"aioseo-editor"},vt={key:0,ref:"line-numbers",class:"aioseo-line-numbers"},Nt={key:1,class:"aioseo-append-icon"},St={key:2,class:"aioseo-append-button"},It={class:"aioseo-tag"},yt={class:"tag-name"},Mt={key:0,class:"tag-custom"},$t={class:"tag-toggle"},kt={class:"aioseo-tag-item"},Pt={class:"aioseo-tag-title"},wt={class:"aioseo-tag-description"},_t={ref:"tag-search"},qt={ref:"tag-custom"},Ht=["innerHTML"];function At(n,t,e,i,s,a){const o=I("svg-caret"),r=I("svg-plus"),h=I("base-input"),u=I("svg-trash");return b(),T("div",Et,[f("div",{class:Y([{"aioseo-editor-line-numbers":e.lineNumbers},{"aioseo-editor-single":e.single},{"aioseo-editor-monospace":e.monospace},{"aioseo-editor-description":e.description}]),ref:"quill",onPaste:t[0]||(t[0]=(...d)=>a.emitPasteEvent&&a.emitPasteEvent(...d))},null,34),e.lineNumbers?(b(),T("div",vt,null,512)):y("",!0),n.$slots["append-icon"]?(b(),T("div",Nt,[O(n.$slots,"append-icon")])):y("",!0),n.$slots["append-button"]?(b(),T("div",St,[O(n.$slots,"append-button")])):y("",!0),(b(!0),T(D,null,G(s.tags.context(e.tagsContext),(d,p)=>(b(),T(D,{key:p},[E(f("div",{ref_for:!0,ref:"select-template"},[f("span",It,[f("span",yt,M(d.name),1),d.custom&&d.customValue?(b(),T("span",Mt," - "+M(d.customValue),1)):y("",!0),f("span",$t,[N(o)])])],512),[[v,!1]]),E(f("div",{ref_for:!0,ref:"menu-template"},[f("div",kt,[f("div",null,[N(r)]),f("div",null,[f("div",Pt,M(d.name),1),f("div",wt,M(d.description),1)])])],512),[[v,!1]])],64))),128)),E(f("div",_t,[N(h,{size:"medium",placeholder:s.strings.searchPlaceholder,prependIcon:"search"},null,8,["placeholder"]),N(u)],512),[[v,!1]]),E(f("div",qt,[N(h,{size:"small",placeholder:s.strings.enterCustomFieldName},null,8,["placeholder"])],512),[[v,!1]]),E(f("div",{ref:"documentation-div",innerHTML:i.links.getDocLink(s.strings.learnMoreSmartTags,"smartTags",!0)},null,8,Ht),[[v,!1]])])}const jt=tt(xt,[["render",At]]);export{jt as B};