@dnd-kit/modifiers 5.0.0-next-202204222123 → 5.0.0-next-202208173143
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +4 -4
- package/dist/modifiers.cjs.development.js +6 -1
- package/dist/modifiers.cjs.development.js.map +1 -1
- package/dist/modifiers.cjs.production.min.js +1 -1
- package/dist/modifiers.cjs.production.min.js.map +1 -1
- package/dist/modifiers.esm.js +7 -2
- package/dist/modifiers.esm.js.map +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# @dnd-kit/modifiers
|
2
2
|
|
3
|
-
## 5.0.0-next-
|
3
|
+
## 5.0.0-next-202208173143
|
4
4
|
|
5
5
|
### Minor Changes
|
6
6
|
|
@@ -29,9 +29,9 @@
|
|
29
29
|
|
30
30
|
### Patch Changes
|
31
31
|
|
32
|
-
- Updated dependencies [[`6310227`](https://github.com/clauderic/dnd-kit/commit/63102272d0d63dae349e2e9f638277e16a7d5970)]:
|
33
|
-
- @dnd-kit/core@5.0.0-next-
|
34
|
-
- @dnd-kit/utilities@3.1.0-next-
|
32
|
+
- Updated dependencies [[`f3ad20d`](https://github.com/clauderic/dnd-kit/commit/f3ad20d5b2c2f2ca7b82c193c9af5eef38c5ce11), [`02edd26`](https://github.com/clauderic/dnd-kit/commit/02edd2691b24bb49f2e7c9f9a3f282031bf658b7), [`c6c67cb`](https://github.com/clauderic/dnd-kit/commit/c6c67cb9cbc6e61027f7bb084fd2232160037d5e), [`6310227`](https://github.com/clauderic/dnd-kit/commit/63102272d0d63dae349e2e9f638277e16a7d5970), [`528c67e`](https://github.com/clauderic/dnd-kit/commit/528c67e4c617dfc0ce5221496aa8b222ffc82ddb), [`02edd26`](https://github.com/clauderic/dnd-kit/commit/02edd2691b24bb49f2e7c9f9a3f282031bf658b7)]:
|
33
|
+
- @dnd-kit/core@5.0.0-next-202208173143
|
34
|
+
- @dnd-kit/utilities@3.1.0-next-202208173143
|
35
35
|
|
36
36
|
## 4.0.0
|
37
37
|
|
@@ -91,8 +91,13 @@ const snapCenterToCursor = ({
|
|
91
91
|
activeNodeRect,
|
92
92
|
transform
|
93
93
|
}) => {
|
94
|
-
if (activeNodeRect && activatorEvent
|
94
|
+
if (activeNodeRect && activatorEvent) {
|
95
95
|
const activatorCoordinates = utilities.getEventCoordinates(activatorEvent);
|
96
|
+
|
97
|
+
if (!activatorCoordinates) {
|
98
|
+
return transform;
|
99
|
+
}
|
100
|
+
|
96
101
|
const offsetX = activatorCoordinates.x - activeNodeRect.left;
|
97
102
|
const offsetY = activatorCoordinates.y - activeNodeRect.top;
|
98
103
|
return { ...transform,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"modifiers.cjs.development.js","sources":["../src/createSnapModifier.ts","../src/restrictToHorizontalAxis.ts","../src/utilities/restrictToBoundingRect.ts","../src/restrictToParentElement.ts","../src/restrictToFirstScrollableAncestor.ts","../src/restrictToVerticalAxis.ts","../src/restrictToWindowEdges.ts","../src/snapCenterToCursor.ts"],"sourcesContent":["import type {Modifier} from '@dnd-kit/core';\n\nexport function createSnapModifier(gridSize: number): Modifier {\n return ({transform}) => ({\n ...transform,\n x: Math.ceil(transform.x / gridSize) * gridSize,\n y: Math.ceil(transform.y / gridSize) * gridSize,\n });\n}\n","import type {Modifier} from '@dnd-kit/core';\n\nexport const restrictToHorizontalAxis: Modifier = ({transform}) => {\n return {\n ...transform,\n y: 0,\n };\n};\n","import type {ClientRect} from '@dnd-kit/core';\nimport type {Transform} from '@dnd-kit/utilities';\n\nexport function restrictToBoundingRect(\n transform: Transform,\n rect: ClientRect,\n boundingRect: ClientRect\n): Transform {\n const value = {\n ...transform,\n };\n\n if (rect.top + transform.y <= boundingRect.top) {\n value.y = boundingRect.top - rect.top;\n } else if (\n rect.bottom + transform.y >=\n boundingRect.top + boundingRect.height\n ) {\n value.y = boundingRect.top + boundingRect.height - rect.bottom;\n }\n\n if (rect.left + transform.x <= boundingRect.left) {\n value.x = boundingRect.left - rect.left;\n } else if (\n rect.right + transform.x >=\n boundingRect.left + boundingRect.width\n ) {\n value.x = boundingRect.left + boundingRect.width - rect.right;\n }\n\n return value;\n}\n","import type {Modifier} from '@dnd-kit/core';\nimport {restrictToBoundingRect} from './utilities';\n\nexport const restrictToParentElement: Modifier = ({\n transform,\n activeNodeRect,\n containerNodeRect,\n}) => {\n if (!activeNodeRect || !containerNodeRect) {\n return transform;\n }\n\n return restrictToBoundingRect(transform, activeNodeRect, containerNodeRect);\n};\n","import type {Modifier} from '@dnd-kit/core';\nimport {restrictToBoundingRect} from './utilities';\n\nexport const restrictToFirstScrollableAncestor: Modifier = ({\n transform,\n activeNodeRect,\n scrollableAncestorRects,\n}) => {\n const firstScrollableAncestorRect = scrollableAncestorRects[0];\n\n if (!activeNodeRect || !firstScrollableAncestorRect) {\n return transform;\n }\n\n return restrictToBoundingRect(\n transform,\n activeNodeRect,\n firstScrollableAncestorRect\n );\n};\n","import type {Modifier} from '@dnd-kit/core';\n\nexport const restrictToVerticalAxis: Modifier = ({transform}) => {\n return {\n ...transform,\n x: 0,\n };\n};\n","import type {Modifier} from '@dnd-kit/core';\n\nimport {restrictToBoundingRect} from './utilities';\n\nexport const restrictToWindowEdges: Modifier = ({\n transform,\n activeNodeRect,\n windowRect,\n}) => {\n if (!activeNodeRect || !windowRect) {\n return transform;\n }\n\n return restrictToBoundingRect(transform, activeNodeRect, windowRect);\n};\n","import type {Modifier} from '@dnd-kit/core';\nimport {
|
1
|
+
{"version":3,"file":"modifiers.cjs.development.js","sources":["../src/createSnapModifier.ts","../src/restrictToHorizontalAxis.ts","../src/utilities/restrictToBoundingRect.ts","../src/restrictToParentElement.ts","../src/restrictToFirstScrollableAncestor.ts","../src/restrictToVerticalAxis.ts","../src/restrictToWindowEdges.ts","../src/snapCenterToCursor.ts"],"sourcesContent":["import type {Modifier} from '@dnd-kit/core';\n\nexport function createSnapModifier(gridSize: number): Modifier {\n return ({transform}) => ({\n ...transform,\n x: Math.ceil(transform.x / gridSize) * gridSize,\n y: Math.ceil(transform.y / gridSize) * gridSize,\n });\n}\n","import type {Modifier} from '@dnd-kit/core';\n\nexport const restrictToHorizontalAxis: Modifier = ({transform}) => {\n return {\n ...transform,\n y: 0,\n };\n};\n","import type {ClientRect} from '@dnd-kit/core';\nimport type {Transform} from '@dnd-kit/utilities';\n\nexport function restrictToBoundingRect(\n transform: Transform,\n rect: ClientRect,\n boundingRect: ClientRect\n): Transform {\n const value = {\n ...transform,\n };\n\n if (rect.top + transform.y <= boundingRect.top) {\n value.y = boundingRect.top - rect.top;\n } else if (\n rect.bottom + transform.y >=\n boundingRect.top + boundingRect.height\n ) {\n value.y = boundingRect.top + boundingRect.height - rect.bottom;\n }\n\n if (rect.left + transform.x <= boundingRect.left) {\n value.x = boundingRect.left - rect.left;\n } else if (\n rect.right + transform.x >=\n boundingRect.left + boundingRect.width\n ) {\n value.x = boundingRect.left + boundingRect.width - rect.right;\n }\n\n return value;\n}\n","import type {Modifier} from '@dnd-kit/core';\nimport {restrictToBoundingRect} from './utilities';\n\nexport const restrictToParentElement: Modifier = ({\n transform,\n activeNodeRect,\n containerNodeRect,\n}) => {\n if (!activeNodeRect || !containerNodeRect) {\n return transform;\n }\n\n return restrictToBoundingRect(transform, activeNodeRect, containerNodeRect);\n};\n","import type {Modifier} from '@dnd-kit/core';\nimport {restrictToBoundingRect} from './utilities';\n\nexport const restrictToFirstScrollableAncestor: Modifier = ({\n transform,\n activeNodeRect,\n scrollableAncestorRects,\n}) => {\n const firstScrollableAncestorRect = scrollableAncestorRects[0];\n\n if (!activeNodeRect || !firstScrollableAncestorRect) {\n return transform;\n }\n\n return restrictToBoundingRect(\n transform,\n activeNodeRect,\n firstScrollableAncestorRect\n );\n};\n","import type {Modifier} from '@dnd-kit/core';\n\nexport const restrictToVerticalAxis: Modifier = ({transform}) => {\n return {\n ...transform,\n x: 0,\n };\n};\n","import type {Modifier} from '@dnd-kit/core';\n\nimport {restrictToBoundingRect} from './utilities';\n\nexport const restrictToWindowEdges: Modifier = ({\n transform,\n activeNodeRect,\n windowRect,\n}) => {\n if (!activeNodeRect || !windowRect) {\n return transform;\n }\n\n return restrictToBoundingRect(transform, activeNodeRect, windowRect);\n};\n","import type {Modifier} from '@dnd-kit/core';\nimport {getEventCoordinates} from '@dnd-kit/utilities';\n\nexport const snapCenterToCursor: Modifier = ({\n activatorEvent,\n activeNodeRect,\n transform,\n}) => {\n if (activeNodeRect && activatorEvent) {\n const activatorCoordinates = getEventCoordinates(activatorEvent);\n\n if (!activatorCoordinates) {\n return transform;\n }\n\n const offsetX = activatorCoordinates.x - activeNodeRect.left;\n const offsetY = activatorCoordinates.y - activeNodeRect.top;\n\n return {\n ...transform,\n x: transform.x + offsetX - activeNodeRect.width / 2,\n y: transform.y + offsetY - activeNodeRect.height / 2,\n };\n }\n\n return transform;\n};\n"],"names":["createSnapModifier","gridSize","transform","x","Math","ceil","y","restrictToHorizontalAxis","restrictToBoundingRect","rect","boundingRect","value","top","bottom","height","left","right","width","restrictToParentElement","activeNodeRect","containerNodeRect","restrictToFirstScrollableAncestor","scrollableAncestorRects","firstScrollableAncestorRect","restrictToVerticalAxis","restrictToWindowEdges","windowRect","snapCenterToCursor","activatorEvent","activatorCoordinates","getEventCoordinates","offsetX","offsetY"],"mappings":";;;;;;SAEgBA,mBAAmBC;AACjC,SAAO,CAAC;AAACC,IAAAA;AAAD,GAAD,MAAkB,EACvB,GAAGA,SADoB;AAEvBC,IAAAA,CAAC,EAAEC,IAAI,CAACC,IAAL,CAAUH,SAAS,CAACC,CAAV,GAAcF,QAAxB,IAAoCA,QAFhB;AAGvBK,IAAAA,CAAC,EAAEF,IAAI,CAACC,IAAL,CAAUH,SAAS,CAACI,CAAV,GAAcL,QAAxB,IAAoCA;AAHhB,GAAlB,CAAP;AAKD;;MCNYM,wBAAwB,GAAa,CAAC;AAACL,EAAAA;AAAD,CAAD;AAChD,SAAO,EACL,GAAGA,SADE;AAELI,IAAAA,CAAC,EAAE;AAFE,GAAP;AAID,CALM;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AAc,CAACF,KAAf,GAAuB,CAF7C;AAGLX,MAAAA,CAAC,EAAEJ,SAAS,CAACI,CAAV,GAAc0B,OAAd,GAAwBb,cAAc,CAACL,MAAf,GAAwB;AAH9C,KAAP;AAKD;;AAED,SAAOZ,SAAP;AACD,CAvBM;;;;;;;;;;"}
|
@@ -1,2 +1,2 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@dnd-kit/utilities");function e(t,e,r){const o={...t};return e.top+t.y<=r.top?o.y=r.top-e.top:e.bottom+t.y>=r.top+r.height&&(o.y=r.top+r.height-e.bottom),e.left+t.x<=r.left?o.x=r.left-e.left:e.right+t.x>=r.left+r.width&&(o.x=r.left+r.width-e.right),o}exports.createSnapModifier=function(t){return({transform:e})=>({...e,x:Math.ceil(e.x/t)*t,y:Math.ceil(e.y/t)*t})},exports.restrictToFirstScrollableAncestor=({transform:t,activeNodeRect:r,scrollableAncestorRects:o})=>{const i=o[0];return r&&i?e(t,r,i):t},exports.restrictToHorizontalAxis=({transform:t})=>({...t,y:0}),exports.restrictToParentElement=({transform:t,activeNodeRect:r,containerNodeRect:o})=>r&&o?e(t,r,o):t,exports.restrictToVerticalAxis=({transform:t})=>({...t,x:0}),exports.restrictToWindowEdges=({transform:t,activeNodeRect:r,windowRect:o})=>r&&o?e(t,r,o):t,exports.snapCenterToCursor=({activatorEvent:e,activeNodeRect:r,transform:o})=>{if(r&&e
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@dnd-kit/utilities");function e(t,e,r){const o={...t};return e.top+t.y<=r.top?o.y=r.top-e.top:e.bottom+t.y>=r.top+r.height&&(o.y=r.top+r.height-e.bottom),e.left+t.x<=r.left?o.x=r.left-e.left:e.right+t.x>=r.left+r.width&&(o.x=r.left+r.width-e.right),o}exports.createSnapModifier=function(t){return({transform:e})=>({...e,x:Math.ceil(e.x/t)*t,y:Math.ceil(e.y/t)*t})},exports.restrictToFirstScrollableAncestor=({transform:t,activeNodeRect:r,scrollableAncestorRects:o})=>{const i=o[0];return r&&i?e(t,r,i):t},exports.restrictToHorizontalAxis=({transform:t})=>({...t,y:0}),exports.restrictToParentElement=({transform:t,activeNodeRect:r,containerNodeRect:o})=>r&&o?e(t,r,o):t,exports.restrictToVerticalAxis=({transform:t})=>({...t,x:0}),exports.restrictToWindowEdges=({transform:t,activeNodeRect:r,windowRect:o})=>r&&o?e(t,r,o):t,exports.snapCenterToCursor=({activatorEvent:e,activeNodeRect:r,transform:o})=>{if(r&&e){const i=t.getEventCoordinates(e);if(!i)return o;const s=i.x-r.left,n=i.y-r.top;return{...o,x:o.x+s-r.width/2,y:o.y+n-r.height/2}}return o};
|
2
2
|
//# sourceMappingURL=modifiers.cjs.production.min.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"modifiers.cjs.production.min.js","sources":["../src/utilities/restrictToBoundingRect.ts","../src/createSnapModifier.ts","../src/restrictToFirstScrollableAncestor.ts","../src/restrictToHorizontalAxis.ts","../src/restrictToParentElement.ts","../src/restrictToVerticalAxis.ts","../src/restrictToWindowEdges.ts","../src/snapCenterToCursor.ts"],"sourcesContent":["import type {ClientRect} from '@dnd-kit/core';\nimport type {Transform} from '@dnd-kit/utilities';\n\nexport function restrictToBoundingRect(\n transform: Transform,\n rect: ClientRect,\n boundingRect: ClientRect\n): Transform {\n const value = {\n ...transform,\n };\n\n if (rect.top + transform.y <= boundingRect.top) {\n value.y = boundingRect.top - rect.top;\n } else if (\n rect.bottom + transform.y >=\n boundingRect.top + boundingRect.height\n ) {\n value.y = boundingRect.top + boundingRect.height - rect.bottom;\n }\n\n if (rect.left + transform.x <= boundingRect.left) {\n value.x = boundingRect.left - rect.left;\n } else if (\n rect.right + transform.x >=\n boundingRect.left + boundingRect.width\n ) {\n value.x = boundingRect.left + boundingRect.width - rect.right;\n }\n\n return value;\n}\n","import type {Modifier} from '@dnd-kit/core';\n\nexport function createSnapModifier(gridSize: number): Modifier {\n return ({transform}) => ({\n ...transform,\n x: Math.ceil(transform.x / gridSize) * gridSize,\n y: Math.ceil(transform.y / gridSize) * gridSize,\n });\n}\n","import type {Modifier} from '@dnd-kit/core';\nimport {restrictToBoundingRect} from './utilities';\n\nexport const restrictToFirstScrollableAncestor: Modifier = ({\n transform,\n activeNodeRect,\n scrollableAncestorRects,\n}) => {\n const firstScrollableAncestorRect = scrollableAncestorRects[0];\n\n if (!activeNodeRect || !firstScrollableAncestorRect) {\n return transform;\n }\n\n return restrictToBoundingRect(\n transform,\n activeNodeRect,\n firstScrollableAncestorRect\n );\n};\n","import type {Modifier} from '@dnd-kit/core';\n\nexport const restrictToHorizontalAxis: Modifier = ({transform}) => {\n return {\n ...transform,\n y: 0,\n };\n};\n","import type {Modifier} from '@dnd-kit/core';\nimport {restrictToBoundingRect} from './utilities';\n\nexport const restrictToParentElement: Modifier = ({\n transform,\n activeNodeRect,\n containerNodeRect,\n}) => {\n if (!activeNodeRect || !containerNodeRect) {\n return transform;\n }\n\n return restrictToBoundingRect(transform, activeNodeRect, containerNodeRect);\n};\n","import type {Modifier} from '@dnd-kit/core';\n\nexport const restrictToVerticalAxis: Modifier = ({transform}) => {\n return {\n ...transform,\n x: 0,\n };\n};\n","import type {Modifier} from '@dnd-kit/core';\n\nimport {restrictToBoundingRect} from './utilities';\n\nexport const restrictToWindowEdges: Modifier = ({\n transform,\n activeNodeRect,\n windowRect,\n}) => {\n if (!activeNodeRect || !windowRect) {\n return transform;\n }\n\n return restrictToBoundingRect(transform, activeNodeRect, windowRect);\n};\n","import type {Modifier} from '@dnd-kit/core';\nimport {
|
1
|
+
{"version":3,"file":"modifiers.cjs.production.min.js","sources":["../src/utilities/restrictToBoundingRect.ts","../src/createSnapModifier.ts","../src/restrictToFirstScrollableAncestor.ts","../src/restrictToHorizontalAxis.ts","../src/restrictToParentElement.ts","../src/restrictToVerticalAxis.ts","../src/restrictToWindowEdges.ts","../src/snapCenterToCursor.ts"],"sourcesContent":["import type {ClientRect} from '@dnd-kit/core';\nimport type {Transform} from '@dnd-kit/utilities';\n\nexport function restrictToBoundingRect(\n transform: Transform,\n rect: ClientRect,\n boundingRect: ClientRect\n): Transform {\n const value = {\n ...transform,\n };\n\n if (rect.top + transform.y <= boundingRect.top) {\n value.y = boundingRect.top - rect.top;\n } else if (\n rect.bottom + transform.y >=\n boundingRect.top + boundingRect.height\n ) {\n value.y = boundingRect.top + boundingRect.height - rect.bottom;\n }\n\n if (rect.left + transform.x <= boundingRect.left) {\n value.x = boundingRect.left - rect.left;\n } else if (\n rect.right + transform.x >=\n boundingRect.left + boundingRect.width\n ) {\n value.x = boundingRect.left + boundingRect.width - rect.right;\n }\n\n return value;\n}\n","import type {Modifier} from '@dnd-kit/core';\n\nexport function createSnapModifier(gridSize: number): Modifier {\n return ({transform}) => ({\n ...transform,\n x: Math.ceil(transform.x / gridSize) * gridSize,\n y: Math.ceil(transform.y / gridSize) * gridSize,\n });\n}\n","import type {Modifier} from '@dnd-kit/core';\nimport {restrictToBoundingRect} from './utilities';\n\nexport const restrictToFirstScrollableAncestor: Modifier = ({\n transform,\n activeNodeRect,\n scrollableAncestorRects,\n}) => {\n const firstScrollableAncestorRect = scrollableAncestorRects[0];\n\n if (!activeNodeRect || !firstScrollableAncestorRect) {\n return transform;\n }\n\n return restrictToBoundingRect(\n transform,\n activeNodeRect,\n firstScrollableAncestorRect\n );\n};\n","import type {Modifier} from '@dnd-kit/core';\n\nexport const restrictToHorizontalAxis: Modifier = ({transform}) => {\n return {\n ...transform,\n y: 0,\n };\n};\n","import type {Modifier} from '@dnd-kit/core';\nimport {restrictToBoundingRect} from './utilities';\n\nexport const restrictToParentElement: Modifier = ({\n transform,\n activeNodeRect,\n containerNodeRect,\n}) => {\n if (!activeNodeRect || !containerNodeRect) {\n return transform;\n }\n\n return restrictToBoundingRect(transform, activeNodeRect, containerNodeRect);\n};\n","import type {Modifier} from '@dnd-kit/core';\n\nexport const restrictToVerticalAxis: Modifier = ({transform}) => {\n return {\n ...transform,\n x: 0,\n };\n};\n","import type {Modifier} from '@dnd-kit/core';\n\nimport {restrictToBoundingRect} from './utilities';\n\nexport const restrictToWindowEdges: Modifier = ({\n transform,\n activeNodeRect,\n windowRect,\n}) => {\n if (!activeNodeRect || !windowRect) {\n return transform;\n }\n\n return restrictToBoundingRect(transform, activeNodeRect, windowRect);\n};\n","import type {Modifier} from '@dnd-kit/core';\nimport {getEventCoordinates} from '@dnd-kit/utilities';\n\nexport const snapCenterToCursor: Modifier = ({\n activatorEvent,\n activeNodeRect,\n transform,\n}) => {\n if (activeNodeRect && activatorEvent) {\n const activatorCoordinates = getEventCoordinates(activatorEvent);\n\n if (!activatorCoordinates) {\n return transform;\n }\n\n const offsetX = activatorCoordinates.x - activeNodeRect.left;\n const offsetY = activatorCoordinates.y - activeNodeRect.top;\n\n return {\n ...transform,\n x: transform.x + offsetX - activeNodeRect.width / 2,\n y: transform.y + offsetY - activeNodeRect.height / 2,\n };\n }\n\n return transform;\n};\n"],"names":["restrictToBoundingRect","transform","rect","boundingRect","value","top","y","bottom","height","left","x","right","width","gridSize","Math","ceil","activeNodeRect","scrollableAncestorRects","firstScrollableAncestorRect","containerNodeRect","windowRect","activatorEvent","activatorCoordinates","getEventCoordinates","offsetX","offsetY"],"mappings":"iHAGgBA,EACdC,EACAC,EACAC,SAEMC,EAAQ,IACTH,UAGDC,EAAKG,IAAMJ,EAAUK,GAAKH,EAAaE,IACzCD,EAAME,EAAIH,EAAaE,IAAMH,EAAKG,IAElCH,EAAKK,OAASN,EAAUK,GACxBH,EAAaE,IAAMF,EAAaK,SAEhCJ,EAAME,EAAIH,EAAaE,IAAMF,EAAaK,OAASN,EAAKK,QAGtDL,EAAKO,KAAOR,EAAUS,GAAKP,EAAaM,KAC1CL,EAAMM,EAAIP,EAAaM,KAAOP,EAAKO,KAEnCP,EAAKS,MAAQV,EAAUS,GACvBP,EAAaM,KAAON,EAAaS,QAEjCR,EAAMM,EAAIP,EAAaM,KAAON,EAAaS,MAAQV,EAAKS,OAGnDP,sCC5B0BS,SAC1B,EAAEZ,UAAAA,UACJA,EACHS,EAAGI,KAAKC,KAAKd,EAAUS,EAAIG,GAAYA,EACvCP,EAAGQ,KAAKC,KAAKd,EAAUK,EAAIO,GAAYA,+CCHgB,EACzDZ,UAAAA,EACAe,eAAAA,EACAC,wBAAAA,YAEMC,EAA8BD,EAAwB,UAEvDD,GAAmBE,EAIjBlB,EACLC,EACAe,EACAE,GANOjB,oCCTuC,EAAEA,UAAAA,MAC3C,IACFA,EACHK,EAAG,oCCF0C,EAC/CL,UAAAA,EACAe,eAAAA,EACAG,kBAAAA,KAEKH,GAAmBG,EAIjBnB,EAAuBC,EAAWe,EAAgBG,GAHhDlB,iCCPqC,EAAEA,UAAAA,MACzC,IACFA,EACHS,EAAG,kCCDwC,EAC7CT,UAAAA,EACAe,eAAAA,EACAI,WAAAA,KAEKJ,GAAmBI,EAIjBpB,EAAuBC,EAAWe,EAAgBI,GAHhDnB,6BCPiC,EAC1CoB,eAAAA,EACAL,eAAAA,EACAf,UAAAA,SAEIe,GAAkBK,EAAgB,OAC9BC,EAAuBC,sBAAoBF,OAE5CC,SACIrB,QAGHuB,EAAUF,EAAqBZ,EAAIM,EAAeP,KAClDgB,EAAUH,EAAqBhB,EAAIU,EAAeX,UAEjD,IACFJ,EACHS,EAAGT,EAAUS,EAAIc,EAAUR,EAAeJ,MAAQ,EAClDN,EAAGL,EAAUK,EAAImB,EAAUT,EAAeR,OAAS,UAIhDP"}
|
package/dist/modifiers.esm.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import {
|
1
|
+
import { getEventCoordinates } from '@dnd-kit/utilities';
|
2
2
|
|
3
3
|
function createSnapModifier(gridSize) {
|
4
4
|
return ({
|
@@ -87,8 +87,13 @@ const snapCenterToCursor = ({
|
|
87
87
|
activeNodeRect,
|
88
88
|
transform
|
89
89
|
}) => {
|
90
|
-
if (activeNodeRect && activatorEvent
|
90
|
+
if (activeNodeRect && activatorEvent) {
|
91
91
|
const activatorCoordinates = getEventCoordinates(activatorEvent);
|
92
|
+
|
93
|
+
if (!activatorCoordinates) {
|
94
|
+
return transform;
|
95
|
+
}
|
96
|
+
|
92
97
|
const offsetX = activatorCoordinates.x - activeNodeRect.left;
|
93
98
|
const offsetY = activatorCoordinates.y - activeNodeRect.top;
|
94
99
|
return { ...transform,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"modifiers.esm.js","sources":["../src/createSnapModifier.ts","../src/restrictToHorizontalAxis.ts","../src/utilities/restrictToBoundingRect.ts","../src/restrictToParentElement.ts","../src/restrictToFirstScrollableAncestor.ts","../src/restrictToVerticalAxis.ts","../src/restrictToWindowEdges.ts","../src/snapCenterToCursor.ts"],"sourcesContent":["import type {Modifier} from '@dnd-kit/core';\n\nexport function createSnapModifier(gridSize: number): Modifier {\n return ({transform}) => ({\n ...transform,\n x: Math.ceil(transform.x / gridSize) * gridSize,\n y: Math.ceil(transform.y / gridSize) * gridSize,\n });\n}\n","import type {Modifier} from '@dnd-kit/core';\n\nexport const restrictToHorizontalAxis: Modifier = ({transform}) => {\n return {\n ...transform,\n y: 0,\n };\n};\n","import type {ClientRect} from '@dnd-kit/core';\nimport type {Transform} from '@dnd-kit/utilities';\n\nexport function restrictToBoundingRect(\n transform: Transform,\n rect: ClientRect,\n boundingRect: ClientRect\n): Transform {\n const value = {\n ...transform,\n };\n\n if (rect.top + transform.y <= boundingRect.top) {\n value.y = boundingRect.top - rect.top;\n } else if (\n rect.bottom + transform.y >=\n boundingRect.top + boundingRect.height\n ) {\n value.y = boundingRect.top + boundingRect.height - rect.bottom;\n }\n\n if (rect.left + transform.x <= boundingRect.left) {\n value.x = boundingRect.left - rect.left;\n } else if (\n rect.right + transform.x >=\n boundingRect.left + boundingRect.width\n ) {\n value.x = boundingRect.left + boundingRect.width - rect.right;\n }\n\n return value;\n}\n","import type {Modifier} from '@dnd-kit/core';\nimport {restrictToBoundingRect} from './utilities';\n\nexport const restrictToParentElement: Modifier = ({\n transform,\n activeNodeRect,\n containerNodeRect,\n}) => {\n if (!activeNodeRect || !containerNodeRect) {\n return transform;\n }\n\n return restrictToBoundingRect(transform, activeNodeRect, containerNodeRect);\n};\n","import type {Modifier} from '@dnd-kit/core';\nimport {restrictToBoundingRect} from './utilities';\n\nexport const restrictToFirstScrollableAncestor: Modifier = ({\n transform,\n activeNodeRect,\n scrollableAncestorRects,\n}) => {\n const firstScrollableAncestorRect = scrollableAncestorRects[0];\n\n if (!activeNodeRect || !firstScrollableAncestorRect) {\n return transform;\n }\n\n return restrictToBoundingRect(\n transform,\n activeNodeRect,\n firstScrollableAncestorRect\n );\n};\n","import type {Modifier} from '@dnd-kit/core';\n\nexport const restrictToVerticalAxis: Modifier = ({transform}) => {\n return {\n ...transform,\n x: 0,\n };\n};\n","import type {Modifier} from '@dnd-kit/core';\n\nimport {restrictToBoundingRect} from './utilities';\n\nexport const restrictToWindowEdges: Modifier = ({\n transform,\n activeNodeRect,\n windowRect,\n}) => {\n if (!activeNodeRect || !windowRect) {\n return transform;\n }\n\n return restrictToBoundingRect(transform, activeNodeRect, windowRect);\n};\n","import type {Modifier} from '@dnd-kit/core';\nimport {
|
1
|
+
{"version":3,"file":"modifiers.esm.js","sources":["../src/createSnapModifier.ts","../src/restrictToHorizontalAxis.ts","../src/utilities/restrictToBoundingRect.ts","../src/restrictToParentElement.ts","../src/restrictToFirstScrollableAncestor.ts","../src/restrictToVerticalAxis.ts","../src/restrictToWindowEdges.ts","../src/snapCenterToCursor.ts"],"sourcesContent":["import type {Modifier} from '@dnd-kit/core';\n\nexport function createSnapModifier(gridSize: number): Modifier {\n return ({transform}) => ({\n ...transform,\n x: Math.ceil(transform.x / gridSize) * gridSize,\n y: Math.ceil(transform.y / gridSize) * gridSize,\n });\n}\n","import type {Modifier} from '@dnd-kit/core';\n\nexport const restrictToHorizontalAxis: Modifier = ({transform}) => {\n return {\n ...transform,\n y: 0,\n };\n};\n","import type {ClientRect} from '@dnd-kit/core';\nimport type {Transform} from '@dnd-kit/utilities';\n\nexport function restrictToBoundingRect(\n transform: Transform,\n rect: ClientRect,\n boundingRect: ClientRect\n): Transform {\n const value = {\n ...transform,\n };\n\n if (rect.top + transform.y <= boundingRect.top) {\n value.y = boundingRect.top - rect.top;\n } else if (\n rect.bottom + transform.y >=\n boundingRect.top + boundingRect.height\n ) {\n value.y = boundingRect.top + boundingRect.height - rect.bottom;\n }\n\n if (rect.left + transform.x <= boundingRect.left) {\n value.x = boundingRect.left - rect.left;\n } else if (\n rect.right + transform.x >=\n boundingRect.left + boundingRect.width\n ) {\n value.x = boundingRect.left + boundingRect.width - rect.right;\n }\n\n return value;\n}\n","import type {Modifier} from '@dnd-kit/core';\nimport {restrictToBoundingRect} from './utilities';\n\nexport const restrictToParentElement: Modifier = ({\n transform,\n activeNodeRect,\n containerNodeRect,\n}) => {\n if (!activeNodeRect || !containerNodeRect) {\n return transform;\n }\n\n return restrictToBoundingRect(transform, activeNodeRect, containerNodeRect);\n};\n","import type {Modifier} from '@dnd-kit/core';\nimport {restrictToBoundingRect} from './utilities';\n\nexport const restrictToFirstScrollableAncestor: Modifier = ({\n transform,\n activeNodeRect,\n scrollableAncestorRects,\n}) => {\n const firstScrollableAncestorRect = scrollableAncestorRects[0];\n\n if (!activeNodeRect || !firstScrollableAncestorRect) {\n return transform;\n }\n\n return restrictToBoundingRect(\n transform,\n activeNodeRect,\n firstScrollableAncestorRect\n );\n};\n","import type {Modifier} from '@dnd-kit/core';\n\nexport const restrictToVerticalAxis: Modifier = ({transform}) => {\n return {\n ...transform,\n x: 0,\n };\n};\n","import type {Modifier} from '@dnd-kit/core';\n\nimport {restrictToBoundingRect} from './utilities';\n\nexport const restrictToWindowEdges: Modifier = ({\n transform,\n activeNodeRect,\n windowRect,\n}) => {\n if (!activeNodeRect || !windowRect) {\n return transform;\n }\n\n return restrictToBoundingRect(transform, activeNodeRect, windowRect);\n};\n","import type {Modifier} from '@dnd-kit/core';\nimport {getEventCoordinates} from '@dnd-kit/utilities';\n\nexport const snapCenterToCursor: Modifier = ({\n activatorEvent,\n activeNodeRect,\n transform,\n}) => {\n if (activeNodeRect && activatorEvent) {\n const activatorCoordinates = getEventCoordinates(activatorEvent);\n\n if (!activatorCoordinates) {\n return transform;\n }\n\n const offsetX = activatorCoordinates.x - activeNodeRect.left;\n const offsetY = activatorCoordinates.y - activeNodeRect.top;\n\n return {\n ...transform,\n x: transform.x + offsetX - activeNodeRect.width / 2,\n y: transform.y + offsetY - activeNodeRect.height / 2,\n };\n }\n\n return transform;\n};\n"],"names":["createSnapModifier","gridSize","transform","x","Math","ceil","y","restrictToHorizontalAxis","restrictToBoundingRect","rect","boundingRect","value","top","bottom","height","left","right","width","restrictToParentElement","activeNodeRect","containerNodeRect","restrictToFirstScrollableAncestor","scrollableAncestorRects","firstScrollableAncestorRect","restrictToVerticalAxis","restrictToWindowEdges","windowRect","snapCenterToCursor","activatorEvent","activatorCoordinates","getEventCoordinates","offsetX","offsetY"],"mappings":";;SAEgBA,mBAAmBC;AACjC,SAAO,CAAC;AAACC,IAAAA;AAAD,GAAD,MAAkB,EACvB,GAAGA,SADoB;AAEvBC,IAAAA,CAAC,EAAEC,IAAI,CAACC,IAAL,CAAUH,SAAS,CAACC,CAAV,GAAcF,QAAxB,IAAoCA,QAFhB;AAGvBK,IAAAA,CAAC,EAAEF,IAAI,CAACC,IAAL,CAAUH,SAAS,CAACI,CAAV,GAAcL,QAAxB,IAAoCA;AAHhB,GAAlB,CAAP;AAKD;;MCNYM,wBAAwB,GAAa,CAAC;AAACL,EAAAA;AAAD,CAAD;AAChD,SAAO,EACL,GAAGA,SADE;AAELI,IAAAA,CAAC,EAAE;AAFE,GAAP;AAID,CALM;;SCCSE,uBACdN,WACAO,MACAC;AAEA,QAAMC,KAAK,GAAG,EACZ,GAAGT;AADS,GAAd;;AAIA,MAAIO,IAAI,CAACG,GAAL,GAAWV,SAAS,CAACI,CAArB,IAA0BI,YAAY,CAACE,GAA3C,EAAgD;AAC9CD,IAAAA,KAAK,CAACL,C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GED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@dnd-kit/modifiers",
|
3
|
-
"version": "5.0.0-next-
|
3
|
+
"version": "5.0.0-next-202208173143",
|
4
4
|
"description": "Translate modifier presets for use with `@dnd-kit` packages.",
|
5
5
|
"author": "Claudéric Demers",
|
6
6
|
"license": "MIT",
|
@@ -26,14 +26,14 @@
|
|
26
26
|
"dist"
|
27
27
|
],
|
28
28
|
"dependencies": {
|
29
|
-
"@dnd-kit/utilities": "^3.1.0-next-
|
29
|
+
"@dnd-kit/utilities": "^3.1.0-next-202208173143",
|
30
30
|
"tslib": "^2.0.0"
|
31
31
|
},
|
32
32
|
"peerDependencies": {
|
33
|
-
"@dnd-kit/core": "^5.0.0-next-
|
33
|
+
"@dnd-kit/core": "^5.0.0-next-202208173143"
|
34
34
|
},
|
35
35
|
"devDependencies": {
|
36
|
-
"@dnd-kit/core": "^5.0.0-next-
|
36
|
+
"@dnd-kit/core": "^5.0.0-next-202208173143"
|
37
37
|
},
|
38
38
|
"publishConfig": {
|
39
39
|
"access": "public"
|