@aquera/nile-elements 0.1.67-beta-2.3 → 0.1.67-beta-2.4
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.
- package/demo/index.html +2 -2
- package/dist/index.js +113 -122
- package/dist/nile-rich-text-editor/nile-rich-text-editor.cjs.js +1 -1
- package/dist/nile-rich-text-editor/nile-rich-text-editor.cjs.js.map +1 -1
- package/dist/nile-rich-text-editor/nile-rich-text-editor.css.cjs.js +1 -1
- package/dist/nile-rich-text-editor/nile-rich-text-editor.css.cjs.js.map +1 -1
- package/dist/nile-rich-text-editor/nile-rich-text-editor.css.esm.js +121 -130
- package/dist/nile-rich-text-editor/nile-rich-text-editor.esm.js +1 -1
- package/dist/src/nile-rich-text-editor/nile-rich-text-editor.css.js +120 -129
- package/dist/src/nile-rich-text-editor/nile-rich-text-editor.css.js.map +1 -1
- package/dist/src/nile-rich-text-editor/nile-rich-text-editor.d.ts +2 -1
- package/dist/src/nile-rich-text-editor/nile-rich-text-editor.js +32 -25
- package/dist/src/nile-rich-text-editor/nile-rich-text-editor.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/nile-rich-text-editor/nile-rich-text-editor.css.ts +121 -130
- package/src/nile-rich-text-editor/nile-rich-text-editor.ts +40 -43
- package/vscode-html-custom-data.json +1 -1
@@ -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"./nile-rte-link.esm.js";import{t as o,s as r,a as h,b as l,c,d as a,n as u,e as d,r as f}from"./utils.esm.js";import{s as m}from"./nile-rich-text-editor.css.esm.js";const b={bold:"format_bold",italic:"format_italic",underline:"format_underline",link:"link_2",left:"format_align_left",center:"format_align_middle",right:"format_align_right",justify:"format_align_justify",ul:"format_list_bulleted",ol:"format_list_numbered",clear:"format_clear"};let p=class extends i{constructor(){super(...arguments),this.value="",this.singleLineEditor=!1,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.onEditorKeydown=t=>{if(this.singleLineEditor&&"Enter"===t.key&&t.shiftKey)return void t.preventDefault();if(t.ctrlKey&&"i"===t.key.toLowerCase()&&(t.preventDefault(),o(this.editorEl,"em"),this.updateContent(),this.updateToolbarState()),this.singleLineEditor&&"Enter"===t.key)return void t.preventDefault();if("Tab"!==t.key)return;t.preventDefault(),this.focusAndRestore();const i=window.getSelection();if(!i||0===i.rangeCount)return;const e=i.getRangeAt(0);if(t.shiftKey){if(e.collapsed&&e.startContainer.nodeType===Node.TEXT_NODE){const t=e.startContainer,s=e.startOffset,n=t.data.slice(0,s),o=n.replace(/(\t|[ \u00a0]{2})$/,"");if(o.length!==n.length){t.data=o+t.data.slice(s);const e=document.createRange();e.setStart(t,o.length),e.collapse(!0),i.removeAllRanges(),i.addRange(e),this.updateContent(),this.updateToolbarState()}}return}e.deleteContents();const s=document.createTextNode("\t");e.insertNode(s);const n=document.createRange();n.setStartAfter(s),n.collapse(!0),i.removeAllRanges(),i.addRange(n),this.updateContent(),this.updateToolbarState()},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.singleLineEditor&&(this.editorEl?.classList.add("single-line"),this.previewEl?.classList.add("single-line")),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),this.mentionsEl&&this.mentionsEl.addEventListener("mention-selected",(t=>{this.updateContentWithMention(t.detail)}))}updateContentWithMention(t){this.updateContent(),this.dispatchEvent(new CustomEvent("content-changed",{detail:{content:this.content,mention:t},bubbles:!0,composed:!0}))}disconnectedCallback(){document.removeEventListener("selectionchange",this.onSelectionChange,!0),this.mentionsEl&&this.mentionsEl.detach&&this.mentionsEl.detach(),super.disconnectedCallback()}updated(t){t.has("singleLineEditor")&&(this.editorEl&&this.editorEl.classList.toggle("single-line",this.singleLineEditor),this.previewEl&&this.previewEl.classList.toggle("single-line",this.singleLineEditor))}ensureEditor(){if(this.editorEl=this.querySelector(".editor"),!this.editorEl){const t=document.createElement("article");t.className="editor",t.setAttribute("contenteditable","true"),this.singleLineEditor&&t.classList.add("single-line"),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()}unwrapMention(t,i=!0){const e=t.parentNode;if(!e)return;const s=i?(t.textContent??"").replace(/\u200B/g,""):"",n=document.createTextNode(s);e.insertBefore(n,t),e.removeChild(t);const o=document.createRange();o.setStartAfter(n),o.collapse(!0);const r=window.getSelection();r?.removeAllRanges(),r?.addRange(o)}scrubBrokenMentions(){if(!this.editorEl)return;this.editorEl.querySelectorAll("span.mention").forEach((t=>{const i=t,e=i.getAttribute("data-mention-key"),s=i.getAttribute("data-mention-label"),n=i.getAttribute("data-mention-trigger")||"",o=(i.textContent??"").replace(/\u200B/g,"").trim(),r=!!e&&!!s&&o.length>0&&o.startsWith(n)&&o.includes(s);o&&r||this.unwrapMention(i,!0)}))}wireEditor(){this.editorEl.addEventListener("input",(()=>{this.ensureAtLeastOneParagraph(),this.scrubBrokenMentions(),this.updateContent()})),this.editorEl.addEventListener("mouseup",(()=>this.saveSelection())),this.editorEl.addEventListener("keyup",(()=>this.saveSelection())),this.editorEl.addEventListener("keydown",this.onEditorKeydown)}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-link"===i)return t.editorEl=this.editorEl,void t.addEventListener("link-changed",(()=>{this.updateContent(),this.updateToolbarState()}));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"),o=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(o)i.innerHTML=t.innerHTML,t.innerHTML="";else{const n=b[e];n?i.innerHTML=`<nile-icon name="${n}" size="20" color="black" aria-label="${s}"></nile-icon>`:i.textContent=s||e,t.innerHTML=""}if(!i.isConnected){const e=document.createElement("nile-tooltip");e.setAttribute("content",s),e.appendChild(i),t.appendChild(e)}i.setAttribute("aria-label",s),i.addEventListener("mousedown",(t=>t.preventDefault())),i.addEventListener("click",(()=>this.onToolbarCommand(e)));const r=this.buttonMap.get(e)??[];return r.push(i),void this.buttonMap.set(e,r)}if("nile-rte-select"!==i)"nile-rte-color"!==i||t.addEventListener("change",(t=>{this.focusAndRestore();const{mode:i,value:e}=t.detail;"backColor"===i?c(this.editorEl,e):a(this.editorEl,e),this.updateContent(),this.updateToolbarState()}));else{const i=t.getAttribute("type")||"";t.addEventListener("change",(t=>{this.focusAndRestore();const e=t.detail;"heading"===i?h(this.editorEl,e):"font"===i&&l(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":o(this.editorEl,"strong");break;case"italic":o(this.editorEl,"em");break;case"underline":o(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":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=d(i.startContainer,this.editorEl)||this.editorEl,o=(()=>{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})(),r=(()=>{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",o),this.setBtnActive("italic",r),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=f(s.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(e).backgroundColor;if(t&&!/transparent|rgba\(\s*0\s*,\s*0\s*,\s*0\s*,\s*0\s*\)/i.test(t)){const i=f(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(){if(!this.editorEl)return;this.ensureAtLeastOneParagraph();const t=this.editorEl.cloneNode(!0),i=document.createTreeWalker(this.editorEl,NodeFilter.SHOW_ELEMENT),e=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT),s=["font-weight","font-style","text-decoration","color","background-color","font-size","font-family","text-align","line-height","letter-spacing","white-space","vertical-align"];for(;i.nextNode()&&e.nextNode();){const t=i.currentNode,n=e.currentNode,o=window.getComputedStyle(t),r=s.map((t=>`${t}:${o.getPropertyValue(t)}`)).join(";");r.trim()&&n.setAttribute("style",r)}this.content=t.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})],p.prototype,"value",void 0),t([e({type:Boolean,attribute:"singlelineeditor"})],p.prototype,"singleLineEditor",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)}})],p.prototype,"mentions",void 0),t([s()],p.prototype,"content",void 0),p=t([n("nile-rich-text-editor")],p);export{p 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"./nile-rte-link.esm.js";import{t as o,s as r,a as h,b as l,c,d as a,n as u,e as d,r as f}from"./utils.esm.js";import{s as m}from"./nile-rich-text-editor.css.esm.js";const b={bold:"format_bold",italic:"format_italic",underline:"format_underline",link:"link_2",left:"format_align_left",center:"format_align_middle",right:"format_align_right",justify:"format_align_justify",ul:"format_list_bulleted",ol:"format_list_numbered",clear:"format_clear"};let p=class extends i{constructor(){super(...arguments),this.value="",this.singleLineEditor=!1,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.containerEl=null,this.mentionsEl=null,this.onEditorKeydown=t=>{if(this.singleLineEditor&&"Enter"===t.key&&t.shiftKey)return void t.preventDefault();if(t.ctrlKey&&"i"===t.key.toLowerCase()&&(t.preventDefault(),o(this.editorEl,"em"),this.updateContent(),this.updateToolbarState()),this.singleLineEditor&&"Enter"===t.key)return void t.preventDefault();if("Tab"!==t.key)return;t.preventDefault(),this.focusAndRestore();const i=window.getSelection();if(!i||0===i.rangeCount)return;const s=i.getRangeAt(0);if(t.shiftKey){if(s.collapsed&&s.startContainer.nodeType===Node.TEXT_NODE){const t=s.startContainer,e=s.startOffset,n=t.data.slice(0,e),o=n.replace(/(\t|[ \u00a0]{2})$/,"");if(o.length!==n.length){t.data=o+t.data.slice(e);const s=document.createRange();s.setStart(t,o.length),s.collapse(!0),i.removeAllRanges(),i.addRange(s),this.updateContent(),this.updateToolbarState()}}return}s.deleteContents();const e=document.createTextNode("\t");s.insertNode(e);const n=document.createRange();n.setStartAfter(e),n.collapse(!0),i.removeAllRanges(),i.addRange(n),this.updateContent(),this.updateToolbarState()},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}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.ensureStructure(),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()}ensureStructure(){this.toolbarEl=this.querySelector("nile-rte-toolbar"),this.previewEl=this.querySelector("nile-rte-preview"),this.containerEl=this.querySelector(".rte-container"),this.containerEl||(this.containerEl=document.createElement("div"),this.containerEl.className="rte-container",this.appendChild(this.containerEl)),this.ensureEditor(),this.toolbarEl&&this.toolbarEl.parentElement!==this.containerEl&&this.containerEl.appendChild(this.toolbarEl),this.editorEl.parentElement!==this.containerEl&&this.containerEl.appendChild(this.editorEl),this.previewEl&&(this.previewEl.parentElement!==this&&this.appendChild(this.previewEl),this.previewEl.previousElementSibling!==this.containerEl&&this.insertBefore(this.previewEl,this.containerEl.nextSibling))}updateContentWithMention(t){this.updateContent(),this.dispatchEvent(new CustomEvent("content-changed",{detail:{content:this.content,mention:t},bubbles:!0,composed:!0}))}disconnectedCallback(){document.removeEventListener("selectionchange",this.onSelectionChange,!0),this.mentionsEl&&this.mentionsEl.detach&&this.mentionsEl.detach(),super.disconnectedCallback()}updated(t){t.has("singleLineEditor")&&(this.editorEl&&this.editorEl.classList.toggle("single-line",this.singleLineEditor),this.previewEl&&this.previewEl.classList.toggle("single-line",this.singleLineEditor))}ensureEditor(){if(this.editorEl=this.querySelector(".editor"),!this.editorEl){const t=document.createElement("article");t.className="editor",t.setAttribute("contenteditable","true"),this.editorEl=t}this.editorEl.innerHTML.trim()||(this.editorEl.innerHTML="<p><br></p>")}unwrapMention(t,i=!0){const s=t.parentNode;if(!s)return;const e=i?(t.textContent??"").replace(/\u200B/g,""):"",n=document.createTextNode(e);s.insertBefore(n,t),s.removeChild(t);const o=document.createRange();o.setStartAfter(n),o.collapse(!0);const r=window.getSelection();r?.removeAllRanges(),r?.addRange(o)}scrubBrokenMentions(){if(!this.editorEl)return;this.editorEl.querySelectorAll("span.mention").forEach((t=>{const i=t,s=i.getAttribute("data-mention-key"),e=i.getAttribute("data-mention-label"),n=i.getAttribute("data-mention-trigger")||"",o=(i.textContent??"").replace(/\u200B/g,"").trim(),r=!!s&&!!e&&o.length>0&&o.startsWith(n)&&o.includes(e);o&&r||this.unwrapMention(i,!0)}))}wireEditor(){this.editorEl.addEventListener("input",(()=>{this.ensureAtLeastOneParagraph(),this.scrubBrokenMentions(),this.updateContent()})),this.editorEl.addEventListener("mouseup",(()=>this.saveSelection())),this.editorEl.addEventListener("keyup",(()=>this.saveSelection())),this.editorEl.addEventListener("keydown",this.onEditorKeydown)}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-link"===i)return t.editorEl=this.editorEl,void t.addEventListener("link-changed",(()=>{this.updateContent(),this.updateToolbarState()}));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"),o=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(o)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=""}if(!i.isConnected){const s=document.createElement("nile-tooltip");s.setAttribute("content",e),s.appendChild(i),t.appendChild(s)}i.setAttribute("aria-label",e),i.addEventListener("mousedown",(t=>t.preventDefault())),i.addEventListener("click",(()=>this.onToolbarCommand(s)));const r=this.buttonMap.get(s)??[];return r.push(i),void this.buttonMap.set(s,r)}if("nile-rte-select"!==i)"nile-rte-color"!==i||t.addEventListener("change",(t=>{this.focusAndRestore();const{mode:i,value:s}=t.detail;"backColor"===i?c(this.editorEl,s):a(this.editorEl,s),this.updateContent(),this.updateToolbarState()}));else{const i=t.getAttribute("type")||"";t.addEventListener("change",(t=>{this.focusAndRestore();const s=t.detail;"heading"===i?h(this.editorEl,s):"font"===i&&l(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":o(this.editorEl,"strong");break;case"italic":o(this.editorEl,"em");break;case"underline":o(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":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=u(i.startContainer)||this.editorEl,e=getComputedStyle(s),n=d(i.startContainer,this.editorEl)||this.editorEl,o=(()=>{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})(),r=(()=>{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,m=!!s.closest("li")&&s.closest("ul,ol")?.tagName.toLowerCase()||"";if(this.setBtnActive("bold",o),this.setBtnActive("italic",r),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=(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=f(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=f(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(){if(!this.editorEl)return;this.ensureAtLeastOneParagraph();const t=this.editorEl.cloneNode(!0),i=document.createTreeWalker(this.editorEl,NodeFilter.SHOW_ELEMENT),s=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT),e=["font-weight","font-style","text-decoration","color","background-color","font-size","font-family","text-align","line-height","letter-spacing","white-space","vertical-align"];for(;i.nextNode()&&s.nextNode();){const t=i.currentNode,n=s.currentNode,o=window.getComputedStyle(t),r=e.map((t=>`${t}:${o.getPropertyValue(t)}`)).join(";");r.trim()&&n.setAttribute("style",r)}this.content=t.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})],p.prototype,"value",void 0),t([s({type:Boolean,attribute:"singlelineeditor"})],p.prototype,"singleLineEditor",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)}})],p.prototype,"mentions",void 0),t([e()],p.prototype,"content",void 0),p=t([n("nile-rich-text-editor")],p);export{p as N};
|
@@ -1,142 +1,133 @@
|
|
1
|
-
// rte-styles.ts
|
1
|
+
// FILE: src/components/rte-styles.ts
|
2
2
|
import { css } from 'lit';
|
3
3
|
export const styles = css `
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
width: 478px;
|
25
|
-
min-height: 50px;
|
26
|
-
overflow-x: auto;
|
27
|
-
white-space: nowrap;
|
28
|
-
border-radius: 8px;
|
29
|
-
}
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
.toolbar, nile-rte-toolbar {
|
37
|
-
width:486px;
|
38
|
-
display:flex; align-items:center; gap:6px; padding:8px;
|
39
|
-
border:1px solid #e5e7eb; border-bottom:none; border-radius:8px 8px 0 0; background:#fff;
|
40
|
-
}
|
41
|
-
|
42
|
-
nile-rte-toolbar-item > button, .toolbar button, nile-rte-toolbar button {
|
43
|
-
border:1px solid #e5e7eb; background:#fff; border-radius:6px;
|
44
|
-
cursor:pointer;
|
45
|
-
}
|
46
|
-
|
47
|
-
|
48
|
-
/* Ensure clicks hit the button (not nested icon internals) */
|
49
|
-
nile-rte-toolbar-item > button nile-icon { pointer-events:none; }
|
50
|
-
|
51
|
-
nile-rte-toolbar-item > button.active { border-color:#2563eb; background:#eff6ff; }
|
52
|
-
nile-rte-select select { height:32px; border:1px solid #e5e7eb; border-radius:6px; background:#fff; }
|
53
|
-
nile-rte-color input[type="color"] { height:32px; width:36px; border:1px solid #e5e7eb; padding:0; border-radius:6px; background:#fff; }
|
54
|
-
nile-rte-divider { width:1px; height:20px; background:#e5e7eb; display:inline-block; margin:0 4px; }
|
55
|
-
|
56
|
-
.editor p { margin:1em 0; }
|
57
|
-
.editor h1, .preview h1 { all: revert; font-size:2em, display: block;
|
58
|
-
font-size: 2em;
|
59
|
-
margin-top: 0.67em;
|
60
|
-
margin-bottom: 0.67em;
|
61
|
-
margin-left: 0;
|
62
|
-
margin-right: 0;
|
63
|
-
font-weight: bold; }
|
64
|
-
.editor h2, .preview h2 { all: revert; display: block;
|
65
|
-
font-size: 1.5em;
|
66
|
-
margin-top: 0.83em;
|
67
|
-
margin-bottom: 0.83em;
|
68
|
-
margin-left: 0;
|
69
|
-
margin-right: 0;
|
70
|
-
font-weight: bold;}
|
71
|
-
.editor h3 { font-size:1.17em }
|
72
|
-
.editor h4 { font-size:1em }
|
73
|
-
.editor h5 { font-size:0.83em }
|
74
|
-
.editor h6 { font-size:0.67em }
|
75
|
-
|
76
|
-
.editor { min-height:160px; max-width:478px; padding:12px; border:1px solid #e5e7eb; border-radius:0 0 8px 8px; background:#fff; outline:none;
|
77
|
-
tab-size: 4;
|
78
|
-
-moz-tab-size: 4;
|
79
|
-
word-break: break-word;
|
80
|
-
}
|
81
|
-
nile-rte-preview { display:block; margin-top:10px; padding:10px; border:1px dashed #cbd5e1; border-radius:8px; background:#fafafa; max-width:478px; }
|
82
|
-
|
83
|
-
nile-rte-preview.single-line {
|
84
|
-
width: 478px;
|
85
|
-
min-height: 50px;
|
86
|
-
overflow-x: auto;
|
87
|
-
white-space: nowrap;
|
88
|
-
}
|
89
|
-
|
90
|
-
.rte-color-trigger {
|
91
|
-
display: inline-flex;
|
4
|
+
.editor { all: revert; }
|
5
|
+
|
6
|
+
nile-rich-text-editor {
|
7
|
+
position: relative;
|
8
|
+
display: block;
|
9
|
+
font-family: inherit;
|
10
|
+
}
|
11
|
+
|
12
|
+
/* --- Card 1: Toolbar + Editor --- */
|
13
|
+
.rte-container {
|
14
|
+
width: 100%;
|
15
|
+
border: 1px solid #e5e7eb;
|
16
|
+
border-radius: 8px;
|
17
|
+
background: #fff;
|
18
|
+
box-sizing: border-box;
|
19
|
+
}
|
20
|
+
|
21
|
+
/* Toolbar inside container */
|
22
|
+
.rte-container nile-rte-toolbar {
|
23
|
+
display: flex;
|
92
24
|
align-items: center;
|
93
|
-
|
94
|
-
|
95
|
-
border-
|
25
|
+
gap: 6px;
|
26
|
+
padding: 8px;
|
27
|
+
border-bottom: 1px solid #e5e7eb;
|
96
28
|
background: #fff;
|
97
|
-
|
98
|
-
border:none;
|
99
|
-
|
29
|
+
border-radius: 8px 8px 0 0;
|
100
30
|
|
101
|
-
|
102
|
-
|
103
|
-
width:32px; height:32px; padding:0px 6px;
|
104
|
-
}
|
105
|
-
.rte-color-trigger .glyph-stack {
|
106
|
-
display: grid; /* stack vertically */
|
107
|
-
grid-auto-rows: max-content;
|
108
|
-
align-items: center;
|
109
|
-
justify-items: center;
|
110
|
-
line-height: 1;
|
31
|
+
width: 100%;
|
32
|
+
box-sizing: border-box;
|
111
33
|
}
|
112
34
|
|
113
|
-
.rte-color-trigger .glyph {
|
114
|
-
font-size: 14px;
|
115
|
-
line-height: 1;
|
116
|
-
margin-bottom: 2px;
|
117
|
-
}
|
118
35
|
|
119
|
-
.rte-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
36
|
+
.rte-container .editor {
|
37
|
+
min-height: 160px;
|
38
|
+
width: 100%;
|
39
|
+
padding: 12px;
|
40
|
+
background: #fff;
|
41
|
+
border-radius: 0 0 8px 8px;
|
42
|
+
outline: none;
|
43
|
+
tab-size: 4;
|
44
|
+
-moz-tab-size: 4;
|
45
|
+
word-break: break-word;
|
46
|
+
box-sizing: border-box;
|
47
|
+
border-radius: 8px;
|
48
|
+
}
|
49
|
+
|
50
|
+
/* --- Card 2: Preview --- */
|
51
|
+
/* Preview card */
|
52
|
+
nile-rte-preview {
|
53
|
+
display: block;
|
54
|
+
width: 100%;
|
55
|
+
margin-top: 16px;
|
56
|
+
padding: 12px;
|
57
|
+
border: 1px dashed #e5e7eb;
|
58
|
+
border-radius: 8px;
|
59
|
+
background: #fafafa;
|
60
|
+
box-sizing: border-box;
|
61
|
+
word-wrap: break-word;
|
135
62
|
}
|
136
63
|
|
137
|
-
|
138
|
-
|
139
|
-
|
64
|
+
|
65
|
+
/* Toolbar button styling */
|
66
|
+
nile-rte-toolbar-item nile-button::part(base) {
|
67
|
+
width: 32px;
|
68
|
+
height: 32px;
|
69
|
+
padding: 0px 6px;
|
70
|
+
border: none;
|
71
|
+
}
|
72
|
+
|
73
|
+
nile-rte-toolbar-item > button,
|
74
|
+
nile-rte-toolbar button {
|
75
|
+
border: 1px solid #e5e7eb;
|
76
|
+
background: #fff;
|
77
|
+
border-radius: 6px;
|
78
|
+
cursor: pointer;
|
79
|
+
}
|
80
|
+
|
81
|
+
nile-rte-toolbar-item > button nile-icon { pointer-events: none; }
|
82
|
+
|
83
|
+
nile-rte-toolbar-item > button.active {
|
84
|
+
border-color: #2563eb;
|
85
|
+
background: #eff6ff;
|
86
|
+
}
|
87
|
+
|
88
|
+
/* Heading normalization */
|
89
|
+
.editor p { margin: 1em 0; }
|
90
|
+
.editor h1, .preview h1 {
|
91
|
+
font-size: 2em;
|
92
|
+
margin: 0.67em 0;
|
93
|
+
font-weight: bold;
|
94
|
+
}
|
95
|
+
.editor h2, .preview h2 {
|
96
|
+
font-size: 1.5em;
|
97
|
+
margin: 0.83em 0;
|
98
|
+
font-weight: bold;
|
99
|
+
}
|
100
|
+
.editor h3 { font-size: 1.17em; }
|
101
|
+
.editor h4 { font-size: 1em; }
|
102
|
+
.editor h5 { font-size: 0.83em; }
|
103
|
+
.editor h6 { font-size: 0.67em; }
|
104
|
+
|
105
|
+
/* Single-line variant */
|
106
|
+
.editor.single-line {
|
107
|
+
min-height: 50px;
|
108
|
+
max-height: 50px;
|
109
|
+
overflow-x: auto;
|
110
|
+
white-space: nowrap;
|
111
|
+
padding: 0px 12px 0px 12px;
|
112
|
+
scrollbar-width: none;
|
113
|
+
-ms-overflow-style: none;
|
114
|
+
}
|
115
|
+
nile-rte-preview.single-line {
|
116
|
+
min-height: 50px;
|
117
|
+
max-height: 50px;
|
118
|
+
padding: 0px 12px 0px 12px;
|
119
|
+
overflow-x: auto;
|
120
|
+
white-space: nowrap;
|
121
|
+
scrollbar-width: none;
|
122
|
+
-ms-overflow-style: none;
|
123
|
+
}
|
124
|
+
nile-rte-divider {
|
125
|
+
margin: 0 4px;
|
126
|
+
display: inline-block;
|
127
|
+
height: 24px;
|
128
|
+
width: 1px;
|
129
|
+
background: #E6E9EB;
|
130
|
+
}
|
140
131
|
`;
|
141
132
|
export default [styles];
|
142
133
|
//# sourceMappingURL=nile-rich-text-editor.css.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"nile-rich-text-editor.css.js","sourceRoot":"","sources":["../../../src/nile-rich-text-editor/nile-rich-text-editor.css.ts"],"names":[],"mappings":"AAAA,
|
1
|
+
{"version":3,"file":"nile-rich-text-editor.css.js","sourceRoot":"","sources":["../../../src/nile-rich-text-editor/nile-rich-text-editor.css.ts"],"names":[],"mappings":"AAAA,qCAAqC;AACrC,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAE1B,MAAM,CAAC,MAAM,MAAM,GAAG,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgIxB,CAAC;AAEF,eAAe,CAAC,MAAM,CAAC,CAAC","sourcesContent":["// FILE: src/components/rte-styles.ts\nimport { css } from 'lit';\n\nexport const styles = css`\n .editor { all: revert; }\n\n nile-rich-text-editor {\n position: relative;\n display: block;\n font-family: inherit;\n }\n\n /* --- Card 1: Toolbar + Editor --- */\n .rte-container {\n width: 100%;\n border: 1px solid #e5e7eb;\n border-radius: 8px;\n background: #fff;\n box-sizing: border-box;\n }\n\n /* Toolbar inside container */\n.rte-container nile-rte-toolbar {\n display: flex;\n align-items: center;\n gap: 6px;\n padding: 8px;\n border-bottom: 1px solid #e5e7eb;\n background: #fff;\n border-radius: 8px 8px 0 0;\n\n width: 100%; \n box-sizing: border-box; \n}\n\n\n .rte-container .editor {\n min-height: 160px;\n width: 100%;\n padding: 12px;\n background: #fff;\n border-radius: 0 0 8px 8px;\n outline: none;\n tab-size: 4;\n -moz-tab-size: 4;\n word-break: break-word;\n box-sizing: border-box;\n border-radius: 8px;\n }\n\n /* --- Card 2: Preview --- */\n /* Preview card */\nnile-rte-preview {\n display: block;\n width: 100%;\n margin-top: 16px; \n padding: 12px;\n border: 1px dashed #e5e7eb;\n border-radius: 8px;\n background: #fafafa;\n box-sizing: border-box;\n word-wrap: break-word;\n}\n\n\n /* Toolbar button styling */\n nile-rte-toolbar-item nile-button::part(base) {\n width: 32px;\n height: 32px;\n padding: 0px 6px;\n border: none;\n }\n\n nile-rte-toolbar-item > button,\n nile-rte-toolbar button {\n border: 1px solid #e5e7eb;\n background: #fff;\n border-radius: 6px;\n cursor: pointer;\n }\n\n nile-rte-toolbar-item > button nile-icon { pointer-events: none; }\n\n nile-rte-toolbar-item > button.active {\n border-color: #2563eb;\n background: #eff6ff;\n }\n\n /* Heading normalization */\n .editor p { margin: 1em 0; }\n .editor h1, .preview h1 {\n font-size: 2em;\n margin: 0.67em 0;\n font-weight: bold;\n }\n .editor h2, .preview h2 {\n font-size: 1.5em;\n margin: 0.83em 0;\n font-weight: bold;\n }\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 /* Single-line variant */\n .editor.single-line {\n min-height: 50px;\n max-height: 50px;\n overflow-x: auto;\n white-space: nowrap;\n padding: 0px 12px 0px 12px;\n scrollbar-width: none;\n -ms-overflow-style: none;\n }\n nile-rte-preview.single-line {\n min-height: 50px;\n max-height: 50px;\n padding: 0px 12px 0px 12px;\n overflow-x: auto;\n white-space: nowrap;\n scrollbar-width: none;\n -ms-overflow-style: none;\n }\n nile-rte-divider { \n margin: 0 4px;\n display: inline-block;\n height: 24px;\n width: 1px;\n background: #E6E9EB;\n }\n`;\n\nexport default [styles];\n"]}
|
@@ -13,7 +13,6 @@ type MentionsConfig = Record<string, {
|
|
13
13
|
}[]>;
|
14
14
|
export declare class NileRichTextEditor extends LitElement {
|
15
15
|
protected createRenderRoot(): this;
|
16
|
-
protected shouldUpdate(): boolean;
|
17
16
|
value: string;
|
18
17
|
singleLineEditor: boolean;
|
19
18
|
mentions: MentionsConfig;
|
@@ -29,9 +28,11 @@ export declare class NileRichTextEditor extends LitElement {
|
|
29
28
|
private bgColorInput;
|
30
29
|
private colorSwatchEl;
|
31
30
|
private bgSwatchEl;
|
31
|
+
private containerEl;
|
32
32
|
private mentionsEl;
|
33
33
|
private injectCss;
|
34
34
|
connectedCallback(): void;
|
35
|
+
private ensureStructure;
|
35
36
|
private updateContentWithMention;
|
36
37
|
disconnectedCallback(): void;
|
37
38
|
protected updated(changed: Map<string, any>): void;
|
@@ -28,6 +28,7 @@ const DEFAULT_ICONS = {
|
|
28
28
|
let NileRichTextEditor = class NileRichTextEditor extends LitElement {
|
29
29
|
constructor() {
|
30
30
|
super(...arguments);
|
31
|
+
// protected shouldUpdate() { return false; }
|
31
32
|
this.value = '';
|
32
33
|
this.singleLineEditor = false;
|
33
34
|
this.mentions = {};
|
@@ -42,6 +43,7 @@ let NileRichTextEditor = class NileRichTextEditor extends LitElement {
|
|
42
43
|
this.bgColorInput = null;
|
43
44
|
this.colorSwatchEl = null;
|
44
45
|
this.bgSwatchEl = null;
|
46
|
+
this.containerEl = null;
|
45
47
|
this.mentionsEl = null;
|
46
48
|
this.onEditorKeydown = (e) => {
|
47
49
|
if (this.singleLineEditor && e.key === 'Enter' && e.shiftKey) {
|
@@ -110,7 +112,6 @@ let NileRichTextEditor = class NileRichTextEditor extends LitElement {
|
|
110
112
|
};
|
111
113
|
}
|
112
114
|
createRenderRoot() { return this; }
|
113
|
-
shouldUpdate() { return false; }
|
114
115
|
injectCss(cssText) {
|
115
116
|
if (this.querySelector('style[data-rte-style]'))
|
116
117
|
return;
|
@@ -122,13 +123,7 @@ let NileRichTextEditor = class NileRichTextEditor extends LitElement {
|
|
122
123
|
connectedCallback() {
|
123
124
|
super.connectedCallback();
|
124
125
|
this.injectCss(styles.cssText);
|
125
|
-
this.
|
126
|
-
this.previewEl = this.querySelector('nile-rte-preview');
|
127
|
-
if (this.singleLineEditor) {
|
128
|
-
this.editorEl?.classList.add('single-line');
|
129
|
-
this.previewEl?.classList.add('single-line');
|
130
|
-
}
|
131
|
-
this.ensureEditor();
|
126
|
+
this.ensureStructure();
|
132
127
|
if (this.value && !this.editorEl.innerHTML.trim()) {
|
133
128
|
this.editorEl.innerHTML = this.value;
|
134
129
|
}
|
@@ -143,11 +138,35 @@ let NileRichTextEditor = class NileRichTextEditor extends LitElement {
|
|
143
138
|
this.wireEditor();
|
144
139
|
this.updateToolbarState();
|
145
140
|
this.syncPreview();
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
141
|
+
}
|
142
|
+
ensureStructure() {
|
143
|
+
this.toolbarEl = this.querySelector('nile-rte-toolbar');
|
144
|
+
this.previewEl = this.querySelector('nile-rte-preview');
|
145
|
+
// container for toolbar + editor
|
146
|
+
this.containerEl = this.querySelector('.rte-container');
|
147
|
+
if (!this.containerEl) {
|
148
|
+
this.containerEl = document.createElement('div');
|
149
|
+
this.containerEl.className = 'rte-container';
|
150
|
+
this.appendChild(this.containerEl);
|
151
|
+
}
|
152
|
+
// ensure editor
|
153
|
+
this.ensureEditor();
|
154
|
+
// put toolbar + editor inside container
|
155
|
+
if (this.toolbarEl && this.toolbarEl.parentElement !== this.containerEl) {
|
156
|
+
this.containerEl.appendChild(this.toolbarEl);
|
157
|
+
}
|
158
|
+
if (this.editorEl.parentElement !== this.containerEl) {
|
159
|
+
this.containerEl.appendChild(this.editorEl);
|
160
|
+
}
|
161
|
+
// 👉 move preview OUTSIDE container, right after it
|
162
|
+
if (this.previewEl) {
|
163
|
+
if (this.previewEl.parentElement !== this) {
|
164
|
+
this.appendChild(this.previewEl);
|
165
|
+
}
|
166
|
+
// ensure preview is placed AFTER container
|
167
|
+
if (this.previewEl.previousElementSibling !== this.containerEl) {
|
168
|
+
this.insertBefore(this.previewEl, this.containerEl.nextSibling);
|
169
|
+
}
|
151
170
|
}
|
152
171
|
}
|
153
172
|
updateContentWithMention(mentionDetail) {
|
@@ -184,23 +203,11 @@ let NileRichTextEditor = class NileRichTextEditor extends LitElement {
|
|
184
203
|
const editor = document.createElement('article');
|
185
204
|
editor.className = 'editor';
|
186
205
|
editor.setAttribute('contenteditable', 'true');
|
187
|
-
if (this.singleLineEditor)
|
188
|
-
editor.classList.add('single-line');
|
189
|
-
if (this.toolbarEl?.nextSibling) {
|
190
|
-
this.insertBefore(editor, this.toolbarEl.nextSibling);
|
191
|
-
}
|
192
|
-
else if (this.previewEl) {
|
193
|
-
this.insertBefore(editor, this.previewEl);
|
194
|
-
}
|
195
|
-
else {
|
196
|
-
this.appendChild(editor);
|
197
|
-
}
|
198
206
|
this.editorEl = editor;
|
199
207
|
}
|
200
208
|
if (!this.editorEl.innerHTML.trim()) {
|
201
209
|
this.editorEl.innerHTML = '<p><br></p>';
|
202
210
|
}
|
203
|
-
this.ensureAtLeastOneParagraph();
|
204
211
|
}
|
205
212
|
unwrapMention(span, preserveText = true) {
|
206
213
|
const parent = span.parentNode;
|