@progress/kendo-react-common 16.1.0-develop.9 → 16.2.0-develop.1
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/Draggable.js +1 -1
- package/Draggable.mjs +11 -9
- package/dist/cdn/js/kendo-react-common.js +1 -1
- package/hooks/useDraggable.d.ts +24 -0
- package/hooks/useDraggable.js +1 -1
- package/hooks/useDraggable.mjs +272 -214
- package/package.json +1 -1
package/hooks/useDraggable.d.ts
CHANGED
|
@@ -36,6 +36,30 @@ export interface DraggableOptions {
|
|
|
36
36
|
* Defaults to `false`.
|
|
37
37
|
*/
|
|
38
38
|
mouseOnly?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Set the `autoTouchAction` property to `false` to prevent the draggable from
|
|
41
|
+
* setting `touch-action: none` on the element (unless `pressHoldDelay > 0`, which
|
|
42
|
+
* requires `touch-action: none` so press-and-hold tracking is not interrupted by
|
|
43
|
+
* `pointercancel`). This allows native touch scrolling while keeping pointer event
|
|
44
|
+
* handling for mouse-based drag selection.
|
|
45
|
+
*
|
|
46
|
+
* @hidden
|
|
47
|
+
*
|
|
48
|
+
* Defaults to `true`.
|
|
49
|
+
*/
|
|
50
|
+
autoTouchAction?: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Delay in milliseconds before enabling drag on touch devices.
|
|
53
|
+
* Useful to distinguish intentional drag gestures from quick scroll gestures.
|
|
54
|
+
* The pointer must stay down for this duration before drag selection starts; movement
|
|
55
|
+
* during the delay is treated as a scroll preview and is superseded by drag-select once
|
|
56
|
+
* the delay elapses, so the user doesn't need to hold still.
|
|
57
|
+
* Only applies to touch devices when `autoTouchAction` is `false`.
|
|
58
|
+
*
|
|
59
|
+
* @hidden
|
|
60
|
+
* @default 0
|
|
61
|
+
*/
|
|
62
|
+
pressHoldDelay?: number;
|
|
39
63
|
/**
|
|
40
64
|
* Set the `autoScroll` property to `false` to disable automatic container scroll when close to the edge.
|
|
41
65
|
* For more information, refer to the [Auto Scroll](https://www.telerik.com/kendo-react-ui/components/common/drag-and-drop/auto-scroll) article.
|
package/hooks/useDraggable.js
CHANGED
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*-------------------------------------------------------------------------------------------
|
|
7
7
|
*/
|
|
8
8
|
"use client";
|
|
9
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
9
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Fe=require("react"),Y=require("@progress/kendo-draggable-common"),p=require("../noop.js"),Re=require("./useInheritedState.js"),We=require("../drag-n-drop/context/index.js"),Ge=require("./use-isomorphic-layout-effect.js");function Je(c){const S=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(c){for(const g in c)if(g!=="default"){const D=Object.getOwnPropertyDescriptor(c,g);Object.defineProperty(S,g,D.get?D:{enumerable:!0,get:()=>c[g]})}}return S.default=c,Object.freeze(S)}const t=Je(Fe),Ke=2e3,Qe=16;function Ze(c,S,g={}){const{onPress:D=p.noop,onRelease:ue=p.noop,onDragStart:ae=p.noop,onDrag:ie=p.noop,onDragEnd:de=p.noop}=S,{hint:d=null,mouseOnly:j=!1,autoTouchAction:A=!0,pressHoldDelay:_=0,autoScroll:s=!0,scrollContainer:f=null,context:Te=We.DragAndDropContext}=g,[m,Ie]=t.useState(!1),[L,Me]=t.useState(!1),{drop:He,setDrop:Xe,drag:Ye,setDrag:je,drops:w,drags:R,registerDrag:T,deregisterDrag:I}=t.useContext(Te),[q]=Re.useInheritedState([He,Xe]),[N,M]=Re.useInheritedState([Ye,je]),O=t.useRef({x:0,y:0}),U=t.useRef(void 0),H=t.useRef(!1),fe=t.useRef(void 0),h=t.useRef(void 0),P=t.useRef(!1),C=t.useRef(null),i=t.useRef(void 0),b=t.useRef(!1),l=t.useRef(null),u=t.useRef(null),B=t.useRef(!1),V=t.useRef({x:0,y:0}),z=t.useRef({x:0,y:0}),x=t.useRef({x:0,y:0}),F=t.useRef({x:0,y:0}),W=t.useRef({x:0,y:0}),G=t.useRef({x:0,y:0}),Ae=!!(typeof window!="undefined"&&window.PointerEvent),he=!j&&Ae,v=!A&&_>0,a=t.useCallback(()=>c.current&&c.current.element?c.current.element:c.current,[c]),_e=t.useCallback(()=>d&&d.current&&d.current.element?d.current.element:d?d.current:null,[d]),pe=t.useCallback(()=>f&&f.current&&f.current.element?f.current.element:f?f.current:null,[f]),ge=t.useCallback(()=>{if(typeof s=="object"&&s.boundaryElementRef&&s.boundaryElementRef.current){const e=s.boundaryElementRef.current;return typeof e=="object"&&"element"in e?e.element:e}return u.current},[s]),E=t.useRef(null);t.useImperativeHandle(E,()=>({get element(){return a()},get hint(){return _e()},onPress:qe,onDragStart:Ue,onDrag:Be,onDragEnd:Ve,onRelease:Ne,data:c.current}));const X=t.useCallback(()=>{const e=a();return e&&e.ownerDocument||document},[a]),y=t.useCallback(()=>{const e=X();return e&&e.defaultView||window},[X]),me=t.useCallback(()=>({get drag(){return N?N.current:null},get drop(){return q?q.current:null},get drags(){return(R!=null?R:[]).map(e=>e.current)},get drops(){return(w!=null?w:[]).map(e=>e.current)},pressed:!!m,ignoreMouse:H.current,scrollOffset:W.current,offset:V.current,pageOffset:z.current,initialScrollOffset:G.current,clientOffset:x.current,initialClientOffset:F.current,velocity:O.current,autoScroll:!!(typeof s=="object"?s.enabled!==!1:s),scrollableParent:ge(),autoScrollDirection:typeof s=="object"?s.direction:{horizontal:!0,vertical:!0},isScrolling:L}),[N,q,R,w,m,H,W,V,z,G,x,F,O,s,L,ge]),Ce=t.useCallback(e=>{Ie(e)},[]),be=t.useCallback(e=>{Me(e)},[]),ve=t.useCallback(e=>{O.current=e},[]),Ee=t.useCallback(e=>{V.current=e},[]),ye=t.useCallback(e=>{x.current=e},[]),ke=t.useCallback(e=>{z.current=e},[]),Se=t.useCallback(e=>{F.current=e},[]),De=t.useCallback(e=>{W.current=e},[]),Oe=t.useCallback(e=>{G.current=e},[]),qe=t.useCallback(e=>{D(e)},[D]),Ne=t.useCallback(e=>{ue(e)},[ue]),Ue=t.useCallback(e=>{M(E,{target:c.current,event:e}),ae(e)},[M,c,ae]),Be=t.useCallback(e=>{ie(e)},[ie]),Ve=t.useCallback(e=>{B.current||(M(null,{target:c.current,event:e}),de(e))},[de,M,c]),r=t.useCallback(e=>{E.current&&Y.dispatchDragAndDrop(me(),{event:e,payload:E.current},{onVelocityChange:ve,onOffsetChange:Ee,onClientOffsetChange:ye,onPageOffsetChange:ke,onInitialClientOffsetChange:Se,onScrollOffsetChange:De,onInitialScrollOffsetChange:Oe,onIsPressedChange:Ce,onIsScrollingChange:be})},[me,ve,Ee,ke,ye,Se,Oe,Ce,De,be]),k=t.useCallback(()=>{h.current&&(window.clearTimeout(h.current),h.current=void 0),P.current=!1,C.current=null,i.current=void 0,b.current=!1,l.current=null},[]),Pe=t.useCallback(e=>v&&e.pointerType==="touch"&&e.pointerId===i.current,[v]),J=t.useCallback((e,n)=>{u.current&&(u.current.scrollTop+=e.y-n.y,u.current.scrollLeft+=e.x-n.x)},[]),xe=t.useCallback(e=>{i.current=e.pointerId,C.current={x:e.clientX,y:e.clientY},l.current={x:e.clientX,y:e.clientY};const n=a();h.current=window.setTimeout(()=>{P.current=!0,b.current=!1;try{n&&i.current!==void 0&&n.setPointerCapture(i.current)}catch{}},_)},[a,_]),K=t.useCallback(e=>{if(!e.isPrimary){r(e);return}k(),v&&e.pointerType==="touch"?xe(e):P.current=!0,r(e)},[r,v,k,xe]),Q=t.useCallback(e=>{if(Pe(e)){if(!P.current&&C.current){if(b.current){l.current&&J(l.current,{x:e.clientX,y:e.clientY}),l.current={x:e.clientX,y:e.clientY};return}const n=Math.abs(e.clientX-C.current.x),o=Math.abs(e.clientY-C.current.y);if(Math.hypot(n,o)>Qe){b.current=!0,J(C.current,{x:e.clientX,y:e.clientY}),l.current={x:e.clientX,y:e.clientY};return}return}if(P.current){if(l.current&&Math.round(e.clientX)===Math.round(l.current.x)&&Math.round(e.clientY)===Math.round(l.current.y))return;l.current={x:e.clientX,y:e.clientY}}}r(e)},[r,Pe,J]),Z=t.useCallback(e=>{(i.current===void 0||e.pointerId===i.current)&&k(),r(e)},[r,k]),$=t.useCallback(e=>{if(i.current!==void 0&&e.pointerId!==i.current){r(e);return}const n=b.current;if(k(),n){const o=new PointerEvent("pointercancel",e);r(o);return}r(e)},[r,k]),ee=t.useCallback(e=>{r(e)},[r]),te=t.useCallback(e=>{r(e)},[r]),ne=t.useCallback(e=>{r(e)},[r]),re=t.useCallback(e=>{e.preventDefault(),r(e)},[r]),oe=t.useCallback(e=>{e.preventDefault(),r(e)},[r]),ce=t.useCallback(e=>{e.preventDefault(),r(e)},[r]),se=t.useCallback(e=>{if(e.touches.length===0&&e.changedTouches.length===1){const n=y();H.current=!0,fe.current=n.setTimeout(()=>{H.current=!1},Ke)}r(e)},[r,y]),le=t.useCallback(e=>{b.current||r(e)},[r]),Le=t.useCallback(()=>{const e=a();if(e&&(A||v)){const n=e.style.touchAction;return e.style.touchAction="none",()=>{e.style.touchAction=n}}},[a,A,v]),we=t.useCallback(()=>(T==null||T(E),()=>{I==null||I(E)}),[I,T]),ze=()=>{const e=y(),n=a(),o=X();return he?(n&&(u.current=Y.getScrollableParent(n),u.current&&u.current.addEventListener("scroll",le,{passive:!0}),n.addEventListener("pointerdown",K,{passive:!0})),m&&(o.addEventListener("pointermove",Q),o.addEventListener("pointerup",$,!0),o.addEventListener("contextmenu",re),o.addEventListener("pointercancel",Z,{passive:!0}))):(e.addEventListener("touchmove",p.noop,{capture:!1,passive:!1}),n&&(n.addEventListener("mousedown",ee,{passive:!0}),j||(n.addEventListener("touchstart",oe,{passive:!0}),m&&(n.addEventListener("touchmove",ce,{passive:!0}),n.addEventListener("touchend",se,{passive:!0})))),m&&(o.addEventListener("mousemove",te,{passive:!0}),o.addEventListener("mouseup",ne,{passive:!0}))),()=>{u.current&&u.current.removeEventListener("scroll",le),n&&(n.removeEventListener("pointerdown",K),n.removeEventListener("mousedown",ee),n.removeEventListener("touchstart",oe),n.removeEventListener("touchmove",ce),n.removeEventListener("touchend",se)),o.removeEventListener("pointermove",Q),o.removeEventListener("pointerup",$,!0),o.removeEventListener("contextmenu",re),o.removeEventListener("pointercancel",Z),o.removeEventListener("mousemove",te),o.removeEventListener("mouseup",ne),e.removeEventListener("touchmove",p.noop),e.clearTimeout(fe.current)}};t.useEffect(()=>{const e=y();if(L){const n=pe()||u.current||Y.getScrollableParent(document.elementFromPoint(x.current.x,x.current.y));e.clearInterval(U.current),U.current=e.setInterval(()=>{Y.autoScroll(n,{x:O.current.x,y:O.current.y})},50)}return()=>{e.clearInterval(U.current)}},[a,pe,y,L]),t.useEffect(Le,[Le]),t.useEffect(ze,[m,y,a,X,j,he,re,ee,te,ne,Z,K,Q,$,se,ce,oe,le]),t.useEffect(()=>(B.current=!1,()=>{B.current=!0,h.current&&(window.clearTimeout(h.current),h.current=void 0)}),[]),Ge.useIsomorphicLayoutEffect(we,[we])}exports.useDraggable=Ze;
|