@esri/calcite-components
Version:
Web Components for Esri's Calcite Design System.
1 lines • 2.15 kB
JavaScript
import{r as registerInstance,c as createEvent,h,H as Host,g as getElement}from"./index-8fd57462.js";import{S as Sortable}from"./sortable.esm-98c2e482.js";var CalciteSortableList=function(){function e(e){var t=this;registerInstance(this,e);this.calciteListOrderChange=createEvent(this,"calciteListOrderChange",7);this.handleSelector="calcite-handle";this.disabled=false;this.loading=false;this.handleActivated=false;this.items=[];this.observer=new MutationObserver((function(){t.cleanUpDragAndDrop();t.items=Array.from(t.el.children);t.setUpDragAndDrop()}))}e.prototype.connectedCallback=function(){this.items=Array.from(this.el.children);this.setUpDragAndDrop();this.beginObserving()};e.prototype.disconnectedCallback=function(){this.observer.disconnect();this.cleanUpDragAndDrop()};e.prototype.calciteHandleNudgeHandler=function(e){var t=this.items.find((function(t){return t.contains(e.detail.handle)||e.composedPath().includes(t)}));var r=this.items.length-1;var i=this.items.indexOf(t);var n=false;var s;switch(e.detail.direction){case"up":e.preventDefault();if(i===0){n=true}else{s=i-1}break;case"down":e.preventDefault();if(i===r){s=0}else if(i===r-1){n=true}else{s=i+2}break;default:return}this.observer.disconnect();if(n){t.parentElement.appendChild(t)}else{t.parentElement.insertBefore(t,this.items[s])}this.items=Array.from(this.el.children);e.detail.handle.activated=true;e.detail.handle.setFocus();this.beginObserving()};e.prototype.setUpDragAndDrop=function(){var e=this;this.sortable=Sortable.create(this.el,{handle:this.handleSelector,onUpdate:function(){e.items=Array.from(e.el.children);e.calciteListOrderChange.emit()},onStart:function(){e.observer.disconnect()},onEnd:function(){e.beginObserving()}})};e.prototype.cleanUpDragAndDrop=function(){this.sortable.destroy();this.sortable=null};e.prototype.beginObserving=function(){this.observer.observe(this.el,{childList:true,subtree:true})};e.prototype.render=function(){return h(Host,null,h("slot",null))};Object.defineProperty(e.prototype,"el",{get:function(){return getElement(this)},enumerable:false,configurable:true});return e}();export{CalciteSortableList as calcite_sortable_list};