@aquera/nile-elements 1.5.9 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/README.md +3 -0
  2. package/dist/index.js +84 -45
  3. package/dist/nile-rich-text-editor/nile-rich-text-editor.cjs.js +1 -1
  4. package/dist/nile-rich-text-editor/nile-rich-text-editor.cjs.js.map +1 -1
  5. package/dist/nile-rich-text-editor/nile-rich-text-editor.css.cjs.js +1 -1
  6. package/dist/nile-rich-text-editor/nile-rich-text-editor.css.cjs.js.map +1 -1
  7. package/dist/nile-rich-text-editor/nile-rich-text-editor.css.esm.js +24 -0
  8. package/dist/nile-rich-text-editor/nile-rich-text-editor.esm.js +1 -1
  9. package/dist/nile-rich-text-editor/nile-rte-link.cjs.js +1 -1
  10. package/dist/nile-rich-text-editor/nile-rte-link.cjs.js.map +1 -1
  11. package/dist/nile-rich-text-editor/nile-rte-link.esm.js +59 -44
  12. package/dist/nile-rich-text-editor/utils/inline-utils.cjs.js +1 -1
  13. package/dist/nile-rich-text-editor/utils/inline-utils.cjs.js.map +1 -1
  14. package/dist/nile-rich-text-editor/utils/inline-utils.esm.js +1 -1
  15. package/dist/src/nile-rich-text-editor/nile-rich-text-editor.css.js +24 -0
  16. package/dist/src/nile-rich-text-editor/nile-rich-text-editor.css.js.map +1 -1
  17. package/dist/src/nile-rich-text-editor/nile-rich-text-editor.d.ts +6 -0
  18. package/dist/src/nile-rich-text-editor/nile-rich-text-editor.js +62 -24
  19. package/dist/src/nile-rich-text-editor/nile-rich-text-editor.js.map +1 -1
  20. package/dist/src/nile-rich-text-editor/nile-rte-link.d.ts +12 -0
  21. package/dist/src/nile-rich-text-editor/nile-rte-link.js +239 -130
  22. package/dist/src/nile-rich-text-editor/nile-rte-link.js.map +1 -1
  23. package/dist/src/nile-rich-text-editor/nile-rte-link.test.d.ts +1 -0
  24. package/dist/src/nile-rich-text-editor/nile-rte-link.test.js +469 -0
  25. package/dist/src/nile-rich-text-editor/nile-rte-link.test.js.map +1 -0
  26. package/dist/src/nile-rich-text-editor/utils/inline-utils.js +13 -4
  27. package/dist/src/nile-rich-text-editor/utils/inline-utils.js.map +1 -1
  28. package/dist/src/version.js +1 -1
  29. package/dist/src/version.js.map +1 -1
  30. package/dist/tsconfig.tsbuildinfo +1 -1
  31. package/package.json +1 -1
  32. package/src/nile-rich-text-editor/nile-rich-text-editor.css.ts +24 -0
  33. package/src/nile-rich-text-editor/nile-rich-text-editor.ts +66 -26
  34. package/src/nile-rich-text-editor/nile-rte-link.test.ts +682 -0
  35. package/src/nile-rich-text-editor/nile-rte-link.ts +195 -100
  36. package/src/nile-rich-text-editor/utils/inline-utils.ts +11 -4
  37. package/vscode-html-custom-data.json +16 -2
package/README.md CHANGED
@@ -79,6 +79,9 @@ To run a local development server that serves the basic demo located in `demo/in
79
79
 
80
80
  In this section, you can find the updates for each release of `nile-elements`. It's a good practice to maintain detailed release notes to help users and developers understand what changes have been made from one version to another and how these changes might affect their projects.
81
81
 
82
+ #### Version 1.6.0 (March 06, 2026)
83
+ - Nile Rich Text Editor: Added New Link Feature (UIF-1131)
84
+
82
85
  #### Version 1.5.9 (March 05, 2026)
83
86
  - Nile Dropdown: Preserve trigger disabled state (UIF-1129)
84
87
 
package/dist/index.js CHANGED
@@ -15484,58 +15484,73 @@ nile-badge::part(content) {
15484
15484
  </div>
15485
15485
  </div>
15486
15486
  </nile-popover>
15487
- `}};e([ce({type:String,attribute:!0,reflect:!0})],Cm.prototype,"mode",void 0),e([ce({type:String,attribute:!0,reflect:!0})],Cm.prototype,"label",void 0),e([ce({type:String,attribute:!0,reflect:!0})],Cm.prototype,"value",void 0),e([ce({type:Array,attribute:!0,reflect:!0})],Cm.prototype,"palette",void 0),e([De()],Cm.prototype,"recentColors",void 0),Cm=e([Ne("nile-rte-color")],Cm);let fm=class extends ae{createRenderRoot(){return this}shouldUpdate(){return!1}};fm=e([Ne("nile-rte-divider")],fm);let vm=class extends ae{createRenderRoot(){return this}shouldUpdate(){return!1}};vm=e([Ne("nile-rte-preview")],vm);let Um=class extends ae{constructor(){super(...arguments),this.displayFormat=!1,this.mentions={},this.mentionFormat={},this.itemsFormats={},this.mentionColors={},this.externalConfig={},this.itemsConfig={},this.mentionActiveIndex=-1,this.itemsColors={},this.editorEl=null,this.hostEl=null,this.dropdownEl=null,this.menuEl=null,this.lastRange=null,this.mentionOpen=!1,this.mentionTrigger=null,this.mentionQuery="",this.mentionSuggestions=[],this.mentionFiltered=[],this.mentionX=0,this.mentionY=0,this.triggerBtn=null,this.mo=null,this.onSelectionChange=()=>{if(!this.editorEl)return;const e=document.getSelection();if(!e||0===e.rangeCount)return;const t=e.getRangeAt(0);this.editorEl.contains(t.commonAncestorContainer)&&(this.lastRange=t.cloneRange())},this.saveSelection=()=>{const e=window.getSelection();e&&e.rangeCount&&(this.lastRange=e.getRangeAt(0).cloneRange())},this.onEditorInput=()=>{if(this.mentionOpen)return void this.handleMention();const e=window.getSelection();if(!e||!e.anchorNode)return;let t=e.anchorNode;if(t.nodeType!==Node.TEXT_NODE&&t.firstChild?.nodeType===Node.TEXT_NODE&&(t=t.firstChild),!t||t.nodeType!==Node.TEXT_NODE)return;const i=t.textContent||"",M=this.config;for(const t of Object.keys(M)){const M=i.lastIndexOf(t);if(-1!==M){const i=e.focusOffset;if(i>=M+t.length&&i<=M+t.length+1)return void this.openMention(t)}}},this.onEditorKeyUp=e=>{this.saveSelection();const t=e.key,i=this.config;if(t&&i[t])return this.mentionOpen&&this.mentionTrigger!==t&&this.closeMention(),void this.openMention(t);this.mentionOpen&&this.handleMention()},this.onEditorKeyDown=e=>{if(!this.mentionOpen)return;const t=e.key;if("ArrowDown"===t||"ArrowUp"===t){if(e.preventDefault(),!this.mentionFiltered.length)return;this.mentionActiveIndex="ArrowDown"===t?(this.mentionActiveIndex+1)%this.mentionFiltered.length:(this.mentionActiveIndex-1+this.mentionFiltered.length)%this.mentionFiltered.length,this.renderMentionList()}else"Enter"===t?this.mentionActiveIndex>=0&&this.mentionFiltered[this.mentionActiveIndex]&&(e.preventDefault(),this.selectMention(this.mentionFiltered[this.mentionActiveIndex])):"Escape"===t&&(e.preventDefault(),this.closeMention())},this.repositionMention=()=>{if(!this.mentionOpen||!this.hostEl||!this.triggerBtn)return;const e=this.getCaretClientRect();if(!e)return;const t=this.hostEl.getBoundingClientRect();this.mentionX=e.left-t.left,this.mentionY=e.bottom-t.top,this.triggerBtn.style.left=`${this.mentionX}px`,this.triggerBtn.style.top=`${this.mentionY}px`}}createRenderRoot(){return this}getTriggerFormat(e){const t=this.itemsFormats[e]||{},i=this.mentionFormat[e]||{};return{prefix:t.prefix??i.prefix??"",suffix:t.suffix??i.suffix??""}}formatLabel(e,t){const{prefix:i,suffix:M}=this.getTriggerFormat(e);return`${i??""}${t}${M??""}`}get config(){return{...this.externalConfig,...this.mentions,...this.itemsConfig}}attach(e,t){this.editorEl=e,this.hostEl=t,this.injectStyles(),this.ensureMentionDropdown(),this.rebuildConfigFromChildren(),this.mo=new MutationObserver((()=>this.rebuildConfigFromChildren())),this.mo.observe(this,{childList:!0,subtree:!0,attributes:!0}),this.editorEl.addEventListener("input",this.onEditorInput),this.editorEl.addEventListener("mouseup",this.saveSelection),this.editorEl.addEventListener("keyup",this.onEditorKeyUp),this.editorEl.addEventListener("keydown",this.onEditorKeyDown),this.editorEl.addEventListener("scroll",this.repositionMention),document.addEventListener("selectionchange",this.onSelectionChange,!0)}detach(){this.mo&&(this.mo.disconnect(),this.mo=null),this.editorEl&&(this.editorEl.removeEventListener("input",this.onEditorInput),this.editorEl.removeEventListener("mouseup",this.saveSelection),this.editorEl.removeEventListener("keyup",this.onEditorKeyUp),this.editorEl.removeEventListener("keydown",this.onEditorKeyDown),this.editorEl.removeEventListener("scroll",this.repositionMention)),document.removeEventListener("selectionchange",this.onSelectionChange,!0)}setExternalConfig(e){this.externalConfig=e||{}}disconnectedCallback(){this.detach(),super.disconnectedCallback()}rebuildConfigFromChildren(){const e={},t={},i={},M=Array.from(this.querySelectorAll("nile-rte-mentions-item"));for(const n of M){const M=n.mentionsCharacter??n.getAttribute("mentionscharacter")??"";if(!M||"string"!=typeof M)continue;let o=n.mentionsData??(()=>{const e=n.getAttribute("mentionsdata");if(!e)return null;try{const t=JSON.parse(e);return Array.isArray(t)?t.filter((e=>e&&"string"==typeof e.key&&"string"==typeof e.label)):[]}catch{return[]}})();const r=n.mentionsColor??n.getAttribute("mentionscolor")??"",s=n.mentionsPrefix??n.getAttribute("mentionsprefix")??"",a=n.mentionsSuffix??n.getAttribute("mentionssuffix")??"";Array.isArray(o)||(o=[]),e[M]=o,r&&(t[M]=String(r)),(s||a)&&(i[M]={prefix:s,suffix:a})}this.itemsConfig=e,this.itemsColors=t,this.itemsFormats=i}injectStyles(){if(this.querySelector("style[data-mentions-style]"))return;const e=document.createElement("style");e.setAttribute("data-mentions-style","true"),e.textContent="\n .mention-dropdown {\n position: absolute; z-index: 1000; list-style: none; margin: 0; padding: 4px;\n border: 1px solid #e5e7eb; border-radius: 6px; background: #fff;\n box-shadow: 0 4px 10px rgba(0,0,0,.08); max-height: 180px; overflow: auto; font-size: 14px;\n }\n .mention-dropdown li { padding: 6px 8px; cursor: pointer; border-radius: 4px; }\n .mention-dropdown li:hover { background: #f1f5f9; }\n .mention { background: #eef2ff; padding: 0 3px; border-radius: 3px; }\n nile-menu.mentions-menu::part(menu__items-wrapper){\n max-height: 260px;\n overflow-y: auto;\n }\n .mentions-menu nile-menu-item.active {\n background: #dbeafe; /* highlight */\n outline: none;\n}\n\n\n ",this.insertBefore(e,this.firstChild)}getTriggerColor(e){return this.itemsColors[e]??this.mentionColors[e]}ensureMentionDropdown(){if(this.dropdownEl||!this.hostEl)return;const e=document.createElement("nile-dropdown");e.style.zIndex="1000";const t=document.createElement("nile-button");t.setAttribute("slot","trigger"),t.style.position="absolute",t.style.width="1px",t.style.height="1px",t.style.border="0",t.style.padding="0",t.style.opacity="0",t.style.pointerEvents="none",e.appendChild(t),this.triggerBtn=t;const i=document.createElement("nile-menu");i.classList.add("mentions-menu"),e.appendChild(i),this.hostEl.appendChild(e),this.dropdownEl=e,this.menuEl=i}restoreSelection(){if(!this.lastRange)return;const e=document.getSelection();e&&(e.removeAllRanges(),e.addRange(this.lastRange))}getCaretClientRect(){const e=document.getSelection();if(!e||0===e.rangeCount)return null;const t=e.getRangeAt(0).cloneRange();t.collapse(!1);const i=t.getClientRects();if(i&&i.length>0)return i[0];const M=document.createElement("span");M.setAttribute("data-caret-marker","1"),M.textContent="​",t.insertNode(M);const n=M.getBoundingClientRect(),o=document.createRange();return o.setStartAfter(M),o.collapse(!0),e.removeAllRanges(),e.addRange(o),M.remove(),n||null}openMention(e){if(this.saveSelection(),!this.editorEl||!this.dropdownEl||!this.hostEl)return;const t=this.getCaretClientRect();if(!t)return;const i=this.hostEl.getBoundingClientRect();this.mentionX=t.left-i.left,this.mentionY=t.bottom-i.top,this.mentionTrigger=e,this.mentionSuggestions=this.config[e]||[],this.mentionQuery="",this.updateMentionFiltered(),this.mentionActiveIndex=this.mentionFiltered.length?0:-1,this.mentionOpen=!0,this.renderMentionList(),this.dispatchEvent(new CustomEvent("nile-mention-opened",{detail:{trigger:e,suggestions:this.mentionSuggestions},bubbles:!0,composed:!0}))}closeMention(){this.mentionOpen=!1,this.mentionTrigger=null,this.mentionQuery="",this.mentionFiltered=[],this.dropdownEl?.removeAttribute("open")}handleMention(){if(!this.mentionOpen||!this.mentionTrigger)return;const e=window.getSelection();if(!e||!e.anchorNode)return;let t=e.anchorNode;if(t.nodeType!==Node.TEXT_NODE){const i=t.childNodes?.[e.anchorOffset]||t.firstChild;i?.nodeType===Node.TEXT_NODE&&(t=i)}const i=t&&t.nodeType===Node.TEXT_NODE&&t.textContent||"",M=i.lastIndexOf(this.mentionTrigger);M>=0?(this.mentionQuery=i.substring(M+1),this.updateMentionFiltered(),this.renderMentionList()):this.closeMention()}updateMentionFiltered(){const e=this.mentionQuery.toLowerCase();this.mentionFiltered=(this.mentionSuggestions||[]).filter((t=>t.label.toLowerCase().startsWith(e)))}renderMentionList(){this.dropdownEl&&this.menuEl&&this.triggerBtn&&(this.triggerBtn.style.left=`${this.mentionX}px`,this.triggerBtn.style.top=`${this.mentionY}px`,this.menuEl.innerHTML="",this.mentionOpen&&this.mentionFiltered.length?(this.mentionFiltered.forEach(((e,t)=>{const i=document.createElement("nile-menu-item");i.textContent=e.label,i.setAttribute("role","option"),t===this.mentionActiveIndex?(i.classList.add("active"),i.setAttribute("aria-selected","true")):(i.classList.remove("active"),i.removeAttribute("aria-selected")),i.addEventListener("mouseenter",(()=>{this.mentionActiveIndex=t,this.renderMentionList()})),i.addEventListener("pointerdown",(t=>{t.preventDefault(),this.selectMention(e)})),this.menuEl?.appendChild(i)})),this.dropdownEl.setAttribute("open","")):this.dropdownEl.removeAttribute("open"))}selectMention(e){if(this.restoreSelection(),!this.lastRange||!this.mentionTrigger||!this.editorEl)return;const t=this.mentionTrigger;let i=this.lastRange.startContainer,M=this.lastRange.startOffset;if(i.nodeType!==Node.TEXT_NODE){const e=i.childNodes[M];if(e?.nodeType!==Node.TEXT_NODE)return;i=e,M=0}const n=i,o=(n.textContent||"").lastIndexOf(this.mentionTrigger,M);if(o<0)return;const r=o+1+this.mentionQuery.length,s=document.createRange();s.setStart(n,o),s.setEnd(n,r),s.deleteContents();const a=document.createElement("span");a.classList.add("mention");const l=this.getTriggerFormat(this.mentionTrigger);this.displayFormat?a.textContent=`${l.prefix??""}${e.label}${l.suffix??""}`:(a.textContent=`${this.mentionTrigger}${e.label}`,l.prefix&&a.setAttribute("data-mention-prefix",l.prefix),l.suffix&&a.setAttribute("data-mention-suffix",l.suffix)),a.setAttribute("data-mention-key",e.key),a.setAttribute("data-mention-label",e.label),a.setAttribute("data-mention-trigger",this.mentionTrigger);const N=this.getTriggerColor(this.mentionTrigger);N&&(a.style.backgroundColor=N),s.insertNode(a);const g=document.createTextNode(" ");a.after(g);const u=window.getSelection(),c=document.createRange();c.setStartAfter(g),c.collapse(!0),u?.removeAllRanges(),u?.addRange(c),this.lastRange=c.cloneRange(),this.closeMention(),this.dispatchEvent(new CustomEvent("nile-mention-selected",{detail:{trigger:t,key:e.key,label:e.label,prefix:l.prefix??"",suffix:l.suffix??""},bubbles:!0,composed:!0})),this.editorEl.dispatchEvent(new InputEvent("input",{bubbles:!0}))}};e([ce({type:Boolean,attribute:"displayformat",reflect:!0})],Um.prototype,"displayFormat",void 0),e([ce({attribute:"mentions",converter:{fromAttribute:e=>{try{const t=JSON.parse(e),i={};for(const e of Object.keys(t)){const M=t[e];Array.isArray(M)&&(i[e]=M.filter((e=>e&&"string"==typeof e.key&&"string"==typeof e.label)).map((e=>({key:e.key,label:e.label}))))}return i}catch{return{}}},toAttribute:e=>JSON.stringify(e)}})],Um.prototype,"mentions",void 0),e([ce({attribute:"mentionformat",converter:{fromAttribute:e=>{try{const t=JSON.parse(e);return t&&"object"==typeof t?t:{}}catch{return{}}},toAttribute:e=>JSON.stringify(e??{})}})],Um.prototype,"mentionFormat",void 0),e([De()],Um.prototype,"itemsFormats",void 0),e([ce({attribute:"mentioncolors",converter:{fromAttribute:e=>{try{const t=JSON.parse(e);return t&&"object"==typeof t?t:{}}catch{return{}}},toAttribute:e=>JSON.stringify(e??{})}})],Um.prototype,"mentionColors",void 0),e([De()],Um.prototype,"externalConfig",void 0),e([De()],Um.prototype,"itemsConfig",void 0),e([De()],Um.prototype,"mentionActiveIndex",void 0),e([De()],Um.prototype,"itemsColors",void 0),Um=e([Ne("nile-rte-mentions")],Um);let Ym=class extends ae{constructor(){super(...arguments),this.newTab=!1,this.placeholder="Type or paste link here",this.label="Link",this.linkValue="",this.hasActiveLink=!1,this.popoverStyle="",this.selectionRange=null,this.activeAnchor=null,this.ignoreBlur=!1,this.isApplying=!1,this.onScroll=()=>{this.closePopover()}}createRenderRoot(){return this}connectedCallback(){super.connectedCallback(),this.injectCss("\n nile-popover.rte-link-popover::part(popover) {\n min-width: 316px;\n background: white;\n border: 1px solid var(--nile-colors-neutral-400,var(--ng-componentcolors-utility-gray-400));\n border-radius: 4px;\n padding: 0;\n gap: 0;\n }\n\n .link-popup {\n display: flex;\n align-items: center;\n gap: 8px;\n padding: 6px 8px;\n }\n\n .link-input {\n flex: 1;\n padding: 6px 8px;\n font-size: 14px;\n width: 276px;\n height: 14px;\n padding: 12px;\n border: 1px solid var(--nile-colors-primary-600, var(--ng-colors-border-brand));\n border-radius: 4px;\n }\n nile-button.rte-link-button::part(base) {\n border: none;\n height: 32px; \n width: 32px;\n }\n nile-button.rte-edit-button::part(base) {\n border: none;\n height: 38px; \n width: 38px;\n }\n ")}injectCss(e){if(this.querySelector("style[data-rte-link-style]"))return;const t=document.createElement("style");t.setAttribute("data-rte-link-style","true"),t.textContent=e,this.insertBefore(t,this.firstChild)}normalizeUrl(e){return/^(https?:|mailto:|tel:)/i.test(e)?e:`https://${e}`}displayUrl(e){return e.replace(/^https?:\/\//i,"")}getSelectionRect(){if(!this.selectionRange)return null;let e=this.selectionRange.getBoundingClientRect();if(0===e.width&&0===e.height){const t=document.createElement("span");t.textContent="​";this.selectionRange.cloneRange().insertNode(t),e=t.getBoundingClientRect(),t.remove()}return e}positionPopover(){const e=this.getSelectionRect();e&&(this.popoverStyle=`\n position: fixed;\n top: ${e.bottom+8}px;\n left: ${e.left+e.width/2}px;\n transform: translateX(-50%);\n z-index: 1000;\n `)}openPopover(){requestAnimationFrame((()=>{const e=this.querySelector("nile-popover");e&&(e.isShow=!0),window.addEventListener("scroll",this.onScroll,!0)}))}closePopover(){const e=this.querySelector("nile-popover");e&&(e.isShow=!1),window.removeEventListener("scroll",this.onScroll,!0),this.linkValue="",this.selectionRange=null,this.activeAnchor=null,this.hasActiveLink=!1,this.popoverStyle=""}unwrapLink(e){for(;e.firstChild;)e.parentNode?.insertBefore(e.firstChild,e);e.remove()}onOpen(){const e=document.getSelection();if(!e||0===e.rangeCount)return;this.selectionRange=e.getRangeAt(0).cloneRange(),this.activeAnchor=null,this.hasActiveLink=!1;let t=this.selectionRange.startContainer;for(;t&&t!==this.editorEl;){if(t instanceof HTMLAnchorElement){this.activeAnchor=t,this.hasActiveLink=!0;break}t=t.parentNode}this.linkValue=this.activeAnchor?this.displayUrl(this.activeAnchor.href):"",this.positionPopover(),this.openPopover(),requestAnimationFrame((()=>{this.querySelector(".link-input")?.focus()}))}onInputKeydown(e){if("Escape"===e.key||"Enter"===e.key)if(e.preventDefault(),e.stopPropagation(),"Escape"!==e.key){this.isApplying=!0;try{this.applyLink()}finally{this.isApplying=!1}}else this.closePopover()}onInputBlur(){this.ignoreBlur||this.isApplying||this.closePopover()}applyLink(){if(!(this.selectionRange instanceof Range))return;let e,t=this.linkValue.trim();if(!t)return;try{if(e=new URL(t,window.location.href),!["http:","https:","mailto:","tel:"].includes(e.protocol))return}catch{return}t=e.href,t=this.normalizeUrl(t),this.editorEl.focus();const i=document.getSelection();if(i){if(i.removeAllRanges(),i.addRange(this.selectionRange),this.activeAnchor)this.activeAnchor.href=t,this.newTab?(this.activeAnchor.target="_blank",this.activeAnchor.rel="noopener noreferrer"):(this.activeAnchor.removeAttribute("target"),this.activeAnchor.removeAttribute("rel"));else{const e=document.createElement("a");if(e.href=t,this.newTab?(e.target="_blank",e.rel="noopener noreferrer"):(e.removeAttribute("target"),e.removeAttribute("rel")),this.selectionRange.collapsed)e.textContent=t,this.selectionRange.insertNode(e);else try{this.selectionRange.surroundContents(e)}catch{const t=this.selectionRange.extractContents();e.appendChild(t),this.selectionRange.insertNode(e)}}this.emit(t),this.closePopover()}}onRemove(){this.activeAnchor&&(this.unwrapLink(this.activeAnchor),this.emit(""),this.closePopover())}emit(e){this.dispatchEvent(new CustomEvent("nile-link-changed",{detail:{href:e},bubbles:!0,composed:!0}))}render(){return R`
15488
- <nile-lite-tooltip content=${this.label}>
15489
- <nile-button
15490
- variant="tertiary"
15491
- size="small"
15492
- @mousedown=${e=>e.preventDefault()}
15493
- @click=${()=>this.onOpen()}
15494
- class="rte-link-button"
15495
- >
15496
- <nile-icon name="link_2"></nile-icon>
15497
- </nile-button>
15498
- </nile-lite-tooltip>
15487
+ `}};e([ce({type:String,attribute:!0,reflect:!0})],Cm.prototype,"mode",void 0),e([ce({type:String,attribute:!0,reflect:!0})],Cm.prototype,"label",void 0),e([ce({type:String,attribute:!0,reflect:!0})],Cm.prototype,"value",void 0),e([ce({type:Array,attribute:!0,reflect:!0})],Cm.prototype,"palette",void 0),e([De()],Cm.prototype,"recentColors",void 0),Cm=e([Ne("nile-rte-color")],Cm);let fm=class extends ae{createRenderRoot(){return this}shouldUpdate(){return!1}};fm=e([Ne("nile-rte-divider")],fm);let vm=class extends ae{createRenderRoot(){return this}shouldUpdate(){return!1}};vm=e([Ne("nile-rte-preview")],vm);let Um=class extends ae{constructor(){super(...arguments),this.displayFormat=!1,this.mentions={},this.mentionFormat={},this.itemsFormats={},this.mentionColors={},this.externalConfig={},this.itemsConfig={},this.mentionActiveIndex=-1,this.itemsColors={},this.editorEl=null,this.hostEl=null,this.dropdownEl=null,this.menuEl=null,this.lastRange=null,this.mentionOpen=!1,this.mentionTrigger=null,this.mentionQuery="",this.mentionSuggestions=[],this.mentionFiltered=[],this.mentionX=0,this.mentionY=0,this.triggerBtn=null,this.mo=null,this.onSelectionChange=()=>{if(!this.editorEl)return;const e=document.getSelection();if(!e||0===e.rangeCount)return;const t=e.getRangeAt(0);this.editorEl.contains(t.commonAncestorContainer)&&(this.lastRange=t.cloneRange())},this.saveSelection=()=>{const e=window.getSelection();e&&e.rangeCount&&(this.lastRange=e.getRangeAt(0).cloneRange())},this.onEditorInput=()=>{if(this.mentionOpen)return void this.handleMention();const e=window.getSelection();if(!e||!e.anchorNode)return;let t=e.anchorNode;if(t.nodeType!==Node.TEXT_NODE&&t.firstChild?.nodeType===Node.TEXT_NODE&&(t=t.firstChild),!t||t.nodeType!==Node.TEXT_NODE)return;const i=t.textContent||"",M=this.config;for(const t of Object.keys(M)){const M=i.lastIndexOf(t);if(-1!==M){const i=e.focusOffset;if(i>=M+t.length&&i<=M+t.length+1)return void this.openMention(t)}}},this.onEditorKeyUp=e=>{this.saveSelection();const t=e.key,i=this.config;if(t&&i[t])return this.mentionOpen&&this.mentionTrigger!==t&&this.closeMention(),void this.openMention(t);this.mentionOpen&&this.handleMention()},this.onEditorKeyDown=e=>{if(!this.mentionOpen)return;const t=e.key;if("ArrowDown"===t||"ArrowUp"===t){if(e.preventDefault(),!this.mentionFiltered.length)return;this.mentionActiveIndex="ArrowDown"===t?(this.mentionActiveIndex+1)%this.mentionFiltered.length:(this.mentionActiveIndex-1+this.mentionFiltered.length)%this.mentionFiltered.length,this.renderMentionList()}else"Enter"===t?this.mentionActiveIndex>=0&&this.mentionFiltered[this.mentionActiveIndex]&&(e.preventDefault(),this.selectMention(this.mentionFiltered[this.mentionActiveIndex])):"Escape"===t&&(e.preventDefault(),this.closeMention())},this.repositionMention=()=>{if(!this.mentionOpen||!this.hostEl||!this.triggerBtn)return;const e=this.getCaretClientRect();if(!e)return;const t=this.hostEl.getBoundingClientRect();this.mentionX=e.left-t.left,this.mentionY=e.bottom-t.top,this.triggerBtn.style.left=`${this.mentionX}px`,this.triggerBtn.style.top=`${this.mentionY}px`}}createRenderRoot(){return this}getTriggerFormat(e){const t=this.itemsFormats[e]||{},i=this.mentionFormat[e]||{};return{prefix:t.prefix??i.prefix??"",suffix:t.suffix??i.suffix??""}}formatLabel(e,t){const{prefix:i,suffix:M}=this.getTriggerFormat(e);return`${i??""}${t}${M??""}`}get config(){return{...this.externalConfig,...this.mentions,...this.itemsConfig}}attach(e,t){this.editorEl=e,this.hostEl=t,this.injectStyles(),this.ensureMentionDropdown(),this.rebuildConfigFromChildren(),this.mo=new MutationObserver((()=>this.rebuildConfigFromChildren())),this.mo.observe(this,{childList:!0,subtree:!0,attributes:!0}),this.editorEl.addEventListener("input",this.onEditorInput),this.editorEl.addEventListener("mouseup",this.saveSelection),this.editorEl.addEventListener("keyup",this.onEditorKeyUp),this.editorEl.addEventListener("keydown",this.onEditorKeyDown),this.editorEl.addEventListener("scroll",this.repositionMention),document.addEventListener("selectionchange",this.onSelectionChange,!0)}detach(){this.mo&&(this.mo.disconnect(),this.mo=null),this.editorEl&&(this.editorEl.removeEventListener("input",this.onEditorInput),this.editorEl.removeEventListener("mouseup",this.saveSelection),this.editorEl.removeEventListener("keyup",this.onEditorKeyUp),this.editorEl.removeEventListener("keydown",this.onEditorKeyDown),this.editorEl.removeEventListener("scroll",this.repositionMention)),document.removeEventListener("selectionchange",this.onSelectionChange,!0)}setExternalConfig(e){this.externalConfig=e||{}}disconnectedCallback(){this.detach(),super.disconnectedCallback()}rebuildConfigFromChildren(){const e={},t={},i={},M=Array.from(this.querySelectorAll("nile-rte-mentions-item"));for(const n of M){const M=n.mentionsCharacter??n.getAttribute("mentionscharacter")??"";if(!M||"string"!=typeof M)continue;let o=n.mentionsData??(()=>{const e=n.getAttribute("mentionsdata");if(!e)return null;try{const t=JSON.parse(e);return Array.isArray(t)?t.filter((e=>e&&"string"==typeof e.key&&"string"==typeof e.label)):[]}catch{return[]}})();const r=n.mentionsColor??n.getAttribute("mentionscolor")??"",s=n.mentionsPrefix??n.getAttribute("mentionsprefix")??"",a=n.mentionsSuffix??n.getAttribute("mentionssuffix")??"";Array.isArray(o)||(o=[]),e[M]=o,r&&(t[M]=String(r)),(s||a)&&(i[M]={prefix:s,suffix:a})}this.itemsConfig=e,this.itemsColors=t,this.itemsFormats=i}injectStyles(){if(this.querySelector("style[data-mentions-style]"))return;const e=document.createElement("style");e.setAttribute("data-mentions-style","true"),e.textContent="\n .mention-dropdown {\n position: absolute; z-index: 1000; list-style: none; margin: 0; padding: 4px;\n border: 1px solid #e5e7eb; border-radius: 6px; background: #fff;\n box-shadow: 0 4px 10px rgba(0,0,0,.08); max-height: 180px; overflow: auto; font-size: 14px;\n }\n .mention-dropdown li { padding: 6px 8px; cursor: pointer; border-radius: 4px; }\n .mention-dropdown li:hover { background: #f1f5f9; }\n .mention { background: #eef2ff; padding: 0 3px; border-radius: 3px; }\n nile-menu.mentions-menu::part(menu__items-wrapper){\n max-height: 260px;\n overflow-y: auto;\n }\n .mentions-menu nile-menu-item.active {\n background: #dbeafe; /* highlight */\n outline: none;\n}\n\n\n ",this.insertBefore(e,this.firstChild)}getTriggerColor(e){return this.itemsColors[e]??this.mentionColors[e]}ensureMentionDropdown(){if(this.dropdownEl||!this.hostEl)return;const e=document.createElement("nile-dropdown");e.style.zIndex="1000";const t=document.createElement("nile-button");t.setAttribute("slot","trigger"),t.style.position="absolute",t.style.width="1px",t.style.height="1px",t.style.border="0",t.style.padding="0",t.style.opacity="0",t.style.pointerEvents="none",e.appendChild(t),this.triggerBtn=t;const i=document.createElement("nile-menu");i.classList.add("mentions-menu"),e.appendChild(i),this.hostEl.appendChild(e),this.dropdownEl=e,this.menuEl=i}restoreSelection(){if(!this.lastRange)return;const e=document.getSelection();e&&(e.removeAllRanges(),e.addRange(this.lastRange))}getCaretClientRect(){const e=document.getSelection();if(!e||0===e.rangeCount)return null;const t=e.getRangeAt(0).cloneRange();t.collapse(!1);const i=t.getClientRects();if(i&&i.length>0)return i[0];const M=document.createElement("span");M.setAttribute("data-caret-marker","1"),M.textContent="​",t.insertNode(M);const n=M.getBoundingClientRect(),o=document.createRange();return o.setStartAfter(M),o.collapse(!0),e.removeAllRanges(),e.addRange(o),M.remove(),n||null}openMention(e){if(this.saveSelection(),!this.editorEl||!this.dropdownEl||!this.hostEl)return;const t=this.getCaretClientRect();if(!t)return;const i=this.hostEl.getBoundingClientRect();this.mentionX=t.left-i.left,this.mentionY=t.bottom-i.top,this.mentionTrigger=e,this.mentionSuggestions=this.config[e]||[],this.mentionQuery="",this.updateMentionFiltered(),this.mentionActiveIndex=this.mentionFiltered.length?0:-1,this.mentionOpen=!0,this.renderMentionList(),this.dispatchEvent(new CustomEvent("nile-mention-opened",{detail:{trigger:e,suggestions:this.mentionSuggestions},bubbles:!0,composed:!0}))}closeMention(){this.mentionOpen=!1,this.mentionTrigger=null,this.mentionQuery="",this.mentionFiltered=[],this.dropdownEl?.removeAttribute("open")}handleMention(){if(!this.mentionOpen||!this.mentionTrigger)return;const e=window.getSelection();if(!e||!e.anchorNode)return;let t=e.anchorNode;if(t.nodeType!==Node.TEXT_NODE){const i=t.childNodes?.[e.anchorOffset]||t.firstChild;i?.nodeType===Node.TEXT_NODE&&(t=i)}const i=t&&t.nodeType===Node.TEXT_NODE&&t.textContent||"",M=i.lastIndexOf(this.mentionTrigger);M>=0?(this.mentionQuery=i.substring(M+1),this.updateMentionFiltered(),this.renderMentionList()):this.closeMention()}updateMentionFiltered(){const e=this.mentionQuery.toLowerCase();this.mentionFiltered=(this.mentionSuggestions||[]).filter((t=>t.label.toLowerCase().startsWith(e)))}renderMentionList(){this.dropdownEl&&this.menuEl&&this.triggerBtn&&(this.triggerBtn.style.left=`${this.mentionX}px`,this.triggerBtn.style.top=`${this.mentionY}px`,this.menuEl.innerHTML="",this.mentionOpen&&this.mentionFiltered.length?(this.mentionFiltered.forEach(((e,t)=>{const i=document.createElement("nile-menu-item");i.textContent=e.label,i.setAttribute("role","option"),t===this.mentionActiveIndex?(i.classList.add("active"),i.setAttribute("aria-selected","true")):(i.classList.remove("active"),i.removeAttribute("aria-selected")),i.addEventListener("mouseenter",(()=>{this.mentionActiveIndex=t,this.renderMentionList()})),i.addEventListener("pointerdown",(t=>{t.preventDefault(),this.selectMention(e)})),this.menuEl?.appendChild(i)})),this.dropdownEl.setAttribute("open","")):this.dropdownEl.removeAttribute("open"))}selectMention(e){if(this.restoreSelection(),!this.lastRange||!this.mentionTrigger||!this.editorEl)return;const t=this.mentionTrigger;let i=this.lastRange.startContainer,M=this.lastRange.startOffset;if(i.nodeType!==Node.TEXT_NODE){const e=i.childNodes[M];if(e?.nodeType!==Node.TEXT_NODE)return;i=e,M=0}const n=i,o=(n.textContent||"").lastIndexOf(this.mentionTrigger,M);if(o<0)return;const r=o+1+this.mentionQuery.length,s=document.createRange();s.setStart(n,o),s.setEnd(n,r),s.deleteContents();const a=document.createElement("span");a.classList.add("mention");const l=this.getTriggerFormat(this.mentionTrigger);this.displayFormat?a.textContent=`${l.prefix??""}${e.label}${l.suffix??""}`:(a.textContent=`${this.mentionTrigger}${e.label}`,l.prefix&&a.setAttribute("data-mention-prefix",l.prefix),l.suffix&&a.setAttribute("data-mention-suffix",l.suffix)),a.setAttribute("data-mention-key",e.key),a.setAttribute("data-mention-label",e.label),a.setAttribute("data-mention-trigger",this.mentionTrigger);const N=this.getTriggerColor(this.mentionTrigger);N&&(a.style.backgroundColor=N),s.insertNode(a);const g=document.createTextNode(" ");a.after(g);const u=window.getSelection(),c=document.createRange();c.setStartAfter(g),c.collapse(!0),u?.removeAllRanges(),u?.addRange(c),this.lastRange=c.cloneRange(),this.closeMention(),this.dispatchEvent(new CustomEvent("nile-mention-selected",{detail:{trigger:t,key:e.key,label:e.label,prefix:l.prefix??"",suffix:l.suffix??""},bubbles:!0,composed:!0})),this.editorEl.dispatchEvent(new InputEvent("input",{bubbles:!0}))}};e([ce({type:Boolean,attribute:"displayformat",reflect:!0})],Um.prototype,"displayFormat",void 0),e([ce({attribute:"mentions",converter:{fromAttribute:e=>{try{const t=JSON.parse(e),i={};for(const e of Object.keys(t)){const M=t[e];Array.isArray(M)&&(i[e]=M.filter((e=>e&&"string"==typeof e.key&&"string"==typeof e.label)).map((e=>({key:e.key,label:e.label}))))}return i}catch{return{}}},toAttribute:e=>JSON.stringify(e)}})],Um.prototype,"mentions",void 0),e([ce({attribute:"mentionformat",converter:{fromAttribute:e=>{try{const t=JSON.parse(e);return t&&"object"==typeof t?t:{}}catch{return{}}},toAttribute:e=>JSON.stringify(e??{})}})],Um.prototype,"mentionFormat",void 0),e([De()],Um.prototype,"itemsFormats",void 0),e([ce({attribute:"mentioncolors",converter:{fromAttribute:e=>{try{const t=JSON.parse(e);return t&&"object"==typeof t?t:{}}catch{return{}}},toAttribute:e=>JSON.stringify(e??{})}})],Um.prototype,"mentionColors",void 0),e([De()],Um.prototype,"externalConfig",void 0),e([De()],Um.prototype,"itemsConfig",void 0),e([De()],Um.prototype,"mentionActiveIndex",void 0),e([De()],Um.prototype,"itemsColors",void 0),Um=e([Ne("nile-rte-mentions")],Um);let Ym=class extends ae{constructor(){super(...arguments),this.newTab=!1,this.disabled=!1,this.showTextSupport=!1,this.placeholder="Type or paste link here",this.textPlaceholder="Display text",this.label="Link",this.linkValue="",this.textValue="",this.hasActiveLink=!1,this.popoverStyle="",this.selectionRange=null,this.activeAnchor=null,this.ignoreBlur=!1,this.isApplying=!1,this.onScroll=()=>{this.closePopover()},this.onOpen=()=>{if(this.disabled)return;const e=document.getSelection();if(!e||0===e.rangeCount)return;if(!this.editorEl.contains(e.getRangeAt(0).commonAncestorContainer))return;this.selectionRange=e.getRangeAt(0).cloneRange(),this.activeAnchor=null,this.hasActiveLink=!1;let t=this.selectionRange.startContainer;for(;t&&t!==this.editorEl;){if(t instanceof HTMLAnchorElement){this.activeAnchor=t,this.hasActiveLink=!0;break}t=t.parentNode}this.linkValue=this.activeAnchor?this.displayUrl(this.activeAnchor.href):"",this.showTextSupport&&(this.activeAnchor?this.textValue=this.activeAnchor.textContent||"":this.selectionRange.collapsed?this.textValue="":this.textValue=this.selectionRange.toString()),this.positionPopover(),this.openPopover(),requestAnimationFrame((()=>{const e=this.querySelectorAll("nile-input"),t=e.length>1?e[1]:e[0];t?.focus()}))},this.onInputKeydown=e=>{if("Escape"===e.key||"Enter"===e.key)if(e.preventDefault(),e.stopPropagation(),"Escape"!==e.key){this.isApplying=!0;try{this.applyLink()}finally{this.isApplying=!1}}else this.closePopover()},this.onInputBlur=()=>{this.ignoreBlur||this.isApplying||requestAnimationFrame((()=>{if(this.ignoreBlur||this.isApplying)return;const e=this.querySelector("nile-popover");e?.matches(":focus-within")||this.closePopover()}))},this.onLinkInput=e=>{this.linkValue=e.detail.value},this.onTextInput=e=>{this.textValue=e.detail.value},this.onPopoverMousedown=()=>{this.ignoreBlur=!0},this.onPopoverMouseup=()=>{this.ignoreBlur=!1},this.onToolbarButtonMousedown=e=>{e.preventDefault()},this.onActionMousedown=e=>{e.preventDefault(),this.ignoreBlur=!0},this.onApplyClick=()=>{this.isApplying=!0,this.applyLink(),this.isApplying=!1,this.ignoreBlur=!1},this.onUnlinkClick=()=>{this.isApplying=!0,this.onRemove(),this.isApplying=!1,this.ignoreBlur=!1}}createRenderRoot(){return this}connectedCallback(){super.connectedCallback(),this.injectCss("\n nile-popover.rte-link-popover::part(popover) {\n min-width: 340px;\n max-width: 420px;\n background: white;\n border: 1px solid var(--nile-colors-neutral-400, var(--ng-componentcolors-utility-gray-400));\n border-radius: 8px;\n padding: 0;\n gap: 0;\n overflow: hidden;\n height: auto;\n box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);\n }\n\n .link-popup-wrap {\n display: flex;\n flex-direction: column;\n gap: 12px;\n padding: 12px;\n }\n\n .link-popup-wrap nile-input {\n width: 100%;\n }\n\n .link-popup-wrap .link-input-row {\n width: 100%;\n }\n\n .link-popup-wrap .link-actions-row {\n display: flex;\n align-items: flex-end;\n gap: 4px;\n width: 100%;\n }\n\n .link-popup-wrap .link-actions-row nile-input {\n flex: 1;\n min-width: 0;\n }\n\n \n nile-button.rte-link-button::part(base) {\n border: none;\n height: 32px;\n width: 32px;\n }\n nile-button.rte-edit-button::part(base) {\n border: none;\n height: 32px;\n width: 32px;\n flex-shrink: 0;\n }\n ")}injectCss(e){if(this.querySelector("style[data-rte-link-style]"))return;const t=document.createElement("style");t.setAttribute("data-rte-link-style","true"),t.textContent=e,this.insertBefore(t,this.firstChild)}normalizeUrl(e){return/^(https?:|mailto:|tel:)/i.test(e)?e:`https://${e}`}displayUrl(e){return e}getSelectionRect(){if(!this.selectionRange)return null;let e=this.selectionRange.getBoundingClientRect();if(0===e.width&&0===e.height){const t=document.createElement("span");t.textContent="​";this.selectionRange.cloneRange().insertNode(t),e=t.getBoundingClientRect(),t.remove()}return e}positionPopover(){const e=this.getSelectionRect();e&&(this.popoverStyle=`\n position: fixed;\n top: ${e.bottom+8}px;\n left: ${e.left+e.width/2}px;\n transform: translateX(-50%);\n z-index: 1000;\n `)}openPopover(){requestAnimationFrame((()=>{const e=this.querySelector("nile-popover");e&&(e.isShow=!0),window.addEventListener("scroll",this.onScroll,!0)}))}closePopover(){const e=this.querySelector("nile-popover");e&&(e.isShow=!1),window.removeEventListener("scroll",this.onScroll,!0),this.linkValue="",this.textValue="",this.selectionRange=null,this.activeAnchor=null,this.hasActiveLink=!1,this.popoverStyle=""}unwrapLink(e){for(;e.firstChild;)e.parentNode?.insertBefore(e.firstChild,e);e.remove()}applyLink(){if(!(this.selectionRange instanceof Range))return;let e=this.linkValue.trim();if(!e)return;if(/^javascript:/i.test(e))return;/^(https?:\/\/|mailto:|tel:|\/)/i.test(e)||(e=`https://${e}`),this.editorEl.focus();const t=document.getSelection();if(!t)return;t.removeAllRanges(),t.addRange(this.selectionRange);const i=this.showTextSupport&&this.textValue.trim()?this.textValue.trim():"";if(this.activeAnchor)this.activeAnchor.href=e,i&&(this.activeAnchor.textContent=i),this.newTab?(this.activeAnchor.target="_blank",this.activeAnchor.rel="noopener noreferrer"):(this.activeAnchor.removeAttribute("target"),this.activeAnchor.removeAttribute("rel"));else{const t=document.createElement("a");if(t.href=e,this.newTab?(t.target="_blank",t.rel="noopener noreferrer"):(t.removeAttribute("target"),t.removeAttribute("rel")),i)this.selectionRange.deleteContents(),t.textContent=i,this.selectionRange.insertNode(t);else if(this.selectionRange.collapsed)t.textContent=e,this.selectionRange.insertNode(t);else try{this.selectionRange.surroundContents(t)}catch{const e=this.selectionRange.extractContents();t.appendChild(e),this.selectionRange.insertNode(t)}}this.emit(e),this.closePopover()}onRemove(){this.activeAnchor&&(this.unwrapLink(this.activeAnchor),this.emit(""),this.closePopover())}emit(e){this.dispatchEvent(new CustomEvent("nile-link-changed",{detail:{href:e},bubbles:!0,composed:!0}))}render(){const e=this.disabled?"var(--nile-colors-neutral-500, var(--ng-colors-fg-disabled-subtle))":"var(--nile-colors-dark-900, var(--ng-colors-text-primary-900))";return R`
15488
+ <nile-lite-tooltip content=${this.label}>
15489
+ <nile-button
15490
+ variant="tertiary"
15491
+ size="small"
15492
+ ?disabled=${this.disabled}
15493
+ @mousedown=${this.onToolbarButtonMousedown}
15494
+ @click=${this.onOpen}
15495
+ class="rte-link-button"
15496
+ >
15497
+ <nile-icon name="link_2" color=${e}></nile-icon>
15498
+ </nile-button>
15499
+ </nile-lite-tooltip>
15499
15500
 
15500
15501
  <nile-popover
15501
15502
  class="rte-link-popover"
15502
15503
  .arrow=${!1}
15503
15504
  style=${this.popoverStyle}
15504
- @mousedown=${()=>this.ignoreBlur=!0}
15505
- @mouseup=${()=>this.ignoreBlur=!1}
15505
+ @mousedown=${this.onPopoverMousedown}
15506
+ @mouseup=${this.onPopoverMouseup}
15506
15507
  >
15507
- <div class="link-popup">
15508
- <input
15509
- class="link-input"
15510
- placeholder=${this.placeholder}
15511
- .value=${this.linkValue}
15512
- @input=${e=>this.linkValue=e.target.value}
15513
- @keydown=${this.onInputKeydown}
15514
- @blur=${this.onInputBlur}
15515
- />
15516
-
15517
- ${this.hasActiveLink?R`
15518
- <nile-button
15519
- size="small"
15520
- variant="tertiary"
15521
- class="rte-edit-button"
15522
- @click=${()=>this.applyLink()}
15523
- >
15524
- <nile-icon name="pencil"></nile-icon>
15525
- </nile-button>
15526
-
15527
- <nile-button
15528
- size="small"
15529
- variant="tertiary"
15530
- class="rte-edit-button"
15531
- @click=${()=>this.onRemove()}
15532
- >
15533
- <nile-icon name="unlink"></nile-icon>
15534
- </nile-button>
15535
- `:null}
15508
+ <div class="link-popup-wrap">
15509
+ ${this.showTextSupport?R`
15510
+ <div class="link-input-row">
15511
+ <nile-input
15512
+ label="Text"
15513
+ placeholder=${this.textPlaceholder}
15514
+ .value=${this.textValue}
15515
+ @nile-input=${this.onTextInput}
15516
+ @keydown=${this.onInputKeydown}
15517
+ @nile-blur=${this.onInputBlur}
15518
+ ></nile-input>
15519
+ </div>
15520
+ `:null}
15521
+ <div class="link-actions-row">
15522
+ <nile-input
15523
+ label=${this.showTextSupport?"URL":""}
15524
+ placeholder=${this.placeholder}
15525
+ .value=${this.linkValue}
15526
+ @nile-input=${this.onLinkInput}
15527
+ @keydown=${this.onInputKeydown}
15528
+ @nile-blur=${this.onInputBlur}
15529
+ ></nile-input>
15530
+ ${this.hasActiveLink?R`
15531
+ <nile-button
15532
+ size="small"
15533
+ variant="tertiary"
15534
+ class="rte-edit-button"
15535
+ @mousedown=${this.onActionMousedown}
15536
+ @click=${this.onApplyClick}
15537
+ >
15538
+ <nile-icon name="pencil"></nile-icon>
15539
+ </nile-button>
15540
+ <nile-button
15541
+ size="small"
15542
+ variant="tertiary"
15543
+ class="rte-edit-button"
15544
+ @mousedown=${this.onActionMousedown}
15545
+ @click=${this.onUnlinkClick}
15546
+ >
15547
+ <nile-icon name="unlink"></nile-icon>
15548
+ </nile-button>
15549
+ `:null}
15550
+ </div>
15536
15551
  </div>
15537
15552
  </nile-popover>
15538
- `}};function Zm(e,t){for(;e&&e!==t;){if(e instanceof HTMLElement){const t=getComputedStyle(e).display;if(e.tagName.match(/^(P|DIV|H1|H2|H3|H4|H5|H6|LI)$/)||"block"===t||"list-item"===t)return e}e=e?.parentNode||null}return t}function Vm(e,t){const i=window.getSelection();if(!i||0===i.rangeCount)return;const M=i.getRangeAt(0),n=M.commonAncestorContainer,o=[],r=document.createTreeWalker(n,NodeFilter.SHOW_ELEMENT,{acceptNode:e=>{const t=e;return M.intersectsNode(t)&&/^(P|DIV|LI|H[1-6])$/.test(t.tagName)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});let s=r.nextNode();for(;s;)o.push(s),s=r.nextNode();if(0===o.length){const t=Zm(i.focusNode,e);t&&o.push(t)}o.forEach((e=>{e.style.textAlign=t}))}function Wm(e,t,i){const M=window.getSelection();if(!M||0===M.rangeCount)return;const n=M.getRangeAt(0),o={strong:["strong","b"],em:["em","i"],u:["u"],span:["span"]}[t]??[t],r=e=>o.includes(e.tagName.toLowerCase());function s(e){const t=e.parentNode;if(t){for(;e.firstChild;)t.insertBefore(e.firstChild,e);t.removeChild(e)}}function a(e){e.querySelectorAll(o.join(",")).forEach((e=>{if(!e.textContent?.trim())return void e.remove();Array.from(e.querySelectorAll(o.join(","))).forEach((t=>{if(t!==e){for(;t.firstChild;)e.insertBefore(t.firstChild,t);t.remove()}}))}))}function l(e){Array.from(e.querySelectorAll(o.join(","))).forEach((e=>{const t=e.nextSibling;if(t instanceof HTMLElement&&r(t)){for(;t.firstChild;)e.appendChild(t.firstChild);t.remove()}}))}if(n.collapsed){let o=!1,N=n.startContainer;for(;N&&N!==e;){if(N instanceof HTMLElement&&r(N)){o=!0;break}N=N.parentNode}if(o&&N instanceof HTMLElement)s(N);else{const e=document.createElement(t);i&&Object.entries(i).forEach((([t,i])=>e.setAttribute(t,i))),e.appendChild(document.createTextNode("​")),n.insertNode(e),n.setStart(e.firstChild,1),n.collapse(!0),M.removeAllRanges(),M.addRange(n)}return a(e),void l(e)}n.startContainer.nodeType===Node.TEXT_NODE&&n.startContainer.splitText(n.startOffset),n.endContainer.nodeType===Node.TEXT_NODE&&n.endContainer.splitText(n.endOffset);const N=document.createTreeWalker(n.commonAncestorContainer,NodeFilter.SHOW_TEXT,{acceptNode:e=>{if(!e.nodeValue?.trim())return NodeFilter.FILTER_REJECT;const t=document.createRange();t.selectNodeContents(e);return n.compareBoundaryPoints(Range.END_TO_START,t)<0&&n.compareBoundaryPoints(Range.START_TO_END,t)>0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_REJECT}}),g=[];let u;for(;u=N.nextNode();)g.push(u);const c=g.length>0&&g.every((t=>{let i=t;for(;i&&i!==e;){if(i instanceof HTMLElement&&r(i))return!0;i=i.parentNode}return!1}));if(c){const i=g[0],M=g[g.length-1],n=i.parentElement?.closest(t);if(n&&n.contains(M)){const e=n.parentNode;if(e){const o=document.createRange();o.setStartBefore(n),o.setEndBefore(i);const r=o.cloneContents(),s=document.createRange();s.setStartAfter(M),s.setEndAfter(n);const a=s.cloneContents(),l=document.createRange();l.setStartBefore(i),l.setEndAfter(M);const N=l.extractContents(),g=document.createDocumentFragment();if(r.childNodes.length){const e=document.createElement(t);for(;r.firstChild;)e.appendChild(r.firstChild);g.appendChild(e)}for(;N.firstChild;)g.appendChild(N.firstChild);if(a.childNodes.length){const e=document.createElement(t);for(;a.firstChild;)e.appendChild(a.firstChild);g.appendChild(e)}e.insertBefore(g,n),e.removeChild(n)}}else g.forEach((t=>{let i=t;for(;i&&i!==e;){if(i instanceof HTMLElement&&r(i)){s(i);break}i=i.parentNode}}))}else g.forEach((e=>{const M=e.parentElement?.closest("a, .mention, nile-mention");if(M)return;const n=document.createElement(t);i&&Object.entries(i).forEach((([e,t])=>n.setAttribute(e,t))),e.parentNode?.insertBefore(n,e),n.appendChild(e)}));a(e),l(e),M.removeAllRanges(),M.addRange(n)}function Pm(e){const t=e.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/i);if(!t)return"#000000";return`#${Number(t[1]).toString(16).padStart(2,"0")}${Number(t[2]).toString(16).padStart(2,"0")}${Number(t[3]).toString(16).padStart(2,"0")}`}function Rm(e,t){const i=document.getSelection();if(!i||0===i.rangeCount)return;const M=i.getRangeAt(0);if(M.collapsed){const e=document.createElement("span");e.style.fontFamily=t,e.appendChild(document.createTextNode("​")),M.insertNode(e);const n=document.createRange();return n.setStart(e.firstChild,1),n.collapse(!0),i.removeAllRanges(),void i.addRange(n)}!function(e,t,i){const M=document.createElement(t);i&&Object.entries(i).forEach((([e,t])=>M.setAttribute(e,t)));try{e.surroundContents(M)}catch{const t=e.extractContents();M.appendChild(t),e.insertNode(M)}}(M,"span",{style:`font-family:${t}`})}function Bm(e,t,i){for(;t&&t!==e;){if(t instanceof HTMLSpanElement&&t.hasAttribute(i))return t;t=t.parentNode}return null}function Gm(e,t,i,M){const n=window.getSelection();if(!n||0===n.rangeCount)return;const o=n.getRangeAt(0);if(!e.contains(o.commonAncestorContainer))return;const r=o.cloneRange();if(r.collapsed){const o=Bm(e,r.startContainer,M);if(o)return o.style[t]=i,void _m(e,M,t);const s=document.createElement("span");s.setAttribute(M,"1"),s.style[t]=i,s.appendChild(document.createTextNode("​")),r.insertNode(s);const a=document.createRange();return a.setStart(s.firstChild,1),a.collapse(!0),n.removeAllRanges(),n.addRange(a),void _m(e,M,t)}const s=Bm(e,r.startContainer,M),a=Bm(e,r.endContainer,M);if(s&&s===a){if(function(e,t){const i=document.createRange();return i.selectNodeContents(t),e.compareBoundaryPoints(Range.START_TO_START,i)<=0&&e.compareBoundaryPoints(Range.END_TO_END,i)>=0}(r,s))s.style[t]=i;else{const e=function(e,t,i,M,n){const o=e.style[M],r=document.createRange();r.setStart(e,0),r.setEnd(t.startContainer,t.startOffset);const s=document.createRange();s.setStart(t.endContainer,t.endOffset),s.setEnd(e,e.childNodes.length);const a=document.createDocumentFragment(),l=e=>{const t=document.createElement("span");return t.setAttribute(i,"1"),t.style[M]=e,t};if(Fm(r)){const e=l(o);e.appendChild(r.cloneContents()),a.appendChild(e)}const N=l(n);if(N.appendChild(t.cloneContents()),a.appendChild(N),Fm(s)){const e=l(o);e.appendChild(s.cloneContents()),a.appendChild(e)}return e.replaceWith(a),N}(s,r,M,t,i),n=window.getSelection(),o=document.createRange();o.selectNodeContents(e),n?.removeAllRanges(),n?.addRange(o)}return void _m(e,M,t)}const l=(()=>{let e=r.commonAncestorContainer;for(;e&&!(e instanceof HTMLElement);)e=e.parentNode;return e})(),N=document.createTreeWalker(l||e,NodeFilter.SHOW_TEXT,{acceptNode:e=>{if(!e.nodeValue||!e.nodeValue.trim())return NodeFilter.FILTER_REJECT;const t=document.createRange();t.selectNodeContents(e);return r.compareBoundaryPoints(Range.END_TO_START,t)<0&&r.compareBoundaryPoints(Range.START_TO_END,t)>0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_REJECT}}),g=[];let u;for(;u=N.nextNode();)g.push(u);g.forEach((n=>{let o=0,s=n.length;n===r.startContainer&&(o=r.startOffset),n===r.endContainer&&(s=r.endOffset),o>0&&(n=n.splitText(o)),s<n.length&&n.splitText(s);const a=Bm(e,n,M);if(a)return void(a.style[t]=i);const l=document.createElement("span");l.setAttribute(M,"1"),l.style[t]=i;n.parentElement.replaceChild(l,n),l.appendChild(n)})),_m(e,M,t),n.removeAllRanges(),n.addRange(r)}function _m(e,t,i){const M=Array.from(e.querySelectorAll(`span[${t}]`)),n=e=>e.style[i];M.forEach((e=>{Array.from(e.querySelectorAll(`span[${t}]`)).forEach((t=>{if(n(t)===n(e)){for(;t.firstChild;)e.insertBefore(t.firstChild,t);t.remove()}}));const i=e.previousSibling;if(i instanceof HTMLSpanElement&&i.hasAttribute(t)&&n(i)===n(e)){for(;e.firstChild;)i.appendChild(e.firstChild);return void e.remove()}const M=e.nextSibling;if(M instanceof HTMLSpanElement&&M.hasAttribute(t)&&n(M)===n(e)){for(;M.firstChild;)e.appendChild(M.firstChild);M.remove()}}))}function Fm(e){if(e.collapsed)return!1;return(e.cloneContents().textContent||"").length>0}function Hm(e,t){const i=document.getSelection();if(!i||0===i.rangeCount)return;const M=i.getRangeAt(0);function n(e){e.style.paddingInlineStart="0",e.style.margin="0"}function o(e){const t=document.getSelection();if(!t)return;const i=document.createRange();i.selectNodeContents(e),i.collapse(!0),t.removeAllRanges(),t.addRange(i)}function r(t){for(;t&&t!==e;){if(t instanceof HTMLElement){const e=getComputedStyle(t).display;if(t.tagName.match(/^(P|DIV|H[1-6]|LI)$/)||"block"===e||"list-item"===e)return t}t=t.parentNode}return null}function s(e,t){const i=document.createElement(t);for(n(i);e.firstChild;)i.appendChild(e.firstChild);e.replaceWith(i)}if(M.collapsed){const i=r(M.startContainer),l=i?.closest("ul,ol");if(l&&l.tagName.toLowerCase()===t)return void function(e){const t=e.closest("li");if(!t)return;const i=t.parentElement,M=document.createElement("p");for(t.style.textAlign&&(M.style.textAlign=t.style.textAlign);t.firstChild;)M.appendChild(t.firstChild);i.parentNode?.insertBefore(M,i.nextSibling),t.remove(),0===i.childNodes.length&&i.remove(),o(M)}(i);if(l&&l.tagName.toLowerCase()!==t)return void s(l,t);if(!i||i===e||0===i.childNodes.length||(a=i,!a.textContent?.trim()&&!a.querySelector("img,br"))){const e=document.createElement(t),i=document.createElement("li");return i.appendChild(document.createElement("br")),e.appendChild(i),n(e),M.insertNode(e),void o(i)}const N=document.createElement(t);n(N);const g=document.createElement("li");for(i.style.textAlign&&(g.style.textAlign=i.style.textAlign);i.firstChild;)g.appendChild(i.firstChild);return N.appendChild(g),i.replaceWith(N),void o(g)}var a;const l=[],N=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:e=>{if(!(e instanceof HTMLElement))return NodeFilter.FILTER_SKIP;if(!/^(P|DIV|LI|H[1-6])$/.test(e.tagName))return NodeFilter.FILTER_SKIP;const t=document.createRange();t.selectNodeContents(e);return M.compareBoundaryPoints(Range.END_TO_START,t)<0&&M.compareBoundaryPoints(Range.START_TO_END,t)>0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_REJECT}});let g;for(;g=N.nextNode();)l.push(g);if(0===l.length){const e=r(M.startContainer);e&&l.push(e)}const u=l[0].closest("li");if(u){const e=u.closest("ul,ol");if(!e)return;return void(e.tagName.toLowerCase()===t?function(e){const t=document.createDocumentFragment();Array.from(e.querySelectorAll("li")).forEach((e=>{const i=document.createElement("p");for(e.style.textAlign&&(i.style.textAlign=e.style.textAlign);e.firstChild;)i.appendChild(e.firstChild);t.appendChild(i)})),e.replaceWith(t)}(e):s(e,t))}const c=document.createElement(t);n(c);for(const e of l){const t=document.createElement("li");for(e.style.textAlign&&(t.style.textAlign=e.style.textAlign);e.firstChild;)t.appendChild(e.firstChild);c.appendChild(t)}l[0].replaceWith(c);for(let e=1;e<l.length;e++)l[e].remove()}e([ce({attribute:!1})],Ym.prototype,"editorEl",void 0),e([ce({type:Boolean})],Ym.prototype,"newTab",void 0),e([ce({type:String})],Ym.prototype,"placeholder",void 0),e([ce({type:String})],Ym.prototype,"label",void 0),e([De()],Ym.prototype,"linkValue",void 0),e([De()],Ym.prototype,"hasActiveLink",void 0),e([De()],Ym.prototype,"popoverStyle",void 0),Ym=e([Ne("nile-rte-link")],Ym);const Jm=r`
15553
+ `}};function Zm(e,t){for(;e&&e!==t;){if(e instanceof HTMLElement){const t=getComputedStyle(e).display;if(e.tagName.match(/^(P|DIV|H1|H2|H3|H4|H5|H6|LI)$/)||"block"===t||"list-item"===t)return e}e=e?.parentNode||null}return t}function Vm(e,t){const i=window.getSelection();if(!i||0===i.rangeCount)return;const M=i.getRangeAt(0),n=M.commonAncestorContainer,o=[],r=document.createTreeWalker(n,NodeFilter.SHOW_ELEMENT,{acceptNode:e=>{const t=e;return M.intersectsNode(t)&&/^(P|DIV|LI|H[1-6])$/.test(t.tagName)?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});let s=r.nextNode();for(;s;)o.push(s),s=r.nextNode();if(0===o.length){const t=Zm(i.focusNode,e);t&&o.push(t)}o.forEach((e=>{e.style.textAlign=t}))}function Wm(e,t,i){const M=window.getSelection();if(!M||0===M.rangeCount)return;const n=M.getRangeAt(0),o={strong:["strong","b"],em:["em","i"],u:["u"],span:["span"]}[t]??[t],r=e=>o.includes(e.tagName.toLowerCase());function s(e){const t=e.parentNode;if(t){for(;e.firstChild;)t.insertBefore(e.firstChild,e);t.removeChild(e)}}function a(e){e.querySelectorAll(o.join(",")).forEach((e=>{if(!e.textContent?.trim())return void e.remove();Array.from(e.querySelectorAll(o.join(","))).forEach((t=>{if(t!==e){for(;t.firstChild;)e.insertBefore(t.firstChild,t);t.remove()}}))}))}function l(e){Array.from(e.querySelectorAll(o.join(","))).forEach((e=>{const t=e.nextSibling;if(t instanceof HTMLElement&&r(t)){for(;t.firstChild;)e.appendChild(t.firstChild);t.remove()}}))}if(n.collapsed){let o=!1,N=n.startContainer;for(;N&&N!==e;){if(N instanceof HTMLElement&&r(N)){o=!0;break}N=N.parentNode}if(o&&N instanceof HTMLElement)s(N);else{const e=document.createElement(t);i&&Object.entries(i).forEach((([t,i])=>e.setAttribute(t,i))),e.appendChild(document.createTextNode("​")),n.insertNode(e),n.setStart(e.firstChild,1),n.collapse(!0),M.removeAllRanges(),M.addRange(n)}return a(e),void l(e)}n.startContainer.nodeType===Node.TEXT_NODE&&n.startContainer.splitText(n.startOffset),n.endContainer.nodeType===Node.TEXT_NODE&&n.endContainer.splitText(n.endOffset);const N=document.createTreeWalker(n.commonAncestorContainer,NodeFilter.SHOW_TEXT,{acceptNode:e=>{if(!e.nodeValue?.trim())return NodeFilter.FILTER_REJECT;const t=document.createRange();t.selectNodeContents(e);return n.compareBoundaryPoints(Range.END_TO_START,t)<0&&n.compareBoundaryPoints(Range.START_TO_END,t)>0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_REJECT}}),g=[];let u;for(;u=N.nextNode();)g.push(u);const c=g.length>0&&g.every((t=>{let i=t;for(;i&&i!==e;){if(i instanceof HTMLElement&&r(i))return!0;i=i.parentNode}return!1}));if(c){const i=g[0],M=g[g.length-1],n=i.parentElement?.closest(t);if(n&&n.contains(M)){const e=n.parentNode;if(e){const o=document.createRange();o.setStartBefore(n),o.setEndBefore(i);const r=o.cloneContents(),s=document.createRange();s.setStartAfter(M),s.setEndAfter(n);const a=s.cloneContents(),l=document.createRange();l.setStartBefore(i),l.setEndAfter(M);const N=l.extractContents(),g=document.createDocumentFragment();if(r.childNodes.length){const e=document.createElement(t);for(;r.firstChild;)e.appendChild(r.firstChild);g.appendChild(e)}for(;N.firstChild;)g.appendChild(N.firstChild);if(a.childNodes.length){const e=document.createElement(t);for(;a.firstChild;)e.appendChild(a.firstChild);g.appendChild(e)}e.insertBefore(g,n),e.removeChild(n)}}else g.forEach((t=>{let i=t;for(;i&&i!==e;){if(i instanceof HTMLElement&&r(i)){s(i);break}i=i.parentNode}}))}else g.forEach((e=>{const M=e.parentElement?.closest(".mention, nile-mention");if(M)return;const n=e.parentElement?.closest("a");if(n&&"span"===t)return;const o=document.createElement(t);i&&Object.entries(i).forEach((([e,t])=>o.setAttribute(e,t))),n?(n.insertBefore(o,e),o.appendChild(e)):(e.parentNode?.insertBefore(o,e),o.appendChild(e))}));a(e),l(e),M.removeAllRanges(),M.addRange(n)}function Pm(e){const t=e.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/i);if(!t)return"#000000";return`#${Number(t[1]).toString(16).padStart(2,"0")}${Number(t[2]).toString(16).padStart(2,"0")}${Number(t[3]).toString(16).padStart(2,"0")}`}function Rm(e,t){const i=document.getSelection();if(!i||0===i.rangeCount)return;const M=i.getRangeAt(0);if(M.collapsed){const e=document.createElement("span");e.style.fontFamily=t,e.appendChild(document.createTextNode("​")),M.insertNode(e);const n=document.createRange();return n.setStart(e.firstChild,1),n.collapse(!0),i.removeAllRanges(),void i.addRange(n)}!function(e,t,i){const M=document.createElement(t);i&&Object.entries(i).forEach((([e,t])=>M.setAttribute(e,t)));try{e.surroundContents(M)}catch{const t=e.extractContents();M.appendChild(t),e.insertNode(M)}}(M,"span",{style:`font-family:${t}`})}function Bm(e,t,i){for(;t&&t!==e;){if(t instanceof HTMLSpanElement&&t.hasAttribute(i))return t;t=t.parentNode}return null}function Gm(e,t,i,M){const n=window.getSelection();if(!n||0===n.rangeCount)return;const o=n.getRangeAt(0);if(!e.contains(o.commonAncestorContainer))return;const r=o.cloneRange();if(r.collapsed){const o=Bm(e,r.startContainer,M);if(o)return o.style[t]=i,void _m(e,M,t);const s=document.createElement("span");s.setAttribute(M,"1"),s.style[t]=i,s.appendChild(document.createTextNode("​")),r.insertNode(s);const a=document.createRange();return a.setStart(s.firstChild,1),a.collapse(!0),n.removeAllRanges(),n.addRange(a),void _m(e,M,t)}const s=Bm(e,r.startContainer,M),a=Bm(e,r.endContainer,M);if(s&&s===a){if(function(e,t){const i=document.createRange();return i.selectNodeContents(t),e.compareBoundaryPoints(Range.START_TO_START,i)<=0&&e.compareBoundaryPoints(Range.END_TO_END,i)>=0}(r,s))s.style[t]=i;else{const e=function(e,t,i,M,n){const o=e.style[M],r=document.createRange();r.setStart(e,0),r.setEnd(t.startContainer,t.startOffset);const s=document.createRange();s.setStart(t.endContainer,t.endOffset),s.setEnd(e,e.childNodes.length);const a=document.createDocumentFragment(),l=e=>{const t=document.createElement("span");return t.setAttribute(i,"1"),t.style[M]=e,t};if(Fm(r)){const e=l(o);e.appendChild(r.cloneContents()),a.appendChild(e)}const N=l(n);if(N.appendChild(t.cloneContents()),a.appendChild(N),Fm(s)){const e=l(o);e.appendChild(s.cloneContents()),a.appendChild(e)}return e.replaceWith(a),N}(s,r,M,t,i),n=window.getSelection(),o=document.createRange();o.selectNodeContents(e),n?.removeAllRanges(),n?.addRange(o)}return void _m(e,M,t)}const l=(()=>{let e=r.commonAncestorContainer;for(;e&&!(e instanceof HTMLElement);)e=e.parentNode;return e})(),N=document.createTreeWalker(l||e,NodeFilter.SHOW_TEXT,{acceptNode:e=>{if(!e.nodeValue||!e.nodeValue.trim())return NodeFilter.FILTER_REJECT;const t=document.createRange();t.selectNodeContents(e);return r.compareBoundaryPoints(Range.END_TO_START,t)<0&&r.compareBoundaryPoints(Range.START_TO_END,t)>0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_REJECT}}),g=[];let u;for(;u=N.nextNode();)g.push(u);g.forEach((n=>{let o=0,s=n.length;n===r.startContainer&&(o=r.startOffset),n===r.endContainer&&(s=r.endOffset),o>0&&(n=n.splitText(o)),s<n.length&&n.splitText(s);const a=Bm(e,n,M);if(a)return void(a.style[t]=i);const l=document.createElement("span");l.setAttribute(M,"1"),l.style[t]=i;n.parentElement.replaceChild(l,n),l.appendChild(n)})),_m(e,M,t),n.removeAllRanges(),n.addRange(r)}function _m(e,t,i){const M=Array.from(e.querySelectorAll(`span[${t}]`)),n=e=>e.style[i];M.forEach((e=>{Array.from(e.querySelectorAll(`span[${t}]`)).forEach((t=>{if(n(t)===n(e)){for(;t.firstChild;)e.insertBefore(t.firstChild,t);t.remove()}}));const i=e.previousSibling;if(i instanceof HTMLSpanElement&&i.hasAttribute(t)&&n(i)===n(e)){for(;e.firstChild;)i.appendChild(e.firstChild);return void e.remove()}const M=e.nextSibling;if(M instanceof HTMLSpanElement&&M.hasAttribute(t)&&n(M)===n(e)){for(;M.firstChild;)e.appendChild(M.firstChild);M.remove()}}))}function Fm(e){if(e.collapsed)return!1;return(e.cloneContents().textContent||"").length>0}function Hm(e,t){const i=document.getSelection();if(!i||0===i.rangeCount)return;const M=i.getRangeAt(0);function n(e){e.style.paddingInlineStart="0",e.style.margin="0"}function o(e){const t=document.getSelection();if(!t)return;const i=document.createRange();i.selectNodeContents(e),i.collapse(!0),t.removeAllRanges(),t.addRange(i)}function r(t){for(;t&&t!==e;){if(t instanceof HTMLElement){const e=getComputedStyle(t).display;if(t.tagName.match(/^(P|DIV|H[1-6]|LI)$/)||"block"===e||"list-item"===e)return t}t=t.parentNode}return null}function s(e,t){const i=document.createElement(t);for(n(i);e.firstChild;)i.appendChild(e.firstChild);e.replaceWith(i)}if(M.collapsed){const i=r(M.startContainer),l=i?.closest("ul,ol");if(l&&l.tagName.toLowerCase()===t)return void function(e){const t=e.closest("li");if(!t)return;const i=t.parentElement,M=document.createElement("p");for(t.style.textAlign&&(M.style.textAlign=t.style.textAlign);t.firstChild;)M.appendChild(t.firstChild);i.parentNode?.insertBefore(M,i.nextSibling),t.remove(),0===i.childNodes.length&&i.remove(),o(M)}(i);if(l&&l.tagName.toLowerCase()!==t)return void s(l,t);if(!i||i===e||0===i.childNodes.length||(a=i,!a.textContent?.trim()&&!a.querySelector("img,br"))){const e=document.createElement(t),i=document.createElement("li");return i.appendChild(document.createElement("br")),e.appendChild(i),n(e),M.insertNode(e),void o(i)}const N=document.createElement(t);n(N);const g=document.createElement("li");for(i.style.textAlign&&(g.style.textAlign=i.style.textAlign);i.firstChild;)g.appendChild(i.firstChild);return N.appendChild(g),i.replaceWith(N),void o(g)}var a;const l=[],N=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:e=>{if(!(e instanceof HTMLElement))return NodeFilter.FILTER_SKIP;if(!/^(P|DIV|LI|H[1-6])$/.test(e.tagName))return NodeFilter.FILTER_SKIP;const t=document.createRange();t.selectNodeContents(e);return M.compareBoundaryPoints(Range.END_TO_START,t)<0&&M.compareBoundaryPoints(Range.START_TO_END,t)>0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_REJECT}});let g;for(;g=N.nextNode();)l.push(g);if(0===l.length){const e=r(M.startContainer);e&&l.push(e)}const u=l[0].closest("li");if(u){const e=u.closest("ul,ol");if(!e)return;return void(e.tagName.toLowerCase()===t?function(e){const t=document.createDocumentFragment();Array.from(e.querySelectorAll("li")).forEach((e=>{const i=document.createElement("p");for(e.style.textAlign&&(i.style.textAlign=e.style.textAlign);e.firstChild;)i.appendChild(e.firstChild);t.appendChild(i)})),e.replaceWith(t)}(e):s(e,t))}const c=document.createElement(t);n(c);for(const e of l){const t=document.createElement("li");for(e.style.textAlign&&(t.style.textAlign=e.style.textAlign);e.firstChild;)t.appendChild(e.firstChild);c.appendChild(t)}l[0].replaceWith(c);for(let e=1;e<l.length;e++)l[e].remove()}e([ce({attribute:!1})],Ym.prototype,"editorEl",void 0),e([ce({type:Boolean,reflect:!0,attribute:!0})],Ym.prototype,"newTab",void 0),e([ce({type:Boolean,reflect:!0,attribute:!0})],Ym.prototype,"disabled",void 0),e([ce({type:Boolean,reflect:!0,attribute:!0})],Ym.prototype,"showTextSupport",void 0),e([ce({type:String,reflect:!0,attribute:!0})],Ym.prototype,"placeholder",void 0),e([ce({type:String,reflect:!0,attribute:!0})],Ym.prototype,"textPlaceholder",void 0),e([ce({type:String,reflect:!0,attribute:!0})],Ym.prototype,"label",void 0),e([De()],Ym.prototype,"linkValue",void 0),e([De()],Ym.prototype,"textValue",void 0),e([De()],Ym.prototype,"hasActiveLink",void 0),e([De()],Ym.prototype,"popoverStyle",void 0),Ym=e([Ne("nile-rte-link")],Ym);const Jm=r`
15539
15554
  .editor { all: revert; }
15540
15555
 
15541
15556
  nile-rich-text-editor {
@@ -15706,6 +15721,30 @@ nile-rte-toolbar-item nile-button[data-active]::part(base):hover {
15706
15721
  background-color: var(--nile-colors-primary-500, var(--ng-componentcolors-utility-blue-500));
15707
15722
  }
15708
15723
 
15724
+ nile-rte-link nile-button[data-active]::part(base) {
15725
+ background-color: var(--nile-colors-primary-400, var(--ng-componentcolors-utility-blue-400));
15726
+ }
15727
+
15728
+ nile-rte-link nile-button[data-active]::part(base):hover {
15729
+ background-color: var(--nile-colors-primary-500, var(--ng-componentcolors-utility-blue-500));
15730
+ }
15731
+
15732
+ .editor a {
15733
+ color: var(--nile-colors-primary-600, var(--ng-colors-text-brand-tertiary-600));
15734
+ cursor: pointer;
15735
+ text-decoration: none;
15736
+ }
15737
+
15738
+ .editor a:hover {
15739
+ text-decoration: none;
15740
+ }
15741
+
15742
+ nile-rich-text-editor[disabled] .editor a {
15743
+ color: var(--nile-colors-dark-500, var(--ng-colors-text-disabled));
15744
+ cursor: not-allowed;
15745
+ pointer-events: none;
15746
+ }
15747
+
15709
15748
  .editor.empty::before {
15710
15749
  content: attr(data-placeholder);
15711
15750
  color: var(--nile-colors-neutral-500, var(--ng-colors-text-secondary));
@@ -15723,7 +15762,7 @@ nile-rte-toolbar-item nile-button[data-active]::part(base):hover {
15723
15762
 
15724
15763
 
15725
15764
 
15726
- `,$m={bold:"format_bold",italic:"format_italic",underline:"format_underline",link:"link_2",left:"format_align_left",center:"format_align_middle",right:"format_align_right",justify:"format_align_justify",ul:"format_list_bulleted",ol:"format_list_numbered",clear:"format_clear"},Xm=["font-weight","font-style","text-decoration","color","background-color","font-size","font-family","text-align","line-height","letter-spacing","white-space","vertical-align","list-style-position","padding-inline-start"];let qm=class extends ae{constructor(){super(...arguments),this.value="",this.noStyles=!1,this.disabled=!1,this.singleLineEditor=!1,this.placeholder="",this.mentions={},this.whitelist=[],this.content="",this.previewEl=null,this.toolbarEl=null,this.lastRange=null,this.buttonMap=new Map,this.headingSelect=null,this.fontSelect=null,this.colorInput=null,this.bgColorInput=null,this.colorSwatchEl=null,this.bgSwatchEl=null,this.containerEl=null,this.mentionsEl=null,this.onEditorKeydown=e=>{if(this.singleLineEditor&&"Enter"===e.key&&e.shiftKey)return void e.preventDefault();if(e.ctrlKey&&"i"===e.key.toLowerCase()&&(e.preventDefault(),Wm(this.editorEl,"em"),this.updateContent(),this.updateToolbarState()),this.singleLineEditor&&"Enter"===e.key)return void e.preventDefault();if("Tab"!==e.key)return;e.preventDefault(),this.focusAndRestore();const t=window.getSelection();if(!t||0===t.rangeCount)return;const i=t.getRangeAt(0);if(e.shiftKey){if(i.collapsed&&i.startContainer.nodeType===Node.TEXT_NODE){const e=i.startContainer,M=i.startOffset,n=e.data.slice(0,M),o=n.replace(/(\t|[ \u00a0]{2})$/,"");if(o.length!==n.length){e.data=o+e.data.slice(M);const i=document.createRange();i.setStart(e,o.length),i.collapse(!0),t.removeAllRanges(),t.addRange(i),this.updateContent(),this.updateToolbarState()}}return}i.deleteContents();const M=document.createTextNode("\t");i.insertNode(M);const n=document.createRange();n.setStartAfter(M),n.collapse(!0),t.removeAllRanges(),t.addRange(n),this.updateContent(),this.updateToolbarState()},this.onSelectionChange=()=>{if(!this.editorEl)return;const e=document.getSelection();if(!e||0===e.rangeCount)return;const t=e.getRangeAt(0);this.editorEl.contains(t.commonAncestorContainer)&&(this.lastRange=t.cloneRange(),this.updateToolbarState())}}createRenderRoot(){return this}injectCss(e){if(this.querySelector("style[data-rte-style]"))return;const t=document.createElement("style");t.setAttribute("data-rte-style","true"),t.textContent=e,this.insertBefore(t,this.firstChild)}connectedCallback(){super.connectedCallback(),this.injectCss(Jm.cssText),this.ensureStructure(),this.placeholder&&this.editorEl&&(this.editorEl.dataset.placeholder=this.placeholder),this.value&&!this.editorEl.innerHTML.trim()&&(this.editorEl.innerHTML=this.value),this.content=this.editorEl.innerHTML,this.toolbarEl&&this.wireAuthoredToolbar(this.toolbarEl),this.mentionsEl=this.querySelector("nile-rte-mentions"),this.mentionsEl&&(this.mentionsEl.attach?.(this.editorEl,this),this.mentionsEl.setExternalConfig?.(this.mentions)),this.wireEditor(),document.addEventListener("selectionchange",this.onSelectionChange,{passive:!0}),this.updateToolbarState(),this.syncPreview()}ensureStructure(){this.toolbarEl=this.querySelector("nile-rte-toolbar"),this.previewEl=this.querySelector("nile-rte-preview"),this.containerEl=this.querySelector(".rte-container"),this.containerEl||(this.containerEl=document.createElement("div"),this.containerEl.className="rte-container",this.appendChild(this.containerEl)),this.ensureEditor(),this.toolbarEl&&this.toolbarEl.parentElement!==this.containerEl&&this.containerEl.appendChild(this.toolbarEl),this.editorEl.parentElement!==this.containerEl&&this.containerEl.appendChild(this.editorEl),this.previewEl&&(this.previewEl.parentElement!==this&&this.appendChild(this.previewEl),this.previewEl.previousElementSibling!==this.containerEl&&this.insertBefore(this.previewEl,this.containerEl.nextSibling))}updateContentWithMention(e){this.updateContent(),this.dispatchEvent(new CustomEvent("nile-change",{detail:{content:this.content,mention:e},bubbles:!0,composed:!0}))}disconnectedCallback(){document.removeEventListener("selectionchange",this.onSelectionChange),this.mentionsEl&&this.mentionsEl.detach&&this.mentionsEl.detach(),super.disconnectedCallback()}updated(e){e.has("value")&&this.editorEl&&this.value!==this.editorEl.innerHTML&&(this.editorEl.innerHTML=this.value||"<p><br></p>",this.content=this.editorEl.innerHTML,this.syncPreview()),e.has("singleLineEditor")&&(this.editorEl&&this.editorEl.classList.toggle("single-line",this.singleLineEditor),this.previewEl&&this.previewEl.classList.toggle("single-line",this.singleLineEditor)),e.has("disabled")&&this.editorEl&&(this.editorEl.setAttribute("contenteditable",this.disabled?"false":"true"),this.editorEl.tabIndex=this.disabled?-1:0)}ensureEditor(){if(this.editorEl=this.querySelector(".editor"),!this.editorEl){const e=document.createElement("article");e.className="editor",e.setAttribute("contenteditable",this.disabled?"false":"true"),e.tabIndex=this.disabled?-1:0,this.editorEl=e}this.placeholder&&(this.editorEl.dataset.placeholder=this.placeholder),this.editorEl.innerHTML.trim()||(this.editorEl.innerHTML="<p><br></p>")}unwrapMention(e,t=!0){const i=e.parentNode;if(!i)return;const M=t?(e.textContent??"").replace(/\u200B/g,""):"",n=document.createTextNode(M);i.insertBefore(n,e),i.removeChild(e);const o=document.createRange();o.setStartAfter(n),o.collapse(!0);const r=window.getSelection();r?.removeAllRanges(),r?.addRange(o)}scrubBrokenMentions(){if(!this.editorEl)return;this.editorEl.querySelectorAll("span.mention").forEach((e=>{const t=e,i=t.getAttribute("data-mention-key"),M=t.getAttribute("data-mention-label"),n=t.getAttribute("data-mention-trigger")||"",o=(t.textContent??"").replace(/\u200B/g,"").trim(),r=!!i&&!!M&&o.length>0&&o.startsWith(n)&&o.includes(M);o&&r||this.unwrapMention(t,!0)}))}wireEditor(){this.editorEl.addEventListener("input",(()=>{this.ensureAtLeastOneParagraph(),this.scrubBrokenMentions(),this.updateContent(),this.updateToolbarState()})),this.editorEl.addEventListener("mouseup",(()=>{this.saveSelection(),this.updateToolbarState()})),this.editorEl.addEventListener("keyup",(e=>{this.saveSelection(),["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Home","End"].includes(e.key)&&this.updateToolbarState()})),this.editorEl.addEventListener("keydown",this.onEditorKeydown)}wireAuthoredToolbar(e){this.buttonMap.clear(),this.headingSelect=null,this.fontSelect=null,this.colorInput=null,Array.from(e.children).forEach((e=>{const t=e.tagName.toLowerCase();if("nile-rte-select"===t&&"align"===e.getAttribute("type"))return e.disabled=this.disabled,void e.addEventListener("change",(e=>{this.focusAndRestore();const t=e.detail;Vm(this.editorEl,t),this.updateContent(),this.updateToolbarState()}));if("nile-rte-link"===t)return e.editorEl=this.editorEl,void e.addEventListener("link-changed",(()=>{this.updateContent(),this.updateToolbarState()}));if("nile-rte-toolbar-item"===t){let t=e.querySelector(":scope > nile-button");const i=e.getAttribute("name")||"",M=e.getAttribute("label")||i,n=e.getAttribute("icon"),o=e.innerHTML.trim().length>0;if(t||(t=document.createElement("nile-button"),t.variant="tertiary",t.size="small"),t.disabled=this.disabled,n)t.innerHTML=`<nile-icon name="${n}" color="${this.disabled?"var(--nile-colors-neutral-500, var(--ng-colors-fg-disabled-subtle))":"var(--nile-colors-dark-900, var(--ng-colors-text-primary-900))"}" ></nile-icon>`,e.innerHTML="";else if(o)t.innerHTML=e.innerHTML,e.innerHTML="";else{const n=$m[i];n?t.innerHTML=`<nile-icon name="${n}" size="20" color="${this.disabled?"var(--nile-colors-neutral-500, var(--ng-colors-fg-disabled-subtle))":"var(--nile-colors-dark-900, var(--ng-colors-text-primary-900))"}" ></nile-icon>`:t.textContent=M||i,e.innerHTML=""}if(!t.isConnected)if(this.disabled)e.appendChild(t);else{const i=document.createElement("nile-lite-tooltip");i.setAttribute("content",M),i.appendChild(t),e.appendChild(i)}t.setAttribute("aria-label",M),t.addEventListener("mousedown",(e=>e.preventDefault())),t.addEventListener("click",(()=>this.onToolbarCommand(i)));const r=this.buttonMap.get(i)??[];return r.push(t),void this.buttonMap.set(i,r)}if("nile-rte-select"!==t)"nile-rte-color"!==t||e.addEventListener("change",(e=>{this.focusAndRestore();const{mode:t,value:i}=e.detail;"backColor"===t?Gm(this.editorEl,"backgroundColor",i,"data-rte-bg"):function(e,t){Gm(e,"color",t,"data-rte-color")}(this.editorEl,i),this.updateContent(),this.updateToolbarState()}));else{const t=e.getAttribute("type")||"";e.addEventListener("change",(e=>{this.focusAndRestore();const i=e.detail;"heading"===t?function(e,t){const i=document.getSelection();if(!i||0===i.rangeCount)return;const M=Zm(i.getRangeAt(0).startContainer,e);if(!M)return;if(M.tagName.toLowerCase()===t)return;const n=document.createElement(t);for(;M.firstChild;)n.appendChild(M.firstChild);M.replaceWith(n);const o=document.createRange();o.selectNodeContents(n),o.collapse(!0),i.removeAllRanges(),i.addRange(o)}(this.editorEl,i):"font"===t&&Rm(this.editorEl,i),this.updateContent(),this.updateToolbarState()}))}}))}saveSelection(){const e=window.getSelection();e&&e.rangeCount&&(this.lastRange=e.getRangeAt(0).cloneRange())}restoreSelection(){if(!this.lastRange)return;const e=document.getSelection();e&&(e.removeAllRanges(),e.addRange(this.lastRange))}focusAndRestore(){this.editorEl?.focus(),this.restoreSelection()}getCleanContent(){const e=this.editorEl.cloneNode(!0);return e.querySelectorAll("*").forEach((e=>{e.removeAttribute("style")})),e.innerHTML}insertList(e){if(this.restoreSelection(),!this.lastRange)return;const t=document.createElement(e),i=this.lastRange.extractContents(),M=document.createElement("div");M.appendChild(i),Array.from(M.childNodes).forEach((e=>{if(e.nodeType===Node.TEXT_NODE&&!e.textContent?.trim())return;const i=document.createElement("li");i.appendChild(e),t.appendChild(i)})),this.lastRange.insertNode(t),this.afterListEdit(t)}afterListEdit(e){const t=document.createRange();t.setStartAfter(e),t.collapse(!0);const i=window.getSelection();i?.removeAllRanges(),i?.addRange(t),this.saveSelection(),this.updateContent(),this.updateToolbarState()}ensureAtLeastOneParagraph(){const e=this.editorEl;if(!e)return;const t=""===(e.textContent??"").replace(/\u200B/g,"").trim();if(0===e.childNodes.length||t)return void(e.innerHTML="<p><br></p>");if(!e.querySelector("p,h1,h2,h3,h4,h5,h6,ul,ol,table,blockquote,pre")){const t=document.createElement("p");for(;e.firstChild;)t.appendChild(e.firstChild);return t.hasChildNodes()||t.appendChild(document.createElement("br")),void e.appendChild(t)}e.querySelectorAll("p").forEach((e=>{""===(e.textContent??"").replace(/\u200B/g,"")&&(e.innerHTML.toLowerCase().includes("<br")||(e.innerHTML="<br>"))}))}onToolbarCommand(e){switch(this.focusAndRestore(),e){case"bold":Wm(this.editorEl,"strong");break;case"italic":Wm(this.editorEl,"em");break;case"underline":Wm(this.editorEl,"u");break;case"left":Vm(this.editorEl,"left");break;case"center":Vm(this.editorEl,"center");break;case"right":Vm(this.editorEl,"right");break;case"justify":Vm(this.editorEl,"justify");break;case"ul":Hm(this.editorEl,"ul"),this.updateContent(),this.updateToolbarState();break;case"ol":Hm(this.editorEl,"ol"),this.updateContent(),this.updateToolbarState();break;case"link":break;case"clear":const e=document.createTreeWalker(this.editorEl,NodeFilter.SHOW_ELEMENT),t=[];for(;e.nextNode();){const i=e.currentNode;i.removeAttribute("style"),["B","STRONG","I","EM","U","SPAN","FONT"].includes(i.tagName)&&t.push(i)}for(const e of t){for(;e.firstChild;)e.parentNode?.insertBefore(e.firstChild,e);e.remove()}this.ensureAtLeastOneParagraph()}this.updateContent(),this.updateToolbarState()}setBtnActive(e,t){const i=this.buttonMap.get(e);if(i)for(const e of i)e.toggleAttribute("data-active",!!t)}updateToolbarState(){if(!this.editorEl)return;const e=document.getSelection();if(!e||0===e.rangeCount)return;const t=e.getRangeAt(0);if(!this.editorEl.contains(t.commonAncestorContainer))return;const i=function(e){for(;e&&!(e instanceof HTMLElement);)e=e.parentNode;return e}(t.startContainer)||this.editorEl,M=getComputedStyle(i),n=Zm(t.startContainer,this.editorEl)||this.editorEl,o=(()=>{let e=i;for(;e&&e!==this.editorEl;){if(e instanceof HTMLElement){const t=e.tagName.toLowerCase();if("strong"===t||"b"===t)return!0;const i=getComputedStyle(e).fontWeight;if(parseInt(i,10)>=600)return!0}e=e.parentNode}return!1})(),r=(()=>{let e=i;for(;e&&e!==this.editorEl;){if(e instanceof HTMLElement){const t=e.tagName.toLowerCase();if("em"===t||"i"===t)return!0;if("italic"===getComputedStyle(e).fontStyle)return!0}e=e.parentNode}return!1})(),s=(()=>{let e=i;for(;e&&e!==this.editorEl;){if(e instanceof HTMLElement){const t=getComputedStyle(e).textDecorationLine;if(t&&t.includes("underline"))return!0;if("u"===e.tagName.toLowerCase())return!0}e=e.parentNode}return!1})(),a=!!i.closest("a"),l=n.style.textAlign||getComputedStyle(n).textAlign||"start",N="start"===l?"left":l,g=!!i.closest("li")&&i.closest("ul,ol")?.tagName.toLowerCase()||"";if(this.setBtnActive("bold",o),this.setBtnActive("italic",r),this.setBtnActive("underline",s),this.setBtnActive("link",a),this.setBtnActive("left","left"===N&&!["center","right","justify"].includes(N)),this.setBtnActive("center","center"===N),this.setBtnActive("right","right"===N),this.setBtnActive("justify","justify"===N),this.setBtnActive("ul","ul"===g),this.setBtnActive("ol","ol"===g),this.headingSelect){const e=n.tagName.toLowerCase(),t=["h1","h2","h3"].includes(e)?e:"p";this.headingSelect.value!==t&&(this.headingSelect.value=t)}if(this.fontSelect){const e=(M.fontFamily||"").replace(/["']/g,"").split(",")[0].trim().toLowerCase();if(e)for(const t of Array.from(this.fontSelect.options))if(t.value.toLowerCase()===e){this.fontSelect.value=t.value;break}}if(this.colorInput){const e=Pm(M.color);e&&this.colorInput.value.toLowerCase()!==e.toLowerCase()&&(this.colorInput.value=e),this.colorSwatchEl&&(this.colorSwatchEl.style.backgroundColor=this.colorInput.value)}if(this.bgColorInput){const e=getComputedStyle(i).backgroundColor;if(e&&!/transparent|rgba\(\s*0\s*,\s*0\s*,\s*0\s*,\s*0\s*\)/i.test(e)){const t=Pm(e);t&&this.bgColorInput.value.toLowerCase()!==t.toLowerCase()&&(this.bgColorInput.value=t)}this.bgSwatchEl&&(this.bgSwatchEl.style.backgroundColor=this.bgColorInput.value)}}syncPreview(){this.updateContent()}getComputedImportantProps(){return Array.from(new Set([...Xm,...this.whitelist??[]]))}updateContent(){if(!this.editorEl)return;this.ensureAtLeastOneParagraph();const e=""===(this.editorEl.textContent??"").trim();this.editorEl.classList.toggle("empty",e);const t=this.editorEl.cloneNode(!0);if(this.noStyles)t.querySelectorAll("[style]").forEach((e=>e.removeAttribute("style")));else{const e=document.createTreeWalker(this.editorEl,NodeFilter.SHOW_ELEMENT),i=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT),M=this.getComputedImportantProps();for(;e.nextNode()&&i.nextNode();){const t=e.currentNode,n=i.currentNode,o=window.getComputedStyle(t),r=M.map((e=>`${e}:${o.getPropertyValue(e)}`)).join(";");r.trim()&&n.setAttribute("style",r)}}this.content=t.innerHTML,this.previewEl&&(this.previewEl.innerHTML=this.content),this.dispatchEvent(new CustomEvent("nile-change",{detail:{content:this.content},bubbles:!0,composed:!0}))}};e([ce({type:String,attribute:!0,reflect:!0})],qm.prototype,"value",void 0),e([ce({type:Boolean,attribute:!0,reflect:!0})],qm.prototype,"noStyles",void 0),e([ce({type:Boolean,attribute:!0,reflect:!0})],qm.prototype,"disabled",void 0),e([ce({type:Boolean,attribute:"singlelineeditor",reflect:!0})],qm.prototype,"singleLineEditor",void 0),e([ce({type:String})],qm.prototype,"placeholder",void 0),e([ce({attribute:"mentions",reflect:!0,converter:{fromAttribute:e=>{try{const t=JSON.parse(e),i={};for(const e of Object.keys(t)){const M=t[e];Array.isArray(M)&&(i[e]=M.filter((e=>e&&"string"==typeof e.key&&"string"==typeof e.label)).map((e=>({key:e.key,label:e.label}))))}return i}catch{return{}}},toAttribute:e=>JSON.stringify(e)}})],qm.prototype,"mentions",void 0),e([ce({attribute:"whitelist",reflect:!1,converter:{fromAttribute:e=>{try{const t=JSON.parse(e);return Array.isArray(t)?t.filter((e=>"string"==typeof e)):[]}catch{return[]}}}})],qm.prototype,"whitelist",void 0),e([De()],qm.prototype,"content",void 0),qm=e([Ne("nile-rich-text-editor")],qm);"undefined"!=typeof window&&(window.nileElementsVersion='"1.5.9"',window.nileVersion="__NILE_VERSION__",window.process=window.process||{env:{NODE_ENV:"production"}});const Km=r`
15765
+ `,$m={bold:"format_bold",italic:"format_italic",underline:"format_underline",link:"link_2",left:"format_align_left",center:"format_align_middle",right:"format_align_right",justify:"format_align_justify",ul:"format_list_bulleted",ol:"format_list_numbered",clear:"format_clear"},Xm=["font-weight","font-style","text-decoration","color","background-color","font-size","font-family","text-align","line-height","letter-spacing","white-space","vertical-align","list-style-position","padding-inline-start"];let qm=class extends ae{constructor(){super(...arguments),this.value="",this.noStyles=!1,this.disabled=!1,this.singleLineEditor=!1,this.placeholder="",this.mentions={},this.whitelist=[],this.content="",this.previewEl=null,this.toolbarEl=null,this.lastRange=null,this.buttonMap=new Map,this.headingSelect=null,this.fontSelect=null,this.colorInput=null,this.bgColorInput=null,this.colorSwatchEl=null,this.bgSwatchEl=null,this.containerEl=null,this.linkEl=null,this.mentionsEl=null,this.onEditorClick=e=>{const t=e.target.closest?.("a");t&&e.preventDefault()},this.onEditorInput=()=>{this.ensureAtLeastOneParagraph(),this.scrubBrokenMentions(),this.updateContent(),this.updateToolbarState()},this.onEditorMouseup=()=>{this.saveSelection(),this.updateToolbarState()},this.onEditorKeyup=e=>{this.saveSelection(),["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Home","End"].includes(e.key)&&this.updateToolbarState()},this.onEditorKeydown=e=>{if(this.singleLineEditor&&"Enter"===e.key&&e.shiftKey)return void e.preventDefault();if(e.ctrlKey&&"i"===e.key.toLowerCase()&&(e.preventDefault(),Wm(this.editorEl,"em"),this.updateContent(),this.updateToolbarState()),this.singleLineEditor&&"Enter"===e.key)return void e.preventDefault();if("Tab"!==e.key)return;e.preventDefault(),this.focusAndRestore();const t=window.getSelection();if(!t||0===t.rangeCount)return;const i=t.getRangeAt(0);if(e.shiftKey){if(i.collapsed&&i.startContainer.nodeType===Node.TEXT_NODE){const e=i.startContainer,M=i.startOffset,n=e.data.slice(0,M),o=n.replace(/(\t|[ \u00a0]{2})$/,"");if(o.length!==n.length){e.data=o+e.data.slice(M);const i=document.createRange();i.setStart(e,o.length),i.collapse(!0),t.removeAllRanges(),t.addRange(i),this.updateContent(),this.updateToolbarState()}}return}i.deleteContents();const M=document.createTextNode("\t");i.insertNode(M);const n=document.createRange();n.setStartAfter(M),n.collapse(!0),t.removeAllRanges(),t.addRange(n),this.updateContent(),this.updateToolbarState()},this.onSelectionChange=()=>{if(!this.editorEl)return;const e=document.getSelection();if(!e||0===e.rangeCount)return;const t=e.getRangeAt(0);this.editorEl.contains(t.commonAncestorContainer)&&(this.lastRange=t.cloneRange(),this.updateToolbarState())}}createRenderRoot(){return this}injectCss(e){if(this.querySelector("style[data-rte-style]"))return;const t=document.createElement("style");t.setAttribute("data-rte-style","true"),t.textContent=e,this.insertBefore(t,this.firstChild)}connectedCallback(){super.connectedCallback(),this.injectCss(Jm.cssText),this.ensureStructure(),this.placeholder&&this.editorEl&&(this.editorEl.dataset.placeholder=this.placeholder),this.value&&!this.editorEl.innerHTML.trim()&&(this.editorEl.innerHTML=this.value),this.content=this.editorEl.innerHTML,this.toolbarEl&&this.wireAuthoredToolbar(this.toolbarEl),this.mentionsEl=this.querySelector("nile-rte-mentions"),this.mentionsEl&&(this.mentionsEl.attach?.(this.editorEl,this),this.mentionsEl.setExternalConfig?.(this.mentions)),this.wireEditor(),document.addEventListener("selectionchange",this.onSelectionChange,{passive:!0}),this.updateToolbarState(),this.syncPreview()}ensureStructure(){this.toolbarEl=this.querySelector("nile-rte-toolbar"),this.previewEl=this.querySelector("nile-rte-preview"),this.containerEl=this.querySelector(".rte-container"),this.containerEl||(this.containerEl=document.createElement("div"),this.containerEl.className="rte-container",this.appendChild(this.containerEl)),this.ensureEditor(),this.toolbarEl&&this.toolbarEl.parentElement!==this.containerEl&&this.containerEl.appendChild(this.toolbarEl),this.editorEl.parentElement!==this.containerEl&&this.containerEl.appendChild(this.editorEl),this.previewEl&&(this.previewEl.parentElement!==this&&this.appendChild(this.previewEl),this.previewEl.previousElementSibling!==this.containerEl&&this.insertBefore(this.previewEl,this.containerEl.nextSibling))}updateContentWithMention(e){this.updateContent(),this.dispatchEvent(new CustomEvent("nile-change",{detail:{content:this.content,mention:e},bubbles:!0,composed:!0}))}disconnectedCallback(){this.unwireEditor(),document.removeEventListener("selectionchange",this.onSelectionChange),this.mentionsEl&&this.mentionsEl.detach&&this.mentionsEl.detach(),super.disconnectedCallback()}updated(e){e.has("value")&&this.editorEl&&this.value!==this.editorEl.innerHTML&&(this.editorEl.innerHTML=this.value||"<p><br></p>",this.content=this.editorEl.innerHTML,this.syncPreview()),e.has("singleLineEditor")&&(this.editorEl&&this.editorEl.classList.toggle("single-line",this.singleLineEditor),this.previewEl&&this.previewEl.classList.toggle("single-line",this.singleLineEditor)),e.has("disabled")&&this.editorEl&&(this.editorEl.setAttribute("contenteditable",this.disabled?"false":"true"),this.editorEl.tabIndex=this.disabled?-1:0,this.linkEl&&(this.linkEl.disabled=this.disabled)),e.has("placeholder")&&this.editorEl&&(this.placeholder?this.editorEl.dataset.placeholder=this.placeholder:delete this.editorEl.dataset.placeholder)}ensureEditor(){if(this.editorEl=this.querySelector(".editor"),!this.editorEl){const e=document.createElement("article");e.className="editor",e.setAttribute("contenteditable",this.disabled?"false":"true"),e.tabIndex=this.disabled?-1:0,this.editorEl=e}this.placeholder&&(this.editorEl.dataset.placeholder=this.placeholder),this.editorEl.innerHTML.trim()||(this.editorEl.innerHTML="<p><br></p>")}unwrapMention(e,t=!0){const i=e.parentNode;if(!i)return;const M=t?(e.textContent??"").replace(/\u200B/g,""):"",n=document.createTextNode(M);i.insertBefore(n,e),i.removeChild(e);const o=document.createRange();o.setStartAfter(n),o.collapse(!0);const r=window.getSelection();r?.removeAllRanges(),r?.addRange(o)}scrubBrokenMentions(){if(!this.editorEl)return;this.editorEl.querySelectorAll("span.mention").forEach((e=>{const t=e,i=t.getAttribute("data-mention-key"),M=t.getAttribute("data-mention-label"),n=t.getAttribute("data-mention-trigger")||"",o=(t.textContent??"").replace(/\u200B/g,"").trim(),r=!!i&&!!M&&o.length>0&&o.startsWith(n)&&o.includes(M);o&&r||this.unwrapMention(t,!0)}))}wireEditor(){this.editorEl.addEventListener("click",this.onEditorClick),this.editorEl.addEventListener("input",this.onEditorInput),this.editorEl.addEventListener("mouseup",this.onEditorMouseup),this.editorEl.addEventListener("keyup",this.onEditorKeyup),this.editorEl.addEventListener("keydown",this.onEditorKeydown)}unwireEditor(){this.editorEl&&(this.editorEl.removeEventListener("click",this.onEditorClick),this.editorEl.removeEventListener("input",this.onEditorInput),this.editorEl.removeEventListener("mouseup",this.onEditorMouseup),this.editorEl.removeEventListener("keyup",this.onEditorKeyup),this.editorEl.removeEventListener("keydown",this.onEditorKeydown))}wireAuthoredToolbar(e){this.buttonMap.clear(),this.headingSelect=null,this.fontSelect=null,this.colorInput=null,Array.from(e.children).forEach((e=>{const t=e.tagName.toLowerCase();if("nile-rte-select"===t&&"align"===e.getAttribute("type"))return e.disabled=this.disabled,void e.addEventListener("change",(e=>{this.focusAndRestore();const t=e.detail;Vm(this.editorEl,t),this.updateContent(),this.updateToolbarState()}));if("nile-rte-link"===t)return e.editorEl=this.editorEl,e.disabled=this.disabled,this.linkEl=e,void e.addEventListener("nile-link-changed",(()=>{this.updateContent(),this.updateToolbarState()}));if("nile-rte-toolbar-item"===t){let t=e.querySelector(":scope > nile-button");const i=e.getAttribute("name")||"",M=e.getAttribute("label")||i,n=e.getAttribute("icon"),o=e.innerHTML.trim().length>0;if(t||(t=document.createElement("nile-button"),t.variant="tertiary",t.size="small"),t.disabled=this.disabled,n)t.innerHTML=`<nile-icon name="${n}" color="${this.disabled?"var(--nile-colors-neutral-500, var(--ng-colors-fg-disabled-subtle))":"var(--nile-colors-dark-900, var(--ng-colors-text-primary-900))"}" ></nile-icon>`,e.innerHTML="";else if(o)t.innerHTML=e.innerHTML,e.innerHTML="";else{const n=$m[i];n?t.innerHTML=`<nile-icon name="${n}" size="20" color="${this.disabled?"var(--nile-colors-neutral-500, var(--ng-colors-fg-disabled-subtle))":"var(--nile-colors-dark-900, var(--ng-colors-text-primary-900))"}" ></nile-icon>`:t.textContent=M||i,e.innerHTML=""}if(!t.isConnected)if(this.disabled)e.appendChild(t);else{const i=document.createElement("nile-lite-tooltip");i.setAttribute("content",M),i.appendChild(t),e.appendChild(i)}t.setAttribute("aria-label",M),t.addEventListener("mousedown",(e=>e.preventDefault())),t.addEventListener("click",(()=>this.onToolbarCommand(i)));const r=this.buttonMap.get(i)??[];return r.push(t),void this.buttonMap.set(i,r)}if("nile-rte-select"!==t)"nile-rte-color"!==t||e.addEventListener("change",(e=>{this.focusAndRestore();const{mode:t,value:i}=e.detail;"backColor"===t?Gm(this.editorEl,"backgroundColor",i,"data-rte-bg"):function(e,t){Gm(e,"color",t,"data-rte-color")}(this.editorEl,i),this.updateContent(),this.updateToolbarState()}));else{const t=e.getAttribute("type")||"";e.addEventListener("change",(e=>{this.focusAndRestore();const i=e.detail;"heading"===t?function(e,t){const i=document.getSelection();if(!i||0===i.rangeCount)return;const M=Zm(i.getRangeAt(0).startContainer,e);if(!M)return;if(M.tagName.toLowerCase()===t)return;const n=document.createElement(t);for(;M.firstChild;)n.appendChild(M.firstChild);M.replaceWith(n);const o=document.createRange();o.selectNodeContents(n),o.collapse(!0),i.removeAllRanges(),i.addRange(o)}(this.editorEl,i):"font"===t&&Rm(this.editorEl,i),this.updateContent(),this.updateToolbarState()}))}}))}saveSelection(){const e=window.getSelection();e&&e.rangeCount&&(this.lastRange=e.getRangeAt(0).cloneRange())}restoreSelection(){if(!this.lastRange)return;const e=document.getSelection();e&&(e.removeAllRanges(),e.addRange(this.lastRange))}focusAndRestore(){this.editorEl?.focus(),this.restoreSelection()}getCleanContent(){const e=this.editorEl.cloneNode(!0);return e.querySelectorAll("*").forEach((e=>{e.removeAttribute("style")})),e.innerHTML}insertList(e){if(this.restoreSelection(),!this.lastRange)return;const t=document.createElement(e),i=this.lastRange.extractContents(),M=document.createElement("div");M.appendChild(i),Array.from(M.childNodes).forEach((e=>{if(e.nodeType===Node.TEXT_NODE&&!e.textContent?.trim())return;const i=document.createElement("li");i.appendChild(e),t.appendChild(i)})),this.lastRange.insertNode(t),this.afterListEdit(t)}afterListEdit(e){const t=document.createRange();t.setStartAfter(e),t.collapse(!0);const i=window.getSelection();i?.removeAllRanges(),i?.addRange(t),this.saveSelection(),this.updateContent(),this.updateToolbarState()}ensureAtLeastOneParagraph(){const e=this.editorEl;if(!e)return;const t=""===(e.textContent??"").replace(/\u200B/g,"").trim();if(0===e.childNodes.length||t)return void(e.innerHTML="<p><br></p>");if(!e.querySelector("p,h1,h2,h3,h4,h5,h6,ul,ol,table,blockquote,pre")){const t=document.createElement("p");for(;e.firstChild;)t.appendChild(e.firstChild);return t.hasChildNodes()||t.appendChild(document.createElement("br")),void e.appendChild(t)}e.querySelectorAll("p").forEach((e=>{""===(e.textContent??"").replace(/\u200B/g,"")&&(e.innerHTML.toLowerCase().includes("<br")||(e.innerHTML="<br>"))}))}onToolbarCommand(e){switch(this.focusAndRestore(),e){case"bold":Wm(this.editorEl,"strong");break;case"italic":Wm(this.editorEl,"em");break;case"underline":Wm(this.editorEl,"u");break;case"left":Vm(this.editorEl,"left");break;case"center":Vm(this.editorEl,"center");break;case"right":Vm(this.editorEl,"right");break;case"justify":Vm(this.editorEl,"justify");break;case"ul":Hm(this.editorEl,"ul"),this.updateContent(),this.updateToolbarState();break;case"ol":Hm(this.editorEl,"ol"),this.updateContent(),this.updateToolbarState();break;case"link":break;case"clear":const e=document.createTreeWalker(this.editorEl,NodeFilter.SHOW_ELEMENT),t=[];for(;e.nextNode();){const i=e.currentNode;i.removeAttribute("style"),["B","STRONG","I","EM","U","SPAN","FONT"].includes(i.tagName)&&t.push(i)}for(const e of t){for(;e.firstChild;)e.parentNode?.insertBefore(e.firstChild,e);e.remove()}this.ensureAtLeastOneParagraph()}this.updateContent(),this.updateToolbarState()}setBtnActive(e,t){const i=this.buttonMap.get(e);if(i)for(const e of i)e.toggleAttribute("data-active",!!t)}updateToolbarState(){if(!this.editorEl)return;const e=document.getSelection();if(!e||0===e.rangeCount)return;const t=e.getRangeAt(0);if(!this.editorEl.contains(t.commonAncestorContainer))return;const i=function(e){for(;e&&!(e instanceof HTMLElement);)e=e.parentNode;return e}(t.startContainer)||this.editorEl,M=getComputedStyle(i),n=Zm(t.startContainer,this.editorEl)||this.editorEl,o=(()=>{let e=i;for(;e&&e!==this.editorEl;){if(e instanceof HTMLElement){const t=e.tagName.toLowerCase();if("strong"===t||"b"===t)return!0;const i=getComputedStyle(e).fontWeight;if(parseInt(i,10)>=600)return!0}e=e.parentNode}return!1})(),r=(()=>{let e=i;for(;e&&e!==this.editorEl;){if(e instanceof HTMLElement){const t=e.tagName.toLowerCase();if("em"===t||"i"===t)return!0;if("italic"===getComputedStyle(e).fontStyle)return!0}e=e.parentNode}return!1})(),s=(()=>{let e=i;for(;e&&e!==this.editorEl;){if(e instanceof HTMLElement){const t=getComputedStyle(e).textDecorationLine;if(t&&t.includes("underline"))return!0;if("u"===e.tagName.toLowerCase())return!0}e=e.parentNode}return!1})(),a=!!i.closest("a"),l=n.style.textAlign||getComputedStyle(n).textAlign||"start",N="start"===l?"left":l,g=!!i.closest("li")&&i.closest("ul,ol")?.tagName.toLowerCase()||"";if(this.setBtnActive("bold",o),this.setBtnActive("italic",r),this.setBtnActive("underline",s),this.setBtnActive("link",a),this.linkEl){const e=this.linkEl.querySelector("nile-button");e&&e.toggleAttribute("data-active",a)}if(this.setBtnActive("left","left"===N&&!["center","right","justify"].includes(N)),this.setBtnActive("center","center"===N),this.setBtnActive("right","right"===N),this.setBtnActive("justify","justify"===N),this.setBtnActive("ul","ul"===g),this.setBtnActive("ol","ol"===g),this.headingSelect){const e=n.tagName.toLowerCase(),t=["h1","h2","h3"].includes(e)?e:"p";this.headingSelect.value!==t&&(this.headingSelect.value=t)}if(this.fontSelect){const e=(M.fontFamily||"").replace(/["']/g,"").split(",")[0].trim().toLowerCase();if(e)for(const t of Array.from(this.fontSelect.options))if(t.value.toLowerCase()===e){this.fontSelect.value=t.value;break}}if(this.colorInput){const e=Pm(M.color);e&&this.colorInput.value.toLowerCase()!==e.toLowerCase()&&(this.colorInput.value=e),this.colorSwatchEl&&(this.colorSwatchEl.style.backgroundColor=this.colorInput.value)}if(this.bgColorInput){const e=getComputedStyle(i).backgroundColor;if(e&&!/transparent|rgba\(\s*0\s*,\s*0\s*,\s*0\s*,\s*0\s*\)/i.test(e)){const t=Pm(e);t&&this.bgColorInput.value.toLowerCase()!==t.toLowerCase()&&(this.bgColorInput.value=t)}this.bgSwatchEl&&(this.bgSwatchEl.style.backgroundColor=this.bgColorInput.value)}}syncPreview(){this.updateContent()}getComputedImportantProps(){return Array.from(new Set([...Xm,...this.whitelist??[]]))}updateContent(){if(!this.editorEl)return;this.ensureAtLeastOneParagraph();const e=""===(this.editorEl.textContent??"").trim();this.editorEl.classList.toggle("empty",e);const t=this.editorEl.cloneNode(!0);if(this.noStyles)t.querySelectorAll("[style]").forEach((e=>e.removeAttribute("style")));else{const e=document.createTreeWalker(this.editorEl,NodeFilter.SHOW_ELEMENT),i=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT),M=this.getComputedImportantProps();for(;e.nextNode()&&i.nextNode();){const t=e.currentNode,n=i.currentNode,o=window.getComputedStyle(t),r=M.map((e=>`${e}:${o.getPropertyValue(e)}`)).join(";");r.trim()&&n.setAttribute("style",r)}}this.content=t.innerHTML,this.previewEl&&(this.previewEl.innerHTML=this.content),this.dispatchEvent(new CustomEvent("nile-change",{detail:{content:this.content},bubbles:!0,composed:!0}))}};e([ce({type:String,attribute:!0,reflect:!0})],qm.prototype,"value",void 0),e([ce({type:Boolean,attribute:!0,reflect:!0})],qm.prototype,"noStyles",void 0),e([ce({type:Boolean,attribute:!0,reflect:!0})],qm.prototype,"disabled",void 0),e([ce({type:Boolean,attribute:"singlelineeditor",reflect:!0})],qm.prototype,"singleLineEditor",void 0),e([ce({type:String})],qm.prototype,"placeholder",void 0),e([ce({attribute:"mentions",reflect:!0,converter:{fromAttribute:e=>{try{const t=JSON.parse(e),i={};for(const e of Object.keys(t)){const M=t[e];Array.isArray(M)&&(i[e]=M.filter((e=>e&&"string"==typeof e.key&&"string"==typeof e.label)).map((e=>({key:e.key,label:e.label}))))}return i}catch{return{}}},toAttribute:e=>JSON.stringify(e)}})],qm.prototype,"mentions",void 0),e([ce({attribute:"whitelist",reflect:!1,converter:{fromAttribute:e=>{try{const t=JSON.parse(e);return Array.isArray(t)?t.filter((e=>"string"==typeof e)):[]}catch{return[]}}}})],qm.prototype,"whitelist",void 0),e([De()],qm.prototype,"content",void 0),qm=e([Ne("nile-rich-text-editor")],qm);"undefined"!=typeof window&&(window.nileElementsVersion='"1.6.0"',window.nileVersion="__NILE_VERSION__",window.process=window.process||{env:{NODE_ENV:"production"}});const Km=r`
15727
15766
  :host {
15728
15767
 
15729
15768
  top: 0;
@@ -1,2 +1,2 @@
1
- function _typeof(o){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(o){return typeof o;}:function(o){return o&&"function"==typeof Symbol&&o.constructor===Symbol&&o!==Symbol.prototype?"symbol":typeof o;},_typeof(o);}System.register(["tslib","lit","lit/decorators.js","./nile-rte-toolbar.cjs.js","./nile-rte-toolbar-item.cjs.js","./nile-rte-select.cjs.js","./nile-rte-color.cjs.js","./nile-rte-divider.cjs.js","./nile-rte-preview.cjs.js","./nile-rte-mentions.cjs.js","./nile-rte-link.cjs.js","./utils/block-utils.cjs.js","./utils/inline-utils.cjs.js","./utils/color-utils.cjs.js","./utils/list-utils.cjs.js","./nile-rich-text-editor.css.cjs.js"],function(_export,_context){"use strict";var t,i,s,e,n,r,o,h,l,c,a,u,d,f,m,p,b,g,y;function _toConsumableArray(r){return _arrayWithoutHoles(r)||_iterableToArray(r)||_unsupportedIterableToArray(r)||_nonIterableSpread();}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}function _iterableToArray(r){if("undefined"!=typeof Symbol&&null!=r[Symbol.iterator]||null!=r["@@iterator"])return Array.from(r);}function _arrayWithoutHoles(r){if(Array.isArray(r))return _arrayLikeToArray(r);}function _createForOfIteratorHelper(r,e){var t="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(!t){if(Array.isArray(r)||(t=_unsupportedIterableToArray(r))||e&&r&&"number"==typeof r.length){t&&(r=t);var n=0,F=function F(){};return{s:F,n:function(_n4){function n(){return _n4.apply(this,arguments);}n.toString=function(){return _n4.toString();};return n;}(function(){return n>=r.length?{done:!0}:{done:!1,value:r[n++]};}),e:function e(r){throw r;},f:F};}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}var o,a=!0,u=!1;return{s:function s(){t=t.call(r);},n:function n(){var r=t.next();return a=r.done,r;},e:function e(r){u=!0,o=r;},f:function f(){try{a||null==t["return"]||t["return"]();}finally{if(u)throw o;}}};}function _unsupportedIterableToArray(r,a){if(r){if("string"==typeof r)return _arrayLikeToArray(r,a);var t={}.toString.call(r).slice(8,-1);return"Object"===t&&r.constructor&&(t=r.constructor.name),"Map"===t||"Set"===t?Array.from(r):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?_arrayLikeToArray(r,a):void 0;}}function _arrayLikeToArray(r,a){(null==a||a>r.length)&&(a=r.length);for(var e=0,n=Array(a);e<a;e++)n[e]=r[e];return n;}function _classCallCheck(a,n){if(!(a instanceof n))throw new TypeError("Cannot call a class as a function");}function _defineProperties(e,r){for(var t=0;t<r.length;t++){var o=r[t];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,_toPropertyKey(o.key),o);}}function _createClass(e,r,t){return r&&_defineProperties(e.prototype,r),t&&_defineProperties(e,t),Object.defineProperty(e,"prototype",{writable:!1}),e;}function _toPropertyKey(t){var i=_toPrimitive(t,"string");return"symbol"==_typeof(i)?i:i+"";}function _toPrimitive(t,r){if("object"!=_typeof(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var i=e.call(t,r||"default");if("object"!=_typeof(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.");}return("string"===r?String:Number)(t);}function _callSuper(t,o,e){return o=_getPrototypeOf(o),_possibleConstructorReturn(t,_isNativeReflectConstruct()?Reflect.construct(o,e||[],_getPrototypeOf(t).constructor):o.apply(t,e));}function _possibleConstructorReturn(t,e){if(e&&("object"==_typeof(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return _assertThisInitialized(t);}function _assertThisInitialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e;}function _isNativeReflectConstruct(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));}catch(t){}return(_isNativeReflectConstruct=function _isNativeReflectConstruct(){return!!t;})();}function _superPropGet(t,o,e,r){var p=_get(_getPrototypeOf(1&r?t.prototype:t),o,e);return 2&r&&"function"==typeof p?function(t){return p.apply(e,t);}:p;}function _get(){return _get="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(e,t,r){var p=_superPropBase(e,t);if(p){var n=Object.getOwnPropertyDescriptor(p,t);return n.get?n.get.call(arguments.length<3?e:r):n.value;}},_get.apply(null,arguments);}function _superPropBase(t,o){for(;!{}.hasOwnProperty.call(t,o)&&null!==(t=_getPrototypeOf(t)););return t;}function _getPrototypeOf(t){return _getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t);},_getPrototypeOf(t);}function _inherits(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&_setPrototypeOf(t,e);}function _setPrototypeOf(t,e){return _setPrototypeOf=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t;},_setPrototypeOf(t,e);}return{setters:[function(_tslib){t=_tslib.__decorate;},function(_lit){i=_lit.LitElement;},function(_litDecoratorsJs){s=_litDecoratorsJs.property;e=_litDecoratorsJs.state;n=_litDecoratorsJs.customElement;},function(_nileRteToolbarCjsJs){},function(_nileRteToolbarItemCjsJs){},function(_nileRteSelectCjsJs){},function(_nileRteColorCjsJs){},function(_nileRteDividerCjsJs){},function(_nileRtePreviewCjsJs){},function(_nileRteMentionsCjsJs){},function(_nileRteLinkCjsJs){},function(_utilsBlockUtilsCjsJs){r=_utilsBlockUtilsCjsJs.s;o=_utilsBlockUtilsCjsJs.a;h=_utilsBlockUtilsCjsJs.n;l=_utilsBlockUtilsCjsJs.c;},function(_utilsInlineUtilsCjsJs){c=_utilsInlineUtilsCjsJs.t;a=_utilsInlineUtilsCjsJs.s;u=_utilsInlineUtilsCjsJs.r;},function(_utilsColorUtilsCjsJs){d=_utilsColorUtilsCjsJs.s;f=_utilsColorUtilsCjsJs.a;},function(_utilsListUtilsCjsJs){m=_utilsListUtilsCjsJs.t;},function(_nileRichTextEditorCssCjsJs){p=_nileRichTextEditorCssCjsJs.s;}],execute:function execute(){b={bold:"format_bold",italic:"format_italic",underline:"format_underline",link:"link_2",left:"format_align_left",center:"format_align_middle",right:"format_align_right",justify:"format_align_justify",ul:"format_list_bulleted",ol:"format_list_numbered",clear:"format_clear"},g=["font-weight","font-style","text-decoration","color","background-color","font-size","font-family","text-align","line-height","letter-spacing","white-space","vertical-align","list-style-position","padding-inline-start"];_export("N",y=/*#__PURE__*/function(_i){function y(){var _this;_classCallCheck(this,y);_this=_callSuper(this,y,arguments),_this.value="",_this.noStyles=!1,_this.disabled=!1,_this.singleLineEditor=!1,_this.placeholder="",_this.mentions={},_this.whitelist=[],_this.content="",_this.previewEl=null,_this.toolbarEl=null,_this.lastRange=null,_this.buttonMap=new Map(),_this.headingSelect=null,_this.fontSelect=null,_this.colorInput=null,_this.bgColorInput=null,_this.colorSwatchEl=null,_this.bgSwatchEl=null,_this.containerEl=null,_this.mentionsEl=null,_this.onEditorKeydown=function(t){if(_this.singleLineEditor&&"Enter"===t.key&&t.shiftKey)return void t.preventDefault();if(t.ctrlKey&&"i"===t.key.toLowerCase()&&(t.preventDefault(),c(_this.editorEl,"em"),_this.updateContent(),_this.updateToolbarState()),_this.singleLineEditor&&"Enter"===t.key)return void t.preventDefault();if("Tab"!==t.key)return;t.preventDefault(),_this.focusAndRestore();var i=window.getSelection();if(!i||0===i.rangeCount)return;var s=i.getRangeAt(0);if(t.shiftKey){if(s.collapsed&&s.startContainer.nodeType===Node.TEXT_NODE){var _t=s.startContainer,_e=s.startOffset,_n=_t.data.slice(0,_e),_r=_n.replace(/(\t|[ \u00a0]{2})$/,"");if(_r.length!==_n.length){_t.data=_r+_t.data.slice(_e);var _s=document.createRange();_s.setStart(_t,_r.length),_s.collapse(!0),i.removeAllRanges(),i.addRange(_s),_this.updateContent(),_this.updateToolbarState();}}return;}s.deleteContents();var e=document.createTextNode("\t");s.insertNode(e);var n=document.createRange();n.setStartAfter(e),n.collapse(!0),i.removeAllRanges(),i.addRange(n),_this.updateContent(),_this.updateToolbarState();},_this.onSelectionChange=function(){if(!_this.editorEl)return;var t=document.getSelection();if(!t||0===t.rangeCount)return;var i=t.getRangeAt(0);_this.editorEl.contains(i.commonAncestorContainer)&&(_this.lastRange=i.cloneRange(),_this.updateToolbarState());};return _this;}_inherits(y,_i);return _createClass(y,[{key:"createRenderRoot",value:function createRenderRoot(){return this;}},{key:"injectCss",value:function injectCss(t){if(this.querySelector("style[data-rte-style]"))return;var i=document.createElement("style");i.setAttribute("data-rte-style","true"),i.textContent=t,this.insertBefore(i,this.firstChild);}},{key:"connectedCallback",value:function connectedCallback(){var _this$mentionsEl$atta,_this$mentionsEl,_this$mentionsEl$setE,_this$mentionsEl2;_superPropGet(y,"connectedCallback",this,3)([]),this.injectCss(p.cssText),this.ensureStructure(),this.placeholder&&this.editorEl&&(this.editorEl.dataset.placeholder=this.placeholder),this.value&&!this.editorEl.innerHTML.trim()&&(this.editorEl.innerHTML=this.value),this.content=this.editorEl.innerHTML,this.toolbarEl&&this.wireAuthoredToolbar(this.toolbarEl),this.mentionsEl=this.querySelector("nile-rte-mentions"),this.mentionsEl&&((_this$mentionsEl$atta=(_this$mentionsEl=this.mentionsEl).attach)!==null&&_this$mentionsEl$atta!==void 0&&_this$mentionsEl$atta.call(_this$mentionsEl,this.editorEl,this),(_this$mentionsEl$setE=(_this$mentionsEl2=this.mentionsEl).setExternalConfig)!==null&&_this$mentionsEl$setE!==void 0&&_this$mentionsEl$setE.call(_this$mentionsEl2,this.mentions)),this.wireEditor(),document.addEventListener("selectionchange",this.onSelectionChange,{passive:!0}),this.updateToolbarState(),this.syncPreview();}},{key:"ensureStructure",value:function ensureStructure(){this.toolbarEl=this.querySelector("nile-rte-toolbar"),this.previewEl=this.querySelector("nile-rte-preview"),this.containerEl=this.querySelector(".rte-container"),this.containerEl||(this.containerEl=document.createElement("div"),this.containerEl.className="rte-container",this.appendChild(this.containerEl)),this.ensureEditor(),this.toolbarEl&&this.toolbarEl.parentElement!==this.containerEl&&this.containerEl.appendChild(this.toolbarEl),this.editorEl.parentElement!==this.containerEl&&this.containerEl.appendChild(this.editorEl),this.previewEl&&(this.previewEl.parentElement!==this&&this.appendChild(this.previewEl),this.previewEl.previousElementSibling!==this.containerEl&&this.insertBefore(this.previewEl,this.containerEl.nextSibling));}},{key:"updateContentWithMention",value:function updateContentWithMention(t){this.updateContent(),this.dispatchEvent(new CustomEvent("nile-change",{detail:{content:this.content,mention:t},bubbles:!0,composed:!0}));}},{key:"disconnectedCallback",value:function disconnectedCallback(){document.removeEventListener("selectionchange",this.onSelectionChange),this.mentionsEl&&this.mentionsEl.detach&&this.mentionsEl.detach(),_superPropGet(y,"disconnectedCallback",this,3)([]);}},{key:"updated",value:function updated(t){t.has("value")&&this.editorEl&&this.value!==this.editorEl.innerHTML&&(this.editorEl.innerHTML=this.value||"<p><br></p>",this.content=this.editorEl.innerHTML,this.syncPreview()),t.has("singleLineEditor")&&(this.editorEl&&this.editorEl.classList.toggle("single-line",this.singleLineEditor),this.previewEl&&this.previewEl.classList.toggle("single-line",this.singleLineEditor)),t.has("disabled")&&this.editorEl&&(this.editorEl.setAttribute("contenteditable",this.disabled?"false":"true"),this.editorEl.tabIndex=this.disabled?-1:0);}},{key:"ensureEditor",value:function ensureEditor(){if(this.editorEl=this.querySelector(".editor"),!this.editorEl){var _t2=document.createElement("article");_t2.className="editor",_t2.setAttribute("contenteditable",this.disabled?"false":"true"),_t2.tabIndex=this.disabled?-1:0,this.editorEl=_t2;}this.placeholder&&(this.editorEl.dataset.placeholder=this.placeholder),this.editorEl.innerHTML.trim()||(this.editorEl.innerHTML="<p><br></p>");}},{key:"unwrapMention",value:function unwrapMention(t){var _t$textContent;var i=arguments.length>1&&arguments[1]!==undefined?arguments[1]:!0;var s=t.parentNode;if(!s)return;var e=i?((_t$textContent=t.textContent)!==null&&_t$textContent!==void 0?_t$textContent:"").replace(/\u200B/g,""):"",n=document.createTextNode(e);s.insertBefore(n,t),s.removeChild(t);var r=document.createRange();r.setStartAfter(n),r.collapse(!0);var o=window.getSelection();o!==null&&o!==void 0&&o.removeAllRanges(),o===null||o===void 0?void 0:o.addRange(r);}},{key:"scrubBrokenMentions",value:function scrubBrokenMentions(){var _this2=this;if(!this.editorEl)return;this.editorEl.querySelectorAll("span.mention").forEach(function(t){var _i$textContent;var i=t,s=i.getAttribute("data-mention-key"),e=i.getAttribute("data-mention-label"),n=i.getAttribute("data-mention-trigger")||"",r=((_i$textContent=i.textContent)!==null&&_i$textContent!==void 0?_i$textContent:"").replace(/\u200B/g,"").trim(),o=!!s&&!!e&&r.length>0&&r.startsWith(n)&&r.includes(e);r&&o||_this2.unwrapMention(i,!0);});}},{key:"wireEditor",value:function wireEditor(){var _this3=this;this.editorEl.addEventListener("input",function(){_this3.ensureAtLeastOneParagraph(),_this3.scrubBrokenMentions(),_this3.updateContent(),_this3.updateToolbarState();}),this.editorEl.addEventListener("mouseup",function(){_this3.saveSelection(),_this3.updateToolbarState();}),this.editorEl.addEventListener("keyup",function(t){_this3.saveSelection(),["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Home","End"].includes(t.key)&&_this3.updateToolbarState();}),this.editorEl.addEventListener("keydown",this.onEditorKeydown);}},{key:"wireAuthoredToolbar",value:function wireAuthoredToolbar(t){var _this4=this;this.buttonMap.clear(),this.headingSelect=null,this.fontSelect=null,this.colorInput=null,Array.from(t.children).forEach(function(t){var i=t.tagName.toLowerCase();if("nile-rte-select"===i&&"align"===t.getAttribute("type"))return t.disabled=_this4.disabled,void t.addEventListener("change",function(t){_this4.focusAndRestore();var i=t.detail;r(_this4.editorEl,i),_this4.updateContent(),_this4.updateToolbarState();});if("nile-rte-link"===i)return t.editorEl=_this4.editorEl,void t.addEventListener("link-changed",function(){_this4.updateContent(),_this4.updateToolbarState();});if("nile-rte-toolbar-item"===i){var _this4$buttonMap$get;var _i2=t.querySelector(":scope > nile-button");var _s2=t.getAttribute("name")||"",_e2=t.getAttribute("label")||_s2,_n2=t.getAttribute("icon"),_r2=t.innerHTML.trim().length>0;if(_i2||(_i2=document.createElement("nile-button"),_i2.variant="tertiary",_i2.size="small"),_i2.disabled=_this4.disabled,_n2)_i2.innerHTML="<nile-icon name=\"".concat(_n2,"\" color=\"").concat(_this4.disabled?"var(--nile-colors-neutral-500, var(--ng-colors-fg-disabled-subtle))":"var(--nile-colors-dark-900, var(--ng-colors-text-primary-900))","\" ></nile-icon>"),t.innerHTML="";else if(_r2)_i2.innerHTML=t.innerHTML,t.innerHTML="";else{var _n3=b[_s2];_n3?_i2.innerHTML="<nile-icon name=\"".concat(_n3,"\" size=\"20\" color=\"").concat(_this4.disabled?"var(--nile-colors-neutral-500, var(--ng-colors-fg-disabled-subtle))":"var(--nile-colors-dark-900, var(--ng-colors-text-primary-900))","\" ></nile-icon>"):_i2.textContent=_e2||_s2,t.innerHTML="";}if(!_i2.isConnected)if(_this4.disabled)t.appendChild(_i2);else{var _s3=document.createElement("nile-lite-tooltip");_s3.setAttribute("content",_e2),_s3.appendChild(_i2),t.appendChild(_s3);}_i2.setAttribute("aria-label",_e2),_i2.addEventListener("mousedown",function(t){return t.preventDefault();}),_i2.addEventListener("click",function(){return _this4.onToolbarCommand(_s2);});var _o=(_this4$buttonMap$get=_this4.buttonMap.get(_s2))!==null&&_this4$buttonMap$get!==void 0?_this4$buttonMap$get:[];return _o.push(_i2),void _this4.buttonMap.set(_s2,_o);}if("nile-rte-select"!==i)"nile-rte-color"!==i||t.addEventListener("change",function(t){_this4.focusAndRestore();var _t$detail=t.detail,i=_t$detail.mode,s=_t$detail.value;"backColor"===i?d(_this4.editorEl,s):f(_this4.editorEl,s),_this4.updateContent(),_this4.updateToolbarState();});else{var _i3=t.getAttribute("type")||"";t.addEventListener("change",function(t){_this4.focusAndRestore();var s=t.detail;"heading"===_i3?o(_this4.editorEl,s):"font"===_i3&&a(_this4.editorEl,s),_this4.updateContent(),_this4.updateToolbarState();});}});}},{key:"saveSelection",value:function saveSelection(){var t=window.getSelection();t&&t.rangeCount&&(this.lastRange=t.getRangeAt(0).cloneRange());}},{key:"restoreSelection",value:function restoreSelection(){if(!this.lastRange)return;var t=document.getSelection();t&&(t.removeAllRanges(),t.addRange(this.lastRange));}},{key:"focusAndRestore",value:function focusAndRestore(){var _this$editorEl;(_this$editorEl=this.editorEl)!==null&&_this$editorEl!==void 0&&_this$editorEl.focus(),this.restoreSelection();}},{key:"getCleanContent",value:function getCleanContent(){var t=this.editorEl.cloneNode(!0);return t.querySelectorAll("*").forEach(function(t){t.removeAttribute("style");}),t.innerHTML;}},{key:"insertList",value:function insertList(t){if(this.restoreSelection(),!this.lastRange)return;var i=document.createElement(t),s=this.lastRange.extractContents(),e=document.createElement("div");e.appendChild(s),Array.from(e.childNodes).forEach(function(t){var _t$textContent2;if(t.nodeType===Node.TEXT_NODE&&!((_t$textContent2=t.textContent)!==null&&_t$textContent2!==void 0&&_t$textContent2.trim()))return;var s=document.createElement("li");s.appendChild(t),i.appendChild(s);}),this.lastRange.insertNode(i),this.afterListEdit(i);}},{key:"afterListEdit",value:function afterListEdit(t){var i=document.createRange();i.setStartAfter(t),i.collapse(!0);var s=window.getSelection();s!==null&&s!==void 0&&s.removeAllRanges(),s!==null&&s!==void 0&&s.addRange(i),this.saveSelection(),this.updateContent(),this.updateToolbarState();}},{key:"ensureAtLeastOneParagraph",value:function ensureAtLeastOneParagraph(){var _t$textContent3;var t=this.editorEl;if(!t)return;var i=""===((_t$textContent3=t.textContent)!==null&&_t$textContent3!==void 0?_t$textContent3:"").replace(/\u200B/g,"").trim();if(0===t.childNodes.length||i)return void(t.innerHTML="<p><br></p>");if(!t.querySelector("p,h1,h2,h3,h4,h5,h6,ul,ol,table,blockquote,pre")){var _i4=document.createElement("p");for(;t.firstChild;)_i4.appendChild(t.firstChild);return _i4.hasChildNodes()||_i4.appendChild(document.createElement("br")),void t.appendChild(_i4);}t.querySelectorAll("p").forEach(function(t){var _t$textContent4;""===((_t$textContent4=t.textContent)!==null&&_t$textContent4!==void 0?_t$textContent4:"").replace(/\u200B/g,"")&&(t.innerHTML.toLowerCase().includes("<br")||(t.innerHTML="<br>"));});}},{key:"onToolbarCommand",value:function onToolbarCommand(t){switch(this.focusAndRestore(),t){case"bold":c(this.editorEl,"strong");break;case"italic":c(this.editorEl,"em");break;case"underline":c(this.editorEl,"u");break;case"left":r(this.editorEl,"left");break;case"center":r(this.editorEl,"center");break;case"right":r(this.editorEl,"right");break;case"justify":r(this.editorEl,"justify");break;case"ul":m(this.editorEl,"ul"),this.updateContent(),this.updateToolbarState();break;case"ol":m(this.editorEl,"ol"),this.updateContent(),this.updateToolbarState();break;case"link":break;case"clear":var _t3=document.createTreeWalker(this.editorEl,NodeFilter.SHOW_ELEMENT),_i5=[];for(;_t3.nextNode();){var _s4=_t3.currentNode;_s4.removeAttribute("style"),["B","STRONG","I","EM","U","SPAN","FONT"].includes(_s4.tagName)&&_i5.push(_s4);}for(var _i7=0,_i6=_i5;_i7<_i6.length;_i7++){var _t4=_i6[_i7];for(;_t4.firstChild;){var _t4$parentNode;(_t4$parentNode=_t4.parentNode)===null||_t4$parentNode===void 0||_t4$parentNode.insertBefore(_t4.firstChild,_t4);}_t4.remove();}this.ensureAtLeastOneParagraph();}this.updateContent(),this.updateToolbarState();}},{key:"setBtnActive",value:function setBtnActive(t,i){var s=this.buttonMap.get(t);if(s){var _iterator=_createForOfIteratorHelper(s),_step;try{for(_iterator.s();!(_step=_iterator.n()).done;){var _t5=_step.value;_t5.toggleAttribute("data-active",!!i);}}catch(err){_iterator.e(err);}finally{_iterator.f();}}}},{key:"updateToolbarState",value:function updateToolbarState(){var _this5=this,_s$closest;if(!this.editorEl)return;var t=document.getSelection();if(!t||0===t.rangeCount)return;var i=t.getRangeAt(0);if(!this.editorEl.contains(i.commonAncestorContainer))return;var s=h(i.startContainer)||this.editorEl,e=getComputedStyle(s),n=l(i.startContainer,this.editorEl)||this.editorEl,r=function(){var t=s;for(;t&&t!==_this5.editorEl;){if(t instanceof HTMLElement){var _i8=t.tagName.toLowerCase();if("strong"===_i8||"b"===_i8)return!0;var _s5=getComputedStyle(t).fontWeight;if(parseInt(_s5,10)>=600)return!0;}t=t.parentNode;}return!1;}(),o=function(){var t=s;for(;t&&t!==_this5.editorEl;){if(t instanceof HTMLElement){var _i9=t.tagName.toLowerCase();if("em"===_i9||"i"===_i9)return!0;if("italic"===getComputedStyle(t).fontStyle)return!0;}t=t.parentNode;}return!1;}(),c=function(){var t=s;for(;t&&t!==_this5.editorEl;){if(t instanceof HTMLElement){var _i10=getComputedStyle(t).textDecorationLine;if(_i10&&_i10.includes("underline"))return!0;if("u"===t.tagName.toLowerCase())return!0;}t=t.parentNode;}return!1;}(),a=!!s.closest("a"),d=n.style.textAlign||getComputedStyle(n).textAlign||"start",f="start"===d?"left":d,m=!!s.closest("li")&&((_s$closest=s.closest("ul,ol"))===null||_s$closest===void 0?void 0:_s$closest.tagName.toLowerCase())||"";if(this.setBtnActive("bold",r),this.setBtnActive("italic",o),this.setBtnActive("underline",c),this.setBtnActive("link",a),this.setBtnActive("left","left"===f&&!["center","right","justify"].includes(f)),this.setBtnActive("center","center"===f),this.setBtnActive("right","right"===f),this.setBtnActive("justify","justify"===f),this.setBtnActive("ul","ul"===m),this.setBtnActive("ol","ol"===m),this.headingSelect){var _t6=n.tagName.toLowerCase(),_i11=["h1","h2","h3"].includes(_t6)?_t6:"p";this.headingSelect.value!==_i11&&(this.headingSelect.value=_i11);}if(this.fontSelect){var _t7=(e.fontFamily||"").replace(/["']/g,"").split(",")[0].trim().toLowerCase();if(_t7)for(var _i12=0,_Array$from=Array.from(this.fontSelect.options);_i12<_Array$from.length;_i12++){var _i13=_Array$from[_i12];if(_i13.value.toLowerCase()===_t7){this.fontSelect.value=_i13.value;break;}}}if(this.colorInput){var _t8=u(e.color);_t8&&this.colorInput.value.toLowerCase()!==_t8.toLowerCase()&&(this.colorInput.value=_t8),this.colorSwatchEl&&(this.colorSwatchEl.style.backgroundColor=this.colorInput.value);}if(this.bgColorInput){var _t9=getComputedStyle(s).backgroundColor;if(_t9&&!/transparent|rgba\(\s*0\s*,\s*0\s*,\s*0\s*,\s*0\s*\)/i.test(_t9)){var _i14=u(_t9);_i14&&this.bgColorInput.value.toLowerCase()!==_i14.toLowerCase()&&(this.bgColorInput.value=_i14);}this.bgSwatchEl&&(this.bgSwatchEl.style.backgroundColor=this.bgColorInput.value);}}},{key:"syncPreview",value:function syncPreview(){this.updateContent();}},{key:"getComputedImportantProps",value:function getComputedImportantProps(){var _this$whitelist;return Array.from(new Set([].concat(g,_toConsumableArray((_this$whitelist=this.whitelist)!==null&&_this$whitelist!==void 0?_this$whitelist:[]))));}},{key:"updateContent",value:function updateContent(){var _this$editorEl$textCo;if(!this.editorEl)return;this.ensureAtLeastOneParagraph();var t=""===((_this$editorEl$textCo=this.editorEl.textContent)!==null&&_this$editorEl$textCo!==void 0?_this$editorEl$textCo:"").trim();this.editorEl.classList.toggle("empty",t);var i=this.editorEl.cloneNode(!0);if(this.noStyles)i.querySelectorAll("[style]").forEach(function(t){return t.removeAttribute("style");});else{var _t10=document.createTreeWalker(this.editorEl,NodeFilter.SHOW_ELEMENT),_s6=document.createTreeWalker(i,NodeFilter.SHOW_ELEMENT),_e3=this.getComputedImportantProps();var _loop=function _loop(){var i=_t10.currentNode,n=_s6.currentNode,r=window.getComputedStyle(i),o=_e3.map(function(t){return"".concat(t,":").concat(r.getPropertyValue(t));}).join(";");o.trim()&&n.setAttribute("style",o);};for(;_t10.nextNode()&&_s6.nextNode();){_loop();}}this.content=i.innerHTML,this.previewEl&&(this.previewEl.innerHTML=this.content),this.dispatchEvent(new CustomEvent("nile-change",{detail:{content:this.content},bubbles:!0,composed:!0}));}}]);}(i));t([s({type:String,attribute:!0,reflect:!0})],y.prototype,"value",void 0),t([s({type:Boolean,attribute:!0,reflect:!0})],y.prototype,"noStyles",void 0),t([s({type:Boolean,attribute:!0,reflect:!0})],y.prototype,"disabled",void 0),t([s({type:Boolean,attribute:"singlelineeditor",reflect:!0})],y.prototype,"singleLineEditor",void 0),t([s({type:String})],y.prototype,"placeholder",void 0),t([s({attribute:"mentions",reflect:!0,converter:{fromAttribute:function fromAttribute(t){try{var _i15=JSON.parse(t),_s7={};for(var _i16=0,_Object$keys=Object.keys(_i15);_i16<_Object$keys.length;_i16++){var _t11=_Object$keys[_i16];var _e4=_i15[_t11];Array.isArray(_e4)&&(_s7[_t11]=_e4.filter(function(t){return t&&"string"==typeof t.key&&"string"==typeof t.label;}).map(function(t){return{key:t.key,label:t.label};}));}return _s7;}catch(_unused){return{};}},toAttribute:function toAttribute(t){return JSON.stringify(t);}}})],y.prototype,"mentions",void 0),t([s({attribute:"whitelist",reflect:!1,converter:{fromAttribute:function fromAttribute(t){try{var _i17=JSON.parse(t);return Array.isArray(_i17)?_i17.filter(function(t){return"string"==typeof t;}):[];}catch(_unused2){return[];}}}})],y.prototype,"whitelist",void 0),t([e()],y.prototype,"content",void 0),_export("N",y=t([n("nile-rich-text-editor")],y));}};});
1
+ function _typeof(o){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(o){return typeof o;}:function(o){return o&&"function"==typeof Symbol&&o.constructor===Symbol&&o!==Symbol.prototype?"symbol":typeof o;},_typeof(o);}System.register(["tslib","lit","lit/decorators.js","./nile-rte-toolbar.cjs.js","./nile-rte-toolbar-item.cjs.js","./nile-rte-select.cjs.js","./nile-rte-color.cjs.js","./nile-rte-divider.cjs.js","./nile-rte-preview.cjs.js","./nile-rte-mentions.cjs.js","./nile-rte-link.cjs.js","./utils/block-utils.cjs.js","./utils/inline-utils.cjs.js","./utils/color-utils.cjs.js","./utils/list-utils.cjs.js","./nile-rich-text-editor.css.cjs.js"],function(_export,_context){"use strict";var t,i,s,e,n,r,o,h,l,c,a,u,d,f,m,p,b,g,y;function _toConsumableArray(r){return _arrayWithoutHoles(r)||_iterableToArray(r)||_unsupportedIterableToArray(r)||_nonIterableSpread();}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}function _iterableToArray(r){if("undefined"!=typeof Symbol&&null!=r[Symbol.iterator]||null!=r["@@iterator"])return Array.from(r);}function _arrayWithoutHoles(r){if(Array.isArray(r))return _arrayLikeToArray(r);}function _createForOfIteratorHelper(r,e){var t="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(!t){if(Array.isArray(r)||(t=_unsupportedIterableToArray(r))||e&&r&&"number"==typeof r.length){t&&(r=t);var n=0,F=function F(){};return{s:F,n:function(_n4){function n(){return _n4.apply(this,arguments);}n.toString=function(){return _n4.toString();};return n;}(function(){return n>=r.length?{done:!0}:{done:!1,value:r[n++]};}),e:function e(r){throw r;},f:F};}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");}var o,a=!0,u=!1;return{s:function s(){t=t.call(r);},n:function n(){var r=t.next();return a=r.done,r;},e:function e(r){u=!0,o=r;},f:function f(){try{a||null==t["return"]||t["return"]();}finally{if(u)throw o;}}};}function _unsupportedIterableToArray(r,a){if(r){if("string"==typeof r)return _arrayLikeToArray(r,a);var t={}.toString.call(r).slice(8,-1);return"Object"===t&&r.constructor&&(t=r.constructor.name),"Map"===t||"Set"===t?Array.from(r):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?_arrayLikeToArray(r,a):void 0;}}function _arrayLikeToArray(r,a){(null==a||a>r.length)&&(a=r.length);for(var e=0,n=Array(a);e<a;e++)n[e]=r[e];return n;}function _classCallCheck(a,n){if(!(a instanceof n))throw new TypeError("Cannot call a class as a function");}function _defineProperties(e,r){for(var t=0;t<r.length;t++){var o=r[t];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,_toPropertyKey(o.key),o);}}function _createClass(e,r,t){return r&&_defineProperties(e.prototype,r),t&&_defineProperties(e,t),Object.defineProperty(e,"prototype",{writable:!1}),e;}function _toPropertyKey(t){var i=_toPrimitive(t,"string");return"symbol"==_typeof(i)?i:i+"";}function _toPrimitive(t,r){if("object"!=_typeof(t)||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var i=e.call(t,r||"default");if("object"!=_typeof(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.");}return("string"===r?String:Number)(t);}function _callSuper(t,o,e){return o=_getPrototypeOf(o),_possibleConstructorReturn(t,_isNativeReflectConstruct()?Reflect.construct(o,e||[],_getPrototypeOf(t).constructor):o.apply(t,e));}function _possibleConstructorReturn(t,e){if(e&&("object"==_typeof(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return _assertThisInitialized(t);}function _assertThisInitialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e;}function _isNativeReflectConstruct(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}));}catch(t){}return(_isNativeReflectConstruct=function _isNativeReflectConstruct(){return!!t;})();}function _superPropGet(t,o,e,r){var p=_get(_getPrototypeOf(1&r?t.prototype:t),o,e);return 2&r&&"function"==typeof p?function(t){return p.apply(e,t);}:p;}function _get(){return _get="undefined"!=typeof Reflect&&Reflect.get?Reflect.get.bind():function(e,t,r){var p=_superPropBase(e,t);if(p){var n=Object.getOwnPropertyDescriptor(p,t);return n.get?n.get.call(arguments.length<3?e:r):n.value;}},_get.apply(null,arguments);}function _superPropBase(t,o){for(;!{}.hasOwnProperty.call(t,o)&&null!==(t=_getPrototypeOf(t)););return t;}function _getPrototypeOf(t){return _getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t);},_getPrototypeOf(t);}function _inherits(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&_setPrototypeOf(t,e);}function _setPrototypeOf(t,e){return _setPrototypeOf=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t;},_setPrototypeOf(t,e);}return{setters:[function(_tslib){t=_tslib.__decorate;},function(_lit){i=_lit.LitElement;},function(_litDecoratorsJs){s=_litDecoratorsJs.property;e=_litDecoratorsJs.state;n=_litDecoratorsJs.customElement;},function(_nileRteToolbarCjsJs){},function(_nileRteToolbarItemCjsJs){},function(_nileRteSelectCjsJs){},function(_nileRteColorCjsJs){},function(_nileRteDividerCjsJs){},function(_nileRtePreviewCjsJs){},function(_nileRteMentionsCjsJs){},function(_nileRteLinkCjsJs){},function(_utilsBlockUtilsCjsJs){r=_utilsBlockUtilsCjsJs.s;o=_utilsBlockUtilsCjsJs.a;h=_utilsBlockUtilsCjsJs.n;l=_utilsBlockUtilsCjsJs.c;},function(_utilsInlineUtilsCjsJs){c=_utilsInlineUtilsCjsJs.t;a=_utilsInlineUtilsCjsJs.s;u=_utilsInlineUtilsCjsJs.r;},function(_utilsColorUtilsCjsJs){d=_utilsColorUtilsCjsJs.s;f=_utilsColorUtilsCjsJs.a;},function(_utilsListUtilsCjsJs){m=_utilsListUtilsCjsJs.t;},function(_nileRichTextEditorCssCjsJs){p=_nileRichTextEditorCssCjsJs.s;}],execute:function execute(){b={bold:"format_bold",italic:"format_italic",underline:"format_underline",link:"link_2",left:"format_align_left",center:"format_align_middle",right:"format_align_right",justify:"format_align_justify",ul:"format_list_bulleted",ol:"format_list_numbered",clear:"format_clear"},g=["font-weight","font-style","text-decoration","color","background-color","font-size","font-family","text-align","line-height","letter-spacing","white-space","vertical-align","list-style-position","padding-inline-start"];_export("N",y=/*#__PURE__*/function(_i){function y(){var _this;_classCallCheck(this,y);_this=_callSuper(this,y,arguments),_this.value="",_this.noStyles=!1,_this.disabled=!1,_this.singleLineEditor=!1,_this.placeholder="",_this.mentions={},_this.whitelist=[],_this.content="",_this.previewEl=null,_this.toolbarEl=null,_this.lastRange=null,_this.buttonMap=new Map(),_this.headingSelect=null,_this.fontSelect=null,_this.colorInput=null,_this.bgColorInput=null,_this.colorSwatchEl=null,_this.bgSwatchEl=null,_this.containerEl=null,_this.linkEl=null,_this.mentionsEl=null,_this.onEditorClick=function(t){var _t$target$closest,_t$target;var i=(_t$target$closest=(_t$target=t.target).closest)===null||_t$target$closest===void 0?void 0:_t$target$closest.call(_t$target,"a");i&&t.preventDefault();},_this.onEditorInput=function(){_this.ensureAtLeastOneParagraph(),_this.scrubBrokenMentions(),_this.updateContent(),_this.updateToolbarState();},_this.onEditorMouseup=function(){_this.saveSelection(),_this.updateToolbarState();},_this.onEditorKeyup=function(t){_this.saveSelection(),["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Home","End"].includes(t.key)&&_this.updateToolbarState();},_this.onEditorKeydown=function(t){if(_this.singleLineEditor&&"Enter"===t.key&&t.shiftKey)return void t.preventDefault();if(t.ctrlKey&&"i"===t.key.toLowerCase()&&(t.preventDefault(),c(_this.editorEl,"em"),_this.updateContent(),_this.updateToolbarState()),_this.singleLineEditor&&"Enter"===t.key)return void t.preventDefault();if("Tab"!==t.key)return;t.preventDefault(),_this.focusAndRestore();var i=window.getSelection();if(!i||0===i.rangeCount)return;var s=i.getRangeAt(0);if(t.shiftKey){if(s.collapsed&&s.startContainer.nodeType===Node.TEXT_NODE){var _t=s.startContainer,_e=s.startOffset,_n=_t.data.slice(0,_e),_r=_n.replace(/(\t|[ \u00a0]{2})$/,"");if(_r.length!==_n.length){_t.data=_r+_t.data.slice(_e);var _s=document.createRange();_s.setStart(_t,_r.length),_s.collapse(!0),i.removeAllRanges(),i.addRange(_s),_this.updateContent(),_this.updateToolbarState();}}return;}s.deleteContents();var e=document.createTextNode("\t");s.insertNode(e);var n=document.createRange();n.setStartAfter(e),n.collapse(!0),i.removeAllRanges(),i.addRange(n),_this.updateContent(),_this.updateToolbarState();},_this.onSelectionChange=function(){if(!_this.editorEl)return;var t=document.getSelection();if(!t||0===t.rangeCount)return;var i=t.getRangeAt(0);_this.editorEl.contains(i.commonAncestorContainer)&&(_this.lastRange=i.cloneRange(),_this.updateToolbarState());};return _this;}_inherits(y,_i);return _createClass(y,[{key:"createRenderRoot",value:function createRenderRoot(){return this;}},{key:"injectCss",value:function injectCss(t){if(this.querySelector("style[data-rte-style]"))return;var i=document.createElement("style");i.setAttribute("data-rte-style","true"),i.textContent=t,this.insertBefore(i,this.firstChild);}},{key:"connectedCallback",value:function connectedCallback(){var _this$mentionsEl$atta,_this$mentionsEl,_this$mentionsEl$setE,_this$mentionsEl2;_superPropGet(y,"connectedCallback",this,3)([]),this.injectCss(p.cssText),this.ensureStructure(),this.placeholder&&this.editorEl&&(this.editorEl.dataset.placeholder=this.placeholder),this.value&&!this.editorEl.innerHTML.trim()&&(this.editorEl.innerHTML=this.value),this.content=this.editorEl.innerHTML,this.toolbarEl&&this.wireAuthoredToolbar(this.toolbarEl),this.mentionsEl=this.querySelector("nile-rte-mentions"),this.mentionsEl&&((_this$mentionsEl$atta=(_this$mentionsEl=this.mentionsEl).attach)!==null&&_this$mentionsEl$atta!==void 0&&_this$mentionsEl$atta.call(_this$mentionsEl,this.editorEl,this),(_this$mentionsEl$setE=(_this$mentionsEl2=this.mentionsEl).setExternalConfig)!==null&&_this$mentionsEl$setE!==void 0&&_this$mentionsEl$setE.call(_this$mentionsEl2,this.mentions)),this.wireEditor(),document.addEventListener("selectionchange",this.onSelectionChange,{passive:!0}),this.updateToolbarState(),this.syncPreview();}},{key:"ensureStructure",value:function ensureStructure(){this.toolbarEl=this.querySelector("nile-rte-toolbar"),this.previewEl=this.querySelector("nile-rte-preview"),this.containerEl=this.querySelector(".rte-container"),this.containerEl||(this.containerEl=document.createElement("div"),this.containerEl.className="rte-container",this.appendChild(this.containerEl)),this.ensureEditor(),this.toolbarEl&&this.toolbarEl.parentElement!==this.containerEl&&this.containerEl.appendChild(this.toolbarEl),this.editorEl.parentElement!==this.containerEl&&this.containerEl.appendChild(this.editorEl),this.previewEl&&(this.previewEl.parentElement!==this&&this.appendChild(this.previewEl),this.previewEl.previousElementSibling!==this.containerEl&&this.insertBefore(this.previewEl,this.containerEl.nextSibling));}},{key:"updateContentWithMention",value:function updateContentWithMention(t){this.updateContent(),this.dispatchEvent(new CustomEvent("nile-change",{detail:{content:this.content,mention:t},bubbles:!0,composed:!0}));}},{key:"disconnectedCallback",value:function disconnectedCallback(){this.unwireEditor(),document.removeEventListener("selectionchange",this.onSelectionChange),this.mentionsEl&&this.mentionsEl.detach&&this.mentionsEl.detach(),_superPropGet(y,"disconnectedCallback",this,3)([]);}},{key:"updated",value:function updated(t){t.has("value")&&this.editorEl&&this.value!==this.editorEl.innerHTML&&(this.editorEl.innerHTML=this.value||"<p><br></p>",this.content=this.editorEl.innerHTML,this.syncPreview()),t.has("singleLineEditor")&&(this.editorEl&&this.editorEl.classList.toggle("single-line",this.singleLineEditor),this.previewEl&&this.previewEl.classList.toggle("single-line",this.singleLineEditor)),t.has("disabled")&&this.editorEl&&(this.editorEl.setAttribute("contenteditable",this.disabled?"false":"true"),this.editorEl.tabIndex=this.disabled?-1:0,this.linkEl&&(this.linkEl.disabled=this.disabled)),t.has("placeholder")&&this.editorEl&&(this.placeholder?this.editorEl.dataset.placeholder=this.placeholder:delete this.editorEl.dataset.placeholder);}},{key:"ensureEditor",value:function ensureEditor(){if(this.editorEl=this.querySelector(".editor"),!this.editorEl){var _t2=document.createElement("article");_t2.className="editor",_t2.setAttribute("contenteditable",this.disabled?"false":"true"),_t2.tabIndex=this.disabled?-1:0,this.editorEl=_t2;}this.placeholder&&(this.editorEl.dataset.placeholder=this.placeholder),this.editorEl.innerHTML.trim()||(this.editorEl.innerHTML="<p><br></p>");}},{key:"unwrapMention",value:function unwrapMention(t){var _t$textContent;var i=arguments.length>1&&arguments[1]!==undefined?arguments[1]:!0;var s=t.parentNode;if(!s)return;var e=i?((_t$textContent=t.textContent)!==null&&_t$textContent!==void 0?_t$textContent:"").replace(/\u200B/g,""):"",n=document.createTextNode(e);s.insertBefore(n,t),s.removeChild(t);var r=document.createRange();r.setStartAfter(n),r.collapse(!0);var o=window.getSelection();o!==null&&o!==void 0&&o.removeAllRanges(),o===null||o===void 0?void 0:o.addRange(r);}},{key:"scrubBrokenMentions",value:function scrubBrokenMentions(){var _this2=this;if(!this.editorEl)return;this.editorEl.querySelectorAll("span.mention").forEach(function(t){var _i$textContent;var i=t,s=i.getAttribute("data-mention-key"),e=i.getAttribute("data-mention-label"),n=i.getAttribute("data-mention-trigger")||"",r=((_i$textContent=i.textContent)!==null&&_i$textContent!==void 0?_i$textContent:"").replace(/\u200B/g,"").trim(),o=!!s&&!!e&&r.length>0&&r.startsWith(n)&&r.includes(e);r&&o||_this2.unwrapMention(i,!0);});}},{key:"wireEditor",value:function wireEditor(){this.editorEl.addEventListener("click",this.onEditorClick),this.editorEl.addEventListener("input",this.onEditorInput),this.editorEl.addEventListener("mouseup",this.onEditorMouseup),this.editorEl.addEventListener("keyup",this.onEditorKeyup),this.editorEl.addEventListener("keydown",this.onEditorKeydown);}},{key:"unwireEditor",value:function unwireEditor(){this.editorEl&&(this.editorEl.removeEventListener("click",this.onEditorClick),this.editorEl.removeEventListener("input",this.onEditorInput),this.editorEl.removeEventListener("mouseup",this.onEditorMouseup),this.editorEl.removeEventListener("keyup",this.onEditorKeyup),this.editorEl.removeEventListener("keydown",this.onEditorKeydown));}},{key:"wireAuthoredToolbar",value:function wireAuthoredToolbar(t){var _this3=this;this.buttonMap.clear(),this.headingSelect=null,this.fontSelect=null,this.colorInput=null,Array.from(t.children).forEach(function(t){var i=t.tagName.toLowerCase();if("nile-rte-select"===i&&"align"===t.getAttribute("type"))return t.disabled=_this3.disabled,void t.addEventListener("change",function(t){_this3.focusAndRestore();var i=t.detail;r(_this3.editorEl,i),_this3.updateContent(),_this3.updateToolbarState();});if("nile-rte-link"===i)return t.editorEl=_this3.editorEl,t.disabled=_this3.disabled,_this3.linkEl=t,void t.addEventListener("nile-link-changed",function(){_this3.updateContent(),_this3.updateToolbarState();});if("nile-rte-toolbar-item"===i){var _this3$buttonMap$get;var _i2=t.querySelector(":scope > nile-button");var _s2=t.getAttribute("name")||"",_e2=t.getAttribute("label")||_s2,_n2=t.getAttribute("icon"),_r2=t.innerHTML.trim().length>0;if(_i2||(_i2=document.createElement("nile-button"),_i2.variant="tertiary",_i2.size="small"),_i2.disabled=_this3.disabled,_n2)_i2.innerHTML="<nile-icon name=\"".concat(_n2,"\" color=\"").concat(_this3.disabled?"var(--nile-colors-neutral-500, var(--ng-colors-fg-disabled-subtle))":"var(--nile-colors-dark-900, var(--ng-colors-text-primary-900))","\" ></nile-icon>"),t.innerHTML="";else if(_r2)_i2.innerHTML=t.innerHTML,t.innerHTML="";else{var _n3=b[_s2];_n3?_i2.innerHTML="<nile-icon name=\"".concat(_n3,"\" size=\"20\" color=\"").concat(_this3.disabled?"var(--nile-colors-neutral-500, var(--ng-colors-fg-disabled-subtle))":"var(--nile-colors-dark-900, var(--ng-colors-text-primary-900))","\" ></nile-icon>"):_i2.textContent=_e2||_s2,t.innerHTML="";}if(!_i2.isConnected)if(_this3.disabled)t.appendChild(_i2);else{var _s3=document.createElement("nile-lite-tooltip");_s3.setAttribute("content",_e2),_s3.appendChild(_i2),t.appendChild(_s3);}_i2.setAttribute("aria-label",_e2),_i2.addEventListener("mousedown",function(t){return t.preventDefault();}),_i2.addEventListener("click",function(){return _this3.onToolbarCommand(_s2);});var _o=(_this3$buttonMap$get=_this3.buttonMap.get(_s2))!==null&&_this3$buttonMap$get!==void 0?_this3$buttonMap$get:[];return _o.push(_i2),void _this3.buttonMap.set(_s2,_o);}if("nile-rte-select"!==i)"nile-rte-color"!==i||t.addEventListener("change",function(t){_this3.focusAndRestore();var _t$detail=t.detail,i=_t$detail.mode,s=_t$detail.value;"backColor"===i?d(_this3.editorEl,s):f(_this3.editorEl,s),_this3.updateContent(),_this3.updateToolbarState();});else{var _i3=t.getAttribute("type")||"";t.addEventListener("change",function(t){_this3.focusAndRestore();var s=t.detail;"heading"===_i3?o(_this3.editorEl,s):"font"===_i3&&a(_this3.editorEl,s),_this3.updateContent(),_this3.updateToolbarState();});}});}},{key:"saveSelection",value:function saveSelection(){var t=window.getSelection();t&&t.rangeCount&&(this.lastRange=t.getRangeAt(0).cloneRange());}},{key:"restoreSelection",value:function restoreSelection(){if(!this.lastRange)return;var t=document.getSelection();t&&(t.removeAllRanges(),t.addRange(this.lastRange));}},{key:"focusAndRestore",value:function focusAndRestore(){var _this$editorEl;(_this$editorEl=this.editorEl)!==null&&_this$editorEl!==void 0&&_this$editorEl.focus(),this.restoreSelection();}},{key:"getCleanContent",value:function getCleanContent(){var t=this.editorEl.cloneNode(!0);return t.querySelectorAll("*").forEach(function(t){t.removeAttribute("style");}),t.innerHTML;}},{key:"insertList",value:function insertList(t){if(this.restoreSelection(),!this.lastRange)return;var i=document.createElement(t),s=this.lastRange.extractContents(),e=document.createElement("div");e.appendChild(s),Array.from(e.childNodes).forEach(function(t){var _t$textContent2;if(t.nodeType===Node.TEXT_NODE&&!((_t$textContent2=t.textContent)!==null&&_t$textContent2!==void 0&&_t$textContent2.trim()))return;var s=document.createElement("li");s.appendChild(t),i.appendChild(s);}),this.lastRange.insertNode(i),this.afterListEdit(i);}},{key:"afterListEdit",value:function afterListEdit(t){var i=document.createRange();i.setStartAfter(t),i.collapse(!0);var s=window.getSelection();s!==null&&s!==void 0&&s.removeAllRanges(),s!==null&&s!==void 0&&s.addRange(i),this.saveSelection(),this.updateContent(),this.updateToolbarState();}},{key:"ensureAtLeastOneParagraph",value:function ensureAtLeastOneParagraph(){var _t$textContent3;var t=this.editorEl;if(!t)return;var i=""===((_t$textContent3=t.textContent)!==null&&_t$textContent3!==void 0?_t$textContent3:"").replace(/\u200B/g,"").trim();if(0===t.childNodes.length||i)return void(t.innerHTML="<p><br></p>");if(!t.querySelector("p,h1,h2,h3,h4,h5,h6,ul,ol,table,blockquote,pre")){var _i4=document.createElement("p");for(;t.firstChild;)_i4.appendChild(t.firstChild);return _i4.hasChildNodes()||_i4.appendChild(document.createElement("br")),void t.appendChild(_i4);}t.querySelectorAll("p").forEach(function(t){var _t$textContent4;""===((_t$textContent4=t.textContent)!==null&&_t$textContent4!==void 0?_t$textContent4:"").replace(/\u200B/g,"")&&(t.innerHTML.toLowerCase().includes("<br")||(t.innerHTML="<br>"));});}},{key:"onToolbarCommand",value:function onToolbarCommand(t){switch(this.focusAndRestore(),t){case"bold":c(this.editorEl,"strong");break;case"italic":c(this.editorEl,"em");break;case"underline":c(this.editorEl,"u");break;case"left":r(this.editorEl,"left");break;case"center":r(this.editorEl,"center");break;case"right":r(this.editorEl,"right");break;case"justify":r(this.editorEl,"justify");break;case"ul":m(this.editorEl,"ul"),this.updateContent(),this.updateToolbarState();break;case"ol":m(this.editorEl,"ol"),this.updateContent(),this.updateToolbarState();break;case"link":break;case"clear":var _t3=document.createTreeWalker(this.editorEl,NodeFilter.SHOW_ELEMENT),_i5=[];for(;_t3.nextNode();){var _s4=_t3.currentNode;_s4.removeAttribute("style"),["B","STRONG","I","EM","U","SPAN","FONT"].includes(_s4.tagName)&&_i5.push(_s4);}for(var _i7=0,_i6=_i5;_i7<_i6.length;_i7++){var _t4=_i6[_i7];for(;_t4.firstChild;){var _t4$parentNode;(_t4$parentNode=_t4.parentNode)===null||_t4$parentNode===void 0||_t4$parentNode.insertBefore(_t4.firstChild,_t4);}_t4.remove();}this.ensureAtLeastOneParagraph();}this.updateContent(),this.updateToolbarState();}},{key:"setBtnActive",value:function setBtnActive(t,i){var s=this.buttonMap.get(t);if(s){var _iterator=_createForOfIteratorHelper(s),_step;try{for(_iterator.s();!(_step=_iterator.n()).done;){var _t5=_step.value;_t5.toggleAttribute("data-active",!!i);}}catch(err){_iterator.e(err);}finally{_iterator.f();}}}},{key:"updateToolbarState",value:function updateToolbarState(){var _this4=this,_s$closest;if(!this.editorEl)return;var t=document.getSelection();if(!t||0===t.rangeCount)return;var i=t.getRangeAt(0);if(!this.editorEl.contains(i.commonAncestorContainer))return;var s=h(i.startContainer)||this.editorEl,e=getComputedStyle(s),n=l(i.startContainer,this.editorEl)||this.editorEl,r=function(){var t=s;for(;t&&t!==_this4.editorEl;){if(t instanceof HTMLElement){var _i8=t.tagName.toLowerCase();if("strong"===_i8||"b"===_i8)return!0;var _s5=getComputedStyle(t).fontWeight;if(parseInt(_s5,10)>=600)return!0;}t=t.parentNode;}return!1;}(),o=function(){var t=s;for(;t&&t!==_this4.editorEl;){if(t instanceof HTMLElement){var _i9=t.tagName.toLowerCase();if("em"===_i9||"i"===_i9)return!0;if("italic"===getComputedStyle(t).fontStyle)return!0;}t=t.parentNode;}return!1;}(),c=function(){var t=s;for(;t&&t!==_this4.editorEl;){if(t instanceof HTMLElement){var _i10=getComputedStyle(t).textDecorationLine;if(_i10&&_i10.includes("underline"))return!0;if("u"===t.tagName.toLowerCase())return!0;}t=t.parentNode;}return!1;}(),a=!!s.closest("a"),d=n.style.textAlign||getComputedStyle(n).textAlign||"start",f="start"===d?"left":d,m=!!s.closest("li")&&((_s$closest=s.closest("ul,ol"))===null||_s$closest===void 0?void 0:_s$closest.tagName.toLowerCase())||"";if(this.setBtnActive("bold",r),this.setBtnActive("italic",o),this.setBtnActive("underline",c),this.setBtnActive("link",a),this.linkEl){var _t6=this.linkEl.querySelector("nile-button");_t6&&_t6.toggleAttribute("data-active",a);}if(this.setBtnActive("left","left"===f&&!["center","right","justify"].includes(f)),this.setBtnActive("center","center"===f),this.setBtnActive("right","right"===f),this.setBtnActive("justify","justify"===f),this.setBtnActive("ul","ul"===m),this.setBtnActive("ol","ol"===m),this.headingSelect){var _t7=n.tagName.toLowerCase(),_i11=["h1","h2","h3"].includes(_t7)?_t7:"p";this.headingSelect.value!==_i11&&(this.headingSelect.value=_i11);}if(this.fontSelect){var _t8=(e.fontFamily||"").replace(/["']/g,"").split(",")[0].trim().toLowerCase();if(_t8)for(var _i12=0,_Array$from=Array.from(this.fontSelect.options);_i12<_Array$from.length;_i12++){var _i13=_Array$from[_i12];if(_i13.value.toLowerCase()===_t8){this.fontSelect.value=_i13.value;break;}}}if(this.colorInput){var _t9=u(e.color);_t9&&this.colorInput.value.toLowerCase()!==_t9.toLowerCase()&&(this.colorInput.value=_t9),this.colorSwatchEl&&(this.colorSwatchEl.style.backgroundColor=this.colorInput.value);}if(this.bgColorInput){var _t10=getComputedStyle(s).backgroundColor;if(_t10&&!/transparent|rgba\(\s*0\s*,\s*0\s*,\s*0\s*,\s*0\s*\)/i.test(_t10)){var _i14=u(_t10);_i14&&this.bgColorInput.value.toLowerCase()!==_i14.toLowerCase()&&(this.bgColorInput.value=_i14);}this.bgSwatchEl&&(this.bgSwatchEl.style.backgroundColor=this.bgColorInput.value);}}},{key:"syncPreview",value:function syncPreview(){this.updateContent();}},{key:"getComputedImportantProps",value:function getComputedImportantProps(){var _this$whitelist;return Array.from(new Set([].concat(g,_toConsumableArray((_this$whitelist=this.whitelist)!==null&&_this$whitelist!==void 0?_this$whitelist:[]))));}},{key:"updateContent",value:function updateContent(){var _this$editorEl$textCo;if(!this.editorEl)return;this.ensureAtLeastOneParagraph();var t=""===((_this$editorEl$textCo=this.editorEl.textContent)!==null&&_this$editorEl$textCo!==void 0?_this$editorEl$textCo:"").trim();this.editorEl.classList.toggle("empty",t);var i=this.editorEl.cloneNode(!0);if(this.noStyles)i.querySelectorAll("[style]").forEach(function(t){return t.removeAttribute("style");});else{var _t11=document.createTreeWalker(this.editorEl,NodeFilter.SHOW_ELEMENT),_s6=document.createTreeWalker(i,NodeFilter.SHOW_ELEMENT),_e3=this.getComputedImportantProps();var _loop=function _loop(){var i=_t11.currentNode,n=_s6.currentNode,r=window.getComputedStyle(i),o=_e3.map(function(t){return"".concat(t,":").concat(r.getPropertyValue(t));}).join(";");o.trim()&&n.setAttribute("style",o);};for(;_t11.nextNode()&&_s6.nextNode();){_loop();}}this.content=i.innerHTML,this.previewEl&&(this.previewEl.innerHTML=this.content),this.dispatchEvent(new CustomEvent("nile-change",{detail:{content:this.content},bubbles:!0,composed:!0}));}}]);}(i));t([s({type:String,attribute:!0,reflect:!0})],y.prototype,"value",void 0),t([s({type:Boolean,attribute:!0,reflect:!0})],y.prototype,"noStyles",void 0),t([s({type:Boolean,attribute:!0,reflect:!0})],y.prototype,"disabled",void 0),t([s({type:Boolean,attribute:"singlelineeditor",reflect:!0})],y.prototype,"singleLineEditor",void 0),t([s({type:String})],y.prototype,"placeholder",void 0),t([s({attribute:"mentions",reflect:!0,converter:{fromAttribute:function fromAttribute(t){try{var _i15=JSON.parse(t),_s7={};for(var _i16=0,_Object$keys=Object.keys(_i15);_i16<_Object$keys.length;_i16++){var _t12=_Object$keys[_i16];var _e4=_i15[_t12];Array.isArray(_e4)&&(_s7[_t12]=_e4.filter(function(t){return t&&"string"==typeof t.key&&"string"==typeof t.label;}).map(function(t){return{key:t.key,label:t.label};}));}return _s7;}catch(_unused){return{};}},toAttribute:function toAttribute(t){return JSON.stringify(t);}}})],y.prototype,"mentions",void 0),t([s({attribute:"whitelist",reflect:!1,converter:{fromAttribute:function fromAttribute(t){try{var _i17=JSON.parse(t);return Array.isArray(_i17)?_i17.filter(function(t){return"string"==typeof t;}):[];}catch(_unused2){return[];}}}})],y.prototype,"whitelist",void 0),t([e()],y.prototype,"content",void 0),_export("N",y=t([n("nile-rich-text-editor")],y));}};});
2
2
  //# sourceMappingURL=nile-rich-text-editor.cjs.js.map