smart-webcomponents-react
Version:
[](https://jqwidgets.com/license/)
6 lines (4 loc) • 66.5 kB
JavaScript
/* Smart UI v23.0.8 (2025-05-13)
Copyright (c) 2011-2024 jQWidgets.
License: https://htmlelements.com/license/ */ //
Smart("smart-tree-item",class extends Smart.MenuItem{static get properties(){return{selected:{value:!1,type:"boolean"}}}ready(){const e=this;Object.defineProperty(e,"hasStyleObserver",{get:function(){return!1}}),super.ready(),e.setAttribute("role","treeitem"),e.setAttribute("aria-label",e.label)}propertyChangedHandler(e,t,r){const n=this,o=n.menu;if(super.propertyChangedHandler(e,t,r),"level"===e)return void(n.level=t);if("disabled"===e||"separator"===e||!o)return;const l=o.context;switch(o.context=o,e){case"label":{const e=o.sorted&&o.autoSort;n.firstElementChild.firstElementChild.firstElementChild.innerHTML=r,e&&(o._unsortItems(o.$.mainContainer),o._applyGrouping(o.$.mainContainer)),o._state.filter&&o._applyFilter(o._state.filter),n.setAttribute("aria-label",r);break}case"selected":n.selected=t,r?o.select(n):o.unselect(n);break;case"shortcut":{let e=n.firstElementChild.children[1];e||(e=document.createElement("div"),e.className="smart-tree-item-shortcut",n.firstElementChild.appendChild(e)),e.innerHTML=r;break}case"value":o.sort&&o.sorted&&o.autoSort&&o._refreshSorting()}o.context=l}_setId(){}}),Smart("smart-tree-items-group",class extends Smart.MenuItemsGroup{static get properties(){return{selected:{value:!1,type:"boolean"}}}ready(){const e=this;Object.defineProperty(e,"hasStyleObserver",{get:function(){return!1}}),super.ready(),e.setAttribute("role","treeitem"),e.removeAttribute("aria-haspopup"),e.setAttribute("aria-label",e.label)}propertyChangedHandler(e,t,r){const n=this,o=n.menu;if(super.propertyChangedHandler(e,t,r),"level"===e)return void(n.level=t);if("disabled"===e||"separator"===e||!o)return;const l=o.context;switch(o.context=o,e){case"expanded":n.expanded=t,r?o.expandItem(n):o.collapseItem(n);break;case"label":{const e=o.sorted&&o.autoSort;n.firstElementChild.firstElementChild.firstElementChild.innerHTML=r,e&&(o._unsortItems(o.$.mainContainer),o._applyGrouping(o.$.mainContainer)),o._state.filter&&o._applyFilter(o._state.filter),n.setAttribute("aria-label",r);break}case"selected":n.selected=t,r?o.select(n):o.unselect(n);break;case"value":o.sort&&o.sorted&&o.autoSort&&o._refreshSorting()}o.context=l}_setId(){}}),Smart("smart-tree",class extends Smart.Menu{static get properties(){return{allowDrag:{value:!1,type:"boolean"},allowDrop:{value:!1,type:"boolean"},autoHideToggleElement:{value:!1,type:"boolean"},autoLoadState:{value:!1,type:"boolean"},autoSaveState:{value:!1,type:"boolean"},autoSort:{value:!0,type:"boolean"},displayLoadingIndicator:{value:!1,type:"boolean"},dragFeedbackFormatFunction:{value:null,type:"function?"},dragOffset:{value:[10,10],type:"array"},dropDownMode:{value:!1,type:"boolean",reflectToAttribute:!1},dropDownWidth:{value:300,type:"any",reflectToAttribute:!1},dropDownHeight:{value:500,type:"any",reflectToAttribute:!1},editable:{value:!1,type:"boolean"},expandMode:{value:"multiple",allowedValues:["multiple","single"],type:"string"},filterable:{value:!1,type:"boolean"},filterOnEnter:{value:!1,type:"boolean"},filterInputPlaceholder:{value:"",type:"string"},filterMember:{value:"label",type:"string"},filterMode:{value:"containsIgnoreCase",allowedValues:["contains","containsIgnoreCase","doesNotContain","doesNotContainIgnoreCase","equals","equalsIgnoreCase","startsWith","startsWithIgnoreCase","endsWith","endsWithIgnoreCase"],type:"string"},hasThreeStates:{value:!1,type:"boolean"},loadingIndicatorPlaceholder:{value:"Loading...",type:"string"},loadingIndicatorPosition:{value:"center",allowedValues:["bottom","center","top"],type:"string"},messages:{value:{en:{noId:"smart-tree: Saving and loading the element's state are not available if the element has no id.",dropDownPlaceholder:"Please select..."}},type:"object",extend:!0},scrollMode:{value:"scrollbar",allowedValues:["scrollbar","scrollButtons"],type:"string"},selectedIndexes:{value:[],type:"array"},selectionDisplayMode:{value:"row",allowedValues:["row","label"],type:"string"},selectionMode:{value:"one",allowedValues:["none","oneOrManyExtended","zeroOrMany","oneOrMany","zeroOrOne","zeroAndOne","one","checkBox","radioButton"],type:"string"},selectionTarget:{value:"all",allowedValues:["all","leaf"],type:"string"},showLines:{value:!1,type:"boolean"},showRootLines:{value:!1,type:"boolean"},sort:{value:null,type:"function?",reflectToAttribute:!1},sortDirection:{value:"asc",allowedValues:["asc","desc"],type:"string"},sorted:{value:!1,type:"boolean"},toggleElementPosition:{value:"near",allowedValues:["near","far"],type:"string"},toggleMode:{value:"dblclick",allowedValues:["click","dblclick","arrow"],type:"string"}}}static get listeners(){return{blur:"_blurHandler",focus:"_focusHandler",keydown:"_keydownHandler",mouseenter:"_mouseenterHandler",mouseleave:"_mouseleaveHandler",resize:"_checkOverflow",styleChanged:"_styleChangedHandler",transitionend:"_overriddenMenuHandler","container.click":"_overriddenMenuHandler","container.mouseout":"_overriddenMenuHandler","container.mouseover":"_overriddenMenuHandler","container.pointerover":"_pointeroverHandler","editInput.blur":"_editInputBlurHandler","filterInput.keydown":"_filterInputKeydownHandler","filterInput.keyup":"_filterInputKeyupHandler","mainContainer.click":"_overriddenMenuHandler","mainContainer.mouseleave":"_overriddenMenuHandler","mainContainer.mouseout":"_overriddenMenuHandler","mainContainer.mouseover":"_overriddenMenuHandler","mainContainer.swipeleft":"_mainContainerSwipeHandler","mainContainer.swiperight":"_mainContainerSwipeHandler","scrollButtonFar.click":"_scrollButtonFarClickHandler","scrollButtonNear.click":"_scrollButtonNearClickHandler","scrollViewer.down":"_scrollViewerDownHandler","scrollViewer.kineticScroll":"_scrollViewerWheelHandler","scrollViewer.touchmove":"_scrollViewerTouchmoveHandler","mainContainer.wheel":"_scrollViewerWheelHandler","document.move":"_moveHandler","document.selectstart":"_selectstartHandler","document.up":"_documentUpHandler"}}static get requires(){return{"Smart.ScrollBar":"smart.scrollbar.js"}}static get styleUrls(){return["smart.scrollbar.css","smart.scrollviewer.css","smart.tree.css"]}template(){return'<div id="container" role="presentation">\n <div class="smart-tree-filter-input-container" role="presentation"><input id="filterInput" class="smart-filter-input" disabled="[[disabled]]" placeholder="[[filterInputPlaceholder]]" type="text" role="searchbox" aria-label="[[filterInputPlaceholder]]" /></div>\n <smart-repeat-button id="scrollButtonNear" class="smart-tree-scroll-button smart-spin-button smart-scroll-button-near smart-hidden" animation="[[animation]]" unfocusable aria-label="Scroll up">\n <div id="arrowNear" class="smart-arrow smart-arrow-up"></div>\n </smart-repeat-button>\n <smart-scroll-viewer id="scrollViewer" animation="[[animation]]" horizontal-scroll-bar-visibility="hidden" right-to-left="[[rightToLeft]]">\n <div id="mainContainer" inner-h-t-m-l=\'[[innerHTML]]\' class="smart-tree-main-container" role="presentation">\n <content></content>\n </div>\n <input type="text" id="editInput" class="smart-tree-edit-input smart-hidden" />\n </smart-scroll-viewer>\n <smart-repeat-button id="scrollButtonFar" class="smart-tree-scroll-button smart-spin-button smart-scroll-button-far smart-hidden" animation="[[animation]]" unfocusable aria-label="Scroll down">\n <div id="arrowFar" class="smart-arrow smart-arrow-down"></div>\n </smart-repeat-button>\n <div id="loadingIndicatorContainer" class="smart-loader-container smart-hidden" role="presentation">\n <span id="loadingIndicator" class="smart-loader" role="img" aria-label="[[loadingIndicatorPlaceholder]]"></span>\n <span id="loadingIndicatorPlaceHolder" class="smart-loader-label smart-hidden">[[loadingIndicatorPlaceholder]]</span>\n </div>\n </div>'}detached(){const e=this,t=e._dragDetails;if(super.detached(),!t)return;const r=Smart.Tree.hoveredTree,n=Smart.Tree.hoveredItem;delete e._dragDetails,delete Smart.Tree.treeItemDragged,delete Smart.Tree.hoveredTree,delete Smart.Tree.hoveredItem,e.$.scrollViewer._scrollView.disableSwipeScroll=!1,t.FeedbackShown&&(n.classList.remove("drop-target","top","bottom"),document.body.classList.remove("smart-dragging"),t.Feedback.remove(),r&&clearInterval(r._dragInterval))}addAfter(e,t){void 0!==(t=this.getItem(t))&&this.addTo(e,t.parentItem,t,!0)}addBefore(e,t){void 0!==(t=this.getItem(t))&&this.addTo(e,t.parentItem,t)}addTo(e,t){const r=this;if(!(e instanceof Smart.TreeItem||e instanceof Smart.TreeItemsGroup))if("string"==typeof e){const t=document.createElement("smart-tree-item");t.label=e,e=t}else{if(!e||!e.label)return;{const t=document.createElement("smart-tree-item");t.label=e.label,e=t}}let n,o;if(e.isDirty=!1,void 0===t)n=1,o=t=r.$.mainContainer;else{if((t=r.getItem(t))instanceof Smart.TreeItemsGroup==0){const n=document.createElement("smart-tree-items-group");return n.innerHTML=t.innerHTML,n.appendChild(e),r.addBefore(n,t),void t.remove()}n=t.level+1,o=t.itemContainer}r._createItemHTMLStructure(e,n,t,o.childElementCount,0);const l=r.sorted&&r.autoSort,a=r._state.filter,s=r.selectedIndexes.slice(0);l&&r._unsortItems(r.$.mainContainer),e instanceof Smart.TreeItemsGroup&&(Array.from(e.querySelectorAll("smart-tree-item, smart-tree-items-group")).forEach((e=>e.isDirty=!1)),r._processHTML(e,n+1,!1));let i=arguments[2];i&&arguments[3]&&(i=i.nextElementSibling),i?(o.insertBefore(e,i),r._menuItems={},r._refreshItemPaths(r.$.mainContainer,!0,void 0,r.sorted&&!r.autoSort)):o.appendChild(e),l&&r._applyGrouping(r.$.mainContainer),a&&r._applyFilter(a),r._checkOverflow(),r._expandItemsByDefault(),r.selectedIndexes=[],r._applySelection(!0,s)}_offsetTop(e){return e?e.offsetTop+this._offsetTop(e.offsetParent):0}_offsetLeft(e){return e?e.offsetLeft+this._offsetLeft(e.offsetParent):0}offset(e){return{left:this._offsetLeft(e),top:this._offsetTop(e)}}openDropDown(){const e=this;if(!e.dropDownMode)return;if(!e.$.dropDownPopup)return;const t=e.$.dropDownPopup,r=e.$.dropDownElement;r.setAttribute("active",""),r.querySelector(".smart-drop-down-button").setAttribute("active",""),e._isOpened=!0,(()=>{const n=0,o=0;if(window.screen.availWidth<400)return t.open("left","top"),t.style.width=e.offsetWidth+"px",void(t.style.height=e.offsetHeight+"px");{const r={width:e.dropDownWidth,height:e.dropDownHeight};t.style.width="auto"===r.width?r.width:r.width+"px",t.style.height="auto"===r.height?r.height:r.height+"px"}const l=r;if(l){const r=e.offset(l),a=r.left-n,s=n,i=Math.max(s,a);t.open(i,r.top+l.offsetHeight-o)}else t.classList.add("center"),t.open("center","center");e.style.display=""})()}closeDropDown(){const e=this;e.dropDownMode&&e.$.dropDownPopup&&(e._isOpened=!1,e.$.dropDownElement.removeAttribute("active"),e.$.dropDownElement.querySelector(".smart-drop-down-button").removeAttribute("active"),e.$.dropDownPopup.close())}_createPopup(e){const t=this;let r=document.createElement("div");return r.setAttribute("animation","none"),r.classList.add("smart-window","smart-tree-popup"),e||(e={height:"auto",width:"auto",left:"center",top:"center"}),r.style.width="auto"===e.width?e.width:e.width+"px",r.style.height="auto"===e.height?e.height:e.height+"px",e.width&&"string"==typeof e.width&&(r.style.width=e.width),e.height&&"string"==typeof e.height&&(r.style.height=e.height),r.style.left="",r.style.top="",r.innerHTML='<div class="smart-container">\n <div class ="smart-content-container" smart-id="container">\n <div class="smart-content"><div class="smart-content-container"></div></div>\n </div>\n </div>\n ',r.querySelector&&r.querySelector(".smart-content")&&(r.content=r.querySelector(".smart-content").firstChild),document.body.appendChild(r),r.remove=function(){},r.close=function(){r.classList.contains("open")&&(r.classList.remove("open"),delete t._resizeHandling,r.addEventListener("transitionend",r.remove),r.addEventListener("transitioncancel",r.remove),r.onClose&&r.onClose())},r.open=function(n,o){r.removeEventListener("transitionend",r.remove),r.removeEventListener("transitioncancel",r.remove),t._resizeHandling=!1,void 0===n&&(n=e.left),void 0===o&&(o=e.top),requestAnimationFrame((function(){r.classList.add("open");const e=function(e,n){let o=t.offset(t);switch((t.dropDownMode||r.dropDownMode)&&(o={left:0,top:0}),"center"===e&&"horizontal"===n&&(e="middle"),e){case"top":return o.top;case"bottom":return Math.max(o.top,o.top+t.offsetHeight-r.offsetHeight);case"center":return Math.max(o.top,o.top+t.offsetHeight/2-r.offsetHeight/2);case"left":return o.left;case"middle":return o.left+t.offsetWidth/2-r.offsetWidth/2;case"right":return o.left+t.offsetWidth-r.offsetWidth}return"horizontal"===n?parseInt(e)+o.left:"vertical"===n?parseInt(e)+o.top:"number"==typeof e?e:parseInt(e)};r.style.left=e(n,"horizontal")+"px",r.style.top=e(o,"vertical")+"px",r.setPosition=(t,n)=>{n?r.style.left=e(t,"horizontal")+"px":r.style.top=e(t,"vertical")+"px"},"center"===n&&parseInt(r.style.left)<0&&(r.style.left="5%",r.style.maxWidth="90%"),"screenMiddle"===n&&(r.style.left="calc(50% - "+r.offsetWidth/2+"px)"),"screenCenter"===o&&(r.style.top="calc(50% - "+r.offsetHeight/2+"px)")})),r.onOpen&&r.onOpen()},r}_renderInDropDown(){const e=this;if(e.dropDownMode&&(e.dropDownMode&&(e.style.display="none"),e.dropDownMode&&void 0===e._dropDownMode)){e._dropDownMode=!0;const t=document.createElement("div"),r=e._createPopup();if(r.allowDrag=!1,r.classList.add("smart-tree-drop-down-popup"),e.$.dropDownElement=t,e.$.dropDownPopup=r,t.onmouseenter=()=>{t.hasAttribute("active")||t.setAttribute("hover","")},t.onmouseleave=()=>{t.removeAttribute("hover")},t.classList.add("smart-tree-drop-down-button","smart-drop-down-box"),e.parentNode.insertBefore(t,e),t.innerHTML=`<div class="smart-container" role="presentation">\n <div class="smart-content" role="presentation">\n <div class="smart-buttons-container" role="presentation">\n <span class="smart-action-button">${e.localize("dropDownPlaceholder")}</span>\n <span class="smart-drop-down-button">\n <span class="smart-drop-down-button-icon" id="arrow" aria-hidden="true"></span>\n </span>\n </div>\n </div>\n </div>`,t.onclick=()=>{r.classList.contains("open")?e.closeDropDown():e.openDropDown()},e.style.height="100%",e.style.width="100%",r.content.appendChild(e),e._cellsMerge=[],e._cellStyles=[],!e._popupDropDown){e._popupDropDown=r,r._refreshPosition=()=>{const n=e.offset(t),o=t.offsetHeight,l=e.offset(e);if(r.style.maxHeight="",r.style.minHeight="",n.top+o+r.offsetHeight>window.innerHeight-l.top){const e=o+n.top+r.offsetHeight-window.innerHeight+l.top;r.style.maxHeight=Math.max(250,r.offsetHeight-e)+"px",r.style.minHeight="250px"}else r.style.maxHeight="",r.style.minHeight=""};const n=()=>{const r=e.getSelectedValues();r&&r.length&&(t.querySelector(".smart-action-button").innerHTML=r[0])};r.onOpen=function(){e._popupDropDown._refreshPosition(),e.$.fireEvent("open"),e.$.listen("change",n)},r.onClose=function(){const r=e.getSelectedValues();r&&r.length&&(t.querySelector(".smart-action-button").innerHTML=r[0]),e.$.fireEvent("close")},r.onkeydown=function(e){"Escape"===e.key&&(r.result=!1,r.close())}}}}getSelectedValues(){const e=this,t=[];for(let r=0;r<e.selectedIndexes.length;r++){const n=e._menuItems[e.selectedIndexes[r]];n.hasAttribute("value")?t.push(n.getAttribute("value")):n.hasAttribute("label")&&t.push(n.getAttribute("label"))}return t}unselectValues(e){const t=this;e&&Object.keys(t._menuItems).forEach((r=>{const n=t._menuItems[r];let o=null;n.hasAttribute("value")?o=n.getAttribute("value"):n.hasAttribute("label")&&(o=n.getAttribute("label")),"string"==typeof e?e===o&&t.unselect(r):e.indexOf(o)>=0&&t.unselect(r)}))}setSelectedValues(e){const t=this;e&&Object.keys(t._menuItems).forEach((r=>{const n=t._menuItems[r];let o=null;n.hasAttribute("value")?o=n.getAttribute("value"):n.hasAttribute("label")&&(o=n.getAttribute("label")),"string"==typeof e?e===o&&t._canItemBeSelected(n)&&t._handleSelection(n,{type:"programmatic"}):e.indexOf(o)>=0&&t._canItemBeSelected(n)&&t._handleSelection(n,{type:"programmatic"})}))}clearSelection(){const e=this,t=e.selectedIndexes.slice(0);e.selectedIndexes=[],e._applySelection(!1,t)}collapseAll(e){const t=this,r=t.animation,n=!1===e&&t.hasAnimation;n&&(t.animation="none"),t._collapseAll(!0),n&&(t.animation=r)}ensureVisible(e){const t=this;if(void 0===(e=t.getItem(e))||e.hidden)return;let r=!1;e.level>1&&!t._isBranchExpanded(e)&&(super.expandItem(e.parentItem,void 0,!0),r=t.hasAnimation,r&&(t._ensureVisibleOnTransitionend=e)),r||t._ensureVisible(e)}expandAll(e){const t=this,r=t.animation,n=!1===e&&t.hasAnimation;let o=1,l=(t.enableShadowDOM?t.shadowRoot:t).querySelectorAll('smart-tree-items-group[level="1"]');for(n&&(t.animation="none");l.length>0;){for(let e=0;e<l.length;e++){const r=l[e];r.expanded||t._menuItemsGroupSelectionHandler(r,{target:r,type:"expand"})}o++,l=(t.enableShadowDOM?t.shadowRoot:t).querySelectorAll('smart-tree-items-group[level="'+o+'"]')}n&&(t.animation=r)}expandItem(e,t){const r=this;if(void 0===(e=r.getItem(e))||e instanceof Smart.TreeItemsGroup==0||e&&e.container&&r._isContainerOpened(e.container.level,e.container))return;void 0!==Smart.Menu.processTimer&&r._lazyInitItems();const n=!1===t&&r.hasAnimation,o=r.animation;n&&(r.animation="none"),r._discardKeyboardHover(),r._menuItemsGroupSelectionHandler(e,{target:e,type:"expand"},arguments[2]),n&&(r.animation=o)}filter(e){const t=this;t.filterable&&(t._applyFilter(e),t.$.filterInput.value=e)}getState(){return JSON.parse(JSON.stringify(this._state))}insert(e,t){const r=this;let n;if(e instanceof Smart.TreeItem||e instanceof Smart.TreeItemsGroup){if(r.contains(e))return;e.isDirty=!1,n=e}else{if("object"!=typeof e||e.constructor!==Object)return;n=function e(t){const n=t[r.itemsMember],o="smart-tree-items-group"===t.tagName||Array.isArray(n)?"smart-tree-items-group":"smart-tree-item",l=document.createElement(o);if(l.isDirty=!1,t.disabled&&(l.disabled=!0),t[r.displayMember]&&(l.label=t[r.displayMember]),t.selected&&(l.selected=!0),t.separator&&(l.separator=!0),t[r.valueMember]&&(l.value=t[r.valueMember]),"smart-tree-items-group"===o){if(t.expanded&&(l.expanded=!0),n)for(let t=0;t<n.length;t++)l.appendChild(e(n[t]))}else t.shortcut&&(l.shortcut=t.shortcut);return l}(e)}if(void 0===t)return void r.addTo(n);if("number"==typeof t)t=t.toString();else if(t instanceof Smart.TreeItem||t instanceof Smart.TreeItemsGroup){if(!r.contains(t))return;t=t.path}else if("string"!=typeof t)return;const o=t.split(".");let l,a;1===o.length?(a=r._menuItems[o[0]],a?r.addBefore(n,a):r.addTo(n)):(a=r._menuItems[t],l=r._menuItems[o.slice(0,o.length-1).join(".")],a?r.addBefore(n,a):l&&l instanceof Smart.TreeItemsGroup&&r.addTo(n,l))}loadState(e){const t=this,r=t.selectedIndexes.slice(0),n=[];if(!e){if(!t.id)return void t.warn(t.localize("noId"));if(!(e=window.localStorage.getItem("smartTree"+t.id)))return}"string"==typeof e&&(e=JSON.parse(e)),e.filter&&!t.filterable&&(e.filter="");let o=e.filter!==t._state.filter;e.sorted!==t.sorted?(t.sorted=e.sorted,t._updateState("sorted",t.sorted),e.sorted?t._applyGrouping(t.$.mainContainer):t._unsortItems(t.$.mainContainer),(e.filter||o)&&(t._applyFilter(e.filter),t.$.filterInput.value=e.filter)):o&&(t._applyFilter(e.filter),t.$.filterInput.value=e.filter),t._menuItemsGroupsToExpand=[];for(let r=0;r<e.expanded.length;r++){const n=t.getItem(e.expanded[r]);n&&t._menuItemsGroupsToExpand.push(n)}t._expandItemsByDefault(!0);for(let r=0;r<e.selected.length;r++){const o=t.getItem(e.selected[r]);o&&n.push(o.path)}t.selectedIndexes=n,t._applySelection(!1,r)}moveDown(e){const t=this,r=(e=t.getItem(e)).nextElementSibling;void 0!==e&&r&&!t.sorted&&(t._moveTreeItem(e,r,2,[t]),t.filterable&&t._state.filter&&t._applyFilter(t._state.filter))}moveUp(e){const t=this,r=(e=t.getItem(e)).previousElementSibling;void 0!==e&&r&&!t.sorted&&(t._moveTreeItem(e,r,0,[t]),t.filterable&&t._state.filter&&t._applyFilter(t._state.filter))}refresh(){this._checkOverflow()}removeItem(e){const t=this;if(void 0===(e=t.getItem(e)))return;if(e instanceof Smart.TreeItemsGroup){const r=e.container;t._isContainerOpened(r.level,r)&&t._closeSubContainersTreeMode(r.level,r)}const r=t.sorted&&t.autoSort;r&&t._unsortItems(t.$.mainContainer);const n=e.closest("smart-tree-items-group");e.parentElement.removeChild(e),t._menuItems={},t._refreshItemPaths(t.$.mainContainer,!0,void 0,t.sorted&&!t.autoSort),r&&t._applyGrouping(t.$.mainContainer);const o=t._state.filter,l=t.selectedIndexes.slice(0);if(o&&t._applyFilter(o),t._checkOverflow(),t.selectedIndexes=[],t._applySelection(!0,l),delete t._treeAnimationInProgress,n&&!n.querySelector("smart-tree-item")){const e=document.createElement("smart-tree-item");return e.innerHTML=n.innerHTML,t.addBefore(e,n),void n.remove()}}saveState(){const e=this;return e.id?window.localStorage.setItem("smartTree"+e.id,JSON.stringify(e._state)):e.warn(e.localize("noId")),JSON.parse(JSON.stringify(e._state))}select(e){const t=this;void 0!==(e=t.getItem(e))&&!e.selected&&t._canItemBeSelected(e)&&t._handleSelection(e,{type:"programmatic"})}unselect(e){void 0!==(e=this.getItem(e))&&e.selected&&!e.templateApplied&&this._handleSelection(e,{type:"programmatic"})}updateItem(e,t){if(void 0===(e=this.getItem(e))||void 0===t)return;const r=e instanceof Smart.TreeItem;for(let n in t)if(Object.prototype.hasOwnProperty.call(t,n)){if(r){if(-1===["disabled","label","level","selected","separator","shortcut","value"].indexOf(n))continue}else if(-1===["disabled","expanded","label","level","selected","separator","value"].indexOf(n))continue;e[n]=t[n]}}propertyChangedHandler(e,t,r){const n=this;switch(super.propertyChangedHandler(e,t,r),e){case"allowDrag":case"allowDrop":case"autoLoadState":case"autoSort":case"editable":case"filterInputPlaceholder":case"loadingIndicatorPlaceholder":case"selectionDisplayMode":case"showLines":case"showRootLines":case"toggleElementPosition":case"toggleMode":break;case"autoHideToggleElement":r?n.$mainContainer.addClass("hidden-arrows"):n.$mainContainer.removeClass("hidden-arrows");break;case"autoSaveState":if(!r)return;if(!n.id)return n.warn(n.localize("noId")),void(n.autoSaveState=!1);window.localStorage.setItem("smartTree"+n.id,JSON.stringify(n._state));break;case"dataSource":{const e=n.selectedIndexes.slice(0);n.selectedIndexes=[],n._menuItems={},n._processDataSource(),n._checkOverflow(),n._expandItemsByDefault(),n._applySelection(!0,e);const t=n._state.filter;t&&n._applyFilter(t);break}case"disabled":n._setFocusable(),n.$.scrollButtonNear.disabled=r,n.$.scrollButtonFar.disabled=r,r||n._updateScrollButtonVisibility();break;case"displayLoadingIndicator":r?(n._discardKeyboardHover(!0),n.$loadingIndicatorContainer.removeClass("smart-hidden")):n.$loadingIndicatorContainer.addClass("smart-hidden");break;case"expandMode":if("single"===r){const e=n._state.expanded.map((e=>Object.values(n._menuItems).find((t=>t.id===e)))),t={};for(let r=0;r<e.length;r++){const o=e[r],l=o.parentItem;if(t[l])continue;t[l]=!0;const a=e.filter((e=>e!==o&&e.parentItem===l));a.length>0&&a.forEach((e=>n.collapseItem(e)))}}break;case"filterable":!1===r&&(n._applyFilter(""),n.$.filterInput.value=""),n._checkOverflow();break;case"filterMode":n.filterable&&n._state.filter&&n._applyFilter(n._state.filter);break;case"hasThreeStates":if("checkBox"!==n.selectionMode)return;if(r)n._applySelection(!1);else{const e=(n.enableShadowDOM?n.shadowRoot:n).querySelectorAll("[indeterminate]");for(let t=0;t<e.length;t++)e[t].removeAttribute("indeterminate")}break;case"innerHTML":n.$.mainContainer.innerHTML=r,n._lazyInitItems();break;case"loadingIndicatorPosition":"center"===r?n.$loadingIndicatorPlaceHolder.addClass("smart-hidden"):n.$loadingIndicatorPlaceHolder.removeClass("smart-hidden");break;case"overflow":if("scrollbar"===n.scrollMode)return"hidden"===r?n.$.scrollViewer.$.verticalScrollBar.setAttribute("aria-hidden",!0):n.$.scrollViewer.$.verticalScrollBar.removeAttribute("aria-hidden"),void(n.$.scrollViewer.verticalScrollBarVisibility="scroll"===r?"visible":"auto");n.$.scrollViewer.scrollTop=0,"hidden"===r?(n.$scrollViewer.removeClass("scroll-buttons-shown"),n.$scrollButtonNear.addClass("smart-hidden"),n.$scrollButtonFar.addClass("smart-hidden")):(n.$.scrollButtonNear.disabled=n.disabled,n.$.scrollButtonFar.disabled=n.disabled,"auto"===r?(n.$scrollButtonNear.addClass("smart-hidden"),n.$scrollButtonFar.addClass("smart-hidden"),n._checkOverflow()):(n.$scrollViewer.addClass("scroll-buttons-shown"),n.$scrollViewer.removeClass("one-button-shown"),n.$scrollButtonNear.removeClass("smart-hidden"),n.$scrollButtonFar.removeClass("smart-hidden"),n._updateScrollButtonVisibility())),n.$.scrollViewer.refresh();break;case"rightToLeft":{let e,t;r?(e="paddingLeft",t="paddingRight"):(e="paddingRight",t="paddingLeft");for(let r in n._menuItems)if(Object.prototype.hasOwnProperty.call(n._menuItems,r)){const o=n._menuItems[r],l=o.firstElementChild;l.style[e]="",n._setIndentation(l,o.level,t)}break}case"scrollMode":if("hidden"===n.overflow)return;if(n.$.scrollViewer.scrollTop=0,"scrollButtons"===r)return"scroll"===n.overflow&&(n.$scrollViewer.addClass("scroll-buttons-shown"),n.$scrollButtonNear.removeClass("smart-hidden"),n.$scrollButtonFar.removeClass("smart-hidden")),n.$.scrollViewer.$.verticalScrollBar.setAttribute("aria-hidden",!0),n.$.scrollViewer.verticalScrollBarVisibility="auto",void n._checkOverflow();n.$.scrollViewer.$.verticalScrollBar.removeAttribute("aria-hidden"),n.$scrollViewer.removeClass("scroll-buttons-shown"),n.$scrollViewer.removeClass("one-button-shown"),n.$scrollButtonNear.addClass("smart-hidden"),n.$scrollButtonFar.addClass("smart-hidden"),"auto"===n.overflow?n.$.scrollViewer.verticalScrollBarVisibility="auto":n.$.scrollViewer.verticalScrollBarVisibility="visible";break;case"selectedIndexes":n._applySelection(!1,t);break;case"selectionMode":if(n.setAttribute("aria-multiselectable",-1!==["oneOrManyExtended","zeroOrMany","oneOrMany","checkBox","radioButton"].indexOf(r)),void 0===n._menuItems[0])return;if("one"===t&&"none"!==r&&"checkBox"!==r&&"radioButton"!==r||-1!==t.indexOf("oneOrMany")&&-1!==r.indexOf("oneOrMany")||"none"===t&&(-1!==r.indexOf("zero")||"checkBox"===r)||"zeroOrMany"===r&&"checkBox"!==t||"radioButton"===t&&-1!==r.indexOf("Many")||!n.hasThreeStates&&("checkBox"===r||"checkBox"===t&&"zeroOrMany"===r))return n._lastSelectedItem="one"===r||"oneOrManyExtended"===r?n._menuItems[n.selectedIndexes[n.selectedIndexes.length-1]]:void 0,void n._applyAriaSelected();if(n.hasThreeStates&&"checkBox"===t){const e=(n.enableShadowDOM?n.shadowRoot:n).querySelectorAll("[indeterminate]");for(let t=0;t<e.length;t++)e[t].removeAttribute("indeterminate")}n._applySelection(!1);break;case"sort":if(!n.sorted)return;n._refreshSorting();break;case"sortDirection":n.sorted&&!n.sort&&(n._unsortItems(n.$.mainContainer),n._applyGrouping(n.$.mainContainer));break;case"sorted":{if(!r&&!n.autoSort)return n._refreshItemPathsAndSelection(),void n._updateState("sorted",!1);r?n._applyGrouping(n.$.mainContainer):n._unsortItems(n.$.mainContainer);const e=n._state.filter;e&&n._applyFilter(e),n._updateState("sorted",r),n._checkOverflow();break}case"unfocusable":n._setFocusable()}}_addDragFeedback(){const e=this,t=document.createElement("div");return t.className="smart-tree-item-feedback",t.setAttribute("parent-tree-id",e.id),e.theme&&t.setAttribute("theme",e.theme),e.dragFeedbackFormatFunction?t.innerHTML=e.dragFeedbackFormatFunction(e._dragDetails.Items):1===e._dragDetails.Items.length?t.innerHTML=e._dragDetails.Item.label:(t.classList.add("multiple"),t.innerHTML=""),document.body.appendChild(t),t}_applyFilter(e){const t=this;function r(e,t){e?(t.hidden&&t.$.removeClass("smart-hidden"),t.hidden=!1):(t.hidden||t.$.addClass("smart-hidden"),t.hidden=!0)}if(""===e&&!t.hasAttribute("filter-applied"))return;const n=Array.from(t.$.mainContainer.getElementsByClassName("last-filtered-child"));for(let e=0;e<n.length;e++)n[e].$.removeClass("last-filtered-child");!function n(o,l){let a,s=!1,i=0;l=Array.from(l);for(let o=0;o<l.length;o++){const d=l[o];d instanceof Smart.TreeItem?r(t._findItem(d,e),d):n(d,d.itemContainer.children),d.hidden||(i++,a=d),s=s||!d.hidden}if(o!==t.$.mainContainer){const n=t._findItem(o,e);r(s||n,o),s&&null===n?o.$.addClass("filtered-child"):o.$.removeClass("filtered-child"),!s&&l.length>0?(o.hiddenChildren=!0,o.$.addClass("hidden-children"),t.collapseItem(o,void 0,!1)):(o.hiddenChildren=!1,o.$.removeClass("hidden-children"))}""!==e&&i>0&&a.$.addClass("last-filtered-child")}(t.$.mainContainer,t.$.mainContainer.children),""!==e?t.setAttribute("filter-applied",""):t.removeAttribute("filter-applied"),t._updateState("filter",e),t._checkOverflow()}_applyHierarchicalSelection(e,t){const r=this,n=e!==r.$.mainContainer,o=n?e.itemContainer.children:e.children;let l=0,a=0;for(let s=0;s<o.length;s++){const i=o[s];e.selected&&i.set("selected",!0),i instanceof Smart.TreeItemsGroup?r._applyHierarchicalSelection(i,t):i.selected&&t.push(i.path),n&&(i.selected?l++:i.hasAttribute("indeterminate")&&a++)}n&&(r._setThreeStateCheckbox(e,l,a),e.selected&&t.push(e.path))}_applyRadioButtonSelection(e,t,r){const n=this,o=e!==n.$.mainContainer?e.itemContainer.children:e.children,l=[];let a;for(let e=0;e<o.length;e++){const a=o[e];a instanceof Smart.TreeItemsGroup&&n._applyRadioButtonSelection(a,t,r),a.set("selected",!1),-1!==t.indexOf(a.path)&&l.push(a)}a=0===l.length?o[0]:l[l.length-1],a.set("selected",!0),r.push(a.path)}_applySelection(e,t){const r=this;let n=r.selectedIndexes.slice(0);function o(e){const t=Object.values(r._menuItems).filter((t=>t.level===e));if(0!==t.length){for(let e=0;e<t.length;e++)if(r._canItemBeSelected(t[e]))return t[e].path;return o(e+1)}}if(void 0===t&&(t=n.slice(0)),void 0===r._menuItems[0])return r.selectedIndexes=[],r._lastSelectedItem=void 0,void(r.isRendered&&JSON.stringify(t)!==JSON.stringify([])&&r.$.fireEvent("change",{selectedIndexes:r.selectedIndexes,oldSelectedIndexes:t}));const l=r.selectionMode,a=Array.from((r.shadowRoot||r).querySelectorAll("smart-tree-item[selected], smart-tree-items-group[selected]"));for(let e=n.length-1;e>=0;e--){const t=r._menuItems[n[e]];void 0!==t&&r._canItemBeSelected(t)||n.splice(e,1)}if(e)for(let e=0;e<a.length;e++)r._canItemBeSelected(a[e])?-1===n.indexOf(a[e].path)&&n.push(a[e].path):a[e].set("selected",!1);else{for(let e=0;e<a.length;e++)a[e].set("selected",!1);a.length=0}switch(r._sortPathCollection(n),l){case"none":n.length=0;for(let e=0;e<a.length;e++)a[e].set("selected",!1);break;case"one":case"zeroAndOne":case"zeroOrOne":"one"===l&&0===n.length&&n.push(o(1));for(let e=0;e<n.length;e++){const t=r._menuItems[n[e]];if(e===n.length-1){t.set("selected",!0),n=[n[e]];break}-1!==a.indexOf(t)&&t.set("selected",!1)}break;case"oneOrMany":case"oneOrManyExtended":0===n.length&&n.push(o(1));for(let e=0;e<n.length;e++)r._menuItems[n[e]].set("selected",!0);break;case"zeroOrMany":case"checkBox":for(let e=0;e<n.length;e++)r._menuItems[n[e]].set("selected",!0);if("checkBox"===l&&r.hasThreeStates){const e=[];r._applyHierarchicalSelection(r.$.mainContainer,e),r._sortPathCollection(e),n=e}break;case"radioButton":{const e=[];r._applyRadioButtonSelection(r.$.mainContainer,n,e),r._sortPathCollection(e),n=e;break}}r.selectedIndexes=n,r._updateState("selected"),r._lastSelectedItem="one"===l||"oneOrManyExtended"===l?r._menuItems[n[n.length-1]]:void 0,r.isRendered&&!1!==arguments[2]&&JSON.stringify(t)!==JSON.stringify(n)&&r.$.fireEvent("change",{selectedIndexes:r.selectedIndexes,oldSelectedIndexes:t}),r._applyAriaSelected()}_applyAriaSelected(){const e=this,t=e.selectionMode;for(let r in e._menuItems){const n=e._menuItems[r];n.selected?n.setAttribute("aria-selected",!0):e._canItemBeSelected(n)&&-1!==["oneOrManyExtended","zeroOrMany","oneOrMany","checkBox","radioButton"].indexOf(t)?n.setAttribute("aria-selected",!1):n.removeAttribute("aria-selected")}}_autoLoadState(e){const t=this,r=[];for(let e=0;e<t._menuItemsGroupsToExpand.length;e++)t._menuItemsGroupsToExpand[e].set("expanded",!1);t._menuItemsGroupsToExpand=[];for(let r=0;r<e.expanded.length;r++){const n=t.getItem(e.expanded[r]);n&&t._menuItemsGroupsToExpand.push(n)}t.filterable&&e.filter&&(t._applyFilter(e.filter),t.$.filterInput.value=e.filter);for(let n=0;n<e.selected.length;n++){const o=t.getItem(e.selected[n]);o&&r.push(o.path)}t.selectedIndexes=r}_blurHandler(){this._discardKeyboardHover(!0)}_canItemBeHovered(e){const t=e.level;return!1===e.disabled&&!0!==e.templateApplied&&!0!==e.hidden&&(1===t||t>1&&this._isContainerOpened(t,e.parentElement.container)&&e.getBoundingClientRect().height>0)}_canItemBeSelected(e,t){return!(!0!==t&&"leaf"===this.selectionTarget&&e instanceof Smart.TreeItemsGroup)&&!1===e.disabled&&!0!==e.templateApplied}_checkOverflow(){const e=this,t=e.$.scrollViewer,r=e.overflow;if("scrollbar"===e.scrollMode||"hidden"===r)return void t.refresh();const n=t.scrollTop;"auto"===r&&(t.$.removeClass("scroll-buttons-shown"),t.$.removeClass("one-button-shown"),e.$scrollButtonNear.addClass("smart-hidden"),e.$scrollButtonFar.addClass("smart-hidden"));const o=Math.round(t.$.scrollViewerContentContainer.offsetHeight)>Math.round(t.$.scrollViewerContainer.offsetHeight),l=Math.round(t.scrollTop)>0,a=Math.round(t.$.scrollViewerContainer.offsetHeight+t.scrollTop)<Math.round(t.$.scrollViewerContentContainer.offsetHeight);o?"auto"===r?(t.$.addClass("scroll-buttons-shown"),l&&e.$scrollButtonNear.removeClass("smart-hidden"),a&&e.$scrollButtonFar.removeClass("smart-hidden"),!1===(l&&a)&&t.$.addClass("one-button-shown"),e.disabled||(e.$.scrollButtonNear.disabled=!1,e.$.scrollButtonFar.disabled=!1),t.scrollTop=n):(e.$scrollButtonNear.removeClass("smart-hidden"),e.$scrollButtonFar.removeClass("smart-hidden"),e.disabled?(e.$.scrollButtonNear.disabled=!0,e.$.scrollButtonFar.disabled=!0):(e.$.scrollButtonNear.disabled=!l,e.$.scrollButtonFar.disabled=!a)):"scroll"===r&&(e.$.scrollButtonNear.disabled=!0,e.$.scrollButtonFar.disabled=!0),t.refresh()}_createElement(){const e=this,t=window.getComputedStyle(e.$.scrollViewer);if(e.setAttribute("role","tree"),e.setAttribute("aria-multiselectable",-1!==["oneOrManyExtended","zeroOrMany","oneOrMany","checkBox","radioButton"].indexOf(e.selectionMode)),e.setAttribute("aria-orientation","vertical"),e.$.scrollViewer.onVerticalChange=e._verticalScrollbarHandler,e.isRendered||Object.defineProperty(e,"dataSource",{get:function(){return e.context===e?e.properties.dataSource.value:e._getDataSource()},set(t){e.updateProperty(e,e._properties.dataSource,t)}}),e.id||!e.autoLoadState&&!e.autoSaveState||(e.warn(e.localize("noId")),e.autoLoadState=!1,e.autoSaveState=!1),e._renderInDropDown(),e.mode="tree",e._element="tree",e._isMobile=Smart.Utilities.Core.isMobile,e._edgeMacFF=!1,e._autoScrollCoefficient=Smart.Utilities.Core.Browser.Firefox?4:Smart.Utilities.Core.Browser.Edge?8:2,e._scrollViewerPadding=parseFloat(t.paddingTop)+parseFloat(t.paddingBottom)||0,e._state={expanded:[],filter:"",selected:[]},e._dblclickObject={numberOfClicks:0},e.autoHideToggleElement&&e.$mainContainer.addClass("hidden-arrows"),e.disabled&&(e.$.scrollButtonNear.disabled=!0,e.$.scrollButtonFar.disabled=!0),"scrollbar"===e.scrollMode&&"scroll"===e.overflow&&(e.$.scrollViewer.verticalScrollBarVisibility="visible"),null===e.dataSource&&e.$.mainContainer.firstElementChild instanceof HTMLUListElement&&e._processUList(),e.isRendered)return e._menuItems={},void(null===e.dataSource?e._processHTML(e.$.mainContainer,1):e._processDataSource());const r=(e.shadowRoot||e).querySelectorAll("smart-tree-item, smart-tree-items-group"),n=function(){let t;e.autoLoadState&&(t=window.localStorage.getItem("smartTree"+e.id),t&&(t=JSON.parse(t),e.sorted=t.sorted)),e._setFocusable(),e._menuItems={},null===e.dataSource?e._processHTML(e.$.mainContainer,1):e._processDataSource(),"scrollButtons"!==e.scrollMode&&"hidden"!==e.overflow||e.$.scrollViewer.$.verticalScrollBar.setAttribute("aria-hidden",!0),"scrollButtons"===e.scrollMode&&"scroll"===e.overflow&&(e.$scrollViewer.addClass("scroll-buttons-shown"),e.$scrollButtonNear.removeClass("smart-hidden"),e.$scrollButtonFar.removeClass("smart-hidden"),e._updateScrollButtonVisibility()),e._checkOverflow(),t&&e._autoLoadState(t),e._expandItemsByDefault(),e._applySelection(!0),e._updateState("sorted",e.sorted),e.displayLoadingIndicator&&e.$loadingIndicatorContainer.removeClass("smart-hidden"),"center"!==e.loadingIndicatorPosition&&e.$loadingIndicatorPlaceHolder.removeClass("smart-hidden"),e.__onCompleted&&(e._onCompleted=e.__onCompleted,e.__onCompleted=null,e._onCompleted())};0===r.length||e.enableShadowDOM||e.isInShadowDOM?n():(e._onCompleted&&(e.__onCompleted=e._onCompleted,e._onCompleted=null),e._ensureItemsReady(r,n))}appendChild(e){const t=this;if(!t.isCompleted){const e=Array.prototype.slice.call(arguments,2);return HTMLElement.prototype.appendChild.apply(t,e.concat(Array.prototype.slice.call(arguments)))}t.$.mainContainer&&t.$.mainContainer.appendChild(e)}_dblclickHandler(e,t,r){"dblclick"!==this.toggleMode||e instanceof Smart.TreeItem||t||this._menuItemsGroupSelectionHandler(e,r)}_discardKeyboardHover(e,t){const r=this;!t&&r._hoveredViaKeyboard&&(!e&&r._hoveredViaKeyboard instanceof Smart.MenuItemsGroup&&r._isContainerOpened(r._hoveredViaKeyboard.level+1,r._hoveredViaKeyboard.container)||(r._hoveredViaKeyboard.removeAttribute("focus"),r._hoveredViaKeyboard=void 0))}_documentUpHandler(e){if("pointercancel"===e.originalEvent.type)return;const t=this,r=t._downTimeoutInfo,n=t._dragDetails;!r||n&&n.FeedbackShown||(clearTimeout(r.timeout),t.$.scrollViewer.scrollTop!==r.scrollTop&&t.getBoundingClientRect().top===r.top||t._continueSelection(r.target,r.event)),delete t._downTimeoutInfo;const o=t._downItem,l=t.isInShadowDOM?e.originalEvent.composedPath()[0]:e.originalEvent.target;if(delete t._downItem,t._editedItem&&!t._editInputDown&&(!t._isMobile&&l!==t.$.editInput||t._isMobile&&t.getRootNode().elementFromPoint(e.clientX,e.clientY)!==t.$.editInput))return void t._endEditing();if(delete t._editInputDown,o){const r=l.closest("smart-tree-item")||l.closest("smart-tree-items-group");!r||!r.selected||r!==o||t._dragDetails&&t._dragDetails.FeedbackShown||r instanceof Smart.TreeItemsGroup&&(l.closest(".smart-tree-items-group-arrow")||l===r.container||l===r.container.firstElementChild)||t._handleSelection(r,e)}if(t.dropDownMode&&t._isOpened&&!l.closest("smart-tree")&&!l.closest(".smart-tree-drop-down-button"))return t.closeDropDown(),e.originalEvent.preventDefault(),e.originalEvent.stopPropagation(),e.preventDefault(),void e.stopPropagation();if(!n)return;const a=Smart.Tree.hoveredTree,s=Smart.Tree.hoveredItem;if(delete t._dragDetails,delete Smart.Tree.treeItemDragged,delete Smart.Tree.hoveredTree,delete Smart.Tree.hoveredItem,t.$.scrollViewer._scrollView.disableSwipeScroll=!1,!n.FeedbackShown)return;const i=a||t.getRootNode().elementFromPoint(e.clientX,e.clientY);let d;document.body.classList.remove("smart-dragging"),document.body.removeChild(n.Feedback),a&&clearInterval(a._dragInterval);const c=n.Item,m=n.Items,u=n.ValidItems;if(!i)return;if(!s||c.contains(s))return void t.$.fireEvent("dragEnd",{item:c,items:m,target:i,data:n,previousContainer:t,container:a||i,originalEvent:e});if(!a||!a.allowDrop||a.disabled)return;const p=[a];let h;if(s.classList.remove("drop-target"),s.classList.contains("top")?(s.classList.remove("top"),h="top",d=0):s.classList.contains("bottom")?(s.classList.remove("bottom"),h="bottom",d=2):(h="inside",d=1),n.DropDetails={item:s,position:h},a!==t)p.push(t);else if(n.ValidateOnDrop)for(let e=0;e<u.length;e++)if(u[e].contains(s))return;if(!t.$.fireEvent("dragEnd",{item:c,items:m,target:s,data:n,previousContainer:t,container:a,originalEvent:e}).defaultPrevented){a.sorted&&a.autoSort&&a._unsortItems(a.$.mainContainer);for(let e=0;e<u.length;e++)t._moveTreeItem(u[e],s,d,p);a.sorted&&a.autoSort&&a._applyGrouping(a.$.mainContainer),a!==t&&a._state.filter&&a._applyFilter(a._state.filter)}}_editInputBlurHandler(){this._endEditing()}_endEditing(e){const t=this,r=t._editedItem;if(!r)return;if(delete t._editedItem,t.$editInput.addClass("smart-hidden"),t.focus(),e)return;const n=t.$.editInput.value,o=t.sorted&&t.autoSort,l=t._state.filter;n!==r.label&&(r.set("label",n),r.setAttribute("aria-label",n),r.firstElementChild.firstElementChild.firstElementChild.innerHTML=n,o&&(t._unsortItems(t.$.mainContainer),t._applyGrouping(t.$.mainContainer)),l&&t._applyFilter(l))}_ensureVisible(e){const t=this;t._ensureVisibleTreeMode(e,e.getBoundingClientRect(),t.$.scrollViewer,t.$.scrollViewer.getBoundingClientRect(),t._scrollViewerPadding),t._ensureVisibleCallback&&t._ensureVisibleCallback(e)}_pointeroverHandler(e){const t=(this.isInShadowDOM?e.composedPath()[0]:e.target).closest(".smart-tree-item-label-element>span");if(!t)return;const r=this.$.container.querySelector(".tooltip");r&&(r.classList.remove("tooltip"),r.removeAttribute("title")),t.scrollWidth>t.offsetWidth&&(t.classList.add("tooltip"),t.title=t.innerText)}getFilter(){return this.$.filterInput.value}_filterInputKeyupHandler(e){const t=this;if(t._filterTimer&&clearTimeout(t._filterTimer),t.filterOnEnter){if("Enter"!==e.key)return;{const e=t.context;t.context=t,t._applyFilter(t.$.filterInput.value,t._view),t.$.fireEvent("filterChange",{value:t.$.filterInput.value}),t._checkOverflow(),t.context=e}}t._filterTimer=setTimeout((function(){const e=t.context;t.context=t,t._applyFilter(t.$.filterInput.value,t._view),t.$.fireEvent("filterChange",{value:t.$.filterInput.value}),t._checkOverflow(),t.context=e}),300)}_filterInputKeydownHandler(e){if("PageDown"!==e.key)return void("PageUp"===e.key&&(e.preventDefault(),e.stopPropagation()));const t=this;let r;if(e.preventDefault(),e.stopPropagation(),t.selectedIndexes.length>0){const e=t.selectedIndexes.slice(0);r=t._lastSelectedItem||t._menuItems[t.selectedIndexes[t.selectedIndexes.length-1]],"checkBox"!==t.selectionMode&&"radioButton"!==t.selectionMode&&(t.selectedIndexes=[r.path],t._applySelection(!1,e)),t.focus()}else r=t._getFirstEnabledChild(t.$.mainContainer),t.focus(),r&&t._hoverViaKeyboard(r);t._ensureVisible(r)}_focusHandler(){const e=this;e.selectedIndexes.length>0&&!e._hoveredViaKeyboard&&(e._lastSelectedItem?e._hoverViaKeyboard(e._lastSelectedItem,!1,void 0,!1):e._hoverViaKeyboard(e._menuItems[e.selectedIndexes[e.selectedIndexes.length-1]],!1,void 0,!1))}_getDataSource(){const e=[];return function e(t,r){for(let n=0;n<t.length;n++){const o=t[n],l={label:o.label};o.disabled&&(l.disabled=!0),o.selected&&(l.selected=!0),o.separator&&(l.separator=!0),null!==o.value&&(l.value=o.value),o instanceof Smart.TreeItem?o.shortcut&&(l.shortcut=o.shortcut):(o.expanded&&(l.expanded=!0),l.items=[],o.itemContainer&&o.itemContainer.children&&e(o.itemContainer.children,l.items)),r.push(l)}}(this.$.mainContainer.children,e),e}_handleHierarchicalSelection(e,t){const r=this;let n=e;for(e.selected?(e.set("selected",!1),e.setAttribute("aria-selected",!1)):(e.set("selected",!0),e.setAttribute("aria-selected",!0),e.removeAttribute("indeterminate"));n.parentItem;){const e=n.parentItem,t=e.itemContainer.children;let o=0,l=0;for(let e=0;e<t.length;e++)t[e].selected?o++:t[e].hasAttribute("indeterminate")&&l++;r._setThreeStateCheckbox(e,o,l),n=e}e instanceof Smart.TreeItemsGroup&&function e(t,r){const n=t.itemContainer.children;for(let t=0;t<n.length;t++){const o=n[t];o.set("selected",r),o.setAttribute("aria-selected",r),o.removeAttribute("indeterminate"),o instanceof Smart.TreeItemsGroup&&e(o,r)}}(e,e.selected),t.length=0;const o=Array.from((r.enableShadowDOM?r.shadowRoot:r).querySelectorAll("[selected]"));for(let e=0;e<o.length;e++)t.push(o[e].path);r._sortPathCollection(t)}_handleSelection(e,t){const r=this,n=r.selectionMode;if("none"===n||"programmatic"!==t.type&&!r._canItemBeSelected(e))return;const o=e.selected;if(o&&"down"===t.type)return;const l=r.selectedIndexes.slice(0);let a=l.slice(0);switch(n){case"one":case"zeroAndOne":if(o)return;r._menuItems[a[0]]&&(r._menuItems[a[0]].set("selected",!1),r._menuItems[a[0]].removeAttribute("aria-selected")),r.selectedIndexes=[e.path],e.set("selected",!0),e.setAttribute("aria-selected",!0),r._lastSelectedItem=e;break;case"zeroOrOne":o?(r.selectedIndexes=[],e.set("selected",!1),e.removeAttribute("aria-selected")):(void 0!==a[0]&&(r._menuItems[a[0]].set("selected",!1),r._menuItems[a[0]].removeAttribute("aria-selected")),r.selectedIndexes=[e.path],e.set("selected",!0),e.setAttribute("aria-selected",!0));break;case"oneOrMany":case"zeroOrMany":if(o){if(1===a.length&&"zeroOrMany"!==n)return;a.splice(a.indexOf(e.path),1),e.set("selected",!1),e.setAttribute("aria-selected",!1)}else a.push(e.path),r._sortPathCollection(a),e.set("selected",!0),e.setAttribute("aria-selected",!0);r.selectedIndexes=a;break;case"oneOrManyExtended":{const n=t.ctrlKey||t.metaKey,o=t.shiftKey;if(!n&&!o||o&&e===r._lastSelectedItem){for(let e=0;e<a.length;e++)r._menuItems[a[e]].set("selected",!1),r._menuItems[a[e]].setAttribute("aria-selected",!1);a=[e.path],e.set("selected",!0),e.setAttribute("aria-selected",!0),r._lastSelectedItem=e}else if(n)e.selected&&a.length>1?(a.splice(a.indexOf(e.path),1),e.set("selected",!1),e.setAttribute("aria-selected",!1)):e.selected||(a.push(e.path),r._sortPathCollection(a),e.set("selected",!0),e.setAttribute("aria-selected",!0),r._lastSelectedItem=e);else if(o){for(let e=0;e<a.length;e++)r._menuItems[a[e]].set("selected",!1),r._menuItems[a[e]].setAttribute("aria-selected",!1);a=r._selectItemRange(r._lastSelectedItem,e)}r.selectedIndexes=a;break}case"checkBox":r.hasThreeStates?r._handleHierarchicalSelection(e,a):o?(a.splice(a.indexOf(e.path),1),e.set("selected",!1),e.setAttribute("aria-selected",!1)):(a.push(e.path),r._sortPathCollection(a),e.set("selected",!0),e.setAttribute("aria-selected",!0)),r.selectedIndexes=a;break;case"radioButton":{if(e.selected)return;let t;for(let r=0;r<e.parentElement.children.length;r++){const n=e.parentElement.children[r];if(n.selected){t=n;break}}const n=a.indexOf(t.path);t.set("selected",!1),e.setAttribute("aria-selected",!1),e.set("selected",!0),e.setAttribute("aria-selected",!0),a.splice(n,1),a.push(e.path),r._sortPathCollection(a),r.selectedIndexes=a;break}}if(r._discardKeyboardHover(!0),r._hoverViaKeyboard(e,!1,void 0,!r._treeAnimationInProgress),r._updateState("selected"),JSON.stringify(l)!==JSON.stringify(r.selectedIndexes)){if(r.ownerElement&&!r.ownerElement.isRendered)return;r.$.fireEvent("change",{item:e,selectedIndexes:r.selectedIndexes,oldSelectedIndexes:l})}}_hoverViaKeyboard(e,t,r,n){if(!e)return;const o=this;e.setAttribute("focus",""),o._hoveredViaKeyboard=e,!1!==n&&o._ensureVisible(e),t&&o._handleSelection(e,r),o._hoverViaKeyboardCallback&&o._hoverViaKeyboardCallback(e)}_keydownHandler(e){const t=this,r=e.key;if(t._editedItem)return void("Enter"===r?t._endEditing():"Escape"===r&&t._endEditing(!0));if(t.getRootNode().activeElement!==t||-1===["ArrowDown","ArrowLeft","ArrowRight","ArrowUp","End","Enter","F2","Home","PageDown","PageUp"," "].indexOf(r)||t.disabled||t.displayLoadingIndicator)return;"Enter"!==r&&e.preventDefault();const n=Array.from(t.$.mainContainer.querySelectorAll("smart-tree-item, smart-tree-items-group")),o="one"===t.selectionMode||"oneOrManyExtended"===t.selectionMode&&!e.ctrlKey&&!e.metaKey,l=t.$.mainContainer.querySelector("[focus]");function a(r){for(let a=r;a<n.length;a++){const r=n[a];if(t._canItemBeHovered(r)){if(l){if(l===r)break;l.removeAttribute("focus")}t._hoverViaKeyboard(r,o,e);break}}}function s(r){for(let a=r;a>=0;a--){const r=n[a];if(t._canItemBeHovered(r)){if(l){if(l===r)break;l.removeAttribute("focus")}t._hoverViaKeyboard(r,o,e);break}}}function i(){l.level>1&&t._canItemBeSelected(l.parentItem)&&(l.removeAttribute("focus"),t._hoverViaKeyboard(l.parentItem,o,e))}let d;switch(r){case"ArrowDown":d=l?n.indexOf(l)+1:0,a(d);break;case"ArrowLeft":if(!l)return;if(l instanceof Smart.TreeItem)i();else{if(t._isContainerOpened(l.level+1,l.container))return void t._closeSubContainersTreeMode(l.level+1,l.container,!0,!0);i()}break;case"ArrowRight":if(!l||l instanceof Smart.TreeItem)return;if(t._isContainerOpened(l.level+1,l.container)){const r=t._getFirstEnabledChild(l.itemContainer);r&&(l.removeAttribute("focus"),t._hoverViaKeyboard(r,o,e))}else t._menuItemsGroupSelectionHandler(l,{target:l,type:"keydown"});break;case"ArrowUp":d=l?n.indexOf(l)-1:n.length-1,s(d);break;case"End":s(n.length-1);break;case"Enter":l&&l instanceof Smart.TreeItemsGroup&&t._menuItemsGroupSelectionHandler(l,{target:l,type:"keydown"});break;case"F2":t.editable&&t._startEditing(l);break;case"Home":a(0);break;case"PageDown":t._pageDownHandler(n,l,o,e);break;case"PageUp":t._pageUpHandler(n,l,o,e);break;case" ":l&&t._handleSelection(l,e)}}_mainContainerSwipeHandler(e){Smart.Tree.treeItemDragged&&e.stopPropagation()}_menuItemsGroupSelectionHandler(e,t,r){const n=this,o=n.toggleMode,l=!!t.originalEvent&&t.originalEvent.target.classList.contains("smart-tree-items-group-arrow"),a=e.container;if(n._waitAnimation&&n._treeAnimationInProgress)return;if("down"!==t.type||l||"dblclick"===o&&1!==n._dblclickObject.numberOfClicks||n._handleSelection(e,t),"down"===t.type&&!l&&("dblclick"===o&&2!==n._dblclickObject.numberOfClicks||"click"===o&&n._dblclickObject.numberOfClicks>1||"arrow"===o)||e.hiddenChildren)return;const s=a.level;let i=n.hasAnimation;if("keydown"===t.type&&n._discardKeyboardHover(),n._treeAnimationInProgress&&(a.removeEv