@openremote/or-tree-menu 1.4.0-snapshot.20250410145009 → 1.4.0-snapshot.20250415072745

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.
@@ -729,4 +729,4 @@
729
729
  <span @click="${t=>{e&&t.currentTarget.parentElement.lastElementChild.open()}}">${t}</span>
730
730
  ${e?ie`<or-mwc-menu ?multiselect="${o}" @or-mwc-menu-closed="${()=>{r&&r()}}" @or-mwc-menu-changed="${t=>{i&&i(t.detail)}}" .translateValues="${a}" .values="${n}" .menuItems="${e}" .midHeight="${l}" .fullWidth="${d}" id="menu"></or-mwc-menu>`:""}
731
731
  </span>
732
- `}(X`<or-mwc-input type=${To.BUTTON} icon="sort-variant"></or-mwc-input>`,(e||[]).map((t=>({value:t,text:t}))),t,(t=>this._onSortClick(String(t))))}_getErrorTemplate(){return X``}_onSortClick(t){this.sortBy=t}_onTreeGroupClick(t){const e=t.currentTarget,n=e.parentElement,i=(t,e)=>{t.select(),this._lastSelectedNode=e,this._notifyNodesSelect()};switch(this.selection){case Fo.LEAF:return;case Fo.MULTI:if(t.shiftKey&&this._lastSelectedNode){const t=Array.from(this._uiNodes||[]),e=n.getGroupNode();if(e){const n=t.indexOf(e),i=t.indexOf(this._lastSelectedNode);return void this._selectNodesBetween(t,n,i)}}else if(t.ctrlKey)return void i(n,e);return this.deselectAllNodes(),void i(n,e);case Fo.SINGLE:return this.deselectAllNodes(),void i(n,e)}}_onTreeNodeClick(t){const e=t.currentTarget;if(e){if(this.selection===Fo.MULTI){if(t.shiftKey&&this._lastSelectedNode){const t=Array.from(this._uiNodes||[]),n=t.indexOf(this._lastSelectedNode),i=t.indexOf(e);if(n>-1&&i>-1)return void this._selectNodesBetween(t,n,i)}else if(t.ctrlKey)return void this._selectNode(e);return this.deselectAllNodes(),void this._selectNode(e)}return this.deselectAllNodes(),void this._selectNode(e)}}_onDragStart(t,e){var n;t.target?null===(n=t.dataTransfer)||void 0===n||n.setData("treeNode",JSON.stringify(e)):t.preventDefault()}_onDragOverList(t){this.draggable&&t.preventDefault()}_onDragOverSingleNode(t,e,n){if(this.draggable&&(t.preventDefault(),n)){const t=this._getUiNodeFromTree(n);null==t||t.setAttribute("drophover","true")}}_onDragOverGroup(t,e){this.draggable&&(t.preventDefault(),t.currentTarget.setAttribute("drophover","true"))}_onDragLeaveSingleNode(t,e,n){if(n&&this.draggable){t.preventDefault();const e=this._getUiNodeFromTree(n);null==e||e.removeAttribute("drophover")}}_onDragLeaveGroup(t,e){this.draggable&&t.currentTarget.removeAttribute("drophover")}_onDragDropList(t){this._onDragDropGroup(t)}_onDragDropSingleNode(t,e,n){this._onDragDropGroup(t,n)}_onDragDropGroup(t,e){var n,i;if(this.draggable){t.preventDefault(),t.stopPropagation(),e&&(null===(n=this._getUiNodeFromTree(e))||void 0===n||n.removeAttribute("drophover"));let r=[];const o=null===(i=t.dataTransfer)||void 0===i?void 0:i.getData("treeNode");if(o){const t=JSON.parse(o);t&&r.push(t)}if(this.selection===Fo.MULTI){let t=this._findSelectedTreeNodes();t=t.filter((t=>!t.children)),t.length>0&&(this.deselectAllNodes(),r.push(...t.filter((t=>!r.find((e=>JSON.stringify(e)===JSON.stringify(t)))))))}(null==e?void 0:e.children)&&(r=r.filter((t=>{var n;return!(null===(n=e.children)||void 0===n?void 0:n.find((e=>e.id===t.id)))}))),r.length>0&&this._dispatchCancellableDragEvent(r,e,this.nodes).then((()=>{this.nodes=Ho(r,e,this.nodes)})).catch((t=>{}))}}_dispatchCancellableDragEvent(t,e,n=[]){return new Promise(((i,r)=>{this.dispatchEvent(new Vo(t,e,n))?i():r()}))}_selectNode(t,e=!0){if(t){if(e){const e=[...this._findSelectedTreeNodes()],n=this._getTreeNodeFromTree(t);if(n&&e.push(n),!this._dispatchSelectEvent(e))return}t.selected=!0,this._lastSelectedNode=t}}_selectNodesBetween(t,e,n,i=!0){const r=[];if(e<n)for(let i=e;i<=n;i++)r.push(t[i]);else if(e>n)for(let i=n;i<=e;i++)r.push(t[i]);if(i){const t=r.map((t=>this._getTreeNodeFromTree(t))).filter((t=>t));if(!this._notifyNodesSelect(t))return}r.forEach((t=>this._selectNode(t)))}_notifyNodesSelect(t){return function(t,e,n,i){return new(n||(n=Promise))((function(r,o){function a(t){try{d(i.next(t))}catch(t){o(t)}}function l(t){try{d(i.throw(t))}catch(t){o(t)}}function d(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,l)}d((i=i.apply(t,e||[])).next())}))}(this,void 0,void 0,(function*(){return yield this.getUpdateComplete(),t||(t=this._findSelectedTreeNodes()),this._dispatchSelectEvent(t)}))}_findSelectedTreeNodes(t=Array.from(this._uiNodes||[]),e=this._treeNodeCache){const n=t.filter((t=>t.selected)),i=Array.from(e.entries());return n.map((t=>i.find((e=>e[1]===t.id)))).map((t=>null==t?void 0:t[0])).filter((t=>void 0!==t))}_getTreeNodeFromTree(t,e=this._treeNodeCache){var n;return null===(n=Array.from(e.entries()).find((e=>e[1]===t.id)))||void 0===n?void 0:n[0]}_getUiNodeFromTree(t,e=this._treeNodeCache){var n;const i=Array.from(e.entries()),r=JSON.stringify(t),o=null===(n=i.find((t=>JSON.stringify(t[0])===r)))||void 0===n?void 0:n[1];return o?this.shadowRoot.getElementById(o):void 0}_dispatchSelectEvent(t){return this.dispatchEvent(new Bo(t||[]))}deselectAllNodes(){(this._uiGroups||[]).forEach((t=>t.deselect())),(this._uiNodes||[]).forEach((t=>t.selected=!1))}_sortNodes(t,e,n=!1){console.debug(`Sorting nodes in the tree menu using '${e}'`);const i=t.filter((t=>void 0!==t.children));if(i.forEach((t=>{var n;return null===(n=t.children)||void 0===n?void 0:n.sort(this._getSortFunction(e))})),n){const n=t.filter((t=>void 0===t.children));return i.sort(this._getSortFunction(e)),n.sort(this._getSortFunction(e)),[...i,...n]}return t.sort(this._getSortFunction(e))}_setTreeNodeId(t,e=Math.random().toString(36).substring(2,11)){return this._treeNodeCache.get(t)?this._treeNodeCache.get(t):(this._treeNodeCache.set(t,e),e)}_getSortFunction(t){return t===Uo.Z_TO_A?(t,e)=>e.label.localeCompare(t.label):jr.Util.sortByString((t=>t.label))}};Wo([pt({type:Array})],Jo.prototype,"nodes",void 0),Wo([pt({type:String})],Jo.prototype,"selection",void 0),Wo([pt({type:Boolean})],Jo.prototype,"draggable",void 0),Wo([pt({type:Boolean,attribute:"no-header"})],Jo.prototype,"noHeader",void 0),Wo([pt({type:String,attribute:"menu-title"})],Jo.prototype,"menuTitle",void 0),Wo([pt({type:Array,attribute:"sort-options"})],Jo.prototype,"sortOptions",void 0),Wo([pt({type:String,attribute:"sort-by",reflect:!0})],Jo.prototype,"sortBy",void 0),Wo([pt({type:Boolean,attribute:"group-first"})],Jo.prototype,"groupFirst",void 0),Wo([ft("or-tree-node")],Jo.prototype,"_uiNodes",void 0),Wo([ft("or-tree-group")],Jo.prototype,"_uiGroups",void 0),Jo=Wo([ct("or-tree-menu")],Jo)})(),a})()));
732
+ `}(X`<or-mwc-input type=${To.BUTTON} icon="sort-variant" title="${Kr.i18next.t("sort")}"></or-mwc-input>`,(e||[]).map((t=>({value:t,text:t}))),t,(t=>this._onSortClick(String(t))))}_getErrorTemplate(){return X``}_onSortClick(t){this.sortBy=t}_onTreeGroupClick(t){const e=t.currentTarget,n=e.parentElement,i=(t,e)=>{t.select(),this._lastSelectedNode=e,this._notifyNodesSelect()};switch(this.selection){case Fo.LEAF:return;case Fo.MULTI:if(t.shiftKey&&this._lastSelectedNode){const t=Array.from(this._uiNodes||[]),e=n.getGroupNode();if(e){const n=t.indexOf(e),i=t.indexOf(this._lastSelectedNode);return void this._selectNodesBetween(t,n,i)}}else if(t.ctrlKey)return void i(n,e);return this.deselectAllNodes(),void i(n,e);case Fo.SINGLE:return this.deselectAllNodes(),void i(n,e)}}_onTreeNodeClick(t){const e=t.currentTarget;if(e){if(this.selection===Fo.MULTI){if(t.shiftKey&&this._lastSelectedNode){const t=Array.from(this._uiNodes||[]),n=t.indexOf(this._lastSelectedNode),i=t.indexOf(e);if(n>-1&&i>-1)return void this._selectNodesBetween(t,n,i)}else if(t.ctrlKey)return void this._selectNode(e);return this.deselectAllNodes(),void this._selectNode(e)}return this.deselectAllNodes(),void this._selectNode(e)}}_onDragStart(t,e){var n;t.target?null===(n=t.dataTransfer)||void 0===n||n.setData("treeNode",JSON.stringify(e)):t.preventDefault()}_onDragOverList(t){this.draggable&&t.preventDefault()}_onDragOverSingleNode(t,e,n){if(this.draggable&&(t.preventDefault(),n)){const t=this._getUiNodeFromTree(n);null==t||t.setAttribute("drophover","true")}}_onDragOverGroup(t,e){this.draggable&&(t.preventDefault(),t.currentTarget.setAttribute("drophover","true"))}_onDragLeaveSingleNode(t,e,n){if(n&&this.draggable){t.preventDefault();const e=this._getUiNodeFromTree(n);null==e||e.removeAttribute("drophover")}}_onDragLeaveGroup(t,e){this.draggable&&t.currentTarget.removeAttribute("drophover")}_onDragDropList(t){this._onDragDropGroup(t)}_onDragDropSingleNode(t,e,n){this._onDragDropGroup(t,n)}_onDragDropGroup(t,e){var n,i;if(this.draggable){t.preventDefault(),t.stopPropagation(),e&&(null===(n=this._getUiNodeFromTree(e))||void 0===n||n.removeAttribute("drophover"));let r=[];const o=null===(i=t.dataTransfer)||void 0===i?void 0:i.getData("treeNode");if(o){const t=JSON.parse(o);t&&r.push(t)}if(this.selection===Fo.MULTI){let t=this._findSelectedTreeNodes();t=t.filter((t=>!t.children)),t.length>0&&(this.deselectAllNodes(),r.push(...t.filter((t=>!r.find((e=>JSON.stringify(e)===JSON.stringify(t)))))))}(null==e?void 0:e.children)&&(r=r.filter((t=>{var n;return!(null===(n=e.children)||void 0===n?void 0:n.find((e=>e.id===t.id)))}))),r.length>0&&this._dispatchCancellableDragEvent(r,e,this.nodes).then((()=>{this.nodes=Ho(r,e,this.nodes)})).catch((t=>{}))}}_dispatchCancellableDragEvent(t,e,n=[]){return new Promise(((i,r)=>{this.dispatchEvent(new Vo(t,e,n))?i():r()}))}_selectNode(t,e=!0){if(t){if(e){const e=[...this._findSelectedTreeNodes()],n=this._getTreeNodeFromTree(t);if(n&&e.push(n),!this._dispatchSelectEvent(e))return}t.selected=!0,this._lastSelectedNode=t}}_selectNodesBetween(t,e,n,i=!0){const r=[];if(e<n)for(let i=e;i<=n;i++)r.push(t[i]);else if(e>n)for(let i=n;i<=e;i++)r.push(t[i]);if(i){const t=r.map((t=>this._getTreeNodeFromTree(t))).filter((t=>t));if(!this._notifyNodesSelect(t))return}r.forEach((t=>this._selectNode(t)))}_notifyNodesSelect(t){return function(t,e,n,i){return new(n||(n=Promise))((function(r,o){function a(t){try{d(i.next(t))}catch(t){o(t)}}function l(t){try{d(i.throw(t))}catch(t){o(t)}}function d(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,l)}d((i=i.apply(t,e||[])).next())}))}(this,void 0,void 0,(function*(){return yield this.getUpdateComplete(),t||(t=this._findSelectedTreeNodes()),this._dispatchSelectEvent(t)}))}_findSelectedTreeNodes(t=Array.from(this._uiNodes||[]),e=this._treeNodeCache){const n=t.filter((t=>t.selected)),i=Array.from(e.entries());return n.map((t=>i.find((e=>e[1]===t.id)))).map((t=>null==t?void 0:t[0])).filter((t=>void 0!==t))}_getTreeNodeFromTree(t,e=this._treeNodeCache){var n;return null===(n=Array.from(e.entries()).find((e=>e[1]===t.id)))||void 0===n?void 0:n[0]}_getUiNodeFromTree(t,e=this._treeNodeCache){var n;const i=Array.from(e.entries()),r=JSON.stringify(t),o=null===(n=i.find((t=>JSON.stringify(t[0])===r)))||void 0===n?void 0:n[1];return o?this.shadowRoot.getElementById(o):void 0}_dispatchSelectEvent(t){return this.dispatchEvent(new Bo(t||[]))}deselectAllNodes(){(this._uiGroups||[]).forEach((t=>t.deselect())),(this._uiNodes||[]).forEach((t=>t.selected=!1))}_sortNodes(t,e,n=!1){console.debug(`Sorting nodes in the tree menu using '${e}'`);const i=t.filter((t=>void 0!==t.children));if(i.forEach((t=>{var n;return null===(n=t.children)||void 0===n?void 0:n.sort(this._getSortFunction(e))})),n){const n=t.filter((t=>void 0===t.children));return i.sort(this._getSortFunction(e)),n.sort(this._getSortFunction(e)),[...i,...n]}return t.sort(this._getSortFunction(e))}_setTreeNodeId(t,e=Math.random().toString(36).substring(2,11)){return this._treeNodeCache.get(t)?this._treeNodeCache.get(t):(this._treeNodeCache.set(t,e),e)}_getSortFunction(t){return t===Uo.Z_TO_A?(t,e)=>e.label.localeCompare(t.label):jr.Util.sortByString((t=>t.label))}};Wo([pt({type:Array})],Jo.prototype,"nodes",void 0),Wo([pt({type:String})],Jo.prototype,"selection",void 0),Wo([pt({type:Boolean})],Jo.prototype,"draggable",void 0),Wo([pt({type:Boolean,attribute:"no-header"})],Jo.prototype,"noHeader",void 0),Wo([pt({type:String,attribute:"menu-title"})],Jo.prototype,"menuTitle",void 0),Wo([pt({type:Array,attribute:"sort-options"})],Jo.prototype,"sortOptions",void 0),Wo([pt({type:String,attribute:"sort-by",reflect:!0})],Jo.prototype,"sortBy",void 0),Wo([pt({type:Boolean,attribute:"group-first"})],Jo.prototype,"groupFirst",void 0),Wo([ft("or-tree-node")],Jo.prototype,"_uiNodes",void 0),Wo([ft("or-tree-group")],Jo.prototype,"_uiGroups",void 0),Jo=Wo([ct("or-tree-menu")],Jo)})(),a})()));
package/dist/umd/index.js CHANGED
@@ -729,4 +729,4 @@
729
729
  <span @click="${t=>{e&&t.currentTarget.parentElement.lastElementChild.open()}}">${t}</span>
730
730
  ${e?ie`<or-mwc-menu ?multiselect="${o}" @or-mwc-menu-closed="${()=>{r&&r()}}" @or-mwc-menu-changed="${t=>{i&&i(t.detail)}}" .translateValues="${a}" .values="${n}" .menuItems="${e}" .midHeight="${l}" .fullWidth="${d}" id="menu"></or-mwc-menu>`:""}
731
731
  </span>
732
- `}(X`<or-mwc-input type=${To.BUTTON} icon="sort-variant"></or-mwc-input>`,(e||[]).map((t=>({value:t,text:t}))),t,(t=>this._onSortClick(String(t))))}_getErrorTemplate(){return X``}_onSortClick(t){this.sortBy=t}_onTreeGroupClick(t){const e=t.currentTarget,n=e.parentElement,i=(t,e)=>{t.select(),this._lastSelectedNode=e,this._notifyNodesSelect()};switch(this.selection){case Fo.LEAF:return;case Fo.MULTI:if(t.shiftKey&&this._lastSelectedNode){const t=Array.from(this._uiNodes||[]),e=n.getGroupNode();if(e){const n=t.indexOf(e),i=t.indexOf(this._lastSelectedNode);return void this._selectNodesBetween(t,n,i)}}else if(t.ctrlKey)return void i(n,e);return this.deselectAllNodes(),void i(n,e);case Fo.SINGLE:return this.deselectAllNodes(),void i(n,e)}}_onTreeNodeClick(t){const e=t.currentTarget;if(e){if(this.selection===Fo.MULTI){if(t.shiftKey&&this._lastSelectedNode){const t=Array.from(this._uiNodes||[]),n=t.indexOf(this._lastSelectedNode),i=t.indexOf(e);if(n>-1&&i>-1)return void this._selectNodesBetween(t,n,i)}else if(t.ctrlKey)return void this._selectNode(e);return this.deselectAllNodes(),void this._selectNode(e)}return this.deselectAllNodes(),void this._selectNode(e)}}_onDragStart(t,e){var n;t.target?null===(n=t.dataTransfer)||void 0===n||n.setData("treeNode",JSON.stringify(e)):t.preventDefault()}_onDragOverList(t){this.draggable&&t.preventDefault()}_onDragOverSingleNode(t,e,n){if(this.draggable&&(t.preventDefault(),n)){const t=this._getUiNodeFromTree(n);null==t||t.setAttribute("drophover","true")}}_onDragOverGroup(t,e){this.draggable&&(t.preventDefault(),t.currentTarget.setAttribute("drophover","true"))}_onDragLeaveSingleNode(t,e,n){if(n&&this.draggable){t.preventDefault();const e=this._getUiNodeFromTree(n);null==e||e.removeAttribute("drophover")}}_onDragLeaveGroup(t,e){this.draggable&&t.currentTarget.removeAttribute("drophover")}_onDragDropList(t){this._onDragDropGroup(t)}_onDragDropSingleNode(t,e,n){this._onDragDropGroup(t,n)}_onDragDropGroup(t,e){var n,i;if(this.draggable){t.preventDefault(),t.stopPropagation(),e&&(null===(n=this._getUiNodeFromTree(e))||void 0===n||n.removeAttribute("drophover"));let r=[];const o=null===(i=t.dataTransfer)||void 0===i?void 0:i.getData("treeNode");if(o){const t=JSON.parse(o);t&&r.push(t)}if(this.selection===Fo.MULTI){let t=this._findSelectedTreeNodes();t=t.filter((t=>!t.children)),t.length>0&&(this.deselectAllNodes(),r.push(...t.filter((t=>!r.find((e=>JSON.stringify(e)===JSON.stringify(t)))))))}(null==e?void 0:e.children)&&(r=r.filter((t=>{var n;return!(null===(n=e.children)||void 0===n?void 0:n.find((e=>e.id===t.id)))}))),r.length>0&&this._dispatchCancellableDragEvent(r,e,this.nodes).then((()=>{this.nodes=Ho(r,e,this.nodes)})).catch((t=>{}))}}_dispatchCancellableDragEvent(t,e,n=[]){return new Promise(((i,r)=>{this.dispatchEvent(new Vo(t,e,n))?i():r()}))}_selectNode(t,e=!0){if(t){if(e){const e=[...this._findSelectedTreeNodes()],n=this._getTreeNodeFromTree(t);if(n&&e.push(n),!this._dispatchSelectEvent(e))return}t.selected=!0,this._lastSelectedNode=t}}_selectNodesBetween(t,e,n,i=!0){const r=[];if(e<n)for(let i=e;i<=n;i++)r.push(t[i]);else if(e>n)for(let i=n;i<=e;i++)r.push(t[i]);if(i){const t=r.map((t=>this._getTreeNodeFromTree(t))).filter((t=>t));if(!this._notifyNodesSelect(t))return}r.forEach((t=>this._selectNode(t)))}_notifyNodesSelect(t){return function(t,e,n,i){return new(n||(n=Promise))((function(r,o){function a(t){try{d(i.next(t))}catch(t){o(t)}}function l(t){try{d(i.throw(t))}catch(t){o(t)}}function d(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,l)}d((i=i.apply(t,e||[])).next())}))}(this,void 0,void 0,(function*(){return yield this.getUpdateComplete(),t||(t=this._findSelectedTreeNodes()),this._dispatchSelectEvent(t)}))}_findSelectedTreeNodes(t=Array.from(this._uiNodes||[]),e=this._treeNodeCache){const n=t.filter((t=>t.selected)),i=Array.from(e.entries());return n.map((t=>i.find((e=>e[1]===t.id)))).map((t=>null==t?void 0:t[0])).filter((t=>void 0!==t))}_getTreeNodeFromTree(t,e=this._treeNodeCache){var n;return null===(n=Array.from(e.entries()).find((e=>e[1]===t.id)))||void 0===n?void 0:n[0]}_getUiNodeFromTree(t,e=this._treeNodeCache){var n;const i=Array.from(e.entries()),r=JSON.stringify(t),o=null===(n=i.find((t=>JSON.stringify(t[0])===r)))||void 0===n?void 0:n[1];return o?this.shadowRoot.getElementById(o):void 0}_dispatchSelectEvent(t){return this.dispatchEvent(new Bo(t||[]))}deselectAllNodes(){(this._uiGroups||[]).forEach((t=>t.deselect())),(this._uiNodes||[]).forEach((t=>t.selected=!1))}_sortNodes(t,e,n=!1){console.debug(`Sorting nodes in the tree menu using '${e}'`);const i=t.filter((t=>void 0!==t.children));if(i.forEach((t=>{var n;return null===(n=t.children)||void 0===n?void 0:n.sort(this._getSortFunction(e))})),n){const n=t.filter((t=>void 0===t.children));return i.sort(this._getSortFunction(e)),n.sort(this._getSortFunction(e)),[...i,...n]}return t.sort(this._getSortFunction(e))}_setTreeNodeId(t,e=Math.random().toString(36).substring(2,11)){return this._treeNodeCache.get(t)?this._treeNodeCache.get(t):(this._treeNodeCache.set(t,e),e)}_getSortFunction(t){return t===Uo.Z_TO_A?(t,e)=>e.label.localeCompare(t.label):jr.Util.sortByString((t=>t.label))}};Wo([pt({type:Array})],Jo.prototype,"nodes",void 0),Wo([pt({type:String})],Jo.prototype,"selection",void 0),Wo([pt({type:Boolean})],Jo.prototype,"draggable",void 0),Wo([pt({type:Boolean,attribute:"no-header"})],Jo.prototype,"noHeader",void 0),Wo([pt({type:String,attribute:"menu-title"})],Jo.prototype,"menuTitle",void 0),Wo([pt({type:Array,attribute:"sort-options"})],Jo.prototype,"sortOptions",void 0),Wo([pt({type:String,attribute:"sort-by",reflect:!0})],Jo.prototype,"sortBy",void 0),Wo([pt({type:Boolean,attribute:"group-first"})],Jo.prototype,"groupFirst",void 0),Wo([ft("or-tree-node")],Jo.prototype,"_uiNodes",void 0),Wo([ft("or-tree-group")],Jo.prototype,"_uiGroups",void 0),Jo=Wo([ct("or-tree-menu")],Jo)})(),a})()));
732
+ `}(X`<or-mwc-input type=${To.BUTTON} icon="sort-variant" title="${Kr.i18next.t("sort")}"></or-mwc-input>`,(e||[]).map((t=>({value:t,text:t}))),t,(t=>this._onSortClick(String(t))))}_getErrorTemplate(){return X``}_onSortClick(t){this.sortBy=t}_onTreeGroupClick(t){const e=t.currentTarget,n=e.parentElement,i=(t,e)=>{t.select(),this._lastSelectedNode=e,this._notifyNodesSelect()};switch(this.selection){case Fo.LEAF:return;case Fo.MULTI:if(t.shiftKey&&this._lastSelectedNode){const t=Array.from(this._uiNodes||[]),e=n.getGroupNode();if(e){const n=t.indexOf(e),i=t.indexOf(this._lastSelectedNode);return void this._selectNodesBetween(t,n,i)}}else if(t.ctrlKey)return void i(n,e);return this.deselectAllNodes(),void i(n,e);case Fo.SINGLE:return this.deselectAllNodes(),void i(n,e)}}_onTreeNodeClick(t){const e=t.currentTarget;if(e){if(this.selection===Fo.MULTI){if(t.shiftKey&&this._lastSelectedNode){const t=Array.from(this._uiNodes||[]),n=t.indexOf(this._lastSelectedNode),i=t.indexOf(e);if(n>-1&&i>-1)return void this._selectNodesBetween(t,n,i)}else if(t.ctrlKey)return void this._selectNode(e);return this.deselectAllNodes(),void this._selectNode(e)}return this.deselectAllNodes(),void this._selectNode(e)}}_onDragStart(t,e){var n;t.target?null===(n=t.dataTransfer)||void 0===n||n.setData("treeNode",JSON.stringify(e)):t.preventDefault()}_onDragOverList(t){this.draggable&&t.preventDefault()}_onDragOverSingleNode(t,e,n){if(this.draggable&&(t.preventDefault(),n)){const t=this._getUiNodeFromTree(n);null==t||t.setAttribute("drophover","true")}}_onDragOverGroup(t,e){this.draggable&&(t.preventDefault(),t.currentTarget.setAttribute("drophover","true"))}_onDragLeaveSingleNode(t,e,n){if(n&&this.draggable){t.preventDefault();const e=this._getUiNodeFromTree(n);null==e||e.removeAttribute("drophover")}}_onDragLeaveGroup(t,e){this.draggable&&t.currentTarget.removeAttribute("drophover")}_onDragDropList(t){this._onDragDropGroup(t)}_onDragDropSingleNode(t,e,n){this._onDragDropGroup(t,n)}_onDragDropGroup(t,e){var n,i;if(this.draggable){t.preventDefault(),t.stopPropagation(),e&&(null===(n=this._getUiNodeFromTree(e))||void 0===n||n.removeAttribute("drophover"));let r=[];const o=null===(i=t.dataTransfer)||void 0===i?void 0:i.getData("treeNode");if(o){const t=JSON.parse(o);t&&r.push(t)}if(this.selection===Fo.MULTI){let t=this._findSelectedTreeNodes();t=t.filter((t=>!t.children)),t.length>0&&(this.deselectAllNodes(),r.push(...t.filter((t=>!r.find((e=>JSON.stringify(e)===JSON.stringify(t)))))))}(null==e?void 0:e.children)&&(r=r.filter((t=>{var n;return!(null===(n=e.children)||void 0===n?void 0:n.find((e=>e.id===t.id)))}))),r.length>0&&this._dispatchCancellableDragEvent(r,e,this.nodes).then((()=>{this.nodes=Ho(r,e,this.nodes)})).catch((t=>{}))}}_dispatchCancellableDragEvent(t,e,n=[]){return new Promise(((i,r)=>{this.dispatchEvent(new Vo(t,e,n))?i():r()}))}_selectNode(t,e=!0){if(t){if(e){const e=[...this._findSelectedTreeNodes()],n=this._getTreeNodeFromTree(t);if(n&&e.push(n),!this._dispatchSelectEvent(e))return}t.selected=!0,this._lastSelectedNode=t}}_selectNodesBetween(t,e,n,i=!0){const r=[];if(e<n)for(let i=e;i<=n;i++)r.push(t[i]);else if(e>n)for(let i=n;i<=e;i++)r.push(t[i]);if(i){const t=r.map((t=>this._getTreeNodeFromTree(t))).filter((t=>t));if(!this._notifyNodesSelect(t))return}r.forEach((t=>this._selectNode(t)))}_notifyNodesSelect(t){return function(t,e,n,i){return new(n||(n=Promise))((function(r,o){function a(t){try{d(i.next(t))}catch(t){o(t)}}function l(t){try{d(i.throw(t))}catch(t){o(t)}}function d(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,l)}d((i=i.apply(t,e||[])).next())}))}(this,void 0,void 0,(function*(){return yield this.getUpdateComplete(),t||(t=this._findSelectedTreeNodes()),this._dispatchSelectEvent(t)}))}_findSelectedTreeNodes(t=Array.from(this._uiNodes||[]),e=this._treeNodeCache){const n=t.filter((t=>t.selected)),i=Array.from(e.entries());return n.map((t=>i.find((e=>e[1]===t.id)))).map((t=>null==t?void 0:t[0])).filter((t=>void 0!==t))}_getTreeNodeFromTree(t,e=this._treeNodeCache){var n;return null===(n=Array.from(e.entries()).find((e=>e[1]===t.id)))||void 0===n?void 0:n[0]}_getUiNodeFromTree(t,e=this._treeNodeCache){var n;const i=Array.from(e.entries()),r=JSON.stringify(t),o=null===(n=i.find((t=>JSON.stringify(t[0])===r)))||void 0===n?void 0:n[1];return o?this.shadowRoot.getElementById(o):void 0}_dispatchSelectEvent(t){return this.dispatchEvent(new Bo(t||[]))}deselectAllNodes(){(this._uiGroups||[]).forEach((t=>t.deselect())),(this._uiNodes||[]).forEach((t=>t.selected=!1))}_sortNodes(t,e,n=!1){console.debug(`Sorting nodes in the tree menu using '${e}'`);const i=t.filter((t=>void 0!==t.children));if(i.forEach((t=>{var n;return null===(n=t.children)||void 0===n?void 0:n.sort(this._getSortFunction(e))})),n){const n=t.filter((t=>void 0===t.children));return i.sort(this._getSortFunction(e)),n.sort(this._getSortFunction(e)),[...i,...n]}return t.sort(this._getSortFunction(e))}_setTreeNodeId(t,e=Math.random().toString(36).substring(2,11)){return this._treeNodeCache.get(t)?this._treeNodeCache.get(t):(this._treeNodeCache.set(t,e),e)}_getSortFunction(t){return t===Uo.Z_TO_A?(t,e)=>e.label.localeCompare(t.label):jr.Util.sortByString((t=>t.label))}};Wo([pt({type:Array})],Jo.prototype,"nodes",void 0),Wo([pt({type:String})],Jo.prototype,"selection",void 0),Wo([pt({type:Boolean})],Jo.prototype,"draggable",void 0),Wo([pt({type:Boolean,attribute:"no-header"})],Jo.prototype,"noHeader",void 0),Wo([pt({type:String,attribute:"menu-title"})],Jo.prototype,"menuTitle",void 0),Wo([pt({type:Array,attribute:"sort-options"})],Jo.prototype,"sortOptions",void 0),Wo([pt({type:String,attribute:"sort-by",reflect:!0})],Jo.prototype,"sortBy",void 0),Wo([pt({type:Boolean,attribute:"group-first"})],Jo.prototype,"groupFirst",void 0),Wo([ft("or-tree-node")],Jo.prototype,"_uiNodes",void 0),Wo([ft("or-tree-group")],Jo.prototype,"_uiGroups",void 0),Jo=Wo([ct("or-tree-menu")],Jo)})(),a})()));