@ionic/core
Version:
Base components for Ionic
4 lines • 5.74 kB
JavaScript
/*!
* (C) Ionic http://ionicframework.com - MIT License
*/
import{r as t,h as s,e,f as r,c as i}from"./p-66a5d6a8.js";import{j as o,k as n}from"./p-da2b833b.js";import{b as a}from"./p-597ff9af.js";import{f as h,g as c}from"./p-c3f9d9fe.js";import{r as d}from"./p-ece78e7b.js";import{a as l,b as f,h as p}from"./p-89b61afc.js";import"./p-3f4327f7.js";import"./p-c61cc894.js";import"./p-7b30edcc.js";const m=class{constructor(s){t(this,s)}onClick(t){const s=this.el.closest("ion-reorder-group");t.preventDefault(),s&&s.disabled||t.stopImmediatePropagation()}render(){const t=a(this);return s(e,{key:"17adf3165f4e09283d5d6434d7cd47bd23519048",class:t},s("slot",{key:"d00d1cd97c689fc5c7b7175a2051cf697fe22871"},s("ion-icon",{key:"eec219aebde6083de98358be3e75965c5a5dc3d0",icon:"ios"===t?o:n,lazy:!1,class:"reorder-icon",part:"icon","aria-hidden":"true"})))}get el(){return r(this)}};m.style={ios:":host([slot]){display:none;line-height:0;z-index:100}.reorder-icon{display:block}::slotted(ion-icon){font-size:dynamic-font(16px)}.reorder-icon{font-size:2.125rem;opacity:0.4}",md:":host([slot]){display:none;line-height:0;z-index:100}.reorder-icon{display:block}::slotted(ion-icon){font-size:dynamic-font(16px)}.reorder-icon{font-size:1.9375rem;opacity:0.3}"};const b=class{constructor(s){t(this,s),this.ionItemReorder=i(this,"ionItemReorder",7),this.lastToIndex=-1,this.cachedHeights=[],this.scrollElTop=0,this.scrollElBottom=0,this.scrollElInitial=0,this.containerTop=0,this.containerBottom=0,this.state=0,this.disabled=!0}disabledChanged(){this.gesture&&this.gesture.enable(!this.disabled)}async connectedCallback(){const t=h(this.el);t&&(this.scrollEl=await c(t)),this.gesture=(await import("./p-8ededb41.js")).createGesture({el:this.el,gestureName:"reorder",gesturePriority:110,threshold:0,direction:"y",passive:!1,canStart:t=>this.canStart(t),onStart:t=>this.onStart(t),onMove:t=>this.onMove(t),onEnd:()=>this.onEnd()}),this.disabledChanged()}disconnectedCallback(){this.onEnd(),this.gesture&&(this.gesture.destroy(),this.gesture=void 0)}complete(t){return Promise.resolve(this.completeReorder(t))}canStart(t){if(this.selectedItemEl||0!==this.state)return!1;const s=t.event.target.closest("ion-reorder");if(!s)return!1;const e=k(s,this.el);return!!e&&(t.data=e,!0)}onStart(t){t.event.preventDefault();const s=this.selectedItemEl=t.data,e=this.cachedHeights;e.length=0;const r=this.el,i=r.children;if(!i||0===i.length)return;let o=0;for(let t=0;t<i.length;t++){const s=i[t];o+=s.offsetHeight,e.push(o),s.$ionIndex=t}const n=r.getBoundingClientRect();if(this.containerTop=n.top,this.containerBottom=n.bottom,this.scrollEl){const t=this.scrollEl.getBoundingClientRect();this.scrollElInitial=this.scrollEl.scrollTop,this.scrollElTop=t.top+g,this.scrollElBottom=t.bottom-g}else this.scrollElInitial=0,this.scrollElTop=0,this.scrollElBottom=0;this.lastToIndex=u(s),this.selectedItemHeight=s.offsetHeight,this.state=1,s.classList.add(w),l()}onMove(t){const s=this.selectedItemEl;if(!s)return;const e=this.autoscroll(t.currentY),r=this.containerTop-e,i=Math.max(r,Math.min(t.currentY,this.containerBottom-e)),o=e+i-t.startY,n=this.itemIndexForTop(i-r);if(n!==this.lastToIndex){const t=u(s);this.lastToIndex=n,f(),this.reorderMove(t,n)}s.style.transform=`translateY(${o}px)`}onEnd(){const t=this.selectedItemEl;if(this.state=2,!t)return void(this.state=0);const s=this.lastToIndex,e=u(t);s===e?this.completeReorder():this.ionItemReorder.emit({from:e,to:s,complete:this.completeReorder.bind(this)}),p()}completeReorder(t){const s=this.selectedItemEl;if(s&&2===this.state){const e=this.el.children,r=e.length,i=this.lastToIndex,o=u(s);d((()=>{i===o||void 0!==t&&!0!==t||this.el.insertBefore(s,o<i?e[i+1]:e[i]);for(let t=0;t<r;t++)e[t].style.transform=""})),Array.isArray(t)&&(t=x(t,o,i)),s.style.transition="",s.classList.remove(w),this.selectedItemEl=void 0,this.state=0}return t}itemIndexForTop(t){const s=this.cachedHeights;for(let e=0;e<s.length;e++)if(s[e]>t)return e;return s.length-1}reorderMove(t,s){const e=this.selectedItemHeight,r=this.el.children;for(let i=0;i<r.length;i++){let o="";i>t&&i<=s?o=`translateY(${-e}px)`:i<t&&i>=s&&(o=`translateY(${e}px)`),r[i].style.transform=o}}autoscroll(t){if(!this.scrollEl)return 0;let s=0;return t<this.scrollElTop?s=-y:t>this.scrollElBottom&&(s=y),0!==s&&this.scrollEl.scrollBy(0,s),this.scrollEl.scrollTop-this.scrollElInitial}render(){const t=a(this);return s(e,{key:"6ca009dd65302a914d459aec638e62977440db20",class:{[t]:!0,"reorder-enabled":!this.disabled,"reorder-list-active":0!==this.state}})}get el(){return r(this)}static get watchers(){return{disabled:["disabledChanged"]}}},u=t=>t.$ionIndex,k=(t,s)=>{let e;for(;t;){if(e=t.parentElement,e===s)return t;t=e}},g=60,y=10,w="reorder-selected",x=(t,s,e)=>{const r=t[s];return t.splice(s,1),t.splice(e,0,r),t.slice()};b.style=".reorder-list-active>*{display:block;-webkit-transition:-webkit-transform 300ms;transition:-webkit-transform 300ms;transition:transform 300ms;transition:transform 300ms, -webkit-transform 300ms;will-change:transform}.reorder-enabled{-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.reorder-enabled ion-reorder{display:block;cursor:-webkit-grab;cursor:grab;pointer-events:all;-ms-touch-action:none;touch-action:none}.reorder-selected,.reorder-selected ion-reorder{cursor:-webkit-grabbing;cursor:grabbing}.reorder-selected{position:relative;-webkit-transition:none !important;transition:none !important;-webkit-box-shadow:0 0 10px rgba(0, 0, 0, 0.4);box-shadow:0 0 10px rgba(0, 0, 0, 0.4);opacity:0.8;z-index:100}.reorder-visible ion-reorder .reorder-icon{-webkit-transform:translate3d(0, 0, 0);transform:translate3d(0, 0, 0)}";export{m as ion_reorder,b as ion_reorder_group}