import{U as t,E as e,h as s,R as n}from"./p-46048b08.js";import{y as o,c as r,a as i,M as a,A as c,p as l,R as d}from"./p-7e9c2be7.js";import"./p-dcc98162.js";import"./p-2ade684f.js";import"./p-add8f9c6.js";import"./p-ce3cf81d.js";import{V as h,a as p,b as u}from"./p-b6152e4f.js";import"./p-dfd0e4f2.js";import"./p-503d32d7.js";import"./p-467fe4d7.js";import"./p-d9bc8c9f.js";import{g as k}from"./p-8b5d3a52.js";import{c as b}from"./p-a841cf13.js";class f extends o{constructor(t,e){super(),this.type="INSERT_TOKEN_NODE",this.rteRange=null,this.actionHandleResult=!1,this.rteRange=t,this.token=e}}class m extends h{constructor(t){super(),this.tokenList=[],this.tokenList=t}render(t,e){return this.renderDropdown(t,e,{},[this.renderButton(t,e,{label:"Tokens",showArrowIcon:!0}),this.renderDropdownListTemplate(t,this.tokenList)])}isDisabled(t){const e=this.getExtensionContext(t.host);if(e){const{host:t,getSelectedNodes:s}=e,[n]=s();return n?t.disabled||!r.canHandle("INSERT_TOKEN_NODE",n.parent):t.disabled}return!1}handleButtonClick(t){}handleDropdownClick(t,e){const s=this.getListItemByKey(this.tokenList,t),{rteRange:n}=e,{startNode:o}=n;if(o&&o.parent){const t=new f(n,s);o.parent.apply(t),t.actionHandleResult&&this.flushEditorUI(e)}}flushEditorUI(t){const e=this.getExtensionContext(t.host);if(e){const{host:t,flushValue:s}=e;s(t.value)}}}class RTETokenNode extends i{constructor(t,e,s,n,o){super(t,s,n,o),this.type="token",this.token=e,this.text=s}static from(t,e){const s=new RTETokenNode(t.id,t.token,t.text,e);return t.annotations&&(s.annotationMap=this.generateTextAnnotationMap(t.annotations)),s}toJSON(){const t=super.toJSON();return Object.assign({id:this.id,type:this.type,text:this.text,token:this.token},t.annotations?{annotations:t.annotations}:{})}isContentEditable(){return!1}clone(t){return new RTETokenNode(this.id,this.token,this.text,t,this.annotationMap)}toHtml(){return`<span class="token" contenteditable="false" template-token-key="${this.token}" token-key="${this.token}"${super.generateAttributeString()}>${this.text}</span>`}}class T extends p{doRender(t,e,s){const{id:n,token:o}=e;return t("span",Object.assign(Object.assign({key:n,"template-token-key":o,"token-key":o,contenteditable:"false",style:e.getStyles(),class:`token ${e.getClasses()}`},this.additionalAttributes(e)),{ref:this.useRef(e),onClick:t=>{t.preventDefault(),s&&!1!==s.editable&&this.handleTokenElementClick(t,e,s.host)}}),e.text)}injectRTEScopeStyles(){return"span[token-key]{padding: 0 2px; margin: 0 1px; background-color: rgba(var(--v-bg-status-info, 205,209,211))}"}handleTokenElementClick(e,s,n){e.preventDefault(),n&&n.value.apply(new t(s,void 0,!0))}additionalAttributes(t){const e=t.getCustomAttributesAnnotation();let s={wrapped:"true"};return e&&(s=Object.assign(Object.assign({},s),e.render())),s}}class j extends o{constructor(t,e){super(),this.type=a.INSERT_NODE_TO_NEAREST_ROOT,this.rteRange=t,this.nodeToBeInserted=e}}class E extends c{handleAction(t,e){const{rteRange:s,token:n}=t;if(s&&s.startNode){const{key:o,label:r,customAttrs:i={wrapped:"true"}}=n,a=new RTETokenNode(k(),o,r,e);a.annotationMap.set("CUSTOM_ATTRIBUTE",new l(i)),e.apply(new j(s,a)),t.actionHandleResult=!0}}}const O=new class extends e{canHandle(t,e){const s=t[e];return"SPAN"===s.nodeName&&s.classList.contains("token")&&s.hasAttribute("token-key")?1:0}handle(t){const e=t[0],n=e.getAttribute("token-key"),o=e.textContent,r=s.generate(i,e),{customAttribute:a}=r,c=function(t,e){var s={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(s[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(t);o<n.length;o++)e.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(t,n[o])&&(s[n[o]]=t[n[o]])}return s}(r,["customAttribute","customClass"]);return{id:k(),type:"token",token:n,text:o,annotations:Object.assign(Object.assign({},c),{customAttribute:this.createCustomAttrs(a)})}}appendChildBlocks(){}shouldProceedToElementChildren(){return!1}createCustomAttrs(t){const e=Object.assign(Object.assign({},t),{contenteditable:null,"template-token-key":null,"token-key":null,wrapped:"false"===t.wrapped?"false":"true"});return b(e)}};class N extends u{constructor(t=[]){super(),this.tokenRenderer=new T,this.registerNode("token",RTETokenNode),this.registerRenderer("token",this.tokenRenderer),this.tokenToolbarButtonRenderer=new m(t),this.registerToolbarButtonRenderer("token",this.tokenToolbarButtonRenderer),this.registerElementToNodeDTOClassStrategy(O)}}(()=>{const t=new E;u.registerActionHandleStrategy(d.name,"INSERT_TOKEN_NODE",t),u.registerActionHandleStrategy(n.name,"INSERT_TOKEN_NODE",t)})();const R=Object.freeze({__proto__:null,VegaRTETokenExtension:N});export{j as I,m as R,N as V,RTETokenNode as a,T as b,R as t}