@aquera/nile-elements 1.3.0-beta-1.2 → 1.3.0-beta-1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +6 -6
- package/dist/nile-auto-complete/nile-auto-complete.cjs.js +1 -1
- package/dist/nile-auto-complete/nile-auto-complete.cjs.js.map +1 -1
- package/dist/nile-auto-complete/nile-auto-complete.esm.js +1 -1
- package/dist/nile-chip/nile-chip.cjs.js +1 -1
- package/dist/nile-chip/nile-chip.cjs.js.map +1 -1
- package/dist/nile-chip/nile-chip.esm.js +1 -1
- package/dist/nile-dropdown/nile-dropdown.cjs.js +1 -1
- package/dist/nile-dropdown/nile-dropdown.cjs.js.map +1 -1
- package/dist/nile-dropdown/nile-dropdown.esm.js +1 -1
- package/dist/nile-popover/nile-popover.cjs.js +1 -1
- package/dist/nile-popover/nile-popover.cjs.js.map +1 -1
- package/dist/nile-popover/nile-popover.esm.js +1 -1
- package/dist/nile-virtual-select/nile-virtual-select.cjs.js +1 -1
- package/dist/nile-virtual-select/nile-virtual-select.cjs.js.map +1 -1
- package/dist/nile-virtual-select/nile-virtual-select.esm.js +1 -1
- package/dist/src/nile-auto-complete/nile-auto-complete.js +0 -1
- package/dist/src/nile-auto-complete/nile-auto-complete.js.map +1 -1
- package/dist/src/nile-chip/nile-chip.js +0 -1
- package/dist/src/nile-chip/nile-chip.js.map +1 -1
- package/dist/src/nile-dropdown/nile-dropdown.js +0 -1
- package/dist/src/nile-dropdown/nile-dropdown.js.map +1 -1
- package/dist/src/nile-popover/nile-popover.js +0 -1
- package/dist/src/nile-popover/nile-popover.js.map +1 -1
- package/dist/src/nile-virtual-select/nile-virtual-select.js +0 -1
- package/dist/src/nile-virtual-select/nile-virtual-select.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-auto-complete/nile-auto-complete.ts +0 -2
- package/src/nile-chip/nile-chip.ts +0 -1
- package/src/nile-dropdown/nile-dropdown.ts +0 -1
- package/src/nile-popover/nile-popover.ts +0 -1
- package/src/nile-virtual-select/nile-virtual-select.ts +0 -1
package/dist/index.js
CHANGED
|
@@ -4832,7 +4832,7 @@ class QM{constructor(e){this._element=null;const t=e??window;this._node=t,e&&(th
|
|
|
4832
4832
|
>
|
|
4833
4833
|
${xe(l)}
|
|
4834
4834
|
</nile-option>
|
|
4835
|
-
`}static shouldUseVirtualizer(e){return e.length>=5}}let PM=class{static calculateAvailableSpace(e){const t=e.getBoundingClientRect(),i=window.innerHeight,M=i-t.bottom;return{spaceAbove:t.top,spaceBelow:M,viewportHeight:i}}static getOptimalPlacement(e){const{spaceAbove:t,spaceBelow:i}=this.calculateAvailableSpace(e);return i<200&&t>i?"top":"bottom"}static findBoundaryElements(e){const t=[];let i=e.parentElement;for(;i&&i!==document.body;){const e=window.getComputedStyle(i),M=e.overflow,n=e.overflowY,o=e.overflowX;"auto"!==M&&"scroll"!==M&&"auto"!==n&&"scroll"!==n&&"auto"!==o&&"scroll"!==o||t.push(i),(i.hasAttribute("data-floating-boundary")||i.classList.contains("floating-boundary")||i.classList.contains("scroll-container"))&&t.push(i),i=i.parentElement}return t.length>0?t:void 0}static calculateOptimalHeight(e,t,i){const M=t-(e.y+e.height),n=e.y;return n>M?Math.max(n-20,100):M>n?Math.max(M-20,100):Math.max(Math.min(n,M)-20,100)}static extractStylesAsCSS(e){return"string"==typeof e?e:Array.isArray(e)?e.map((e=>this.extractStylesAsCSS(e))).join("\n"):e&&"object"==typeof e&&e.cssText?e.cssText:""}static generateStyleId(){return`nile-select-styles-${Math.random().toString(36).substring(2,11)}`}static isPositioningOptimal(e,t){const{spaceAbove:i,spaceBelow:M}=this.calculateAvailableSpace(t),n=e.startsWith("top"),o=e.startsWith("bottom");return!(n&&M>i)&&!(o&&i>M)}static applyCollisionData(e,t,i){if(t.flip){const{overflows:M}=t.flip;if(e.setAttribute("data-placement",i),M&&M.length>0){const t=M.map((e=>e.placement)).join(",");e.setAttribute("data-overflow",t)}else e.removeAttribute("data-overflow")}if(t.shift){const{x:i,y:M}=t.shift;void 0===i||void 0===M||0===i&&0===M?e.removeAttribute("data-shift"):e.setAttribute("data-shift",`${i},${M}`)}if(t.size){const{availableWidth:i,availableHeight:M}=t.size;void 0!==i&&e.setAttribute("data-available-width",i.toString()),void 0!==M&&e.setAttribute("data-available-height",M.toString())}}static createFloatingUIMiddleware(e,t){return[]}},RM=class{static createBaseListbox(e){const t=document.createElement("div");return t.className="select__listbox "+(e.searchEnabled?"select__search-enabled ":""),t.setAttribute("tabindex","-1"),t}static addSearchSection(e,t){if(!t.searchEnabled)return;const i=document.createElement("div");i.className="select__search",i.innerHTML=`\n <nile-input size="small" clearable value="${t.searchValue}" placeholder="${t.internalSearchPlaceHolder}">\n <nile-icon name="var(--nile-icon-search, var(--ng-icon-search-lg))" method="var(--nile-svg-method-fill, var(--ng-svg-method-stroke))" slot="suffix"></nile-icon>\n </nile-input>\n `,e.appendChild(i)}static addLoadingSection(e,t){if(!t.optionsLoading)return;const i=document.createElement("span");i.className="select__loader",i.innerHTML='\n <nile-icon class="select__loader--icon" name="var(--nile-icon-button-loading-blue, var(--ng-icon-button-loading-blue))" method="var(--nile-svg-method-fill, var(--ng-svg-method-stroke))"></nile-icon>\n ',e.appendChild(i)}static addOptionsSection(e,t){const i=document.createElement("div");i.className="select__options "+(t.searchEnabled?"select__options__search-enabled":""),this.addNoResultsMessage(i,t),this.addClonedOptions(i,t),e.appendChild(i)}static addNoResultsMessage(e,t){if(!t.showNoResults)return;const i=document.createElement("div");i.className="select__no-results",i.textContent=t.noResultsMessage,e.appendChild(i)}static addClonedOptions(e,t){Array.from(t.querySelectorAll("nile-option")).forEach((t=>{const i=this.cloneOption(t);e.appendChild(i)}))}static cloneOption(e){const t=e.cloneNode(!0);return Array.from(e.attributes).forEach((e=>{t.setAttribute(e.name,e.value)})),this.copyOptionProperties(e,t),t}static copyOptionProperties(e,t){["selected","disabled","current","hidden"].forEach((i=>{void 0!==e[i]&&(t[i]=e[i])}))}static addFooterSection(e,t){if(!t.multiple)return;const i=this.createFooter(t);e.appendChild(i)}static createFooter(e){const t=document.createElement("div");return t.setAttribute("part","footer"),t.className="select__footer",this.addShowSelectedToggle(t,e),this.addClearAllButton(t,e),t}static addShowSelectedToggle(e,t){const i=document.createElement("span");i.style.cursor="pointer";const M=document.createElement("nile-checkbox");M.disabled=0===t.selectedOptions.length,M.checked=t.showSelected,M.innerHTML=" Show Selected",i.appendChild(M),e.appendChild(i)}static addClearAllButton(e,t){if(0===t.selectedOptions.length)return;const i=document.createElement("span");i.className="select__clear",i.textContent="Clear All",i.style.cursor="pointer",e.appendChild(i)}static updateClonedOptions(e,t){const i=e.querySelector(".select__options");if(!i)return;const M=Array.from(t.querySelectorAll("nile-option")),n=Array.from(i.querySelectorAll("nile-option"));M.forEach(((e,t)=>{const i=n[t];i&&this.updateClonedOption(e,i)}))}static updateClonedOption(e,t){t.selected=e.selected,t.disabled=e.disabled,t.current=e.current,t.hidden=e.hidden,this.updateClonedOptionAttributes(e,t)}static updateClonedOptionAttributes(e,t){[{prop:"selected",attr:"selected"},{prop:"disabled",attr:"disabled"},{prop:"current",attr:"current"},{prop:"hidden",attr:"hidden"}].forEach((({prop:i,attr:M})=>{e[i]?t.setAttribute(M,""):t.removeAttribute(M)}))}static createPortalListbox(e){const t=this.createBaseListbox(e);return this.addSearchSection(t,e),this.addLoadingSection(t,e),this.addOptionsSection(t,e),this.addFooterSection(t,e),t}},BM=class{static setupPortalEventListeners(e,t){e&&(this.setupOptionClickListeners(e,t),this.setupScrollListeners(e,t),this.setupSearchListeners(e,t),this.setupFooterListeners(e,t),this.setupSlotListeners(e,t))}static setupOptionClickListeners(e,t){e&&e.addEventListener("mouseup",(e=>{const i=e.target.closest("nile-option");i&&this.handleOptionClick(i,t)}))}static handleOptionClick(e,t){const i=t.querySelector(`nile-option[value="${e.getAttribute("value")}"]`);if(i){const e=new MouseEvent("mouseup",{bubbles:!0,cancelable:!0,view:window});Object.defineProperty(e,"target",{value:i,writable:!1}),t.handleOptionClick&&t.handleOptionClick(e)}}static setupScrollListeners(e,t){e&&e.addEventListener("scroll",(e=>{t.handleScroll&&t.handleScroll(e)}))}static setupSearchListeners(e,t){if(!e)return;const i=e.querySelector("nile-input");i&&(i.addEventListener("nile-input",(e=>{t.handleSearchChange&&t.handleSearchChange(e)})),i.addEventListener("nile-focus",(e=>{t.handleSearchFocus&&t.handleSearchFocus()})),i.addEventListener("nile-blur",(e=>{t.handleSearchBlur&&t.handleSearchBlur()})))}static setupFooterListeners(e,t){if(!e)return;const i=e.querySelector(".select__footer");i&&(this.setupFooterClickHandlers(i),this.setupShowSelectedToggle(i,t),this.setupClearAllHandler(i,t))}static setupFooterClickHandlers(e){e.addEventListener("click",(e=>{e.stopPropagation(),e.preventDefault()}))}static setupShowSelectedToggle(e,t){const i=e.querySelector('span[style*="cursor: pointer"]');i&&i.addEventListener("click",(e=>{e.stopPropagation(),e.preventDefault(),t.toggleShowSelected&&t.toggleShowSelected(e)}))}static setupClearAllHandler(e,t){e.addEventListener("click",(e=>{e.target.classList.contains("select__clear")&&(e.stopPropagation(),e.preventDefault(),t.unSlectAll&&t.unSlectAll())}))}static setupSlotListeners(e,t){if(!e)return;const i=e.querySelector("slot");i&&i.addEventListener("slotchange",(()=>{t.updatePortalContent&&t.updatePortalContent()}))}},GM=class{constructor(e){this.portalContainer=null,this.originalListboxParent=null,this.measuredPopupHeight=null,this.cleanupAutoUpdate=null,this.currentPlacement="bottom",this.currentMiddlewareData=null,this.component=e}createPortalAppendContainer(){const e=document.createElement("div");return e.style.position="absolute",e.style.zIndex="9999",e.style.pointerEvents="none",e.className="nile-virtual-select-portal-append",e}positionPortalAppend(){this.portalContainer&&this.component.popup&&(this.measurePopupHeight(),this.computeFloatingUIPosition())}measurePopupHeight(){!this.measuredPopupHeight&&this.portalContainer&&(this.portalContainer.style.position="absolute",this.portalContainer.style.visibility="hidden",this.portalContainer.style.top="0px",this.portalContainer.style.left="0px",this.portalContainer.offsetHeight,this.measuredPopupHeight=this.portalContainer.offsetHeight,this.portalContainer.style.visibility="")}async computeFloatingUIPosition(){if(!this.portalContainer)return;const e=this.component.combobox||this.component,t=this.portalContainer;try{const{x:i,y:M,placement:n,middlewareData:o}=await this.calculateFloatingUIPosition(e,t);this.applyFloatingUIPosition(t,e,i,M,n,o)}catch(e){console.warn("Floating UI positioning failed, falling back to simple positioning:",e),this.fallbackPositioning()}}async calculateFloatingUIPosition(e,t){const i=PM.findBoundaryElements(e),M=PM.getOptimalPlacement(e),n=this.createFloatingUIMiddleware(i);return await Ji(e,t,{placement:M,strategy:"fixed",middleware:n,platform:this.createCustomPlatform()})}createFloatingUIMiddleware(e){return[Bi(4),Fi({apply:this.handleSizeMiddleware.bind(this),padding:10,boundary:e}),_i({fallbackPlacements:["bottom","top","bottom-start","top-start","bottom-end","top-end"],fallbackStrategy:"bestFit",padding:10,boundary:e}),Gi({padding:10,crossAxis:!0,boundary:e})]}handleSizeMiddleware({availableWidth:e,availableHeight:t,elements:i,rects:M}){const n=PM.calculateOptimalHeight(M.reference,window.innerHeight,this.currentPlacement);i.floating.style.maxWidth=`${e}px`,i.floating.style.maxHeight=`${n}px`,i.floating.style.setProperty("--auto-size-available-width",`${e}px`),i.floating.style.setProperty("--auto-size-available-height",`${n}px`)}createCustomPlatform(){return Wi}applyFloatingUIPosition(e,t,i,M,n,o){Object.assign(e.style,{left:`${i}px`,top:`${M}px`,position:"fixed",pointerEvents:"auto"}),this.currentPlacement=n,this.currentMiddlewareData=o,PM.applyCollisionData(e,o,n);const r=n.split("-")[0];e.className=`nile-virtual-select-portal-append select__listbox--${r}`;const s=t.getBoundingClientRect();e.style.width=`${s.width}px`}fallbackPositioning(){if(!this.portalContainer)return;const e=(this.component.combobox||this.component).getBoundingClientRect(),t=window.innerHeight;this.measuredPopupHeight;const i=t-e.bottom,M=e.top;let n,o,r;M>i?(r=Math.max(M-20,100),n=Math.max(e.top-r-4,10),o="top"):(r=Math.max(i-20,100),n=e.bottom+4,o="bottom"),this.portalContainer.style.left=`${e.left}px`,this.portalContainer.style.top=`${n}px`,this.portalContainer.style.width=`${e.width}px`,this.portalContainer.style.maxHeight=`${r}px`,this.portalContainer.style.pointerEvents="auto",this.portalContainer.className=`nile-virtual-select-portal-append select__listbox--${o}`,this.calculateAndSetAutoSizeProperties(e,n,o)}calculateAndSetAutoSizeProperties(e,t,i){if(!this.portalContainer)return;const M=window.innerHeight,n=window.innerWidth;let o;o="top"===i?e.top-10:M-e.bottom-10;const r=Math.min(e.width,n-e.left-10);this.portalContainer.style.setProperty("--auto-size-available-height",`${Math.max(o,100)}px`),this.portalContainer.style.setProperty("--auto-size-available-width",`${Math.max(r,200)}px`)}updatePortalAppendPosition(){this.component.portal&&this.portalContainer&&this.positionPortalAppend()}handleWindowResize(){this.component.portal&&this.portalContainer&&this.positionPortalAppend()}setupAutoUpdatePositioning(){this.portalContainer&&this.component&&(this.cleanupAutoUpdatePositioning(),this.cleanupAutoUpdate=Ri(this.component,this.portalContainer,(()=>{this.computeFloatingUIPosition()}),{ancestorScroll:!0,ancestorResize:!0,elementResize:!0,layoutShift:!0,animationFrame:!0}))}cleanupAutoUpdatePositioning(){this.cleanupAutoUpdate&&(this.cleanupAutoUpdate(),this.cleanupAutoUpdate=null)}extractStylesAsCSS(e){return"string"==typeof e?e:Array.isArray(e)?e.map((e=>this.extractStylesAsCSS(e))).join("\n"):e&&"object"==typeof e&&e.cssText?e.cssText:""}injectStylesToDocument(){if(!this.portalContainer)return;const e=`nile-virtual-select-styles-${Math.random().toString(36).substring(2,11)}`;if(document.getElementById(e))return;const t=this.component.constructor.styles;if(!t)return;const i=document.createElement("style");i.id=e,i.textContent=this.extractStylesAsCSS(t),document.head.appendChild(i),this.portalContainer.__injectedStyleId=e}adoptStylesToPortalAppend(){this.portalContainer&&this.injectStylesToDocument()}setupPortalAppend(){this.component.portal&&this.component.updateComplete.then((()=>{const e=this.component.shadowRoot?.querySelector("#listbox");e&&(this.originalListboxParent=e.parentElement,this.portalContainer=this.createPortalAppendContainer(),this.portalContainer.appendChild(e),document.body.appendChild(this.portalContainer),this.adoptStylesToPortalAppend(),e.style.display="",this.positionPortalAppend(),this.setupAutoUpdatePositioning(),window.addEventListener("resize",this.handleWindowResize.bind(this)))}))}cleanupPortalAppend(){if(this.cleanupAutoUpdatePositioning(),this.portalContainer&&this.portalContainer.parentNode){const e=this.portalContainer.querySelector("#listbox");e&&this.originalListboxParent&&(this.originalListboxParent.appendChild(e),e.style.display=this.component.portal?"none":"");const t=this.portalContainer.__injectedStyleId;if(t){const e=document.getElementById(t);e&&e.remove()}this.portalContainer.parentNode.removeChild(this.portalContainer)}window.removeEventListener("resize",this.handleWindowResize.bind(this)),this.portalContainer=null,this.originalListboxParent=null,this.measuredPopupHeight=null,this.currentPlacement="bottom",this.currentMiddlewareData=null}async resetScrollPosition(){await this.component.updateComplete,requestAnimationFrame((()=>{let e=null;if(e=this.component.portal&&this.portalContainer?this.portalContainer.querySelector("#listbox"):this.component.shadowRoot?.querySelector("#listbox"),!e||!e.isConnected)return;e.scrollTop=0;const t=e.querySelector(".virtualized");if(t&&t.isConnected){this.component.data?.length<=5?(t.style.overflowY="hidden",t.style.maxHeight="none",e.style.overflowY="hidden",e.style.maxHeight="fit-content"):(t.style.overflowY="auto",t.style.maxHeight="",e.style.overflowY="auto",e.style.maxHeight=""),t.scrollTop=0}const i=e.querySelector("lit-virtualizer");i&&i.isConnected&&(i.scrollTop=0)}))}get portalContainerElement(){return this.portalContainer}resetMeasuredHeight(){this.measuredPopupHeight=null}forceReposition(){this.portalContainer&&this.computeFloatingUIPosition()}getCurrentPlacement(){return this.currentPlacement}getCurrentMiddlewareData(){return this.currentMiddlewareData}isUsingFloatingUI(){return null!==this.cleanupAutoUpdate}handleViewportChange(){this.portalContainer&&(this.resetMeasuredHeight(),this.forceReposition())}isPositioningOptimal(){if(!this.portalContainer||!this.currentMiddlewareData)return!0;const e=(this.component.combobox||this.component).getBoundingClientRect(),t=window.innerHeight-e.bottom,i=e.top,M=this.currentPlacement.startsWith("top"),n=this.currentPlacement.startsWith("bottom");return!(M&&t>i)&&!(n&&i>t)}},_M=class{constructor(e,{target:t,config:i,callback:M,skipInitial:n}){this.t=new Set,this.o=!1,this.i=!1,this.h=e,null!==t&&this.t.add(t??e),this.l=i,this.o=n??this.o,this.callback=M,window.ResizeObserver?(this.u=new ResizeObserver((e=>{this.handleChanges(e),this.h.requestUpdate()})),e.addController(this)):console.warn("ResizeController error: browser does not support ResizeObserver.")}handleChanges(e){this.value=this.callback?.(e,this.u)}hostConnected(){for(const e of this.t)this.observe(e)}hostDisconnected(){this.disconnect()}async hostUpdated(){!this.o&&this.i&&this.handleChanges([]),this.i=!1}observe(e){this.t.add(e),this.u.observe(e,this.l),this.i=!0,this.h.requestUpdate()}unobserve(e){this.t.delete(e),this.u.unobserve(e)}disconnect(){this.u.disconnect()}},FM=class extends Re{constructor(){super(...arguments),this.formControlController=new ve(this,{assumeInteractionOn:["nile-blur","nile-input"]}),this.hasSlotController=new Ye(this,"help-text","label"),this.portalManager=new GM(this),this.hasFocus=!1,this.displayLabel="",this.selectedOptions=[],this.oldValue="",this.scrolling=!1,this.name="",this.data=[],this.originalOptionItems=[],this.value="",this.defaultValue="",this.size="medium",this.placeholder="Select...",this.autoResize=!1,this.searchValue="",this.searchEnabled=!1,this.enableVisibilityEffect=!1,this.internalSearchPlaceHolder="Search...",this.disableLocalSearch=!1,this.optionsLoading=!1,this.loading=!1,this.multiple=!1,this.helpText="",this.errorMessage="",this.warning=!1,this.error=!1,this.success=!1,this.disabled=!1,this.clearable=!1,this.open=!1,this.hoist=!1,this.filled=!1,this.pill=!1,this.label="",this.placement="bottom",this.form="",this.required=!1,this.showNoResults=!1,this.noResultsMessage="No results found",this.showSelected=!1,this.blockValueChange=!1,this.noWidthSync=!1,this.portal=!1,this.maxOptionsVisible=3,this.oldMaxOptionsVisible=1,this.enableTabClose=!1,this.showListbox=!1,this.wasShowSelectedCheckedOnClose=!1,this.handleDocumentMouseDown=e=>{if(!this.open)return;const t=e.composedPath(),i=t.includes(this),M=this.popup&&t.includes(this.popup),n=this.portal&&this.portalManager.portalContainerElement&&t.includes(this.portalManager.portalContainerElement);i||M||n||this.hide()},this.handleWindowError=e=>{(e.error?.message||e.message||"").includes("Cannot read properties of null (reading 'insertBefore')")&&e.preventDefault()},this.handleWindowResize=()=>{this.portalManager.updatePortalAppendPosition()},this.handleWindowScroll=()=>{this.portalManager.updatePortalAppendPosition()},this.resizeController=new _M(this,{callback:e=>{for(const t of e)t.target.classList.contains("select__tags")&&this.calculateTotalWidthOfTags()}})}get validity(){return this.valueInput?.validity}get validationMessage(){return this.valueInput?.validationMessage??""}connectedCallback(){super.connectedCallback(),this.initializeComponent(),this.setupEventListeners(),this.updateComplete.then((()=>{this.value&&this.data.length>0&&this.selectionChanged()}))}disconnectedCallback(){this.removeOpenListeners(),this.visibilityManager?.cleanup(),this.scrollTimeout&&(clearTimeout(this.scrollTimeout),this.scrollTimeout=void 0),this.portalManager.cleanupPortalAppend()}updated(e){if(e.has("value")&&this.selectionChanged(),e.has("autoResize")){const e=this.shadowRoot?.querySelector(".select__tags");this.autoResize&&e?this.resizeController.observe(e):e&&this.resizeController.unobserve(e)}}initializeComponent(){this.open=!1,this.emit("nile-init")}getDisplayText(e){return this.renderItemConfig?.getDisplayText?this.renderItemConfig.getDisplayText(e):e?.label||e?.name||e?.toString()||""}getItemValue(e){return this.renderItemConfig?.getValue?this.renderItemConfig.getValue(e):e?.value||e}getSearchText(e){return this.renderItemConfig?.getSearchText?this.renderItemConfig.getSearchText(e):this.getDisplayText(e)}setupEventListeners(){this.handleDocumentFocusIn=this.handleDocumentFocusIn.bind(this),this.handleDocumentKeyDown=this.handleDocumentKeyDown.bind(this),this.handleDocumentMouseDown=this.handleDocumentMouseDown.bind(this),this.handleWindowError=this.handleWindowError.bind(this),this.handleWindowResize=this.handleWindowResize.bind(this),this.handleWindowScroll=this.handleWindowScroll.bind(this)}addOpenListeners(){document.addEventListener("focusin",this.handleDocumentFocusIn),document.addEventListener("keydown",this.handleDocumentKeyDown),document.addEventListener("mousedown",this.handleDocumentMouseDown),window.addEventListener("error",this.handleWindowError),this.portal&&(window.addEventListener("resize",this.handleWindowResize),window.addEventListener("scroll",this.handleWindowScroll,!0))}removeOpenListeners(){document.removeEventListener("focusin",this.handleDocumentFocusIn),document.removeEventListener("keydown",this.handleDocumentKeyDown),document.removeEventListener("mousedown",this.handleDocumentMouseDown),window.removeEventListener("error",this.handleWindowError),window.removeEventListener("resize",this.handleWindowResize),window.removeEventListener("scroll",this.handleWindowScroll,!0)}handleFocus(){this.hasFocus=!0,this.emit("nile-focus")}handleBlur(){this.hasFocus=!1,this.emit("nile-blur")}firstUpdated(e){super.firstUpdated?.(e),this.visibilityManager=new tM({host:this,target:this.combobox,enableVisibilityEffect:this.enableVisibilityEffect,enableTabClose:this.enableTabClose,isOpen:()=>this.open,onAnchorOutOfView:()=>{this.hide(),this.emit("nile-visibility-change",{visible:!1,reason:"anchor-out-of-view",name:this.name})},onDocumentHidden:()=>{this.hide(),this.emit("nile-visibility-change",{visible:!1,reason:"document-hidden",name:this.name})},emit:(e,t)=>this.emit(`nile-${e}`,t)})}handleDocumentFocusIn(e){if(!this.open)return;const t=e.composedPath(),i=t.includes(this),M=this.popup&&t.includes(this.popup),n=this.portal&&this.portalManager.portalContainerElement&&t.includes(this.portalManager.portalContainerElement);i||M||n||this.hide()}handleDocumentKeyDown(e){this.shouldIgnoreKeyPress(e)||(this.isEscapeKey(e)&&this.handleEscapeKey(e),this.isEnterOrSpaceKey(e)&&this.handleEnterOrSpaceKey(e))}shouldIgnoreKeyPress(e){const t=e.target,i=null!==t.closest(".select__clear"),M=null!==t.closest("nile-icon-button");return i||M}isEscapeKey(e){return"Escape"===e.key&&this.open}handleEscapeKey(e){e.preventDefault(),e.stopPropagation(),this.hide(),this.displayInput.focus({preventScroll:!0})}isEnterOrSpaceKey(e){return"Enter"===e.key||" "===e.key}handleEnterOrSpaceKey(e){e.preventDefault(),e.stopImmediatePropagation(),this.open?this.multiple||(this.hide(),this.displayInput.focus({preventScroll:!0})):this.show()}handleFooterClick(e){e.stopPropagation(),e.preventDefault()}toggleShowSelected(e){if(e.stopPropagation(),e.preventDefault(),0!==this.selectedOptions?.length){if(this.showSelected=!this.showSelected,this.showSelected){this.searchValue="";const e=Array.isArray(this.value)?this.value:[this.value];this.data=this.originalOptionItems.filter((t=>{const i=this.getItemValue(t);return e.some((e=>String(e)===String(i)))}))}else this.data=[...this.originalOptionItems];this.portalManager.resetMeasuredHeight(),this.requestUpdate(),this.repaintOptionsContainer()}}unSelectAll(){this.showSelected=!1,this.value=this.multiple?[]:"",this.data=[...this.originalOptionItems],this.selectionChanged(),this.emit("nile-change",{value:this.value,name:this.name}),this.emit("nile-clear",{value:this.multiple?this.value:"",name:this.name}),this.resetScrollPosition()}handleLabelClick(){this.displayInput.focus(),this.hide()}handleComboboxMouseDown(e){this.shouldIgnoreComboboxClick(e)||(e.preventDefault(),this.displayInput.focus({preventScroll:!0}),this.open=!this.open)}shouldIgnoreComboboxClick(e){const t=e.composedPath().some((e=>e instanceof Element&&"nile-icon-button"===e.tagName.toLowerCase()));return this.disabled||t}handleComboboxKeyDown(e){this.isEnterOrSpaceKey(e)&&(e.preventDefault(),this.open=!this.open)}handleClearClick(e){e.stopPropagation(),this.clearSelection()}clearSelection(){this.value,this.value=this.multiple?[]:"",this.selectionChanged(),this.updateComplete.then((()=>{this.nileInput({value:this.value,name:this.name}),this.nileChange({value:this.value,name:this.name}),this.emit("nile-clear")}))}handleClearMouseDown(e){e.stopPropagation()}handleOptionClick(e){const t=e.target.closest("nile-option");if(this.shouldBlockValueChange(t))return;const i=this.value;this.oldValue=i,t&&!t.disabled&&this.handleOptionSelection(t)}shouldBlockValueChange(e){return!(!this.blockValueChange||!e)&&(this.emit("nile-block-change",{value:e?.value,name:this.name}),this.hide(),!0)}handleOptionSelection(e){const t=e.value;this.multiple?this.toggleOptionSelection(t):this.setSelectedOptions(t),this.updateComplete.then((()=>this.displayInput.focus({preventScroll:!0}))),this.value!==this.oldValue&&this.updateComplete.then((()=>{this.nileInput({value:this.value,name:this.name}),this.nileChange({value:this.value,name:this.name})})),this.multiple||(this.hide(),this.displayInput.focus({preventScroll:!0}))}setSelectedOptions(e){this.value=e,this.selectionChanged()}toggleOptionSelection(e){const t=Array.isArray(this.value)?this.value:[];t.includes(e)?this.value=t.filter((t=>t!==e)):this.value=[...t,e],this.selectionChanged()}handleTagRemove(e,t){e.stopPropagation(),this.disabled||(this.removeTagFromSelection(t),this.emitTagRemovalEvent(t))}removeTagFromSelection(e){let t=this.value;Array.isArray(t)||(t=t?[t]:[]);const i=t.filter((t=>t!==e.value));this.value=i,this.selectionChanged()}emitTagRemovalEvent(e){this.updateComplete.then((()=>{this.nileInput({value:this.value,name:this.name}),this.nileChange({value:this.value,name:this.name}),this.emit("nile-tag-remove",{value:this.value,name:this.name,removedtagvalue:e.value})}))}selectionChanged(){const e=this.originalOptionItems.length>0?this.originalOptionItems:this.data;if(this.selectedOptions=jM.createVirtualOptionsFromValues(this.value,e,this.getDisplayText.bind(this),this.renderItemConfig?.getValue),this.multiple)this.placeholder&&0===this.value.length?this.displayLabel="":this.displayLabel=this.selectedOptions.length+" selected";else{const e=Array.isArray(this.value)?this.value[0]:this.value,t=this.selectedOptions[0]?.getTextLabel();this.displayLabel=t||(e??"")}this.updateValidity(),0===this.selectedOptions.length&&(this.showSelected=!1,this.originalOptionItems?.length>0&&!this.searchValue&&(this.data=[...this.originalOptionItems]),this.repaintOptionsContainer()),this.calculateTotalWidthOfTags()}handleSearchFocus(){document.removeEventListener("keydown",this.handleDocumentKeyDown)}handleSearchBlur(){document.addEventListener("keydown",this.handleDocumentKeyDown)}handleSearchChange(e){this.searchValue=e.detail.value,this.portal&&this.portalManager.updatePortalAppendPosition(),this.emit("nile-search",{query:this.searchValue,name:this.name}),this.disableLocalSearch||(this.filterVirtualOptions(this.searchValue),this.repaintOptionsContainer(),this.portalManager.resetMeasuredHeight())}repaintOptionsContainer(){this.resetScrollPosition(),this.updateComplete.then((()=>{const e=this.shadowRoot?.querySelector(".virtualized");e&&(this.data.length<=5?e.classList.add("no-scroll"):e.classList.remove("no-scroll"))}))}handleScroll(e){if(this.showSelected)return;const t=e.target;this.emit("nile-scroll",{scrollTop:t.scrollTop,scrollLeft:t.scrollLeft,name:this.name}),this.scrolling||(this.scrolling=!0,this.emit("nile-scroll-start",{scrollTop:t.scrollTop,scrollLeft:t.scrollLeft,name:this.name})),clearTimeout(this.scrollTimeout),this.scrollTimeout=window.setTimeout((()=>{this.scrolling&&(this.scrolling=!1)}),300);Math.ceil(t.scrollTop)>=Math.floor(t.scrollHeight-t.offsetHeight)&&!this.searchValue&&this.emit("nile-scroll-end",{scrollTop:t.scrollTop,scrollLeft:t.scrollLeft,name:this.name,isAtBottom:!0})}filterVirtualOptions(e){const t=IM.filterVirtualOptions(e,this.originalOptionItems,this.data,this.getDisplayText.bind(this),this.renderItemConfig?.getSearchText);this.portal?(this.portalManager.updatePortalAppendPosition(),this.updateComplete.then((()=>{requestAnimationFrame((()=>{this.resetScrollPosition()}))}))):this.resetScrollPosition(),this.data=t.filteredItems,this.showNoResults=t.showNoResults,this.showSelected=!1,this.requestUpdate()}handleInvalid(e){this.formControlController.setValidity(!1),this.formControlController.emitInvalidEvent(e)}handleDisabledChange(){this.disabled&&(this.open=!1,this.handleOpenChange())}handleValueChange(){this.selectionChanged(),this.requestUpdate(),this.portal&&this.portalManager.portalContainerElement&&this.portalManager.updatePortalAppendPosition()}handleDataChange(){this.data.length>0&&this.open&&!this.showSelected&&!this.searchValue&&(this.originalOptionItems=[...this.data]),this.selectionChanged(),this.optionsLoading||this.loading||0!==this.data.length?this.data.length>0&&(this.showNoResults=!1):this.showNoResults=!0,this.requestUpdate(),this.portalManager.resetMeasuredHeight(),this.portal&&this.portalManager.portalContainerElement&&this.portalManager.updatePortalAppendPosition()}handleRenderItemConfigChange(){this.value&&this.data.length>0&&(this.selectionChanged(),this.requestUpdate())}handleOptionsLoadingChange(){this.optionsLoading||0!==this.data.length||(this.showNoResults=!0),this.requestUpdate(),this.portal&&this.portalManager.portalContainerElement&&this.portalManager.updatePortalAppendPosition()}handlePortalAppendChange(){this.open&&(this.portal?this.portalManager.setupPortalAppend():this.portalManager.cleanupPortalAppend())}async handleOpenChange(){this.open&&!this.disabled?(this.visibilityManager?.setup(),this.showListbox=!0,await this.updateComplete,await this.handleOpen(),this.portal&&this.portalManager.setupPortalAppend()):(this.visibilityManager?.cleanup(),await this.handleClose(),this.showListbox=!1,this.portal&&this.portalManager.cleanupPortalAppend())}async handleOpen(){this.emit("nile-show",{value:this.value,name:this.name}),this.addOpenListeners(),this.showNoResults=!this.data?.length,await jt(this),this.popup?.popup&&(this.popup.popup.style.visibility="hidden"),this.popup.active=!0,await new Promise((e=>requestAnimationFrame(e))),await new Promise((e=>requestAnimationFrame(e))),this.popup?.popup&&(this.popup.popup.style.visibility="");const{keyframes:e,options:t}=yt(this,"select.show",{dir:"ltr"});await ut(this.popup.popup,e,t),this.wasShowSelectedCheckedOnClose&&(this.showSelected=!1,this.data=[...this.originalOptionItems],this.wasShowSelectedCheckedOnClose=!1),this.filterVirtualOptions(""),this.resetScrollPosition(),this.emit("nile-after-show",{value:this.value,name:this.name})}async handleClose(){this.emit("nile-hide",{value:this.value,name:this.name}),this.removeOpenListeners(),this.wasShowSelectedCheckedOnClose=this.showSelected,await jt(this);const{keyframes:e,options:t}=yt(this,"select.hide",{dir:"ltr"});await ut(this.popup.popup,e,t),this.popup.active=!1,this.popup?.popup&&(this.popup.popup.style.visibility=""),this.searchValue="",this.portalManager.resetMeasuredHeight(),this.emit("nile-after-hide",{value:this.value,name:this.name})}async show(){if(!this.open&&!this.disabled)return this.open=!0,St(this,"nile-after-show");this.open=!1}async hide(){if(this.open&&!this.disabled)return this.open=!1,St(this,"nile-after-hide");this.open=!1}checkValidity(){return this.valueInput.checkValidity()}getForm(){return this.formControlController.getForm()}reportValidity(){return this.valueInput.reportValidity()}setCustomValidity(e){this.valueInput.setCustomValidity(e),this.formControlController.updateValidity()}focus(e){this.displayInput.focus(e)}blur(){this.displayInput.blur()}onInputChange(e){e.stopPropagation()}render(){const e=this.hasSlotController.test("label");this.hasSlotController.test("help-text");const t=this.hasSlotController.test("label-suffix"),i=this.hasSlotController.test("custom-select"),M=!!this.label||!!e,n=this.clearable&&!this.disabled&&this.value.length>0,o=!!this.placeholder&&0===this.value.length,r=!!this.helpText,s=!!this.errorMessage;return R`
|
|
4835
|
+
`}static shouldUseVirtualizer(e){return e.length>=5}}let PM=class{static calculateAvailableSpace(e){const t=e.getBoundingClientRect(),i=window.innerHeight,M=i-t.bottom;return{spaceAbove:t.top,spaceBelow:M,viewportHeight:i}}static getOptimalPlacement(e){const{spaceAbove:t,spaceBelow:i}=this.calculateAvailableSpace(e);return i<200&&t>i?"top":"bottom"}static findBoundaryElements(e){const t=[];let i=e.parentElement;for(;i&&i!==document.body;){const e=window.getComputedStyle(i),M=e.overflow,n=e.overflowY,o=e.overflowX;"auto"!==M&&"scroll"!==M&&"auto"!==n&&"scroll"!==n&&"auto"!==o&&"scroll"!==o||t.push(i),(i.hasAttribute("data-floating-boundary")||i.classList.contains("floating-boundary")||i.classList.contains("scroll-container"))&&t.push(i),i=i.parentElement}return t.length>0?t:void 0}static calculateOptimalHeight(e,t,i){const M=t-(e.y+e.height),n=e.y;return n>M?Math.max(n-20,100):M>n?Math.max(M-20,100):Math.max(Math.min(n,M)-20,100)}static extractStylesAsCSS(e){return"string"==typeof e?e:Array.isArray(e)?e.map((e=>this.extractStylesAsCSS(e))).join("\n"):e&&"object"==typeof e&&e.cssText?e.cssText:""}static generateStyleId(){return`nile-select-styles-${Math.random().toString(36).substring(2,11)}`}static isPositioningOptimal(e,t){const{spaceAbove:i,spaceBelow:M}=this.calculateAvailableSpace(t),n=e.startsWith("top"),o=e.startsWith("bottom");return!(n&&M>i)&&!(o&&i>M)}static applyCollisionData(e,t,i){if(t.flip){const{overflows:M}=t.flip;if(e.setAttribute("data-placement",i),M&&M.length>0){const t=M.map((e=>e.placement)).join(",");e.setAttribute("data-overflow",t)}else e.removeAttribute("data-overflow")}if(t.shift){const{x:i,y:M}=t.shift;void 0===i||void 0===M||0===i&&0===M?e.removeAttribute("data-shift"):e.setAttribute("data-shift",`${i},${M}`)}if(t.size){const{availableWidth:i,availableHeight:M}=t.size;void 0!==i&&e.setAttribute("data-available-width",i.toString()),void 0!==M&&e.setAttribute("data-available-height",M.toString())}}static createFloatingUIMiddleware(e,t){return[]}},RM=class{static createBaseListbox(e){const t=document.createElement("div");return t.className="select__listbox "+(e.searchEnabled?"select__search-enabled ":""),t.setAttribute("tabindex","-1"),t}static addSearchSection(e,t){if(!t.searchEnabled)return;const i=document.createElement("div");i.className="select__search",i.innerHTML=`\n <nile-input size="small" clearable value="${t.searchValue}" placeholder="${t.internalSearchPlaceHolder}">\n <nile-icon name="var(--nile-icon-search, var(--ng-icon-search-lg))" method="var(--nile-svg-method-fill, var(--ng-svg-method-stroke))" slot="suffix"></nile-icon>\n </nile-input>\n `,e.appendChild(i)}static addLoadingSection(e,t){if(!t.optionsLoading)return;const i=document.createElement("span");i.className="select__loader",i.innerHTML='\n <nile-icon class="select__loader--icon" name="var(--nile-icon-button-loading-blue, var(--ng-icon-button-loading-blue))" method="var(--nile-svg-method-fill, var(--ng-svg-method-stroke))"></nile-icon>\n ',e.appendChild(i)}static addOptionsSection(e,t){const i=document.createElement("div");i.className="select__options "+(t.searchEnabled?"select__options__search-enabled":""),this.addNoResultsMessage(i,t),this.addClonedOptions(i,t),e.appendChild(i)}static addNoResultsMessage(e,t){if(!t.showNoResults)return;const i=document.createElement("div");i.className="select__no-results",i.textContent=t.noResultsMessage,e.appendChild(i)}static addClonedOptions(e,t){Array.from(t.querySelectorAll("nile-option")).forEach((t=>{const i=this.cloneOption(t);e.appendChild(i)}))}static cloneOption(e){const t=e.cloneNode(!0);return Array.from(e.attributes).forEach((e=>{t.setAttribute(e.name,e.value)})),this.copyOptionProperties(e,t),t}static copyOptionProperties(e,t){["selected","disabled","current","hidden"].forEach((i=>{void 0!==e[i]&&(t[i]=e[i])}))}static addFooterSection(e,t){if(!t.multiple)return;const i=this.createFooter(t);e.appendChild(i)}static createFooter(e){const t=document.createElement("div");return t.setAttribute("part","footer"),t.className="select__footer",this.addShowSelectedToggle(t,e),this.addClearAllButton(t,e),t}static addShowSelectedToggle(e,t){const i=document.createElement("span");i.style.cursor="pointer";const M=document.createElement("nile-checkbox");M.disabled=0===t.selectedOptions.length,M.checked=t.showSelected,M.innerHTML=" Show Selected",i.appendChild(M),e.appendChild(i)}static addClearAllButton(e,t){if(0===t.selectedOptions.length)return;const i=document.createElement("span");i.className="select__clear",i.textContent="Clear All",i.style.cursor="pointer",e.appendChild(i)}static updateClonedOptions(e,t){const i=e.querySelector(".select__options");if(!i)return;const M=Array.from(t.querySelectorAll("nile-option")),n=Array.from(i.querySelectorAll("nile-option"));M.forEach(((e,t)=>{const i=n[t];i&&this.updateClonedOption(e,i)}))}static updateClonedOption(e,t){t.selected=e.selected,t.disabled=e.disabled,t.current=e.current,t.hidden=e.hidden,this.updateClonedOptionAttributes(e,t)}static updateClonedOptionAttributes(e,t){[{prop:"selected",attr:"selected"},{prop:"disabled",attr:"disabled"},{prop:"current",attr:"current"},{prop:"hidden",attr:"hidden"}].forEach((({prop:i,attr:M})=>{e[i]?t.setAttribute(M,""):t.removeAttribute(M)}))}static createPortalListbox(e){const t=this.createBaseListbox(e);return this.addSearchSection(t,e),this.addLoadingSection(t,e),this.addOptionsSection(t,e),this.addFooterSection(t,e),t}},BM=class{static setupPortalEventListeners(e,t){e&&(this.setupOptionClickListeners(e,t),this.setupScrollListeners(e,t),this.setupSearchListeners(e,t),this.setupFooterListeners(e,t),this.setupSlotListeners(e,t))}static setupOptionClickListeners(e,t){e&&e.addEventListener("mouseup",(e=>{const i=e.target.closest("nile-option");i&&this.handleOptionClick(i,t)}))}static handleOptionClick(e,t){const i=t.querySelector(`nile-option[value="${e.getAttribute("value")}"]`);if(i){const e=new MouseEvent("mouseup",{bubbles:!0,cancelable:!0,view:window});Object.defineProperty(e,"target",{value:i,writable:!1}),t.handleOptionClick&&t.handleOptionClick(e)}}static setupScrollListeners(e,t){e&&e.addEventListener("scroll",(e=>{t.handleScroll&&t.handleScroll(e)}))}static setupSearchListeners(e,t){if(!e)return;const i=e.querySelector("nile-input");i&&(i.addEventListener("nile-input",(e=>{t.handleSearchChange&&t.handleSearchChange(e)})),i.addEventListener("nile-focus",(e=>{t.handleSearchFocus&&t.handleSearchFocus()})),i.addEventListener("nile-blur",(e=>{t.handleSearchBlur&&t.handleSearchBlur()})))}static setupFooterListeners(e,t){if(!e)return;const i=e.querySelector(".select__footer");i&&(this.setupFooterClickHandlers(i),this.setupShowSelectedToggle(i,t),this.setupClearAllHandler(i,t))}static setupFooterClickHandlers(e){e.addEventListener("click",(e=>{e.stopPropagation(),e.preventDefault()}))}static setupShowSelectedToggle(e,t){const i=e.querySelector('span[style*="cursor: pointer"]');i&&i.addEventListener("click",(e=>{e.stopPropagation(),e.preventDefault(),t.toggleShowSelected&&t.toggleShowSelected(e)}))}static setupClearAllHandler(e,t){e.addEventListener("click",(e=>{e.target.classList.contains("select__clear")&&(e.stopPropagation(),e.preventDefault(),t.unSlectAll&&t.unSlectAll())}))}static setupSlotListeners(e,t){if(!e)return;const i=e.querySelector("slot");i&&i.addEventListener("slotchange",(()=>{t.updatePortalContent&&t.updatePortalContent()}))}},GM=class{constructor(e){this.portalContainer=null,this.originalListboxParent=null,this.measuredPopupHeight=null,this.cleanupAutoUpdate=null,this.currentPlacement="bottom",this.currentMiddlewareData=null,this.component=e}createPortalAppendContainer(){const e=document.createElement("div");return e.style.position="absolute",e.style.zIndex="9999",e.style.pointerEvents="none",e.className="nile-virtual-select-portal-append",e}positionPortalAppend(){this.portalContainer&&this.component.popup&&(this.measurePopupHeight(),this.computeFloatingUIPosition())}measurePopupHeight(){!this.measuredPopupHeight&&this.portalContainer&&(this.portalContainer.style.position="absolute",this.portalContainer.style.visibility="hidden",this.portalContainer.style.top="0px",this.portalContainer.style.left="0px",this.portalContainer.offsetHeight,this.measuredPopupHeight=this.portalContainer.offsetHeight,this.portalContainer.style.visibility="")}async computeFloatingUIPosition(){if(!this.portalContainer)return;const e=this.component.combobox||this.component,t=this.portalContainer;try{const{x:i,y:M,placement:n,middlewareData:o}=await this.calculateFloatingUIPosition(e,t);this.applyFloatingUIPosition(t,e,i,M,n,o)}catch(e){console.warn("Floating UI positioning failed, falling back to simple positioning:",e),this.fallbackPositioning()}}async calculateFloatingUIPosition(e,t){const i=PM.findBoundaryElements(e),M=PM.getOptimalPlacement(e),n=this.createFloatingUIMiddleware(i);return await Ji(e,t,{placement:M,strategy:"fixed",middleware:n,platform:this.createCustomPlatform()})}createFloatingUIMiddleware(e){return[Bi(4),Fi({apply:this.handleSizeMiddleware.bind(this),padding:10,boundary:e}),_i({fallbackPlacements:["bottom","top","bottom-start","top-start","bottom-end","top-end"],fallbackStrategy:"bestFit",padding:10,boundary:e}),Gi({padding:10,crossAxis:!0,boundary:e})]}handleSizeMiddleware({availableWidth:e,availableHeight:t,elements:i,rects:M}){const n=PM.calculateOptimalHeight(M.reference,window.innerHeight,this.currentPlacement);i.floating.style.maxWidth=`${e}px`,i.floating.style.maxHeight=`${n}px`,i.floating.style.setProperty("--auto-size-available-width",`${e}px`),i.floating.style.setProperty("--auto-size-available-height",`${n}px`)}createCustomPlatform(){return Wi}applyFloatingUIPosition(e,t,i,M,n,o){Object.assign(e.style,{left:`${i}px`,top:`${M}px`,position:"fixed",pointerEvents:"auto"}),this.currentPlacement=n,this.currentMiddlewareData=o,PM.applyCollisionData(e,o,n);const r=n.split("-")[0];e.className=`nile-virtual-select-portal-append select__listbox--${r}`;const s=t.getBoundingClientRect();e.style.width=`${s.width}px`}fallbackPositioning(){if(!this.portalContainer)return;const e=(this.component.combobox||this.component).getBoundingClientRect(),t=window.innerHeight;this.measuredPopupHeight;const i=t-e.bottom,M=e.top;let n,o,r;M>i?(r=Math.max(M-20,100),n=Math.max(e.top-r-4,10),o="top"):(r=Math.max(i-20,100),n=e.bottom+4,o="bottom"),this.portalContainer.style.left=`${e.left}px`,this.portalContainer.style.top=`${n}px`,this.portalContainer.style.width=`${e.width}px`,this.portalContainer.style.maxHeight=`${r}px`,this.portalContainer.style.pointerEvents="auto",this.portalContainer.className=`nile-virtual-select-portal-append select__listbox--${o}`,this.calculateAndSetAutoSizeProperties(e,n,o)}calculateAndSetAutoSizeProperties(e,t,i){if(!this.portalContainer)return;const M=window.innerHeight,n=window.innerWidth;let o;o="top"===i?e.top-10:M-e.bottom-10;const r=Math.min(e.width,n-e.left-10);this.portalContainer.style.setProperty("--auto-size-available-height",`${Math.max(o,100)}px`),this.portalContainer.style.setProperty("--auto-size-available-width",`${Math.max(r,200)}px`)}updatePortalAppendPosition(){this.component.portal&&this.portalContainer&&this.positionPortalAppend()}handleWindowResize(){this.component.portal&&this.portalContainer&&this.positionPortalAppend()}setupAutoUpdatePositioning(){this.portalContainer&&this.component&&(this.cleanupAutoUpdatePositioning(),this.cleanupAutoUpdate=Ri(this.component,this.portalContainer,(()=>{this.computeFloatingUIPosition()}),{ancestorScroll:!0,ancestorResize:!0,elementResize:!0,layoutShift:!0,animationFrame:!0}))}cleanupAutoUpdatePositioning(){this.cleanupAutoUpdate&&(this.cleanupAutoUpdate(),this.cleanupAutoUpdate=null)}extractStylesAsCSS(e){return"string"==typeof e?e:Array.isArray(e)?e.map((e=>this.extractStylesAsCSS(e))).join("\n"):e&&"object"==typeof e&&e.cssText?e.cssText:""}injectStylesToDocument(){if(!this.portalContainer)return;const e=`nile-virtual-select-styles-${Math.random().toString(36).substring(2,11)}`;if(document.getElementById(e))return;const t=this.component.constructor.styles;if(!t)return;const i=document.createElement("style");i.id=e,i.textContent=this.extractStylesAsCSS(t),document.head.appendChild(i),this.portalContainer.__injectedStyleId=e}adoptStylesToPortalAppend(){this.portalContainer&&this.injectStylesToDocument()}setupPortalAppend(){this.component.portal&&this.component.updateComplete.then((()=>{const e=this.component.shadowRoot?.querySelector("#listbox");e&&(this.originalListboxParent=e.parentElement,this.portalContainer=this.createPortalAppendContainer(),this.portalContainer.appendChild(e),document.body.appendChild(this.portalContainer),this.adoptStylesToPortalAppend(),e.style.display="",this.positionPortalAppend(),this.setupAutoUpdatePositioning(),window.addEventListener("resize",this.handleWindowResize.bind(this)))}))}cleanupPortalAppend(){if(this.cleanupAutoUpdatePositioning(),this.portalContainer&&this.portalContainer.parentNode){const e=this.portalContainer.querySelector("#listbox");e&&this.originalListboxParent&&(this.originalListboxParent.appendChild(e),e.style.display=this.component.portal?"none":"");const t=this.portalContainer.__injectedStyleId;if(t){const e=document.getElementById(t);e&&e.remove()}this.portalContainer.parentNode.removeChild(this.portalContainer)}window.removeEventListener("resize",this.handleWindowResize.bind(this)),this.portalContainer=null,this.originalListboxParent=null,this.measuredPopupHeight=null,this.currentPlacement="bottom",this.currentMiddlewareData=null}async resetScrollPosition(){await this.component.updateComplete,requestAnimationFrame((()=>{let e=null;if(e=this.component.portal&&this.portalContainer?this.portalContainer.querySelector("#listbox"):this.component.shadowRoot?.querySelector("#listbox"),!e||!e.isConnected)return;e.scrollTop=0;const t=e.querySelector(".virtualized");if(t&&t.isConnected){this.component.data?.length<=5?(t.style.overflowY="hidden",t.style.maxHeight="none",e.style.overflowY="hidden",e.style.maxHeight="fit-content"):(t.style.overflowY="auto",t.style.maxHeight="",e.style.overflowY="auto",e.style.maxHeight=""),t.scrollTop=0}const i=e.querySelector("lit-virtualizer");i&&i.isConnected&&(i.scrollTop=0)}))}get portalContainerElement(){return this.portalContainer}resetMeasuredHeight(){this.measuredPopupHeight=null}forceReposition(){this.portalContainer&&this.computeFloatingUIPosition()}getCurrentPlacement(){return this.currentPlacement}getCurrentMiddlewareData(){return this.currentMiddlewareData}isUsingFloatingUI(){return null!==this.cleanupAutoUpdate}handleViewportChange(){this.portalContainer&&(this.resetMeasuredHeight(),this.forceReposition())}isPositioningOptimal(){if(!this.portalContainer||!this.currentMiddlewareData)return!0;const e=(this.component.combobox||this.component).getBoundingClientRect(),t=window.innerHeight-e.bottom,i=e.top,M=this.currentPlacement.startsWith("top"),n=this.currentPlacement.startsWith("bottom");return!(M&&t>i)&&!(n&&i>t)}},_M=class{constructor(e,{target:t,config:i,callback:M,skipInitial:n}){this.t=new Set,this.o=!1,this.i=!1,this.h=e,null!==t&&this.t.add(t??e),this.l=i,this.o=n??this.o,this.callback=M,window.ResizeObserver?(this.u=new ResizeObserver((e=>{this.handleChanges(e),this.h.requestUpdate()})),e.addController(this)):console.warn("ResizeController error: browser does not support ResizeObserver.")}handleChanges(e){this.value=this.callback?.(e,this.u)}hostConnected(){for(const e of this.t)this.observe(e)}hostDisconnected(){this.disconnect()}async hostUpdated(){!this.o&&this.i&&this.handleChanges([]),this.i=!1}observe(e){this.t.add(e),this.u.observe(e,this.l),this.i=!0,this.h.requestUpdate()}unobserve(e){this.t.delete(e),this.u.unobserve(e)}disconnect(){this.u.disconnect()}},FM=class extends Re{constructor(){super(...arguments),this.formControlController=new ve(this,{assumeInteractionOn:["nile-blur","nile-input"]}),this.hasSlotController=new Ye(this,"help-text","label"),this.portalManager=new GM(this),this.hasFocus=!1,this.displayLabel="",this.selectedOptions=[],this.oldValue="",this.scrolling=!1,this.name="",this.data=[],this.originalOptionItems=[],this.value="",this.defaultValue="",this.size="medium",this.placeholder="Select...",this.autoResize=!1,this.searchValue="",this.searchEnabled=!1,this.enableVisibilityEffect=!1,this.internalSearchPlaceHolder="Search...",this.disableLocalSearch=!1,this.optionsLoading=!1,this.loading=!1,this.multiple=!1,this.helpText="",this.errorMessage="",this.warning=!1,this.error=!1,this.success=!1,this.disabled=!1,this.clearable=!1,this.open=!1,this.hoist=!1,this.filled=!1,this.pill=!1,this.label="",this.placement="bottom",this.form="",this.required=!1,this.showNoResults=!1,this.noResultsMessage="No results found",this.showSelected=!1,this.blockValueChange=!1,this.noWidthSync=!1,this.portal=!1,this.maxOptionsVisible=3,this.oldMaxOptionsVisible=1,this.enableTabClose=!1,this.showListbox=!1,this.wasShowSelectedCheckedOnClose=!1,this.handleDocumentMouseDown=e=>{if(!this.open)return;const t=e.composedPath(),i=t.includes(this),M=this.popup&&t.includes(this.popup),n=this.portal&&this.portalManager.portalContainerElement&&t.includes(this.portalManager.portalContainerElement);i||M||n||this.hide()},this.handleWindowError=e=>{(e.error?.message||e.message||"").includes("Cannot read properties of null (reading 'insertBefore')")&&e.preventDefault()},this.handleWindowResize=()=>{this.portalManager.updatePortalAppendPosition()},this.handleWindowScroll=()=>{this.portalManager.updatePortalAppendPosition()},this.resizeController=new _M(this,{callback:e=>{for(const t of e)t.target.classList.contains("select__tags")&&this.calculateTotalWidthOfTags()}})}get validity(){return this.valueInput?.validity}get validationMessage(){return this.valueInput?.validationMessage??""}connectedCallback(){super.connectedCallback(),this.initializeComponent(),this.setupEventListeners(),this.updateComplete.then((()=>{this.value&&this.data.length>0&&this.selectionChanged()}))}disconnectedCallback(){this.removeOpenListeners(),this.visibilityManager?.cleanup(),this.scrollTimeout&&(clearTimeout(this.scrollTimeout),this.scrollTimeout=void 0),this.portalManager.cleanupPortalAppend()}updated(e){if(e.has("value")&&this.selectionChanged(),e.has("autoResize")){const e=this.shadowRoot?.querySelector(".select__tags");this.autoResize&&e?this.resizeController.observe(e):e&&this.resizeController.unobserve(e)}}initializeComponent(){this.open=!1,this.emit("nile-init")}getDisplayText(e){return this.renderItemConfig?.getDisplayText?this.renderItemConfig.getDisplayText(e):e?.label||e?.name||e?.toString()||""}getItemValue(e){return this.renderItemConfig?.getValue?this.renderItemConfig.getValue(e):e?.value||e}getSearchText(e){return this.renderItemConfig?.getSearchText?this.renderItemConfig.getSearchText(e):this.getDisplayText(e)}setupEventListeners(){this.handleDocumentFocusIn=this.handleDocumentFocusIn.bind(this),this.handleDocumentKeyDown=this.handleDocumentKeyDown.bind(this),this.handleDocumentMouseDown=this.handleDocumentMouseDown.bind(this),this.handleWindowError=this.handleWindowError.bind(this),this.handleWindowResize=this.handleWindowResize.bind(this),this.handleWindowScroll=this.handleWindowScroll.bind(this)}addOpenListeners(){document.addEventListener("focusin",this.handleDocumentFocusIn),document.addEventListener("keydown",this.handleDocumentKeyDown),document.addEventListener("mousedown",this.handleDocumentMouseDown),window.addEventListener("error",this.handleWindowError),this.portal&&(window.addEventListener("resize",this.handleWindowResize),window.addEventListener("scroll",this.handleWindowScroll,!0))}removeOpenListeners(){document.removeEventListener("focusin",this.handleDocumentFocusIn),document.removeEventListener("keydown",this.handleDocumentKeyDown),document.removeEventListener("mousedown",this.handleDocumentMouseDown),window.removeEventListener("error",this.handleWindowError),window.removeEventListener("resize",this.handleWindowResize),window.removeEventListener("scroll",this.handleWindowScroll,!0)}handleFocus(){this.hasFocus=!0,this.emit("nile-focus")}handleBlur(){this.hasFocus=!1,this.emit("nile-blur")}firstUpdated(e){this.visibilityManager=new tM({host:this,target:this.combobox,enableVisibilityEffect:this.enableVisibilityEffect,enableTabClose:this.enableTabClose,isOpen:()=>this.open,onAnchorOutOfView:()=>{this.hide(),this.emit("nile-visibility-change",{visible:!1,reason:"anchor-out-of-view",name:this.name})},onDocumentHidden:()=>{this.hide(),this.emit("nile-visibility-change",{visible:!1,reason:"document-hidden",name:this.name})},emit:(e,t)=>this.emit(`nile-${e}`,t)})}handleDocumentFocusIn(e){if(!this.open)return;const t=e.composedPath(),i=t.includes(this),M=this.popup&&t.includes(this.popup),n=this.portal&&this.portalManager.portalContainerElement&&t.includes(this.portalManager.portalContainerElement);i||M||n||this.hide()}handleDocumentKeyDown(e){this.shouldIgnoreKeyPress(e)||(this.isEscapeKey(e)&&this.handleEscapeKey(e),this.isEnterOrSpaceKey(e)&&this.handleEnterOrSpaceKey(e))}shouldIgnoreKeyPress(e){const t=e.target,i=null!==t.closest(".select__clear"),M=null!==t.closest("nile-icon-button");return i||M}isEscapeKey(e){return"Escape"===e.key&&this.open}handleEscapeKey(e){e.preventDefault(),e.stopPropagation(),this.hide(),this.displayInput.focus({preventScroll:!0})}isEnterOrSpaceKey(e){return"Enter"===e.key||" "===e.key}handleEnterOrSpaceKey(e){e.preventDefault(),e.stopImmediatePropagation(),this.open?this.multiple||(this.hide(),this.displayInput.focus({preventScroll:!0})):this.show()}handleFooterClick(e){e.stopPropagation(),e.preventDefault()}toggleShowSelected(e){if(e.stopPropagation(),e.preventDefault(),0!==this.selectedOptions?.length){if(this.showSelected=!this.showSelected,this.showSelected){this.searchValue="";const e=Array.isArray(this.value)?this.value:[this.value];this.data=this.originalOptionItems.filter((t=>{const i=this.getItemValue(t);return e.some((e=>String(e)===String(i)))}))}else this.data=[...this.originalOptionItems];this.portalManager.resetMeasuredHeight(),this.requestUpdate(),this.repaintOptionsContainer()}}unSelectAll(){this.showSelected=!1,this.value=this.multiple?[]:"",this.data=[...this.originalOptionItems],this.selectionChanged(),this.emit("nile-change",{value:this.value,name:this.name}),this.emit("nile-clear",{value:this.multiple?this.value:"",name:this.name}),this.resetScrollPosition()}handleLabelClick(){this.displayInput.focus(),this.hide()}handleComboboxMouseDown(e){this.shouldIgnoreComboboxClick(e)||(e.preventDefault(),this.displayInput.focus({preventScroll:!0}),this.open=!this.open)}shouldIgnoreComboboxClick(e){const t=e.composedPath().some((e=>e instanceof Element&&"nile-icon-button"===e.tagName.toLowerCase()));return this.disabled||t}handleComboboxKeyDown(e){this.isEnterOrSpaceKey(e)&&(e.preventDefault(),this.open=!this.open)}handleClearClick(e){e.stopPropagation(),this.clearSelection()}clearSelection(){this.value,this.value=this.multiple?[]:"",this.selectionChanged(),this.updateComplete.then((()=>{this.nileInput({value:this.value,name:this.name}),this.nileChange({value:this.value,name:this.name}),this.emit("nile-clear")}))}handleClearMouseDown(e){e.stopPropagation()}handleOptionClick(e){const t=e.target.closest("nile-option");if(this.shouldBlockValueChange(t))return;const i=this.value;this.oldValue=i,t&&!t.disabled&&this.handleOptionSelection(t)}shouldBlockValueChange(e){return!(!this.blockValueChange||!e)&&(this.emit("nile-block-change",{value:e?.value,name:this.name}),this.hide(),!0)}handleOptionSelection(e){const t=e.value;this.multiple?this.toggleOptionSelection(t):this.setSelectedOptions(t),this.updateComplete.then((()=>this.displayInput.focus({preventScroll:!0}))),this.value!==this.oldValue&&this.updateComplete.then((()=>{this.nileInput({value:this.value,name:this.name}),this.nileChange({value:this.value,name:this.name})})),this.multiple||(this.hide(),this.displayInput.focus({preventScroll:!0}))}setSelectedOptions(e){this.value=e,this.selectionChanged()}toggleOptionSelection(e){const t=Array.isArray(this.value)?this.value:[];t.includes(e)?this.value=t.filter((t=>t!==e)):this.value=[...t,e],this.selectionChanged()}handleTagRemove(e,t){e.stopPropagation(),this.disabled||(this.removeTagFromSelection(t),this.emitTagRemovalEvent(t))}removeTagFromSelection(e){let t=this.value;Array.isArray(t)||(t=t?[t]:[]);const i=t.filter((t=>t!==e.value));this.value=i,this.selectionChanged()}emitTagRemovalEvent(e){this.updateComplete.then((()=>{this.nileInput({value:this.value,name:this.name}),this.nileChange({value:this.value,name:this.name}),this.emit("nile-tag-remove",{value:this.value,name:this.name,removedtagvalue:e.value})}))}selectionChanged(){const e=this.originalOptionItems.length>0?this.originalOptionItems:this.data;if(this.selectedOptions=jM.createVirtualOptionsFromValues(this.value,e,this.getDisplayText.bind(this),this.renderItemConfig?.getValue),this.multiple)this.placeholder&&0===this.value.length?this.displayLabel="":this.displayLabel=this.selectedOptions.length+" selected";else{const e=Array.isArray(this.value)?this.value[0]:this.value,t=this.selectedOptions[0]?.getTextLabel();this.displayLabel=t||(e??"")}this.updateValidity(),0===this.selectedOptions.length&&(this.showSelected=!1,this.originalOptionItems?.length>0&&!this.searchValue&&(this.data=[...this.originalOptionItems]),this.repaintOptionsContainer()),this.calculateTotalWidthOfTags()}handleSearchFocus(){document.removeEventListener("keydown",this.handleDocumentKeyDown)}handleSearchBlur(){document.addEventListener("keydown",this.handleDocumentKeyDown)}handleSearchChange(e){this.searchValue=e.detail.value,this.portal&&this.portalManager.updatePortalAppendPosition(),this.emit("nile-search",{query:this.searchValue,name:this.name}),this.disableLocalSearch||(this.filterVirtualOptions(this.searchValue),this.repaintOptionsContainer(),this.portalManager.resetMeasuredHeight())}repaintOptionsContainer(){this.resetScrollPosition(),this.updateComplete.then((()=>{const e=this.shadowRoot?.querySelector(".virtualized");e&&(this.data.length<=5?e.classList.add("no-scroll"):e.classList.remove("no-scroll"))}))}handleScroll(e){if(this.showSelected)return;const t=e.target;this.emit("nile-scroll",{scrollTop:t.scrollTop,scrollLeft:t.scrollLeft,name:this.name}),this.scrolling||(this.scrolling=!0,this.emit("nile-scroll-start",{scrollTop:t.scrollTop,scrollLeft:t.scrollLeft,name:this.name})),clearTimeout(this.scrollTimeout),this.scrollTimeout=window.setTimeout((()=>{this.scrolling&&(this.scrolling=!1)}),300);Math.ceil(t.scrollTop)>=Math.floor(t.scrollHeight-t.offsetHeight)&&!this.searchValue&&this.emit("nile-scroll-end",{scrollTop:t.scrollTop,scrollLeft:t.scrollLeft,name:this.name,isAtBottom:!0})}filterVirtualOptions(e){const t=IM.filterVirtualOptions(e,this.originalOptionItems,this.data,this.getDisplayText.bind(this),this.renderItemConfig?.getSearchText);this.portal?(this.portalManager.updatePortalAppendPosition(),this.updateComplete.then((()=>{requestAnimationFrame((()=>{this.resetScrollPosition()}))}))):this.resetScrollPosition(),this.data=t.filteredItems,this.showNoResults=t.showNoResults,this.showSelected=!1,this.requestUpdate()}handleInvalid(e){this.formControlController.setValidity(!1),this.formControlController.emitInvalidEvent(e)}handleDisabledChange(){this.disabled&&(this.open=!1,this.handleOpenChange())}handleValueChange(){this.selectionChanged(),this.requestUpdate(),this.portal&&this.portalManager.portalContainerElement&&this.portalManager.updatePortalAppendPosition()}handleDataChange(){this.data.length>0&&this.open&&!this.showSelected&&!this.searchValue&&(this.originalOptionItems=[...this.data]),this.selectionChanged(),this.optionsLoading||this.loading||0!==this.data.length?this.data.length>0&&(this.showNoResults=!1):this.showNoResults=!0,this.requestUpdate(),this.portalManager.resetMeasuredHeight(),this.portal&&this.portalManager.portalContainerElement&&this.portalManager.updatePortalAppendPosition()}handleRenderItemConfigChange(){this.value&&this.data.length>0&&(this.selectionChanged(),this.requestUpdate())}handleOptionsLoadingChange(){this.optionsLoading||0!==this.data.length||(this.showNoResults=!0),this.requestUpdate(),this.portal&&this.portalManager.portalContainerElement&&this.portalManager.updatePortalAppendPosition()}handlePortalAppendChange(){this.open&&(this.portal?this.portalManager.setupPortalAppend():this.portalManager.cleanupPortalAppend())}async handleOpenChange(){this.open&&!this.disabled?(this.visibilityManager?.setup(),this.showListbox=!0,await this.updateComplete,await this.handleOpen(),this.portal&&this.portalManager.setupPortalAppend()):(this.visibilityManager?.cleanup(),await this.handleClose(),this.showListbox=!1,this.portal&&this.portalManager.cleanupPortalAppend())}async handleOpen(){this.emit("nile-show",{value:this.value,name:this.name}),this.addOpenListeners(),this.showNoResults=!this.data?.length,await jt(this),this.popup?.popup&&(this.popup.popup.style.visibility="hidden"),this.popup.active=!0,await new Promise((e=>requestAnimationFrame(e))),await new Promise((e=>requestAnimationFrame(e))),this.popup?.popup&&(this.popup.popup.style.visibility="");const{keyframes:e,options:t}=yt(this,"select.show",{dir:"ltr"});await ut(this.popup.popup,e,t),this.wasShowSelectedCheckedOnClose&&(this.showSelected=!1,this.data=[...this.originalOptionItems],this.wasShowSelectedCheckedOnClose=!1),this.filterVirtualOptions(""),this.resetScrollPosition(),this.emit("nile-after-show",{value:this.value,name:this.name})}async handleClose(){this.emit("nile-hide",{value:this.value,name:this.name}),this.removeOpenListeners(),this.wasShowSelectedCheckedOnClose=this.showSelected,await jt(this);const{keyframes:e,options:t}=yt(this,"select.hide",{dir:"ltr"});await ut(this.popup.popup,e,t),this.popup.active=!1,this.popup?.popup&&(this.popup.popup.style.visibility=""),this.searchValue="",this.portalManager.resetMeasuredHeight(),this.emit("nile-after-hide",{value:this.value,name:this.name})}async show(){if(!this.open&&!this.disabled)return this.open=!0,St(this,"nile-after-show");this.open=!1}async hide(){if(this.open&&!this.disabled)return this.open=!1,St(this,"nile-after-hide");this.open=!1}checkValidity(){return this.valueInput.checkValidity()}getForm(){return this.formControlController.getForm()}reportValidity(){return this.valueInput.reportValidity()}setCustomValidity(e){this.valueInput.setCustomValidity(e),this.formControlController.updateValidity()}focus(e){this.displayInput.focus(e)}blur(){this.displayInput.blur()}onInputChange(e){e.stopPropagation()}render(){const e=this.hasSlotController.test("label");this.hasSlotController.test("help-text");const t=this.hasSlotController.test("label-suffix"),i=this.hasSlotController.test("custom-select"),M=!!this.label||!!e,n=this.clearable&&!this.disabled&&this.value.length>0,o=!!this.placeholder&&0===this.value.length,r=!!this.helpText,s=!!this.errorMessage;return R`
|
|
4836
4836
|
<div
|
|
4837
4837
|
part="form-control"
|
|
4838
4838
|
class=${pe({"form-control":!0,"form-control--small":"small"===this.size,"form-control--medium":"medium"===this.size,"form-control--large":"large"===this.size,"form-control--has-label":M,"form-control--has-help-text":r})}
|
|
@@ -5682,7 +5682,7 @@ class QM{constructor(e){this._element=null;const t=e??window;this._node=t,e&&(th
|
|
|
5682
5682
|
max-width: var(--auto-size-available-width) !important;
|
|
5683
5683
|
max-height: var(--auto-size-available-height) !important;
|
|
5684
5684
|
}
|
|
5685
|
-
`;let Mn=class{static calculateAvailableSpace(e){const t=e.getBoundingClientRect(),i=window.innerHeight,M=window.innerWidth,n=i-t.bottom,o=t.top,r=M-t.right;return{spaceAbove:o,spaceBelow:n,spaceLeft:t.left,spaceRight:r,viewportHeight:i,viewportWidth:M}}static getOptimalPlacement(e){const{spaceAbove:t,spaceBelow:i,spaceLeft:M,spaceRight:n}=this.calculateAvailableSpace(e);return i>=200&&i>=t?"bottom":t>=200&&t>i?"top":n>=200&&n>=M?"right":M>=200?"left":"bottom"}static findBoundaryElements(e){const t=[];let i=e.parentElement;for(;i&&i!==document.body;){const e=window.getComputedStyle(i),M=e.overflow,n=e.overflowY,o=e.overflowX;"auto"!==M&&"scroll"!==M&&"auto"!==n&&"scroll"!==n&&"auto"!==o&&"scroll"!==o||t.push(i),(i.hasAttribute("data-floating-boundary")||i.classList.contains("floating-boundary")||i.classList.contains("scroll-container"))&&t.push(i),i=i.parentElement}return t.length>0?t:void 0}static calculateOptimalHeight(e,t,i){const M=t-(e.y+e.height),n=e.y;return i.startsWith("top")?Math.max(n-20,100):i.startsWith("bottom")?Math.max(M-20,100):(i.startsWith("left")||i.startsWith("right"),Math.max(Math.min(n,M)-20,100))}static extractStylesAsCSS(e){return"string"==typeof e?e:Array.isArray(e)?e.map((e=>this.extractStylesAsCSS(e))).join("\n"):e&&"object"==typeof e&&e.cssText?e.cssText:""}static generateStyleId(){return`nile-dropdown-styles-${Math.random().toString(36).substring(2,11)}`}static isPositioningOptimal(e,t){const{spaceAbove:i,spaceBelow:M,spaceLeft:n,spaceRight:o}=this.calculateAvailableSpace(t),r=e.startsWith("top"),s=e.startsWith("bottom"),a=e.startsWith("left"),l=e.startsWith("right");return!(r&&M>i)&&(!(s&&i>M)&&(!(a&&o>n)&&!(l&&n>o)))}static applyCollisionData(e,t,i){if(t.flip){const{overflows:M}=t.flip;if(e.setAttribute("data-placement",i),M&&M.length>0){const t=M.map((e=>e.placement)).join(",");e.setAttribute("data-overflow",t)}else e.removeAttribute("data-overflow")}if(t.shift){const{x:i,y:M}=t.shift;void 0===i||void 0===M||0===i&&0===M?e.removeAttribute("data-shift"):e.setAttribute("data-shift",`${i},${M}`)}if(t.size){const{availableWidth:i,availableHeight:M}=t.size;void 0!==i&&e.setAttribute("data-available-width",i.toString()),void 0!==M&&e.setAttribute("data-available-height",M.toString())}}},nn=class{static createPortalPanel(e){const t=e.shadowRoot?.querySelector(".dropdown__panel");if(!t){const t=e.querySelector("[slot]");if(!t||"trigger"===t.getAttribute("slot"))return document.createElement("div")}let i=t?.assignedElements({flatten:!0})||[];if(0===i.length){i=Array.from(e.children).filter((e=>{const t=e.getAttribute("slot");return!t||"trigger"!==t}))}const M=document.createElement("div");return M.className="dropdown__panel",M.setAttribute("part","panel"),M.setAttribute("aria-hidden","false"),M.setAttribute("aria-labelledby","dropdown"),i.forEach((e=>{const t=e.cloneNode(!0);M.appendChild(t)})),M}static updatePortalPanel(e,t){if(!e)return;e.innerHTML="";const i=t.shadowRoot?.querySelector(".dropdown__panel");let M=i?.assignedElements({flatten:!0})||[];if(0===M.length){M=Array.from(t.children).filter((e=>{const t=e.getAttribute("slot");return!t||"trigger"!==t}))}M.forEach((t=>{const i=t.cloneNode(!0);e.appendChild(i)}))}},on=class{static setupPortalEventListeners(e,t){e&&(this.setupMenuSelectListeners(e,t),this.setupKeyDownListeners(e,t))}static setupMenuSelectListeners(e,t){e&&e.addEventListener("nile-select",(e=>{const i=e;t.handlePanelSelect&&t.handlePanelSelect(i)}))}static setupKeyDownListeners(e,t){e&&e.addEventListener("keydown",(e=>{t.handleKeyDown&&t.handleKeyDown(e)}))}};class rn{constructor(e){this.portalContainer=null,this.measuredPanelHeight=null,this.clonedPanel=null,this.cleanupAutoUpdate=null,this.currentPlacement="bottom-start",this.currentMiddlewareData=null,this.boundHandleWindowResize=null,this.component=e}createPortalAppendContainer(){const e=document.createElement("div");return e.style.position="absolute",e.style.zIndex="9999",e.style.pointerEvents="none",e.style.width="auto",e.style.maxWidth="none",e.style.minWidth="auto",e.className="nile-dropdown-portal-append",e}positionPortalAppend(){this.portalContainer&&this.component.open&&(this.measurePanelHeight(),this.computeFloatingUIPosition())}measurePanelHeight(){!this.measuredPanelHeight&&this.portalContainer&&(this.portalContainer.style.position="absolute",this.portalContainer.style.visibility="hidden",this.portalContainer.style.top="0px",this.portalContainer.style.left="0px",this.portalContainer.offsetHeight,this.measuredPanelHeight=this.portalContainer.offsetHeight,this.portalContainer.style.visibility="")}async computeFloatingUIPosition(){if(!this.portalContainer)return;const e=this.component.shadowRoot?.querySelector('[slot="anchor"]')?.assignedElements({flatten:!0})[0]||this.component.querySelector('[slot="trigger"]')?.assignedElements({flatten:!0})[0]||this.component,t=this.portalContainer;try{const{x:i,y:M,placement:n,middlewareData:o}=await this.calculateFloatingUIPosition(e,t);this.applyFloatingUIPosition(t,e,i,M,n,o)}catch(e){console.warn("Floating UI positioning failed, falling back to simple positioning:",e),this.fallbackPositioning()}}async calculateFloatingUIPosition(e,t){const i=Mn.findBoundaryElements(e),M=this.getInitialPlacement(),n=this.createFloatingUIMiddleware(i);return await Ji(e,t,{placement:M,strategy:"fixed",middleware:n,platform:this.createCustomPlatform()})}getInitialPlacement(){return this.component.placement||"bottom-start"}createFloatingUIMiddleware(e){const t=[Bi(this.component.distance||0)];return this.component.sync&&t.push(Fi({apply:this.handleSizeMiddleware.bind(this),padding:10,boundary:e})),t.push(_i({fallbackPlacements:this.getFallbackPlacements(),fallbackStrategy:"bestFit",padding:10,boundary:e})),t.push(Gi({padding:10,crossAxis:!0,boundary:e})),t}handleSizeMiddleware({availableWidth:e,availableHeight:t,elements:i,rects:M}){const n=Mn.calculateOptimalHeight(M.reference,window.innerHeight,this.currentPlacement);"width"!==this.component.sync&&"both"!==this.component.sync||(i.floating.style.width=`${M.reference.width}px`),"height"!==this.component.sync&&"both"!==this.component.sync||(i.floating.style.height=`${M.reference.height}px`),i.floating.style.maxHeight=`${n}px`,i.floating.style.setProperty("--auto-size-available-width",`${e}px`),i.floating.style.setProperty("--auto-size-available-height",`${n}px`)}getFallbackPlacements(){const e=this.component.placement||"bottom-start",t=[];return e.startsWith("top")?t.push("bottom-start","bottom","bottom-end","top","top-end","right-start","left-start"):e.startsWith("bottom")?t.push("top-start","top","top-end","bottom","bottom-end","right-start","left-start"):e.startsWith("left")?t.push("right-start","right","right-end","left","left-end","top-start","bottom-start"):e.startsWith("right")&&t.push("left-start","left","left-end","right","right-end","top-start","bottom-start"),t}createCustomPlatform(){return Wi}applyFloatingUIPosition(e,t,i,M,n,o){const r=t.getBoundingClientRect();Object.assign(e.style,{left:`${i}px`,top:`${M}px`,position:"fixed",pointerEvents:"auto",width:"auto",minWidth:"auto"}),"width"!==this.component.sync&&"both"!==this.component.sync||(e.style.width=`${r.width}px`),this.currentPlacement=n,this.currentMiddlewareData=o,Mn.applyCollisionData(e,o,n);const s=n.split("-")[0];e.className=`nile-dropdown-portal-append dropdown--open dropdown__panel--${s}`}fallbackPositioning(){if(!this.portalContainer)return;const e=(this.component.shadowRoot?.querySelector('[slot="anchor"]')?.assignedElements({flatten:!0})[0]||this.component.querySelector('[slot="trigger"]')?.assignedElements({flatten:!0})[0]||this.component).getBoundingClientRect(),t=window.innerHeight,i=window.innerWidth,M=t-e.bottom,n=e.top,o=i-e.right,r=e.left;let s,a,l,N=e.left;const g=this.component.placement||"bottom-start";g.startsWith("bottom")?(l=Math.max(M-20,100),s=e.bottom+(this.component.distance||0),a="bottom"):g.startsWith("top")?(l=Math.max(n-20,100),s=Math.max(e.top-l-(this.component.distance||0),10),a="top"):g.startsWith("right")?(l=Math.max(Math.min(o,M,n)-20,100),s=e.top,N=e.right+(this.component.distance||0),a="right"):(l=Math.max(Math.min(r,M,n)-20,100),s=e.top,N=Math.max(e.left-200-(this.component.distance||0),10),a="left"),this.portalContainer.style.left=`${N}px`,this.portalContainer.style.top=`${s}px`,this.portalContainer.style.maxHeight=`${l}px`,this.portalContainer.style.pointerEvents="auto",this.portalContainer.style.width="auto",this.portalContainer.style.minWidth="auto","width"!==this.component.sync&&"both"!==this.component.sync||(this.portalContainer.style.width=`${e.width}px`),this.portalContainer.className=`nile-dropdown-portal-append dropdown__panel--${a}`,this.calculateAndSetAutoSizeProperties(e,s,a)}calculateAndSetAutoSizeProperties(e,t,i){if(!this.portalContainer)return;const M=window.innerHeight,n=window.innerWidth;let o,r=n-e.left-10;"top"===i?o=e.top-10:"bottom"===i?o=M-e.bottom-10:"left"===i?(o=Math.min(M-e.top,e.bottom),r=e.left-10):(o=Math.min(M-e.top,e.bottom),r=n-e.right-10),this.portalContainer.style.setProperty("--auto-size-available-height",`${Math.max(o,100)}px`),this.portalContainer.style.setProperty("--auto-size-available-width",`${Math.max(r,200)}px`)}updatePortalAppendPosition(){this.component.portal&&this.portalContainer&&this.positionPortalAppend()}handleWindowResize(){this.component.portal&&this.portalContainer&&this.positionPortalAppend()}setupAutoUpdatePositioning(){if(!this.portalContainer||!this.component)return;this.cleanupAutoUpdatePositioning();const e=this.component.shadowRoot?.querySelector('[slot="anchor"]')?.assignedElements({flatten:!0})[0]||this.component.querySelector('[slot="trigger"]')?.assignedElements({flatten:!0})[0]||this.component;this.cleanupAutoUpdate=Ri(e,this.portalContainer,(()=>{this.computeFloatingUIPosition()}),{ancestorScroll:!0,ancestorResize:!0,elementResize:!0,layoutShift:!0,animationFrame:!0})}cleanupAutoUpdatePositioning(){this.cleanupAutoUpdate&&(this.cleanupAutoUpdate(),this.cleanupAutoUpdate=null)}injectStylesToDocument(){if(!this.portalContainer)return;const e=Mn.generateStyleId();if(document.getElementById(e))return;const t=this.component.constructor.styles;if(!t)return;const i=document.createElement("style");i.id=e,i.textContent=Mn.extractStylesAsCSS(t),document.head.appendChild(i),this.portalContainer.__injectedStyleId=e}adoptStylesToPortalAppend(){this.portalContainer&&this.injectStylesToDocument()}setupPortalAppend(){this.component.portal&&this.component.updateComplete.then((()=>{setTimeout((()=>{this.component.open&&(this.clonedPanel=this.createPortalPanel(),this.portalContainer=this.createPortalAppendContainer(),this.portalContainer.appendChild(this.clonedPanel),document.body.appendChild(this.portalContainer),this.adoptStylesToPortalAppend(),this.clonedPanel.style.display="",this.positionPortalAppend(),this.setupPortalEventListeners(),this.setupAutoUpdatePositioning(),this.boundHandleWindowResize=this.handleWindowResize.bind(this),window.addEventListener("resize",this.boundHandleWindowResize))}),10)}))}createPortalPanel(){return nn.createPortalPanel(this.component)}setupPortalEventListeners(){on.setupPortalEventListeners(this.clonedPanel,this.component)}cleanupPortalAppend(){if(this.cleanupAutoUpdatePositioning(),this.portalContainer&&this.portalContainer.parentNode){const e=this.portalContainer.__injectedStyleId;if(e){const t=document.getElementById(e);t&&t.remove()}this.portalContainer.parentNode.removeChild(this.portalContainer)}this.boundHandleWindowResize&&(window.removeEventListener("resize",this.boundHandleWindowResize),this.boundHandleWindowResize=null),this.portalContainer=null,this.clonedPanel=null,this.measuredPanelHeight=null,this.currentPlacement="bottom-start",this.currentMiddlewareData=null}get portalContainerElement(){return this.portalContainer}resetMeasuredHeight(){this.measuredPanelHeight=null}forceReposition(){this.portalContainer&&this.computeFloatingUIPosition()}getCurrentPlacement(){return this.currentPlacement}getCurrentMiddlewareData(){return this.currentMiddlewareData}isUsingFloatingUI(){return null!==this.cleanupAutoUpdate}isPositioningOptimal(){if(!this.portalContainer||!this.currentMiddlewareData)return!0;const e=(this.component.shadowRoot?.querySelector('[slot="anchor"]')?.assignedElements({flatten:!0})[0]||this.component.querySelector('[slot="trigger"]')?.assignedElements({flatten:!0})[0]||this.component).getBoundingClientRect(),t=window.innerHeight-e.bottom,i=e.top,M=this.currentPlacement.startsWith("top"),n=this.currentPlacement.startsWith("bottom");return!(M&&t>i)&&!(n&&i>t)}updatePortalPanel(){this.portalContainer&&this.clonedPanel&&(nn.updatePortalPanel(this.clonedPanel,this.component),this.forceReposition())}}let sn=class extends Re{constructor(){super(...arguments),this.open=!1,this.placement="bottom-start",this.disabled=!1,this.stayOpenOnSelect=!1,this.distance=0,this.noOpenOnClick=!1,this.skidding=0,this.hoist=!1,this.portal=!1,this.enableVisibilityEffect=!1,this.enableTabClose=!1,this.portalManager=null}connectedCallback(){super.connectedCallback(),this.handlePanelSelect=this.handlePanelSelect.bind(this),this.handleKeyDown=this.handleKeyDown.bind(this),this.handleDocumentKeyDown=this.handleDocumentKeyDown.bind(this),this.handleDocumentMouseDown=this.handleDocumentMouseDown.bind(this),this.containingElement||(this.containingElement=this),this.emit("nile-init"),requestAnimationFrame((()=>{this.portal&&!this.portalManager&&(this.portalManager=new rn(this))}))}async firstUpdated(e){super.firstUpdated?.(e),this.panel.hidden=!this.open,this.open&&(this.addOpenListeners(),this.popup.active=!0),await this.updateComplete;const t=this.trigger.assignedElements({flatten:!0})[0];this.visibilityManager=new tM({host:this,target:t||null,enableVisibilityEffect:this.enableVisibilityEffect,enableTabClose:this.enableTabClose,isOpen:()=>this.open,onAnchorOutOfView:()=>{this.hide(),this.emit("nile-visibility-change",{visible:!1,reason:"anchor-out-of-view"})},onDocumentHidden:()=>{this.hide(),this.emit("nile-visibility-change",{visible:!1,reason:"document-hidden"})},emit:(e,t)=>this.emit(`nile-${e}`,t)})}disconnectedCallback(){super.disconnectedCallback(),this.visibilityManager?.cleanup(),this.removeOpenListeners(),this.hide(),this.emit("nile-destroy"),this.portalManager&&(this.portalManager.cleanupPortalAppend(),this.portalManager=null)}focusOnTrigger(){const e=this.trigger.assignedElements({flatten:!0})[0];"function"==typeof e?.focus&&e.focus()}getMenu(){return this.panel.assignedElements({flatten:!0}).find((e=>"nile-menu"===e.tagName.toLowerCase()))}handleKeyDown(e){this.open&&"Escape"===e.key&&(e.stopPropagation(),this.hide(),this.focusOnTrigger())}handleDocumentKeyDown(e){if("Escape"===e.key&&this.open)return e.stopPropagation(),this.focusOnTrigger(),void this.hide();if("Tab"===e.key){if(this.open&&"nile-menu-item"===document.activeElement?.tagName.toLowerCase())return e.preventDefault(),this.hide(),void this.focusOnTrigger();setTimeout((()=>{const e=this.containingElement?.getRootNode()instanceof ShadowRoot?document.activeElement?.shadowRoot?.activeElement:document.activeElement,t=this.containingElement&&e?.closest(this.containingElement.tagName.toLowerCase())===this.containingElement,i=this.portal&&this.portalManager?.portalContainerElement&&(e===this.portalManager.portalContainerElement||e?.closest(".nile-dropdown-portal-append")===this.portalManager.portalContainerElement);t||i||this.hide()}))}}handleDocumentMouseDown(e){const t=e.composedPath(),i=this.containingElement&&t.includes(this.containingElement),M=this.portal&&this.portalManager?.portalContainerElement&&t.includes(this.portalManager.portalContainerElement);i||M||this.hide()}handlePanelSelect(e){const t=e.target;this.stayOpenOnSelect||"nile-menu"!==t.tagName.toLowerCase()||(this.hide(),this.focusOnTrigger())}handleTriggerClick(){this.noOpenOnClick||(this.open?this.hide():(this.show(),this.focusOnTrigger()))}handleTriggerKeyDown(e){const t=this.getMenu();if(t){const i=t.getAllItems(),M=i[0],n=i[i.length-1];["ArrowDown","ArrowUp","Home","End"].includes(e.key)&&(e.preventDefault(),this.open||this.show(),i.length>0&&this.updateComplete.then((()=>{"ArrowDown"!==e.key&&"Home"!==e.key||(t.setCurrentItem(M),M.focus()),"ArrowUp"!==e.key&&"End"!==e.key||(t.setCurrentItem(n),n.focus())})))}}handleTriggerKeyUp(e){" "===e.key&&e.preventDefault()}handleTriggerSlotChange(){this.updateAccessibleTrigger()}updateAccessibleTrigger(){const e=this.trigger.assignedElements({flatten:!0}).find((e=>mt(e).start));let t;if(e){switch(e.tagName.toLowerCase()){case"nile-button":case"nile-icon-button":t=e.button;break;default:t=e}t.setAttribute("aria-haspopup","true"),t.setAttribute("aria-expanded",this.open?"true":"false")}}async show(){if(!this.open)return this.open=!0,St(this,"nile-after-show")}async hide(){if(this.open)return this.open=!1,St(this,"nile-after-hide")}reposition(){this.popup.reposition()}addOpenListeners(){this.panel.addEventListener("nile-select",this.handlePanelSelect),this.panel.addEventListener("keydown",this.handleKeyDown),document.addEventListener("keydown",this.handleDocumentKeyDown),document.addEventListener("mousedown",this.handleDocumentMouseDown)}removeOpenListeners(){this.panel&&(this.panel.removeEventListener("nile-select",this.handlePanelSelect),this.panel.removeEventListener("keydown",this.handleKeyDown)),document.removeEventListener("keydown",this.handleDocumentKeyDown),document.removeEventListener("mousedown",this.handleDocumentMouseDown)}updated(e){super.updated(e),e.has("portal")&&(this.portal&&!this.portalManager?(this.portalManager=new rn(this),this.open&&this.portalManager.setupPortalAppend()):!this.portal&&this.portalManager&&(this.portalManager.cleanupPortalAppend(),this.portalManager=null))}async handleOpenChange(){if(this.visibilityManager?.setup(),this.disabled)this.open=!1;else if(this.updateAccessibleTrigger(),this.open){if(this.emit("nile-show"),this.addOpenListeners(),this.portal&&this.portalManager?this.portalManager.setupPortalAppend():this.portal&&!this.portalManager&&(this.portalManager=new rn(this),this.portalManager.setupPortalAppend()),await jt(this),!this.portal){this.panel.hidden=!1,this.popup.active=!0;const{keyframes:e,options:t}=yt(this,"dropdown.show",{dir:""});await ut(this.popup.popup,e,t)}this.emit("nile-after-show")}else{if(this.emit("nile-hide"),this.removeOpenListeners(),this.visibilityManager?.cleanup(),this.portal&&this.portalManager&&this.portalManager.cleanupPortalAppend(),await jt(this),!this.portal){const{keyframes:e,options:t}=yt(this,"dropdown.hide",{dir:""});await ut(this.popup.popup,e,t),this.panel.hidden=!0,this.popup.active=!1}this.emit("nile-after-hide")}}render(){return R`
|
|
5685
|
+
`;let Mn=class{static calculateAvailableSpace(e){const t=e.getBoundingClientRect(),i=window.innerHeight,M=window.innerWidth,n=i-t.bottom,o=t.top,r=M-t.right;return{spaceAbove:o,spaceBelow:n,spaceLeft:t.left,spaceRight:r,viewportHeight:i,viewportWidth:M}}static getOptimalPlacement(e){const{spaceAbove:t,spaceBelow:i,spaceLeft:M,spaceRight:n}=this.calculateAvailableSpace(e);return i>=200&&i>=t?"bottom":t>=200&&t>i?"top":n>=200&&n>=M?"right":M>=200?"left":"bottom"}static findBoundaryElements(e){const t=[];let i=e.parentElement;for(;i&&i!==document.body;){const e=window.getComputedStyle(i),M=e.overflow,n=e.overflowY,o=e.overflowX;"auto"!==M&&"scroll"!==M&&"auto"!==n&&"scroll"!==n&&"auto"!==o&&"scroll"!==o||t.push(i),(i.hasAttribute("data-floating-boundary")||i.classList.contains("floating-boundary")||i.classList.contains("scroll-container"))&&t.push(i),i=i.parentElement}return t.length>0?t:void 0}static calculateOptimalHeight(e,t,i){const M=t-(e.y+e.height),n=e.y;return i.startsWith("top")?Math.max(n-20,100):i.startsWith("bottom")?Math.max(M-20,100):(i.startsWith("left")||i.startsWith("right"),Math.max(Math.min(n,M)-20,100))}static extractStylesAsCSS(e){return"string"==typeof e?e:Array.isArray(e)?e.map((e=>this.extractStylesAsCSS(e))).join("\n"):e&&"object"==typeof e&&e.cssText?e.cssText:""}static generateStyleId(){return`nile-dropdown-styles-${Math.random().toString(36).substring(2,11)}`}static isPositioningOptimal(e,t){const{spaceAbove:i,spaceBelow:M,spaceLeft:n,spaceRight:o}=this.calculateAvailableSpace(t),r=e.startsWith("top"),s=e.startsWith("bottom"),a=e.startsWith("left"),l=e.startsWith("right");return!(r&&M>i)&&(!(s&&i>M)&&(!(a&&o>n)&&!(l&&n>o)))}static applyCollisionData(e,t,i){if(t.flip){const{overflows:M}=t.flip;if(e.setAttribute("data-placement",i),M&&M.length>0){const t=M.map((e=>e.placement)).join(",");e.setAttribute("data-overflow",t)}else e.removeAttribute("data-overflow")}if(t.shift){const{x:i,y:M}=t.shift;void 0===i||void 0===M||0===i&&0===M?e.removeAttribute("data-shift"):e.setAttribute("data-shift",`${i},${M}`)}if(t.size){const{availableWidth:i,availableHeight:M}=t.size;void 0!==i&&e.setAttribute("data-available-width",i.toString()),void 0!==M&&e.setAttribute("data-available-height",M.toString())}}},nn=class{static createPortalPanel(e){const t=e.shadowRoot?.querySelector(".dropdown__panel");if(!t){const t=e.querySelector("[slot]");if(!t||"trigger"===t.getAttribute("slot"))return document.createElement("div")}let i=t?.assignedElements({flatten:!0})||[];if(0===i.length){i=Array.from(e.children).filter((e=>{const t=e.getAttribute("slot");return!t||"trigger"!==t}))}const M=document.createElement("div");return M.className="dropdown__panel",M.setAttribute("part","panel"),M.setAttribute("aria-hidden","false"),M.setAttribute("aria-labelledby","dropdown"),i.forEach((e=>{const t=e.cloneNode(!0);M.appendChild(t)})),M}static updatePortalPanel(e,t){if(!e)return;e.innerHTML="";const i=t.shadowRoot?.querySelector(".dropdown__panel");let M=i?.assignedElements({flatten:!0})||[];if(0===M.length){M=Array.from(t.children).filter((e=>{const t=e.getAttribute("slot");return!t||"trigger"!==t}))}M.forEach((t=>{const i=t.cloneNode(!0);e.appendChild(i)}))}},on=class{static setupPortalEventListeners(e,t){e&&(this.setupMenuSelectListeners(e,t),this.setupKeyDownListeners(e,t))}static setupMenuSelectListeners(e,t){e&&e.addEventListener("nile-select",(e=>{const i=e;t.handlePanelSelect&&t.handlePanelSelect(i)}))}static setupKeyDownListeners(e,t){e&&e.addEventListener("keydown",(e=>{t.handleKeyDown&&t.handleKeyDown(e)}))}};class rn{constructor(e){this.portalContainer=null,this.measuredPanelHeight=null,this.clonedPanel=null,this.cleanupAutoUpdate=null,this.currentPlacement="bottom-start",this.currentMiddlewareData=null,this.boundHandleWindowResize=null,this.component=e}createPortalAppendContainer(){const e=document.createElement("div");return e.style.position="absolute",e.style.zIndex="9999",e.style.pointerEvents="none",e.style.width="auto",e.style.maxWidth="none",e.style.minWidth="auto",e.className="nile-dropdown-portal-append",e}positionPortalAppend(){this.portalContainer&&this.component.open&&(this.measurePanelHeight(),this.computeFloatingUIPosition())}measurePanelHeight(){!this.measuredPanelHeight&&this.portalContainer&&(this.portalContainer.style.position="absolute",this.portalContainer.style.visibility="hidden",this.portalContainer.style.top="0px",this.portalContainer.style.left="0px",this.portalContainer.offsetHeight,this.measuredPanelHeight=this.portalContainer.offsetHeight,this.portalContainer.style.visibility="")}async computeFloatingUIPosition(){if(!this.portalContainer)return;const e=this.component.shadowRoot?.querySelector('[slot="anchor"]')?.assignedElements({flatten:!0})[0]||this.component.querySelector('[slot="trigger"]')?.assignedElements({flatten:!0})[0]||this.component,t=this.portalContainer;try{const{x:i,y:M,placement:n,middlewareData:o}=await this.calculateFloatingUIPosition(e,t);this.applyFloatingUIPosition(t,e,i,M,n,o)}catch(e){console.warn("Floating UI positioning failed, falling back to simple positioning:",e),this.fallbackPositioning()}}async calculateFloatingUIPosition(e,t){const i=Mn.findBoundaryElements(e),M=this.getInitialPlacement(),n=this.createFloatingUIMiddleware(i);return await Ji(e,t,{placement:M,strategy:"fixed",middleware:n,platform:this.createCustomPlatform()})}getInitialPlacement(){return this.component.placement||"bottom-start"}createFloatingUIMiddleware(e){const t=[Bi(this.component.distance||0)];return this.component.sync&&t.push(Fi({apply:this.handleSizeMiddleware.bind(this),padding:10,boundary:e})),t.push(_i({fallbackPlacements:this.getFallbackPlacements(),fallbackStrategy:"bestFit",padding:10,boundary:e})),t.push(Gi({padding:10,crossAxis:!0,boundary:e})),t}handleSizeMiddleware({availableWidth:e,availableHeight:t,elements:i,rects:M}){const n=Mn.calculateOptimalHeight(M.reference,window.innerHeight,this.currentPlacement);"width"!==this.component.sync&&"both"!==this.component.sync||(i.floating.style.width=`${M.reference.width}px`),"height"!==this.component.sync&&"both"!==this.component.sync||(i.floating.style.height=`${M.reference.height}px`),i.floating.style.maxHeight=`${n}px`,i.floating.style.setProperty("--auto-size-available-width",`${e}px`),i.floating.style.setProperty("--auto-size-available-height",`${n}px`)}getFallbackPlacements(){const e=this.component.placement||"bottom-start",t=[];return e.startsWith("top")?t.push("bottom-start","bottom","bottom-end","top","top-end","right-start","left-start"):e.startsWith("bottom")?t.push("top-start","top","top-end","bottom","bottom-end","right-start","left-start"):e.startsWith("left")?t.push("right-start","right","right-end","left","left-end","top-start","bottom-start"):e.startsWith("right")&&t.push("left-start","left","left-end","right","right-end","top-start","bottom-start"),t}createCustomPlatform(){return Wi}applyFloatingUIPosition(e,t,i,M,n,o){const r=t.getBoundingClientRect();Object.assign(e.style,{left:`${i}px`,top:`${M}px`,position:"fixed",pointerEvents:"auto",width:"auto",minWidth:"auto"}),"width"!==this.component.sync&&"both"!==this.component.sync||(e.style.width=`${r.width}px`),this.currentPlacement=n,this.currentMiddlewareData=o,Mn.applyCollisionData(e,o,n);const s=n.split("-")[0];e.className=`nile-dropdown-portal-append dropdown--open dropdown__panel--${s}`}fallbackPositioning(){if(!this.portalContainer)return;const e=(this.component.shadowRoot?.querySelector('[slot="anchor"]')?.assignedElements({flatten:!0})[0]||this.component.querySelector('[slot="trigger"]')?.assignedElements({flatten:!0})[0]||this.component).getBoundingClientRect(),t=window.innerHeight,i=window.innerWidth,M=t-e.bottom,n=e.top,o=i-e.right,r=e.left;let s,a,l,N=e.left;const g=this.component.placement||"bottom-start";g.startsWith("bottom")?(l=Math.max(M-20,100),s=e.bottom+(this.component.distance||0),a="bottom"):g.startsWith("top")?(l=Math.max(n-20,100),s=Math.max(e.top-l-(this.component.distance||0),10),a="top"):g.startsWith("right")?(l=Math.max(Math.min(o,M,n)-20,100),s=e.top,N=e.right+(this.component.distance||0),a="right"):(l=Math.max(Math.min(r,M,n)-20,100),s=e.top,N=Math.max(e.left-200-(this.component.distance||0),10),a="left"),this.portalContainer.style.left=`${N}px`,this.portalContainer.style.top=`${s}px`,this.portalContainer.style.maxHeight=`${l}px`,this.portalContainer.style.pointerEvents="auto",this.portalContainer.style.width="auto",this.portalContainer.style.minWidth="auto","width"!==this.component.sync&&"both"!==this.component.sync||(this.portalContainer.style.width=`${e.width}px`),this.portalContainer.className=`nile-dropdown-portal-append dropdown__panel--${a}`,this.calculateAndSetAutoSizeProperties(e,s,a)}calculateAndSetAutoSizeProperties(e,t,i){if(!this.portalContainer)return;const M=window.innerHeight,n=window.innerWidth;let o,r=n-e.left-10;"top"===i?o=e.top-10:"bottom"===i?o=M-e.bottom-10:"left"===i?(o=Math.min(M-e.top,e.bottom),r=e.left-10):(o=Math.min(M-e.top,e.bottom),r=n-e.right-10),this.portalContainer.style.setProperty("--auto-size-available-height",`${Math.max(o,100)}px`),this.portalContainer.style.setProperty("--auto-size-available-width",`${Math.max(r,200)}px`)}updatePortalAppendPosition(){this.component.portal&&this.portalContainer&&this.positionPortalAppend()}handleWindowResize(){this.component.portal&&this.portalContainer&&this.positionPortalAppend()}setupAutoUpdatePositioning(){if(!this.portalContainer||!this.component)return;this.cleanupAutoUpdatePositioning();const e=this.component.shadowRoot?.querySelector('[slot="anchor"]')?.assignedElements({flatten:!0})[0]||this.component.querySelector('[slot="trigger"]')?.assignedElements({flatten:!0})[0]||this.component;this.cleanupAutoUpdate=Ri(e,this.portalContainer,(()=>{this.computeFloatingUIPosition()}),{ancestorScroll:!0,ancestorResize:!0,elementResize:!0,layoutShift:!0,animationFrame:!0})}cleanupAutoUpdatePositioning(){this.cleanupAutoUpdate&&(this.cleanupAutoUpdate(),this.cleanupAutoUpdate=null)}injectStylesToDocument(){if(!this.portalContainer)return;const e=Mn.generateStyleId();if(document.getElementById(e))return;const t=this.component.constructor.styles;if(!t)return;const i=document.createElement("style");i.id=e,i.textContent=Mn.extractStylesAsCSS(t),document.head.appendChild(i),this.portalContainer.__injectedStyleId=e}adoptStylesToPortalAppend(){this.portalContainer&&this.injectStylesToDocument()}setupPortalAppend(){this.component.portal&&this.component.updateComplete.then((()=>{setTimeout((()=>{this.component.open&&(this.clonedPanel=this.createPortalPanel(),this.portalContainer=this.createPortalAppendContainer(),this.portalContainer.appendChild(this.clonedPanel),document.body.appendChild(this.portalContainer),this.adoptStylesToPortalAppend(),this.clonedPanel.style.display="",this.positionPortalAppend(),this.setupPortalEventListeners(),this.setupAutoUpdatePositioning(),this.boundHandleWindowResize=this.handleWindowResize.bind(this),window.addEventListener("resize",this.boundHandleWindowResize))}),10)}))}createPortalPanel(){return nn.createPortalPanel(this.component)}setupPortalEventListeners(){on.setupPortalEventListeners(this.clonedPanel,this.component)}cleanupPortalAppend(){if(this.cleanupAutoUpdatePositioning(),this.portalContainer&&this.portalContainer.parentNode){const e=this.portalContainer.__injectedStyleId;if(e){const t=document.getElementById(e);t&&t.remove()}this.portalContainer.parentNode.removeChild(this.portalContainer)}this.boundHandleWindowResize&&(window.removeEventListener("resize",this.boundHandleWindowResize),this.boundHandleWindowResize=null),this.portalContainer=null,this.clonedPanel=null,this.measuredPanelHeight=null,this.currentPlacement="bottom-start",this.currentMiddlewareData=null}get portalContainerElement(){return this.portalContainer}resetMeasuredHeight(){this.measuredPanelHeight=null}forceReposition(){this.portalContainer&&this.computeFloatingUIPosition()}getCurrentPlacement(){return this.currentPlacement}getCurrentMiddlewareData(){return this.currentMiddlewareData}isUsingFloatingUI(){return null!==this.cleanupAutoUpdate}isPositioningOptimal(){if(!this.portalContainer||!this.currentMiddlewareData)return!0;const e=(this.component.shadowRoot?.querySelector('[slot="anchor"]')?.assignedElements({flatten:!0})[0]||this.component.querySelector('[slot="trigger"]')?.assignedElements({flatten:!0})[0]||this.component).getBoundingClientRect(),t=window.innerHeight-e.bottom,i=e.top,M=this.currentPlacement.startsWith("top"),n=this.currentPlacement.startsWith("bottom");return!(M&&t>i)&&!(n&&i>t)}updatePortalPanel(){this.portalContainer&&this.clonedPanel&&(nn.updatePortalPanel(this.clonedPanel,this.component),this.forceReposition())}}let sn=class extends Re{constructor(){super(...arguments),this.open=!1,this.placement="bottom-start",this.disabled=!1,this.stayOpenOnSelect=!1,this.distance=0,this.noOpenOnClick=!1,this.skidding=0,this.hoist=!1,this.portal=!1,this.enableVisibilityEffect=!1,this.enableTabClose=!1,this.portalManager=null}connectedCallback(){super.connectedCallback(),this.handlePanelSelect=this.handlePanelSelect.bind(this),this.handleKeyDown=this.handleKeyDown.bind(this),this.handleDocumentKeyDown=this.handleDocumentKeyDown.bind(this),this.handleDocumentMouseDown=this.handleDocumentMouseDown.bind(this),this.containingElement||(this.containingElement=this),this.emit("nile-init"),requestAnimationFrame((()=>{this.portal&&!this.portalManager&&(this.portalManager=new rn(this))}))}async firstUpdated(e){this.panel.hidden=!this.open,this.open&&(this.addOpenListeners(),this.popup.active=!0),await this.updateComplete;const t=this.trigger.assignedElements({flatten:!0})[0];this.visibilityManager=new tM({host:this,target:t||null,enableVisibilityEffect:this.enableVisibilityEffect,enableTabClose:this.enableTabClose,isOpen:()=>this.open,onAnchorOutOfView:()=>{this.hide(),this.emit("nile-visibility-change",{visible:!1,reason:"anchor-out-of-view"})},onDocumentHidden:()=>{this.hide(),this.emit("nile-visibility-change",{visible:!1,reason:"document-hidden"})},emit:(e,t)=>this.emit(`nile-${e}`,t)})}disconnectedCallback(){super.disconnectedCallback(),this.visibilityManager?.cleanup(),this.removeOpenListeners(),this.hide(),this.emit("nile-destroy"),this.portalManager&&(this.portalManager.cleanupPortalAppend(),this.portalManager=null)}focusOnTrigger(){const e=this.trigger.assignedElements({flatten:!0})[0];"function"==typeof e?.focus&&e.focus()}getMenu(){return this.panel.assignedElements({flatten:!0}).find((e=>"nile-menu"===e.tagName.toLowerCase()))}handleKeyDown(e){this.open&&"Escape"===e.key&&(e.stopPropagation(),this.hide(),this.focusOnTrigger())}handleDocumentKeyDown(e){if("Escape"===e.key&&this.open)return e.stopPropagation(),this.focusOnTrigger(),void this.hide();if("Tab"===e.key){if(this.open&&"nile-menu-item"===document.activeElement?.tagName.toLowerCase())return e.preventDefault(),this.hide(),void this.focusOnTrigger();setTimeout((()=>{const e=this.containingElement?.getRootNode()instanceof ShadowRoot?document.activeElement?.shadowRoot?.activeElement:document.activeElement,t=this.containingElement&&e?.closest(this.containingElement.tagName.toLowerCase())===this.containingElement,i=this.portal&&this.portalManager?.portalContainerElement&&(e===this.portalManager.portalContainerElement||e?.closest(".nile-dropdown-portal-append")===this.portalManager.portalContainerElement);t||i||this.hide()}))}}handleDocumentMouseDown(e){const t=e.composedPath(),i=this.containingElement&&t.includes(this.containingElement),M=this.portal&&this.portalManager?.portalContainerElement&&t.includes(this.portalManager.portalContainerElement);i||M||this.hide()}handlePanelSelect(e){const t=e.target;this.stayOpenOnSelect||"nile-menu"!==t.tagName.toLowerCase()||(this.hide(),this.focusOnTrigger())}handleTriggerClick(){this.noOpenOnClick||(this.open?this.hide():(this.show(),this.focusOnTrigger()))}handleTriggerKeyDown(e){const t=this.getMenu();if(t){const i=t.getAllItems(),M=i[0],n=i[i.length-1];["ArrowDown","ArrowUp","Home","End"].includes(e.key)&&(e.preventDefault(),this.open||this.show(),i.length>0&&this.updateComplete.then((()=>{"ArrowDown"!==e.key&&"Home"!==e.key||(t.setCurrentItem(M),M.focus()),"ArrowUp"!==e.key&&"End"!==e.key||(t.setCurrentItem(n),n.focus())})))}}handleTriggerKeyUp(e){" "===e.key&&e.preventDefault()}handleTriggerSlotChange(){this.updateAccessibleTrigger()}updateAccessibleTrigger(){const e=this.trigger.assignedElements({flatten:!0}).find((e=>mt(e).start));let t;if(e){switch(e.tagName.toLowerCase()){case"nile-button":case"nile-icon-button":t=e.button;break;default:t=e}t.setAttribute("aria-haspopup","true"),t.setAttribute("aria-expanded",this.open?"true":"false")}}async show(){if(!this.open)return this.open=!0,St(this,"nile-after-show")}async hide(){if(this.open)return this.open=!1,St(this,"nile-after-hide")}reposition(){this.popup.reposition()}addOpenListeners(){this.panel.addEventListener("nile-select",this.handlePanelSelect),this.panel.addEventListener("keydown",this.handleKeyDown),document.addEventListener("keydown",this.handleDocumentKeyDown),document.addEventListener("mousedown",this.handleDocumentMouseDown)}removeOpenListeners(){this.panel&&(this.panel.removeEventListener("nile-select",this.handlePanelSelect),this.panel.removeEventListener("keydown",this.handleKeyDown)),document.removeEventListener("keydown",this.handleDocumentKeyDown),document.removeEventListener("mousedown",this.handleDocumentMouseDown)}updated(e){super.updated(e),e.has("portal")&&(this.portal&&!this.portalManager?(this.portalManager=new rn(this),this.open&&this.portalManager.setupPortalAppend()):!this.portal&&this.portalManager&&(this.portalManager.cleanupPortalAppend(),this.portalManager=null))}async handleOpenChange(){if(this.visibilityManager?.setup(),this.disabled)this.open=!1;else if(this.updateAccessibleTrigger(),this.open){if(this.emit("nile-show"),this.addOpenListeners(),this.portal&&this.portalManager?this.portalManager.setupPortalAppend():this.portal&&!this.portalManager&&(this.portalManager=new rn(this),this.portalManager.setupPortalAppend()),await jt(this),!this.portal){this.panel.hidden=!1,this.popup.active=!0;const{keyframes:e,options:t}=yt(this,"dropdown.show",{dir:""});await ut(this.popup.popup,e,t)}this.emit("nile-after-show")}else{if(this.emit("nile-hide"),this.removeOpenListeners(),this.visibilityManager?.cleanup(),this.portal&&this.portalManager&&this.portalManager.cleanupPortalAppend(),await jt(this),!this.portal){const{keyframes:e,options:t}=yt(this,"dropdown.hide",{dir:""});await ut(this.popup.popup,e,t),this.panel.hidden=!0,this.popup.active=!1}this.emit("nile-after-hide")}}render(){return R`
|
|
5686
5686
|
<nile-popup
|
|
5687
5687
|
part="base"
|
|
5688
5688
|
id="dropdown"
|
|
@@ -5741,7 +5741,7 @@ class QM{constructor(e){this._element=null;const t=e??window;this._node=t,e&&(th
|
|
|
5741
5741
|
.nile-auto-complete--input {
|
|
5742
5742
|
width: 100%;
|
|
5743
5743
|
}
|
|
5744
|
-
`;let ln=class{static calculateAvailableSpace(e){const t=e.getBoundingClientRect(),i=window.innerHeight,M=i-t.bottom;return{spaceAbove:t.top,spaceBelow:M,viewportHeight:i}}static getOptimalPlacement(e){const{spaceAbove:t,spaceBelow:i}=this.calculateAvailableSpace(e);return i<200&&t>i?"top":"bottom"}static findBoundaryElements(e){const t=[];let i=e.parentElement;for(;i&&i!==document.body;){const e=window.getComputedStyle(i),M=e.overflow,n=e.overflowY,o=e.overflowX;"auto"!==M&&"scroll"!==M&&"auto"!==n&&"scroll"!==n&&"auto"!==o&&"scroll"!==o||t.push(i),(i.hasAttribute("data-floating-boundary")||i.classList.contains("floating-boundary")||i.classList.contains("scroll-container"))&&t.push(i),i=i.parentElement}return t.length>0?t:void 0}static calculateOptimalHeight(e,t,i){const M=t-(e.y+e.height),n=e.y;return n>M?Math.max(n-20,100):M>n?Math.max(M-20,100):Math.max(Math.min(n,M)-20,100)}static extractStylesAsCSS(e){return"string"==typeof e?e:Array.isArray(e)?e.map((e=>this.extractStylesAsCSS(e))).join("\n"):e&&"object"==typeof e&&e.cssText?e.cssText:""}static generateStyleId(){return`nile-auto-complete-styles-${Math.random().toString(36).substring(2,11)}`}static isPositioningOptimal(e,t){const{spaceAbove:i,spaceBelow:M}=this.calculateAvailableSpace(t),n=e.startsWith("top"),o=e.startsWith("bottom");return!(n&&M>i)&&!(o&&i>M)}static applyCollisionData(e,t,i){if(t.flip){const{overflows:M}=t.flip;if(e.setAttribute("data-placement",i),M&&M.length>0){const t=M.map((e=>e.placement)).join(",");e.setAttribute("data-overflow",t)}else e.removeAttribute("data-overflow")}if(t.shift){const{x:i,y:M}=t.shift;void 0===i||void 0===M||0===i&&0===M?e.removeAttribute("data-shift"):e.setAttribute("data-shift",`${i},${M}`)}if(t.size){const{availableWidth:i,availableHeight:M}=t.size;void 0!==i&&e.setAttribute("data-available-width",i.toString()),void 0!==M&&e.setAttribute("data-available-height",M.toString())}}},Nn=class{static createBaseMenu(e){const t=document.createElement("nile-menu");return t.id="content-menu",t.className=e.enableVirtualScroll?"virtualized__menu":"",e.enableVirtualScroll,t.setAttribute("exportparts","menu__items-wrapper:options__wrapper"),t}static addMenuItems(e,t){(t.menuItems||[]).forEach((i=>{const M=this.createMenuItem(i,t);e.appendChild(M)}))}static createMenuItem(e,t){const i=document.createElement("div"),M=t.getItemRenderFunction(e);return se(M,i),i.firstElementChild}static createPortalMenu(e){const t=this.createBaseMenu(e);return this.addMenuItems(t,e),t}static updatePortalMenuItems(e,t){if(!e)return;e.querySelectorAll("nile-menu-item").forEach((e=>e.remove())),this.addMenuItems(e,t)}},gn=class{static setupPortalEventListeners(e,t){e&&this.setupMenuSelectListeners(e,t)}static setupMenuSelectListeners(e,t){e&&e.addEventListener("nile-select",(e=>{const i=e;t.handleSelect&&t.handleSelect(i)}))}};class un{constructor(e){this.portalContainer=null,this.originalMenuParent=null,this.measuredMenuHeight=null,this.clonedMenu=null,this.cleanupAutoUpdate=null,this.currentPlacement="bottom",this.currentMiddlewareData=null,this.component=e}createPortalAppendContainer(){const e=document.createElement("div");return e.style.position="absolute",e.style.zIndex="9999",e.style.pointerEvents="none",e.style.width="auto",e.style.minWidth="auto",e.className="nile-auto-complete-portal-append",e}positionPortalAppend(){this.portalContainer&&this.component.dropdownElement&&(this.measureMenuHeight(),this.computeFloatingUIPosition())}measureMenuHeight(){!this.measuredMenuHeight&&this.portalContainer&&(this.portalContainer.style.position="absolute",this.portalContainer.style.visibility="hidden",this.portalContainer.style.top="0px",this.portalContainer.style.left="0px",this.portalContainer.offsetHeight,this.measuredMenuHeight=this.portalContainer.offsetHeight,this.portalContainer.style.visibility="")}async computeFloatingUIPosition(){if(!this.portalContainer)return;const e=this.component.inputElement||this.component,t=this.portalContainer;try{const{x:i,y:M,placement:n,middlewareData:o}=await this.calculateFloatingUIPosition(e,t);this.applyFloatingUIPosition(t,e,i,M,n,o)}catch(e){console.warn("Floating UI positioning failed, falling back to simple positioning:",e),this.fallbackPositioning()}}async calculateFloatingUIPosition(e,t){const i=ln.findBoundaryElements(e),M="top"===ln.getOptimalPlacement(e)?"top-start":"bottom-start",n=this.createFloatingUIMiddleware(i);return await Ji(e,t,{placement:M,strategy:"fixed",middleware:n,platform:this.createCustomPlatform()})}createFloatingUIMiddleware(e){return[Bi(4),Fi({apply:this.handleSizeMiddleware.bind(this),padding:10,boundary:e}),_i({fallbackPlacements:["bottom-start","top-start","bottom","top","bottom-end","top-end"],fallbackStrategy:"bestFit",padding:10,boundary:e}),Gi({padding:10,crossAxis:!0,boundary:e})]}handleSizeMiddleware({availableWidth:e,availableHeight:t,elements:i,rects:M}){const n=ln.calculateOptimalHeight(M.reference,window.innerHeight,this.currentPlacement);i.floating.style.maxHeight=`${n}px`,i.floating.style.setProperty("--auto-size-available-width",`${e}px`),i.floating.style.setProperty("--auto-size-available-height",`${n}px`)}createCustomPlatform(){return Wi}applyFloatingUIPosition(e,t,i,M,n,o){const r=t.getBoundingClientRect();Object.assign(e.style,{left:`${r.left}px`,top:`${M}px`,position:"fixed",pointerEvents:"auto",width:"auto",minWidth:"auto"}),this.currentPlacement=n,this.currentMiddlewareData=o,ln.applyCollisionData(e,o,n);const s=n.split("-")[0];e.className=`nile-auto-complete-portal-append menu__listbox--${s}`}fallbackPositioning(){if(!this.portalContainer)return;const e=(this.component.inputElement||this.component).getBoundingClientRect(),t=window.innerHeight;this.measuredMenuHeight;const i=t-e.bottom,M=e.top;let n,o,r;M>i?(r=Math.max(M-20,100),n=Math.max(e.top-r-4,10),o="top"):(r=Math.max(i-20,100),n=e.bottom+4,o="bottom"),this.portalContainer.style.left=`${e.left}px`,this.portalContainer.style.top=`${n}px`,this.portalContainer.style.width="auto",this.portalContainer.style.minWidth="auto",this.portalContainer.style.maxHeight=`${r}px`,this.portalContainer.style.pointerEvents="auto",this.portalContainer.className=`nile-auto-complete-portal-append menu__listbox--${o}`,this.calculateAndSetAutoSizeProperties(e,n,o)}calculateAndSetAutoSizeProperties(e,t,i){if(!this.portalContainer)return;const M=window.innerHeight,n=window.innerWidth;let o;o="top"===i?e.top-10:M-e.bottom-10;const r=Math.min(e.width,n-e.left-10);this.portalContainer.style.setProperty("--auto-size-available-height",`${Math.max(o,100)}px`),this.portalContainer.style.setProperty("--auto-size-available-width",`${Math.max(r,200)}px`)}updatePortalAppendPosition(){this.component.portal&&this.portalContainer&&this.positionPortalAppend()}handleWindowResize(){this.component.portal&&this.portalContainer&&this.positionPortalAppend()}setupAutoUpdatePositioning(){this.portalContainer&&this.component&&(this.cleanupAutoUpdatePositioning(),this.cleanupAutoUpdate=Ri(this.component,this.portalContainer,(()=>{this.computeFloatingUIPosition()}),{ancestorScroll:!0,ancestorResize:!0,elementResize:!0,layoutShift:!0,animationFrame:!0}))}cleanupAutoUpdatePositioning(){this.cleanupAutoUpdate&&(this.cleanupAutoUpdate(),this.cleanupAutoUpdate=null)}injectStylesToDocument(){if(!this.portalContainer)return;const e=ln.generateStyleId();if(document.getElementById(e))return;const t=this.component.constructor.styles;if(!t)return;const i=document.createElement("style");i.id=e,i.textContent=ln.extractStylesAsCSS(t),document.head.appendChild(i),this.portalContainer.__injectedStyleId=e}adoptStylesToPortalAppend(){this.portalContainer&&this.injectStylesToDocument()}setupPortalAppend(){this.component.portal&&this.component.updateComplete.then((()=>{setTimeout((()=>{const e=this.component.shadowRoot?.querySelector("#content-menu")||this.component.querySelector("#content-menu");e&&this.component.isDropdownOpen&&(this.originalMenuParent=e.parentElement,this.clonedMenu=this.createPortalMenu(),this.portalContainer=this.createPortalAppendContainer(),this.portalContainer.appendChild(this.clonedMenu),document.body.appendChild(this.portalContainer),this.adoptStylesToPortalAppend(),this.clonedMenu.style.display="",this.positionPortalAppend(),this.setupPortalEventListeners(),this.setupAutoUpdatePositioning(),window.addEventListener("resize",this.handleWindowResize.bind(this)))}),10)}))}createPortalMenu(){return Nn.createPortalMenu(this.component)}setupPortalEventListeners(){gn.setupPortalEventListeners(this.clonedMenu,this.component)}cleanupPortalAppend(){if(this.cleanupAutoUpdatePositioning(),this.portalContainer&&this.portalContainer.parentNode){const e=this.portalContainer.__injectedStyleId;if(e){const t=document.getElementById(e);t&&t.remove()}this.portalContainer.parentNode.removeChild(this.portalContainer)}window.removeEventListener("resize",this.handleWindowResize.bind(this)),this.portalContainer=null,this.originalMenuParent=null,this.clonedMenu=null,this.measuredMenuHeight=null,this.currentPlacement="bottom",this.currentMiddlewareData=null}get portalContainerElement(){return this.portalContainer}resetMeasuredHeight(){this.measuredMenuHeight=null}updatePortalOptions(){this.portalContainer&&this.clonedMenu&&(Nn.updatePortalMenuItems(this.clonedMenu,this.component),this.forceReposition())}forceReposition(){this.portalContainer&&this.computeFloatingUIPosition()}getCurrentPlacement(){return this.currentPlacement}getCurrentMiddlewareData(){return this.currentMiddlewareData}isUsingFloatingUI(){return null!==this.cleanupAutoUpdate}isPositioningOptimal(){if(!this.portalContainer||!this.currentMiddlewareData)return!0;const e=(this.component.inputElement||this.component).getBoundingClientRect(),t=window.innerHeight-e.bottom,i=e.top,M=this.currentPlacement.startsWith("top"),n=this.currentPlacement.startsWith("bottom");return!(M&&t>i)&&!(n&&i>t)}}let cn=class extends Re{constructor(){super(...arguments),this.disabled=!1,this.isDropdownOpen=!1,this.portal=!1,this.portalManager=new un(this),this.enableVirtualScroll=!1,this.openOnFocus=!1,this.value="",this.placeholder="Type here ..",this.noBorder=!1,this.noOutline=!1,this.noPadding=!1,this.loading=!1,this.filterFunction=(e,t)=>e.toLowerCase().includes(t.toLowerCase()),this.renderItemFunction=e=>e,this.allMenuItems=[],this.enableVisibilityEffect=!1,this.enableTabClose=!1,this.menuItems=[],this.handleWindowResize=()=>{this.portalManager.updatePortalAppendPosition()},this.handleWindowScroll=()=>{this.portalManager.updatePortalAppendPosition()}}async firstUpdated(e){super.firstUpdated?.(e),await this.updateComplete,console.log("AutoComplete target:",this.inputElement?.input),this.visibilityManager=new tM({host:this,target:this.inputElement.input,enableVisibilityEffect:this.enableVisibilityEffect,enableTabClose:this.enableTabClose,isOpen:()=>this.isDropdownOpen,onAnchorOutOfView:()=>{this.isDropdownOpen=!1,this.dropdownElement?.hide(),this.emit("nile-visibility-change",{visible:!1,reason:"anchor-out-of-view"})},onDocumentHidden:()=>{this.isDropdownOpen=!1,this.dropdownElement?.hide(),this.emit("nile-visibility-change",{visible:!1,reason:"document-hidden"})},emit:(e,t)=>this.emit(`nile-${e}`,t)})}connectedCallback(){super.connectedCallback(),this.renderItemFunction=e=>e,this.handleDocumentFocusIn=this.handleDocumentFocusIn.bind(this),this.handleDocumentMouseDown=this.handleDocumentMouseDown.bind(this),this.handleWindowResize=this.handleWindowResize.bind(this),this.handleWindowScroll=this.handleWindowScroll.bind(this)}disconnectedCallback(){super.disconnectedCallback(),this.removeOpenListeners(),this.visibilityManager?.cleanup(),this.portalManager.cleanupPortalAppend()}updated(e){super.updated(e),e.has("allMenuItems")&&(this.menuItems=this.applyFilter(this.allMenuItems,this.filterFunction),this.setVirtualMenuWidth(),this.portal&&this.isDropdownOpen&&this.portalManager.updatePortalOptions()),e.has("isDropdownOpen")&&(this.menuItems=this.applyFilter(this.allMenuItems,this.filterFunction),this.handleDropdownOpenChange()),e.has("value")&&(this.menuItems=this.applyFilter(this.allMenuItems,this.filterFunction),this.portal&&this.isDropdownOpen&&this.portalManager.updatePortalOptions()),e.has("portal")&&this.handlePortalChange()}handlePortalChange(){this.isDropdownOpen&&(this.portal?this.portalManager.setupPortalAppend():this.portalManager.cleanupPortalAppend())}handleDropdownOpenChange(){this.isDropdownOpen?(this.addOpenListeners(),this.visibilityManager?.setup(),this.portal&&this.portalManager.setupPortalAppend()):(this.removeOpenListeners(),this.visibilityManager?.cleanup(),this.portal&&this.portalManager.cleanupPortalAppend())}addOpenListeners(){document.addEventListener("focusin",this.handleDocumentFocusIn),document.addEventListener("mousedown",this.handleDocumentMouseDown),this.portal&&(window.addEventListener("resize",this.handleWindowResize),window.addEventListener("scroll",this.handleWindowScroll,!0))}removeOpenListeners(){document.removeEventListener("focusin",this.handleDocumentFocusIn),document.removeEventListener("mousedown",this.handleDocumentMouseDown),window.removeEventListener("resize",this.handleWindowResize),window.removeEventListener("scroll",this.handleWindowScroll,!0)}handleDocumentFocusIn(e){if(!this.isDropdownOpen)return;const t=e.composedPath(),i=t.includes(this),M=this.dropdownElement&&t.includes(this.dropdownElement),n=this.portal&&this.portalManager.portalContainerElement&&t.includes(this.portalManager.portalContainerElement);i||M||n||(this.isDropdownOpen=!1,this.dropdownElement?.hide())}handleDocumentMouseDown(e){if(!this.isDropdownOpen)return;const t=e.composedPath(),i=t.includes(this),M=this.dropdownElement&&t.includes(this.dropdownElement),n=this.portal&&this.portalManager.portalContainerElement&&t.includes(this.portalManager.portalContainerElement);i||M||n||(this.isDropdownOpen=!1,this.dropdownElement?.hide())}render(){const e=this.enableVirtualScroll?this.getVirtualizedContent():this.getContent();return R`
|
|
5744
|
+
`;let ln=class{static calculateAvailableSpace(e){const t=e.getBoundingClientRect(),i=window.innerHeight,M=i-t.bottom;return{spaceAbove:t.top,spaceBelow:M,viewportHeight:i}}static getOptimalPlacement(e){const{spaceAbove:t,spaceBelow:i}=this.calculateAvailableSpace(e);return i<200&&t>i?"top":"bottom"}static findBoundaryElements(e){const t=[];let i=e.parentElement;for(;i&&i!==document.body;){const e=window.getComputedStyle(i),M=e.overflow,n=e.overflowY,o=e.overflowX;"auto"!==M&&"scroll"!==M&&"auto"!==n&&"scroll"!==n&&"auto"!==o&&"scroll"!==o||t.push(i),(i.hasAttribute("data-floating-boundary")||i.classList.contains("floating-boundary")||i.classList.contains("scroll-container"))&&t.push(i),i=i.parentElement}return t.length>0?t:void 0}static calculateOptimalHeight(e,t,i){const M=t-(e.y+e.height),n=e.y;return n>M?Math.max(n-20,100):M>n?Math.max(M-20,100):Math.max(Math.min(n,M)-20,100)}static extractStylesAsCSS(e){return"string"==typeof e?e:Array.isArray(e)?e.map((e=>this.extractStylesAsCSS(e))).join("\n"):e&&"object"==typeof e&&e.cssText?e.cssText:""}static generateStyleId(){return`nile-auto-complete-styles-${Math.random().toString(36).substring(2,11)}`}static isPositioningOptimal(e,t){const{spaceAbove:i,spaceBelow:M}=this.calculateAvailableSpace(t),n=e.startsWith("top"),o=e.startsWith("bottom");return!(n&&M>i)&&!(o&&i>M)}static applyCollisionData(e,t,i){if(t.flip){const{overflows:M}=t.flip;if(e.setAttribute("data-placement",i),M&&M.length>0){const t=M.map((e=>e.placement)).join(",");e.setAttribute("data-overflow",t)}else e.removeAttribute("data-overflow")}if(t.shift){const{x:i,y:M}=t.shift;void 0===i||void 0===M||0===i&&0===M?e.removeAttribute("data-shift"):e.setAttribute("data-shift",`${i},${M}`)}if(t.size){const{availableWidth:i,availableHeight:M}=t.size;void 0!==i&&e.setAttribute("data-available-width",i.toString()),void 0!==M&&e.setAttribute("data-available-height",M.toString())}}},Nn=class{static createBaseMenu(e){const t=document.createElement("nile-menu");return t.id="content-menu",t.className=e.enableVirtualScroll?"virtualized__menu":"",e.enableVirtualScroll,t.setAttribute("exportparts","menu__items-wrapper:options__wrapper"),t}static addMenuItems(e,t){(t.menuItems||[]).forEach((i=>{const M=this.createMenuItem(i,t);e.appendChild(M)}))}static createMenuItem(e,t){const i=document.createElement("div"),M=t.getItemRenderFunction(e);return se(M,i),i.firstElementChild}static createPortalMenu(e){const t=this.createBaseMenu(e);return this.addMenuItems(t,e),t}static updatePortalMenuItems(e,t){if(!e)return;e.querySelectorAll("nile-menu-item").forEach((e=>e.remove())),this.addMenuItems(e,t)}},gn=class{static setupPortalEventListeners(e,t){e&&this.setupMenuSelectListeners(e,t)}static setupMenuSelectListeners(e,t){e&&e.addEventListener("nile-select",(e=>{const i=e;t.handleSelect&&t.handleSelect(i)}))}};class un{constructor(e){this.portalContainer=null,this.originalMenuParent=null,this.measuredMenuHeight=null,this.clonedMenu=null,this.cleanupAutoUpdate=null,this.currentPlacement="bottom",this.currentMiddlewareData=null,this.component=e}createPortalAppendContainer(){const e=document.createElement("div");return e.style.position="absolute",e.style.zIndex="9999",e.style.pointerEvents="none",e.style.width="auto",e.style.minWidth="auto",e.className="nile-auto-complete-portal-append",e}positionPortalAppend(){this.portalContainer&&this.component.dropdownElement&&(this.measureMenuHeight(),this.computeFloatingUIPosition())}measureMenuHeight(){!this.measuredMenuHeight&&this.portalContainer&&(this.portalContainer.style.position="absolute",this.portalContainer.style.visibility="hidden",this.portalContainer.style.top="0px",this.portalContainer.style.left="0px",this.portalContainer.offsetHeight,this.measuredMenuHeight=this.portalContainer.offsetHeight,this.portalContainer.style.visibility="")}async computeFloatingUIPosition(){if(!this.portalContainer)return;const e=this.component.inputElement||this.component,t=this.portalContainer;try{const{x:i,y:M,placement:n,middlewareData:o}=await this.calculateFloatingUIPosition(e,t);this.applyFloatingUIPosition(t,e,i,M,n,o)}catch(e){console.warn("Floating UI positioning failed, falling back to simple positioning:",e),this.fallbackPositioning()}}async calculateFloatingUIPosition(e,t){const i=ln.findBoundaryElements(e),M="top"===ln.getOptimalPlacement(e)?"top-start":"bottom-start",n=this.createFloatingUIMiddleware(i);return await Ji(e,t,{placement:M,strategy:"fixed",middleware:n,platform:this.createCustomPlatform()})}createFloatingUIMiddleware(e){return[Bi(4),Fi({apply:this.handleSizeMiddleware.bind(this),padding:10,boundary:e}),_i({fallbackPlacements:["bottom-start","top-start","bottom","top","bottom-end","top-end"],fallbackStrategy:"bestFit",padding:10,boundary:e}),Gi({padding:10,crossAxis:!0,boundary:e})]}handleSizeMiddleware({availableWidth:e,availableHeight:t,elements:i,rects:M}){const n=ln.calculateOptimalHeight(M.reference,window.innerHeight,this.currentPlacement);i.floating.style.maxHeight=`${n}px`,i.floating.style.setProperty("--auto-size-available-width",`${e}px`),i.floating.style.setProperty("--auto-size-available-height",`${n}px`)}createCustomPlatform(){return Wi}applyFloatingUIPosition(e,t,i,M,n,o){const r=t.getBoundingClientRect();Object.assign(e.style,{left:`${r.left}px`,top:`${M}px`,position:"fixed",pointerEvents:"auto",width:"auto",minWidth:"auto"}),this.currentPlacement=n,this.currentMiddlewareData=o,ln.applyCollisionData(e,o,n);const s=n.split("-")[0];e.className=`nile-auto-complete-portal-append menu__listbox--${s}`}fallbackPositioning(){if(!this.portalContainer)return;const e=(this.component.inputElement||this.component).getBoundingClientRect(),t=window.innerHeight;this.measuredMenuHeight;const i=t-e.bottom,M=e.top;let n,o,r;M>i?(r=Math.max(M-20,100),n=Math.max(e.top-r-4,10),o="top"):(r=Math.max(i-20,100),n=e.bottom+4,o="bottom"),this.portalContainer.style.left=`${e.left}px`,this.portalContainer.style.top=`${n}px`,this.portalContainer.style.width="auto",this.portalContainer.style.minWidth="auto",this.portalContainer.style.maxHeight=`${r}px`,this.portalContainer.style.pointerEvents="auto",this.portalContainer.className=`nile-auto-complete-portal-append menu__listbox--${o}`,this.calculateAndSetAutoSizeProperties(e,n,o)}calculateAndSetAutoSizeProperties(e,t,i){if(!this.portalContainer)return;const M=window.innerHeight,n=window.innerWidth;let o;o="top"===i?e.top-10:M-e.bottom-10;const r=Math.min(e.width,n-e.left-10);this.portalContainer.style.setProperty("--auto-size-available-height",`${Math.max(o,100)}px`),this.portalContainer.style.setProperty("--auto-size-available-width",`${Math.max(r,200)}px`)}updatePortalAppendPosition(){this.component.portal&&this.portalContainer&&this.positionPortalAppend()}handleWindowResize(){this.component.portal&&this.portalContainer&&this.positionPortalAppend()}setupAutoUpdatePositioning(){this.portalContainer&&this.component&&(this.cleanupAutoUpdatePositioning(),this.cleanupAutoUpdate=Ri(this.component,this.portalContainer,(()=>{this.computeFloatingUIPosition()}),{ancestorScroll:!0,ancestorResize:!0,elementResize:!0,layoutShift:!0,animationFrame:!0}))}cleanupAutoUpdatePositioning(){this.cleanupAutoUpdate&&(this.cleanupAutoUpdate(),this.cleanupAutoUpdate=null)}injectStylesToDocument(){if(!this.portalContainer)return;const e=ln.generateStyleId();if(document.getElementById(e))return;const t=this.component.constructor.styles;if(!t)return;const i=document.createElement("style");i.id=e,i.textContent=ln.extractStylesAsCSS(t),document.head.appendChild(i),this.portalContainer.__injectedStyleId=e}adoptStylesToPortalAppend(){this.portalContainer&&this.injectStylesToDocument()}setupPortalAppend(){this.component.portal&&this.component.updateComplete.then((()=>{setTimeout((()=>{const e=this.component.shadowRoot?.querySelector("#content-menu")||this.component.querySelector("#content-menu");e&&this.component.isDropdownOpen&&(this.originalMenuParent=e.parentElement,this.clonedMenu=this.createPortalMenu(),this.portalContainer=this.createPortalAppendContainer(),this.portalContainer.appendChild(this.clonedMenu),document.body.appendChild(this.portalContainer),this.adoptStylesToPortalAppend(),this.clonedMenu.style.display="",this.positionPortalAppend(),this.setupPortalEventListeners(),this.setupAutoUpdatePositioning(),window.addEventListener("resize",this.handleWindowResize.bind(this)))}),10)}))}createPortalMenu(){return Nn.createPortalMenu(this.component)}setupPortalEventListeners(){gn.setupPortalEventListeners(this.clonedMenu,this.component)}cleanupPortalAppend(){if(this.cleanupAutoUpdatePositioning(),this.portalContainer&&this.portalContainer.parentNode){const e=this.portalContainer.__injectedStyleId;if(e){const t=document.getElementById(e);t&&t.remove()}this.portalContainer.parentNode.removeChild(this.portalContainer)}window.removeEventListener("resize",this.handleWindowResize.bind(this)),this.portalContainer=null,this.originalMenuParent=null,this.clonedMenu=null,this.measuredMenuHeight=null,this.currentPlacement="bottom",this.currentMiddlewareData=null}get portalContainerElement(){return this.portalContainer}resetMeasuredHeight(){this.measuredMenuHeight=null}updatePortalOptions(){this.portalContainer&&this.clonedMenu&&(Nn.updatePortalMenuItems(this.clonedMenu,this.component),this.forceReposition())}forceReposition(){this.portalContainer&&this.computeFloatingUIPosition()}getCurrentPlacement(){return this.currentPlacement}getCurrentMiddlewareData(){return this.currentMiddlewareData}isUsingFloatingUI(){return null!==this.cleanupAutoUpdate}isPositioningOptimal(){if(!this.portalContainer||!this.currentMiddlewareData)return!0;const e=(this.component.inputElement||this.component).getBoundingClientRect(),t=window.innerHeight-e.bottom,i=e.top,M=this.currentPlacement.startsWith("top"),n=this.currentPlacement.startsWith("bottom");return!(M&&t>i)&&!(n&&i>t)}}let cn=class extends Re{constructor(){super(...arguments),this.disabled=!1,this.isDropdownOpen=!1,this.portal=!1,this.portalManager=new un(this),this.enableVirtualScroll=!1,this.openOnFocus=!1,this.value="",this.placeholder="Type here ..",this.noBorder=!1,this.noOutline=!1,this.noPadding=!1,this.loading=!1,this.filterFunction=(e,t)=>e.toLowerCase().includes(t.toLowerCase()),this.renderItemFunction=e=>e,this.allMenuItems=[],this.enableVisibilityEffect=!1,this.enableTabClose=!1,this.menuItems=[],this.handleWindowResize=()=>{this.portalManager.updatePortalAppendPosition()},this.handleWindowScroll=()=>{this.portalManager.updatePortalAppendPosition()}}async firstUpdated(e){await this.updateComplete,console.log("AutoComplete target:",this.inputElement?.input),this.visibilityManager=new tM({host:this,target:this.inputElement.input,enableVisibilityEffect:this.enableVisibilityEffect,enableTabClose:this.enableTabClose,isOpen:()=>this.isDropdownOpen,onAnchorOutOfView:()=>{this.isDropdownOpen=!1,this.dropdownElement?.hide(),this.emit("nile-visibility-change",{visible:!1,reason:"anchor-out-of-view"})},onDocumentHidden:()=>{this.isDropdownOpen=!1,this.dropdownElement?.hide(),this.emit("nile-visibility-change",{visible:!1,reason:"document-hidden"})},emit:(e,t)=>this.emit(`nile-${e}`,t)})}connectedCallback(){super.connectedCallback(),this.renderItemFunction=e=>e,this.handleDocumentFocusIn=this.handleDocumentFocusIn.bind(this),this.handleDocumentMouseDown=this.handleDocumentMouseDown.bind(this),this.handleWindowResize=this.handleWindowResize.bind(this),this.handleWindowScroll=this.handleWindowScroll.bind(this)}disconnectedCallback(){super.disconnectedCallback(),this.removeOpenListeners(),this.visibilityManager?.cleanup(),this.portalManager.cleanupPortalAppend()}updated(e){super.updated(e),e.has("allMenuItems")&&(this.menuItems=this.applyFilter(this.allMenuItems,this.filterFunction),this.setVirtualMenuWidth(),this.portal&&this.isDropdownOpen&&this.portalManager.updatePortalOptions()),e.has("isDropdownOpen")&&(this.menuItems=this.applyFilter(this.allMenuItems,this.filterFunction),this.handleDropdownOpenChange()),e.has("value")&&(this.menuItems=this.applyFilter(this.allMenuItems,this.filterFunction),this.portal&&this.isDropdownOpen&&this.portalManager.updatePortalOptions()),e.has("portal")&&this.handlePortalChange()}handlePortalChange(){this.isDropdownOpen&&(this.portal?this.portalManager.setupPortalAppend():this.portalManager.cleanupPortalAppend())}handleDropdownOpenChange(){this.isDropdownOpen?(this.addOpenListeners(),this.visibilityManager?.setup(),this.portal&&this.portalManager.setupPortalAppend()):(this.removeOpenListeners(),this.visibilityManager?.cleanup(),this.portal&&this.portalManager.cleanupPortalAppend())}addOpenListeners(){document.addEventListener("focusin",this.handleDocumentFocusIn),document.addEventListener("mousedown",this.handleDocumentMouseDown),this.portal&&(window.addEventListener("resize",this.handleWindowResize),window.addEventListener("scroll",this.handleWindowScroll,!0))}removeOpenListeners(){document.removeEventListener("focusin",this.handleDocumentFocusIn),document.removeEventListener("mousedown",this.handleDocumentMouseDown),window.removeEventListener("resize",this.handleWindowResize),window.removeEventListener("scroll",this.handleWindowScroll,!0)}handleDocumentFocusIn(e){if(!this.isDropdownOpen)return;const t=e.composedPath(),i=t.includes(this),M=this.dropdownElement&&t.includes(this.dropdownElement),n=this.portal&&this.portalManager.portalContainerElement&&t.includes(this.portalManager.portalContainerElement);i||M||n||(this.isDropdownOpen=!1,this.dropdownElement?.hide())}handleDocumentMouseDown(e){if(!this.isDropdownOpen)return;const t=e.composedPath(),i=t.includes(this),M=this.dropdownElement&&t.includes(this.dropdownElement),n=this.portal&&this.portalManager.portalContainerElement&&t.includes(this.portalManager.portalContainerElement);i||M||n||(this.isDropdownOpen=!1,this.dropdownElement?.hide())}render(){const e=this.enableVirtualScroll?this.getVirtualizedContent():this.getContent();return R`
|
|
5745
5745
|
<nile-dropdown class="nile-dropdown--input" ?open=${this.isDropdownOpen} noOpenOnCLick exportparts="input, base">
|
|
5746
5746
|
<nile-input class="nile-auto-complete--input"
|
|
5747
5747
|
?no-border=${this.noBorder}
|
|
@@ -5948,7 +5948,7 @@ class QM{constructor(e){this._element=null;const t=e??window;this._node=t,e&&(th
|
|
|
5948
5948
|
nile-auto-complete::part(base)::before {
|
|
5949
5949
|
box-shadow: none;
|
|
5950
5950
|
}
|
|
5951
|
-
`;let jn=class extends Re{constructor(){super(...arguments),this.hasSlotController=new Ye(this,"help-text","label"),this.tags=[],this.inputValue="",this.isDropdownOpen=!1,this.tooltips=[],this.warning=!1,this.noAutoComplete=!1,this.error=!1,this.success=!1,this.noDuplicates=!1,this.label="",this.tagVariant="",this.acceptUserInput=!1,this.clearable=!1,this.placeholder="type here...",this.readonly=!1,this.disabled=!1,this.portal=!1,this.enableVirtualScroll=!1,this.autoCompleteOptions=[],this.filteredAutoCompleteOptions=[],this.value=[],this.noWrap=!1,this.loading=!1,this.errorIndexes=[],this.helpText="",this.errorMessage="",this.filterFunction=(e,t)=>e.toLowerCase().includes(t.toLowerCase()),this.renderItemFunction=e=>e,this.enableVisibilityEffect=!1,this.enableTabClose=!1,this.showTooltip=!1,this.handleDocumentClick=e=>{e.composedPath().includes(this)||(this.isDropdownOpen=!1)}}static get styles(){return[Dn]}updated(e){if(super.updated(e),e.has("autoCompleteOptions")){let e=this.autoCompleteOptions;if("string"==typeof e)try{e=JSON.parse(e)}catch(t){e=[]}this.filteredAutoCompleteOptions=Array.isArray(e)?[...e]:[],this.noDuplicates&&(this.filteredAutoCompleteOptions=this.filteredAutoCompleteOptions.filter((e=>!this.value.includes(e))))}e.has("value")&&(this.tags=[...this.value],this.onTagsChanged()),e.has("tags")&&this.onTagsChanged()}async firstUpdated(e){
|
|
5951
|
+
`;let jn=class extends Re{constructor(){super(...arguments),this.hasSlotController=new Ye(this,"help-text","label"),this.tags=[],this.inputValue="",this.isDropdownOpen=!1,this.tooltips=[],this.warning=!1,this.noAutoComplete=!1,this.error=!1,this.success=!1,this.noDuplicates=!1,this.label="",this.tagVariant="",this.acceptUserInput=!1,this.clearable=!1,this.placeholder="type here...",this.readonly=!1,this.disabled=!1,this.portal=!1,this.enableVirtualScroll=!1,this.autoCompleteOptions=[],this.filteredAutoCompleteOptions=[],this.value=[],this.noWrap=!1,this.loading=!1,this.errorIndexes=[],this.helpText="",this.errorMessage="",this.filterFunction=(e,t)=>e.toLowerCase().includes(t.toLowerCase()),this.renderItemFunction=e=>e,this.enableVisibilityEffect=!1,this.enableTabClose=!1,this.showTooltip=!1,this.handleDocumentClick=e=>{e.composedPath().includes(this)||(this.isDropdownOpen=!1)}}static get styles(){return[Dn]}updated(e){if(super.updated(e),e.has("autoCompleteOptions")){let e=this.autoCompleteOptions;if("string"==typeof e)try{e=JSON.parse(e)}catch(t){e=[]}this.filteredAutoCompleteOptions=Array.isArray(e)?[...e]:[],this.noDuplicates&&(this.filteredAutoCompleteOptions=this.filteredAutoCompleteOptions.filter((e=>!this.value.includes(e))))}e.has("value")&&(this.tags=[...this.value],this.onTagsChanged()),e.has("tags")&&this.onTagsChanged()}async firstUpdated(e){await this.updateComplete;const t=this.noAutoComplete?this.renderRoot.querySelector("nile-input")?.input:this.autoComplete?.inputElement?.input||this.autoComplete?.inputElement;this.visibilityManager=new tM({host:this,target:t,enableVisibilityEffect:this.enableVisibilityEffect,enableTabClose:this.enableTabClose,isOpen:()=>this.isDropdownOpen,onAnchorOutOfView:()=>{this.isDropdownOpen=!1,this.autoComplete&&(this.autoComplete.isDropdownOpen=!1),this.emit("nile-visibility-change",{visible:!1,reason:"anchor-out-of-view"})},onDocumentHidden:()=>{this.isDropdownOpen=!1,this.autoComplete&&(this.autoComplete.isDropdownOpen=!1),this.emit("nile-visibility-change",{visible:!1,reason:"document-hidden"})},emit:(e,t)=>this.emit(`nile-${e}`,t)})}connectedCallback(){super.connectedCallback(),document.addEventListener("click",this.handleDocumentClick),this.noDuplicates&&(this.filteredAutoCompleteOptions=this.filteredAutoCompleteOptions.filter((e=>!this.value.includes(e)))),this.emit("nile-init")}disconnectedCallback(){super.disconnectedCallback(),this.visibilityManager?.cleanup(),document.removeEventListener("click",this.handleDocumentClick),this.emit("nile-destroy")}render(){const e=this.hasSlotController.test("label");this.hasSlotController.test("help-text");const t=!!this.label||!!e,i=!!this.helpText,M=!!this.errorMessage;return R`
|
|
5952
5952
|
<div
|
|
5953
5953
|
part="form-control"
|
|
5954
5954
|
class=${pe({"form-control":!0,"form-control--medium":!0,"form-control--has-label":t,"form-control--has-help-text":i,"nile-chip--disabled":this.disabled})}
|
|
@@ -9053,7 +9053,7 @@ box-shadow: none;
|
|
|
9053
9053
|
border: solid 1px var(--nile-colors-dark-200, var(--ng-colors-border-secondary-alt));
|
|
9054
9054
|
box-shadow: var(--nile-box-shadow-2, var(--ng-shadow-lg));
|
|
9055
9055
|
}
|
|
9056
|
-
`;class dp{static calculateAvailableSpace(e){const t=e.getBoundingClientRect(),i=window.innerHeight,M=window.innerWidth,n=i-t.bottom,o=t.top,r=M-t.right;return{spaceAbove:o,spaceBelow:n,spaceLeft:t.left,spaceRight:r,viewportHeight:i,viewportWidth:M}}static getOptimalPlacement(e){const{spaceAbove:t,spaceBelow:i,spaceLeft:M,spaceRight:n}=this.calculateAvailableSpace(e);return i>=200&&i>=t?"bottom":t>=200&&t>i?"top":n>=200&&n>=M?"right":M>=200?"left":"bottom"}static findBoundaryElements(e){const t=[];let i=e.parentElement;for(;i&&i!==document.body;){const e=window.getComputedStyle(i),M=e.overflow,n=e.overflowY,o=e.overflowX;"auto"!==M&&"scroll"!==M&&"auto"!==n&&"scroll"!==n&&"auto"!==o&&"scroll"!==o||t.push(i),(i.hasAttribute("data-floating-boundary")||i.classList.contains("floating-boundary")||i.classList.contains("scroll-container"))&&t.push(i),i=i.parentElement}return t.length>0?t:void 0}static calculateOptimalHeight(e,t,i){const M=t-(e.y+e.height),n=e.y;return i.startsWith("top")?Math.max(n-20,100):i.startsWith("bottom")?Math.max(M-20,100):(i.startsWith("left")||i.startsWith("right"),Math.max(Math.min(n,M)-20,100))}static extractStylesAsCSS(e){return"string"==typeof e?e:Array.isArray(e)?e.map((e=>this.extractStylesAsCSS(e))).join("\n"):e&&"object"==typeof e&&e.cssText?e.cssText:""}static generateStyleId(){return`nile-popover-styles-${Math.random().toString(36).substring(2,11)}`}static isPositioningOptimal(e,t){const{spaceAbove:i,spaceBelow:M,spaceLeft:n,spaceRight:o}=this.calculateAvailableSpace(t),r=e.startsWith("top"),s=e.startsWith("bottom"),a=e.startsWith("left"),l=e.startsWith("right");return!(r&&M>i)&&(!(s&&i>M)&&(!(a&&o>n)&&!(l&&n>o)))}static applyCollisionData(e,t,i){if(t.flip){const{overflows:M}=t.flip;if(e.setAttribute("data-placement",i),M&&M.length>0){const t=M.map((e=>e.placement)).join(",");e.setAttribute("data-overflow",t)}else e.removeAttribute("data-overflow")}if(t.shift){const{x:i,y:M}=t.shift;void 0===i||void 0===M||0===i&&0===M?e.removeAttribute("data-shift"):e.setAttribute("data-shift",`${i},${M}`)}if(t.size){const{availableWidth:i,availableHeight:M}=t.size;void 0!==i&&e.setAttribute("data-available-width",i.toString()),void 0!==M&&e.setAttribute("data-available-height",M.toString())}}}class hp{static createBasePopover(e){const t=document.createElement("div");return t.className="popover__box",t.setAttribute("part","popover"),t}static addTitleSection(e,t){if(!t.title)return;const i=document.createElement("div");i.className="popover__title",i.textContent=t.title,e.appendChild(i)}static addContentSection(e,t){const i=document.createElement("div");i.setAttribute("part","base"),i.style.display="contents";Array.from(t.children).forEach((e=>{const t=e.getAttribute("slot");if(!t||"anchor"!==t&&"title"!==t&&"action"!==t){const t=e.cloneNode(!0);i.appendChild(t)}})),e.appendChild(i)}static cloneContent(e,t){Array.from(e.childNodes).forEach((e=>{const i=e.cloneNode(!0);t.appendChild(i)})),Array.from(e.attributes).forEach((e=>{t.setAttribute(e.name,e.value)}))}static addActionSection(e,t){const i=document.createElement("div");i.className="popover__action";t.querySelectorAll('[slot="action"]').forEach((e=>{const t=e.cloneNode(!0);i.appendChild(t)})),e.appendChild(i)}static addArrowElement(e,t){const i=document.createElement("div");i.className="popup__arrow",i.setAttribute("part","arrow"),i.setAttribute("role","presentation"),e.appendChild(i)}static createPortalPopover(e){const t=this.createBasePopover(e);return this.addTitleSection(t,e),this.addContentSection(t,e),this.addActionSection(t,e),e.arrow&&this.addArrowElement(t,e),t}static updatePortalContent(e,t){if(!e)return;const i=e.querySelector(".popover__title");i&&t.title&&(i.textContent=t.title);const M=e.querySelector('[part="base"]');if(M){M.innerHTML="";Array.from(t.children).forEach((e=>{const t=e.getAttribute("slot");if(!t||"anchor"!==t&&"title"!==t&&"action"!==t){const t=e.cloneNode(!0);M.appendChild(t)}}))}const n=e.querySelector(".popover__action");if(n){n.innerHTML="";t.querySelectorAll('[slot="action"]').forEach((e=>{const t=e.cloneNode(!0);n.appendChild(t)}))}}}class Tp{static setupPortalEventListeners(e,t){e&&(this.setupClickListeners(e,t),this.setupContentListeners(e,t),this.setupActionListeners(e,t))}static setupClickListeners(e,t){e&&e.addEventListener("click",(e=>{e.stopPropagation()}))}static setupContentListeners(e,t){if(!e)return;const i=e.querySelector('[part="base"]');i&&(i.addEventListener("nile-click",(e=>{t.handleContentClick&&t.handleContentClick(e)})),i.addEventListener("nile-input",(e=>{t.handleContentInput&&t.handleContentInput(e)})),i.addEventListener("nile-change",(e=>{t.handleContentChange&&t.handleContentChange(e)})))}static setupActionListeners(e,t){if(!e)return;const i=e.querySelector(".popover__action");i&&(i.addEventListener("click",(e=>{const i=e.target;("BUTTON"===i.tagName||i.closest("button"))&&t.handleActionClick&&t.handleActionClick(e)})),i.addEventListener("nile-click",(e=>{t.handleActionClick&&t.handleActionClick(e)})))}static forwardEventToOriginal(e,t,i){const M=new CustomEvent(i,{bubbles:!0,cancelable:!0,detail:e.detail});t.dispatchEvent(M)}}class yp{constructor(e){this.portalContainer=null,this.measuredPopoverHeight=null,this.clonedPopover=null,this.cleanupAutoUpdate=null,this.currentPlacement="top",this.currentMiddlewareData=null,this.boundHandleWindowResize=null,this.component=e}createPortalAppendContainer(){const e=document.createElement("div");return e.style.position="absolute",e.style.zIndex="9999",e.style.pointerEvents="none",e.style.width="auto",e.style.maxWidth="none",e.style.minWidth="200px",e.className="nile-popover-portal-append",e}positionPortalAppend(){this.portalContainer&&this.component.isShow&&(this.measurePopoverHeight(),this.computeFloatingUIPosition())}measurePopoverHeight(){!this.measuredPopoverHeight&&this.portalContainer&&(this.portalContainer.style.position="absolute",this.portalContainer.style.visibility="hidden",this.portalContainer.style.top="0px",this.portalContainer.style.left="0px",this.portalContainer.offsetHeight,this.measuredPopoverHeight=this.portalContainer.offsetHeight,this.portalContainer.style.visibility="")}async computeFloatingUIPosition(){if(!this.portalContainer)return;const e=this.component.querySelector('[slot="anchor"]')||this.component,t=this.portalContainer;try{const{x:i,y:M,placement:n,middlewareData:o}=await this.calculateFloatingUIPosition(e,t);this.applyFloatingUIPosition(t,e,i,M,n,o)}catch(e){console.warn("Floating UI positioning failed, falling back to simple positioning:",e),this.fallbackPositioning()}}async calculateFloatingUIPosition(e,t){const i=dp.findBoundaryElements(e),M=this.getInitialPlacement(),n=this.createFloatingUIMiddleware(i);return await Ji(e,t,{placement:M,strategy:"fixed",middleware:n,platform:this.createCustomPlatform()})}getInitialPlacement(){return this.component.placement||"top"}createFloatingUIMiddleware(e){return[Bi(this.component.distance||18),_i({fallbackPlacements:this.getFallbackPlacements(),fallbackStrategy:"bestFit",padding:10,boundary:e}),Gi({padding:10,crossAxis:!0,boundary:e})]}getFallbackPlacements(){const e=this.component.placement||"top",t=[];return e.startsWith("top")?t.push("bottom","right","left","top-start","top-end","bottom-start","bottom-end"):e.startsWith("bottom")?t.push("top","right","left","bottom-start","bottom-end","top-start","top-end"):e.startsWith("left")?t.push("right","top","bottom","left-start","left-end","right-start","right-end"):e.startsWith("right")&&t.push("left","top","bottom","right-start","right-end","left-start","left-end"),t}createCustomPlatform(){return Wi}positionArrow(e,t,i){if(!this.component.arrow)return;const M=e.querySelector(".popup__arrow");if(!M)return;const n=t.getBoundingClientRect(),o=e.getBoundingClientRect();let r="",s="",a="",l="";switch(i.split("-")[0]){case"top":a="calc(var(--arrow-size-diagonal) * -1)",l=this.calculateArrowXPosition(n,o,i,18);break;case"bottom":r="calc(var(--arrow-size-diagonal) * -1)",l=this.calculateArrowXPosition(n,o,i,18);break;case"left":s="calc(var(--arrow-size-diagonal) * -1)",r=this.calculateArrowYPosition(n,o,i,18);break;case"right":l="calc(var(--arrow-size-diagonal) * -1)",r=this.calculateArrowYPosition(n,o,i,18)}Object.assign(M.style,{top:r,right:s,bottom:a,left:l})}calculateArrowXPosition(e,t,i,M){const n=e.left+e.width/2-t.left-M;return i.includes("start")?`${M}px`:i.includes("end")?`calc(100% - ${2*M}px)`:`${Math.max(M,Math.min(n,t.width-2*M))}px`}calculateArrowYPosition(e,t,i,M){const n=e.top+e.height/2-t.top-M;return i.includes("start")?`${M}px`:i.includes("end")?`calc(100% - ${2*M}px)`:`${Math.max(M,Math.min(n,t.height-2*M))}px`}applyFloatingUIPosition(e,t,i,M,n,o){Object.assign(e.style,{left:`${i}px`,top:`${M}px`,position:"fixed",pointerEvents:"auto",width:"auto",maxWidth:"none",minWidth:"200px"}),this.currentPlacement=n,this.currentMiddlewareData=o,dp.applyCollisionData(e,o,n),e.className="nile-popover-portal-append";const r=t.getBoundingClientRect();e.style.minWidth=`${Math.max(r.width,200)}px`,this.positionArrow(e,t,n)}fallbackPositioning(){if(!this.portalContainer)return;const e=this.component.querySelector('[slot="anchor"]')||this.component,t=e.getBoundingClientRect(),i=window.innerHeight,M=window.innerWidth,n=i-t.bottom,o=t.top,r=M-t.right,s=t.left;let a,l,N,g=t.left;n>o&&n>200?(N=Math.max(n-20,100),a=t.bottom+(this.component.distance||18),l="bottom"):o>n&&o>200?(N=Math.max(o-20,100),a=Math.max(t.top-N-(this.component.distance||18),10),l="top"):r>s&&r>200?(N=Math.max(Math.min(r,n,o)-20,100),a=t.top,g=t.right+(this.component.distance||18),l="right"):(N=Math.max(Math.min(s,n,o)-20,100),a=t.top,g=Math.max(t.left-200-(this.component.distance||18),10),l="left"),"left"===l||"right"===l?(this.portalContainer.style.left=`${g}px`,this.portalContainer.style.top=`${a}px`):(this.portalContainer.style.left=`${t.left}px`,this.portalContainer.style.top=`${a}px`),this.portalContainer.style.maxHeight=`${N}px`,this.portalContainer.style.pointerEvents="auto",this.portalContainer.style.width="auto",this.portalContainer.style.maxWidth="none",this.portalContainer.style.minWidth="200px",this.portalContainer.className=`nile-popover-portal-append popover__box popover__box--${l}`,this.calculateAndSetAutoSizeProperties(t,a,l),this.positionArrow(this.portalContainer,e,l)}calculateAndSetAutoSizeProperties(e,t,i){if(!this.portalContainer)return;const M=window.innerHeight,n=window.innerWidth;let o,r=n-e.left-10;"top"===i?o=e.top-10:"bottom"===i?o=M-e.bottom-10:"left"===i?(o=Math.min(M-e.top,e.bottom),r=e.left-10):(o=Math.min(M-e.top,e.bottom),r=n-e.right-10),this.portalContainer.style.setProperty("--auto-size-available-height",`${Math.max(o,100)}px`),this.portalContainer.style.setProperty("--auto-size-available-width",`${Math.max(r,200)}px`)}updatePortalAppendPosition(){this.component.portal&&this.portalContainer&&this.positionPortalAppend()}handleWindowResize(){this.component.portal&&this.portalContainer&&this.positionPortalAppend()}setupAutoUpdatePositioning(){this.portalContainer&&this.component&&(this.cleanupAutoUpdatePositioning(),this.cleanupAutoUpdate=Ri(this.component,this.portalContainer,(()=>{this.computeFloatingUIPosition()}),{ancestorScroll:!0,ancestorResize:!0,elementResize:!0,layoutShift:!0,animationFrame:!0}))}cleanupAutoUpdatePositioning(){this.cleanupAutoUpdate&&(this.cleanupAutoUpdate(),this.cleanupAutoUpdate=null)}injectStylesToDocument(){if(!this.portalContainer)return;const e=dp.generateStyleId();if(document.getElementById(e))return;const t=this.component.constructor.styles;if(!t)return;const i=document.createElement("style");i.id=e,i.textContent=dp.extractStylesAsCSS(t),document.head.appendChild(i),this.portalContainer.__injectedStyleId=e}adoptStylesToPortalAppend(){this.portalContainer&&this.injectStylesToDocument()}setupPortalAppend(){this.component.portal&&this.component.updateComplete.then((()=>{setTimeout((()=>{this.component.isShow&&(this.clonedPopover=this.createPortalPopover(),this.portalContainer=this.createPortalAppendContainer(),this.portalContainer.appendChild(this.clonedPopover),document.body.appendChild(this.portalContainer),this.adoptStylesToPortalAppend(),this.clonedPopover.style.display="",this.positionPortalAppend(),this.setupPortalEventListeners(),this.setupAutoUpdatePositioning(),this.boundHandleWindowResize=this.handleWindowResize.bind(this),window.addEventListener("resize",this.boundHandleWindowResize))}),10)}))}createPortalPopover(){return hp.createPortalPopover(this.component)}setupPortalEventListeners(){Tp.setupPortalEventListeners(this.clonedPopover,this.component)}cleanupPortalAppend(){if(this.cleanupAutoUpdatePositioning(),this.portalContainer&&this.portalContainer.parentNode){const e=this.portalContainer.__injectedStyleId;if(e){const t=document.getElementById(e);t&&t.remove()}this.portalContainer.parentNode.removeChild(this.portalContainer)}this.boundHandleWindowResize&&(window.removeEventListener("resize",this.boundHandleWindowResize),this.boundHandleWindowResize=null),this.portalContainer=null,this.clonedPopover=null,this.measuredPopoverHeight=null,this.currentPlacement="top",this.currentMiddlewareData=null}get portalContainerElement(){return this.portalContainer}resetMeasuredHeight(){this.measuredPopoverHeight=null}forceReposition(){this.portalContainer&&this.computeFloatingUIPosition()}getCurrentPlacement(){return this.currentPlacement}getCurrentMiddlewareData(){return this.currentMiddlewareData}isUsingFloatingUI(){return null!==this.cleanupAutoUpdate}updatePositioningConfig(e){this.forceReposition()}handleViewportChange(){this.portalContainer&&(this.resetMeasuredHeight(),this.forceReposition())}isPositioningOptimal(){if(!this.portalContainer||!this.currentMiddlewareData)return!0;const e=(this.component.querySelector('[slot="anchor"]')||this.component).getBoundingClientRect(),t=window.innerHeight-e.bottom,i=e.top,M=this.currentPlacement.startsWith("top"),n=this.currentPlacement.startsWith("bottom");return!(M&&t>i)&&!(n&&i>t)}}let Ap=class extends Re{constructor(){super(...arguments),this.placement="top",this.distance=18,this.preventOverlayClose=!1,this.arrow=!0,this.title="",this.open=!1,this.isShow=!1,this.arrowPlacement="anchor",this.portalManager=null,this.enableVisibilityEffect=!1,this.enableTabClose=!1,this.hoist=!1,this.portal=!1,this.flip=!1,this.handleClick=()=>{this.isShow=!this.isShow;document.querySelectorAll("nile-popover").forEach((e=>{e!==this&&(e.isShow=!1)}))},this.handleDocumentClick=()=>{this.isShow&&!this.preventOverlayClose&&(this.isShow=!1)}}static get styles(){return[zp]}connectedCallback(){super.connectedCallback(),this.emit("nile-init"),document.addEventListener("click",this.handleDocumentClick),requestAnimationFrame((()=>{this.portal&&!this.portalManager&&(this.portalManager=new yp(this))}))}disconnectedCallback(){super.disconnectedCallback(),this.emit("nile-destroy"),this.visibilityManager?.cleanup(),document.removeEventListener("click",this.handleDocumentClick),this.portalManager&&(this.portalManager.cleanupPortalAppend(),this.portalManager=null)}async firstUpdated(e){super.firstUpdated?.(e),await this.updateComplete;const t=this.renderRoot.querySelector('slot[name="anchor"]'),i=t?.assignedElements({flatten:!0})[0];this.visibilityManager=new tM({host:this,target:i||null,enableVisibilityEffect:this.enableVisibilityEffect,enableTabClose:this.enableTabClose,isOpen:()=>this.isShow,onAnchorOutOfView:()=>{this.isShow=!1,this.emit("nile-visibility-change",{visible:!1,reason:"anchor-out-of-view"})},onDocumentHidden:()=>{this.isShow=!1,this.emit("nile-visibility-change",{visible:!1,reason:"document-hidden"})},emit:(e,t)=>this.emit(`nile-${e}`,t)})}updated(e){e.has("open")&&(this.isShow=this.open),e.has("portal")&&(this.portal&&!this.portalManager?this.portalManager=new yp(this):!this.portal&&this.portalManager&&(this.portalManager.cleanupPortalAppend(),this.portalManager=null))}handleShowHide(){this.isShow?(this.emit("nile-show"),this.visibilityManager?.setup(),this.portal&&this.portalManager?this.portalManager.setupPortalAppend():this.portal&&!this.portalManager&&(this.portalManager=new yp(this),this.portalManager.setupPortalAppend())):(this.emit("nile-hide"),this.visibilityManager?.cleanup(),this.portal&&this.portalManager&&this.portalManager.cleanupPortalAppend())}render(){const e=this.isShow&&!(this.portal&&this.portalManager);return R`
|
|
9056
|
+
`;class dp{static calculateAvailableSpace(e){const t=e.getBoundingClientRect(),i=window.innerHeight,M=window.innerWidth,n=i-t.bottom,o=t.top,r=M-t.right;return{spaceAbove:o,spaceBelow:n,spaceLeft:t.left,spaceRight:r,viewportHeight:i,viewportWidth:M}}static getOptimalPlacement(e){const{spaceAbove:t,spaceBelow:i,spaceLeft:M,spaceRight:n}=this.calculateAvailableSpace(e);return i>=200&&i>=t?"bottom":t>=200&&t>i?"top":n>=200&&n>=M?"right":M>=200?"left":"bottom"}static findBoundaryElements(e){const t=[];let i=e.parentElement;for(;i&&i!==document.body;){const e=window.getComputedStyle(i),M=e.overflow,n=e.overflowY,o=e.overflowX;"auto"!==M&&"scroll"!==M&&"auto"!==n&&"scroll"!==n&&"auto"!==o&&"scroll"!==o||t.push(i),(i.hasAttribute("data-floating-boundary")||i.classList.contains("floating-boundary")||i.classList.contains("scroll-container"))&&t.push(i),i=i.parentElement}return t.length>0?t:void 0}static calculateOptimalHeight(e,t,i){const M=t-(e.y+e.height),n=e.y;return i.startsWith("top")?Math.max(n-20,100):i.startsWith("bottom")?Math.max(M-20,100):(i.startsWith("left")||i.startsWith("right"),Math.max(Math.min(n,M)-20,100))}static extractStylesAsCSS(e){return"string"==typeof e?e:Array.isArray(e)?e.map((e=>this.extractStylesAsCSS(e))).join("\n"):e&&"object"==typeof e&&e.cssText?e.cssText:""}static generateStyleId(){return`nile-popover-styles-${Math.random().toString(36).substring(2,11)}`}static isPositioningOptimal(e,t){const{spaceAbove:i,spaceBelow:M,spaceLeft:n,spaceRight:o}=this.calculateAvailableSpace(t),r=e.startsWith("top"),s=e.startsWith("bottom"),a=e.startsWith("left"),l=e.startsWith("right");return!(r&&M>i)&&(!(s&&i>M)&&(!(a&&o>n)&&!(l&&n>o)))}static applyCollisionData(e,t,i){if(t.flip){const{overflows:M}=t.flip;if(e.setAttribute("data-placement",i),M&&M.length>0){const t=M.map((e=>e.placement)).join(",");e.setAttribute("data-overflow",t)}else e.removeAttribute("data-overflow")}if(t.shift){const{x:i,y:M}=t.shift;void 0===i||void 0===M||0===i&&0===M?e.removeAttribute("data-shift"):e.setAttribute("data-shift",`${i},${M}`)}if(t.size){const{availableWidth:i,availableHeight:M}=t.size;void 0!==i&&e.setAttribute("data-available-width",i.toString()),void 0!==M&&e.setAttribute("data-available-height",M.toString())}}}class hp{static createBasePopover(e){const t=document.createElement("div");return t.className="popover__box",t.setAttribute("part","popover"),t}static addTitleSection(e,t){if(!t.title)return;const i=document.createElement("div");i.className="popover__title",i.textContent=t.title,e.appendChild(i)}static addContentSection(e,t){const i=document.createElement("div");i.setAttribute("part","base"),i.style.display="contents";Array.from(t.children).forEach((e=>{const t=e.getAttribute("slot");if(!t||"anchor"!==t&&"title"!==t&&"action"!==t){const t=e.cloneNode(!0);i.appendChild(t)}})),e.appendChild(i)}static cloneContent(e,t){Array.from(e.childNodes).forEach((e=>{const i=e.cloneNode(!0);t.appendChild(i)})),Array.from(e.attributes).forEach((e=>{t.setAttribute(e.name,e.value)}))}static addActionSection(e,t){const i=document.createElement("div");i.className="popover__action";t.querySelectorAll('[slot="action"]').forEach((e=>{const t=e.cloneNode(!0);i.appendChild(t)})),e.appendChild(i)}static addArrowElement(e,t){const i=document.createElement("div");i.className="popup__arrow",i.setAttribute("part","arrow"),i.setAttribute("role","presentation"),e.appendChild(i)}static createPortalPopover(e){const t=this.createBasePopover(e);return this.addTitleSection(t,e),this.addContentSection(t,e),this.addActionSection(t,e),e.arrow&&this.addArrowElement(t,e),t}static updatePortalContent(e,t){if(!e)return;const i=e.querySelector(".popover__title");i&&t.title&&(i.textContent=t.title);const M=e.querySelector('[part="base"]');if(M){M.innerHTML="";Array.from(t.children).forEach((e=>{const t=e.getAttribute("slot");if(!t||"anchor"!==t&&"title"!==t&&"action"!==t){const t=e.cloneNode(!0);M.appendChild(t)}}))}const n=e.querySelector(".popover__action");if(n){n.innerHTML="";t.querySelectorAll('[slot="action"]').forEach((e=>{const t=e.cloneNode(!0);n.appendChild(t)}))}}}class Tp{static setupPortalEventListeners(e,t){e&&(this.setupClickListeners(e,t),this.setupContentListeners(e,t),this.setupActionListeners(e,t))}static setupClickListeners(e,t){e&&e.addEventListener("click",(e=>{e.stopPropagation()}))}static setupContentListeners(e,t){if(!e)return;const i=e.querySelector('[part="base"]');i&&(i.addEventListener("nile-click",(e=>{t.handleContentClick&&t.handleContentClick(e)})),i.addEventListener("nile-input",(e=>{t.handleContentInput&&t.handleContentInput(e)})),i.addEventListener("nile-change",(e=>{t.handleContentChange&&t.handleContentChange(e)})))}static setupActionListeners(e,t){if(!e)return;const i=e.querySelector(".popover__action");i&&(i.addEventListener("click",(e=>{const i=e.target;("BUTTON"===i.tagName||i.closest("button"))&&t.handleActionClick&&t.handleActionClick(e)})),i.addEventListener("nile-click",(e=>{t.handleActionClick&&t.handleActionClick(e)})))}static forwardEventToOriginal(e,t,i){const M=new CustomEvent(i,{bubbles:!0,cancelable:!0,detail:e.detail});t.dispatchEvent(M)}}class yp{constructor(e){this.portalContainer=null,this.measuredPopoverHeight=null,this.clonedPopover=null,this.cleanupAutoUpdate=null,this.currentPlacement="top",this.currentMiddlewareData=null,this.boundHandleWindowResize=null,this.component=e}createPortalAppendContainer(){const e=document.createElement("div");return e.style.position="absolute",e.style.zIndex="9999",e.style.pointerEvents="none",e.style.width="auto",e.style.maxWidth="none",e.style.minWidth="200px",e.className="nile-popover-portal-append",e}positionPortalAppend(){this.portalContainer&&this.component.isShow&&(this.measurePopoverHeight(),this.computeFloatingUIPosition())}measurePopoverHeight(){!this.measuredPopoverHeight&&this.portalContainer&&(this.portalContainer.style.position="absolute",this.portalContainer.style.visibility="hidden",this.portalContainer.style.top="0px",this.portalContainer.style.left="0px",this.portalContainer.offsetHeight,this.measuredPopoverHeight=this.portalContainer.offsetHeight,this.portalContainer.style.visibility="")}async computeFloatingUIPosition(){if(!this.portalContainer)return;const e=this.component.querySelector('[slot="anchor"]')||this.component,t=this.portalContainer;try{const{x:i,y:M,placement:n,middlewareData:o}=await this.calculateFloatingUIPosition(e,t);this.applyFloatingUIPosition(t,e,i,M,n,o)}catch(e){console.warn("Floating UI positioning failed, falling back to simple positioning:",e),this.fallbackPositioning()}}async calculateFloatingUIPosition(e,t){const i=dp.findBoundaryElements(e),M=this.getInitialPlacement(),n=this.createFloatingUIMiddleware(i);return await Ji(e,t,{placement:M,strategy:"fixed",middleware:n,platform:this.createCustomPlatform()})}getInitialPlacement(){return this.component.placement||"top"}createFloatingUIMiddleware(e){return[Bi(this.component.distance||18),_i({fallbackPlacements:this.getFallbackPlacements(),fallbackStrategy:"bestFit",padding:10,boundary:e}),Gi({padding:10,crossAxis:!0,boundary:e})]}getFallbackPlacements(){const e=this.component.placement||"top",t=[];return e.startsWith("top")?t.push("bottom","right","left","top-start","top-end","bottom-start","bottom-end"):e.startsWith("bottom")?t.push("top","right","left","bottom-start","bottom-end","top-start","top-end"):e.startsWith("left")?t.push("right","top","bottom","left-start","left-end","right-start","right-end"):e.startsWith("right")&&t.push("left","top","bottom","right-start","right-end","left-start","left-end"),t}createCustomPlatform(){return Wi}positionArrow(e,t,i){if(!this.component.arrow)return;const M=e.querySelector(".popup__arrow");if(!M)return;const n=t.getBoundingClientRect(),o=e.getBoundingClientRect();let r="",s="",a="",l="";switch(i.split("-")[0]){case"top":a="calc(var(--arrow-size-diagonal) * -1)",l=this.calculateArrowXPosition(n,o,i,18);break;case"bottom":r="calc(var(--arrow-size-diagonal) * -1)",l=this.calculateArrowXPosition(n,o,i,18);break;case"left":s="calc(var(--arrow-size-diagonal) * -1)",r=this.calculateArrowYPosition(n,o,i,18);break;case"right":l="calc(var(--arrow-size-diagonal) * -1)",r=this.calculateArrowYPosition(n,o,i,18)}Object.assign(M.style,{top:r,right:s,bottom:a,left:l})}calculateArrowXPosition(e,t,i,M){const n=e.left+e.width/2-t.left-M;return i.includes("start")?`${M}px`:i.includes("end")?`calc(100% - ${2*M}px)`:`${Math.max(M,Math.min(n,t.width-2*M))}px`}calculateArrowYPosition(e,t,i,M){const n=e.top+e.height/2-t.top-M;return i.includes("start")?`${M}px`:i.includes("end")?`calc(100% - ${2*M}px)`:`${Math.max(M,Math.min(n,t.height-2*M))}px`}applyFloatingUIPosition(e,t,i,M,n,o){Object.assign(e.style,{left:`${i}px`,top:`${M}px`,position:"fixed",pointerEvents:"auto",width:"auto",maxWidth:"none",minWidth:"200px"}),this.currentPlacement=n,this.currentMiddlewareData=o,dp.applyCollisionData(e,o,n),e.className="nile-popover-portal-append";const r=t.getBoundingClientRect();e.style.minWidth=`${Math.max(r.width,200)}px`,this.positionArrow(e,t,n)}fallbackPositioning(){if(!this.portalContainer)return;const e=this.component.querySelector('[slot="anchor"]')||this.component,t=e.getBoundingClientRect(),i=window.innerHeight,M=window.innerWidth,n=i-t.bottom,o=t.top,r=M-t.right,s=t.left;let a,l,N,g=t.left;n>o&&n>200?(N=Math.max(n-20,100),a=t.bottom+(this.component.distance||18),l="bottom"):o>n&&o>200?(N=Math.max(o-20,100),a=Math.max(t.top-N-(this.component.distance||18),10),l="top"):r>s&&r>200?(N=Math.max(Math.min(r,n,o)-20,100),a=t.top,g=t.right+(this.component.distance||18),l="right"):(N=Math.max(Math.min(s,n,o)-20,100),a=t.top,g=Math.max(t.left-200-(this.component.distance||18),10),l="left"),"left"===l||"right"===l?(this.portalContainer.style.left=`${g}px`,this.portalContainer.style.top=`${a}px`):(this.portalContainer.style.left=`${t.left}px`,this.portalContainer.style.top=`${a}px`),this.portalContainer.style.maxHeight=`${N}px`,this.portalContainer.style.pointerEvents="auto",this.portalContainer.style.width="auto",this.portalContainer.style.maxWidth="none",this.portalContainer.style.minWidth="200px",this.portalContainer.className=`nile-popover-portal-append popover__box popover__box--${l}`,this.calculateAndSetAutoSizeProperties(t,a,l),this.positionArrow(this.portalContainer,e,l)}calculateAndSetAutoSizeProperties(e,t,i){if(!this.portalContainer)return;const M=window.innerHeight,n=window.innerWidth;let o,r=n-e.left-10;"top"===i?o=e.top-10:"bottom"===i?o=M-e.bottom-10:"left"===i?(o=Math.min(M-e.top,e.bottom),r=e.left-10):(o=Math.min(M-e.top,e.bottom),r=n-e.right-10),this.portalContainer.style.setProperty("--auto-size-available-height",`${Math.max(o,100)}px`),this.portalContainer.style.setProperty("--auto-size-available-width",`${Math.max(r,200)}px`)}updatePortalAppendPosition(){this.component.portal&&this.portalContainer&&this.positionPortalAppend()}handleWindowResize(){this.component.portal&&this.portalContainer&&this.positionPortalAppend()}setupAutoUpdatePositioning(){this.portalContainer&&this.component&&(this.cleanupAutoUpdatePositioning(),this.cleanupAutoUpdate=Ri(this.component,this.portalContainer,(()=>{this.computeFloatingUIPosition()}),{ancestorScroll:!0,ancestorResize:!0,elementResize:!0,layoutShift:!0,animationFrame:!0}))}cleanupAutoUpdatePositioning(){this.cleanupAutoUpdate&&(this.cleanupAutoUpdate(),this.cleanupAutoUpdate=null)}injectStylesToDocument(){if(!this.portalContainer)return;const e=dp.generateStyleId();if(document.getElementById(e))return;const t=this.component.constructor.styles;if(!t)return;const i=document.createElement("style");i.id=e,i.textContent=dp.extractStylesAsCSS(t),document.head.appendChild(i),this.portalContainer.__injectedStyleId=e}adoptStylesToPortalAppend(){this.portalContainer&&this.injectStylesToDocument()}setupPortalAppend(){this.component.portal&&this.component.updateComplete.then((()=>{setTimeout((()=>{this.component.isShow&&(this.clonedPopover=this.createPortalPopover(),this.portalContainer=this.createPortalAppendContainer(),this.portalContainer.appendChild(this.clonedPopover),document.body.appendChild(this.portalContainer),this.adoptStylesToPortalAppend(),this.clonedPopover.style.display="",this.positionPortalAppend(),this.setupPortalEventListeners(),this.setupAutoUpdatePositioning(),this.boundHandleWindowResize=this.handleWindowResize.bind(this),window.addEventListener("resize",this.boundHandleWindowResize))}),10)}))}createPortalPopover(){return hp.createPortalPopover(this.component)}setupPortalEventListeners(){Tp.setupPortalEventListeners(this.clonedPopover,this.component)}cleanupPortalAppend(){if(this.cleanupAutoUpdatePositioning(),this.portalContainer&&this.portalContainer.parentNode){const e=this.portalContainer.__injectedStyleId;if(e){const t=document.getElementById(e);t&&t.remove()}this.portalContainer.parentNode.removeChild(this.portalContainer)}this.boundHandleWindowResize&&(window.removeEventListener("resize",this.boundHandleWindowResize),this.boundHandleWindowResize=null),this.portalContainer=null,this.clonedPopover=null,this.measuredPopoverHeight=null,this.currentPlacement="top",this.currentMiddlewareData=null}get portalContainerElement(){return this.portalContainer}resetMeasuredHeight(){this.measuredPopoverHeight=null}forceReposition(){this.portalContainer&&this.computeFloatingUIPosition()}getCurrentPlacement(){return this.currentPlacement}getCurrentMiddlewareData(){return this.currentMiddlewareData}isUsingFloatingUI(){return null!==this.cleanupAutoUpdate}updatePositioningConfig(e){this.forceReposition()}handleViewportChange(){this.portalContainer&&(this.resetMeasuredHeight(),this.forceReposition())}isPositioningOptimal(){if(!this.portalContainer||!this.currentMiddlewareData)return!0;const e=(this.component.querySelector('[slot="anchor"]')||this.component).getBoundingClientRect(),t=window.innerHeight-e.bottom,i=e.top,M=this.currentPlacement.startsWith("top"),n=this.currentPlacement.startsWith("bottom");return!(M&&t>i)&&!(n&&i>t)}}let Ap=class extends Re{constructor(){super(...arguments),this.placement="top",this.distance=18,this.preventOverlayClose=!1,this.arrow=!0,this.title="",this.open=!1,this.isShow=!1,this.arrowPlacement="anchor",this.portalManager=null,this.enableVisibilityEffect=!1,this.enableTabClose=!1,this.hoist=!1,this.portal=!1,this.flip=!1,this.handleClick=()=>{this.isShow=!this.isShow;document.querySelectorAll("nile-popover").forEach((e=>{e!==this&&(e.isShow=!1)}))},this.handleDocumentClick=()=>{this.isShow&&!this.preventOverlayClose&&(this.isShow=!1)}}static get styles(){return[zp]}connectedCallback(){super.connectedCallback(),this.emit("nile-init"),document.addEventListener("click",this.handleDocumentClick),requestAnimationFrame((()=>{this.portal&&!this.portalManager&&(this.portalManager=new yp(this))}))}disconnectedCallback(){super.disconnectedCallback(),this.emit("nile-destroy"),this.visibilityManager?.cleanup(),document.removeEventListener("click",this.handleDocumentClick),this.portalManager&&(this.portalManager.cleanupPortalAppend(),this.portalManager=null)}async firstUpdated(e){await this.updateComplete;const t=this.renderRoot.querySelector('slot[name="anchor"]'),i=t?.assignedElements({flatten:!0})[0];this.visibilityManager=new tM({host:this,target:i||null,enableVisibilityEffect:this.enableVisibilityEffect,enableTabClose:this.enableTabClose,isOpen:()=>this.isShow,onAnchorOutOfView:()=>{this.isShow=!1,this.emit("nile-visibility-change",{visible:!1,reason:"anchor-out-of-view"})},onDocumentHidden:()=>{this.isShow=!1,this.emit("nile-visibility-change",{visible:!1,reason:"document-hidden"})},emit:(e,t)=>this.emit(`nile-${e}`,t)})}updated(e){e.has("open")&&(this.isShow=this.open),e.has("portal")&&(this.portal&&!this.portalManager?this.portalManager=new yp(this):!this.portal&&this.portalManager&&(this.portalManager.cleanupPortalAppend(),this.portalManager=null))}handleShowHide(){this.isShow?(this.emit("nile-show"),this.visibilityManager?.setup(),this.portal&&this.portalManager?this.portalManager.setupPortalAppend():this.portal&&!this.portalManager&&(this.portalManager=new yp(this),this.portalManager.setupPortalAppend())):(this.emit("nile-hide"),this.visibilityManager?.cleanup(),this.portal&&this.portalManager&&this.portalManager.cleanupPortalAppend())}render(){const e=this.isShow&&!(this.portal&&this.portalManager);return R`
|
|
9057
9057
|
<nile-popup
|
|
9058
9058
|
active
|
|
9059
9059
|
.arrow="${this.arrow&&this.isShow&&!this.portal}"
|
|
@@ -14318,7 +14318,7 @@ nile-rte-toolbar-item nile-button[data-active]::part(base):hover {
|
|
|
14318
14318
|
|
|
14319
14319
|
|
|
14320
14320
|
|
|
14321
|
-
`,wS={bold:"format_bold",italic:"format_italic",underline:"format_underline",link:"link_2",left:"format_align_left",center:"format_align_middle",right:"format_align_right",justify:"format_align_justify",ul:"format_list_bulleted",ol:"format_list_numbered",clear:"format_clear"};let QS=class extends ae{constructor(){super(...arguments),this.value="",this.noStyles=!1,this.singleLineEditor=!1,this.placeholder="",this.mentions={},this.content="",this.previewEl=null,this.toolbarEl=null,this.lastRange=null,this.buttonMap=new Map,this.headingSelect=null,this.fontSelect=null,this.colorInput=null,this.bgColorInput=null,this.colorSwatchEl=null,this.bgSwatchEl=null,this.containerEl=null,this.mentionsEl=null,this.onEditorKeydown=e=>{if(this.singleLineEditor&&"Enter"===e.key&&e.shiftKey)return void e.preventDefault();if(e.ctrlKey&&"i"===e.key.toLowerCase()&&(e.preventDefault(),yS(this.editorEl,"em"),this.updateContent(),this.updateToolbarState()),this.singleLineEditor&&"Enter"===e.key)return void e.preventDefault();if("Tab"!==e.key)return;e.preventDefault(),this.focusAndRestore();const t=window.getSelection();if(!t||0===t.rangeCount)return;const i=t.getRangeAt(0);if(e.shiftKey){if(i.collapsed&&i.startContainer.nodeType===Node.TEXT_NODE){const e=i.startContainer,M=i.startOffset,n=e.data.slice(0,M),o=n.replace(/(\t|[ \u00a0]{2})$/,"");if(o.length!==n.length){e.data=o+e.data.slice(M);const i=document.createRange();i.setStart(e,o.length),i.collapse(!0),t.removeAllRanges(),t.addRange(i),this.updateContent(),this.updateToolbarState()}}return}i.deleteContents();const M=document.createTextNode("\t");i.insertNode(M);const n=document.createRange();n.setStartAfter(M),n.collapse(!0),t.removeAllRanges(),t.addRange(n),this.updateContent(),this.updateToolbarState()},this.onSelectionChange=()=>{if(!this.editorEl)return;const e=document.getSelection();if(!e||0===e.rangeCount)return;const t=e.getRangeAt(0);this.editorEl.contains(t.commonAncestorContainer)&&(this.lastRange=t.cloneRange(),this.updateToolbarState())}}createRenderRoot(){return this}injectCss(e){if(this.querySelector("style[data-rte-style]"))return;const t=document.createElement("style");t.setAttribute("data-rte-style","true"),t.textContent=e,this.insertBefore(t,this.firstChild)}connectedCallback(){super.connectedCallback(),this.injectCss(mS.cssText),this.ensureStructure(),this.placeholder&&this.editorEl&&(this.editorEl.dataset.placeholder=this.placeholder),this.value&&!this.editorEl.innerHTML.trim()&&(this.editorEl.innerHTML=this.value),this.content=this.editorEl.innerHTML,this.toolbarEl&&this.wireAuthoredToolbar(this.toolbarEl),this.mentionsEl=this.querySelector("nile-rte-mentions"),this.mentionsEl&&(this.mentionsEl.attach?.(this.editorEl,this),this.mentionsEl.setExternalConfig?.(this.mentions)),this.wireEditor(),document.addEventListener("selectionchange",this.onSelectionChange,{passive:!0}),this.updateToolbarState(),this.syncPreview()}ensureStructure(){this.toolbarEl=this.querySelector("nile-rte-toolbar"),this.previewEl=this.querySelector("nile-rte-preview"),this.containerEl=this.querySelector(".rte-container"),this.containerEl||(this.containerEl=document.createElement("div"),this.containerEl.className="rte-container",this.appendChild(this.containerEl)),this.ensureEditor(),this.toolbarEl&&this.toolbarEl.parentElement!==this.containerEl&&this.containerEl.appendChild(this.toolbarEl),this.editorEl.parentElement!==this.containerEl&&this.containerEl.appendChild(this.editorEl),this.previewEl&&(this.previewEl.parentElement!==this&&this.appendChild(this.previewEl),this.previewEl.previousElementSibling!==this.containerEl&&this.insertBefore(this.previewEl,this.containerEl.nextSibling))}updateContentWithMention(e){this.updateContent(),this.dispatchEvent(new CustomEvent("nile-change",{detail:{content:this.content,mention:e},bubbles:!0,composed:!0}))}disconnectedCallback(){document.removeEventListener("selectionchange",this.onSelectionChange),this.mentionsEl&&this.mentionsEl.detach&&this.mentionsEl.detach(),super.disconnectedCallback()}updated(e){e.has("value")&&this.editorEl&&this.value!==this.editorEl.innerHTML&&(this.editorEl.innerHTML=this.value||"<p><br></p>",this.content=this.editorEl.innerHTML,this.syncPreview()),e.has("singleLineEditor")&&(this.editorEl&&this.editorEl.classList.toggle("single-line",this.singleLineEditor),this.previewEl&&this.previewEl.classList.toggle("single-line",this.singleLineEditor))}ensureEditor(){if(this.editorEl=this.querySelector(".editor"),!this.editorEl){const e=document.createElement("article");e.className="editor",e.setAttribute("contenteditable","true"),this.editorEl=e}this.placeholder&&(this.editorEl.dataset.placeholder=this.placeholder),this.editorEl.innerHTML.trim()||(this.editorEl.innerHTML="<p><br></p>")}unwrapMention(e,t=!0){const i=e.parentNode;if(!i)return;const M=t?(e.textContent??"").replace(/\u200B/g,""):"",n=document.createTextNode(M);i.insertBefore(n,e),i.removeChild(e);const o=document.createRange();o.setStartAfter(n),o.collapse(!0);const r=window.getSelection();r?.removeAllRanges(),r?.addRange(o)}scrubBrokenMentions(){if(!this.editorEl)return;this.editorEl.querySelectorAll("span.mention").forEach((e=>{const t=e,i=t.getAttribute("data-mention-key"),M=t.getAttribute("data-mention-label"),n=t.getAttribute("data-mention-trigger")||"",o=(t.textContent??"").replace(/\u200B/g,"").trim(),r=!!i&&!!M&&o.length>0&&o.startsWith(n)&&o.includes(M);o&&r||this.unwrapMention(t,!0)}))}wireEditor(){this.editorEl.addEventListener("input",(()=>{this.ensureAtLeastOneParagraph(),this.scrubBrokenMentions(),this.updateContent(),this.updateToolbarState()})),this.editorEl.addEventListener("mouseup",(()=>{this.saveSelection(),this.updateToolbarState()})),this.editorEl.addEventListener("keyup",(e=>{this.saveSelection(),["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Home","End"].includes(e.key)&&this.updateToolbarState()})),this.editorEl.addEventListener("keydown",this.onEditorKeydown)}wireAuthoredToolbar(e){this.buttonMap.clear(),this.headingSelect=null,this.fontSelect=null,this.colorInput=null,Array.from(e.children).forEach((e=>{const t=e.tagName.toLowerCase();if("nile-rte-select"!==t||"align"!==e.getAttribute("type")){if("nile-rte-link"===t)return e.editorEl=this.editorEl,void e.addEventListener("link-changed",(()=>{this.updateContent(),this.updateToolbarState()}));if("nile-rte-toolbar-item"===t){let t=e.querySelector(":scope > nile-button");const i=e.getAttribute("name")||"",M=e.getAttribute("label")||i,n=e.getAttribute("icon"),o=e.innerHTML.trim().length>0;if(t||(t=document.createElement("nile-button"),t.variant="tertiary",t.size="small"),n)t.innerHTML=`<nile-icon name="${n}" aria-label="${M}"></nile-icon>`,e.innerHTML="";else if(o)t.innerHTML=e.innerHTML,e.innerHTML="";else{const n=wS[i];n?t.innerHTML=`<nile-icon name="${n}" size="20" color="black" aria-label="${M}"></nile-icon>`:t.textContent=M||i,e.innerHTML=""}if(!t.isConnected){const i=document.createElement("nile-tooltip");i.setAttribute("content",M),i.appendChild(t),e.appendChild(i)}t.setAttribute("aria-label",M),t.addEventListener("mousedown",(e=>e.preventDefault())),t.addEventListener("click",(()=>this.onToolbarCommand(i)));const r=this.buttonMap.get(i)??[];return r.push(t),void this.buttonMap.set(i,r)}if("nile-rte-select"!==t)"nile-rte-color"!==t||e.addEventListener("change",(e=>{this.focusAndRestore();const{mode:t,value:i}=e.detail;"backColor"===t?LS(this.editorEl,"backgroundColor",i,"data-rte-bg"):function(e,t){LS(e,"color",t,"data-rte-color")}(this.editorEl,i),this.updateContent(),this.updateToolbarState()}));else{const t=e.getAttribute("type")||"";e.addEventListener("change",(e=>{this.focusAndRestore();const i=e.detail;"heading"===t?function(e,t){const i=document.getSelection();if(!i||0===i.rangeCount)return;const M=hS(i.getRangeAt(0).startContainer,e);if(!M)return;if(M.tagName.toLowerCase()===t)return;const n=document.createElement(t);for(;M.firstChild;)n.appendChild(M.firstChild);M.replaceWith(n);const o=document.createRange();o.selectNodeContents(n),o.collapse(!0),i.removeAllRanges(),i.addRange(o)}(this.editorEl,i):"font"===t&&OS(this.editorEl,i),this.updateContent(),this.updateToolbarState()}))}}else e.addEventListener("change",(e=>{this.focusAndRestore();const t=e.detail;TS(this.editorEl,t),this.updateContent(),this.updateToolbarState()}))}))}saveSelection(){const e=window.getSelection();e&&e.rangeCount&&(this.lastRange=e.getRangeAt(0).cloneRange())}restoreSelection(){if(!this.lastRange)return;const e=document.getSelection();e&&(e.removeAllRanges(),e.addRange(this.lastRange))}focusAndRestore(){this.editorEl?.focus(),this.restoreSelection()}getCleanContent(){const e=this.editorEl.cloneNode(!0);return e.querySelectorAll("*").forEach((e=>{e.removeAttribute("style")})),e.innerHTML}insertList(e){if(this.restoreSelection(),!this.lastRange)return;const t=document.createElement(e),i=this.lastRange.extractContents(),M=document.createElement("div");M.appendChild(i),Array.from(M.childNodes).forEach((e=>{if(e.nodeType===Node.TEXT_NODE&&!e.textContent?.trim())return;const i=document.createElement("li");i.appendChild(e),t.appendChild(i)})),this.lastRange.insertNode(t),this.afterListEdit(t)}afterListEdit(e){const t=document.createRange();t.setStartAfter(e),t.collapse(!0);const i=window.getSelection();i?.removeAllRanges(),i?.addRange(t),this.saveSelection(),this.updateContent(),this.updateToolbarState()}ensureAtLeastOneParagraph(){const e=this.editorEl;if(!e)return;const t=""===(e.textContent??"").replace(/\u200B/g,"").trim();if(0===e.childNodes.length||t)return void(e.innerHTML="<p><br></p>");if(!e.querySelector("p,h1,h2,h3,h4,h5,h6,ul,ol,table,blockquote,pre")){const t=document.createElement("p");for(;e.firstChild;)t.appendChild(e.firstChild);return t.hasChildNodes()||t.appendChild(document.createElement("br")),void e.appendChild(t)}e.querySelectorAll("p").forEach((e=>{""===(e.textContent??"").replace(/\u200B/g,"")&&(e.innerHTML.toLowerCase().includes("<br")||(e.innerHTML="<br>"))}))}onToolbarCommand(e){switch(this.focusAndRestore(),e){case"bold":yS(this.editorEl,"strong");break;case"italic":yS(this.editorEl,"em");break;case"underline":yS(this.editorEl,"u");break;case"left":TS(this.editorEl,"left");break;case"center":TS(this.editorEl,"center");break;case"right":TS(this.editorEl,"right");break;case"justify":TS(this.editorEl,"justify");break;case"ul":ES(this.editorEl,"ul"),this.updateContent(),this.updateToolbarState();break;case"ol":ES(this.editorEl,"ol"),this.updateContent(),this.updateToolbarState();break;case"link":break;case"clear":const e=document.createTreeWalker(this.editorEl,NodeFilter.SHOW_ELEMENT),t=[];for(;e.nextNode();){const i=e.currentNode;i.removeAttribute("style"),["B","STRONG","I","EM","U","SPAN","FONT"].includes(i.tagName)&&t.push(i)}for(const e of t){for(;e.firstChild;)e.parentNode?.insertBefore(e.firstChild,e);e.remove()}this.ensureAtLeastOneParagraph()}this.updateContent(),this.updateToolbarState()}setBtnActive(e,t){const i=this.buttonMap.get(e);if(i)for(const e of i)e.toggleAttribute("data-active",!!t)}updateToolbarState(){if(!this.editorEl)return;const e=document.getSelection();if(!e||0===e.rangeCount)return;const t=e.getRangeAt(0);if(!this.editorEl.contains(t.commonAncestorContainer))return;const i=function(e){for(;e&&!(e instanceof HTMLElement);)e=e.parentNode;return e}(t.startContainer)||this.editorEl,M=getComputedStyle(i),n=hS(t.startContainer,this.editorEl)||this.editorEl,o=(()=>{let e=i;for(;e&&e!==this.editorEl;){if(e instanceof HTMLElement){const t=e.tagName.toLowerCase();if("strong"===t||"b"===t)return!0;const i=getComputedStyle(e).fontWeight;if(parseInt(i,10)>=600)return!0}e=e.parentNode}return!1})(),r=(()=>{let e=i;for(;e&&e!==this.editorEl;){if(e instanceof HTMLElement){const t=e.tagName.toLowerCase();if("em"===t||"i"===t)return!0;if("italic"===getComputedStyle(e).fontStyle)return!0}e=e.parentNode}return!1})(),s=(()=>{let e=i;for(;e&&e!==this.editorEl;){if(e instanceof HTMLElement){const t=getComputedStyle(e).textDecorationLine;if(t&&t.includes("underline"))return!0;if("u"===e.tagName.toLowerCase())return!0}e=e.parentNode}return!1})(),a=!!i.closest("a"),l=n.style.textAlign||getComputedStyle(n).textAlign||"start",N="start"===l?"left":l,g=!!i.closest("li")&&i.closest("ul,ol")?.tagName.toLowerCase()||"";if(this.setBtnActive("bold",o),this.setBtnActive("italic",r),this.setBtnActive("underline",s),this.setBtnActive("link",a),this.setBtnActive("left","left"===N&&!["center","right","justify"].includes(N)),this.setBtnActive("center","center"===N),this.setBtnActive("right","right"===N),this.setBtnActive("justify","justify"===N),this.setBtnActive("ul","ul"===g),this.setBtnActive("ol","ol"===g),this.headingSelect){const e=n.tagName.toLowerCase(),t=["h1","h2","h3"].includes(e)?e:"p";this.headingSelect.value!==t&&(this.headingSelect.value=t)}if(this.fontSelect){const e=(M.fontFamily||"").replace(/["']/g,"").split(",")[0].trim().toLowerCase();if(e)for(const t of Array.from(this.fontSelect.options))if(t.value.toLowerCase()===e){this.fontSelect.value=t.value;break}}if(this.colorInput){const e=AS(M.color);e&&this.colorInput.value.toLowerCase()!==e.toLowerCase()&&(this.colorInput.value=e),this.colorSwatchEl&&(this.colorSwatchEl.style.backgroundColor=this.colorInput.value)}if(this.bgColorInput){const e=getComputedStyle(i).backgroundColor;if(e&&!/transparent|rgba\(\s*0\s*,\s*0\s*,\s*0\s*,\s*0\s*\)/i.test(e)){const t=AS(e);t&&this.bgColorInput.value.toLowerCase()!==t.toLowerCase()&&(this.bgColorInput.value=t)}this.bgSwatchEl&&(this.bgSwatchEl.style.backgroundColor=this.bgColorInput.value)}}syncPreview(){this.updateContent()}updateContent(){if(!this.editorEl)return;this.ensureAtLeastOneParagraph();const e=""===(this.editorEl.textContent??"").trim();this.editorEl.classList.toggle("empty",e);const t=this.editorEl.cloneNode(!0);if(this.noStyles)t.querySelectorAll("[style]").forEach((e=>e.removeAttribute("style")));else{const e=document.createTreeWalker(this.editorEl,NodeFilter.SHOW_ELEMENT),i=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT),M=["font-weight","font-style","text-decoration","color","background-color","font-size","font-family","text-align","line-height","letter-spacing","white-space","vertical-align","list-style-position","padding-inline-start"];for(;e.nextNode()&&i.nextNode();){const t=e.currentNode,n=i.currentNode,o=window.getComputedStyle(t),r=M.map((e=>`${e}:${o.getPropertyValue(e)}`)).join(";");r.trim()&&n.setAttribute("style",r)}}this.content=t.innerHTML,this.previewEl&&(this.previewEl.innerHTML=this.content),this.dispatchEvent(new CustomEvent("nile-change",{detail:{content:this.content},bubbles:!0,composed:!0}))}};e([ce({type:String,attribute:!0,reflect:!0})],QS.prototype,"value",void 0),e([ce({type:Boolean,attribute:!0,reflect:!0})],QS.prototype,"noStyles",void 0),e([ce({type:Boolean,attribute:"singlelineeditor",reflect:!0})],QS.prototype,"singleLineEditor",void 0),e([ce({type:String})],QS.prototype,"placeholder",void 0),e([ce({attribute:"mentions",reflect:!0,converter:{fromAttribute:e=>{try{const t=JSON.parse(e),i={};for(const e of Object.keys(t)){const M=t[e];Array.isArray(M)&&(i[e]=M.filter((e=>e&&"string"==typeof e.key&&"string"==typeof e.label)).map((e=>({key:e.key,label:e.label}))))}return i}catch{return{}}},toAttribute:e=>JSON.stringify(e)}})],QS.prototype,"mentions",void 0),e([De()],QS.prototype,"content",void 0),QS=e([Ne("nile-rich-text-editor")],QS);"undefined"!=typeof window&&(window.nileElementsVersion='"1.3.0-beta-1.2"',window.nileVersion="__NILE_VERSION__",window.process=window.process||{env:{NODE_ENV:"production"}});const kS=r`
|
|
14321
|
+
`,wS={bold:"format_bold",italic:"format_italic",underline:"format_underline",link:"link_2",left:"format_align_left",center:"format_align_middle",right:"format_align_right",justify:"format_align_justify",ul:"format_list_bulleted",ol:"format_list_numbered",clear:"format_clear"};let QS=class extends ae{constructor(){super(...arguments),this.value="",this.noStyles=!1,this.singleLineEditor=!1,this.placeholder="",this.mentions={},this.content="",this.previewEl=null,this.toolbarEl=null,this.lastRange=null,this.buttonMap=new Map,this.headingSelect=null,this.fontSelect=null,this.colorInput=null,this.bgColorInput=null,this.colorSwatchEl=null,this.bgSwatchEl=null,this.containerEl=null,this.mentionsEl=null,this.onEditorKeydown=e=>{if(this.singleLineEditor&&"Enter"===e.key&&e.shiftKey)return void e.preventDefault();if(e.ctrlKey&&"i"===e.key.toLowerCase()&&(e.preventDefault(),yS(this.editorEl,"em"),this.updateContent(),this.updateToolbarState()),this.singleLineEditor&&"Enter"===e.key)return void e.preventDefault();if("Tab"!==e.key)return;e.preventDefault(),this.focusAndRestore();const t=window.getSelection();if(!t||0===t.rangeCount)return;const i=t.getRangeAt(0);if(e.shiftKey){if(i.collapsed&&i.startContainer.nodeType===Node.TEXT_NODE){const e=i.startContainer,M=i.startOffset,n=e.data.slice(0,M),o=n.replace(/(\t|[ \u00a0]{2})$/,"");if(o.length!==n.length){e.data=o+e.data.slice(M);const i=document.createRange();i.setStart(e,o.length),i.collapse(!0),t.removeAllRanges(),t.addRange(i),this.updateContent(),this.updateToolbarState()}}return}i.deleteContents();const M=document.createTextNode("\t");i.insertNode(M);const n=document.createRange();n.setStartAfter(M),n.collapse(!0),t.removeAllRanges(),t.addRange(n),this.updateContent(),this.updateToolbarState()},this.onSelectionChange=()=>{if(!this.editorEl)return;const e=document.getSelection();if(!e||0===e.rangeCount)return;const t=e.getRangeAt(0);this.editorEl.contains(t.commonAncestorContainer)&&(this.lastRange=t.cloneRange(),this.updateToolbarState())}}createRenderRoot(){return this}injectCss(e){if(this.querySelector("style[data-rte-style]"))return;const t=document.createElement("style");t.setAttribute("data-rte-style","true"),t.textContent=e,this.insertBefore(t,this.firstChild)}connectedCallback(){super.connectedCallback(),this.injectCss(mS.cssText),this.ensureStructure(),this.placeholder&&this.editorEl&&(this.editorEl.dataset.placeholder=this.placeholder),this.value&&!this.editorEl.innerHTML.trim()&&(this.editorEl.innerHTML=this.value),this.content=this.editorEl.innerHTML,this.toolbarEl&&this.wireAuthoredToolbar(this.toolbarEl),this.mentionsEl=this.querySelector("nile-rte-mentions"),this.mentionsEl&&(this.mentionsEl.attach?.(this.editorEl,this),this.mentionsEl.setExternalConfig?.(this.mentions)),this.wireEditor(),document.addEventListener("selectionchange",this.onSelectionChange,{passive:!0}),this.updateToolbarState(),this.syncPreview()}ensureStructure(){this.toolbarEl=this.querySelector("nile-rte-toolbar"),this.previewEl=this.querySelector("nile-rte-preview"),this.containerEl=this.querySelector(".rte-container"),this.containerEl||(this.containerEl=document.createElement("div"),this.containerEl.className="rte-container",this.appendChild(this.containerEl)),this.ensureEditor(),this.toolbarEl&&this.toolbarEl.parentElement!==this.containerEl&&this.containerEl.appendChild(this.toolbarEl),this.editorEl.parentElement!==this.containerEl&&this.containerEl.appendChild(this.editorEl),this.previewEl&&(this.previewEl.parentElement!==this&&this.appendChild(this.previewEl),this.previewEl.previousElementSibling!==this.containerEl&&this.insertBefore(this.previewEl,this.containerEl.nextSibling))}updateContentWithMention(e){this.updateContent(),this.dispatchEvent(new CustomEvent("nile-change",{detail:{content:this.content,mention:e},bubbles:!0,composed:!0}))}disconnectedCallback(){document.removeEventListener("selectionchange",this.onSelectionChange),this.mentionsEl&&this.mentionsEl.detach&&this.mentionsEl.detach(),super.disconnectedCallback()}updated(e){e.has("value")&&this.editorEl&&this.value!==this.editorEl.innerHTML&&(this.editorEl.innerHTML=this.value||"<p><br></p>",this.content=this.editorEl.innerHTML,this.syncPreview()),e.has("singleLineEditor")&&(this.editorEl&&this.editorEl.classList.toggle("single-line",this.singleLineEditor),this.previewEl&&this.previewEl.classList.toggle("single-line",this.singleLineEditor))}ensureEditor(){if(this.editorEl=this.querySelector(".editor"),!this.editorEl){const e=document.createElement("article");e.className="editor",e.setAttribute("contenteditable","true"),this.editorEl=e}this.placeholder&&(this.editorEl.dataset.placeholder=this.placeholder),this.editorEl.innerHTML.trim()||(this.editorEl.innerHTML="<p><br></p>")}unwrapMention(e,t=!0){const i=e.parentNode;if(!i)return;const M=t?(e.textContent??"").replace(/\u200B/g,""):"",n=document.createTextNode(M);i.insertBefore(n,e),i.removeChild(e);const o=document.createRange();o.setStartAfter(n),o.collapse(!0);const r=window.getSelection();r?.removeAllRanges(),r?.addRange(o)}scrubBrokenMentions(){if(!this.editorEl)return;this.editorEl.querySelectorAll("span.mention").forEach((e=>{const t=e,i=t.getAttribute("data-mention-key"),M=t.getAttribute("data-mention-label"),n=t.getAttribute("data-mention-trigger")||"",o=(t.textContent??"").replace(/\u200B/g,"").trim(),r=!!i&&!!M&&o.length>0&&o.startsWith(n)&&o.includes(M);o&&r||this.unwrapMention(t,!0)}))}wireEditor(){this.editorEl.addEventListener("input",(()=>{this.ensureAtLeastOneParagraph(),this.scrubBrokenMentions(),this.updateContent(),this.updateToolbarState()})),this.editorEl.addEventListener("mouseup",(()=>{this.saveSelection(),this.updateToolbarState()})),this.editorEl.addEventListener("keyup",(e=>{this.saveSelection(),["ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Home","End"].includes(e.key)&&this.updateToolbarState()})),this.editorEl.addEventListener("keydown",this.onEditorKeydown)}wireAuthoredToolbar(e){this.buttonMap.clear(),this.headingSelect=null,this.fontSelect=null,this.colorInput=null,Array.from(e.children).forEach((e=>{const t=e.tagName.toLowerCase();if("nile-rte-select"!==t||"align"!==e.getAttribute("type")){if("nile-rte-link"===t)return e.editorEl=this.editorEl,void e.addEventListener("link-changed",(()=>{this.updateContent(),this.updateToolbarState()}));if("nile-rte-toolbar-item"===t){let t=e.querySelector(":scope > nile-button");const i=e.getAttribute("name")||"",M=e.getAttribute("label")||i,n=e.getAttribute("icon"),o=e.innerHTML.trim().length>0;if(t||(t=document.createElement("nile-button"),t.variant="tertiary",t.size="small"),n)t.innerHTML=`<nile-icon name="${n}" aria-label="${M}"></nile-icon>`,e.innerHTML="";else if(o)t.innerHTML=e.innerHTML,e.innerHTML="";else{const n=wS[i];n?t.innerHTML=`<nile-icon name="${n}" size="20" color="black" aria-label="${M}"></nile-icon>`:t.textContent=M||i,e.innerHTML=""}if(!t.isConnected){const i=document.createElement("nile-tooltip");i.setAttribute("content",M),i.appendChild(t),e.appendChild(i)}t.setAttribute("aria-label",M),t.addEventListener("mousedown",(e=>e.preventDefault())),t.addEventListener("click",(()=>this.onToolbarCommand(i)));const r=this.buttonMap.get(i)??[];return r.push(t),void this.buttonMap.set(i,r)}if("nile-rte-select"!==t)"nile-rte-color"!==t||e.addEventListener("change",(e=>{this.focusAndRestore();const{mode:t,value:i}=e.detail;"backColor"===t?LS(this.editorEl,"backgroundColor",i,"data-rte-bg"):function(e,t){LS(e,"color",t,"data-rte-color")}(this.editorEl,i),this.updateContent(),this.updateToolbarState()}));else{const t=e.getAttribute("type")||"";e.addEventListener("change",(e=>{this.focusAndRestore();const i=e.detail;"heading"===t?function(e,t){const i=document.getSelection();if(!i||0===i.rangeCount)return;const M=hS(i.getRangeAt(0).startContainer,e);if(!M)return;if(M.tagName.toLowerCase()===t)return;const n=document.createElement(t);for(;M.firstChild;)n.appendChild(M.firstChild);M.replaceWith(n);const o=document.createRange();o.selectNodeContents(n),o.collapse(!0),i.removeAllRanges(),i.addRange(o)}(this.editorEl,i):"font"===t&&OS(this.editorEl,i),this.updateContent(),this.updateToolbarState()}))}}else e.addEventListener("change",(e=>{this.focusAndRestore();const t=e.detail;TS(this.editorEl,t),this.updateContent(),this.updateToolbarState()}))}))}saveSelection(){const e=window.getSelection();e&&e.rangeCount&&(this.lastRange=e.getRangeAt(0).cloneRange())}restoreSelection(){if(!this.lastRange)return;const e=document.getSelection();e&&(e.removeAllRanges(),e.addRange(this.lastRange))}focusAndRestore(){this.editorEl?.focus(),this.restoreSelection()}getCleanContent(){const e=this.editorEl.cloneNode(!0);return e.querySelectorAll("*").forEach((e=>{e.removeAttribute("style")})),e.innerHTML}insertList(e){if(this.restoreSelection(),!this.lastRange)return;const t=document.createElement(e),i=this.lastRange.extractContents(),M=document.createElement("div");M.appendChild(i),Array.from(M.childNodes).forEach((e=>{if(e.nodeType===Node.TEXT_NODE&&!e.textContent?.trim())return;const i=document.createElement("li");i.appendChild(e),t.appendChild(i)})),this.lastRange.insertNode(t),this.afterListEdit(t)}afterListEdit(e){const t=document.createRange();t.setStartAfter(e),t.collapse(!0);const i=window.getSelection();i?.removeAllRanges(),i?.addRange(t),this.saveSelection(),this.updateContent(),this.updateToolbarState()}ensureAtLeastOneParagraph(){const e=this.editorEl;if(!e)return;const t=""===(e.textContent??"").replace(/\u200B/g,"").trim();if(0===e.childNodes.length||t)return void(e.innerHTML="<p><br></p>");if(!e.querySelector("p,h1,h2,h3,h4,h5,h6,ul,ol,table,blockquote,pre")){const t=document.createElement("p");for(;e.firstChild;)t.appendChild(e.firstChild);return t.hasChildNodes()||t.appendChild(document.createElement("br")),void e.appendChild(t)}e.querySelectorAll("p").forEach((e=>{""===(e.textContent??"").replace(/\u200B/g,"")&&(e.innerHTML.toLowerCase().includes("<br")||(e.innerHTML="<br>"))}))}onToolbarCommand(e){switch(this.focusAndRestore(),e){case"bold":yS(this.editorEl,"strong");break;case"italic":yS(this.editorEl,"em");break;case"underline":yS(this.editorEl,"u");break;case"left":TS(this.editorEl,"left");break;case"center":TS(this.editorEl,"center");break;case"right":TS(this.editorEl,"right");break;case"justify":TS(this.editorEl,"justify");break;case"ul":ES(this.editorEl,"ul"),this.updateContent(),this.updateToolbarState();break;case"ol":ES(this.editorEl,"ol"),this.updateContent(),this.updateToolbarState();break;case"link":break;case"clear":const e=document.createTreeWalker(this.editorEl,NodeFilter.SHOW_ELEMENT),t=[];for(;e.nextNode();){const i=e.currentNode;i.removeAttribute("style"),["B","STRONG","I","EM","U","SPAN","FONT"].includes(i.tagName)&&t.push(i)}for(const e of t){for(;e.firstChild;)e.parentNode?.insertBefore(e.firstChild,e);e.remove()}this.ensureAtLeastOneParagraph()}this.updateContent(),this.updateToolbarState()}setBtnActive(e,t){const i=this.buttonMap.get(e);if(i)for(const e of i)e.toggleAttribute("data-active",!!t)}updateToolbarState(){if(!this.editorEl)return;const e=document.getSelection();if(!e||0===e.rangeCount)return;const t=e.getRangeAt(0);if(!this.editorEl.contains(t.commonAncestorContainer))return;const i=function(e){for(;e&&!(e instanceof HTMLElement);)e=e.parentNode;return e}(t.startContainer)||this.editorEl,M=getComputedStyle(i),n=hS(t.startContainer,this.editorEl)||this.editorEl,o=(()=>{let e=i;for(;e&&e!==this.editorEl;){if(e instanceof HTMLElement){const t=e.tagName.toLowerCase();if("strong"===t||"b"===t)return!0;const i=getComputedStyle(e).fontWeight;if(parseInt(i,10)>=600)return!0}e=e.parentNode}return!1})(),r=(()=>{let e=i;for(;e&&e!==this.editorEl;){if(e instanceof HTMLElement){const t=e.tagName.toLowerCase();if("em"===t||"i"===t)return!0;if("italic"===getComputedStyle(e).fontStyle)return!0}e=e.parentNode}return!1})(),s=(()=>{let e=i;for(;e&&e!==this.editorEl;){if(e instanceof HTMLElement){const t=getComputedStyle(e).textDecorationLine;if(t&&t.includes("underline"))return!0;if("u"===e.tagName.toLowerCase())return!0}e=e.parentNode}return!1})(),a=!!i.closest("a"),l=n.style.textAlign||getComputedStyle(n).textAlign||"start",N="start"===l?"left":l,g=!!i.closest("li")&&i.closest("ul,ol")?.tagName.toLowerCase()||"";if(this.setBtnActive("bold",o),this.setBtnActive("italic",r),this.setBtnActive("underline",s),this.setBtnActive("link",a),this.setBtnActive("left","left"===N&&!["center","right","justify"].includes(N)),this.setBtnActive("center","center"===N),this.setBtnActive("right","right"===N),this.setBtnActive("justify","justify"===N),this.setBtnActive("ul","ul"===g),this.setBtnActive("ol","ol"===g),this.headingSelect){const e=n.tagName.toLowerCase(),t=["h1","h2","h3"].includes(e)?e:"p";this.headingSelect.value!==t&&(this.headingSelect.value=t)}if(this.fontSelect){const e=(M.fontFamily||"").replace(/["']/g,"").split(",")[0].trim().toLowerCase();if(e)for(const t of Array.from(this.fontSelect.options))if(t.value.toLowerCase()===e){this.fontSelect.value=t.value;break}}if(this.colorInput){const e=AS(M.color);e&&this.colorInput.value.toLowerCase()!==e.toLowerCase()&&(this.colorInput.value=e),this.colorSwatchEl&&(this.colorSwatchEl.style.backgroundColor=this.colorInput.value)}if(this.bgColorInput){const e=getComputedStyle(i).backgroundColor;if(e&&!/transparent|rgba\(\s*0\s*,\s*0\s*,\s*0\s*,\s*0\s*\)/i.test(e)){const t=AS(e);t&&this.bgColorInput.value.toLowerCase()!==t.toLowerCase()&&(this.bgColorInput.value=t)}this.bgSwatchEl&&(this.bgSwatchEl.style.backgroundColor=this.bgColorInput.value)}}syncPreview(){this.updateContent()}updateContent(){if(!this.editorEl)return;this.ensureAtLeastOneParagraph();const e=""===(this.editorEl.textContent??"").trim();this.editorEl.classList.toggle("empty",e);const t=this.editorEl.cloneNode(!0);if(this.noStyles)t.querySelectorAll("[style]").forEach((e=>e.removeAttribute("style")));else{const e=document.createTreeWalker(this.editorEl,NodeFilter.SHOW_ELEMENT),i=document.createTreeWalker(t,NodeFilter.SHOW_ELEMENT),M=["font-weight","font-style","text-decoration","color","background-color","font-size","font-family","text-align","line-height","letter-spacing","white-space","vertical-align","list-style-position","padding-inline-start"];for(;e.nextNode()&&i.nextNode();){const t=e.currentNode,n=i.currentNode,o=window.getComputedStyle(t),r=M.map((e=>`${e}:${o.getPropertyValue(e)}`)).join(";");r.trim()&&n.setAttribute("style",r)}}this.content=t.innerHTML,this.previewEl&&(this.previewEl.innerHTML=this.content),this.dispatchEvent(new CustomEvent("nile-change",{detail:{content:this.content},bubbles:!0,composed:!0}))}};e([ce({type:String,attribute:!0,reflect:!0})],QS.prototype,"value",void 0),e([ce({type:Boolean,attribute:!0,reflect:!0})],QS.prototype,"noStyles",void 0),e([ce({type:Boolean,attribute:"singlelineeditor",reflect:!0})],QS.prototype,"singleLineEditor",void 0),e([ce({type:String})],QS.prototype,"placeholder",void 0),e([ce({attribute:"mentions",reflect:!0,converter:{fromAttribute:e=>{try{const t=JSON.parse(e),i={};for(const e of Object.keys(t)){const M=t[e];Array.isArray(M)&&(i[e]=M.filter((e=>e&&"string"==typeof e.key&&"string"==typeof e.label)).map((e=>({key:e.key,label:e.label}))))}return i}catch{return{}}},toAttribute:e=>JSON.stringify(e)}})],QS.prototype,"mentions",void 0),e([De()],QS.prototype,"content",void 0),QS=e([Ne("nile-rich-text-editor")],QS);"undefined"!=typeof window&&(window.nileElementsVersion='"1.3.0-beta-1.4"',window.nileVersion="__NILE_VERSION__",window.process=window.process||{env:{NODE_ENV:"production"}});const kS=r`
|
|
14322
14322
|
:host {
|
|
14323
14323
|
--sidebar-width: 240px;
|
|
14324
14324
|
--sidebar-collapsed-width: 70px;
|