@openremote/or-tree-menu 1.6.3 → 1.6.5
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/custom-elements.json +15 -0
- package/dist/umd/index.bundle.js +1 -1
- package/dist/umd/index.js +1 -1
- package/dist/umd/index.orbundle.js +2 -2
- package/lib/index.d.ts +6 -0
- package/lib/index.js +2 -2
- package/lib/index.js.map +1 -1
- package/package.json +5 -5
package/custom-elements.json
CHANGED
|
@@ -868,6 +868,21 @@
|
|
|
868
868
|
}
|
|
869
869
|
],
|
|
870
870
|
"description": "Function for retrieving the sorting for TreeNodes based on a sortBy parameter.\nThe sortBy parameter represents a key in the TreeNode object like 'label'."
|
|
871
|
+
},
|
|
872
|
+
{
|
|
873
|
+
"kind": "method",
|
|
874
|
+
"name": "expandGroup",
|
|
875
|
+
"privacy": "public",
|
|
876
|
+
"parameters": [
|
|
877
|
+
{
|
|
878
|
+
"name": "groupId",
|
|
879
|
+
"type": {
|
|
880
|
+
"text": "string"
|
|
881
|
+
},
|
|
882
|
+
"description": "The ID of the group to expand."
|
|
883
|
+
}
|
|
884
|
+
],
|
|
885
|
+
"description": "Programmatically finds a group by its ID and sets it to be expanded.\nThis is called by the parent component after a new node is added to a tree group."
|
|
871
886
|
}
|
|
872
887
|
],
|
|
873
888
|
"events": [
|
package/dist/umd/index.bundle.js
CHANGED
|
@@ -730,4 +730,4 @@
|
|
|
730
730
|
<span @click="${t=>{if(e){if(s&&m){const e=t.currentTarget;!function(t,e){e||(e=document.body);const n=e.getBoundingClientRect();Object.assign(t.style,{position:"fixed",top:`${n.bottom}px`,left:`${n.left}px`,zIndex:"1000",display:"block"})}(m,e)}t.currentTarget.parentElement.lastElementChild.open()}}}">${t}</span>
|
|
731
731
|
${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="${c}" ${cn((t=>m=t))}></or-mwc-menu>`:""}
|
|
732
732
|
</span>
|
|
733
|
-
`}(X`<or-mwc-input type=${Io.BUTTON} icon="sort-variant" title="${Jr.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 Uo.LEAF:return;case Uo.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 Uo.SINGLE:return this.deselectAllNodes(),void i(n,e)}}_onTreeNodeClick(t){const e=t.currentTarget;if(e){if(this.selection===Uo.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===Uo.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=Fo(r,e,this.nodes)})).catch((t=>{}))}}_dispatchCancellableDragEvent(t,e,n=[]){return new Promise(((i,r)=>{this.dispatchEvent(new Xo(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 Vo(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===Bo.Z_TO_A?(t,e)=>e.label.localeCompare(t.label):Gr.Util.sortByString((t=>t.label))}};Ko([pt({type:Array})],Qo.prototype,"nodes",void 0),Ko([pt({type:String})],Qo.prototype,"selection",void 0),Ko([pt({type:Boolean})],Qo.prototype,"draggable",void 0),Ko([pt({type:Boolean,attribute:"no-header"})],Qo.prototype,"noHeader",void 0),Ko([pt({type:String,attribute:"menu-title"})],Qo.prototype,"menuTitle",void 0),Ko([pt({type:Array,attribute:"sort-options"})],Qo.prototype,"sortOptions",void 0),Ko([pt({type:String,attribute:"sort-by",reflect:!0})],Qo.prototype,"sortBy",void 0),Ko([pt({type:Boolean,attribute:"group-first"})],Qo.prototype,"groupFirst",void 0),Ko([ft("or-tree-node")],Qo.prototype,"_uiNodes",void 0),Ko([ft("or-tree-group")],Qo.prototype,"_uiGroups",void 0),Qo=Ko([ct("or-tree-menu")],Qo)})(),a})()));
|
|
733
|
+
`}(X`<or-mwc-input type=${Io.BUTTON} icon="sort-variant" title="${Jr.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 Uo.LEAF:return;case Uo.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 Uo.SINGLE:return this.deselectAllNodes(),void i(n,e)}}_onTreeNodeClick(t){const e=t.currentTarget;if(e){if(this.selection===Uo.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===Uo.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=Fo(r,e,this.nodes)})).catch((t=>{}))}}_dispatchCancellableDragEvent(t,e,n=[]){return new Promise(((i,r)=>{this.dispatchEvent(new Xo(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 Vo(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===Bo.Z_TO_A?(t,e)=>e.label.localeCompare(t.label):Gr.Util.sortByString((t=>t.label))}expandGroup(t){this.updateComplete.then((()=>{const e=this.nodes.find((e=>e.id===t&&e.children));e&&(e.expanded=!0,this.requestUpdate())}))}};Ko([pt({type:Array})],Qo.prototype,"nodes",void 0),Ko([pt({type:String})],Qo.prototype,"selection",void 0),Ko([pt({type:Boolean})],Qo.prototype,"draggable",void 0),Ko([pt({type:Boolean,attribute:"no-header"})],Qo.prototype,"noHeader",void 0),Ko([pt({type:String,attribute:"menu-title"})],Qo.prototype,"menuTitle",void 0),Ko([pt({type:Array,attribute:"sort-options"})],Qo.prototype,"sortOptions",void 0),Ko([pt({type:String,attribute:"sort-by",reflect:!0})],Qo.prototype,"sortBy",void 0),Ko([pt({type:Boolean,attribute:"group-first"})],Qo.prototype,"groupFirst",void 0),Ko([ft("or-tree-node")],Qo.prototype,"_uiNodes",void 0),Ko([ft("or-tree-group")],Qo.prototype,"_uiGroups",void 0),Qo=Ko([ct("or-tree-menu")],Qo)})(),a})()));
|
package/dist/umd/index.js
CHANGED
|
@@ -730,4 +730,4 @@
|
|
|
730
730
|
<span @click="${t=>{if(e){if(s&&m){const e=t.currentTarget;!function(t,e){e||(e=document.body);const n=e.getBoundingClientRect();Object.assign(t.style,{position:"fixed",top:`${n.bottom}px`,left:`${n.left}px`,zIndex:"1000",display:"block"})}(m,e)}t.currentTarget.parentElement.lastElementChild.open()}}}">${t}</span>
|
|
731
731
|
${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="${c}" ${cn((t=>m=t))}></or-mwc-menu>`:""}
|
|
732
732
|
</span>
|
|
733
|
-
`}(X`<or-mwc-input type=${Io.BUTTON} icon="sort-variant" title="${Jr.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 Uo.LEAF:return;case Uo.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 Uo.SINGLE:return this.deselectAllNodes(),void i(n,e)}}_onTreeNodeClick(t){const e=t.currentTarget;if(e){if(this.selection===Uo.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===Uo.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=Fo(r,e,this.nodes)})).catch((t=>{}))}}_dispatchCancellableDragEvent(t,e,n=[]){return new Promise(((i,r)=>{this.dispatchEvent(new Xo(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 Vo(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===Bo.Z_TO_A?(t,e)=>e.label.localeCompare(t.label):Gr.Util.sortByString((t=>t.label))}};Ko([pt({type:Array})],Qo.prototype,"nodes",void 0),Ko([pt({type:String})],Qo.prototype,"selection",void 0),Ko([pt({type:Boolean})],Qo.prototype,"draggable",void 0),Ko([pt({type:Boolean,attribute:"no-header"})],Qo.prototype,"noHeader",void 0),Ko([pt({type:String,attribute:"menu-title"})],Qo.prototype,"menuTitle",void 0),Ko([pt({type:Array,attribute:"sort-options"})],Qo.prototype,"sortOptions",void 0),Ko([pt({type:String,attribute:"sort-by",reflect:!0})],Qo.prototype,"sortBy",void 0),Ko([pt({type:Boolean,attribute:"group-first"})],Qo.prototype,"groupFirst",void 0),Ko([ft("or-tree-node")],Qo.prototype,"_uiNodes",void 0),Ko([ft("or-tree-group")],Qo.prototype,"_uiGroups",void 0),Qo=Ko([ct("or-tree-menu")],Qo)})(),a})()));
|
|
733
|
+
`}(X`<or-mwc-input type=${Io.BUTTON} icon="sort-variant" title="${Jr.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 Uo.LEAF:return;case Uo.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 Uo.SINGLE:return this.deselectAllNodes(),void i(n,e)}}_onTreeNodeClick(t){const e=t.currentTarget;if(e){if(this.selection===Uo.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===Uo.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=Fo(r,e,this.nodes)})).catch((t=>{}))}}_dispatchCancellableDragEvent(t,e,n=[]){return new Promise(((i,r)=>{this.dispatchEvent(new Xo(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 Vo(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===Bo.Z_TO_A?(t,e)=>e.label.localeCompare(t.label):Gr.Util.sortByString((t=>t.label))}expandGroup(t){this.updateComplete.then((()=>{const e=this.nodes.find((e=>e.id===t&&e.children));e&&(e.expanded=!0,this.requestUpdate())}))}};Ko([pt({type:Array})],Qo.prototype,"nodes",void 0),Ko([pt({type:String})],Qo.prototype,"selection",void 0),Ko([pt({type:Boolean})],Qo.prototype,"draggable",void 0),Ko([pt({type:Boolean,attribute:"no-header"})],Qo.prototype,"noHeader",void 0),Ko([pt({type:String,attribute:"menu-title"})],Qo.prototype,"menuTitle",void 0),Ko([pt({type:Array,attribute:"sort-options"})],Qo.prototype,"sortOptions",void 0),Ko([pt({type:String,attribute:"sort-by",reflect:!0})],Qo.prototype,"sortBy",void 0),Ko([pt({type:Boolean,attribute:"group-first"})],Qo.prototype,"groupFirst",void 0),Ko([ft("or-tree-node")],Qo.prototype,"_uiNodes",void 0),Ko([ft("or-tree-group")],Qo.prototype,"_uiGroups",void 0),Qo=Ko([ct("or-tree-menu")],Qo)})(),a})()));
|