@progress/kendo-react-sortable 8.2.0-develop.9 → 8.2.0
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/Sortable.js +1 -1
- package/Sortable.mjs +155 -142
- package/dist/cdn/js/kendo-react-sortable.js +1 -1
- package/index.d.mts +14 -4
- package/index.d.ts +14 -4
- package/package-metadata.mjs +1 -1
- package/package.json +3 -3
package/Sortable.js
CHANGED
|
@@ -5,4 +5,4 @@
|
|
|
5
5
|
* Licensed under commercial license. See LICENSE.md in the package root for more information
|
|
6
6
|
*-------------------------------------------------------------------------------------------
|
|
7
7
|
*/
|
|
8
|
-
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const M=require("react"),d=require("prop-types"),h=require("@progress/kendo-react-common"),N=require("./events/SortableOnDragStartEvent.js"),P=require("./events/SortableOnDragOverEvent.js"),U=require("./events/SortableOnDragEndEvent.js"),B=require("./events/SortableOnNavigateEvent.js"),x=require("@progress/kendo-react-intl"),R=require("./messages/index.js"),f=require("./utils/utils.js"),F=require("./package-metadata.js");function k(v){const c=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(v){for(const t in v)if(t!=="default"){const e=Object.getOwnPropertyDescriptor(v,t);Object.defineProperty(c,t,e.get?e:{enumerable:!0,get:()=>v[t]})}}return c.default=v,Object.freeze(c)}const p=k(M),w=200,S="data-sortable-id",A="data-sortable-component",q={[A]:!0},y=class y extends p.Component{constructor(c){super(c),this.state={clientX:0,clientY:0,isDragging:!1,activeId:"",dragCueWidth:0,dragCueHeight:0},this.isRtl=!1,this.itemRefsMap={},this.oldSizesMap={},this.animatingItemMap={},this.draggableRef=null,this.isUnmounted=!1,this.focusActiveId=!1,this.isKeyboardNavigated=!1,this.isDragPrevented=!1,this.swapItems=(t,e,i)=>{let s=t[e];return t[e]=t[i],t[i]=s,e=i,e},this.generateNewState=(t,e)=>{const{data:i}=this.props,s=[...i];if(t>e)for(let r=t-1;r>=e;r--){const o=i[r];this.isItemDisabled(o)||(t=this.swapItems(s,t,r))}else for(let r=t+1;r<=e;r++){const o=i[r];this.isItemDisabled(o)||(t=this.swapItems(s,t,r))}return s},this.closestSortableItem=t=>{let e=t;for(;e;){const i=e.getAttribute(S);if(i&&this.itemRefsMap[i]===e)return{id:i,element:e};e=e.parentElement}return{id:"",element:null}},this.isSortable=t=>!!t.hasAttribute(A),this.closestSortable=t=>{let e=t;for(;e;){if(this.isSortable(e))return e;e=e.parentElement}return null},this.isSameSortable=t=>this.closestSortable(t)===this.container,this.idComparer=(t,e)=>t+""==e+"",this.findItem=t=>{const{data:e,idField:i}=this.props;if(!(t+""))return;const s=h.getter(i);return f.find(e,a=>this.idComparer(s(a),t))},this.findIndex=t=>{const{data:e,idField:i}=this.props;return t+""?f.findIndex(e,s=>this.idComparer(s[i],t)):-1},this.isItemDisabled=t=>t&&t[this.props.disabledField||""]===!0,this.shouldResetActive=()=>{const t=h.getActiveElement(document);return t instanceof HTMLElement?!this.closestSortableItem(t).element:!1},this.widgetTarget=t=>{const e=f.closest(t,i=>f.hasClasses(i,"k-widget")||this.isSortable(i));return e&&!this.isSortable(e)},this.allowDrag=t=>t.hasAttribute(S)||!(f.isFocusable(t)||this.widgetTarget(t)),this.onDragStart=t=>{const{event:e}=t,{onDragStart:i}=this.props,s=document.elementFromPoint(e.clientX,e.clientY),{id:a,element:r}=this.closestSortableItem(s),o=this.findItem(a);if(!a||o&&this.isItemDisabled(o)||!this.allowDrag(s)||!this.isSameSortable(s)){this.isDragPrevented=!0;return}e.isTouch&&e.originalEvent.preventDefault();const n=new N.SortableOnDragStartEvent(this,this.findIndex(a),s);i&&i.call(void 0,n),this.isDragPrevented=n.isDefaultPrevented(),this.isDragPrevented?e.originalEvent.preventDefault():(this.offsetParent=f.relativeContextElement(this.container),this.setState({activeId:a,dragCueWidth:r&&r.clientWidth||0,dragCueHeight:r&&r.clientHeight||0}))},this.onDragOver=t=>{const{event:e}=t,{onDragOver:i,data:s}=this.props;if(this.isDragPrevented)return;e.originalEvent.preventDefault();const a=this.findIndex(this.state.activeId);if(a===-1){this.resetState();return}const r=document.elementFromPoint(e.clientX,e.clientY),o=this.closestSortableItem(r),n=this.findIndex(o.id),l=s[n];if(i&&n>-1&&a!==n&&!this.isItemDisabled(l)&&!this.animatingItemMap[o.id]&&this.shouldReorder(o.element,e.clientX,e.clientY)){const u=new P.SortableOnDragOverEvent(this,a,n,this.generateNewState(a,n));i.call(void 0,u)}const g=this.parentOffset();this.setState({clientX:e.clientX-g.left,clientY:e.clientY-g.top,isDragging:!0})},this.onDragEnd=t=>{const{event:e}=t,i=this.shouldResetActive();if(this.isDragPrevented)return;const{onDragEnd:s,data:a}=this.props,r=document.elementFromPoint(e.clientX,e.clientY),o=this.closestSortableItem(r);let n=this.findIndex(o.id),l=this.findIndex(this.state.activeId);const g=this.isItemDisabled(a[n]);if((n===-1||g)&&(n=l),s){let u=this.generateNewState(l,n);if(!g){const m=this.thresholdRect(o.element);if(m&&(e.clientX<m.left||e.clientX>m.right||e.clientY<m.top||e.clientY>m.bottom)){const D=l;l=n,n=D,u=this.props.data.slice()}}const I=new U.SortableOnDragEndEvent(this,l,n,u);s.call(void 0,I)}this.resetState(i)},this.shouldReorder=(t,e,i)=>{const s=this.thresholdRect(t);return s&&e>s.left&&e<s.right&&i>s.top&&i<s.bottom},this.thresholdRect=t=>{const e=this.state.activeId,i=this.container,a=(i?Array.from(i.childNodes):[]).find(m=>m instanceof HTMLElement&&m.getAttribute(S)===e);if(!t||!a)return null;const{width:r,height:o}=a.getBoundingClientRect(),n=t.getBoundingClientRect(),l=n.top+n.height/2-o/2,g=n.left+n.width/2-r/2,u=l+o,I=g+r;return{top:l,left:g,bottom:u,right:I}},this.onItemBlur=()=>{window.setTimeout(()=>{this.isUnmounted||this.shouldResetActive()&&!this.state.isDragging&&this.setState({activeId:""})})},this.onItemFocus=t=>{const{id:e,element:i}=this.closestSortableItem(t.currentTarget);!this.idComparer(e,this.state.activeId)&&this.isSameSortable(t.target)&&i===t.target&&this.setState({activeId:e})},this.onKeyDown=t=>{const{data:e,idField:i,onNavigate:s,navigation:a}=this.props,{activeId:r}=this.state;if(!a||!r||!this.isSameSortable(t.target))return;const o=this.isRtl,n=e.filter(b=>!this.isItemDisabled(b)),l=f.findIndex(n,b=>this.idComparer(b[i],r)),g=n.length-1;let u=l;switch(t.keyCode===h.Keys.left&&(o?t.keyCode=h.Keys.down:t.keyCode=h.Keys.up),t.keyCode===h.Keys.right&&(o?t.keyCode=h.Keys.up:t.keyCode=h.Keys.down),t.keyCode){case h.Keys.up:l>0&&(u=l-1);break;case h.Keys.down:l<g&&(u=l+1);break}if(u===l)return;t.stopPropagation(),t.preventDefault();const I=n[u],m=I?I[i]:"",D=n[l],T=D?D[i]:"";if(t.ctrlKey){if(s){const b=this.findIndex(T),C=this.findIndex(m),O=new B.SortableOnNavigateEvent(this,b,C,this.generateNewState(b,C));this.isKeyboardNavigated=!0,s.call(void 0,O)}}else this.focusActiveId=!0,this.setState({activeId:m+""})},this.resetState=t=>{this.isDragPrevented=!1,this.setState({clientX:0,clientY:0,isDragging:!1,dragCueWidth:0,dragCueHeight:0,activeId:t?"":this.state.activeId})},this.renderData=()=>{const{data:t,itemUI:e,idField:i,tabIndex:s}=this.props;return t.map(a=>{const o=h.getter(i)(a),n=this.isItemDisabled(a),l=this.idComparer(this.state.activeId,o);return p.createElement(e,{key:o,forwardRef:g=>this.refAssign(g,o),dataItem:a,isDisabled:n,isActive:l,isDragged:l&&this.state.isDragging,isDragCue:!1,attributes:{[S]:o,"aria-disabled":n,"aria-grabbed":l&&this.state.isDragging&&!this.isDragPrevented,"aria-dropeffect":n?"none":"move",tabIndex:h.getTabIndex(s,n),onFocus:this.onItemFocus,onBlur:this.onItemBlur},style:{cursor:n?"auto":"move",MozUserSelect:"none",msUserSelect:"none",WebkitUserSelect:"none",userSelect:"none"}})})},this.renderNoData=()=>{const{emptyItemUI:t}=this.props,i=x.provideLocalizationService(this).toLanguageString(R.noData,R.messages[R.noData]);if(t)return p.createElement(t,{message:i})},this.renderDragCue=()=>{const{itemUI:t}=this.props,{isDragging:e,activeId:i,clientX:s,clientY:a}=this.state,r=this.findItem(i);if(!(!e||!r))return p.createElement(t,{dataItem:r,isDisabled:!1,isActive:!0,isDragged:!0,isDragCue:!0,style:{position:"fixed",top:a+10,left:s+10,width:this.state.dragCueWidth,height:this.state.dragCueHeight},attributes:{}})},this.refAssign=(t,e)=>{t?this.itemRefsMap[e]=t:delete this.itemRefsMap[e]},this.draggableRefAssign=t=>{this.draggableRef=t},h.validatePackage(F.packageMetadata)}get container(){return this.draggableRef&&this.draggableRef.element}getSnapshotBeforeUpdate(){const{idField:c,animation:t}=this.props;return this.oldSizesMap={},t&&this.props.data.forEach(e=>{const i=e[c],s=this.itemRefsMap[i];s&&(this.oldSizesMap[i]=s.getBoundingClientRect())}),null}componentDidUpdate(c){const{idField:t,animation:e}=this.props;this.focusActiveId&&(this.focusActiveId=!1,this.itemRefsMap[this.state.activeId].focus()),!(!e||!this.state.isDragging&&!this.isKeyboardNavigated)&&(this.isKeyboardNavigated=!1,c.data.forEach(i=>{const s=i[t],a=this.itemRefsMap[s];if(!a)return;const r=a.getBoundingClientRect(),o=this.oldSizesMap[s],n=o.left-r.left,l=o.top-r.top;n===0&&l===0||requestAnimationFrame(()=>{this.animatingItemMap[s]=!0,a.style.transform=`translate(${n}px, ${l}px)`,a.style.transition="transform 0s",requestAnimationFrame(()=>{a.style.transform="",a.style.transition=`transform ${w}ms cubic-bezier(0.2, 0, 0, 1) 0s`,window.setTimeout(()=>this.animatingItemMap[s]=!1,w)})})}))}componentDidMount(){this.isRtl=this.container&&getComputedStyle(this.container).direction==="rtl"||!1}componentWillUnmount(){this.isUnmounted=!0}parentOffset(){const c=this.offsetParent;if(c&&c.ownerDocument&&c!==c.ownerDocument.body){const t=c.getBoundingClientRect();return{left:t.left-c.scrollLeft,top:t.top-c.scrollTop}}return{left:0,top:0}}render(){const{data:c,style:t,className:e,itemsWrapUI:i}=this.props,s=i||"div";return p.createElement(h.Draggable,{onDragStart:this.onDragStart,onDrag:this.onDragOver,onDragEnd:this.onDragEnd,ref:this.draggableRefAssign},p.createElement(s,{...q,className:e,style:{touchAction:"none",...t},onKeyDown:this.onKeyDown},c&&c.length?this.renderData():this.renderNoData(),this.renderDragCue()))}};y.defaultProps={navigation:!0,animation:!0,emptyItemUI:c=>p.createElement("div",null,c.message)},y.propTypes={idField:d.string.isRequired,disabledField:d.string,data:d.array.isRequired,tabIndex:d.number,navigation:d.bool,animation:d.bool,itemsWrapUI:d.any,itemUI:d.func.isRequired,emptyItemUI:d.func,style:d.object,className:d.string,onDragStart:d.func,onDragOver:d.func,onDragEnd:d.func,onNavigate:d.func};let E=y;x.registerForLocalization(E);exports.Sortable=E;
|
|
8
|
+
"use client";"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const N=require("react"),g=require("prop-types"),m=require("@progress/kendo-react-common"),P=require("./events/SortableOnDragStartEvent.js"),M=require("./events/SortableOnDragOverEvent.js"),U=require("./events/SortableOnDragEndEvent.js"),F=require("./events/SortableOnNavigateEvent.js"),T=require("@progress/kendo-react-intl"),R=require("./messages/index.js"),p=require("./utils/utils.js"),B=require("./package-metadata.js");function q(b){const c=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(b){for(const t in b)if(t!=="default"){const e=Object.getOwnPropertyDescriptor(b,t);Object.defineProperty(c,t,e.get?e:{enumerable:!0,get:()=>b[t]})}}return c.default=b,Object.freeze(c)}const v=q(N),A=200,D="data-sortable-id",C="data-sortable-component",w="[data-sortable-id]:not(.k-disabled)",k={[C]:!0},E=class E extends v.Component{constructor(c){super(c),this.state={clientX:0,clientY:0,isDragging:!1,activeId:"",dragCueWidth:0,dragCueHeight:0},this.isRtl=!1,this.itemRefsMap={},this.oldSizesMap={},this.animatingItemMap={},this.draggableRef=null,this.isUnmounted=!1,this.focusActiveId=!1,this.isKeyboardNavigated=!1,this.isDragPrevented=!1,this.swapItems=(t,e,i)=>{const s=t[e];return t[e]=t[i],t[i]=s,e=i,e},this.generateNewState=(t,e)=>{const{data:i}=this.props,s=[...i];if(t>e)for(let n=t-1;n>=e;n--){const o=i[n];this.isItemDisabled(o)||(t=this.swapItems(s,t,n))}else for(let n=t+1;n<=e;n++){const o=i[n];this.isItemDisabled(o)||(t=this.swapItems(s,t,n))}return s},this.closestSortableItem=t=>{let e=t;for(;e;){const i=e.getAttribute(D);if(i&&this.itemRefsMap[i]===e)return{id:i,element:e};e=e.parentElement}return{id:"",element:null}},this.isSortable=t=>!!t.hasAttribute(C),this.closestSortable=t=>{let e=t;for(;e;){if(this.isSortable(e))return e;e=e.parentElement}return null},this.isSameSortable=t=>this.closestSortable(t)===this.container,this.idComparer=(t,e)=>t+""==e+"",this.findItem=t=>{const{data:e,idField:i}=this.props;if(!(t+""))return;const s=m.getter(i);return p.find(e,a=>this.idComparer(s(a),t))},this.findIndex=t=>{const{data:e,idField:i}=this.props;return t+""?p.findIndex(e,s=>this.idComparer(s[i],t)):-1},this.isItemDisabled=t=>t&&t[this.props.disabledField||""]===!0,this.shouldResetActive=()=>{const t=m.getActiveElement(document);return t instanceof HTMLElement?!this.closestSortableItem(t).element:!1},this.widgetTarget=t=>{const e=p.closest(t,i=>p.hasClasses(i,"k-widget")||this.isSortable(i));return e&&!this.isSortable(e)},this.allowDrag=t=>t.hasAttribute(D)||!(p.isFocusable(t)||this.widgetTarget(t)),this.onDragStart=t=>{const{event:e}=t,{onDragStart:i}=this.props,s=document.elementFromPoint(e.clientX,e.clientY),{id:a,element:n}=this.closestSortableItem(s),o=this.findItem(a);if(!a||o&&this.isItemDisabled(o)||!this.allowDrag(s)||!this.isSameSortable(s)){this.isDragPrevented=!0;return}e.isTouch&&e.originalEvent.preventDefault();const r=new P.SortableOnDragStartEvent(this,this.findIndex(a),s);i&&i.call(void 0,r),this.isDragPrevented=r.isDefaultPrevented(),this.isDragPrevented?e.originalEvent.preventDefault():(this.offsetParent=p.relativeContextElement(this.container),this.setState({activeId:a,dragCueWidth:n&&n.clientWidth||0,dragCueHeight:n&&n.clientHeight||0}))},this.onDragOver=t=>{const{event:e}=t,{onDragOver:i,data:s}=this.props;if(this.isDragPrevented)return;e.originalEvent.preventDefault();const a=this.findIndex(this.state.activeId);if(a===-1){this.resetState();return}const n=document.elementFromPoint(e.clientX,e.clientY),o=this.closestSortableItem(n),r=this.findIndex(o.id),l=s[r];if(i&&r>-1&&a!==r&&!this.isItemDisabled(l)&&!this.animatingItemMap[o.id]&&this.shouldReorder(o.element,e.clientX,e.clientY)){const h=new M.SortableOnDragOverEvent(this,a,r,this.generateNewState(a,r));i.call(void 0,h)}const d=this.parentOffset();this.setState({clientX:e.clientX-d.left,clientY:e.clientY-d.top,isDragging:!0})},this.onDragEnd=t=>{const{event:e}=t,i=this.shouldResetActive();if(this.isDragPrevented)return;const{onDragEnd:s,data:a}=this.props,n=document.elementFromPoint(e.clientX,e.clientY),o=this.closestSortableItem(n);let r=this.findIndex(o.id),l=this.findIndex(this.state.activeId);const d=this.isItemDisabled(a[r]);if((r===-1||d)&&(r=l),s){let h=this.generateNewState(l,r);if(!d){const u=this.thresholdRect(o.element);if(u&&(e.clientX<u.left||e.clientX>u.right||e.clientY<u.top||e.clientY>u.bottom)){const I=l;l=r,r=I,h=this.props.data.slice()}}const f=new U.SortableOnDragEndEvent(this,l,r,h);s.call(void 0,f)}this.resetState(i)},this.shouldReorder=(t,e,i)=>{const s=this.thresholdRect(t);return s&&e>s.left&&e<s.right&&i>s.top&&i<s.bottom},this.thresholdRect=t=>{const e=this.state.activeId,i=this.container,a=(i?Array.from(i.childNodes):[]).find(u=>u instanceof HTMLElement&&u.getAttribute(D)===e);if(!t||!a)return null;const{width:n,height:o}=a.getBoundingClientRect(),r=t.getBoundingClientRect(),l=r.top+r.height/2-o/2,d=r.left+r.width/2-n/2,h=l+o,f=d+n;return{top:l,left:d,bottom:h,right:f}},this.onItemBlur=()=>{window.setTimeout(()=>{this.isUnmounted||this.shouldResetActive()&&!this.state.isDragging&&this.setState({activeId:""})})},this.onItemFocus=t=>{const{id:e,element:i}=this.closestSortableItem(t.currentTarget);!this.idComparer(e,this.state.activeId)&&this.isSameSortable(t.target)&&i===t.target&&this.setState({activeId:e})},this.resetState=t=>{this.isDragPrevented=!1,this.setState({clientX:0,clientY:0,isDragging:!1,dragCueWidth:0,dragCueHeight:0,activeId:t?"":this.state.activeId})},this.renderData=()=>{const{data:t,itemUI:e,idField:i,tabIndex:s,navigatable:a}=this.props;return t.map(n=>{const r=m.getter(i)(n),l=this.isItemDisabled(n),d=this.idComparer(this.state.activeId,r),h=a?d?0:-1:s;return v.createElement(e,{key:r,forwardRef:f=>this.refAssign(f,r),dataItem:n,isDisabled:l,isActive:d,isDragged:d&&this.state.isDragging,isDragCue:!1,attributes:{[D]:r,"aria-disabled":l,"aria-grabbed":d&&this.state.isDragging&&!this.isDragPrevented,"aria-dropeffect":l?"none":"move",tabIndex:m.getTabIndex(h,l),onFocus:this.onItemFocus,onBlur:this.onItemBlur},style:{cursor:l?"auto":"move",MozUserSelect:"none",msUserSelect:"none",WebkitUserSelect:"none",userSelect:"none"}})})},this.renderNoData=()=>{const{emptyItemUI:t}=this.props,i=T.provideLocalizationService(this).toLanguageString(R.noData,R.messages[R.noData]);if(t)return v.createElement(t,{message:i})},this.renderDragCue=()=>{const{itemUI:t}=this.props,{isDragging:e,activeId:i,clientX:s,clientY:a}=this.state,n=this.findItem(i);if(!(!e||!n))return v.createElement(t,{dataItem:n,isDisabled:!1,isActive:!0,isDragged:!0,isDragCue:!0,style:{position:"fixed",top:a+10,left:s+10,width:this.state.dragCueWidth,height:this.state.dragCueHeight},attributes:{}})},this.refAssign=(t,e)=>{t?this.itemRefsMap[e]=t:delete this.itemRefsMap[e]},this.draggableRefAssign=t=>{this.draggableRef=t},this.onKeyDown=t=>{var r,l,d;const{data:e,idField:i}=this.props,{activeId:s}=this.state,a=e.filter(h=>!this.isItemDisabled(h)),n=p.findIndex(a,h=>this.idComparer(h[i],s)),o=n<0?0:n;t.key===m.KEYS.tab&&m.getActiveElement(document)!==((r=this.draggableRef)==null?void 0:r.element)&&(t.preventDefault(),t.stopPropagation()),this.navigation&&((l=this.draggableRef)!=null&&l.element)&&this.navigation.triggerKeyboardEvent({target:(d=this.draggableRef)==null?void 0:d.element.querySelectorAll(w)[o],key:t.key,nativeEvent:{type:t.type},originalEvent:t})},this.handleNext=(t,e,i)=>{var s;m.getActiveElement(document)!==((s=this.draggableRef)==null?void 0:s.element)&&(i.originalEvent.metaKey?this.moveItem(t,e,i,"next"):e.focusNext(t))},this.handlePrev=(t,e,i)=>{var s;m.getActiveElement(document)!==((s=this.draggableRef)==null?void 0:s.element)&&(i.originalEvent.metaKey?this.moveItem(t,e,i,"prev"):e.focusPrevious(t))},this.moveItem=(t,e,i,s)=>{var a;if(m.getActiveElement(document)!==((a=this.draggableRef)==null?void 0:a.element)){const{onNavigate:n,data:o,idField:r}=this.props,l=this.findIndex(this.state.activeId);if(n){let d,h;s==="next"?(d=o[l+1],h=d&&d.disabled?o[l+2]:o[l+1]):(d=o[l-1],h=d&&d.disabled?o[l-2]:o[l-1]);const f=h&&h[r],u=o[l],I=u?u[r]:"",y=this.findIndex(I),x=this.findIndex(f||I),O=new F.SortableOnNavigateEvent(this,y,x,this.generateNewState(y,x));this.isKeyboardNavigated=!0,n.call(void 0,O)}}},m.validatePackage(B.packageMetadata),this.onKeyDown=this.onKeyDown.bind(this)}get container(){return this.draggableRef&&this.draggableRef.element}getSnapshotBeforeUpdate(){const{idField:c,animation:t}=this.props;return this.oldSizesMap={},t&&this.props.data.forEach(e=>{const i=e[c],s=this.itemRefsMap[i];s&&(this.oldSizesMap[i]=s.getBoundingClientRect())}),null}componentDidUpdate(c){const{idField:t,animation:e}=this.props;this.focusActiveId&&(this.focusActiveId=!1,this.itemRefsMap[this.state.activeId].focus()),!(!e||!this.state.isDragging&&!this.isKeyboardNavigated)&&(this.isKeyboardNavigated=!1,c.data.forEach(i=>{const s=i[t],a=this.itemRefsMap[s];if(!a)return;const n=a.getBoundingClientRect(),o=this.oldSizesMap[s],r=o.left-n.left,l=o.top-n.top;r===0&&l===0||requestAnimationFrame(()=>{this.animatingItemMap[s]=!0,a.style.transform=`translate(${r}px, ${l}px)`,a.style.transition="transform 0s",requestAnimationFrame(()=>{a.style.transform="",a.style.transition=`transform ${A}ms cubic-bezier(0.2, 0, 0, 1) 0s`,window.setTimeout(()=>this.animatingItemMap[s]=!1,A)})})}))}componentDidMount(){var c,t;(c=this.draggableRef)!=null&&c.element&&(this.navigation=new m.Navigation({tabIndex:0,root:{current:(t=this.draggableRef)==null?void 0:t.element},rovingTabIndex:!0,selectors:[w],keyboardEvents:{keydown:{ArrowDown:this.handleNext,ArrowRight:this.handleNext,ArrowUp:this.handlePrev,ArrowLeft:this.handlePrev,Enter:(e,i,s)=>{i.focusElement(i.first,e)},Escape:(e,i,s)=>{var a,n;e.setAttribute("tabindex","-1"),(n=(a=this.draggableRef)==null?void 0:a.element)==null||n.focus(),this.setState({activeId:""})}}}})),this.isRtl=this.container&&getComputedStyle(this.container).direction==="rtl"||!1}componentWillUnmount(){this.isUnmounted=!0}parentOffset(){const c=this.offsetParent;if(c&&c.ownerDocument&&c!==c.ownerDocument.body){const t=c.getBoundingClientRect();return{left:t.left-c.scrollLeft,top:t.top-c.scrollTop}}return{left:0,top:0}}render(){const{data:c,style:t,className:e,itemsWrapUI:i,tabIndex:s,navigatable:a}=this.props,n=i||"div";return v.createElement(m.Draggable,{onDragStart:this.onDragStart,onDrag:this.onDragOver,onDragEnd:this.onDragEnd,ref:this.draggableRefAssign},v.createElement(n,{onKeyDown:o=>a&&this.onKeyDown(o),...k,className:e,style:{touchAction:"none",...t},tabIndex:a?s||0:void 0},c&&c.length?this.renderData():this.renderNoData(),this.renderDragCue()))}};E.defaultProps={navigation:!0,animation:!0,emptyItemUI:c=>v.createElement("div",null,c.message)},E.propTypes={idField:g.string.isRequired,disabledField:g.string,data:g.array.isRequired,tabIndex:g.number,navigation:g.bool,animation:g.bool,itemsWrapUI:g.any,itemUI:g.func.isRequired,emptyItemUI:g.func,style:g.object,className:g.string,onDragStart:g.func,onDragOver:g.func,onDragEnd:g.func,onNavigate:g.func};let S=E;T.registerForLocalization(S);exports.Sortable=S;
|
package/Sortable.mjs
CHANGED
|
@@ -7,17 +7,17 @@
|
|
|
7
7
|
*/
|
|
8
8
|
"use client";
|
|
9
9
|
import * as u from "react";
|
|
10
|
-
import
|
|
11
|
-
import { getter as R, getActiveElement as
|
|
12
|
-
import { SortableOnDragStartEvent as
|
|
13
|
-
import { SortableOnDragOverEvent as
|
|
14
|
-
import { SortableOnDragEndEvent as
|
|
15
|
-
import { SortableOnNavigateEvent as
|
|
16
|
-
import { provideLocalizationService as
|
|
17
|
-
import { noData as
|
|
18
|
-
import { find as
|
|
19
|
-
import { packageMetadata as
|
|
20
|
-
const
|
|
10
|
+
import m from "prop-types";
|
|
11
|
+
import { getter as R, getActiveElement as p, getTabIndex as N, KEYS as P, validatePackage as U, Navigation as M, Draggable as O } from "@progress/kendo-react-common";
|
|
12
|
+
import { SortableOnDragStartEvent as F } from "./events/SortableOnDragStartEvent.mjs";
|
|
13
|
+
import { SortableOnDragOverEvent as B } from "./events/SortableOnDragOverEvent.mjs";
|
|
14
|
+
import { SortableOnDragEndEvent as K } from "./events/SortableOnDragEndEvent.mjs";
|
|
15
|
+
import { SortableOnNavigateEvent as Y } from "./events/SortableOnNavigateEvent.mjs";
|
|
16
|
+
import { provideLocalizationService as k, registerForLocalization as L } from "@progress/kendo-react-intl";
|
|
17
|
+
import { noData as x, messages as X } from "./messages/index.mjs";
|
|
18
|
+
import { find as z, findIndex as y, closest as W, isFocusable as H, relativeContextElement as _, hasClasses as q } from "./utils/utils.mjs";
|
|
19
|
+
import { packageMetadata as G } from "./package-metadata.mjs";
|
|
20
|
+
const A = 200, I = "data-sortable-id", T = "data-sortable-component", w = "[data-sortable-id]:not(.k-disabled)", $ = { [T]: !0 }, b = class b extends u.Component {
|
|
21
21
|
constructor(c) {
|
|
22
22
|
super(c), this.state = {
|
|
23
23
|
clientX: 0,
|
|
@@ -27,25 +27,25 @@ const w = 200, b = "data-sortable-id", x = "data-sortable-component", G = { [x]:
|
|
|
27
27
|
dragCueWidth: 0,
|
|
28
28
|
dragCueHeight: 0
|
|
29
29
|
}, this.isRtl = !1, this.itemRefsMap = {}, this.oldSizesMap = {}, this.animatingItemMap = {}, this.draggableRef = null, this.isUnmounted = !1, this.focusActiveId = !1, this.isKeyboardNavigated = !1, this.isDragPrevented = !1, this.swapItems = (t, e, i) => {
|
|
30
|
-
|
|
30
|
+
const s = t[e];
|
|
31
31
|
return t[e] = t[i], t[i] = s, e = i, e;
|
|
32
32
|
}, this.generateNewState = (t, e) => {
|
|
33
33
|
const { data: i } = this.props, s = [...i];
|
|
34
34
|
if (t > e)
|
|
35
|
-
for (let
|
|
36
|
-
const o = i[
|
|
37
|
-
this.isItemDisabled(o) || (t = this.swapItems(s, t,
|
|
35
|
+
for (let n = t - 1; n >= e; n--) {
|
|
36
|
+
const o = i[n];
|
|
37
|
+
this.isItemDisabled(o) || (t = this.swapItems(s, t, n));
|
|
38
38
|
}
|
|
39
39
|
else
|
|
40
|
-
for (let
|
|
41
|
-
const o = i[
|
|
42
|
-
this.isItemDisabled(o) || (t = this.swapItems(s, t,
|
|
40
|
+
for (let n = t + 1; n <= e; n++) {
|
|
41
|
+
const o = i[n];
|
|
42
|
+
this.isItemDisabled(o) || (t = this.swapItems(s, t, n));
|
|
43
43
|
}
|
|
44
44
|
return s;
|
|
45
45
|
}, this.closestSortableItem = (t) => {
|
|
46
46
|
let e = t;
|
|
47
47
|
for (; e; ) {
|
|
48
|
-
const i = e.getAttribute(
|
|
48
|
+
const i = e.getAttribute(I);
|
|
49
49
|
if (i && this.itemRefsMap[i] === e)
|
|
50
50
|
return {
|
|
51
51
|
id: i,
|
|
@@ -57,7 +57,7 @@ const w = 200, b = "data-sortable-id", x = "data-sortable-component", G = { [x]:
|
|
|
57
57
|
id: "",
|
|
58
58
|
element: null
|
|
59
59
|
};
|
|
60
|
-
}, this.isSortable = (t) => !!t.hasAttribute(
|
|
60
|
+
}, this.isSortable = (t) => !!t.hasAttribute(T), this.closestSortable = (t) => {
|
|
61
61
|
let e = t;
|
|
62
62
|
for (; e; ) {
|
|
63
63
|
if (this.isSortable(e))
|
|
@@ -70,32 +70,32 @@ const w = 200, b = "data-sortable-id", x = "data-sortable-component", G = { [x]:
|
|
|
70
70
|
if (!(t + ""))
|
|
71
71
|
return;
|
|
72
72
|
const s = R(i);
|
|
73
|
-
return
|
|
73
|
+
return z(e, (a) => this.idComparer(s(a), t));
|
|
74
74
|
}, this.findIndex = (t) => {
|
|
75
75
|
const { data: e, idField: i } = this.props;
|
|
76
76
|
return t + "" ? y(e, (s) => this.idComparer(s[i], t)) : -1;
|
|
77
77
|
}, this.isItemDisabled = (t) => t && t[this.props.disabledField || ""] === !0, this.shouldResetActive = () => {
|
|
78
|
-
const t =
|
|
78
|
+
const t = p(document);
|
|
79
79
|
return t instanceof HTMLElement ? !this.closestSortableItem(t).element : !1;
|
|
80
80
|
}, this.widgetTarget = (t) => {
|
|
81
|
-
const e =
|
|
81
|
+
const e = W(t, (i) => q(i, "k-widget") || this.isSortable(i));
|
|
82
82
|
return e && !this.isSortable(e);
|
|
83
|
-
}, this.allowDrag = (t) => t.hasAttribute(
|
|
84
|
-
const { event: e } = t, { onDragStart: i } = this.props, s = document.elementFromPoint(e.clientX, e.clientY), { id: a, element:
|
|
83
|
+
}, this.allowDrag = (t) => t.hasAttribute(I) || !(H(t) || this.widgetTarget(t)), this.onDragStart = (t) => {
|
|
84
|
+
const { event: e } = t, { onDragStart: i } = this.props, s = document.elementFromPoint(e.clientX, e.clientY), { id: a, element: n } = this.closestSortableItem(s), o = this.findItem(a);
|
|
85
85
|
if (!a || o && this.isItemDisabled(o) || !this.allowDrag(s) || !this.isSameSortable(s)) {
|
|
86
86
|
this.isDragPrevented = !0;
|
|
87
87
|
return;
|
|
88
88
|
}
|
|
89
89
|
e.isTouch && e.originalEvent.preventDefault();
|
|
90
|
-
const
|
|
90
|
+
const r = new F(
|
|
91
91
|
this,
|
|
92
92
|
this.findIndex(a),
|
|
93
93
|
s
|
|
94
94
|
);
|
|
95
|
-
i && i.call(void 0,
|
|
95
|
+
i && i.call(void 0, r), this.isDragPrevented = r.isDefaultPrevented(), this.isDragPrevented ? e.originalEvent.preventDefault() : (this.offsetParent = _(this.container), this.setState({
|
|
96
96
|
activeId: a,
|
|
97
|
-
dragCueWidth:
|
|
98
|
-
dragCueHeight:
|
|
97
|
+
dragCueWidth: n && n.clientWidth || 0,
|
|
98
|
+
dragCueHeight: n && n.clientHeight || 0
|
|
99
99
|
}));
|
|
100
100
|
}, this.onDragOver = (t) => {
|
|
101
101
|
const { event: e } = t, { onDragOver: i, data: s } = this.props;
|
|
@@ -107,45 +107,45 @@ const w = 200, b = "data-sortable-id", x = "data-sortable-component", G = { [x]:
|
|
|
107
107
|
this.resetState();
|
|
108
108
|
return;
|
|
109
109
|
}
|
|
110
|
-
const
|
|
111
|
-
if (i &&
|
|
112
|
-
const
|
|
110
|
+
const n = document.elementFromPoint(e.clientX, e.clientY), o = this.closestSortableItem(n), r = this.findIndex(o.id), l = s[r];
|
|
111
|
+
if (i && r > -1 && a !== r && !this.isItemDisabled(l) && !this.animatingItemMap[o.id] && this.shouldReorder(o.element, e.clientX, e.clientY)) {
|
|
112
|
+
const h = new B(
|
|
113
113
|
this,
|
|
114
114
|
a,
|
|
115
|
-
|
|
116
|
-
this.generateNewState(a,
|
|
115
|
+
r,
|
|
116
|
+
this.generateNewState(a, r)
|
|
117
117
|
);
|
|
118
|
-
i.call(void 0,
|
|
118
|
+
i.call(void 0, h);
|
|
119
119
|
}
|
|
120
|
-
const
|
|
120
|
+
const d = this.parentOffset();
|
|
121
121
|
this.setState({
|
|
122
|
-
clientX: e.clientX -
|
|
123
|
-
clientY: e.clientY -
|
|
122
|
+
clientX: e.clientX - d.left,
|
|
123
|
+
clientY: e.clientY - d.top,
|
|
124
124
|
isDragging: !0
|
|
125
125
|
});
|
|
126
126
|
}, this.onDragEnd = (t) => {
|
|
127
127
|
const { event: e } = t, i = this.shouldResetActive();
|
|
128
128
|
if (this.isDragPrevented)
|
|
129
129
|
return;
|
|
130
|
-
const { onDragEnd: s, data: a } = this.props,
|
|
131
|
-
let
|
|
132
|
-
const
|
|
133
|
-
if ((
|
|
134
|
-
let
|
|
135
|
-
if (!
|
|
130
|
+
const { onDragEnd: s, data: a } = this.props, n = document.elementFromPoint(e.clientX, e.clientY), o = this.closestSortableItem(n);
|
|
131
|
+
let r = this.findIndex(o.id), l = this.findIndex(this.state.activeId);
|
|
132
|
+
const d = this.isItemDisabled(a[r]);
|
|
133
|
+
if ((r === -1 || d) && (r = l), s) {
|
|
134
|
+
let h = this.generateNewState(l, r);
|
|
135
|
+
if (!d) {
|
|
136
136
|
const g = this.thresholdRect(o.element);
|
|
137
137
|
if (g && (e.clientX < g.left || e.clientX > g.right || e.clientY < g.top || e.clientY > g.bottom)) {
|
|
138
138
|
const v = l;
|
|
139
|
-
l =
|
|
139
|
+
l = r, r = v, h = this.props.data.slice();
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
|
-
const
|
|
142
|
+
const f = new K(
|
|
143
143
|
this,
|
|
144
144
|
l,
|
|
145
|
-
|
|
146
|
-
|
|
145
|
+
r,
|
|
146
|
+
h
|
|
147
147
|
);
|
|
148
|
-
s.call(void 0,
|
|
148
|
+
s.call(void 0, f);
|
|
149
149
|
}
|
|
150
150
|
this.resetState(i);
|
|
151
151
|
}, this.shouldReorder = (t, e, i) => {
|
|
@@ -153,12 +153,12 @@ const w = 200, b = "data-sortable-id", x = "data-sortable-component", G = { [x]:
|
|
|
153
153
|
return s && e > s.left && e < s.right && i > s.top && i < s.bottom;
|
|
154
154
|
}, this.thresholdRect = (t) => {
|
|
155
155
|
const e = this.state.activeId, i = this.container, a = (i ? Array.from(i.childNodes) : []).find(
|
|
156
|
-
(g) => g instanceof HTMLElement && g.getAttribute(
|
|
156
|
+
(g) => g instanceof HTMLElement && g.getAttribute(I) === e
|
|
157
157
|
);
|
|
158
158
|
if (!t || !a)
|
|
159
159
|
return null;
|
|
160
|
-
const { width:
|
|
161
|
-
return { top: l, left:
|
|
160
|
+
const { width: n, height: o } = a.getBoundingClientRect(), r = t.getBoundingClientRect(), l = r.top + r.height / 2 - o / 2, d = r.left + r.width / 2 - n / 2, h = l + o, f = d + n;
|
|
161
|
+
return { top: l, left: d, bottom: h, right: f };
|
|
162
162
|
}, this.onItemBlur = () => {
|
|
163
163
|
window.setTimeout(() => {
|
|
164
164
|
this.isUnmounted || this.shouldResetActive() && !this.state.isDragging && this.setState({
|
|
@@ -171,38 +171,6 @@ const w = 200, b = "data-sortable-id", x = "data-sortable-component", G = { [x]:
|
|
|
171
171
|
!this.idComparer(e, this.state.activeId) && this.isSameSortable(t.target) && i === t.target && this.setState({
|
|
172
172
|
activeId: e
|
|
173
173
|
});
|
|
174
|
-
}, this.onKeyDown = (t) => {
|
|
175
|
-
const { data: e, idField: i, onNavigate: s, navigation: a } = this.props, { activeId: r } = this.state;
|
|
176
|
-
if (!a || !r || !this.isSameSortable(t.target))
|
|
177
|
-
return;
|
|
178
|
-
const o = this.isRtl, n = e.filter((I) => !this.isItemDisabled(I)), l = y(n, (I) => this.idComparer(I[i], r)), h = n.length - 1;
|
|
179
|
-
let m = l;
|
|
180
|
-
switch (t.keyCode === f.left && (o ? t.keyCode = f.down : t.keyCode = f.up), t.keyCode === f.right && (o ? t.keyCode = f.up : t.keyCode = f.down), t.keyCode) {
|
|
181
|
-
case f.up:
|
|
182
|
-
l > 0 && (m = l - 1);
|
|
183
|
-
break;
|
|
184
|
-
case f.down:
|
|
185
|
-
l < h && (m = l + 1);
|
|
186
|
-
break;
|
|
187
|
-
}
|
|
188
|
-
if (m === l)
|
|
189
|
-
return;
|
|
190
|
-
t.stopPropagation(), t.preventDefault();
|
|
191
|
-
const p = n[m], g = p ? p[i] : "", v = n[l], A = v ? v[i] : "";
|
|
192
|
-
if (t.ctrlKey) {
|
|
193
|
-
if (s) {
|
|
194
|
-
const I = this.findIndex(A), E = this.findIndex(g), T = new k(
|
|
195
|
-
this,
|
|
196
|
-
I,
|
|
197
|
-
E,
|
|
198
|
-
this.generateNewState(I, E)
|
|
199
|
-
);
|
|
200
|
-
this.isKeyboardNavigated = !0, s.call(void 0, T);
|
|
201
|
-
}
|
|
202
|
-
} else
|
|
203
|
-
this.focusActiveId = !0, this.setState({
|
|
204
|
-
activeId: g + ""
|
|
205
|
-
});
|
|
206
174
|
}, this.resetState = (t) => {
|
|
207
175
|
this.isDragPrevented = !1, this.setState({
|
|
208
176
|
clientX: 0,
|
|
@@ -213,35 +181,30 @@ const w = 200, b = "data-sortable-id", x = "data-sortable-component", G = { [x]:
|
|
|
213
181
|
activeId: t ? "" : this.state.activeId
|
|
214
182
|
});
|
|
215
183
|
}, this.renderData = () => {
|
|
216
|
-
const {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
idField: i,
|
|
220
|
-
tabIndex: s
|
|
221
|
-
} = this.props;
|
|
222
|
-
return t.map((a) => {
|
|
223
|
-
const o = R(i)(a), n = this.isItemDisabled(a), l = this.idComparer(this.state.activeId, o);
|
|
184
|
+
const { data: t, itemUI: e, idField: i, tabIndex: s, navigatable: a } = this.props;
|
|
185
|
+
return t.map((n) => {
|
|
186
|
+
const r = R(i)(n), l = this.isItemDisabled(n), d = this.idComparer(this.state.activeId, r), h = a ? d ? 0 : -1 : s;
|
|
224
187
|
return /* @__PURE__ */ u.createElement(
|
|
225
188
|
e,
|
|
226
189
|
{
|
|
227
|
-
key:
|
|
228
|
-
forwardRef: (
|
|
229
|
-
dataItem:
|
|
230
|
-
isDisabled:
|
|
231
|
-
isActive:
|
|
232
|
-
isDragged:
|
|
190
|
+
key: r,
|
|
191
|
+
forwardRef: (f) => this.refAssign(f, r),
|
|
192
|
+
dataItem: n,
|
|
193
|
+
isDisabled: l,
|
|
194
|
+
isActive: d,
|
|
195
|
+
isDragged: d && this.state.isDragging,
|
|
233
196
|
isDragCue: !1,
|
|
234
197
|
attributes: {
|
|
235
|
-
[
|
|
236
|
-
"aria-disabled":
|
|
237
|
-
"aria-grabbed":
|
|
238
|
-
"aria-dropeffect":
|
|
239
|
-
tabIndex:
|
|
198
|
+
[I]: r,
|
|
199
|
+
"aria-disabled": l,
|
|
200
|
+
"aria-grabbed": d && this.state.isDragging && !this.isDragPrevented,
|
|
201
|
+
"aria-dropeffect": l ? "none" : "move",
|
|
202
|
+
tabIndex: N(h, l),
|
|
240
203
|
onFocus: this.onItemFocus,
|
|
241
204
|
onBlur: this.onItemBlur
|
|
242
205
|
},
|
|
243
206
|
style: {
|
|
244
|
-
cursor:
|
|
207
|
+
cursor: l ? "auto" : "move",
|
|
245
208
|
MozUserSelect: "none",
|
|
246
209
|
msUserSelect: "none",
|
|
247
210
|
WebkitUserSelect: "none",
|
|
@@ -251,16 +214,16 @@ const w = 200, b = "data-sortable-id", x = "data-sortable-component", G = { [x]:
|
|
|
251
214
|
);
|
|
252
215
|
});
|
|
253
216
|
}, this.renderNoData = () => {
|
|
254
|
-
const { emptyItemUI: t } = this.props, i =
|
|
217
|
+
const { emptyItemUI: t } = this.props, i = k(this).toLanguageString(x, X[x]);
|
|
255
218
|
if (t)
|
|
256
219
|
return /* @__PURE__ */ u.createElement(t, { message: i });
|
|
257
220
|
}, this.renderDragCue = () => {
|
|
258
|
-
const { itemUI: t } = this.props, { isDragging: e, activeId: i, clientX: s, clientY: a } = this.state,
|
|
259
|
-
if (!(!e || !
|
|
221
|
+
const { itemUI: t } = this.props, { isDragging: e, activeId: i, clientX: s, clientY: a } = this.state, n = this.findItem(i);
|
|
222
|
+
if (!(!e || !n))
|
|
260
223
|
return /* @__PURE__ */ u.createElement(
|
|
261
224
|
t,
|
|
262
225
|
{
|
|
263
|
-
dataItem:
|
|
226
|
+
dataItem: n,
|
|
264
227
|
isDisabled: !1,
|
|
265
228
|
isActive: !0,
|
|
266
229
|
isDragged: !0,
|
|
@@ -279,7 +242,38 @@ const w = 200, b = "data-sortable-id", x = "data-sortable-component", G = { [x]:
|
|
|
279
242
|
t ? this.itemRefsMap[e] = t : delete this.itemRefsMap[e];
|
|
280
243
|
}, this.draggableRefAssign = (t) => {
|
|
281
244
|
this.draggableRef = t;
|
|
282
|
-
},
|
|
245
|
+
}, this.onKeyDown = (t) => {
|
|
246
|
+
var r, l, d;
|
|
247
|
+
const { data: e, idField: i } = this.props, { activeId: s } = this.state, a = e.filter((h) => !this.isItemDisabled(h)), n = y(a, (h) => this.idComparer(h[i], s)), o = n < 0 ? 0 : n;
|
|
248
|
+
t.key === P.tab && p(document) !== ((r = this.draggableRef) == null ? void 0 : r.element) && (t.preventDefault(), t.stopPropagation()), this.navigation && ((l = this.draggableRef) != null && l.element) && this.navigation.triggerKeyboardEvent({
|
|
249
|
+
target: (d = this.draggableRef) == null ? void 0 : d.element.querySelectorAll(w)[o],
|
|
250
|
+
key: t.key,
|
|
251
|
+
nativeEvent: { type: t.type },
|
|
252
|
+
originalEvent: t
|
|
253
|
+
});
|
|
254
|
+
}, this.handleNext = (t, e, i) => {
|
|
255
|
+
var s;
|
|
256
|
+
p(document) !== ((s = this.draggableRef) == null ? void 0 : s.element) && (i.originalEvent.metaKey ? this.moveItem(t, e, i, "next") : e.focusNext(t));
|
|
257
|
+
}, this.handlePrev = (t, e, i) => {
|
|
258
|
+
var s;
|
|
259
|
+
p(document) !== ((s = this.draggableRef) == null ? void 0 : s.element) && (i.originalEvent.metaKey ? this.moveItem(t, e, i, "prev") : e.focusPrevious(t));
|
|
260
|
+
}, this.moveItem = (t, e, i, s) => {
|
|
261
|
+
var a;
|
|
262
|
+
if (p(document) !== ((a = this.draggableRef) == null ? void 0 : a.element)) {
|
|
263
|
+
const { onNavigate: n, data: o, idField: r } = this.props, l = this.findIndex(this.state.activeId);
|
|
264
|
+
if (n) {
|
|
265
|
+
let d, h;
|
|
266
|
+
s === "next" ? (d = o[l + 1], h = d && d.disabled ? o[l + 2] : o[l + 1]) : (d = o[l - 1], h = d && d.disabled ? o[l - 2] : o[l - 1]);
|
|
267
|
+
const f = h && h[r], g = o[l], v = g ? g[r] : "", S = this.findIndex(v), E = this.findIndex(f || v), C = new Y(
|
|
268
|
+
this,
|
|
269
|
+
S,
|
|
270
|
+
E,
|
|
271
|
+
this.generateNewState(S, E)
|
|
272
|
+
);
|
|
273
|
+
this.isKeyboardNavigated = !0, n.call(void 0, C);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}, U(G), this.onKeyDown = this.onKeyDown.bind(this);
|
|
283
277
|
}
|
|
284
278
|
get container() {
|
|
285
279
|
return this.draggableRef && this.draggableRef.element;
|
|
@@ -303,10 +297,10 @@ const w = 200, b = "data-sortable-id", x = "data-sortable-component", G = { [x]:
|
|
|
303
297
|
const s = i[t], a = this.itemRefsMap[s];
|
|
304
298
|
if (!a)
|
|
305
299
|
return;
|
|
306
|
-
const
|
|
307
|
-
|
|
308
|
-
this.animatingItemMap[s] = !0, a.style.transform = `translate(${
|
|
309
|
-
a.style.transform = "", a.style.transition = `transform ${
|
|
300
|
+
const n = a.getBoundingClientRect(), o = this.oldSizesMap[s], r = o.left - n.left, l = o.top - n.top;
|
|
301
|
+
r === 0 && l === 0 || requestAnimationFrame(() => {
|
|
302
|
+
this.animatingItemMap[s] = !0, a.style.transform = `translate(${r}px, ${l}px)`, a.style.transition = "transform 0s", requestAnimationFrame(() => {
|
|
303
|
+
a.style.transform = "", a.style.transition = `transform ${A}ms cubic-bezier(0.2, 0, 0, 1) 0s`, window.setTimeout(() => this.animatingItemMap[s] = !1, A);
|
|
310
304
|
});
|
|
311
305
|
});
|
|
312
306
|
}));
|
|
@@ -315,7 +309,28 @@ const w = 200, b = "data-sortable-id", x = "data-sortable-component", G = { [x]:
|
|
|
315
309
|
* @hidden
|
|
316
310
|
*/
|
|
317
311
|
componentDidMount() {
|
|
318
|
-
|
|
312
|
+
var c, t;
|
|
313
|
+
(c = this.draggableRef) != null && c.element && (this.navigation = new M({
|
|
314
|
+
tabIndex: 0,
|
|
315
|
+
root: { current: (t = this.draggableRef) == null ? void 0 : t.element },
|
|
316
|
+
rovingTabIndex: !0,
|
|
317
|
+
selectors: [w],
|
|
318
|
+
keyboardEvents: {
|
|
319
|
+
keydown: {
|
|
320
|
+
ArrowDown: this.handleNext,
|
|
321
|
+
ArrowRight: this.handleNext,
|
|
322
|
+
ArrowUp: this.handlePrev,
|
|
323
|
+
ArrowLeft: this.handlePrev,
|
|
324
|
+
Enter: (e, i, s) => {
|
|
325
|
+
i.focusElement(i.first, e);
|
|
326
|
+
},
|
|
327
|
+
Escape: (e, i, s) => {
|
|
328
|
+
var a, n;
|
|
329
|
+
e.setAttribute("tabindex", "-1"), (n = (a = this.draggableRef) == null ? void 0 : a.element) == null || n.focus(), this.setState({ activeId: "" });
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
})), this.isRtl = this.container && getComputedStyle(this.container).direction === "rtl" || !1;
|
|
319
334
|
}
|
|
320
335
|
/**
|
|
321
336
|
* @hidden
|
|
@@ -337,13 +352,10 @@ const w = 200, b = "data-sortable-id", x = "data-sortable-component", G = { [x]:
|
|
|
337
352
|
}
|
|
338
353
|
return { left: 0, top: 0 };
|
|
339
354
|
}
|
|
340
|
-
/**
|
|
341
|
-
* @hidden
|
|
342
|
-
*/
|
|
343
355
|
render() {
|
|
344
|
-
const { data: c, style: t, className: e, itemsWrapUI: i } = this.props,
|
|
356
|
+
const { data: c, style: t, className: e, itemsWrapUI: i, tabIndex: s, navigatable: a } = this.props, n = i || "div";
|
|
345
357
|
return /* @__PURE__ */ u.createElement(
|
|
346
|
-
|
|
358
|
+
O,
|
|
347
359
|
{
|
|
348
360
|
onDragStart: this.onDragStart,
|
|
349
361
|
onDrag: this.onDragOver,
|
|
@@ -351,15 +363,16 @@ const w = 200, b = "data-sortable-id", x = "data-sortable-component", G = { [x]:
|
|
|
351
363
|
ref: this.draggableRefAssign
|
|
352
364
|
},
|
|
353
365
|
/* @__PURE__ */ u.createElement(
|
|
354
|
-
|
|
366
|
+
n,
|
|
355
367
|
{
|
|
356
|
-
|
|
368
|
+
onKeyDown: (o) => a && this.onKeyDown(o),
|
|
369
|
+
...$,
|
|
357
370
|
className: e,
|
|
358
371
|
style: {
|
|
359
372
|
touchAction: "none",
|
|
360
373
|
...t
|
|
361
374
|
},
|
|
362
|
-
|
|
375
|
+
tabIndex: a ? s || 0 : void 0
|
|
363
376
|
},
|
|
364
377
|
c && c.length ? this.renderData() : this.renderNoData(),
|
|
365
378
|
this.renderDragCue()
|
|
@@ -367,29 +380,29 @@ const w = 200, b = "data-sortable-id", x = "data-sortable-component", G = { [x]:
|
|
|
367
380
|
);
|
|
368
381
|
}
|
|
369
382
|
};
|
|
370
|
-
|
|
383
|
+
b.defaultProps = {
|
|
371
384
|
navigation: !0,
|
|
372
385
|
animation: !0,
|
|
373
386
|
emptyItemUI: (c) => /* @__PURE__ */ u.createElement("div", null, c.message)
|
|
374
|
-
},
|
|
375
|
-
idField:
|
|
376
|
-
disabledField:
|
|
377
|
-
data:
|
|
378
|
-
tabIndex:
|
|
379
|
-
navigation:
|
|
380
|
-
animation:
|
|
381
|
-
itemsWrapUI:
|
|
382
|
-
itemUI:
|
|
383
|
-
emptyItemUI:
|
|
384
|
-
style:
|
|
385
|
-
className:
|
|
386
|
-
onDragStart:
|
|
387
|
-
onDragOver:
|
|
388
|
-
onDragEnd:
|
|
389
|
-
onNavigate:
|
|
387
|
+
}, b.propTypes = {
|
|
388
|
+
idField: m.string.isRequired,
|
|
389
|
+
disabledField: m.string,
|
|
390
|
+
data: m.array.isRequired,
|
|
391
|
+
tabIndex: m.number,
|
|
392
|
+
navigation: m.bool,
|
|
393
|
+
animation: m.bool,
|
|
394
|
+
itemsWrapUI: m.any,
|
|
395
|
+
itemUI: m.func.isRequired,
|
|
396
|
+
emptyItemUI: m.func,
|
|
397
|
+
style: m.object,
|
|
398
|
+
className: m.string,
|
|
399
|
+
onDragStart: m.func,
|
|
400
|
+
onDragOver: m.func,
|
|
401
|
+
onDragEnd: m.func,
|
|
402
|
+
onNavigate: m.func
|
|
390
403
|
};
|
|
391
|
-
let
|
|
392
|
-
|
|
404
|
+
let D = b;
|
|
405
|
+
L(D);
|
|
393
406
|
export {
|
|
394
|
-
|
|
407
|
+
D as Sortable
|
|
395
408
|
};
|
|
@@ -5,4 +5,4 @@
|
|
|
5
5
|
* Licensed under commercial license. See LICENSE.md in the package root for more information
|
|
6
6
|
*-------------------------------------------------------------------------------------------
|
|
7
7
|
*/
|
|
8
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react"),require("prop-types"),require("@progress/kendo-react-common"),require("@progress/kendo-react-intl")):"function"==typeof define&&define.amd?define(["exports","react","prop-types","@progress/kendo-react-common","@progress/kendo-react-intl"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).KendoReactSortable={},t.React,t.PropTypes,t.KendoReactCommon,t.KendoReactIntl)}(this,(function(t,e,i,s,n){"use strict";function r(t){var e=Object.create(null);return t&&Object.keys(t).forEach((function(i){if("default"!==i){var s=Object.getOwnPropertyDescriptor(t,i);Object.defineProperty(e,i,s.get?s:{enumerable:!0,get:function(){return t[i]}})}})),e.default=t,Object.freeze(e)}var a=r(e);let o=class{constructor(){this.prevented=!1}preventDefault(){this.prevented=!0}isDefaultPrevented(){return this.prevented}};class l extends o{constructor(t,e,i){super(),this.target=t,this.prevIndex=e,this.element=i}}let d=class{constructor(t,e,i,s){this.target=t,this.prevIndex=e,this.nextIndex=i,this.newState=s}},h=class{constructor(t,e,i,s){this.target=t,this.prevIndex=e,this.nextIndex=i,this.newState=s}};class c{constructor(t,e,i,s){this.target=t,this.prevIndex=e,this.nextIndex=i,this.newState=s}}const g="sortable.noData",u={[g]:"No Data"},m=(t,e)=>{for(let i=0;i<t.length;i++)if(e(t[i]))return i;return-1},p=t=>String(t).trim().split(" "),f=/^(?:a|input|select|option|textarea|button|object)$/i,v=s.hasRelativeStackingContext(),b={name:"@progress/kendo-react-sortable",productName:"KendoReact",productCodes:["KENDOUIREACT","KENDOUICOMPLETE"],publishDate:0,version:"",licensingDocsUrl:"https://www.telerik.com/kendo-react-ui/components/my-license/"},I="data-sortable-id",D="data-sortable-component",S={[D]:!0},y=class extends a.Component{constructor(t){super(t),this.state={clientX:0,clientY:0,isDragging:!1,activeId:"",dragCueWidth:0,dragCueHeight:0},this.isRtl=!1,this.itemRefsMap={},this.oldSizesMap={},this.animatingItemMap={},this.draggableRef=null,this.isUnmounted=!1,this.focusActiveId=!1,this.isKeyboardNavigated=!1,this.isDragPrevented=!1,this.swapItems=(t,e,i)=>{let s=t[e];return t[e]=t[i],t[i]=s,e=i},this.generateNewState=(t,e)=>{const{data:i}=this.props,s=[...i];if(t>e)for(let n=t-1;n>=e;n--){const e=i[n];this.isItemDisabled(e)||(t=this.swapItems(s,t,n))}else for(let n=t+1;n<=e;n++){const e=i[n];this.isItemDisabled(e)||(t=this.swapItems(s,t,n))}return s},this.closestSortableItem=t=>{let e=t;for(;e;){const t=e.getAttribute(I);if(t&&this.itemRefsMap[t]===e)return{id:t,element:e};e=e.parentElement}return{id:"",element:null}},this.isSortable=t=>!!t.hasAttribute(D),this.closestSortable=t=>{let e=t;for(;e;){if(this.isSortable(e))return e;e=e.parentElement}return null},this.isSameSortable=t=>this.closestSortable(t)===this.container,this.idComparer=(t,e)=>t+""==e+"",this.findItem=t=>{const{data:e,idField:i}=this.props;if(!(t+""))return;const n=s.getter(i);return((t,e)=>{for(let i=0;i<t.length;i++)if(e(t[i]))return t[i]})(e,(e=>this.idComparer(n(e),t)))},this.findIndex=t=>{const{data:e,idField:i}=this.props;return t+""?m(e,(e=>this.idComparer(e[i],t))):-1},this.isItemDisabled=t=>t&&!0===t[this.props.disabledField||""],this.shouldResetActive=()=>{const t=s.getActiveElement(document);return t instanceof HTMLElement&&!this.closestSortableItem(t).element},this.widgetTarget=t=>{const e=((t,e)=>{for(;t&&!e(t);)t=t.parentNode;return t})(t,(t=>((t,e)=>{const i=p(e);return!!p(t.className).find((t=>i.indexOf(t)>=0))})(t,"k-widget")||this.isSortable(t)));return e&&!this.isSortable(e)},this.allowDrag=t=>t.hasAttribute(I)||!((t=>{if(t.tagName){const e=t.tagName.toLowerCase(),i=t.getAttribute("tabIndex"),s="-1"===i;let n=null!==i&&!s;return f.test(e)&&(n=!t.disabled&&!s),n}return!1})(t)||this.widgetTarget(t)),this.onDragStart=t=>{const{event:e}=t,{onDragStart:i}=this.props,s=document.elementFromPoint(e.clientX,e.clientY),{id:n,element:r}=this.closestSortableItem(s),a=this.findItem(n);if(!n||a&&this.isItemDisabled(a)||!this.allowDrag(s)||!this.isSameSortable(s))return void(this.isDragPrevented=!0);e.isTouch&&e.originalEvent.preventDefault();const o=new l(this,this.findIndex(n),s);i&&i.call(void 0,o),this.isDragPrevented=o.isDefaultPrevented(),this.isDragPrevented?e.originalEvent.preventDefault():(this.offsetParent=(t=>{if(!t||!v)return null;let e=t.parentElement;for(;e;){if("none"!==window.getComputedStyle(e).transform)return e;e=e.parentElement}})(this.container),this.setState({activeId:n,dragCueWidth:r&&r.clientWidth||0,dragCueHeight:r&&r.clientHeight||0}))},this.onDragOver=t=>{const{event:e}=t,{onDragOver:i,data:s}=this.props;if(this.isDragPrevented)return;e.originalEvent.preventDefault();const n=this.findIndex(this.state.activeId);if(-1===n)return void this.resetState();const r=document.elementFromPoint(e.clientX,e.clientY),a=this.closestSortableItem(r),o=this.findIndex(a.id),l=s[o];if(i&&o>-1&&n!==o&&!this.isItemDisabled(l)&&!this.animatingItemMap[a.id]&&this.shouldReorder(a.element,e.clientX,e.clientY)){const t=new d(this,n,o,this.generateNewState(n,o));i.call(void 0,t)}const h=this.parentOffset();this.setState({clientX:e.clientX-h.left,clientY:e.clientY-h.top,isDragging:!0})},this.onDragEnd=t=>{const{event:e}=t,i=this.shouldResetActive();if(this.isDragPrevented)return;const{onDragEnd:s,data:n}=this.props,r=document.elementFromPoint(e.clientX,e.clientY),a=this.closestSortableItem(r);let o=this.findIndex(a.id),l=this.findIndex(this.state.activeId);const d=this.isItemDisabled(n[o]);if((-1===o||d)&&(o=l),s){let t=this.generateNewState(l,o);if(!d){const i=this.thresholdRect(a.element);if(i&&(e.clientX<i.left||e.clientX>i.right||e.clientY<i.top||e.clientY>i.bottom)){const e=l;l=o,o=e,t=this.props.data.slice()}}const i=new h(this,l,o,t);s.call(void 0,i)}this.resetState(i)},this.shouldReorder=(t,e,i)=>{const s=this.thresholdRect(t);return s&&e>s.left&&e<s.right&&i>s.top&&i<s.bottom},this.thresholdRect=t=>{const e=this.state.activeId,i=this.container,s=(i?Array.from(i.childNodes):[]).find((t=>t instanceof HTMLElement&&t.getAttribute(I)===e));if(!t||!s)return null;const{width:n,height:r}=s.getBoundingClientRect(),a=t.getBoundingClientRect(),o=a.top+a.height/2-r/2,l=a.left+a.width/2-n/2;return{top:o,left:l,bottom:o+r,right:l+n}},this.onItemBlur=()=>{window.setTimeout((()=>{this.isUnmounted||this.shouldResetActive()&&!this.state.isDragging&&this.setState({activeId:""})}))},this.onItemFocus=t=>{const{id:e,element:i}=this.closestSortableItem(t.currentTarget);!this.idComparer(e,this.state.activeId)&&this.isSameSortable(t.target)&&i===t.target&&this.setState({activeId:e})},this.onKeyDown=t=>{const{data:e,idField:i,onNavigate:n,navigation:r}=this.props,{activeId:a}=this.state;if(!r||!a||!this.isSameSortable(t.target))return;const o=this.isRtl,l=e.filter((t=>!this.isItemDisabled(t))),d=m(l,(t=>this.idComparer(t[i],a))),h=l.length-1;let g=d;switch(t.keyCode===s.Keys.left&&(t.keyCode=o?s.Keys.down:s.Keys.up),t.keyCode===s.Keys.right&&(t.keyCode=o?s.Keys.up:s.Keys.down),t.keyCode){case s.Keys.up:d>0&&(g=d-1);break;case s.Keys.down:d<h&&(g=d+1)}if(g===d)return;t.stopPropagation(),t.preventDefault();const u=l[g],p=u?u[i]:"",f=l[d],v=f?f[i]:"";if(t.ctrlKey){if(n){const t=this.findIndex(v),e=this.findIndex(p),i=new c(this,t,e,this.generateNewState(t,e));this.isKeyboardNavigated=!0,n.call(void 0,i)}}else this.focusActiveId=!0,this.setState({activeId:p+""})},this.resetState=t=>{this.isDragPrevented=!1,this.setState({clientX:0,clientY:0,isDragging:!1,dragCueWidth:0,dragCueHeight:0,activeId:t?"":this.state.activeId})},this.renderData=()=>{const{data:t,itemUI:e,idField:i,tabIndex:n}=this.props;return t.map((t=>{const r=s.getter(i)(t),o=this.isItemDisabled(t),l=this.idComparer(this.state.activeId,r);return a.createElement(e,{key:r,forwardRef:t=>this.refAssign(t,r),dataItem:t,isDisabled:o,isActive:l,isDragged:l&&this.state.isDragging,isDragCue:!1,attributes:{[I]:r,"aria-disabled":o,"aria-grabbed":l&&this.state.isDragging&&!this.isDragPrevented,"aria-dropeffect":o?"none":"move",tabIndex:s.getTabIndex(n,o),onFocus:this.onItemFocus,onBlur:this.onItemBlur},style:{cursor:o?"auto":"move",MozUserSelect:"none",msUserSelect:"none",WebkitUserSelect:"none",userSelect:"none"}})}))},this.renderNoData=()=>{const{emptyItemUI:t}=this.props,e=n.provideLocalizationService(this).toLanguageString(g,u[g]);if(t)return a.createElement(t,{message:e})},this.renderDragCue=()=>{const{itemUI:t}=this.props,{isDragging:e,activeId:i,clientX:s,clientY:n}=this.state,r=this.findItem(i);if(e&&r)return a.createElement(t,{dataItem:r,isDisabled:!1,isActive:!0,isDragged:!0,isDragCue:!0,style:{position:"fixed",top:n+10,left:s+10,width:this.state.dragCueWidth,height:this.state.dragCueHeight},attributes:{}})},this.refAssign=(t,e)=>{t?this.itemRefsMap[e]=t:delete this.itemRefsMap[e]},this.draggableRefAssign=t=>{this.draggableRef=t},s.validatePackage(b)}get container(){return this.draggableRef&&this.draggableRef.element}getSnapshotBeforeUpdate(){const{idField:t,animation:e}=this.props;return this.oldSizesMap={},e&&this.props.data.forEach((e=>{const i=e[t],s=this.itemRefsMap[i];s&&(this.oldSizesMap[i]=s.getBoundingClientRect())})),null}componentDidUpdate(t){const{idField:e,animation:i}=this.props;this.focusActiveId&&(this.focusActiveId=!1,this.itemRefsMap[this.state.activeId].focus()),i&&(this.state.isDragging||this.isKeyboardNavigated)&&(this.isKeyboardNavigated=!1,t.data.forEach((t=>{const i=t[e],s=this.itemRefsMap[i];if(!s)return;const n=s.getBoundingClientRect(),r=this.oldSizesMap[i],a=r.left-n.left,o=r.top-n.top;0===a&&0===o||requestAnimationFrame((()=>{this.animatingItemMap[i]=!0,s.style.transform=`translate(${a}px, ${o}px)`,s.style.transition="transform 0s",requestAnimationFrame((()=>{s.style.transform="",s.style.transition="transform 200ms cubic-bezier(0.2, 0, 0, 1) 0s",window.setTimeout((()=>this.animatingItemMap[i]=!1),200)}))}))})))}componentDidMount(){this.isRtl=this.container&&"rtl"===getComputedStyle(this.container).direction||!1}componentWillUnmount(){this.isUnmounted=!0}parentOffset(){const t=this.offsetParent;if(t&&t.ownerDocument&&t!==t.ownerDocument.body){const e=t.getBoundingClientRect();return{left:e.left-t.scrollLeft,top:e.top-t.scrollTop}}return{left:0,top:0}}render(){const{data:t,style:e,className:i,itemsWrapUI:n}=this.props,r=n||"div";return a.createElement(s.Draggable,{onDragStart:this.onDragStart,onDrag:this.onDragOver,onDragEnd:this.onDragEnd,ref:this.draggableRefAssign},a.createElement(r,{...S,className:i,style:{touchAction:"none",...e},onKeyDown:this.onKeyDown},t&&t.length?this.renderData():this.renderNoData(),this.renderDragCue()))}};y.defaultProps={navigation:!0,animation:!0,emptyItemUI:t=>a.createElement("div",null,t.message)},y.propTypes={idField:i.string.isRequired,disabledField:i.string,data:i.array.isRequired,tabIndex:i.number,navigation:i.bool,animation:i.bool,itemsWrapUI:i.any,itemUI:i.func.isRequired,emptyItemUI:i.func,style:i.object,className:i.string,onDragStart:i.func,onDragOver:i.func,onDragEnd:i.func,onNavigate:i.func};let w=y;n.registerForLocalization(w),t.Sortable=w,t.SortableOnDragEndEvent=h,t.SortableOnDragOverEvent=d,t.SortableOnDragStartEvent=l,t.SortableOnNavigateEvent=c}));
|
|
8
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react"),require("prop-types"),require("@progress/kendo-react-common"),require("@progress/kendo-react-intl")):"function"==typeof define&&define.amd?define(["exports","react","prop-types","@progress/kendo-react-common","@progress/kendo-react-intl"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).KendoReactSortable={},t.React,t.PropTypes,t.KendoReactCommon,t.KendoReactIntl)}(this,(function(t,e,i,s,n){"use strict";function r(t){var e=Object.create(null);return t&&Object.keys(t).forEach((function(i){if("default"!==i){var s=Object.getOwnPropertyDescriptor(t,i);Object.defineProperty(e,i,s.get?s:{enumerable:!0,get:function(){return t[i]}})}})),e.default=t,Object.freeze(e)}var a=r(e);let o=class{constructor(){this.prevented=!1}preventDefault(){this.prevented=!0}isDefaultPrevented(){return this.prevented}};class l extends o{constructor(t,e,i){super(),this.target=t,this.prevIndex=e,this.element=i}}let d=class{constructor(t,e,i,s){this.target=t,this.prevIndex=e,this.nextIndex=i,this.newState=s}},h=class{constructor(t,e,i,s){this.target=t,this.prevIndex=e,this.nextIndex=i,this.newState=s}};class c{constructor(t,e,i,s){this.target=t,this.prevIndex=e,this.nextIndex=i,this.newState=s}}const g="sortable.noData",u={[g]:"No Data"},m=(t,e)=>{for(let i=0;i<t.length;i++)if(e(t[i]))return i;return-1},f=t=>String(t).trim().split(" "),p=/^(?:a|input|select|option|textarea|button|object)$/i,v=s.hasRelativeStackingContext(),b={name:"@progress/kendo-react-sortable",productName:"KendoReact",productCodes:["KENDOUIREACT","KENDOUICOMPLETE"],publishDate:0,version:"",licensingDocsUrl:"https://www.telerik.com/kendo-react-ui/components/my-license/"},I="data-sortable-id",D="data-sortable-component",S="[data-sortable-id]:not(.k-disabled)",y={[D]:!0},R=class extends a.Component{constructor(t){super(t),this.state={clientX:0,clientY:0,isDragging:!1,activeId:"",dragCueWidth:0,dragCueHeight:0},this.isRtl=!1,this.itemRefsMap={},this.oldSizesMap={},this.animatingItemMap={},this.draggableRef=null,this.isUnmounted=!1,this.focusActiveId=!1,this.isKeyboardNavigated=!1,this.isDragPrevented=!1,this.swapItems=(t,e,i)=>{const s=t[e];return t[e]=t[i],t[i]=s,e=i},this.generateNewState=(t,e)=>{const{data:i}=this.props,s=[...i];if(t>e)for(let n=t-1;n>=e;n--){const e=i[n];this.isItemDisabled(e)||(t=this.swapItems(s,t,n))}else for(let n=t+1;n<=e;n++){const e=i[n];this.isItemDisabled(e)||(t=this.swapItems(s,t,n))}return s},this.closestSortableItem=t=>{let e=t;for(;e;){const t=e.getAttribute(I);if(t&&this.itemRefsMap[t]===e)return{id:t,element:e};e=e.parentElement}return{id:"",element:null}},this.isSortable=t=>!!t.hasAttribute(D),this.closestSortable=t=>{let e=t;for(;e;){if(this.isSortable(e))return e;e=e.parentElement}return null},this.isSameSortable=t=>this.closestSortable(t)===this.container,this.idComparer=(t,e)=>t+""==e+"",this.findItem=t=>{const{data:e,idField:i}=this.props;if(!(t+""))return;const n=s.getter(i);return((t,e)=>{for(let i=0;i<t.length;i++)if(e(t[i]))return t[i]})(e,(e=>this.idComparer(n(e),t)))},this.findIndex=t=>{const{data:e,idField:i}=this.props;return t+""?m(e,(e=>this.idComparer(e[i],t))):-1},this.isItemDisabled=t=>t&&!0===t[this.props.disabledField||""],this.shouldResetActive=()=>{const t=s.getActiveElement(document);return t instanceof HTMLElement&&!this.closestSortableItem(t).element},this.widgetTarget=t=>{const e=((t,e)=>{for(;t&&!e(t);)t=t.parentNode;return t})(t,(t=>((t,e)=>{const i=f(e);return!!f(t.className).find((t=>i.indexOf(t)>=0))})(t,"k-widget")||this.isSortable(t)));return e&&!this.isSortable(e)},this.allowDrag=t=>t.hasAttribute(I)||!((t=>{if(t.tagName){const e=t.tagName.toLowerCase(),i=t.getAttribute("tabIndex"),s="-1"===i;let n=null!==i&&!s;return p.test(e)&&(n=!t.disabled&&!s),n}return!1})(t)||this.widgetTarget(t)),this.onDragStart=t=>{const{event:e}=t,{onDragStart:i}=this.props,s=document.elementFromPoint(e.clientX,e.clientY),{id:n,element:r}=this.closestSortableItem(s),a=this.findItem(n);if(!n||a&&this.isItemDisabled(a)||!this.allowDrag(s)||!this.isSameSortable(s))return void(this.isDragPrevented=!0);e.isTouch&&e.originalEvent.preventDefault();const o=new l(this,this.findIndex(n),s);i&&i.call(void 0,o),this.isDragPrevented=o.isDefaultPrevented(),this.isDragPrevented?e.originalEvent.preventDefault():(this.offsetParent=(t=>{if(!t||!v)return null;let e=t.parentElement;for(;e;){if("none"!==window.getComputedStyle(e).transform)return e;e=e.parentElement}})(this.container),this.setState({activeId:n,dragCueWidth:r&&r.clientWidth||0,dragCueHeight:r&&r.clientHeight||0}))},this.onDragOver=t=>{const{event:e}=t,{onDragOver:i,data:s}=this.props;if(this.isDragPrevented)return;e.originalEvent.preventDefault();const n=this.findIndex(this.state.activeId);if(-1===n)return void this.resetState();const r=document.elementFromPoint(e.clientX,e.clientY),a=this.closestSortableItem(r),o=this.findIndex(a.id),l=s[o];if(i&&o>-1&&n!==o&&!this.isItemDisabled(l)&&!this.animatingItemMap[a.id]&&this.shouldReorder(a.element,e.clientX,e.clientY)){const t=new d(this,n,o,this.generateNewState(n,o));i.call(void 0,t)}const h=this.parentOffset();this.setState({clientX:e.clientX-h.left,clientY:e.clientY-h.top,isDragging:!0})},this.onDragEnd=t=>{const{event:e}=t,i=this.shouldResetActive();if(this.isDragPrevented)return;const{onDragEnd:s,data:n}=this.props,r=document.elementFromPoint(e.clientX,e.clientY),a=this.closestSortableItem(r);let o=this.findIndex(a.id),l=this.findIndex(this.state.activeId);const d=this.isItemDisabled(n[o]);if((-1===o||d)&&(o=l),s){let t=this.generateNewState(l,o);if(!d){const i=this.thresholdRect(a.element);if(i&&(e.clientX<i.left||e.clientX>i.right||e.clientY<i.top||e.clientY>i.bottom)){const e=l;l=o,o=e,t=this.props.data.slice()}}const i=new h(this,l,o,t);s.call(void 0,i)}this.resetState(i)},this.shouldReorder=(t,e,i)=>{const s=this.thresholdRect(t);return s&&e>s.left&&e<s.right&&i>s.top&&i<s.bottom},this.thresholdRect=t=>{const e=this.state.activeId,i=this.container,s=(i?Array.from(i.childNodes):[]).find((t=>t instanceof HTMLElement&&t.getAttribute(I)===e));if(!t||!s)return null;const{width:n,height:r}=s.getBoundingClientRect(),a=t.getBoundingClientRect(),o=a.top+a.height/2-r/2,l=a.left+a.width/2-n/2;return{top:o,left:l,bottom:o+r,right:l+n}},this.onItemBlur=()=>{window.setTimeout((()=>{this.isUnmounted||this.shouldResetActive()&&!this.state.isDragging&&this.setState({activeId:""})}))},this.onItemFocus=t=>{const{id:e,element:i}=this.closestSortableItem(t.currentTarget);!this.idComparer(e,this.state.activeId)&&this.isSameSortable(t.target)&&i===t.target&&this.setState({activeId:e})},this.resetState=t=>{this.isDragPrevented=!1,this.setState({clientX:0,clientY:0,isDragging:!1,dragCueWidth:0,dragCueHeight:0,activeId:t?"":this.state.activeId})},this.renderData=()=>{const{data:t,itemUI:e,idField:i,tabIndex:n,navigatable:r}=this.props;return t.map((t=>{const o=s.getter(i)(t),l=this.isItemDisabled(t),d=this.idComparer(this.state.activeId,o),h=r?d?0:-1:n;return a.createElement(e,{key:o,forwardRef:t=>this.refAssign(t,o),dataItem:t,isDisabled:l,isActive:d,isDragged:d&&this.state.isDragging,isDragCue:!1,attributes:{[I]:o,"aria-disabled":l,"aria-grabbed":d&&this.state.isDragging&&!this.isDragPrevented,"aria-dropeffect":l?"none":"move",tabIndex:s.getTabIndex(h,l),onFocus:this.onItemFocus,onBlur:this.onItemBlur},style:{cursor:l?"auto":"move",MozUserSelect:"none",msUserSelect:"none",WebkitUserSelect:"none",userSelect:"none"}})}))},this.renderNoData=()=>{const{emptyItemUI:t}=this.props,e=n.provideLocalizationService(this).toLanguageString(g,u[g]);if(t)return a.createElement(t,{message:e})},this.renderDragCue=()=>{const{itemUI:t}=this.props,{isDragging:e,activeId:i,clientX:s,clientY:n}=this.state,r=this.findItem(i);if(e&&r)return a.createElement(t,{dataItem:r,isDisabled:!1,isActive:!0,isDragged:!0,isDragCue:!0,style:{position:"fixed",top:n+10,left:s+10,width:this.state.dragCueWidth,height:this.state.dragCueHeight},attributes:{}})},this.refAssign=(t,e)=>{t?this.itemRefsMap[e]=t:delete this.itemRefsMap[e]},this.draggableRefAssign=t=>{this.draggableRef=t},this.onKeyDown=t=>{var e,i,n;const{data:r,idField:a}=this.props,{activeId:o}=this.state,l=r.filter((t=>!this.isItemDisabled(t))),d=m(l,(t=>this.idComparer(t[a],o))),h=d<0?0:d;t.key===s.KEYS.tab&&s.getActiveElement(document)!==(null==(e=this.draggableRef)?void 0:e.element)&&(t.preventDefault(),t.stopPropagation()),this.navigation&&null!=(i=this.draggableRef)&&i.element&&this.navigation.triggerKeyboardEvent({target:null==(n=this.draggableRef)?void 0:n.element.querySelectorAll(S)[h],key:t.key,nativeEvent:{type:t.type},originalEvent:t})},this.handleNext=(t,e,i)=>{var n;s.getActiveElement(document)!==(null==(n=this.draggableRef)?void 0:n.element)&&(i.originalEvent.metaKey?this.moveItem(t,e,i,"next"):e.focusNext(t))},this.handlePrev=(t,e,i)=>{var n;s.getActiveElement(document)!==(null==(n=this.draggableRef)?void 0:n.element)&&(i.originalEvent.metaKey?this.moveItem(t,e,i,"prev"):e.focusPrevious(t))},this.moveItem=(t,e,i,n)=>{var r;if(s.getActiveElement(document)!==(null==(r=this.draggableRef)?void 0:r.element)){const{onNavigate:t,data:e,idField:i}=this.props,s=this.findIndex(this.state.activeId);if(t){let r,a;"next"===n?(r=e[s+1],a=r&&r.disabled?e[s+2]:e[s+1]):(r=e[s-1],a=r&&r.disabled?e[s-2]:e[s-1]);const o=a&&a[i],l=e[s],d=l?l[i]:"",h=this.findIndex(d),g=this.findIndex(o||d),u=new c(this,h,g,this.generateNewState(h,g));this.isKeyboardNavigated=!0,t.call(void 0,u)}}},s.validatePackage(b),this.onKeyDown=this.onKeyDown.bind(this)}get container(){return this.draggableRef&&this.draggableRef.element}getSnapshotBeforeUpdate(){const{idField:t,animation:e}=this.props;return this.oldSizesMap={},e&&this.props.data.forEach((e=>{const i=e[t],s=this.itemRefsMap[i];s&&(this.oldSizesMap[i]=s.getBoundingClientRect())})),null}componentDidUpdate(t){const{idField:e,animation:i}=this.props;this.focusActiveId&&(this.focusActiveId=!1,this.itemRefsMap[this.state.activeId].focus()),i&&(this.state.isDragging||this.isKeyboardNavigated)&&(this.isKeyboardNavigated=!1,t.data.forEach((t=>{const i=t[e],s=this.itemRefsMap[i];if(!s)return;const n=s.getBoundingClientRect(),r=this.oldSizesMap[i],a=r.left-n.left,o=r.top-n.top;0===a&&0===o||requestAnimationFrame((()=>{this.animatingItemMap[i]=!0,s.style.transform=`translate(${a}px, ${o}px)`,s.style.transition="transform 0s",requestAnimationFrame((()=>{s.style.transform="",s.style.transition="transform 200ms cubic-bezier(0.2, 0, 0, 1) 0s",window.setTimeout((()=>this.animatingItemMap[i]=!1),200)}))}))})))}componentDidMount(){var t,e;null!=(t=this.draggableRef)&&t.element&&(this.navigation=new s.Navigation({tabIndex:0,root:{current:null==(e=this.draggableRef)?void 0:e.element},rovingTabIndex:!0,selectors:[S],keyboardEvents:{keydown:{ArrowDown:this.handleNext,ArrowRight:this.handleNext,ArrowUp:this.handlePrev,ArrowLeft:this.handlePrev,Enter:(t,e,i)=>{e.focusElement(e.first,t)},Escape:(t,e,i)=>{var s,n;t.setAttribute("tabindex","-1"),null==(n=null==(s=this.draggableRef)?void 0:s.element)||n.focus(),this.setState({activeId:""})}}}})),this.isRtl=this.container&&"rtl"===getComputedStyle(this.container).direction||!1}componentWillUnmount(){this.isUnmounted=!0}parentOffset(){const t=this.offsetParent;if(t&&t.ownerDocument&&t!==t.ownerDocument.body){const e=t.getBoundingClientRect();return{left:e.left-t.scrollLeft,top:e.top-t.scrollTop}}return{left:0,top:0}}render(){const{data:t,style:e,className:i,itemsWrapUI:n,tabIndex:r,navigatable:o}=this.props,l=n||"div";return a.createElement(s.Draggable,{onDragStart:this.onDragStart,onDrag:this.onDragOver,onDragEnd:this.onDragEnd,ref:this.draggableRefAssign},a.createElement(l,{onKeyDown:t=>o&&this.onKeyDown(t),...y,className:i,style:{touchAction:"none",...e},tabIndex:o?r||0:void 0},t&&t.length?this.renderData():this.renderNoData(),this.renderDragCue()))}};R.defaultProps={navigation:!0,animation:!0,emptyItemUI:t=>a.createElement("div",null,t.message)},R.propTypes={idField:i.string.isRequired,disabledField:i.string,data:i.array.isRequired,tabIndex:i.number,navigation:i.bool,animation:i.bool,itemsWrapUI:i.any,itemUI:i.func.isRequired,emptyItemUI:i.func,style:i.object,className:i.string,onDragStart:i.func,onDragOver:i.func,onDragEnd:i.func,onNavigate:i.func};let w=R;n.registerForLocalization(w),t.Sortable=w,t.SortableOnDragEndEvent=h,t.SortableOnDragOverEvent=d,t.SortableOnDragStartEvent=l,t.SortableOnNavigateEvent=c}));
|
package/index.d.mts
CHANGED
|
@@ -9,6 +9,7 @@ import { DraggableDragEvent } from '@progress/kendo-react-common';
|
|
|
9
9
|
import { DraggableDragStartEvent } from '@progress/kendo-react-common';
|
|
10
10
|
import { DraggableReleaseEvent } from '@progress/kendo-react-common';
|
|
11
11
|
import { JSX as JSX_2 } from 'react/jsx-runtime';
|
|
12
|
+
import { Navigation } from '@progress/kendo-react-common';
|
|
12
13
|
import PropTypes from 'prop-types';
|
|
13
14
|
import * as React_2 from 'react';
|
|
14
15
|
|
|
@@ -88,6 +89,7 @@ export declare class Sortable extends React_2.Component<SortableProps, SortableS
|
|
|
88
89
|
private focusActiveId;
|
|
89
90
|
private isKeyboardNavigated;
|
|
90
91
|
private isDragPrevented;
|
|
92
|
+
private navigation?;
|
|
91
93
|
constructor(props: SortableProps);
|
|
92
94
|
/**
|
|
93
95
|
* @hidden
|
|
@@ -197,10 +199,6 @@ export declare class Sortable extends React_2.Component<SortableProps, SortableS
|
|
|
197
199
|
* @hidden
|
|
198
200
|
*/
|
|
199
201
|
onItemFocus: (event: React_2.FocusEvent<HTMLDivElement>) => void;
|
|
200
|
-
/**
|
|
201
|
-
* @hidden
|
|
202
|
-
*/
|
|
203
|
-
onKeyDown: (event: React_2.KeyboardEvent<HTMLDivElement>) => void;
|
|
204
202
|
/**
|
|
205
203
|
* @hidden
|
|
206
204
|
*/
|
|
@@ -228,6 +226,13 @@ export declare class Sortable extends React_2.Component<SortableProps, SortableS
|
|
|
228
226
|
/**
|
|
229
227
|
* @hidden
|
|
230
228
|
*/
|
|
229
|
+
onKeyDown: (event: React_2.KeyboardEvent<HTMLDivElement>) => void;
|
|
230
|
+
/**
|
|
231
|
+
* @hidden
|
|
232
|
+
*/
|
|
233
|
+
handleNext: (t: HTMLElement, nav: Navigation, ev: React_2.KeyboardEvent<HTMLElement>) => void;
|
|
234
|
+
handlePrev: (t: HTMLElement, nav: Navigation, ev: React_2.KeyboardEvent<HTMLElement>) => void;
|
|
235
|
+
moveItem: (t: HTMLElement, nav: Navigation, ev: React_2.KeyboardEvent<HTMLElement>, direction: 'next' | 'prev') => void;
|
|
231
236
|
render(): JSX_2.Element;
|
|
232
237
|
}
|
|
233
238
|
|
|
@@ -455,6 +460,11 @@ export declare interface SortableProps extends SortableDefaultProps {
|
|
|
455
460
|
* Fires when the user is navigates within the Srotable by using the keyboard.
|
|
456
461
|
*/
|
|
457
462
|
onNavigate?: (event: SortableOnNavigateEvent) => void;
|
|
463
|
+
/**
|
|
464
|
+
* If set to `true`, the user can use dedicated shortcuts to interact with the Srotable.
|
|
465
|
+
* By default, navigation is disabled.
|
|
466
|
+
*/
|
|
467
|
+
navigatable?: boolean;
|
|
458
468
|
}
|
|
459
469
|
|
|
460
470
|
/**
|
package/index.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { DraggableDragEvent } from '@progress/kendo-react-common';
|
|
|
9
9
|
import { DraggableDragStartEvent } from '@progress/kendo-react-common';
|
|
10
10
|
import { DraggableReleaseEvent } from '@progress/kendo-react-common';
|
|
11
11
|
import { JSX as JSX_2 } from 'react/jsx-runtime';
|
|
12
|
+
import { Navigation } from '@progress/kendo-react-common';
|
|
12
13
|
import PropTypes from 'prop-types';
|
|
13
14
|
import * as React_2 from 'react';
|
|
14
15
|
|
|
@@ -88,6 +89,7 @@ export declare class Sortable extends React_2.Component<SortableProps, SortableS
|
|
|
88
89
|
private focusActiveId;
|
|
89
90
|
private isKeyboardNavigated;
|
|
90
91
|
private isDragPrevented;
|
|
92
|
+
private navigation?;
|
|
91
93
|
constructor(props: SortableProps);
|
|
92
94
|
/**
|
|
93
95
|
* @hidden
|
|
@@ -197,10 +199,6 @@ export declare class Sortable extends React_2.Component<SortableProps, SortableS
|
|
|
197
199
|
* @hidden
|
|
198
200
|
*/
|
|
199
201
|
onItemFocus: (event: React_2.FocusEvent<HTMLDivElement>) => void;
|
|
200
|
-
/**
|
|
201
|
-
* @hidden
|
|
202
|
-
*/
|
|
203
|
-
onKeyDown: (event: React_2.KeyboardEvent<HTMLDivElement>) => void;
|
|
204
202
|
/**
|
|
205
203
|
* @hidden
|
|
206
204
|
*/
|
|
@@ -228,6 +226,13 @@ export declare class Sortable extends React_2.Component<SortableProps, SortableS
|
|
|
228
226
|
/**
|
|
229
227
|
* @hidden
|
|
230
228
|
*/
|
|
229
|
+
onKeyDown: (event: React_2.KeyboardEvent<HTMLDivElement>) => void;
|
|
230
|
+
/**
|
|
231
|
+
* @hidden
|
|
232
|
+
*/
|
|
233
|
+
handleNext: (t: HTMLElement, nav: Navigation, ev: React_2.KeyboardEvent<HTMLElement>) => void;
|
|
234
|
+
handlePrev: (t: HTMLElement, nav: Navigation, ev: React_2.KeyboardEvent<HTMLElement>) => void;
|
|
235
|
+
moveItem: (t: HTMLElement, nav: Navigation, ev: React_2.KeyboardEvent<HTMLElement>, direction: 'next' | 'prev') => void;
|
|
231
236
|
render(): JSX_2.Element;
|
|
232
237
|
}
|
|
233
238
|
|
|
@@ -455,6 +460,11 @@ export declare interface SortableProps extends SortableDefaultProps {
|
|
|
455
460
|
* Fires when the user is navigates within the Srotable by using the keyboard.
|
|
456
461
|
*/
|
|
457
462
|
onNavigate?: (event: SortableOnNavigateEvent) => void;
|
|
463
|
+
/**
|
|
464
|
+
* If set to `true`, the user can use dedicated shortcuts to interact with the Srotable.
|
|
465
|
+
* By default, navigation is disabled.
|
|
466
|
+
*/
|
|
467
|
+
navigatable?: boolean;
|
|
458
468
|
}
|
|
459
469
|
|
|
460
470
|
/**
|
package/package-metadata.mjs
CHANGED
|
@@ -10,7 +10,7 @@ const e = {
|
|
|
10
10
|
name: "@progress/kendo-react-sortable",
|
|
11
11
|
productName: "KendoReact",
|
|
12
12
|
productCodes: ["KENDOUIREACT", "KENDOUICOMPLETE"],
|
|
13
|
-
publishDate:
|
|
13
|
+
publishDate: 1722844072,
|
|
14
14
|
version: "",
|
|
15
15
|
licensingDocsUrl: "https://www.telerik.com/kendo-react-ui/components/my-license/"
|
|
16
16
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@progress/kendo-react-sortable",
|
|
3
|
-
"version": "8.2.0
|
|
3
|
+
"version": "8.2.0",
|
|
4
4
|
"description": "React Sortable provides a sortable drag-and-drop functionality to elements within a list. KendoReact Sortable package",
|
|
5
5
|
"author": "Progress",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
"sideEffects": false,
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"@progress/kendo-licensing": "^1.3.4",
|
|
26
|
-
"@progress/kendo-react-common": "8.2.0
|
|
27
|
-
"@progress/kendo-react-intl": "8.2.0
|
|
26
|
+
"@progress/kendo-react-common": "8.2.0",
|
|
27
|
+
"@progress/kendo-react-intl": "8.2.0",
|
|
28
28
|
"react": "^16.8.2 || ^17.0.0 || ^18.0.0",
|
|
29
29
|
"react-dom": "^16.8.2 || ^17.0.0 || ^18.0.0"
|
|
30
30
|
},
|