@aquera/nile-elements 0.1.64-beta-1.2 → 0.1.65-beta-1.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 (38) hide show
  1. package/demo/index.html +29 -109
  2. package/dist/index.js +608 -547
  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 +45 -2
  8. package/dist/nile-rich-text-editor/nile-rich-text-editor.esm.js +1 -1
  9. package/dist/nile-rich-text-editor/nile-rte-mentions.cjs.js +1 -1
  10. package/dist/nile-rich-text-editor/nile-rte-mentions.cjs.js.map +1 -1
  11. package/dist/nile-rich-text-editor/nile-rte-mentions.esm.js +1 -1
  12. package/dist/nile-rich-text-editor/nile-rte-select.cjs.js +1 -1
  13. package/dist/nile-rich-text-editor/nile-rte-select.cjs.js.map +1 -1
  14. package/dist/nile-rich-text-editor/nile-rte-select.esm.js +31 -13
  15. package/dist/nile-rich-text-editor/utils.cjs.js +1 -1
  16. package/dist/nile-rich-text-editor/utils.cjs.js.map +1 -1
  17. package/dist/nile-rich-text-editor/utils.esm.js +1 -1
  18. package/dist/src/nile-rich-text-editor/nile-rich-text-editor.css.js +43 -0
  19. package/dist/src/nile-rich-text-editor/nile-rich-text-editor.css.js.map +1 -1
  20. package/dist/src/nile-rich-text-editor/nile-rich-text-editor.d.ts +3 -0
  21. package/dist/src/nile-rich-text-editor/nile-rich-text-editor.js +81 -22
  22. package/dist/src/nile-rich-text-editor/nile-rich-text-editor.js.map +1 -1
  23. package/dist/src/nile-rich-text-editor/nile-rte-mentions.js +5 -0
  24. package/dist/src/nile-rich-text-editor/nile-rte-mentions.js.map +1 -1
  25. package/dist/src/nile-rich-text-editor/nile-rte-select.d.ts +15 -1
  26. package/dist/src/nile-rich-text-editor/nile-rte-select.js +85 -52
  27. package/dist/src/nile-rich-text-editor/nile-rte-select.js.map +1 -1
  28. package/dist/src/nile-rich-text-editor/utils.d.ts +1 -0
  29. package/dist/src/nile-rich-text-editor/utils.js +17 -0
  30. package/dist/src/nile-rich-text-editor/utils.js.map +1 -1
  31. package/dist/tsconfig.tsbuildinfo +1 -1
  32. package/package.json +1 -1
  33. package/src/nile-rich-text-editor/nile-rich-text-editor.css.ts +43 -0
  34. package/src/nile-rich-text-editor/nile-rich-text-editor.ts +112 -40
  35. package/src/nile-rich-text-editor/nile-rte-mentions.ts +5 -0
  36. package/src/nile-rich-text-editor/nile-rte-select.ts +97 -58
  37. package/src/nile-rich-text-editor/utils.ts +18 -0
  38. package/vscode-html-custom-data.json +3 -3
@@ -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","./utils.cjs.js","./nile-rich-text-editor.css.cjs.js"],function(_export,_context){"use strict";var t,i,e,s,n,r,o,h,l,c,a,u,f,d,m,p,b;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(_n3){function n(){return _n3.apply(this,arguments);}n.toString=function(){return _n3.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){e=_litDecoratorsJs.property;s=_litDecoratorsJs.state;n=_litDecoratorsJs.customElement;},function(_nileRteToolbarCjsJs){},function(_nileRteToolbarItemCjsJs){},function(_nileRteSelectCjsJs){},function(_nileRteColorCjsJs){},function(_nileRteDividerCjsJs){},function(_nileRtePreviewCjsJs){},function(_nileRteMentionsCjsJs){},function(_utilsCjsJs){r=_utilsCjsJs.s;o=_utilsCjsJs.a;h=_utilsCjsJs.b;l=_utilsCjsJs.c;c=_utilsCjsJs.i;a=_utilsCjsJs.t;u=_utilsCjsJs.n;f=_utilsCjsJs.d;d=_utilsCjsJs.r;},function(_nileRichTextEditorCssCjsJs){m=_nileRichTextEditorCssCjsJs.s;}],execute:function execute(){p={bold:"nile-bold",italic:"nile-italic",underline:"nile-underline",link:"user",left:"nile-leftalign",center:"nile-centeralign",right:"nile-rightalign",justify:"nile-justify",ul:"nile-ul",ol:"nile-ol",clear:"error"};_export("N",b=/*#__PURE__*/function(_i){function b(){var _this;_classCallCheck(this,b);_this=_callSuper(this,b,arguments),_this.value="",_this.mentions={},_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.mentionsEl=null,_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(b,_i);return _createClass(b,[{key:"createRenderRoot",value:function createRenderRoot(){return this;}},{key:"shouldUpdate",value:function shouldUpdate(){return!1;}},{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(b,"connectedCallback",this,3)([]),this.injectCss(m.cssText),this.toolbarEl=this.querySelector("nile-rte-toolbar"),this.previewEl=this.querySelector("nile-rte-preview"),this.ensureEditor(),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(),this.updateToolbarState(),this.syncPreview(),document.addEventListener("selectionchange",this.onSelectionChange,!0);}},{key:"disconnectedCallback",value:function disconnectedCallback(){document.removeEventListener("selectionchange",this.onSelectionChange,!0),this.mentionsEl&&this.mentionsEl.detach&&this.mentionsEl.detach(),_superPropGet(b,"disconnectedCallback",this,3)([]);}},{key:"ensureEditor",value:function ensureEditor(){if(this.editorEl=this.querySelector(".editor"),!this.editorEl){var _this$toolbarEl;var _t=document.createElement("div");_t.className="editor",_t.setAttribute("contenteditable","true"),(_this$toolbarEl=this.toolbarEl)!==null&&_this$toolbarEl!==void 0&&_this$toolbarEl.nextSibling?this.insertBefore(_t,this.toolbarEl.nextSibling):this.previewEl?this.insertBefore(_t,this.previewEl):this.appendChild(_t),this.editorEl=_t;}this.editorEl.innerHTML.trim()||(this.editorEl.innerHTML="<p><br></p>"),this.ensureAtLeastOneParagraph();}},{key:"wireEditor",value:function wireEditor(){var _this2=this;this.editorEl.addEventListener("input",function(){_this2.ensureAtLeastOneParagraph(),_this2.updateContent();}),this.editorEl.addEventListener("mouseup",function(){return _this2.saveSelection();}),this.editorEl.addEventListener("keyup",function(){return _this2.saveSelection();});}},{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")){if("nile-rte-toolbar-item"===i){var _this3$buttonMap$get;var _i2=t.querySelector(":scope > nile-button");var _e=t.getAttribute("name")||"",_s=t.getAttribute("label")||_e,_n=t.getAttribute("icon"),_r=t.innerHTML.trim().length>0;if(_i2||(_i2=document.createElement("nile-button"),_i2.variant="tertiary",_i2.size="small"),_n)_i2.innerHTML="<nile-icon name=\"".concat(_n,"\" aria-label=\"").concat(_s,"\"></nile-icon>"),t.innerHTML="";else if(_r)_i2.innerHTML=t.innerHTML,t.innerHTML="";else{var _n2=p[_e];_n2?_i2.innerHTML="<nile-icon name=\"".concat(_n2,"\" size=\"20\" color=\"black\" aria-label=\"").concat(_s,"\"></nile-icon>"):_i2.textContent=_s||_e,t.innerHTML="";}_i2.isConnected||t.appendChild(_i2),_i2.setAttribute("aria-label",_s),_i2.addEventListener("mousedown",function(t){return t.preventDefault();}),_i2.addEventListener("click",function(){return _this3.onToolbarCommand(_e);});var _o=(_this3$buttonMap$get=_this3.buttonMap.get(_e))!==null&&_this3$buttonMap$get!==void 0?_this3$buttonMap$get:[];return _o.push(_i2),void _this3.buttonMap.set(_e,_o);}if("nile-rte-select"!==i){if("nile-rte-color"===i){var _t$getAttribute,_t$getAttribute2;var _i3=(_t$getAttribute=t.getAttribute("label"))!==null&&_t$getAttribute!==void 0?_t$getAttribute:"Text color",_e2=(_t$getAttribute2=t.getAttribute("value"))!==null&&_t$getAttribute2!==void 0?_t$getAttribute2:"#000000";var _s2=t.querySelector(':scope > input[type="color"]');_s2||(_s2=document.createElement("input"),_s2.type="color",t.appendChild(_s2)),_s2.title=_i3,_s2.value=_e2,_s2.addEventListener("mousedown",function(t){return t.preventDefault();}),_s2.addEventListener("input",function(){_this3.focusAndRestore(),l(_this3.editorEl,_s2.value),_this3.updateContent(),_this3.updateToolbarState();}),_this3.colorInput=_s2;}}else{var _i4=t.getAttribute("type")||"";t.addEventListener("change",function(t){_this3.focusAndRestore();var e=t.detail;"heading"===_i4?o(_this3.editorEl,e):"font"===_i4&&h(_this3.editorEl,e),_this3.updateContent(),_this3.updateToolbarState();});}}else t.addEventListener("change",function(t){_this3.focusAndRestore();var i=t.detail;r(_this3.editorEl,i),_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:"insertList",value:function insertList(t){if(this.restoreSelection(),!this.lastRange)return;var i=document.createElement(t),e=this.lastRange.extractContents(),s=document.createElement("div");s.appendChild(e),Array.from(s.childNodes).forEach(function(t){var _t$textContent;if(t.nodeType===Node.TEXT_NODE&&!((_t$textContent=t.textContent)!==null&&_t$textContent!==void 0&&_t$textContent.trim()))return;var e=document.createElement("li");e.appendChild(t),i.appendChild(e);}),this.lastRange.insertNode(i),this.afterListEdit(i);}},{key:"afterListEdit",value:function afterListEdit(t){var i=document.createRange();i.setStartAfter(t),i.collapse(!0);var e=window.getSelection();e!==null&&e!==void 0&&e.removeAllRanges(),e!==null&&e!==void 0&&e.addRange(i),this.saveSelection(),this.updateContent(),this.updateToolbarState();}},{key:"ensureAtLeastOneParagraph",value:function ensureAtLeastOneParagraph(){var _t$textContent2;var t=this.editorEl;if(!t)return;var i=""===((_t$textContent2=t.textContent)!==null&&_t$textContent2!==void 0?_t$textContent2:"").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 _i5=document.createElement("p");for(;t.firstChild;)_i5.appendChild(t.firstChild);return _i5.hasChildNodes()||_i5.appendChild(document.createElement("br")),void t.appendChild(_i5);}t.querySelectorAll("p").forEach(function(t){var _t$textContent3;""===((_t$textContent3=t.textContent)!==null&&_t$textContent3!==void 0?_t$textContent3:"").replace(/\u200B/g,"")&&(t.innerHTML.toLowerCase().includes("<br")||(t.innerHTML="<br>"));});}},{key:"onToolbarCommand",value:function onToolbarCommand(t){switch(this.focusAndRestore(),t){case"bold":a(this.editorEl,"strong");break;case"italic":a(this.editorEl,"em");break;case"underline":a(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":this.insertList("ul");break;case"ol":this.insertList("ol");break;case"link":c(this.editorEl);break;case"clear":var _t2=document.createTreeWalker(this.editorEl,NodeFilter.SHOW_ELEMENT),_i6=[];for(;_t2.nextNode();){var _e3=_t2.currentNode;_e3.removeAttribute("style"),["B","STRONG","I","EM","U","SPAN","FONT"].includes(_e3.tagName)&&_i6.push(_e3);}for(var _i8=0,_i7=_i6;_i8<_i7.length;_i8++){var _t3=_i7[_i8];for(;_t3.firstChild;){var _t3$parentNode;(_t3$parentNode=_t3.parentNode)===null||_t3$parentNode===void 0||_t3$parentNode.insertBefore(_t3.firstChild,_t3);}_t3.remove();}this.ensureAtLeastOneParagraph();}this.updateContent(),this.updateToolbarState();}},{key:"setBtnActive",value:function setBtnActive(t,i){var e=this.buttonMap.get(t);if(e){var _iterator=_createForOfIteratorHelper(e),_step;try{for(_iterator.s();!(_step=_iterator.n()).done;){var _t4=_step.value;_t4.toggleAttribute("data-active",!!i);}}catch(err){_iterator.e(err);}finally{_iterator.f();}}}},{key:"updateToolbarState",value:function updateToolbarState(){var _this4=this,_e$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 e=u(i.startContainer)||this.editorEl,s=getComputedStyle(e),n=f(i.startContainer,this.editorEl)||this.editorEl,r=function(){var t=e;for(;t&&t!==_this4.editorEl;){if(t instanceof HTMLElement){var _i9=t.tagName.toLowerCase();if("strong"===_i9||"b"===_i9)return!0;var _e4=getComputedStyle(t).fontWeight;if(parseInt(_e4,10)>=600)return!0;}t=t.parentNode;}return!1;}(),o=function(){var t=e;for(;t&&t!==_this4.editorEl;){if(t instanceof HTMLElement){var _i10=t.tagName.toLowerCase();if("em"===_i10||"i"===_i10)return!0;if("italic"===getComputedStyle(t).fontStyle)return!0;}t=t.parentNode;}return!1;}(),h=function(){var t=e;for(;t&&t!==_this4.editorEl;){if(t instanceof HTMLElement){var _i11=getComputedStyle(t).textDecorationLine;if(_i11&&_i11.includes("underline"))return!0;if("u"===t.tagName.toLowerCase())return!0;}t=t.parentNode;}return!1;}(),l=!!e.closest("a"),c=n.style.textAlign||getComputedStyle(n).textAlign||"start",a="start"===c?"left":c,m=!!e.closest("li")&&((_e$closest=e.closest("ul,ol"))===null||_e$closest===void 0?void 0:_e$closest.tagName.toLowerCase())||"";if(this.setBtnActive("bold",r),this.setBtnActive("italic",o),this.setBtnActive("underline",h),this.setBtnActive("link",l),this.setBtnActive("left","left"===a&&!["center","right","justify"].includes(a)),this.setBtnActive("center","center"===a),this.setBtnActive("right","right"===a),this.setBtnActive("justify","justify"===a),this.setBtnActive("ul","ul"===m),this.setBtnActive("ol","ol"===m),this.headingSelect){var _t5=n.tagName.toLowerCase(),_i12=["h1","h2","h3"].includes(_t5)?_t5:"p";this.headingSelect.value!==_i12&&(this.headingSelect.value=_i12);}if(this.fontSelect){var _t6=(s.fontFamily||"").replace(/["']/g,"").split(",")[0].trim().toLowerCase();if(_t6)for(var _i13=0,_Array$from=Array.from(this.fontSelect.options);_i13<_Array$from.length;_i13++){var _i14=_Array$from[_i13];if(_i14.value.toLowerCase()===_t6){this.fontSelect.value=_i14.value;break;}}}if(this.colorInput){var _t7=d(s.color);_t7&&this.colorInput.value.toLowerCase()!==_t7.toLowerCase()&&(this.colorInput.value=_t7);}}},{key:"syncPreview",value:function syncPreview(){this.updateContent();}},{key:"updateContent",value:function updateContent(){this.editorEl&&(this.ensureAtLeastOneParagraph(),this.content=this.editorEl.innerHTML,this.previewEl&&(this.previewEl.innerHTML=this.content),this.dispatchEvent(new CustomEvent("content-changed",{detail:{content:this.content},bubbles:!0,composed:!0})));}}]);}(i));t([e({type:String})],b.prototype,"value",void 0),t([e({attribute:"mentions",converter:{fromAttribute:function fromAttribute(t){try{var _i15=JSON.parse(t),_e5={};for(var _i16=0,_Object$keys=Object.keys(_i15);_i16<_Object$keys.length;_i16++){var _t8=_Object$keys[_i16];var _s3=_i15[_t8];Array.isArray(_s3)&&(_e5[_t8]=_s3.filter(function(t){return t&&"string"==typeof t.key&&"string"==typeof t.label;}).map(function(t){return{key:t.key,label:t.label};}));}return _e5;}catch(_unused){return{};}},toAttribute:function toAttribute(t){return JSON.stringify(t);}}})],b.prototype,"mentions",void 0),t([s()],b.prototype,"content",void 0),_export("N",b=t([n("nile-rich-text-editor")],b));}};});
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","./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,p,m,b,g;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(_utilsCjsJs){r=_utilsCjsJs.s;o=_utilsCjsJs.a;h=_utilsCjsJs.b;l=_utilsCjsJs.c;c=_utilsCjsJs.d;a=_utilsCjsJs.i;u=_utilsCjsJs.t;d=_utilsCjsJs.n;f=_utilsCjsJs.e;p=_utilsCjsJs.r;},function(_nileRichTextEditorCssCjsJs){m=_nileRichTextEditorCssCjsJs.s;}],execute:function execute(){b={bold:"nile-bold",italic:"nile-italic",underline:"nile-underline",link:"user",left:"nile-leftalign",center:"nile-centeralign",right:"nile-rightalign",justify:"nile-justify",ul:"nile-ul",ol:"nile-ol",clear:"error"};_export("N",g=/*#__PURE__*/function(_i){function g(){var _this;_classCallCheck(this,g);_this=_callSuper(this,g,arguments),_this.value="",_this.mentions={},_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.mentionsEl=null,_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(g,_i);return _createClass(g,[{key:"createRenderRoot",value:function createRenderRoot(){return this;}},{key:"shouldUpdate",value:function shouldUpdate(){return!1;}},{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(g,"connectedCallback",this,3)([]),this.injectCss(m.cssText),this.toolbarEl=this.querySelector("nile-rte-toolbar"),this.previewEl=this.querySelector("nile-rte-preview"),this.ensureEditor(),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(),this.updateToolbarState(),this.syncPreview(),document.addEventListener("selectionchange",this.onSelectionChange,!0);}},{key:"disconnectedCallback",value:function disconnectedCallback(){document.removeEventListener("selectionchange",this.onSelectionChange,!0),this.mentionsEl&&this.mentionsEl.detach&&this.mentionsEl.detach(),_superPropGet(g,"disconnectedCallback",this,3)([]);}},{key:"ensureEditor",value:function ensureEditor(){if(this.editorEl=this.querySelector(".editor"),!this.editorEl){var _this$toolbarEl;var _t=document.createElement("div");_t.className="editor",_t.setAttribute("contenteditable","true"),(_this$toolbarEl=this.toolbarEl)!==null&&_this$toolbarEl!==void 0&&_this$toolbarEl.nextSibling?this.insertBefore(_t,this.toolbarEl.nextSibling):this.previewEl?this.insertBefore(_t,this.previewEl):this.appendChild(_t),this.editorEl=_t;}this.editorEl.innerHTML.trim()||(this.editorEl.innerHTML="<p><br></p>"),this.ensureAtLeastOneParagraph();}},{key:"wireEditor",value:function wireEditor(){var _this2=this;this.editorEl.addEventListener("input",function(){_this2.ensureAtLeastOneParagraph(),_this2.updateContent();}),this.editorEl.addEventListener("mouseup",function(){return _this2.saveSelection();}),this.editorEl.addEventListener("keyup",function(){return _this2.saveSelection();});}},{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")){if("nile-rte-toolbar-item"===i){var _this3$buttonMap$get;var _i2=t.querySelector(":scope > nile-button");var _s=t.getAttribute("name")||"",_e=t.getAttribute("label")||_s,_n=t.getAttribute("icon"),_r=t.innerHTML.trim().length>0;if(_i2||(_i2=document.createElement("nile-button"),_i2.variant="tertiary",_i2.size="small"),_n)_i2.innerHTML="<nile-icon name=\"".concat(_n,"\" aria-label=\"").concat(_e,"\"></nile-icon>"),t.innerHTML="";else if(_r)_i2.innerHTML=t.innerHTML,t.innerHTML="";else{var _n2=b[_s];_n2?_i2.innerHTML="<nile-icon name=\"".concat(_n2,"\" size=\"20\" color=\"black\" aria-label=\"").concat(_e,"\"></nile-icon>"):_i2.textContent=_e||_s,t.innerHTML="";}_i2.isConnected||t.appendChild(_i2),_i2.setAttribute("aria-label",_e),_i2.addEventListener("mousedown",function(t){return t.preventDefault();}),_i2.addEventListener("click",function(){return _this3.onToolbarCommand(_s);});var _o=(_this3$buttonMap$get=_this3.buttonMap.get(_s))!==null&&_this3$buttonMap$get!==void 0?_this3$buttonMap$get:[];return _o.push(_i2),void _this3.buttonMap.set(_s,_o);}if("nile-rte-select"!==i){if("nile-rte-color"===i){var _t$getAttribute,_t$getAttribute2,_t$getAttribute3;var _i3=(_t$getAttribute=t.getAttribute("label"))!==null&&_t$getAttribute!==void 0?_t$getAttribute:"Text color",_s2=(_t$getAttribute2=t.getAttribute("value"))!==null&&_t$getAttribute2!==void 0?_t$getAttribute2:"#000000",_e2=(_t$getAttribute3=t.getAttribute("mode"))!==null&&_t$getAttribute3!==void 0?_t$getAttribute3:"text";var _n3=t.querySelector(':scope > input[type="color"]');_n3||(_n3=document.createElement("input"),_n3.type="color",_n3.style.position="absolute",_n3.style.opacity="0",_n3.style.pointerEvents="none",t.appendChild(_n3)),_n3.title=_i3,_n3.value=_s2;var _r2=t.querySelector(":scope > button.rte-color-trigger");_r2||(_r2=document.createElement("button"),_r2.type="button",_r2.className="rte-color-trigger",_r2.setAttribute("aria-label",_i3),_r2.innerHTML="background"===_e2?'\n <span class="swatch-box" aria-hidden="true"></span>\n ':'\n <span class="glyph-stack" aria-hidden="true">\n <span class="glyph">A</span>\n <span class="underline"></span>\n </span>\n ',t.appendChild(_r2));var _o2=_r2.querySelector(".underline"),_h=_r2.querySelector(".swatch-box");"background"===_e2?(_this3.bgColorInput=_n3,_this3.bgSwatchEl=_h,_this3.bgSwatchEl&&(_this3.bgSwatchEl.style.backgroundColor=_n3.value)):(_this3.colorInput=_n3,_this3.colorSwatchEl=_o2,_this3.colorSwatchEl&&(_this3.colorSwatchEl.style.backgroundColor=_n3.value)),_r2.addEventListener("click",function(t){t.preventDefault(),_this3.focusAndRestore(),_n3.click();}),_n3.addEventListener("input",function(){_this3.focusAndRestore(),"background"===_e2?(l(_this3.editorEl,_n3.value),_this3.bgSwatchEl&&(_this3.bgSwatchEl.style.backgroundColor=_n3.value)):(c(_this3.editorEl,_n3.value),_this3.colorSwatchEl&&(_this3.colorSwatchEl.style.backgroundColor=_n3.value)),_this3.updateContent(),_this3.updateToolbarState();}),_r2.addEventListener("mousedown",function(t){return t.preventDefault();}),_n3.addEventListener("mousedown",function(t){return t.preventDefault();});}}else{var _i4=t.getAttribute("type")||"";t.addEventListener("change",function(t){_this3.focusAndRestore();var s=t.detail;"heading"===_i4?o(_this3.editorEl,s):"font"===_i4&&h(_this3.editorEl,s),_this3.updateContent(),_this3.updateToolbarState();});}}else t.addEventListener("change",function(t){_this3.focusAndRestore();var i=t.detail;r(_this3.editorEl,i),_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:"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$textContent;if(t.nodeType===Node.TEXT_NODE&&!((_t$textContent=t.textContent)!==null&&_t$textContent!==void 0&&_t$textContent.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$textContent2;var t=this.editorEl;if(!t)return;var i=""===((_t$textContent2=t.textContent)!==null&&_t$textContent2!==void 0?_t$textContent2:"").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 _i5=document.createElement("p");for(;t.firstChild;)_i5.appendChild(t.firstChild);return _i5.hasChildNodes()||_i5.appendChild(document.createElement("br")),void t.appendChild(_i5);}t.querySelectorAll("p").forEach(function(t){var _t$textContent3;""===((_t$textContent3=t.textContent)!==null&&_t$textContent3!==void 0?_t$textContent3:"").replace(/\u200B/g,"")&&(t.innerHTML.toLowerCase().includes("<br")||(t.innerHTML="<br>"));});}},{key:"onToolbarCommand",value:function onToolbarCommand(t){switch(this.focusAndRestore(),t){case"bold":u(this.editorEl,"strong");break;case"italic":u(this.editorEl,"em");break;case"underline":u(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":this.insertList("ul");break;case"ol":this.insertList("ol");break;case"link":a(this.editorEl);break;case"clear":var _t2=document.createTreeWalker(this.editorEl,NodeFilter.SHOW_ELEMENT),_i6=[];for(;_t2.nextNode();){var _s3=_t2.currentNode;_s3.removeAttribute("style"),["B","STRONG","I","EM","U","SPAN","FONT"].includes(_s3.tagName)&&_i6.push(_s3);}for(var _i8=0,_i7=_i6;_i8<_i7.length;_i8++){var _t3=_i7[_i8];for(;_t3.firstChild;){var _t3$parentNode;(_t3$parentNode=_t3.parentNode)===null||_t3$parentNode===void 0||_t3$parentNode.insertBefore(_t3.firstChild,_t3);}_t3.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 _t4=_step.value;_t4.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=d(i.startContainer)||this.editorEl,e=getComputedStyle(s),n=f(i.startContainer,this.editorEl)||this.editorEl,r=function(){var t=s;for(;t&&t!==_this4.editorEl;){if(t instanceof HTMLElement){var _i9=t.tagName.toLowerCase();if("strong"===_i9||"b"===_i9)return!0;var _s4=getComputedStyle(t).fontWeight;if(parseInt(_s4,10)>=600)return!0;}t=t.parentNode;}return!1;}(),o=function(){var t=s;for(;t&&t!==_this4.editorEl;){if(t instanceof HTMLElement){var _i10=t.tagName.toLowerCase();if("em"===_i10||"i"===_i10)return!0;if("italic"===getComputedStyle(t).fontStyle)return!0;}t=t.parentNode;}return!1;}(),h=function(){var t=s;for(;t&&t!==_this4.editorEl;){if(t instanceof HTMLElement){var _i11=getComputedStyle(t).textDecorationLine;if(_i11&&_i11.includes("underline"))return!0;if("u"===t.tagName.toLowerCase())return!0;}t=t.parentNode;}return!1;}(),l=!!s.closest("a"),c=n.style.textAlign||getComputedStyle(n).textAlign||"start",a="start"===c?"left":c,u=!!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",h),this.setBtnActive("link",l),this.setBtnActive("left","left"===a&&!["center","right","justify"].includes(a)),this.setBtnActive("center","center"===a),this.setBtnActive("right","right"===a),this.setBtnActive("justify","justify"===a),this.setBtnActive("ul","ul"===u),this.setBtnActive("ol","ol"===u),this.headingSelect){var _t5=n.tagName.toLowerCase(),_i12=["h1","h2","h3"].includes(_t5)?_t5:"p";this.headingSelect.value!==_i12&&(this.headingSelect.value=_i12);}if(this.fontSelect){var _t6=(e.fontFamily||"").replace(/["']/g,"").split(",")[0].trim().toLowerCase();if(_t6)for(var _i13=0,_Array$from=Array.from(this.fontSelect.options);_i13<_Array$from.length;_i13++){var _i14=_Array$from[_i13];if(_i14.value.toLowerCase()===_t6){this.fontSelect.value=_i14.value;break;}}}if(this.colorInput){var _t7=p(e.color);_t7&&this.colorInput.value.toLowerCase()!==_t7.toLowerCase()&&(this.colorInput.value=_t7),this.colorSwatchEl&&(this.colorSwatchEl.style.backgroundColor=this.colorInput.value);}if(this.bgColorInput){var _t8=getComputedStyle(s).backgroundColor;if(_t8&&!/transparent|rgba\(\s*0\s*,\s*0\s*,\s*0\s*,\s*0\s*\)/i.test(_t8)){var _i15=p(_t8);_i15&&this.bgColorInput.value.toLowerCase()!==_i15.toLowerCase()&&(this.bgColorInput.value=_i15);}this.bgSwatchEl&&(this.bgSwatchEl.style.backgroundColor=this.bgColorInput.value);}}},{key:"syncPreview",value:function syncPreview(){this.updateContent();}},{key:"updateContent",value:function updateContent(){this.editorEl&&(this.ensureAtLeastOneParagraph(),this.content=this.editorEl.innerHTML,this.previewEl&&(this.previewEl.innerHTML=this.content),this.dispatchEvent(new CustomEvent("content-changed",{detail:{content:this.content},bubbles:!0,composed:!0})));}}]);}(i));t([s({type:String})],g.prototype,"value",void 0),t([s({attribute:"mentions",converter:{fromAttribute:function fromAttribute(t){try{var _i16=JSON.parse(t),_s5={};for(var _i17=0,_Object$keys=Object.keys(_i16);_i17<_Object$keys.length;_i17++){var _t9=_Object$keys[_i17];var _e3=_i16[_t9];Array.isArray(_e3)&&(_s5[_t9]=_e3.filter(function(t){return t&&"string"==typeof t.key&&"string"==typeof t.label;}).map(function(t){return{key:t.key,label:t.label};}));}return _s5;}catch(_unused){return{};}},toAttribute:function toAttribute(t){return JSON.stringify(t);}}})],g.prototype,"mentions",void 0),t([e()],g.prototype,"content",void 0),_export("N",g=t([n("nile-rich-text-editor")],g));}};});
2
2
  //# sourceMappingURL=nile-rich-text-editor.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"nile-rich-text-editor.cjs.js","sources":["../../../src/nile-rich-text-editor/nile-rich-text-editor.ts"],"sourcesContent":["// nile-rich-text-editor.ts\nimport { LitElement } from 'lit';\nimport { customElement, property, state } from 'lit/decorators.js';\n\nimport './nile-rte-toolbar';\nimport './nile-rte-toolbar-item';\nimport './nile-rte-select';\nimport './nile-rte-color';\nimport './nile-rte-divider';\nimport './nile-rte-preview';\nimport './nile-rte-mentions';\n\nimport {\n closestBlock, nearestElement, rgbToHex,\n toggleInlineTag, setBlockTag, setAlignment,\n setFontFamily, setForeColor, insertOrEditLink\n} from './utils';\n\nimport {styles} from './nile-rich-text-editor.css'; \n\ntype MentionsConfig = Record<string, { key: string; label: string }[]>;\n\n/**\n * Map commands → default icon names from your <nile-icon> set.\n * Adjust values to match the real names you have.\n */\nconst DEFAULT_ICONS: Record<string, string> = {\n bold: 'nile-bold',\n italic: 'nile-italic',\n underline: 'nile-underline',\n link: 'user',\n left: 'nile-leftalign',\n center: 'nile-centeralign',\n right: 'nile-rightalign',\n justify: 'nile-justify',\n ul: 'nile-ul',\n ol: 'nile-ol',\n clear: 'error',\n};\n\n@customElement('nile-rich-text-editor')\nexport class NileRichTextEditor extends LitElement {\n protected createRenderRoot() { return this; } \n protected shouldUpdate() { return false; } \n\n /** Initial HTML content */\n @property({ type: String }) value = '';\n\n /** Optional mentions config (can also be on <nile-rte-mentions mentions=\"...\">) */\n @property({\n attribute: 'mentions',\n converter: {\n fromAttribute: (value: string): MentionsConfig => {\n try {\n const parsed = JSON.parse(value);\n const out: MentionsConfig = {};\n for (const trig of Object.keys(parsed)) {\n const arr = parsed[trig];\n if (Array.isArray(arr)) {\n out[trig] = arr\n .filter(i => i && typeof i.key === 'string' && typeof i.label === 'string')\n .map(i => ({ key: i.key, label: i.label }));\n }\n }\n return out;\n } catch { return {}; }\n },\n toAttribute: (v: MentionsConfig) => JSON.stringify(v),\n }\n })\n mentions: MentionsConfig = {};\n\n // ----- internal state (no Lit render) -----\n @state() private content = '';\n private editorEl!: HTMLElement;\n private previewEl: HTMLElement | null = null;\n private toolbarEl: HTMLElement | null = null;\n\n private lastRange: Range | null = null;\n\n // map for button active reflections\n private buttonMap = new Map<string, HTMLElement[]>();\n private headingSelect: HTMLSelectElement | null = null;\n private fontSelect: HTMLSelectElement | null = null;\n private colorInput: HTMLInputElement | null = null;\n\n // Mentions controller (child)\n private mentionsEl: HTMLElement | null = null;\n\n \n\n private injectCss(cssText: string) {\n if (this.querySelector('style[data-rte-style]')) return;\n const style = document.createElement('style');\n style.setAttribute('data-rte-style', 'true');\n style.textContent = cssText;\n this.insertBefore(style, this.firstChild);\n }\n\n connectedCallback(): void {\n super.connectedCallback();\n\n // 1) Inject styles once (so authored DOM stays as-is)\n this.injectCss(styles.cssText); \n \n\n // 2) Keep authored nodes\n this.toolbarEl = this.querySelector('nile-rte-toolbar');\n this.previewEl = this.querySelector('nile-rte-preview');\n\n // 3) Ensure there is an editor element; create if missing.\n this.ensureEditor();\n\n // 4) Fill initial content\n if (this.value && !this.editorEl.innerHTML.trim()) {\n this.editorEl.innerHTML = this.value;\n }\n this.content = this.editorEl.innerHTML;\n\n // 5) Wire toolbar authored children directly\n if (this.toolbarEl) this.wireAuthoredToolbar(this.toolbarEl);\n\n // 6) Mentions: delegate to child controller\n this.mentionsEl = this.querySelector('nile-rte-mentions');\n if (this.mentionsEl) {\n \n (this.mentionsEl as any).attach?.(this.editorEl, this as HTMLElement);\n \n (this.mentionsEl as any).setExternalConfig?.(this.mentions);\n }\n\n \n this.wireEditor();\n\n \n this.updateToolbarState();\n this.syncPreview();\n\n \n document.addEventListener('selectionchange', this.onSelectionChange, true);\n }\n\n disconnectedCallback(): void {\n document.removeEventListener('selectionchange', this.onSelectionChange, true);\n // Optionally tell mentions to cleanup\n if (this.mentionsEl && (this.mentionsEl as any).detach) {\n (this.mentionsEl as any).detach();\n }\n super.disconnectedCallback();\n }\n\n \n \n\n private ensureEditor() {\n this.editorEl = this.querySelector('.editor') as HTMLElement;\n if (!this.editorEl) {\n const editor = document.createElement('div');\n editor.className = 'editor';\n editor.setAttribute('contenteditable','true');\n if (this.toolbarEl?.nextSibling) {\n this.insertBefore(editor, this.toolbarEl.nextSibling);\n } else if (this.previewEl) {\n this.insertBefore(editor, this.previewEl);\n } else {\n this.appendChild(editor);\n }\n this.editorEl = editor;\n }\n // **NEW**: seed an empty paragraph so setBlockTag() has something to swap\n if (!this.editorEl.innerHTML.trim()) {\n this.editorEl.innerHTML = '<p><br></p>';\n }\n this.ensureAtLeastOneParagraph();\n }\n\n private wireEditor() {\n // Input & selection preservation\n this.editorEl.addEventListener('input', () => { \n this.ensureAtLeastOneParagraph();\n this.updateContent();\n });\n this.editorEl.addEventListener('mouseup', () => this.saveSelection());\n this.editorEl.addEventListener('keyup', () => this.saveSelection()); // keep range fresh for toolbar\n }\n\n private wireAuthoredToolbar(tb: HTMLElement) {\n // Clear previous map\n this.buttonMap.clear();\n this.headingSelect = null;\n this.fontSelect = null;\n this.colorInput = null;\n\n // Process children\n Array.from(tb.children).forEach(child => {\n const tag = child.tagName.toLowerCase();\n\n if (tag === 'nile-rte-select' && child.getAttribute('type') === 'align') {\n child.addEventListener('change', (e: any) => {\n this.focusAndRestore();\n const alignment = e.detail as 'left'|'center'|'right'|'justify';\n setAlignment(this.editorEl, alignment);\n this.updateContent();\n this.updateToolbarState();\n });\n return;\n }\n \n\n if (tag === 'nile-rte-toolbar-item') {\n // Look for an authored <nile-button> (so authors can override)\n let btn = child.querySelector(':scope > nile-button') as HTMLElement | null;\n \n const cmd = child.getAttribute('name') || '';\n const label = child.getAttribute('label') || cmd;\n const iconAttr = child.getAttribute('icon');\n const authoredHasContent = child.innerHTML.trim().length > 0;\n \n // If none, create one\n if (!btn) {\n btn = document.createElement('nile-button');\n (btn as any).variant = 'tertiary';\n (btn as any).size = 'small'; // optional\n }\n \n // Fill visual content\n if (iconAttr) {\n btn.innerHTML = `<nile-icon name=\"${iconAttr}\" aria-label=\"${label}\"></nile-icon>`;\n child.innerHTML = '';\n } else if (!authoredHasContent) {\n const defaultIcon = DEFAULT_ICONS[cmd];\n if (defaultIcon) {\n btn.innerHTML = `<nile-icon name=\"${defaultIcon}\" size=\"20\" color=\"black\" aria-label=\"${label}\"></nile-icon>`;\n } else {\n btn.textContent = label || cmd;\n }\n child.innerHTML = '';\n } else {\n // Author provided custom content (could be a <nile-icon> already)\n btn.innerHTML = child.innerHTML;\n child.innerHTML = '';\n }\n \n // Mount it\n if (!btn.isConnected) child.appendChild(btn);\n \n // Interactions\n btn.setAttribute('aria-label', label);\n btn.addEventListener('mousedown', e => e.preventDefault());\n btn.addEventListener('click', () => this.onToolbarCommand(cmd));\n \n // Register for active reflection\n const arr = this.buttonMap.get(cmd) ?? [];\n arr.push(btn);\n this.buttonMap.set(cmd, arr);\n \n return; // done with this child\n }\n if (tag === 'nile-rte-select') {\n const type = child.getAttribute('type') || '';\n\n // listen for our custom dropdown’s change event\n child.addEventListener('change', (e: any) => {\n // restore focus & selection\n this.focusAndRestore();\n\n const val = e.detail as string;\n\n if (type === 'heading') {\n // apply block tag\n setBlockTag(this.editorEl, val as any);\n }\n else if (type === 'font') {\n setFontFamily(this.editorEl, val);\n }\n \n // update the editor content & toolbar UI\n this.updateContent();\n this.updateToolbarState();\n });\n\n // nothing else to inject into the DOM\n return;\n }\n \n\n if (tag === 'nile-rte-color') {\n const label = child.getAttribute('label') ?? 'Text color';\n const value = child.getAttribute('value') ?? '#000000';\n // render internal <input type=\"color\">\n let input = child.querySelector(':scope > input[type=\"color\"]') as HTMLInputElement | null;\n if (!input) {\n input = document.createElement('input');\n input.type = 'color';\n child.appendChild(input);\n }\n input.title = label;\n input.value = value;\n input.addEventListener('mousedown', e => e.preventDefault());\n input.addEventListener('input', () => {\n this.focusAndRestore();\n setForeColor(this.editorEl, input!.value);\n this.updateContent(); this.updateToolbarState();\n });\n this.colorInput = input;\n }\n\n // nile-rte-divider: no-op (purely visual)\n });\n }\n\n // ---------- Selection helpers (for toolbar state only) ----------\n private onSelectionChange = () => {\n if (!this.editorEl) return;\n const sel = document.getSelection();\n if (!sel || sel.rangeCount === 0) return;\n const range = sel.getRangeAt(0);\n if (this.editorEl.contains(range.commonAncestorContainer)) {\n this.lastRange = range.cloneRange();\n this.updateToolbarState();\n }\n };\n private saveSelection() {\n const sel = window.getSelection();\n if (sel && sel.rangeCount) this.lastRange = sel.getRangeAt(0).cloneRange();\n }\n private restoreSelection() {\n if (!this.lastRange) return;\n const sel = document.getSelection(); if (!sel) return;\n sel.removeAllRanges(); sel.addRange(this.lastRange);\n }\n private focusAndRestore() { this.editorEl?.focus(); this.restoreSelection(); }\n\n /*──────────────────────── LIST HELPERS ────────────────────────*/\nprivate insertList(type: 'ul' | 'ol') {\n this.restoreSelection();\n if (!this.lastRange) return;\n\n // build <ul>/<ol>\n const list = document.createElement(type);\n\n // grab the selected fragment\n const frag = this.lastRange.extractContents();\n const temp = document.createElement('div');\n temp.appendChild(frag);\n\n // wrap each top-level node in an <li>\n Array.from(temp.childNodes).forEach(n => {\n // skip empty whitespace text nodes\n if (n.nodeType === Node.TEXT_NODE && !n.textContent?.trim()) return;\n const li = document.createElement('li');\n li.appendChild(n); // moves the node!\n list.appendChild(li);\n });\n\n // insert list where the selection was\n this.lastRange.insertNode(list);\n this.afterListEdit(list);\n}\n\nprivate afterListEdit(node: Node) {\n const range = document.createRange();\n range.setStartAfter(node);\n range.collapse(true);\n const sel = window.getSelection();\n sel?.removeAllRanges();\n sel?.addRange(range);\n\n this.saveSelection();\n this.updateContent();\n this.updateToolbarState();\n}\n // Keep at least one <p><br></p> and wrap stray inline/text into a <p>\nprivate ensureAtLeastOneParagraph() {\n const el = this.editorEl;\n if (!el) return;\n\n // 1) If completely empty → seed a paragraph\n const onlyWhitespace =\n (el.textContent ?? '').replace(/\\u200B/g, '').trim() === '';\n if (el.childNodes.length === 0 || onlyWhitespace) {\n el.innerHTML = '<p><br></p>';\n return;\n }\n\n // 2) If no block elements exist, wrap whatever is there into a <p>\n const hasBlock = el.querySelector('p,h1,h2,h3,h4,h5,h6,ul,ol,table,blockquote,pre');\n if (!hasBlock) {\n const p = document.createElement('p');\n while (el.firstChild) p.appendChild(el.firstChild);\n if (!p.hasChildNodes()) p.appendChild(document.createElement('br'));\n el.appendChild(p);\n return;\n }\n\n // 3) Make sure the first/only empty <p> still has a <br>\n el.querySelectorAll('p').forEach(p => {\n if ((p.textContent ?? '').replace(/\\u200B/g, '') === '') {\n if (!p.innerHTML.toLowerCase().includes('<br')) p.innerHTML = '<br>';\n }\n });\n}\n\n\n\n // ---------- Toolbar/commands ----------\n private onToolbarCommand(cmd: string) {\n this.focusAndRestore();\n switch (cmd) {\n case 'bold': toggleInlineTag(this.editorEl, 'strong'); break;\n case 'italic': toggleInlineTag(this.editorEl, 'em'); break;\n case 'underline': toggleInlineTag(this.editorEl, 'u'); break;\n case 'left': setAlignment(this.editorEl, 'left'); break;\n case 'center': setAlignment(this.editorEl, 'center'); break;\n case 'right': setAlignment(this.editorEl, 'right'); break;\n case 'justify': setAlignment(this.editorEl, 'justify'); break;\n case 'ul': this.insertList('ul'); break;\n case 'ol': this.insertList('ol'); break;\n case 'link': insertOrEditLink(this.editorEl); break;\n case 'clear':\n const walker = document.createTreeWalker(this.editorEl, NodeFilter.SHOW_ELEMENT);\n const toUnwrap: HTMLElement[] = [];\n while (walker.nextNode()) {\n const el = walker.currentNode as HTMLElement;\n el.removeAttribute('style');\n if (['B','STRONG','I','EM','U','SPAN','FONT'].includes(el.tagName)) {\n toUnwrap.push(el);\n }\n }\n for (const el of toUnwrap) {\n while (el.firstChild) el.parentNode?.insertBefore(el.firstChild, el);\n el.remove();\n }\n this.ensureAtLeastOneParagraph();\n break;\n\n default: break;\n }\n this.updateContent(); this.updateToolbarState();\n }\n\n private setBtnActive(cmd: string, active: boolean) {\n const arr = this.buttonMap.get(cmd); if (!arr) return;\n for (const btn of arr) btn.toggleAttribute('data-active', !!active);\n }\n\n private updateToolbarState() {\n if (!this.editorEl) return;\n const sel = document.getSelection();\n if (!sel || sel.rangeCount === 0) return;\n const range = sel.getRangeAt(0);\n if (!this.editorEl.contains(range.commonAncestorContainer)) return;\n\n const startElm = nearestElement(range.startContainer) || this.editorEl;\n const comp = getComputedStyle(startElm);\n const block = closestBlock(range.startContainer, this.editorEl) || this.editorEl;\n\n const isBold = (() => {\n let n: Node | null = startElm;\n while (n && n !== this.editorEl) {\n if (n instanceof HTMLElement) {\n const t = n.tagName.toLowerCase();\n if (t === 'strong' || t === 'b') return true;\n const w = getComputedStyle(n).fontWeight;\n if (parseInt(w, 10) >= 600) return true;\n }\n n = n.parentNode;\n }\n return false;\n })();\n\n const isItalic = (() => {\n let n: Node | null = startElm;\n while (n && n !== this.editorEl) {\n if (n instanceof HTMLElement) {\n const t = n.tagName.toLowerCase();\n if (t === 'em' || t === 'i') return true;\n if (getComputedStyle(n).fontStyle === 'italic') return true;\n }\n n = n.parentNode;\n }\n return false;\n })();\n\n const isUnderline = (() => {\n let n: Node | null = startElm;\n while (n && n !== this.editorEl) {\n if (n instanceof HTMLElement) {\n const tdl = getComputedStyle(n).textDecorationLine;\n if (tdl && tdl.includes('underline')) return true;\n if (n.tagName.toLowerCase() === 'u') return true;\n }\n n = n.parentNode;\n }\n return false;\n })();\n\n const inLink = !!startElm.closest('a');\n\n const align = (block.style.textAlign || getComputedStyle(block).textAlign || 'start') as string;\n const alignNorm = align === 'start' ? 'left' : align;\n\n const inLi = !!startElm.closest('li');\n const listType = inLi ? (startElm.closest('ul,ol')?.tagName.toLowerCase() || '') : '';\n\n this.setBtnActive('bold', isBold);\n this.setBtnActive('italic', isItalic);\n this.setBtnActive('underline', isUnderline);\n this.setBtnActive('link', inLink);\n\n this.setBtnActive('left', alignNorm === 'left' && !['center','right','justify'].includes(alignNorm));\n this.setBtnActive('center', alignNorm === 'center');\n this.setBtnActive('right', alignNorm === 'right');\n this.setBtnActive('justify', alignNorm === 'justify');\n\n this.setBtnActive('ul', listType === 'ul');\n this.setBtnActive('ol', listType === 'ol');\n\n // Reflect heading\n if (this.headingSelect) {\n const tag = block.tagName.toLowerCase();\n const v = ['h1','h2','h3'].includes(tag) ? tag : 'p';\n if (this.headingSelect.value !== v) this.headingSelect.value = v;\n }\n\n // Reflect font family\n if (this.fontSelect) {\n const ff = (comp.fontFamily || '').replace(/[\"']/g, '').split(',')[0].trim().toLowerCase();\n if (ff) {\n for (const opt of Array.from(this.fontSelect.options)) {\n if (opt.value.toLowerCase() === ff) { this.fontSelect.value = opt.value; break; }\n }\n }\n }\n\n // Reflect color\n if (this.colorInput) {\n const hex = rgbToHex(comp.color);\n if (hex && this.colorInput.value.toLowerCase() !== hex.toLowerCase()) {\n this.colorInput.value = hex;\n }\n }\n }\n\n private syncPreview() {\n this.updateContent();\n }\n\n private updateContent() {\n if (!this.editorEl) return;\n this.ensureAtLeastOneParagraph();\n this.content = this.editorEl.innerHTML;\n\n // live preview on the authored node (kept in place)\n if (this.previewEl) this.previewEl.innerHTML = this.content;\n\n this.dispatchEvent(new CustomEvent('content-changed', {\n detail: { content: this.content }, bubbles: true, composed: true\n }));\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'nile-rich-text-editor': NileRichTextEditor;\n }\n}\n\n"],"names":["DEFAULT_ICONS","bold","italic","underline","link","left","center","right","justify","ul","ol","clear","_export","NileRichTextEditor","_i","b","constructor","this","value","mentions","content","previewEl","toolbarEl","lastRange","buttonMap","Map","headingSelect","fontSelect","colorInput","mentionsEl","onSelectionChange","editorEl","sel","document","getSelection","rangeCount","range","getRangeAt","contains","commonAncestorContainer","cloneRange","updateToolbarState","_this","_inherits","_createClass","key","createRenderRoot","shouldUpdate","injectCss","cssText","querySelector","style","createElement","setAttribute","textContent","insertBefore","firstChild","connectedCallback","super","styles","ensureEditor","innerHTML","trim","wireAuthoredToolbar","attach","setExternalConfig","wireEditor","syncPreview","addEventListener","disconnectedCallback","removeEventListener","detach","_this$toolbarEl","editor","className","nextSibling","appendChild","ensureAtLeastOneParagraph","updateContent","saveSelection","tb","Array","from","children","forEach","child","tag","tagName","toLowerCase","getAttribute","_this3$buttonMap$get","btn","cmd","label","iconAttr","authoredHasContent","length","variant","size","defaultIcon","isConnected","e","preventDefault","onToolbarCommand","arr","get","push","set","_t$getAttribute","_t$getAttribute2","input","type","title","focusAndRestore","setForeColor","val","detail","setBlockTag","setFontFamily","alignment","setAlignment","window","restoreSelection","removeAllRanges","addRange","focus","insertList","list","frag","extractContents","temp","childNodes","n","nodeType","Node","TEXT_NODE","li","insertNode","afterListEdit","node","createRange","setStartAfter","collapse","el","onlyWhitespace","replace","p","hasChildNodes","querySelectorAll","includes","toggleInlineTag","insertOrEditLink","walker","createTreeWalker","NodeFilter","SHOW_ELEMENT","toUnwrap","nextNode","currentNode","removeAttribute","_i8","_i7","parentNode","remove","setBtnActive","active","_iterator","_createForOfIteratorHelper","s","_step","done","toggleAttribute","err","f","_this4","_e$closest","startElm","nearestElement","startContainer","comp","getComputedStyle","block","closestBlock","isBold","HTMLElement","t","w","fontWeight","parseInt","isItalic","fontStyle","isUnderline","tdl","textDecorationLine","inLink","closest","align","textAlign","alignNorm","listType","v","ff","fontFamily","split","_i13","_Array$from","options","opt","hex","rgbToHex","color","dispatchEvent","CustomEvent","bubbles","composed","__decorate","LitElement","property","String","prototype","attribute","converter","fromAttribute","parsed","JSON","parse","out","_i16","_Object$keys","Object","keys","trig","isArray","filter","i","map","_unused","toAttribute","stringify","state","customElement"],"mappings":"8zKA0BMA,CAAAA,CAAwC,CAC5CC,IAAM,CAAA,WAAA,CACNC,OAAQ,aACRC,CAAAA,SAAAA,CAAW,iBACXC,IAAM,CAAA,MAAA,CACNC,KAAM,gBACNC,CAAAA,MAAAA,CAAQ,mBACRC,KAAO,CAAA,iBAAA,CACPC,OAAS,CAAA,cAAA,CACTC,GAAI,SACJC,CAAAA,EAAAA,CAAI,UACJC,KAAO,CAAA,OAAA,CAAA,CAAAC,OAAA,KAIIC,CAAN,uBAAAC,EAAA,EAAA,SAAAC,EAAA,CAAAC,KAAAA,KAAAA,CAAAA,eAAAA,MAAAA,CAAAA,mCAKuBC,EAAAA,KAAAA,CAAKC,MAAG,EAwBpCD,CAAAA,KAAAA,CAAQE,SAAmB,GAGVF,KAAAA,CAAOG,OAAAA,CAAG,GAEnBH,KAAAA,CAASI,SAAAA,CAAuB,KAChCJ,KAAAA,CAASK,SAAAA,CAAuB,KAEhCL,KAAAA,CAASM,SAAAA,CAAiB,KAG1BN,KAAAA,CAAAO,SAAAA,CAAY,GAAIC,CAAAA,GAChBR,CAAAA,CAAAA,CAAAA,KAAAA,CAAaS,cAA6B,IAC1CT,CAAAA,KAAAA,CAAUU,WAA6B,IACvCV,CAAAA,KAAAA,CAAUW,UAA4B,CAAA,IAAA,CAGtCX,KAAAA,CAAUY,UAAuB,CAAA,IAAA,CAiOjCZ,KAAAA,CAAiBa,iBAAG,CAAA,UAAA,CAC1B,IAAKb,KAAAA,CAAKc,QAAAA,CAAU,OACpB,GAAMC,CAAAA,CAAAA,CAAMC,SAASC,YACrB,CAAA,CAAA,CAAA,GAAA,CAAKF,GAA0B,CAAnBA,GAAAA,CAAAA,CAAIG,WAAkB,OAClC,GAAMC,CAAAA,CAAQJ,CAAAA,CAAAA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,CAAA,IAAA,IAGbJ,CAAA,CAAA,CAAhBwB,KAA6BlO,CAAA8M,CAAAA,SAAAA,CAAA,cAAA,EAhCnB9M,CAAAA,CAAAA,OAAAA,KAAAA,CAAAA,CAAkB0M,EAAA,CAD9ByB,CAAAA,CAAc,0BACFnO"}
1
+ {"version":3,"file":"nile-rich-text-editor.cjs.js","sources":["../../../src/nile-rich-text-editor/nile-rich-text-editor.ts"],"sourcesContent":["// nile-rich-text-editor.ts\nimport { LitElement } from 'lit';\nimport { customElement, property, state } from 'lit/decorators.js';\n\nimport './nile-rte-toolbar';\nimport './nile-rte-toolbar-item';\nimport './nile-rte-select';\nimport './nile-rte-color';\nimport './nile-rte-divider';\nimport './nile-rte-preview';\nimport './nile-rte-mentions';\n\nimport {\n closestBlock, nearestElement, rgbToHex,\n toggleInlineTag, setBlockTag, setAlignment,\n setFontFamily, setForeColor, insertOrEditLink, setBackColor\n} from './utils';\n\nimport {styles} from './nile-rich-text-editor.css'; \n\ntype MentionsConfig = Record<string, { key: string; label: string }[]>;\n\n/**\n * Map commands → default icon names from your <nile-icon> set.\n * Adjust values to match the real names you have.\n */\nconst DEFAULT_ICONS: Record<string, string> = {\n bold: 'nile-bold',\n italic: 'nile-italic',\n underline: 'nile-underline',\n link: 'user',\n left: 'nile-leftalign',\n center: 'nile-centeralign',\n right: 'nile-rightalign',\n justify: 'nile-justify',\n ul: 'nile-ul',\n ol: 'nile-ol',\n clear: 'error',\n};\n\n@customElement('nile-rich-text-editor')\nexport class NileRichTextEditor extends LitElement {\n protected createRenderRoot() { return this; } \n protected shouldUpdate() { return false; } \n\n /** Initial HTML content */\n @property({ type: String }) value = '';\n\n /** Optional mentions config (can also be on <nile-rte-mentions mentions=\"...\">) */\n @property({\n attribute: 'mentions',\n converter: {\n fromAttribute: (value: string): MentionsConfig => {\n try {\n const parsed = JSON.parse(value);\n const out: MentionsConfig = {};\n for (const trig of Object.keys(parsed)) {\n const arr = parsed[trig];\n if (Array.isArray(arr)) {\n out[trig] = arr\n .filter(i => i && typeof i.key === 'string' && typeof i.label === 'string')\n .map(i => ({ key: i.key, label: i.label }));\n }\n }\n return out;\n } catch { return {}; }\n },\n toAttribute: (v: MentionsConfig) => JSON.stringify(v),\n }\n })\n mentions: MentionsConfig = {};\n\n // ----- internal state (no Lit render) -----\n @state() private content = '';\n private editorEl!: HTMLElement;\n private previewEl: HTMLElement | null = null;\n private toolbarEl: HTMLElement | null = null;\n\n private lastRange: Range | null = null;\n\n // map for button active reflections\n private buttonMap = new Map<string, HTMLElement[]>();\n private headingSelect: HTMLSelectElement | null = null;\n private fontSelect: HTMLSelectElement | null = null;\n private colorInput: HTMLInputElement | null = null;\nprivate bgColorInput: HTMLInputElement | null = null; \nprivate colorSwatchEl: HTMLElement | null = null; \nprivate bgSwatchEl: HTMLElement | null = null; \n\n\n // Mentions controller (child)\n private mentionsEl: HTMLElement | null = null;\n\n \n\n private injectCss(cssText: string) {\n if (this.querySelector('style[data-rte-style]')) return;\n const style = document.createElement('style');\n style.setAttribute('data-rte-style', 'true');\n style.textContent = cssText;\n this.insertBefore(style, this.firstChild);\n }\n\n connectedCallback(): void {\n super.connectedCallback();\n\n \n this.injectCss(styles.cssText); \n \n\n \n this.toolbarEl = this.querySelector('nile-rte-toolbar');\n this.previewEl = this.querySelector('nile-rte-preview');\n\n \n this.ensureEditor();\n\n \n if (this.value && !this.editorEl.innerHTML.trim()) {\n this.editorEl.innerHTML = this.value;\n }\n this.content = this.editorEl.innerHTML;\n\n \n if (this.toolbarEl) this.wireAuthoredToolbar(this.toolbarEl);\n\n \n this.mentionsEl = this.querySelector('nile-rte-mentions');\n if (this.mentionsEl) {\n \n (this.mentionsEl as any).attach?.(this.editorEl, this as HTMLElement);\n \n (this.mentionsEl as any).setExternalConfig?.(this.mentions);\n }\n\n \n this.wireEditor();\n\n \n this.updateToolbarState();\n this.syncPreview();\n\n \n document.addEventListener('selectionchange', this.onSelectionChange, true);\n }\n\n disconnectedCallback(): void {\n document.removeEventListener('selectionchange', this.onSelectionChange, true);\n \n if (this.mentionsEl && (this.mentionsEl as any).detach) {\n (this.mentionsEl as any).detach();\n }\n super.disconnectedCallback();\n }\n\n \n \n\n private ensureEditor() {\n this.editorEl = this.querySelector('.editor') as HTMLElement;\n if (!this.editorEl) {\n const editor = document.createElement('div');\n editor.className = 'editor';\n editor.setAttribute('contenteditable','true');\n if (this.toolbarEl?.nextSibling) {\n this.insertBefore(editor, this.toolbarEl.nextSibling);\n } else if (this.previewEl) {\n this.insertBefore(editor, this.previewEl);\n } else {\n this.appendChild(editor);\n }\n this.editorEl = editor;\n }\n if (!this.editorEl.innerHTML.trim()) {\n this.editorEl.innerHTML = '<p><br></p>';\n }\n this.ensureAtLeastOneParagraph();\n }\n\n private wireEditor() {\n // Input & selection preservation\n this.editorEl.addEventListener('input', () => { \n this.ensureAtLeastOneParagraph();\n this.updateContent();\n });\n this.editorEl.addEventListener('mouseup', () => this.saveSelection());\n this.editorEl.addEventListener('keyup', () => this.saveSelection()); \n }\n\n private wireAuthoredToolbar(tb: HTMLElement) {\n \n this.buttonMap.clear();\n this.headingSelect = null;\n this.fontSelect = null;\n this.colorInput = null;\n\n \n Array.from(tb.children).forEach(child => {\n const tag = child.tagName.toLowerCase();\n\n if (tag === 'nile-rte-select' && child.getAttribute('type') === 'align') {\n child.addEventListener('change', (e: any) => {\n this.focusAndRestore();\n const alignment = e.detail as 'left'|'center'|'right'|'justify';\n setAlignment(this.editorEl, alignment);\n this.updateContent();\n this.updateToolbarState();\n });\n return;\n }\n \n\n if (tag === 'nile-rte-toolbar-item') {\n \n let btn = child.querySelector(':scope > nile-button') as HTMLElement | null;\n \n const cmd = child.getAttribute('name') || '';\n const label = child.getAttribute('label') || cmd;\n const iconAttr = child.getAttribute('icon');\n const authoredHasContent = child.innerHTML.trim().length > 0;\n \n \n if (!btn) {\n btn = document.createElement('nile-button');\n (btn as any).variant = 'tertiary';\n (btn as any).size = 'small'; // optional\n }\n \n \n if (iconAttr) {\n btn.innerHTML = `<nile-icon name=\"${iconAttr}\" aria-label=\"${label}\"></nile-icon>`;\n child.innerHTML = '';\n } else if (!authoredHasContent) {\n const defaultIcon = DEFAULT_ICONS[cmd];\n if (defaultIcon) {\n btn.innerHTML = `<nile-icon name=\"${defaultIcon}\" size=\"20\" color=\"black\" aria-label=\"${label}\"></nile-icon>`;\n } else {\n btn.textContent = label || cmd;\n }\n child.innerHTML = '';\n } else {\n // Author provided custom content (could be a <nile-icon> already)\n btn.innerHTML = child.innerHTML;\n child.innerHTML = '';\n }\n \n // Mount it\n if (!btn.isConnected) child.appendChild(btn);\n \n // Interactions\n btn.setAttribute('aria-label', label);\n btn.addEventListener('mousedown', e => e.preventDefault());\n btn.addEventListener('click', () => this.onToolbarCommand(cmd));\n \n // Register for active reflection\n const arr = this.buttonMap.get(cmd) ?? [];\n arr.push(btn);\n this.buttonMap.set(cmd, arr);\n \n return; // done with this child\n }\n if (tag === 'nile-rte-select') {\n const type = child.getAttribute('type') || '';\n\n // listen for our custom dropdown’s change event\n child.addEventListener('change', (e: any) => {\n // restore focus & selection\n this.focusAndRestore();\n\n const val = e.detail as string;\n\n if (type === 'heading') {\n // apply block tag\n setBlockTag(this.editorEl, val as any);\n }\n else if (type === 'font') {\n setFontFamily(this.editorEl, val);\n }\n \n // update the editor content & toolbar UI\n this.updateContent();\n this.updateToolbarState();\n });\n\n // nothing else to inject into the DOM\n return;\n }\n \n\n if (tag === 'nile-rte-color') {\n const label = child.getAttribute('label') ?? 'Text color';\n const value = child.getAttribute('value') ?? '#000000';\n const mode = child.getAttribute('mode') ?? 'text'; // 'text' | 'background'\n \n // Create/attach the hidden color input\n let input = child.querySelector(':scope > input[type=\"color\"]') as HTMLInputElement | null;\n if (!input) {\n input = document.createElement('input');\n input.type = 'color';\n input.style.position = 'absolute';\n input.style.opacity = '0';\n input.style.pointerEvents = 'none'; // we'll click it programmatically\n child.appendChild(input);\n }\n input.title = label;\n input.value = value;\n \n // Build a custom trigger that shows the current color\n let trigger = child.querySelector(':scope > button.rte-color-trigger') as HTMLButtonElement | null;\n if (!trigger) {\n trigger = document.createElement('button');\n trigger.type = 'button';\n trigger.className = 'rte-color-trigger';\n trigger.setAttribute('aria-label', label);\n \n if (mode === 'background') {\n trigger.innerHTML = `\n <span class=\"swatch-box\" aria-hidden=\"true\"></span>\n `;\n } else {\n trigger.innerHTML = `\n <span class=\"glyph-stack\" aria-hidden=\"true\">\n <span class=\"glyph\">A</span>\n <span class=\"underline\"></span>\n </span>\n `;\n }\n child.appendChild(trigger);\n }\n \n // Cache swatch elements to update later\n const underline = trigger.querySelector('.underline') as HTMLElement | null;\n const square = trigger.querySelector('.swatch-box') as HTMLElement | null;\n \n if (mode === 'background') {\n this.bgColorInput = input;\n this.bgSwatchEl = square;\n if (this.bgSwatchEl) this.bgSwatchEl.style.backgroundColor = input.value;\n } else {\n this.colorInput = input;\n this.colorSwatchEl = underline;\n if (this.colorSwatchEl) this.colorSwatchEl.style.backgroundColor = input.value;\n }\n \n // Open native picker on trigger click\n trigger.addEventListener('click', (e) => {\n e.preventDefault();\n // Keep selection before opening the picker\n this.focusAndRestore();\n input!.click();\n });\n \n // When the user picks a color, apply it + update swatch\n input.addEventListener('input', () => {\n this.focusAndRestore();\n if (mode === 'background') {\n setBackColor(this.editorEl, input!.value);\n if (this.bgSwatchEl) this.bgSwatchEl.style.backgroundColor = input!.value;\n } else {\n setForeColor(this.editorEl, input!.value);\n if (this.colorSwatchEl) this.colorSwatchEl.style.backgroundColor = input!.value;\n }\n this.updateContent();\n this.updateToolbarState();\n });\n \n // Prevent losing selection when interacting\n trigger.addEventListener('mousedown', e => e.preventDefault());\n input.addEventListener('mousedown', e => e.preventDefault());\n }\n });\n }\n private onSelectionChange = () => {\n if (!this.editorEl) return;\n const sel = document.getSelection();\n if (!sel || sel.rangeCount === 0) return;\n const range = sel.getRangeAt(0);\n if (this.editorEl.contains(range.commonAncestorContainer)) {\n this.lastRange = range.cloneRange();\n this.updateToolbarState();\n }\n };\n private saveSelection() {\n const sel = window.getSelection();\n if (sel && sel.rangeCount) this.lastRange = sel.getRangeAt(0).cloneRange();\n }\n private restoreSelection() {\n if (!this.lastRange) return;\n const sel = document.getSelection(); if (!sel) return;\n sel.removeAllRanges(); sel.addRange(this.lastRange);\n }\n private focusAndRestore() { this.editorEl?.focus(); this.restoreSelection(); }\n\n /*──────────────────────── LIST HELPERS ────────────────────────*/\nprivate insertList(type: 'ul' | 'ol') {\n this.restoreSelection();\n if (!this.lastRange) return;\n\n // build <ul>/<ol>\n const list = document.createElement(type);\n\n // grab the selected fragment\n const frag = this.lastRange.extractContents();\n const temp = document.createElement('div');\n temp.appendChild(frag);\n\n // wrap each top-level node in an <li>\n Array.from(temp.childNodes).forEach(n => {\n // skip empty whitespace text nodes\n if (n.nodeType === Node.TEXT_NODE && !n.textContent?.trim()) return;\n const li = document.createElement('li');\n li.appendChild(n); // moves the node!\n list.appendChild(li);\n });\n\n // insert list where the selection was\n this.lastRange.insertNode(list);\n this.afterListEdit(list);\n}\n\nprivate afterListEdit(node: Node) {\n const range = document.createRange();\n range.setStartAfter(node);\n range.collapse(true);\n const sel = window.getSelection();\n sel?.removeAllRanges();\n sel?.addRange(range);\n\n this.saveSelection();\n this.updateContent();\n this.updateToolbarState();\n}\n // Keep at least one <p><br></p> and wrap stray inline/text into a <p>\nprivate ensureAtLeastOneParagraph() {\n const el = this.editorEl;\n if (!el) return;\n\n // 1) If completely empty → seed a paragraph\n const onlyWhitespace =\n (el.textContent ?? '').replace(/\\u200B/g, '').trim() === '';\n if (el.childNodes.length === 0 || onlyWhitespace) {\n el.innerHTML = '<p><br></p>';\n return;\n }\n\n // 2) If no block elements exist, wrap whatever is there into a <p>\n const hasBlock = el.querySelector('p,h1,h2,h3,h4,h5,h6,ul,ol,table,blockquote,pre');\n if (!hasBlock) {\n const p = document.createElement('p');\n while (el.firstChild) p.appendChild(el.firstChild);\n if (!p.hasChildNodes()) p.appendChild(document.createElement('br'));\n el.appendChild(p);\n return;\n }\n\n // 3) Make sure the first/only empty <p> still has a <br>\n el.querySelectorAll('p').forEach(p => {\n if ((p.textContent ?? '').replace(/\\u200B/g, '') === '') {\n if (!p.innerHTML.toLowerCase().includes('<br')) p.innerHTML = '<br>';\n }\n });\n}\n\n\n\n // ---------- Toolbar/commands ----------\n private onToolbarCommand(cmd: string) {\n this.focusAndRestore();\n switch (cmd) {\n case 'bold': toggleInlineTag(this.editorEl, 'strong'); break;\n case 'italic': toggleInlineTag(this.editorEl, 'em'); break;\n case 'underline': toggleInlineTag(this.editorEl, 'u'); break;\n case 'left': setAlignment(this.editorEl, 'left'); break;\n case 'center': setAlignment(this.editorEl, 'center'); break;\n case 'right': setAlignment(this.editorEl, 'right'); break;\n case 'justify': setAlignment(this.editorEl, 'justify'); break;\n case 'ul': this.insertList('ul'); break;\n case 'ol': this.insertList('ol'); break;\n case 'link': insertOrEditLink(this.editorEl); break;\n case 'clear':\n const walker = document.createTreeWalker(this.editorEl, NodeFilter.SHOW_ELEMENT);\n const toUnwrap: HTMLElement[] = [];\n while (walker.nextNode()) {\n const el = walker.currentNode as HTMLElement;\n el.removeAttribute('style');\n if (['B','STRONG','I','EM','U','SPAN','FONT'].includes(el.tagName)) {\n toUnwrap.push(el);\n }\n }\n for (const el of toUnwrap) {\n while (el.firstChild) el.parentNode?.insertBefore(el.firstChild, el);\n el.remove();\n }\n this.ensureAtLeastOneParagraph();\n break;\n\n default: break;\n }\n this.updateContent(); this.updateToolbarState();\n }\n\n private setBtnActive(cmd: string, active: boolean) {\n const arr = this.buttonMap.get(cmd); if (!arr) return;\n for (const btn of arr) btn.toggleAttribute('data-active', !!active);\n }\n\n private updateToolbarState() {\n if (!this.editorEl) return;\n const sel = document.getSelection();\n if (!sel || sel.rangeCount === 0) return;\n const range = sel.getRangeAt(0);\n if (!this.editorEl.contains(range.commonAncestorContainer)) return;\n\n const startElm = nearestElement(range.startContainer) || this.editorEl;\n const comp = getComputedStyle(startElm);\n const block = closestBlock(range.startContainer, this.editorEl) || this.editorEl;\n\n const isBold = (() => {\n let n: Node | null = startElm;\n while (n && n !== this.editorEl) {\n if (n instanceof HTMLElement) {\n const t = n.tagName.toLowerCase();\n if (t === 'strong' || t === 'b') return true;\n const w = getComputedStyle(n).fontWeight;\n if (parseInt(w, 10) >= 600) return true;\n }\n n = n.parentNode;\n }\n return false;\n })();\n\n const isItalic = (() => {\n let n: Node | null = startElm;\n while (n && n !== this.editorEl) {\n if (n instanceof HTMLElement) {\n const t = n.tagName.toLowerCase();\n if (t === 'em' || t === 'i') return true;\n if (getComputedStyle(n).fontStyle === 'italic') return true;\n }\n n = n.parentNode;\n }\n return false;\n })();\n\n const isUnderline = (() => {\n let n: Node | null = startElm;\n while (n && n !== this.editorEl) {\n if (n instanceof HTMLElement) {\n const tdl = getComputedStyle(n).textDecorationLine;\n if (tdl && tdl.includes('underline')) return true;\n if (n.tagName.toLowerCase() === 'u') return true;\n }\n n = n.parentNode;\n }\n return false;\n })();\n\n const inLink = !!startElm.closest('a');\n\n const align = (block.style.textAlign || getComputedStyle(block).textAlign || 'start') as string;\n const alignNorm = align === 'start' ? 'left' : align;\n\n const inLi = !!startElm.closest('li');\n const listType = inLi ? (startElm.closest('ul,ol')?.tagName.toLowerCase() || '') : '';\n\n this.setBtnActive('bold', isBold);\n this.setBtnActive('italic', isItalic);\n this.setBtnActive('underline', isUnderline);\n this.setBtnActive('link', inLink);\n\n this.setBtnActive('left', alignNorm === 'left' && !['center','right','justify'].includes(alignNorm));\n this.setBtnActive('center', alignNorm === 'center');\n this.setBtnActive('right', alignNorm === 'right');\n this.setBtnActive('justify', alignNorm === 'justify');\n\n this.setBtnActive('ul', listType === 'ul');\n this.setBtnActive('ol', listType === 'ol');\n\n // Reflect heading\n if (this.headingSelect) {\n const tag = block.tagName.toLowerCase();\n const v = ['h1','h2','h3'].includes(tag) ? tag : 'p';\n if (this.headingSelect.value !== v) this.headingSelect.value = v;\n }\n\n // Reflect font family\n if (this.fontSelect) {\n const ff = (comp.fontFamily || '').replace(/[\"']/g, '').split(',')[0].trim().toLowerCase();\n if (ff) {\n for (const opt of Array.from(this.fontSelect.options)) {\n if (opt.value.toLowerCase() === ff) { this.fontSelect.value = opt.value; break; }\n }\n }\n }\n\n if (this.colorInput) {\n const hex = rgbToHex(comp.color);\n if (hex && this.colorInput.value.toLowerCase() !== hex.toLowerCase()) {\n this.colorInput.value = hex;\n }\n if (this.colorSwatchEl) this.colorSwatchEl.style.backgroundColor = this.colorInput.value;\n }\n \n\n if (this.bgColorInput) {\n const bg = getComputedStyle(startElm).backgroundColor;\n if (bg && !/transparent|rgba\\(\\s*0\\s*,\\s*0\\s*,\\s*0\\s*,\\s*0\\s*\\)/i.test(bg)) {\n const bgHex = rgbToHex(bg);\n if (bgHex && this.bgColorInput.value.toLowerCase() !== bgHex.toLowerCase()) {\n this.bgColorInput.value = bgHex;\n }\n }\n if (this.bgSwatchEl) this.bgSwatchEl.style.backgroundColor = this.bgColorInput.value;\n }\n }\n\n private syncPreview() {\n this.updateContent();\n }\n\n private updateContent() {\n if (!this.editorEl) return;\n this.ensureAtLeastOneParagraph();\n this.content = this.editorEl.innerHTML;\n\n // live preview on the authored node (kept in place)\n if (this.previewEl) this.previewEl.innerHTML = this.content;\n\n this.dispatchEvent(new CustomEvent('content-changed', {\n detail: { content: this.content }, bubbles: true, composed: true\n }));\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'nile-rich-text-editor': NileRichTextEditor;\n }\n}\n\n"],"names":["DEFAULT_ICONS","bold","italic","underline","link","left","center","right","justify","ul","ol","clear","_export","NileRichTextEditor","_i","g","constructor","this","value","mentions","content","previewEl","toolbarEl","lastRange","buttonMap","Map","headingSelect","fontSelect","colorInput","bgColorInput","colorSwatchEl","bgSwatchEl","mentionsEl","onSelectionChange","editorEl","sel","document","getSelection","rangeCount","range","getRangeAt","contains","commonAncestorContainer","cloneRange","updateToolbarState","_this","_inherits","_createClass","key","createRenderRoot","shouldUpdate","injectCss","cssText","querySelector","style","createElement","setAttribute","textContent","insertBefore","firstChild","connectedCallback","super","styles","ensureEditor","innerHTML","trim","wireAuthoredToolbar","attach","setExternalConfig","wireEditor","syncPreview","addEventListener","disconnectedCallback","removeEventListener","detach","_this$toolbarEl","editor","className","nextSibling","appendChild","ensureAtLeastOneParagraph","updateContent","saveSelection","tb","Array","from","children","forEach","child","tag","tagName","toLowerCase","getAttribute","_this3$buttonMap$get","btn","cmd","label","iconAttr","authoredHasContent","length","variant","size","defaultIcon","isConnected","e","preventDefault","onToolbarCommand","arr","get","push","set","_t$getAttribute","_t$getAttribute2","_t$getAttribute3","mode","input","type","position","opacity","pointerEvents","title","trigger","square","backgroundColor","focusAndRestore","click","setBackColor","setForeColor","val","detail","setBlockTag","setFontFamily","alignment","setAlignment","window","restoreSelection","removeAllRanges","addRange","focus","insertList","list","frag","extractContents","temp","childNodes","n","_t$textContent","nodeType","Node","TEXT_NODE","li","insertNode","afterListEdit","node","createRange","setStartAfter","collapse","el","onlyWhitespace","_t$textContent2","replace","p","hasChildNodes","querySelectorAll","includes","toggleInlineTag","insertOrEditLink","walker","createTreeWalker","NodeFilter","SHOW_ELEMENT","toUnwrap","nextNode","currentNode","removeAttribute","_i8","_i7","parentNode","remove","setBtnActive","active","_iterator","s","_step","done","toggleAttribute","err","f","startElm","nearestElement","startContainer","comp","getComputedStyle","block","closestBlock","isBold","HTMLElement","t","w","fontWeight","parseInt","isItalic","fontStyle","isUnderline","tdl","textDecorationLine","inLink","closest","align","textAlign","alignNorm","listType","_s$closest","v","ff","fontFamily","split","_i13","_Array$from","options","opt","hex","rgbToHex","color","bg","test","bgHex","dispatchEvent","CustomEvent","bubbles","composed","__decorate","LitElement","property","String","prototype","attribute","converter","fromAttribute","parsed","JSON","parse","out","_i17","_Object$keys","Object","keys","trig","isArray","filter","i","map","_unused","toAttribute","stringify","state","customElement"],"mappings":"g1KA0BMA,CAAAA,CAAwC,CAC5CC,IAAM,CAAA,WAAA,CACNC,MAAQ,CAAA,aAAA,CACRC,SA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AA,CAAOC,SAAAA,SAAKA,CAAAA,CAAsB,EAAA,QAAA,EAAA,MAAVA,CAAAA,EAAE1M,GAAuC,EAAA,QAAA,EAAA,MAAZ0M,CAAAA,CAAE1J,CAAAA,KAAAA,EAAAA,CAAAA,CACvD2J,GAAID,CAAAA,SAAAA,CAAAA,SAAQ1M,GAAK0M,CAAAA,CAAAA,CAAE1M,IAAKgD,KAAO0J,CAAAA,CAAAA,CAAE1J,UAEvC,EACD,MAAOkJ,CAAAA,GACR,EAAC,MAAAU,OAAA,CAAQ,CAAA,MAAO,EAAK,EAAA,CAAA,CAExBC,YAAcxC,QAAdwC,CAAAA,YAAcxC,CAAsB2B,QAAAA,CAAAA,IAAAA,CAAKc,UAAUzC,CAGzBxM,CAAAA,GAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAA8N,SAAA,CAAA,UAAA,CAAA,IAAA,EAGbJ,CAAAA,CAAAA,CAAAA,CAAA,CAAhBwB,CAA6BlP,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAA8N,UAAA,SAAA,CAAA,IAAA,EAAA,CAAA,CAAA/N,OAAA,KAhCnBC,EAAkB0N,CAAA,CAAA,CAD9ByB,CAAc,CAAA,uBAAA,CAAA,CAAA,CACFnP"}
@@ -1,2 +1,2 @@
1
- System.register(["lit"],function(_export,_context){"use strict";var e,_templateObject,o;function _taggedTemplateLiteral(e,t){return t||(t=e.slice(0)),Object.freeze(Object.defineProperties(e,{raw:{value:Object.freeze(t)}}));}return{setters:[function(_lit){e=_lit.css;}],execute:function execute(){_export("s",o=e(_templateObject||(_templateObject=_taggedTemplateLiteral(["\n /* Host positioning for overlays */\n nile-rich-text-editor { position: relative; display: block; font-family: inherit; }\n\n \nnile-rte-toolbar-item > nile-button::part(base) {\n \n width:32px; height:32px; padding:0px 6px;\n border: none;\n}\n \n \n\n\n .toolbar, nile-rte-toolbar {\n display:flex; align-items:center; gap:8px; padding:8px; \n border:1px solid #e5e7eb; border-bottom:none; border-radius:8px 8px 0 0; background:#fff;\n }\n\n nile-rte-toolbar-item > button, .toolbar button, nile-rte-toolbar button {\n border:1px solid #e5e7eb; background:#fff; border-radius:6px;\n cursor:pointer;\n }\n\n \n /* Ensure clicks hit the button (not nested icon internals) */\n nile-rte-toolbar-item > button nile-icon { pointer-events:none; }\n\n nile-rte-toolbar-item > button.active { border-color:#2563eb; background:#eff6ff; }\n nile-rte-select select { height:32px; border:1px solid #e5e7eb; border-radius:6px; background:#fff; }\n nile-rte-color input[type=\"color\"] { height:32px; width:36px; border:1px solid #e5e7eb; padding:0; border-radius:6px; background:#fff; }\n nile-rte-divider { width:1px; height:20px; background:#e5e7eb; display:inline-block; margin:0 4px; }\n\n .editor p { margin:1em 0; }\n .editor h1 { font-size:2em }\n .editor h2 { font-size:1.5em }\n .editor h3 { font-size:1.17em }\n .editor h4 { font-size:1em }\n .editor h5 { font-size:0.83em }\n .editor h6 { font-size:0.67em }\n\n .editor { min-height:160px; padding:12px; border:1px solid #e5e7eb; border-radius:0 0 8px 8px; background:#fff; outline:none; }\n nile-rte-preview { display:block; margin-top:10px; padding:10px; border:1px dashed #cbd5e1; border-radius:8px; background:#fafafa; }\n"]))));}};});
1
+ System.register(["lit"],function(_export,_context){"use strict";var e,_templateObject,r;function _taggedTemplateLiteral(e,t){return t||(t=e.slice(0)),Object.freeze(Object.defineProperties(e,{raw:{value:Object.freeze(t)}}));}return{setters:[function(_lit){e=_lit.css;}],execute:function execute(){_export("s",r=e(_templateObject||(_templateObject=_taggedTemplateLiteral(["\n /* Host positioning for overlays */\n nile-rich-text-editor { position: relative; display: block; font-family: inherit; }\n\n \nnile-rte-toolbar-item > nile-button::part(base) {\n \n width:32px; height:32px; padding:0px 6px;\n border: none;\n}\n \n \n\n\n .toolbar, nile-rte-toolbar {\n display:flex; align-items:center; gap:8px; padding:8px; \n border:1px solid #e5e7eb; border-bottom:none; border-radius:8px 8px 0 0; background:#fff;\n }\n\n nile-rte-toolbar-item > button, .toolbar button, nile-rte-toolbar button {\n border:1px solid #e5e7eb; background:#fff; border-radius:6px;\n cursor:pointer;\n }\n\n \n /* Ensure clicks hit the button (not nested icon internals) */\n nile-rte-toolbar-item > button nile-icon { pointer-events:none; }\n\n nile-rte-toolbar-item > button.active { border-color:#2563eb; background:#eff6ff; }\n nile-rte-select select { height:32px; border:1px solid #e5e7eb; border-radius:6px; background:#fff; }\n nile-rte-color input[type=\"color\"] { height:32px; width:36px; border:1px solid #e5e7eb; padding:0; border-radius:6px; background:#fff; }\n nile-rte-divider { width:1px; height:20px; background:#e5e7eb; display:inline-block; margin:0 4px; }\n\n .editor p { margin:1em 0; }\n .editor h1 { font-size:2em }\n .editor h2 { font-size:1.5em }\n .editor h3 { font-size:1.17em }\n .editor h4 { font-size:1em }\n .editor h5 { font-size:0.83em }\n .editor h6 { font-size:0.67em }\n\n .editor { min-height:160px; padding:12px; border:1px solid #e5e7eb; border-radius:0 0 8px 8px; background:#fff; outline:none; }\n nile-rte-preview { display:block; margin-top:10px; padding:10px; border:1px dashed #cbd5e1; border-radius:8px; background:#fafafa; }\n\n .rte-color-trigger {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n height: 28px;\n padding: 0 8px;\n border: 1px solid var(--nile-color-border, #d9d9d9);\n border-radius: 6px;\n background: #fff;\n cursor: pointer;\n}\n\n.rte-color-trigger .glyph-stack {\n display: grid; /* stack vertically */\n grid-auto-rows: max-content; \n align-items: center;\n justify-items: center;\n line-height: 1;\n}\n\n.rte-color-trigger .glyph {\n font-size: 14px;\n line-height: 1;\n margin-bottom: 2px; /* little breathing space above underline */\n}\n\n.rte-color-trigger .underline {\n width: 18px;\n height: 3px;\n border-radius: 2px;\n background: currentColor; /* we override via JS with backgroundColor */\n}\n\n/* (unchanged) highlight square */\n.rte-color-trigger .swatch-box {\n width: 18px;\n height: 16px;\n border-radius: 4px;\n border: 1px solid rgba(0,0,0,0.35);\n background: currentColor; /* overridden via JS */\n}\n\n"]))));}};});
2
2
  //# sourceMappingURL=nile-rich-text-editor.css.cjs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"nile-rich-text-editor.css.cjs.js","sources":["../../../src/nile-rich-text-editor/nile-rich-text-editor.css.ts"],"sourcesContent":["// rte-styles.ts\nimport { css } from 'lit';\n\nexport const styles = css`\n /* Host positioning for overlays */\n nile-rich-text-editor { position: relative; display: block; font-family: inherit; }\n\n \nnile-rte-toolbar-item > nile-button::part(base) {\n \n width:32px; height:32px; padding:0px 6px;\n border: none;\n}\n \n \n\n\n .toolbar, nile-rte-toolbar {\n display:flex; align-items:center; gap:8px; padding:8px; \n border:1px solid #e5e7eb; border-bottom:none; border-radius:8px 8px 0 0; background:#fff;\n }\n\n nile-rte-toolbar-item > button, .toolbar button, nile-rte-toolbar button {\n border:1px solid #e5e7eb; background:#fff; border-radius:6px;\n cursor:pointer;\n }\n\n \n /* Ensure clicks hit the button (not nested icon internals) */\n nile-rte-toolbar-item > button nile-icon { pointer-events:none; }\n\n nile-rte-toolbar-item > button.active { border-color:#2563eb; background:#eff6ff; }\n nile-rte-select select { height:32px; border:1px solid #e5e7eb; border-radius:6px; background:#fff; }\n nile-rte-color input[type=\"color\"] { height:32px; width:36px; border:1px solid #e5e7eb; padding:0; border-radius:6px; background:#fff; }\n nile-rte-divider { width:1px; height:20px; background:#e5e7eb; display:inline-block; margin:0 4px; }\n\n .editor p { margin:1em 0; }\n .editor h1 { font-size:2em }\n .editor h2 { font-size:1.5em }\n .editor h3 { font-size:1.17em }\n .editor h4 { font-size:1em }\n .editor h5 { font-size:0.83em }\n .editor h6 { font-size:0.67em }\n\n .editor { min-height:160px; padding:12px; border:1px solid #e5e7eb; border-radius:0 0 8px 8px; background:#fff; outline:none; }\n nile-rte-preview { display:block; margin-top:10px; padding:10px; border:1px dashed #cbd5e1; border-radius:8px; background:#fafafa; }\n`;\n\nexport default [styles];"],"names":["styles","css","_templateObject","_taggedTemplateLiteral"],"mappings":"oTAGaA,CAAAA,CAASC,CAAG,CAAAC,eAAA,GAAAA,eAAA,CAAAC,sBAAA"}
1
+ {"version":3,"file":"nile-rich-text-editor.css.cjs.js","sources":["../../../src/nile-rich-text-editor/nile-rich-text-editor.css.ts"],"sourcesContent":["// rte-styles.ts\nimport { css } from 'lit';\n\nexport const styles = css`\n /* Host positioning for overlays */\n nile-rich-text-editor { position: relative; display: block; font-family: inherit; }\n\n \nnile-rte-toolbar-item > nile-button::part(base) {\n \n width:32px; height:32px; padding:0px 6px;\n border: none;\n}\n \n \n\n\n .toolbar, nile-rte-toolbar {\n display:flex; align-items:center; gap:8px; padding:8px; \n border:1px solid #e5e7eb; border-bottom:none; border-radius:8px 8px 0 0; background:#fff;\n }\n\n nile-rte-toolbar-item > button, .toolbar button, nile-rte-toolbar button {\n border:1px solid #e5e7eb; background:#fff; border-radius:6px;\n cursor:pointer;\n }\n\n \n /* Ensure clicks hit the button (not nested icon internals) */\n nile-rte-toolbar-item > button nile-icon { pointer-events:none; }\n\n nile-rte-toolbar-item > button.active { border-color:#2563eb; background:#eff6ff; }\n nile-rte-select select { height:32px; border:1px solid #e5e7eb; border-radius:6px; background:#fff; }\n nile-rte-color input[type=\"color\"] { height:32px; width:36px; border:1px solid #e5e7eb; padding:0; border-radius:6px; background:#fff; }\n nile-rte-divider { width:1px; height:20px; background:#e5e7eb; display:inline-block; margin:0 4px; }\n\n .editor p { margin:1em 0; }\n .editor h1 { font-size:2em }\n .editor h2 { font-size:1.5em }\n .editor h3 { font-size:1.17em }\n .editor h4 { font-size:1em }\n .editor h5 { font-size:0.83em }\n .editor h6 { font-size:0.67em }\n\n .editor { min-height:160px; padding:12px; border:1px solid #e5e7eb; border-radius:0 0 8px 8px; background:#fff; outline:none; }\n nile-rte-preview { display:block; margin-top:10px; padding:10px; border:1px dashed #cbd5e1; border-radius:8px; background:#fafafa; }\n\n .rte-color-trigger {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n height: 28px;\n padding: 0 8px;\n border: 1px solid var(--nile-color-border, #d9d9d9);\n border-radius: 6px;\n background: #fff;\n cursor: pointer;\n}\n\n.rte-color-trigger .glyph-stack {\n display: grid; /* stack vertically */\n grid-auto-rows: max-content; \n align-items: center;\n justify-items: center;\n line-height: 1;\n}\n\n.rte-color-trigger .glyph {\n font-size: 14px;\n line-height: 1;\n margin-bottom: 2px; /* little breathing space above underline */\n}\n\n.rte-color-trigger .underline {\n width: 18px;\n height: 3px;\n border-radius: 2px;\n background: currentColor; /* we override via JS with backgroundColor */\n}\n\n/* (unchanged) highlight square */\n.rte-color-trigger .swatch-box {\n width: 18px;\n height: 16px;\n border-radius: 4px;\n border: 1px solid rgba(0,0,0,0.35);\n background: currentColor; /* overridden via JS */\n}\n\n`;\n\nexport default [styles];"],"names":["styles","css","_templateObject","_taggedTemplateLiteral"],"mappings":"oTAGaA,CAAAA,CAASC,CAAG,CAAAC,eAAA,GAAAA,eAAA,CAAAC,sBAAA"}
@@ -1,4 +1,4 @@
1
- import{css as e}from"lit";const o=e`
1
+ import{css as e}from"lit";const r=e`
2
2
  /* Host positioning for overlays */
3
3
  nile-rich-text-editor { position: relative; display: block; font-family: inherit; }
4
4
 
@@ -41,4 +41,47 @@ nile-rte-toolbar-item > nile-button::part(base) {
41
41
 
42
42
  .editor { min-height:160px; padding:12px; border:1px solid #e5e7eb; border-radius:0 0 8px 8px; background:#fff; outline:none; }
43
43
  nile-rte-preview { display:block; margin-top:10px; padding:10px; border:1px dashed #cbd5e1; border-radius:8px; background:#fafafa; }
44
- `;export{o as s};
44
+
45
+ .rte-color-trigger {
46
+ display: inline-flex;
47
+ align-items: center;
48
+ justify-content: center;
49
+ height: 28px;
50
+ padding: 0 8px;
51
+ border: 1px solid var(--nile-color-border, #d9d9d9);
52
+ border-radius: 6px;
53
+ background: #fff;
54
+ cursor: pointer;
55
+ }
56
+
57
+ .rte-color-trigger .glyph-stack {
58
+ display: grid; /* stack vertically */
59
+ grid-auto-rows: max-content;
60
+ align-items: center;
61
+ justify-items: center;
62
+ line-height: 1;
63
+ }
64
+
65
+ .rte-color-trigger .glyph {
66
+ font-size: 14px;
67
+ line-height: 1;
68
+ margin-bottom: 2px; /* little breathing space above underline */
69
+ }
70
+
71
+ .rte-color-trigger .underline {
72
+ width: 18px;
73
+ height: 3px;
74
+ border-radius: 2px;
75
+ background: currentColor; /* we override via JS with backgroundColor */
76
+ }
77
+
78
+ /* (unchanged) highlight square */
79
+ .rte-color-trigger .swatch-box {
80
+ width: 18px;
81
+ height: 16px;
82
+ border-radius: 4px;
83
+ border: 1px solid rgba(0,0,0,0.35);
84
+ background: currentColor; /* overridden via JS */
85
+ }
86
+
87
+ `;export{r as s};
@@ -1 +1 @@
1
- import{__decorate as t}from"tslib";import{LitElement as i}from"lit";import{property as e,state as s,customElement as n}from"lit/decorators.js";import"./nile-rte-toolbar.esm.js";import"./nile-rte-toolbar-item.esm.js";import"./nile-rte-select.esm.js";import"./nile-rte-color.esm.js";import"./nile-rte-divider.esm.js";import"./nile-rte-preview.esm.js";import"./nile-rte-mentions.esm.js";import{s as r,a as o,b as h,c as l,i as c,t as a,n as u,d as f,r as d}from"./utils.esm.js";import{s as m}from"./nile-rich-text-editor.css.esm.js";const p={bold:"nile-bold",italic:"nile-italic",underline:"nile-underline",link:"user",left:"nile-leftalign",center:"nile-centeralign",right:"nile-rightalign",justify:"nile-justify",ul:"nile-ul",ol:"nile-ol",clear:"error"};let b=class extends i{constructor(){super(...arguments),this.value="",this.mentions={},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.mentionsEl=null,this.onSelectionChange=()=>{if(!this.editorEl)return;const t=document.getSelection();if(!t||0===t.rangeCount)return;const i=t.getRangeAt(0);this.editorEl.contains(i.commonAncestorContainer)&&(this.lastRange=i.cloneRange(),this.updateToolbarState())}}createRenderRoot(){return this}shouldUpdate(){return!1}injectCss(t){if(this.querySelector("style[data-rte-style]"))return;const i=document.createElement("style");i.setAttribute("data-rte-style","true"),i.textContent=t,this.insertBefore(i,this.firstChild)}connectedCallback(){super.connectedCallback(),this.injectCss(m.cssText),this.toolbarEl=this.querySelector("nile-rte-toolbar"),this.previewEl=this.querySelector("nile-rte-preview"),this.ensureEditor(),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(),this.updateToolbarState(),this.syncPreview(),document.addEventListener("selectionchange",this.onSelectionChange,!0)}disconnectedCallback(){document.removeEventListener("selectionchange",this.onSelectionChange,!0),this.mentionsEl&&this.mentionsEl.detach&&this.mentionsEl.detach(),super.disconnectedCallback()}ensureEditor(){if(this.editorEl=this.querySelector(".editor"),!this.editorEl){const t=document.createElement("div");t.className="editor",t.setAttribute("contenteditable","true"),this.toolbarEl?.nextSibling?this.insertBefore(t,this.toolbarEl.nextSibling):this.previewEl?this.insertBefore(t,this.previewEl):this.appendChild(t),this.editorEl=t}this.editorEl.innerHTML.trim()||(this.editorEl.innerHTML="<p><br></p>"),this.ensureAtLeastOneParagraph()}wireEditor(){this.editorEl.addEventListener("input",(()=>{this.ensureAtLeastOneParagraph(),this.updateContent()})),this.editorEl.addEventListener("mouseup",(()=>this.saveSelection())),this.editorEl.addEventListener("keyup",(()=>this.saveSelection()))}wireAuthoredToolbar(t){this.buttonMap.clear(),this.headingSelect=null,this.fontSelect=null,this.colorInput=null,Array.from(t.children).forEach((t=>{const i=t.tagName.toLowerCase();if("nile-rte-select"!==i||"align"!==t.getAttribute("type")){if("nile-rte-toolbar-item"===i){let i=t.querySelector(":scope > nile-button");const e=t.getAttribute("name")||"",s=t.getAttribute("label")||e,n=t.getAttribute("icon"),r=t.innerHTML.trim().length>0;if(i||(i=document.createElement("nile-button"),i.variant="tertiary",i.size="small"),n)i.innerHTML=`<nile-icon name="${n}" aria-label="${s}"></nile-icon>`,t.innerHTML="";else if(r)i.innerHTML=t.innerHTML,t.innerHTML="";else{const n=p[e];n?i.innerHTML=`<nile-icon name="${n}" size="20" color="black" aria-label="${s}"></nile-icon>`:i.textContent=s||e,t.innerHTML=""}i.isConnected||t.appendChild(i),i.setAttribute("aria-label",s),i.addEventListener("mousedown",(t=>t.preventDefault())),i.addEventListener("click",(()=>this.onToolbarCommand(e)));const o=this.buttonMap.get(e)??[];return o.push(i),void this.buttonMap.set(e,o)}if("nile-rte-select"!==i){if("nile-rte-color"===i){const i=t.getAttribute("label")??"Text color",e=t.getAttribute("value")??"#000000";let s=t.querySelector(':scope > input[type="color"]');s||(s=document.createElement("input"),s.type="color",t.appendChild(s)),s.title=i,s.value=e,s.addEventListener("mousedown",(t=>t.preventDefault())),s.addEventListener("input",(()=>{this.focusAndRestore(),l(this.editorEl,s.value),this.updateContent(),this.updateToolbarState()})),this.colorInput=s}}else{const i=t.getAttribute("type")||"";t.addEventListener("change",(t=>{this.focusAndRestore();const e=t.detail;"heading"===i?o(this.editorEl,e):"font"===i&&h(this.editorEl,e),this.updateContent(),this.updateToolbarState()}))}}else t.addEventListener("change",(t=>{this.focusAndRestore();const i=t.detail;r(this.editorEl,i),this.updateContent(),this.updateToolbarState()}))}))}saveSelection(){const t=window.getSelection();t&&t.rangeCount&&(this.lastRange=t.getRangeAt(0).cloneRange())}restoreSelection(){if(!this.lastRange)return;const t=document.getSelection();t&&(t.removeAllRanges(),t.addRange(this.lastRange))}focusAndRestore(){this.editorEl?.focus(),this.restoreSelection()}insertList(t){if(this.restoreSelection(),!this.lastRange)return;const i=document.createElement(t),e=this.lastRange.extractContents(),s=document.createElement("div");s.appendChild(e),Array.from(s.childNodes).forEach((t=>{if(t.nodeType===Node.TEXT_NODE&&!t.textContent?.trim())return;const e=document.createElement("li");e.appendChild(t),i.appendChild(e)})),this.lastRange.insertNode(i),this.afterListEdit(i)}afterListEdit(t){const i=document.createRange();i.setStartAfter(t),i.collapse(!0);const e=window.getSelection();e?.removeAllRanges(),e?.addRange(i),this.saveSelection(),this.updateContent(),this.updateToolbarState()}ensureAtLeastOneParagraph(){const t=this.editorEl;if(!t)return;const i=""===(t.textContent??"").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")){const i=document.createElement("p");for(;t.firstChild;)i.appendChild(t.firstChild);return i.hasChildNodes()||i.appendChild(document.createElement("br")),void t.appendChild(i)}t.querySelectorAll("p").forEach((t=>{""===(t.textContent??"").replace(/\u200B/g,"")&&(t.innerHTML.toLowerCase().includes("<br")||(t.innerHTML="<br>"))}))}onToolbarCommand(t){switch(this.focusAndRestore(),t){case"bold":a(this.editorEl,"strong");break;case"italic":a(this.editorEl,"em");break;case"underline":a(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":this.insertList("ul");break;case"ol":this.insertList("ol");break;case"link":c(this.editorEl);break;case"clear":const t=document.createTreeWalker(this.editorEl,NodeFilter.SHOW_ELEMENT),i=[];for(;t.nextNode();){const e=t.currentNode;e.removeAttribute("style"),["B","STRONG","I","EM","U","SPAN","FONT"].includes(e.tagName)&&i.push(e)}for(const t of i){for(;t.firstChild;)t.parentNode?.insertBefore(t.firstChild,t);t.remove()}this.ensureAtLeastOneParagraph()}this.updateContent(),this.updateToolbarState()}setBtnActive(t,i){const e=this.buttonMap.get(t);if(e)for(const t of e)t.toggleAttribute("data-active",!!i)}updateToolbarState(){if(!this.editorEl)return;const t=document.getSelection();if(!t||0===t.rangeCount)return;const i=t.getRangeAt(0);if(!this.editorEl.contains(i.commonAncestorContainer))return;const e=u(i.startContainer)||this.editorEl,s=getComputedStyle(e),n=f(i.startContainer,this.editorEl)||this.editorEl,r=(()=>{let t=e;for(;t&&t!==this.editorEl;){if(t instanceof HTMLElement){const i=t.tagName.toLowerCase();if("strong"===i||"b"===i)return!0;const e=getComputedStyle(t).fontWeight;if(parseInt(e,10)>=600)return!0}t=t.parentNode}return!1})(),o=(()=>{let t=e;for(;t&&t!==this.editorEl;){if(t instanceof HTMLElement){const i=t.tagName.toLowerCase();if("em"===i||"i"===i)return!0;if("italic"===getComputedStyle(t).fontStyle)return!0}t=t.parentNode}return!1})(),h=(()=>{let t=e;for(;t&&t!==this.editorEl;){if(t instanceof HTMLElement){const i=getComputedStyle(t).textDecorationLine;if(i&&i.includes("underline"))return!0;if("u"===t.tagName.toLowerCase())return!0}t=t.parentNode}return!1})(),l=!!e.closest("a"),c=n.style.textAlign||getComputedStyle(n).textAlign||"start",a="start"===c?"left":c,m=!!e.closest("li")&&e.closest("ul,ol")?.tagName.toLowerCase()||"";if(this.setBtnActive("bold",r),this.setBtnActive("italic",o),this.setBtnActive("underline",h),this.setBtnActive("link",l),this.setBtnActive("left","left"===a&&!["center","right","justify"].includes(a)),this.setBtnActive("center","center"===a),this.setBtnActive("right","right"===a),this.setBtnActive("justify","justify"===a),this.setBtnActive("ul","ul"===m),this.setBtnActive("ol","ol"===m),this.headingSelect){const t=n.tagName.toLowerCase(),i=["h1","h2","h3"].includes(t)?t:"p";this.headingSelect.value!==i&&(this.headingSelect.value=i)}if(this.fontSelect){const t=(s.fontFamily||"").replace(/["']/g,"").split(",")[0].trim().toLowerCase();if(t)for(const i of Array.from(this.fontSelect.options))if(i.value.toLowerCase()===t){this.fontSelect.value=i.value;break}}if(this.colorInput){const t=d(s.color);t&&this.colorInput.value.toLowerCase()!==t.toLowerCase()&&(this.colorInput.value=t)}}syncPreview(){this.updateContent()}updateContent(){this.editorEl&&(this.ensureAtLeastOneParagraph(),this.content=this.editorEl.innerHTML,this.previewEl&&(this.previewEl.innerHTML=this.content),this.dispatchEvent(new CustomEvent("content-changed",{detail:{content:this.content},bubbles:!0,composed:!0})))}};t([e({type:String})],b.prototype,"value",void 0),t([e({attribute:"mentions",converter:{fromAttribute:t=>{try{const i=JSON.parse(t),e={};for(const t of Object.keys(i)){const s=i[t];Array.isArray(s)&&(e[t]=s.filter((t=>t&&"string"==typeof t.key&&"string"==typeof t.label)).map((t=>({key:t.key,label:t.label}))))}return e}catch{return{}}},toAttribute:t=>JSON.stringify(t)}})],b.prototype,"mentions",void 0),t([s()],b.prototype,"content",void 0),b=t([n("nile-rich-text-editor")],b);export{b as N};
1
+ import{__decorate as t}from"tslib";import{LitElement as i}from"lit";import{property as s,state as e,customElement as n}from"lit/decorators.js";import"./nile-rte-toolbar.esm.js";import"./nile-rte-toolbar-item.esm.js";import"./nile-rte-select.esm.js";import"./nile-rte-color.esm.js";import"./nile-rte-divider.esm.js";import"./nile-rte-preview.esm.js";import"./nile-rte-mentions.esm.js";import{s as r,a as o,b as h,c as l,d as c,i as a,t as u,n as d,e as f,r as m}from"./utils.esm.js";import{s as p}from"./nile-rich-text-editor.css.esm.js";const b={bold:"nile-bold",italic:"nile-italic",underline:"nile-underline",link:"user",left:"nile-leftalign",center:"nile-centeralign",right:"nile-rightalign",justify:"nile-justify",ul:"nile-ul",ol:"nile-ol",clear:"error"};let g=class extends i{constructor(){super(...arguments),this.value="",this.mentions={},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.mentionsEl=null,this.onSelectionChange=()=>{if(!this.editorEl)return;const t=document.getSelection();if(!t||0===t.rangeCount)return;const i=t.getRangeAt(0);this.editorEl.contains(i.commonAncestorContainer)&&(this.lastRange=i.cloneRange(),this.updateToolbarState())}}createRenderRoot(){return this}shouldUpdate(){return!1}injectCss(t){if(this.querySelector("style[data-rte-style]"))return;const i=document.createElement("style");i.setAttribute("data-rte-style","true"),i.textContent=t,this.insertBefore(i,this.firstChild)}connectedCallback(){super.connectedCallback(),this.injectCss(p.cssText),this.toolbarEl=this.querySelector("nile-rte-toolbar"),this.previewEl=this.querySelector("nile-rte-preview"),this.ensureEditor(),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(),this.updateToolbarState(),this.syncPreview(),document.addEventListener("selectionchange",this.onSelectionChange,!0)}disconnectedCallback(){document.removeEventListener("selectionchange",this.onSelectionChange,!0),this.mentionsEl&&this.mentionsEl.detach&&this.mentionsEl.detach(),super.disconnectedCallback()}ensureEditor(){if(this.editorEl=this.querySelector(".editor"),!this.editorEl){const t=document.createElement("div");t.className="editor",t.setAttribute("contenteditable","true"),this.toolbarEl?.nextSibling?this.insertBefore(t,this.toolbarEl.nextSibling):this.previewEl?this.insertBefore(t,this.previewEl):this.appendChild(t),this.editorEl=t}this.editorEl.innerHTML.trim()||(this.editorEl.innerHTML="<p><br></p>"),this.ensureAtLeastOneParagraph()}wireEditor(){this.editorEl.addEventListener("input",(()=>{this.ensureAtLeastOneParagraph(),this.updateContent()})),this.editorEl.addEventListener("mouseup",(()=>this.saveSelection())),this.editorEl.addEventListener("keyup",(()=>this.saveSelection()))}wireAuthoredToolbar(t){this.buttonMap.clear(),this.headingSelect=null,this.fontSelect=null,this.colorInput=null,Array.from(t.children).forEach((t=>{const i=t.tagName.toLowerCase();if("nile-rte-select"!==i||"align"!==t.getAttribute("type")){if("nile-rte-toolbar-item"===i){let i=t.querySelector(":scope > nile-button");const s=t.getAttribute("name")||"",e=t.getAttribute("label")||s,n=t.getAttribute("icon"),r=t.innerHTML.trim().length>0;if(i||(i=document.createElement("nile-button"),i.variant="tertiary",i.size="small"),n)i.innerHTML=`<nile-icon name="${n}" aria-label="${e}"></nile-icon>`,t.innerHTML="";else if(r)i.innerHTML=t.innerHTML,t.innerHTML="";else{const n=b[s];n?i.innerHTML=`<nile-icon name="${n}" size="20" color="black" aria-label="${e}"></nile-icon>`:i.textContent=e||s,t.innerHTML=""}i.isConnected||t.appendChild(i),i.setAttribute("aria-label",e),i.addEventListener("mousedown",(t=>t.preventDefault())),i.addEventListener("click",(()=>this.onToolbarCommand(s)));const o=this.buttonMap.get(s)??[];return o.push(i),void this.buttonMap.set(s,o)}if("nile-rte-select"!==i){if("nile-rte-color"===i){const i=t.getAttribute("label")??"Text color",s=t.getAttribute("value")??"#000000",e=t.getAttribute("mode")??"text";let n=t.querySelector(':scope > input[type="color"]');n||(n=document.createElement("input"),n.type="color",n.style.position="absolute",n.style.opacity="0",n.style.pointerEvents="none",t.appendChild(n)),n.title=i,n.value=s;let r=t.querySelector(":scope > button.rte-color-trigger");r||(r=document.createElement("button"),r.type="button",r.className="rte-color-trigger",r.setAttribute("aria-label",i),r.innerHTML="background"===e?'\n <span class="swatch-box" aria-hidden="true"></span>\n ':'\n <span class="glyph-stack" aria-hidden="true">\n <span class="glyph">A</span>\n <span class="underline"></span>\n </span>\n ',t.appendChild(r));const o=r.querySelector(".underline"),h=r.querySelector(".swatch-box");"background"===e?(this.bgColorInput=n,this.bgSwatchEl=h,this.bgSwatchEl&&(this.bgSwatchEl.style.backgroundColor=n.value)):(this.colorInput=n,this.colorSwatchEl=o,this.colorSwatchEl&&(this.colorSwatchEl.style.backgroundColor=n.value)),r.addEventListener("click",(t=>{t.preventDefault(),this.focusAndRestore(),n.click()})),n.addEventListener("input",(()=>{this.focusAndRestore(),"background"===e?(l(this.editorEl,n.value),this.bgSwatchEl&&(this.bgSwatchEl.style.backgroundColor=n.value)):(c(this.editorEl,n.value),this.colorSwatchEl&&(this.colorSwatchEl.style.backgroundColor=n.value)),this.updateContent(),this.updateToolbarState()})),r.addEventListener("mousedown",(t=>t.preventDefault())),n.addEventListener("mousedown",(t=>t.preventDefault()))}}else{const i=t.getAttribute("type")||"";t.addEventListener("change",(t=>{this.focusAndRestore();const s=t.detail;"heading"===i?o(this.editorEl,s):"font"===i&&h(this.editorEl,s),this.updateContent(),this.updateToolbarState()}))}}else t.addEventListener("change",(t=>{this.focusAndRestore();const i=t.detail;r(this.editorEl,i),this.updateContent(),this.updateToolbarState()}))}))}saveSelection(){const t=window.getSelection();t&&t.rangeCount&&(this.lastRange=t.getRangeAt(0).cloneRange())}restoreSelection(){if(!this.lastRange)return;const t=document.getSelection();t&&(t.removeAllRanges(),t.addRange(this.lastRange))}focusAndRestore(){this.editorEl?.focus(),this.restoreSelection()}insertList(t){if(this.restoreSelection(),!this.lastRange)return;const i=document.createElement(t),s=this.lastRange.extractContents(),e=document.createElement("div");e.appendChild(s),Array.from(e.childNodes).forEach((t=>{if(t.nodeType===Node.TEXT_NODE&&!t.textContent?.trim())return;const s=document.createElement("li");s.appendChild(t),i.appendChild(s)})),this.lastRange.insertNode(i),this.afterListEdit(i)}afterListEdit(t){const i=document.createRange();i.setStartAfter(t),i.collapse(!0);const s=window.getSelection();s?.removeAllRanges(),s?.addRange(i),this.saveSelection(),this.updateContent(),this.updateToolbarState()}ensureAtLeastOneParagraph(){const t=this.editorEl;if(!t)return;const i=""===(t.textContent??"").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")){const i=document.createElement("p");for(;t.firstChild;)i.appendChild(t.firstChild);return i.hasChildNodes()||i.appendChild(document.createElement("br")),void t.appendChild(i)}t.querySelectorAll("p").forEach((t=>{""===(t.textContent??"").replace(/\u200B/g,"")&&(t.innerHTML.toLowerCase().includes("<br")||(t.innerHTML="<br>"))}))}onToolbarCommand(t){switch(this.focusAndRestore(),t){case"bold":u(this.editorEl,"strong");break;case"italic":u(this.editorEl,"em");break;case"underline":u(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":this.insertList("ul");break;case"ol":this.insertList("ol");break;case"link":a(this.editorEl);break;case"clear":const t=document.createTreeWalker(this.editorEl,NodeFilter.SHOW_ELEMENT),i=[];for(;t.nextNode();){const s=t.currentNode;s.removeAttribute("style"),["B","STRONG","I","EM","U","SPAN","FONT"].includes(s.tagName)&&i.push(s)}for(const t of i){for(;t.firstChild;)t.parentNode?.insertBefore(t.firstChild,t);t.remove()}this.ensureAtLeastOneParagraph()}this.updateContent(),this.updateToolbarState()}setBtnActive(t,i){const s=this.buttonMap.get(t);if(s)for(const t of s)t.toggleAttribute("data-active",!!i)}updateToolbarState(){if(!this.editorEl)return;const t=document.getSelection();if(!t||0===t.rangeCount)return;const i=t.getRangeAt(0);if(!this.editorEl.contains(i.commonAncestorContainer))return;const s=d(i.startContainer)||this.editorEl,e=getComputedStyle(s),n=f(i.startContainer,this.editorEl)||this.editorEl,r=(()=>{let t=s;for(;t&&t!==this.editorEl;){if(t instanceof HTMLElement){const i=t.tagName.toLowerCase();if("strong"===i||"b"===i)return!0;const s=getComputedStyle(t).fontWeight;if(parseInt(s,10)>=600)return!0}t=t.parentNode}return!1})(),o=(()=>{let t=s;for(;t&&t!==this.editorEl;){if(t instanceof HTMLElement){const i=t.tagName.toLowerCase();if("em"===i||"i"===i)return!0;if("italic"===getComputedStyle(t).fontStyle)return!0}t=t.parentNode}return!1})(),h=(()=>{let t=s;for(;t&&t!==this.editorEl;){if(t instanceof HTMLElement){const i=getComputedStyle(t).textDecorationLine;if(i&&i.includes("underline"))return!0;if("u"===t.tagName.toLowerCase())return!0}t=t.parentNode}return!1})(),l=!!s.closest("a"),c=n.style.textAlign||getComputedStyle(n).textAlign||"start",a="start"===c?"left":c,u=!!s.closest("li")&&s.closest("ul,ol")?.tagName.toLowerCase()||"";if(this.setBtnActive("bold",r),this.setBtnActive("italic",o),this.setBtnActive("underline",h),this.setBtnActive("link",l),this.setBtnActive("left","left"===a&&!["center","right","justify"].includes(a)),this.setBtnActive("center","center"===a),this.setBtnActive("right","right"===a),this.setBtnActive("justify","justify"===a),this.setBtnActive("ul","ul"===u),this.setBtnActive("ol","ol"===u),this.headingSelect){const t=n.tagName.toLowerCase(),i=["h1","h2","h3"].includes(t)?t:"p";this.headingSelect.value!==i&&(this.headingSelect.value=i)}if(this.fontSelect){const t=(e.fontFamily||"").replace(/["']/g,"").split(",")[0].trim().toLowerCase();if(t)for(const i of Array.from(this.fontSelect.options))if(i.value.toLowerCase()===t){this.fontSelect.value=i.value;break}}if(this.colorInput){const t=m(e.color);t&&this.colorInput.value.toLowerCase()!==t.toLowerCase()&&(this.colorInput.value=t),this.colorSwatchEl&&(this.colorSwatchEl.style.backgroundColor=this.colorInput.value)}if(this.bgColorInput){const t=getComputedStyle(s).backgroundColor;if(t&&!/transparent|rgba\(\s*0\s*,\s*0\s*,\s*0\s*,\s*0\s*\)/i.test(t)){const i=m(t);i&&this.bgColorInput.value.toLowerCase()!==i.toLowerCase()&&(this.bgColorInput.value=i)}this.bgSwatchEl&&(this.bgSwatchEl.style.backgroundColor=this.bgColorInput.value)}}syncPreview(){this.updateContent()}updateContent(){this.editorEl&&(this.ensureAtLeastOneParagraph(),this.content=this.editorEl.innerHTML,this.previewEl&&(this.previewEl.innerHTML=this.content),this.dispatchEvent(new CustomEvent("content-changed",{detail:{content:this.content},bubbles:!0,composed:!0})))}};t([s({type:String})],g.prototype,"value",void 0),t([s({attribute:"mentions",converter:{fromAttribute:t=>{try{const i=JSON.parse(t),s={};for(const t of Object.keys(i)){const e=i[t];Array.isArray(e)&&(s[t]=e.filter((t=>t&&"string"==typeof t.key&&"string"==typeof t.label)).map((t=>({key:t.key,label:t.label}))))}return s}catch{return{}}},toAttribute:t=>JSON.stringify(t)}})],g.prototype,"mentions",void 0),t([e()],g.prototype,"content",void 0),g=t([n("nile-rich-text-editor")],g);export{g as N};
@@ -1,3 +1,3 @@
1
1
  System.register(["tslib","lit","lit/decorators.js"],function(_export,_context){"use strict";var t,i,s,n,e,o;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);}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(_n2){function n(){return _n2.apply(this,arguments);}n.toString=function(){return _n2.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 ownKeys(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);r&&(o=o.filter(function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable;})),t.push.apply(t,o);}return t;}function _objectSpread(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?ownKeys(Object(t),!0).forEach(function(r){_defineProperty(e,r,t[r]);}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):ownKeys(Object(t)).forEach(function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r));});}return e;}function _defineProperty(e,r,t){return(r=_toPropertyKey(r))in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e;}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;n=_litDecoratorsJs.state;e=_litDecoratorsJs.customElement;}],execute:function execute(){o=/*#__PURE__*/function(_i){function o(){var _this;_classCallCheck(this,o);_this=_callSuper(this,o,arguments),_this.mentions={},_this.mentionColors={},_this.externalConfig={},_this.itemsConfig={},_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=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.saveSelection=function(){var t=window.getSelection();t&&t.rangeCount&&(_this.lastRange=t.getRangeAt(0).cloneRange());},_this.onEditorInput=function(){_this.mentionOpen&&_this.handleMention();},_this.onEditorKeyUp=function(t){_this.saveSelection();var i=t.key,s=_this.config;!_this.mentionOpen&&i&&s[i]?_this.openMention(i):_this.mentionOpen&&_this.handleMention();},_this.onEditorKeyDown=function(t){if(!_this.mentionOpen)return;var i=t.key;"ArrowDown"===i||"ArrowUp"===i||"Enter"===i?(t.preventDefault(),"Enter"===i&&_this.mentionFiltered.length&&_this.selectMention(_this.mentionFiltered[0])):"Escape"===i&&(t.preventDefault(),_this.closeMention());},_this.repositionMention=function(){if(!_this.mentionOpen||!_this.hostEl||!_this.triggerBtn)return;var t=_this.getCaretClientRect();if(!t)return;var i=_this.hostEl.getBoundingClientRect();_this.mentionX=t.left-i.left,_this.mentionY=t.bottom-i.top,_this.triggerBtn.style.left="".concat(_this.mentionX,"px"),_this.triggerBtn.style.top="".concat(_this.mentionY,"px");};return _this;}_inherits(o,_i);return _createClass(o,[{key:"createRenderRoot",value:function createRenderRoot(){return this;}},{key:"config",get:function get(){return _objectSpread(_objectSpread(_objectSpread({},this.externalConfig),this.mentions),this.itemsConfig);}},{key:"attach",value:function attach(t,i){var _this2=this;this.editorEl=t,this.hostEl=i,this.injectStyles(),this.ensureMentionDropdown(),this.rebuildConfigFromChildren(),this.mo=new MutationObserver(function(){return _this2.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);}},{key:"detach",value:function 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);}},{key:"setExternalConfig",value:function setExternalConfig(t){this.externalConfig=t||{};}},{key:"disconnectedCallback",value:function disconnectedCallback(){this.detach(),_superPropGet(o,"disconnectedCallback",this,3)([]);}},{key:"rebuildConfigFromChildren",value:function rebuildConfigFromChildren(){var t={},i={},s=Array.from(this.querySelectorAll("nile-rte-mentions-item"));var _loop=function _loop(){var _ref,_n$mentionsCharacter,_n$mentionsData,_ref2,_n$mentionsColor;var n=_s[_i2];var s=(_ref=(_n$mentionsCharacter=n.mentionsCharacter)!==null&&_n$mentionsCharacter!==void 0?_n$mentionsCharacter:n.getAttribute("mentionscharacter"))!==null&&_ref!==void 0?_ref:"";if(!s||"string"!=typeof s)return 1;// continue
2
- var e=(_n$mentionsData=n.mentionsData)!==null&&_n$mentionsData!==void 0?_n$mentionsData:function(){var t=n.getAttribute("mentionsdata");if(!t)return null;try{var _i3=JSON.parse(t);return Array.isArray(_i3)?_i3.filter(function(t){return t&&"string"==typeof t.key&&"string"==typeof t.label;}):[];}catch(_unused){return[];}}();var _o=(_ref2=(_n$mentionsColor=n.mentionsColor)!==null&&_n$mentionsColor!==void 0?_n$mentionsColor:n.getAttribute("mentionscolor"))!==null&&_ref2!==void 0?_ref2:"";Array.isArray(e)||(e=[]),t[s]=e,_o&&(i[s]=String(_o));};for(var _i2=0,_s=s;_i2<_s.length;_i2++){if(_loop())continue;}this.itemsConfig=t,this.itemsColors=i;}},{key:"injectStyles",value:function injectStyles(){if(this.querySelector("style[data-mentions-style]"))return;var t=document.createElement("style");t.setAttribute("data-mentions-style","true"),t.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 ",this.insertBefore(t,this.firstChild);}},{key:"getTriggerColor",value:function getTriggerColor(t){var _this$itemsColors$t;return(_this$itemsColors$t=this.itemsColors[t])!==null&&_this$itemsColors$t!==void 0?_this$itemsColors$t:this.mentionColors[t];}},{key:"ensureMentionDropdown",value:function ensureMentionDropdown(){if(this.dropdownEl||!this.hostEl)return;var t=document.createElement("nile-dropdown");t.style.zIndex="1000";var i=document.createElement("nile-button");i.setAttribute("slot","trigger"),i.style.position="absolute",i.style.width="1px",i.style.height="1px",i.style.border="0",i.style.padding="0",i.style.opacity="0",i.style.pointerEvents="none",t.appendChild(i),this.triggerBtn=i;var s=document.createElement("nile-menu");t.appendChild(s),this.hostEl.appendChild(t),this.dropdownEl=t,this.menuEl=s;}},{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:"getCaretClientRect",value:function getCaretClientRect(){var t=document.getSelection();if(!t||0===t.rangeCount)return null;var i=t.getRangeAt(0).cloneRange();i.collapse(!1);var s=i.getClientRects();if(s&&s.length>0)return s[0];var n=document.createElement("span");n.setAttribute("data-caret-marker","1"),n.textContent="​",i.insertNode(n);var e=n.getBoundingClientRect(),_o2=document.createRange();return _o2.setStartAfter(n),_o2.collapse(!0),t.removeAllRanges(),t.addRange(_o2),n.remove(),e||null;}},{key:"openMention",value:function openMention(t){if(this.saveSelection(),!this.editorEl||!this.dropdownEl||!this.hostEl)return;var i=this.getCaretClientRect();if(!i)return;var s=this.hostEl.getBoundingClientRect();this.mentionX=i.left-s.left,this.mentionY=i.bottom-s.top,this.mentionTrigger=t,this.mentionSuggestions=this.config[t]||[],this.mentionQuery="",this.updateMentionFiltered(),this.mentionOpen=!0,this.renderMentionList();}},{key:"closeMention",value:function closeMention(){var _this$dropdownEl;this.mentionOpen=!1,this.mentionTrigger=null,this.mentionQuery="",this.mentionFiltered=[],(_this$dropdownEl=this.dropdownEl)===null||_this$dropdownEl===void 0?void 0:_this$dropdownEl.removeAttribute("open");}},{key:"handleMention",value:function handleMention(){if(!this.mentionOpen||!this.mentionTrigger)return;var t=window.getSelection();if(!t||!t.anchorNode)return;var i=t.anchorNode;if(i.nodeType!==Node.TEXT_NODE){var _i$childNodes;var _s2=((_i$childNodes=i.childNodes)===null||_i$childNodes===void 0?void 0:_i$childNodes[t.anchorOffset])||i.firstChild;(_s2===null||_s2===void 0?void 0:_s2.nodeType)===Node.TEXT_NODE&&(i=_s2);}var s=i&&i.nodeType===Node.TEXT_NODE&&i.textContent||"",n=s.lastIndexOf(this.mentionTrigger);n>=0?(this.mentionQuery=s.substring(n+1),this.updateMentionFiltered(),this.renderMentionList()):this.closeMention();}},{key:"updateMentionFiltered",value:function updateMentionFiltered(){var t=this.mentionQuery.toLowerCase();this.mentionFiltered=(this.mentionSuggestions||[]).filter(function(i){return i.label.toLowerCase().startsWith(t);});}},{key:"renderMentionList",value:function renderMentionList(){var _this3=this;if(this.dropdownEl&&this.menuEl&&this.triggerBtn)if(this.triggerBtn.style.position="absolute",this.triggerBtn.style.left="".concat(this.mentionX,"px"),this.triggerBtn.style.top="".concat(this.mentionY,"px"),this.menuEl.innerHTML="",this.mentionOpen&&this.mentionFiltered.length){var _iterator=_createForOfIteratorHelper(this.mentionFiltered),_step;try{var _loop2=function _loop2(){var t=_step.value;var i=document.createElement("nile-menu-item");i.textContent=t.label,i.addEventListener("mousedown",function(i){i.preventDefault(),_this3.selectMention(t);}),_this3.menuEl.appendChild(i);};for(_iterator.s();!(_step=_iterator.n()).done;){_loop2();}}catch(err){_iterator.e(err);}finally{_iterator.f();}this.dropdownEl.setAttribute("open","");}else this.dropdownEl.removeAttribute("open");}},{key:"selectMention",value:function selectMention(t){if(this.restoreSelection(),!this.lastRange||!this.mentionTrigger||!this.editorEl)return;var i=this.lastRange.startContainer,s=this.lastRange.startOffset;if(i.nodeType!==Node.TEXT_NODE){var _t=i.childNodes[s];if((_t===null||_t===void 0?void 0:_t.nodeType)!==Node.TEXT_NODE)return;i=_t,s=0;}var n=i,e=(n.textContent||"").lastIndexOf(this.mentionTrigger,s);if(e<0)return;var _o3=e+1+this.mentionQuery.length,h=document.createRange();h.setStart(n,e),h.setEnd(n,_o3),h.deleteContents();var r=document.createElement("span");r.classList.add("mention"),r.textContent="".concat(this.mentionTrigger).concat(t.label);var c=this.getTriggerColor(this.mentionTrigger);c&&(r.style.backgroundColor=c),h.insertNode(r);var u=document.createTextNode(" ");r.after(u);var l=window.getSelection(),d=document.createRange();d.setStartAfter(u),d.collapse(!0),l!==null&&l!==void 0&&l.removeAllRanges(),l!==null&&l!==void 0&&l.addRange(d),this.lastRange=d.cloneRange(),this.closeMention(),this.editorEl.dispatchEvent(new InputEvent("input",{bubbles:!0}));}}]);}(i);t([s({attribute:"mentions",converter:{fromAttribute:function fromAttribute(t){try{var _i4=JSON.parse(t),_s3={};for(var _i5=0,_Object$keys=Object.keys(_i4);_i5<_Object$keys.length;_i5++){var _t2=_Object$keys[_i5];var _n=_i4[_t2];Array.isArray(_n)&&(_s3[_t2]=_n.filter(function(t){return t&&"string"==typeof t.key&&"string"==typeof t.label;}).map(function(t){return{key:t.key,label:t.label};}));}return _s3;}catch(_unused2){return{};}},toAttribute:function toAttribute(t){return JSON.stringify(t);}}})],o.prototype,"mentions",void 0),t([s({attribute:"mentioncolors",converter:{fromAttribute:function fromAttribute(t){try{var _i6=JSON.parse(t);return _i6&&"object"==_typeof(_i6)?_i6:{};}catch(_unused3){return{};}},toAttribute:function toAttribute(t){return JSON.stringify(t!==null&&t!==void 0?t:{});}}})],o.prototype,"mentionColors",void 0),t([n()],o.prototype,"externalConfig",void 0),t([n()],o.prototype,"itemsConfig",void 0),t([n()],o.prototype,"itemsColors",void 0),o=t([e("nile-rte-mentions")],o);}};});
2
+ var e=(_n$mentionsData=n.mentionsData)!==null&&_n$mentionsData!==void 0?_n$mentionsData:function(){var t=n.getAttribute("mentionsdata");if(!t)return null;try{var _i3=JSON.parse(t);return Array.isArray(_i3)?_i3.filter(function(t){return t&&"string"==typeof t.key&&"string"==typeof t.label;}):[];}catch(_unused){return[];}}();var _o=(_ref2=(_n$mentionsColor=n.mentionsColor)!==null&&_n$mentionsColor!==void 0?_n$mentionsColor:n.getAttribute("mentionscolor"))!==null&&_ref2!==void 0?_ref2:"";Array.isArray(e)||(e=[]),t[s]=e,_o&&(i[s]=String(_o));};for(var _i2=0,_s=s;_i2<_s.length;_i2++){if(_loop())continue;}this.itemsConfig=t,this.itemsColors=i;}},{key:"injectStyles",value:function injectStyles(){if(this.querySelector("style[data-mentions-style]"))return;var t=document.createElement("style");t.setAttribute("data-mentions-style","true"),t.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 }\n\n ",this.insertBefore(t,this.firstChild);}},{key:"getTriggerColor",value:function getTriggerColor(t){var _this$itemsColors$t;return(_this$itemsColors$t=this.itemsColors[t])!==null&&_this$itemsColors$t!==void 0?_this$itemsColors$t:this.mentionColors[t];}},{key:"ensureMentionDropdown",value:function ensureMentionDropdown(){if(this.dropdownEl||!this.hostEl)return;var t=document.createElement("nile-dropdown");t.style.zIndex="1000";var i=document.createElement("nile-button");i.setAttribute("slot","trigger"),i.style.position="absolute",i.style.width="1px",i.style.height="1px",i.style.border="0",i.style.padding="0",i.style.opacity="0",i.style.pointerEvents="none",t.appendChild(i),this.triggerBtn=i;var s=document.createElement("nile-menu");s.classList.add("mentions-menu"),t.appendChild(s),this.hostEl.appendChild(t),this.dropdownEl=t,this.menuEl=s;}},{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:"getCaretClientRect",value:function getCaretClientRect(){var t=document.getSelection();if(!t||0===t.rangeCount)return null;var i=t.getRangeAt(0).cloneRange();i.collapse(!1);var s=i.getClientRects();if(s&&s.length>0)return s[0];var n=document.createElement("span");n.setAttribute("data-caret-marker","1"),n.textContent="​",i.insertNode(n);var e=n.getBoundingClientRect(),_o2=document.createRange();return _o2.setStartAfter(n),_o2.collapse(!0),t.removeAllRanges(),t.addRange(_o2),n.remove(),e||null;}},{key:"openMention",value:function openMention(t){if(this.saveSelection(),!this.editorEl||!this.dropdownEl||!this.hostEl)return;var i=this.getCaretClientRect();if(!i)return;var s=this.hostEl.getBoundingClientRect();this.mentionX=i.left-s.left,this.mentionY=i.bottom-s.top,this.mentionTrigger=t,this.mentionSuggestions=this.config[t]||[],this.mentionQuery="",this.updateMentionFiltered(),this.mentionOpen=!0,this.renderMentionList();}},{key:"closeMention",value:function closeMention(){var _this$dropdownEl;this.mentionOpen=!1,this.mentionTrigger=null,this.mentionQuery="",this.mentionFiltered=[],(_this$dropdownEl=this.dropdownEl)===null||_this$dropdownEl===void 0?void 0:_this$dropdownEl.removeAttribute("open");}},{key:"handleMention",value:function handleMention(){if(!this.mentionOpen||!this.mentionTrigger)return;var t=window.getSelection();if(!t||!t.anchorNode)return;var i=t.anchorNode;if(i.nodeType!==Node.TEXT_NODE){var _i$childNodes;var _s2=((_i$childNodes=i.childNodes)===null||_i$childNodes===void 0?void 0:_i$childNodes[t.anchorOffset])||i.firstChild;(_s2===null||_s2===void 0?void 0:_s2.nodeType)===Node.TEXT_NODE&&(i=_s2);}var s=i&&i.nodeType===Node.TEXT_NODE&&i.textContent||"",n=s.lastIndexOf(this.mentionTrigger);n>=0?(this.mentionQuery=s.substring(n+1),this.updateMentionFiltered(),this.renderMentionList()):this.closeMention();}},{key:"updateMentionFiltered",value:function updateMentionFiltered(){var t=this.mentionQuery.toLowerCase();this.mentionFiltered=(this.mentionSuggestions||[]).filter(function(i){return i.label.toLowerCase().startsWith(t);});}},{key:"renderMentionList",value:function renderMentionList(){var _this3=this;if(this.dropdownEl&&this.menuEl&&this.triggerBtn)if(this.triggerBtn.style.position="absolute",this.triggerBtn.style.left="".concat(this.mentionX,"px"),this.triggerBtn.style.top="".concat(this.mentionY,"px"),this.menuEl.innerHTML="",this.mentionOpen&&this.mentionFiltered.length){var _iterator=_createForOfIteratorHelper(this.mentionFiltered),_step;try{var _loop2=function _loop2(){var t=_step.value;var i=document.createElement("nile-menu-item");i.textContent=t.label,i.addEventListener("mousedown",function(i){i.preventDefault(),_this3.selectMention(t);}),_this3.menuEl.appendChild(i);};for(_iterator.s();!(_step=_iterator.n()).done;){_loop2();}}catch(err){_iterator.e(err);}finally{_iterator.f();}this.dropdownEl.setAttribute("open","");}else this.dropdownEl.removeAttribute("open");}},{key:"selectMention",value:function selectMention(t){if(this.restoreSelection(),!this.lastRange||!this.mentionTrigger||!this.editorEl)return;var i=this.lastRange.startContainer,s=this.lastRange.startOffset;if(i.nodeType!==Node.TEXT_NODE){var _t=i.childNodes[s];if((_t===null||_t===void 0?void 0:_t.nodeType)!==Node.TEXT_NODE)return;i=_t,s=0;}var n=i,e=(n.textContent||"").lastIndexOf(this.mentionTrigger,s);if(e<0)return;var _o3=e+1+this.mentionQuery.length,h=document.createRange();h.setStart(n,e),h.setEnd(n,_o3),h.deleteContents();var r=document.createElement("span");r.classList.add("mention"),r.textContent="".concat(this.mentionTrigger).concat(t.label);var u=this.getTriggerColor(this.mentionTrigger);u&&(r.style.backgroundColor=u),h.insertNode(r);var c=document.createTextNode(" ");r.after(c);var l=window.getSelection(),d=document.createRange();d.setStartAfter(c),d.collapse(!0),l!==null&&l!==void 0&&l.removeAllRanges(),l!==null&&l!==void 0&&l.addRange(d),this.lastRange=d.cloneRange(),this.closeMention(),this.editorEl.dispatchEvent(new InputEvent("input",{bubbles:!0}));}}]);}(i);t([s({attribute:"mentions",converter:{fromAttribute:function fromAttribute(t){try{var _i4=JSON.parse(t),_s3={};for(var _i5=0,_Object$keys=Object.keys(_i4);_i5<_Object$keys.length;_i5++){var _t2=_Object$keys[_i5];var _n=_i4[_t2];Array.isArray(_n)&&(_s3[_t2]=_n.filter(function(t){return t&&"string"==typeof t.key&&"string"==typeof t.label;}).map(function(t){return{key:t.key,label:t.label};}));}return _s3;}catch(_unused2){return{};}},toAttribute:function toAttribute(t){return JSON.stringify(t);}}})],o.prototype,"mentions",void 0),t([s({attribute:"mentioncolors",converter:{fromAttribute:function fromAttribute(t){try{var _i6=JSON.parse(t);return _i6&&"object"==_typeof(_i6)?_i6:{};}catch(_unused3){return{};}},toAttribute:function toAttribute(t){return JSON.stringify(t!==null&&t!==void 0?t:{});}}})],o.prototype,"mentionColors",void 0),t([n()],o.prototype,"externalConfig",void 0),t([n()],o.prototype,"itemsConfig",void 0),t([n()],o.prototype,"itemsColors",void 0),o=t([e("nile-rte-mentions")],o);}};});
3
3
  //# sourceMappingURL=nile-rte-mentions.cjs.js.map