@dnd-kit/sortable
Advanced tools
Comparing version 7.0.0-next-20222231225 to 7.0.0-next-20223141625
# @dnd-kit/sortable | ||
## 7.0.0-next-20222231225 | ||
## 7.0.0-next-20223141625 | ||
@@ -22,5 +22,7 @@ ### Major Changes | ||
- Updated dependencies [[`a41e5b8`](https://github.com/clauderic/dnd-kit/commit/a41e5b8eff84f0528ffc8b3455b94b95ab60a4a9), [`a41e5b8`](https://github.com/clauderic/dnd-kit/commit/a41e5b8eff84f0528ffc8b3455b94b95ab60a4a9), [`a41e5b8`](https://github.com/clauderic/dnd-kit/commit/a41e5b8eff84f0528ffc8b3455b94b95ab60a4a9), [`77e3d44`](https://github.com/clauderic/dnd-kit/commit/77e3d44502383d2f9a9f9af014b053619b3e37b3), [`e6e242c`](https://github.com/clauderic/dnd-kit/commit/e6e242cbc718ed687a26f5c622eeed4dbd6c2425), [`10f6836`](https://github.com/clauderic/dnd-kit/commit/10f683631103b1d919f2fbca1177141b9369d2cf), [`c1b3b5a`](https://github.com/clauderic/dnd-kit/commit/c1b3b5a0be5759b707e22c4e1b1236aaa82773a2)]: | ||
- @dnd-kit/core@5.1.0-next-20222231225 | ||
- [#685](https://github.com/clauderic/dnd-kit/pull/685) [`4b286e4`](https://github.com/clauderic/dnd-kit/commit/4b286e41288f5f50cdcdb24a663c314a91cda7cb) Thanks [@tmcw](https://github.com/tmcw)! - Faster (and safer) equal implementation. | ||
- Updated dependencies [[`a41e5b8`](https://github.com/clauderic/dnd-kit/commit/a41e5b8eff84f0528ffc8b3455b94b95ab60a4a9), [`a41e5b8`](https://github.com/clauderic/dnd-kit/commit/a41e5b8eff84f0528ffc8b3455b94b95ab60a4a9), [`a41e5b8`](https://github.com/clauderic/dnd-kit/commit/a41e5b8eff84f0528ffc8b3455b94b95ab60a4a9), [`77e3d44`](https://github.com/clauderic/dnd-kit/commit/77e3d44502383d2f9a9f9af014b053619b3e37b3), [`e302bd4`](https://github.com/clauderic/dnd-kit/commit/e302bd4488bdfb6735c97ac42c1f4a0b1e8bfdf9), [`e6e242c`](https://github.com/clauderic/dnd-kit/commit/e6e242cbc718ed687a26f5c622eeed4dbd6c2425), [`10f6836`](https://github.com/clauderic/dnd-kit/commit/10f683631103b1d919f2fbca1177141b9369d2cf), [`c1b3b5a`](https://github.com/clauderic/dnd-kit/commit/c1b3b5a0be5759b707e22c4e1b1236aaa82773a2)]: | ||
- @dnd-kit/core@5.1.0-next-20223141625 | ||
## 6.0.1 | ||
@@ -27,0 +29,0 @@ |
@@ -307,3 +307,12 @@ 'use strict'; | ||
function isEqual(arr1, arr2) { | ||
return arr1.join() === arr2.join(); | ||
if (arr1 === arr2) return true; | ||
if (arr1.length !== arr2.length) return false; | ||
for (let i = 0; i < arr1.length; i++) { | ||
if (arr1[i] !== arr2[i]) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
@@ -310,0 +319,0 @@ |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("react"),r=(e=t)&&"object"==typeof e&&"default"in e?e.default:e,n=require("@dnd-kit/core"),i=require("@dnd-kit/utilities");function o(e,t,r){const n=e.slice();return n.splice(r<0?n.length+r:r,0,n.splice(t,1)[0]),n}function s(e,t){return e.reduce((e,r,n)=>{const i=t.get(r);return i&&(e[n]=i),e},Array(e.length))}function a(e){return null!==e&&e>=0}const d={scaleX:1,scaleY:1},c=({rects:e,activeIndex:t,overIndex:r,index:n})=>{const i=o(e,r,t),s=e[n],a=i[n];return a&&s?{x:a.left-s.left,y:a.top-s.top,scaleX:a.width/s.width,scaleY:a.height/s.height}:null},l={scaleX:1,scaleY:1},u=r.createContext({activeIndex:-1,containerId:"Sortable",disableTransforms:!1,items:[],overIndex:-1,useDragOverlay:!1,sortedRects:[],strategy:c}),f=({id:e,items:t,activeIndex:r,overIndex:n})=>o(t,r,n).indexOf(e),x=({containerId:e,isSorting:t,wasDragging:r,index:n,items:i,newIndex:o,previousItems:s,previousContainerId:a,transition:d})=>!(!d||!r||s!==i&&n===o||!t&&(o===n||e!==a)),p={duration:200,easing:"ease"},g=i.CSS.Transition.toString({property:"transform",duration:0,easing:"linear"}),v={roleDescription:"sortable"},h=[n.KeyboardCode.Down,n.KeyboardCode.Right,n.KeyboardCode.Up,n.KeyboardCode.Left];exports.SortableContext=function({children:e,id:o,items:a,strategy:d=c}){const{active:l,dragOverlay:f,droppableRects:x,over:p,measureDroppableContainers:g,measuringScheduled:v}=n.useDndContext(),h=i.useUniqueId("Sortable",o),I=Boolean(null!==f.rect),y=t.useMemo(()=>a.map(e=>"string"==typeof e?e:e.id),[a]),b=l?y.indexOf(l.id):-1,m=p?y.indexOf(p.id):-1,w=t.useRef(y),C=(S=w.current,!(y.join()===S.join()));var S;const R=-1!==m&&-1===b||C;i.useIsomorphicLayoutEffect(()=>{C&&!v&&g(y)},[C,y,g,v]),t.useEffect(()=>{w.current=y},[y]);const D=t.useMemo(()=>({activeIndex:b,containerId:h,disableTransforms:R,items:y,overIndex:m,useDragOverlay:I,sortedRects:s(y,x),strategy:d}),[b,h,R,y,m,x,I,d]);return r.createElement(u.Provider,{value:D},e)},exports.arrayMove=o,exports.arraySwap=function(e,t,r){const n=e.slice();return n[t]=e[r],n[r]=e[t],n},exports.defaultAnimateLayoutChanges=x,exports.defaultNewIndexGetter=f,exports.horizontalListSortingStrategy=({rects:e,activeNodeRect:t,activeIndex:r,overIndex:n,index:i})=>{var o;const s=null!=(o=e[r])?o:t;if(!s)return null;const a=function(e,t,r){const n=e[t],i=e[t-1],o=e[t+1];return n&&(i||o)?r<t?i?n.left-(i.left+i.width):o.left-(n.left+n.width):o?o.left-(n.left+n.width):n.left-(i.left+i.width):0}(e,i,r);if(i===r){const t=e[n];return t?{x:r<n?t.left+t.width-(s.left+s.width):t.left-s.left,y:0,...d}:null}return i>r&&i<=n?{x:-s.width-a,y:0,...d}:i<r&&i>=n?{x:s.width+a,y:0,...d}:{x:0,y:0,...d}},exports.rectSortingStrategy=c,exports.rectSwappingStrategy=({activeIndex:e,index:t,rects:r,overIndex:n})=>{let i,o;return t===e&&(i=r[t],o=r[n]),t===n&&(i=r[t],o=r[e]),o&&i?{x:o.left-i.left,y:o.top-i.top,scaleX:o.width/i.width,scaleY:o.height/i.height}:null},exports.sortableKeyboardCoordinates=(e,{context:{active:t,collisionRect:r,droppableRects:i,droppableContainers:o,over:s,scrollableAncestors:a}})=>{if(h.includes(e.code)){if(e.preventDefault(),!t||!r)return;const d=[];o.getEnabled().forEach(t=>{if(!t||(null==t?void 0:t.disabled))return;const i=null==t?void 0:t.rect.current;if(i)switch(e.code){case n.KeyboardCode.Down:r.top<i.top&&d.push(t);break;case n.KeyboardCode.Up:r.top>i.top&&d.push(t);break;case n.KeyboardCode.Left:r.left>i.left&&d.push(t);break;case n.KeyboardCode.Right:r.left<i.left&&d.push(t)}});const c=n.closestCorners({active:t,collisionRect:r,droppableRects:i,droppableContainers:d,pointerCoordinates:null});let l=n.getFirstCollision(c,"id");if(l===(null==s?void 0:s.id)&&c.length>1&&(l=c[1].id),null!=l){const e=o.get(l),t=null==e?void 0:e.node.current,i=null==e?void 0:e.rect.current;if(t&&i){const e=n.getScrollableAncestors(t).some((e,t)=>a[t]!==e)?{x:0,y:0}:{x:r.width-i.width,y:r.height-i.height};return{x:i.left-e.x,y:i.top-e.y}}}}},exports.useSortable=function({animateLayoutChanges:e=x,attributes:r,disabled:o,data:s,getNewIndex:d=f,id:c,strategy:l,resizeObserverConfig:h,transition:I=p}){const{items:y,containerId:b,activeIndex:m,disableTransforms:w,sortedRects:C,overIndex:S,useDragOverlay:R,strategy:D}=t.useContext(u),O=y.indexOf(c),N=t.useMemo(()=>({sortable:{containerId:b,index:O,items:y},...s}),[b,s,O,y]),E=t.useMemo(()=>y.slice(y.indexOf(c)),[y,c]),{rect:K,node:L,isOver:M,setNodeRef:T}=n.useDroppable({id:c,data:N,resizeObserverConfig:{updateMeasurementsFor:E,...h}}),{active:k,activatorEvent:q,activeNodeRect:A,attributes:X,setNodeRef:Y,listeners:j,isDragging:z,over:F,transform:U}=n.useDraggable({id:c,data:N,attributes:{...v,...r},disabled:o}),B=i.useCombinedRefs(T,Y),P=Boolean(k),_=P&&!w&&a(m)&&a(S),G=!R&&z,H=G&&_?U:null,J=_?null!=H?H:(null!=l?l:D)({rects:C,activeNodeRect:A,activeIndex:m,overIndex:S,index:O}):null,Q=a(m)&&a(S)?d({id:c,items:y,activeIndex:m,overIndex:S}):O,V=null==k?void 0:k.id,W=t.useRef({activeId:V,items:y,newIndex:Q,containerId:b}),Z=y!==W.current.items,$=e({active:k,containerId:b,isDragging:z,isSorting:P,id:c,index:O,items:y,newIndex:W.current.newIndex,previousItems:W.current.items,previousContainerId:W.current.containerId,transition:I,wasDragging:null!=W.current.activeId}),ee=function({disabled:e,index:r,node:o,rect:s}){const[a,d]=t.useState(null),c=t.useRef(r);return i.useIsomorphicLayoutEffect(()=>{if(!e&&r!==c.current&&o.current){const e=s.current;if(e){const t=n.getClientRect(o.current,{ignoreTransform:!0}),r={x:e.left-t.left,y:e.top-t.top,scaleX:e.width/t.width,scaleY:e.height/t.height};(r.x||r.y)&&d(r)}}r!==c.current&&(c.current=r)},[e,r,o,s]),t.useEffect(()=>{a&&requestAnimationFrame(()=>{d(null)})},[a]),a}({disabled:!$,index:O,node:L,rect:K});return t.useEffect(()=>{P&&W.current.newIndex!==Q&&(W.current.newIndex=Q),b!==W.current.containerId&&(W.current.containerId=b),y!==W.current.items&&(W.current.items=y),V!==W.current.activeId&&(W.current.activeId=V)},[V,P,Q,b,y]),{active:k,activeIndex:m,attributes:X,rect:K,index:O,newIndex:Q,items:y,isOver:M,isSorting:P,isDragging:z,listeners:j,node:L,overIndex:S,over:F,setNodeRef:B,setDroppableNodeRef:T,setDraggableNodeRef:Y,transform:null!=ee?ee:J,transition:ee||Z&&W.current.newIndex===O?g:G&&!i.isKeyboardEvent(q)||!I?void 0:P||$?i.CSS.Transition.toString({...I,property:"transform"}):void 0}},exports.verticalListSortingStrategy=({activeIndex:e,activeNodeRect:t,index:r,rects:n,overIndex:i})=>{var o;const s=null!=(o=n[e])?o:t;if(!s)return null;if(r===e){const t=n[i];return t?{x:0,y:e<i?t.top+t.height-(s.top+s.height):t.top-s.top,...l}:null}const a=function(e,t,r){const n=e[t],i=e[t-1],o=e[t+1];return n?r<t?i?n.top-(i.top+i.height):o?o.top-(n.top+n.height):0:o?o.top-(n.top+n.height):i?n.top-(i.top+i.height):0:0}(n,r,e);return r>e&&r<=i?{x:0,y:-s.height-a,...l}:r<e&&r>=i?{x:0,y:s.height+a,...l}:{x:0,y:0,...l}}; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("react"),r=(e=t)&&"object"==typeof e&&"default"in e?e.default:e,n=require("@dnd-kit/core"),i=require("@dnd-kit/utilities");function o(e,t,r){const n=e.slice();return n.splice(r<0?n.length+r:r,0,n.splice(t,1)[0]),n}function s(e,t){return e.reduce((e,r,n)=>{const i=t.get(r);return i&&(e[n]=i),e},Array(e.length))}function a(e){return null!==e&&e>=0}const d={scaleX:1,scaleY:1},c=({rects:e,activeIndex:t,overIndex:r,index:n})=>{const i=o(e,r,t),s=e[n],a=i[n];return a&&s?{x:a.left-s.left,y:a.top-s.top,scaleX:a.width/s.width,scaleY:a.height/s.height}:null},l={scaleX:1,scaleY:1},u=r.createContext({activeIndex:-1,containerId:"Sortable",disableTransforms:!1,items:[],overIndex:-1,useDragOverlay:!1,sortedRects:[],strategy:c}),f=({id:e,items:t,activeIndex:r,overIndex:n})=>o(t,r,n).indexOf(e),g=({containerId:e,isSorting:t,wasDragging:r,index:n,items:i,newIndex:o,previousItems:s,previousContainerId:a,transition:d})=>!(!d||!r||s!==i&&n===o||!t&&(o===n||e!==a)),x={duration:200,easing:"ease"},p=i.CSS.Transition.toString({property:"transform",duration:0,easing:"linear"}),v={roleDescription:"sortable"},h=[n.KeyboardCode.Down,n.KeyboardCode.Right,n.KeyboardCode.Up,n.KeyboardCode.Left];exports.SortableContext=function({children:e,id:o,items:a,strategy:d=c}){const{active:l,dragOverlay:f,droppableRects:g,over:x,measureDroppableContainers:p,measuringScheduled:v}=n.useDndContext(),h=i.useUniqueId("Sortable",o),I=Boolean(null!==f.rect),y=t.useMemo(()=>a.map(e=>"string"==typeof e?e:e.id),[a]),b=l?y.indexOf(l.id):-1,m=x?y.indexOf(x.id):-1,w=t.useRef(y),C=!function(e,t){if(e===t)return!0;if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(e[r]!==t[r])return!1;return!0}(y,w.current),S=-1!==m&&-1===b||C;i.useIsomorphicLayoutEffect(()=>{C&&!v&&p(y)},[C,y,p,v]),t.useEffect(()=>{w.current=y},[y]);const R=t.useMemo(()=>({activeIndex:b,containerId:h,disableTransforms:S,items:y,overIndex:m,useDragOverlay:I,sortedRects:s(y,g),strategy:d}),[b,h,S,y,m,g,I,d]);return r.createElement(u.Provider,{value:R},e)},exports.arrayMove=o,exports.arraySwap=function(e,t,r){const n=e.slice();return n[t]=e[r],n[r]=e[t],n},exports.defaultAnimateLayoutChanges=g,exports.defaultNewIndexGetter=f,exports.horizontalListSortingStrategy=({rects:e,activeNodeRect:t,activeIndex:r,overIndex:n,index:i})=>{var o;const s=null!=(o=e[r])?o:t;if(!s)return null;const a=function(e,t,r){const n=e[t],i=e[t-1],o=e[t+1];return n&&(i||o)?r<t?i?n.left-(i.left+i.width):o.left-(n.left+n.width):o?o.left-(n.left+n.width):n.left-(i.left+i.width):0}(e,i,r);if(i===r){const t=e[n];return t?{x:r<n?t.left+t.width-(s.left+s.width):t.left-s.left,y:0,...d}:null}return i>r&&i<=n?{x:-s.width-a,y:0,...d}:i<r&&i>=n?{x:s.width+a,y:0,...d}:{x:0,y:0,...d}},exports.rectSortingStrategy=c,exports.rectSwappingStrategy=({activeIndex:e,index:t,rects:r,overIndex:n})=>{let i,o;return t===e&&(i=r[t],o=r[n]),t===n&&(i=r[t],o=r[e]),o&&i?{x:o.left-i.left,y:o.top-i.top,scaleX:o.width/i.width,scaleY:o.height/i.height}:null},exports.sortableKeyboardCoordinates=(e,{context:{active:t,collisionRect:r,droppableRects:i,droppableContainers:o,over:s,scrollableAncestors:a}})=>{if(h.includes(e.code)){if(e.preventDefault(),!t||!r)return;const d=[];o.getEnabled().forEach(t=>{if(!t||(null==t?void 0:t.disabled))return;const i=null==t?void 0:t.rect.current;if(i)switch(e.code){case n.KeyboardCode.Down:r.top<i.top&&d.push(t);break;case n.KeyboardCode.Up:r.top>i.top&&d.push(t);break;case n.KeyboardCode.Left:r.left>i.left&&d.push(t);break;case n.KeyboardCode.Right:r.left<i.left&&d.push(t)}});const c=n.closestCorners({active:t,collisionRect:r,droppableRects:i,droppableContainers:d,pointerCoordinates:null});let l=n.getFirstCollision(c,"id");if(l===(null==s?void 0:s.id)&&c.length>1&&(l=c[1].id),null!=l){const e=o.get(l),t=null==e?void 0:e.node.current,i=null==e?void 0:e.rect.current;if(t&&i){const e=n.getScrollableAncestors(t).some((e,t)=>a[t]!==e)?{x:0,y:0}:{x:r.width-i.width,y:r.height-i.height};return{x:i.left-e.x,y:i.top-e.y}}}}},exports.useSortable=function({animateLayoutChanges:e=g,attributes:r,disabled:o,data:s,getNewIndex:d=f,id:c,strategy:l,resizeObserverConfig:h,transition:I=x}){const{items:y,containerId:b,activeIndex:m,disableTransforms:w,sortedRects:C,overIndex:S,useDragOverlay:R,strategy:D}=t.useContext(u),O=y.indexOf(c),N=t.useMemo(()=>({sortable:{containerId:b,index:O,items:y},...s}),[b,s,O,y]),E=t.useMemo(()=>y.slice(y.indexOf(c)),[y,c]),{rect:K,node:L,isOver:M,setNodeRef:T}=n.useDroppable({id:c,data:N,resizeObserverConfig:{updateMeasurementsFor:E,...h}}),{active:k,activatorEvent:q,activeNodeRect:A,attributes:X,setNodeRef:Y,listeners:z,isDragging:F,over:U,transform:j}=n.useDraggable({id:c,data:N,attributes:{...v,...r},disabled:o}),B=i.useCombinedRefs(T,Y),P=Boolean(k),_=P&&!w&&a(m)&&a(S),G=!R&&F,H=G&&_?j:null,J=_?null!=H?H:(null!=l?l:D)({rects:C,activeNodeRect:A,activeIndex:m,overIndex:S,index:O}):null,Q=a(m)&&a(S)?d({id:c,items:y,activeIndex:m,overIndex:S}):O,V=null==k?void 0:k.id,W=t.useRef({activeId:V,items:y,newIndex:Q,containerId:b}),Z=y!==W.current.items,$=e({active:k,containerId:b,isDragging:F,isSorting:P,id:c,index:O,items:y,newIndex:W.current.newIndex,previousItems:W.current.items,previousContainerId:W.current.containerId,transition:I,wasDragging:null!=W.current.activeId}),ee=function({disabled:e,index:r,node:o,rect:s}){const[a,d]=t.useState(null),c=t.useRef(r);return i.useIsomorphicLayoutEffect(()=>{if(!e&&r!==c.current&&o.current){const e=s.current;if(e){const t=n.getClientRect(o.current,{ignoreTransform:!0}),r={x:e.left-t.left,y:e.top-t.top,scaleX:e.width/t.width,scaleY:e.height/t.height};(r.x||r.y)&&d(r)}}r!==c.current&&(c.current=r)},[e,r,o,s]),t.useEffect(()=>{a&&requestAnimationFrame(()=>{d(null)})},[a]),a}({disabled:!$,index:O,node:L,rect:K});return t.useEffect(()=>{P&&W.current.newIndex!==Q&&(W.current.newIndex=Q),b!==W.current.containerId&&(W.current.containerId=b),y!==W.current.items&&(W.current.items=y),V!==W.current.activeId&&(W.current.activeId=V)},[V,P,Q,b,y]),{active:k,activeIndex:m,attributes:X,rect:K,index:O,newIndex:Q,items:y,isOver:M,isSorting:P,isDragging:F,listeners:z,node:L,overIndex:S,over:U,setNodeRef:B,setDroppableNodeRef:T,setDraggableNodeRef:Y,transform:null!=ee?ee:J,transition:ee||Z&&W.current.newIndex===O?p:G&&!i.isKeyboardEvent(q)||!I?void 0:P||$?i.CSS.Transition.toString({...I,property:"transform"}):void 0}},exports.verticalListSortingStrategy=({activeIndex:e,activeNodeRect:t,index:r,rects:n,overIndex:i})=>{var o;const s=null!=(o=n[e])?o:t;if(!s)return null;if(r===e){const t=n[i];return t?{x:0,y:e<i?t.top+t.height-(s.top+s.height):t.top-s.top,...l}:null}const a=function(e,t,r){const n=e[t],i=e[t-1],o=e[t+1];return n?r<t?i?n.top-(i.top+i.height):o?o.top-(n.top+n.height):0:o?o.top-(n.top+n.height):i?n.top-(i.top+i.height):0:0}(n,r,e);return r>e&&r<=i?{x:0,y:-s.height-a,...l}:r<e&&r>=i?{x:0,y:s.height+a,...l}:{x:0,y:0,...l}}; | ||
//# sourceMappingURL=sortable.cjs.production.min.js.map |
@@ -300,3 +300,12 @@ import React, { useMemo, useRef, useEffect, useState, useContext } from 'react'; | ||
function isEqual(arr1, arr2) { | ||
return arr1.join() === arr2.join(); | ||
if (arr1 === arr2) return true; | ||
if (arr1.length !== arr2.length) return false; | ||
for (let i = 0; i < arr1.length; i++) { | ||
if (arr1[i] !== arr2[i]) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
@@ -303,0 +312,0 @@ |
{ | ||
"name": "@dnd-kit/sortable", | ||
"version": "7.0.0-next-20222231225", | ||
"version": "7.0.0-next-20223141625", | ||
"description": "Official sortable preset and sensors for dnd kit", | ||
@@ -34,6 +34,6 @@ "author": "Claudéric Demers", | ||
"react": ">=16.8.0", | ||
"@dnd-kit/core": "^5.1.0-next-20222231225" | ||
"@dnd-kit/core": "^5.1.0-next-20223141625" | ||
}, | ||
"devDependencies": { | ||
"@dnd-kit/core": "^5.1.0-next-20222231225" | ||
"@dnd-kit/core": "^5.1.0-next-20223141625" | ||
}, | ||
@@ -40,0 +40,0 @@ "publishConfig": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
200475
1390