@aquera/nile-elements 2.0.27 → 2.0.28
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/README.md +4 -1
- package/dist/index.js +2 -2
- package/dist/nile-rich-text-editor/nile-rte-link.cjs.js +1 -1
- package/dist/nile-rich-text-editor/nile-rte-link.cjs.js.map +1 -1
- package/dist/nile-rich-text-editor/nile-rte-link.esm.js +1 -1
- package/dist/src/nile-rich-text-editor/nile-rte-link.js +1 -1
- package/dist/src/nile-rich-text-editor/nile-rte-link.js.map +1 -1
- package/dist/src/nile-rich-text-editor/nile-rte-link.test.js +7 -0
- package/dist/src/nile-rich-text-editor/nile-rte-link.test.js.map +1 -1
- package/dist/src/version.js +1 -1
- package/dist/src/version.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/nile-rich-text-editor/nile-rte-link.test.ts +10 -0
- package/src/nile-rich-text-editor/nile-rte-link.ts +1 -1
package/README.md
CHANGED
|
@@ -91,7 +91,10 @@ To run a local development server that serves the basic demo located in `demo/in
|
|
|
91
91
|
|
|
92
92
|
In this section, you can find the updates for each release of `nile-elements`. It's a good practice to maintain detailed release notes to help users and developers understand what changes have been made from one version to another and how these changes might affect their projects.
|
|
93
93
|
|
|
94
|
-
#### Version 2.0.28 (November
|
|
94
|
+
#### Version 2.0.28 (November 27, 2026)
|
|
95
|
+
- Nile RTE Link: The link popover now follows the theme. Its background uses a design token instead of a hardcoded white, so it shows correctly in dark theme (UIF-1444)
|
|
96
|
+
|
|
97
|
+
#### Version 2.0.27 (November 26, 2026)
|
|
95
98
|
- Nile Code Editor: Added a `portal` property that mounts autocomplete and tooltip popups on `document.body` with fixed positioning, so dialogs and drawers no longer clip them. Popup styles stay in sync with `readonly`, `customThemeCSS`, `autoCompleteStyle` and theme changes. Off by default (UIF-1442)
|
|
96
99
|
- Nile Detail: Added `contentDisabled` (also available through the selection `config`). In `variant="selection"` it locks the selection: item checkboxes, Select All, Clear and Restore ignore input and emit no events, while expand/collapse, search, "show selected", scrolling and programmatic `selected` keep working (UIF-1443)
|
|
97
100
|
- Nile Combobox: Fixed "show selected only". It turns off when nothing is selected, re-filters when the value changes and stays applied when `data` is replaced. The options list is capped at 150px (UIF-1441)
|
package/dist/index.js
CHANGED
|
@@ -20058,7 +20058,7 @@ nile-badge::part(content) {
|
|
|
20058
20058
|
</div>
|
|
20059
20059
|
</div>
|
|
20060
20060
|
</nile-popover>
|
|
20061
|
-
`}};e([de({type:String,attribute:!0,reflect:!0})],Nk.prototype,"mode",void 0),e([de({type:String,attribute:!0,reflect:!0})],Nk.prototype,"label",void 0),e([de({type:String,attribute:!0,reflect:!0})],Nk.prototype,"value",void 0),e([de({type:Array,attribute:!0,reflect:!0})],Nk.prototype,"palette",void 0),e([he()],Nk.prototype,"recentColors",void 0),Nk=e([ce("nile-rte-color")],Nk);let pk=class extends le{createRenderRoot(){return this}shouldUpdate(){return!1}};pk=e([ce("nile-rte-divider")],pk);let Dk=class extends le{createRenderRoot(){return this}shouldUpdate(){return!1}};Dk=e([ce("nile-rte-preview")],Dk);let yk=class extends le{constructor(){super(...arguments),this.displayFormat=!1,this.mentions={},this.mentionFormat={},this.itemsFormats={},this.mentionColors={},this.externalConfig={},this.itemsConfig={},this.mentionActiveIndex=-1,this.itemsColors={},this.editorEl=null,this.hostEl=null,this.dropdownEl=null,this.menuEl=null,this.lastRange=null,this.mentionOpen=!1,this.mentionTrigger=null,this.mentionQuery="",this.mentionSuggestions=[],this.mentionFiltered=[],this.mentionX=0,this.mentionY=0,this.triggerBtn=null,this.mo=null,this.onSelectionChange=()=>{if(!this.editorEl)return;const e=document.getSelection();if(!e||0===e.rangeCount)return;const t=e.getRangeAt(0);this.editorEl.contains(t.commonAncestorContainer)&&(this.lastRange=t.cloneRange())},this.saveSelection=()=>{const e=window.getSelection();e&&e.rangeCount&&(this.lastRange=e.getRangeAt(0).cloneRange())},this.onEditorInput=()=>{if(this.mentionOpen)return void this.handleMention();const e=window.getSelection();if(!e||!e.anchorNode)return;let t=e.anchorNode;if(t.nodeType!==Node.TEXT_NODE&&t.firstChild?.nodeType===Node.TEXT_NODE&&(t=t.firstChild),!t||t.nodeType!==Node.TEXT_NODE)return;const i=t.textContent||"",n=this.config;for(const t of Object.keys(n)){const n=i.lastIndexOf(t);if(-1!==n){const i=e.focusOffset;if(i>=n+t.length&&i<=n+t.length+1)return void this.openMention(t)}}},this.onEditorKeyUp=e=>{this.saveSelection();const t=e.key,i=this.config;if(t&&i[t])return this.mentionOpen&&this.mentionTrigger!==t&&this.closeMention(),void this.openMention(t);this.mentionOpen&&this.handleMention()},this.onEditorKeyDown=e=>{if(!this.mentionOpen)return;const t=e.key;if("ArrowDown"===t||"ArrowUp"===t){if(e.preventDefault(),!this.mentionFiltered.length)return;this.mentionActiveIndex="ArrowDown"===t?(this.mentionActiveIndex+1)%this.mentionFiltered.length:(this.mentionActiveIndex-1+this.mentionFiltered.length)%this.mentionFiltered.length,this.renderMentionList()}else"Enter"===t?this.mentionActiveIndex>=0&&this.mentionFiltered[this.mentionActiveIndex]&&(e.preventDefault(),this.selectMention(this.mentionFiltered[this.mentionActiveIndex])):"Escape"===t&&(e.preventDefault(),this.closeMention())},this.repositionMention=()=>{if(!this.mentionOpen||!this.hostEl||!this.triggerBtn)return;const e=this.getCaretClientRect();if(!e)return;const t=this.hostEl.getBoundingClientRect();this.mentionX=e.left-t.left,this.mentionY=e.bottom-t.top,this.triggerBtn.style.left=`${this.mentionX}px`,this.triggerBtn.style.top=`${this.mentionY}px`}}createRenderRoot(){return this}getTriggerFormat(e){const t=this.itemsFormats[e]||{},i=this.mentionFormat[e]||{};return{prefix:t.prefix??i.prefix??"",suffix:t.suffix??i.suffix??""}}formatLabel(e,t){const{prefix:i,suffix:n}=this.getTriggerFormat(e);return`${i??""}${t}${n??""}`}get config(){return{...this.externalConfig,...this.mentions,...this.itemsConfig}}attach(e,t){this.editorEl=e,this.hostEl=t,this.injectStyles(),this.ensureMentionDropdown(),this.rebuildConfigFromChildren(),this.mo=new MutationObserver((()=>this.rebuildConfigFromChildren())),this.mo.observe(this,{childList:!0,subtree:!0,attributes:!0}),this.editorEl.addEventListener("input",this.onEditorInput),this.editorEl.addEventListener("mouseup",this.saveSelection),this.editorEl.addEventListener("keyup",this.onEditorKeyUp),this.editorEl.addEventListener("keydown",this.onEditorKeyDown),this.editorEl.addEventListener("scroll",this.repositionMention),document.addEventListener("selectionchange",this.onSelectionChange,!0)}detach(){this.mo&&(this.mo.disconnect(),this.mo=null),this.editorEl&&(this.editorEl.removeEventListener("input",this.onEditorInput),this.editorEl.removeEventListener("mouseup",this.saveSelection),this.editorEl.removeEventListener("keyup",this.onEditorKeyUp),this.editorEl.removeEventListener("keydown",this.onEditorKeyDown),this.editorEl.removeEventListener("scroll",this.repositionMention)),document.removeEventListener("selectionchange",this.onSelectionChange,!0)}setExternalConfig(e){this.externalConfig=e||{}}disconnectedCallback(){this.detach(),super.disconnectedCallback()}rebuildConfigFromChildren(){const e={},t={},i={},n=Array.from(this.querySelectorAll("nile-rte-mentions-item"));for(const o of n){const n=o.mentionsCharacter??o.getAttribute("mentionscharacter")??"";if(!n||"string"!=typeof n)continue;let r=o.mentionsData??(()=>{const e=o.getAttribute("mentionsdata");if(!e)return null;try{const t=JSON.parse(e);return Array.isArray(t)?t.filter((e=>e&&"string"==typeof e.key&&"string"==typeof e.label)):[]}catch{return[]}})();const s=o.mentionsColor??o.getAttribute("mentionscolor")??"",a=o.mentionsPrefix??o.getAttribute("mentionsprefix")??"",l=o.mentionsSuffix??o.getAttribute("mentionssuffix")??"";Array.isArray(r)||(r=[]),e[n]=r,s&&(t[n]=String(s)),(a||l)&&(i[n]={prefix:a,suffix:l})}this.itemsConfig=e,this.itemsColors=t,this.itemsFormats=i}injectStyles(){if(this.querySelector("style[data-mentions-style]"))return;const e=document.createElement("style");e.setAttribute("data-mentions-style","true"),e.textContent="\n .mention-dropdown {\n position: absolute; z-index: 1000; list-style: none; margin: 0; padding: 4px;\n border: 1px solid #e5e7eb; border-radius: 6px; background: #fff;\n box-shadow: 0 4px 10px rgba(0,0,0,.08); max-height: 180px; overflow: auto; font-size: 14px;\n }\n .mention-dropdown li { padding: 6px 8px; cursor: pointer; border-radius: 4px; }\n .mention-dropdown li:hover { background: #f1f5f9; }\n .mention { background: #eef2ff; padding: 0 3px; border-radius: 3px; }\n nile-menu.mentions-menu::part(menu__items-wrapper){\n max-height: 260px;\n overflow-y: auto;\n }\n .mentions-menu nile-menu-item.active {\n background: #dbeafe; /* highlight */\n outline: none;\n}\n\n\n ",this.insertBefore(e,this.firstChild)}getTriggerColor(e){return this.itemsColors[e]??this.mentionColors[e]}ensureMentionDropdown(){if(this.dropdownEl||!this.hostEl)return;const e=document.createElement("nile-dropdown");e.style.zIndex="1000";const t=document.createElement("nile-button");t.setAttribute("slot","trigger"),t.style.position="absolute",t.style.width="1px",t.style.height="1px",t.style.border="0",t.style.padding="0",t.style.opacity="0",t.style.pointerEvents="none",e.appendChild(t),this.triggerBtn=t;const i=document.createElement("nile-menu");i.classList.add("mentions-menu"),e.appendChild(i),this.hostEl.appendChild(e),this.dropdownEl=e,this.menuEl=i}restoreSelection(){if(!this.lastRange)return;const e=document.getSelection();e&&(e.removeAllRanges(),e.addRange(this.lastRange))}getCaretClientRect(){const e=document.getSelection();if(!e||0===e.rangeCount)return null;const t=e.getRangeAt(0).cloneRange();t.collapse(!1);const i=t.getClientRects();if(i&&i.length>0)return i[0];const n=document.createElement("span");n.setAttribute("data-caret-marker","1"),n.textContent="",t.insertNode(n);const o=n.getBoundingClientRect(),r=document.createRange();return r.setStartAfter(n),r.collapse(!0),e.removeAllRanges(),e.addRange(r),n.remove(),o||null}openMention(e){if(this.saveSelection(),!this.editorEl||!this.dropdownEl||!this.hostEl)return;const t=this.getCaretClientRect();if(!t)return;const i=this.hostEl.getBoundingClientRect();this.mentionX=t.left-i.left,this.mentionY=t.bottom-i.top,this.mentionTrigger=e,this.mentionSuggestions=this.config[e]||[],this.mentionQuery="",this.updateMentionFiltered(),this.mentionActiveIndex=this.mentionFiltered.length?0:-1,this.mentionOpen=!0,this.renderMentionList(),this.dispatchEvent(new CustomEvent("nile-mention-opened",{detail:{trigger:e,suggestions:this.mentionSuggestions},bubbles:!0,composed:!0}))}closeMention(){this.mentionOpen=!1,this.mentionTrigger=null,this.mentionQuery="",this.mentionFiltered=[],this.dropdownEl?.removeAttribute("open")}handleMention(){if(!this.mentionOpen||!this.mentionTrigger)return;const e=window.getSelection();if(!e||!e.anchorNode)return;let t=e.anchorNode;if(t.nodeType!==Node.TEXT_NODE){const i=t.childNodes?.[e.anchorOffset]||t.firstChild;i?.nodeType===Node.TEXT_NODE&&(t=i)}const i=t&&t.nodeType===Node.TEXT_NODE&&t.textContent||"",n=i.lastIndexOf(this.mentionTrigger);n>=0?(this.mentionQuery=i.substring(n+1),this.updateMentionFiltered(),this.renderMentionList()):this.closeMention()}updateMentionFiltered(){const e=this.mentionQuery.toLowerCase();this.mentionFiltered=(this.mentionSuggestions||[]).filter((t=>t.label.toLowerCase().startsWith(e)))}renderMentionList(){this.dropdownEl&&this.menuEl&&this.triggerBtn&&(this.triggerBtn.style.left=`${this.mentionX}px`,this.triggerBtn.style.top=`${this.mentionY}px`,this.menuEl.innerHTML="",this.mentionOpen&&this.mentionFiltered.length?(this.mentionFiltered.forEach(((e,t)=>{const i=document.createElement("nile-menu-item");i.textContent=e.label,i.setAttribute("role","option"),t===this.mentionActiveIndex?(i.classList.add("active"),i.setAttribute("aria-selected","true")):(i.classList.remove("active"),i.removeAttribute("aria-selected")),i.addEventListener("mouseenter",(()=>{this.mentionActiveIndex=t,this.renderMentionList()})),i.addEventListener("pointerdown",(t=>{t.preventDefault(),this.selectMention(e)})),this.menuEl?.appendChild(i)})),this.dropdownEl.setAttribute("open","")):this.dropdownEl.removeAttribute("open"))}selectMention(e){if(this.restoreSelection(),!this.lastRange||!this.mentionTrigger||!this.editorEl)return;const t=this.mentionTrigger;let i=this.lastRange.startContainer,n=this.lastRange.startOffset;if(i.nodeType!==Node.TEXT_NODE){const e=i.childNodes[n];if(e?.nodeType!==Node.TEXT_NODE)return;i=e,n=0}const o=i,r=(o.textContent||"").lastIndexOf(this.mentionTrigger,n);if(r<0)return;const s=r+1+this.mentionQuery.length,a=document.createRange();a.setStart(o,r),a.setEnd(o,s),a.deleteContents();const l=document.createElement("span");l.classList.add("mention");const M=this.getTriggerFormat(this.mentionTrigger);this.displayFormat?l.textContent=`${M.prefix??""}${e.label}${M.suffix??""}`:(l.textContent=`${this.mentionTrigger}${e.label}`,M.prefix&&l.setAttribute("data-mention-prefix",M.prefix),M.suffix&&l.setAttribute("data-mention-suffix",M.suffix)),l.setAttribute("data-mention-key",e.key),l.setAttribute("data-mention-label",e.label),l.setAttribute("data-mention-trigger",this.mentionTrigger);const c=this.getTriggerColor(this.mentionTrigger);c&&(l.style.backgroundColor=c),a.insertNode(l);const g=document.createTextNode(" ");l.after(g);const u=window.getSelection(),d=document.createRange();d.setStartAfter(g),d.collapse(!0),u?.removeAllRanges(),u?.addRange(d),this.lastRange=d.cloneRange(),this.closeMention(),this.dispatchEvent(new CustomEvent("nile-mention-selected",{detail:{trigger:t,key:e.key,label:e.label,prefix:M.prefix??"",suffix:M.suffix??""},bubbles:!0,composed:!0})),this.editorEl.dispatchEvent(new InputEvent("input",{bubbles:!0}))}};e([de({type:Boolean,attribute:"displayformat",reflect:!0})],yk.prototype,"displayFormat",void 0),e([de({attribute:"mentions",converter:{fromAttribute:e=>{try{const t=JSON.parse(e),i={};for(const e of Object.keys(t)){const n=t[e];Array.isArray(n)&&(i[e]=n.filter((e=>e&&"string"==typeof e.key&&"string"==typeof e.label)).map((e=>({key:e.key,label:e.label}))))}return i}catch{return{}}},toAttribute:e=>JSON.stringify(e)}})],yk.prototype,"mentions",void 0),e([de({attribute:"mentionformat",converter:{fromAttribute:e=>{try{const t=JSON.parse(e);return t&&"object"==typeof t?t:{}}catch{return{}}},toAttribute:e=>JSON.stringify(e??{})}})],yk.prototype,"mentionFormat",void 0),e([he()],yk.prototype,"itemsFormats",void 0),e([de({attribute:"mentioncolors",converter:{fromAttribute:e=>{try{const t=JSON.parse(e);return t&&"object"==typeof t?t:{}}catch{return{}}},toAttribute:e=>JSON.stringify(e??{})}})],yk.prototype,"mentionColors",void 0),e([he()],yk.prototype,"externalConfig",void 0),e([he()],yk.prototype,"itemsConfig",void 0),e([he()],yk.prototype,"mentionActiveIndex",void 0),e([he()],yk.prototype,"itemsColors",void 0),yk=e([ce("nile-rte-mentions")],yk);let Ik=class extends le{constructor(){super(...arguments),this.newTab=!1,this.disabled=!1,this.showTextSupport=!1,this.placeholder="Type or paste link here",this.textPlaceholder="Display text",this.label="Link",this.linkValue="",this.textValue="",this.hasActiveLink=!1,this.popoverStyle="",this.selectionRange=null,this.activeAnchor=null,this.ignoreBlur=!1,this.isApplying=!1,this.onScroll=()=>{this.closePopover()},this.onOpen=()=>{if(this.disabled)return;const e=document.getSelection();if(!e||0===e.rangeCount)return;if(!this.editorEl.contains(e.getRangeAt(0).commonAncestorContainer))return;this.selectionRange=e.getRangeAt(0).cloneRange(),this.activeAnchor=null,this.hasActiveLink=!1;let t=this.selectionRange.startContainer;for(;t&&t!==this.editorEl;){if(t instanceof HTMLAnchorElement){this.activeAnchor=t,this.hasActiveLink=!0;break}t=t.parentNode}this.linkValue=this.activeAnchor?this.displayUrl(this.activeAnchor.href):"",this.showTextSupport&&(this.activeAnchor?this.textValue=this.activeAnchor.textContent||"":this.selectionRange.collapsed?this.textValue="":this.textValue=this.selectionRange.toString()),this.positionPopover(),this.openPopover(),requestAnimationFrame((()=>{const e=this.querySelectorAll("nile-input"),t=e.length>1?e[1]:e[0];t?.focus()}))},this.onInputKeydown=e=>{if("Escape"===e.key||"Enter"===e.key)if(e.preventDefault(),e.stopPropagation(),"Escape"!==e.key){this.isApplying=!0;try{this.applyLink()}finally{this.isApplying=!1}}else this.closePopover()},this.onInputBlur=()=>{this.ignoreBlur||this.isApplying||requestAnimationFrame((()=>{if(this.ignoreBlur||this.isApplying)return;const e=this.querySelector("nile-popover");e?.matches(":focus-within")||this.closePopover()}))},this.onLinkInput=e=>{this.linkValue=e.detail.value},this.onTextInput=e=>{this.textValue=e.detail.value},this.onPopoverMousedown=()=>{this.ignoreBlur=!0},this.onPopoverMouseup=()=>{this.ignoreBlur=!1},this.onToolbarButtonMousedown=e=>{e.preventDefault()},this.onActionMousedown=e=>{e.preventDefault(),this.ignoreBlur=!0},this.onApplyClick=()=>{this.isApplying=!0,this.applyLink(),this.isApplying=!1,this.ignoreBlur=!1},this.onUnlinkClick=()=>{this.isApplying=!0,this.onRemove(),this.isApplying=!1,this.ignoreBlur=!1}}createRenderRoot(){return this}connectedCallback(){super.connectedCallback(),this.injectCss("\n nile-popover.rte-link-popover::part(popover) {\n min-width: 340px;\n max-width: 420px;\n background: white;\n border: 1px solid var(--nile-colors-neutral-400, var(--ng-componentcolors-utility-gray-400));\n border-radius: 8px;\n padding: 0;\n gap: 0;\n overflow: hidden;\n height: auto;\n box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);\n }\n\n .link-popup-wrap {\n display: flex;\n flex-direction: column;\n gap: 12px;\n padding: 12px;\n }\n\n .link-popup-wrap nile-input {\n width: 100%;\n }\n\n .link-popup-wrap .link-input-row {\n width: 100%;\n }\n\n .link-popup-wrap .link-actions-row {\n display: flex;\n align-items: flex-end;\n gap: 4px;\n width: 100%;\n }\n\n .link-popup-wrap .link-actions-row nile-input {\n flex: 1;\n min-width: 0;\n }\n\n \n nile-button.rte-link-button::part(base) {\n border: none;\n height: 32px;\n width: 32px;\n }\n nile-button.rte-edit-button::part(base) {\n border: none;\n height: 32px;\n width: 32px;\n flex-shrink: 0;\n }\n ")}injectCss(e){if(this.querySelector("style[data-rte-link-style]"))return;const t=document.createElement("style");t.setAttribute("data-rte-link-style","true"),t.textContent=e,this.insertBefore(t,this.firstChild)}normalizeUrl(e){return/^(https?:|mailto:|tel:)/i.test(e)?e:`https://${e}`}displayUrl(e){return e}getSelectionRect(){if(!this.selectionRange)return null;let e=this.selectionRange.getBoundingClientRect();if(0===e.width&&0===e.height){const t=document.createElement("span");t.textContent="";this.selectionRange.cloneRange().insertNode(t),e=t.getBoundingClientRect(),t.remove()}return e}positionPopover(){const e=this.getSelectionRect();e&&(this.popoverStyle=`\n position: fixed;\n top: ${e.bottom+8}px;\n left: ${e.left+e.width/2}px;\n transform: translateX(-50%);\n z-index: 1000;\n `)}openPopover(){requestAnimationFrame((()=>{const e=this.querySelector("nile-popover");e&&(e.isShow=!0),window.addEventListener("scroll",this.onScroll,!0)}))}closePopover(){const e=this.querySelector("nile-popover");e&&(e.isShow=!1),window.removeEventListener("scroll",this.onScroll,!0),this.linkValue="",this.textValue="",this.selectionRange=null,this.activeAnchor=null,this.hasActiveLink=!1,this.popoverStyle=""}unwrapLink(e){for(;e.firstChild;)e.parentNode?.insertBefore(e.firstChild,e);e.remove()}applyLink(){if(!(this.selectionRange instanceof Range))return;let e=this.linkValue.trim();if(!e)return;if(/^javascript:/i.test(e))return;/^(https?:\/\/|mailto:|tel:|\/)/i.test(e)||(e=`https://${e}`),this.editorEl.focus();const t=document.getSelection();if(!t)return;t.removeAllRanges(),t.addRange(this.selectionRange);const i=this.showTextSupport&&this.textValue.trim()?this.textValue.trim():"";if(this.activeAnchor)this.activeAnchor.href=e,i&&(this.activeAnchor.textContent=i),this.newTab?(this.activeAnchor.target="_blank",this.activeAnchor.rel="noopener noreferrer"):(this.activeAnchor.removeAttribute("target"),this.activeAnchor.removeAttribute("rel"));else{const t=document.createElement("a");if(t.href=e,this.newTab?(t.target="_blank",t.rel="noopener noreferrer"):(t.removeAttribute("target"),t.removeAttribute("rel")),i)this.selectionRange.deleteContents(),t.textContent=i,this.selectionRange.insertNode(t);else if(this.selectionRange.collapsed)t.textContent=e,this.selectionRange.insertNode(t);else try{this.selectionRange.surroundContents(t)}catch{const e=this.selectionRange.extractContents();t.appendChild(e),this.selectionRange.insertNode(t)}}this.emit(e),this.closePopover()}onRemove(){this.activeAnchor&&(this.unwrapLink(this.activeAnchor),this.emit(""),this.closePopover())}emit(e){this.dispatchEvent(new CustomEvent("nile-link-changed",{detail:{href:e},bubbles:!0,composed:!0}))}render(){const e=this.disabled?"var(--nile-colors-neutral-500, var(--ng-colors-fg-disabled-subtle))":"var(--nile-colors-dark-900, var(--ng-colors-text-primary-900))";return R`
|
|
20061
|
+
`}};e([de({type:String,attribute:!0,reflect:!0})],Nk.prototype,"mode",void 0),e([de({type:String,attribute:!0,reflect:!0})],Nk.prototype,"label",void 0),e([de({type:String,attribute:!0,reflect:!0})],Nk.prototype,"value",void 0),e([de({type:Array,attribute:!0,reflect:!0})],Nk.prototype,"palette",void 0),e([he()],Nk.prototype,"recentColors",void 0),Nk=e([ce("nile-rte-color")],Nk);let pk=class extends le{createRenderRoot(){return this}shouldUpdate(){return!1}};pk=e([ce("nile-rte-divider")],pk);let Dk=class extends le{createRenderRoot(){return this}shouldUpdate(){return!1}};Dk=e([ce("nile-rte-preview")],Dk);let yk=class extends le{constructor(){super(...arguments),this.displayFormat=!1,this.mentions={},this.mentionFormat={},this.itemsFormats={},this.mentionColors={},this.externalConfig={},this.itemsConfig={},this.mentionActiveIndex=-1,this.itemsColors={},this.editorEl=null,this.hostEl=null,this.dropdownEl=null,this.menuEl=null,this.lastRange=null,this.mentionOpen=!1,this.mentionTrigger=null,this.mentionQuery="",this.mentionSuggestions=[],this.mentionFiltered=[],this.mentionX=0,this.mentionY=0,this.triggerBtn=null,this.mo=null,this.onSelectionChange=()=>{if(!this.editorEl)return;const e=document.getSelection();if(!e||0===e.rangeCount)return;const t=e.getRangeAt(0);this.editorEl.contains(t.commonAncestorContainer)&&(this.lastRange=t.cloneRange())},this.saveSelection=()=>{const e=window.getSelection();e&&e.rangeCount&&(this.lastRange=e.getRangeAt(0).cloneRange())},this.onEditorInput=()=>{if(this.mentionOpen)return void this.handleMention();const e=window.getSelection();if(!e||!e.anchorNode)return;let t=e.anchorNode;if(t.nodeType!==Node.TEXT_NODE&&t.firstChild?.nodeType===Node.TEXT_NODE&&(t=t.firstChild),!t||t.nodeType!==Node.TEXT_NODE)return;const i=t.textContent||"",n=this.config;for(const t of Object.keys(n)){const n=i.lastIndexOf(t);if(-1!==n){const i=e.focusOffset;if(i>=n+t.length&&i<=n+t.length+1)return void this.openMention(t)}}},this.onEditorKeyUp=e=>{this.saveSelection();const t=e.key,i=this.config;if(t&&i[t])return this.mentionOpen&&this.mentionTrigger!==t&&this.closeMention(),void this.openMention(t);this.mentionOpen&&this.handleMention()},this.onEditorKeyDown=e=>{if(!this.mentionOpen)return;const t=e.key;if("ArrowDown"===t||"ArrowUp"===t){if(e.preventDefault(),!this.mentionFiltered.length)return;this.mentionActiveIndex="ArrowDown"===t?(this.mentionActiveIndex+1)%this.mentionFiltered.length:(this.mentionActiveIndex-1+this.mentionFiltered.length)%this.mentionFiltered.length,this.renderMentionList()}else"Enter"===t?this.mentionActiveIndex>=0&&this.mentionFiltered[this.mentionActiveIndex]&&(e.preventDefault(),this.selectMention(this.mentionFiltered[this.mentionActiveIndex])):"Escape"===t&&(e.preventDefault(),this.closeMention())},this.repositionMention=()=>{if(!this.mentionOpen||!this.hostEl||!this.triggerBtn)return;const e=this.getCaretClientRect();if(!e)return;const t=this.hostEl.getBoundingClientRect();this.mentionX=e.left-t.left,this.mentionY=e.bottom-t.top,this.triggerBtn.style.left=`${this.mentionX}px`,this.triggerBtn.style.top=`${this.mentionY}px`}}createRenderRoot(){return this}getTriggerFormat(e){const t=this.itemsFormats[e]||{},i=this.mentionFormat[e]||{};return{prefix:t.prefix??i.prefix??"",suffix:t.suffix??i.suffix??""}}formatLabel(e,t){const{prefix:i,suffix:n}=this.getTriggerFormat(e);return`${i??""}${t}${n??""}`}get config(){return{...this.externalConfig,...this.mentions,...this.itemsConfig}}attach(e,t){this.editorEl=e,this.hostEl=t,this.injectStyles(),this.ensureMentionDropdown(),this.rebuildConfigFromChildren(),this.mo=new MutationObserver((()=>this.rebuildConfigFromChildren())),this.mo.observe(this,{childList:!0,subtree:!0,attributes:!0}),this.editorEl.addEventListener("input",this.onEditorInput),this.editorEl.addEventListener("mouseup",this.saveSelection),this.editorEl.addEventListener("keyup",this.onEditorKeyUp),this.editorEl.addEventListener("keydown",this.onEditorKeyDown),this.editorEl.addEventListener("scroll",this.repositionMention),document.addEventListener("selectionchange",this.onSelectionChange,!0)}detach(){this.mo&&(this.mo.disconnect(),this.mo=null),this.editorEl&&(this.editorEl.removeEventListener("input",this.onEditorInput),this.editorEl.removeEventListener("mouseup",this.saveSelection),this.editorEl.removeEventListener("keyup",this.onEditorKeyUp),this.editorEl.removeEventListener("keydown",this.onEditorKeyDown),this.editorEl.removeEventListener("scroll",this.repositionMention)),document.removeEventListener("selectionchange",this.onSelectionChange,!0)}setExternalConfig(e){this.externalConfig=e||{}}disconnectedCallback(){this.detach(),super.disconnectedCallback()}rebuildConfigFromChildren(){const e={},t={},i={},n=Array.from(this.querySelectorAll("nile-rte-mentions-item"));for(const o of n){const n=o.mentionsCharacter??o.getAttribute("mentionscharacter")??"";if(!n||"string"!=typeof n)continue;let r=o.mentionsData??(()=>{const e=o.getAttribute("mentionsdata");if(!e)return null;try{const t=JSON.parse(e);return Array.isArray(t)?t.filter((e=>e&&"string"==typeof e.key&&"string"==typeof e.label)):[]}catch{return[]}})();const s=o.mentionsColor??o.getAttribute("mentionscolor")??"",a=o.mentionsPrefix??o.getAttribute("mentionsprefix")??"",l=o.mentionsSuffix??o.getAttribute("mentionssuffix")??"";Array.isArray(r)||(r=[]),e[n]=r,s&&(t[n]=String(s)),(a||l)&&(i[n]={prefix:a,suffix:l})}this.itemsConfig=e,this.itemsColors=t,this.itemsFormats=i}injectStyles(){if(this.querySelector("style[data-mentions-style]"))return;const e=document.createElement("style");e.setAttribute("data-mentions-style","true"),e.textContent="\n .mention-dropdown {\n position: absolute; z-index: 1000; list-style: none; margin: 0; padding: 4px;\n border: 1px solid #e5e7eb; border-radius: 6px; background: #fff;\n box-shadow: 0 4px 10px rgba(0,0,0,.08); max-height: 180px; overflow: auto; font-size: 14px;\n }\n .mention-dropdown li { padding: 6px 8px; cursor: pointer; border-radius: 4px; }\n .mention-dropdown li:hover { background: #f1f5f9; }\n .mention { background: #eef2ff; padding: 0 3px; border-radius: 3px; }\n nile-menu.mentions-menu::part(menu__items-wrapper){\n max-height: 260px;\n overflow-y: auto;\n }\n .mentions-menu nile-menu-item.active {\n background: #dbeafe; /* highlight */\n outline: none;\n}\n\n\n ",this.insertBefore(e,this.firstChild)}getTriggerColor(e){return this.itemsColors[e]??this.mentionColors[e]}ensureMentionDropdown(){if(this.dropdownEl||!this.hostEl)return;const e=document.createElement("nile-dropdown");e.style.zIndex="1000";const t=document.createElement("nile-button");t.setAttribute("slot","trigger"),t.style.position="absolute",t.style.width="1px",t.style.height="1px",t.style.border="0",t.style.padding="0",t.style.opacity="0",t.style.pointerEvents="none",e.appendChild(t),this.triggerBtn=t;const i=document.createElement("nile-menu");i.classList.add("mentions-menu"),e.appendChild(i),this.hostEl.appendChild(e),this.dropdownEl=e,this.menuEl=i}restoreSelection(){if(!this.lastRange)return;const e=document.getSelection();e&&(e.removeAllRanges(),e.addRange(this.lastRange))}getCaretClientRect(){const e=document.getSelection();if(!e||0===e.rangeCount)return null;const t=e.getRangeAt(0).cloneRange();t.collapse(!1);const i=t.getClientRects();if(i&&i.length>0)return i[0];const n=document.createElement("span");n.setAttribute("data-caret-marker","1"),n.textContent="",t.insertNode(n);const o=n.getBoundingClientRect(),r=document.createRange();return r.setStartAfter(n),r.collapse(!0),e.removeAllRanges(),e.addRange(r),n.remove(),o||null}openMention(e){if(this.saveSelection(),!this.editorEl||!this.dropdownEl||!this.hostEl)return;const t=this.getCaretClientRect();if(!t)return;const i=this.hostEl.getBoundingClientRect();this.mentionX=t.left-i.left,this.mentionY=t.bottom-i.top,this.mentionTrigger=e,this.mentionSuggestions=this.config[e]||[],this.mentionQuery="",this.updateMentionFiltered(),this.mentionActiveIndex=this.mentionFiltered.length?0:-1,this.mentionOpen=!0,this.renderMentionList(),this.dispatchEvent(new CustomEvent("nile-mention-opened",{detail:{trigger:e,suggestions:this.mentionSuggestions},bubbles:!0,composed:!0}))}closeMention(){this.mentionOpen=!1,this.mentionTrigger=null,this.mentionQuery="",this.mentionFiltered=[],this.dropdownEl?.removeAttribute("open")}handleMention(){if(!this.mentionOpen||!this.mentionTrigger)return;const e=window.getSelection();if(!e||!e.anchorNode)return;let t=e.anchorNode;if(t.nodeType!==Node.TEXT_NODE){const i=t.childNodes?.[e.anchorOffset]||t.firstChild;i?.nodeType===Node.TEXT_NODE&&(t=i)}const i=t&&t.nodeType===Node.TEXT_NODE&&t.textContent||"",n=i.lastIndexOf(this.mentionTrigger);n>=0?(this.mentionQuery=i.substring(n+1),this.updateMentionFiltered(),this.renderMentionList()):this.closeMention()}updateMentionFiltered(){const e=this.mentionQuery.toLowerCase();this.mentionFiltered=(this.mentionSuggestions||[]).filter((t=>t.label.toLowerCase().startsWith(e)))}renderMentionList(){this.dropdownEl&&this.menuEl&&this.triggerBtn&&(this.triggerBtn.style.left=`${this.mentionX}px`,this.triggerBtn.style.top=`${this.mentionY}px`,this.menuEl.innerHTML="",this.mentionOpen&&this.mentionFiltered.length?(this.mentionFiltered.forEach(((e,t)=>{const i=document.createElement("nile-menu-item");i.textContent=e.label,i.setAttribute("role","option"),t===this.mentionActiveIndex?(i.classList.add("active"),i.setAttribute("aria-selected","true")):(i.classList.remove("active"),i.removeAttribute("aria-selected")),i.addEventListener("mouseenter",(()=>{this.mentionActiveIndex=t,this.renderMentionList()})),i.addEventListener("pointerdown",(t=>{t.preventDefault(),this.selectMention(e)})),this.menuEl?.appendChild(i)})),this.dropdownEl.setAttribute("open","")):this.dropdownEl.removeAttribute("open"))}selectMention(e){if(this.restoreSelection(),!this.lastRange||!this.mentionTrigger||!this.editorEl)return;const t=this.mentionTrigger;let i=this.lastRange.startContainer,n=this.lastRange.startOffset;if(i.nodeType!==Node.TEXT_NODE){const e=i.childNodes[n];if(e?.nodeType!==Node.TEXT_NODE)return;i=e,n=0}const o=i,r=(o.textContent||"").lastIndexOf(this.mentionTrigger,n);if(r<0)return;const s=r+1+this.mentionQuery.length,a=document.createRange();a.setStart(o,r),a.setEnd(o,s),a.deleteContents();const l=document.createElement("span");l.classList.add("mention");const M=this.getTriggerFormat(this.mentionTrigger);this.displayFormat?l.textContent=`${M.prefix??""}${e.label}${M.suffix??""}`:(l.textContent=`${this.mentionTrigger}${e.label}`,M.prefix&&l.setAttribute("data-mention-prefix",M.prefix),M.suffix&&l.setAttribute("data-mention-suffix",M.suffix)),l.setAttribute("data-mention-key",e.key),l.setAttribute("data-mention-label",e.label),l.setAttribute("data-mention-trigger",this.mentionTrigger);const c=this.getTriggerColor(this.mentionTrigger);c&&(l.style.backgroundColor=c),a.insertNode(l);const g=document.createTextNode(" ");l.after(g);const u=window.getSelection(),d=document.createRange();d.setStartAfter(g),d.collapse(!0),u?.removeAllRanges(),u?.addRange(d),this.lastRange=d.cloneRange(),this.closeMention(),this.dispatchEvent(new CustomEvent("nile-mention-selected",{detail:{trigger:t,key:e.key,label:e.label,prefix:M.prefix??"",suffix:M.suffix??""},bubbles:!0,composed:!0})),this.editorEl.dispatchEvent(new InputEvent("input",{bubbles:!0}))}};e([de({type:Boolean,attribute:"displayformat",reflect:!0})],yk.prototype,"displayFormat",void 0),e([de({attribute:"mentions",converter:{fromAttribute:e=>{try{const t=JSON.parse(e),i={};for(const e of Object.keys(t)){const n=t[e];Array.isArray(n)&&(i[e]=n.filter((e=>e&&"string"==typeof e.key&&"string"==typeof e.label)).map((e=>({key:e.key,label:e.label}))))}return i}catch{return{}}},toAttribute:e=>JSON.stringify(e)}})],yk.prototype,"mentions",void 0),e([de({attribute:"mentionformat",converter:{fromAttribute:e=>{try{const t=JSON.parse(e);return t&&"object"==typeof t?t:{}}catch{return{}}},toAttribute:e=>JSON.stringify(e??{})}})],yk.prototype,"mentionFormat",void 0),e([he()],yk.prototype,"itemsFormats",void 0),e([de({attribute:"mentioncolors",converter:{fromAttribute:e=>{try{const t=JSON.parse(e);return t&&"object"==typeof t?t:{}}catch{return{}}},toAttribute:e=>JSON.stringify(e??{})}})],yk.prototype,"mentionColors",void 0),e([he()],yk.prototype,"externalConfig",void 0),e([he()],yk.prototype,"itemsConfig",void 0),e([he()],yk.prototype,"mentionActiveIndex",void 0),e([he()],yk.prototype,"itemsColors",void 0),yk=e([ce("nile-rte-mentions")],yk);let Ik=class extends le{constructor(){super(...arguments),this.newTab=!1,this.disabled=!1,this.showTextSupport=!1,this.placeholder="Type or paste link here",this.textPlaceholder="Display text",this.label="Link",this.linkValue="",this.textValue="",this.hasActiveLink=!1,this.popoverStyle="",this.selectionRange=null,this.activeAnchor=null,this.ignoreBlur=!1,this.isApplying=!1,this.onScroll=()=>{this.closePopover()},this.onOpen=()=>{if(this.disabled)return;const e=document.getSelection();if(!e||0===e.rangeCount)return;if(!this.editorEl.contains(e.getRangeAt(0).commonAncestorContainer))return;this.selectionRange=e.getRangeAt(0).cloneRange(),this.activeAnchor=null,this.hasActiveLink=!1;let t=this.selectionRange.startContainer;for(;t&&t!==this.editorEl;){if(t instanceof HTMLAnchorElement){this.activeAnchor=t,this.hasActiveLink=!0;break}t=t.parentNode}this.linkValue=this.activeAnchor?this.displayUrl(this.activeAnchor.href):"",this.showTextSupport&&(this.activeAnchor?this.textValue=this.activeAnchor.textContent||"":this.selectionRange.collapsed?this.textValue="":this.textValue=this.selectionRange.toString()),this.positionPopover(),this.openPopover(),requestAnimationFrame((()=>{const e=this.querySelectorAll("nile-input"),t=e.length>1?e[1]:e[0];t?.focus()}))},this.onInputKeydown=e=>{if("Escape"===e.key||"Enter"===e.key)if(e.preventDefault(),e.stopPropagation(),"Escape"!==e.key){this.isApplying=!0;try{this.applyLink()}finally{this.isApplying=!1}}else this.closePopover()},this.onInputBlur=()=>{this.ignoreBlur||this.isApplying||requestAnimationFrame((()=>{if(this.ignoreBlur||this.isApplying)return;const e=this.querySelector("nile-popover");e?.matches(":focus-within")||this.closePopover()}))},this.onLinkInput=e=>{this.linkValue=e.detail.value},this.onTextInput=e=>{this.textValue=e.detail.value},this.onPopoverMousedown=()=>{this.ignoreBlur=!0},this.onPopoverMouseup=()=>{this.ignoreBlur=!1},this.onToolbarButtonMousedown=e=>{e.preventDefault()},this.onActionMousedown=e=>{e.preventDefault(),this.ignoreBlur=!0},this.onApplyClick=()=>{this.isApplying=!0,this.applyLink(),this.isApplying=!1,this.ignoreBlur=!1},this.onUnlinkClick=()=>{this.isApplying=!0,this.onRemove(),this.isApplying=!1,this.ignoreBlur=!1}}createRenderRoot(){return this}connectedCallback(){super.connectedCallback(),this.injectCss("\n nile-popover.rte-link-popover::part(popover) {\n min-width: 340px;\n max-width: 420px;\n background: var(--nile-colors-white-base, var(--ng-colors-bg-primary));\n border: 1px solid var(--nile-colors-neutral-400, var(--ng-componentcolors-utility-gray-400));\n border-radius: 8px;\n padding: 0;\n gap: 0;\n overflow: hidden;\n height: auto;\n box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);\n }\n\n .link-popup-wrap {\n display: flex;\n flex-direction: column;\n gap: 12px;\n padding: 12px;\n }\n\n .link-popup-wrap nile-input {\n width: 100%;\n }\n\n .link-popup-wrap .link-input-row {\n width: 100%;\n }\n\n .link-popup-wrap .link-actions-row {\n display: flex;\n align-items: flex-end;\n gap: 4px;\n width: 100%;\n }\n\n .link-popup-wrap .link-actions-row nile-input {\n flex: 1;\n min-width: 0;\n }\n\n \n nile-button.rte-link-button::part(base) {\n border: none;\n height: 32px;\n width: 32px;\n }\n nile-button.rte-edit-button::part(base) {\n border: none;\n height: 32px;\n width: 32px;\n flex-shrink: 0;\n }\n ")}injectCss(e){if(this.querySelector("style[data-rte-link-style]"))return;const t=document.createElement("style");t.setAttribute("data-rte-link-style","true"),t.textContent=e,this.insertBefore(t,this.firstChild)}normalizeUrl(e){return/^(https?:|mailto:|tel:)/i.test(e)?e:`https://${e}`}displayUrl(e){return e}getSelectionRect(){if(!this.selectionRange)return null;let e=this.selectionRange.getBoundingClientRect();if(0===e.width&&0===e.height){const t=document.createElement("span");t.textContent="";this.selectionRange.cloneRange().insertNode(t),e=t.getBoundingClientRect(),t.remove()}return e}positionPopover(){const e=this.getSelectionRect();e&&(this.popoverStyle=`\n position: fixed;\n top: ${e.bottom+8}px;\n left: ${e.left+e.width/2}px;\n transform: translateX(-50%);\n z-index: 1000;\n `)}openPopover(){requestAnimationFrame((()=>{const e=this.querySelector("nile-popover");e&&(e.isShow=!0),window.addEventListener("scroll",this.onScroll,!0)}))}closePopover(){const e=this.querySelector("nile-popover");e&&(e.isShow=!1),window.removeEventListener("scroll",this.onScroll,!0),this.linkValue="",this.textValue="",this.selectionRange=null,this.activeAnchor=null,this.hasActiveLink=!1,this.popoverStyle=""}unwrapLink(e){for(;e.firstChild;)e.parentNode?.insertBefore(e.firstChild,e);e.remove()}applyLink(){if(!(this.selectionRange instanceof Range))return;let e=this.linkValue.trim();if(!e)return;if(/^javascript:/i.test(e))return;/^(https?:\/\/|mailto:|tel:|\/)/i.test(e)||(e=`https://${e}`),this.editorEl.focus();const t=document.getSelection();if(!t)return;t.removeAllRanges(),t.addRange(this.selectionRange);const i=this.showTextSupport&&this.textValue.trim()?this.textValue.trim():"";if(this.activeAnchor)this.activeAnchor.href=e,i&&(this.activeAnchor.textContent=i),this.newTab?(this.activeAnchor.target="_blank",this.activeAnchor.rel="noopener noreferrer"):(this.activeAnchor.removeAttribute("target"),this.activeAnchor.removeAttribute("rel"));else{const t=document.createElement("a");if(t.href=e,this.newTab?(t.target="_blank",t.rel="noopener noreferrer"):(t.removeAttribute("target"),t.removeAttribute("rel")),i)this.selectionRange.deleteContents(),t.textContent=i,this.selectionRange.insertNode(t);else if(this.selectionRange.collapsed)t.textContent=e,this.selectionRange.insertNode(t);else try{this.selectionRange.surroundContents(t)}catch{const e=this.selectionRange.extractContents();t.appendChild(e),this.selectionRange.insertNode(t)}}this.emit(e),this.closePopover()}onRemove(){this.activeAnchor&&(this.unwrapLink(this.activeAnchor),this.emit(""),this.closePopover())}emit(e){this.dispatchEvent(new CustomEvent("nile-link-changed",{detail:{href:e},bubbles:!0,composed:!0}))}render(){const e=this.disabled?"var(--nile-colors-neutral-500, var(--ng-colors-fg-disabled-subtle))":"var(--nile-colors-dark-900, var(--ng-colors-text-primary-900))";return R`
|
|
20062
20062
|
<nile-lite-tooltip content=${this.label}>
|
|
20063
20063
|
<nile-button
|
|
20064
20064
|
variant="tertiary"
|
|
@@ -20677,7 +20677,7 @@ nile-rich-text-editor[disabled] .editor figure.rte-image {
|
|
|
20677
20677
|
${this._renderTrigger()}
|
|
20678
20678
|
${e}
|
|
20679
20679
|
</nile-popover>
|
|
20680
|
-
`:e}};e([de({type:String,attribute:!0,reflect:!0})],Pk.prototype,"type",void 0),e([de({type:String,attribute:!0,reflect:!0})],Pk.prototype,"value",void 0),e([de({type:String,reflect:!0})],Pk.prototype,"swatchTooltip",void 0),e([de({type:Number,reflect:!0})],Pk.prototype,"recentColorsCount",void 0),e([de({type:Boolean,reflect:!0})],Pk.prototype,"noFill",void 0),e([de({type:String,reflect:!0})],Pk.prototype,"mode",void 0),e([de({type:Boolean,reflect:!0})],Pk.prototype,"showCanvas",void 0),e([de({type:Boolean,reflect:!0})],Pk.prototype,"showHue",void 0),e([de({type:Boolean,reflect:!0})],Pk.prototype,"showInputs",void 0),e([de({type:Boolean,reflect:!0})],Pk.prototype,"showActions",void 0),e([de({type:Boolean,reflect:!0,attribute:!0})],Pk.prototype,"open",void 0),e([de({attribute:"palette",converter:{fromAttribute:e=>{try{const t=JSON.parse(e);return Array.isArray(t)?t.map((e=>"string"==typeof e?{color:e,name:e}:e&&"string"==typeof e.color?{color:e.color,name:e.name||e.color}:null)).filter(Boolean):[]}catch{return[]}},toAttribute:e=>JSON.stringify(e)}})],Pk.prototype,"palette",void 0),e([he()],Pk.prototype,"_view",void 0),e([he()],Pk.prototype,"_recentColors",void 0),e([he()],Pk.prototype,"_hue",void 0),e([he()],Pk.prototype,"_sat",void 0),e([he()],Pk.prototype,"_val",void 0),e([he()],Pk.prototype,"_colorMode",void 0),e([he()],Pk.prototype,"_hexInput",void 0),e([he()],Pk.prototype,"_r",void 0),e([he()],Pk.prototype,"_g",void 0),e([he()],Pk.prototype,"_b",void 0),Pk=e([ce("nile-color-picker")],Pk);function Vk(){return function(){if("undefined"==typeof window||"function"!=typeof getComputedStyle)return null;try{return getComputedStyle(document.documentElement).getPropertyValue("--nile-version").trim().replace(/^["']|["']$/g,"")||null}catch{return null}}()??"1.3.7"}if("undefined"!=typeof window){window.nileElementsVersion='"2.0.
|
|
20680
|
+
`:e}};e([de({type:String,attribute:!0,reflect:!0})],Pk.prototype,"type",void 0),e([de({type:String,attribute:!0,reflect:!0})],Pk.prototype,"value",void 0),e([de({type:String,reflect:!0})],Pk.prototype,"swatchTooltip",void 0),e([de({type:Number,reflect:!0})],Pk.prototype,"recentColorsCount",void 0),e([de({type:Boolean,reflect:!0})],Pk.prototype,"noFill",void 0),e([de({type:String,reflect:!0})],Pk.prototype,"mode",void 0),e([de({type:Boolean,reflect:!0})],Pk.prototype,"showCanvas",void 0),e([de({type:Boolean,reflect:!0})],Pk.prototype,"showHue",void 0),e([de({type:Boolean,reflect:!0})],Pk.prototype,"showInputs",void 0),e([de({type:Boolean,reflect:!0})],Pk.prototype,"showActions",void 0),e([de({type:Boolean,reflect:!0,attribute:!0})],Pk.prototype,"open",void 0),e([de({attribute:"palette",converter:{fromAttribute:e=>{try{const t=JSON.parse(e);return Array.isArray(t)?t.map((e=>"string"==typeof e?{color:e,name:e}:e&&"string"==typeof e.color?{color:e.color,name:e.name||e.color}:null)).filter(Boolean):[]}catch{return[]}},toAttribute:e=>JSON.stringify(e)}})],Pk.prototype,"palette",void 0),e([he()],Pk.prototype,"_view",void 0),e([he()],Pk.prototype,"_recentColors",void 0),e([he()],Pk.prototype,"_hue",void 0),e([he()],Pk.prototype,"_sat",void 0),e([he()],Pk.prototype,"_val",void 0),e([he()],Pk.prototype,"_colorMode",void 0),e([he()],Pk.prototype,"_hexInput",void 0),e([he()],Pk.prototype,"_r",void 0),e([he()],Pk.prototype,"_g",void 0),e([he()],Pk.prototype,"_b",void 0),Pk=e([ce("nile-color-picker")],Pk);function Vk(){return function(){if("undefined"==typeof window||"function"!=typeof getComputedStyle)return null;try{return getComputedStyle(document.documentElement).getPropertyValue("--nile-version").trim().replace(/^["']|["']$/g,"")||null}catch{return null}}()??"1.3.7"}if("undefined"!=typeof window){window.nileElementsVersion='"2.0.28"';let e=null;Object.defineProperty(window,"nileVersion",{configurable:!0,get:()=>e??Vk(),set:t=>{e=t}}),window.process=window.process||{env:{NODE_ENV:"production"}}}const Rk=s`
|
|
20681
20681
|
.utility-control::part(base) {
|
|
20682
20682
|
width: var(--nile-app-shell-utility-size, 32px);
|
|
20683
20683
|
height: var(--nile-app-shell-utility-size, 32px);
|
|
@@ -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"],function(_export,_context){"use strict";var t,i,n,e,s,l,_templateObject,_templateObject2,_templateObject3,o;function _taggedTemplateLiteral(e,t){return t||(t=e.slice(0)),Object.freeze(Object.defineProperties(e,{raw:{value:Object.freeze(t)}}));}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;n=_lit.html;},function(_litDecoratorsJs){e=_litDecoratorsJs.property;s=_litDecoratorsJs.state;l=_litDecoratorsJs.customElement;}],execute:function execute(){o=/*#__PURE__*/function(_i){function o(){var _this;_classCallCheck(this,o);_this=_callSuper(this,o,arguments),_this.newTab=!1,_this.disabled=!1,_this.showTextSupport=!1,_this.placeholder="Type or paste link here",_this.textPlaceholder="Display text",_this.label="Link",_this.linkValue="",_this.textValue="",_this.hasActiveLink=!1,_this.popoverStyle="",_this.selectionRange=null,_this.activeAnchor=null,_this.ignoreBlur=!1,_this.isApplying=!1,_this.onScroll=function(){_this.closePopover();},_this.onOpen=function(){if(_this.disabled)return;var t=document.getSelection();if(!t||0===t.rangeCount)return;if(!_this.editorEl.contains(t.getRangeAt(0).commonAncestorContainer))return;_this.selectionRange=t.getRangeAt(0).cloneRange(),_this.activeAnchor=null,_this.hasActiveLink=!1;var i=_this.selectionRange.startContainer;for(;i&&i!==_this.editorEl;){if(i instanceof HTMLAnchorElement){_this.activeAnchor=i,_this.hasActiveLink=!0;break;}i=i.parentNode;}_this.linkValue=_this.activeAnchor?_this.displayUrl(_this.activeAnchor.href):"",_this.showTextSupport&&(_this.activeAnchor?_this.textValue=_this.activeAnchor.textContent||"":_this.selectionRange.collapsed?_this.textValue="":_this.textValue=_this.selectionRange.toString()),_this.positionPopover(),_this.openPopover(),requestAnimationFrame(function(){var t=_this.querySelectorAll("nile-input"),i=t.length>1?t[1]:t[0];i===null||i===void 0||i.focus();});},_this.onInputKeydown=function(t){if("Escape"===t.key||"Enter"===t.key)if(t.preventDefault(),t.stopPropagation(),"Escape"!==t.key){_this.isApplying=!0;try{_this.applyLink();}finally{_this.isApplying=!1;}}else _this.closePopover();},_this.onInputBlur=function(){_this.ignoreBlur||_this.isApplying||requestAnimationFrame(function(){if(_this.ignoreBlur||_this.isApplying)return;var t=_this.querySelector("nile-popover");(t===null||t===void 0?void 0:t.matches(":focus-within"))||_this.closePopover();});},_this.onLinkInput=function(t){_this.linkValue=t.detail.value;},_this.onTextInput=function(t){_this.textValue=t.detail.value;},_this.onPopoverMousedown=function(){_this.ignoreBlur=!0;},_this.onPopoverMouseup=function(){_this.ignoreBlur=!1;},_this.onToolbarButtonMousedown=function(t){t.preventDefault();},_this.onActionMousedown=function(t){t.preventDefault(),_this.ignoreBlur=!0;},_this.onApplyClick=function(){_this.isApplying=!0,_this.applyLink(),_this.isApplying=!1,_this.ignoreBlur=!1;},_this.onUnlinkClick=function(){_this.isApplying=!0,_this.onRemove(),_this.isApplying=!1,_this.ignoreBlur=!1;};return _this;}_inherits(o,_i);return _createClass(o,[{key:"createRenderRoot",value:function createRenderRoot(){return this;}},{key:"connectedCallback",value:function connectedCallback(){_superPropGet(o,"connectedCallback",this,3)([]),this.injectCss("\n nile-popover.rte-link-popover::part(popover) {\n min-width: 340px;\n max-width: 420px;\n background: white;\n border: 1px solid var(--nile-colors-neutral-400, var(--ng-componentcolors-utility-gray-400));\n border-radius: 8px;\n padding: 0;\n gap: 0;\n overflow: hidden;\n height: auto;\n box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);\n }\n\n .link-popup-wrap {\n display: flex;\n flex-direction: column;\n gap: 12px;\n padding: 12px;\n }\n\n .link-popup-wrap nile-input {\n width: 100%;\n }\n\n .link-popup-wrap .link-input-row {\n width: 100%;\n }\n\n .link-popup-wrap .link-actions-row {\n display: flex;\n align-items: flex-end;\n gap: 4px;\n width: 100%;\n }\n\n .link-popup-wrap .link-actions-row nile-input {\n flex: 1;\n min-width: 0;\n }\n\n \n nile-button.rte-link-button::part(base) {\n border: none;\n height: 32px;\n width: 32px;\n }\n nile-button.rte-edit-button::part(base) {\n border: none;\n height: 32px;\n width: 32px;\n flex-shrink: 0;\n }\n ");}},{key:"injectCss",value:function injectCss(t){if(this.querySelector("style[data-rte-link-style]"))return;var i=document.createElement("style");i.setAttribute("data-rte-link-style","true"),i.textContent=t,this.insertBefore(i,this.firstChild);}},{key:"normalizeUrl",value:function normalizeUrl(t){return /^(https?:|mailto:|tel:)/i.test(t)?t:"https://".concat(t);}},{key:"displayUrl",value:function displayUrl(t){return t;}},{key:"getSelectionRect",value:function getSelectionRect(){if(!this.selectionRange)return null;var t=this.selectionRange.getBoundingClientRect();if(0===t.width&&0===t.height){var _i2=document.createElement("span");_i2.textContent="";this.selectionRange.cloneRange().insertNode(_i2),t=_i2.getBoundingClientRect(),_i2.remove();}return t;}},{key:"positionPopover",value:function positionPopover(){var t=this.getSelectionRect();t&&(this.popoverStyle="\n position: fixed;\n top: ".concat(t.bottom+8,"px;\n left: ").concat(t.left+t.width/2,"px;\n transform: translateX(-50%);\n z-index: 1000;\n "));}},{key:"openPopover",value:function openPopover(){var _this2=this;requestAnimationFrame(function(){var t=_this2.querySelector("nile-popover");t&&(t.isShow=!0),window.addEventListener("scroll",_this2.onScroll,!0);});}},{key:"closePopover",value:function closePopover(){var t=this.querySelector("nile-popover");t&&(t.isShow=!1),window.removeEventListener("scroll",this.onScroll,!0),this.linkValue="",this.textValue="",this.selectionRange=null,this.activeAnchor=null,this.hasActiveLink=!1,this.popoverStyle="";}},{key:"unwrapLink",value:function unwrapLink(t){for(;t.firstChild;){var _t$parentNode;(_t$parentNode=t.parentNode)===null||_t$parentNode===void 0||_t$parentNode.insertBefore(t.firstChild,t);}t.remove();}},{key:"applyLink",value:function applyLink(){if(!(this.selectionRange instanceof Range))return;var t=this.linkValue.trim();if(!t)return;if(/^javascript:/i.test(t))return;/^(https?:\/\/|mailto:|tel:|\/)/i.test(t)||(t="https://".concat(t)),this.editorEl.focus();var i=document.getSelection();if(!i)return;i.removeAllRanges(),i.addRange(this.selectionRange);var n=this.showTextSupport&&this.textValue.trim()?this.textValue.trim():"";if(this.activeAnchor)this.activeAnchor.href=t,n&&(this.activeAnchor.textContent=n),this.newTab?(this.activeAnchor.target="_blank",this.activeAnchor.rel="noopener noreferrer"):(this.activeAnchor.removeAttribute("target"),this.activeAnchor.removeAttribute("rel"));else{var _i3=document.createElement("a");if(_i3.href=t,this.newTab?(_i3.target="_blank",_i3.rel="noopener noreferrer"):(_i3.removeAttribute("target"),_i3.removeAttribute("rel")),n)this.selectionRange.deleteContents(),_i3.textContent=n,this.selectionRange.insertNode(_i3);else if(this.selectionRange.collapsed)_i3.textContent=t,this.selectionRange.insertNode(_i3);else try{this.selectionRange.surroundContents(_i3);}catch(_unused){var _t=this.selectionRange.extractContents();_i3.appendChild(_t),this.selectionRange.insertNode(_i3);}}this.emit(t),this.closePopover();}},{key:"onRemove",value:function onRemove(){this.activeAnchor&&(this.unwrapLink(this.activeAnchor),this.emit(""),this.closePopover());}},{key:"emit",value:function emit(t){this.dispatchEvent(new CustomEvent("nile-link-changed",{detail:{href:t},bubbles:!0,composed:!0}));}},{key:"render",value:function render(){var t=this.disabled?"var(--nile-colors-neutral-500, var(--ng-colors-fg-disabled-subtle))":"var(--nile-colors-dark-900, var(--ng-colors-text-primary-900))";return n(_templateObject||(_templateObject=_taggedTemplateLiteral(["\n <nile-lite-tooltip content=",">\n <nile-button\n variant=\"tertiary\"\n size=\"small\"\n ?disabled=","\n @mousedown=","\n @click=","\n class=\"rte-link-button\"\n >\n <nile-icon name=\"link_2\" color=","></nile-icon>\n </nile-button>\n </nile-lite-tooltip>\n\n <nile-popover\n class=\"rte-link-popover\"\n .arrow=","\n style=","\n @mousedown=","\n @mouseup=","\n >\n <div class=\"link-popup-wrap\">\n ","\n <div class=\"link-actions-row\">\n <nile-input\n label=","\n placeholder=","\n .value=","\n @nile-input=","\n @keydown=","\n @nile-blur=","\n ></nile-input>\n ","\n </div>\n </div>\n </nile-popover>\n "])),this.label,this.disabled,this.onToolbarButtonMousedown,this.onOpen,t,!1,this.popoverStyle,this.onPopoverMousedown,this.onPopoverMouseup,this.showTextSupport?n(_templateObject2||(_templateObject2=_taggedTemplateLiteral(["\n <div class=\"link-input-row\">\n <nile-input\n label=\"Text\"\n placeholder=","\n .value=","\n @nile-input=","\n @keydown=","\n @nile-blur=","\n ></nile-input>\n </div>\n "])),this.textPlaceholder,this.textValue,this.onTextInput,this.onInputKeydown,this.onInputBlur):null,this.showTextSupport?"URL":"",this.placeholder,this.linkValue,this.onLinkInput,this.onInputKeydown,this.onInputBlur,this.hasActiveLink?n(_templateObject3||(_templateObject3=_taggedTemplateLiteral(["\n <nile-button\n size=\"small\"\n variant=\"tertiary\"\n class=\"rte-edit-button\"\n @mousedown=","\n @click=","\n >\n <nile-icon name=\"pencil\"></nile-icon>\n </nile-button>\n <nile-button\n size=\"small\"\n variant=\"tertiary\"\n class=\"rte-edit-button\"\n @mousedown=","\n @click=","\n >\n <nile-icon name=\"unlink\"></nile-icon>\n </nile-button>\n "])),this.onActionMousedown,this.onApplyClick,this.onActionMousedown,this.onUnlinkClick):null);}}]);}(i);t([e({attribute:!1})],o.prototype,"editorEl",void 0),t([e({type:Boolean,reflect:!0,attribute:!0})],o.prototype,"newTab",void 0),t([e({type:Boolean,reflect:!0,attribute:!0})],o.prototype,"disabled",void 0),t([e({type:Boolean,reflect:!0,attribute:!0})],o.prototype,"showTextSupport",void 0),t([e({type:String,reflect:!0,attribute:!0})],o.prototype,"placeholder",void 0),t([e({type:String,reflect:!0,attribute:!0})],o.prototype,"textPlaceholder",void 0),t([e({type:String,reflect:!0,attribute:!0})],o.prototype,"label",void 0),t([s()],o.prototype,"linkValue",void 0),t([s()],o.prototype,"textValue",void 0),t([s()],o.prototype,"hasActiveLink",void 0),t([s()],o.prototype,"popoverStyle",void 0),o=t([l("nile-rte-link")],o);}};});
|
|
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"],function(_export,_context){"use strict";var t,i,n,e,s,l,_templateObject,_templateObject2,_templateObject3,o;function _taggedTemplateLiteral(e,t){return t||(t=e.slice(0)),Object.freeze(Object.defineProperties(e,{raw:{value:Object.freeze(t)}}));}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;n=_lit.html;},function(_litDecoratorsJs){e=_litDecoratorsJs.property;s=_litDecoratorsJs.state;l=_litDecoratorsJs.customElement;}],execute:function execute(){o=/*#__PURE__*/function(_i){function o(){var _this;_classCallCheck(this,o);_this=_callSuper(this,o,arguments),_this.newTab=!1,_this.disabled=!1,_this.showTextSupport=!1,_this.placeholder="Type or paste link here",_this.textPlaceholder="Display text",_this.label="Link",_this.linkValue="",_this.textValue="",_this.hasActiveLink=!1,_this.popoverStyle="",_this.selectionRange=null,_this.activeAnchor=null,_this.ignoreBlur=!1,_this.isApplying=!1,_this.onScroll=function(){_this.closePopover();},_this.onOpen=function(){if(_this.disabled)return;var t=document.getSelection();if(!t||0===t.rangeCount)return;if(!_this.editorEl.contains(t.getRangeAt(0).commonAncestorContainer))return;_this.selectionRange=t.getRangeAt(0).cloneRange(),_this.activeAnchor=null,_this.hasActiveLink=!1;var i=_this.selectionRange.startContainer;for(;i&&i!==_this.editorEl;){if(i instanceof HTMLAnchorElement){_this.activeAnchor=i,_this.hasActiveLink=!0;break;}i=i.parentNode;}_this.linkValue=_this.activeAnchor?_this.displayUrl(_this.activeAnchor.href):"",_this.showTextSupport&&(_this.activeAnchor?_this.textValue=_this.activeAnchor.textContent||"":_this.selectionRange.collapsed?_this.textValue="":_this.textValue=_this.selectionRange.toString()),_this.positionPopover(),_this.openPopover(),requestAnimationFrame(function(){var t=_this.querySelectorAll("nile-input"),i=t.length>1?t[1]:t[0];i===null||i===void 0||i.focus();});},_this.onInputKeydown=function(t){if("Escape"===t.key||"Enter"===t.key)if(t.preventDefault(),t.stopPropagation(),"Escape"!==t.key){_this.isApplying=!0;try{_this.applyLink();}finally{_this.isApplying=!1;}}else _this.closePopover();},_this.onInputBlur=function(){_this.ignoreBlur||_this.isApplying||requestAnimationFrame(function(){if(_this.ignoreBlur||_this.isApplying)return;var t=_this.querySelector("nile-popover");(t===null||t===void 0?void 0:t.matches(":focus-within"))||_this.closePopover();});},_this.onLinkInput=function(t){_this.linkValue=t.detail.value;},_this.onTextInput=function(t){_this.textValue=t.detail.value;},_this.onPopoverMousedown=function(){_this.ignoreBlur=!0;},_this.onPopoverMouseup=function(){_this.ignoreBlur=!1;},_this.onToolbarButtonMousedown=function(t){t.preventDefault();},_this.onActionMousedown=function(t){t.preventDefault(),_this.ignoreBlur=!0;},_this.onApplyClick=function(){_this.isApplying=!0,_this.applyLink(),_this.isApplying=!1,_this.ignoreBlur=!1;},_this.onUnlinkClick=function(){_this.isApplying=!0,_this.onRemove(),_this.isApplying=!1,_this.ignoreBlur=!1;};return _this;}_inherits(o,_i);return _createClass(o,[{key:"createRenderRoot",value:function createRenderRoot(){return this;}},{key:"connectedCallback",value:function connectedCallback(){_superPropGet(o,"connectedCallback",this,3)([]),this.injectCss("\n nile-popover.rte-link-popover::part(popover) {\n min-width: 340px;\n max-width: 420px;\n background: var(--nile-colors-white-base, var(--ng-colors-bg-primary));\n border: 1px solid var(--nile-colors-neutral-400, var(--ng-componentcolors-utility-gray-400));\n border-radius: 8px;\n padding: 0;\n gap: 0;\n overflow: hidden;\n height: auto;\n box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);\n }\n\n .link-popup-wrap {\n display: flex;\n flex-direction: column;\n gap: 12px;\n padding: 12px;\n }\n\n .link-popup-wrap nile-input {\n width: 100%;\n }\n\n .link-popup-wrap .link-input-row {\n width: 100%;\n }\n\n .link-popup-wrap .link-actions-row {\n display: flex;\n align-items: flex-end;\n gap: 4px;\n width: 100%;\n }\n\n .link-popup-wrap .link-actions-row nile-input {\n flex: 1;\n min-width: 0;\n }\n\n \n nile-button.rte-link-button::part(base) {\n border: none;\n height: 32px;\n width: 32px;\n }\n nile-button.rte-edit-button::part(base) {\n border: none;\n height: 32px;\n width: 32px;\n flex-shrink: 0;\n }\n ");}},{key:"injectCss",value:function injectCss(t){if(this.querySelector("style[data-rte-link-style]"))return;var i=document.createElement("style");i.setAttribute("data-rte-link-style","true"),i.textContent=t,this.insertBefore(i,this.firstChild);}},{key:"normalizeUrl",value:function normalizeUrl(t){return /^(https?:|mailto:|tel:)/i.test(t)?t:"https://".concat(t);}},{key:"displayUrl",value:function displayUrl(t){return t;}},{key:"getSelectionRect",value:function getSelectionRect(){if(!this.selectionRange)return null;var t=this.selectionRange.getBoundingClientRect();if(0===t.width&&0===t.height){var _i2=document.createElement("span");_i2.textContent="";this.selectionRange.cloneRange().insertNode(_i2),t=_i2.getBoundingClientRect(),_i2.remove();}return t;}},{key:"positionPopover",value:function positionPopover(){var t=this.getSelectionRect();t&&(this.popoverStyle="\n position: fixed;\n top: ".concat(t.bottom+8,"px;\n left: ").concat(t.left+t.width/2,"px;\n transform: translateX(-50%);\n z-index: 1000;\n "));}},{key:"openPopover",value:function openPopover(){var _this2=this;requestAnimationFrame(function(){var t=_this2.querySelector("nile-popover");t&&(t.isShow=!0),window.addEventListener("scroll",_this2.onScroll,!0);});}},{key:"closePopover",value:function closePopover(){var t=this.querySelector("nile-popover");t&&(t.isShow=!1),window.removeEventListener("scroll",this.onScroll,!0),this.linkValue="",this.textValue="",this.selectionRange=null,this.activeAnchor=null,this.hasActiveLink=!1,this.popoverStyle="";}},{key:"unwrapLink",value:function unwrapLink(t){for(;t.firstChild;){var _t$parentNode;(_t$parentNode=t.parentNode)===null||_t$parentNode===void 0||_t$parentNode.insertBefore(t.firstChild,t);}t.remove();}},{key:"applyLink",value:function applyLink(){if(!(this.selectionRange instanceof Range))return;var t=this.linkValue.trim();if(!t)return;if(/^javascript:/i.test(t))return;/^(https?:\/\/|mailto:|tel:|\/)/i.test(t)||(t="https://".concat(t)),this.editorEl.focus();var i=document.getSelection();if(!i)return;i.removeAllRanges(),i.addRange(this.selectionRange);var n=this.showTextSupport&&this.textValue.trim()?this.textValue.trim():"";if(this.activeAnchor)this.activeAnchor.href=t,n&&(this.activeAnchor.textContent=n),this.newTab?(this.activeAnchor.target="_blank",this.activeAnchor.rel="noopener noreferrer"):(this.activeAnchor.removeAttribute("target"),this.activeAnchor.removeAttribute("rel"));else{var _i3=document.createElement("a");if(_i3.href=t,this.newTab?(_i3.target="_blank",_i3.rel="noopener noreferrer"):(_i3.removeAttribute("target"),_i3.removeAttribute("rel")),n)this.selectionRange.deleteContents(),_i3.textContent=n,this.selectionRange.insertNode(_i3);else if(this.selectionRange.collapsed)_i3.textContent=t,this.selectionRange.insertNode(_i3);else try{this.selectionRange.surroundContents(_i3);}catch(_unused){var _t=this.selectionRange.extractContents();_i3.appendChild(_t),this.selectionRange.insertNode(_i3);}}this.emit(t),this.closePopover();}},{key:"onRemove",value:function onRemove(){this.activeAnchor&&(this.unwrapLink(this.activeAnchor),this.emit(""),this.closePopover());}},{key:"emit",value:function emit(t){this.dispatchEvent(new CustomEvent("nile-link-changed",{detail:{href:t},bubbles:!0,composed:!0}));}},{key:"render",value:function render(){var t=this.disabled?"var(--nile-colors-neutral-500, var(--ng-colors-fg-disabled-subtle))":"var(--nile-colors-dark-900, var(--ng-colors-text-primary-900))";return n(_templateObject||(_templateObject=_taggedTemplateLiteral(["\n <nile-lite-tooltip content=",">\n <nile-button\n variant=\"tertiary\"\n size=\"small\"\n ?disabled=","\n @mousedown=","\n @click=","\n class=\"rte-link-button\"\n >\n <nile-icon name=\"link_2\" color=","></nile-icon>\n </nile-button>\n </nile-lite-tooltip>\n\n <nile-popover\n class=\"rte-link-popover\"\n .arrow=","\n style=","\n @mousedown=","\n @mouseup=","\n >\n <div class=\"link-popup-wrap\">\n ","\n <div class=\"link-actions-row\">\n <nile-input\n label=","\n placeholder=","\n .value=","\n @nile-input=","\n @keydown=","\n @nile-blur=","\n ></nile-input>\n ","\n </div>\n </div>\n </nile-popover>\n "])),this.label,this.disabled,this.onToolbarButtonMousedown,this.onOpen,t,!1,this.popoverStyle,this.onPopoverMousedown,this.onPopoverMouseup,this.showTextSupport?n(_templateObject2||(_templateObject2=_taggedTemplateLiteral(["\n <div class=\"link-input-row\">\n <nile-input\n label=\"Text\"\n placeholder=","\n .value=","\n @nile-input=","\n @keydown=","\n @nile-blur=","\n ></nile-input>\n </div>\n "])),this.textPlaceholder,this.textValue,this.onTextInput,this.onInputKeydown,this.onInputBlur):null,this.showTextSupport?"URL":"",this.placeholder,this.linkValue,this.onLinkInput,this.onInputKeydown,this.onInputBlur,this.hasActiveLink?n(_templateObject3||(_templateObject3=_taggedTemplateLiteral(["\n <nile-button\n size=\"small\"\n variant=\"tertiary\"\n class=\"rte-edit-button\"\n @mousedown=","\n @click=","\n >\n <nile-icon name=\"pencil\"></nile-icon>\n </nile-button>\n <nile-button\n size=\"small\"\n variant=\"tertiary\"\n class=\"rte-edit-button\"\n @mousedown=","\n @click=","\n >\n <nile-icon name=\"unlink\"></nile-icon>\n </nile-button>\n "])),this.onActionMousedown,this.onApplyClick,this.onActionMousedown,this.onUnlinkClick):null);}}]);}(i);t([e({attribute:!1})],o.prototype,"editorEl",void 0),t([e({type:Boolean,reflect:!0,attribute:!0})],o.prototype,"newTab",void 0),t([e({type:Boolean,reflect:!0,attribute:!0})],o.prototype,"disabled",void 0),t([e({type:Boolean,reflect:!0,attribute:!0})],o.prototype,"showTextSupport",void 0),t([e({type:String,reflect:!0,attribute:!0})],o.prototype,"placeholder",void 0),t([e({type:String,reflect:!0,attribute:!0})],o.prototype,"textPlaceholder",void 0),t([e({type:String,reflect:!0,attribute:!0})],o.prototype,"label",void 0),t([s()],o.prototype,"linkValue",void 0),t([s()],o.prototype,"textValue",void 0),t([s()],o.prototype,"hasActiveLink",void 0),t([s()],o.prototype,"popoverStyle",void 0),o=t([l("nile-rte-link")],o);}};});
|
|
2
2
|
//# sourceMappingURL=nile-rte-link.cjs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nile-rte-link.cjs.js","sources":["../../../src/nile-rich-text-editor/nile-rte-link.ts"],"sourcesContent":["import { LitElement, html } from 'lit';\nimport { customElement, property, state } from 'lit/decorators.js';\n\n@customElement('nile-rte-link')\nexport class NileRteLink extends LitElement {\n protected createRenderRoot() {\n return this;\n }\n\n @property({ attribute: false }) editorEl!: HTMLElement;\n @property({ type: Boolean, reflect: true, attribute: true }) newTab = false;\n @property({ type: Boolean, reflect: true, attribute: true }) disabled = false;\n @property({ type: Boolean, reflect: true, attribute: true }) showTextSupport = false;\n @property({ type: String, reflect: true, attribute: true }) placeholder = 'Type or paste link here';\n @property({ type: String, reflect: true, attribute: true }) textPlaceholder = 'Display text';\n @property({ type: String, reflect: true, attribute: true }) label = 'Link';\n\n @state() private linkValue = '';\n @state() private textValue = '';\n @state() private hasActiveLink = false;\n @state() private popoverStyle = '';\n\n private selectionRange: Range | null = null;\n private activeAnchor: HTMLAnchorElement | null = null;\n\n private ignoreBlur = false;\n private isApplying = false;\n\n \n\n connectedCallback() {\n super.connectedCallback();\n\n this.injectCss(`\n nile-popover.rte-link-popover::part(popover) {\n min-width: 340px;\n max-width: 420px;\n background: white;\n border: 1px solid var(--nile-colors-neutral-400, var(--ng-componentcolors-utility-gray-400));\n border-radius: 8px;\n padding: 0;\n gap: 0;\n overflow: hidden;\n height: auto;\n box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);\n }\n\n .link-popup-wrap {\n display: flex;\n flex-direction: column;\n gap: 12px;\n padding: 12px;\n }\n\n .link-popup-wrap nile-input {\n width: 100%;\n }\n\n .link-popup-wrap .link-input-row {\n width: 100%;\n }\n\n .link-popup-wrap .link-actions-row {\n display: flex;\n align-items: flex-end;\n gap: 4px;\n width: 100%;\n }\n\n .link-popup-wrap .link-actions-row nile-input {\n flex: 1;\n min-width: 0;\n }\n\n \n nile-button.rte-link-button::part(base) {\n border: none;\n height: 32px;\n width: 32px;\n }\n nile-button.rte-edit-button::part(base) {\n border: none;\n height: 32px;\n width: 32px;\n flex-shrink: 0;\n }\n `);\n }\n\n private injectCss(cssText: string) {\n if (this.querySelector('style[data-rte-link-style]')) return;\n const style = document.createElement('style');\n style.setAttribute('data-rte-link-style', 'true');\n style.textContent = cssText;\n this.insertBefore(style, this.firstChild);\n }\n\n \n\n private normalizeUrl(url: string) {\n if (/^(https?:|mailto:|tel:)/i.test(url)) return url;\n return `https://${url}`;\n }\n\n private displayUrl(url: string): string {\n return url;\n }\n\n private getSelectionRect(): DOMRect | null {\n if (!this.selectionRange) return null;\n\n let rect = this.selectionRange.getBoundingClientRect();\n if (rect.width === 0 && rect.height === 0) {\n const span = document.createElement('span');\n span.textContent = '\\u200b';\n const tempRange = this.selectionRange.cloneRange();\n tempRange.insertNode(span);\n rect = span.getBoundingClientRect();\n span.remove(); \n }\n return rect;\n }\n\n private positionPopover() {\n const rect = this.getSelectionRect();\n if (!rect) return;\n\n this.popoverStyle = `\n position: fixed;\n top: ${rect.bottom + 8}px;\n left: ${rect.left + rect.width / 2}px;\n transform: translateX(-50%);\n z-index: 1000;\n `;\n }\n\n private onScroll = () => {\n this.closePopover();\n };\n\n private openPopover() {\n requestAnimationFrame(() => {\n const pop = this.querySelector('nile-popover') as any;\n pop && (pop.isShow = true);\n window.addEventListener('scroll', this.onScroll, true);\n });\n }\n\n private closePopover() {\n const pop = this.querySelector('nile-popover') as any;\n pop && (pop.isShow = false);\n\n window.removeEventListener('scroll', this.onScroll, true);\n\n this.linkValue = '';\n this.textValue = '';\n this.selectionRange = null;\n this.activeAnchor = null;\n this.hasActiveLink = false;\n this.popoverStyle = '';\n }\n\n private unwrapLink(a: HTMLAnchorElement) {\n while (a.firstChild) a.parentNode?.insertBefore(a.firstChild, a);\n a.remove();\n }\n\n \n\n private onOpen = () => {\n if (this.disabled) return;\n\n const sel = document.getSelection();\n if (!sel || sel.rangeCount === 0) return;\n if (!this.editorEl.contains(sel.getRangeAt(0).commonAncestorContainer)) return;\n\n this.selectionRange = sel.getRangeAt(0).cloneRange();\n this.activeAnchor = null;\n this.hasActiveLink = false;\n\n let n: Node | null = this.selectionRange.startContainer;\n while (n && n !== this.editorEl) {\n if (n instanceof HTMLAnchorElement) {\n this.activeAnchor = n;\n this.hasActiveLink = true;\n break;\n }\n n = n.parentNode;\n }\n\n this.linkValue = this.activeAnchor\n ? this.displayUrl(this.activeAnchor.href)\n : '';\n\n if (this.showTextSupport) {\n if (this.activeAnchor) {\n this.textValue = this.activeAnchor.textContent || '';\n } else if (!this.selectionRange.collapsed) {\n this.textValue = this.selectionRange.toString();\n } else {\n this.textValue = '';\n }\n }\n\n this.positionPopover();\n this.openPopover();\n\n requestAnimationFrame(() => {\n const inputs = this.querySelectorAll('nile-input');\n const target = inputs.length > 1 ? inputs[1] : inputs[0];\n (target as any)?.focus();\n });\n }\n\n \n\n private onInputKeydown = (e: KeyboardEvent) => {\n if (e.key !== 'Escape' && e.key !== 'Enter') return;\n e.preventDefault();\n e.stopPropagation();\n if (e.key === 'Escape') {\n this.closePopover();\n return;\n }\n this.isApplying = true;\n try {\n this.applyLink();\n } finally {\n this.isApplying = false;\n }\n };\n private onInputBlur = () => {\n if (this.ignoreBlur || this.isApplying) return;\n requestAnimationFrame(() => {\n if (this.ignoreBlur || this.isApplying) return;\n const pop = this.querySelector('nile-popover');\n if (pop?.matches(':focus-within')) return;\n this.closePopover();\n });\n };\n\n private onLinkInput = (e: CustomEvent) => {\n this.linkValue = e.detail.value;\n };\n\n private onTextInput = (e: CustomEvent) => {\n this.textValue = e.detail.value;\n };\n\n private onPopoverMousedown = () => {\n this.ignoreBlur = true;\n };\n\n private onPopoverMouseup = () => {\n this.ignoreBlur = false;\n };\n\n private onToolbarButtonMousedown = (e: Event) => {\n e.preventDefault();\n };\n\n private onActionMousedown = (e: Event) => {\n e.preventDefault();\n this.ignoreBlur = true;\n };\n\n private onApplyClick = () => {\n this.isApplying = true;\n this.applyLink();\n this.isApplying = false;\n this.ignoreBlur = false;\n };\n\n private onUnlinkClick = () => {\n this.isApplying = true;\n this.onRemove();\n this.isApplying = false;\n this.ignoreBlur = false;\n };\n\n \n\n private applyLink() {\n if (!(this.selectionRange instanceof Range)) return;\n\n let url = this.linkValue.trim();\n if (!url) return;\n\n if (/^javascript:/i.test(url)) return;\n\n if (!/^(https?:\\/\\/|mailto:|tel:|\\/)/i.test(url)) {\n url = `https://${url}`;\n }\n\n this.editorEl.focus();\n\n const sel = document.getSelection();\n if (!sel) return;\n\n sel.removeAllRanges();\n sel.addRange(this.selectionRange);\n\n const displayText = this.showTextSupport && this.textValue.trim()\n ? this.textValue.trim()\n : '';\n\n if (this.activeAnchor) {\n this.activeAnchor.href = url;\n\n if (displayText) {\n this.activeAnchor.textContent = displayText;\n }\n\n if (this.newTab) {\n this.activeAnchor.target = '_blank';\n this.activeAnchor.rel = 'noopener noreferrer';\n } else {\n this.activeAnchor.removeAttribute('target');\n this.activeAnchor.removeAttribute('rel');\n }\n \n } else {\n const link = document.createElement('a');\n link.href = url;\n \n if (this.newTab) {\n link.target = '_blank';\n link.rel = 'noopener noreferrer';\n } else {\n link.removeAttribute('target');\n link.removeAttribute('rel');\n } \n\n if (displayText) {\n this.selectionRange.deleteContents();\n link.textContent = displayText;\n this.selectionRange.insertNode(link);\n } else if (this.selectionRange.collapsed) {\n link.textContent = url;\n this.selectionRange.insertNode(link);\n } else {\n try {\n this.selectionRange.surroundContents(link);\n } catch {\n const frag = this.selectionRange.extractContents();\n link.appendChild(frag);\n this.selectionRange.insertNode(link);\n }\n }\n }\n\n this.emit(url);\n this.closePopover();\n }\n\n private onRemove() {\n if (!this.activeAnchor) return;\n this.unwrapLink(this.activeAnchor);\n this.emit('');\n this.closePopover();\n }\n\n private emit(href: string) {\n this.dispatchEvent(\n new CustomEvent('nile-link-changed', {\n detail: { href },\n bubbles: true,\n composed: true,\n })\n );\n }\n\n render() {\n const iconColor = this.disabled\n ? 'var(--nile-colors-neutral-500, var(--ng-colors-fg-disabled-subtle))'\n : 'var(--nile-colors-dark-900, var(--ng-colors-text-primary-900))';\n\n return html`\n <nile-lite-tooltip content=${this.label}>\n <nile-button\n variant=\"tertiary\"\n size=\"small\"\n ?disabled=${this.disabled}\n @mousedown=${this.onToolbarButtonMousedown}\n @click=${this.onOpen}\n class=\"rte-link-button\"\n >\n <nile-icon name=\"link_2\" color=${iconColor}></nile-icon>\n </nile-button>\n </nile-lite-tooltip>\n\n <nile-popover\n class=\"rte-link-popover\"\n .arrow=${false}\n style=${this.popoverStyle}\n @mousedown=${this.onPopoverMousedown}\n @mouseup=${this.onPopoverMouseup}\n >\n <div class=\"link-popup-wrap\">\n ${this.showTextSupport ? html`\n <div class=\"link-input-row\">\n <nile-input\n label=\"Text\"\n placeholder=${this.textPlaceholder}\n .value=${this.textValue}\n @nile-input=${this.onTextInput}\n @keydown=${this.onInputKeydown}\n @nile-blur=${this.onInputBlur}\n ></nile-input>\n </div>\n ` : null}\n <div class=\"link-actions-row\">\n <nile-input\n label=${this.showTextSupport ? 'URL' : ''}\n placeholder=${this.placeholder}\n .value=${this.linkValue}\n @nile-input=${this.onLinkInput}\n @keydown=${this.onInputKeydown}\n @nile-blur=${this.onInputBlur}\n ></nile-input>\n ${this.hasActiveLink ? html`\n <nile-button\n size=\"small\"\n variant=\"tertiary\"\n class=\"rte-edit-button\"\n @mousedown=${this.onActionMousedown}\n @click=${this.onApplyClick}\n >\n <nile-icon name=\"pencil\"></nile-icon>\n </nile-button>\n <nile-button\n size=\"small\"\n variant=\"tertiary\"\n class=\"rte-edit-button\"\n @mousedown=${this.onActionMousedown}\n @click=${this.onUnlinkClick}\n >\n <nile-icon name=\"unlink\"></nile-icon>\n </nile-button>\n ` : null}\n </div>\n </div>\n </nile-popover>\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'nile-rte-link': NileRteLink;\n }\n}\n"],"names":["NileRteLink","_i","o","constructor","this","newTab","disabled","showTextSupport","placeholder","textPlaceholder","label","linkValue","textValue","hasActiveLink","popoverStyle","selectionRange","activeAnchor","ignoreBlur","isApplying","onScroll","closePopover","onOpen","sel","document","getSelection","rangeCount","editorEl","contains","getRangeAt","commonAncestorContainer","cloneRange","n","startContainer","HTMLAnchorElement","parentNode","displayUrl","href","textContent","collapsed","toString","positionPopover","openPopover","requestAnimationFrame","inputs","querySelectorAll","target","length","focus","onInputKeydown","e","key","preventDefault","stopPropagation","applyLink","onInputBlur","pop","querySelector","matches","onLinkInput","detail","value","onTextInput","onPopoverMousedown","onPopoverMouseup","onToolbarButtonMousedown","onActionMousedown","onApplyClick","onUnlinkClick","onRemove","_this","_inherits","_createClass","createRenderRoot","connectedCallback","super","injectCss","cssText","style","createElement","setAttribute","insertBefore","firstChild","normalizeUrl","url","test","getSelectionRect","rect","getBoundingClientRect","width","height","span","insertNode","remove","concat","bottom","left","isShow","window","addEventListener","removeEventListener","unwrapLink","a","Range","trim","removeAllRanges","addRange","displayText","rel","removeAttribute","link","deleteContents","surroundContents","_unused","frag","extractContents","appendChild","emit","dispatchEvent","CustomEvent","bubbles","composed","render","iconColor","html","_templateObject","_taggedTemplateLiteral","_templateObject2","_templateObject3","LitElement","__decorate","property","attribute","prototype","type","Boolean","reflect","String","state","customElement"],"mappings":"ghHAIaA,CAAN,uBAAAC,EAAA,EAAA,SAAAC,EAAA,CAAAC,KAAAA,KAAAA,CAAAA,eAAAA,MAAAA,CAAAA,mCAMwDC,EAAAA,KAAAA,CAAMC,QAAG,CACTD,CAAAA,KAAAA,CAAQE,QA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A,CAAA,CACfH,CAAA,CAAA,CAAhBQ,CAA+BzI,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAoI,SAAA,CAAA,WAAA,CAAA,IAAA,EACfH,CAAAA,CAAAA,CAAAA,CAAA,CAAhBQ,CAAAA,CAAAA,CAAAA,CAAAA,CAAsCzI,CAAAoI,CAAAA,SAAAA,CAAA,eAAA,CAAA,IAAA,EAAA,CAAA,CACtBH,CAAA,CAAA,CAAhBQ,CAAkCzI,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAoI,SAAA,CAAA,cAAA,CAAA,IAAA,EAhBxBpI,CAAAA,CAAAA,CAAAA,CAAWiI,CAAA,CAAA,CADvBS,EAAc,eACF1I,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA"}
|
|
1
|
+
{"version":3,"file":"nile-rte-link.cjs.js","sources":["../../../src/nile-rich-text-editor/nile-rte-link.ts"],"sourcesContent":["import { LitElement, html } from 'lit';\nimport { customElement, property, state } from 'lit/decorators.js';\n\n@customElement('nile-rte-link')\nexport class NileRteLink extends LitElement {\n protected createRenderRoot() {\n return this;\n }\n\n @property({ attribute: false }) editorEl!: HTMLElement;\n @property({ type: Boolean, reflect: true, attribute: true }) newTab = false;\n @property({ type: Boolean, reflect: true, attribute: true }) disabled = false;\n @property({ type: Boolean, reflect: true, attribute: true }) showTextSupport = false;\n @property({ type: String, reflect: true, attribute: true }) placeholder = 'Type or paste link here';\n @property({ type: String, reflect: true, attribute: true }) textPlaceholder = 'Display text';\n @property({ type: String, reflect: true, attribute: true }) label = 'Link';\n\n @state() private linkValue = '';\n @state() private textValue = '';\n @state() private hasActiveLink = false;\n @state() private popoverStyle = '';\n\n private selectionRange: Range | null = null;\n private activeAnchor: HTMLAnchorElement | null = null;\n\n private ignoreBlur = false;\n private isApplying = false;\n\n \n\n connectedCallback() {\n super.connectedCallback();\n\n this.injectCss(`\n nile-popover.rte-link-popover::part(popover) {\n min-width: 340px;\n max-width: 420px;\n background: var(--nile-colors-white-base, var(--ng-colors-bg-primary));\n border: 1px solid var(--nile-colors-neutral-400, var(--ng-componentcolors-utility-gray-400));\n border-radius: 8px;\n padding: 0;\n gap: 0;\n overflow: hidden;\n height: auto;\n box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);\n }\n\n .link-popup-wrap {\n display: flex;\n flex-direction: column;\n gap: 12px;\n padding: 12px;\n }\n\n .link-popup-wrap nile-input {\n width: 100%;\n }\n\n .link-popup-wrap .link-input-row {\n width: 100%;\n }\n\n .link-popup-wrap .link-actions-row {\n display: flex;\n align-items: flex-end;\n gap: 4px;\n width: 100%;\n }\n\n .link-popup-wrap .link-actions-row nile-input {\n flex: 1;\n min-width: 0;\n }\n\n \n nile-button.rte-link-button::part(base) {\n border: none;\n height: 32px;\n width: 32px;\n }\n nile-button.rte-edit-button::part(base) {\n border: none;\n height: 32px;\n width: 32px;\n flex-shrink: 0;\n }\n `);\n }\n\n private injectCss(cssText: string) {\n if (this.querySelector('style[data-rte-link-style]')) return;\n const style = document.createElement('style');\n style.setAttribute('data-rte-link-style', 'true');\n style.textContent = cssText;\n this.insertBefore(style, this.firstChild);\n }\n\n \n\n private normalizeUrl(url: string) {\n if (/^(https?:|mailto:|tel:)/i.test(url)) return url;\n return `https://${url}`;\n }\n\n private displayUrl(url: string): string {\n return url;\n }\n\n private getSelectionRect(): DOMRect | null {\n if (!this.selectionRange) return null;\n\n let rect = this.selectionRange.getBoundingClientRect();\n if (rect.width === 0 && rect.height === 0) {\n const span = document.createElement('span');\n span.textContent = '\\u200b';\n const tempRange = this.selectionRange.cloneRange();\n tempRange.insertNode(span);\n rect = span.getBoundingClientRect();\n span.remove(); \n }\n return rect;\n }\n\n private positionPopover() {\n const rect = this.getSelectionRect();\n if (!rect) return;\n\n this.popoverStyle = `\n position: fixed;\n top: ${rect.bottom + 8}px;\n left: ${rect.left + rect.width / 2}px;\n transform: translateX(-50%);\n z-index: 1000;\n `;\n }\n\n private onScroll = () => {\n this.closePopover();\n };\n\n private openPopover() {\n requestAnimationFrame(() => {\n const pop = this.querySelector('nile-popover') as any;\n pop && (pop.isShow = true);\n window.addEventListener('scroll', this.onScroll, true);\n });\n }\n\n private closePopover() {\n const pop = this.querySelector('nile-popover') as any;\n pop && (pop.isShow = false);\n\n window.removeEventListener('scroll', this.onScroll, true);\n\n this.linkValue = '';\n this.textValue = '';\n this.selectionRange = null;\n this.activeAnchor = null;\n this.hasActiveLink = false;\n this.popoverStyle = '';\n }\n\n private unwrapLink(a: HTMLAnchorElement) {\n while (a.firstChild) a.parentNode?.insertBefore(a.firstChild, a);\n a.remove();\n }\n\n \n\n private onOpen = () => {\n if (this.disabled) return;\n\n const sel = document.getSelection();\n if (!sel || sel.rangeCount === 0) return;\n if (!this.editorEl.contains(sel.getRangeAt(0).commonAncestorContainer)) return;\n\n this.selectionRange = sel.getRangeAt(0).cloneRange();\n this.activeAnchor = null;\n this.hasActiveLink = false;\n\n let n: Node | null = this.selectionRange.startContainer;\n while (n && n !== this.editorEl) {\n if (n instanceof HTMLAnchorElement) {\n this.activeAnchor = n;\n this.hasActiveLink = true;\n break;\n }\n n = n.parentNode;\n }\n\n this.linkValue = this.activeAnchor\n ? this.displayUrl(this.activeAnchor.href)\n : '';\n\n if (this.showTextSupport) {\n if (this.activeAnchor) {\n this.textValue = this.activeAnchor.textContent || '';\n } else if (!this.selectionRange.collapsed) {\n this.textValue = this.selectionRange.toString();\n } else {\n this.textValue = '';\n }\n }\n\n this.positionPopover();\n this.openPopover();\n\n requestAnimationFrame(() => {\n const inputs = this.querySelectorAll('nile-input');\n const target = inputs.length > 1 ? inputs[1] : inputs[0];\n (target as any)?.focus();\n });\n }\n\n \n\n private onInputKeydown = (e: KeyboardEvent) => {\n if (e.key !== 'Escape' && e.key !== 'Enter') return;\n e.preventDefault();\n e.stopPropagation();\n if (e.key === 'Escape') {\n this.closePopover();\n return;\n }\n this.isApplying = true;\n try {\n this.applyLink();\n } finally {\n this.isApplying = false;\n }\n };\n private onInputBlur = () => {\n if (this.ignoreBlur || this.isApplying) return;\n requestAnimationFrame(() => {\n if (this.ignoreBlur || this.isApplying) return;\n const pop = this.querySelector('nile-popover');\n if (pop?.matches(':focus-within')) return;\n this.closePopover();\n });\n };\n\n private onLinkInput = (e: CustomEvent) => {\n this.linkValue = e.detail.value;\n };\n\n private onTextInput = (e: CustomEvent) => {\n this.textValue = e.detail.value;\n };\n\n private onPopoverMousedown = () => {\n this.ignoreBlur = true;\n };\n\n private onPopoverMouseup = () => {\n this.ignoreBlur = false;\n };\n\n private onToolbarButtonMousedown = (e: Event) => {\n e.preventDefault();\n };\n\n private onActionMousedown = (e: Event) => {\n e.preventDefault();\n this.ignoreBlur = true;\n };\n\n private onApplyClick = () => {\n this.isApplying = true;\n this.applyLink();\n this.isApplying = false;\n this.ignoreBlur = false;\n };\n\n private onUnlinkClick = () => {\n this.isApplying = true;\n this.onRemove();\n this.isApplying = false;\n this.ignoreBlur = false;\n };\n\n \n\n private applyLink() {\n if (!(this.selectionRange instanceof Range)) return;\n\n let url = this.linkValue.trim();\n if (!url) return;\n\n if (/^javascript:/i.test(url)) return;\n\n if (!/^(https?:\\/\\/|mailto:|tel:|\\/)/i.test(url)) {\n url = `https://${url}`;\n }\n\n this.editorEl.focus();\n\n const sel = document.getSelection();\n if (!sel) return;\n\n sel.removeAllRanges();\n sel.addRange(this.selectionRange);\n\n const displayText = this.showTextSupport && this.textValue.trim()\n ? this.textValue.trim()\n : '';\n\n if (this.activeAnchor) {\n this.activeAnchor.href = url;\n\n if (displayText) {\n this.activeAnchor.textContent = displayText;\n }\n\n if (this.newTab) {\n this.activeAnchor.target = '_blank';\n this.activeAnchor.rel = 'noopener noreferrer';\n } else {\n this.activeAnchor.removeAttribute('target');\n this.activeAnchor.removeAttribute('rel');\n }\n \n } else {\n const link = document.createElement('a');\n link.href = url;\n \n if (this.newTab) {\n link.target = '_blank';\n link.rel = 'noopener noreferrer';\n } else {\n link.removeAttribute('target');\n link.removeAttribute('rel');\n } \n\n if (displayText) {\n this.selectionRange.deleteContents();\n link.textContent = displayText;\n this.selectionRange.insertNode(link);\n } else if (this.selectionRange.collapsed) {\n link.textContent = url;\n this.selectionRange.insertNode(link);\n } else {\n try {\n this.selectionRange.surroundContents(link);\n } catch {\n const frag = this.selectionRange.extractContents();\n link.appendChild(frag);\n this.selectionRange.insertNode(link);\n }\n }\n }\n\n this.emit(url);\n this.closePopover();\n }\n\n private onRemove() {\n if (!this.activeAnchor) return;\n this.unwrapLink(this.activeAnchor);\n this.emit('');\n this.closePopover();\n }\n\n private emit(href: string) {\n this.dispatchEvent(\n new CustomEvent('nile-link-changed', {\n detail: { href },\n bubbles: true,\n composed: true,\n })\n );\n }\n\n render() {\n const iconColor = this.disabled\n ? 'var(--nile-colors-neutral-500, var(--ng-colors-fg-disabled-subtle))'\n : 'var(--nile-colors-dark-900, var(--ng-colors-text-primary-900))';\n\n return html`\n <nile-lite-tooltip content=${this.label}>\n <nile-button\n variant=\"tertiary\"\n size=\"small\"\n ?disabled=${this.disabled}\n @mousedown=${this.onToolbarButtonMousedown}\n @click=${this.onOpen}\n class=\"rte-link-button\"\n >\n <nile-icon name=\"link_2\" color=${iconColor}></nile-icon>\n </nile-button>\n </nile-lite-tooltip>\n\n <nile-popover\n class=\"rte-link-popover\"\n .arrow=${false}\n style=${this.popoverStyle}\n @mousedown=${this.onPopoverMousedown}\n @mouseup=${this.onPopoverMouseup}\n >\n <div class=\"link-popup-wrap\">\n ${this.showTextSupport ? html`\n <div class=\"link-input-row\">\n <nile-input\n label=\"Text\"\n placeholder=${this.textPlaceholder}\n .value=${this.textValue}\n @nile-input=${this.onTextInput}\n @keydown=${this.onInputKeydown}\n @nile-blur=${this.onInputBlur}\n ></nile-input>\n </div>\n ` : null}\n <div class=\"link-actions-row\">\n <nile-input\n label=${this.showTextSupport ? 'URL' : ''}\n placeholder=${this.placeholder}\n .value=${this.linkValue}\n @nile-input=${this.onLinkInput}\n @keydown=${this.onInputKeydown}\n @nile-blur=${this.onInputBlur}\n ></nile-input>\n ${this.hasActiveLink ? html`\n <nile-button\n size=\"small\"\n variant=\"tertiary\"\n class=\"rte-edit-button\"\n @mousedown=${this.onActionMousedown}\n @click=${this.onApplyClick}\n >\n <nile-icon name=\"pencil\"></nile-icon>\n </nile-button>\n <nile-button\n size=\"small\"\n variant=\"tertiary\"\n class=\"rte-edit-button\"\n @mousedown=${this.onActionMousedown}\n @click=${this.onUnlinkClick}\n >\n <nile-icon name=\"unlink\"></nile-icon>\n </nile-button>\n ` : null}\n </div>\n </div>\n </nile-popover>\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'nile-rte-link': NileRteLink;\n }\n}\n"],"names":["NileRteLink","_i","o","constructor","this","newTab","disabled","showTextSupport","placeholder","textPlaceholder","label","linkValue","textValue","hasActiveLink","popoverStyle","selectionRange","activeAnchor","ignoreBlur","isApplying","onScroll","closePopover","onOpen","sel","document","getSelection","rangeCount","editorEl","contains","getRangeAt","commonAncestorContainer","cloneRange","n","startContainer","HTMLAnchorElement","parentNode","displayUrl","href","textContent","collapsed","toString","positionPopover","openPopover","requestAnimationFrame","inputs","querySelectorAll","target","length","focus","onInputKeydown","e","key","preventDefault","stopPropagation","applyLink","onInputBlur","pop","querySelector","matches","onLinkInput","detail","value","onTextInput","onPopoverMousedown","onPopoverMouseup","onToolbarButtonMousedown","onActionMousedown","onApplyClick","onUnlinkClick","onRemove","_this","_inherits","_createClass","createRenderRoot","connectedCallback","super","injectCss","cssText","style","createElement","setAttribute","insertBefore","firstChild","normalizeUrl","url","test","getSelectionRect","rect","getBoundingClientRect","width","height","span","insertNode","remove","concat","bottom","left","isShow","window","addEventListener","removeEventListener","unwrapLink","a","Range","trim","removeAllRanges","addRange","displayText","rel","removeAttribute","link","deleteContents","surroundContents","_unused","frag","extractContents","appendChild","emit","dispatchEvent","CustomEvent","bubbles","composed","render","iconColor","html","_templateObject","_taggedTemplateLiteral","_templateObject2","_templateObject3","LitElement","__decorate","property","attribute","protot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AAAA,CAAAA,CAAAA,CAAAA,CAAAoI,SAAA,CAAA,OAAA,CAAA,IAAA,EAE1DH,CAAAA,CAAAA,CAAAA,CAAA,CAAhBQ,CAAAA,CAAAA,CAAAA,CAAAA,CAA+BzI,CAAAoI,CAAAA,SAAAA,CAAA,WAAA,CAAA,IAAA,EAAA,CAAA,CACfH,CAAA,CAAA,CAAhBQ,CAA+BzI,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAoI,SAAA,CAAA,WAAA,CAAA,IAAA,EACfH,CAAAA,CAAAA,CAAAA,CAAA,CAAhBQ,CAAAA,CAAAA,CAAAA,CAAAA,CAAsCzI,CAAAoI,CAAAA,SAAAA,CAAA,eAAA,CAAA,IAAA,EAAA,CAAA,CACtBH,CAAA,CAAA,CAAhBQ,CAAkCzI,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAoI,SAAA,CAAA,cAAA,CAAA,IAAA,EAhBxBpI,CAAAA,CAAAA,CAAAA,CAAWiI,CAAA,CAAA,CADvBS,EAAc,eACF1I,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA,CAAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{__decorate as t}from"tslib";import{LitElement as i,html as n}from"lit";import{property as e,state as s,customElement as l}from"lit/decorators.js";let o=class extends i{constructor(){super(...arguments),this.newTab=!1,this.disabled=!1,this.showTextSupport=!1,this.placeholder="Type or paste link here",this.textPlaceholder="Display text",this.label="Link",this.linkValue="",this.textValue="",this.hasActiveLink=!1,this.popoverStyle="",this.selectionRange=null,this.activeAnchor=null,this.ignoreBlur=!1,this.isApplying=!1,this.onScroll=()=>{this.closePopover()},this.onOpen=()=>{if(this.disabled)return;const t=document.getSelection();if(!t||0===t.rangeCount)return;if(!this.editorEl.contains(t.getRangeAt(0).commonAncestorContainer))return;this.selectionRange=t.getRangeAt(0).cloneRange(),this.activeAnchor=null,this.hasActiveLink=!1;let i=this.selectionRange.startContainer;for(;i&&i!==this.editorEl;){if(i instanceof HTMLAnchorElement){this.activeAnchor=i,this.hasActiveLink=!0;break}i=i.parentNode}this.linkValue=this.activeAnchor?this.displayUrl(this.activeAnchor.href):"",this.showTextSupport&&(this.activeAnchor?this.textValue=this.activeAnchor.textContent||"":this.selectionRange.collapsed?this.textValue="":this.textValue=this.selectionRange.toString()),this.positionPopover(),this.openPopover(),requestAnimationFrame((()=>{const t=this.querySelectorAll("nile-input"),i=t.length>1?t[1]:t[0];i?.focus()}))},this.onInputKeydown=t=>{if("Escape"===t.key||"Enter"===t.key)if(t.preventDefault(),t.stopPropagation(),"Escape"!==t.key){this.isApplying=!0;try{this.applyLink()}finally{this.isApplying=!1}}else this.closePopover()},this.onInputBlur=()=>{this.ignoreBlur||this.isApplying||requestAnimationFrame((()=>{if(this.ignoreBlur||this.isApplying)return;const t=this.querySelector("nile-popover");t?.matches(":focus-within")||this.closePopover()}))},this.onLinkInput=t=>{this.linkValue=t.detail.value},this.onTextInput=t=>{this.textValue=t.detail.value},this.onPopoverMousedown=()=>{this.ignoreBlur=!0},this.onPopoverMouseup=()=>{this.ignoreBlur=!1},this.onToolbarButtonMousedown=t=>{t.preventDefault()},this.onActionMousedown=t=>{t.preventDefault(),this.ignoreBlur=!0},this.onApplyClick=()=>{this.isApplying=!0,this.applyLink(),this.isApplying=!1,this.ignoreBlur=!1},this.onUnlinkClick=()=>{this.isApplying=!0,this.onRemove(),this.isApplying=!1,this.ignoreBlur=!1}}createRenderRoot(){return this}connectedCallback(){super.connectedCallback(),this.injectCss("\n nile-popover.rte-link-popover::part(popover) {\n min-width: 340px;\n max-width: 420px;\n background: white;\n border: 1px solid var(--nile-colors-neutral-400, var(--ng-componentcolors-utility-gray-400));\n border-radius: 8px;\n padding: 0;\n gap: 0;\n overflow: hidden;\n height: auto;\n box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);\n }\n\n .link-popup-wrap {\n display: flex;\n flex-direction: column;\n gap: 12px;\n padding: 12px;\n }\n\n .link-popup-wrap nile-input {\n width: 100%;\n }\n\n .link-popup-wrap .link-input-row {\n width: 100%;\n }\n\n .link-popup-wrap .link-actions-row {\n display: flex;\n align-items: flex-end;\n gap: 4px;\n width: 100%;\n }\n\n .link-popup-wrap .link-actions-row nile-input {\n flex: 1;\n min-width: 0;\n }\n\n \n nile-button.rte-link-button::part(base) {\n border: none;\n height: 32px;\n width: 32px;\n }\n nile-button.rte-edit-button::part(base) {\n border: none;\n height: 32px;\n width: 32px;\n flex-shrink: 0;\n }\n ")}injectCss(t){if(this.querySelector("style[data-rte-link-style]"))return;const i=document.createElement("style");i.setAttribute("data-rte-link-style","true"),i.textContent=t,this.insertBefore(i,this.firstChild)}normalizeUrl(t){return/^(https?:|mailto:|tel:)/i.test(t)?t:`https://${t}`}displayUrl(t){return t}getSelectionRect(){if(!this.selectionRange)return null;let t=this.selectionRange.getBoundingClientRect();if(0===t.width&&0===t.height){const i=document.createElement("span");i.textContent="";this.selectionRange.cloneRange().insertNode(i),t=i.getBoundingClientRect(),i.remove()}return t}positionPopover(){const t=this.getSelectionRect();t&&(this.popoverStyle=`\n position: fixed;\n top: ${t.bottom+8}px;\n left: ${t.left+t.width/2}px;\n transform: translateX(-50%);\n z-index: 1000;\n `)}openPopover(){requestAnimationFrame((()=>{const t=this.querySelector("nile-popover");t&&(t.isShow=!0),window.addEventListener("scroll",this.onScroll,!0)}))}closePopover(){const t=this.querySelector("nile-popover");t&&(t.isShow=!1),window.removeEventListener("scroll",this.onScroll,!0),this.linkValue="",this.textValue="",this.selectionRange=null,this.activeAnchor=null,this.hasActiveLink=!1,this.popoverStyle=""}unwrapLink(t){for(;t.firstChild;)t.parentNode?.insertBefore(t.firstChild,t);t.remove()}applyLink(){if(!(this.selectionRange instanceof Range))return;let t=this.linkValue.trim();if(!t)return;if(/^javascript:/i.test(t))return;/^(https?:\/\/|mailto:|tel:|\/)/i.test(t)||(t=`https://${t}`),this.editorEl.focus();const i=document.getSelection();if(!i)return;i.removeAllRanges(),i.addRange(this.selectionRange);const n=this.showTextSupport&&this.textValue.trim()?this.textValue.trim():"";if(this.activeAnchor)this.activeAnchor.href=t,n&&(this.activeAnchor.textContent=n),this.newTab?(this.activeAnchor.target="_blank",this.activeAnchor.rel="noopener noreferrer"):(this.activeAnchor.removeAttribute("target"),this.activeAnchor.removeAttribute("rel"));else{const i=document.createElement("a");if(i.href=t,this.newTab?(i.target="_blank",i.rel="noopener noreferrer"):(i.removeAttribute("target"),i.removeAttribute("rel")),n)this.selectionRange.deleteContents(),i.textContent=n,this.selectionRange.insertNode(i);else if(this.selectionRange.collapsed)i.textContent=t,this.selectionRange.insertNode(i);else try{this.selectionRange.surroundContents(i)}catch{const t=this.selectionRange.extractContents();i.appendChild(t),this.selectionRange.insertNode(i)}}this.emit(t),this.closePopover()}onRemove(){this.activeAnchor&&(this.unwrapLink(this.activeAnchor),this.emit(""),this.closePopover())}emit(t){this.dispatchEvent(new CustomEvent("nile-link-changed",{detail:{href:t},bubbles:!0,composed:!0}))}render(){const t=this.disabled?"var(--nile-colors-neutral-500, var(--ng-colors-fg-disabled-subtle))":"var(--nile-colors-dark-900, var(--ng-colors-text-primary-900))";return n`
|
|
1
|
+
import{__decorate as t}from"tslib";import{LitElement as i,html as n}from"lit";import{property as e,state as s,customElement as l}from"lit/decorators.js";let o=class extends i{constructor(){super(...arguments),this.newTab=!1,this.disabled=!1,this.showTextSupport=!1,this.placeholder="Type or paste link here",this.textPlaceholder="Display text",this.label="Link",this.linkValue="",this.textValue="",this.hasActiveLink=!1,this.popoverStyle="",this.selectionRange=null,this.activeAnchor=null,this.ignoreBlur=!1,this.isApplying=!1,this.onScroll=()=>{this.closePopover()},this.onOpen=()=>{if(this.disabled)return;const t=document.getSelection();if(!t||0===t.rangeCount)return;if(!this.editorEl.contains(t.getRangeAt(0).commonAncestorContainer))return;this.selectionRange=t.getRangeAt(0).cloneRange(),this.activeAnchor=null,this.hasActiveLink=!1;let i=this.selectionRange.startContainer;for(;i&&i!==this.editorEl;){if(i instanceof HTMLAnchorElement){this.activeAnchor=i,this.hasActiveLink=!0;break}i=i.parentNode}this.linkValue=this.activeAnchor?this.displayUrl(this.activeAnchor.href):"",this.showTextSupport&&(this.activeAnchor?this.textValue=this.activeAnchor.textContent||"":this.selectionRange.collapsed?this.textValue="":this.textValue=this.selectionRange.toString()),this.positionPopover(),this.openPopover(),requestAnimationFrame((()=>{const t=this.querySelectorAll("nile-input"),i=t.length>1?t[1]:t[0];i?.focus()}))},this.onInputKeydown=t=>{if("Escape"===t.key||"Enter"===t.key)if(t.preventDefault(),t.stopPropagation(),"Escape"!==t.key){this.isApplying=!0;try{this.applyLink()}finally{this.isApplying=!1}}else this.closePopover()},this.onInputBlur=()=>{this.ignoreBlur||this.isApplying||requestAnimationFrame((()=>{if(this.ignoreBlur||this.isApplying)return;const t=this.querySelector("nile-popover");t?.matches(":focus-within")||this.closePopover()}))},this.onLinkInput=t=>{this.linkValue=t.detail.value},this.onTextInput=t=>{this.textValue=t.detail.value},this.onPopoverMousedown=()=>{this.ignoreBlur=!0},this.onPopoverMouseup=()=>{this.ignoreBlur=!1},this.onToolbarButtonMousedown=t=>{t.preventDefault()},this.onActionMousedown=t=>{t.preventDefault(),this.ignoreBlur=!0},this.onApplyClick=()=>{this.isApplying=!0,this.applyLink(),this.isApplying=!1,this.ignoreBlur=!1},this.onUnlinkClick=()=>{this.isApplying=!0,this.onRemove(),this.isApplying=!1,this.ignoreBlur=!1}}createRenderRoot(){return this}connectedCallback(){super.connectedCallback(),this.injectCss("\n nile-popover.rte-link-popover::part(popover) {\n min-width: 340px;\n max-width: 420px;\n background: var(--nile-colors-white-base, var(--ng-colors-bg-primary));\n border: 1px solid var(--nile-colors-neutral-400, var(--ng-componentcolors-utility-gray-400));\n border-radius: 8px;\n padding: 0;\n gap: 0;\n overflow: hidden;\n height: auto;\n box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);\n }\n\n .link-popup-wrap {\n display: flex;\n flex-direction: column;\n gap: 12px;\n padding: 12px;\n }\n\n .link-popup-wrap nile-input {\n width: 100%;\n }\n\n .link-popup-wrap .link-input-row {\n width: 100%;\n }\n\n .link-popup-wrap .link-actions-row {\n display: flex;\n align-items: flex-end;\n gap: 4px;\n width: 100%;\n }\n\n .link-popup-wrap .link-actions-row nile-input {\n flex: 1;\n min-width: 0;\n }\n\n \n nile-button.rte-link-button::part(base) {\n border: none;\n height: 32px;\n width: 32px;\n }\n nile-button.rte-edit-button::part(base) {\n border: none;\n height: 32px;\n width: 32px;\n flex-shrink: 0;\n }\n ")}injectCss(t){if(this.querySelector("style[data-rte-link-style]"))return;const i=document.createElement("style");i.setAttribute("data-rte-link-style","true"),i.textContent=t,this.insertBefore(i,this.firstChild)}normalizeUrl(t){return/^(https?:|mailto:|tel:)/i.test(t)?t:`https://${t}`}displayUrl(t){return t}getSelectionRect(){if(!this.selectionRange)return null;let t=this.selectionRange.getBoundingClientRect();if(0===t.width&&0===t.height){const i=document.createElement("span");i.textContent="";this.selectionRange.cloneRange().insertNode(i),t=i.getBoundingClientRect(),i.remove()}return t}positionPopover(){const t=this.getSelectionRect();t&&(this.popoverStyle=`\n position: fixed;\n top: ${t.bottom+8}px;\n left: ${t.left+t.width/2}px;\n transform: translateX(-50%);\n z-index: 1000;\n `)}openPopover(){requestAnimationFrame((()=>{const t=this.querySelector("nile-popover");t&&(t.isShow=!0),window.addEventListener("scroll",this.onScroll,!0)}))}closePopover(){const t=this.querySelector("nile-popover");t&&(t.isShow=!1),window.removeEventListener("scroll",this.onScroll,!0),this.linkValue="",this.textValue="",this.selectionRange=null,this.activeAnchor=null,this.hasActiveLink=!1,this.popoverStyle=""}unwrapLink(t){for(;t.firstChild;)t.parentNode?.insertBefore(t.firstChild,t);t.remove()}applyLink(){if(!(this.selectionRange instanceof Range))return;let t=this.linkValue.trim();if(!t)return;if(/^javascript:/i.test(t))return;/^(https?:\/\/|mailto:|tel:|\/)/i.test(t)||(t=`https://${t}`),this.editorEl.focus();const i=document.getSelection();if(!i)return;i.removeAllRanges(),i.addRange(this.selectionRange);const n=this.showTextSupport&&this.textValue.trim()?this.textValue.trim():"";if(this.activeAnchor)this.activeAnchor.href=t,n&&(this.activeAnchor.textContent=n),this.newTab?(this.activeAnchor.target="_blank",this.activeAnchor.rel="noopener noreferrer"):(this.activeAnchor.removeAttribute("target"),this.activeAnchor.removeAttribute("rel"));else{const i=document.createElement("a");if(i.href=t,this.newTab?(i.target="_blank",i.rel="noopener noreferrer"):(i.removeAttribute("target"),i.removeAttribute("rel")),n)this.selectionRange.deleteContents(),i.textContent=n,this.selectionRange.insertNode(i);else if(this.selectionRange.collapsed)i.textContent=t,this.selectionRange.insertNode(i);else try{this.selectionRange.surroundContents(i)}catch{const t=this.selectionRange.extractContents();i.appendChild(t),this.selectionRange.insertNode(i)}}this.emit(t),this.closePopover()}onRemove(){this.activeAnchor&&(this.unwrapLink(this.activeAnchor),this.emit(""),this.closePopover())}emit(t){this.dispatchEvent(new CustomEvent("nile-link-changed",{detail:{href:t},bubbles:!0,composed:!0}))}render(){const t=this.disabled?"var(--nile-colors-neutral-500, var(--ng-colors-fg-disabled-subtle))":"var(--nile-colors-dark-900, var(--ng-colors-text-primary-900))";return n`
|
|
2
2
|
<nile-lite-tooltip content=${this.label}>
|
|
3
3
|
<nile-button
|
|
4
4
|
variant="tertiary"
|
|
@@ -133,7 +133,7 @@ let NileRteLink = class NileRteLink extends LitElement {
|
|
|
133
133
|
nile-popover.rte-link-popover::part(popover) {
|
|
134
134
|
min-width: 340px;
|
|
135
135
|
max-width: 420px;
|
|
136
|
-
background: white;
|
|
136
|
+
background: var(--nile-colors-white-base, var(--ng-colors-bg-primary));
|
|
137
137
|
border: 1px solid var(--nile-colors-neutral-400, var(--ng-componentcolors-utility-gray-400));
|
|
138
138
|
border-radius: 8px;
|
|
139
139
|
padding: 0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nile-rte-link.js","sourceRoot":"","sources":["../../../src/nile-rich-text-editor/nile-rte-link.ts"],"names":[],"mappings":";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B;yBAC1B,IAAI,CAAC,aAAa;;;;aAI9B,CAAC,CAAC,CAAC,IAAI;;;;KAIf,CAAC;IACJ,CAAC;CACF,CAAA;AApbiC;IAA/B,QAAQ,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;6CAAwB;AACM;IAA5D,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;2CAAgB;AACf;IAA5D,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;6CAAkB;AACjB;IAA5D,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;oDAAyB;AACzB;IAA3D,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;gDAAyC;AACxC;IAA3D,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;oDAAkC;AACjC;IAA3D,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;0CAAgB;AAE1D;IAAhB,KAAK,EAAE;8CAAwB;AACf;IAAhB,KAAK,EAAE;8CAAwB;AACf;IAAhB,KAAK,EAAE;kDAA+B;AACtB;IAAhB,KAAK,EAAE;iDAA2B;AAhBxB,WAAW;IADvB,aAAa,CAAC,eAAe,CAAC;GAClB,WAAW,CAybvB","sourcesContent":["import { LitElement, html } from 'lit';\nimport { customElement, property, state } from 'lit/decorators.js';\n\n@customElement('nile-rte-link')\nexport class NileRteLink extends LitElement {\n protected createRenderRoot() {\n return this;\n }\n\n @property({ attribute: false }) editorEl!: HTMLElement;\n @property({ type: Boolean, reflect: true, attribute: true }) newTab = false;\n @property({ type: Boolean, reflect: true, attribute: true }) disabled = false;\n @property({ type: Boolean, reflect: true, attribute: true }) showTextSupport = false;\n @property({ type: String, reflect: true, attribute: true }) placeholder = 'Type or paste link here';\n @property({ type: String, reflect: true, attribute: true }) textPlaceholder = 'Display text';\n @property({ type: String, reflect: true, attribute: true }) label = 'Link';\n\n @state() private linkValue = '';\n @state() private textValue = '';\n @state() private hasActiveLink = false;\n @state() private popoverStyle = '';\n\n private selectionRange: Range | null = null;\n private activeAnchor: HTMLAnchorElement | null = null;\n\n private ignoreBlur = false;\n private isApplying = false;\n\n \n\n connectedCallback() {\n super.connectedCallback();\n\n this.injectCss(`\n nile-popover.rte-link-popover::part(popover) {\n min-width: 340px;\n max-width: 420px;\n background: white;\n border: 1px solid var(--nile-colors-neutral-400, var(--ng-componentcolors-utility-gray-400));\n border-radius: 8px;\n padding: 0;\n gap: 0;\n overflow: hidden;\n height: auto;\n box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);\n }\n\n .link-popup-wrap {\n display: flex;\n flex-direction: column;\n gap: 12px;\n padding: 12px;\n }\n\n .link-popup-wrap nile-input {\n width: 100%;\n }\n\n .link-popup-wrap .link-input-row {\n width: 100%;\n }\n\n .link-popup-wrap .link-actions-row {\n display: flex;\n align-items: flex-end;\n gap: 4px;\n width: 100%;\n }\n\n .link-popup-wrap .link-actions-row nile-input {\n flex: 1;\n min-width: 0;\n }\n\n \n nile-button.rte-link-button::part(base) {\n border: none;\n height: 32px;\n width: 32px;\n }\n nile-button.rte-edit-button::part(base) {\n border: none;\n height: 32px;\n width: 32px;\n flex-shrink: 0;\n }\n `);\n }\n\n private injectCss(cssText: string) {\n if (this.querySelector('style[data-rte-link-style]')) return;\n const style = document.createElement('style');\n style.setAttribute('data-rte-link-style', 'true');\n style.textContent = cssText;\n this.insertBefore(style, this.firstChild);\n }\n\n \n\n private normalizeUrl(url: string) {\n if (/^(https?:|mailto:|tel:)/i.test(url)) return url;\n return `https://${url}`;\n }\n\n private displayUrl(url: string): string {\n return url;\n }\n\n private getSelectionRect(): DOMRect | null {\n if (!this.selectionRange) return null;\n\n let rect = this.selectionRange.getBoundingClientRect();\n if (rect.width === 0 && rect.height === 0) {\n const span = document.createElement('span');\n span.textContent = '\\u200b';\n const tempRange = this.selectionRange.cloneRange();\n tempRange.insertNode(span);\n rect = span.getBoundingClientRect();\n span.remove(); \n }\n return rect;\n }\n\n private positionPopover() {\n const rect = this.getSelectionRect();\n if (!rect) return;\n\n this.popoverStyle = `\n position: fixed;\n top: ${rect.bottom + 8}px;\n left: ${rect.left + rect.width / 2}px;\n transform: translateX(-50%);\n z-index: 1000;\n `;\n }\n\n private onScroll = () => {\n this.closePopover();\n };\n\n private openPopover() {\n requestAnimationFrame(() => {\n const pop = this.querySelector('nile-popover') as any;\n pop && (pop.isShow = true);\n window.addEventListener('scroll', this.onScroll, true);\n });\n }\n\n private closePopover() {\n const pop = this.querySelector('nile-popover') as any;\n pop && (pop.isShow = false);\n\n window.removeEventListener('scroll', this.onScroll, true);\n\n this.linkValue = '';\n this.textValue = '';\n this.selectionRange = null;\n this.activeAnchor = null;\n this.hasActiveLink = false;\n this.popoverStyle = '';\n }\n\n private unwrapLink(a: HTMLAnchorElement) {\n while (a.firstChild) a.parentNode?.insertBefore(a.firstChild, a);\n a.remove();\n }\n\n \n\n private onOpen = () => {\n if (this.disabled) return;\n\n const sel = document.getSelection();\n if (!sel || sel.rangeCount === 0) return;\n if (!this.editorEl.contains(sel.getRangeAt(0).commonAncestorContainer)) return;\n\n this.selectionRange = sel.getRangeAt(0).cloneRange();\n this.activeAnchor = null;\n this.hasActiveLink = false;\n\n let n: Node | null = this.selectionRange.startContainer;\n while (n && n !== this.editorEl) {\n if (n instanceof HTMLAnchorElement) {\n this.activeAnchor = n;\n this.hasActiveLink = true;\n break;\n }\n n = n.parentNode;\n }\n\n this.linkValue = this.activeAnchor\n ? this.displayUrl(this.activeAnchor.href)\n : '';\n\n if (this.showTextSupport) {\n if (this.activeAnchor) {\n this.textValue = this.activeAnchor.textContent || '';\n } else if (!this.selectionRange.collapsed) {\n this.textValue = this.selectionRange.toString();\n } else {\n this.textValue = '';\n }\n }\n\n this.positionPopover();\n this.openPopover();\n\n requestAnimationFrame(() => {\n const inputs = this.querySelectorAll('nile-input');\n const target = inputs.length > 1 ? inputs[1] : inputs[0];\n (target as any)?.focus();\n });\n }\n\n \n\n private onInputKeydown = (e: KeyboardEvent) => {\n if (e.key !== 'Escape' && e.key !== 'Enter') return;\n e.preventDefault();\n e.stopPropagation();\n if (e.key === 'Escape') {\n this.closePopover();\n return;\n }\n this.isApplying = true;\n try {\n this.applyLink();\n } finally {\n this.isApplying = false;\n }\n };\n private onInputBlur = () => {\n if (this.ignoreBlur || this.isApplying) return;\n requestAnimationFrame(() => {\n if (this.ignoreBlur || this.isApplying) return;\n const pop = this.querySelector('nile-popover');\n if (pop?.matches(':focus-within')) return;\n this.closePopover();\n });\n };\n\n private onLinkInput = (e: CustomEvent) => {\n this.linkValue = e.detail.value;\n };\n\n private onTextInput = (e: CustomEvent) => {\n this.textValue = e.detail.value;\n };\n\n private onPopoverMousedown = () => {\n this.ignoreBlur = true;\n };\n\n private onPopoverMouseup = () => {\n this.ignoreBlur = false;\n };\n\n private onToolbarButtonMousedown = (e: Event) => {\n e.preventDefault();\n };\n\n private onActionMousedown = (e: Event) => {\n e.preventDefault();\n this.ignoreBlur = true;\n };\n\n private onApplyClick = () => {\n this.isApplying = true;\n this.applyLink();\n this.isApplying = false;\n this.ignoreBlur = false;\n };\n\n private onUnlinkClick = () => {\n this.isApplying = true;\n this.onRemove();\n this.isApplying = false;\n this.ignoreBlur = false;\n };\n\n \n\n private applyLink() {\n if (!(this.selectionRange instanceof Range)) return;\n\n let url = this.linkValue.trim();\n if (!url) return;\n\n if (/^javascript:/i.test(url)) return;\n\n if (!/^(https?:\\/\\/|mailto:|tel:|\\/)/i.test(url)) {\n url = `https://${url}`;\n }\n\n this.editorEl.focus();\n\n const sel = document.getSelection();\n if (!sel) return;\n\n sel.removeAllRanges();\n sel.addRange(this.selectionRange);\n\n const displayText = this.showTextSupport && this.textValue.trim()\n ? this.textValue.trim()\n : '';\n\n if (this.activeAnchor) {\n this.activeAnchor.href = url;\n\n if (displayText) {\n this.activeAnchor.textContent = displayText;\n }\n\n if (this.newTab) {\n this.activeAnchor.target = '_blank';\n this.activeAnchor.rel = 'noopener noreferrer';\n } else {\n this.activeAnchor.removeAttribute('target');\n this.activeAnchor.removeAttribute('rel');\n }\n \n } else {\n const link = document.createElement('a');\n link.href = url;\n \n if (this.newTab) {\n link.target = '_blank';\n link.rel = 'noopener noreferrer';\n } else {\n link.removeAttribute('target');\n link.removeAttribute('rel');\n } \n\n if (displayText) {\n this.selectionRange.deleteContents();\n link.textContent = displayText;\n this.selectionRange.insertNode(link);\n } else if (this.selectionRange.collapsed) {\n link.textContent = url;\n this.selectionRange.insertNode(link);\n } else {\n try {\n this.selectionRange.surroundContents(link);\n } catch {\n const frag = this.selectionRange.extractContents();\n link.appendChild(frag);\n this.selectionRange.insertNode(link);\n }\n }\n }\n\n this.emit(url);\n this.closePopover();\n }\n\n private onRemove() {\n if (!this.activeAnchor) return;\n this.unwrapLink(this.activeAnchor);\n this.emit('');\n this.closePopover();\n }\n\n private emit(href: string) {\n this.dispatchEvent(\n new CustomEvent('nile-link-changed', {\n detail: { href },\n bubbles: true,\n composed: true,\n })\n );\n }\n\n render() {\n const iconColor = this.disabled\n ? 'var(--nile-colors-neutral-500, var(--ng-colors-fg-disabled-subtle))'\n : 'var(--nile-colors-dark-900, var(--ng-colors-text-primary-900))';\n\n return html`\n <nile-lite-tooltip content=${this.label}>\n <nile-button\n variant=\"tertiary\"\n size=\"small\"\n ?disabled=${this.disabled}\n @mousedown=${this.onToolbarButtonMousedown}\n @click=${this.onOpen}\n class=\"rte-link-button\"\n >\n <nile-icon name=\"link_2\" color=${iconColor}></nile-icon>\n </nile-button>\n </nile-lite-tooltip>\n\n <nile-popover\n class=\"rte-link-popover\"\n .arrow=${false}\n style=${this.popoverStyle}\n @mousedown=${this.onPopoverMousedown}\n @mouseup=${this.onPopoverMouseup}\n >\n <div class=\"link-popup-wrap\">\n ${this.showTextSupport ? html`\n <div class=\"link-input-row\">\n <nile-input\n label=\"Text\"\n placeholder=${this.textPlaceholder}\n .value=${this.textValue}\n @nile-input=${this.onTextInput}\n @keydown=${this.onInputKeydown}\n @nile-blur=${this.onInputBlur}\n ></nile-input>\n </div>\n ` : null}\n <div class=\"link-actions-row\">\n <nile-input\n label=${this.showTextSupport ? 'URL' : ''}\n placeholder=${this.placeholder}\n .value=${this.linkValue}\n @nile-input=${this.onLinkInput}\n @keydown=${this.onInputKeydown}\n @nile-blur=${this.onInputBlur}\n ></nile-input>\n ${this.hasActiveLink ? html`\n <nile-button\n size=\"small\"\n variant=\"tertiary\"\n class=\"rte-edit-button\"\n @mousedown=${this.onActionMousedown}\n @click=${this.onApplyClick}\n >\n <nile-icon name=\"pencil\"></nile-icon>\n </nile-button>\n <nile-button\n size=\"small\"\n variant=\"tertiary\"\n class=\"rte-edit-button\"\n @mousedown=${this.onActionMousedown}\n @click=${this.onUnlinkClick}\n >\n <nile-icon name=\"unlink\"></nile-icon>\n </nile-button>\n ` : null}\n </div>\n </div>\n </nile-popover>\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'nile-rte-link': NileRteLink;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"nile-rte-link.js","sourceRoot":"","sources":["../../../src/nile-rich-text-editor/nile-rte-link.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAG5D,IAAM,WAAW,GAAjB,MAAM,WAAY,SAAQ,UAAU;IAApC;;QAMwD,WAAM,GAAG,KAAK,CAAC;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AE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;2CAAgB;AACf;IAA5D,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;6CAAkB;AACjB;IAA5D,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;oDAAyB;AACzB;IAA3D,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;gDAAyC;AACxC;IAA3D,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;oDAAkC;AACjC;IAA3D,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;0CAAgB;AAE1D;IAAhB,KAAK,EAAE;8CAAwB;AACf;IAAhB,KAAK,EAAE;8CAAwB;AACf;IAAhB,KAAK,EAAE;kDAA+B;AACtB;IAAhB,KAAK,EAAE;iDAA2B;AAhBxB,WAAW;IADvB,aAAa,CAAC,eAAe,CAAC;GAClB,WAAW,CAybvB","sourcesContent":["import { LitElement, html } from 'lit';\nimport { customElement, property, state } from 'lit/decorators.js';\n\n@customElement('nile-rte-link')\nexport class NileRteLink extends LitElement {\n protected createRenderRoot() {\n return this;\n }\n\n @property({ attribute: false }) editorEl!: HTMLElement;\n @property({ type: Boolean, reflect: true, attribute: true }) newTab = false;\n @property({ type: Boolean, reflect: true, attribute: true }) disabled = false;\n @property({ type: Boolean, reflect: true, attribute: true }) showTextSupport = false;\n @property({ type: String, reflect: true, attribute: true }) placeholder = 'Type or paste link here';\n @property({ type: String, reflect: true, attribute: true }) textPlaceholder = 'Display text';\n @property({ type: String, reflect: true, attribute: true }) label = 'Link';\n\n @state() private linkValue = '';\n @state() private textValue = '';\n @state() private hasActiveLink = false;\n @state() private popoverStyle = '';\n\n private selectionRange: Range | null = null;\n private activeAnchor: HTMLAnchorElement | null = null;\n\n private ignoreBlur = false;\n private isApplying = false;\n\n \n\n connectedCallback() {\n super.connectedCallback();\n\n this.injectCss(`\n nile-popover.rte-link-popover::part(popover) {\n min-width: 340px;\n max-width: 420px;\n background: var(--nile-colors-white-base, var(--ng-colors-bg-primary));\n border: 1px solid var(--nile-colors-neutral-400, var(--ng-componentcolors-utility-gray-400));\n border-radius: 8px;\n padding: 0;\n gap: 0;\n overflow: hidden;\n height: auto;\n box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);\n }\n\n .link-popup-wrap {\n display: flex;\n flex-direction: column;\n gap: 12px;\n padding: 12px;\n }\n\n .link-popup-wrap nile-input {\n width: 100%;\n }\n\n .link-popup-wrap .link-input-row {\n width: 100%;\n }\n\n .link-popup-wrap .link-actions-row {\n display: flex;\n align-items: flex-end;\n gap: 4px;\n width: 100%;\n }\n\n .link-popup-wrap .link-actions-row nile-input {\n flex: 1;\n min-width: 0;\n }\n\n \n nile-button.rte-link-button::part(base) {\n border: none;\n height: 32px;\n width: 32px;\n }\n nile-button.rte-edit-button::part(base) {\n border: none;\n height: 32px;\n width: 32px;\n flex-shrink: 0;\n }\n `);\n }\n\n private injectCss(cssText: string) {\n if (this.querySelector('style[data-rte-link-style]')) return;\n const style = document.createElement('style');\n style.setAttribute('data-rte-link-style', 'true');\n style.textContent = cssText;\n this.insertBefore(style, this.firstChild);\n }\n\n \n\n private normalizeUrl(url: string) {\n if (/^(https?:|mailto:|tel:)/i.test(url)) return url;\n return `https://${url}`;\n }\n\n private displayUrl(url: string): string {\n return url;\n }\n\n private getSelectionRect(): DOMRect | null {\n if (!this.selectionRange) return null;\n\n let rect = this.selectionRange.getBoundingClientRect();\n if (rect.width === 0 && rect.height === 0) {\n const span = document.createElement('span');\n span.textContent = '\\u200b';\n const tempRange = this.selectionRange.cloneRange();\n tempRange.insertNode(span);\n rect = span.getBoundingClientRect();\n span.remove(); \n }\n return rect;\n }\n\n private positionPopover() {\n const rect = this.getSelectionRect();\n if (!rect) return;\n\n this.popoverStyle = `\n position: fixed;\n top: ${rect.bottom + 8}px;\n left: ${rect.left + rect.width / 2}px;\n transform: translateX(-50%);\n z-index: 1000;\n `;\n }\n\n private onScroll = () => {\n this.closePopover();\n };\n\n private openPopover() {\n requestAnimationFrame(() => {\n const pop = this.querySelector('nile-popover') as any;\n pop && (pop.isShow = true);\n window.addEventListener('scroll', this.onScroll, true);\n });\n }\n\n private closePopover() {\n const pop = this.querySelector('nile-popover') as any;\n pop && (pop.isShow = false);\n\n window.removeEventListener('scroll', this.onScroll, true);\n\n this.linkValue = '';\n this.textValue = '';\n this.selectionRange = null;\n this.activeAnchor = null;\n this.hasActiveLink = false;\n this.popoverStyle = '';\n }\n\n private unwrapLink(a: HTMLAnchorElement) {\n while (a.firstChild) a.parentNode?.insertBefore(a.firstChild, a);\n a.remove();\n }\n\n \n\n private onOpen = () => {\n if (this.disabled) return;\n\n const sel = document.getSelection();\n if (!sel || sel.rangeCount === 0) return;\n if (!this.editorEl.contains(sel.getRangeAt(0).commonAncestorContainer)) return;\n\n this.selectionRange = sel.getRangeAt(0).cloneRange();\n this.activeAnchor = null;\n this.hasActiveLink = false;\n\n let n: Node | null = this.selectionRange.startContainer;\n while (n && n !== this.editorEl) {\n if (n instanceof HTMLAnchorElement) {\n this.activeAnchor = n;\n this.hasActiveLink = true;\n break;\n }\n n = n.parentNode;\n }\n\n this.linkValue = this.activeAnchor\n ? this.displayUrl(this.activeAnchor.href)\n : '';\n\n if (this.showTextSupport) {\n if (this.activeAnchor) {\n this.textValue = this.activeAnchor.textContent || '';\n } else if (!this.selectionRange.collapsed) {\n this.textValue = this.selectionRange.toString();\n } else {\n this.textValue = '';\n }\n }\n\n this.positionPopover();\n this.openPopover();\n\n requestAnimationFrame(() => {\n const inputs = this.querySelectorAll('nile-input');\n const target = inputs.length > 1 ? inputs[1] : inputs[0];\n (target as any)?.focus();\n });\n }\n\n \n\n private onInputKeydown = (e: KeyboardEvent) => {\n if (e.key !== 'Escape' && e.key !== 'Enter') return;\n e.preventDefault();\n e.stopPropagation();\n if (e.key === 'Escape') {\n this.closePopover();\n return;\n }\n this.isApplying = true;\n try {\n this.applyLink();\n } finally {\n this.isApplying = false;\n }\n };\n private onInputBlur = () => {\n if (this.ignoreBlur || this.isApplying) return;\n requestAnimationFrame(() => {\n if (this.ignoreBlur || this.isApplying) return;\n const pop = this.querySelector('nile-popover');\n if (pop?.matches(':focus-within')) return;\n this.closePopover();\n });\n };\n\n private onLinkInput = (e: CustomEvent) => {\n this.linkValue = e.detail.value;\n };\n\n private onTextInput = (e: CustomEvent) => {\n this.textValue = e.detail.value;\n };\n\n private onPopoverMousedown = () => {\n this.ignoreBlur = true;\n };\n\n private onPopoverMouseup = () => {\n this.ignoreBlur = false;\n };\n\n private onToolbarButtonMousedown = (e: Event) => {\n e.preventDefault();\n };\n\n private onActionMousedown = (e: Event) => {\n e.preventDefault();\n this.ignoreBlur = true;\n };\n\n private onApplyClick = () => {\n this.isApplying = true;\n this.applyLink();\n this.isApplying = false;\n this.ignoreBlur = false;\n };\n\n private onUnlinkClick = () => {\n this.isApplying = true;\n this.onRemove();\n this.isApplying = false;\n this.ignoreBlur = false;\n };\n\n \n\n private applyLink() {\n if (!(this.selectionRange instanceof Range)) return;\n\n let url = this.linkValue.trim();\n if (!url) return;\n\n if (/^javascript:/i.test(url)) return;\n\n if (!/^(https?:\\/\\/|mailto:|tel:|\\/)/i.test(url)) {\n url = `https://${url}`;\n }\n\n this.editorEl.focus();\n\n const sel = document.getSelection();\n if (!sel) return;\n\n sel.removeAllRanges();\n sel.addRange(this.selectionRange);\n\n const displayText = this.showTextSupport && this.textValue.trim()\n ? this.textValue.trim()\n : '';\n\n if (this.activeAnchor) {\n this.activeAnchor.href = url;\n\n if (displayText) {\n this.activeAnchor.textContent = displayText;\n }\n\n if (this.newTab) {\n this.activeAnchor.target = '_blank';\n this.activeAnchor.rel = 'noopener noreferrer';\n } else {\n this.activeAnchor.removeAttribute('target');\n this.activeAnchor.removeAttribute('rel');\n }\n \n } else {\n const link = document.createElement('a');\n link.href = url;\n \n if (this.newTab) {\n link.target = '_blank';\n link.rel = 'noopener noreferrer';\n } else {\n link.removeAttribute('target');\n link.removeAttribute('rel');\n } \n\n if (displayText) {\n this.selectionRange.deleteContents();\n link.textContent = displayText;\n this.selectionRange.insertNode(link);\n } else if (this.selectionRange.collapsed) {\n link.textContent = url;\n this.selectionRange.insertNode(link);\n } else {\n try {\n this.selectionRange.surroundContents(link);\n } catch {\n const frag = this.selectionRange.extractContents();\n link.appendChild(frag);\n this.selectionRange.insertNode(link);\n }\n }\n }\n\n this.emit(url);\n this.closePopover();\n }\n\n private onRemove() {\n if (!this.activeAnchor) return;\n this.unwrapLink(this.activeAnchor);\n this.emit('');\n this.closePopover();\n }\n\n private emit(href: string) {\n this.dispatchEvent(\n new CustomEvent('nile-link-changed', {\n detail: { href },\n bubbles: true,\n composed: true,\n })\n );\n }\n\n render() {\n const iconColor = this.disabled\n ? 'var(--nile-colors-neutral-500, var(--ng-colors-fg-disabled-subtle))'\n : 'var(--nile-colors-dark-900, var(--ng-colors-text-primary-900))';\n\n return html`\n <nile-lite-tooltip content=${this.label}>\n <nile-button\n variant=\"tertiary\"\n size=\"small\"\n ?disabled=${this.disabled}\n @mousedown=${this.onToolbarButtonMousedown}\n @click=${this.onOpen}\n class=\"rte-link-button\"\n >\n <nile-icon name=\"link_2\" color=${iconColor}></nile-icon>\n </nile-button>\n </nile-lite-tooltip>\n\n <nile-popover\n class=\"rte-link-popover\"\n .arrow=${false}\n style=${this.popoverStyle}\n @mousedown=${this.onPopoverMousedown}\n @mouseup=${this.onPopoverMouseup}\n >\n <div class=\"link-popup-wrap\">\n ${this.showTextSupport ? html`\n <div class=\"link-input-row\">\n <nile-input\n label=\"Text\"\n placeholder=${this.textPlaceholder}\n .value=${this.textValue}\n @nile-input=${this.onTextInput}\n @keydown=${this.onInputKeydown}\n @nile-blur=${this.onInputBlur}\n ></nile-input>\n </div>\n ` : null}\n <div class=\"link-actions-row\">\n <nile-input\n label=${this.showTextSupport ? 'URL' : ''}\n placeholder=${this.placeholder}\n .value=${this.linkValue}\n @nile-input=${this.onLinkInput}\n @keydown=${this.onInputKeydown}\n @nile-blur=${this.onInputBlur}\n ></nile-input>\n ${this.hasActiveLink ? html`\n <nile-button\n size=\"small\"\n variant=\"tertiary\"\n class=\"rte-edit-button\"\n @mousedown=${this.onActionMousedown}\n @click=${this.onApplyClick}\n >\n <nile-icon name=\"pencil\"></nile-icon>\n </nile-button>\n <nile-button\n size=\"small\"\n variant=\"tertiary\"\n class=\"rte-edit-button\"\n @mousedown=${this.onActionMousedown}\n @click=${this.onUnlinkClick}\n >\n <nile-icon name=\"unlink\"></nile-icon>\n </nile-button>\n ` : null}\n </div>\n </div>\n </nile-popover>\n `;\n }\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'nile-rte-link': NileRteLink;\n }\n}\n"]}
|
|
@@ -466,5 +466,12 @@ describe('NileRteLink', () => {
|
|
|
466
466
|
const styleTags = el.querySelectorAll('style[data-rte-link-style]');
|
|
467
467
|
expect(styleTags.length).to.equal(1);
|
|
468
468
|
});
|
|
469
|
+
it('46. popover background is themed, not hardcoded white (PC-3998)', async () => {
|
|
470
|
+
editor = createEditor();
|
|
471
|
+
const el = await fixture(html `<nile-rte-link .editorEl=${editor}></nile-rte-link>`);
|
|
472
|
+
const css = el.querySelector('style[data-rte-link-style]').textContent;
|
|
473
|
+
expect(css).to.not.match(/background:\s*white/);
|
|
474
|
+
expect(css).to.contain('--ng-colors-bg-primary');
|
|
475
|
+
});
|
|
469
476
|
});
|
|
470
477
|
//# sourceMappingURL=nile-rte-link.test.js.map
|